@odoo/o-spreadsheet 15.0.28 → 15.0.29
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.
|
@@ -19771,11 +19771,7 @@ class FindAndReplacePlugin extends UIPlugin {
|
|
|
19771
19771
|
for (const cell of Object.values(cells)) {
|
|
19772
19772
|
if (cell &&
|
|
19773
19773
|
this.currentSearchRegex &&
|
|
19774
|
-
this.currentSearchRegex.test(this.searchOptions.searchFormulas
|
|
19775
|
-
? cell.isFormula()
|
|
19776
|
-
? cell.content
|
|
19777
|
-
: String(cell.evaluated.value)
|
|
19778
|
-
: String(cell.evaluated.value))) {
|
|
19774
|
+
this.currentSearchRegex.test(this.searchOptions.searchFormulas ? cell.content : String(cell.evaluated.value))) {
|
|
19779
19775
|
const position = this.getters.getCellPosition(cell.id);
|
|
19780
19776
|
const match = { col: position.col, row: position.row, selected: false };
|
|
19781
19777
|
matches.push(match);
|
|
@@ -26028,6 +26024,9 @@ class Model extends owl__namespace.core.EventBus {
|
|
|
26028
26024
|
this.uuidGenerator.setIsFastStrategy(false);
|
|
26029
26025
|
// starting plugins
|
|
26030
26026
|
this.dispatch("START");
|
|
26027
|
+
// move in "Loading" mode where we ignore redundant calls to finalize triggered by the
|
|
26028
|
+
// replay of stateUpdateMessages in the session
|
|
26029
|
+
this.isLoading = true;
|
|
26031
26030
|
// This should be done after construction of LocalHistory due to order of
|
|
26032
26031
|
// events
|
|
26033
26032
|
this.setupSessionEvents();
|
|
@@ -26037,6 +26036,9 @@ class Model extends owl__namespace.core.EventBus {
|
|
|
26037
26036
|
if (config.snapshotRequested) {
|
|
26038
26037
|
this.session.snapshot(this.exportData());
|
|
26039
26038
|
}
|
|
26039
|
+
this.isLoading = false;
|
|
26040
|
+
// ensure propre recomputation of plugin states after the message replays
|
|
26041
|
+
this.finalize();
|
|
26040
26042
|
}
|
|
26041
26043
|
get handlers() {
|
|
26042
26044
|
return [this.range, ...this.corePlugins, ...this.uiPlugins, this.history];
|
|
@@ -26152,6 +26154,9 @@ class Model extends owl__namespace.core.EventBus {
|
|
|
26152
26154
|
return DispatchResult.Success;
|
|
26153
26155
|
}
|
|
26154
26156
|
finalize() {
|
|
26157
|
+
if (this.isLoading) {
|
|
26158
|
+
return;
|
|
26159
|
+
}
|
|
26155
26160
|
this.status = 3 /* Finalizing */;
|
|
26156
26161
|
for (const h of this.handlers) {
|
|
26157
26162
|
h.finalize();
|
|
@@ -31571,6 +31576,6 @@ exports.registries = registries;
|
|
|
31571
31576
|
exports.setTranslationMethod = setTranslationMethod;
|
|
31572
31577
|
|
|
31573
31578
|
|
|
31574
|
-
__info__.version = '15.0.
|
|
31575
|
-
__info__.date = '2024-
|
|
31576
|
-
__info__.hash = '
|
|
31579
|
+
__info__.version = '15.0.29';
|
|
31580
|
+
__info__.date = '2024-10-14T07:46:39.258Z';
|
|
31581
|
+
__info__.hash = 'd39f433';
|
package/dist/o-spreadsheet.d.ts
CHANGED
|
@@ -19748,11 +19748,7 @@ class FindAndReplacePlugin extends UIPlugin {
|
|
|
19748
19748
|
for (const cell of Object.values(cells)) {
|
|
19749
19749
|
if (cell &&
|
|
19750
19750
|
this.currentSearchRegex &&
|
|
19751
|
-
this.currentSearchRegex.test(this.searchOptions.searchFormulas
|
|
19752
|
-
? cell.isFormula()
|
|
19753
|
-
? cell.content
|
|
19754
|
-
: String(cell.evaluated.value)
|
|
19755
|
-
: String(cell.evaluated.value))) {
|
|
19751
|
+
this.currentSearchRegex.test(this.searchOptions.searchFormulas ? cell.content : String(cell.evaluated.value))) {
|
|
19756
19752
|
const position = this.getters.getCellPosition(cell.id);
|
|
19757
19753
|
const match = { col: position.col, row: position.row, selected: false };
|
|
19758
19754
|
matches.push(match);
|
|
@@ -26005,6 +26001,9 @@ class Model extends owl.core.EventBus {
|
|
|
26005
26001
|
this.uuidGenerator.setIsFastStrategy(false);
|
|
26006
26002
|
// starting plugins
|
|
26007
26003
|
this.dispatch("START");
|
|
26004
|
+
// move in "Loading" mode where we ignore redundant calls to finalize triggered by the
|
|
26005
|
+
// replay of stateUpdateMessages in the session
|
|
26006
|
+
this.isLoading = true;
|
|
26008
26007
|
// This should be done after construction of LocalHistory due to order of
|
|
26009
26008
|
// events
|
|
26010
26009
|
this.setupSessionEvents();
|
|
@@ -26014,6 +26013,9 @@ class Model extends owl.core.EventBus {
|
|
|
26014
26013
|
if (config.snapshotRequested) {
|
|
26015
26014
|
this.session.snapshot(this.exportData());
|
|
26016
26015
|
}
|
|
26016
|
+
this.isLoading = false;
|
|
26017
|
+
// ensure propre recomputation of plugin states after the message replays
|
|
26018
|
+
this.finalize();
|
|
26017
26019
|
}
|
|
26018
26020
|
get handlers() {
|
|
26019
26021
|
return [this.range, ...this.corePlugins, ...this.uiPlugins, this.history];
|
|
@@ -26129,6 +26131,9 @@ class Model extends owl.core.EventBus {
|
|
|
26129
26131
|
return DispatchResult.Success;
|
|
26130
26132
|
}
|
|
26131
26133
|
finalize() {
|
|
26134
|
+
if (this.isLoading) {
|
|
26135
|
+
return;
|
|
26136
|
+
}
|
|
26132
26137
|
this.status = 3 /* Finalizing */;
|
|
26133
26138
|
for (const h of this.handlers) {
|
|
26134
26139
|
h.finalize();
|
|
@@ -31526,6 +31531,6 @@ const helpers = {
|
|
|
31526
31531
|
export { CommandResult, CorePlugin, DATETIME_FORMAT, DataSource, DispatchResult, Model, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, DEBUG as __DEBUG__, __info__, astToFormula, cellTypes, convertAstNodes, coreTypes, functionCache, helpers, invalidateEvaluationCommands, normalize, parse, readonlyAllowedCommands, registries, setTranslationMethod };
|
|
31527
31532
|
|
|
31528
31533
|
|
|
31529
|
-
__info__.version = '15.0.
|
|
31530
|
-
__info__.date = '2024-
|
|
31531
|
-
__info__.hash = '
|
|
31534
|
+
__info__.version = '15.0.29';
|
|
31535
|
+
__info__.date = '2024-10-14T07:46:39.258Z';
|
|
31536
|
+
__info__.hash = 'd39f433';
|
|
@@ -19768,11 +19768,7 @@
|
|
|
19768
19768
|
for (const cell of Object.values(cells)) {
|
|
19769
19769
|
if (cell &&
|
|
19770
19770
|
this.currentSearchRegex &&
|
|
19771
|
-
this.currentSearchRegex.test(this.searchOptions.searchFormulas
|
|
19772
|
-
? cell.isFormula()
|
|
19773
|
-
? cell.content
|
|
19774
|
-
: String(cell.evaluated.value)
|
|
19775
|
-
: String(cell.evaluated.value))) {
|
|
19771
|
+
this.currentSearchRegex.test(this.searchOptions.searchFormulas ? cell.content : String(cell.evaluated.value))) {
|
|
19776
19772
|
const position = this.getters.getCellPosition(cell.id);
|
|
19777
19773
|
const match = { col: position.col, row: position.row, selected: false };
|
|
19778
19774
|
matches.push(match);
|
|
@@ -26025,6 +26021,9 @@
|
|
|
26025
26021
|
this.uuidGenerator.setIsFastStrategy(false);
|
|
26026
26022
|
// starting plugins
|
|
26027
26023
|
this.dispatch("START");
|
|
26024
|
+
// move in "Loading" mode where we ignore redundant calls to finalize triggered by the
|
|
26025
|
+
// replay of stateUpdateMessages in the session
|
|
26026
|
+
this.isLoading = true;
|
|
26028
26027
|
// This should be done after construction of LocalHistory due to order of
|
|
26029
26028
|
// events
|
|
26030
26029
|
this.setupSessionEvents();
|
|
@@ -26034,6 +26033,9 @@
|
|
|
26034
26033
|
if (config.snapshotRequested) {
|
|
26035
26034
|
this.session.snapshot(this.exportData());
|
|
26036
26035
|
}
|
|
26036
|
+
this.isLoading = false;
|
|
26037
|
+
// ensure propre recomputation of plugin states after the message replays
|
|
26038
|
+
this.finalize();
|
|
26037
26039
|
}
|
|
26038
26040
|
get handlers() {
|
|
26039
26041
|
return [this.range, ...this.corePlugins, ...this.uiPlugins, this.history];
|
|
@@ -26149,6 +26151,9 @@
|
|
|
26149
26151
|
return DispatchResult.Success;
|
|
26150
26152
|
}
|
|
26151
26153
|
finalize() {
|
|
26154
|
+
if (this.isLoading) {
|
|
26155
|
+
return;
|
|
26156
|
+
}
|
|
26152
26157
|
this.status = 3 /* Finalizing */;
|
|
26153
26158
|
for (const h of this.handlers) {
|
|
26154
26159
|
h.finalize();
|
|
@@ -31570,9 +31575,9 @@
|
|
|
31570
31575
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
31571
31576
|
|
|
31572
31577
|
|
|
31573
|
-
__info__.version = '15.0.
|
|
31574
|
-
__info__.date = '2024-
|
|
31575
|
-
__info__.hash = '
|
|
31578
|
+
__info__.version = '15.0.29';
|
|
31579
|
+
__info__.date = '2024-10-14T07:46:39.258Z';
|
|
31580
|
+
__info__.hash = 'd39f433';
|
|
31576
31581
|
|
|
31577
31582
|
|
|
31578
31583
|
})(this.o_spreadsheet = this.o_spreadsheet || {}, owl);
|
|
@@ -1041,7 +1041,7 @@
|
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
}
|
|
1044
|
-
`;class Eh extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.state=t.useState(this.initialState())}get hasSearchResult(){return null!==this.env.getters.getCurrentSelectedMatchIndex()}mounted(){this.focusInput()}async willUnmount(){this.env.dispatch("CLEAR_SEARCH")}onInput(e){this.state.toSearch=e.target.value,this.debouncedUpdateSearch()}onKeydownSearch(e){"Enter"===e.key&&(e.preventDefault(),this.onSelectNextCell())}onKeydownReplace(e){"Enter"===e.key&&(e.preventDefault(),this.replace())}onFocusSidePanel(){this.state.searchOptions.searchFormulas=this.getters.shouldShowFormulas(),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas?this.state.searchOptions.searchFormulas:this.state.replaceOptions.modifyFormulas,this.env.dispatch("REFRESH_SEARCH")}searchFormulas(){this.env.dispatch("SET_FORMULA_VISIBILITY",{show:this.state.searchOptions.searchFormulas}),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas,this.updateSearch()}onSelectPreviousCell(){this.env.dispatch("SELECT_SEARCH_PREVIOUS_MATCH")}onSelectNextCell(){this.env.dispatch("SELECT_SEARCH_NEXT_MATCH")}updateSearch(){this.env.dispatch("UPDATE_SEARCH",{toSearch:this.state.toSearch,searchOptions:this.state.searchOptions})}debouncedUpdateSearch(){clearTimeout(this.inDebounce),this.inDebounce=setTimeout((()=>this.updateSearch.call(this)),400)}replace(){this.env.dispatch("REPLACE_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}replaceAll(){this.env.dispatch("REPLACE_ALL_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}focusInput(){const e=this.el.querySelector("input");e&&e.focus()}initialState(){return{toSearch:"",replaceWith:"",searchOptions:{matchCase:!1,exactMatch:!1,searchFormulas:!1},replaceOptions:{modifyFormulas:!1}}}}Eh.template=mh,Eh.style=vh;const Sh=new Le;Sh.add("ConditionalFormatting",{title:a("Conditional formatting"),Body:ph}),Sh.add("ChartPanel",{title:a("Chart"),Body:Nc}),Sh.add("FindAndReplace",{title:a("Find and Replace"),Body:Eh});const bh=new Le;class Ch extends ma{constructor(e,t,s,i){super(t,s,i),this.getters=e,this.ui=i}drawGrid(e,t){}}Ch.layers=[];class Ih{constructor(e,t,s){this.index=0,this.cells=e,this.getters=t,this.direction=s}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:s,tooltip:i}=Ma.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:s,tooltip:i,origin:{col:e.data.col,row:e.data.row}}}}class yh extends Ch{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:gs(e.col,0,this.getters.getSheet(t).cols.length),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:gs(e.row,0,this.getters.getSheet(t).rows.length),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:30;case"AUTOFILL_AUTO":const s=this.getters.getSelectedZone();return s.top===s.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||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),s=this.autofillZone;switch(this.direction){case 1:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(os(i,e));const n=this.createGenerator(o);for(let t=s.top;t<=s.bottom;t++)this.computeNewCell(n,i,t,e)}break;case 0:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(os(i,e));const n=this.createGenerator(o);for(let t=s.bottom;t>=s.top;t--)this.computeNewCell(n,i,t,e)}break;case 2:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(os(e,i));const n=this.createGenerator(o);for(let t=s.right;t>=s.left;t--)this.computeNewCell(n,t,i,e)}break;case 3:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(os(e,i));const n=this.createGenerator(o);for(let t=s.left;t<=s.right;t++)this.computeNewCell(n,t,i,e)}}if(e){const e=Bs(this.getters.getSelectedZone(),this.autofillZone);this.autofillZone=void 0,this.lastCellSelected={},this.direction=void 0,this.tooltip=void 0,this.dispatch("SET_SELECTION",{zones:[e],anchor:[e.left,e.top],anchorZone:e})}}select(e,t){const s=this.getters.getSelectedZone();if(zs(e,t,s))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,s.top-1,s.left,s.right);break;case 1:this.saveZone(s.bottom+1,t,s.left,s.right);break;case 2:this.saveZone(s.top,s.bottom,e,s.left-1);break;case 3:this.saveZone(s.top,s.bottom,s.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let s=e.left,i=e.bottom;if(s>0){let e=this.getters.getCell(t,s-1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s-1,i)}if(i===e.bottom&&(s=e.right,s<=this.getters.getActiveSheet().cols.length)){let e=this.getters.getCell(t,s+1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s+1,i)}i!==e.bottom&&(this.select(e.left,i-1),this.autofill(!0))}computeNewCell(e,t,s,i){const{cellData:o,tooltip:n,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=n,i&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:s,content:a,style:l,border:c,format:h})}getRule(e,t){const s=Aa.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((s=>s.condition(e,t)));return s&&s.generateRule(e,t)}createGenerator(e){const t=[],s=[],i=this.getters.getActiveSheetId();for(let t of e){const[e,o]=is(t),n=this.getters.getCell(i,e,o);s.push({col:e,row:o,cell:n,sheetId:i})}const o=s.map((e=>e.cell));for(let e of s){let s={type:"COPY_MODIFIER"};if(e&&e.cell){s=this.getRule(e.cell,o)||s}const{sheetId:i,col:n,row:r}=e,a=this.getters.getCellBorder(i,n,r)||void 0;t.push({data:{...e,border:a},rule:s})}return new Ih(t,this.getters,this.direction)}saveZone(e,t,s,i){this.autofillZone={top:e,bottom:t,left:s,right:i}}getDirection(e,t){const s=this.getters.getSelectedZone(),i={up:{number:s.top-t,value:0},down:{number:t-s.bottom,value:1},left:{number:s.left-e,value:2},right:{number:e-s.right,value:3}};if(1===Object.values(i).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(i).find((e=>e.number>0?1:0)).value;const o=i.up.number>0?"up":"down",n=i.left.number>0?"left":"right";return Math.abs(i[o].number)>=Math.abs(i[n].number)?i[o].value:i[n].value}autoFillMerge(e,t,s,i){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,s,i)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const n=this.getters.getMerge(o.id,e,t);(null==n?void 0:n.topLeft.col)===e&&(null==n?void 0:n.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:i,bottom:i+n.bottom-n.top,left:s,right:s+n.right-n.left}]})}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:s,thinLineWidth:i}=e,[o,n,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(s.strokeStyle="black",s.lineWidth=i,s.setLineDash([3]),s.strokeRect(o,n,r,a),s.setLineDash([]))}}yh.layers=[6],yh.getters=["getAutofillTooltip"],yh.modes=["normal"];class wh extends Ch{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:s}=this.getters.getSelection();for(const i of t){const t=this.getAutomaticSums(e,i,s);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,s){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,s):this.sumData(e,t)}sumData(e,t){const s=this.dimensionsToSum(e,t),i=this.sumDimensions(e,t,s).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return s.has("ROW")&&s.has("COL")&&i.push(this.sumTotal(t)),i}sumAdjacentData(e,t,s){const[i,o]=zs(s[0],s[1],t)?s:[t.left,t.top],n=this.findAdjacentData(e,i,o);return n?this.getters.isSingleCellOrMerge(e,t)||js(Bs(n,t))?[{position:[i,o],zone:n}]:this.sumDimensions(e,Bs(n,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,s){const i=this.getters.getSheet(e),o=this.findSuitableZoneToSum(i,...this.getters.getMainCell(e,t,s));if(o)return this.getters.expandZone(e,o)}findSuitableZoneToSum(e,t,s){const i=this.getters.getCell(e.id,t,s-1),o=this.getters.getCell(e.id,t-1,s);if(this.isNumber(o)&&!this.isNumber(i))return this.findHorizontalZone(e,t,s);const n=this.findVerticalZone(e,t,s);if(this.isZoneValid(n))return n;const r=this.findHorizontalZone(e,t,s);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,s){const i={top:0,bottom:s-1,left:t,right:t},o=this.reduceZoneStart(e,i,i.bottom);return{...i,top:o}}findHorizontalZone(e,t,s){const i={top:s,bottom:s,left:0,right:t-1},o=this.reduceZoneStart(e,i,i.right);return{...i,left:o}}reduceZoneStart(e,t,s){const i=Ws(t,e,(e=>e),void 0).flat(),o=ms(s,-1,-1),n=Os(o.filter((e=>{var t;return i[e]&&!(null===(t=i[e])||void 0===t?void 0:t.isAutoSummable)}))),r=vs(o.filter((e=>this.isNumber(i[e]))))[0]||[];return Os(r)<n?1/0:Ns(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===ke.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(A))}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 s=new Set;return js(t)?(s.add(1===qs(t).width?"COL":"ROW"),s):(this.lastColIsEmpty(e,t)&&s.add("ROW"),this.lastRowIsEmpty(e,t)&&s.add("COL"),0===s.size&&s.add("COL"),s)}sumDimensions(e,t,s){return[...s.has("COL")?this.sumColumns(t,e):[],...s.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:s}=e;return{position:[s,t],zone:{...e,top:t,right:s-1}}}sumColumns(e,t){const s=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,s.bottom-1)},Ys(s).map((t=>({position:t,zone:{...e,right:t[0],left:t[0]}})))}sumRows(e,t){const s=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,s.right-1)},Ys(s).map((t=>({position:t,zone:{...e,top:t[1],bottom:t[1]}})))}dispatchCellUpdates(e,t){for(const s of t){const[t,i]=s.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,content:`=SUM(${this.getters.zoneToXC(e,s.zone)})`})}}nextEmptyRow(e,t){let s=t.bottom+1;const{left:i,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:s,top:s,left:i,right:o});)s++;return{...t,top:s,bottom:s}}nextEmptyCol(e,t){let s=t.right+1;const{top:i,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:s,right:s,top:i,bottom:o});)s++;return{...t,left:s,right:s}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}wh.getters=["getAutomaticSums"],wh.modes=["normal","headless"];class Th extends Ch{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"PASTE":return this.isPasteAllowed(this.state,e.target,!!e.force);case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}}return 0}handle(e){var t,s,i,o;switch(e.type){case"COPY":case"CUT":this.state=this.getClipboardState(e.target,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);if(this._isPaintingFormat=!1,e.interactive)this.interactivePaste(this.state,e.target,e);else{const t=this.state.cells.length,s=this.state.cells[0].length;this.paste(this.state,e.target,n),this.selectPastedZone(s,t,e.target),this.status="invisible"}break;case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!$s(t[0])){for(const[t,s]of Ys(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:s,sheetId:this.getters.getActiveSheetId()});break}const i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(s=this.state)||void 0===s?void 0:s.sheetId))return;this.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)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this.state=this.getClipboardState(e.target,"COPY"),this._isPaintingFormat=!0,this.status="visible";break;default:Ue(e)&&(this.status="invisible")}}getClipboardContent(){return this.state&&this.state.cells.length&&this.state.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const s=this.getters.getActiveSheet();let i;return i="COL"===t?{...e,left:e.right+1,right:s.cols.length-1}:{...e,top:e.bottom+1,bottom:s.rows.length-1},{cut:[i],paste:[e]}}getInsertCellsTargets(e,t){const s=this.getters.getActiveSheet();let i,o;return"COL"===t?(i={...e,right:s.cols.length-1},o={...e,left:e.right+1,right:e.right+1}):(i={...e,bottom:s.rows.length-1},o={...e,top:e.bottom+1,bottom:s.rows.length-1}),{cut:[i],paste:[o]}}removeMergeIfTopLeft(e){const{sheetId:t,col:s,row:i}=e,[o,n]=this.getters.getMainCell(t,s,i);if(n===i&&o===s){const e=this.getters.getMerge(t,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:t,target:[e]})}}pasteMergeIfExist(e,t){let{sheetId:s,col:i,row:o}=e;const[n,r]=this.getters.getMainCell(s,i,o);if(n===i&&r===o){const e=this.getters.getMerge(s,i,o);if(!e)return;({sheetId:s,col:i,row:o}=t),this.dispatch("ADD_MERGE",{sheetId:s,force:!0,target:[{left:i,top:o,right:i+e.right-e.left,bottom:o+e.bottom-e.top}]})}}getPasteZones(e,t){if(!t.length||!t[0].length)return e;const s=[],i=t.length,o=t[0].length,n=e[e.length-1],r=n.left,a=n.top,l=Math.max(1,Math.floor((n.right+1-r)/o)),c=Math.max(1,Math.floor((n.bottom+1-a)/i));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)s.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*i});return s}getClipboardState(e,t){const s=new Set(e.map((e=>e.top))),i=new Set(e.map((e=>e.bottom)));let o=1===s.size&&1===i.size?e:[e[e.length-1]];o=o.map((e=>({...e})));const n=[],r=[],a=this.getters.getActiveSheetId(),{top:l,bottom:c}=o[0];for(let e=l;e<=c;e++){const t=[];n.push(t);for(let s of o)for(let i=s.left;i<=s.right;i++){const s=this.getters.getCell(a,i,e),o=this.getters.getCellBorder(a,i,e)||void 0;t.push({cell:s,border:o,position:{col:i,row:e,sheetId:a}});const n=this.getters.getMerge(a,i,e);n&&n.top===e&&n.left===i&&r.push(n)}}return{cells:n,operation:t,sheetId:a,zones:o,merges:r}}pasteFromClipboard(e,t){this.status="invisible";const s=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:i,top:o}=e[0],n=Math.max.apply(Math,s.map((e=>e.length))),r=s.length,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,r,i,o);for(let e=0;e<s.length;e++)for(let t=0;t<s[e].length;t++)this.dispatch("UPDATE_CELL",{row:o+e,col:i+t,content:s[e][t],sheetId:a.id});const l={left:i,top:o,right:i+n-1,bottom:o+r-1};this.dispatch("SET_SELECTION",{anchor:[i,o],zones:[l],anchorZone:l})}isPasteAllowed(e,t,s){const i=this.getters.getActiveSheetId();if(!e)return 20;if(t.length>1&&(e.cells.length>1||e.cells[0].length>1))return 19;if(!s)for(let s of this.getPasteZones(t,e.cells))if(this.getters.doesIntersectMerge(i,s))return 2;return 0}paste(e,t,s){if("CUT"===e.operation&&this.clearClippedZones(e),t.length>1)for(const i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,t,o,s);else{const i=e.cells.length,o=e.cells[0].length,n=t[0],r=Math.max(1,Math.floor((n.right+1-n.left)/o)),a=Math.max(1,Math.floor((n.bottom+1-n.top)/i));for(let t=0;t<r;t++)for(let r=0;r<a;r++)this.pasteZone(e,n.left+t*o,n.top+r*i,s)}"CUT"===e.operation&&(this.dispatch("REMOVE_MERGE",{sheetId:e.sheetId,target:e.merges}),this.state=void 0)}selectPastedZone(e,t,s){const i=s[0],o=i.left,n=i.top,r=Math.max(1,Math.floor((i.right+1-i.left)/e)),a=Math.max(1,Math.floor((i.bottom+1-i.top)/t));if(t>1||e>1){const s={left:o,top:n,right:o+r*e-1,bottom:n+a*t-1},[i,l]=this.getters.getSelection().anchor,c=gs(i,o,o+r*e-1),h=gs(l,n,n+a*t-1);this.dispatch("SET_SELECTION",{anchor:[c,h],zones:[s],anchorZone:s})}}clearClippedZones(e){for(const t of e.cells)for(const e of t)e.cell&&this.dispatch("CLEAR_CELL",e.position);this.dispatch("CLEAR_FORMATTING",{sheetId:e.sheetId,target:e.zones})}pasteZone(e,t,s,i){const o=e.cells.length,n=e.cells[0].length,r="onlyValue"!==i&&this.state&&this.state===e,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,o,t,s);for(let l=0;l<o;l++){const o=e.cells[l];for(let c=0;c<n;c++){const n=o[c],h={col:t+c,row:s+l,sheetId:a.id};this.removeMergeIfTopLeft(h),this.pasteMergeIfExist(n.position,h),this.pasteCell(n,h,e.operation,e.zones,i),r&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:h,operation:e.operation})}}}addMissingDimensions(e,t,s,i,o){const{cols:n,rows:r,id:a}=e,l=s+o-r.length;l>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:r.length-1,sheetId:a,quantity:l,position:"after"});const c=t+i-n.length;c>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:n.length-1,sheetId:a,quantity:c,position:"after"})}pasteCell(e,t,s,i,o){const{sheetId:n,col:r,row:a}=t,l=this.getters.getCell(n,r,a);if("onlyValue"!==o&&this.dispatch("SET_BORDER",{sheetId:n,col:r,row:a,border:e.border}),e.cell){if("onlyFormat"===o)return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.format});if("onlyValue"===o){const s=jr(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:s})}let l=e.cell.content;if(e.cell.isFormula()){const t=r-e.position.col,o=a-e.position.row;l=this.getUpdatedContent(n,e.cell,t,o,i,s)}this.dispatch("UPDATE_CELL",{...t,content:l,style:e.cell.style||null,format:e.cell.format})}else l&&("onlyValue"===o?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===o?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,s,i,o,n){if("CUT"===n){const n=[];for(const r of t.dependencies.references)this.isZoneOverlapClippedZone(o,r.zone)?n.push(...this.getters.createAdaptedRanges([r],s,i,e)):n.push(r);const r={...t.dependencies,references:n};return this.getters.buildFormulaContent(e,t.normalizedText,r)}const r=this.getters.createAdaptedRanges(t.dependencies.references,s,i,e),a={...t.dependencies,references:r};return this.getters.buildFormulaContent(e,t.normalizedText,a)}isZoneOverlapClippedZone(e,t){return e.some((e=>Hs(t,e)))}interactivePaste(e,t,s){const i=this.isPasteAllowed(e,t,!1);0!==i?(19===i&&this.ui.notifyUser(a("This operation is not allowed with multiple selections.")),2===i&&this.ui.notifyUser(a("This operation is not possible due to a merge. Please remove the merges first than try again."))):this.dispatch(s.type,{...s,interactive:!1})}isColRowDirtyingClipboard(e,t){if(!this.state||!this.state.zones)return!1;for(let s of this.state.zones){if("COL"===t&&e<=s.right)return!0;if("ROW"===t&&e<=s.bottom)return!0}return!1}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e;if("visible"===this.status&&this.state&&this.state.zones&&this.state.zones.length&&this.state.sheetId===this.getters.getActiveSheetId()){s.setLineDash([8,5]),s.strokeStyle=p,s.lineWidth=3.3*i;for(const e of this.state.zones){const[i,o,n,r]=this.getters.getRect(e,t);n>0&&r>0&&s.strokeRect(i,o,n,r)}}}}var xh;Th.layers=[2],Th.getters=["getClipboardContent","isPaintingFormat"],Th.modes=["normal"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}(xh||(xh={}));class Rh extends Ch{constructor(e,t,s,i){super(e,t,s,i),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0],anchorZone:{top:0,left:0,bottom:0,right:0}},this.selectedFigureId=null,this.activeCol=0,this.activeRow=0,this.mode=xh.idle,this.sheetsData={},this.activeSheet=null,this.moveClient=i.moveClient}allowDispatch(e){switch(e.type){case"SET_SELECTION":if(-1===e.zones.findIndex((t=>Vs(t,e.anchorZone))))return 16;break;case"ALTER_SELECTION":if(e.delta){const{left:t,right:s,top:i,bottom:o}=this.getSelectedZone(),n=this.getters.getActiveSheet(),r=ai(n,"cols",ms(t,s+1)),a=ai(n,"rows",ms(i,o+1));if(0!==e.delta[0]&&void 0===a||0!==e.delta[1]&&void 0===r)return 17}break;case"MOVE_POSITION":{const{cols:t,rows:s}=this.getters.getActiveSheet();if(0!==e.deltaX&&s[this.activeRow].isHidden||0!==e.deltaY&&t[this.activeCol].isHidden)return 17;const{col:i,row:o}=this.getNextAvailablePosition(e.deltaX,e.deltaY);if(o<0||o>s.length-1||i<0||i>t.length-1)return 17;break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().cols.length)return 17;break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().rows.length)return 17;break}case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 23}case"MOVE_COLUMNS_ROWS":const t=this.isMoveElementAllowed(e);return 2===t&&this.ui.notifyUser(a("Merged cells are preventing this operation. Unmerge those cells and try again.")),t}return 0}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":case"CREATE_FIGURE":case"CREATE_CHART":case"UPDATE_FIGURE":case"EVALUATE_CELLS":case"DISABLE_SELECTION_INPUT":case"ENABLE_NEW_SELECTION_INPUT":case"RESIZE_VIEWPORT":break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;default:this.selectedFigureId=null}switch(e.type){case"START":const t=ri(this.getters.getSheets()[0],0,0);this.activeCol=t[0],this.activeRow=t[1],this.dispatch("ACTIVATE_SHEET",{sheetIdTo:this.getters.getSheets()[0].id,sheetIdFrom:this.getters.getSheets()[0].id}),this.selectCell(...t);break;case"ACTIVATE_SHEET":this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow},e.sheetIdTo in this.sheetsData?Object.assign(this,this.sheetsData[e.sheetIdTo]):this.selectCell(...ri(this.getters.getSheet(e.sheetIdTo),0,0));break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.anchorZone,e.strict);break;case"START_SELECTION":this.mode=xh.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=xh.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=xh.expanding;break;case"STOP_SELECTION":this.mode=xh.idle;break;case"MOVE_POSITION":this.movePosition(e.deltaX,e.deltaY);break;case"SELECT_CELL":this.selectCell(e.col,e.row);break;case"SELECT_COLUMN":this.selectColumn(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ROW":this.selectRow(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ALL":this.selectAll();break;case"ALTER_SELECTION":e.delta&&this.moveSelection(e.delta[0],e.delta[1]),e.cell&&this.addCellToSelection(...e.cell);break;case"UNDO":case"REDO":case"DELETE_SHEET":if(!this.getters.tryGetSheet(this.getActiveSheetId())){const e=this.getters.getVisibleSheets();this.activeSheet=this.getters.getSheet(e[0]),this.selectCell(0,0)}this.ensureSelectionValidity();break;case"REMOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&("COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e));break;case"ADD_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onAddElements(e);break;case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"UPDATE_CHART":case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left")}}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getMainCell(e,this.activeCol,this.activeRow);return this.getters.getCell(e,t,s)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.getters.getActiveSheet().rows.length-1)for(let s=t.left;s<=t.right;s++)e.add(s);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.getters.getActiveSheet().cols.length-1)for(let s=t.top;s<=t.bottom;s++)e.add(s);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.anchorZone}getSelection(){return this.selection}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return[this.activeCol,this.activeRow]}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?[t.activeCol,t.activeRow]:ri(this.getters.getSheet(e),0,0)}}getAggregate(){let e=0,t=0;for(let s of this.selection.zones)for(let i=s.top;i<=s.bottom;i++){const o=this.getters.getRow(this.getters.getActiveSheetId(),i);if(void 0!==o)for(let i=s.left;i<=s.right;i++){const s=o.cells[i];(null==s?void 0:s.evaluated.type)===ke.number&&(t++,e+=s.evaluated.value)}}return t<2?null:ie(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Vs(t,e)))}getVisibleFigures(e){const t=[],s=this.getters.getFigures(e),{offsetX:i,offsetY:o}=this.getters.getSnappedViewport(e),{width:n,height:r}=this.getters.getViewportDimension();for(let e of s)e.x>=i+n||e.x+e.width<=i||e.y>=o+r||e.y+e.height<=o||t.push(e);return t}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 s=[];const i="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[i]+1},((t,s)=>e[i]+s));s=s.concat(t)}return[...new Set(s)].sort()}selectColumn(e,t,s){const i=this.getters.getActiveSheet().rows.length-1;let o={left:e,right:e,top:0,bottom:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().rows.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Bs(o,{left:e,right:e,top:l,bottom:i}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[e,l];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectRow(e,t,s){const i=this.getters.getActiveSheet().cols.length-1;let o={top:e,bottom:e,left:0,right:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().cols.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Bs(o,{left:l,right:i,top:t,bottom:t}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[l,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectAll(){const e={left:0,top:0,bottom:this.getters.getActiveSheet().rows.length-1,right:this.getters.getActiveSheet().cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0],anchorZone:e})}selectCell(e,t){const s=this.getters.getActiveSheet();this.moveClient({sheetId:s.id,col:e,row:t});let i=this.getters.expandZone(s.id,{left:e,right:e,top:t,bottom:t});this.mode===xh.expanding?this.selection.zones.push(i):this.selection.zones=[i],this.selection.zones=Ks(this.selection.zones),this.selection.anchorZone=i,this.selection.anchor=[e,t],this.activeCol=e,this.activeRow=t}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}getNextAvailablePosition(e,t){return{col:this.getNextAvailableCol(e,this.activeCol,this.activeRow),row:this.getNextAvailableRow(t,this.activeCol,this.activeRow)}}getNextAvailableCol(e,t,s){const{cols:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,t,n,(e=>this.getters.isInSameMerge(o,t,s,e,s)))}getNextAvailableRow(e,t,s){const{rows:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,s,n,(e=>this.getters.isInSameMerge(o,t,s,t,e)))}getNextAvailableHeader(e,t,s,i,o){var n,r,a;const l=this.getters.getActiveSheetId(),{col:c,row:h}=i;if(0===e)return s;let d=s+e;if(this.getters.isInMerge(l,c,h)){for(;o(d);)d+=e;for(;null===(n=t[d])||void 0===n?void 0:n.isHidden;)d+=e}else if(null===(r=t[d])||void 0===r?void 0:r.isHidden)for(;null===(a=t[d])||void 0===a?void 0:a.isHidden;)d+=e;return d<0||d>t.length-1?t[s].isHidden?this.getNextAvailableHeader(-e,t,s,i,o):s:d}movePosition(e,t){const{col:s,row:i}=this.getNextAvailablePosition(e,t);this.selectCell(s,i)}setSelection(e,t,s,i=!1){this.selectCell(...e);const o=this.getters.getActiveSheetId();let n;t=Ks(t),n=i?{zones:t,anchorZone:s,anchor:e}:{anchor:e,zones:t.map((e=>this.getters.expandZone(o,e))),anchorZone:this.getters.expandZone(o,s)},this.selection=this.clipSelection(o,n)}getReferencePosition(){const e=this.getters.getActiveSheet(),t=this.selection,{left:s,right:i,top:o,bottom:n}=t.anchorZone,[r,a]=t.anchor;return{col:e.cols[r].isHidden&&ai(e,"cols",ms(s,i+1))||r,row:e.rows[a].isHidden&&ai(e,"rows",ms(o,n+1))||a}}moveSelection(e,t){const s=this.selection;let i=[];const[o,n]=s.anchor,{left:r,right:a,top:l,bottom:c}=s.anchorZone;let h=s.anchorZone;const d=this.getters.getActiveSheet(),u=e=>{const{left:t,right:s,top:i,bottom:o}=this.getters.expandZone(d.id,e);return{left:Math.max(0,t),right:Math.min(d.cols.length-1,s),top:Math.max(0,i),bottom:Math.min(d.rows.length-1,o)}},{col:p,row:g}=this.getReferencePosition();let f=0;for(;null!==h;){if(f++,e<0){const t=this.getNextAvailableCol(e,a-(f-1),g);h=p<=a-f?u({top:l,left:r,bottom:c,right:t}):null}if(e>0){const t=this.getNextAvailableCol(e,r+(f-1),g);h=r+f<=p?u({top:l,left:t,bottom:c,right:a}):null}if(t<0){const e=this.getNextAvailableRow(t,p,c-(f-1));h=g<=c-f?u({top:l,left:r,bottom:e,right:a}):null}if(t>0){const e=this.getNextAvailableRow(t,p,l+(f-1));h=l+f<=g?u({top:e,left:r,bottom:c,right:a}):null}if(h=h?Qs(h):h,h&&!Vs(h,s.anchorZone))return i=this.updateSelectionZones(h),void this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h})}h=u(Bs({top:n,bottom:n,left:o,right:o},Qs({top:this.getNextAvailableRow(t,p,l),left:this.getNextAvailableCol(e,r,g),bottom:this.getNextAvailableRow(t,p,c),right:this.getNextAvailableCol(e,a,g)}))),Vs(h,s.anchorZone)||(i=this.updateSelectionZones(h),this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h}))}addCellToSelection(e,t){const s=this.selection,[i,o]=s.anchor,n={left:Math.min(i,e),top:Math.min(o,t),right:Math.max(i,e),bottom:Math.max(o,t)},r=this.updateSelectionZones(n);this.dispatch("SET_SELECTION",{zones:r,anchor:[i,o],anchorZone:n})}ensureSelectionValidity(){const{anchor:e,zones:t,anchorZone:s}=this.clipSelection(this.getActiveSheetId(),this.selection);this.setSelection(e,t,s);const i=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of i)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:s,anchorZone:i}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:s,anchorZone:i},activeCol:t[0],activeRow:t[1]}}}clipSelection(e,t){const s=this.getters.getSheet(e),i=s.cols.length-1,o=s.rows.length-1,n=t.zones.map((e=>({left:gs(e.left,0,i),right:gs(e.right,0,i),top:gs(e.top,0,o),bottom:gs(e.bottom,0,o)})));return{anchor:[gs(t.anchor[0],0,i),gs(t.anchor[1],0,o)],zones:n,anchorZone:{left:gs(t.anchorZone.left,0,i),right:gs(t.anchorZone.right,0,i),top:gs(t.anchorZone.top,0,o),bottom:gs(t.anchorZone.bottom,0,o)}}}onColumnsRemoved(e){const t=Ps(this.getSelectedZone(),"left",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onRowsRemoved(e){const t=Ps(this.getSelectedZone(),"top",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onAddElements(e){const t=Us(this.getSelectedZone(),"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.setSelection([t.left,t.top],[t],t,!0)}updateSelectionZones(e){let t=[...this.selection.zones];const s=this.selection.anchorZone,i=t.findIndex((e=>Vs(e,s)));return i>=0&&(t[i]=e),t}activateNextSheet(e){const t=this.getters.getSheets().map((e=>e.id)),s=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[s]})}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 s="COL"===e.dimension,i=e.elements[0],o=e.elements[t-1],n=e.base<i,r=n&&s?t:0,a=n&&!s?t:0,l=this.getters.getSheet(e.sheetId);this.dispatch("CUT",{target:[{left:s?i+r:0,right:s?o+r:l.cols.length-1,top:s?0:i+a,bottom:s?l.rows.length-1:o+a}]}),this.dispatch("PASTE",{target:[{left:s?e.base:0,right:s?e.base+t-1:l.cols.length-1,top:s?0:e.base,bottom:s?l.rows.length-1:e.base+t-1}]});const c=n?e.elements.map((e=>e+t)):e.elements;let h=e.base;for(const t of c){const s="COL"===e.dimension?this.getters.getCol(e.sheetId,t).size:this.getters.getRow(e.sheetId,t).size;this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:s,elements:[h]}),h+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:c})}isMoveElementAllowed(e){const t="COL"===e.dimension,s=e.elements[0],i=e.elements[e.elements.length-1],o=e.sheetId,n=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return n(o,s-1,s)||n(o,i,i+1)||n(o,e.base-1,e.base)?2:0}drawGrid(e){if("inactive"!==this.getters.getEditionMode())return;const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getSelectedZones();s.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;s.fillStyle=n?"#f3f7fe":"#e9f0ff",s.strokeStyle=p,s.lineWidth=1.5*i,s.globalCompositeOperation="multiply";for(const e of o){const[i,o,n,r]=this.getters.getRect(e,t);s.fillRect(i,o,n,r),s.strokeRect(i,o,n,r)}s.globalCompositeOperation="source-over";const r=this.getters.getActiveSheetId(),[a,l]=this.getPosition();let c;s.strokeStyle=p,s.lineWidth=3*i,c=this.getters.isInMerge(r,a,l)?this.getters.getMerge(r,a,l):{top:l,bottom:l,left:a,right:a};const[h,d,u,g]=this.getters.getRect(c,t);u>0&&g>0&&s.strokeRect(h,d,u,g)}}Rh.layers=[5],Rh.modes=["normal"],Rh.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getAggregate","getSelectedFigureId","getVisibleFigures","getSelection","getPosition","getSheetPosition","getSelectionMode","isSelected","getElementsFromSelection"];const Lh=a("The cell you are trying to edit has been deleted.");class Mh extends Ch{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.multiSelectionInitialStart=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=this.getters.getActiveCell(),s=e.text||(null==t?void 0:t.composerContent)||"";return this.validateSelection(s.length,e.selection.start,e.selection.end)}return 0;default:return 0}}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":this.startEdition(e.text,e.selection);break;case"STOP_EDITION":e.cancel?(this.cancelEdition(),this.resetContent()):this.stopEdition();break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0);break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEdition(),this.resetContent();break;case"SELECT_CELL":case"SET_SELECTION":case"MOVE_POSITION":switch(this.mode){case"editing":this.dispatch("STOP_EDITION");break;case"waitingForRangeSelection":this.insertSelectedRange();break;case"rangeSelected":switch(e.type){case"MOVE_POSITION":this.replaceAllSelectedRanges();break;case"SELECT_CELL":this.getters.getSelectionMode()===xh.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges();break;case"SET_SELECTION":e.strict?this.getters.getSelectionMode()===xh.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges():this.replaceSelectedRange()}}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.currentTokens.filter((e=>"SYMBOL"===e.type)).find((t=>{let s=t.value;const{xc:i,sheetName:o}=ts(s),n=o||this.getters.getSheetName(this.sheet),r=this.getters.getActiveSheetId();return Vs(this.getters.expandZone(r,Fs(i)),e.zone)&&this.getters.getSheetName(r)===n}));this.previousRef=t.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=t.start;break;case"CHANGE_HIGHLIGHT":const s=this.getZoneReference(e.zone,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(s),this.previousRef=s,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheet)||"inactive"===this.mode||(this.cancelEdition(),this.resetContent(),this.ui.notifyUser(Lh))}}getEditionMode(){return this.mode}getCurrentContent(){if("inactive"===this.mode){const e=this.getters.getActiveCell();return(null==e?void 0:e.composerContent)||""}return this.currentContent}getEditionSheet(){return this.sheet}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}isSelectingForComposer(){return"waitingForRangeSelection"===this.mode||"rangeSelected"===this.mode||"resettingPosition"===this.mode}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((s=>s.start<=e&&s.end>=t))}validateSelection(e,t,s){return t>=0&&t<=e&&s>=0&&s<=e?0:31}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Lh);const{top:t,left:s}=Ps({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",e.elements);this.col=s,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Lh);const{top:t,left:s}=Ps({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",e.elements);this.col=s,this.row=t}onAddElements(e){const{top:t,left:s}=Us({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=s,this.row=t}startComposerRangeSelection(){this.mode="resettingPosition",this.sheet===this.getters.getActiveSheetId()&&this.dispatch("SELECT_CELL",{col:this.col,row:this.row}),this.mode="waitingForRangeSelection",this.multiSelectionInitialStart=this.selectionStart}startEdition(e,t){const s=this.getters.getActiveCell();this.initialContent=(null==s?void 0:s.composerContent)||"",this.mode="editing";const[i,o]=this.getters.getPosition();this.col=i,this.row=o,this.sheet=this.getters.getActiveSheetId(),this.setContent(e||this.initialContent,t),this.colorIndexByRange={}}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();const e=this.getters.getActiveSheetId(),t=this.getters.getSheets().find((e=>e.id===this.sheet)).id,[s,i]=this.getters.getMainCell(t,this.col,this.row);let o=this.currentContent;if(!(this.initialContent!==o))return;if(o){const t=this.getters.getCell(e,s,i);if(o.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,s=e-t;s>0&&(o+=new Array(s).fill(")").join(""))}else(null==t?void 0:t.isLink())&&(o=ws(o,t.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheet,col:s,row:i,content:o})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheet,content:"",col:s,row:i});e!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheet}),this.setContent("")}}cancelEdition(){this.mode="inactive"}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,s){e=e.replace(/[\r\n]/g,"");const i=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(i||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?Zr(e):[],this.currentTokens.length>100&&s&&this.ui.notifyUser(a("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(){const e=Math.min(this.selectionStart,this.selectionEnd),t=this.getZoneReference(this.getters.getSelectedZone());if("waitingForRangeSelection"===this.mode)return this.insertText(t,e),this.selectionInitialStart=e,void(this.mode="rangeSelected");this.insertText(","+t,e),this.selectionInitialStart=e+1}replaceSelectedRange(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.selectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone()))}replaceAllSelectedRanges(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.multiSelectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone())),this.selectionInitialStart=this.multiSelectionInitialStart}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const s=this.getters.getActiveSheetId();let i=this.getters.zoneToXC(s,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){i=`${ps(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${i}`}return i}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),s=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,s)}replaceText(e,t,s){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(s,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const s=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),i=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:s,selection:{start:i,end:i}})}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=[],t={};for(let s of this.currentTokens.filter((e=>"SYMBOL"===e.type))){let i=s.value;const{xc:o,sheetName:n}=ts(i);if(es.test(o)){const s=(n?`${n}!`:`${this.getters.getSheetName(this.getters.getEditionSheet())}!`)+o.replace(/\$/g,"");e.push(s);const i=this.colorIndexByRange[s];void 0!==i&&(t[s]=i)}}this.colorIndexByRange=t;let s=Object.values(t),i=0;return e.map((e=>{if(void 0===this.colorIndexByRange[e]){for(;s.includes(i);)i++;s.push(i),this.colorIndexByRange[e]=i}return[e,jt[this.colorIndexByRange[e]%jt.length]]}))}canStartComposerRangeSelection(){if("editing"!==this.mode&&this.selectionStart===this.selectionEnd)return!1;if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(e){const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let s=t,i=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type||s<1)return!1;s--,i=this.currentTokens[s]}for(s=t+1,i=this.currentTokens[s];i&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type)return!1;s++,i=this.currentTokens[s]}s++,i=this.currentTokens[s]}return!0}return!1}}Mh.getters=["getEditionMode","isSelectingForComposer","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights"],Mh.modes=["normal"];const Ah=ar.mapping;class _h extends Ch{constructor(e,t,s,i){super(e,t,s,i),this.isUpToDate=new Set,this.evalContext=i.evalContext,i.dataSources.on("data-loaded",this,(()=>{this.dispatch("EVALUATE_CELLS",{sheetId:this.getters.getActiveSheetId()})}))}handle(e){switch(Fe.has(e.type)&&this.isUpToDate.clear(),e.type){case"UPDATE_CELL":"content"in e&&this.isUpToDate.clear();break;case"ACTIVATE_SHEET":this.evaluate(e.sheetIdTo),this.isUpToDate.add(e.sheetIdTo);break;case"EVALUATE_CELLS":this.evaluate(e.sheetId),this.isUpToDate.add(e.sheetId);break;case"EVALUATE_ALL_SHEETS":this.evaluateAllSheets()}}finalize(){const e=this.getters.getActiveSheetId();this.isUpToDate.has(e)||(this.evaluate(e),this.isUpToDate.add(e))}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{let s=Gr(e);const i=Vr(s),o=this.getFormulaParameters((()=>{})),n=[];for(let e of s.dependencies.references)n.push(this.getters.getRangeFromSheetXC(t,e));return i({...s.dependencies,references:n},t,...o)}catch(e){return"#ERROR"}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Ws(e.zone,t,(e=>this.getters.getCellText(e,this.getters.shouldShowFormulas())),"")}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Ws(e.zone,t,(e=>e.evaluated.value))}evaluate(e){const t=this.getters.getCells(e),s=this.getFormulaParameters(o),i={};for(let s of Object.values(t))o(s,e);function o(e,t){if(!e.isFormula())return;const o=e.id;if(o in i)null===i[o]&&e.assignError("#CYCLE",a("Circular reference"));else{i[o]=null;try{if(s[2].__originCellXC=()=>{const e=s[2].getters.getCellPosition(o);return os(e.col,e.row)},e.assignValue(e.compiledFormula(e.dependencies,t,...s)),Array.isArray(e.evaluated.value))throw new Error(a("This formula depends on invalid values"))}catch(t){!function(e,t){if(e instanceof Error||(e=new Error(e)),"#CYCLE"!==t.evaluated.value){t.assignValue("#ERROR");const i=s[2].__lastFnCalled||"";t.assignError("#ERROR",e.message.replace("[[FUNCTION_NAME]]",i))}}(t,e)}i[o]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Ah),this.evalContext,{getters:this.getters});function s(t,s){if(e(t,s),t.evaluated.type===ke.error)throw new Error(a("This formula depends on invalid values"));return t.evaluated.value}function i(e){o(e);const i=t.getters.getSheet(e.sheetId),n={top:0,bottom:i.rows.length-1,left:0,right:i.cols.length-1},r=[],a=function(e,t){if(Hs(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom,t.bottom),right:Math.min(e.right,t.right)}}(e.zone,n);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const o=[];for(let n=a.top;n<=a.bottom;n++){const r=t.getters.getCell(e.sheetId,i,n);o.push(r?s(r,e.sheetId):void 0)}r.push(o)}return r}function o(e){if(!$s(e.zone))throw new Error(a("Invalid reference"));if(e.invalidSheetName)throw new Error(a("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,i,n,r,l,c){const h=i[e];if(o(h),r)return t.getters.getRangeString(h,n);if(h.zone.bottom!==h.zone.top||h.zone.left!==h.zone.right)throw new Error(c?a("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",l.toString(),c.toString()):a("Function %s expects its parameters to be single values or single cell references, not ranges.",l.toString()));return function(e){var i;const o=null===(i=t.getters.getSheet(e.sheetId).rows[e.zone.top])||void 0===i?void 0:i.cells[e.zone.left];return!o||o.isEmpty()?null:s(o,e.sheetId)}(h)},function(e,t,s){return i(t[e])},t]}evaluateAllSheets(){for(const e of this.getters.getVisibleSheets())this.evaluate(e),this.isUpToDate.add(e)}}_h.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"],_h.modes=["normal"];const Oh=["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 Nh{constructor(){this.graphColorIndex=0}next(){return Oh[this.graphColorIndex++%Oh.length]}}class kh extends Ch{constructor(){super(...arguments),this.chartRuntime={},this.outOfDate=new Set}handle(e){if(Fe.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type&&"content"in e)for(let e of Object.keys(this.chartRuntime))this.outOfDate.add(e);switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const t=this.getters.getChartDefinition(e.id);this.chartRuntime[e.id]=this.mapDefinitionToRuntime(t);break;case"DELETE_FIGURE":delete this.chartRuntime[e.id];break;case"REFRESH_CHART":this.evaluateUsedSheets([e.id]),this.outOfDate.add(e.id);break;case"ACTIVATE_SHEET":const s=this.getters.getChartsIdBySheet(e.sheetIdTo);this.evaluateUsedSheets(s);break;case"DELETE_SHEET":for(let e of Object.keys(this.chartRuntime))this.getters.getChartDefinition(e)||delete this.chartRuntime[e]}}getChartRuntime(e){if(this.outOfDate.has(e)||!(e in this.chartRuntime)){const t=this.getters.getChartDefinition(e);if(void 0===t)return;this.chartRuntime[e]=this.mapDefinitionToRuntime(t),this.outOfDate.delete(e)}return this.chartRuntime[e]}truncateLabel(e){return e?e.length>20?e.substring(0,20)+"…":e:""}getDefaultConfiguration(e,t){const s={};e.labelRange||1!==e.dataSets.length?s.position=e.legendPosition:s.display=!1;const i={type:e.type,options:{legend:s,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:e.title}},data:{labels:t.map(this.truncateLabel),datasets:[]}};return"pie"!==e.type?(i.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{position:e.verticalAxisPosition,ticks:{beginAtZero:!0}}]},"bar"===e.type&&e.stackedBar&&(i.options.scales.xAxes[0].stacked=!0,i.options.scales.yAxes[0].stacked=!0)):i.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},i}getSheetIdsUsedInChart(e){const t=new Set;for(let s of e.dataSets)t.add(s.dataRange.sheetId);return e.labelRange&&t.add(e.labelRange.sheetId),t}evaluateUsedSheets(e){const t=new Set;for(let s of e){const e=this.getters.getChartDefinition(s);(void 0!==e?this.getSheetIdsUsedInChart(e):[]).forEach((e=>{e!==this.getters.getActiveSheetId()&&t.add(e)}))}for(let e of t)this.dispatch("EVALUATE_CELLS",{sheetId:e})}mapDefinitionToRuntime(e){let t=[];if(e.labelRange)e.labelRange.invalidXc||e.labelRange.invalidSheetName||(t=this.getters.getRangeFormattedValues(e.labelRange).flat(1));else if(1===e.dataSets.length)for(let s=0;s<this.getData(e.dataSets[0],e.sheetId).length;s++)t.push("");else if(e.dataSets[0]){t=ms(0,this.getData(e.dataSets[0],e.sheetId).length).map((e=>e.toString()))}const s=this.getDefaultConfiguration(e,t),i=new Nh,o=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.getData(t,e.sheetId).length)));for(let e=0;e<=t;e++)o.push(i.next())}for(const[t,n]of Object.entries(e.dataSets)){let r;if(n.labelCell){const e=n.labelCell,s=e?this.getters.getCell(e.sheetId,e.zone.left,e.zone.top):void 0;r=s&&e?this.truncateLabel(s.formattedValue):r=`${uc.Series} ${parseInt(t)+1}`}else r=r=`${uc.Series} ${parseInt(t)+1}`;const a="pie"!==e.type?i.next():"#FFFFFF",l={label:r,data:n.dataRange?this.getData(n,e.sheetId):[],lineTension:0,borderColor:a,backgroundColor:a};"pie"===e.type&&(l.backgroundColor=o),s.data.datasets.push(l)}return s}getData(e,t){if(e.dataRange){const t=e.labelCell?[Ds(e.labelCell.zone)]:[],s=Zs([Ds(e.dataRange.zone)],t)[0];if(void 0===s)return[];const i=this.getters.getRangeFromSheetXC(e.dataRange.sheetId,s);return this.getters.getRangeValues(i).flat(1)}return[]}}kh.getters=["getChartRuntime"],kh.modes=["normal"];class Fh extends Ch{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new ni,this.rulePredicate={CellIsRule:(e,t)=>{var s,i,o,n,r,l;if(e&&e.evaluated.type===ke.error)return!1;const c=t.values.map(Yr);switch(t.operator){case"IsEmpty":return!Ms(e)||""===(null===(s=e.evaluated.value)||void 0===s?void 0:s.toString().trim());case"IsNotEmpty":return Ms(e)&&""!==(null===(i=e.evaluated.value)||void 0===i?void 0:i.toString().trim());case"BeginsWith":return!(!e&&""===c[0])&&(Ms(e)&&(null===(o=e.evaluated.value)||void 0===o?void 0:o.toString().startsWith(c[0].toString())));case"EndsWith":return!(!e&&""===c[0])&&(Ms(e)&&(null===(n=e.evaluated.value)||void 0===n?void 0:n.toString().endsWith(c[0].toString())));case"Between":return Ms(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1];case"NotBetween":return!(Ms(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1]);case"ContainsText":return Ms(e)&&(null===(r=e.evaluated.value)||void 0===r?void 0:r.toString().indexOf(c[0].toString()))>-1;case"NotContains":return!Ms(e)||!e.evaluated.value||-1==(null===(l=e.evaluated.value)||void 0===l?void 0:l.toString().indexOf(c[0].toString()));case"GreaterThan":return Ms(e)&&e.evaluated.value>c[0];case"GreaterThanOrEqual":return Ms(e)&&e.evaluated.value>=c[0];case"LessThan":return Ms(e)&&e.evaluated.value<c[0];case"LessThanOrEqual":return Ms(e)&&e.evaluated.value<=c[0];case"NotEqual":return!(!Ms(e)&&""===c[0])&&(Ms(e)&&e.evaluated.value!==c[0]);case"Equal":return!e&&""===c[0]||Ms(e)&&e.evaluated.value===c[0];default:console.warn(a("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch(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 s=this.getters.getActiveSheetId(),i=this.getters.getRulesByCell(s,e.originCol,e.originRow);for(const t of i)this.adaptRules(s,t,[os(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation);break;case"DUPLICATE_SHEET":case"CREATE_SHEET":case"DELETE_SHEET":case"ADD_CONDITIONAL_FORMAT":case"REMOVE_CONDITIONAL_FORMAT":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":case"DELETE_CELL":case"INSERT_CELL":this.isStale=!0}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getConditionalStyle(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedStyles[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}getConditionalIcon(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedIcons[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const s=this.computedStyles[t];for(let i of this.getters.getConditionalFormats(t))switch(i.rule.type){case"ColorScaleRule":for(let e of i.ranges)this.applyColorScale(e,i.rule);break;case"IconSetRule":for(let e of i.ranges)this.applyIcon(e,i.rule);break;default:for(let o of i.ranges){const n=Fs(o);for(let o=n.top;o<=n.bottom;o++)for(let r=n.left;r<=n.right;r++){const n=this.rulePredicate[i.rule.type];let a=this.getters.getCell(t,r,o);n&&n(a,i.rule)&&(s[r]||(s[r]=[]),s[r][o]=Object.assign((null===(e=s[r])||void 0===e?void 0:e[o])||{},i.rule.style))}}}}parsePoint(e,t,s){switch(t.type){case"value":return this.getters.evaluateFormula(`=${s}(${e})`);case"number":return Number(t.value);case"percentage":const i=this.getters.evaluateFormula(`=min(${e})`);return i+(this.getters.evaluateFormula(`=max(${e})`)-i)*Number(t.value)/100;case"percentile":return this.getters.evaluateFormula(`=PERCENTILE(${e},${Number(t.value)/100})`);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof o?o:null;default:return null}}applyIcon(e,t){const s=this.parsePoint(e,t.lowerInflectionPoint),i=this.parsePoint(e,t.upperInflectionPoint);if(null===s||null===i||s>i)return;const o=Fs(e),n=this.getters.getActiveSheetId(),r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=o.top;e<=o.bottom;e++)for(let l=o.left;l<=o.right;l++){const o=this.getters.getCell(n,l,e);if((null==o?void 0:o.evaluated.type)!==ke.number)continue;const c=this.computeIcon(o.evaluated.value,i,t.upperInflectionPoint.operator,s,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,s,i,o,n){return"ge"===s&&e>=t||"gt"===s&&e>t?n[0]:"ge"===o&&e>=i||"gt"===o&&e>i?n[1]:n[2]}applyColorScale(e,t){var s;const i=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,n=this.parsePoint(e,t.maximum,"max");if(null===i||null===n||i>=n||o&&(i>=o||o>=n))return;const r=Fs(e),a=this.getters.getActiveSheetId(),l=this.computedStyles[a],c=[];t.midpoint&&o?(c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.midpoint.color,t.maximum.color)})):c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,n,t.minimum.color,t.maximum.color)});for(let e=r.top;e<=r.bottom;e++)for(let t=r.left;t<=r.right;t++){const r=this.getters.getCell(a,t,e);if((null==r?void 0:r.evaluated.type)===ke.number){const a=gs(r.evaluated.value,i,n);let h;h=2===c.length&&o?a<=o?this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(a,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(s=l[t])||void 0===s?void 0:s[e])||{},l[t][e].fillColor="#"+Yt(h)}}}computeColorDiffUnits(e,t,s,i){const o=t-e;return[((s>>16)%256-(i>>16)%256)/o,((s>>8)%256-(i>>8)%256)/o,(s%256-i%256)/o]}colorCell(e,t,s,i){const[o,n,r]=i;return Math.round((s>>16)%256-o*(e-t))<<16|Math.round((s>>8)%256-n*(e-t))<<8|Math.round(s%256-r*(e-t))}adaptRules(e,t,s,i){if(0===s.length&&0===i.length)return;const o=this.getters.getConditionalFormats(e),n=o.findIndex((e=>e.id===t.id));let r=[];n>-1&&(r=o[n].ranges),r=r.concat(s);const a=Zs(r,i);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},target:a.map(Fs),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,s){const i=os(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let n of o.ranges)if(zs(e.col,e.row,Fs(n))){const n=o,r=[];if("CUT"===s&&r.push(os(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,n,[i],r);else{this.adaptRules(e.sheetId,n,[],r);const s=this.getCFToCopyTo(t.sheetId,n);this.adaptRules(t.sheetId,s,[i],[])}}}getCFToCopyTo(e,t){const s=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&_s(e.rule,t.rule)));return s||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}Fh.getters=["getConditionalStyle","getConditionalIcon"],Fh.modes=["normal"];var $h;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}($h||($h={}));class Dh extends Ch{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1},this.toSearch=""}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell($h.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell($h.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith,e.replaceOptions);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith,e.replaceOptions);break;case"ACTIVATE_SHEET":case"REFRESH_SEARCH":this.refreshSearch()}}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($h.current)}updateRegex(){let e=ds(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),s=[];if(this.toSearch)for(const e of Object.values(t))if(e&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas&&e.isFormula()?e.content:String(e.evaluated.value))){const t=this.getters.getCellPosition(e.id),i={col:t.col,row:t.row,selected:!1};s.push(i)}return s.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 s;s=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,s=(s%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===s||(this.selectedMatchIndex=s,this.dispatch("SELECT_CELL",{col:t[s].col,row:t[s].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},this.replaceOptions={modifyFormulas:!1}}replace(e,t){if(this.replaceOptions=t,null===this.selectedMatchIndex||!this.currentSearchRegex)return;const s=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),o=this.getters.getCell(i,s.col,s.row),n=this.toReplace(o,i);if(o&&n){const t=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),i=n.toString().replace(t,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:s.col,row:s.row,content:i}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell($h.current)}else this.selectNextCell($h.next)}replaceAll(e,t){const s=this.searchMatches.length;for(let i=0;i<s;i++)this.replace(e,t)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.replaceOptions.modifyFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t,viewport:s}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge(i,e.col,e.row),n=o?o.left:e.col,r=o?o.right:e.col,a=o?o.top:e.row,l=o?o.bottom:e.row,[c,h,d,u]=this.getters.getRect({top:a,left:n,right:r,bottom:l},s);d>0&&u>0&&(t.fillStyle="#8B008B33",t.fillRect(c,h,d,u),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(c,h,d,u)))}}}Dh.layers=[3],Dh.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Uh extends Ch{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,s){const i=this.searchNumberFormat(e,t);if(void 0!==i){const o=this.changeDecimalFormat(i,s);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var s;for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++){const i=this.getters.getCell(e,o,t);if((null==i?void 0:i.evaluated.type)===ke.number&&!(null===(s=i.format)||void 0===s?void 0:s.match(A)))return i.format||this.setDefaultNumberFormat(i.evaluated.value)}}setDefaultNumberFormat(e){const t=e.toString().split(".");return 1===t.length?"0":"0."+Array(t[1].length+1).join("0")}changeDecimalFormat(e,t){const s=Math.sign(t),i=e.split(";");let o=[];for(let e of i){const t=e.indexOf("."),i=e.toUpperCase().indexOf("E");let n;const r=i>-1?e.slice(0,i):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?s>0?n=a<ne?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(n=e.slice(0,l)+e.slice(l+1),1===a&&(n=n.slice(0,t)+n.slice(t+1))):n=e:n=e,o.push(n)}return o.join(";")}}Uh.modes=["normal"];class Ph extends Ch{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){if(0===e.length)return[];const t=this.getters.getActiveSheetId(),s=[];for(let[i,o]of e){const{xc:e,sheetName:n}=ts(i),r=n?this.getters.getSheetIdByName(n):t;if(r){let i=Fs(e);const{height:n,width:a}=qs(i);i=n*a==1?this.getters.expandZone(t,Fs(e)):i,s.push({zone:i,color:o,sheet:r})}}return s.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getSheet(e.sheet).rows.length&&e.zone.right<this.getters.getSheet(e.sheet).cols.length))}drawGrid(e){const{ctx:t,viewport:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;for(let e of this.getHighlights().filter(((e,t)=>this.getHighlights().findIndex((t=>Vs(t.zone,e.zone)&&t.sheet===o))===t))){const[i,o,r,a]=this.getters.getRect(e.zone,s);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,r-n,a-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,r-2*n,a-2*n))}}}function Bh(e,t){return e.isFormula()&&t?"left":e.defaultAlign}function Vh(e,t){let s=0,i=e.length-1;for(;s<=i;){const o=Math.floor((s+i)/2),n=e[o];if(t<n.start)i=o-1;else if(t>n.end)s=o+1;else{if(!n.isHidden)return o;s+=1}}return-1}Ph.modes=["normal"],Ph.layers=[1],Ph.getters=["getHighlights"];class Hh extends Ch{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t,s){if(e<m)return-1;const i=(s||this.getters.getActiveSheet()).cols;return Vh(i,e-m+i[t].start+1)}getRowIndex(e,t,s){if(e<f)return-1;const i=(s||this.getters.getActiveSheet()).rows;return Vh(i,e-f+i[t].start+1)}getRect(e,t){const{left:s,top:i,right:o,bottom:n}=e;let{offsetY:r,offsetX:a}=t;a-=m,r-=f;const{cols:l,rows:c}=this.getters.getActiveSheet(),h=Math.max(l[s].start-a,m),d=l[o].end-a-h,u=Math.max(c[i].start-r,f);return[h,u,d,c[n].end-r-u]}isVisibleInViewport(e,t,s){const{right:i,left:o,top:n,bottom:r}=s;return t<=r&&t>=n&&e>=o&&e<=i}getEdgeScrollCol(e){let t=!1,s=0,i=0;const{width:o}=this.getters.getViewportDimension(),{width:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{left:r,offsetX:a}=this.getters.getActiveSnappedViewport();return e<m&&r>0?(t=!0,s=-1,i=ls(m-e)):e>o&&a<n-o&&(t=!0,s=1,i=ls(e-o)),{canEdgeScroll:t,direction:s,delay:i}}getEdgeScrollRow(e){let t=!1,s=0,i=0;const{height:o}=this.getters.getViewportDimension(),{height:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{top:r,offsetY:a}=this.getters.getActiveSnappedViewport();return e<f&&r>0?(t=!0,s=-1,i=ls(f-e)):e>o&&a<n-o&&(t=!0,s=1,i=ls(e-o)),{canEdgeScroll:t,direction:s,delay:i}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e);break;case 7:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,top:r,left:a,bottom:l,right:c}=s;const{width:h,height:d}=this.getters.getViewportDimension(),{cols:u,rows:p,id:g}=this.getters.getActiveSheet();if(t.fillStyle="white",t.fillRect(0,0,h,d),o-=m,n-=f,!this.getters.getGridLinesVisibility(g))return;t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();const v=Math.min(d,p[l].end-n);for(let e=a;e<=c;e++){if(u[e].isHidden)continue;const s=u[e].end-o;t.moveTo(s,0),t.lineTo(s,v)}const E=Math.min(h,u[c].end-o);for(let e=r;e<=l;e++){if(p[e].isHidden)continue;const s=p[e].end-n;t.moveTo(0,s),t.lineTo(E,s)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:s}=e;t.lineWidth=.3*s;const i=.1*s;t.strokeStyle="#111";const o=this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());for(let e of this.boxes){let s=e.style;s&&s.fillColor&&"#ffffff"!==s.fillColor&&(t.fillStyle=s.fillColor,t.fillRect(e.x,e.y,e.width,e.height),o&&t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)),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())}}drawBorders(e){const{ctx:t,thinLineWidth:s}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:s,y:o,width:n,height:r}=e;t.left&&i(t.left,s,o,s,o+r),t.top&&i(t.top,s,o,s+n,o),t.right&&i(t.right,s+n,o,s+n,o+r),t.bottom&&i(t.bottom,s,o+r,s+n,o+r)}}function i([e,i],o,n,r,a){t.strokeStyle=i,t.lineWidth=("thin"===e?2:3)*s,t.beginPath(),t.moveTo(o,n),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:s}=e;let i;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const o=e.style||{},n=e.align,r=o.italic?"italic ":"",a=o.bold?"bold":T,l=o.fontSize||x,c=hs[l],h=`${r}${a} ${c}px ${R}`;let d;h!==i&&(i=h,t.font=h),t.fillStyle=o.textColor||"#000";let u=e.y+e.height/2+1;d="left"===n?e.x+(e.image?e.image.size+2*I:4):"right"===n?e.x+e.width-4:e.x+e.width/2,t.textAlign=n,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(d),Math.round(u)),(o.strikethrough||o.underline)&&("right"===n?d-=e.textWidth:"center"===n&&(d-=e.textWidth/2),o.strikethrough&&t.fillRect(d,u,e.textWidth,2.6*s),o.underline&&(u=e.y+e.height/2+1+c/2,t.fillRect(d,u,e.textWidth,1.3*s))),e.clipRect&&t.restore()}}async drawIcon(e){const{ctx:t}=e;for(let e of this.boxes)if(e.image){let s=e.x,i=e.y;const o=e.image.image,n=e.image.size,r=(e.height-n)/2;e.image.clipIcon&&(t.save(),t.beginPath(),t.rect(...e.image.clipIcon),t.clip()),t.drawImage(o,s+I,i+r,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,left:r,top:a,right:l,bottom:p}=s;const{width:g,height:v}=this.getters.getViewportDimension();o-=m,n-=f;const E=this.getters.getSelectedZones(),{cols:S,rows:b}=this.getters.getActiveSheet(),C=this.getters.getActiveCols(),I=this.getters.getActiveRows();t.fillStyle=c,t.font=`400 11px ${R}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333",t.fillRect(0,0,g,f),t.fillRect(0,0,m,v),t.fillStyle=h;for(let e of E){const s=Math.max(m,S[e.left].start-o),i=Math.max(m,S[e.right].end-o),r=Math.max(f,b[e.top].start-n),a=Math.max(f,b[e.bottom].end-n);t.fillStyle=C.has(e.left)?d:h,t.fillRect(s,0,i-s,f),t.fillStyle=I.has(e.top)?d:h,t.fillRect(0,r,m,a-r)}t.beginPath(),t.moveTo(m,0),t.lineTo(m,v),t.moveTo(0,f),t.lineTo(g,f),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=r;e<=l;e++){const s=S[e];s.isHidden||(t.fillStyle=C.has(e)?"#fff":u,t.fillText(s.name,(s.start+s.end)/2-o,13),t.moveTo(s.end-o,0),t.lineTo(s.end-o,f))}for(let e=a;e<=p;e++){const s=b[e];s.isHidden||(t.fillStyle=I.has(e)?"#fff":u,t.fillText(s.name,24,(s.start+s.end)/2-n),t.moveTo(0,s.end-n),t.lineTo(m,s.end-n))}t.stroke()}hasContent(e,t){const s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);return i&&!i.isEmpty()||this.getters.isInMerge(s,e,t)}getGridBoxes(e){const{viewport:t}=e;let{right:s,left:i,top:o,bottom:n,offsetX:r,offsetY:a}=t;r-=m,a-=f;const l=this.getters.shouldShowFormulas(),c=[],{cols:h,rows:d,id:u}=this.getters.getActiveSheet();for(let e=o;e<=n;e++){const t=d[e];if(!t.isHidden)for(let o=i;o<=s;o++){const n=h[o];if(n.isHidden)continue;let d=t.cells[o];const p=this.getters.getCellBorder(u,o,e),g=this.getters.getConditionalStyle(o,e),f=this.getters.getConditionalIcon(o,e);if(!this.getters.isInMerge(u,o,e))if(d){const u=this.getters.getCellText(d,l);let m=this.getters.getCellStyle(d);g&&(m=Object.assign({},m,g));let v=u?m&&m.align||Bh(d,l):void 0,E=null,S=null;const b=this.getters.getTextWidth(d),C=m.fontSize||x,y=hs[C],w=f?y+2*I:0,T=w+b>h[o].size||hs[C]>t.size;if(T&&d.evaluated.type===ke.number&&(v="center"!==v?"left":v),f){const e=n.end-n.start;E=[n.start-r+w,t.start-a,Math.max(0,e-w),t.size],S=[n.start-r,t.start-a,Math.min(w,e),t.size]}else if(T){let l,c;switch(v){case"left":for(l=o;l<s&&!this.hasContent(l+1,e);)l++;c=h[l].end-n.start,(c<b||hs[C]>t.size)&&(E=[n.start-r,t.start-a,c,t.size]);break;case"right":for(l=o;l>i&&!this.hasContent(l-1,e);)l--;c=n.end-h[l].start,(c<b||hs[C]>t.size)&&(E=[h[l].start-r,t.start-a,c,t.size]);break;case"center":let d=o;for(;d>i&&!this.hasContent(d-1,e);)d--;let u=o;for(;u<s&&!this.hasContent(u+1,e);)u++;const p=Math.min(d,o),g=Math.max(u,o);c=h[g].end-h[p].start,(c<b||p===o||g===o||hs[C]>t.size)&&(E=[h[p].start-r,t.start-a,c,t.size])}}c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:u,textWidth:b,border:p,style:m,align:v,clipRect:E,error:d.evaluated.type===ke.error?d.evaluated.error:void 0,image:f?{type:"icon",size:y,clipIcon:S,image:Zl[f].img}:void 0})}else c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:"",textWidth:0,border:p,style:g||null,align:void 0,clipRect:null,error:void 0})}}const p=this.getters.getActiveSheetId();for(let e of this.getters.getMerges(p))if(!this.getters.isMergeHidden(p,e)&&Hs(e,t)){const t=this.getters.getCell(p,e.left,e.top),s=this.getters.getCellBorder(p,e.left,e.top),i=this.getters.getCellBorder(p,e.right,e.bottom),o=h[e.right].end-h[e.left].start;let n,u,g,f,m;if(g=t?this.getters.getCellStyle(t):null,t||i||s){n=t?this.getters.getCellText(t,l):"",u=t?this.getters.getTextWidth(t):null;const o=this.getters.getConditionalStyle(e.topLeft.col,e.topLeft.row);o&&(g=Object.assign({},g,o)),f=n?g&&g.align||Bh(t,l):null,m={bottom:i?i.bottom:null,left:s?s.left:null,right:i?i.right:null,top:s?s.top:null}}g=g||{},g.fillColor&&"#ffffff"!==g.fillColor||(g=Object.create(g),g.fillColor="#fff");const v=h[e.left].start-r,E=d[e.top].start-a,S=d[e.bottom].end-d[e.top].start,b=this.getters.getConditionalIcon(e.left,e.top),C=g.fontSize||x,y=hs[C],w=b?2*I+y:0,T=w+u;f=n&&(null==t?void 0:t.evaluated.type)===ke.number&&T>o&&"center"!==f?"left":f;const R=b?[v+w,E,Math.max(0,o-w),S]:[v,E,o,S],L=b?[v,E,Math.min(w,o),S]:null;c.push({x:v,y:E,width:o,height:S,text:n,textWidth:u,border:m,style:g,align:f,clipRect:R,error:t&&t.evaluated.type===ke.error?t.evaluated.error:void 0,image:b?{type:"icon",clipIcon:L,size:y,image:Zl[b].img}:void 0})}return c}}Hh.layers=[0,7],Hh.getters=["getColIndex","getRowIndex","getRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow"],Hh.modes=["normal"];const zh=new ni;class Zh extends Ch{constructor(){super(...arguments),this.inputs={},this.activeSheets={},this.inputHasSingleRange={},this.focusedInputId=null,this.focusedRange=null,this.willAddNewRange=!1}allowDispatch(e){switch(e.type){case"FOCUS_RANGE":const t=this.getIndex(e.id,e.rangeId);if(this.focusedInputId===e.id&&this.focusedRange===t)return 24;break;case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange[e.id]&&1===this.inputs[e.id].length)return 25}return 0}handle(e){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],delete this.activeSheets[e.id],delete this.inputHasSingleRange[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(e.id,this.getIndex(e.id,e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.id,e.rangeId);if(null!==t){const s=e.id;this.focusedInputId===s&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:s,rangeId:this.inputs[s][t].id});const i=e.value.split(",").map((e=>e.trim()));this.setRange(s,t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(e.id,this.inputs[e.id].length,[""]),this.focusLast(e.id);break;case"REMOVE_RANGE":const t=this.getIndex(e.id,e.rangeId);null!==t&&this.removeRange(e.id,t);break;case"SELECT_CELL":case"SET_SELECTION":if(!this.focusedInputId)break;const s=this.getSelectionInputValue(this.focusedInputId),i=(this.inputHasSingleRange[this.focusedInputId]?[this.getters.getSelectedZone()]:this.getters.getSelectedZones()).map(Ds).filter((e=>!s.includes(e))),o=this.activeSheets[this.focusedInputId],n=this.getters.getActiveSheetId(),r=this.getters.getSheetName(n);this.add(i.map((e=>n===o?e:`${ps(r)}!${e}`)));break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInputId,this.focusedRange];null===e||null===t||this.inputHasSingleRange[e]||(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,s)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.focusedRange&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.focusedRange===s}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:s}=ts(e);return null!==t.match(es)&&(!s||void 0!==this.getters.getSheetIdByName(s))}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].map((e=>this.inputToHighlights(this.focusedInputId,e))).flat():[]}initInput(e,t,s=!1){this.inputs[e]=[],this.insertNewRange(e,0,t),this.activeSheets[e]=this.getters.getActiveSheetId(),this.inputHasSingleRange[e]=s,0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){this.focusedInputId=e,this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}unfocus(){this.focusedInputId=null,this.focusedRange=null}add(e){if(null===this.focusedInputId||null===this.focusedRange||this.getters.isSelectingForComposer()||0===e.length)return;if(this.getters.getSelectionMode()===xh.expanding&&this.willAddNewRange){const t=this.focusedInputId;this.insertNewRange(t,this.inputs[t].length,e),this.focusLast(this.focusedInputId),this.willAddNewRange=!1}else this.setRange(this.focusedInputId,this.focusedRange,e)}setContent(e,t,s){this.inputs[e][t]={...this.inputs[e][t],id:zh.uuidv4(),xc:s}}insertNewRange(e,t,s){this.inputs[e].splice(t,0,...s.map(((t,s)=>({xc:t,id:(this.inputs[e].length+s+1).toString(),color:Kt()}))))}setRange(e,t,s){const[,...i]=s;this.setContent(e,t,s[0]),this.insertNewRange(e,t+1,i),i.length&&this.focus(e,t+i.length)}removeRange(e,t){this.inputs[e].splice(t,1),this.focusedInputId===e&&null!==this.focusedRange&&this.focusLast(e)}inputToHighlights(e,{xc:t,color:s}){const i=this.cleanInputs([t]).filter((e=>this.isRangeValid(e))).filter((t=>this.shouldBeHighlighted(this.activeSheets[e],t)));if(0===i.length)return[];const[o,...n]=i,r=[[o,s||Kt()]];for(const e of n)r.push([e,Kt()]);return r}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:s}=ts(t),i=this.getters.getSheetIdByName(s),o=this.getters.getActiveSheet().id;return this.isRangeValid(t)&&(i===o||void 0===i&&o===e)}getIndex(e,t){const s=this.inputs[e].findIndex((e=>e.id===t));return s>=0?s:null}}Zh.modes=["normal"],Zh.layers=[1],Zh.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Gh{constructor(){this.bus=new i.core.EventBus}on(e,t,s){this.bus.on(e,t,s)}trigger(e,t){this.bus.trigger(e,t)}off(e,t){this.bus.off(e,t)}clear(){this.bus.clear()}}function Wh(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?function(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<=r&&e[i]>=r&&n--;if(!(o>n))return{...e,[t]:o,[i]:n}}(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?function(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom",l="before"===i?e[a]>r:e[a]>=r;return e[t]<=r&&l?Xs(e,n,"RESIZE",o):r<e[t]?Xs(e,n,"MOVE",o):{...e}}(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function qh(e,t){const s=e.definition;let i,o;return s.labelRange&&(i=Wh(Fs(s.labelRange),t)),s.dataSets&&(o=s.dataSets.map(Fs).map((e=>Wh(e,t))).filter(Ms).map(Ds)),{...e,definition:{...s,dataSets:o,labelRange:i?Ds(i):void 0}}}ml.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],qh),ml.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],qh),ml.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),ml.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var s;if(e.name===t.name)return{...e,name:(null===(s=e.name)||void 0===s?void 0:s.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),ml.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const s=[];for(const i of e.target)for(const e of t.target)Hs(i,e)||s.push({...i});if(s.length)return{...e,target:s};return}));const jh=[{match:function(e){return"sheetId"in e},fn:function(e,t){const s="DELETE_SHEET"===t.type&&t.sheetId;if(e.sheetId===s)return"IGNORE_COMMAND";if("CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId)return e;return"SKIP_TRANSFORMATION"}},{match:function(e){return"target"in e},fn:function(e,t){const s=[];for(const i of e.target){const e=Wh(i,t);e&&s.push(e)}if(!s.length)return"IGNORE_COMMAND";return{...e,target:s}}},{match:function(e){return"col"in e&&"row"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const s="COL"===t.dimension?"col":"row";let i=e[s];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(i))return"IGNORE_COMMAND";for(let t of e)i>=t&&i--}"ADD_COLUMNS_ROWS"===t.type&&(i>t.base||i===t.base&&"before"===t.position)&&(i+=t.quantity);return{...e,[s]:i}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const s of t.target){if(!(e.col===s.left&&e.row===s.top)&&zs(e.col,e.row,s))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const s="ADD_COLUMNS_ROWS"===e.type,i=s?"base":"elements";let o=s?[e[i]]:e[i];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const s=t.elements.sort(((e,t)=>t-e));for(let t of s)e>t&&e--;return e})).filter(Ms)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((s=>s>e?s+t.quantity:s))}if(o.length){let t=o;return s&&(t=o[0]),{...e,[i]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}}];function Yh(e,t){const s=ml.getTransformation(e.type,t.type);return s?s(e,t):function(e,t){for(const{match:s,fn:i}of jh)if(s(e)){const s=i(e,t);if("SKIP_TRANSFORMATION"===s)continue;if("IGNORE_COMMAND"===s)return;return s}return e}(e,t)}function Xh(e,t){let s=[...e];for(const e of t)s=s.map((t=>Yh(t,e))).filter(Ms);return s}class Kh{constructor(e,t,s,i){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...s],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Qh extends Error{}class Jh extends Gh{constructor(e,t,s=O){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=s,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new ni,this.debouncedMove=i.utils.debounce(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const s=new Kh(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(s.id,s),this.trigger("new-local-state-update",{id:s.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:s.id,clientId:s.clientId,commands:s.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 Qh("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Ms))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const s=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==s?void 0:s.col)===e.col&&s.row===e.row&&s.sheetId===e.sheetId)return;const i=s?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:i,version:1,client:{...o,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:s}=e,i=new Kh(e.nextRevisionId,t,s);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:Xh(s,t)})}break;case"SNAPSHOT_CREATED":{const t=new Kh(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){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 ed=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class td extends Ch{constructor(){super(...arguments),this.availableColors=new Set(ed),this.colors={}}isPositionValid(e){const t=this.getters.getSheet(e.sheetId);return e.row<t.rows.length&&e.col<t.cols.length}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(ed));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 Qh)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const s of this.getters.getConnectedClients())if(s.id!==this.getters.getClient().id&&s.position&&s.position.sheetId===e&&this.isPositionValid(s.position)){const e=s.position;this.colors[s.id]||(this.colors[s.id]=this.chooseNewColor());const i=this.colors[s.id];t.push({...s,position:e,color:i})}return t}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:r}=e.position,a=this.getters.expandZone(o,{top:n,bottom:n,left:r,right:r}),[l,c,h,d]=this.getters.getRect(a,t);if(h<=0||d<=0)continue;const u=e.color,p=`${u}10`;s.fillStyle=p,s.lineWidth=4*i,s.strokeStyle=u,s.globalCompositeOperation="multiply",s.fillRect(l,c,h,d),s.globalCompositeOperation="source-over",s.strokeRect(l,c,h,d),s.font=`bold ${x+1}px ${R}`}}}td.getters=["getClientsToDisplay"],td.layers=[5],td.modes=["normal"];class sd extends Ch{allowDispatch(e){if("SORT_CELLS"===e.type){if(!zs(e.anchor[0],e.anchor[1],e.zone))throw new Error(a("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)e.interactive?this.interactiveSortSelection(e.sheetId,e.anchor,e.zone,e.sortDirection):this.sortZone(e.sheetId,e.anchor,e.zone,e.sortDirection)}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let s=t.top;s<=t.bottom;s++)for(let i=t.left;i<=t.right;i++)if(!this.getters.isInMerge(e,i,s))return 48;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const s=this.getters.getMerges(e).filter((e=>Hs(e,t))),i=qs(s[0]);let[o,n]=[i.width,i.height];return s.every((e=>{let[t,s]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&s===n}))?0:48}interactiveSortSelection(e,t,s,i){let o=Pe.Success,n=s.right>s.left;if(this.getters.doesIntersectMerge(e,s)){let t;n=!1;for(let i=s.top;i<=s.bottom;i++){t=[];for(let o=s.left;o<=s.right;o++){let s=this.getters.getMerge(e,o,i);s&&!t.includes(s.id.toString())&&t.push(s.id.toString())}if(t.length>=2){n=!0;break}}}if(n)o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i});else{const n=this.getContiguousZone(e,s);Vs(n,s)?o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i}):this.ui.askConfirmation(a("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>{s=n,o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}),(()=>{o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}))}o.isCancelledBecause(48)&&(this.dispatch("SET_SELECTION",{anchor:t,zones:[s],anchorZone:s}),this.ui.notifyUser(a("Cannot sort. To sort, select only cells or only merges that have the same size.")))}expand(e,t){const{left:s,right:i,top:o,bottom:n}=this.getters.expandZone(e.id,t);return{left:Math.max(0,s),right:Math.min(e.cols.length-1,i),top:Math.max(0,o),bottom:Math.min(e.rows.length-1,n)}}checkExpandedValues(e,t){const s=this.expand(e,t),i=e.id;let o,n=[];if(this.getters.doesIntersectMerge(i,s)){const{left:e,right:t,top:r,bottom:a}=s;for(let s=e;s<=t;s++)for(let e=r;e<=a;e++){const[t,r]=this.getters.getMainCell(i,s,e);o=this.getters.getCell(i,t,r),n.push((null==o?void 0:o.formattedValue)||"")}}else{const t=Ws(s,e,(e=>e.formattedValue),"");n=t.flat()}return n.some((e=>""!==e))}getContiguousZone(e,t){let s,{top:i,bottom:o,left:n,right:r}=t;const a=this.getters.getSheet(e);let l=!1;for(;!l;)l=!0,i>0&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:i-1,bottom:i-1}),s&&(l=!1,i--)),n>0&&(s=this.checkExpandedValues(a,{left:n-1,right:n-1,top:i-1,bottom:o+1}),s&&(l=!1,n--)),r<a.cols.length-1&&(s=this.checkExpandedValues(a,{left:r+1,right:r+1,top:i-1,bottom:o+1}),s&&(l=!1,r++)),o<a.rows.length-1&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:o+1,bottom:o+1}),s&&(l=!1,o++));return{left:n,right:r,top:i,bottom:o}}hasHeader(e,t,s,i){const{left:o,right:n,top:r,bottom:a}=t;if(a-r+1==1)return!1;let l=Ws({left:o,right:n,top:r,bottom:r+2*i-1},e,(e=>e.evaluated.type),ke.empty,s,i);return l[0][0]===ke.empty&&(l=l.slice(1)),!l.some((e=>e[0]===ke.empty))&&!!l.some((e=>e[1]!==ke.empty&&e[0]!==e[1]))}sortCellsList(e,t){const s=e.map(((e,t)=>({index:t,val:e}))),i=s.filter((e=>!(null==e.val||""===e.val.evaluated.value))),o=s.filter((e=>null==e.val||""===e.val.evaluated.value)),n="descending"===t?-1:1,r=[ke.number,ke.error,ke.text,ke.boolean];return i.map((e=>{return{index:e.index,val:(t=e.val,{type:t.evaluated.type,value:t.evaluated.value})};var t})).sort(((e,t)=>{let s=r.indexOf(e.val.type)-r.indexOf(t.val.type);return 0===s&&(s=e.val.type===ke.text||e.val.type===ke.error?e.val.value.localeCompare(t.val.value):e.val.value-t.val.value),n*s})).concat(o)}sortZone(e,t,s,i){let o=1,n=1,r=t[0],a=Object.assign({},s);if(this.getters.doesIntersectMerge(e,a)){const[s,i]=t,a=this.getters.getMerge(e,s,i);o=a.right-a.left+1,n=a.bottom-a.top+1,r=a.topLeft.col}const l=this.getters.getSheet(e);this.hasHeader(l,a,o,n)&&(a.top+=n);const c=Ws(a,l,(e=>e),void 0,o,n),h=c[r-a.left],d=this.sortCellsList(h,i).map((e=>e.index)),[u,p]=[c.length,c[0].length];for(let t=0;t<u;t++)for(let s=0;s<p;s++){let i=c[t][d[s]],r=a.left+t*o,l=a.top+s*n,h={sheetId:e,col:r,row:l,content:"",value:""};if(i){let t=i.content;if(i.isFormula()){const s=l-this.getters.getCellPosition(i.id).row,o=this.getters.createAdaptedRanges(i.dependencies.references,0,s,e);t=this.getters.buildFormulaContent(e,i.normalizedText,{...i.dependencies,references:o})}h.style=i.style,h.content=t,h.format=i.format,h.value=i.evaluated.value}this.dispatch("UPDATE_CELL",h)}}}sd.getters=["getContiguousZone"];class id extends Ch{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}id.modes=["normal"],id.getters=["shouldShowFormulas"];class od extends Ch{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":case"DELETE_SHEET_CONFIRMATION":try{this.getters.getSheet(e.sheetId);break}catch(e){return 23}}return 0}handle(e){switch(e.type){case"RENAME_SHEET":e.interactive&&this.interactiveRenameSheet(e.sheetId,a("Rename Sheet"));break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheetId);break;case"ADD_MERGE":e.interactive&&this.interactiveMerge(e.sheetId,e.target);break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const s=this.getColMaxWidth(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:s+6,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const s=this.getRowMaxHeight(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:s+6,sheetId:e.sheetId})}}}getCellWidth(e){let t=this.getTextWidth(e);const s=this.getters.getCellPosition(e.id);return this.getters.getConditionalIcon(s.col,s.row)&&(t+=function(e,t){const s=t.fontSize||x;return hs[s]+2*I}(this.ctx,this.getters.getCellStyle(e))),t}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas());return fs(this.ctx,t,this.getters.getCellStyle(e))}getCellHeight(e){const t=this.getters.getCellStyle(e).fontSize||x;return hs[t]}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===ke.error)?e.content:e.formattedValue}getColMaxWidth(e,t){const s=this.getters.getColCells(e,t).map((e=>this.getCellWidth(e)));return Math.max(0,Os(s))}getRowMaxHeight(e,t){const s=this.getters.getSheet(e),i=Object.values(s.rows[t].cells).map((e=>this.getCellHeight(e)));return Math.max(0,Os(i))}interactiveRenameSheet(e,t){const s=this.getters.getSheetName(e);this.ui.editText(t,s,(t=>{if(!t)return;const s=this.dispatch("RENAME_SHEET",{sheetId:e,name:t}),i=this.getters.getSheetName(e);s.isSuccessful||i===t||this.interactiveRenameSheet(e,a("Please enter a valid sheet name"))}))}interactiveDeleteSheet(e){this.ui.askConfirmation(a("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheetId:e})}))}interactiveMerge(e,t){const s=this.dispatch("ADD_MERGE",{sheetId:e,target:t});s.isSuccessful||s.isCancelledBecause(3)&&this.ui.askConfirmation(a("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheetId:e,target:t,force:!0})}))}}od.getters=["getCellWidth","getCellHeight","getTextWidth","getCellText"];class nd extends Ch{constructor(){super(...arguments),this.viewports={},this.snappedViewports={},this.updateSnap=!1,this.clientWidth=1e3,this.clientHeight=1e3}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkOffsetValidity(e.offsetX,e.offsetY);case"RESIZE_VIEWPORT":return e.width<0||e.height<0?54:0;default:return 0}}handle(e){switch(e.type){case"UNDO":case"REDO":this.cleanViewports(),this.resetViewports();break;case"RESIZE_VIEWPORT":this.cleanViewports(),this.resizeViewport(e.height,e.width);break;case"SET_VIEWPORT_OFFSET":this.setViewportOffset(e.offsetX,e.offsetY);break;case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportOffsetX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportOffsetY(e.sheetId,this.getViewport(e.sheetId));break;case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportZoneX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportZoneY(e.sheetId,this.getViewport(e.sheetId));break;case"ACTIVATE_SHEET":this.refreshViewport(e.sheetIdTo);break;case"SELECT_CELL":case"MOVE_POSITION":this.refreshViewport(this.getters.getActiveSheetId())}}finalize(){this.updateSnap&&(this.snapViewportToCell(this.getters.getActiveSheetId()),this.updateSnap=!1)}getViewportDimension(){return{width:this.clientWidth,height:this.clientHeight}}getActiveViewport(){const e=this.getters.getActiveSheetId();return this.getViewport(e)}getActiveSnappedViewport(){const e=this.getters.getActiveSheetId();return this.getSnappedViewport(e)}getGridDimension(e){const t=li(e,"cols"),s=this.clientWidth-m,i=li(e,"rows"),o=this.clientHeight-f,n=e.cols.find((e=>e.end>t.end-s))||e.cols[e.cols.length-1],r=e.rows.find((e=>e.end>i.end-o))||e.rows[e.rows.length-1];return{width:t.end+Math.max(E,Math.min(n.size,s-t.size)),height:i.end+Math.max(S+5,Math.min(r.size,o-i.size))}}getMaximumViewportOffset(e){const{width:t,height:s}=this.getters.getGridDimension(e);return{maxOffsetX:Math.max(0,t-this.clientWidth+m+1),maxOffsetY:Math.max(0,s-this.clientHeight+f+1)}}checkOffsetValidity(e,t){const s=this.getters.getActiveSheet(),{maxOffsetX:i,maxOffsetY:o}=this.getMaximumViewportOffset(s);return e<0||t<0||t>o||e>i?53:0}getSnappedViewport(e){return this.snapViewportToCell(e),this.snappedViewports[e]}getViewport(e){return this.viewports[e]?this.viewports[e]:this.generateViewportState(e)}cleanViewports(){const e=this.getters.getVisibleSheets();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetViewports(){for(let[e,t]of Object.entries(this.viewports))this.adjustViewportOffsetX(e,t),this.adjustViewportOffsetY(e,t),this.adjustViewportsPosition(e)}adjustViewportOffsetX(e,t){const{offsetX:s}=t,{width:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientWidth-m+s>i){const e=this.clientWidth-m+s-i;t.offsetX=Math.max(0,s-e)}this.adjustViewportZoneX(e,t)}adjustViewportOffsetY(e,t){const{offsetY:s}=t,{height:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientHeight-f+s>i){const e=this.clientHeight-f+s-i;t.offsetY=Math.max(0,s-e)}this.adjustViewportZoneY(e,t)}resizeViewport(e,t){this.clientHeight=e,this.clientWidth=t,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.adjustViewportOffsetX(e,this.viewports[e]),this.adjustViewportOffsetY(e,this.viewports[e])}setViewportOffset(e,t){const s=this.getters.getActiveSheetId();this.getActiveViewport(),this.viewports[s].offsetX=e,this.viewports[s].offsetY=t,this.adjustViewportZone(s,this.viewports[s])}generateViewportState(e){return this.viewports[e]={left:0,right:0,top:0,bottom:0,offsetX:0,offsetY:0},this.viewports[e]}refreshViewport(e){const t=this.getViewport(e);this.adjustViewportZone(e,t),this.adjustViewportsPosition(e)}adjustViewportZone(e,t){this.adjustViewportZoneX(e,t),this.adjustViewportZoneY(e,t)}adjustViewportZoneX(e,t){const s=this.getters.getSheet(e),i=s.cols;t.left=this.getters.getColIndex(t.offsetX+m,0,s);const o=this.clientWidth+t.offsetX-m;t.right=i.length-1;for(let e=t.left;e<i.length;e++)if(o<i[e].end){t.right=e;break}this.updateSnap=!0}adjustViewportZoneY(e,t){const s=this.getters.getSheet(e),i=s.rows;t.top=this.getters.getRowIndex(t.offsetY+f,0,s);const o=this.clientHeight+t.offsetY-f;t.bottom=i.length-1;for(let e=t.top;e<i.length;e++)if(o<i[e].end){t.bottom=e;break}this.updateSnap=!0}adjustViewportsPosition(e,t){const s=this.getters.getSheet(e),{cols:i,rows:o}=s,n=this.getSnappedViewport(e);t=t||this.getters.getSheetPosition(e);const[r,a]=ri(s,...this.getters.getMainCell(e,t[0],t[1]));for(;i[r].end>n.offsetX+this.clientWidth-m&&n.offsetX<i[r].start;)n.offsetX=i[n.left].end,this.adjustViewportZoneX(e,n);for(;r<n.left;){const t=i.slice(0,n.left).reverse().findIndex((e=>!e.isHidden));n.offsetX=i[n.left-1-t].start,this.adjustViewportZoneX(e,n)}for(;o[a].end>n.offsetY+this.clientHeight-f&&n.offsetY<o[a].start;)n.offsetY=o[n.top].end,this.adjustViewportZoneY(e,n);for(;a<n.top;){const t=o.slice(0,n.top).reverse().findIndex((e=>!e.isHidden));n.offsetY=o[n.top-1-t].start,this.adjustViewportZoneY(e,n)}const{top:l,left:c}=this.viewports[e];l===n.top&&c===n.left||(this.viewports[e]=n),this.updateSnap=!1}snapViewportToCell(e){const{cols:t,rows:s}=this.getters.getSheet(e),i=this.getViewport(e),o=Object.assign({},i);this.adjustViewportOffsetX(e,o),this.adjustViewportOffsetY(e,o),o.offsetX=t[o.left].start,o.offsetY=s[o.top].start,this.adjustViewportZone(e,o),this.snappedViewports[e]=o}}nd.getters=["getActiveViewport","getSnappedViewport","getActiveSnappedViewport","getViewportDimension","getGridDimension","getMaximumViewportOffset"],nd.modes=["normal"];const rd=(new Le).add("sheet",La).add("cell",Ca).add("merge",xa).add("borders",Ea).add("conditional formatting",wa).add("figures",Ta).add("chart",Ia),ad=(new Le).add("selection",Rh).add("ui_sheet",od).add("ui_options",id).add("evaluation",_h).add("evaluation_cf",Fh).add("evaluation_chart",kh).add("clipboard",Th).add("edition",Mh).add("highlight",Ph).add("selectionInput",Zh).add("viewport",nd).add("grid renderer",Hh).add("autofill",yh).add("find_and_replace",Dh).add("sort",sd).add("automatic_sum",wh).add("format",Uh).add("selection_multiuser",td);class ld{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}class cd extends i.core.EventBus{constructor(){super(...arguments),this.registry=new Le}add(e,t){this.registry.add(e,t);const s=i.utils.debounce((()=>this.trigger("data-loaded",{id:e})),0);return t.on("data-loaded",this,(()=>s())),t.loadMetadata(),this}get(e){return this.registry.get(e)}getAll(){return this.registry.getAll()}remove(e){this.get(e).off("data-loaded",this),this.registry.remove(e)}async waitForReady(){const e=[];for(const t of this.getAll())e.push(t.get());return Promise.all(e)}}class hd extends i.core.EventBus{async loadMetadata(){this.metadataPromise||(this.metadataPromise=this._fetchMetadata().then((e=>(this.metadata=e,e)))),await this.metadataPromise}async get(e){return e&&e.forceFetch&&(this.data=void 0,this.dataPromise=void 0),await this.loadMetadata(),this.dataPromise||(this.dataPromise=this._fetch(e).then((e=>(this.data=e,this.lastUpdate=Date.now(),this.trigger("data-loaded"),e)))),this.dataPromise}getSync(){return this.data}getMetadataSync(){return this.metadata}getLastUpdate(){return this.lastUpdate}}function dd(e){return Oa.get(e.type)(e)}function ud(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class pd{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const s of this.operations){if(s.id===e)return e;if(s.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const s=this.buildTransformation.with(e.data),{before:i,operation:o,after:n}=this.locateOperation(t);this.operations=[...i,o,e,...n.map((e=>e.transformed(s)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new pd(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:s}=this.locateOperation(e);this.operations=t.concat([s])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class gd{constructor(e,t){this.id=e,this.data=t}transformed(e){return new gd(this.id,e(this.data))}}class fd{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new fd(function*(e,t){for(const s of e)if(yield s,s.operation.id===t)return}(this.operations,e))}stopBefore(e){return new fd(function*(e,t){for(const s of e){if(s.operation.id===t)return;yield s}}(this.operations,e))}startAfter(e){return new fd(function*(e,t){let s=!0;for(const i of e)s||(yield i),i.operation.id===t&&(s=!1)}(this.operations,e))}}class md{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new fd(Es(this._execution(e),this._execution(e)))}revertedExecution(e){return new fd(Es(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var s;const i=e.getLastOperationId()||(null===(s=this.previousBranch(e))||void 0===s?void 0:s.getLastOperationId());e.append(t),i&&this.insertPrevious(e,t,i)}insertOperationAfter(e,t,s){e.insert(t,s),this.updateNextWith(e,t,s),this.insertPrevious(e,t,s)}undo(e,t){const s=this.buildTransformation.without(t.data),i=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);i&&this.branchingOperationIds.set(o,i),this.insertBranchAfter(e,o),this.transform(o,s)}redo(e){const t=this.nextBranch(e);if(!t)return;const s=this.nextBranch(t);this.removeBranchFromTree(t);const i=this.branchingOperationIds.get(t);i?this.branchingOperationIds.set(e,i):this.branchingOperationIds.delete(e),s&&this.rebaseUp(s)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const s of this.revertedExecution(e))if(s.operation.id===t)return s;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:s}=this.findPreviousBranchingOperation(e);if(!t||!s)return;const i=this.buildTransformation.without(s.data),o=t.fork(s.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(i);const n=this.nextBranch(o);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const s=this.branches.findIndex((t=>t===e));this.branches.splice(s+1,0,t)}updateNextWith(e,t,s){const i=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(i&&o)if(e.getFirstOperationAmong(s,i)===i){const n=this.addToNextBranch(e,o,i,t,s);this.updateNextWith(o,n,s)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,s,i,o){let n=i;return o===s?(n=this.getTransformedOperation(e,s,i),t.prepend(n)):t.contains(o)?(n=this.getTransformedOperation(e,s,i),t.insert(n,o)):t.append(i),n}getTransformedOperation(e,t,s){const i=e.getOperation(t),o=this.buildTransformation.without(i.data);return s.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const s=this.nextBranch(e);s&&this.transform(s,t)}insertPrevious(e,t,s){const{previousBranch:i,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!i||!o)return;const n=this.buildTransformation.with(o.data),r=e.fork(s);r.transform(n),i.cutAfter(s),i.appendBranch(r);const a=t.transformed(n);this.insertPrevious(i,a,s)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const s=this.branchingOperationIds.get(t);return s?{previousBranch:t,branchingOperation:t.getOperation(s)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let s=!!t;const i=e.getOperations();for(let o=i.length-1;o>=0;o--){const n=i[o];n.id===t&&(s=!1),s||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class vd{constructor(e,t,s,i,o){this.applyOperation=t,this.revertOperation=s,this.buildEmpty=i,this.buildTransformation=o,this.HEAD_BRANCH=new pd(this.buildTransformation),this.tree=new md(o,this.HEAD_BRANCH);const n=new gd(e,i(e));this.tree.insertOperationLast(this.HEAD_BRANCH,n),this.HEAD_OPERATION=n}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const s=new gd(e,t),i=this.tree.getLastBranch();this.tree.insertOperationLast(i,s),this.HEAD_BRANCH=i,this.HEAD_OPERATION=s}insert(e,t,s){const i=new gd(e,t);this.revertTo(s),this.tree.insertOperationAfter(this.HEAD_BRANCH,i,s),this.fastForward()}undo(e,t,s){const{branch:i,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(i,o),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}redo(e,t,s){const{branch:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(i),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}drop(e){this.revertBefore(e),this.tree.drop(e)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:s,isCancelled:i}of e)i||this.revertOperation(s.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:s,isCancelled:i}of e)i||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=s}}function Ed(e,t,s){return new vd(e,(e=>{const i=e.commands.slice(),{changes:o}=t((()=>{for(const e of i)s(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Sd(t.changes[e],"before")}}([e])),(e=>new Kh(e,"empty",[],[])),{with:e=>t=>new Kh(t.id,t.clientId,Xh(t.commands,e.commands)),without:e=>t=>new Kh(t.id,t.clientId,Xh(t.commands,e.commands.map(dd).flat()))})}function Sd(e,t){let s=e.path[0];const i=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const i=e.path[t];if(void 0===s[i]){const o=e.path[t+1];s[i]=ud(o)}s=s[i]}void 0===e[t]?delete s[i]:s[i]=e[t]}class bd extends i.core.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("pending-revisions-dropped",this,(({revisionIds:e})=>this.drop(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}drop(e){this.undoStack=this.undoStack.filter((t=>!e.includes(t))),this.redoStack=[]}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class Cd{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return 0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";e.elements.sort(((e,t)=>t-e));const o=vs(e.elements);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of o){const o=Ns(e),l=Os(e);if(n.zone[t]<=o&&o<=n.zone[s]){const e=Math.min(n.zone[s],l)-o+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e)}else if(n.zone[t]>=o&&n.zone[s]<=l)a="REMOVE",r=this.buildInvalidRange(_);else if(n.zone[t]<=l&&n.zone[s]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e),r=this.createAdaptedRange(r,i,"MOVE",-(n.zone[t]-o))}else o<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,i,a,-(l-o+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>t.sheetId!==e.sheetId?{changeType:"NONE"}:{changeType:"REMOVE",range:t={...this.buildInvalidRange(_),invalidSheetName:this.getters.getSheetName(e.sheetId)}}),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 s={...t,zone:{...t.zone}};return s.invalidSheetName=void 0,s.sheetId=e.sheetId,{changeType:"CHANGE",range:s}}return{changeType:"NONE"}}))}}finalize(){}verifyRangeRemoved(e){return t=>{const s=e(t);return"NONE"===s.changeType||$s(s.range.zone)?s:{range:s.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,s,i){return{...e,zone:Xs(e.zone,t,s,i)}}executeOnAllRanges(e,t){const s=this.verifyRangeRemoved(e);for(const e of this.providers)e(s,t)}addRangeProvider(e){this.providers.push(e)}orderZone(e,t){if(e.right<e.left){let s=e.right;e.right=e.left,e.left=s;let i=t[1].colFixed;t[1].colFixed=t[0].colFixed,t[0].colFixed=i}if(e.bottom<e.top){let s=e.bottom;e.bottom=e.top,e.top=s;let i=t[1].rowFixed;t[1].rowFixed=t[0].rowFixed,t[0].rowFixed=i}}createAdaptedRanges(e,t,s,i){return e.map((e=>$s(e.zone)?(e={...e,sheetId:e.prefixSheet?e.sheetId:i,zone:{left:e.zone.left+(e.parts[0].colFixed?0:t),right:e.zone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.zone.top+(e.parts[0].rowFixed?0:s),bottom:e.zone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:s)}},this.orderZone(e.zone,e.parts),e):e))}getRangeFromSheetXC(e,t){let s,i,o,n=t,r=!1;if(!es.test(t))return this.buildInvalidRange(t);t.includes("!")&&(({xc:n,sheetName:s}=ts(t)),s?(i=this.getters.getSheetIdByName(s),r=!0,i||(o=s)):o=s);const a=ks(n);let l=n.split(":").map((e=>({colFixed:e.startsWith("$"),rowFixed:e.includes("$",1)})));return this.orderZone(a,l),{sheetId:i||e,zone:a,parts:l,invalidSheetName:o,prefixSheet:r}}getRangeString(e,t){if(!e)return _;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return _;if(e.zone.left<0||e.zone.top<0)return _;let s=e.sheetId!==t||e.invalidSheetName||e.prefixSheet,i="";if(s&&(i=e.invalidSheetName?e.invalidSheetName:ps(this.getters.getSheetName(e.sheetId))),s&&!i)return _;let o=Array(9);return o[0]=e.parts&&e.parts[0].colFixed?"$":"",o[1]=ss(e.zone.left),o[2]=e.parts&&e.parts[0].rowFixed?"$":"",o[3]=String(e.zone.top+1),e.parts&&2===e.parts.length&&(e.zone.top!==e.zone.bottom||e.zone.left!==e.zone.right||e.parts[0].rowFixed||e.parts[0].colFixed||e.parts[1].rowFixed||e.parts[1].colFixed)&&(o[4]=":",o[5]=e.parts[1].colFixed?"$":"",o[6]=ss(e.zone.right),o[7]=e.parts[1].rowFixed?"$":"",o[8]=String(e.zone.bottom+1)),`${s?i+"!":""}${o.join("")}`}buildInvalidRange(e){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:e}}}Cd.getters=["getRangeString","getRangeFromSheetXC","createAdaptedRanges"];class Id{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let s=e[0],i=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const i=e[t];if(void 0===s[i]){const o=e[t+1];s[i]=ud(o)}s=s[i]}s[i]!==t&&(this.changes.push({path:e,before:s[i],after:t}),void 0===t?delete s[i]:s[i]=t)}}const yd={General:0,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},wd={arrow:"3Arrows",smiley:"3Symbols",dot:"3TrafficLights1"},Td={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"},xd="http://schemas.openxmlformats.org/drawingml/2006/main",Rd="http://schemas.openxmlformats.org/drawingml/2006/chart",Ld={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"},Md="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ad=.75,_d=.1425,Od=164,Nd={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}]},kd=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"];function Fd(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function $d(e){return Math.round(Ad*e*window.devicePixelRatio*100)/100}function Dd(e){return Math.round(_d*e*100)/100}function Ud(e,t){let s={};e.style&&(s=t.styles[e.style]);const i={font:{size:(null==s?void 0:s.fontSize)||x,color:(null==s?void 0:s.textColor)?s.textColor:"000000",family:2,name:"Arial"},fill:(null==s?void 0:s.fillColor)?{fgColor:s.fillColor}:{reservedAttribute:"none"},numFmt:e.format,border:e.border||0,verticalAlignment:"center",horizontalAlignment:null==s?void 0:s.align};return i.font.strike=!!(null==s?void 0:s.strikethrough)||void 0,i.font.underline=!!(null==s?void 0:s.underline)||void 0,i.font.bold=!!(null==s?void 0:s.bold)||void 0,i.font.italic=!!(null==s?void 0:s.italic)||void 0,i}function Pd(e,t){const s=function(e,t){if(!e)return 0;let s=yd[e];s||(s=Vd(e,t)+Od);return s}(t.numFmt,e.numFmts),i={fontId:Vd(t.font,e.fonts),fillId:Vd(t.fill,e.fills),borderId:t.border,numFmtId:s,verticalAlignment:t.verticalAlignment,horizontalAlignment:t.horizontalAlignment};return Vd(i,e.styles)}function Bd(e,t,s){let i,o=e.find((e=>e.path===t));return o?(i=`rId${(o.rels.length+1).toString()}`,o.rels.push({...s,id:i})):(i="rId1",e.push({path:t,rels:[{...s,id:i}]})),i}function Vd(e,t){let s=t.length;const i="object"==typeof e?_s:(e,t)=>e===t;for(let o=0;o<s;o++)if(i(e,t[o]))return o;return t[t.length]=e,t.length-1}const Hd=[];function zd(e){const t=Hd.findIndex((t=>t===e));return-1===t?(Hd.push(e),Hd.length):t+1}function Zd(e){return Math.round(914400*e/96)}class Gd{constructor(e){this.xmlString=e}toString(){return this.xmlString}}function Wd(e,t,s){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:s}}function qd(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function jd(e){return new Gd(e.map((([e,t])=>`${e}="${qd(t)}"`)).join(" "))}function Yd(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),s=t.querySelector("parsererror");if(s){const t=s.innerHTML,i=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),n=o.slice(Math.max(i-3,0),Math.min(i+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${n}`)}return t}function Xd(e,t){return Qd`
|
|
1044
|
+
`;class Eh extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.state=t.useState(this.initialState())}get hasSearchResult(){return null!==this.env.getters.getCurrentSelectedMatchIndex()}mounted(){this.focusInput()}async willUnmount(){this.env.dispatch("CLEAR_SEARCH")}onInput(e){this.state.toSearch=e.target.value,this.debouncedUpdateSearch()}onKeydownSearch(e){"Enter"===e.key&&(e.preventDefault(),this.onSelectNextCell())}onKeydownReplace(e){"Enter"===e.key&&(e.preventDefault(),this.replace())}onFocusSidePanel(){this.state.searchOptions.searchFormulas=this.getters.shouldShowFormulas(),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas?this.state.searchOptions.searchFormulas:this.state.replaceOptions.modifyFormulas,this.env.dispatch("REFRESH_SEARCH")}searchFormulas(){this.env.dispatch("SET_FORMULA_VISIBILITY",{show:this.state.searchOptions.searchFormulas}),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas,this.updateSearch()}onSelectPreviousCell(){this.env.dispatch("SELECT_SEARCH_PREVIOUS_MATCH")}onSelectNextCell(){this.env.dispatch("SELECT_SEARCH_NEXT_MATCH")}updateSearch(){this.env.dispatch("UPDATE_SEARCH",{toSearch:this.state.toSearch,searchOptions:this.state.searchOptions})}debouncedUpdateSearch(){clearTimeout(this.inDebounce),this.inDebounce=setTimeout((()=>this.updateSearch.call(this)),400)}replace(){this.env.dispatch("REPLACE_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}replaceAll(){this.env.dispatch("REPLACE_ALL_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}focusInput(){const e=this.el.querySelector("input");e&&e.focus()}initialState(){return{toSearch:"",replaceWith:"",searchOptions:{matchCase:!1,exactMatch:!1,searchFormulas:!1},replaceOptions:{modifyFormulas:!1}}}}Eh.template=mh,Eh.style=vh;const Sh=new Le;Sh.add("ConditionalFormatting",{title:a("Conditional formatting"),Body:ph}),Sh.add("ChartPanel",{title:a("Chart"),Body:Nc}),Sh.add("FindAndReplace",{title:a("Find and Replace"),Body:Eh});const bh=new Le;class Ch extends ma{constructor(e,t,s,i){super(t,s,i),this.getters=e,this.ui=i}drawGrid(e,t){}}Ch.layers=[];class Ih{constructor(e,t,s){this.index=0,this.cells=e,this.getters=t,this.direction=s}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:s,tooltip:i}=Ma.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:s,tooltip:i,origin:{col:e.data.col,row:e.data.row}}}}class yh extends Ch{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:gs(e.col,0,this.getters.getSheet(t).cols.length),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:gs(e.row,0,this.getters.getSheet(t).rows.length),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:30;case"AUTOFILL_AUTO":const s=this.getters.getSelectedZone();return s.top===s.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||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),s=this.autofillZone;switch(this.direction){case 1:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(os(i,e));const n=this.createGenerator(o);for(let t=s.top;t<=s.bottom;t++)this.computeNewCell(n,i,t,e)}break;case 0:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(os(i,e));const n=this.createGenerator(o);for(let t=s.bottom;t>=s.top;t--)this.computeNewCell(n,i,t,e)}break;case 2:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(os(e,i));const n=this.createGenerator(o);for(let t=s.right;t>=s.left;t--)this.computeNewCell(n,t,i,e)}break;case 3:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(os(e,i));const n=this.createGenerator(o);for(let t=s.left;t<=s.right;t++)this.computeNewCell(n,t,i,e)}}if(e){const e=Bs(this.getters.getSelectedZone(),this.autofillZone);this.autofillZone=void 0,this.lastCellSelected={},this.direction=void 0,this.tooltip=void 0,this.dispatch("SET_SELECTION",{zones:[e],anchor:[e.left,e.top],anchorZone:e})}}select(e,t){const s=this.getters.getSelectedZone();if(zs(e,t,s))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,s.top-1,s.left,s.right);break;case 1:this.saveZone(s.bottom+1,t,s.left,s.right);break;case 2:this.saveZone(s.top,s.bottom,e,s.left-1);break;case 3:this.saveZone(s.top,s.bottom,s.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let s=e.left,i=e.bottom;if(s>0){let e=this.getters.getCell(t,s-1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s-1,i)}if(i===e.bottom&&(s=e.right,s<=this.getters.getActiveSheet().cols.length)){let e=this.getters.getCell(t,s+1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s+1,i)}i!==e.bottom&&(this.select(e.left,i-1),this.autofill(!0))}computeNewCell(e,t,s,i){const{cellData:o,tooltip:n,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=n,i&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:s,content:a,style:l,border:c,format:h})}getRule(e,t){const s=Aa.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((s=>s.condition(e,t)));return s&&s.generateRule(e,t)}createGenerator(e){const t=[],s=[],i=this.getters.getActiveSheetId();for(let t of e){const[e,o]=is(t),n=this.getters.getCell(i,e,o);s.push({col:e,row:o,cell:n,sheetId:i})}const o=s.map((e=>e.cell));for(let e of s){let s={type:"COPY_MODIFIER"};if(e&&e.cell){s=this.getRule(e.cell,o)||s}const{sheetId:i,col:n,row:r}=e,a=this.getters.getCellBorder(i,n,r)||void 0;t.push({data:{...e,border:a},rule:s})}return new Ih(t,this.getters,this.direction)}saveZone(e,t,s,i){this.autofillZone={top:e,bottom:t,left:s,right:i}}getDirection(e,t){const s=this.getters.getSelectedZone(),i={up:{number:s.top-t,value:0},down:{number:t-s.bottom,value:1},left:{number:s.left-e,value:2},right:{number:e-s.right,value:3}};if(1===Object.values(i).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(i).find((e=>e.number>0?1:0)).value;const o=i.up.number>0?"up":"down",n=i.left.number>0?"left":"right";return Math.abs(i[o].number)>=Math.abs(i[n].number)?i[o].value:i[n].value}autoFillMerge(e,t,s,i){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,s,i)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const n=this.getters.getMerge(o.id,e,t);(null==n?void 0:n.topLeft.col)===e&&(null==n?void 0:n.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:i,bottom:i+n.bottom-n.top,left:s,right:s+n.right-n.left}]})}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:s,thinLineWidth:i}=e,[o,n,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(s.strokeStyle="black",s.lineWidth=i,s.setLineDash([3]),s.strokeRect(o,n,r,a),s.setLineDash([]))}}yh.layers=[6],yh.getters=["getAutofillTooltip"],yh.modes=["normal"];class wh extends Ch{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:s}=this.getters.getSelection();for(const i of t){const t=this.getAutomaticSums(e,i,s);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,s){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,s):this.sumData(e,t)}sumData(e,t){const s=this.dimensionsToSum(e,t),i=this.sumDimensions(e,t,s).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return s.has("ROW")&&s.has("COL")&&i.push(this.sumTotal(t)),i}sumAdjacentData(e,t,s){const[i,o]=zs(s[0],s[1],t)?s:[t.left,t.top],n=this.findAdjacentData(e,i,o);return n?this.getters.isSingleCellOrMerge(e,t)||js(Bs(n,t))?[{position:[i,o],zone:n}]:this.sumDimensions(e,Bs(n,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,s){const i=this.getters.getSheet(e),o=this.findSuitableZoneToSum(i,...this.getters.getMainCell(e,t,s));if(o)return this.getters.expandZone(e,o)}findSuitableZoneToSum(e,t,s){const i=this.getters.getCell(e.id,t,s-1),o=this.getters.getCell(e.id,t-1,s);if(this.isNumber(o)&&!this.isNumber(i))return this.findHorizontalZone(e,t,s);const n=this.findVerticalZone(e,t,s);if(this.isZoneValid(n))return n;const r=this.findHorizontalZone(e,t,s);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,s){const i={top:0,bottom:s-1,left:t,right:t},o=this.reduceZoneStart(e,i,i.bottom);return{...i,top:o}}findHorizontalZone(e,t,s){const i={top:s,bottom:s,left:0,right:t-1},o=this.reduceZoneStart(e,i,i.right);return{...i,left:o}}reduceZoneStart(e,t,s){const i=Ws(t,e,(e=>e),void 0).flat(),o=ms(s,-1,-1),n=Os(o.filter((e=>{var t;return i[e]&&!(null===(t=i[e])||void 0===t?void 0:t.isAutoSummable)}))),r=vs(o.filter((e=>this.isNumber(i[e]))))[0]||[];return Os(r)<n?1/0:Ns(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===ke.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(A))}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 s=new Set;return js(t)?(s.add(1===qs(t).width?"COL":"ROW"),s):(this.lastColIsEmpty(e,t)&&s.add("ROW"),this.lastRowIsEmpty(e,t)&&s.add("COL"),0===s.size&&s.add("COL"),s)}sumDimensions(e,t,s){return[...s.has("COL")?this.sumColumns(t,e):[],...s.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:s}=e;return{position:[s,t],zone:{...e,top:t,right:s-1}}}sumColumns(e,t){const s=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,s.bottom-1)},Ys(s).map((t=>({position:t,zone:{...e,right:t[0],left:t[0]}})))}sumRows(e,t){const s=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,s.right-1)},Ys(s).map((t=>({position:t,zone:{...e,top:t[1],bottom:t[1]}})))}dispatchCellUpdates(e,t){for(const s of t){const[t,i]=s.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,content:`=SUM(${this.getters.zoneToXC(e,s.zone)})`})}}nextEmptyRow(e,t){let s=t.bottom+1;const{left:i,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:s,top:s,left:i,right:o});)s++;return{...t,top:s,bottom:s}}nextEmptyCol(e,t){let s=t.right+1;const{top:i,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:s,right:s,top:i,bottom:o});)s++;return{...t,left:s,right:s}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}wh.getters=["getAutomaticSums"],wh.modes=["normal","headless"];class Th extends Ch{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"PASTE":return this.isPasteAllowed(this.state,e.target,!!e.force);case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}}return 0}handle(e){var t,s,i,o;switch(e.type){case"COPY":case"CUT":this.state=this.getClipboardState(e.target,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);if(this._isPaintingFormat=!1,e.interactive)this.interactivePaste(this.state,e.target,e);else{const t=this.state.cells.length,s=this.state.cells[0].length;this.paste(this.state,e.target,n),this.selectPastedZone(s,t,e.target),this.status="invisible"}break;case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!$s(t[0])){for(const[t,s]of Ys(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:s,sheetId:this.getters.getActiveSheetId()});break}const i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(s=this.state)||void 0===s?void 0:s.sheetId))return;this.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)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this.state=this.getClipboardState(e.target,"COPY"),this._isPaintingFormat=!0,this.status="visible";break;default:Ue(e)&&(this.status="invisible")}}getClipboardContent(){return this.state&&this.state.cells.length&&this.state.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const s=this.getters.getActiveSheet();let i;return i="COL"===t?{...e,left:e.right+1,right:s.cols.length-1}:{...e,top:e.bottom+1,bottom:s.rows.length-1},{cut:[i],paste:[e]}}getInsertCellsTargets(e,t){const s=this.getters.getActiveSheet();let i,o;return"COL"===t?(i={...e,right:s.cols.length-1},o={...e,left:e.right+1,right:e.right+1}):(i={...e,bottom:s.rows.length-1},o={...e,top:e.bottom+1,bottom:s.rows.length-1}),{cut:[i],paste:[o]}}removeMergeIfTopLeft(e){const{sheetId:t,col:s,row:i}=e,[o,n]=this.getters.getMainCell(t,s,i);if(n===i&&o===s){const e=this.getters.getMerge(t,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:t,target:[e]})}}pasteMergeIfExist(e,t){let{sheetId:s,col:i,row:o}=e;const[n,r]=this.getters.getMainCell(s,i,o);if(n===i&&r===o){const e=this.getters.getMerge(s,i,o);if(!e)return;({sheetId:s,col:i,row:o}=t),this.dispatch("ADD_MERGE",{sheetId:s,force:!0,target:[{left:i,top:o,right:i+e.right-e.left,bottom:o+e.bottom-e.top}]})}}getPasteZones(e,t){if(!t.length||!t[0].length)return e;const s=[],i=t.length,o=t[0].length,n=e[e.length-1],r=n.left,a=n.top,l=Math.max(1,Math.floor((n.right+1-r)/o)),c=Math.max(1,Math.floor((n.bottom+1-a)/i));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)s.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*i});return s}getClipboardState(e,t){const s=new Set(e.map((e=>e.top))),i=new Set(e.map((e=>e.bottom)));let o=1===s.size&&1===i.size?e:[e[e.length-1]];o=o.map((e=>({...e})));const n=[],r=[],a=this.getters.getActiveSheetId(),{top:l,bottom:c}=o[0];for(let e=l;e<=c;e++){const t=[];n.push(t);for(let s of o)for(let i=s.left;i<=s.right;i++){const s=this.getters.getCell(a,i,e),o=this.getters.getCellBorder(a,i,e)||void 0;t.push({cell:s,border:o,position:{col:i,row:e,sheetId:a}});const n=this.getters.getMerge(a,i,e);n&&n.top===e&&n.left===i&&r.push(n)}}return{cells:n,operation:t,sheetId:a,zones:o,merges:r}}pasteFromClipboard(e,t){this.status="invisible";const s=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:i,top:o}=e[0],n=Math.max.apply(Math,s.map((e=>e.length))),r=s.length,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,r,i,o);for(let e=0;e<s.length;e++)for(let t=0;t<s[e].length;t++)this.dispatch("UPDATE_CELL",{row:o+e,col:i+t,content:s[e][t],sheetId:a.id});const l={left:i,top:o,right:i+n-1,bottom:o+r-1};this.dispatch("SET_SELECTION",{anchor:[i,o],zones:[l],anchorZone:l})}isPasteAllowed(e,t,s){const i=this.getters.getActiveSheetId();if(!e)return 20;if(t.length>1&&(e.cells.length>1||e.cells[0].length>1))return 19;if(!s)for(let s of this.getPasteZones(t,e.cells))if(this.getters.doesIntersectMerge(i,s))return 2;return 0}paste(e,t,s){if("CUT"===e.operation&&this.clearClippedZones(e),t.length>1)for(const i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,t,o,s);else{const i=e.cells.length,o=e.cells[0].length,n=t[0],r=Math.max(1,Math.floor((n.right+1-n.left)/o)),a=Math.max(1,Math.floor((n.bottom+1-n.top)/i));for(let t=0;t<r;t++)for(let r=0;r<a;r++)this.pasteZone(e,n.left+t*o,n.top+r*i,s)}"CUT"===e.operation&&(this.dispatch("REMOVE_MERGE",{sheetId:e.sheetId,target:e.merges}),this.state=void 0)}selectPastedZone(e,t,s){const i=s[0],o=i.left,n=i.top,r=Math.max(1,Math.floor((i.right+1-i.left)/e)),a=Math.max(1,Math.floor((i.bottom+1-i.top)/t));if(t>1||e>1){const s={left:o,top:n,right:o+r*e-1,bottom:n+a*t-1},[i,l]=this.getters.getSelection().anchor,c=gs(i,o,o+r*e-1),h=gs(l,n,n+a*t-1);this.dispatch("SET_SELECTION",{anchor:[c,h],zones:[s],anchorZone:s})}}clearClippedZones(e){for(const t of e.cells)for(const e of t)e.cell&&this.dispatch("CLEAR_CELL",e.position);this.dispatch("CLEAR_FORMATTING",{sheetId:e.sheetId,target:e.zones})}pasteZone(e,t,s,i){const o=e.cells.length,n=e.cells[0].length,r="onlyValue"!==i&&this.state&&this.state===e,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,o,t,s);for(let l=0;l<o;l++){const o=e.cells[l];for(let c=0;c<n;c++){const n=o[c],h={col:t+c,row:s+l,sheetId:a.id};this.removeMergeIfTopLeft(h),this.pasteMergeIfExist(n.position,h),this.pasteCell(n,h,e.operation,e.zones,i),r&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:h,operation:e.operation})}}}addMissingDimensions(e,t,s,i,o){const{cols:n,rows:r,id:a}=e,l=s+o-r.length;l>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:r.length-1,sheetId:a,quantity:l,position:"after"});const c=t+i-n.length;c>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:n.length-1,sheetId:a,quantity:c,position:"after"})}pasteCell(e,t,s,i,o){const{sheetId:n,col:r,row:a}=t,l=this.getters.getCell(n,r,a);if("onlyValue"!==o&&this.dispatch("SET_BORDER",{sheetId:n,col:r,row:a,border:e.border}),e.cell){if("onlyFormat"===o)return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.format});if("onlyValue"===o){const s=jr(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:s})}let l=e.cell.content;if(e.cell.isFormula()){const t=r-e.position.col,o=a-e.position.row;l=this.getUpdatedContent(n,e.cell,t,o,i,s)}this.dispatch("UPDATE_CELL",{...t,content:l,style:e.cell.style||null,format:e.cell.format})}else l&&("onlyValue"===o?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===o?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,s,i,o,n){if("CUT"===n){const n=[];for(const r of t.dependencies.references)this.isZoneOverlapClippedZone(o,r.zone)?n.push(...this.getters.createAdaptedRanges([r],s,i,e)):n.push(r);const r={...t.dependencies,references:n};return this.getters.buildFormulaContent(e,t.normalizedText,r)}const r=this.getters.createAdaptedRanges(t.dependencies.references,s,i,e),a={...t.dependencies,references:r};return this.getters.buildFormulaContent(e,t.normalizedText,a)}isZoneOverlapClippedZone(e,t){return e.some((e=>Hs(t,e)))}interactivePaste(e,t,s){const i=this.isPasteAllowed(e,t,!1);0!==i?(19===i&&this.ui.notifyUser(a("This operation is not allowed with multiple selections.")),2===i&&this.ui.notifyUser(a("This operation is not possible due to a merge. Please remove the merges first than try again."))):this.dispatch(s.type,{...s,interactive:!1})}isColRowDirtyingClipboard(e,t){if(!this.state||!this.state.zones)return!1;for(let s of this.state.zones){if("COL"===t&&e<=s.right)return!0;if("ROW"===t&&e<=s.bottom)return!0}return!1}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e;if("visible"===this.status&&this.state&&this.state.zones&&this.state.zones.length&&this.state.sheetId===this.getters.getActiveSheetId()){s.setLineDash([8,5]),s.strokeStyle=p,s.lineWidth=3.3*i;for(const e of this.state.zones){const[i,o,n,r]=this.getters.getRect(e,t);n>0&&r>0&&s.strokeRect(i,o,n,r)}}}}var xh;Th.layers=[2],Th.getters=["getClipboardContent","isPaintingFormat"],Th.modes=["normal"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}(xh||(xh={}));class Rh extends Ch{constructor(e,t,s,i){super(e,t,s,i),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0],anchorZone:{top:0,left:0,bottom:0,right:0}},this.selectedFigureId=null,this.activeCol=0,this.activeRow=0,this.mode=xh.idle,this.sheetsData={},this.activeSheet=null,this.moveClient=i.moveClient}allowDispatch(e){switch(e.type){case"SET_SELECTION":if(-1===e.zones.findIndex((t=>Vs(t,e.anchorZone))))return 16;break;case"ALTER_SELECTION":if(e.delta){const{left:t,right:s,top:i,bottom:o}=this.getSelectedZone(),n=this.getters.getActiveSheet(),r=ai(n,"cols",ms(t,s+1)),a=ai(n,"rows",ms(i,o+1));if(0!==e.delta[0]&&void 0===a||0!==e.delta[1]&&void 0===r)return 17}break;case"MOVE_POSITION":{const{cols:t,rows:s}=this.getters.getActiveSheet();if(0!==e.deltaX&&s[this.activeRow].isHidden||0!==e.deltaY&&t[this.activeCol].isHidden)return 17;const{col:i,row:o}=this.getNextAvailablePosition(e.deltaX,e.deltaY);if(o<0||o>s.length-1||i<0||i>t.length-1)return 17;break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().cols.length)return 17;break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().rows.length)return 17;break}case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 23}case"MOVE_COLUMNS_ROWS":const t=this.isMoveElementAllowed(e);return 2===t&&this.ui.notifyUser(a("Merged cells are preventing this operation. Unmerge those cells and try again.")),t}return 0}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":case"CREATE_FIGURE":case"CREATE_CHART":case"UPDATE_FIGURE":case"EVALUATE_CELLS":case"DISABLE_SELECTION_INPUT":case"ENABLE_NEW_SELECTION_INPUT":case"RESIZE_VIEWPORT":break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;default:this.selectedFigureId=null}switch(e.type){case"START":const t=ri(this.getters.getSheets()[0],0,0);this.activeCol=t[0],this.activeRow=t[1],this.dispatch("ACTIVATE_SHEET",{sheetIdTo:this.getters.getSheets()[0].id,sheetIdFrom:this.getters.getSheets()[0].id}),this.selectCell(...t);break;case"ACTIVATE_SHEET":this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow},e.sheetIdTo in this.sheetsData?Object.assign(this,this.sheetsData[e.sheetIdTo]):this.selectCell(...ri(this.getters.getSheet(e.sheetIdTo),0,0));break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.anchorZone,e.strict);break;case"START_SELECTION":this.mode=xh.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=xh.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=xh.expanding;break;case"STOP_SELECTION":this.mode=xh.idle;break;case"MOVE_POSITION":this.movePosition(e.deltaX,e.deltaY);break;case"SELECT_CELL":this.selectCell(e.col,e.row);break;case"SELECT_COLUMN":this.selectColumn(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ROW":this.selectRow(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ALL":this.selectAll();break;case"ALTER_SELECTION":e.delta&&this.moveSelection(e.delta[0],e.delta[1]),e.cell&&this.addCellToSelection(...e.cell);break;case"UNDO":case"REDO":case"DELETE_SHEET":if(!this.getters.tryGetSheet(this.getActiveSheetId())){const e=this.getters.getVisibleSheets();this.activeSheet=this.getters.getSheet(e[0]),this.selectCell(0,0)}this.ensureSelectionValidity();break;case"REMOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&("COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e));break;case"ADD_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onAddElements(e);break;case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"UPDATE_CHART":case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left")}}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getMainCell(e,this.activeCol,this.activeRow);return this.getters.getCell(e,t,s)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.getters.getActiveSheet().rows.length-1)for(let s=t.left;s<=t.right;s++)e.add(s);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.getters.getActiveSheet().cols.length-1)for(let s=t.top;s<=t.bottom;s++)e.add(s);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.anchorZone}getSelection(){return this.selection}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return[this.activeCol,this.activeRow]}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?[t.activeCol,t.activeRow]:ri(this.getters.getSheet(e),0,0)}}getAggregate(){let e=0,t=0;for(let s of this.selection.zones)for(let i=s.top;i<=s.bottom;i++){const o=this.getters.getRow(this.getters.getActiveSheetId(),i);if(void 0!==o)for(let i=s.left;i<=s.right;i++){const s=o.cells[i];(null==s?void 0:s.evaluated.type)===ke.number&&(t++,e+=s.evaluated.value)}}return t<2?null:ie(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Vs(t,e)))}getVisibleFigures(e){const t=[],s=this.getters.getFigures(e),{offsetX:i,offsetY:o}=this.getters.getSnappedViewport(e),{width:n,height:r}=this.getters.getViewportDimension();for(let e of s)e.x>=i+n||e.x+e.width<=i||e.y>=o+r||e.y+e.height<=o||t.push(e);return t}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 s=[];const i="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[i]+1},((t,s)=>e[i]+s));s=s.concat(t)}return[...new Set(s)].sort()}selectColumn(e,t,s){const i=this.getters.getActiveSheet().rows.length-1;let o={left:e,right:e,top:0,bottom:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().rows.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Bs(o,{left:e,right:e,top:l,bottom:i}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[e,l];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectRow(e,t,s){const i=this.getters.getActiveSheet().cols.length-1;let o={top:e,bottom:e,left:0,right:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().cols.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Bs(o,{left:l,right:i,top:t,bottom:t}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[l,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectAll(){const e={left:0,top:0,bottom:this.getters.getActiveSheet().rows.length-1,right:this.getters.getActiveSheet().cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0],anchorZone:e})}selectCell(e,t){const s=this.getters.getActiveSheet();this.moveClient({sheetId:s.id,col:e,row:t});let i=this.getters.expandZone(s.id,{left:e,right:e,top:t,bottom:t});this.mode===xh.expanding?this.selection.zones.push(i):this.selection.zones=[i],this.selection.zones=Ks(this.selection.zones),this.selection.anchorZone=i,this.selection.anchor=[e,t],this.activeCol=e,this.activeRow=t}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}getNextAvailablePosition(e,t){return{col:this.getNextAvailableCol(e,this.activeCol,this.activeRow),row:this.getNextAvailableRow(t,this.activeCol,this.activeRow)}}getNextAvailableCol(e,t,s){const{cols:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,t,n,(e=>this.getters.isInSameMerge(o,t,s,e,s)))}getNextAvailableRow(e,t,s){const{rows:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,s,n,(e=>this.getters.isInSameMerge(o,t,s,t,e)))}getNextAvailableHeader(e,t,s,i,o){var n,r,a;const l=this.getters.getActiveSheetId(),{col:c,row:h}=i;if(0===e)return s;let d=s+e;if(this.getters.isInMerge(l,c,h)){for(;o(d);)d+=e;for(;null===(n=t[d])||void 0===n?void 0:n.isHidden;)d+=e}else if(null===(r=t[d])||void 0===r?void 0:r.isHidden)for(;null===(a=t[d])||void 0===a?void 0:a.isHidden;)d+=e;return d<0||d>t.length-1?t[s].isHidden?this.getNextAvailableHeader(-e,t,s,i,o):s:d}movePosition(e,t){const{col:s,row:i}=this.getNextAvailablePosition(e,t);this.selectCell(s,i)}setSelection(e,t,s,i=!1){this.selectCell(...e);const o=this.getters.getActiveSheetId();let n;t=Ks(t),n=i?{zones:t,anchorZone:s,anchor:e}:{anchor:e,zones:t.map((e=>this.getters.expandZone(o,e))),anchorZone:this.getters.expandZone(o,s)},this.selection=this.clipSelection(o,n)}getReferencePosition(){const e=this.getters.getActiveSheet(),t=this.selection,{left:s,right:i,top:o,bottom:n}=t.anchorZone,[r,a]=t.anchor;return{col:e.cols[r].isHidden&&ai(e,"cols",ms(s,i+1))||r,row:e.rows[a].isHidden&&ai(e,"rows",ms(o,n+1))||a}}moveSelection(e,t){const s=this.selection;let i=[];const[o,n]=s.anchor,{left:r,right:a,top:l,bottom:c}=s.anchorZone;let h=s.anchorZone;const d=this.getters.getActiveSheet(),u=e=>{const{left:t,right:s,top:i,bottom:o}=this.getters.expandZone(d.id,e);return{left:Math.max(0,t),right:Math.min(d.cols.length-1,s),top:Math.max(0,i),bottom:Math.min(d.rows.length-1,o)}},{col:p,row:g}=this.getReferencePosition();let f=0;for(;null!==h;){if(f++,e<0){const t=this.getNextAvailableCol(e,a-(f-1),g);h=p<=a-f?u({top:l,left:r,bottom:c,right:t}):null}if(e>0){const t=this.getNextAvailableCol(e,r+(f-1),g);h=r+f<=p?u({top:l,left:t,bottom:c,right:a}):null}if(t<0){const e=this.getNextAvailableRow(t,p,c-(f-1));h=g<=c-f?u({top:l,left:r,bottom:e,right:a}):null}if(t>0){const e=this.getNextAvailableRow(t,p,l+(f-1));h=l+f<=g?u({top:e,left:r,bottom:c,right:a}):null}if(h=h?Qs(h):h,h&&!Vs(h,s.anchorZone))return i=this.updateSelectionZones(h),void this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h})}h=u(Bs({top:n,bottom:n,left:o,right:o},Qs({top:this.getNextAvailableRow(t,p,l),left:this.getNextAvailableCol(e,r,g),bottom:this.getNextAvailableRow(t,p,c),right:this.getNextAvailableCol(e,a,g)}))),Vs(h,s.anchorZone)||(i=this.updateSelectionZones(h),this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h}))}addCellToSelection(e,t){const s=this.selection,[i,o]=s.anchor,n={left:Math.min(i,e),top:Math.min(o,t),right:Math.max(i,e),bottom:Math.max(o,t)},r=this.updateSelectionZones(n);this.dispatch("SET_SELECTION",{zones:r,anchor:[i,o],anchorZone:n})}ensureSelectionValidity(){const{anchor:e,zones:t,anchorZone:s}=this.clipSelection(this.getActiveSheetId(),this.selection);this.setSelection(e,t,s);const i=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of i)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:s,anchorZone:i}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:s,anchorZone:i},activeCol:t[0],activeRow:t[1]}}}clipSelection(e,t){const s=this.getters.getSheet(e),i=s.cols.length-1,o=s.rows.length-1,n=t.zones.map((e=>({left:gs(e.left,0,i),right:gs(e.right,0,i),top:gs(e.top,0,o),bottom:gs(e.bottom,0,o)})));return{anchor:[gs(t.anchor[0],0,i),gs(t.anchor[1],0,o)],zones:n,anchorZone:{left:gs(t.anchorZone.left,0,i),right:gs(t.anchorZone.right,0,i),top:gs(t.anchorZone.top,0,o),bottom:gs(t.anchorZone.bottom,0,o)}}}onColumnsRemoved(e){const t=Ps(this.getSelectedZone(),"left",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onRowsRemoved(e){const t=Ps(this.getSelectedZone(),"top",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onAddElements(e){const t=Us(this.getSelectedZone(),"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.setSelection([t.left,t.top],[t],t,!0)}updateSelectionZones(e){let t=[...this.selection.zones];const s=this.selection.anchorZone,i=t.findIndex((e=>Vs(e,s)));return i>=0&&(t[i]=e),t}activateNextSheet(e){const t=this.getters.getSheets().map((e=>e.id)),s=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[s]})}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 s="COL"===e.dimension,i=e.elements[0],o=e.elements[t-1],n=e.base<i,r=n&&s?t:0,a=n&&!s?t:0,l=this.getters.getSheet(e.sheetId);this.dispatch("CUT",{target:[{left:s?i+r:0,right:s?o+r:l.cols.length-1,top:s?0:i+a,bottom:s?l.rows.length-1:o+a}]}),this.dispatch("PASTE",{target:[{left:s?e.base:0,right:s?e.base+t-1:l.cols.length-1,top:s?0:e.base,bottom:s?l.rows.length-1:e.base+t-1}]});const c=n?e.elements.map((e=>e+t)):e.elements;let h=e.base;for(const t of c){const s="COL"===e.dimension?this.getters.getCol(e.sheetId,t).size:this.getters.getRow(e.sheetId,t).size;this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:s,elements:[h]}),h+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:c})}isMoveElementAllowed(e){const t="COL"===e.dimension,s=e.elements[0],i=e.elements[e.elements.length-1],o=e.sheetId,n=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return n(o,s-1,s)||n(o,i,i+1)||n(o,e.base-1,e.base)?2:0}drawGrid(e){if("inactive"!==this.getters.getEditionMode())return;const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getSelectedZones();s.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;s.fillStyle=n?"#f3f7fe":"#e9f0ff",s.strokeStyle=p,s.lineWidth=1.5*i,s.globalCompositeOperation="multiply";for(const e of o){const[i,o,n,r]=this.getters.getRect(e,t);s.fillRect(i,o,n,r),s.strokeRect(i,o,n,r)}s.globalCompositeOperation="source-over";const r=this.getters.getActiveSheetId(),[a,l]=this.getPosition();let c;s.strokeStyle=p,s.lineWidth=3*i,c=this.getters.isInMerge(r,a,l)?this.getters.getMerge(r,a,l):{top:l,bottom:l,left:a,right:a};const[h,d,u,g]=this.getters.getRect(c,t);u>0&&g>0&&s.strokeRect(h,d,u,g)}}Rh.layers=[5],Rh.modes=["normal"],Rh.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getAggregate","getSelectedFigureId","getVisibleFigures","getSelection","getPosition","getSheetPosition","getSelectionMode","isSelected","getElementsFromSelection"];const Lh=a("The cell you are trying to edit has been deleted.");class Mh extends Ch{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.multiSelectionInitialStart=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=this.getters.getActiveCell(),s=e.text||(null==t?void 0:t.composerContent)||"";return this.validateSelection(s.length,e.selection.start,e.selection.end)}return 0;default:return 0}}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":this.startEdition(e.text,e.selection);break;case"STOP_EDITION":e.cancel?(this.cancelEdition(),this.resetContent()):this.stopEdition();break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0);break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEdition(),this.resetContent();break;case"SELECT_CELL":case"SET_SELECTION":case"MOVE_POSITION":switch(this.mode){case"editing":this.dispatch("STOP_EDITION");break;case"waitingForRangeSelection":this.insertSelectedRange();break;case"rangeSelected":switch(e.type){case"MOVE_POSITION":this.replaceAllSelectedRanges();break;case"SELECT_CELL":this.getters.getSelectionMode()===xh.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges();break;case"SET_SELECTION":e.strict?this.getters.getSelectionMode()===xh.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges():this.replaceSelectedRange()}}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.currentTokens.filter((e=>"SYMBOL"===e.type)).find((t=>{let s=t.value;const{xc:i,sheetName:o}=ts(s),n=o||this.getters.getSheetName(this.sheet),r=this.getters.getActiveSheetId();return Vs(this.getters.expandZone(r,Fs(i)),e.zone)&&this.getters.getSheetName(r)===n}));this.previousRef=t.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=t.start;break;case"CHANGE_HIGHLIGHT":const s=this.getZoneReference(e.zone,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(s),this.previousRef=s,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheet)||"inactive"===this.mode||(this.cancelEdition(),this.resetContent(),this.ui.notifyUser(Lh))}}getEditionMode(){return this.mode}getCurrentContent(){if("inactive"===this.mode){const e=this.getters.getActiveCell();return(null==e?void 0:e.composerContent)||""}return this.currentContent}getEditionSheet(){return this.sheet}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}isSelectingForComposer(){return"waitingForRangeSelection"===this.mode||"rangeSelected"===this.mode||"resettingPosition"===this.mode}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((s=>s.start<=e&&s.end>=t))}validateSelection(e,t,s){return t>=0&&t<=e&&s>=0&&s<=e?0:31}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Lh);const{top:t,left:s}=Ps({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",e.elements);this.col=s,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Lh);const{top:t,left:s}=Ps({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",e.elements);this.col=s,this.row=t}onAddElements(e){const{top:t,left:s}=Us({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=s,this.row=t}startComposerRangeSelection(){this.mode="resettingPosition",this.sheet===this.getters.getActiveSheetId()&&this.dispatch("SELECT_CELL",{col:this.col,row:this.row}),this.mode="waitingForRangeSelection",this.multiSelectionInitialStart=this.selectionStart}startEdition(e,t){const s=this.getters.getActiveCell();this.initialContent=(null==s?void 0:s.composerContent)||"",this.mode="editing";const[i,o]=this.getters.getPosition();this.col=i,this.row=o,this.sheet=this.getters.getActiveSheetId(),this.setContent(e||this.initialContent,t),this.colorIndexByRange={}}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();const e=this.getters.getActiveSheetId(),t=this.getters.getSheets().find((e=>e.id===this.sheet)).id,[s,i]=this.getters.getMainCell(t,this.col,this.row);let o=this.currentContent;if(!(this.initialContent!==o))return;if(o){const t=this.getters.getCell(e,s,i);if(o.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,s=e-t;s>0&&(o+=new Array(s).fill(")").join(""))}else(null==t?void 0:t.isLink())&&(o=ws(o,t.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheet,col:s,row:i,content:o})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheet,content:"",col:s,row:i});e!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheet}),this.setContent("")}}cancelEdition(){this.mode="inactive"}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,s){e=e.replace(/[\r\n]/g,"");const i=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(i||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?Zr(e):[],this.currentTokens.length>100&&s&&this.ui.notifyUser(a("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(){const e=Math.min(this.selectionStart,this.selectionEnd),t=this.getZoneReference(this.getters.getSelectedZone());if("waitingForRangeSelection"===this.mode)return this.insertText(t,e),this.selectionInitialStart=e,void(this.mode="rangeSelected");this.insertText(","+t,e),this.selectionInitialStart=e+1}replaceSelectedRange(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.selectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone()))}replaceAllSelectedRanges(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.multiSelectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone())),this.selectionInitialStart=this.multiSelectionInitialStart}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const s=this.getters.getActiveSheetId();let i=this.getters.zoneToXC(s,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){i=`${ps(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${i}`}return i}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),s=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,s)}replaceText(e,t,s){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(s,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const s=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),i=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:s,selection:{start:i,end:i}})}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=[],t={};for(let s of this.currentTokens.filter((e=>"SYMBOL"===e.type))){let i=s.value;const{xc:o,sheetName:n}=ts(i);if(es.test(o)){const s=(n?`${n}!`:`${this.getters.getSheetName(this.getters.getEditionSheet())}!`)+o.replace(/\$/g,"");e.push(s);const i=this.colorIndexByRange[s];void 0!==i&&(t[s]=i)}}this.colorIndexByRange=t;let s=Object.values(t),i=0;return e.map((e=>{if(void 0===this.colorIndexByRange[e]){for(;s.includes(i);)i++;s.push(i),this.colorIndexByRange[e]=i}return[e,jt[this.colorIndexByRange[e]%jt.length]]}))}canStartComposerRangeSelection(){if("editing"!==this.mode&&this.selectionStart===this.selectionEnd)return!1;if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(e){const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let s=t,i=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type||s<1)return!1;s--,i=this.currentTokens[s]}for(s=t+1,i=this.currentTokens[s];i&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type)return!1;s++,i=this.currentTokens[s]}s++,i=this.currentTokens[s]}return!0}return!1}}Mh.getters=["getEditionMode","isSelectingForComposer","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights"],Mh.modes=["normal"];const Ah=ar.mapping;class _h extends Ch{constructor(e,t,s,i){super(e,t,s,i),this.isUpToDate=new Set,this.evalContext=i.evalContext,i.dataSources.on("data-loaded",this,(()=>{this.dispatch("EVALUATE_CELLS",{sheetId:this.getters.getActiveSheetId()})}))}handle(e){switch(Fe.has(e.type)&&this.isUpToDate.clear(),e.type){case"UPDATE_CELL":"content"in e&&this.isUpToDate.clear();break;case"ACTIVATE_SHEET":this.evaluate(e.sheetIdTo),this.isUpToDate.add(e.sheetIdTo);break;case"EVALUATE_CELLS":this.evaluate(e.sheetId),this.isUpToDate.add(e.sheetId);break;case"EVALUATE_ALL_SHEETS":this.evaluateAllSheets()}}finalize(){const e=this.getters.getActiveSheetId();this.isUpToDate.has(e)||(this.evaluate(e),this.isUpToDate.add(e))}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{let s=Gr(e);const i=Vr(s),o=this.getFormulaParameters((()=>{})),n=[];for(let e of s.dependencies.references)n.push(this.getters.getRangeFromSheetXC(t,e));return i({...s.dependencies,references:n},t,...o)}catch(e){return"#ERROR"}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Ws(e.zone,t,(e=>this.getters.getCellText(e,this.getters.shouldShowFormulas())),"")}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Ws(e.zone,t,(e=>e.evaluated.value))}evaluate(e){const t=this.getters.getCells(e),s=this.getFormulaParameters(o),i={};for(let s of Object.values(t))o(s,e);function o(e,t){if(!e.isFormula())return;const o=e.id;if(o in i)null===i[o]&&e.assignError("#CYCLE",a("Circular reference"));else{i[o]=null;try{if(s[2].__originCellXC=()=>{const e=s[2].getters.getCellPosition(o);return os(e.col,e.row)},e.assignValue(e.compiledFormula(e.dependencies,t,...s)),Array.isArray(e.evaluated.value))throw new Error(a("This formula depends on invalid values"))}catch(t){!function(e,t){if(e instanceof Error||(e=new Error(e)),"#CYCLE"!==t.evaluated.value){t.assignValue("#ERROR");const i=s[2].__lastFnCalled||"";t.assignError("#ERROR",e.message.replace("[[FUNCTION_NAME]]",i))}}(t,e)}i[o]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Ah),this.evalContext,{getters:this.getters});function s(t,s){if(e(t,s),t.evaluated.type===ke.error)throw new Error(a("This formula depends on invalid values"));return t.evaluated.value}function i(e){o(e);const i=t.getters.getSheet(e.sheetId),n={top:0,bottom:i.rows.length-1,left:0,right:i.cols.length-1},r=[],a=function(e,t){if(Hs(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom,t.bottom),right:Math.min(e.right,t.right)}}(e.zone,n);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const o=[];for(let n=a.top;n<=a.bottom;n++){const r=t.getters.getCell(e.sheetId,i,n);o.push(r?s(r,e.sheetId):void 0)}r.push(o)}return r}function o(e){if(!$s(e.zone))throw new Error(a("Invalid reference"));if(e.invalidSheetName)throw new Error(a("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,i,n,r,l,c){const h=i[e];if(o(h),r)return t.getters.getRangeString(h,n);if(h.zone.bottom!==h.zone.top||h.zone.left!==h.zone.right)throw new Error(c?a("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",l.toString(),c.toString()):a("Function %s expects its parameters to be single values or single cell references, not ranges.",l.toString()));return function(e){var i;const o=null===(i=t.getters.getSheet(e.sheetId).rows[e.zone.top])||void 0===i?void 0:i.cells[e.zone.left];return!o||o.isEmpty()?null:s(o,e.sheetId)}(h)},function(e,t,s){return i(t[e])},t]}evaluateAllSheets(){for(const e of this.getters.getVisibleSheets())this.evaluate(e),this.isUpToDate.add(e)}}_h.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"],_h.modes=["normal"];const Oh=["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 Nh{constructor(){this.graphColorIndex=0}next(){return Oh[this.graphColorIndex++%Oh.length]}}class kh extends Ch{constructor(){super(...arguments),this.chartRuntime={},this.outOfDate=new Set}handle(e){if(Fe.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type&&"content"in e)for(let e of Object.keys(this.chartRuntime))this.outOfDate.add(e);switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const t=this.getters.getChartDefinition(e.id);this.chartRuntime[e.id]=this.mapDefinitionToRuntime(t);break;case"DELETE_FIGURE":delete this.chartRuntime[e.id];break;case"REFRESH_CHART":this.evaluateUsedSheets([e.id]),this.outOfDate.add(e.id);break;case"ACTIVATE_SHEET":const s=this.getters.getChartsIdBySheet(e.sheetIdTo);this.evaluateUsedSheets(s);break;case"DELETE_SHEET":for(let e of Object.keys(this.chartRuntime))this.getters.getChartDefinition(e)||delete this.chartRuntime[e]}}getChartRuntime(e){if(this.outOfDate.has(e)||!(e in this.chartRuntime)){const t=this.getters.getChartDefinition(e);if(void 0===t)return;this.chartRuntime[e]=this.mapDefinitionToRuntime(t),this.outOfDate.delete(e)}return this.chartRuntime[e]}truncateLabel(e){return e?e.length>20?e.substring(0,20)+"…":e:""}getDefaultConfiguration(e,t){const s={};e.labelRange||1!==e.dataSets.length?s.position=e.legendPosition:s.display=!1;const i={type:e.type,options:{legend:s,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:e.title}},data:{labels:t.map(this.truncateLabel),datasets:[]}};return"pie"!==e.type?(i.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{position:e.verticalAxisPosition,ticks:{beginAtZero:!0}}]},"bar"===e.type&&e.stackedBar&&(i.options.scales.xAxes[0].stacked=!0,i.options.scales.yAxes[0].stacked=!0)):i.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},i}getSheetIdsUsedInChart(e){const t=new Set;for(let s of e.dataSets)t.add(s.dataRange.sheetId);return e.labelRange&&t.add(e.labelRange.sheetId),t}evaluateUsedSheets(e){const t=new Set;for(let s of e){const e=this.getters.getChartDefinition(s);(void 0!==e?this.getSheetIdsUsedInChart(e):[]).forEach((e=>{e!==this.getters.getActiveSheetId()&&t.add(e)}))}for(let e of t)this.dispatch("EVALUATE_CELLS",{sheetId:e})}mapDefinitionToRuntime(e){let t=[];if(e.labelRange)e.labelRange.invalidXc||e.labelRange.invalidSheetName||(t=this.getters.getRangeFormattedValues(e.labelRange).flat(1));else if(1===e.dataSets.length)for(let s=0;s<this.getData(e.dataSets[0],e.sheetId).length;s++)t.push("");else if(e.dataSets[0]){t=ms(0,this.getData(e.dataSets[0],e.sheetId).length).map((e=>e.toString()))}const s=this.getDefaultConfiguration(e,t),i=new Nh,o=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.getData(t,e.sheetId).length)));for(let e=0;e<=t;e++)o.push(i.next())}for(const[t,n]of Object.entries(e.dataSets)){let r;if(n.labelCell){const e=n.labelCell,s=e?this.getters.getCell(e.sheetId,e.zone.left,e.zone.top):void 0;r=s&&e?this.truncateLabel(s.formattedValue):r=`${uc.Series} ${parseInt(t)+1}`}else r=r=`${uc.Series} ${parseInt(t)+1}`;const a="pie"!==e.type?i.next():"#FFFFFF",l={label:r,data:n.dataRange?this.getData(n,e.sheetId):[],lineTension:0,borderColor:a,backgroundColor:a};"pie"===e.type&&(l.backgroundColor=o),s.data.datasets.push(l)}return s}getData(e,t){if(e.dataRange){const t=e.labelCell?[Ds(e.labelCell.zone)]:[],s=Zs([Ds(e.dataRange.zone)],t)[0];if(void 0===s)return[];const i=this.getters.getRangeFromSheetXC(e.dataRange.sheetId,s);return this.getters.getRangeValues(i).flat(1)}return[]}}kh.getters=["getChartRuntime"],kh.modes=["normal"];class Fh extends Ch{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new ni,this.rulePredicate={CellIsRule:(e,t)=>{var s,i,o,n,r,l;if(e&&e.evaluated.type===ke.error)return!1;const c=t.values.map(Yr);switch(t.operator){case"IsEmpty":return!Ms(e)||""===(null===(s=e.evaluated.value)||void 0===s?void 0:s.toString().trim());case"IsNotEmpty":return Ms(e)&&""!==(null===(i=e.evaluated.value)||void 0===i?void 0:i.toString().trim());case"BeginsWith":return!(!e&&""===c[0])&&(Ms(e)&&(null===(o=e.evaluated.value)||void 0===o?void 0:o.toString().startsWith(c[0].toString())));case"EndsWith":return!(!e&&""===c[0])&&(Ms(e)&&(null===(n=e.evaluated.value)||void 0===n?void 0:n.toString().endsWith(c[0].toString())));case"Between":return Ms(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1];case"NotBetween":return!(Ms(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1]);case"ContainsText":return Ms(e)&&(null===(r=e.evaluated.value)||void 0===r?void 0:r.toString().indexOf(c[0].toString()))>-1;case"NotContains":return!Ms(e)||!e.evaluated.value||-1==(null===(l=e.evaluated.value)||void 0===l?void 0:l.toString().indexOf(c[0].toString()));case"GreaterThan":return Ms(e)&&e.evaluated.value>c[0];case"GreaterThanOrEqual":return Ms(e)&&e.evaluated.value>=c[0];case"LessThan":return Ms(e)&&e.evaluated.value<c[0];case"LessThanOrEqual":return Ms(e)&&e.evaluated.value<=c[0];case"NotEqual":return!(!Ms(e)&&""===c[0])&&(Ms(e)&&e.evaluated.value!==c[0]);case"Equal":return!e&&""===c[0]||Ms(e)&&e.evaluated.value===c[0];default:console.warn(a("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch(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 s=this.getters.getActiveSheetId(),i=this.getters.getRulesByCell(s,e.originCol,e.originRow);for(const t of i)this.adaptRules(s,t,[os(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation);break;case"DUPLICATE_SHEET":case"CREATE_SHEET":case"DELETE_SHEET":case"ADD_CONDITIONAL_FORMAT":case"REMOVE_CONDITIONAL_FORMAT":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":case"DELETE_CELL":case"INSERT_CELL":this.isStale=!0}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getConditionalStyle(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedStyles[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}getConditionalIcon(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedIcons[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const s=this.computedStyles[t];for(let i of this.getters.getConditionalFormats(t))switch(i.rule.type){case"ColorScaleRule":for(let e of i.ranges)this.applyColorScale(e,i.rule);break;case"IconSetRule":for(let e of i.ranges)this.applyIcon(e,i.rule);break;default:for(let o of i.ranges){const n=Fs(o);for(let o=n.top;o<=n.bottom;o++)for(let r=n.left;r<=n.right;r++){const n=this.rulePredicate[i.rule.type];let a=this.getters.getCell(t,r,o);n&&n(a,i.rule)&&(s[r]||(s[r]=[]),s[r][o]=Object.assign((null===(e=s[r])||void 0===e?void 0:e[o])||{},i.rule.style))}}}}parsePoint(e,t,s){switch(t.type){case"value":return this.getters.evaluateFormula(`=${s}(${e})`);case"number":return Number(t.value);case"percentage":const i=this.getters.evaluateFormula(`=min(${e})`);return i+(this.getters.evaluateFormula(`=max(${e})`)-i)*Number(t.value)/100;case"percentile":return this.getters.evaluateFormula(`=PERCENTILE(${e},${Number(t.value)/100})`);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof o?o:null;default:return null}}applyIcon(e,t){const s=this.parsePoint(e,t.lowerInflectionPoint),i=this.parsePoint(e,t.upperInflectionPoint);if(null===s||null===i||s>i)return;const o=Fs(e),n=this.getters.getActiveSheetId(),r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=o.top;e<=o.bottom;e++)for(let l=o.left;l<=o.right;l++){const o=this.getters.getCell(n,l,e);if((null==o?void 0:o.evaluated.type)!==ke.number)continue;const c=this.computeIcon(o.evaluated.value,i,t.upperInflectionPoint.operator,s,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,s,i,o,n){return"ge"===s&&e>=t||"gt"===s&&e>t?n[0]:"ge"===o&&e>=i||"gt"===o&&e>i?n[1]:n[2]}applyColorScale(e,t){var s;const i=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,n=this.parsePoint(e,t.maximum,"max");if(null===i||null===n||i>=n||o&&(i>=o||o>=n))return;const r=Fs(e),a=this.getters.getActiveSheetId(),l=this.computedStyles[a],c=[];t.midpoint&&o?(c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.midpoint.color,t.maximum.color)})):c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,n,t.minimum.color,t.maximum.color)});for(let e=r.top;e<=r.bottom;e++)for(let t=r.left;t<=r.right;t++){const r=this.getters.getCell(a,t,e);if((null==r?void 0:r.evaluated.type)===ke.number){const a=gs(r.evaluated.value,i,n);let h;h=2===c.length&&o?a<=o?this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(a,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(s=l[t])||void 0===s?void 0:s[e])||{},l[t][e].fillColor="#"+Yt(h)}}}computeColorDiffUnits(e,t,s,i){const o=t-e;return[((s>>16)%256-(i>>16)%256)/o,((s>>8)%256-(i>>8)%256)/o,(s%256-i%256)/o]}colorCell(e,t,s,i){const[o,n,r]=i;return Math.round((s>>16)%256-o*(e-t))<<16|Math.round((s>>8)%256-n*(e-t))<<8|Math.round(s%256-r*(e-t))}adaptRules(e,t,s,i){if(0===s.length&&0===i.length)return;const o=this.getters.getConditionalFormats(e),n=o.findIndex((e=>e.id===t.id));let r=[];n>-1&&(r=o[n].ranges),r=r.concat(s);const a=Zs(r,i);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},target:a.map(Fs),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,s){const i=os(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let n of o.ranges)if(zs(e.col,e.row,Fs(n))){const n=o,r=[];if("CUT"===s&&r.push(os(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,n,[i],r);else{this.adaptRules(e.sheetId,n,[],r);const s=this.getCFToCopyTo(t.sheetId,n);this.adaptRules(t.sheetId,s,[i],[])}}}getCFToCopyTo(e,t){const s=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&_s(e.rule,t.rule)));return s||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}Fh.getters=["getConditionalStyle","getConditionalIcon"],Fh.modes=["normal"];var $h;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}($h||($h={}));class Dh extends Ch{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1},this.toSearch=""}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell($h.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell($h.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith,e.replaceOptions);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith,e.replaceOptions);break;case"ACTIVATE_SHEET":case"REFRESH_SEARCH":this.refreshSearch()}}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($h.current)}updateRegex(){let e=ds(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),s=[];if(this.toSearch)for(const e of Object.values(t))if(e&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas?e.content:String(e.evaluated.value))){const t=this.getters.getCellPosition(e.id),i={col:t.col,row:t.row,selected:!1};s.push(i)}return s.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 s;s=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,s=(s%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===s||(this.selectedMatchIndex=s,this.dispatch("SELECT_CELL",{col:t[s].col,row:t[s].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},this.replaceOptions={modifyFormulas:!1}}replace(e,t){if(this.replaceOptions=t,null===this.selectedMatchIndex||!this.currentSearchRegex)return;const s=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),o=this.getters.getCell(i,s.col,s.row),n=this.toReplace(o,i);if(o&&n){const t=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),i=n.toString().replace(t,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:s.col,row:s.row,content:i}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell($h.current)}else this.selectNextCell($h.next)}replaceAll(e,t){const s=this.searchMatches.length;for(let i=0;i<s;i++)this.replace(e,t)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.replaceOptions.modifyFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t,viewport:s}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge(i,e.col,e.row),n=o?o.left:e.col,r=o?o.right:e.col,a=o?o.top:e.row,l=o?o.bottom:e.row,[c,h,d,u]=this.getters.getRect({top:a,left:n,right:r,bottom:l},s);d>0&&u>0&&(t.fillStyle="#8B008B33",t.fillRect(c,h,d,u),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(c,h,d,u)))}}}Dh.layers=[3],Dh.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Uh extends Ch{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,s){const i=this.searchNumberFormat(e,t);if(void 0!==i){const o=this.changeDecimalFormat(i,s);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var s;for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++){const i=this.getters.getCell(e,o,t);if((null==i?void 0:i.evaluated.type)===ke.number&&!(null===(s=i.format)||void 0===s?void 0:s.match(A)))return i.format||this.setDefaultNumberFormat(i.evaluated.value)}}setDefaultNumberFormat(e){const t=e.toString().split(".");return 1===t.length?"0":"0."+Array(t[1].length+1).join("0")}changeDecimalFormat(e,t){const s=Math.sign(t),i=e.split(";");let o=[];for(let e of i){const t=e.indexOf("."),i=e.toUpperCase().indexOf("E");let n;const r=i>-1?e.slice(0,i):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?s>0?n=a<ne?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(n=e.slice(0,l)+e.slice(l+1),1===a&&(n=n.slice(0,t)+n.slice(t+1))):n=e:n=e,o.push(n)}return o.join(";")}}Uh.modes=["normal"];class Ph extends Ch{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){if(0===e.length)return[];const t=this.getters.getActiveSheetId(),s=[];for(let[i,o]of e){const{xc:e,sheetName:n}=ts(i),r=n?this.getters.getSheetIdByName(n):t;if(r){let i=Fs(e);const{height:n,width:a}=qs(i);i=n*a==1?this.getters.expandZone(t,Fs(e)):i,s.push({zone:i,color:o,sheet:r})}}return s.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getSheet(e.sheet).rows.length&&e.zone.right<this.getters.getSheet(e.sheet).cols.length))}drawGrid(e){const{ctx:t,viewport:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;for(let e of this.getHighlights().filter(((e,t)=>this.getHighlights().findIndex((t=>Vs(t.zone,e.zone)&&t.sheet===o))===t))){const[i,o,r,a]=this.getters.getRect(e.zone,s);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,r-n,a-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,r-2*n,a-2*n))}}}function Bh(e,t){return e.isFormula()&&t?"left":e.defaultAlign}function Vh(e,t){let s=0,i=e.length-1;for(;s<=i;){const o=Math.floor((s+i)/2),n=e[o];if(t<n.start)i=o-1;else if(t>n.end)s=o+1;else{if(!n.isHidden)return o;s+=1}}return-1}Ph.modes=["normal"],Ph.layers=[1],Ph.getters=["getHighlights"];class Hh extends Ch{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t,s){if(e<m)return-1;const i=(s||this.getters.getActiveSheet()).cols;return Vh(i,e-m+i[t].start+1)}getRowIndex(e,t,s){if(e<f)return-1;const i=(s||this.getters.getActiveSheet()).rows;return Vh(i,e-f+i[t].start+1)}getRect(e,t){const{left:s,top:i,right:o,bottom:n}=e;let{offsetY:r,offsetX:a}=t;a-=m,r-=f;const{cols:l,rows:c}=this.getters.getActiveSheet(),h=Math.max(l[s].start-a,m),d=l[o].end-a-h,u=Math.max(c[i].start-r,f);return[h,u,d,c[n].end-r-u]}isVisibleInViewport(e,t,s){const{right:i,left:o,top:n,bottom:r}=s;return t<=r&&t>=n&&e>=o&&e<=i}getEdgeScrollCol(e){let t=!1,s=0,i=0;const{width:o}=this.getters.getViewportDimension(),{width:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{left:r,offsetX:a}=this.getters.getActiveSnappedViewport();return e<m&&r>0?(t=!0,s=-1,i=ls(m-e)):e>o&&a<n-o&&(t=!0,s=1,i=ls(e-o)),{canEdgeScroll:t,direction:s,delay:i}}getEdgeScrollRow(e){let t=!1,s=0,i=0;const{height:o}=this.getters.getViewportDimension(),{height:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{top:r,offsetY:a}=this.getters.getActiveSnappedViewport();return e<f&&r>0?(t=!0,s=-1,i=ls(f-e)):e>o&&a<n-o&&(t=!0,s=1,i=ls(e-o)),{canEdgeScroll:t,direction:s,delay:i}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e);break;case 7:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,top:r,left:a,bottom:l,right:c}=s;const{width:h,height:d}=this.getters.getViewportDimension(),{cols:u,rows:p,id:g}=this.getters.getActiveSheet();if(t.fillStyle="white",t.fillRect(0,0,h,d),o-=m,n-=f,!this.getters.getGridLinesVisibility(g))return;t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();const v=Math.min(d,p[l].end-n);for(let e=a;e<=c;e++){if(u[e].isHidden)continue;const s=u[e].end-o;t.moveTo(s,0),t.lineTo(s,v)}const E=Math.min(h,u[c].end-o);for(let e=r;e<=l;e++){if(p[e].isHidden)continue;const s=p[e].end-n;t.moveTo(0,s),t.lineTo(E,s)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:s}=e;t.lineWidth=.3*s;const i=.1*s;t.strokeStyle="#111";const o=this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());for(let e of this.boxes){let s=e.style;s&&s.fillColor&&"#ffffff"!==s.fillColor&&(t.fillStyle=s.fillColor,t.fillRect(e.x,e.y,e.width,e.height),o&&t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)),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())}}drawBorders(e){const{ctx:t,thinLineWidth:s}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:s,y:o,width:n,height:r}=e;t.left&&i(t.left,s,o,s,o+r),t.top&&i(t.top,s,o,s+n,o),t.right&&i(t.right,s+n,o,s+n,o+r),t.bottom&&i(t.bottom,s,o+r,s+n,o+r)}}function i([e,i],o,n,r,a){t.strokeStyle=i,t.lineWidth=("thin"===e?2:3)*s,t.beginPath(),t.moveTo(o,n),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:s}=e;let i;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const o=e.style||{},n=e.align,r=o.italic?"italic ":"",a=o.bold?"bold":T,l=o.fontSize||x,c=hs[l],h=`${r}${a} ${c}px ${R}`;let d;h!==i&&(i=h,t.font=h),t.fillStyle=o.textColor||"#000";let u=e.y+e.height/2+1;d="left"===n?e.x+(e.image?e.image.size+2*I:4):"right"===n?e.x+e.width-4:e.x+e.width/2,t.textAlign=n,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(d),Math.round(u)),(o.strikethrough||o.underline)&&("right"===n?d-=e.textWidth:"center"===n&&(d-=e.textWidth/2),o.strikethrough&&t.fillRect(d,u,e.textWidth,2.6*s),o.underline&&(u=e.y+e.height/2+1+c/2,t.fillRect(d,u,e.textWidth,1.3*s))),e.clipRect&&t.restore()}}async drawIcon(e){const{ctx:t}=e;for(let e of this.boxes)if(e.image){let s=e.x,i=e.y;const o=e.image.image,n=e.image.size,r=(e.height-n)/2;e.image.clipIcon&&(t.save(),t.beginPath(),t.rect(...e.image.clipIcon),t.clip()),t.drawImage(o,s+I,i+r,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,left:r,top:a,right:l,bottom:p}=s;const{width:g,height:v}=this.getters.getViewportDimension();o-=m,n-=f;const E=this.getters.getSelectedZones(),{cols:S,rows:b}=this.getters.getActiveSheet(),C=this.getters.getActiveCols(),I=this.getters.getActiveRows();t.fillStyle=c,t.font=`400 11px ${R}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333",t.fillRect(0,0,g,f),t.fillRect(0,0,m,v),t.fillStyle=h;for(let e of E){const s=Math.max(m,S[e.left].start-o),i=Math.max(m,S[e.right].end-o),r=Math.max(f,b[e.top].start-n),a=Math.max(f,b[e.bottom].end-n);t.fillStyle=C.has(e.left)?d:h,t.fillRect(s,0,i-s,f),t.fillStyle=I.has(e.top)?d:h,t.fillRect(0,r,m,a-r)}t.beginPath(),t.moveTo(m,0),t.lineTo(m,v),t.moveTo(0,f),t.lineTo(g,f),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=r;e<=l;e++){const s=S[e];s.isHidden||(t.fillStyle=C.has(e)?"#fff":u,t.fillText(s.name,(s.start+s.end)/2-o,13),t.moveTo(s.end-o,0),t.lineTo(s.end-o,f))}for(let e=a;e<=p;e++){const s=b[e];s.isHidden||(t.fillStyle=I.has(e)?"#fff":u,t.fillText(s.name,24,(s.start+s.end)/2-n),t.moveTo(0,s.end-n),t.lineTo(m,s.end-n))}t.stroke()}hasContent(e,t){const s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);return i&&!i.isEmpty()||this.getters.isInMerge(s,e,t)}getGridBoxes(e){const{viewport:t}=e;let{right:s,left:i,top:o,bottom:n,offsetX:r,offsetY:a}=t;r-=m,a-=f;const l=this.getters.shouldShowFormulas(),c=[],{cols:h,rows:d,id:u}=this.getters.getActiveSheet();for(let e=o;e<=n;e++){const t=d[e];if(!t.isHidden)for(let o=i;o<=s;o++){const n=h[o];if(n.isHidden)continue;let d=t.cells[o];const p=this.getters.getCellBorder(u,o,e),g=this.getters.getConditionalStyle(o,e),f=this.getters.getConditionalIcon(o,e);if(!this.getters.isInMerge(u,o,e))if(d){const u=this.getters.getCellText(d,l);let m=this.getters.getCellStyle(d);g&&(m=Object.assign({},m,g));let v=u?m&&m.align||Bh(d,l):void 0,E=null,S=null;const b=this.getters.getTextWidth(d),C=m.fontSize||x,y=hs[C],w=f?y+2*I:0,T=w+b>h[o].size||hs[C]>t.size;if(T&&d.evaluated.type===ke.number&&(v="center"!==v?"left":v),f){const e=n.end-n.start;E=[n.start-r+w,t.start-a,Math.max(0,e-w),t.size],S=[n.start-r,t.start-a,Math.min(w,e),t.size]}else if(T){let l,c;switch(v){case"left":for(l=o;l<s&&!this.hasContent(l+1,e);)l++;c=h[l].end-n.start,(c<b||hs[C]>t.size)&&(E=[n.start-r,t.start-a,c,t.size]);break;case"right":for(l=o;l>i&&!this.hasContent(l-1,e);)l--;c=n.end-h[l].start,(c<b||hs[C]>t.size)&&(E=[h[l].start-r,t.start-a,c,t.size]);break;case"center":let d=o;for(;d>i&&!this.hasContent(d-1,e);)d--;let u=o;for(;u<s&&!this.hasContent(u+1,e);)u++;const p=Math.min(d,o),g=Math.max(u,o);c=h[g].end-h[p].start,(c<b||p===o||g===o||hs[C]>t.size)&&(E=[h[p].start-r,t.start-a,c,t.size])}}c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:u,textWidth:b,border:p,style:m,align:v,clipRect:E,error:d.evaluated.type===ke.error?d.evaluated.error:void 0,image:f?{type:"icon",size:y,clipIcon:S,image:Zl[f].img}:void 0})}else c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:"",textWidth:0,border:p,style:g||null,align:void 0,clipRect:null,error:void 0})}}const p=this.getters.getActiveSheetId();for(let e of this.getters.getMerges(p))if(!this.getters.isMergeHidden(p,e)&&Hs(e,t)){const t=this.getters.getCell(p,e.left,e.top),s=this.getters.getCellBorder(p,e.left,e.top),i=this.getters.getCellBorder(p,e.right,e.bottom),o=h[e.right].end-h[e.left].start;let n,u,g,f,m;if(g=t?this.getters.getCellStyle(t):null,t||i||s){n=t?this.getters.getCellText(t,l):"",u=t?this.getters.getTextWidth(t):null;const o=this.getters.getConditionalStyle(e.topLeft.col,e.topLeft.row);o&&(g=Object.assign({},g,o)),f=n?g&&g.align||Bh(t,l):null,m={bottom:i?i.bottom:null,left:s?s.left:null,right:i?i.right:null,top:s?s.top:null}}g=g||{},g.fillColor&&"#ffffff"!==g.fillColor||(g=Object.create(g),g.fillColor="#fff");const v=h[e.left].start-r,E=d[e.top].start-a,S=d[e.bottom].end-d[e.top].start,b=this.getters.getConditionalIcon(e.left,e.top),C=g.fontSize||x,y=hs[C],w=b?2*I+y:0,T=w+u;f=n&&(null==t?void 0:t.evaluated.type)===ke.number&&T>o&&"center"!==f?"left":f;const R=b?[v+w,E,Math.max(0,o-w),S]:[v,E,o,S],L=b?[v,E,Math.min(w,o),S]:null;c.push({x:v,y:E,width:o,height:S,text:n,textWidth:u,border:m,style:g,align:f,clipRect:R,error:t&&t.evaluated.type===ke.error?t.evaluated.error:void 0,image:b?{type:"icon",clipIcon:L,size:y,image:Zl[b].img}:void 0})}return c}}Hh.layers=[0,7],Hh.getters=["getColIndex","getRowIndex","getRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow"],Hh.modes=["normal"];const zh=new ni;class Zh extends Ch{constructor(){super(...arguments),this.inputs={},this.activeSheets={},this.inputHasSingleRange={},this.focusedInputId=null,this.focusedRange=null,this.willAddNewRange=!1}allowDispatch(e){switch(e.type){case"FOCUS_RANGE":const t=this.getIndex(e.id,e.rangeId);if(this.focusedInputId===e.id&&this.focusedRange===t)return 24;break;case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange[e.id]&&1===this.inputs[e.id].length)return 25}return 0}handle(e){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],delete this.activeSheets[e.id],delete this.inputHasSingleRange[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(e.id,this.getIndex(e.id,e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.id,e.rangeId);if(null!==t){const s=e.id;this.focusedInputId===s&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:s,rangeId:this.inputs[s][t].id});const i=e.value.split(",").map((e=>e.trim()));this.setRange(s,t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(e.id,this.inputs[e.id].length,[""]),this.focusLast(e.id);break;case"REMOVE_RANGE":const t=this.getIndex(e.id,e.rangeId);null!==t&&this.removeRange(e.id,t);break;case"SELECT_CELL":case"SET_SELECTION":if(!this.focusedInputId)break;const s=this.getSelectionInputValue(this.focusedInputId),i=(this.inputHasSingleRange[this.focusedInputId]?[this.getters.getSelectedZone()]:this.getters.getSelectedZones()).map(Ds).filter((e=>!s.includes(e))),o=this.activeSheets[this.focusedInputId],n=this.getters.getActiveSheetId(),r=this.getters.getSheetName(n);this.add(i.map((e=>n===o?e:`${ps(r)}!${e}`)));break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInputId,this.focusedRange];null===e||null===t||this.inputHasSingleRange[e]||(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,s)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.focusedRange&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.focusedRange===s}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:s}=ts(e);return null!==t.match(es)&&(!s||void 0!==this.getters.getSheetIdByName(s))}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].map((e=>this.inputToHighlights(this.focusedInputId,e))).flat():[]}initInput(e,t,s=!1){this.inputs[e]=[],this.insertNewRange(e,0,t),this.activeSheets[e]=this.getters.getActiveSheetId(),this.inputHasSingleRange[e]=s,0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){this.focusedInputId=e,this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}unfocus(){this.focusedInputId=null,this.focusedRange=null}add(e){if(null===this.focusedInputId||null===this.focusedRange||this.getters.isSelectingForComposer()||0===e.length)return;if(this.getters.getSelectionMode()===xh.expanding&&this.willAddNewRange){const t=this.focusedInputId;this.insertNewRange(t,this.inputs[t].length,e),this.focusLast(this.focusedInputId),this.willAddNewRange=!1}else this.setRange(this.focusedInputId,this.focusedRange,e)}setContent(e,t,s){this.inputs[e][t]={...this.inputs[e][t],id:zh.uuidv4(),xc:s}}insertNewRange(e,t,s){this.inputs[e].splice(t,0,...s.map(((t,s)=>({xc:t,id:(this.inputs[e].length+s+1).toString(),color:Kt()}))))}setRange(e,t,s){const[,...i]=s;this.setContent(e,t,s[0]),this.insertNewRange(e,t+1,i),i.length&&this.focus(e,t+i.length)}removeRange(e,t){this.inputs[e].splice(t,1),this.focusedInputId===e&&null!==this.focusedRange&&this.focusLast(e)}inputToHighlights(e,{xc:t,color:s}){const i=this.cleanInputs([t]).filter((e=>this.isRangeValid(e))).filter((t=>this.shouldBeHighlighted(this.activeSheets[e],t)));if(0===i.length)return[];const[o,...n]=i,r=[[o,s||Kt()]];for(const e of n)r.push([e,Kt()]);return r}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:s}=ts(t),i=this.getters.getSheetIdByName(s),o=this.getters.getActiveSheet().id;return this.isRangeValid(t)&&(i===o||void 0===i&&o===e)}getIndex(e,t){const s=this.inputs[e].findIndex((e=>e.id===t));return s>=0?s:null}}Zh.modes=["normal"],Zh.layers=[1],Zh.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Gh{constructor(){this.bus=new i.core.EventBus}on(e,t,s){this.bus.on(e,t,s)}trigger(e,t){this.bus.trigger(e,t)}off(e,t){this.bus.off(e,t)}clear(){this.bus.clear()}}function Wh(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?function(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<=r&&e[i]>=r&&n--;if(!(o>n))return{...e,[t]:o,[i]:n}}(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?function(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom",l="before"===i?e[a]>r:e[a]>=r;return e[t]<=r&&l?Xs(e,n,"RESIZE",o):r<e[t]?Xs(e,n,"MOVE",o):{...e}}(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function qh(e,t){const s=e.definition;let i,o;return s.labelRange&&(i=Wh(Fs(s.labelRange),t)),s.dataSets&&(o=s.dataSets.map(Fs).map((e=>Wh(e,t))).filter(Ms).map(Ds)),{...e,definition:{...s,dataSets:o,labelRange:i?Ds(i):void 0}}}ml.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],qh),ml.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],qh),ml.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),ml.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var s;if(e.name===t.name)return{...e,name:(null===(s=e.name)||void 0===s?void 0:s.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),ml.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const s=[];for(const i of e.target)for(const e of t.target)Hs(i,e)||s.push({...i});if(s.length)return{...e,target:s};return}));const jh=[{match:function(e){return"sheetId"in e},fn:function(e,t){const s="DELETE_SHEET"===t.type&&t.sheetId;if(e.sheetId===s)return"IGNORE_COMMAND";if("CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId)return e;return"SKIP_TRANSFORMATION"}},{match:function(e){return"target"in e},fn:function(e,t){const s=[];for(const i of e.target){const e=Wh(i,t);e&&s.push(e)}if(!s.length)return"IGNORE_COMMAND";return{...e,target:s}}},{match:function(e){return"col"in e&&"row"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const s="COL"===t.dimension?"col":"row";let i=e[s];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(i))return"IGNORE_COMMAND";for(let t of e)i>=t&&i--}"ADD_COLUMNS_ROWS"===t.type&&(i>t.base||i===t.base&&"before"===t.position)&&(i+=t.quantity);return{...e,[s]:i}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const s of t.target){if(!(e.col===s.left&&e.row===s.top)&&zs(e.col,e.row,s))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const s="ADD_COLUMNS_ROWS"===e.type,i=s?"base":"elements";let o=s?[e[i]]:e[i];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const s=t.elements.sort(((e,t)=>t-e));for(let t of s)e>t&&e--;return e})).filter(Ms)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((s=>s>e?s+t.quantity:s))}if(o.length){let t=o;return s&&(t=o[0]),{...e,[i]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}}];function Yh(e,t){const s=ml.getTransformation(e.type,t.type);return s?s(e,t):function(e,t){for(const{match:s,fn:i}of jh)if(s(e)){const s=i(e,t);if("SKIP_TRANSFORMATION"===s)continue;if("IGNORE_COMMAND"===s)return;return s}return e}(e,t)}function Xh(e,t){let s=[...e];for(const e of t)s=s.map((t=>Yh(t,e))).filter(Ms);return s}class Kh{constructor(e,t,s,i){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...s],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Qh extends Error{}class Jh extends Gh{constructor(e,t,s=O){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=s,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new ni,this.debouncedMove=i.utils.debounce(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const s=new Kh(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(s.id,s),this.trigger("new-local-state-update",{id:s.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:s.id,clientId:s.clientId,commands:s.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 Qh("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Ms))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const s=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==s?void 0:s.col)===e.col&&s.row===e.row&&s.sheetId===e.sheetId)return;const i=s?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:i,version:1,client:{...o,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:s}=e,i=new Kh(e.nextRevisionId,t,s);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:Xh(s,t)})}break;case"SNAPSHOT_CREATED":{const t=new Kh(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){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 ed=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class td extends Ch{constructor(){super(...arguments),this.availableColors=new Set(ed),this.colors={}}isPositionValid(e){const t=this.getters.getSheet(e.sheetId);return e.row<t.rows.length&&e.col<t.cols.length}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(ed));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 Qh)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const s of this.getters.getConnectedClients())if(s.id!==this.getters.getClient().id&&s.position&&s.position.sheetId===e&&this.isPositionValid(s.position)){const e=s.position;this.colors[s.id]||(this.colors[s.id]=this.chooseNewColor());const i=this.colors[s.id];t.push({...s,position:e,color:i})}return t}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:r}=e.position,a=this.getters.expandZone(o,{top:n,bottom:n,left:r,right:r}),[l,c,h,d]=this.getters.getRect(a,t);if(h<=0||d<=0)continue;const u=e.color,p=`${u}10`;s.fillStyle=p,s.lineWidth=4*i,s.strokeStyle=u,s.globalCompositeOperation="multiply",s.fillRect(l,c,h,d),s.globalCompositeOperation="source-over",s.strokeRect(l,c,h,d),s.font=`bold ${x+1}px ${R}`}}}td.getters=["getClientsToDisplay"],td.layers=[5],td.modes=["normal"];class sd extends Ch{allowDispatch(e){if("SORT_CELLS"===e.type){if(!zs(e.anchor[0],e.anchor[1],e.zone))throw new Error(a("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)e.interactive?this.interactiveSortSelection(e.sheetId,e.anchor,e.zone,e.sortDirection):this.sortZone(e.sheetId,e.anchor,e.zone,e.sortDirection)}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let s=t.top;s<=t.bottom;s++)for(let i=t.left;i<=t.right;i++)if(!this.getters.isInMerge(e,i,s))return 48;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const s=this.getters.getMerges(e).filter((e=>Hs(e,t))),i=qs(s[0]);let[o,n]=[i.width,i.height];return s.every((e=>{let[t,s]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&s===n}))?0:48}interactiveSortSelection(e,t,s,i){let o=Pe.Success,n=s.right>s.left;if(this.getters.doesIntersectMerge(e,s)){let t;n=!1;for(let i=s.top;i<=s.bottom;i++){t=[];for(let o=s.left;o<=s.right;o++){let s=this.getters.getMerge(e,o,i);s&&!t.includes(s.id.toString())&&t.push(s.id.toString())}if(t.length>=2){n=!0;break}}}if(n)o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i});else{const n=this.getContiguousZone(e,s);Vs(n,s)?o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i}):this.ui.askConfirmation(a("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>{s=n,o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}),(()=>{o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}))}o.isCancelledBecause(48)&&(this.dispatch("SET_SELECTION",{anchor:t,zones:[s],anchorZone:s}),this.ui.notifyUser(a("Cannot sort. To sort, select only cells or only merges that have the same size.")))}expand(e,t){const{left:s,right:i,top:o,bottom:n}=this.getters.expandZone(e.id,t);return{left:Math.max(0,s),right:Math.min(e.cols.length-1,i),top:Math.max(0,o),bottom:Math.min(e.rows.length-1,n)}}checkExpandedValues(e,t){const s=this.expand(e,t),i=e.id;let o,n=[];if(this.getters.doesIntersectMerge(i,s)){const{left:e,right:t,top:r,bottom:a}=s;for(let s=e;s<=t;s++)for(let e=r;e<=a;e++){const[t,r]=this.getters.getMainCell(i,s,e);o=this.getters.getCell(i,t,r),n.push((null==o?void 0:o.formattedValue)||"")}}else{const t=Ws(s,e,(e=>e.formattedValue),"");n=t.flat()}return n.some((e=>""!==e))}getContiguousZone(e,t){let s,{top:i,bottom:o,left:n,right:r}=t;const a=this.getters.getSheet(e);let l=!1;for(;!l;)l=!0,i>0&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:i-1,bottom:i-1}),s&&(l=!1,i--)),n>0&&(s=this.checkExpandedValues(a,{left:n-1,right:n-1,top:i-1,bottom:o+1}),s&&(l=!1,n--)),r<a.cols.length-1&&(s=this.checkExpandedValues(a,{left:r+1,right:r+1,top:i-1,bottom:o+1}),s&&(l=!1,r++)),o<a.rows.length-1&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:o+1,bottom:o+1}),s&&(l=!1,o++));return{left:n,right:r,top:i,bottom:o}}hasHeader(e,t,s,i){const{left:o,right:n,top:r,bottom:a}=t;if(a-r+1==1)return!1;let l=Ws({left:o,right:n,top:r,bottom:r+2*i-1},e,(e=>e.evaluated.type),ke.empty,s,i);return l[0][0]===ke.empty&&(l=l.slice(1)),!l.some((e=>e[0]===ke.empty))&&!!l.some((e=>e[1]!==ke.empty&&e[0]!==e[1]))}sortCellsList(e,t){const s=e.map(((e,t)=>({index:t,val:e}))),i=s.filter((e=>!(null==e.val||""===e.val.evaluated.value))),o=s.filter((e=>null==e.val||""===e.val.evaluated.value)),n="descending"===t?-1:1,r=[ke.number,ke.error,ke.text,ke.boolean];return i.map((e=>{return{index:e.index,val:(t=e.val,{type:t.evaluated.type,value:t.evaluated.value})};var t})).sort(((e,t)=>{let s=r.indexOf(e.val.type)-r.indexOf(t.val.type);return 0===s&&(s=e.val.type===ke.text||e.val.type===ke.error?e.val.value.localeCompare(t.val.value):e.val.value-t.val.value),n*s})).concat(o)}sortZone(e,t,s,i){let o=1,n=1,r=t[0],a=Object.assign({},s);if(this.getters.doesIntersectMerge(e,a)){const[s,i]=t,a=this.getters.getMerge(e,s,i);o=a.right-a.left+1,n=a.bottom-a.top+1,r=a.topLeft.col}const l=this.getters.getSheet(e);this.hasHeader(l,a,o,n)&&(a.top+=n);const c=Ws(a,l,(e=>e),void 0,o,n),h=c[r-a.left],d=this.sortCellsList(h,i).map((e=>e.index)),[u,p]=[c.length,c[0].length];for(let t=0;t<u;t++)for(let s=0;s<p;s++){let i=c[t][d[s]],r=a.left+t*o,l=a.top+s*n,h={sheetId:e,col:r,row:l,content:"",value:""};if(i){let t=i.content;if(i.isFormula()){const s=l-this.getters.getCellPosition(i.id).row,o=this.getters.createAdaptedRanges(i.dependencies.references,0,s,e);t=this.getters.buildFormulaContent(e,i.normalizedText,{...i.dependencies,references:o})}h.style=i.style,h.content=t,h.format=i.format,h.value=i.evaluated.value}this.dispatch("UPDATE_CELL",h)}}}sd.getters=["getContiguousZone"];class id extends Ch{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}id.modes=["normal"],id.getters=["shouldShowFormulas"];class od extends Ch{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":case"DELETE_SHEET_CONFIRMATION":try{this.getters.getSheet(e.sheetId);break}catch(e){return 23}}return 0}handle(e){switch(e.type){case"RENAME_SHEET":e.interactive&&this.interactiveRenameSheet(e.sheetId,a("Rename Sheet"));break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheetId);break;case"ADD_MERGE":e.interactive&&this.interactiveMerge(e.sheetId,e.target);break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const s=this.getColMaxWidth(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:s+6,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const s=this.getRowMaxHeight(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:s+6,sheetId:e.sheetId})}}}getCellWidth(e){let t=this.getTextWidth(e);const s=this.getters.getCellPosition(e.id);return this.getters.getConditionalIcon(s.col,s.row)&&(t+=function(e,t){const s=t.fontSize||x;return hs[s]+2*I}(this.ctx,this.getters.getCellStyle(e))),t}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas());return fs(this.ctx,t,this.getters.getCellStyle(e))}getCellHeight(e){const t=this.getters.getCellStyle(e).fontSize||x;return hs[t]}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===ke.error)?e.content:e.formattedValue}getColMaxWidth(e,t){const s=this.getters.getColCells(e,t).map((e=>this.getCellWidth(e)));return Math.max(0,Os(s))}getRowMaxHeight(e,t){const s=this.getters.getSheet(e),i=Object.values(s.rows[t].cells).map((e=>this.getCellHeight(e)));return Math.max(0,Os(i))}interactiveRenameSheet(e,t){const s=this.getters.getSheetName(e);this.ui.editText(t,s,(t=>{if(!t)return;const s=this.dispatch("RENAME_SHEET",{sheetId:e,name:t}),i=this.getters.getSheetName(e);s.isSuccessful||i===t||this.interactiveRenameSheet(e,a("Please enter a valid sheet name"))}))}interactiveDeleteSheet(e){this.ui.askConfirmation(a("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheetId:e})}))}interactiveMerge(e,t){const s=this.dispatch("ADD_MERGE",{sheetId:e,target:t});s.isSuccessful||s.isCancelledBecause(3)&&this.ui.askConfirmation(a("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheetId:e,target:t,force:!0})}))}}od.getters=["getCellWidth","getCellHeight","getTextWidth","getCellText"];class nd extends Ch{constructor(){super(...arguments),this.viewports={},this.snappedViewports={},this.updateSnap=!1,this.clientWidth=1e3,this.clientHeight=1e3}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkOffsetValidity(e.offsetX,e.offsetY);case"RESIZE_VIEWPORT":return e.width<0||e.height<0?54:0;default:return 0}}handle(e){switch(e.type){case"UNDO":case"REDO":this.cleanViewports(),this.resetViewports();break;case"RESIZE_VIEWPORT":this.cleanViewports(),this.resizeViewport(e.height,e.width);break;case"SET_VIEWPORT_OFFSET":this.setViewportOffset(e.offsetX,e.offsetY);break;case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportOffsetX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportOffsetY(e.sheetId,this.getViewport(e.sheetId));break;case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportZoneX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportZoneY(e.sheetId,this.getViewport(e.sheetId));break;case"ACTIVATE_SHEET":this.refreshViewport(e.sheetIdTo);break;case"SELECT_CELL":case"MOVE_POSITION":this.refreshViewport(this.getters.getActiveSheetId())}}finalize(){this.updateSnap&&(this.snapViewportToCell(this.getters.getActiveSheetId()),this.updateSnap=!1)}getViewportDimension(){return{width:this.clientWidth,height:this.clientHeight}}getActiveViewport(){const e=this.getters.getActiveSheetId();return this.getViewport(e)}getActiveSnappedViewport(){const e=this.getters.getActiveSheetId();return this.getSnappedViewport(e)}getGridDimension(e){const t=li(e,"cols"),s=this.clientWidth-m,i=li(e,"rows"),o=this.clientHeight-f,n=e.cols.find((e=>e.end>t.end-s))||e.cols[e.cols.length-1],r=e.rows.find((e=>e.end>i.end-o))||e.rows[e.rows.length-1];return{width:t.end+Math.max(E,Math.min(n.size,s-t.size)),height:i.end+Math.max(S+5,Math.min(r.size,o-i.size))}}getMaximumViewportOffset(e){const{width:t,height:s}=this.getters.getGridDimension(e);return{maxOffsetX:Math.max(0,t-this.clientWidth+m+1),maxOffsetY:Math.max(0,s-this.clientHeight+f+1)}}checkOffsetValidity(e,t){const s=this.getters.getActiveSheet(),{maxOffsetX:i,maxOffsetY:o}=this.getMaximumViewportOffset(s);return e<0||t<0||t>o||e>i?53:0}getSnappedViewport(e){return this.snapViewportToCell(e),this.snappedViewports[e]}getViewport(e){return this.viewports[e]?this.viewports[e]:this.generateViewportState(e)}cleanViewports(){const e=this.getters.getVisibleSheets();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetViewports(){for(let[e,t]of Object.entries(this.viewports))this.adjustViewportOffsetX(e,t),this.adjustViewportOffsetY(e,t),this.adjustViewportsPosition(e)}adjustViewportOffsetX(e,t){const{offsetX:s}=t,{width:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientWidth-m+s>i){const e=this.clientWidth-m+s-i;t.offsetX=Math.max(0,s-e)}this.adjustViewportZoneX(e,t)}adjustViewportOffsetY(e,t){const{offsetY:s}=t,{height:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientHeight-f+s>i){const e=this.clientHeight-f+s-i;t.offsetY=Math.max(0,s-e)}this.adjustViewportZoneY(e,t)}resizeViewport(e,t){this.clientHeight=e,this.clientWidth=t,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.adjustViewportOffsetX(e,this.viewports[e]),this.adjustViewportOffsetY(e,this.viewports[e])}setViewportOffset(e,t){const s=this.getters.getActiveSheetId();this.getActiveViewport(),this.viewports[s].offsetX=e,this.viewports[s].offsetY=t,this.adjustViewportZone(s,this.viewports[s])}generateViewportState(e){return this.viewports[e]={left:0,right:0,top:0,bottom:0,offsetX:0,offsetY:0},this.viewports[e]}refreshViewport(e){const t=this.getViewport(e);this.adjustViewportZone(e,t),this.adjustViewportsPosition(e)}adjustViewportZone(e,t){this.adjustViewportZoneX(e,t),this.adjustViewportZoneY(e,t)}adjustViewportZoneX(e,t){const s=this.getters.getSheet(e),i=s.cols;t.left=this.getters.getColIndex(t.offsetX+m,0,s);const o=this.clientWidth+t.offsetX-m;t.right=i.length-1;for(let e=t.left;e<i.length;e++)if(o<i[e].end){t.right=e;break}this.updateSnap=!0}adjustViewportZoneY(e,t){const s=this.getters.getSheet(e),i=s.rows;t.top=this.getters.getRowIndex(t.offsetY+f,0,s);const o=this.clientHeight+t.offsetY-f;t.bottom=i.length-1;for(let e=t.top;e<i.length;e++)if(o<i[e].end){t.bottom=e;break}this.updateSnap=!0}adjustViewportsPosition(e,t){const s=this.getters.getSheet(e),{cols:i,rows:o}=s,n=this.getSnappedViewport(e);t=t||this.getters.getSheetPosition(e);const[r,a]=ri(s,...this.getters.getMainCell(e,t[0],t[1]));for(;i[r].end>n.offsetX+this.clientWidth-m&&n.offsetX<i[r].start;)n.offsetX=i[n.left].end,this.adjustViewportZoneX(e,n);for(;r<n.left;){const t=i.slice(0,n.left).reverse().findIndex((e=>!e.isHidden));n.offsetX=i[n.left-1-t].start,this.adjustViewportZoneX(e,n)}for(;o[a].end>n.offsetY+this.clientHeight-f&&n.offsetY<o[a].start;)n.offsetY=o[n.top].end,this.adjustViewportZoneY(e,n);for(;a<n.top;){const t=o.slice(0,n.top).reverse().findIndex((e=>!e.isHidden));n.offsetY=o[n.top-1-t].start,this.adjustViewportZoneY(e,n)}const{top:l,left:c}=this.viewports[e];l===n.top&&c===n.left||(this.viewports[e]=n),this.updateSnap=!1}snapViewportToCell(e){const{cols:t,rows:s}=this.getters.getSheet(e),i=this.getViewport(e),o=Object.assign({},i);this.adjustViewportOffsetX(e,o),this.adjustViewportOffsetY(e,o),o.offsetX=t[o.left].start,o.offsetY=s[o.top].start,this.adjustViewportZone(e,o),this.snappedViewports[e]=o}}nd.getters=["getActiveViewport","getSnappedViewport","getActiveSnappedViewport","getViewportDimension","getGridDimension","getMaximumViewportOffset"],nd.modes=["normal"];const rd=(new Le).add("sheet",La).add("cell",Ca).add("merge",xa).add("borders",Ea).add("conditional formatting",wa).add("figures",Ta).add("chart",Ia),ad=(new Le).add("selection",Rh).add("ui_sheet",od).add("ui_options",id).add("evaluation",_h).add("evaluation_cf",Fh).add("evaluation_chart",kh).add("clipboard",Th).add("edition",Mh).add("highlight",Ph).add("selectionInput",Zh).add("viewport",nd).add("grid renderer",Hh).add("autofill",yh).add("find_and_replace",Dh).add("sort",sd).add("automatic_sum",wh).add("format",Uh).add("selection_multiuser",td);class ld{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}class cd extends i.core.EventBus{constructor(){super(...arguments),this.registry=new Le}add(e,t){this.registry.add(e,t);const s=i.utils.debounce((()=>this.trigger("data-loaded",{id:e})),0);return t.on("data-loaded",this,(()=>s())),t.loadMetadata(),this}get(e){return this.registry.get(e)}getAll(){return this.registry.getAll()}remove(e){this.get(e).off("data-loaded",this),this.registry.remove(e)}async waitForReady(){const e=[];for(const t of this.getAll())e.push(t.get());return Promise.all(e)}}class hd extends i.core.EventBus{async loadMetadata(){this.metadataPromise||(this.metadataPromise=this._fetchMetadata().then((e=>(this.metadata=e,e)))),await this.metadataPromise}async get(e){return e&&e.forceFetch&&(this.data=void 0,this.dataPromise=void 0),await this.loadMetadata(),this.dataPromise||(this.dataPromise=this._fetch(e).then((e=>(this.data=e,this.lastUpdate=Date.now(),this.trigger("data-loaded"),e)))),this.dataPromise}getSync(){return this.data}getMetadataSync(){return this.metadata}getLastUpdate(){return this.lastUpdate}}function dd(e){return Oa.get(e.type)(e)}function ud(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class pd{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const s of this.operations){if(s.id===e)return e;if(s.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const s=this.buildTransformation.with(e.data),{before:i,operation:o,after:n}=this.locateOperation(t);this.operations=[...i,o,e,...n.map((e=>e.transformed(s)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new pd(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:s}=this.locateOperation(e);this.operations=t.concat([s])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class gd{constructor(e,t){this.id=e,this.data=t}transformed(e){return new gd(this.id,e(this.data))}}class fd{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new fd(function*(e,t){for(const s of e)if(yield s,s.operation.id===t)return}(this.operations,e))}stopBefore(e){return new fd(function*(e,t){for(const s of e){if(s.operation.id===t)return;yield s}}(this.operations,e))}startAfter(e){return new fd(function*(e,t){let s=!0;for(const i of e)s||(yield i),i.operation.id===t&&(s=!1)}(this.operations,e))}}class md{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new fd(Es(this._execution(e),this._execution(e)))}revertedExecution(e){return new fd(Es(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var s;const i=e.getLastOperationId()||(null===(s=this.previousBranch(e))||void 0===s?void 0:s.getLastOperationId());e.append(t),i&&this.insertPrevious(e,t,i)}insertOperationAfter(e,t,s){e.insert(t,s),this.updateNextWith(e,t,s),this.insertPrevious(e,t,s)}undo(e,t){const s=this.buildTransformation.without(t.data),i=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);i&&this.branchingOperationIds.set(o,i),this.insertBranchAfter(e,o),this.transform(o,s)}redo(e){const t=this.nextBranch(e);if(!t)return;const s=this.nextBranch(t);this.removeBranchFromTree(t);const i=this.branchingOperationIds.get(t);i?this.branchingOperationIds.set(e,i):this.branchingOperationIds.delete(e),s&&this.rebaseUp(s)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const s of this.revertedExecution(e))if(s.operation.id===t)return s;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:s}=this.findPreviousBranchingOperation(e);if(!t||!s)return;const i=this.buildTransformation.without(s.data),o=t.fork(s.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(i);const n=this.nextBranch(o);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const s=this.branches.findIndex((t=>t===e));this.branches.splice(s+1,0,t)}updateNextWith(e,t,s){const i=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(i&&o)if(e.getFirstOperationAmong(s,i)===i){const n=this.addToNextBranch(e,o,i,t,s);this.updateNextWith(o,n,s)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,s,i,o){let n=i;return o===s?(n=this.getTransformedOperation(e,s,i),t.prepend(n)):t.contains(o)?(n=this.getTransformedOperation(e,s,i),t.insert(n,o)):t.append(i),n}getTransformedOperation(e,t,s){const i=e.getOperation(t),o=this.buildTransformation.without(i.data);return s.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const s=this.nextBranch(e);s&&this.transform(s,t)}insertPrevious(e,t,s){const{previousBranch:i,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!i||!o)return;const n=this.buildTransformation.with(o.data),r=e.fork(s);r.transform(n),i.cutAfter(s),i.appendBranch(r);const a=t.transformed(n);this.insertPrevious(i,a,s)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const s=this.branchingOperationIds.get(t);return s?{previousBranch:t,branchingOperation:t.getOperation(s)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let s=!!t;const i=e.getOperations();for(let o=i.length-1;o>=0;o--){const n=i[o];n.id===t&&(s=!1),s||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class vd{constructor(e,t,s,i,o){this.applyOperation=t,this.revertOperation=s,this.buildEmpty=i,this.buildTransformation=o,this.HEAD_BRANCH=new pd(this.buildTransformation),this.tree=new md(o,this.HEAD_BRANCH);const n=new gd(e,i(e));this.tree.insertOperationLast(this.HEAD_BRANCH,n),this.HEAD_OPERATION=n}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const s=new gd(e,t),i=this.tree.getLastBranch();this.tree.insertOperationLast(i,s),this.HEAD_BRANCH=i,this.HEAD_OPERATION=s}insert(e,t,s){const i=new gd(e,t);this.revertTo(s),this.tree.insertOperationAfter(this.HEAD_BRANCH,i,s),this.fastForward()}undo(e,t,s){const{branch:i,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(i,o),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}redo(e,t,s){const{branch:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(i),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}drop(e){this.revertBefore(e),this.tree.drop(e)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:s,isCancelled:i}of e)i||this.revertOperation(s.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:s,isCancelled:i}of e)i||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=s}}function Ed(e,t,s){return new vd(e,(e=>{const i=e.commands.slice(),{changes:o}=t((()=>{for(const e of i)s(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Sd(t.changes[e],"before")}}([e])),(e=>new Kh(e,"empty",[],[])),{with:e=>t=>new Kh(t.id,t.clientId,Xh(t.commands,e.commands)),without:e=>t=>new Kh(t.id,t.clientId,Xh(t.commands,e.commands.map(dd).flat()))})}function Sd(e,t){let s=e.path[0];const i=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const i=e.path[t];if(void 0===s[i]){const o=e.path[t+1];s[i]=ud(o)}s=s[i]}void 0===e[t]?delete s[i]:s[i]=e[t]}class bd extends i.core.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("pending-revisions-dropped",this,(({revisionIds:e})=>this.drop(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}drop(e){this.undoStack=this.undoStack.filter((t=>!e.includes(t))),this.redoStack=[]}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class Cd{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return 0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";e.elements.sort(((e,t)=>t-e));const o=vs(e.elements);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of o){const o=Ns(e),l=Os(e);if(n.zone[t]<=o&&o<=n.zone[s]){const e=Math.min(n.zone[s],l)-o+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e)}else if(n.zone[t]>=o&&n.zone[s]<=l)a="REMOVE",r=this.buildInvalidRange(_);else if(n.zone[t]<=l&&n.zone[s]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e),r=this.createAdaptedRange(r,i,"MOVE",-(n.zone[t]-o))}else o<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,i,a,-(l-o+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>t.sheetId!==e.sheetId?{changeType:"NONE"}:{changeType:"REMOVE",range:t={...this.buildInvalidRange(_),invalidSheetName:this.getters.getSheetName(e.sheetId)}}),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 s={...t,zone:{...t.zone}};return s.invalidSheetName=void 0,s.sheetId=e.sheetId,{changeType:"CHANGE",range:s}}return{changeType:"NONE"}}))}}finalize(){}verifyRangeRemoved(e){return t=>{const s=e(t);return"NONE"===s.changeType||$s(s.range.zone)?s:{range:s.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,s,i){return{...e,zone:Xs(e.zone,t,s,i)}}executeOnAllRanges(e,t){const s=this.verifyRangeRemoved(e);for(const e of this.providers)e(s,t)}addRangeProvider(e){this.providers.push(e)}orderZone(e,t){if(e.right<e.left){let s=e.right;e.right=e.left,e.left=s;let i=t[1].colFixed;t[1].colFixed=t[0].colFixed,t[0].colFixed=i}if(e.bottom<e.top){let s=e.bottom;e.bottom=e.top,e.top=s;let i=t[1].rowFixed;t[1].rowFixed=t[0].rowFixed,t[0].rowFixed=i}}createAdaptedRanges(e,t,s,i){return e.map((e=>$s(e.zone)?(e={...e,sheetId:e.prefixSheet?e.sheetId:i,zone:{left:e.zone.left+(e.parts[0].colFixed?0:t),right:e.zone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.zone.top+(e.parts[0].rowFixed?0:s),bottom:e.zone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:s)}},this.orderZone(e.zone,e.parts),e):e))}getRangeFromSheetXC(e,t){let s,i,o,n=t,r=!1;if(!es.test(t))return this.buildInvalidRange(t);t.includes("!")&&(({xc:n,sheetName:s}=ts(t)),s?(i=this.getters.getSheetIdByName(s),r=!0,i||(o=s)):o=s);const a=ks(n);let l=n.split(":").map((e=>({colFixed:e.startsWith("$"),rowFixed:e.includes("$",1)})));return this.orderZone(a,l),{sheetId:i||e,zone:a,parts:l,invalidSheetName:o,prefixSheet:r}}getRangeString(e,t){if(!e)return _;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return _;if(e.zone.left<0||e.zone.top<0)return _;let s=e.sheetId!==t||e.invalidSheetName||e.prefixSheet,i="";if(s&&(i=e.invalidSheetName?e.invalidSheetName:ps(this.getters.getSheetName(e.sheetId))),s&&!i)return _;let o=Array(9);return o[0]=e.parts&&e.parts[0].colFixed?"$":"",o[1]=ss(e.zone.left),o[2]=e.parts&&e.parts[0].rowFixed?"$":"",o[3]=String(e.zone.top+1),e.parts&&2===e.parts.length&&(e.zone.top!==e.zone.bottom||e.zone.left!==e.zone.right||e.parts[0].rowFixed||e.parts[0].colFixed||e.parts[1].rowFixed||e.parts[1].colFixed)&&(o[4]=":",o[5]=e.parts[1].colFixed?"$":"",o[6]=ss(e.zone.right),o[7]=e.parts[1].rowFixed?"$":"",o[8]=String(e.zone.bottom+1)),`${s?i+"!":""}${o.join("")}`}buildInvalidRange(e){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:e}}}Cd.getters=["getRangeString","getRangeFromSheetXC","createAdaptedRanges"];class Id{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let s=e[0],i=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const i=e[t];if(void 0===s[i]){const o=e[t+1];s[i]=ud(o)}s=s[i]}s[i]!==t&&(this.changes.push({path:e,before:s[i],after:t}),void 0===t?delete s[i]:s[i]=t)}}const yd={General:0,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},wd={arrow:"3Arrows",smiley:"3Symbols",dot:"3TrafficLights1"},Td={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"},xd="http://schemas.openxmlformats.org/drawingml/2006/main",Rd="http://schemas.openxmlformats.org/drawingml/2006/chart",Ld={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"},Md="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ad=.75,_d=.1425,Od=164,Nd={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}]},kd=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"];function Fd(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function $d(e){return Math.round(Ad*e*window.devicePixelRatio*100)/100}function Dd(e){return Math.round(_d*e*100)/100}function Ud(e,t){let s={};e.style&&(s=t.styles[e.style]);const i={font:{size:(null==s?void 0:s.fontSize)||x,color:(null==s?void 0:s.textColor)?s.textColor:"000000",family:2,name:"Arial"},fill:(null==s?void 0:s.fillColor)?{fgColor:s.fillColor}:{reservedAttribute:"none"},numFmt:e.format,border:e.border||0,verticalAlignment:"center",horizontalAlignment:null==s?void 0:s.align};return i.font.strike=!!(null==s?void 0:s.strikethrough)||void 0,i.font.underline=!!(null==s?void 0:s.underline)||void 0,i.font.bold=!!(null==s?void 0:s.bold)||void 0,i.font.italic=!!(null==s?void 0:s.italic)||void 0,i}function Pd(e,t){const s=function(e,t){if(!e)return 0;let s=yd[e];s||(s=Vd(e,t)+Od);return s}(t.numFmt,e.numFmts),i={fontId:Vd(t.font,e.fonts),fillId:Vd(t.fill,e.fills),borderId:t.border,numFmtId:s,verticalAlignment:t.verticalAlignment,horizontalAlignment:t.horizontalAlignment};return Vd(i,e.styles)}function Bd(e,t,s){let i,o=e.find((e=>e.path===t));return o?(i=`rId${(o.rels.length+1).toString()}`,o.rels.push({...s,id:i})):(i="rId1",e.push({path:t,rels:[{...s,id:i}]})),i}function Vd(e,t){let s=t.length;const i="object"==typeof e?_s:(e,t)=>e===t;for(let o=0;o<s;o++)if(i(e,t[o]))return o;return t[t.length]=e,t.length-1}const Hd=[];function zd(e){const t=Hd.findIndex((t=>t===e));return-1===t?(Hd.push(e),Hd.length):t+1}function Zd(e){return Math.round(914400*e/96)}class Gd{constructor(e){this.xmlString=e}toString(){return this.xmlString}}function Wd(e,t,s){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:s}}function qd(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function jd(e){return new Gd(e.map((([e,t])=>`${e}="${qd(t)}"`)).join(" "))}function Yd(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),s=t.querySelector("parsererror");if(s){const t=s.innerHTML,i=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),n=o.slice(Math.max(i-3,0),Math.min(i+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${n}`)}return t}function Xd(e,t){return Qd`
|
|
1045
1045
|
<Override ContentType="${t}" PartName="${e}" />
|
|
1046
1046
|
`}function Kd(e){return new Gd(e.join("\n"))}function Qd(e,...t){let s=[e[0]];for(let i=0;i<t.length;i++){const o=t[i]instanceof Gd?t[i]:qd(t[i]);s.push(o+e[i+1])}return new Gd(s.join(""))}const Jd=17781237,eu=88853993;function tu(e){const t=[["xmlns:r",Md],["xmlns:a",xd],["xmlns:c",Rd]],s=su({backgroundColor:Qt(e.data.backgroundColor),line:{color:"000000"}});let i=Qd``;e.data.title&&(i=Qd`
|
|
1047
1047
|
<c:title>
|
|
@@ -1444,7 +1444,7 @@
|
|
|
1444
1444
|
<Relationships xmlns="${Td.Relationships}">
|
|
1445
1445
|
<Relationship ${jd(e)} />
|
|
1446
1446
|
</Relationships>
|
|
1447
|
-
`;return Wd(Yd(t),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}var _u;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing",e[e.Interactive=4]="Interactive"}(_u||(_u={}));class Ou extends i.core.EventBus{constructor(e={},t={},s=[],i=new ni){super(),this.corePlugins=[],this.uiPlugins=[],this.dataSources=new cd,this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.dispatch=(e,t)=>{const s={type:e,...t};let i=s.interactive?4:this.status;if(this.config.isReadonly&&(o=s,!$e.has(o.type)))return new Pe(52);var o;if(!this.session.canApplyOptimisticUpdate())return new Pe(49);switch(i){case 0:const t=this.checkDispatchAllowed(s);if(!t.isSuccessful)return t;this.status=1;const{changes:i,commands:o}=this.state.recordChanges((()=>{Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s),this.finalize()}));this.session.save(o,i),this.status=0,"headless"!==this.config.mode&&this.trigger("update");break;case 1:if(Ue(s)){const e=this.checkDispatchAllowed(s);if(!e.isSuccessful)return e;this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s)}else this.dispatchToHandlers(this.handlers,s);break;case 4:Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s);break;case 3:throw new Error(a("Cannot dispatch commands in the finalize state"));case 2:if(Ue(s))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,s)}return Pe.Success},this.dispatchFromCorePlugin=(e,t)=>{const s={type:e,...t},i=this.status;this.status=2;const o=this.isReplayingCommand?[this.range,...this.corePlugins]:this.handlers;return this.dispatchToHandlers(o,s),this.status=i,Pe.Success},As.model=this,s=ua(e,s);const o=ha(e);this.state=new Id,this.uuidGenerator=i,this.config=this.setupConfig(t),this.session=this.setupSession(o.revisionId),this.config.moveClient=this.session.move.bind(this.session),this.history=new bd(this.dispatchFromCorePlugin,this.session),this.getters={isReadonly:()=>this.config.isReadonly,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.range=new Cd(this.getters),this.getters.getRangeString=this.range.getRangeString.bind(this.range),this.getters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.getters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.uuidGenerator.setIsFastStrategy(!0);for(let e of rd.getAll())this.setupCorePlugin(e,o);for(let e of ad.getAll())this.setupUiPlugin(e);this.uuidGenerator.setIsFastStrategy(!1),this.dispatch("START"),this.setupSessionEvents(),this.session.loadInitialMessages(s),this.joinSession(t.client),t.snapshotRequested&&this.session.snapshot(this.exportData())}get handlers(){return[this.range,...this.corePlugins,...this.uiPlugins,this.history]}joinSession(e){this.session.join(e)}leaveSession(){this.session.leave()}destroy(){delete As.model}setupUiPlugin(e){if(e.modes.includes(this.config.mode)){const t=new e(this.getters,this.state,this.dispatch,this.config);for(let s of e.getters){if(!(s in t))throw new Error(`Invalid getter name: ${s} for plugin ${t.constructor}`);this.getters[s]=t[s].bind(t)}this.uiPlugins.push(t);const s=e.layers.map((e=>[t,e]));this.renderers.push(...s),this.renderers.sort(((e,t)=>e[1]-t[1]))}}setupCorePlugin(e,t){if(e.modes.includes(this.config.mode)){const s=new e(this.getters,this.state,this.range,this.dispatchFromCorePlugin,this.config,this.uuidGenerator);s.import(t);for(let t of e.getters){if(!(t in s))throw new Error(`Invalid getter name: ${t} for plugin ${s.constructor}`);this.getters[t]=s[t].bind(s)}this.corePlugins.push(s)}}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.uiPlugins,t),this.status=e}this.finalize()}setupSession(e){return new Jh(Ed(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers([this.range,...this.corePlugins],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:a("Anonymous").toString()},s=e.transportService||new ld;return{mode:e.mode||"normal",openSidePanel:e.openSidePanel||(()=>{}),notifyUser:e.notifyUser||(()=>{}),askConfirmation:e.askConfirmation||(()=>{}),editText:e.editText||(()=>{}),evalContext:e.evalContext||{},transportService:s,client:t,moveClient:()=>{},isHeadless:"headless"===e.mode||!1,isReadonly:e.isReadonly||!1,snapshotRequested:!1,dataSources:this.dataSources}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return t.some((e=>0!==e))?new Pe(t.flat()):Pe.Success}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}dispatchToHandlers(e,t){for(const s of e)s.beforeHandle(t);for(const s of e)s.handle(t)}drawGrid(e){e.viewport=this.getters.getActiveSnappedViewport();for(let[t,s]of this.renderers)e.ctx.save(),t.drawGrid(e,s),e.ctx.restore()}exportData(){let e=fa();for(let t of this.handlers)t instanceof va&&t.export(e);return e.revisionId=this.session.getRevisionId()||O,e=JSON.parse(JSON.stringify(e)),e}updateReadOnly(e){e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.isReadonly=e||!1}waitForIdle(){return this.dataSources.waitForReady()}async exportXLSX(){await this.waitForIdle(),this.dispatch("EVALUATE_ALL_SHEETS");let e={...fa(),sheets:[(t=ca,s="Sheet1",{...ga(t,s),charts:[]})]};var t,s;for(let t of this.handlers)t instanceof va&&t.exportForExcel(e);return e=JSON.parse(JSON.stringify(e)),Au(e)}}const{useComponent:Nu,useState:ku,onPatched:Fu,onMounted:$u}=t.hooks;function Du(e){const t=ku({x:0,y:0}),s=Nu(),i=function(){const e=ku({x:0,y:0});let t=document.querySelector(".o-spreadsheet");function s(){if(t||(t=document.querySelector(".o-spreadsheet")),t){const{top:s,left:i}=t.getBoundingClientRect();e.x=i,e.y=s}}return $u(s),Fu(s),e}();function o(){const o=(null==e?void 0:e.el)||s.el,{top:n,left:r}=o.getBoundingClientRect(),a=r-i.x,l=n-i.y;a===t.x&&l===t.y||(t.x=a,t.y=l)}return $u(o),Fu(o),t}const{Portal:Uu}=t.misc,{xml:Pu}=t.tags,Bu=Pu`
|
|
1447
|
+
`;return Wd(Yd(t),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}var _u;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing",e[e.Interactive=4]="Interactive"}(_u||(_u={}));class Ou extends i.core.EventBus{constructor(e={},t={},s=[],i=new ni){super(),this.corePlugins=[],this.uiPlugins=[],this.dataSources=new cd,this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.dispatch=(e,t)=>{const s={type:e,...t};let i=s.interactive?4:this.status;if(this.config.isReadonly&&(o=s,!$e.has(o.type)))return new Pe(52);var o;if(!this.session.canApplyOptimisticUpdate())return new Pe(49);switch(i){case 0:const t=this.checkDispatchAllowed(s);if(!t.isSuccessful)return t;this.status=1;const{changes:i,commands:o}=this.state.recordChanges((()=>{Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s),this.finalize()}));this.session.save(o,i),this.status=0,"headless"!==this.config.mode&&this.trigger("update");break;case 1:if(Ue(s)){const e=this.checkDispatchAllowed(s);if(!e.isSuccessful)return e;this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s)}else this.dispatchToHandlers(this.handlers,s);break;case 4:Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s);break;case 3:throw new Error(a("Cannot dispatch commands in the finalize state"));case 2:if(Ue(s))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,s)}return Pe.Success},this.dispatchFromCorePlugin=(e,t)=>{const s={type:e,...t},i=this.status;this.status=2;const o=this.isReplayingCommand?[this.range,...this.corePlugins]:this.handlers;return this.dispatchToHandlers(o,s),this.status=i,Pe.Success},As.model=this,s=ua(e,s);const o=ha(e);this.state=new Id,this.uuidGenerator=i,this.config=this.setupConfig(t),this.session=this.setupSession(o.revisionId),this.config.moveClient=this.session.move.bind(this.session),this.history=new bd(this.dispatchFromCorePlugin,this.session),this.getters={isReadonly:()=>this.config.isReadonly,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.range=new Cd(this.getters),this.getters.getRangeString=this.range.getRangeString.bind(this.range),this.getters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.getters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.uuidGenerator.setIsFastStrategy(!0);for(let e of rd.getAll())this.setupCorePlugin(e,o);for(let e of ad.getAll())this.setupUiPlugin(e);this.uuidGenerator.setIsFastStrategy(!1),this.dispatch("START"),this.isLoading=!0,this.setupSessionEvents(),this.session.loadInitialMessages(s),this.joinSession(t.client),t.snapshotRequested&&this.session.snapshot(this.exportData()),this.isLoading=!1,this.finalize()}get handlers(){return[this.range,...this.corePlugins,...this.uiPlugins,this.history]}joinSession(e){this.session.join(e)}leaveSession(){this.session.leave()}destroy(){delete As.model}setupUiPlugin(e){if(e.modes.includes(this.config.mode)){const t=new e(this.getters,this.state,this.dispatch,this.config);for(let s of e.getters){if(!(s in t))throw new Error(`Invalid getter name: ${s} for plugin ${t.constructor}`);this.getters[s]=t[s].bind(t)}this.uiPlugins.push(t);const s=e.layers.map((e=>[t,e]));this.renderers.push(...s),this.renderers.sort(((e,t)=>e[1]-t[1]))}}setupCorePlugin(e,t){if(e.modes.includes(this.config.mode)){const s=new e(this.getters,this.state,this.range,this.dispatchFromCorePlugin,this.config,this.uuidGenerator);s.import(t);for(let t of e.getters){if(!(t in s))throw new Error(`Invalid getter name: ${t} for plugin ${s.constructor}`);this.getters[t]=s[t].bind(s)}this.corePlugins.push(s)}}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.uiPlugins,t),this.status=e}this.finalize()}setupSession(e){return new Jh(Ed(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers([this.range,...this.corePlugins],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:a("Anonymous").toString()},s=e.transportService||new ld;return{mode:e.mode||"normal",openSidePanel:e.openSidePanel||(()=>{}),notifyUser:e.notifyUser||(()=>{}),askConfirmation:e.askConfirmation||(()=>{}),editText:e.editText||(()=>{}),evalContext:e.evalContext||{},transportService:s,client:t,moveClient:()=>{},isHeadless:"headless"===e.mode||!1,isReadonly:e.isReadonly||!1,snapshotRequested:!1,dataSources:this.dataSources}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return t.some((e=>0!==e))?new Pe(t.flat()):Pe.Success}finalize(){if(!this.isLoading){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}}dispatchToHandlers(e,t){for(const s of e)s.beforeHandle(t);for(const s of e)s.handle(t)}drawGrid(e){e.viewport=this.getters.getActiveSnappedViewport();for(let[t,s]of this.renderers)e.ctx.save(),t.drawGrid(e,s),e.ctx.restore()}exportData(){let e=fa();for(let t of this.handlers)t instanceof va&&t.export(e);return e.revisionId=this.session.getRevisionId()||O,e=JSON.parse(JSON.stringify(e)),e}updateReadOnly(e){e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.isReadonly=e||!1}waitForIdle(){return this.dataSources.waitForReady()}async exportXLSX(){await this.waitForIdle(),this.dispatch("EVALUATE_ALL_SHEETS");let e={...fa(),sheets:[(t=ca,s="Sheet1",{...ga(t,s),charts:[]})]};var t,s;for(let t of this.handlers)t instanceof va&&t.exportForExcel(e);return e=JSON.parse(JSON.stringify(e)),Au(e)}}const{useComponent:Nu,useState:ku,onPatched:Fu,onMounted:$u}=t.hooks;function Du(e){const t=ku({x:0,y:0}),s=Nu(),i=function(){const e=ku({x:0,y:0});let t=document.querySelector(".o-spreadsheet");function s(){if(t||(t=document.querySelector(".o-spreadsheet")),t){const{top:s,left:i}=t.getBoundingClientRect();e.x=i,e.y=s}}return $u(s),Fu(s),e}();function o(){const o=(null==e?void 0:e.el)||s.el,{top:n,left:r}=o.getBoundingClientRect(),a=r-i.x,l=n-i.y;a===t.x&&l===t.y||(t.x=a,t.y=l)}return $u(o),Fu(o),t}const{Portal:Uu}=t.misc,{xml:Pu}=t.tags,Bu=Pu`
|
|
1448
1448
|
<Portal target="'.o-spreadsheet'">
|
|
1449
1449
|
<div class="o-popover" t-att-style="style">
|
|
1450
1450
|
<t t-slot="default"/>
|
|
@@ -3072,4 +3072,4 @@
|
|
|
3072
3072
|
height: ${15}px;
|
|
3073
3073
|
vertical-align: sub;
|
|
3074
3074
|
}
|
|
3075
|
-
`;class Hf extends t.Component{constructor(e,s={}){super(e,s),this.model=new Ou(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,s)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:s}),editText:(e,t,s)=>this.trigger("edit-text",{title:e,placeholder:t,callback:s}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env},transportService:this.props.transportService,client:this.props.client,isReadonly:this.props.isReadonly,snapshotRequested:this.props.snapshotRequested},this.props.stateUpdateMessages),this.grid=Df("grid"),this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.linkEditor=t.useState({isOpen:!1}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.clipBoardString="",this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},$f({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,uuidGenerator:this.model.uuidGenerator,_t:Hf._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model),waitForIdle:this.model.waitForIdle.bind(this.model),exportXLSX:this.model.exportXLSX.bind(this.model),openLinkEditor:()=>this.openLinkEditor()}),Ff(window,"resize",this.render),Ff(document.body,"cut",this.copy.bind(this,!0)),Ff(document.body,"copy",this.copy.bind(this,!1)),Ff(document.body,"paste",this.paste),Ff(document.body,"keyup",this.onKeyup.bind(this)),Ff(window,"beforeunload",this.leaveCollaborativeSession.bind(this)),this.activateFirstSheet()}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}mounted(){this.model.on("update",this,this.render),this.model.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.props.client&&this.model.joinSession(this.props.client)}willUnmount(){this.leaveCollaborativeSession()}async willUpdateProps(e){this.props.isReadonly!==e.isReadonly&&this.model.updateReadOnly(e.isReadonly)}leaveCollaborativeSession(){this.model.off("update",this),this.model.leaveSession()}activateFirstSheet(){const e=this.model.getters.getActiveSheetId(),[t]=this.model.getters.getSheets();t.id!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:t.id})}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}openLinkEditor(){this.linkEditor.isOpen=!0}closeLinkEditor(){this.linkEditor.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const s=e?"CUT":"COPY",i=this.model.getters.getSelectedZones();this.model.dispatch(s,{target:i});const o=this.model.getters.getClipboardContent();this.clipBoardString=o,t.clipboardData.setData("text/plain",o),t.preventDefault()}paste(e){if(!this.grid.el.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),s=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:s,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==xh.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===xh.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION");let t="";(e.ctrlKey||e.metaKey)&&(t+="CTRL+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];if(s)return e.preventDefault(),e.stopPropagation(),void s()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerCellFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}}Hf.template=Bf,Hf.style=Vf,Hf.components={TopBar:kf,Grid:nf,BottomBar:ep,SidePanel:df,LinkEditor:Pg},Hf._t=e=>e;const zf={},Zf={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:f,HEADER_WIDTH:m,TOPBAR_HEIGHT:v,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:E,DEFAULT_CELL_HEIGHT:S,SCROLLBAR_WIDTH:b},Gf={autofillModifiersRegistry:Ma,autofillRulesRegistry:Aa,cellMenuRegistry:hl,colMenuRegistry:dl,linkMenuRegistry:ul,functionRegistry:ar,uiPluginRegistry:ad,corePluginRegistry:rd,rowMenuRegistry:pl,sidePanelRegistry:Sh,sheetMenuRegistry:gl,topbarMenuRegistry:fl,topbarComponentRegistry:bh,otRegistry:ml,inverseCommandRegistry:Oa,cellRegistry:qr},Wf={LinkCell:sa},qf={args:_e,toBoolean:ge,toNumber:he,toString:ue,toXC:os,toZone:Fs,toCartesian:is,numberToLetters:ss,createFullMenuItem:Fa,UuidGenerator:ni,formatDecimal:re,computeTextWidth:fs,isMarkdownLink:ys,parseMarkdownLink:Ts,markdownLink:ws,createEmptyWorkbookData:fa};e.CorePlugin=va,e.DATETIME_FORMAT=A,e.DataSource=hd,e.DispatchResult=Pe,e.Model=Ou,e.Revision=Kh,e.SPREADSHEET_DIMENSIONS=Zf,e.Spreadsheet=Hf,e.UIPlugin=Ch,e.__DEBUG__=As,e.__info__=zf,e.astToFormula=kr,e.cellTypes=Wf,e.convertAstNodes=Nr,e.coreTypes=De,e.functionCache=Br,e.helpers=qf,e.invalidateEvaluationCommands=Fe,e.normalize=Gr,e.parse=Or,e.readonlyAllowedCommands=$e,e.registries=Gf,e.setTranslationMethod=function(e){o=e},Object.defineProperty(e,"__esModule",{value:!0}),zf.version="15.0.
|
|
3075
|
+
`;class Hf extends t.Component{constructor(e,s={}){super(e,s),this.model=new Ou(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,s)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:s}),editText:(e,t,s)=>this.trigger("edit-text",{title:e,placeholder:t,callback:s}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env},transportService:this.props.transportService,client:this.props.client,isReadonly:this.props.isReadonly,snapshotRequested:this.props.snapshotRequested},this.props.stateUpdateMessages),this.grid=Df("grid"),this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.linkEditor=t.useState({isOpen:!1}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.clipBoardString="",this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},$f({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,uuidGenerator:this.model.uuidGenerator,_t:Hf._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model),waitForIdle:this.model.waitForIdle.bind(this.model),exportXLSX:this.model.exportXLSX.bind(this.model),openLinkEditor:()=>this.openLinkEditor()}),Ff(window,"resize",this.render),Ff(document.body,"cut",this.copy.bind(this,!0)),Ff(document.body,"copy",this.copy.bind(this,!1)),Ff(document.body,"paste",this.paste),Ff(document.body,"keyup",this.onKeyup.bind(this)),Ff(window,"beforeunload",this.leaveCollaborativeSession.bind(this)),this.activateFirstSheet()}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}mounted(){this.model.on("update",this,this.render),this.model.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.props.client&&this.model.joinSession(this.props.client)}willUnmount(){this.leaveCollaborativeSession()}async willUpdateProps(e){this.props.isReadonly!==e.isReadonly&&this.model.updateReadOnly(e.isReadonly)}leaveCollaborativeSession(){this.model.off("update",this),this.model.leaveSession()}activateFirstSheet(){const e=this.model.getters.getActiveSheetId(),[t]=this.model.getters.getSheets();t.id!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:t.id})}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}openLinkEditor(){this.linkEditor.isOpen=!0}closeLinkEditor(){this.linkEditor.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const s=e?"CUT":"COPY",i=this.model.getters.getSelectedZones();this.model.dispatch(s,{target:i});const o=this.model.getters.getClipboardContent();this.clipBoardString=o,t.clipboardData.setData("text/plain",o),t.preventDefault()}paste(e){if(!this.grid.el.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),s=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:s,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==xh.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===xh.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION");let t="";(e.ctrlKey||e.metaKey)&&(t+="CTRL+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];if(s)return e.preventDefault(),e.stopPropagation(),void s()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerCellFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}}Hf.template=Bf,Hf.style=Vf,Hf.components={TopBar:kf,Grid:nf,BottomBar:ep,SidePanel:df,LinkEditor:Pg},Hf._t=e=>e;const zf={},Zf={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:f,HEADER_WIDTH:m,TOPBAR_HEIGHT:v,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:E,DEFAULT_CELL_HEIGHT:S,SCROLLBAR_WIDTH:b},Gf={autofillModifiersRegistry:Ma,autofillRulesRegistry:Aa,cellMenuRegistry:hl,colMenuRegistry:dl,linkMenuRegistry:ul,functionRegistry:ar,uiPluginRegistry:ad,corePluginRegistry:rd,rowMenuRegistry:pl,sidePanelRegistry:Sh,sheetMenuRegistry:gl,topbarMenuRegistry:fl,topbarComponentRegistry:bh,otRegistry:ml,inverseCommandRegistry:Oa,cellRegistry:qr},Wf={LinkCell:sa},qf={args:_e,toBoolean:ge,toNumber:he,toString:ue,toXC:os,toZone:Fs,toCartesian:is,numberToLetters:ss,createFullMenuItem:Fa,UuidGenerator:ni,formatDecimal:re,computeTextWidth:fs,isMarkdownLink:ys,parseMarkdownLink:Ts,markdownLink:ws,createEmptyWorkbookData:fa};e.CorePlugin=va,e.DATETIME_FORMAT=A,e.DataSource=hd,e.DispatchResult=Pe,e.Model=Ou,e.Revision=Kh,e.SPREADSHEET_DIMENSIONS=Zf,e.Spreadsheet=Hf,e.UIPlugin=Ch,e.__DEBUG__=As,e.__info__=zf,e.astToFormula=kr,e.cellTypes=Wf,e.convertAstNodes=Nr,e.coreTypes=De,e.functionCache=Br,e.helpers=qf,e.invalidateEvaluationCommands=Fe,e.normalize=Gr,e.parse=Or,e.readonlyAllowedCommands=$e,e.registries=Gf,e.setTranslationMethod=function(e){o=e},Object.defineProperty(e,"__esModule",{value:!0}),zf.version="15.0.29",zf.date="2024-10-14T07:46:39.258Z",zf.hash="d39f433"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|