@odoo/o-spreadsheet 15.0.23 → 15.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var i=s(t);let o=e=>e;function n(e,...t){if(1===t.length&&"object"==typeof t[0]){const s=t[0];e=e.replace(/\%\(?([^\)]+)\)s/g,((e,t)=>s[t]))}else t.length>0&&(e=e.replace(/\%s/g,(()=>t.shift())));return e}const r=function(e,...t){return n(o(e),...t)},a=function(e,...t){return{toString:function(){return n(o(e),...t)}}},l="#f5f5f5",c="#F8F9FA",h="#E8EAED",d="#595959",u="#666666",p="#3266ca",g="#FFFFFF",f=26,m=48,v=63,E=96,b=23,S=15,C=14,I=4,y=200,w=1,T="400",x=10,R="'Roboto', arial",L=["thin","#000"],M="#00f",A=/[ymd:]/,_="#REF",O="START_REVISION",N=a("Invalid expression"),k=/'|\*|\?|\/|\\|\[|\]/,F=void 0,$="|";class D{constructor(e,t,s,i=0,o=0,n=0){this.jsDate=new Date(Date.UTC(e,t,s,i,o,n,0))}static fromTimestamp(e){const t=new Date(e);return new D(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds())}static now(){const e=new Date;return new D(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())}toString(){return this.jsDate.toString()}getTime(){return this.jsDate.getTime()}getFullYear(){return this.jsDate.getUTCFullYear()}getMonth(){return this.jsDate.getUTCMonth()}getDate(){return this.jsDate.getUTCDate()}getDay(){return this.jsDate.getUTCDay()}getHours(){return this.jsDate.getUTCHours()}getMinutes(){return this.jsDate.getUTCMinutes()}getSeconds(){return this.jsDate.getUTCSeconds()}setDate(e){this.jsDate.setUTCDate(e)}setHours(e){this.jsDate.setUTCHours(e)}setMinutes(e){this.jsDate.setUTCMinutes(e)}setSeconds(e){this.jsDate.setUTCSeconds(e)}}const U=2e3,P=D.now().getFullYear(),B=new D(1899,11,30),V=D.fromTimestamp(0).getTime()-B.getTime(),H=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,z=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,Z=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function G(e){let t;const s=(e=e.trim()).match(Z);if(s){if(t=function(e){if(e=e.trim(),Z.test(e)){const t=/AM/i.test(e),s=/PM/i.test(e),i=(t||s?e.substring(0,e.length-2).trim():e).split(/:/),o=i.length>=2,n=3===i.length;let r=Number(i[0]),a=o?Number(i[1]):0,l=n?Number(i[2]):0,c=n?"hh:mm:ss":"hh:mm";if(t||s)c+=" a";else if(!o)return null;r>=12&&t?r-=12:r<12&&s&&(r+=12),a+=Math.floor(l/60),l%=60,r+=Math.floor(a/60),a%=60,r>=24&&(c="hhhh:mm:ss");return{value:r/24+a/1440+l/86400,format:c,jsDate:new D(1899,11,30,r,a,l)}}return null}(s[0]),null===t)return null;e=e.replace(s[0],"").trim()}let i;const o=e.match(H),n=e.match(z);if(o||n){let t;if(o?(t=o[0],i=W(t,"mdy")):(t=n[0],i=W(t,"ymd")),null===i)return null;e=e.replace(t,"").trim()}return""!==e||!i&&!t?null:i&&t?{value:i.value+t.value,format:i.format+" "+("hhhh:mm:ss"===t.format?"hh:mm:ss":t.format),jsDate:new D(i.jsDate.getFullYear()+t.jsDate.getFullYear()-1899,i.jsDate.getMonth()+t.jsDate.getMonth()-11,i.jsDate.getDate()+t.jsDate.getDate()-30,i.jsDate.getHours()+t.jsDate.getHours(),i.jsDate.getMinutes()+t.jsDate.getMinutes(),i.jsDate.getSeconds()+t.jsDate.getSeconds())}:i||t}function W(e,t){const s="mdy"===t;if(s||"ymd"===t){const t=e.split(/\/|-|\s/),i=s?0:1,o=s?1:2,n=s?2:0,r=Number(t[i]),a=Number(t[o]),l=2===t[i].length&&r<10||2===t[o].length&&a<10,c=t[n]?function(e){const t=Number(e);switch(e.length){case 1:return U+t;case 2:return U+(U+t>P+10?-100:0)+t;case 3:case 4:return t}return 0}(t[n]):P,h=new D(c,r-1,a),d=e.match(/\/|-|\s/)[0];if(h.getMonth()!==r-1||h.getDate()!==a)return null;const u=h.getTime()-B.getTime();let p=l?`mm${d}dd`:`m${d}d`;return t[n]&&(p=s?p+d+"yyyy":"yyyy"+d+p),{value:Math.round(u/864e5),format:p,jsDate:h}}return null}function q(e){const t=Math.trunc(e);let s=D.fromTimestamp(86400*t*1e3-V),i=e-t;i=i<0?1+i:i;const o=Math.round(24*i),n=Math.round(24*(i-o/24)*60),r=Math.round(24*(i-o/24-n/24/60)*60*60);return s.setHours(o),s.setMinutes(n),s.setSeconds(r),s}function j(e){const t=e.format,s=e.jsDate||q(e.value),i=t.indexOf("h");let o="",n="";return i>0?(o=Y(s,t.substring(0,i-1)),n=X(s,t.substring(i))):0===i?n=X(s,t):i<0&&(o=Y(s,t)),o+(o&&n?" ":"")+n}function Y(e,t){const s=t.match(/\/|-|\s/)[0];return t.split(s).map((s=>{switch(s){case"d":return e.getDate();case"dd":return e.getDate().toString().padStart(2,"0");case"m":return e.getMonth()+1;case"mm":return String(e.getMonth()+1).padStart(2,"0");case"yyyy":return e.getFullYear();default:throw new Error(`invalid format: ${t}`)}})).join(s)}function X(e,t){let s=t.split(/:|\s/);const i=e.getHours(),o="a"===s[s.length-1];let n=i,r="";return o&&(n=0===n?12:n>12?n-12:n,r=i>=12?" PM":" AM",s.pop()),s.map((s=>{switch(s){case"hhhh":return Math.floor((e.getTime()-B.getTime())/36e5).toString();case"hh":return n.toString().padStart(2,"0");case"mm":return e.getMinutes().toString().padStart(2,"0");case"ss":return e.getSeconds().toString().padStart(2,"0");default:throw new Error(`invalid format: ${t}`)}})).join(":")+r}const K=/(^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?)(?!\w|!)/,Q=/^-?\d+(,\d+)*(\.?\d*(e\d+)?)?(\s*%)?$|^-?\.\d+(\s*%)?$/;function J(e){return Q.test(e.trim())}const ee=/,/g;function te(e){let t=Number(e.replace(ee,""));return isNaN(t)&&e.includes("%")&&(t=Number(e.split("%")[0]),!isNaN(t))?t/100:t}const se=new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:10});function ie(e){return Number.isInteger(e)?e.toString():se.format(e)}let oe=[];const ne=20;function re(e,t,s=""){if(e<0)return"-"+re(-e,t);const i=t>=ne?ne:t;let o=oe[i];o||(o=new Intl.NumberFormat("en-US",{minimumFractionDigits:i,maximumFractionDigits:i,useGrouping:!1}),oe[i]=o);let n=o.format(e);if(s){let e=n.indexOf(".");n=n.replace(/\d(?=(?:\d{3})+(?:\.|$))/g,((t,i)=>e<0||i<e?`${t}${s}`:t))}return n}function ae(e,t){const s=t.split("."),i=1===s.length?0:s[1].match(/0/g).length,o=s[0].includes(",")?",":"",n=t.includes("%");n&&(e*=100);const r=re(e,i,o);return n?r+"%":r}function le(e,t){if(!e())throw new Error(t)}const ce=e=>a("The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.",e);function he(e){switch(typeof e){case"number":return e;case"boolean":return e?1:0;case"string":if(J(e)||""===e)return te(e);const t=G(e);if(t)return t.value;throw new Error(ce(e));default:return 0}}function de(e){if(""===e)throw new Error(ce(e));return he(e)}function ue(e){switch(typeof e){case"string":return e;case"number":return e.toString();case"boolean":return e?"TRUE":"FALSE";default:return""}}const pe=e=>a("The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a number.",e);function ge(e){switch(typeof e){case"boolean":return e;case"string":if(e){let t=e.toUpperCase();if("TRUE"===t)return!0;if("FALSE"===t)return!1;throw new Error(pe(e))}return!1;case"number":return!!e;default:return!1}}function fe(e){return q(he(e))}function me(e,t,s){for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let o=0;o<s;o++)for(let s=0;s<e;s++)t(i[s][o])}else s(i)}function ve(e,t){me(e,t,t)}function Ee(e,t){me(e,(e=>{"number"==typeof e&&t(e)}),(e=>{t(de(e))}))}function be(e,t,s,i){let o=i;for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let n=0;n<s;n++)for(let s=0;s<e;s++)o=t(o,i[s][n])}else o=s(o,i);return o}function Se(e,t,s){return be(e,t,t,s)}function Ce(e,t,s){return be(e,((e,s)=>"number"==typeof s?t(e,s):e),((e,s)=>t(e,de(s))),s)}function Ie(e,t,s){return be(e,((e,s)=>null!=s?t(e,"number"==typeof s?s:"boolean"==typeof s?he(s):0):e),((e,s)=>t(e,he(s))),s)}function ye(e,t){return function(e,t,s){for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let o=0;o<s;o++)for(let s=0;s<e;s++)if(!t(i[s][o]))return}else if(!s(i))return}(e,(e=>"boolean"==typeof e?t(e):"number"!=typeof e||t(!!e)),(e=>null==e||t(function(e){if(""===e)throw new Error(pe(e));return ge(e)}(e))))}function we(e,t){let s,i,o=e.substring(0,2);"<="===o||">="===o||"<>"===o?(s=o,i=e.substring(2)):(o=e.substring(0,1),"<"===o||">"===o||"="===o?(s=o,i=e.substring(1)):(s="=",i=e)),J(i)?i=he(i):"TRUE"!==i&&"FALSE"!==i||(i=ge(i));const n={operator:s,operand:i};return"string"==typeof i&&(t&&(i+="*"),n.regexp=function(e){let t="",s="";for(let i of e)"?"===i&&"~"!==s?t+=".":"*"===i&&"~"!==s?t+=".*":("*"!==i&&"?"!==i||(t=t.slice(0,-1)),["^",".","[","]","$","(",")","*","+","?","|","{","}","\\"].includes(i)&&(t+="\\"),t+=i),s=i;return new RegExp("^"+t+"$","i")}(i)),n}function Te(e,t){const{operator:s,operand:i}=t;if(void 0===e||void 0===i)return!1;if("number"==typeof i&&"="===s)return ue(e)===ue(i);if("<>"===s||"="===s){let o;return o=typeof e==typeof i&&("string"==typeof e&&t.regexp?t.regexp.test(e):e===i),"="===s?o:!o}if(typeof e==typeof i)switch(s){case"<":return e<i;case">":return e>i;case"<=":return e<=i;case">=":return e>=i}return!1}function xe(e,t,s=!1){const i=e.length;if(i%2==1)throw new Error(a("Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs."));const o=e[0].length,n=e[0][0].length;let r=[];for(let t=0;t<i-1;t+=2){const i=e[t];if(!Array.isArray(i)||i.length!==o||i[0].length!==n)throw new Error(a("Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension"));const l=ue(e[t+1]);r.push(we(l,s))}for(let s=0;s<o;s++)for(let o=0;o<n;o++){let n=!0;for(let t=0;t<i-1;t+=2){if(n=Te(e[t][s][o],r[t/2]),!n)break}n&&t(s,o)}}function Re(e,t){if(void 0===t)return-1;const s=typeof t;let i,o,n,r,a,l,c=0,h=e.length-1;if(typeof e[c]===s&&t<e[c])return-1;if(typeof e[h]===s&&e[h]<=t)return h;for(;h-c>=0;){for(n=Math.ceil((c+h)/2),r=n,a=e[r],l=typeof a;c<=r&&s!==l;)r--,a=e[r],l=typeof a;l===s&&a<=t&&(void 0===i||i<a||i===a&&o<r)&&(i=a,o=r),l===s&&a>t?h=r-1:c=n+1}return void 0!==o?o:-1}class Le{constructor(){this.content={}}add(e,t){return this.content[e]=t,this}get(e){const t=this.content[e];if(!t&&!(e in this.content))throw new Error(`Cannot find ${e} in this registry!`);return t}contains(e){return e in this.content}getAll(){return Object.values(this.content)}remove(e){delete this.content[e]}}const Me=/(.*?)\((.*?)\)(.*)/,Ae=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>","META"];function _e(e){let t=e.split("\n");const s=[];for(let e of t)e=e.trim(),e&&s.push(Oe(e));return s}function Oe(e){let t,s=e.match(Me),i=s[1].trim(),o=[],n=!1,r=!1,a=!1;for(let e of s[2].split(",")){const s=e.trim().toUpperCase();let i=Ae.find((e=>s===e));i?o.push(i):"RANGE<ANY>"===s?o.push("RANGE"):"OPTIONAL"===s?n=!0:"REPEATING"===s?r=!0:"LAZY"===s?a=!0:s.startsWith("DEFAULT=")&&(t=e.trim().slice(8))}const l={name:i,description:s[3].trim(),type:o};return n&&(l.optional=!0),r&&(l.repeating=!0),a&&(l.lazy=!0),void 0!==t&&(l.default=!0,l.defaultValue=t),l}function Ne(e){let t=0,s=0,i=0;for(let o of e.args)t++,o.optional||o.repeating||o.default||s++,o.repeating&&i++;const o=e;return o.minArgRequired=s,o.maxArgPossible=i?1/0:t,o.nbrArgRepeating=i,o.getArgToFocus=function(e,t){if(!t)return e=>e;if(1===t)return t=>Math.min(t,e);const s=e-t;return e=>{if(e<=s)return e;return s+((e-s)%t||t)}}(t,i),o}var ke;!function(e){e.boolean="boolean",e.number="number",e.text="text",e.empty="empty",e.error="error"}(ke||(ke={}));const Fe=new Set(["RENAME_SHEET","DELETE_SHEET","CREATE_SHEET","ADD_COLUMNS_ROWS","REMOVE_COLUMNS_ROWS","DELETE_CELL","INSERT_CELL","UNDO","REDO"]),$e=new Set(["START","ACTIVATE_SHEET","COPY","START_SELECTION","SET_SELECTION","ALTER_SELECTION","START_SELECTION_EXPANSION","PREPARE_SELECTION_EXPANSION","STOP_SELECTION","RESIZE_VIEWPORT","SET_VIEWPORT_OFFSET","SELECT_ALL","SELECT_CELL","SELECT_COLUMN","SELECT_ROW","MOVE_POSITION","SELECT_SEARCH_NEXT_MATCH","SELECT_SEARCH_PREVIOUS_MATCH","REFRESH_SEARCH","UPDATE_SEARCH","CLEAR_SEARCH","EVALUATE_CELLS","SET_CURRENT_CONTENT","SET_FORMULA_VISIBILITY"]),De=new Set(["UPDATE_CELL","UPDATE_CELL_POSITION","CLEAR_CELL","DELETE_CONTENT","ADD_COLUMNS_ROWS","REMOVE_COLUMNS_ROWS","RESIZE_COLUMNS_ROWS","HIDE_COLUMNS_ROWS","UNHIDE_COLUMNS_ROWS","SET_GRID_LINES_VISIBILITY","ADD_MERGE","REMOVE_MERGE","CREATE_SHEET","DELETE_SHEET","DUPLICATE_SHEET","MOVE_SHEET","RENAME_SHEET","ADD_CONDITIONAL_FORMAT","REMOVE_CONDITIONAL_FORMAT","CREATE_FIGURE","DELETE_FIGURE","UPDATE_FIGURE","SET_FORMATTING","CLEAR_FORMATTING","SET_BORDER","CREATE_CHART","UPDATE_CHART"]);function Ue(e){return De.has(e.type)}class Pe{constructor(e=[]){Array.isArray(e)||(e=[e]),e=[...new Set(e)],this.reasons=e.filter((e=>0!==e))}static get Success(){return new Pe}get isSuccessful(){return 0===this.reasons.length}isCancelledBecause(e){return this.reasons.includes(e)}}var Be,Ve,He,ze;e.CommandResult=void 0,(Be=e.CommandResult||(e.CommandResult={}))[Be.Success=0]="Success",Be[Be.CancelledForUnknownReason=1]="CancelledForUnknownReason",Be[Be.WillRemoveExistingMerge=2]="WillRemoveExistingMerge",Be[Be.MergeIsDestructive=3]="MergeIsDestructive",Be[Be.CellIsMerged=4]="CellIsMerged",Be[Be.InvalidTarget=5]="InvalidTarget",Be[Be.EmptyUndoStack=6]="EmptyUndoStack",Be[Be.EmptyRedoStack=7]="EmptyRedoStack",Be[Be.NotEnoughElements=8]="NotEnoughElements",Be[Be.NotEnoughSheets=9]="NotEnoughSheets",Be[Be.MissingSheetName=10]="MissingSheetName",Be[Be.DuplicatedSheetName=11]="DuplicatedSheetName",Be[Be.DuplicatedSheetId=12]="DuplicatedSheetId",Be[Be.ForbiddenCharactersInSheetName=13]="ForbiddenCharactersInSheetName",Be[Be.WrongSheetMove=14]="WrongSheetMove",Be[Be.WrongSheetPosition=15]="WrongSheetPosition",Be[Be.InvalidAnchorZone=16]="InvalidAnchorZone",Be[Be.SelectionOutOfBound=17]="SelectionOutOfBound",Be[Be.TargetOutOfSheet=18]="TargetOutOfSheet",Be[Be.WrongPasteSelection=19]="WrongPasteSelection",Be[Be.EmptyClipboard=20]="EmptyClipboard",Be[Be.EmptyRange=21]="EmptyRange",Be[Be.InvalidRange=22]="InvalidRange",Be[Be.InvalidSheetId=23]="InvalidSheetId",Be[Be.InputAlreadyFocused=24]="InputAlreadyFocused",Be[Be.MaximumRangesReached=25]="MaximumRangesReached",Be[Be.InvalidChartDefinition=26]="InvalidChartDefinition",Be[Be.EmptyDataSet=27]="EmptyDataSet",Be[Be.InvalidDataSet=28]="InvalidDataSet",Be[Be.InvalidLabelRange=29]="InvalidLabelRange",Be[Be.InvalidAutofillSelection=30]="InvalidAutofillSelection",Be[Be.WrongComposerSelection=31]="WrongComposerSelection",Be[Be.MinBiggerThanMax=32]="MinBiggerThanMax",Be[Be.LowerBiggerThanUpper=33]="LowerBiggerThanUpper",Be[Be.MidBiggerThanMax=34]="MidBiggerThanMax",Be[Be.MinBiggerThanMid=35]="MinBiggerThanMid",Be[Be.FirstArgMissing=36]="FirstArgMissing",Be[Be.SecondArgMissing=37]="SecondArgMissing",Be[Be.MinNaN=38]="MinNaN",Be[Be.MidNaN=39]="MidNaN",Be[Be.MaxNaN=40]="MaxNaN",Be[Be.ValueUpperInflectionNaN=41]="ValueUpperInflectionNaN",Be[Be.ValueLowerInflectionNaN=42]="ValueLowerInflectionNaN",Be[Be.MinInvalidFormula=43]="MinInvalidFormula",Be[Be.MidInvalidFormula=44]="MidInvalidFormula",Be[Be.MaxInvalidFormula=45]="MaxInvalidFormula",Be[Be.ValueUpperInvalidFormula=46]="ValueUpperInvalidFormula",Be[Be.ValueLowerInvalidFormula=47]="ValueLowerInvalidFormula",Be[Be.InvalidSortZone=48]="InvalidSortZone",Be[Be.WaitingSessionConfirmation=49]="WaitingSessionConfirmation",Be[Be.MergeOverlap=50]="MergeOverlap",Be[Be.TooManyHiddenElements=51]="TooManyHiddenElements",Be[Be.Readonly=52]="Readonly",Be[Be.InvalidOffset=53]="InvalidOffset",Be[Be.InvalidViewportSize=54]="InvalidViewportSize",Be[Be.FigureDoesNotExist=55]="FigureDoesNotExist",Be[Be.DuplicatedFigureId=56]="DuplicatedFigureId",Be[Be.DuplicatedChartId=57]="DuplicatedChartId",Be[Be.ChartDoesNotExist=58]="ChartDoesNotExist",function(e){e.FormatFromArgument="FormatFromArgument"}(Ve||(Ve={})),function(e){e[e.UP=0]="UP",e[e.DOWN=1]="DOWN",e[e.LEFT=2]="LEFT",e[e.RIGHT=3]="RIGHT"}(He||(He={})),function(e){e[e.Background=0]="Background",e[e.Highlights=1]="Highlights",e[e.Clipboard=2]="Clipboard",e[e.Search=3]="Search",e[e.Chart=4]="Chart",e[e.Selection=5]="Selection",e[e.Autofill=6]="Autofill",e[e.Headers=7]="Headers"}(ze||(ze={}));const Ze={description:a("Absolute value of a number."),args:_e(`\n value (number) ${a("The number of which to return the absolute value.")}\n `),returns:["NUMBER"],compute:function(e){return Math.abs(he(e))},isExported:!0},Ge={description:a("Inverse cosine of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<=1),a("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.acos(t)},isExported:!0},We={description:a("Inverse hyperbolic cosine of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic cosine. Must be greater than or equal to 1.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>t>=1),a("The value (%s) must be greater than or equal to 1.",t.toString())),Math.acosh(t)},isExported:!0},qe={description:a("Inverse cotangent of a value."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse cotangent.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)},isExported:!0},je={description:a("Inverse hyperbolic cotangent of a value."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic cotangent. Must not be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)>1),a("The value (%s) cannot be between -1 and 1 inclusive.",t.toString())),Math.log((t+1)/(t-1))/2},isExported:!0},Ye={description:a("Inverse sine of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<=1),a("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.asin(t)},isExported:!0},Xe={description:a("Inverse hyperbolic sine of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic sine.")}\n `),returns:["NUMBER"],compute:function(e){return Math.asinh(he(e))},isExported:!0},Ke={description:a("Inverse tangent of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse tangent.")}\n `),returns:["NUMBER"],compute:function(e){return Math.atan(he(e))},isExported:!0},Qe={description:a("Angle from the X axis to a point (x,y), in radians."),args:_e(`\n x (number) ${a("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n y (number) ${a("The y coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n `),returns:["NUMBER"],compute:function(e,t){const s=he(e),i=he(t);return le((()=>0!==s||0!==i),a("Function [[FUNCTION_NAME]] caused a divide by zero error.")),Math.atan2(i,s)},isExported:!0},Je={description:a("Inverse hyperbolic tangent of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic tangent. Must be between -1 and 1, exclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<1),a("The value (%s) must be between -1 and 1 exclusive.",t.toString())),Math.atanh(t)},isExported:!0},et={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n value (number) ${a("The value to round up to the nearest integer multiple of factor.")}\n factor (number, default=1) ${a("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){const s=he(e),i=he(t);return le((()=>i>=0||s<=0),a("The factor (%s) must be positive when the value (%s) is positive.",i.toString(),s.toString())),i?Math.ceil(s/i)*i:0},isExported:!0},tt={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, default=0) ${a("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded towards zero. Otherwise, it is rounded away from zero.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1,s=0){let i=he(t);if(0===i)return 0;const o=he(e);if(i=Math.abs(i),o>=0)return Math.ceil(o/i)*i;return 0===he(s)?-Math.floor(Math.abs(o)/i)*i:-Math.ceil(Math.abs(o)/i)*i},isExported:!0},st={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return tt.compute(e,t,0)},isExported:!0},it={description:a("Cosine of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cosine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cos(he(e))},isExported:!0},ot={description:a("Hyperbolic cosine of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cosine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cosh(he(e))},isExported:!0},nt={description:a("Cotangent of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cotangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.tan(t)},isExported:!0},rt={description:a("Hyperbolic cotangent of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cotangent of.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.tanh(t)},isExported:!0},at={description:a("Number of empty values."),args:_e(`\n value1 (any, range) ${a("The first value or range in which to count the number of blanks.")}\n value2 (any, range, repeating) ${a("Additional values or ranges in which to count the number of blanks.")}\n `),returns:["NUMBER"],compute:function(...e){return Se(e,((e,t)=>null==t||""===t?e+1:e),0)},isExported:!0},lt={description:a("A conditional count across a range."),args:_e(`\n range (range) ${a("The range that is tested against criterion.")}\n criterion (string) ${a("The pattern or test to apply to range.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;return xe(e,((e,s)=>{t+=1})),t},isExported:!0},ct={description:a("Count values depending on multiple criteria."),args:_e(`\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("Additional criteria to check.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;return xe(e,((e,s)=>{t+=1})),t},isExported:!0};function ht(e){switch(e){case void 0:case"":case null:return!1;default:return!0}}const dt={description:a("Counts number of unique values in a range."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider for uniqueness.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider for uniqueness.")}\n `),returns:["NUMBER"],compute:function(...e){return Se(e,((e,t)=>ht(t)?e.add(t):e),new Set).size}},ut={description:a("Counts number of unique values in a range, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the number of unique values will be counted.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=new Set;return xe(t,((t,i)=>{const o=e[t][i];ht(o)&&s.add(o)})),s.size}},pt={description:a("Cosecant of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cosecant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.sin(t)},isExported:!0},gt={description:a("Hyperbolic cosecant of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cosecant of.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.sinh(t)},isExported:!0},ft={description:a("Converts from another base to decimal."),args:_e(`\n value (string) ${a("The number to convert.")},\n base (number) ${a("The base to convert the value from.")},\n `),returns:["NUMBER"],compute:function(e,t){let s=he(t);s=Math.floor(s),le((()=>2<=s&&s<=36),a("The base (%s) must be between 2 and 36 inclusive.",s.toString()));const i=ue(e);if(""===i)return 0;le((()=>!!i.match(/^-?[a-z0-9]+$/i)),a("The value (%s) must be a valid base %s representation.",i,s.toString()));const o=parseInt(i,s);return le((()=>!isNaN(o)),a("The value (%s) must be a valid base %s representation.",i,s.toString())),o},isExported:!0},mt={description:a("Converts an angle value in radians to degrees."),args:_e(`\n angle (number) ${a("The angle to convert from radians to degrees.")}\n `),returns:["NUMBER"],compute:function(e){return 180*he(e)/Math.PI},isExported:!0},vt={description:a("Euler's number, e (~2.718) raised to a power."),args:_e(`\n value (number) ${a("The exponent to raise e.")}\n `),returns:["NUMBER"],compute:function(e){return Math.exp(he(e))},isExported:!0},Et={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n value (number) ${a("The value to round down to the nearest integer multiple of factor.")}\n factor (number, default=1) ${a("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){const s=he(e),i=he(t);return le((()=>i>=0||s<=0),a("The factor (%s) must be positive when the value (%s) is positive.",i.toString(),s.toString())),i?Math.floor(s/i)*i:0},isExported:!0},bt={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round down to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, default=0) ${a("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded away from zero. Otherwise, it is rounded towards zero.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1,s=0){let i=he(t);if(0===i)return 0;const o=he(e);if(i=Math.abs(i),o>=0)return Math.floor(o/i)*i;return 0===he(s)?-Math.ceil(Math.abs(o)/i)*i:-Math.floor(Math.abs(o)/i)*i},isExported:!0},St={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round down to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){return bt.compute(e,t,0)},isExported:!0},Ct={description:a("Whether the provided value is even."),args:_e(`\n value (number) ${a("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=de(e);return!(1&Math.floor(Math.abs(t)))},isExported:!0},It={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){return tt.compute(e,t,0)},isExported:!0},yt={description:a("Whether the provided value is even."),args:_e(`\n value (number) ${a("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=de(e);return!!(1&Math.floor(Math.abs(t)))},isExported:!0},wt={description:a("The logarithm of a number, base e (euler's number)."),args:_e(`\n value (number) ${a("The value for which to calculate the logarithm, base e.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>t>0),a("The value (%s) must be strictly positive.",t.toString())),Math.log(t)},isExported:!0},Tt={description:a("Modulo (remainder) operator."),args:_e(`\n dividend (number) ${a("The number to be divided to find the remainder.")}\n divisor (number) ${a("The number to divide by.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(t);le((()=>0!==s),a("The divisor must be different from 0."));const i=he(e)%s;return i>0&&s<0||i<0&&s>0?i+s:i},isExported:!0},xt={description:a("Rounds a number up to the nearest odd integer."),args:_e(`\n value (number) ${a("The value to round to the next greatest odd number.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e){const t=he(e);let s=Math.ceil(Math.abs(t));return s=1&s?s:s+1,t<0?-s:s},isExported:!0},Rt={description:a("The number pi."),args:[],returns:["NUMBER"],compute:function(){return Math.PI},isExported:!0},Lt={description:a("A number raised to a power."),args:_e(`\n base (number) ${a("The number to raise to the exponent power.")}\n exponent (number) ${a("The exponent to raise base to.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(e),i=he(t);return le((()=>s>=0||Number.isInteger(i)),a("The exponent (%s) must be an integer when the base is negative.",i.toString())),Math.pow(s,i)},isExported:!0},Mt={description:a("Result of multiplying a series of numbers together."),args:_e(`\n factor1 (number, range<number>) ${a("The first number or range to calculate for the product.")}\n factor2 (number, range<number>, repeating) ${a("More numbers or ranges to calculate for the product.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0,s=1;for(let i of e)if(Array.isArray(i))for(let e of i)for(let i of e)"number"==typeof i&&(s*=i,t+=1);else null!=i&&(s*=de(i),t+=1);return 0===t?0:s},isExported:!0},At={description:a("A random number between 0 inclusive and 1 exclusive."),args:[],returns:["NUMBER"],compute:function(){return Math.random()},isExported:!0},_t={description:a("Random integer between two values, inclusive."),args:_e(`\n low (number) ${a("The low end of the random range.")}\n high (number) ${a("The high end of the random range.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){let s=he(e);Number.isInteger(s)||(s=Math.ceil(s));let i=he(t);return Number.isInteger(i)||(i=Math.floor(i)),le((()=>s<=i),a("The high (%s) must be greater than or equal to the low (%s).",i.toString(),s.toString())),s+Math.ceil((i-s+1)*Math.random())-1},isExported:!0},Ot={description:a("Rounds a number according to standard rules."),args:_e(`\n value (number) ${a("The value to round to places number of places.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.round(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.round(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},Nt={description:a("Rounds down a number."),args:_e(`\n value (number) ${a("The value to round to places number of places, always rounding down.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.floor(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.floor(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},kt={description:a("Rounds up a number."),args:_e(`\n value (number) ${a("The value to round to places number of places, always rounding up.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.ceil(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.ceil(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},Ft={description:a("Secant of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the secant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cos(he(e))},isExported:!0},$t={description:a("Hyperbolic secant of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic secant of.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cosh(he(e))},isExported:!0},Dt={description:a("Sine of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the sine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sin(he(e))},isExported:!0},Ut={description:a("Hyperbolic sine of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic sine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sinh(he(e))},isExported:!0},Pt={description:a("Positive square root of a positive number."),args:_e(`\n value (number) ${a("The number for which to calculate the positive square root.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e){const t=he(e);return le((()=>t>=0),a("The value (%s) must be positive or null.",t.toString())),Math.sqrt(t)},isExported:!0},Bt={description:a("Sum of a series of numbers and/or cells."),args:_e(`\n value1 (number, range<number>) ${a("The first number or range to add together.")}\n value2 (number, range<number>, repeating) ${a("Additional numbers or ranges to add to value1.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){return Ce(e,((e,t)=>e+t),0)},isExported:!0},Vt={description:a("A conditional sum across a range."),args:_e(`\n criteria_range (range) ${a("The range which is tested against criterion.")}\n criterion (string) ${a("The pattern or test to apply to range.")}\n sum_range (range, default=criteria_range) ${a("The range to be summed, if different from range.")}\n `),returns:["NUMBER"],compute:function(e,t,s){void 0===s&&(s=e);let i=0;return xe([e,t],((e,t)=>{const o=s[e][t];"number"==typeof o&&(i+=o)})),i},isExported:!0},Ht={description:a("Sums a range depending on multiple criteria."),args:_e(`\n sum_range (range) ${a("The range to sum.")}\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges to check.")}\n criterion2 (string, repeating) ${a("Additional criteria to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s+=o)})),s},isExported:!0},zt={description:a("Tangent of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the tangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tan(he(e))},isExported:!0},Zt={description:a("Hyperbolic tangent of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic tangent of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tanh(he(e))},isExported:!0},Gt={description:a("Truncates a number."),args:_e(`\n value (number) ${a("The value to be truncated.")}\n places (number, default=0) ${a("The number of significant digits to the right of the decimal point to retain.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);return 0===i?Math.trunc(s):(Number.isInteger(i)||(i=Math.trunc(i)),Math.trunc(s*Math.pow(10,i))/Math.pow(10,i))},isExported:!0};var Wt=Object.freeze({__proto__:null,ABS:Ze,ACOS:Ge,ACOSH:We,ACOT:qe,ACOTH:je,ASIN:Ye,ASINH:Xe,ATAN:Ke,ATAN2:Qe,ATANH:Je,CEILING:et,CEILING_MATH:tt,CEILING_PRECISE:st,COS:it,COSH:ot,COT:nt,COTH:rt,COUNTBLANK:at,COUNTIF:lt,COUNTIFS:ct,COUNTUNIQUE:dt,COUNTUNIQUEIFS:ut,CSC:pt,CSCH:gt,DECIMAL:ft,DEGREES:mt,EXP:vt,FLOOR:Et,FLOOR_MATH:bt,FLOOR_PRECISE:St,ISEVEN:Ct,ISO_CEILING:It,ISODD:yt,LN:wt,MOD:Tt,ODD:xt,PI:Rt,POWER:Lt,PRODUCT:Mt,RAND:At,RANDBETWEEN:_t,ROUND:Ot,ROUNDDOWN:Nt,ROUNDUP:kt,SEC:Ft,SECH:$t,SIN:Dt,SINH:Ut,SQRT:Pt,SUM:Bt,SUMIF:Vt,SUMIFS:Ht,TAN:zt,TANH:Zt,TRUNC:Gt});const qt=["#eb6d00","#0074d9","#ad8e00","#169ed4","#b10dc9","#00a82d","#00a3a3","#f012be","#3d9970","#111111","#62A300","#ff4136","#949494","#85144b","#001f3f"];function jt(e){return e.toString(16).padStart(6,"0")}let Yt=0;function Xt(){return Yt=++Yt%qt.length,qt[Yt]}function Kt(e){return e.includes("rgb")?function(e){return e.slice(4,-1).split(",").map((e=>parseInt(e,10).toString(16).padStart(2,"0"))).join("").toUpperCase()}(e):(3===(e=e.replace("#","").toUpperCase()).length&&(e=e.split("").reduce(((e,t)=>e+t+t),"")),e)}const Qt=new RegExp(/\$?([A-Z]{1,3})\$?([0-9]{1,7})/,"i"),Jt=new RegExp(/^\s*(.*!)?\$?[A-Z]{1,3}\$?[0-9]{1,7}\s*(\s*:\s*\$?[A-Z]{1,3}\$?[0-9]{1,7}\s*)?$/,"i");function es(e){const t=e.split("!"),s=t.pop();return{sheetName:t.join("!")||void 0,xc:s}}function ts(e){return e<26?String.fromCharCode(65+e):ts(Math.floor(e/26)-1)+ts(e%26)}function ss(e){e=e.toUpperCase().trim();const[t,s,i]=e.match(Qt);if(t!==e)throw new Error(`Invalid cell description: ${e}`);const o=function(e){let t=0;const s=e.length;for(let i=0;i<s;i++)t+=(e.charCodeAt(i)-65+(i<s-1?1:0))*26**(s-i-1);return t}(s);return[o,parseInt(i,10)-1]}function is(e,t,s={colFixed:!1,rowFixed:!1}){return(s.colFixed?"$":"")+ts(e)+(s.rowFixed?"$":"")+String(t+1)}const os=140,ns=20,rs=.035;function as(e){return ns+(os-ns)*Math.exp(-rs*(e-1))}const ls=[{pt:7.5,px:10},{pt:8,px:11},{pt:9,px:12},{pt:10,px:13},{pt:10.5,px:14},{pt:11,px:15},{pt:12,px:16},{pt:14,px:18.7},{pt:15,px:20},{pt:16,px:21.3},{pt:18,px:24},{pt:22,px:29.3},{pt:24,px:32},{pt:26,px:34.7},{pt:36,px:48}],cs={};for(let e of ls)cs[e.pt]=e.px;function hs(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ds(e){const t=Array.isArray(e)?[]:{};switch(typeof e){case"object":if(null===e)return e;if(!(function(e){return"object"==typeof e&&(null==e?void 0:e.constructor)===Object}(e)||e instanceof Array))throw new Error("Unsupported type: only objects and arrays are supported");for(const s in e)t[s]=ds(e[s]);return t;case"number":case"string":case"boolean":case"function":case"undefined":return e;default:throw new Error("Unsupported type: "+typeof e)}}function us(e){var t;return(null===(t=e.match(/\w/g))||void 0===t?void 0:t.length)!==e.length&&(e=`'${e}'`),e}function ps(e,t,s){return e<t?t:e>s?s:e}function gs(e,t,s){const i=s.italic?"italic ":"",o=s.bold?"bold":T,n=s.fontSize||x,r=cs[n];return e.font=`${i}${o} ${r}px ${R}`,e.measureText(t).width}function fs(e,t,s=1){if(t<=e&&s>0)return[];if(0===s)throw new Error("range() step must not be zero");const i=Math.ceil(Math.abs((t-e)/s)),o=Array(i);for(let t=0;t<i;t++)o[t]=e+t*s;return o}function ms(e){return e.reduce(((e,t,s,i)=>{if(1===Math.abs(t-i[s-1])){e[e.length-1].push(t)}else e.push([t]);return e}),[])}function*vs(e,t){t.next();for(const s of e){const e=t.next();yield{...s,next:e.done?void 0:e.value}}}function Es(e){const t=e.toUpperCase();return"TRUE"===t||"FALSE"===t}function bs(e){return null!==G(e)}const Ss=/^\[(.+)\]\((.+)\)$/,Cs=/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;function Is(e){return Ss.test(e)}function ys(e,t){return`[${e}](${t})`}function ws(e){const t=e.match(Ss)||[],s=t[1],i=t[2];if(!s||!i)throw new Error(`Could not parse markdown link ${e}.`);return{label:s,url:i}}const Ts="o-spreadsheet://";function xs(e){if(!Is(e))return!1;const{url:t}=ws(e);return t.startsWith(Ts)}function Rs(e){if(e.startsWith(Ts))return e.substr(Ts.length);throw new Error(`${e} is not a valid sheet link`)}function Ls(e){return void 0!==e}const Ms={};function As(e,t){if(e===t)return!0;if(e&&!t||t&&!e)return!1;if(typeof e!=typeof t)return!1;if("object"!=typeof e)return!1;const s=new Set;Object.keys(e).forEach((e=>s.add(e))),Object.keys(t).forEach((e=>s.add(e)));for(let i of s){if(typeof e[i]!=typeof e[i])return!1;if("object"==typeof e[i]){if(!As(e[i],t[i]))return!1}else if(e[i]!==t[i])return!1}return!0}function _s(e){let t=e.length;if(t<1e5)return Math.max(...e);let s=-1/0;for(;t--;)s=e[t]>s?e[t]:s;return s}function Os(e){let t=e.length;if(t<1e5)return Math.min(...e);let s=1/0;for(;t--;)s=e[t]<s?e[t]:s;return s}function Ns(e){const t=(e=e.split("!").pop()).replace(/\$/g,"").split(":");let s,i,o,n,r=ss(t[0].trim());if(o=n=r[0],s=i=r[1],2===t.length){let e=ss(t[1].trim());n=e[0],i=e[1]}return{top:s,bottom:i,left:o,right:n}}function ks(e){let{top:t,bottom:s,left:i,right:o}=Ns(e);return o<i&&([o,i]=[i,o]),s<t&&([s,t]=[t,s]),{top:t,bottom:s,left:i,right:o}}function Fs(e){return!(isNaN(e.bottom)||isNaN(e.top)||isNaN(e.left)||isNaN(e.right))&&(!(e.top<0||e.left<0||e.right<0||e.bottom<0)&&(e.bottom>=e.top&&e.right>=e.left))}function $s(e){const{top:t,bottom:s,left:i,right:o}=e;return t===s&&i===o?is(i,t):`${is(i,t)}:${is(o,s)}`}function Ds(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom";return e[t]<=r&&e[a]>r?Ys(e,n,"RESIZE",o):r<e[t]?Ys(e,n,"MOVE",o):{...e}}function Us(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<r&&e[i]>=r&&n--;return{...e,[t]:o,[i]:n}}function Ps(e,t){return{top:Math.min(e.top,t.top),left:Math.min(e.left,t.left),bottom:Math.max(e.bottom,t.bottom),right:Math.max(e.right,t.right)}}function Bs(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function Vs(e,t){return!(e.bottom<t.top||t.bottom<e.top)&&!(e.right<t.left||t.right<e.left)}function Hs(e,t,s){const{left:i,right:o,top:n,bottom:r}=s;return e>=i&&e<=o&&t>=n&&t<=r}function zs(e,t){const s={};for(let t of e)if(t){const e=ks(t);for(let t=e.left;t<=e.right;t++)void 0===s[t]&&(s[t]=[]),s[t].push({top:e.top,bottom:e.bottom,remove:!1})}for(let e of t){const t=ks(e);for(let e=t.left;e<=t.right;e++)void 0===s[e]&&(s[e]=[]),s[e].push({top:t.top,bottom:t.bottom,remove:!0})}const i=[];for(let[e,t]of Object.entries(s))i.push({col:parseInt(e),ranges:Zs(t)});return function(e){const t=e.sort(((e,t)=>e.col-t.col)),s=[];let i=[],o=0;for(let e=0;e<=t.length-1;e++){let n=[];if(o+1===t[e].col)for(let s of t[e].ranges){let o=!1;for(let e of i)s.top==e.top&&s.bottom==e.bottom&&(n.push(e),o=!0);o||n.push({top:s.top,bottom:s.bottom,startCol:t[e].col})}else n=t[e].ranges.map((s=>({top:s.top,bottom:s.bottom,startCol:t[e].col})));const r=i.filter((e=>!n.includes(e)));for(let e of r)s.push({top:e.top,bottom:e.bottom,left:e.startCol,right:o});o=t[e].col,i=n}for(let e of i)s.push({top:e.top,bottom:e.bottom,left:e.startCol,right:o});return s}(i).map($s)}function Zs(e){const t=new Set,s=new Set;for(let i of e)for(let e=i.top;e<=i.bottom;e++)i.remove?s.add(e):t.add(e);const i=[...t].filter((e=>!s.has(e))).sort(((e,t)=>e-t)),o=[];let n;for(let e of i)n?e===n.bottom+1?n.bottom=e:(o.push({top:n.top,bottom:n.bottom}),n={top:e,bottom:e}):n={top:e,bottom:e};return n&&o.push({top:n.top,bottom:n.bottom}),o}function Gs(e,t,s,i,o=1,n=1){var r;const{top:a,bottom:l,left:c,right:h}=e,d=new Array(Math.floor((h-c+1)/o));for(let e=c;e<=h;e+=o){let o=new Array(Math.floor((l-a+1)/n));d[e-c]=o;for(let c=a;c<=l;c+=n){let l=null===(r=t.rows[c])||void 0===r?void 0:r.cells[e];o[(c-a)/n]=l?s(l):i}}return d}function Ws(e){return{height:e.bottom-e.top+1,width:e.right-e.left+1}}function qs(e){const{width:t,height:s}=Ws(e);return 1===t||1===s}function js(e){const t=[],[s,i]=[e.right,e.left].sort(((e,t)=>e-t)),[o,n]=[e.top,e.bottom].sort(((e,t)=>e-t));for(const e of fs(s,i+1))for(const s of fs(o,n+1))t.push([e,s]);return t}function Ys(e,t,s,i){const o="columns"===t?"right":"bottom",n={...e};return"MOVE"===s&&(n["columns"===t?"left":"top"]+=i),n[o]+=i,n}function Xs(e){return e.reverse().filter(((e,t,s)=>t===s.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}function Ks(e){return{top:Math.min(e.top,e.bottom),bottom:Math.max(e.top,e.bottom),left:Math.min(e.left,e.right),right:Math.max(e.left,e.right)}}function Qs(e){const t=[];let s=0;for(let i=0;i<e;i++){const e={start:s,end:s+E,size:E,name:ts(i)};t.push(e),s=e.end}return t}function Js(e){const t=[];let s=0;for(let i=0;i<e;i++){const e={start:s,end:s+b,size:b,name:String(i+1),cells:{}};t.push(e),s=e.end}return t}function ei(e,t){var s;const i=[];let o=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||E,r=(null===(s=e[n])||void 0===s?void 0:s.isHidden)||!1,a={start:o,end:r?o:o+t,size:t,name:ts(n)};r&&(a.isHidden=r),i.push(a),o=a.end}return i}function ti(e,t){var s;const i=[];let o=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||b,r=(null===(s=e[n])||void 0===s?void 0:s.isHidden)||!1,a={start:o,end:r?o:o+t,size:t,name:String(n+1),cells:{}};r&&(a.isHidden=r),i.push(a),o=a.end}return i}function si(e,t=!1){const s={};for(let i in e){const o=e[i];(o.size!==E||t)&&(s[i]={size:o.size}),o.isHidden&&(s[i]=s[i]||{},s[i].isHidden=o.isHidden)}return s}function ii(e,t=!1){const s={};for(let i in e){const o=e[i];(o.size!==b||t)&&(s[i]={size:o.size}),o.isHidden&&(s[i]=s[i]||{},s[i].isHidden=o.isHidden)}return s}class oi{constructor(e=!1){this.isFastIdStrategy=!1,this.fastIdStart=0,this.setIsFastStrategy(e)}setIsFastStrategy(e){this.isFastIdStrategy=e}uuidv4(){return this.isFastIdStrategy?(this.fastIdStart++,String(this.fastIdStart)):window.crypto&&window.crypto.getRandomValues?([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))):"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))}}function ni(e,t,s){return[ri(e,"cols",fs(t,e.cols.length)),ri(e,"rows",fs(s,e.rows.length))]}function ri(e,t,s){const i=e[t];return s.find((e=>!i[e].isHidden))}function ai(e,t){let s=e[t].length-1;for(;s>=0&&!0===e[t][s].isHidden;)s--;return e[t][s]}function li(e,t,s){let i=[],o=[],n=0,r=0;ve([e],(e=>{i.push(e),n+=1})),ve([t],(e=>{o.push(e),r+=1})),le((()=>n===r),a("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",n.toString(),r.toString()));let l=0,c=0,h=0;for(let e=0;e<n;e++){const t=i[e],s=o[e];"number"==typeof t&&"number"==typeof s&&(l+=1,c+=t,h+=s)}le((()=>0!==l&&(!s||1!==l)),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const d=c/l,u=h/l;let p=0;for(let e=0;e<n;e++){const t=i[e],s=o[e];"number"==typeof t&&"number"==typeof s&&(p+=(t-d)*(s-u))}return p/(l-(s?1:0))}function ci(e,t,s){let i=0,o=0;const n=s?Ie:Ce;o=n(e,((e,t)=>(i+=1,e+t)),0),le((()=>0!==i&&(!t||1!==i)),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const r=o/i;return n(e,((e,t)=>e+Math.pow(t-r,2)),0)/(i-(t?1:0))}function hi(e,t,s){const i=he(t);le((()=>s?0<=i&&i<=1:0<i&&i<1),a("Function [[FUNCTION_NAME]] parameter 2 value is out of range."));let o,n=[],r=0;ve(e,(e=>{"number"==typeof e&&(o=Re(n,e),n.splice(o+1,0,e),r++)})),le((()=>0!==r),a("[[FUNCTION_NAME]] has no valid input data."));let l=(r+(s?-1:1))*i;if(s||(le((()=>1<=l&&l<=r),a("Function [[FUNCTION_NAME]] parameter 2 value is out of range.")),l--),Number.isInteger(l))return n[l];const c=Math.ceil(l),h=Math.floor(l);return n[c]*(l-h)+n[h]*(c-l)}const di={description:a("Average magnitude of deviations from mean."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;const s=Ce(e,((e,s)=>(t+=1,e+s)),0);le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const i=s/t;return Ce(e,((e,t)=>e+Math.abs(i-t)),0)/t},isExported:!0},ui={description:a("Numerical average value in a dataset, ignoring text."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0;const s=Ce(e,((e,s)=>(t+=1,e+s)),0);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),s/t},isExported:!0},pi=a("[[FUNCTION_NAME]] has mismatched range sizes."),gi=a("[[FUNCTION_NAME]] expects the weight to be positive or equal to 0."),fi={description:a("Weighted average."),args:_e(`\n values (number, range<number>) ${a("Values to average.")}\n weights (number, range<number>) ${a("Weights for each corresponding value.")}\n additional_values (number, range<number>, repeating) ${a("Additional values to average.")}\n additional_weights (number, range<number>, repeating) ${a("Additional weights.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t,s,i=0,o=0;le((()=>e.length%2==0),a("Wrong number of Argument[]. Expected an even number of Argument[]."));for(let n=0;n<e.length-1;n+=2)if(t=e[n],s=e[n+1],Array.isArray(t)){le((()=>Array.isArray(s)),pi);let e=t.length,n=t[0].length;le((()=>e===s.length&&n===s[0].length),pi);for(let r=0;r<e;r++)for(let e=0;e<n;e++){let n=t[r][e],l=s[r][e],c="number"==typeof n,h="number"==typeof l;le((()=>c===h),a("[[FUNCTION_NAME]] expects number values.")),h&&(le((()=>l>=0),gi),i+=n*l,o+=l)}}else s=he(s),t=he(t),le((()=>s>=0),gi),i+=t*s,o+=s;return le((()=>0!==o),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),i/o}},mi={description:a("Numerical average value in a dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0;const s=Ie(e,((e,s)=>(t+=1,e+s)),0);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),s/t},isExported:!0},vi={description:a("Average of values depending on criteria."),args:_e(`\n criteria_range (range) ${a("The range to check against criterion.")}\n criterion (string) ${a("The pattern or test to apply to criteria_range.")}\n average_range (range, default=criteria_range) ${a("The range to average. If not included, criteria_range is used for the average instead.")}\n `),returns:["NUMBER"],compute:function(e,t,s){null==s&&(s=e);let i=0,o=0;return xe([e,t],((t,n)=>{const r=(s||e)[t][n];"number"==typeof r&&(i+=1,o+=r)})),le((()=>0!==i),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),o/i},isExported:!0},Ei={description:a("Average of values depending on multiple criteria."),args:_e(`\n average_range (range) ${a("The range to average.")}\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional criteria_range and criterion to check.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=0,i=0;return xe(t,((t,o)=>{const n=e[t][o];"number"==typeof n&&(s+=1,i+=n)})),le((()=>0!==s),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),i/s},isExported:!0},bi={description:a("The number of numeric values in dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when counting.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;for(let s of e)if(Array.isArray(s))for(let e of s)for(let s of e)"number"==typeof s&&(t+=1);else("string"!=typeof s||J(s)||G(s))&&(t+=1);return t},isExported:!0},Si={description:a("The number of values in a dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when counting.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(...e){return Se(e,((e,t)=>null!=t?e+1:e),0)},isExported:!0},Ci={description:a("The covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!1)},isExported:!0},Ii={description:a("The covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!1)},isExported:!0},yi={description:a("The sample covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!0)},isExported:!0},wi={description:a("Nth largest element from a data set."),args:_e(`\n data (any, range) ${a("Array or range containing the dataset to consider.")}\n n (number) ${a("The rank from largest to smallest of the element to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=Math.trunc(he(t));let i,o=[],n=0;ve([e],(e=>{"number"==typeof e&&(i=Re(o,e),o.splice(i+1,0,e),n++,n>s&&(o.shift(),n--))}));const r=o.shift();return le((()=>void 0!==r),a("[[FUNCTION_NAME]] has no valid input data.")),le((()=>n>=s),a("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",s.toString())),r},isExported:!0},Ti={description:a("Maximum value in a numeric dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the maximum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ce(e,((e,t)=>e<t?t:e),-1/0);return t===-1/0?0:t},isExported:!0},xi={description:a("Maximum numeric value in a dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when calculating the maximum value.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ie(e,((e,t)=>Math.max(t,e)),-1/0);return t===-1/0?0:t},isExported:!0},Ri={description:a("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the maximum will be determined.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=-1/0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s=s<o?o:s)})),s===-1/0?0:s},isExported:!0},Li={description:a("Median value in a numeric dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when calculating the median value.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when calculating the median value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=[];return Ee(e,(e=>{t.push(e)})),hi(t,.5,!0)},isExported:!0},Mi={description:a("Minimum value in a numeric dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ce(e,((e,t)=>t<e?t:e),1/0);return t===1/0?0:t},isExported:!0},Ai={description:a("Minimum numeric value in a dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ie(e,((e,t)=>Math.min(t,e)),1/0);return t===1/0?0:t},isExported:!0},_i={description:a("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the minimum will be determined.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=1/0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s=s>o?o:s)})),s===1/0?0:s},isExported:!0},Oi={description:a("Value at a given percentile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile whose value within data will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return ki.compute(e,t)},isExported:!0},Ni={description:a("Value at a given percentile of a dataset exclusive of 0 and 1."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile, exclusive of 0 and 1, whose value within 'data' will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],t,!1)},isExported:!0},ki={description:a("Value at a given percentile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile whose value within data will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],t,!0)},isExported:!0},Fi={description:a("Value nearest to a specific quartile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return Di.compute(e,t)},isExported:!0},$i={description:a("Value nearest to a specific quartile of a dataset exclusive of 0 and 4."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value, exclusive of 0 and 4, to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],.25*Math.trunc(he(t)),!1)},isExported:!0},Di={description:a("Value nearest to a specific quartile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],.25*Math.trunc(he(t)),!0)},isExported:!0},Ui={description:a("Nth smallest element in a data set."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n n (number) ${a("The rank from smallest to largest of the element to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=Math.trunc(he(t));let i,o=[],n=0;ve([e],(e=>{"number"==typeof e&&(i=Re(o,e),o.splice(i+1,0,e),n++,n>s&&(o.pop(),n--))}));const r=o.pop();return le((()=>void 0!==r),a("[[FUNCTION_NAME]] has no valid input data.")),le((()=>n>=s),a("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",s.toString())),r},isExported:!0},Pi={description:a("Standard deviation."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Gi.compute(...e))},isExported:!0},Bi={description:a("Standard deviation of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Wi.compute(...e))},isExported:!0},Vi={description:a("Standard deviation."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(qi.compute(...e))},isExported:!0},Hi={description:a("Standard deviation of sample (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(ji.compute(...e))},isExported:!0},zi={description:a("Standard deviation of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Yi.compute(...e))},isExported:!0},Zi={description:a("Standard deviation of entire population (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Xi.compute(...e))},isExported:!0},Gi={description:a("Variance."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!1)},isExported:!0},Wi={description:a("Variance of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!1)},isExported:!0},qi={description:a("Variance."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!1)},isExported:!0},ji={description:a("Variance of sample (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!0)},isExported:!0},Yi={description:a("Variance of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!1)},isExported:!0},Xi={description:a("Variance of entire population (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!0)},isExported:!0};var Ki=Object.freeze({__proto__:null,AVEDEV:di,AVERAGE:ui,AVERAGE_WEIGHTED:fi,AVERAGEA:mi,AVERAGEIF:vi,AVERAGEIFS:Ei,COUNT:bi,COUNTA:Si,COVAR:Ci,COVARIANCE_P:Ii,COVARIANCE_S:yi,LARGE:wi,MAX:Ti,MAXA:xi,MAXIFS:Ri,MEDIAN:Li,MIN:Mi,MINA:Ai,MINIFS:_i,PERCENTILE:Oi,PERCENTILE_EXC:Ni,PERCENTILE_INC:ki,QUARTILE:Fi,QUARTILE_EXC:$i,QUARTILE_INC:Di,SMALL:Ui,STDEV:Pi,STDEV_P:Bi,STDEV_S:Vi,STDEVA:Hi,STDEVP:zi,STDEVPA:Zi,VAR:Gi,VAR_P:Wi,VAR_S:qi,VARA:ji,VARP:Yi,VARPA:Xi});function Qi(e,t,s){var i;const o=new Map,n=e.length;for(let t=n-1;t>=0;t--)o.set(ue(e[t][0]).toUpperCase(),t);if("number"!=typeof t&&"string"!=typeof t)throw new Error(a("The field must be a number or a string"));let r;if("number"==typeof t){if(r=Math.trunc(t)-1,r<0||n-1<r)throw new Error(a("The field (%s) must be one of %s or must be a number between 1 and %s inclusive.",t.toString(),n.toString()))}else{const e=ue(t).toUpperCase();if(r=null!==(i=o.get(e))&&void 0!==i?i:-1,-1===r)throw new Error(a("The field (%s) must be one of %s.",ue(t),[...o.keys()].toString()))}const l=s[0].length;if(l<2)throw new Error(a("The criteria range contains %s row, it must be at least 2 rows.",l.toString()));let c=new Set;const h=e[0].length;for(let t=1;t<l;t++){let i=[],n=!0;for(let r=0;r<s.length;r++){const a=ue(s[r][0]).toUpperCase(),l=o.get(a),c=s[r][t];if(void 0!==c){if(void 0===l){n=!1;break}i.push([e[l].slice(1,h)]),i.push(c)}}if(n){if(!(i.length>0)){c=new Set(Array(h-1).keys());break}xe(i,((e,t)=>{c.add(t)}),!0)}}const d=e[r];return[...c].map((e=>d[e+1]))}const Ji=_e(`\n database (range) ${a("The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values.")}\n field (any) ${a("Indicates which column in database contains the values to be extracted and operated on.")}\n criteria (range) ${a("An array or range containing zero or more criteria to filter the database values by before operating.")}\n`),eo={description:a("Average of a set of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return ui.compute([i])},isExported:!0},to={description:a("Counts values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return bi.compute([i])},isExported:!0},so={description:a("Counts values and text from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Si.compute([i])},isExported:!0},io={description:a("Single value from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return le((()=>1===i.length),a("More than one match found in DGET evaluation.")),i[0]},isExported:!0},oo={description:a("Maximum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Ti.compute([i])},isExported:!0},no={description:a("Minimum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Mi.compute([i])},isExported:!0},ro={description:a("Product of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Mt.compute([i])},isExported:!0},ao={description:a("Standard deviation of population sample from table."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Pi.compute([i])},isExported:!0},lo={description:a("Standard deviation of entire population from table."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return zi.compute([i])},isExported:!0},co={description:a("Sum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Bt.compute([i])},isExported:!0},ho={description:a("Variance of population sample from table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Gi.compute([i])},isExported:!0},uo={description:a("Variance of a population from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Yi.compute([i])},isExported:!0};var po=Object.freeze({__proto__:null,DAVERAGE:eo,DCOUNT:to,DCOUNTA:so,DGET:io,DMAX:oo,DMIN:no,DPRODUCT:ro,DSTDEV:ao,DSTDEVP:lo,DSUM:co,DVAR:ho,DVARP:uo});const go=new D(1899,11,30);function fo(e){const t=Math.trunc(e);return t%4==0&&t%100!=0||t%400==0}const mo={description:a("Converts year/month/day into a date."),args:_e(`\n year (number) ${a("The year component of the date.")}\n month (number) ${a("The month component of the date.")}\n day (number) ${a("The day component of the date.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s){let i=Math.trunc(he(e));const o=Math.trunc(he(t)),n=Math.trunc(he(s));le((()=>0<=i&&i<=9999),a("The year (%s) must be between 0 and 9999 inclusive.",i.toString())),i<1900&&(i+=1900);const r=new D(i,o-1,n).getTime()-go.getTime();return le((()=>r>=0),a("The function [[FUNCTION_NAME]] result must be greater than or equal 01/01/1900.")),Math.round(r/864e5)},isExported:!0},vo={description:a("Converts a date string to a date value."),args:_e(`\n date_string (string) ${a("The string representing the date.")}\n `),returns:["NUMBER"],compute:function(e){const t=ue(e),s=G(t);return le((()=>null!==s),a("The date_string (%s) cannot be parsed to date/time.",t.toString())),Math.trunc(s.value)},isExported:!0},Eo={description:a("Day of the month that a specific date falls on."),args:_e(`\n date (string) ${a("The date from which to extract the day.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getDate()},isExported:!0},bo={description:a("Number of days between two dates."),args:_e(`\n end_date (date) ${a("The end of the date range.")}\n start_date (date) ${a("The start of the date range.")}\n `),returns:["NUMBER"],compute:function(e,t){const s=fe(e),i=fe(t),o=s.getTime()-i.getTime();return Math.round(o/864e5)},isExported:!0},So={description:a("Date a number of months before/after another date."),args:_e(`\n start_date (date) ${a("The date from which to calculate the result.")}\n months (number) ${a("The number of months before (negative) or after (positive) 'start_date' to calculate.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t){const s=fe(e),i=Math.trunc(he(t)),o=s.getFullYear(),n=s.getMonth(),r=s.getDate(),a=new D(o,n+i,r).getTime()-go.getTime();return Math.round(a/864e5)},isExported:!0},Co={description:a("Last day of a month before or after a date."),args:_e(`\n start_date (date) ${a("The date from which to calculate the result.")}\n months (number) ${a("The number of months before (negative) or after (positive) 'start_date' to consider.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t){const s=fe(e),i=Math.trunc(he(t)),o=s.getFullYear(),n=s.getMonth(),r=new D(o,n+i+1,0).getTime()-go.getTime();return Math.round(r/864e5)},isExported:!0},Io={description:a("Hour component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the hour component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getHours()},isExported:!0},yo={description:a("ISO week number of the year."),args:_e(`\n date (date) ${a("The date for which to determine the ISO week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n `),returns:["NUMBER"],compute:function(e){const t=fe(e),s=t.getFullYear();let i=1;for(;4!==new D(s,0,i).getDay();)i+=1;const o=new D(s,0,i-3);let n=31;for(;4!==new D(s,11,n).getDay();)n-=1;const r=new D(s,11,n+3);let a,l;switch(a=o.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=o;break;case 1:l=new D(s,11,n+3+1);break;case-1:let e=1;for(;4!==new D(s-1,0,e).getDay();)e+=1;l=new D(s-1,0,e-3)}const c=(t.getTime()-l.getTime())/864e5;return Math.floor(c/7)+1},isExported:!0},wo={description:a("Minute component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the minute component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getMinutes()},isExported:!0},To={description:a("Month of the year a specific date falls in"),args:_e(`\n date (date) ${a("The date from which to extract the month.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getMonth()+1},isExported:!0},xo={description:a("Net working days between two provided days."),args:_e(`\n start_date (date) ${a("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${a("The end date of the period from which to calculate the number of net working days.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the date serial numbers to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,s){return Lo.compute(e,t,1,s)},isExported:!0};function Ro(e){if("string"==typeof e){le((()=>{if(7!==e.length)return!1;for(let t of e)if("0"!==t&&"1"!==t)return!1;return!0}),a('When weekend is a string (%s) it must be composed of "0" or "1".',e));let t=[];for(let s=0;s<7;s++)"1"===e[s]&&t.push((s+1)%7);return t}if("number"==typeof e)return le((()=>1<=e&&e<=7||11<=e&&e<=17),a("The weekend (%s) must be a string or a number in the range 1-7 or 11-17.",e.toString())),e<=7?[e-2==-1?6:e-2,e-1]:[e-11];throw Error(a("The weekend (%s) must be a number or a string.",e.toString()))}const Lo={description:a("Net working days between two dates (specifying weekends)."),args:_e(`\n start_date (date) ${a("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${a("The end date of the period from which to calculate the number of net working days.")}\n weekend (any, default=1) ${a("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider as holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1,i){const o=fe(e),n=fe(t),r=Ro(s);let a=new Set;void 0!==i&&ve([i],(e=>{const t=fe(e);a.add(t.getTime())}));const l=o.getTime()>n.getTime(),c=D.fromTimestamp((l?o:n).getTime());let h=D.fromTimestamp((l?n:o).getTime());const d=c.getTime();let u=h.getTime(),p=0;for(;u<=d;)r.includes(h.getDay())||a.has(u)||(p+=1),h.setDate(h.getDate()+1),u=h.getTime();return l?-p:p},isExported:!0},Mo={description:a("Current date and time as a date value."),args:[],returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy hh:mm:ss"},compute:function(){let e=D.now();const t=e.getTime()-go.getTime(),s=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return Math.floor(t/864e5)+s},isExported:!0},Ao={description:a("Minute component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the second component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getSeconds()},isExported:!0},_o={description:a("Converts hour/minute/second into a time."),args:_e(`\n hour (number) ${a("The hour component of the time.")}\n minute (number) ${a("The minute component of the time.")}\n second (number) ${a("The second component of the time.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"hh:mm:ss a"},compute:function(e,t,s){let i=Math.trunc(he(e)),o=Math.trunc(he(t)),n=Math.trunc(he(s));return o+=Math.floor(n/60),n=n%60+(n<0?60:0),i+=Math.floor(o/60),o=o%60+(o<0?60:0),i%=24,le((()=>i>=0),a("The function [[FUNCTION_NAME]] result cannot be negative")),i/24+o/1440+n/86400},isExported:!0},Oo={description:a("Converts a time string into its serial number representation."),args:_e(`\n time_string (string) ${a("The string that holds the time representation.")}\n `),returns:["NUMBER"],compute:function(e){const t=ue(e),s=G(t);le((()=>null!==s),a("The time_string (%s) cannot be parsed to date/time.",t));const i=s.value-Math.trunc(s.value);return i<0?1+i:i},isExported:!0},No={description:a("Current date as a date value."),args:[],returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(){const e=D.now(),t=new D(e.getFullYear(),e.getMonth(),e.getDate()).getTime()-go.getTime();return Math.round(t/864e5)},isExported:!0},ko={description:a("Day of the week of the date provided (as number)."),args:_e(`\n date (date) ${a("The date for which to determine the day of the week. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n type (number, default=1) ${a("A number indicating which numbering system to use to represent weekdays. By default, counts starting with Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const s=fe(e),i=Math.round(he(t)),o=s.getDay();return le((()=>[1,2,3].includes(i)),a("The type (%s) must be 1, 2 or 3.",i.toString())),1===i?o+1:2===i?0===o?7:o:0===o?6:o-1},isExported:!0},Fo={description:a("Week number of the year."),args:_e(`\n date (date) ${a("The date for which to determine the week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n type (number, default=1) ${a("A number representing the day that a week starts on. Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const s=fe(e),i=Math.round(he(t));if(le((()=>1===i||2===i||11<=i&&i<=17||21===i),a("The type (%s) is out of range.",i.toString())),21===i)return yo.compute(e);let o;o=1===i||2===i?i-1:i-10==7?0:i-10;const n=s.getFullYear();let r=1,l=new D(n,0,r);for(;l.getDay()!==o;)r+=1,l=new D(n,0,r);const c=(s.getTime()-l.getTime())/864e5;return c<0?1:Math.floor(c/7)+(1===r?1:2)},isExported:!0},$o={description:a("Number of working days from start date."),args:_e(`\n start_date (date) ${a("The date from which to begin counting.")}\n num_days (number) ${a("The number of working days to advance from start_date. If negative, counts backwards.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider holidays.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s){return Do.compute(e,t,1,s)},isExported:!0},Do={description:a("Net working days between two dates (specifying weekends)."),args:_e(`\n start_date (date) ${a("The date from which to begin counting.")}\n num_days (number) ${a("The number of working days to advance from start_date. If negative, counts backwards.")}\n weekend (any, default=1) ${a("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider holidays.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s=1,i){let o=fe(e),n=Math.trunc(he(t));"string"==typeof s&&le((()=>"1111111"!==s),a("The weekend (%s) must be different from '1111111'.",s));const r=Ro(s);let l=new Set;void 0!==i&&ve([i],(e=>{const t=fe(e);l.add(t.getTime())}));let c=D.fromTimestamp(o.getTime()),h=c.getTime();const d=Math.sign(n);let u=Math.abs(n);for(;u>0;)c.setDate(c.getDate()+d),h=c.getTime(),r.includes(c.getDay())||l.has(h)||(u-=1);const p=h-go.getTime();return Math.round(p/864e5)},isExported:!0},Uo={description:a("Year specified by a given date."),args:_e(`\n date (date) ${a("The date from which to extract the year.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getFullYear()},isExported:!0},Po={description:a("Exact number of years between two dates."),args:_e(`\n start_date (date) ${a("The start date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n end_date (date) ${a("The end date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n day_count_convention (number, default=0) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s=0){let i=Math.trunc(he(e)),o=Math.trunc(he(t));const n=Math.trunc(he(s));if(le((()=>i>=0),a("The start_date (%s) must be positive or null.",i.toString())),le((()=>o>=0),a("The end_date (%s) must be positive or null.",o.toString())),le((()=>0<=n&&n<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",n.toString())),i===o)return 0;if(i>o){const e=o;o=i,i=e}const r=fe(i),l=fe(o);let c=r.getDate(),h=l.getDate();const d=r.getMonth(),u=l.getMonth(),p=r.getFullYear(),g=l.getFullYear();let f=0,m=0;switch(n){case 0:31===c&&(c=30),30===c&&31===h&&(h=30),1===d&&c===(fo(p)?29:28)&&(c=30,1===u&&h===(fo(g)?29:28)&&(h=30)),f=p+(30*d+c)/360,m=g+(30*u+h)/360;break;case 1:let e=365;const t=p===g;if(!t&&!(p+1===g)||!t&&d<u||!t&&d===u&&c<h){let t=0,s=0;for(let e=p;e<=g;e++)t++,s+=fo(e)?366:365;e=s/t}else t?fo(p)&&(e=366):(fo(p)&&d<2&&(e=366),fo(g)&&(u>1||1===u&&29===h)&&(e=366));f=i/e,m=o/e;break;case 2:f=i/360,m=o/360;break;case 3:f=i/365,m=o/365;break;case 4:31===c&&(c=30),31===h&&(h=30),f=p+(30*d+c)/360,m=g+(30*u+h)/360}return m-f}};var Bo=Object.freeze({__proto__:null,DATE:mo,DATEVALUE:vo,DAY:Eo,DAYS:bo,EDATE:So,EOMONTH:Co,HOUR:Io,ISOWEEKNUM:yo,MINUTE:wo,MONTH:To,NETWORKDAYS:xo,NETWORKDAYS_INTL:Lo,NOW:Mo,SECOND:Ao,TIME:_o,TIMEVALUE:Oo,TODAY:No,WEEKDAY:ko,WEEKNUM:Fo,WORKDAY:$o,WORKDAY_INTL:Do,YEAR:Uo,YEARFRAC:Po});function Vo(e,t,s,i,o=1e-10){let n,r,l,c=s,h=!1,d=0;do{l=e(c),n=c-l/t(c),r=Math.abs(n-c),c=n,h=r<o||Math.abs(l)<o,le((()=>d<i),a("Function [[FUNCTION_NAME]] didn't find any result")),d++}while(!h);return c}const Ho={description:a("Depreciation via declining balance method."),args:_e(`\n cost (number) ${a("The initial cost of the asset.")}\n salvage (number) ${a("The value of the asset at the end of depreciation.")}\n life (number) ${a("The number of periods over which the asset is depreciated.")}\n period (number) ${a("The single period within life for which to calculate depreciation.")}\n month (number, optional) ${a("The number of months in the first year of depreciation.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i,...o){const n=he(e),r=he(t),l=he(s),c=Math.trunc(he(i)),h=o.length?Math.trunc(he(o[0])):12,d=l+(12===h?0:1);le((()=>n>0),a("The cost (%s) must be strictly positive.",n.toString())),le((()=>r>=0),a("The salvage (%s) must be positive or null.",r.toString())),le((()=>l>0),a("The life (%s) must be strictly positive.",l.toString())),le((()=>c>0),a("The period (%s) must be strictly positive.",c.toString())),le((()=>1<=h&&h<=12),a("The month (%s) must be between 1 and 12 inclusive.",h.toString())),le((()=>c<=d),a("The period (%s) must be less than or equal to %s.",c.toString(),d.toString()));const u=h/12;let p=1-Math.pow(r/n,1/l);p=Math.round(1e3*p)/1e3;let g=n,f=n*(1-p*u);for(let e=1;e<c;e++)g=f,f=g*(1-p),e===l&&(f=g*(1-p*(1-u)));return g-f}},zo={description:a("Number of periods for an investment to reach a value."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){n=n||0;const r=Math.trunc(he(e)),l=Math.trunc(he(t)),c=he(s),h=he(i),d=Math.trunc(he(o)),u=Math.trunc(he(n));le((()=>r<l),a("The maturity (%s) must be strictly greater than the settlement (%s).",l.toString(),r.toString())),le((()=>c>=0),a("The rate (%s) must be positive or null.",c.toString())),le((()=>h>=0),a("The yield (%s) must be positive or null.",h.toString())),le((()=>[1,2,4].includes(d)),a("The frequency (%s) must be one of %s",d.toString(),[1,2,4].toString())),le((()=>0<=u&&u<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",u.toString()));const p=Po.compute(r,l,u),g=p-Math.trunc(p)||1/d,f=Math.ceil(p*d),m=c/d,v=h/d;let E=0,b=0;for(let e=1;e<=f;e++){const t=(m+(e===f?1:0))/(1+v)**e;b+=(g+(e-1)/d)*t,E+=t}return 0===E?0:b/E}},Zo={description:a("Future value of an annuity investment."),args:_e(`\n rate (number) ${a("The interest rate.")}\n number_of_periods (number) ${a("The number of payments to be made.")}\n payment_amount (number) ${a("The amount per period to be paid.")}\n present_value (number, default=0) ${a("The current value of the annuity.")}\n end_or_beginning (number, default=0) ${a("Whether payments are due at the end (0) or beginning (1) of each period.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i=0,o=0){i=i||0,o=o||0;const n=he(e),r=he(t),a=he(s),l=he(i),c=ge(o)?1:0;return n?-l*(1+n)**r-a*(1+n*c)*((1+n)**r-1)/n:-(l+a*r)}},Go={description:a("Internal rate of return given periodic cashflows."),args:_e(`\n cashflow_amounts (number, range<number>) ${a("An array or range containing the income or payments associated with the investment.")}\n rate_guess (number, default=0.1) ${a("An estimate for what the internal rate of return will be.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"0%"},compute:function(e,t=.1){const s=he(t);le((()=>s>-1),a("The rate_guess (%s) must be strictly greater than -1.",s.toString()));let i=!1,o=!1,n=[];Ee([e],(e=>{e>0&&(i=!0),e<0&&(o=!0),n.push(e)})),le((()=>i&&o),a("The cashflow_amounts must include negative and positive values."));const r=n.shift();return Vo((function(e){return function(e,t,s){const i=s.length;let o=0;return s.reduce(((t,s)=>(o++,t+s*e**(i-o))),t*e**i)}(e,r,n)}),(function(e){return function(e,t,s){const i=s.length;let o=0;return s.reduce(((t,s)=>(o++,t+s*(i-o)*e**(i-o-1))),t*i*e**(i-1))}(e,r,n)}),s+1,20,1e-5)-1}},Wo={description:a("Modified Macaulay duration."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){return zo.compute(e,t,s,i,o,n)/(1+he(i)/Math.trunc(he(o)))}};const qo={description:a("The net present value of an investment based on a series of periodic cash flows and a discount rate."),args:_e(`\n discount (number) ${a("The discount rate of the investment over one period.")}\n cashflow1 (number, range<number>) ${a("The first future cash flow.")}\n cashflow2 (number, range<number>, repeating) ${a("Additional future cash flows.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,...t){const s=he(e);return le((()=>-1!==s),a("The discount (%s) must be different from -1.",s.toString())),function(e,t,s){let i=0;return Ce(s,((t,s)=>(i++,t+s/(1+e)**i)),t)}(s,0,t)}},jo={description:a("Computes the number of periods needed for an investment to reach a value."),args:_e(`\n rate (number) ${a("The rate at which the investment grows each period.")}\n present_value (number) ${a("The investment's current value.")}\n future_value (number) ${a("The investment's desired future value.")}\n `),returns:["NUMBER"],compute:function(e,t,s){const i=he(e),o=he(t),n=he(s);return le((()=>i>0),a("The rate (%s) must be strictly positive.",i.toString())),le((()=>o>0),a("The present_value (%s) must be strictly positive.",o.toString())),le((()=>n>0),a("The future_value (%s) must be strictly positive.",n.toString())),(Math.log(n)-Math.log(o))/Math.log(1+i)}},Yo={description:a("Present value of an annuity investment."),args:_e(`\n rate (number) ${a("The interest rate.")}\n number_of_periods (number) ${a("The number of payments to be made.")}\n payment_amount (number) ${a("The amount per period to be paid.")}\n future_value (number, default=0) ${a("The future value remaining after the final payment has been made.")}\n end_or_beginning (number, default=0) ${a("Whether payments are due at the end (0) or beginning (1) of each period.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i=0,o=0){i=i||0,o=o||0;const n=he(e),r=he(t),a=he(s),l=he(i),c=ge(o)?1:0;return n?-(a*(1+n*c)*((1+n)**r-1)/n+l)/(1+n)**r:-(l+a*r)}},Xo={description:a("Price of a security paying periodic interest."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n redemption (number) ${a("The redemption amount per 100 face value, or par.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n,r=0){r=r||0;const l=Math.trunc(he(e)),c=Math.trunc(he(t)),h=he(s),d=he(i),u=he(o),p=Math.trunc(he(n)),g=Math.trunc(he(r));le((()=>c>l),a("The maturity (%s) must be strictly greater than the settlement (%s).",c.toString(),l.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>=0),a("The yield (%s) must be positive or null.",d.toString())),le((()=>u>0),a("The redemption (%s) must be strictly positive.",u.toString())),le((()=>[1,2,4].includes(p)),a("The frequency (%s) must be one of %s.",p.toString(),[1,2,4].toString())),le((()=>0<=g&&g<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",g.toString()));const f=Po.compute(l,c,g)*p,m=Math.ceil(f),v=f-Math.floor(f)||1,E=1+d/p,b=100*h/p;if(1===m)return(b+u)/(v*d/p+1)-b*(1-v);let S=0;for(let e=1;e<=m;e++)S+=b/E**(e-1+v);return u/E**(m-1+v)+S-b*(1-v)}},Ko={description:a("Annual yield of a security paying periodic interest."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n price (number) ${a("The price at which the security is bought per 100 face value.")}\n redemption (number) ${a("The redemption amount per 100 face value, or par.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n,r=0){r=r||0;const l=Math.trunc(he(e)),c=Math.trunc(he(t)),h=he(s),d=he(i),u=he(o),p=Math.trunc(he(n)),g=Math.trunc(he(r));le((()=>c>l),a("The maturity (%s) must be strictly greater than the settlement (%s).",c.toString(),l.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>0),a("The price (%s) must be strictly positive.",d.toString())),le((()=>u>0),a("The redemption (%s) must be strictly positive.",u.toString())),le((()=>[1,2,4].includes(p)),a("The frequency (%s) must be one of %s.",p.toString(),[1,2,4].toString())),le((()=>0<=g&&g<=4),a("The day_count_convention (%s) must between 0 and 4 inclusive.",g.toString()));const f=Po.compute(l,c,g)*p,m=Math.ceil(f),v=f-Math.floor(f)||1,E=100*h/p;if(1===m){const e=d+E*(1-v);return(u+E-e)*p*(1/v)/e}const b=Vo((function(e){return function(e,t,s,i,o,n){let r=n-(e+o*(1-t))*i**(s-1+t);for(let e=1;e<=s;e++)r+=o*i**(e-1);return r}(d,v,m,e,E,u)}),(function(e){return function(e,t,s,i,o){let n=-(e+o*(1-t))*(s-1+t)*i**(s-2+t);for(let e=1;e<=s;e++)n+=o*(e-1)*i**(e-2);return n}(d,v,m,e,E)}),1+(h+1)/p,100,1e-5);return(b-1)*p}},Qo={description:a("Annual yield of a security paying interest at maturity."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n issue (date) ${a("The date the security was initially issued.")}\n rate (number) ${a("The annualized rate of interest.")}\n price (number) ${a("The price at which the security is bought.")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){n=n||0;const r=Math.trunc(he(e)),l=Math.trunc(he(t)),c=Math.trunc(he(s)),h=he(i),d=he(o),u=Math.trunc(he(n));le((()=>r>=c),a("The settlement (%s) must be greater than or equal to the issue (%s).",r.toString(),c.toString())),le((()=>l>r),a("The maturity (%s) must be strictly greater than the settlement (%s).",l.toString(),r.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>0),a("The price (%s) must be strictly positive.",d.toString())),le((()=>0<=u&&u<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",u.toString()));const p=Po.compute(c,l,u),g=Po.compute(c,r,u),f=Po.compute(r,l,u);return(100*(1+h*p)/(d+100*h*g)-1)/f}};var Jo=Object.freeze({__proto__:null,DB:Ho,DURATION:zo,FV:Zo,IRR:Go,MDURATION:Wo,NPV:qo,PDURATION:jo,PV:Yo,PRICE:Xo,YIELD:Ko,YIELDMAT:Qo});const en={description:a("Whether a value is an error."),args:_e(`value (any, lazy) ${a("The value to be verified as an error type.")}`),returns:["BOOLEAN"],compute:function(e){try{return e(),!1}catch(e){return!0}},isExported:!0},tn={description:a("Whether a value is `true` or `false`."),args:_e(`value (any) ${a("The value to be verified as a logical TRUE or FALSE.")}`),returns:["BOOLEAN"],compute:function(e){return"boolean"==typeof e},isExported:!0},sn={description:a("Whether a value is non-textual."),args:_e(`value (any) ${a("The value to be checked.")}`),returns:["BOOLEAN"],compute:function(e){return"string"!=typeof e},isExported:!0},on={description:a("Whether a value is a number."),args:_e(`value (any) ${a("The value to be verified as a number.")}`),returns:["BOOLEAN"],compute:function(e){return"number"==typeof e},isExported:!0},nn={description:a("Whether a value is text."),args:_e(`value (any) ${a("The value to be verified as text.")}`),returns:["BOOLEAN"],compute:function(e){return"string"==typeof e},isExported:!0};var rn=Object.freeze({__proto__:null,ISERROR:en,ISLOGICAL:tn,ISNONTEXT:sn,ISNUMBER:on,ISTEXT:nn});const an={description:a("Logical `and` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that represent logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!0;return ye(e,(e=>(t=!0,s=s&&e,s))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0},ln={description:a("Returns value depending on logical expression."),args:_e(`\n logical_expression (boolean) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE.")}\n value_if_true (any, lazy) ${a("The value the function returns if logical_expression is TRUE.")}\n value_if_false (any, lazy, default=FALSE) ${a("The value the function returns if logical_expression is FALSE.")}\n `),returns:["ANY"],compute:function(e,t,s=(()=>!1)){const i=ge(e)?t():s();return null==i?"":i},isExported:!0},cn={description:a("Value if it is not an error, otherwise 2nd argument."),args:_e(`\n value (any, lazy) ${a("The value to return if value itself is not an error.")}\n value_if_error (any, lazy, default=${a("An empty value")}) ${a("The value the function returns if value is an error.")}\n `),returns:["ANY"],compute:function(e,t=(()=>"")){let s;try{s=e()}catch(e){s=t()}return null==s?"":s},isExported:!0},hn={description:a("Returns a value depending on multiple logical expressions."),args:_e(`\n condition1 (boolean, lazy) ${a("The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those.")}\n value1 (any, lazy) ${a("The returned value if condition1 is TRUE.")}\n condition2 (boolean, lazy, repeating) ${a("Additional conditions to be evaluated if the previous ones are FALSE.")}\n value2 (any, lazy, repeating) ${a("Additional values to be returned if their corresponding conditions are TRUE.")}\n `),returns:["ANY"],compute:function(...e){le((()=>e.length%2==0),a("Wrong number of arguments. Expected an even number of arguments."));for(let t=0;t<e.length-1;t+=2)if(ge(e[t]()))return e[t+1]();throw new Error(a("No match."))},isExported:!0},dn={description:a("Returns opposite of provided logical value."),args:_e(`logical_expression (boolean) ${a("An expression or reference to a cell holding an expression that represents some logical value.")}\n `),returns:["BOOLEAN"],compute:function(e){return!ge(e)},isExported:!0},un={description:a("Logical `or` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!1;return ye(e,(e=>(t=!0,s=s||e,!s))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0},pn={description:a("Logical `xor` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!1;return ye(e,(e=>(t=!0,s=s?!e:e,!0))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0};var gn=Object.freeze({__proto__:null,AND:an,IF:ln,IFERROR:cn,IFS:hn,NOT:dn,OR:un,XOR:pn});function fn(e,t){for(let s=0;s<e.length;s++)if(e[s]===t)return s;return-1}const mn={description:a("Column number of a specified cell."),args:_e(`cell_reference (meta, default=${a("The cell in which the formula is entered")}) ${a("The cell whose column number will be returned. Column A corresponds to 1.")}\n `),returns:["NUMBER"],compute:function(e){var t;e=e||(null===(t=this.__originCellXC)||void 0===t?void 0:t.call(this)),le((()=>!!e),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter.");return ks(e).left+1},isExported:!0},vn={description:a("Number of columns in a specified array or range."),args:_e(`range (meta) ${a("The range whose column count will be returned.")}`),returns:["NUMBER"],compute:function(e){const t=ks(e);return t.right-t.left+1},isExported:!0},En={description:a("Horizontal lookup"),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (range) ${a("The range to consider for the search. The first row in the range is searched for the key specified in search_key.")}\n index (number) ${a("The row index of the value to be returned, where the first row in range is numbered 1.")}\n is_sorted (boolean, default=true) ${a("Indicates whether the row to be searched (the first row of the specified range) is sorted, in which case the closest match for search_key will be returned.")}\n `),returns:["ANY"],compute:function(e,t,s,i=true){const o=Math.trunc(he(s));le((()=>1<=o&&o<=t[0].length),a("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const n=ge(i),r=t.map((e=>e[0]));let l;return l=n?Re(r,e):fn(r,e),le((()=>l>-1),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),t[l][o-1]},isExported:!0},bn={description:a("Look up a value."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n search_array (range) ${a("One method of using this function is to provide a single sorted row or column search_array to look through for the search_key with a second argument result_range. The other way is to combine these two arguments into one search_array where the first row or column is searched and a value is returned from the last row or column in the array. If search_key is not found, a non-exact match may be returned.")}\n result_range (range, optional) ${a("The range from which to return a result. The value returned corresponds to the location where search_key is found in search_range. This range must be only a single row or column and should not be used if using the search_result_array method.")}\n `),returns:["ANY"],compute:function(e,t,s){let i=t.length,o=t[0].length;const n=o>=i,r=Re(n?t[0]:t.map((e=>e[0])),e);return le((()=>r>=0),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),void 0===s?n?t[i-1][r]:t[r][o-1]:(i=s.length,o=s[0].length,le((()=>1===i||1===o),a("The result_range must be a single row or a single column.")),i>1?(le((()=>r<=i-1),a("[[FUNCTION_NAME]] evaluates to an out of range row value %s.",(r+1).toString())),s[r][0]):(le((()=>r<=o-1),a("[[FUNCTION_NAME]] evaluates to an out of range column value %s.",(r+1).toString())),s[0][r]))},isExported:!0},Sn={description:a("Position of item in range that matches value."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${a("The one-dimensional array to be searched.")}\n search_type (number, default=1) ${a("The search method. 1 (default) finds the largest value less than or equal to search_key when range is sorted in ascending order. 0 finds the exact value when range is unsorted. -1 finds the smallest value greater than or equal to search_key when range is sorted in descending order.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){let i=he(s);const o=t.length,n=t[0].length;le((()=>1===o||1===n),a("The range must be a single row or a single column."));let r=-1;const l=t.flat();switch(i=Math.sign(i),i){case 1:r=Re(l,e);break;case 0:r=fn(l,e);break;case-1:r=function(e,t){const s=typeof t;let i,o,n,r,a,l,c=0,h=e.length-1;if(typeof e[c]===s&&t>e[c])return-1;if(typeof e[h]===s&&e[h]>t)return h;for(;h-c>=0;){for(n=Math.ceil((c+h)/2),r=n,a=e[r],l=typeof a;c<=r&&s!==l;)r--,a=e[r],l=typeof a;l===s&&a>=t&&(void 0===i||i>a||i===a&&o>r)&&(i=a,o=r),l===s&&a<=t?h=r-1:c=n+1}return void 0!==o?o:-1}(l,e)}return le((()=>r>=0),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),r+1},isExported:!0},Cn={description:a("Row number of a specified cell."),args:_e(`cell_reference (meta, default=${a("The cell in which the formula is entered by default")}) ${a("The cell whose row number will be returned.")}`),returns:["NUMBER"],compute:function(e){var t;e=e||(null===(t=this.__originCellXC)||void 0===t?void 0:t.call(this)),le((()=>!!e),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter.");return ks(e).top+1},isExported:!0},In={description:a("Number of rows in a specified array or range."),args:_e(`range (meta) ${a("The range whose row count will be returned.")}`),returns:["NUMBER"],compute:function(e){const t=ks(e);return t.bottom-t.top+1},isExported:!0},yn={description:a("Vertical lookup."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${a("The range to consider for the search. The first column in the range is searched for the key specified in search_key.")}\n index (number) ${a("The column index of the value to be returned, where the first column in range is numbered 1.")}\n is_sorted (boolean, default=true) ${a("Indicates whether the column to be searched (the first column of the specified range) is sorted, in which case the closest match for search_key will be returned.")}\n `),returns:["ANY"],compute:function(e,t,s,i=true){const o=Math.trunc(he(s));le((()=>1<=o&&o<=t.length),a("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const n=ge(i),r=t[0];let l;return l=n?Re(r,e):fn(r,e),le((()=>l>-1),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),t[o-1][l]},isExported:!0};var wn=Object.freeze({__proto__:null,COLUMN:mn,COLUMNS:vn,HLOOKUP:En,LOOKUP:bn,MATCH:Sn,ROW:Cn,ROWS:In,VLOOKUP:yn});const Tn={description:a("Sum of two numbers."),args:_e(`\n value1 (number) ${a("The first addend.")}\n value2 (number) ${a("The second addend.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)+he(t)}},xn={description:a("Concatenation of two values."),args:_e(`\n value1 (string) ${a("The value to which value2 will be appended.")}\n value2 (string) ${a("The value to append to value1.")}\n `),returns:["STRING"],compute:function(e,t){return ue(e)+ue(t)},isExported:!0},Rn={description:a("One number divided by another."),args:_e(`\n dividend (number) ${a("The number to be divided.")}\n divisor (number) ${a("The number to divide by.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(t);return le((()=>0!==s),a("The divisor must be different from zero.")),he(e)/s}};function Ln(e){return null==e}const Mn={number:0,string:"",boolean:!1},An={description:a("Equal."),args:_e(`\n value1 (any) ${a("The first value.")}\n value2 (any) ${a("The value to test against value1 for equality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return e=Ln(e)?Mn[typeof t]:e,t=Ln(t)?Mn[typeof e]:t,"string"==typeof e&&(e=e.toUpperCase()),"string"==typeof t&&(t=t.toUpperCase()),e===t}};function _n(e,t,s){e=Ln(e)?Mn[typeof t]:e,t=Ln(t)?Mn[typeof e]:t,"number"!=typeof e&&(e=ue(e).toUpperCase()),"number"!=typeof t&&(t=ue(t).toUpperCase());const i=typeof e,o=typeof t;return"string"===i&&"number"===o||("string"!==o||"number"!==i)&&s(e,t)}const On={description:a("Strictly greater than."),args:_e(`\n value1 (any) ${a("The value to test as being greater than value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return _n(e,t,((e,t)=>e>t))}},Nn={description:a("Greater than or equal to."),args:_e(`\n value1 (any) ${a("The value to test as being greater than or equal to value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return _n(e,t,((e,t)=>e>=t))}},kn={description:a("Less than."),args:_e(`\n value1 (any) ${a("The value to test as being less than value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Nn.compute(e,t)}},Fn={description:a("Less than or equal to."),args:_e(`\n value1 (any) ${a("The value to test as being less than or equal to value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!On.compute(e,t)}},$n={description:a("Difference of two numbers."),args:_e(`\n value1 (number) ${a("The minuend, or number to be subtracted from.")}\n value2 (number) ${a("The subtrahend, or number to subtract from value1.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)-he(t)}},Dn={description:a("Product of two numbers"),args:_e(`\n factor1 (number) ${a("The first multiplicand.")}\n factor2 (number) ${a("The second multiplicand.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)*he(t)}},Un={description:a("Not equal."),args:_e(`\n value1 (any) ${a("The first value.")}\n value2 (any) ${a("The value to test against value1 for inequality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!An.compute(e,t)}},Pn={description:a("A number raised to a power."),args:_e(`\n base (number) ${a("The number to raise to the exponent power.")}\n exponent (number) ${a("The exponent to raise base to.")}\n `),returns:["NUMBER"],compute:function(e,t){return Lt.compute(e,t)}},Bn={description:a("A number with the sign reversed."),args:_e(`\n value (number) ${a("The number to have its sign reversed. Equivalently, the number to multiply by -1.")}\n `),returnFormat:Ve.FormatFromArgument,returns:["NUMBER"],compute:function(e){return-he(e)}},Vn={description:a("Value interpreted as a percentage."),args:_e(`\n percentage (number) ${a("The value to interpret as a percentage.")}\n `),returns:["NUMBER"],compute:function(e){return he(e)/100}},Hn={description:a("A specified number, unchanged."),args:_e(`\n value (any) ${a("The number to return.")}\n `),returnFormat:Ve.FormatFromArgument,returns:["ANY"],compute:function(e){return e}};var zn=Object.freeze({__proto__:null,ADD:Tn,CONCAT:xn,DIVIDE:Rn,EQ:An,GT:On,GTE:Nn,LT:kn,LTE:Fn,MINUS:$n,MULTIPLY:Dn,NE:Un,POW:Pn,UMINUS:Bn,UNARY_PERCENT:Vn,UPLUS:Hn});const Zn={description:a("Gets character associated with number."),args:_e(`\n table_number (number) ${a("The number of the character to look up from the current Unicode table in decimal format.")}\n `),returns:["STRING"],compute:function(e){const t=Math.trunc(he(e));return le((()=>t>=1),a("The table_number (%s) is out of range.",t.toString())),String.fromCharCode(t)},isExported:!0},Gn={description:a("Appends strings to one another."),args:_e(`\n string1 (string, range<string>) ${a("The initial string.")}\n string2 (string, range<string>, repeating) ${a("More strings to append in sequence.")}\n `),returns:["STRING"],compute:function(...e){return Se(e,((e,t)=>e+ue(t)),"")},isExported:!0},Wn={description:a("Tests whether two strings are identical."),args:_e(`\n string1 (string) ${a("The first string to compare.")}\n string2 (string) ${a("The second string to compare.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return ue(e)===ue(t)},isExported:!0},qn={description:a("First position of string found in text, case-sensitive."),args:_e(`\n search_for (string) ${a("The string to look for within text_to_search.")}\n text_to_search (string) ${a("The text to search for the first occurrence of search_for.")}\n starting_at (number, default=1) ${a("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){const i=ue(e),o=ue(t),n=he(s);le((()=>""!==o),a("The text_to_search must be non-empty.")),le((()=>n>=1),a("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=o.indexOf(i,n-1);return le((()=>r>=0),a("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",i.toString(),o)),r+1},isExported:!0},jn={description:a("Concatenates elements of arrays with delimiter."),args:_e(`\n delimiter (string) ${a("The character or string to place between each concatenated value.")}\n value_or_array1 (string, range<string>) ${a("The value or values to be appended using delimiter.")}\n value_or_array2 (string, range<string>, repeating) ${a("More values to be appended using delimiter.")}\n `),returns:["STRING"],compute:function(e,...t){const s=ue(e);return Se(t,((e,t)=>(e?e+s:"")+ue(t)),"")}},Yn={description:a("Substring from beginning of specified string."),args:_e(`\n text (string) ${a("The string from which the left portion will be returned.")}\n number_of_characters (number, optional) ${a("The number of characters to return from the left side of string.")}\n `),returns:["STRING"],compute:function(e,...t){const s=t.length?he(t[0]):1;return le((()=>s>=0),a("The number_of_characters (%s) must be positive or null.",s.toString())),ue(e).substring(0,s)},isExported:!0},Xn={description:a("Length of a string."),args:_e(`\n text (string) ${a("The string whose length will be returned.")}\n `),returns:["NUMBER"],compute:function(e){return ue(e).length},isExported:!0},Kn={description:a("Converts a specified string to lowercase."),args:_e(`\n text (string) ${a("The string to convert to lowercase.")}\n `),returns:["STRING"],compute:function(e){return ue(e).toLowerCase()},isExported:!0},Qn={description:a("Replaces part of a text string with different text."),args:_e(`\n text (string) ${a("The text, a part of which will be replaced.")}\n position (number) ${a("The position where the replacement will begin (starting from 1).")}\n length (number) ${a("The number of characters in the text to be replaced.")}\n new_text (string) ${a("The text which will be inserted into the original text.")}\n `),returns:["STRING"],compute:function(e,t,s,i){const o=he(t);le((()=>o>=1),a("The position (%s) must be greater than or equal to 1.",o.toString()));const n=ue(e),r=he(s),l=ue(i);return n.substring(0,o-1)+l+n.substring(o-1+r)},isExported:!0},Jn={description:a("A substring from the end of a specified string."),args:_e(`\n text (string) ${a("The string from which the right portion will be returned.")}\n number_of_characters (number, optional) ${a("The number of characters to return from the right side of string.")}\n `),returns:["STRING"],compute:function(e,...t){const s=t.length?he(t[0]):1;le((()=>s>=0),a("The number_of_characters (%s) must be positive or null.",s.toString()));const i=ue(e),o=i.length;return i.substring(o-s,o)},isExported:!0},er={description:a("First position of string found in text, ignoring case."),args:_e(`\n search_for (string) ${a("The string to look for within text_to_search.")}\n text_to_search (string) ${a("The text to search for the first occurrence of search_for.")}\n starting_at (number, default=1) ${a("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){const i=ue(e).toLowerCase(),o=ue(t).toLowerCase(),n=he(s);le((()=>""!==o),a("The text_to_search must be non-empty.")),le((()=>n>=1),a("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=o.indexOf(i,n-1);return le((()=>r>=0),a("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",i,o)),r+1},isExported:!0},tr={description:a("Replaces existing text with new text in a string."),args:_e(`\n text_to_search (string) ${a("The text within which to search and replace.")}\n search_for (string) ${a("The string to search for within text_to_search.")}\n replace_with (string) ${a("The string that will replace search_for.")}\n occurrence_number (number, optional) ${a("The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i){const o=he(i);le((()=>o>=0),a("The occurrenceNumber (%s) must be positive or null.",o.toString()));const n=ue(e),r=ue(t);if(""===r)return n;const l=ue(s),c=new RegExp(hs(r),"g");if(0===o)return n.replace(c,l);let h=0;return n.replace(c,(e=>++h===o?l:e))},isExported:!0},sr={description:a("Combines text from multiple strings and/or arrays."),args:_e(`\n delimiter (string) ${a(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")}\n ignore_empty (boolean) ${a("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")}\n text1 (string, range<string>) ${a("Any text item. This could be a string, or an array of strings in a range.")}\n text2 (string, range<string>, repeating) ${a("Additional text item(s).")}\n `),returns:["STRING"],compute:function(e,t,...s){const i=ue(e),o=ge(t);let n=0;return Se(s,((e,t)=>o&&""===ue(t)?e:(n++?e+i:"")+ue(t)),"")},isExported:!0},ir={description:a("Removes space characters."),args:_e(`\n text (string) ${a("The text or reference to a cell containing text to be trimmed.")}\n `),returns:["STRING"],compute:function(e){return ue(e).trim()},isExported:!0},or={description:a("Converts a specified string to uppercase."),args:_e(`\n text (string) ${a("The string to convert to uppercase.")}\n `),returns:["STRING"],compute:function(e){return ue(e).toUpperCase()},isExported:!0};const nr={database:po,date:Bo,financial:Jo,info:rn,lookup:wn,logical:gn,math:Wt,operators:zn,statistical:Ki,text:Object.freeze({__proto__:null,CHAR:Zn,CONCATENATE:Gn,EXACT:Wn,FIND:qn,JOIN:jn,LEFT:Yn,LEN:Xn,LOWER:Kn,REPLACE:Qn,RIGHT:Jn,SEARCH:er,SUBSTITUTE:tr,TEXTJOIN:sr,TRIM:ir,UPPER:or})};const rr=new class extends Le{constructor(){super(...arguments),this.mapping={}}add(e,t){e=e.toUpperCase().replace("_",".");const s=Ne(t);return function(e){let t=!1,s=!1,i=!1;for(let o of e){if(o.type.includes("META")&&o.type.length>1)throw new Error(a("Function ${name} has an argument that has been declared with more than one type whose type 'META'. The 'META' type can only be declared alone."));if(t&&!o.repeating)throw new Error(a("Function ${name} has no-repeatable arguments declared after repeatable ones. All repeatable arguments must be declared last."));const e=s||t||i,n=!(o.optional||o.repeating||o.default);if(e&&n)throw new Error(a("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=o.repeating,s=o.optional,i=o.default}}(s.args),this.mapping[e]=s.compute,super.add(e,s),this}};for(let e in nr){const t=nr[e];for(let s in t){const i=t[s];i.category=e,rr.add(s,{isExported:!1,...i})}}const ar=/^[S|N]?\d+/,lr=rr.content,cr="+,-,*,/,:,=,<>,>=,>,<=,<,%,^,&".split(",");function hr(e){const t=e.split(""),s=[];for(;t.length;){let e=Ir(t)||gr(t)||mr(t)||Er(t)||ur(t)||dr(t)||yr(t)||vr(t)||Sr(t);e||(e={type:"UNKNOWN",value:t.shift()}),s.push(e)}return s}function dr(e){if(e[0]===$){e.shift();const t=e.join("").match(ar);if(!t)return null;e.splice(0,t[0].length),e[0]===$&&e.shift();const s=t[0];switch(s[0]){case"S":return{type:"NORMALIZED_STRING",value:s.substring(1)};case"N":return{type:"NORMALIZED_NUMBER",value:s.substring(1)};default:return{type:"REFERENCE",value:s}}}return null}function ur(e){return"?"===e[0]?(e.shift(),{type:"DEBUGGER",value:"?"}):null}const pr={",":"COMMA","(":"LEFT_PAREN",")":"RIGHT_PAREN"};function gr(e){if(e[0]in pr){const t=e.shift();return{type:pr[t],value:t}}return null}function fr(e,t){for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}function mr(e){for(let t of cr)if(fr(e,t))return e.splice(0,t.length),{type:"OPERATOR",value:t};return null}function vr(e){const t=e.join("").match(K);return t?(e.splice(0,t[0].length),{type:"NUMBER",value:t[0]}):null}function Er(e){if('"'===e[0]){const t=e.shift(),s=[t];for(;e[0]&&(e[0]!==t||"\\"===s[s.length-1]);)s.push(e.shift());return'"'===e[0]&&s.push(e.shift()),{type:"STRING",value:s.join("")}}return null}const br=/\w|\.|!|\$/;function Sr(e){const t=[];if("'"===e[0]){let s=e.shift();for(t.push(s);e[0];)if(s=e.shift(),t.push(s),"'"===s){if(!e[0]||"'"!==e[0])break;s=e.shift(),t.push(s)}if("'"!==s)return{type:"UNKNOWN",value:t.join("")}}for(;e[0]&&e[0].match(br);)t.push(e.shift());if(t.length){const e=t.join("");return{type:e.toUpperCase()in lr?"FUNCTION":"SYMBOL",value:e}}return null}const Cr=/\s/;function Ir(e){let t=0;for(;e[0]&&e[0].match(Cr);)t++,e.shift();return t?{type:"SPACE",value:" ".repeat(t)}:null}function yr(e){return fr(e,_)?(e.splice(0,_.length),{type:"INVALID_REFERENCE",value:_}):null}const wr=["-","+"],Tr=["*","+","&"],xr={"^":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10},Rr=6;function Lr(e){switch(e.type){case"NUMBER":case"SYMBOL":return 0;case"COMMA":return 3;case"LEFT_PAREN":case"RIGHT_PAREN":return 5;case"OPERATOR":return xr[e.value]||15}throw new Error(a("Unknown token: %s",e.value))}function Mr(e,t,s){if("OPERATOR"===t.type){const i=Ar(s,Lr(t));return{type:"BIN_OPERATION",value:t.value,left:e,right:i}}throw new Error(N)}function Ar(e,t){const s=e.shift();if(!s)throw new Error(N);let i=function(e,t){var s;switch(e.type){case"DEBUGGER":const i=Ar(t,1e3);return i.debug=!0,i;case"NUMBER":return{type:"NUMBER",value:te(e.value)};case"NORMALIZED_NUMBER":return{type:"NORMALIZED_NUMBER",value:parseInt(e.value,10)};case"STRING":return{type:"STRING",value:e.value};case"NORMALIZED_STRING":return{type:"NORMALIZED_STRING",value:parseInt(e.value,10)};case"FUNCTION":if("LEFT_PAREN"!==t.shift().type)throw new Error(a("Wrong function call"));{const i=[];if(t[0]&&"RIGHT_PAREN"!==t[0].type)for("COMMA"===t[0].type?i.push({type:"UNKNOWN",value:""}):i.push(Ar(t,Rr));"COMMA"===(null===(s=t[0])||void 0===s?void 0:s.type);){t.shift();const e=t[0];if("RIGHT_PAREN"===(null==e?void 0:e.type)){i.push({type:"UNKNOWN",value:""});break}"COMMA"===(null==e?void 0:e.type)?i.push({type:"UNKNOWN",value:""}):i.push(Ar(t,Rr))}const o=t.shift();if(!o||"RIGHT_PAREN"!==o.type)throw new Error(a("Wrong function call"));return{type:"FUNCALL",value:e.value,args:i}}case"REFERENCE":return{type:"NORMALIZED_REFERENCE",value:parseInt(e.value,10)};case"INVALID_REFERENCE":throw new Error(a("Invalid reference"));case"SYMBOL":if(Qt.test(e.value))return{type:"REFERENCE",value:e.value};if(["TRUE","FALSE"].includes(e.value.toUpperCase()))return{type:"BOOLEAN",value:"TRUE"===e.value.toUpperCase()};if(e.value)throw new Error(a("Invalid formula"));return{type:"STRING",value:e.value};case"LEFT_PAREN":const o=Ar(t,5);if(!t.length||"RIGHT_PAREN"!==t[0].type)throw new Error(a("Unmatched left parenthesis"));return t.shift(),o;default:if("OPERATOR"===e.type&&wr.includes(e.value))return{type:"UNARY_OPERATION",value:e.value,right:Ar(t,xr[e.value])};throw new Error(a("Unexpected token: %s",e.value))}}(s,e);for(;e[0]&&Lr(e[0])>t;)i=Mr(i,e.shift(),e);return i}function _r(e){const t=hr(e).filter((e=>"SPACE"!==e.type));"OPERATOR"===t[0].type&&"="===t[0].value&&t.splice(0,1);const s=Ar(t,0);if(t.length)throw new Error(N);return s}function Or(e,t,s){switch(t===e.type&&(e=s(e)),e.type){case"FUNCALL":return{...e,args:e.args.map((e=>Or(e,t,s)))};case"UNARY_OPERATION":return{...e,right:Or(e.right,t,s)};case"BIN_OPERATION":return{...e,right:Or(e.right,t,s),left:Or(e.left,t,s)};default:return e}}function Nr(e,t={references:[],numbers:[],strings:[]}){switch(e.type){case"FUNCALL":const s=e.args.map((e=>Nr(e,t)));return`${e.value}(${s.join(",")})`;case"NUMBER":return e.value.toString();case"NORMALIZED_STRING":return`"${t.strings[e.value]}"`;case"NORMALIZED_NUMBER":return t.numbers[e.value].toString();case"NORMALIZED_REFERENCE":return t.references[e.value].toString();case"REFERENCE":case"STRING":default:return e.value;case"BOOLEAN":return e.value?"TRUE":"FALSE";case"UNARY_OPERATION":return e.value+kr(e,t);case"BIN_OPERATION":return function(e,t){const s=e.value,i=e.left,o=i.value;return"BIN_OPERATION"===i.type&&xr[o]<xr[s]?`(${Nr(i,t)})`:Nr(i,t)}(e,t)+e.value+kr(e,t)}}function kr(e,t){const s=e.value,i=e.right,o=xr[i.value],n=xr[s];let r=!1;return"BIN_OPERATION"!==i.type?r=!1:o<n?r=!0:o!==n||Tr.includes(s)||(r=!0),r?`(${Nr(i,t)})`:Nr(i,t)}const Fr=rr.content,$r={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},Dr={"-":"UMINUS","+":"UPLUS"};function Ur(e){return e.map((e=>e.split("\n"))).flat().filter((e=>""!==e.trim()))}const Pr={};function Br(e){if(!Pr[e.text]){const t=_r(e.text);let s=1;if("BIN_OPERATION"===t.type&&":"===t.value)throw new Error(a("Invalid formula"));if("UNKNOWN"===t.type)throw new Error(a("Invalid formula"));const i=l(t),o=Ur([`// ${e.text}`,i.code,`return ${i.id};`]).join("\n");let n=new Function("deps","sheetId","ref","range","ctx",o);function r(e){const t=Fr[e.value.toUpperCase()],s=e.args,i=s.length;if(i<t.minArgRequired)throw new Error(a("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",e.value.toUpperCase(),t.minArgRequired.toString(),i.toString()));if(i>t.maxArgPossible)throw new Error(a("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",e.value.toUpperCase(),t.maxArgPossible.toString(),i.toString()));const o=t.nbrArgRepeating;if(o>1){const s=t.args.length-o;if((i-s)%o!=0)throw new Error(a("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",e.value.toUpperCase(),s.toString(),o.toString()))}let n=[];for(let o=0;o<i;o++){const i=t.getArgToFocus(o+1)-1;if(0<=i&&i<t.args.length){const r=s[o],c=t.args[i],h=c.type||[],d=h.includes("META"),u=c.lazy,p=h.some((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e)),g=h.every((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e));if(g&&"NORMALIZED_REFERENCE"!==r.type)throw new Error(a("Function %s expects the parameter %s to be reference to a cell or range, not a %s.",e.value.toUpperCase(),(o+1).toString(),r.type.toLowerCase().replace("normalized_","")));const f=l(r,u,d,p,{functionName:e.value.toUpperCase(),paramIndex:o+1});n.push(f)}}return n}function l(t,i=!1,o=!1,n=!1,c={}){const h=[];let d,u,p;if("NORMALIZED_REFERENCE"!==t.type&&("BIN_OPERATION"!==t.type||":"!==t.value)&&o)throw new Error(a("Argument must be a reference to a cell or range."));switch(t.debug&&h.push("debugger;"),t.type){case"BOOLEAN":case"NUMBER":case"STRING":if(!i)return{id:t.value,code:""};d=s++,p=`${t.value}`;break;case"NORMALIZED_NUMBER":d=s++,p=`deps.numbers[${t.value}]`;break;case"NORMALIZED_STRING":d=s++,p=`deps.strings[${t.value}]`;break;case"REFERENCE":throw new Error(`Only normalized references can be compiled: ${t.value}`);case"NORMALIZED_REFERENCE":if(!e.dependencies.references[t.value]){d=s++,p="null";break}d=s++,p=n?`range(${t.value}, deps.references, sheetId)`:`ref(${t.value}, deps.references, sheetId, ${o?"true":"false"}, "${c.functionName||$r["="]}", ${c.paramIndex})`;break;case"FUNCALL":d=s++;const a=r(t);h.push(Ur(a.map((e=>e.code))).join("\n")),u=t.value.toUpperCase(),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}'](${a.map((e=>e.id))})`;break;case"UNARY_OPERATION":{d=s++,u=Dr[t.value];const e=l(t.right,!1,!1,!1,{functionName:u});h.push(e.code),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}']( ${e.id})`;break}case"BIN_OPERATION":{d=s++,u=$r[t.value];const e=l(t.left,!1,!1,!1,{functionName:u}),i=l(t.right,!1,!1,!1,{functionName:u});h.push(e.code),h.push(i.code),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}'](${e.id}, ${i.id})`;break}case"UNKNOWN":if(!i)return{id:"undefined",code:""};d=s++,p="undefined"}if(i){return{id:`_${d}`,code:`const _${d} = () => {\n\t${Ur(h).join("\n\t")}\n\treturn ${p};\n}`}}return h.push(`let _${d} = ${p};`),{id:`_${d}`,code:Ur(h).join("\n")}}function c(t){let s;switch(t.type){case"NORMALIZED_REFERENCE":if(e.dependencies.references[t.value])return[t.value];break;case"FUNCALL":if(s=Fr[t.value.toUpperCase()],s.returnFormat){if("FormatFromArgument"!==s.returnFormat)return[s.returnFormat.specificFormat];if(t.args.length>0){const e=0;if(!s.args[e].type.includes("META"))return c(t.args[e])}}break;case"UNARY_OPERATION":return c(t.right);case"BIN_OPERATION":if(s=Fr[$r[t.value]],s.returnFormat){if("FormatFromArgument"===s.returnFormat){const e=c(t.left);if("string"==typeof e[e.length-1])return e;const s=c(t.right);return e.concat(s)}return[s.returnFormat.specificFormat]}}return[]}Pr[e.text]=n,Pr[e.text].dependenciesFormat=c(t)}return Pr[e.text]}function Vr(e,t=!1){let s,i,o,n;const r=()=>{n=void 0,i=void 0,s=void 0,o=void 0};for(let a=0;a<e.length;a++){const l=e[a];if(n)if(i){if("SPACE"===l.type)continue;if("OPERATOR"===l.type&&":"===l.value)s=a;else if(s&&"SYMBOL"===l.type)o=a;else if(n&&i&&s&&o){const s={type:"SYMBOL",value:e.slice(n,a).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(n,a-n,s),a=n+1,r()}else"SYMBOL"===l.type?(n=a,i=a,s=void 0):r()}else"SYMBOL"===l.type?(i=a,s=o=void 0):r();else["SPACE","SYMBOL"].includes(l.type)?(n=a,i="SYMBOL"===l.type?a:void 0,s=o=void 0):r()}const a=e.length-1;if(n&&i&&s&&o){const s={type:"SYMBOL",value:e.slice(n,a+1).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(n,a-n+1,s)}return e}function Hr(e){return Vr(hr(e),!0)}function zr(e){return function(e){let t=[],s="";return e.map(((e,i)=>{switch(["SPACE","LEFT_PAREN"].includes(e.type)||(s=""),e.type){case"FUNCTION":s=e.value;break;case"LEFT_PAREN":t.push({parent:s,argPosition:0}),s="";break;case"RIGHT_PAREN":t.pop();break;case"COMMA":t.length&&t[t.length-1].argPosition++}if(t.length){const s=t[t.length-1];s.parent&&(e.functionContext=Object.assign({},s))}return e}))}(function(e){let t=1;const s=[];return e.map((e=>("LEFT_PAREN"===e.type?(s.push(t),e.parenIndex=t,t++):"RIGHT_PAREN"===e.type&&(e.parenIndex=s.pop()),e)))}(function(e){let t=0;return e.map((e=>{const s=e.value.toString().length,i=Object.assign({},e,{start:t,end:t+s,length:s});return t=i.end,i}))}(Vr(hr(e)))))}function Zr(e){const t=Hr(e);let s={numbers:[],strings:[],references:[]};return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Qt.test(e.value)){const t=e.value.trim();s.references.includes(t)||s.references.push(t);return Gr(s.references.indexOf(t).toString())}if("STRING"===e.type){const t=e.value.slice(1).slice(0,e.value.length-2);s.strings.includes(t)||s.strings.push(t);const i=s.strings.indexOf(t);return Gr(`${e.type[0]}${i}`)}if("NUMBER"===e.type){const t=te(e.value);s.numbers.includes(t)||s.numbers.push(t);const i=s.numbers.indexOf(t);return Gr(`${e.type[0]}${i}`)}return e.value}))),dependencies:s}}function Gr(e){return`${$}${e}${$}`}const Wr=new Le;function qr(e,t){switch(typeof e){case"string":return e.includes('\\"')?e.replace(/\\"/g,'"'):e;case"boolean":return e?"TRUE":"FALSE";case"number":return(null==t?void 0:t.match(A))?j({value:e,format:t}):t?function(e,t){const s=t.split(";"),i=s.length;return e<0?i>1?ae(-e,s[1]):"-"+ae(-e,s[0]):ae(e,s[3===i&&0===e?2:0])}(e,t):ie(e);case"object":return"0"}}function jr(e){return""===e?"":J(e)?te(e):Es(e)?"TRUE"===e.toUpperCase():bs(e)?G(e).value:e}class Yr{constructor(e,t,s){this.id=e,this.evaluated=t,this.style=s.style,this.format=s.format}isFormula(){return!1}isLink(){return!1}isEmpty(){return!1}get formattedValue(){return qr(this.evaluated.value,this.format)}get composerContent(){return this.content}get defaultAlign(){switch(this.evaluated.type){case ke.number:return"right";case ke.boolean:case ke.error:return"center";case ke.text:case ke.empty:return"left"}}get isAutoSummable(){var e;switch(this.evaluated.type){case ke.empty:case ke.text:return!0;case ke.number:return!(null===(e=this.format)||void 0===e?void 0:e.match(A));case ke.error:case ke.boolean:return!1}}}class Xr extends Yr{constructor(e,t={}){super(e,{value:"",type:ke.empty},t),this.content=""}isEmpty(){return!0}}class Kr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.number},s),this.content=ie(this.evaluated.value)}}class Qr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.boolean},s),this.content=this.evaluated.value?"TRUE":"FALSE"}}class Jr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.text},s),this.content=this.evaluated.value}}class ea extends Kr{constructor(e,t,s){super(e,t,s),this.format=s.format}get composerContent(){return qr(this.evaluated.value,this.format)}}class ta extends Yr{constructor(e,t,s={}){const i=ws(t);super(e,{value:i.label,type:ke.text},s),this.link=i,this.content=t}isLink(){return!0}get composerContent(){return this.link.label}}class sa extends ta{constructor(e,t,s={}){super(e,t,s),this.link.url=this.withHttp(this.link.url),this.link.isExternal=!0,this.content=ys(this.link.label,this.link.url),this.urlRepresentation=this.link.url,this.isUrlEditable=!0}action(e){window.open(this.link.url,"_blank")}withHttp(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}}class ia extends ta{constructor(e,t,s={},i){super(e,t,s),this.sheetName=i,this.sheetId=Rs(this.link.url),this.isUrlEditable=!1}action(e){e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}get urlRepresentation(){return this.sheetName(this.sheetId)||a("Invalid sheet")}}class oa extends Yr{constructor(e,t,s,i,o,n){super(t,{value:"Loading...",type:ke.text},n),this.buildFormulaString=e,this.normalizedText=s,this.compiledFormula=i,this.dependencies=o}get content(){return this.buildFormulaString(this.normalizedText,this.dependencies)}isFormula(){return!0}assignValue(e){switch(typeof e){case"number":this.evaluated={value:e,type:ke.number};break;case"boolean":this.evaluated={value:e,type:ke.boolean};break;case"string":this.evaluated={value:e,type:ke.text};break;case"object":case"undefined":this.evaluated={value:e,type:ke.empty}}}assignError(e,t){this.evaluated={value:e,error:t,type:ke.error}}}class na extends Yr{constructor(e,t,s,i){super(e,{value:"#BAD_EXPR",type:ke.error,error:s},i),this.content=t}}function ra(e){const t=Hr(e);let s=[];return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Qt.test(e.value)){const t=e.value.trim();return s.includes(t)||s.push(t),`${$}${s.indexOf(t)}${$}`}return e.value}))),dependencies:s}}Wr.add("Formula",{sequence:10,match:e=>e.startsWith("="),createCell:(e,t,s,i,o)=>{const n=Zr(t),r=n.text,a=Br(n),l=n.dependencies.references.map((e=>o.getRangeFromSheetXC(i,e))),c=s.format||function(e,t,s){var i;const o=t.dependenciesFormat;for(let t of o)switch(typeof t){case"string":return t;case"number":const o=s[t],n=e[o.sheetId];if(n){const e=null===(i=n.rows[o.zone.top])||void 0===i?void 0:i.cells[o.zone.left];if(e&&e.format)return e.format}}return F}(o.getEvaluationSheets(),a,l);return new oa(((e,t)=>o.buildFormulaContent(i,e,t)),e,r,a,{...n.dependencies,references:l},{...s,format:c})}}).add("Empty",{sequence:20,match:e=>""===e,createCell:(e,t,s)=>new Xr(e,s)}).add("Number",{sequence:30,match:e=>J(e),createCell:(e,t,s)=>(!s.format&&t.includes("%")&&(s.format=t.includes(".")?"0.00%":"0%"),new Kr(e,te(t),s))}).add("Boolean",{sequence:40,match:e=>Es(e),createCell:(e,t,s)=>new Qr(e,"TRUE"===t.toUpperCase(),s)}).add("DateTime",{sequence:50,match:e=>bs(e),createCell:(e,t,s)=>{const i=G(t),o=s.format||i.format;return new ea(e,i.value,{...s,format:o})}}).add("MarkdownSheetLink",{sequence:60,match:e=>xs(e),createCell:(e,t,s,i,o)=>new ia(e,t,s,(e=>o.tryGetSheetName(e)))}).add("MarkdownLink",{sequence:70,match:e=>Is(e),createCell:(e,t,s)=>new sa(e,t,s)}).add("WebLink",{sequence:80,match:e=>{return t=e,Cs.test(t);var t},createCell:(e,t,s)=>new sa(e,ys(t,t),s)});const aa=10,la="Sheet1";function ca(e){return e?("version"in(e=JSON.parse(JSON.stringify(e)))&&e.version<aa&&(e=function(e){for(let t=ha.findIndex((t=>t.from===e.version));t<ha.length;t++)e=ha[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,s=new oi;for(const i of e.sheets||[])for(const e of i.figures||[])t.has(e.id)&&(e.id+=s.uuidv4()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(ga(),e,{version:aa}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(pa(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(pa(la,"Sheet1"));return e}(e),e}(e),e):ga()}const ha=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const s=t.cells[e];s.content&&s.content.startsWith("=")&&(s.formula=ra(s.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:s,...i}=t.figures[e].data,o=[];for(let e of s)if(e.labelCell){const t=ks(e.dataRange),s=e.labelCell+":"+is(t.right,t.bottom);o.push(s)}else o.push(e.dataRange);i.dataSetsHaveTitle=Boolean(s[0].labelCell),i.dataSets=o,t.figures[e].data=i}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const s=[],i=new RegExp(k,"g");for(let o of e.sheets||[]){if(!o.name)continue;const e=o.name,n=e.replace(i,"_");let r=1,a=n;for(;s.includes(a);)a=`${n}${r}`,r++;o.name=a,s.push(a);const l=t=>{if(void 0===t)return t;let s=t.replace(e,a),i=t;for(;i!==s;)i=s,s=i.replace(e,a);return i};for(let e in o.cells){const t=o.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of o.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),s=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:s}}for(let e of o.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const s of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[s])||void 0===t?void 0:t.type)&&(e.rule[s].value=l(e.rule[s].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=g,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stackedBar=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const s=t.cells[e];if(s.formula){let{text:e,dependencies:t}=s.formula;for(let[s,i]of Object.entries(t)){const t=`\\${$}${s}\\${$}`;e=e.replace(new RegExp(t,"g"),i)}s.content=e,delete s.formula}}return e}}];function da(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const s=[],i=[],o=e=>{if("CREATE_SHEET"===e.type)s.push(e.sheetId);else if("sheetId"in e&&!s.includes(e.sheetId))return{...e,sheetId:la};return e};for(const e of t)"REMOTE_REVISION"===e.type?i.push({...e,commands:e.commands.map(o)}):i.push(e);return i}(e,t),t=ua(t,"SORT_CELLS"),t=ua(t,"SET_DECIMAL")}function ua(e,t){const s=[];for(const i of e)"REMOTE_REVISION"===i.type?s.push({...i,commands:i.commands.filter((e=>e.type!==t))}):s.push(i);return s}function pa(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[]}}function ga(e="Sheet1"){return{version:aa,sheets:[pa(la,e)],entities:{},styles:{},borders:{},revisionId:O,uniqueFigureIds:!0}}class fa{constructor(e,t,s){this.history=Object.assign(Object.create(e),{update:e.addChange.bind(e,this),selectCell:()=>{}}),this.dispatch=t,this.currentMode=s.mode}allowDispatch(e){return 0}beforeHandle(e){}handle(e){}finalize(){}batchValidations(...e){return t=>e.map((e=>e.call(this,t))).flat()}chainValidations(...e){return t=>{for(const s of e){let e=s.call(this,t);Array.isArray(e)||(e=[e]);const i=e.filter((e=>0!==e));if(i.length)return i}return 0}}checkValidations(e,...t){return this.batchValidations(...t)(e)}}fa.getters=[],fa.modes=["headless","normal"];class ma extends fa{constructor(e,t,s,i,o,n){super(t,i,o),this.dispatch=i,this.range=s,s.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=n}import(e){}export(e){}exportForExcel(e){}adaptRanges(e,t){}}class va extends ma{constructor(){super(...arguments),this.borders={}}handle(e){switch(e.type){case"ADD_MERGE":if(!e.interactive)for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const s=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,s)}break;case"DELETE_SHEET":const s={...this.borders};delete s[e.sheetId],this.history.update("borders",s);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=this.getters.getSheet(e.sheetId),s=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(t,s,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":for(let t of e.elements)"COL"===e.dimension?this.shiftBordersHorizontally(e.sheetId,t+1,-1):this.shiftBordersVertically(e.sheetId,t+1,-1);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){const t=this.getters.getSheet(e.sheetId);let s,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),s=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),s=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(t,s,i)}handleAddRows(e){const t=this.getters.getSheet(e.sheetId);let s,i;"before"===e.position?(this.shiftBordersVertically(t.id,e.base,e.quantity,{moveFirstTopBorder:!0}),s=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(t.id,e.base+1,e.quantity,{moveFirstTopBorder:!1}),s=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(t,s,i)}getCellBorder(e,t,s){var i,o,n,r,a,l,c,h,d,u,p,g;const f={top:null===(n=null===(o=null===(i=this.borders[e])||void 0===i?void 0:i[t])||void 0===o?void 0:o[s])||void 0===n?void 0:n.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[s+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[s])||void 0===d?void 0:d.vertical,right:null===(g=null===(p=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===p?void 0:p[s])||void 0===g?void 0:g.vertical};return f.bottom||f.left||f.right||f.top?f:null}ensureColumnBorderContinuity(e,t,s){const i=fs(t+1,s);for(let o=0;o<e.rows.length;o++){const n=this.getCellBorder(e.id,t,o),r=this.getCellBorder(e.id,s,o);if(n&&r){const t=this.getCommonSides(n,r);for(let s of i)this.addBorder(e.id,s,o,t)}}}ensureRowBorderContinuity(e,t,s){const i=fs(t+1,s);for(let o=0;o<e.cols.length;o++){const n=this.getCellBorder(e.id,o,t),r=this.getCellBorder(e.id,o,s);if(n&&r){const t=this.getCommonSides(n,r);for(let s of i)this.addBorder(e.id,o,s,t)}}}getCommonSides(e,t){const s={};for(let i of["top","bottom","left","right"])e[i]&&e[i]===t[i]&&(s[i]=e[i]);return s}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsRange(e){if(!this.borders[e])return[];return fs(0,this.getters.getSheet(e).rows.length+1)}shiftBordersHorizontally(e,t,s,{moveFirstLeftBorder:i}={}){this.borders[e]&&(s<0&&this.moveBordersOfColumn(e,t,s,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>s<0?e-t:t-e)).forEach((o=>{(o===t&&i||o!==t)&&this.moveBordersOfColumn(e,o,s,"vertical"),this.moveBordersOfColumn(e,o,s,"horizontal")})))}shiftBordersVertically(e,t,s,{moveFirstTopBorder:i}={}){this.borders[e]&&(s<0&&this.moveBordersOfRow(e,t,s,"horizontal",{destructive:!1}),this.getRowsRange(e).filter((e=>e>=t)).sort(((e,t)=>s<0?e-t:t-e)).forEach((o=>{(o===t&&i||o!==t)&&this.moveBordersOfRow(e,o,s,"horizontal"),this.moveBordersOfRow(e,o,s,"vertical")})))}moveBordersOfRow(e,t,s,i,{destructive:o}={destructive:!0}){const n=this.borders[e];n&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=n[r])||void 0===a?void 0:a[t+s])||void 0===l?void 0:l[i],u=null===(h=null===(c=n[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i];this.history.update("borders",e,r,t+s,i,o?u:u||d),this.history.update("borders",e,r,t,i,void 0)}))}moveBordersOfColumn(e,t,s,i,{destructive:o}={destructive:!0}){const n=this.borders[e];n&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=n[t+s])||void 0===a?void 0:a[r])||void 0===l?void 0:l[i],u=null===(h=null===(c=n[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[i];this.history.update("borders",e,t+s,r,i,o?u:u||d),this.history.update("borders",e,t,r,i,void 0)}))}setBorder(e,t,s,i){this.history.update("borders",e,t,s,{vertical:null==i?void 0:i.left,horizontal:null==i?void 0:i.top}),this.history.update("borders",e,t+1,s,"vertical",null==i?void 0:i.right),this.history.update("borders",e,t,s+1,"horizontal",null==i?void 0:i.bottom)}clearBorders(e,t){for(let s of t){for(let t=s.top;t<=s.bottom;t++){this.history.update("borders",e,s.right+1,t,"vertical",void 0);for(let i=s.left;i<=s.right;i++)this.history.update("borders",e,i,t,void 0)}for(let t=s.left;t<=s.right;t++)this.history.update("borders",e,t,s.bottom+1,"horizontal",void 0)}}addBorder(e,t,s,i){this.setBorder(e,t,s,{...this.getCellBorder(e,t,s),...i})}setBorders(e,t,s){const i=e.id;if("clear"===s)return this.clearBorders(i,t);for(let e of t){if("h"===s||"hv"===s||"all"===s)for(let t=e.top+1;t<=e.bottom;t++)for(let s=e.left;s<=e.right;s++)this.addBorder(i,s,t,{top:L});if("v"===s||"hv"===s||"all"===s)for(let t=e.top;t<=e.bottom;t++)for(let s=e.left+1;s<=e.right;s++)this.addBorder(i,s,t,{left:L});if("left"===s||"all"===s||"external"===s)for(let t=e.top;t<=e.bottom;t++)this.addBorder(i,e.left,t,{left:L});if("right"===s||"all"===s||"external"===s)for(let t=e.top;t<=e.bottom;t++)this.addBorder(i,e.right+1,t,{left:L});if("top"===s||"all"===s||"external"===s)for(let t=e.left;t<=e.right;t++)this.addBorder(i,t,e.top,{top:L});if("bottom"===s||"all"===s||"external"===s)for(let t=e.left;t<=e.right;t++)this.addBorder(i,t,e.bottom+1,{top:L})}}addBordersToMerge(e,t){const s=this.getters.getSheet(e),{left:i,right:o,top:n,bottom:r}=t,a=this.getCellBorder(s.id,i,n),l=this.getCellBorder(s.id,o,r);this.clearBorders(e,[t]),(null==a?void 0:a.top)&&this.setBorders(s,[{...t,bottom:n}],"top"),(null==a?void 0:a.left)&&this.setBorders(s,[{...t,right:i}],"left"),((null==l?void 0:l.bottom)||(null==a?void 0:a.bottom))&&this.setBorders(s,[{...t,top:r}],"bottom"),((null==l?void 0:l.right)||(null==a?void 0:a.right))&&this.setBorders(s,[{...t,left:o}],"right")}import(e){if(e.borders)for(let t of e.sheets)for(let[s,i]of Object.entries(t.cells))if(null==i?void 0:i.border){const o=e.borders[i.border],[n,r]=ss(s);this.setBorder(t.id,n,r,o)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,ks(e))}export(e){let t=0;const s={};function i(e){for(let[t,i]of Object.entries(s))if(As(i,e))return parseInt(t,10);return s[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let s=0;s<t.rowNumber;s++){const o=this.getCellBorder(t.id,e,s);if(o){const n=is(e,s),r=t.cells[n],a=i(o);r?r.border=a:t.cells[n]={border:a}}}e.borders=s}exportForExcel(e){this.export(e)}}va.getters=["getCellBorder"];const Ea=new RegExp(String.fromCharCode(160),"g"),ba={textColor:M,underline:!0};class Sa extends ma{constructor(){super(...arguments),this.cells={},this.cellUuidGenerator=new oi(!0),this.createCell=function(e){const t=Wr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(s,i,o,n){const r=t.find((e=>e.match(i)));if(!r)return new Jr(s,i,o);try{return r.createCell(s,i,o,n,e)}catch(e){return new na(s,i,e.message||N,o)}}}(this.getters)}adaptRanges(e,t){for(const s of Object.keys(this.cells))for(const i of Object.values(this.cells[s]||{}))if(i.isFormula())for(const o of i.dependencies.references)if(!t||o.sheetId===t){const t=e(o);"NONE"!==t.changeType&&this.history.update("cells",s,i.id,"dependencies","references",i.dependencies.references.indexOf(o),t.range)}}allowDispatch(e){switch(e.type){case"UPDATE_CELL":case"CLEAR_CELL":return this.checkCellOutOfSheet(e.sheetId,e.col,e.row);default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearStyles(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(this.getters.getSheet(e.sheetId),e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""})}}setFormatter(e,t,s){for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,format:s})}clearStyles(e,t){for(let s of t)for(let t=s.left;t<=s.right;t++)for(let i=s.top;i<=s.bottom;i++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,style:null})}handleAddColumnsRows(e,t){const s=this.getters.getSheet(e.sheetId);let i,o;"before"===e.position?(i=fs(e.base,e.base+e.quantity),o=e.base+e.quantity):(i=fs(e.base+1,e.base+e.quantity+1),o=e.base),t(s,o,i)}import(e){for(let t of e.sheets){const s=this.getters.getSheet(t.id);for(let i in t.cells){const o=t.cells[i],[n,r]=ss(i);if((null==o?void 0:o.content)||(null==o?void 0:o.format)||(null==o?void 0:o.style)){const i=this.importCell(s,o,e.styles);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cell:i,cellId:i.id,col:n,row:r,sheetId:t.id})}}}}export(e){let t=0;const s={};function i(e){for(let[t,i]of Object.entries(s))if(As(i,e))return parseInt(t,10);return s[++t]=e,t}for(let t of e.sheets){const e={},s=Object.keys(this.cells[t.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const{col:o,row:n}of s){const s=this.getters.getCell(t.id,o,n);e[is(o,n)]={style:s.style&&i(s.style),format:s.format,content:s.content}}t.cells=e}e.styles=s}importCell(e,t,s){const i=t.style&&s[t.style]||void 0,o=this.cellUuidGenerator.uuidv4(),n={format:null==t?void 0:t.format,style:i};return this.createCell(o,(null==t?void 0:t.content)||"",n,e.id)}exportForExcel(e){this.export(e);for(let t of e.sheets)for(const e in t.cells){const[s,i]=ss(e),o=this.getters.getCell(t.id,s,i),n=t.cells[e];n.value=o.evaluated.value,n.isFormula=o.isFormula()}}getCells(e){return this.cells[e]||{}}getCellById(e){const t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}buildFormulaContent(e,t,s){let i=t;for(let[t,o]of Object.entries(s.references)){const s=this.getters.getRangeString(o,e),n=`\\${$}${t}\\${$}`;i=i.replace(new RegExp(n,"g"),s)}for(let[e,t]of Object.entries(s.strings)){const s=`\\${$}S${e}\\${$}`;i=i.replace(new RegExp(s,"g"),`"${t}"`)}for(let[e,t]of Object.entries(s.numbers)){const s=`\\${$}N${e}\\${$}`;i=i.replace(new RegExp(s,"g"),t.toString())}return i}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t.normalizedText,t.dependencies)}getCellStyle(e){return{...e.isLink()?ba:{},...e.style}}zoneToXC(e,t,s=[{colFixed:!1,rowFixed:!1}]){const i=is((t=this.getters.expandZone(e,t)).left,t.top,s[0]),o=is(t.right,t.bottom,s.length>1?s[1]:s[0]),n=this.getters.getMainCell(e,t.left,t.top),r=this.getters.getMainCell(e,t.right,t.bottom),a=n[0]==r[0]&&n[1]==r[1];return i==o||a?i:i+":"+o}setStyle(e,t,s){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++){const i=this.getters.getCell(e,t,o);this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:s?{...null==i?void 0:i.style,...s}:void 0})}}copyColumnStyle(e,t,s){for(let i=0;i<e.rows.length;i++){const o=this.getFormat(e.id,t,i);if(o.style||o.format)for(let t of s)this.dispatch("UPDATE_CELL",{sheetId:e.id,col:t,row:i,...o})}}copyRowStyle(e,t,s){for(let i=0;i<e.cols.length;i++){const o=this.getFormat(e.id,i,t);if(o.style||o.format)for(let t of s)this.dispatch("UPDATE_CELL",{sheetId:e.id,col:i,row:t,...o})}}getFormat(e,t,s){const i={},[o,n]=this.getters.getMainCell(e,t,s),r=this.getters.getCell(e,o,n);return r&&(r.style&&(i.style=r.style),r.format&&(i.format=r.format)),i}updateCell(e,t,s,i){var o;const n=e.rows[s].cells[t],r="content"in i||"formula"in i,a=r?(null===(o=i.content)||void 0===o?void 0:o.replace(Ea,""))||"":(null==n?void 0:n.content)||"";let l;l=void 0!==i.style?i.style||void 0:n?n.style:void 0;let c=("format"in i?i.format:n&&n.format)||F;if((r&&!a&&!i.formula||!r&&(!n||n.isEmpty()))&&!l&&!c)return void(n&&(this.history.update("cells",e.id,n.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:n.id,col:t,row:s,sheetId:e.id,cell:void 0})));const h=(null==n?void 0:n.id)||this.cellUuidGenerator.uuidv4(),d=r,u={format:c,style:l},p=this.createCell(h,a,u,e.id);n&&!d&&p.isFormula()&&(p.assignValue(n.evaluated.value),n.evaluated.type===ke.error&&p.assignError(n.evaluated.value,n.evaluated.error)),this.history.update("cells",e.id,p.id,p),this.dispatch("UPDATE_CELL_POSITION",{cell:p,cellId:p.id,col:t,row:s,sheetId:e.id})}checkCellOutOfSheet(e,t,s){const i=this.getters.tryGetSheet(e);if(!i)return 23;return Hs(t,s,{top:0,left:0,bottom:i.rows.length-1,right:i.cols.length-1})?0:18}}Sa.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class Ca extends ma{constructor(){super(...arguments),this.chartFigures={}}adaptRanges(e){for(let[t,s]of Object.entries(this.chartFigures))s&&(this.adaptDataSetRanges(s,t,e),this.adaptLabelRanges(s,t,e))}adaptDataSetRanges(e,t,s){for(let i of e.dataSets){if(i.labelCell){const o=s(i.labelCell);switch(o.changeType){case"REMOVE":this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"labelCell",void 0);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"labelCell",o.range)}}const o=s(i.dataRange);switch(o.changeType){case"REMOVE":const s=e.dataSets.filter((e=>e!==i));this.history.update("chartFigures",t,"dataSets",s);break;case"RESIZE":case"MOVE":case"CHANGE":if(this.getters.getRangeString(o.range,o.range.sheetId)!==_)this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"dataRange",o.range);else{const s=e.dataSets.filter((e=>e!==i));this.history.update("chartFigures",t,"dataSets",s)}}}}adaptLabelRanges(e,t,s){if(e.labelRange){const i=s(e.labelRange);switch(i.changeType){case"REMOVE":this.history.update("chartFigures",t,"labelRange",void 0);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("chartFigures",t,"labelRange",i.range)}}}allowDispatch(e){switch(e.type){case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.checkEmptyDataset,this.checkDataset,this.checkChartExists),this.checkLabelRange);case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.checkEmptyDataset,this.checkDataset,this.checkChartDuplicate),this.checkLabelRange);default:return 0}}handle(e){var t,s;switch(e.type){case"CREATE_CHART":const i=e.position?e.position.x:0,o=e.position?e.position.y:0;this.addChartFigure(e.sheetId,this.createChartDefinition(e.definition,e.sheetId),{id:e.id,x:i,y:o,height:335,width:536,tag:"chart"});break;case"UPDATE_CHART":this.updateChartDefinition(e.id,e.definition);break;case"DUPLICATE_SHEET":{const s=this.getters.getFigures(e.sheetId);for(const i of s)if("chart"===i.tag){const s=i.id.split("??").pop(),o=`${e.sheetIdTo}??${s}`,n={...ds(this.chartFigures[i.id]),id:o};n.sheetId=e.sheetIdTo,n.dataSets.forEach((t=>{var s;t.dataRange.sheetId===e.sheetId&&(t.dataRange.sheetId=e.sheetIdTo),(null===(s=t.labelCell)||void 0===s?void 0:s.sheetId)===e.sheetId&&(t.labelCell.sheetId=e.sheetIdTo)})),(null===(t=n.labelRange)||void 0===t?void 0:t.sheetId)===e.sheetId&&(n.labelRange.sheetId=e.sheetIdTo);const r={id:o,x:i.x,y:i.y,height:i.height,width:i.width,tag:"chart"};this.addChartFigure(e.sheetIdTo,n,r)}break}case"DELETE_FIGURE":this.history.update("chartFigures",e.id,void 0);break;case"DELETE_SHEET":for(let t of Object.keys(this.chartFigures))(null===(s=this.chartFigures[t])||void 0===s?void 0:s.sheetId)===e.sheetId&&this.history.update("chartFigures",t,void 0)}}getChartDefinition(e){return this.chartFigures[e]}getChartsIdBySheet(e){return Object.entries(this.chartFigures).filter((t=>t[1].sheetId===e)).map((e=>e[0]))}getChartDefinitionUI(e,t){const s=this.chartFigures[t];if(!s)return;const i=s.dataSets.map((t=>t?this.getters.getRangeString(t.dataRange,e):"")).filter((e=>""!==e));return{title:s&&s.title?s.title:"",dataSets:i,labelRange:s.labelRange?this.getters.getRangeString(s.labelRange,e):void 0,type:s?s.type:"bar",dataSetsHaveTitle:!(!s||0===i.length)&&Boolean(s.dataSets[0].labelCell),background:s.background,verticalAxisPosition:s.verticalAxisPosition,legendPosition:s.legendPosition,stackedBar:s.stackedBar}}getChartDefinitionExcel(e,t){const s=this.chartFigures[t],i=this.getChartDefinitionUI("forceSheetReference",t);if(!s||!i)return;const o=s.dataSets.map((e=>this.toExcelDataset(e))).filter((e=>""!==e.range));return{...i,backgroundColor:s.background,dataSets:o}}toExcelDataset(e){var t;const s=null===(t=e.labelCell)||void 0===t?void 0:t.zone;let i=e.dataRange.zone;if(s){const{height:e,width:t}=Ws(i);1===e?i={...i,left:i.left+1}:1===t&&(i={...i,top:i.top+1})}const o={...e.dataRange,zone:i};return{label:e.labelCell?this.getters.getRangeString(e.labelCell,"forceSheetReference"):void 0,range:this.getters.getRangeString(o,"forceSheetReference")}}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)if("chart"===e.tag){const s={...e.data};this.chartFigures[e.id]=this.createChartDefinition(s,t.id),delete e.data}}export(e){if(e.sheets)for(let t of e.sheets){const e=this.getters.getFigures(t.id),s=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=this.getChartDefinitionUI(t.id,e.id);i&&(e.data=i,s.push(e))}else s.push(e)}t.figures=s}}exportForExcel(e){for(let t of e.sheets){const e=this.getters.getFigures(t.id),s=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=this.getChartDefinitionExcel(t.id,e.id);i&&(e.data=i,s.push(e))}else s.push(e)}t.charts=s}}createChartDefinition(e,t){return{...e,dataSets:this.createDataSets(e.dataSets,t,e.dataSetsHaveTitle),labelRange:e.labelRange?this.getters.getRangeFromSheetXC(t,e.labelRange):void 0,sheetId:t}}updateChartDefinition(e,t){const s=this.chartFigures[e];if(!s)throw new Error(`There is no chart with the given id: ${e}`);if(void 0!==t.title&&this.history.update("chartFigures",e,"title",t.title),t.type&&this.history.update("chartFigures",e,"type",t.type),t.dataSets){const i=!!t.dataSetsHaveTitle,o=this.createDataSets(t.dataSets,s.sheetId,i);this.history.update("chartFigures",e,"dataSets",o)}if(void 0!==t.labelRange){const i=t.labelRange?this.getters.getRangeFromSheetXC(s.sheetId,t.labelRange):void 0;this.history.update("chartFigures",e,"labelRange",i)}t.background&&this.history.update("chartFigures",e,"background",t.background),t.verticalAxisPosition&&this.history.update("chartFigures",e,"verticalAxisPosition",t.verticalAxisPosition),t.legendPosition&&this.history.update("chartFigures",e,"legendPosition",t.legendPosition),void 0!==t.stackedBar&&this.history.update("chartFigures",e,"stackedBar",t.stackedBar)}createDataSets(e,t,s){const i=[];for(const o of e){const e=this.getters.getRangeFromSheetXC(t,o),{zone:n,sheetId:r,invalidSheetName:a}=e;if(!a)if(n.left!==n.right&&n.top!==n.bottom)for(let e=n.left;e<=n.right;e++){const t={left:e,right:e,top:n.top,bottom:n.bottom};i.push(this.createDataSet(r,t,s?{top:t.top,bottom:t.top,left:t.left,right:t.left}:void 0))}else n.left===n.right&&n.top===n.bottom?s||i.push(this.createDataSet(r,n,void 0)):i.push(this.createDataSet(r,n,s?{top:n.top,bottom:n.top,left:n.left,right:n.left}:void 0))}return i}addChartFigure(e,t,s){this.dispatch("CREATE_FIGURE",{sheetId:e,figure:s}),this.history.update("chartFigures",s.id,t)}createDataSet(e,t,s){if(t.left!==t.right&&t.top!==t.bottom)throw new Error(`Zone should be a single column or row: ${$s(t)}`);if(s){const i=$s(t),o=$s(s);return{labelCell:this.getters.getRangeFromSheetXC(e,o),dataRange:this.getters.getRangeFromSheetXC(e,i)}}return{labelCell:void 0,dataRange:this.getters.getRangeFromSheetXC(e,$s(t))}}checkEmptyDataset(e){return e.definition.dataSets&&0===e.definition.dataSets.length?27:0}checkDataset(e){if(!e.definition.dataSets)return 0;const t=void 0!==e.definition.dataSets.find((e=>!Jt.test(e)));return t?28:0}checkLabelRange(e){if(!e.definition.labelRange)return 0;return!Jt.test(e.definition.labelRange||"")?29:0}checkChartDuplicate(e){for(const t of this.getters.getSheets())if(this.getters.getFigure(t.id,e.id))return 57;return 0}checkChartExists(e){return this.getters.getFigure(e.sheetId,e.id)?0:58}}function Ia(e){return""===e?NaN:Number(e)}Ca.getters=["getChartDefinition","getChartDefinitionUI","getChartsIdBySheet"];class ya extends ma{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const s of this.cfRules[e])for(const i of s.ranges){const o=t(i);switch(o.changeType){case"REMOVE":let t=s.ranges.slice();t.splice(s.ranges.indexOf(i),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(s),"ranges",t):this.removeConditionalFormatting(s.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(s),"ranges",s.ranges.indexOf(i),o.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){return"ADD_CONDITIONAL_FORMAT"===e.type?this.checkValidations(e,this.checkCFRule,this.checkEmptyRange):0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const s={...e.cf,ranges:e.target.map($s)};this.addConditionalFormatting(s,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){this.export(e)}getConditionalFormats(e){return this.cfRules[e].map((t=>this.mapToConditionalFormat(e,t)))||[]}getRulesSelection(e,t){const s=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{s.add(e)}))})),Array.from(s)}getRulesByZone(e,t){const s=new Set;for(let i=t.top;i<=t.bottom;i++)for(let o=t.left;o<=t.right;o++){this.getRulesByCell(e,o,i).forEach((e=>{s.add(e.id)}))}return s}getRulesByCell(e,t,s){const i=[];for(let o of this.cfRules[e])for(let e of o.ranges)Hs(t,s,e.zone)&&i.push(o);return new Set(i.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e)))}}mapToConditionalFormatInternal(e,t){const s={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return s}addConditionalFormatting(e,t){const s=this.cfRules[t].slice(),i=s.findIndex((t=>t.id===e.id)),o=this.mapToConditionalFormatInternal(t,e);i>-1?s.splice(i,1,o):s.push(o),this.history.update("cfRules",t,s)}checkEmptyRange(e){return e.target.length?0:21}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return s=>{if(t.includes(s.operator)){const t=[],i=e=>void 0===e||""===e;return e>=1&&i(s.values[0])&&t.push(36),e>=2&&i(s.values[1])&&t.push(37),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 38;case"max":return 40;case"mid":return 39;case"upperInflectionPoint":return 41;case"lowerInflectionPoint":return 42}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{Br(Zr(e.value||""))}catch(e){switch(t){case"min":return 43;case"max":return 45;case"mid":return 44;case"upperInflectionPoint":return 46;case"lowerInflectionPoint":return 47}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,s=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(s)?33:0}checkMinBiggerThanMax(e){const t=e.minimum.value,s=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&Ia(t)>=Ia(s)?32:0}checkMidBiggerThanMax(e){var t;const s=null===(t=e.midpoint)||void 0===t?void 0:t.value,i=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&Ia(s)>=Ia(i)?34:0}checkMinBiggerThanMid(e){var t;const s=e.minimum.value,i=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&Ia(s)>=Ia(i)?35:0}removeConditionalFormatting(e,t){const s=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==s){const e=this.cfRules[t].slice();e.splice(s,1),this.history.update("cfRules",t,e)}}}ya.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class wa extends ma{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.getters.getFigures(e.sheetId).forEach((t=>{this.dispatch("DELETE_FIGURE",{id:t.id,sheetId:e.sheetId})})),this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:s,...i}=e,o=i;this.updateFigure(s,o);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[s,i]of Object.entries(t))switch(s){case"x":case"y":void 0!==i&&this.history.update("figures",e,t.id,s,Math.max(i,0));break;case"width":case"height":void 0!==i&&this.history.update("figures",e,t.id,s,i)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var s;return void 0===(null===(s=this.figures[e])||void 0===s?void 0:s[t])?55:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?56:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(Ls)}getFigure(e,t){var s;return null===(s=this.figures[e])||void 0===s?void 0:s[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var s;return void 0!==(null===(s=this.figures[t])||void 0===s?void 0:s[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const s=void 0;t.figures.push({...e,data:s})}}exportForExcel(e){this.export(e)}}wa.getters=["getFigures","getFigure","getFigureSheetId"];class Ta extends ma{constructor(){super(...arguments),this.nextId=1,this.pending=null,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?0:this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}beforeHandle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.exportAndRemoveMerges(e.sheetId,(t=>function(e,t){let{left:s,right:i,top:o,bottom:n}=ks(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)s>e&&(s-=1),(s>=e||i>=e)&&(i-=1);return s>i?null:is(s,o)+":"+is(i,n)}(t,e.elements)),!0):this.exportAndRemoveMerges(e.sheetId,(t=>function(e,t){let{left:s,right:i,top:o,bottom:n}=ks(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)o>e&&(o-=1),(o>=e||n>=e)&&(n-=1);return o>n?null:is(s,o)+":"+is(i,n)}(t,e.elements)),!1);break;case"ADD_COLUMNS_ROWS":const t="before"===e.position?e.base:e.base+1;"COL"===e.dimension?this.exportAndRemoveMerges(e.sheetId,(s=>function(e,t,s){let{left:i,right:o,top:n,bottom:r}=ks(e);return i>=t&&(i+=s),(i>=t||o>=t)&&(o+=s),i>o?null:is(i,n)+":"+is(o,r)}(s,t,e.quantity)),!0):this.exportAndRemoveMerges(e.sheetId,(s=>function(e,t,s){let{left:i,right:o,top:n,bottom:r}=ks(e);return n>=t&&(n+=s),(n>=t||r>=t)&&(r+=s),n>r?null:is(i,n)+":"+is(o,r)}(s,t,e.quantity)),!1)}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":this.history.update("merges",e.sheetIdTo,Object.assign({},this.merges[e.sheetId])),this.history.update("mergeCellMap",e.sheetIdTo,Object.assign({},this.mergeCellMap[e.sheetId]));break;case"ADD_MERGE":if(!e.interactive)for(const t of e.target)this.addMerge(this.getters.getSheet(e.sheetId),t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t);break;case"ADD_COLUMNS_ROWS":case"REMOVE_COLUMNS_ROWS":this.pending&&(this.importMerges(this.pending.sheet,this.pending.merges),this.pending=null)}}getMerges(e){return Object.values(this.merges[e]||{}).filter(Ls)}getMerge(e,t,s){var i;const o=this.mergeCellMap[e],n=o?t in o&&(null===(i=o[t])||void 0===i?void 0:i[s]):void 0;return n?this.getMergeById(e,n):void 0}doesIntersectMerge(e,t){const{left:s,right:i,top:o,bottom:n}=t;for(let t=o;t<=n;t++)for(let o=s;o<=i;o++)if(this.getMerge(e,o,t))return!0;return!1}doesColumnsHaveCommonMerges(e,t,s){const i=this.getters.getSheet(e);for(let e=0;e<i.rows.length;e++)if(this.isInSameMerge(i.id,t,e,s,e))return!0;return!1}doesRowsHaveCommonMerges(e,t,s){const i=this.getters.getSheet(e);for(let e=0;e<=i.cols.length;e++)if(this.isInSameMerge(i.id,e,t,e,s))return!0;return!1}expandZone(e,t){let{left:s,right:i,top:o,bottom:n}=t,r={left:s,right:i,top:o,bottom:n};for(let t in this.merges[e]){const s=this.getMergeById(e,parseInt(t));s&&Vs(s,r)&&(r=Ps(s,r))}return Bs(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,s,i,o){return!(!this.isInMerge(e,t,s)||!this.isInMerge(e,i,o))&&this.getMerge(e,t,s)===this.getMerge(e,i,o)}isInMerge(e,t,s){var i;const o=this.mergeCellMap[e];return!!o&&(t in o&&Boolean(null===(i=o[t])||void 0===i?void 0:i[s]))}getMainCell(e,t,s){if(!this.isInMerge(e,t,s))return[t,s];const i=this.getMerge(e,t,s).topLeft;return[i.col,i.row]}getBottomLeftCell(e,t,s){if(!this.isInMerge(e,t,s))return[t,s];const{bottom:i,left:o}=this.getMerge(e,t,s);return[o,i]}isMergeHidden(e,t){const s=this.getters.getHiddenColsGroups(e),i=this.getters.getHiddenRowsGroups(e);for(let e of s)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of i)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const s=this.getMerge(e,t.left,t.top);if(s)return Bs(t,s);const{width:i,height:o}=Ws(t);return 1===i&&1===o}isMergeDestructive(e,t){let{left:s,right:i,top:o,bottom:n}=t;i=ps(i,0,e.cols.length-1),n=ps(n,0,e.rows.length-1);for(let t=o;t<=n;t++){const n=this.getters.getRow(e.id,t);for(let e=s;e<=i;e++)if(e!==s||t!==o){const t=n.cells[e];if(t&&!t.isEmpty())return!0}}return!1}getMergeById(e,t){const s=this.merges[e];return void 0!==s?s[t]:void 0}checkDestructiveMerge({sheetId:e,target:t}){const s=this.getters.tryGetSheet(e);if(!s)return 0;return t.some((e=>this.isMergeDestructive(s,e)))?3:0}checkOverlap({target:e}){for(const t of e)for(const s of e)if(t!==s&&Vs(t,s))return 50;return 0}checkMergedContentUpdate(e){const{col:t,row:s,sheetId:i,content:o}=e;if(void 0===o)return 0;const[n,r]=this.getMainCell(i,t,s);return n===t&&r===s?0:4}checkMergeExists(e){const{sheetId:t,target:s}=e;for(const e of s){const{left:s,top:i}=e,o=this.getMerge(t,s,i);if(void 0===o||!Bs(e,o))return 5}return 0}addMerge(e,t){let{left:s,right:i,top:o,bottom:n}=t;i=ps(i,0,e.cols.length-1),n=ps(n,0,e.rows.length-1);if(is(s,o)===is(i,n))return;const r=this.getters.getCell(e.id,s,o);let a=this.nextId++;this.history.update("merges",e.id,a,{id:a,left:s,top:o,right:i,bottom:n,topLeft:{col:s,row:o}});let l=new Set;for(let t=o;t<=n;t++)for(let n=s;n<=i;n++){n===s&&t===o||this.dispatch("UPDATE_CELL",{sheetId:e.id,col:n,row:t,style:r?r.style:null,content:void 0});const i=this.getMerge(e.id,n,t);i&&l.add(i.id),this.history.update("mergeCellMap",e.id,n,t,a)}for(let t of l){const{top:s,bottom:i,left:o,right:n}=this.getMergeById(e.id,t);for(let t=s;t<=i;t++)for(let s=o;s<=n;s++){const i=this.getMerge(e.id,s,t);i&&i.id===a||(this.history.update("mergeCellMap",e.id,s,t,void 0),this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:t}))}this.history.update("merges",e.id,t,void 0)}}removeMerge(e,t){const{left:s,top:i,bottom:o,right:n}=t,r=this.getMerge(e,s,i);if(void 0!==r&&Bs(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=i;t<=o;t++)for(let i=s;i<=n;i++)this.history.update("mergeCellMap",e,i,t,void 0)}}removeAllMerges(e){for(let t in this.merges[e])this.history.update("merges",e,parseInt(t),void 0);for(let t in this.mergeCellMap[e])this.history.update("mergeCellMap",e,parseInt(t),void 0)}exportAndRemoveMerges(e,t,s){const i=this.merges[e];if(!i)return;const o=xa(i),n=[];for(let e of o){const s=t(e);if(s){const[e,t]=s.split(":");e!==t&&n.push(s)}}this.removeAllMerges(e),this.pending={sheet:e,merges:n}}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){const s=this.getters.getSheet(e);for(let e of t)this.addMerge(s,ks(e))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...xa(e))}}exportForExcel(e){this.export(e)}}function xa(e){return Object.values(e).filter(Ls).map((e=>is(e.left,e.top)+":"+is(e.right,e.bottom)))}Ta.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCell","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","isSingleCellOrMerge"];class Ra extends ma{constructor(){super(...arguments),this.sheetIds={},this.visibleSheets=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"MOVE_SHEET":const t=this.visibleSheets.findIndex((t=>t===e.sheetId));return"left"===e.direction&&0===t||"right"===e.direction&&t===this.visibleSheets.length-1?14:0;case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.visibleSheets.length>1?0:9;case"REMOVE_COLUMNS_ROWS":const s=this.getSheet(e.sheetId);return("COL"===e.dimension?s.cols.length:s.rows.length)>e.elements.length?0:8;case"HIDE_COLUMNS_ROWS":{const t=this.sheets[e.sheetId],s="COL"===e.dimension?t.hiddenColsGroups:t.hiddenRowsGroups,i="COL"===e.dimension?t.cols:t.rows;return(s||[]).flat().concat(e.elements).length<i.length?0:51}default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIds",t.name,t.id);break;case"RESIZE_COLUMNS_ROWS":const s="COL"===e.dimension?"cols":"rows";for(let t of e.elements)this.setHeaderSize(this.getSheet(e.sheetId),s,t,e.size);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.direction);break;case"RENAME_SHEET":e.interactive||this.renameSheet(this.sheets[e.sheetId],e.name);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],e.elements):this.removeRows(this.sheets[e.sheetId],e.elements);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"cols","hide"):this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"rows","hide");break;case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"cols","show"):this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"rows","show");break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e)}}import(e){for(let t of e.sheets)this.sheetIds[t.name]=t.id;for(let t of e.sheets){const e=t.name||r("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:i}=this.getImportedSheetSize(t),o={id:t.id,name:e,cols:ei(t.cols||{},s),rows:ti(t.rows||{},i),hiddenColsGroups:[],hiddenRowsGroups:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible};this.visibleSheets.push(o.id),this.sheets[o.id]=o,this.updateHiddenElementsGroups(o.id,"cols"),this.updateHiddenElementsGroups(o.id,"rows")}}exportSheets(e,t=!1){e.sheets=this.visibleSheets.filter(Ls).map((e=>{const s=this.sheets[e];return{id:s.id,name:s.name,colNumber:s.cols.length,rowNumber:s.rows.length,rows:ii(s.rows,t),cols:si(s.cols,t),merges:[],cells:{},conditionalFormats:[],figures:[],areGridLinesVisible:void 0===s.areGridLinesVisible||s.areGridLinesVisible}}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e,!0)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const s=((t=e).startsWith("'")&&(t=t.slice(1,-1).replace(/''/g,"'")),t);for(const e in this.sheetIds)if(e.toUpperCase()===s.toUpperCase())return this.sheetIds[e]}var t}getSheets(){const{visibleSheets:e,sheets:t}=this;return e.map((e=>t[e])).filter(Ls)}getVisibleSheets(){return this.visibleSheets}getEvaluationSheets(){return this.sheets}getCol(e,t){var s;return null===(s=this.sheets[e])||void 0===s?void 0:s.cols[t]}getRow(e,t){var s;return null===(s=this.sheets[e])||void 0===s?void 0:s.rows[t]}getCell(e,t,s){const i=this.tryGetSheet(e);return i&&i.rows[s]&&i.rows[s].cells[t]||void 0}getColCells(e,t){return this.getSheet(e).rows.reduce(((e,s)=>{const i=s.cells[t];return void 0!==i?e.concat(i):e}),[])}getColsZone(e,t,s){return{top:0,bottom:this.getSheet(e).rows.length-1,left:t,right:s}}getRowsZone(e,t,s){return{top:t,bottom:s,left:0,right:this.getSheet(e).cols.length-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getHiddenColsGroups(e){var t;return(null===(t=this.sheets[e])||void 0===t?void 0:t.hiddenColsGroups)||[]}getHiddenRowsGroups(e){var t;return(null===(t=this.sheets[e])||void 0===t?void 0:t.hiddenRowsGroups)||[]}getNumberCols(e){return this.getSheet(e).cols.length}getNumberRows(e){return this.getSheet(e).rows.length}getNextSheetName(e="Sheet"){let t=1;const s=this.getSheets().map((e=>e.name));let i=`${e}${t}`;for(;s.includes(i);)i=`${e}${t}`,t++;return i}isEmpty(e,t){return Gs(t,this.getSheet(e),(e=>e),void 0).flat().every((e=>!e||e.isEmpty()))}setHeaderSize(e,t,s,i){let o,n;const r=e[t],a=r[s],l=i-a.size;this.history.update("sheets",e.id,t,s,"size",i),a.isHidden||this.history.update("sheets",e.id,t,s,"end",a.end+l),o=a.end;for(let i=s+1;i<r.length;i++){const s=r[i];n=s.isHidden?o:o+s.size,this.history.update("sheets",e.id,t,i,"start",o),this.history.update("sheets",e.id,t,i,"end",n),o=n}}updateCellPosition(e){if(e.cell){const t=this.cellPosition[e.cellId];t&&this.history.update("sheets",e.sheetId,"rows",t.row,"cells",t.col,void 0),this.history.update("cellPosition",e.cell.id,{row:e.row,col:e.col,sheetId:e.sheetId}),this.history.update("sheets",e.sheetId,"rows",e.row,"cells",e.col,e.cell)}else this.history.update("cellPosition",e.cellId,void 0),this.history.update("sheets",e.sheetId,"rows",e.row,"cells",e.col,void 0)}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let s of t)for(let t=s.left;t<=s.right;t++)for(let i=s.top;i<=s.bottom;i++){this.sheets[e].rows[i].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:i})}}createSheet(e,t,s,i,o){const n={id:e,name:t,cols:Qs(s),rows:Js(i),hiddenColsGroups:[],hiddenRowsGroups:[],areGridLinesVisible:!0},r=this.visibleSheets.slice();r.splice(o,0,n.id);const a=this.sheets;return this.history.update("visibleSheets",r),this.history.update("sheets",Object.assign({},a,{[n.id]:n})),n}moveSheet(e,t){const s=this.visibleSheets.slice(),i=s.findIndex((t=>t===e)),o=s.splice(i,1);s.splice(i+("left"===t?-1:1),0,o[0]),this.history.update("visibleSheets",s)}checkSheetName(e){const{visibleSheets:t,sheets:s}=this,i=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return(null===(t=s[e])||void 0===t?void 0:t.name.toLowerCase())===i}))?11:k.test(i)?13:0}checkSheetPosition(e){const{visibleSheets:t}=this;return e.position>t.length||e.position<0?15:0}isRenameAllowed(e){if(e.interactive)return 0;return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const s=e.name;this.history.update("sheets",e.id,"name",t.trim());const i=Object.assign({},this.sheetIds);i[t]=e.id,delete i[s],this.history.update("sheetIds",i)}duplicateSheet(e,t){const s=this.getSheet(e),i=this.getDuplicateSheetName(s.name),o=JSON.parse(JSON.stringify(s));o.id=t,o.name=i;for(let e=0;e<=o.cols.length;e++)for(let t=0;t<=o.rows.length;t++)o.rows[t]&&(o.rows[t].cells[e]=void 0);const n=this.visibleSheets.slice(),r=n.findIndex((t=>t===e));n.splice(r+1,0,o.id),this.history.update("visibleSheets",n),this.history.update("sheets",Object.assign({},this.sheets,{[o.id]:o}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:s}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:o.id,col:e,row:s,content:t.content,format:t.format,style:t.style})}const a=Object.assign({},this.sheetIds);a[o.name]=o.id,this.history.update("sheetIds",a)}getDuplicateSheetName(e){let t=1;const s=this.getters.getSheets().map((e=>e.name)),i=a("Copy of %s",e);let o=i.toString();for(;s.includes(o);)o=`${i} (${t})`,t++;return o}deleteSheet(e){const t=e.name,s=Object.assign({},this.sheets);delete s[e.id],this.history.update("sheets",s);const i=this.visibleSheets.slice(),o=i.findIndex((t=>t===e.id));i.splice(o,1),this.history.update("visibleSheets",i);const n=Object.assign({},this.sheetIds);delete n[t],this.history.update("sheetIds",n)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let s of t)this.moveCellOnColumnsDeletion(e,s);this.updateColumnsStructureOnDeletion(e,t)}removeRows(e,t){t.sort(((e,t)=>t-e));for(let s of ms(t))this.moveCellOnRowsDeletion(e,s[s.length-1],s[0]),s.map((t=>this.updateRowsStructureOnDeletion(t,e)))}addColumns(e,t,s,i){this.moveCellsOnAddition(e,"before"===s?t:t+1,i,"columns"),this.updateColumnsStructureOnAddition(e,t,i)}addRows(e,t,s,i){this.addEmptyRows(e,i),this.moveCellsOnAddition(e,"before"===s?t:t+1,i,"rows"),this.updateRowsStructureOnAddition(e,t,i)}moveCellOnColumnsDeletion(e,t){for(let[s,i]of Object.entries(e.rows)){const o=parseInt(s,10);for(let s in i.cells){const n=parseInt(s,10),r=i.cells[s];r&&(n===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:n,row:o}),n>t&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r.id,cell:r,col:n-1,row:o}))}}}moveCellsOnAddition(e,t,s,i){const o=[];for(const[n,r]of Object.entries(e.rows)){const a=parseInt(n,10);if("rows"!==i||a>=t)for(let n in r.cells){const l=parseInt(n,10),c=r.cells[n];c&&("rows"===i||l>=t)&&o.push({type:"UPDATE_CELL_POSITION",sheetId:e.id,cellId:c.id,cell:c,col:l+("columns"===i?s:0),row:a+("rows"===i?s:0)})}}for(let e of o.reverse())this.dispatch(e.type,e)}moveCellOnRowsDeletion(e,t,s){const i=s-t+1;for(let[o,n]of Object.entries(e.rows)){const r=parseInt(o,10);if(r>=t&&r<=s)for(let t in n.cells){const s=parseInt(t,10);n.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:r})}if(r>s)for(let t in n.cells){const s=parseInt(t,10),o=n.cells[t];o&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:o.id,cell:o,col:s,row:r-i})}}}updateColumnsStructureOnDeletion(e,t){const s=[];let i=0,o=0;for(let n in e.cols){if(t.includes(parseInt(n,10)))continue;const{size:r,isHidden:a}=e.cols[n],l=a?i:i+r;s.push({name:ts(o),size:r,start:i,end:l,isHidden:a}),i=l,o++}this.history.update("sheets",e.id,"cols",s),this.updateHiddenElementsGroups(e.id,"cols")}updateColumnsStructureOnAddition(e,t,s){const i=[];let o=0,n=0;for(let r in e.cols){if(parseInt(r,10)===t){const{size:t}=e.cols[n];for(let e=0;e<s;e++)i.push({name:ts(n),size:t,start:o,end:o+t}),o+=t,n++}const{size:a,isHidden:l}=e.cols[r],c=l?o:o+a;i.push({name:ts(n),size:a,start:o,end:c,isHidden:l}),o=c,n++}this.history.update("sheets",e.id,"cols",i),this.updateHiddenElementsGroups(e.id,"cols")}updateRowsStructureOnDeletion(e,t){const s=[];let i=0,o=0;const n=t.rows.map((e=>e.cells));for(let r in t.rows){const a=t.rows[r],{size:l,isHidden:c}=a,h=c?i:i+l;parseInt(r,10)!==e&&(o++,s.push({start:i,end:h,size:l,cells:n.shift(),name:String(o),isHidden:c}),i=h)}this.history.update("sheets",t.id,"rows",s),this.updateHiddenElementsGroups(t.id,"rows")}updateRowsStructureOnAddition(e,t,s){const i=[];let o=0,n=0,r=0;const a=e.rows.map((e=>e.cells));for(let l in e.rows){const{size:c,isHidden:h}=e.rows[r],d=h?o:o+c;(parseInt(l,10)<t||parseInt(l,10)>=t+s)&&r++,n++,i.push({start:o,end:d,size:c,cells:a.shift(),name:String(n),isHidden:h}),o=d}this.history.update("sheets",e.id,"rows",i),this.updateHiddenElementsGroups(e.id,"rows")}addEmptyRows(e,t){const s=e.rows[e.rows.length-1].end,i=e.rows.slice();for(let e=0;e<t;e++)i.push({start:s,end:s,size:0,name:(i.length+1).toString(),cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(ss);return{rowNumber:Math.max(e.rowNumber,_s(t.map((([e,t])=>t+1)))),colNumber:Math.max(e.colNumber,_s(t.map((([e,t])=>e+1))))}}setElementsVisibility(e,t,s,i){let o=0;const n="hide"===i;for(let i=0;i<e[s].length;i++){const{size:r,isHidden:a}=e[s][i],l=t.includes(i)?n:a||!1,c=l?o:o+r;this.history.update("sheets",e.id,s,i,"start",o),this.history.update("sheets",e.id,s,i,"end",c),this.history.update("sheets",e.id,s,i,"isHidden",l),o=c}this.updateHiddenElementsGroups(e.id,s)}updateHiddenElementsGroups(e,t){var s;const i="cols"===t?"hiddenColsGroups":"hiddenRowsGroups",o=((null===(s=this.sheets[e])||void 0===s?void 0:s[t])||[]).reduce(((e,t,s)=>{if(!t.isHidden)return e;const i=e[e.length-1];return i&&i[i.length-1]==s-1||e.push([]),e[e.length-1].push(s),e}),[]);this.history.update("sheets",e,i,o)}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?23:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),!t.every(Fs))return 22;if(t.length&&"sheetId"in e){const s=this.getSheet(e.sheetId),i={top:0,left:0,bottom:s.rows.length-1,right:s.cols.length-1};return t.every((e=>{return Bs(Ps(t=i,e),t);var t}))?0:18}return 0}}Ra.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheets","getVisibleSheets","getEvaluationSheets","getCol","getRow","getCell","getCellPosition","getColCells","getColsZone","getRowsZone","getNumberCols","getNumberRows","getHiddenColsGroups","getHiddenRowsGroups","getGridLinesVisibility","getNextSheetName","isEmpty"];const La=new Le;La.add("INCREMENT_MODIFIER",{apply:(e,t)=>{var s;e.current+=e.increment;const i=e.current.toString(),o=qr(e.current,null===(s=t.cell)||void 0===s?void 0:s.format);return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i},tooltip:i?{props:{content:o}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,s)=>{var i,o;const n=(null===(i=t.cell)||void 0===i?void 0:i.content)||"";return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:n},tooltip:n?{props:{content:null===(o=t.cell)||void 0===o?void 0:o.formattedValue}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,s,i)=>{e.current+=e.increment;let o=0,n=0;switch(i){case 0:o=0,n=-e.current;break;case 1:o=0,n=e.current;break;case 2:o=-e.current,n=0;break;case 3:o=e.current,n=0}if(!t.cell||!t.cell.isFormula())return{cellData:{}};const r=t.sheetId,a=s.createAdaptedRanges(t.cell.dependencies.references,o,n,r),l=s.buildFormulaContent(r,t.cell.normalizedText,{...t.cell.dependencies,references:a});return{cellData:{border:t.border,style:t.cell.style,format:t.cell.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const Ma=new Le;Ma.add("simple_value_copy",{condition:(e,t)=>{var s;return 1===t.length&&!e.isFormula()&&!(null===(s=e.format)||void 0===s?void 0:s.match(A))},generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("copy_text",{condition:e=>!e.isFormula()&&e.evaluated.type===ke.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.evaluated.type===ke.number,generateRule:(e,t)=>{const s=function(e,t){let s=[],i=!1;for(let o of t)if(o===e&&(i=!0),(null==o?void 0:o.evaluated.type)===ke.number)s.push(o.evaluated.value);else{if(i)return s;s=[]}return s}(e,t);let i=1;return 2==s.length?i=2*(s[1]-s[0]):s.length>2&&(i=function(e){const t=[];let s=e[0];for(let i=1;i<e.length;i++){const o=e[i];t.push(o-s),s=o}return t.reduce(((e,t)=>e+t),0)/t.length}(s)*s.length),{type:"INCREMENT_MODIFIER",increment:i,current:e.evaluated.type===ke.number?e.evaluated.value:0}},sequence:40});const Aa=new Le,_a=(new Le).add("ADD_COLUMNS_ROWS",(function(e){const t=[];let s=e.base;"after"===e.position&&s++;for(let i=0;i<e.quantity;i++)t.push(i+s);return[{type:"REMOVE_COLUMNS_ROWS",dimension:e.dimension,elements:t,sheetId:e.sheetId}]})).add("REMOVE_COLUMNS_ROWS",(function(e){const t=[],s=[...e.elements].sort(((e,t)=>e-t));for(let i of ms(s)){const s=0===i[0]?0:i[0]-1,o=0===i[0]?"before":"after";t.push({type:"ADD_COLUMNS_ROWS",dimension:e.dimension,quantity:i.length,base:s,sheetId:e.sheetId,position:o})}return t})).add("ADD_MERGE",(function(e){return[{type:"REMOVE_MERGE",sheetId:e.sheetId,target:e.target}]})).add("REMOVE_MERGE",(function(e){return[{type:"ADD_MERGE",sheetId:e.sheetId,target:e.target}]})).add("CREATE_SHEET",(function(e){return[{type:"DELETE_SHEET",sheetId:e.sheetId}]})).add("DELETE_SHEET",(function(e){return[{type:"CREATE_SHEET",sheetId:e.sheetId,position:1}]})).add("DUPLICATE_SHEET",(function(e){return[{type:"DELETE_SHEET",sheetId:e.sheetIdTo}]})).add("CREATE_FIGURE",(function(e){return[{type:"DELETE_FIGURE",id:e.figure.id,sheetId:e.sheetId}]})).add("CREATE_CHART",(function(e){return[{type:"DELETE_FIGURE",id:e.id,sheetId:e.sheetId}]})).add("HIDE_COLUMNS_ROWS",(function(e){return[{type:"UNHIDE_COLUMNS_ROWS",sheetId:e.sheetId,dimension:e.dimension,elements:e.elements}]})).add("UNHIDE_COLUMNS_ROWS",(function(e){return[{type:"HIDE_COLUMNS_ROWS",sheetId:e.sheetId,dimension:e.dimension,elements:e.elements}]}));for(const e of De.values())_a.contains(e)||_a.add(e,Oa);function Oa(e){return[e]}const Na=e=>({isVisible:()=>!0,isEnabled:()=>!0,isReadonlyAllowed:!1,shortCut:"",action:!1,children:[],separator:!1,icon:!1,id:e});function ka(e,t){return Object.assign({},Na(e),t)}class Fa extends Le{add(e,t){return this.content[e]=ka(e,t),this}addChild(e,t,s){const i=t.splice(0,1)[0];let o=this.content[i];if(!o)throw new Error(`Path ${i+":"+t.join(":")} not found`);for(let e of t)if(o="function"==typeof o.children?void 0:o.children.find((t=>t.id===e)),!o)throw new Error(`Path ${i+":"+t.join(":")} not found`);return o.children.push(ka(e,s)),this}getChildren(e,t){return"function"==typeof e.children?e.children(t).sort(((e,t)=>e.sequence-t.sequence)):e.children.sort(((e,t)=>e.sequence-t.sequence))}getName(e,t){return"function"==typeof e.name?e.name(t):e.name}getShortCut(e){return e.shortCut?e.shortCut:""}getAll(){return super.getAll().sort(((e,t)=>e.sequence-t.sequence))}}function $a(e){const t=e.getters.getActiveCols();if(t.size)return t.size;{const t=e.getters.getSelectedZones()[0];return t.right-t.left+1}}function Da(e){const t=e.getters.getActiveRows();if(t.size)return t.size;{const t=e.getters.getSelectedZones()[0];return t.bottom-t.top+1}}function Ua(e,t){e.dispatch("SET_FORMATTING",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones(),format:t})}function Pa(e,t){e.dispatch("SET_FORMATTING",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones(),style:t})}const Ba=async e=>{e.dispatch("COPY",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Va=async e=>{e.dispatch("CUT",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Ha=async e=>{const t=e.getters.getClipboardContent();let s;try{s=await e.clipboard.readText()}catch(e){console.warn("The OS clipboard could not be read."),console.error(e)}const i=e.getters.getSelectedZones();s&&s!==t?e.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:i,text:s}):e.dispatch("PASTE",{target:i,interactive:!0})},za=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),pasteOption:"onlyValue"}),Za=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),pasteOption:"onlyFormat"}),Ga=e=>e.dispatch("DELETE_CONTENT",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones()}),Wa=e=>{let t,s;const i=e.getters.getActiveRows();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.top,s=i.bottom}return t===s?a("Delete row %s",(t+1).toString()):a("Delete rows %s - %s",(t+1).toString(),(s+1).toString())},qa=e=>{let t=[...e.getters.getActiveRows()];if(!t.length){const s=e.getters.getSelectedZones()[0];for(let e=s.top;e<=s.bottom;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},ja=e=>{let t,s;const i=e.getters.getActiveCols();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.left,s=i.right}return t===s?a("Delete column %s",ts(t)):a("Delete columns %s - %s",ts(t),ts(s))},Ya=e=>{let t=[...e.getters.getActiveCols()];if(!t.length){const s=e.getters.getSelectedZones()[0];for(let e=s.left;e<=s.right;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},Xa=e=>{const t=e.getters.getSelectedZone();e.dispatch("INSERT_CELL",{shiftDimension:"ROW",zone:t,interactive:!0})},Ka=e=>{const t=e.getters.getSelectedZone();e.dispatch("INSERT_CELL",{shiftDimension:"COL",zone:t,interactive:!0})},Qa=e=>{const t=e.getters.getSelectedZone();e.dispatch("DELETE_CELL",{shiftDimension:"ROW",zone:t,interactive:!0})},Ja=e=>{const t=e.getters.getSelectedZone();e.dispatch("DELETE_CELL",{shiftDimension:"COL",zone:t,interactive:!0})},el=e=>{const t=e.getters.getActiveRows();let s,i;if(t.size)s=Os([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.top,i=t.bottom-t.top+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"before",base:s,quantity:i,dimension:"ROW"})},tl=e=>{const t=e.getters.getActiveRows();let s,i;if(t.size)s=_s([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.bottom,i=t.bottom-t.top+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"after",base:s,quantity:i,dimension:"ROW"})},sl=e=>{const t=e.getters.getActiveCols();let s,i;if(t.size)s=Os([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.left,i=t.right-t.left+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"before",dimension:"COL",base:s,quantity:i})},il=e=>{const t=e.getters.getActiveCols();let s,i;if(t.size)s=_s([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.right,i=t.right-t.left+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"after",dimension:"COL",base:s,quantity:i})},ol=e=>{e.openSidePanel("ConditionalFormatting",{selection:e.getters.getSelectedZones()})},nl=e=>{e.openLinkEditor()},rl=e=>{const{anchor:t,zones:s}=e.getters.getSelection();e.dispatch("SORT_CELLS",{interactive:!0,sheetId:e.getters.getActiveSheetId(),anchor:t,zone:s[0],sortDirection:"ascending"})},al=e=>{const{anchor:t,zones:s}=e.getters.getSelection();e.dispatch("SORT_CELLS",{interactive:!0,sheetId:e.getters.getActiveSheetId(),anchor:t,zone:s[0],sortDirection:"descending"})},ll=e=>1===e.getters.getSelectedZones().length,cl=new Fa;cl.add("cut",{name:a("Cut"),shortCut:"Ctrl+X",sequence:10,action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha,isVisible:ll}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0,isVisible:ll}).addChild("paste_value_only",["paste_special"],{name:a("Paste values only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("sort_range",{name:a("Sort range"),sequence:50,isVisible:ll,separator:!0}).addChild("sort_ascending",["sort_range"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["sort_range"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).add("add_row_before",{name:e=>{const t=Da(e);return 1===t?a("Insert row"):a("Insert %s rows",t.toString())},sequence:70,action:el,isVisible:ll}).add("add_column_before",{name:e=>{const t=$a(e);return 1===t?a("Insert column"):a("Insert %s columns",t.toString())},sequence:90,action:sl,isVisible:ll}).add("insert_cell",{name:a("Insert cells"),sequence:100,isVisible:ll,separator:!0}).addChild("insert_cell_down",["insert_cell"],{name:a("Shift down"),sequence:10,action:Xa}).addChild("insert_cell_right",["insert_cell"],{name:a("Shift right"),sequence:20,action:Ka}).add("delete_row",{name:Wa,sequence:110,action:qa,isVisible:ll}).add("delete_column",{name:ja,sequence:120,action:Ya,isVisible:ll}).add("delete_cell",{name:a("Delete cells"),sequence:130,isVisible:ll}).addChild("delete_cell_up",["delete_cell"],{name:a("Shift up"),sequence:10,action:Qa}).addChild("delete_cell_down",["delete_cell"],{name:a("Shift left"),sequence:20,action:Ja}).add("clear_cell",{name:a("Clear cells"),sequence:140,action:Ga,isEnabled:e=>{const t=e.getters.getActiveCell();return Boolean(t)},separator:!0}).add("insert_link",{name:a("Insert link"),separator:!0,sequence:150,action:nl}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:160,action:ol,separator:!0});const hl=new Fa;hl.add("cut",{name:a("Cut"),shortCut:"Ctrl+X",sequence:10,action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("sort_columns",{name:e=>e.getters.getActiveCols().size>1?a("Sort columns"):a("Sort column"),sequence:50,isVisible:ll,separator:!0}).addChild("sort_ascending",["sort_columns"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["sort_columns"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).add("add_column_before",{name:e=>{const t=$a(e);return 1===t?a("Insert column left"):a("Insert %s columns left",t.toString())},sequence:70,action:sl}).add("add_column_after",{name:e=>{const t=$a(e);return 1===t?a("Insert column right"):a("Insert %s columns right",t.toString())},sequence:80,action:il}).add("delete_column",{name:ja,sequence:90,action:Ya}).add("clear_column",{name:e=>{let t,s;const i=e.getters.getActiveCols();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.left,s=i.right}return t===s?a("Clear column %s",ts(t)):a("Clear columns %s - %s",ts(t),ts(s))},sequence:100,action:e=>{const t=e.getters.getActiveSheetId(),s=[...e.getters.getActiveCols()].map((s=>e.getters.getColsZone(t,s,s)));e.dispatch("DELETE_CONTENT",{target:s,sheetId:e.getters.getActiveSheetId()})}}).add("hide_columns",{name:e=>{const t=e.getters.getElementsFromSelection("COL");let s=t[0],i=t[t.length-1];return 1===t.length?a("Hide column %s",ts(s).toString()):i-s+1===t.length?a("Hide columns %s - %s",ts(s).toString(),ts(i).toString()):a("Hide columns")},sequence:85,action:e=>{const t=e.getters.getElementsFromSelection("COL");e.dispatch("HIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},isVisible:e=>{const t=e.getters.getActiveSheet(),s=e.getters.getHiddenColsGroups(t.id).flat();return t.cols.length>s.length+e.getters.getElementsFromSelection("COL").length},separator:!0}).add("unhide_columns",{name:"Unhide columns",sequence:86,action:e=>{const t=e.getters.getElementsFromSelection("COL");e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},isVisible:e=>{const t=e.getters.getHiddenColsGroups(e.getters.getActiveSheetId()).flat();return e.getters.getElementsFromSelection("COL").some((e=>t.includes(e)))},separator:!0}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:110,action:ol});const dl=new Fa;dl.add("sheet",{name:a("Link sheet"),sequence:10,children:e=>e.getters.getSheets().map(((e,t)=>ka(e.id,{name:e.name,sequence:t,action:()=>{return{link:{label:e.name,url:(t=e.id,`${Ts}${t}`)},urlRepresentation:e.name,isUrlEditable:!1};var t}})))});const ul=new Fa;ul.add("cut",{name:a("Cut"),sequence:10,shortCut:"Ctrl+X",action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("add_row_before",{name:e=>{const t=Da(e);return 1===t?a("Insert row above"):a("Insert %s rows above",t.toString())},sequence:50,action:el}).add("add_row_after",{name:e=>{const t=Da(e);return 1===t?a("Insert row below"):a("Insert %s rows below",t.toString())},sequence:60,action:tl}).add("delete_row",{name:Wa,sequence:70,action:qa}).add("clear_row",{name:e=>{let t,s;const i=e.getters.getActiveRows();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.top,s=i.bottom}return t===s?a("Clear row %s",(t+1).toString()):a("Clear rows %s - %s",(t+1).toString(),(s+1).toString())},sequence:80,action:e=>{const t=e.getters.getActiveSheetId(),s=[...e.getters.getActiveRows()].map((s=>e.getters.getRowsZone(t,s,s)));e.dispatch("DELETE_CONTENT",{target:s,sheetId:e.getters.getActiveSheetId()})}}).add("hide_rows",{name:e=>{const t=e.getters.getElementsFromSelection("ROW");let s=t[0],i=t[t.length-1];return 1===t.length?a("Hide row %s",(s+1).toString()):i-s+1===t.length?a("Hide rows %s - %s",(s+1).toString(),(i+1).toString()):a("Hide rows")},sequence:85,action:e=>{const t=e.getters.getElementsFromSelection("ROW");e.dispatch("HIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},isVisible:e=>{const t=e.getters.getActiveSheet(),s=e.getters.getHiddenRowsGroups(t.id).flat();return t.rows.length>s.length+e.getters.getElementsFromSelection("ROW").length},separator:!0}).add("unhide_rows",{name:"Unhide rows",sequence:86,action:e=>{const t=e.getters.getElementsFromSelection("ROW");e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},isVisible:e=>{const t=e.getters.getHiddenRowsGroups(e.getters.getActiveSheetId()).flat();return e.getters.getElementsFromSelection("ROW").some((e=>t.includes(e)))},separator:!0}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:90,action:ol});const pl=new Fa;pl.add("delete",{name:a("Delete"),sequence:10,isVisible:e=>e.getters.getSheets().length>1,action:e=>e.dispatch("DELETE_SHEET_CONFIRMATION",{sheetId:e.getters.getActiveSheetId()})}).add("duplicate",{name:a("Duplicate"),sequence:20,action:e=>{const t=e.getters.getActiveSheetId(),s=e.uuidGenerator.uuidv4();e.dispatch("DUPLICATE_SHEET",{sheetId:t,sheetIdTo:s}),e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:s})}}).add("rename",{name:a("Rename"),sequence:30,action:e=>e.dispatch("RENAME_SHEET",{interactive:!0,sheetId:e.getters.getActiveSheetId()})}).add("move_right",{name:a("Move right"),sequence:40,isVisible:e=>{const t=e.getters.getActiveSheetId(),s=e.getters.getSheets();return s.findIndex((e=>e.id===t))!==s.length-1},action:e=>e.dispatch("MOVE_SHEET",{sheetId:e.getters.getActiveSheetId(),direction:"right"})}).add("move_left",{name:a("Move left"),sequence:50,isVisible:e=>{const t=e.getters.getActiveSheetId();return 0!==e.getters.getSheets().findIndex((e=>e.id===t))},action:e=>e.dispatch("MOVE_SHEET",{sheetId:e.getters.getActiveSheetId(),direction:"left"})});const gl=new Fa;gl.add("file",{name:a("File"),sequence:10}).add("edit",{name:a("Edit"),sequence:20}).add("view",{name:a("View"),sequence:30}).add("insert",{name:a("Insert"),sequence:40}).add("format",{name:a("Format"),sequence:50}).add("data",{name:a("Data"),sequence:60}).addChild("save",["file"],{name:a("Save"),shortCut:"Ctrl+S",sequence:10,action:()=>console.log("Not implemented")}).addChild("undo",["edit"],{name:a("Undo"),shortCut:"Ctrl+Z",sequence:10,action:e=>e.dispatch("REQUEST_UNDO")}).addChild("redo",["edit"],{name:a("Redo"),shortCut:"Ctrl+Y",sequence:20,action:e=>e.dispatch("REQUEST_REDO"),separator:!0}).addChild("copy",["edit"],{name:a("Copy"),shortCut:"Ctrl+C",sequence:30,isReadonlyAllowed:!0,action:Ba}).addChild("cut",["edit"],{name:a("Cut"),shortCut:"Ctrl+X",sequence:40,action:Va}).addChild("paste",["edit"],{name:a("Paste"),shortCut:"Ctrl+V",sequence:50,action:Ha}).addChild("paste_special",["edit"],{name:a("Paste special"),sequence:60,separator:!0}).addChild("paste_special_value",["edit","paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_special_format",["edit","paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).addChild("sort_range",["edit"],{name:a("Sort range"),sequence:62,isVisible:ll,separator:!0}).addChild("sort_ascending",["edit","sort_range"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["edit","sort_range"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).addChild("find_and_replace",["edit"],{name:a("Find and replace"),shortCut:"Ctrl+H",sequence:65,isReadonlyAllowed:!0,action:e=>{e.openSidePanel("FindAndReplace",{})},separator:!0}).addChild("edit_delete_cell_values",["edit"],{name:a("Delete values"),sequence:70,action:Ga}).addChild("edit_delete_row",["edit"],{name:Wa,sequence:80,action:qa}).addChild("edit_delete_column",["edit"],{name:ja,sequence:90,action:Ya}).addChild("edit_delete_cell_shift_up",["edit"],{name:a("Delete cell and shift up"),sequence:93,action:Qa}).addChild("edit_delete_cell_shift_left",["edit"],{name:a("Delete cell and shift left"),sequence:97,action:Ja}).addChild("edit_unhide_columns",["edit"],{name:a("Unhide all columns"),sequence:100,action:e=>{const t=e.getters.getActiveSheet();e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:t.id,dimension:"COL",elements:Array.from(Array(t.cols.length).keys())})},isVisible:e=>e.getters.getHiddenColsGroups(e.getters.getActiveSheetId()).length>0}).addChild("edit_unhide_rows",["edit"],{name:a("Unhide all rows"),sequence:100,action:e=>{const t=e.getters.getActiveSheet();e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:t.id,dimension:"ROW",elements:Array.from(Array(t.rows.length).keys())})},isVisible:e=>e.getters.getHiddenRowsGroups(e.getters.getActiveSheetId()).length>0}).addChild("insert_row_before",["insert"],{name:e=>{const t=Da(e);return 1===t?a("Row above"):a("%s Rows above",t.toString())},sequence:10,action:el,isVisible:e=>0===e.getters.getActiveCols().size}).addChild("insert_row_after",["insert"],{name:e=>{const t=Da(e);return 1===t?a("Row below"):a("%s Rows below",t.toString())},sequence:20,action:tl,isVisible:e=>0===e.getters.getActiveCols().size,separator:!0}).addChild("insert_column_before",["insert"],{name:e=>{const t=$a(e);return 1===t?a("Column left"):a("%s Columns left",t.toString())},sequence:30,action:sl,isVisible:e=>0===e.getters.getActiveRows().size}).addChild("insert_column_after",["insert"],{name:e=>{const t=$a(e);return 1===t?a("Column right"):a("%s Columns right",t.toString())},sequence:40,action:il,isVisible:e=>0===e.getters.getActiveRows().size,separator:!0}).addChild("insert_insert_cell_shift_down",["insert"],{name:a("Insert cells and shift down"),sequence:43,action:Xa}).addChild("insert_insert_cell_shift_right",["insert"],{name:a("Insert cells and shift right"),sequence:47,action:Ka,separator:!0}).addChild("insert_chart",["insert"],{name:a("Chart"),sequence:50,action:e=>{var t,s;const i=e.getters.getSelectedZone();let o=i;const n=e.uuidGenerator.uuidv4();let r;i.left!==i.right&&(o={...i,left:i.left+1});const a=[$s(o)],l=e.getters.getActiveSheetId(),c={x:(null===(t=e.getters.getCol(l,i.right+1))||void 0===t?void 0:t.start)||0,y:(null===(s=e.getters.getRow(l,i.top))||void 0===s?void 0:s.start)||0};let h=!1;for(let t=o.left;t<=o.right;t++){const s=e.getters.getCell(l,t,i.top);if(s&&s.evaluated.type!==ke.number){h=!0;break}}i.left!==i.right&&(r=$s({...i,right:i.left,top:h?i.top+1:i.top})),e.dispatch("CREATE_CHART",{sheetId:l,id:n,position:c,definition:{title:"",dataSets:a,labelRange:r,type:"bar",stackedBar:!1,dataSetsHaveTitle:h,background:g,verticalAxisPosition:"left",legendPosition:"top"}});const d=e.getters.getFigure(l,n);e.openSidePanel("ChartPanel",{figure:d})}}).addChild("insert_link",["insert"],{name:a("Link"),separator:!0,sequence:60,action:nl}).addChild("insert_sheet",["insert"],{name:a("New sheet"),sequence:70,action:e=>{const t=e.getters.getActiveSheetId(),s=e.getters.getVisibleSheets().findIndex((e=>e===t))+1,i=e.uuidGenerator.uuidv4();e.dispatch("CREATE_SHEET",{sheetId:i,position:s}),e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:i})},separator:!0}).addChild("view_gridlines",["view"],{name:e=>e.getters.getGridLinesVisibility(e.getters.getActiveSheetId())?a("Hide gridlines"):a("Show gridlines"),action:e=>{const t=e.getters.getActiveSheetId();e.dispatch("SET_GRID_LINES_VISIBILITY",{sheetId:t,areGridLinesVisible:!e.getters.getGridLinesVisibility(t)})},sequence:5,separator:!0}).addChild("view_formulas",["view"],{name:e=>e.getters.shouldShowFormulas()?a("Hide formulas"):a("Show formulas"),action:e=>e.dispatch("SET_FORMULA_VISIBILITY",{show:!e.getters.shouldShowFormulas()}),isReadonlyAllowed:!0,sequence:10}).addChild("format_number",["format"],{name:a("Numbers"),sequence:10,separator:!0}).addChild("format_number_general",["format","format_number"],{name:a("General"),sequence:10,separator:!0,action:e=>Ua(e,"")}).addChild("format_number_number",["format","format_number"],{name:a("Number (1,000.12)"),sequence:20,action:e=>Ua(e,"#,##0.00")}).addChild("format_number_percent",["format","format_number"],{name:a("Percent (10.12%)"),sequence:30,separator:!0,action:e=>Ua(e,"0.00%")}).addChild("format_number_date",["format","format_number"],{name:a("Date (9/26/2008)"),sequence:40,action:e=>Ua(e,"m/d/yyyy")}).addChild("format_number_time",["format","format_number"],{name:a("Time (10:43:00 PM)"),sequence:50,action:e=>Ua(e,"hh:mm:ss a")}).addChild("format_number_date_time",["format","format_number"],{name:a("Date time (9/26/2008 22:43:00)"),sequence:60,action:e=>Ua(e,"m/d/yyyy hh:mm:ss")}).addChild("format_number_duration",["format","format_number"],{name:a("Duration (27:51:38)"),sequence:70,separator:!0,action:e=>Ua(e,"hhhh:mm:ss")}).addChild("format_bold",["format"],{name:a("Bold"),sequence:20,shortCut:"Ctrl+B",action:e=>Pa(e,{bold:!e.getters.getCurrentStyle().bold})}).addChild("format_italic",["format"],{name:a("Italic"),sequence:30,shortCut:"Ctrl+I",action:e=>Pa(e,{italic:!e.getters.getCurrentStyle().italic})}).addChild("format_underline",["format"],{name:a("Underline"),shortCut:"Ctrl+U",sequence:40,action:e=>Pa(e,{underline:!e.getters.getCurrentStyle().underline})}).addChild("format_strikethrough",["format"],{name:a("Strikethrough"),sequence:50,action:e=>Pa(e,{strikethrough:!e.getters.getCurrentStyle().strikethrough}),separator:!0}).addChild("format_font_size",["format"],{name:a("Font size"),sequence:60,separator:!0}).addChild("format_cf",["format"],{name:a("Conditional formatting"),sequence:70,action:ol,separator:!0});for(let e of ls)gl.addChild(`format_font_size_${e.pt}`,["format","format_font_size"],{name:e.pt.toString(),sequence:e.pt,action:t=>Pa(t,{fontSize:e.pt})});const fl=new class extends Le{addTransformation(e,t,s){for(let i of t)this.content[i]||(this.content[i]=new Map),this.content[i].set(e,s);return this}getTransformation(e,t){return this.content[e]&&this.content[e].get(t)}},{css:ml,xml:vl}=t.tags,El=[["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#f3f3f3","#ffffff"],["#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff"],["#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc"],["#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd"],["#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"],["#a61c00","#cc0000","#e69138","#f1c232","#6aa84f","#45818e","#3c78d8","#3d85c6","#674ea7","#a64d79"],["#85200c","#990000","#b45f06","#bf9000","#38761d","#134f5c","#1155cc","#0b5394","#351c75","#741b47"],["#5b0f00","#660000","#783f04","#7f6000","#274e13","#0c343d","#1c4587","#073763","#20124d","#4c1130"]],bl=24*Math.max(...El.map((e=>e.length)))+12;class Sl extends t.Component{constructor(){super(...arguments),this.COLORS=El}onColorClick(e){const t=e.target.dataset.color;t&&this.trigger("color-picked",{color:t})}}Sl.template=vl`
|
|
1
|
+
!function(e,t){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var i=s(t);let o=e=>e;function n(e,...t){if(1===t.length&&"object"==typeof t[0]){const s=t[0];e=e.replace(/\%\(?([^\)]+)\)s/g,((e,t)=>s[t]))}else t.length>0&&(e=e.replace(/\%s/g,(()=>t.shift())));return e}const r=function(e,...t){return n(o(e),...t)},a=function(e,...t){return{toString:function(){return n(o(e),...t)}}},l="#f5f5f5",c="#F8F9FA",h="#E8EAED",d="#595959",u="#666666",p="#3266ca",g="#FFFFFF",f=26,m=48,v=63,E=96,S=23,b=15,C=14,I=4,y=200,w=1,T="400",x=10,R="'Roboto', arial",L=["thin","#000"],A="#00f",M=/[ymd:]/,_="#REF",O="START_REVISION",N=a("Invalid expression"),k=/'|\*|\?|\/|\\|\[|\]/,F=void 0,$="|";class D{constructor(e,t,s,i=0,o=0,n=0){this.jsDate=new Date(Date.UTC(e,t,s,i,o,n,0))}static fromTimestamp(e){const t=new Date(e);return new D(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds())}static now(){const e=new Date;return new D(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())}toString(){return this.jsDate.toString()}getTime(){return this.jsDate.getTime()}getFullYear(){return this.jsDate.getUTCFullYear()}getMonth(){return this.jsDate.getUTCMonth()}getDate(){return this.jsDate.getUTCDate()}getDay(){return this.jsDate.getUTCDay()}getHours(){return this.jsDate.getUTCHours()}getMinutes(){return this.jsDate.getUTCMinutes()}getSeconds(){return this.jsDate.getUTCSeconds()}setDate(e){this.jsDate.setUTCDate(e)}setHours(e){this.jsDate.setUTCHours(e)}setMinutes(e){this.jsDate.setUTCMinutes(e)}setSeconds(e){this.jsDate.setUTCSeconds(e)}}const U=2e3,P=D.now().getFullYear(),B=new D(1899,11,30),V=D.fromTimestamp(0).getTime()-B.getTime(),H=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,z=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,Z=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function G(e){let t;const s=(e=e.trim()).match(Z);if(s){if(t=function(e){if(e=e.trim(),Z.test(e)){const t=/AM/i.test(e),s=/PM/i.test(e),i=(t||s?e.substring(0,e.length-2).trim():e).split(/:/),o=i.length>=2,n=3===i.length;let r=Number(i[0]),a=o?Number(i[1]):0,l=n?Number(i[2]):0,c=n?"hh:mm:ss":"hh:mm";if(t||s)c+=" a";else if(!o)return null;r>=12&&t?r-=12:r<12&&s&&(r+=12),a+=Math.floor(l/60),l%=60,r+=Math.floor(a/60),a%=60,r>=24&&(c="hhhh:mm:ss");return{value:r/24+a/1440+l/86400,format:c,jsDate:new D(1899,11,30,r,a,l)}}return null}(s[0]),null===t)return null;e=e.replace(s[0],"").trim()}let i;const o=e.match(H),n=e.match(z);if(o||n){let t;if(o?(t=o[0],i=W(t,"mdy")):(t=n[0],i=W(t,"ymd")),null===i)return null;e=e.replace(t,"").trim()}return""!==e||!i&&!t?null:i&&t?{value:i.value+t.value,format:i.format+" "+("hhhh:mm:ss"===t.format?"hh:mm:ss":t.format),jsDate:new D(i.jsDate.getFullYear()+t.jsDate.getFullYear()-1899,i.jsDate.getMonth()+t.jsDate.getMonth()-11,i.jsDate.getDate()+t.jsDate.getDate()-30,i.jsDate.getHours()+t.jsDate.getHours(),i.jsDate.getMinutes()+t.jsDate.getMinutes(),i.jsDate.getSeconds()+t.jsDate.getSeconds())}:i||t}function W(e,t){const s="mdy"===t;if(s||"ymd"===t){const t=e.split(/\/|-|\s/),i=s?0:1,o=s?1:2,n=s?2:0,r=Number(t[i]),a=Number(t[o]),l=2===t[i].length&&r<10||2===t[o].length&&a<10,c=t[n]?function(e){const t=Number(e);switch(e.length){case 1:return U+t;case 2:return U+(U+t>P+10?-100:0)+t;case 3:case 4:return t}return 0}(t[n]):P,h=new D(c,r-1,a),d=e.match(/\/|-|\s/)[0];if(h.getMonth()!==r-1||h.getDate()!==a)return null;const u=h.getTime()-B.getTime();let p=l?`mm${d}dd`:`m${d}d`;return t[n]&&(p=s?p+d+"yyyy":"yyyy"+d+p),{value:Math.round(u/864e5),format:p,jsDate:h}}return null}function q(e){const t=Math.trunc(e);let s=D.fromTimestamp(86400*t*1e3-V),i=e-t;i=i<0?1+i:i;const o=Math.round(24*i),n=Math.round(24*(i-o/24)*60),r=Math.round(24*(i-o/24-n/24/60)*60*60);return s.setHours(o),s.setMinutes(n),s.setSeconds(r),s}function j(e){const t=e.format,s=e.jsDate||q(e.value),i=t.indexOf("h");let o="",n="";return i>0?(o=Y(s,t.substring(0,i-1)),n=X(s,t.substring(i))):0===i?n=X(s,t):i<0&&(o=Y(s,t)),o+(o&&n?" ":"")+n}function Y(e,t){const s=t.match(/\/|-|\s/)[0];return t.split(s).map((s=>{switch(s){case"d":return e.getDate();case"dd":return e.getDate().toString().padStart(2,"0");case"m":return e.getMonth()+1;case"mm":return String(e.getMonth()+1).padStart(2,"0");case"yyyy":return e.getFullYear();default:throw new Error(`invalid format: ${t}`)}})).join(s)}function X(e,t){let s=t.split(/:|\s/);const i=e.getHours(),o="a"===s[s.length-1];let n=i,r="";return o&&(n=0===n?12:n>12?n-12:n,r=i>=12?" PM":" AM",s.pop()),s.map((s=>{switch(s){case"hhhh":return Math.floor((e.getTime()-B.getTime())/36e5).toString();case"hh":return n.toString().padStart(2,"0");case"mm":return e.getMinutes().toString().padStart(2,"0");case"ss":return e.getSeconds().toString().padStart(2,"0");default:throw new Error(`invalid format: ${t}`)}})).join(":")+r}const K=/(^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?)(?!\w|!)/,Q=/^-?\d+(,\d+)*(\.?\d*(e\d+)?)?(\s*%)?$|^-?\.\d+(\s*%)?$/;function J(e){return Q.test(e.trim())}const ee=/,/g;function te(e){let t=Number(e.replace(ee,""));return isNaN(t)&&e.includes("%")&&(t=Number(e.split("%")[0]),!isNaN(t))?t/100:t}const se=new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:10});function ie(e){return Number.isInteger(e)?e.toString():se.format(e)}let oe=[];const ne=20;function re(e,t,s=""){if(e<0)return"-"+re(-e,t);const i=t>=ne?ne:t;let o=oe[i];o||(o=new Intl.NumberFormat("en-US",{minimumFractionDigits:i,maximumFractionDigits:i,useGrouping:!1}),oe[i]=o);let n=o.format(e);if(s){let e=n.indexOf(".");n=n.replace(/\d(?=(?:\d{3})+(?:\.|$))/g,((t,i)=>e<0||i<e?`${t}${s}`:t))}return n}function ae(e,t){const s=t.split("."),i=1===s.length?0:s[1].match(/0/g).length,o=s[0].includes(",")?",":"",n=t.includes("%");n&&(e*=100);const r=re(e,i,o);return n?r+"%":r}function le(e,t){if(!e())throw new Error(t)}const ce=e=>a("The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.",e);function he(e){switch(typeof e){case"number":return e;case"boolean":return e?1:0;case"string":if(J(e)||""===e)return te(e);const t=G(e);if(t)return t.value;throw new Error(ce(e));default:return 0}}function de(e){if(""===e)throw new Error(ce(e));return he(e)}function ue(e){switch(typeof e){case"string":return e;case"number":return e.toString();case"boolean":return e?"TRUE":"FALSE";default:return""}}const pe=e=>a("The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a number.",e);function ge(e){switch(typeof e){case"boolean":return e;case"string":if(e){let t=e.toUpperCase();if("TRUE"===t)return!0;if("FALSE"===t)return!1;throw new Error(pe(e))}return!1;case"number":return!!e;default:return!1}}function fe(e){return q(he(e))}function me(e,t,s){for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let o=0;o<s;o++)for(let s=0;s<e;s++)t(i[s][o])}else s(i)}function ve(e,t){me(e,t,t)}function Ee(e,t){me(e,(e=>{"number"==typeof e&&t(e)}),(e=>{t(de(e))}))}function Se(e,t,s,i){let o=i;for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let n=0;n<s;n++)for(let s=0;s<e;s++)o=t(o,i[s][n])}else o=s(o,i);return o}function be(e,t,s){return Se(e,t,t,s)}function Ce(e,t,s){return Se(e,((e,s)=>"number"==typeof s?t(e,s):e),((e,s)=>t(e,de(s))),s)}function Ie(e,t,s){return Se(e,((e,s)=>null!=s?t(e,"number"==typeof s?s:"boolean"==typeof s?he(s):0):e),((e,s)=>t(e,he(s))),s)}function ye(e,t){return function(e,t,s){for(let i of e)if(Array.isArray(i)){const e=i.length,s=i[0].length;for(let o=0;o<s;o++)for(let s=0;s<e;s++)if(!t(i[s][o]))return}else if(!s(i))return}(e,(e=>"boolean"==typeof e?t(e):"number"!=typeof e||t(!!e)),(e=>null==e||t(function(e){if(""===e)throw new Error(pe(e));return ge(e)}(e))))}function we(e,t){let s,i,o=e.substring(0,2);"<="===o||">="===o||"<>"===o?(s=o,i=e.substring(2)):(o=e.substring(0,1),"<"===o||">"===o||"="===o?(s=o,i=e.substring(1)):(s="=",i=e)),J(i)?i=he(i):"TRUE"!==i&&"FALSE"!==i||(i=ge(i));const n={operator:s,operand:i};return"string"==typeof i&&(t&&(i+="*"),n.regexp=function(e){let t="",s="";for(let i of e)"?"===i&&"~"!==s?t+=".":"*"===i&&"~"!==s?t+=".*":("*"!==i&&"?"!==i||(t=t.slice(0,-1)),["^",".","[","]","$","(",")","*","+","?","|","{","}","\\"].includes(i)&&(t+="\\"),t+=i),s=i;return new RegExp("^"+t+"$","i")}(i)),n}function Te(e,t){const{operator:s,operand:i}=t;if(void 0===e||void 0===i)return!1;if("number"==typeof i&&"="===s)return ue(e)===ue(i);if("<>"===s||"="===s){let o;return o=typeof e==typeof i&&("string"==typeof e&&t.regexp?t.regexp.test(e):e===i),"="===s?o:!o}if(typeof e==typeof i)switch(s){case"<":return e<i;case">":return e>i;case"<=":return e<=i;case">=":return e>=i}return!1}function xe(e,t,s=!1){const i=e.length;if(i%2==1)throw new Error(a("Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs."));const o=e[0].length,n=e[0][0].length;let r=[];for(let t=0;t<i-1;t+=2){const i=e[t];if(!Array.isArray(i)||i.length!==o||i[0].length!==n)throw new Error(a("Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension"));const l=ue(e[t+1]);r.push(we(l,s))}for(let s=0;s<o;s++)for(let o=0;o<n;o++){let n=!0;for(let t=0;t<i-1;t+=2){if(n=Te(e[t][s][o],r[t/2]),!n)break}n&&t(s,o)}}function Re(e,t){if(void 0===t)return-1;const s=typeof t;let i,o,n,r,a,l,c=0,h=e.length-1;if(typeof e[c]===s&&t<e[c])return-1;if(typeof e[h]===s&&e[h]<=t)return h;for(;h-c>=0;){for(n=Math.ceil((c+h)/2),r=n,a=e[r],l=typeof a;c<=r&&s!==l;)r--,a=e[r],l=typeof a;l===s&&a<=t&&(void 0===i||i<a||i===a&&o<r)&&(i=a,o=r),l===s&&a>t?h=r-1:c=n+1}return void 0!==o?o:-1}class Le{constructor(){this.content={}}add(e,t){return this.content[e]=t,this}get(e){const t=this.content[e];if(!t&&!(e in this.content))throw new Error(`Cannot find ${e} in this registry!`);return t}contains(e){return e in this.content}getAll(){return Object.values(this.content)}remove(e){delete this.content[e]}}const Ae=/(.*?)\((.*?)\)(.*)/,Me=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>","META"];function _e(e){let t=e.split("\n");const s=[];for(let e of t)e=e.trim(),e&&s.push(Oe(e));return s}function Oe(e){let t,s=e.match(Ae),i=s[1].trim(),o=[],n=!1,r=!1,a=!1;for(let e of s[2].split(",")){const s=e.trim().toUpperCase();let i=Me.find((e=>s===e));i?o.push(i):"RANGE<ANY>"===s?o.push("RANGE"):"OPTIONAL"===s?n=!0:"REPEATING"===s?r=!0:"LAZY"===s?a=!0:s.startsWith("DEFAULT=")&&(t=e.trim().slice(8))}const l={name:i,description:s[3].trim(),type:o};return n&&(l.optional=!0),r&&(l.repeating=!0),a&&(l.lazy=!0),void 0!==t&&(l.default=!0,l.defaultValue=t),l}function Ne(e){let t=0,s=0,i=0;for(let o of e.args)t++,o.optional||o.repeating||o.default||s++,o.repeating&&i++;const o=e;return o.minArgRequired=s,o.maxArgPossible=i?1/0:t,o.nbrArgRepeating=i,o.getArgToFocus=function(e,t){if(!t)return e=>e;if(1===t)return t=>Math.min(t,e);const s=e-t;return e=>{if(e<=s)return e;return s+((e-s)%t||t)}}(t,i),o}var ke;!function(e){e.boolean="boolean",e.number="number",e.text="text",e.empty="empty",e.error="error"}(ke||(ke={}));const Fe=new Set(["RENAME_SHEET","DELETE_SHEET","CREATE_SHEET","ADD_COLUMNS_ROWS","REMOVE_COLUMNS_ROWS","DELETE_CELL","INSERT_CELL","UNDO","REDO"]),$e=new Set(["START","ACTIVATE_SHEET","COPY","START_SELECTION","SET_SELECTION","ALTER_SELECTION","START_SELECTION_EXPANSION","PREPARE_SELECTION_EXPANSION","STOP_SELECTION","RESIZE_VIEWPORT","SET_VIEWPORT_OFFSET","SELECT_ALL","SELECT_CELL","SELECT_COLUMN","SELECT_ROW","MOVE_POSITION","SELECT_SEARCH_NEXT_MATCH","SELECT_SEARCH_PREVIOUS_MATCH","REFRESH_SEARCH","UPDATE_SEARCH","CLEAR_SEARCH","EVALUATE_CELLS","SET_CURRENT_CONTENT","SET_FORMULA_VISIBILITY"]),De=new Set(["UPDATE_CELL","UPDATE_CELL_POSITION","CLEAR_CELL","DELETE_CONTENT","ADD_COLUMNS_ROWS","REMOVE_COLUMNS_ROWS","RESIZE_COLUMNS_ROWS","HIDE_COLUMNS_ROWS","UNHIDE_COLUMNS_ROWS","SET_GRID_LINES_VISIBILITY","ADD_MERGE","REMOVE_MERGE","CREATE_SHEET","DELETE_SHEET","DUPLICATE_SHEET","MOVE_SHEET","RENAME_SHEET","ADD_CONDITIONAL_FORMAT","REMOVE_CONDITIONAL_FORMAT","CREATE_FIGURE","DELETE_FIGURE","UPDATE_FIGURE","SET_FORMATTING","CLEAR_FORMATTING","SET_BORDER","CREATE_CHART","UPDATE_CHART"]);function Ue(e){return De.has(e.type)}class Pe{constructor(e=[]){Array.isArray(e)||(e=[e]),e=[...new Set(e)],this.reasons=e.filter((e=>0!==e))}static get Success(){return new Pe}get isSuccessful(){return 0===this.reasons.length}isCancelledBecause(e){return this.reasons.includes(e)}}var Be,Ve,He,ze;e.CommandResult=void 0,(Be=e.CommandResult||(e.CommandResult={}))[Be.Success=0]="Success",Be[Be.CancelledForUnknownReason=1]="CancelledForUnknownReason",Be[Be.WillRemoveExistingMerge=2]="WillRemoveExistingMerge",Be[Be.MergeIsDestructive=3]="MergeIsDestructive",Be[Be.CellIsMerged=4]="CellIsMerged",Be[Be.InvalidTarget=5]="InvalidTarget",Be[Be.EmptyUndoStack=6]="EmptyUndoStack",Be[Be.EmptyRedoStack=7]="EmptyRedoStack",Be[Be.NotEnoughElements=8]="NotEnoughElements",Be[Be.NotEnoughSheets=9]="NotEnoughSheets",Be[Be.MissingSheetName=10]="MissingSheetName",Be[Be.DuplicatedSheetName=11]="DuplicatedSheetName",Be[Be.DuplicatedSheetId=12]="DuplicatedSheetId",Be[Be.ForbiddenCharactersInSheetName=13]="ForbiddenCharactersInSheetName",Be[Be.WrongSheetMove=14]="WrongSheetMove",Be[Be.WrongSheetPosition=15]="WrongSheetPosition",Be[Be.InvalidAnchorZone=16]="InvalidAnchorZone",Be[Be.SelectionOutOfBound=17]="SelectionOutOfBound",Be[Be.TargetOutOfSheet=18]="TargetOutOfSheet",Be[Be.WrongPasteSelection=19]="WrongPasteSelection",Be[Be.EmptyClipboard=20]="EmptyClipboard",Be[Be.EmptyRange=21]="EmptyRange",Be[Be.InvalidRange=22]="InvalidRange",Be[Be.InvalidSheetId=23]="InvalidSheetId",Be[Be.InputAlreadyFocused=24]="InputAlreadyFocused",Be[Be.MaximumRangesReached=25]="MaximumRangesReached",Be[Be.InvalidChartDefinition=26]="InvalidChartDefinition",Be[Be.EmptyDataSet=27]="EmptyDataSet",Be[Be.InvalidDataSet=28]="InvalidDataSet",Be[Be.InvalidLabelRange=29]="InvalidLabelRange",Be[Be.InvalidAutofillSelection=30]="InvalidAutofillSelection",Be[Be.WrongComposerSelection=31]="WrongComposerSelection",Be[Be.MinBiggerThanMax=32]="MinBiggerThanMax",Be[Be.LowerBiggerThanUpper=33]="LowerBiggerThanUpper",Be[Be.MidBiggerThanMax=34]="MidBiggerThanMax",Be[Be.MinBiggerThanMid=35]="MinBiggerThanMid",Be[Be.FirstArgMissing=36]="FirstArgMissing",Be[Be.SecondArgMissing=37]="SecondArgMissing",Be[Be.MinNaN=38]="MinNaN",Be[Be.MidNaN=39]="MidNaN",Be[Be.MaxNaN=40]="MaxNaN",Be[Be.ValueUpperInflectionNaN=41]="ValueUpperInflectionNaN",Be[Be.ValueLowerInflectionNaN=42]="ValueLowerInflectionNaN",Be[Be.MinInvalidFormula=43]="MinInvalidFormula",Be[Be.MidInvalidFormula=44]="MidInvalidFormula",Be[Be.MaxInvalidFormula=45]="MaxInvalidFormula",Be[Be.ValueUpperInvalidFormula=46]="ValueUpperInvalidFormula",Be[Be.ValueLowerInvalidFormula=47]="ValueLowerInvalidFormula",Be[Be.InvalidSortZone=48]="InvalidSortZone",Be[Be.WaitingSessionConfirmation=49]="WaitingSessionConfirmation",Be[Be.MergeOverlap=50]="MergeOverlap",Be[Be.TooManyHiddenElements=51]="TooManyHiddenElements",Be[Be.Readonly=52]="Readonly",Be[Be.InvalidOffset=53]="InvalidOffset",Be[Be.InvalidViewportSize=54]="InvalidViewportSize",Be[Be.FigureDoesNotExist=55]="FigureDoesNotExist",Be[Be.DuplicatedFigureId=56]="DuplicatedFigureId",Be[Be.DuplicatedChartId=57]="DuplicatedChartId",Be[Be.ChartDoesNotExist=58]="ChartDoesNotExist",function(e){e.FormatFromArgument="FormatFromArgument"}(Ve||(Ve={})),function(e){e[e.UP=0]="UP",e[e.DOWN=1]="DOWN",e[e.LEFT=2]="LEFT",e[e.RIGHT=3]="RIGHT"}(He||(He={})),function(e){e[e.Background=0]="Background",e[e.Highlights=1]="Highlights",e[e.Clipboard=2]="Clipboard",e[e.Search=3]="Search",e[e.Chart=4]="Chart",e[e.Selection=5]="Selection",e[e.Autofill=6]="Autofill",e[e.Headers=7]="Headers"}(ze||(ze={}));const Ze={description:a("Absolute value of a number."),args:_e(`\n value (number) ${a("The number of which to return the absolute value.")}\n `),returns:["NUMBER"],compute:function(e){return Math.abs(he(e))},isExported:!0},Ge={description:a("Inverse cosine of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<=1),a("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.acos(t)},isExported:!0},We={description:a("Inverse hyperbolic cosine of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic cosine. Must be greater than or equal to 1.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>t>=1),a("The value (%s) must be greater than or equal to 1.",t.toString())),Math.acosh(t)},isExported:!0},qe={description:a("Inverse cotangent of a value."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse cotangent.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)},isExported:!0},je={description:a("Inverse hyperbolic cotangent of a value."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic cotangent. Must not be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)>1),a("The value (%s) cannot be between -1 and 1 inclusive.",t.toString())),Math.log((t+1)/(t-1))/2},isExported:!0},Ye={description:a("Inverse sine of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<=1),a("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.asin(t)},isExported:!0},Xe={description:a("Inverse hyperbolic sine of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic sine.")}\n `),returns:["NUMBER"],compute:function(e){return Math.asinh(he(e))},isExported:!0},Ke={description:a("Inverse tangent of a value, in radians."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse tangent.")}\n `),returns:["NUMBER"],compute:function(e){return Math.atan(he(e))},isExported:!0},Qe={description:a("Angle from the X axis to a point (x,y), in radians."),args:_e(`\n x (number) ${a("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n y (number) ${a("The y coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n `),returns:["NUMBER"],compute:function(e,t){const s=he(e),i=he(t);return le((()=>0!==s||0!==i),a("Function [[FUNCTION_NAME]] caused a divide by zero error.")),Math.atan2(i,s)},isExported:!0},Je={description:a("Inverse hyperbolic tangent of a number."),args:_e(`\n value (number) ${a("The value for which to calculate the inverse hyperbolic tangent. Must be between -1 and 1, exclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>Math.abs(t)<1),a("The value (%s) must be between -1 and 1 exclusive.",t.toString())),Math.atanh(t)},isExported:!0},et={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n value (number) ${a("The value to round up to the nearest integer multiple of factor.")}\n factor (number, default=1) ${a("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){const s=he(e),i=he(t);return le((()=>i>=0||s<=0),a("The factor (%s) must be positive when the value (%s) is positive.",i.toString(),s.toString())),i?Math.ceil(s/i)*i:0},isExported:!0},tt={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, default=0) ${a("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded towards zero. Otherwise, it is rounded away from zero.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1,s=0){let i=he(t);if(0===i)return 0;const o=he(e);if(i=Math.abs(i),o>=0)return Math.ceil(o/i)*i;return 0===he(s)?-Math.floor(Math.abs(o)/i)*i:-Math.ceil(Math.abs(o)/i)*i},isExported:!0},st={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return tt.compute(e,t,0)},isExported:!0},it={description:a("Cosine of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cosine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cos(he(e))},isExported:!0},ot={description:a("Hyperbolic cosine of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cosine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cosh(he(e))},isExported:!0},nt={description:a("Cotangent of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cotangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.tan(t)},isExported:!0},rt={description:a("Hyperbolic cotangent of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cotangent of.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.tanh(t)},isExported:!0},at={description:a("Number of empty values."),args:_e(`\n value1 (any, range) ${a("The first value or range in which to count the number of blanks.")}\n value2 (any, range, repeating) ${a("Additional values or ranges in which to count the number of blanks.")}\n `),returns:["NUMBER"],compute:function(...e){return be(e,((e,t)=>null==t||""===t?e+1:e),0)},isExported:!0},lt={description:a("A conditional count across a range."),args:_e(`\n range (range) ${a("The range that is tested against criterion.")}\n criterion (string) ${a("The pattern or test to apply to range.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;return xe(e,((e,s)=>{t+=1})),t},isExported:!0},ct={description:a("Count values depending on multiple criteria."),args:_e(`\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("Additional criteria to check.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;return xe(e,((e,s)=>{t+=1})),t},isExported:!0};function ht(e){switch(e){case void 0:case"":case null:return!1;default:return!0}}const dt={description:a("Counts number of unique values in a range."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider for uniqueness.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider for uniqueness.")}\n `),returns:["NUMBER"],compute:function(...e){return be(e,((e,t)=>ht(t)?e.add(t):e),new Set).size}},ut={description:a("Counts number of unique values in a range, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the number of unique values will be counted.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=new Set;return xe(t,((t,i)=>{const o=e[t][i];ht(o)&&s.add(o)})),s.size}},pt={description:a("Cosecant of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the cosecant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.sin(t)},isExported:!0},gt={description:a("Hyperbolic cosecant of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic cosecant of.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),1/Math.sinh(t)},isExported:!0},ft={description:a("Converts from another base to decimal."),args:_e(`\n value (string) ${a("The number to convert.")},\n base (number) ${a("The base to convert the value from.")},\n `),returns:["NUMBER"],compute:function(e,t){let s=he(t);s=Math.floor(s),le((()=>2<=s&&s<=36),a("The base (%s) must be between 2 and 36 inclusive.",s.toString()));const i=ue(e);if(""===i)return 0;le((()=>!!i.match(/^-?[a-z0-9]+$/i)),a("The value (%s) must be a valid base %s representation.",i,s.toString()));const o=parseInt(i,s);return le((()=>!isNaN(o)),a("The value (%s) must be a valid base %s representation.",i,s.toString())),o},isExported:!0},mt={description:a("Converts an angle value in radians to degrees."),args:_e(`\n angle (number) ${a("The angle to convert from radians to degrees.")}\n `),returns:["NUMBER"],compute:function(e){return 180*he(e)/Math.PI},isExported:!0},vt={description:a("Euler's number, e (~2.718) raised to a power."),args:_e(`\n value (number) ${a("The exponent to raise e.")}\n `),returns:["NUMBER"],compute:function(e){return Math.exp(he(e))},isExported:!0},Et={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n value (number) ${a("The value to round down to the nearest integer multiple of factor.")}\n factor (number, default=1) ${a("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){const s=he(e),i=he(t);return le((()=>i>=0||s<=0),a("The factor (%s) must be positive when the value (%s) is positive.",i.toString(),s.toString())),i?Math.floor(s/i)*i:0},isExported:!0},St={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round down to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, default=0) ${a("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded away from zero. Otherwise, it is rounded towards zero.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1,s=0){let i=he(t);if(0===i)return 0;const o=he(e);if(i=Math.abs(i),o>=0)return Math.floor(o/i)*i;return 0===he(s)?-Math.ceil(Math.abs(o)/i)*i:-Math.floor(Math.abs(o)/i)*i},isExported:!0},bt={description:a("Rounds number down to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round down to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){return St.compute(e,t,0)},isExported:!0},Ct={description:a("Whether the provided value is even."),args:_e(`\n value (number) ${a("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=de(e);return!(1&Math.floor(Math.abs(t)))},isExported:!0},It={description:a("Rounds number up to nearest multiple of factor."),args:_e(`\n number (number) ${a("The value to round up to the nearest integer multiple of significance.")}\n significance (number, default=1) ${a("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=1){return tt.compute(e,t,0)},isExported:!0},yt={description:a("Whether the provided value is even."),args:_e(`\n value (number) ${a("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=de(e);return!!(1&Math.floor(Math.abs(t)))},isExported:!0},wt={description:a("The logarithm of a number, base e (euler's number)."),args:_e(`\n value (number) ${a("The value for which to calculate the logarithm, base e.")}\n `),returns:["NUMBER"],compute:function(e){const t=he(e);return le((()=>t>0),a("The value (%s) must be strictly positive.",t.toString())),Math.log(t)},isExported:!0},Tt={description:a("Modulo (remainder) operator."),args:_e(`\n dividend (number) ${a("The number to be divided to find the remainder.")}\n divisor (number) ${a("The number to divide by.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(t);le((()=>0!==s),a("The divisor must be different from 0."));const i=he(e)%s;return i>0&&s<0||i<0&&s>0?i+s:i},isExported:!0},xt={description:a("Rounds a number up to the nearest odd integer."),args:_e(`\n value (number) ${a("The value to round to the next greatest odd number.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e){const t=he(e);let s=Math.ceil(Math.abs(t));return s=1&s?s:s+1,t<0?-s:s},isExported:!0},Rt={description:a("The number pi."),args:[],returns:["NUMBER"],compute:function(){return Math.PI},isExported:!0},Lt={description:a("A number raised to a power."),args:_e(`\n base (number) ${a("The number to raise to the exponent power.")}\n exponent (number) ${a("The exponent to raise base to.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(e),i=he(t);return le((()=>s>=0||Number.isInteger(i)),a("The exponent (%s) must be an integer when the base is negative.",i.toString())),Math.pow(s,i)},isExported:!0},At={description:a("Result of multiplying a series of numbers together."),args:_e(`\n factor1 (number, range<number>) ${a("The first number or range to calculate for the product.")}\n factor2 (number, range<number>, repeating) ${a("More numbers or ranges to calculate for the product.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0,s=1;for(let i of e)if(Array.isArray(i))for(let e of i)for(let i of e)"number"==typeof i&&(s*=i,t+=1);else null!=i&&(s*=de(i),t+=1);return 0===t?0:s},isExported:!0},Mt={description:a("A random number between 0 inclusive and 1 exclusive."),args:[],returns:["NUMBER"],compute:function(){return Math.random()},isExported:!0},_t={description:a("Random integer between two values, inclusive."),args:_e(`\n low (number) ${a("The low end of the random range.")}\n high (number) ${a("The high end of the random range.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){let s=he(e);Number.isInteger(s)||(s=Math.ceil(s));let i=he(t);return Number.isInteger(i)||(i=Math.floor(i)),le((()=>s<=i),a("The high (%s) must be greater than or equal to the low (%s).",i.toString(),s.toString())),s+Math.ceil((i-s+1)*Math.random())-1},isExported:!0},Ot={description:a("Rounds a number according to standard rules."),args:_e(`\n value (number) ${a("The value to round to places number of places.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.round(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.round(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},Nt={description:a("Rounds down a number."),args:_e(`\n value (number) ${a("The value to round to places number of places, always rounding down.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.floor(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.floor(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},kt={description:a("Rounds up a number."),args:_e(`\n value (number) ${a("The value to round to places number of places, always rounding up.")}\n places (number, default=0) ${a("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);const o=Math.abs(s);let n;return 0===i?n=Math.ceil(o):(Number.isInteger(i)||(i=Math.trunc(i)),n=Math.ceil(o*Math.pow(10,i))/Math.pow(10,i)),s>=0?n:-n},isExported:!0},Ft={description:a("Secant of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the secant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cos(he(e))},isExported:!0},$t={description:a("Hyperbolic secant of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic secant of.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cosh(he(e))},isExported:!0},Dt={description:a("Sine of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the sine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sin(he(e))},isExported:!0},Ut={description:a("Hyperbolic sine of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic sine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sinh(he(e))},isExported:!0},Pt={description:a("Positive square root of a positive number."),args:_e(`\n value (number) ${a("The number for which to calculate the positive square root.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e){const t=he(e);return le((()=>t>=0),a("The value (%s) must be positive or null.",t.toString())),Math.sqrt(t)},isExported:!0},Bt={description:a("Sum of a series of numbers and/or cells."),args:_e(`\n value1 (number, range<number>) ${a("The first number or range to add together.")}\n value2 (number, range<number>, repeating) ${a("Additional numbers or ranges to add to value1.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){return Ce(e,((e,t)=>e+t),0)},isExported:!0},Vt={description:a("A conditional sum across a range."),args:_e(`\n criteria_range (range) ${a("The range which is tested against criterion.")}\n criterion (string) ${a("The pattern or test to apply to range.")}\n sum_range (range, default=criteria_range) ${a("The range to be summed, if different from range.")}\n `),returns:["NUMBER"],compute:function(e,t,s){void 0===s&&(s=e);let i=0;return xe([e,t],((e,t)=>{const o=s[e][t];"number"==typeof o&&(i+=o)})),i},isExported:!0},Ht={description:a("Sums a range depending on multiple criteria."),args:_e(`\n sum_range (range) ${a("The range to sum.")}\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges to check.")}\n criterion2 (string, repeating) ${a("Additional criteria to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s+=o)})),s},isExported:!0},zt={description:a("Tangent of an angle provided in radians."),args:_e(`\n angle (number) ${a("The angle to find the tangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tan(he(e))},isExported:!0},Zt={description:a("Hyperbolic tangent of any real number."),args:_e(`\n value (number) ${a("Any real value to calculate the hyperbolic tangent of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tanh(he(e))},isExported:!0},Gt={description:a("Truncates a number."),args:_e(`\n value (number) ${a("The value to be truncated.")}\n places (number, default=0) ${a("The number of significant digits to the right of the decimal point to retain.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t=0){const s=he(e);let i=he(t);return 0===i?Math.trunc(s):(Number.isInteger(i)||(i=Math.trunc(i)),Math.trunc(s*Math.pow(10,i))/Math.pow(10,i))},isExported:!0};var Wt=Object.freeze({__proto__:null,ABS:Ze,ACOS:Ge,ACOSH:We,ACOT:qe,ACOTH:je,ASIN:Ye,ASINH:Xe,ATAN:Ke,ATAN2:Qe,ATANH:Je,CEILING:et,CEILING_MATH:tt,CEILING_PRECISE:st,COS:it,COSH:ot,COT:nt,COTH:rt,COUNTBLANK:at,COUNTIF:lt,COUNTIFS:ct,COUNTUNIQUE:dt,COUNTUNIQUEIFS:ut,CSC:pt,CSCH:gt,DECIMAL:ft,DEGREES:mt,EXP:vt,FLOOR:Et,FLOOR_MATH:St,FLOOR_PRECISE:bt,ISEVEN:Ct,ISO_CEILING:It,ISODD:yt,LN:wt,MOD:Tt,ODD:xt,PI:Rt,POWER:Lt,PRODUCT:At,RAND:Mt,RANDBETWEEN:_t,ROUND:Ot,ROUNDDOWN:Nt,ROUNDUP:kt,SEC:Ft,SECH:$t,SIN:Dt,SINH:Ut,SQRT:Pt,SUM:Bt,SUMIF:Vt,SUMIFS:Ht,TAN:zt,TANH:Zt,TRUNC:Gt});const qt=["#eb6d00","#0074d9","#ad8e00","#169ed4","#b10dc9","#00a82d","#00a3a3","#f012be","#3d9970","#111111","#62A300","#ff4136","#949494","#85144b","#001f3f"];function jt(e){return e.toString(16).padStart(6,"0")}let Yt=0;function Xt(){return Yt=++Yt%qt.length,qt[Yt]}function Kt(e){return e.includes("rgb")?function(e){return e.slice(4,-1).split(",").map((e=>parseInt(e,10).toString(16).padStart(2,"0"))).join("").toUpperCase()}(e):(3===(e=e.replace("#","").toUpperCase()).length&&(e=e.split("").reduce(((e,t)=>e+t+t),"")),e)}const Qt=new RegExp(/\$?([A-Z]{1,3})\$?([0-9]{1,7})/,"i"),Jt=new RegExp(/^\s*(.*!)?\$?[A-Z]{1,3}\$?[0-9]{1,7}\s*(\s*:\s*\$?[A-Z]{1,3}\$?[0-9]{1,7}\s*)?$/,"i");function es(e){const t=e.split("!"),s=t.pop();return{sheetName:t.join("!")||void 0,xc:s}}function ts(e){return e<26?String.fromCharCode(65+e):ts(Math.floor(e/26)-1)+ts(e%26)}function ss(e){e=e.toUpperCase().trim();const[t,s,i]=e.match(Qt);if(t!==e)throw new Error(`Invalid cell description: ${e}`);const o=function(e){let t=0;const s=e.length;for(let i=0;i<s;i++)t+=(e.charCodeAt(i)-65+(i<s-1?1:0))*26**(s-i-1);return t}(s);return[o,parseInt(i,10)-1]}function is(e,t,s={colFixed:!1,rowFixed:!1}){return(s.colFixed?"$":"")+ts(e)+(s.rowFixed?"$":"")+String(t+1)}const os=140,ns=20,rs=.035;function as(e){return ns+(os-ns)*Math.exp(-rs*(e-1))}const ls=[{pt:7.5,px:10},{pt:8,px:11},{pt:9,px:12},{pt:10,px:13},{pt:10.5,px:14},{pt:11,px:15},{pt:12,px:16},{pt:14,px:18.7},{pt:15,px:20},{pt:16,px:21.3},{pt:18,px:24},{pt:22,px:29.3},{pt:24,px:32},{pt:26,px:34.7},{pt:36,px:48}],cs={};for(let e of ls)cs[e.pt]=e.px;function hs(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ds(e){const t=Array.isArray(e)?[]:{};switch(typeof e){case"object":if(null===e)return e;if(!(function(e){return"object"==typeof e&&(null==e?void 0:e.constructor)===Object}(e)||e instanceof Array))throw new Error("Unsupported type: only objects and arrays are supported");for(const s in e)t[s]=ds(e[s]);return t;case"number":case"string":case"boolean":case"function":case"undefined":return e;default:throw new Error("Unsupported type: "+typeof e)}}function us(e){var t;return(null===(t=e.match(/\w/g))||void 0===t?void 0:t.length)!==e.length&&(e=`'${e}'`),e}function ps(e,t,s){return e<t?t:e>s?s:e}function gs(e,t,s){const i=s.italic?"italic ":"",o=s.bold?"bold":T,n=s.fontSize||x,r=cs[n];return e.font=`${i}${o} ${r}px ${R}`,e.measureText(t).width}function fs(e,t,s=1){if(t<=e&&s>0)return[];if(0===s)throw new Error("range() step must not be zero");const i=Math.ceil(Math.abs((t-e)/s)),o=Array(i);for(let t=0;t<i;t++)o[t]=e+t*s;return o}function ms(e){return e.reduce(((e,t,s,i)=>{if(1===Math.abs(t-i[s-1])){e[e.length-1].push(t)}else e.push([t]);return e}),[])}function*vs(e,t){t.next();for(const s of e){const e=t.next();yield{...s,next:e.done?void 0:e.value}}}function Es(e){const t=e.toUpperCase();return"TRUE"===t||"FALSE"===t}function Ss(e){return null!==G(e)}const bs=/^\[(.+)\]\((.+)\)$/,Cs=/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;function Is(e){return bs.test(e)}function ys(e,t){return`[${e}](${t})`}function ws(e){const t=e.match(bs)||[],s=t[1],i=t[2];if(!s||!i)throw new Error(`Could not parse markdown link ${e}.`);return{label:s,url:i}}const Ts="o-spreadsheet://";function xs(e){if(!Is(e))return!1;const{url:t}=ws(e);return t.startsWith(Ts)}function Rs(e){if(e.startsWith(Ts))return e.substr(Ts.length);throw new Error(`${e} is not a valid sheet link`)}function Ls(e){return void 0!==e}const As={};function Ms(e,t){if(e===t)return!0;if(e&&!t||t&&!e)return!1;if(typeof e!=typeof t)return!1;if("object"!=typeof e)return!1;const s=new Set;Object.keys(e).forEach((e=>s.add(e))),Object.keys(t).forEach((e=>s.add(e)));for(let i of s){if(typeof e[i]!=typeof e[i])return!1;if("object"==typeof e[i]){if(!Ms(e[i],t[i]))return!1}else if(e[i]!==t[i])return!1}return!0}function _s(e){let t=e.length;if(t<1e5)return Math.max(...e);let s=-1/0;for(;t--;)s=e[t]>s?e[t]:s;return s}function Os(e){let t=e.length;if(t<1e5)return Math.min(...e);let s=1/0;for(;t--;)s=e[t]<s?e[t]:s;return s}function Ns(e){const t=(e=e.split("!").pop()).replace(/\$/g,"").split(":");let s,i,o,n,r=ss(t[0].trim());if(o=n=r[0],s=i=r[1],2===t.length){let e=ss(t[1].trim());n=e[0],i=e[1]}return{top:s,bottom:i,left:o,right:n}}function ks(e){let{top:t,bottom:s,left:i,right:o}=Ns(e);return o<i&&([o,i]=[i,o]),s<t&&([s,t]=[t,s]),{top:t,bottom:s,left:i,right:o}}function Fs(e){return!(isNaN(e.bottom)||isNaN(e.top)||isNaN(e.left)||isNaN(e.right))&&(!(e.top<0||e.left<0||e.right<0||e.bottom<0)&&(e.bottom>=e.top&&e.right>=e.left))}function $s(e){const{top:t,bottom:s,left:i,right:o}=e;return t===s&&i===o?is(i,t):`${is(i,t)}:${is(o,s)}`}function Ds(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom";return e[t]<=r&&e[a]>r?Ys(e,n,"RESIZE",o):r<e[t]?Ys(e,n,"MOVE",o):{...e}}function Us(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<r&&e[i]>=r&&n--;return{...e,[t]:o,[i]:n}}function Ps(e,t){return{top:Math.min(e.top,t.top),left:Math.min(e.left,t.left),bottom:Math.max(e.bottom,t.bottom),right:Math.max(e.right,t.right)}}function Bs(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function Vs(e,t){return!(e.bottom<t.top||t.bottom<e.top)&&!(e.right<t.left||t.right<e.left)}function Hs(e,t,s){const{left:i,right:o,top:n,bottom:r}=s;return e>=i&&e<=o&&t>=n&&t<=r}function zs(e,t){const s={};for(let t of e)if(t){const e=ks(t);for(let t=e.left;t<=e.right;t++)void 0===s[t]&&(s[t]=[]),s[t].push({top:e.top,bottom:e.bottom,remove:!1})}for(let e of t){const t=ks(e);for(let e=t.left;e<=t.right;e++)void 0===s[e]&&(s[e]=[]),s[e].push({top:t.top,bottom:t.bottom,remove:!0})}const i=[];for(let[e,t]of Object.entries(s))i.push({col:parseInt(e),ranges:Zs(t)});return function(e){const t=e.sort(((e,t)=>e.col-t.col)),s=[];let i=[],o=0;for(let e=0;e<=t.length-1;e++){let n=[];if(o+1===t[e].col)for(let s of t[e].ranges){let o=!1;for(let e of i)s.top==e.top&&s.bottom==e.bottom&&(n.push(e),o=!0);o||n.push({top:s.top,bottom:s.bottom,startCol:t[e].col})}else n=t[e].ranges.map((s=>({top:s.top,bottom:s.bottom,startCol:t[e].col})));const r=i.filter((e=>!n.includes(e)));for(let e of r)s.push({top:e.top,bottom:e.bottom,left:e.startCol,right:o});o=t[e].col,i=n}for(let e of i)s.push({top:e.top,bottom:e.bottom,left:e.startCol,right:o});return s}(i).map($s)}function Zs(e){const t=new Set,s=new Set;for(let i of e)for(let e=i.top;e<=i.bottom;e++)i.remove?s.add(e):t.add(e);const i=[...t].filter((e=>!s.has(e))).sort(((e,t)=>e-t)),o=[];let n;for(let e of i)n?e===n.bottom+1?n.bottom=e:(o.push({top:n.top,bottom:n.bottom}),n={top:e,bottom:e}):n={top:e,bottom:e};return n&&o.push({top:n.top,bottom:n.bottom}),o}function Gs(e,t,s,i,o=1,n=1){var r;const{top:a,bottom:l,left:c,right:h}=e,d=new Array(Math.floor((h-c+1)/o));for(let e=c;e<=h;e+=o){let o=new Array(Math.floor((l-a+1)/n));d[e-c]=o;for(let c=a;c<=l;c+=n){let l=null===(r=t.rows[c])||void 0===r?void 0:r.cells[e];o[(c-a)/n]=l?s(l):i}}return d}function Ws(e){return{height:e.bottom-e.top+1,width:e.right-e.left+1}}function qs(e){const{width:t,height:s}=Ws(e);return 1===t||1===s}function js(e){const t=[],[s,i]=[e.right,e.left].sort(((e,t)=>e-t)),[o,n]=[e.top,e.bottom].sort(((e,t)=>e-t));for(const e of fs(s,i+1))for(const s of fs(o,n+1))t.push([e,s]);return t}function Ys(e,t,s,i){const o="columns"===t?"right":"bottom",n={...e};return"MOVE"===s&&(n["columns"===t?"left":"top"]+=i),n[o]+=i,n}function Xs(e){return e.reverse().filter(((e,t,s)=>t===s.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}function Ks(e){return{top:Math.min(e.top,e.bottom),bottom:Math.max(e.top,e.bottom),left:Math.min(e.left,e.right),right:Math.max(e.left,e.right)}}function Qs(e){const t=[];let s=0;for(let i=0;i<e;i++){const e={start:s,end:s+E,size:E,name:ts(i)};t.push(e),s=e.end}return t}function Js(e){const t=[];let s=0;for(let i=0;i<e;i++){const e={start:s,end:s+S,size:S,name:String(i+1),cells:{}};t.push(e),s=e.end}return t}function ei(e,t){var s;const i=[];let o=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||E,r=(null===(s=e[n])||void 0===s?void 0:s.isHidden)||!1,a={start:o,end:r?o:o+t,size:t,name:ts(n)};r&&(a.isHidden=r),i.push(a),o=a.end}return i}function ti(e,t){var s;const i=[];let o=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||S,r=(null===(s=e[n])||void 0===s?void 0:s.isHidden)||!1,a={start:o,end:r?o:o+t,size:t,name:String(n+1),cells:{}};r&&(a.isHidden=r),i.push(a),o=a.end}return i}function si(e,t=!1){const s={};for(let i in e){const o=e[i];(o.size!==E||t)&&(s[i]={size:o.size}),o.isHidden&&(s[i]=s[i]||{},s[i].isHidden=o.isHidden)}return s}function ii(e,t=!1){const s={};for(let i in e){const o=e[i];(o.size!==S||t)&&(s[i]={size:o.size}),o.isHidden&&(s[i]=s[i]||{},s[i].isHidden=o.isHidden)}return s}class oi{constructor(e=!1){this.isFastIdStrategy=!1,this.fastIdStart=0,this.setIsFastStrategy(e)}setIsFastStrategy(e){this.isFastIdStrategy=e}uuidv4(){return this.isFastIdStrategy?(this.fastIdStart++,String(this.fastIdStart)):window.crypto&&window.crypto.getRandomValues?([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))):"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))}}function ni(e,t,s){return[ri(e,"cols",fs(t,e.cols.length)),ri(e,"rows",fs(s,e.rows.length))]}function ri(e,t,s){const i=e[t];return s.find((e=>!i[e].isHidden))}function ai(e,t){let s=e[t].length-1;for(;s>=0&&!0===e[t][s].isHidden;)s--;return e[t][s]}function li(e,t,s){let i=[],o=[],n=0,r=0;ve([e],(e=>{i.push(e),n+=1})),ve([t],(e=>{o.push(e),r+=1})),le((()=>n===r),a("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",n.toString(),r.toString()));let l=0,c=0,h=0;for(let e=0;e<n;e++){const t=i[e],s=o[e];"number"==typeof t&&"number"==typeof s&&(l+=1,c+=t,h+=s)}le((()=>0!==l&&(!s||1!==l)),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const d=c/l,u=h/l;let p=0;for(let e=0;e<n;e++){const t=i[e],s=o[e];"number"==typeof t&&"number"==typeof s&&(p+=(t-d)*(s-u))}return p/(l-(s?1:0))}function ci(e,t,s){let i=0,o=0;const n=s?Ie:Ce;o=n(e,((e,t)=>(i+=1,e+t)),0),le((()=>0!==i&&(!t||1!==i)),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const r=o/i;return n(e,((e,t)=>e+Math.pow(t-r,2)),0)/(i-(t?1:0))}function hi(e,t,s){const i=he(t);le((()=>s?0<=i&&i<=1:0<i&&i<1),a("Function [[FUNCTION_NAME]] parameter 2 value is out of range."));let o,n=[],r=0;ve(e,(e=>{"number"==typeof e&&(o=Re(n,e),n.splice(o+1,0,e),r++)})),le((()=>0!==r),a("[[FUNCTION_NAME]] has no valid input data."));let l=(r+(s?-1:1))*i;if(s||(le((()=>1<=l&&l<=r),a("Function [[FUNCTION_NAME]] parameter 2 value is out of range.")),l--),Number.isInteger(l))return n[l];const c=Math.ceil(l),h=Math.floor(l);return n[c]*(l-h)+n[h]*(c-l)}const di={description:a("Average magnitude of deviations from mean."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;const s=Ce(e,((e,s)=>(t+=1,e+s)),0);le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const i=s/t;return Ce(e,((e,t)=>e+Math.abs(i-t)),0)/t},isExported:!0},ui={description:a("Numerical average value in a dataset, ignoring text."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0;const s=Ce(e,((e,s)=>(t+=1,e+s)),0);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),s/t},isExported:!0},pi=a("[[FUNCTION_NAME]] has mismatched range sizes."),gi=a("[[FUNCTION_NAME]] expects the weight to be positive or equal to 0."),fi={description:a("Weighted average."),args:_e(`\n values (number, range<number>) ${a("Values to average.")}\n weights (number, range<number>) ${a("Weights for each corresponding value.")}\n additional_values (number, range<number>, repeating) ${a("Additional values to average.")}\n additional_weights (number, range<number>, repeating) ${a("Additional weights.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t,s,i=0,o=0;le((()=>e.length%2==0),a("Wrong number of Argument[]. Expected an even number of Argument[]."));for(let n=0;n<e.length-1;n+=2)if(t=e[n],s=e[n+1],Array.isArray(t)){le((()=>Array.isArray(s)),pi);let e=t.length,n=t[0].length;le((()=>e===s.length&&n===s[0].length),pi);for(let r=0;r<e;r++)for(let e=0;e<n;e++){let n=t[r][e],l=s[r][e],c="number"==typeof n,h="number"==typeof l;le((()=>c===h),a("[[FUNCTION_NAME]] expects number values.")),h&&(le((()=>l>=0),gi),i+=n*l,o+=l)}}else s=he(s),t=he(t),le((()=>s>=0),gi),i+=t*s,o+=s;return le((()=>0!==o),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),i/o}},mi={description:a("Numerical average value in a dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=0;const s=Ie(e,((e,s)=>(t+=1,e+s)),0);return le((()=>0!==t),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),s/t},isExported:!0},vi={description:a("Average of values depending on criteria."),args:_e(`\n criteria_range (range) ${a("The range to check against criterion.")}\n criterion (string) ${a("The pattern or test to apply to criteria_range.")}\n average_range (range, default=criteria_range) ${a("The range to average. If not included, criteria_range is used for the average instead.")}\n `),returns:["NUMBER"],compute:function(e,t,s){null==s&&(s=e);let i=0,o=0;return xe([e,t],((t,n)=>{const r=(s||e)[t][n];"number"==typeof r&&(i+=1,o+=r)})),le((()=>0!==i),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),o/i},isExported:!0},Ei={description:a("Average of values depending on multiple criteria."),args:_e(`\n average_range (range) ${a("The range to average.")}\n criteria_range1 (range) ${a("The range to check against criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1.")}\n criteria_range2 (any, range, repeating) ${a("Additional criteria_range and criterion to check.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=0,i=0;return xe(t,((t,o)=>{const n=e[t][o];"number"==typeof n&&(s+=1,i+=n)})),le((()=>0!==s),a("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.")),i/s},isExported:!0},Si={description:a("The number of numeric values in dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when counting.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(...e){let t=0;for(let s of e)if(Array.isArray(s))for(let e of s)for(let s of e)"number"==typeof s&&(t+=1);else("string"!=typeof s||J(s)||G(s))&&(t+=1);return t},isExported:!0},bi={description:a("The number of values in a dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when counting.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(...e){return be(e,((e,t)=>null!=t?e+1:e),0)},isExported:!0},Ci={description:a("The covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!1)},isExported:!0},Ii={description:a("The covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!1)},isExported:!0},yi={description:a("The sample covariance of a dataset."),args:_e(`\n data_y (any, range) ${a("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${a("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return li(e,t,!0)},isExported:!0},wi={description:a("Nth largest element from a data set."),args:_e(`\n data (any, range) ${a("Array or range containing the dataset to consider.")}\n n (number) ${a("The rank from largest to smallest of the element to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=Math.trunc(he(t));let i,o=[],n=0;ve([e],(e=>{"number"==typeof e&&(i=Re(o,e),o.splice(i+1,0,e),n++,n>s&&(o.shift(),n--))}));const r=o.shift();return le((()=>void 0!==r),a("[[FUNCTION_NAME]] has no valid input data.")),le((()=>n>=s),a("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",s.toString())),r},isExported:!0},Ti={description:a("Maximum value in a numeric dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the maximum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ce(e,((e,t)=>e<t?t:e),-1/0);return t===-1/0?0:t},isExported:!0},xi={description:a("Maximum numeric value in a dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when calculating the maximum value.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ie(e,((e,t)=>Math.max(t,e)),-1/0);return t===-1/0?0:t},isExported:!0},Ri={description:a("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the maximum will be determined.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=-1/0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s=s<o?o:s)})),s===-1/0?0:s},isExported:!0},Li={description:a("Median value in a numeric dataset."),args:_e(`\n value1 (any, range) ${a("The first value or range to consider when calculating the median value.")}\n value2 (any, range, repeating) ${a("Additional values or ranges to consider when calculating the median value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){let t=[];return Ee(e,(e=>{t.push(e)})),hi(t,.5,!0)},isExported:!0},Ai={description:a("Minimum value in a numeric dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ce(e,((e,t)=>t<e?t:e),1/0);return t===1/0?0:t},isExported:!0},Mi={description:a("Minimum numeric value in a dataset."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(...e){const t=Ie(e,((e,t)=>Math.min(t,e)),1/0);return t===1/0?0:t},isExported:!0},_i={description:a("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:_e(`\n range (range) ${a("The range of cells from which the minimum will be determined.")}\n criteria_range1 (range) ${a("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${a("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")}\n criteria_range2 (any, range, repeating) ${a("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")}\n criterion2 (string, repeating) ${a("The pattern or test to apply to criteria_range2.")}\n `),returns:["NUMBER"],compute:function(e,...t){let s=1/0;return xe(t,((t,i)=>{const o=e[t][i];"number"==typeof o&&(s=s>o?o:s)})),s===1/0?0:s},isExported:!0},Oi={description:a("Value at a given percentile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile whose value within data will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return ki.compute(e,t)},isExported:!0},Ni={description:a("Value at a given percentile of a dataset exclusive of 0 and 1."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile, exclusive of 0 and 1, whose value within 'data' will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],t,!1)},isExported:!0},ki={description:a("Value at a given percentile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n percentile (number) ${a("The percentile whose value within data will be calculated and returned.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],t,!0)},isExported:!0},Fi={description:a("Value nearest to a specific quartile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return Di.compute(e,t)},isExported:!0},$i={description:a("Value nearest to a specific quartile of a dataset exclusive of 0 and 4."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value, exclusive of 0 and 4, to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],.25*Math.trunc(he(t)),!1)},isExported:!0},Di={description:a("Value nearest to a specific quartile of a dataset."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n quartile_number (number) ${a("Which quartile value to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return hi([e],.25*Math.trunc(he(t)),!0)},isExported:!0},Ui={description:a("Nth smallest element in a data set."),args:_e(`\n data (any, range) ${a("The array or range containing the dataset to consider.")}\n n (number) ${a("The rank from smallest to largest of the element to return.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=Math.trunc(he(t));let i,o=[],n=0;ve([e],(e=>{"number"==typeof e&&(i=Re(o,e),o.splice(i+1,0,e),n++,n>s&&(o.pop(),n--))}));const r=o.pop();return le((()=>void 0!==r),a("[[FUNCTION_NAME]] has no valid input data.")),le((()=>n>=s),a("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",s.toString())),r},isExported:!0},Pi={description:a("Standard deviation."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Gi.compute(...e))},isExported:!0},Bi={description:a("Standard deviation of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Wi.compute(...e))},isExported:!0},Vi={description:a("Standard deviation."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(qi.compute(...e))},isExported:!0},Hi={description:a("Standard deviation of sample (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(ji.compute(...e))},isExported:!0},zi={description:a("Standard deviation of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Yi.compute(...e))},isExported:!0},Zi={description:a("Standard deviation of entire population (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return Math.sqrt(Xi.compute(...e))},isExported:!0},Gi={description:a("Variance."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!1)},isExported:!0},Wi={description:a("Variance of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!1)},isExported:!0},qi={description:a("Variance."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!1)},isExported:!0},ji={description:a("Variance of sample (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the sample.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!0,!0)},isExported:!0},Yi={description:a("Variance of entire population."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!1)},isExported:!0},Xi={description:a("Variance of entire population (text as 0)."),args:_e(`\n value1 (number, range<number>) ${a("The first value or range of the population.")}\n value2 (number, range<number>, repeating) ${a("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(...e){return ci(e,!1,!0)},isExported:!0};var Ki=Object.freeze({__proto__:null,AVEDEV:di,AVERAGE:ui,AVERAGE_WEIGHTED:fi,AVERAGEA:mi,AVERAGEIF:vi,AVERAGEIFS:Ei,COUNT:Si,COUNTA:bi,COVAR:Ci,COVARIANCE_P:Ii,COVARIANCE_S:yi,LARGE:wi,MAX:Ti,MAXA:xi,MAXIFS:Ri,MEDIAN:Li,MIN:Ai,MINA:Mi,MINIFS:_i,PERCENTILE:Oi,PERCENTILE_EXC:Ni,PERCENTILE_INC:ki,QUARTILE:Fi,QUARTILE_EXC:$i,QUARTILE_INC:Di,SMALL:Ui,STDEV:Pi,STDEV_P:Bi,STDEV_S:Vi,STDEVA:Hi,STDEVP:zi,STDEVPA:Zi,VAR:Gi,VAR_P:Wi,VAR_S:qi,VARA:ji,VARP:Yi,VARPA:Xi});function Qi(e,t,s){var i;const o=new Map,n=e.length;for(let t=n-1;t>=0;t--)o.set(ue(e[t][0]).toUpperCase(),t);if("number"!=typeof t&&"string"!=typeof t)throw new Error(a("The field must be a number or a string"));let r;if("number"==typeof t){if(r=Math.trunc(t)-1,r<0||n-1<r)throw new Error(a("The field (%s) must be one of %s or must be a number between 1 and %s inclusive.",t.toString(),n.toString()))}else{const e=ue(t).toUpperCase();if(r=null!==(i=o.get(e))&&void 0!==i?i:-1,-1===r)throw new Error(a("The field (%s) must be one of %s.",ue(t),[...o.keys()].toString()))}const l=s[0].length;if(l<2)throw new Error(a("The criteria range contains %s row, it must be at least 2 rows.",l.toString()));let c=new Set;const h=e[0].length;for(let t=1;t<l;t++){let i=[],n=!0;for(let r=0;r<s.length;r++){const a=ue(s[r][0]).toUpperCase(),l=o.get(a),c=s[r][t];if(void 0!==c){if(void 0===l){n=!1;break}i.push([e[l].slice(1,h)]),i.push(c)}}if(n){if(!(i.length>0)){c=new Set(Array(h-1).keys());break}xe(i,((e,t)=>{c.add(t)}),!0)}}const d=e[r];return[...c].map((e=>d[e+1]))}const Ji=_e(`\n database (range) ${a("The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values.")}\n field (any) ${a("Indicates which column in database contains the values to be extracted and operated on.")}\n criteria (range) ${a("An array or range containing zero or more criteria to filter the database values by before operating.")}\n`),eo={description:a("Average of a set of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return ui.compute([i])},isExported:!0},to={description:a("Counts values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Si.compute([i])},isExported:!0},so={description:a("Counts values and text from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return bi.compute([i])},isExported:!0},io={description:a("Single value from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return le((()=>1===i.length),a("More than one match found in DGET evaluation.")),i[0]},isExported:!0},oo={description:a("Maximum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Ti.compute([i])},isExported:!0},no={description:a("Minimum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Ai.compute([i])},isExported:!0},ro={description:a("Product of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return At.compute([i])},isExported:!0},ao={description:a("Standard deviation of population sample from table."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Pi.compute([i])},isExported:!0},lo={description:a("Standard deviation of entire population from table."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return zi.compute([i])},isExported:!0},co={description:a("Sum of values from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Bt.compute([i])},isExported:!0},ho={description:a("Variance of population sample from table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Gi.compute([i])},isExported:!0},uo={description:a("Variance of a population from a table-like range."),args:Ji,returns:["NUMBER"],compute:function(e,t,s){const i=Qi(e,t,s);return Yi.compute([i])},isExported:!0};var po=Object.freeze({__proto__:null,DAVERAGE:eo,DCOUNT:to,DCOUNTA:so,DGET:io,DMAX:oo,DMIN:no,DPRODUCT:ro,DSTDEV:ao,DSTDEVP:lo,DSUM:co,DVAR:ho,DVARP:uo});const go=new D(1899,11,30);function fo(e){const t=Math.trunc(e);return t%4==0&&t%100!=0||t%400==0}const mo={description:a("Converts year/month/day into a date."),args:_e(`\n year (number) ${a("The year component of the date.")}\n month (number) ${a("The month component of the date.")}\n day (number) ${a("The day component of the date.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s){let i=Math.trunc(he(e));const o=Math.trunc(he(t)),n=Math.trunc(he(s));le((()=>0<=i&&i<=9999),a("The year (%s) must be between 0 and 9999 inclusive.",i.toString())),i<1900&&(i+=1900);const r=new D(i,o-1,n).getTime()-go.getTime();return le((()=>r>=0),a("The function [[FUNCTION_NAME]] result must be greater than or equal 01/01/1900.")),Math.round(r/864e5)},isExported:!0},vo={description:a("Converts a date string to a date value."),args:_e(`\n date_string (string) ${a("The string representing the date.")}\n `),returns:["NUMBER"],compute:function(e){const t=ue(e),s=G(t);return le((()=>null!==s),a("The date_string (%s) cannot be parsed to date/time.",t.toString())),Math.trunc(s.value)},isExported:!0},Eo={description:a("Day of the month that a specific date falls on."),args:_e(`\n date (string) ${a("The date from which to extract the day.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getDate()},isExported:!0},So={description:a("Number of days between two dates."),args:_e(`\n end_date (date) ${a("The end of the date range.")}\n start_date (date) ${a("The start of the date range.")}\n `),returns:["NUMBER"],compute:function(e,t){const s=fe(e),i=fe(t),o=s.getTime()-i.getTime();return Math.round(o/864e5)},isExported:!0},bo={description:a("Date a number of months before/after another date."),args:_e(`\n start_date (date) ${a("The date from which to calculate the result.")}\n months (number) ${a("The number of months before (negative) or after (positive) 'start_date' to calculate.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t){const s=fe(e),i=Math.trunc(he(t)),o=s.getFullYear(),n=s.getMonth(),r=s.getDate(),a=new D(o,n+i,r).getTime()-go.getTime();return Math.round(a/864e5)},isExported:!0},Co={description:a("Last day of a month before or after a date."),args:_e(`\n start_date (date) ${a("The date from which to calculate the result.")}\n months (number) ${a("The number of months before (negative) or after (positive) 'start_date' to consider.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t){const s=fe(e),i=Math.trunc(he(t)),o=s.getFullYear(),n=s.getMonth(),r=new D(o,n+i+1,0).getTime()-go.getTime();return Math.round(r/864e5)},isExported:!0},Io={description:a("Hour component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the hour component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getHours()},isExported:!0},yo={description:a("ISO week number of the year."),args:_e(`\n date (date) ${a("The date for which to determine the ISO week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n `),returns:["NUMBER"],compute:function(e){const t=fe(e),s=t.getFullYear();let i=1;for(;4!==new D(s,0,i).getDay();)i+=1;const o=new D(s,0,i-3);let n=31;for(;4!==new D(s,11,n).getDay();)n-=1;const r=new D(s,11,n+3);let a,l;switch(a=o.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=o;break;case 1:l=new D(s,11,n+3+1);break;case-1:let e=1;for(;4!==new D(s-1,0,e).getDay();)e+=1;l=new D(s-1,0,e-3)}const c=(t.getTime()-l.getTime())/864e5;return Math.floor(c/7)+1},isExported:!0},wo={description:a("Minute component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the minute component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getMinutes()},isExported:!0},To={description:a("Month of the year a specific date falls in"),args:_e(`\n date (date) ${a("The date from which to extract the month.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getMonth()+1},isExported:!0},xo={description:a("Net working days between two provided days."),args:_e(`\n start_date (date) ${a("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${a("The end date of the period from which to calculate the number of net working days.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the date serial numbers to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,s){return Lo.compute(e,t,1,s)},isExported:!0};function Ro(e){if("string"==typeof e){le((()=>{if(7!==e.length)return!1;for(let t of e)if("0"!==t&&"1"!==t)return!1;return!0}),a('When weekend is a string (%s) it must be composed of "0" or "1".',e));let t=[];for(let s=0;s<7;s++)"1"===e[s]&&t.push((s+1)%7);return t}if("number"==typeof e)return le((()=>1<=e&&e<=7||11<=e&&e<=17),a("The weekend (%s) must be a string or a number in the range 1-7 or 11-17.",e.toString())),e<=7?[e-2==-1?6:e-2,e-1]:[e-11];throw Error(a("The weekend (%s) must be a number or a string.",e.toString()))}const Lo={description:a("Net working days between two dates (specifying weekends)."),args:_e(`\n start_date (date) ${a("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${a("The end date of the period from which to calculate the number of net working days.")}\n weekend (any, default=1) ${a("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider as holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1,i){const o=fe(e),n=fe(t),r=Ro(s);let a=new Set;void 0!==i&&ve([i],(e=>{const t=fe(e);a.add(t.getTime())}));const l=o.getTime()>n.getTime(),c=D.fromTimestamp((l?o:n).getTime());let h=D.fromTimestamp((l?n:o).getTime());const d=c.getTime();let u=h.getTime(),p=0;for(;u<=d;)r.includes(h.getDay())||a.has(u)||(p+=1),h.setDate(h.getDate()+1),u=h.getTime();return l?-p:p},isExported:!0},Ao={description:a("Current date and time as a date value."),args:[],returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy hh:mm:ss"},compute:function(){let e=D.now();const t=e.getTime()-go.getTime(),s=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return Math.floor(t/864e5)+s},isExported:!0},Mo={description:a("Minute component of a specific time."),args:_e(`\n time (date) ${a("The time from which to calculate the second component.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getSeconds()},isExported:!0},_o={description:a("Converts hour/minute/second into a time."),args:_e(`\n hour (number) ${a("The hour component of the time.")}\n minute (number) ${a("The minute component of the time.")}\n second (number) ${a("The second component of the time.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"hh:mm:ss a"},compute:function(e,t,s){let i=Math.trunc(he(e)),o=Math.trunc(he(t)),n=Math.trunc(he(s));return o+=Math.floor(n/60),n=n%60+(n<0?60:0),i+=Math.floor(o/60),o=o%60+(o<0?60:0),i%=24,le((()=>i>=0),a("The function [[FUNCTION_NAME]] result cannot be negative")),i/24+o/1440+n/86400},isExported:!0},Oo={description:a("Converts a time string into its serial number representation."),args:_e(`\n time_string (string) ${a("The string that holds the time representation.")}\n `),returns:["NUMBER"],compute:function(e){const t=ue(e),s=G(t);le((()=>null!==s),a("The time_string (%s) cannot be parsed to date/time.",t));const i=s.value-Math.trunc(s.value);return i<0?1+i:i},isExported:!0},No={description:a("Current date as a date value."),args:[],returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(){const e=D.now(),t=new D(e.getFullYear(),e.getMonth(),e.getDate()).getTime()-go.getTime();return Math.round(t/864e5)},isExported:!0},ko={description:a("Day of the week of the date provided (as number)."),args:_e(`\n date (date) ${a("The date for which to determine the day of the week. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n type (number, default=1) ${a("A number indicating which numbering system to use to represent weekdays. By default, counts starting with Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const s=fe(e),i=Math.round(he(t)),o=s.getDay();return le((()=>[1,2,3].includes(i)),a("The type (%s) must be 1, 2 or 3.",i.toString())),1===i?o+1:2===i?0===o?7:o:0===o?6:o-1},isExported:!0},Fo={description:a("Week number of the year."),args:_e(`\n date (date) ${a("The date for which to determine the week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n type (number, default=1) ${a("A number representing the day that a week starts on. Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const s=fe(e),i=Math.round(he(t));if(le((()=>1===i||2===i||11<=i&&i<=17||21===i),a("The type (%s) is out of range.",i.toString())),21===i)return yo.compute(e);let o;o=1===i||2===i?i-1:i-10==7?0:i-10;const n=s.getFullYear();let r=1,l=new D(n,0,r);for(;l.getDay()!==o;)r+=1,l=new D(n,0,r);const c=(s.getTime()-l.getTime())/864e5;return c<0?1:Math.floor(c/7)+(1===r?1:2)},isExported:!0},$o={description:a("Number of working days from start date."),args:_e(`\n start_date (date) ${a("The date from which to begin counting.")}\n num_days (number) ${a("The number of working days to advance from start_date. If negative, counts backwards.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider holidays.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s){return Do.compute(e,t,1,s)},isExported:!0},Do={description:a("Net working days between two dates (specifying weekends)."),args:_e(`\n start_date (date) ${a("The date from which to begin counting.")}\n num_days (number) ${a("The number of working days to advance from start_date. If negative, counts backwards.")}\n weekend (any, default=1) ${a("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${a("A range or array constant containing the dates to consider holidays.")}\n `),returns:["DATE"],returnFormat:{specificFormat:"m/d/yyyy"},compute:function(e,t,s=1,i){let o=fe(e),n=Math.trunc(he(t));"string"==typeof s&&le((()=>"1111111"!==s),a("The weekend (%s) must be different from '1111111'.",s));const r=Ro(s);let l=new Set;void 0!==i&&ve([i],(e=>{const t=fe(e);l.add(t.getTime())}));let c=D.fromTimestamp(o.getTime()),h=c.getTime();const d=Math.sign(n);let u=Math.abs(n);for(;u>0;)c.setDate(c.getDate()+d),h=c.getTime(),r.includes(c.getDay())||l.has(h)||(u-=1);const p=h-go.getTime();return Math.round(p/864e5)},isExported:!0},Uo={description:a("Year specified by a given date."),args:_e(`\n date (date) ${a("The date from which to extract the year.")}\n `),returns:["NUMBER"],compute:function(e){return fe(e).getFullYear()},isExported:!0},Po={description:a("Exact number of years between two dates."),args:_e(`\n start_date (date) ${a("The start date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n end_date (date) ${a("The end date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")}\n day_count_convention (number, default=0) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s=0){let i=Math.trunc(he(e)),o=Math.trunc(he(t));const n=Math.trunc(he(s));if(le((()=>i>=0),a("The start_date (%s) must be positive or null.",i.toString())),le((()=>o>=0),a("The end_date (%s) must be positive or null.",o.toString())),le((()=>0<=n&&n<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",n.toString())),i===o)return 0;if(i>o){const e=o;o=i,i=e}const r=fe(i),l=fe(o);let c=r.getDate(),h=l.getDate();const d=r.getMonth(),u=l.getMonth(),p=r.getFullYear(),g=l.getFullYear();let f=0,m=0;switch(n){case 0:31===c&&(c=30),30===c&&31===h&&(h=30),1===d&&c===(fo(p)?29:28)&&(c=30,1===u&&h===(fo(g)?29:28)&&(h=30)),f=p+(30*d+c)/360,m=g+(30*u+h)/360;break;case 1:let e=365;const t=p===g;if(!t&&!(p+1===g)||!t&&d<u||!t&&d===u&&c<h){let t=0,s=0;for(let e=p;e<=g;e++)t++,s+=fo(e)?366:365;e=s/t}else t?fo(p)&&(e=366):(fo(p)&&d<2&&(e=366),fo(g)&&(u>1||1===u&&29===h)&&(e=366));f=i/e,m=o/e;break;case 2:f=i/360,m=o/360;break;case 3:f=i/365,m=o/365;break;case 4:31===c&&(c=30),31===h&&(h=30),f=p+(30*d+c)/360,m=g+(30*u+h)/360}return m-f}};var Bo=Object.freeze({__proto__:null,DATE:mo,DATEVALUE:vo,DAY:Eo,DAYS:So,EDATE:bo,EOMONTH:Co,HOUR:Io,ISOWEEKNUM:yo,MINUTE:wo,MONTH:To,NETWORKDAYS:xo,NETWORKDAYS_INTL:Lo,NOW:Ao,SECOND:Mo,TIME:_o,TIMEVALUE:Oo,TODAY:No,WEEKDAY:ko,WEEKNUM:Fo,WORKDAY:$o,WORKDAY_INTL:Do,YEAR:Uo,YEARFRAC:Po});function Vo(e,t,s,i,o=1e-10){let n,r,l,c=s,h=!1,d=0;do{l=e(c),n=c-l/t(c),r=Math.abs(n-c),c=n,h=r<o||Math.abs(l)<o,le((()=>d<i),a("Function [[FUNCTION_NAME]] didn't find any result")),d++}while(!h);return c}const Ho={description:a("Depreciation via declining balance method."),args:_e(`\n cost (number) ${a("The initial cost of the asset.")}\n salvage (number) ${a("The value of the asset at the end of depreciation.")}\n life (number) ${a("The number of periods over which the asset is depreciated.")}\n period (number) ${a("The single period within life for which to calculate depreciation.")}\n month (number, optional) ${a("The number of months in the first year of depreciation.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i,...o){const n=he(e),r=he(t),l=he(s),c=Math.trunc(he(i)),h=o.length?Math.trunc(he(o[0])):12,d=l+(12===h?0:1);le((()=>n>0),a("The cost (%s) must be strictly positive.",n.toString())),le((()=>r>=0),a("The salvage (%s) must be positive or null.",r.toString())),le((()=>l>0),a("The life (%s) must be strictly positive.",l.toString())),le((()=>c>0),a("The period (%s) must be strictly positive.",c.toString())),le((()=>1<=h&&h<=12),a("The month (%s) must be between 1 and 12 inclusive.",h.toString())),le((()=>c<=d),a("The period (%s) must be less than or equal to %s.",c.toString(),d.toString()));const u=h/12;let p=1-Math.pow(r/n,1/l);p=Math.round(1e3*p)/1e3;let g=n,f=n*(1-p*u);for(let e=1;e<c;e++)g=f,f=g*(1-p),e===l&&(f=g*(1-p*(1-u)));return g-f}},zo={description:a("Number of periods for an investment to reach a value."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){n=n||0;const r=Math.trunc(he(e)),l=Math.trunc(he(t)),c=he(s),h=he(i),d=Math.trunc(he(o)),u=Math.trunc(he(n));le((()=>r<l),a("The maturity (%s) must be strictly greater than the settlement (%s).",l.toString(),r.toString())),le((()=>c>=0),a("The rate (%s) must be positive or null.",c.toString())),le((()=>h>=0),a("The yield (%s) must be positive or null.",h.toString())),le((()=>[1,2,4].includes(d)),a("The frequency (%s) must be one of %s",d.toString(),[1,2,4].toString())),le((()=>0<=u&&u<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",u.toString()));const p=Po.compute(r,l,u),g=p-Math.trunc(p)||1/d,f=Math.ceil(p*d),m=c/d,v=h/d;let E=0,S=0;for(let e=1;e<=f;e++){const t=(m+(e===f?1:0))/(1+v)**e;S+=(g+(e-1)/d)*t,E+=t}return 0===E?0:S/E}},Zo={description:a("Future value of an annuity investment."),args:_e(`\n rate (number) ${a("The interest rate.")}\n number_of_periods (number) ${a("The number of payments to be made.")}\n payment_amount (number) ${a("The amount per period to be paid.")}\n present_value (number, default=0) ${a("The current value of the annuity.")}\n end_or_beginning (number, default=0) ${a("Whether payments are due at the end (0) or beginning (1) of each period.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i=0,o=0){i=i||0,o=o||0;const n=he(e),r=he(t),a=he(s),l=he(i),c=ge(o)?1:0;return n?-l*(1+n)**r-a*(1+n*c)*((1+n)**r-1)/n:-(l+a*r)}},Go={description:a("Internal rate of return given periodic cashflows."),args:_e(`\n cashflow_amounts (number, range<number>) ${a("An array or range containing the income or payments associated with the investment.")}\n rate_guess (number, default=0.1) ${a("An estimate for what the internal rate of return will be.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"0%"},compute:function(e,t=.1){const s=he(t);le((()=>s>-1),a("The rate_guess (%s) must be strictly greater than -1.",s.toString()));let i=!1,o=!1,n=[];Ee([e],(e=>{e>0&&(i=!0),e<0&&(o=!0),n.push(e)})),le((()=>i&&o),a("The cashflow_amounts must include negative and positive values."));const r=n.shift();return Vo((function(e){return function(e,t,s){const i=s.length;let o=0;return s.reduce(((t,s)=>(o++,t+s*e**(i-o))),t*e**i)}(e,r,n)}),(function(e){return function(e,t,s){const i=s.length;let o=0;return s.reduce(((t,s)=>(o++,t+s*(i-o)*e**(i-o-1))),t*i*e**(i-1))}(e,r,n)}),s+1,20,1e-5)-1}},Wo={description:a("Modified Macaulay duration."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){return zo.compute(e,t,s,i,o,n)/(1+he(i)/Math.trunc(he(o)))}};const qo={description:a("The net present value of an investment based on a series of periodic cash flows and a discount rate."),args:_e(`\n discount (number) ${a("The discount rate of the investment over one period.")}\n cashflow1 (number, range<number>) ${a("The first future cash flow.")}\n cashflow2 (number, range<number>, repeating) ${a("Additional future cash flows.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,...t){const s=he(e);return le((()=>-1!==s),a("The discount (%s) must be different from -1.",s.toString())),function(e,t,s){let i=0;return Ce(s,((t,s)=>(i++,t+s/(1+e)**i)),t)}(s,0,t)}},jo={description:a("Computes the number of periods needed for an investment to reach a value."),args:_e(`\n rate (number) ${a("The rate at which the investment grows each period.")}\n present_value (number) ${a("The investment's current value.")}\n future_value (number) ${a("The investment's desired future value.")}\n `),returns:["NUMBER"],compute:function(e,t,s){const i=he(e),o=he(t),n=he(s);return le((()=>i>0),a("The rate (%s) must be strictly positive.",i.toString())),le((()=>o>0),a("The present_value (%s) must be strictly positive.",o.toString())),le((()=>n>0),a("The future_value (%s) must be strictly positive.",n.toString())),(Math.log(n)-Math.log(o))/Math.log(1+i)}},Yo={description:a("Present value of an annuity investment."),args:_e(`\n rate (number) ${a("The interest rate.")}\n number_of_periods (number) ${a("The number of payments to be made.")}\n payment_amount (number) ${a("The amount per period to be paid.")}\n future_value (number, default=0) ${a("The future value remaining after the final payment has been made.")}\n end_or_beginning (number, default=0) ${a("Whether payments are due at the end (0) or beginning (1) of each period.")}\n `),returns:["NUMBER"],returnFormat:{specificFormat:"#,##0.00"},compute:function(e,t,s,i=0,o=0){i=i||0,o=o||0;const n=he(e),r=he(t),a=he(s),l=he(i),c=ge(o)?1:0;return n?-(a*(1+n*c)*((1+n)**r-1)/n+l)/(1+n)**r:-(l+a*r)}},Xo={description:a("Price of a security paying periodic interest."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n yield (number) ${a("The expected annual yield of the security.")}\n redemption (number) ${a("The redemption amount per 100 face value, or par.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n,r=0){r=r||0;const l=Math.trunc(he(e)),c=Math.trunc(he(t)),h=he(s),d=he(i),u=he(o),p=Math.trunc(he(n)),g=Math.trunc(he(r));le((()=>c>l),a("The maturity (%s) must be strictly greater than the settlement (%s).",c.toString(),l.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>=0),a("The yield (%s) must be positive or null.",d.toString())),le((()=>u>0),a("The redemption (%s) must be strictly positive.",u.toString())),le((()=>[1,2,4].includes(p)),a("The frequency (%s) must be one of %s.",p.toString(),[1,2,4].toString())),le((()=>0<=g&&g<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",g.toString()));const f=Po.compute(l,c,g)*p,m=Math.ceil(f),v=f-Math.floor(f)||1,E=1+d/p,S=100*h/p;if(1===m)return(S+u)/(v*d/p+1)-S*(1-v);let b=0;for(let e=1;e<=m;e++)b+=S/E**(e-1+v);return u/E**(m-1+v)+b-S*(1-v)}},Ko={description:a("Annual yield of a security paying periodic interest."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n rate (number) ${a("The annualized rate of interest.")}\n price (number) ${a("The price at which the security is bought per 100 face value.")}\n redemption (number) ${a("The redemption amount per 100 face value, or par.")}\n frequency (number) ${a("The number of interest or coupon payments per year (1, 2, or 4).")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n,r=0){r=r||0;const l=Math.trunc(he(e)),c=Math.trunc(he(t)),h=he(s),d=he(i),u=he(o),p=Math.trunc(he(n)),g=Math.trunc(he(r));le((()=>c>l),a("The maturity (%s) must be strictly greater than the settlement (%s).",c.toString(),l.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>0),a("The price (%s) must be strictly positive.",d.toString())),le((()=>u>0),a("The redemption (%s) must be strictly positive.",u.toString())),le((()=>[1,2,4].includes(p)),a("The frequency (%s) must be one of %s.",p.toString(),[1,2,4].toString())),le((()=>0<=g&&g<=4),a("The day_count_convention (%s) must between 0 and 4 inclusive.",g.toString()));const f=Po.compute(l,c,g)*p,m=Math.ceil(f),v=f-Math.floor(f)||1,E=100*h/p;if(1===m){const e=d+E*(1-v);return(u+E-e)*p*(1/v)/e}const S=Vo((function(e){return function(e,t,s,i,o,n){let r=n-(e+o*(1-t))*i**(s-1+t);for(let e=1;e<=s;e++)r+=o*i**(e-1);return r}(d,v,m,e,E,u)}),(function(e){return function(e,t,s,i,o){let n=-(e+o*(1-t))*(s-1+t)*i**(s-2+t);for(let e=1;e<=s;e++)n+=o*(e-1)*i**(e-2);return n}(d,v,m,e,E)}),1+(h+1)/p,100,1e-5);return(S-1)*p}},Qo={description:a("Annual yield of a security paying interest at maturity."),args:_e(`\n settlement (date) ${a("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")}\n maturity (date) ${a("The maturity or end date of the security, when it can be redeemed at face, or par value.")}\n issue (date) ${a("The date the security was initially issued.")}\n rate (number) ${a("The annualized rate of interest.")}\n price (number) ${a("The price at which the security is bought.")}\n day_count_convention (number, default=0 ) ${a("An indicator of what day count method to use.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i,o,n=0){n=n||0;const r=Math.trunc(he(e)),l=Math.trunc(he(t)),c=Math.trunc(he(s)),h=he(i),d=he(o),u=Math.trunc(he(n));le((()=>r>=c),a("The settlement (%s) must be greater than or equal to the issue (%s).",r.toString(),c.toString())),le((()=>l>r),a("The maturity (%s) must be strictly greater than the settlement (%s).",l.toString(),r.toString())),le((()=>h>=0),a("The rate (%s) must be positive or null.",h.toString())),le((()=>d>0),a("The price (%s) must be strictly positive.",d.toString())),le((()=>0<=u&&u<=4),a("The day_count_convention (%s) must be between 0 and 4 inclusive.",u.toString()));const p=Po.compute(c,l,u),g=Po.compute(c,r,u),f=Po.compute(r,l,u);return(100*(1+h*p)/(d+100*h*g)-1)/f}};var Jo=Object.freeze({__proto__:null,DB:Ho,DURATION:zo,FV:Zo,IRR:Go,MDURATION:Wo,NPV:qo,PDURATION:jo,PV:Yo,PRICE:Xo,YIELD:Ko,YIELDMAT:Qo});const en={description:a("Whether a value is an error."),args:_e(`value (any, lazy) ${a("The value to be verified as an error type.")}`),returns:["BOOLEAN"],compute:function(e){try{return e(),!1}catch(e){return!0}},isExported:!0},tn={description:a("Whether a value is `true` or `false`."),args:_e(`value (any) ${a("The value to be verified as a logical TRUE or FALSE.")}`),returns:["BOOLEAN"],compute:function(e){return"boolean"==typeof e},isExported:!0},sn={description:a("Whether a value is non-textual."),args:_e(`value (any) ${a("The value to be checked.")}`),returns:["BOOLEAN"],compute:function(e){return"string"!=typeof e},isExported:!0},on={description:a("Whether a value is a number."),args:_e(`value (any) ${a("The value to be verified as a number.")}`),returns:["BOOLEAN"],compute:function(e){return"number"==typeof e},isExported:!0},nn={description:a("Whether a value is text."),args:_e(`value (any) ${a("The value to be verified as text.")}`),returns:["BOOLEAN"],compute:function(e){return"string"==typeof e},isExported:!0};var rn=Object.freeze({__proto__:null,ISERROR:en,ISLOGICAL:tn,ISNONTEXT:sn,ISNUMBER:on,ISTEXT:nn});const an={description:a("Logical `and` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that represent logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!0;return ye(e,(e=>(t=!0,s=s&&e,s))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0},ln={description:a("Returns value depending on logical expression."),args:_e(`\n logical_expression (boolean) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE.")}\n value_if_true (any, lazy) ${a("The value the function returns if logical_expression is TRUE.")}\n value_if_false (any, lazy, default=FALSE) ${a("The value the function returns if logical_expression is FALSE.")}\n `),returns:["ANY"],compute:function(e,t,s=(()=>!1)){const i=ge(e)?t():s();return null==i?"":i},isExported:!0},cn={description:a("Value if it is not an error, otherwise 2nd argument."),args:_e(`\n value (any, lazy) ${a("The value to return if value itself is not an error.")}\n value_if_error (any, lazy, default=${a("An empty value")}) ${a("The value the function returns if value is an error.")}\n `),returns:["ANY"],compute:function(e,t=(()=>"")){let s;try{s=e()}catch(e){s=t()}return null==s?"":s},isExported:!0},hn={description:a("Returns a value depending on multiple logical expressions."),args:_e(`\n condition1 (boolean, lazy) ${a("The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those.")}\n value1 (any, lazy) ${a("The returned value if condition1 is TRUE.")}\n condition2 (boolean, lazy, repeating) ${a("Additional conditions to be evaluated if the previous ones are FALSE.")}\n value2 (any, lazy, repeating) ${a("Additional values to be returned if their corresponding conditions are TRUE.")}\n `),returns:["ANY"],compute:function(...e){le((()=>e.length%2==0),a("Wrong number of arguments. Expected an even number of arguments."));for(let t=0;t<e.length-1;t+=2)if(ge(e[t]()))return e[t+1]();throw new Error(a("No match."))},isExported:!0},dn={description:a("Returns opposite of provided logical value."),args:_e(`logical_expression (boolean) ${a("An expression or reference to a cell holding an expression that represents some logical value.")}\n `),returns:["BOOLEAN"],compute:function(e){return!ge(e)},isExported:!0},un={description:a("Logical `or` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!1;return ye(e,(e=>(t=!0,s=s||e,!s))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0},pn={description:a("Logical `xor` operator."),args:_e(`\n logical_expression1 (boolean, range<boolean>) ${a("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")}\n logical_expression2 (boolean, range<boolean>, repeating) ${a("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(...e){let t=!1,s=!1;return ye(e,(e=>(t=!0,s=s?!e:e,!0))),le((()=>t),a("[[FUNCTION_NAME]] has no valid input data.")),s},isExported:!0};var gn=Object.freeze({__proto__:null,AND:an,IF:ln,IFERROR:cn,IFS:hn,NOT:dn,OR:un,XOR:pn});function fn(e,t){for(let s=0;s<e.length;s++)if(e[s]===t)return s;return-1}const mn={description:a("Column number of a specified cell."),args:_e(`cell_reference (meta, default=${a("The cell in which the formula is entered")}) ${a("The cell whose column number will be returned. Column A corresponds to 1.")}\n `),returns:["NUMBER"],compute:function(e){var t;e=e||(null===(t=this.__originCellXC)||void 0===t?void 0:t.call(this)),le((()=>!!e),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter.");return ks(e).left+1},isExported:!0},vn={description:a("Number of columns in a specified array or range."),args:_e(`range (meta) ${a("The range whose column count will be returned.")}`),returns:["NUMBER"],compute:function(e){const t=ks(e);return t.right-t.left+1},isExported:!0},En={description:a("Horizontal lookup"),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (range) ${a("The range to consider for the search. The first row in the range is searched for the key specified in search_key.")}\n index (number) ${a("The row index of the value to be returned, where the first row in range is numbered 1.")}\n is_sorted (boolean, default=true) ${a("Indicates whether the row to be searched (the first row of the specified range) is sorted, in which case the closest match for search_key will be returned.")}\n `),returns:["ANY"],compute:function(e,t,s,i=true){const o=Math.trunc(he(s));le((()=>1<=o&&o<=t[0].length),a("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const n=ge(i),r=t.map((e=>e[0]));let l;return l=n?Re(r,e):fn(r,e),le((()=>l>-1),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),t[l][o-1]},isExported:!0},Sn={description:a("Look up a value."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n search_array (range) ${a("One method of using this function is to provide a single sorted row or column search_array to look through for the search_key with a second argument result_range. The other way is to combine these two arguments into one search_array where the first row or column is searched and a value is returned from the last row or column in the array. If search_key is not found, a non-exact match may be returned.")}\n result_range (range, optional) ${a("The range from which to return a result. The value returned corresponds to the location where search_key is found in search_range. This range must be only a single row or column and should not be used if using the search_result_array method.")}\n `),returns:["ANY"],compute:function(e,t,s){let i=t.length,o=t[0].length;const n=o>=i,r=Re(n?t[0]:t.map((e=>e[0])),e);return le((()=>r>=0),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),void 0===s?n?t[i-1][r]:t[r][o-1]:(i=s.length,o=s[0].length,le((()=>1===i||1===o),a("The result_range must be a single row or a single column.")),i>1?(le((()=>r<=i-1),a("[[FUNCTION_NAME]] evaluates to an out of range row value %s.",(r+1).toString())),s[r][0]):(le((()=>r<=o-1),a("[[FUNCTION_NAME]] evaluates to an out of range column value %s.",(r+1).toString())),s[0][r]))},isExported:!0},bn={description:a("Position of item in range that matches value."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${a("The one-dimensional array to be searched.")}\n search_type (number, default=1) ${a("The search method. 1 (default) finds the largest value less than or equal to search_key when range is sorted in ascending order. 0 finds the exact value when range is unsorted. -1 finds the smallest value greater than or equal to search_key when range is sorted in descending order.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){let i=he(s);const o=t.length,n=t[0].length;le((()=>1===o||1===n),a("The range must be a single row or a single column."));let r=-1;const l=t.flat();switch(i=Math.sign(i),i){case 1:r=Re(l,e);break;case 0:r=fn(l,e);break;case-1:r=function(e,t){const s=typeof t;let i,o,n,r,a,l,c=0,h=e.length-1;if(typeof e[c]===s&&t>e[c])return-1;if(typeof e[h]===s&&e[h]>t)return h;for(;h-c>=0;){for(n=Math.ceil((c+h)/2),r=n,a=e[r],l=typeof a;c<=r&&s!==l;)r--,a=e[r],l=typeof a;l===s&&a>=t&&(void 0===i||i>a||i===a&&o>r)&&(i=a,o=r),l===s&&a<=t?h=r-1:c=n+1}return void 0!==o?o:-1}(l,e)}return le((()=>r>=0),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),r+1},isExported:!0},Cn={description:a("Row number of a specified cell."),args:_e(`cell_reference (meta, default=${a("The cell in which the formula is entered by default")}) ${a("The cell whose row number will be returned.")}`),returns:["NUMBER"],compute:function(e){var t;e=e||(null===(t=this.__originCellXC)||void 0===t?void 0:t.call(this)),le((()=>!!e),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter.");return ks(e).top+1},isExported:!0},In={description:a("Number of rows in a specified array or range."),args:_e(`range (meta) ${a("The range whose row count will be returned.")}`),returns:["NUMBER"],compute:function(e){const t=ks(e);return t.bottom-t.top+1},isExported:!0},yn={description:a("Vertical lookup."),args:_e(`\n search_key (any) ${a("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${a("The range to consider for the search. The first column in the range is searched for the key specified in search_key.")}\n index (number) ${a("The column index of the value to be returned, where the first column in range is numbered 1.")}\n is_sorted (boolean, default=true) ${a("Indicates whether the column to be searched (the first column of the specified range) is sorted, in which case the closest match for search_key will be returned.")}\n `),returns:["ANY"],compute:function(e,t,s,i=true){const o=Math.trunc(he(s));le((()=>1<=o&&o<=t.length),a("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const n=ge(i),r=t[0];let l;return l=n?Re(r,e):fn(r,e),le((()=>l>-1),a("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",ue(e))),t[o-1][l]},isExported:!0};var wn=Object.freeze({__proto__:null,COLUMN:mn,COLUMNS:vn,HLOOKUP:En,LOOKUP:Sn,MATCH:bn,ROW:Cn,ROWS:In,VLOOKUP:yn});const Tn={description:a("Sum of two numbers."),args:_e(`\n value1 (number) ${a("The first addend.")}\n value2 (number) ${a("The second addend.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)+he(t)}},xn={description:a("Concatenation of two values."),args:_e(`\n value1 (string) ${a("The value to which value2 will be appended.")}\n value2 (string) ${a("The value to append to value1.")}\n `),returns:["STRING"],compute:function(e,t){return ue(e)+ue(t)},isExported:!0},Rn={description:a("One number divided by another."),args:_e(`\n dividend (number) ${a("The number to be divided.")}\n divisor (number) ${a("The number to divide by.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){const s=he(t);return le((()=>0!==s),a("The divisor must be different from zero.")),he(e)/s}};function Ln(e){return null==e}const An={number:0,string:"",boolean:!1},Mn={description:a("Equal."),args:_e(`\n value1 (any) ${a("The first value.")}\n value2 (any) ${a("The value to test against value1 for equality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return e=Ln(e)?An[typeof t]:e,t=Ln(t)?An[typeof e]:t,"string"==typeof e&&(e=e.toUpperCase()),"string"==typeof t&&(t=t.toUpperCase()),e===t}};function _n(e,t,s){e=Ln(e)?An[typeof t]:e,t=Ln(t)?An[typeof e]:t,"number"!=typeof e&&(e=ue(e).toUpperCase()),"number"!=typeof t&&(t=ue(t).toUpperCase());const i=typeof e,o=typeof t;return"string"===i&&"number"===o||("string"!==o||"number"!==i)&&s(e,t)}const On={description:a("Strictly greater than."),args:_e(`\n value1 (any) ${a("The value to test as being greater than value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return _n(e,t,((e,t)=>e>t))}},Nn={description:a("Greater than or equal to."),args:_e(`\n value1 (any) ${a("The value to test as being greater than or equal to value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return _n(e,t,((e,t)=>e>=t))}},kn={description:a("Less than."),args:_e(`\n value1 (any) ${a("The value to test as being less than value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Nn.compute(e,t)}},Fn={description:a("Less than or equal to."),args:_e(`\n value1 (any) ${a("The value to test as being less than or equal to value2.")}\n value2 (any) ${a("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!On.compute(e,t)}},$n={description:a("Difference of two numbers."),args:_e(`\n value1 (number) ${a("The minuend, or number to be subtracted from.")}\n value2 (number) ${a("The subtrahend, or number to subtract from value1.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)-he(t)}},Dn={description:a("Product of two numbers"),args:_e(`\n factor1 (number) ${a("The first multiplicand.")}\n factor2 (number) ${a("The second multiplicand.")}\n `),returns:["NUMBER"],returnFormat:Ve.FormatFromArgument,compute:function(e,t){return he(e)*he(t)}},Un={description:a("Not equal."),args:_e(`\n value1 (any) ${a("The first value.")}\n value2 (any) ${a("The value to test against value1 for inequality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Mn.compute(e,t)}},Pn={description:a("A number raised to a power."),args:_e(`\n base (number) ${a("The number to raise to the exponent power.")}\n exponent (number) ${a("The exponent to raise base to.")}\n `),returns:["NUMBER"],compute:function(e,t){return Lt.compute(e,t)}},Bn={description:a("A number with the sign reversed."),args:_e(`\n value (number) ${a("The number to have its sign reversed. Equivalently, the number to multiply by -1.")}\n `),returnFormat:Ve.FormatFromArgument,returns:["NUMBER"],compute:function(e){return-he(e)}},Vn={description:a("Value interpreted as a percentage."),args:_e(`\n percentage (number) ${a("The value to interpret as a percentage.")}\n `),returns:["NUMBER"],compute:function(e){return he(e)/100}},Hn={description:a("A specified number, unchanged."),args:_e(`\n value (any) ${a("The number to return.")}\n `),returnFormat:Ve.FormatFromArgument,returns:["ANY"],compute:function(e){return e}};var zn=Object.freeze({__proto__:null,ADD:Tn,CONCAT:xn,DIVIDE:Rn,EQ:Mn,GT:On,GTE:Nn,LT:kn,LTE:Fn,MINUS:$n,MULTIPLY:Dn,NE:Un,POW:Pn,UMINUS:Bn,UNARY_PERCENT:Vn,UPLUS:Hn});const Zn={description:a("Gets character associated with number."),args:_e(`\n table_number (number) ${a("The number of the character to look up from the current Unicode table in decimal format.")}\n `),returns:["STRING"],compute:function(e){const t=Math.trunc(he(e));return le((()=>t>=1),a("The table_number (%s) is out of range.",t.toString())),String.fromCharCode(t)},isExported:!0},Gn={description:a("Appends strings to one another."),args:_e(`\n string1 (string, range<string>) ${a("The initial string.")}\n string2 (string, range<string>, repeating) ${a("More strings to append in sequence.")}\n `),returns:["STRING"],compute:function(...e){return be(e,((e,t)=>e+ue(t)),"")},isExported:!0},Wn={description:a("Tests whether two strings are identical."),args:_e(`\n string1 (string) ${a("The first string to compare.")}\n string2 (string) ${a("The second string to compare.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return ue(e)===ue(t)},isExported:!0},qn={description:a("First position of string found in text, case-sensitive."),args:_e(`\n search_for (string) ${a("The string to look for within text_to_search.")}\n text_to_search (string) ${a("The text to search for the first occurrence of search_for.")}\n starting_at (number, default=1) ${a("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){const i=ue(e),o=ue(t),n=he(s);le((()=>""!==o),a("The text_to_search must be non-empty.")),le((()=>n>=1),a("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=o.indexOf(i,n-1);return le((()=>r>=0),a("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",i.toString(),o)),r+1},isExported:!0},jn={description:a("Concatenates elements of arrays with delimiter."),args:_e(`\n delimiter (string) ${a("The character or string to place between each concatenated value.")}\n value_or_array1 (string, range<string>) ${a("The value or values to be appended using delimiter.")}\n value_or_array2 (string, range<string>, repeating) ${a("More values to be appended using delimiter.")}\n `),returns:["STRING"],compute:function(e,...t){const s=ue(e);return be(t,((e,t)=>(e?e+s:"")+ue(t)),"")}},Yn={description:a("Substring from beginning of specified string."),args:_e(`\n text (string) ${a("The string from which the left portion will be returned.")}\n number_of_characters (number, optional) ${a("The number of characters to return from the left side of string.")}\n `),returns:["STRING"],compute:function(e,...t){const s=t.length?he(t[0]):1;return le((()=>s>=0),a("The number_of_characters (%s) must be positive or null.",s.toString())),ue(e).substring(0,s)},isExported:!0},Xn={description:a("Length of a string."),args:_e(`\n text (string) ${a("The string whose length will be returned.")}\n `),returns:["NUMBER"],compute:function(e){return ue(e).length},isExported:!0},Kn={description:a("Converts a specified string to lowercase."),args:_e(`\n text (string) ${a("The string to convert to lowercase.")}\n `),returns:["STRING"],compute:function(e){return ue(e).toLowerCase()},isExported:!0},Qn={description:a("Replaces part of a text string with different text."),args:_e(`\n text (string) ${a("The text, a part of which will be replaced.")}\n position (number) ${a("The position where the replacement will begin (starting from 1).")}\n length (number) ${a("The number of characters in the text to be replaced.")}\n new_text (string) ${a("The text which will be inserted into the original text.")}\n `),returns:["STRING"],compute:function(e,t,s,i){const o=he(t);le((()=>o>=1),a("The position (%s) must be greater than or equal to 1.",o.toString()));const n=ue(e),r=he(s),l=ue(i);return n.substring(0,o-1)+l+n.substring(o-1+r)},isExported:!0},Jn={description:a("A substring from the end of a specified string."),args:_e(`\n text (string) ${a("The string from which the right portion will be returned.")}\n number_of_characters (number, optional) ${a("The number of characters to return from the right side of string.")}\n `),returns:["STRING"],compute:function(e,...t){const s=t.length?he(t[0]):1;le((()=>s>=0),a("The number_of_characters (%s) must be positive or null.",s.toString()));const i=ue(e),o=i.length;return i.substring(o-s,o)},isExported:!0},er={description:a("First position of string found in text, ignoring case."),args:_e(`\n search_for (string) ${a("The string to look for within text_to_search.")}\n text_to_search (string) ${a("The text to search for the first occurrence of search_for.")}\n starting_at (number, default=1) ${a("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,s=1){const i=ue(e).toLowerCase(),o=ue(t).toLowerCase(),n=he(s);le((()=>""!==o),a("The text_to_search must be non-empty.")),le((()=>n>=1),a("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=o.indexOf(i,n-1);return le((()=>r>=0),a("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",i,o)),r+1},isExported:!0},tr={description:a("Replaces existing text with new text in a string."),args:_e(`\n text_to_search (string) ${a("The text within which to search and replace.")}\n search_for (string) ${a("The string to search for within text_to_search.")}\n replace_with (string) ${a("The string that will replace search_for.")}\n occurrence_number (number, optional) ${a("The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced.")}\n `),returns:["NUMBER"],compute:function(e,t,s,i){const o=he(i);le((()=>o>=0),a("The occurrenceNumber (%s) must be positive or null.",o.toString()));const n=ue(e),r=ue(t);if(""===r)return n;const l=ue(s),c=new RegExp(hs(r),"g");if(0===o)return n.replace(c,l);let h=0;return n.replace(c,(e=>++h===o?l:e))},isExported:!0},sr={description:a("Combines text from multiple strings and/or arrays."),args:_e(`\n delimiter (string) ${a(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")}\n ignore_empty (boolean) ${a("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")}\n text1 (string, range<string>) ${a("Any text item. This could be a string, or an array of strings in a range.")}\n text2 (string, range<string>, repeating) ${a("Additional text item(s).")}\n `),returns:["STRING"],compute:function(e,t,...s){const i=ue(e),o=ge(t);let n=0;return be(s,((e,t)=>o&&""===ue(t)?e:(n++?e+i:"")+ue(t)),"")},isExported:!0},ir={description:a("Removes space characters."),args:_e(`\n text (string) ${a("The text or reference to a cell containing text to be trimmed.")}\n `),returns:["STRING"],compute:function(e){return ue(e).trim()},isExported:!0},or={description:a("Converts a specified string to uppercase."),args:_e(`\n text (string) ${a("The string to convert to uppercase.")}\n `),returns:["STRING"],compute:function(e){return ue(e).toUpperCase()},isExported:!0};const nr={database:po,date:Bo,financial:Jo,info:rn,lookup:wn,logical:gn,math:Wt,operators:zn,statistical:Ki,text:Object.freeze({__proto__:null,CHAR:Zn,CONCATENATE:Gn,EXACT:Wn,FIND:qn,JOIN:jn,LEFT:Yn,LEN:Xn,LOWER:Kn,REPLACE:Qn,RIGHT:Jn,SEARCH:er,SUBSTITUTE:tr,TEXTJOIN:sr,TRIM:ir,UPPER:or})};const rr=new class extends Le{constructor(){super(...arguments),this.mapping={}}add(e,t){e=e.toUpperCase().replace("_",".");const s=Ne(t);return function(e){let t=!1,s=!1,i=!1;for(let o of e){if(o.type.includes("META")&&o.type.length>1)throw new Error(a("Function ${name} has an argument that has been declared with more than one type whose type 'META'. The 'META' type can only be declared alone."));if(t&&!o.repeating)throw new Error(a("Function ${name} has no-repeatable arguments declared after repeatable ones. All repeatable arguments must be declared last."));const e=s||t||i,n=!(o.optional||o.repeating||o.default);if(e&&n)throw new Error(a("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=o.repeating,s=o.optional,i=o.default}}(s.args),this.mapping[e]=s.compute,super.add(e,s),this}};for(let e in nr){const t=nr[e];for(let s in t){const i=t[s];i.category=e,rr.add(s,{isExported:!1,...i})}}const ar=/^[S|N]?\d+/,lr=rr.content,cr="+,-,*,/,:,=,<>,>=,>,<=,<,%,^,&".split(",");function hr(e){const t=e.split(""),s=[];for(;t.length;){let e=Ir(t)||gr(t)||mr(t)||Er(t)||ur(t)||dr(t)||yr(t)||vr(t)||br(t);e||(e={type:"UNKNOWN",value:t.shift()}),s.push(e)}return s}function dr(e){if(e[0]===$){e.shift();const t=e.join("").match(ar);if(!t)return null;e.splice(0,t[0].length),e[0]===$&&e.shift();const s=t[0];switch(s[0]){case"S":return{type:"NORMALIZED_STRING",value:s.substring(1)};case"N":return{type:"NORMALIZED_NUMBER",value:s.substring(1)};default:return{type:"REFERENCE",value:s}}}return null}function ur(e){return"?"===e[0]?(e.shift(),{type:"DEBUGGER",value:"?"}):null}const pr={",":"COMMA","(":"LEFT_PAREN",")":"RIGHT_PAREN"};function gr(e){if(e[0]in pr){const t=e.shift();return{type:pr[t],value:t}}return null}function fr(e,t){for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}function mr(e){for(let t of cr)if(fr(e,t))return e.splice(0,t.length),{type:"OPERATOR",value:t};return null}function vr(e){const t=e.join("").match(K);return t?(e.splice(0,t[0].length),{type:"NUMBER",value:t[0]}):null}function Er(e){if('"'===e[0]){const t=e.shift(),s=[t];for(;e[0]&&(e[0]!==t||"\\"===s[s.length-1]);)s.push(e.shift());return'"'===e[0]&&s.push(e.shift()),{type:"STRING",value:s.join("")}}return null}const Sr=/\w|\.|!|\$/;function br(e){const t=[];if("'"===e[0]){let s=e.shift();for(t.push(s);e[0];)if(s=e.shift(),t.push(s),"'"===s){if(!e[0]||"'"!==e[0])break;s=e.shift(),t.push(s)}if("'"!==s)return{type:"UNKNOWN",value:t.join("")}}for(;e[0]&&e[0].match(Sr);)t.push(e.shift());if(t.length){const e=t.join("");return{type:e.toUpperCase()in lr?"FUNCTION":"SYMBOL",value:e}}return null}const Cr=/\s/;function Ir(e){let t=0;for(;e[0]&&e[0].match(Cr);)t++,e.shift();return t?{type:"SPACE",value:" ".repeat(t)}:null}function yr(e){return fr(e,_)?(e.splice(0,_.length),{type:"INVALID_REFERENCE",value:_}):null}const wr=["-","+"],Tr=["*","+","&"],xr={"^":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10},Rr=6;function Lr(e){switch(e.type){case"NUMBER":case"SYMBOL":return 0;case"COMMA":return 3;case"LEFT_PAREN":case"RIGHT_PAREN":return 5;case"OPERATOR":return xr[e.value]||15}throw new Error(a("Unknown token: %s",e.value))}function Ar(e,t,s){if("OPERATOR"===t.type){const i=Mr(s,Lr(t));return{type:"BIN_OPERATION",value:t.value,left:e,right:i}}throw new Error(N)}function Mr(e,t){const s=e.shift();if(!s)throw new Error(N);let i=function(e,t){var s;switch(e.type){case"DEBUGGER":const i=Mr(t,1e3);return i.debug=!0,i;case"NUMBER":return{type:"NUMBER",value:te(e.value)};case"NORMALIZED_NUMBER":return{type:"NORMALIZED_NUMBER",value:parseInt(e.value,10)};case"STRING":return{type:"STRING",value:e.value};case"NORMALIZED_STRING":return{type:"NORMALIZED_STRING",value:parseInt(e.value,10)};case"FUNCTION":if("LEFT_PAREN"!==t.shift().type)throw new Error(a("Wrong function call"));{const i=[];if(t[0]&&"RIGHT_PAREN"!==t[0].type)for("COMMA"===t[0].type?i.push({type:"UNKNOWN",value:""}):i.push(Mr(t,Rr));"COMMA"===(null===(s=t[0])||void 0===s?void 0:s.type);){t.shift();const e=t[0];if("RIGHT_PAREN"===(null==e?void 0:e.type)){i.push({type:"UNKNOWN",value:""});break}"COMMA"===(null==e?void 0:e.type)?i.push({type:"UNKNOWN",value:""}):i.push(Mr(t,Rr))}const o=t.shift();if(!o||"RIGHT_PAREN"!==o.type)throw new Error(a("Wrong function call"));return{type:"FUNCALL",value:e.value,args:i}}case"REFERENCE":return{type:"NORMALIZED_REFERENCE",value:parseInt(e.value,10)};case"INVALID_REFERENCE":throw new Error(a("Invalid reference"));case"SYMBOL":if(Qt.test(e.value))return{type:"REFERENCE",value:e.value};if(["TRUE","FALSE"].includes(e.value.toUpperCase()))return{type:"BOOLEAN",value:"TRUE"===e.value.toUpperCase()};if(e.value)throw new Error(a("Invalid formula"));return{type:"STRING",value:e.value};case"LEFT_PAREN":const o=Mr(t,5);if(!t.length||"RIGHT_PAREN"!==t[0].type)throw new Error(a("Unmatched left parenthesis"));return t.shift(),o;default:if("OPERATOR"===e.type&&wr.includes(e.value))return{type:"UNARY_OPERATION",value:e.value,right:Mr(t,xr[e.value])};throw new Error(a("Unexpected token: %s",e.value))}}(s,e);for(;e[0]&&Lr(e[0])>t;)i=Ar(i,e.shift(),e);return i}function _r(e){const t=hr(e).filter((e=>"SPACE"!==e.type));"OPERATOR"===t[0].type&&"="===t[0].value&&t.splice(0,1);const s=Mr(t,0);if(t.length)throw new Error(N);return s}function Or(e,t,s){switch(t===e.type&&(e=s(e)),e.type){case"FUNCALL":return{...e,args:e.args.map((e=>Or(e,t,s)))};case"UNARY_OPERATION":return{...e,right:Or(e.right,t,s)};case"BIN_OPERATION":return{...e,right:Or(e.right,t,s),left:Or(e.left,t,s)};default:return e}}function Nr(e,t={references:[],numbers:[],strings:[]}){switch(e.type){case"FUNCALL":const s=e.args.map((e=>Nr(e,t)));return`${e.value}(${s.join(",")})`;case"NUMBER":return e.value.toString();case"NORMALIZED_STRING":return`"${t.strings[e.value]}"`;case"NORMALIZED_NUMBER":return t.numbers[e.value].toString();case"NORMALIZED_REFERENCE":return t.references[e.value].toString();case"REFERENCE":case"STRING":default:return e.value;case"BOOLEAN":return e.value?"TRUE":"FALSE";case"UNARY_OPERATION":return e.value+kr(e,t);case"BIN_OPERATION":return function(e,t){const s=e.value,i=e.left,o=i.value;return"BIN_OPERATION"===i.type&&xr[o]<xr[s]?`(${Nr(i,t)})`:Nr(i,t)}(e,t)+e.value+kr(e,t)}}function kr(e,t){const s=e.value,i=e.right,o=xr[i.value],n=xr[s];let r=!1;return"BIN_OPERATION"!==i.type?r=!1:o<n?r=!0:o!==n||Tr.includes(s)||(r=!0),r?`(${Nr(i,t)})`:Nr(i,t)}const Fr=rr.content,$r={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},Dr={"-":"UMINUS","+":"UPLUS"};function Ur(e){return e.map((e=>e.split("\n"))).flat().filter((e=>""!==e.trim()))}const Pr={};function Br(e){if(!Pr[e.text]){const t=_r(e.text);let s=1;if("BIN_OPERATION"===t.type&&":"===t.value)throw new Error(a("Invalid formula"));if("UNKNOWN"===t.type)throw new Error(a("Invalid formula"));const i=l(t),o=Ur([`// ${e.text}`,i.code,`return ${i.id};`]).join("\n");let n=new Function("deps","sheetId","ref","range","ctx",o);function r(e){const t=Fr[e.value.toUpperCase()],s=e.args,i=s.length;if(i<t.minArgRequired)throw new Error(a("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",e.value.toUpperCase(),t.minArgRequired.toString(),i.toString()));if(i>t.maxArgPossible)throw new Error(a("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",e.value.toUpperCase(),t.maxArgPossible.toString(),i.toString()));const o=t.nbrArgRepeating;if(o>1){const s=t.args.length-o;if((i-s)%o!=0)throw new Error(a("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",e.value.toUpperCase(),s.toString(),o.toString()))}let n=[];for(let o=0;o<i;o++){const i=t.getArgToFocus(o+1)-1;if(0<=i&&i<t.args.length){const r=s[o],c=t.args[i],h=c.type||[],d=h.includes("META"),u=c.lazy,p=h.some((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e)),g=h.every((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e));if(g&&"NORMALIZED_REFERENCE"!==r.type)throw new Error(a("Function %s expects the parameter %s to be reference to a cell or range, not a %s.",e.value.toUpperCase(),(o+1).toString(),r.type.toLowerCase().replace("normalized_","")));const f=l(r,u,d,p,{functionName:e.value.toUpperCase(),paramIndex:o+1});n.push(f)}}return n}function l(t,i=!1,o=!1,n=!1,c={}){const h=[];let d,u,p;if("NORMALIZED_REFERENCE"!==t.type&&("BIN_OPERATION"!==t.type||":"!==t.value)&&o)throw new Error(a("Argument must be a reference to a cell or range."));switch(t.debug&&h.push("debugger;"),t.type){case"BOOLEAN":case"NUMBER":case"STRING":if(!i)return{id:t.value,code:""};d=s++,p=`${t.value}`;break;case"NORMALIZED_NUMBER":d=s++,p=`deps.numbers[${t.value}]`;break;case"NORMALIZED_STRING":d=s++,p=`deps.strings[${t.value}]`;break;case"REFERENCE":throw new Error(`Only normalized references can be compiled: ${t.value}`);case"NORMALIZED_REFERENCE":if(!e.dependencies.references[t.value]){d=s++,p="null";break}d=s++,p=n?`range(${t.value}, deps.references, sheetId)`:`ref(${t.value}, deps.references, sheetId, ${o?"true":"false"}, "${c.functionName||$r["="]}", ${c.paramIndex})`;break;case"FUNCALL":d=s++;const a=r(t);h.push(Ur(a.map((e=>e.code))).join("\n")),u=t.value.toUpperCase(),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}'](${a.map((e=>e.id))})`;break;case"UNARY_OPERATION":{d=s++,u=Dr[t.value];const e=l(t.right,!1,!1,!1,{functionName:u});h.push(e.code),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}']( ${e.id})`;break}case"BIN_OPERATION":{d=s++,u=$r[t.value];const e=l(t.left,!1,!1,!1,{functionName:u}),i=l(t.right,!1,!1,!1,{functionName:u});h.push(e.code),h.push(i.code),h.push(`ctx.__lastFnCalled = '${u}';`),p=`ctx['${u}'](${e.id}, ${i.id})`;break}case"UNKNOWN":if(!i)return{id:"undefined",code:""};d=s++,p="undefined"}if(i){return{id:`_${d}`,code:`const _${d} = () => {\n\t${Ur(h).join("\n\t")}\n\treturn ${p};\n}`}}return h.push(`let _${d} = ${p};`),{id:`_${d}`,code:Ur(h).join("\n")}}function c(t){let s;switch(t.type){case"NORMALIZED_REFERENCE":if(e.dependencies.references[t.value])return[t.value];break;case"FUNCALL":if(s=Fr[t.value.toUpperCase()],s.returnFormat){if("FormatFromArgument"!==s.returnFormat)return[s.returnFormat.specificFormat];if(t.args.length>0){const e=0;if(!s.args[e].type.includes("META"))return c(t.args[e])}}break;case"UNARY_OPERATION":return c(t.right);case"BIN_OPERATION":if(s=Fr[$r[t.value]],s.returnFormat){if("FormatFromArgument"===s.returnFormat){const e=c(t.left);if("string"==typeof e[e.length-1])return e;const s=c(t.right);return e.concat(s)}return[s.returnFormat.specificFormat]}}return[]}Pr[e.text]=n,Pr[e.text].dependenciesFormat=c(t)}return Pr[e.text]}function Vr(e,t=!1){let s,i,o,n;const r=()=>{n=void 0,i=void 0,s=void 0,o=void 0};for(let a=0;a<e.length;a++){const l=e[a];if(n)if(i){if("SPACE"===l.type)continue;if("OPERATOR"===l.type&&":"===l.value)s=a;else if(s&&"SYMBOL"===l.type)o=a;else if(n&&i&&s&&o){const s={type:"SYMBOL",value:e.slice(n,a).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(n,a-n,s),a=n+1,r()}else"SYMBOL"===l.type?(n=a,i=a,s=void 0):r()}else"SYMBOL"===l.type?(i=a,s=o=void 0):r();else["SPACE","SYMBOL"].includes(l.type)?(n=a,i="SYMBOL"===l.type?a:void 0,s=o=void 0):r()}const a=e.length-1;if(n&&i&&s&&o){const s={type:"SYMBOL",value:e.slice(n,a+1).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(n,a-n+1,s)}return e}function Hr(e){return Vr(hr(e),!0)}function zr(e){return function(e){let t=[],s="";return e.map(((e,i)=>{switch(["SPACE","LEFT_PAREN"].includes(e.type)||(s=""),e.type){case"FUNCTION":s=e.value;break;case"LEFT_PAREN":t.push({parent:s,argPosition:0}),s="";break;case"RIGHT_PAREN":t.pop();break;case"COMMA":t.length&&t[t.length-1].argPosition++}if(t.length){const s=t[t.length-1];s.parent&&(e.functionContext=Object.assign({},s))}return e}))}(function(e){let t=1;const s=[];return e.map((e=>("LEFT_PAREN"===e.type?(s.push(t),e.parenIndex=t,t++):"RIGHT_PAREN"===e.type&&(e.parenIndex=s.pop()),e)))}(function(e){let t=0;return e.map((e=>{const s=e.value.toString().length,i=Object.assign({},e,{start:t,end:t+s,length:s});return t=i.end,i}))}(Vr(hr(e)))))}function Zr(e){const t=Hr(e);let s={numbers:[],strings:[],references:[]};return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Qt.test(e.value)){const t=e.value.trim();s.references.includes(t)||s.references.push(t);return Gr(s.references.indexOf(t).toString())}if("STRING"===e.type){const t=e.value.slice(1).slice(0,e.value.length-2);s.strings.includes(t)||s.strings.push(t);const i=s.strings.indexOf(t);return Gr(`${e.type[0]}${i}`)}if("NUMBER"===e.type){const t=te(e.value);s.numbers.includes(t)||s.numbers.push(t);const i=s.numbers.indexOf(t);return Gr(`${e.type[0]}${i}`)}return e.value}))),dependencies:s}}function Gr(e){return`${$}${e}${$}`}const Wr=new Le;function qr(e,t){switch(typeof e){case"string":return e.includes('\\"')?e.replace(/\\"/g,'"'):e;case"boolean":return e?"TRUE":"FALSE";case"number":return(null==t?void 0:t.match(M))?j({value:e,format:t}):t?function(e,t){const s=t.split(";"),i=s.length;return e<0?i>1?ae(-e,s[1]):"-"+ae(-e,s[0]):ae(e,s[3===i&&0===e?2:0])}(e,t):ie(e);case"object":return"0"}}function jr(e){return""===e?"":J(e)?te(e):Es(e)?"TRUE"===e.toUpperCase():Ss(e)?G(e).value:e}class Yr{constructor(e,t,s){this.id=e,this.evaluated=t,this.style=s.style,this.format=s.format}isFormula(){return!1}isLink(){return!1}isEmpty(){return!1}get formattedValue(){return qr(this.evaluated.value,this.format)}get composerContent(){return this.content}get defaultAlign(){switch(this.evaluated.type){case ke.number:return"right";case ke.boolean:case ke.error:return"center";case ke.text:case ke.empty:return"left"}}get isAutoSummable(){var e;switch(this.evaluated.type){case ke.empty:case ke.text:return!0;case ke.number:return!(null===(e=this.format)||void 0===e?void 0:e.match(M));case ke.error:case ke.boolean:return!1}}}class Xr extends Yr{constructor(e,t={}){super(e,{value:"",type:ke.empty},t),this.content=""}isEmpty(){return!0}}class Kr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.number},s),this.content=ie(this.evaluated.value)}}class Qr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.boolean},s),this.content=this.evaluated.value?"TRUE":"FALSE"}}class Jr extends Yr{constructor(e,t,s={}){super(e,{value:t,type:ke.text},s),this.content=this.evaluated.value}}class ea extends Kr{constructor(e,t,s){super(e,t,s),this.format=s.format}get composerContent(){return qr(this.evaluated.value,this.format)}}class ta extends Yr{constructor(e,t,s={}){const i=ws(t);super(e,{value:i.label,type:ke.text},s),this.link=i,this.content=t}isLink(){return!0}get composerContent(){return this.link.label}}class sa extends ta{constructor(e,t,s={}){super(e,t,s),this.link.url=this.withHttp(this.link.url),this.link.isExternal=!0,this.content=ys(this.link.label,this.link.url),this.urlRepresentation=this.link.url,this.isUrlEditable=!0}action(e){window.open(this.link.url,"_blank")}withHttp(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}}class ia extends ta{constructor(e,t,s={},i){super(e,t,s),this.sheetName=i,this.sheetId=Rs(this.link.url),this.isUrlEditable=!1}action(e){e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}get urlRepresentation(){return this.sheetName(this.sheetId)||a("Invalid sheet")}}class oa extends Yr{constructor(e,t,s,i,o,n){super(t,{value:"Loading...",type:ke.text},n),this.buildFormulaString=e,this.normalizedText=s,this.compiledFormula=i,this.dependencies=o}get content(){return this.buildFormulaString(this.normalizedText,this.dependencies)}isFormula(){return!0}assignValue(e){switch(typeof e){case"number":this.evaluated={value:e,type:ke.number};break;case"boolean":this.evaluated={value:e,type:ke.boolean};break;case"string":this.evaluated={value:e,type:ke.text};break;case"object":case"undefined":this.evaluated={value:e,type:ke.empty}}}assignError(e,t){this.evaluated={value:e,error:t,type:ke.error}}}class na extends Yr{constructor(e,t,s,i){super(e,{value:"#BAD_EXPR",type:ke.error,error:s},i),this.content=t}}function ra(e){const t=Hr(e);let s=[];return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Qt.test(e.value)){const t=e.value.trim();return s.includes(t)||s.push(t),`${$}${s.indexOf(t)}${$}`}return e.value}))),dependencies:s}}Wr.add("Formula",{sequence:10,match:e=>e.startsWith("="),createCell:(e,t,s,i,o)=>{const n=Zr(t),r=n.text,a=Br(n),l=n.dependencies.references.map((e=>o.getRangeFromSheetXC(i,e))),c=s.format||function(e,t,s){var i;const o=t.dependenciesFormat;for(let t of o)switch(typeof t){case"string":return t;case"number":const o=s[t],n=e[o.sheetId];if(n){const e=null===(i=n.rows[o.zone.top])||void 0===i?void 0:i.cells[o.zone.left];if(e&&e.format)return e.format}}return F}(o.getEvaluationSheets(),a,l);return new oa(((e,t)=>o.buildFormulaContent(i,e,t)),e,r,a,{...n.dependencies,references:l},{...s,format:c})}}).add("Empty",{sequence:20,match:e=>""===e,createCell:(e,t,s)=>new Xr(e,s)}).add("Number",{sequence:30,match:e=>J(e),createCell:(e,t,s)=>(!s.format&&t.includes("%")&&(s.format=t.includes(".")?"0.00%":"0%"),new Kr(e,te(t),s))}).add("Boolean",{sequence:40,match:e=>Es(e),createCell:(e,t,s)=>new Qr(e,"TRUE"===t.toUpperCase(),s)}).add("DateTime",{sequence:50,match:e=>Ss(e),createCell:(e,t,s)=>{const i=G(t),o=s.format||i.format;return new ea(e,i.value,{...s,format:o})}}).add("MarkdownSheetLink",{sequence:60,match:e=>xs(e),createCell:(e,t,s,i,o)=>new ia(e,t,s,(e=>o.tryGetSheetName(e)))}).add("MarkdownLink",{sequence:70,match:e=>Is(e),createCell:(e,t,s)=>new sa(e,t,s)}).add("WebLink",{sequence:80,match:e=>{return t=e,Cs.test(t);var t},createCell:(e,t,s)=>new sa(e,ys(t,t),s)});const aa=10,la="Sheet1";function ca(e){return e?("version"in(e=JSON.parse(JSON.stringify(e)))&&e.version<aa&&(e=function(e){for(let t=ha.findIndex((t=>t.from===e.version));t<ha.length;t++)e=ha[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,s=new oi;for(const i of e.sheets||[])for(const e of i.figures||[])t.has(e.id)&&(e.id+=s.uuidv4()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(ga(),e,{version:aa}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(pa(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(pa(la,"Sheet1"));return e}(e),e}(e),e):ga()}const ha=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const s=t.cells[e];s.content&&s.content.startsWith("=")&&(s.formula=ra(s.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:s,...i}=t.figures[e].data,o=[];for(let e of s)if(e.labelCell){const t=ks(e.dataRange),s=e.labelCell+":"+is(t.right,t.bottom);o.push(s)}else o.push(e.dataRange);i.dataSetsHaveTitle=Boolean(s[0].labelCell),i.dataSets=o,t.figures[e].data=i}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const s=[],i=new RegExp(k,"g");for(let o of e.sheets||[]){if(!o.name)continue;const e=o.name,n=e.replace(i,"_");let r=1,a=n;for(;s.includes(a);)a=`${n}${r}`,r++;o.name=a,s.push(a);const l=t=>{if(void 0===t)return t;let s=t.replace(e,a),i=t;for(;i!==s;)i=s,s=i.replace(e,a);return i};for(let e in o.cells){const t=o.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of o.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),s=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:s}}for(let e of o.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const s of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[s])||void 0===t?void 0:t.type)&&(e.rule[s].value=l(e.rule[s].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=g,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stackedBar=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const s=t.cells[e];if(s.formula){let{text:e,dependencies:t}=s.formula;for(let[s,i]of Object.entries(t)){const t=`\\${$}${s}\\${$}`;e=e.replace(new RegExp(t,"g"),i)}s.content=e,delete s.formula}}return e}}];function da(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const s=[],i=[],o=e=>{if("CREATE_SHEET"===e.type)s.push(e.sheetId);else if("sheetId"in e&&!s.includes(e.sheetId))return{...e,sheetId:la};return e};for(const e of t)"REMOTE_REVISION"===e.type?i.push({...e,commands:e.commands.map(o)}):i.push(e);return i}(e,t),t=ua(t,"SORT_CELLS"),t=ua(t,"SET_DECIMAL")}function ua(e,t){const s=[];for(const i of e)"REMOTE_REVISION"===i.type?s.push({...i,commands:i.commands.filter((e=>e.type!==t))}):s.push(i);return s}function pa(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[]}}function ga(e="Sheet1"){return{version:aa,sheets:[pa(la,e)],entities:{},styles:{},borders:{},revisionId:O,uniqueFigureIds:!0}}class fa{constructor(e,t,s){this.history=Object.assign(Object.create(e),{update:e.addChange.bind(e,this),selectCell:()=>{}}),this.dispatch=t,this.currentMode=s.mode}allowDispatch(e){return 0}beforeHandle(e){}handle(e){}finalize(){}batchValidations(...e){return t=>e.map((e=>e.call(this,t))).flat()}chainValidations(...e){return t=>{for(const s of e){let e=s.call(this,t);Array.isArray(e)||(e=[e]);const i=e.filter((e=>0!==e));if(i.length)return i}return 0}}checkValidations(e,...t){return this.batchValidations(...t)(e)}}fa.getters=[],fa.modes=["headless","normal"];class ma extends fa{constructor(e,t,s,i,o,n){super(t,i,o),this.dispatch=i,this.range=s,s.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=n}import(e){}export(e){}exportForExcel(e){}adaptRanges(e,t){}}class va extends ma{constructor(){super(...arguments),this.borders={}}handle(e){switch(e.type){case"ADD_MERGE":if(!e.interactive)for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const s=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,s)}break;case"DELETE_SHEET":const s={...this.borders};delete s[e.sheetId],this.history.update("borders",s);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=this.getters.getSheet(e.sheetId),s=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(t,s,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":for(let t of e.elements)"COL"===e.dimension?this.shiftBordersHorizontally(e.sheetId,t+1,-1):this.shiftBordersVertically(e.sheetId,t+1,-1);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){const t=this.getters.getSheet(e.sheetId);let s,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),s=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),s=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(t,s,i)}handleAddRows(e){const t=this.getters.getSheet(e.sheetId);let s,i;"before"===e.position?(this.shiftBordersVertically(t.id,e.base,e.quantity,{moveFirstTopBorder:!0}),s=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(t.id,e.base+1,e.quantity,{moveFirstTopBorder:!1}),s=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(t,s,i)}getCellBorder(e,t,s){var i,o,n,r,a,l,c,h,d,u,p,g;const f={top:null===(n=null===(o=null===(i=this.borders[e])||void 0===i?void 0:i[t])||void 0===o?void 0:o[s])||void 0===n?void 0:n.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[s+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[s])||void 0===d?void 0:d.vertical,right:null===(g=null===(p=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===p?void 0:p[s])||void 0===g?void 0:g.vertical};return f.bottom||f.left||f.right||f.top?f:null}ensureColumnBorderContinuity(e,t,s){const i=fs(t+1,s);for(let o=0;o<e.rows.length;o++){const n=this.getCellBorder(e.id,t,o),r=this.getCellBorder(e.id,s,o);if(n&&r){const t=this.getCommonSides(n,r);for(let s of i)this.addBorder(e.id,s,o,t)}}}ensureRowBorderContinuity(e,t,s){const i=fs(t+1,s);for(let o=0;o<e.cols.length;o++){const n=this.getCellBorder(e.id,o,t),r=this.getCellBorder(e.id,o,s);if(n&&r){const t=this.getCommonSides(n,r);for(let s of i)this.addBorder(e.id,o,s,t)}}}getCommonSides(e,t){const s={};for(let i of["top","bottom","left","right"])e[i]&&e[i]===t[i]&&(s[i]=e[i]);return s}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsWithBorders(e){var t;const s=null===(t=this.borders[e])||void 0===t?void 0:t.filter(Ls);if(!s)return[];const i=new Set;for(const e of s)for(const t in e)i.add(parseInt(t,10));return Array.from(i)}getRowsRange(e){if(!this.borders[e])return[];return fs(0,this.getters.getSheet(e).rows.length+1)}shiftBordersHorizontally(e,t,s,{moveFirstLeftBorder:i}={}){this.borders[e]&&(s<0&&this.moveBordersOfColumn(e,t,s,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>s<0?e-t:t-e)).forEach((o=>{(o===t&&i||o!==t)&&this.moveBordersOfColumn(e,o,s,"vertical"),this.moveBordersOfColumn(e,o,s,"horizontal")})))}shiftBordersVertically(e,t,s,{moveFirstTopBorder:i}={}){this.borders[e]&&(s<0&&this.moveBordersOfRow(e,t,s,"horizontal",{destructive:!1}),this.getRowsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>s<0?e-t:t-e)).forEach((o=>{(o===t&&i||o!==t)&&this.moveBordersOfRow(e,o,s,"horizontal"),this.moveBordersOfRow(e,o,s,"vertical")})))}moveBordersOfRow(e,t,s,i,{destructive:o}={destructive:!0}){const n=this.borders[e];n&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=n[r])||void 0===a?void 0:a[t+s])||void 0===l?void 0:l[i],u=null===(h=null===(c=n[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i];this.history.update("borders",e,r,t+s,i,o?u:u||d),this.history.update("borders",e,r,t,i,void 0)}))}moveBordersOfColumn(e,t,s,i,{destructive:o}={destructive:!0}){const n=this.borders[e];n&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=n[t+s])||void 0===a?void 0:a[r])||void 0===l?void 0:l[i],u=null===(h=null===(c=n[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[i];this.history.update("borders",e,t+s,r,i,o?u:u||d),this.history.update("borders",e,t,r,i,void 0)}))}setBorder(e,t,s,i){this.history.update("borders",e,t,s,{vertical:null==i?void 0:i.left,horizontal:null==i?void 0:i.top}),this.history.update("borders",e,t+1,s,"vertical",null==i?void 0:i.right),this.history.update("borders",e,t,s+1,"horizontal",null==i?void 0:i.bottom)}clearBorders(e,t){for(let s of t){for(let t=s.top;t<=s.bottom;t++){this.history.update("borders",e,s.right+1,t,"vertical",void 0);for(let i=s.left;i<=s.right;i++)this.history.update("borders",e,i,t,void 0)}for(let t=s.left;t<=s.right;t++)this.history.update("borders",e,t,s.bottom+1,"horizontal",void 0)}}addBorder(e,t,s,i){this.setBorder(e,t,s,{...this.getCellBorder(e,t,s),...i})}setBorders(e,t,s){const i=e.id;if("clear"===s)return this.clearBorders(i,t);for(let e of t){if("h"===s||"hv"===s||"all"===s)for(let t=e.top+1;t<=e.bottom;t++)for(let s=e.left;s<=e.right;s++)this.addBorder(i,s,t,{top:L});if("v"===s||"hv"===s||"all"===s)for(let t=e.top;t<=e.bottom;t++)for(let s=e.left+1;s<=e.right;s++)this.addBorder(i,s,t,{left:L});if("left"===s||"all"===s||"external"===s)for(let t=e.top;t<=e.bottom;t++)this.addBorder(i,e.left,t,{left:L});if("right"===s||"all"===s||"external"===s)for(let t=e.top;t<=e.bottom;t++)this.addBorder(i,e.right+1,t,{left:L});if("top"===s||"all"===s||"external"===s)for(let t=e.left;t<=e.right;t++)this.addBorder(i,t,e.top,{top:L});if("bottom"===s||"all"===s||"external"===s)for(let t=e.left;t<=e.right;t++)this.addBorder(i,t,e.bottom+1,{top:L})}}addBordersToMerge(e,t){const s=this.getters.getSheet(e),{left:i,right:o,top:n,bottom:r}=t,a=this.getCellBorder(s.id,i,n),l=this.getCellBorder(s.id,o,r);this.clearBorders(e,[t]),(null==a?void 0:a.top)&&this.setBorders(s,[{...t,bottom:n}],"top"),(null==a?void 0:a.left)&&this.setBorders(s,[{...t,right:i}],"left"),((null==l?void 0:l.bottom)||(null==a?void 0:a.bottom))&&this.setBorders(s,[{...t,top:r}],"bottom"),((null==l?void 0:l.right)||(null==a?void 0:a.right))&&this.setBorders(s,[{...t,left:o}],"right")}import(e){if(e.borders)for(let t of e.sheets)for(let[s,i]of Object.entries(t.cells))if(null==i?void 0:i.border){const o=e.borders[i.border],[n,r]=ss(s);this.setBorder(t.id,n,r,o)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,ks(e))}export(e){let t=0;const s={};function i(e){for(let[t,i]of Object.entries(s))if(Ms(i,e))return parseInt(t,10);return s[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let s=0;s<t.rowNumber;s++){const o=this.getCellBorder(t.id,e,s);if(o){const n=is(e,s),r=t.cells[n],a=i(o);r?r.border=a:t.cells[n]={border:a}}}e.borders=s}exportForExcel(e){this.export(e)}}va.getters=["getCellBorder"];const Ea=new RegExp(String.fromCharCode(160),"g"),Sa={textColor:A,underline:!0};class ba extends ma{constructor(){super(...arguments),this.cells={},this.cellUuidGenerator=new oi(!0),this.createCell=function(e){const t=Wr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(s,i,o,n){const r=t.find((e=>e.match(i)));if(!r)return new Jr(s,i,o);try{return r.createCell(s,i,o,n,e)}catch(e){return new na(s,i,e.message||N,o)}}}(this.getters)}adaptRanges(e,t){for(const s of Object.keys(this.cells))for(const i of Object.values(this.cells[s]||{}))if(i.isFormula())for(const o of i.dependencies.references)if(!t||o.sheetId===t){const t=e(o);"NONE"!==t.changeType&&this.history.update("cells",s,i.id,"dependencies","references",i.dependencies.references.indexOf(o),t.range)}}allowDispatch(e){switch(e.type){case"UPDATE_CELL":case"CLEAR_CELL":return this.checkCellOutOfSheet(e.sheetId,e.col,e.row);default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearStyles(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(this.getters.getSheet(e.sheetId),e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""})}}setFormatter(e,t,s){for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,format:s})}clearStyles(e,t){for(let s of t)for(let t=s.left;t<=s.right;t++)for(let i=s.top;i<=s.bottom;i++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,style:null})}handleAddColumnsRows(e,t){const s=this.getters.getSheet(e.sheetId);let i,o;"before"===e.position?(i=fs(e.base,e.base+e.quantity),o=e.base+e.quantity):(i=fs(e.base+1,e.base+e.quantity+1),o=e.base),t(s,o,i)}import(e){for(let t of e.sheets){const s=this.getters.getSheet(t.id);for(let i in t.cells){const o=t.cells[i],[n,r]=ss(i);if((null==o?void 0:o.content)||(null==o?void 0:o.format)||(null==o?void 0:o.style)){const i=this.importCell(s,o,e.styles);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cell:i,cellId:i.id,col:n,row:r,sheetId:t.id})}}}}export(e){let t=0;const s={};function i(e){for(let[t,i]of Object.entries(s))if(Ms(i,e))return parseInt(t,10);return s[++t]=e,t}for(let t of e.sheets){const e={},s=Object.keys(this.cells[t.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const{col:o,row:n}of s){const s=this.getters.getCell(t.id,o,n);e[is(o,n)]={style:s.style&&i(s.style),format:s.format,content:s.content}}t.cells=e}e.styles=s}importCell(e,t,s){const i=t.style&&s[t.style]||void 0,o=this.cellUuidGenerator.uuidv4(),n={format:null==t?void 0:t.format,style:i};return this.createCell(o,(null==t?void 0:t.content)||"",n,e.id)}exportForExcel(e){this.export(e);for(let t of e.sheets)for(const e in t.cells){const[s,i]=ss(e),o=this.getters.getCell(t.id,s,i),n=t.cells[e];n.value=o.evaluated.value,n.isFormula=o.isFormula()}}getCells(e){return this.cells[e]||{}}getCellById(e){const t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}buildFormulaContent(e,t,s){let i=t;for(let[t,o]of Object.entries(s.references)){const s=this.getters.getRangeString(o,e),n=`\\${$}${t}\\${$}`;i=i.replace(new RegExp(n,"g"),s)}for(let[e,t]of Object.entries(s.strings)){const s=`\\${$}S${e}\\${$}`;i=i.replace(new RegExp(s,"g"),`"${t}"`)}for(let[e,t]of Object.entries(s.numbers)){const s=`\\${$}N${e}\\${$}`;i=i.replace(new RegExp(s,"g"),t.toString())}return i}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t.normalizedText,t.dependencies)}getCellStyle(e){return{...e.isLink()?Sa:{},...e.style}}zoneToXC(e,t,s=[{colFixed:!1,rowFixed:!1}]){const i=is((t=this.getters.expandZone(e,t)).left,t.top,s[0]),o=is(t.right,t.bottom,s.length>1?s[1]:s[0]),n=this.getters.getMainCell(e,t.left,t.top),r=this.getters.getMainCell(e,t.right,t.bottom),a=n[0]==r[0]&&n[1]==r[1];return i==o||a?i:i+":"+o}setStyle(e,t,s){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++){const i=this.getters.getCell(e,t,o);this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:s?{...null==i?void 0:i.style,...s}:void 0})}}copyColumnStyle(e,t,s){for(let i=0;i<e.rows.length;i++){const o=this.getFormat(e.id,t,i);if(o.style||o.format)for(let t of s)this.dispatch("UPDATE_CELL",{sheetId:e.id,col:t,row:i,...o})}}copyRowStyle(e,t,s){for(let i=0;i<e.cols.length;i++){const o=this.getFormat(e.id,i,t);if(o.style||o.format)for(let t of s)this.dispatch("UPDATE_CELL",{sheetId:e.id,col:i,row:t,...o})}}getFormat(e,t,s){const i={},[o,n]=this.getters.getMainCell(e,t,s),r=this.getters.getCell(e,o,n);return r&&(r.style&&(i.style=r.style),r.format&&(i.format=r.format)),i}updateCell(e,t,s,i){var o;const n=e.rows[s].cells[t],r="content"in i||"formula"in i,a=r?(null===(o=i.content)||void 0===o?void 0:o.replace(Ea,""))||"":(null==n?void 0:n.content)||"";let l;l=void 0!==i.style?i.style||void 0:n?n.style:void 0;let c=("format"in i?i.format:n&&n.format)||F;if((r&&!a&&!i.formula||!r&&(!n||n.isEmpty()))&&!l&&!c)return void(n&&(this.history.update("cells",e.id,n.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:n.id,col:t,row:s,sheetId:e.id,cell:void 0})));const h=(null==n?void 0:n.id)||this.cellUuidGenerator.uuidv4(),d=r,u={format:c,style:l},p=this.createCell(h,a,u,e.id);n&&!d&&p.isFormula()&&(p.assignValue(n.evaluated.value),n.evaluated.type===ke.error&&p.assignError(n.evaluated.value,n.evaluated.error)),this.history.update("cells",e.id,p.id,p),this.dispatch("UPDATE_CELL_POSITION",{cell:p,cellId:p.id,col:t,row:s,sheetId:e.id})}checkCellOutOfSheet(e,t,s){const i=this.getters.tryGetSheet(e);if(!i)return 23;return Hs(t,s,{top:0,left:0,bottom:i.rows.length-1,right:i.cols.length-1})?0:18}}ba.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class Ca extends ma{constructor(){super(...arguments),this.chartFigures={}}adaptRanges(e){for(let[t,s]of Object.entries(this.chartFigures))s&&(this.adaptDataSetRanges(s,t,e),this.adaptLabelRanges(s,t,e))}adaptDataSetRanges(e,t,s){for(let i of e.dataSets){if(i.labelCell){const o=s(i.labelCell);switch(o.changeType){case"REMOVE":this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"labelCell",void 0);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"labelCell",o.range)}}const o=s(i.dataRange);switch(o.changeType){case"REMOVE":const s=e.dataSets.filter((e=>e!==i));this.history.update("chartFigures",t,"dataSets",s);break;case"RESIZE":case"MOVE":case"CHANGE":if(this.getters.getRangeString(o.range,o.range.sheetId)!==_)this.history.update("chartFigures",t,"dataSets",e.dataSets.indexOf(i),"dataRange",o.range);else{const s=e.dataSets.filter((e=>e!==i));this.history.update("chartFigures",t,"dataSets",s)}}}}adaptLabelRanges(e,t,s){if(e.labelRange){const i=s(e.labelRange);switch(i.changeType){case"REMOVE":this.history.update("chartFigures",t,"labelRange",void 0);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("chartFigures",t,"labelRange",i.range)}}}allowDispatch(e){switch(e.type){case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.checkEmptyDataset,this.checkDataset,this.checkChartExists),this.checkLabelRange);case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.checkEmptyDataset,this.checkDataset,this.checkChartDuplicate),this.checkLabelRange);default:return 0}}handle(e){var t,s;switch(e.type){case"CREATE_CHART":const i=e.position?e.position.x:0,o=e.position?e.position.y:0;this.addChartFigure(e.sheetId,this.createChartDefinition(e.definition,e.sheetId),{id:e.id,x:i,y:o,height:335,width:536,tag:"chart"});break;case"UPDATE_CHART":this.updateChartDefinition(e.id,e.definition);break;case"DUPLICATE_SHEET":{const s=this.getters.getFigures(e.sheetId);for(const i of s)if("chart"===i.tag){const s=i.id.split("??").pop(),o=`${e.sheetIdTo}??${s}`,n={...ds(this.chartFigures[i.id]),id:o};n.sheetId=e.sheetIdTo,n.dataSets.forEach((t=>{var s;t.dataRange.sheetId===e.sheetId&&(t.dataRange.sheetId=e.sheetIdTo),(null===(s=t.labelCell)||void 0===s?void 0:s.sheetId)===e.sheetId&&(t.labelCell.sheetId=e.sheetIdTo)})),(null===(t=n.labelRange)||void 0===t?void 0:t.sheetId)===e.sheetId&&(n.labelRange.sheetId=e.sheetIdTo);const r={id:o,x:i.x,y:i.y,height:i.height,width:i.width,tag:"chart"};this.addChartFigure(e.sheetIdTo,n,r)}break}case"DELETE_FIGURE":this.history.update("chartFigures",e.id,void 0);break;case"DELETE_SHEET":for(let t of Object.keys(this.chartFigures))(null===(s=this.chartFigures[t])||void 0===s?void 0:s.sheetId)===e.sheetId&&this.history.update("chartFigures",t,void 0)}}getChartDefinition(e){return this.chartFigures[e]}getChartsIdBySheet(e){return Object.entries(this.chartFigures).filter((t=>t[1].sheetId===e)).map((e=>e[0]))}getChartDefinitionUI(e,t){const s=this.chartFigures[t];if(!s)return;const i=s.dataSets.map((t=>t?this.getters.getRangeString(t.dataRange,e):"")).filter((e=>""!==e));return{title:s&&s.title?s.title:"",dataSets:i,labelRange:s.labelRange?this.getters.getRangeString(s.labelRange,e):void 0,type:s?s.type:"bar",dataSetsHaveTitle:!(!s||0===i.length)&&Boolean(s.dataSets[0].labelCell),background:s.background,verticalAxisPosition:s.verticalAxisPosition,legendPosition:s.legendPosition,stackedBar:s.stackedBar}}getChartDefinitionExcel(e,t){const s=this.chartFigures[t],i=this.getChartDefinitionUI("forceSheetReference",t);if(!s||!i)return;const o=s.dataSets.map((e=>this.toExcelDataset(e))).filter((e=>""!==e.range));return{...i,backgroundColor:s.background,dataSets:o}}toExcelDataset(e){var t;const s=null===(t=e.labelCell)||void 0===t?void 0:t.zone;let i=e.dataRange.zone;if(s){const{height:e,width:t}=Ws(i);1===e?i={...i,left:i.left+1}:1===t&&(i={...i,top:i.top+1})}const o={...e.dataRange,zone:i};return{label:e.labelCell?this.getters.getRangeString(e.labelCell,"forceSheetReference"):void 0,range:this.getters.getRangeString(o,"forceSheetReference")}}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)if("chart"===e.tag){const s={...e.data};this.chartFigures[e.id]=this.createChartDefinition(s,t.id),delete e.data}}export(e){if(e.sheets)for(let t of e.sheets){const e=this.getters.getFigures(t.id),s=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=this.getChartDefinitionUI(t.id,e.id);i&&(e.data=i,s.push(e))}else s.push(e)}t.figures=s}}exportForExcel(e){for(let t of e.sheets){const e=this.getters.getFigures(t.id),s=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=this.getChartDefinitionExcel(t.id,e.id);i&&(e.data=i,s.push(e))}else s.push(e)}t.charts=s}}createChartDefinition(e,t){return{...e,dataSets:this.createDataSets(e.dataSets,t,e.dataSetsHaveTitle),labelRange:e.labelRange?this.getters.getRangeFromSheetXC(t,e.labelRange):void 0,sheetId:t}}updateChartDefinition(e,t){const s=this.chartFigures[e];if(!s)throw new Error(`There is no chart with the given id: ${e}`);if(void 0!==t.title&&this.history.update("chartFigures",e,"title",t.title),t.type&&this.history.update("chartFigures",e,"type",t.type),t.dataSets){const i=!!t.dataSetsHaveTitle,o=this.createDataSets(t.dataSets,s.sheetId,i);this.history.update("chartFigures",e,"dataSets",o)}if(void 0!==t.labelRange){const i=t.labelRange?this.getters.getRangeFromSheetXC(s.sheetId,t.labelRange):void 0;this.history.update("chartFigures",e,"labelRange",i)}t.background&&this.history.update("chartFigures",e,"background",t.background),t.verticalAxisPosition&&this.history.update("chartFigures",e,"verticalAxisPosition",t.verticalAxisPosition),t.legendPosition&&this.history.update("chartFigures",e,"legendPosition",t.legendPosition),void 0!==t.stackedBar&&this.history.update("chartFigures",e,"stackedBar",t.stackedBar)}createDataSets(e,t,s){const i=[];for(const o of e){const e=this.getters.getRangeFromSheetXC(t,o),{zone:n,sheetId:r,invalidSheetName:a}=e;if(!a)if(n.left!==n.right&&n.top!==n.bottom)for(let e=n.left;e<=n.right;e++){const t={left:e,right:e,top:n.top,bottom:n.bottom};i.push(this.createDataSet(r,t,s?{top:t.top,bottom:t.top,left:t.left,right:t.left}:void 0))}else n.left===n.right&&n.top===n.bottom?s||i.push(this.createDataSet(r,n,void 0)):i.push(this.createDataSet(r,n,s?{top:n.top,bottom:n.top,left:n.left,right:n.left}:void 0))}return i}addChartFigure(e,t,s){this.dispatch("CREATE_FIGURE",{sheetId:e,figure:s}),this.history.update("chartFigures",s.id,t)}createDataSet(e,t,s){if(t.left!==t.right&&t.top!==t.bottom)throw new Error(`Zone should be a single column or row: ${$s(t)}`);if(s){const i=$s(t),o=$s(s);return{labelCell:this.getters.getRangeFromSheetXC(e,o),dataRange:this.getters.getRangeFromSheetXC(e,i)}}return{labelCell:void 0,dataRange:this.getters.getRangeFromSheetXC(e,$s(t))}}checkEmptyDataset(e){return e.definition.dataSets&&0===e.definition.dataSets.length?27:0}checkDataset(e){if(!e.definition.dataSets)return 0;const t=void 0!==e.definition.dataSets.find((e=>!Jt.test(e)));return t?28:0}checkLabelRange(e){if(!e.definition.labelRange)return 0;return!Jt.test(e.definition.labelRange||"")?29:0}checkChartDuplicate(e){for(const t of this.getters.getSheets())if(this.getters.getFigure(t.id,e.id))return 57;return 0}checkChartExists(e){return this.getters.getFigure(e.sheetId,e.id)?0:58}}function Ia(e){return""===e?NaN:Number(e)}Ca.getters=["getChartDefinition","getChartDefinitionUI","getChartsIdBySheet"];class ya extends ma{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const s of this.cfRules[e])for(const i of s.ranges){const o=t(i);switch(o.changeType){case"REMOVE":let t=s.ranges.slice();t.splice(s.ranges.indexOf(i),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(s),"ranges",t):this.removeConditionalFormatting(s.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(s),"ranges",s.ranges.indexOf(i),o.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){return"ADD_CONDITIONAL_FORMAT"===e.type?this.checkValidations(e,this.checkCFRule,this.checkEmptyRange):0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const s={...e.cf,ranges:e.target.map($s)};this.addConditionalFormatting(s,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){this.export(e)}getConditionalFormats(e){return this.cfRules[e].map((t=>this.mapToConditionalFormat(e,t)))||[]}getRulesSelection(e,t){const s=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{s.add(e)}))})),Array.from(s)}getRulesByZone(e,t){const s=new Set;for(let i=t.top;i<=t.bottom;i++)for(let o=t.left;o<=t.right;o++){this.getRulesByCell(e,o,i).forEach((e=>{s.add(e.id)}))}return s}getRulesByCell(e,t,s){const i=[];for(let o of this.cfRules[e])for(let e of o.ranges)Hs(t,s,e.zone)&&i.push(o);return new Set(i.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e)))}}mapToConditionalFormatInternal(e,t){const s={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return s}addConditionalFormatting(e,t){const s=this.cfRules[t].slice(),i=s.findIndex((t=>t.id===e.id)),o=this.mapToConditionalFormatInternal(t,e);i>-1?s.splice(i,1,o):s.push(o),this.history.update("cfRules",t,s)}checkEmptyRange(e){return e.target.length?0:21}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return s=>{if(t.includes(s.operator)){const t=[],i=e=>void 0===e||""===e;return e>=1&&i(s.values[0])&&t.push(36),e>=2&&i(s.values[1])&&t.push(37),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 38;case"max":return 40;case"mid":return 39;case"upperInflectionPoint":return 41;case"lowerInflectionPoint":return 42}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{Br(Zr(e.value||""))}catch(e){switch(t){case"min":return 43;case"max":return 45;case"mid":return 44;case"upperInflectionPoint":return 46;case"lowerInflectionPoint":return 47}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,s=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(s)?33:0}checkMinBiggerThanMax(e){const t=e.minimum.value,s=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&Ia(t)>=Ia(s)?32:0}checkMidBiggerThanMax(e){var t;const s=null===(t=e.midpoint)||void 0===t?void 0:t.value,i=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&Ia(s)>=Ia(i)?34:0}checkMinBiggerThanMid(e){var t;const s=e.minimum.value,i=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&Ia(s)>=Ia(i)?35:0}removeConditionalFormatting(e,t){const s=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==s){const e=this.cfRules[t].slice();e.splice(s,1),this.history.update("cfRules",t,e)}}}ya.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class wa extends ma{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.getters.getFigures(e.sheetId).forEach((t=>{this.dispatch("DELETE_FIGURE",{id:t.id,sheetId:e.sheetId})})),this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:s,...i}=e,o=i;this.updateFigure(s,o);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[s,i]of Object.entries(t))switch(s){case"x":case"y":void 0!==i&&this.history.update("figures",e,t.id,s,Math.max(i,0));break;case"width":case"height":void 0!==i&&this.history.update("figures",e,t.id,s,i)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var s;return void 0===(null===(s=this.figures[e])||void 0===s?void 0:s[t])?55:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?56:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(Ls)}getFigure(e,t){var s;return null===(s=this.figures[e])||void 0===s?void 0:s[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var s;return void 0!==(null===(s=this.figures[t])||void 0===s?void 0:s[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const s=void 0;t.figures.push({...e,data:s})}}exportForExcel(e){this.export(e)}}wa.getters=["getFigures","getFigure","getFigureSheetId"];class Ta extends ma{constructor(){super(...arguments),this.nextId=1,this.pending=null,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?0:this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}beforeHandle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.exportAndRemoveMerges(e.sheetId,(t=>function(e,t){let{left:s,right:i,top:o,bottom:n}=ks(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)s>e&&(s-=1),(s>=e||i>=e)&&(i-=1);return s>i?null:is(s,o)+":"+is(i,n)}(t,e.elements)),!0):this.exportAndRemoveMerges(e.sheetId,(t=>function(e,t){let{left:s,right:i,top:o,bottom:n}=ks(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)o>e&&(o-=1),(o>=e||n>=e)&&(n-=1);return o>n?null:is(s,o)+":"+is(i,n)}(t,e.elements)),!1);break;case"ADD_COLUMNS_ROWS":const t="before"===e.position?e.base:e.base+1;"COL"===e.dimension?this.exportAndRemoveMerges(e.sheetId,(s=>function(e,t,s){let{left:i,right:o,top:n,bottom:r}=ks(e);return i>=t&&(i+=s),(i>=t||o>=t)&&(o+=s),i>o?null:is(i,n)+":"+is(o,r)}(s,t,e.quantity)),!0):this.exportAndRemoveMerges(e.sheetId,(s=>function(e,t,s){let{left:i,right:o,top:n,bottom:r}=ks(e);return n>=t&&(n+=s),(n>=t||r>=t)&&(r+=s),n>r?null:is(i,n)+":"+is(o,r)}(s,t,e.quantity)),!1)}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":this.history.update("merges",e.sheetIdTo,Object.assign({},this.merges[e.sheetId])),this.history.update("mergeCellMap",e.sheetIdTo,Object.assign({},this.mergeCellMap[e.sheetId]));break;case"ADD_MERGE":if(!e.interactive)for(const t of e.target)this.addMerge(this.getters.getSheet(e.sheetId),t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t);break;case"ADD_COLUMNS_ROWS":case"REMOVE_COLUMNS_ROWS":this.pending&&(this.importMerges(this.pending.sheet,this.pending.merges),this.pending=null)}}getMerges(e){return Object.values(this.merges[e]||{}).filter(Ls)}getMerge(e,t,s){var i;const o=this.mergeCellMap[e],n=o?t in o&&(null===(i=o[t])||void 0===i?void 0:i[s]):void 0;return n?this.getMergeById(e,n):void 0}doesIntersectMerge(e,t){const{left:s,right:i,top:o,bottom:n}=t;for(let t=o;t<=n;t++)for(let o=s;o<=i;o++)if(this.getMerge(e,o,t))return!0;return!1}doesColumnsHaveCommonMerges(e,t,s){const i=this.getters.getSheet(e);for(let e=0;e<i.rows.length;e++)if(this.isInSameMerge(i.id,t,e,s,e))return!0;return!1}doesRowsHaveCommonMerges(e,t,s){const i=this.getters.getSheet(e);for(let e=0;e<=i.cols.length;e++)if(this.isInSameMerge(i.id,e,t,e,s))return!0;return!1}expandZone(e,t){let{left:s,right:i,top:o,bottom:n}=t,r={left:s,right:i,top:o,bottom:n};for(let t in this.merges[e]){const s=this.getMergeById(e,parseInt(t));s&&Vs(s,r)&&(r=Ps(s,r))}return Bs(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,s,i,o){return!(!this.isInMerge(e,t,s)||!this.isInMerge(e,i,o))&&this.getMerge(e,t,s)===this.getMerge(e,i,o)}isInMerge(e,t,s){var i;const o=this.mergeCellMap[e];return!!o&&(t in o&&Boolean(null===(i=o[t])||void 0===i?void 0:i[s]))}getMainCell(e,t,s){if(!this.isInMerge(e,t,s))return[t,s];const i=this.getMerge(e,t,s).topLeft;return[i.col,i.row]}getBottomLeftCell(e,t,s){if(!this.isInMerge(e,t,s))return[t,s];const{bottom:i,left:o}=this.getMerge(e,t,s);return[o,i]}isMergeHidden(e,t){const s=this.getters.getHiddenColsGroups(e),i=this.getters.getHiddenRowsGroups(e);for(let e of s)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of i)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const s=this.getMerge(e,t.left,t.top);if(s)return Bs(t,s);const{width:i,height:o}=Ws(t);return 1===i&&1===o}isMergeDestructive(e,t){let{left:s,right:i,top:o,bottom:n}=t;i=ps(i,0,e.cols.length-1),n=ps(n,0,e.rows.length-1);for(let t=o;t<=n;t++){const n=this.getters.getRow(e.id,t);for(let e=s;e<=i;e++)if(e!==s||t!==o){const t=n.cells[e];if(t&&!t.isEmpty())return!0}}return!1}getMergeById(e,t){const s=this.merges[e];return void 0!==s?s[t]:void 0}checkDestructiveMerge({sheetId:e,target:t}){const s=this.getters.tryGetSheet(e);if(!s)return 0;return t.some((e=>this.isMergeDestructive(s,e)))?3:0}checkOverlap({target:e}){for(const t of e)for(const s of e)if(t!==s&&Vs(t,s))return 50;return 0}checkMergedContentUpdate(e){const{col:t,row:s,sheetId:i,content:o}=e;if(void 0===o)return 0;const[n,r]=this.getMainCell(i,t,s);return n===t&&r===s?0:4}checkMergeExists(e){const{sheetId:t,target:s}=e;for(const e of s){const{left:s,top:i}=e,o=this.getMerge(t,s,i);if(void 0===o||!Bs(e,o))return 5}return 0}addMerge(e,t){let{left:s,right:i,top:o,bottom:n}=t;i=ps(i,0,e.cols.length-1),n=ps(n,0,e.rows.length-1);if(is(s,o)===is(i,n))return;const r=this.getters.getCell(e.id,s,o);let a=this.nextId++;this.history.update("merges",e.id,a,{id:a,left:s,top:o,right:i,bottom:n,topLeft:{col:s,row:o}});let l=new Set;for(let t=o;t<=n;t++)for(let n=s;n<=i;n++){n===s&&t===o||this.dispatch("UPDATE_CELL",{sheetId:e.id,col:n,row:t,style:r?r.style:null,content:void 0});const i=this.getMerge(e.id,n,t);i&&l.add(i.id),this.history.update("mergeCellMap",e.id,n,t,a)}for(let t of l){const{top:s,bottom:i,left:o,right:n}=this.getMergeById(e.id,t);for(let t=s;t<=i;t++)for(let s=o;s<=n;s++){const i=this.getMerge(e.id,s,t);i&&i.id===a||(this.history.update("mergeCellMap",e.id,s,t,void 0),this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:t}))}this.history.update("merges",e.id,t,void 0)}}removeMerge(e,t){const{left:s,top:i,bottom:o,right:n}=t,r=this.getMerge(e,s,i);if(void 0!==r&&Bs(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=i;t<=o;t++)for(let i=s;i<=n;i++)this.history.update("mergeCellMap",e,i,t,void 0)}}removeAllMerges(e){for(let t in this.merges[e])this.history.update("merges",e,parseInt(t),void 0);for(let t in this.mergeCellMap[e])this.history.update("mergeCellMap",e,parseInt(t),void 0)}exportAndRemoveMerges(e,t,s){const i=this.merges[e];if(!i)return;const o=xa(i),n=[];for(let e of o){const s=t(e);if(s){const[e,t]=s.split(":");e!==t&&n.push(s)}}this.removeAllMerges(e),this.pending={sheet:e,merges:n}}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){const s=this.getters.getSheet(e);for(let e of t)this.addMerge(s,ks(e))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...xa(e))}}exportForExcel(e){this.export(e)}}function xa(e){return Object.values(e).filter(Ls).map((e=>is(e.left,e.top)+":"+is(e.right,e.bottom)))}Ta.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCell","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","isSingleCellOrMerge"];class Ra extends ma{constructor(){super(...arguments),this.sheetIds={},this.visibleSheets=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"MOVE_SHEET":const t=this.visibleSheets.findIndex((t=>t===e.sheetId));return"left"===e.direction&&0===t||"right"===e.direction&&t===this.visibleSheets.length-1?14:0;case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.visibleSheets.length>1?0:9;case"REMOVE_COLUMNS_ROWS":const s=this.getSheet(e.sheetId);return("COL"===e.dimension?s.cols.length:s.rows.length)>e.elements.length?0:8;case"HIDE_COLUMNS_ROWS":{const t=this.sheets[e.sheetId],s="COL"===e.dimension?t.hiddenColsGroups:t.hiddenRowsGroups,i="COL"===e.dimension?t.cols:t.rows;return(s||[]).flat().concat(e.elements).length<i.length?0:51}default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIds",t.name,t.id);break;case"RESIZE_COLUMNS_ROWS":const s="COL"===e.dimension?"cols":"rows";for(let t of e.elements)this.setHeaderSize(this.getSheet(e.sheetId),s,t,e.size);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.direction);break;case"RENAME_SHEET":e.interactive||this.renameSheet(this.sheets[e.sheetId],e.name);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],e.elements):this.removeRows(this.sheets[e.sheetId],e.elements);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"cols","hide"):this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"rows","hide");break;case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"cols","show"):this.setElementsVisibility(this.sheets[e.sheetId],e.elements,"rows","show");break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e)}}import(e){for(let t of e.sheets)this.sheetIds[t.name]=t.id;for(let t of e.sheets){const e=t.name||r("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:i}=this.getImportedSheetSize(t),o={id:t.id,name:e,cols:ei(t.cols||{},s),rows:ti(t.rows||{},i),hiddenColsGroups:[],hiddenRowsGroups:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible};this.visibleSheets.push(o.id),this.sheets[o.id]=o,this.updateHiddenElementsGroups(o.id,"cols"),this.updateHiddenElementsGroups(o.id,"rows")}}exportSheets(e,t=!1){e.sheets=this.visibleSheets.filter(Ls).map((e=>{const s=this.sheets[e];return{id:s.id,name:s.name,colNumber:s.cols.length,rowNumber:s.rows.length,rows:ii(s.rows,t),cols:si(s.cols,t),merges:[],cells:{},conditionalFormats:[],figures:[],areGridLinesVisible:void 0===s.areGridLinesVisible||s.areGridLinesVisible}}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e,!0)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const s=((t=e).startsWith("'")&&(t=t.slice(1,-1).replace(/''/g,"'")),t);for(const e in this.sheetIds)if(e.toUpperCase()===s.toUpperCase())return this.sheetIds[e]}var t}getSheets(){const{visibleSheets:e,sheets:t}=this;return e.map((e=>t[e])).filter(Ls)}getVisibleSheets(){return this.visibleSheets}getEvaluationSheets(){return this.sheets}getCol(e,t){var s;return null===(s=this.sheets[e])||void 0===s?void 0:s.cols[t]}getRow(e,t){var s;return null===(s=this.sheets[e])||void 0===s?void 0:s.rows[t]}getCell(e,t,s){const i=this.tryGetSheet(e);return i&&i.rows[s]&&i.rows[s].cells[t]||void 0}getColCells(e,t){return this.getSheet(e).rows.reduce(((e,s)=>{const i=s.cells[t];return void 0!==i?e.concat(i):e}),[])}getColsZone(e,t,s){return{top:0,bottom:this.getSheet(e).rows.length-1,left:t,right:s}}getRowsZone(e,t,s){return{top:t,bottom:s,left:0,right:this.getSheet(e).cols.length-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getHiddenColsGroups(e){var t;return(null===(t=this.sheets[e])||void 0===t?void 0:t.hiddenColsGroups)||[]}getHiddenRowsGroups(e){var t;return(null===(t=this.sheets[e])||void 0===t?void 0:t.hiddenRowsGroups)||[]}getNumberCols(e){return this.getSheet(e).cols.length}getNumberRows(e){return this.getSheet(e).rows.length}getNextSheetName(e="Sheet"){let t=1;const s=this.getSheets().map((e=>e.name));let i=`${e}${t}`;for(;s.includes(i);)i=`${e}${t}`,t++;return i}isEmpty(e,t){return Gs(t,this.getSheet(e),(e=>e),void 0).flat().every((e=>!e||e.isEmpty()))}setHeaderSize(e,t,s,i){let o,n;const r=e[t],a=r[s],l=i-a.size;this.history.update("sheets",e.id,t,s,"size",i),a.isHidden||this.history.update("sheets",e.id,t,s,"end",a.end+l),o=a.end;for(let i=s+1;i<r.length;i++){const s=r[i];n=s.isHidden?o:o+s.size,this.history.update("sheets",e.id,t,i,"start",o),this.history.update("sheets",e.id,t,i,"end",n),o=n}}updateCellPosition(e){if(e.cell){const t=this.cellPosition[e.cellId];t&&this.history.update("sheets",e.sheetId,"rows",t.row,"cells",t.col,void 0),this.history.update("cellPosition",e.cell.id,{row:e.row,col:e.col,sheetId:e.sheetId}),this.history.update("sheets",e.sheetId,"rows",e.row,"cells",e.col,e.cell)}else this.history.update("cellPosition",e.cellId,void 0),this.history.update("sheets",e.sheetId,"rows",e.row,"cells",e.col,void 0)}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let s of t)for(let t=s.left;t<=s.right;t++)for(let i=s.top;i<=s.bottom;i++){this.sheets[e].rows[i].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:i})}}createSheet(e,t,s,i,o){const n={id:e,name:t,cols:Qs(s),rows:Js(i),hiddenColsGroups:[],hiddenRowsGroups:[],areGridLinesVisible:!0},r=this.visibleSheets.slice();r.splice(o,0,n.id);const a=this.sheets;return this.history.update("visibleSheets",r),this.history.update("sheets",Object.assign({},a,{[n.id]:n})),n}moveSheet(e,t){const s=this.visibleSheets.slice(),i=s.findIndex((t=>t===e)),o=s.splice(i,1);s.splice(i+("left"===t?-1:1),0,o[0]),this.history.update("visibleSheets",s)}checkSheetName(e){const{visibleSheets:t,sheets:s}=this,i=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return(null===(t=s[e])||void 0===t?void 0:t.name.toLowerCase())===i}))?11:k.test(i)?13:0}checkSheetPosition(e){const{visibleSheets:t}=this;return e.position>t.length||e.position<0?15:0}isRenameAllowed(e){if(e.interactive)return 0;return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const s=e.name;this.history.update("sheets",e.id,"name",t.trim());const i=Object.assign({},this.sheetIds);i[t]=e.id,delete i[s],this.history.update("sheetIds",i)}duplicateSheet(e,t){const s=this.getSheet(e),i=this.getDuplicateSheetName(s.name),o=JSON.parse(JSON.stringify(s));o.id=t,o.name=i;for(let e=0;e<=o.cols.length;e++)for(let t=0;t<=o.rows.length;t++)o.rows[t]&&(o.rows[t].cells[e]=void 0);const n=this.visibleSheets.slice(),r=n.findIndex((t=>t===e));n.splice(r+1,0,o.id),this.history.update("visibleSheets",n),this.history.update("sheets",Object.assign({},this.sheets,{[o.id]:o}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:s}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:o.id,col:e,row:s,content:t.content,format:t.format,style:t.style})}const a=Object.assign({},this.sheetIds);a[o.name]=o.id,this.history.update("sheetIds",a)}getDuplicateSheetName(e){let t=1;const s=this.getters.getSheets().map((e=>e.name)),i=a("Copy of %s",e);let o=i.toString();for(;s.includes(o);)o=`${i} (${t})`,t++;return o}deleteSheet(e){const t=e.name,s=Object.assign({},this.sheets);delete s[e.id],this.history.update("sheets",s);const i=this.visibleSheets.slice(),o=i.findIndex((t=>t===e.id));i.splice(o,1),this.history.update("visibleSheets",i);const n=Object.assign({},this.sheetIds);delete n[t],this.history.update("sheetIds",n)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let s of t)this.moveCellOnColumnsDeletion(e,s);this.updateColumnsStructureOnDeletion(e,t)}removeRows(e,t){t.sort(((e,t)=>t-e));for(let s of ms(t))this.moveCellOnRowsDeletion(e,s[s.length-1],s[0]),s.map((t=>this.updateRowsStructureOnDeletion(t,e)))}addColumns(e,t,s,i){this.moveCellsOnAddition(e,"before"===s?t:t+1,i,"columns"),this.updateColumnsStructureOnAddition(e,t,i)}addRows(e,t,s,i){this.addEmptyRows(e,i),this.moveCellsOnAddition(e,"before"===s?t:t+1,i,"rows"),this.updateRowsStructureOnAddition(e,t,i)}moveCellOnColumnsDeletion(e,t){for(let[s,i]of Object.entries(e.rows)){const o=parseInt(s,10);for(let s in i.cells){const n=parseInt(s,10),r=i.cells[s];r&&(n===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:n,row:o}),n>t&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r.id,cell:r,col:n-1,row:o}))}}}moveCellsOnAddition(e,t,s,i){const o=[];for(const[n,r]of Object.entries(e.rows)){const a=parseInt(n,10);if("rows"!==i||a>=t)for(let n in r.cells){const l=parseInt(n,10),c=r.cells[n];c&&("rows"===i||l>=t)&&o.push({type:"UPDATE_CELL_POSITION",sheetId:e.id,cellId:c.id,cell:c,col:l+("columns"===i?s:0),row:a+("rows"===i?s:0)})}}for(let e of o.reverse())this.dispatch(e.type,e)}moveCellOnRowsDeletion(e,t,s){const i=s-t+1;for(let[o,n]of Object.entries(e.rows)){const r=parseInt(o,10);if(r>=t&&r<=s)for(let t in n.cells){const s=parseInt(t,10);n.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:r})}if(r>s)for(let t in n.cells){const s=parseInt(t,10),o=n.cells[t];o&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:o.id,cell:o,col:s,row:r-i})}}}updateColumnsStructureOnDeletion(e,t){const s=[];let i=0,o=0;for(let n in e.cols){if(t.includes(parseInt(n,10)))continue;const{size:r,isHidden:a}=e.cols[n],l=a?i:i+r;s.push({name:ts(o),size:r,start:i,end:l,isHidden:a}),i=l,o++}this.history.update("sheets",e.id,"cols",s),this.updateHiddenElementsGroups(e.id,"cols")}updateColumnsStructureOnAddition(e,t,s){const i=[];let o=0,n=0;for(let r in e.cols){if(parseInt(r,10)===t){const{size:t}=e.cols[n];for(let e=0;e<s;e++)i.push({name:ts(n),size:t,start:o,end:o+t}),o+=t,n++}const{size:a,isHidden:l}=e.cols[r],c=l?o:o+a;i.push({name:ts(n),size:a,start:o,end:c,isHidden:l}),o=c,n++}this.history.update("sheets",e.id,"cols",i),this.updateHiddenElementsGroups(e.id,"cols")}updateRowsStructureOnDeletion(e,t){const s=[];let i=0,o=0;const n=t.rows.map((e=>e.cells));for(let r in t.rows){const a=t.rows[r],{size:l,isHidden:c}=a,h=c?i:i+l;parseInt(r,10)!==e&&(o++,s.push({start:i,end:h,size:l,cells:n.shift(),name:String(o),isHidden:c}),i=h)}this.history.update("sheets",t.id,"rows",s),this.updateHiddenElementsGroups(t.id,"rows")}updateRowsStructureOnAddition(e,t,s){const i=[];let o=0,n=0,r=0;const a=e.rows.map((e=>e.cells));for(let l in e.rows){const{size:c,isHidden:h}=e.rows[r],d=h?o:o+c;(parseInt(l,10)<t||parseInt(l,10)>=t+s)&&r++,n++,i.push({start:o,end:d,size:c,cells:a.shift(),name:String(n),isHidden:h}),o=d}this.history.update("sheets",e.id,"rows",i),this.updateHiddenElementsGroups(e.id,"rows")}addEmptyRows(e,t){const s=e.rows[e.rows.length-1].end,i=e.rows.slice();for(let e=0;e<t;e++)i.push({start:s,end:s,size:0,name:(i.length+1).toString(),cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(ss);return{rowNumber:Math.max(e.rowNumber,_s(t.map((([e,t])=>t+1)))),colNumber:Math.max(e.colNumber,_s(t.map((([e,t])=>e+1))))}}setElementsVisibility(e,t,s,i){let o=0;const n="hide"===i;for(let i=0;i<e[s].length;i++){const{size:r,isHidden:a}=e[s][i],l=t.includes(i)?n:a||!1,c=l?o:o+r;this.history.update("sheets",e.id,s,i,"start",o),this.history.update("sheets",e.id,s,i,"end",c),this.history.update("sheets",e.id,s,i,"isHidden",l),o=c}this.updateHiddenElementsGroups(e.id,s)}updateHiddenElementsGroups(e,t){var s;const i="cols"===t?"hiddenColsGroups":"hiddenRowsGroups",o=((null===(s=this.sheets[e])||void 0===s?void 0:s[t])||[]).reduce(((e,t,s)=>{if(!t.isHidden)return e;const i=e[e.length-1];return i&&i[i.length-1]==s-1||e.push([]),e[e.length-1].push(s),e}),[]);this.history.update("sheets",e,i,o)}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?23:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),!t.every(Fs))return 22;if(t.length&&"sheetId"in e){const s=this.getSheet(e.sheetId),i={top:0,left:0,bottom:s.rows.length-1,right:s.cols.length-1};return t.every((e=>{return Bs(Ps(t=i,e),t);var t}))?0:18}return 0}}Ra.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheets","getVisibleSheets","getEvaluationSheets","getCol","getRow","getCell","getCellPosition","getColCells","getColsZone","getRowsZone","getNumberCols","getNumberRows","getHiddenColsGroups","getHiddenRowsGroups","getGridLinesVisibility","getNextSheetName","isEmpty"];const La=new Le;La.add("INCREMENT_MODIFIER",{apply:(e,t)=>{var s;e.current+=e.increment;const i=e.current.toString(),o=qr(e.current,null===(s=t.cell)||void 0===s?void 0:s.format);return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i},tooltip:i?{props:{content:o}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,s)=>{var i,o;const n=(null===(i=t.cell)||void 0===i?void 0:i.content)||"";return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:n},tooltip:n?{props:{content:null===(o=t.cell)||void 0===o?void 0:o.formattedValue}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,s,i)=>{e.current+=e.increment;let o=0,n=0;switch(i){case 0:o=0,n=-e.current;break;case 1:o=0,n=e.current;break;case 2:o=-e.current,n=0;break;case 3:o=e.current,n=0}if(!t.cell||!t.cell.isFormula())return{cellData:{}};const r=t.sheetId,a=s.createAdaptedRanges(t.cell.dependencies.references,o,n,r),l=s.buildFormulaContent(r,t.cell.normalizedText,{...t.cell.dependencies,references:a});return{cellData:{border:t.border,style:t.cell.style,format:t.cell.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const Aa=new Le;Aa.add("simple_value_copy",{condition:(e,t)=>{var s;return 1===t.length&&!e.isFormula()&&!(null===(s=e.format)||void 0===s?void 0:s.match(M))},generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("copy_text",{condition:e=>!e.isFormula()&&e.evaluated.type===ke.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.evaluated.type===ke.number,generateRule:(e,t)=>{const s=function(e,t){let s=[],i=!1;for(let o of t)if(o===e&&(i=!0),(null==o?void 0:o.evaluated.type)===ke.number)s.push(o.evaluated.value);else{if(i)return s;s=[]}return s}(e,t);let i=1;return 2==s.length?i=2*(s[1]-s[0]):s.length>2&&(i=function(e){const t=[];let s=e[0];for(let i=1;i<e.length;i++){const o=e[i];t.push(o-s),s=o}return t.reduce(((e,t)=>e+t),0)/t.length}(s)*s.length),{type:"INCREMENT_MODIFIER",increment:i,current:e.evaluated.type===ke.number?e.evaluated.value:0}},sequence:40});const Ma=new Le,_a=(new Le).add("ADD_COLUMNS_ROWS",(function(e){const t=[];let s=e.base;"after"===e.position&&s++;for(let i=0;i<e.quantity;i++)t.push(i+s);return[{type:"REMOVE_COLUMNS_ROWS",dimension:e.dimension,elements:t,sheetId:e.sheetId}]})).add("REMOVE_COLUMNS_ROWS",(function(e){const t=[],s=[...e.elements].sort(((e,t)=>e-t));for(let i of ms(s)){const s=0===i[0]?0:i[0]-1,o=0===i[0]?"before":"after";t.push({type:"ADD_COLUMNS_ROWS",dimension:e.dimension,quantity:i.length,base:s,sheetId:e.sheetId,position:o})}return t})).add("ADD_MERGE",(function(e){return[{type:"REMOVE_MERGE",sheetId:e.sheetId,target:e.target}]})).add("REMOVE_MERGE",(function(e){return[{type:"ADD_MERGE",sheetId:e.sheetId,target:e.target}]})).add("CREATE_SHEET",(function(e){return[{type:"DELETE_SHEET",sheetId:e.sheetId}]})).add("DELETE_SHEET",(function(e){return[{type:"CREATE_SHEET",sheetId:e.sheetId,position:1}]})).add("DUPLICATE_SHEET",(function(e){return[{type:"DELETE_SHEET",sheetId:e.sheetIdTo}]})).add("CREATE_FIGURE",(function(e){return[{type:"DELETE_FIGURE",id:e.figure.id,sheetId:e.sheetId}]})).add("CREATE_CHART",(function(e){return[{type:"DELETE_FIGURE",id:e.id,sheetId:e.sheetId}]})).add("HIDE_COLUMNS_ROWS",(function(e){return[{type:"UNHIDE_COLUMNS_ROWS",sheetId:e.sheetId,dimension:e.dimension,elements:e.elements}]})).add("UNHIDE_COLUMNS_ROWS",(function(e){return[{type:"HIDE_COLUMNS_ROWS",sheetId:e.sheetId,dimension:e.dimension,elements:e.elements}]}));for(const e of De.values())_a.contains(e)||_a.add(e,Oa);function Oa(e){return[e]}const Na=e=>({isVisible:()=>!0,isEnabled:()=>!0,isReadonlyAllowed:!1,shortCut:"",action:!1,children:[],separator:!1,icon:!1,id:e});function ka(e,t){return Object.assign({},Na(e),t)}class Fa extends Le{add(e,t){return this.content[e]=ka(e,t),this}addChild(e,t,s){const i=t.splice(0,1)[0];let o=this.content[i];if(!o)throw new Error(`Path ${i+":"+t.join(":")} not found`);for(let e of t)if(o="function"==typeof o.children?void 0:o.children.find((t=>t.id===e)),!o)throw new Error(`Path ${i+":"+t.join(":")} not found`);return o.children.push(ka(e,s)),this}getChildren(e,t){return"function"==typeof e.children?e.children(t).sort(((e,t)=>e.sequence-t.sequence)):e.children.sort(((e,t)=>e.sequence-t.sequence))}getName(e,t){return"function"==typeof e.name?e.name(t):e.name}getShortCut(e){return e.shortCut?e.shortCut:""}getAll(){return super.getAll().sort(((e,t)=>e.sequence-t.sequence))}}function $a(e){const t=e.getters.getActiveCols();if(t.size)return t.size;{const t=e.getters.getSelectedZones()[0];return t.right-t.left+1}}function Da(e){const t=e.getters.getActiveRows();if(t.size)return t.size;{const t=e.getters.getSelectedZones()[0];return t.bottom-t.top+1}}function Ua(e,t){e.dispatch("SET_FORMATTING",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones(),format:t})}function Pa(e,t){e.dispatch("SET_FORMATTING",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones(),style:t})}const Ba=async e=>{e.dispatch("COPY",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Va=async e=>{e.dispatch("CUT",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Ha=async e=>{const t=e.getters.getClipboardContent();let s;try{s=await e.clipboard.readText()}catch(e){console.warn("The OS clipboard could not be read."),console.error(e)}const i=e.getters.getSelectedZones();s&&s!==t?e.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:i,text:s}):e.dispatch("PASTE",{target:i,interactive:!0})},za=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),pasteOption:"onlyValue"}),Za=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),pasteOption:"onlyFormat"}),Ga=e=>e.dispatch("DELETE_CONTENT",{sheetId:e.getters.getActiveSheetId(),target:e.getters.getSelectedZones()}),Wa=e=>{let t,s;const i=e.getters.getActiveRows();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.top,s=i.bottom}return t===s?a("Delete row %s",(t+1).toString()):a("Delete rows %s - %s",(t+1).toString(),(s+1).toString())},qa=e=>{let t=[...e.getters.getActiveRows()];if(!t.length){const s=e.getters.getSelectedZones()[0];for(let e=s.top;e<=s.bottom;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},ja=e=>{let t,s;const i=e.getters.getActiveCols();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.left,s=i.right}return t===s?a("Delete column %s",ts(t)):a("Delete columns %s - %s",ts(t),ts(s))},Ya=e=>{let t=[...e.getters.getActiveCols()];if(!t.length){const s=e.getters.getSelectedZones()[0];for(let e=s.left;e<=s.right;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},Xa=e=>{const t=e.getters.getSelectedZone();e.dispatch("INSERT_CELL",{shiftDimension:"ROW",zone:t,interactive:!0})},Ka=e=>{const t=e.getters.getSelectedZone();e.dispatch("INSERT_CELL",{shiftDimension:"COL",zone:t,interactive:!0})},Qa=e=>{const t=e.getters.getSelectedZone();e.dispatch("DELETE_CELL",{shiftDimension:"ROW",zone:t,interactive:!0})},Ja=e=>{const t=e.getters.getSelectedZone();e.dispatch("DELETE_CELL",{shiftDimension:"COL",zone:t,interactive:!0})},el=e=>{const t=e.getters.getActiveRows();let s,i;if(t.size)s=Os([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.top,i=t.bottom-t.top+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"before",base:s,quantity:i,dimension:"ROW"})},tl=e=>{const t=e.getters.getActiveRows();let s,i;if(t.size)s=_s([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.bottom,i=t.bottom-t.top+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"after",base:s,quantity:i,dimension:"ROW"})},sl=e=>{const t=e.getters.getActiveCols();let s,i;if(t.size)s=Os([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.left,i=t.right-t.left+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"before",dimension:"COL",base:s,quantity:i})},il=e=>{const t=e.getters.getActiveCols();let s,i;if(t.size)s=_s([...t]),i=t.size;else{const t=e.getters.getSelectedZones()[0];s=t.right,i=t.right-t.left+1}e.dispatch("ADD_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),position:"after",dimension:"COL",base:s,quantity:i})},ol=e=>{e.openSidePanel("ConditionalFormatting",{selection:e.getters.getSelectedZones()})},nl=e=>{e.openLinkEditor()},rl=e=>{const{anchor:t,zones:s}=e.getters.getSelection();e.dispatch("SORT_CELLS",{interactive:!0,sheetId:e.getters.getActiveSheetId(),anchor:t,zone:s[0],sortDirection:"ascending"})},al=e=>{const{anchor:t,zones:s}=e.getters.getSelection();e.dispatch("SORT_CELLS",{interactive:!0,sheetId:e.getters.getActiveSheetId(),anchor:t,zone:s[0],sortDirection:"descending"})},ll=e=>1===e.getters.getSelectedZones().length,cl=new Fa;cl.add("cut",{name:a("Cut"),shortCut:"Ctrl+X",sequence:10,action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha,isVisible:ll}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0,isVisible:ll}).addChild("paste_value_only",["paste_special"],{name:a("Paste values only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("sort_range",{name:a("Sort range"),sequence:50,isVisible:ll,separator:!0}).addChild("sort_ascending",["sort_range"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["sort_range"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).add("add_row_before",{name:e=>{const t=Da(e);return 1===t?a("Insert row"):a("Insert %s rows",t.toString())},sequence:70,action:el,isVisible:ll}).add("add_column_before",{name:e=>{const t=$a(e);return 1===t?a("Insert column"):a("Insert %s columns",t.toString())},sequence:90,action:sl,isVisible:ll}).add("insert_cell",{name:a("Insert cells"),sequence:100,isVisible:ll,separator:!0}).addChild("insert_cell_down",["insert_cell"],{name:a("Shift down"),sequence:10,action:Xa}).addChild("insert_cell_right",["insert_cell"],{name:a("Shift right"),sequence:20,action:Ka}).add("delete_row",{name:Wa,sequence:110,action:qa,isVisible:ll}).add("delete_column",{name:ja,sequence:120,action:Ya,isVisible:ll}).add("delete_cell",{name:a("Delete cells"),sequence:130,isVisible:ll}).addChild("delete_cell_up",["delete_cell"],{name:a("Shift up"),sequence:10,action:Qa}).addChild("delete_cell_down",["delete_cell"],{name:a("Shift left"),sequence:20,action:Ja}).add("clear_cell",{name:a("Clear cells"),sequence:140,action:Ga,isEnabled:e=>{const t=e.getters.getActiveCell();return Boolean(t)},separator:!0}).add("insert_link",{name:a("Insert link"),separator:!0,sequence:150,action:nl}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:160,action:ol,separator:!0});const hl=new Fa;hl.add("cut",{name:a("Cut"),shortCut:"Ctrl+X",sequence:10,action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("sort_columns",{name:e=>e.getters.getActiveCols().size>1?a("Sort columns"):a("Sort column"),sequence:50,isVisible:ll,separator:!0}).addChild("sort_ascending",["sort_columns"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["sort_columns"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).add("add_column_before",{name:e=>{const t=$a(e);return 1===t?a("Insert column left"):a("Insert %s columns left",t.toString())},sequence:70,action:sl}).add("add_column_after",{name:e=>{const t=$a(e);return 1===t?a("Insert column right"):a("Insert %s columns right",t.toString())},sequence:80,action:il}).add("delete_column",{name:ja,sequence:90,action:Ya}).add("clear_column",{name:e=>{let t,s;const i=e.getters.getActiveCols();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.left,s=i.right}return t===s?a("Clear column %s",ts(t)):a("Clear columns %s - %s",ts(t),ts(s))},sequence:100,action:e=>{const t=e.getters.getActiveSheetId(),s=[...e.getters.getActiveCols()].map((s=>e.getters.getColsZone(t,s,s)));e.dispatch("DELETE_CONTENT",{target:s,sheetId:e.getters.getActiveSheetId()})}}).add("hide_columns",{name:e=>{const t=e.getters.getElementsFromSelection("COL");let s=t[0],i=t[t.length-1];return 1===t.length?a("Hide column %s",ts(s).toString()):i-s+1===t.length?a("Hide columns %s - %s",ts(s).toString(),ts(i).toString()):a("Hide columns")},sequence:85,action:e=>{const t=e.getters.getElementsFromSelection("COL");e.dispatch("HIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},isVisible:e=>{const t=e.getters.getActiveSheet(),s=e.getters.getHiddenColsGroups(t.id).flat();return t.cols.length>s.length+e.getters.getElementsFromSelection("COL").length},separator:!0}).add("unhide_columns",{name:"Unhide columns",sequence:86,action:e=>{const t=e.getters.getElementsFromSelection("COL");e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"COL",elements:t})},isVisible:e=>{const t=e.getters.getHiddenColsGroups(e.getters.getActiveSheetId()).flat();return e.getters.getElementsFromSelection("COL").some((e=>t.includes(e)))},separator:!0}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:110,action:ol});const dl=new Fa;dl.add("sheet",{name:a("Link sheet"),sequence:10,children:e=>e.getters.getSheets().map(((e,t)=>ka(e.id,{name:e.name,sequence:t,action:()=>{return{link:{label:e.name,url:(t=e.id,`${Ts}${t}`)},urlRepresentation:e.name,isUrlEditable:!1};var t}})))});const ul=new Fa;ul.add("cut",{name:a("Cut"),sequence:10,shortCut:"Ctrl+X",action:Va}).add("copy",{name:a("Copy"),shortCut:"Ctrl+C",sequence:20,isReadonlyAllowed:!0,action:Ba}).add("paste",{name:a("Paste"),shortCut:"Ctrl+V",sequence:30,action:Ha}).add("paste_special",{name:a("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_format_only",["paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).add("add_row_before",{name:e=>{const t=Da(e);return 1===t?a("Insert row above"):a("Insert %s rows above",t.toString())},sequence:50,action:el}).add("add_row_after",{name:e=>{const t=Da(e);return 1===t?a("Insert row below"):a("Insert %s rows below",t.toString())},sequence:60,action:tl}).add("delete_row",{name:Wa,sequence:70,action:qa}).add("clear_row",{name:e=>{let t,s;const i=e.getters.getActiveRows();if(0!==i.size)t=Os([...i]),s=_s([...i]);else{const i=e.getters.getSelectedZones()[0];t=i.top,s=i.bottom}return t===s?a("Clear row %s",(t+1).toString()):a("Clear rows %s - %s",(t+1).toString(),(s+1).toString())},sequence:80,action:e=>{const t=e.getters.getActiveSheetId(),s=[...e.getters.getActiveRows()].map((s=>e.getters.getRowsZone(t,s,s)));e.dispatch("DELETE_CONTENT",{target:s,sheetId:e.getters.getActiveSheetId()})}}).add("hide_rows",{name:e=>{const t=e.getters.getElementsFromSelection("ROW");let s=t[0],i=t[t.length-1];return 1===t.length?a("Hide row %s",(s+1).toString()):i-s+1===t.length?a("Hide rows %s - %s",(s+1).toString(),(i+1).toString()):a("Hide rows")},sequence:85,action:e=>{const t=e.getters.getElementsFromSelection("ROW");e.dispatch("HIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},isVisible:e=>{const t=e.getters.getActiveSheet(),s=e.getters.getHiddenRowsGroups(t.id).flat();return t.rows.length>s.length+e.getters.getElementsFromSelection("ROW").length},separator:!0}).add("unhide_rows",{name:"Unhide rows",sequence:86,action:e=>{const t=e.getters.getElementsFromSelection("ROW");e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:e.getters.getActiveSheetId(),dimension:"ROW",elements:t})},isVisible:e=>{const t=e.getters.getHiddenRowsGroups(e.getters.getActiveSheetId()).flat();return e.getters.getElementsFromSelection("ROW").some((e=>t.includes(e)))},separator:!0}).add("conditional_formatting",{name:a("Conditional formatting"),sequence:90,action:ol});const pl=new Fa;pl.add("delete",{name:a("Delete"),sequence:10,isVisible:e=>e.getters.getSheets().length>1,action:e=>e.dispatch("DELETE_SHEET_CONFIRMATION",{sheetId:e.getters.getActiveSheetId()})}).add("duplicate",{name:a("Duplicate"),sequence:20,action:e=>{const t=e.getters.getActiveSheetId(),s=e.uuidGenerator.uuidv4();e.dispatch("DUPLICATE_SHEET",{sheetId:t,sheetIdTo:s}),e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:s})}}).add("rename",{name:a("Rename"),sequence:30,action:e=>e.dispatch("RENAME_SHEET",{interactive:!0,sheetId:e.getters.getActiveSheetId()})}).add("move_right",{name:a("Move right"),sequence:40,isVisible:e=>{const t=e.getters.getActiveSheetId(),s=e.getters.getSheets();return s.findIndex((e=>e.id===t))!==s.length-1},action:e=>e.dispatch("MOVE_SHEET",{sheetId:e.getters.getActiveSheetId(),direction:"right"})}).add("move_left",{name:a("Move left"),sequence:50,isVisible:e=>{const t=e.getters.getActiveSheetId();return 0!==e.getters.getSheets().findIndex((e=>e.id===t))},action:e=>e.dispatch("MOVE_SHEET",{sheetId:e.getters.getActiveSheetId(),direction:"left"})});const gl=new Fa;gl.add("file",{name:a("File"),sequence:10}).add("edit",{name:a("Edit"),sequence:20}).add("view",{name:a("View"),sequence:30}).add("insert",{name:a("Insert"),sequence:40}).add("format",{name:a("Format"),sequence:50}).add("data",{name:a("Data"),sequence:60}).addChild("save",["file"],{name:a("Save"),shortCut:"Ctrl+S",sequence:10,action:()=>console.log("Not implemented")}).addChild("undo",["edit"],{name:a("Undo"),shortCut:"Ctrl+Z",sequence:10,action:e=>e.dispatch("REQUEST_UNDO")}).addChild("redo",["edit"],{name:a("Redo"),shortCut:"Ctrl+Y",sequence:20,action:e=>e.dispatch("REQUEST_REDO"),separator:!0}).addChild("copy",["edit"],{name:a("Copy"),shortCut:"Ctrl+C",sequence:30,isReadonlyAllowed:!0,action:Ba}).addChild("cut",["edit"],{name:a("Cut"),shortCut:"Ctrl+X",sequence:40,action:Va}).addChild("paste",["edit"],{name:a("Paste"),shortCut:"Ctrl+V",sequence:50,action:Ha}).addChild("paste_special",["edit"],{name:a("Paste special"),sequence:60,separator:!0}).addChild("paste_special_value",["edit","paste_special"],{name:a("Paste value only"),sequence:10,action:za}).addChild("paste_special_format",["edit","paste_special"],{name:a("Paste format only"),sequence:20,action:Za}).addChild("sort_range",["edit"],{name:a("Sort range"),sequence:62,isVisible:ll,separator:!0}).addChild("sort_ascending",["edit","sort_range"],{name:a("Ascending (A ⟶ Z)"),sequence:10,action:rl}).addChild("sort_descending",["edit","sort_range"],{name:a("Descending (Z ⟶ A)"),sequence:20,action:al}).addChild("find_and_replace",["edit"],{name:a("Find and replace"),shortCut:"Ctrl+H",sequence:65,isReadonlyAllowed:!0,action:e=>{e.openSidePanel("FindAndReplace",{})},separator:!0}).addChild("edit_delete_cell_values",["edit"],{name:a("Delete values"),sequence:70,action:Ga}).addChild("edit_delete_row",["edit"],{name:Wa,sequence:80,action:qa}).addChild("edit_delete_column",["edit"],{name:ja,sequence:90,action:Ya}).addChild("edit_delete_cell_shift_up",["edit"],{name:a("Delete cell and shift up"),sequence:93,action:Qa}).addChild("edit_delete_cell_shift_left",["edit"],{name:a("Delete cell and shift left"),sequence:97,action:Ja}).addChild("edit_unhide_columns",["edit"],{name:a("Unhide all columns"),sequence:100,action:e=>{const t=e.getters.getActiveSheet();e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:t.id,dimension:"COL",elements:Array.from(Array(t.cols.length).keys())})},isVisible:e=>e.getters.getHiddenColsGroups(e.getters.getActiveSheetId()).length>0}).addChild("edit_unhide_rows",["edit"],{name:a("Unhide all rows"),sequence:100,action:e=>{const t=e.getters.getActiveSheet();e.dispatch("UNHIDE_COLUMNS_ROWS",{sheetId:t.id,dimension:"ROW",elements:Array.from(Array(t.rows.length).keys())})},isVisible:e=>e.getters.getHiddenRowsGroups(e.getters.getActiveSheetId()).length>0}).addChild("insert_row_before",["insert"],{name:e=>{const t=Da(e);return 1===t?a("Row above"):a("%s Rows above",t.toString())},sequence:10,action:el,isVisible:e=>0===e.getters.getActiveCols().size}).addChild("insert_row_after",["insert"],{name:e=>{const t=Da(e);return 1===t?a("Row below"):a("%s Rows below",t.toString())},sequence:20,action:tl,isVisible:e=>0===e.getters.getActiveCols().size,separator:!0}).addChild("insert_column_before",["insert"],{name:e=>{const t=$a(e);return 1===t?a("Column left"):a("%s Columns left",t.toString())},sequence:30,action:sl,isVisible:e=>0===e.getters.getActiveRows().size}).addChild("insert_column_after",["insert"],{name:e=>{const t=$a(e);return 1===t?a("Column right"):a("%s Columns right",t.toString())},sequence:40,action:il,isVisible:e=>0===e.getters.getActiveRows().size,separator:!0}).addChild("insert_insert_cell_shift_down",["insert"],{name:a("Insert cells and shift down"),sequence:43,action:Xa}).addChild("insert_insert_cell_shift_right",["insert"],{name:a("Insert cells and shift right"),sequence:47,action:Ka,separator:!0}).addChild("insert_chart",["insert"],{name:a("Chart"),sequence:50,action:e=>{var t,s;const i=e.getters.getSelectedZone();let o=i;const n=e.uuidGenerator.uuidv4();let r;i.left!==i.right&&(o={...i,left:i.left+1});const a=[$s(o)],l=e.getters.getActiveSheetId(),c={x:(null===(t=e.getters.getCol(l,i.right+1))||void 0===t?void 0:t.start)||0,y:(null===(s=e.getters.getRow(l,i.top))||void 0===s?void 0:s.start)||0};let h=!1;for(let t=o.left;t<=o.right;t++){const s=e.getters.getCell(l,t,i.top);if(s&&s.evaluated.type!==ke.number){h=!0;break}}i.left!==i.right&&(r=$s({...i,right:i.left,top:h?i.top+1:i.top})),e.dispatch("CREATE_CHART",{sheetId:l,id:n,position:c,definition:{title:"",dataSets:a,labelRange:r,type:"bar",stackedBar:!1,dataSetsHaveTitle:h,background:g,verticalAxisPosition:"left",legendPosition:"top"}});const d=e.getters.getFigure(l,n);e.openSidePanel("ChartPanel",{figure:d})}}).addChild("insert_link",["insert"],{name:a("Link"),separator:!0,sequence:60,action:nl}).addChild("insert_sheet",["insert"],{name:a("New sheet"),sequence:70,action:e=>{const t=e.getters.getActiveSheetId(),s=e.getters.getVisibleSheets().findIndex((e=>e===t))+1,i=e.uuidGenerator.uuidv4();e.dispatch("CREATE_SHEET",{sheetId:i,position:s}),e.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:i})},separator:!0}).addChild("view_gridlines",["view"],{name:e=>e.getters.getGridLinesVisibility(e.getters.getActiveSheetId())?a("Hide gridlines"):a("Show gridlines"),action:e=>{const t=e.getters.getActiveSheetId();e.dispatch("SET_GRID_LINES_VISIBILITY",{sheetId:t,areGridLinesVisible:!e.getters.getGridLinesVisibility(t)})},sequence:5,separator:!0}).addChild("view_formulas",["view"],{name:e=>e.getters.shouldShowFormulas()?a("Hide formulas"):a("Show formulas"),action:e=>e.dispatch("SET_FORMULA_VISIBILITY",{show:!e.getters.shouldShowFormulas()}),isReadonlyAllowed:!0,sequence:10}).addChild("format_number",["format"],{name:a("Numbers"),sequence:10,separator:!0}).addChild("format_number_general",["format","format_number"],{name:a("General"),sequence:10,separator:!0,action:e=>Ua(e,"")}).addChild("format_number_number",["format","format_number"],{name:a("Number (1,000.12)"),sequence:20,action:e=>Ua(e,"#,##0.00")}).addChild("format_number_percent",["format","format_number"],{name:a("Percent (10.12%)"),sequence:30,separator:!0,action:e=>Ua(e,"0.00%")}).addChild("format_number_date",["format","format_number"],{name:a("Date (9/26/2008)"),sequence:40,action:e=>Ua(e,"m/d/yyyy")}).addChild("format_number_time",["format","format_number"],{name:a("Time (10:43:00 PM)"),sequence:50,action:e=>Ua(e,"hh:mm:ss a")}).addChild("format_number_date_time",["format","format_number"],{name:a("Date time (9/26/2008 22:43:00)"),sequence:60,action:e=>Ua(e,"m/d/yyyy hh:mm:ss")}).addChild("format_number_duration",["format","format_number"],{name:a("Duration (27:51:38)"),sequence:70,separator:!0,action:e=>Ua(e,"hhhh:mm:ss")}).addChild("format_bold",["format"],{name:a("Bold"),sequence:20,shortCut:"Ctrl+B",action:e=>Pa(e,{bold:!e.getters.getCurrentStyle().bold})}).addChild("format_italic",["format"],{name:a("Italic"),sequence:30,shortCut:"Ctrl+I",action:e=>Pa(e,{italic:!e.getters.getCurrentStyle().italic})}).addChild("format_underline",["format"],{name:a("Underline"),shortCut:"Ctrl+U",sequence:40,action:e=>Pa(e,{underline:!e.getters.getCurrentStyle().underline})}).addChild("format_strikethrough",["format"],{name:a("Strikethrough"),sequence:50,action:e=>Pa(e,{strikethrough:!e.getters.getCurrentStyle().strikethrough}),separator:!0}).addChild("format_font_size",["format"],{name:a("Font size"),sequence:60,separator:!0}).addChild("format_cf",["format"],{name:a("Conditional formatting"),sequence:70,action:ol,separator:!0});for(let e of ls)gl.addChild(`format_font_size_${e.pt}`,["format","format_font_size"],{name:e.pt.toString(),sequence:e.pt,action:t=>Pa(t,{fontSize:e.pt})});const fl=new class extends Le{addTransformation(e,t,s){for(let i of t)this.content[i]||(this.content[i]=new Map),this.content[i].set(e,s);return this}getTransformation(e,t){return this.content[e]&&this.content[e].get(t)}},{css:ml,xml:vl}=t.tags,El=[["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#f3f3f3","#ffffff"],["#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff"],["#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc"],["#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd"],["#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"],["#a61c00","#cc0000","#e69138","#f1c232","#6aa84f","#45818e","#3c78d8","#3d85c6","#674ea7","#a64d79"],["#85200c","#990000","#b45f06","#bf9000","#38761d","#134f5c","#1155cc","#0b5394","#351c75","#741b47"],["#5b0f00","#660000","#783f04","#7f6000","#274e13","#0c343d","#1c4587","#073763","#20124d","#4c1130"]],Sl=24*Math.max(...El.map((e=>e.length)))+12;class bl extends t.Component{constructor(){super(...arguments),this.COLORS=El}onColorClick(e){const t=e.target.dataset.color;t&&this.trigger("color-picked",{color:t})}}bl.template=vl`
|
|
2
2
|
<div class="o-color-picker"
|
|
3
3
|
t-att-class="props.dropdownDirection || 'right'"
|
|
4
4
|
t-on-click="onColorClick">
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<div class="o-color-picker-line-item" t-att-data-color="color" t-attf-style="background-color:{{color}};"></div>
|
|
8
8
|
</t>
|
|
9
9
|
</div>
|
|
10
|
-
</div>`,
|
|
10
|
+
</div>`,bl.style=ml`
|
|
11
11
|
.o-color-picker {
|
|
12
12
|
position: absolute;
|
|
13
13
|
top: calc(100% + 5px);
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
right: 0;
|
|
42
42
|
}
|
|
43
43
|
&.center {
|
|
44
|
-
left: calc(50% - ${
|
|
44
|
+
left: calc(50% - ${Sl/2}px);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
`;const Cl='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 8 0" transform="translate(5 7)"/></svg>',Il='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 0 8" transform="translate(5 5)"/></svg>',yl='<svg class="o-icon"><path fill="#000000" fill-rule="evenodd" d="M9,3.5 C9,1.57 7.43,0 5.5,0 L1.77635684e-15,0 L1.77635684e-15,12 L6.25,12 C8.04,12 9.5,10.54 9.5,8.75 C9.5,7.45 8.73,6.34 7.63,5.82 C8.46,5.24 9,4.38 9,3.5 Z M5,2 C5.82999992,2 6.5,2.67 6.5,3.5 C6.5,4.33 5.82999992,5 5,5 L3,5 L3,2 L5,2 Z M3,10 L3,7 L5.5,7 C6.32999992,7 7,7.67 7,8.5 C7,9.33 6.32999992,10 5.5,10 L3,10 Z" transform="translate(4 3)"/></svg>',wl='<svg class="o-icon"><polygon fill="#000000" fill-rule="evenodd" points="4 0 4 2 6.58 2 2.92 10 0 10 0 12 8 12 8 10 5.42 10 9.08 2 12 2 12 0" transform="translate(3 3)"/></svg>',Tl='<svg class="o-icon"><path fill="#010101" fill-rule="evenodd" d="M2.8875,3.06 C2.8875,2.6025 2.985,2.18625 3.18375,1.8075 C3.3825,1.42875 3.66,1.10625 4.02,0.84 C4.38,0.57375 4.80375,0.3675 5.29875,0.22125 C5.79375,0.075 6.33375,0 6.92625,0 C7.53375,0 8.085,0.0825 8.58,0.25125 C9.075,0.42 9.49875,0.6525 9.85125,0.95625 C10.20375,1.25625 10.47375,1.6125 10.665,2.02875 C10.85625,2.44125 10.95,2.895 10.95,3.38625 L8.6925,3.38625 C8.6925,3.1575 8.655,2.94375 8.58375,2.74875 C8.5125,2.55 8.4,2.38125 8.25,2.2425 C8.1,2.10375 7.9125,1.99125 7.6875,1.91625 C7.4625,1.8375 7.19625,1.8 6.88875,1.8 C6.5925,1.8 6.3375,1.83375 6.11625,1.8975 C5.89875,1.96125 5.71875,2.05125 5.57625,2.1675 C5.43375,2.28375 5.325,2.41875 5.25375,2.5725 C5.1825,2.72625 5.145,2.895 5.145,3.0675 C5.145,3.4275 5.32875,3.73125 5.69625,3.975 C5.71780203,3.98908066 5.73942012,4.00311728 5.76118357,4.01733315 C6.02342923,4.18863185 6.5,4.5 7,5 L4,5 C4,5 3.21375,4.37625 3.17625,4.30875 C2.985,3.9525 2.8875,3.53625 2.8875,3.06 Z M14,6 L0,6 L0,8 L7.21875,8 C7.35375,8.0525 7.51875,8.105 7.63125,8.15375 C7.90875,8.2775 8.12625,8.40875 8.28375,8.53625 C8.44125,8.6675 8.54625,8.81 8.6025,8.96 C8.65875,9.11375 8.685,9.28625 8.685,9.47375 C8.685,9.65 8.65125,9.815 8.58375,9.965 C8.51625,10.11875 8.41125,10.25 8.2725,10.35875 C8.13375,10.4675 7.95375,10.55375 7.74,10.6175 C7.5225,10.68125 7.27125,10.71125 6.97875,10.71125 C6.6525,10.71125 6.35625,10.6775 6.09,10.61375 C5.82375,10.55 5.59875,10.445 5.41125,10.3025 C5.22375,10.16 5.0775,9.9725 4.9725,9.74375 C4.8675,9.515 4.78125,9.17 4.78125,9 L2.55,9 C2.55,9.2525 2.61,9.6875 2.72625,10.025 C2.8425,10.3625 3.0075,10.66625 3.21375,10.9325 C3.42,11.19875 3.6675,11.4275 3.94875,11.6225 C4.23,11.8175 4.53375,11.9825 4.86375,12.11 C5.19375,12.24125 5.535,12.33875 5.89875,12.39875 C6.25875,12.4625 6.6225,12.4925 6.9825,12.4925 C7.5825,12.4925 8.13,12.425 8.6175,12.28625 C9.105,12.1475 9.525,11.94875 9.87,11.69375 C10.215,11.435 10.48125,11.12 10.6725,10.74125 C10.86375,10.3625 10.95375,9.935 10.95375,9.455 C10.95375,9.005 10.875,8.6 10.72125,8.24375 C10.68375,8.1575 10.6425,8.075 10.59375,7.9925 L14,8 L14,6 Z" transform="translate(2 3)"/></svg>',xl='<svg class="o-icon"><path fill="#000000" d="M7,0 L5,0 L0.5,12 L2.5,12 L3.62,9 L8.37,9 L9.49,12 L11.49,12 L7,0 L7,0 Z M4.38,7 L6,2.67 L7.62,7 L4.38,7 L4.38,7 Z" transform="translate(3 1)"/></svg>',Rl='<svg class="o-icon"><path fill="#000000" d="M14.5,8.87 C14.5,8.87 13,10.49 13,11.49 C13,12.32 13.67,12.99 14.5,12.99 C15.33,12.99 16,12.32 16,11.49 C16,10.5 14.5,8.87 14.5,8.87 L14.5,8.87 Z M12.71,6.79 L5.91,0 L4.85,1.06 L6.44,2.65 L2.29,6.79 C1.9,7.18 1.9,7.81 2.29,8.2 L6.79,12.7 C6.99,12.9 7.24,13 7.5,13 C7.76,13 8.01,12.9 8.21,12.71 L12.71,8.21 C13.1,7.82 13.1,7.18 12.71,6.79 L12.71,6.79 Z M4.21,7 L7.5,3.71 L10.79,7 L4.21,7 L4.21,7 Z"/></svg>',Ll='<svg class="o-icon"><path fill="#000000" d="M0,14 L10,14 L10,12 L0,12 L0,14 Z M10,4 L0,4 L0,6 L10,6 L10,4 Z M0,0 L0,2 L14,2 L14,0 L0,0 Z M0,10 L14,10 L14,8 L0,8 L0,10 Z" transform="translate(2 2)"/></svg>',
|
|
47
|
+
`;const Cl='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 8 0" transform="translate(5 7)"/></svg>',Il='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 0 8" transform="translate(5 5)"/></svg>',yl='<svg class="o-icon"><path fill="#000000" fill-rule="evenodd" d="M9,3.5 C9,1.57 7.43,0 5.5,0 L1.77635684e-15,0 L1.77635684e-15,12 L6.25,12 C8.04,12 9.5,10.54 9.5,8.75 C9.5,7.45 8.73,6.34 7.63,5.82 C8.46,5.24 9,4.38 9,3.5 Z M5,2 C5.82999992,2 6.5,2.67 6.5,3.5 C6.5,4.33 5.82999992,5 5,5 L3,5 L3,2 L5,2 Z M3,10 L3,7 L5.5,7 C6.32999992,7 7,7.67 7,8.5 C7,9.33 6.32999992,10 5.5,10 L3,10 Z" transform="translate(4 3)"/></svg>',wl='<svg class="o-icon"><polygon fill="#000000" fill-rule="evenodd" points="4 0 4 2 6.58 2 2.92 10 0 10 0 12 8 12 8 10 5.42 10 9.08 2 12 2 12 0" transform="translate(3 3)"/></svg>',Tl='<svg class="o-icon"><path fill="#010101" fill-rule="evenodd" d="M2.8875,3.06 C2.8875,2.6025 2.985,2.18625 3.18375,1.8075 C3.3825,1.42875 3.66,1.10625 4.02,0.84 C4.38,0.57375 4.80375,0.3675 5.29875,0.22125 C5.79375,0.075 6.33375,0 6.92625,0 C7.53375,0 8.085,0.0825 8.58,0.25125 C9.075,0.42 9.49875,0.6525 9.85125,0.95625 C10.20375,1.25625 10.47375,1.6125 10.665,2.02875 C10.85625,2.44125 10.95,2.895 10.95,3.38625 L8.6925,3.38625 C8.6925,3.1575 8.655,2.94375 8.58375,2.74875 C8.5125,2.55 8.4,2.38125 8.25,2.2425 C8.1,2.10375 7.9125,1.99125 7.6875,1.91625 C7.4625,1.8375 7.19625,1.8 6.88875,1.8 C6.5925,1.8 6.3375,1.83375 6.11625,1.8975 C5.89875,1.96125 5.71875,2.05125 5.57625,2.1675 C5.43375,2.28375 5.325,2.41875 5.25375,2.5725 C5.1825,2.72625 5.145,2.895 5.145,3.0675 C5.145,3.4275 5.32875,3.73125 5.69625,3.975 C5.71780203,3.98908066 5.73942012,4.00311728 5.76118357,4.01733315 C6.02342923,4.18863185 6.5,4.5 7,5 L4,5 C4,5 3.21375,4.37625 3.17625,4.30875 C2.985,3.9525 2.8875,3.53625 2.8875,3.06 Z M14,6 L0,6 L0,8 L7.21875,8 C7.35375,8.0525 7.51875,8.105 7.63125,8.15375 C7.90875,8.2775 8.12625,8.40875 8.28375,8.53625 C8.44125,8.6675 8.54625,8.81 8.6025,8.96 C8.65875,9.11375 8.685,9.28625 8.685,9.47375 C8.685,9.65 8.65125,9.815 8.58375,9.965 C8.51625,10.11875 8.41125,10.25 8.2725,10.35875 C8.13375,10.4675 7.95375,10.55375 7.74,10.6175 C7.5225,10.68125 7.27125,10.71125 6.97875,10.71125 C6.6525,10.71125 6.35625,10.6775 6.09,10.61375 C5.82375,10.55 5.59875,10.445 5.41125,10.3025 C5.22375,10.16 5.0775,9.9725 4.9725,9.74375 C4.8675,9.515 4.78125,9.17 4.78125,9 L2.55,9 C2.55,9.2525 2.61,9.6875 2.72625,10.025 C2.8425,10.3625 3.0075,10.66625 3.21375,10.9325 C3.42,11.19875 3.6675,11.4275 3.94875,11.6225 C4.23,11.8175 4.53375,11.9825 4.86375,12.11 C5.19375,12.24125 5.535,12.33875 5.89875,12.39875 C6.25875,12.4625 6.6225,12.4925 6.9825,12.4925 C7.5825,12.4925 8.13,12.425 8.6175,12.28625 C9.105,12.1475 9.525,11.94875 9.87,11.69375 C10.215,11.435 10.48125,11.12 10.6725,10.74125 C10.86375,10.3625 10.95375,9.935 10.95375,9.455 C10.95375,9.005 10.875,8.6 10.72125,8.24375 C10.68375,8.1575 10.6425,8.075 10.59375,7.9925 L14,8 L14,6 Z" transform="translate(2 3)"/></svg>',xl='<svg class="o-icon"><path fill="#000000" d="M7,0 L5,0 L0.5,12 L2.5,12 L3.62,9 L8.37,9 L9.49,12 L11.49,12 L7,0 L7,0 Z M4.38,7 L6,2.67 L7.62,7 L4.38,7 L4.38,7 Z" transform="translate(3 1)"/></svg>',Rl='<svg class="o-icon"><path fill="#000000" d="M14.5,8.87 C14.5,8.87 13,10.49 13,11.49 C13,12.32 13.67,12.99 14.5,12.99 C15.33,12.99 16,12.32 16,11.49 C16,10.5 14.5,8.87 14.5,8.87 L14.5,8.87 Z M12.71,6.79 L5.91,0 L4.85,1.06 L6.44,2.65 L2.29,6.79 C1.9,7.18 1.9,7.81 2.29,8.2 L6.79,12.7 C6.99,12.9 7.24,13 7.5,13 C7.76,13 8.01,12.9 8.21,12.71 L12.71,8.21 C13.1,7.82 13.1,7.18 12.71,6.79 L12.71,6.79 Z M4.21,7 L7.5,3.71 L10.79,7 L4.21,7 L4.21,7 Z"/></svg>',Ll='<svg class="o-icon"><path fill="#000000" d="M0,14 L10,14 L10,12 L0,12 L0,14 Z M10,4 L0,4 L0,6 L10,6 L10,4 Z M0,0 L0,2 L14,2 L14,0 L0,0 Z M0,10 L14,10 L14,8 L0,8 L0,10 Z" transform="translate(2 2)"/></svg>',Al='<svg class="o-icon"><path fill="#000000" d="M2,12 L2,14 L12,14 L12,12 L2,12 Z M2,4 L2,6 L12,6 L12,4 L2,4 Z M0,10 L14,10 L14,8 L0,8 L0,10 Z M0,0 L0,2 L14,2 L14,0 L0,0 Z" transform="translate(2 2)"/></svg>',Ml='<svg class="o-icon"><path fill="#000000" d="M4,14 L14,14 L14,12 L4,12 L4,14 Z M0,10 L14,10 L14,8 L0,8 L0,10 Z M0,0 L0,2 L14,2 L14,0 L0,0 Z M4,6 L14,6 L14,4 L4,4 L4,6 Z" transform="translate(2 2)"/></svg>',_l='<svg class="o-icon"><path fill="#000000" d="M0,0 L0,14 L14,14 L14,0 L0,0 L0,0 Z M6,12 L2,12 L2,8 L6,8 L6,12 L6,12 Z M6,6 L2,6 L2,2 L6,2 L6,6 L6,6 Z M12,12 L8,12 L8,8 L12,8 L12,12 L12,12 Z M12,6 L8,6 L8,2 L12,2 L12,6 L12,6 Z" transform="translate(2 2)"/></svg>',Ol='<svg class="o-icon" viewBox="0 0 384 384"><rect x="0" y="277.333" width="384" height="42.667"/><rect x="0" y="170.667" width="384" height="42.667"/><rect x="0" y="64" width="384" height="42.667"/></svg>',Nl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon arrow-down" width="10" height="10" focusable="false" viewBox="0 0 448 512"><path fill="#DC6965" d="M413.1 222.5l22.2 22.2c9.4 9.4 9.4 24.6 0 33.9L241 473c-9.4 9.4-24.6 9.4-33.9 0L12.7 278.6c-9.4-9.4-9.4-24.6 0-33.9l22.2-22.2c9.5-9.5 25-9.3 34.3.4L184 343.4V56c0-13.3 10.7-24 24-24h32c13.3 0 24 10.7 24 24v287.4l114.8-120.5c9.3-9.8 24.8-10 34.3-.4z"></path></svg>',kl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon arrow-up" width="10" height="10" focusable="false" viewBox="0 0 448 512"><path fill="#00A04A" d="M34.9 289.5l-22.2-22.2c-9.4-9.4-9.4-24.6 0-33.9L207 39c9.4-9.4 24.6-9.4 33.9 0l194.3 194.3c9.4 9.4 9.4 24.6 0 33.9L413 289.4c-9.5 9.5-25 9.3-34.3-.4L264 168.6V456c0 13.3-10.7 24-24 24h-32c-13.3 0-24-10.7-24-24V168.6L69.2 289.1c-9.3 9.8-24.8 10-34.3.4z"></path></svg>',Fl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon arrow-right" width="10" height="10" focusable="false" viewBox="0 0 448 512"><path fill="#F0AD4E" d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"></path></svg>',$l='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon smile" width="10" height="10" focusable="false" viewBox="0 0 496 512"><path fill="#00A04A" d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160 0c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm4 72.6c-20.8 25-51.5 39.4-84 39.4s-63.2-14.3-84-39.4c-8.5-10.2-23.7-11.5-33.8-3.1-10.2 8.5-11.5 23.6-3.1 33.8 30 36 74.1 56.6 120.9 56.6s90.9-20.6 120.9-56.6c8.5-10.2 7.1-25.3-3.1-33.8-10.1-8.4-25.3-7.1-33.8 3.1z"></path></svg>',Dl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon meh" width="10" height="10" focusable="false" viewBox="0 0 496 512"><path fill="#F0AD4E" d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160-64c-17.7 0-32 14.3-32 32s14.3 32 32 32 32-14.3 32-32-14.3-32-32-32zm8 144H160c-13.2 0-24 10.8-24 24s10.8 24 24 24h176c13.2 0 24-10.8 24-24s-10.8-24-24-24z"></path></svg>',Ul='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon frown" width="10" height="10" focusable="false" viewBox="0 0 496 512"><path fill="#DC6965" d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160-64c-17.7 0-32 14.3-32 32s14.3 32 32 32 32-14.3 32-32-14.3-32-32-32zm-80 128c-40.2 0-78 17.7-103.8 48.6-8.5 10.2-7.1 25.3 3.1 33.8 10.2 8.4 25.3 7.1 33.8-3.1 16.6-19.9 41-31.4 66.9-31.4s50.3 11.4 66.9 31.4c8.1 9.7 23.1 11.9 33.8 3.1 10.2-8.5 11.5-23.6 3.1-33.8C326 321.7 288.2 304 248 304z"></path></svg>',Pl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon green-dot" width="10" height="10" focusable="false" viewBox="0 0 512 512"><path fill="#00A04A" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"></path></svg>',Bl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon yellow-dot" width="10" height="10" focusable="false" viewBox="0 0 512 512"><path fill="#F0AD4E" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"></path></svg>',Vl='<svg xmlns="http://www.w3.org/2000/svg" class="o-cf-icon red-dot" width="10" height="10" focusable="false" viewBox="0 0 512 512"><path fill="#DC6965" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"></path></svg>';function Hl(e){const t=new Image;return t.src="data:image/svg+xml; charset=utf8, "+encodeURIComponent(e),t}const zl={arrowGood:{img:Hl(kl),svg:kl},arrowNeutral:{img:Hl(Fl),svg:Fl},arrowBad:{img:Hl(Nl),svg:Nl},smileyGood:{img:Hl($l),svg:$l},smileyNeutral:{img:Hl(Dl),svg:Dl},smileyBad:{img:Hl(Ul),svg:Ul},dotGood:{img:Hl(Pl),svg:Pl},dotNeutral:{img:Hl(Bl),svg:Bl},dotBad:{img:Hl(Vl),svg:Vl}},Zl={arrows:{good:"arrowGood",neutral:"arrowNeutral",bad:"arrowBad"},smiley:{good:"smileyGood",neutral:"smileyNeutral",bad:"smileyBad"},dots:{good:"dotGood",neutral:"dotNeutral",bad:"dotBad"}},{xml:Gl,css:Wl}=t.tags,ql=new oi,jl=Gl`
|
|
48
48
|
<div class="o-selection">
|
|
49
49
|
<div t-foreach="ranges" t-as="range" t-key="range.id" class="o-selection-input">
|
|
50
50
|
<input
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
`;class Xl extends t.Component{constructor(){super(...arguments),this.id=ql.uuidv4(),this.previousRanges=this.props.ranges||[],this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.originSheet=this.env.getters.getActiveSheetId(),this.state=t.useState({isMissing:!1})}get ranges(){const e=this.getters.getSelectionInput(this.id);return(e.length?e:this.props.ranges?this.props.ranges.map(((e,t)=>({xc:e,id:t.toString(),isFocused:!1}))):[]).map((e=>({...e,isValidRange:""===e.xc||this.getters.isRangeValid(e.xc)})))}get hasFocus(){return this.ranges.filter((e=>e.isFocused)).length>0}get canAddRange(){return!this.props.hasSingleRange}get isInvalid(){return this.props.isInvalid||this.state.isMissing}mounted(){this.dispatch("ENABLE_NEW_SELECTION_INPUT",{id:this.id,initialRanges:this.props.ranges,hasSingleRange:this.props.hasSingleRange})}async willUnmount(){this.dispatch("DISABLE_SELECTION_INPUT",{id:this.id})}async patched(){const e=this.getters.getSelectionInputValue(this.id);this.previousRanges.join()!==e.join()&&this.triggerChange()}getColor(e){return"color: "+(e.color||"#000")+";"}triggerChange(){const e=this.getters.getSelectionInputValue(this.id);this.trigger("selection-changed",{ranges:e}),this.previousRanges=e}focus(e){this.state.isMissing=!1,this.dispatch("STOP_EDITION",{cancel:!0}),this.dispatch("FOCUS_RANGE",{id:this.id,rangeId:e})}addEmptyInput(){this.dispatch("ADD_EMPTY_RANGE",{id:this.id})}removeInput(e){this.dispatch("REMOVE_RANGE",{id:this.id,rangeId:e}),this.triggerChange(),this.trigger("selection-confirmed")}onInputChanged(e,t){const s=t.target;this.dispatch("CHANGE_RANGE",{id:this.id,rangeId:e,value:s.value}),s.blur(),this.triggerChange()}disable(){this.dispatch("UNFOCUS_SELECTION_INPUT");const e=this.getters.getSelectionInputValue(this.id);this.props.required&&0===e.length&&(this.state.isMissing=!0);const t=this.getters.getActiveSheetId();this.originSheet!==t&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:this.originSheet}),this.trigger("selection-confirmed")}}Xl.template=jl,Xl.style=Yl;const Kl={CF_TITLE:a("Format rules"),IS_RULE:a("Format cells if..."),FORMATTING_STYLE:a("Formatting style"),BOLD:a("Bold"),ITALIC:a("Italic"),UNDERLINE:a("Underline"),STRIKE_THROUGH:a("Strikethrough"),TEXT_COLOR:a("Text Color"),FILL_COLOR:a("Fill Color"),CANCEL:a("Cancel"),SAVE:a("Save"),PREVIEW_TEXT:a("Preview text"),Errors:{22:a("The range is invalid"),36:a("The argument is missing. Please provide a value"),37:a("The second argument is missing. Please provide a value"),38:a("The minpoint must be a number"),39:a("The midpoint must be a number"),40:a("The maxpoint must be a number"),41:a("The first value must be a number"),42:a("The second value must be a number"),32:a("Minimum must be smaller then Maximum"),35:a("Minimum must be smaller then Midpoint"),34:a("Midpoint must be smaller then Maximum"),33:a("Lower inflection point must be smaller then upper inflection point"),43:a("Invalid Minpoint formula"),45:a("Invalid Maxpoint formula"),44:a("Invalid Midpoint formula"),46:a("Invalid upper inflection point formula"),47:a("Invalid lower inflection point formula"),21:a("A range needs to be defined"),unexpected:a("The rule is invalid for an unknown reason")},SingleColor:a("Single color"),ColorScale:a("Color scale"),IconSet:a("Icon set"),newRule:a("Add another rule"),FixedNumber:a("Number"),Percentage:a("Percentage"),Percentile:a("Percentile"),Formula:a("Formula")},Ql=a("Cell values"),Jl=a("None"),ec=a("Preview"),tc=a("Minpoint"),sc=a("Maxpoint"),ic=a("Midpoint"),oc=a("When value is"),nc=a("Else"),rc=a("Reverse icons"),ac=a("Icons"),lc=a("Type"),cc=a("Value"),hc={IsEmpty:a("Is empty"),IsNotEmpty:a("Is not empty"),ContainsText:a("Contains"),NotContains:a("Does not contain"),BeginsWith:a("Starts with"),EndsWith:a("Ends with"),Equal:a("Is equal to"),NotEqual:a("Is not equal to"),GreaterThan:a("Is greater than"),GreaterThanOrEqual:a("Is greater than or equal to"),LessThan:a("Is less than"),LessThanOrEqual:a("Is less than or equal to"),Between:a("Is between"),NotBetween:a("Is not between")},dc={ChartType:a("Chart type"),Line:a("Line"),Bar:a("Bar"),Pie:a("Pie"),StackedBar:a("Stacked barchart"),Title:a("Title"),Series:a("Series"),DataSeries:a("Data Series"),MyDataHasTitle:a("Data series include title"),DataCategories:a("Categories / Labels"),UpdateChart:a("Update chart"),CreateChart:a("Create chart"),TitlePlaceholder:a("New Chart"),BackgroundColor:a("Background color"),SelectColor:a("Select a color..."),VerticalAxisPosition:a("Vertical axis position"),LegendPosition:a("Legend position"),Left:a("Left"),Right:a("Right"),None:a("None"),Top:a("Top"),Bottom:a("Bottom"),Center:a("Center"),Linear:a("Linear"),Exponential:a("Exponential"),Logarithmic:a("Logarithmic"),Errors:{27:a("A dataset needs to be defined"),28:a("The dataset is invalid"),29:a("Labels are invalid"),unexpected:a("The chart definition is invalid for an unknown reason")}},uc=a("Search"),pc=a("Replace"),gc=a("Next"),fc=a("Previous"),mc=a("Match case"),vc=a("Match entire cell content"),Ec=a("Search in formulas"),
|
|
128
|
+
`;class Xl extends t.Component{constructor(){super(...arguments),this.id=ql.uuidv4(),this.previousRanges=this.props.ranges||[],this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.originSheet=this.env.getters.getActiveSheetId(),this.state=t.useState({isMissing:!1})}get ranges(){const e=this.getters.getSelectionInput(this.id);return(e.length?e:this.props.ranges?this.props.ranges.map(((e,t)=>({xc:e,id:t.toString(),isFocused:!1}))):[]).map((e=>({...e,isValidRange:""===e.xc||this.getters.isRangeValid(e.xc)})))}get hasFocus(){return this.ranges.filter((e=>e.isFocused)).length>0}get canAddRange(){return!this.props.hasSingleRange}get isInvalid(){return this.props.isInvalid||this.state.isMissing}mounted(){this.dispatch("ENABLE_NEW_SELECTION_INPUT",{id:this.id,initialRanges:this.props.ranges,hasSingleRange:this.props.hasSingleRange})}async willUnmount(){this.dispatch("DISABLE_SELECTION_INPUT",{id:this.id})}async patched(){const e=this.getters.getSelectionInputValue(this.id);this.previousRanges.join()!==e.join()&&this.triggerChange()}getColor(e){return"color: "+(e.color||"#000")+";"}triggerChange(){const e=this.getters.getSelectionInputValue(this.id);this.trigger("selection-changed",{ranges:e}),this.previousRanges=e}focus(e){this.state.isMissing=!1,this.dispatch("STOP_EDITION",{cancel:!0}),this.dispatch("FOCUS_RANGE",{id:this.id,rangeId:e})}addEmptyInput(){this.dispatch("ADD_EMPTY_RANGE",{id:this.id})}removeInput(e){this.dispatch("REMOVE_RANGE",{id:this.id,rangeId:e}),this.triggerChange(),this.trigger("selection-confirmed")}onInputChanged(e,t){const s=t.target;this.dispatch("CHANGE_RANGE",{id:this.id,rangeId:e,value:s.value}),s.blur(),this.triggerChange()}disable(){this.dispatch("UNFOCUS_SELECTION_INPUT");const e=this.getters.getSelectionInputValue(this.id);this.props.required&&0===e.length&&(this.state.isMissing=!0);const t=this.getters.getActiveSheetId();this.originSheet!==t&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:t,sheetIdTo:this.originSheet}),this.trigger("selection-confirmed")}}Xl.template=jl,Xl.style=Yl;const Kl={CF_TITLE:a("Format rules"),IS_RULE:a("Format cells if..."),FORMATTING_STYLE:a("Formatting style"),BOLD:a("Bold"),ITALIC:a("Italic"),UNDERLINE:a("Underline"),STRIKE_THROUGH:a("Strikethrough"),TEXT_COLOR:a("Text Color"),FILL_COLOR:a("Fill Color"),CANCEL:a("Cancel"),SAVE:a("Save"),PREVIEW_TEXT:a("Preview text"),Errors:{22:a("The range is invalid"),36:a("The argument is missing. Please provide a value"),37:a("The second argument is missing. Please provide a value"),38:a("The minpoint must be a number"),39:a("The midpoint must be a number"),40:a("The maxpoint must be a number"),41:a("The first value must be a number"),42:a("The second value must be a number"),32:a("Minimum must be smaller then Maximum"),35:a("Minimum must be smaller then Midpoint"),34:a("Midpoint must be smaller then Maximum"),33:a("Lower inflection point must be smaller then upper inflection point"),43:a("Invalid Minpoint formula"),45:a("Invalid Maxpoint formula"),44:a("Invalid Midpoint formula"),46:a("Invalid upper inflection point formula"),47:a("Invalid lower inflection point formula"),21:a("A range needs to be defined"),unexpected:a("The rule is invalid for an unknown reason")},SingleColor:a("Single color"),ColorScale:a("Color scale"),IconSet:a("Icon set"),newRule:a("Add another rule"),FixedNumber:a("Number"),Percentage:a("Percentage"),Percentile:a("Percentile"),Formula:a("Formula")},Ql=a("Cell values"),Jl=a("None"),ec=a("Preview"),tc=a("Minpoint"),sc=a("Maxpoint"),ic=a("Midpoint"),oc=a("When value is"),nc=a("Else"),rc=a("Reverse icons"),ac=a("Icons"),lc=a("Type"),cc=a("Value"),hc={IsEmpty:a("Is empty"),IsNotEmpty:a("Is not empty"),ContainsText:a("Contains"),NotContains:a("Does not contain"),BeginsWith:a("Starts with"),EndsWith:a("Ends with"),Equal:a("Is equal to"),NotEqual:a("Is not equal to"),GreaterThan:a("Is greater than"),GreaterThanOrEqual:a("Is greater than or equal to"),LessThan:a("Is less than"),LessThanOrEqual:a("Is less than or equal to"),Between:a("Is between"),NotBetween:a("Is not between")},dc={ChartType:a("Chart type"),Line:a("Line"),Bar:a("Bar"),Pie:a("Pie"),StackedBar:a("Stacked barchart"),Title:a("Title"),Series:a("Series"),DataSeries:a("Data Series"),MyDataHasTitle:a("Data series include title"),DataCategories:a("Categories / Labels"),UpdateChart:a("Update chart"),CreateChart:a("Create chart"),TitlePlaceholder:a("New Chart"),BackgroundColor:a("Background color"),SelectColor:a("Select a color..."),VerticalAxisPosition:a("Vertical axis position"),LegendPosition:a("Legend position"),Left:a("Left"),Right:a("Right"),None:a("None"),Top:a("Top"),Bottom:a("Bottom"),Center:a("Center"),Linear:a("Linear"),Exponential:a("Exponential"),Logarithmic:a("Logarithmic"),Errors:{27:a("A dataset needs to be defined"),28:a("The dataset is invalid"),29:a("Labels are invalid"),unexpected:a("The chart definition is invalid for an unknown reason")}},uc=a("Search"),pc=a("Replace"),gc=a("Next"),fc=a("Previous"),mc=a("Match case"),vc=a("Match entire cell content"),Ec=a("Search in formulas"),Sc=a("Replace all"),bc=a("Also modify formulas"),Cc=a("Text"),Ic=a("Link"),yc=a("Confirm"),wc=a("Cancel"),Tc=a("Edit link"),xc=a("Remove link"),Rc=a("and"),{xml:Lc,css:Ac}=t.tags,Mc=Lc`
|
|
129
129
|
<div class="o-chart">
|
|
130
130
|
<div class="o-panel">
|
|
131
131
|
<div class="o-panel-element"
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
`}"/>
|
|
221
221
|
</t>
|
|
222
222
|
</div>
|
|
223
|
-
`,_c=
|
|
223
|
+
`,_c=Ac`
|
|
224
224
|
.o-chart {
|
|
225
225
|
.o-panel {
|
|
226
226
|
display: flex;
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
border-bottom: 4px solid;
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
`;class Oc extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.chartSheetId=this.findSheetId(this.props.figure.id),this.state=t.useState(this.initialState(this.props.figure))}async willUpdateProps(e){this.getters.getChartDefinition(e.figure.id)?e.figure.id!==this.props.figure.id&&(this.chartSheetId=this.findSheetId(e.figure.id),this.state.panel="configuration",this.state.fillColorTool=!1,this.state.datasetDispatchResult=void 0,this.state.labelsDispatchResult=void 0,this.state.chart=this.env.getters.getChartDefinitionUI(this.chartSheetId,e.figure.id)):this.trigger("close-side-panel")}get errorMessages(){var e,t;return[...(null===(e=this.state.datasetDispatchResult)||void 0===e?void 0:e.reasons)||[],...(null===(t=this.state.labelsDispatchResult)||void 0===t?void 0:t.reasons)||[]].map((e=>this.env._t(dc.Errors[e]||dc.Errors.unexpected)))}get isDatasetInvalid(){var e,t;return!(!(null===(e=this.state.datasetDispatchResult)||void 0===e?void 0:e.isCancelledBecause(27))&&!(null===(t=this.state.datasetDispatchResult)||void 0===t?void 0:t.isCancelledBecause(28)))}get isLabelInvalid(){var e;return!!(null===(e=this.state.labelsDispatchResult)||void 0===e?void 0:e.isCancelledBecause(29))}onSeriesChanged(e){this.state.chart.dataSets=e.detail.ranges}updateDataSet(){this.state.datasetDispatchResult=this.updateChart({dataSets:this.state.chart.dataSets,dataSetsHaveTitle:this.state.chart.dataSetsHaveTitle})}updateStacked(){this.updateChart({stackedBar:this.state.chart.stackedBar})}updateTitle(){this.updateChart({title:this.state.chart.title})}updateSelect(e,t){this.state.chart[e]=t.target.value,this.updateChart({[e]:t.target.value})}updateLabelRange(){this.state.labelsDispatchResult=this.updateChart({labelRange:this.state.chart.labelRange||null})}updateChart(e){return this.env.dispatch("UPDATE_CHART",{id:this.props.figure.id,sheetId:this.chartSheetId,definition:e})}onLabelRangeChanged(e){this.state.chart.labelRange=e.detail.ranges[0]}getKey(e){return e+this.props.figure.id}toggleColorPicker(){this.state.fillColorTool=!this.state.fillColorTool}setColor(e){this.state.chart.background=e.detail.color,this.state.fillColorTool=!1,this.updateChart({background:this.state.chart.background})}activate(e){this.state.panel=e}initialState(e){const t=this.findSheetId(e.id);return{chart:this.env.getters.getChartDefinitionUI(t,e.id),panel:"configuration",fillColorTool:!1}}findSheetId(e){return this.env.getters.getFigureSheetId(e)||""}}function Nc(e,t){return!!t.target&&e.contains(t.target)}function kc({strikethrough:e,underline:t}){return e||t?`${e?"line-through":""} ${t?"underline":""}`:"none"}Oc.template=
|
|
253
|
+
`;class Oc extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.chartSheetId=this.findSheetId(this.props.figure.id),this.state=t.useState(this.initialState(this.props.figure))}async willUpdateProps(e){this.getters.getChartDefinition(e.figure.id)?e.figure.id!==this.props.figure.id&&(this.chartSheetId=this.findSheetId(e.figure.id),this.state.panel="configuration",this.state.fillColorTool=!1,this.state.datasetDispatchResult=void 0,this.state.labelsDispatchResult=void 0,this.state.chart=this.env.getters.getChartDefinitionUI(this.chartSheetId,e.figure.id)):this.trigger("close-side-panel")}get errorMessages(){var e,t;return[...(null===(e=this.state.datasetDispatchResult)||void 0===e?void 0:e.reasons)||[],...(null===(t=this.state.labelsDispatchResult)||void 0===t?void 0:t.reasons)||[]].map((e=>this.env._t(dc.Errors[e]||dc.Errors.unexpected)))}get isDatasetInvalid(){var e,t;return!(!(null===(e=this.state.datasetDispatchResult)||void 0===e?void 0:e.isCancelledBecause(27))&&!(null===(t=this.state.datasetDispatchResult)||void 0===t?void 0:t.isCancelledBecause(28)))}get isLabelInvalid(){var e;return!!(null===(e=this.state.labelsDispatchResult)||void 0===e?void 0:e.isCancelledBecause(29))}onSeriesChanged(e){this.state.chart.dataSets=e.detail.ranges}updateDataSet(){this.state.datasetDispatchResult=this.updateChart({dataSets:this.state.chart.dataSets,dataSetsHaveTitle:this.state.chart.dataSetsHaveTitle})}updateStacked(){this.updateChart({stackedBar:this.state.chart.stackedBar})}updateTitle(){this.updateChart({title:this.state.chart.title})}updateSelect(e,t){this.state.chart[e]=t.target.value,this.updateChart({[e]:t.target.value})}updateLabelRange(){this.state.labelsDispatchResult=this.updateChart({labelRange:this.state.chart.labelRange||null})}updateChart(e){return this.env.dispatch("UPDATE_CHART",{id:this.props.figure.id,sheetId:this.chartSheetId,definition:e})}onLabelRangeChanged(e){this.state.chart.labelRange=e.detail.ranges[0]}getKey(e){return e+this.props.figure.id}toggleColorPicker(){this.state.fillColorTool=!this.state.fillColorTool}setColor(e){this.state.chart.background=e.detail.color,this.state.fillColorTool=!1,this.updateChart({background:this.state.chart.background})}activate(e){this.state.panel=e}initialState(e){const t=this.findSheetId(e.id);return{chart:this.env.getters.getChartDefinitionUI(t,e.id),panel:"configuration",fillColorTool:!1}}findSheetId(e){return this.env.getters.getFigureSheetId(e)||""}}function Nc(e,t){return!!t.target&&e.contains(t.target)}function kc({strikethrough:e,underline:t}){return e||t?`${e?"line-through":""} ${t?"underline":""}`:"none"}Oc.template=Mc,Oc.style=_c,Oc.components={SelectionInput:Xl,ColorPicker:bl};const{useExternalListener:Fc}=t.hooks,{xml:$c,css:Dc}=t.tags,Uc=$c`
|
|
254
254
|
<div class="o-cf-preview-line"
|
|
255
255
|
t-attf-style="font-weight:{{currentStyle.bold ?'bold':'normal'}};
|
|
256
256
|
text-decoration:{{getTextDecoration(currentStyle)}};
|
|
@@ -332,7 +332,7 @@
|
|
|
332
332
|
.o-color-picker {
|
|
333
333
|
pointer-events: all;
|
|
334
334
|
}
|
|
335
|
-
`;class Vc extends t.Component{constructor(){super(...arguments),this.cellIsOperators=hc,this.getTextDecoration=kc,this.state=t.useState({condition:{operator:this.props.rule&&this.props.rule.operator?this.props.rule.operator:"IsNotEmpty",value1:this.props.rule&&this.props.rule.values.length>0?this.props.rule.values[0]:"",value2:this.props.rule.values.length>1?this.props.rule.values[1]:""},textColorTool:!1,fillColorTool:!1,style:{fillColor:this.props.rule.style.fillColor,textColor:this.props.rule.style.textColor,bold:this.props.rule.style.bold,italic:this.props.rule.style.italic,strikethrough:this.props.rule.style.strikethrough,underline:this.props.rule.style.underline}}),Fc(window,"click",this.closeMenus)}get isValue1Invalid(){var e;return!!(null===(e=this.props.errors)||void 0===e?void 0:e.includes(36))}get isValue2Invalid(){var e;return!!(null===(e=this.props.errors)||void 0===e?void 0:e.includes(37))}getRule(){const e={},t=this.state.style;return void 0!==t.bold&&(e.bold=t.bold),void 0!==t.italic&&(e.italic=t.italic),void 0!==t.strikethrough&&(e.strikethrough=t.strikethrough),void 0!==t.underline&&(e.underline=t.underline),t.fillColor&&(e.fillColor=t.fillColor),t.textColor&&(e.textColor=t.textColor),{type:"CellIsRule",operator:this.state.condition.operator,values:[this.state.condition.value1,this.state.condition.value2],style:e}}toggleMenu(e){const t=this.state[e];this.closeMenus(),this.state[e]=!t}toggleTool(e){this.state.style[e]=!this.state.style[e],this.closeMenus()}setColor(e,t){const s=t.detail.color;this.state.style[e]=s,this.closeMenus()}closeMenus(){this.state.textColorTool=!1,this.state.fillColorTool=!1}static getDefaultRule(){return{type:"CellIsRule",operator:"IsNotEmpty",values:[],style:{fillColor:"#b6d7a8"}}}}Vc.template=Pc,Vc.style=Bc,Vc.components={ColorPicker:
|
|
335
|
+
`;class Vc extends t.Component{constructor(){super(...arguments),this.cellIsOperators=hc,this.getTextDecoration=kc,this.state=t.useState({condition:{operator:this.props.rule&&this.props.rule.operator?this.props.rule.operator:"IsNotEmpty",value1:this.props.rule&&this.props.rule.values.length>0?this.props.rule.values[0]:"",value2:this.props.rule.values.length>1?this.props.rule.values[1]:""},textColorTool:!1,fillColorTool:!1,style:{fillColor:this.props.rule.style.fillColor,textColor:this.props.rule.style.textColor,bold:this.props.rule.style.bold,italic:this.props.rule.style.italic,strikethrough:this.props.rule.style.strikethrough,underline:this.props.rule.style.underline}}),Fc(window,"click",this.closeMenus)}get isValue1Invalid(){var e;return!!(null===(e=this.props.errors)||void 0===e?void 0:e.includes(36))}get isValue2Invalid(){var e;return!!(null===(e=this.props.errors)||void 0===e?void 0:e.includes(37))}getRule(){const e={},t=this.state.style;return void 0!==t.bold&&(e.bold=t.bold),void 0!==t.italic&&(e.italic=t.italic),void 0!==t.strikethrough&&(e.strikethrough=t.strikethrough),void 0!==t.underline&&(e.underline=t.underline),t.fillColor&&(e.fillColor=t.fillColor),t.textColor&&(e.textColor=t.textColor),{type:"CellIsRule",operator:this.state.condition.operator,values:[this.state.condition.value1,this.state.condition.value2],style:e}}toggleMenu(e){const t=this.state[e];this.closeMenus(),this.state[e]=!t}toggleTool(e){this.state.style[e]=!this.state.style[e],this.closeMenus()}setColor(e,t){const s=t.detail.color;this.state.style[e]=s,this.closeMenus()}closeMenus(){this.state.textColorTool=!1,this.state.fillColorTool=!1}static getDefaultRule(){return{type:"CellIsRule",operator:"IsNotEmpty",values:[],style:{fillColor:"#b6d7a8"}}}}Vc.template=Pc,Vc.style=Bc,Vc.components={ColorPicker:bl},Vc.defaultProps={errors:[]};const{useExternalListener:Hc}=t.hooks,{xml:zc,css:Zc}=t.tags,Gc=zc`
|
|
336
336
|
<div class="o-cf-preview-gradient" t-attf-style="{{getPreviewGradient()}}">
|
|
337
337
|
<t t-esc="env._t('${Kl.PREVIEW_TEXT}')"/>
|
|
338
338
|
</div>
|
|
@@ -421,7 +421,7 @@
|
|
|
421
421
|
padding: 10px;
|
|
422
422
|
border-radius: 4px;
|
|
423
423
|
}
|
|
424
|
-
`;class Yc extends t.Component{constructor(){super(...arguments),this.colorNumberString=jt,this.stateColorScale=t.useState({minimum:this.props.rule.minimum,maximum:this.props.rule.maximum,midpoint:this.props.rule.midpoint?this.props.rule.midpoint:{color:11982760,type:"none"},maximumColorTool:!1,minimumColorTool:!1,midpointColorTool:!1}),Hc(window,"click",this.closeMenus)}getRule(){const e={...this.stateColorScale.minimum},t={...this.stateColorScale.midpoint};return{type:"ColorScaleRule",minimum:e,maximum:{...this.stateColorScale.maximum},midpoint:"none"===t.type?void 0:t}}toggleMenu(e){const t=this.stateColorScale[e];this.closeMenus(),this.stateColorScale[e]=!t}setColor(e,t){const s=t.detail.color;this.stateColorScale[e].color=Number.parseInt(s.substr(1),16),this.closeMenus()}getPreviewGradient(){const e=jt(this.stateColorScale.minimum.color),t=jt(this.stateColorScale.midpoint.color),s=jt(this.stateColorScale.maximum.color),i="background-image: linear-gradient(to right, #";return"none"===this.stateColorScale.midpoint.type?i+e+", #"+s+")":i+e+", #"+t+", #"+s+")"}isValueInvalid(e){switch(e){case"minimum":return this.props.errors.includes(43)||this.props.errors.includes(35)||this.props.errors.includes(32)||this.props.errors.includes(38);case"midpoint":return this.props.errors.includes(44)||this.props.errors.includes(39)||this.props.errors.includes(34);case"maximum":return this.props.errors.includes(45)||this.props.errors.includes(40);default:return!1}}closeMenus(){this.stateColorScale.minimumColorTool=!1,this.stateColorScale.midpointColorTool=!1,this.stateColorScale.maximumColorTool=!1}static getDefaultRule(){return{type:"ColorScaleRule",minimum:{type:"value",color:16777215},midpoint:void 0,maximum:{type:"value",color:6989903}}}}Yc.template=qc,Yc.style=jc,Yc.components={ColorPicker:
|
|
424
|
+
`;class Yc extends t.Component{constructor(){super(...arguments),this.colorNumberString=jt,this.stateColorScale=t.useState({minimum:this.props.rule.minimum,maximum:this.props.rule.maximum,midpoint:this.props.rule.midpoint?this.props.rule.midpoint:{color:11982760,type:"none"},maximumColorTool:!1,minimumColorTool:!1,midpointColorTool:!1}),Hc(window,"click",this.closeMenus)}getRule(){const e={...this.stateColorScale.minimum},t={...this.stateColorScale.midpoint};return{type:"ColorScaleRule",minimum:e,maximum:{...this.stateColorScale.maximum},midpoint:"none"===t.type?void 0:t}}toggleMenu(e){const t=this.stateColorScale[e];this.closeMenus(),this.stateColorScale[e]=!t}setColor(e,t){const s=t.detail.color;this.stateColorScale[e].color=Number.parseInt(s.substr(1),16),this.closeMenus()}getPreviewGradient(){const e=jt(this.stateColorScale.minimum.color),t=jt(this.stateColorScale.midpoint.color),s=jt(this.stateColorScale.maximum.color),i="background-image: linear-gradient(to right, #";return"none"===this.stateColorScale.midpoint.type?i+e+", #"+s+")":i+e+", #"+t+", #"+s+")"}isValueInvalid(e){switch(e){case"minimum":return this.props.errors.includes(43)||this.props.errors.includes(35)||this.props.errors.includes(32)||this.props.errors.includes(38);case"midpoint":return this.props.errors.includes(44)||this.props.errors.includes(39)||this.props.errors.includes(34);case"maximum":return this.props.errors.includes(45)||this.props.errors.includes(40);default:return!1}}closeMenus(){this.stateColorScale.minimumColorTool=!1,this.stateColorScale.midpointColorTool=!1,this.stateColorScale.maximumColorTool=!1}static getDefaultRule(){return{type:"ColorScaleRule",minimum:{type:"value",color:16777215},midpoint:void 0,maximum:{type:"value",color:6989903}}}}Yc.template=qc,Yc.style=jc,Yc.components={ColorPicker:bl},Yc.defaultProps={errors:[]};const{css:Xc,xml:Kc}=t.tags;class Qc extends t.Component{constructor(){super(...arguments),this.icons=zl,this.iconSets=Zl}onIconClick(e){e&&this.trigger("icon-picked",{icon:e})}}Qc.template=Kc`
|
|
425
425
|
<div class="o-icon-picker" >
|
|
426
426
|
<t t-foreach="iconSets" t-as="iconSet" t-key="iconset">
|
|
427
427
|
<div class="o-cf-icon-line">
|
|
@@ -995,7 +995,7 @@
|
|
|
995
995
|
<label class="o-far-checkbox">
|
|
996
996
|
<input class="o-far-input" t-att-disabled="state.searchOptions.searchFormulas" type="checkbox"
|
|
997
997
|
t-model="state.replaceOptions.modifyFormulas"/>
|
|
998
|
-
<span class="o-far-label"><t t-esc="env._t('${
|
|
998
|
+
<span class="o-far-label"><t t-esc="env._t('${bc}')"/></span>
|
|
999
999
|
</label>
|
|
1000
1000
|
</div>
|
|
1001
1001
|
</div>
|
|
@@ -1004,7 +1004,7 @@
|
|
|
1004
1004
|
<button t-att-disabled="env.getters.getCurrentSelectedMatchIndex() === null" t-on-click="replace"
|
|
1005
1005
|
class="o-sidePanelButton" t-esc="env._t('${pc}')"/>
|
|
1006
1006
|
<button t-att-disabled="env.getters.getCurrentSelectedMatchIndex() === null" t-on-click="replaceAll"
|
|
1007
|
-
class="o-sidePanelButton" t-esc="env._t('${
|
|
1007
|
+
class="o-sidePanelButton" t-esc="env._t('${Sc}')"/>
|
|
1008
1008
|
</div>
|
|
1009
1009
|
|
|
1010
1010
|
</div>
|
|
@@ -1041,7 +1041,7 @@
|
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
}
|
|
1044
|
-
`;class vh extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.state=t.useState(this.initialState())}get hasSearchResult(){return null!==this.env.getters.getCurrentSelectedMatchIndex()}mounted(){this.focusInput()}async willUnmount(){this.env.dispatch("CLEAR_SEARCH")}onInput(e){this.state.toSearch=e.target.value,this.debouncedUpdateSearch()}onKeydownSearch(e){"Enter"===e.key&&(e.preventDefault(),this.onSelectNextCell())}onKeydownReplace(e){"Enter"===e.key&&(e.preventDefault(),this.replace())}onFocusSidePanel(){this.state.searchOptions.searchFormulas=this.getters.shouldShowFormulas(),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas?this.state.searchOptions.searchFormulas:this.state.replaceOptions.modifyFormulas,this.env.dispatch("REFRESH_SEARCH")}searchFormulas(){this.env.dispatch("SET_FORMULA_VISIBILITY",{show:this.state.searchOptions.searchFormulas}),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas,this.updateSearch()}onSelectPreviousCell(){this.env.dispatch("SELECT_SEARCH_PREVIOUS_MATCH")}onSelectNextCell(){this.env.dispatch("SELECT_SEARCH_NEXT_MATCH")}updateSearch(){this.env.dispatch("UPDATE_SEARCH",{toSearch:this.state.toSearch,searchOptions:this.state.searchOptions})}debouncedUpdateSearch(){clearTimeout(this.inDebounce),this.inDebounce=setTimeout((()=>this.updateSearch.call(this)),400)}replace(){this.env.dispatch("REPLACE_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}replaceAll(){this.env.dispatch("REPLACE_ALL_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}focusInput(){const e=this.el.querySelector("input");e&&e.focus()}initialState(){return{toSearch:"",replaceWith:"",searchOptions:{matchCase:!1,exactMatch:!1,searchFormulas:!1},replaceOptions:{modifyFormulas:!1}}}}vh.template=fh,vh.style=mh;const Eh=new Le;Eh.add("ConditionalFormatting",{title:a("Conditional formatting"),Body:uh}),Eh.add("ChartPanel",{title:a("Chart"),Body:Oc}),Eh.add("FindAndReplace",{title:a("Find and Replace"),Body:vh});const bh=new Le;class Sh extends fa{constructor(e,t,s,i){super(t,s,i),this.getters=e,this.ui=i}drawGrid(e,t){}}Sh.layers=[];class Ch{constructor(e,t,s){this.index=0,this.cells=e,this.getters=t,this.direction=s}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:s,tooltip:i}=La.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:s,tooltip:i,origin:{col:e.data.col,row:e.data.row}}}}class Ih extends Sh{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:ps(e.col,0,this.getters.getSheet(t).cols.length),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:ps(e.row,0,this.getters.getSheet(t).rows.length),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:30;case"AUTOFILL_AUTO":const s=this.getters.getSelectedZone();return s.top===s.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),s=this.autofillZone;switch(this.direction){case 1:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(is(i,e));const n=this.createGenerator(o);for(let t=s.top;t<=s.bottom;t++)this.computeNewCell(n,i,t,e)}break;case 0:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(is(i,e));const n=this.createGenerator(o);for(let t=s.bottom;t>=s.top;t--)this.computeNewCell(n,i,t,e)}break;case 2:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(is(e,i));const n=this.createGenerator(o);for(let t=s.right;t>=s.left;t--)this.computeNewCell(n,t,i,e)}break;case 3:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(is(e,i));const n=this.createGenerator(o);for(let t=s.left;t<=s.right;t++)this.computeNewCell(n,t,i,e)}}if(e){const e=Ps(this.getters.getSelectedZone(),this.autofillZone);this.autofillZone=void 0,this.lastCellSelected={},this.direction=void 0,this.tooltip=void 0,this.dispatch("SET_SELECTION",{zones:[e],anchor:[e.left,e.top],anchorZone:e})}}select(e,t){const s=this.getters.getSelectedZone();if(Hs(e,t,s))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,s.top-1,s.left,s.right);break;case 1:this.saveZone(s.bottom+1,t,s.left,s.right);break;case 2:this.saveZone(s.top,s.bottom,e,s.left-1);break;case 3:this.saveZone(s.top,s.bottom,s.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let s=e.left,i=e.bottom;if(s>0){let e=this.getters.getCell(t,s-1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s-1,i)}if(i===e.bottom&&(s=e.right,s<=this.getters.getActiveSheet().cols.length)){let e=this.getters.getCell(t,s+1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s+1,i)}i!==e.bottom&&(this.select(e.left,i-1),this.autofill(!0))}computeNewCell(e,t,s,i){const{cellData:o,tooltip:n,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=n,i&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:s,content:a,style:l,border:c,format:h})}getRule(e,t){const s=Ma.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((s=>s.condition(e,t)));return s&&s.generateRule(e,t)}createGenerator(e){const t=[],s=[],i=this.getters.getActiveSheetId();for(let t of e){const[e,o]=ss(t),n=this.getters.getCell(i,e,o);s.push({col:e,row:o,cell:n,sheetId:i})}const o=s.map((e=>e.cell));for(let e of s){let s={type:"COPY_MODIFIER"};if(e&&e.cell){s=this.getRule(e.cell,o)||s}const{sheetId:i,col:n,row:r}=e,a=this.getters.getCellBorder(i,n,r)||void 0;t.push({data:{...e,border:a},rule:s})}return new Ch(t,this.getters,this.direction)}saveZone(e,t,s,i){this.autofillZone={top:e,bottom:t,left:s,right:i}}getDirection(e,t){const s=this.getters.getSelectedZone(),i={up:{number:s.top-t,value:0},down:{number:t-s.bottom,value:1},left:{number:s.left-e,value:2},right:{number:e-s.right,value:3}};if(1===Object.values(i).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(i).find((e=>e.number>0?1:0)).value;const o=i.up.number>0?"up":"down",n=i.left.number>0?"left":"right";return Math.abs(i[o].number)>=Math.abs(i[n].number)?i[o].value:i[n].value}autoFillMerge(e,t,s,i){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,s,i)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const n=this.getters.getMerge(o.id,e,t);(null==n?void 0:n.topLeft.col)===e&&(null==n?void 0:n.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:i,bottom:i+n.bottom-n.top,left:s,right:s+n.right-n.left}]})}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:s,thinLineWidth:i}=e,[o,n,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(s.strokeStyle="black",s.lineWidth=i,s.setLineDash([3]),s.strokeRect(o,n,r,a),s.setLineDash([]))}}Ih.layers=[6],Ih.getters=["getAutofillTooltip"],Ih.modes=["normal"];class yh extends Sh{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:s}=this.getters.getSelection();for(const i of t){const t=this.getAutomaticSums(e,i,s);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,s){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,s):this.sumData(e,t)}sumData(e,t){const s=this.dimensionsToSum(e,t),i=this.sumDimensions(e,t,s).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return s.has("ROW")&&s.has("COL")&&i.push(this.sumTotal(t)),i}sumAdjacentData(e,t,s){const[i,o]=Hs(s[0],s[1],t)?s:[t.left,t.top],n=this.findAdjacentData(e,i,o);return n?this.getters.isSingleCellOrMerge(e,t)||qs(Ps(n,t))?[{position:[i,o],zone:n}]:this.sumDimensions(e,Ps(n,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,s){const i=this.getters.getSheet(e),o=this.findSuitableZoneToSum(i,...this.getters.getMainCell(e,t,s));if(o)return this.getters.expandZone(e,o)}findSuitableZoneToSum(e,t,s){const i=this.getters.getCell(e.id,t,s-1),o=this.getters.getCell(e.id,t-1,s);if(this.isNumber(o)&&!this.isNumber(i))return this.findHorizontalZone(e,t,s);const n=this.findVerticalZone(e,t,s);if(this.isZoneValid(n))return n;const r=this.findHorizontalZone(e,t,s);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,s){const i={top:0,bottom:s-1,left:t,right:t},o=this.reduceZoneStart(e,i,i.bottom);return{...i,top:o}}findHorizontalZone(e,t,s){const i={top:s,bottom:s,left:0,right:t-1},o=this.reduceZoneStart(e,i,i.right);return{...i,left:o}}reduceZoneStart(e,t,s){const i=Gs(t,e,(e=>e),void 0).flat(),o=fs(s,-1,-1),n=_s(o.filter((e=>{var t;return i[e]&&!(null===(t=i[e])||void 0===t?void 0:t.isAutoSummable)}))),r=ms(o.filter((e=>this.isNumber(i[e]))))[0]||[];return _s(r)<n?1/0:Os(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===ke.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(A))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const s=new Set;return qs(t)?(s.add(1===Ws(t).width?"COL":"ROW"),s):(this.lastColIsEmpty(e,t)&&s.add("ROW"),this.lastRowIsEmpty(e,t)&&s.add("COL"),0===s.size&&s.add("COL"),s)}sumDimensions(e,t,s){return[...s.has("COL")?this.sumColumns(t,e):[],...s.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:s}=e;return{position:[s,t],zone:{...e,top:t,right:s-1}}}sumColumns(e,t){const s=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,s.bottom-1)},js(s).map((t=>({position:t,zone:{...e,right:t[0],left:t[0]}})))}sumRows(e,t){const s=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,s.right-1)},js(s).map((t=>({position:t,zone:{...e,top:t[1],bottom:t[1]}})))}dispatchCellUpdates(e,t){for(const s of t){const[t,i]=s.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,content:`=SUM(${this.getters.zoneToXC(e,s.zone)})`})}}nextEmptyRow(e,t){let s=t.bottom+1;const{left:i,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:s,top:s,left:i,right:o});)s++;return{...t,top:s,bottom:s}}nextEmptyCol(e,t){let s=t.right+1;const{top:i,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:s,right:s,top:i,bottom:o});)s++;return{...t,left:s,right:s}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}yh.getters=["getAutomaticSums"],yh.modes=["normal","headless"];class wh extends Sh{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"PASTE":return this.isPasteAllowed(this.state,e.target,!!e.force);case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}}return 0}handle(e){var t,s,i,o;switch(e.type){case"COPY":case"CUT":this.state=this.getClipboardState(e.target,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);if(this._isPaintingFormat=!1,e.interactive)this.interactivePaste(this.state,e.target,e);else{const t=this.state.cells.length,s=this.state.cells[0].length;this.paste(this.state,e.target,n),this.selectPastedZone(s,t,e.target),this.status="invisible"}break;case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Fs(t[0])){for(const[t,s]of js(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:s,sheetId:this.getters.getActiveSheetId()});break}const i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(s=this.state)||void 0===s?void 0:s.sheetId))return;this.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(i=this.state)||void 0===i?void 0:i.operation)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this.state=this.getClipboardState(e.target,"COPY"),this._isPaintingFormat=!0,this.status="visible";break;default:Ue(e)&&(this.status="invisible")}}getClipboardContent(){return this.state&&this.state.cells.length&&this.state.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const s=this.getters.getActiveSheet();let i;return i="COL"===t?{...e,left:e.right+1,right:s.cols.length-1}:{...e,top:e.bottom+1,bottom:s.rows.length-1},{cut:[i],paste:[e]}}getInsertCellsTargets(e,t){const s=this.getters.getActiveSheet();let i,o;return"COL"===t?(i={...e,right:s.cols.length-1},o={...e,left:e.right+1,right:e.right+1}):(i={...e,bottom:s.rows.length-1},o={...e,top:e.bottom+1,bottom:s.rows.length-1}),{cut:[i],paste:[o]}}removeMergeIfTopLeft(e){const{sheetId:t,col:s,row:i}=e,[o,n]=this.getters.getMainCell(t,s,i);if(n===i&&o===s){const e=this.getters.getMerge(t,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:t,target:[e]})}}pasteMergeIfExist(e,t){let{sheetId:s,col:i,row:o}=e;const[n,r]=this.getters.getMainCell(s,i,o);if(n===i&&r===o){const e=this.getters.getMerge(s,i,o);if(!e)return;({sheetId:s,col:i,row:o}=t),this.dispatch("ADD_MERGE",{sheetId:s,force:!0,target:[{left:i,top:o,right:i+e.right-e.left,bottom:o+e.bottom-e.top}]})}}getPasteZones(e,t){if(!t.length||!t[0].length)return e;const s=[],i=t.length,o=t[0].length,n=e[e.length-1],r=n.left,a=n.top,l=Math.max(1,Math.floor((n.right+1-r)/o)),c=Math.max(1,Math.floor((n.bottom+1-a)/i));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)s.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*i});return s}getClipboardState(e,t){const s=new Set(e.map((e=>e.top))),i=new Set(e.map((e=>e.bottom)));let o=1===s.size&&1===i.size?e:[e[e.length-1]];o=o.map((e=>({...e})));const n=[],r=[],a=this.getters.getActiveSheetId(),{top:l,bottom:c}=o[0];for(let e=l;e<=c;e++){const t=[];n.push(t);for(let s of o)for(let i=s.left;i<=s.right;i++){const s=this.getters.getCell(a,i,e),o=this.getters.getCellBorder(a,i,e)||void 0;t.push({cell:s,border:o,position:{col:i,row:e,sheetId:a}});const n=this.getters.getMerge(a,i,e);n&&n.top===e&&n.left===i&&r.push(n)}}return{cells:n,operation:t,sheetId:a,zones:o,merges:r}}pasteFromClipboard(e,t){this.status="invisible";const s=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:i,top:o}=e[0],n=Math.max.apply(Math,s.map((e=>e.length))),r=s.length,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,r,i,o);for(let e=0;e<s.length;e++)for(let t=0;t<s[e].length;t++)this.dispatch("UPDATE_CELL",{row:o+e,col:i+t,content:s[e][t],sheetId:a.id});const l={left:i,top:o,right:i+n-1,bottom:o+r-1};this.dispatch("SET_SELECTION",{anchor:[i,o],zones:[l],anchorZone:l})}isPasteAllowed(e,t,s){const i=this.getters.getActiveSheetId();if(!e)return 20;if(t.length>1&&(e.cells.length>1||e.cells[0].length>1))return 19;if(!s)for(let s of this.getPasteZones(t,e.cells))if(this.getters.doesIntersectMerge(i,s))return 2;return 0}paste(e,t,s){if("CUT"===e.operation&&this.clearClippedZones(e),t.length>1)for(const i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,t,o,s);else{const i=e.cells.length,o=e.cells[0].length,n=t[0],r=Math.max(1,Math.floor((n.right+1-n.left)/o)),a=Math.max(1,Math.floor((n.bottom+1-n.top)/i));for(let t=0;t<r;t++)for(let r=0;r<a;r++)this.pasteZone(e,n.left+t*o,n.top+r*i,s)}"CUT"===e.operation&&(this.dispatch("REMOVE_MERGE",{sheetId:e.sheetId,target:e.merges}),this.state=void 0)}selectPastedZone(e,t,s){const i=s[0],o=i.left,n=i.top,r=Math.max(1,Math.floor((i.right+1-i.left)/e)),a=Math.max(1,Math.floor((i.bottom+1-i.top)/t));if(t>1||e>1){const s={left:o,top:n,right:o+r*e-1,bottom:n+a*t-1},[i,l]=this.getters.getSelection().anchor,c=ps(i,o,o+r*e-1),h=ps(l,n,n+a*t-1);this.dispatch("SET_SELECTION",{anchor:[c,h],zones:[s],anchorZone:s})}}clearClippedZones(e){for(const t of e.cells)for(const e of t)e.cell&&this.dispatch("CLEAR_CELL",e.position);this.dispatch("CLEAR_FORMATTING",{sheetId:e.sheetId,target:e.zones})}pasteZone(e,t,s,i){const o=e.cells.length,n=e.cells[0].length,r="onlyValue"!==i&&this.state&&this.state===e,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,o,t,s);for(let l=0;l<o;l++){const o=e.cells[l];for(let c=0;c<n;c++){const n=o[c],h={col:t+c,row:s+l,sheetId:a.id};this.removeMergeIfTopLeft(h),this.pasteMergeIfExist(n.position,h),this.pasteCell(n,h,e.operation,e.zones,i),r&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:h,operation:e.operation})}}}addMissingDimensions(e,t,s,i,o){const{cols:n,rows:r,id:a}=e,l=s+o-r.length;l>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:r.length-1,sheetId:a,quantity:l,position:"after"});const c=t+i-n.length;c>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:n.length-1,sheetId:a,quantity:c,position:"after"})}pasteCell(e,t,s,i,o){const{sheetId:n,col:r,row:a}=t,l=this.getters.getCell(n,r,a);if("onlyValue"!==o&&this.dispatch("SET_BORDER",{sheetId:n,col:r,row:a,border:e.border}),e.cell){if("onlyFormat"===o)return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.format});if("onlyValue"===o){const s=qr(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:s})}let l=e.cell.content;if(e.cell.isFormula()){const t=r-e.position.col,o=a-e.position.row;l=this.getUpdatedContent(n,e.cell,t,o,i,s)}this.dispatch("UPDATE_CELL",{...t,content:l,style:e.cell.style||null,format:e.cell.format})}else l&&("onlyValue"===o?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===o?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,s,i,o,n){if("CUT"===n){const n=[];for(const r of t.dependencies.references)this.isZoneOverlapClippedZone(o,r.zone)?n.push(...this.getters.createAdaptedRanges([r],s,i,e)):n.push(r);const r={...t.dependencies,references:n};return this.getters.buildFormulaContent(e,t.normalizedText,r)}const r=this.getters.createAdaptedRanges(t.dependencies.references,s,i,e),a={...t.dependencies,references:r};return this.getters.buildFormulaContent(e,t.normalizedText,a)}isZoneOverlapClippedZone(e,t){return e.some((e=>Vs(t,e)))}interactivePaste(e,t,s){const i=this.isPasteAllowed(e,t,!1);0!==i?(19===i&&this.ui.notifyUser(a("This operation is not allowed with multiple selections.")),2===i&&this.ui.notifyUser(a("This operation is not possible due to a merge. Please remove the merges first than try again."))):this.dispatch(s.type,{...s,interactive:!1})}isColRowDirtyingClipboard(e,t){if(!this.state||!this.state.zones)return!1;for(let s of this.state.zones){if("COL"===t&&e<=s.right)return!0;if("ROW"===t&&e<=s.bottom)return!0}return!1}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e;if("visible"===this.status&&this.state&&this.state.zones&&this.state.zones.length&&this.state.sheetId===this.getters.getActiveSheetId()){s.setLineDash([8,5]),s.strokeStyle=p,s.lineWidth=3.3*i;for(const e of this.state.zones){const[i,o,n,r]=this.getters.getRect(e,t);n>0&&r>0&&s.strokeRect(i,o,n,r)}}}}var Th;wh.layers=[2],wh.getters=["getClipboardContent","isPaintingFormat"],wh.modes=["normal"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}(Th||(Th={}));class xh extends Sh{constructor(e,t,s,i){super(e,t,s,i),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0],anchorZone:{top:0,left:0,bottom:0,right:0}},this.selectedFigureId=null,this.activeCol=0,this.activeRow=0,this.mode=Th.idle,this.sheetsData={},this.activeSheet=null,this.moveClient=i.moveClient}allowDispatch(e){switch(e.type){case"SET_SELECTION":if(-1===e.zones.findIndex((t=>Bs(t,e.anchorZone))))return 16;break;case"ALTER_SELECTION":if(e.delta){const{left:t,right:s,top:i,bottom:o}=this.getSelectedZone(),n=this.getters.getActiveSheet(),r=ri(n,"cols",fs(t,s+1)),a=ri(n,"rows",fs(i,o+1));if(0!==e.delta[0]&&void 0===a||0!==e.delta[1]&&void 0===r)return 17}break;case"MOVE_POSITION":{const{cols:t,rows:s}=this.getters.getActiveSheet();if(0!==e.deltaX&&s[this.activeRow].isHidden||0!==e.deltaY&&t[this.activeCol].isHidden)return 17;const{col:i,row:o}=this.getNextAvailablePosition(e.deltaX,e.deltaY);if(o<0||o>s.length-1||i<0||i>t.length-1)return 17;break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().cols.length)return 17;break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().rows.length)return 17;break}case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 23}case"MOVE_COLUMNS_ROWS":const t=this.isMoveElementAllowed(e);return 2===t&&this.ui.notifyUser(a("Merged cells are preventing this operation. Unmerge those cells and try again.")),t}return 0}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":case"CREATE_FIGURE":case"CREATE_CHART":case"UPDATE_FIGURE":case"EVALUATE_CELLS":case"DISABLE_SELECTION_INPUT":case"ENABLE_NEW_SELECTION_INPUT":case"RESIZE_VIEWPORT":break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;default:this.selectedFigureId=null}switch(e.type){case"START":const t=ni(this.getters.getSheets()[0],0,0);this.activeCol=t[0],this.activeRow=t[1],this.dispatch("ACTIVATE_SHEET",{sheetIdTo:this.getters.getSheets()[0].id,sheetIdFrom:this.getters.getSheets()[0].id}),this.selectCell(...t);break;case"ACTIVATE_SHEET":this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow},e.sheetIdTo in this.sheetsData?Object.assign(this,this.sheetsData[e.sheetIdTo]):this.selectCell(...ni(this.getters.getSheet(e.sheetIdTo),0,0));break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.anchorZone,e.strict);break;case"START_SELECTION":this.mode=Th.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=Th.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=Th.expanding;break;case"STOP_SELECTION":this.mode=Th.idle;break;case"MOVE_POSITION":this.movePosition(e.deltaX,e.deltaY);break;case"SELECT_CELL":this.selectCell(e.col,e.row);break;case"SELECT_COLUMN":this.selectColumn(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ROW":this.selectRow(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ALL":this.selectAll();break;case"ALTER_SELECTION":e.delta&&this.moveSelection(e.delta[0],e.delta[1]),e.cell&&this.addCellToSelection(...e.cell);break;case"UNDO":case"REDO":case"DELETE_SHEET":if(!this.getters.tryGetSheet(this.getActiveSheetId())){const e=this.getters.getVisibleSheets();this.activeSheet=this.getters.getSheet(e[0]),this.selectCell(0,0)}this.ensureSelectionValidity();break;case"REMOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&("COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e));break;case"ADD_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onAddElements(e);break;case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"UPDATE_CHART":case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left")}}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getMainCell(e,this.activeCol,this.activeRow);return this.getters.getCell(e,t,s)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.getters.getActiveSheet().rows.length-1)for(let s=t.left;s<=t.right;s++)e.add(s);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.getters.getActiveSheet().cols.length-1)for(let s=t.top;s<=t.bottom;s++)e.add(s);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.anchorZone}getSelection(){return this.selection}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return[this.activeCol,this.activeRow]}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?[t.activeCol,t.activeRow]:ni(this.getters.getSheet(e),0,0)}}getAggregate(){let e=0,t=0;for(let s of this.selection.zones)for(let i=s.top;i<=s.bottom;i++){const o=this.getters.getRow(this.getters.getActiveSheetId(),i);if(void 0!==o)for(let i=s.left;i<=s.right;i++){const s=o.cells[i];(null==s?void 0:s.evaluated.type)===ke.number&&(t++,e+=s.evaluated.value)}}return t<2?null:ie(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Bs(t,e)))}getVisibleFigures(e){const t=[],s=this.getters.getFigures(e),{offsetX:i,offsetY:o}=this.getters.getSnappedViewport(e),{width:n,height:r}=this.getters.getViewportDimension();for(let e of s)e.x>=i+n||e.x+e.width<=i||e.y>=o+r||e.y+e.height<=o||t.push(e);return t}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let s=[];const i="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[i]+1},((t,s)=>e[i]+s));s=s.concat(t)}return[...new Set(s)].sort()}selectColumn(e,t,s){const i=this.getters.getActiveSheet().rows.length-1;let o={left:e,right:e,top:0,bottom:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().rows.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Ps(o,{left:e,right:e,top:l,bottom:i}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[e,l];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectRow(e,t,s){const i=this.getters.getActiveSheet().cols.length-1;let o={top:e,bottom:e,left:0,right:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().cols.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Ps(o,{left:l,right:i,top:t,bottom:t}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[l,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectAll(){const e={left:0,top:0,bottom:this.getters.getActiveSheet().rows.length-1,right:this.getters.getActiveSheet().cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0],anchorZone:e})}selectCell(e,t){const s=this.getters.getActiveSheet();this.moveClient({sheetId:s.id,col:e,row:t});let i=this.getters.expandZone(s.id,{left:e,right:e,top:t,bottom:t});this.mode===Th.expanding?this.selection.zones.push(i):this.selection.zones=[i],this.selection.zones=Xs(this.selection.zones),this.selection.anchorZone=i,this.selection.anchor=[e,t],this.activeCol=e,this.activeRow=t}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}getNextAvailablePosition(e,t){return{col:this.getNextAvailableCol(e,this.activeCol,this.activeRow),row:this.getNextAvailableRow(t,this.activeCol,this.activeRow)}}getNextAvailableCol(e,t,s){const{cols:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,t,n,(e=>this.getters.isInSameMerge(o,t,s,e,s)))}getNextAvailableRow(e,t,s){const{rows:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,s,n,(e=>this.getters.isInSameMerge(o,t,s,t,e)))}getNextAvailableHeader(e,t,s,i,o){var n,r,a;const l=this.getters.getActiveSheetId(),{col:c,row:h}=i;if(0===e)return s;let d=s+e;if(this.getters.isInMerge(l,c,h)){for(;o(d);)d+=e;for(;null===(n=t[d])||void 0===n?void 0:n.isHidden;)d+=e}else if(null===(r=t[d])||void 0===r?void 0:r.isHidden)for(;null===(a=t[d])||void 0===a?void 0:a.isHidden;)d+=e;return d<0||d>t.length-1?t[s].isHidden?this.getNextAvailableHeader(-e,t,s,i,o):s:d}movePosition(e,t){const{col:s,row:i}=this.getNextAvailablePosition(e,t);this.selectCell(s,i)}setSelection(e,t,s,i=!1){this.selectCell(...e);const o=this.getters.getActiveSheetId();let n;t=Xs(t),n=i?{zones:t,anchorZone:s,anchor:e}:{anchor:e,zones:t.map((e=>this.getters.expandZone(o,e))),anchorZone:this.getters.expandZone(o,s)},this.selection=this.clipSelection(o,n)}getReferencePosition(){const e=this.getters.getActiveSheet(),t=this.selection,{left:s,right:i,top:o,bottom:n}=t.anchorZone,[r,a]=t.anchor;return{col:e.cols[r].isHidden&&ri(e,"cols",fs(s,i+1))||r,row:e.rows[a].isHidden&&ri(e,"rows",fs(o,n+1))||a}}moveSelection(e,t){const s=this.selection;let i=[];const[o,n]=s.anchor,{left:r,right:a,top:l,bottom:c}=s.anchorZone;let h=s.anchorZone;const d=this.getters.getActiveSheet(),u=e=>{const{left:t,right:s,top:i,bottom:o}=this.getters.expandZone(d.id,e);return{left:Math.max(0,t),right:Math.min(d.cols.length-1,s),top:Math.max(0,i),bottom:Math.min(d.rows.length-1,o)}},{col:p,row:g}=this.getReferencePosition();let f=0;for(;null!==h;){if(f++,e<0){const t=this.getNextAvailableCol(e,a-(f-1),g);h=p<=a-f?u({top:l,left:r,bottom:c,right:t}):null}if(e>0){const t=this.getNextAvailableCol(e,r+(f-1),g);h=r+f<=p?u({top:l,left:t,bottom:c,right:a}):null}if(t<0){const e=this.getNextAvailableRow(t,p,c-(f-1));h=g<=c-f?u({top:l,left:r,bottom:e,right:a}):null}if(t>0){const e=this.getNextAvailableRow(t,p,l+(f-1));h=l+f<=g?u({top:e,left:r,bottom:c,right:a}):null}if(h=h?Ks(h):h,h&&!Bs(h,s.anchorZone))return i=this.updateSelectionZones(h),void this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h})}h=u(Ps({top:n,bottom:n,left:o,right:o},Ks({top:this.getNextAvailableRow(t,p,l),left:this.getNextAvailableCol(e,r,g),bottom:this.getNextAvailableRow(t,p,c),right:this.getNextAvailableCol(e,a,g)}))),Bs(h,s.anchorZone)||(i=this.updateSelectionZones(h),this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h}))}addCellToSelection(e,t){const s=this.selection,[i,o]=s.anchor,n={left:Math.min(i,e),top:Math.min(o,t),right:Math.max(i,e),bottom:Math.max(o,t)},r=this.updateSelectionZones(n);this.dispatch("SET_SELECTION",{zones:r,anchor:[i,o],anchorZone:n})}ensureSelectionValidity(){const{anchor:e,zones:t,anchorZone:s}=this.clipSelection(this.getActiveSheetId(),this.selection);this.setSelection(e,t,s);const i=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of i)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:s,anchorZone:i}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:s,anchorZone:i},activeCol:t[0],activeRow:t[1]}}}clipSelection(e,t){const s=this.getters.getSheet(e),i=s.cols.length-1,o=s.rows.length-1,n=t.zones.map((e=>({left:ps(e.left,0,i),right:ps(e.right,0,i),top:ps(e.top,0,o),bottom:ps(e.bottom,0,o)})));return{anchor:[ps(t.anchor[0],0,i),ps(t.anchor[1],0,o)],zones:n,anchorZone:{left:ps(t.anchorZone.left,0,i),right:ps(t.anchorZone.right,0,i),top:ps(t.anchorZone.top,0,o),bottom:ps(t.anchorZone.bottom,0,o)}}}onColumnsRemoved(e){const t=Us(this.getSelectedZone(),"left",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onRowsRemoved(e){const t=Us(this.getSelectedZone(),"top",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onAddElements(e){const t=Ds(this.getSelectedZone(),"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.setSelection([t.left,t.top],[t],t,!0)}updateSelectionZones(e){let t=[...this.selection.zones];const s=this.selection.anchorZone,i=t.findIndex((e=>Bs(e,s)));return i>=0&&(t[i]=e),t}activateNextSheet(e){const t=this.getters.getSheets().map((e=>e.id)),s=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[s]})}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:"before"});const s="COL"===e.dimension,i=e.elements[0],o=e.elements[t-1],n=e.base<i,r=n&&s?t:0,a=n&&!s?t:0,l=this.getters.getSheet(e.sheetId);this.dispatch("CUT",{target:[{left:s?i+r:0,right:s?o+r:l.cols.length-1,top:s?0:i+a,bottom:s?l.rows.length-1:o+a}]}),this.dispatch("PASTE",{target:[{left:s?e.base:0,right:s?e.base+t-1:l.cols.length-1,top:s?0:e.base,bottom:s?l.rows.length-1:e.base+t-1}]});const c=n?e.elements.map((e=>e+t)):e.elements;let h=e.base;for(const t of c){const s="COL"===e.dimension?this.getters.getCol(e.sheetId,t).size:this.getters.getRow(e.sheetId,t).size;this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:s,elements:[h]}),h+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:c})}isMoveElementAllowed(e){const t="COL"===e.dimension,s=e.elements[0],i=e.elements[e.elements.length-1],o=e.sheetId,n=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return n(o,s-1,s)||n(o,i,i+1)||n(o,e.base-1,e.base)?2:0}drawGrid(e){if("inactive"!==this.getters.getEditionMode())return;const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getSelectedZones();s.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;s.fillStyle=n?"#f3f7fe":"#e9f0ff",s.strokeStyle=p,s.lineWidth=1.5*i,s.globalCompositeOperation="multiply";for(const e of o){const[i,o,n,r]=this.getters.getRect(e,t);s.fillRect(i,o,n,r),s.strokeRect(i,o,n,r)}s.globalCompositeOperation="source-over";const r=this.getters.getActiveSheetId(),[a,l]=this.getPosition();let c;s.strokeStyle=p,s.lineWidth=3*i,c=this.getters.isInMerge(r,a,l)?this.getters.getMerge(r,a,l):{top:l,bottom:l,left:a,right:a};const[h,d,u,g]=this.getters.getRect(c,t);u>0&&g>0&&s.strokeRect(h,d,u,g)}}xh.layers=[5],xh.modes=["normal"],xh.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getAggregate","getSelectedFigureId","getVisibleFigures","getSelection","getPosition","getSheetPosition","getSelectionMode","isSelected","getElementsFromSelection"];const Rh=a("The cell you are trying to edit has been deleted.");class Lh extends Sh{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.multiSelectionInitialStart=0,this.initialContent="",this.previousRef="",this.previousRange=void 0,this.colorIndexByRange={}}allowDispatch(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":return this.validateSelection(this.currentContent.length,e.start,e.end);case"SET_CURRENT_CONTENT":return e.selection?this.validateSelection(e.content.length,e.selection.start,e.selection.end):0;case"START_EDITION":if(e.selection){const t=this.getters.getActiveCell(),s=e.text||(null==t?void 0:t.composerContent)||"";return this.validateSelection(s.length,e.selection.start,e.selection.end)}return 0;default:return 0}}handle(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":this.selectionStart=e.start,this.selectionEnd=e.end;break;case"STOP_COMPOSER_RANGE_SELECTION":this.isSelectingForComposer()&&(this.mode="editing");break;case"START_EDITION":this.startEdition(e.text,e.selection);break;case"STOP_EDITION":e.cancel?(this.cancelEdition(),this.resetContent()):this.stopEdition();break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0);break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEdition(),this.resetContent();break;case"SELECT_CELL":case"SET_SELECTION":case"MOVE_POSITION":switch(this.mode){case"editing":this.dispatch("STOP_EDITION");break;case"waitingForRangeSelection":this.insertSelectedRange();break;case"rangeSelected":switch(e.type){case"MOVE_POSITION":this.replaceAllSelectedRanges();break;case"SELECT_CELL":this.getters.getSelectionMode()===Th.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges();break;case"SET_SELECTION":e.strict?this.getters.getSelectionMode()===Th.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges():this.replaceSelectedRange()}}break;case"ADD_COLUMNS_ROWS":this.onAddElements(e);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);break;case"START_CHANGE_HIGHLIGHT":this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const t=this.currentTokens.filter((e=>"SYMBOL"===e.type)).find((t=>{let s=t.value;const{xc:i,sheetName:o}=es(s),n=o||this.getters.getSheetName(this.sheet),r=this.getters.getActiveSheetId();return Bs(this.getters.expandZone(r,ks(i)),e.zone)&&this.getters.getSheetName(r)===n}));this.previousRef=t.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=t.start;break;case"CHANGE_HIGHLIGHT":const s=this.getZoneReference(e.zone,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(s),this.previousRef=s,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheet)||"inactive"===this.mode||(this.cancelEdition(),this.resetContent(),this.ui.notifyUser(Rh))}}getEditionMode(){return this.mode}getCurrentContent(){if("inactive"===this.mode){const e=this.getters.getActiveCell();return(null==e?void 0:e.composerContent)||""}return this.currentContent}getEditionSheet(){return this.sheet}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}isSelectingForComposer(){return"waitingForRangeSelection"===this.mode||"rangeSelected"===this.mode||"resettingPosition"===this.mode}getCurrentTokens(){return this.currentTokens}getTokenAtCursor(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return e===t&&0===t?void 0:this.currentTokens.find((s=>s.start<=e&&s.end>=t))}validateSelection(e,t,s){return t>=0&&t<=e&&s>=0&&s<=e?0:31}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Rh);const{top:t,left:s}=Us({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",e.elements);this.col=s,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Rh);const{top:t,left:s}=Us({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",e.elements);this.col=s,this.row=t}onAddElements(e){const{top:t,left:s}=Ds({left:this.col,right:this.col,top:this.row,bottom:this.row},"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.col=s,this.row=t}startComposerRangeSelection(){this.mode="resettingPosition",this.sheet===this.getters.getActiveSheetId()&&this.dispatch("SELECT_CELL",{col:this.col,row:this.row}),this.mode="waitingForRangeSelection",this.multiSelectionInitialStart=this.selectionStart}startEdition(e,t){const s=this.getters.getActiveCell();this.initialContent=(null==s?void 0:s.composerContent)||"",this.mode="editing";const[i,o]=this.getters.getPosition();this.col=i,this.row=o,this.sheet=this.getters.getActiveSheetId(),this.setContent(e||this.initialContent,t),this.colorIndexByRange={}}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();const e=this.getters.getActiveSheetId(),t=this.getters.getSheets().find((e=>e.id===this.sheet)).id,[s,i]=this.getters.getMainCell(t,this.col,this.row);let o=this.currentContent;if(!(this.initialContent!==o))return;if(o){const t=this.getters.getCell(e,s,i);if(o.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,s=e-t;s>0&&(o+=new Array(s).fill(")").join(""))}else(null==t?void 0:t.isLink())&&(o=ys(o,t.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheet,col:s,row:i,content:o})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheet,content:"",col:s,row:i});e!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheet}),this.setContent("")}}cancelEdition(){this.mode="inactive"}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,s){e=e.replace(/[\r\n]/g,"");const i=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(i||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?zr(e):[],this.currentTokens.length>100&&s&&this.ui.notifyUser(a("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(){const e=Math.min(this.selectionStart,this.selectionEnd),t=this.getZoneReference(this.getters.getSelectedZone());if("waitingForRangeSelection"===this.mode)return this.insertText(t,e),this.selectionInitialStart=e,void(this.mode="rangeSelected");this.insertText(","+t,e),this.selectionInitialStart=e+1}replaceSelectedRange(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.selectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone()))}replaceAllSelectedRanges(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.multiSelectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone())),this.selectionInitialStart=this.multiSelectionInitialStart}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const s=this.getters.getActiveSheetId();let i=this.getters.zoneToXC(s,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){i=`${us(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${i}`}return i}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),s=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,s)}replaceText(e,t,s){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(s,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const s=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),i=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:s,selection:{start:i,end:i}})}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=[],t={};for(let s of this.currentTokens.filter((e=>"SYMBOL"===e.type))){let i=s.value;const{xc:o,sheetName:n}=es(i);if(Jt.test(o)){const s=(n?`${n}!`:`${this.getters.getSheetName(this.getters.getEditionSheet())}!`)+o.replace(/\$/g,"");e.push(s);const i=this.colorIndexByRange[s];void 0!==i&&(t[s]=i)}}this.colorIndexByRange=t;let s=Object.values(t),i=0;return e.map((e=>{if(void 0===this.colorIndexByRange[e]){for(;s.includes(i);)i++;s.push(i),this.colorIndexByRange[e]=i}return[e,qt[this.colorIndexByRange[e]%qt.length]]}))}canStartComposerRangeSelection(){if("editing"!==this.mode&&this.selectionStart===this.selectionEnd)return!1;if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(e){const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let s=t,i=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type||s<1)return!1;s--,i=this.currentTokens[s]}for(s=t+1,i=this.currentTokens[s];i&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type)return!1;s++,i=this.currentTokens[s]}s++,i=this.currentTokens[s]}return!0}return!1}}Lh.getters=["getEditionMode","isSelectingForComposer","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights"],Lh.modes=["normal"];const Mh=rr.mapping;class Ah extends Sh{constructor(e,t,s,i){super(e,t,s,i),this.isUpToDate=new Set,this.evalContext=i.evalContext,i.dataSources.on("data-loaded",this,(()=>{this.dispatch("EVALUATE_CELLS",{sheetId:this.getters.getActiveSheetId()})}))}handle(e){switch(Fe.has(e.type)&&this.isUpToDate.clear(),e.type){case"UPDATE_CELL":"content"in e&&this.isUpToDate.clear();break;case"ACTIVATE_SHEET":this.evaluate(e.sheetIdTo),this.isUpToDate.add(e.sheetIdTo);break;case"EVALUATE_CELLS":this.evaluate(e.sheetId),this.isUpToDate.add(e.sheetId);break;case"EVALUATE_ALL_SHEETS":this.evaluateAllSheets()}}finalize(){const e=this.getters.getActiveSheetId();this.isUpToDate.has(e)||(this.evaluate(e),this.isUpToDate.add(e))}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{let s=Zr(e);const i=Br(s),o=this.getFormulaParameters((()=>{})),n=[];for(let e of s.dependencies.references)n.push(this.getters.getRangeFromSheetXC(t,e));return i({...s.dependencies,references:n},t,...o)}catch(e){return"#ERROR"}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Gs(e.zone,t,(e=>this.getters.getCellText(e,this.getters.shouldShowFormulas())),"")}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Gs(e.zone,t,(e=>e.evaluated.value))}evaluate(e){const t=this.getters.getCells(e),s=this.getFormulaParameters(o),i={};for(let s of Object.values(t))o(s,e);function o(e,t){if(!e.isFormula())return;const o=e.id;if(o in i)null===i[o]&&e.assignError("#CYCLE",a("Circular reference"));else{i[o]=null;try{if(s[2].__originCellXC=()=>{const e=s[2].getters.getCellPosition(o);return is(e.col,e.row)},e.assignValue(e.compiledFormula(e.dependencies,t,...s)),Array.isArray(e.evaluated.value))throw new Error(a("This formula depends on invalid values"))}catch(t){!function(e,t){if(e instanceof Error||(e=new Error(e)),"#CYCLE"!==t.evaluated.value){t.assignValue("#ERROR");const i=s[2].__lastFnCalled||"";t.assignError("#ERROR",e.message.replace("[[FUNCTION_NAME]]",i))}}(t,e)}i[o]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Mh),this.evalContext,{getters:this.getters});function s(t,s){if(e(t,s),t.evaluated.type===ke.error)throw new Error(a("This formula depends on invalid values"));return t.evaluated.value}function i(e){o(e);const i=t.getters.getSheet(e.sheetId),n={top:0,bottom:i.rows.length-1,left:0,right:i.cols.length-1},r=[],a=function(e,t){if(Vs(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom,t.bottom),right:Math.min(e.right,t.right)}}(e.zone,n);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const o=[];for(let n=a.top;n<=a.bottom;n++){const r=t.getters.getCell(e.sheetId,i,n);o.push(r?s(r,e.sheetId):void 0)}r.push(o)}return r}function o(e){if(!Fs(e.zone))throw new Error(a("Invalid reference"));if(e.invalidSheetName)throw new Error(a("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,i,n,r,l,c){const h=i[e];if(o(h),r)return t.getters.getRangeString(h,n);if(h.zone.bottom!==h.zone.top||h.zone.left!==h.zone.right)throw new Error(c?a("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",l.toString(),c.toString()):a("Function %s expects its parameters to be single values or single cell references, not ranges.",l.toString()));return function(e){var i;const o=null===(i=t.getters.getSheet(e.sheetId).rows[e.zone.top])||void 0===i?void 0:i.cells[e.zone.left];return!o||o.isEmpty()?null:s(o,e.sheetId)}(h)},function(e,t,s){return i(t[e])},t]}evaluateAllSheets(){for(const e of this.getters.getVisibleSheets())this.evaluate(e),this.isUpToDate.add(e)}}Ah.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"],Ah.modes=["normal"];const _h=["rgb(31,119,180)","rgb(255,127,14)","rgb(174,199,232)","rgb(255,187,120)","rgb(44,160,44)","rgb(152,223,138)","rgb(214,39,40)","rgb(255,152,150)","rgb(148,103,189)","rgb(197,176,213)","rgb(140,86,75)","rgb(196,156,148)","rgb(227,119,194)","rgb(247,182,210)","rgb(127,127,127)","rgb(199,199,199)","rgb(188,189,34)","rgb(219,219,141)","rgb(23,190,207)","rgb(158,218,229)"];class Oh{constructor(){this.graphColorIndex=0}next(){return _h[this.graphColorIndex++%_h.length]}}class Nh extends Sh{constructor(){super(...arguments),this.chartRuntime={},this.outOfDate=new Set}handle(e){if(Fe.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type&&"content"in e)for(let e of Object.keys(this.chartRuntime))this.outOfDate.add(e);switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const t=this.getters.getChartDefinition(e.id);this.chartRuntime[e.id]=this.mapDefinitionToRuntime(t);break;case"DELETE_FIGURE":delete this.chartRuntime[e.id];break;case"REFRESH_CHART":this.evaluateUsedSheets([e.id]),this.outOfDate.add(e.id);break;case"ACTIVATE_SHEET":const s=this.getters.getChartsIdBySheet(e.sheetIdTo);this.evaluateUsedSheets(s);break;case"DELETE_SHEET":for(let e of Object.keys(this.chartRuntime))this.getters.getChartDefinition(e)||delete this.chartRuntime[e]}}getChartRuntime(e){if(this.outOfDate.has(e)||!(e in this.chartRuntime)){const t=this.getters.getChartDefinition(e);if(void 0===t)return;this.chartRuntime[e]=this.mapDefinitionToRuntime(t),this.outOfDate.delete(e)}return this.chartRuntime[e]}truncateLabel(e){return e?e.length>20?e.substring(0,20)+"…":e:""}getDefaultConfiguration(e,t){const s={};e.labelRange||1!==e.dataSets.length?s.position=e.legendPosition:s.display=!1;const i={type:e.type,options:{legend:s,responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:e.title?10:25,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!!e.title,fontSize:22,fontStyle:"normal",text:e.title}},data:{labels:t.map(this.truncateLabel),datasets:[]}};return"pie"!==e.type?(i.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{position:e.verticalAxisPosition,ticks:{beginAtZero:!0}}]},"bar"===e.type&&e.stackedBar&&(i.options.scales.xAxes[0].stacked=!0,i.options.scales.yAxes[0].stacked=!0)):i.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},i}getSheetIdsUsedInChart(e){const t=new Set;for(let s of e.dataSets)t.add(s.dataRange.sheetId);return e.labelRange&&t.add(e.labelRange.sheetId),t}evaluateUsedSheets(e){const t=new Set;for(let s of e){const e=this.getters.getChartDefinition(s);(void 0!==e?this.getSheetIdsUsedInChart(e):[]).forEach((e=>{e!==this.getters.getActiveSheetId()&&t.add(e)}))}for(let e of t)this.dispatch("EVALUATE_CELLS",{sheetId:e})}mapDefinitionToRuntime(e){let t=[];if(e.labelRange)e.labelRange.invalidXc||e.labelRange.invalidSheetName||(t=this.getters.getRangeFormattedValues(e.labelRange).flat(1));else if(1===e.dataSets.length)for(let s=0;s<this.getData(e.dataSets[0],e.sheetId).length;s++)t.push("");else if(e.dataSets[0]){t=fs(0,this.getData(e.dataSets[0],e.sheetId).length).map((e=>e.toString()))}const s=this.getDefaultConfiguration(e,t),i=new Oh,o=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.getData(t,e.sheetId).length)));for(let e=0;e<=t;e++)o.push(i.next())}for(const[t,n]of Object.entries(e.dataSets)){let r;if(n.labelCell){const e=n.labelCell,s=e?this.getters.getCell(e.sheetId,e.zone.left,e.zone.top):void 0;r=s&&e?this.truncateLabel(s.formattedValue):r=`${dc.Series} ${parseInt(t)+1}`}else r=r=`${dc.Series} ${parseInt(t)+1}`;const a="pie"!==e.type?i.next():"#FFFFFF",l={label:r,data:n.dataRange?this.getData(n,e.sheetId):[],lineTension:0,borderColor:a,backgroundColor:a};"pie"===e.type&&(l.backgroundColor=o),s.data.datasets.push(l)}return s}getData(e,t){if(e.dataRange){const t=e.labelCell?[$s(e.labelCell.zone)]:[],s=zs([$s(e.dataRange.zone)],t)[0];if(void 0===s)return[];const i=this.getters.getRangeFromSheetXC(e.dataRange.sheetId,s);return this.getters.getRangeValues(i).flat(1)}return[]}}Nh.getters=["getChartRuntime"],Nh.modes=["normal"];class kh extends Sh{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new oi,this.rulePredicate={CellIsRule:(e,t)=>{var s,i,o,n,r,l;if(e&&e.evaluated.type===ke.error)return!1;const c=t.values.map(jr);switch(t.operator){case"IsEmpty":return!Ls(e)||""===(null===(s=e.evaluated.value)||void 0===s?void 0:s.toString().trim());case"IsNotEmpty":return Ls(e)&&""!==(null===(i=e.evaluated.value)||void 0===i?void 0:i.toString().trim());case"BeginsWith":return!(!e&&""===c[0])&&(Ls(e)&&(null===(o=e.evaluated.value)||void 0===o?void 0:o.toString().startsWith(c[0].toString())));case"EndsWith":return!(!e&&""===c[0])&&(Ls(e)&&(null===(n=e.evaluated.value)||void 0===n?void 0:n.toString().endsWith(c[0].toString())));case"Between":return Ls(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1];case"NotBetween":return!(Ls(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1]);case"ContainsText":return Ls(e)&&(null===(r=e.evaluated.value)||void 0===r?void 0:r.toString().indexOf(c[0].toString()))>-1;case"NotContains":return!Ls(e)||!e.evaluated.value||-1==(null===(l=e.evaluated.value)||void 0===l?void 0:l.toString().indexOf(c[0].toString()));case"GreaterThan":return Ls(e)&&e.evaluated.value>c[0];case"GreaterThanOrEqual":return Ls(e)&&e.evaluated.value>=c[0];case"LessThan":return Ls(e)&&e.evaluated.value<c[0];case"LessThanOrEqual":return Ls(e)&&e.evaluated.value<=c[0];case"NotEqual":return!(!Ls(e)&&""===c[0])&&(Ls(e)&&e.evaluated.value!==c[0]);case"Equal":return!e&&""===c[0]||Ls(e)&&e.evaluated.value===c[0];default:console.warn(a("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch(e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const s=this.getters.getActiveSheetId(),i=this.getters.getRulesByCell(s,e.originCol,e.originRow);for(const t of i)this.adaptRules(s,t,[is(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation);break;case"DUPLICATE_SHEET":case"CREATE_SHEET":case"DELETE_SHEET":case"ADD_CONDITIONAL_FORMAT":case"REMOVE_CONDITIONAL_FORMAT":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":case"DELETE_CELL":case"INSERT_CELL":this.isStale=!0}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getConditionalStyle(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedStyles[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}getConditionalIcon(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedIcons[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const s=this.computedStyles[t];for(let i of this.getters.getConditionalFormats(t))switch(i.rule.type){case"ColorScaleRule":for(let e of i.ranges)this.applyColorScale(e,i.rule);break;case"IconSetRule":for(let e of i.ranges)this.applyIcon(e,i.rule);break;default:for(let o of i.ranges){const n=ks(o);for(let o=n.top;o<=n.bottom;o++)for(let r=n.left;r<=n.right;r++){const n=this.rulePredicate[i.rule.type];let a=this.getters.getCell(t,r,o);n&&n(a,i.rule)&&(s[r]||(s[r]=[]),s[r][o]=Object.assign((null===(e=s[r])||void 0===e?void 0:e[o])||{},i.rule.style))}}}}parsePoint(e,t,s){switch(t.type){case"value":return this.getters.evaluateFormula(`=${s}(${e})`);case"number":return Number(t.value);case"percentage":const i=this.getters.evaluateFormula(`=min(${e})`);return i+(this.getters.evaluateFormula(`=max(${e})`)-i)*Number(t.value)/100;case"percentile":return this.getters.evaluateFormula(`=PERCENTILE(${e},${Number(t.value)/100})`);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof o?o:null;default:return null}}applyIcon(e,t){const s=this.parsePoint(e,t.lowerInflectionPoint),i=this.parsePoint(e,t.upperInflectionPoint);if(null===s||null===i||s>i)return;const o=ks(e),n=this.getters.getActiveSheetId(),r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=o.top;e<=o.bottom;e++)for(let l=o.left;l<=o.right;l++){const o=this.getters.getCell(n,l,e);if((null==o?void 0:o.evaluated.type)!==ke.number)continue;const c=this.computeIcon(o.evaluated.value,i,t.upperInflectionPoint.operator,s,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,s,i,o,n){return"ge"===s&&e>=t||"gt"===s&&e>t?n[0]:"ge"===o&&e>=i||"gt"===o&&e>i?n[1]:n[2]}applyColorScale(e,t){var s;const i=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,n=this.parsePoint(e,t.maximum,"max");if(null===i||null===n||i>=n||o&&(i>=o||o>=n))return;const r=ks(e),a=this.getters.getActiveSheetId(),l=this.computedStyles[a],c=[];t.midpoint&&o?(c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.midpoint.color,t.maximum.color)})):c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,n,t.minimum.color,t.maximum.color)});for(let e=r.top;e<=r.bottom;e++)for(let t=r.left;t<=r.right;t++){const r=this.getters.getCell(a,t,e);if((null==r?void 0:r.evaluated.type)===ke.number){const a=ps(r.evaluated.value,i,n);let h;h=2===c.length&&o?a<=o?this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(a,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(s=l[t])||void 0===s?void 0:s[e])||{},l[t][e].fillColor="#"+jt(h)}}}computeColorDiffUnits(e,t,s,i){const o=t-e;return[((s>>16)%256-(i>>16)%256)/o,((s>>8)%256-(i>>8)%256)/o,(s%256-i%256)/o]}colorCell(e,t,s,i){const[o,n,r]=i;return Math.round((s>>16)%256-o*(e-t))<<16|Math.round((s>>8)%256-n*(e-t))<<8|Math.round(s%256-r*(e-t))}adaptRules(e,t,s,i){if(0===s.length&&0===i.length)return;const o=this.getters.getConditionalFormats(e),n=o.findIndex((e=>e.id===t.id));let r=[];n>-1&&(r=o[n].ranges),r=r.concat(s);const a=zs(r,i);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},target:a.map(ks),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,s){const i=is(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let n of o.ranges)if(Hs(e.col,e.row,ks(n))){const n=o,r=[];if("CUT"===s&&r.push(is(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,n,[i],r);else{this.adaptRules(e.sheetId,n,[],r);const s=this.getCFToCopyTo(t.sheetId,n);this.adaptRules(t.sheetId,s,[i],[])}}}getCFToCopyTo(e,t){const s=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&As(e.rule,t.rule)));return s||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}kh.getters=["getConditionalStyle","getConditionalIcon"],kh.modes=["normal"];var Fh;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(Fh||(Fh={}));class $h extends Sh{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1},this.toSearch=""}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(Fh.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(Fh.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith,e.replaceOptions);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith,e.replaceOptions);break;case"ACTIVATE_SHEET":case"REFRESH_SEARCH":this.refreshSearch()}}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(Fh.current)}updateRegex(){let e=hs(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),s=[];if(this.toSearch)for(const e of Object.values(t))if(e&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas&&e.isFormula()?e.content:String(e.evaluated.value))){const t=this.getters.getCellPosition(e.id),i={col:t.col,row:t.row,selected:!1};s.push(i)}return s.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let s;s=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,s=(s%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===s||(this.selectedMatchIndex=s,this.dispatch("SELECT_CELL",{col:t[s].col,row:t[s].row}));for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1}}replace(e,t){if(this.replaceOptions=t,null===this.selectedMatchIndex||!this.currentSearchRegex)return;const s=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),o=this.getters.getCell(i,s.col,s.row),n=this.toReplace(o,i);if(o&&n){const t=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),i=n.toString().replace(t,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:s.col,row:s.row,content:i}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell(Fh.current)}else this.selectNextCell(Fh.next)}replaceAll(e,t){const s=this.searchMatches.length;for(let i=0;i<s;i++)this.replace(e,t)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.replaceOptions.modifyFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t,viewport:s}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge(i,e.col,e.row),n=o?o.left:e.col,r=o?o.right:e.col,a=o?o.top:e.row,l=o?o.bottom:e.row,[c,h,d,u]=this.getters.getRect({top:a,left:n,right:r,bottom:l},s);d>0&&u>0&&(t.fillStyle="#8B008B33",t.fillRect(c,h,d,u),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(c,h,d,u)))}}}$h.layers=[3],$h.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Dh extends Sh{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,s){const i=this.searchNumberFormat(e,t);if(void 0!==i){const o=this.changeDecimalFormat(i,s);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var s;for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++){const i=this.getters.getCell(e,o,t);if((null==i?void 0:i.evaluated.type)===ke.number&&!(null===(s=i.format)||void 0===s?void 0:s.match(A)))return i.format||this.setDefaultNumberFormat(i.evaluated.value)}}setDefaultNumberFormat(e){const t=e.toString().split(".");return 1===t.length?"0":"0."+Array(t[1].length+1).join("0")}changeDecimalFormat(e,t){const s=Math.sign(t),i=e.split(";");let o=[];for(let e of i){const t=e.indexOf("."),i=e.toUpperCase().indexOf("E");let n;const r=i>-1?e.slice(0,i):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?s>0?n=a<ne?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(n=e.slice(0,l)+e.slice(l+1),1===a&&(n=n.slice(0,t)+n.slice(t+1))):n=e:n=e,o.push(n)}return o.join(";")}}Dh.modes=["normal"];class Uh extends Sh{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){if(0===e.length)return[];const t=this.getters.getActiveSheetId(),s=[];for(let[i,o]of e){const{xc:e,sheetName:n}=es(i),r=n?this.getters.getSheetIdByName(n):t;if(r){let i=ks(e);const{height:n,width:a}=Ws(i);i=n*a==1?this.getters.expandZone(t,ks(e)):i,s.push({zone:i,color:o,sheet:r})}}return s.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getSheet(e.sheet).rows.length&&e.zone.right<this.getters.getSheet(e.sheet).cols.length))}drawGrid(e){const{ctx:t,viewport:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;for(let e of this.getHighlights().filter(((e,t)=>this.getHighlights().findIndex((t=>Bs(t.zone,e.zone)&&t.sheet===o))===t))){const[i,o,r,a]=this.getters.getRect(e.zone,s);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,r-n,a-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,r-2*n,a-2*n))}}}function Ph(e,t){return e.isFormula()&&t?"left":e.defaultAlign}function Bh(e,t){let s=0,i=e.length-1;for(;s<=i;){const o=Math.floor((s+i)/2),n=e[o];if(t<n.start)i=o-1;else if(t>n.end)s=o+1;else{if(!n.isHidden)return o;s+=1}}return-1}Uh.modes=["normal"],Uh.layers=[1],Uh.getters=["getHighlights"];class Vh extends Sh{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t,s){if(e<m)return-1;const i=(s||this.getters.getActiveSheet()).cols;return Bh(i,e-m+i[t].start+1)}getRowIndex(e,t,s){if(e<f)return-1;const i=(s||this.getters.getActiveSheet()).rows;return Bh(i,e-f+i[t].start+1)}getRect(e,t){const{left:s,top:i,right:o,bottom:n}=e;let{offsetY:r,offsetX:a}=t;a-=m,r-=f;const{cols:l,rows:c}=this.getters.getActiveSheet(),h=Math.max(l[s].start-a,m),d=l[o].end-a-h,u=Math.max(c[i].start-r,f);return[h,u,d,c[n].end-r-u]}isVisibleInViewport(e,t,s){const{right:i,left:o,top:n,bottom:r}=s;return t<=r&&t>=n&&e>=o&&e<=i}getEdgeScrollCol(e){let t=!1,s=0,i=0;const{width:o}=this.getters.getViewportDimension(),{width:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{left:r,offsetX:a}=this.getters.getActiveSnappedViewport();return e<m&&r>0?(t=!0,s=-1,i=as(m-e)):e>o&&a<n-o&&(t=!0,s=1,i=as(e-o)),{canEdgeScroll:t,direction:s,delay:i}}getEdgeScrollRow(e){let t=!1,s=0,i=0;const{height:o}=this.getters.getViewportDimension(),{height:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{top:r,offsetY:a}=this.getters.getActiveSnappedViewport();return e<f&&r>0?(t=!0,s=-1,i=as(f-e)):e>o&&a<n-o&&(t=!0,s=1,i=as(e-o)),{canEdgeScroll:t,direction:s,delay:i}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e);break;case 7:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,top:r,left:a,bottom:l,right:c}=s;const{width:h,height:d}=this.getters.getViewportDimension(),{cols:u,rows:p,id:g}=this.getters.getActiveSheet();if(t.fillStyle="white",t.fillRect(0,0,h,d),o-=m,n-=f,!this.getters.getGridLinesVisibility(g))return;t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();const v=Math.min(d,p[l].end-n);for(let e=a;e<=c;e++){if(u[e].isHidden)continue;const s=u[e].end-o;t.moveTo(s,0),t.lineTo(s,v)}const E=Math.min(h,u[c].end-o);for(let e=r;e<=l;e++){if(p[e].isHidden)continue;const s=p[e].end-n;t.moveTo(0,s),t.lineTo(E,s)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:s}=e;t.lineWidth=.3*s;const i=.1*s;t.strokeStyle="#111";const o=this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());for(let e of this.boxes){let s=e.style;s&&s.fillColor&&"#ffffff"!==s.fillColor&&(t.fillStyle=s.fillColor,t.fillRect(e.x,e.y,e.width,e.height),o&&t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawBorders(e){const{ctx:t,thinLineWidth:s}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:s,y:o,width:n,height:r}=e;t.left&&i(t.left,s,o,s,o+r),t.top&&i(t.top,s,o,s+n,o),t.right&&i(t.right,s+n,o,s+n,o+r),t.bottom&&i(t.bottom,s,o+r,s+n,o+r)}}function i([e,i],o,n,r,a){t.strokeStyle=i,t.lineWidth=("thin"===e?2:3)*s,t.beginPath(),t.moveTo(o,n),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:s}=e;let i;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const o=e.style||{},n=e.align,r=o.italic?"italic ":"",a=o.bold?"bold":T,l=o.fontSize||x,c=cs[l],h=`${r}${a} ${c}px ${R}`;let d;h!==i&&(i=h,t.font=h),t.fillStyle=o.textColor||"#000";let u=e.y+e.height/2+1;d="left"===n?e.x+(e.image?e.image.size+2*I:4):"right"===n?e.x+e.width-4:e.x+e.width/2,t.textAlign=n,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(d),Math.round(u)),(o.strikethrough||o.underline)&&("right"===n?d-=e.textWidth:"center"===n&&(d-=e.textWidth/2),o.strikethrough&&t.fillRect(d,u,e.textWidth,2.6*s),o.underline&&(u=e.y+e.height/2+1+c/2,t.fillRect(d,u,e.textWidth,1.3*s))),e.clipRect&&t.restore()}}async drawIcon(e){const{ctx:t}=e;for(let e of this.boxes)if(e.image){let s=e.x,i=e.y;const o=e.image.image,n=e.image.size,r=(e.height-n)/2;e.image.clipIcon&&(t.save(),t.beginPath(),t.rect(...e.image.clipIcon),t.clip()),t.drawImage(o,s+I,i+r,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,left:r,top:a,right:l,bottom:p}=s;const{width:g,height:v}=this.getters.getViewportDimension();o-=m,n-=f;const E=this.getters.getSelectedZones(),{cols:b,rows:S}=this.getters.getActiveSheet(),C=this.getters.getActiveCols(),I=this.getters.getActiveRows();t.fillStyle=c,t.font=`400 11px ${R}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333",t.fillRect(0,0,g,f),t.fillRect(0,0,m,v),t.fillStyle=h;for(let e of E){const s=Math.max(m,b[e.left].start-o),i=Math.max(m,b[e.right].end-o),r=Math.max(f,S[e.top].start-n),a=Math.max(f,S[e.bottom].end-n);t.fillStyle=C.has(e.left)?d:h,t.fillRect(s,0,i-s,f),t.fillStyle=I.has(e.top)?d:h,t.fillRect(0,r,m,a-r)}t.beginPath(),t.moveTo(m,0),t.lineTo(m,v),t.moveTo(0,f),t.lineTo(g,f),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=r;e<=l;e++){const s=b[e];s.isHidden||(t.fillStyle=C.has(e)?"#fff":u,t.fillText(s.name,(s.start+s.end)/2-o,13),t.moveTo(s.end-o,0),t.lineTo(s.end-o,f))}for(let e=a;e<=p;e++){const s=S[e];s.isHidden||(t.fillStyle=I.has(e)?"#fff":u,t.fillText(s.name,24,(s.start+s.end)/2-n),t.moveTo(0,s.end-n),t.lineTo(m,s.end-n))}t.stroke()}hasContent(e,t){const s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);return i&&!i.isEmpty()||this.getters.isInMerge(s,e,t)}getGridBoxes(e){const{viewport:t}=e;let{right:s,left:i,top:o,bottom:n,offsetX:r,offsetY:a}=t;r-=m,a-=f;const l=this.getters.shouldShowFormulas(),c=[],{cols:h,rows:d,id:u}=this.getters.getActiveSheet();for(let e=o;e<=n;e++){const t=d[e];if(!t.isHidden)for(let o=i;o<=s;o++){const n=h[o];if(n.isHidden)continue;let d=t.cells[o];const p=this.getters.getCellBorder(u,o,e),g=this.getters.getConditionalStyle(o,e),f=this.getters.getConditionalIcon(o,e);if(!this.getters.isInMerge(u,o,e))if(d){const u=this.getters.getCellText(d,l);let m=this.getters.getCellStyle(d);g&&(m=Object.assign({},m,g));let v=u?m&&m.align||Ph(d,l):void 0,E=null,b=null;const S=this.getters.getTextWidth(d),C=m.fontSize||x,y=cs[C],w=f?y+2*I:0,T=w+S>h[o].size||cs[C]>t.size;if(T&&d.evaluated.type===ke.number&&(v="center"!==v?"left":v),f){const e=n.end-n.start;E=[n.start-r+w,t.start-a,Math.max(0,e-w),t.size],b=[n.start-r,t.start-a,Math.min(w,e),t.size]}else if(T){let l,c;switch(v){case"left":for(l=o;l<s&&!this.hasContent(l+1,e);)l++;c=h[l].end-n.start,(c<S||cs[C]>t.size)&&(E=[n.start-r,t.start-a,c,t.size]);break;case"right":for(l=o;l>i&&!this.hasContent(l-1,e);)l--;c=n.end-h[l].start,(c<S||cs[C]>t.size)&&(E=[h[l].start-r,t.start-a,c,t.size]);break;case"center":let d=o;for(;d>i&&!this.hasContent(d-1,e);)d--;let u=o;for(;u<s&&!this.hasContent(u+1,e);)u++;const p=Math.min(d,o),g=Math.max(u,o);c=h[g].end-h[p].start,(c<S||p===o||g===o||cs[C]>t.size)&&(E=[h[p].start-r,t.start-a,c,t.size])}}c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:u,textWidth:S,border:p,style:m,align:v,clipRect:E,error:d.evaluated.type===ke.error?d.evaluated.error:void 0,image:f?{type:"icon",size:y,clipIcon:b,image:zl[f].img}:void 0})}else c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:"",textWidth:0,border:p,style:g||null,align:void 0,clipRect:null,error:void 0})}}const p=this.getters.getActiveSheetId();for(let e of this.getters.getMerges(p))if(!this.getters.isMergeHidden(p,e)&&Vs(e,t)){const t=this.getters.getCell(p,e.left,e.top),s=this.getters.getCellBorder(p,e.left,e.top),i=this.getters.getCellBorder(p,e.right,e.bottom),o=h[e.right].end-h[e.left].start;let n,u,g,f,m;if(g=t?this.getters.getCellStyle(t):null,t||i||s){n=t?this.getters.getCellText(t,l):"",u=t?this.getters.getTextWidth(t):null;const o=this.getters.getConditionalStyle(e.topLeft.col,e.topLeft.row);o&&(g=Object.assign({},g,o)),f=n?g&&g.align||Ph(t,l):null,m={bottom:i?i.bottom:null,left:s?s.left:null,right:i?i.right:null,top:s?s.top:null}}g=g||{},g.fillColor&&"#ffffff"!==g.fillColor||(g=Object.create(g),g.fillColor="#fff");const v=h[e.left].start-r,E=d[e.top].start-a,b=d[e.bottom].end-d[e.top].start,S=this.getters.getConditionalIcon(e.left,e.top),C=g.fontSize||x,y=cs[C],w=S?2*I+y:0,T=w+u;f=n&&(null==t?void 0:t.evaluated.type)===ke.number&&T>o&&"center"!==f?"left":f;const R=S?[v+w,E,Math.max(0,o-w),b]:[v,E,o,b],L=S?[v,E,Math.min(w,o),b]:null;c.push({x:v,y:E,width:o,height:b,text:n,textWidth:u,border:m,style:g,align:f,clipRect:R,error:t&&t.evaluated.type===ke.error?t.evaluated.error:void 0,image:S?{type:"icon",clipIcon:L,size:y,image:zl[S].img}:void 0})}return c}}Vh.layers=[0,7],Vh.getters=["getColIndex","getRowIndex","getRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow"],Vh.modes=["normal"];const Hh=new oi;class zh extends Sh{constructor(){super(...arguments),this.inputs={},this.activeSheets={},this.inputHasSingleRange={},this.focusedInputId=null,this.focusedRange=null,this.willAddNewRange=!1}allowDispatch(e){switch(e.type){case"FOCUS_RANGE":const t=this.getIndex(e.id,e.rangeId);if(this.focusedInputId===e.id&&this.focusedRange===t)return 24;break;case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange[e.id]&&1===this.inputs[e.id].length)return 25}return 0}handle(e){switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id],delete this.activeSheets[e.id],delete this.inputHasSingleRange[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(e.id,this.getIndex(e.id,e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.id,e.rangeId);if(null!==t){const s=e.id;this.focusedInputId===s&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:s,rangeId:this.inputs[s][t].id});const i=e.value.split(",").map((e=>e.trim()));this.setRange(s,t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(e.id,this.inputs[e.id].length,[""]),this.focusLast(e.id);break;case"REMOVE_RANGE":const t=this.getIndex(e.id,e.rangeId);null!==t&&this.removeRange(e.id,t);break;case"SELECT_CELL":case"SET_SELECTION":if(!this.focusedInputId)break;const s=this.getSelectionInputValue(this.focusedInputId),i=(this.inputHasSingleRange[this.focusedInputId]?[this.getters.getSelectedZone()]:this.getters.getSelectedZones()).map($s).filter((e=>!s.includes(e))),o=this.activeSheets[this.focusedInputId],n=this.getters.getActiveSheetId(),r=this.getters.getSheetName(n);this.add(i.map((e=>n===o?e:`${us(r)}!${e}`)));break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInputId,this.focusedRange];null===e||null===t||this.inputHasSingleRange[e]||(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,s)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.focusedRange&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.focusedRange===s}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:s}=es(e);return null!==t.match(Jt)&&(!s||void 0!==this.getters.getSheetIdByName(s))}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].map((e=>this.inputToHighlights(this.focusedInputId,e))).flat():[]}initInput(e,t,s=!1){this.inputs[e]=[],this.insertNewRange(e,0,t),this.activeSheets[e]=this.getters.getActiveSheetId(),this.inputHasSingleRange[e]=s,0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){this.focusedInputId=e,this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}unfocus(){this.focusedInputId=null,this.focusedRange=null}add(e){if(null===this.focusedInputId||null===this.focusedRange||this.getters.isSelectingForComposer()||0===e.length)return;if(this.getters.getSelectionMode()===Th.expanding&&this.willAddNewRange){const t=this.focusedInputId;this.insertNewRange(t,this.inputs[t].length,e),this.focusLast(this.focusedInputId),this.willAddNewRange=!1}else this.setRange(this.focusedInputId,this.focusedRange,e)}setContent(e,t,s){this.inputs[e][t]={...this.inputs[e][t],id:Hh.uuidv4(),xc:s}}insertNewRange(e,t,s){this.inputs[e].splice(t,0,...s.map(((t,s)=>({xc:t,id:(this.inputs[e].length+s+1).toString(),color:Xt()}))))}setRange(e,t,s){const[,...i]=s;this.setContent(e,t,s[0]),this.insertNewRange(e,t+1,i),i.length&&this.focus(e,t+i.length)}removeRange(e,t){this.inputs[e].splice(t,1),this.focusedInputId===e&&null!==this.focusedRange&&this.focusLast(e)}inputToHighlights(e,{xc:t,color:s}){const i=this.cleanInputs([t]).filter((e=>this.isRangeValid(e))).filter((t=>this.shouldBeHighlighted(this.activeSheets[e],t)));if(0===i.length)return[];const[o,...n]=i,r=[[o,s||Xt()]];for(const e of n)r.push([e,Xt()]);return r}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:s}=es(t),i=this.getters.getSheetIdByName(s),o=this.getters.getActiveSheet().id;return this.isRangeValid(t)&&(i===o||void 0===i&&o===e)}getIndex(e,t){const s=this.inputs[e].findIndex((e=>e.id===t));return s>=0?s:null}}zh.modes=["normal"],zh.layers=[1],zh.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Zh{constructor(){this.bus=new i.core.EventBus}on(e,t,s){this.bus.on(e,t,s)}trigger(e,t){this.bus.trigger(e,t)}off(e,t){this.bus.off(e,t)}clear(){this.bus.clear()}}function Gh(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?function(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<=r&&e[i]>=r&&n--;if(!(o>n))return{...e,[t]:o,[i]:n}}(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?function(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom",l="before"===i?e[a]>r:e[a]>=r;return e[t]<=r&&l?Ys(e,n,"RESIZE",o):r<e[t]?Ys(e,n,"MOVE",o):{...e}}(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function Wh(e,t){const s=e.definition;let i,o;return s.labelRange&&(i=Gh(ks(s.labelRange),t)),s.dataSets&&(o=s.dataSets.map(ks).map((e=>Gh(e,t))).filter(Ls).map($s)),{...e,definition:{...s,dataSets:o,labelRange:i?$s(i):void 0}}}fl.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Wh),fl.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Wh),fl.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),fl.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var s;if(e.name===t.name)return{...e,name:(null===(s=e.name)||void 0===s?void 0:s.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),fl.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const s=[];for(const i of e.target)for(const e of t.target)Vs(i,e)||s.push({...i});if(s.length)return{...e,target:s};return}));const qh=[{match:function(e){return"sheetId"in e},fn:function(e,t){const s="DELETE_SHEET"===t.type&&t.sheetId;if(e.sheetId===s)return"IGNORE_COMMAND";if("CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId)return e;return"SKIP_TRANSFORMATION"}},{match:function(e){return"target"in e},fn:function(e,t){const s=[];for(const i of e.target){const e=Gh(i,t);e&&s.push(e)}if(!s.length)return"IGNORE_COMMAND";return{...e,target:s}}},{match:function(e){return"col"in e&&"row"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const s="COL"===t.dimension?"col":"row";let i=e[s];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(i))return"IGNORE_COMMAND";for(let t of e)i>=t&&i--}"ADD_COLUMNS_ROWS"===t.type&&(i>t.base||i===t.base&&"before"===t.position)&&(i+=t.quantity);return{...e,[s]:i}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const s of t.target){if(!(e.col===s.left&&e.row===s.top)&&Hs(e.col,e.row,s))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const s="ADD_COLUMNS_ROWS"===e.type,i=s?"base":"elements";let o=s?[e[i]]:e[i];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const s=t.elements.sort(((e,t)=>t-e));for(let t of s)e>t&&e--;return e})).filter(Ls)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((s=>s>e?s+t.quantity:s))}if(o.length){let t=o;return s&&(t=o[0]),{...e,[i]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}}];function jh(e,t){const s=fl.getTransformation(e.type,t.type);return s?s(e,t):function(e,t){for(const{match:s,fn:i}of qh)if(s(e)){const s=i(e,t);if("SKIP_TRANSFORMATION"===s)continue;if("IGNORE_COMMAND"===s)return;return s}return e}(e,t)}function Yh(e,t){let s=[...e];for(const e of t)s=s.map((t=>jh(t,e))).filter(Ls);return s}class Xh{constructor(e,t,s,i){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...s],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Kh extends Error{}class Qh extends Zh{constructor(e,t,s=O){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=s,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new oi,this.debouncedMove=i.utils.debounce(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const s=new Xh(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(s.id,s),this.trigger("new-local-state-update",{id:s.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:s.id,clientId:s.clientId,commands:s.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new Kh("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Ls))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const s=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==s?void 0:s.col)===e.col&&s.row===e.row&&s.sheetId===e.sheetId)return;const i=s?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:i,version:1,client:{...o,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:s}=e,i=new Xh(e.nextRevisionId,t,s);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:Yh(s,t)})}break;case"SNAPSHOT_CREATED":{const t=new Xh(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||(this.waitingAck=!0,this.sendPendingMessage())}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){const t=this.revisions.get(e.nextRevisionId);if(0===t.commands.length){this.revisions.drop(t.id);const e=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.nextRevisionId));return this.trigger("pending-revisions-dropped",{revisionIds:e}),this.waitingAck=!1,this.waitingUndoRedoAck=!1,void(this.pendingMessages=[])}e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage()}}isAlreadyProcessed(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const Jh=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class ed extends Sh{constructor(){super(...arguments),this.availableColors=new Set(Jh),this.colors={}}isPositionValid(e){const t=this.getters.getSheet(e.sheetId);return e.row<t.rows.length&&e.col<t.cols.length}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(Jh));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof Kh)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const s of this.getters.getConnectedClients())if(s.id!==this.getters.getClient().id&&s.position&&s.position.sheetId===e&&this.isPositionValid(s.position)){const e=s.position;this.colors[s.id]||(this.colors[s.id]=this.chooseNewColor());const i=this.colors[s.id];t.push({...s,position:e,color:i})}return t}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:r}=e.position,a=this.getters.expandZone(o,{top:n,bottom:n,left:r,right:r}),[l,c,h,d]=this.getters.getRect(a,t);if(h<=0||d<=0)continue;const u=e.color,p=`${u}10`;s.fillStyle=p,s.lineWidth=4*i,s.strokeStyle=u,s.globalCompositeOperation="multiply",s.fillRect(l,c,h,d),s.globalCompositeOperation="source-over",s.strokeRect(l,c,h,d),s.font=`bold ${x+1}px ${R}`}}}ed.getters=["getClientsToDisplay"],ed.layers=[5],ed.modes=["normal"];class td extends Sh{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Hs(e.anchor[0],e.anchor[1],e.zone))throw new Error(a("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)e.interactive?this.interactiveSortSelection(e.sheetId,e.anchor,e.zone,e.sortDirection):this.sortZone(e.sheetId,e.anchor,e.zone,e.sortDirection)}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let s=t.top;s<=t.bottom;s++)for(let i=t.left;i<=t.right;i++)if(!this.getters.isInMerge(e,i,s))return 48;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const s=this.getters.getMerges(e).filter((e=>Vs(e,t))),i=Ws(s[0]);let[o,n]=[i.width,i.height];return s.every((e=>{let[t,s]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&s===n}))?0:48}interactiveSortSelection(e,t,s,i){let o=Pe.Success,n=s.right>s.left;if(this.getters.doesIntersectMerge(e,s)){let t;n=!1;for(let i=s.top;i<=s.bottom;i++){t=[];for(let o=s.left;o<=s.right;o++){let s=this.getters.getMerge(e,o,i);s&&!t.includes(s.id.toString())&&t.push(s.id.toString())}if(t.length>=2){n=!0;break}}}if(n)o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i});else{const n=this.getContiguousZone(e,s);Bs(n,s)?o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i}):this.ui.askConfirmation(a("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>{s=n,o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}),(()=>{o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}))}o.isCancelledBecause(48)&&(this.dispatch("SET_SELECTION",{anchor:t,zones:[s],anchorZone:s}),this.ui.notifyUser(a("Cannot sort. To sort, select only cells or only merges that have the same size.")))}expand(e,t){const{left:s,right:i,top:o,bottom:n}=this.getters.expandZone(e.id,t);return{left:Math.max(0,s),right:Math.min(e.cols.length-1,i),top:Math.max(0,o),bottom:Math.min(e.rows.length-1,n)}}checkExpandedValues(e,t){const s=this.expand(e,t),i=e.id;let o,n=[];if(this.getters.doesIntersectMerge(i,s)){const{left:e,right:t,top:r,bottom:a}=s;for(let s=e;s<=t;s++)for(let e=r;e<=a;e++){const[t,r]=this.getters.getMainCell(i,s,e);o=this.getters.getCell(i,t,r),n.push((null==o?void 0:o.formattedValue)||"")}}else{const t=Gs(s,e,(e=>e.formattedValue),"");n=t.flat()}return n.some((e=>""!==e))}getContiguousZone(e,t){let s,{top:i,bottom:o,left:n,right:r}=t;const a=this.getters.getSheet(e);let l=!1;for(;!l;)l=!0,i>0&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:i-1,bottom:i-1}),s&&(l=!1,i--)),n>0&&(s=this.checkExpandedValues(a,{left:n-1,right:n-1,top:i-1,bottom:o+1}),s&&(l=!1,n--)),r<a.cols.length-1&&(s=this.checkExpandedValues(a,{left:r+1,right:r+1,top:i-1,bottom:o+1}),s&&(l=!1,r++)),o<a.rows.length-1&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:o+1,bottom:o+1}),s&&(l=!1,o++));return{left:n,right:r,top:i,bottom:o}}hasHeader(e,t,s,i){const{left:o,right:n,top:r,bottom:a}=t;if(a-r+1==1)return!1;let l=Gs({left:o,right:n,top:r,bottom:r+2*i-1},e,(e=>e.evaluated.type),ke.empty,s,i);return l[0][0]===ke.empty&&(l=l.slice(1)),!l.some((e=>e[0]===ke.empty))&&!!l.some((e=>e[1]!==ke.empty&&e[0]!==e[1]))}sortCellsList(e,t){const s=e.map(((e,t)=>({index:t,val:e}))),i=s.filter((e=>!(null==e.val||""===e.val.evaluated.value))),o=s.filter((e=>null==e.val||""===e.val.evaluated.value)),n="descending"===t?-1:1,r=[ke.number,ke.error,ke.text,ke.boolean];return i.map((e=>{return{index:e.index,val:(t=e.val,{type:t.evaluated.type,value:t.evaluated.value})};var t})).sort(((e,t)=>{let s=r.indexOf(e.val.type)-r.indexOf(t.val.type);return 0===s&&(s=e.val.type===ke.text||e.val.type===ke.error?e.val.value.localeCompare(t.val.value):e.val.value-t.val.value),n*s})).concat(o)}sortZone(e,t,s,i){let o=1,n=1,r=t[0],a=Object.assign({},s);if(this.getters.doesIntersectMerge(e,a)){const[s,i]=t,a=this.getters.getMerge(e,s,i);o=a.right-a.left+1,n=a.bottom-a.top+1,r=a.topLeft.col}const l=this.getters.getSheet(e);this.hasHeader(l,a,o,n)&&(a.top+=n);const c=Gs(a,l,(e=>e),void 0,o,n),h=c[r-a.left],d=this.sortCellsList(h,i).map((e=>e.index)),[u,p]=[c.length,c[0].length];for(let t=0;t<u;t++)for(let s=0;s<p;s++){let i=c[t][d[s]],r=a.left+t*o,l=a.top+s*n,h={sheetId:e,col:r,row:l,content:"",value:""};if(i){let t=i.content;if(i.isFormula()){const s=l-this.getters.getCellPosition(i.id).row,o=this.getters.createAdaptedRanges(i.dependencies.references,0,s,e);t=this.getters.buildFormulaContent(e,i.normalizedText,{...i.dependencies,references:o})}h.style=i.style,h.content=t,h.format=i.format,h.value=i.evaluated.value}this.dispatch("UPDATE_CELL",h)}}}td.getters=["getContiguousZone"];class sd extends Sh{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}sd.modes=["normal"],sd.getters=["shouldShowFormulas"];class id extends Sh{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":case"DELETE_SHEET_CONFIRMATION":try{this.getters.getSheet(e.sheetId);break}catch(e){return 23}}return 0}handle(e){switch(e.type){case"RENAME_SHEET":e.interactive&&this.interactiveRenameSheet(e.sheetId,a("Rename Sheet"));break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheetId);break;case"ADD_MERGE":e.interactive&&this.interactiveMerge(e.sheetId,e.target);break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const s=this.getColMaxWidth(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:s+6,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const s=this.getRowMaxHeight(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:s+6,sheetId:e.sheetId})}}}getCellWidth(e){let t=this.getTextWidth(e);const s=this.getters.getCellPosition(e.id);return this.getters.getConditionalIcon(s.col,s.row)&&(t+=function(e,t){const s=t.fontSize||x;return cs[s]+2*I}(this.ctx,this.getters.getCellStyle(e))),t}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas());return gs(this.ctx,t,this.getters.getCellStyle(e))}getCellHeight(e){const t=this.getters.getCellStyle(e).fontSize||x;return cs[t]}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===ke.error)?e.content:e.formattedValue}getColMaxWidth(e,t){const s=this.getters.getColCells(e,t).map((e=>this.getCellWidth(e)));return Math.max(0,_s(s))}getRowMaxHeight(e,t){const s=this.getters.getSheet(e),i=Object.values(s.rows[t].cells).map((e=>this.getCellHeight(e)));return Math.max(0,_s(i))}interactiveRenameSheet(e,t){const s=this.getters.getSheetName(e);this.ui.editText(t,s,(t=>{if(!t)return;const s=this.dispatch("RENAME_SHEET",{sheetId:e,name:t}),i=this.getters.getSheetName(e);s.isSuccessful||i===t||this.interactiveRenameSheet(e,a("Please enter a valid sheet name"))}))}interactiveDeleteSheet(e){this.ui.askConfirmation(a("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheetId:e})}))}interactiveMerge(e,t){const s=this.dispatch("ADD_MERGE",{sheetId:e,target:t});s.isSuccessful||s.isCancelledBecause(3)&&this.ui.askConfirmation(a("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheetId:e,target:t,force:!0})}))}}id.getters=["getCellWidth","getCellHeight","getTextWidth","getCellText"];class od extends Sh{constructor(){super(...arguments),this.viewports={},this.snappedViewports={},this.updateSnap=!1,this.clientWidth=1e3,this.clientHeight=1e3}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkOffsetValidity(e.offsetX,e.offsetY);case"RESIZE_VIEWPORT":return e.width<0||e.height<0?54:0;default:return 0}}handle(e){switch(e.type){case"UNDO":case"REDO":this.cleanViewports(),this.resetViewports();break;case"RESIZE_VIEWPORT":this.cleanViewports(),this.resizeViewport(e.height,e.width);break;case"SET_VIEWPORT_OFFSET":this.setViewportOffset(e.offsetX,e.offsetY);break;case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportOffsetX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportOffsetY(e.sheetId,this.getViewport(e.sheetId));break;case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportZoneX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportZoneY(e.sheetId,this.getViewport(e.sheetId));break;case"ACTIVATE_SHEET":this.refreshViewport(e.sheetIdTo);break;case"SELECT_CELL":case"MOVE_POSITION":this.refreshViewport(this.getters.getActiveSheetId())}}finalize(){this.updateSnap&&(this.snapViewportToCell(this.getters.getActiveSheetId()),this.updateSnap=!1)}getViewportDimension(){return{width:this.clientWidth,height:this.clientHeight}}getActiveViewport(){const e=this.getters.getActiveSheetId();return this.getViewport(e)}getActiveSnappedViewport(){const e=this.getters.getActiveSheetId();return this.getSnappedViewport(e)}getGridDimension(e){const t=ai(e,"cols"),s=this.clientWidth-m,i=ai(e,"rows"),o=this.clientHeight-f,n=e.cols.find((e=>e.end>t.end-s))||e.cols[e.cols.length-1],r=e.rows.find((e=>e.end>i.end-o))||e.rows[e.rows.length-1];return{width:t.end+Math.max(E,Math.min(n.size,s-t.size)),height:i.end+Math.max(b+5,Math.min(r.size,o-i.size))}}getMaximumViewportOffset(e){const{width:t,height:s}=this.getters.getGridDimension(e);return{maxOffsetX:Math.max(0,t-this.clientWidth+m+1),maxOffsetY:Math.max(0,s-this.clientHeight+f+1)}}checkOffsetValidity(e,t){const s=this.getters.getActiveSheet(),{maxOffsetX:i,maxOffsetY:o}=this.getMaximumViewportOffset(s);return e<0||t<0||t>o||e>i?53:0}getSnappedViewport(e){return this.snapViewportToCell(e),this.snappedViewports[e]}getViewport(e){return this.viewports[e]?this.viewports[e]:this.generateViewportState(e)}cleanViewports(){const e=this.getters.getVisibleSheets();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetViewports(){for(let[e,t]of Object.entries(this.viewports))this.adjustViewportOffsetX(e,t),this.adjustViewportOffsetY(e,t),this.adjustViewportsPosition(e)}adjustViewportOffsetX(e,t){const{offsetX:s}=t,{width:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientWidth-m+s>i){const e=this.clientWidth-m+s-i;t.offsetX=Math.max(0,s-e)}this.adjustViewportZoneX(e,t)}adjustViewportOffsetY(e,t){const{offsetY:s}=t,{height:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientHeight-f+s>i){const e=this.clientHeight-f+s-i;t.offsetY=Math.max(0,s-e)}this.adjustViewportZoneY(e,t)}resizeViewport(e,t){this.clientHeight=e,this.clientWidth=t,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.adjustViewportOffsetX(e,this.viewports[e]),this.adjustViewportOffsetY(e,this.viewports[e])}setViewportOffset(e,t){const s=this.getters.getActiveSheetId();this.getActiveViewport(),this.viewports[s].offsetX=e,this.viewports[s].offsetY=t,this.adjustViewportZone(s,this.viewports[s])}generateViewportState(e){return this.viewports[e]={left:0,right:0,top:0,bottom:0,offsetX:0,offsetY:0},this.viewports[e]}refreshViewport(e){const t=this.getViewport(e);this.adjustViewportZone(e,t),this.adjustViewportsPosition(e)}adjustViewportZone(e,t){this.adjustViewportZoneX(e,t),this.adjustViewportZoneY(e,t)}adjustViewportZoneX(e,t){const s=this.getters.getSheet(e),i=s.cols;t.left=this.getters.getColIndex(t.offsetX+m,0,s);const o=this.clientWidth+t.offsetX-m;t.right=i.length-1;for(let e=t.left;e<i.length;e++)if(o<i[e].end){t.right=e;break}this.updateSnap=!0}adjustViewportZoneY(e,t){const s=this.getters.getSheet(e),i=s.rows;t.top=this.getters.getRowIndex(t.offsetY+f,0,s);const o=this.clientHeight+t.offsetY-f;t.bottom=i.length-1;for(let e=t.top;e<i.length;e++)if(o<i[e].end){t.bottom=e;break}this.updateSnap=!0}adjustViewportsPosition(e,t){const s=this.getters.getSheet(e),{cols:i,rows:o}=s,n=this.getSnappedViewport(e);t=t||this.getters.getSheetPosition(e);const[r,a]=ni(s,...this.getters.getMainCell(e,t[0],t[1]));for(;i[r].end>n.offsetX+this.clientWidth-m&&n.offsetX<i[r].start;)n.offsetX=i[n.left].end,this.adjustViewportZoneX(e,n);for(;r<n.left;){const t=i.slice(0,n.left).reverse().findIndex((e=>!e.isHidden));n.offsetX=i[n.left-1-t].start,this.adjustViewportZoneX(e,n)}for(;o[a].end>n.offsetY+this.clientHeight-f&&n.offsetY<o[a].start;)n.offsetY=o[n.top].end,this.adjustViewportZoneY(e,n);for(;a<n.top;){const t=o.slice(0,n.top).reverse().findIndex((e=>!e.isHidden));n.offsetY=o[n.top-1-t].start,this.adjustViewportZoneY(e,n)}const{top:l,left:c}=this.viewports[e];l===n.top&&c===n.left||(this.viewports[e]=n),this.updateSnap=!1}snapViewportToCell(e){const{cols:t,rows:s}=this.getters.getSheet(e),i=this.getViewport(e),o=Object.assign({},i);this.adjustViewportOffsetX(e,o),this.adjustViewportOffsetY(e,o),o.offsetX=t[o.left].start,o.offsetY=s[o.top].start,this.adjustViewportZone(e,o),this.snappedViewports[e]=o}}od.getters=["getActiveViewport","getSnappedViewport","getActiveSnappedViewport","getViewportDimension","getGridDimension","getMaximumViewportOffset"],od.modes=["normal"];const nd=(new Le).add("sheet",Ra).add("cell",Sa).add("merge",Ta).add("borders",va).add("conditional formatting",ya).add("figures",wa).add("chart",Ca),rd=(new Le).add("selection",xh).add("ui_sheet",id).add("ui_options",sd).add("evaluation",Ah).add("evaluation_cf",kh).add("evaluation_chart",Nh).add("clipboard",wh).add("edition",Lh).add("highlight",Uh).add("selectionInput",zh).add("viewport",od).add("grid renderer",Vh).add("autofill",Ih).add("find_and_replace",$h).add("sort",td).add("automatic_sum",yh).add("format",Dh).add("selection_multiuser",ed);class ad{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}class ld extends i.core.EventBus{constructor(){super(...arguments),this.registry=new Le}add(e,t){this.registry.add(e,t);const s=i.utils.debounce((()=>this.trigger("data-loaded",{id:e})),0);return t.on("data-loaded",this,(()=>s())),t.loadMetadata(),this}get(e){return this.registry.get(e)}getAll(){return this.registry.getAll()}remove(e){this.get(e).off("data-loaded",this),this.registry.remove(e)}async waitForReady(){const e=[];for(const t of this.getAll())e.push(t.get());return Promise.all(e)}}class cd extends i.core.EventBus{async loadMetadata(){this.metadataPromise||(this.metadataPromise=this._fetchMetadata().then((e=>(this.metadata=e,e)))),await this.metadataPromise}async get(e){return e&&e.forceFetch&&(this.data=void 0,this.dataPromise=void 0),await this.loadMetadata(),this.dataPromise||(this.dataPromise=this._fetch(e).then((e=>(this.data=e,this.lastUpdate=Date.now(),this.trigger("data-loaded"),e)))),this.dataPromise}getSync(){return this.data}getMetadataSync(){return this.metadata}getLastUpdate(){return this.lastUpdate}}function hd(e){return _a.get(e.type)(e)}function dd(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class ud{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const s of this.operations){if(s.id===e)return e;if(s.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const s=this.buildTransformation.with(e.data),{before:i,operation:o,after:n}=this.locateOperation(t);this.operations=[...i,o,e,...n.map((e=>e.transformed(s)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new ud(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:s}=this.locateOperation(e);this.operations=t.concat([s])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class pd{constructor(e,t){this.id=e,this.data=t}transformed(e){return new pd(this.id,e(this.data))}}class gd{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new gd(function*(e,t){for(const s of e)if(yield s,s.operation.id===t)return}(this.operations,e))}stopBefore(e){return new gd(function*(e,t){for(const s of e){if(s.operation.id===t)return;yield s}}(this.operations,e))}startAfter(e){return new gd(function*(e,t){let s=!0;for(const i of e)s||(yield i),i.operation.id===t&&(s=!1)}(this.operations,e))}}class fd{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new gd(vs(this._execution(e),this._execution(e)))}revertedExecution(e){return new gd(vs(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var s;const i=e.getLastOperationId()||(null===(s=this.previousBranch(e))||void 0===s?void 0:s.getLastOperationId());e.append(t),i&&this.insertPrevious(e,t,i)}insertOperationAfter(e,t,s){e.insert(t,s),this.updateNextWith(e,t,s),this.insertPrevious(e,t,s)}undo(e,t){const s=this.buildTransformation.without(t.data),i=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);i&&this.branchingOperationIds.set(o,i),this.insertBranchAfter(e,o),this.transform(o,s)}redo(e){const t=this.nextBranch(e);if(!t)return;const s=this.nextBranch(t);this.removeBranchFromTree(t);const i=this.branchingOperationIds.get(t);i?this.branchingOperationIds.set(e,i):this.branchingOperationIds.delete(e),s&&this.rebaseUp(s)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const s of this.revertedExecution(e))if(s.operation.id===t)return s;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:s}=this.findPreviousBranchingOperation(e);if(!t||!s)return;const i=this.buildTransformation.without(s.data),o=t.fork(s.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(i);const n=this.nextBranch(o);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const s=this.branches.findIndex((t=>t===e));this.branches.splice(s+1,0,t)}updateNextWith(e,t,s){const i=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(i&&o)if(e.getFirstOperationAmong(s,i)===i){const n=this.addToNextBranch(e,o,i,t,s);this.updateNextWith(o,n,s)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,s,i,o){let n=i;return o===s?(n=this.getTransformedOperation(e,s,i),t.prepend(n)):t.contains(o)?(n=this.getTransformedOperation(e,s,i),t.insert(n,o)):t.append(i),n}getTransformedOperation(e,t,s){const i=e.getOperation(t),o=this.buildTransformation.without(i.data);return s.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const s=this.nextBranch(e);s&&this.transform(s,t)}insertPrevious(e,t,s){const{previousBranch:i,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!i||!o)return;const n=this.buildTransformation.with(o.data),r=e.fork(s);r.transform(n),i.cutAfter(s),i.appendBranch(r);const a=t.transformed(n);this.insertPrevious(i,a,s)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const s=this.branchingOperationIds.get(t);return s?{previousBranch:t,branchingOperation:t.getOperation(s)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let s=!!t;const i=e.getOperations();for(let o=i.length-1;o>=0;o--){const n=i[o];n.id===t&&(s=!1),s||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class md{constructor(e,t,s,i,o){this.applyOperation=t,this.revertOperation=s,this.buildEmpty=i,this.buildTransformation=o,this.HEAD_BRANCH=new ud(this.buildTransformation),this.tree=new fd(o,this.HEAD_BRANCH);const n=new pd(e,i(e));this.tree.insertOperationLast(this.HEAD_BRANCH,n),this.HEAD_OPERATION=n}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const s=new pd(e,t),i=this.tree.getLastBranch();this.tree.insertOperationLast(i,s),this.HEAD_BRANCH=i,this.HEAD_OPERATION=s}insert(e,t,s){const i=new pd(e,t);this.revertTo(s),this.tree.insertOperationAfter(this.HEAD_BRANCH,i,s),this.fastForward()}undo(e,t,s){const{branch:i,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(i,o),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}redo(e,t,s){const{branch:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(i),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}drop(e){this.revertBefore(e),this.tree.drop(e)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:s,isCancelled:i}of e)i||this.revertOperation(s.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:s,isCancelled:i}of e)i||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=s}}function vd(e,t,s){return new md(e,(e=>{const i=e.commands.slice(),{changes:o}=t((()=>{for(const e of i)s(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Ed(t.changes[e],"before")}}([e])),(e=>new Xh(e,"empty",[],[])),{with:e=>t=>new Xh(t.id,t.clientId,Yh(t.commands,e.commands)),without:e=>t=>new Xh(t.id,t.clientId,Yh(t.commands,e.commands.map(hd).flat()))})}function Ed(e,t){let s=e.path[0];const i=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const i=e.path[t];if(void 0===s[i]){const o=e.path[t+1];s[i]=dd(o)}s=s[i]}void 0===e[t]?delete s[i]:s[i]=e[t]}class bd extends i.core.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("pending-revisions-dropped",this,(({revisionIds:e})=>this.drop(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}drop(e){this.undoStack=this.undoStack.filter((t=>!e.includes(t))),this.redoStack=[]}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class Sd{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return 0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";e.elements.sort(((e,t)=>t-e));const o=ms(e.elements);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of o){const o=Os(e),l=_s(e);if(n.zone[t]<=o&&o<=n.zone[s]){const e=Math.min(n.zone[s],l)-o+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e)}else if(n.zone[t]>=o&&n.zone[s]<=l)a="REMOVE",r=this.buildInvalidRange(_);else if(n.zone[t]<=l&&n.zone[s]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e),r=this.createAdaptedRange(r,i,"MOVE",-(n.zone[t]-o))}else o<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,i,a,-(l-o+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>t.sheetId!==e.sheetId?{changeType:"NONE"}:{changeType:"REMOVE",range:t={...this.buildInvalidRange(_),invalidSheetName:this.getters.getSheetName(e.sheetId)}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(e.name&&t.invalidSheetName===e.name){const s={...t,zone:{...t.zone}};return s.invalidSheetName=void 0,s.sheetId=e.sheetId,{changeType:"CHANGE",range:s}}return{changeType:"NONE"}}))}}finalize(){}verifyRangeRemoved(e){return t=>{const s=e(t);return"NONE"===s.changeType||Fs(s.range.zone)?s:{range:s.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,s,i){return{...e,zone:Ys(e.zone,t,s,i)}}executeOnAllRanges(e,t){const s=this.verifyRangeRemoved(e);for(const e of this.providers)e(s,t)}addRangeProvider(e){this.providers.push(e)}orderZone(e,t){if(e.right<e.left){let s=e.right;e.right=e.left,e.left=s;let i=t[1].colFixed;t[1].colFixed=t[0].colFixed,t[0].colFixed=i}if(e.bottom<e.top){let s=e.bottom;e.bottom=e.top,e.top=s;let i=t[1].rowFixed;t[1].rowFixed=t[0].rowFixed,t[0].rowFixed=i}}createAdaptedRanges(e,t,s,i){return e.map((e=>Fs(e.zone)?(e={...e,sheetId:e.prefixSheet?e.sheetId:i,zone:{left:e.zone.left+(e.parts[0].colFixed?0:t),right:e.zone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.zone.top+(e.parts[0].rowFixed?0:s),bottom:e.zone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:s)}},this.orderZone(e.zone,e.parts),e):e))}getRangeFromSheetXC(e,t){let s,i,o,n=t,r=!1;if(!Jt.test(t))return this.buildInvalidRange(t);t.includes("!")&&(({xc:n,sheetName:s}=es(t)),s?(i=this.getters.getSheetIdByName(s),r=!0,i||(o=s)):o=s);const a=Ns(n);let l=n.split(":").map((e=>({colFixed:e.startsWith("$"),rowFixed:e.includes("$",1)})));return this.orderZone(a,l),{sheetId:i||e,zone:a,parts:l,invalidSheetName:o,prefixSheet:r}}getRangeString(e,t){if(!e)return _;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return _;if(e.zone.left<0||e.zone.top<0)return _;let s=e.sheetId!==t||e.invalidSheetName||e.prefixSheet,i="";if(s&&(i=e.invalidSheetName?e.invalidSheetName:us(this.getters.getSheetName(e.sheetId))),s&&!i)return _;let o=Array(9);return o[0]=e.parts&&e.parts[0].colFixed?"$":"",o[1]=ts(e.zone.left),o[2]=e.parts&&e.parts[0].rowFixed?"$":"",o[3]=String(e.zone.top+1),e.parts&&2===e.parts.length&&(e.zone.top!==e.zone.bottom||e.zone.left!==e.zone.right||e.parts[0].rowFixed||e.parts[0].colFixed||e.parts[1].rowFixed||e.parts[1].colFixed)&&(o[4]=":",o[5]=e.parts[1].colFixed?"$":"",o[6]=ts(e.zone.right),o[7]=e.parts[1].rowFixed?"$":"",o[8]=String(e.zone.bottom+1)),`${s?i+"!":""}${o.join("")}`}buildInvalidRange(e){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:e}}}Sd.getters=["getRangeString","getRangeFromSheetXC","createAdaptedRanges"];class Cd{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let s=e[0],i=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const i=e[t];if(void 0===s[i]){const o=e[t+1];s[i]=dd(o)}s=s[i]}s[i]!==t&&(this.changes.push({path:e,before:s[i],after:t}),void 0===t?delete s[i]:s[i]=t)}}const Id={General:0,0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},yd={arrow:"3Arrows",smiley:"3Symbols",dot:"3TrafficLights1"},wd={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"},Td="http://schemas.openxmlformats.org/drawingml/2006/main",xd="http://schemas.openxmlformats.org/drawingml/2006/chart",Rd={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml"},Ld="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Md=.75,Ad=.1425,_d=164,Od={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},Nd=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","ERF.PRECISE","ERFC.PRECISE","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOWEEKNUM","LOGNORM.DIST","LOGNORM.INV","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANK.AVG","RANK.EQ","RRI","SEC","SECH","SHEET","SHEETS","SKEW.P","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TEXTJOIN","UNICHAR","UNICODE","VAR.P","VAR.S","WEBSERVICE","WEIBULL.DIST","XOR","Z.TEST"];function kd(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function Fd(e){return Math.round(Md*e*window.devicePixelRatio*100)/100}function $d(e){return Math.round(Ad*e*100)/100}function Dd(e,t){let s={};e.style&&(s=t.styles[e.style]);const i={font:{size:(null==s?void 0:s.fontSize)||x,color:(null==s?void 0:s.textColor)?s.textColor:"000000",family:2,name:"Arial"},fill:(null==s?void 0:s.fillColor)?{fgColor:s.fillColor}:{reservedAttribute:"none"},numFmt:e.format,border:e.border||0,verticalAlignment:"center",horizontalAlignment:null==s?void 0:s.align};return i.font.strike=!!(null==s?void 0:s.strikethrough)||void 0,i.font.underline=!!(null==s?void 0:s.underline)||void 0,i.font.bold=!!(null==s?void 0:s.bold)||void 0,i.font.italic=!!(null==s?void 0:s.italic)||void 0,i}function Ud(e,t){const s=function(e,t){if(!e)return 0;let s=Id[e];s||(s=Bd(e,t)+_d);return s}(t.numFmt,e.numFmts),i={fontId:Bd(t.font,e.fonts),fillId:Bd(t.fill,e.fills),borderId:t.border,numFmtId:s,verticalAlignment:t.verticalAlignment,horizontalAlignment:t.horizontalAlignment};return Bd(i,e.styles)}function Pd(e,t,s){let i,o=e.find((e=>e.path===t));return o?(i=`rId${(o.rels.length+1).toString()}`,o.rels.push({...s,id:i})):(i="rId1",e.push({path:t,rels:[{...s,id:i}]})),i}function Bd(e,t){let s=t.length;const i="object"==typeof e?As:(e,t)=>e===t;for(let o=0;o<s;o++)if(i(e,t[o]))return o;return t[t.length]=e,t.length-1}const Vd=[];function Hd(e){const t=Vd.findIndex((t=>t===e));return-1===t?(Vd.push(e),Vd.length):t+1}function zd(e){return Math.round(914400*e/96)}class Zd{constructor(e){this.xmlString=e}toString(){return this.xmlString}}function Gd(e,t,s){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:s}}function Wd(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function qd(e){return new Zd(e.map((([e,t])=>`${e}="${Wd(t)}"`)).join(" "))}function jd(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),s=t.querySelector("parsererror");if(s){const t=s.innerHTML,i=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),n=o.slice(Math.max(i-3,0),Math.min(i+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${n}`)}return t}function Yd(e,t){return Kd`
|
|
1044
|
+
`;class vh extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.state=t.useState(this.initialState())}get hasSearchResult(){return null!==this.env.getters.getCurrentSelectedMatchIndex()}mounted(){this.focusInput()}async willUnmount(){this.env.dispatch("CLEAR_SEARCH")}onInput(e){this.state.toSearch=e.target.value,this.debouncedUpdateSearch()}onKeydownSearch(e){"Enter"===e.key&&(e.preventDefault(),this.onSelectNextCell())}onKeydownReplace(e){"Enter"===e.key&&(e.preventDefault(),this.replace())}onFocusSidePanel(){this.state.searchOptions.searchFormulas=this.getters.shouldShowFormulas(),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas?this.state.searchOptions.searchFormulas:this.state.replaceOptions.modifyFormulas,this.env.dispatch("REFRESH_SEARCH")}searchFormulas(){this.env.dispatch("SET_FORMULA_VISIBILITY",{show:this.state.searchOptions.searchFormulas}),this.state.replaceOptions.modifyFormulas=this.state.searchOptions.searchFormulas,this.updateSearch()}onSelectPreviousCell(){this.env.dispatch("SELECT_SEARCH_PREVIOUS_MATCH")}onSelectNextCell(){this.env.dispatch("SELECT_SEARCH_NEXT_MATCH")}updateSearch(){this.env.dispatch("UPDATE_SEARCH",{toSearch:this.state.toSearch,searchOptions:this.state.searchOptions})}debouncedUpdateSearch(){clearTimeout(this.inDebounce),this.inDebounce=setTimeout((()=>this.updateSearch.call(this)),400)}replace(){this.env.dispatch("REPLACE_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}replaceAll(){this.env.dispatch("REPLACE_ALL_SEARCH",{replaceWith:this.state.replaceWith,replaceOptions:this.state.replaceOptions})}focusInput(){const e=this.el.querySelector("input");e&&e.focus()}initialState(){return{toSearch:"",replaceWith:"",searchOptions:{matchCase:!1,exactMatch:!1,searchFormulas:!1},replaceOptions:{modifyFormulas:!1}}}}vh.template=fh,vh.style=mh;const Eh=new Le;Eh.add("ConditionalFormatting",{title:a("Conditional formatting"),Body:uh}),Eh.add("ChartPanel",{title:a("Chart"),Body:Oc}),Eh.add("FindAndReplace",{title:a("Find and Replace"),Body:vh});const Sh=new Le;class bh extends fa{constructor(e,t,s,i){super(t,s,i),this.getters=e,this.ui=i}drawGrid(e,t){}}bh.layers=[];class Ch{constructor(e,t,s){this.index=0,this.cells=e,this.getters=t,this.direction=s}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:s,tooltip:i}=La.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:s,tooltip:i,origin:{col:e.data.col,row:e.data.row}}}}class Ih extends bh{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:ps(e.col,0,this.getters.getSheet(t).cols.length),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:ps(e.row,0,this.getters.getSheet(t).rows.length),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:30;case"AUTOFILL_AUTO":const s=this.getters.getSelectedZone();return s.top===s.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),s=this.autofillZone;switch(this.direction){case 1:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(is(i,e));const n=this.createGenerator(o);for(let t=s.top;t<=s.bottom;t++)this.computeNewCell(n,i,t,e)}break;case 0:for(let i=t.left;i<=t.right;i++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(is(i,e));const n=this.createGenerator(o);for(let t=s.bottom;t>=s.top;t--)this.computeNewCell(n,i,t,e)}break;case 2:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(is(e,i));const n=this.createGenerator(o);for(let t=s.right;t>=s.left;t--)this.computeNewCell(n,t,i,e)}break;case 3:for(let i=t.top;i<=t.bottom;i++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(is(e,i));const n=this.createGenerator(o);for(let t=s.left;t<=s.right;t++)this.computeNewCell(n,t,i,e)}}if(e){const e=Ps(this.getters.getSelectedZone(),this.autofillZone);this.autofillZone=void 0,this.lastCellSelected={},this.direction=void 0,this.tooltip=void 0,this.dispatch("SET_SELECTION",{zones:[e],anchor:[e.left,e.top],anchorZone:e})}}select(e,t){const s=this.getters.getSelectedZone();if(Hs(e,t,s))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,s.top-1,s.left,s.right);break;case 1:this.saveZone(s.bottom+1,t,s.left,s.right);break;case 2:this.saveZone(s.top,s.bottom,e,s.left-1);break;case 3:this.saveZone(s.top,s.bottom,s.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let s=e.left,i=e.bottom;if(s>0){let e=this.getters.getCell(t,s-1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s-1,i)}if(i===e.bottom&&(s=e.right,s<=this.getters.getActiveSheet().cols.length)){let e=this.getters.getCell(t,s+1,i);for(;e&&!e.isEmpty();)i+=1,e=this.getters.getCell(t,s+1,i)}i!==e.bottom&&(this.select(e.left,i-1),this.autofill(!0))}computeNewCell(e,t,s,i){const{cellData:o,tooltip:n,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=n,i&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:s,content:a,style:l,border:c,format:h})}getRule(e,t){const s=Aa.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((s=>s.condition(e,t)));return s&&s.generateRule(e,t)}createGenerator(e){const t=[],s=[],i=this.getters.getActiveSheetId();for(let t of e){const[e,o]=ss(t),n=this.getters.getCell(i,e,o);s.push({col:e,row:o,cell:n,sheetId:i})}const o=s.map((e=>e.cell));for(let e of s){let s={type:"COPY_MODIFIER"};if(e&&e.cell){s=this.getRule(e.cell,o)||s}const{sheetId:i,col:n,row:r}=e,a=this.getters.getCellBorder(i,n,r)||void 0;t.push({data:{...e,border:a},rule:s})}return new Ch(t,this.getters,this.direction)}saveZone(e,t,s,i){this.autofillZone={top:e,bottom:t,left:s,right:i}}getDirection(e,t){const s=this.getters.getSelectedZone(),i={up:{number:s.top-t,value:0},down:{number:t-s.bottom,value:1},left:{number:s.left-e,value:2},right:{number:e-s.right,value:3}};if(1===Object.values(i).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(i).find((e=>e.number>0?1:0)).value;const o=i.up.number>0?"up":"down",n=i.left.number>0?"left":"right";return Math.abs(i[o].number)>=Math.abs(i[n].number)?i[o].value:i[n].value}autoFillMerge(e,t,s,i){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,s,i)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const n=this.getters.getMerge(o.id,e,t);(null==n?void 0:n.topLeft.col)===e&&(null==n?void 0:n.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:i,bottom:i+n.bottom-n.top,left:s,right:s+n.right-n.left}]})}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:s,thinLineWidth:i}=e,[o,n,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(s.strokeStyle="black",s.lineWidth=i,s.setLineDash([3]),s.strokeRect(o,n,r,a),s.setLineDash([]))}}Ih.layers=[6],Ih.getters=["getAutofillTooltip"],Ih.modes=["normal"];class yh extends bh{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:s}=this.getters.getSelection();for(const i of t){const t=this.getAutomaticSums(e,i,s);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,s){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,s):this.sumData(e,t)}sumData(e,t){const s=this.dimensionsToSum(e,t),i=this.sumDimensions(e,t,s).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return s.has("ROW")&&s.has("COL")&&i.push(this.sumTotal(t)),i}sumAdjacentData(e,t,s){const[i,o]=Hs(s[0],s[1],t)?s:[t.left,t.top],n=this.findAdjacentData(e,i,o);return n?this.getters.isSingleCellOrMerge(e,t)||qs(Ps(n,t))?[{position:[i,o],zone:n}]:this.sumDimensions(e,Ps(n,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,s){const i=this.getters.getSheet(e),o=this.findSuitableZoneToSum(i,...this.getters.getMainCell(e,t,s));if(o)return this.getters.expandZone(e,o)}findSuitableZoneToSum(e,t,s){const i=this.getters.getCell(e.id,t,s-1),o=this.getters.getCell(e.id,t-1,s);if(this.isNumber(o)&&!this.isNumber(i))return this.findHorizontalZone(e,t,s);const n=this.findVerticalZone(e,t,s);if(this.isZoneValid(n))return n;const r=this.findHorizontalZone(e,t,s);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,s){const i={top:0,bottom:s-1,left:t,right:t},o=this.reduceZoneStart(e,i,i.bottom);return{...i,top:o}}findHorizontalZone(e,t,s){const i={top:s,bottom:s,left:0,right:t-1},o=this.reduceZoneStart(e,i,i.right);return{...i,left:o}}reduceZoneStart(e,t,s){const i=Gs(t,e,(e=>e),void 0).flat(),o=fs(s,-1,-1),n=_s(o.filter((e=>{var t;return i[e]&&!(null===(t=i[e])||void 0===t?void 0:t.isAutoSummable)}))),r=ms(o.filter((e=>this.isNumber(i[e]))))[0]||[];return _s(r)<n?1/0:Os(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===ke.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(M))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const s=new Set;return qs(t)?(s.add(1===Ws(t).width?"COL":"ROW"),s):(this.lastColIsEmpty(e,t)&&s.add("ROW"),this.lastRowIsEmpty(e,t)&&s.add("COL"),0===s.size&&s.add("COL"),s)}sumDimensions(e,t,s){return[...s.has("COL")?this.sumColumns(t,e):[],...s.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:s}=e;return{position:[s,t],zone:{...e,top:t,right:s-1}}}sumColumns(e,t){const s=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,s.bottom-1)},js(s).map((t=>({position:t,zone:{...e,right:t[0],left:t[0]}})))}sumRows(e,t){const s=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,s.right-1)},js(s).map((t=>({position:t,zone:{...e,top:t[1],bottom:t[1]}})))}dispatchCellUpdates(e,t){for(const s of t){const[t,i]=s.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:i,content:`=SUM(${this.getters.zoneToXC(e,s.zone)})`})}}nextEmptyRow(e,t){let s=t.bottom+1;const{left:i,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:s,top:s,left:i,right:o});)s++;return{...t,top:s,bottom:s}}nextEmptyCol(e,t){let s=t.right+1;const{top:i,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:s,right:s,top:i,bottom:o});)s++;return{...t,left:s,right:s}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}yh.getters=["getAutomaticSums"],yh.modes=["normal","headless"];class wh extends bh{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"PASTE":return this.isPasteAllowed(this.state,e.target,!!e.force);case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");return this.isPasteAllowed(i,s,!1)}}return 0}handle(e){var t,s,i,o;switch(e.type){case"COPY":case"CUT":this.state=this.getClipboardState(e.target,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);if(this._isPaintingFormat=!1,e.interactive)this.interactivePaste(this.state,e.target,e);else{const t=this.state.cells.length,s=this.state.cells[0].length;this.paste(this.state,e.target,n),this.selectPastedZone(s,t,e.target),this.status="invisible"}break;case"DELETE_CELL":{const{cut:t,paste:s}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Fs(t[0])){for(const[t,s]of js(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:s,sheetId:this.getters.getActiveSheetId()});break}const i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"INSERT_CELL":{const{cut:t,paste:s}=this.getInsertCellsTargets(e.zone,e.shiftDimension),i=this.getClipboardState(t,"CUT");e.interactive?this.interactivePaste(i,s,e):this.paste(i,s);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(s=this.state)||void 0===s?void 0:s.sheetId))return;this.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(i=this.state)||void 0===i?void 0:i.operation)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this.state=this.getClipboardState(e.target,"COPY"),this._isPaintingFormat=!0,this.status="visible";break;default:Ue(e)&&(this.status="invisible")}}getClipboardContent(){return this.state&&this.state.cells.length&&this.state.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const s=this.getters.getActiveSheet();let i;return i="COL"===t?{...e,left:e.right+1,right:s.cols.length-1}:{...e,top:e.bottom+1,bottom:s.rows.length-1},{cut:[i],paste:[e]}}getInsertCellsTargets(e,t){const s=this.getters.getActiveSheet();let i,o;return"COL"===t?(i={...e,right:s.cols.length-1},o={...e,left:e.right+1,right:e.right+1}):(i={...e,bottom:s.rows.length-1},o={...e,top:e.bottom+1,bottom:s.rows.length-1}),{cut:[i],paste:[o]}}removeMergeIfTopLeft(e){const{sheetId:t,col:s,row:i}=e,[o,n]=this.getters.getMainCell(t,s,i);if(n===i&&o===s){const e=this.getters.getMerge(t,s,i);e&&this.dispatch("REMOVE_MERGE",{sheetId:t,target:[e]})}}pasteMergeIfExist(e,t){let{sheetId:s,col:i,row:o}=e;const[n,r]=this.getters.getMainCell(s,i,o);if(n===i&&r===o){const e=this.getters.getMerge(s,i,o);if(!e)return;({sheetId:s,col:i,row:o}=t),this.dispatch("ADD_MERGE",{sheetId:s,force:!0,target:[{left:i,top:o,right:i+e.right-e.left,bottom:o+e.bottom-e.top}]})}}getPasteZones(e,t){if(!t.length||!t[0].length)return e;const s=[],i=t.length,o=t[0].length,n=e[e.length-1],r=n.left,a=n.top,l=Math.max(1,Math.floor((n.right+1-r)/o)),c=Math.max(1,Math.floor((n.bottom+1-a)/i));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)s.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*i});return s}getClipboardState(e,t){const s=new Set(e.map((e=>e.top))),i=new Set(e.map((e=>e.bottom)));let o=1===s.size&&1===i.size?e:[e[e.length-1]];o=o.map((e=>({...e})));const n=[],r=[],a=this.getters.getActiveSheetId(),{top:l,bottom:c}=o[0];for(let e=l;e<=c;e++){const t=[];n.push(t);for(let s of o)for(let i=s.left;i<=s.right;i++){const s=this.getters.getCell(a,i,e),o=this.getters.getCellBorder(a,i,e)||void 0;t.push({cell:s,border:o,position:{col:i,row:e,sheetId:a}});const n=this.getters.getMerge(a,i,e);n&&n.top===e&&n.left===i&&r.push(n)}}return{cells:n,operation:t,sheetId:a,zones:o,merges:r}}pasteFromClipboard(e,t){this.status="invisible";const s=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:i,top:o}=e[0],n=Math.max.apply(Math,s.map((e=>e.length))),r=s.length,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,r,i,o);for(let e=0;e<s.length;e++)for(let t=0;t<s[e].length;t++)this.dispatch("UPDATE_CELL",{row:o+e,col:i+t,content:s[e][t],sheetId:a.id});const l={left:i,top:o,right:i+n-1,bottom:o+r-1};this.dispatch("SET_SELECTION",{anchor:[i,o],zones:[l],anchorZone:l})}isPasteAllowed(e,t,s){const i=this.getters.getActiveSheetId();if(!e)return 20;if(t.length>1&&(e.cells.length>1||e.cells[0].length>1))return 19;if(!s)for(let s of this.getPasteZones(t,e.cells))if(this.getters.doesIntersectMerge(i,s))return 2;return 0}paste(e,t,s){if("CUT"===e.operation&&this.clearClippedZones(e),t.length>1)for(const i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,t,o,s);else{const i=e.cells.length,o=e.cells[0].length,n=t[0],r=Math.max(1,Math.floor((n.right+1-n.left)/o)),a=Math.max(1,Math.floor((n.bottom+1-n.top)/i));for(let t=0;t<r;t++)for(let r=0;r<a;r++)this.pasteZone(e,n.left+t*o,n.top+r*i,s)}"CUT"===e.operation&&(this.dispatch("REMOVE_MERGE",{sheetId:e.sheetId,target:e.merges}),this.state=void 0)}selectPastedZone(e,t,s){const i=s[0],o=i.left,n=i.top,r=Math.max(1,Math.floor((i.right+1-i.left)/e)),a=Math.max(1,Math.floor((i.bottom+1-i.top)/t));if(t>1||e>1){const s={left:o,top:n,right:o+r*e-1,bottom:n+a*t-1},[i,l]=this.getters.getSelection().anchor,c=ps(i,o,o+r*e-1),h=ps(l,n,n+a*t-1);this.dispatch("SET_SELECTION",{anchor:[c,h],zones:[s],anchorZone:s})}}clearClippedZones(e){for(const t of e.cells)for(const e of t)e.cell&&this.dispatch("CLEAR_CELL",e.position);this.dispatch("CLEAR_FORMATTING",{sheetId:e.sheetId,target:e.zones})}pasteZone(e,t,s,i){const o=e.cells.length,n=e.cells[0].length,r="onlyValue"!==i&&this.state&&this.state===e,a=this.getters.getActiveSheet();this.addMissingDimensions(a,n,o,t,s);for(let l=0;l<o;l++){const o=e.cells[l];for(let c=0;c<n;c++){const n=o[c],h={col:t+c,row:s+l,sheetId:a.id};this.removeMergeIfTopLeft(h),this.pasteMergeIfExist(n.position,h),this.pasteCell(n,h,e.operation,e.zones,i),r&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:h,operation:e.operation})}}}addMissingDimensions(e,t,s,i,o){const{cols:n,rows:r,id:a}=e,l=s+o-r.length;l>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:r.length-1,sheetId:a,quantity:l,position:"after"});const c=t+i-n.length;c>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:n.length-1,sheetId:a,quantity:c,position:"after"})}pasteCell(e,t,s,i,o){const{sheetId:n,col:r,row:a}=t,l=this.getters.getCell(n,r,a);if("onlyValue"!==o&&this.dispatch("SET_BORDER",{sheetId:n,col:r,row:a,border:e.border}),e.cell){if("onlyFormat"===o)return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.format});if("onlyValue"===o){const s=qr(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:s})}let l=e.cell.content;if(e.cell.isFormula()){const t=r-e.position.col,o=a-e.position.row;l=this.getUpdatedContent(n,e.cell,t,o,i,s)}this.dispatch("UPDATE_CELL",{...t,content:l,style:e.cell.style||null,format:e.cell.format})}else l&&("onlyValue"===o?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===o?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,s,i,o,n){if("CUT"===n){const n=[];for(const r of t.dependencies.references)this.isZoneOverlapClippedZone(o,r.zone)?n.push(...this.getters.createAdaptedRanges([r],s,i,e)):n.push(r);const r={...t.dependencies,references:n};return this.getters.buildFormulaContent(e,t.normalizedText,r)}const r=this.getters.createAdaptedRanges(t.dependencies.references,s,i,e),a={...t.dependencies,references:r};return this.getters.buildFormulaContent(e,t.normalizedText,a)}isZoneOverlapClippedZone(e,t){return e.some((e=>Vs(t,e)))}interactivePaste(e,t,s){const i=this.isPasteAllowed(e,t,!1);0!==i?(19===i&&this.ui.notifyUser(a("This operation is not allowed with multiple selections.")),2===i&&this.ui.notifyUser(a("This operation is not possible due to a merge. Please remove the merges first than try again."))):this.dispatch(s.type,{...s,interactive:!1})}isColRowDirtyingClipboard(e,t){if(!this.state||!this.state.zones)return!1;for(let s of this.state.zones){if("COL"===t&&e<=s.right)return!0;if("ROW"===t&&e<=s.bottom)return!0}return!1}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e;if("visible"===this.status&&this.state&&this.state.zones&&this.state.zones.length&&this.state.sheetId===this.getters.getActiveSheetId()){s.setLineDash([8,5]),s.strokeStyle=p,s.lineWidth=3.3*i;for(const e of this.state.zones){const[i,o,n,r]=this.getters.getRect(e,t);n>0&&r>0&&s.strokeRect(i,o,n,r)}}}}var Th;wh.layers=[2],wh.getters=["getClipboardContent","isPaintingFormat"],wh.modes=["normal"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}(Th||(Th={}));class xh extends bh{constructor(e,t,s,i){super(e,t,s,i),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0],anchorZone:{top:0,left:0,bottom:0,right:0}},this.selectedFigureId=null,this.activeCol=0,this.activeRow=0,this.mode=Th.idle,this.sheetsData={},this.activeSheet=null,this.moveClient=i.moveClient}allowDispatch(e){switch(e.type){case"SET_SELECTION":if(-1===e.zones.findIndex((t=>Bs(t,e.anchorZone))))return 16;break;case"ALTER_SELECTION":if(e.delta){const{left:t,right:s,top:i,bottom:o}=this.getSelectedZone(),n=this.getters.getActiveSheet(),r=ri(n,"cols",fs(t,s+1)),a=ri(n,"rows",fs(i,o+1));if(0!==e.delta[0]&&void 0===a||0!==e.delta[1]&&void 0===r)return 17}break;case"MOVE_POSITION":{const{cols:t,rows:s}=this.getters.getActiveSheet();if(0!==e.deltaX&&s[this.activeRow].isHidden||0!==e.deltaY&&t[this.activeCol].isHidden)return 17;const{col:i,row:o}=this.getNextAvailablePosition(e.deltaX,e.deltaY);if(o<0||o>s.length-1||i<0||i>t.length-1)return 17;break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().cols.length)return 17;break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.getters.getActiveSheet().rows.length)return 17;break}case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 23}case"MOVE_COLUMNS_ROWS":const t=this.isMoveElementAllowed(e);return 2===t&&this.ui.notifyUser(a("Merged cells are preventing this operation. Unmerge those cells and try again.")),t}return 0}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":case"CREATE_FIGURE":case"CREATE_CHART":case"UPDATE_FIGURE":case"EVALUATE_CELLS":case"DISABLE_SELECTION_INPUT":case"ENABLE_NEW_SELECTION_INPUT":case"RESIZE_VIEWPORT":break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;default:this.selectedFigureId=null}switch(e.type){case"START":const t=ni(this.getters.getSheets()[0],0,0);this.activeCol=t[0],this.activeRow=t[1],this.dispatch("ACTIVATE_SHEET",{sheetIdTo:this.getters.getSheets()[0].id,sheetIdFrom:this.getters.getSheets()[0].id}),this.selectCell(...t);break;case"ACTIVATE_SHEET":this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow},e.sheetIdTo in this.sheetsData?Object.assign(this,this.sheetsData[e.sheetIdTo]):this.selectCell(...ni(this.getters.getSheet(e.sheetIdTo),0,0));break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.anchorZone,e.strict);break;case"START_SELECTION":this.mode=Th.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=Th.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=Th.expanding;break;case"STOP_SELECTION":this.mode=Th.idle;break;case"MOVE_POSITION":this.movePosition(e.deltaX,e.deltaY);break;case"SELECT_CELL":this.selectCell(e.col,e.row);break;case"SELECT_COLUMN":this.selectColumn(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ROW":this.selectRow(e.index,e.createRange||!1,e.updateRange||!1);break;case"SELECT_ALL":this.selectAll();break;case"ALTER_SELECTION":e.delta&&this.moveSelection(e.delta[0],e.delta[1]),e.cell&&this.addCellToSelection(...e.cell);break;case"UNDO":case"REDO":case"DELETE_SHEET":if(!this.getters.tryGetSheet(this.getActiveSheetId())){const e=this.getters.getVisibleSheets();this.activeSheet=this.getters.getSheet(e[0]),this.selectCell(0,0)}this.ensureSelectionValidity();break;case"REMOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&("COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e));break;case"ADD_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onAddElements(e);break;case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"UPDATE_CHART":case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left")}}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getMainCell(e,this.activeCol,this.activeRow);return this.getters.getCell(e,t,s)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.getters.getActiveSheet().rows.length-1)for(let s=t.left;s<=t.right;s++)e.add(s);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.getters.getActiveSheet().cols.length-1)for(let s=t.top;s<=t.bottom;s++)e.add(s);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.anchorZone}getSelection(){return this.selection}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return[this.activeCol,this.activeRow]}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?[t.activeCol,t.activeRow]:ni(this.getters.getSheet(e),0,0)}}getAggregate(){let e=0,t=0;for(let s of this.selection.zones)for(let i=s.top;i<=s.bottom;i++){const o=this.getters.getRow(this.getters.getActiveSheetId(),i);if(void 0!==o)for(let i=s.left;i<=s.right;i++){const s=o.cells[i];(null==s?void 0:s.evaluated.type)===ke.number&&(t++,e+=s.evaluated.value)}}return t<2?null:ie(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Bs(t,e)))}getVisibleFigures(e){const t=[],s=this.getters.getFigures(e),{offsetX:i,offsetY:o}=this.getters.getSnappedViewport(e),{width:n,height:r}=this.getters.getViewportDimension();for(let e of s)e.x>=i+n||e.x+e.width<=i||e.y>=o+r||e.y+e.height<=o||t.push(e);return t}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let s=[];const i="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[i]+1},((t,s)=>e[i]+s));s=s.concat(t)}return[...new Set(s)].sort()}selectColumn(e,t,s){const i=this.getters.getActiveSheet().rows.length-1;let o={left:e,right:e,top:0,bottom:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().rows.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Ps(o,{left:e,right:e,top:l,bottom:i}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[e,l];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectRow(e,t,s){const i=this.getters.getActiveSheet().cols.length-1;let o={top:e,bottom:e,left:0,right:i};const n=this.selection.zones;let r,a;const l=this.getters.getActiveSheet().cols.findIndex((e=>!e.isHidden));if(s){const[e,t]=this.selection.anchor;o=Ps(o,{left:l,right:i,top:t,bottom:t}),r=this.updateSelectionZones(o),a=[e,t]}else r=t?n.concat(o):[o],a=[l,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0,anchorZone:o})}selectAll(){const e={left:0,top:0,bottom:this.getters.getActiveSheet().rows.length-1,right:this.getters.getActiveSheet().cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0],anchorZone:e})}selectCell(e,t){const s=this.getters.getActiveSheet();this.moveClient({sheetId:s.id,col:e,row:t});let i=this.getters.expandZone(s.id,{left:e,right:e,top:t,bottom:t});this.mode===Th.expanding?this.selection.zones.push(i):this.selection.zones=[i],this.selection.zones=Xs(this.selection.zones),this.selection.anchorZone=i,this.selection.anchor=[e,t],this.activeCol=e,this.activeRow=t}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}getNextAvailablePosition(e,t){return{col:this.getNextAvailableCol(e,this.activeCol,this.activeRow),row:this.getNextAvailableRow(t,this.activeCol,this.activeRow)}}getNextAvailableCol(e,t,s){const{cols:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,t,n,(e=>this.getters.isInSameMerge(o,t,s,e,s)))}getNextAvailableRow(e,t,s){const{rows:i,id:o}=this.getActiveSheet(),n={col:t,row:s};return this.getNextAvailableHeader(e,i,s,n,(e=>this.getters.isInSameMerge(o,t,s,t,e)))}getNextAvailableHeader(e,t,s,i,o){var n,r,a;const l=this.getters.getActiveSheetId(),{col:c,row:h}=i;if(0===e)return s;let d=s+e;if(this.getters.isInMerge(l,c,h)){for(;o(d);)d+=e;for(;null===(n=t[d])||void 0===n?void 0:n.isHidden;)d+=e}else if(null===(r=t[d])||void 0===r?void 0:r.isHidden)for(;null===(a=t[d])||void 0===a?void 0:a.isHidden;)d+=e;return d<0||d>t.length-1?t[s].isHidden?this.getNextAvailableHeader(-e,t,s,i,o):s:d}movePosition(e,t){const{col:s,row:i}=this.getNextAvailablePosition(e,t);this.selectCell(s,i)}setSelection(e,t,s,i=!1){this.selectCell(...e);const o=this.getters.getActiveSheetId();let n;t=Xs(t),n=i?{zones:t,anchorZone:s,anchor:e}:{anchor:e,zones:t.map((e=>this.getters.expandZone(o,e))),anchorZone:this.getters.expandZone(o,s)},this.selection=this.clipSelection(o,n)}getReferencePosition(){const e=this.getters.getActiveSheet(),t=this.selection,{left:s,right:i,top:o,bottom:n}=t.anchorZone,[r,a]=t.anchor;return{col:e.cols[r].isHidden&&ri(e,"cols",fs(s,i+1))||r,row:e.rows[a].isHidden&&ri(e,"rows",fs(o,n+1))||a}}moveSelection(e,t){const s=this.selection;let i=[];const[o,n]=s.anchor,{left:r,right:a,top:l,bottom:c}=s.anchorZone;let h=s.anchorZone;const d=this.getters.getActiveSheet(),u=e=>{const{left:t,right:s,top:i,bottom:o}=this.getters.expandZone(d.id,e);return{left:Math.max(0,t),right:Math.min(d.cols.length-1,s),top:Math.max(0,i),bottom:Math.min(d.rows.length-1,o)}},{col:p,row:g}=this.getReferencePosition();let f=0;for(;null!==h;){if(f++,e<0){const t=this.getNextAvailableCol(e,a-(f-1),g);h=p<=a-f?u({top:l,left:r,bottom:c,right:t}):null}if(e>0){const t=this.getNextAvailableCol(e,r+(f-1),g);h=r+f<=p?u({top:l,left:t,bottom:c,right:a}):null}if(t<0){const e=this.getNextAvailableRow(t,p,c-(f-1));h=g<=c-f?u({top:l,left:r,bottom:e,right:a}):null}if(t>0){const e=this.getNextAvailableRow(t,p,l+(f-1));h=l+f<=g?u({top:e,left:r,bottom:c,right:a}):null}if(h=h?Ks(h):h,h&&!Bs(h,s.anchorZone))return i=this.updateSelectionZones(h),void this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h})}h=u(Ps({top:n,bottom:n,left:o,right:o},Ks({top:this.getNextAvailableRow(t,p,l),left:this.getNextAvailableCol(e,r,g),bottom:this.getNextAvailableRow(t,p,c),right:this.getNextAvailableCol(e,a,g)}))),Bs(h,s.anchorZone)||(i=this.updateSelectionZones(h),this.dispatch("SET_SELECTION",{zones:i,anchor:[o,n],anchorZone:h}))}addCellToSelection(e,t){const s=this.selection,[i,o]=s.anchor,n={left:Math.min(i,e),top:Math.min(o,t),right:Math.max(i,e),bottom:Math.max(o,t)},r=this.updateSelectionZones(n);this.dispatch("SET_SELECTION",{zones:r,anchor:[i,o],anchorZone:n})}ensureSelectionValidity(){const{anchor:e,zones:t,anchorZone:s}=this.clipSelection(this.getActiveSheetId(),this.selection);this.setSelection(e,t,s);const i=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of i)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:s,anchorZone:i}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:s,anchorZone:i},activeCol:t[0],activeRow:t[1]}}}clipSelection(e,t){const s=this.getters.getSheet(e),i=s.cols.length-1,o=s.rows.length-1,n=t.zones.map((e=>({left:ps(e.left,0,i),right:ps(e.right,0,i),top:ps(e.top,0,o),bottom:ps(e.bottom,0,o)})));return{anchor:[ps(t.anchor[0],0,i),ps(t.anchor[1],0,o)],zones:n,anchorZone:{left:ps(t.anchorZone.left,0,i),right:ps(t.anchorZone.right,0,i),top:ps(t.anchorZone.top,0,o),bottom:ps(t.anchorZone.bottom,0,o)}}}onColumnsRemoved(e){const t=Us(this.getSelectedZone(),"left",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onRowsRemoved(e){const t=Us(this.getSelectedZone(),"top",e.elements);this.setSelection([t.left,t.top],[t],t,!0),this.ensureSelectionValidity()}onAddElements(e){const t=Ds(this.getSelectedZone(),"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.setSelection([t.left,t.top],[t],t,!0)}updateSelectionZones(e){let t=[...this.selection.zones];const s=this.selection.anchorZone,i=t.findIndex((e=>Bs(e,s)));return i>=0&&(t[i]=e),t}activateNextSheet(e){const t=this.getters.getSheets().map((e=>e.id)),s=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[s]})}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:"before"});const s="COL"===e.dimension,i=e.elements[0],o=e.elements[t-1],n=e.base<i,r=n&&s?t:0,a=n&&!s?t:0,l=this.getters.getSheet(e.sheetId);this.dispatch("CUT",{target:[{left:s?i+r:0,right:s?o+r:l.cols.length-1,top:s?0:i+a,bottom:s?l.rows.length-1:o+a}]}),this.dispatch("PASTE",{target:[{left:s?e.base:0,right:s?e.base+t-1:l.cols.length-1,top:s?0:e.base,bottom:s?l.rows.length-1:e.base+t-1}]});const c=n?e.elements.map((e=>e+t)):e.elements;let h=e.base;for(const t of c){const s="COL"===e.dimension?this.getters.getCol(e.sheetId,t).size:this.getters.getRow(e.sheetId,t).size;this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:s,elements:[h]}),h+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:c})}isMoveElementAllowed(e){const t="COL"===e.dimension,s=e.elements[0],i=e.elements[e.elements.length-1],o=e.sheetId,n=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return n(o,s-1,s)||n(o,i,i+1)||n(o,e.base-1,e.base)?2:0}drawGrid(e){if("inactive"!==this.getters.getEditionMode())return;const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getSelectedZones();s.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;s.fillStyle=n?"#f3f7fe":"#e9f0ff",s.strokeStyle=p,s.lineWidth=1.5*i,s.globalCompositeOperation="multiply";for(const e of o){const[i,o,n,r]=this.getters.getRect(e,t);s.fillRect(i,o,n,r),s.strokeRect(i,o,n,r)}s.globalCompositeOperation="source-over";const r=this.getters.getActiveSheetId(),[a,l]=this.getPosition();let c;s.strokeStyle=p,s.lineWidth=3*i,c=this.getters.isInMerge(r,a,l)?this.getters.getMerge(r,a,l):{top:l,bottom:l,left:a,right:a};const[h,d,u,g]=this.getters.getRect(c,t);u>0&&g>0&&s.strokeRect(h,d,u,g)}}xh.layers=[5],xh.modes=["normal"],xh.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getAggregate","getSelectedFigureId","getVisibleFigures","getSelection","getPosition","getSheetPosition","getSelectionMode","isSelected","getElementsFromSelection"];const Rh=a("The cell you are trying to edit has been deleted.");class Lh extends bh{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.multiSelectionInitialStart=0,this.initialContent="",this.previousRef="",this.previousRange=void 0,this.colorIndexByRange={}}allowDispatch(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":return this.validateSelection(this.currentContent.length,e.start,e.end);case"SET_CURRENT_CONTENT":return e.selection?this.validateSelection(e.content.length,e.selection.start,e.selection.end):0;case"START_EDITION":if(e.selection){const t=this.getters.getActiveCell(),s=e.text||(null==t?void 0:t.composerContent)||"";return this.validateSelection(s.length,e.selection.start,e.selection.end)}return 0;default:return 0}}handle(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":this.selectionStart=e.start,this.selectionEnd=e.end;break;case"STOP_COMPOSER_RANGE_SELECTION":this.isSelectingForComposer()&&(this.mode="editing");break;case"START_EDITION":this.startEdition(e.text,e.selection);break;case"STOP_EDITION":e.cancel?(this.cancelEdition(),this.resetContent()):this.stopEdition();break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0);break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEdition(),this.resetContent();break;case"SELECT_CELL":case"SET_SELECTION":case"MOVE_POSITION":switch(this.mode){case"editing":this.dispatch("STOP_EDITION");break;case"waitingForRangeSelection":this.insertSelectedRange();break;case"rangeSelected":switch(e.type){case"MOVE_POSITION":this.replaceAllSelectedRanges();break;case"SELECT_CELL":this.getters.getSelectionMode()===Th.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges();break;case"SET_SELECTION":e.strict?this.getters.getSelectionMode()===Th.expanding?this.insertSelectedRange():this.replaceAllSelectedRanges():this.replaceSelectedRange()}}break;case"ADD_COLUMNS_ROWS":this.onAddElements(e);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);break;case"START_CHANGE_HIGHLIGHT":this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const t=this.currentTokens.filter((e=>"SYMBOL"===e.type)).find((t=>{let s=t.value;const{xc:i,sheetName:o}=es(s),n=o||this.getters.getSheetName(this.sheet),r=this.getters.getActiveSheetId();return Bs(this.getters.expandZone(r,ks(i)),e.zone)&&this.getters.getSheetName(r)===n}));this.previousRef=t.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=t.start;break;case"CHANGE_HIGHLIGHT":const s=this.getZoneReference(e.zone,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(s),this.previousRef=s,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheet)||"inactive"===this.mode||(this.cancelEdition(),this.resetContent(),this.ui.notifyUser(Rh))}}getEditionMode(){return this.mode}getCurrentContent(){if("inactive"===this.mode){const e=this.getters.getActiveCell();return(null==e?void 0:e.composerContent)||""}return this.currentContent}getEditionSheet(){return this.sheet}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}isSelectingForComposer(){return"waitingForRangeSelection"===this.mode||"rangeSelected"===this.mode||"resettingPosition"===this.mode}getCurrentTokens(){return this.currentTokens}getTokenAtCursor(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return e===t&&0===t?void 0:this.currentTokens.find((s=>s.start<=e&&s.end>=t))}validateSelection(e,t,s){return t>=0&&t<=e&&s>=0&&s<=e?0:31}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Rh);const{top:t,left:s}=Us({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",e.elements);this.col=s,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUser(Rh);const{top:t,left:s}=Us({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",e.elements);this.col=s,this.row=t}onAddElements(e){const{top:t,left:s}=Ds({left:this.col,right:this.col,top:this.row,bottom:this.row},"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.col=s,this.row=t}startComposerRangeSelection(){this.mode="resettingPosition",this.sheet===this.getters.getActiveSheetId()&&this.dispatch("SELECT_CELL",{col:this.col,row:this.row}),this.mode="waitingForRangeSelection",this.multiSelectionInitialStart=this.selectionStart}startEdition(e,t){const s=this.getters.getActiveCell();this.initialContent=(null==s?void 0:s.composerContent)||"",this.mode="editing";const[i,o]=this.getters.getPosition();this.col=i,this.row=o,this.sheet=this.getters.getActiveSheetId(),this.setContent(e||this.initialContent,t),this.colorIndexByRange={}}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();const e=this.getters.getActiveSheetId(),t=this.getters.getSheets().find((e=>e.id===this.sheet)).id,[s,i]=this.getters.getMainCell(t,this.col,this.row);let o=this.currentContent;if(!(this.initialContent!==o))return;if(o){const t=this.getters.getCell(e,s,i);if(o.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,s=e-t;s>0&&(o+=new Array(s).fill(")").join(""))}else(null==t?void 0:t.isLink())&&(o=ys(o,t.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheet,col:s,row:i,content:o})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheet,content:"",col:s,row:i});e!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheet}),this.setContent("")}}cancelEdition(){this.mode="inactive"}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,s){e=e.replace(/[\r\n]/g,"");const i=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(i||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?zr(e):[],this.currentTokens.length>100&&s&&this.ui.notifyUser(a("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(){const e=Math.min(this.selectionStart,this.selectionEnd),t=this.getZoneReference(this.getters.getSelectedZone());if("waitingForRangeSelection"===this.mode)return this.insertText(t,e),this.selectionInitialStart=e,void(this.mode="rangeSelected");this.insertText(","+t,e),this.selectionInitialStart=e+1}replaceSelectedRange(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.selectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone()))}replaceAllSelectedRanges(){const{end:e}=this.getters.getComposerSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:this.multiSelectionInitialStart,end:e}),this.replaceSelection(this.getZoneReference(this.getters.getSelectedZone())),this.selectionInitialStart=this.multiSelectionInitialStart}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const s=this.getters.getActiveSheetId();let i=this.getters.zoneToXC(s,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){i=`${us(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${i}`}return i}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),s=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,s)}replaceText(e,t,s){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(s,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const s=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),i=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:s,selection:{start:i,end:i}})}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=[],t={};for(let s of this.currentTokens.filter((e=>"SYMBOL"===e.type))){let i=s.value;const{xc:o,sheetName:n}=es(i);if(Jt.test(o)){const s=(n?`${n}!`:`${this.getters.getSheetName(this.getters.getEditionSheet())}!`)+o.replace(/\$/g,"");e.push(s);const i=this.colorIndexByRange[s];void 0!==i&&(t[s]=i)}}this.colorIndexByRange=t;let s=Object.values(t),i=0;return e.map((e=>{if(void 0===this.colorIndexByRange[e]){for(;s.includes(i);)i++;s.push(i),this.colorIndexByRange[e]=i}return[e,qt[this.colorIndexByRange[e]%qt.length]]}))}canStartComposerRangeSelection(){if("editing"!==this.mode&&this.selectionStart===this.selectionEnd)return!1;if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(e){const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let s=t,i=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type||s<1)return!1;s--,i=this.currentTokens[s]}for(s=t+1,i=this.currentTokens[s];i&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(i.type);){if("SPACE"!==i.type)return!1;s++,i=this.currentTokens[s]}s++,i=this.currentTokens[s]}return!0}return!1}}Lh.getters=["getEditionMode","isSelectingForComposer","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights"],Lh.modes=["normal"];const Ah=rr.mapping;class Mh extends bh{constructor(e,t,s,i){super(e,t,s,i),this.isUpToDate=new Set,this.evalContext=i.evalContext,i.dataSources.on("data-loaded",this,(()=>{this.dispatch("EVALUATE_CELLS",{sheetId:this.getters.getActiveSheetId()})}))}handle(e){switch(Fe.has(e.type)&&this.isUpToDate.clear(),e.type){case"UPDATE_CELL":"content"in e&&this.isUpToDate.clear();break;case"ACTIVATE_SHEET":this.evaluate(e.sheetIdTo),this.isUpToDate.add(e.sheetIdTo);break;case"EVALUATE_CELLS":this.evaluate(e.sheetId),this.isUpToDate.add(e.sheetId);break;case"EVALUATE_ALL_SHEETS":this.evaluateAllSheets()}}finalize(){const e=this.getters.getActiveSheetId();this.isUpToDate.has(e)||(this.evaluate(e),this.isUpToDate.add(e))}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{let s=Zr(e);const i=Br(s),o=this.getFormulaParameters((()=>{})),n=[];for(let e of s.dependencies.references)n.push(this.getters.getRangeFromSheetXC(t,e));return i({...s.dependencies,references:n},t,...o)}catch(e){return"#ERROR"}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Gs(e.zone,t,(e=>this.getters.getCellText(e,this.getters.shouldShowFormulas())),"")}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[[]]:Gs(e.zone,t,(e=>e.evaluated.value))}evaluate(e){const t=this.getters.getCells(e),s=this.getFormulaParameters(o),i={};for(let s of Object.values(t))o(s,e);function o(e,t){if(!e.isFormula())return;const o=e.id;if(o in i)null===i[o]&&e.assignError("#CYCLE",a("Circular reference"));else{i[o]=null;try{if(s[2].__originCellXC=()=>{const e=s[2].getters.getCellPosition(o);return is(e.col,e.row)},e.assignValue(e.compiledFormula(e.dependencies,t,...s)),Array.isArray(e.evaluated.value))throw new Error(a("This formula depends on invalid values"))}catch(t){!function(e,t){if(e instanceof Error||(e=new Error(e)),"#CYCLE"!==t.evaluated.value){t.assignValue("#ERROR");const i=s[2].__lastFnCalled||"";t.assignError("#ERROR",e.message.replace("[[FUNCTION_NAME]]",i))}}(t,e)}i[o]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Ah),this.evalContext,{getters:this.getters});function s(t,s){if(e(t,s),t.evaluated.type===ke.error)throw new Error(a("This formula depends on invalid values"));return t.evaluated.value}function i(e){o(e);const i=t.getters.getSheet(e.sheetId),n={top:0,bottom:i.rows.length-1,left:0,right:i.cols.length-1},r=[],a=function(e,t){if(Vs(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom,t.bottom),right:Math.min(e.right,t.right)}}(e.zone,n);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const o=[];for(let n=a.top;n<=a.bottom;n++){const r=t.getters.getCell(e.sheetId,i,n);o.push(r?s(r,e.sheetId):void 0)}r.push(o)}return r}function o(e){if(!Fs(e.zone))throw new Error(a("Invalid reference"));if(e.invalidSheetName)throw new Error(a("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,i,n,r,l,c){const h=i[e];if(o(h),r)return t.getters.getRangeString(h,n);if(h.zone.bottom!==h.zone.top||h.zone.left!==h.zone.right)throw new Error(c?a("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",l.toString(),c.toString()):a("Function %s expects its parameters to be single values or single cell references, not ranges.",l.toString()));return function(e){var i;const o=null===(i=t.getters.getSheet(e.sheetId).rows[e.zone.top])||void 0===i?void 0:i.cells[e.zone.left];return!o||o.isEmpty()?null:s(o,e.sheetId)}(h)},function(e,t,s){return i(t[e])},t]}evaluateAllSheets(){for(const e of this.getters.getVisibleSheets())this.evaluate(e),this.isUpToDate.add(e)}}Mh.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"],Mh.modes=["normal"];const _h=["rgb(31,119,180)","rgb(255,127,14)","rgb(174,199,232)","rgb(255,187,120)","rgb(44,160,44)","rgb(152,223,138)","rgb(214,39,40)","rgb(255,152,150)","rgb(148,103,189)","rgb(197,176,213)","rgb(140,86,75)","rgb(196,156,148)","rgb(227,119,194)","rgb(247,182,210)","rgb(127,127,127)","rgb(199,199,199)","rgb(188,189,34)","rgb(219,219,141)","rgb(23,190,207)","rgb(158,218,229)"];class Oh{constructor(){this.graphColorIndex=0}next(){return _h[this.graphColorIndex++%_h.length]}}class Nh extends bh{constructor(){super(...arguments),this.chartRuntime={},this.outOfDate=new Set}handle(e){if(Fe.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type&&"content"in e)for(let e of Object.keys(this.chartRuntime))this.outOfDate.add(e);switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const t=this.getters.getChartDefinition(e.id);this.chartRuntime[e.id]=this.mapDefinitionToRuntime(t);break;case"DELETE_FIGURE":delete this.chartRuntime[e.id];break;case"REFRESH_CHART":this.evaluateUsedSheets([e.id]),this.outOfDate.add(e.id);break;case"ACTIVATE_SHEET":const s=this.getters.getChartsIdBySheet(e.sheetIdTo);this.evaluateUsedSheets(s);break;case"DELETE_SHEET":for(let e of Object.keys(this.chartRuntime))this.getters.getChartDefinition(e)||delete this.chartRuntime[e]}}getChartRuntime(e){if(this.outOfDate.has(e)||!(e in this.chartRuntime)){const t=this.getters.getChartDefinition(e);if(void 0===t)return;this.chartRuntime[e]=this.mapDefinitionToRuntime(t),this.outOfDate.delete(e)}return this.chartRuntime[e]}truncateLabel(e){return e?e.length>20?e.substring(0,20)+"…":e:""}getDefaultConfiguration(e,t){const s={};e.labelRange||1!==e.dataSets.length?s.position=e.legendPosition:s.display=!1;const i={type:e.type,options:{legend:s,responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:e.title?10:25,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!!e.title,fontSize:22,fontStyle:"normal",text:e.title}},data:{labels:t.map(this.truncateLabel),datasets:[]}};return"pie"!==e.type?(i.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{position:e.verticalAxisPosition,ticks:{beginAtZero:!0}}]},"bar"===e.type&&e.stackedBar&&(i.options.scales.xAxes[0].stacked=!0,i.options.scales.yAxes[0].stacked=!0)):i.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},i}getSheetIdsUsedInChart(e){const t=new Set;for(let s of e.dataSets)t.add(s.dataRange.sheetId);return e.labelRange&&t.add(e.labelRange.sheetId),t}evaluateUsedSheets(e){const t=new Set;for(let s of e){const e=this.getters.getChartDefinition(s);(void 0!==e?this.getSheetIdsUsedInChart(e):[]).forEach((e=>{e!==this.getters.getActiveSheetId()&&t.add(e)}))}for(let e of t)this.dispatch("EVALUATE_CELLS",{sheetId:e})}mapDefinitionToRuntime(e){let t=[];if(e.labelRange)e.labelRange.invalidXc||e.labelRange.invalidSheetName||(t=this.getters.getRangeFormattedValues(e.labelRange).flat(1));else if(1===e.dataSets.length)for(let s=0;s<this.getData(e.dataSets[0],e.sheetId).length;s++)t.push("");else if(e.dataSets[0]){t=fs(0,this.getData(e.dataSets[0],e.sheetId).length).map((e=>e.toString()))}const s=this.getDefaultConfiguration(e,t),i=new Oh,o=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.getData(t,e.sheetId).length)));for(let e=0;e<=t;e++)o.push(i.next())}for(const[t,n]of Object.entries(e.dataSets)){let r;if(n.labelCell){const e=n.labelCell,s=e?this.getters.getCell(e.sheetId,e.zone.left,e.zone.top):void 0;r=s&&e?this.truncateLabel(s.formattedValue):r=`${dc.Series} ${parseInt(t)+1}`}else r=r=`${dc.Series} ${parseInt(t)+1}`;const a="pie"!==e.type?i.next():"#FFFFFF",l={label:r,data:n.dataRange?this.getData(n,e.sheetId):[],lineTension:0,borderColor:a,backgroundColor:a};"pie"===e.type&&(l.backgroundColor=o),s.data.datasets.push(l)}return s}getData(e,t){if(e.dataRange){const t=e.labelCell?[$s(e.labelCell.zone)]:[],s=zs([$s(e.dataRange.zone)],t)[0];if(void 0===s)return[];const i=this.getters.getRangeFromSheetXC(e.dataRange.sheetId,s);return this.getters.getRangeValues(i).flat(1)}return[]}}Nh.getters=["getChartRuntime"],Nh.modes=["normal"];class kh extends bh{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new oi,this.rulePredicate={CellIsRule:(e,t)=>{var s,i,o,n,r,l;if(e&&e.evaluated.type===ke.error)return!1;const c=t.values.map(jr);switch(t.operator){case"IsEmpty":return!Ls(e)||""===(null===(s=e.evaluated.value)||void 0===s?void 0:s.toString().trim());case"IsNotEmpty":return Ls(e)&&""!==(null===(i=e.evaluated.value)||void 0===i?void 0:i.toString().trim());case"BeginsWith":return!(!e&&""===c[0])&&(Ls(e)&&(null===(o=e.evaluated.value)||void 0===o?void 0:o.toString().startsWith(c[0].toString())));case"EndsWith":return!(!e&&""===c[0])&&(Ls(e)&&(null===(n=e.evaluated.value)||void 0===n?void 0:n.toString().endsWith(c[0].toString())));case"Between":return Ls(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1];case"NotBetween":return!(Ls(e)&&e.evaluated.value>=c[0]&&e.evaluated.value<=c[1]);case"ContainsText":return Ls(e)&&(null===(r=e.evaluated.value)||void 0===r?void 0:r.toString().indexOf(c[0].toString()))>-1;case"NotContains":return!Ls(e)||!e.evaluated.value||-1==(null===(l=e.evaluated.value)||void 0===l?void 0:l.toString().indexOf(c[0].toString()));case"GreaterThan":return Ls(e)&&e.evaluated.value>c[0];case"GreaterThanOrEqual":return Ls(e)&&e.evaluated.value>=c[0];case"LessThan":return Ls(e)&&e.evaluated.value<c[0];case"LessThanOrEqual":return Ls(e)&&e.evaluated.value<=c[0];case"NotEqual":return!(!Ls(e)&&""===c[0])&&(Ls(e)&&e.evaluated.value!==c[0]);case"Equal":return!e&&""===c[0]||Ls(e)&&e.evaluated.value===c[0];default:console.warn(a("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch(e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const s=this.getters.getActiveSheetId(),i=this.getters.getRulesByCell(s,e.originCol,e.originRow);for(const t of i)this.adaptRules(s,t,[is(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation);break;case"DUPLICATE_SHEET":case"CREATE_SHEET":case"DELETE_SHEET":case"ADD_CONDITIONAL_FORMAT":case"REMOVE_CONDITIONAL_FORMAT":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":case"DELETE_CELL":case"INSERT_CELL":this.isStale=!0}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getConditionalStyle(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedStyles[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}getConditionalIcon(e,t){var s;const i=this.getters.getActiveSheetId(),o=this.computedIcons[i];return o&&(null===(s=o[e])||void 0===s?void 0:s[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const s=this.computedStyles[t];for(let i of this.getters.getConditionalFormats(t))switch(i.rule.type){case"ColorScaleRule":for(let e of i.ranges)this.applyColorScale(e,i.rule);break;case"IconSetRule":for(let e of i.ranges)this.applyIcon(e,i.rule);break;default:for(let o of i.ranges){const n=ks(o);for(let o=n.top;o<=n.bottom;o++)for(let r=n.left;r<=n.right;r++){const n=this.rulePredicate[i.rule.type];let a=this.getters.getCell(t,r,o);n&&n(a,i.rule)&&(s[r]||(s[r]=[]),s[r][o]=Object.assign((null===(e=s[r])||void 0===e?void 0:e[o])||{},i.rule.style))}}}}parsePoint(e,t,s){switch(t.type){case"value":return this.getters.evaluateFormula(`=${s}(${e})`);case"number":return Number(t.value);case"percentage":const i=this.getters.evaluateFormula(`=min(${e})`);return i+(this.getters.evaluateFormula(`=max(${e})`)-i)*Number(t.value)/100;case"percentile":return this.getters.evaluateFormula(`=PERCENTILE(${e},${Number(t.value)/100})`);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof o?o:null;default:return null}}applyIcon(e,t){const s=this.parsePoint(e,t.lowerInflectionPoint),i=this.parsePoint(e,t.upperInflectionPoint);if(null===s||null===i||s>i)return;const o=ks(e),n=this.getters.getActiveSheetId(),r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=o.top;e<=o.bottom;e++)for(let l=o.left;l<=o.right;l++){const o=this.getters.getCell(n,l,e);if((null==o?void 0:o.evaluated.type)!==ke.number)continue;const c=this.computeIcon(o.evaluated.value,i,t.upperInflectionPoint.operator,s,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,s,i,o,n){return"ge"===s&&e>=t||"gt"===s&&e>t?n[0]:"ge"===o&&e>=i||"gt"===o&&e>i?n[1]:n[2]}applyColorScale(e,t){var s;const i=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,n=this.parsePoint(e,t.maximum,"max");if(null===i||null===n||i>=n||o&&(i>=o||o>=n))return;const r=ks(e),a=this.getters.getActiveSheetId(),l=this.computedStyles[a],c=[];t.midpoint&&o?(c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.midpoint.color,t.maximum.color)})):c.push({minValue:i,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,n,t.minimum.color,t.maximum.color)});for(let e=r.top;e<=r.bottom;e++)for(let t=r.left;t<=r.right;t++){const r=this.getters.getCell(a,t,e);if((null==r?void 0:r.evaluated.type)===ke.number){const a=ps(r.evaluated.value,i,n);let h;h=2===c.length&&o?a<=o?this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(a,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(a,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(s=l[t])||void 0===s?void 0:s[e])||{},l[t][e].fillColor="#"+jt(h)}}}computeColorDiffUnits(e,t,s,i){const o=t-e;return[((s>>16)%256-(i>>16)%256)/o,((s>>8)%256-(i>>8)%256)/o,(s%256-i%256)/o]}colorCell(e,t,s,i){const[o,n,r]=i;return Math.round((s>>16)%256-o*(e-t))<<16|Math.round((s>>8)%256-n*(e-t))<<8|Math.round(s%256-r*(e-t))}adaptRules(e,t,s,i){if(0===s.length&&0===i.length)return;const o=this.getters.getConditionalFormats(e),n=o.findIndex((e=>e.id===t.id));let r=[];n>-1&&(r=o[n].ranges),r=r.concat(s);const a=zs(r,i);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},target:a.map(ks),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,s){const i=is(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let n of o.ranges)if(Hs(e.col,e.row,ks(n))){const n=o,r=[];if("CUT"===s&&r.push(is(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,n,[i],r);else{this.adaptRules(e.sheetId,n,[],r);const s=this.getCFToCopyTo(t.sheetId,n);this.adaptRules(t.sheetId,s,[i],[])}}}getCFToCopyTo(e,t){const s=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&Ms(e.rule,t.rule)));return s||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}kh.getters=["getConditionalStyle","getConditionalIcon"],kh.modes=["normal"];var Fh;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(Fh||(Fh={}));class $h extends bh{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1},this.toSearch=""}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(Fh.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(Fh.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith,e.replaceOptions);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith,e.replaceOptions);break;case"ACTIVATE_SHEET":case"REFRESH_SEARCH":this.refreshSearch()}}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(Fh.current)}updateRegex(){let e=hs(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),s=[];if(this.toSearch)for(const e of Object.values(t))if(e&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas&&e.isFormula()?e.content:String(e.evaluated.value))){const t=this.getters.getCellPosition(e.id),i={col:t.col,row:t.row,selected:!1};s.push(i)}return s.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let s;s=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,s=(s%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===s||(this.selectedMatchIndex=s,this.dispatch("SELECT_CELL",{col:t[s].col,row:t[s].row}));for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.replaceOptions={modifyFormulas:!1}}replace(e,t){if(this.replaceOptions=t,null===this.selectedMatchIndex||!this.currentSearchRegex)return;const s=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),o=this.getters.getCell(i,s.col,s.row),n=this.toReplace(o,i);if(o&&n){const t=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),i=n.toString().replace(t,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:s.col,row:s.row,content:i}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell(Fh.current)}else this.selectNextCell(Fh.next)}replaceAll(e,t){const s=this.searchMatches.length;for(let i=0;i<s;i++)this.replace(e,t)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.replaceOptions.modifyFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t,viewport:s}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge(i,e.col,e.row),n=o?o.left:e.col,r=o?o.right:e.col,a=o?o.top:e.row,l=o?o.bottom:e.row,[c,h,d,u]=this.getters.getRect({top:a,left:n,right:r,bottom:l},s);d>0&&u>0&&(t.fillStyle="#8B008B33",t.fillRect(c,h,d,u),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(c,h,d,u)))}}}$h.layers=[3],$h.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Dh extends bh{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,s){const i=this.searchNumberFormat(e,t);if(void 0!==i){const o=this.changeDecimalFormat(i,s);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var s;for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let o=i.left;o<=i.right;o++){const i=this.getters.getCell(e,o,t);if((null==i?void 0:i.evaluated.type)===ke.number&&!(null===(s=i.format)||void 0===s?void 0:s.match(M)))return i.format||this.setDefaultNumberFormat(i.evaluated.value)}}setDefaultNumberFormat(e){const t=e.toString().split(".");return 1===t.length?"0":"0."+Array(t[1].length+1).join("0")}changeDecimalFormat(e,t){const s=Math.sign(t),i=e.split(";");let o=[];for(let e of i){const t=e.indexOf("."),i=e.toUpperCase().indexOf("E");let n;const r=i>-1?e.slice(0,i):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?s>0?n=a<ne?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(n=e.slice(0,l)+e.slice(l+1),1===a&&(n=n.slice(0,t)+n.slice(t+1))):n=e:n=e,o.push(n)}return o.join(";")}}Dh.modes=["normal"];class Uh extends bh{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){if(0===e.length)return[];const t=this.getters.getActiveSheetId(),s=[];for(let[i,o]of e){const{xc:e,sheetName:n}=es(i),r=n?this.getters.getSheetIdByName(n):t;if(r){let i=ks(e);const{height:n,width:a}=Ws(i);i=n*a==1?this.getters.expandZone(t,ks(e)):i,s.push({zone:i,color:o,sheet:r})}}return s.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getSheet(e.sheet).rows.length&&e.zone.right<this.getters.getSheet(e.sheet).cols.length))}drawGrid(e){const{ctx:t,viewport:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;for(let e of this.getHighlights().filter(((e,t)=>this.getHighlights().findIndex((t=>Bs(t.zone,e.zone)&&t.sheet===o))===t))){const[i,o,r,a]=this.getters.getRect(e.zone,s);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,r-n,a-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,r-2*n,a-2*n))}}}function Ph(e,t){return e.isFormula()&&t?"left":e.defaultAlign}function Bh(e,t){let s=0,i=e.length-1;for(;s<=i;){const o=Math.floor((s+i)/2),n=e[o];if(t<n.start)i=o-1;else if(t>n.end)s=o+1;else{if(!n.isHidden)return o;s+=1}}return-1}Uh.modes=["normal"],Uh.layers=[1],Uh.getters=["getHighlights"];class Vh extends bh{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t,s){if(e<m)return-1;const i=(s||this.getters.getActiveSheet()).cols;return Bh(i,e-m+i[t].start+1)}getRowIndex(e,t,s){if(e<f)return-1;const i=(s||this.getters.getActiveSheet()).rows;return Bh(i,e-f+i[t].start+1)}getRect(e,t){const{left:s,top:i,right:o,bottom:n}=e;let{offsetY:r,offsetX:a}=t;a-=m,r-=f;const{cols:l,rows:c}=this.getters.getActiveSheet(),h=Math.max(l[s].start-a,m),d=l[o].end-a-h,u=Math.max(c[i].start-r,f);return[h,u,d,c[n].end-r-u]}isVisibleInViewport(e,t,s){const{right:i,left:o,top:n,bottom:r}=s;return t<=r&&t>=n&&e>=o&&e<=i}getEdgeScrollCol(e){let t=!1,s=0,i=0;const{width:o}=this.getters.getViewportDimension(),{width:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{left:r,offsetX:a}=this.getters.getActiveSnappedViewport();return e<m&&r>0?(t=!0,s=-1,i=as(m-e)):e>o&&a<n-o&&(t=!0,s=1,i=as(e-o)),{canEdgeScroll:t,direction:s,delay:i}}getEdgeScrollRow(e){let t=!1,s=0,i=0;const{height:o}=this.getters.getViewportDimension(),{height:n}=this.getters.getGridDimension(this.getters.getActiveSheet()),{top:r,offsetY:a}=this.getters.getActiveSnappedViewport();return e<f&&r>0?(t=!0,s=-1,i=as(f-e)):e>o&&a<n-o&&(t=!0,s=1,i=as(e-o)),{canEdgeScroll:t,direction:s,delay:i}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e);break;case 7:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,top:r,left:a,bottom:l,right:c}=s;const{width:h,height:d}=this.getters.getViewportDimension(),{cols:u,rows:p,id:g}=this.getters.getActiveSheet();if(t.fillStyle="white",t.fillRect(0,0,h,d),o-=m,n-=f,!this.getters.getGridLinesVisibility(g))return;t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();const v=Math.min(d,p[l].end-n);for(let e=a;e<=c;e++){if(u[e].isHidden)continue;const s=u[e].end-o;t.moveTo(s,0),t.lineTo(s,v)}const E=Math.min(h,u[c].end-o);for(let e=r;e<=l;e++){if(p[e].isHidden)continue;const s=p[e].end-n;t.moveTo(0,s),t.lineTo(E,s)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:s}=e;t.lineWidth=.3*s;const i=.1*s;t.strokeStyle="#111";const o=this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());for(let e of this.boxes){let s=e.style;s&&s.fillColor&&"#ffffff"!==s.fillColor&&(t.fillStyle=s.fillColor,t.fillRect(e.x,e.y,e.width,e.height),o&&t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawBorders(e){const{ctx:t,thinLineWidth:s}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:s,y:o,width:n,height:r}=e;t.left&&i(t.left,s,o,s,o+r),t.top&&i(t.top,s,o,s+n,o),t.right&&i(t.right,s+n,o,s+n,o+r),t.bottom&&i(t.bottom,s,o+r,s+n,o+r)}}function i([e,i],o,n,r,a){t.strokeStyle=i,t.lineWidth=("thin"===e?2:3)*s,t.beginPath(),t.moveTo(o,n),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:s}=e;let i;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const o=e.style||{},n=e.align,r=o.italic?"italic ":"",a=o.bold?"bold":T,l=o.fontSize||x,c=cs[l],h=`${r}${a} ${c}px ${R}`;let d;h!==i&&(i=h,t.font=h),t.fillStyle=o.textColor||"#000";let u=e.y+e.height/2+1;d="left"===n?e.x+(e.image?e.image.size+2*I:4):"right"===n?e.x+e.width-4:e.x+e.width/2,t.textAlign=n,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(d),Math.round(u)),(o.strikethrough||o.underline)&&("right"===n?d-=e.textWidth:"center"===n&&(d-=e.textWidth/2),o.strikethrough&&t.fillRect(d,u,e.textWidth,2.6*s),o.underline&&(u=e.y+e.height/2+1+c/2,t.fillRect(d,u,e.textWidth,1.3*s))),e.clipRect&&t.restore()}}async drawIcon(e){const{ctx:t}=e;for(let e of this.boxes)if(e.image){let s=e.x,i=e.y;const o=e.image.image,n=e.image.size,r=(e.height-n)/2;e.image.clipIcon&&(t.save(),t.beginPath(),t.rect(...e.image.clipIcon),t.clip()),t.drawImage(o,s+I,i+r,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:s,thinLineWidth:i}=e;let{offsetX:o,offsetY:n,left:r,top:a,right:l,bottom:p}=s;const{width:g,height:v}=this.getters.getViewportDimension();o-=m,n-=f;const E=this.getters.getSelectedZones(),{cols:S,rows:b}=this.getters.getActiveSheet(),C=this.getters.getActiveCols(),I=this.getters.getActiveRows();t.fillStyle=c,t.font=`400 11px ${R}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333",t.fillRect(0,0,g,f),t.fillRect(0,0,m,v),t.fillStyle=h;for(let e of E){const s=Math.max(m,S[e.left].start-o),i=Math.max(m,S[e.right].end-o),r=Math.max(f,b[e.top].start-n),a=Math.max(f,b[e.bottom].end-n);t.fillStyle=C.has(e.left)?d:h,t.fillRect(s,0,i-s,f),t.fillStyle=I.has(e.top)?d:h,t.fillRect(0,r,m,a-r)}t.beginPath(),t.moveTo(m,0),t.lineTo(m,v),t.moveTo(0,f),t.lineTo(g,f),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=r;e<=l;e++){const s=S[e];s.isHidden||(t.fillStyle=C.has(e)?"#fff":u,t.fillText(s.name,(s.start+s.end)/2-o,13),t.moveTo(s.end-o,0),t.lineTo(s.end-o,f))}for(let e=a;e<=p;e++){const s=b[e];s.isHidden||(t.fillStyle=I.has(e)?"#fff":u,t.fillText(s.name,24,(s.start+s.end)/2-n),t.moveTo(0,s.end-n),t.lineTo(m,s.end-n))}t.stroke()}hasContent(e,t){const s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);return i&&!i.isEmpty()||this.getters.isInMerge(s,e,t)}getGridBoxes(e){const{viewport:t}=e;let{right:s,left:i,top:o,bottom:n,offsetX:r,offsetY:a}=t;r-=m,a-=f;const l=this.getters.shouldShowFormulas(),c=[],{cols:h,rows:d,id:u}=this.getters.getActiveSheet();for(let e=o;e<=n;e++){const t=d[e];if(!t.isHidden)for(let o=i;o<=s;o++){const n=h[o];if(n.isHidden)continue;let d=t.cells[o];const p=this.getters.getCellBorder(u,o,e),g=this.getters.getConditionalStyle(o,e),f=this.getters.getConditionalIcon(o,e);if(!this.getters.isInMerge(u,o,e))if(d){const u=this.getters.getCellText(d,l);let m=this.getters.getCellStyle(d);g&&(m=Object.assign({},m,g));let v=u?m&&m.align||Ph(d,l):void 0,E=null,S=null;const b=this.getters.getTextWidth(d),C=m.fontSize||x,y=cs[C],w=f?y+2*I:0,T=w+b>h[o].size||cs[C]>t.size;if(T&&d.evaluated.type===ke.number&&(v="center"!==v?"left":v),f){const e=n.end-n.start;E=[n.start-r+w,t.start-a,Math.max(0,e-w),t.size],S=[n.start-r,t.start-a,Math.min(w,e),t.size]}else if(T){let l,c;switch(v){case"left":for(l=o;l<s&&!this.hasContent(l+1,e);)l++;c=h[l].end-n.start,(c<b||cs[C]>t.size)&&(E=[n.start-r,t.start-a,c,t.size]);break;case"right":for(l=o;l>i&&!this.hasContent(l-1,e);)l--;c=n.end-h[l].start,(c<b||cs[C]>t.size)&&(E=[h[l].start-r,t.start-a,c,t.size]);break;case"center":let d=o;for(;d>i&&!this.hasContent(d-1,e);)d--;let u=o;for(;u<s&&!this.hasContent(u+1,e);)u++;const p=Math.min(d,o),g=Math.max(u,o);c=h[g].end-h[p].start,(c<b||p===o||g===o||cs[C]>t.size)&&(E=[h[p].start-r,t.start-a,c,t.size])}}c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:u,textWidth:b,border:p,style:m,align:v,clipRect:E,error:d.evaluated.type===ke.error?d.evaluated.error:void 0,image:f?{type:"icon",size:y,clipIcon:S,image:zl[f].img}:void 0})}else c.push({x:n.start-r,y:t.start-a,width:n.size,height:t.size,text:"",textWidth:0,border:p,style:g||null,align:void 0,clipRect:null,error:void 0})}}const p=this.getters.getActiveSheetId();for(let e of this.getters.getMerges(p))if(!this.getters.isMergeHidden(p,e)&&Vs(e,t)){const t=this.getters.getCell(p,e.left,e.top),s=this.getters.getCellBorder(p,e.left,e.top),i=this.getters.getCellBorder(p,e.right,e.bottom),o=h[e.right].end-h[e.left].start;let n,u,g,f,m;if(g=t?this.getters.getCellStyle(t):null,t||i||s){n=t?this.getters.getCellText(t,l):"",u=t?this.getters.getTextWidth(t):null;const o=this.getters.getConditionalStyle(e.topLeft.col,e.topLeft.row);o&&(g=Object.assign({},g,o)),f=n?g&&g.align||Ph(t,l):null,m={bottom:i?i.bottom:null,left:s?s.left:null,right:i?i.right:null,top:s?s.top:null}}g=g||{},g.fillColor&&"#ffffff"!==g.fillColor||(g=Object.create(g),g.fillColor="#fff");const v=h[e.left].start-r,E=d[e.top].start-a,S=d[e.bottom].end-d[e.top].start,b=this.getters.getConditionalIcon(e.left,e.top),C=g.fontSize||x,y=cs[C],w=b?2*I+y:0,T=w+u;f=n&&(null==t?void 0:t.evaluated.type)===ke.number&&T>o&&"center"!==f?"left":f;const R=b?[v+w,E,Math.max(0,o-w),S]:[v,E,o,S],L=b?[v,E,Math.min(w,o),S]:null;c.push({x:v,y:E,width:o,height:S,text:n,textWidth:u,border:m,style:g,align:f,clipRect:R,error:t&&t.evaluated.type===ke.error?t.evaluated.error:void 0,image:b?{type:"icon",clipIcon:L,size:y,image:zl[b].img}:void 0})}return c}}Vh.layers=[0,7],Vh.getters=["getColIndex","getRowIndex","getRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow"],Vh.modes=["normal"];const Hh=new oi;class zh extends bh{constructor(){super(...arguments),this.inputs={},this.activeSheets={},this.inputHasSingleRange={},this.focusedInputId=null,this.focusedRange=null,this.willAddNewRange=!1}allowDispatch(e){switch(e.type){case"FOCUS_RANGE":const t=this.getIndex(e.id,e.rangeId);if(this.focusedInputId===e.id&&this.focusedRange===t)return 24;break;case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange[e.id]&&1===this.inputs[e.id].length)return 25}return 0}handle(e){switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id],delete this.activeSheets[e.id],delete this.inputHasSingleRange[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(e.id,this.getIndex(e.id,e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.id,e.rangeId);if(null!==t){const s=e.id;this.focusedInputId===s&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:s,rangeId:this.inputs[s][t].id});const i=e.value.split(",").map((e=>e.trim()));this.setRange(s,t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(e.id,this.inputs[e.id].length,[""]),this.focusLast(e.id);break;case"REMOVE_RANGE":const t=this.getIndex(e.id,e.rangeId);null!==t&&this.removeRange(e.id,t);break;case"SELECT_CELL":case"SET_SELECTION":if(!this.focusedInputId)break;const s=this.getSelectionInputValue(this.focusedInputId),i=(this.inputHasSingleRange[this.focusedInputId]?[this.getters.getSelectedZone()]:this.getters.getSelectedZones()).map($s).filter((e=>!s.includes(e))),o=this.activeSheets[this.focusedInputId],n=this.getters.getActiveSheetId(),r=this.getters.getSheetName(n);this.add(i.map((e=>n===o?e:`${us(r)}!${e}`)));break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInputId,this.focusedRange];null===e||null===t||this.inputHasSingleRange[e]||(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,s)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.focusedRange&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.focusedRange===s}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:s}=es(e);return null!==t.match(Jt)&&(!s||void 0!==this.getters.getSheetIdByName(s))}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].map((e=>this.inputToHighlights(this.focusedInputId,e))).flat():[]}initInput(e,t,s=!1){this.inputs[e]=[],this.insertNewRange(e,0,t),this.activeSheets[e]=this.getters.getActiveSheetId(),this.inputHasSingleRange[e]=s,0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){this.focusedInputId=e,this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}unfocus(){this.focusedInputId=null,this.focusedRange=null}add(e){if(null===this.focusedInputId||null===this.focusedRange||this.getters.isSelectingForComposer()||0===e.length)return;if(this.getters.getSelectionMode()===Th.expanding&&this.willAddNewRange){const t=this.focusedInputId;this.insertNewRange(t,this.inputs[t].length,e),this.focusLast(this.focusedInputId),this.willAddNewRange=!1}else this.setRange(this.focusedInputId,this.focusedRange,e)}setContent(e,t,s){this.inputs[e][t]={...this.inputs[e][t],id:Hh.uuidv4(),xc:s}}insertNewRange(e,t,s){this.inputs[e].splice(t,0,...s.map(((t,s)=>({xc:t,id:(this.inputs[e].length+s+1).toString(),color:Xt()}))))}setRange(e,t,s){const[,...i]=s;this.setContent(e,t,s[0]),this.insertNewRange(e,t+1,i),i.length&&this.focus(e,t+i.length)}removeRange(e,t){this.inputs[e].splice(t,1),this.focusedInputId===e&&null!==this.focusedRange&&this.focusLast(e)}inputToHighlights(e,{xc:t,color:s}){const i=this.cleanInputs([t]).filter((e=>this.isRangeValid(e))).filter((t=>this.shouldBeHighlighted(this.activeSheets[e],t)));if(0===i.length)return[];const[o,...n]=i,r=[[o,s||Xt()]];for(const e of n)r.push([e,Xt()]);return r}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:s}=es(t),i=this.getters.getSheetIdByName(s),o=this.getters.getActiveSheet().id;return this.isRangeValid(t)&&(i===o||void 0===i&&o===e)}getIndex(e,t){const s=this.inputs[e].findIndex((e=>e.id===t));return s>=0?s:null}}zh.modes=["normal"],zh.layers=[1],zh.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Zh{constructor(){this.bus=new i.core.EventBus}on(e,t,s){this.bus.on(e,t,s)}trigger(e,t){this.bus.trigger(e,t)}off(e,t){this.bus.off(e,t)}clear(){this.bus.clear()}}function Gh(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?function(e,t,s){const i="left"===t?"right":"bottom";let o=e[t],n=e[i];for(let r of s.sort(((e,t)=>t-e)))e[t]>r&&(o--,n--),e[t]<=r&&e[i]>=r&&n--;if(!(o>n))return{...e,[t]:o,[i]:n}}(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?function(e,t,s,i,o){const n="left"===t?"columns":"rows",r="before"===i?s-1:s,a="left"===t?"right":"bottom",l="before"===i?e[a]>r:e[a]>=r;return e[t]<=r&&l?Ys(e,n,"RESIZE",o):r<e[t]?Ys(e,n,"MOVE",o):{...e}}(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function Wh(e,t){const s=e.definition;let i,o;return s.labelRange&&(i=Gh(ks(s.labelRange),t)),s.dataSets&&(o=s.dataSets.map(ks).map((e=>Gh(e,t))).filter(Ls).map($s)),{...e,definition:{...s,dataSets:o,labelRange:i?$s(i):void 0}}}fl.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Wh),fl.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Wh),fl.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),fl.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var s;if(e.name===t.name)return{...e,name:(null===(s=e.name)||void 0===s?void 0:s.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),fl.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const s=[];for(const i of e.target)for(const e of t.target)Vs(i,e)||s.push({...i});if(s.length)return{...e,target:s};return}));const qh=[{match:function(e){return"sheetId"in e},fn:function(e,t){const s="DELETE_SHEET"===t.type&&t.sheetId;if(e.sheetId===s)return"IGNORE_COMMAND";if("CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId)return e;return"SKIP_TRANSFORMATION"}},{match:function(e){return"target"in e},fn:function(e,t){const s=[];for(const i of e.target){const e=Gh(i,t);e&&s.push(e)}if(!s.length)return"IGNORE_COMMAND";return{...e,target:s}}},{match:function(e){return"col"in e&&"row"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const s="COL"===t.dimension?"col":"row";let i=e[s];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(i))return"IGNORE_COMMAND";for(let t of e)i>=t&&i--}"ADD_COLUMNS_ROWS"===t.type&&(i>t.base||i===t.base&&"before"===t.position)&&(i+=t.quantity);return{...e,[s]:i}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const s of t.target){if(!(e.col===s.left&&e.row===s.top)&&Hs(e.col,e.row,s))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e},fn:function(e,t){if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const s="ADD_COLUMNS_ROWS"===e.type,i=s?"base":"elements";let o=s?[e[i]]:e[i];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const s=t.elements.sort(((e,t)=>t-e));for(let t of s)e>t&&e--;return e})).filter(Ls)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((s=>s>e?s+t.quantity:s))}if(o.length){let t=o;return s&&(t=o[0]),{...e,[i]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}}];function jh(e,t){const s=fl.getTransformation(e.type,t.type);return s?s(e,t):function(e,t){for(const{match:s,fn:i}of qh)if(s(e)){const s=i(e,t);if("SKIP_TRANSFORMATION"===s)continue;if("IGNORE_COMMAND"===s)return;return s}return e}(e,t)}function Yh(e,t){let s=[...e];for(const e of t)s=s.map((t=>jh(t,e))).filter(Ls);return s}class Xh{constructor(e,t,s,i){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...s],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Kh extends Error{}class Qh extends Zh{constructor(e,t,s=O){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=s,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new oi,this.debouncedMove=i.utils.debounce(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const s=new Xh(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(s.id,s),this.trigger("new-local-state-update",{id:s.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:s.id,clientId:s.clientId,commands:s.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new Kh("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Ls))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const s=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==s?void 0:s.col)===e.col&&s.row===e.row&&s.sheetId===e.sheetId)return;const i=s?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:i,version:1,client:{...o,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:s}=e,i=new Xh(e.nextRevisionId,t,s);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:Yh(s,t)})}break;case"SNAPSHOT_CREATED":{const t=new Xh(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||(this.waitingAck=!0,this.sendPendingMessage())}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){const t=this.revisions.get(e.nextRevisionId);if(0===t.commands.length){this.revisions.drop(t.id);const e=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.nextRevisionId));return this.trigger("pending-revisions-dropped",{revisionIds:e}),this.waitingAck=!1,this.waitingUndoRedoAck=!1,void(this.pendingMessages=[])}e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage()}}isAlreadyProcessed(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const Jh=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class ed extends bh{constructor(){super(...arguments),this.availableColors=new Set(Jh),this.colors={}}isPositionValid(e){const t=this.getters.getSheet(e.sheetId);return e.row<t.rows.length&&e.col<t.cols.length}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(Jh));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof Kh)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const s of this.getters.getConnectedClients())if(s.id!==this.getters.getClient().id&&s.position&&s.position.sheetId===e&&this.isPositionValid(s.position)){const e=s.position;this.colors[s.id]||(this.colors[s.id]=this.chooseNewColor());const i=this.colors[s.id];t.push({...s,position:e,color:i})}return t}drawGrid(e){const{viewport:t,ctx:s,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:r}=e.position,a=this.getters.expandZone(o,{top:n,bottom:n,left:r,right:r}),[l,c,h,d]=this.getters.getRect(a,t);if(h<=0||d<=0)continue;const u=e.color,p=`${u}10`;s.fillStyle=p,s.lineWidth=4*i,s.strokeStyle=u,s.globalCompositeOperation="multiply",s.fillRect(l,c,h,d),s.globalCompositeOperation="source-over",s.strokeRect(l,c,h,d),s.font=`bold ${x+1}px ${R}`}}}ed.getters=["getClientsToDisplay"],ed.layers=[5],ed.modes=["normal"];class td extends bh{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Hs(e.anchor[0],e.anchor[1],e.zone))throw new Error(a("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)e.interactive?this.interactiveSortSelection(e.sheetId,e.anchor,e.zone,e.sortDirection):this.sortZone(e.sheetId,e.anchor,e.zone,e.sortDirection)}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let s=t.top;s<=t.bottom;s++)for(let i=t.left;i<=t.right;i++)if(!this.getters.isInMerge(e,i,s))return 48;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const s=this.getters.getMerges(e).filter((e=>Vs(e,t))),i=Ws(s[0]);let[o,n]=[i.width,i.height];return s.every((e=>{let[t,s]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&s===n}))?0:48}interactiveSortSelection(e,t,s,i){let o=Pe.Success,n=s.right>s.left;if(this.getters.doesIntersectMerge(e,s)){let t;n=!1;for(let i=s.top;i<=s.bottom;i++){t=[];for(let o=s.left;o<=s.right;o++){let s=this.getters.getMerge(e,o,i);s&&!t.includes(s.id.toString())&&t.push(s.id.toString())}if(t.length>=2){n=!0;break}}}if(n)o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i});else{const n=this.getContiguousZone(e,s);Bs(n,s)?o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i}):this.ui.askConfirmation(a("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>{s=n,o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}),(()=>{o=this.dispatch("SORT_CELLS",{sheetId:e,anchor:t,zone:s,sortDirection:i})}))}o.isCancelledBecause(48)&&(this.dispatch("SET_SELECTION",{anchor:t,zones:[s],anchorZone:s}),this.ui.notifyUser(a("Cannot sort. To sort, select only cells or only merges that have the same size.")))}expand(e,t){const{left:s,right:i,top:o,bottom:n}=this.getters.expandZone(e.id,t);return{left:Math.max(0,s),right:Math.min(e.cols.length-1,i),top:Math.max(0,o),bottom:Math.min(e.rows.length-1,n)}}checkExpandedValues(e,t){const s=this.expand(e,t),i=e.id;let o,n=[];if(this.getters.doesIntersectMerge(i,s)){const{left:e,right:t,top:r,bottom:a}=s;for(let s=e;s<=t;s++)for(let e=r;e<=a;e++){const[t,r]=this.getters.getMainCell(i,s,e);o=this.getters.getCell(i,t,r),n.push((null==o?void 0:o.formattedValue)||"")}}else{const t=Gs(s,e,(e=>e.formattedValue),"");n=t.flat()}return n.some((e=>""!==e))}getContiguousZone(e,t){let s,{top:i,bottom:o,left:n,right:r}=t;const a=this.getters.getSheet(e);let l=!1;for(;!l;)l=!0,i>0&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:i-1,bottom:i-1}),s&&(l=!1,i--)),n>0&&(s=this.checkExpandedValues(a,{left:n-1,right:n-1,top:i-1,bottom:o+1}),s&&(l=!1,n--)),r<a.cols.length-1&&(s=this.checkExpandedValues(a,{left:r+1,right:r+1,top:i-1,bottom:o+1}),s&&(l=!1,r++)),o<a.rows.length-1&&(s=this.checkExpandedValues(a,{left:n-1,right:r+1,top:o+1,bottom:o+1}),s&&(l=!1,o++));return{left:n,right:r,top:i,bottom:o}}hasHeader(e,t,s,i){const{left:o,right:n,top:r,bottom:a}=t;if(a-r+1==1)return!1;let l=Gs({left:o,right:n,top:r,bottom:r+2*i-1},e,(e=>e.evaluated.type),ke.empty,s,i);return l[0][0]===ke.empty&&(l=l.slice(1)),!l.some((e=>e[0]===ke.empty))&&!!l.some((e=>e[1]!==ke.empty&&e[0]!==e[1]))}sortCellsList(e,t){const s=e.map(((e,t)=>({index:t,val:e}))),i=s.filter((e=>!(null==e.val||""===e.val.evaluated.value))),o=s.filter((e=>null==e.val||""===e.val.evaluated.value)),n="descending"===t?-1:1,r=[ke.number,ke.error,ke.text,ke.boolean];return i.map((e=>{return{index:e.index,val:(t=e.val,{type:t.evaluated.type,value:t.evaluated.value})};var t})).sort(((e,t)=>{let s=r.indexOf(e.val.type)-r.indexOf(t.val.type);return 0===s&&(s=e.val.type===ke.text||e.val.type===ke.error?e.val.value.localeCompare(t.val.value):e.val.value-t.val.value),n*s})).concat(o)}sortZone(e,t,s,i){let o=1,n=1,r=t[0],a=Object.assign({},s);if(this.getters.doesIntersectMerge(e,a)){const[s,i]=t,a=this.getters.getMerge(e,s,i);o=a.right-a.left+1,n=a.bottom-a.top+1,r=a.topLeft.col}const l=this.getters.getSheet(e);this.hasHeader(l,a,o,n)&&(a.top+=n);const c=Gs(a,l,(e=>e),void 0,o,n),h=c[r-a.left],d=this.sortCellsList(h,i).map((e=>e.index)),[u,p]=[c.length,c[0].length];for(let t=0;t<u;t++)for(let s=0;s<p;s++){let i=c[t][d[s]],r=a.left+t*o,l=a.top+s*n,h={sheetId:e,col:r,row:l,content:"",value:""};if(i){let t=i.content;if(i.isFormula()){const s=l-this.getters.getCellPosition(i.id).row,o=this.getters.createAdaptedRanges(i.dependencies.references,0,s,e);t=this.getters.buildFormulaContent(e,i.normalizedText,{...i.dependencies,references:o})}h.style=i.style,h.content=t,h.format=i.format,h.value=i.evaluated.value}this.dispatch("UPDATE_CELL",h)}}}td.getters=["getContiguousZone"];class sd extends bh{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}sd.modes=["normal"],sd.getters=["shouldShowFormulas"];class id extends bh{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":case"DELETE_SHEET_CONFIRMATION":try{this.getters.getSheet(e.sheetId);break}catch(e){return 23}}return 0}handle(e){switch(e.type){case"RENAME_SHEET":e.interactive&&this.interactiveRenameSheet(e.sheetId,a("Rename Sheet"));break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheetId);break;case"ADD_MERGE":e.interactive&&this.interactiveMerge(e.sheetId,e.target);break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const s=this.getColMaxWidth(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:s+6,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const s=this.getRowMaxHeight(e.sheetId,t);0!==s&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:s+6,sheetId:e.sheetId})}}}getCellWidth(e){let t=this.getTextWidth(e);const s=this.getters.getCellPosition(e.id);return this.getters.getConditionalIcon(s.col,s.row)&&(t+=function(e,t){const s=t.fontSize||x;return cs[s]+2*I}(this.ctx,this.getters.getCellStyle(e))),t}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas());return gs(this.ctx,t,this.getters.getCellStyle(e))}getCellHeight(e){const t=this.getters.getCellStyle(e).fontSize||x;return cs[t]}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===ke.error)?e.content:e.formattedValue}getColMaxWidth(e,t){const s=this.getters.getColCells(e,t).map((e=>this.getCellWidth(e)));return Math.max(0,_s(s))}getRowMaxHeight(e,t){const s=this.getters.getSheet(e),i=Object.values(s.rows[t].cells).map((e=>this.getCellHeight(e)));return Math.max(0,_s(i))}interactiveRenameSheet(e,t){const s=this.getters.getSheetName(e);this.ui.editText(t,s,(t=>{if(!t)return;const s=this.dispatch("RENAME_SHEET",{sheetId:e,name:t}),i=this.getters.getSheetName(e);s.isSuccessful||i===t||this.interactiveRenameSheet(e,a("Please enter a valid sheet name"))}))}interactiveDeleteSheet(e){this.ui.askConfirmation(a("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheetId:e})}))}interactiveMerge(e,t){const s=this.dispatch("ADD_MERGE",{sheetId:e,target:t});s.isSuccessful||s.isCancelledBecause(3)&&this.ui.askConfirmation(a("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheetId:e,target:t,force:!0})}))}}id.getters=["getCellWidth","getCellHeight","getTextWidth","getCellText"];class od extends bh{constructor(){super(...arguments),this.viewports={},this.snappedViewports={},this.updateSnap=!1,this.clientWidth=1e3,this.clientHeight=1e3}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkOffsetValidity(e.offsetX,e.offsetY);case"RESIZE_VIEWPORT":return e.width<0||e.height<0?54:0;default:return 0}}handle(e){switch(e.type){case"UNDO":case"REDO":this.cleanViewports(),this.resetViewports();break;case"RESIZE_VIEWPORT":this.cleanViewports(),this.resizeViewport(e.height,e.width);break;case"SET_VIEWPORT_OFFSET":this.setViewportOffset(e.offsetX,e.offsetY);break;case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportOffsetX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportOffsetY(e.sheetId,this.getViewport(e.sheetId));break;case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":"COL"===e.dimension?this.adjustViewportZoneX(e.sheetId,this.getViewport(e.sheetId)):this.adjustViewportZoneY(e.sheetId,this.getViewport(e.sheetId));break;case"ACTIVATE_SHEET":this.refreshViewport(e.sheetIdTo);break;case"SELECT_CELL":case"MOVE_POSITION":this.refreshViewport(this.getters.getActiveSheetId())}}finalize(){this.updateSnap&&(this.snapViewportToCell(this.getters.getActiveSheetId()),this.updateSnap=!1)}getViewportDimension(){return{width:this.clientWidth,height:this.clientHeight}}getActiveViewport(){const e=this.getters.getActiveSheetId();return this.getViewport(e)}getActiveSnappedViewport(){const e=this.getters.getActiveSheetId();return this.getSnappedViewport(e)}getGridDimension(e){const t=ai(e,"cols"),s=this.clientWidth-m,i=ai(e,"rows"),o=this.clientHeight-f,n=e.cols.find((e=>e.end>t.end-s))||e.cols[e.cols.length-1],r=e.rows.find((e=>e.end>i.end-o))||e.rows[e.rows.length-1];return{width:t.end+Math.max(E,Math.min(n.size,s-t.size)),height:i.end+Math.max(S+5,Math.min(r.size,o-i.size))}}getMaximumViewportOffset(e){const{width:t,height:s}=this.getters.getGridDimension(e);return{maxOffsetX:Math.max(0,t-this.clientWidth+m+1),maxOffsetY:Math.max(0,s-this.clientHeight+f+1)}}checkOffsetValidity(e,t){const s=this.getters.getActiveSheet(),{maxOffsetX:i,maxOffsetY:o}=this.getMaximumViewportOffset(s);return e<0||t<0||t>o||e>i?53:0}getSnappedViewport(e){return this.snapViewportToCell(e),this.snappedViewports[e]}getViewport(e){return this.viewports[e]?this.viewports[e]:this.generateViewportState(e)}cleanViewports(){const e=this.getters.getVisibleSheets();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetViewports(){for(let[e,t]of Object.entries(this.viewports))this.adjustViewportOffsetX(e,t),this.adjustViewportOffsetY(e,t),this.adjustViewportsPosition(e)}adjustViewportOffsetX(e,t){const{offsetX:s}=t,{width:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientWidth-m+s>i){const e=this.clientWidth-m+s-i;t.offsetX=Math.max(0,s-e)}this.adjustViewportZoneX(e,t)}adjustViewportOffsetY(e,t){const{offsetY:s}=t,{height:i}=this.getGridDimension(this.getters.getSheet(e));if(this.clientHeight-f+s>i){const e=this.clientHeight-f+s-i;t.offsetY=Math.max(0,s-e)}this.adjustViewportZoneY(e,t)}resizeViewport(e,t){this.clientHeight=e,this.clientWidth=t,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.adjustViewportOffsetX(e,this.viewports[e]),this.adjustViewportOffsetY(e,this.viewports[e])}setViewportOffset(e,t){const s=this.getters.getActiveSheetId();this.getActiveViewport(),this.viewports[s].offsetX=e,this.viewports[s].offsetY=t,this.adjustViewportZone(s,this.viewports[s])}generateViewportState(e){return this.viewports[e]={left:0,right:0,top:0,bottom:0,offsetX:0,offsetY:0},this.viewports[e]}refreshViewport(e){const t=this.getViewport(e);this.adjustViewportZone(e,t),this.adjustViewportsPosition(e)}adjustViewportZone(e,t){this.adjustViewportZoneX(e,t),this.adjustViewportZoneY(e,t)}adjustViewportZoneX(e,t){const s=this.getters.getSheet(e),i=s.cols;t.left=this.getters.getColIndex(t.offsetX+m,0,s);const o=this.clientWidth+t.offsetX-m;t.right=i.length-1;for(let e=t.left;e<i.length;e++)if(o<i[e].end){t.right=e;break}this.updateSnap=!0}adjustViewportZoneY(e,t){const s=this.getters.getSheet(e),i=s.rows;t.top=this.getters.getRowIndex(t.offsetY+f,0,s);const o=this.clientHeight+t.offsetY-f;t.bottom=i.length-1;for(let e=t.top;e<i.length;e++)if(o<i[e].end){t.bottom=e;break}this.updateSnap=!0}adjustViewportsPosition(e,t){const s=this.getters.getSheet(e),{cols:i,rows:o}=s,n=this.getSnappedViewport(e);t=t||this.getters.getSheetPosition(e);const[r,a]=ni(s,...this.getters.getMainCell(e,t[0],t[1]));for(;i[r].end>n.offsetX+this.clientWidth-m&&n.offsetX<i[r].start;)n.offsetX=i[n.left].end,this.adjustViewportZoneX(e,n);for(;r<n.left;){const t=i.slice(0,n.left).reverse().findIndex((e=>!e.isHidden));n.offsetX=i[n.left-1-t].start,this.adjustViewportZoneX(e,n)}for(;o[a].end>n.offsetY+this.clientHeight-f&&n.offsetY<o[a].start;)n.offsetY=o[n.top].end,this.adjustViewportZoneY(e,n);for(;a<n.top;){const t=o.slice(0,n.top).reverse().findIndex((e=>!e.isHidden));n.offsetY=o[n.top-1-t].start,this.adjustViewportZoneY(e,n)}const{top:l,left:c}=this.viewports[e];l===n.top&&c===n.left||(this.viewports[e]=n),this.updateSnap=!1}snapViewportToCell(e){const{cols:t,rows:s}=this.getters.getSheet(e),i=this.getViewport(e),o=Object.assign({},i);this.adjustViewportOffsetX(e,o),this.adjustViewportOffsetY(e,o),o.offsetX=t[o.left].start,o.offsetY=s[o.top].start,this.adjustViewportZone(e,o),this.snappedViewports[e]=o}}od.getters=["getActiveViewport","getSnappedViewport","getActiveSnappedViewport","getViewportDimension","getGridDimension","getMaximumViewportOffset"],od.modes=["normal"];const nd=(new Le).add("sheet",Ra).add("cell",ba).add("merge",Ta).add("borders",va).add("conditional formatting",ya).add("figures",wa).add("chart",Ca),rd=(new Le).add("selection",xh).add("ui_sheet",id).add("ui_options",sd).add("evaluation",Mh).add("evaluation_cf",kh).add("evaluation_chart",Nh).add("clipboard",wh).add("edition",Lh).add("highlight",Uh).add("selectionInput",zh).add("viewport",od).add("grid renderer",Vh).add("autofill",Ih).add("find_and_replace",$h).add("sort",td).add("automatic_sum",yh).add("format",Dh).add("selection_multiuser",ed);class ad{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}class ld extends i.core.EventBus{constructor(){super(...arguments),this.registry=new Le}add(e,t){this.registry.add(e,t);const s=i.utils.debounce((()=>this.trigger("data-loaded",{id:e})),0);return t.on("data-loaded",this,(()=>s())),t.loadMetadata(),this}get(e){return this.registry.get(e)}getAll(){return this.registry.getAll()}remove(e){this.get(e).off("data-loaded",this),this.registry.remove(e)}async waitForReady(){const e=[];for(const t of this.getAll())e.push(t.get());return Promise.all(e)}}class cd extends i.core.EventBus{async loadMetadata(){this.metadataPromise||(this.metadataPromise=this._fetchMetadata().then((e=>(this.metadata=e,e)))),await this.metadataPromise}async get(e){return e&&e.forceFetch&&(this.data=void 0,this.dataPromise=void 0),await this.loadMetadata(),this.dataPromise||(this.dataPromise=this._fetch(e).then((e=>(this.data=e,this.lastUpdate=Date.now(),this.trigger("data-loaded"),e)))),this.dataPromise}getSync(){return this.data}getMetadataSync(){return this.metadata}getLastUpdate(){return this.lastUpdate}}function hd(e){return _a.get(e.type)(e)}function dd(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class ud{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const s of this.operations){if(s.id===e)return e;if(s.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const s=this.buildTransformation.with(e.data),{before:i,operation:o,after:n}=this.locateOperation(t);this.operations=[...i,o,e,...n.map((e=>e.transformed(s)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new ud(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:s}=this.locateOperation(e);this.operations=t.concat([s])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class pd{constructor(e,t){this.id=e,this.data=t}transformed(e){return new pd(this.id,e(this.data))}}class gd{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new gd(function*(e,t){for(const s of e)if(yield s,s.operation.id===t)return}(this.operations,e))}stopBefore(e){return new gd(function*(e,t){for(const s of e){if(s.operation.id===t)return;yield s}}(this.operations,e))}startAfter(e){return new gd(function*(e,t){let s=!0;for(const i of e)s||(yield i),i.operation.id===t&&(s=!1)}(this.operations,e))}}class fd{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new gd(vs(this._execution(e),this._execution(e)))}revertedExecution(e){return new gd(vs(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var s;const i=e.getLastOperationId()||(null===(s=this.previousBranch(e))||void 0===s?void 0:s.getLastOperationId());e.append(t),i&&this.insertPrevious(e,t,i)}insertOperationAfter(e,t,s){e.insert(t,s),this.updateNextWith(e,t,s),this.insertPrevious(e,t,s)}undo(e,t){const s=this.buildTransformation.without(t.data),i=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);i&&this.branchingOperationIds.set(o,i),this.insertBranchAfter(e,o),this.transform(o,s)}redo(e){const t=this.nextBranch(e);if(!t)return;const s=this.nextBranch(t);this.removeBranchFromTree(t);const i=this.branchingOperationIds.get(t);i?this.branchingOperationIds.set(e,i):this.branchingOperationIds.delete(e),s&&this.rebaseUp(s)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const s of this.revertedExecution(e))if(s.operation.id===t)return s;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:s}=this.findPreviousBranchingOperation(e);if(!t||!s)return;const i=this.buildTransformation.without(s.data),o=t.fork(s.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(i);const n=this.nextBranch(o);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const s=this.branches.findIndex((t=>t===e));this.branches.splice(s+1,0,t)}updateNextWith(e,t,s){const i=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(i&&o)if(e.getFirstOperationAmong(s,i)===i){const n=this.addToNextBranch(e,o,i,t,s);this.updateNextWith(o,n,s)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,s,i,o){let n=i;return o===s?(n=this.getTransformedOperation(e,s,i),t.prepend(n)):t.contains(o)?(n=this.getTransformedOperation(e,s,i),t.insert(n,o)):t.append(i),n}getTransformedOperation(e,t,s){const i=e.getOperation(t),o=this.buildTransformation.without(i.data);return s.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const s=this.nextBranch(e);s&&this.transform(s,t)}insertPrevious(e,t,s){const{previousBranch:i,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!i||!o)return;const n=this.buildTransformation.with(o.data),r=e.fork(s);r.transform(n),i.cutAfter(s),i.appendBranch(r);const a=t.transformed(n);this.insertPrevious(i,a,s)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const s=this.branchingOperationIds.get(t);return s?{previousBranch:t,branchingOperation:t.getOperation(s)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let s=!!t;const i=e.getOperations();for(let o=i.length-1;o>=0;o--){const n=i[o];n.id===t&&(s=!1),s||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class md{constructor(e,t,s,i,o){this.applyOperation=t,this.revertOperation=s,this.buildEmpty=i,this.buildTransformation=o,this.HEAD_BRANCH=new ud(this.buildTransformation),this.tree=new fd(o,this.HEAD_BRANCH);const n=new pd(e,i(e));this.tree.insertOperationLast(this.HEAD_BRANCH,n),this.HEAD_OPERATION=n}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const s=new pd(e,t),i=this.tree.getLastBranch();this.tree.insertOperationLast(i,s),this.HEAD_BRANCH=i,this.HEAD_OPERATION=s}insert(e,t,s){const i=new pd(e,t);this.revertTo(s),this.tree.insertOperationAfter(this.HEAD_BRANCH,i,s),this.fastForward()}undo(e,t,s){const{branch:i,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(i,o),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}redo(e,t,s){const{branch:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(i),this.fastForward(),this.insert(t,this.buildEmpty(t),s)}drop(e){this.revertBefore(e),this.tree.drop(e)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:s,isCancelled:i}of e)i||this.revertOperation(s.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:s,isCancelled:i}of e)i||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=s}}function vd(e,t,s){return new md(e,(e=>{const i=e.commands.slice(),{changes:o}=t((()=>{for(const e of i)s(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Ed(t.changes[e],"before")}}([e])),(e=>new Xh(e,"empty",[],[])),{with:e=>t=>new Xh(t.id,t.clientId,Yh(t.commands,e.commands)),without:e=>t=>new Xh(t.id,t.clientId,Yh(t.commands,e.commands.map(hd).flat()))})}function Ed(e,t){let s=e.path[0];const i=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const i=e.path[t];if(void 0===s[i]){const o=e.path[t+1];s[i]=dd(o)}s=s[i]}void 0===e[t]?delete s[i]:s[i]=e[t]}class Sd extends i.core.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("pending-revisions-dropped",this,(({revisionIds:e})=>this.drop(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}drop(e){this.undoStack=this.undoStack.filter((t=>!e.includes(t))),this.redoStack=[]}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class bd{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return 0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";e.elements.sort(((e,t)=>t-e));const o=ms(e.elements);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of o){const o=Os(e),l=_s(e);if(n.zone[t]<=o&&o<=n.zone[s]){const e=Math.min(n.zone[s],l)-o+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e)}else if(n.zone[t]>=o&&n.zone[s]<=l)a="REMOVE",r=this.buildInvalidRange(_);else if(n.zone[t]<=l&&n.zone[s]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,i,a,-e),r=this.createAdaptedRange(r,i,"MOVE",-(n.zone[t]-o))}else o<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,i,a,-(l-o+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",s="COL"===e.dimension?"right":"bottom",i="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[s])return{changeType:"RESIZE",range:this.createAdaptedRange(o,i,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,i,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>t.sheetId!==e.sheetId?{changeType:"NONE"}:{changeType:"REMOVE",range:t={...this.buildInvalidRange(_),invalidSheetName:this.getters.getSheetName(e.sheetId)}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(e.name&&t.invalidSheetName===e.name){const s={...t,zone:{...t.zone}};return s.invalidSheetName=void 0,s.sheetId=e.sheetId,{changeType:"CHANGE",range:s}}return{changeType:"NONE"}}))}}finalize(){}verifyRangeRemoved(e){return t=>{const s=e(t);return"NONE"===s.changeType||Fs(s.range.zone)?s:{range:s.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,s,i){return{...e,zone:Ys(e.zone,t,s,i)}}executeOnAllRanges(e,t){const s=this.verifyRangeRemoved(e);for(const e of this.providers)e(s,t)}addRangeProvider(e){this.providers.push(e)}orderZone(e,t){if(e.right<e.left){let s=e.right;e.right=e.left,e.left=s;let i=t[1].colFixed;t[1].colFixed=t[0].colFixed,t[0].colFixed=i}if(e.bottom<e.top){let s=e.bottom;e.bottom=e.top,e.top=s;let i=t[1].rowFixed;t[1].rowFixed=t[0].rowFixed,t[0].rowFixed=i}}createAdaptedRanges(e,t,s,i){return e.map((e=>Fs(e.zone)?(e={...e,sheetId:e.prefixSheet?e.sheetId:i,zone:{left:e.zone.left+(e.parts[0].colFixed?0:t),right:e.zone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.zone.top+(e.parts[0].rowFixed?0:s),bottom:e.zone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:s)}},this.orderZone(e.zone,e.parts),e):e))}getRangeFromSheetXC(e,t){let s,i,o,n=t,r=!1;if(!Jt.test(t))return this.buildInvalidRange(t);t.includes("!")&&(({xc:n,sheetName:s}=es(t)),s?(i=this.getters.getSheetIdByName(s),r=!0,i||(o=s)):o=s);const a=Ns(n);let l=n.split(":").map((e=>({colFixed:e.startsWith("$"),rowFixed:e.includes("$",1)})));return this.orderZone(a,l),{sheetId:i||e,zone:a,parts:l,invalidSheetName:o,prefixSheet:r}}getRangeString(e,t){if(!e)return _;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return _;if(e.zone.left<0||e.zone.top<0)return _;let s=e.sheetId!==t||e.invalidSheetName||e.prefixSheet,i="";if(s&&(i=e.invalidSheetName?e.invalidSheetName:us(this.getters.getSheetName(e.sheetId))),s&&!i)return _;let o=Array(9);return o[0]=e.parts&&e.parts[0].colFixed?"$":"",o[1]=ts(e.zone.left),o[2]=e.parts&&e.parts[0].rowFixed?"$":"",o[3]=String(e.zone.top+1),e.parts&&2===e.parts.length&&(e.zone.top!==e.zone.bottom||e.zone.left!==e.zone.right||e.parts[0].rowFixed||e.parts[0].colFixed||e.parts[1].rowFixed||e.parts[1].colFixed)&&(o[4]=":",o[5]=e.parts[1].colFixed?"$":"",o[6]=ts(e.zone.right),o[7]=e.parts[1].rowFixed?"$":"",o[8]=String(e.zone.bottom+1)),`${s?i+"!":""}${o.join("")}`}buildInvalidRange(e){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:e}}}bd.getters=["getRangeString","getRangeFromSheetXC","createAdaptedRanges"];class Cd{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let s=e[0],i=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const i=e[t];if(void 0===s[i]){const o=e[t+1];s[i]=dd(o)}s=s[i]}s[i]!==t&&(this.changes.push({path:e,before:s[i],after:t}),void 0===t?delete s[i]:s[i]=t)}}const Id={General:0,0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},yd={arrow:"3Arrows",smiley:"3Symbols",dot:"3TrafficLights1"},wd={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"},Td="http://schemas.openxmlformats.org/drawingml/2006/main",xd="http://schemas.openxmlformats.org/drawingml/2006/chart",Rd={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml"},Ld="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ad=.75,Md=.1425,_d=164,Od={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},Nd=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"];function kd(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function Fd(e){return Math.round(Ad*e*window.devicePixelRatio*100)/100}function $d(e){return Math.round(Md*e*100)/100}function Dd(e,t){let s={};e.style&&(s=t.styles[e.style]);const i={font:{size:(null==s?void 0:s.fontSize)||x,color:(null==s?void 0:s.textColor)?s.textColor:"000000",family:2,name:"Arial"},fill:(null==s?void 0:s.fillColor)?{fgColor:s.fillColor}:{reservedAttribute:"none"},numFmt:e.format,border:e.border||0,verticalAlignment:"center",horizontalAlignment:null==s?void 0:s.align};return i.font.strike=!!(null==s?void 0:s.strikethrough)||void 0,i.font.underline=!!(null==s?void 0:s.underline)||void 0,i.font.bold=!!(null==s?void 0:s.bold)||void 0,i.font.italic=!!(null==s?void 0:s.italic)||void 0,i}function Ud(e,t){const s=function(e,t){if(!e)return 0;let s=Id[e];s||(s=Bd(e,t)+_d);return s}(t.numFmt,e.numFmts),i={fontId:Bd(t.font,e.fonts),fillId:Bd(t.fill,e.fills),borderId:t.border,numFmtId:s,verticalAlignment:t.verticalAlignment,horizontalAlignment:t.horizontalAlignment};return Bd(i,e.styles)}function Pd(e,t,s){let i,o=e.find((e=>e.path===t));return o?(i=`rId${(o.rels.length+1).toString()}`,o.rels.push({...s,id:i})):(i="rId1",e.push({path:t,rels:[{...s,id:i}]})),i}function Bd(e,t){let s=t.length;const i="object"==typeof e?Ms:(e,t)=>e===t;for(let o=0;o<s;o++)if(i(e,t[o]))return o;return t[t.length]=e,t.length-1}const Vd=[];function Hd(e){const t=Vd.findIndex((t=>t===e));return-1===t?(Vd.push(e),Vd.length):t+1}function zd(e){return Math.round(914400*e/96)}class Zd{constructor(e){this.xmlString=e}toString(){return this.xmlString}}function Gd(e,t,s){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:s}}function Wd(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function qd(e){return new Zd(e.map((([e,t])=>`${e}="${Wd(t)}"`)).join(" "))}function jd(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),s=t.querySelector("parsererror");if(s){const t=s.innerHTML,i=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),n=o.slice(Math.max(i-3,0),Math.min(i+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${n}`)}return t}function Yd(e,t){return Kd`
|
|
1045
1045
|
<Override ContentType="${t}" PartName="${e}" />
|
|
1046
1046
|
`}function Xd(e){return new Zd(e.join("\n"))}function Kd(e,...t){let s=[e[0]];for(let i=0;i<t.length;i++){const o=t[i]instanceof Zd?t[i]:Wd(t[i]);s.push(o+e[i+1])}return new Zd(s.join(""))}const Qd=17781237,Jd=88853993;function eu(e){const t=[["xmlns:r",Ld],["xmlns:a",Td],["xmlns:c",xd]],s=tu({backgroundColor:Kt(e.data.backgroundColor),line:{color:"000000"}});let i=Kd``;e.data.title&&(i=Kd`
|
|
1047
1047
|
<c:title>
|
|
@@ -1245,7 +1245,7 @@
|
|
|
1245
1245
|
${Xd(n)}
|
|
1246
1246
|
</cfRule>
|
|
1247
1247
|
</conditionalFormatting>
|
|
1248
|
-
`}function fu(e,t){const s=vu(e);s.push(["type","colorScale"]);const i=[];for(const o of e.ranges){const e=[],n=[];let r=!0;for(let s of["minimum","midpoint","maximum"]){const i=t[s];i&&("formula"!==i.type?(e.push(
|
|
1248
|
+
`}function fu(e,t){const s=vu(e);s.push(["type","colorScale"]);const i=[];for(const o of e.ranges){const e=[],n=[];let r=!0;for(let s of["minimum","midpoint","maximum"]){const i=t[s];i&&("formula"!==i.type?(e.push(Su(i,s)),n.push([["rgb",jt(i.color)]])):r=!1)}if(!r){console.warn("Conditional formats with formula rules are not supported at the moment. The rule is therefore skipped.");continue}const a=e.map((e=>Kd`<cfvo ${qd(e)}/>`)),l=n.map((e=>Kd`<color ${qd(e)}/>`));i.push(Kd`
|
|
1249
1249
|
<conditionalFormatting sqref="${o}">
|
|
1250
1250
|
<cfRule ${qd(s)}>
|
|
1251
1251
|
<colorScale>
|
|
@@ -1254,7 +1254,7 @@
|
|
|
1254
1254
|
</colorScale>
|
|
1255
1255
|
</cfRule>
|
|
1256
1256
|
</conditionalFormatting>
|
|
1257
|
-
`)}return Xd(i)}function mu(e,t){const s=vu(e);s.push(["type","iconSet"]);const i=[];for(const o of e.ranges){const e=[[["type","percent"],["val",0]]];let n=!0;for(let s of["lowerInflectionPoint","upperInflectionPoint"]){if("formula"===t[s].type){n=!1;continue}const i=t[s];e.push([...
|
|
1257
|
+
`)}return Xd(i)}function mu(e,t){const s=vu(e);s.push(["type","iconSet"]);const i=[];for(const o of e.ranges){const e=[[["type","percent"],["val",0]]];let n=!0;for(let s of["lowerInflectionPoint","upperInflectionPoint"]){if("formula"===t[s].type){n=!1;continue}const i=t[s];e.push([...Su(i,s),["gte","ge"===i.operator?"1":"0"]])}if(!n){console.warn("Conditional formats with formula rules are not supported at the moment. The rule is therefore skipped.");continue}const r=e.map((e=>Kd`<cfvo ${qd(e)} />`));i.push(Kd`
|
|
1258
1258
|
<conditionalFormatting sqref="${o}">
|
|
1259
1259
|
<cfRule ${qd(s)}>
|
|
1260
1260
|
<iconSet iconSet="${Eu(t.icons)}">
|
|
@@ -1262,7 +1262,7 @@
|
|
|
1262
1262
|
</iconSet>
|
|
1263
1263
|
</cfRule>
|
|
1264
1264
|
</conditionalFormatting>
|
|
1265
|
-
`)}return Xd(i)}function vu(e){return[["priority",1],["stopIfTrue",e.stopIfTrue?1:0]]}function Eu(e){return yd[Object.keys(yd).find((t=>e.upper.toLowerCase().startsWith(t)))||"dots"]}function
|
|
1265
|
+
`)}return Xd(i)}function vu(e){return[["priority",1],["stopIfTrue",e.stopIfTrue?1:0]]}function Eu(e){return yd[Object.keys(yd).find((t=>e.upper.toLowerCase().startsWith(t)))||"dots"]}function Su(e,t){const s=function(e,t){switch(e){case"value":return"minimum"===t?"min":"max";case"number":return"num";case"percentage":return"percent";default:return e}}(e.type,t),i=[["type",s]];if("min"!==s&&"max"!==s){let t=e.value;if("formula"===s)try{!function(e){const{dependencies:t}=Zr(e);t.references.length&&console.warn("Relative references might not work in conditional format formula thresholds in Excel.")}(e.value),t=du(e.value)}catch(s){t=e.value}i.push(["val",t])}return i}function bu(e,t,s){const i=[["xmlns:xdr",wd.drawing],["xmlns:r",Ld],["xmlns:a",Td],["xmlns:c",xd]],o=[];for(const[i,n]of Object.entries(s)){const{from:s,to:r}=Cu(n,t),a=Hd(n.id),l=[["id",a],["name",`Chart ${a}`],["title","Chart"]];o.push(Kd`
|
|
1266
1266
|
<xdr:twoCellAnchor>
|
|
1267
1267
|
<xdr:from>
|
|
1268
1268
|
<xdr:col>${s.col}</xdr:col>
|
|
@@ -1313,7 +1313,7 @@
|
|
|
1313
1313
|
<cols>
|
|
1314
1314
|
${Xd(t)}
|
|
1315
1315
|
</cols>
|
|
1316
|
-
`}function xu(e,t,s){const i=[];for(let o=0;o<s.rowNumber;o++){const n=[["r",o+1]],r=s.rows[o]||{};n.push(["ht",Fd(r.size||
|
|
1316
|
+
`}function xu(e,t,s){const i=[];for(let o=0;o<s.rowNumber;o++){const n=[["r",o+1]],r=s.rows[o]||{};n.push(["ht",Fd(r.size||S)],["customHeight",1],["hidden",r.isHidden?1:0]);const a=[];for(let i=0;i<s.colNumber;i++){const n=is(i,o),r=s.cells[n];if(r){const s=[["r",n]],i=Ud(e,Dd(r,t));s.push(["s",i]);let o=[],l=Kd``;if(r.isFormula){const e=cu(r);if(!e)continue;({attrs:o,node:l}=e)}else if(r.content&&Is(r.content)){const{label:t}=ws(r.content);({attrs:o,node:l}=hu(t,e.sharedStrings))}else r.content&&""!==r.content&&({attrs:o,node:l}=hu(r.content,e.sharedStrings));s.push(...o),a.push(Kd`
|
|
1317
1317
|
<c ${qd(s)}>
|
|
1318
1318
|
${l}
|
|
1319
1319
|
</c>
|
|
@@ -1337,7 +1337,7 @@
|
|
|
1337
1337
|
<mergeCells count="${e.length}">
|
|
1338
1338
|
${Xd(t)}
|
|
1339
1339
|
</mergeCells>
|
|
1340
|
-
`}return Kd``}function
|
|
1340
|
+
`}return Kd``}function Au(e){const t=[],s=function(e){const t=[{},...Object.values(e.borders)];return{relsFiles:[],sharedStrings:[],styles:[{fontId:0,fillId:0,numFmtId:0,borderId:0,verticalAlignment:"center"}],fonts:[{size:x,family:2,color:"000000",name:"Calibri"}],fills:[{reservedAttribute:"none"},{reservedAttribute:"gray125"}],borders:t,numFmts:[],dxfs:[]}}(e);return t.push(function(e,t){const s=[["xmlns",wd.workbook],["xmlns:r",Ld]],i=[];for(const[s,o]of Object.entries(e.sheets)){const e=[["name",o.name],["sheetId",parseInt(s)+1],["r:id",`rId${parseInt(s)+1}`]];i.push(Kd`
|
|
1341
1341
|
<sheet ${qd(e)} />
|
|
1342
1342
|
`),Pd(t.relsFiles,"xl/_rels/workbook.xml.rels",{type:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",target:`worksheets/sheet${s}.xml`})}const o=Kd`
|
|
1343
1343
|
<workbook ${qd(s)}>
|
|
@@ -1345,7 +1345,7 @@
|
|
|
1345
1345
|
${Xd(i)}
|
|
1346
1346
|
</sheets>
|
|
1347
1347
|
</workbook>
|
|
1348
|
-
`;return Gd(jd(o),"xl/workbook.xml","workbook")}(e,s)),t.push(...function(e,t){const s=[];for(const[i,o]of Object.entries(e.sheets)){const n=[["xmlns",wd.worksheet],["xmlns:r",Ld]],r=[["defaultRowHeight",Fd(
|
|
1348
|
+
`;return Gd(jd(o),"xl/workbook.xml","workbook")}(e,s)),t.push(...function(e,t){const s=[];for(const[i,o]of Object.entries(e.sheets)){const n=[["xmlns",wd.worksheet],["xmlns:r",Ld]],r=[["defaultRowHeight",Fd(S)],["defaultColWidth",$d(E)]];let a=Kd``;const l=o.charts;if(l.length){const e=[];for(const o of l){const n=Hd(o.id),r=Pd(t.relsFiles,`xl/drawings/_rels/drawing${i}.xml.rels`,{target:`../charts/chart${n}.xml`,type:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"});e.push(r),s.push(Gd(eu(o),`xl/charts/chart${n}.xml`,"chart"))}const n=Pd(t.relsFiles,`xl/worksheets/_rels/sheet${i}.xml.rels`,{target:`../drawings/drawing${i}.xml`,type:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"});s.push(Gd(bu(e,o,l),`xl/drawings/drawing${i}.xml`,"drawing")),a=Kd`<drawing r:id="${n}" />`}const c=Kd`
|
|
1349
1349
|
<worksheet ${qd(n)}>
|
|
1350
1350
|
<sheetFormatPr ${qd(r)} />
|
|
1351
1351
|
${Tu(o.cols)}
|
|
@@ -1444,13 +1444,13 @@
|
|
|
1444
1444
|
<Relationships xmlns="${wd.Relationships}">
|
|
1445
1445
|
<Relationship ${qd(e)} />
|
|
1446
1446
|
</Relationships>
|
|
1447
|
-
`;return Gd(jd(t),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}var
|
|
1447
|
+
`;return Gd(jd(t),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}var Mu;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing",e[e.Interactive=4]="Interactive"}(Mu||(Mu={}));class _u extends i.core.EventBus{constructor(e={},t={},s=[],i=new oi){super(),this.corePlugins=[],this.uiPlugins=[],this.dataSources=new ld,this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.dispatch=(e,t)=>{const s={type:e,...t};let i=s.interactive?4:this.status;if(this.config.isReadonly&&(o=s,!$e.has(o.type)))return new Pe(52);var o;if(!this.session.canApplyOptimisticUpdate())return new Pe(49);switch(i){case 0:const t=this.checkDispatchAllowed(s);if(!t.isSuccessful)return t;this.status=1;const{changes:i,commands:o}=this.state.recordChanges((()=>{Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s),this.finalize()}));this.session.save(o,i),this.status=0,"headless"!==this.config.mode&&this.trigger("update");break;case 1:if(Ue(s)){const e=this.checkDispatchAllowed(s);if(!e.isSuccessful)return e;this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s)}else this.dispatchToHandlers(this.handlers,s);break;case 4:Ue(s)&&this.state.addCommand(s),this.dispatchToHandlers(this.handlers,s);break;case 3:throw new Error(a("Cannot dispatch commands in the finalize state"));case 2:if(Ue(s))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,s)}return Pe.Success},this.dispatchFromCorePlugin=(e,t)=>{const s={type:e,...t},i=this.status;this.status=2;const o=this.isReplayingCommand?[this.range,...this.corePlugins]:this.handlers;return this.dispatchToHandlers(o,s),this.status=i,Pe.Success},As.model=this,s=da(e,s);const o=ca(e);this.state=new Cd,this.uuidGenerator=i,this.config=this.setupConfig(t),this.session=this.setupSession(o.revisionId),this.config.moveClient=this.session.move.bind(this.session),this.history=new Sd(this.dispatchFromCorePlugin,this.session),this.getters={isReadonly:()=>this.config.isReadonly,canUndo:this.history.canUndo.bind(this.history),canRedo:this.history.canRedo.bind(this.history),getClient:this.session.getClient.bind(this.session),getConnectedClients:this.session.getConnectedClients.bind(this.session),isFullySynchronized:this.session.isFullySynchronized.bind(this.session)},this.range=new bd(this.getters),this.getters.getRangeString=this.range.getRangeString.bind(this.range),this.getters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.getters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.uuidGenerator.setIsFastStrategy(!0);for(let e of nd.getAll())this.setupCorePlugin(e,o);for(let e of rd.getAll())this.setupUiPlugin(e);this.uuidGenerator.setIsFastStrategy(!1),this.dispatch("START"),this.setupSessionEvents(),this.session.loadInitialMessages(s),this.joinSession(t.client),t.snapshotRequested&&this.session.snapshot(this.exportData())}get handlers(){return[this.range,...this.corePlugins,...this.uiPlugins,this.history]}joinSession(e){this.session.join(e)}leaveSession(){this.session.leave()}destroy(){delete As.model}setupUiPlugin(e){if(e.modes.includes(this.config.mode)){const t=new e(this.getters,this.state,this.dispatch,this.config);for(let s of e.getters){if(!(s in t))throw new Error(`Invalid getter name: ${s} for plugin ${t.constructor}`);this.getters[s]=t[s].bind(t)}this.uiPlugins.push(t);const s=e.layers.map((e=>[t,e]));this.renderers.push(...s),this.renderers.sort(((e,t)=>e[1]-t[1]))}}setupCorePlugin(e,t){if(e.modes.includes(this.config.mode)){const s=new e(this.getters,this.state,this.range,this.dispatchFromCorePlugin,this.config,this.uuidGenerator);s.import(t);for(let t of e.getters){if(!(t in s))throw new Error(`Invalid getter name: ${t} for plugin ${s.constructor}`);this.getters[t]=s[t].bind(s)}this.corePlugins.push(s)}}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.uiPlugins,t),this.status=e}this.finalize()}setupSession(e){return new Qh(vd(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers([this.range,...this.corePlugins],e),this.isReplayingCommand=!1)})),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-redone",this,this.finalize),this.session.on("revision-undone",this,this.finalize),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.uuidv4(),name:a("Anonymous").toString()},s=e.transportService||new ad;return{mode:e.mode||"normal",openSidePanel:e.openSidePanel||(()=>{}),notifyUser:e.notifyUser||(()=>{}),askConfirmation:e.askConfirmation||(()=>{}),editText:e.editText||(()=>{}),evalContext:e.evalContext||{},transportService:s,client:t,moveClient:()=>{},isHeadless:"headless"===e.mode||!1,isReadonly:e.isReadonly||!1,snapshotRequested:!1,dataSources:this.dataSources}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return t.some((e=>0!==e))?new Pe(t.flat()):Pe.Success}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}dispatchToHandlers(e,t){for(const s of e)s.beforeHandle(t);for(const s of e)s.handle(t)}drawGrid(e){e.viewport=this.getters.getActiveSnappedViewport();for(let[t,s]of this.renderers)e.ctx.save(),t.drawGrid(e,s),e.ctx.restore()}exportData(){let e=ga();for(let t of this.handlers)t instanceof ma&&t.export(e);return e.revisionId=this.session.getRevisionId()||O,e=JSON.parse(JSON.stringify(e)),e}updateReadOnly(e){e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.isReadonly=e||!1}waitForIdle(){return this.dataSources.waitForReady()}async exportXLSX(){await this.waitForIdle(),this.dispatch("EVALUATE_ALL_SHEETS");let e={...ga(),sheets:[(t=la,s="Sheet1",{...pa(t,s),charts:[]})]};var t,s;for(let t of this.handlers)t instanceof ma&&t.exportForExcel(e);return e=JSON.parse(JSON.stringify(e)),Au(e)}}const{useComponent:Ou,useState:Nu,onPatched:ku,onMounted:Fu}=t.hooks;function $u(e){const t=Nu({x:0,y:0}),s=Ou(),i=function(){const e=Nu({x:0,y:0});let t=document.querySelector(".o-spreadsheet");function s(){if(t||(t=document.querySelector(".o-spreadsheet")),t){const{top:s,left:i}=t.getBoundingClientRect();e.x=i,e.y=s}}return Fu(s),ku(s),e}();function o(){const o=(null==e?void 0:e.el)||s.el,{top:n,left:r}=o.getBoundingClientRect(),a=r-i.x,l=n-i.y;a===t.x&&l===t.y||(t.x=a,t.y=l)}return Fu(o),ku(o),t}const{Portal:Du}=t.misc,{xml:Uu}=t.tags,Pu=Uu`
|
|
1448
1448
|
<Portal target="'.o-spreadsheet'">
|
|
1449
1449
|
<div class="o-popover" t-att-style="style">
|
|
1450
1450
|
<t t-slot="default"/>
|
|
1451
1451
|
</div>
|
|
1452
1452
|
</Portal>
|
|
1453
|
-
`;class Bu extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters}get maxHeight(){return Math.max(0,this.viewportDimension.height-36-
|
|
1453
|
+
`;class Bu extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters}get maxHeight(){return Math.max(0,this.viewportDimension.height-36-b)}get style(){const e=`left:${this.horizontalPosition()}`;return`\n position: absolute;\n z-index: 5;\n ${`top:${this.verticalPosition()}`}px;\n ${e}px;\n ${`max-height:${this.maxHeight}`}px;\n width:${this.props.childWidth}px;\n overflow-y: auto;\n overflow-x: hidden;\n box-shadow: 1px 2px 5px 2px rgb(51 51 51 / 15%);\n `}get viewportDimension(){return this.getters.getViewportDimension()}get shouldRenderRight(){const{x:e}=this.props.position;return e+this.props.childWidth<this.viewportDimension.width}get shouldRenderBottom(){const{y:e}=this.props.position;return e+Math.min(this.props.childHeight,this.maxHeight)<this.viewportDimension.height+v}horizontalPosition(){const{x:e}=this.props.position;return this.shouldRenderRight?e:e-this.props.childWidth-this.props.flipHorizontalOffset}verticalPosition(){const{y:e}=this.props.position;return this.shouldRenderBottom?e:Math.max(e-this.props.childHeight+this.props.flipVerticalOffset,this.props.marginTop)}}Bu.template=Pu,Bu.components={Portal:Du},Bu.defaultProps={flipHorizontalOffset:0,flipVerticalOffset:0,verticalOffset:0,marginTop:0};const{xml:Vu,css:Hu}=t.tags,{useExternalListener:zu,useRef:Zu}=t.hooks,Gu=Vu`
|
|
1454
1454
|
<Popover
|
|
1455
1455
|
position="props.position"
|
|
1456
1456
|
childWidth="${y}"
|
|
@@ -1710,7 +1710,7 @@
|
|
|
1710
1710
|
<div class="o-autocomplete-description" t-esc="v.description" t-if="state.selectedIndex === v_index"/>
|
|
1711
1711
|
</div>
|
|
1712
1712
|
</t>
|
|
1713
|
-
</div>`,
|
|
1713
|
+
</div>`,Sp=fp`
|
|
1714
1714
|
.o-autocomplete-dropdown {
|
|
1715
1715
|
pointer-events: auto;
|
|
1716
1716
|
background-color: #fff;
|
|
@@ -1734,7 +1734,7 @@
|
|
|
1734
1734
|
}
|
|
1735
1735
|
}
|
|
1736
1736
|
}
|
|
1737
|
-
`;class
|
|
1737
|
+
`;class bp extends t.Component{constructor(){super(...arguments),this.state=t.useState({values:[],selectedIndex:0})}mounted(){this.filter(this.props.search)}willUpdateProps(e){return e.search!==this.props.search&&this.filter(e.search),super.willUpdateProps(e)}async filter(e){let t=vp.get(this.props.provider)();t=this.props.filter?this.props.filter(e,t):t.filter((t=>t.text.toUpperCase().startsWith(e.toUpperCase()))).sort(((e,t)=>e.text<t.text?-1:e.text>t.text?1:0)),this.state.values=t.slice(0,10),this.state.selectedIndex=0}fillValue(e){this.state.selectedIndex=e,this.trigger("completed",{text:this.getValueToFill()})}moveDown(){this.state.selectedIndex=(this.state.selectedIndex+1)%this.state.values.length}moveUp(){this.state.selectedIndex--,this.state.selectedIndex<0&&(this.state.selectedIndex=this.state.values.length-1)}getValueToFill(){if(this.state.values.length)return this.state.values[this.state.selectedIndex].text}}bp.template=Ep,bp.style=Sp;class Cp{constructor(e){this.el=e}updateEl(e){this.el=e}selectRange(e,t){let s=window.getSelection();this.removeSelection();let i=document.createRange();if(e==t&&0===e)i.setStart(this.el,0),i.setEnd(this.el,0),s.addRange(i);else{(e<0||t>this.el.textContent.length)&&(console.warn(`wrong selection asked start ${e}, end ${t}, text content length ${this.el.textContent.length}`),e<0&&(e=0),t>this.el.textContent.length&&(t=this.el.textContent.length),e>this.el.textContent.length&&(e=this.el.textContent.length));let o=this.findChildAtCharacterIndex(e),n=this.findChildAtCharacterIndex(t);i.setStart(o.node,o.offset),s.addRange(i),s.extend(n.node,n.offset)}}findChildAtCharacterIndex(e){let t,s,i=this.iterateChildren(this.el),o=e;do{t=i.next(),t.done||t.value.hasChildNodes()||(t.value.textContent&&t.value.textContent.length<o?o-=t.value.textContent.length:i.return(t.value),s=t.value)}while(!t.done);return t.value?{node:t.value,offset:o}:{node:s,offset:o}}*iterateChildren(e){if(yield e,e.hasChildNodes())for(let t of e.childNodes)yield*this.iterateChildren(t)}setText(e){if(0!==e.length)for(const t of e){const e=document.createElement("span");e.innerText=t.value,t.color&&(e.style.color=t.color),t.class&&e.classList.add(t.class),this.el.appendChild(e)}}removeSelection(){window.getSelection().removeAllRanges()}removeAll(){if(this.el)for(;this.el.firstChild;)this.el.removeChild(this.el.firstChild)}getCurrentSelection(){let{startElement:e,endElement:t,startSelectionOffset:s,endSelectionOffset:i}=this.getStartAndEndSelection();return{start:this.findSelectionIndex(e,s),end:this.findSelectionIndex(t,i)}}findSelectionIndex(e,t){let s=this.iterateChildren(this.el),i=0,o=s.next();for(;!o.done&&o.value!==e;)o.value.hasChildNodes()||o.value.textContent&&(i+=o.value.textContent.length),o=s.next();if(o.value===e)if(o.value.hasChildNodes()){const e=[...o.value.childNodes].slice(0,t);for(const t of e)t.textContent&&(i+=t.textContent.length)}else i+=t;return i}getStartAndEndSelection(){const e=document.getSelection();return{startElement:e.anchorNode||this.el,startSelectionOffset:e.anchorOffset,endElement:e.focusNode||this.el,endSelectionOffset:e.focusOffset}}}const Ip=a("ABOUT"),yp=a("optional"),wp=a("by default"),Tp=a("repeatable"),{xml:xp,css:Rp}=t.tags,{useState:Lp}=t.hooks,Ap=xp`
|
|
1738
1738
|
<div class="o-formula-assistant-container"
|
|
1739
1739
|
t-att-style="props.borderStyle"
|
|
1740
1740
|
t-att-class="{
|
|
@@ -1786,7 +1786,7 @@
|
|
|
1786
1786
|
|
|
1787
1787
|
</div>
|
|
1788
1788
|
</div>
|
|
1789
|
-
`,
|
|
1789
|
+
`,Mp=Rp`
|
|
1790
1790
|
.o-formula-assistant {
|
|
1791
1791
|
white-space: normal;
|
|
1792
1792
|
background-color: #fff;
|
|
@@ -1833,7 +1833,7 @@
|
|
|
1833
1833
|
.o-formula-assistant-transparency {
|
|
1834
1834
|
opacity: 0.3;
|
|
1835
1835
|
}
|
|
1836
|
-
`;class _p extends t.Component{constructor(){super(...arguments),this.assistantState=Lp({allowCellSelectionBehind:!1}),this.timeOutId=0}willUnmount(){this.timeOutId&&clearTimeout(this.timeOutId)}getContext(){return this.props}onMouseMove(){this.assistantState.allowCellSelectionBehind=!0,this.timeOutId&&clearTimeout(this.timeOutId),this.timeOutId=setTimeout((()=>{this.assistantState.allowCellSelectionBehind=!1}),2e3)}}_p.template=
|
|
1836
|
+
`;class _p extends t.Component{constructor(){super(...arguments),this.assistantState=Lp({allowCellSelectionBehind:!1}),this.timeOutId=0}willUnmount(){this.timeOutId&&clearTimeout(this.timeOutId)}getContext(){return this.props}onMouseMove(){this.assistantState.allowCellSelectionBehind=!0,this.timeOutId&&clearTimeout(this.timeOutId),this.timeOutId=setTimeout((()=>{this.assistantState.allowCellSelectionBehind=!1}),2e3)}}_p.template=Ap,_p.style=Mp;const{useState:Op,useRef:Np}=t.hooks,{xml:kp,css:Fp}=t.tags,$p=rr.content,Dp="#4a4e4d",Up="#3da4ab",Pp="#02c39a",Bp="selector-flag",Vp={OPERATOR:Up,NUMBER:Pp,STRING:"#f6cd61",FUNCTION:Dp,DEBUGGER:Up,LEFT_PAREN:Dp,RIGHT_PAREN:Dp,COMMA:Dp},Hp=kp`
|
|
1837
1837
|
<div class="o-composer-container">
|
|
1838
1838
|
<div
|
|
1839
1839
|
t-att-class="{ 'o-composer': true, 'text-muted': getters.isReadonly(), 'unfocusable': getters.isReadonly() }"
|
|
@@ -1912,7 +1912,7 @@
|
|
|
1912
1912
|
.o-topbar-toolbar .o-composer-container:focus-within {
|
|
1913
1913
|
border: 1px solid ${p};
|
|
1914
1914
|
}
|
|
1915
|
-
`;class Zp extends t.Component{constructor(){super(...arguments),this.composerRef=Np("o_composer"),this.autoCompleteRef=Np("o_autocomplete_provider"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.composerState=Op({positionStart:0,positionEnd:0}),this.autoCompleteState=Op({showProvider:!1,provider:"functions",search:""}),this.functionDescriptionState=Op({showDescription:!1,functionName:"",functionDescription:{},argToFocus:0}),this.isKeyStillDown=!1,this.compositionActive=!1,this.borderStyle="box-shadow: 0 1px 4px 3px rgba(60, 64, 67, 0.15);",this.shouldProcessInputEvents=!1,this.tokens=[],this.keyMapping={ArrowUp:this.processArrowKeys,ArrowDown:this.processArrowKeys,ArrowLeft:this.processArrowKeys,ArrowRight:this.processArrowKeys,Enter:this.processEnterKey,Escape:this.processEscapeKey,F2:()=>console.warn("Not implemented"),F4:()=>console.warn("Not implemented"),Tab:e=>this.processTabKey(e)},this.contentHelper=new Cp(this.composerRef.el)}get assistantStyle(){if(this.props.delimitation&&this.props.rect){const[e,t,,s]=this.props.rect;let i="";return t>this.props.delimitation.height-(t+s)&&(i+="\n top: -8px;\n transform: translate(0, -100%);\n "),e+300>this.props.delimitation.width&&(i+="right:0px;"),i+="width:300px;"}return"width:300px;"}mounted(){
|
|
1915
|
+
`;class Zp extends t.Component{constructor(){super(...arguments),this.composerRef=Np("o_composer"),this.autoCompleteRef=Np("o_autocomplete_provider"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.composerState=Op({positionStart:0,positionEnd:0}),this.autoCompleteState=Op({showProvider:!1,provider:"functions",search:""}),this.functionDescriptionState=Op({showDescription:!1,functionName:"",functionDescription:{},argToFocus:0}),this.isKeyStillDown=!1,this.compositionActive=!1,this.borderStyle="box-shadow: 0 1px 4px 3px rgba(60, 64, 67, 0.15);",this.shouldProcessInputEvents=!1,this.tokens=[],this.keyMapping={ArrowUp:this.processArrowKeys,ArrowDown:this.processArrowKeys,ArrowLeft:this.processArrowKeys,ArrowRight:this.processArrowKeys,Enter:this.processEnterKey,Escape:this.processEscapeKey,F2:()=>console.warn("Not implemented"),F4:()=>console.warn("Not implemented"),Tab:e=>this.processTabKey(e)},this.contentHelper=new Cp(this.composerRef.el)}get assistantStyle(){if(this.props.delimitation&&this.props.rect){const[e,t,,s]=this.props.rect;let i="";return t>this.props.delimitation.height-(t+s)&&(i+="\n top: -8px;\n transform: translate(0, -100%);\n "),e+300>this.props.delimitation.width&&(i+="right:0px;"),i+="width:300px;"}return"width:300px;"}mounted(){As.composer=this;const e=this.composerRef.el;this.contentHelper.updateEl(e),this.processContent()}willUnmount(){delete As.composer,this.trigger("composer-unmounted")}patched(){this.isKeyStillDown||this.processContent()}processArrowKeys(e){if(this.getters.isSelectingForComposer())return void(this.functionDescriptionState.showDescription=!1);if("cellFocus"===this.props.focus&&!this.autoCompleteState.showProvider)return;e.stopPropagation();const t=this.autoCompleteRef.comp;["ArrowUp","ArrowDown"].includes(e.key)&&this.autoCompleteState.showProvider&&t&&(e.preventDefault(),"ArrowUp"===e.key?t.moveUp():t.moveDown()),this.updateCursorIfNeeded()}processTabKey(e){e.preventDefault(),e.stopPropagation();const t=this.autoCompleteRef.comp;if(this.autoCompleteState.showProvider&&t){const e=t.getValueToFill();if(e)return void this.autoComplete(e)}else this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const s=e.shiftKey?-1:1;this.dispatch("MOVE_POSITION",{deltaX:s,deltaY:0})}processEnterKey(e){e.preventDefault(),e.stopPropagation(),this.isKeyStillDown=!1;const t=this.autoCompleteRef.comp;if(this.autoCompleteState.showProvider&&t){const e=t.getValueToFill();if(e)return void this.autoComplete(e)}this.dispatch("STOP_EDITION"),this.dispatch("MOVE_POSITION",{deltaX:0,deltaY:e.shiftKey?-1:1})}processEscapeKey(){this.dispatch("STOP_EDITION",{cancel:!0})}onCompositionStart(){this.compositionActive=!0}onCompositionEnd(){this.compositionActive=!1}onKeydown(e){let t=this.keyMapping[e.key];t?t.call(this,e):(e.stopPropagation(),this.updateCursorIfNeeded())}updateCursorIfNeeded(){if(!this.getters.isSelectingForComposer()){const{start:e,end:t}=this.contentHelper.getCurrentSelection();this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:e,end:t}),this.isKeyStillDown=!0}}onInput(){if("inactive"===this.props.focus||!this.shouldProcessInputEvents)return;this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const e=this.composerRef.el;this.dispatch("SET_CURRENT_CONTENT",{content:e.childNodes.length?e.textContent:"",selection:this.contentHelper.getCurrentSelection()})}onKeyup(e){if(this.isKeyStillDown=!1,"inactive"===this.props.focus||["Control","Shift","Tab","Enter"].includes(e.key))return;if(this.autoCompleteState.showProvider&&["ArrowUp","ArrowDown"].includes(e.key))return;if(this.getters.isSelectingForComposer()&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return;if(e.preventDefault(),e.stopPropagation(),this.autoCompleteState.showProvider=!1,e.ctrlKey&&" "===e.key)return this.autoCompleteState.search="",this.autoCompleteState.showProvider=!0,void this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const{start:t,end:s}=this.getters.getComposerSelection(),{start:i,end:o}=this.contentHelper.getCurrentSelection();i===t&&o===s||this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",this.contentHelper.getCurrentSelection()),this.processTokenAtCursor(),this.processContent()}onMousedown(e){e.button>0||this.contentHelper.removeSelection()}onClick(){if(this.getters.isReadonly())return;const e=this.contentHelper.getCurrentSelection();this.dispatch("STOP_COMPOSER_RANGE_SELECTION"),"inactive"===this.props.focus&&this.trigger("composer-content-focused",{selection:e}),this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",e),this.processTokenAtCursor()}onBlur(){this.isKeyStillDown=!1}onCompleted(e){this.autoComplete(e.detail.text)}processContent(){if(this.compositionActive)return;this.contentHelper.removeAll(),this.shouldProcessInputEvents=!1,"inactive"!==this.props.focus&&this.contentHelper.selectRange(0,0);const e=this.getContent();if(0!==e.length){this.contentHelper.setText(e);const{start:t,end:s}=this.getters.getComposerSelection();"inactive"!==this.props.focus&&this.contentHelper.selectRange(t,s)}this.shouldProcessInputEvents=!0}getContent(){let e;const t=this.getters.getCurrentContent(),s=t.startsWith("=")&&this.getters.getCurrentTokens().length>0;return e=""===t?[]:s&&"inactive"!==this.getters.getEditionMode()?this.getColoredTokens():[{value:t}],e}getColoredTokens(){const e=this.getters.getCurrentTokens(),t=this.getters.getTokenAtCursor(),s=[],{end:i}=this.getters.getComposerSelection();for(const o of e){switch(o.type){case"OPERATOR":case"NUMBER":case"FUNCTION":case"COMMA":case"STRING":s.push({value:o.value,color:Vp[o.type]||"#000"});break;case"SYMBOL":let e=o.value;const{xc:i,sheetName:n}=es(e);Jt.test(i)?s.push({value:o.value,color:this.rangeColor(i,n)||"#000"}):["TRUE","FALSE"].includes(e.toUpperCase())?s.push({value:o.value,color:Pp}):s.push({value:o.value,color:"#000"});break;case"LEFT_PAREN":case"RIGHT_PAREN":t&&["LEFT_PAREN","RIGHT_PAREN"].includes(t.type)&&t.parenIndex&&t.parenIndex===o.parenIndex?s.push({value:o.value,color:"pink"}):s.push({value:o.value,color:Vp[o.type]||"#000"});break;default:s.push({value:o.value,color:"#000"})}"waitingForRangeSelection"===this.getters.getEditionMode()&&i===o.end&&(s[s.length-1].class=Bp)}return s}rangeColor(e,t){if("inactive"===this.getters.getEditionMode())return;const s=this.getters.getHighlights(),i=t?this.getters.getSheetIdByName(t):this.getters.getEditionSheet(),o=s.find((t=>{if(t.sheet!==i)return!1;let s=ks(e);const{height:o,width:n}=Ws(s);return s=o*n==1?this.getters.expandZone(i,ks(e)):s,t.sheet===i&&Bs(s,t.zone)}));return o&&o.color?o.color:void 0}processTokenAtCursor(){let e=this.getters.getCurrentContent();if(this.autoCompleteState.showProvider=!1,this.functionDescriptionState.showDescription=!1,e.startsWith("=")){const e=this.getters.getTokenAtCursor();if(e){const{xc:t}=es(e.value);if("FUNCTION"===e.type||"SYMBOL"===e.type&&!Jt.test(t))this.autoCompleteState.search=e.value,this.autoCompleteState.showProvider=!0;else if(e.functionContext&&"UNKNOWN"!==e.type){const t=e.functionContext,s=t.parent.toUpperCase(),i=$p[s],o=t.argPosition;this.functionDescriptionState.functionName=s,this.functionDescriptionState.functionDescription=i,this.functionDescriptionState.argToFocus=i.getArgToFocus(o+1)-1,this.functionDescriptionState.showDescription=!0}}}}autoComplete(e){if(e){const t=this.getters.getTokenAtCursor();if(t){let s=t.end,i=t.end;["SYMBOL","FUNCTION"].includes(t.type)&&(s=t.start);const o=this.getters.getCurrentTokens();if(this.autoCompleteState.provider&&o.length){e+="(";const s=o.map((e=>e.start)).indexOf(t.start);if(s+1<o.length){"LEFT_PAREN"===o[s+1].type&&i++}}this.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION",{start:s,end:i})}this.dispatch("REPLACE_COMPOSER_CURSOR_SELECTION",{text:e})}this.processTokenAtCursor()}}Zp.template=Hp,Zp.style=zp,Zp.components={TextValueProvider:bp,FunctionDescriptionProvider:_p},Zp.defaultProps={inputStyle:"",focus:"inactive"};const{useState:Gp}=t.hooks,{xml:Wp,css:qp}=t.tags,jp=Wp`
|
|
1916
1916
|
<div class="o-grid-composer" t-att-style="containerStyle">
|
|
1917
1917
|
<Composer
|
|
1918
1918
|
focus = "props.focus"
|
|
@@ -1929,7 +1929,7 @@
|
|
|
1929
1929
|
position: absolute;
|
|
1930
1930
|
border: ${3*.4*window.devicePixelRatio||1}px solid ${p};
|
|
1931
1931
|
}
|
|
1932
|
-
`;class Xp extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.composerState=Gp({rect:null,delimitation:null});const[e,t]=this.getters.getPosition();this.zone=this.getters.expandZone(this.getters.getActiveSheetId(),{left:e,right:e,top:t,bottom:t}),this.rect=this.getters.getRect(this.zone,this.getters.getActiveSnappedViewport())}get containerStyle(){const e=this.getters.getCurrentContent().startsWith("="),t=this.getters.getCurrentStyle(),[s,i,o,n]=this.rect,r=!e&&t.fillColor||"#ffffff",a=!e&&t.textColor||"#000000",l=!e&&t.fontSize||10,c=!e&&t.bold?"bold":500,h=!e&&t.italic?"italic":"normal",d=e?"none":kc(t);let u="left";if(!e){const e=this.getters.getActiveCell();u=t.align||(null==e?void 0:e.defaultAlign)||"left"}return`\n left: ${s-1}px;\n top: ${i}px;\n min-width: ${o+2}px;\n min-height: ${n+1}px;\n\n background: ${r};\n color: ${a};\n\n font-size: ${cs[l]}px;\n font-weight: ${c};\n font-style: ${h};\n text-decoration: ${d};\n\n text-align: ${u};\n `}get composerStyle(){return`\n line-height: ${
|
|
1932
|
+
`;class Xp extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters,this.composerState=Gp({rect:null,delimitation:null});const[e,t]=this.getters.getPosition();this.zone=this.getters.expandZone(this.getters.getActiveSheetId(),{left:e,right:e,top:t,bottom:t}),this.rect=this.getters.getRect(this.zone,this.getters.getActiveSnappedViewport())}get containerStyle(){const e=this.getters.getCurrentContent().startsWith("="),t=this.getters.getCurrentStyle(),[s,i,o,n]=this.rect,r=!e&&t.fillColor||"#ffffff",a=!e&&t.textColor||"#000000",l=!e&&t.fontSize||10,c=!e&&t.bold?"bold":500,h=!e&&t.italic?"italic":"normal",d=e?"none":kc(t);let u="left";if(!e){const e=this.getters.getActiveCell();u=t.align||(null==e?void 0:e.defaultAlign)||"left"}return`\n left: ${s-1}px;\n top: ${i}px;\n min-width: ${o+2}px;\n min-height: ${n+1}px;\n\n background: ${r};\n color: ${a};\n\n font-size: ${cs[l]}px;\n font-weight: ${c};\n font-style: ${h};\n text-decoration: ${d};\n\n text-align: ${u};\n `}get composerStyle(){return`\n line-height: ${S}px;\n max-height: inherit;\n overflow: hidden;\n `}mounted(){const e=this.el,t=e.parentElement.clientHeight-this.rect[1]-15;e.style.maxHeight=t+"px";const s=e.parentElement.clientWidth-this.rect[0]-14;e.style.maxWidth=s+"px",this.composerState.rect=[this.rect[0],this.rect[1],e.clientWidth,e.clientHeight],this.composerState.delimitation={width:e.parentElement.clientWidth,height:e.parentElement.clientHeight}}onKeydown(e){["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key)&&e.preventDefault()}}Xp.template=jp,Xp.style=Yp,Xp.components={Composer:Zp};const{xml:Kp,css:Qp}=t.tags,Jp=Kp`
|
|
1933
1933
|
<div class="o-error-tooltip">
|
|
1934
1934
|
<t t-esc="props.text"/>
|
|
1935
1935
|
</div>
|
|
@@ -2076,7 +2076,7 @@
|
|
|
2076
2076
|
}
|
|
2077
2077
|
}
|
|
2078
2078
|
}
|
|
2079
|
-
`;class gg extends t.Component{constructor(){super(...arguments),this.figureRegistry=
|
|
2079
|
+
`;class gg extends t.Component{constructor(){super(...arguments),this.figureRegistry=Ma,this.dnd=dg({figureId:"",x:0,y:0,width:0,height:0}),this.getters=this.env.getters,this.dispatch=this.env.dispatch}getVisibleFigures(){const e=this.getters.getSelectedFigureId();return this.getters.getVisibleFigures(this.getters.getActiveSheetId()).map((t=>({id:t.id,isSelected:t.id===e,figure:t})))}getDims(e){const{figure:t,isSelected:s}=e,i=2*(s?2:1),{width:o,height:n}=s&&this.dnd.figureId?this.dnd:t;return`width:${o+i}px;height:${n+i}px`}getStyle(e){const{figure:t,isSelected:s}=e,{offsetX:i,offsetY:o}=this.getters.getActiveSnappedViewport(),n=t.id===(s&&this.dnd.figureId)?this.dnd:t,{width:r,height:a}=n;let l=n.x-i+m-1,c=n.y-o+f-1;const h=Math.max(0,m-l);l+=h;const d=Math.max(0,f-c);if(c+=d,r<0||a<0)return"position:absolute;display:none;";const u=10+(s?2:1);return`position:absolute; top:${c+1}px; left:${l+1}px; width:${r-h+u}px; height:${a-d+u}px`}mounted(){this.render()}resize(e,t,s,i){i.stopPropagation();const o=i.clientX,n=i.clientY;this.dnd.figureId=e.id,this.dnd.x=e.x,this.dnd.y=e.y,this.dnd.width=e.width,this.dnd.height=e.height;ep((i=>{const r=t*(i.clientX-o),a=s*(i.clientY-n);this.dnd.width=Math.max(e.width+r,80),this.dnd.height=Math.max(e.height+a,80),t<0&&(this.dnd.x=e.x-r),s<0&&(this.dnd.y=e.y-a)}),(i=>{this.dnd.figureId="";const o={x:this.dnd.x,y:this.dnd.y};t&&(o.width=this.dnd.width),s&&(o.height=this.dnd.height),this.dispatch("UPDATE_FIGURE",{sheetId:this.getters.getActiveSheetId(),id:e.id,...o})}))}onMouseDown(e,t){if(t.button>0)return;if(!this.dispatch("SELECT_FIGURE",{id:e.id}).isSuccessful)return;this.props.sidePanelIsOpen&&this.env.openSidePanel("ChartPanel",{figure:e});const s=t.clientX,i=t.clientY;this.dnd.figureId=e.id,this.dnd.x=e.x,this.dnd.y=e.y,this.dnd.width=e.width,this.dnd.height=e.height;ep((t=>{this.dnd.x=Math.max(e.x-s+t.clientX,0),this.dnd.y=Math.max(e.y-i+t.clientY,0)}),(t=>{this.dnd.figureId="",this.dispatch("UPDATE_FIGURE",{sheetId:this.getters.getActiveSheetId(),id:e.id,x:this.dnd.x,y:this.dnd.y})}))}onKeyDown(e,t){switch(t.preventDefault(),t.key){case"Delete":this.dispatch("DELETE_FIGURE",{sheetId:this.getters.getActiveSheetId(),id:e.id}),this.trigger("figure-deleted");break;case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":const s={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}[t.key];this.dispatch("UPDATE_FIGURE",{sheetId:this.getters.getActiveSheetId(),id:e.id,x:e.x+s[0],y:e.y+s[1]})}}}gg.template=ug,gg.style=pg,gg.components={},Ma.add("chart",{Component:lg,SidePanelComponent:"ChartPanel"});const{xml:fg,css:mg}=t.tags,vg=fg`
|
|
2080
2080
|
<div class="o-border"
|
|
2081
2081
|
t-on-mousedown="onMouseDown"
|
|
2082
2082
|
t-att-style="style"
|
|
@@ -2100,7 +2100,7 @@
|
|
|
2100
2100
|
.o-moving {
|
|
2101
2101
|
cursor: grabbing;
|
|
2102
2102
|
}
|
|
2103
|
-
`;class
|
|
2103
|
+
`;class Sg extends t.Component{get style(){const e=["n","w","e"].includes(this.props.orientation),t=["n","w","s"].includes(this.props.orientation),s=["n","s"].includes(this.props.orientation),i=["w","e"].includes(this.props.orientation),o=this.env.getters.getActiveSheet(),n=this.props.zone,r=o.cols[n.left].start+2,a=o.cols[n.right].end-4,l=o.rows[n.top].start+2,c=o.rows[n.bottom].end-4,h=t?r:a,d=e?l:c,u=s?a-r:4,p=i?c-l:4,{offsetX:g,offsetY:v}=this.env.getters.getActiveSnappedViewport();return`\n left:${h+m-g}px;\n top:${d+f-v}px;\n width:${u}px;\n height:${p}px;\n `}onMouseDown(e){this.trigger("move-highlight",{clientX:e.clientX,clientY:e.clientY})}}Sg.template=vg,Sg.style=Eg;const{xml:bg,css:Cg}=t.tags,Ig=bg`
|
|
2104
2104
|
<div class="o-corner"
|
|
2105
2105
|
t-on-mousedown="onMouseDown"
|
|
2106
2106
|
t-att-style="style"
|
|
@@ -2155,7 +2155,7 @@
|
|
|
2155
2155
|
/>
|
|
2156
2156
|
</t>
|
|
2157
2157
|
</div>
|
|
2158
|
-
`;class Rg extends t.Component{constructor(){super(...arguments),this.highlightState=t.useState({shiftingMode:"none"})}onResizeHighlight(e){this.highlightState.shiftingMode="isResizing";const t=this.props.zone,s=e.detail.isLeft?t.right:t.left,i=e.detail.isTop?t.bottom:t.top;let o=e.detail.isLeft?t.left:t.right,n=e.detail.isTop?t.top:t.bottom,r=t;this.env.dispatch("START_CHANGE_HIGHLIGHT",{zone:r});tp(this.el.parentElement,this.env,((e,t)=>{if(o!==e||n!==t){const a=this.env.getters.getActiveSheet();o=ps(-1===e?o:e,0,a.cols.length-1),n=ps(-1===t?n:t,0,a.rows.length-1);let l={left:Math.min(s,o),top:Math.min(i,n),right:Math.max(s,o),bottom:Math.max(i,n)};l=this.env.getters.expandZone(a.id,l),Bs(l,r)||(this.env.dispatch("CHANGE_HIGHLIGHT",{zone:l}),r=l)}}),(()=>{this.highlightState.shiftingMode="none",this.env.dispatch("STOP_COMPOSER_RANGE_SELECTION")}))}onMoveHighlight(e){this.highlightState.shiftingMode="isMoving";const t=this.props.zone,s=this.el.parentElement,i=s.getBoundingClientRect(),o=this.env.getters.getActiveSheet(),{top:n,left:r}=this.env.getters.getActiveSnappedViewport(),a=this.env.getters.getColIndex(e.detail.clientX-i.left,r),l=this.env.getters.getRowIndex(e.detail.clientY-i.top,n),c=-t.left,h=o.cols.length-t.right-1,d=-t.top,u=o.rows.length-t.bottom-1;let p=t;this.env.dispatch("START_CHANGE_HIGHLIGHT",{zone:p});let g=a,f=l;tp(s,this.env,((e,s)=>{if(g!==e||f!==s){g=-1===e?g:e,f=-1===s?f:s;const i=ps(g-a,c,h),n=ps(f-l,d,u);let r={left:t.left+i,top:t.top+n,right:t.right+i,bottom:t.bottom+n};r=this.env.getters.expandZone(o.id,r),Bs(r,p)||(this.env.dispatch("CHANGE_HIGHLIGHT",{zone:r}),p=r)}}),(()=>{this.highlightState.shiftingMode="none",this.env.dispatch("STOP_COMPOSER_RANGE_SELECTION")}))}}Rg.template=xg,Rg.components={Corner:wg,Border:
|
|
2158
|
+
`;class Rg extends t.Component{constructor(){super(...arguments),this.highlightState=t.useState({shiftingMode:"none"})}onResizeHighlight(e){this.highlightState.shiftingMode="isResizing";const t=this.props.zone,s=e.detail.isLeft?t.right:t.left,i=e.detail.isTop?t.bottom:t.top;let o=e.detail.isLeft?t.left:t.right,n=e.detail.isTop?t.top:t.bottom,r=t;this.env.dispatch("START_CHANGE_HIGHLIGHT",{zone:r});tp(this.el.parentElement,this.env,((e,t)=>{if(o!==e||n!==t){const a=this.env.getters.getActiveSheet();o=ps(-1===e?o:e,0,a.cols.length-1),n=ps(-1===t?n:t,0,a.rows.length-1);let l={left:Math.min(s,o),top:Math.min(i,n),right:Math.max(s,o),bottom:Math.max(i,n)};l=this.env.getters.expandZone(a.id,l),Bs(l,r)||(this.env.dispatch("CHANGE_HIGHLIGHT",{zone:l}),r=l)}}),(()=>{this.highlightState.shiftingMode="none",this.env.dispatch("STOP_COMPOSER_RANGE_SELECTION")}))}onMoveHighlight(e){this.highlightState.shiftingMode="isMoving";const t=this.props.zone,s=this.el.parentElement,i=s.getBoundingClientRect(),o=this.env.getters.getActiveSheet(),{top:n,left:r}=this.env.getters.getActiveSnappedViewport(),a=this.env.getters.getColIndex(e.detail.clientX-i.left,r),l=this.env.getters.getRowIndex(e.detail.clientY-i.top,n),c=-t.left,h=o.cols.length-t.right-1,d=-t.top,u=o.rows.length-t.bottom-1;let p=t;this.env.dispatch("START_CHANGE_HIGHLIGHT",{zone:p});let g=a,f=l;tp(s,this.env,((e,s)=>{if(g!==e||f!==s){g=-1===e?g:e,f=-1===s?f:s;const i=ps(g-a,c,h),n=ps(f-l,d,u);let r={left:t.left+i,top:t.top+n,right:t.right+i,bottom:t.bottom+n};r=this.env.getters.expandZone(o.id,r),Bs(r,p)||(this.env.dispatch("CHANGE_HIGHLIGHT",{zone:r}),p=r)}}),(()=>{this.highlightState.shiftingMode="none",this.env.dispatch("STOP_COMPOSER_RANGE_SELECTION")}))}}Rg.template=xg,Rg.components={Corner:wg,Border:Sg};const{xml:Lg,css:Ag}=t.tags,Mg=Lg`
|
|
2159
2159
|
<div class="o-link-tool">
|
|
2160
2160
|
<t t-set="link" t-value="cell.link"/>
|
|
2161
2161
|
<a t-if="link.isExternal"
|
|
@@ -2175,7 +2175,7 @@
|
|
|
2175
2175
|
<span t-if="!env.getters.isReadonly()" class="o-link-icon o-unlink" t-on-click="unlink" title="${xc}">${'<svg class="o-icon" viewBox="0 0 512 512"><path fill="currentColor" d="M304.083 405.907c4.686 4.686 4.686 12.284 0 16.971l-44.674 44.674c-59.263 59.262-155.693 59.266-214.961 0-59.264-59.265-59.264-155.696 0-214.96l44.675-44.675c4.686-4.686 12.284-4.686 16.971 0l39.598 39.598c4.686 4.686 4.686 12.284 0 16.971l-44.675 44.674c-28.072 28.073-28.072 73.75 0 101.823 28.072 28.072 73.75 28.073 101.824 0l44.674-44.674c4.686-4.686 12.284-4.686 16.971 0l39.597 39.598zm-56.568-260.216c4.686 4.686 12.284 4.686 16.971 0l44.674-44.674c28.072-28.075 73.75-28.073 101.824 0 28.072 28.073 28.072 73.75 0 101.823l-44.675 44.674c-4.686 4.686-4.686 12.284 0 16.971l39.598 39.598c4.686 4.686 12.284 4.686 16.971 0l44.675-44.675c59.265-59.265 59.265-155.695 0-214.96-59.266-59.264-155.695-59.264-214.961 0l-44.674 44.674c-4.686 4.686-4.686 12.284 0 16.971l39.597 39.598zm234.828 359.28l22.627-22.627c9.373-9.373 9.373-24.569 0-33.941L63.598 7.029c-9.373-9.373-24.569-9.373-33.941 0L7.029 29.657c-9.373 9.373-9.373 24.569 0 33.941l441.373 441.373c9.373 9.372 24.569 9.372 33.941 0z"></path></svg>'}</span>
|
|
2176
2176
|
<span t-if="!env.getters.isReadonly()" class="o-link-icon o-edit-link" t-on-click="edit" title="${Tc}">${'<svg class="o-icon" viewBox="0 0 576 512"><path fill="currentColor" d="M402.6 83.2l90.2 90.2c3.8 3.8 3.8 10 0 13.8L274.4 405.6l-92.8 10.3c-12.4 1.4-22.9-9.1-21.5-21.5l10.3-92.8L388.8 83.2c3.8-3.8 10-3.8 13.8 0zm162-22.9l-48.8-48.8c-15.2-15.2-39.9-15.2-55.2 0l-35.4 35.4c-3.8 3.8-3.8 10 0 13.8l90.2 90.2c3.8 3.8 10 3.8 13.8 0l35.4-35.4c15.2-15.3 15.2-40 0-55.2zM384 346.2V448H64V128h229.8c3.2 0 6.2-1.3 8.5-3.5l40-40c7.6-7.6 2.2-20.5-8.5-20.5H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V306.2c0-10.7-12.9-16-20.5-8.5l-40 40c-2.2 2.3-3.5 5.3-3.5 8.5z"></path></svg>'}</span>
|
|
2177
2177
|
</div>
|
|
2178
|
-
`,_g=
|
|
2178
|
+
`,_g=Ag`
|
|
2179
2179
|
.o-link-tool {
|
|
2180
2180
|
font-size: 13px;
|
|
2181
2181
|
background-color: white;
|
|
@@ -2212,7 +2212,7 @@
|
|
|
2212
2212
|
cursor: pointer;
|
|
2213
2213
|
color: #000;
|
|
2214
2214
|
}
|
|
2215
|
-
`;class Og extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters}get cell(){const{col:e,row:t}=this.props.cellPosition,s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);if(null==i?void 0:i.isLink())return i;throw new Error(`LinkDisplay Component can only be used with link cells. ${is(e,t)} is not a link.`)}openLink(){this.cell.action(this.env)}edit(){this.env.openLinkEditor()}unlink(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getPosition(),[i,o]=this.getters.getMainCell(e,t,s),n=this.cell.style,r=(null==n?void 0:n.textColor)===
|
|
2215
|
+
`;class Og extends t.Component{constructor(){super(...arguments),this.getters=this.env.getters}get cell(){const{col:e,row:t}=this.props.cellPosition,s=this.getters.getActiveSheetId(),i=this.getters.getCell(s,e,t);if(null==i?void 0:i.isLink())return i;throw new Error(`LinkDisplay Component can only be used with link cells. ${is(e,t)} is not a link.`)}openLink(){this.cell.action(this.env)}edit(){this.env.openLinkEditor()}unlink(){const e=this.getters.getActiveSheetId(),[t,s]=this.getters.getPosition(),[i,o]=this.getters.getMainCell(e,t,s),n=this.cell.style,r=(null==n?void 0:n.textColor)===A||null==n?void 0:n.textColor;this.env.dispatch("UPDATE_CELL",{col:i,row:o,sheetId:e,content:this.cell.link.label,style:{...n,textColor:r,underline:void 0}})}}Og.template=Mg,Og.components={Menu:qu},Og.style=_g;const{xml:Ng,css:kg}=t.tags,{useRef:Fg}=t.hooks,$g=Ng`
|
|
2216
2216
|
<div class="o-link-editor" t-on-click.stop="menu.isOpen=false" t-on-keydown.stop="onKeyDown">
|
|
2217
2217
|
<div class="o-section">
|
|
2218
2218
|
<div t-esc="env._t('${Cc}')" class="o-section-title"/>
|
|
@@ -2593,20 +2593,20 @@
|
|
|
2593
2593
|
&.vertical {
|
|
2594
2594
|
right: 0;
|
|
2595
2595
|
top: ${f}px;
|
|
2596
|
-
bottom: ${
|
|
2597
|
-
width: ${
|
|
2596
|
+
bottom: ${b}px;
|
|
2597
|
+
width: ${b}px;
|
|
2598
2598
|
overflow-x: hidden;
|
|
2599
2599
|
}
|
|
2600
2600
|
&.horizontal {
|
|
2601
2601
|
bottom: 0;
|
|
2602
|
-
height: ${
|
|
2602
|
+
height: ${b}px;
|
|
2603
2603
|
right: ${16}px;
|
|
2604
2604
|
left: ${m}px;
|
|
2605
2605
|
overflow-y: hidden;
|
|
2606
2606
|
}
|
|
2607
2607
|
}
|
|
2608
2608
|
}
|
|
2609
|
-
`;class of extends t.Component{constructor(){super(...arguments),this.menuState=Qg({isOpen:!1,position:null,menuItems:[]}),this.vScrollbarRef=Yg("vscrollbar"),this.hScrollbarRef=Yg("hscrollbar"),this.canvas=Yg("canvas"),this.hiddenInput=Yg("hiddenInput"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.currentSheet=this.getters.getActiveSheetId(),this.clickedCol=0,this.clickedRow=0,this.hoveredCell=ef(this.env,(()=>this.getters.getActiveSnappedViewport())),this.keyDownMapping={ENTER:()=>{const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")},TAB:()=>this.dispatch("MOVE_POSITION",{deltaX:1,deltaY:0}),"SHIFT+TAB":()=>this.dispatch("MOVE_POSITION",{deltaX:-1,deltaY:0}),F2:()=>{const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")},DELETE:()=>{this.dispatch("DELETE_CONTENT",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones()})},"CTRL+A":()=>this.dispatch("SELECT_ALL"),"CTRL+S":()=>{this.trigger("save-requested")},"CTRL+Z":()=>this.dispatch("REQUEST_UNDO"),"CTRL+Y":()=>this.dispatch("REQUEST_REDO"),"CTRL+B":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{bold:!this.getters.getCurrentStyle().bold}}),"CTRL+I":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{italic:!this.getters.getCurrentStyle().italic}}),"CTRL+U":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{underline:!this.getters.getCurrentStyle().underline}}),"ALT+=":()=>{var e;const t=this.getters.getActiveSheetId(),s=this.getters.getSelectedZone(),i=this.getters.getAutomaticSums(t,s,this.getters.getPosition());if(this.getters.isSingleCellOrMerge(t,s)||this.getters.isEmpty(t,s)&&i.length<=1){const s=(null===(e=i[0])||void 0===e?void 0:e.zone)?this.getters.zoneToXC(t,i[0].zone):"",o=`=SUM(${s})`;this.trigger("composer-cell-focused",{content:o,selection:{start:5,end:5+s.length}})}else this.dispatch("SUM_SELECTION")},"CTRL+HOME":()=>{const e=this.getters.getActiveSheet(),[t,s]=ni(e,0,0);this.dispatch("SELECT_CELL",{col:t,row:s})},"CTRL+END":()=>{const e=this.getters.getActiveSheet(),t=ri(e,"cols",fs(0,e.cols.length).reverse()),s=ri(e,"rows",fs(0,e.rows.length).reverse());this.dispatch("SELECT_CELL",{col:t,row:s})},"SHIFT+ ":()=>{const{cols:e}=this.getters.getActiveSheet(),t={...this.getters.getSelectedZone(),left:0,right:e.length-1};this.dispatch("SET_SELECTION",{anchor:this.getters.getPosition(),zones:[t],anchorZone:t})},"CTRL+ ":()=>{const{rows:e}=this.getters.getActiveSheet(),t={...this.getters.getSelectedZone(),top:0,bottom:e.length-1};this.dispatch("SET_SELECTION",{anchor:this.getters.getPosition(),zones:[t],anchorZone:t})},"CTRL+SHIFT+ ":()=>{this.dispatch("SELECT_ALL")},"SHIFT+PAGEDOWN":()=>{this.dispatch("ACTIVATE_NEXT_SHEET")},"SHIFT+PAGEUP":()=>{this.dispatch("ACTIVATE_PREVIOUS_SHEET")}},this.vScrollbar=new Wg(this.vScrollbarRef.el,"vertical"),this.hScrollbar=new Wg(this.hScrollbarRef.el,"horizontal"),function(e,t){const s=Yg("canvas");let i=null,o=null;function n(e){1===e.touches.length&&(i=e.touches[0].clientX,o=e.touches[0].clientY)}function r(){i=null,o=null}function a(s){if(1!==s.touches.length)return;t()&&(s.preventDefault(),s.stopPropagation());const n=s.touches[0].clientX,r=s.touches[0].clientY;e(i-n,o-r),i=n,o=r}Xg((()=>{s.el.addEventListener("touchstart",n),s.el.addEventListener("touchend",r),s.el.addEventListener("touchmove",a)})),Kg((()=>{s.el.removeEventListener("touchstart",n),s.el.removeEventListener("touchend",r),s.el.removeEventListener("touchmove",a)}))}(this.moveCanvas.bind(this),(()=>this.vScrollbar.scroll>0)),this.props.exposeFocus((()=>this.focus()))}get errorTooltip(){const{col:e,row:t}=this.hoveredCell;if(void 0===e||void 0===t)return{isOpen:!1};const s=this.getters.getActiveSheetId(),[i,o]=this.getters.getMainCell(s,e,t),n=this.getters.getCell(s,i,o);if(n&&n.evaluated.type===ke.error){const s=this.getters.getActiveSnappedViewport(),[i,o,r]=this.getters.getRect({left:e,top:t,right:e,bottom:t},s);return{isOpen:!0,position:{x:i+r,y:o+v},text:n.evaluated.error,cellWidth:r}}return{isOpen:!1}}get activeCellPosition(){const[e,t]=this.getters.getMainCell(this.getters.getActiveSheetId(),...this.getters.getPosition());return{col:e,row:t}}get shouldDisplayLink(){const e=this.getters.getActiveSheetId(),{col:t,row:s}=this.activeCellPosition,i=this.getters.getActiveSnappedViewport(),o=this.getters.getCell(e,t,s);return this.getters.isVisibleInViewport(t,s,i)&&!!o&&o.isLink()&&!this.menuState.isOpen&&!this.props.linkEditorIsOpen&&!this.props.sidePanelIsOpen}get popoverPosition(){const[e,t]=this.getters.getBottomLeftCell(this.getters.getActiveSheetId(),...this.getters.getPosition()),s=this.getters.getActiveSnappedViewport(),[i,o,n,r]=this.getters.getRect({left:e,top:t,right:e,bottom:t},s);return{position:{x:i,y:o+r+v},cellWidth:n,cellHeight:r}}mounted(){this.vScrollbar.el=this.vScrollbarRef.el,this.hScrollbar.el=this.hScrollbarRef.el,this.focus(),this.resizeGrid(),this.drawGrid()}patched(){this.resizeGrid(),this.drawGrid()}focus(){this.getters.isSelectingForComposer()||this.getters.getSelectedFigureId()||this.hiddenInput.el.focus()}resizeGrid(){const e=this.el.clientHeight-S,t=this.el.clientWidth-S,{height:s,width:i}=this.getters.getViewportDimension();e==s&&t===i||this.dispatch("RESIZE_VIEWPORT",{height:e,width:t})}onScroll(){const{offsetX:e,offsetY:t}=this.getters.getActiveViewport();if(e!==this.hScrollbar.scroll||t!==this.vScrollbar.scroll){const{maxOffsetX:e,maxOffsetY:t}=this.getters.getMaximumViewportOffset(this.getters.getActiveSheet());this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:Math.min(this.hScrollbar.scroll,e),offsetY:Math.min(this.vScrollbar.scroll,t)})}}checkSheetChanges(){const e=this.getters.getActiveSheetId();e!==this.currentSheet&&(this.focus(),this.currentSheet=e)}getAutofillPosition(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheet(),{offsetX:s,offsetY:i}=this.getters.getActiveSnappedViewport();return{left:t.cols[e.right].end-4+m-s,top:t.rows[e.bottom].end-4+f-i}}drawGrid(){const{offsetX:e,offsetY:t}=this.getters.getActiveViewport();this.hScrollbar.scroll=e,this.vScrollbar.scroll=t,this.checkSheetChanges();const s=this.canvas.el,i=window.devicePixelRatio||1,o=s.getContext("2d",{alpha:!1}),n=.4*i,r={ctx:o,viewport:this.getters.getActiveViewport(),dpr:i,thinLineWidth:n},{width:a,height:l}=this.getters.getViewportDimension();s.style.width=`${a}px`,s.style.height=`${l}px`,s.width=a*i,s.height=l*i,s.setAttribute("style",`width:${a}px;height:${l}px;`),o.translate(-.5,-.5),o.scale(i,i),this.props.model.drawGrid(r)}moveCanvas(e,t){this.vScrollbar.scroll=this.vScrollbar.scroll+t,this.hScrollbar.scroll=this.hScrollbar.scroll+e,this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:this.hScrollbar.scroll,offsetY:this.vScrollbar.scroll})}getClientPositionKey(e){var t,s,i;return`${e.id}-${null===(t=e.position)||void 0===t?void 0:t.sheetId}-${null===(s=e.position)||void 0===s?void 0:s.col}-${null===(i=e.position)||void 0===i?void 0:i.row}`}onMouseWheel(e){if(e.ctrlKey)return;function t(t){return t*(0===e.deltaMode?1:b)}const s=e.shiftKey?e.deltaY:e.deltaX,i=e.shiftKey?e.deltaX:e.deltaY;this.moveCanvas(t(s),t(i))}isCellHovered(e,t){return this.hoveredCell.col===e&&this.hoveredCell.row===t}getCoordinates(e){const t=this.el.getBoundingClientRect();return[e.pageX-t.left,e.pageY-t.top]}getCartesianCoordinates(e){const[t,s]=this.getCoordinates(e),{left:i,top:o}=this.getters.getActiveSnappedViewport();return[this.getters.getColIndex(t,i),this.getters.getRowIndex(s,o)]}onMouseDown(e){if(e.button>0)return;const[t,s]=this.getCartesianCoordinates(e);if(t<0||s<0)return;this.clickedCol=t,this.clickedRow=s;const i=this.getters.getActiveSheetId(),[o,n]=this.getters.getMainCell(i,t,s),r=this.getters.getCell(i,o,n);(null==r?void 0:r.isLink())||this.closeLinkEditor(),this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this.dispatch("ALTER_SELECTION",{cell:[t,s]}):(this.dispatch("SELECT_CELL",{col:t,row:s}),this.checkSheetChanges());let a,l=t,c=s,h=!1,d=null,u=0;const p=this.getters.getActiveSheet(),g=e=>{if(a=e,d)return;const[t,s]=this.getCoordinates(a);h=!1,u=0;const i=this.getters.getEdgeScrollCol(t),o=this.getters.getEdgeScrollRow(s),{left:n,right:r,top:f,bottom:m}=this.getters.getActiveSnappedViewport();let v,E;if(i.canEdgeScroll?v=i.direction>0?r:n-1:(v=this.getters.getColIndex(t,n),v=-1===v?l:v),o.canEdgeScroll?E=o.direction>0?m:f-1:(E=this.getters.getRowIndex(s,f),E=-1===E?c:E),h=i.canEdgeScroll||o.canEdgeScroll,u=Math.min(i.canEdgeScroll?i.delay:os,o.canEdgeScroll?o.delay:os),v===l&&E===c||(l=v,c=E,this.dispatch("ALTER_SELECTION",{cell:[v,E]})),h){const e=p.cols[n+i.direction].start,t=p.rows[f+o.direction].start;this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:e,offsetY:t}),d=setTimeout((()=>{d=null,g(a)}),Math.round(u))}};ep(g,(e=>{clearTimeout(d),this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION"),this.canvas.el.removeEventListener("mousemove",g),this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}))}onDoubleClick(e){const[t,s]=this.getCartesianCoordinates(e);if(this.clickedCol===t&&this.clickedRow===s){const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")}}closeLinkEditor(){this.trigger("link-editor-closed")}processTabKey(e){e.preventDefault();const t=e.shiftKey?-1:1;this.dispatch("MOVE_POSITION",{deltaX:t,deltaY:0})}processArrows(e){e.preventDefault(),e.stopPropagation(),this.closeLinkEditor();const t={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}[e.key];if(e.shiftKey){const e=this.getters.getSelectedZone();this.dispatch("ALTER_SELECTION",{delta:t});const s=this.getters.getSelectedZone(),i=this.getters.getActiveSnappedViewport(),o=this.getters.getActiveSheet(),[n,r]=function(e,t,s){let i,o;const{left:n,right:r,top:a,bottom:l}=e,{left:c,right:h,top:d,bottom:u}=t;return i=c!=n?c:h!=r?h:s.left,o=d!=a?d:u!=l?u:s.top,[i,o]}(e,s,i),{left:a,right:l,top:c,bottom:h,offsetX:d,offsetY:u}=i,p=n<a||n>l-1?o.cols[a+t[0]].start:d,g=r<c||r>h-1?o.rows[c+t[1]].start:u;p===d&&g===u||this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:p,offsetY:g})}else this.dispatch("MOVE_POSITION",{deltaX:t[0],deltaY:t[1]});this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}onInput(e){(e.isComposing||"insertFromPaste"!==e.inputType)&&e.data&&(e.preventDefault(),e.stopPropagation(),this.trigger("composer-cell-focused",{content:e.data}))}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";e.ctrlKey&&(t+="CTRL+"),e.metaKey&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];return s?(e.preventDefault(),e.stopPropagation(),void s()):void 0}onInputContextMenu(e){e.preventDefault();const t=this.getters.getSelectedZone(),{left:s,top:i}=t;let o="CELL";this.dispatch("STOP_EDITION"),this.getters.getActiveCols().has(s)?o="COL":this.getters.getActiveRows().has(i)&&(o="ROW");const[n,r,a,l]=this.getters.getRect(t,this.getters.getActiveSnappedViewport());this.toggleContextMenu(o,n+a,r+l)}onCanvasContextMenu(e){e.preventDefault();const[t,s]=this.getCartesianCoordinates(e);if(t<0||s<0)return;const i=this.getters.getSelectedZones();let o="CELL";Hs(t,s,i[i.length-1])?this.getters.getActiveCols().has(t)?o="COL":this.getters.getActiveRows().has(s)&&(o="ROW"):(this.dispatch("STOP_EDITION"),this.dispatch("SELECT_CELL",{col:t,row:s})),this.toggleContextMenu(o,e.offsetX,e.offsetY)}onOverlayContextMenu(e){const t=e.detail.type,s=e.detail.x,i=e.detail.y;this.toggleContextMenu(t,s,i)}toggleContextMenu(e,t,s){this.closeLinkEditor(),this.menuState.isOpen=!0,this.menuState.position={x:t,y:s+v},this.menuState.menuItems=Jg[e].getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}closeMenu(){this.menuState.isOpen=!1,this.focus()}}of.template=tf,of.style=sf,of.components={GridComposer:Xp,Overlay:Gg,Menu:qu,Autofill:ap,FiguresContainer:gg,ClientTag:pp,Highlight:Rg,ErrorToolTip:tg,LinkDisplay:Og,LinkEditor:Ug,Popover:Bu};const{xml:nf,css:rf}=t.tags,{useState:af}=t.hooks,lf=nf`
|
|
2609
|
+
`;class of extends t.Component{constructor(){super(...arguments),this.menuState=Qg({isOpen:!1,position:null,menuItems:[]}),this.vScrollbarRef=Yg("vscrollbar"),this.hScrollbarRef=Yg("hscrollbar"),this.canvas=Yg("canvas"),this.hiddenInput=Yg("hiddenInput"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.currentSheet=this.getters.getActiveSheetId(),this.clickedCol=0,this.clickedRow=0,this.hoveredCell=ef(this.env,(()=>this.getters.getActiveSnappedViewport())),this.keyDownMapping={ENTER:()=>{const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")},TAB:()=>this.dispatch("MOVE_POSITION",{deltaX:1,deltaY:0}),"SHIFT+TAB":()=>this.dispatch("MOVE_POSITION",{deltaX:-1,deltaY:0}),F2:()=>{const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")},DELETE:()=>{this.dispatch("DELETE_CONTENT",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones()})},"CTRL+A":()=>this.dispatch("SELECT_ALL"),"CTRL+S":()=>{this.trigger("save-requested")},"CTRL+Z":()=>this.dispatch("REQUEST_UNDO"),"CTRL+Y":()=>this.dispatch("REQUEST_REDO"),"CTRL+B":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{bold:!this.getters.getCurrentStyle().bold}}),"CTRL+I":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{italic:!this.getters.getCurrentStyle().italic}}),"CTRL+U":()=>this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),style:{underline:!this.getters.getCurrentStyle().underline}}),"ALT+=":()=>{var e;const t=this.getters.getActiveSheetId(),s=this.getters.getSelectedZone(),i=this.getters.getAutomaticSums(t,s,this.getters.getPosition());if(this.getters.isSingleCellOrMerge(t,s)||this.getters.isEmpty(t,s)&&i.length<=1){const s=(null===(e=i[0])||void 0===e?void 0:e.zone)?this.getters.zoneToXC(t,i[0].zone):"",o=`=SUM(${s})`;this.trigger("composer-cell-focused",{content:o,selection:{start:5,end:5+s.length}})}else this.dispatch("SUM_SELECTION")},"CTRL+HOME":()=>{const e=this.getters.getActiveSheet(),[t,s]=ni(e,0,0);this.dispatch("SELECT_CELL",{col:t,row:s})},"CTRL+END":()=>{const e=this.getters.getActiveSheet(),t=ri(e,"cols",fs(0,e.cols.length).reverse()),s=ri(e,"rows",fs(0,e.rows.length).reverse());this.dispatch("SELECT_CELL",{col:t,row:s})},"SHIFT+ ":()=>{const{cols:e}=this.getters.getActiveSheet(),t={...this.getters.getSelectedZone(),left:0,right:e.length-1};this.dispatch("SET_SELECTION",{anchor:this.getters.getPosition(),zones:[t],anchorZone:t})},"CTRL+ ":()=>{const{rows:e}=this.getters.getActiveSheet(),t={...this.getters.getSelectedZone(),top:0,bottom:e.length-1};this.dispatch("SET_SELECTION",{anchor:this.getters.getPosition(),zones:[t],anchorZone:t})},"CTRL+SHIFT+ ":()=>{this.dispatch("SELECT_ALL")},"SHIFT+PAGEDOWN":()=>{this.dispatch("ACTIVATE_NEXT_SHEET")},"SHIFT+PAGEUP":()=>{this.dispatch("ACTIVATE_PREVIOUS_SHEET")}},this.vScrollbar=new Wg(this.vScrollbarRef.el,"vertical"),this.hScrollbar=new Wg(this.hScrollbarRef.el,"horizontal"),function(e,t){const s=Yg("canvas");let i=null,o=null;function n(e){1===e.touches.length&&(i=e.touches[0].clientX,o=e.touches[0].clientY)}function r(){i=null,o=null}function a(s){if(1!==s.touches.length)return;t()&&(s.preventDefault(),s.stopPropagation());const n=s.touches[0].clientX,r=s.touches[0].clientY;e(i-n,o-r),i=n,o=r}Xg((()=>{s.el.addEventListener("touchstart",n),s.el.addEventListener("touchend",r),s.el.addEventListener("touchmove",a)})),Kg((()=>{s.el.removeEventListener("touchstart",n),s.el.removeEventListener("touchend",r),s.el.removeEventListener("touchmove",a)}))}(this.moveCanvas.bind(this),(()=>this.vScrollbar.scroll>0)),this.props.exposeFocus((()=>this.focus()))}get errorTooltip(){const{col:e,row:t}=this.hoveredCell;if(void 0===e||void 0===t)return{isOpen:!1};const s=this.getters.getActiveSheetId(),[i,o]=this.getters.getMainCell(s,e,t),n=this.getters.getCell(s,i,o);if(n&&n.evaluated.type===ke.error){const s=this.getters.getActiveSnappedViewport(),[i,o,r]=this.getters.getRect({left:e,top:t,right:e,bottom:t},s);return{isOpen:!0,position:{x:i+r,y:o+v},text:n.evaluated.error,cellWidth:r}}return{isOpen:!1}}get activeCellPosition(){const[e,t]=this.getters.getMainCell(this.getters.getActiveSheetId(),...this.getters.getPosition());return{col:e,row:t}}get shouldDisplayLink(){const e=this.getters.getActiveSheetId(),{col:t,row:s}=this.activeCellPosition,i=this.getters.getActiveSnappedViewport(),o=this.getters.getCell(e,t,s);return this.getters.isVisibleInViewport(t,s,i)&&!!o&&o.isLink()&&!this.menuState.isOpen&&!this.props.linkEditorIsOpen&&!this.props.sidePanelIsOpen}get popoverPosition(){const[e,t]=this.getters.getBottomLeftCell(this.getters.getActiveSheetId(),...this.getters.getPosition()),s=this.getters.getActiveSnappedViewport(),[i,o,n,r]=this.getters.getRect({left:e,top:t,right:e,bottom:t},s);return{position:{x:i,y:o+r+v},cellWidth:n,cellHeight:r}}mounted(){this.vScrollbar.el=this.vScrollbarRef.el,this.hScrollbar.el=this.hScrollbarRef.el,this.focus(),this.resizeGrid(),this.drawGrid()}patched(){this.resizeGrid(),this.drawGrid()}focus(){this.getters.isSelectingForComposer()||this.getters.getSelectedFigureId()||this.hiddenInput.el.focus()}resizeGrid(){const e=this.el.clientHeight-b,t=this.el.clientWidth-b,{height:s,width:i}=this.getters.getViewportDimension();e==s&&t===i||this.dispatch("RESIZE_VIEWPORT",{height:e,width:t})}onScroll(){const{offsetX:e,offsetY:t}=this.getters.getActiveViewport();if(e!==this.hScrollbar.scroll||t!==this.vScrollbar.scroll){const{maxOffsetX:e,maxOffsetY:t}=this.getters.getMaximumViewportOffset(this.getters.getActiveSheet());this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:Math.min(this.hScrollbar.scroll,e),offsetY:Math.min(this.vScrollbar.scroll,t)})}}checkSheetChanges(){const e=this.getters.getActiveSheetId();e!==this.currentSheet&&(this.focus(),this.currentSheet=e)}getAutofillPosition(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheet(),{offsetX:s,offsetY:i}=this.getters.getActiveSnappedViewport();return{left:t.cols[e.right].end-4+m-s,top:t.rows[e.bottom].end-4+f-i}}drawGrid(){const{offsetX:e,offsetY:t}=this.getters.getActiveViewport();this.hScrollbar.scroll=e,this.vScrollbar.scroll=t,this.checkSheetChanges();const s=this.canvas.el,i=window.devicePixelRatio||1,o=s.getContext("2d",{alpha:!1}),n=.4*i,r={ctx:o,viewport:this.getters.getActiveViewport(),dpr:i,thinLineWidth:n},{width:a,height:l}=this.getters.getViewportDimension();s.style.width=`${a}px`,s.style.height=`${l}px`,s.width=a*i,s.height=l*i,s.setAttribute("style",`width:${a}px;height:${l}px;`),o.translate(-.5,-.5),o.scale(i,i),this.props.model.drawGrid(r)}moveCanvas(e,t){this.vScrollbar.scroll=this.vScrollbar.scroll+t,this.hScrollbar.scroll=this.hScrollbar.scroll+e,this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:this.hScrollbar.scroll,offsetY:this.vScrollbar.scroll})}getClientPositionKey(e){var t,s,i;return`${e.id}-${null===(t=e.position)||void 0===t?void 0:t.sheetId}-${null===(s=e.position)||void 0===s?void 0:s.col}-${null===(i=e.position)||void 0===i?void 0:i.row}`}onMouseWheel(e){if(e.ctrlKey)return;function t(t){return t*(0===e.deltaMode?1:S)}const s=e.shiftKey?e.deltaY:e.deltaX,i=e.shiftKey?e.deltaX:e.deltaY;this.moveCanvas(t(s),t(i))}isCellHovered(e,t){return this.hoveredCell.col===e&&this.hoveredCell.row===t}getCoordinates(e){const t=this.el.getBoundingClientRect();return[e.pageX-t.left,e.pageY-t.top]}getCartesianCoordinates(e){const[t,s]=this.getCoordinates(e),{left:i,top:o}=this.getters.getActiveSnappedViewport();return[this.getters.getColIndex(t,i),this.getters.getRowIndex(s,o)]}onMouseDown(e){if(e.button>0)return;const[t,s]=this.getCartesianCoordinates(e);if(t<0||s<0)return;this.clickedCol=t,this.clickedRow=s;const i=this.getters.getActiveSheetId(),[o,n]=this.getters.getMainCell(i,t,s),r=this.getters.getCell(i,o,n);(null==r?void 0:r.isLink())||this.closeLinkEditor(),this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this.dispatch("ALTER_SELECTION",{cell:[t,s]}):(this.dispatch("SELECT_CELL",{col:t,row:s}),this.checkSheetChanges());let a,l=t,c=s,h=!1,d=null,u=0;const p=this.getters.getActiveSheet(),g=e=>{if(a=e,d)return;const[t,s]=this.getCoordinates(a);h=!1,u=0;const i=this.getters.getEdgeScrollCol(t),o=this.getters.getEdgeScrollRow(s),{left:n,right:r,top:f,bottom:m}=this.getters.getActiveSnappedViewport();let v,E;if(i.canEdgeScroll?v=i.direction>0?r:n-1:(v=this.getters.getColIndex(t,n),v=-1===v?l:v),o.canEdgeScroll?E=o.direction>0?m:f-1:(E=this.getters.getRowIndex(s,f),E=-1===E?c:E),h=i.canEdgeScroll||o.canEdgeScroll,u=Math.min(i.canEdgeScroll?i.delay:os,o.canEdgeScroll?o.delay:os),v===l&&E===c||(l=v,c=E,this.dispatch("ALTER_SELECTION",{cell:[v,E]})),h){const e=p.cols[n+i.direction].start,t=p.rows[f+o.direction].start;this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:e,offsetY:t}),d=setTimeout((()=>{d=null,g(a)}),Math.round(u))}};ep(g,(e=>{clearTimeout(d),this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION"),this.canvas.el.removeEventListener("mousemove",g),this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}))}onDoubleClick(e){const[t,s]=this.getCartesianCoordinates(e);if(this.clickedCol===t&&this.clickedRow===s){const e=this.getters.getActiveCell();!e||e.isEmpty()?this.trigger("composer-cell-focused"):this.trigger("composer-content-focused")}}closeLinkEditor(){this.trigger("link-editor-closed")}processTabKey(e){e.preventDefault();const t=e.shiftKey?-1:1;this.dispatch("MOVE_POSITION",{deltaX:t,deltaY:0})}processArrows(e){e.preventDefault(),e.stopPropagation(),this.closeLinkEditor();const t={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}[e.key];if(e.shiftKey){const e=this.getters.getSelectedZone();this.dispatch("ALTER_SELECTION",{delta:t});const s=this.getters.getSelectedZone(),i=this.getters.getActiveSnappedViewport(),o=this.getters.getActiveSheet(),[n,r]=function(e,t,s){let i,o;const{left:n,right:r,top:a,bottom:l}=e,{left:c,right:h,top:d,bottom:u}=t;return i=c!=n?c:h!=r?h:s.left,o=d!=a?d:u!=l?u:s.top,[i,o]}(e,s,i),{left:a,right:l,top:c,bottom:h,offsetX:d,offsetY:u}=i,p=n<a||n>l-1?o.cols[a+t[0]].start:d,g=r<c||r>h-1?o.rows[c+t[1]].start:u;p===d&&g===u||this.dispatch("SET_VIEWPORT_OFFSET",{offsetX:p,offsetY:g})}else this.dispatch("MOVE_POSITION",{deltaX:t[0],deltaY:t[1]});this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}onInput(e){(e.isComposing||"insertFromPaste"!==e.inputType)&&e.data&&(e.preventDefault(),e.stopPropagation(),this.trigger("composer-cell-focused",{content:e.data}))}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";e.ctrlKey&&(t+="CTRL+"),e.metaKey&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];return s?(e.preventDefault(),e.stopPropagation(),void s()):void 0}onInputContextMenu(e){e.preventDefault();const t=this.getters.getSelectedZone(),{left:s,top:i}=t;let o="CELL";this.dispatch("STOP_EDITION"),this.getters.getActiveCols().has(s)?o="COL":this.getters.getActiveRows().has(i)&&(o="ROW");const[n,r,a,l]=this.getters.getRect(t,this.getters.getActiveSnappedViewport());this.toggleContextMenu(o,n+a,r+l)}onCanvasContextMenu(e){e.preventDefault();const[t,s]=this.getCartesianCoordinates(e);if(t<0||s<0)return;const i=this.getters.getSelectedZones();let o="CELL";Hs(t,s,i[i.length-1])?this.getters.getActiveCols().has(t)?o="COL":this.getters.getActiveRows().has(s)&&(o="ROW"):(this.dispatch("STOP_EDITION"),this.dispatch("SELECT_CELL",{col:t,row:s})),this.toggleContextMenu(o,e.offsetX,e.offsetY)}onOverlayContextMenu(e){const t=e.detail.type,s=e.detail.x,i=e.detail.y;this.toggleContextMenu(t,s,i)}toggleContextMenu(e,t,s){this.closeLinkEditor(),this.menuState.isOpen=!0,this.menuState.position={x:t,y:s+v},this.menuState.menuItems=Jg[e].getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}closeMenu(){this.menuState.isOpen=!1,this.focus()}}of.template=tf,of.style=sf,of.components={GridComposer:Xp,Overlay:Gg,Menu:qu,Autofill:ap,FiguresContainer:gg,ClientTag:pp,Highlight:Rg,ErrorToolTip:tg,LinkDisplay:Og,LinkEditor:Ug,Popover:Bu};const{xml:nf,css:rf}=t.tags,{useState:af}=t.hooks,lf=nf`
|
|
2610
2610
|
<div class="o-sidePanel" >
|
|
2611
2611
|
<div class="o-sidePanelHeader">
|
|
2612
2612
|
<div class="o-sidePanelTitle" t-esc="getTitle()"/>
|
|
@@ -2717,7 +2717,7 @@
|
|
|
2717
2717
|
text-align: left;
|
|
2718
2718
|
}
|
|
2719
2719
|
}
|
|
2720
|
-
`;class hf extends t.Component{constructor(){super(...arguments),this.state=af({panel:Eh.get(this.props.component)})}async willUpdateProps(e){this.state.panel=Eh.get(e.component)}getTitle(){return"function"==typeof this.state.panel.title?this.state.panel.title(this.env):this.state.panel.title}}hf.template=lf,hf.style=cf;const{xml:df,css:uf}=t.tags,{useExternalListener:pf,useRef:gf}=t.hooks,ff=a("Undo"),mf=a("Redo"),vf=a("Paint Format"),Ef=a("Clear Format"),
|
|
2720
|
+
`;class hf extends t.Component{constructor(){super(...arguments),this.state=af({panel:Eh.get(this.props.component)})}async willUpdateProps(e){this.state.panel=Eh.get(e.component)}getTitle(){return"function"==typeof this.state.panel.title?this.state.panel.title(this.env):this.state.panel.title}}hf.template=lf,hf.style=cf;const{xml:df,css:uf}=t.tags,{useExternalListener:pf,useRef:gf}=t.hooks,ff=a("Undo"),mf=a("Redo"),vf=a("Paint Format"),Ef=a("Clear Format"),Sf=a("Format as percent"),bf=a("Decrease decimal places"),Cf=a("Increase decimal places"),If=a("More formats"),yf=a("Font Size"),wf=a("Bold"),Tf=a("Italic"),xf=a("Strikethrough"),Rf=a("Text Color"),Lf=a("Fill Color"),Af=a("Borders"),Mf=a("Merge Cells"),_f=a("Horizontal align"),Of=[{name:"general",text:a("General (no specific format)")},{name:"number",text:a("Number (1,000.12)"),value:"#,##0.00"},{name:"percent",text:a("Percent (10.12%)"),value:"0.00%"},{name:"date",text:a("Date (9/26/2008)"),value:"m/d/yyyy"},{name:"time",text:a("Time (10:43:00 PM)"),value:"hh:mm:ss a"},{name:"datetime",text:a("Date time (9/26/2008 22:43:00)"),value:"m/d/yyyy hh:mm:ss"},{name:"duration",text:a("Duration (27:51:38)"),value:"hhhh:mm:ss"}];class Nf extends t.Component{constructor(){super(...arguments),this.formats=Of,this.currentFormat="general",this.fontSizes=ls,this.dispatch=this.env.dispatch,this.getters=this.env.getters,this.style={},this.state=t.useState({menuState:{isOpen:!1,position:null,menuItems:[]},activeTool:""}),this.isSelectingMenu=!1,this.openedEl=null,this.inMerge=!1,this.cannotMerge=!1,this.undoTool=!1,this.redoTool=!1,this.paintFormatTool=!1,this.fillColor="white",this.textColor="black",this.menus=[],this.menuRef=gf("menuRef"),this.composerStyle="\n line-height: 34px;\n padding-left: 8px;\n height: 34px;\n background-color: white;\n ",pf(window,"click",this.onClick)}get topbarComponents(){return Sh.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}async willStart(){this.updateCellState()}async willUpdateProps(){this.updateCellState()}onClick(e){this.openedEl&&Nc(this.openedEl,e)||this.closeMenus()}toogleStyle(e){Pa(this.env,{[e]:!this.style[e]})}toogleFormat(e){const t=Of.find((t=>t.name===e)),s=t&&t.value||"";Ua(this.env,s)}toggleAlign(e){Pa(this.env,{align:e})}onMenuMouseOver(e,t){this.isSelectingMenu&&this.toggleContextMenu(e,t)}toggleDropdownTool(e,t){const s=this.state.activeTool===e;this.closeMenus(),this.state.activeTool=s?"":e,this.openedEl=s?null:t.target}toggleContextMenu(e,t){this.closeMenus();const s=t.target.offsetLeft,i=t.target.clientHeight+t.target.offsetTop;this.state.menuState.isOpen=!0,this.state.menuState.position={x:s,y:i},this.state.menuState.menuItems=gl.getChildren(e,this.env).filter((e=>!e.isVisible||e.isVisible(this.env))),this.isSelectingMenu=!0,this.openedEl=t.target}closeMenus(){this.state.activeTool="",this.state.menuState.isOpen=!1,this.isSelectingMenu=!1,this.openedEl=null,this.menuRef.comp&&this.menuRef.comp.closeSubMenus()}updateCellState(){this.style=this.getters.getCurrentStyle(),this.fillColor=this.style.fillColor||"white",this.textColor=this.style.textColor||"black";const e=this.getters.getSelectedZones(),{top:t,left:s,right:i,bottom:o}=e[0];if(this.cannotMerge=e.length>1||t===o&&s===i,this.inMerge=!1,!this.cannotMerge){const[t,s]=this.getters.getPosition(),i=this.getters.expandZone(this.getters.getActiveSheetId(),{left:t,right:t,top:s,bottom:s});this.inMerge=Bs(e[0],i)}this.undoTool=this.getters.canUndo(),this.redoTool=this.getters.canRedo(),this.paintFormatTool=this.getters.isPaintingFormat();const n=this.getters.getActiveCell();if(n&&n.format){const e=this.formats.find((e=>e.value===n.format));this.currentFormat=e?e.name:""}else this.currentFormat="general";this.menus=gl.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}getMenuName(e){return gl.getName(e,this.env)}toggleMerge(){const e=this.getters.getSelectedZones(),t=[e[e.length-1]],s=this.getters.getActiveSheetId();this.inMerge?this.dispatch("REMOVE_MERGE",{sheetId:s,target:t}):this.dispatch("ADD_MERGE",{sheetId:s,target:t,interactive:!0})}setColor(e,t){Pa(this.env,{[e]:t.detail.color})}setBorder(e){this.dispatch("SET_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),border:e})}setFormat(e){const t=e.target.dataset.format;t&&this.toogleFormat(t)}setDecimal(e){this.dispatch("SET_DECIMAL",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones(),step:e})}paintFormat(){this.dispatch("ACTIVATE_PAINT_FORMAT",{target:this.getters.getSelectedZones()})}clearFormatting(){this.dispatch("CLEAR_FORMATTING",{sheetId:this.getters.getActiveSheetId(),target:this.getters.getSelectedZones()})}setSize(e){const t=parseFloat(e.target.dataset.size);Pa(this.env,{fontSize:t})}doAction(e){e(this.env),this.closeMenus()}undo(){this.dispatch("REQUEST_UNDO")}redo(){this.dispatch("REQUEST_REDO")}}Nf.template=df`
|
|
2721
2721
|
<div class="o-spreadsheet-topbar">
|
|
2722
2722
|
<div class="o-topbar-top">
|
|
2723
2723
|
<!-- Menus -->
|
|
@@ -2757,8 +2757,8 @@
|
|
|
2757
2757
|
<div class="o-tool" title="${vf}" t-att-class="{active:paintFormatTool}" t-on-click="paintFormat">${'<svg class="o-icon"><path fill="#000000" d="M9,0 L1,0 C0.45,0 0,0.45 0,1 L0,4 C0,4.55 0.45,5 1,5 L9,5 C9.55,5 10,4.55 10,4 L10,3 L11,3 L11,6 L4,6 L4,14 L6,14 L6,8 L13,8 L13,2 L10,2 L10,1 C10,0.45 9.55,0 9,0 Z" transform="translate(3 2)"/></svg>'}</div>
|
|
2758
2758
|
<div class="o-tool" title="${Ef}" t-on-click="clearFormatting()">${'<svg class="o-icon"><path fill="#000000" d="M0.27,1.55 L5.43,6.7 L3,12 L5.5,12 L7.14,8.42 L11.73,13 L13,11.73 L1.55,0.27 L0.27,1.55 L0.27,1.55 Z M3.82,0 L5.82,2 L7.58,2 L7.03,3.21 L8.74,4.92 L10.08,2 L14,2 L14,0 L3.82,0 L3.82,0 Z" transform="translate(2 3)"/></svg>'}</div>
|
|
2759
2759
|
<div class="o-divider"/>
|
|
2760
|
-
<div class="o-tool" title="${
|
|
2761
|
-
<div class="o-tool" title="${
|
|
2760
|
+
<div class="o-tool" title="${Sf}" t-on-click="toogleFormat('percent')">%</div>
|
|
2761
|
+
<div class="o-tool" title="${bf}" t-on-click="setDecimal(-1)">.0</div>
|
|
2762
2762
|
<div class="o-tool" title="${Cf}" t-on-click="setDecimal(+1)">.00</div>
|
|
2763
2763
|
<div class="o-tool o-dropdown" title="${If}" t-on-click="toggleDropdownTool('formatTool')">
|
|
2764
2764
|
<div class="o-text-icon">123${Cl}</div>
|
|
@@ -2791,7 +2791,7 @@
|
|
|
2791
2791
|
<span t-attf-style="border-color:{{fillColor}}">${Rl}</span>
|
|
2792
2792
|
<ColorPicker t-if="state.activeTool === 'fillColorTool'" t-on-color-picked="setColor('fillColor')" t-key="fillColor"/>
|
|
2793
2793
|
</div>
|
|
2794
|
-
<div class="o-tool o-dropdown" t-on-click="toggleDropdownTool('borderTool')" title="${
|
|
2794
|
+
<div class="o-tool o-dropdown" t-on-click="toggleDropdownTool('borderTool')" title="${Af}">
|
|
2795
2795
|
<span>${_l}</span>
|
|
2796
2796
|
<div class="o-dropdown-content o-border" t-if="state.activeTool === 'borderTool'">
|
|
2797
2797
|
<div class="o-dropdown-line">
|
|
@@ -2810,19 +2810,19 @@
|
|
|
2810
2810
|
</div>
|
|
2811
2811
|
</div>
|
|
2812
2812
|
</div>
|
|
2813
|
-
<div class="o-tool" title="${
|
|
2813
|
+
<div class="o-tool" title="${Mf}" t-att-class="{active:inMerge, 'o-disabled': cannotMerge}" t-on-click="toggleMerge">${'<svg class="o-icon"><path fill="#000000" d="M3,6 L1,6 L1,2 L8,2 L8,4 L3,4 L3,6 Z M10,4 L10,2 L17,2 L17,6 L15,6 L15,4 L10,4 Z M10,14 L15,14 L15,12 L17,12 L17,16 L10,16 L10,14 Z M1,12 L3,12 L3,14 L8,14 L8,16 L1,16 L1,12 Z M1,8 L5,8 L5,6 L8,9 L5,12 L5,10 L1,10 L1,8 Z M10,9 L13,6 L13,8 L17,8 L17,10 L13,10 L13,12 L10,9 Z"/></svg>'}</div>
|
|
2814
2814
|
<div class="o-divider"/>
|
|
2815
2815
|
<div class="o-tool o-dropdown" title="${_f}" t-on-click="toggleDropdownTool('alignTool')">
|
|
2816
2816
|
<span>
|
|
2817
|
-
<t t-if="style.align === 'right'">${
|
|
2818
|
-
<t t-elif="style.align === 'center'">${
|
|
2817
|
+
<t t-if="style.align === 'right'">${Ml}</t>
|
|
2818
|
+
<t t-elif="style.align === 'center'">${Al}</t>
|
|
2819
2819
|
<t t-else="">${Ll}</t>
|
|
2820
2820
|
${Cl}
|
|
2821
2821
|
</span>
|
|
2822
2822
|
<div t-if="state.activeTool === 'alignTool'" class="o-dropdown-content">
|
|
2823
2823
|
<div class="o-dropdown-item" t-on-click="toggleAlign('left')">${Ll}</div>
|
|
2824
|
-
<div class="o-dropdown-item" t-on-click="toggleAlign('center')">${
|
|
2825
|
-
<div class="o-dropdown-item" t-on-click="toggleAlign('right')">${
|
|
2824
|
+
<div class="o-dropdown-item" t-on-click="toggleAlign('center')">${Al}</div>
|
|
2825
|
+
<div class="o-dropdown-item" t-on-click="toggleAlign('right')">${Ml}</div>
|
|
2826
2826
|
</div>
|
|
2827
2827
|
</div>
|
|
2828
2828
|
<!-- <div class="o-tool" title="Vertical align"><span>${'<svg class="o-icon"><path fill="#000000" d="M9.5,3 L7,3 L7,0 L5,0 L5,3 L2.5,3 L6,6.5 L9.5,3 L9.5,3 Z M0,8 L0,10 L12,10 L12,8 L0,8 L0,8 Z M2.5,15 L5,15 L5,18 L7,18 L7,15 L9.5,15 L6,11.5 L2.5,15 L2.5,15 Z" transform="translate(3)"/></svg>'}</span> ${Cl}</div> -->
|
|
@@ -3016,7 +3016,7 @@
|
|
|
3016
3016
|
}
|
|
3017
3017
|
}
|
|
3018
3018
|
}
|
|
3019
|
-
`,Nf.components={ColorPicker:
|
|
3019
|
+
`,Nf.components={ColorPicker:bl,Menu:qu,Composer:Zp};const{useExternalListener:kf,useSubEnv:Ff,useRef:$f}=t.hooks,{xml:Df,css:Uf}=t.tags,Pf=Df`
|
|
3020
3020
|
<div class="o-spreadsheet" t-on-save-requested="save" t-on-keydown="onKeydown">
|
|
3021
3021
|
<TopBar
|
|
3022
3022
|
t-on-click="focusGrid"
|
|
@@ -3072,4 +3072,4 @@
|
|
|
3072
3072
|
height: ${15}px;
|
|
3073
3073
|
vertical-align: sub;
|
|
3074
3074
|
}
|
|
3075
|
-
`;class Vf extends t.Component{constructor(e,s={}){super(e,s),this.model=new _u(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,s)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:s}),editText:(e,t,s)=>this.trigger("edit-text",{title:e,placeholder:t,callback:s}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env},transportService:this.props.transportService,client:this.props.client,isReadonly:this.props.isReadonly,snapshotRequested:this.props.snapshotRequested},this.props.stateUpdateMessages),this.grid=$f("grid"),this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.linkEditor=t.useState({isOpen:!1}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.clipBoardString="",this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},Ff({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,uuidGenerator:this.model.uuidGenerator,_t:Vf._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model),waitForIdle:this.model.waitForIdle.bind(this.model),exportXLSX:this.model.exportXLSX.bind(this.model),openLinkEditor:()=>this.openLinkEditor()}),kf(window,"resize",this.render),kf(document.body,"cut",this.copy.bind(this,!0)),kf(document.body,"copy",this.copy.bind(this,!1)),kf(document.body,"paste",this.paste),kf(document.body,"keyup",this.onKeyup.bind(this)),kf(window,"beforeunload",this.leaveCollaborativeSession.bind(this)),this.activateFirstSheet()}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}mounted(){this.model.on("update",this,this.render),this.model.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.props.client&&this.model.joinSession(this.props.client)}willUnmount(){this.leaveCollaborativeSession()}async willUpdateProps(e){this.props.isReadonly!==e.isReadonly&&this.model.updateReadOnly(e.isReadonly)}leaveCollaborativeSession(){this.model.off("update",this),this.model.leaveSession()}activateFirstSheet(){const e=this.model.getters.getActiveSheetId(),[t]=this.model.getters.getSheets();t.id!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:t.id})}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}openLinkEditor(){this.linkEditor.isOpen=!0}closeLinkEditor(){this.linkEditor.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const s=e?"CUT":"COPY",i=this.model.getters.getSelectedZones();this.model.dispatch(s,{target:i});const o=this.model.getters.getClipboardContent();this.clipBoardString=o,t.clipboardData.setData("text/plain",o),t.preventDefault()}paste(e){if(!this.grid.el.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),s=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:s,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==Th.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===Th.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION");let t="";(e.ctrlKey||e.metaKey)&&(t+="CTRL+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];if(s)return e.preventDefault(),e.stopPropagation(),void s()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerCellFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}}Vf.template=Pf,Vf.style=Bf,Vf.components={TopBar:Nf,Grid:of,BottomBar:Ju,SidePanel:hf,LinkEditor:Ug},Vf._t=e=>e;const Hf={},zf={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:f,HEADER_WIDTH:m,TOPBAR_HEIGHT:v,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:E,DEFAULT_CELL_HEIGHT:
|
|
3075
|
+
`;class Vf extends t.Component{constructor(e,s={}){super(e,s),this.model=new _u(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,s)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:s}),editText:(e,t,s)=>this.trigger("edit-text",{title:e,placeholder:t,callback:s}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env},transportService:this.props.transportService,client:this.props.client,isReadonly:this.props.isReadonly,snapshotRequested:this.props.snapshotRequested},this.props.stateUpdateMessages),this.grid=$f("grid"),this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.linkEditor=t.useState({isOpen:!1}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.clipBoardString="",this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},Ff({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,uuidGenerator:this.model.uuidGenerator,_t:Vf._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model),waitForIdle:this.model.waitForIdle.bind(this.model),exportXLSX:this.model.exportXLSX.bind(this.model),openLinkEditor:()=>this.openLinkEditor()}),kf(window,"resize",this.render),kf(document.body,"cut",this.copy.bind(this,!0)),kf(document.body,"copy",this.copy.bind(this,!1)),kf(document.body,"paste",this.paste),kf(document.body,"keyup",this.onKeyup.bind(this)),kf(window,"beforeunload",this.leaveCollaborativeSession.bind(this)),this.activateFirstSheet()}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}mounted(){this.model.on("update",this,this.render),this.model.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.props.client&&this.model.joinSession(this.props.client)}willUnmount(){this.leaveCollaborativeSession()}async willUpdateProps(e){this.props.isReadonly!==e.isReadonly&&this.model.updateReadOnly(e.isReadonly)}leaveCollaborativeSession(){this.model.off("update",this),this.model.leaveSession()}activateFirstSheet(){const e=this.model.getters.getActiveSheetId(),[t]=this.model.getters.getSheets();t.id!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:t.id})}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}openLinkEditor(){this.linkEditor.isOpen=!0}closeLinkEditor(){this.linkEditor.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const s=e?"CUT":"COPY",i=this.model.getters.getSelectedZones();this.model.dispatch(s,{target:i});const o=this.model.getters.getClipboardContent();this.clipBoardString=o,t.clipboardData.setData("text/plain",o),t.preventDefault()}paste(e){if(!this.grid.el.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),s=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:s,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==Th.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===Th.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION");let t="";(e.ctrlKey||e.metaKey)&&(t+="CTRL+"),t+=e.key.toUpperCase();let s=this.keyDownMapping[t];if(s)return e.preventDefault(),e.stopPropagation(),void s()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}onGridComposerCellFocused(e){this.model.getters.isReadonly()||(this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent(e.detail||{}),this.env.dispatch("UNFOCUS_SELECTION_INPUT"))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}}Vf.template=Pf,Vf.style=Bf,Vf.components={TopBar:Nf,Grid:of,BottomBar:Ju,SidePanel:hf,LinkEditor:Ug},Vf._t=e=>e;const Hf={},zf={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:f,HEADER_WIDTH:m,TOPBAR_HEIGHT:v,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:E,DEFAULT_CELL_HEIGHT:S,SCROLLBAR_WIDTH:b},Zf={autofillModifiersRegistry:La,autofillRulesRegistry:Aa,cellMenuRegistry:cl,colMenuRegistry:hl,linkMenuRegistry:dl,functionRegistry:rr,uiPluginRegistry:rd,corePluginRegistry:nd,rowMenuRegistry:ul,sidePanelRegistry:Eh,sheetMenuRegistry:pl,topbarMenuRegistry:gl,topbarComponentRegistry:Sh,otRegistry:fl,inverseCommandRegistry:_a,cellRegistry:Wr},Gf={LinkCell:ta},Wf={args:_e,toBoolean:ge,toNumber:he,toString:ue,toXC:is,toZone:ks,toCartesian:ss,numberToLetters:ts,createFullMenuItem:ka,UuidGenerator:oi,formatDecimal:re,computeTextWidth:gs,isMarkdownLink:Is,parseMarkdownLink:ws,markdownLink:ys,createEmptyWorkbookData:ga};e.CorePlugin=ma,e.DATETIME_FORMAT=M,e.DataSource=cd,e.DispatchResult=Pe,e.Model=_u,e.Revision=Xh,e.SPREADSHEET_DIMENSIONS=zf,e.Spreadsheet=Vf,e.UIPlugin=bh,e.__DEBUG__=As,e.__info__=Hf,e.astToFormula=Nr,e.cellTypes=Gf,e.convertAstNodes=Or,e.coreTypes=De,e.functionCache=Pr,e.helpers=Wf,e.invalidateEvaluationCommands=Fe,e.normalize=Zr,e.parse=_r,e.readonlyAllowedCommands=$e,e.registries=Zf,e.setTranslationMethod=function(e){o=e},Object.defineProperty(e,"__esModule",{value:!0}),Hf.version="15.0.24",Hf.date="2024-07-02T08:44:51.424Z",Hf.hash="d1f2791"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|