@odoo/o-spreadsheet 17.3.5 → 17.3.6

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.
@@ -3,9 +3,9 @@
3
3
  /**
4
4
  * This file is generated by o-spreadsheet build tools. Do not edit it.
5
5
  * @see https://github.com/odoo/o-spreadsheet
6
- * @version 17.3.5
7
- * @date 2024-06-26T11:05:50.339Z
8
- * @hash 54eb151
6
+ * @version 17.3.6
7
+ * @date 2024-07-02T09:04:06.235Z
8
+ * @hash 979c0b1
9
9
  */
10
10
 
11
11
  'use strict';
@@ -21689,7 +21689,6 @@ const ALL_PERIODS = {
21689
21689
  month: _t("Month"),
21690
21690
  week: _t("Week"),
21691
21691
  day: _t("Day"),
21692
- year_number: _t("Year"),
21693
21692
  quarter_number: _t("Quarter"),
21694
21693
  month_number: _t("Month"),
21695
21694
  iso_week_number: _t("Week"),
@@ -35362,7 +35361,7 @@ function createDate(dimension, value, locale) {
35362
35361
  const date = toJsDate(value, locale);
35363
35362
  let number = 0;
35364
35363
  switch (granularity) {
35365
- case "year_number":
35364
+ case "year":
35366
35365
  number = date.getFullYear();
35367
35366
  break;
35368
35367
  case "quarter_number":
@@ -35389,7 +35388,7 @@ function createDate(dimension, value, locale) {
35389
35388
  * This map is used to cache the different values of a pivot date value
35390
35389
  * 43_831 -> 01/01/2012
35391
35390
  * Example: {
35392
- * year_number: {
35391
+ * year: {
35393
35392
  * set: { 43_831 },
35394
35393
  * values: { '43_831': 2012 }
35395
35394
  * },
@@ -35416,7 +35415,7 @@ function createDate(dimension, value, locale) {
35416
35415
  * }
35417
35416
  */
35418
35417
  const MAP_VALUE_DIMENSION_DATE = {
35419
- year_number: {
35418
+ year: {
35420
35419
  set: new Set(),
35421
35420
  values: {},
35422
35421
  },
@@ -35775,7 +35774,7 @@ pivotRegistry.add("SPREADSHEET", {
35775
35774
  externalData: false,
35776
35775
  onIterationEndEvaluation: (pivot) => pivot.markAsDirtyForEvaluation(),
35777
35776
  granularities: [
35778
- "year_number",
35777
+ "year",
35779
35778
  "quarter_number",
35780
35779
  "month_number",
35781
35780
  "iso_week_number",
@@ -60692,7 +60691,7 @@ class BottomBarSheet extends owl.Component {
60692
60691
  this.DOMFocusableElementStore.focus();
60693
60692
  }
60694
60693
  }
60695
- onClickSheetName(ev) {
60694
+ onMouseEventSheetName(ev) {
60696
60695
  if (this.state.isEditing)
60697
60696
  ev.stopPropagation();
60698
60697
  }
@@ -67014,6 +67013,6 @@ exports.tokenColors = tokenColors;
67014
67013
  exports.tokenize = tokenize;
67015
67014
 
67016
67015
 
67017
- __info__.version = "17.3.5";
67018
- __info__.date = "2024-06-26T11:05:50.339Z";
67019
- __info__.hash = "54eb151";
67016
+ __info__.version = "17.3.6";
67017
+ __info__.date = "2024-07-02T09:04:06.235Z";
67018
+ __info__.hash = "979c0b1";
@@ -499,7 +499,7 @@ interface SearchOptions {
499
499
  }
500
500
 
501
501
  type Aggregator = "array_agg" | "count" | "count_distinct" | "bool_and" | "bool_or" | "max" | "min" | "avg" | "sum";
502
- type Granularity = "day" | "week" | "month" | "quarter" | "year" | "day_of_month" | "iso_week_number" | "month_number" | "quarter_number" | "year_number";
502
+ type Granularity = "day" | "week" | "month" | "quarter" | "year" | "day_of_month" | "iso_week_number" | "month_number" | "quarter_number";
503
503
  interface PivotCoreDimension {
504
504
  name: string;
505
505
  order?: "asc" | "desc";
@@ -9049,7 +9049,6 @@ declare class PivotDimensionGranularity extends Component<Props$e, SpreadsheetCh
9049
9049
  month: string;
9050
9050
  week: string;
9051
9051
  day: string;
9052
- year_number: string;
9053
9052
  quarter_number: string;
9054
9053
  month_number: string;
9055
9054
  iso_week_number: string;
@@ -9433,7 +9432,7 @@ declare class BottomBarSheet extends Component<Props$b, SpreadsheetChildEnv> {
9433
9432
  private activateSheet;
9434
9433
  onDblClick(): void;
9435
9434
  onKeyDown(ev: KeyboardEvent): void;
9436
- onClickSheetName(ev: MouseEvent): void;
9435
+ onMouseEventSheetName(ev: MouseEvent): void;
9437
9436
  private startEdition;
9438
9437
  private stopEdition;
9439
9438
  private cancelEdition;
@@ -3,9 +3,9 @@
3
3
  /**
4
4
  * This file is generated by o-spreadsheet build tools. Do not edit it.
5
5
  * @see https://github.com/odoo/o-spreadsheet
6
- * @version 17.3.5
7
- * @date 2024-06-26T11:05:50.339Z
8
- * @hash 54eb151
6
+ * @version 17.3.6
7
+ * @date 2024-07-02T09:04:06.235Z
8
+ * @hash 979c0b1
9
9
  */
10
10
 
11
11
  import { useEnv, useSubEnv, onWillUnmount, useComponent, status, Component, useRef, onMounted, useEffect, useState, onPatched, onWillPatch, onWillUpdateProps, useExternalListener, onWillStart, xml, useChildSubEnv, markRaw, toRaw } from '@odoo/owl';
@@ -21687,7 +21687,6 @@ const ALL_PERIODS = {
21687
21687
  month: _t("Month"),
21688
21688
  week: _t("Week"),
21689
21689
  day: _t("Day"),
21690
- year_number: _t("Year"),
21691
21690
  quarter_number: _t("Quarter"),
21692
21691
  month_number: _t("Month"),
21693
21692
  iso_week_number: _t("Week"),
@@ -35360,7 +35359,7 @@ function createDate(dimension, value, locale) {
35360
35359
  const date = toJsDate(value, locale);
35361
35360
  let number = 0;
35362
35361
  switch (granularity) {
35363
- case "year_number":
35362
+ case "year":
35364
35363
  number = date.getFullYear();
35365
35364
  break;
35366
35365
  case "quarter_number":
@@ -35387,7 +35386,7 @@ function createDate(dimension, value, locale) {
35387
35386
  * This map is used to cache the different values of a pivot date value
35388
35387
  * 43_831 -> 01/01/2012
35389
35388
  * Example: {
35390
- * year_number: {
35389
+ * year: {
35391
35390
  * set: { 43_831 },
35392
35391
  * values: { '43_831': 2012 }
35393
35392
  * },
@@ -35414,7 +35413,7 @@ function createDate(dimension, value, locale) {
35414
35413
  * }
35415
35414
  */
35416
35415
  const MAP_VALUE_DIMENSION_DATE = {
35417
- year_number: {
35416
+ year: {
35418
35417
  set: new Set(),
35419
35418
  values: {},
35420
35419
  },
@@ -35773,7 +35772,7 @@ pivotRegistry.add("SPREADSHEET", {
35773
35772
  externalData: false,
35774
35773
  onIterationEndEvaluation: (pivot) => pivot.markAsDirtyForEvaluation(),
35775
35774
  granularities: [
35776
- "year_number",
35775
+ "year",
35777
35776
  "quarter_number",
35778
35777
  "month_number",
35779
35778
  "iso_week_number",
@@ -60690,7 +60689,7 @@ class BottomBarSheet extends Component {
60690
60689
  this.DOMFocusableElementStore.focus();
60691
60690
  }
60692
60691
  }
60693
- onClickSheetName(ev) {
60692
+ onMouseEventSheetName(ev) {
60694
60693
  if (this.state.isEditing)
60695
60694
  ev.stopPropagation();
60696
60695
  }
@@ -66969,6 +66968,6 @@ const constants = {
66969
66968
  export { AbstractCellClipboardHandler, AbstractChart, AbstractFigureClipboardHandler, CellErrorType, CommandResult, CorePlugin, DispatchResult, EvaluationError, Model, PivotRuntimeDefinition, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, SpreadsheetPivotTable, UIPlugin, __info__, addFunction, addRenderingLayer, astToFormula, compile, compileTokens, components, constants, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, hooks, invalidateCFEvaluationCommands, invalidateDependenciesCommands, invalidateEvaluationCommands, iterateAstNodes, links, load, parse, parseTokens, readonlyAllowedCommands, registries, setDefaultSheetViewSize, setTranslationMethod, stores, tokenColors, tokenize };
66970
66969
 
66971
66970
 
66972
- __info__.version = "17.3.5";
66973
- __info__.date = "2024-06-26T11:05:50.339Z";
66974
- __info__.hash = "54eb151";
66971
+ __info__.version = "17.3.6";
66972
+ __info__.date = "2024-07-02T09:04:06.235Z";
66973
+ __info__.hash = "979c0b1";
@@ -3,9 +3,9 @@
3
3
  /**
4
4
  * This file is generated by o-spreadsheet build tools. Do not edit it.
5
5
  * @see https://github.com/odoo/o-spreadsheet
6
- * @version 17.3.5
7
- * @date 2024-06-26T11:05:50.339Z
8
- * @hash 54eb151
6
+ * @version 17.3.6
7
+ * @date 2024-07-02T09:04:06.235Z
8
+ * @hash 979c0b1
9
9
  */
10
10
 
11
11
  (function (exports, owl) {
@@ -21688,7 +21688,6 @@ stores.inject(MyMetaStore, storeInstance);
21688
21688
  month: _t("Month"),
21689
21689
  week: _t("Week"),
21690
21690
  day: _t("Day"),
21691
- year_number: _t("Year"),
21692
21691
  quarter_number: _t("Quarter"),
21693
21692
  month_number: _t("Month"),
21694
21693
  iso_week_number: _t("Week"),
@@ -35361,7 +35360,7 @@ stores.inject(MyMetaStore, storeInstance);
35361
35360
  const date = toJsDate(value, locale);
35362
35361
  let number = 0;
35363
35362
  switch (granularity) {
35364
- case "year_number":
35363
+ case "year":
35365
35364
  number = date.getFullYear();
35366
35365
  break;
35367
35366
  case "quarter_number":
@@ -35388,7 +35387,7 @@ stores.inject(MyMetaStore, storeInstance);
35388
35387
  * This map is used to cache the different values of a pivot date value
35389
35388
  * 43_831 -> 01/01/2012
35390
35389
  * Example: {
35391
- * year_number: {
35390
+ * year: {
35392
35391
  * set: { 43_831 },
35393
35392
  * values: { '43_831': 2012 }
35394
35393
  * },
@@ -35415,7 +35414,7 @@ stores.inject(MyMetaStore, storeInstance);
35415
35414
  * }
35416
35415
  */
35417
35416
  const MAP_VALUE_DIMENSION_DATE = {
35418
- year_number: {
35417
+ year: {
35419
35418
  set: new Set(),
35420
35419
  values: {},
35421
35420
  },
@@ -35774,7 +35773,7 @@ stores.inject(MyMetaStore, storeInstance);
35774
35773
  externalData: false,
35775
35774
  onIterationEndEvaluation: (pivot) => pivot.markAsDirtyForEvaluation(),
35776
35775
  granularities: [
35777
- "year_number",
35776
+ "year",
35778
35777
  "quarter_number",
35779
35778
  "month_number",
35780
35779
  "iso_week_number",
@@ -60691,7 +60690,7 @@ stores.inject(MyMetaStore, storeInstance);
60691
60690
  this.DOMFocusableElementStore.focus();
60692
60691
  }
60693
60692
  }
60694
- onClickSheetName(ev) {
60693
+ onMouseEventSheetName(ev) {
60695
60694
  if (this.state.isEditing)
60696
60695
  ev.stopPropagation();
60697
60696
  }
@@ -67013,9 +67012,9 @@ stores.inject(MyMetaStore, storeInstance);
67013
67012
  exports.tokenize = tokenize;
67014
67013
 
67015
67014
 
67016
- __info__.version = "17.3.5";
67017
- __info__.date = "2024-06-26T11:05:50.339Z";
67018
- __info__.hash = "54eb151";
67015
+ __info__.version = "17.3.6";
67016
+ __info__.date = "2024-07-02T09:04:06.235Z";
67017
+ __info__.hash = "979c0b1";
67019
67018
 
67020
67019
 
67021
67020
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);
@@ -87,7 +87,7 @@
87
87
  }
88
88
  }
89
89
  }
90
- `;class lb extends t.Component{static template="o-spreadsheet-Composer";static props={focus:{validate:e=>["inactive","cellFocus","contentFocus"].includes(e)},inputStyle:{type:String,optional:!0},rect:{type:Object,optional:!0},delimitation:{type:Object,optional:!0},onComposerCellFocused:{type:Function,optional:!0},onComposerContentFocused:Function,isDefaultFocus:{type:Boolean,optional:!0},onInputContextMenu:{type:Function,optional:!0}};static components={TextValueProvider:Qf,FunctionDescriptionProvider:ob};static defaultProps={inputStyle:"",isDefaultFocus:!1};composerStore;DOMFocusableElementStore;composerRef=t.useRef("o_composer");contentHelper=new eb(this.composerRef.el);composerState=t.useState({positionStart:0,positionEnd:0});autoCompleteState;functionDescriptionState=t.useState({showDescription:!1,functionName:"",functionDescription:{},argToFocus:0});compositionActive=!1;get assistantStyle(){const e={};e["min-width"]=`${this.props.rect?.width||300}px`;const t=this.autoCompleteState.provider?.proposals,o=t?.some((e=>e.description));if((this.functionDescriptionState.showDescription||o)&&(e.width="300px"),this.props.delimitation&&this.props.rect){const{x:t,y:o,height:s}=this.props.rect,i=this.props.delimitation.height-(o+s);if(e["max-height"]=`${i}px`,o>i){const t=o;e["max-height"]=`${t}px`,e.top="-3px",e.transform="translate(0, -100%)"}t+300>this.props.delimitation.width&&(e.right="0px")}else this.props.delimitation&&(e["max-height"]=`${this.props.delimitation.height}px`);return Uf(e)}shouldProcessInputEvents=!1;tokens=[];keyMapping={Enter:e=>this.processEnterKey(e,"down"),"Shift+Enter":e=>this.processEnterKey(e,"up"),"Alt+Enter":this.processNewLineEvent,"Ctrl+Enter":this.processNewLineEvent,Escape:this.processEscapeKey,F2:()=>console.warn("Not implemented"),F4:e=>this.processF4Key(e),Tab:e=>this.processTabKey(e,"right"),"Shift+Tab":e=>this.processTabKey(e,"left")};keyCodeMapping={NumpadDecimal:this.processNumpadDecimal};setup(){this.composerStore=Wa(il),this.DOMFocusableElementStore=Wa(Ff),this.autoCompleteState=qa(Jf),t.onMounted((()=>{const e=this.composerRef.el;this.props.isDefaultFocus&&this.DOMFocusableElementStore.setFocusableElement(e),this.contentHelper.updateEl(e)})),t.useEffect((()=>{this.processContent()})),t.useEffect((()=>{this.processTokenAtCursor()}),(()=>["inactive"!==this.composerStore.editionMode]))}processArrowKeys(e){const t=this.composerStore.tokenAtCursor;if((this.composerStore.isSelectingRange||"inactive"===this.composerStore.editionMode)&&(!["ArrowUp","ArrowDown"].includes(e.key)||!this.autoCompleteState.provider||"REFERENCE"===t?.type))return this.functionDescriptionState.showDescription=!1,this.autoCompleteState.hide(),e.preventDefault(),e.stopPropagation(),void Kf(e,this.env.model.selection);const o=this.composerStore.currentContent;"cellFocus"!==this.props.focus||this.autoCompleteState.provider||o.startsWith("=")?(e.stopPropagation(),this.handleArrowKeysForAutocomplete(e)):this.composerStore.stopEdition()}handleArrowKeysForAutocomplete(e){["ArrowUp","ArrowDown"].includes(e.key)&&this.autoCompleteState.provider&&(e.preventDefault(),this.autoCompleteState.moveSelection("ArrowDown"===e.key?"next":"previous"))}processTabKey(e,t){if(e.preventDefault(),e.stopPropagation(),"inactive"!==this.composerStore.editionMode){const e=this.autoCompleteState;if(e.provider&&void 0!==e.selectedIndex){const t=e.provider.proposals[e.selectedIndex]?.text;if(t)return void this.autoComplete(t)}this.composerStore.stopEdition()}this.env.model.selection.moveAnchorCell(t,1)}processEnterKey(e,t){e.preventDefault(),e.stopPropagation();const o=this.autoCompleteState;if(o.provider&&void 0!==o.selectedIndex){const e=o.provider.proposals[o.selectedIndex]?.text;if(e)return void this.autoComplete(e)}this.composerStore.stopEdition(),this.env.model.selection.moveAnchorCell(t,1)}processNewLineEvent(e){e.preventDefault(),e.stopPropagation();const t=this.contentHelper.getText(),o=this.contentHelper.getCurrentSelection(),s=Math.min(o.start,o.end),i=Math.max(o.start,o.end);this.composerStore.stopComposerRangeSelection(),this.composerStore.setCurrentContent(t.slice(0,s)+le+t.slice(i),{start:s+1,end:s+1}),this.processContent()}processEscapeKey(){this.composerStore.cancelEdition()}processF4Key(e){e.stopPropagation(),this.composerStore.cycleReferences(),this.processContent()}processNumpadDecimal(e){e.stopPropagation(),e.preventDefault();const t=this.env.model.getters.getLocale(),o=this.contentHelper.getCurrentSelection(),s=this.composerStore.currentContent,i=s.slice(0,o.start)+t.decimalSeparator+s.slice(o.end);this.composerStore.setCurrentContent(i,{start:o.start+1,end:o.start+1}),this.processContent()}onCompositionStart(){this.compositionActive=!0}onCompositionEnd(){this.compositionActive=!1}onKeydown(e){if("inactive"===this.composerStore.editionMode)return;if(e.key.startsWith("Arrow"))return void this.processArrowKeys(e);let t=this.keyMapping[Zf(e)]||this.keyCodeMapping[Zf(e,"code")];t?t.call(this,e):e.stopPropagation()}onPaste(e){"inactive"!==this.composerStore.editionMode?e.stopPropagation():e.preventDefault()}onInput(e){if(!this.shouldProcessInputEvents)return;let t;if(e.stopPropagation(),t="inactive"===this.composerStore.editionMode?e.data||"":this.contentHelper.getText(),"inactive"===this.props.focus)return this.props.onComposerCellFocused?.(t);let o=this.contentHelper.getCurrentSelection();this.composerStore.stopComposerRangeSelection(),this.composerStore.setCurrentContent(t,o),this.processTokenAtCursor()}onKeyup(e){if(this.contentHelper.el===document.activeElement){if(this.autoCompleteState.provider&&["ArrowUp","ArrowDown"].includes(e.key))return;if(this.composerStore.isSelectingRange&&e.key?.startsWith("Arrow"))return;const{start:t,end:o}=this.composerStore.composerSelection,{start:s,end:i}=this.contentHelper.getCurrentSelection();s===t&&i===o||this.composerStore.changeComposerCursorSelection(s,i),this.processTokenAtCursor()}}updateAutoCompleteIndex(e){this.autoCompleteState.selectIndex(fe(0,e,10))}onMousedown(e){e.button>0||this.contentHelper.removeSelection()}onClick(){if(this.env.model.getters.isReadonly())return;const e=this.contentHelper.getCurrentSelection();this.composerStore.stopComposerRangeSelection(),this.props.onComposerContentFocused(),this.composerStore.changeComposerCursorSelection(e.start,e.end),this.processTokenAtCursor()}onDblClick(){if(this.env.model.getters.isReadonly())return;const e=this.composerStore.currentContent;if(e.startsWith("=")){const t=this.composerStore.currentTokens,o=this.contentHelper.getCurrentSelection();if(o.start===o.end)return;const s=e.substring(o.start,o.end),i=t.filter((e=>e.value.includes(s)&&e.start<=o.start&&e.end>=o.end))[0];if(!i)return;"REFERENCE"===i.type&&this.composerStore.changeComposerCursorSelection(i.start,i.end)}}onContextMenu(e){"inactive"===this.composerStore.editionMode&&this.props.onInputContextMenu?.(e)}processContent(){if(this.compositionActive)return;this.shouldProcessInputEvents=!1,"inactive"!==this.props.focus&&this.contentHelper.el.focus();const e=this.getContentLines();if(this.contentHelper.setText(e),0!==e.length&&0!==e.length[0]){if("inactive"!==this.props.focus){const{start:e,end:t}=this.composerStore.composerSelection;this.contentHelper.selectRange(e,t)}this.contentHelper.scrollSelectionIntoView()}this.shouldProcessInputEvents=!0}getContentLines(){let e=this.composerStore.currentContent;const t=e.startsWith("=");return""===e?[]:t&&"inactive"!==this.props.focus?this.splitHtmlContentIntoLines(this.getColoredTokens()):this.splitHtmlContentIntoLines([{value:e}])}getColoredTokens(){const e=this.composerStore.currentTokens,t=this.composerStore.tokenAtCursor,o=[],{end:s,start:i}=this.composerStore.composerSelection;for(const n of e){switch(n.type){case"OPERATOR":case"NUMBER":case"ARG_SEPARATOR":case"STRING":o.push({value:n.value,color:ab[n.type]||"#000"});break;case"REFERENCE":const{xc:e,sheetName:s}=Ai(n.value);o.push({value:n.value,color:this.rangeColor(e,s)||"#000"});break;case"SYMBOL":const i=n.value.toUpperCase();"TRUE"===i||"FALSE"===i?o.push({value:n.value,color:ab.NUMBER}):i in Mf.content?o.push({value:n.value,color:ab.FUNCTION}):o.push({value:n.value,color:"#000"});break;case"LEFT_PAREN":case"RIGHT_PAREN":t&&["LEFT_PAREN","RIGHT_PAREN"].includes(t.type)&&t.parenIndex&&t.parenIndex===n.parenIndex?o.push({value:n.value,color:ab.MATCHING_PAREN||"#000"}):o.push({value:n.value,color:ab[n.type]||"#000"});break;default:o.push({value:n.value,color:"#000"})}this.composerStore.showSelectionIndicator&&s===i&&s===n.end&&(o[o.length-1].class=ib)}return o}splitHtmlContentIntoLines(e){const t=[];let o=[];for(const s of e)if(s.value.includes(le)){const e=s.value.split(le),i=e.pop();for(const i of e)o.push({color:s.color,value:i}),t.push(o),o=[];o.push({...s,value:i})}else o.push(s);o.length&&t.push(o);const s=[];for(const e of t)e.every(this.isContentEmpty)?s.push([e[0]]):s.push(e.filter((e=>!this.isContentEmpty(e))));return s}isContentEmpty(e){return!(e.value||e.class)}rangeColor(e,t){if("inactive"===this.props.focus)return;const o=this.composerStore.highlights,s=t?this.env.model.getters.getSheetIdByName(t):this.composerStore.currentEditedCell.sheetId,i=o.find((t=>{if(t.sheetId!==s)return!1;let o=this.env.model.getters.getRangeFromSheetXC(s,e).zone;return o=1===an(o)?this.env.model.getters.expandZone(s,o):o,Zi(o,t.zone)}));return i&&i.color?i.color:void 0}processTokenAtCursor(){let e=this.composerStore.currentContent;this.autoCompleteState.provider&&this.autoCompleteState.hide(),this.functionDescriptionState.showDescription=!1;const t=this.composerStore.autocompleteProvider;if(t)return void this.autoCompleteState.useProvider(t);const o=this.composerStore.tokenAtCursor;if(e.startsWith("=")&&o&&"SYMBOL"!==o.type){const e=o.functionContext,t=e?.parent.toUpperCase();if(e&&t&&t in sb&&"UNKNOWN"!==o.type){const o=sb[t],s=e.argPosition;this.functionDescriptionState.functionName=t,this.functionDescriptionState.functionDescription=o,this.functionDescriptionState.argToFocus=o.getArgToFocus(s+1)-1,this.functionDescriptionState.showDescription=!0}}}autoComplete(e){e&&(this.autoCompleteState.provider?.selectProposal(e),this.processTokenAtCursor())}}class cb{scope;code="";constructor(e=new db){this.scope=e}append(...e){this.code+=e.map((e=>e.toString())).join("\n")+"\n"}return(e){return new hb(this.scope,this.code,e)}toString(){return ub(this.code)}}class hb{scope;returnExpression;code;constructor(e,t,o){this.scope=e,this.returnExpression=o,this.code=ub(t)}toString(){return this.code}assignResultToVariable(){if(this.scope.isAlreadyDeclared(this.returnExpression))return this;const e=this.scope.nextVariableName(),t=new cb(this.scope);return t.append(this.code),t.append(`const ${e} = ${this.returnExpression};`),t.return(e)}}class db{nextId=1;declaredVariables=new Set;nextVariableName(){const e="_"+this.nextId++;return this.declaredVariables.add(e),e}isAlreadyDeclared(e){return this.declaredVariables.has(e)}}function ub(e){let t="",o=0;const s=e.split("\n").map((e=>e.trim())).filter((e=>""!==e));for(const e of s)e.startsWith("}")&&o--,t+="\t".repeat(o)+e+"\n",e.endsWith("{")&&o++;return t.trim()}const gb=Mf.content,pb={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},mb={"-":"UMINUS","+":"UPLUS","%":"UNARY.PERCENT"},fb={};function bb(e){return vb(Jr(e))}function vb(e){const{dependencies:t,constantValues:o}=function(e){const t={numbers:[],strings:[]},o=[];for(const s of e)switch(s.type){case"INVALID_REFERENCE":case"REFERENCE":o.push(s.value);break;case"STRING":const e=he(s.value);t.strings.includes(e)||t.strings.push(e);break;case"NUMBER":{const e=no(s.value,Oo);t.numbers.includes(e)||t.numbers.push(e);break}}return{dependencies:o,constantValues:t}}(e),s=function(e,t,o){return Pe(e.map((e=>{switch(e.type){case"STRING":const s=he(e.value);return`|S${o.strings.indexOf(s)}|`;case"NUMBER":return`|N${o.numbers.indexOf(no(e.value,Oo))}|`;case"REFERENCE":case"INVALID_REFERENCE":return e.value.includes(":")?`R|${t.indexOf(e.value)}|`:`C|${t.indexOf(e.value)}|`;case"SPACE":return"";default:return e.value}})))}(e,t,o);if(!fb[s]){const i=Br([...e]),n=new db;if("BIN_OPERATION"===i.type&&":"===i.value)throw new Vo(go("Invalid formula"));if("EMPTY"===i.type)throw new Vo(go("Invalid formula"));const r=h(i),a=new cb;a.append(`// ${s}`),a.append(r),a.append(`return ${r.returnExpression};`);let l=new Function("deps","ref","range","ctx",a.toString());function c(e){const{args:t}=e,o=e.value.toUpperCase(),s=gb[o];if(!s)throw new Ho(go('Unknown function: "%s"',e.value));!function(e){const t=e.args.length,o=e.value.toUpperCase(),s=gb[o];if(t<s.minArgRequired)throw new Vo(go("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",o,s.minArgRequired.toString(),t.toString()));if(t>s.maxArgPossible)throw new Vo(go("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",o,s.maxArgPossible.toString(),t.toString()));const i=s.nbrArgRepeating;if(i>1){const e=s.args.length-i;if((t-e)%i!=0)throw new Vo(go("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",o,e.toString(),i.toString()))}}(e);const i=[];for(let e=0;e<t.length;e++){const o=s.getArgToFocus(e+1)-1,n=s.args[o],r=t[e],a=n.type||[],l=a.includes("META"),c=a.some((e=>e.startsWith("RANGE")));i.push(h(r,l,c))}return i}function h(e,s=!1,i=!1){const r=new cb(n);if("REFERENCE"!==e.type&&("BIN_OPERATION"!==e.type||":"!==e.value)&&s)throw new Vo(go("Argument must be a reference to a cell or range."));switch(e.debug&&r.append("debugger;"),e.type){case"BOOLEAN":return r.return(`{ value: ${e.value} }`);case"NUMBER":return r.return(`{ value: this.constantValues.numbers[${o.numbers.indexOf(e.value)}] }`);case"STRING":return r.return(`{ value: this.constantValues.strings[${o.strings.indexOf(e.value)}] }`);case"REFERENCE":const n=t.indexOf(e.value);return!s&&e.value.includes(":")||i?r.return(`range(deps[${n}])`):r.return(`ref(deps[${n}], ${s?"true":"false"})`);case"FUNCALL":const a=c(e).map((e=>e.assignResultToVariable()));r.append(...a);const l=e.value.toUpperCase();return r.return(`ctx['${l}'](${a.map((e=>e.returnExpression))})`);case"UNARY_OPERATION":{const t=mb[e.value],o=h(e.operand,!1,!1).assignResultToVariable();return r.append(o),r.return(`ctx['${t}'](${o.returnExpression})`)}case"BIN_OPERATION":{const t=pb[e.value],o=h(e.left,!1,!1).assignResultToVariable(),s=h(e.right,!1,!1).assignResultToVariable();return r.append(o),r.append(s),r.return(`ctx['${t}'](${o.returnExpression}, ${s.returnExpression})`)}case"EMPTY":return r.return("undefined")}}fb[s]=l}return{execute:fb[s],dependencies:t,constantValues:o,tokens:e}}const Sb=Mf.content;function Cb(e){try{return 0===zr(Br(e)).filter((e=>"FUNCALL"===e.type&&!Sb[e.value.toUpperCase()]?.isExported)).length}catch(e){return!1}}function yb(e,t){if(!e.some((e=>"SYMBOL"===e.type&&t.includes(e.value.toUpperCase()))))return[];let o;try{o=Br(e)}catch{return[]}return function(e,t){return zr(e).filter((e=>"FUNCALL"===e.type&&t.includes(e.value.toUpperCase()))).map((e=>({functionName:e.value.toUpperCase(),args:e.args})))}(o,t)}const Eb=["PIVOT.VALUE","PIVOT.HEADER","PIVOT"],xb={count:go("Count"),count_distinct:go("Count Distinct"),bool_and:go("Boolean And"),bool_or:go("Boolean Or"),max:go("Maximum"),min:go("Minimum"),avg:go("Average"),sum:go("Sum")},wb=["max","min","avg","sum","count_distinct","count"],Ib={integer:wb,char:wb},Rb={};for(const e in Ib){Rb[e]={};for(const t of Ib[e])Rb[e][t]=xb[t]}const Tb={count:{fn:e=>$h([e]),format:()=>"0"},count_distinct:{fn:e=>Oc([e]),format:()=>"0"},bool_and:{fn:e=>em([e]).result,format:()=>{}},bool_or:{fn:e=>tm([e]).result,format:()=>{}},max:{fn:(e,t)=>Gh([e],t),format:Wo},min:{fn:(e,t)=>Wh([e],t),format:Wo},avg:{fn:(e,t)=>Hh([e],t),format:Wo},sum:{fn:(e,t)=>Ac([e],t),format:Wo}};function Ab(e,t){return`=${e}(${t.map((e=>{const t="string"==typeof e&&!isNaN(Number(e))&&Number(e).toString()===e;return"number"==typeof e||t?`${e}`:`"${e.toString().replace(/"/g,'\\"')}"`})).join(",")})`}function Ob(e){const t=Object.keys(e);if(!t.length)return 0;const o=t.map((e=>parseInt(e,10)));return Math.max(...o)}function _b(e){return yb(e,Eb)[0]}function Db(e){return yb(e,Eb).length}const Mb={year:go("Year"),quarter:go("Quarter"),month:go("Month"),week:go("Week"),day:go("Day"),year_number:go("Year"),quarter_number:go("Quarter"),month_number:go("Month"),iso_week_number:go("Week"),day_of_month:go("Day of Month")},Fb=["date","datetime"];function Nb(e){const[t,o]=e.split(":");return o?{name:t,granularity:o}:{name:t}}function Pb(e){return Fb.includes(e.type)}function Lb(e,t){const o=`"${t?`${e.name}:${t}`:e.name}"`;return{text:o,description:e.string+(e.help?` (${e.help})`:""),htmlContent:[{value:o,color:ab.STRING}],fuzzySearchKey:e.string+o}}function kb(e,t){let o=e.end;const s=e.end;"ARG_SEPARATOR"!==e.type&&(o=e.start),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function Vb(e,t){let o=e.end;const s=e.end;"LEFT_PAREN"!==e.type&&(o=e.start),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function Ub(e){const t=e.functionContext?.args[0];if(t&&["STRING","NUMBER"].includes(t.type))return t.value}function Bb(e){if(e.length%2!=0)throw new Error("Invalid domain: odd number of elements");const t=[];for(let o=0;o<e.length-1;o+=2)t.push({field:e[o],value:e[o+1]});return t}Sa.add("pivot_ids",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!["PIVOT.VALUE","PIVOT.HEADER","PIVOT"].includes(t.parent.toUpperCase())||0!==t.argPosition)return;const o=this.getters.getPivotIds();return o.includes(e.value)?void 0:o.map((e=>{const o=this.getters.getPivotCoreDefinition(e);if("PIVOT"!==t.parent.toUpperCase()&&!gm.get(o.type))return;const s=`${this.getters.getPivotFormulaId(e)}`;return{text:s,description:o.name,htmlContent:[{value:s,color:ab.NUMBER}],fuzzySearchKey:s+o.name}})).filter(_e)},selectProposal:Vb}),Sa.add("pivot_measures",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if("PIVOT.VALUE"!==t?.parent.toUpperCase()||1!==t.argPosition)return[];const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return[];const i=this.getters.getPivot(s).getFields();if(!i)return[];const n=this.getters.getPivotCoreDefinition(s);return gm.get(n.type)?n.measures.map((e=>{if("__count"===e.name){const e='"__count"';return{text:e,description:go("Count"),htmlContent:[{value:e,color:ab.STRING}],fuzzySearchKey:go("Count")+e}}const t=i[e.name];if(t)return Lb(t)})).filter(_e):[]},selectProposal:kb}),Sa.add("pivot_group_fields",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==0}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==1}(e))return;const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s),n=i.getFields();if(!n)return;const{type:r}=this.getters.getPivotCoreDefinition(s),{columns:a,rows:l}=i.definition;if(!gm.get(r))return[];let c=t.args;"PIVOT.VALUE"===t?.parent.toUpperCase()?(c=c.filter(((e,t)=>t%2==0)),c=c.slice(1,t.argPosition)):c=c.filter(((e,t)=>t%2==1));const h=c.map((e=>e?.value)).filter(_e),d=a.map((e=>e.nameWithGranularity)),u=l.map((e=>e.nameWithGranularity)),g=[],p=["ARG_SEPARATOR","SPACE"].includes(e.type)?h.at(-1):h.at(-2);if(void 0===p&&(g.push(d[0]),g.push(u[0])),u.includes(p)){const e=u[u.indexOf(p)+1];g.push(e),g.push(d[0])}if(d.includes(p)){const e=d[d.indexOf(p)+1];g.push(e)}const m=g.filter(_e);return m.map((e=>{const[t,o]=e.split(":"),s=n[t];return s?Lb(s,o):void 0})).concat(m.map((e=>{const t=e.split(":")[0],o=n[t];if(!o)return;const s=`"#${e}"`;return{text:s,description:go("%s (positional)",o.string)+(o.help?` (${o.help})`:""),htmlContent:[{value:s,color:ab.STRING}],fuzzySearchKey:o.string+s}}))).filter(_e)},selectProposal:kb}),Sa.add("pivot_group_values",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!e||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==1}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==0}(e))return;const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const{type:i}=this.getters.getPivotCoreDefinition(s);if(!gm.get(i))return[];const n=this.getters.getPivot(s);if(!n.isValid())return;const r=t.argPosition,a=e.functionContext?.args[r-1]?.value;return a?n.getPossibleFieldValues(a.toString().split(":")[0]).map((({value:e,label:t})=>{const o="string"==typeof e,s=o?`"${e}"`:e.toString();return{text:s,description:t,htmlContent:[{value:s,color:o?ab.STRING:ab.NUMBER}],fuzzySearchKey:e+t}})):void 0},selectProposal:kb}),Sa.add("sheet_names",{sequence:150,autoSelectFirstProposal:!0,getProposals(e){return"SYMBOL"===e.type||"UNKNOWN"===e.type&&e.value.startsWith("'")?this.getters.getSheetIds().map((e=>{const t=me(this.getters.getSheetName(e));return{text:t,fuzzySearchKey:t.startsWith("'")?t:"'"+t}})):[]},selectProposal(e,t){const o=e.start,s=e.end;this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t+"!")}});const Hb=new $n;Hb.add("ALPHANUMERIC_INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=`${e.prefix}${e.current.toString().padStart(e.numberPostfixLength||0,"0")}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:o},tooltip:{props:{content:o}}}}}).add("INCREMENT_MODIFIER",{apply:(e,t,o)=>{e.current+=e.increment;const s=e.current.toString(),i=o.getLocale(),n=zs(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:n}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,o)=>{const s=t.cell?.content||"",i={locale:o.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:ca(t.cell?.content,i).formattedValue}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let i=0,n=0;switch(s){case"up":i=0,n=-e.current;break;case"down":i=0,n=e.current;break;case"left":i=-e.current,n=0;break;case"right":i=e.current,n=0}const r=t.cell;if(!r||!r.isFormula)return{cellData:{}};const a=t.sheetId,l=o.getTranslatedCellFormula(a,i,n,r.compiledFormula);return{cellData:{border:t.border,style:r.style,format:r.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const zb=new $n,$b=/(\d+)$/,Gb=/^(.*\D+)/,Wb=/^(.*\D+)(\d+)$/;function qb(e,t,o){let s=[],i=!1;for(let n of t){n===e&&(i=!0);const t=n?.isFormula?void 0:ca(n?.content,{locale:Oo});if(t&&o(t))s.push(t);else{if(i)return s;s=[]}}return s}function Zb(e){let t=1;return e.length>=2&&(t=function(e){const t=[];let o=e[0];for(let s=1;s<e.length;s++){const i=e[s];t.push(i-o),o=i}return t.reduce(((e,t)=>e+t),0)/t.length}(e)*e.length),t}zb.add("simple_value_copy",{condition:(e,t)=>!(1!==t.length||e.isFormula||e.format&&Ys(e.format)),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("increment_alphanumeric_value",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.text&&Wb.test(e.content),generateRule:(e,t)=>{const o=parseInt(e.content.match($b)[0]),s=e.content.match(Gb)[0],i=e.content.length-s.length,n=Zb(qb(e,t,(e=>e.type===mo.text&&Wb.test(e.value))).filter((e=>s===(e.value??"").toString().match(Gb)[0])).map((e=>parseInt((e.value??"").toString().match($b)[0]))));return{type:"ALPHANUMERIC_INCREMENT_MODIFIER",prefix:s,current:o,increment:n,numberPostfixLength:i}},sequence:15}).add("copy_text",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.text,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>e.isFormula,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_number",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.number,generateRule:(e,t)=>{const o=Zb(qb(e,t,(e=>e.type===mo.number)).map((e=>Number(e.value)))),s=ca(e.content,{locale:Oo});return{type:"INCREMENT_MODIFIER",increment:o,current:s.type===mo.number?s.value:0}},sequence:40});const jb=new $n,Yb=30,Xb=10,Kb=20,Qb=12,Jb=80,ev="#F3F2F1",tv="#666666",ov="#C8C8C8",sv="#666666aa",iv=6,nv=25,rv=T,av=R,lv=R;function cv(e,t){const o=e.getBoundingClientRect();e.width=o.width,e.height=o.height;const s=e.getContext("2d"),i=function(e,t,o){const s=t.maxValue,i=t.minValue,n=t.gaugeValue,r=function(e,t){const o=t?nv:0,s=e.height-Kb-o-Xb,i=e.width-2*Yb;let n,r;i>2*s?(n=2*s,r=s):(n=i,r=i/2);const a=o+Xb+(s-r)/2;return{x:Yb+(i-n)/2,y:a,width:n,height:r}}(e,t.title.text),a=r.width/6,l=n?(n.value-i.value)/(s.value-i.value):0,c={x:e.width/2,y:r.y+r.height-r.height/12};let h=Jb;r.height<300&&(h*=r.height/300);const d=r.width/2,u=n?.label||"-";wn(o,u,{fontSize:h},"px")>d&&(h=Fn(d,h,(e=>wn(o,u,{fontSize:e},"px"))));const g={x:r.x+a/2,y:r.y+r.height+Qb},p={x:r.x+r.width-a/2,y:r.y+r.height+Qb},m=(b=t.background,lt(b)>.3?tv:ov),f=function(e,t,o,s){const i=e.maxValue,n=e.minValue,r={x:t.x+t.width/2,y:t.y+t.height},a={fontSize:Qb},l=[],c=[];for(const h of e.inflectionValues){const e=(h.value-n.value)/(i.value-n.value),d=wn(s,h.label,a,"px"),u=Math.PI-Math.PI*e,g=pv(u,t.height+iv,r.x,r.y,d+2,Qb);let p=c.some((e=>gv(e,g)))?Qb:0;c.push(g),l.push({rotation:u,label:h.label,fontSize:Qb,color:o,offset:p})}return l}(t,r,m,o);var b;let v=0,S=0,C=0;t.title.text&&({width:S,height:C}=Tn(o,t.title.text,{...t.title,fontSize:rv},"px"));switch(t.title.align){case"right":v=e.width-S-av;break;case"center":v=(e.width-S)/2;break;default:v=av}return{width:e.width,height:e.height,title:{label:t.title.text??"",fontSize:rv,textPosition:{x:v,y:lv+C/2},color:t.title.color??m,bold:t.title.bold,italic:t.title.italic},backgroundColor:t.background,gauge:{rect:r,arcWidth:a,percentage:fe(l,0,1),color:hv(t)},inflectionValues:f,gaugeValue:{label:u,textPosition:c,fontSize:h,color:m},minLabel:{label:t.minValue.label,textPosition:g,fontSize:Qb,color:m},maxLabel:{label:t.maxValue.label,textPosition:p,fontSize:Qb,color:m}}}(o,t,s);!function(e,t){e.save(),e.fillStyle=t.backgroundColor,e.fillRect(0,0,t.width,t.height),e.restore()}(s,i),function(e,t){e.save();const o=t.gauge,s=o.rect.x+o.rect.width/2,i=o.rect.y+o.rect.height,n=o.rect.height-o.arcWidth/2;if(n<0)return;const r=1===o.percentage?0:Math.PI*(1+o.percentage);e.strokeStyle=ev,e.beginPath(),e.lineWidth=o.arcWidth,e.arc(s,i,n,r,0),e.stroke(),e.strokeStyle=o.color,e.beginPath(),e.arc(s,i,n,Math.PI,r),e.stroke(),e.restore()}(s,i),function(e,t){const{x:o,y:s,width:i,height:n}=t.gauge.rect;for(const r of t.inflectionValues){e.save(),e.translate(o+i/2-.5,s+n-.5),e.rotate(Math.PI/2-r.rotation),e.lineWidth=2,e.strokeStyle=sv,e.beginPath(),e.moveTo(0,-(n-t.gauge.arcWidth)),e.lineTo(0,-n-3),e.stroke(),e.textAlign="center",e.font=`${r.fontSize}px ${W}`,e.fillStyle=r.color;const a=-n-iv-r.offset;e.fillText(r.label,0,a),e.restore()}}(s,i),function(e,t){for(const o of[t.minLabel,t.maxLabel,t.gaugeValue])e.save(),e.textAlign="center",e.fillStyle=o.color,e.font=`${o.fontSize}px ${W}`,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(s,i),function(e,t){e.save();const o=t.title;e.font=En(o.fontSize,o.bold,o.italic),e.textBaseline="middle",e.fillStyle=o.color,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(s,i)}function hv(e){const t=e.gaugeValue?.value;if(void 0===t)return ev;let o=0;for(;e.inflectionValues[o]?.value<=t;)o++;return e.colors[o]}function dv(e){return[{start:e.topLeft,end:e.topRight},{start:e.topRight,end:e.bottomRight},{start:e.bottomRight,end:e.bottomLeft},{start:e.bottomLeft,end:e.topLeft}]}function uv(e,t){const o=e.start,s=e.end,i=t.start,n=t.end;function r(e,t,o){return(o.y-e.y)*(t.x-e.x)>(t.y-e.y)*(o.x-e.x)}return r(o,i,n)!==r(s,i,n)&&r(o,s,i)!==r(o,s,n)}function gv(e,t){const o=dv(e),s=dv(t);for(const e of o)for(const t of s)if(uv(e,t))return!0;return!1}function pv(e,t,o,s,i,n){const r=Math.cos(e),a=Math.sin(e),l=r*t,c=a*t,h=a*(i/2),d=r*(i/2),u=r*(t+n),g=a*(t+n);return{bottomLeft:{x:l-h+o,y:s-(c+d)},bottomRight:{x:l+h+o,y:s-(c-d)},topRight:{x:u+h+o,y:s-(g-d)},topLeft:{x:u-h+o,y:s-(g+d)}}}class mv extends t.Component{static template="o-spreadsheet-GaugeChartComponent";canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}setup(){t.useEffect((()=>cv(this.canvas.el,this.runtime)),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el]}))}}function fv(e){return 8===(e=it(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}function bv(e,t){if(t.dataRange){const o=t.labelCell?[t.labelCell.zone]:[],s=_i([t.dataRange.zone],o)[0];if(void 0===s)return[];const i=e.getRangeFromZone(t.dataRange.sheetId,s);return e.getRangeValues(i).map((e=>""===e?void 0:e))}return[]}function vv(e,t){const o=be(0,Math.max(e.length,...t.map((e=>e.data?.length||0)))).filter((o=>{const s=e[o],i=t.map((e=>e.data?.[o]));return s||i.some((e=>0===e||Boolean(e)))}));return{labels:o.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:o.map((t=>e.data[t]))})))}}function Sv(e,t){const o=new Set(e),s={};o.forEach((e=>{s[e]=new Array(t.length).fill(0)}));for(const o of be(0,e.length)){const n=e[o];for(const e of be(0,t.length))s[n][e]+="number"==typeof(i=t[e].data[o])?i:0}var i;return{labels:Array.from(o),dataSetsValues:t.map(((e,t)=>({...e,data:Array.from(o).map((e=>s[e][t]))})))}}function Cv(e){return e?e.length>X?e.substring(0,X)+"…":e:""}function yv(e,t,o,{format:s,locale:i,truncateLabels:n}){const r=e.title.text?e.title:{...e.title,content:""},a={responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:R,right:R,top:r.text?R/2:R+5,bottom:R}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:!1,plugins:{title:{display:!!r.text,text:go(r.text),color:r?.color??o,align:"center"===r.align?"center":"right"===r.align?"end":"start",font:{size:T,weight:r.bold?"bold":"normal",style:r.italic?"italic":"normal"}},legend:{onClick:()=>{}},tooltip:{callbacks:{label:function(e){const t=e.dataset?.label||e.label,o=e.parsed.y??e.parsed,n=zs(o,{format:!s&&Math.abs(o)>=1e3?"#,##":s,locale:i});return t?`${t}: ${n}`:n}}}}};return{type:e.type,options:a,data:{labels:n?t.map(Cv):t,datasets:[]},platform:void 0,plugins:[]}}function Ev(e,t,o){let s={values:[],formattedValues:[]};if(o)o.invalidXc||o.invalidSheetName||(s={formattedValues:e.getRangeFormattedValues(o),values:e.getRangeValues(o).map((e=>String(e??"")))});else if(1===t.length)for(let o=0;o<bv(e,t[0]).length;o++)s.formattedValues.push(""),s.values.push("");else if(t[0]){s={formattedValues:be(0,bv(e,t[0]).length).map((e=>e.toString())),values:s.formattedValues}}return s}function xv(e,t){for(const o of t){const t=e.getRangeFormats(o.dataRange).find((e=>void 0!==e&&!Ys(e)));if(t)return t}}function wv(e,t){const o=[];for(const[s,i]of Object.entries(t)){let t;if(i.labelCell){const o=i.labelCell,n=o?e.getEvaluatedCell({sheetId:o.sheetId,col:o.zone.left,row:o.zone.top}):void 0;t=n&&o?Cv(n.formattedValue):t=`${Ra.Series} ${parseInt(s)+1}`}else t=`${Ra.Series} ${parseInt(s)+1}`;let n=i.dataRange?bv(e,i):[];n.every((e=>"string"==typeof e&&!qo(e)))&&n.fill(1),o.push({data:n,label:t})}return o}function Iv(e){return 0===e?"origin":e-1}function Rv(e,t,o){const s=document.createElement("div");s.style.width=`${t.width}px`,s.style.height=`${t.height}px`;const i=document.createElement("canvas");if(s.append(i),i.setAttribute("width",t.width.toString()),i.setAttribute("height",t.height.toString()),document.body.append(s),"chartJsConfig"in e){const t=ue(e.chartJsConfig);t.plugins=[Tv];const o=new window.Chart(i,t),n=o.toBase64Image();return o.destroy(),s.remove(),n}if("scorecard"===o){Fl(Ll(t,e),i);const o=i.toDataURL();return s.remove(),o}if("gauge"===o){cv(i,e);const t=i.toDataURL();return s.remove(),t}}mv.props={figure:Object};const Tv={id:"customCanvasBackgroundColor",beforeDraw:e=>{const{ctx:t}=e;t.save(),t.globalCompositeOperation="destination-over",t.fillStyle="#ffffff",t.fillRect(0,0,e.width,e.height),t.restore()}};class Av extends hl{dataSets;labelRange;background;legendPosition;stacked;aggregated;type="bar";dataSetsHaveTitle;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.stacked=e.stacked,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,stacked:e.stacked??!1,aggregated:e.aggregated??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"bar",labelRange:e.auxiliaryRange||void 0,axesDesign:e.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Av(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Av(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"bar",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,stacked:this.stacked,aggregated:this.aggregated,axesDesign:this.axesDesign}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Av(i,this.sheetId,this.getters)}}class Ov extends hl{dataSets;labelRange;background;legendPosition;aggregated;dataSetsHaveTitle;dataSetDesign;axesDesign;type="combo";constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"combo",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated,axesDesign:this.axesDesign}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Ov(i,this.sheetId,this.getters)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,aggregated:e.aggregated,legendPosition:e.legendPosition??"top",title:e.title||{text:""},labelRange:e.auxiliaryRange||void 0,type:"combo",axesDesign:e.axesDesign}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Ov(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Ov(t,e,this.getters)}}function _v(e){return e.dataRange&&!Ei.test(e.dataRange)?"InvalidGaugeDataRange":"Success"}function Dv(e,t){return t((t=>t.sectionRule?e(t.sectionRule.rangeMin,"rangeMin"):"Success"),(t=>t.sectionRule?e(t.sectionRule.rangeMax,"rangeMax"):"Success"))}function Mv(e){return e.sectionRule&&Number(e.sectionRule.rangeMin)>=Number(e.sectionRule.rangeMax)?"GaugeRangeMinBiggerThanRangeMax":"Success"}function Fv(e,t){if(""===e)switch(t){case"rangeMin":return"EmptyGaugeRangeMin";case"rangeMax":return"EmptyGaugeRangeMax"}return"Success"}function Nv(e,t){if(isNaN(e))switch(t){case"rangeMin":return"GaugeRangeMinNaN";case"rangeMax":return"GaugeRangeMaxNaN";case"lowerInflectionPointValue":return"GaugeLowerInflectionPointNaN";case"upperInflectionPointValue":return"GaugeUpperInflectionPointNaN"}return"Success"}class Pv extends hl{dataRange;sectionRule;background;type="gauge";constructor(e,t,o){super(e,t,o),this.dataRange=mn(this.getters,this.sheetId,e.dataRange),this.sectionRule=e.sectionRule,this.background=e.background}static validateChartDefinition(e,t){return e.checkValidations(t,_v,e.chainValidations(Dv(Fv,e.batchValidations),Dv(Nv,e.batchValidations),Mv),e.chainValidations((o=Nv,(0,e.batchValidations)((e=>e.sectionRule?o(e.sectionRule.lowerInflectionPoint.value,"lowerInflectionPointValue"):"Success"),(e=>e.sectionRule?o(e.sectionRule.upperInflectionPoint.value,"upperInflectionPointValue"):"Success")))));var o}static transformDefinition(e,t){let o;return e.dataRange&&(o=Ar(Li(e.dataRange),t)),{...e,dataRange:o?Bi(o):void 0}}static getDefinitionFromContextCreation(e){return{background:e.background,title:e.title||{text:""},type:"gauge",dataRange:e.range?e.range[0].dataRange:void 0,sectionRule:{colors:{lowerColor:"#cc0000",middleColor:"#f1c232",upperColor:"#6aa84f"},rangeMin:"0",rangeMax:"100",lowerInflectionPoint:{type:"percentage",value:"15"},upperInflectionPoint:{type:"percentage",value:"40"}}}}copyForSheetId(e){const t=gl(this.sheetId,e,this.dataRange),o=this.getDefinitionWithSpecificRanges(t,e);return new Pv(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.dataRange,e);return new Pv(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.dataRange)}getDefinitionWithSpecificRanges(e,t){return{background:this.background,sectionRule:this.sectionRule,title:this.title,type:"gauge",dataRange:e?this.getters.getRangeString(e,t||this.sheetId):void 0}}getDefinitionForExcel(){}getContextCreation(){return{...this,range:this.dataRange?[{dataRange:this.getters.getRangeString(this.dataRange,this.sheetId)}]:void 0}}updateRanges(e){const t=pl(this.dataRange,e);if(this.dataRange===t)return this;const o=this.getDefinitionWithSpecificRanges(t);return new Pv(o,this.sheetId,this.getters)}}function Lv(e,t,o){if(""===e.value||isNaN(Number(e.value)))return;const s=Number(e.value);return fe("number"===e.type?s:t+(o-t)*s/100,t,o)}const kv={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,year:31536e6},Vv={inSeconds:function(e){return Math.floor(e/kv.second)},inMinutes:function(e){return Math.floor(e/kv.minute)},inHours:function(e){return Math.floor(e/kv.hour)},inDays:function(e){return Math.floor(e/kv.day)},inMonths:function(e){return Math.floor(e/kv.month)},inYears:function(e){return Math.floor(e/kv.year)}},Uv=/^((d|dd|m|mm|yyyy|yy|hh|h|ss|a)(-|:|\s|\/))*(d|dd|m|mm|yyyy|yy|hh|h|ss|a)$/i;function Bv(e,t,o){const s=function(e){const t=e.indexOf("h");e=t>=0?e.slice(0,t).replace(/m/g,"M")+e.slice(t):e.replace(/m/g,"M");e.includes("a")||(e=e.replace(/h/g,"H"));return e}(t),i=function(e,t,o){const s=e.map((e=>zt(e,o)?.jsDate));if(s.some((e=>void 0===e))||e.length<2)return;const i=s.map((e=>e.getTime())),n=Qe(i)-Je(i),r=function(e){if(e.includes("s"))return"second";if(e.includes("m"))return"minute";if(e.includes("h")||e.includes("H"))return"hour";if(e.includes("d"))return"day";if(e.includes("M"))return"month";return"year"}(t);if(kv.second>=kv[r]&&Vv.inSeconds(n)<180)return"second";if(kv.minute>=kv[r]&&Vv.inMinutes(n)<180)return"minute";if(kv.hour>=kv[r]&&Vv.inHours(n)<96)return"hour";if(kv.day>=kv[r]&&Vv.inDays(n)<90)return"day";if(kv.month>=kv[r]&&Vv.inMonths(n)<36)return"month";return"year"}(e,s,o),n={};return i&&(n[i]=s),{parser:s,displayFormats:n,unit:i??!1}}function Hv(e,t){return $v(e,t)||Gv(e,t)}function zv(e,t){return function(e,t){return!e.labelsAsText&&$v(e.labelRange,t)}(e,t)&&function(){if(!window.Chart)return!1;const e="luxon"===new window.Chart._adapters._date({})._id;e||Wv||(Wv=!0,console.warn("'chartjs-adapter-luxon' time adapter is not installed. Time scale axes are disabled."));return e}()?"time":function(e,t){return!e.labelsAsText&&Gv(e.labelRange,t)}(e,t)?"linear":"category"}function $v(e,t){if(!e||!Gv(e,t))return!1;const o=t.getEvaluatedCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}).format;return Boolean(o&&Uv.test(o))}function Gv(e,t){if(!e)return!1;const o=t.getRangeValues(e);return!o.some((e=>isNaN(Number(e))&&e))&&!o.every((e=>!e))}let Wv=!1;function qv(e,t){const o=zv(e,t),s=Ev(t,e.dataSets,e.labelRange);let i="linear"===o?s.values:s.formattedValues,n=wv(t,e.dataSets);e.dataSetsHaveTitle&&n[0]&&i.length>n[0].data.length&&i.shift(),({labels:i,dataSetsValues:n}=vv(i,n)),"time"===o&&({labels:i,dataSetsValues:n}=function(e,t){if(0===e.length||e.every((e=>!e)))return{labels:e,dataSetsValues:t};const o=[...e],s=ue(t);for(let e=0;e<o.length;e++)if(!o[e]){o[e]=ke(o,e);for(let t of s)t.data[e]=void 0}return{labels:o,dataSetsValues:s}}(i,n)),e.aggregated&&({labels:i,dataSetsValues:n}=Sv(i,n));const r=t.getLocale(),a="category"===o,l=xv(t,e.dataSets),c=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s,generateLabels(e){const{data:t}=e,o=window.Chart.defaults.plugins.legend.labels.generateLabels(e);for(const[e,s]of o.entries())s.fillStyle=t.datasets[e].borderColor;return o}}};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,Object.assign(i.options.plugins.legend||{},n),i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.scales={x:{ticks:{padding:5,color:s},title:wl(e.axesDesign?.x)}};const r={beginAtZero:!0,ticks:{color:s,callback:e=>{if(e=Number(e),isNaN(e))return e;const{locale:t,format:s}=o;return zs(e,{locale:t,format:!s&&Math.abs(e)>=1e3?"#,##":s})}}},{useLeftAxis:a,useRightAxis:l}=Il(e.getDefinition());return a&&(i.options.scales.y={...r,position:"left",title:wl(e.axesDesign?.y)}),l&&(i.options.scales.y1={...r,position:"right",title:wl(e.axesDesign?.y1)}),"stacked"in e&&e.stacked&&(a&&(i.options.scales.y.stacked=!0),l&&(i.options.scales.y1.stacked=!0)),i}(e,i,{format:l,locale:r,truncateLabels:a}),h=function(e,t){if(t)return e.getEvaluatedCell({sheetId:t.sheetId,col:t.zone.left,row:t.zone.top}).format}(t,e.labelRange);if("time"===o){const e={type:"time",time:Bv(i,h,r)};Object.assign(c.options.scales.x,e),c.options.scales.x.ticks.maxTicksLimit=15}else"linear"===o&&(c.options.scales.x.type="linear",c.options.scales.x.ticks.callback=e=>zs(e,{format:h,locale:r}),c.options.plugins.tooltip.callbacks.title=e=>zs(e[0].parsed.x||e[0].label,{locale:r,format:h}));const u="stacked"in e&&e.stacked,g="cumulative"in e&&e.cumulative,p=new St,m=e.getDefinition();for(let[e,{label:t,data:s}]of n.entries()){["linear","time"].includes(o)&&(s=s.map(((e,t)=>({x:i[t]||void 0,y:e}))));const n=p.next();let r=ht(n);if(u&&(r.a=te),g){let e=0;s=s.map((t=>isNaN(t)?t:(e+=parseFloat(t),e)))}const a={label:t,data:s,tension:0,borderColor:n,backgroundColor:ct(r),pointBackgroundColor:n,fill:!!u&&Iv(e)};c.data.datasets.push(a)}for(const[e,t]of c.data.datasets.entries()){if(m.dataSets?.[e]?.backgroundColor){const o=m.dataSets[e].backgroundColor;t.backgroundColor=o,t.borderColor=o,t.pointBackgroundColor=o}if(m.dataSets?.[e]?.label){const o=m.dataSets[e].label;t.label=o}m.dataSets?.[e]?.yAxisId&&(t.yAxisID=m.dataSets[e].yAxisId)}return{chartJsConfig:c,background:e.background||d,dataSetsValues:n,labelValues:s,dataSetFormat:l,labelFormat:h}}class Zv extends hl{dataSets;labelRange;background;legendPosition;labelsAsText;stacked;aggregated;type="line";dataSetsHaveTitle;cumulative;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(this.getters,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.stacked=e.stacked,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.cumulative=e.cumulative,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static transformDefinition(e,t){return Sl(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,labelsAsText:e.labelsAsText??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"line",labelRange:e.auxiliaryRange||void 0,stacked:e.stacked??!1,aggregated:e.aggregated??!1,cumulative:e.cumulative??!1,axesDesign:e.axesDesign}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"line",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,stacked:this.stacked,aggregated:this.aggregated,cumulative:this.cumulative,axesDesign:this.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Zv(i,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Zv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Zv(t,e,this.getters)}}class jv extends hl{dataSets;labelRange;background;legendPosition;type="pie";aggregated;dataSetsHaveTitle;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"pie",labelRange:e.auxiliaryRange||void 0,aggregated:e.aggregated??!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getContextCreation(){return{...this,range:this.dataSets.map((e=>({dataRange:this.getters.getRangeString(e.dataRange,this.sheetId)}))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinitionWithSpecificDataSets(e,t,o){return{type:"pie",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>({dataRange:this.getters.getRangeString(e.dataRange,o||this.sheetId)}))),legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new jv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new jv(t,e,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle));return{...this.getDefinition(),backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new jv(i,this.sheetId,this.getters)}}class Yv extends hl{dataSets;labelRange;background;legendPosition;labelsAsText;aggregated;type="scatter";dataSetsHaveTitle;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(this.getters,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static transformDefinition(e,t){return Sl(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,labelsAsText:e.labelsAsText??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"scatter",labelRange:e.auxiliaryRange||void 0,aggregated:e.aggregated??!1,axesDesign:e.axesDesign}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"scatter",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,aggregated:this.aggregated,axesDesign:this.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Yv(i,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Yv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Yv(t,e,this.getters)}}class Xv extends hl{dataSets;labelRange;background;verticalAxisPosition;legendPosition;aggregated;type="waterfall";dataSetsHaveTitle;showSubTotals;firstValueAsSubtotal;showConnectorLines;positiveValuesColor;negativeValuesColor;subTotalValuesColor;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.showSubTotals=e.showSubTotals,this.showConnectorLines=e.showConnectorLines,this.positiveValuesColor=e.positiveValuesColor,this.negativeValuesColor=e.negativeValuesColor,this.subTotalValuesColor=e.subTotalValuesColor,this.firstValueAsSubtotal=e.firstValueAsSubtotal,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,aggregated:e.aggregated??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"waterfall",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0,showSubTotals:e.showSubTotals??!1,showConnectorLines:e.showConnectorLines??!0,firstValueAsSubtotal:e.firstValueAsSubtotal??!1,axesDesign:e.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Xv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Xv(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"waterfall",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated,showSubTotals:this.showSubTotals,showConnectorLines:this.showConnectorLines,positiveValuesColor:this.positiveValuesColor,negativeValuesColor:this.negativeValuesColor,subTotalValuesColor:this.subTotalValuesColor,firstValueAsSubtotal:this.firstValueAsSubtotal,axesDesign:this.axesDesign}}getDefinitionForExcel(){}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Xv(i,this.sheetId,this.getters)}}const Kv=new $n;Kv.add("bar",{match:e=>"bar"===e,createChart:(e,t,o)=>new Av(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s));const i=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s}};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,i.options.plugins.legend={...i.options.plugins?.legend,...n},i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.scales={x:{ticks:{padding:5,color:s},title:wl(e.axesDesign?.x)}};const r={beginAtZero:!0,ticks:{color:s,callback:e=>{if(e=Number(e),isNaN(e))return e;const{locale:t,format:s}=o;return zs(e,{locale:t,format:!s&&Math.abs(e)>=1e3?"#,##":s})}}},{useLeftAxis:a,useRightAxis:l}=Il(e.getDefinition());return a&&(i.options.scales.y={...r,position:"left",title:wl(e.axesDesign?.y)}),l&&(i.options.scales.y1={...r,position:"right",title:wl(e.axesDesign?.y1)}),e.stacked&&(i.options.scales.x.stacked=!0,a&&(i.options.scales.y.stacked=!0),l&&(i.options.scales.y1.stacked=!0)),i}(e,o,{format:xv(t,e.dataSets),locale:t.getLocale()}),n=new St,r=e.getDefinition();for(const{label:e,data:t}of s){const o=n.next(),s={label:e,data:t,borderColor:o,backgroundColor:o};i.data.datasets.push(s)}for(const[e,t]of i.data.datasets.entries()){if(r.dataSets?.[e]?.backgroundColor){const o=r.dataSets[e].backgroundColor;t.backgroundColor=o,t.borderColor=o}if(r.dataSets?.[e]?.label){const o=r.dataSets[e].label;t.label=o}r.dataSets?.[e]?.yAxisId&&(t.yAxisID=r.dataSets[e].yAxisId)}return{chartJsConfig:i,background:e.background||d}},validateChartDefinition:Av.validateChartDefinition,transformDefinition:Av.transformDefinition,getChartDefinitionFromContextCreation:Av.getDefinitionFromContextCreation,name:go("Bar"),sequence:10}),Kv.add("combo",{match:e=>"combo"===e,createChart:(e,t,o)=>new Ov(e,t,o),getChartRuntime:function(e,t){const o=e.dataSets.length?xv(t,[e.dataSets[0]]):void 0,s=xv(t,e.dataSets.slice(1)),i=t.getLocale();let n=Ev(t,e.dataSets,e.labelRange).formattedValues,r=wv(t,e.dataSets);e.dataSetsHaveTitle&&r[0]&&n.length>r[0].data.length&&n.shift(),({labels:n,dataSetsValues:r}=vv(n,r)),e.aggregated&&({labels:n,dataSetsValues:r}=Sv(n,r));const a={format:o,locale:i},l=Cl(e.background),c=yv(e,n,l,a),h={labels:{color:l},reverse:!0};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?h.display=!1:h.position=e.legendPosition,c.options.plugins.legend={...c.options.plugins?.legend,...h},c.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},c.options.scales={x:{ticks:{padding:5,color:l},title:wl(e.axesDesign?.x)}};const u=e=>t=>{if(t=Number(t),isNaN(t))return t;const{locale:o}=a;return zs(t,{locale:o,format:!e&&Math.abs(t)>=1e3?"#,##":e})},g={beginAtZero:!0,ticks:{color:l,callback:u(o)}},p={beginAtZero:!0,ticks:{color:l,callback:u(s)}},m=e.getDefinition(),{useLeftAxis:f,useRightAxis:b}=Il(m);f&&(c.options.scales.y={...g,position:"left",title:wl(e.axesDesign?.y)}),b&&(c.options.scales.y1={...p,position:"right",grid:{display:!1},title:wl(e.axesDesign?.y1)});const v=new St;for(let[e,{label:t,data:o}]of r.entries()){const s=m.dataSets[e],i=v.next(),n={label:s?.label??t,data:o,borderColor:s?.backgroundColor??i,backgroundColor:s.backgroundColor??i,yAxisID:s?.yAxisId??"y",type:0===e?"bar":"line",order:-e};c.data.datasets.push(n)}return{chartJsConfig:c,background:e.background||d}},validateChartDefinition:Ov.validateChartDefinition,transformDefinition:Ov.transformDefinition,getChartDefinitionFromContextCreation:Ov.getDefinitionFromContextCreation,name:go("Combo"),sequence:15}),Kv.add("line",{match:e=>"line"===e,createChart:(e,t,o)=>new Zv(e,t,o),getChartRuntime:function(e,t){const{chartJsConfig:o,background:s}=qv(e,t);return{chartJsConfig:o,background:s}},validateChartDefinition:Zv.validateChartDefinition,transformDefinition:Zv.transformDefinition,getChartDefinitionFromContextCreation:Zv.getDefinitionFromContextCreation,name:go("Line"),sequence:20}),Kv.add("pie",{match:e=>"pie"===e,createChart:(e,t,o)=>new jv(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s)),({dataSetsValues:s,labels:o}=function(e,t){const o=e.reduce(((e,o,s)=>(t.some((e=>{const t=e.data[s];return"number"!=typeof t||t>=0}))&&e.push(s),e)),[]);return{labels:o.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:o.map((t=>{const o=e.data[t];return"number"!=typeof o||o>=0?o:0}))})))}}(o,s));const i=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,Object.assign(i.options.plugins.legend||{},n),i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.plugins.tooltip.callbacks.title=function(e){return e[0].dataset.label},i.options.plugins.tooltip.callbacks.label=function(e){const{format:t,locale:s}=o,i=function(e,t){const o=e.filter((e=>"number"==typeof e)).reduce(((e,t)=>e+t),0);if(!o)return"";return(e[t]/o*100).toFixed(2)}(e.dataset.data,e.dataIndex),n=e.label||e.dataset.label,r=e.parsed.y??e.parsed,a=zs(r,{format:!t&&r>=1e3?"#,##":t,locale:s});return n?`${n}: ${a} (${i}%)`:`${a} (${i}%)`},i}(e,o,{format:xv(t,e.dataSets),locale:t.getLocale()}),n=function(e,t){const o=[],s=Qe(t.map((e=>e.data.length)));for(let t=0;t<=s;t++)o.push(e.next());return o}(new St,s);for(const{label:e,data:t}of s){const o={label:e,data:t,borderColor:"#FFFFFF",backgroundColor:n};i.data.datasets.push(o)}return{chartJsConfig:i,background:e.background||d}},validateChartDefinition:jv.validateChartDefinition,transformDefinition:jv.transformDefinition,getChartDefinitionFromContextCreation:jv.getDefinitionFromContextCreation,name:go("Pie"),sequence:30}),Kv.add("scorecard",{match:e=>"scorecard"===e,createChart:(e,t,o)=>new Ml(e,t,o),getChartRuntime:function(e,t){let o,s="";const i=t.getLocale();if(e.keyValue){const n={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};o=t.getEvaluatedCell(n),s=function(e,t,o){return e?t?ri(e,o):e.formattedValue??String(e.value??""):""}(o,e.humanize??!1,i)}let n;const r=e.baseline;if(r){const e={sheetId:r.sheetId,col:r.zone.left,row:r.zone.top};n=t.getEvaluatedCell(e)}const{background:a,fontColor:l}=t.getStyleOfSingleCellChart(e.background,e.keyValue),c=function(e,t,o,s,i){if(!e)return"";if("text"===o||t?.type!==mo.number||e.type!==mo.number)return s?ri(e,i):e.formattedValue;let{value:n,format:r}=e;return"progress"===o?(n=t.value/n,r="0.0%"):(n=Math.abs(t.value-n),"percentage"===o&&0!==n&&(n/=e.value),"percentage"===o&&(r="0.0%"),r||(n=Math.round(100*n)/100)),s?ri({value:n,format:r},i):zs(n,{format:r,locale:i})}(n,o,e.baselineMode,e.humanize??!1,i),h="progress"===e.baselineMode&&so(c,i)?jo(c,i):0;return{title:{...e.title,text:go(e.title.text??"")},keyValue:s,baselineDisplay:c,baselineArrow:Tl(n,o,e.baselineMode),baselineColor:Rl(n,e.baselineMode,o,e.baselineColorUp,e.baselineColorDown),baselineDescr:"progress"!==e.baselineMode&&e.baselineDescr?go(e.baselineDescr):"",fontColor:l,background:a,baselineStyle:"percentage"!==e.baselineMode&&"progress"!==e.baselineMode&&r?t.getCellStyle({sheetId:r.sheetId,col:r.zone.left,row:r.zone.top}):void 0,keyValueStyle:e.keyValue?t.getCellStyle({sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top}):void 0,progressBar:"progress"===e.baselineMode?{value:h,color:h>0?e.baselineColorUp:e.baselineColorDown}:void 0}},validateChartDefinition:Ml.validateChartDefinition,transformDefinition:Ml.transformDefinition,getChartDefinitionFromContextCreation:Ml.getDefinitionFromContextCreation,name:go("Scorecard"),sequence:40}),Kv.add("gauge",{match:e=>"gauge"===e,createChart:(e,t,o)=>new Pv(e,t,o),getChartRuntime:function(e,t){const o=t.getLocale(),s=e.sectionRule.colors;let i,n,r;const a=e.dataRange;if(void 0!==a){const e=t.getEvaluatedCell({sheetId:a.sheetId,col:a.zone.left,row:a.zone.top});e.type===mo.number&&(i=e.value,n=e.formattedValue,r=e.format)}const l=Number(e.sectionRule.rangeMin),c=Number(e.sectionRule.rangeMax),h=e.sectionRule.lowerInflectionPoint,d=e.sectionRule.upperInflectionPoint,u=Lv(h,l,c),g=Lv(d,l,c),p=[],m=[];return void 0!==u&&(p.push({value:u,label:zs(u,{locale:o,format:r})}),m.push(s.lowerColor)),void 0!==g&&g!==u&&(p.push({value:g,label:zs(g,{locale:o,format:r})}),m.push(s.middleColor)),void 0!==g&&void 0!==u&&u>g&&(p.reverse(),m.reverse()),m.push(s.upperColor),{background:t.getStyleOfSingleCellChart(e.background,a).background,title:e.title??{text:""},minValue:{value:l,label:zs(l,{locale:o,format:r})},maxValue:{value:c,label:zs(c,{locale:o,format:r})},gaugeValue:void 0!==i&&n?{value:i,label:n}:void 0,inflectionValues:p,colors:m}},validateChartDefinition:Pv.validateChartDefinition,transformDefinition:Pv.transformDefinition,getChartDefinitionFromContextCreation:Pv.getDefinitionFromContextCreation,name:go("Gauge"),sequence:50}),Kv.add("scatter",{match:e=>"scatter"===e,createChart:(e,t,o)=>new Yv(e,t,o),getChartRuntime:function(e,t){const{chartJsConfig:o,background:s,dataSetsValues:i,dataSetFormat:n,labelValues:r,labelFormat:a}=qv(e,t);o.type="line";const l=o.options,c=t.getLocale();l.plugins.tooltip.callbacks.title=()=>"",l.plugins.tooltip.callbacks.label=e=>{const t=i[e.datasetIndex].data[e.dataIndex];let o=e.label||r.values[e.dataIndex];so(o,c)&&(o=jo(o,c));const s=zs(o,{locale:c,format:a}),l=zs(t,{locale:c,format:n}),h=e.dataset.label;return s?`${h}: (${s}, ${l})`:`${h}: ${l}`};for(const e of o.data.datasets)e.showLine=!1;return{chartJsConfig:o,background:s}},validateChartDefinition:Yv.validateChartDefinition,transformDefinition:Yv.transformDefinition,getChartDefinitionFromContextCreation:Yv.getDefinitionFromContextCreation,name:go("Scatter"),sequence:60}),Kv.add("waterfall",{match:e=>"waterfall"===e,createChart:(e,t,o)=>new Xv(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s)),e.showSubTotals&&o.push(go("Subtotal"));const i=xv(t,e.dataSets),n=t.getLocale(),r=function(e,t,o,s){const{locale:i,format:n}=s,r=Cl(e.background),a=yv(e,t,r,s),l=e.negativeValuesColor||w,c=e.positiveValuesColor||x,h=e.subTotalValuesColor||I,d={labels:{generateLabels:()=>{const t=[{text:go("Positive values"),fontColor:r,fillStyle:c},{text:go("Negative values"),fontColor:r,fillStyle:l}];return(e.showSubTotals||e.firstValueAsSubtotal)&&t.push({text:go("Subtotals"),fontColor:r,fillStyle:h}),t}}};return"none"===e.legendPosition?d.display=!1:d.position=e.legendPosition,a.options.plugins.legend={...a.options.plugins?.legend,...d},a.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},a.options.scales={x:{ticks:{padding:5,color:r},grid:{display:!1},title:wl(e.axesDesign?.x)},y:{position:e.verticalAxisPosition,ticks:{color:r,callback:e=>(e=Number(e),isNaN(e)?e:zs(e,{locale:i,format:!n&&Math.abs(e)>1e3?"#,##":n}))},grid:{lineWidth:e=>0===e.tick.value?2:1},title:wl(e.axesDesign?.y)}},a.options.plugins.tooltip={callbacks:{label:function(e){const[s,r]=e.raw,a=r-s,l=Math.floor(e.dataIndex/t.length),c=o[l],h=zs(a,{format:!n&&Math.abs(a)>1e3?"#,##":n,locale:i});return c?`${c}: ${h}`:h}}},a.options.plugins.waterfallLinesPlugin={showConnectorLines:e.showConnectorLines},a}(e,o,s.map((e=>e.label)),{format:i,locale:n});r.type="bar";const a=e.negativeValuesColor||w,l=e.positiveValuesColor||x,c=e.subTotalValuesColor||I,h=[],u=[],g={label:"",data:u,backgroundColor:h},p=[];let m=0;for(const t of s){for(let i=0;i<t.data.length;i++){const n=t.data[i];if(p.push(o[i]),isNaN(Number(n))){u.push([m,m]),h.push("");continue}u.push([m,n+m]);let r=n>=0?l:a;0===i&&t===s[0]&&e.firstValueAsSubtotal&&(r=c),h.push(r),m+=n}e.showSubTotals&&(p.push(go("Subtotal")),u.push([0,m]),h.push(c))}return r.data.datasets.push(g),r.data.labels=p.map(Cv),{chartJsConfig:r,background:e.background||d}},validateChartDefinition:Xv.validateChartDefinition,transformDefinition:Xv.transformDefinition,getChartDefinitionFromContextCreation:Xv.getDefinitionFromContextCreation,name:go("Waterfall"),sequence:70});const Qv=new $n;Qv.add("line",cl),Qv.add("bar",cl),Qv.add("combo",cl),Qv.add("pie",cl),Qv.add("gauge",mv),Qv.add("scatter",cl),Qv.add("scorecard",Bl),Qv.add("waterfall",cl);const Jv=new $n;Lf`
90
+ `;class lb extends t.Component{static template="o-spreadsheet-Composer";static props={focus:{validate:e=>["inactive","cellFocus","contentFocus"].includes(e)},inputStyle:{type:String,optional:!0},rect:{type:Object,optional:!0},delimitation:{type:Object,optional:!0},onComposerCellFocused:{type:Function,optional:!0},onComposerContentFocused:Function,isDefaultFocus:{type:Boolean,optional:!0},onInputContextMenu:{type:Function,optional:!0}};static components={TextValueProvider:Qf,FunctionDescriptionProvider:ob};static defaultProps={inputStyle:"",isDefaultFocus:!1};composerStore;DOMFocusableElementStore;composerRef=t.useRef("o_composer");contentHelper=new eb(this.composerRef.el);composerState=t.useState({positionStart:0,positionEnd:0});autoCompleteState;functionDescriptionState=t.useState({showDescription:!1,functionName:"",functionDescription:{},argToFocus:0});compositionActive=!1;get assistantStyle(){const e={};e["min-width"]=`${this.props.rect?.width||300}px`;const t=this.autoCompleteState.provider?.proposals,o=t?.some((e=>e.description));if((this.functionDescriptionState.showDescription||o)&&(e.width="300px"),this.props.delimitation&&this.props.rect){const{x:t,y:o,height:s}=this.props.rect,i=this.props.delimitation.height-(o+s);if(e["max-height"]=`${i}px`,o>i){const t=o;e["max-height"]=`${t}px`,e.top="-3px",e.transform="translate(0, -100%)"}t+300>this.props.delimitation.width&&(e.right="0px")}else this.props.delimitation&&(e["max-height"]=`${this.props.delimitation.height}px`);return Uf(e)}shouldProcessInputEvents=!1;tokens=[];keyMapping={Enter:e=>this.processEnterKey(e,"down"),"Shift+Enter":e=>this.processEnterKey(e,"up"),"Alt+Enter":this.processNewLineEvent,"Ctrl+Enter":this.processNewLineEvent,Escape:this.processEscapeKey,F2:()=>console.warn("Not implemented"),F4:e=>this.processF4Key(e),Tab:e=>this.processTabKey(e,"right"),"Shift+Tab":e=>this.processTabKey(e,"left")};keyCodeMapping={NumpadDecimal:this.processNumpadDecimal};setup(){this.composerStore=Wa(il),this.DOMFocusableElementStore=Wa(Ff),this.autoCompleteState=qa(Jf),t.onMounted((()=>{const e=this.composerRef.el;this.props.isDefaultFocus&&this.DOMFocusableElementStore.setFocusableElement(e),this.contentHelper.updateEl(e)})),t.useEffect((()=>{this.processContent()})),t.useEffect((()=>{this.processTokenAtCursor()}),(()=>["inactive"!==this.composerStore.editionMode]))}processArrowKeys(e){const t=this.composerStore.tokenAtCursor;if((this.composerStore.isSelectingRange||"inactive"===this.composerStore.editionMode)&&(!["ArrowUp","ArrowDown"].includes(e.key)||!this.autoCompleteState.provider||"REFERENCE"===t?.type))return this.functionDescriptionState.showDescription=!1,this.autoCompleteState.hide(),e.preventDefault(),e.stopPropagation(),void Kf(e,this.env.model.selection);const o=this.composerStore.currentContent;"cellFocus"!==this.props.focus||this.autoCompleteState.provider||o.startsWith("=")?(e.stopPropagation(),this.handleArrowKeysForAutocomplete(e)):this.composerStore.stopEdition()}handleArrowKeysForAutocomplete(e){["ArrowUp","ArrowDown"].includes(e.key)&&this.autoCompleteState.provider&&(e.preventDefault(),this.autoCompleteState.moveSelection("ArrowDown"===e.key?"next":"previous"))}processTabKey(e,t){if(e.preventDefault(),e.stopPropagation(),"inactive"!==this.composerStore.editionMode){const e=this.autoCompleteState;if(e.provider&&void 0!==e.selectedIndex){const t=e.provider.proposals[e.selectedIndex]?.text;if(t)return void this.autoComplete(t)}this.composerStore.stopEdition()}this.env.model.selection.moveAnchorCell(t,1)}processEnterKey(e,t){e.preventDefault(),e.stopPropagation();const o=this.autoCompleteState;if(o.provider&&void 0!==o.selectedIndex){const e=o.provider.proposals[o.selectedIndex]?.text;if(e)return void this.autoComplete(e)}this.composerStore.stopEdition(),this.env.model.selection.moveAnchorCell(t,1)}processNewLineEvent(e){e.preventDefault(),e.stopPropagation();const t=this.contentHelper.getText(),o=this.contentHelper.getCurrentSelection(),s=Math.min(o.start,o.end),i=Math.max(o.start,o.end);this.composerStore.stopComposerRangeSelection(),this.composerStore.setCurrentContent(t.slice(0,s)+le+t.slice(i),{start:s+1,end:s+1}),this.processContent()}processEscapeKey(){this.composerStore.cancelEdition()}processF4Key(e){e.stopPropagation(),this.composerStore.cycleReferences(),this.processContent()}processNumpadDecimal(e){e.stopPropagation(),e.preventDefault();const t=this.env.model.getters.getLocale(),o=this.contentHelper.getCurrentSelection(),s=this.composerStore.currentContent,i=s.slice(0,o.start)+t.decimalSeparator+s.slice(o.end);this.composerStore.setCurrentContent(i,{start:o.start+1,end:o.start+1}),this.processContent()}onCompositionStart(){this.compositionActive=!0}onCompositionEnd(){this.compositionActive=!1}onKeydown(e){if("inactive"===this.composerStore.editionMode)return;if(e.key.startsWith("Arrow"))return void this.processArrowKeys(e);let t=this.keyMapping[Zf(e)]||this.keyCodeMapping[Zf(e,"code")];t?t.call(this,e):e.stopPropagation()}onPaste(e){"inactive"!==this.composerStore.editionMode?e.stopPropagation():e.preventDefault()}onInput(e){if(!this.shouldProcessInputEvents)return;let t;if(e.stopPropagation(),t="inactive"===this.composerStore.editionMode?e.data||"":this.contentHelper.getText(),"inactive"===this.props.focus)return this.props.onComposerCellFocused?.(t);let o=this.contentHelper.getCurrentSelection();this.composerStore.stopComposerRangeSelection(),this.composerStore.setCurrentContent(t,o),this.processTokenAtCursor()}onKeyup(e){if(this.contentHelper.el===document.activeElement){if(this.autoCompleteState.provider&&["ArrowUp","ArrowDown"].includes(e.key))return;if(this.composerStore.isSelectingRange&&e.key?.startsWith("Arrow"))return;const{start:t,end:o}=this.composerStore.composerSelection,{start:s,end:i}=this.contentHelper.getCurrentSelection();s===t&&i===o||this.composerStore.changeComposerCursorSelection(s,i),this.processTokenAtCursor()}}updateAutoCompleteIndex(e){this.autoCompleteState.selectIndex(fe(0,e,10))}onMousedown(e){e.button>0||this.contentHelper.removeSelection()}onClick(){if(this.env.model.getters.isReadonly())return;const e=this.contentHelper.getCurrentSelection();this.composerStore.stopComposerRangeSelection(),this.props.onComposerContentFocused(),this.composerStore.changeComposerCursorSelection(e.start,e.end),this.processTokenAtCursor()}onDblClick(){if(this.env.model.getters.isReadonly())return;const e=this.composerStore.currentContent;if(e.startsWith("=")){const t=this.composerStore.currentTokens,o=this.contentHelper.getCurrentSelection();if(o.start===o.end)return;const s=e.substring(o.start,o.end),i=t.filter((e=>e.value.includes(s)&&e.start<=o.start&&e.end>=o.end))[0];if(!i)return;"REFERENCE"===i.type&&this.composerStore.changeComposerCursorSelection(i.start,i.end)}}onContextMenu(e){"inactive"===this.composerStore.editionMode&&this.props.onInputContextMenu?.(e)}processContent(){if(this.compositionActive)return;this.shouldProcessInputEvents=!1,"inactive"!==this.props.focus&&this.contentHelper.el.focus();const e=this.getContentLines();if(this.contentHelper.setText(e),0!==e.length&&0!==e.length[0]){if("inactive"!==this.props.focus){const{start:e,end:t}=this.composerStore.composerSelection;this.contentHelper.selectRange(e,t)}this.contentHelper.scrollSelectionIntoView()}this.shouldProcessInputEvents=!0}getContentLines(){let e=this.composerStore.currentContent;const t=e.startsWith("=");return""===e?[]:t&&"inactive"!==this.props.focus?this.splitHtmlContentIntoLines(this.getColoredTokens()):this.splitHtmlContentIntoLines([{value:e}])}getColoredTokens(){const e=this.composerStore.currentTokens,t=this.composerStore.tokenAtCursor,o=[],{end:s,start:i}=this.composerStore.composerSelection;for(const n of e){switch(n.type){case"OPERATOR":case"NUMBER":case"ARG_SEPARATOR":case"STRING":o.push({value:n.value,color:ab[n.type]||"#000"});break;case"REFERENCE":const{xc:e,sheetName:s}=Ai(n.value);o.push({value:n.value,color:this.rangeColor(e,s)||"#000"});break;case"SYMBOL":const i=n.value.toUpperCase();"TRUE"===i||"FALSE"===i?o.push({value:n.value,color:ab.NUMBER}):i in Mf.content?o.push({value:n.value,color:ab.FUNCTION}):o.push({value:n.value,color:"#000"});break;case"LEFT_PAREN":case"RIGHT_PAREN":t&&["LEFT_PAREN","RIGHT_PAREN"].includes(t.type)&&t.parenIndex&&t.parenIndex===n.parenIndex?o.push({value:n.value,color:ab.MATCHING_PAREN||"#000"}):o.push({value:n.value,color:ab[n.type]||"#000"});break;default:o.push({value:n.value,color:"#000"})}this.composerStore.showSelectionIndicator&&s===i&&s===n.end&&(o[o.length-1].class=ib)}return o}splitHtmlContentIntoLines(e){const t=[];let o=[];for(const s of e)if(s.value.includes(le)){const e=s.value.split(le),i=e.pop();for(const i of e)o.push({color:s.color,value:i}),t.push(o),o=[];o.push({...s,value:i})}else o.push(s);o.length&&t.push(o);const s=[];for(const e of t)e.every(this.isContentEmpty)?s.push([e[0]]):s.push(e.filter((e=>!this.isContentEmpty(e))));return s}isContentEmpty(e){return!(e.value||e.class)}rangeColor(e,t){if("inactive"===this.props.focus)return;const o=this.composerStore.highlights,s=t?this.env.model.getters.getSheetIdByName(t):this.composerStore.currentEditedCell.sheetId,i=o.find((t=>{if(t.sheetId!==s)return!1;let o=this.env.model.getters.getRangeFromSheetXC(s,e).zone;return o=1===an(o)?this.env.model.getters.expandZone(s,o):o,Zi(o,t.zone)}));return i&&i.color?i.color:void 0}processTokenAtCursor(){let e=this.composerStore.currentContent;this.autoCompleteState.provider&&this.autoCompleteState.hide(),this.functionDescriptionState.showDescription=!1;const t=this.composerStore.autocompleteProvider;if(t)return void this.autoCompleteState.useProvider(t);const o=this.composerStore.tokenAtCursor;if(e.startsWith("=")&&o&&"SYMBOL"!==o.type){const e=o.functionContext,t=e?.parent.toUpperCase();if(e&&t&&t in sb&&"UNKNOWN"!==o.type){const o=sb[t],s=e.argPosition;this.functionDescriptionState.functionName=t,this.functionDescriptionState.functionDescription=o,this.functionDescriptionState.argToFocus=o.getArgToFocus(s+1)-1,this.functionDescriptionState.showDescription=!0}}}autoComplete(e){e&&(this.autoCompleteState.provider?.selectProposal(e),this.processTokenAtCursor())}}class cb{scope;code="";constructor(e=new db){this.scope=e}append(...e){this.code+=e.map((e=>e.toString())).join("\n")+"\n"}return(e){return new hb(this.scope,this.code,e)}toString(){return ub(this.code)}}class hb{scope;returnExpression;code;constructor(e,t,o){this.scope=e,this.returnExpression=o,this.code=ub(t)}toString(){return this.code}assignResultToVariable(){if(this.scope.isAlreadyDeclared(this.returnExpression))return this;const e=this.scope.nextVariableName(),t=new cb(this.scope);return t.append(this.code),t.append(`const ${e} = ${this.returnExpression};`),t.return(e)}}class db{nextId=1;declaredVariables=new Set;nextVariableName(){const e="_"+this.nextId++;return this.declaredVariables.add(e),e}isAlreadyDeclared(e){return this.declaredVariables.has(e)}}function ub(e){let t="",o=0;const s=e.split("\n").map((e=>e.trim())).filter((e=>""!==e));for(const e of s)e.startsWith("}")&&o--,t+="\t".repeat(o)+e+"\n",e.endsWith("{")&&o++;return t.trim()}const gb=Mf.content,pb={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},mb={"-":"UMINUS","+":"UPLUS","%":"UNARY.PERCENT"},fb={};function bb(e){return vb(Jr(e))}function vb(e){const{dependencies:t,constantValues:o}=function(e){const t={numbers:[],strings:[]},o=[];for(const s of e)switch(s.type){case"INVALID_REFERENCE":case"REFERENCE":o.push(s.value);break;case"STRING":const e=he(s.value);t.strings.includes(e)||t.strings.push(e);break;case"NUMBER":{const e=no(s.value,Oo);t.numbers.includes(e)||t.numbers.push(e);break}}return{dependencies:o,constantValues:t}}(e),s=function(e,t,o){return Pe(e.map((e=>{switch(e.type){case"STRING":const s=he(e.value);return`|S${o.strings.indexOf(s)}|`;case"NUMBER":return`|N${o.numbers.indexOf(no(e.value,Oo))}|`;case"REFERENCE":case"INVALID_REFERENCE":return e.value.includes(":")?`R|${t.indexOf(e.value)}|`:`C|${t.indexOf(e.value)}|`;case"SPACE":return"";default:return e.value}})))}(e,t,o);if(!fb[s]){const i=Br([...e]),n=new db;if("BIN_OPERATION"===i.type&&":"===i.value)throw new Vo(go("Invalid formula"));if("EMPTY"===i.type)throw new Vo(go("Invalid formula"));const r=h(i),a=new cb;a.append(`// ${s}`),a.append(r),a.append(`return ${r.returnExpression};`);let l=new Function("deps","ref","range","ctx",a.toString());function c(e){const{args:t}=e,o=e.value.toUpperCase(),s=gb[o];if(!s)throw new Ho(go('Unknown function: "%s"',e.value));!function(e){const t=e.args.length,o=e.value.toUpperCase(),s=gb[o];if(t<s.minArgRequired)throw new Vo(go("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",o,s.minArgRequired.toString(),t.toString()));if(t>s.maxArgPossible)throw new Vo(go("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",o,s.maxArgPossible.toString(),t.toString()));const i=s.nbrArgRepeating;if(i>1){const e=s.args.length-i;if((t-e)%i!=0)throw new Vo(go("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",o,e.toString(),i.toString()))}}(e);const i=[];for(let e=0;e<t.length;e++){const o=s.getArgToFocus(e+1)-1,n=s.args[o],r=t[e],a=n.type||[],l=a.includes("META"),c=a.some((e=>e.startsWith("RANGE")));i.push(h(r,l,c))}return i}function h(e,s=!1,i=!1){const r=new cb(n);if("REFERENCE"!==e.type&&("BIN_OPERATION"!==e.type||":"!==e.value)&&s)throw new Vo(go("Argument must be a reference to a cell or range."));switch(e.debug&&r.append("debugger;"),e.type){case"BOOLEAN":return r.return(`{ value: ${e.value} }`);case"NUMBER":return r.return(`{ value: this.constantValues.numbers[${o.numbers.indexOf(e.value)}] }`);case"STRING":return r.return(`{ value: this.constantValues.strings[${o.strings.indexOf(e.value)}] }`);case"REFERENCE":const n=t.indexOf(e.value);return!s&&e.value.includes(":")||i?r.return(`range(deps[${n}])`):r.return(`ref(deps[${n}], ${s?"true":"false"})`);case"FUNCALL":const a=c(e).map((e=>e.assignResultToVariable()));r.append(...a);const l=e.value.toUpperCase();return r.return(`ctx['${l}'](${a.map((e=>e.returnExpression))})`);case"UNARY_OPERATION":{const t=mb[e.value],o=h(e.operand,!1,!1).assignResultToVariable();return r.append(o),r.return(`ctx['${t}'](${o.returnExpression})`)}case"BIN_OPERATION":{const t=pb[e.value],o=h(e.left,!1,!1).assignResultToVariable(),s=h(e.right,!1,!1).assignResultToVariable();return r.append(o),r.append(s),r.return(`ctx['${t}'](${o.returnExpression}, ${s.returnExpression})`)}case"EMPTY":return r.return("undefined")}}fb[s]=l}return{execute:fb[s],dependencies:t,constantValues:o,tokens:e}}const Sb=Mf.content;function Cb(e){try{return 0===zr(Br(e)).filter((e=>"FUNCALL"===e.type&&!Sb[e.value.toUpperCase()]?.isExported)).length}catch(e){return!1}}function yb(e,t){if(!e.some((e=>"SYMBOL"===e.type&&t.includes(e.value.toUpperCase()))))return[];let o;try{o=Br(e)}catch{return[]}return function(e,t){return zr(e).filter((e=>"FUNCALL"===e.type&&t.includes(e.value.toUpperCase()))).map((e=>({functionName:e.value.toUpperCase(),args:e.args})))}(o,t)}const Eb=["PIVOT.VALUE","PIVOT.HEADER","PIVOT"],xb={count:go("Count"),count_distinct:go("Count Distinct"),bool_and:go("Boolean And"),bool_or:go("Boolean Or"),max:go("Maximum"),min:go("Minimum"),avg:go("Average"),sum:go("Sum")},wb=["max","min","avg","sum","count_distinct","count"],Ib={integer:wb,char:wb},Rb={};for(const e in Ib){Rb[e]={};for(const t of Ib[e])Rb[e][t]=xb[t]}const Tb={count:{fn:e=>$h([e]),format:()=>"0"},count_distinct:{fn:e=>Oc([e]),format:()=>"0"},bool_and:{fn:e=>em([e]).result,format:()=>{}},bool_or:{fn:e=>tm([e]).result,format:()=>{}},max:{fn:(e,t)=>Gh([e],t),format:Wo},min:{fn:(e,t)=>Wh([e],t),format:Wo},avg:{fn:(e,t)=>Hh([e],t),format:Wo},sum:{fn:(e,t)=>Ac([e],t),format:Wo}};function Ab(e,t){return`=${e}(${t.map((e=>{const t="string"==typeof e&&!isNaN(Number(e))&&Number(e).toString()===e;return"number"==typeof e||t?`${e}`:`"${e.toString().replace(/"/g,'\\"')}"`})).join(",")})`}function Ob(e){const t=Object.keys(e);if(!t.length)return 0;const o=t.map((e=>parseInt(e,10)));return Math.max(...o)}function _b(e){return yb(e,Eb)[0]}function Db(e){return yb(e,Eb).length}const Mb={year:go("Year"),quarter:go("Quarter"),month:go("Month"),week:go("Week"),day:go("Day"),quarter_number:go("Quarter"),month_number:go("Month"),iso_week_number:go("Week"),day_of_month:go("Day of Month")},Fb=["date","datetime"];function Nb(e){const[t,o]=e.split(":");return o?{name:t,granularity:o}:{name:t}}function Pb(e){return Fb.includes(e.type)}function Lb(e,t){const o=`"${t?`${e.name}:${t}`:e.name}"`;return{text:o,description:e.string+(e.help?` (${e.help})`:""),htmlContent:[{value:o,color:ab.STRING}],fuzzySearchKey:e.string+o}}function kb(e,t){let o=e.end;const s=e.end;"ARG_SEPARATOR"!==e.type&&(o=e.start),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function Vb(e,t){let o=e.end;const s=e.end;"LEFT_PAREN"!==e.type&&(o=e.start),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function Ub(e){const t=e.functionContext?.args[0];if(t&&["STRING","NUMBER"].includes(t.type))return t.value}function Bb(e){if(e.length%2!=0)throw new Error("Invalid domain: odd number of elements");const t=[];for(let o=0;o<e.length-1;o+=2)t.push({field:e[o],value:e[o+1]});return t}Sa.add("pivot_ids",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!["PIVOT.VALUE","PIVOT.HEADER","PIVOT"].includes(t.parent.toUpperCase())||0!==t.argPosition)return;const o=this.getters.getPivotIds();return o.includes(e.value)?void 0:o.map((e=>{const o=this.getters.getPivotCoreDefinition(e);if("PIVOT"!==t.parent.toUpperCase()&&!gm.get(o.type))return;const s=`${this.getters.getPivotFormulaId(e)}`;return{text:s,description:o.name,htmlContent:[{value:s,color:ab.NUMBER}],fuzzySearchKey:s+o.name}})).filter(_e)},selectProposal:Vb}),Sa.add("pivot_measures",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if("PIVOT.VALUE"!==t?.parent.toUpperCase()||1!==t.argPosition)return[];const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return[];const i=this.getters.getPivot(s).getFields();if(!i)return[];const n=this.getters.getPivotCoreDefinition(s);return gm.get(n.type)?n.measures.map((e=>{if("__count"===e.name){const e='"__count"';return{text:e,description:go("Count"),htmlContent:[{value:e,color:ab.STRING}],fuzzySearchKey:go("Count")+e}}const t=i[e.name];if(t)return Lb(t)})).filter(_e):[]},selectProposal:kb}),Sa.add("pivot_group_fields",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==0}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==1}(e))return;const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s),n=i.getFields();if(!n)return;const{type:r}=this.getters.getPivotCoreDefinition(s),{columns:a,rows:l}=i.definition;if(!gm.get(r))return[];let c=t.args;"PIVOT.VALUE"===t?.parent.toUpperCase()?(c=c.filter(((e,t)=>t%2==0)),c=c.slice(1,t.argPosition)):c=c.filter(((e,t)=>t%2==1));const h=c.map((e=>e?.value)).filter(_e),d=a.map((e=>e.nameWithGranularity)),u=l.map((e=>e.nameWithGranularity)),g=[],p=["ARG_SEPARATOR","SPACE"].includes(e.type)?h.at(-1):h.at(-2);if(void 0===p&&(g.push(d[0]),g.push(u[0])),u.includes(p)){const e=u[u.indexOf(p)+1];g.push(e),g.push(d[0])}if(d.includes(p)){const e=d[d.indexOf(p)+1];g.push(e)}const m=g.filter(_e);return m.map((e=>{const[t,o]=e.split(":"),s=n[t];return s?Lb(s,o):void 0})).concat(m.map((e=>{const t=e.split(":")[0],o=n[t];if(!o)return;const s=`"#${e}"`;return{text:s,description:go("%s (positional)",o.string)+(o.help?` (${o.help})`:""),htmlContent:[{value:s,color:ab.STRING}],fuzzySearchKey:o.string+s}}))).filter(_e)},selectProposal:kb}),Sa.add("pivot_group_values",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!e||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==1}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==0}(e))return;const o=Ub(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const{type:i}=this.getters.getPivotCoreDefinition(s);if(!gm.get(i))return[];const n=this.getters.getPivot(s);if(!n.isValid())return;const r=t.argPosition,a=e.functionContext?.args[r-1]?.value;return a?n.getPossibleFieldValues(a.toString().split(":")[0]).map((({value:e,label:t})=>{const o="string"==typeof e,s=o?`"${e}"`:e.toString();return{text:s,description:t,htmlContent:[{value:s,color:o?ab.STRING:ab.NUMBER}],fuzzySearchKey:e+t}})):void 0},selectProposal:kb}),Sa.add("sheet_names",{sequence:150,autoSelectFirstProposal:!0,getProposals(e){return"SYMBOL"===e.type||"UNKNOWN"===e.type&&e.value.startsWith("'")?this.getters.getSheetIds().map((e=>{const t=me(this.getters.getSheetName(e));return{text:t,fuzzySearchKey:t.startsWith("'")?t:"'"+t}})):[]},selectProposal(e,t){const o=e.start,s=e.end;this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t+"!")}});const Hb=new $n;Hb.add("ALPHANUMERIC_INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=`${e.prefix}${e.current.toString().padStart(e.numberPostfixLength||0,"0")}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:o},tooltip:{props:{content:o}}}}}).add("INCREMENT_MODIFIER",{apply:(e,t,o)=>{e.current+=e.increment;const s=e.current.toString(),i=o.getLocale(),n=zs(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:n}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,o)=>{const s=t.cell?.content||"",i={locale:o.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:ca(t.cell?.content,i).formattedValue}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let i=0,n=0;switch(s){case"up":i=0,n=-e.current;break;case"down":i=0,n=e.current;break;case"left":i=-e.current,n=0;break;case"right":i=e.current,n=0}const r=t.cell;if(!r||!r.isFormula)return{cellData:{}};const a=t.sheetId,l=o.getTranslatedCellFormula(a,i,n,r.compiledFormula);return{cellData:{border:t.border,style:r.style,format:r.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const zb=new $n,$b=/(\d+)$/,Gb=/^(.*\D+)/,Wb=/^(.*\D+)(\d+)$/;function qb(e,t,o){let s=[],i=!1;for(let n of t){n===e&&(i=!0);const t=n?.isFormula?void 0:ca(n?.content,{locale:Oo});if(t&&o(t))s.push(t);else{if(i)return s;s=[]}}return s}function Zb(e){let t=1;return e.length>=2&&(t=function(e){const t=[];let o=e[0];for(let s=1;s<e.length;s++){const i=e[s];t.push(i-o),o=i}return t.reduce(((e,t)=>e+t),0)/t.length}(e)*e.length),t}zb.add("simple_value_copy",{condition:(e,t)=>!(1!==t.length||e.isFormula||e.format&&Ys(e.format)),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("increment_alphanumeric_value",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.text&&Wb.test(e.content),generateRule:(e,t)=>{const o=parseInt(e.content.match($b)[0]),s=e.content.match(Gb)[0],i=e.content.length-s.length,n=Zb(qb(e,t,(e=>e.type===mo.text&&Wb.test(e.value))).filter((e=>s===(e.value??"").toString().match(Gb)[0])).map((e=>parseInt((e.value??"").toString().match($b)[0]))));return{type:"ALPHANUMERIC_INCREMENT_MODIFIER",prefix:s,current:o,increment:n,numberPostfixLength:i}},sequence:15}).add("copy_text",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.text,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>e.isFormula,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_number",{condition:e=>!e.isFormula&&ca(e.content,{locale:Oo}).type===mo.number,generateRule:(e,t)=>{const o=Zb(qb(e,t,(e=>e.type===mo.number)).map((e=>Number(e.value)))),s=ca(e.content,{locale:Oo});return{type:"INCREMENT_MODIFIER",increment:o,current:s.type===mo.number?s.value:0}},sequence:40});const jb=new $n,Yb=30,Xb=10,Kb=20,Qb=12,Jb=80,ev="#F3F2F1",tv="#666666",ov="#C8C8C8",sv="#666666aa",iv=6,nv=25,rv=T,av=R,lv=R;function cv(e,t){const o=e.getBoundingClientRect();e.width=o.width,e.height=o.height;const s=e.getContext("2d"),i=function(e,t,o){const s=t.maxValue,i=t.minValue,n=t.gaugeValue,r=function(e,t){const o=t?nv:0,s=e.height-Kb-o-Xb,i=e.width-2*Yb;let n,r;i>2*s?(n=2*s,r=s):(n=i,r=i/2);const a=o+Xb+(s-r)/2;return{x:Yb+(i-n)/2,y:a,width:n,height:r}}(e,t.title.text),a=r.width/6,l=n?(n.value-i.value)/(s.value-i.value):0,c={x:e.width/2,y:r.y+r.height-r.height/12};let h=Jb;r.height<300&&(h*=r.height/300);const d=r.width/2,u=n?.label||"-";wn(o,u,{fontSize:h},"px")>d&&(h=Fn(d,h,(e=>wn(o,u,{fontSize:e},"px"))));const g={x:r.x+a/2,y:r.y+r.height+Qb},p={x:r.x+r.width-a/2,y:r.y+r.height+Qb},m=(b=t.background,lt(b)>.3?tv:ov),f=function(e,t,o,s){const i=e.maxValue,n=e.minValue,r={x:t.x+t.width/2,y:t.y+t.height},a={fontSize:Qb},l=[],c=[];for(const h of e.inflectionValues){const e=(h.value-n.value)/(i.value-n.value),d=wn(s,h.label,a,"px"),u=Math.PI-Math.PI*e,g=pv(u,t.height+iv,r.x,r.y,d+2,Qb);let p=c.some((e=>gv(e,g)))?Qb:0;c.push(g),l.push({rotation:u,label:h.label,fontSize:Qb,color:o,offset:p})}return l}(t,r,m,o);var b;let v=0,S=0,C=0;t.title.text&&({width:S,height:C}=Tn(o,t.title.text,{...t.title,fontSize:rv},"px"));switch(t.title.align){case"right":v=e.width-S-av;break;case"center":v=(e.width-S)/2;break;default:v=av}return{width:e.width,height:e.height,title:{label:t.title.text??"",fontSize:rv,textPosition:{x:v,y:lv+C/2},color:t.title.color??m,bold:t.title.bold,italic:t.title.italic},backgroundColor:t.background,gauge:{rect:r,arcWidth:a,percentage:fe(l,0,1),color:hv(t)},inflectionValues:f,gaugeValue:{label:u,textPosition:c,fontSize:h,color:m},minLabel:{label:t.minValue.label,textPosition:g,fontSize:Qb,color:m},maxLabel:{label:t.maxValue.label,textPosition:p,fontSize:Qb,color:m}}}(o,t,s);!function(e,t){e.save(),e.fillStyle=t.backgroundColor,e.fillRect(0,0,t.width,t.height),e.restore()}(s,i),function(e,t){e.save();const o=t.gauge,s=o.rect.x+o.rect.width/2,i=o.rect.y+o.rect.height,n=o.rect.height-o.arcWidth/2;if(n<0)return;const r=1===o.percentage?0:Math.PI*(1+o.percentage);e.strokeStyle=ev,e.beginPath(),e.lineWidth=o.arcWidth,e.arc(s,i,n,r,0),e.stroke(),e.strokeStyle=o.color,e.beginPath(),e.arc(s,i,n,Math.PI,r),e.stroke(),e.restore()}(s,i),function(e,t){const{x:o,y:s,width:i,height:n}=t.gauge.rect;for(const r of t.inflectionValues){e.save(),e.translate(o+i/2-.5,s+n-.5),e.rotate(Math.PI/2-r.rotation),e.lineWidth=2,e.strokeStyle=sv,e.beginPath(),e.moveTo(0,-(n-t.gauge.arcWidth)),e.lineTo(0,-n-3),e.stroke(),e.textAlign="center",e.font=`${r.fontSize}px ${W}`,e.fillStyle=r.color;const a=-n-iv-r.offset;e.fillText(r.label,0,a),e.restore()}}(s,i),function(e,t){for(const o of[t.minLabel,t.maxLabel,t.gaugeValue])e.save(),e.textAlign="center",e.fillStyle=o.color,e.font=`${o.fontSize}px ${W}`,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(s,i),function(e,t){e.save();const o=t.title;e.font=En(o.fontSize,o.bold,o.italic),e.textBaseline="middle",e.fillStyle=o.color,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(s,i)}function hv(e){const t=e.gaugeValue?.value;if(void 0===t)return ev;let o=0;for(;e.inflectionValues[o]?.value<=t;)o++;return e.colors[o]}function dv(e){return[{start:e.topLeft,end:e.topRight},{start:e.topRight,end:e.bottomRight},{start:e.bottomRight,end:e.bottomLeft},{start:e.bottomLeft,end:e.topLeft}]}function uv(e,t){const o=e.start,s=e.end,i=t.start,n=t.end;function r(e,t,o){return(o.y-e.y)*(t.x-e.x)>(t.y-e.y)*(o.x-e.x)}return r(o,i,n)!==r(s,i,n)&&r(o,s,i)!==r(o,s,n)}function gv(e,t){const o=dv(e),s=dv(t);for(const e of o)for(const t of s)if(uv(e,t))return!0;return!1}function pv(e,t,o,s,i,n){const r=Math.cos(e),a=Math.sin(e),l=r*t,c=a*t,h=a*(i/2),d=r*(i/2),u=r*(t+n),g=a*(t+n);return{bottomLeft:{x:l-h+o,y:s-(c+d)},bottomRight:{x:l+h+o,y:s-(c-d)},topRight:{x:u+h+o,y:s-(g-d)},topLeft:{x:u-h+o,y:s-(g+d)}}}class mv extends t.Component{static template="o-spreadsheet-GaugeChartComponent";canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}setup(){t.useEffect((()=>cv(this.canvas.el,this.runtime)),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el]}))}}function fv(e){return 8===(e=it(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}function bv(e,t){if(t.dataRange){const o=t.labelCell?[t.labelCell.zone]:[],s=_i([t.dataRange.zone],o)[0];if(void 0===s)return[];const i=e.getRangeFromZone(t.dataRange.sheetId,s);return e.getRangeValues(i).map((e=>""===e?void 0:e))}return[]}function vv(e,t){const o=be(0,Math.max(e.length,...t.map((e=>e.data?.length||0)))).filter((o=>{const s=e[o],i=t.map((e=>e.data?.[o]));return s||i.some((e=>0===e||Boolean(e)))}));return{labels:o.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:o.map((t=>e.data[t]))})))}}function Sv(e,t){const o=new Set(e),s={};o.forEach((e=>{s[e]=new Array(t.length).fill(0)}));for(const o of be(0,e.length)){const n=e[o];for(const e of be(0,t.length))s[n][e]+="number"==typeof(i=t[e].data[o])?i:0}var i;return{labels:Array.from(o),dataSetsValues:t.map(((e,t)=>({...e,data:Array.from(o).map((e=>s[e][t]))})))}}function Cv(e){return e?e.length>X?e.substring(0,X)+"…":e:""}function yv(e,t,o,{format:s,locale:i,truncateLabels:n}){const r=e.title.text?e.title:{...e.title,content:""},a={responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:R,right:R,top:r.text?R/2:R+5,bottom:R}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:!1,plugins:{title:{display:!!r.text,text:go(r.text),color:r?.color??o,align:"center"===r.align?"center":"right"===r.align?"end":"start",font:{size:T,weight:r.bold?"bold":"normal",style:r.italic?"italic":"normal"}},legend:{onClick:()=>{}},tooltip:{callbacks:{label:function(e){const t=e.dataset?.label||e.label,o=e.parsed.y??e.parsed,n=zs(o,{format:!s&&Math.abs(o)>=1e3?"#,##":s,locale:i});return t?`${t}: ${n}`:n}}}}};return{type:e.type,options:a,data:{labels:n?t.map(Cv):t,datasets:[]},platform:void 0,plugins:[]}}function Ev(e,t,o){let s={values:[],formattedValues:[]};if(o)o.invalidXc||o.invalidSheetName||(s={formattedValues:e.getRangeFormattedValues(o),values:e.getRangeValues(o).map((e=>String(e??"")))});else if(1===t.length)for(let o=0;o<bv(e,t[0]).length;o++)s.formattedValues.push(""),s.values.push("");else if(t[0]){s={formattedValues:be(0,bv(e,t[0]).length).map((e=>e.toString())),values:s.formattedValues}}return s}function xv(e,t){for(const o of t){const t=e.getRangeFormats(o.dataRange).find((e=>void 0!==e&&!Ys(e)));if(t)return t}}function wv(e,t){const o=[];for(const[s,i]of Object.entries(t)){let t;if(i.labelCell){const o=i.labelCell,n=o?e.getEvaluatedCell({sheetId:o.sheetId,col:o.zone.left,row:o.zone.top}):void 0;t=n&&o?Cv(n.formattedValue):t=`${Ra.Series} ${parseInt(s)+1}`}else t=`${Ra.Series} ${parseInt(s)+1}`;let n=i.dataRange?bv(e,i):[];n.every((e=>"string"==typeof e&&!qo(e)))&&n.fill(1),o.push({data:n,label:t})}return o}function Iv(e){return 0===e?"origin":e-1}function Rv(e,t,o){const s=document.createElement("div");s.style.width=`${t.width}px`,s.style.height=`${t.height}px`;const i=document.createElement("canvas");if(s.append(i),i.setAttribute("width",t.width.toString()),i.setAttribute("height",t.height.toString()),document.body.append(s),"chartJsConfig"in e){const t=ue(e.chartJsConfig);t.plugins=[Tv];const o=new window.Chart(i,t),n=o.toBase64Image();return o.destroy(),s.remove(),n}if("scorecard"===o){Fl(Ll(t,e),i);const o=i.toDataURL();return s.remove(),o}if("gauge"===o){cv(i,e);const t=i.toDataURL();return s.remove(),t}}mv.props={figure:Object};const Tv={id:"customCanvasBackgroundColor",beforeDraw:e=>{const{ctx:t}=e;t.save(),t.globalCompositeOperation="destination-over",t.fillStyle="#ffffff",t.fillRect(0,0,e.width,e.height),t.restore()}};class Av extends hl{dataSets;labelRange;background;legendPosition;stacked;aggregated;type="bar";dataSetsHaveTitle;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.stacked=e.stacked,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,stacked:e.stacked??!1,aggregated:e.aggregated??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"bar",labelRange:e.auxiliaryRange||void 0,axesDesign:e.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Av(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Av(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"bar",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,stacked:this.stacked,aggregated:this.aggregated,axesDesign:this.axesDesign}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Av(i,this.sheetId,this.getters)}}class Ov extends hl{dataSets;labelRange;background;legendPosition;aggregated;dataSetsHaveTitle;dataSetDesign;axesDesign;type="combo";constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"combo",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated,axesDesign:this.axesDesign}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Ov(i,this.sheetId,this.getters)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,aggregated:e.aggregated,legendPosition:e.legendPosition??"top",title:e.title||{text:""},labelRange:e.auxiliaryRange||void 0,type:"combo",axesDesign:e.axesDesign}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Ov(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Ov(t,e,this.getters)}}function _v(e){return e.dataRange&&!Ei.test(e.dataRange)?"InvalidGaugeDataRange":"Success"}function Dv(e,t){return t((t=>t.sectionRule?e(t.sectionRule.rangeMin,"rangeMin"):"Success"),(t=>t.sectionRule?e(t.sectionRule.rangeMax,"rangeMax"):"Success"))}function Mv(e){return e.sectionRule&&Number(e.sectionRule.rangeMin)>=Number(e.sectionRule.rangeMax)?"GaugeRangeMinBiggerThanRangeMax":"Success"}function Fv(e,t){if(""===e)switch(t){case"rangeMin":return"EmptyGaugeRangeMin";case"rangeMax":return"EmptyGaugeRangeMax"}return"Success"}function Nv(e,t){if(isNaN(e))switch(t){case"rangeMin":return"GaugeRangeMinNaN";case"rangeMax":return"GaugeRangeMaxNaN";case"lowerInflectionPointValue":return"GaugeLowerInflectionPointNaN";case"upperInflectionPointValue":return"GaugeUpperInflectionPointNaN"}return"Success"}class Pv extends hl{dataRange;sectionRule;background;type="gauge";constructor(e,t,o){super(e,t,o),this.dataRange=mn(this.getters,this.sheetId,e.dataRange),this.sectionRule=e.sectionRule,this.background=e.background}static validateChartDefinition(e,t){return e.checkValidations(t,_v,e.chainValidations(Dv(Fv,e.batchValidations),Dv(Nv,e.batchValidations),Mv),e.chainValidations((o=Nv,(0,e.batchValidations)((e=>e.sectionRule?o(e.sectionRule.lowerInflectionPoint.value,"lowerInflectionPointValue"):"Success"),(e=>e.sectionRule?o(e.sectionRule.upperInflectionPoint.value,"upperInflectionPointValue"):"Success")))));var o}static transformDefinition(e,t){let o;return e.dataRange&&(o=Ar(Li(e.dataRange),t)),{...e,dataRange:o?Bi(o):void 0}}static getDefinitionFromContextCreation(e){return{background:e.background,title:e.title||{text:""},type:"gauge",dataRange:e.range?e.range[0].dataRange:void 0,sectionRule:{colors:{lowerColor:"#cc0000",middleColor:"#f1c232",upperColor:"#6aa84f"},rangeMin:"0",rangeMax:"100",lowerInflectionPoint:{type:"percentage",value:"15"},upperInflectionPoint:{type:"percentage",value:"40"}}}}copyForSheetId(e){const t=gl(this.sheetId,e,this.dataRange),o=this.getDefinitionWithSpecificRanges(t,e);return new Pv(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.dataRange,e);return new Pv(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.dataRange)}getDefinitionWithSpecificRanges(e,t){return{background:this.background,sectionRule:this.sectionRule,title:this.title,type:"gauge",dataRange:e?this.getters.getRangeString(e,t||this.sheetId):void 0}}getDefinitionForExcel(){}getContextCreation(){return{...this,range:this.dataRange?[{dataRange:this.getters.getRangeString(this.dataRange,this.sheetId)}]:void 0}}updateRanges(e){const t=pl(this.dataRange,e);if(this.dataRange===t)return this;const o=this.getDefinitionWithSpecificRanges(t);return new Pv(o,this.sheetId,this.getters)}}function Lv(e,t,o){if(""===e.value||isNaN(Number(e.value)))return;const s=Number(e.value);return fe("number"===e.type?s:t+(o-t)*s/100,t,o)}const kv={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,year:31536e6},Vv={inSeconds:function(e){return Math.floor(e/kv.second)},inMinutes:function(e){return Math.floor(e/kv.minute)},inHours:function(e){return Math.floor(e/kv.hour)},inDays:function(e){return Math.floor(e/kv.day)},inMonths:function(e){return Math.floor(e/kv.month)},inYears:function(e){return Math.floor(e/kv.year)}},Uv=/^((d|dd|m|mm|yyyy|yy|hh|h|ss|a)(-|:|\s|\/))*(d|dd|m|mm|yyyy|yy|hh|h|ss|a)$/i;function Bv(e,t,o){const s=function(e){const t=e.indexOf("h");e=t>=0?e.slice(0,t).replace(/m/g,"M")+e.slice(t):e.replace(/m/g,"M");e.includes("a")||(e=e.replace(/h/g,"H"));return e}(t),i=function(e,t,o){const s=e.map((e=>zt(e,o)?.jsDate));if(s.some((e=>void 0===e))||e.length<2)return;const i=s.map((e=>e.getTime())),n=Qe(i)-Je(i),r=function(e){if(e.includes("s"))return"second";if(e.includes("m"))return"minute";if(e.includes("h")||e.includes("H"))return"hour";if(e.includes("d"))return"day";if(e.includes("M"))return"month";return"year"}(t);if(kv.second>=kv[r]&&Vv.inSeconds(n)<180)return"second";if(kv.minute>=kv[r]&&Vv.inMinutes(n)<180)return"minute";if(kv.hour>=kv[r]&&Vv.inHours(n)<96)return"hour";if(kv.day>=kv[r]&&Vv.inDays(n)<90)return"day";if(kv.month>=kv[r]&&Vv.inMonths(n)<36)return"month";return"year"}(e,s,o),n={};return i&&(n[i]=s),{parser:s,displayFormats:n,unit:i??!1}}function Hv(e,t){return $v(e,t)||Gv(e,t)}function zv(e,t){return function(e,t){return!e.labelsAsText&&$v(e.labelRange,t)}(e,t)&&function(){if(!window.Chart)return!1;const e="luxon"===new window.Chart._adapters._date({})._id;e||Wv||(Wv=!0,console.warn("'chartjs-adapter-luxon' time adapter is not installed. Time scale axes are disabled."));return e}()?"time":function(e,t){return!e.labelsAsText&&Gv(e.labelRange,t)}(e,t)?"linear":"category"}function $v(e,t){if(!e||!Gv(e,t))return!1;const o=t.getEvaluatedCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}).format;return Boolean(o&&Uv.test(o))}function Gv(e,t){if(!e)return!1;const o=t.getRangeValues(e);return!o.some((e=>isNaN(Number(e))&&e))&&!o.every((e=>!e))}let Wv=!1;function qv(e,t){const o=zv(e,t),s=Ev(t,e.dataSets,e.labelRange);let i="linear"===o?s.values:s.formattedValues,n=wv(t,e.dataSets);e.dataSetsHaveTitle&&n[0]&&i.length>n[0].data.length&&i.shift(),({labels:i,dataSetsValues:n}=vv(i,n)),"time"===o&&({labels:i,dataSetsValues:n}=function(e,t){if(0===e.length||e.every((e=>!e)))return{labels:e,dataSetsValues:t};const o=[...e],s=ue(t);for(let e=0;e<o.length;e++)if(!o[e]){o[e]=ke(o,e);for(let t of s)t.data[e]=void 0}return{labels:o,dataSetsValues:s}}(i,n)),e.aggregated&&({labels:i,dataSetsValues:n}=Sv(i,n));const r=t.getLocale(),a="category"===o,l=xv(t,e.dataSets),c=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s,generateLabels(e){const{data:t}=e,o=window.Chart.defaults.plugins.legend.labels.generateLabels(e);for(const[e,s]of o.entries())s.fillStyle=t.datasets[e].borderColor;return o}}};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,Object.assign(i.options.plugins.legend||{},n),i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.scales={x:{ticks:{padding:5,color:s},title:wl(e.axesDesign?.x)}};const r={beginAtZero:!0,ticks:{color:s,callback:e=>{if(e=Number(e),isNaN(e))return e;const{locale:t,format:s}=o;return zs(e,{locale:t,format:!s&&Math.abs(e)>=1e3?"#,##":s})}}},{useLeftAxis:a,useRightAxis:l}=Il(e.getDefinition());return a&&(i.options.scales.y={...r,position:"left",title:wl(e.axesDesign?.y)}),l&&(i.options.scales.y1={...r,position:"right",title:wl(e.axesDesign?.y1)}),"stacked"in e&&e.stacked&&(a&&(i.options.scales.y.stacked=!0),l&&(i.options.scales.y1.stacked=!0)),i}(e,i,{format:l,locale:r,truncateLabels:a}),h=function(e,t){if(t)return e.getEvaluatedCell({sheetId:t.sheetId,col:t.zone.left,row:t.zone.top}).format}(t,e.labelRange);if("time"===o){const e={type:"time",time:Bv(i,h,r)};Object.assign(c.options.scales.x,e),c.options.scales.x.ticks.maxTicksLimit=15}else"linear"===o&&(c.options.scales.x.type="linear",c.options.scales.x.ticks.callback=e=>zs(e,{format:h,locale:r}),c.options.plugins.tooltip.callbacks.title=e=>zs(e[0].parsed.x||e[0].label,{locale:r,format:h}));const u="stacked"in e&&e.stacked,g="cumulative"in e&&e.cumulative,p=new St,m=e.getDefinition();for(let[e,{label:t,data:s}]of n.entries()){["linear","time"].includes(o)&&(s=s.map(((e,t)=>({x:i[t]||void 0,y:e}))));const n=p.next();let r=ht(n);if(u&&(r.a=te),g){let e=0;s=s.map((t=>isNaN(t)?t:(e+=parseFloat(t),e)))}const a={label:t,data:s,tension:0,borderColor:n,backgroundColor:ct(r),pointBackgroundColor:n,fill:!!u&&Iv(e)};c.data.datasets.push(a)}for(const[e,t]of c.data.datasets.entries()){if(m.dataSets?.[e]?.backgroundColor){const o=m.dataSets[e].backgroundColor;t.backgroundColor=o,t.borderColor=o,t.pointBackgroundColor=o}if(m.dataSets?.[e]?.label){const o=m.dataSets[e].label;t.label=o}m.dataSets?.[e]?.yAxisId&&(t.yAxisID=m.dataSets[e].yAxisId)}return{chartJsConfig:c,background:e.background||d,dataSetsValues:n,labelValues:s,dataSetFormat:l,labelFormat:h}}class Zv extends hl{dataSets;labelRange;background;legendPosition;labelsAsText;stacked;aggregated;type="line";dataSetsHaveTitle;cumulative;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(this.getters,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.stacked=e.stacked,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.cumulative=e.cumulative,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static transformDefinition(e,t){return Sl(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,labelsAsText:e.labelsAsText??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"line",labelRange:e.auxiliaryRange||void 0,stacked:e.stacked??!1,aggregated:e.aggregated??!1,cumulative:e.cumulative??!1,axesDesign:e.axesDesign}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"line",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,stacked:this.stacked,aggregated:this.aggregated,cumulative:this.cumulative,axesDesign:this.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Zv(i,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Zv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Zv(t,e,this.getters)}}class jv extends hl{dataSets;labelRange;background;legendPosition;type="pie";aggregated;dataSetsHaveTitle;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"pie",labelRange:e.auxiliaryRange||void 0,aggregated:e.aggregated??!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getContextCreation(){return{...this,range:this.dataSets.map((e=>({dataRange:this.getters.getRangeString(e.dataRange,this.sheetId)}))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinitionWithSpecificDataSets(e,t,o){return{type:"pie",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>({dataRange:this.getters.getRangeString(e.dataRange,o||this.sheetId)}))),legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new jv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new jv(t,e,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range&&e.range!==Po.InvalidReference)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle));return{...this.getDefinition(),backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new jv(i,this.sheetId,this.getters)}}class Yv extends hl{dataSets;labelRange;background;legendPosition;labelsAsText;aggregated;type="scatter";dataSetsHaveTitle;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(this.getters,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static transformDefinition(e,t){return Sl(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range??[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,labelsAsText:e.labelsAsText??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"scatter",labelRange:e.auxiliaryRange||void 0,aggregated:e.aggregated??!1,axesDesign:e.axesDesign}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"scatter",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,aggregated:this.aggregated,axesDesign:this.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Yv(i,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>bl(this.getters,e))).filter((e=>""!==e.range)),t=vl(this.getters,this.labelRange,xl(this.labelRange,this.dataSets[0],this.dataSetsHaveTitle)),o=this.getDefinition();return{...o,backgroundColor:fv(this.background||d),fontColor:fv(Cl(this.background)),dataSets:e,labelRange:t,verticalAxis:Il(o)}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Yv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Yv(t,e,this.getters)}}class Xv extends hl{dataSets;labelRange;background;verticalAxisPosition;legendPosition;aggregated;type="waterfall";dataSetsHaveTitle;showSubTotals;firstValueAsSubtotal;showConnectorLines;positiveValuesColor;negativeValuesColor;subTotalValuesColor;dataSetDesign;axesDesign;constructor(e,t,o){super(e,t,o),this.dataSets=ml(o,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=mn(o,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated,this.dataSetsHaveTitle=e.dataSetsHaveTitle,this.showSubTotals=e.showSubTotals,this.showConnectorLines=e.showConnectorLines,this.positiveValuesColor=e.positiveValuesColor,this.negativeValuesColor=e.negativeValuesColor,this.subTotalValuesColor=e.subTotalValuesColor,this.firstValueAsSubtotal=e.firstValueAsSubtotal,this.dataSetDesign=e.dataSets,this.axesDesign=e.axesDesign}static transformDefinition(e,t){return Sl(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,yl,El)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:e.dataSetsHaveTitle??!1,aggregated:e.aggregated??!1,legendPosition:e.legendPosition??"top",title:e.title||{text:""},type:"waterfall",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0,showSubTotals:e.showSubTotals??!1,showConnectorLines:e.showConnectorLines??!0,firstValueAsSubtotal:e.firstValueAsSubtotal??!1,axesDesign:e.axesDesign}}getContextCreation(){const e=[];for(const[t,o]of this.dataSets.entries())e.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(o.dataRange,this.sheetId)});return{...this,range:e,auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ul(this.sheetId,e,this.dataSets),o=gl(this.sheetId,e,this.labelRange),s=this.getDefinitionWithSpecificDataSets(t,o,e);return new Xv(s,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Xv(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,o){const s=[];for(const[t,i]of e.entries())s.push({...this.dataSetDesign?.[t],dataRange:this.getters.getRangeString(i.dataRange,o||this.sheetId)});return{type:"waterfall",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:s,legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,o||this.sheetId):void 0,title:this.title,aggregated:this.aggregated,showSubTotals:this.showSubTotals,showConnectorLines:this.showConnectorLines,positiveValuesColor:this.positiveValuesColor,negativeValuesColor:this.negativeValuesColor,subTotalValuesColor:this.subTotalValuesColor,firstValueAsSubtotal:this.firstValueAsSubtotal,axesDesign:this.axesDesign}}getDefinitionForExcel(){}updateRanges(e){const{dataSets:t,labelRange:o,isStale:s}=dl(this.getters,e,this.dataSets,this.labelRange);if(!s)return this;const i=this.getDefinitionWithSpecificDataSets(t,o);return new Xv(i,this.sheetId,this.getters)}}const Kv=new $n;Kv.add("bar",{match:e=>"bar"===e,createChart:(e,t,o)=>new Av(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s));const i=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s}};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,i.options.plugins.legend={...i.options.plugins?.legend,...n},i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.scales={x:{ticks:{padding:5,color:s},title:wl(e.axesDesign?.x)}};const r={beginAtZero:!0,ticks:{color:s,callback:e=>{if(e=Number(e),isNaN(e))return e;const{locale:t,format:s}=o;return zs(e,{locale:t,format:!s&&Math.abs(e)>=1e3?"#,##":s})}}},{useLeftAxis:a,useRightAxis:l}=Il(e.getDefinition());return a&&(i.options.scales.y={...r,position:"left",title:wl(e.axesDesign?.y)}),l&&(i.options.scales.y1={...r,position:"right",title:wl(e.axesDesign?.y1)}),e.stacked&&(i.options.scales.x.stacked=!0,a&&(i.options.scales.y.stacked=!0),l&&(i.options.scales.y1.stacked=!0)),i}(e,o,{format:xv(t,e.dataSets),locale:t.getLocale()}),n=new St,r=e.getDefinition();for(const{label:e,data:t}of s){const o=n.next(),s={label:e,data:t,borderColor:o,backgroundColor:o};i.data.datasets.push(s)}for(const[e,t]of i.data.datasets.entries()){if(r.dataSets?.[e]?.backgroundColor){const o=r.dataSets[e].backgroundColor;t.backgroundColor=o,t.borderColor=o}if(r.dataSets?.[e]?.label){const o=r.dataSets[e].label;t.label=o}r.dataSets?.[e]?.yAxisId&&(t.yAxisID=r.dataSets[e].yAxisId)}return{chartJsConfig:i,background:e.background||d}},validateChartDefinition:Av.validateChartDefinition,transformDefinition:Av.transformDefinition,getChartDefinitionFromContextCreation:Av.getDefinitionFromContextCreation,name:go("Bar"),sequence:10}),Kv.add("combo",{match:e=>"combo"===e,createChart:(e,t,o)=>new Ov(e,t,o),getChartRuntime:function(e,t){const o=e.dataSets.length?xv(t,[e.dataSets[0]]):void 0,s=xv(t,e.dataSets.slice(1)),i=t.getLocale();let n=Ev(t,e.dataSets,e.labelRange).formattedValues,r=wv(t,e.dataSets);e.dataSetsHaveTitle&&r[0]&&n.length>r[0].data.length&&n.shift(),({labels:n,dataSetsValues:r}=vv(n,r)),e.aggregated&&({labels:n,dataSetsValues:r}=Sv(n,r));const a={format:o,locale:i},l=Cl(e.background),c=yv(e,n,l,a),h={labels:{color:l},reverse:!0};!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?h.display=!1:h.position=e.legendPosition,c.options.plugins.legend={...c.options.plugins?.legend,...h},c.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},c.options.scales={x:{ticks:{padding:5,color:l},title:wl(e.axesDesign?.x)}};const u=e=>t=>{if(t=Number(t),isNaN(t))return t;const{locale:o}=a;return zs(t,{locale:o,format:!e&&Math.abs(t)>=1e3?"#,##":e})},g={beginAtZero:!0,ticks:{color:l,callback:u(o)}},p={beginAtZero:!0,ticks:{color:l,callback:u(s)}},m=e.getDefinition(),{useLeftAxis:f,useRightAxis:b}=Il(m);f&&(c.options.scales.y={...g,position:"left",title:wl(e.axesDesign?.y)}),b&&(c.options.scales.y1={...p,position:"right",grid:{display:!1},title:wl(e.axesDesign?.y1)});const v=new St;for(let[e,{label:t,data:o}]of r.entries()){const s=m.dataSets[e],i=v.next(),n={label:s?.label??t,data:o,borderColor:s?.backgroundColor??i,backgroundColor:s.backgroundColor??i,yAxisID:s?.yAxisId??"y",type:0===e?"bar":"line",order:-e};c.data.datasets.push(n)}return{chartJsConfig:c,background:e.background||d}},validateChartDefinition:Ov.validateChartDefinition,transformDefinition:Ov.transformDefinition,getChartDefinitionFromContextCreation:Ov.getDefinitionFromContextCreation,name:go("Combo"),sequence:15}),Kv.add("line",{match:e=>"line"===e,createChart:(e,t,o)=>new Zv(e,t,o),getChartRuntime:function(e,t){const{chartJsConfig:o,background:s}=qv(e,t);return{chartJsConfig:o,background:s}},validateChartDefinition:Zv.validateChartDefinition,transformDefinition:Zv.transformDefinition,getChartDefinitionFromContextCreation:Zv.getDefinitionFromContextCreation,name:go("Line"),sequence:20}),Kv.add("pie",{match:e=>"pie"===e,createChart:(e,t,o)=>new jv(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s)),({dataSetsValues:s,labels:o}=function(e,t){const o=e.reduce(((e,o,s)=>(t.some((e=>{const t=e.data[s];return"number"!=typeof t||t>=0}))&&e.push(s),e)),[]);return{labels:o.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:o.map((t=>{const o=e.data[t];return"number"!=typeof o||o>=0?o:0}))})))}}(o,s));const i=function(e,t,o){const s=Cl(e.background),i=yv(e,t,s,o),n={labels:{color:s}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?n.display=!1:n.position=e.legendPosition,Object.assign(i.options.plugins.legend||{},n),i.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},i.options.plugins.tooltip.callbacks.title=function(e){return e[0].dataset.label},i.options.plugins.tooltip.callbacks.label=function(e){const{format:t,locale:s}=o,i=function(e,t){const o=e.filter((e=>"number"==typeof e)).reduce(((e,t)=>e+t),0);if(!o)return"";return(e[t]/o*100).toFixed(2)}(e.dataset.data,e.dataIndex),n=e.label||e.dataset.label,r=e.parsed.y??e.parsed,a=zs(r,{format:!t&&r>=1e3?"#,##":t,locale:s});return n?`${n}: ${a} (${i}%)`:`${a} (${i}%)`},i}(e,o,{format:xv(t,e.dataSets),locale:t.getLocale()}),n=function(e,t){const o=[],s=Qe(t.map((e=>e.data.length)));for(let t=0;t<=s;t++)o.push(e.next());return o}(new St,s);for(const{label:e,data:t}of s){const o={label:e,data:t,borderColor:"#FFFFFF",backgroundColor:n};i.data.datasets.push(o)}return{chartJsConfig:i,background:e.background||d}},validateChartDefinition:jv.validateChartDefinition,transformDefinition:jv.transformDefinition,getChartDefinitionFromContextCreation:jv.getDefinitionFromContextCreation,name:go("Pie"),sequence:30}),Kv.add("scorecard",{match:e=>"scorecard"===e,createChart:(e,t,o)=>new Ml(e,t,o),getChartRuntime:function(e,t){let o,s="";const i=t.getLocale();if(e.keyValue){const n={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};o=t.getEvaluatedCell(n),s=function(e,t,o){return e?t?ri(e,o):e.formattedValue??String(e.value??""):""}(o,e.humanize??!1,i)}let n;const r=e.baseline;if(r){const e={sheetId:r.sheetId,col:r.zone.left,row:r.zone.top};n=t.getEvaluatedCell(e)}const{background:a,fontColor:l}=t.getStyleOfSingleCellChart(e.background,e.keyValue),c=function(e,t,o,s,i){if(!e)return"";if("text"===o||t?.type!==mo.number||e.type!==mo.number)return s?ri(e,i):e.formattedValue;let{value:n,format:r}=e;return"progress"===o?(n=t.value/n,r="0.0%"):(n=Math.abs(t.value-n),"percentage"===o&&0!==n&&(n/=e.value),"percentage"===o&&(r="0.0%"),r||(n=Math.round(100*n)/100)),s?ri({value:n,format:r},i):zs(n,{format:r,locale:i})}(n,o,e.baselineMode,e.humanize??!1,i),h="progress"===e.baselineMode&&so(c,i)?jo(c,i):0;return{title:{...e.title,text:go(e.title.text??"")},keyValue:s,baselineDisplay:c,baselineArrow:Tl(n,o,e.baselineMode),baselineColor:Rl(n,e.baselineMode,o,e.baselineColorUp,e.baselineColorDown),baselineDescr:"progress"!==e.baselineMode&&e.baselineDescr?go(e.baselineDescr):"",fontColor:l,background:a,baselineStyle:"percentage"!==e.baselineMode&&"progress"!==e.baselineMode&&r?t.getCellStyle({sheetId:r.sheetId,col:r.zone.left,row:r.zone.top}):void 0,keyValueStyle:e.keyValue?t.getCellStyle({sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top}):void 0,progressBar:"progress"===e.baselineMode?{value:h,color:h>0?e.baselineColorUp:e.baselineColorDown}:void 0}},validateChartDefinition:Ml.validateChartDefinition,transformDefinition:Ml.transformDefinition,getChartDefinitionFromContextCreation:Ml.getDefinitionFromContextCreation,name:go("Scorecard"),sequence:40}),Kv.add("gauge",{match:e=>"gauge"===e,createChart:(e,t,o)=>new Pv(e,t,o),getChartRuntime:function(e,t){const o=t.getLocale(),s=e.sectionRule.colors;let i,n,r;const a=e.dataRange;if(void 0!==a){const e=t.getEvaluatedCell({sheetId:a.sheetId,col:a.zone.left,row:a.zone.top});e.type===mo.number&&(i=e.value,n=e.formattedValue,r=e.format)}const l=Number(e.sectionRule.rangeMin),c=Number(e.sectionRule.rangeMax),h=e.sectionRule.lowerInflectionPoint,d=e.sectionRule.upperInflectionPoint,u=Lv(h,l,c),g=Lv(d,l,c),p=[],m=[];return void 0!==u&&(p.push({value:u,label:zs(u,{locale:o,format:r})}),m.push(s.lowerColor)),void 0!==g&&g!==u&&(p.push({value:g,label:zs(g,{locale:o,format:r})}),m.push(s.middleColor)),void 0!==g&&void 0!==u&&u>g&&(p.reverse(),m.reverse()),m.push(s.upperColor),{background:t.getStyleOfSingleCellChart(e.background,a).background,title:e.title??{text:""},minValue:{value:l,label:zs(l,{locale:o,format:r})},maxValue:{value:c,label:zs(c,{locale:o,format:r})},gaugeValue:void 0!==i&&n?{value:i,label:n}:void 0,inflectionValues:p,colors:m}},validateChartDefinition:Pv.validateChartDefinition,transformDefinition:Pv.transformDefinition,getChartDefinitionFromContextCreation:Pv.getDefinitionFromContextCreation,name:go("Gauge"),sequence:50}),Kv.add("scatter",{match:e=>"scatter"===e,createChart:(e,t,o)=>new Yv(e,t,o),getChartRuntime:function(e,t){const{chartJsConfig:o,background:s,dataSetsValues:i,dataSetFormat:n,labelValues:r,labelFormat:a}=qv(e,t);o.type="line";const l=o.options,c=t.getLocale();l.plugins.tooltip.callbacks.title=()=>"",l.plugins.tooltip.callbacks.label=e=>{const t=i[e.datasetIndex].data[e.dataIndex];let o=e.label||r.values[e.dataIndex];so(o,c)&&(o=jo(o,c));const s=zs(o,{locale:c,format:a}),l=zs(t,{locale:c,format:n}),h=e.dataset.label;return s?`${h}: (${s}, ${l})`:`${h}: ${l}`};for(const e of o.data.datasets)e.showLine=!1;return{chartJsConfig:o,background:s}},validateChartDefinition:Yv.validateChartDefinition,transformDefinition:Yv.transformDefinition,getChartDefinitionFromContextCreation:Yv.getDefinitionFromContextCreation,name:go("Scatter"),sequence:60}),Kv.add("waterfall",{match:e=>"waterfall"===e,createChart:(e,t,o)=>new Xv(e,t,o),getChartRuntime:function(e,t){let o=Ev(t,e.dataSets,e.labelRange).formattedValues,s=wv(t,e.dataSets);e.dataSetsHaveTitle&&s[0]&&o.length>s[0].data.length&&o.shift(),({labels:o,dataSetsValues:s}=vv(o,s)),e.aggregated&&({labels:o,dataSetsValues:s}=Sv(o,s)),e.showSubTotals&&o.push(go("Subtotal"));const i=xv(t,e.dataSets),n=t.getLocale(),r=function(e,t,o,s){const{locale:i,format:n}=s,r=Cl(e.background),a=yv(e,t,r,s),l=e.negativeValuesColor||w,c=e.positiveValuesColor||x,h=e.subTotalValuesColor||I,d={labels:{generateLabels:()=>{const t=[{text:go("Positive values"),fontColor:r,fillStyle:c},{text:go("Negative values"),fontColor:r,fillStyle:l}];return(e.showSubTotals||e.firstValueAsSubtotal)&&t.push({text:go("Subtotals"),fontColor:r,fillStyle:h}),t}}};return"none"===e.legendPosition?d.display=!1:d.position=e.legendPosition,a.options.plugins.legend={...a.options.plugins?.legend,...d},a.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},a.options.scales={x:{ticks:{padding:5,color:r},grid:{display:!1},title:wl(e.axesDesign?.x)},y:{position:e.verticalAxisPosition,ticks:{color:r,callback:e=>(e=Number(e),isNaN(e)?e:zs(e,{locale:i,format:!n&&Math.abs(e)>1e3?"#,##":n}))},grid:{lineWidth:e=>0===e.tick.value?2:1},title:wl(e.axesDesign?.y)}},a.options.plugins.tooltip={callbacks:{label:function(e){const[s,r]=e.raw,a=r-s,l=Math.floor(e.dataIndex/t.length),c=o[l],h=zs(a,{format:!n&&Math.abs(a)>1e3?"#,##":n,locale:i});return c?`${c}: ${h}`:h}}},a.options.plugins.waterfallLinesPlugin={showConnectorLines:e.showConnectorLines},a}(e,o,s.map((e=>e.label)),{format:i,locale:n});r.type="bar";const a=e.negativeValuesColor||w,l=e.positiveValuesColor||x,c=e.subTotalValuesColor||I,h=[],u=[],g={label:"",data:u,backgroundColor:h},p=[];let m=0;for(const t of s){for(let i=0;i<t.data.length;i++){const n=t.data[i];if(p.push(o[i]),isNaN(Number(n))){u.push([m,m]),h.push("");continue}u.push([m,n+m]);let r=n>=0?l:a;0===i&&t===s[0]&&e.firstValueAsSubtotal&&(r=c),h.push(r),m+=n}e.showSubTotals&&(p.push(go("Subtotal")),u.push([0,m]),h.push(c))}return r.data.datasets.push(g),r.data.labels=p.map(Cv),{chartJsConfig:r,background:e.background||d}},validateChartDefinition:Xv.validateChartDefinition,transformDefinition:Xv.transformDefinition,getChartDefinitionFromContextCreation:Xv.getDefinitionFromContextCreation,name:go("Waterfall"),sequence:70});const Qv=new $n;Qv.add("line",cl),Qv.add("bar",cl),Qv.add("combo",cl),Qv.add("pie",cl),Qv.add("gauge",mv),Qv.add("scatter",cl),Qv.add("scorecard",Bl),Qv.add("waterfall",cl);const Jv=new $n;Lf`
91
91
  .o-chart-container {
92
92
  width: 100%;
93
93
  height: 100%;
@@ -1163,7 +1163,7 @@
1163
1163
  background-color: white;
1164
1164
  }
1165
1165
  }
1166
- `;class $w extends t.Component{static template="o-spreadsheet-PivotDimension";static props={dimension:Object,onRemoved:{type:Function,optional:!0},slots:{type:Object,optional:!0}}}class Gw extends t.Component{static template="o-spreadsheet-PivotDimensionGranularity";static props={dimension:Object,onUpdated:Function,availableGranularities:Set,allGranularities:Array};periods=Mb}class Ww extends t.Component{static template="o-spreadsheet-PivotDimensionOrder";static props={dimension:Object,onUpdated:Function}}class qw extends t.Component{static template="o-spreadsheet-PivotLayoutConfigurator";static components={AddDimensionButton:zw,PivotDimension:$w,PivotDimensionOrder:Ww,PivotDimensionGranularity:Gw};static props={definition:Object,onDimensionsUpdated:Function,unusedGroupableFields:Array,unusedMeasureFields:Array,unusedDateTimeGranularities:Object,allGranularities:Array};dimensionsRef=t.useRef("pivot-dimensions");dragAndDrop=hw();AGGREGATORS=Rb;isDateField=Pb;startDragAndDrop(e,t){if(0!==t.button||"SELECT"===t.target.tagName)return;const o=this.getDimensionElementsRects(),s=this.props.definition,{columns:i,rows:n}=s,r=[...i.map((e=>e.nameWithGranularity)),"__rows_title__",...n.map((e=>e.nameWithGranularity))],a=r.map(((e,t)=>({id:e,size:o[t+1].height,position:o[t+1].y})));this.dragAndDrop.start("vertical",{draggedItemId:e.nameWithGranularity,initialMousePosition:t.clientY,items:a,containerEl:this.dimensionsRef.el,onDragEnd:(e,t)=>{const o=r.findIndex((t=>t===e));if(o===t)return;const s=[...r];s.splice(o,1),s.splice(t,0,e);const i=s.slice(0,s.indexOf("__rows_title__")),n=s.slice(s.indexOf("__rows_title__")+1);this.props.onDimensionsUpdated({columns:i.map(Nb),rows:n.map(Nb)})}})}startDragAndDropMeasures(e,t){if(0!==t.button||"SELECT"===t.target.tagName)return;const o=this.getDimensionElementsRects(),s=this.props.definition,{measures:i,columns:n,rows:r}=s,a=i.map((e=>e.name)),l=3+n.length+r.length,c=a.map(((e,t)=>({id:e,size:o[t+l].height,position:o[t+l].y})));this.dragAndDrop.start("vertical",{draggedItemId:e.name,initialMousePosition:t.clientY,items:c,containerEl:this.dimensionsRef.el,onDragEnd:(e,t)=>{const o=a.findIndex((t=>t===e));if(o===t)return;const s=[...a];s.splice(o,1),s.splice(t,0,e),this.props.onDimensionsUpdated({measures:s.map((e=>i.find((t=>t.name===e)))).filter(_e)})}})}getDimensionElementsRects(){return Array.from(this.dimensionsRef.el.children).map((e=>{const t=getComputedStyle(e),o=e.getBoundingClientRect();return{x:o.x,y:o.y,width:o.width+parseInt(t.marginLeft||"0")+parseInt(t.marginRight||"0"),height:o.height+parseInt(t.marginTop||"0")+parseInt(t.marginBottom||"0")}}))}removeDimension(e){const{columns:t,rows:o}=this.props.definition;this.props.onDimensionsUpdated({columns:t.filter((t=>t.nameWithGranularity!==e.nameWithGranularity)),rows:o.filter((t=>t.nameWithGranularity!==e.nameWithGranularity))})}removeMeasureDimension(e){const{measures:t}=this.props.definition;this.props.onDimensionsUpdated({measures:t.filter((t=>t.name!==e.name))})}addColumnDimension(e){const{columns:t}=this.props.definition;this.props.onDimensionsUpdated({columns:t.concat([{name:e,order:"asc"}])})}addRowDimension(e){const{rows:t}=this.props.definition;this.props.onDimensionsUpdated({rows:t.concat([{name:e,order:"asc"}])})}addMeasureDimension(e){const{measures:t}=this.props.definition;this.props.onDimensionsUpdated({measures:t.concat([{name:e}])})}updateAggregator(e,t){const{measures:o}=this.props.definition;this.props.onDimensionsUpdated({measures:o.map((o=>o===e?{...o,aggregator:t}:o))})}updateOrder(e,t){const{rows:o,columns:s}=this.props.definition;this.props.onDimensionsUpdated({rows:o.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,order:t||void 0}:o)),columns:s.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,order:t||void 0}:o))})}updateGranularity(e,t){const{rows:o,columns:s}=this.props.definition;this.props.onDimensionsUpdated({rows:o.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,granularity:t}:o)),columns:s.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,granularity:t}:o))})}}class Zw{measures;columns;rows;constructor(e,t){this.measures=e.measures.map((e=>function(e,t){const o=t.name,s="__count"===o?{name:"__count",string:go("Count"),type:"integer",aggregator:"sum"}:e[o],i=t.aggregator||s?.aggregator;return{nameWithAggregator:o+(i?`:${i}`:""),displayName:s?.string??o,name:o,aggregator:i,type:"__count"===o?"integer":s?.type??"integer",isValid:!!s}}(t,e))),this.columns=e.columns.map((e=>jw(t,e))),this.rows=e.rows.map((e=>jw(t,e)))}getDimension(e){const t=this.columns.find((t=>t.nameWithGranularity===e))||this.rows.find((t=>t.nameWithGranularity===e));if(!t)throw new ko(go("Dimension %s does not exist",e));return t}getMeasure(e){const t=this.measures.find((t=>t.name===e));if(!t)throw new ko(go("Field %s does not exist",e));return t}}function jw(e,t){const o=e[t.name],s=o?.type??"integer",i=o&&Pb(o)?t.granularity:void 0;return{displayName:o?.string??t.name,nameWithGranularity:t.name+(i?`:${i}`:""),name:t.name,granularity:i,type:s,order:t.order,isValid:!!o}}class Yw extends Zw{range;constructor(e,t,o){if(super(e,t),e.dataSet){const{sheetId:t,zone:s}=e.dataSet;this.range=o.getRangeFromZone(t,s)}}}class Xw{columns;rows;measures;rowTitle;maxIndent;pivotCells={};constructor(e,t,o,s=""){this.columns=e.map((e=>{let t=1;return e.map((e=>(e={...e,offset:t},t+=e.width,e)))})),this.rows=t,this.measures=o,this.rowTitle=s,this.maxIndent=Math.max(...this.rows.map((e=>e.indent)))}getNumberOfDataColumns(){return this.columns.at(-1)?.length||0}getPivotCells(e=!0,t=!0){const o=JSON.stringify({includeTotal:e,includeColumnHeaders:t});if(!this.pivotCells[o]){const s=this.rows.length,i=this.getNumberOfDataColumns();let n=this.columns.length+s,r=1+i;e||1===s||(n-=1),e||i===this.measures.length||(r-=this.measures.length);const a=[],l=t?0:this.columns.length;for(let t=0;t<r;t++){a.push([]);for(let o=l;o<n;o++)(e||o!==n)&&a[t].push(this.getPivotCell(t,o,e))}this.pivotCells[o]=a}return this.pivotCells[o]}isTotalRow(e){return this.rows[e].indent!==this.maxIndent}getPivotCell(e,t,o=!0){const s=this.columns.length;if(0===e&&t===s-1)return{content:this.rowTitle,isHeader:!0};if(t<=s-1){return{domain:this.getColHeaderDomain(e,t),isHeader:!0}}if(0===e){const e=t-s;return{domain:this.getRowDomain(e),isHeader:!0}}{const i=t-s;if(!o&&this.isTotalRow(i))return{isHeader:!1};return{domain:[...this.getRowDomain(i),...this.getColDomain(e)],isHeader:!1,measure:this.getColMeasure(e)}}}getColHeaderDomain(e,t){if(0===e)return;const o=[],s=this.columns[t].find((t=>t.offset===e));if(s){for(let e=0;e<s.fields.length;e++)o.push(s.fields[e]),o.push(s.values[e]);return o}}getColDomain(e){const t=this.getColHeaderDomain(e,this.columns.length-1);return t?t.slice(0,-2):[]}getColMeasure(e){const t=this.getColHeaderDomain(e,this.columns.length-1);return t?.at(-1)}getRowDomain(e){const t=[];for(let o=0;o<this.rows[e].fields.length;o++)t.push(this.rows[e].fields[o]),t.push(this.rows[e].values[o]);return t}export(){return{cols:this.columns,rows:this.rows,measures:this.measures,rowTitle:this.rowTitle}}}function Kw(e,t){const o=Jw(e,t.columns,0);eI(o,t.measures.length);const s=function(e,t){const o=t.columns.map((e=>e.nameWithGranularity)),s=o.length,i=t.measures.length,n=new Array(s).fill(0).map((()=>[]));function r(e,t,i){const a=n[t];for(const n of e){const e=i.concat([n.value]),l={fields:o.slice(0,t+1),values:e,width:n.width,offset:0};a.push(l),t<=s-1&&r(n.children,t+1,e)}}r(e,0,[]);const a=o.length>0,l=[];a&&n[n.length-1].forEach((e=>{t.measures.forEach((t=>{const o={fields:[...e.fields,"measure"],values:[...e.values,t.name],width:1,offset:0};l.push(o)}))}));t.measures.forEach((e=>{const t={fields:["measure"],values:[e.name],width:1,offset:0};l.push(t)})),n.push(l),1===n.length&&n.unshift([]);return n[n.length-2].push({fields:[],values:[],width:i,offset:0}),n}(o,t),i=Qw(e,0,t.rows,[],[]);i.push({fields:[],values:[],indent:0});const n=t.measures.map((e=>e.name)),r=i.length>0?i[0].values[0]:"";return new Xw(s,i,n,r)}function Qw(e,t,o,s,i){if(t>=o.length)return[];const n=o[t],r=n.nameWithGranularity,a=tI(e,n),l=oI(a,n),c=[],h=s.concat(r);for(const e of l){const s=i.concat(e);c.push({fields:h,values:s,indent:t});const n=a[e];n&&c.push(...Qw(n,t+1,o,h,s))}return c}function Jw(e,t,o){if(o>=t.length)return[];const s=t[o],i=t[o].nameWithGranularity,n=tI(e,s);return oI(n,t[o]).map((e=>({value:e,field:i,children:Jw(n[e]||[],t,o+1),width:0})))}function eI(e,t){for(const o in e){const s=e[o];0===s.children.length?s.width=t:(eI(s.children,t),s.width=s.children.reduce(((e,t)=>e+t.width),0))}}function tI(e,t){return Object.groupBy(e,function(e){const t=e.nameWithGranularity;return e=>`${e[t]?.value??null}`}(t))}function oI(e,t){return t.order?Object.keys(e).sort(((e,o)=>function(e,t,o){if("integer"===e.type||"date"===e.type)return"asc"===e.order?Number(t)-Number(o):Number(o)-Number(t);return"asc"===e.order?t.localeCompare(o):o.localeCompare(t)}(t,e,o))):Object.keys(e)}function sI(e,t,o){const s=e.granularity;if(!s||!(s in iI))throw new Error(`Unknown date granularity: ${s}`);if(null===t)return null;if(!iI[s].set.has(t)){iI[s].set.add(t);const e=rs(t,o);let i=0;switch(s){case"year_number":i=e.getFullYear();break;case"quarter_number":i=Math.floor(e.getMonth()/3)+1;break;case"month_number":i=e.getMonth();break;case"iso_week_number":i=e.getIsoWeek();break;case"day_of_month":i=e.getDate();break;case"day":i=Math.floor(jo(t,o))}iI[s].values[`${t}`]=i}return iI[s].values[`${t}`]}const iI={year_number:{set:new Set,values:{}},quarter_number:{set:new Set,values:{}},month_number:{set:new Set,values:{}},iso_week_number:{set:new Set,values:{}},day_of_month:{set:new Set,values:{}},day:{set:new Set,values:{}}};const nI=new $n;nI.add("SPREADSHEET",{ui:class{type="SPREADSHEET";getters;_definition;coreDefinition;dataEntries=[];fields={};fieldKeys=[];table;invalidRangeError;needsReevaluation=!0;constructor(e,t){this.getters=t.getters,this.coreDefinition=t.definition}init(e={}){if(!this._definition||e.reload){if(this.invalidRangeError=void 0,this.coreDefinition.dataSet){const{zone:e,sheetId:t}=this.coreDefinition.dataSet,o=this.getters.getRangeFromZone(t,e);try{({fields:this.fields,fieldKeys:this.fieldKeys}=this.extractFieldsFromRange(o))}catch(e){this.fields={},this.fieldKeys=[],this.invalidRangeError=e}}else this.invalidRangeError=new ko(go("The pivot cannot be created because the dataset is missing."));this._definition=new Yw(this.coreDefinition,this.fields,this.getters),this.table=void 0,this.dataEntries=[];const e=this._definition.range;this.isValid()&&e&&(this.dataEntries=this.extractDataEntriesFromRange(e)),this.needsReevaluation=!1}}get isInvalidRange(){return!!this.invalidRangeError}get invalidRangeMessage(){return this.invalidRangeError?.message}get definition(){if(!this._definition)throw new Error("Pivot not loaded yet");return this._definition}isValid(){if(this.invalidRangeError||!this._definition)return!1;for(const e of this.definition.measures)if(!e.isValid)return!1;for(const e of this.definition.columns)if(!e.isValid)return!1;for(const e of this.definition.rows)if(!e.isValid)return!1;return!0}assertIsValid({throwOnError:e}){if(!this.isValid()){if(e)throw this.invalidRangeError?this.invalidRangeError:new ko(go("At least one measure and/or dimension is not correct."));return{value:Po.GenericError,message:this.invalidRangeError?.message??go("At least one measure and/or dimension is not correct.")}}}markAsDirtyForEvaluation(){this.needsReevaluation=!0}getMeasure(e){return this.definition.getMeasure(e)}getPivotHeaderValueAndFormat(e){const t=Bb(e),o=t.at(-1);if(!o)return{value:go("Total")};if("measure"===o.field)return{value:this.getMeasure(o.value).displayName};const s=this.getDimension(o.field),i=this.filterDataEntriesFromDomain(this.dataEntries,t),n=i[0]?.[s.nameWithGranularity];if(!n)return{value:""};if(null===n.value||"null"===n.value)return{value:go("(Undefined)")};if("date"===s.type){if("day"===s.granularity)return{value:jo(n.value,this.getters.getLocale()),format:this.getters.getLocale().dateFormat};if("month_number"===s.granularity)return{value:Vs[jo(n.value,this.getters.getLocale())].toString()}}return{value:n.value,format:n.format}}getPivotCellValueAndFormat(e,t){const o=Bb(t),s=this.filterDataEntriesFromDomain(this.dataEntries,o);if(0===s.length)return{value:""};const i=s.map((t=>t[e])).filter((e=>e&&e.type!==mo.empty)).filter(_e),n=this.getMeasure(e).aggregator||"count",r=Tb[n];if(!r)throw new Error(`Aggregator ${n} does not exist`);try{return{value:i.length?r.fn([i],this.getters.getLocale()):"",format:r.format(i[0])}}catch(e){return Of(e,n.toUpperCase())}}getPossibleFieldValues(e){throw new Error("Method not implemented.")}getTableStructure(){if(!this.isValid())throw new Error("Pivot is not valid !");return this.table||(this.table=Kw(this.dataEntries,this.definition)),this.table}getFields(){return this.fields}filterDataEntriesFromDomain(e,t){return t.reduce(((e,t)=>this.filterDataEntriesFromDomainNode(e,t)),e)}filterDataEntriesFromDomainNode(e,t){const{field:o,value:s}=t,i=this.getDimension(o);return e.filter((e=>`${e[i.nameWithGranularity]?.value}`===s))}getDimension(e){return this.definition.getDimension(e)}getTypeFromZone(e,t){const o=this.getters.getEvaluatedCellsInZone(e,t).filter((e=>e.type!==mo.empty));return 0===o.length?"integer":o.every((e=>e.format&&Ys(e.format)))?"date":o.every((e=>e.type===mo.boolean))?"boolean":o.some((e=>e.type===mo.text))?"char":"integer"}assertCellIsValidField(e,t,o){if(o.type===mo.error)throw new ko(go("The pivot cannot be created because cell %s contains an error",Rt(e,t)));if(o.type===mo.empty)throw new ko(go("The pivot cannot be created because cell %s is empty",Rt(e,t)));if("__count"===o.value)throw new ko(go("The pivot cannot be created because cell %s contains a reserved value",Rt(e,t)))}extractFieldsFromRange(e){const t={},o=[],s=e.sheetId,i=e.zone.top;for(let n=e.zone.left;n<=e.zone.right;n++){const r=this.getters.getEvaluatedCell({sheetId:s,col:n,row:i});this.assertCellIsValidField(n,i,r);const a=r.value?.toString();if(a){const i=this.getTypeFromZone(s,{top:e.zone.top+1,left:n,bottom:e.zone.bottom,right:n}),r=this.findName(a,t);t[r]={name:r,type:i,string:r,aggregator:"integer"===i?"sum":"count"},o.push(r)}}return{fields:t,fieldKeys:o}}findName(e,t){let o=1;const s=e;for(;e in t;)e=`${s}${++o}`;return e}extractDataEntriesFromRange(e){const t=[];for(let o=e.zone.top+1;o<=e.zone.bottom;o++){const s={top:o,bottom:o,left:e.zone.left,right:e.zone.right},i=this.getters.getEvaluatedCellsInZone(e.sheetId,s),n={};for(const e in i){const t=i[e],o=this.fields[this.fieldKeys[e]];if(!o)throw new Error(`Field ${this.fieldKeys[e]} does not exist`);""===t.value?n[o.name]={value:null,type:mo.empty}:n[o.name]=t}n.__count={value:1,type:mo.number},t.push(n)}const o=this.definition.columns.concat(this.definition.rows).filter((e=>"date"===e.type));if(o.length)for(const e of t)for(const t of o)e[t.nameWithGranularity]={value:`${sI(t,e[t.name]?.value||null,this.getters.getLocale())}`,type:e[t.name]?.type||mo.empty,format:e[t.name]?.format};return t}},definition:Yw,externalData:!1,onIterationEndEvaluation:e=>e.markAsDirtyForEvaluation(),granularities:["year_number","quarter_number","month_number","iso_week_number","day_of_month","day"],isMeasureCandidate:e=>!["date","boolean"].includes(e.type),isGroupable:()=>!0});class rI extends Ja{pivotId;mutators=["reset","deferUpdates","applyUpdate","discardPendingUpdate","renamePivot","update"];updatesAreDeferred=!0;draft=null;constructor(e,t){super(e),this.pivotId=t}handle(e){if("UPDATE_PIVOT"===e.type)e.pivotId===this.pivotId&&this.getters.getPivot(this.pivotId).init()}get fields(){const e=this.pivot.getFields();if(!e)throw new Error("Fields not found");return e}get pivot(){return this.getters.getPivot(this.pivotId)}get definition(){const e=nI.get(this.pivot.type).definition;return this.draft?new e(this.draft,this.fields,this.getters):this.pivot.definition}get isDirty(){return!!this.draft}get unusedMeasureFields(){const e=[{name:"__count",string:go("Count"),type:"integer",aggregator:"sum"}],t=this.fields;for(const o in t){const s=t[o];s&&(nI.get(this.pivot.type).isMeasureCandidate(s)&&e.push(s))}const{rows:o,columns:s,measures:i}=this.definition,n=i.concat(o).concat(s).map((e=>e.name));return e.filter((e=>!n.includes(e.name))).sort(((e,t)=>e.string.localeCompare(t.string)))}get unusedGroupableFields(){const e=[],t=this.fields;for(const o in t){const s=t[o];s&&(nI.get(this.pivot.type).isGroupable(s)&&e.push(s))}const{columns:o,rows:s,measures:i}=this.definition,n=i.concat(s).concat(o).map((e=>e.name)),r=this.unusedDateTimeGranularities;return e.filter((e=>Pb(e)?!n.includes(e.name)||r[e.name].size>0:!n.includes(e.name))).sort(((e,t)=>e.string.localeCompare(t.string)))}get allGranularities(){return nI.get(this.pivot.type).granularities}get unusedDateTimeGranularities(){return this.getUnusedDateTimeGranularities(this.fields,this.draft??this.getters.getPivotCoreDefinition(this.pivotId))}reset(e){this.pivotId=e,this.updatesAreDeferred=!0,this.draft=null}deferUpdates(e){this.updatesAreDeferred=e,!1===e&&this.draft&&this.applyUpdate()}applyUpdate(){this.draft&&(this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:this.draft}),this.draft=null)}discardPendingUpdate(){this.draft=null}renamePivot(e){const t=this.getters.getPivotCoreDefinition(this.pivotId);this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:{...t,name:e}})}update(e){const t=this.getters.getPivotCoreDefinition(this.pivotId),o={...t,...this.draft,...e},s={...o,columns:o.columns.map((e=>({name:e.name,order:e.order,granularity:e.granularity}))),rows:o.rows.map((e=>({name:e.name,order:e.order,granularity:e.granularity}))),measures:o.measures.map((e=>({name:e.name,aggregator:e.aggregator})))};if(!this.draft&&Ue(t,s))return;const i=this.addDefaultDateTimeGranularity(this.fields,s);this.updatesAreDeferred?this.draft=i:this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:i})}addDefaultDateTimeGranularity(e,t){const{columns:o,rows:s}=t,i=ue(o),n=ue(s),r=this.getUnusedDateTimeGranularities(e,t);for(const t of i.concat(n)){const o=e[t.name]?.type;if(("date"===o||"datetime"===o)&&!t.granularity){const e=r[t.name]?.values().next().value||"year";r[t.name]?.delete(e),t.granularity=e}}return{...t,columns:i,rows:n}}getUnusedDateTimeGranularities(e,t){const{columns:o,rows:s}=t,i=o.concat(s).filter((t=>{const o=e[t.name]?.type;return"date"===o||"datetime"===o})),n=this.allGranularities,r={};for(const e of i)r[e.name]=new Set(n);for(const e of i)r[e.name].delete(e.granularity);return r}}class aI extends t.Component{static template="o-spreadsheet-PivotSpreadsheetSidePanel";static props={pivotId:String,onCloseSidePanel:Function};static components={PivotLayoutConfigurator:qw,Section:Ix,SelectionInput:Ax,EditableName:Hw,Checkbox:wx};store;state;setup(){this.store=qa(rI,this.props.pivotId),this.pivot.init(),this.state=t.useState({range:void 0,rangeHasChanged:!1})}get shouldDisplayInvalidRangeError(){return(!this.store.isDirty||!this.state.rangeHasChanged)&&this.pivot.isInvalidRange}get ranges(){return this.state.range?[this.state.range]:this.definition.range?[this.env.model.getters.getRangeString(this.definition.range,"forceSheetReference")]:[]}get pivot(){return this.store.pivot}get name(){return this.env.model.getters.getPivotName(this.props.pivotId)}get displayName(){return this.env.model.getters.getPivotDisplayName(this.props.pivotId)}get definition(){return this.store.definition}get deferUpdatesLabel(){return go("Defer updates")}get deferUpdatesTooltip(){return go("Changing the pivot definition requires to reload the data. It may take some time.")}onSelectionChanged(e){this.state.rangeHasChanged=!0,this.state.range=e[0]}onSelectionConfirmed(){if(this.state.range){const{sheetName:e,xc:t}=Ai(this.state.range),o=e?this.env.model.getters.getSheetIdByName(e):this.env.model.getters.getActiveSheetId();if(!o)return;const s={sheetId:o,zone:ki(t)};this.store.update({dataSet:s}),this.store.applyUpdate()}}duplicatePivot(){const e=this.env.model.uuidGenerator.uuidv4(),t=this.env.model.dispatch("DUPLICATE_PIVOT",{pivotId:this.props.pivotId,newPivotId:e}),o=t.isSuccessful?go("Pivot duplicated."):go("Pivot duplication failed"),s=t.isSuccessful?"success":"danger";this.env.notifyUser({text:o,sticky:!1,type:s}),t.isSuccessful&&this.env.openSidePanel("PivotSidePanel",{pivotId:e})}onNameChanged(e){this.store.renamePivot(e)}onDimensionsUpdated(e){this.store.update(e)}back(){this.env.openSidePanel("PivotSidePanel",{})}delete(){this.env.model.dispatch("REMOVE_PIVOT",{pivotId:this.props.pivotId})}}const lI=new $n;lI.add("SPREADSHEET",{editor:aI}),Lf`
1166
+ `;class $w extends t.Component{static template="o-spreadsheet-PivotDimension";static props={dimension:Object,onRemoved:{type:Function,optional:!0},slots:{type:Object,optional:!0}}}class Gw extends t.Component{static template="o-spreadsheet-PivotDimensionGranularity";static props={dimension:Object,onUpdated:Function,availableGranularities:Set,allGranularities:Array};periods=Mb}class Ww extends t.Component{static template="o-spreadsheet-PivotDimensionOrder";static props={dimension:Object,onUpdated:Function}}class qw extends t.Component{static template="o-spreadsheet-PivotLayoutConfigurator";static components={AddDimensionButton:zw,PivotDimension:$w,PivotDimensionOrder:Ww,PivotDimensionGranularity:Gw};static props={definition:Object,onDimensionsUpdated:Function,unusedGroupableFields:Array,unusedMeasureFields:Array,unusedDateTimeGranularities:Object,allGranularities:Array};dimensionsRef=t.useRef("pivot-dimensions");dragAndDrop=hw();AGGREGATORS=Rb;isDateField=Pb;startDragAndDrop(e,t){if(0!==t.button||"SELECT"===t.target.tagName)return;const o=this.getDimensionElementsRects(),s=this.props.definition,{columns:i,rows:n}=s,r=[...i.map((e=>e.nameWithGranularity)),"__rows_title__",...n.map((e=>e.nameWithGranularity))],a=r.map(((e,t)=>({id:e,size:o[t+1].height,position:o[t+1].y})));this.dragAndDrop.start("vertical",{draggedItemId:e.nameWithGranularity,initialMousePosition:t.clientY,items:a,containerEl:this.dimensionsRef.el,onDragEnd:(e,t)=>{const o=r.findIndex((t=>t===e));if(o===t)return;const s=[...r];s.splice(o,1),s.splice(t,0,e);const i=s.slice(0,s.indexOf("__rows_title__")),n=s.slice(s.indexOf("__rows_title__")+1);this.props.onDimensionsUpdated({columns:i.map(Nb),rows:n.map(Nb)})}})}startDragAndDropMeasures(e,t){if(0!==t.button||"SELECT"===t.target.tagName)return;const o=this.getDimensionElementsRects(),s=this.props.definition,{measures:i,columns:n,rows:r}=s,a=i.map((e=>e.name)),l=3+n.length+r.length,c=a.map(((e,t)=>({id:e,size:o[t+l].height,position:o[t+l].y})));this.dragAndDrop.start("vertical",{draggedItemId:e.name,initialMousePosition:t.clientY,items:c,containerEl:this.dimensionsRef.el,onDragEnd:(e,t)=>{const o=a.findIndex((t=>t===e));if(o===t)return;const s=[...a];s.splice(o,1),s.splice(t,0,e),this.props.onDimensionsUpdated({measures:s.map((e=>i.find((t=>t.name===e)))).filter(_e)})}})}getDimensionElementsRects(){return Array.from(this.dimensionsRef.el.children).map((e=>{const t=getComputedStyle(e),o=e.getBoundingClientRect();return{x:o.x,y:o.y,width:o.width+parseInt(t.marginLeft||"0")+parseInt(t.marginRight||"0"),height:o.height+parseInt(t.marginTop||"0")+parseInt(t.marginBottom||"0")}}))}removeDimension(e){const{columns:t,rows:o}=this.props.definition;this.props.onDimensionsUpdated({columns:t.filter((t=>t.nameWithGranularity!==e.nameWithGranularity)),rows:o.filter((t=>t.nameWithGranularity!==e.nameWithGranularity))})}removeMeasureDimension(e){const{measures:t}=this.props.definition;this.props.onDimensionsUpdated({measures:t.filter((t=>t.name!==e.name))})}addColumnDimension(e){const{columns:t}=this.props.definition;this.props.onDimensionsUpdated({columns:t.concat([{name:e,order:"asc"}])})}addRowDimension(e){const{rows:t}=this.props.definition;this.props.onDimensionsUpdated({rows:t.concat([{name:e,order:"asc"}])})}addMeasureDimension(e){const{measures:t}=this.props.definition;this.props.onDimensionsUpdated({measures:t.concat([{name:e}])})}updateAggregator(e,t){const{measures:o}=this.props.definition;this.props.onDimensionsUpdated({measures:o.map((o=>o===e?{...o,aggregator:t}:o))})}updateOrder(e,t){const{rows:o,columns:s}=this.props.definition;this.props.onDimensionsUpdated({rows:o.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,order:t||void 0}:o)),columns:s.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,order:t||void 0}:o))})}updateGranularity(e,t){const{rows:o,columns:s}=this.props.definition;this.props.onDimensionsUpdated({rows:o.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,granularity:t}:o)),columns:s.map((o=>o.nameWithGranularity===e.nameWithGranularity?{...o,granularity:t}:o))})}}class Zw{measures;columns;rows;constructor(e,t){this.measures=e.measures.map((e=>function(e,t){const o=t.name,s="__count"===o?{name:"__count",string:go("Count"),type:"integer",aggregator:"sum"}:e[o],i=t.aggregator||s?.aggregator;return{nameWithAggregator:o+(i?`:${i}`:""),displayName:s?.string??o,name:o,aggregator:i,type:"__count"===o?"integer":s?.type??"integer",isValid:!!s}}(t,e))),this.columns=e.columns.map((e=>jw(t,e))),this.rows=e.rows.map((e=>jw(t,e)))}getDimension(e){const t=this.columns.find((t=>t.nameWithGranularity===e))||this.rows.find((t=>t.nameWithGranularity===e));if(!t)throw new ko(go("Dimension %s does not exist",e));return t}getMeasure(e){const t=this.measures.find((t=>t.name===e));if(!t)throw new ko(go("Field %s does not exist",e));return t}}function jw(e,t){const o=e[t.name],s=o?.type??"integer",i=o&&Pb(o)?t.granularity:void 0;return{displayName:o?.string??t.name,nameWithGranularity:t.name+(i?`:${i}`:""),name:t.name,granularity:i,type:s,order:t.order,isValid:!!o}}class Yw extends Zw{range;constructor(e,t,o){if(super(e,t),e.dataSet){const{sheetId:t,zone:s}=e.dataSet;this.range=o.getRangeFromZone(t,s)}}}class Xw{columns;rows;measures;rowTitle;maxIndent;pivotCells={};constructor(e,t,o,s=""){this.columns=e.map((e=>{let t=1;return e.map((e=>(e={...e,offset:t},t+=e.width,e)))})),this.rows=t,this.measures=o,this.rowTitle=s,this.maxIndent=Math.max(...this.rows.map((e=>e.indent)))}getNumberOfDataColumns(){return this.columns.at(-1)?.length||0}getPivotCells(e=!0,t=!0){const o=JSON.stringify({includeTotal:e,includeColumnHeaders:t});if(!this.pivotCells[o]){const s=this.rows.length,i=this.getNumberOfDataColumns();let n=this.columns.length+s,r=1+i;e||1===s||(n-=1),e||i===this.measures.length||(r-=this.measures.length);const a=[],l=t?0:this.columns.length;for(let t=0;t<r;t++){a.push([]);for(let o=l;o<n;o++)(e||o!==n)&&a[t].push(this.getPivotCell(t,o,e))}this.pivotCells[o]=a}return this.pivotCells[o]}isTotalRow(e){return this.rows[e].indent!==this.maxIndent}getPivotCell(e,t,o=!0){const s=this.columns.length;if(0===e&&t===s-1)return{content:this.rowTitle,isHeader:!0};if(t<=s-1){return{domain:this.getColHeaderDomain(e,t),isHeader:!0}}if(0===e){const e=t-s;return{domain:this.getRowDomain(e),isHeader:!0}}{const i=t-s;if(!o&&this.isTotalRow(i))return{isHeader:!1};return{domain:[...this.getRowDomain(i),...this.getColDomain(e)],isHeader:!1,measure:this.getColMeasure(e)}}}getColHeaderDomain(e,t){if(0===e)return;const o=[],s=this.columns[t].find((t=>t.offset===e));if(s){for(let e=0;e<s.fields.length;e++)o.push(s.fields[e]),o.push(s.values[e]);return o}}getColDomain(e){const t=this.getColHeaderDomain(e,this.columns.length-1);return t?t.slice(0,-2):[]}getColMeasure(e){const t=this.getColHeaderDomain(e,this.columns.length-1);return t?.at(-1)}getRowDomain(e){const t=[];for(let o=0;o<this.rows[e].fields.length;o++)t.push(this.rows[e].fields[o]),t.push(this.rows[e].values[o]);return t}export(){return{cols:this.columns,rows:this.rows,measures:this.measures,rowTitle:this.rowTitle}}}function Kw(e,t){const o=Jw(e,t.columns,0);eI(o,t.measures.length);const s=function(e,t){const o=t.columns.map((e=>e.nameWithGranularity)),s=o.length,i=t.measures.length,n=new Array(s).fill(0).map((()=>[]));function r(e,t,i){const a=n[t];for(const n of e){const e=i.concat([n.value]),l={fields:o.slice(0,t+1),values:e,width:n.width,offset:0};a.push(l),t<=s-1&&r(n.children,t+1,e)}}r(e,0,[]);const a=o.length>0,l=[];a&&n[n.length-1].forEach((e=>{t.measures.forEach((t=>{const o={fields:[...e.fields,"measure"],values:[...e.values,t.name],width:1,offset:0};l.push(o)}))}));t.measures.forEach((e=>{const t={fields:["measure"],values:[e.name],width:1,offset:0};l.push(t)})),n.push(l),1===n.length&&n.unshift([]);return n[n.length-2].push({fields:[],values:[],width:i,offset:0}),n}(o,t),i=Qw(e,0,t.rows,[],[]);i.push({fields:[],values:[],indent:0});const n=t.measures.map((e=>e.name)),r=i.length>0?i[0].values[0]:"";return new Xw(s,i,n,r)}function Qw(e,t,o,s,i){if(t>=o.length)return[];const n=o[t],r=n.nameWithGranularity,a=tI(e,n),l=oI(a,n),c=[],h=s.concat(r);for(const e of l){const s=i.concat(e);c.push({fields:h,values:s,indent:t});const n=a[e];n&&c.push(...Qw(n,t+1,o,h,s))}return c}function Jw(e,t,o){if(o>=t.length)return[];const s=t[o],i=t[o].nameWithGranularity,n=tI(e,s);return oI(n,t[o]).map((e=>({value:e,field:i,children:Jw(n[e]||[],t,o+1),width:0})))}function eI(e,t){for(const o in e){const s=e[o];0===s.children.length?s.width=t:(eI(s.children,t),s.width=s.children.reduce(((e,t)=>e+t.width),0))}}function tI(e,t){return Object.groupBy(e,function(e){const t=e.nameWithGranularity;return e=>`${e[t]?.value??null}`}(t))}function oI(e,t){return t.order?Object.keys(e).sort(((e,o)=>function(e,t,o){if("integer"===e.type||"date"===e.type)return"asc"===e.order?Number(t)-Number(o):Number(o)-Number(t);return"asc"===e.order?t.localeCompare(o):o.localeCompare(t)}(t,e,o))):Object.keys(e)}function sI(e,t,o){const s=e.granularity;if(!s||!(s in iI))throw new Error(`Unknown date granularity: ${s}`);if(null===t)return null;if(!iI[s].set.has(t)){iI[s].set.add(t);const e=rs(t,o);let i=0;switch(s){case"year":i=e.getFullYear();break;case"quarter_number":i=Math.floor(e.getMonth()/3)+1;break;case"month_number":i=e.getMonth();break;case"iso_week_number":i=e.getIsoWeek();break;case"day_of_month":i=e.getDate();break;case"day":i=Math.floor(jo(t,o))}iI[s].values[`${t}`]=i}return iI[s].values[`${t}`]}const iI={year:{set:new Set,values:{}},quarter_number:{set:new Set,values:{}},month_number:{set:new Set,values:{}},iso_week_number:{set:new Set,values:{}},day_of_month:{set:new Set,values:{}},day:{set:new Set,values:{}}};const nI=new $n;nI.add("SPREADSHEET",{ui:class{type="SPREADSHEET";getters;_definition;coreDefinition;dataEntries=[];fields={};fieldKeys=[];table;invalidRangeError;needsReevaluation=!0;constructor(e,t){this.getters=t.getters,this.coreDefinition=t.definition}init(e={}){if(!this._definition||e.reload){if(this.invalidRangeError=void 0,this.coreDefinition.dataSet){const{zone:e,sheetId:t}=this.coreDefinition.dataSet,o=this.getters.getRangeFromZone(t,e);try{({fields:this.fields,fieldKeys:this.fieldKeys}=this.extractFieldsFromRange(o))}catch(e){this.fields={},this.fieldKeys=[],this.invalidRangeError=e}}else this.invalidRangeError=new ko(go("The pivot cannot be created because the dataset is missing."));this._definition=new Yw(this.coreDefinition,this.fields,this.getters),this.table=void 0,this.dataEntries=[];const e=this._definition.range;this.isValid()&&e&&(this.dataEntries=this.extractDataEntriesFromRange(e)),this.needsReevaluation=!1}}get isInvalidRange(){return!!this.invalidRangeError}get invalidRangeMessage(){return this.invalidRangeError?.message}get definition(){if(!this._definition)throw new Error("Pivot not loaded yet");return this._definition}isValid(){if(this.invalidRangeError||!this._definition)return!1;for(const e of this.definition.measures)if(!e.isValid)return!1;for(const e of this.definition.columns)if(!e.isValid)return!1;for(const e of this.definition.rows)if(!e.isValid)return!1;return!0}assertIsValid({throwOnError:e}){if(!this.isValid()){if(e)throw this.invalidRangeError?this.invalidRangeError:new ko(go("At least one measure and/or dimension is not correct."));return{value:Po.GenericError,message:this.invalidRangeError?.message??go("At least one measure and/or dimension is not correct.")}}}markAsDirtyForEvaluation(){this.needsReevaluation=!0}getMeasure(e){return this.definition.getMeasure(e)}getPivotHeaderValueAndFormat(e){const t=Bb(e),o=t.at(-1);if(!o)return{value:go("Total")};if("measure"===o.field)return{value:this.getMeasure(o.value).displayName};const s=this.getDimension(o.field),i=this.filterDataEntriesFromDomain(this.dataEntries,t),n=i[0]?.[s.nameWithGranularity];if(!n)return{value:""};if(null===n.value||"null"===n.value)return{value:go("(Undefined)")};if("date"===s.type){if("day"===s.granularity)return{value:jo(n.value,this.getters.getLocale()),format:this.getters.getLocale().dateFormat};if("month_number"===s.granularity)return{value:Vs[jo(n.value,this.getters.getLocale())].toString()}}return{value:n.value,format:n.format}}getPivotCellValueAndFormat(e,t){const o=Bb(t),s=this.filterDataEntriesFromDomain(this.dataEntries,o);if(0===s.length)return{value:""};const i=s.map((t=>t[e])).filter((e=>e&&e.type!==mo.empty)).filter(_e),n=this.getMeasure(e).aggregator||"count",r=Tb[n];if(!r)throw new Error(`Aggregator ${n} does not exist`);try{return{value:i.length?r.fn([i],this.getters.getLocale()):"",format:r.format(i[0])}}catch(e){return Of(e,n.toUpperCase())}}getPossibleFieldValues(e){throw new Error("Method not implemented.")}getTableStructure(){if(!this.isValid())throw new Error("Pivot is not valid !");return this.table||(this.table=Kw(this.dataEntries,this.definition)),this.table}getFields(){return this.fields}filterDataEntriesFromDomain(e,t){return t.reduce(((e,t)=>this.filterDataEntriesFromDomainNode(e,t)),e)}filterDataEntriesFromDomainNode(e,t){const{field:o,value:s}=t,i=this.getDimension(o);return e.filter((e=>`${e[i.nameWithGranularity]?.value}`===s))}getDimension(e){return this.definition.getDimension(e)}getTypeFromZone(e,t){const o=this.getters.getEvaluatedCellsInZone(e,t).filter((e=>e.type!==mo.empty));return 0===o.length?"integer":o.every((e=>e.format&&Ys(e.format)))?"date":o.every((e=>e.type===mo.boolean))?"boolean":o.some((e=>e.type===mo.text))?"char":"integer"}assertCellIsValidField(e,t,o){if(o.type===mo.error)throw new ko(go("The pivot cannot be created because cell %s contains an error",Rt(e,t)));if(o.type===mo.empty)throw new ko(go("The pivot cannot be created because cell %s is empty",Rt(e,t)));if("__count"===o.value)throw new ko(go("The pivot cannot be created because cell %s contains a reserved value",Rt(e,t)))}extractFieldsFromRange(e){const t={},o=[],s=e.sheetId,i=e.zone.top;for(let n=e.zone.left;n<=e.zone.right;n++){const r=this.getters.getEvaluatedCell({sheetId:s,col:n,row:i});this.assertCellIsValidField(n,i,r);const a=r.value?.toString();if(a){const i=this.getTypeFromZone(s,{top:e.zone.top+1,left:n,bottom:e.zone.bottom,right:n}),r=this.findName(a,t);t[r]={name:r,type:i,string:r,aggregator:"integer"===i?"sum":"count"},o.push(r)}}return{fields:t,fieldKeys:o}}findName(e,t){let o=1;const s=e;for(;e in t;)e=`${s}${++o}`;return e}extractDataEntriesFromRange(e){const t=[];for(let o=e.zone.top+1;o<=e.zone.bottom;o++){const s={top:o,bottom:o,left:e.zone.left,right:e.zone.right},i=this.getters.getEvaluatedCellsInZone(e.sheetId,s),n={};for(const e in i){const t=i[e],o=this.fields[this.fieldKeys[e]];if(!o)throw new Error(`Field ${this.fieldKeys[e]} does not exist`);""===t.value?n[o.name]={value:null,type:mo.empty}:n[o.name]=t}n.__count={value:1,type:mo.number},t.push(n)}const o=this.definition.columns.concat(this.definition.rows).filter((e=>"date"===e.type));if(o.length)for(const e of t)for(const t of o)e[t.nameWithGranularity]={value:`${sI(t,e[t.name]?.value||null,this.getters.getLocale())}`,type:e[t.name]?.type||mo.empty,format:e[t.name]?.format};return t}},definition:Yw,externalData:!1,onIterationEndEvaluation:e=>e.markAsDirtyForEvaluation(),granularities:["year","quarter_number","month_number","iso_week_number","day_of_month","day"],isMeasureCandidate:e=>!["date","boolean"].includes(e.type),isGroupable:()=>!0});class rI extends Ja{pivotId;mutators=["reset","deferUpdates","applyUpdate","discardPendingUpdate","renamePivot","update"];updatesAreDeferred=!0;draft=null;constructor(e,t){super(e),this.pivotId=t}handle(e){if("UPDATE_PIVOT"===e.type)e.pivotId===this.pivotId&&this.getters.getPivot(this.pivotId).init()}get fields(){const e=this.pivot.getFields();if(!e)throw new Error("Fields not found");return e}get pivot(){return this.getters.getPivot(this.pivotId)}get definition(){const e=nI.get(this.pivot.type).definition;return this.draft?new e(this.draft,this.fields,this.getters):this.pivot.definition}get isDirty(){return!!this.draft}get unusedMeasureFields(){const e=[{name:"__count",string:go("Count"),type:"integer",aggregator:"sum"}],t=this.fields;for(const o in t){const s=t[o];s&&(nI.get(this.pivot.type).isMeasureCandidate(s)&&e.push(s))}const{rows:o,columns:s,measures:i}=this.definition,n=i.concat(o).concat(s).map((e=>e.name));return e.filter((e=>!n.includes(e.name))).sort(((e,t)=>e.string.localeCompare(t.string)))}get unusedGroupableFields(){const e=[],t=this.fields;for(const o in t){const s=t[o];s&&(nI.get(this.pivot.type).isGroupable(s)&&e.push(s))}const{columns:o,rows:s,measures:i}=this.definition,n=i.concat(s).concat(o).map((e=>e.name)),r=this.unusedDateTimeGranularities;return e.filter((e=>Pb(e)?!n.includes(e.name)||r[e.name].size>0:!n.includes(e.name))).sort(((e,t)=>e.string.localeCompare(t.string)))}get allGranularities(){return nI.get(this.pivot.type).granularities}get unusedDateTimeGranularities(){return this.getUnusedDateTimeGranularities(this.fields,this.draft??this.getters.getPivotCoreDefinition(this.pivotId))}reset(e){this.pivotId=e,this.updatesAreDeferred=!0,this.draft=null}deferUpdates(e){this.updatesAreDeferred=e,!1===e&&this.draft&&this.applyUpdate()}applyUpdate(){this.draft&&(this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:this.draft}),this.draft=null)}discardPendingUpdate(){this.draft=null}renamePivot(e){const t=this.getters.getPivotCoreDefinition(this.pivotId);this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:{...t,name:e}})}update(e){const t=this.getters.getPivotCoreDefinition(this.pivotId),o={...t,...this.draft,...e},s={...o,columns:o.columns.map((e=>({name:e.name,order:e.order,granularity:e.granularity}))),rows:o.rows.map((e=>({name:e.name,order:e.order,granularity:e.granularity}))),measures:o.measures.map((e=>({name:e.name,aggregator:e.aggregator})))};if(!this.draft&&Ue(t,s))return;const i=this.addDefaultDateTimeGranularity(this.fields,s);this.updatesAreDeferred?this.draft=i:this.model.dispatch("UPDATE_PIVOT",{pivotId:this.pivotId,pivot:i})}addDefaultDateTimeGranularity(e,t){const{columns:o,rows:s}=t,i=ue(o),n=ue(s),r=this.getUnusedDateTimeGranularities(e,t);for(const t of i.concat(n)){const o=e[t.name]?.type;if(("date"===o||"datetime"===o)&&!t.granularity){const e=r[t.name]?.values().next().value||"year";r[t.name]?.delete(e),t.granularity=e}}return{...t,columns:i,rows:n}}getUnusedDateTimeGranularities(e,t){const{columns:o,rows:s}=t,i=o.concat(s).filter((t=>{const o=e[t.name]?.type;return"date"===o||"datetime"===o})),n=this.allGranularities,r={};for(const e of i)r[e.name]=new Set(n);for(const e of i)r[e.name].delete(e.granularity);return r}}class aI extends t.Component{static template="o-spreadsheet-PivotSpreadsheetSidePanel";static props={pivotId:String,onCloseSidePanel:Function};static components={PivotLayoutConfigurator:qw,Section:Ix,SelectionInput:Ax,EditableName:Hw,Checkbox:wx};store;state;setup(){this.store=qa(rI,this.props.pivotId),this.pivot.init(),this.state=t.useState({range:void 0,rangeHasChanged:!1})}get shouldDisplayInvalidRangeError(){return(!this.store.isDirty||!this.state.rangeHasChanged)&&this.pivot.isInvalidRange}get ranges(){return this.state.range?[this.state.range]:this.definition.range?[this.env.model.getters.getRangeString(this.definition.range,"forceSheetReference")]:[]}get pivot(){return this.store.pivot}get name(){return this.env.model.getters.getPivotName(this.props.pivotId)}get displayName(){return this.env.model.getters.getPivotDisplayName(this.props.pivotId)}get definition(){return this.store.definition}get deferUpdatesLabel(){return go("Defer updates")}get deferUpdatesTooltip(){return go("Changing the pivot definition requires to reload the data. It may take some time.")}onSelectionChanged(e){this.state.rangeHasChanged=!0,this.state.range=e[0]}onSelectionConfirmed(){if(this.state.range){const{sheetName:e,xc:t}=Ai(this.state.range),o=e?this.env.model.getters.getSheetIdByName(e):this.env.model.getters.getActiveSheetId();if(!o)return;const s={sheetId:o,zone:ki(t)};this.store.update({dataSet:s}),this.store.applyUpdate()}}duplicatePivot(){const e=this.env.model.uuidGenerator.uuidv4(),t=this.env.model.dispatch("DUPLICATE_PIVOT",{pivotId:this.props.pivotId,newPivotId:e}),o=t.isSuccessful?go("Pivot duplicated."):go("Pivot duplication failed"),s=t.isSuccessful?"success":"danger";this.env.notifyUser({text:o,sticky:!1,type:s}),t.isSuccessful&&this.env.openSidePanel("PivotSidePanel",{pivotId:e})}onNameChanged(e){this.store.renamePivot(e)}onDimensionsUpdated(e){this.store.update(e)}back(){this.env.openSidePanel("PivotSidePanel",{})}delete(){this.env.model.dispatch("REMOVE_PIVOT",{pivotId:this.props.pivotId})}}const lI=new $n;lI.add("SPREADSHEET",{editor:aI}),Lf`
1167
1167
  .o_pivot_list_item {
1168
1168
  cursor: pointer;
1169
1169
  &:hover {
@@ -1768,7 +1768,7 @@
1768
1768
  }
1769
1769
  }
1770
1770
  }
1771
- `;class $_ extends t.Component{static template="o-spreadsheet-BottomBarSheet";static props={sheetId:String,openContextMenu:Function,style:{type:String,optional:!0},onMouseDown:{type:Function,optional:!0}};static components={Ripple:z_};static defaultProps={onMouseDown:()=>{},style:""};state=t.useState({isEditing:!1});sheetDivRef=t.useRef("sheetDiv");sheetNameRef=t.useRef("sheetNameSpan");editionState="initializing";DOMFocusableElementStore;setup(){t.onMounted((()=>{this.isSheetActive&&this.scrollToSheet()})),t.onPatched((()=>{this.sheetNameRef.el&&this.state.isEditing&&"initializing"===this.editionState&&(this.editionState="editing",this.focusInputAndSelectContent())})),this.DOMFocusableElementStore=Wa(Ff)}focusInputAndSelectContent(){if(!this.state.isEditing||!this.sheetNameRef.el)return;this.sheetNameRef.el.focus();const e=window.getSelection();e&&this.sheetNameRef.el.firstChild&&e.setBaseAndExtent(this.sheetNameRef.el.firstChild,0,this.sheetNameRef.el.firstChild,this.sheetNameRef.el.textContent?.length||0)}scrollToSheet(){this.sheetDivRef.el?.scrollIntoView?.()}onFocusOut(){this.state.isEditing&&"initializing"!==this.editionState&&this.stopEdition()}onMouseDown(e){this.activateSheet(),this.props.onMouseDown(e)}activateSheet(){this.env.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.env.model.getters.getActiveSheetId(),sheetIdTo:this.props.sheetId}),this.scrollToSheet()}onDblClick(){this.env.model.getters.isReadonly()||this.startEdition()}onKeyDown(e){this.state.isEditing&&("Enter"===e.key&&(e.preventDefault(),this.stopEdition(),this.DOMFocusableElementStore.focus()),"Escape"===e.key&&(this.cancelEdition(),this.DOMFocusableElementStore.focus()))}onClickSheetName(e){this.state.isEditing&&e.stopPropagation()}startEdition(){this.state.isEditing=!0,this.editionState="initializing"}stopEdition(){const e=this.sheetNameRef.el;if(!this.state.isEditing||!e)return;this.state.isEditing=!1,this.editionState="initializing",e.blur();const t=this.getInputContent()||"";e.innerText=t,function(e,t,o,s){const i=e.model.dispatch("RENAME_SHEET",{sheetId:t,name:o});i.reasons.includes("MissingSheetName")?e.raiseError(go("The sheet name cannot be empty."),s):i.reasons.includes("DuplicatedSheetName")?e.raiseError(go("A sheet with the name %s already exists. Please select another name.",o),s):i.reasons.includes("ForbiddenCharactersInSheetName")&&e.raiseError(go("Some used characters are not allowed in a sheet name (Forbidden characters are %s).",oe.join(" ")),s)}(this.env,this.props.sheetId,t,(()=>this.startEdition()))}cancelEdition(){this.state.isEditing=!1,this.editionState="initializing",this.sheetNameRef.el?.blur(),this.setInputContent(this.sheetName)}onIconClick(e){this.isSheetActive||this.activateSheet(),this.props.openContextMenu(this.contextMenuRegistry,e)}onContextMenu(e){this.isSheetActive||this.activateSheet(),this.props.openContextMenu(this.contextMenuRegistry,e)}getInputContent(){return this.sheetNameRef.el?.textContent}setInputContent(e){this.sheetNameRef.el&&(this.sheetNameRef.el.textContent=e)}get contextMenuRegistry(){return function(e){const t=new cS;return t.add("delete",{...MS,sequence:10}).add("duplicate",{...FS,sequence:20}).add("rename",{...NS(e),sequence:30}).add("move_right",{...PS,sequence:40}).add("move_left",{...LS,sequence:50}).add("hide_sheet",{...kS,sequence:60}),t}({renameSheetCallback:()=>{this.scrollToSheet(),this.startEdition()}})}get isSheetActive(){return this.env.model.getters.getActiveSheetId()===this.props.sheetId}get sheetName(){return this.env.model.getters.getSheetName(this.props.sheetId)}}const G_=[{name:go("Sum"),types:[mo.number],compute:(e,t)=>Ac([[e]],t)},{name:go("Avg"),types:[mo.number],compute:(e,t)=>Hh([[e]],t)},{name:go("Min"),types:[mo.number],compute:(e,t)=>Wh([[e]],t)},{name:go("Max"),types:[mo.number],compute:(e,t)=>Gh([[e]],t)},{name:go("Count"),types:[mo.number,mo.text,mo.boolean,mo.error],compute:e=>$h([[e]])},{name:go("Count Numbers"),types:[mo.number,mo.text,mo.boolean,mo.error],compute:(e,t)=>zh([[e]],t)}];class W_ extends Ja{statisticFnResults=this._computeStatisticFnResults();isDirty=!1;constructor(e){super(e),this.model.selection.observe(this,{handleEvent:this.handleEvent.bind(this)})}handle(e){switch((bo.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isDirty=!0),e.type){case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"GROUP_HEADERS":case"UNGROUP_HEADERS":case"ACTIVATE_SHEET":case"ACTIVATE_NEXT_SHEET":case"ACTIVATE_PREVIOUS_SHEET":case"EVALUATE_CELLS":case"UNDO":case"REDO":this.isDirty=!0}}finalize(){this.isDirty&&(this.isDirty=!1,this.statisticFnResults=this._computeStatisticFnResults())}handleEvent(){this.getters.isGridSelectionActive()&&(this.statisticFnResults=this._computeStatisticFnResults())}_computeStatisticFnResults(){const e=this.getters,t=e.getActiveSheetId(),o=[],s=_i(e.getSelectedZones(),[]),i=this.getters.getSheetSize(t).numberOfRows-1,n=this.getters.getSheetSize(t).numberOfCols-1;for(const r of s)for(let s=r.left;s<=(r.right??n);s++)for(let n=r.top;n<=(r.bottom??i);n++){if(e.isRowHidden(t,n)||e.isColHidden(t,s))continue;const i=e.getEvaluatedCell({sheetId:t,col:s,row:n});i.type!==mo.empty&&o.push(i)}const r=e.getLocale();let a={};const l=Ze((e=>{const t=e.split(",");return o.filter((e=>t.includes(e.type)))}));for(let e of G_){let t;const o=l(e.types.sort().join(","));o.length&&(t=Le((()=>e.compute(o,r)))),a[e.name]=t}return a}}Lf`
1771
+ `;class $_ extends t.Component{static template="o-spreadsheet-BottomBarSheet";static props={sheetId:String,openContextMenu:Function,style:{type:String,optional:!0},onMouseDown:{type:Function,optional:!0}};static components={Ripple:z_};static defaultProps={onMouseDown:()=>{},style:""};state=t.useState({isEditing:!1});sheetDivRef=t.useRef("sheetDiv");sheetNameRef=t.useRef("sheetNameSpan");editionState="initializing";DOMFocusableElementStore;setup(){t.onMounted((()=>{this.isSheetActive&&this.scrollToSheet()})),t.onPatched((()=>{this.sheetNameRef.el&&this.state.isEditing&&"initializing"===this.editionState&&(this.editionState="editing",this.focusInputAndSelectContent())})),this.DOMFocusableElementStore=Wa(Ff)}focusInputAndSelectContent(){if(!this.state.isEditing||!this.sheetNameRef.el)return;this.sheetNameRef.el.focus();const e=window.getSelection();e&&this.sheetNameRef.el.firstChild&&e.setBaseAndExtent(this.sheetNameRef.el.firstChild,0,this.sheetNameRef.el.firstChild,this.sheetNameRef.el.textContent?.length||0)}scrollToSheet(){this.sheetDivRef.el?.scrollIntoView?.()}onFocusOut(){this.state.isEditing&&"initializing"!==this.editionState&&this.stopEdition()}onMouseDown(e){this.activateSheet(),this.props.onMouseDown(e)}activateSheet(){this.env.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.env.model.getters.getActiveSheetId(),sheetIdTo:this.props.sheetId}),this.scrollToSheet()}onDblClick(){this.env.model.getters.isReadonly()||this.startEdition()}onKeyDown(e){this.state.isEditing&&("Enter"===e.key&&(e.preventDefault(),this.stopEdition(),this.DOMFocusableElementStore.focus()),"Escape"===e.key&&(this.cancelEdition(),this.DOMFocusableElementStore.focus()))}onMouseEventSheetName(e){this.state.isEditing&&e.stopPropagation()}startEdition(){this.state.isEditing=!0,this.editionState="initializing"}stopEdition(){const e=this.sheetNameRef.el;if(!this.state.isEditing||!e)return;this.state.isEditing=!1,this.editionState="initializing",e.blur();const t=this.getInputContent()||"";e.innerText=t,function(e,t,o,s){const i=e.model.dispatch("RENAME_SHEET",{sheetId:t,name:o});i.reasons.includes("MissingSheetName")?e.raiseError(go("The sheet name cannot be empty."),s):i.reasons.includes("DuplicatedSheetName")?e.raiseError(go("A sheet with the name %s already exists. Please select another name.",o),s):i.reasons.includes("ForbiddenCharactersInSheetName")&&e.raiseError(go("Some used characters are not allowed in a sheet name (Forbidden characters are %s).",oe.join(" ")),s)}(this.env,this.props.sheetId,t,(()=>this.startEdition()))}cancelEdition(){this.state.isEditing=!1,this.editionState="initializing",this.sheetNameRef.el?.blur(),this.setInputContent(this.sheetName)}onIconClick(e){this.isSheetActive||this.activateSheet(),this.props.openContextMenu(this.contextMenuRegistry,e)}onContextMenu(e){this.isSheetActive||this.activateSheet(),this.props.openContextMenu(this.contextMenuRegistry,e)}getInputContent(){return this.sheetNameRef.el?.textContent}setInputContent(e){this.sheetNameRef.el&&(this.sheetNameRef.el.textContent=e)}get contextMenuRegistry(){return function(e){const t=new cS;return t.add("delete",{...MS,sequence:10}).add("duplicate",{...FS,sequence:20}).add("rename",{...NS(e),sequence:30}).add("move_right",{...PS,sequence:40}).add("move_left",{...LS,sequence:50}).add("hide_sheet",{...kS,sequence:60}),t}({renameSheetCallback:()=>{this.scrollToSheet(),this.startEdition()}})}get isSheetActive(){return this.env.model.getters.getActiveSheetId()===this.props.sheetId}get sheetName(){return this.env.model.getters.getSheetName(this.props.sheetId)}}const G_=[{name:go("Sum"),types:[mo.number],compute:(e,t)=>Ac([[e]],t)},{name:go("Avg"),types:[mo.number],compute:(e,t)=>Hh([[e]],t)},{name:go("Min"),types:[mo.number],compute:(e,t)=>Wh([[e]],t)},{name:go("Max"),types:[mo.number],compute:(e,t)=>Gh([[e]],t)},{name:go("Count"),types:[mo.number,mo.text,mo.boolean,mo.error],compute:e=>$h([[e]])},{name:go("Count Numbers"),types:[mo.number,mo.text,mo.boolean,mo.error],compute:(e,t)=>zh([[e]],t)}];class W_ extends Ja{statisticFnResults=this._computeStatisticFnResults();isDirty=!1;constructor(e){super(e),this.model.selection.observe(this,{handleEvent:this.handleEvent.bind(this)})}handle(e){switch((bo.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isDirty=!0),e.type){case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"GROUP_HEADERS":case"UNGROUP_HEADERS":case"ACTIVATE_SHEET":case"ACTIVATE_NEXT_SHEET":case"ACTIVATE_PREVIOUS_SHEET":case"EVALUATE_CELLS":case"UNDO":case"REDO":this.isDirty=!0}}finalize(){this.isDirty&&(this.isDirty=!1,this.statisticFnResults=this._computeStatisticFnResults())}handleEvent(){this.getters.isGridSelectionActive()&&(this.statisticFnResults=this._computeStatisticFnResults())}_computeStatisticFnResults(){const e=this.getters,t=e.getActiveSheetId(),o=[],s=_i(e.getSelectedZones(),[]),i=this.getters.getSheetSize(t).numberOfRows-1,n=this.getters.getSheetSize(t).numberOfCols-1;for(const r of s)for(let s=r.left;s<=(r.right??n);s++)for(let n=r.top;n<=(r.bottom??i);n++){if(e.isRowHidden(t,n)||e.isColHidden(t,s))continue;const i=e.getEvaluatedCell({sheetId:t,col:s,row:n});i.type!==mo.empty&&o.push(i)}const r=e.getLocale();let a={};const l=Ze((e=>{const t=e.split(",");return o.filter((e=>t.includes(e.type)))}));for(let e of G_){let t;const o=l(e.types.sort().join(","));o.length&&(t=Le((()=>e.compute(o,r)))),a[e.name]=t}return a}}Lf`
1772
1772
  .o-selection-statistic {
1773
1773
  margin-right: 20px;
1774
1774
  padding: 4px 4px 4px 8px;
@@ -3049,4 +3049,4 @@
3049
3049
  <tableParts count="${e.tables.length}">
3050
3050
  ${MA(a)}
3051
3051
  </tableParts>
3052
- `}var pM;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(pM||(pM={}));function mM(e,t={}){const o=ue(t);return o.type=e,o}const fM={},bM={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:O,HEADER_WIDTH:_,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:D,DEFAULT_CELL_HEIGHT:M,SCROLLBAR_WIDTH:F},vM={autoCompleteProviders:Sa,autofillModifiersRegistry:Hb,autofillRulesRegistry:zb,cellMenuRegistry:My,colMenuRegistry:fx,errorTypes:Lo,linkMenuRegistry:VS,functionRegistry:Mf,featurePluginRegistry:P_,statefulUIPluginRegistry:L_,coreViewsPluginRegistry:k_,corePluginRegistry:N_,rowMenuRegistry:Cx,sidePanelRegistry:MI,figureRegistry:sS,chartSidePanelComponentRegistry:sw,chartComponentRegistry:Qv,chartRegistry:Kv,topbarMenuRegistry:Ex,topbarComponentRegistry:FI,clickableCellRegistry:V_,otRegistry:xx,inverseCommandRegistry:aS,urlRegistry:oa,cellPopoverRegistry:jb,numberFormatMenuRegistry:bx,repeatLocalCommandTransformRegistry:__,repeatCommandTransformRegistry:O_,clipboardHandlersRegistries:Tr,pivotRegistry:nI,pivotTimeAdapterRegistry:OR,pivotSidePanelRegistry:lI,supportedPivotExplodedFormulaRegistry:gm},SM={arg:Gl,isEvaluationError:qo,toBoolean:ns,toJsDate:rs,toNumber:jo,toString:os,toXC:Rt,toZone:ki,toUnboundedZone:Li,toCartesian:It,numberToLetters:Ct,lettersToNumber:Et,UuidGenerator:Un,formatValue:zs,createCurrencyFormat:ii,ColorGenerator:St,computeTextWidth:wn,createEmptyWorkbookData:aO,createEmptySheet:rO,createEmptyExcelSheet:lO,getDefaultChartJsRuntime:yv,chartFontColor:Cl,getChartAxisTitleRuntime:wl,getFillingMode:Iv,rgbaToHex:ct,colorToRGBA:ht,positionToZone:sn,isDefined:_e,isMatrix:Do,lazy:Le,genericRepeat:D_,createAction:zn,createActions:Bn,transformRangeData:Or,deepEquals:Ue,overlap:ji,union:Wi,isInside:Yi,deepCopy:ue,expandZoneOnInsertion:Hi,reduceZoneOnDeletion:Gi,unquote:pe,makePivotFormula:Ab,getMaxObjectId:Ob,getFunctionsFromTokens:yb,getFirstPivotFunction:_b,getNumberOfPivotFunctions:Db,parseDimension:Nb,isDateField:Pb,makeFieldProposal:Lb,insertTokenAfterArgSeparator:kb,insertTokenAfterLeftParenthesis:Vb,mergeContiguousZones:un,getPivotHighlights:yx,pivotTimeAdapter:function(e){return OR.get(e)},UNDO_REDO_PIVOT_COMMANDS:o_},CM={isMarkdownLink:Ee,parseMarkdownLink:Ie,markdownLink:we,openLink:aa,urlRepresentation:ra},yM={Checkbox:wx,Section:Ix,RoundColorPicker:Wx,ChartDataSeries:Ox,ChartErrorSection:Dx,ChartLabelRange:Mx,ChartTitle:qx,ChartPanel:nw,ChartFigure:eS,ChartJsComponent:cl,Grid:AR,GridOverlay:cR,ScorecardChart:Bl,LineConfigPanel:Qx,BarConfigPanel:Nx,PieChartDesignPanel:Jx,GenericChartConfigPanel:Fx,ChartWithAxisDesignPanel:Yx,GaugeChartConfigPanel:Xx,GaugeChartDesignPanel:Kx,ScorecardChartConfigPanel:ew,ScorecardChartDesignPanel:tw,FigureComponent:NI,Menu:US,Popover:SS,SelectionInput:Ax,ValidationMessages:_x,AddDimensionButton:zw,PivotDimensionGranularity:Gw,PivotDimensionOrder:Ww,PivotDimension:$w,PivotLayoutConfigurator:qw,EditableName:Hw},EM={useDragAndDropListItems:hw,useHighlights:bw,useHighlightsOnHover:fw},xM={useStoreProvider:Ga,DependencyContainer:Ha,CellPopoverStore:gS,ComposerFocusStore:nl,ComposerStore:il,FindAndReplaceStore:kw,HighlightStore:tl,HoveredCellStore:uS,ModelStore:Xa,NotificationStore:ol,RendererStore:Qa,SelectionInputStore:Tx,SpreadsheetStore:Ja,useStore:Wa,useLocalStore:qa,SidePanelStore:wR,PivotSidePanelStore:rI};const wM={DEFAULT_LOCALE:Oo,HIGHLIGHT_COLOR:s,PIVOT_TABLE_CONFIG:{hasFilters:!1,totalRow:!1,firstColumn:!0,lastColumn:!1,numberOfHeaders:1,bandedRows:!0,bandedColumns:!1,styleId:"TableStyleMedium5"}};e.AbstractCellClipboardHandler=Zn,e.AbstractChart=hl,e.AbstractFigureClipboardHandler=Rr,e.CellErrorType=Po,e.CorePlugin=hO,e.DispatchResult=wo,e.EvaluationError=ko,e.Model=class extends Ba{corePlugins=[];featurePlugins=[];statefulUIPlugins=[];coreViewsPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},o={},s=[],i=new Un,n=!0){const r=performance.now();console.group("Model creation"),super(),co===ao&&ho===lo&&(ho=()=>!0),s=sO(e,s);const a=tO(e,n);this.state=new RD,this.uuidGenerator=i,this.config=this.setupConfig(o),this.session=this.setupSession(a.revisionId),this.coreGetters={},this.range=new fO(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new wD(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of N_.getAll())this.setupCorePlugin(e,a);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(s);for(let e of k_.getAll()){const t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of L_.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of P_.getAll()){const t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}if(this.uuidGenerator.setIsFastStrategy(!1),this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.joinSession(),o.snapshotRequested){const e=performance.now();console.info("Snapshot requested"),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.info("Snapshot taken in",performance.now()-e,"ms")}t.markRaw(this),console.info("Model created in",performance.now()-r,"ms"),console.groupEnd()}joinSession(){this.session.join(this.config.client)}leaveSession(){this.session.leave(this.exportData())}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}for(const o of e.layers)this.renderers[o]||(this.renderers[o]=[]),this.renderers[o].push(t);return t}setupCorePlugin(e,t){const o=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in o))throw new Error(`Invalid getter name: ${t} for plugin ${o.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=o[t].bind(o)}o.import(t),this.corePlugins.push(o),this.coreHandlers.push(o),this.handlers.push(o)}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new b_(yD({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1)}}),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-undone",this,(({commands:e})=>{this.dispatchFromCorePlugin("UNDO",{commands:e}),this.finalize()})),this.session.on("revision-redone",this,(({commands:e})=>{this.dispatchFromCorePlugin("REDO",{commands:e}),this.finalize()})),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.uuidv4(),name:go("Anonymous").toString()},o=e.transportService||new gD;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:o,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),raiseBlockingErrorUI:e=>this.trigger("raise-error-ui",{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){const t=e.loadLocales||(()=>Promise.resolve(Ao));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrencyFormat:this.config.defaultCurrencyFormat,customColors:this.config.customColors||[]}}checkDispatchAllowed(e){const t=xo(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some((e=>"Success"!==e))?new wo(t.flat()):wo.Success}checkDispatchAllowedCoreCommand(e){const t=this.corePlugins.map((t=>t.allowDispatch(e)));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map((t=>t.allowDispatch(e)))}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0,this.trigger("command-finalized")}canDispatch=(e,t)=>this.checkDispatchAllowed(mM(e,t));dispatch=(e,t)=>{const o=mM(e,t);let s=this.status;if(this.getters.isReadonly()&&(i=o,!yo.has(i.type)))return new wo("Readonly");var i;if(!this.session.canApplyOptimisticUpdate())return new wo("WaitingSessionConfirmation");switch(s){case 0:const t=this.checkDispatchAllowed(o);if(!t.isSuccessful)return t;this.status=1;const{changes:s,commands:i}=this.state.recordChanges((()=>{const t=performance.now();xo(o)&&this.state.addCommand(o),this.dispatchToHandlers(this.handlers,o),this.finalize();const s=performance.now()-t;s>5&&console.info(e,s,"ms")}));this.session.save(o,i,s),this.status=0,this.trigger("update");break;case 1:if(xo(o)){const e=this.checkDispatchAllowed(o);if(!e.isSuccessful)return e;this.state.addCommand(o)}this.dispatchToHandlers(this.handlers,o);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(xo(o))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,o)}return wo.Success};dispatchFromCorePlugin=(e,t)=>{const o=mM(e,t),s=this.status;this.status=2;const i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,o),this.status=s,wo.Success};dispatchToHandlers(e,t){const o=xo(t);for(const s of e)!o&&s instanceof hO||s.beforeHandle(t);for(const s of e)!o&&s instanceof hO||s.handle(t);this.trigger("command-dispatched",t)}drawLayer(e,t){const o=this.renderers[t];if(o)for(const s of o)e.ctx.save(),s.drawLayer(e,t),e.ctx.restore()}exportData(){let e=aO();for(let t of this.handlers)t instanceof hO&&t.export(e);return e.revisionId=this.session.getRevisionId()||j,e=ue(e),e}updateMode(e){this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...aO(),sheets:[lO(eO,"Sheet1")]};for(let t of this.handlers)t instanceof cO&&t.exportForExcel(e);return e=ue(e),uM(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.PivotRuntimeDefinition=Zw,e.Registry=$n,e.Revision=m_,e.SPREADSHEET_DIMENSIONS=bM,e.Spreadsheet=uD,e.SpreadsheetPivotTable=Xw,e.UIPlugin=vO,e.__info__=fM,e.addFunction=function e(t,o){return Mf.add(t,o),{addFunction:(t,o)=>e(t,o)}},e.addRenderingLayer=function(e,t){if(Fo[e])throw new Error(`Layer ${e} already exists`);Fo[e]=t},e.astToFormula=Wr,e.compile=bb,e.compileTokens=vb,e.components=yM,e.constants=wM,e.convertAstNodes=Hr,e.coreTypes=Eo,e.findCellInNewZone=on,e.functionCache=fb,e.helpers=SM,e.hooks=EM,e.invalidateCFEvaluationCommands=So,e.invalidateDependenciesCommands=vo,e.invalidateEvaluationCommands=bo,e.iterateAstNodes=zr,e.links=CM,e.load=tO,e.parse=Ur,e.parseTokens=Br,e.readonlyAllowedCommands=yo,e.registries=vM,e.setDefaultSheetViewSize=function(e){re=e},e.setTranslationMethod=function(e,t=(()=>!0)){co=e,ho=t},e.stores=xM,e.tokenColors=ab,e.tokenize=Xn,fM.version="17.3.5",fM.date="2024-06-26T11:05:50.339Z",fM.hash="54eb151"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
3052
+ `}var pM;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(pM||(pM={}));function mM(e,t={}){const o=ue(t);return o.type=e,o}const fM={},bM={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:O,HEADER_WIDTH:_,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:D,DEFAULT_CELL_HEIGHT:M,SCROLLBAR_WIDTH:F},vM={autoCompleteProviders:Sa,autofillModifiersRegistry:Hb,autofillRulesRegistry:zb,cellMenuRegistry:My,colMenuRegistry:fx,errorTypes:Lo,linkMenuRegistry:VS,functionRegistry:Mf,featurePluginRegistry:P_,statefulUIPluginRegistry:L_,coreViewsPluginRegistry:k_,corePluginRegistry:N_,rowMenuRegistry:Cx,sidePanelRegistry:MI,figureRegistry:sS,chartSidePanelComponentRegistry:sw,chartComponentRegistry:Qv,chartRegistry:Kv,topbarMenuRegistry:Ex,topbarComponentRegistry:FI,clickableCellRegistry:V_,otRegistry:xx,inverseCommandRegistry:aS,urlRegistry:oa,cellPopoverRegistry:jb,numberFormatMenuRegistry:bx,repeatLocalCommandTransformRegistry:__,repeatCommandTransformRegistry:O_,clipboardHandlersRegistries:Tr,pivotRegistry:nI,pivotTimeAdapterRegistry:OR,pivotSidePanelRegistry:lI,supportedPivotExplodedFormulaRegistry:gm},SM={arg:Gl,isEvaluationError:qo,toBoolean:ns,toJsDate:rs,toNumber:jo,toString:os,toXC:Rt,toZone:ki,toUnboundedZone:Li,toCartesian:It,numberToLetters:Ct,lettersToNumber:Et,UuidGenerator:Un,formatValue:zs,createCurrencyFormat:ii,ColorGenerator:St,computeTextWidth:wn,createEmptyWorkbookData:aO,createEmptySheet:rO,createEmptyExcelSheet:lO,getDefaultChartJsRuntime:yv,chartFontColor:Cl,getChartAxisTitleRuntime:wl,getFillingMode:Iv,rgbaToHex:ct,colorToRGBA:ht,positionToZone:sn,isDefined:_e,isMatrix:Do,lazy:Le,genericRepeat:D_,createAction:zn,createActions:Bn,transformRangeData:Or,deepEquals:Ue,overlap:ji,union:Wi,isInside:Yi,deepCopy:ue,expandZoneOnInsertion:Hi,reduceZoneOnDeletion:Gi,unquote:pe,makePivotFormula:Ab,getMaxObjectId:Ob,getFunctionsFromTokens:yb,getFirstPivotFunction:_b,getNumberOfPivotFunctions:Db,parseDimension:Nb,isDateField:Pb,makeFieldProposal:Lb,insertTokenAfterArgSeparator:kb,insertTokenAfterLeftParenthesis:Vb,mergeContiguousZones:un,getPivotHighlights:yx,pivotTimeAdapter:function(e){return OR.get(e)},UNDO_REDO_PIVOT_COMMANDS:o_},CM={isMarkdownLink:Ee,parseMarkdownLink:Ie,markdownLink:we,openLink:aa,urlRepresentation:ra},yM={Checkbox:wx,Section:Ix,RoundColorPicker:Wx,ChartDataSeries:Ox,ChartErrorSection:Dx,ChartLabelRange:Mx,ChartTitle:qx,ChartPanel:nw,ChartFigure:eS,ChartJsComponent:cl,Grid:AR,GridOverlay:cR,ScorecardChart:Bl,LineConfigPanel:Qx,BarConfigPanel:Nx,PieChartDesignPanel:Jx,GenericChartConfigPanel:Fx,ChartWithAxisDesignPanel:Yx,GaugeChartConfigPanel:Xx,GaugeChartDesignPanel:Kx,ScorecardChartConfigPanel:ew,ScorecardChartDesignPanel:tw,FigureComponent:NI,Menu:US,Popover:SS,SelectionInput:Ax,ValidationMessages:_x,AddDimensionButton:zw,PivotDimensionGranularity:Gw,PivotDimensionOrder:Ww,PivotDimension:$w,PivotLayoutConfigurator:qw,EditableName:Hw},EM={useDragAndDropListItems:hw,useHighlights:bw,useHighlightsOnHover:fw},xM={useStoreProvider:Ga,DependencyContainer:Ha,CellPopoverStore:gS,ComposerFocusStore:nl,ComposerStore:il,FindAndReplaceStore:kw,HighlightStore:tl,HoveredCellStore:uS,ModelStore:Xa,NotificationStore:ol,RendererStore:Qa,SelectionInputStore:Tx,SpreadsheetStore:Ja,useStore:Wa,useLocalStore:qa,SidePanelStore:wR,PivotSidePanelStore:rI};const wM={DEFAULT_LOCALE:Oo,HIGHLIGHT_COLOR:s,PIVOT_TABLE_CONFIG:{hasFilters:!1,totalRow:!1,firstColumn:!0,lastColumn:!1,numberOfHeaders:1,bandedRows:!0,bandedColumns:!1,styleId:"TableStyleMedium5"}};e.AbstractCellClipboardHandler=Zn,e.AbstractChart=hl,e.AbstractFigureClipboardHandler=Rr,e.CellErrorType=Po,e.CorePlugin=hO,e.DispatchResult=wo,e.EvaluationError=ko,e.Model=class extends Ba{corePlugins=[];featurePlugins=[];statefulUIPlugins=[];coreViewsPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},o={},s=[],i=new Un,n=!0){const r=performance.now();console.group("Model creation"),super(),co===ao&&ho===lo&&(ho=()=>!0),s=sO(e,s);const a=tO(e,n);this.state=new RD,this.uuidGenerator=i,this.config=this.setupConfig(o),this.session=this.setupSession(a.revisionId),this.coreGetters={},this.range=new fO(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new wD(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of N_.getAll())this.setupCorePlugin(e,a);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(s);for(let e of k_.getAll()){const t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of L_.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of P_.getAll()){const t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}if(this.uuidGenerator.setIsFastStrategy(!1),this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.joinSession(),o.snapshotRequested){const e=performance.now();console.info("Snapshot requested"),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.info("Snapshot taken in",performance.now()-e,"ms")}t.markRaw(this),console.info("Model created in",performance.now()-r,"ms"),console.groupEnd()}joinSession(){this.session.join(this.config.client)}leaveSession(){this.session.leave(this.exportData())}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}for(const o of e.layers)this.renderers[o]||(this.renderers[o]=[]),this.renderers[o].push(t);return t}setupCorePlugin(e,t){const o=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in o))throw new Error(`Invalid getter name: ${t} for plugin ${o.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=o[t].bind(o)}o.import(t),this.corePlugins.push(o),this.coreHandlers.push(o),this.handlers.push(o)}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new b_(yD({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1)}}),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-undone",this,(({commands:e})=>{this.dispatchFromCorePlugin("UNDO",{commands:e}),this.finalize()})),this.session.on("revision-redone",this,(({commands:e})=>{this.dispatchFromCorePlugin("REDO",{commands:e}),this.finalize()})),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.uuidv4(),name:go("Anonymous").toString()},o=e.transportService||new gD;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:o,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),raiseBlockingErrorUI:e=>this.trigger("raise-error-ui",{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){const t=e.loadLocales||(()=>Promise.resolve(Ao));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrencyFormat:this.config.defaultCurrencyFormat,customColors:this.config.customColors||[]}}checkDispatchAllowed(e){const t=xo(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some((e=>"Success"!==e))?new wo(t.flat()):wo.Success}checkDispatchAllowedCoreCommand(e){const t=this.corePlugins.map((t=>t.allowDispatch(e)));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map((t=>t.allowDispatch(e)))}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0,this.trigger("command-finalized")}canDispatch=(e,t)=>this.checkDispatchAllowed(mM(e,t));dispatch=(e,t)=>{const o=mM(e,t);let s=this.status;if(this.getters.isReadonly()&&(i=o,!yo.has(i.type)))return new wo("Readonly");var i;if(!this.session.canApplyOptimisticUpdate())return new wo("WaitingSessionConfirmation");switch(s){case 0:const t=this.checkDispatchAllowed(o);if(!t.isSuccessful)return t;this.status=1;const{changes:s,commands:i}=this.state.recordChanges((()=>{const t=performance.now();xo(o)&&this.state.addCommand(o),this.dispatchToHandlers(this.handlers,o),this.finalize();const s=performance.now()-t;s>5&&console.info(e,s,"ms")}));this.session.save(o,i,s),this.status=0,this.trigger("update");break;case 1:if(xo(o)){const e=this.checkDispatchAllowed(o);if(!e.isSuccessful)return e;this.state.addCommand(o)}this.dispatchToHandlers(this.handlers,o);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(xo(o))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,o)}return wo.Success};dispatchFromCorePlugin=(e,t)=>{const o=mM(e,t),s=this.status;this.status=2;const i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,o),this.status=s,wo.Success};dispatchToHandlers(e,t){const o=xo(t);for(const s of e)!o&&s instanceof hO||s.beforeHandle(t);for(const s of e)!o&&s instanceof hO||s.handle(t);this.trigger("command-dispatched",t)}drawLayer(e,t){const o=this.renderers[t];if(o)for(const s of o)e.ctx.save(),s.drawLayer(e,t),e.ctx.restore()}exportData(){let e=aO();for(let t of this.handlers)t instanceof hO&&t.export(e);return e.revisionId=this.session.getRevisionId()||j,e=ue(e),e}updateMode(e){this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...aO(),sheets:[lO(eO,"Sheet1")]};for(let t of this.handlers)t instanceof cO&&t.exportForExcel(e);return e=ue(e),uM(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.PivotRuntimeDefinition=Zw,e.Registry=$n,e.Revision=m_,e.SPREADSHEET_DIMENSIONS=bM,e.Spreadsheet=uD,e.SpreadsheetPivotTable=Xw,e.UIPlugin=vO,e.__info__=fM,e.addFunction=function e(t,o){return Mf.add(t,o),{addFunction:(t,o)=>e(t,o)}},e.addRenderingLayer=function(e,t){if(Fo[e])throw new Error(`Layer ${e} already exists`);Fo[e]=t},e.astToFormula=Wr,e.compile=bb,e.compileTokens=vb,e.components=yM,e.constants=wM,e.convertAstNodes=Hr,e.coreTypes=Eo,e.findCellInNewZone=on,e.functionCache=fb,e.helpers=SM,e.hooks=EM,e.invalidateCFEvaluationCommands=So,e.invalidateDependenciesCommands=vo,e.invalidateEvaluationCommands=bo,e.iterateAstNodes=zr,e.links=CM,e.load=tO,e.parse=Ur,e.parseTokens=Br,e.readonlyAllowedCommands=yo,e.registries=vM,e.setDefaultSheetViewSize=function(e){re=e},e.setTranslationMethod=function(e,t=(()=>!0)){co=e,ho=t},e.stores=xM,e.tokenColors=ab,e.tokenize=Xn,fM.version="17.3.6",fM.date="2024-07-02T09:04:06.235Z",fM.hash="979c0b1"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
@@ -1,9 +1,9 @@
1
1
  <!--
2
2
  This file is generated by o-spreadsheet build tools. Do not edit it.
3
3
  @see https://github.com/odoo/o-spreadsheet
4
- @version 17.3.5
5
- @date 2024-06-26T11:06:35.975Z
6
- @hash 54eb151
4
+ @version 17.3.6
5
+ @date 2024-07-02T09:04:52.264Z
6
+ @hash 979c0b1
7
7
  -->
8
8
  <odoo>
9
9
  <t t-name="o-spreadsheet-ActionButton">
@@ -272,7 +272,8 @@
272
272
  t-att-class="{'o-sheet-name-editable': state.isEditing }"
273
273
  t-ref="sheetNameSpan"
274
274
  t-esc="sheetName"
275
- t-on-click="(ev) => this.onClickSheetName(ev)"
275
+ t-on-click="(ev) => this.onMouseEventSheetName(ev)"
276
+ t-on-pointerdown="(ev) => this.onMouseEventSheetName(ev)"
276
277
  t-on-dblclick="() => this.onDblClick()"
277
278
  t-on-focusout="() => this.onFocusOut()"
278
279
  t-on-keydown="(ev) => this.onKeyDown(ev)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odoo/o-spreadsheet",
3
- "version": "17.3.5",
3
+ "version": "17.3.6",
4
4
  "description": "A spreadsheet component",
5
5
  "type": "module",
6
6
  "main": "dist/o-spreadsheet.cjs.js",