@odoo/o-spreadsheet 14.0.2 → 14.0.3

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 o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var s=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,s.get?s:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var s=o(t);const n="#f5f5f5",i="#E8EAED",r="#595959",a="#666666",l="#3266ca",c=26,h=48,u=96,d=23,p=15,g=["#ff851b","#0074d9","#ffdc00","#7fdbff","#b10dc9","#0ecc40","#39cccc","#f012be","#3d9970","#111111","#01ff70","#ff4136","#aaaaaa","#85144b","#001f3f"];function f(e){return e.toString(16).padStart(6,"0")}let m=0;function v(){return m=++m%g.length,g[m]}function b(e){return e<26?String.fromCharCode(65+e):b(Math.floor(e/26)-1)+b(e%26)}function E(e){e=e.toUpperCase();const[t,o,s]=e.match(/\$?([A-Z]*)\$?([0-9]*)/);if(t!==e)throw new Error(`Invalid cell description: ${e}`);const n=function(e){let t=0;const o=e.length;for(let s=0;s<o;s++)t+=(e.charCodeAt(s)-65+(s<o-1?1:0))*26**(o-s-1);return t}(o);return[n,parseInt(s,10)-1]}function w(e,t){return b(e)+String(t+1)}function L(e){const t=(e=e.split("!").pop()).replace("$","").split(":");let o,s,n,i,r=E(t[0].trim());if(n=i=r[0],o=s=r[1],2===t.length){let e=E(t[1].trim());i=e[0],s=e[1],i<n&&([i,n]=[n,i]),s<o&&([s,o]=[o,s])}return{top:o,bottom:s,left:n,right:i}}function S(e){const{top:t,bottom:o,left:s,right:n}=e;return t===o&&s===n?w(s,t):`${w(s,t)}:${w(n,o)}`}function C(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 y(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function T(e,t){return!(e.bottom<t.top||t.bottom<e.top)&&!(e.right<t.left||t.right<e.left)}function x(e,t,o){const{left:s,right:n,top:i,bottom:r}=o;return e>=s&&e<=n&&t>=i&&t<=r}function R(e,t){const o={};for(let t of e){const e=L(t);for(let t=e.left;t<=e.right;t++)void 0===o[t]&&(o[t]=[]),o[t].push({top:e.top,bottom:e.bottom,remove:!1})}for(let e of t){const t=L(e);for(let e=t.left;e<=t.right;e++)void 0===o[e]&&(o[e]=[]),o[e].push({top:t.top,bottom:t.bottom,remove:!0})}const s=[];for(let[e,t]of Object.entries(o))s.push({col:parseInt(e),ranges:M(t)});return function(e){const t=e.sort(((e,t)=>e.col-t.col)),o=[];let s=[],n=0;for(let e=0;e<=t.length-1;e++){let i=[];if(n+1===t[e].col)for(let o of t[e].ranges){let n=!1;for(let e of s)o.top==e.top&&o.bottom==e.bottom&&(i.push(e),n=!0);n||i.push({top:o.top,bottom:o.bottom,startCol:t[e].col})}else i=t[e].ranges.map((o=>({top:o.top,bottom:o.bottom,startCol:t[e].col})));const r=s.filter((e=>!i.includes(e)));for(let e of r)o.push({top:e.top,bottom:e.bottom,left:e.startCol,right:n});n=t[e].col,s=i}for(let e of s)o.push({top:e.top,bottom:e.bottom,left:e.startCol,right:n});return o}(s).map(S)}function M(e){const t=new Set,o=new Set;for(let s of e)for(let e=s.top;e<=s.bottom;e++)s.remove?o.add(e):t.add(e);const s=[...t].filter((e=>!o.has(e))).sort(((e,t)=>e-t)),n=[];let i;for(let e of s)i?e===i.bottom+1?i.bottom=e:(n.push({top:i.top,bottom:i.bottom}),i={top:e,bottom:e}):i={top:e,bottom:e};return i&&n.push({top:i.top,bottom:i.bottom}),n}function A(e,t,o,s){const{top:n,bottom:i,left:r,right:a}=e,l=new Array(a-r+1);for(let e=r;e<=a;e++){let a=new Array(i-n+1);l[e-r]=a;for(let r=n;r<=i;r++){let i=t.rows[r].cells[e];a[r-n]=i?o(i):s}}return l}function N(e,t){let{left:o,right:s,top:n,bottom:i}=L(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)o>e&&(o-=1),(o>=e||s>=e)&&(s-=1);return o>s?null:w(o,n)+":"+w(s,i)}function k(e,t){let{left:o,right:s,top:n,bottom:i}=L(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)n>e&&(n-=1),(n>=e||i>=e)&&(i-=1);return n>i?null:w(o,n)+":"+w(s,i)}function _(e,t,o){let{left:s,right:n,top:i,bottom:r}=L(e);return s>=t&&(s+=o),(s>=t||n>=t)&&(n+=o),s>n?null:w(s,i)+":"+w(n,r)}function I(e,t,o){let{left:s,right:n,top:i,bottom:r}=L(e);return i>=t&&(i+=o),(i>=t||r>=t)&&(r+=o),i>r?null:w(s,i)+":"+w(n,r)}function O(e){return JSON.stringify(e,Object.keys(e).sort())}function D(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 o in e)t[o]=D(e[o]);return t;case"number":case"string":case"boolean":case"function":case"undefined":return e;default:throw new Error("Unsupported type: "+typeof e)}}function $(e){return e.startsWith("'")&&(e=e.slice(1,-1).replace(/''/g,"'")),e}function U(e){return e.includes(" ")&&(e=`'${e}'`),e}function F(e,t,o){return e<t?t:e>o?o:e}const P={},B=/^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?/,z=/^-?\d+(,\d+)*(\.?\d*(e\d+)?)?(\s*%)?$|^-?\.\d+(\s*%)?$/;function Z(e){return z.test(e.trim())}const H=/,/g;function G(e){let t=Number(e.replace(H,""));return isNaN(t)&&e.includes("%")&&(t=Number(e.split("%")[0]),!isNaN(t))?t/100:t}const V=new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:10});function j(e){return Number.isInteger(e)?e.toString():V.format(e)}let q=[];function W(e,t,o=""){if(e<0)return"-"+W(-e,t);const s=t>=20?20:t;let n=q[s];n||(n=new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s,useGrouping:!1}),q[s]=n);let i=n.format(e);if(o){let e=i.indexOf(".");i=i.replace(/\d(?=(?:\d{3})+(?:\.|$))/g,((t,s)=>e<0||s<e?`${t}${o}`:t))}return i}function Y(e,t){const o=t.split(";"),s=o.length;if(e<0)return s>1?X(-e,o[1]):"-"+X(-e,o[0]);return X(e,o[3===s&&0===e?2:0])}function X(e,t){const o=t.split("."),s=1===o.length?0:o[1].match(/0/g).length,n=o[0].includes(",")?",":"",i=t.includes("%");i&&(e*=100);const r=W(e,s,n);return i?r+"%":r}function K(){return 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)}))}let J=e=>e;const Q=function(e,...t){return{toString:function(){return function(e,...t){if(1===t.length&&"object"==typeof t[0]){const o=t[0];e=e.replace(/%\(?([^\)]+)\)s/g,((e,t)=>o[t]))}else t.length>0&&(e=e.replace(/\%s/g,(()=>t.shift())));return e}(J(e),...t)}}},ee=2e3,te=(new Date).getFullYear(),oe=new Date(1899,11,30),se=new Date(0)-oe,ne=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,ie=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,re=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function ae(e){let t;const o=(e=e.trim()).match(re);if(o){if(t=function(e){if(e=e.trim(),re.test(e)){const t=/AM/i.test(e),o=/PM/i.test(e),s=(t||o?e.substring(0,e.length-2).trim():e).split(/:/),n=s.length>=2,i=3===s.length;let r=Number(s[0]),a=n?Number(s[1]):0,l=i?Number(s[2]):0,c=i?"hh:mm:ss":"hh:mm";if(t||o)c+=" a";else if(!n)return null;r>=12&&t?r-=12:r<12&&o&&(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 Date(1899,11,30,r,a,l)}}return null}(o[0]),null===t)return null;e=e.replace(o[0],"").trim()}let s;const n=e.match(ne),i=e.match(ie);if(n||i){let t;if(n?(t=n[0],s=le(t,"mdy")):(t=i[0],s=le(t,"ymd")),null===s)return null;e=e.replace(t,"").trim()}return""!==e||!s&&!t?null:s&&t?{value:s.value+t.value,format:s.format+" "+("hhhh:mm:ss"===t.format?"hh:mm:ss":t.format),jsDate:new Date(s.jsDate.getFullYear()+t.jsDate.getFullYear()-1899,s.jsDate.getMonth()+t.jsDate.getMonth()-11,s.jsDate.getDate()+t.jsDate.getDate()-30,s.jsDate.getHours()+t.jsDate.getHours(),s.jsDate.getMinutes()+t.jsDate.getMinutes(),s.jsDate.getSeconds()+t.jsDate.getSeconds())}:s||t}function le(e,t){const o="mdy"===t;if(o||"ymd"===t){const t=e.split(/\/|-|\s/),s=o?0:1,n=o?1:2,i=o?2:0,r=Number(t[s]),a=Number(t[n]),l=2===t[s].length&&r<10||2===t[n].length&&a<10,c=t[i]?function(e){const t=Number(e);switch(e.length){case 1:return ee+t;case 2:return ee+(ee+t>te+10?-100:0)+t;case 3:case 4:return t}return 0}(t[i]):te,h=new Date(c,r-1,a),u=e.match(/\/|-|\s/)[0];if(h.getMonth()!==r-1||h.getDate()!==a)return null;const d=h-oe;let p=l?`mm${u}dd`:`m${u}d`;return t[i]&&(p=o?p+u+"yyyy":"yyyy"+u+p),{value:Math.round(d/864e5),format:p,jsDate:h}}return null}function ce(e){if("object"==typeof e&&null!==e)return e.jsDate||(e.jsDate=new Date(86400*e.value*1e3-se)),e.jsDate;if("string"==typeof e){let t=ae(e);if(null!==t&&t.jsDate)return t.jsDate}return function(e){const t=Math.trunc(e);let o=new Date(86400*t*1e3-se),s=e-t;s=s<0?1+s:s;const n=Math.round(24*s),i=Math.round(24*(s-n/24)*60),r=Math.round(24*(s-n/24-i/24/60)*60*60);return o.setHours(n),o.setMinutes(i),o.setSeconds(r),o}(me(e))}function he(e,t){const o=t||e.format,s=ce(e),n=o.indexOf("h");let i="",r="";return n>0?(i=ue(s,o.substring(0,n-1)),r=de(s,o.substring(n))):0===n?r=de(s,o):n<0&&(i=ue(s,o)),i+(i&&r?" ":"")+r}function ue(e,t){const o=t.match(/\/|-|\s/)[0];return t.split(o).map((t=>{switch(t){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(Q("invalid format"))}})).join(o)}function de(e,t){let o=t.split(/:|\s/);const s=e.getHours(),n="a"===o[o.length-1];let i=s,r="";return n&&(i=0===i?12:i>12?i-12:i,r=s>=12?" PM":" AM",o.pop()),o.map((t=>{switch(t){case"hhhh":return Math.floor((e.getTime()-oe)/36e5).toString();case"hh":return i.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")}})).join(":")+r}const pe=new Date(1899,11,30),ge=new Date(0)-pe,fe=e=>Q("The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.",e);function me(e){switch(typeof e){case"number":return e;case"boolean":return e?1:0;case"string":if(Z(e)||""===e)return G(e);const t=ae(e);if(t)return t.value;throw new Error(fe(e));case"object":return null!==e&&e.jsDate?e.value:e||0;default:return e||0}}function ve(e){if(""===e)throw new Error(fe(e));return me(e)}function be(e,t){if(Array.isArray(e))for(let o of e)for(let e of o)t(e);else t(e)}function Ee(e,t,o){let s=o;for(let o of e)be(o,(e=>{s=t(s,e)}));return s}function we(e,t,o){let s=o;return function(e,t){for(let o of e)if(Array.isArray(o))for(let e of o)for(let o of e)"number"==typeof o?t(o):"object"==typeof o&&null!==o&&o.jsDate&&t(o.value);else t(ve(o))}(e,(e=>{s=t(s,e)})),s}function Le(e,t,o){let s=o;return function(e,t){for(let o of e)if(Array.isArray(o))for(let e of o)for(let o of e)null!=o&&("number"==typeof o?t(o):"boolean"==typeof o?t(me(o)):"object"==typeof o&&null!==o&&o.jsDate?t(o.value):t(0));else t(me(o))}(e,(e=>{s=t(s,e)})),s}function Se(e){switch(typeof e){case"string":return e;case"number":return e.toString();case"boolean":return e?"TRUE":"FALSE";default:return""}}const Ce=e=>Q("The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a number.",e);function ye(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(Ce(e))}return!1;case"number":return!!e;default:return!1}}function Te(e,t){!function(e,t,o){for(let s of e)if(Array.isArray(s)){for(let e of s)for(let o of e)if(!t(o))return}else if(!o(s))return}(e,(e=>"boolean"==typeof e?t(e):"number"!=typeof e||t(!!e)),(e=>null===e||t(function(e){if(""===e)throw new Error(Ce(e));return ye(e)}(e))))}function xe(e,t){let o,s,n=e.substring(0,2);"<="===n||">="===n||"<>"===n?(o=n,s=e.substring(2)):(n=e.substring(0,1),"<"===n||">"===n||"="===n?(o=n,s=e.substring(1)):(o="=",s=e)),Z(s)?s=me(s):"TRUE"!==s&&"FALSE"!==s||(s=ye(s));const i={operator:o,operand:s};return"string"==typeof s&&(t&&(s+="*"),i.regexp=function(e){let t="",o="";for(let s of e)"?"===s&&"~"!==o?t+=".":"*"===s&&"~"!==o?t+=".*":("*"!==s&&"?"!==s||(t=t.slice(0,-1)),["^",".","[","]","$","(",")","*","+","?","|","{","}","\\"].includes(s)&&(t+="\\"),t+=s),o=s;return new RegExp("^"+t+"$","i")}(s)),i}function Re(e,t){const{operator:o,operand:s}=t;if("number"==typeof s&&"="===o)return Se(e)===Se(s);if("<>"===o||"="===o){let n;return n=typeof e==typeof s&&(t.regexp?t.regexp.test(e):e===s),"="===o?n:!n}if(typeof e==typeof s)switch(o){case"<":return e<s;case">":return e>s;case"<=":return e<=s;case">=":return e>=s}return!1}function Me(e,t,o=!1){const s=e.length;if(s%2==1)throw new Error(Q("Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs."));const n=e[0].length,i=e[0][0].length;let r=[];for(let t=0;t<s-1;t+=2){const s=e[t];if(s.length!==n||s[0].length!==i)throw new Error(Q("Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension"));const a=Se(e[t+1]);r.push(xe(a,o))}for(let o=0;o<n;o++)for(let n=0;n<i;n++){let i=!0;for(let t=0;t<s-1;t+=2){if(i=Re(e[t][o][n],r[t/2]),!i)break}i&&t(o,n)}}function Ae(e,t){const o=typeof t;let s,n,i,r,a,l,c=0,h=e.length-1;if(typeof e[c]===o&&t<e[c])return-1;if(typeof e[h]===o&&e[h]<=t)return h;for(;h-c>=0;){for(i=Math.ceil((c+h)/2),r=i,a=e[r],l=typeof a;c<=r&&o!==l;)r--,a=e[r],l=typeof a;l===o&&a<=t&&(void 0===s||s<a||s===a&&n<r)&&(s=a,n=r),l===o&&a>t?h=r-1:c=i+1}return void 0!==n?n:-1}function Ne(e){return"object"==typeof e&&e.jsDate?e.value:e}function ke(e){const t=Math.trunc(e);let o=new Date(864e5*t-ge),s=e-t;s=s<0?1+s:s;const n=Math.round(24*s),i=Math.round(24*(s-n/24)*60),r=Math.round(24*(s-n/24-i/24/60)*60*60);return o.setHours(n),o.setMinutes(i),o.setSeconds(r),o}class _e{constructor(){this.content={}}add(e,t){return this.content[e]=t,this}get(e){if(!(e in this.content))throw new Error(`Cannot find ${e} in this registry!`);return this.content[e]}getAll(){return Object.values(this.content)}remove(e){delete this.content[e]}}const Ie=/(.*?)\((.*?)\)(.*)/,Oe=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>"];function De(e){let t=e.split("\n");const o=[];for(let e of t)e=e.trim(),e&&o.push($e(e));return o}function $e(e){let t,o=e.match(Ie),s=o[1].trim(),n=[],i=!1,r=!1,a=!1;for(let e of o[2].split(",")){const o=e.trim().toUpperCase();let s=Oe.find((e=>o===e));if(s)n.push(s);else if("RANGE<ANY>"===o)n.push("RANGE");else if("OPTIONAL"===o)i=!0;else if("REPEATING"===o)r=!0;else if("LAZY"===o)a=!0;else if(o.startsWith("DEFAULT=")){const o=e.trim().slice(8);t='"'===o[0]?o.slice(1,-1):parseFloat(o)}}const l={name:s,description:o[3].trim(),type:n};return i&&(l.optional=!0),r&&(l.repeating=!0),a&&(l.lazy=!0),void 0!==t&&(l.default=t),l}const Ue={description:Q("Inverse cosine of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(Math.abs(t)>1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values are between -1 and 1 inclusive.",t.toString()));return Math.acos(t)}},Fe={description:Q("Inverse hyperbolic cosine of a number."),args:De(`\n value (number) ${Q("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=me(e);if(t<1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. It should be greater than or equal to 1.",t.toString()));return Math.acosh(t)}},Pe={description:Q("Inverse cotangent of a value."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse cotangent.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)}},Be={description:Q("Inverse hyperbolic cotangent of a value."),args:De(`\n value (number) ${Q("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=me(e);if(Math.abs(t)<=1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values cannot be between -1 and 1 inclusive.",t.toString()));return Math.log((t+1)/(t-1))/2}},ze={description:Q("Inverse sine of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(Math.abs(t)>1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %S. Valid values are between -1 and 1 inclusive.",t.toString()));return Math.asin(t)}},Ze={description:Q("Inverse hyperbolic sine of a number."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse hyperbolic sine.")}\n `),returns:["NUMBER"],compute:function(e){return Math.asinh(me(e))}},He={description:Q("Inverse tangent of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse tangent.")}\n `),returns:["NUMBER"],compute:function(e){return Math.atan(me(e))}},Ge={description:Q("Angle from the X axis to a point (x,y), in radians."),args:De(`\n x (number) ${Q("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n y (number) ${Q("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 o=me(e),s=me(t);if(0===o&&0===s)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return Math.atan2(s,o)}},Ve={description:Q("Inverse hyperbolic tangent of a number."),args:De(`\n value (number) ${Q("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=me(e);if(Math.abs(t)>=1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values are between -1 and 1 exclusive.",t.toString()));return Math.atanh(t)}},je={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n value (number) ${Q("The value to round up to the nearest integer multiple of factor.")}\n factor (number, optional, default=1) ${Q("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=me(e),s=me(t);if(o>0&&s<0)throw new Error(Q("Function CEILING expects the parameter '%s' to be positive when parameter '%s' is positive. Change '%s' from [%s] to a positive value.",je.args[1].name,je.args[0].name,je.args[1].name,s.toString()));return s?Math.ceil(o/s)*s:0}},qe={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, optional, default=0) ${Q("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"],compute:function(e,t=1,o=0){let s=me(t);if(0===s)return 0;const n=me(e);if(s=Math.abs(s),n>=0)return Math.ceil(n/s)*s;return 0===me(o)?-Math.floor(Math.abs(n)/s)*s:-Math.ceil(Math.abs(n)/s)*s}},We={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t){return qe.compute(e,t,0)}},Ye={description:Q("Cosine of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cosine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cos(me(e))}},Xe={description:Q("Hyperbolic cosine of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cosine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cosh(me(e))}},Ke={description:Q("Cotangent of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cotangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.tan(t)}},Je={description:Q("Hyperbolic cotangent of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cotangent of.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.tanh(t)}},Qe={description:Q("Number of empty values."),args:De(`\n value1 (any, range) ${Q("The first value or range in which to count the number of blanks.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges in which to count the number of blanks.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>null==t||""===t?e+1:e),0)}},et={description:Q("A conditional count across a range."),args:De(`\n range (range) ${Q("The range that is tested against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to range.")}\n `),returns:["NUMBER"],compute:function(){let e=0;return Me(arguments,((t,o)=>{e+=1})),e}},tt={description:Q("Count values depending on multiple criteria."),args:De(`\n criteria_range (range) ${Q("The range to check against criterion1.")}\n criterion (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(){let e=0;return Me(arguments,((t,o)=>{e+=1})),e}};function ot(e){switch(e){case void 0:case"":case null:return!1;default:return!0}}const st={description:Q("Counts number of unique values in a range."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider for uniqueness.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider for uniqueness.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>ot(t)?e.add(t):e),new Set).size}},nt={description:Q("Counts number of unique values in a range, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the number of unique values will be counted.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=new Set;return Me(t,((t,s)=>{const n=e[t][s];ot(n)&&o.add(n)})),o.size}},it={description:Q("Cosecant of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cosecant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.sin(t)}},rt={description:Q("Hyperbolic cosecant of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cosecant of.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.sinh(t)}},at=(e,t,o)=>Q("Function DECIMAL expects the parameter '%s' to be a valid base %s representation. Change '%s' from [%s] to a valid base %s representation.",e,t,e,o,t),lt={description:Q("Converts from another base to decimal."),args:De(`\n value (string) ${Q("The number to convert.")},\n base (number) ${Q("The base to convert the value from.")},\n `),returns:["NUMBER"],compute:function(e,t){let o=me(t);if(o=Math.floor(o),o<2||o>36)throw new Error(Q("Function DECIMAL expects the parameter '%s' to be between 2 and 36 inclusive. Change '%s' from [%s] to a value between 2 and 36.",lt.args[1].name,lt.args[1].name,o.toString()));const s=Se(e);if(""===s)return 0;if(!s.match(/^-?[a-z0-9]+$/i))throw new Error(at(lt.args[0].name,o,s));const n=parseInt(s,o);if(isNaN(n))throw new Error(at(lt.args[0].name,o,s));return n}},ct={description:Q("Converts an angle value in radians to degrees."),args:De(`\n angle (number) ${Q("The angle to convert from radians to degrees.")}\n `),returns:["NUMBER"],compute:function(e){return 180*me(e)/Math.PI}},ht={description:Q("Euler's number, e (~2.718) raised to a power."),args:De(`\n value (number) ${Q("The exponent to raise e.")}\n `),returns:["NUMBER"],compute:function(e){return Math.exp(me(e))}},ut={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n value (number) ${Q("The value to round down to the nearest integer multiple of factor.")}\n factor (number, optional, default=1) ${Q("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=me(e),s=me(t);if(o>0&&s<0)throw new Error(Q("Function FLOOR expects the parameter '%s' to be positive when parameter '%s' is positive. Change '%s' from [%s] to a positive value.",ut.args[1].name,ut.args[0].name,ut.args[1].name,s.toString()));return s?Math.floor(o/s)*s:0}},dt={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round down to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, optional, default=0) ${Q("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"],compute:function(e,t=1,o=0){let s=me(t);if(0===s)return 0;const n=me(e);if(s=Math.abs(s),n>=0)return Math.floor(n/s)*s;return 0===me(o)?-Math.ceil(Math.abs(n)/s)*s:-Math.floor(Math.abs(n)/s)*s}},pt={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round down to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){return dt.compute(e,t,0)}},gt={description:Q("Whether the provided value is even."),args:De(`\n value (number) ${Q("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=ve(e);return!(1&Math.floor(Math.abs(t)))}},ft={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t){return qe.compute(e,t,0)}},mt={description:Q("Whether the provided value is even."),args:De(`\n value (number) ${Q("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=ve(e);return!!(1&Math.floor(Math.abs(t)))}},vt={description:Q("The logarithm of a number, base e (euler's number)."),args:De(`\n value (number) ${Q("The value for which to calculate the logarithm, base e.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(t<=0)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. It should be greater than 0.",t.toString()));return Math.log(t)}},bt={description:Q("Modulo (remainder) operator."),args:De(`\n dividend (number) ${Q("The number to be divided to find the remainder.")}\n divisor (number) ${Q("The number to divide by.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(t);if(0===o)throw new Error(Q("Function MOD expects the parameter '%s' to be different from 0. Change '%s' to a value other than 0.",bt.args[1].name,bt.args[1].name));const s=me(e)%o;return s>0&&o<0||s<0&&o>0?s+o:s}},Et={description:Q("Rounds a number up to the nearest odd integer."),args:De(`\n value (number) ${Q("The value to round to the next greatest odd number.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);let o=Math.ceil(Math.abs(t));return o=1&o?o:o+1,t<0?-o:o}},wt={description:Q("The number pi."),args:[],returns:["NUMBER"],compute:function(){return Math.PI}},Lt={description:Q("A number raised to a power."),args:De(`\n base (number) ${Q("The number to raise to the exponent power.")}\n exponent (number) ${Q("The exponent to raise base to.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(e),s=me(t);if(o>=0)return Math.pow(o,s);if(!Number.isInteger(s))throw new Error(Q("Function POWER expects the parameter '%s' to be an integer when parameter '%s' is negative. Change '%s' from [%s] to an integer value.",Lt.args[1].name,Lt.args[0].name,Lt.args[1].name,s.toString()));return Math.pow(o,s)}},St={description:Q("Result of multiplying a series of numbers together."),args:De(`\n factor1 (number, range<number>) ${Q("The first number or range to calculate for the product.")}\n factor2 (number, range<number>, optional, repeating) ${Q("More numbers or ranges to calculate for the product.")}\n `),returns:["NUMBER"],compute:function(){let e=0,t=1;for(let o of arguments)if(Array.isArray(o))for(let s of o)for(let o of s)"number"==typeof o&&(t*=o,e+=1);else null!==o&&(t*=ve(o),e+=1);return 0===e?0:t}},Ct={description:Q("A random number between 0 inclusive and 1 exclusive."),args:[],returns:["NUMBER"],compute:function(){return Math.random()}},yt={description:Q("Random integer between two values, inclusive."),args:De(`\n low (number) ${Q("The low end of the random range.")}\n high (number) ${Q("The high end of the random range.")}\n `),returns:["NUMBER"],compute:function(e,t){let o=me(e);Number.isInteger(o)||(o=Math.ceil(o));let s=me(t);if(Number.isInteger(s)||(s=Math.floor(s)),s<o)throw new Error(Q("Function RANDBETWEEN parameter '%s' value is %s. It should be greater than or equal to [%s].",yt.args[1].name,s.toString(),o.toString()));return o+Math.ceil((s-o+1)*Math.random())-1}},Tt={description:Q("Rounds a number according to standard rules."),args:De(`\n value (number) ${Q("The value to round to places number of places.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.round(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.round(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},xt={description:Q("Rounds down a number."),args:De(`\n value (number) ${Q("The value to round to places number of places, always rounding down.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.floor(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.floor(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},Rt={description:Q("Rounds up a number."),args:De(`\n value (number) ${Q("The value to round to places number of places, always rounding up.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.ceil(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.ceil(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},Mt={description:Q("Secant of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the secant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cos(me(e))}},At={description:Q("Hyperbolic secant of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic secant of.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cosh(me(e))}},Nt={description:Q("Sine of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the sine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sin(me(e))}},kt={description:Q("Hyperbolic sine of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic sine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sinh(me(e))}},_t={description:Q("Positive square root of a positive number."),args:De(`\n value (number) ${Q("The number for which to calculate the positive square root.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(t<0)throw new Error(Q("Function SQRT parameter '%s' value is negative. It should be positive or zero. Change '%s' from [%s] to a positive value.",_t.args[0].name,_t.args[0].name,t.toString()));return Math.sqrt(t)}},It={description:Q("Sum of a series of numbers and/or cells."),args:De(`\n value1 (number, range<number>) ${Q("The first number or range to add together.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional numbers or ranges to add to value1.")}\n `),returns:["NUMBER"],compute:function(){return we(arguments,((e,t)=>e+t),0)}},Ot={description:Q("A conditional sum across a range."),args:De(`\n criteria_range (range) ${Q("The range which is tested against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to range.")}\n sum_range (range, optional, default=criteria_range) ${Q("The range to be summed, if different from range.")}\n `),returns:["NUMBER"],compute:function(e,t,o){void 0===o&&(o=e);let s=0;return Me([e,t],((e,t)=>{const n=o[e][t];"number"==typeof n&&(s+=n)})),s}},Dt={description:Q("Sums a range depending on multiple criteria."),args:De(`\n sum_range (range) ${Q("The range to sum.")}\n criteria_range1 (range) ${Q("The range to check against criterion1.")}\n criterion1 (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o+=n)})),o}},$t={description:Q("Tangent of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the tangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tan(me(e))}},Ut={description:Q("Hyperbolic tangent of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic tangent of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tanh(me(e))}},Ft={description:Q("Truncates a number."),args:De(`\n value (number) ${Q("The value to be truncated.")}\n places (number, optional, default=0) ${Q("The number of significant digits to the right of the decimal point to retain.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);return 0===s?Math.trunc(o):(Number.isInteger(s)||(s=Math.trunc(s)),Math.trunc(o*Math.pow(10,s))/Math.pow(10,s))}};var Pt=Object.freeze({__proto__:null,ACOS:Ue,ACOSH:Fe,ACOT:Pe,ACOTH:Be,ASIN:ze,ASINH:Ze,ATAN:He,ATAN2:Ge,ATANH:Ve,CEILING:je,CEILING_MATH:qe,CEILING_PRECISE:We,COS:Ye,COSH:Xe,COT:Ke,COTH:Je,COUNTBLANK:Qe,COUNTIF:et,COUNTIFS:tt,COUNTUNIQUE:st,COUNTUNIQUEIFS:nt,CSC:it,CSCH:rt,DECIMAL:lt,DEGREES:ct,EXP:ht,FLOOR:ut,FLOOR_MATH:dt,FLOOR_PRECISE:pt,ISEVEN:gt,ISO_CEILING:ft,ISODD:mt,LN:vt,MOD:bt,ODD:Et,PI:wt,POWER:Lt,PRODUCT:St,RAND:Ct,RANDBETWEEN:yt,ROUND:Tt,ROUNDDOWN:xt,ROUNDUP:Rt,SEC:Mt,SECH:At,SIN:Nt,SINH:kt,SQRT:_t,SUM:It,SUMIF:Ot,SUMIFS:Dt,TAN:$t,TANH:Ut,TRUNC:Ft});function Bt(e,t,o){let s=[],n=[],i=0,r=0;if(be(e,(e=>{s.push(e),i+=1})),be(t,(e=>{n.push(e),r+=1})),i!==r)throw new Error(Q("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",i.toString(),r.toString()));let a=0,l=0,c=0;for(let e=0;e<i;e++){const t=s[e],o=n[e];"number"==typeof t&&"number"==typeof o&&(a+=1,l+=t,c+=o)}if(0===a||o&&1===a)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const h=l/a,u=c/a;let d=0;for(let e=0;e<i;e++){const t=s[e],o=n[e];"number"==typeof t&&"number"==typeof o&&(d+=(t-h)*(o-u))}return d/(a-(o?1:0))}function zt(e,t,o){let s=0,n=0;const i=o?Le:we;if(n=i(e,((e,t)=>(s+=1,e+t)),0),0===s||t&&1===s)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const r=n/s;return i(e,((e,t)=>e+Math.pow(t-r,2)),0)/(s-(t?1:0))}const Zt={description:Q("Average magnitude of deviations from mean."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=we(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVEDEV caused a divide by zero error."));const o=t/e;return we(arguments,((e,t)=>e+Math.abs(o-t)),0)/e}},Ht={description:Q("Numerical average value in a dataset, ignoring text."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=we(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVERAGE caused a divide by zero error."));return t/e}},Gt=Q("AVERAGE.WEIGHTED has mismatched range sizes."),Vt=Q("AVERAGE.WEIGHTED expects the weight to be positive or equal to 0."),jt={description:Q("Weighted average."),args:De(`\n values (number, range<number>) ${Q("Values to average.")}\n weights (number, range<number>) ${Q("Weights for each corresponding value.")}\n additional_values (number, range<number>, optional, repeating) ${Q("Additional values to average with weights.")}\n `),returns:["NUMBER"],compute:function(){let e,t,o=0,s=0;if(arguments.length%2==1)throw new Error(Q("Wrong number of arguments. Expected an even number of arguments."));for(let n=0;n<arguments.length-1;n+=2)if(e=arguments[n],t=arguments[n+1],Array.isArray(e)){if(!Array.isArray(t))throw new Error(Gt);let n=e.length,i=e[0].length;if(n!==t.length||i!=t[0].length)throw new Error(Gt);for(let r=0;r<n;r++)for(let n=0;n<i;n++){let i=e[r][n],a=t[r][n],l="number"==typeof a;if("number"==typeof i!==l)throw new Error(Q("AVERAGE.WEIGHTED expects number values."));if(l){if(a<0)throw new Error(Vt);o+=i*a,s+=a}}}else{if(t=me(t),e=me(e),t<0)throw new Error(Vt);o+=e*t,s+=t}if(0===s)throw new Error(Q("Evaluation of function AVERAGE.WEIGHTED caused a divide by zero error."));return o/s}},qt={description:Q("Numerical average value in a dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=Le(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVERAGEA caused a divide by zero error."));return t/e}},Wt={description:Q("Average of values depending on criteria."),args:De(`\n criteria_range (range) ${Q("The range to check against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to criteria_range.")}\n average_range (range, optional, default=criteria_range) ${Q("The range to average. If not included, criteria_range is used for the average instead.")}\n `),returns:["NUMBER"],compute:function(e,t,o){void 0===o&&(o=e);let s=0,n=0;if(Me([e,t],((e,t)=>{const i=o[e][t];"number"==typeof i&&(s+=1,n+=i)})),0===s)throw new Error(Q("Evaluation of function AVERAGEIF caused a divide by zero error."));return n/s}},Yt={description:Q("Average of values depending on multiple criteria."),args:De(`\n average_range (range) ${Q("The range to average.")}\n criteria_range1 (range) ${Q("The range to check against criterion1.")}\n criterion1 (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=0,s=0;if(Me(t,((t,n)=>{const i=e[t][n];"number"==typeof i&&(o+=1,s+=i)})),0===o)throw new Error(Q("Evaluation of function AVERAGEIFS caused a divide by zero error."));return s/o}},Xt={description:Q("The number of numeric values in dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when counting.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(){let e=0;for(let t of arguments)if(Array.isArray(t))for(let o of t)for(let t of o)("number"==typeof t||"object"==typeof t&&null!==t&&t.jsDate)&&(e+=1);else("string"!=typeof t||Z(t)||ae(t))&&(e+=1);return e}},Kt={description:Q("The number of values in a dataset."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider when counting.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>null!=t?e+1:e),0)}},Jt={description:Q("The covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!1)}},Qt={description:Q("The covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!1)}},eo={description:Q("The sample covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!0)}},to={description:Q("Nth largest element from a data set."),args:De(`\n data (any, range) ${Q("Array or range containing the dataset to consider.")}\n n (number) ${Q("The rank from largest to smallest of the element to return.")}\n `),returns:["NUMBER"],compute:function(e,t){t=Math.trunc(me(t));let o,s=[],n=0;be(e,(e=>{"number"==typeof(e=Ne(e))&&(o=Ae(s,e),s.splice(o+1,0,e),n++,n>t&&(s.shift(),n--))}));const i=s.shift();if(void 0===i)throw new Error(Q("LARGE has no valid input data."));if(n<t)throw new Error(Q("Function LARGE parameter 2 value %s is out of range.",t.toString()));return i}},oo={description:Q("Maximum value in a numeric dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the maximum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],compute:function(){const e=we(arguments,((e,t)=>e<t?t:e),-1/0);return e===-1/0?0:e}},so={description:Q("Maximum numeric value in a dataset."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider when calculating the maximum value.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],compute:function(){const e=Le(arguments,((e,t)=>Math.max(t,e)),-1/0);return e===-1/0?0:e}},no={description:Q("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the maximum will be determined.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=-1/0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o=o<n?n:o)})),o===-1/0?0:o}},io={description:Q("Minimum value in a numeric dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],compute:function(){const e=we(arguments,((e,t)=>t<e?t:e),1/0);return e===1/0?0:e}},ro={description:Q("Minimum numeric value in a dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],compute:function(){const e=Le(arguments,((e,t)=>Math.min(t,e)),1/0);return e===1/0?0:e}},ao={description:Q("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the minimum will be determined.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=1/0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o=o>n?n:o)})),o===1/0?0:o}},lo={description:Q("Nth smallest element in a data set."),args:De(`\n data (any, range) ${Q("The array or range containing the dataset to consider.")}\n n (number) ${Q("The rank from smallest to largest of the element to return.")}\n `),returns:["NUMBER"],compute:function(e,t){t=Math.trunc(me(t));let o,s=[],n=0;be(e,(e=>{"number"==typeof(e=Ne(e))&&(o=Ae(s,e),s.splice(o+1,0,e),n++,n>t&&(s.pop(),n--))}));const i=s.pop();if(void 0===i)throw new Error(Q("SMALL has no valid input data."));if(n<t)throw new Error(Q("Function SMALL parameter 2 value %s is out of range.",t.toString()));return i}},co={description:Q("Standard deviation."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(mo.compute(...arguments))}},ho={description:Q("Standard deviation of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(vo.compute(...arguments))}},uo={description:Q("Standard deviation."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(bo.compute(...arguments))}},po={description:Q("Standard deviation of sample (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(Eo.compute(...arguments))}},go={description:Q("Standard deviation of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(wo.compute(...arguments))}},fo={description:Q("Standard deviation of entire population (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(Lo.compute(...arguments))}},mo={description:Q("Variance."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!0,!1)}},vo={description:Q("Variance of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!1,!1)}},bo={description:Q("Variance."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!0,!1)}},Eo={description:Q("Variance of sample (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!0,!0)}},wo={description:Q("Variance of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!1,!1)}},Lo={description:Q("Variance of entire population (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return zt(arguments,!1,!0)}};var So=Object.freeze({__proto__:null,AVEDEV:Zt,AVERAGE:Ht,AVERAGE_WEIGHTED:jt,AVERAGEA:qt,AVERAGEIF:Wt,AVERAGEIFS:Yt,COUNT:Xt,COUNTA:Kt,COVAR:Jt,COVARIANCE_P:Qt,COVARIANCE_S:eo,LARGE:to,MAX:oo,MAXA:so,MAXIFS:no,MIN:io,MINA:ro,MINIFS:ao,SMALL:lo,STDEV:co,STDEV_P:ho,STDEV_S:uo,STDEVA:po,STDEVP:go,STDEVPA:fo,VAR:mo,VAR_P:vo,VAR_S:bo,VARA:Eo,VARP:wo,VARPA:Lo});function Co(e,t,o){const s=new Map,n=e.length;for(let t=n-1;t>=0;t--)s.set(Se(e[t][0]).toUpperCase(),t);const i=typeof t;let r;if("number"===i){if(r=Math.trunc(t)-1,r<0||r>n-1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 2 value is %s. Valid values are between 1 and %s inclusive.",t,n))}else{const e="string"===i?t.toUpperCase():t;if(r=s.get(e),void 0===r)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 2 value is %s. It should be one of: %s.",t,[...s.keys()].map((e=>"'"+e+"'")).join(", ")))}const a=o[0].length;if(a<2)throw new Error(Q("[[FUNCTION_NAME]] criteria range must be at least 2 rows."));let l=new Set;const c=e[0].length;for(let t=1;t<a;t++){let n=[],i=!0;for(let r=0;r<o.length;r++){const a=Se(o[r][0]).toUpperCase(),l=s.get(a),h=o[r][t];if(void 0!==h){if(void 0===l){i=!1;break}n.push([e[l].slice(1,c)]),n.push(h)}}if(i){if(!(n.length>0)){l=new Set(Array(c-1).keys());break}Me(n,((e,t)=>{l.add(t)}),!0)}}const h=e[r];return[...l].map((e=>h[e+1]))}const yo=De(`\n database (range) ${Q("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) ${Q("Indicates which column in database contains the values to be extracted and operated on.")}\n criteria (range) ${Q("An array or range containing zero or more criteria to filter the database values by before operating.")}\n`),To={description:Q("Average of a set of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Ht.compute([s])}},xo={description:Q("Counts values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Xt.compute([s])}},Ro={description:Q("Counts values and text from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Kt.compute([s])}},Mo={description:Q("Single value from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);if(s.length>1)throw new Error(Q("More than one match found in DGET evaluation."));return s[0]}},Ao={description:Q("Maximum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return oo.compute([s])}},No={description:Q("Minimum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return io.compute([s])}},ko={description:Q("Product of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return St.compute([s])}},_o={description:Q("Standard deviation of population sample from table."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return co.compute([s])}},Io={description:Q("Standard deviation of entire population from table."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return go.compute([s])}},Oo={description:Q("Sum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return It.compute([s])}},Do={description:Q("Variance of population sample from table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return mo.compute([s])}},$o={description:Q("Variance of a population from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return wo.compute([s])}};var Uo=Object.freeze({__proto__:null,DAVERAGE:To,DCOUNT:xo,DCOUNTA:Ro,DGET:Mo,DMAX:Ao,DMIN:No,DPRODUCT:ko,DSTDEV:_o,DSTDEVP:Io,DSUM:Oo,DVAR:Do,DVARP:$o});const Fo=new Date(1899,11,30),Po={description:Q("Converts year/month/day into a date."),args:De(`\n year (number) ${Q("The year component of the date.")}")}\n month (number) ${Q("The month component of the date.")}")}\n day (number) ${Q("The day component of the date.")}")}\n `),returns:["DATE"],compute:function(e,t,o){let s=Math.trunc(me(e));const n=Math.trunc(me(t)),i=Math.trunc(me(o));if(s<0||1e4<=s)throw new Error(Q("function DATE parameter year should be greater or equal to 0 and lesser than 10000."));s<1900&&(s+=1900);const r=new Date(s,n-1,i),a=r.getTime()-Fo.getTime();if(a<0)throw new Error(Q("function DATE result should not be lesser than 01/01/1900"));return{value:Math.round(a/864e5),format:"m/d/yyyy",jsDate:r}}},Bo={description:Q("Converts a date string to a date value."),args:De(`\n date_string (string) ${Q("The string representing the date.")}\n `),returns:["NUMBER"],compute:function(e){const t=Se(e),o=ae(t);if(null===o)throw new Error(Q("DATEVALUE parameter '%s' cannot be parsed to date/time.",t));return Math.trunc(o.value)}},zo={description:Q("Day of the month that a specific date falls on."),args:De(`\n date (string) ${Q("The date from which to extract the day.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getDate()}},Zo={description:Q("Number of days between two dates."),args:De(`\n end_date (date) ${Q("The end of the date range.")}\n start_date (date) ${Q("The start of the date range.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=ce(e),s=ce(t),n=o.getTime()-s.getTime();return Math.round(n/864e5)}},Ho={description:Q("Date a number of months before/after another date."),args:De(`\n start_date (date) ${Q("The date from which to calculate the result.")}\n months (number) ${Q("The number of months before (negative) or after (positive) 'start_date' to calculate.")}\n `),returns:["DATE"],compute:function(e,t){const o=ce(e),s=Math.trunc(me(t)),n=o.getFullYear(),i=o.getMonth(),r=o.getDate(),a=new Date(n,i+s,r),l=a.getTime()-Fo.getTime();return{value:Math.round(l/864e5),format:"m/d/yyyy",jsDate:a}}},Go={description:Q("Last day of a month before or after a date."),args:De(`\n start_date (date) ${Q("The date from which to calculate the result.")}\n months (number) ${Q("The number of months before (negative) or after (positive) 'start_date' to consider.")}\n `),returns:["DATE"],compute:function(e,t){const o=ce(e),s=Math.trunc(me(t)),n=o.getFullYear(),i=o.getMonth(),r=new Date(n,i+s+1,0),a=r.getTime()-Fo.getTime();return{value:Math.round(a/864e5),format:"m/d/yyyy",jsDate:r}}},Vo={description:Q("Hour component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the hour component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getHours()}},jo={description:Q("ISO week number of the year."),args:De(`\n date (date) ${Q("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=ce(e),o=t.getFullYear();let s=1;for(;4!==new Date(o,0,s).getDay();)s+=1;const n=new Date(o,0,s-3);let i=31;for(;4!==new Date(o,11,i).getDay();)i-=1;const r=new Date(o,11,i+3);let a,l;switch(a=n.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=n;break;case 1:l=new Date(o,11,i+3+1);break;case-1:let e=1;for(;4!==new Date(o-1,0,e).getDay();)e+=1;l=new Date(o-1,0,e-3)}const c=(t.getTime()-l.getTime())/864e5;return Math.floor(c/7)+1}},qo={description:Q("Minute component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the minute component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getMinutes()}},Wo={description:Q("Month of the year a specific date falls in"),args:De(`\n date (date) ${Q("The date from which to extract the month.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getMonth()+1}},Yo={description:Q("Net working days between two provided days."),args:De(`\n start_date (date) ${Q("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${Q("The end date of the period from which to calculate the number of net working days.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the date serial numbers to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o){return Ko.compute(e,t,1,o)}};function Xo(e){if("string"==typeof e){let t=[];if(7===e.length){for(let o=0;o<7;o++)switch(e.charAt(o)){case"0":break;case"1":t.push(o+1===7?0:o+1);break;default:throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string composed of 0 or 1. Actual string is '%s'.",e))}return t}throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string with 7 characters. Actual string is '%s'.",e))}if("number"==typeof e){if(1<=e&&e<=7)return[e-2==-1?6:e-2,e-1];if(11<=e&&e<=17)return[e-11];throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string or a number in the range 1-7 or 11-17. Actual number is %s.",e.toString()))}throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a number or a string."))}const Ko={description:Q("Net working days between two dates (specifying weekends)."),args:De(`\n start_date (date) ${Q("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${Q("The end date of the period from which to calculate the number of net working days.")}\n weekend (any, optional, default=1) ${Q("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider as holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1,s){const n=ce(e),i=ce(t),r=Xo(o);let a=new Set;void 0!==s&&be(s,(e=>{const t=ce(e);a.add(t.getTime())}));const l=n.getTime()>i.getTime(),c=new Date((l?n:i).getTime());let h=new Date((l?i:n).getTime());const u=c.getTime();let d=h.getTime(),p=0;for(;d<=u;)r.includes(h.getDay())||a.has(d)||(p+=1),h.setDate(h.getDate()+1),d=h.getTime();return l?-p:p}},Jo={description:Q("Current date and time as a date value."),args:[],returns:["DATE"],compute:function(){let e=new Date;e.setMilliseconds(0);const t=e.getTime()-Fo.getTime(),o=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return{value:Math.floor(t/864e5)+o,format:"m/d/yyyy hh:mm:ss",jsDate:e}}},Qo={description:Q("Minute component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the second component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getSeconds()}},es={description:Q("Converts hour/minute/second into a time."),args:De(`\n hour (number) ${Q("The hour component of the time.")}\n minute (number) ${Q("The minute component of the time.")}\n second (number) ${Q("The second component of the time.")}\n `),returns:["DATE"],compute:function(e,t,o){let s=Math.trunc(me(e)),n=Math.trunc(me(t)),i=Math.trunc(me(o));if(n+=Math.floor(i/60),i=i%60+(i<0?60:0),s+=Math.floor(n/60),n=n%60+(n<0?60:0),s%=24,s<0)throw new Error(Q("function Time result should not be negative"));return{value:s/24+n/1440+i/86400,format:"hh:mm:ss a",jsDate:new Date(1899,11,30,s,n,i)}}},ts={description:Q("Converts a time string into its serial number representation."),args:De(`\n time_string (string) ${Q("The string that holds the time representation.")}\n `),returns:["NUMBER"],compute:function(e){const t=Se(e),o=ae(t);if(null===o)throw new Error(Q("TIMEVALUE parameter '%s' cannot be parsed to date/time.",t));const s=o.value-Math.trunc(o.value);return s<0?1+s:s}},os={description:Q("Current date as a date value."),args:[],returns:["DATE"],compute:function(){const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),o=t.getTime()-Fo.getTime();return{value:Math.round(o/864e5),format:"m/d/yyyy",jsDate:t}}},ss={description:Q("Day of the week of the date provided (as number)."),args:De(`\n date (date) ${Q("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, optional, default=1) ${Q("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 o=ce(e),s=Math.round(me(t)),n=o.getDay();switch(s){case 1:return n+1;case 2:return 0===n?7:n;case 3:return 0===n?6:n-1}throw new Error(Q("Function WEEKDAY parameter 2 value %s is out of range.",s.toString()))}},ns={description:Q("Week number of the year."),args:De(`\n date (date) ${Q("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, optional, default=1) ${Q("A number representing the day that a week starts on. Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=ce(e),s=Math.round(me(t));let n;if(1===s||2===s)n=s-1;else{if(!(11<=s&&s<=17)){if(21===s)return jo.compute(e);throw new Error(Q("Function WEEKNUM parameter 2 value %s is out of range.",s.toString()))}n=s-10==7?0:s-10}const i=o.getFullYear();let r=1,a=new Date(i,0,r);for(;a.getDay()!==n;)r+=1,a=new Date(i,0,r);const l=(o.getTime()-a.getTime())/864e5;return l<0?1:Math.floor(l/7)+(1===r?1:2)}},is={description:Q("Number of working days from start date."),args:De(`\n start_date (date) ${Q("The date from which to begin counting.")}\n num_days (number) ${Q("The number of working days to advance from start_date. If negative, counts backwards.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o){return rs.compute(e,t,1,o)}},rs={description:Q("Net working days between two dates (specifying weekends)."),args:De(`\n start_date (date) ${Q("The date from which to begin counting.")}\n num_days (number) ${Q("The number of working days to advance from start_date. If negative, counts backwards.")}\n weekend (any, optional, default=1) ${Q("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider holidays.")}\n `),returns:["DATE"],compute:function(e,t,o=1,s){let n=ce(e),i=Math.trunc(me(t));if("1111111"===o)throw new Error(Q("Function WORKDAY.INTL parameter 3 cannot be equal to '1111111'."));const r=Xo(o);let a=new Set;void 0!==s&&be(s,(e=>{const t=ce(e);a.add(t.getTime())}));let l=new Date(n.getTime()),c=l.getTime();const h=Math.sign(i);let u=Math.abs(i);for(;u>0;)l.setDate(l.getDate()+h),c=l.getTime(),r.includes(l.getDay())||a.has(c)||(u-=1);const d=c-Fo.getTime();return{value:Math.round(d/864e5),format:"m/d/yyyy",jsDate:l}}},as={description:Q("Year specified by a given date."),args:De(`\n date (date) ${Q("The date from which to extract the year.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getFullYear()}};var ls=Object.freeze({__proto__:null,DATE:Po,DATEVALUE:Bo,DAY:zo,DAYS:Zo,EDATE:Ho,EOMONTH:Go,HOUR:Vo,ISOWEEKNUM:jo,MINUTE:qo,MONTH:Wo,NETWORKDAYS:Yo,NETWORKDAYS_INTL:Ko,NOW:Jo,SECOND:Qo,TIME:es,TIMEVALUE:ts,TODAY:os,WEEKDAY:ss,WEEKNUM:ns,WORKDAY:is,WORKDAY_INTL:rs,YEAR:as});const cs={description:Q("Whether a value is an error."),args:De(`value (any, lazy) ${Q("The value to be verified as an error type.")}`),returns:["BOOLEAN"],compute:function(e){try{return e(),!1}catch(e){return!0}}},hs={description:Q("Whether a value is `true` or `false`."),args:De(`value (any) ${Q("The value to be verified as a logical TRUE or FALSE.")}`),returns:["BOOLEAN"],compute:function(e){return"boolean"==typeof e}},us={description:Q("Whether a value is non-textual."),args:De(`value (any) ${Q("The value to be checked.")}`),returns:["BOOLEAN"],compute:function(e){return"string"!=typeof e}},ds={description:Q("Whether a value is a number."),args:De(`value (any) ${Q("The value to be verified as a number.")}`),returns:["BOOLEAN"],compute:function(e){return"number"==typeof e}},ps={description:Q("Whether a value is text."),args:De(`value (any) ${Q("The value to be verified as text.")}`),returns:["BOOLEAN"],compute:function(e){return"string"==typeof e}};var gs=Object.freeze({__proto__:null,ISERROR:cs,ISLOGICAL:hs,ISNONTEXT:us,ISNUMBER:ds,ISTEXT:ps});const fs={description:Q("Wait"),args:De(`ms (number) ${Q("wait time in milliseconds")}`),returns:["ANY"],async:!0,compute:function(e){return new Promise((function(t,o){setTimeout((function(){t(e)}),e)}))}},ms={description:Q("Logical `and` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that represent logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!0,t=!1;if(Te(arguments,(o=>(e=e&&o,t=!0,e))),!t)throw new Error(Q("AND has no valid input data."));return e}},vs={description:Q("Returns value depending on logical expression."),args:De(`\n logical_expression (boolean) ${Q("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) ${Q("The value the function returns if logical_expression is TRUE.")}\n value_if_false (any, lazy, optional, default=FALSE) ${Q("The value the function returns if logical_expression is FALSE.")}\n `),returns:["ANY"],compute:function(e,t,o=(()=>!1)){const s=ye(e)?t():o();return null===s?"":s}},bs={description:Q("Value if it is not an error, otherwise 2nd argument."),args:De(`\n value (any, lazy) ${Q("The value to return if value itself is not an error.")}\n value_if_error (any, lazy, optional, default="") ${Q("The value the function returns if value is an error.")}\n `),returns:["ANY"],compute:function(e,t=(()=>"")){let o;try{o=e()}catch(e){o=t()}return null===o?"":o}},Es={description:Q("Returns a value depending on multiple logical expressions."),args:De(`\n condition1 (boolean, lazy) ${Q("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) ${Q("The returned value if condition1 is TRUE.")}\n additional_values (any, lazy, optional, repeating) ${Q("Additional conditions and values to be evaluated if the previous ones are FALSE.")}\n `),returns:["ANY"],compute:function(){if(arguments.length%2==1)throw new Error(Q("Wrong number of arguments. Expected an even number of arguments."));for(let e=0;e<arguments.length-1;e+=2)if(ye(arguments[e]()))return arguments[e+1]();throw new Error(Q("No match."))}},ws={description:Q("Returns opposite of provided logical value."),args:De(`logical_expression (boolean) ${Q("An expression or reference to a cell holding an expression that represents some logical value.")}\n `),returns:["BOOLEAN"],compute:function(e){return!ye(e)}},Ls={description:Q("Logical `or` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!1,t=!1;if(Te(arguments,(o=>(e=e||o,t=!0,!e))),!t)throw new Error(Q("OR has no valid input data."));return e}},Ss={description:Q("Logical `xor` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!1,t=!1;if(Te(arguments,(o=>(e=e?!o:o,t=!0,!0))),!t)throw new Error(Q("XOR has no valid input data."));return e}};var Cs=Object.freeze({__proto__:null,WAIT:fs,AND:ms,IF:vs,IFERROR:bs,IFS:Es,NOT:ws,OR:Ls,XOR:Ss});function ys(e,t){for(let o=0;o<e.length;o++)if(e[o]===t)return o;return-1}const Ts={description:Q("Look up a value."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n search_array (any, range) ${Q("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 (any, range, optional) ${Q("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,o){const s=t[0].length>=t.length,n=Ae((s?t[0]:t.map((e=>e[0]))).map((e=>Ne(e))),Ne(e));if(-1===n){const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in LOOKUP evaluation.",t))}if(void 0===o)return s?t.pop()[n]:t[n].pop();const i=o.length,r=o[0].length;if(i>1&&r>1)throw new Error(Q("LOOKUP range must be a single row or a single column."));if(i>1){if(i-1<n)throw new Error(Q("LOOKUP evaluates to an out of range row value %s.",(n+1).toString()));return o[n][0]}if(r-1<n)throw new Error(Q("LOOKUP evaluates to an out of range column value %s.",(n+1).toString()));return o[0][n]}},xs={description:Q("Position of item in range that matches value."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${Q("The one-dimensional array to be searched.")}\n search_type (number, optional, default=1) ${Q("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,o=1){let s=me(o);const n=t.length,i=t[0].length;if(n>1&&i>1)throw new Error(Q("MATCH range must be a single row or a single column."));let r=-1;t=t.flat().map((e=>Ne(e)));const a=Ne(e);switch(s=Math.sign(s),s){case 1:r=Ae(t,a);break;case 0:r=ys(t,a);break;case-1:r=function(e,t){const o=typeof t;let s,n,i,r,a,l,c=0,h=e.length-1;if(typeof e[c]===o&&t>e[c])return-1;if(typeof e[h]===o&&e[h]>t)return h;for(;h-c>=0;){for(i=Math.ceil((c+h)/2),r=i,a=e[r],l=typeof a;c<=r&&o!==l;)r--,a=e[r],l=typeof a;l===o&&a>=t&&(void 0===s||s>a||s===a&&n>r)&&(s=a,n=r),l===o&&a<=t?h=r-1:c=i+1}return void 0!==n?n:-1}(t,a)}if(r>-1)return r+1;{const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in MATCH evaluation.",t))}}},Rs={description:Q("Vertical lookup."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${Q("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) ${Q("The column index of the value to be returned, where the first column in range is numbered 1.")}\n is_sorted (boolean, optional, default = TRUE) ${Q("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,o,s=!0){const n=Math.trunc(me(o));if(n<1||t.length<n)throw new Error(Q("VLOOKUP evaluates to an out of bounds range."));const i=ye(s),r=t[0].map((e=>Ne(e))),a=Ne(e);let l;if(l=i?Ae(r,a):ys(r,a),l>-1)return t[n-1][l];{const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in VLOOKUP evaluation.",t))}}};var Ms=Object.freeze({__proto__:null,LOOKUP:Ts,MATCH:xs,VLOOKUP:Rs});const As={description:Q("Sum of two numbers."),args:De(`\n value1 (number) ${Q("The first addend.")}\n value2 (number) ${Q("The second addend.")}\n `),returns:["NUMBER"],compute:function(e,t){return e&&e.value?t&&t.value?e.value+t.value:{value:e.value+me(t),format:e.format,jsDate:ke(e.value+me(t))}:me(e)+me(t)}},Ns={description:Q("Concatenation of two values."),args:De(`\n value1 (string) ${Q("The value to which value2 will be appended.")}\n value2 (string) ${Q("The value to append to value1.")}\n `),returns:["STRING"],compute:function(e,t){return Se(e)+Se(t)}},ks={description:Q("One number divided by another."),args:De(`\n dividend (number) ${Q("The number to be divided.")}\n divisor (number) ${Q("The number to divide by.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(t);if(0===o)throw new Error(Q("Function DIVIDE parameter 2 cannot be zero."));return me(e)/o}};function _s(e){return null==e}const Is={number:0,string:"",boolean:!1},Os={description:Q("Equal."),args:De(`\n value1 (any) ${Q("The first value.")}\n value2 (any) ${Q("The value to test against value1 for equality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return e=_s(e)?Is[typeof t]:e,t=_s(t)?Is[typeof e]:t,"string"==typeof e&&(e=e.toUpperCase()),"string"==typeof t&&(t=t.toUpperCase()),(e=Ne(e))===(t=Ne(t))}};function Ds(e,t,o){e=_s(e)?Is[typeof t]:e,t=_s(t)?Is[typeof e]:t,e=Ne(e),t=Ne(t),"number"!=typeof e&&(e=Se(e).toUpperCase()),"number"!=typeof t&&(t=Se(t).toUpperCase());const s=typeof e,n=typeof t;return"string"===s&&"number"===n||("string"!==n||"number"!==s)&&o(e,t)}const $s={description:Q("Strictly greater than."),args:De(`\n value1 (any) ${Q("The value to test as being greater than value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Ds(e,t,((e,t)=>e>t))}},Us={description:Q("Greater than or equal to."),args:De(`\n value1 (any) ${Q("The value to test as being greater than or equal to value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Ds(e,t,((e,t)=>e>=t))}},Fs={description:Q("Less than."),args:De(`\n value1 (any) ${Q("The value to test as being less than value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Us.compute(e,t)}},Ps={description:Q("Less than or equal to."),args:De(`\n value1 (any) ${Q("The value to test as being less than or equal to value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!$s.compute(e,t)}},Bs={description:Q("Difference of two numbers."),args:De(`\n value1 (number) ${Q("The minuend, or number to be subtracted from.")}\n value2 (number) ${Q("The subtrahend, or number to subtract from value1.")}\n `),returns:["NUMBER"],compute:function(e,t){return me(e)-me(t)}},zs={description:Q("Product of two numbers"),args:De(`\n factor1 (number) ${Q("The first multiplicand.")}\n factor2 (number) ${Q("The second multiplicand.")}\n `),returns:["NUMBER"],compute:function(e,t){return me(e)*me(t)}},Zs={description:Q("Not equal."),args:De(`\n value1 (any) ${Q("The first value.")}\n value2 (any) ${Q("The value to test against value1 for inequality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Os.compute(e,t)}},Hs={description:Q("A number raised to a power."),args:De(`\n base (number) ${Q("The number to raise to the exponent power.")}\n exponent (number) ${Q("The exponent to raise base to.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Lt.compute(e,t)}},Gs={description:Q("A number with the sign reversed."),args:De(`\n value (number) ${Q("The number to have its sign reversed. Equivalently, the number to multiply by -1.")}\n `),returns:["NUMBER"],compute:function(e){return-me(e)}},Vs={description:Q("Value interpreted as a percentage."),args:De(`\n percentage (number) ${Q("The value to interpret as a percentage.")}\n `),returns:["NUMBER"],compute:function(e){return me(e)/100}},js={description:Q("A specified number, unchanged."),args:De(`\n value (any) ${Q("The number to return.")}\n `),returns:["ANY"],compute:function(e){return e}};var qs=Object.freeze({__proto__:null,ADD:As,CONCAT:Ns,DIVIDE:ks,EQ:Os,GT:$s,GTE:Us,LT:Fs,LTE:Ps,MINUS:Bs,MULTIPLY:zs,NE:Zs,POW:Hs,UMINUS:Gs,UNARY_PERCENT:Vs,UPLUS:js});const Ws={description:Q("Gets character associated with number."),args:De(`\n table_number (number) ${Q("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(me(e));if(t<1)throw new Error(Q("Function CHAR parameter 1 value %s is out of range.",t.toString()));return String.fromCharCode(t)}},Ys={description:Q("Appends strings to one another."),args:De(`\n string1 (string, range<string>) ${Q("The initial string.")}\n string2 (string, range<string>, optional, repeating) ${Q("More strings to append in sequence.")}\n `),returns:["STRING"],compute:function(){return Ee(arguments,((e,t)=>e+Se(t)),"")}},Xs={description:Q("Tests whether two strings are identical."),args:De(`\n string1 (string) ${Q("The first string to compare.")}\n string2 (string) ${Q("The second string to compare.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Se(e)===Se(t)}},Ks={description:Q("First position of string found in text, case-sensitive."),args:De(`\n search_for (string) ${Q("The string to look for within text_to_search.")}\n text_to_search (string) ${Q("The text to search for the first occurrence of search_for.")}\n starting_at (number, optional, default=1 ) ${Q("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1){const s=Se(t);if(""===s)throw new Error(Q("Function FIND parameter 2 value should be non-empty."));const n=me(o);if(0===n)throw new Error(Q("Function FIND parameter 3 value is 0. It should be greater than or equal to 1."));const i=Se(e),r=s.indexOf(i,n-1);if(r<0)throw new Error(Q("In FIND evaluation, cannot find '%s' within '%s'.",i.toString(),s));return r+1}},Js={description:Q("Concatenates elements of arrays with delimiter."),args:De(`\n delimiter (string) ${Q("The character or string to place between each concatenated value.")}\n value_or_array1 (string, range<string>) ${Q("The value or values to be appended using delimiter.")}\n value_or_array2 (string, range<string>, optional, repeating) ${Q("More values to be appended using delimiter.")}\n `),returns:["STRING"],compute:function(e,...t){const o=Se(e);return Ee(t,((e,t)=>(e?e+o:"")+Se(t)),"")}},Qs={description:Q("Substring from beginning of specified string."),args:De(`\n text (string) ${Q("The string from which the left portion will be returned.")}\n number_of_characters (number, optional, default=1) ${Q("The number of characters to return from the left side of string.")}\n `),returns:["STRING"],compute:function(e,t=1){const o=me(t);if(o<0)throw new Error(Q("Function LEFT parameter 2 value is negative. It should be positive or zero."));return Se(e).substring(0,o)}},en={description:Q("Length of a string."),args:De(`\n text (string) ${Q("The string whose length will be returned.")}\n `),returns:["NUMBER"],compute:function(e){return Se(e).length}},tn={description:Q("Converts a specified string to lowercase."),args:De(`\n text (string) ${Q("The string to convert to lowercase.")}\n `),returns:["STRING"],compute:function(e){return Se(e).toLowerCase()}},on={description:Q("Replaces part of a text string with different text."),args:De(`\n text (string) ${Q("The text, a part of which will be replaced.")}\n position (number) ${Q("The position where the replacement will begin (starting from 1).")}\n length (number) ${Q("The number of characters in the text to be replaced.")}\n new_text (string) ${Q("The text which will be inserted into the original text.")}\n `),returns:["STRING"],compute:function(e,t,o,s){const n=me(t);if(n<1)throw new Error(Q("Function REPLACE parameter 2 value is %s. It should be greater than or equal to 1.",Se(n)));const i=Se(e),r=me(o),a=Se(s);return i.substring(0,n-1)+a+i.substring(n-1+r)}},sn={description:Q("A substring from the end of a specified string."),args:De(`\n text (string) ${Q("The string from which the right portion will be returned.")}\n number_of_characters (number, optional, default=1) ${Q("The number of characters to return from the right side of string.")}\n `),returns:["STRING"],compute:function(e,t=1){const o=me(t);if(o<0)throw new Error(Q("Function RIGHT parameter 2 value is negative. It should be positive or zero."));const s=Se(e),n=s.length;return s.substring(n-o,n)}},nn={description:Q("First position of string found in text, ignoring case."),args:De(`\n search_for (string) ${Q("The string to look for within text_to_search.")}\n text_to_search (string) ${Q("The text to search for the first occurrence of search_for.")}\n starting_at (number, optional, default=1 ) ${Q("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1){const s=Se(t).toLowerCase();if(""===s)throw new Error(Q("Function SEARCH parameter 2 value should be non-empty."));const n=me(o);if(0===n)throw new Error(Q("Function SEARCH parameter 3 value is 0. It should be greater than or equal to 1."));const i=Se(e).toLowerCase(),r=s.indexOf(i,n-1);if(r<0)throw new Error(Q("In SEARCH evaluation, cannot find '%s' within '%s'.",i,s));return r+1}},rn={description:Q("Replaces existing text with new text in a string."),args:De(`\n text_to_search (string) ${Q("The text within which to search and replace.")}\n search_for (string) ${Q("The string to search for within text_to_search.")}\n replace_with (string) ${Q("The string that will replace search_for.")}\n occurrence_number (number, optional) ${Q("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,o,s){const n=me(s);if(n<0)throw new Error(Q("Function SUBSTITUTE parameter 4 value is negative. It should be positive or zero."));const i=Se(e),r=Se(t);if(""===r)return i;const a=Se(o),l=new RegExp(r,"g");if(0===n)return i.replace(l,a);let c=0;return i.replace(l,(e=>++c===n?a:e))}},an={description:Q("Combines text from multiple strings and/or arrays."),args:De(`\n delimiter (string) ${Q(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")}\n ignore_empty (boolean) ${Q("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")}\n text1 (string, range<string>) ${Q("Any text item. This could be a string, or an array of strings in a range.")}\n text2 (string, range<string>, optional, repeating) ${Q("Additional text item(s).")}\n `),returns:["STRING"],compute:function(e,t,...o){const s=Se(e),n=ye(t);let i=0;return Ee(o,((e,t)=>n&&""===Se(t)?e:(i++?e+s:"")+Se(t)),"")}},ln={description:Q("Removes space characters."),args:De(`\n text (string) ${Q("The text or reference to a cell containing text to be trimmed.")}\n `),returns:["STRING"],compute:function(e){return Se(e).trim()}},cn={description:Q("Converts a specified string to uppercase."),args:De(`\n text (string) ${Q("The string to convert to uppercase.")}\n `),returns:["STRING"],compute:function(e){return Se(e).toUpperCase()}};const hn={database:Uo,date:ls,info:gs,lookup:Ms,logical:Cs,math:Pt,operators:qs,statistical:So,text:Object.freeze({__proto__:null,CHAR:Ws,CONCATENATE:Ys,EXACT:Xs,FIND:Ks,JOIN:Js,LEFT:Qs,LEN:en,LOWER:tn,REPLACE:on,RIGHT:sn,SEARCH:nn,SUBSTITUTE:rn,TEXTJOIN:an,TRIM:ln,UPPER:cn})};const un=new class extends _e{constructor(){super(...arguments),this.mapping={}}add(e,t){return e=e.toUpperCase().replace("_","."),function(e){let t=!1,o=!1;for(let s of e){if(t)throw new Error(Q("Function ${name} has at least 2 arguments that are repeating. The maximum repeating arguments is 1."));if(o&&!s.optional)throw new Error(Q("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=s.repeating,o=s.optional}}(t.args),this.mapping[e]=t.compute,super.add(e,t),this}};for(let e in hn){const t=hn[e];for(let o in t){const s=t[o];s.category=e,un.add(o,s)}}class dn{constructor(e,t,o,s,n){this.workbook=e,this.getters=t,this.history=Object.assign(Object.create(o),{updateLocalState:o.updateStateFromRoot.bind(o,this)}),this.dispatch=s,this.currentMode=n.mode,this.ui=n}allowDispatch(e){return{status:"SUCCESS"}}beforeHandle(e){}handle(e){}finalize(e){}drawGrid(e,t){}import(e){}export(e){}}dn.layers=[],dn.getters=[],dn.modes=["headless","normal","readonly"];const pn=new _e;pn.add("INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=(parseFloat(t.content)+e.current).toString();return{cellData:Object.assign({},t,{content:o}),tooltip:o?{props:{content:o}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t)=>({cellData:t,tooltip:t.content?{props:{content:t.content}}:void 0})}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let n=0,i=0;switch(s){case 0:n=0,i=-e.current;break;case 1:n=0,i=e.current;break;case 2:n=-e.current,i=0;break;case 3:n=e.current,i=0}const r=o.applyOffset(t.content,n,i);return{cellData:Object.assign({},t,{content:r}),tooltip:r?{props:{content:r}}:void 0}}});const gn=new _e;gn.add("simple_value_copy",{condition:(e,t)=>1===t.length&&["text","date","number"].includes(e.type),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("copy_text",{condition:e=>"text"===e.type,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>"formula"===e.type,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_number",{condition:e=>"number"===e.type,generateRule:(e,t)=>{const o=function(e,t){let o=[],s=!1;for(let n of t){if(n===e&&(s=!0),!n||"number"!==n.type){if(s)return o;o=[]}n&&"number"===n.type&&n.content&&o.push(n.content)}return o}(e,t);let s=1;return 2==o.length?s=2*(parseFloat(o[1])-parseFloat(o[0])):o.length>2&&(s=function(e){const t=[];let o=parseFloat(e[0]);for(let s=1;s<e.length;s++){const n=parseFloat(e[s]);t.push(n-o),o=n}return t.reduce(((e,t)=>e+t),0)/t.length}(o)*o.length),{type:"INCREMENT_MODIFIER",increment:s,current:0}},sequence:40});const{xml:fn,css:mn}=t.tags,{useRef:vn}=t.hooks,bn=fn`
1
+ !function(e,t){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var s=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,s.get?s:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var s=o(t);const n="#f5f5f5",i="#E8EAED",r="#595959",a="#666666",l="#3266ca",c=26,h=48,u=96,d=23,p=15,g=["#ff851b","#0074d9","#ffdc00","#7fdbff","#b10dc9","#0ecc40","#39cccc","#f012be","#3d9970","#111111","#01ff70","#ff4136","#aaaaaa","#85144b","#001f3f"];function f(e){return e.toString(16).padStart(6,"0")}let m=0;function v(){return m=++m%g.length,g[m]}function b(e){return e<26?String.fromCharCode(65+e):b(Math.floor(e/26)-1)+b(e%26)}function E(e){e=e.toUpperCase();const[t,o,s]=e.match(/\$?([A-Z]*)\$?([0-9]*)/);if(t!==e)throw new Error(`Invalid cell description: ${e}`);const n=function(e){let t=0;const o=e.length;for(let s=0;s<o;s++)t+=(e.charCodeAt(s)-65+(s<o-1?1:0))*26**(o-s-1);return t}(o);return[n,parseInt(s,10)-1]}function w(e,t){return b(e)+String(t+1)}function L(e){const t=(e=e.split("!").pop()).replace("$","").split(":");let o,s,n,i,r=E(t[0].trim());if(n=i=r[0],o=s=r[1],2===t.length){let e=E(t[1].trim());i=e[0],s=e[1],i<n&&([i,n]=[n,i]),s<o&&([s,o]=[o,s])}return{top:o,bottom:s,left:n,right:i}}function S(e){const{top:t,bottom:o,left:s,right:n}=e;return t===o&&s===n?w(s,t):`${w(s,t)}:${w(n,o)}`}function C(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 y(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function T(e,t){return!(e.bottom<t.top||t.bottom<e.top)&&!(e.right<t.left||t.right<e.left)}function x(e,t,o){const{left:s,right:n,top:i,bottom:r}=o;return e>=s&&e<=n&&t>=i&&t<=r}function R(e,t){const o={};for(let t of e){const e=L(t);for(let t=e.left;t<=e.right;t++)void 0===o[t]&&(o[t]=[]),o[t].push({top:e.top,bottom:e.bottom,remove:!1})}for(let e of t){const t=L(e);for(let e=t.left;e<=t.right;e++)void 0===o[e]&&(o[e]=[]),o[e].push({top:t.top,bottom:t.bottom,remove:!0})}const s=[];for(let[e,t]of Object.entries(o))s.push({col:parseInt(e),ranges:M(t)});return function(e){const t=e.sort(((e,t)=>e.col-t.col)),o=[];let s=[],n=0;for(let e=0;e<=t.length-1;e++){let i=[];if(n+1===t[e].col)for(let o of t[e].ranges){let n=!1;for(let e of s)o.top==e.top&&o.bottom==e.bottom&&(i.push(e),n=!0);n||i.push({top:o.top,bottom:o.bottom,startCol:t[e].col})}else i=t[e].ranges.map((o=>({top:o.top,bottom:o.bottom,startCol:t[e].col})));const r=s.filter((e=>!i.includes(e)));for(let e of r)o.push({top:e.top,bottom:e.bottom,left:e.startCol,right:n});n=t[e].col,s=i}for(let e of s)o.push({top:e.top,bottom:e.bottom,left:e.startCol,right:n});return o}(s).map(S)}function M(e){const t=new Set,o=new Set;for(let s of e)for(let e=s.top;e<=s.bottom;e++)s.remove?o.add(e):t.add(e);const s=[...t].filter((e=>!o.has(e))).sort(((e,t)=>e-t)),n=[];let i;for(let e of s)i?e===i.bottom+1?i.bottom=e:(n.push({top:i.top,bottom:i.bottom}),i={top:e,bottom:e}):i={top:e,bottom:e};return i&&n.push({top:i.top,bottom:i.bottom}),n}function A(e,t,o,s){const{top:n,bottom:i,left:r,right:a}=e,l=new Array(a-r+1);for(let e=r;e<=a;e++){let a=new Array(i-n+1);l[e-r]=a;for(let r=n;r<=i;r++){let i=t.rows[r].cells[e];a[r-n]=i?o(i):s}}return l}function N(e,t){let{left:o,right:s,top:n,bottom:i}=L(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)o>e&&(o-=1),(o>=e||s>=e)&&(s-=1);return o>s?null:w(o,n)+":"+w(s,i)}function k(e,t){let{left:o,right:s,top:n,bottom:i}=L(e);t=t.slice().sort(((e,t)=>t-e));for(let e of t)n>e&&(n-=1),(n>=e||i>=e)&&(i-=1);return n>i?null:w(o,n)+":"+w(s,i)}function _(e,t,o){let{left:s,right:n,top:i,bottom:r}=L(e);return s>=t&&(s+=o),(s>=t||n>=t)&&(n+=o),s>n?null:w(s,i)+":"+w(n,r)}function I(e,t,o){let{left:s,right:n,top:i,bottom:r}=L(e);return i>=t&&(i+=o),(i>=t||r>=t)&&(r+=o),i>r?null:w(s,i)+":"+w(n,r)}function O(e){return JSON.stringify(e,Object.keys(e).sort())}function D(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 o in e)t[o]=D(e[o]);return t;case"number":case"string":case"boolean":case"function":case"undefined":return e;default:throw new Error("Unsupported type: "+typeof e)}}function $(e){return e.startsWith("'")&&(e=e.slice(1,-1).replace(/''/g,"'")),e}function U(e){return e.includes(" ")&&(e=`'${e}'`),e}function F(e,t,o){return e<t?t:e>o?o:e}const P={},B=/^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?/,Z=/^-?\d+(,\d+)*(\.?\d*(e\d+)?)?(\s*%)?$|^-?\.\d+(\s*%)?$/;function z(e){return Z.test(e.trim())}const H=/,/g;function G(e){let t=Number(e.replace(H,""));return isNaN(t)&&e.includes("%")&&(t=Number(e.split("%")[0]),!isNaN(t))?t/100:t}const V=new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:10});function j(e){return Number.isInteger(e)?e.toString():V.format(e)}let q=[];function W(e,t,o=""){if(e<0)return"-"+W(-e,t);const s=t>=20?20:t;let n=q[s];n||(n=new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s,useGrouping:!1}),q[s]=n);let i=n.format(e);if(o){let e=i.indexOf(".");i=i.replace(/\d(?=(?:\d{3})+(?:\.|$))/g,((t,s)=>e<0||s<e?`${t}${o}`:t))}return i}function Y(e,t){const o=t.split(";"),s=o.length;if(e<0)return s>1?X(-e,o[1]):"-"+X(-e,o[0]);return X(e,o[3===s&&0===e?2:0])}function X(e,t){const o=t.split("."),s=1===o.length?0:o[1].match(/0/g).length,n=o[0].includes(",")?",":"",i=t.includes("%");i&&(e*=100);const r=W(e,s,n);return i?r+"%":r}function K(){return 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)}))}let J=e=>e;const Q=function(e,...t){return{toString:function(){return function(e,...t){if(1===t.length&&"object"==typeof t[0]){const o=t[0];e=e.replace(/%\(?([^\)]+)\)s/g,((e,t)=>o[t]))}else t.length>0&&(e=e.replace(/\%s/g,(()=>t.shift())));return e}(J(e),...t)}}},ee=2e3,te=(new Date).getFullYear(),oe=new Date(1899,11,30),se=new Date(0)-oe,ne=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,ie=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,re=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function ae(e){let t;const o=(e=e.trim()).match(re);if(o){if(t=function(e){if(e=e.trim(),re.test(e)){const t=/AM/i.test(e),o=/PM/i.test(e),s=(t||o?e.substring(0,e.length-2).trim():e).split(/:/),n=s.length>=2,i=3===s.length;let r=Number(s[0]),a=n?Number(s[1]):0,l=i?Number(s[2]):0,c=i?"hh:mm:ss":"hh:mm";if(t||o)c+=" a";else if(!n)return null;r>=12&&t?r-=12:r<12&&o&&(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 Date(1899,11,30,r,a,l)}}return null}(o[0]),null===t)return null;e=e.replace(o[0],"").trim()}let s;const n=e.match(ne),i=e.match(ie);if(n||i){let t;if(n?(t=n[0],s=le(t,"mdy")):(t=i[0],s=le(t,"ymd")),null===s)return null;e=e.replace(t,"").trim()}return""!==e||!s&&!t?null:s&&t?{value:s.value+t.value,format:s.format+" "+("hhhh:mm:ss"===t.format?"hh:mm:ss":t.format),jsDate:new Date(s.jsDate.getFullYear()+t.jsDate.getFullYear()-1899,s.jsDate.getMonth()+t.jsDate.getMonth()-11,s.jsDate.getDate()+t.jsDate.getDate()-30,s.jsDate.getHours()+t.jsDate.getHours(),s.jsDate.getMinutes()+t.jsDate.getMinutes(),s.jsDate.getSeconds()+t.jsDate.getSeconds())}:s||t}function le(e,t){const o="mdy"===t;if(o||"ymd"===t){const t=e.split(/\/|-|\s/),s=o?0:1,n=o?1:2,i=o?2:0,r=Number(t[s]),a=Number(t[n]),l=2===t[s].length&&r<10||2===t[n].length&&a<10,c=t[i]?function(e){const t=Number(e);switch(e.length){case 1:return ee+t;case 2:return ee+(ee+t>te+10?-100:0)+t;case 3:case 4:return t}return 0}(t[i]):te,h=new Date(c,r-1,a),u=e.match(/\/|-|\s/)[0];if(h.getMonth()!==r-1||h.getDate()!==a)return null;const d=h-oe;let p=l?`mm${u}dd`:`m${u}d`;return t[i]&&(p=o?p+u+"yyyy":"yyyy"+u+p),{value:Math.round(d/864e5),format:p,jsDate:h}}return null}function ce(e){if("object"==typeof e&&null!==e)return e.jsDate||(e.jsDate=new Date(86400*e.value*1e3-se)),e.jsDate;if("string"==typeof e){let t=ae(e);if(null!==t&&t.jsDate)return t.jsDate}return function(e){const t=Math.trunc(e);let o=new Date(86400*t*1e3-se),s=e-t;s=s<0?1+s:s;const n=Math.round(24*s),i=Math.round(24*(s-n/24)*60),r=Math.round(24*(s-n/24-i/24/60)*60*60);return o.setHours(n),o.setMinutes(i),o.setSeconds(r),o}(me(e))}function he(e,t){const o=t||e.format,s=ce(e),n=o.indexOf("h");let i="",r="";return n>0?(i=ue(s,o.substring(0,n-1)),r=de(s,o.substring(n))):0===n?r=de(s,o):n<0&&(i=ue(s,o)),i+(i&&r?" ":"")+r}function ue(e,t){const o=t.match(/\/|-|\s/)[0];return t.split(o).map((t=>{switch(t){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(Q("invalid format"))}})).join(o)}function de(e,t){let o=t.split(/:|\s/);const s=e.getHours(),n="a"===o[o.length-1];let i=s,r="";return n&&(i=0===i?12:i>12?i-12:i,r=s>=12?" PM":" AM",o.pop()),o.map((t=>{switch(t){case"hhhh":return Math.floor((e.getTime()-oe)/36e5).toString();case"hh":return i.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")}})).join(":")+r}const pe=new Date(1899,11,30),ge=new Date(0)-pe,fe=e=>Q("The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.",e);function me(e){switch(typeof e){case"number":return e;case"boolean":return e?1:0;case"string":if(z(e)||""===e)return G(e);const t=ae(e);if(t)return t.value;throw new Error(fe(e));case"object":return null!==e&&e.jsDate?e.value:e||0;default:return e||0}}function ve(e){if(""===e)throw new Error(fe(e));return me(e)}function be(e,t){if(Array.isArray(e))for(let o of e)for(let e of o)t(e);else t(e)}function Ee(e,t,o){let s=o;for(let o of e)be(o,(e=>{s=t(s,e)}));return s}function we(e,t,o){let s=o;return function(e,t){for(let o of e)if(Array.isArray(o))for(let e of o)for(let o of e)"number"==typeof o?t(o):"object"==typeof o&&null!==o&&o.jsDate&&t(o.value);else t(ve(o))}(e,(e=>{s=t(s,e)})),s}function Le(e,t,o){let s=o;return function(e,t){for(let o of e)if(Array.isArray(o))for(let e of o)for(let o of e)null!=o&&("number"==typeof o?t(o):"boolean"==typeof o?t(me(o)):"object"==typeof o&&null!==o&&o.jsDate?t(o.value):t(0));else t(me(o))}(e,(e=>{s=t(s,e)})),s}function Se(e){switch(typeof e){case"string":return e;case"number":return e.toString();case"boolean":return e?"TRUE":"FALSE";default:return""}}const Ce=e=>Q("The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a number.",e);function ye(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(Ce(e))}return!1;case"number":return!!e;default:return!1}}function Te(e,t){!function(e,t,o){for(let s of e)if(Array.isArray(s)){for(let e of s)for(let o of e)if(!t(o))return}else if(!o(s))return}(e,(e=>"boolean"==typeof e?t(e):"number"!=typeof e||t(!!e)),(e=>null===e||t(function(e){if(""===e)throw new Error(Ce(e));return ye(e)}(e))))}function xe(e,t){let o,s,n=e.substring(0,2);"<="===n||">="===n||"<>"===n?(o=n,s=e.substring(2)):(n=e.substring(0,1),"<"===n||">"===n||"="===n?(o=n,s=e.substring(1)):(o="=",s=e)),z(s)?s=me(s):"TRUE"!==s&&"FALSE"!==s||(s=ye(s));const i={operator:o,operand:s};return"string"==typeof s&&(t&&(s+="*"),i.regexp=function(e){let t="",o="";for(let s of e)"?"===s&&"~"!==o?t+=".":"*"===s&&"~"!==o?t+=".*":("*"!==s&&"?"!==s||(t=t.slice(0,-1)),["^",".","[","]","$","(",")","*","+","?","|","{","}","\\"].includes(s)&&(t+="\\"),t+=s),o=s;return new RegExp("^"+t+"$","i")}(s)),i}function Re(e,t){const{operator:o,operand:s}=t;if("number"==typeof s&&"="===o)return Se(e)===Se(s);if("<>"===o||"="===o){let n;return n=typeof e==typeof s&&(t.regexp?t.regexp.test(e):e===s),"="===o?n:!n}if(typeof e==typeof s)switch(o){case"<":return e<s;case">":return e>s;case"<=":return e<=s;case">=":return e>=s}return!1}function Me(e,t,o=!1){const s=e.length;if(s%2==1)throw new Error(Q("Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs."));const n=e[0].length,i=e[0][0].length;let r=[];for(let t=0;t<s-1;t+=2){const s=e[t];if(s.length!==n||s[0].length!==i)throw new Error(Q("Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension"));const a=Se(e[t+1]);r.push(xe(a,o))}for(let o=0;o<n;o++)for(let n=0;n<i;n++){let i=!0;for(let t=0;t<s-1;t+=2){if(i=Re(e[t][o][n],r[t/2]),!i)break}i&&t(o,n)}}function Ae(e,t){const o=typeof t;let s,n,i,r,a,l,c=0,h=e.length-1;if(typeof e[c]===o&&t<e[c])return-1;if(typeof e[h]===o&&e[h]<=t)return h;for(;h-c>=0;){for(i=Math.ceil((c+h)/2),r=i,a=e[r],l=typeof a;c<=r&&o!==l;)r--,a=e[r],l=typeof a;l===o&&a<=t&&(void 0===s||s<a||s===a&&n<r)&&(s=a,n=r),l===o&&a>t?h=r-1:c=i+1}return void 0!==n?n:-1}function Ne(e){return"object"==typeof e&&e.jsDate?e.value:e}function ke(e){const t=Math.trunc(e);let o=new Date(864e5*t-ge),s=e-t;s=s<0?1+s:s;const n=Math.round(24*s),i=Math.round(24*(s-n/24)*60),r=Math.round(24*(s-n/24-i/24/60)*60*60);return o.setHours(n),o.setMinutes(i),o.setSeconds(r),o}class _e{constructor(){this.content={}}add(e,t){return this.content[e]=t,this}get(e){if(!(e in this.content))throw new Error(`Cannot find ${e} in this registry!`);return this.content[e]}getAll(){return Object.values(this.content)}remove(e){delete this.content[e]}}const Ie=/(.*?)\((.*?)\)(.*)/,Oe=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>"];function De(e){let t=e.split("\n");const o=[];for(let e of t)e=e.trim(),e&&o.push($e(e));return o}function $e(e){let t,o=e.match(Ie),s=o[1].trim(),n=[],i=!1,r=!1,a=!1;for(let e of o[2].split(",")){const o=e.trim().toUpperCase();let s=Oe.find((e=>o===e));if(s)n.push(s);else if("RANGE<ANY>"===o)n.push("RANGE");else if("OPTIONAL"===o)i=!0;else if("REPEATING"===o)r=!0;else if("LAZY"===o)a=!0;else if(o.startsWith("DEFAULT=")){const o=e.trim().slice(8);t='"'===o[0]?o.slice(1,-1):parseFloat(o)}}const l={name:s,description:o[3].trim(),type:n};return i&&(l.optional=!0),r&&(l.repeating=!0),a&&(l.lazy=!0),void 0!==t&&(l.default=t),l}const Ue={description:Q("Inverse cosine of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(Math.abs(t)>1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values are between -1 and 1 inclusive.",t.toString()));return Math.acos(t)}},Fe={description:Q("Inverse hyperbolic cosine of a number."),args:De(`\n value (number) ${Q("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=me(e);if(t<1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. It should be greater than or equal to 1.",t.toString()));return Math.acosh(t)}},Pe={description:Q("Inverse cotangent of a value."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse cotangent.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)}},Be={description:Q("Inverse hyperbolic cotangent of a value."),args:De(`\n value (number) ${Q("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=me(e);if(Math.abs(t)<=1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values cannot be between -1 and 1 inclusive.",t.toString()));return Math.log((t+1)/(t-1))/2}},Ze={description:Q("Inverse sine of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(Math.abs(t)>1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %S. Valid values are between -1 and 1 inclusive.",t.toString()));return Math.asin(t)}},ze={description:Q("Inverse hyperbolic sine of a number."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse hyperbolic sine.")}\n `),returns:["NUMBER"],compute:function(e){return Math.asinh(me(e))}},He={description:Q("Inverse tangent of a value, in radians."),args:De(`\n value (number) ${Q("The value for which to calculate the inverse tangent.")}\n `),returns:["NUMBER"],compute:function(e){return Math.atan(me(e))}},Ge={description:Q("Angle from the X axis to a point (x,y), in radians."),args:De(`\n x (number) ${Q("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")}\n y (number) ${Q("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 o=me(e),s=me(t);if(0===o&&0===s)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return Math.atan2(s,o)}},Ve={description:Q("Inverse hyperbolic tangent of a number."),args:De(`\n value (number) ${Q("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=me(e);if(Math.abs(t)>=1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. Valid values are between -1 and 1 exclusive.",t.toString()));return Math.atanh(t)}},je={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n value (number) ${Q("The value to round up to the nearest integer multiple of factor.")}\n factor (number, optional, default=1) ${Q("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=me(e),s=me(t);if(o>0&&s<0)throw new Error(Q("Function CEILING expects the parameter '%s' to be positive when parameter '%s' is positive. Change '%s' from [%s] to a positive value.",je.args[1].name,je.args[0].name,je.args[1].name,s.toString()));return s?Math.ceil(o/s)*s:0}},qe={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, optional, default=0) ${Q("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"],compute:function(e,t=1,o=0){let s=me(t);if(0===s)return 0;const n=me(e);if(s=Math.abs(s),n>=0)return Math.ceil(n/s)*s;return 0===me(o)?-Math.floor(Math.abs(n)/s)*s:-Math.ceil(Math.abs(n)/s)*s}},We={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t){return qe.compute(e,t,0)}},Ye={description:Q("Cosine of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cosine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cos(me(e))}},Xe={description:Q("Hyperbolic cosine of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cosine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.cosh(me(e))}},Ke={description:Q("Cotangent of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cotangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.tan(t)}},Je={description:Q("Hyperbolic cotangent of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cotangent of.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.tanh(t)}},Qe={description:Q("Number of empty values."),args:De(`\n value1 (any, range) ${Q("The first value or range in which to count the number of blanks.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges in which to count the number of blanks.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>null==t||""===t?e+1:e),0)}},et={description:Q("A conditional count across a range."),args:De(`\n range (range) ${Q("The range that is tested against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to range.")}\n `),returns:["NUMBER"],compute:function(){let e=0;return Me(arguments,((t,o)=>{e+=1})),e}},tt={description:Q("Count values depending on multiple criteria."),args:De(`\n criteria_range (range) ${Q("The range to check against criterion1.")}\n criterion (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(){let e=0;return Me(arguments,((t,o)=>{e+=1})),e}};function ot(e){switch(e){case void 0:case"":case null:return!1;default:return!0}}const st={description:Q("Counts number of unique values in a range."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider for uniqueness.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider for uniqueness.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>ot(t)?e.add(t):e),new Set).size}},nt={description:Q("Counts number of unique values in a range, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the number of unique values will be counted.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=new Set;return Me(t,((t,s)=>{const n=e[t][s];ot(n)&&o.add(n)})),o.size}},it={description:Q("Cosecant of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the cosecant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.sin(t)}},rt={description:Q("Hyperbolic cosecant of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic cosecant of.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(0===t)throw new Error(Q("Function [[FUNCTION_NAME]] caused a divide by zero error."));return 1/Math.sinh(t)}},at=(e,t,o)=>Q("Function DECIMAL expects the parameter '%s' to be a valid base %s representation. Change '%s' from [%s] to a valid base %s representation.",e,t,e,o,t),lt={description:Q("Converts from another base to decimal."),args:De(`\n value (string) ${Q("The number to convert.")},\n base (number) ${Q("The base to convert the value from.")},\n `),returns:["NUMBER"],compute:function(e,t){let o=me(t);if(o=Math.floor(o),o<2||o>36)throw new Error(Q("Function DECIMAL expects the parameter '%s' to be between 2 and 36 inclusive. Change '%s' from [%s] to a value between 2 and 36.",lt.args[1].name,lt.args[1].name,o.toString()));const s=Se(e);if(""===s)return 0;if(!s.match(/^-?[a-z0-9]+$/i))throw new Error(at(lt.args[0].name,o,s));const n=parseInt(s,o);if(isNaN(n))throw new Error(at(lt.args[0].name,o,s));return n}},ct={description:Q("Converts an angle value in radians to degrees."),args:De(`\n angle (number) ${Q("The angle to convert from radians to degrees.")}\n `),returns:["NUMBER"],compute:function(e){return 180*me(e)/Math.PI}},ht={description:Q("Euler's number, e (~2.718) raised to a power."),args:De(`\n value (number) ${Q("The exponent to raise e.")}\n `),returns:["NUMBER"],compute:function(e){return Math.exp(me(e))}},ut={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n value (number) ${Q("The value to round down to the nearest integer multiple of factor.")}\n factor (number, optional, default=1) ${Q("The number to whose multiples value will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=me(e),s=me(t);if(o>0&&s<0)throw new Error(Q("Function FLOOR expects the parameter '%s' to be positive when parameter '%s' is positive. Change '%s' from [%s] to a positive value.",ut.args[1].name,ut.args[0].name,ut.args[1].name,s.toString()));return s?Math.floor(o/s)*s:0}},dt={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round down to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded. The sign of significance will be ignored.")}\n mode (number, optional, default=0) ${Q("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"],compute:function(e,t=1,o=0){let s=me(t);if(0===s)return 0;const n=me(e);if(s=Math.abs(s),n>=0)return Math.floor(n/s)*s;return 0===me(o)?-Math.ceil(Math.abs(n)/s)*s:-Math.floor(Math.abs(n)/s)*s}},pt={description:Q("Rounds number down to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round down to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t=1){return dt.compute(e,t,0)}},gt={description:Q("Whether the provided value is even."),args:De(`\n value (number) ${Q("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=ve(e);return!(1&Math.floor(Math.abs(t)))}},ft={description:Q("Rounds number up to nearest multiple of factor."),args:De(`\n number (number) ${Q("The value to round up to the nearest integer multiple of significance.")}\n significance (number, optional, default=1) ${Q("The number to whose multiples number will be rounded.")}\n `),returns:["NUMBER"],compute:function(e,t){return qe.compute(e,t,0)}},mt={description:Q("Whether the provided value is even."),args:De(`\n value (number) ${Q("The value to be verified as even.")}\n `),returns:["BOOLEAN"],compute:function(e){const t=ve(e);return!!(1&Math.floor(Math.abs(t)))}},vt={description:Q("The logarithm of a number, base e (euler's number)."),args:De(`\n value (number) ${Q("The value for which to calculate the logarithm, base e.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(t<=0)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 1 value is %s. It should be greater than 0.",t.toString()));return Math.log(t)}},bt={description:Q("Modulo (remainder) operator."),args:De(`\n dividend (number) ${Q("The number to be divided to find the remainder.")}\n divisor (number) ${Q("The number to divide by.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(t);if(0===o)throw new Error(Q("Function MOD expects the parameter '%s' to be different from 0. Change '%s' to a value other than 0.",bt.args[1].name,bt.args[1].name));const s=me(e)%o;return s>0&&o<0||s<0&&o>0?s+o:s}},Et={description:Q("Rounds a number up to the nearest odd integer."),args:De(`\n value (number) ${Q("The value to round to the next greatest odd number.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);let o=Math.ceil(Math.abs(t));return o=1&o?o:o+1,t<0?-o:o}},wt={description:Q("The number pi."),args:[],returns:["NUMBER"],compute:function(){return Math.PI}},Lt={description:Q("A number raised to a power."),args:De(`\n base (number) ${Q("The number to raise to the exponent power.")}\n exponent (number) ${Q("The exponent to raise base to.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(e),s=me(t);if(o>=0)return Math.pow(o,s);if(!Number.isInteger(s))throw new Error(Q("Function POWER expects the parameter '%s' to be an integer when parameter '%s' is negative. Change '%s' from [%s] to an integer value.",Lt.args[1].name,Lt.args[0].name,Lt.args[1].name,s.toString()));return Math.pow(o,s)}},St={description:Q("Result of multiplying a series of numbers together."),args:De(`\n factor1 (number, range<number>) ${Q("The first number or range to calculate for the product.")}\n factor2 (number, range<number>, optional, repeating) ${Q("More numbers or ranges to calculate for the product.")}\n `),returns:["NUMBER"],compute:function(){let e=0,t=1;for(let o of arguments)if(Array.isArray(o))for(let s of o)for(let o of s)"number"==typeof o&&(t*=o,e+=1);else null!==o&&(t*=ve(o),e+=1);return 0===e?0:t}},Ct={description:Q("A random number between 0 inclusive and 1 exclusive."),args:[],returns:["NUMBER"],compute:function(){return Math.random()}},yt={description:Q("Random integer between two values, inclusive."),args:De(`\n low (number) ${Q("The low end of the random range.")}\n high (number) ${Q("The high end of the random range.")}\n `),returns:["NUMBER"],compute:function(e,t){let o=me(e);Number.isInteger(o)||(o=Math.ceil(o));let s=me(t);if(Number.isInteger(s)||(s=Math.floor(s)),s<o)throw new Error(Q("Function RANDBETWEEN parameter '%s' value is %s. It should be greater than or equal to [%s].",yt.args[1].name,s.toString(),o.toString()));return o+Math.ceil((s-o+1)*Math.random())-1}},Tt={description:Q("Rounds a number according to standard rules."),args:De(`\n value (number) ${Q("The value to round to places number of places.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.round(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.round(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},xt={description:Q("Rounds down a number."),args:De(`\n value (number) ${Q("The value to round to places number of places, always rounding down.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.floor(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.floor(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},Rt={description:Q("Rounds up a number."),args:De(`\n value (number) ${Q("The value to round to places number of places, always rounding up.")}\n places (number, optional, default=0) ${Q("The number of decimal places to which to round.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(e);let s=me(t);const n=Math.abs(o);let i;return 0===s?i=Math.ceil(n):(Number.isInteger(s)||(s=Math.trunc(s)),i=Math.ceil(n*Math.pow(10,s))/Math.pow(10,s)),o>=0?i:-i}},Mt={description:Q("Secant of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the secant of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cos(me(e))}},At={description:Q("Hyperbolic secant of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic secant of.")}\n `),returns:["NUMBER"],compute:function(e){return 1/Math.cosh(me(e))}},Nt={description:Q("Sine of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the sine of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sin(me(e))}},kt={description:Q("Hyperbolic sine of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic sine of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.sinh(me(e))}},_t={description:Q("Positive square root of a positive number."),args:De(`\n value (number) ${Q("The number for which to calculate the positive square root.")}\n `),returns:["NUMBER"],compute:function(e){const t=me(e);if(t<0)throw new Error(Q("Function SQRT parameter '%s' value is negative. It should be positive or zero. Change '%s' from [%s] to a positive value.",_t.args[0].name,_t.args[0].name,t.toString()));return Math.sqrt(t)}},It={description:Q("Sum of a series of numbers and/or cells."),args:De(`\n value1 (number, range<number>) ${Q("The first number or range to add together.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional numbers or ranges to add to value1.")}\n `),returns:["NUMBER"],compute:function(){return we(arguments,((e,t)=>e+t),0)}},Ot={description:Q("A conditional sum across a range."),args:De(`\n criteria_range (range) ${Q("The range which is tested against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to range.")}\n sum_range (range, optional, default=criteria_range) ${Q("The range to be summed, if different from range.")}\n `),returns:["NUMBER"],compute:function(e,t,o){void 0===o&&(o=e);let s=0;return Me([e,t],((e,t)=>{const n=o[e][t];"number"==typeof n&&(s+=n)})),s}},Dt={description:Q("Sums a range depending on multiple criteria."),args:De(`\n sum_range (range) ${Q("The range to sum.")}\n criteria_range1 (range) ${Q("The range to check against criterion1.")}\n criterion1 (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o+=n)})),o}},$t={description:Q("Tangent of an angle provided in radians."),args:De(`\n angle (number) ${Q("The angle to find the tangent of, in radians.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tan(me(e))}},Ut={description:Q("Hyperbolic tangent of any real number."),args:De(`\n value (number) ${Q("Any real value to calculate the hyperbolic tangent of.")}\n `),returns:["NUMBER"],compute:function(e){return Math.tanh(me(e))}},Ft={description:Q("Truncates a number."),args:De(`\n value (number) ${Q("The value to be truncated.")}\n places (number, optional, default=0) ${Q("The number of significant digits to the right of the decimal point to retain.")}\n `),returns:["NUMBER"],compute:function(e,t=0){const o=me(e);let s=me(t);return 0===s?Math.trunc(o):(Number.isInteger(s)||(s=Math.trunc(s)),Math.trunc(o*Math.pow(10,s))/Math.pow(10,s))}};var Pt=Object.freeze({__proto__:null,ACOS:Ue,ACOSH:Fe,ACOT:Pe,ACOTH:Be,ASIN:Ze,ASINH:ze,ATAN:He,ATAN2:Ge,ATANH:Ve,CEILING:je,CEILING_MATH:qe,CEILING_PRECISE:We,COS:Ye,COSH:Xe,COT:Ke,COTH:Je,COUNTBLANK:Qe,COUNTIF:et,COUNTIFS:tt,COUNTUNIQUE:st,COUNTUNIQUEIFS:nt,CSC:it,CSCH:rt,DECIMAL:lt,DEGREES:ct,EXP:ht,FLOOR:ut,FLOOR_MATH:dt,FLOOR_PRECISE:pt,ISEVEN:gt,ISO_CEILING:ft,ISODD:mt,LN:vt,MOD:bt,ODD:Et,PI:wt,POWER:Lt,PRODUCT:St,RAND:Ct,RANDBETWEEN:yt,ROUND:Tt,ROUNDDOWN:xt,ROUNDUP:Rt,SEC:Mt,SECH:At,SIN:Nt,SINH:kt,SQRT:_t,SUM:It,SUMIF:Ot,SUMIFS:Dt,TAN:$t,TANH:Ut,TRUNC:Ft});function Bt(e,t,o){let s=[],n=[],i=0,r=0;if(be(e,(e=>{s.push(e),i+=1})),be(t,(e=>{n.push(e),r+=1})),i!==r)throw new Error(Q("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",i.toString(),r.toString()));let a=0,l=0,c=0;for(let e=0;e<i;e++){const t=s[e],o=n[e];"number"==typeof t&&"number"==typeof o&&(a+=1,l+=t,c+=o)}if(0===a||o&&1===a)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const h=l/a,u=c/a;let d=0;for(let e=0;e<i;e++){const t=s[e],o=n[e];"number"==typeof t&&"number"==typeof o&&(d+=(t-h)*(o-u))}return d/(a-(o?1:0))}function Zt(e,t,o){let s=0,n=0;const i=o?Le:we;if(n=i(e,((e,t)=>(s+=1,e+t)),0),0===s||t&&1===s)throw new Error(Q("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."));const r=n/s;return i(e,((e,t)=>e+Math.pow(t-r,2)),0)/(s-(t?1:0))}const zt={description:Q("Average magnitude of deviations from mean."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=we(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVEDEV caused a divide by zero error."));const o=t/e;return we(arguments,((e,t)=>e+Math.abs(o-t)),0)/e}},Ht={description:Q("Numerical average value in a dataset, ignoring text."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=we(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVERAGE caused a divide by zero error."));return t/e}},Gt=Q("AVERAGE.WEIGHTED has mismatched range sizes."),Vt=Q("AVERAGE.WEIGHTED expects the weight to be positive or equal to 0."),jt={description:Q("Weighted average."),args:De(`\n values (number, range<number>) ${Q("Values to average.")}\n weights (number, range<number>) ${Q("Weights for each corresponding value.")}\n additional_values (number, range<number>, optional, repeating) ${Q("Additional values to average with weights.")}\n `),returns:["NUMBER"],compute:function(){let e,t,o=0,s=0;if(arguments.length%2==1)throw new Error(Q("Wrong number of arguments. Expected an even number of arguments."));for(let n=0;n<arguments.length-1;n+=2)if(e=arguments[n],t=arguments[n+1],Array.isArray(e)){if(!Array.isArray(t))throw new Error(Gt);let n=e.length,i=e[0].length;if(n!==t.length||i!=t[0].length)throw new Error(Gt);for(let r=0;r<n;r++)for(let n=0;n<i;n++){let i=e[r][n],a=t[r][n],l="number"==typeof a;if("number"==typeof i!==l)throw new Error(Q("AVERAGE.WEIGHTED expects number values."));if(l){if(a<0)throw new Error(Vt);o+=i*a,s+=a}}}else{if(t=me(t),e=me(e),t<0)throw new Error(Vt);o+=e*t,s+=t}if(0===s)throw new Error(Q("Evaluation of function AVERAGE.WEIGHTED caused a divide by zero error."));return o/s}},qt={description:Q("Numerical average value in a dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the average value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the average value.")}\n `),returns:["NUMBER"],compute:function(){let e=0;const t=Le(arguments,((t,o)=>(e+=1,t+o)),0);if(0===e)throw new Error(Q("Evaluation of function AVERAGEA caused a divide by zero error."));return t/e}},Wt={description:Q("Average of values depending on criteria."),args:De(`\n criteria_range (range) ${Q("The range to check against criterion.")}\n criterion (string) ${Q("The pattern or test to apply to criteria_range.")}\n average_range (range, optional, default=criteria_range) ${Q("The range to average. If not included, criteria_range is used for the average instead.")}\n `),returns:["NUMBER"],compute:function(e,t,o){void 0===o&&(o=e);let s=0,n=0;if(Me([e,t],((e,t)=>{const i=o[e][t];"number"==typeof i&&(s+=1,n+=i)})),0===s)throw new Error(Q("Evaluation of function AVERAGEIF caused a divide by zero error."));return n/s}},Yt={description:Q("Average of values depending on multiple criteria."),args:De(`\n average_range (range) ${Q("The range to average.")}\n criteria_range1 (range) ${Q("The range to check against criterion1.")}\n criterion1 (string) ${Q("The pattern or test to apply to criteria_range1.")}\n additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=0,s=0;if(Me(t,((t,n)=>{const i=e[t][n];"number"==typeof i&&(o+=1,s+=i)})),0===o)throw new Error(Q("Evaluation of function AVERAGEIFS caused a divide by zero error."));return s/o}},Xt={description:Q("The number of numeric values in dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when counting.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(){let e=0;for(let t of arguments)if(Array.isArray(t))for(let o of t)for(let t of o)("number"==typeof t||"object"==typeof t&&null!==t&&t.jsDate)&&(e+=1);else("string"!=typeof t||z(t)||ae(t))&&(e+=1);return e}},Kt={description:Q("The number of values in a dataset."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider when counting.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider when counting.")}\n `),returns:["NUMBER"],compute:function(){return Ee(arguments,((e,t)=>null!=t?e+1:e),0)}},Jt={description:Q("The covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!1)}},Qt={description:Q("The covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!1)}},eo={description:Q("The sample covariance of a dataset."),args:De(`\n data_y (any, range) ${Q("The range representing the array or matrix of dependent data.")}\n data_x (any, range) ${Q("The range representing the array or matrix of independent data.")}\n `),returns:["NUMBER"],compute:function(e,t){return Bt(e,t,!0)}},to={description:Q("Nth largest element from a data set."),args:De(`\n data (any, range) ${Q("Array or range containing the dataset to consider.")}\n n (number) ${Q("The rank from largest to smallest of the element to return.")}\n `),returns:["NUMBER"],compute:function(e,t){t=Math.trunc(me(t));let o,s=[],n=0;be(e,(e=>{"number"==typeof(e=Ne(e))&&(o=Ae(s,e),s.splice(o+1,0,e),n++,n>t&&(s.shift(),n--))}));const i=s.shift();if(void 0===i)throw new Error(Q("LARGE has no valid input data."));if(n<t)throw new Error(Q("Function LARGE parameter 2 value %s is out of range.",t.toString()));return i}},oo={description:Q("Maximum value in a numeric dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the maximum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],compute:function(){const e=we(arguments,((e,t)=>e<t?t:e),-1/0);return e===-1/0?0:e}},so={description:Q("Maximum numeric value in a dataset."),args:De(`\n value1 (any, range) ${Q("The first value or range to consider when calculating the maximum value.")}\n value2 (any, range, optional, repeating) ${Q("Additional values or ranges to consider when calculating the maximum value.")}\n `),returns:["NUMBER"],compute:function(){const e=Le(arguments,((e,t)=>Math.max(t,e)),-1/0);return e===-1/0?0:e}},no={description:Q("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the maximum will be determined.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=-1/0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o=o<n?n:o)})),o===-1/0?0:o}},io={description:Q("Minimum value in a numeric dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],compute:function(){const e=we(arguments,((e,t)=>t<e?t:e),1/0);return e===1/0?0:e}},ro={description:Q("Minimum numeric value in a dataset."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range to consider when calculating the minimum value.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to consider when calculating the minimum value.")}\n `),returns:["NUMBER"],compute:function(){const e=Le(arguments,((e,t)=>Math.min(t,e)),1/0);return e===1/0?0:e}},ao={description:Q("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:De(`\n range (range) ${Q("The range of cells from which the minimum will be determined.")}\n criteria_range1 (range) ${Q("The range of cells over which to evaluate criterion1.")}\n criterion1 (string) ${Q("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 additional_values (any, range, optional, repeating) ${Q("Additional criteria_range and criterion to check.")}\n `),returns:["NUMBER"],compute:function(e,...t){let o=1/0;return Me(t,((t,s)=>{const n=e[t][s];"number"==typeof n&&(o=o>n?n:o)})),o===1/0?0:o}},lo={description:Q("Nth smallest element in a data set."),args:De(`\n data (any, range) ${Q("The array or range containing the dataset to consider.")}\n n (number) ${Q("The rank from smallest to largest of the element to return.")}\n `),returns:["NUMBER"],compute:function(e,t){t=Math.trunc(me(t));let o,s=[],n=0;be(e,(e=>{"number"==typeof(e=Ne(e))&&(o=Ae(s,e),s.splice(o+1,0,e),n++,n>t&&(s.pop(),n--))}));const i=s.pop();if(void 0===i)throw new Error(Q("SMALL has no valid input data."));if(n<t)throw new Error(Q("Function SMALL parameter 2 value %s is out of range.",t.toString()));return i}},co={description:Q("Standard deviation."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(mo.compute(...arguments))}},ho={description:Q("Standard deviation of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(vo.compute(...arguments))}},uo={description:Q("Standard deviation."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(bo.compute(...arguments))}},po={description:Q("Standard deviation of sample (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(Eo.compute(...arguments))}},go={description:Q("Standard deviation of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(wo.compute(...arguments))}},fo={description:Q("Standard deviation of entire population (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Math.sqrt(Lo.compute(...arguments))}},mo={description:Q("Variance."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!0,!1)}},vo={description:Q("Variance of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!1,!1)}},bo={description:Q("Variance."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!0,!1)}},Eo={description:Q("Variance of sample (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the sample.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the sample.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!0,!0)}},wo={description:Q("Variance of entire population."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!1,!1)}},Lo={description:Q("Variance of entire population (text as 0)."),args:De(`\n value1 (number, range<number>) ${Q("The first value or range of the population.")}\n value2 (number, range<number>, optional, repeating) ${Q("Additional values or ranges to include in the population.")}\n `),returns:["NUMBER"],compute:function(){return Zt(arguments,!1,!0)}};var So=Object.freeze({__proto__:null,AVEDEV:zt,AVERAGE:Ht,AVERAGE_WEIGHTED:jt,AVERAGEA:qt,AVERAGEIF:Wt,AVERAGEIFS:Yt,COUNT:Xt,COUNTA:Kt,COVAR:Jt,COVARIANCE_P:Qt,COVARIANCE_S:eo,LARGE:to,MAX:oo,MAXA:so,MAXIFS:no,MIN:io,MINA:ro,MINIFS:ao,SMALL:lo,STDEV:co,STDEV_P:ho,STDEV_S:uo,STDEVA:po,STDEVP:go,STDEVPA:fo,VAR:mo,VAR_P:vo,VAR_S:bo,VARA:Eo,VARP:wo,VARPA:Lo});function Co(e,t,o){const s=new Map,n=e.length;for(let t=n-1;t>=0;t--)s.set(Se(e[t][0]).toUpperCase(),t);const i=typeof t;let r;if("number"===i){if(r=Math.trunc(t)-1,r<0||r>n-1)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 2 value is %s. Valid values are between 1 and %s inclusive.",t,n))}else{const e="string"===i?t.toUpperCase():t;if(r=s.get(e),void 0===r)throw new Error(Q("Function [[FUNCTION_NAME]] parameter 2 value is %s. It should be one of: %s.",t,[...s.keys()].map((e=>"'"+e+"'")).join(", ")))}const a=o[0].length;if(a<2)throw new Error(Q("[[FUNCTION_NAME]] criteria range must be at least 2 rows."));let l=new Set;const c=e[0].length;for(let t=1;t<a;t++){let n=[],i=!0;for(let r=0;r<o.length;r++){const a=Se(o[r][0]).toUpperCase(),l=s.get(a),h=o[r][t];if(void 0!==h){if(void 0===l){i=!1;break}n.push([e[l].slice(1,c)]),n.push(h)}}if(i){if(!(n.length>0)){l=new Set(Array(c-1).keys());break}Me(n,((e,t)=>{l.add(t)}),!0)}}const h=e[r];return[...l].map((e=>h[e+1]))}const yo=De(`\n database (range) ${Q("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) ${Q("Indicates which column in database contains the values to be extracted and operated on.")}\n criteria (range) ${Q("An array or range containing zero or more criteria to filter the database values by before operating.")}\n`),To={description:Q("Average of a set of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Ht.compute([s])}},xo={description:Q("Counts values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Xt.compute([s])}},Ro={description:Q("Counts values and text from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return Kt.compute([s])}},Mo={description:Q("Single value from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);if(s.length>1)throw new Error(Q("More than one match found in DGET evaluation."));return s[0]}},Ao={description:Q("Maximum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return oo.compute([s])}},No={description:Q("Minimum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return io.compute([s])}},ko={description:Q("Product of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return St.compute([s])}},_o={description:Q("Standard deviation of population sample from table."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return co.compute([s])}},Io={description:Q("Standard deviation of entire population from table."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return go.compute([s])}},Oo={description:Q("Sum of values from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return It.compute([s])}},Do={description:Q("Variance of population sample from table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return mo.compute([s])}},$o={description:Q("Variance of a population from a table-like range."),args:yo,returns:["NUMBER"],compute:function(e,t,o){const s=Co(e,t,o);return wo.compute([s])}};var Uo=Object.freeze({__proto__:null,DAVERAGE:To,DCOUNT:xo,DCOUNTA:Ro,DGET:Mo,DMAX:Ao,DMIN:No,DPRODUCT:ko,DSTDEV:_o,DSTDEVP:Io,DSUM:Oo,DVAR:Do,DVARP:$o});const Fo=new Date(1899,11,30),Po={description:Q("Converts year/month/day into a date."),args:De(`\n year (number) ${Q("The year component of the date.")}")}\n month (number) ${Q("The month component of the date.")}")}\n day (number) ${Q("The day component of the date.")}")}\n `),returns:["DATE"],compute:function(e,t,o){let s=Math.trunc(me(e));const n=Math.trunc(me(t)),i=Math.trunc(me(o));if(s<0||1e4<=s)throw new Error(Q("function DATE parameter year should be greater or equal to 0 and lesser than 10000."));s<1900&&(s+=1900);const r=new Date(s,n-1,i),a=r.getTime()-Fo.getTime();if(a<0)throw new Error(Q("function DATE result should not be lesser than 01/01/1900"));return{value:Math.round(a/864e5),format:"m/d/yyyy",jsDate:r}}},Bo={description:Q("Converts a date string to a date value."),args:De(`\n date_string (string) ${Q("The string representing the date.")}\n `),returns:["NUMBER"],compute:function(e){const t=Se(e),o=ae(t);if(null===o)throw new Error(Q("DATEVALUE parameter '%s' cannot be parsed to date/time.",t));return Math.trunc(o.value)}},Zo={description:Q("Day of the month that a specific date falls on."),args:De(`\n date (string) ${Q("The date from which to extract the day.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getDate()}},zo={description:Q("Number of days between two dates."),args:De(`\n end_date (date) ${Q("The end of the date range.")}\n start_date (date) ${Q("The start of the date range.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=ce(e),s=ce(t),n=o.getTime()-s.getTime();return Math.round(n/864e5)}},Ho={description:Q("Date a number of months before/after another date."),args:De(`\n start_date (date) ${Q("The date from which to calculate the result.")}\n months (number) ${Q("The number of months before (negative) or after (positive) 'start_date' to calculate.")}\n `),returns:["DATE"],compute:function(e,t){const o=ce(e),s=Math.trunc(me(t)),n=o.getFullYear(),i=o.getMonth(),r=o.getDate(),a=new Date(n,i+s,r),l=a.getTime()-Fo.getTime();return{value:Math.round(l/864e5),format:"m/d/yyyy",jsDate:a}}},Go={description:Q("Last day of a month before or after a date."),args:De(`\n start_date (date) ${Q("The date from which to calculate the result.")}\n months (number) ${Q("The number of months before (negative) or after (positive) 'start_date' to consider.")}\n `),returns:["DATE"],compute:function(e,t){const o=ce(e),s=Math.trunc(me(t)),n=o.getFullYear(),i=o.getMonth(),r=new Date(n,i+s+1,0),a=r.getTime()-Fo.getTime();return{value:Math.round(a/864e5),format:"m/d/yyyy",jsDate:r}}},Vo={description:Q("Hour component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the hour component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getHours()}},jo={description:Q("ISO week number of the year."),args:De(`\n date (date) ${Q("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=ce(e),o=t.getFullYear();let s=1;for(;4!==new Date(o,0,s).getDay();)s+=1;const n=new Date(o,0,s-3);let i=31;for(;4!==new Date(o,11,i).getDay();)i-=1;const r=new Date(o,11,i+3);let a,l;switch(a=n.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=n;break;case 1:l=new Date(o,11,i+3+1);break;case-1:let e=1;for(;4!==new Date(o-1,0,e).getDay();)e+=1;l=new Date(o-1,0,e-3)}const c=(t.getTime()-l.getTime())/864e5;return Math.floor(c/7)+1}},qo={description:Q("Minute component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the minute component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getMinutes()}},Wo={description:Q("Month of the year a specific date falls in"),args:De(`\n date (date) ${Q("The date from which to extract the month.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getMonth()+1}},Yo={description:Q("Net working days between two provided days."),args:De(`\n start_date (date) ${Q("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${Q("The end date of the period from which to calculate the number of net working days.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the date serial numbers to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o){return Ko.compute(e,t,1,o)}};function Xo(e){if("string"==typeof e){let t=[];if(7===e.length){for(let o=0;o<7;o++)switch(e.charAt(o)){case"0":break;case"1":t.push(o+1===7?0:o+1);break;default:throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string composed of 0 or 1. Actual string is '%s'.",e))}return t}throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string with 7 characters. Actual string is '%s'.",e))}if("number"==typeof e){if(1<=e&&e<=7)return[e-2==-1?6:e-2,e-1];if(11<=e&&e<=17)return[e-11];throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a string or a number in the range 1-7 or 11-17. Actual number is %s.",e.toString()))}throw new Error(Q("Function [[FUNCTION_NAME]] parameter 3 requires a number or a string."))}const Ko={description:Q("Net working days between two dates (specifying weekends)."),args:De(`\n start_date (date) ${Q("The start date of the period from which to calculate the number of net working days.")}\n end_date (date) ${Q("The end date of the period from which to calculate the number of net working days.")}\n weekend (any, optional, default=1) ${Q("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider as holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1,s){const n=ce(e),i=ce(t),r=Xo(o);let a=new Set;void 0!==s&&be(s,(e=>{const t=ce(e);a.add(t.getTime())}));const l=n.getTime()>i.getTime(),c=new Date((l?n:i).getTime());let h=new Date((l?i:n).getTime());const u=c.getTime();let d=h.getTime(),p=0;for(;d<=u;)r.includes(h.getDay())||a.has(d)||(p+=1),h.setDate(h.getDate()+1),d=h.getTime();return l?-p:p}},Jo={description:Q("Current date and time as a date value."),args:[],returns:["DATE"],compute:function(){let e=new Date;e.setMilliseconds(0);const t=e.getTime()-Fo.getTime(),o=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return{value:Math.floor(t/864e5)+o,format:"m/d/yyyy hh:mm:ss",jsDate:e}}},Qo={description:Q("Minute component of a specific time."),args:De(`\n time (date) ${Q("The time from which to calculate the second component.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getSeconds()}},es={description:Q("Converts hour/minute/second into a time."),args:De(`\n hour (number) ${Q("The hour component of the time.")}\n minute (number) ${Q("The minute component of the time.")}\n second (number) ${Q("The second component of the time.")}\n `),returns:["DATE"],compute:function(e,t,o){let s=Math.trunc(me(e)),n=Math.trunc(me(t)),i=Math.trunc(me(o));if(n+=Math.floor(i/60),i=i%60+(i<0?60:0),s+=Math.floor(n/60),n=n%60+(n<0?60:0),s%=24,s<0)throw new Error(Q("function Time result should not be negative"));return{value:s/24+n/1440+i/86400,format:"hh:mm:ss a",jsDate:new Date(1899,11,30,s,n,i)}}},ts={description:Q("Converts a time string into its serial number representation."),args:De(`\n time_string (string) ${Q("The string that holds the time representation.")}\n `),returns:["NUMBER"],compute:function(e){const t=Se(e),o=ae(t);if(null===o)throw new Error(Q("TIMEVALUE parameter '%s' cannot be parsed to date/time.",t));const s=o.value-Math.trunc(o.value);return s<0?1+s:s}},os={description:Q("Current date as a date value."),args:[],returns:["DATE"],compute:function(){const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),o=t.getTime()-Fo.getTime();return{value:Math.round(o/864e5),format:"m/d/yyyy",jsDate:t}}},ss={description:Q("Day of the week of the date provided (as number)."),args:De(`\n date (date) ${Q("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, optional, default=1) ${Q("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 o=ce(e),s=Math.round(me(t)),n=o.getDay();switch(s){case 1:return n+1;case 2:return 0===n?7:n;case 3:return 0===n?6:n-1}throw new Error(Q("Function WEEKDAY parameter 2 value %s is out of range.",s.toString()))}},ns={description:Q("Week number of the year."),args:De(`\n date (date) ${Q("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, optional, default=1) ${Q("A number representing the day that a week starts on. Sunday = 1.")}\n `),returns:["NUMBER"],compute:function(e,t=1){const o=ce(e),s=Math.round(me(t));let n;if(1===s||2===s)n=s-1;else{if(!(11<=s&&s<=17)){if(21===s)return jo.compute(e);throw new Error(Q("Function WEEKNUM parameter 2 value %s is out of range.",s.toString()))}n=s-10==7?0:s-10}const i=o.getFullYear();let r=1,a=new Date(i,0,r);for(;a.getDay()!==n;)r+=1,a=new Date(i,0,r);const l=(o.getTime()-a.getTime())/864e5;return l<0?1:Math.floor(l/7)+(1===r?1:2)}},is={description:Q("Number of working days from start date."),args:De(`\n start_date (date) ${Q("The date from which to begin counting.")}\n num_days (number) ${Q("The number of working days to advance from start_date. If negative, counts backwards.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider holidays.")}\n `),returns:["NUMBER"],compute:function(e,t,o){return rs.compute(e,t,1,o)}},rs={description:Q("Net working days between two dates (specifying weekends)."),args:De(`\n start_date (date) ${Q("The date from which to begin counting.")}\n num_days (number) ${Q("The number of working days to advance from start_date. If negative, counts backwards.")}\n weekend (any, optional, default=1) ${Q("A number or string representing which days of the week are considered weekends.")}\n holidays (date, range<date>, optional) ${Q("A range or array constant containing the dates to consider holidays.")}\n `),returns:["DATE"],compute:function(e,t,o=1,s){let n=ce(e),i=Math.trunc(me(t));if("1111111"===o)throw new Error(Q("Function WORKDAY.INTL parameter 3 cannot be equal to '1111111'."));const r=Xo(o);let a=new Set;void 0!==s&&be(s,(e=>{const t=ce(e);a.add(t.getTime())}));let l=new Date(n.getTime()),c=l.getTime();const h=Math.sign(i);let u=Math.abs(i);for(;u>0;)l.setDate(l.getDate()+h),c=l.getTime(),r.includes(l.getDay())||a.has(c)||(u-=1);const d=c-Fo.getTime();return{value:Math.round(d/864e5),format:"m/d/yyyy",jsDate:l}}},as={description:Q("Year specified by a given date."),args:De(`\n date (date) ${Q("The date from which to extract the year.")}\n `),returns:["NUMBER"],compute:function(e){return ce(e).getFullYear()}};var ls=Object.freeze({__proto__:null,DATE:Po,DATEVALUE:Bo,DAY:Zo,DAYS:zo,EDATE:Ho,EOMONTH:Go,HOUR:Vo,ISOWEEKNUM:jo,MINUTE:qo,MONTH:Wo,NETWORKDAYS:Yo,NETWORKDAYS_INTL:Ko,NOW:Jo,SECOND:Qo,TIME:es,TIMEVALUE:ts,TODAY:os,WEEKDAY:ss,WEEKNUM:ns,WORKDAY:is,WORKDAY_INTL:rs,YEAR:as});const cs={description:Q("Whether a value is an error."),args:De(`value (any, lazy) ${Q("The value to be verified as an error type.")}`),returns:["BOOLEAN"],compute:function(e){try{return e(),!1}catch(e){return!0}}},hs={description:Q("Whether a value is `true` or `false`."),args:De(`value (any) ${Q("The value to be verified as a logical TRUE or FALSE.")}`),returns:["BOOLEAN"],compute:function(e){return"boolean"==typeof e}},us={description:Q("Whether a value is non-textual."),args:De(`value (any) ${Q("The value to be checked.")}`),returns:["BOOLEAN"],compute:function(e){return"string"!=typeof e}},ds={description:Q("Whether a value is a number."),args:De(`value (any) ${Q("The value to be verified as a number.")}`),returns:["BOOLEAN"],compute:function(e){return"number"==typeof e}},ps={description:Q("Whether a value is text."),args:De(`value (any) ${Q("The value to be verified as text.")}`),returns:["BOOLEAN"],compute:function(e){return"string"==typeof e}};var gs=Object.freeze({__proto__:null,ISERROR:cs,ISLOGICAL:hs,ISNONTEXT:us,ISNUMBER:ds,ISTEXT:ps});const fs={description:Q("Wait"),args:De(`ms (number) ${Q("wait time in milliseconds")}`),returns:["ANY"],async:!0,compute:function(e){return new Promise((function(t,o){setTimeout((function(){t(e)}),e)}))}},ms={description:Q("Logical `and` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that represent logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!0,t=!1;if(Te(arguments,(o=>(e=e&&o,t=!0,e))),!t)throw new Error(Q("AND has no valid input data."));return e}},vs={description:Q("Returns value depending on logical expression."),args:De(`\n logical_expression (boolean) ${Q("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) ${Q("The value the function returns if logical_expression is TRUE.")}\n value_if_false (any, lazy, optional, default=FALSE) ${Q("The value the function returns if logical_expression is FALSE.")}\n `),returns:["ANY"],compute:function(e,t,o=(()=>!1)){const s=ye(e)?t():o();return null===s?"":s}},bs={description:Q("Value if it is not an error, otherwise 2nd argument."),args:De(`\n value (any, lazy) ${Q("The value to return if value itself is not an error.")}\n value_if_error (any, lazy, optional, default="") ${Q("The value the function returns if value is an error.")}\n `),returns:["ANY"],compute:function(e,t=(()=>"")){let o;try{o=e()}catch(e){o=t()}return null===o?"":o}},Es={description:Q("Returns a value depending on multiple logical expressions."),args:De(`\n condition1 (boolean, lazy) ${Q("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) ${Q("The returned value if condition1 is TRUE.")}\n additional_values (any, lazy, optional, repeating) ${Q("Additional conditions and values to be evaluated if the previous ones are FALSE.")}\n `),returns:["ANY"],compute:function(){if(arguments.length%2==1)throw new Error(Q("Wrong number of arguments. Expected an even number of arguments."));for(let e=0;e<arguments.length-1;e+=2)if(ye(arguments[e]()))return arguments[e+1]();throw new Error(Q("No match."))}},ws={description:Q("Returns opposite of provided logical value."),args:De(`logical_expression (boolean) ${Q("An expression or reference to a cell holding an expression that represents some logical value.")}\n `),returns:["BOOLEAN"],compute:function(e){return!ye(e)}},Ls={description:Q("Logical `or` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!1,t=!1;if(Te(arguments,(o=>(e=e||o,t=!0,!e))),!t)throw new Error(Q("OR has no valid input data."));return e}},Ss={description:Q("Logical `xor` operator."),args:De(`\n logical_expression1 (boolean, range<boolean>) ${Q("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>, optional, repeating) ${Q("More expressions that evaluate to logical values.")}\n `),returns:["BOOLEAN"],compute:function(){let e=!1,t=!1;if(Te(arguments,(o=>(e=e?!o:o,t=!0,!0))),!t)throw new Error(Q("XOR has no valid input data."));return e}};var Cs=Object.freeze({__proto__:null,WAIT:fs,AND:ms,IF:vs,IFERROR:bs,IFS:Es,NOT:ws,OR:Ls,XOR:Ss});function ys(e,t){for(let o=0;o<e.length;o++)if(e[o]===t)return o;return-1}const Ts={description:Q("Look up a value."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n search_array (any, range) ${Q("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 (any, range, optional) ${Q("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,o){const s=t[0].length>=t.length,n=Ae((s?t[0]:t.map((e=>e[0]))).map((e=>Ne(e))),Ne(e));if(-1===n){const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in LOOKUP evaluation.",t))}if(void 0===o)return s?t.pop()[n]:t[n].pop();const i=o.length,r=o[0].length;if(i>1&&r>1)throw new Error(Q("LOOKUP range must be a single row or a single column."));if(i>1){if(i-1<n)throw new Error(Q("LOOKUP evaluates to an out of range row value %s.",(n+1).toString()));return o[n][0]}if(r-1<n)throw new Error(Q("LOOKUP evaluates to an out of range column value %s.",(n+1).toString()));return o[0][n]}},xs={description:Q("Position of item in range that matches value."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${Q("The one-dimensional array to be searched.")}\n search_type (number, optional, default=1) ${Q("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,o=1){let s=me(o);const n=t.length,i=t[0].length;if(n>1&&i>1)throw new Error(Q("MATCH range must be a single row or a single column."));let r=-1;t=t.flat().map((e=>Ne(e)));const a=Ne(e);switch(s=Math.sign(s),s){case 1:r=Ae(t,a);break;case 0:r=ys(t,a);break;case-1:r=function(e,t){const o=typeof t;let s,n,i,r,a,l,c=0,h=e.length-1;if(typeof e[c]===o&&t>e[c])return-1;if(typeof e[h]===o&&e[h]>t)return h;for(;h-c>=0;){for(i=Math.ceil((c+h)/2),r=i,a=e[r],l=typeof a;c<=r&&o!==l;)r--,a=e[r],l=typeof a;l===o&&a>=t&&(void 0===s||s>a||s===a&&n>r)&&(s=a,n=r),l===o&&a<=t?h=r-1:c=i+1}return void 0!==n?n:-1}(t,a)}if(r>-1)return r+1;{const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in MATCH evaluation.",t))}}},Rs={description:Q("Vertical lookup."),args:De(`\n search_key (any) ${Q("The value to search for. For example, 42, 'Cats', or I24.")}\n range (any, range) ${Q("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) ${Q("The column index of the value to be returned, where the first column in range is numbered 1.")}\n is_sorted (boolean, optional, default = TRUE) ${Q("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,o,s=!0){const n=Math.trunc(me(o));if(n<1||t.length<n)throw new Error(Q("VLOOKUP evaluates to an out of bounds range."));const i=ye(s),r=t[0].map((e=>Ne(e))),a=Ne(e);let l;if(l=i?Ae(r,a):ys(r,a),l>-1)return t[n-1][l];{const t="object"==typeof e&&e.jsDate?he(e):e;throw new Error(Q("Did not find value '%s' in VLOOKUP evaluation.",t))}}};var Ms=Object.freeze({__proto__:null,LOOKUP:Ts,MATCH:xs,VLOOKUP:Rs});const As={description:Q("Sum of two numbers."),args:De(`\n value1 (number) ${Q("The first addend.")}\n value2 (number) ${Q("The second addend.")}\n `),returns:["NUMBER"],compute:function(e,t){return e&&e.value?t&&t.value?e.value+t.value:{value:e.value+me(t),format:e.format,jsDate:ke(e.value+me(t))}:me(e)+me(t)}},Ns={description:Q("Concatenation of two values."),args:De(`\n value1 (string) ${Q("The value to which value2 will be appended.")}\n value2 (string) ${Q("The value to append to value1.")}\n `),returns:["STRING"],compute:function(e,t){return Se(e)+Se(t)}},ks={description:Q("One number divided by another."),args:De(`\n dividend (number) ${Q("The number to be divided.")}\n divisor (number) ${Q("The number to divide by.")}\n `),returns:["NUMBER"],compute:function(e,t){const o=me(t);if(0===o)throw new Error(Q("Function DIVIDE parameter 2 cannot be zero."));return me(e)/o}};function _s(e){return null==e}const Is={number:0,string:"",boolean:!1},Os={description:Q("Equal."),args:De(`\n value1 (any) ${Q("The first value.")}\n value2 (any) ${Q("The value to test against value1 for equality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return e=_s(e)?Is[typeof t]:e,t=_s(t)?Is[typeof e]:t,"string"==typeof e&&(e=e.toUpperCase()),"string"==typeof t&&(t=t.toUpperCase()),(e=Ne(e))===(t=Ne(t))}};function Ds(e,t,o){e=_s(e)?Is[typeof t]:e,t=_s(t)?Is[typeof e]:t,e=Ne(e),t=Ne(t),"number"!=typeof e&&(e=Se(e).toUpperCase()),"number"!=typeof t&&(t=Se(t).toUpperCase());const s=typeof e,n=typeof t;return"string"===s&&"number"===n||("string"!==n||"number"!==s)&&o(e,t)}const $s={description:Q("Strictly greater than."),args:De(`\n value1 (any) ${Q("The value to test as being greater than value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Ds(e,t,((e,t)=>e>t))}},Us={description:Q("Greater than or equal to."),args:De(`\n value1 (any) ${Q("The value to test as being greater than or equal to value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Ds(e,t,((e,t)=>e>=t))}},Fs={description:Q("Less than."),args:De(`\n value1 (any) ${Q("The value to test as being less than value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Us.compute(e,t)}},Ps={description:Q("Less than or equal to."),args:De(`\n value1 (any) ${Q("The value to test as being less than or equal to value2.")}\n value2 (any) ${Q("The second value.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!$s.compute(e,t)}},Bs={description:Q("Difference of two numbers."),args:De(`\n value1 (number) ${Q("The minuend, or number to be subtracted from.")}\n value2 (number) ${Q("The subtrahend, or number to subtract from value1.")}\n `),returns:["NUMBER"],compute:function(e,t){return me(e)-me(t)}},Zs={description:Q("Product of two numbers"),args:De(`\n factor1 (number) ${Q("The first multiplicand.")}\n factor2 (number) ${Q("The second multiplicand.")}\n `),returns:["NUMBER"],compute:function(e,t){return me(e)*me(t)}},zs={description:Q("Not equal."),args:De(`\n value1 (any) ${Q("The first value.")}\n value2 (any) ${Q("The value to test against value1 for inequality.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return!Os.compute(e,t)}},Hs={description:Q("A number raised to a power."),args:De(`\n base (number) ${Q("The number to raise to the exponent power.")}\n exponent (number) ${Q("The exponent to raise base to.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Lt.compute(e,t)}},Gs={description:Q("A number with the sign reversed."),args:De(`\n value (number) ${Q("The number to have its sign reversed. Equivalently, the number to multiply by -1.")}\n `),returns:["NUMBER"],compute:function(e){return-me(e)}},Vs={description:Q("Value interpreted as a percentage."),args:De(`\n percentage (number) ${Q("The value to interpret as a percentage.")}\n `),returns:["NUMBER"],compute:function(e){return me(e)/100}},js={description:Q("A specified number, unchanged."),args:De(`\n value (any) ${Q("The number to return.")}\n `),returns:["ANY"],compute:function(e){return e}};var qs=Object.freeze({__proto__:null,ADD:As,CONCAT:Ns,DIVIDE:ks,EQ:Os,GT:$s,GTE:Us,LT:Fs,LTE:Ps,MINUS:Bs,MULTIPLY:Zs,NE:zs,POW:Hs,UMINUS:Gs,UNARY_PERCENT:Vs,UPLUS:js});const Ws={description:Q("Gets character associated with number."),args:De(`\n table_number (number) ${Q("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(me(e));if(t<1)throw new Error(Q("Function CHAR parameter 1 value %s is out of range.",t.toString()));return String.fromCharCode(t)}},Ys={description:Q("Appends strings to one another."),args:De(`\n string1 (string, range<string>) ${Q("The initial string.")}\n string2 (string, range<string>, optional, repeating) ${Q("More strings to append in sequence.")}\n `),returns:["STRING"],compute:function(){return Ee(arguments,((e,t)=>e+Se(t)),"")}},Xs={description:Q("Tests whether two strings are identical."),args:De(`\n string1 (string) ${Q("The first string to compare.")}\n string2 (string) ${Q("The second string to compare.")}\n `),returns:["BOOLEAN"],compute:function(e,t){return Se(e)===Se(t)}},Ks={description:Q("First position of string found in text, case-sensitive."),args:De(`\n search_for (string) ${Q("The string to look for within text_to_search.")}\n text_to_search (string) ${Q("The text to search for the first occurrence of search_for.")}\n starting_at (number, optional, default=1 ) ${Q("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1){const s=Se(t);if(""===s)throw new Error(Q("Function FIND parameter 2 value should be non-empty."));const n=me(o);if(0===n)throw new Error(Q("Function FIND parameter 3 value is 0. It should be greater than or equal to 1."));const i=Se(e),r=s.indexOf(i,n-1);if(r<0)throw new Error(Q("In FIND evaluation, cannot find '%s' within '%s'.",i.toString(),s));return r+1}},Js={description:Q("Concatenates elements of arrays with delimiter."),args:De(`\n delimiter (string) ${Q("The character or string to place between each concatenated value.")}\n value_or_array1 (string, range<string>) ${Q("The value or values to be appended using delimiter.")}\n value_or_array2 (string, range<string>, optional, repeating) ${Q("More values to be appended using delimiter.")}\n `),returns:["STRING"],compute:function(e,...t){const o=Se(e);return Ee(t,((e,t)=>(e?e+o:"")+Se(t)),"")}},Qs={description:Q("Substring from beginning of specified string."),args:De(`\n text (string) ${Q("The string from which the left portion will be returned.")}\n number_of_characters (number, optional, default=1) ${Q("The number of characters to return from the left side of string.")}\n `),returns:["STRING"],compute:function(e,t=1){const o=me(t);if(o<0)throw new Error(Q("Function LEFT parameter 2 value is negative. It should be positive or zero."));return Se(e).substring(0,o)}},en={description:Q("Length of a string."),args:De(`\n text (string) ${Q("The string whose length will be returned.")}\n `),returns:["NUMBER"],compute:function(e){return Se(e).length}},tn={description:Q("Converts a specified string to lowercase."),args:De(`\n text (string) ${Q("The string to convert to lowercase.")}\n `),returns:["STRING"],compute:function(e){return Se(e).toLowerCase()}},on={description:Q("Replaces part of a text string with different text."),args:De(`\n text (string) ${Q("The text, a part of which will be replaced.")}\n position (number) ${Q("The position where the replacement will begin (starting from 1).")}\n length (number) ${Q("The number of characters in the text to be replaced.")}\n new_text (string) ${Q("The text which will be inserted into the original text.")}\n `),returns:["STRING"],compute:function(e,t,o,s){const n=me(t);if(n<1)throw new Error(Q("Function REPLACE parameter 2 value is %s. It should be greater than or equal to 1.",Se(n)));const i=Se(e),r=me(o),a=Se(s);return i.substring(0,n-1)+a+i.substring(n-1+r)}},sn={description:Q("A substring from the end of a specified string."),args:De(`\n text (string) ${Q("The string from which the right portion will be returned.")}\n number_of_characters (number, optional, default=1) ${Q("The number of characters to return from the right side of string.")}\n `),returns:["STRING"],compute:function(e,t=1){const o=me(t);if(o<0)throw new Error(Q("Function RIGHT parameter 2 value is negative. It should be positive or zero."));const s=Se(e),n=s.length;return s.substring(n-o,n)}},nn={description:Q("First position of string found in text, ignoring case."),args:De(`\n search_for (string) ${Q("The string to look for within text_to_search.")}\n text_to_search (string) ${Q("The text to search for the first occurrence of search_for.")}\n starting_at (number, optional, default=1 ) ${Q("The character within text_to_search at which to start the search.")}\n `),returns:["NUMBER"],compute:function(e,t,o=1){const s=Se(t).toLowerCase();if(""===s)throw new Error(Q("Function SEARCH parameter 2 value should be non-empty."));const n=me(o);if(0===n)throw new Error(Q("Function SEARCH parameter 3 value is 0. It should be greater than or equal to 1."));const i=Se(e).toLowerCase(),r=s.indexOf(i,n-1);if(r<0)throw new Error(Q("In SEARCH evaluation, cannot find '%s' within '%s'.",i,s));return r+1}},rn={description:Q("Replaces existing text with new text in a string."),args:De(`\n text_to_search (string) ${Q("The text within which to search and replace.")}\n search_for (string) ${Q("The string to search for within text_to_search.")}\n replace_with (string) ${Q("The string that will replace search_for.")}\n occurrence_number (number, optional) ${Q("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,o,s){const n=me(s);if(n<0)throw new Error(Q("Function SUBSTITUTE parameter 4 value is negative. It should be positive or zero."));const i=Se(e),r=Se(t);if(""===r)return i;const a=Se(o),l=new RegExp(r,"g");if(0===n)return i.replace(l,a);let c=0;return i.replace(l,(e=>++c===n?a:e))}},an={description:Q("Combines text from multiple strings and/or arrays."),args:De(`\n delimiter (string) ${Q(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")}\n ignore_empty (boolean) ${Q("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")}\n text1 (string, range<string>) ${Q("Any text item. This could be a string, or an array of strings in a range.")}\n text2 (string, range<string>, optional, repeating) ${Q("Additional text item(s).")}\n `),returns:["STRING"],compute:function(e,t,...o){const s=Se(e),n=ye(t);let i=0;return Ee(o,((e,t)=>n&&""===Se(t)?e:(i++?e+s:"")+Se(t)),"")}},ln={description:Q("Removes space characters."),args:De(`\n text (string) ${Q("The text or reference to a cell containing text to be trimmed.")}\n `),returns:["STRING"],compute:function(e){return Se(e).trim()}},cn={description:Q("Converts a specified string to uppercase."),args:De(`\n text (string) ${Q("The string to convert to uppercase.")}\n `),returns:["STRING"],compute:function(e){return Se(e).toUpperCase()}};const hn={database:Uo,date:ls,info:gs,lookup:Ms,logical:Cs,math:Pt,operators:qs,statistical:So,text:Object.freeze({__proto__:null,CHAR:Ws,CONCATENATE:Ys,EXACT:Xs,FIND:Ks,JOIN:Js,LEFT:Qs,LEN:en,LOWER:tn,REPLACE:on,RIGHT:sn,SEARCH:nn,SUBSTITUTE:rn,TEXTJOIN:an,TRIM:ln,UPPER:cn})};const un=new class extends _e{constructor(){super(...arguments),this.mapping={}}add(e,t){return e=e.toUpperCase().replace("_","."),function(e){let t=!1,o=!1;for(let s of e){if(t)throw new Error(Q("Function ${name} has at least 2 arguments that are repeating. The maximum repeating arguments is 1."));if(o&&!s.optional)throw new Error(Q("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=s.repeating,o=s.optional}}(t.args),this.mapping[e]=t.compute,super.add(e,t),this}};for(let e in hn){const t=hn[e];for(let o in t){const s=t[o];s.category=e,un.add(o,s)}}class dn{constructor(e,t,o,s,n){this.workbook=e,this.getters=t,this.history=Object.assign(Object.create(o),{updateLocalState:o.updateStateFromRoot.bind(o,this)}),this.dispatch=s,this.currentMode=n.mode,this.ui=n}allowDispatch(e){return{status:"SUCCESS"}}beforeHandle(e){}handle(e){}finalize(e){}drawGrid(e,t){}import(e){}export(e){}}dn.layers=[],dn.getters=[],dn.modes=["headless","normal","readonly"];const pn=new _e;pn.add("INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=(parseFloat(t.content)+e.current).toString();return{cellData:Object.assign({},t,{content:o}),tooltip:o?{props:{content:o}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t)=>({cellData:t,tooltip:t.content?{props:{content:t.content}}:void 0})}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let n=0,i=0;switch(s){case 0:n=0,i=-e.current;break;case 1:n=0,i=e.current;break;case 2:n=-e.current,i=0;break;case 3:n=e.current,i=0}const r=o.applyOffset(t.content,n,i);return{cellData:Object.assign({},t,{content:r}),tooltip:r?{props:{content:r}}:void 0}}});const gn=new _e;gn.add("simple_value_copy",{condition:(e,t)=>1===t.length&&["text","date","number"].includes(e.type),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("copy_text",{condition:e=>"text"===e.type,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>"formula"===e.type,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_number",{condition:e=>"number"===e.type,generateRule:(e,t)=>{const o=function(e,t){let o=[],s=!1;for(let n of t){if(n===e&&(s=!0),!n||"number"!==n.type){if(s)return o;o=[]}n&&"number"===n.type&&n.content&&o.push(n.content)}return o}(e,t);let s=1;return 2==o.length?s=2*(parseFloat(o[1])-parseFloat(o[0])):o.length>2&&(s=function(e){const t=[];let o=parseFloat(e[0]);for(let s=1;s<e.length;s++){const n=parseFloat(e[s]);t.push(n-o),o=n}return t.reduce(((e,t)=>e+t),0)/t.length}(o)*o.length),{type:"INCREMENT_MODIFIER",increment:s,current:0}},sequence:40});const{xml:fn,css:mn}=t.tags,{useRef:vn}=t.hooks,bn=fn`
2
2
  <div class="o-chart-container">
3
3
  <canvas t-ref="graphContainer" />
4
4
  </div>`,En=mn`
@@ -27,7 +27,7 @@
27
27
  margin: 5px;
28
28
  }
29
29
  }
30
- `;class Tn extends t.Component{}Tn.template=Cn,Tn.style=yn;const xn=new _e;xn.add("text",{Component:Tn}),xn.add("chart",{Component:wn,SidePanelComponent:"ChartPanel"});function Rn(e,t){return Object.assign({},(e=>({isVisible:()=>!0,isEnabled:()=>!0,action:!1,children:[],separator:!1,id:e}))(e),t)}class Mn extends _e{add(e,t){return this.content[e]=Rn(e,t),this}addChild(e,t,o){const s=t.splice(0,1)[0];let n=this.content[s];if(!n)throw new Error(`Path ${s+":"+t.join(":")} not found`);for(let e of t)if(n="function"==typeof n.children?void 0:n.children.find((t=>t.id===e)),!n)throw new Error(`Path ${s+":"+t.join(":")} not found`);return n.children.push(Rn(e,o)),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}getAll(){return super.getAll().sort(((e,t)=>e.sequence-t.sequence))}}function An(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 Nn(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 kn(e,t){e.dispatch("SET_FORMATTER",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones(),formatter:t})}function _n(e,t){e.dispatch("SET_FORMATTING",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones(),style:t})}const In=async e=>{e.dispatch("COPY",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},On=async e=>{e.dispatch("CUT",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Dn=async e=>{const t=e.getters.getClipboardContent();let o;try{o=await e.clipboard.readText()}catch(e){console.warn("The OS clipboard could not be read."),console.error(e)}const s=e.getters.getSelectedZones();o&&o!==t?e.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:o}):e.dispatch("PASTE",{target:s,interactive:!0})},$n=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),onlyValue:!0}),Un=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),onlyFormat:!0}),Fn=e=>e.dispatch("DELETE_CONTENT",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones()}),Pn=e=>{let t,o;const s=e.getters.getActiveRows();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.top,o=s.bottom}return t===o?Q("Delete row %s",(t+1).toString()):Q("Delete rows %s - %s",(t+1).toString(),(o+1).toString())},Bn=e=>{let t=[...e.getters.getActiveRows()];if(!t.length){const o=e.getters.getSelectedZones()[0];for(let e=o.top;e<=o.bottom;e++)t.push(e)}e.dispatch("REMOVE_ROWS",{sheet:e.getters.getActiveSheet(),rows:t})},zn=e=>{let t,o;const s=e.getters.getActiveCols();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.left,o=s.right}return t===o?Q("Delete column %s",b(t)):Q("Delete columns %s - %s",b(t),b(o))},Zn=e=>{let t=[...e.getters.getActiveCols()];if(!t.length){const o=e.getters.getSelectedZones()[0];for(let e=o.left;e<=o.right;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS",{sheet:e.getters.getActiveSheet(),columns:t})},Hn=e=>{const t=e.getters.getActiveRows();let o,s;if(t.size)o=Math.min(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.top,s=t.bottom-t.top+1}e.dispatch("ADD_ROWS",{sheet:e.getters.getActiveSheet(),position:"before",row:o,quantity:s})},Gn=e=>{const t=e.getters.getActiveRows();let o,s;if(t.size)o=Math.max(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.bottom,s=t.bottom-t.top+1}e.dispatch("ADD_ROWS",{sheet:e.getters.getActiveSheet(),position:"after",row:o,quantity:s})},Vn=e=>{const t=e.getters.getActiveCols();let o,s;if(t.size)o=Math.min(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.left,s=t.right-t.left+1}e.dispatch("ADD_COLUMNS",{sheet:e.getters.getActiveSheet(),position:"before",column:o,quantity:s})},jn=e=>{const t=e.getters.getActiveCols();let o,s;if(t.size)o=Math.max(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.right,s=t.right-t.left+1}e.dispatch("ADD_COLUMNS",{sheet:e.getters.getActiveSheet(),position:"after",column:o,quantity:s})},qn=e=>{e.openSidePanel("ConditionalFormatting",{selection:e.getters.getSelectedZones()})},Wn=new Mn;Wn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste values only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_row_before",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row"):Q("Insert %s rows",t.toString())},sequence:50,action:Hn}).add("add_column_before",{name:e=>{const t=An(e);return 1===t?Q("Insert column"):Q("Insert %s columns",t.toString())},sequence:70,action:Vn,separator:!0}).add("delete_row",{name:Pn,sequence:90,action:Bn}).add("delete_column",{name:zn,sequence:100,action:Zn,separator:!0}).add("clear_cell",{name:Q("Clear cell"),sequence:110,action:Fn,isEnabled:e=>{const t=e.getters.getActiveCell();return Boolean(t&&t.content)}}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:120,action:qn,separator:!0});const Yn=new Mn;Yn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_column_before",{name:e=>{const t=An(e);return 1===t?Q("Insert column left"):Q("Insert %s columns left",t.toString())},sequence:50,action:Vn}).add("add_column_after",{name:e=>{const t=An(e);return 1===t?Q("Insert column right"):Q("Insert %s columns right",t.toString())},sequence:60,action:jn}).add("delete_column",{name:zn,sequence:70,action:Zn}).add("clear_column",{name:e=>{let t,o;const s=e.getters.getActiveCols();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.left,o=s.right}return t===o?Q("Clear column %s",b(t)):Q("Clear columns %s - %s",b(t),b(o))},sequence:80,action:e=>{const t=[...e.getters.getActiveCols()].map((t=>e.getters.getColsZone(t,t)));e.dispatch("DELETE_CONTENT",{target:t,sheet:e.getters.getActiveSheet()})},separator:!0}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:90,action:qn});const Xn=new Mn;Xn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_row_before",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row above"):Q("Insert %s rows above",t.toString())},sequence:50,action:Hn}).add("add_row_after",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row below"):Q("Insert %s rows below",t.toString())},sequence:60,action:Gn}).add("delete_row",{name:Pn,sequence:70,action:Bn}).add("clear_row",{name:e=>{let t,o;const s=e.getters.getActiveRows();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.top,o=s.bottom}return t===o?Q("Clear row %s",(t+1).toString()):Q("Clear rows %s - %s",(t+1).toString(),(o+1).toString())},sequence:80,action:e=>{const t=[...e.getters.getActiveRows()].map((t=>e.getters.getRowsZone(t,t)));e.dispatch("DELETE_CONTENT",{target:t,sheet:e.getters.getActiveSheet()})},separator:!0}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:90,action:qn});const Kn=new Mn;Kn.add("delete",{name:Q("Delete"),sequence:10,isVisible:e=>e.getters.getSheets().length>1,action:e=>e.dispatch("DELETE_SHEET_CONFIRMATION",{sheet:e.getters.getActiveSheet()})}).add("duplicate",{name:Q("Duplicate"),sequence:20,action:e=>{const t=e.getters.getActiveSheet(),o=function(e,t){let o=1;const s=e.getters.getSheets().map((e=>e.name)),n=Q("Copy of %s",t);let i=n.toString();for(;s.includes(i);)i=`${n} (${o})`,o++;return i}(e,e.getters.getSheets().find((e=>e.id===t)).name);e.dispatch("DUPLICATE_SHEET",{sheet:t,id:K(),name:o})}}).add("rename",{name:Q("Rename"),sequence:30,action:e=>e.dispatch("RENAME_SHEET",{interactive:!0,sheet:e.getters.getActiveSheet()})}).add("move_right",{name:Q("Move right"),sequence:40,isVisible:e=>{const t=e.getters.getActiveSheet(),o=e.getters.getSheets();return o.findIndex((e=>e.id===t))!==o.length-1},action:e=>e.dispatch("MOVE_SHEET",{sheet:e.getters.getActiveSheet(),direction:"right"})}).add("move_left",{name:Q("Move left"),sequence:50,isVisible:e=>{const t=e.getters.getActiveSheet();return 0!==e.getters.getSheets().findIndex((e=>e.id===t))},action:e=>e.dispatch("MOVE_SHEET",{sheet:e.getters.getActiveSheet(),direction:"left"})});const Jn=[{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}],Qn={};for(let e of Jn)Qn[e.pt]=e.px;const ei=new Mn;ei.add("file",{name:Q("File"),sequence:10}).add("edit",{name:Q("Edit"),sequence:20}).add("view",{name:Q("View"),sequence:30}).add("insert",{name:Q("Insert"),sequence:40}).add("format",{name:Q("Format"),sequence:50}).add("data",{name:Q("Data"),sequence:60}).addChild("save",["file"],{name:Q("Save"),sequence:10,action:()=>console.log("Not implemented")}).addChild("undo",["edit"],{name:Q("Undo"),sequence:10,action:e=>e.dispatch("UNDO")}).addChild("redo",["edit"],{name:Q("Redo"),sequence:20,action:e=>e.dispatch("REDO"),separator:!0}).addChild("copy",["edit"],{name:Q("Copy"),sequence:30,action:In}).addChild("cut",["edit"],{name:Q("Cut"),sequence:40,action:On}).addChild("paste",["edit"],{name:Q("Paste"),sequence:50,action:Dn}).addChild("paste_special",["edit"],{name:Q("Paste special"),sequence:60,separator:!0}).addChild("paste_special_value",["edit","paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_special_format",["edit","paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).addChild("edit_delete_cell_values",["edit"],{name:Q("Delete values"),sequence:70,action:Fn}).addChild("edit_delete_row",["edit"],{name:Pn,sequence:80,action:Bn}).addChild("edit_delete_column",["edit"],{name:zn,sequence:90,action:Zn}).addChild("insert_row_before",["insert"],{name:e=>{const t=Nn(e);return 1===t?Q("Row above"):Q("%s Rows above",t.toString())},sequence:10,action:Hn,isVisible:e=>0===e.getters.getActiveCols().size}).addChild("insert_row_after",["insert"],{name:e=>{const t=Nn(e);return 1===t?Q("Row below"):Q("%s Rows below",t.toString())},sequence:20,action:Gn,isVisible:e=>0===e.getters.getActiveCols().size,separator:!0}).addChild("insert_column_before",["insert"],{name:e=>{const t=An(e);return 1===t?Q("Column left"):Q("%s Columns left",t.toString())},sequence:30,action:Vn,isVisible:e=>0===e.getters.getActiveRows().size}).addChild("insert_column_after",["insert"],{name:e=>{const t=An(e);return 1===t?Q("Column right"):Q("%s Columns right",t.toString())},sequence:40,action:jn,isVisible:e=>0===e.getters.getActiveRows().size,separator:!0}).addChild("insert_chart",["insert"],{name:Q("Chart"),sequence:50,action:e=>{e.openSidePanel("ChartPanel")},separator:!0}).addChild("insert_sheet",["insert"],{name:Q("New sheet"),sequence:60,action:e=>{e.dispatch("CREATE_SHEET",{activate:!0,id:K()})},separator:!0}).addChild("view_formulas",["view"],{name:e=>e.getters.shouldShowFormulas()?Q("Hide formulas"):Q("Show formulas"),action:e=>e.dispatch("SET_FORMULA_VISIBILITY",{show:!e.getters.shouldShowFormulas()}),sequence:10}).addChild("format_number",["format"],{name:Q("Numbers"),sequence:10,separator:!0}).addChild("format_number_auto",["format","format_number"],{name:Q("Automatic"),sequence:10,separator:!0,action:e=>kn(e,"")}).addChild("format_number_number",["format","format_number"],{name:Q("Number (1,000.12)"),sequence:20,action:e=>kn(e,"#,##0.00")}).addChild("format_number_percent",["format","format_number"],{name:Q("Percent (10.12%)"),sequence:30,separator:!0,action:e=>kn(e,"0.00%")}).addChild("format_number_date",["format","format_number"],{name:Q("Date (9/26/2008)"),sequence:40,action:e=>kn(e,"m/d/yyyy")}).addChild("format_number_time",["format","format_number"],{name:Q("Time (10:43:00 PM)"),sequence:50,action:e=>kn(e,"hh:mm:ss a")}).addChild("format_number_date_time",["format","format_number"],{name:Q("Date time (9/26/2008 22:43:00)"),sequence:60,action:e=>kn(e,"m/d/yyyy hh:mm:ss")}).addChild("format_number_duration",["format","format_number"],{name:Q("Duration (27:51:38)"),sequence:70,separator:!0,action:e=>kn(e,"hhhh:mm:ss")}).addChild("format_bold",["format"],{name:Q("Bold"),sequence:20,action:e=>_n(e,{bold:!e.getters.getCurrentStyle().bold})}).addChild("format_italic",["format"],{name:Q("Italic"),sequence:30,action:e=>_n(e,{italic:!e.getters.getCurrentStyle().italic})}).addChild("format_strikethrough",["format"],{name:Q("Strikethrough"),sequence:50,action:e=>_n(e,{strikethrough:!e.getters.getCurrentStyle().strikethrough}),separator:!0}).addChild("format_font_size",["format"],{name:Q("Font size"),sequence:60,separator:!0}).addChild("format_cf",["format"],{name:Q("Conditional formatting"),sequence:70,action:qn,separator:!0});for(let e of Jn)ei.addChild(`format_font_size_${e.pt}`,["format","format_font_size"],{name:e.pt.toString(),sequence:e.pt,action:t=>_n(t,{fontSize:e.pt})});const ti=s.Component,{xml:oi,css:si}=s.tags,ni=oi`
30
+ `;class Tn extends t.Component{}Tn.template=Cn,Tn.style=yn;const xn=new _e;xn.add("text",{Component:Tn}),xn.add("chart",{Component:wn,SidePanelComponent:"ChartPanel"});function Rn(e,t){return Object.assign({},(e=>({isVisible:()=>!0,isEnabled:()=>!0,action:!1,children:[],separator:!1,id:e}))(e),t)}class Mn extends _e{add(e,t){return this.content[e]=Rn(e,t),this}addChild(e,t,o){const s=t.splice(0,1)[0];let n=this.content[s];if(!n)throw new Error(`Path ${s+":"+t.join(":")} not found`);for(let e of t)if(n="function"==typeof n.children?void 0:n.children.find((t=>t.id===e)),!n)throw new Error(`Path ${s+":"+t.join(":")} not found`);return n.children.push(Rn(e,o)),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}getAll(){return super.getAll().sort(((e,t)=>e.sequence-t.sequence))}}function An(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 Nn(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 kn(e,t){e.dispatch("SET_FORMATTER",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones(),formatter:t})}function _n(e,t){e.dispatch("SET_FORMATTING",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones(),style:t})}const In=async e=>{e.dispatch("COPY",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},On=async e=>{e.dispatch("CUT",{target:e.getters.getSelectedZones()}),await e.clipboard.writeText(e.getters.getClipboardContent())},Dn=async e=>{const t=e.getters.getClipboardContent();let o;try{o=await e.clipboard.readText()}catch(e){console.warn("The OS clipboard could not be read."),console.error(e)}const s=e.getters.getSelectedZones();o&&o!==t?e.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:s,text:o}):e.dispatch("PASTE",{target:s,interactive:!0})},$n=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),onlyValue:!0}),Un=e=>e.dispatch("PASTE",{target:e.getters.getSelectedZones(),onlyFormat:!0}),Fn=e=>e.dispatch("DELETE_CONTENT",{sheet:e.getters.getActiveSheet(),target:e.getters.getSelectedZones()}),Pn=e=>{let t,o;const s=e.getters.getActiveRows();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.top,o=s.bottom}return t===o?Q("Delete row %s",(t+1).toString()):Q("Delete rows %s - %s",(t+1).toString(),(o+1).toString())},Bn=e=>{let t=[...e.getters.getActiveRows()];if(!t.length){const o=e.getters.getSelectedZones()[0];for(let e=o.top;e<=o.bottom;e++)t.push(e)}e.dispatch("REMOVE_ROWS",{sheet:e.getters.getActiveSheet(),rows:t})},Zn=e=>{let t,o;const s=e.getters.getActiveCols();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.left,o=s.right}return t===o?Q("Delete column %s",b(t)):Q("Delete columns %s - %s",b(t),b(o))},zn=e=>{let t=[...e.getters.getActiveCols()];if(!t.length){const o=e.getters.getSelectedZones()[0];for(let e=o.left;e<=o.right;e++)t.push(e)}e.dispatch("REMOVE_COLUMNS",{sheet:e.getters.getActiveSheet(),columns:t})},Hn=e=>{const t=e.getters.getActiveRows();let o,s;if(t.size)o=Math.min(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.top,s=t.bottom-t.top+1}e.dispatch("ADD_ROWS",{sheet:e.getters.getActiveSheet(),position:"before",row:o,quantity:s})},Gn=e=>{const t=e.getters.getActiveRows();let o,s;if(t.size)o=Math.max(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.bottom,s=t.bottom-t.top+1}e.dispatch("ADD_ROWS",{sheet:e.getters.getActiveSheet(),position:"after",row:o,quantity:s})},Vn=e=>{const t=e.getters.getActiveCols();let o,s;if(t.size)o=Math.min(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.left,s=t.right-t.left+1}e.dispatch("ADD_COLUMNS",{sheet:e.getters.getActiveSheet(),position:"before",column:o,quantity:s})},jn=e=>{const t=e.getters.getActiveCols();let o,s;if(t.size)o=Math.max(...t),s=t.size;else{const t=e.getters.getSelectedZones()[0];o=t.right,s=t.right-t.left+1}e.dispatch("ADD_COLUMNS",{sheet:e.getters.getActiveSheet(),position:"after",column:o,quantity:s})},qn=e=>{e.openSidePanel("ConditionalFormatting",{selection:e.getters.getSelectedZones()})},Wn=new Mn;Wn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste values only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_row_before",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row"):Q("Insert %s rows",t.toString())},sequence:50,action:Hn}).add("add_column_before",{name:e=>{const t=An(e);return 1===t?Q("Insert column"):Q("Insert %s columns",t.toString())},sequence:70,action:Vn,separator:!0}).add("delete_row",{name:Pn,sequence:90,action:Bn}).add("delete_column",{name:Zn,sequence:100,action:zn,separator:!0}).add("clear_cell",{name:Q("Clear cell"),sequence:110,action:Fn,isEnabled:e=>{const t=e.getters.getActiveCell();return Boolean(t&&t.content)}}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:120,action:qn,separator:!0});const Yn=new Mn;Yn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_column_before",{name:e=>{const t=An(e);return 1===t?Q("Insert column left"):Q("Insert %s columns left",t.toString())},sequence:50,action:Vn}).add("add_column_after",{name:e=>{const t=An(e);return 1===t?Q("Insert column right"):Q("Insert %s columns right",t.toString())},sequence:60,action:jn}).add("delete_column",{name:Zn,sequence:70,action:zn}).add("clear_column",{name:e=>{let t,o;const s=e.getters.getActiveCols();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.left,o=s.right}return t===o?Q("Clear column %s",b(t)):Q("Clear columns %s - %s",b(t),b(o))},sequence:80,action:e=>{const t=[...e.getters.getActiveCols()].map((t=>e.getters.getColsZone(t,t)));e.dispatch("DELETE_CONTENT",{target:t,sheet:e.getters.getActiveSheet()})},separator:!0}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:90,action:qn});const Xn=new Mn;Xn.add("cut",{name:Q("Cut"),sequence:10,action:On}).add("copy",{name:Q("Copy"),sequence:20,action:In}).add("paste",{name:Q("Paste"),sequence:30,action:Dn}).add("paste_special",{name:Q("Paste special"),sequence:40,separator:!0}).addChild("paste_value_only",["paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_format_only",["paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).add("add_row_before",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row above"):Q("Insert %s rows above",t.toString())},sequence:50,action:Hn}).add("add_row_after",{name:e=>{const t=Nn(e);return 1===t?Q("Insert row below"):Q("Insert %s rows below",t.toString())},sequence:60,action:Gn}).add("delete_row",{name:Pn,sequence:70,action:Bn}).add("clear_row",{name:e=>{let t,o;const s=e.getters.getActiveRows();if(0!==s.size)t=Math.min(...s),o=Math.max(...s);else{const s=e.getters.getSelectedZones()[0];t=s.top,o=s.bottom}return t===o?Q("Clear row %s",(t+1).toString()):Q("Clear rows %s - %s",(t+1).toString(),(o+1).toString())},sequence:80,action:e=>{const t=[...e.getters.getActiveRows()].map((t=>e.getters.getRowsZone(t,t)));e.dispatch("DELETE_CONTENT",{target:t,sheet:e.getters.getActiveSheet()})},separator:!0}).add("conditional_formatting",{name:Q("Conditional formatting"),sequence:90,action:qn});const Kn=new Mn;Kn.add("delete",{name:Q("Delete"),sequence:10,isVisible:e=>e.getters.getSheets().length>1,action:e=>e.dispatch("DELETE_SHEET_CONFIRMATION",{sheet:e.getters.getActiveSheet()})}).add("duplicate",{name:Q("Duplicate"),sequence:20,action:e=>{const t=e.getters.getActiveSheet(),o=function(e,t){let o=1;const s=e.getters.getSheets().map((e=>e.name)),n=Q("Copy of %s",t);let i=n.toString();for(;s.includes(i);)i=`${n} (${o})`,o++;return i}(e,e.getters.getSheets().find((e=>e.id===t)).name);e.dispatch("DUPLICATE_SHEET",{sheet:t,id:K(),name:o})}}).add("rename",{name:Q("Rename"),sequence:30,action:e=>e.dispatch("RENAME_SHEET",{interactive:!0,sheet:e.getters.getActiveSheet()})}).add("move_right",{name:Q("Move right"),sequence:40,isVisible:e=>{const t=e.getters.getActiveSheet(),o=e.getters.getSheets();return o.findIndex((e=>e.id===t))!==o.length-1},action:e=>e.dispatch("MOVE_SHEET",{sheet:e.getters.getActiveSheet(),direction:"right"})}).add("move_left",{name:Q("Move left"),sequence:50,isVisible:e=>{const t=e.getters.getActiveSheet();return 0!==e.getters.getSheets().findIndex((e=>e.id===t))},action:e=>e.dispatch("MOVE_SHEET",{sheet:e.getters.getActiveSheet(),direction:"left"})});const Jn=[{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}],Qn={};for(let e of Jn)Qn[e.pt]=e.px;const ei=new Mn;ei.add("file",{name:Q("File"),sequence:10}).add("edit",{name:Q("Edit"),sequence:20}).add("view",{name:Q("View"),sequence:30}).add("insert",{name:Q("Insert"),sequence:40}).add("format",{name:Q("Format"),sequence:50}).add("data",{name:Q("Data"),sequence:60}).addChild("save",["file"],{name:Q("Save"),sequence:10,action:()=>console.log("Not implemented")}).addChild("undo",["edit"],{name:Q("Undo"),sequence:10,action:e=>e.dispatch("UNDO")}).addChild("redo",["edit"],{name:Q("Redo"),sequence:20,action:e=>e.dispatch("REDO"),separator:!0}).addChild("copy",["edit"],{name:Q("Copy"),sequence:30,action:In}).addChild("cut",["edit"],{name:Q("Cut"),sequence:40,action:On}).addChild("paste",["edit"],{name:Q("Paste"),sequence:50,action:Dn}).addChild("paste_special",["edit"],{name:Q("Paste special"),sequence:60,separator:!0}).addChild("paste_special_value",["edit","paste_special"],{name:Q("Paste value only"),sequence:10,action:$n}).addChild("paste_special_format",["edit","paste_special"],{name:Q("Paste format only"),sequence:20,action:Un}).addChild("edit_delete_cell_values",["edit"],{name:Q("Delete values"),sequence:70,action:Fn}).addChild("edit_delete_row",["edit"],{name:Pn,sequence:80,action:Bn}).addChild("edit_delete_column",["edit"],{name:Zn,sequence:90,action:zn}).addChild("insert_row_before",["insert"],{name:e=>{const t=Nn(e);return 1===t?Q("Row above"):Q("%s Rows above",t.toString())},sequence:10,action:Hn,isVisible:e=>0===e.getters.getActiveCols().size}).addChild("insert_row_after",["insert"],{name:e=>{const t=Nn(e);return 1===t?Q("Row below"):Q("%s Rows below",t.toString())},sequence:20,action:Gn,isVisible:e=>0===e.getters.getActiveCols().size,separator:!0}).addChild("insert_column_before",["insert"],{name:e=>{const t=An(e);return 1===t?Q("Column left"):Q("%s Columns left",t.toString())},sequence:30,action:Vn,isVisible:e=>0===e.getters.getActiveRows().size}).addChild("insert_column_after",["insert"],{name:e=>{const t=An(e);return 1===t?Q("Column right"):Q("%s Columns right",t.toString())},sequence:40,action:jn,isVisible:e=>0===e.getters.getActiveRows().size,separator:!0}).addChild("insert_chart",["insert"],{name:Q("Chart"),sequence:50,action:e=>{e.openSidePanel("ChartPanel")},separator:!0}).addChild("insert_sheet",["insert"],{name:Q("New sheet"),sequence:60,action:e=>{e.dispatch("CREATE_SHEET",{activate:!0,id:K()})},separator:!0}).addChild("view_formulas",["view"],{name:e=>e.getters.shouldShowFormulas()?Q("Hide formulas"):Q("Show formulas"),action:e=>e.dispatch("SET_FORMULA_VISIBILITY",{show:!e.getters.shouldShowFormulas()}),sequence:10}).addChild("format_number",["format"],{name:Q("Numbers"),sequence:10,separator:!0}).addChild("format_number_auto",["format","format_number"],{name:Q("Automatic"),sequence:10,separator:!0,action:e=>kn(e,"")}).addChild("format_number_number",["format","format_number"],{name:Q("Number (1,000.12)"),sequence:20,action:e=>kn(e,"#,##0.00")}).addChild("format_number_percent",["format","format_number"],{name:Q("Percent (10.12%)"),sequence:30,separator:!0,action:e=>kn(e,"0.00%")}).addChild("format_number_date",["format","format_number"],{name:Q("Date (9/26/2008)"),sequence:40,action:e=>kn(e,"m/d/yyyy")}).addChild("format_number_time",["format","format_number"],{name:Q("Time (10:43:00 PM)"),sequence:50,action:e=>kn(e,"hh:mm:ss a")}).addChild("format_number_date_time",["format","format_number"],{name:Q("Date time (9/26/2008 22:43:00)"),sequence:60,action:e=>kn(e,"m/d/yyyy hh:mm:ss")}).addChild("format_number_duration",["format","format_number"],{name:Q("Duration (27:51:38)"),sequence:70,separator:!0,action:e=>kn(e,"hhhh:mm:ss")}).addChild("format_bold",["format"],{name:Q("Bold"),sequence:20,action:e=>_n(e,{bold:!e.getters.getCurrentStyle().bold})}).addChild("format_italic",["format"],{name:Q("Italic"),sequence:30,action:e=>_n(e,{italic:!e.getters.getCurrentStyle().italic})}).addChild("format_strikethrough",["format"],{name:Q("Strikethrough"),sequence:50,action:e=>_n(e,{strikethrough:!e.getters.getCurrentStyle().strikethrough}),separator:!0}).addChild("format_font_size",["format"],{name:Q("Font size"),sequence:60,separator:!0}).addChild("format_cf",["format"],{name:Q("Conditional formatting"),sequence:70,action:qn,separator:!0});for(let e of Jn)ei.addChild(`format_font_size_${e.pt}`,["format","format_font_size"],{name:e.pt.toString(),sequence:e.pt,action:t=>_n(t,{fontSize:e.pt})});const ti=s.Component,{xml:oi,css:si}=s.tags,ni=oi`
31
31
  <div class="o-selection">
32
32
  <t t-foreach="ranges" t-as="range" t-key="range.id">
33
33
  <input
@@ -91,7 +91,7 @@
91
91
  height: 25px;
92
92
  }
93
93
  }
94
- `;class ri extends ti{constructor(){super(...arguments),this.id=K(),this.previousRanges=this.props.ranges||[],this.getters=this.env.getters,this.dispatch=this.env.dispatch}get ranges(){return this.getters.getSelectionInput(this.id)}get hasFocus(){return this.ranges.filter((e=>e.isFocused)).length>0}get canAddRange(){return!this.props.maximumRanges||this.ranges.length<this.props.maximumRanges}mounted(){this.dispatch("ENABLE_NEW_SELECTION_INPUT",{id:this.id,initialRanges:this.props.ranges,maximumRanges:this.props.maximumRanges})}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()}triggerChange(){const e=this.getters.getSelectionInputValue(this.id);this.trigger("selection-changed",{ranges:e}),this.previousRanges=e}focus(e){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()}onInputChanged(e,t){const o=t.target;this.dispatch("CHANGE_RANGE",{id:this.id,rangeId:e,value:o.value}),o.blur(),this.triggerChange()}disable(){this.dispatch("FOCUS_RANGE",{id:this.id,rangeId:null})}}ri.template=ni,ri.style=ii;const ai=Q("Format rules"),li=Q("Format cells if..."),ci=Q("Formatting style"),hi=Q("Bold"),ui=Q("Italic"),di=Q("Strikethrough"),pi=Q("Text Color"),gi=Q("Fill Color"),fi=Q("Cancel"),mi=Q("Save"),vi=Q("Preview text"),bi={BeginsWith:Q("Begins with"),Between:Q("Between"),ContainsText:Q("Contains text"),EndsWith:Q("Ends with"),Equal:Q("Is equal to"),GreaterThan:Q("Greater than"),GreaterThanOrEqual:Q("Greater than or equal"),LessThan:Q("Less than"),LessThanOrEqual:Q("Less than or equal"),NotBetween:Q("Not between"),NotContains:Q("Not contains"),NotEqual:Q("Not equal")},Ei=Q("Chart type"),wi=Q("Line"),Li=Q("Bar"),Si=Q("Pie"),Ci=Q("Title"),yi=Q("Series"),Ti=Q("Data Series"),xi=Q("My data has title"),Ri=Q("Data categories (labels)"),Mi=Q("Update chart"),Ai=Q("Create chart"),Ni=Q("New Chart"),ki=s.Component,{useState:_i}=s,{xml:Ii}=s.tags,Oi=Ii`
94
+ `;class ri extends ti{constructor(){super(...arguments),this.id=K(),this.previousRanges=this.props.ranges||[],this.getters=this.env.getters,this.dispatch=this.env.dispatch}get ranges(){return this.getters.getSelectionInput(this.id)}get hasFocus(){return this.ranges.filter((e=>e.isFocused)).length>0}get canAddRange(){return!this.props.maximumRanges||this.ranges.length<this.props.maximumRanges}mounted(){this.dispatch("ENABLE_NEW_SELECTION_INPUT",{id:this.id,initialRanges:this.props.ranges,maximumRanges:this.props.maximumRanges})}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()}triggerChange(){const e=this.getters.getSelectionInputValue(this.id);this.trigger("selection-changed",{ranges:e}),this.previousRanges=e}focus(e){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()}onInputChanged(e,t){const o=t.target;this.dispatch("CHANGE_RANGE",{id:this.id,rangeId:e,value:o.value}),o.blur(),this.triggerChange()}disable(){this.dispatch("FOCUS_RANGE",{id:this.id,rangeId:null})}}ri.template=ni,ri.style=ii;const ai=Q("Format rules"),li=Q("Format cells if..."),ci=Q("Formatting style"),hi=Q("Bold"),ui=Q("Italic"),di=Q("Strikethrough"),pi=Q("Text Color"),gi=Q("Fill Color"),fi=Q("Cancel"),mi=Q("Save"),vi=Q("Preview text"),bi={BeginsWith:Q("Begins with"),Between:Q("Between"),ContainsText:Q("Contains text"),EndsWith:Q("Ends with"),Equal:Q("Is equal to"),GreaterThan:Q("Greater than"),GreaterThanOrEqual:Q("Greater than or equal"),LessThan:Q("Less than"),LessThanOrEqual:Q("Less than or equal"),NotBetween:Q("Not between"),NotContains:Q("Not contains"),NotEqual:Q("Not equal")},Ei=Q("Chart type"),wi=Q("Line"),Li=Q("Bar"),Si=Q("Pie"),Ci=Q("Title"),yi=Q("Series"),Ti=Q("Data Series"),xi=Q("My data has title"),Ri=Q("Data categories (labels)"),Mi=Q("Update chart"),Ai=Q("Create chart"),Ni=Q("New Chart"),ki=s.Component,{useState:_i}=s,{xml:Ii,css:Oi}=s.tags,Di=Ii`
95
95
  <div class="o-chart">
96
96
  <div class="o-section">
97
97
  <div class="o-section-title"><t t-esc="env._t('${Ei}')"/></div>
@@ -116,17 +116,23 @@
116
116
  </div>
117
117
  <div class="o-sidePanelButtons">
118
118
  <button t-if="props.figure" t-on-click="updateChart(props.figure)" class="o-sidePanelButton" t-esc="env._t('${Mi}')"/>
119
- <button t-else="" t-on-click="createChart" class="o-sidePanelButton" t-esc="env._t('${Ai}')"/>
119
+ <button t-else="" t-on-click="createChart" t-att-class="{ 'o-error': state.errorWhileCreating }" class="o-sidePanelButton" t-esc="env._t('${Ai}')"/>
120
120
  </div>
121
121
  </div>
122
- `;class Di extends ki{constructor(){super(...arguments),this.getters=this.env.getters,this.state=_i(this.initialState())}onSeriesChanged(e){this.state.ranges=e.detail.ranges}onLabelRangeChanged(e){this.state.labelRange=e.detail.ranges[0]}createChart(){this.env.dispatch("CREATE_CHART",{sheetId:this.getters.getActiveSheet(),id:K(),definition:this.getChartDefinition()}),this.trigger("close-side-panel")}updateChart(e){this.env.dispatch("UPDATE_CHART",{id:e.id,definition:this.getChartDefinition()}),this.trigger("close-side-panel")}getChartDefinition(){return{type:this.state.type,title:this.state.title,labelRange:this.state.labelRange.trim()||"",dataSets:this.state.ranges.slice(),seriesHasTitle:this.state.seriesHasTitle}}initialState(){const e=this.props.figure?this.props.figure.data:void 0;return{title:e&&e.title?e.title:"",ranges:e?e.dataSets.map((e=>e.dataRange)):[],labelRange:e?e.labelRange:"",type:e?e.type:"bar",seriesHasTitle:!!e&&void 0!==e.title}}}Di.template=Oi,Di.components={SelectionInput:ri};const $i=s.Component,{css:Ui,xml:Fi}=s.tags,Pi=[["#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"]];class Bi extends $i{constructor(){super(...arguments),this.COLORS=Pi}onColorClick(e){const t=e.target.dataset.color;t&&this.trigger("color-picked",{color:t})}}Bi.template=Fi`
122
+ `,$i=Oi`
123
+ .o-chart {
124
+ .o-sidePanelButton.o-error {
125
+ border-color: #e14747;
126
+ }
127
+ }
128
+ `;class Ui extends ki{constructor(){super(...arguments),this.getters=this.env.getters,this.state=_i(this.initialState())}onSeriesChanged(e){this.state.ranges=e.detail.ranges}onLabelRangeChanged(e){this.state.labelRange=e.detail.ranges[0]}createChart(){"SUCCESS"===this.env.dispatch("CREATE_CHART",{sheetId:this.getters.getActiveSheet(),id:K(),definition:this.getChartDefinition()}).status?this.trigger("close-side-panel"):this.state.errorWhileCreating=!0}updateChart(e){this.env.dispatch("UPDATE_CHART",{id:e.id,definition:this.getChartDefinition()}),this.trigger("close-side-panel")}getChartDefinition(){return{type:this.state.type,title:this.state.title,labelRange:this.state.labelRange.trim()||"",dataSets:this.state.ranges.slice(),seriesHasTitle:this.state.seriesHasTitle}}initialState(){const e=this.props.figure?this.props.figure.data:void 0;return{title:e&&e.title?e.title:"",ranges:e?e.dataSets.map((e=>e.dataRange)):[],labelRange:e?e.labelRange:"",type:e?e.type:"bar",seriesHasTitle:!!e&&void 0!==e.title,errorWhileCreating:!1}}}Ui.template=Di,Ui.style=$i,Ui.components={SelectionInput:ri};const Fi=s.Component,{css:Pi,xml:Bi}=s.tags,Zi=[["#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"]];class zi extends Fi{constructor(){super(...arguments),this.COLORS=Zi}onColorClick(e){const t=e.target.dataset.color;t&&this.trigger("color-picked",{color:t})}}zi.template=Bi`
123
129
  <div class="o-color-picker" t-on-click="onColorClick">
124
130
  <div class="o-color-picker-line" t-foreach="COLORS" t-as="colors" t-key="colors">
125
131
  <t t-foreach="colors" t-as="color" t-key="color">
126
132
  <div class="o-color-picker-line-item" t-att-data-color="color" t-attf-style="background-color:{{color}};"></div>
127
133
  </t>
128
134
  </div>
129
- </div>`,Bi.style=Ui`
135
+ </div>`,zi.style=Pi`
130
136
  .o-color-picker {
131
137
  position: absolute;
132
138
  top: calc(100% + 5px);
@@ -152,7 +158,7 @@
152
158
  }
153
159
  }
154
160
  }
155
- `;const zi='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 8 0" transform="translate(5 7)"/></svg>',Zi='<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>',Hi='<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>',Gi='<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>',Vi='<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>',ji='<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>',qi='<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>',Wi='<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>',Yi='<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>',Xi='<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>',Ki=s.Component,{useState:Ji,hooks:Qi}=s,{useExternalListener:er}=Qi,{xml:tr,css:or}=s.tags,sr=tr`
161
+ `;const Hi='<svg class="o-icon"><polygon fill="#000000" points="0 0 4 4 8 0" transform="translate(5 7)"/></svg>',Gi='<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>',Vi='<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>',ji='<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>',qi='<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>',Wi='<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>',Yi='<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>',Xi='<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>',Ki='<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>',Ji='<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>',Qi=s.Component,{useState:er,hooks:tr}=s,{useExternalListener:or}=tr,{xml:sr,css:nr}=s.tags,ir=sr`
156
162
  <div>
157
163
  <div class="o-section-title" t-esc="env._t('${ai}')"></div>
158
164
  <div class="o-cf-title-text" t-esc="env._t('${li}')"></div>
@@ -167,7 +173,7 @@
167
173
  </t>
168
174
  <div class="o-cf-title-text" t-esc="env._t('${ci}')"></div>
169
175
 
170
- <t t-call="${tr`
176
+ <t t-call="${sr`
171
177
  <div class="o-cf-preview-line"
172
178
  t-attf-style="font-weight:{{currentStyle.bold ?'bold':'normal'}};
173
179
  text-decoration:{{currentStyle.strikethrough ? 'line-through':'none'}};
@@ -180,23 +186,23 @@
180
186
  </t>
181
187
  <div class="o-tools">
182
188
  <div class="o-tool" t-att-title="env._t('${hi}')" t-att-class="{active:state.style.bold}" t-on-click="toggleTool('bold')">
183
- ${Zi}
189
+ ${Gi}
184
190
  </div>
185
191
  <div class="o-tool" t-att-title="env._t('${ui}')" t-att-class="{active:state.style.italic}" t-on-click="toggleTool('italic')">
186
- ${Hi}
192
+ ${Vi}
187
193
  </div>
188
194
  <div class="o-tool" t-att-title="env._t('${di}')" t-att-class="{active:state.style.strikethrough}"
189
- t-on-click="toggleTool('strikethrough')">${Gi}
195
+ t-on-click="toggleTool('strikethrough')">${ji}
190
196
  </div>
191
197
  <div class="o-tool o-dropdown o-with-color">
192
198
  <span t-att-title="env._t('${pi}')" t-attf-style="border-color:{{state.style.textColor}}"
193
- t-on-click.stop="toggleMenu('textColorTool')">${Vi}</span>
199
+ t-on-click.stop="toggleMenu('textColorTool')">${qi}</span>
194
200
  <ColorPicker t-if="state.textColorTool" t-on-color-picked="setColor('textColor')" t-key="textColor"/>
195
201
  </div>
196
202
  <div class="o-divider"/>
197
203
  <div class="o-tool o-dropdown o-with-color">
198
204
  <span t-att-title="env._t('${gi}')" t-attf-style="border-color:{{state.style.fillColor}}"
199
- t-on-click.stop="toggleMenu('fillColorTool')">${ji}</span>
205
+ t-on-click.stop="toggleMenu('fillColorTool')">${Wi}</span>
200
206
  <ColorPicker t-if="state.fillColorTool" t-on-color-picked="setColor('fillColor')" t-key="fillColor"/>
201
207
  </div>
202
208
  </div>
@@ -205,7 +211,7 @@
205
211
  <button t-on-click="onSave" class="o-sidePanelButton o-cf-save" t-esc="env._t('${mi}')"></button>
206
212
  </div>
207
213
  </div>
208
- `,nr=or`
214
+ `,rr=nr`
209
215
  .o-cf-title-text {
210
216
  font-size: 12px;
211
217
  line-height: 14px;
@@ -216,12 +222,12 @@
216
222
  border: 1px solid darkgrey;
217
223
  padding: 10px;
218
224
  }
219
- `;class ir extends Ki{constructor(){super(...arguments),this.cellIsOperators=bi,this.cf=this.props.conditionalFormat,this.rule=this.cf.rule,this.state=Ji({condition:{operator:this.rule&&this.rule.operator?this.rule.operator:"Equal",value1:this.rule&&this.rule.values.length>0?this.rule.values[0]:"",value2:this.cf&&this.rule.values.length>1?this.rule.values[1]:""},textColorTool:!1,fillColorTool:!1,style:{fillColor:this.cf&&this.rule.style.fillColor,textColor:this.cf&&this.rule.style.textColor,bold:this.cf&&this.rule.style.bold,italic:this.cf&&this.rule.style.italic,strikethrough:this.cf&&this.rule.style.strikethrough}}),er(window,"click",this.closeMenus)}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 o=t.detail.color;this.state.style[e]=o,this.closeMenus()}closeMenus(){this.state.textColorTool=!1,this.state.fillColorTool=!1}onSave(){const e={},t=this.state.style;void 0!==t.bold&&(e.bold=t.bold),void 0!==t.italic&&(e.italic=t.italic),void 0!==t.strikethrough&&(e.strikethrough=t.strikethrough),t.fillColor&&(e.fillColor=t.fillColor),t.textColor&&(e.textColor=t.textColor),this.trigger("modify-rule",{rule:{type:"CellIsRule",operator:this.state.condition.operator,values:[this.state.condition.value1,this.state.condition.value2],stopIfTrue:!1,style:e}})}onCancel(){this.trigger("cancel-edit")}}ir.template=sr,ir.style=nr,ir.components={ColorPicker:Bi};const rr=s.Component,{useState:ar,hooks:lr}=s,{useExternalListener:cr}=lr,{xml:hr,css:ur}=s.tags,dr=hr`
225
+ `;class ar extends Qi{constructor(){super(...arguments),this.cellIsOperators=bi,this.cf=this.props.conditionalFormat,this.rule=this.cf.rule,this.state=er({condition:{operator:this.rule&&this.rule.operator?this.rule.operator:"Equal",value1:this.rule&&this.rule.values.length>0?this.rule.values[0]:"",value2:this.cf&&this.rule.values.length>1?this.rule.values[1]:""},textColorTool:!1,fillColorTool:!1,style:{fillColor:this.cf&&this.rule.style.fillColor,textColor:this.cf&&this.rule.style.textColor,bold:this.cf&&this.rule.style.bold,italic:this.cf&&this.rule.style.italic,strikethrough:this.cf&&this.rule.style.strikethrough}}),or(window,"click",this.closeMenus)}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 o=t.detail.color;this.state.style[e]=o,this.closeMenus()}closeMenus(){this.state.textColorTool=!1,this.state.fillColorTool=!1}onSave(){const e={},t=this.state.style;void 0!==t.bold&&(e.bold=t.bold),void 0!==t.italic&&(e.italic=t.italic),void 0!==t.strikethrough&&(e.strikethrough=t.strikethrough),t.fillColor&&(e.fillColor=t.fillColor),t.textColor&&(e.textColor=t.textColor),this.trigger("modify-rule",{rule:{type:"CellIsRule",operator:this.state.condition.operator,values:[this.state.condition.value1,this.state.condition.value2],stopIfTrue:!1,style:e}})}onCancel(){this.trigger("cancel-edit")}}ar.template=ir,ar.style=rr,ar.components={ColorPicker:zi};const lr=s.Component,{useState:cr,hooks:hr}=s,{useExternalListener:ur}=hr,{xml:dr,css:pr}=s.tags,gr=dr`
220
226
  <div t-attf-class="o-threshold o-threshold-{{thresholdType}}">
221
227
  <div class="o-tools">
222
228
  <div class="o-tool o-dropdown o-with-color">
223
229
  <span title="Fill Color" t-attf-style="border-color:#{{colorNumberString(threshold.color)}}"
224
- t-on-click.stop="toggleMenu(thresholdType+'ColorTool')">${ji}</span>
230
+ t-on-click.stop="toggleMenu(thresholdType+'ColorTool')">${Wi}</span>
225
231
  <ColorPicker t-if="state[thresholdType+'ColorTool']" t-on-color-picked="setColor(thresholdType)"/>
226
232
  </div>
227
233
  </div>
@@ -235,22 +241,22 @@
235
241
 
236
242
  <input type="text" t-model="threshold.value" class="o-threshold-value"
237
243
  t-att-disabled="threshold.type !== 'number'"/>
238
- </div>`,pr=hr`
244
+ </div>`,fr=dr`
239
245
  <div>
240
246
  <div class="o-section-title">Format rules</div>
241
247
  <div class="o-cf-title-text">Preview</div>
242
- <t t-call="${hr`
248
+ <t t-call="${dr`
243
249
  <div class="o-cf-preview-gradient" t-attf-style="background-image: linear-gradient(to right, #{{colorNumberString(state.minimum.color)}}, #{{colorNumberString(state.maximum.color)}})">
244
250
  <div t-esc="previewText">Preview text</div>
245
251
  </div>
246
252
  `}"/>
247
253
  <div class="o-cf-title-text">Minpoint</div>
248
- <t t-call="${dr}">
254
+ <t t-call="${gr}">
249
255
  <t t-set="threshold" t-value="state.minimum" ></t>
250
256
  <t t-set="thresholdType" t-value="'minimum'" ></t>
251
257
  </t>
252
258
  <div class="o-cf-title-text">MaxPoint</div>
253
- <t t-call="${dr}">
259
+ <t t-call="${gr}">
254
260
  <t t-set="threshold" t-value="state.maximum" ></t>
255
261
  <t t-set="thresholdType" t-value="'maximum'" ></t>
256
262
  </t>
@@ -258,7 +264,7 @@
258
264
  <button t-on-click="onCancel" class="o-sidePanelButton o-cf-cancel">Cancel</button>
259
265
  <button t-on-click="onSave" class="o-sidePanelButton o-cf-save">Save</button>
260
266
  </div>
261
- </div>`,gr=ur`
267
+ </div>`,mr=pr`
262
268
  .o-cf-title-text {
263
269
  font-size: 12px;
264
270
  line-height: 14px;
@@ -279,12 +285,12 @@
279
285
  border: 1px solid darkgrey;
280
286
  padding: 10px;
281
287
  }
282
- `;class fr extends rr{constructor(){super(...arguments),this.cf=this.props.conditionalFormat,this.colorNumberString=f,this.rule=this.cf?this.cf.rule:null,this.state=ar({minimum:this.rule?Object.assign({},this.rule.minimum):{color:16777215,type:"value",value:null},maximum:this.rule?Object.assign({},this.rule.maximum):{color:0,type:"value",value:null},midpoint:this.rule&&Object.assign({},this.rule.midpoint)?this.rule.midpoint:{color:16777215,type:"value",value:null},maximumColorTool:!1,minimumColorTool:!1}),cr(window,"click",this.closeMenus)}toggleMenu(e){const t=this.state[e];this.closeMenus(),this.state[e]=!t}toggleTool(e){this.closeMenus()}setColor(e,t){const o=t.detail.color;this.state[e].color=Number.parseInt(o.substr(1),16),this.closeMenus()}closeMenus(){this.state.minimumColorTool=!1,this.state.maximumColorTool=!1}onSave(){this.trigger("modify-rule",{rule:{type:"ColorScaleRule",minimum:this.state.minimum,maximum:this.state.maximum,midpoint:this.state.midpoint}})}onCancel(){this.trigger("cancel-edit")}}fr.template=pr,fr.style=gr,fr.components={ColorPicker:Bi};const mr=s.Component,{useState:vr}=s,{xml:br,css:Er}=s.tags,wr=br`
288
+ `;class vr extends lr{constructor(){super(...arguments),this.cf=this.props.conditionalFormat,this.colorNumberString=f,this.rule=this.cf?this.cf.rule:null,this.state=cr({minimum:this.rule?Object.assign({},this.rule.minimum):{color:16777215,type:"value",value:null},maximum:this.rule?Object.assign({},this.rule.maximum):{color:0,type:"value",value:null},midpoint:this.rule&&Object.assign({},this.rule.midpoint)?this.rule.midpoint:{color:16777215,type:"value",value:null},maximumColorTool:!1,minimumColorTool:!1}),ur(window,"click",this.closeMenus)}toggleMenu(e){const t=this.state[e];this.closeMenus(),this.state[e]=!t}toggleTool(e){this.closeMenus()}setColor(e,t){const o=t.detail.color;this.state[e].color=Number.parseInt(o.substr(1),16),this.closeMenus()}closeMenus(){this.state.minimumColorTool=!1,this.state.maximumColorTool=!1}onSave(){this.trigger("modify-rule",{rule:{type:"ColorScaleRule",minimum:this.state.minimum,maximum:this.state.maximum,midpoint:this.state.midpoint}})}onCancel(){this.trigger("cancel-edit")}}vr.template=fr,vr.style=mr,vr.components={ColorPicker:zi};const br=s.Component,{useState:Er}=s,{xml:wr,css:Lr}=s.tags,Sr=wr`
283
289
  <div class="o-cf">
284
290
  <t t-if="state.mode === 'list'">
285
291
  <div class="o-cf-preview-list" >
286
292
  <div t-on-click="onRuleClick(cf)" t-foreach="getters.getConditionalFormats()" t-as="cf" t-key="cf.id">
287
- <t t-call="${br`
293
+ <t t-call="${wr`
288
294
  <div class="o-cf-preview">
289
295
  <div t-att-style="getStyle(cf.rule)" class="o-cf-preview-image">
290
296
  123
@@ -336,7 +342,7 @@
336
342
  <div class="o-cf-add" t-if="state.mode === 'list'" t-on-click.prevent.stop="onAdd">
337
343
  + Add another rule
338
344
  </div>
339
- </div>`,Lr=Er`
345
+ </div>`,Cr=Lr`
340
346
  .o-cf {
341
347
  min-width: 350px;
342
348
  .o-cf-type-selector {
@@ -485,7 +491,7 @@
485
491
  cursor: pointer;
486
492
  }
487
493
  }
488
- `;class Sr extends mr{constructor(e,t){super(e,t),this.colorNumberString=f,this.getters=this.env.getters,this.cellIsOperators=bi,this.state=vr({currentCF:void 0,currentRanges:[],mode:"list",toRuleType:"CellIsRule"}),this.editors={CellIsRule:ir,ColorScaleRule:fr},this.activeSheetId=this.getters.getActiveSheet(),t.selection&&1===this.getters.getRulesSelection(t.selection).length&&this.openCf(this.getters.getRulesSelection(t.selection)[0])}async willUpdateProps(e){const t=this.getters.getActiveSheet();t!==this.activeSheetId?(this.activeSheetId=t,this.resetState()):e.selection&&e.selection!==this.props.selection&&(e.selection&&1===this.getters.getRulesSelection(e.selection).length?this.openCf(this.getters.getRulesSelection(e.selection)[0]):this.resetState())}resetState(){this.state.currentCF=void 0,this.state.currentRanges=[],this.state.mode="list",this.state.toRuleType="CellIsRule"}getStyle(e){if("CellIsRule"===e.type){const t=e;return`font-weight:${t.style.bold?"bold":"normal"};\n text-decoration:${t.style.strikethrough?"line-through":"none"};\n font-style:${t.style.italic?"italic":"normal"};\n color:${t.style.textColor||"none"};\n background-color:${t.style.fillColor||"none"};`}{const t=e;return`background-image: linear-gradient(to right, #${f(t.minimum.color)}, #${f(t.maximum.color)})`}}getDescription(e){return"CellIsRule"===e.rule.type?bi[e.rule.operator]:"Color scale"}onSave(e){this.state.currentCF&&this.env.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{rule:e.detail.rule,ranges:this.state.currentRanges,id:"edit"===this.state.mode?this.state.currentCF.id:K()},sheet:this.getters.getActiveSheet()}),this.state.mode="list"}onCancel(){this.state.mode="list",this.state.currentCF=void 0}onDeleteClick(e){this.env.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:e.id,sheet:this.getters.getActiveSheet()})}onRuleClick(e){this.state.mode="edit",this.state.currentCF=e,this.state.toRuleType="CellIsRule"===e.rule.type?"CellIsRule":"ColorScaleRule",this.state.currentRanges=this.state.currentCF.ranges}openCf(e){const t=this.getters.getConditionalFormats(),o=t.findIndex((t=>t.id===e)),s=t[o];s&&(this.state.mode="edit",this.state.currentCF=s,this.state.toRuleType="CellIsRule"===s.rule.type?"CellIsRule":"ColorScaleRule",this.state.currentRanges=this.state.currentCF.ranges)}defaultCellIsRule(){return{rule:{type:"CellIsRule",operator:"Equal",values:[],style:{fillColor:"#FF0000"}},ranges:this.getters.getSelectedZones().map(this.getters.zoneToXC),id:K()}}defaultColorScaleRule(){return{rule:{minimum:{type:"value",color:0},maximum:{type:"value",color:15663086},type:"ColorScaleRule"},ranges:this.getters.getSelectedZones().map(this.getters.zoneToXC),id:K()}}onAdd(){this.state.mode="add",this.state.currentCF=this.defaultCellIsRule(),this.state.currentRanges=this.state.currentCF.ranges}setRuleType(e){"ColorScaleRule"===e&&(this.state.currentCF=this.defaultColorScaleRule()),"CellIsRule"===e&&(this.state.currentCF=this.defaultCellIsRule()),this.state.toRuleType=e}onRangesChanged({detail:e}){this.state.currentRanges=e.ranges}}Sr.template=wr,Sr.style=Lr,Sr.components={CellIsRuleEditor:ir,ColorScaleRuleEditor:fr,SelectionInput:ri};const Cr=new _e;Cr.add("ConditionalFormatting",{title:Q("Conditional formatting"),Body:Sr}),Cr.add("ChartPanel",{title:Q("Chart"),Body:Di});const yr=new _e;class Tr{constructor(e,t,o){this.index=0,this.cells=e,this.getters=t,this.direction=o}next(){const e=this.cells[this.index++%this.cells.length];if(!e.rule)return{cellData:e.data,tooltip:e.data.content?{props:e.data.content}:void 0};const t=e.rule,{cellData:o,tooltip:s}=pn.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:Object.assign({},e.data,o),tooltip:s}}}class xr extends dn{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheet();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:F(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:F(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?{status:"SUCCESS"}:{status:"CANCELLED",reason:17};case"AUTOFILL_AUTO":const o=this.getters.getSelectedZone();return o.top===o.bottom?{status:"SUCCESS"}:{status:"CANCELLED",reason:0}}return{status:"SUCCESS"}}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":const t=this.getters.getActiveSheet();this.dispatch("UPDATE_CELL",{sheet:t,col:e.col,row:e.row,style:e.style,border:e.border,content:e.content,format:e.format})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),o=this.autofillZone;switch(this.direction){case 1:for(let s=t.left;s<=t.right;s++){const n=[];for(let e=t.top;e<=t.bottom;e++)n.push(w(s,e));const i=this.createGenerator(n);for(let t=o.top;t<=o.bottom;t++)this.computeNewCell(i,s,t,e)}break;case 0:for(let s=t.left;s<=t.right;s++){const n=[];for(let e=t.bottom;e>=t.top;e--)n.push(w(s,e));const i=this.createGenerator(n);for(let t=o.bottom;t>=o.top;t--)this.computeNewCell(i,s,t,e)}break;case 2:for(let s=t.top;s<=t.bottom;s++){const n=[];for(let e=t.right;e>=t.left;e--)n.push(w(e,s));const i=this.createGenerator(n);for(let t=o.right;t>=o.left;t--)this.computeNewCell(i,t,s,e)}break;case 3:for(let s=t.top;s<=t.bottom;s++){const n=[];for(let e=t.left;e<=t.right;e++)n.push(w(e,s));const i=this.createGenerator(n);for(let t=o.left;t<=o.right;t++)this.computeNewCell(i,t,s,e)}}if(e){const e=C(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]})}}select(e,t){const o=this.getters.getSelectedZone();if(x(e,t,o))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,o.top-1,o.left,o.right);break;case 1:this.saveZone(o.bottom+1,t,o.left,o.right);break;case 2:this.saveZone(o.top,o.bottom,e,o.left-1);break;case 3:this.saveZone(o.top,o.bottom,o.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone();let t=e.left,o=e.bottom;if(t>0){let e=this.getters.getCell(t-1,o);for(;e&&e.content;)o+=1,e=this.getters.getCell(t-1,o)}if(o===e.bottom&&(t=e.right,t<=this.getters.getNumberCols(this.getters.getActiveSheet()))){let e=this.getters.getCell(t+1,o);for(;e&&e.content;)o+=1,e=this.getters.getCell(t+1,o)}o!==e.bottom&&(this.select(e.left,o-1),this.autofill(!0))}computeNewCell(e,t,o,s){const{cellData:n,tooltip:i}=e.next(),{col:r,row:a,content:l,style:c,border:h,format:u}=n;this.tooltip=i,s&&this.dispatch("AUTOFILL_CELL",{originCol:r,originRow:a,col:t,row:o,content:l,style:c,border:h,format:u})}getRule(e,t){const o=gn.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((o=>o.condition(e,t)));return o&&o.generateRule(e,t)}createGenerator(e){const t=[],o=[];for(let t of e){const[e,s]=E(t);let n={col:e,row:s,cell:this.getters.getCell(e,s)};o.push(n)}const s=o.map((e=>e.cell));for(let e of o){let o;o=e&&e.cell&&e.cell.content?this.getRule(e.cell,s):{type:"COPY_MODIFIER"};const n={row:e.row,col:e.col,content:e.cell?e.cell.content:void 0,style:e.cell?e.cell.style:void 0,border:e.cell?e.cell.border:void 0,format:e.cell?e.cell.format:void 0};t.push({data:n,rule:o})}return new Tr(t,this.getters,this.direction)}saveZone(e,t,o,s){this.autofillZone={top:e,bottom:t,left:o,right:s}}getDirection(e,t){const o=this.getters.getSelectedZone(),s={up:{number:o.top-t,value:0},down:{number:t-o.bottom,value:1},left:{number:o.left-e,value:2},right:{number:e-o.right,value:3}};if(1===Object.values(s).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(s).find((e=>e.number>0?1:0)).value;const n=s.up.number>0?"up":"down",i=s.left.number>0?"left":"right";return Math.abs(s[n].number)>=Math.abs(s[i].number)?s[n].value:s[i].value}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:o,thinLineWidth:s}=e,[n,i,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(o.strokeStyle="black",o.lineWidth=s,o.setLineDash([3]),o.strokeRect(n,i,r,a),o.setLineDash([]))}}xr.layers=[5],xr.getters=["getAutofillTooltip"],xr.modes=["normal","readonly"];const Rr=/^[S|N]?\d+/,Mr=un.content,Ar="+,-,*,/,:,=,<>,>=,>,<=,<,%,^,&".split(",");function Nr(e){const t=e.split(""),o=[];let s=0;for(;t.length;){if(s++,s>100)throw new Error(Q("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"));let e=Hr(t)||Dr(t)||Ur(t)||Pr(t)||Ir(t)||_r(t)||Fr(t)||zr(t);e||(e={type:"UNKNOWN",value:t.shift()}),o.push(e)}return o}const kr="|";function _r(e){if(e[0]===kr){e.shift();const t=e.join("").match(Rr);if(!t)return null;e.splice(0,t[0].length),e[0]===kr&&e.shift();const o=t[0];switch(o[0]){case"S":return{type:"NORMALIZED_STRING",value:o.substring(1)};case"N":return{type:"NORMALIZED_NUMBER",value:o.substring(1)};default:return{type:"REFERENCE",value:o}}}return null}function Ir(e){return"?"===e[0]?(e.shift(),{type:"DEBUGGER",value:"?"}):null}const Or={",":"COMMA","(":"LEFT_PAREN",")":"RIGHT_PAREN"};function Dr(e){if(e[0]in Or){const t=e.shift();return{type:Or[t],value:t}}return null}function $r(e,t){for(let o=0;o<t.length;o++)if(t[o]!==e[o])return!1;return!0}function Ur(e){for(let t of Ar)if($r(e,t))return e.splice(0,t.length),{type:"OPERATOR",value:t};return null}function Fr(e){const t=e.join("").match(B);return t?(e.splice(0,t[0].length),{type:"NUMBER",value:t[0]}):null}function Pr(e){if('"'===e[0]){const t=e.shift(),o=[t];for(;e[0]&&(e[0]!==t||"\\"===o[o.length-1]);)o.push(e.shift());return'"'===e[0]&&o.push(e.shift()),{type:"STRING",value:o.join("")}}return null}const Br=/\w|\.|!|\$/;function zr(e){const t=[];if("'"===e[0]){let o=e.shift();for(t.push(o);e[0];)if(o=e.shift(),t.push(o),"'"===o){if(!e[0]||"'"!==e[0])break;o=e.shift(),t.push(o)}if("'"!==o)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 Mr?"FUNCTION":"SYMBOL",value:e}}return null}const Zr=/\s/;function Hr(e){let t=0;for(;e[0]&&e[0].match(Zr);)t++,e.shift();return t?{type:"SPACE",value:" ".repeat(t)}:null}const Gr=un.content,Vr=["-","+"],jr={"^":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10};function qr(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 jr[e.value]||15}throw new Error("?")}const Wr=new RegExp(/\$?[A-Z]+\$?[0-9]+/,"i"),Yr=new RegExp(/^\s*\$?[A-Z]+\$?[0-9]+\s*(\s*:\s*\$?[A-Z]+\$?[0-9]+\s*)?$/,"i");function Xr(e,t,o){if("OPERATOR"===t.type){const s=Kr(o,qr(t));return{type:"BIN_OPERATION",value:t.value,left:e,right:s}}throw new Error(Q("nope"))}function Kr(e,t){const o=e.shift();if(!o)throw new Error(Q("invalid expression"));let s=function(e,t){var o;switch(e.type){case"DEBUGGER":const s=Kr(t,1e3);return s.debug=!0,s;case"NUMBER":return{type:"NUMBER",value:G(e.value)};case"NORMALIZED_NUMBER":return{type:"NORMALIZED_NUMBER",value:e.value};case"STRING":return{type:"STRING",value:e.value};case"NORMALIZED_STRING":return{type:"NORMALIZED_STRING",value:e.value};case"FUNCTION":if("LEFT_PAREN"!==t.shift().type)throw new Error(Q("wrong function call"));{const s=[];if(t[0]&&"RIGHT_PAREN"!==t[0].type)for("COMMA"===t[0].type?s.push({type:"UNKNOWN",value:""}):s.push(Kr(t,6));"COMMA"===(null===(o=t[0])||void 0===o?void 0:o.type);){t.shift();const e=t[0];if("RIGHT_PAREN"===(null==e?void 0:e.type)){s.push({type:"UNKNOWN",value:""});break}"COMMA"===(null==e?void 0:e.type)?s.push({type:"UNKNOWN",value:""}):s.push(Kr(t,6))}const n=t.shift();if(!n||"RIGHT_PAREN"!==n.type)throw new Error(Q("wrong function call"));return{type:Gr[e.value.toUpperCase()].async?"ASYNC_FUNCALL":"FUNCALL",value:e.value,args:s}}case"REFERENCE":return{type:"REFERENCE",value:parseInt(e.value,10)};case"SYMBOL":if(["TRUE","FALSE"].includes(e.value.toUpperCase()))return{type:"BOOLEAN",value:"TRUE"===e.value.toUpperCase()};if(e.value)throw new Error(Q("Invalid formula"));return{type:"UNKNOWN",value:e.value};case"LEFT_PAREN":const n=Kr(t,5);if(!t.length||"RIGHT_PAREN"!==t[0].type)throw new Error(Q("unmatched left parenthesis"));return t.shift(),n;default:if("OPERATOR"===e.type&&Vr.includes(e.value))return{type:"UNARY_OPERATION",value:e.value,right:Kr(t,jr[e.value])};throw new Error(Q("nope"))}}(o,e);for(;e[0]&&qr(e[0])>t;)s=Xr(s,e.shift(),e);return s}function Jr(e){const t=Nr(e).filter((e=>"SPACE"!==e.type));"OPERATOR"===t[0].type&&"="===t[0].value&&t.splice(0,1);const o=Kr(t,0);if(t.length)throw new Error(Q("invalid expression"));return o}const Qr=["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 ea extends dn{constructor(){super(...arguments),this.chartFigures=new Set,this.chartRuntime={},this.outOfDate=new Set}allowDispatch(e){const t={status:"SUCCESS"};switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const o=void 0!==e.definition.dataSets.find((e=>!Yr.test(e.split("!").pop()))),s=!Yr.test(e.definition.labelRange.split("!").pop());return o||s?{status:"CANCELLED",reason:16}:t;default:return t}}handle(e){switch(e.type){case"CREATE_CHART":this.addChartFigure(e.sheetId,{id:e.id,data:this.createChartDefinition(e.definition,e.sheetId),x:0,y:0,height:500,width:800,tag:"chart"});break;case"UPDATE_CHART":{const t=this.createChartDefinition(e.definition,this.getChartDefinition(e.id).sheetId);this.dispatch("UPDATE_FIGURE",{id:e.id,data:t}),this.history.updateLocalState(["chartRuntime",e.id],this.mapDefinitionToRuntime(t));break}case"DELETE_FIGURE":if(this.chartFigures.has(e.id)){const t=new Set(this.chartFigures);t.delete(e.id),this.history.updateLocalState(["chartFigures"],t),this.history.updateLocalState(["chartRuntime",e.id],void 0)}break;case"DUPLICATE_SHEET":{const t=e.id,o=[...this.chartFigures].map((e=>this.getters.getFigure(e))).filter((t=>t.data.sheetId===e.sheet)).map(D);for(let e of o)e.data.sheetId=t,e.id=K(),this.addChartFigure(t,e);break}case"DELETE_SHEET":const t=new Set(this.chartFigures),o={...this.chartRuntime};for(let e of this.chartFigures){this.getters.getFigure(e)||(t.delete(e),delete o[e])}this.history.updateLocalState(["chartFigures"],t),this.history.updateLocalState(["chartRuntime"],o);break;case"UPDATE_CELL":for(let t of this.chartFigures){const o=this.getChartDefinition(t);this.isCellUsedInChart(o,e.col,e.row)&&this.outOfDate.add(t)}}}finalize(e){switch(e.type){case"EVALUATE_CELLS":case"START":for(let e in this.chartRuntime)this.outOfDate.add(e)}}import(e){for(let t of e.sheets)for(let e of t.figures)"chart"===e.tag&&(this.outOfDate.add(e.id),this.chartFigures.add(e.id))}getChartRuntime(e){return this.outOfDate.has(e)&&(this.chartRuntime[e]=this.mapDefinitionToRuntime(this.getChartDefinition(e)),this.outOfDate.delete(e)),this.chartRuntime[e]}getChartDefinition(e){return this.getters.getFigure(e).data}createChartDefinition(e,t){let o=[];for(let t of e.dataSets){let s=L(t);if(s.left!==s.right&&s.top!==s.bottom)for(let t=s.left;t<=s.right;t++){const n={left:t,right:t,top:s.top,bottom:s.bottom};o.push(this.createDataset(n,e.seriesHasTitle))}else s.left===s.right&&s.top===s.bottom?e.seriesHasTitle||o.push({dataRange:S(s)}):o.push(this.createDataset(s,e.seriesHasTitle))}return{title:e.title,type:e.type,dataSets:o,labelRange:e.labelRange,sheetId:t}}createDataset(e,t){if(e.left!==e.right&&e.top!==e.bottom)throw new Error(`Zone should be a single column or row: ${S(e)}`);const o=t?w(e.left,e.top):void 0,s=t?1:0,n=e.top!==e.bottom&&e.left===e.right;return{labelCell:o,dataRange:S({top:n?e.top+s:e.top,bottom:e.bottom,left:n?e.left:e.left+s,right:e.right})}}getDefaultConfiguration(e,t,o){const s={type:e,options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:10,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!0,fontSize:22,fontStyle:"normal",text:t}},data:{labels:o,datasets:[]}};return"pie"!==e?s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{ticks:{beginAtZero:!0}}]}:s.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},s}extractDataFromRange(e,t){return t?this.getters.getRangeValues(t,e).flat(1):[]}mapDefinitionToRuntime(e){const t=""!==e.labelRange?this.getters.getRangeFormattedValues(e.labelRange,e.sheetId).flat(1):[],o=this.getDefaultConfiguration(e.type,e.title,t);let s=0;const n=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.extractDataFromRange(e.sheetId,t.dataRange).length)));for(let e=0;e<=t;e++)n.push(Qr[s]),s=++s%Qr.length}for(const[t,i]of Object.entries(e.dataSets)){let r;if(i.labelCell)try{r=this.getters.evaluateFormula(i.labelCell,e.sheetId)}catch(e){r=`${yi} ${parseInt(t)+1}`}else r=`${yi} ${parseInt(t)+1}`;const a={label:r,data:this.extractDataFromRange(e.sheetId,i.dataRange),lineTension:0,borderColor:"pie"!==e.type?Qr[s]:"#FFFFFF",backgroundColor:Qr[s]};"pie"===e.type&&(a.backgroundColor=n),s=++s%Qr.length,o.data.datasets.push(a)}return o}addChartFigure(e,t){this.dispatch("CREATE_FIGURE",{sheet:e,figure:t}),this.history.updateLocalState(["chartFigures"],new Set(this.chartFigures).add(t.id)),this.history.updateLocalState(["chartRuntime",t.id],this.mapDefinitionToRuntime(t.data))}isCellUsedInChart(e,t,o){if(x(t,o,L(e.labelRange)))return!0;for(let s of e.dataSets){if(s.dataRange&&s.dataRange.length>0&&x(t,o,L(s.dataRange)))return!0;if(s.labelCell&&s.labelCell.length>0&&x(t,o,L(s.labelCell)))return!0}return!1}}ea.getters=["getChartRuntime"],ea.layers=[3];class ta extends dn{constructor(){super(...arguments),this.status="empty",this.zones=[],this.originSheet=this.workbook.activeSheet.id,this._isPaintingFormat=!1,this.pasteOnlyValue=!1,this.pasteOnlyFormat=!1}allowDispatch(e){return"PASTE"===e.type?this.isPasteAllowed(e.target):{status:"SUCCESS"}}handle(e){switch(e.type){case"COPY":this.cutOrCopy(e.target,!1);break;case"CUT":this.cutOrCopy(e.target,!0);break;case"PASTE":this.pasteOnlyValue="onlyValue"in e&&!!e.onlyValue;const t="onlyFormat"in e?!!e.onlyFormat:this._isPaintingFormat;this._isPaintingFormat=!1,this.pasteOnlyFormat=!this.pasteOnlyValue&&t,e.interactive?this.interactivePaste(e.target):this.pasteFromModel(e.target);break;case"PASTE_CELL":this.pasteCell(e.origin,e.col,e.row,e.onlyValue,e.onlyFormat);break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this._isPaintingFormat=!0,this.cutOrCopy(e.target,!1)}}getClipboardContent(){return this.cells&&this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell):"")).join("\t"))).join("\n")||"\t"}getPasteZones(e){if(!this.cells)return e;const t=this.cells.length,o=this.cells[0].length,s=e[e.length-1],n=[];let i=s.left,r=s.top;const a=Math.max(1,Math.floor((s.right+1-s.left)/o)),l=Math.max(1,Math.floor((s.bottom+1-s.top)/t));for(let e=1;e<=a;e++)for(let s=1;s<=l;s++)n.push({left:i,top:r,right:i-1+e*o,bottom:r-1+s*t});return n}isPaintingFormat(){return this._isPaintingFormat}cutOrCopy(e,t){const o=new Set(e.map((e=>e.top))),s=new Set(e.map((e=>e.bottom)));let n=1===o.size&&1===s.size?e:[e[e.length-1]];n=n.map((e=>Object.assign({},e)));const i=[];let{top:r,bottom:a}=n[0];for(let e=r;e<=a;e++){const t=[];i.push(t);for(let o of n){let{left:s,right:n}=o;for(let o=s;o<=n;o++){const s=this.getters.getCell(o,e);t.push({cell:s?Object.assign({},s):null,col:o,row:e})}}}this.status="visible",this.shouldCut=t,this.zones=n,this.cells=i,this.originSheet=this.workbook.activeSheet.id}pasteFromClipboard(e,t){this.status="invisible";const o=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:s,top:n}=e[0],i=Math.max.apply(Math,o.map((e=>e.length))),r=o.length;this.addMissingDimensions(i,r,s,n);for(let e=0;e<o.length;e++)for(let t=0;t<o[e].length;t++){const i=w(s+t,n+e);this.dispatch("SET_VALUE",{xc:i,text:o[e][t]})}this.dispatch("SET_SELECTION",{anchor:[s,n],zones:[{left:s,top:n,right:s+i-1,bottom:n+r-1}]})}isPasteAllowed(e){const{zones:t,cells:o,status:s}=this;return t&&o&&"empty"!==s?e.length>1&&(o.length>1||o[0].length>1)?{status:"CANCELLED",reason:11}:{status:"SUCCESS"}:{status:"CANCELLED",reason:12}}pasteFromModel(e){const{cells:t,shouldCut:o}=this;if(!t)return;this.status=o?"empty":"invisible",o&&this.clearCutZone();const s=t.length,n=t[0].length;if(e.length>1){for(let t of e)for(let e=t.left;e<=t.right;e++)for(let o=t.top;o<=t.bottom;o++)this.pasteZone(n,s,e,o);return}const i=e[e.length-1];let r=i.left,a=i.top;const l=Math.max(1,Math.floor((i.right+1-i.left)/n)),c=Math.max(1,Math.floor((i.bottom+1-i.top)/s));for(let e=0;e<l;e++)for(let t=0;t<c;t++)this.pasteZone(n,s,r+e*n,a+t*s);if(s>1||n>1){const e={left:r,top:a,right:r+l*n-1,bottom:a+c*s-1},[t,o]=this.getters.getSelection().anchor,i=F(t,r,r+l*n-1),h=F(o,a,a+c*s-1);this.dispatch("SET_SELECTION",{anchor:[i,h],zones:[e]})}}clearCutZone(){for(let e of this.cells)for(let t of e)t&&this.dispatch("CLEAR_CELL",{sheet:this.originSheet,col:t.col,row:t.row})}pasteZone(e,t,o,s){this.addMissingDimensions(e,t,o,s);for(let n=0;n<t;n++){const t=this.cells[n];for(let i=0;i<e;i++){const e=t[i];this.dispatch("PASTE_CELL",{origin:e.cell,originCol:e.col,originRow:e.row,col:o+i,row:s+n,sheet:this.originSheet,cut:this.shouldCut,onlyValue:this.pasteOnlyValue,onlyFormat:this.pasteOnlyFormat})}}}addMissingDimensions(e,t,o,s){const{cols:n,rows:i}=this.workbook.activeSheet,r=t+s-i.length;r>0&&this.dispatch("ADD_ROWS",{row:i.length-1,sheet:this.workbook.activeSheet.id,quantity:r,position:"after"});const a=e+o-n.length;a>0&&this.dispatch("ADD_COLUMNS",{column:n.length-1,sheet:this.workbook.activeSheet.id,quantity:a,position:"after"})}pasteCell(e,t,o,s,n){const i=this.getters.getCell(t,o);if(e){let r=e.style,a=e.border,l=e.format,c=e.content||"";if(s)r=i?i.style:void 0,a=i?i.border:void 0,l=i?i.format:void 0,i&&"date"===i.type&&(l=i.value.format),"formula"!==e.type&&"date"!==e.type||(c=this.valueToContent(e.value));else if(n)c=i?i.content:"";else if("formula"===e.type){const s=t-e.col,n=o-e.row;c=this.getters.applyOffset(c,s,n)}let h={style:r,border:a,format:l,sheet:this.workbook.activeSheet.id,col:t,row:o,content:c};this.dispatch("UPDATE_CELL",h)}!e&&i&&(s?i.content&&(this.history.updateCell(i,"content",""),this.history.updateCell(i,"value","")):n?(i.style&&this.history.updateCell(i,"style",void 0),i.border&&this.history.updateCell(i,"border",void 0),i.format&&this.history.updateCell(i,"format",void 0)):this.dispatch("CLEAR_CELL",{sheet:this.workbook.activeSheet.id,col:t,row:o}))}valueToContent(e){switch(typeof e){case"number":return e.toString();case"string":return e;case"boolean":return e?"TRUE":"FALSE";case"object":return e.value.toString();default:return""}}interactivePaste(e){const t=this.dispatch("PASTE",{target:e,onlyFormat:!1});"CANCELLED"===t.status&&(11===t.reason&&this.ui.notifyUser(Q("This operation is not allowed with multiple selections.")),1===t.reason&&this.ui.askConfirmation(Q("Pasting here will remove existing merge(s). Paste anyway?"),(()=>this.dispatch("PASTE",{target:e,onlyFormat:!1,force:!0}))))}drawGrid(e){const{viewport:t,ctx:o,thinLineWidth:s}=e,n=this.zones;if("visible"===this.status&&n.length&&this.originSheet===this.getters.getActiveSheet()){o.save(),o.setLineDash([8,5]),o.strokeStyle="#3266ca",o.lineWidth=3.3*s;for(const e of n){const[s,n,i,r]=this.getters.getRect(e,t);i>0&&r>0&&o.strokeRect(s,n,i,r)}o.restore()}}}ta.layers=[2],ta.getters=["getClipboardContent","isPaintingFormat","getPasteZones"],ta.modes=["normal","readonly"];class oa extends dn{constructor(){super(...arguments),this.isStale=!0,this.cfRules={},this.computedStyles={},this.rulePredicate={CellIsRule:(e,t)=>{switch(t.operator){case"BeginsWith":return!(!e&&""===t.values[0])&&(e&&e.value.startsWith(t.values[0]));case"EndsWith":return!(!e&&""===t.values[0])&&(e&&e.value.endsWith(t.values[0]));case"Between":return e&&e.value>=t.values[0]&&e.value<=t.values[1];case"NotBetween":return!(e&&e.value>=t.values[0]&&e.value<=t.values[1]);case"ContainsText":return e&&e.value&&e.value.toString().indexOf(t.values[0])>-1;case"NotContains":return e&&e.value&&-1==e.value.toString().indexOf(t.values[0]);case"GreaterThan":return e&&e.value>t.values[0];case"GreaterThanOrEqual":return e&&e.value>=t.values[0];case"LessThan":return e&&e.value<t.values[0];case"LessThanOrEqual":return e&&e.value<=t.values[0];case"NotEqual":return!(!e&&""===t.values[0])&&(e&&e.value!=t.values[0]);case"Equal":return!e&&""===t.values[0]||e&&e.value==t.values[0];default:console.warn(Q("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.to;this.computedStyles[t]=this.computedStyles[t]||{},this.isStale=!0;break;case"CREATE_SHEET":this.cfRules[e.id]=[],this.isStale=!0;break;case"DUPLICATE_SHEET":this.history.updateLocalState(["cfRules",e.id],this.cfRules[e.sheet].slice()),this.isStale=!0;break;case"DELETE_SHEET":const o=Object.assign({},this.cfRules);delete o[e.sheet],this.history.updateLocalState(["cfRules"],o),this.isStale=!0;break;case"ADD_CONDITIONAL_FORMAT":this.addConditionalFormatting(e.cf,e.sheet),this.isStale=!0;break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheet),this.isStale=!0;break;case"REMOVE_COLUMNS":this.adaptcfRules(e.sheet,(t=>N(t,e.columns))),this.isStale=!0;break;case"REMOVE_ROWS":this.adaptcfRules(e.sheet,(t=>k(t,e.rows))),this.isStale=!0;break;case"ADD_COLUMNS":const s="before"===e.position?e.column:e.column+1;this.adaptcfRules(e.sheet,(t=>_(t,s,e.quantity))),this.isStale=!0;break;case"AUTOFILL_CELL":const n=this.getters.getActiveSheet(),i=this.getRulesByCell(w(e.originCol,e.originRow));for(const t of i)this.adaptRules(n,t,[w(e.col,e.row)],[]);break;case"ADD_ROWS":const r="before"===e.position?e.row:e.row+1;this.adaptcfRules(e.sheet,(t=>I(t,r,e.quantity))),this.isStale=!0;break;case"PASTE_CELL":e.onlyValue||this.pasteCf(e.originCol,e.originRow,e.col,e.row,e.sheet,e.cut);break;case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":this.isStale=!0}}finalize(){this.isStale&&"headless"!==this.currentMode&&(this.computeStyles(),this.isStale=!1)}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id])}getConditionalFormats(){return this.cfRules[this.workbook.activeSheet.id]}getConditionalStyle(e){return this.computedStyles[this.workbook.activeSheet.id]&&this.computedStyles[this.workbook.activeSheet.id][e]}getRulesSelection(e){const t=new Set;return e.forEach((e=>{this.getRulesByZone(e).forEach((e=>{t.add(e)}))})),Array.from(t)}getRulesByZone(e){const t=new Set;for(let o=e.top;o<=e.bottom;o++)for(let s=e.left;s<=e.right;s++){this.getRulesByCell(w(s,o)).forEach((e=>{t.add(e.id)}))}return t}getRulesByCell(e){const t=this.workbook.activeSheet.id,o=new Set;for(let s of this.cfRules[t])for(let t of s.ranges){const n=L(t);for(let t=n.top;t<=n.bottom;t++)for(let i=n.left;i<=n.right;i++){e==w(i,t)&&o.add(s)}}return o}addConditionalFormatting(e,t){const o=this.cfRules[t].slice(),s=o.findIndex((t=>t.id===e.id));s>-1?o.splice(s,1,e):o.push(e),this.history.updateLocalState(["cfRules",t],o)}applyColorScale(e,t){const o=Number(this.getters.evaluateFormula(`=min(${e})`)),s=Number(this.getters.evaluateFormula(`=max(${e})`));if(Number.isNaN(o)||Number.isNaN(s))return;const n=s-o;if(!n)return;const i=((t.minimum.color>>16)%256-(t.maximum.color>>16)%256)/n,r=((t.minimum.color>>8)%256-(t.maximum.color>>8)%256)/n,a=(t.minimum.color%256-t.maximum.color%256)/n,l=L(e);for(let e=l.top;e<=l.bottom;e++)for(let s=l.left;s<=l.right;s++){const n=this.getters.getCell(s,e);if(n&&!Number.isNaN(Number.parseFloat(n.value))){const e=Math.round((t.minimum.color>>16)%256-i*(n.value-o))<<16|Math.round((t.minimum.color>>8)%256-r*(n.value-o))<<8|Math.round(t.minimum.color%256-a*(n.value-o));this.computedStyles[this.workbook.activeSheet.id][n.xc]=this.computedStyles[this.workbook.activeSheet.id][n.xc]||{},this.computedStyles[this.workbook.activeSheet.id][n.xc].fillColor="#"+f(e)}}}computeStyles(){const e=this.workbook.activeSheet.id;this.computedStyles[e]={};for(let t of this.cfRules[e])try{if("ColorScaleRule"===t.rule.type)for(let e of t.ranges)this.applyColorScale(e,t.rule);else for(let o of t.ranges){const s=L(o);for(let o=s.top;o<=s.bottom;o++)for(let n=s.left;n<=s.right;n++){const s=this.rulePredicate[t.rule.type];let i=this.workbook.activeSheet.rows[o].cells[n],r=w(n,o);s&&s(i,t.rule)&&(this.computedStyles[e][r]=Object.assign(this.computedStyles[e][r]||{},t.rule.style))}}}catch(e){}}adaptcfRules(e,t){const o=this.cfRules[e],s=[];for(let e of o){const o=[];for(let s of e.ranges){const e=t(s);e&&o.push(e)}0!==o.length&&s.push({...e,ranges:o})}this.history.updateLocalState(["cfRules",e],s)}removeConditionalFormatting(e,t){const o=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==o){const e=this.cfRules[t].slice();e.splice(o,1),this.history.updateLocalState(["cfRules",t],e)}}pasteCf(e,t,o,s,n,i){const r=w(o,s);for(let o of this.cfRules[n])for(let s of o.ranges)if(x(e,t,L(s))){const s=o,a=[];i&&a.push(w(e,t)),n===this.workbook.activeSheet.id?this.adaptRules(n,s,[r],a):(this.adaptRules(this.workbook.activeSheet.id,s,[r],[]),this.adaptRules(n,s,[],a))}}adaptRules(e,t,o,s){if(0===o.length&&0===s.length)return;const n=this.cfRules[e].findIndex((e=>e.id===t.id));let i=[];n>-1&&(i=this.cfRules[e][n].ranges),i=i.concat(o);const r=R(i,s);this.addConditionalFormatting({id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue,ranges:r},e)}}oa.getters=["getConditionalFormats","getConditionalStyle","getRulesSelection"];const sa=un.content,na={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},ia={"-":"UMINUS","+":"UPLUS"},ra={},aa=Object.getPrototypeOf((async function(){})).constructor;function la(e){let t=!1;if(!ra[e.text]){const o=Jr(e.text);let s=1;const n=[`// ${e.text}`];if("BIN_OPERATION"===o.type&&":"===o.value)throw new Error(Q("Invalid formula"));if("UNKNOWN"===o.type)throw new Error(Q("Invalid formula"));function i(e){const t=sa[e.value.toUpperCase()];let o;const s=[],n=e.args;let i=0,a=!!t.args.length&&t.args[t.args.length-1].repeating?1/0:t.args.length;for(let e of t.args)e.optional||i++;if(n.length<i||n.length>a)throw new Error(Q("Invalid number of arguments for the %s function. Expected %s, but got %s instead.",e.value.toUpperCase(),t.args.length.toString(),n.length.toString()));for(let i=0;i<n.length;i++){const a=n[i];o=t.args[i]||o;const l=o&&o.lazy,c=o&&o.type||[],h=c.some((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e)),u=c.every((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e));if(u&&"REFERENCE"!==a.type)throw new Error(Q("Function %s expects the parameter %s to be reference to a cell or range, not a %s.",e.value.toUpperCase(),(i+1).toString(),a.type.toLowerCase().replace("normalized_","")));if("BIN_OPERATION"===a.type&&":"===a.value&&a.left.value!==a.right.value&&!h)throw new Error(Q("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",e.value.toUpperCase(),(i+1).toString()));let d=r(a,l,h,{functionName:e.value.toUpperCase(),paramIndex:i+1});s.push(d)}return s}function r(o,a=!1,l=!1,c={}){let h,u,d,p,g,f;switch(o.debug&&n.push("debugger;"),o.type){case"BOOLEAN":case"NUMBER":case"STRING":h=s++,f=o.value;break;case"NORMALIZED_NUMBER":case"NORMALIZED_STRING":h=s++,f=`deps[${o.value}]`;break;case"REFERENCE":if(!e.dependencies[o.value]){h=s++,f="null";break}h=s++,f=l?`range(${o.value}, deps, sheetId)`:`ref(${o.value}, deps, sheetId,\n "${c.functionName}", ${c.paramIndex})`;break;case"FUNCALL":h=s++,p=i(o),g=o.value.toUpperCase(),n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}'](${p})`;break;case"ASYNC_FUNCALL":h=s++,t=!0,p=i(o),g=o.value.toUpperCase(),n.push(`ctx.__lastFnCalled = '${g}'`),f=`await ctx['${g}'](${p})`;break;case"UNARY_OPERATION":h=s++,d=r(o.right),g=ia[o.value],n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}']( ${d})`;break;case"BIN_OPERATION":h=s++,u=r(o.left),d=r(o.right),g=na[o.value],n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}'](${u}, ${d})`;break;case"UNKNOWN":if(!a)return"null";h=s++,f="null"}return n.push(`let _${h} = `+(a?"()=> ":"")+f),`_${h}`}n.push(`return ${r(o)};`);let a=new(t?aa:Function)("deps","sheetId","ref","range","ctx",n.join("\n"));ra[e.text]=a,ra[e.text].async=t}return ra[e.text]}function ca(e,t=!1){let o,s,n,i;const r=()=>{i=void 0,s=void 0,o=void 0,n=void 0};for(let a=0;a<e.length;a++){const l=e[a];if(i)if(s){if("SPACE"===l.type)continue;if("OPERATOR"===l.type&&":"===l.value)o=a;else if(o&&"SYMBOL"===l.type)n=a;else if(i&&s&&o&&n){const o={type:"SYMBOL",value:e.slice(i,a).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(i,a-i,o),a=i+1,r()}else"SYMBOL"===l.type?(i=a,s=a,o=void 0):r()}else"SYMBOL"===l.type?(s=a,o=n=void 0):r();else["SPACE","SYMBOL"].includes(l.type)?(i=a,s="SYMBOL"===l.type?a:void 0,o=n=void 0):r()}const a=e.length-1;if(i&&s&&o&&n){const o={type:"SYMBOL",value:e.slice(i,a+1).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(i,a-i+1,o)}return e}function ha(e){return ca(Nr(e),!0)}function ua(e){return function(e){let t=1;const o=[];return e.map((e=>("LEFT_PAREN"===e.type?(o.push(t),e.parenIndex=t,t++):"RIGHT_PAREN"===e.type&&(e.parenIndex=o.pop()),e)))}(function(e){let t=0;return e.map((e=>{const o=e.value.toString().length,s=Object.assign({},e,{start:t,end:t+o,length:o});return t=s.end,s}))}(ca(Nr(e))))}function da(e){const t=ha(e);let o=[];return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Wr.test(e.value)){const t=e.value.trim();return o.includes(t)||o.push(t),`|${o.indexOf(t)}|`}if(["STRING","NUMBER"].includes(e.type)){const t="STRING"===e.type?e.value.slice(1).slice(0,e.value.length-2):G(e.value);return o.includes(t)||o.push(t),`|${e.type[0]}${o.indexOf(t)}|`}return e.value}))),dependencies:o}}const pa=new RegExp(String.fromCharCode(160),"g");class ga extends dn{constructor(){super(...arguments),this.sheetIds={},this.showFormulas=!1,this.updateColumnsRef=(e,t,o,s)=>{let n=E(e)[0];return n===o&&-1===s?"#REF":this.updateReference(e,n>o?s:0,0,this.getSheetIdByName(t),!1)},this.updateColumnsRange=(e,t,o,s)=>{const n=L(e),i=s<0?R([e],[this.zoneToXC({...n,left:o+s+1,right:o})]):[e];if(0===i.length)return"#REF";const r=L(i[0]),a=s<0&&n.left<o+s+1&&o<n.right?L(i[1]):r,l=o<r.left?r.left+s:r.left,c=o<a.right?a.right+s:a.right,[h,u]=e.split(":"),d=this.getters.getSheetIdByName(t),p=this.updateReference(h,l-n.left,0,d,!1,!1),g=this.updateReference(u,c-n.right,0,d,!1,!1);return p===g?p:`${p}:${g.split("!").pop()}`},this.updateRowsRef=(e,t,o,s)=>{let n=E(e)[1];return o+s<n&&n<=o?"#REF":this.updateReference(e,0,n>o?s:0,this.getSheetIdByName(t),!1)},this.updateRowsRange=(e,t,o,s)=>{const n=L(e),i=s<0?R([e],[this.zoneToXC({...n,top:o+s+1,bottom:o})]):[e];if(0===i.length)return"#REF";const r=L(i[0]),a=s<0&&n.top<o+s+1&&o<n.bottom?L(i[1]):r,l=o<r.top?r.top+s:r.top,c=o<a.bottom?a.bottom+s:a.bottom,[h,u]=e.split(":"),d=this.getters.getSheetIdByName(t),p=this.updateReference(h,0,l-n.top,d,!1,!1),g=this.updateReference(u,0,c-n.bottom,d,!1,!1);return p===g?p:`${p}:${g.split("!").pop()}`}}allowDispatch(e){switch(e.type){case"REMOVE_COLUMNS":return this.workbook.sheets[e.sheet].cols.length>e.columns.length?{status:"SUCCESS"}:{status:"CANCELLED",reason:5};case"REMOVE_ROWS":return this.workbook.sheets[e.sheet].rows.length>e.rows.length?{status:"SUCCESS"}:{status:"CANCELLED",reason:6};case"CREATE_SHEET":case"DUPLICATE_SHEET":const{visibleSheets:t,sheets:o}=this.workbook;return e.name&&t.find((t=>o[t].name===e.name))?{status:"CANCELLED",reason:8}:{status:"SUCCESS"};case"MOVE_SHEET":const s=this.workbook.visibleSheets.findIndex((t=>t===e.sheet));return-1===s?{status:"CANCELLED",reason:8}:"left"===e.direction&&0===s||"right"===e.direction&&s===this.workbook.visibleSheets.length-1?{status:"CANCELLED",reason:9}:{status:"SUCCESS"};case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET_CONFIRMATION":case"DELETE_SHEET":return this.workbook.visibleSheets.length>1?{status:"SUCCESS"}:{status:"CANCELLED",reason:7};default:return{status:"SUCCESS"}}}handle(e){switch(e.type){case"ACTIVATE_SHEET":this.history.updateState(["activeSheet"],this.workbook.sheets[e.to]);break;case"CREATE_SHEET":const t=this.createSheet(e.id,e.name||this.generateSheetName(),e.cols||26,e.rows||100);this.sheetIds[this.workbook.sheets[t].name]=t,e.activate&&this.dispatch("ACTIVATE_SHEET",{from:this.workbook.activeSheet.id,to:t});break;case"MOVE_SHEET":this.moveSheet(e.sheet,e.direction);break;case"RENAME_SHEET":e.interactive?this.interactiveRenameSheet(e.sheet,Q("Rename Sheet")):this.renameSheet(e.sheet,e.name);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheet,e.id,e.name);break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheet);break;case"DELETE_SHEET":this.deleteSheet(e.sheet);break;case"DELETE_CONTENT":this.clearZones(e.sheet,e.target);break;case"SET_VALUE":const[o,s]=E(e.xc);this.dispatch("UPDATE_CELL",{sheet:e.sheetId?e.sheetId:this.workbook.activeSheet.id,col:o,row:s,content:e.text});break;case"UPDATE_CELL":this.updateCell(e.sheet,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheet:e.sheet,col:e.col,row:e.row,content:"",border:0,style:0,format:""});break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const o=this.getColMaxWidth(t);0!==o&&this.setColSize(e.sheet,t,o+6)}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const o=this.getRowMaxHeight(t);0!==o&&this.setRowSize(e.sheet,t,o+6)}break;case"RESIZE_COLUMNS":for(let t of e.cols)this.setColSize(e.sheet,t,e.size);break;case"RESIZE_ROWS":for(let t of e.rows)this.setRowSize(e.sheet,t,e.size);break;case"REMOVE_COLUMNS":this.removeColumns(e.sheet,e.columns),this.history.updateState(["sheets",e.sheet,"colNumber"],this.workbook.sheets[e.sheet].colNumber-e.columns.length);break;case"REMOVE_ROWS":this.removeRows(e.sheet,e.rows),this.history.updateState(["sheets",e.sheet,"rowNumber"],this.workbook.sheets[e.sheet].rowNumber-e.rows.length);break;case"ADD_COLUMNS":this.addColumns(e.sheet,e.column,e.position,e.quantity),this.history.updateState(["activeSheet","colNumber"],this.workbook.activeSheet.colNumber+e.quantity);break;case"ADD_ROWS":this.addRows(e.sheet,e.row,e.position,e.quantity),this.history.updateState(["activeSheet","rowNumber"],this.workbook.activeSheet.rowNumber+e.quantity);break;case"SET_FORMULA_VISIBILITY":this.showFormulas=e.show}}applyOffset(e,t,o){return ha(e).map((e=>{if("SYMBOL"===e.type&&Wr.test(e.value)){const[s,n]=e.value.split("!").reverse(),i=this.getSheetIdByName(n);return s.includes(":")?this.updateRange(s,t,o,i):this.updateReference(s,t,o,i,!0,!1)}return e.value})).join("")}getCell(e,t,o){let s;if(o){const e=Object.values(this.workbook.sheets).find((e=>e.name===o));if(!e)return null;s=e.rows[t]}else s=this.workbook.activeSheet.rows[t];return s&&s.cells[e]||null}getCellText(e){const t=this.showFormulas?e.content:e.value,o=(t||0===t)&&e.format&&!e.error&&!e.pending,s=o&&e.format.match(/y|m|d|:/),n=o&&!s;switch(typeof t){case"string":return t;case"boolean":return t?"TRUE":"FALSE";case"number":return s?he({value:t,format:e.format}):n?Y(t,e.format):j(t);case"object":if(!t)return"0";if("value"in t&&"format"in t){if(s)return he(t,e.format);if(n)return Y(t.value,e.format);if(t&&t.format.match(/y|m|d|:/))return he(t)}return t.toString()}return""}zoneToXC(e){const t=w((e=this.getters.expandZone(e)).left,e.top),o=w(e.right,e.bottom);return t!=o&&this.getters.getMainCell(t)!==this.getters.getMainCell(o)?t+":"+o:t}getActiveSheet(){return this.workbook.activeSheet.id}getSheetName(e){return this.workbook.sheets[e]&&this.workbook.sheets[e].name}getSheetIdByName(e){return e&&this.sheetIds[$(e)]}getSheets(){const{visibleSheets:e,sheets:t}=this.workbook;return e.map((e=>t[e]))}getCol(e,t){return this.workbook.sheets[e].cols[t]}getRow(e,t){return this.workbook.sheets[e].rows[t]}getColCells(e){return this.workbook.activeSheet.rows.reduce(((t,o)=>o.cells[e]?t.concat(o.cells[e]):t),[])}getNumberCols(e){return this.workbook.sheets[e].cols.length}getNumberRows(e){return this.workbook.sheets[e].rows.length}getColsZone(e,t){return{top:0,bottom:this.workbook.activeSheet.rows.length-1,left:e,right:t}}getRowsZone(e,t){return{top:e,bottom:t,left:0,right:this.workbook.activeSheet.cols.length-1}}getGridSize(){const e=this.workbook.activeSheet,t=e.rows[e.rows.length-1].end+d+5;return[e.cols[e.cols.length-1].end+u,t]}shouldShowFormulas(){return this.showFormulas}getRangeValues(e,t){const[o,s]=e.split("!").reverse(),n=s?this.sheetIds[s]:t;return A(L(o),this.workbook.sheets[n],(e=>e.value))}getRangeFormattedValues(e,t){const[o,s]=e.split("!").reverse(),n=s?this.sheetIds[s]:t;return A(L(o),this.workbook.sheets[n],this.getters.getCellText,"")}getColMaxWidth(e){const t=this.workbook.activeSheet.rows.reduce(((t,o)=>o.cells[e]?t.concat(o.cells[e]):t),[]).map(this.getters.getCellWidth);return Math.max(0,...t)}getRowMaxHeight(e){const t=Object.values(this.workbook.activeSheet.rows[e].cells).map(this.getters.getCellHeight);return Math.max(0,...t)}setColSize(e,t,o){const s=this.workbook.sheets[e].cols,n=s[t],i=o-n.size;this.history.updateState(["sheets",e,"cols",t,"size"],o),this.history.updateState(["sheets",e,"cols",t,"end"],n.end+i);for(let o=t+1;o<s.length;o++){const t=s[o];this.history.updateState(["sheets",e,"cols",o,"start"],t.start+i),this.history.updateState(["sheets",e,"cols",o,"end"],t.end+i)}}setRowSize(e,t,o){const s=this.workbook.sheets[e].rows,n=s[t],i=o-n.size;this.history.updateState(["sheets",e,"rows",t,"size"],o),this.history.updateState(["sheets",e,"rows",t,"end"],n.end+i);for(let o=t+1;o<s.length;o++){const t=s[o];this.history.updateState(["sheets",e,"rows",o,"start"],t.start+i),this.history.updateState(["sheets",e,"rows",o,"end"],t.end+i)}}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let o of t)this.updateColumnsFormulas(o,-1,e),this.moveCellsHorizontally(o,-1,e),this.manageColumnsHeaders(o,-1,e)}removeRows(e,t){t.sort(((e,t)=>t-e));const o=t.reduce(((e,t,o,s)=>{if(t-s[o-1]==-1){e[e.length-1].push(t)}else e.push([t]);return e}),[]);for(let t of o)this.updateRowsFormulas(t[0],-t.length,e),this.moveCellVerticallyBatched(t[t.length-1],t[0],e),t.map((t=>this.processRowsHeaderDelete(t,e)))}addColumns(e,t,o,s){this.updateColumnsFormulas("before"===o?t-1:t,s,e),this.moveCellsHorizontally("before"===o?t:t+1,s,e),this.manageColumnsHeaders(t,s,e)}addRows(e,t,o,s){for(let e=0;e<s;e++)this.addEmptyRow();this.updateRowsFormulas("before"===o?t-1:t,s,e),this.moveCellsVertically("before"===o?t:t+1,s,e),this.processRowsHeaderAdd(t,s)}moveCellsHorizontally(e,t,o){return this.processCellsToMove((t=>t.col>=e),(o=>o.col!==e||-1!==t),(e=>({type:"UPDATE_CELL",sheet:o,col:e.col+t,row:e.row,content:e.content,border:e.border,style:e.style,format:e.format})),o)}moveCellVerticallyBatched(e,t,o){return this.processCellsToMove((({row:t})=>t>=e),(({row:e})=>e>t),(s=>({type:"UPDATE_CELL",sheet:this.workbook.sheets[o].id,col:s.col,row:s.row-(t-e+1),content:s.content,border:s.border,style:s.style,format:s.format})),o)}moveCellsVertically(e,t,o){return this.processCellsToMove((t=>t.row>=e),(o=>o.row!==e||-1!==t),(e=>({type:"UPDATE_CELL",sheet:o,col:e.col,row:e.row+t,content:e.content,border:e.border,style:e.style,format:e.format})),o)}manageColumnsHeaders(e,t,o){const s=[];let n=0,i=0;const r=this.workbook.sheets[o];for(let o in r.cols){if(parseInt(o,10)===e){if(-1===t)continue;{const{size:e}=r.cols[i];for(let o=0;o<t;o++)s.push({name:b(i),size:e,start:n,end:n+e}),n+=e,i++}}const{size:a}=r.cols[o];s.push({name:b(i),size:a,start:n,end:n+a}),n+=a,i++}this.history.updateState(["sheets",o,"cols"],s)}processRowsHeaderDelete(e,t){const o=[];let s=0,n=0;const i=this.workbook.sheets[t],r=i.rows.map((e=>e.cells));for(let t in i.rows){const a=i.rows[t],{size:l}=a;parseInt(t,10)!==e&&(n++,o.push({start:s,end:s+l,size:l,cells:r.shift(),name:String(n)}),s+=l)}this.history.updateState(["sheets",t,"rows"],o)}processRowsHeaderAdd(e,t){const o=[];let s=0,n=0,i=0;const r=this.workbook.activeSheet.rows.map((e=>e.cells));for(let a in this.workbook.activeSheet.rows){const{size:l}=this.workbook.activeSheet.rows[i];(parseInt(a,10)<e||parseInt(a,10)>=e+t)&&i++,n++,o.push({start:s,end:s+l,size:l,cells:r.shift(),name:String(n)}),s+=l}this.history.updateState(["activeSheet","rows"],o)}addEmptyRow(){const e=this.workbook.activeSheet.rows[this.workbook.activeSheet.rows.length-1].end,t=(this.workbook.activeSheet.rows.length+1).toString(),o=this.workbook.activeSheet.rows.slice();o.push({start:e,end:e+0,size:0,name:t,cells:{}});this.history.updateState(["activeSheet","rows"],o)}updateColumnsFormulas(e,t,o){return this.visitFormulas(this.workbook.sheets[o].name,((o,s)=>o.includes(":")?this.updateColumnsRange(o,s,e,t):this.updateColumnsRef(o,s,e,t)))}updateRowsFormulas(e,t,o){return this.visitFormulas(this.workbook.sheets[o].name,((o,s)=>o.includes(":")?this.updateRowsRange(o,s,e,t):this.updateRowsRef(o,s,e,t)))}processCellsToMove(e,t,o,s){const n=[],i=[],r=this.workbook.sheets[s];for(let s in r.cells){let a=r.cells[s];if(e(a)){const[e,l]=E(s);n.push({type:"CLEAR_CELL",sheet:r.id,col:e,row:l}),t(a)&&i.push(o(a))}}for(let e of n)this.dispatch(e.type,e);for(let e of i)this.dispatch(e.type,e)}updateCell(e,t,o,s){const n=this.workbook.sheets[e],i=n.rows[o].cells[t],r=i&&i.xc||w(t,o),a="content"in s,l=s.content?s.content.replace(pa,""):"";let c=a?l:i&&i.content||"";const h="style"in s?s.style:i&&i.style||0,u="border"in s?s.border:i&&i.border||0;let d="format"in s?s.format:i&&i.format||"";if(!(c||h||u||d))return void(i&&(this.history.updateSheet(n,["cells",r],void 0),this.history.updateSheet(n,["rows",o,"cells",t],void 0)));const p=!i&&l||a&&i&&i.content!==l;let g;if(i&&!p)g={col:t,row:o,xc:r,content:c,value:i.value,type:i.type},"formula"===g.type&&(g.error=i.error,g.pending=i.pending,g.formula=i.formula);else{let e="="===c[0]?"formula":"text",s=c;Z(c)&&(s=G(c),e="number",c.includes("%")&&(d=c.includes(".")?"0.00%":"0%"));let n=ae(c);n&&(e="date",s=n,c=he(n));const i=c.toUpperCase();if("TRUE"===i&&(s=!0),"FALSE"===i&&(s=!1),g={col:t,row:o,xc:r,content:c,value:s,type:e},"formula"===g.type){g.error=void 0;try{let e=da(g.content||""),t=la(e);g.formula={compiledFormula:t,dependencies:e.dependencies,text:e.text}}catch(e){g.value="#BAD_EXPR",g.error=e.message||Q("Invalid Expression")}}}h&&(g.style=h),u&&(g.border=u),d&&(g.format=d),this.history.updateSheet(n,["cells",r],g),this.history.updateSheet(n,["rows",o,"cells",t],g)}generateSheetName(){let e=1;const t=this.getSheets().map((e=>e.name)),o=Q("Sheet");let s=`${o}${e}`;for(;t.includes(s);)s=`${o}${e}`,e++;return s}createSheet(e,t,o,s){const n={id:e,name:t,cells:{},colNumber:o,rowNumber:s,cols:fa(o),rows:ma(s),merges:{},mergeCellMap:{}},i=this.workbook.visibleSheets.slice(),r=i.findIndex((e=>this.workbook.activeSheet.id===e));i.splice(r+1,0,n.id);const a=this.workbook.sheets;return this.history.updateState(["visibleSheets"],i),this.history.updateState(["sheets"],Object.assign({},a,{[n.id]:n})),n.id}moveSheet(e,t){const o=this.workbook.visibleSheets.slice(),s=o.findIndex((t=>t===e)),n=o.splice(s,1);o.splice(s+("left"===t?-1:1),0,n[0]),this.history.updateState(["visibleSheets"],o)}isRenameAllowed(e){if(e.interactive)return{status:"SUCCESS"};const t=e.name&&e.name.trim().toLowerCase();return t&&-1===this.workbook.visibleSheets.findIndex((e=>this.workbook.sheets[e].name.toLowerCase()===t))?{status:"SUCCESS"}:{status:"CANCELLED",reason:8}}interactiveRenameSheet(e,t){const o=this.getSheetName(e);this.ui.editText(t,o,(t=>{if(!t)return;const o=this.dispatch("RENAME_SHEET",{sheet:e,name:t}),s=this.getSheetName(e);"CANCELLED"===o.status&&s!==t&&this.interactiveRenameSheet(e,Q("Please enter a valid sheet name"))}))}renameSheet(e,t){const o=this.workbook.sheets[e],s=o.name;this.history.updateSheet(o,["name"],t.trim());const n=Object.assign({},this.sheetIds);n[t]=o.id,delete n[s],this.history.updateLocalState(["sheetIds"],n),this.visitAllFormulasSymbols((e=>{let[t,n]=e.split("!").reverse();return n&&(n=$(n),n===s)?t.includes(":")?this.updateRange(t,0,0,o.id):this.updateReference(t,0,0,o.id):e}))}duplicateSheet(e,t,o){const s=this.workbook.sheets[e],n=JSON.parse(JSON.stringify(s));n.id=t,n.name=o;const i=this.workbook.visibleSheets.slice(),r=i.findIndex((t=>t===e));i.splice(r+1,0,n.id),this.history.updateState(["visibleSheets"],i),this.history.updateState(["sheets"],Object.assign({},this.workbook.sheets,{[n.id]:n}));const a=Object.assign({},this.sheetIds);a[n.name]=n.id,this.history.updateLocalState(["sheetIds"],a),this.dispatch("ACTIVATE_SHEET",{from:this.workbook.activeSheet.id,to:t})}interactiveDeleteSheet(e){this.ui.askConfirmation(Q("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheet:e})}))}deleteSheet(e){const t=this.workbook.sheets[e].name,o=Object.assign({},this.workbook.sheets);delete o[e],this.history.updateState(["sheets"],o);const s=this.workbook.visibleSheets.slice(),n=s.findIndex((t=>t===e));s.splice(n,1),this.history.updateState(["visibleSheets"],s);const i=Object.assign({},this.sheetIds);delete i[t],this.history.updateLocalState(["sheetIds"],i),this.visitAllFormulasSymbols((e=>{let[,o]=e.split("!").reverse();return o&&(o=$(o),o===t)?"#REF":e})),this.getActiveSheet()===e&&this.dispatch("ACTIVATE_SHEET",{from:e,to:s[Math.max(0,n-1)]})}clearZones(e,t){const o=this.workbook.activeSheet.cells;for(let s of t)for(let t=s.left;t<=s.right;t++)for(let n=s.top;n<=s.bottom;n++){w(t,n)in o&&this.dispatch("UPDATE_CELL",{sheet:e,content:"",col:t,row:n})}}updateRange(e,t,o,s){let[n,i]=e.split(":");return n=this.updateReference(n,t,o,s,!0,!1),i=this.updateReference(i,t,o,s,!0,!1),"#REF"===n||"#REF"===i?"#REF":(i=i.split("!").pop(),`${n}:${i}`)}updateReference(e,t,o,s,n=!0,i=!0){const r=e.replace(/\$/g,"");let[a,l]=E(r);const c=e.startsWith("$"),h=e.includes("$",1);if(a+=c&&n?0:t,l+=h&&n?0:o,a<0||l<0||i&&(a>=this.getters.getNumberCols(s||this.getters.getActiveSheet())||l>=this.getters.getNumberRows(s||this.getters.getActiveSheet())))return"#REF";const u=s&&U(this.getters.getSheetName(s));return(u?`${u}!`:"")+(c?"$":"")+b(a)+(h?"$":"")+String(l+1)}visitAllFormulasSymbols(e){for(let t in this.workbook.sheets){const o=this.workbook.sheets[t];for(let[t,s]of Object.entries(o.cells))if("formula"===s.type){const n=ha(s.content).map((t=>"SYMBOL"===t.type&&Wr.test(t.value)?e(t.value,o.id):t.value)).join("");if(n!==s.content){const[e,s]=E(t);this.dispatch("UPDATE_CELL",{sheet:o.id,col:e,row:s,content:n})}}}}visitFormulas(e,t){this.visitAllFormulasSymbols(((o,s)=>{let[n,i]=o.split("!").reverse();if(i){if(i=$(i),i===e)return t(n,i)}else if(this.sheetIds[e]===s)return t(n,void 0);return o}))}import(e){for(let t of e.sheets)this.sheetIds[t.name]=t.id;for(let t of e.sheets)this.importSheet(t);this.workbook.activeSheet=this.workbook.sheets[e.activeSheet]}importSheet(e){let{sheets:t,visibleSheets:o}=this.workbook;const s=e.name||`Sheet${Object.keys(t).length+1}`,{colNumber:n,rowNumber:i}=function(e){const t=Object.keys(e.cells).map(E);return{rowNumber:Math.max(e.rowNumber,...new Set(t.map((([e,t])=>t+1)))),colNumber:Math.max(e.colNumber,...new Set(t.map((([e,t])=>e+1))))}}(e),r={id:e.id,name:s,cells:{},colNumber:n,rowNumber:i,cols:va(e.cols||{},n),rows:ba(e.rows||{},i),merges:{},mergeCellMap:{}};o=o.slice(),o.push(r.id),this.history.updateState(["visibleSheets"],o),this.history.updateState(["sheets"],Object.assign({},t,{[r.id]:r}));for(let t in e.cells){const o=e.cells[t],[s,n]=E(t);this.updateCell(e.id,s,n,o)}}export(e){e.sheets=this.workbook.visibleSheets.map((e=>{const t=this.workbook.sheets[e],o={};for(let[e,s]of Object.entries(t.cells))o[e]={content:s.content,border:s.border,style:s.style,format:s.format};return{id:t.id,name:t.name,colNumber:t.colNumber,rowNumber:t.rowNumber,rows:wa(t.rows),cols:Ea(t.cols),merges:[],cells:o,conditionalFormats:[],figures:[]}})),e.activeSheet=this.workbook.activeSheet.id}}function fa(e){const t=[];let o=0;for(let s=0;s<e;s++){const e={start:o,end:o+u,size:u,name:b(s)};t.push(e),o=e.end}return t}function ma(e){const t=[];let o=0;for(let s=0;s<e;s++){const e={start:o,end:o+d,size:d,name:String(s+1),cells:{}};t.push(e),o=e.end}return t}function va(e,t){const o=[];let s=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||u,i={start:s,end:s+t,size:t,name:b(n)};o.push(i),s=i.end}return o}function ba(e,t){const o=[];let s=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||d,i={start:s,end:s+t,size:t,name:String(n+1),cells:{}};o.push(i),s=i.end}return o}function Ea(e){const t={};for(let o in e){const s=e[o];s.size!==u&&(t[o]={size:s.size})}return t}function wa(e){const t={};for(let o in e){const s=e[o];s.size!==d&&(t[o]={size:s.size})}return t}ga.getters=["applyOffset","getColsZone","getRowsZone","getCell","getCellText","zoneToXC","getActiveSheet","getSheetName","getSheetIdByName","getSheets","getCol","getRow","getColCells","getNumberCols","getNumberRows","getGridSize","shouldShowFormulas","getRangeValues","getRangeFormattedValues"];class La extends dn{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent=""}beforeHandle(e){if("ACTIVATE_SHEET"===e.type)"selecting"!==this.mode&&this.stopEdition()}handle(e){switch(e.type){case"START_COMPOSER_SELECTION":this.mode="selecting",this.dispatch("SET_SELECTION",{zones:this.getters.getSelectedZones(),anchor:this.getters.getPosition()});break;case"STOP_COMPOSER_SELECTION":"selecting"===this.mode&&(this.mode="editing");break;case"START_EDITION":this.startEdition(e.text);break;case"STOP_EDITION":e.cancel?this.cancelEdition():this.stopEdition();break;case"SET_CURRENT_CONTENT":this.currentContent=e.content;break;case"SELECT_CELL":case"MOVE_POSITION":"editing"===this.mode&&this.stopEdition()}}getEditionMode(){return this.mode}getCurrentContent(){return this.currentContent}getEditionSheet(){return this.sheet}startEdition(e){if(!e){const t=this.getters.getActiveCell();e=t&&t.content||""}this.mode="editing",this.currentContent=e||"",this.dispatch("REMOVE_ALL_HIGHLIGHTS");const[t,o]=this.getters.getPosition();this.col=t,this.row=o,this.sheet=this.getters.getActiveSheet()}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();let e=w(this.col,this.row);const{mergeCellMap:t,merges:o,cells:s}=this.getters.getSheets().find((e=>e.id===this.sheet));if(e in t){e=o[t[e]].topLeft}let n=this.currentContent;this.currentContent="";const i=s[e];if(!(i?i.content!==n:""!==n))return;const[r,a]=E(e);if(n){if(n.startsWith("=")){const e=Nr(n),t=e.filter((e=>"LEFT_PAREN"===e.type)).length,o=e.filter((e=>"RIGHT_PAREN"===e.type)).length,s=t-o;s>0&&(n+=new Array(s).fill(")").join(""))}this.dispatch("UPDATE_CELL",{sheet:this.sheet,col:r,row:a,content:n})}else this.dispatch("UPDATE_CELL",{sheet:this.sheet,content:"",col:r,row:a});this.getters.getActiveSheet()!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:this.sheet})}}cancelEdition(){this.mode="inactive",this.dispatch("REMOVE_ALL_HIGHLIGHTS")}}function*Sa(e){for(let t of e)yield t}La.layers=[1],La.getters=["getEditionMode","getCurrentContent","getEditionSheet"],La.modes=["normal","readonly"];const Ca=un.mapping,ya="Loading...";class Ta extends dn{constructor(e,t,o,s,n){super(e,t,o,s,n),this.isUptodate=new Set,this.loadingCells=0,this.isStarted=!1,this.PENDING=new Set,this.WAITING={},this.COMPUTED=new Set,this.evalContext=n.evalContext}handle(e){switch(e.type){case"START":this.evaluate();break;case"UPDATE_CELL":"content"in e&&this.isUptodate.clear();break;case"EVALUATE_CELLS":if(e.onlyWaiting)for(const e in this.WAITING){const t=new Set(this.WAITING[e]);this.WAITING[e].clear(),this.evaluateCells(Sa(t),e)}else{for(const e in this.WAITING)delete this.WAITING[e];this.evaluate()}this.isUptodate.add(this.workbook.activeSheet.id);break;case"UNDO":case"REDO":this.isUptodate.clear()}}finalize(){this.isUptodate.has(this.workbook.activeSheet.id)||(this.evaluate(),this.isUptodate.add(this.workbook.activeSheet.id)),this.loadingCells>0&&this.startScheduler()}evaluateFormula(e,t=this.workbook.activeSheet.id){let o=da(e);const s=la(o),n=this.getFormulaParameters((()=>{}));return s(o.dependencies,t,...n)}isIdle(){return 0===this.loadingCells}startScheduler(){if(!this.isStarted){this.isStarted=!0;let e=this.loadingCells;const t=()=>{this.loadingCells!==e&&(this.dispatch("EVALUATE_CELLS",{onlyWaiting:!0}),e=this.loadingCells,0===e&&(this.isStarted=!1)),e>0&&window.setTimeout(t,15)};window.setTimeout(t,5)}}evaluate(){this.COMPUTED.clear(),this.evaluateCells(function*(e){for(let t in e)yield e[t]}(this.workbook.activeSheet.cells),this.workbook.activeSheet.id)}evaluateCells(e,t){const o=this,{COMPUTED:s,PENDING:n,WAITING:i}=this,r=this.getFormulaParameters(h),a={},l=[...e];for(let e of l)"#BAD_EXPR"!==e.value&&(e.error=void 0);for(let e of l)h(e,t);function c(e,t,s){if(e instanceof Error||(e=new Error(e)),n.has(t)&&(n.delete(t),o.loadingCells--),"not ready"===e.message)i[s]||(i[s]=new Set),i[s].add(t),t.pending=!0,t.value=ya;else if(!t.error){t.value="#ERROR";const o=r[2].__lastFnCalled||"";t.error=e.message.replace("[[FUNCTION_NAME]]",o)}}function h(e,t){if("formula"!==e.type||!e.formula)return;const i=e.xc;if(a[t]=a[t]||{},i in a[t])null===a[t][i]&&(e.value="#CYCLE",e.error=Q("Circular reference"));else if(!s.has(e)&&!n.has(e)){a[t][i]=null,e.error=void 0;try{if(r[2].__originCellXC=i,e.formula.compiledFormula.async?(e.value=ya,e.pending=!0,n.add(e),e.formula.compiledFormula(e.formula.dependencies,t,...r).then((t=>{e.value=t,o.loadingCells--,n.has(e)&&(n.delete(e),e.pending=!1,s.add(e))})).catch((o=>c(o,e,t))),o.loadingCells++):(e.value=e.formula.compiledFormula(e.formula.dependencies,t,...r),e.pending=!1),Array.isArray(e.value))throw new Error(Q("This formula depends on invalid values"));e.error=void 0}catch(o){c(o,e,t)}a[t][i]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Ca),this.evalContext,{getters:this.getters}),o=this.workbook.sheets,s=this.PENDING;function n(t,o){if(t.formula&&t.formula.compiledFormula.async&&t.error&&!s.has(t))throw new Error(Q("This formula depends on invalid values"));if(e(t,o),t.error)throw new Error(Q("This formula depends on invalid values"));return t.value}function i(e,t,s){const i=o[s];let[r,a]=E(e),[l,c]=E(t);if(l=Math.min(l,i.colNumber-1),c=Math.min(c,i.rowNumber-1),r>l){const e=r;r=l,l=e}if(a>c){const e=a;a=c,c=e}const h=A({left:r,top:a,right:l,bottom:c},i,(e=>n(e,s)));for(const e of h)for(const t of e)if(t===ya)throw new Error("not ready");return h}return[function(e,s,i,r,a){const l=s[e],[c,h]=l.split("!").reverse(),u=h?t.getters.getSheetIdByName(h):i,d=L(l);if(d.top>d.bottom||d.left>d.right)throw new Error(Q("invalid range %s:%s",w(d.left,d.top),w(d.right,d.bottom)));if(d.bottom!==d.top||d.left!==d.right)throw new Error(Q("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",r.toString(),a.toString()));return function(e,t){let s;const i=o[t];if(!i)throw new Error(Q("Invalid sheet name"));if(s=i.cells[e.toUpperCase().replace(/\$/g,"")],!s||""===s.content)return null;const r=n(s,t);if(r===ya)throw new Error("not ready");return r}(c,u)},function(e,o,s){const n=o[e],[r,a]=n.split("!").reverse(),l=a?t.getters.getSheetIdByName(a):s;if(o[e]&&!o[e].includes(":"))return i(r,r,l);{const[e,t]=r.split(":");return i(e,t,l)}},t]}}Ta.getters=["evaluateFormula","isIdle"],Ta.modes=["normal","readonly"];class xa extends dn{constructor(){super(...arguments),this.selectedFigureId=null,this.figures={},this.sheetFigures={}}handle(e){switch(e.type){case"DELETE_SHEET":this.deleteSheet(e.sheet);break;case"CREATE_FIGURE":this.history.updateLocalState(["figures",e.figure.id],e.figure);const t=(this.sheetFigures[e.sheet]||[]).slice();t.push(e.figure),this.history.updateLocalState(["sheetFigures",e.sheet],t);break;case"UPDATE_FIGURE":void 0!==e.x&&this.history.updateLocalState(["figures",e.id,"x"],Math.max(e.x,0)),void 0!==e.y&&this.history.updateLocalState(["figures",e.id,"y"],Math.max(e.y,0)),void 0!==e.width&&this.history.updateLocalState(["figures",e.id,"width"],e.width),void 0!==e.height&&this.history.updateLocalState(["figures",e.id,"height"],e.height),void 0!==e.data&&this.history.updateLocalState(["figures",e.id,"data"],e.data);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"DELETE_FIGURE":this.history.updateLocalState(["figures",e.id],void 0);for(let t in this.sheetFigures){let o=this.sheetFigures[t].findIndex((t=>t.id===e.id));if(o>-1){const e=this.sheetFigures[t].slice();e.splice(o,1),this.history.updateLocalState(["sheetFigures",t],e),this.selectedFigureId=null}}break;case"EVALUATE_CELLS":break;default:this.selectedFigureId=null}}deleteSheet(e){for(let t of this.sheetFigures[e]||[])this.history.updateLocalState(["figures",t.id],void 0);const t=Object.assign({},this.sheetFigures);delete t[e],this.history.updateLocalState(["sheetFigures"],t)}getFigures(e){const t=[],o=this.sheetFigures[this.workbook.activeSheet.id]||[],{offsetX:s,offsetY:n,width:i,height:r}=e;for(let e of o)e.x>=s+i||e.x+e.width<=s||e.y>=n+r||e.y+e.height<=n||t.push(e);return t}getSelectedFigureId(){return this.selectedFigureId}getFigure(e){return this.figures[e]}import(e){for(let t of e.sheets){const e=[];for(let o of t.figures)this.figures[o.id]=o,e.push(o);this.sheetFigures[t.id]=e}}export(e){for(let t of e.sheets)t.figures=this.sheetFigures[t.id]||[]}}xa.getters=["getFigures","getSelectedFigureId","getFigure"];const Ra={top:["top"],left:["left"],right:["right"],bottom:["bottom"],all:["top","left","bottom","right"]},Ma={fillColor:"white",textColor:"black",fontSize:11};class Aa extends dn{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d"),this.styles={},this.borders={},this.nextId=1}handle(e){switch(e.type){case"SET_FORMATTING":e.style&&this.setStyle(e.sheet,e.target,e.style),e.border&&this.setBorder(e.sheet,e.target,e.border);break;case"CLEAR_FORMATTING":this.clearFormatting(e.target);break;case"SET_FORMATTER":this.setFormatter(e.sheet,e.target,e.formatter);break;case"SET_DECIMAL":this.setDecimal(e.sheet,e.target,e.step);break;case"ADD_COLUMNS":const t="before"===e.position?e.column-1:e.column,o=t+e.quantity+1;this.onAddElements(t,o,!0,"before"===e.position);break;case"ADD_ROWS":const s="before"===e.position?e.row-1:e.row,n=s+e.quantity+1;this.onAddElements(s,n,!1,"before"===e.position)}}getCellWidth(e){const t=e.style||0,o=this.getters.getCellText(e);return this.getTextWidth(o,t)}getTextWidth(e,t=0){const o=this.styles[t],s=o.italic?"italic ":"",n=o.bold?"bold":"400",i=o.fontSize||10,r=Qn[i];return this.ctx.font=`${s}${n} ${r}px 'Roboto', arial`,this.ctx.measureText(e).width}getCellHeight(e){const t=this.styles[e&&e.style||0].fontSize||10;return Qn[t]}getCellStyle(e){return e.style?this.styles[e.style]:{}}getCellBorder(e){return e.border?this.borders[e.border]:null}getCurrentStyle(){const e=this.getters.getActiveCell();return e&&e.style?this.styles[e.style]:{}}setStyle(e,t,o){for(let e of t)for(let t=e.left;t<=e.right;t++)for(let s=e.top;s<=e.bottom;s++)this.setStyleToCell(t,s,o)}setStyleToCell(e,t,o){const s=this.getters.getCell(e,t),n=s&&s.style?this.styles[s.style]:{},i=Object.assign({},n,o),r=this.registerStyle(i);this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:e,row:t,style:r})}registerStyle(e){const t=O(e);for(let e in this.styles)if(O(this.styles[e])===t)return parseInt(e,10);const o=this.nextId++;return this.styles[o]=e,o}setBorder(e,t,o){const s={};for(let n of t)this.aggregateBorderCommands(e,n,o,s);for(let[t,o]of Object.entries(s)){const[s,n]=E(t),i=this.getters.getCell(s,n);(i&&i.border||0)!==o&&this.dispatch("UPDATE_CELL",{sheet:e,col:s,row:n,border:o})}}aggregateBorderCommands(e,t,o,s){if("clear"===o){for(let o=t.top;o<=t.bottom;o++)for(let n=t.left;n<=t.right;n++)this.clearBorder(e,n,o,s);return}if("external"===o)return this.aggregateBorderCommands(e,t,"left",s),this.aggregateBorderCommands(e,t,"right",s),this.aggregateBorderCommands(e,t,"top",s),void this.aggregateBorderCommands(e,t,"bottom",s);if("hv"===o)return this.aggregateBorderCommands(e,t,"h",s),void this.aggregateBorderCommands(e,t,"v",s);const{left:n,top:i,right:r,bottom:a}=t;if("h"===o){for(let t=i+1;t<=a;t++)this.aggregateBorderCommands(e,{left:n,top:t,right:r,bottom:t},"top",s);return}if("v"===o){for(let t=n+1;t<=r;t++)this.aggregateBorderCommands(e,{left:t,top:i,right:t,bottom:a},"left",s);return}const l={};for(let e of Ra[o])l[e]=["thin","#000"];const c=function(e,t){const{left:o,right:s,top:n,bottom:i}=e;switch(t){case"left":return{left:o,top:n,right:o,bottom:i};case"top":return{left:o,top:n,right:s,bottom:n};case"right":return{left:s,top:n,right:s,bottom:i};case"bottom":return{left:o,top:i,right:s,bottom:i}}return e}(t,o);for(let t=c.top;t<=c.bottom;t++)for(let o=c.left;o<=c.right;o++)this.setBorderToMap(e,o,t,l,s)}clearBorder(e,t,o,s){const n=this.getters.getCell(t,o);s[n?n.xc:w(t,o)]=0,t>0&&this.clearSide(e,t-1,o,"right",s),o>0&&this.clearSide(e,t,o-1,"bottom",s),t<this.workbook.activeSheet.cols.length-1&&this.clearSide(e,t+1,o,"left",s),o<this.workbook.activeSheet.rows.length-1&&this.clearSide(e,t,o+1,"top",s)}clearSide(e,t,o,s,n){const i=this.getters.getCell(t,o),r=i?i.xc:w(t,o),a=r in n?n[r]:i&&i.border?i.border:0,l=this.borders[a]||{};if(s in l){const e=Object.assign({},l);delete e[s],n[r]=this.registerBorder(e)}}setBorderToMap(e,t,o,s,n){const i=this.getters.getCell(t,o),r=i?i.xc:w(t,o),a=r in n?n[r]:i&&i.border?i.border:0,l=this.borders[a]||{},c=Object.assign({},l,s),h=this.registerBorder(c);n[r]=h}registerBorder(e){if(!Object.keys(e).length)return 0;const t=O(e);for(let e in this.borders)if(O(this.borders[e])===t)return parseInt(e,10);const o=this.nextId++;return this.borders[o]=e,o}clearFormatting(e){for(let t of e)for(let e=t.left;e<=t.right;e++)for(let o=t.top;o<=t.bottom;o++)this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:e,row:o,style:0,border:0})}setFormatter(e,t,o){for(let s of t)for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++)this.dispatch("UPDATE_CELL",{sheet:e,col:n,row:t,format:o})}setDecimal(e,t,o){const s=this.searchNumberFormat(t);if(void 0!==s){const n=this.changeDecimalFormat(s,o);this.setFormatter(e,t,n)}}searchNumberFormat(e){for(let t of e)for(let e=t.top;e<=t.bottom;e++)for(let o=t.left;o<=t.right;o++){const t=this.getters.getCell(o,e);if(t&&("number"===t.type||"formula"===t.type&&"number"==typeof t.value))return t.format||this.setDefaultNumberFormat(t.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 o=Math.sign(t),s=e.split(";");let n=[];for(let e of s){const t=e.indexOf("."),s=e.toUpperCase().indexOf("E");let i;const r=s>-1?e.slice(0,s):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?o>0?i=a<20?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(i=e.slice(0,l)+e.slice(l+1),1===a&&(i=i.slice(0,t)+i.slice(t+1))):i=e:i=e,n.push(i)}return n.join(";")}onAddElements(e,t,o,s){const n=o?this.workbook.activeSheet.rows.length:this.workbook.activeSheet.cols.length,i=e+1;for(let r=0;r<n;r++){const n=o?w(i,r):w(r,i);if(this.getters.isInMerge(n))continue;const a={};let l=o?this.getFormat(w(e,r)):this.getFormat(w(r,e)),c=o?this.getFormat(w(t,r)):this.getFormat(w(r,t));if(s?(c.style&&(a.style=c.style),c.format&&(a.format=c.format)):(l.style&&(a.style=l.style),l.format&&(a.format=l.format)),c.border&&c.border===l.border&&(a.border=c.border),0!==Object.keys(a).length)for(let e=i;e<t;e++)this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:o?e:r,row:o?r:e,style:a.style,border:a.border,format:a.format})}}getFormat(e){const t={};return(e=this.getters.getMainCell(e))in this.workbook.activeSheet.cells&&(this.workbook.activeSheet.cells[e].border&&(t.border=this.workbook.activeSheet.cells[e].border),this.workbook.activeSheet.cells[e].style&&(t.style=this.workbook.activeSheet.cells[e].style),this.workbook.activeSheet.cells[e].format&&(t.format=this.workbook.activeSheet.cells[e].format)),t}import(e){e.styles&&(this.styles=e.styles),this.styles[0]=Object.assign({},Ma,this.styles[0]),e.borders&&(this.borders=e.borders);let t=1;for(let e in this.styles)t=Math.max(e,t);for(let e in this.borders)t=Math.max(e,t);this.nextId=t+1}export(e){e.styles=this.styles,e.borders=this.borders}}Aa.getters=["getCurrentStyle","getCellWidth","getTextWidth","getCellHeight","getCellStyle","getCellBorder"];class Na extends dn{constructor(){super(...arguments),this.highlights=[],this.color="#000",this.highlightSelectionEnabled=!1,this.pendingHighlights=[]}handle(e){switch(e.type){case"ADD_HIGHLIGHTS":this.addHighlights(e.ranges);break;case"REMOVE_ALL_HIGHLIGHTS":this.highlights=[];break;case"REMOVE_HIGHLIGHTS":this.removeHighlights(e.ranges);break;case"SELECT_CELL":case"SET_SELECTION":this.highlightSelectionEnabled&&this.highlightSelection();break;case"START_SELECTION_EXPANSION":this.color=v();break;case"HIGHLIGHT_SELECTION":this.highlightSelectionEnabled=e.enabled,e.enabled||this.dispatch("RESET_PENDING_HIGHLIGHT");break;case"RESET_PENDING_HIGHLIGHT":this.pendingHighlights=[];break;case"ADD_PENDING_HIGHLIGHTS":this.addPendingHighlight(e.ranges);break;case"SET_HIGHLIGHT_COLOR":this.color=e.color}}getHighlights(){return this.highlights}addHighlights(e){let t=this.prepareHighlights(e);this.highlights=this.highlights.concat(t)}addPendingHighlight(e){let t=this.prepareHighlights(e);this.pendingHighlights=this.pendingHighlights.concat(t)}prepareHighlights(e){return 0===Object.keys(e).length?[]:Object.keys(e).map((t=>{const[o,s]=t.split("!").reverse(),n=s?this.getters.getSheetIdByName(s):this.getters.getActiveSheet();return{zone:this.getters.expandZone(L(o)),color:e[t],sheet:n}})).filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.workbook.activeSheet.rows.length&&e.zone.right<this.workbook.activeSheet.cols.length))}removeHighlights(e){const t=this.getters.getActiveSheet(),o={};for(let[s,n]of Object.entries(e)){const[e,i]=s.split("!").reverse(),r=this.getters.getSheetIdByName(i);o[r||t]=Object.assign({[e]:n},o[r||t]||{})}this.highlights=this.highlights.filter((e=>!(o[e.sheet]&&o[e.sheet][this.getters.zoneToXC(e.zone)]===e.color)))}highlightSelection(){this.removePendingHighlights();const e=this.getters.getSelectedZones().filter((e=>!this.isHighlighted(e))),t={};let o=this.color;for(const s of e)t[this.getters.zoneToXC(s)]=o,o=v();this.dispatch("ADD_HIGHLIGHTS",{ranges:t}),this.dispatch("ADD_PENDING_HIGHLIGHTS",{ranges:t})}isHighlighted(e){return!!this.highlights.find((t=>y(t.zone,e)))}removePendingHighlights(){const e={},[t,o]=this.pendingHighlights.reduce((([e,t],o)=>this.getters.isSelected(o.zone)?[[...e,o],t]:[e,[...t,o]]),[[],[]]);for(const{zone:t,color:s}of o)e[this.getters.zoneToXC(t)]=s;this.dispatch("REMOVE_HIGHLIGHTS",{ranges:e}),this.pendingHighlights=t}drawGrid(e){const{ctx:t,viewport:o,thinLineWidth:s}=e,n=this.getters.getActiveSheet(),i=3*s;t.lineWidth=i;for(let e of this.highlights.filter((e=>e.sheet===n))){const[s,n,r,a]=this.getters.getRect(e.zone,o);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(s+i/2,n+i/2,r-i,a-i),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(s+i,n+i,r-2*i,a-2*i))}}}Na.modes=["normal","readonly"],Na.layers=[1],Na.getters=["getHighlights"];class ka extends dn{constructor(){super(...arguments),this.nextId=1,this.pending=null}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"PASTE":return this.isPasteAllowed(e.target,t);case"ADD_MERGE":return this.isMergeAllowed(e.zone,t);default:return{status:"SUCCESS"}}}beforeHandle(e){switch(e.type){case"REMOVE_COLUMNS":this.exportAndRemoveMerges(e.sheet,(t=>N(t,e.columns)),!0);break;case"REMOVE_ROWS":this.exportAndRemoveMerges(e.sheet,(t=>k(t,e.rows)),!1);break;case"ADD_COLUMNS":const t="before"===e.position?e.column:e.column+1;this.exportAndRemoveMerges(e.sheet,(o=>_(o,t,e.quantity)),!0);break;case"ADD_ROWS":const o="before"===e.position?e.row:e.row+1;this.exportAndRemoveMerges(e.sheet,(t=>I(t,o,e.quantity)),!1)}}handle(e){switch(e.type){case"ADD_MERGE":e.interactive?this.interactiveMerge(e.sheet,e.zone):this.addMerge(e.sheet,e.zone);break;case"REMOVE_MERGE":this.removeMerge(e.sheet,e.zone);break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);break;case"PASTE_CELL":const t=w(e.originCol,e.originRow);this.isMainCell(t,e.sheet)&&this.duplicateMerge(t,e.col,e.row,e.sheet,e.cut)}this.pending&&(this.importMerges(this.pending.sheet,this.pending.merges),this.history.updateLocalState(["pending"],null))}isMergeDestructive(e){const{left:t,right:o,top:s,bottom:n}=e;for(let e=s;e<=n;e++){const n=this.workbook.activeSheet.rows[e];for(let i=t;i<=o;i++)if(i!==t||e!==s){const e=n.cells[i];if(e&&e.content)return!0}}return!1}doesIntersectMerge(e){const{left:t,right:o,top:s,bottom:n}=e;for(let e=s;e<=n;e++)for(let s=t;s<=o;s++){const t=w(s,e);if(this.workbook.activeSheet.mergeCellMap[t])return!0}return!1}expandZone(e){let{left:t,right:o,top:s,bottom:n}=e;const i=this.workbook.activeSheet;let r={left:t,right:o,top:s,bottom:n};for(let e in i.merges){const t=i.merges[e];T(t,r)&&(r=C(t,r))}return y(r,e)?r:this.expandZone(r)}isInMerge(e){return e in this.workbook.activeSheet.mergeCellMap}isMainCell(e,t){const o=this.workbook.sheets[t].merges;for(let t in o)if(o[t].topLeft===e)return!0;return!1}getMainCell(e){if(!this.isInMerge(e))return e;const t=this.workbook.activeSheet,o=t.mergeCellMap[e];return t.merges[o].topLeft}isMergeAllowed(e,t){return!t&&this.isMergeDestructive(e)?{status:"CANCELLED",reason:2}:{status:"SUCCESS"}}addMerge(e,t){const o=this.workbook.sheets[e],{left:s,right:n,top:i,bottom:r}=t,a=w(s,i);if(a===w(n,r))return;const l=this.getters.getCell(s,i);let c=this.nextId++;this.history.updateState(["sheets",e,"merges",c],{id:c,left:s,top:i,right:n,bottom:r,topLeft:a});let h=new Set;for(let t=i;t<=r;t++)for(let r=s;r<=n;r++){const n=w(r,t);r===s&&t===i||this.dispatch("UPDATE_CELL",{sheet:e,col:r,row:t,style:l?l.style:void 0,content:void 0}),o.mergeCellMap[n]&&h.add(o.mergeCellMap[n]),this.history.updateState(["sheets",e,"mergeCellMap",n],c)}this.applyBorderMerge(t,e);for(let t of h){const{top:s,bottom:n,left:i,right:r}=o.merges[t];for(let t=s;t<=n;t++)for(let s=i;s<=r;s++){const n=w(s,t);o.mergeCellMap[n]!==c&&(this.history.updateState(["sheets",e,"mergeCellMap",n],void 0),this.dispatch("CLEAR_CELL",{sheet:e,col:s,row:t}))}this.history.updateState(["sheets",e,"merges",t],void 0)}}applyBorderMerge(e,t){const{left:o,right:s,top:n,bottom:i}=e,r=this.getters.getCell(o,n),a=this.getters.getCell(s,i)||r,l=r?this.getters.getCellBorder(r):null,c=(a?this.getters.getCellBorder(a):null)||l;if(this.dispatch("SET_FORMATTING",{sheet:t,target:[{left:o,right:s,top:n,bottom:i}],border:"clear"}),c&&c.right){const e=[{left:s,right:s,top:n,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"right"})}if(l&&l.left){const e=[{left:o,right:o,top:n,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"left"})}if(l&&l.top){const e=[{left:o,right:s,top:n,bottom:n}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"top"})}if(c&&c.bottom){const e=[{left:o,right:s,top:i,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"bottom"})}}removeMerge(e,t){const{left:o,top:s,bottom:n,right:i}=t;let r=w(o,s);const a=this.workbook.sheets[e].mergeCellMap[r];if(!y(t,this.workbook.sheets[e].merges[a]))throw new Error(Q("Invalid merge zone"));this.history.updateState(["sheets",e,"merges",a],void 0);for(let t=s;t<=n;t++)for(let s=o;s<=i;s++){const o=w(s,t);this.history.updateState(["sheets",e,"mergeCellMap",o],void 0)}}interactiveMerge(e,t){const o=this.dispatch("ADD_MERGE",{sheet:e,zone:t});"CANCELLED"===o.status&&2===o.reason&&this.ui.askConfirmation(Q("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheet:e,zone:t,force:!0})}))}duplicateMerge(e,t,o,s,n){const i=this.workbook.sheets[s].mergeCellMap[e],r=this.workbook.sheets[s].merges[i],a=this.getters.getNumberCols(s)-1,l=this.getters.getNumberRows(s)-1,c={left:t,top:o,right:F(t+r.right-r.left,0,a),bottom:F(o+r.bottom-r.top,0,l)};n&&this.dispatch("REMOVE_MERGE",{sheet:s,zone:r}),this.dispatch("ADD_MERGE",{sheet:this.workbook.activeSheet.id,zone:c})}removeAllMerges(e){const t=this.workbook.sheets[e];for(let o in t.merges)this.history.updateState(["sheets",e,"merges",o],void 0);for(let o in t.mergeCellMap)this.history.updateState(["sheets",e,"mergeCellMap",o],void 0)}exportAndRemoveMerges(e,t,o){const s=_a(this.workbook.sheets[e].merges),n=[];for(let e of s){const o=t(e);if(o){const[e,t]=o.split(":");e!==t&&n.push(o)}}this.updateMergesStyles(e,o),this.removeAllMerges(e),this.history.updateLocalState(["pending"],{sheet:e,merges:n})}updateMergesStyles(e,t){const o=this.workbook.sheets[e];for(let e of Object.values(o.merges)){const s=e.topLeft,n=o.cells[s];if(!n)continue;let[i,r]=E(s);t&&e.left!==e.right&&(i+=1),t||e.top===e.bottom||(r+=1),this.dispatch("UPDATE_CELL",{sheet:o.id,col:i,row:r,style:n.style,border:n.border,format:n.format})}}isPasteAllowed(e,t){if(!t){const t=this.getters.getPasteZones(e);for(let e of t)if(this.doesIntersectMerge(e))return{status:"CANCELLED",reason:1}}return{status:"SUCCESS"}}autoFillMerge(e,t,o,s){const n=w(e,t),i=w(o,s),r=this.getters.getActiveSheet();if(this.isInMerge(i)&&!this.isInMerge(n)){const e=this.workbook.sheets[r].mergeCellMap[i],t=this.workbook.sheets[r].merges[e];this.dispatch("REMOVE_MERGE",{sheet:r,zone:t})}this.isMainCell(n,r)&&this.duplicateMerge(n,o,s,r)}import(e){const t=e.sheets||[];for(let e of t){const t=this.workbook.sheets[e.id];t&&e.merges&&this.importMerges(t.id,e.merges)}}importMerges(e,t){for(let o of t){let t=this.nextId++;const[s,n]=o.split(":"),[i,r]=E(s),[a,l]=E(n);this.history.updateState(["sheets",e,"merges",t],{id:t,left:i,top:r,right:a,bottom:l,topLeft:s});for(let o=r;o<=l;o++)for(let s=i;s<=a;s++){const n=w(s,o);this.history.updateState(["sheets",e,"mergeCellMap",n],t)}}}export(e){for(let t of e.sheets){const e=this.workbook.sheets[t.id];t.merges.push(..._a(e.merges))}}}function _a(e){return Object.values(e).map((e=>w(e.left,e.top)+":"+w(e.right,e.bottom)))}function Ia(e,t){if("formula"===e.type&&t)return"left";if(e.error||e.pending)return"center";switch(typeof e.value){case"object":case"number":return"right";case"boolean":return"center";default:return"left"}}function Oa(e,t){let o=0,s=e.length-1;for(;o<=s;){const n=Math.floor((o+s)/2),i=e[n];if(t<i.start)s=n-1;else{if(!(t>i.end))return n;o=n+1}}return-1}ka.getters=["isMergeDestructive","isInMerge","getMainCell","expandZone","doesIntersectMerge"];class Da extends dn{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t){if(e<h)return-1;const o=this.workbook.activeSheet.cols;return Oa(o,e-h+o[t].start+1)}getRowIndex(e,t){if(e<c)return-1;const o=this.workbook.activeSheet.rows;return Oa(o,e-c+o[t].start+1)}getRect(e,t){const{left:o,top:s,right:n,bottom:i}=e;let{offsetY:r,offsetX:a}=t;a-=h,r-=c;const{cols:l,rows:u}=this.workbook.activeSheet,d=Math.max(l[o].start-a,h),p=l[n].end-a-d,g=Math.max(u[s].start-r,c);return[d,g,p,u[i].end-r-g]}snapViewportToCell(e){const{cols:t,rows:o}=this.workbook.activeSheet,s=Object.assign({},e);return s.offsetX=t[e.left].start,s.offsetY=o[e.top].start,s}adjustViewportPosition(e){const t=Object.assign({},e),{cols:o,rows:s}=this.workbook.activeSheet,[n,i]=this.getters.getPosition();for(;n>=t.right&&n!==o.length-1;)t.offsetX=o[t.left].end,this.adjustViewportZoneX(t);for(;n<t.left;)t.offsetX=o[t.left-1].start,this.adjustViewportZoneX(t);for(;i>=t.bottom&&i!==s.length-1;)t.offsetY=s[t.top].end,this.adjustViewportZoneY(t);for(;i<t.top;)t.offsetY=s[t.top-1].start,this.adjustViewportZoneY(t);return t}adjustViewportZone(e){const t=Object.assign({},e);return this.adjustViewportZoneX(t),this.adjustViewportZoneY(t),t}adjustViewportZoneX(e){const{cols:t}=this.workbook.activeSheet,{width:o,offsetX:s}=e;e.left=this.getColIndex(s+h,0);const n=o+s-h;e.right=t.length-1;for(let o=e.left;o<t.length;o++)if(n<t[o].end){e.right=o;break}}adjustViewportZoneY(e){const{rows:t}=this.workbook.activeSheet,{height:o,offsetY:s}=e;e.top=this.getRowIndex(s+c,0);let n=o+s-c;e.bottom=t.length-1;for(let o=e.top;o<t.length;o++)if(n<t[o].end){e.bottom=o;break}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e);break;case 6:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:o,thinLineWidth:s}=e;let{width:n,height:i,offsetX:r,offsetY:a,top:l,left:u,bottom:d,right:p}=o;const{rows:g,cols:f}=this.workbook.activeSheet;t.fillStyle="white",t.fillRect(0,0,o.width,o.height),r-=h,a-=c,t.lineWidth=2*s,t.strokeStyle="#E2E3E3",t.beginPath();const m=Math.min(i,g[d].end-a);for(let e=u;e<=p;e++){const o=f[e].end-r;t.moveTo(o,0),t.lineTo(o,m)}const v=Math.min(n,f[p].end-r);for(let e=l;e<=d;e++){const o=g[e].end-a;t.moveTo(0,o),t.lineTo(v,o)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:o}=e;t.lineWidth=.3*o;const s=.1*o;t.strokeStyle="#111";for(let e of this.boxes){let o=e.style;o&&o.fillColor&&"#ffffff"!==o.fillColor&&(t.fillStyle=o.fillColor,t.fillRect(e.x,e.y,e.width,e.height),t.strokeRect(e.x+s,e.y+s,e.width-2*s,e.height-2*s)),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:o}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:o,y:n,width:i,height:r}=e;t.left&&s(t.left,o,n,o,n+r),t.top&&s(t.top,o,n,o+i,n),t.right&&s(t.right,o+i,n,o+i,n+r),t.bottom&&s(t.bottom,o,n+r,o+i,n+r)}}function s([e,s],n,i,r,a){t.strokeStyle=s,t.lineWidth=("thin"===e?2:3)*o,t.beginPath(),t.moveTo(n,i),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:o}=e;let s;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const n=e.style||{},i=e.align,r=n.italic?"italic ":"",a=n.bold?"bold":"400",l=n.fontSize||10,c=`${r}${a} ${Qn[l]}px 'Roboto', arial`;let h;c!==s&&(s=c,t.font=c),t.fillStyle=n.textColor||"#000";let u=e.y+e.height/2+1;h="left"===i?e.x+3:"right"===i?e.x+e.width-3:e.x+e.width/2,t.textAlign=i,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(h),Math.round(u)),n.strikethrough&&("right"===i?h-=e.textWidth:"center"===i&&(h-=e.textWidth/2),t.fillRect(h,u,e.textWidth,2.6*o)),e.clipRect&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:o,thinLineWidth:s}=e;let{width:n,height:l,offsetX:u,offsetY:d,left:p,top:g,right:f,bottom:m}=o;u-=h,d-=c;const v=this.getters.getSelectedZones(),{cols:b,rows:E}=this.workbook.activeSheet,w=this.getters.getActiveCols(),L=this.getters.getActiveRows();t.fillStyle="#F8F9FA",t.font="400 11px 'Roboto', arial",t.textAlign="center",t.textBaseline="middle",t.lineWidth=s,t.strokeStyle="#333",t.fillRect(0,0,n,c),t.fillRect(0,0,h,l),t.fillStyle=i;for(let e of v){const o=Math.max(h,b[e.left].start-u),s=Math.max(h,b[e.right].end-u),n=Math.max(c,E[e.top].start-d),a=Math.max(c,E[e.bottom].end-d);t.fillStyle=w.has(e.left)?r:i,t.fillRect(o,0,s-o,c),t.fillStyle=L.has(e.top)?r:i,t.fillRect(0,n,h,a-n)}t.beginPath(),t.moveTo(h,0),t.lineTo(h,l),t.moveTo(0,c),t.lineTo(n,c),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=p;e<=f;e++){const o=b[e];t.fillStyle=w.has(e)?"#fff":a,t.fillText(o.name,(o.start+o.end)/2-u,13),t.moveTo(o.end-u,0),t.lineTo(o.end-u,c)}for(let e=g;e<=m;e++){const o=E[e];t.fillStyle=L.has(e)?"#fff":a,t.fillText(o.name,24,(o.start+o.end)/2-d),t.moveTo(0,o.end-d),t.lineTo(h,o.end-d)}t.stroke()}hasContent(e,t){const{cells:o,mergeCellMap:s}=this.workbook.activeSheet,n=w(e,t),i=o[n];return i&&i.content||n in s}getGridBoxes(e){const{viewport:t}=e;let{right:o,left:s,top:n,bottom:i,offsetX:r,offsetY:a}=t;r-=h,a-=c;const l=[],{cols:u,rows:d,mergeCellMap:p,cells:g,merges:f}=this.workbook.activeSheet;for(let e=n;e<=i;e++){let t=d[e];for(let n=s;n<=o;n++){let i=t.cells[n];if(i&&!(i.xc in p)){let c=u[n];const h=this.getters.getCellText(i),d=this.getters.getCellWidth(i);let p=this.getters.getCellStyle(i);const g=this.getters.getConditionalStyle(i.xc);g&&(p=Object.assign({},p,g));const f=h?p&&p.align||Ia(i,this.getters.shouldShowFormulas()):void 0;let m=null;if(h&&d>u[i.col].size){let l,h;switch(f){case"left":for(l=i.col;l<o&&!this.hasContent(l+1,i.row);)l++;h=u[l].end-c.start,h<d&&(m=[c.start-r,t.start-a,h,t.size]);break;case"right":for(l=i.col;l>s&&!this.hasContent(l-1,i.row);)l--;h=c.end-u[l].start,h<d&&(m=[u[l].start-r,t.start-a,h,t.size]);break;case"center":let p=n;for(;p>s&&!this.hasContent(p-1,e);)p--;let g=n;for(;g<o&&!this.hasContent(g+1,e);)g++;const f=Math.min(p,n),v=Math.max(g,n);h=u[v].end-u[f].start,(h<d||f===n||v===n)&&(m=[u[f].start-r,t.start-a,h,t.size])}}l.push({x:c.start-r,y:t.start-a,width:c.size,height:t.size,text:h,textWidth:d,border:this.getters.getCellBorder(i),style:p,align:f,clipRect:m,error:i.error})}}}for(let e in f){let o=f[e];if(T(o,t)){const e=g[o.topLeft],t=g[w(o.right,o.bottom)],s=u[o.right].end-u[o.left].start;let n,i,c,h,p;if(e||t){n=e?this.getters.getCellText(e):"",i=e?this.getters.getCellWidth(e):null;const s=this.getters.getConditionalStyle(o.topLeft);c=s||(e?this.getters.getCellStyle(e):null),h=n?c&&c.align||Ia(e,this.getters.shouldShowFormulas()):null;const r=e?this.getters.getCellBorder(e):null,a=t?this.getters.getCellBorder(t):null;p={bottom:a?a.bottom:null,left:r?r.left:null,right:a?a.right:null,top:r?r.top:null}}c=c||{},c.fillColor&&"#ffffff"!==c.fillColor||(c=Object.create(c),c.fillColor="#fff");const f=u[o.left].start-r,m=d[o.top].start-a,v=d[o.bottom].end-d[o.top].start;l.push({x:f,y:m,width:s,height:v,text:n,textWidth:i,border:p,style:c,align:h,clipRect:[f,m,s,v],error:e?e.error:void 0})}}return l}}var $a;Da.layers=[0,6],Da.getters=["getColIndex","getRowIndex","getRect","snapViewportToCell","adjustViewportPosition","adjustViewportZone"],Da.modes=["normal","readonly"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}($a||($a={}));class Ua extends dn{constructor(){super(...arguments),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0]},this.activeCol=0,this.activeRow=0,this.activeXc="A1",this.mode=$a.idle,this.sheetsData={}}allowDispatch(e){switch(e.type){case"MOVE_POSITION":{const[t,o]=this.getReferenceCoords(),{cols:s,rows:n}=this.workbook.activeSheet;if(e.deltaY<0&&0===o||e.deltaY>0&&o===n.length-1||e.deltaX<0&&0===t||e.deltaX>0&&t===s.length-1)return{status:"CANCELLED",reason:10};break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.workbook.activeSheet.cols.length)return{status:"CANCELLED",reason:10};break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.workbook.activeSheet.rows.length)return{status:"CANCELLED",reason:10};break}}return{status:"SUCCESS"}}handle(e){switch(e.type){case"START":this.selectCell(0,0);break;case"ACTIVATE_SHEET":this.sheetsData[e.from]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow,activeXc:this.activeXc},e.to in this.sheetsData?Object.assign(this,this.sheetsData[e.to]):this.selectCell(0,0);break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.strict);break;case"START_SELECTION":this.mode=$a.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=$a.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=$a.expanding;break;case"STOP_SELECTION":this.mode=$a.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"REMOVE_COLUMNS":case"REMOVE_ROWS":this.ensureSelectionValidity();break;case"ADD_COLUMNS":"before"===e.position&&this.onAddColumns(e.quantity);break;case"ADD_ROWS":"before"===e.position&&this.onAddRows(e.quantity)}}getActiveCell(){const e=this.workbook.activeSheet;let t=e.mergeCellMap[this.activeXc];return t?e.cells[e.merges[t].topLeft]:this.getters.getCell(this.activeCol,this.activeRow)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.workbook.activeSheet.rows.length-1)for(let o=t.left;o<=t.right;o++)e.add(o);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.workbook.activeSheet.cols.length-1)for(let o=t.top;o<=t.bottom;o++)e.add(o);return e}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.zones[this.selection.zones.length-1]}getSelection(){return this.selection}getPosition(){return[this.activeCol,this.activeRow]}getAggregate(){let e=0,t=0;for(let o of this.selection.zones)for(let s=o.top;s<=o.bottom;s++){const n=this.workbook.activeSheet.rows[s];for(let s=o.left;s<=o.right;s++){const o=n.cells[s];o&&"text"!==o.type&&!o.error&&"number"==typeof o.value&&(t++,e+=o.value)}}return t<2?null:j(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>y(t,e)))}getReferenceCoords(){return"selecting"===this.getters.getEditionMode()?this.selection.anchor:[this.activeCol,this.activeRow]}selectColumn(e,t,o){const s=this.workbook.activeSheet.rows.length-1,n={left:e,right:e,top:0,bottom:s},i=this.selection.zones;let r,a;if(o){const[e,t]=this.selection.anchor,o=C(n,{left:e,right:e,top:0,bottom:s});r=i.slice(0,-1).concat(o),a=[e,t]}else r=t?i.concat(n):[n],a=[e,0];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0})}selectRow(e,t,o){const s=this.workbook.activeSheet.cols.length-1,n={top:e,bottom:e,left:0,right:s},i=this.selection.zones;let r,a;if(o){const[e,t]=this.selection.anchor,o=C(n,{left:0,right:s,top:t,bottom:t});r=i.slice(0,-1).concat(o),a=[e,t]}else r=t?i.concat(n):[n],a=[0,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0})}selectAll(){const e={left:0,top:0,bottom:this.workbook.activeSheet.rows.length-1,right:this.workbook.activeSheet.cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0]})}selectCell(e,t){const o=w(e,t);let s=this.getters.expandZone({left:e,right:e,top:t,bottom:t});this.mode===$a.expanding?this.selection.zones.push(s):this.selection.zones=[s],this.selection.anchor=[e,t],"selecting"!==this.getters.getEditionMode()&&(this.activeCol=e,this.activeRow=t,this.activeXc=o)}movePosition(e,t){const[o,s]=this.getReferenceCoords(),n=w(o,s),i=this.workbook.activeSheet;let r=i.mergeCellMap[n];if(r){let n=o,a=s;for(;i.mergeCellMap[w(n,a)]===r;)n+=e,a+=t;n>=0&&a>=0&&this.selectCell(n,a)}else this.selectCell(o+e,s+t)}setSelection(e,t,o=!1){this.selectCell(...e),this.selection.zones=o?t:t.map(this.getters.expandZone),this.selection.anchor=e}moveSelection(e,t){const o=this.selection,s=o.zones.slice(),n=s[o.zones.length-1],[i,r]=o.anchor,{left:a,right:l,top:c,bottom:h}=n;let u=n;const d=e=>{const{left:t,right:o,top:s,bottom:n}=this.getters.expandZone(e);return{left:Math.max(0,t),right:Math.min(this.workbook.activeSheet.cols.length-1,o),top:Math.max(0,s),bottom:Math.min(this.workbook.activeSheet.rows.length-1,n)}};let p=0;for(;null!==u;)if(p++,e<0&&(u=i<=l-p?d({top:c,left:a,bottom:h,right:l-p}):null),e>0&&(u=a+p<=i?d({top:c,left:a+p,bottom:h,right:l}):null),t<0&&(u=r<=h-p?d({top:c,left:a,bottom:h-p,right:l}):null),t>0&&(u=c+p<=r?d({top:c+p,left:a,bottom:h,right:l}):null),u&&!y(u,n))return s[s.length-1]=u,void this.dispatch("SET_SELECTION",{zones:s,anchor:[i,r]});u=d(C({top:r,bottom:r,left:i,right:i},{top:c+t,left:a+e,bottom:h+t,right:l+e})),y(u,n)||(s[s.length-1]=u,this.dispatch("SET_SELECTION",{zones:s,anchor:[i,r]}))}addCellToSelection(e,t){const o=this.selection,[s,n]=o.anchor,i={left:Math.min(s,e),top:Math.min(n,t),right:Math.max(s,e),bottom:Math.max(n,t)},r=o.zones.slice(0,-1).concat(i);this.dispatch("SET_SELECTION",{zones:r,anchor:[s,n]})}ensureSelectionValidity(){const e=this.getters.getSheets().map((e=>e.id));if(e.includes(this.getters.getActiveSheet())){const{anchor:e,zones:t}=this.clipSelection(this.getters.getActiveSheet(),this.selection);this.setSelection(e,t)}else this.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:e[0]});const t=Object.keys(this.sheetsData).filter((t=>!e.includes(t)));for(const e of t)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:o}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:o},activeCol:t[0],activeRow:t[1],activeXc:w(...t)}}}clipSelection(e,t){const o=this.getters.getNumberCols(e)-1,s=this.getters.getNumberRows(e)-1,n=t.zones.map((e=>({left:F(e.left,0,o),right:F(e.right,0,o),top:F(e.top,0,s),bottom:F(e.bottom,0,s)})));return{anchor:[n[n.length-1].left,n[n.length-1].top],zones:n}}onAddColumns(e){const t=this.getSelectedZone(),o={left:t.left+e,right:t.right+e,top:t.top,bottom:t.bottom};this.dispatch("SET_SELECTION",{zones:[o],anchor:[o.left,o.top],strict:!0})}onAddRows(e){const t=this.getSelectedZone(),o={left:t.left,right:t.right,top:t.top+e,bottom:t.bottom+e};this.dispatch("SET_SELECTION",{zones:[o],anchor:[o.left,o.top],strict:!0})}drawGrid(e){const{viewport:t,ctx:o,thinLineWidth:s}=e,n=this.getSelectedZones();o.fillStyle="#f3f7fe";const i=1===n.length&&n[0].left===n[0].right&&n[0].top===n[0].bottom;o.fillStyle=i?"#f3f7fe":"#e9f0ff",o.strokeStyle=l,o.lineWidth=1.5*s,o.globalCompositeOperation="multiply";for(const e of n){const[s,n,i,r]=this.getters.getRect(e,t);i>0&&r>0&&(o.fillRect(s,n,i,r),o.strokeRect(s,n,i,r))}o.globalCompositeOperation="source-over";const{mergeCellMap:r,merges:a}=this.workbook.activeSheet,[c,h]=this.getPosition(),u=w(c,h);let d;o.strokeStyle="#3266ca",o.lineWidth=3*s,d=u in r?a[r[u]]:{top:h,bottom:h,left:c,right:c};const[p,g,f,m]=this.getters.getRect(d,t);f>0&&m>0&&o.strokeRect(p,g,f,m)}}Ua.layers=[4],Ua.modes=["normal","readonly"],Ua.getters=["getActiveCell","getActiveCols","getActiveRows","getSelectedZones","getSelectedZone","getAggregate","getSelection","getPosition","getSelectionMode","isSelected"];class Fa extends dn{constructor(){super(...arguments),this.inputs={},this.inputMaximums={},this.focusedInput=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.focusedInput===e.id&&this.focusedRange===t)return{status:"CANCELLED",reason:14};break;case"ADD_EMPTY_RANGE":if(this.inputs[e.id].length===this.inputMaximums[e.id])return{status:"CANCELLED",reason:15}}return{status:"SUCCESS"}}handle(e){switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.maximumRanges);break;case"DISABLE_SELECTION_INPUT":this.focusedInput===e.id&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!1}),this.dispatch("REMOVE_ALL_HIGHLIGHTS"),this.focusedRange=null,this.focusedInput=null),delete this.inputs[e.id],delete this.inputMaximums[e.id];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);null!==t&&this.changeRange(e.id,t,e.value);break}case"ADD_EMPTY_RANGE":this.inputs[e.id]=[...this.inputs[e.id],Object.freeze({xc:"",id:K()})],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"ADD_HIGHLIGHTS":const o=this.getters.getHighlights();this.add(o.slice(o.length-Object.keys(e.ranges).length));break;case"START_SELECTION_EXPANSION":this.willAddNewRange&&this.dispatch("RESET_PENDING_HIGHLIGHT");break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInput,this.focusedRange];null!==e&&null!==t&&(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,o)=>Object.assign({},t,{color:this.focusedInput===e&&null!==this.focusedRange?t.color:null,isFocused:this.focusedInput===e&&this.focusedRange===o}))):[]}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc)))}initInput(e,t,o){this.inputs[e]=t.map((e=>Object.freeze({xc:e,id:K()}))),void 0!==o&&(this.inputMaximums[e]=o),0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){const o=this.focusedInput,s=this.focusedInput&&this.focusedRange;if(this.focusedInput=e,null!==s&&null==t&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!1}),this.removeAllHighlights()),null!==o&&null!==e&&o!==e&&this.removeAllHighlights(),(null===s&&null!==t||o!==e)&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!0}),this.highlightAllRanges(e)),this.setPendingRange(e,t),null!==t){const o=this.inputs[e][t].color||v();this.dispatch("SET_HIGHLIGHT_COLOR",{color:o})}this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}removeAllHighlights(){this.dispatch("REMOVE_ALL_HIGHLIGHTS")}highlightAllRanges(e){const t=this.inputs[e];for(const[e,o]of t.entries()){this.focusedRange=e;const t=this.inputToHighlights(o);Object.keys(t).length>0&&this.dispatch("ADD_HIGHLIGHTS",{ranges:t})}}add(e){if(null===this.focusedInput||null===this.focusedRange||"selecting"===this.getters.getEditionMode()||0===e.length)return;this.getters.getSelectionMode()===$a.expanding&&this.willAddNewRange?(this.addNewRange(this.focusedInput,e),this.willAddNewRange=!1):this.setRange(this.focusedInput,this.focusedRange,e)}addNewRange(e,t){this.inputMaximums[e]<this.inputs[e].length+t.length||(this.inputs[e]=this.inputs[e].concat(this.highlightsToInput(t)),this.focusLast(e))}setRange(e,t,o){let[s,...n]=this.highlightsToInput(o);const i=this.inputs[e].length+n.length-this.inputMaximums[e];i&&(n=n.slice(0,n.length-i)),this.inputs[e].splice(t,1,s,...n),n.length&&this.focus(e,t+n.length)}changeRange(e,t,o){this.focusedInput===e&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:e,rangeId:this.inputs[e][t].id});const s=this.inputs[e][t];this.dispatch("REMOVE_HIGHLIGHTS",{ranges:this.inputToHighlights(s)}),this.dispatch("ADD_HIGHLIGHTS",{ranges:this.inputToHighlights({color:s.color,xc:o})})}removeRange(e,t){const[o]=this.inputs[e].splice(t,1);this.focusedInput===e&&null!==this.focusedRange&&(this.dispatch("REMOVE_HIGHLIGHTS",{ranges:this.inputToHighlights(o)}),this.focusLast(e))}setPendingRange(e,t){this.dispatch("RESET_PENDING_HIGHLIGHT"),null!==t&&this.inputs[e][t].xc&&this.dispatch("ADD_PENDING_HIGHLIGHTS",{ranges:this.inputToHighlights(this.inputs[e][t])})}highlightsToInput(e){return e.map((e=>Object.freeze({xc:this.getters.zoneToXC(e.zone),id:K(),color:e.color})))}inputToHighlights({xc:e,color:t}){const o=this.cleanInputs([e]);if(0===o.length)return{};const[s,...n]=o,i={[s]:t||v()};for(const e of n)i[e]=v();return i}isRangeValid(e){return null!==e.match(Yr)}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e)).filter(this.isRangeValid)}getIndex(e,t){const o=this.inputs[e].findIndex((e=>e.id===t));return o>=0?o:null}}Fa.modes=["normal","readonly"],Fa.layers=[1],Fa.getters=["getSelectionInput","getSelectionInputValue"];const Pa=(new _e).add("core",ga).add("evaluation",Ta).add("clipboard",ta).add("merge",ka).add("formatting",Aa).add("edition",La).add("selection",Ua).add("highlight",Na).add("selectionInput",Fa).add("conditional formatting",oa).add("figures",xa).add("chart",ea).add("grid renderer",Da).add("autofill",xr);function Ba(e){return e?("version"in(e=Object.assign({},e))&&e.version<5&&(e=function(e){for(let t=za.findIndex((t=>t.from===e.version));t<za.length;t++)e=za[t].applyMigration(e);return e}(e)),(e=Object.assign(Ha(),e,{version:5})).sheets=e.sheets.map(((e,t)=>Object.assign(Za(`Sheet${t+1}`),e))),e.sheets.map((e=>e.id)).includes(e.activeSheet)||(e.activeSheet=e.sheets[0].id),0===e.sheets.length&&e.sheets.push(Za()),e):Ha()}const za=[{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){const t=e.sheets.find((t=>t.name===e.activeSheet));return e.activeSheet=t.id,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}}];function Za(e="Sheet1"){return{id:K(),name:e,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[]}}function Ha(){const e={version:5,sheets:[Za("Sheet1")],activeSheet:"",entities:{},styles:{},borders:{}};return e.activeSheet=e.sheets[0].id,e}class Ga{constructor(e){this.current=null,this.undoStack=[],this.redoStack=[],this.workbook=e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}allowDispatch(e){switch(e.type){case"UNDO":return this.canUndo()?{status:"SUCCESS"}:{status:"CANCELLED",reason:3};case"REDO":return this.canRedo()?{status:"SUCCESS"}:{status:"CANCELLED",reason:4}}return{status:"SUCCESS"}}beforeHandle(e){this.current||"REDO"===e.type||"UNDO"===e.type||(this.current=[])}handle(e){switch(e.type){case"UNDO":this.undo();break;case"REDO":this.redo()}}finalize(){this.current&&this.current.length&&(this.isActiveSheet()||this.undoStack.push(this.current),this.redoStack=[],this.current=null,this.undoStack.length>99&&this.undoStack.shift())}isActiveSheet(){return this.current&&1===this.current.length&&1===this.current[0].path.length&&"activeSheet"===this.current[0].path[0]}undo(){const e=this.undoStack.pop();if(e){this.redoStack.push(e);for(let t=e.length-1;t>=0;t--){let o=e[t];this.applyChange(o,"before")}}}redo(){const e=this.redoStack.pop();if(e){this.undoStack.push(e);for(let t of e)this.applyChange(t,"after")}}applyChange(e,t){let o=e.root,s=e.path[e.path.length-1];for(let t of e.path.slice(0,-1))o=o[t];void 0===e[t]?delete o[s]:o[s]=e[t]}updateStateFromRoot(e,t,o){let s=e,n=t[t.length-1];for(let e of t.slice(0,-1))s=s[e];s[n]!==o&&(this.current&&this.current.push({root:e,path:t,before:s[n],after:o}),void 0===o?delete s[n]:s[n]=o)}updateState(e,t){this.updateStateFromRoot(this.workbook,e,t)}updateCell(e,t,o){this.updateStateFromRoot(e,[t],o)}updateSheet(e,t,o){this.updateStateFromRoot(e,t,o)}}var Va;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.Finalizing=2]="Finalizing",e[e.Interactive=3]="Interactive"}(Va||(Va={}));class ja extends s.core.EventBus{constructor(e={},t={}){super(),this.renderers=[],this.status=0,this.dispatch=(e,t)=>{const o=Object.assign({type:e},t);switch(o.interactive?3:this.status){case 0:for(let e of this.handlers){const t=e.allowDispatch(o);if("CANCELLED"===t.status)return t}this.status=1;for(const e of this.handlers)e.beforeHandle(o);for(const e of this.handlers)e.handle(o);this.status=2;for(const e of this.handlers)e.finalize(o);this.status=0,"headless"!==this.config.mode&&this.trigger("update");break;case 1:case 3:for(const e of this.handlers)e.beforeHandle(o);for(const e of this.handlers)e.handle(o);break;case 2:throw new Error(Q("Nope. Don't do that"))}return{status:"SUCCESS"}},P.model=this;const o=Ba(e);this.workbook={visibleSheets:[],sheets:{},activeSheet:null};const s=new Ga(this.workbook);this.getters={canUndo:s.canUndo.bind(s),canRedo:s.canRedo.bind(s)},this.handlers=[s],this.config={mode:t.mode||"normal",openSidePanel:t.openSidePanel||(()=>{}),notifyUser:t.notifyUser||(()=>{}),askConfirmation:t.askConfirmation||(()=>{}),editText:t.editText||(()=>{}),evalContext:t.evalContext||{}};for(let e of Pa.getAll())this.setupPlugin(e,o);this.dispatch("START")}destroy(){delete P.model}setupPlugin(e,t){const o=this.dispatch.bind(this),s=this.handlers.find((e=>e instanceof Ga));if(e.modes.includes(this.config.mode)){const n=new e(this.workbook,this.getters,s,o,this.config);n.import(t);for(let t of e.getters){if(!(t in n))throw new Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);this.getters[t]=n[t].bind(n)}this.handlers.push(n);const i=e.layers.map((e=>[n,e]));this.renderers.push(...i),this.renderers.sort(((e,t)=>e[1]-t[1]))}}drawGrid(e){e.viewport=this.getters.snapViewportToCell(e.viewport);for(let[t,o]of this.renderers)t.drawGrid(e,o)}exportData(){const e=Ha();for(let t of this.handlers)t instanceof dn&&t.export(e);return e}}function qa(e,t){return!!t.target&&e.contains(t.target)}const{xml:Wa,css:Ya}=t.tags,{useExternalListener:Xa,useRef:Ka}=t.hooks,Ja=200,Qa=32,el=Wa`
494
+ `;class yr extends br{constructor(e,t){super(e,t),this.colorNumberString=f,this.getters=this.env.getters,this.cellIsOperators=bi,this.state=Er({currentCF:void 0,currentRanges:[],mode:"list",toRuleType:"CellIsRule"}),this.editors={CellIsRule:ar,ColorScaleRule:vr},this.activeSheetId=this.getters.getActiveSheet(),t.selection&&1===this.getters.getRulesSelection(t.selection).length&&this.openCf(this.getters.getRulesSelection(t.selection)[0])}async willUpdateProps(e){const t=this.getters.getActiveSheet();t!==this.activeSheetId?(this.activeSheetId=t,this.resetState()):e.selection&&e.selection!==this.props.selection&&(e.selection&&1===this.getters.getRulesSelection(e.selection).length?this.openCf(this.getters.getRulesSelection(e.selection)[0]):this.resetState())}resetState(){this.state.currentCF=void 0,this.state.currentRanges=[],this.state.mode="list",this.state.toRuleType="CellIsRule"}getStyle(e){if("CellIsRule"===e.type){const t=e;return`font-weight:${t.style.bold?"bold":"normal"};\n text-decoration:${t.style.strikethrough?"line-through":"none"};\n font-style:${t.style.italic?"italic":"normal"};\n color:${t.style.textColor||"none"};\n background-color:${t.style.fillColor||"none"};`}{const t=e;return`background-image: linear-gradient(to right, #${f(t.minimum.color)}, #${f(t.maximum.color)})`}}getDescription(e){return"CellIsRule"===e.rule.type?bi[e.rule.operator]:"Color scale"}onSave(e){this.state.currentCF&&this.env.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{rule:e.detail.rule,ranges:this.state.currentRanges,id:"edit"===this.state.mode?this.state.currentCF.id:K()},sheet:this.getters.getActiveSheet()}),this.state.mode="list"}onCancel(){this.state.mode="list",this.state.currentCF=void 0}onDeleteClick(e){this.env.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:e.id,sheet:this.getters.getActiveSheet()})}onRuleClick(e){this.state.mode="edit",this.state.currentCF=e,this.state.toRuleType="CellIsRule"===e.rule.type?"CellIsRule":"ColorScaleRule",this.state.currentRanges=this.state.currentCF.ranges}openCf(e){const t=this.getters.getConditionalFormats(),o=t.findIndex((t=>t.id===e)),s=t[o];s&&(this.state.mode="edit",this.state.currentCF=s,this.state.toRuleType="CellIsRule"===s.rule.type?"CellIsRule":"ColorScaleRule",this.state.currentRanges=this.state.currentCF.ranges)}defaultCellIsRule(){return{rule:{type:"CellIsRule",operator:"Equal",values:[],style:{fillColor:"#FF0000"}},ranges:this.getters.getSelectedZones().map(this.getters.zoneToXC),id:K()}}defaultColorScaleRule(){return{rule:{minimum:{type:"value",color:0},maximum:{type:"value",color:15663086},type:"ColorScaleRule"},ranges:this.getters.getSelectedZones().map(this.getters.zoneToXC),id:K()}}onAdd(){this.state.mode="add",this.state.currentCF=this.defaultCellIsRule(),this.state.currentRanges=this.state.currentCF.ranges}setRuleType(e){"ColorScaleRule"===e&&(this.state.currentCF=this.defaultColorScaleRule()),"CellIsRule"===e&&(this.state.currentCF=this.defaultCellIsRule()),this.state.toRuleType=e}onRangesChanged({detail:e}){this.state.currentRanges=e.ranges}}yr.template=Sr,yr.style=Cr,yr.components={CellIsRuleEditor:ar,ColorScaleRuleEditor:vr,SelectionInput:ri};const Tr=new _e;Tr.add("ConditionalFormatting",{title:Q("Conditional formatting"),Body:yr}),Tr.add("ChartPanel",{title:Q("Chart"),Body:Ui});const xr=new _e;class Rr{constructor(e,t,o){this.index=0,this.cells=e,this.getters=t,this.direction=o}next(){const e=this.cells[this.index++%this.cells.length];if(!e.rule)return{cellData:e.data,tooltip:e.data.content?{props:e.data.content}:void 0};const t=e.rule,{cellData:o,tooltip:s}=pn.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:Object.assign({},e.data,o),tooltip:s}}}class Mr extends dn{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheet();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:F(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:F(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?{status:"SUCCESS"}:{status:"CANCELLED",reason:17};case"AUTOFILL_AUTO":const o=this.getters.getSelectedZone();return o.top===o.bottom?{status:"SUCCESS"}:{status:"CANCELLED",reason:0}}return{status:"SUCCESS"}}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":const t=this.getters.getActiveSheet();this.dispatch("UPDATE_CELL",{sheet:t,col:e.col,row:e.row,style:e.style,border:e.border,content:e.content,format:e.format})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),o=this.autofillZone;switch(this.direction){case 1:for(let s=t.left;s<=t.right;s++){const n=[];for(let e=t.top;e<=t.bottom;e++)n.push(w(s,e));const i=this.createGenerator(n);for(let t=o.top;t<=o.bottom;t++)this.computeNewCell(i,s,t,e)}break;case 0:for(let s=t.left;s<=t.right;s++){const n=[];for(let e=t.bottom;e>=t.top;e--)n.push(w(s,e));const i=this.createGenerator(n);for(let t=o.bottom;t>=o.top;t--)this.computeNewCell(i,s,t,e)}break;case 2:for(let s=t.top;s<=t.bottom;s++){const n=[];for(let e=t.right;e>=t.left;e--)n.push(w(e,s));const i=this.createGenerator(n);for(let t=o.right;t>=o.left;t--)this.computeNewCell(i,t,s,e)}break;case 3:for(let s=t.top;s<=t.bottom;s++){const n=[];for(let e=t.left;e<=t.right;e++)n.push(w(e,s));const i=this.createGenerator(n);for(let t=o.left;t<=o.right;t++)this.computeNewCell(i,t,s,e)}}if(e){const e=C(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]})}}select(e,t){const o=this.getters.getSelectedZone();if(x(e,t,o))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case 0:this.saveZone(t,o.top-1,o.left,o.right);break;case 1:this.saveZone(o.bottom+1,t,o.left,o.right);break;case 2:this.saveZone(o.top,o.bottom,e,o.left-1);break;case 3:this.saveZone(o.top,o.bottom,o.right+1,e)}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone();let t=e.left,o=e.bottom;if(t>0){let e=this.getters.getCell(t-1,o);for(;e&&e.content;)o+=1,e=this.getters.getCell(t-1,o)}if(o===e.bottom&&(t=e.right,t<=this.getters.getNumberCols(this.getters.getActiveSheet()))){let e=this.getters.getCell(t+1,o);for(;e&&e.content;)o+=1,e=this.getters.getCell(t+1,o)}o!==e.bottom&&(this.select(e.left,o-1),this.autofill(!0))}computeNewCell(e,t,o,s){const{cellData:n,tooltip:i}=e.next(),{col:r,row:a,content:l,style:c,border:h,format:u}=n;this.tooltip=i,s&&this.dispatch("AUTOFILL_CELL",{originCol:r,originRow:a,col:t,row:o,content:l,style:c,border:h,format:u})}getRule(e,t){const o=gn.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((o=>o.condition(e,t)));return o&&o.generateRule(e,t)}createGenerator(e){const t=[],o=[];for(let t of e){const[e,s]=E(t);let n={col:e,row:s,cell:this.getters.getCell(e,s)};o.push(n)}const s=o.map((e=>e.cell));for(let e of o){let o;o=e&&e.cell&&e.cell.content?this.getRule(e.cell,s):{type:"COPY_MODIFIER"};const n={row:e.row,col:e.col,content:e.cell?e.cell.content:void 0,style:e.cell?e.cell.style:void 0,border:e.cell?e.cell.border:void 0,format:e.cell?e.cell.format:void 0};t.push({data:n,rule:o})}return new Rr(t,this.getters,this.direction)}saveZone(e,t,o,s){this.autofillZone={top:e,bottom:t,left:o,right:s}}getDirection(e,t){const o=this.getters.getSelectedZone(),s={up:{number:o.top-t,value:0},down:{number:t-o.bottom,value:1},left:{number:o.left-e,value:2},right:{number:e-o.right,value:3}};if(1===Object.values(s).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(s).find((e=>e.number>0?1:0)).value;const n=s.up.number>0?"up":"down",i=s.left.number>0?"left":"right";return Math.abs(s[n].number)>=Math.abs(s[i].number)?s[n].value:s[i].value}drawGrid(e){if(!this.autofillZone)return;const{viewport:t,ctx:o,thinLineWidth:s}=e,[n,i,r,a]=this.getters.getRect(this.autofillZone,t);r>0&&a>0&&(o.strokeStyle="black",o.lineWidth=s,o.setLineDash([3]),o.strokeRect(n,i,r,a),o.setLineDash([]))}}Mr.layers=[5],Mr.getters=["getAutofillTooltip"],Mr.modes=["normal","readonly"];const Ar=/^[S|N]?\d+/,Nr=un.content,kr="+,-,*,/,:,=,<>,>=,>,<=,<,%,^,&".split(",");function _r(e){const t=e.split(""),o=[];let s=0;for(;t.length;){if(s++,s>100)throw new Error(Q("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"));let e=Vr(t)||Ur(t)||Pr(t)||Zr(t)||Dr(t)||Or(t)||Br(t)||Hr(t);e||(e={type:"UNKNOWN",value:t.shift()}),o.push(e)}return o}const Ir="|";function Or(e){if(e[0]===Ir){e.shift();const t=e.join("").match(Ar);if(!t)return null;e.splice(0,t[0].length),e[0]===Ir&&e.shift();const o=t[0];switch(o[0]){case"S":return{type:"NORMALIZED_STRING",value:o.substring(1)};case"N":return{type:"NORMALIZED_NUMBER",value:o.substring(1)};default:return{type:"REFERENCE",value:o}}}return null}function Dr(e){return"?"===e[0]?(e.shift(),{type:"DEBUGGER",value:"?"}):null}const $r={",":"COMMA","(":"LEFT_PAREN",")":"RIGHT_PAREN"};function Ur(e){if(e[0]in $r){const t=e.shift();return{type:$r[t],value:t}}return null}function Fr(e,t){for(let o=0;o<t.length;o++)if(t[o]!==e[o])return!1;return!0}function Pr(e){for(let t of kr)if(Fr(e,t))return e.splice(0,t.length),{type:"OPERATOR",value:t};return null}function Br(e){const t=e.join("").match(B);return t?(e.splice(0,t[0].length),{type:"NUMBER",value:t[0]}):null}function Zr(e){if('"'===e[0]){const t=e.shift(),o=[t];for(;e[0]&&(e[0]!==t||"\\"===o[o.length-1]);)o.push(e.shift());return'"'===e[0]&&o.push(e.shift()),{type:"STRING",value:o.join("")}}return null}const zr=/\w|\.|!|\$/;function Hr(e){const t=[];if("'"===e[0]){let o=e.shift();for(t.push(o);e[0];)if(o=e.shift(),t.push(o),"'"===o){if(!e[0]||"'"!==e[0])break;o=e.shift(),t.push(o)}if("'"!==o)return{type:"UNKNOWN",value:t.join("")}}for(;e[0]&&e[0].match(zr);)t.push(e.shift());if(t.length){const e=t.join("");return{type:e.toUpperCase()in Nr?"FUNCTION":"SYMBOL",value:e}}return null}const Gr=/\s/;function Vr(e){let t=0;for(;e[0]&&e[0].match(Gr);)t++,e.shift();return t?{type:"SPACE",value:" ".repeat(t)}:null}const jr=un.content,qr=["-","+"],Wr={"^":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10};function Yr(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 Wr[e.value]||15}throw new Error("?")}const Xr=new RegExp(/\$?[A-Z]+\$?[0-9]+/,"i"),Kr=new RegExp(/^\s*\$?[A-Z]+\$?[0-9]+\s*(\s*:\s*\$?[A-Z]+\$?[0-9]+\s*)?$/,"i");function Jr(e,t,o){if("OPERATOR"===t.type){const s=Qr(o,Yr(t));return{type:"BIN_OPERATION",value:t.value,left:e,right:s}}throw new Error(Q("nope"))}function Qr(e,t){const o=e.shift();if(!o)throw new Error(Q("invalid expression"));let s=function(e,t){var o;switch(e.type){case"DEBUGGER":const s=Qr(t,1e3);return s.debug=!0,s;case"NUMBER":return{type:"NUMBER",value:G(e.value)};case"NORMALIZED_NUMBER":return{type:"NORMALIZED_NUMBER",value:e.value};case"STRING":return{type:"STRING",value:e.value};case"NORMALIZED_STRING":return{type:"NORMALIZED_STRING",value:e.value};case"FUNCTION":if("LEFT_PAREN"!==t.shift().type)throw new Error(Q("wrong function call"));{const s=[];if(t[0]&&"RIGHT_PAREN"!==t[0].type)for("COMMA"===t[0].type?s.push({type:"UNKNOWN",value:""}):s.push(Qr(t,6));"COMMA"===(null===(o=t[0])||void 0===o?void 0:o.type);){t.shift();const e=t[0];if("RIGHT_PAREN"===(null==e?void 0:e.type)){s.push({type:"UNKNOWN",value:""});break}"COMMA"===(null==e?void 0:e.type)?s.push({type:"UNKNOWN",value:""}):s.push(Qr(t,6))}const n=t.shift();if(!n||"RIGHT_PAREN"!==n.type)throw new Error(Q("wrong function call"));return{type:jr[e.value.toUpperCase()].async?"ASYNC_FUNCALL":"FUNCALL",value:e.value,args:s}}case"REFERENCE":return{type:"REFERENCE",value:parseInt(e.value,10)};case"SYMBOL":if(["TRUE","FALSE"].includes(e.value.toUpperCase()))return{type:"BOOLEAN",value:"TRUE"===e.value.toUpperCase()};if(e.value)throw new Error(Q("Invalid formula"));return{type:"UNKNOWN",value:e.value};case"LEFT_PAREN":const n=Qr(t,5);if(!t.length||"RIGHT_PAREN"!==t[0].type)throw new Error(Q("unmatched left parenthesis"));return t.shift(),n;default:if("OPERATOR"===e.type&&qr.includes(e.value))return{type:"UNARY_OPERATION",value:e.value,right:Qr(t,Wr[e.value])};throw new Error(Q("nope"))}}(o,e);for(;e[0]&&Yr(e[0])>t;)s=Jr(s,e.shift(),e);return s}function ea(e){const t=_r(e).filter((e=>"SPACE"!==e.type));"OPERATOR"===t[0].type&&"="===t[0].value&&t.splice(0,1);const o=Qr(t,0);if(t.length)throw new Error(Q("invalid expression"));return o}const ta=["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 oa extends dn{constructor(){super(...arguments),this.chartFigures=new Set,this.chartRuntime={},this.outOfDate=new Set}allowDispatch(e){const t={status:"SUCCESS"};switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":const o=void 0!==e.definition.dataSets.find((e=>!Kr.test(e.split("!").pop()))),s=!Kr.test(e.definition.labelRange.split("!").pop());return o||s?{status:"CANCELLED",reason:16}:t;default:return t}}handle(e){switch(e.type){case"CREATE_CHART":this.addChartFigure(e.sheetId,{id:e.id,data:this.createChartDefinition(e.definition,e.sheetId),x:0,y:0,height:500,width:800,tag:"chart"});break;case"UPDATE_CHART":{const t=this.createChartDefinition(e.definition,this.getChartDefinition(e.id).sheetId);this.dispatch("UPDATE_FIGURE",{id:e.id,data:t}),this.history.updateLocalState(["chartRuntime",e.id],this.mapDefinitionToRuntime(t));break}case"DELETE_FIGURE":if(this.chartFigures.has(e.id)){const t=new Set(this.chartFigures);t.delete(e.id),this.history.updateLocalState(["chartFigures"],t),this.history.updateLocalState(["chartRuntime",e.id],void 0)}break;case"DUPLICATE_SHEET":{const t=e.id,o=[...this.chartFigures].map((e=>this.getters.getFigure(e))).filter((t=>t.data.sheetId===e.sheet)).map(D);for(let e of o)e.data.sheetId=t,e.id=K(),this.addChartFigure(t,e);break}case"DELETE_SHEET":const t=new Set(this.chartFigures),o={...this.chartRuntime};for(let e of this.chartFigures){this.getters.getFigure(e)||(t.delete(e),delete o[e])}this.history.updateLocalState(["chartFigures"],t),this.history.updateLocalState(["chartRuntime"],o);break;case"UPDATE_CELL":for(let t of this.chartFigures){const o=this.getChartDefinition(t);this.isCellUsedInChart(o,e.col,e.row)&&this.outOfDate.add(t)}}}finalize(e){switch(e.type){case"EVALUATE_CELLS":case"START":for(let e in this.chartRuntime)this.outOfDate.add(e)}}import(e){for(let t of e.sheets)for(let e of t.figures)"chart"===e.tag&&(this.outOfDate.add(e.id),this.chartFigures.add(e.id))}getChartRuntime(e){return this.outOfDate.has(e)&&(this.chartRuntime[e]=this.mapDefinitionToRuntime(this.getChartDefinition(e)),this.outOfDate.delete(e)),this.chartRuntime[e]}getChartDefinition(e){return this.getters.getFigure(e).data}createChartDefinition(e,t){let o=[];for(let t of e.dataSets){let s=L(t);if(s.left!==s.right&&s.top!==s.bottom)for(let t=s.left;t<=s.right;t++){const n={left:t,right:t,top:s.top,bottom:s.bottom};o.push(this.createDataset(n,e.seriesHasTitle))}else s.left===s.right&&s.top===s.bottom?e.seriesHasTitle||o.push({dataRange:S(s)}):o.push(this.createDataset(s,e.seriesHasTitle))}return{title:e.title,type:e.type,dataSets:o,labelRange:e.labelRange,sheetId:t}}createDataset(e,t){if(e.left!==e.right&&e.top!==e.bottom)throw new Error(`Zone should be a single column or row: ${S(e)}`);const o=t?w(e.left,e.top):void 0,s=t?1:0,n=e.top!==e.bottom&&e.left===e.right;return{labelCell:o,dataRange:S({top:n?e.top+s:e.top,bottom:e.bottom,left:n?e.left:e.left+s,right:e.right})}}getDefaultConfiguration(e,t,o){const s={type:e,options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:10,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!0,fontSize:22,fontStyle:"normal",text:t}},data:{labels:o,datasets:[]}};return"pie"!==e?s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2}}],yAxes:[{ticks:{beginAtZero:!0}}]}:s.options.tooltips={callbacks:{title:function(e,t){return t.datasets[e[0].datasetIndex].label}}},s}extractDataFromRange(e,t){return t?this.getters.getRangeValues(t,e).flat(1):[]}mapDefinitionToRuntime(e){const t=""!==e.labelRange?this.getters.getRangeFormattedValues(e.labelRange,e.sheetId).flat(1):[],o=this.getDefaultConfiguration(e.type,e.title,t);let s=0;const n=[];if("pie"===e.type){const t=Math.max(...e.dataSets.map((t=>this.extractDataFromRange(e.sheetId,t.dataRange).length)));for(let e=0;e<=t;e++)n.push(ta[s]),s=++s%ta.length}for(const[t,i]of Object.entries(e.dataSets)){let r;if(i.labelCell)try{r=this.getters.evaluateFormula(i.labelCell,e.sheetId)}catch(e){r=`${yi} ${parseInt(t)+1}`}else r=`${yi} ${parseInt(t)+1}`;const a={label:r,data:this.extractDataFromRange(e.sheetId,i.dataRange),lineTension:0,borderColor:"pie"!==e.type?ta[s]:"#FFFFFF",backgroundColor:ta[s]};"pie"===e.type&&(a.backgroundColor=n),s=++s%ta.length,o.data.datasets.push(a)}return o}addChartFigure(e,t){this.dispatch("CREATE_FIGURE",{sheet:e,figure:t}),this.history.updateLocalState(["chartFigures"],new Set(this.chartFigures).add(t.id)),this.history.updateLocalState(["chartRuntime",t.id],this.mapDefinitionToRuntime(t.data))}isCellUsedInChart(e,t,o){if(x(t,o,L(e.labelRange)))return!0;for(let s of e.dataSets){if(s.dataRange&&s.dataRange.length>0&&x(t,o,L(s.dataRange)))return!0;if(s.labelCell&&s.labelCell.length>0&&x(t,o,L(s.labelCell)))return!0}return!1}}oa.getters=["getChartRuntime"],oa.layers=[3];class sa extends dn{constructor(){super(...arguments),this.status="empty",this.zones=[],this.originSheet=this.workbook.activeSheet.id,this._isPaintingFormat=!1,this.pasteOnlyValue=!1,this.pasteOnlyFormat=!1}allowDispatch(e){return"PASTE"===e.type?this.isPasteAllowed(e.target):{status:"SUCCESS"}}handle(e){switch(e.type){case"COPY":this.cutOrCopy(e.target,!1);break;case"CUT":this.cutOrCopy(e.target,!0);break;case"PASTE":this.pasteOnlyValue="onlyValue"in e&&!!e.onlyValue;const t="onlyFormat"in e?!!e.onlyFormat:this._isPaintingFormat;this._isPaintingFormat=!1,this.pasteOnlyFormat=!this.pasteOnlyValue&&t,e.interactive?this.interactivePaste(e.target):this.pasteFromModel(e.target);break;case"PASTE_CELL":this.pasteCell(e.origin,e.col,e.row,e.onlyValue,e.onlyFormat);break;case"PASTE_FROM_OS_CLIPBOARD":this.pasteFromClipboard(e.target,e.text);break;case"ACTIVATE_PAINT_FORMAT":this._isPaintingFormat=!0,this.cutOrCopy(e.target,!1)}}getClipboardContent(){return this.cells&&this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell):"")).join("\t"))).join("\n")||"\t"}getPasteZones(e){if(!this.cells)return e;const t=this.cells.length,o=this.cells[0].length,s=e[e.length-1],n=[];let i=s.left,r=s.top;const a=Math.max(1,Math.floor((s.right+1-s.left)/o)),l=Math.max(1,Math.floor((s.bottom+1-s.top)/t));for(let e=1;e<=a;e++)for(let s=1;s<=l;s++)n.push({left:i,top:r,right:i-1+e*o,bottom:r-1+s*t});return n}isPaintingFormat(){return this._isPaintingFormat}cutOrCopy(e,t){const o=new Set(e.map((e=>e.top))),s=new Set(e.map((e=>e.bottom)));let n=1===o.size&&1===s.size?e:[e[e.length-1]];n=n.map((e=>Object.assign({},e)));const i=[];let{top:r,bottom:a}=n[0];for(let e=r;e<=a;e++){const t=[];i.push(t);for(let o of n){let{left:s,right:n}=o;for(let o=s;o<=n;o++){const s=this.getters.getCell(o,e);t.push({cell:s?Object.assign({},s):null,col:o,row:e})}}}this.status="visible",this.shouldCut=t,this.zones=n,this.cells=i,this.originSheet=this.workbook.activeSheet.id}pasteFromClipboard(e,t){this.status="invisible";const o=t.replace(/\r/g,"").split("\n").map((e=>e.split("\t"))),{left:s,top:n}=e[0],i=Math.max.apply(Math,o.map((e=>e.length))),r=o.length;this.addMissingDimensions(i,r,s,n);for(let e=0;e<o.length;e++)for(let t=0;t<o[e].length;t++){const i=w(s+t,n+e);this.dispatch("SET_VALUE",{xc:i,text:o[e][t]})}this.dispatch("SET_SELECTION",{anchor:[s,n],zones:[{left:s,top:n,right:s+i-1,bottom:n+r-1}]})}isPasteAllowed(e){const{zones:t,cells:o,status:s}=this;return t&&o&&"empty"!==s?e.length>1&&(o.length>1||o[0].length>1)?{status:"CANCELLED",reason:11}:{status:"SUCCESS"}:{status:"CANCELLED",reason:12}}pasteFromModel(e){const{cells:t,shouldCut:o}=this;if(!t)return;this.status=o?"empty":"invisible",o&&this.clearCutZone();const s=t.length,n=t[0].length;if(e.length>1){for(let t of e)for(let e=t.left;e<=t.right;e++)for(let o=t.top;o<=t.bottom;o++)this.pasteZone(n,s,e,o);return}const i=e[e.length-1];let r=i.left,a=i.top;const l=Math.max(1,Math.floor((i.right+1-i.left)/n)),c=Math.max(1,Math.floor((i.bottom+1-i.top)/s));for(let e=0;e<l;e++)for(let t=0;t<c;t++)this.pasteZone(n,s,r+e*n,a+t*s);if(s>1||n>1){const e={left:r,top:a,right:r+l*n-1,bottom:a+c*s-1},[t,o]=this.getters.getSelection().anchor,i=F(t,r,r+l*n-1),h=F(o,a,a+c*s-1);this.dispatch("SET_SELECTION",{anchor:[i,h],zones:[e]})}}clearCutZone(){for(let e of this.cells)for(let t of e)t&&this.dispatch("CLEAR_CELL",{sheet:this.originSheet,col:t.col,row:t.row})}pasteZone(e,t,o,s){this.addMissingDimensions(e,t,o,s);for(let n=0;n<t;n++){const t=this.cells[n];for(let i=0;i<e;i++){const e=t[i];this.dispatch("PASTE_CELL",{origin:e.cell,originCol:e.col,originRow:e.row,col:o+i,row:s+n,sheet:this.originSheet,cut:this.shouldCut,onlyValue:this.pasteOnlyValue,onlyFormat:this.pasteOnlyFormat})}}}addMissingDimensions(e,t,o,s){const{cols:n,rows:i}=this.workbook.activeSheet,r=t+s-i.length;r>0&&this.dispatch("ADD_ROWS",{row:i.length-1,sheet:this.workbook.activeSheet.id,quantity:r,position:"after"});const a=e+o-n.length;a>0&&this.dispatch("ADD_COLUMNS",{column:n.length-1,sheet:this.workbook.activeSheet.id,quantity:a,position:"after"})}pasteCell(e,t,o,s,n){const i=this.getters.getCell(t,o);if(e){let r=e.style,a=e.border,l=e.format,c=e.content||"";if(s)r=i?i.style:void 0,a=i?i.border:void 0,l=i?i.format:void 0,i&&"date"===i.type&&(l=i.value.format),"formula"!==e.type&&"date"!==e.type||(c=this.valueToContent(e.value));else if(n)c=i?i.content:"";else if("formula"===e.type){const s=t-e.col,n=o-e.row;c=this.getters.applyOffset(c,s,n)}let h={style:r,border:a,format:l,sheet:this.workbook.activeSheet.id,col:t,row:o,content:c};this.dispatch("UPDATE_CELL",h)}!e&&i&&(s?i.content&&(this.history.updateCell(i,"content",""),this.history.updateCell(i,"value","")):n?(i.style&&this.history.updateCell(i,"style",void 0),i.border&&this.history.updateCell(i,"border",void 0),i.format&&this.history.updateCell(i,"format",void 0)):this.dispatch("CLEAR_CELL",{sheet:this.workbook.activeSheet.id,col:t,row:o}))}valueToContent(e){switch(typeof e){case"number":return e.toString();case"string":return e;case"boolean":return e?"TRUE":"FALSE";case"object":return e.value.toString();default:return""}}interactivePaste(e){const t=this.dispatch("PASTE",{target:e,onlyFormat:!1});"CANCELLED"===t.status&&(11===t.reason&&this.ui.notifyUser(Q("This operation is not allowed with multiple selections.")),1===t.reason&&this.ui.askConfirmation(Q("Pasting here will remove existing merge(s). Paste anyway?"),(()=>this.dispatch("PASTE",{target:e,onlyFormat:!1,force:!0}))))}drawGrid(e){const{viewport:t,ctx:o,thinLineWidth:s}=e,n=this.zones;if("visible"===this.status&&n.length&&this.originSheet===this.getters.getActiveSheet()){o.save(),o.setLineDash([8,5]),o.strokeStyle="#3266ca",o.lineWidth=3.3*s;for(const e of n){const[s,n,i,r]=this.getters.getRect(e,t);i>0&&r>0&&o.strokeRect(s,n,i,r)}o.restore()}}}sa.layers=[2],sa.getters=["getClipboardContent","isPaintingFormat","getPasteZones"],sa.modes=["normal","readonly"];class na extends dn{constructor(){super(...arguments),this.isStale=!0,this.cfRules={},this.computedStyles={},this.rulePredicate={CellIsRule:(e,t)=>{switch(t.operator){case"BeginsWith":return!(!e&&""===t.values[0])&&(e&&e.value.startsWith(t.values[0]));case"EndsWith":return!(!e&&""===t.values[0])&&(e&&e.value.endsWith(t.values[0]));case"Between":return e&&e.value>=t.values[0]&&e.value<=t.values[1];case"NotBetween":return!(e&&e.value>=t.values[0]&&e.value<=t.values[1]);case"ContainsText":return e&&e.value&&e.value.toString().indexOf(t.values[0])>-1;case"NotContains":return e&&e.value&&-1==e.value.toString().indexOf(t.values[0]);case"GreaterThan":return e&&e.value>t.values[0];case"GreaterThanOrEqual":return e&&e.value>=t.values[0];case"LessThan":return e&&e.value<t.values[0];case"LessThanOrEqual":return e&&e.value<=t.values[0];case"NotEqual":return!(!e&&""===t.values[0])&&(e&&e.value!=t.values[0]);case"Equal":return!e&&""===t.values[0]||e&&e.value==t.values[0];default:console.warn(Q("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.to;this.computedStyles[t]=this.computedStyles[t]||{},this.isStale=!0;break;case"CREATE_SHEET":this.cfRules[e.id]=[],this.isStale=!0;break;case"DUPLICATE_SHEET":this.history.updateLocalState(["cfRules",e.id],this.cfRules[e.sheet].slice()),this.isStale=!0;break;case"DELETE_SHEET":const o=Object.assign({},this.cfRules);delete o[e.sheet],this.history.updateLocalState(["cfRules"],o),this.isStale=!0;break;case"ADD_CONDITIONAL_FORMAT":this.addConditionalFormatting(e.cf,e.sheet),this.isStale=!0;break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheet),this.isStale=!0;break;case"REMOVE_COLUMNS":this.adaptcfRules(e.sheet,(t=>N(t,e.columns))),this.isStale=!0;break;case"REMOVE_ROWS":this.adaptcfRules(e.sheet,(t=>k(t,e.rows))),this.isStale=!0;break;case"ADD_COLUMNS":const s="before"===e.position?e.column:e.column+1;this.adaptcfRules(e.sheet,(t=>_(t,s,e.quantity))),this.isStale=!0;break;case"AUTOFILL_CELL":const n=this.getters.getActiveSheet(),i=this.getRulesByCell(w(e.originCol,e.originRow));for(const t of i)this.adaptRules(n,t,[w(e.col,e.row)],[]);break;case"ADD_ROWS":const r="before"===e.position?e.row:e.row+1;this.adaptcfRules(e.sheet,(t=>I(t,r,e.quantity))),this.isStale=!0;break;case"PASTE_CELL":e.onlyValue||this.pasteCf(e.originCol,e.originRow,e.col,e.row,e.sheet,e.cut);break;case"EVALUATE_CELLS":case"UPDATE_CELL":case"UNDO":case"REDO":this.isStale=!0}}finalize(){this.isStale&&"headless"!==this.currentMode&&(this.computeStyles(),this.isStale=!1)}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id])}getConditionalFormats(){return this.cfRules[this.workbook.activeSheet.id]}getConditionalStyle(e){return this.computedStyles[this.workbook.activeSheet.id]&&this.computedStyles[this.workbook.activeSheet.id][e]}getRulesSelection(e){const t=new Set;return e.forEach((e=>{this.getRulesByZone(e).forEach((e=>{t.add(e)}))})),Array.from(t)}getRulesByZone(e){const t=new Set;for(let o=e.top;o<=e.bottom;o++)for(let s=e.left;s<=e.right;s++){this.getRulesByCell(w(s,o)).forEach((e=>{t.add(e.id)}))}return t}getRulesByCell(e){const t=this.workbook.activeSheet.id,o=new Set;for(let s of this.cfRules[t])for(let t of s.ranges){const n=L(t);for(let t=n.top;t<=n.bottom;t++)for(let i=n.left;i<=n.right;i++){e==w(i,t)&&o.add(s)}}return o}addConditionalFormatting(e,t){const o=this.cfRules[t].slice(),s=o.findIndex((t=>t.id===e.id));s>-1?o.splice(s,1,e):o.push(e),this.history.updateLocalState(["cfRules",t],o)}applyColorScale(e,t){const o=Number(this.getters.evaluateFormula(`=min(${e})`)),s=Number(this.getters.evaluateFormula(`=max(${e})`));if(Number.isNaN(o)||Number.isNaN(s))return;const n=s-o;if(!n)return;const i=((t.minimum.color>>16)%256-(t.maximum.color>>16)%256)/n,r=((t.minimum.color>>8)%256-(t.maximum.color>>8)%256)/n,a=(t.minimum.color%256-t.maximum.color%256)/n,l=L(e);for(let e=l.top;e<=l.bottom;e++)for(let s=l.left;s<=l.right;s++){const n=this.getters.getCell(s,e);if(n&&!Number.isNaN(Number.parseFloat(n.value))){const e=Math.round((t.minimum.color>>16)%256-i*(n.value-o))<<16|Math.round((t.minimum.color>>8)%256-r*(n.value-o))<<8|Math.round(t.minimum.color%256-a*(n.value-o));this.computedStyles[this.workbook.activeSheet.id][n.xc]=this.computedStyles[this.workbook.activeSheet.id][n.xc]||{},this.computedStyles[this.workbook.activeSheet.id][n.xc].fillColor="#"+f(e)}}}computeStyles(){const e=this.workbook.activeSheet.id;this.computedStyles[e]={};for(let t of this.cfRules[e])try{if("ColorScaleRule"===t.rule.type)for(let e of t.ranges)this.applyColorScale(e,t.rule);else for(let o of t.ranges){const s=L(o);for(let o=s.top;o<=s.bottom;o++)for(let n=s.left;n<=s.right;n++){const s=this.rulePredicate[t.rule.type];let i=this.workbook.activeSheet.rows[o].cells[n],r=w(n,o);s&&s(i,t.rule)&&(this.computedStyles[e][r]=Object.assign(this.computedStyles[e][r]||{},t.rule.style))}}}catch(e){}}adaptcfRules(e,t){const o=this.cfRules[e],s=[];for(let e of o){const o=[];for(let s of e.ranges){const e=t(s);e&&o.push(e)}0!==o.length&&s.push({...e,ranges:o})}this.history.updateLocalState(["cfRules",e],s)}removeConditionalFormatting(e,t){const o=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==o){const e=this.cfRules[t].slice();e.splice(o,1),this.history.updateLocalState(["cfRules",t],e)}}pasteCf(e,t,o,s,n,i){const r=w(o,s);for(let o of this.cfRules[n])for(let s of o.ranges)if(x(e,t,L(s))){const s=o,a=[];i&&a.push(w(e,t)),n===this.workbook.activeSheet.id?this.adaptRules(n,s,[r],a):(this.adaptRules(this.workbook.activeSheet.id,s,[r],[]),this.adaptRules(n,s,[],a))}}adaptRules(e,t,o,s){if(0===o.length&&0===s.length)return;const n=this.cfRules[e].findIndex((e=>e.id===t.id));let i=[];n>-1&&(i=this.cfRules[e][n].ranges),i=i.concat(o);const r=R(i,s);this.addConditionalFormatting({id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue,ranges:r},e)}}na.getters=["getConditionalFormats","getConditionalStyle","getRulesSelection"];const ia=un.content,ra={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},aa={"-":"UMINUS","+":"UPLUS"},la={},ca=Object.getPrototypeOf((async function(){})).constructor;function ha(e){let t=!1;if(!la[e.text]){const o=ea(e.text);let s=1;const n=[`// ${e.text}`];if("BIN_OPERATION"===o.type&&":"===o.value)throw new Error(Q("Invalid formula"));if("UNKNOWN"===o.type)throw new Error(Q("Invalid formula"));function i(e){const t=ia[e.value.toUpperCase()];let o;const s=[],n=e.args;let i=0,a=!!t.args.length&&t.args[t.args.length-1].repeating?1/0:t.args.length;for(let e of t.args)e.optional||i++;if(n.length<i||n.length>a)throw new Error(Q("Invalid number of arguments for the %s function. Expected %s, but got %s instead.",e.value.toUpperCase(),t.args.length.toString(),n.length.toString()));for(let i=0;i<n.length;i++){const a=n[i];o=t.args[i]||o;const l=o&&o.lazy,c=o&&o.type||[],h=c.some((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e)),u=c.every((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e));if(u&&"REFERENCE"!==a.type)throw new Error(Q("Function %s expects the parameter %s to be reference to a cell or range, not a %s.",e.value.toUpperCase(),(i+1).toString(),a.type.toLowerCase().replace("normalized_","")));if("BIN_OPERATION"===a.type&&":"===a.value&&a.left.value!==a.right.value&&!h)throw new Error(Q("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",e.value.toUpperCase(),(i+1).toString()));let d=r(a,l,h,{functionName:e.value.toUpperCase(),paramIndex:i+1});s.push(d)}return s}function r(o,a=!1,l=!1,c={}){let h,u,d,p,g,f;switch(o.debug&&n.push("debugger;"),o.type){case"BOOLEAN":case"NUMBER":case"STRING":h=s++,f=o.value;break;case"NORMALIZED_NUMBER":case"NORMALIZED_STRING":h=s++,f=`deps[${o.value}]`;break;case"REFERENCE":if(!e.dependencies[o.value]){h=s++,f="null";break}h=s++,f=l?`range(${o.value}, deps, sheetId)`:`ref(${o.value}, deps, sheetId,\n "${c.functionName}", ${c.paramIndex})`;break;case"FUNCALL":h=s++,p=i(o),g=o.value.toUpperCase(),n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}'](${p})`;break;case"ASYNC_FUNCALL":h=s++,t=!0,p=i(o),g=o.value.toUpperCase(),n.push(`ctx.__lastFnCalled = '${g}'`),f=`await ctx['${g}'](${p})`;break;case"UNARY_OPERATION":h=s++,d=r(o.right),g=aa[o.value],n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}']( ${d})`;break;case"BIN_OPERATION":h=s++,u=r(o.left),d=r(o.right),g=ra[o.value],n.push(`ctx.__lastFnCalled = '${g}'`),f=`ctx['${g}'](${u}, ${d})`;break;case"UNKNOWN":if(!a)return"null";h=s++,f="null"}return n.push(`let _${h} = `+(a?"()=> ":"")+f),`_${h}`}n.push(`return ${r(o)};`);let a=new(t?ca:Function)("deps","sheetId","ref","range","ctx",n.join("\n"));la[e.text]=a,la[e.text].async=t}return la[e.text]}function ua(e,t=!1){let o,s,n,i;const r=()=>{i=void 0,s=void 0,o=void 0,n=void 0};for(let a=0;a<e.length;a++){const l=e[a];if(i)if(s){if("SPACE"===l.type)continue;if("OPERATOR"===l.type&&":"===l.value)o=a;else if(o&&"SYMBOL"===l.type)n=a;else if(i&&s&&o&&n){const o={type:"SYMBOL",value:e.slice(i,a).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(i,a-i,o),a=i+1,r()}else"SYMBOL"===l.type?(i=a,s=a,o=void 0):r()}else"SYMBOL"===l.type?(s=a,o=n=void 0):r();else["SPACE","SYMBOL"].includes(l.type)?(i=a,s="SYMBOL"===l.type?a:void 0,o=n=void 0):r()}const a=e.length-1;if(i&&s&&o&&n){const o={type:"SYMBOL",value:e.slice(i,a+1).filter((e=>!t||"SPACE"!==e.type)).map((e=>e.value)).join("")};e.splice(i,a-i+1,o)}return e}function da(e){return ua(_r(e),!0)}function pa(e){return function(e){let t=1;const o=[];return e.map((e=>("LEFT_PAREN"===e.type?(o.push(t),e.parenIndex=t,t++):"RIGHT_PAREN"===e.type&&(e.parenIndex=o.pop()),e)))}(function(e){let t=0;return e.map((e=>{const o=e.value.toString().length,s=Object.assign({},e,{start:t,end:t+o,length:o});return t=s.end,s}))}(ua(_r(e))))}function ga(e){const t=da(e);let o=[];return{text:"".concat(...t.map((e=>{if("SYMBOL"===e.type&&Xr.test(e.value)){const t=e.value.trim();return o.includes(t)||o.push(t),`|${o.indexOf(t)}|`}if(["STRING","NUMBER"].includes(e.type)){const t="STRING"===e.type?e.value.slice(1).slice(0,e.value.length-2):G(e.value);return o.includes(t)||o.push(t),`|${e.type[0]}${o.indexOf(t)}|`}return e.value}))),dependencies:o}}const fa=new RegExp(String.fromCharCode(160),"g");class ma extends dn{constructor(){super(...arguments),this.sheetIds={},this.showFormulas=!1,this.updateColumnsRef=(e,t,o,s)=>{let n=E(e)[0];return n===o&&-1===s?"#REF":this.updateReference(e,n>o?s:0,0,this.getSheetIdByName(t),!1)},this.updateColumnsRange=(e,t,o,s)=>{const n=L(e),i=s<0?R([e],[this.zoneToXC({...n,left:o+s+1,right:o})]):[e];if(0===i.length)return"#REF";const r=L(i[0]),a=s<0&&n.left<o+s+1&&o<n.right?L(i[1]):r,l=o<r.left?r.left+s:r.left,c=o<a.right?a.right+s:a.right,[h,u]=e.split(":"),d=this.getters.getSheetIdByName(t),p=this.updateReference(h,l-n.left,0,d,!1,!1),g=this.updateReference(u,c-n.right,0,d,!1,!1);return p===g?p:`${p}:${g.split("!").pop()}`},this.updateRowsRef=(e,t,o,s)=>{let n=E(e)[1];return o+s<n&&n<=o?"#REF":this.updateReference(e,0,n>o?s:0,this.getSheetIdByName(t),!1)},this.updateRowsRange=(e,t,o,s)=>{const n=L(e),i=s<0?R([e],[this.zoneToXC({...n,top:o+s+1,bottom:o})]):[e];if(0===i.length)return"#REF";const r=L(i[0]),a=s<0&&n.top<o+s+1&&o<n.bottom?L(i[1]):r,l=o<r.top?r.top+s:r.top,c=o<a.bottom?a.bottom+s:a.bottom,[h,u]=e.split(":"),d=this.getters.getSheetIdByName(t),p=this.updateReference(h,0,l-n.top,d,!1,!1),g=this.updateReference(u,0,c-n.bottom,d,!1,!1);return p===g?p:`${p}:${g.split("!").pop()}`}}allowDispatch(e){switch(e.type){case"REMOVE_COLUMNS":return this.workbook.sheets[e.sheet].cols.length>e.columns.length?{status:"SUCCESS"}:{status:"CANCELLED",reason:5};case"REMOVE_ROWS":return this.workbook.sheets[e.sheet].rows.length>e.rows.length?{status:"SUCCESS"}:{status:"CANCELLED",reason:6};case"CREATE_SHEET":case"DUPLICATE_SHEET":const{visibleSheets:t,sheets:o}=this.workbook;return e.name&&t.find((t=>o[t].name===e.name))?{status:"CANCELLED",reason:8}:{status:"SUCCESS"};case"MOVE_SHEET":const s=this.workbook.visibleSheets.findIndex((t=>t===e.sheet));return-1===s?{status:"CANCELLED",reason:8}:"left"===e.direction&&0===s||"right"===e.direction&&s===this.workbook.visibleSheets.length-1?{status:"CANCELLED",reason:9}:{status:"SUCCESS"};case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET_CONFIRMATION":case"DELETE_SHEET":return this.workbook.visibleSheets.length>1?{status:"SUCCESS"}:{status:"CANCELLED",reason:7};default:return{status:"SUCCESS"}}}handle(e){switch(e.type){case"ACTIVATE_SHEET":this.history.updateState(["activeSheet"],this.workbook.sheets[e.to]);break;case"CREATE_SHEET":const t=this.createSheet(e.id,e.name||this.generateSheetName(),e.cols||26,e.rows||100);this.sheetIds[this.workbook.sheets[t].name]=t,e.activate&&this.dispatch("ACTIVATE_SHEET",{from:this.workbook.activeSheet.id,to:t});break;case"MOVE_SHEET":this.moveSheet(e.sheet,e.direction);break;case"RENAME_SHEET":e.interactive?this.interactiveRenameSheet(e.sheet,Q("Rename Sheet")):this.renameSheet(e.sheet,e.name);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheet,e.id,e.name);break;case"DELETE_SHEET_CONFIRMATION":this.interactiveDeleteSheet(e.sheet);break;case"DELETE_SHEET":this.deleteSheet(e.sheet);break;case"DELETE_CONTENT":this.clearZones(e.sheet,e.target);break;case"SET_VALUE":const[o,s]=E(e.xc);this.dispatch("UPDATE_CELL",{sheet:e.sheetId?e.sheetId:this.workbook.activeSheet.id,col:o,row:s,content:e.text});break;case"UPDATE_CELL":this.updateCell(e.sheet,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheet:e.sheet,col:e.col,row:e.row,content:"",border:0,style:0,format:""});break;case"AUTORESIZE_COLUMNS":for(let t of e.cols){const o=this.getColMaxWidth(t);0!==o&&this.setColSize(e.sheet,t,o+6)}break;case"AUTORESIZE_ROWS":for(let t of e.rows){const o=this.getRowMaxHeight(t);0!==o&&this.setRowSize(e.sheet,t,o+6)}break;case"RESIZE_COLUMNS":for(let t of e.cols)this.setColSize(e.sheet,t,e.size);break;case"RESIZE_ROWS":for(let t of e.rows)this.setRowSize(e.sheet,t,e.size);break;case"REMOVE_COLUMNS":this.removeColumns(e.sheet,e.columns),this.history.updateState(["sheets",e.sheet,"colNumber"],this.workbook.sheets[e.sheet].colNumber-e.columns.length);break;case"REMOVE_ROWS":this.removeRows(e.sheet,e.rows),this.history.updateState(["sheets",e.sheet,"rowNumber"],this.workbook.sheets[e.sheet].rowNumber-e.rows.length);break;case"ADD_COLUMNS":this.addColumns(e.sheet,e.column,e.position,e.quantity),this.history.updateState(["activeSheet","colNumber"],this.workbook.activeSheet.colNumber+e.quantity);break;case"ADD_ROWS":this.addRows(e.sheet,e.row,e.position,e.quantity),this.history.updateState(["activeSheet","rowNumber"],this.workbook.activeSheet.rowNumber+e.quantity);break;case"SET_FORMULA_VISIBILITY":this.showFormulas=e.show}}applyOffset(e,t,o){return da(e).map((e=>{if("SYMBOL"===e.type&&Xr.test(e.value)){const[s,n]=e.value.split("!").reverse(),i=this.getSheetIdByName(n);return s.includes(":")?this.updateRange(s,t,o,i):this.updateReference(s,t,o,i,!0,!1)}return e.value})).join("")}getCell(e,t,o){let s;if(o){const e=Object.values(this.workbook.sheets).find((e=>e.name===o));if(!e)return null;s=e.rows[t]}else s=this.workbook.activeSheet.rows[t];return s&&s.cells[e]||null}getCellText(e){const t=this.showFormulas?e.content:e.value,o=(t||0===t)&&e.format&&!e.error&&!e.pending,s=o&&e.format.match(/y|m|d|:/),n=o&&!s;switch(typeof t){case"string":return t;case"boolean":return t?"TRUE":"FALSE";case"number":return s?he({value:t,format:e.format}):n?Y(t,e.format):j(t);case"object":if(!t)return"0";if("value"in t&&"format"in t){if(s)return he(t,e.format);if(n)return Y(t.value,e.format);if(t&&t.format.match(/y|m|d|:/))return he(t)}return t.toString()}return""}zoneToXC(e){const t=w((e=this.getters.expandZone(e)).left,e.top),o=w(e.right,e.bottom);return t!=o&&this.getters.getMainCell(t)!==this.getters.getMainCell(o)?t+":"+o:t}getActiveSheet(){return this.workbook.activeSheet.id}getSheetName(e){return this.workbook.sheets[e]&&this.workbook.sheets[e].name}getSheetIdByName(e){return e&&this.sheetIds[$(e)]}getSheets(){const{visibleSheets:e,sheets:t}=this.workbook;return e.map((e=>t[e]))}getCol(e,t){return this.workbook.sheets[e].cols[t]}getRow(e,t){return this.workbook.sheets[e].rows[t]}getColCells(e){return this.workbook.activeSheet.rows.reduce(((t,o)=>o.cells[e]?t.concat(o.cells[e]):t),[])}getNumberCols(e){return this.workbook.sheets[e].cols.length}getNumberRows(e){return this.workbook.sheets[e].rows.length}getColsZone(e,t){return{top:0,bottom:this.workbook.activeSheet.rows.length-1,left:e,right:t}}getRowsZone(e,t){return{top:e,bottom:t,left:0,right:this.workbook.activeSheet.cols.length-1}}getGridSize(){const e=this.workbook.activeSheet,t=e.rows[e.rows.length-1].end+d+5;return[e.cols[e.cols.length-1].end+u,t]}shouldShowFormulas(){return this.showFormulas}getRangeValues(e,t){const[o,s]=e.split("!").reverse(),n=s?this.sheetIds[s]:t;return A(L(o),this.workbook.sheets[n],(e=>e.value))}getRangeFormattedValues(e,t){const[o,s]=e.split("!").reverse(),n=s?this.sheetIds[s]:t;return A(L(o),this.workbook.sheets[n],this.getters.getCellText,"")}getColMaxWidth(e){const t=this.workbook.activeSheet.rows.reduce(((t,o)=>o.cells[e]?t.concat(o.cells[e]):t),[]).map(this.getters.getCellWidth);return Math.max(0,...t)}getRowMaxHeight(e){const t=Object.values(this.workbook.activeSheet.rows[e].cells).map(this.getters.getCellHeight);return Math.max(0,...t)}setColSize(e,t,o){const s=this.workbook.sheets[e].cols,n=s[t],i=o-n.size;this.history.updateState(["sheets",e,"cols",t,"size"],o),this.history.updateState(["sheets",e,"cols",t,"end"],n.end+i);for(let o=t+1;o<s.length;o++){const t=s[o];this.history.updateState(["sheets",e,"cols",o,"start"],t.start+i),this.history.updateState(["sheets",e,"cols",o,"end"],t.end+i)}}setRowSize(e,t,o){const s=this.workbook.sheets[e].rows,n=s[t],i=o-n.size;this.history.updateState(["sheets",e,"rows",t,"size"],o),this.history.updateState(["sheets",e,"rows",t,"end"],n.end+i);for(let o=t+1;o<s.length;o++){const t=s[o];this.history.updateState(["sheets",e,"rows",o,"start"],t.start+i),this.history.updateState(["sheets",e,"rows",o,"end"],t.end+i)}}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let o of t)this.updateColumnsFormulas(o,-1,e),this.moveCellsHorizontally(o,-1,e),this.manageColumnsHeaders(o,-1,e)}removeRows(e,t){t.sort(((e,t)=>t-e));const o=t.reduce(((e,t,o,s)=>{if(t-s[o-1]==-1){e[e.length-1].push(t)}else e.push([t]);return e}),[]);for(let t of o)this.updateRowsFormulas(t[0],-t.length,e),this.moveCellVerticallyBatched(t[t.length-1],t[0],e),t.map((t=>this.processRowsHeaderDelete(t,e)))}addColumns(e,t,o,s){this.updateColumnsFormulas("before"===o?t-1:t,s,e),this.moveCellsHorizontally("before"===o?t:t+1,s,e),this.manageColumnsHeaders(t,s,e)}addRows(e,t,o,s){for(let e=0;e<s;e++)this.addEmptyRow();this.updateRowsFormulas("before"===o?t-1:t,s,e),this.moveCellsVertically("before"===o?t:t+1,s,e),this.processRowsHeaderAdd(t,s)}moveCellsHorizontally(e,t,o){return this.processCellsToMove((t=>t.col>=e),(o=>o.col!==e||-1!==t),(e=>({type:"UPDATE_CELL",sheet:o,col:e.col+t,row:e.row,content:e.content,border:e.border,style:e.style,format:e.format})),o)}moveCellVerticallyBatched(e,t,o){return this.processCellsToMove((({row:t})=>t>=e),(({row:e})=>e>t),(s=>({type:"UPDATE_CELL",sheet:this.workbook.sheets[o].id,col:s.col,row:s.row-(t-e+1),content:s.content,border:s.border,style:s.style,format:s.format})),o)}moveCellsVertically(e,t,o){return this.processCellsToMove((t=>t.row>=e),(o=>o.row!==e||-1!==t),(e=>({type:"UPDATE_CELL",sheet:o,col:e.col,row:e.row+t,content:e.content,border:e.border,style:e.style,format:e.format})),o)}manageColumnsHeaders(e,t,o){const s=[];let n=0,i=0;const r=this.workbook.sheets[o];for(let o in r.cols){if(parseInt(o,10)===e){if(-1===t)continue;{const{size:e}=r.cols[i];for(let o=0;o<t;o++)s.push({name:b(i),size:e,start:n,end:n+e}),n+=e,i++}}const{size:a}=r.cols[o];s.push({name:b(i),size:a,start:n,end:n+a}),n+=a,i++}this.history.updateState(["sheets",o,"cols"],s)}processRowsHeaderDelete(e,t){const o=[];let s=0,n=0;const i=this.workbook.sheets[t],r=i.rows.map((e=>e.cells));for(let t in i.rows){const a=i.rows[t],{size:l}=a;parseInt(t,10)!==e&&(n++,o.push({start:s,end:s+l,size:l,cells:r.shift(),name:String(n)}),s+=l)}this.history.updateState(["sheets",t,"rows"],o)}processRowsHeaderAdd(e,t){const o=[];let s=0,n=0,i=0;const r=this.workbook.activeSheet.rows.map((e=>e.cells));for(let a in this.workbook.activeSheet.rows){const{size:l}=this.workbook.activeSheet.rows[i];(parseInt(a,10)<e||parseInt(a,10)>=e+t)&&i++,n++,o.push({start:s,end:s+l,size:l,cells:r.shift(),name:String(n)}),s+=l}this.history.updateState(["activeSheet","rows"],o)}addEmptyRow(){const e=this.workbook.activeSheet.rows[this.workbook.activeSheet.rows.length-1].end,t=(this.workbook.activeSheet.rows.length+1).toString(),o=this.workbook.activeSheet.rows.slice();o.push({start:e,end:e+0,size:0,name:t,cells:{}});this.history.updateState(["activeSheet","rows"],o)}updateColumnsFormulas(e,t,o){return this.visitFormulas(this.workbook.sheets[o].name,((o,s)=>o.includes(":")?this.updateColumnsRange(o,s,e,t):this.updateColumnsRef(o,s,e,t)))}updateRowsFormulas(e,t,o){return this.visitFormulas(this.workbook.sheets[o].name,((o,s)=>o.includes(":")?this.updateRowsRange(o,s,e,t):this.updateRowsRef(o,s,e,t)))}processCellsToMove(e,t,o,s){const n=[],i=[],r=this.workbook.sheets[s];for(let s in r.cells){let a=r.cells[s];if(e(a)){const[e,l]=E(s);n.push({type:"CLEAR_CELL",sheet:r.id,col:e,row:l}),t(a)&&i.push(o(a))}}for(let e of n)this.dispatch(e.type,e);for(let e of i)this.dispatch(e.type,e)}updateCell(e,t,o,s){const n=this.workbook.sheets[e],i=n.rows[o].cells[t],r=i&&i.xc||w(t,o),a="content"in s,l=s.content?s.content.replace(fa,""):"";let c=a?l:i&&i.content||"";const h="style"in s?s.style:i&&i.style||0,u="border"in s?s.border:i&&i.border||0;let d="format"in s?s.format:i&&i.format||"";if(!(c||h||u||d))return void(i&&(this.history.updateSheet(n,["cells",r],void 0),this.history.updateSheet(n,["rows",o,"cells",t],void 0)));const p=!i&&l||a&&i&&i.content!==l;let g;if(i&&!p)g={col:t,row:o,xc:r,content:c,value:i.value,type:i.type},"formula"===g.type&&(g.error=i.error,g.pending=i.pending,g.formula=i.formula);else{let e="="===c[0]?"formula":"text",s=c;z(c)&&(s=G(c),e="number",c.includes("%")&&(d=c.includes(".")?"0.00%":"0%"));let n=ae(c);n&&(e="date",s=n,c=he(n));const i=c.toUpperCase();if("TRUE"===i&&(s=!0),"FALSE"===i&&(s=!1),g={col:t,row:o,xc:r,content:c,value:s,type:e},"formula"===g.type){g.error=void 0;try{let e=ga(g.content||""),t=ha(e);g.formula={compiledFormula:t,dependencies:e.dependencies,text:e.text}}catch(e){g.value="#BAD_EXPR",g.error=e.message||Q("Invalid Expression")}}}h&&(g.style=h),u&&(g.border=u),d&&(g.format=d),this.history.updateSheet(n,["cells",r],g),this.history.updateSheet(n,["rows",o,"cells",t],g)}generateSheetName(){let e=1;const t=this.getSheets().map((e=>e.name)),o=Q("Sheet");let s=`${o}${e}`;for(;t.includes(s);)s=`${o}${e}`,e++;return s}createSheet(e,t,o,s){const n={id:e,name:t,cells:{},colNumber:o,rowNumber:s,cols:va(o),rows:ba(s),merges:{},mergeCellMap:{}},i=this.workbook.visibleSheets.slice(),r=i.findIndex((e=>this.workbook.activeSheet.id===e));i.splice(r+1,0,n.id);const a=this.workbook.sheets;return this.history.updateState(["visibleSheets"],i),this.history.updateState(["sheets"],Object.assign({},a,{[n.id]:n})),n.id}moveSheet(e,t){const o=this.workbook.visibleSheets.slice(),s=o.findIndex((t=>t===e)),n=o.splice(s,1);o.splice(s+("left"===t?-1:1),0,n[0]),this.history.updateState(["visibleSheets"],o)}isRenameAllowed(e){if(e.interactive)return{status:"SUCCESS"};const t=e.name&&e.name.trim().toLowerCase();return t&&-1===this.workbook.visibleSheets.findIndex((e=>this.workbook.sheets[e].name.toLowerCase()===t))?{status:"SUCCESS"}:{status:"CANCELLED",reason:8}}interactiveRenameSheet(e,t){const o=this.getSheetName(e);this.ui.editText(t,o,(t=>{if(!t)return;const o=this.dispatch("RENAME_SHEET",{sheet:e,name:t}),s=this.getSheetName(e);"CANCELLED"===o.status&&s!==t&&this.interactiveRenameSheet(e,Q("Please enter a valid sheet name"))}))}renameSheet(e,t){const o=this.workbook.sheets[e],s=o.name;this.history.updateSheet(o,["name"],t.trim());const n=Object.assign({},this.sheetIds);n[t]=o.id,delete n[s],this.history.updateLocalState(["sheetIds"],n),this.visitAllFormulasSymbols((e=>{let[t,n]=e.split("!").reverse();return n&&(n=$(n),n===s)?t.includes(":")?this.updateRange(t,0,0,o.id):this.updateReference(t,0,0,o.id):e}))}duplicateSheet(e,t,o){const s=this.workbook.sheets[e],n=JSON.parse(JSON.stringify(s));n.id=t,n.name=o;const i=this.workbook.visibleSheets.slice(),r=i.findIndex((t=>t===e));i.splice(r+1,0,n.id),this.history.updateState(["visibleSheets"],i),this.history.updateState(["sheets"],Object.assign({},this.workbook.sheets,{[n.id]:n}));const a=Object.assign({},this.sheetIds);a[n.name]=n.id,this.history.updateLocalState(["sheetIds"],a),this.dispatch("ACTIVATE_SHEET",{from:this.workbook.activeSheet.id,to:t})}interactiveDeleteSheet(e){this.ui.askConfirmation(Q("Are you sure you want to delete this sheet ?"),(()=>{this.dispatch("DELETE_SHEET",{sheet:e})}))}deleteSheet(e){const t=this.workbook.sheets[e].name,o=Object.assign({},this.workbook.sheets);delete o[e],this.history.updateState(["sheets"],o);const s=this.workbook.visibleSheets.slice(),n=s.findIndex((t=>t===e));s.splice(n,1),this.history.updateState(["visibleSheets"],s);const i=Object.assign({},this.sheetIds);delete i[t],this.history.updateLocalState(["sheetIds"],i),this.visitAllFormulasSymbols((e=>{let[,o]=e.split("!").reverse();return o&&(o=$(o),o===t)?"#REF":e})),this.getActiveSheet()===e&&this.dispatch("ACTIVATE_SHEET",{from:e,to:s[Math.max(0,n-1)]})}clearZones(e,t){const o=this.workbook.activeSheet.cells;for(let s of t)for(let t=s.left;t<=s.right;t++)for(let n=s.top;n<=s.bottom;n++){w(t,n)in o&&this.dispatch("UPDATE_CELL",{sheet:e,content:"",col:t,row:n})}}updateRange(e,t,o,s){let[n,i]=e.split(":");return n=this.updateReference(n,t,o,s,!0,!1),i=this.updateReference(i,t,o,s,!0,!1),"#REF"===n||"#REF"===i?"#REF":(i=i.split("!").pop(),`${n}:${i}`)}updateReference(e,t,o,s,n=!0,i=!0){const r=e.replace(/\$/g,"");let[a,l]=E(r);const c=e.startsWith("$"),h=e.includes("$",1);if(a+=c&&n?0:t,l+=h&&n?0:o,a<0||l<0||i&&(a>=this.getters.getNumberCols(s||this.getters.getActiveSheet())||l>=this.getters.getNumberRows(s||this.getters.getActiveSheet())))return"#REF";const u=s&&U(this.getters.getSheetName(s));return(u?`${u}!`:"")+(c?"$":"")+b(a)+(h?"$":"")+String(l+1)}visitAllFormulasSymbols(e){for(let t in this.workbook.sheets){const o=this.workbook.sheets[t];for(let[t,s]of Object.entries(o.cells))if("formula"===s.type){const n=da(s.content).map((t=>"SYMBOL"===t.type&&Xr.test(t.value)?e(t.value,o.id):t.value)).join("");if(n!==s.content){const[e,s]=E(t);this.dispatch("UPDATE_CELL",{sheet:o.id,col:e,row:s,content:n})}}}}visitFormulas(e,t){this.visitAllFormulasSymbols(((o,s)=>{let[n,i]=o.split("!").reverse();if(i){if(i=$(i),i===e)return t(n,i)}else if(this.sheetIds[e]===s)return t(n,void 0);return o}))}import(e){for(let t of e.sheets)this.sheetIds[t.name]=t.id;for(let t of e.sheets)this.importSheet(t);this.workbook.activeSheet=this.workbook.sheets[e.activeSheet]}importSheet(e){let{sheets:t,visibleSheets:o}=this.workbook;const s=e.name||`Sheet${Object.keys(t).length+1}`,{colNumber:n,rowNumber:i}=function(e){const t=Object.keys(e.cells).map(E);return{rowNumber:Math.max(e.rowNumber,...new Set(t.map((([e,t])=>t+1)))),colNumber:Math.max(e.colNumber,...new Set(t.map((([e,t])=>e+1))))}}(e),r={id:e.id,name:s,cells:{},colNumber:n,rowNumber:i,cols:Ea(e.cols||{},n),rows:wa(e.rows||{},i),merges:{},mergeCellMap:{}};o=o.slice(),o.push(r.id),this.history.updateState(["visibleSheets"],o),this.history.updateState(["sheets"],Object.assign({},t,{[r.id]:r}));for(let t in e.cells){const o=e.cells[t],[s,n]=E(t);this.updateCell(e.id,s,n,o)}}export(e){e.sheets=this.workbook.visibleSheets.map((e=>{const t=this.workbook.sheets[e],o={};for(let[e,s]of Object.entries(t.cells))o[e]={content:s.content,border:s.border,style:s.style,format:s.format};return{id:t.id,name:t.name,colNumber:t.colNumber,rowNumber:t.rowNumber,rows:Sa(t.rows),cols:La(t.cols),merges:[],cells:o,conditionalFormats:[],figures:[]}})),e.activeSheet=this.workbook.activeSheet.id}}function va(e){const t=[];let o=0;for(let s=0;s<e;s++){const e={start:o,end:o+u,size:u,name:b(s)};t.push(e),o=e.end}return t}function ba(e){const t=[];let o=0;for(let s=0;s<e;s++){const e={start:o,end:o+d,size:d,name:String(s+1),cells:{}};t.push(e),o=e.end}return t}function Ea(e,t){const o=[];let s=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||u,i={start:s,end:s+t,size:t,name:b(n)};o.push(i),s=i.end}return o}function wa(e,t){const o=[];let s=0;for(let n=0;n<t;n++){const t=e[n]&&e[n].size||d,i={start:s,end:s+t,size:t,name:String(n+1),cells:{}};o.push(i),s=i.end}return o}function La(e){const t={};for(let o in e){const s=e[o];s.size!==u&&(t[o]={size:s.size})}return t}function Sa(e){const t={};for(let o in e){const s=e[o];s.size!==d&&(t[o]={size:s.size})}return t}ma.getters=["applyOffset","getColsZone","getRowsZone","getCell","getCellText","zoneToXC","getActiveSheet","getSheetName","getSheetIdByName","getSheets","getCol","getRow","getColCells","getNumberCols","getNumberRows","getGridSize","shouldShowFormulas","getRangeValues","getRangeFormattedValues"];class Ca extends dn{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheet="",this.currentContent=""}beforeHandle(e){if("ACTIVATE_SHEET"===e.type)"selecting"!==this.mode&&this.stopEdition()}handle(e){switch(e.type){case"START_COMPOSER_SELECTION":this.mode="selecting",this.dispatch("SET_SELECTION",{zones:this.getters.getSelectedZones(),anchor:this.getters.getPosition()});break;case"STOP_COMPOSER_SELECTION":"selecting"===this.mode&&(this.mode="editing");break;case"START_EDITION":this.startEdition(e.text);break;case"STOP_EDITION":e.cancel?this.cancelEdition():this.stopEdition();break;case"SET_CURRENT_CONTENT":this.currentContent=e.content;break;case"SELECT_CELL":case"MOVE_POSITION":"editing"===this.mode&&this.stopEdition()}}getEditionMode(){return this.mode}getCurrentContent(){return this.currentContent}getEditionSheet(){return this.sheet}startEdition(e){if(!e){const t=this.getters.getActiveCell();e=t&&t.content||""}this.mode="editing",this.currentContent=e||"",this.dispatch("REMOVE_ALL_HIGHLIGHTS");const[t,o]=this.getters.getPosition();this.col=t,this.row=o,this.sheet=this.getters.getActiveSheet()}stopEdition(){if("inactive"!==this.mode){this.cancelEdition();let e=w(this.col,this.row);const{mergeCellMap:t,merges:o,cells:s}=this.getters.getSheets().find((e=>e.id===this.sheet));if(e in t){e=o[t[e]].topLeft}let n=this.currentContent;this.currentContent="";const i=s[e];if(!(i?i.content!==n:""!==n))return;const[r,a]=E(e);if(n){if(n.startsWith("=")){const e=_r(n),t=e.filter((e=>"LEFT_PAREN"===e.type)).length,o=e.filter((e=>"RIGHT_PAREN"===e.type)).length,s=t-o;s>0&&(n+=new Array(s).fill(")").join(""))}this.dispatch("UPDATE_CELL",{sheet:this.sheet,col:r,row:a,content:n})}else this.dispatch("UPDATE_CELL",{sheet:this.sheet,content:"",col:r,row:a});this.getters.getActiveSheet()!==this.sheet&&this.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:this.sheet})}}cancelEdition(){this.mode="inactive",this.dispatch("REMOVE_ALL_HIGHLIGHTS")}}function*ya(e){for(let t of e)yield t}Ca.layers=[1],Ca.getters=["getEditionMode","getCurrentContent","getEditionSheet"],Ca.modes=["normal","readonly"];const Ta=un.mapping,xa="Loading...";class Ra extends dn{constructor(e,t,o,s,n){super(e,t,o,s,n),this.isUptodate=new Set,this.loadingCells=0,this.isStarted=!1,this.PENDING=new Set,this.WAITING={},this.COMPUTED=new Set,this.evalContext=n.evalContext}handle(e){switch(e.type){case"START":this.evaluate();break;case"UPDATE_CELL":"content"in e&&this.isUptodate.clear();break;case"EVALUATE_CELLS":if(e.onlyWaiting)for(const e in this.WAITING){const t=new Set(this.WAITING[e]);this.WAITING[e].clear(),this.evaluateCells(ya(t),e)}else{for(const e in this.WAITING)delete this.WAITING[e];this.evaluate()}this.isUptodate.add(this.workbook.activeSheet.id);break;case"UNDO":case"REDO":this.isUptodate.clear()}}finalize(){this.isUptodate.has(this.workbook.activeSheet.id)||(this.evaluate(),this.isUptodate.add(this.workbook.activeSheet.id)),this.loadingCells>0&&this.startScheduler()}evaluateFormula(e,t=this.workbook.activeSheet.id){let o=ga(e);const s=ha(o),n=this.getFormulaParameters((()=>{}));return s(o.dependencies,t,...n)}isIdle(){return 0===this.loadingCells}startScheduler(){if(!this.isStarted){this.isStarted=!0;let e=this.loadingCells;const t=()=>{this.loadingCells!==e&&(this.dispatch("EVALUATE_CELLS",{onlyWaiting:!0}),e=this.loadingCells,0===e&&(this.isStarted=!1)),e>0&&window.setTimeout(t,15)};window.setTimeout(t,5)}}evaluate(){this.COMPUTED.clear(),this.evaluateCells(function*(e){for(let t in e)yield e[t]}(this.workbook.activeSheet.cells),this.workbook.activeSheet.id)}evaluateCells(e,t){const o=this,{COMPUTED:s,PENDING:n,WAITING:i}=this,r=this.getFormulaParameters(h),a={},l=[...e];for(let e of l)"#BAD_EXPR"!==e.value&&(e.error=void 0);for(let e of l)h(e,t);function c(e,t,s){if(e instanceof Error||(e=new Error(e)),n.has(t)&&(n.delete(t),o.loadingCells--),"not ready"===e.message)i[s]||(i[s]=new Set),i[s].add(t),t.pending=!0,t.value=xa;else if(!t.error){t.value="#ERROR";const o=r[2].__lastFnCalled||"";t.error=e.message.replace("[[FUNCTION_NAME]]",o)}}function h(e,t){if("formula"!==e.type||!e.formula)return;const i=e.xc;if(a[t]=a[t]||{},i in a[t])null===a[t][i]&&(e.value="#CYCLE",e.error=Q("Circular reference"));else if(!s.has(e)&&!n.has(e)){a[t][i]=null,e.error=void 0;try{if(r[2].__originCellXC=i,e.formula.compiledFormula.async?(e.value=xa,e.pending=!0,n.add(e),e.formula.compiledFormula(e.formula.dependencies,t,...r).then((t=>{e.value=t,o.loadingCells--,n.has(e)&&(n.delete(e),e.pending=!1,s.add(e))})).catch((o=>c(o,e,t))),o.loadingCells++):(e.value=e.formula.compiledFormula(e.formula.dependencies,t,...r),e.pending=!1),Array.isArray(e.value))throw new Error(Q("This formula depends on invalid values"));e.error=void 0}catch(o){c(o,e,t)}a[t][i]=!0}}}getFormulaParameters(e){const t=Object.assign(Object.create(Ta),this.evalContext,{getters:this.getters}),o=this.workbook.sheets,s=this.PENDING;function n(t,o){if(t.formula&&t.formula.compiledFormula.async&&t.error&&!s.has(t))throw new Error(Q("This formula depends on invalid values"));if(e(t,o),t.error)throw new Error(Q("This formula depends on invalid values"));return t.value}function i(e,t,s){const i=o[s];let[r,a]=E(e),[l,c]=E(t);if(l=Math.min(l,i.colNumber-1),c=Math.min(c,i.rowNumber-1),r>l){const e=r;r=l,l=e}if(a>c){const e=a;a=c,c=e}const h=A({left:r,top:a,right:l,bottom:c},i,(e=>n(e,s)));for(const e of h)for(const t of e)if(t===xa)throw new Error("not ready");return h}return[function(e,s,i,r,a){const l=s[e],[c,h]=l.split("!").reverse(),u=h?t.getters.getSheetIdByName(h):i,d=L(l);if(d.top>d.bottom||d.left>d.right)throw new Error(Q("invalid range %s:%s",w(d.left,d.top),w(d.right,d.bottom)));if(d.bottom!==d.top||d.left!==d.right)throw new Error(Q("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",r.toString(),a.toString()));return function(e,t){let s;const i=o[t];if(!i)throw new Error(Q("Invalid sheet name"));if(s=i.cells[e.toUpperCase().replace(/\$/g,"")],!s||""===s.content)return null;const r=n(s,t);if(r===xa)throw new Error("not ready");return r}(c,u)},function(e,o,s){const n=o[e],[r,a]=n.split("!").reverse(),l=a?t.getters.getSheetIdByName(a):s;if(o[e]&&!o[e].includes(":"))return i(r,r,l);{const[e,t]=r.split(":");return i(e,t,l)}},t]}}Ra.getters=["evaluateFormula","isIdle"],Ra.modes=["normal","readonly"];class Ma extends dn{constructor(){super(...arguments),this.selectedFigureId=null,this.figures={},this.sheetFigures={}}handle(e){switch(e.type){case"DELETE_SHEET":this.deleteSheet(e.sheet);break;case"CREATE_FIGURE":this.history.updateLocalState(["figures",e.figure.id],e.figure);const t=(this.sheetFigures[e.sheet]||[]).slice();t.push(e.figure),this.history.updateLocalState(["sheetFigures",e.sheet],t);break;case"UPDATE_FIGURE":void 0!==e.x&&this.history.updateLocalState(["figures",e.id,"x"],Math.max(e.x,0)),void 0!==e.y&&this.history.updateLocalState(["figures",e.id,"y"],Math.max(e.y,0)),void 0!==e.width&&this.history.updateLocalState(["figures",e.id,"width"],e.width),void 0!==e.height&&this.history.updateLocalState(["figures",e.id,"height"],e.height),void 0!==e.data&&this.history.updateLocalState(["figures",e.id,"data"],e.data);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"DELETE_FIGURE":this.history.updateLocalState(["figures",e.id],void 0);for(let t in this.sheetFigures){let o=this.sheetFigures[t].findIndex((t=>t.id===e.id));if(o>-1){const e=this.sheetFigures[t].slice();e.splice(o,1),this.history.updateLocalState(["sheetFigures",t],e),this.selectedFigureId=null}}break;case"EVALUATE_CELLS":break;default:this.selectedFigureId=null}}deleteSheet(e){for(let t of this.sheetFigures[e]||[])this.history.updateLocalState(["figures",t.id],void 0);const t=Object.assign({},this.sheetFigures);delete t[e],this.history.updateLocalState(["sheetFigures"],t)}getFigures(e){const t=[],o=this.sheetFigures[this.workbook.activeSheet.id]||[],{offsetX:s,offsetY:n,width:i,height:r}=e;for(let e of o)e.x>=s+i||e.x+e.width<=s||e.y>=n+r||e.y+e.height<=n||t.push(e);return t}getSelectedFigureId(){return this.selectedFigureId}getFigure(e){return this.figures[e]}import(e){for(let t of e.sheets){const e=[];for(let o of t.figures)this.figures[o.id]=o,e.push(o);this.sheetFigures[t.id]=e}}export(e){for(let t of e.sheets)t.figures=this.sheetFigures[t.id]||[]}}Ma.getters=["getFigures","getSelectedFigureId","getFigure"];const Aa={top:["top"],left:["left"],right:["right"],bottom:["bottom"],all:["top","left","bottom","right"]},Na={fillColor:"white",textColor:"black",fontSize:11};class ka extends dn{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d"),this.styles={},this.borders={},this.nextId=1}handle(e){switch(e.type){case"SET_FORMATTING":e.style&&this.setStyle(e.sheet,e.target,e.style),e.border&&this.setBorder(e.sheet,e.target,e.border);break;case"CLEAR_FORMATTING":this.clearFormatting(e.target);break;case"SET_FORMATTER":this.setFormatter(e.sheet,e.target,e.formatter);break;case"SET_DECIMAL":this.setDecimal(e.sheet,e.target,e.step);break;case"ADD_COLUMNS":const t="before"===e.position?e.column-1:e.column,o=t+e.quantity+1;this.onAddElements(t,o,!0,"before"===e.position);break;case"ADD_ROWS":const s="before"===e.position?e.row-1:e.row,n=s+e.quantity+1;this.onAddElements(s,n,!1,"before"===e.position)}}getCellWidth(e){const t=e.style||0,o=this.getters.getCellText(e);return this.getTextWidth(o,t)}getTextWidth(e,t=0){const o=this.styles[t],s=o.italic?"italic ":"",n=o.bold?"bold":"400",i=o.fontSize||10,r=Qn[i];return this.ctx.font=`${s}${n} ${r}px 'Roboto', arial`,this.ctx.measureText(e).width}getCellHeight(e){const t=this.styles[e&&e.style||0].fontSize||10;return Qn[t]}getCellStyle(e){return e.style?this.styles[e.style]:{}}getCellBorder(e){return e.border?this.borders[e.border]:null}getCurrentStyle(){const e=this.getters.getActiveCell();return e&&e.style?this.styles[e.style]:{}}setStyle(e,t,o){for(let e of t)for(let t=e.left;t<=e.right;t++)for(let s=e.top;s<=e.bottom;s++)this.setStyleToCell(t,s,o)}setStyleToCell(e,t,o){const s=this.getters.getCell(e,t),n=s&&s.style?this.styles[s.style]:{},i=Object.assign({},n,o),r=this.registerStyle(i);this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:e,row:t,style:r})}registerStyle(e){const t=O(e);for(let e in this.styles)if(O(this.styles[e])===t)return parseInt(e,10);const o=this.nextId++;return this.styles[o]=e,o}setBorder(e,t,o){const s={};for(let n of t)this.aggregateBorderCommands(e,n,o,s);for(let[t,o]of Object.entries(s)){const[s,n]=E(t),i=this.getters.getCell(s,n);(i&&i.border||0)!==o&&this.dispatch("UPDATE_CELL",{sheet:e,col:s,row:n,border:o})}}aggregateBorderCommands(e,t,o,s){if("clear"===o){for(let o=t.top;o<=t.bottom;o++)for(let n=t.left;n<=t.right;n++)this.clearBorder(e,n,o,s);return}if("external"===o)return this.aggregateBorderCommands(e,t,"left",s),this.aggregateBorderCommands(e,t,"right",s),this.aggregateBorderCommands(e,t,"top",s),void this.aggregateBorderCommands(e,t,"bottom",s);if("hv"===o)return this.aggregateBorderCommands(e,t,"h",s),void this.aggregateBorderCommands(e,t,"v",s);const{left:n,top:i,right:r,bottom:a}=t;if("h"===o){for(let t=i+1;t<=a;t++)this.aggregateBorderCommands(e,{left:n,top:t,right:r,bottom:t},"top",s);return}if("v"===o){for(let t=n+1;t<=r;t++)this.aggregateBorderCommands(e,{left:t,top:i,right:t,bottom:a},"left",s);return}const l={};for(let e of Aa[o])l[e]=["thin","#000"];const c=function(e,t){const{left:o,right:s,top:n,bottom:i}=e;switch(t){case"left":return{left:o,top:n,right:o,bottom:i};case"top":return{left:o,top:n,right:s,bottom:n};case"right":return{left:s,top:n,right:s,bottom:i};case"bottom":return{left:o,top:i,right:s,bottom:i}}return e}(t,o);for(let t=c.top;t<=c.bottom;t++)for(let o=c.left;o<=c.right;o++)this.setBorderToMap(e,o,t,l,s)}clearBorder(e,t,o,s){const n=this.getters.getCell(t,o);s[n?n.xc:w(t,o)]=0,t>0&&this.clearSide(e,t-1,o,"right",s),o>0&&this.clearSide(e,t,o-1,"bottom",s),t<this.workbook.activeSheet.cols.length-1&&this.clearSide(e,t+1,o,"left",s),o<this.workbook.activeSheet.rows.length-1&&this.clearSide(e,t,o+1,"top",s)}clearSide(e,t,o,s,n){const i=this.getters.getCell(t,o),r=i?i.xc:w(t,o),a=r in n?n[r]:i&&i.border?i.border:0,l=this.borders[a]||{};if(s in l){const e=Object.assign({},l);delete e[s],n[r]=this.registerBorder(e)}}setBorderToMap(e,t,o,s,n){const i=this.getters.getCell(t,o),r=i?i.xc:w(t,o),a=r in n?n[r]:i&&i.border?i.border:0,l=this.borders[a]||{},c=Object.assign({},l,s),h=this.registerBorder(c);n[r]=h}registerBorder(e){if(!Object.keys(e).length)return 0;const t=O(e);for(let e in this.borders)if(O(this.borders[e])===t)return parseInt(e,10);const o=this.nextId++;return this.borders[o]=e,o}clearFormatting(e){for(let t of e)for(let e=t.left;e<=t.right;e++)for(let o=t.top;o<=t.bottom;o++)this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:e,row:o,style:0,border:0})}setFormatter(e,t,o){for(let s of t)for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++)this.dispatch("UPDATE_CELL",{sheet:e,col:n,row:t,format:o})}setDecimal(e,t,o){const s=this.searchNumberFormat(t);if(void 0!==s){const n=this.changeDecimalFormat(s,o);this.setFormatter(e,t,n)}}searchNumberFormat(e){for(let t of e)for(let e=t.top;e<=t.bottom;e++)for(let o=t.left;o<=t.right;o++){const t=this.getters.getCell(o,e);if(t&&("number"===t.type||"formula"===t.type&&"number"==typeof t.value))return t.format||this.setDefaultNumberFormat(t.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 o=Math.sign(t),s=e.split(";");let n=[];for(let e of s){const t=e.indexOf("."),s=e.toUpperCase().indexOf("E");let i;const r=s>-1?e.slice(0,s):e,a=t>-1?r.slice(t).match(/0/g).length:0,l=r.lastIndexOf("0");l>-1?o>0?i=a<20?e.slice(0,l+1)+(0===a?".0":"0")+e.slice(l+1):e:a>0?(i=e.slice(0,l)+e.slice(l+1),1===a&&(i=i.slice(0,t)+i.slice(t+1))):i=e:i=e,n.push(i)}return n.join(";")}onAddElements(e,t,o,s){const n=o?this.workbook.activeSheet.rows.length:this.workbook.activeSheet.cols.length,i=e+1;for(let r=0;r<n;r++){const n=o?w(i,r):w(r,i);if(this.getters.isInMerge(n))continue;const a={};let l=o?this.getFormat(w(e,r)):this.getFormat(w(r,e)),c=o?this.getFormat(w(t,r)):this.getFormat(w(r,t));if(s?(c.style&&(a.style=c.style),c.format&&(a.format=c.format)):(l.style&&(a.style=l.style),l.format&&(a.format=l.format)),c.border&&c.border===l.border&&(a.border=c.border),0!==Object.keys(a).length)for(let e=i;e<t;e++)this.dispatch("UPDATE_CELL",{sheet:this.workbook.activeSheet.id,col:o?e:r,row:o?r:e,style:a.style,border:a.border,format:a.format})}}getFormat(e){const t={};return(e=this.getters.getMainCell(e))in this.workbook.activeSheet.cells&&(this.workbook.activeSheet.cells[e].border&&(t.border=this.workbook.activeSheet.cells[e].border),this.workbook.activeSheet.cells[e].style&&(t.style=this.workbook.activeSheet.cells[e].style),this.workbook.activeSheet.cells[e].format&&(t.format=this.workbook.activeSheet.cells[e].format)),t}import(e){e.styles&&(this.styles=e.styles),this.styles[0]=Object.assign({},Na,this.styles[0]),e.borders&&(this.borders=e.borders);let t=1;for(let e in this.styles)t=Math.max(e,t);for(let e in this.borders)t=Math.max(e,t);this.nextId=t+1}export(e){e.styles=this.styles,e.borders=this.borders}}ka.getters=["getCurrentStyle","getCellWidth","getTextWidth","getCellHeight","getCellStyle","getCellBorder"];class _a extends dn{constructor(){super(...arguments),this.highlights=[],this.color="#000",this.highlightSelectionEnabled=!1,this.pendingHighlights=[]}handle(e){switch(e.type){case"ADD_HIGHLIGHTS":this.addHighlights(e.ranges);break;case"REMOVE_ALL_HIGHLIGHTS":this.highlights=[];break;case"REMOVE_HIGHLIGHTS":this.removeHighlights(e.ranges);break;case"SELECT_CELL":case"SET_SELECTION":this.highlightSelectionEnabled&&this.highlightSelection();break;case"START_SELECTION_EXPANSION":this.color=v();break;case"HIGHLIGHT_SELECTION":this.highlightSelectionEnabled=e.enabled,e.enabled||this.dispatch("RESET_PENDING_HIGHLIGHT");break;case"RESET_PENDING_HIGHLIGHT":this.pendingHighlights=[];break;case"ADD_PENDING_HIGHLIGHTS":this.addPendingHighlight(e.ranges);break;case"SET_HIGHLIGHT_COLOR":this.color=e.color}}getHighlights(){return this.highlights}addHighlights(e){let t=this.prepareHighlights(e);this.highlights=this.highlights.concat(t)}addPendingHighlight(e){let t=this.prepareHighlights(e);this.pendingHighlights=this.pendingHighlights.concat(t)}prepareHighlights(e){return 0===Object.keys(e).length?[]:Object.keys(e).map((t=>{const[o,s]=t.split("!").reverse(),n=s?this.getters.getSheetIdByName(s):this.getters.getActiveSheet();return{zone:this.getters.expandZone(L(o)),color:e[t],sheet:n}})).filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.workbook.activeSheet.rows.length&&e.zone.right<this.workbook.activeSheet.cols.length))}removeHighlights(e){const t=this.getters.getActiveSheet(),o={};for(let[s,n]of Object.entries(e)){const[e,i]=s.split("!").reverse(),r=this.getters.getSheetIdByName(i);o[r||t]=Object.assign({[e]:n},o[r||t]||{})}this.highlights=this.highlights.filter((e=>!(o[e.sheet]&&o[e.sheet][this.getters.zoneToXC(e.zone)]===e.color)))}highlightSelection(){this.removePendingHighlights();const e=this.getters.getSelectedZones().filter((e=>!this.isHighlighted(e))),t={};let o=this.color;for(const s of e)t[this.getters.zoneToXC(s)]=o,o=v();this.dispatch("ADD_HIGHLIGHTS",{ranges:t}),this.dispatch("ADD_PENDING_HIGHLIGHTS",{ranges:t})}isHighlighted(e){return!!this.highlights.find((t=>y(t.zone,e)))}removePendingHighlights(){const e={},[t,o]=this.pendingHighlights.reduce((([e,t],o)=>this.getters.isSelected(o.zone)?[[...e,o],t]:[e,[...t,o]]),[[],[]]);for(const{zone:t,color:s}of o)e[this.getters.zoneToXC(t)]=s;this.dispatch("REMOVE_HIGHLIGHTS",{ranges:e}),this.pendingHighlights=t}drawGrid(e){const{ctx:t,viewport:o,thinLineWidth:s}=e,n=this.getters.getActiveSheet(),i=3*s;t.lineWidth=i;for(let e of this.highlights.filter((e=>e.sheet===n))){const[s,n,r,a]=this.getters.getRect(e.zone,o);r>0&&a>0&&(t.strokeStyle=e.color,t.strokeRect(s+i/2,n+i/2,r-i,a-i),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(s+i,n+i,r-2*i,a-2*i))}}}_a.modes=["normal","readonly"],_a.layers=[1],_a.getters=["getHighlights"];class Ia extends dn{constructor(){super(...arguments),this.nextId=1,this.pending=null}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"PASTE":return this.isPasteAllowed(e.target,t);case"ADD_MERGE":return this.isMergeAllowed(e.zone,t);default:return{status:"SUCCESS"}}}beforeHandle(e){switch(e.type){case"REMOVE_COLUMNS":this.exportAndRemoveMerges(e.sheet,(t=>N(t,e.columns)),!0);break;case"REMOVE_ROWS":this.exportAndRemoveMerges(e.sheet,(t=>k(t,e.rows)),!1);break;case"ADD_COLUMNS":const t="before"===e.position?e.column:e.column+1;this.exportAndRemoveMerges(e.sheet,(o=>_(o,t,e.quantity)),!0);break;case"ADD_ROWS":const o="before"===e.position?e.row:e.row+1;this.exportAndRemoveMerges(e.sheet,(t=>I(t,o,e.quantity)),!1)}}handle(e){switch(e.type){case"ADD_MERGE":e.interactive?this.interactiveMerge(e.sheet,e.zone):this.addMerge(e.sheet,e.zone);break;case"REMOVE_MERGE":this.removeMerge(e.sheet,e.zone);break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);break;case"PASTE_CELL":const t=w(e.originCol,e.originRow);this.isMainCell(t,e.sheet)&&this.duplicateMerge(t,e.col,e.row,e.sheet,e.cut)}this.pending&&(this.importMerges(this.pending.sheet,this.pending.merges),this.history.updateLocalState(["pending"],null))}isMergeDestructive(e){const{left:t,right:o,top:s,bottom:n}=e;for(let e=s;e<=n;e++){const n=this.workbook.activeSheet.rows[e];for(let i=t;i<=o;i++)if(i!==t||e!==s){const e=n.cells[i];if(e&&e.content)return!0}}return!1}doesIntersectMerge(e){const{left:t,right:o,top:s,bottom:n}=e;for(let e=s;e<=n;e++)for(let s=t;s<=o;s++){const t=w(s,e);if(this.workbook.activeSheet.mergeCellMap[t])return!0}return!1}expandZone(e){let{left:t,right:o,top:s,bottom:n}=e;const i=this.workbook.activeSheet;let r={left:t,right:o,top:s,bottom:n};for(let e in i.merges){const t=i.merges[e];T(t,r)&&(r=C(t,r))}return y(r,e)?r:this.expandZone(r)}isInMerge(e){return e in this.workbook.activeSheet.mergeCellMap}isMainCell(e,t){const o=this.workbook.sheets[t].merges;for(let t in o)if(o[t].topLeft===e)return!0;return!1}getMainCell(e){if(!this.isInMerge(e))return e;const t=this.workbook.activeSheet,o=t.mergeCellMap[e];return t.merges[o].topLeft}isMergeAllowed(e,t){return!t&&this.isMergeDestructive(e)?{status:"CANCELLED",reason:2}:{status:"SUCCESS"}}addMerge(e,t){const o=this.workbook.sheets[e],{left:s,right:n,top:i,bottom:r}=t,a=w(s,i);if(a===w(n,r))return;const l=this.getters.getCell(s,i);let c=this.nextId++;this.history.updateState(["sheets",e,"merges",c],{id:c,left:s,top:i,right:n,bottom:r,topLeft:a});let h=new Set;for(let t=i;t<=r;t++)for(let r=s;r<=n;r++){const n=w(r,t);r===s&&t===i||this.dispatch("UPDATE_CELL",{sheet:e,col:r,row:t,style:l?l.style:void 0,content:void 0}),o.mergeCellMap[n]&&h.add(o.mergeCellMap[n]),this.history.updateState(["sheets",e,"mergeCellMap",n],c)}this.applyBorderMerge(t,e);for(let t of h){const{top:s,bottom:n,left:i,right:r}=o.merges[t];for(let t=s;t<=n;t++)for(let s=i;s<=r;s++){const n=w(s,t);o.mergeCellMap[n]!==c&&(this.history.updateState(["sheets",e,"mergeCellMap",n],void 0),this.dispatch("CLEAR_CELL",{sheet:e,col:s,row:t}))}this.history.updateState(["sheets",e,"merges",t],void 0)}}applyBorderMerge(e,t){const{left:o,right:s,top:n,bottom:i}=e,r=this.getters.getCell(o,n),a=this.getters.getCell(s,i)||r,l=r?this.getters.getCellBorder(r):null,c=(a?this.getters.getCellBorder(a):null)||l;if(this.dispatch("SET_FORMATTING",{sheet:t,target:[{left:o,right:s,top:n,bottom:i}],border:"clear"}),c&&c.right){const e=[{left:s,right:s,top:n,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"right"})}if(l&&l.left){const e=[{left:o,right:o,top:n,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"left"})}if(l&&l.top){const e=[{left:o,right:s,top:n,bottom:n}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"top"})}if(c&&c.bottom){const e=[{left:o,right:s,top:i,bottom:i}];this.dispatch("SET_FORMATTING",{sheet:t,target:e,border:"bottom"})}}removeMerge(e,t){const{left:o,top:s,bottom:n,right:i}=t;let r=w(o,s);const a=this.workbook.sheets[e].mergeCellMap[r];if(!y(t,this.workbook.sheets[e].merges[a]))throw new Error(Q("Invalid merge zone"));this.history.updateState(["sheets",e,"merges",a],void 0);for(let t=s;t<=n;t++)for(let s=o;s<=i;s++){const o=w(s,t);this.history.updateState(["sheets",e,"mergeCellMap",o],void 0)}}interactiveMerge(e,t){const o=this.dispatch("ADD_MERGE",{sheet:e,zone:t});"CANCELLED"===o.status&&2===o.reason&&this.ui.askConfirmation(Q("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),(()=>{this.dispatch("ADD_MERGE",{sheet:e,zone:t,force:!0})}))}duplicateMerge(e,t,o,s,n){const i=this.workbook.sheets[s].mergeCellMap[e],r=this.workbook.sheets[s].merges[i],a=this.getters.getNumberCols(s)-1,l=this.getters.getNumberRows(s)-1,c={left:t,top:o,right:F(t+r.right-r.left,0,a),bottom:F(o+r.bottom-r.top,0,l)};n&&this.dispatch("REMOVE_MERGE",{sheet:s,zone:r}),this.dispatch("ADD_MERGE",{sheet:this.workbook.activeSheet.id,zone:c})}removeAllMerges(e){const t=this.workbook.sheets[e];for(let o in t.merges)this.history.updateState(["sheets",e,"merges",o],void 0);for(let o in t.mergeCellMap)this.history.updateState(["sheets",e,"mergeCellMap",o],void 0)}exportAndRemoveMerges(e,t,o){const s=Oa(this.workbook.sheets[e].merges),n=[];for(let e of s){const o=t(e);if(o){const[e,t]=o.split(":");e!==t&&n.push(o)}}this.updateMergesStyles(e,o),this.removeAllMerges(e),this.history.updateLocalState(["pending"],{sheet:e,merges:n})}updateMergesStyles(e,t){const o=this.workbook.sheets[e];for(let e of Object.values(o.merges)){const s=e.topLeft,n=o.cells[s];if(!n)continue;let[i,r]=E(s);t&&e.left!==e.right&&(i+=1),t||e.top===e.bottom||(r+=1),this.dispatch("UPDATE_CELL",{sheet:o.id,col:i,row:r,style:n.style,border:n.border,format:n.format})}}isPasteAllowed(e,t){if(!t){const t=this.getters.getPasteZones(e);for(let e of t)if(this.doesIntersectMerge(e))return{status:"CANCELLED",reason:1}}return{status:"SUCCESS"}}autoFillMerge(e,t,o,s){const n=w(e,t),i=w(o,s),r=this.getters.getActiveSheet();if(this.isInMerge(i)&&!this.isInMerge(n)){const e=this.workbook.sheets[r].mergeCellMap[i],t=this.workbook.sheets[r].merges[e];this.dispatch("REMOVE_MERGE",{sheet:r,zone:t})}this.isMainCell(n,r)&&this.duplicateMerge(n,o,s,r)}import(e){const t=e.sheets||[];for(let e of t){const t=this.workbook.sheets[e.id];t&&e.merges&&this.importMerges(t.id,e.merges)}}importMerges(e,t){for(let o of t){let t=this.nextId++;const[s,n]=o.split(":"),[i,r]=E(s),[a,l]=E(n);this.history.updateState(["sheets",e,"merges",t],{id:t,left:i,top:r,right:a,bottom:l,topLeft:s});for(let o=r;o<=l;o++)for(let s=i;s<=a;s++){const n=w(s,o);this.history.updateState(["sheets",e,"mergeCellMap",n],t)}}}export(e){for(let t of e.sheets){const e=this.workbook.sheets[t.id];t.merges.push(...Oa(e.merges))}}}function Oa(e){return Object.values(e).map((e=>w(e.left,e.top)+":"+w(e.right,e.bottom)))}function Da(e,t){if("formula"===e.type&&t)return"left";if(e.error||e.pending)return"center";switch(typeof e.value){case"object":case"number":return"right";case"boolean":return"center";default:return"left"}}function $a(e,t){let o=0,s=e.length-1;for(;o<=s;){const n=Math.floor((o+s)/2),i=e[n];if(t<i.start)s=n-1;else{if(!(t>i.end))return n;o=n+1}}return-1}Ia.getters=["isMergeDestructive","isInMerge","getMainCell","expandZone","doesIntersectMerge"];class Ua extends dn{constructor(){super(...arguments),this.boxes=[]}getColIndex(e,t){if(e<h)return-1;const o=this.workbook.activeSheet.cols;return $a(o,e-h+o[t].start+1)}getRowIndex(e,t){if(e<c)return-1;const o=this.workbook.activeSheet.rows;return $a(o,e-c+o[t].start+1)}getRect(e,t){const{left:o,top:s,right:n,bottom:i}=e;let{offsetY:r,offsetX:a}=t;a-=h,r-=c;const{cols:l,rows:u}=this.workbook.activeSheet,d=Math.max(l[o].start-a,h),p=l[n].end-a-d,g=Math.max(u[s].start-r,c);return[d,g,p,u[i].end-r-g]}snapViewportToCell(e){const{cols:t,rows:o}=this.workbook.activeSheet,s=Object.assign({},e);return s.offsetX=t[e.left].start,s.offsetY=o[e.top].start,s}adjustViewportPosition(e){const t=Object.assign({},e),{cols:o,rows:s}=this.workbook.activeSheet,[n,i]=this.getters.getPosition();for(;n>=t.right&&n!==o.length-1;)t.offsetX=o[t.left].end,this.adjustViewportZoneX(t);for(;n<t.left;)t.offsetX=o[t.left-1].start,this.adjustViewportZoneX(t);for(;i>=t.bottom&&i!==s.length-1;)t.offsetY=s[t.top].end,this.adjustViewportZoneY(t);for(;i<t.top;)t.offsetY=s[t.top-1].start,this.adjustViewportZoneY(t);return t}adjustViewportZone(e){const t=Object.assign({},e);return this.adjustViewportZoneX(t),this.adjustViewportZoneY(t),t}adjustViewportZoneX(e){const{cols:t}=this.workbook.activeSheet,{width:o,offsetX:s}=e;e.left=this.getColIndex(s+h,0);const n=o+s-h;e.right=t.length-1;for(let o=e.left;o<t.length;o++)if(n<t[o].end){e.right=o;break}}adjustViewportZoneY(e){const{rows:t}=this.workbook.activeSheet,{height:o,offsetY:s}=e;e.top=this.getRowIndex(s+c,0);let n=o+s-c;e.bottom=t.length-1;for(let o=e.top;o<t.length;o++)if(n<t[o].end){e.bottom=o;break}}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(e),this.drawBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e);break;case 6:this.drawHeaders(e)}}drawBackground(e){const{ctx:t,viewport:o,thinLineWidth:s}=e;let{width:n,height:i,offsetX:r,offsetY:a,top:l,left:u,bottom:d,right:p}=o;const{rows:g,cols:f}=this.workbook.activeSheet;t.fillStyle="white",t.fillRect(0,0,o.width,o.height),r-=h,a-=c,t.lineWidth=2*s,t.strokeStyle="#E2E3E3",t.beginPath();const m=Math.min(i,g[d].end-a);for(let e=u;e<=p;e++){const o=f[e].end-r;t.moveTo(o,0),t.lineTo(o,m)}const v=Math.min(n,f[p].end-r);for(let e=l;e<=d;e++){const o=g[e].end-a;t.moveTo(0,o),t.lineTo(v,o)}t.stroke()}drawCellBackground(e){const{ctx:t,thinLineWidth:o}=e;t.lineWidth=.3*o;const s=.1*o;t.strokeStyle="#111";for(let e of this.boxes){let o=e.style;o&&o.fillColor&&"#ffffff"!==o.fillColor&&(t.fillStyle=o.fillColor,t.fillRect(e.x,e.y,e.width,e.height),t.strokeRect(e.x+s,e.y+s,e.width-2*s,e.height-2*s)),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:o}=e;for(let e of this.boxes){let t=e.border;if(t){const{x:o,y:n,width:i,height:r}=e;t.left&&s(t.left,o,n,o,n+r),t.top&&s(t.top,o,n,o+i,n),t.right&&s(t.right,o+i,n,o+i,n+r),t.bottom&&s(t.bottom,o,n+r,o+i,n+r)}}function s([e,s],n,i,r,a){t.strokeStyle=s,t.lineWidth=("thin"===e?2:3)*o,t.beginPath(),t.moveTo(n,i),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:o}=e;let s;t.textBaseline="middle";for(let e of this.boxes)if(e.text){const n=e.style||{},i=e.align,r=n.italic?"italic ":"",a=n.bold?"bold":"400",l=n.fontSize||10,c=`${r}${a} ${Qn[l]}px 'Roboto', arial`;let h;c!==s&&(s=c,t.font=c),t.fillStyle=n.textColor||"#000";let u=e.y+e.height/2+1;h="left"===i?e.x+3:"right"===i?e.x+e.width-3:e.x+e.width/2,t.textAlign=i,e.clipRect&&(t.save(),t.beginPath(),t.rect(...e.clipRect),t.clip()),t.fillText(e.text,Math.round(h),Math.round(u)),n.strikethrough&&("right"===i?h-=e.textWidth:"center"===i&&(h-=e.textWidth/2),t.fillRect(h,u,e.textWidth,2.6*o)),e.clipRect&&t.restore()}}drawHeaders(e){const{ctx:t,viewport:o,thinLineWidth:s}=e;let{width:n,height:l,offsetX:u,offsetY:d,left:p,top:g,right:f,bottom:m}=o;u-=h,d-=c;const v=this.getters.getSelectedZones(),{cols:b,rows:E}=this.workbook.activeSheet,w=this.getters.getActiveCols(),L=this.getters.getActiveRows();t.fillStyle="#F8F9FA",t.font="400 11px 'Roboto', arial",t.textAlign="center",t.textBaseline="middle",t.lineWidth=s,t.strokeStyle="#333",t.fillRect(0,0,n,c),t.fillRect(0,0,h,l),t.fillStyle=i;for(let e of v){const o=Math.max(h,b[e.left].start-u),s=Math.max(h,b[e.right].end-u),n=Math.max(c,E[e.top].start-d),a=Math.max(c,E[e.bottom].end-d);t.fillStyle=w.has(e.left)?r:i,t.fillRect(o,0,s-o,c),t.fillStyle=L.has(e.top)?r:i,t.fillRect(0,n,h,a-n)}t.beginPath(),t.moveTo(h,0),t.lineTo(h,l),t.moveTo(0,c),t.lineTo(n,c),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(let e=p;e<=f;e++){const o=b[e];t.fillStyle=w.has(e)?"#fff":a,t.fillText(o.name,(o.start+o.end)/2-u,13),t.moveTo(o.end-u,0),t.lineTo(o.end-u,c)}for(let e=g;e<=m;e++){const o=E[e];t.fillStyle=L.has(e)?"#fff":a,t.fillText(o.name,24,(o.start+o.end)/2-d),t.moveTo(0,o.end-d),t.lineTo(h,o.end-d)}t.stroke()}hasContent(e,t){const{cells:o,mergeCellMap:s}=this.workbook.activeSheet,n=w(e,t),i=o[n];return i&&i.content||n in s}getGridBoxes(e){const{viewport:t}=e;let{right:o,left:s,top:n,bottom:i,offsetX:r,offsetY:a}=t;r-=h,a-=c;const l=[],{cols:u,rows:d,mergeCellMap:p,cells:g,merges:f}=this.workbook.activeSheet;for(let e=n;e<=i;e++){let t=d[e];for(let n=s;n<=o;n++){let i=t.cells[n];if(i&&!(i.xc in p)){let c=u[n];const h=this.getters.getCellText(i),d=this.getters.getCellWidth(i);let p=this.getters.getCellStyle(i);const g=this.getters.getConditionalStyle(i.xc);g&&(p=Object.assign({},p,g));const f=h?p&&p.align||Da(i,this.getters.shouldShowFormulas()):void 0;let m=null;if(h&&d>u[i.col].size){let l,h;switch(f){case"left":for(l=i.col;l<o&&!this.hasContent(l+1,i.row);)l++;h=u[l].end-c.start,h<d&&(m=[c.start-r,t.start-a,h,t.size]);break;case"right":for(l=i.col;l>s&&!this.hasContent(l-1,i.row);)l--;h=c.end-u[l].start,h<d&&(m=[u[l].start-r,t.start-a,h,t.size]);break;case"center":let p=n;for(;p>s&&!this.hasContent(p-1,e);)p--;let g=n;for(;g<o&&!this.hasContent(g+1,e);)g++;const f=Math.min(p,n),v=Math.max(g,n);h=u[v].end-u[f].start,(h<d||f===n||v===n)&&(m=[u[f].start-r,t.start-a,h,t.size])}}l.push({x:c.start-r,y:t.start-a,width:c.size,height:t.size,text:h,textWidth:d,border:this.getters.getCellBorder(i),style:p,align:f,clipRect:m,error:i.error})}}}for(let e in f){let o=f[e];if(T(o,t)){const e=g[o.topLeft],t=g[w(o.right,o.bottom)],s=u[o.right].end-u[o.left].start;let n,i,c,h,p;if(e||t){n=e?this.getters.getCellText(e):"",i=e?this.getters.getCellWidth(e):null;const s=this.getters.getConditionalStyle(o.topLeft);c=s||(e?this.getters.getCellStyle(e):null),h=n?c&&c.align||Da(e,this.getters.shouldShowFormulas()):null;const r=e?this.getters.getCellBorder(e):null,a=t?this.getters.getCellBorder(t):null;p={bottom:a?a.bottom:null,left:r?r.left:null,right:a?a.right:null,top:r?r.top:null}}c=c||{},c.fillColor&&"#ffffff"!==c.fillColor||(c=Object.create(c),c.fillColor="#fff");const f=u[o.left].start-r,m=d[o.top].start-a,v=d[o.bottom].end-d[o.top].start;l.push({x:f,y:m,width:s,height:v,text:n,textWidth:i,border:p,style:c,align:h,clipRect:[f,m,s,v],error:e?e.error:void 0})}}return l}}var Fa;Ua.layers=[0,6],Ua.getters=["getColIndex","getRowIndex","getRect","snapViewportToCell","adjustViewportPosition","adjustViewportZone"],Ua.modes=["normal","readonly"],function(e){e[e.idle=0]="idle",e[e.selecting=1]="selecting",e[e.readyToExpand=2]="readyToExpand",e[e.expanding=3]="expanding"}(Fa||(Fa={}));class Pa extends dn{constructor(){super(...arguments),this.selection={zones:[{top:0,left:0,bottom:0,right:0}],anchor:[0,0]},this.activeCol=0,this.activeRow=0,this.activeXc="A1",this.mode=Fa.idle,this.sheetsData={}}allowDispatch(e){switch(e.type){case"MOVE_POSITION":{const[t,o]=this.getReferenceCoords(),{cols:s,rows:n}=this.workbook.activeSheet;if(e.deltaY<0&&0===o||e.deltaY>0&&o===n.length-1||e.deltaX<0&&0===t||e.deltaX>0&&t===s.length-1)return{status:"CANCELLED",reason:10};break}case"SELECT_COLUMN":{const{index:t}=e;if(t<0||t>=this.workbook.activeSheet.cols.length)return{status:"CANCELLED",reason:10};break}case"SELECT_ROW":{const{index:t}=e;if(t<0||t>=this.workbook.activeSheet.rows.length)return{status:"CANCELLED",reason:10};break}}return{status:"SUCCESS"}}handle(e){switch(e.type){case"START":this.selectCell(0,0);break;case"ACTIVATE_SHEET":this.sheetsData[e.from]={selection:JSON.parse(JSON.stringify(this.selection)),activeCol:this.activeCol,activeRow:this.activeRow,activeXc:this.activeXc},e.to in this.sheetsData?Object.assign(this,this.sheetsData[e.to]):this.selectCell(0,0);break;case"SET_SELECTION":this.setSelection(e.anchor,e.zones,e.strict);break;case"START_SELECTION":this.mode=Fa.selecting;break;case"PREPARE_SELECTION_EXPANSION":this.mode=Fa.readyToExpand;break;case"START_SELECTION_EXPANSION":this.mode=Fa.expanding;break;case"STOP_SELECTION":this.mode=Fa.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"REMOVE_COLUMNS":case"REMOVE_ROWS":this.ensureSelectionValidity();break;case"ADD_COLUMNS":"before"===e.position&&this.onAddColumns(e.quantity);break;case"ADD_ROWS":"before"===e.position&&this.onAddRows(e.quantity)}}getActiveCell(){const e=this.workbook.activeSheet;let t=e.mergeCellMap[this.activeXc];return t?e.cells[e.merges[t].topLeft]:this.getters.getCell(this.activeCol,this.activeRow)}getActiveCols(){const e=new Set;for(let t of this.selection.zones)if(0===t.top&&t.bottom===this.workbook.activeSheet.rows.length-1)for(let o=t.left;o<=t.right;o++)e.add(o);return e}getActiveRows(){const e=new Set;for(let t of this.selection.zones)if(0===t.left&&t.right===this.workbook.activeSheet.cols.length-1)for(let o=t.top;o<=t.bottom;o++)e.add(o);return e}getSelectedZones(){return this.selection.zones}getSelectedZone(){return this.selection.zones[this.selection.zones.length-1]}getSelection(){return this.selection}getPosition(){return[this.activeCol,this.activeRow]}getAggregate(){let e=0,t=0;for(let o of this.selection.zones)for(let s=o.top;s<=o.bottom;s++){const n=this.workbook.activeSheet.rows[s];for(let s=o.left;s<=o.right;s++){const o=n.cells[s];o&&"text"!==o.type&&!o.error&&"number"==typeof o.value&&(t++,e+=o.value)}}return t<2?null:j(e)}getSelectionMode(){return this.mode}isSelected(e){return!!this.getters.getSelectedZones().find((t=>y(t,e)))}getReferenceCoords(){return"selecting"===this.getters.getEditionMode()?this.selection.anchor:[this.activeCol,this.activeRow]}selectColumn(e,t,o){const s=this.workbook.activeSheet.rows.length-1,n={left:e,right:e,top:0,bottom:s},i=this.selection.zones;let r,a;if(o){const[e,t]=this.selection.anchor,o=C(n,{left:e,right:e,top:0,bottom:s});r=i.slice(0,-1).concat(o),a=[e,t]}else r=t?i.concat(n):[n],a=[e,0];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0})}selectRow(e,t,o){const s=this.workbook.activeSheet.cols.length-1,n={top:e,bottom:e,left:0,right:s},i=this.selection.zones;let r,a;if(o){const[e,t]=this.selection.anchor,o=C(n,{left:0,right:s,top:t,bottom:t});r=i.slice(0,-1).concat(o),a=[e,t]}else r=t?i.concat(n):[n],a=[0,e];this.dispatch("SET_SELECTION",{zones:r,anchor:a,strict:!0})}selectAll(){const e={left:0,top:0,bottom:this.workbook.activeSheet.rows.length-1,right:this.workbook.activeSheet.cols.length-1};this.dispatch("SET_SELECTION",{zones:[e],anchor:[0,0]})}selectCell(e,t){const o=w(e,t);let s=this.getters.expandZone({left:e,right:e,top:t,bottom:t});this.mode===Fa.expanding?this.selection.zones.push(s):this.selection.zones=[s],this.selection.anchor=[e,t],"selecting"!==this.getters.getEditionMode()&&(this.activeCol=e,this.activeRow=t,this.activeXc=o)}movePosition(e,t){const[o,s]=this.getReferenceCoords(),n=w(o,s),i=this.workbook.activeSheet;let r=i.mergeCellMap[n];if(r){let n=o,a=s;for(;i.mergeCellMap[w(n,a)]===r;)n+=e,a+=t;n>=0&&a>=0&&this.selectCell(n,a)}else this.selectCell(o+e,s+t)}setSelection(e,t,o=!1){this.selectCell(...e),this.selection.zones=o?t:t.map(this.getters.expandZone),this.selection.anchor=e}moveSelection(e,t){const o=this.selection,s=o.zones.slice(),n=s[o.zones.length-1],[i,r]=o.anchor,{left:a,right:l,top:c,bottom:h}=n;let u=n;const d=e=>{const{left:t,right:o,top:s,bottom:n}=this.getters.expandZone(e);return{left:Math.max(0,t),right:Math.min(this.workbook.activeSheet.cols.length-1,o),top:Math.max(0,s),bottom:Math.min(this.workbook.activeSheet.rows.length-1,n)}};let p=0;for(;null!==u;)if(p++,e<0&&(u=i<=l-p?d({top:c,left:a,bottom:h,right:l-p}):null),e>0&&(u=a+p<=i?d({top:c,left:a+p,bottom:h,right:l}):null),t<0&&(u=r<=h-p?d({top:c,left:a,bottom:h-p,right:l}):null),t>0&&(u=c+p<=r?d({top:c+p,left:a,bottom:h,right:l}):null),u&&!y(u,n))return s[s.length-1]=u,void this.dispatch("SET_SELECTION",{zones:s,anchor:[i,r]});u=d(C({top:r,bottom:r,left:i,right:i},{top:c+t,left:a+e,bottom:h+t,right:l+e})),y(u,n)||(s[s.length-1]=u,this.dispatch("SET_SELECTION",{zones:s,anchor:[i,r]}))}addCellToSelection(e,t){const o=this.selection,[s,n]=o.anchor,i={left:Math.min(s,e),top:Math.min(n,t),right:Math.max(s,e),bottom:Math.max(n,t)},r=o.zones.slice(0,-1).concat(i);this.dispatch("SET_SELECTION",{zones:r,anchor:[s,n]})}ensureSelectionValidity(){const e=this.getters.getSheets().map((e=>e.id));if(e.includes(this.getters.getActiveSheet())){const{anchor:e,zones:t}=this.clipSelection(this.getters.getActiveSheet(),this.selection);this.setSelection(e,t)}else this.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:e[0]});const t=Object.keys(this.sheetsData).filter((t=>!e.includes(t)));for(const e of t)delete this.sheetsData[e];for(const e in this.sheetsData){const{anchor:t,zones:o}=this.clipSelection(e,this.sheetsData[e].selection);this.sheetsData[e]={selection:{anchor:t,zones:o},activeCol:t[0],activeRow:t[1],activeXc:w(...t)}}}clipSelection(e,t){const o=this.getters.getNumberCols(e)-1,s=this.getters.getNumberRows(e)-1,n=t.zones.map((e=>({left:F(e.left,0,o),right:F(e.right,0,o),top:F(e.top,0,s),bottom:F(e.bottom,0,s)})));return{anchor:[n[n.length-1].left,n[n.length-1].top],zones:n}}onAddColumns(e){const t=this.getSelectedZone(),o={left:t.left+e,right:t.right+e,top:t.top,bottom:t.bottom};this.dispatch("SET_SELECTION",{zones:[o],anchor:[o.left,o.top],strict:!0})}onAddRows(e){const t=this.getSelectedZone(),o={left:t.left,right:t.right,top:t.top+e,bottom:t.bottom+e};this.dispatch("SET_SELECTION",{zones:[o],anchor:[o.left,o.top],strict:!0})}drawGrid(e){const{viewport:t,ctx:o,thinLineWidth:s}=e,n=this.getSelectedZones();o.fillStyle="#f3f7fe";const i=1===n.length&&n[0].left===n[0].right&&n[0].top===n[0].bottom;o.fillStyle=i?"#f3f7fe":"#e9f0ff",o.strokeStyle=l,o.lineWidth=1.5*s,o.globalCompositeOperation="multiply";for(const e of n){const[s,n,i,r]=this.getters.getRect(e,t);i>0&&r>0&&(o.fillRect(s,n,i,r),o.strokeRect(s,n,i,r))}o.globalCompositeOperation="source-over";const{mergeCellMap:r,merges:a}=this.workbook.activeSheet,[c,h]=this.getPosition(),u=w(c,h);let d;o.strokeStyle="#3266ca",o.lineWidth=3*s,d=u in r?a[r[u]]:{top:h,bottom:h,left:c,right:c};const[p,g,f,m]=this.getters.getRect(d,t);f>0&&m>0&&o.strokeRect(p,g,f,m)}}Pa.layers=[4],Pa.modes=["normal","readonly"],Pa.getters=["getActiveCell","getActiveCols","getActiveRows","getSelectedZones","getSelectedZone","getAggregate","getSelection","getPosition","getSelectionMode","isSelected"];class Ba extends dn{constructor(){super(...arguments),this.inputs={},this.inputMaximums={},this.focusedInput=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.focusedInput===e.id&&this.focusedRange===t)return{status:"CANCELLED",reason:14};break;case"ADD_EMPTY_RANGE":if(this.inputs[e.id].length===this.inputMaximums[e.id])return{status:"CANCELLED",reason:15}}return{status:"SUCCESS"}}handle(e){switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.maximumRanges);break;case"DISABLE_SELECTION_INPUT":this.focusedInput===e.id&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!1}),this.dispatch("REMOVE_ALL_HIGHLIGHTS"),this.focusedRange=null,this.focusedInput=null),delete this.inputs[e.id],delete this.inputMaximums[e.id];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);null!==t&&this.changeRange(e.id,t,e.value);break}case"ADD_EMPTY_RANGE":this.inputs[e.id]=[...this.inputs[e.id],Object.freeze({xc:"",id:K()})],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"ADD_HIGHLIGHTS":const o=this.getters.getHighlights();this.add(o.slice(o.length-Object.keys(e.ranges).length));break;case"START_SELECTION_EXPANSION":this.willAddNewRange&&this.dispatch("RESET_PENDING_HIGHLIGHT");break;case"PREPARE_SELECTION_EXPANSION":{const[e,t]=[this.focusedInput,this.focusedRange];null!==e&&null!==t&&(this.willAddNewRange=""!==this.inputs[e][t].xc.trim());break}}}getSelectionInput(e){return this.inputs[e]?this.inputs[e].map(((t,o)=>Object.assign({},t,{color:this.focusedInput===e&&null!==this.focusedRange?t.color:null,isFocused:this.focusedInput===e&&this.focusedRange===o}))):[]}getSelectionInputValue(e){return this.cleanInputs(this.inputs[e].map((e=>e.xc)))}initInput(e,t,o){this.inputs[e]=t.map((e=>Object.freeze({xc:e,id:K()}))),void 0!==o&&(this.inputMaximums[e]=o),0===this.inputs[e].length&&this.dispatch("ADD_EMPTY_RANGE",{id:e})}focus(e,t){const o=this.focusedInput,s=this.focusedInput&&this.focusedRange;if(this.focusedInput=e,null!==s&&null==t&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!1}),this.removeAllHighlights()),null!==o&&null!==e&&o!==e&&this.removeAllHighlights(),(null===s&&null!==t||o!==e)&&(this.dispatch("HIGHLIGHT_SELECTION",{enabled:!0}),this.highlightAllRanges(e)),this.setPendingRange(e,t),null!==t){const o=this.inputs[e][t].color||v();this.dispatch("SET_HIGHLIGHT_COLOR",{color:o})}this.focusedRange=t}focusLast(e){this.focus(e,this.inputs[e].length-1)}removeAllHighlights(){this.dispatch("REMOVE_ALL_HIGHLIGHTS")}highlightAllRanges(e){const t=this.inputs[e];for(const[e,o]of t.entries()){this.focusedRange=e;const t=this.inputToHighlights(o);Object.keys(t).length>0&&this.dispatch("ADD_HIGHLIGHTS",{ranges:t})}}add(e){if(null===this.focusedInput||null===this.focusedRange||"selecting"===this.getters.getEditionMode()||0===e.length)return;this.getters.getSelectionMode()===Fa.expanding&&this.willAddNewRange?(this.addNewRange(this.focusedInput,e),this.willAddNewRange=!1):this.setRange(this.focusedInput,this.focusedRange,e)}addNewRange(e,t){this.inputMaximums[e]<this.inputs[e].length+t.length||(this.inputs[e]=this.inputs[e].concat(this.highlightsToInput(t)),this.focusLast(e))}setRange(e,t,o){let[s,...n]=this.highlightsToInput(o);const i=this.inputs[e].length+n.length-this.inputMaximums[e];i&&(n=n.slice(0,n.length-i)),this.inputs[e].splice(t,1,s,...n),n.length&&this.focus(e,t+n.length)}changeRange(e,t,o){this.focusedInput===e&&this.focusedRange===t||this.dispatch("FOCUS_RANGE",{id:e,rangeId:this.inputs[e][t].id});const s=this.inputs[e][t];this.dispatch("REMOVE_HIGHLIGHTS",{ranges:this.inputToHighlights(s)}),this.dispatch("ADD_HIGHLIGHTS",{ranges:this.inputToHighlights({color:s.color,xc:o})})}removeRange(e,t){const[o]=this.inputs[e].splice(t,1);this.focusedInput===e&&null!==this.focusedRange&&(this.dispatch("REMOVE_HIGHLIGHTS",{ranges:this.inputToHighlights(o)}),this.focusLast(e))}setPendingRange(e,t){this.dispatch("RESET_PENDING_HIGHLIGHT"),null!==t&&this.inputs[e][t].xc&&this.dispatch("ADD_PENDING_HIGHLIGHTS",{ranges:this.inputToHighlights(this.inputs[e][t])})}highlightsToInput(e){return e.map((e=>Object.freeze({xc:this.getters.zoneToXC(e.zone),id:K(),color:e.color})))}inputToHighlights({xc:e,color:t}){const o=this.cleanInputs([e]);if(0===o.length)return{};const[s,...n]=o,i={[s]:t||v()};for(const e of n)i[e]=v();return i}isRangeValid(e){return null!==e.match(Kr)}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e)).filter(this.isRangeValid)}getIndex(e,t){const o=this.inputs[e].findIndex((e=>e.id===t));return o>=0?o:null}}Ba.modes=["normal","readonly"],Ba.layers=[1],Ba.getters=["getSelectionInput","getSelectionInputValue"];const Za=(new _e).add("core",ma).add("evaluation",Ra).add("clipboard",sa).add("merge",Ia).add("formatting",ka).add("edition",Ca).add("selection",Pa).add("highlight",_a).add("selectionInput",Ba).add("conditional formatting",na).add("figures",Ma).add("chart",oa).add("grid renderer",Ua).add("autofill",Mr);function za(e){return e?("version"in(e=Object.assign({},e))&&e.version<5&&(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=Object.assign(Va(),e,{version:5})).sheets=e.sheets.map(((e,t)=>Object.assign(Ga(`Sheet${t+1}`),e))),e.sheets.map((e=>e.id)).includes(e.activeSheet)||(e.activeSheet=e.sheets[0].id),0===e.sheets.length&&e.sheets.push(Ga()),e):Va()}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){const t=e.sheets.find((t=>t.name===e.activeSheet));return e.activeSheet=t.id,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}}];function Ga(e="Sheet1"){return{id:K(),name:e,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[]}}function Va(){const e={version:5,sheets:[Ga("Sheet1")],activeSheet:"",entities:{},styles:{},borders:{}};return e.activeSheet=e.sheets[0].id,e}class ja{constructor(e){this.current=null,this.undoStack=[],this.redoStack=[],this.workbook=e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}allowDispatch(e){switch(e.type){case"UNDO":return this.canUndo()?{status:"SUCCESS"}:{status:"CANCELLED",reason:3};case"REDO":return this.canRedo()?{status:"SUCCESS"}:{status:"CANCELLED",reason:4}}return{status:"SUCCESS"}}beforeHandle(e){this.current||"REDO"===e.type||"UNDO"===e.type||(this.current=[])}handle(e){switch(e.type){case"UNDO":this.undo();break;case"REDO":this.redo()}}finalize(){this.current&&this.current.length&&(this.isActiveSheet()||this.undoStack.push(this.current),this.redoStack=[],this.current=null,this.undoStack.length>99&&this.undoStack.shift())}isActiveSheet(){return this.current&&1===this.current.length&&1===this.current[0].path.length&&"activeSheet"===this.current[0].path[0]}undo(){const e=this.undoStack.pop();if(e){this.redoStack.push(e);for(let t=e.length-1;t>=0;t--){let o=e[t];this.applyChange(o,"before")}}}redo(){const e=this.redoStack.pop();if(e){this.undoStack.push(e);for(let t of e)this.applyChange(t,"after")}}applyChange(e,t){let o=e.root,s=e.path[e.path.length-1];for(let t of e.path.slice(0,-1))o=o[t];void 0===e[t]?delete o[s]:o[s]=e[t]}updateStateFromRoot(e,t,o){let s=e,n=t[t.length-1];for(let e of t.slice(0,-1))s=s[e];s[n]!==o&&(this.current&&this.current.push({root:e,path:t,before:s[n],after:o}),void 0===o?delete s[n]:s[n]=o)}updateState(e,t){this.updateStateFromRoot(this.workbook,e,t)}updateCell(e,t,o){this.updateStateFromRoot(e,[t],o)}updateSheet(e,t,o){this.updateStateFromRoot(e,t,o)}}var qa;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.Finalizing=2]="Finalizing",e[e.Interactive=3]="Interactive"}(qa||(qa={}));class Wa extends s.core.EventBus{constructor(e={},t={}){super(),this.renderers=[],this.status=0,this.dispatch=(e,t)=>{const o=Object.assign({type:e},t);switch(o.interactive?3:this.status){case 0:for(let e of this.handlers){const t=e.allowDispatch(o);if("CANCELLED"===t.status)return t}this.status=1;for(const e of this.handlers)e.beforeHandle(o);for(const e of this.handlers)e.handle(o);this.status=2;for(const e of this.handlers)e.finalize(o);this.status=0,"headless"!==this.config.mode&&this.trigger("update");break;case 1:case 3:for(const e of this.handlers)e.beforeHandle(o);for(const e of this.handlers)e.handle(o);break;case 2:throw new Error(Q("Nope. Don't do that"))}return{status:"SUCCESS"}},P.model=this;const o=za(e);this.workbook={visibleSheets:[],sheets:{},activeSheet:null};const s=new ja(this.workbook);this.getters={canUndo:s.canUndo.bind(s),canRedo:s.canRedo.bind(s)},this.handlers=[s],this.config={mode:t.mode||"normal",openSidePanel:t.openSidePanel||(()=>{}),notifyUser:t.notifyUser||(()=>{}),askConfirmation:t.askConfirmation||(()=>{}),editText:t.editText||(()=>{}),evalContext:t.evalContext||{}};for(let e of Za.getAll())this.setupPlugin(e,o);this.dispatch("START")}destroy(){delete P.model}setupPlugin(e,t){const o=this.dispatch.bind(this),s=this.handlers.find((e=>e instanceof ja));if(e.modes.includes(this.config.mode)){const n=new e(this.workbook,this.getters,s,o,this.config);n.import(t);for(let t of e.getters){if(!(t in n))throw new Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);this.getters[t]=n[t].bind(n)}this.handlers.push(n);const i=e.layers.map((e=>[n,e]));this.renderers.push(...i),this.renderers.sort(((e,t)=>e[1]-t[1]))}}drawGrid(e){e.viewport=this.getters.snapViewportToCell(e.viewport);for(let[t,o]of this.renderers)t.drawGrid(e,o)}exportData(){const e=Va();for(let t of this.handlers)t instanceof dn&&t.export(e);return e}}function Ya(e,t){return!!t.target&&e.contains(t.target)}const{xml:Xa,css:Ka}=t.tags,{useExternalListener:Ja,useRef:Qa}=t.hooks,el=200,tl=32,ol=Xa`
489
495
  <div>
490
496
  <div class="o-menu" t-att-style="style" t-on-scroll="onScroll" t-on-wheel.stop="" t-on-contextmenu.prevent="">
491
497
  <t t-foreach="props.menuItems" t-as="menuItem" t-key="menuItem.id">
@@ -515,10 +521,10 @@
515
521
  depth="props.depth + 1"
516
522
  t-ref="subMenuRef"
517
523
  t-on-close="subMenu.isOpen=false"/>
518
- </div>`,tl=Ya`
524
+ </div>`,sl=Ka`
519
525
  .o-menu {
520
526
  position: absolute;
521
- width: ${Ja}px;
527
+ width: ${el}px;
522
528
  background-color: white;
523
529
  box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
524
530
  font-size: 13px;
@@ -527,7 +533,7 @@
527
533
  padding: 5px 0px;
528
534
  .o-menu-item {
529
535
  box-sizing: border-box;
530
- height: ${Qa}px;
536
+ height: ${tl}px;
531
537
  padding: 7px 20px;
532
538
  padding-right: 2px;
533
539
  overflow: hidden;
@@ -555,7 +561,7 @@
555
561
  }
556
562
  }
557
563
  }
558
- `;class ol extends t.Component{constructor(){super(...arguments),this.subMenuRef=Ka("subMenuRef"),Xa(window,"click",this.onClick),Xa(window,"contextmenu",this.onContextMenu),this.subMenu=t.useState({isOpen:!1,position:null,scrollOffset:0,menuItems:[]})}get subMenuPosition(){const e=Object.assign({},this.subMenu.position);return e.y-=this.subMenu.scrollOffset||0,e}get renderRight(){const{x:e,width:t}=this.props.position;return e<t-Ja}get renderBottom(){const{y:e,height:t}=this.props.position;return e<t-this.menuHeight}get menuHeight(){const e=this.props.menuItems.filter((e=>e.separator)),t=this.props.menuItems;return Qa*t.length+1*e.length}get style(){const{x:e,height:t}=this.props.position,o=`left:${this.renderRight?e:e-Ja}`;return`${`top:${this.menuVerticalPosition()}`}px;${o}px;${`max-height:${t}`}px`}activateMenu(e){e.action(this.env),this.close()}close(){this.subMenu.isOpen=!1,this.trigger("close")}menuVerticalPosition(){const{y:e,height:t}=this.props.position;return this.renderBottom?e:Math.max(Qa,e-Math.min(this.menuHeight,t))}subMenuHorizontalPosition(){const{x:e,width:t}=this.props.position,o=e+400<t;return this.renderRight&&o?e+Ja:this.renderRight&&!o?e-Ja:e-(this.props.depth+1)*Ja}subMenuVerticalPosition(e,t){const{height:o}=this.props.position,s=this.menuVerticalPosition()+this.menuItemVerticalOffset(t),n=e*Qa;return s<o-n?s:Math.max(Qa,s-n+Qa)}menuItemVerticalOffset(e){return this.props.menuItems.slice(0,e).length*Qa}onClick(e){this.el&&qa(this.el,e)||this.close()}onContextMenu(e){this.el&&qa(this.el,e)||(this.subMenu.isOpen=!1)}getName(e){return Wn.getName(e,this.env)}isRoot(e){return!e.action}isEnabled(e){return e.isEnabled(this.env)}closeSubMenus(){this.subMenuRef.comp&&this.subMenuRef.comp.closeSubMenus(),this.subMenu.isOpen=!1}onScroll(e){this.subMenu.scrollOffset=e.target.scrollTop}openSubMenu(e,t){this.closeSubMenus(),this.subMenu.isOpen=!0,this.subMenu.menuItems=Wn.getChildren(e,this.env);const{width:o,height:s}=this.props.position;this.subMenu.position={x:this.subMenuHorizontalPosition(),y:this.subMenuVerticalPosition(this.subMenu.menuItems.length,t),height:s,width:o}}onClickMenu(e,t){e.isEnabled(this.env)&&(this.isRoot(e)?this.openSubMenu(e,t):this.activateMenu(e))}onMouseOver(e,t){e.isEnabled(this.env)&&(this.isRoot(e)?this.openSubMenu(e,t):this.subMenu.isOpen=!1)}}ol.template=el,ol.components={Menu:ol},ol.style=tl,ol.defaultProps={depth:1};const sl=s.Component,{xml:nl,css:il}=s.tags,{useState:rl}=s.hooks,al=nl`
564
+ `;class nl extends t.Component{constructor(){super(...arguments),this.subMenuRef=Qa("subMenuRef"),Ja(window,"click",this.onClick),Ja(window,"contextmenu",this.onContextMenu),this.subMenu=t.useState({isOpen:!1,position:null,scrollOffset:0,menuItems:[]})}get subMenuPosition(){const e=Object.assign({},this.subMenu.position);return e.y-=this.subMenu.scrollOffset||0,e}get renderRight(){const{x:e,width:t}=this.props.position;return e<t-el}get renderBottom(){const{y:e,height:t}=this.props.position;return e<t-this.menuHeight}get menuHeight(){const e=this.props.menuItems.filter((e=>e.separator)),t=this.props.menuItems;return tl*t.length+1*e.length}get style(){const{x:e,height:t}=this.props.position,o=`left:${this.renderRight?e:e-el}`;return`${`top:${this.menuVerticalPosition()}`}px;${o}px;${`max-height:${t}`}px`}activateMenu(e){e.action(this.env),this.close()}close(){this.subMenu.isOpen=!1,this.trigger("close")}menuVerticalPosition(){const{y:e,height:t}=this.props.position;return this.renderBottom?e:Math.max(tl,e-Math.min(this.menuHeight,t))}subMenuHorizontalPosition(){const{x:e,width:t}=this.props.position,o=e+400<t;return this.renderRight&&o?e+el:this.renderRight&&!o?e-el:e-(this.props.depth+1)*el}subMenuVerticalPosition(e,t){const{height:o}=this.props.position,s=this.menuVerticalPosition()+this.menuItemVerticalOffset(t),n=e*tl;return s<o-n?s:Math.max(tl,s-n+tl)}menuItemVerticalOffset(e){return this.props.menuItems.slice(0,e).length*tl}onClick(e){this.el&&Ya(this.el,e)||this.close()}onContextMenu(e){this.el&&Ya(this.el,e)||(this.subMenu.isOpen=!1)}getName(e){return Wn.getName(e,this.env)}isRoot(e){return!e.action}isEnabled(e){return e.isEnabled(this.env)}closeSubMenus(){this.subMenuRef.comp&&this.subMenuRef.comp.closeSubMenus(),this.subMenu.isOpen=!1}onScroll(e){this.subMenu.scrollOffset=e.target.scrollTop}openSubMenu(e,t){this.closeSubMenus(),this.subMenu.isOpen=!0,this.subMenu.menuItems=Wn.getChildren(e,this.env);const{width:o,height:s}=this.props.position;this.subMenu.position={x:this.subMenuHorizontalPosition(),y:this.subMenuVerticalPosition(this.subMenu.menuItems.length,t),height:s,width:o}}onClickMenu(e,t){e.isEnabled(this.env)&&(this.isRoot(e)?this.openSubMenu(e,t):this.activateMenu(e))}onMouseOver(e,t){e.isEnabled(this.env)&&(this.isRoot(e)?this.openSubMenu(e,t):this.subMenu.isOpen=!1)}}nl.template=ol,nl.components={Menu:nl},nl.style=sl,nl.defaultProps={depth:1};const il=s.Component,{xml:rl,css:al}=s.tags,{useState:ll}=s.hooks,cl=rl`
559
565
  <div class="o-spreadsheet-bottom-bar">
560
566
  <div class="o-sheet-item o-add-sheet" t-on-click="addSheet">${'<svg class="o-icon"><path fill="#000000" d="M8,0 L10,0 L10,8 L18,8 L18,10 L10,10 L10,18 L8,18 L8,10 L0,10 L0,8 L8,8"/></svg>'}</div>
561
567
  <div class="o-sheet-item o-list-sheets" t-on-click="listSheets">${'<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>'}</div>
@@ -567,7 +573,7 @@
567
573
  t-att-data-id="sheet.id"
568
574
  t-att-class="{active: sheet.id === getters.getActiveSheet()}">
569
575
  <span class="o-sheet-name" t-esc="sheet.name" t-on-dblclick="onDblClick(sheet.id)"/>
570
- <span class="o-sheet-icon" t-on-click.stop="onIconClick(sheet.id)">${zi}</span>
576
+ <span class="o-sheet-icon" t-on-click.stop="onIconClick(sheet.id)">${Hi}</span>
571
577
  </div>
572
578
  </t>
573
579
  </div>
@@ -577,7 +583,7 @@
577
583
  position="menuState.position"
578
584
  menuItems="menuState.menuItems"
579
585
  t-on-close="menuState.isOpen=false"/>
580
- </div>`,ll=il`
586
+ </div>`,hl=al`
581
587
  .o-spreadsheet-bottom-bar {
582
588
  background-color: ${n};
583
589
  padding-left: ${h}px;
@@ -651,7 +657,7 @@
651
657
  opacity: 0;
652
658
  }
653
659
  }
654
- `;class cl extends sl{constructor(){super(...arguments),this.getters=this.env.getters,this.menuState=rl({isOpen:!1,position:null,menuItems:[]})}mounted(){this.focusSheet()}patched(){this.focusSheet()}focusSheet(){const e=this.el.querySelector(`[data-id="${this.getters.getActiveSheet()}"]`);e&&e.scrollIntoView&&e.scrollIntoView()}addSheet(){this.env.dispatch("CREATE_SHEET",{activate:!0,id:K()})}listSheets(e){const t=new Mn,o=this.getters.getActiveSheet();let s=0;for(let e of this.getters.getSheets())t.add(e.id,{name:e.name,sequence:s,action:t=>t.dispatch("ACTIVATE_SHEET",{from:o,to:e.id})}),s++;this.openContextMenu(e.currentTarget,t)}activateSheet(e){this.env.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:e})}onDblClick(e){this.env.dispatch("RENAME_SHEET",{interactive:!0,sheet:e})}openContextMenu(e,t){const o=e.offsetLeft,s=e.offsetTop;this.menuState.isOpen=!0,this.menuState.menuItems=t.getAll().filter((e=>e.isVisible(this.env))),this.menuState.position={x:o,y:s,height:400,width:this.el.clientWidth}}onIconClick(e,t){this.getters.getActiveSheet()!==e&&this.activateSheet(e),this.menuState.isOpen?this.menuState.isOpen=!1:this.openContextMenu(t.currentTarget.parentElement,Kn)}onContextMenu(e,t){this.getters.getActiveSheet()!==e&&this.activateSheet(e),this.openContextMenu(t.currentTarget,Kn)}}function hl(e,t){const o=n=>{t(n),window.removeEventListener("mouseup",o),window.removeEventListener("dragstart",s),window.removeEventListener("mousemove",e)};function s(e){e.preventDefault()}window.addEventListener("mouseup",o),window.addEventListener("dragstart",s),window.addEventListener("mousemove",e)}cl.template=al,cl.style=ll,cl.components={Menu:ol};const ul=s.Component,{xml:dl,css:pl}=s.tags,{useState:gl}=s.hooks,fl=dl`
660
+ `;class ul extends il{constructor(){super(...arguments),this.getters=this.env.getters,this.menuState=ll({isOpen:!1,position:null,menuItems:[]})}mounted(){this.focusSheet()}patched(){this.focusSheet()}focusSheet(){const e=this.el.querySelector(`[data-id="${this.getters.getActiveSheet()}"]`);e&&e.scrollIntoView&&e.scrollIntoView()}addSheet(){this.env.dispatch("CREATE_SHEET",{activate:!0,id:K()})}listSheets(e){const t=new Mn,o=this.getters.getActiveSheet();let s=0;for(let e of this.getters.getSheets())t.add(e.id,{name:e.name,sequence:s,action:t=>t.dispatch("ACTIVATE_SHEET",{from:o,to:e.id})}),s++;this.openContextMenu(e.currentTarget,t)}activateSheet(e){this.env.dispatch("ACTIVATE_SHEET",{from:this.getters.getActiveSheet(),to:e})}onDblClick(e){this.env.dispatch("RENAME_SHEET",{interactive:!0,sheet:e})}openContextMenu(e,t){const o=e.offsetLeft,s=e.offsetTop;this.menuState.isOpen=!0,this.menuState.menuItems=t.getAll().filter((e=>e.isVisible(this.env))),this.menuState.position={x:o,y:s,height:400,width:this.el.clientWidth}}onIconClick(e,t){this.getters.getActiveSheet()!==e&&this.activateSheet(e),this.menuState.isOpen?this.menuState.isOpen=!1:this.openContextMenu(t.currentTarget.parentElement,Kn)}onContextMenu(e,t){this.getters.getActiveSheet()!==e&&this.activateSheet(e),this.openContextMenu(t.currentTarget,Kn)}}function dl(e,t){const o=n=>{t(n),window.removeEventListener("mouseup",o),window.removeEventListener("dragstart",s),window.removeEventListener("mousemove",e)};function s(e){e.preventDefault()}window.addEventListener("mouseup",o),window.addEventListener("dragstart",s),window.addEventListener("mousemove",e)}ul.template=cl,ul.style=hl,ul.components={Menu:nl};const pl=s.Component,{xml:gl,css:fl}=s.tags,{useState:ml}=s.hooks,vl=gl`
655
661
  <div class="o-autofill" t-on-mousedown="onMouseDown" t-att-style="style" t-on-dblclick="onDblClick">
656
662
  <div class="o-autofill-handler" t-att-style="styleHandler"/>
657
663
  <t t-set="tooltip" t-value="getTooltip()"/>
@@ -659,7 +665,7 @@
659
665
  <t t-component="tooltip.component" t-props="tooltip.props"/>
660
666
  </div>
661
667
  </div>
662
- `,ml=pl`
668
+ `,bl=fl`
663
669
  .o-autofill {
664
670
  height: 6px;
665
671
  width: 6px;
@@ -687,9 +693,9 @@
687
693
  white-space: nowrap;
688
694
  }
689
695
  }
690
- `;class vl extends ul{constructor(){super(...arguments),this.state=gl({position:{left:0,top:0},handler:!1})}get style(){const{left:e,top:t}=this.props.position;return`top:${t}px;left:${e}px`}get styleHandler(){let e=this.state.handler?this.state.position:{left:0,top:0};return`top:${e.top}px;left:${e.left}px;`}get styleNextvalue(){let e=this.state.handler?this.state.position:{left:0,top:0};return`top:${e.top+5}px;left:${e.left+15}px;`}getTooltip(){const e=this.env.getters.getAutofillTooltip();return e&&!e.component&&(e.component=bl),e}onMouseDown(e){this.state.handler=!0,this.state.position={left:0,top:0};const t=e.clientX,o=e.clientY;let s,n;hl((e=>{this.state.position={left:e.clientX-t,top:e.clientY-o};const i=this.el.parentElement.getBoundingClientRect(),r=this.env.getters.getColIndex(e.clientX-i.left,this.props.viewport.left),a=this.env.getters.getRowIndex(e.clientY-i.top,this.props.viewport.top);if(s!==r||n!==a){const e=this.env.getters.getActiveSheet();s=-1===r?s:F(r,0,this.env.getters.getNumberCols(e)),n=-1===a?n:F(a,0,this.env.getters.getNumberRows(e)),void 0!==s&&void 0!==n&&this.env.dispatch("AUTOFILL_SELECT",{col:s,row:n})}}),(()=>{this.state.handler=!1,this.env.dispatch("AUTOFILL")}))}onDblClick(){this.env.dispatch("AUTOFILL_AUTO")}}vl.template=fl,vl.style=ml;class bl extends ul{}bl.template=dl`
696
+ `;class El extends pl{constructor(){super(...arguments),this.state=ml({position:{left:0,top:0},handler:!1})}get style(){const{left:e,top:t}=this.props.position;return`top:${t}px;left:${e}px`}get styleHandler(){let e=this.state.handler?this.state.position:{left:0,top:0};return`top:${e.top}px;left:${e.left}px;`}get styleNextvalue(){let e=this.state.handler?this.state.position:{left:0,top:0};return`top:${e.top+5}px;left:${e.left+15}px;`}getTooltip(){const e=this.env.getters.getAutofillTooltip();return e&&!e.component&&(e.component=wl),e}onMouseDown(e){this.state.handler=!0,this.state.position={left:0,top:0};const t=e.clientX,o=e.clientY;let s,n;dl((e=>{this.state.position={left:e.clientX-t,top:e.clientY-o};const i=this.el.parentElement.getBoundingClientRect(),r=this.env.getters.getColIndex(e.clientX-i.left,this.props.viewport.left),a=this.env.getters.getRowIndex(e.clientY-i.top,this.props.viewport.top);if(s!==r||n!==a){const e=this.env.getters.getActiveSheet();s=-1===r?s:F(r,0,this.env.getters.getNumberCols(e)),n=-1===a?n:F(a,0,this.env.getters.getNumberRows(e)),void 0!==s&&void 0!==n&&this.env.dispatch("AUTOFILL_SELECT",{col:s,row:n})}}),(()=>{this.state.handler=!1,this.env.dispatch("AUTOFILL")}))}onDblClick(){this.env.dispatch("AUTOFILL_AUTO")}}El.template=vl,El.style=bl;class wl extends pl{}wl.template=gl`
691
697
  <div t-esc="props.content"/>
692
- `;const El=s.Component,{useState:wl}=s,{xml:Ll,css:Sl}=s.tags,Cl=un.content,yl=new _e;yl.add("functions",(async function(){return Object.keys(Cl).map((e=>({text:e,description:Cl[e].description})))}));const Tl=Ll`
698
+ `;const Ll=s.Component,{useState:Sl}=s,{xml:Cl,css:yl}=s.tags,Tl=un.content,xl=new _e;xl.add("functions",(async function(){return Object.keys(Tl).map((e=>({text:e,description:Tl[e].description})))}));const Rl=Cl`
693
699
  <div t-att-class="{'o-autocomplete-dropdown':state.values.length}" >
694
700
  <t t-foreach="state.values" t-as="v" t-key="v.text">
695
701
  <div t-att-class="{'o-autocomplete-value-focus': state.selectedIndex === v_index}" t-on-click.stop.prevent="fillValue(v_index)">
@@ -697,7 +703,7 @@
697
703
  <div class="o-autocomplete-description" t-esc="v.description" t-if="state.selectedIndex === v_index"/>
698
704
  </div>
699
705
  </t>
700
- </div>`,xl=Sl`
706
+ </div>`,Ml=yl`
701
707
  .o-autocomplete-dropdown {
702
708
  width: 260px;
703
709
  margin: 4px;
@@ -724,7 +730,7 @@
724
730
  }
725
731
  }
726
732
  }
727
- `;class Rl extends El{constructor(){super(...arguments),this.state=wl({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){const t=yl.get(this.props.provider);let o=await t();o=this.props.filter?this.props.filter(e,o):o.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=o.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}}Rl.template=Tl,Rl.style=xl;class Ml{constructor(e){this.el=e}updateEl(e){this.el=e,this.el.focus()}selectRange(e,t){let o=window.getSelection();this.removeSelection();let s=document.createRange();if(e==t&&0===e)s.setStart(this.el,0),s.setEnd(this.el,0);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));let o=this.findChildAtCharacterIndex(e),n=this.findChildAtCharacterIndex(t);s.setStart(o.node,o.offset),s.setEnd(n.node,n.offset)}o.addRange(s)}findChildAtCharacterIndex(e){let t,o,s=this.iterateChildren(this.el),n=e;do{t=s.next(),t.done||t.value.hasChildNodes()||(t.value.textContent&&t.value.textContent.length<n?n-=t.value.textContent.length:s.return(t.value),o=t.value)}while(!t.done);return t.value?{node:t.value,offset:n}:{node:o,offset:n}}*iterateChildren(e){if(yield e,e.hasChildNodes())for(let t of e.childNodes)yield*this.iterateChildren(t)}insertText(e,t="#000"){document.execCommand("foreColor",!1,t),document.execCommand("insertText",!1,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:o,endSelectionOffset:s}=this.getStartAndEndSelection();return{start:this.findSizeBeforeElement(e)+o,end:this.findSizeBeforeElement(t)+s}}findSizeBeforeElement(e){let t=this.iterateChildren(this.el),o=0,s=t.next();for(;!s.done&&s.value!==e;)s.value.hasChildNodes()||s.value.textContent&&(o+=s.value.textContent.length),s=t.next();return o}getStartAndEndSelection(){const e=document.getSelection().getRangeAt(0);return{startElement:e.startContainer,startSelectionOffset:e.startOffset,endElement:e.endContainer,endSelectionOffset:e.endOffset}}}const Al=s.Component,{useRef:Nl,useState:kl}=s.hooks,{xml:_l,css:Il}=s.tags,Ol="#3da4ab",Dl="#02c39a",$l={OPERATOR:Ol,NUMBER:Dl,STRING:"#f6cd61",BOOLEAN:Dl,FUNCTION:"#4a4e4d",DEBUGGER:Ol,LEFT_PAREN:Ol,RIGHT_PAREN:Ol},Ul=_l`
733
+ `;class Al extends Ll{constructor(){super(...arguments),this.state=Sl({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){const t=xl.get(this.props.provider);let o=await t();o=this.props.filter?this.props.filter(e,o):o.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=o.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}}Al.template=Rl,Al.style=Ml;class Nl{constructor(e){this.el=e}updateEl(e){this.el=e,this.el.focus()}selectRange(e,t){let o=window.getSelection();this.removeSelection();let s=document.createRange();if(e==t&&0===e)s.setStart(this.el,0),s.setEnd(this.el,0);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));let o=this.findChildAtCharacterIndex(e),n=this.findChildAtCharacterIndex(t);s.setStart(o.node,o.offset),s.setEnd(n.node,n.offset)}o.addRange(s)}findChildAtCharacterIndex(e){let t,o,s=this.iterateChildren(this.el),n=e;do{t=s.next(),t.done||t.value.hasChildNodes()||(t.value.textContent&&t.value.textContent.length<n?n-=t.value.textContent.length:s.return(t.value),o=t.value)}while(!t.done);return t.value?{node:t.value,offset:n}:{node:o,offset:n}}*iterateChildren(e){if(yield e,e.hasChildNodes())for(let t of e.childNodes)yield*this.iterateChildren(t)}insertText(e,t="#000"){document.execCommand("foreColor",!1,t),document.execCommand("insertText",!1,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:o,endSelectionOffset:s}=this.getStartAndEndSelection();return{start:this.findSelectionIndex(e,o),end:this.findSelectionIndex(t,s)}}findSelectionIndex(e,t){let o=this.iterateChildren(this.el),s=0,n=o.next();for(;!n.done&&n.value!==e;)n.value.hasChildNodes()||n.value.textContent&&(s+=n.value.textContent.length),n=o.next();if(n.value===e)if(n.value.hasChildNodes()){const e=[...n.value.childNodes].slice(0,t);for(const t of e)t.textContent&&(s+=t.textContent.length)}else s+=t;return s}getStartAndEndSelection(){const e=document.getSelection().getRangeAt(0);return{startElement:e.startContainer,startSelectionOffset:e.startOffset,endElement:e.endContainer,endSelectionOffset:e.endOffset}}}const kl=s.Component,{useRef:_l,useState:Il}=s.hooks,{xml:Ol,css:Dl}=s.tags,$l="#3da4ab",Ul="#02c39a",Fl={OPERATOR:$l,NUMBER:Ul,STRING:"#f6cd61",BOOLEAN:Ul,FUNCTION:"#4a4e4d",DEBUGGER:$l,LEFT_PAREN:$l,RIGHT_PAREN:$l},Pl=Ol`
728
734
  <div class="o-composer-container" t-att-style="containerStyle">
729
735
  <div class="o-composer"
730
736
  t-att-style="composerStyle"
@@ -748,7 +754,7 @@
748
754
  t-on-completed="onCompleted"
749
755
  />
750
756
  </div>
751
- `,Fl=Il`
757
+ `,Bl=Dl`
752
758
  .o-composer-container {
753
759
  box-sizing: border-box;
754
760
  position: absolute;
@@ -769,7 +775,7 @@
769
775
  }
770
776
  }
771
777
  }
772
- `;class Pl extends Al{constructor(){super(...arguments),this.composerRef=Nl("o_composer"),this.autoCompleteRef=Nl("o_autocomplete_provider"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.selectionEnd=0,this.selectionStart=0,this.autoCompleteState=kl({showProvider:!1,provider:"functions",search:""}),this.tokenAtCursor=void 0,this.shouldProcessInputEvents=!1,this.isDone=!1,this.refSelectionStart=0,this.tokens=[],this.keyMapping={Enter:this.processEnterKey,Escape:this.processEscapeKey,Tab:e=>this.processTabKey(e),F2:()=>console.warn("Not implemented"),F4:()=>console.warn("Not implemented"),ArrowUp:this.processArrowKeys,ArrowDown:this.processArrowKeys,ArrowLeft:this.processArrowKeys,ArrowRight:this.processArrowKeys},this.contentHelper=new Ml(this.composerRef.el);const[e,t]=this.getters.getPosition();this.zone=this.getters.expandZone({left:e,right:e,top:t,bottom:t}),this.rect=this.getters.getRect(this.zone,this.props.viewport)}mounted(){P.composer=this;const e=this.composerRef.el;this.contentHelper.updateEl(e);const t=this.getters.getCurrentContent();t&&(this.contentHelper.insertText(t),this.contentHelper.selectRange(t.length,t.length)),this.processContent(),e.style.width=Math.max(e.scrollWidth+10,this.rect[2]+.5)+"px",e.style.height=this.rect[3]+.5+"px"}willUnmount(){delete P.composer,this.trigger("composer-unmounted")}get containerStyle(){const e=this.getters.getCurrentStyle(),[t,o,,s]=this.rect,n=`font-weight:${e.bold?"bold":500};`,i=e.italic?"font-style: italic;":"",r=e.strikethrough?"text-decoration:line-through;":"";return`left: ${t-1}px;\n top:${o}px;\n height:${s}px;\n font-size:${Qn[e.fontSize||10]}px;\n ${n}${i}${r}`}get composerStyle(){const e=this.getters.getCurrentStyle(),t=this.getters.getActiveCell()||{type:"text"},o=this.rect[3];return`text-align:${"align"in e?e.align:"number"===t.type?"right":"left"};\n line-height:${o-1.5}px;`}processArrowKeys(e){if("selecting"===this.getters.getEditionMode())return void e.preventDefault();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())}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_SELECTION");const o=e.shiftKey?-1:1;this.isDone=!0,this.dispatch("MOVE_POSITION",{deltaX:o,deltaY:0})}processEnterKey(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)}this.dispatch("STOP_EDITION"),this.dispatch("MOVE_POSITION",{deltaX:0,deltaY:e.shiftKey?-1:1}),this.isDone=!0}processEscapeKey(){this.dispatch("STOP_EDITION",{cancel:!0}),this.isDone=!0}onKeydown(e){let t=this.keyMapping[e.key];if(t)return t.call(this,e);e.stopPropagation()}onInput(e){if(this.isDone||!this.shouldProcessInputEvents)return;const t=this.composerRef.el;t.clientWidth!==t.scrollWidth&&(t.style.width=`${t.scrollWidth+20}px`);const o=t.childNodes.length?t.textContent:"";this.dispatch("SET_CURRENT_CONTENT",{content:o})}onKeyup(e){this.isDone||["Control","Shift","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Enter"].includes(e.key)||(e.preventDefault(),e.stopPropagation(),this.autoCompleteState.showProvider=!1,this.autoCompleteState.search="",this.dispatch("STOP_COMPOSER_SELECTION"),e.ctrlKey&&" "===e.key?this.autoCompleteState.showProvider=!0:(this.processContent(),this.processTokenAtCursor()))}onClick(e){e.stopPropagation(),this.processContent(),this.processTokenAtCursor()}onCompleted(e){this.autoComplete(e.detail.text)}processContent(){this.shouldProcessInputEvents=!1;let e=this.getters.getCurrentContent();if(this.tokenAtCursor=void 0,e.startsWith("=")){this.saveSelection(),this.contentHelper.removeAll(),this.contentHelper.selectRange(0,0),this.dispatch("REMOVE_ALL_HIGHLIGHTS");const t={};let o=0;this.tokens=ua(e),this.selectionStart===this.selectionEnd&&0===this.selectionEnd?this.tokenAtCursor=void 0:this.tokenAtCursor=this.tokens.find((e=>e.start<=this.selectionStart&&e.end>=this.selectionEnd));for(let e of this.tokens)switch(e.type){case"OPERATOR":case"NUMBER":case"FUNCTION":case"COMMA":case"BOOLEAN":this.contentHelper.insertText(e.value,$l[e.type]);break;case"SYMBOL":let s=e.value;const[n,i]=s.split("!").reverse();if(Yr.test(n)){const e=U(i?`${i}`:`${this.getters.getSheetName(this.getters.getEditionSheet())}`)+"!"+n.replace(/\$/g,"");t[e]||(t[e]=g[o],o=++o%g.length),this.contentHelper.insertText(s,t[e])}else this.contentHelper.insertText(s);break;case"LEFT_PAREN":case"RIGHT_PAREN":this.tokenAtCursor&&["LEFT_PAREN","RIGHT_PAREN"].includes(this.tokenAtCursor.type)&&this.tokenAtCursor.parenIndex&&this.tokenAtCursor.parenIndex===e.parenIndex?this.contentHelper.insertText(e.value,"pink"):this.contentHelper.insertText(e.value);break;default:this.contentHelper.insertText(e.value)}this.contentHelper.selectRange(this.selectionStart,this.selectionEnd),Object.keys(t).length&&this.dispatch("ADD_HIGHLIGHTS",{ranges:t})}this.shouldProcessInputEvents=!0}processTokenAtCursor(){this.tokenAtCursor&&(["BOOLEAN","FUNCTION","SYMBOL"].includes(this.tokenAtCursor.type)?this.tokenAtCursor.value.length>0&&(this.autoCompleteState.search=this.tokenAtCursor.value,this.autoCompleteState.showProvider=!0):["COMMA","LEFT_PAREN","OPERATOR","SPACE"].includes(this.tokenAtCursor.type)&&(this.dispatch("START_COMPOSER_SELECTION"),this.refSelectionStart=this.selectionStart))}addText(e){this.contentHelper.selectRange(this.selectionStart,this.selectionEnd),this.contentHelper.insertText(e),this.selectionStart=this.selectionEnd=this.selectionStart+e.length,this.contentHelper.selectRange(this.selectionStart,this.selectionEnd)}addTextFromSelection(){const e=this.getters.getSelectedZones()[0];let t=this.getters.zoneToXC(e);if(this.refSelectionStart&&(this.selectionStart=this.refSelectionStart),this.getters.getEditionSheet()!==this.getters.getActiveSheet()){t=`${U(this.getters.getSheetName(this.getters.getActiveSheet()))}!${t}`}this.addText(t),this.processContent()}autoComplete(e){if(this.saveSelection(),e){if(this.tokenAtCursor){let t=this.tokenAtCursor.end,o=this.tokenAtCursor.end;if(["SYMBOL","FUNCTION"].includes(this.tokenAtCursor.type)&&(t=this.tokenAtCursor.start),this.autoCompleteState.provider&&this.tokens.length){e+="(";const t=this.tokens.map((e=>e.start)).indexOf(this.tokenAtCursor.start);if(t+1<this.tokens.length){"LEFT_PAREN"===this.tokens[t+1].type&&o++}}this.selectionStart=t,this.selectionEnd=o}this.addText(e)}this.autoCompleteState.search="",this.autoCompleteState.showProvider=!1,this.processContent(),this.processTokenAtCursor()}saveSelection(){const e=this.contentHelper.getCurrentSelection();this.selectionStart=e.start,this.selectionEnd=e.end}}Pl.template=Ul,Pl.style=Fl,Pl.components={TextValueProvider:Rl};const{xml:Bl,css:zl}=s.tags,{useState:Zl}=s,Hl=Bl`<div>
778
+ `;class Zl extends kl{constructor(){super(...arguments),this.composerRef=_l("o_composer"),this.autoCompleteRef=_l("o_autocomplete_provider"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.selectionEnd=0,this.selectionStart=0,this.autoCompleteState=Il({showProvider:!1,provider:"functions",search:""}),this.tokenAtCursor=void 0,this.shouldProcessInputEvents=!1,this.isDone=!1,this.refSelectionStart=0,this.tokens=[],this.keyMapping={Enter:this.processEnterKey,Escape:this.processEscapeKey,Tab:e=>this.processTabKey(e),F2:()=>console.warn("Not implemented"),F4:()=>console.warn("Not implemented"),ArrowUp:this.processArrowKeys,ArrowDown:this.processArrowKeys,ArrowLeft:this.processArrowKeys,ArrowRight:this.processArrowKeys},this.contentHelper=new Nl(this.composerRef.el);const[e,t]=this.getters.getPosition();this.zone=this.getters.expandZone({left:e,right:e,top:t,bottom:t}),this.rect=this.getters.getRect(this.zone,this.props.viewport)}mounted(){P.composer=this;const e=this.composerRef.el;this.contentHelper.updateEl(e);const t=this.getters.getCurrentContent();t&&(this.contentHelper.insertText(t),this.contentHelper.selectRange(t.length,t.length)),this.processContent(),e.style.width=Math.max(e.scrollWidth+10,this.rect[2]+.5)+"px",e.style.height=this.rect[3]+.5+"px"}willUnmount(){delete P.composer,this.trigger("composer-unmounted")}get containerStyle(){const e=this.getters.getCurrentStyle(),[t,o,,s]=this.rect,n=`font-weight:${e.bold?"bold":500};`,i=e.italic?"font-style: italic;":"",r=e.strikethrough?"text-decoration:line-through;":"";return`left: ${t-1}px;\n top:${o}px;\n height:${s}px;\n font-size:${Qn[e.fontSize||10]}px;\n ${n}${i}${r}`}get composerStyle(){const e=this.getters.getCurrentStyle(),t=this.getters.getActiveCell()||{type:"text"},o=this.rect[3];return`text-align:${"align"in e?e.align:"number"===t.type?"right":"left"};\n line-height:${o-1.5}px;`}processArrowKeys(e){if("selecting"===this.getters.getEditionMode())return void e.preventDefault();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())}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_SELECTION");const o=e.shiftKey?-1:1;this.isDone=!0,this.dispatch("MOVE_POSITION",{deltaX:o,deltaY:0})}processEnterKey(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)}this.dispatch("STOP_EDITION"),this.dispatch("MOVE_POSITION",{deltaX:0,deltaY:e.shiftKey?-1:1}),this.isDone=!0}processEscapeKey(){this.dispatch("STOP_EDITION",{cancel:!0}),this.isDone=!0}onKeydown(e){let t=this.keyMapping[e.key];if(t)return t.call(this,e);e.stopPropagation()}onInput(e){if(this.isDone||!this.shouldProcessInputEvents)return;const t=this.composerRef.el;t.clientWidth!==t.scrollWidth&&(t.style.width=`${t.scrollWidth+20}px`);const o=t.childNodes.length?t.textContent:"";this.dispatch("SET_CURRENT_CONTENT",{content:o})}onKeyup(e){this.isDone||["Control","Shift","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Enter"].includes(e.key)||(e.preventDefault(),e.stopPropagation(),this.autoCompleteState.showProvider=!1,this.autoCompleteState.search="",this.dispatch("STOP_COMPOSER_SELECTION"),e.ctrlKey&&" "===e.key?this.autoCompleteState.showProvider=!0:(this.processContent(),this.processTokenAtCursor()))}onClick(e){e.stopPropagation(),this.processContent(),this.processTokenAtCursor()}onCompleted(e){this.autoComplete(e.detail.text)}processContent(){this.shouldProcessInputEvents=!1;let e=this.getters.getCurrentContent();if(this.tokenAtCursor=void 0,e.startsWith("=")){this.saveSelection(),this.contentHelper.removeAll(),this.contentHelper.selectRange(0,0),this.dispatch("REMOVE_ALL_HIGHLIGHTS");const t={};let o=0;this.tokens=pa(e),this.selectionStart===this.selectionEnd&&0===this.selectionEnd?this.tokenAtCursor=void 0:this.tokenAtCursor=this.tokens.find((e=>e.start<=this.selectionStart&&e.end>=this.selectionEnd));for(let e of this.tokens)switch(e.type){case"OPERATOR":case"NUMBER":case"FUNCTION":case"COMMA":case"BOOLEAN":this.contentHelper.insertText(e.value,Fl[e.type]);break;case"SYMBOL":let s=e.value;const[n,i]=s.split("!").reverse();if(Kr.test(n)){const e=U(i?`${i}`:`${this.getters.getSheetName(this.getters.getEditionSheet())}`)+"!"+n.replace(/\$/g,"");t[e]||(t[e]=g[o],o=++o%g.length),this.contentHelper.insertText(s,t[e])}else this.contentHelper.insertText(s);break;case"LEFT_PAREN":case"RIGHT_PAREN":this.tokenAtCursor&&["LEFT_PAREN","RIGHT_PAREN"].includes(this.tokenAtCursor.type)&&this.tokenAtCursor.parenIndex&&this.tokenAtCursor.parenIndex===e.parenIndex?this.contentHelper.insertText(e.value,"pink"):this.contentHelper.insertText(e.value);break;default:this.contentHelper.insertText(e.value)}this.contentHelper.selectRange(this.selectionStart,this.selectionEnd),Object.keys(t).length&&this.dispatch("ADD_HIGHLIGHTS",{ranges:t})}this.shouldProcessInputEvents=!0}processTokenAtCursor(){this.tokenAtCursor&&(["BOOLEAN","FUNCTION","SYMBOL"].includes(this.tokenAtCursor.type)?this.tokenAtCursor.value.length>0&&(this.autoCompleteState.search=this.tokenAtCursor.value,this.autoCompleteState.showProvider=!0):["COMMA","LEFT_PAREN","OPERATOR","SPACE"].includes(this.tokenAtCursor.type)&&(this.dispatch("START_COMPOSER_SELECTION"),this.refSelectionStart=this.selectionStart))}addText(e){this.contentHelper.selectRange(this.selectionStart,this.selectionEnd),this.contentHelper.insertText(e),this.selectionStart=this.selectionEnd=this.selectionStart+e.length,this.contentHelper.selectRange(this.selectionStart,this.selectionEnd)}addTextFromSelection(){const e=this.getters.getSelectedZones()[0];let t=this.getters.zoneToXC(e);if(this.refSelectionStart&&(this.selectionStart=this.refSelectionStart),this.getters.getEditionSheet()!==this.getters.getActiveSheet()){t=`${U(this.getters.getSheetName(this.getters.getActiveSheet()))}!${t}`}this.addText(t),this.processContent()}autoComplete(e){if(this.saveSelection(),e){if(this.tokenAtCursor){let t=this.tokenAtCursor.end,o=this.tokenAtCursor.end;if(["SYMBOL","FUNCTION"].includes(this.tokenAtCursor.type)&&(t=this.tokenAtCursor.start),this.autoCompleteState.provider&&this.tokens.length){e+="(";const t=this.tokens.map((e=>e.start)).indexOf(this.tokenAtCursor.start);if(t+1<this.tokens.length){"LEFT_PAREN"===this.tokens[t+1].type&&o++}}this.selectionStart=t,this.selectionEnd=o}this.addText(e)}this.autoCompleteState.search="",this.autoCompleteState.showProvider=!1,this.processContent(),this.processTokenAtCursor()}saveSelection(){const e=this.contentHelper.getCurrentSelection();this.selectionStart=e.start,this.selectionEnd=e.end}}Zl.template=Pl,Zl.style=Bl,Zl.components={TextValueProvider:Al};const{xml:zl,css:Hl}=s.tags,{useState:Gl}=s,Vl=zl`<div>
773
779
  <t t-foreach="getFigures()" t-as="info" t-key="info.id">
774
780
  <div class="o-figure-wrapper"
775
781
  t-att-style="getStyle(info)"
@@ -797,7 +803,7 @@
797
803
  </div>
798
804
  </t>
799
805
  </div>
800
- `,Gl=zl`
806
+ `,jl=Hl`
801
807
  .o-figure-wrapper {
802
808
  overflow: hidden;
803
809
  }
@@ -870,7 +876,7 @@
870
876
  }
871
877
  }
872
878
  }
873
- `;class Vl extends t.Component{constructor(){super(...arguments),this.figureRegistry=xn,this.dnd=Zl({figureId:"",x:0,y:0,width:0,height:0}),this.getters=this.env.getters,this.dispatch=this.env.dispatch}getFigures(){const e=this.getters.getSelectedFigureId();return this.getters.getFigures(this.props.viewport).map((t=>({id:t.id,isSelected:t.id===e,figure:t})))}getDims(e){const{figure:t,isSelected:o}=e,s=2*(o?2:1),{width:n,height:i}=o&&this.dnd.figureId?this.dnd:t;return`width:${n+s}px;height:${i+s}px`}getStyle(e){const{figure:t,isSelected:o}=e,{offsetX:s,offsetY:n}=this.props.viewport,i=t.id===(o&&this.dnd.figureId)?this.dnd:t,{width:r,height:a}=i;let l=i.x-s+h-1,u=i.y-n+c-1;const d=Math.max(0,h-l);l+=d;const p=Math.max(0,c-u);if(u+=p,r<0||a<0)return"position:absolute;display:none;";const g=10+(o?2:1);return`position:absolute; top:${u+1}px; left:${l+1}px; width:${r-d+g}px; height:${a-p+g}px`}mounted(){this.render()}resize(e,t,o,s){s.stopPropagation();const n=s.clientX,i=s.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;hl((s=>{const r=t*(s.clientX-n),a=o*(s.clientY-i);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),o<0&&(this.dnd.y=e.y-a)}),(s=>{this.dnd.figureId="";const n={id:e.id,x:this.dnd.x,y:this.dnd.y};t&&(n.width=this.dnd.width),o&&(n.height=this.dnd.height),this.dispatch("UPDATE_FIGURE",n)}))}onMouseDown(e,t){if(t.button>0)return;this.dispatch("SELECT_FIGURE",{id:e.id});const o=t.clientX,s=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;hl((t=>{this.dnd.x=Math.max(e.x-o+t.clientX,0),this.dnd.y=Math.max(e.y-s+t.clientY,0)}),(t=>{this.dnd.figureId="",this.dispatch("UPDATE_FIGURE",{id:e.id,x:this.dnd.x,y:this.dnd.y})}))}onKeyDown(e,t){if("Delete"===t.key)t.preventDefault(),this.dispatch("DELETE_FIGURE",{id:e.id}),this.trigger("figure-deleted")}}Vl.template=Hl,Vl.style=Gl,Vl.components={};const jl=s.Component,{xml:ql,css:Wl}=s.tags,{useState:Yl}=s.hooks;class Xl extends jl{constructor(){super(...arguments),this.PADDING=0,this.MAX_SIZE_MARGIN=0,this.MIN_ELEMENT_SIZE=0,this.lastSelectedElement=null,this.lastElement=null,this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.state=Yl({isActive:!1,isResizing:!1,activeElement:0,styleValue:0,delta:0})}_computeHandleDisplay(e){const t=this._getEvOffset(e),o=this._getElementIndex(t);if(o<0)return;const s=this._getElement(o),n=this._getStateOffset();t-(s.start-n)<this.PADDING&&o!==this._getViewportOffset()?(this.state.isActive=!0,this.state.styleValue=s.start-n-this._getHeaderSize(),this.state.activeElement=o-1):s.end-n-t<this.PADDING?(this.state.isActive=!0,this.state.styleValue=s.end-n-this._getHeaderSize(),this.state.activeElement=o):this.state.isActive=!1}onMouseMove(e){this.state.isResizing||this._computeHandleDisplay(e)}onMouseLeave(){this.state.isActive=this.state.isResizing}onDblClick(){this._fitElementSize(this.state.activeElement),this.state.isResizing=!1}onMouseDown(e){this.state.isResizing=!0,this.state.delta=0;const t=this._getClientPosition(e),o=this.state.styleValue,s=this._getElement(this.state.activeElement).size,n=o-s+this.MIN_ELEMENT_SIZE,i=this._getMaxSize();hl((e=>{this.state.delta=this._getClientPosition(e)-t,this.state.styleValue=o+this.state.delta,this.state.styleValue<n&&(this.state.styleValue=n,this.state.delta=this.MIN_ELEMENT_SIZE-s),this.state.styleValue>i&&(this.state.styleValue=i,this.state.delta=i-o)}),(e=>{this.state.isResizing=!1,0!==this.state.delta&&this._updateSize()}))}select(e){if(e.button>0)return;const t=this._getElementIndex(this._getEvOffset(e));if(t<0)return;this.lastElement=t,this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this._increaseSelection(t):(this.lastSelectedElement=t,this._selectElement(t,e.ctrlKey));const o=this._getClientPosition(e),s=this._getEvOffset(e);hl((e=>{const t=this._getClientPosition(e)-o+s,n=this._getElementIndex(t);n!==this.lastElement&&-1!==n&&(this._increaseSelection(n),this.lastElement=n)}),(()=>{this.lastElement=null,this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION")}))}onMouseUp(e){this.lastElement=null}onContextMenu(e){e.preventDefault();const t=this._getElementIndex(this._getEvOffset(e));if(t<0)return;this._getActiveElements().has(t)||(this.lastSelectedElement=t,this._selectElement(t,!1));const o=this._getType(),{x:s,y:n}=this._getXY(e);this.trigger("open-contextmenu",{type:o,x:s,y:n})}}class Kl extends Xl{constructor(){super(...arguments),this.PADDING=15,this.MAX_SIZE_MARGIN=90,this.MIN_ELEMENT_SIZE=5}_getEvOffset(e){return e.offsetX+h}_getStateOffset(){return this.props.viewport.offsetX-h}_getViewportOffset(){return this.props.viewport.left}_getClientPosition(e){return e.clientX}_getElementIndex(e){return this.getters.getColIndex(e,this.props.viewport.left)}_getElement(e){return this.getters.getCol(this.getters.getActiveSheet(),e)}_getBottomRightValue(e){return e.end}_getHeaderSize(){return h}_getMaxSize(){return this.el.clientWidth}_updateSize(){const e=this.state.activeElement,t=this.state.delta+this._getElement(e).size,o=this.getters.getActiveCols();this.dispatch("RESIZE_COLUMNS",{sheet:this.getters.getActiveSheet(),cols:o.has(e)?[...o]:[e],size:t})}_selectElement(e,t){this.dispatch("SELECT_COLUMN",{index:e,createRange:t})}_increaseSelection(e){this.dispatch("SELECT_COLUMN",{index:e,updateRange:!0})}_fitElementSize(e){const t=this.getters.getActiveCols();this.dispatch("AUTORESIZE_COLUMNS",{sheet:this.getters.getActiveSheet(),cols:t.has(e)?[...t]:[e]})}_getType(){return"COL"}_getActiveElements(){return this.getters.getActiveCols()}_getXY(e){return{x:e.offsetX+h,y:e.offsetY}}}Kl.template=ql`
879
+ `;class ql extends t.Component{constructor(){super(...arguments),this.figureRegistry=xn,this.dnd=Gl({figureId:"",x:0,y:0,width:0,height:0}),this.getters=this.env.getters,this.dispatch=this.env.dispatch}getFigures(){const e=this.getters.getSelectedFigureId();return this.getters.getFigures(this.props.viewport).map((t=>({id:t.id,isSelected:t.id===e,figure:t})))}getDims(e){const{figure:t,isSelected:o}=e,s=2*(o?2:1),{width:n,height:i}=o&&this.dnd.figureId?this.dnd:t;return`width:${n+s}px;height:${i+s}px`}getStyle(e){const{figure:t,isSelected:o}=e,{offsetX:s,offsetY:n}=this.props.viewport,i=t.id===(o&&this.dnd.figureId)?this.dnd:t,{width:r,height:a}=i;let l=i.x-s+h-1,u=i.y-n+c-1;const d=Math.max(0,h-l);l+=d;const p=Math.max(0,c-u);if(u+=p,r<0||a<0)return"position:absolute;display:none;";const g=10+(o?2:1);return`position:absolute; top:${u+1}px; left:${l+1}px; width:${r-d+g}px; height:${a-p+g}px`}mounted(){this.render()}resize(e,t,o,s){s.stopPropagation();const n=s.clientX,i=s.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;dl((s=>{const r=t*(s.clientX-n),a=o*(s.clientY-i);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),o<0&&(this.dnd.y=e.y-a)}),(s=>{this.dnd.figureId="";const n={id:e.id,x:this.dnd.x,y:this.dnd.y};t&&(n.width=this.dnd.width),o&&(n.height=this.dnd.height),this.dispatch("UPDATE_FIGURE",n)}))}onMouseDown(e,t){if(t.button>0)return;this.dispatch("SELECT_FIGURE",{id:e.id});const o=t.clientX,s=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;dl((t=>{this.dnd.x=Math.max(e.x-o+t.clientX,0),this.dnd.y=Math.max(e.y-s+t.clientY,0)}),(t=>{this.dnd.figureId="",this.dispatch("UPDATE_FIGURE",{id:e.id,x:this.dnd.x,y:this.dnd.y})}))}onKeyDown(e,t){if("Delete"===t.key)t.preventDefault(),this.dispatch("DELETE_FIGURE",{id:e.id}),this.trigger("figure-deleted")}}ql.template=Vl,ql.style=jl,ql.components={};const Wl=s.Component,{xml:Yl,css:Xl}=s.tags,{useState:Kl}=s.hooks;class Jl extends Wl{constructor(){super(...arguments),this.PADDING=0,this.MAX_SIZE_MARGIN=0,this.MIN_ELEMENT_SIZE=0,this.lastSelectedElement=null,this.lastElement=null,this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.state=Kl({isActive:!1,isResizing:!1,activeElement:0,styleValue:0,delta:0})}_computeHandleDisplay(e){const t=this._getEvOffset(e),o=this._getElementIndex(t);if(o<0)return;const s=this._getElement(o),n=this._getStateOffset();t-(s.start-n)<this.PADDING&&o!==this._getViewportOffset()?(this.state.isActive=!0,this.state.styleValue=s.start-n-this._getHeaderSize(),this.state.activeElement=o-1):s.end-n-t<this.PADDING?(this.state.isActive=!0,this.state.styleValue=s.end-n-this._getHeaderSize(),this.state.activeElement=o):this.state.isActive=!1}onMouseMove(e){this.state.isResizing||this._computeHandleDisplay(e)}onMouseLeave(){this.state.isActive=this.state.isResizing}onDblClick(){this._fitElementSize(this.state.activeElement),this.state.isResizing=!1}onMouseDown(e){this.state.isResizing=!0,this.state.delta=0;const t=this._getClientPosition(e),o=this.state.styleValue,s=this._getElement(this.state.activeElement).size,n=o-s+this.MIN_ELEMENT_SIZE,i=this._getMaxSize();dl((e=>{this.state.delta=this._getClientPosition(e)-t,this.state.styleValue=o+this.state.delta,this.state.styleValue<n&&(this.state.styleValue=n,this.state.delta=this.MIN_ELEMENT_SIZE-s),this.state.styleValue>i&&(this.state.styleValue=i,this.state.delta=i-o)}),(e=>{this.state.isResizing=!1,0!==this.state.delta&&this._updateSize()}))}select(e){if(e.button>0)return;const t=this._getElementIndex(this._getEvOffset(e));if(t<0)return;this.lastElement=t,this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this._increaseSelection(t):(this.lastSelectedElement=t,this._selectElement(t,e.ctrlKey));const o=this._getClientPosition(e),s=this._getEvOffset(e);dl((e=>{const t=this._getClientPosition(e)-o+s,n=this._getElementIndex(t);n!==this.lastElement&&-1!==n&&(this._increaseSelection(n),this.lastElement=n)}),(()=>{this.lastElement=null,this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION")}))}onMouseUp(e){this.lastElement=null}onContextMenu(e){e.preventDefault();const t=this._getElementIndex(this._getEvOffset(e));if(t<0)return;this._getActiveElements().has(t)||(this.lastSelectedElement=t,this._selectElement(t,!1));const o=this._getType(),{x:s,y:n}=this._getXY(e);this.trigger("open-contextmenu",{type:o,x:s,y:n})}}class Ql extends Jl{constructor(){super(...arguments),this.PADDING=15,this.MAX_SIZE_MARGIN=90,this.MIN_ELEMENT_SIZE=5}_getEvOffset(e){return e.offsetX+h}_getStateOffset(){return this.props.viewport.offsetX-h}_getViewportOffset(){return this.props.viewport.left}_getClientPosition(e){return e.clientX}_getElementIndex(e){return this.getters.getColIndex(e,this.props.viewport.left)}_getElement(e){return this.getters.getCol(this.getters.getActiveSheet(),e)}_getBottomRightValue(e){return e.end}_getHeaderSize(){return h}_getMaxSize(){return this.el.clientWidth}_updateSize(){const e=this.state.activeElement,t=this.state.delta+this._getElement(e).size,o=this.getters.getActiveCols();this.dispatch("RESIZE_COLUMNS",{sheet:this.getters.getActiveSheet(),cols:o.has(e)?[...o]:[e],size:t})}_selectElement(e,t){this.dispatch("SELECT_COLUMN",{index:e,createRange:t})}_increaseSelection(e){this.dispatch("SELECT_COLUMN",{index:e,updateRange:!0})}_fitElementSize(e){const t=this.getters.getActiveCols();this.dispatch("AUTORESIZE_COLUMNS",{sheet:this.getters.getActiveSheet(),cols:t.has(e)?[...t]:[e]})}_getType(){return"COL"}_getActiveElements(){return this.getters.getActiveCols()}_getXY(e){return{x:e.offsetX+h,y:e.offsetY}}}Ql.template=Yl`
874
880
  <div class="o-col-resizer" t-on-mousemove.self="onMouseMove" t-on-mouseleave="onMouseLeave" t-on-mousedown.self.prevent="select"
875
881
  t-on-mouseup.self="onMouseUp" t-on-contextmenu.self="onContextMenu">
876
882
  <t t-if="state.isActive">
@@ -879,7 +885,7 @@
879
885
  <div class="dragging" t-if="state.isResizing"/>
880
886
  </div>
881
887
  </t>
882
- </div>`,Kl.style=Wl`
888
+ </div>`,Ql.style=Xl`
883
889
  .o-col-resizer {
884
890
  position: absolute;
885
891
  top: 0;
@@ -902,7 +908,7 @@
902
908
  background-color: #3266ca;
903
909
  }
904
910
  }
905
- `;class Jl extends Xl{constructor(){super(...arguments),this.PADDING=5,this.MAX_SIZE_MARGIN=60,this.MIN_ELEMENT_SIZE=10}_getEvOffset(e){return e.offsetY+c}_getStateOffset(){return this.props.viewport.offsetY-c}_getViewportOffset(){return this.props.viewport.top}_getClientPosition(e){return e.clientY}_getElementIndex(e){return this.getters.getRowIndex(e,this.props.viewport.top)}_getElement(e){return this.getters.getRow(this.getters.getActiveSheet(),e)}_getHeaderSize(){return c}_getMaxSize(){return this.el.clientHeight}_updateSize(){const e=this.state.activeElement,t=this.state.delta+this._getElement(e).size,o=this.getters.getActiveRows();this.dispatch("RESIZE_ROWS",{sheet:this.getters.getActiveSheet(),rows:o.has(e)?[...o]:[e],size:t})}_selectElement(e,t){this.dispatch("SELECT_ROW",{index:e,createRange:t})}_increaseSelection(e){this.dispatch("SELECT_ROW",{index:e,updateRange:!0})}_fitElementSize(e){const t=this.getters.getActiveRows();this.dispatch("AUTORESIZE_ROWS",{sheet:this.getters.getActiveSheet(),rows:t.has(e)?[...t]:[e]})}_getType(){return"ROW"}_getActiveElements(){return this.getters.getActiveRows()}_getXY(e){return{x:e.offsetX,y:e.offsetY+c}}}Jl.template=ql`
911
+ `;class ec extends Jl{constructor(){super(...arguments),this.PADDING=5,this.MAX_SIZE_MARGIN=60,this.MIN_ELEMENT_SIZE=10}_getEvOffset(e){return e.offsetY+c}_getStateOffset(){return this.props.viewport.offsetY-c}_getViewportOffset(){return this.props.viewport.top}_getClientPosition(e){return e.clientY}_getElementIndex(e){return this.getters.getRowIndex(e,this.props.viewport.top)}_getElement(e){return this.getters.getRow(this.getters.getActiveSheet(),e)}_getHeaderSize(){return c}_getMaxSize(){return this.el.clientHeight}_updateSize(){const e=this.state.activeElement,t=this.state.delta+this._getElement(e).size,o=this.getters.getActiveRows();this.dispatch("RESIZE_ROWS",{sheet:this.getters.getActiveSheet(),rows:o.has(e)?[...o]:[e],size:t})}_selectElement(e,t){this.dispatch("SELECT_ROW",{index:e,createRange:t})}_increaseSelection(e){this.dispatch("SELECT_ROW",{index:e,updateRange:!0})}_fitElementSize(e){const t=this.getters.getActiveRows();this.dispatch("AUTORESIZE_ROWS",{sheet:this.getters.getActiveSheet(),rows:t.has(e)?[...t]:[e]})}_getType(){return"ROW"}_getActiveElements(){return this.getters.getActiveRows()}_getXY(e){return{x:e.offsetX,y:e.offsetY+c}}}ec.template=Yl`
906
912
  <div class="o-row-resizer" t-on-mousemove.self="onMouseMove" t-on-mouseleave="onMouseLeave" t-on-mousedown.self.prevent="select"
907
913
  t-on-mouseup.self="onMouseUp" t-on-contextmenu.self="onContextMenu">
908
914
  <t t-if="state.isActive">
@@ -911,7 +917,7 @@
911
917
  <div class="dragging" t-if="state.isResizing"/>
912
918
  </div>
913
919
  </t>
914
- </div>`,Jl.style=Wl`
920
+ </div>`,ec.style=Xl`
915
921
  .o-row-resizer {
916
922
  position: absolute;
917
923
  top: ${c}px;
@@ -935,12 +941,12 @@
935
941
  background-color: #3266ca;
936
942
  }
937
943
  }
938
- `;class Ql extends jl{selectAll(){this.env.dispatch("SELECT_ALL")}}Ql.template=ql`
944
+ `;class tc extends Wl{selectAll(){this.env.dispatch("SELECT_ALL")}}tc.template=Yl`
939
945
  <div class="o-overlay">
940
946
  <ColResizer viewport="props.viewport"/>
941
947
  <RowResizer viewport="props.viewport"/>
942
948
  <div class="all" t-on-mousedown.self="selectAll"/>
943
- </div>`,Ql.style=Wl`
949
+ </div>`,tc.style=Xl`
944
950
  .o-overlay {
945
951
  .all {
946
952
  position: absolute;
@@ -951,7 +957,7 @@
951
957
  height: ${c}px;
952
958
  }
953
959
  }
954
- `,Ql.components={ColResizer:Kl,RowResizer:Jl};class ec{constructor(e,t){this.el=e,this.direction=t}get scroll(){return"horizontal"===this.direction?this.el.scrollLeft:this.el.scrollTop}set scroll(e){"horizontal"===this.direction?this.el.scrollLeft=e:this.el.scrollTop=e}}const{useState:tc}=s,oc=s.Component,{xml:sc,css:nc}=s.tags,{useRef:ic,onMounted:rc,onWillUnmount:ac}=s.hooks,lc={ROW:Xn,COL:Yn,CELL:Wn},cc=["CTRL+C","CTRL+V"];const hc=sc`
960
+ `,tc.components={ColResizer:Ql,RowResizer:ec};class oc{constructor(e,t){this.el=e,this.direction=t}get scroll(){return"horizontal"===this.direction?this.el.scrollLeft:this.el.scrollTop}set scroll(e){"horizontal"===this.direction?this.el.scrollLeft=e:this.el.scrollTop=e}}const{useState:sc}=s,nc=s.Component,{xml:ic,css:rc}=s.tags,{useRef:ac,onMounted:lc,onWillUnmount:cc}=s.hooks,hc={ROW:Xn,COL:Yn,CELL:Wn},uc=["CTRL+C","CTRL+V"];const dc=ic`
955
961
  <div class="o-grid" t-on-click="focus" t-on-keydown="onKeydown" t-on-wheel="onMouseWheel">
956
962
  <t t-if="getters.getEditionMode() !== 'inactive'">
957
963
  <Composer t-ref="composer" t-on-composer-unmounted="focus" viewport="snappedViewport"/>
@@ -981,7 +987,7 @@
981
987
  <div class="o-scrollbar horizontal" t-on-scroll="onScroll" t-ref="hscrollbar">
982
988
  <div t-attf-style="height:1px;width:{{gridSize[0]}}px"/>
983
989
  </div>
984
- </div>`,uc=nc`
990
+ </div>`,pc=rc`
985
991
  .o-grid {
986
992
  position: relative;
987
993
  overflow: hidden;
@@ -1025,7 +1031,7 @@
1025
1031
  }
1026
1032
  }
1027
1033
  }
1028
- `;class dc extends oc{constructor(){super(...arguments),this.menuState=tc({isOpen:!1,position:null,menuItems:[]}),this.composer=ic("composer"),this.vScrollbarRef=ic("vscrollbar"),this.hScrollbarRef=ic("hscrollbar"),this.canvas=ic("canvas"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.currentPosition=this.getters.getPosition(),this.currentSheet=this.getters.getActiveSheet(),this.currentPositionInViewport=!1,this.clickedCol=0,this.clickedRow=0,this.viewport={width:0,height:0,offsetX:0,offsetY:0,left:0,top:0,right:0,bottom:0},this.snappedViewport=this.viewport,this.errorTooltip=function(e,t){const{browser:o,getters:s}=e,{Date:n,setInterval:i,clearInterval:r}=o;let a,l,c=0,h=0,u=0;const d=ic("canvas"),p=tc({isOpen:!1,text:"",style:""});let g;function f(e){c=e.offsetX,h=e.offsetY,u=n.now()}function m(){const e=t();return[s.getColIndex(c,e.left),s.getRowIndex(h,e.top)]}function v(){if(p.isOpen){const[e,t]=m();e===a&&t===l||(p.isOpen=!1)}else{const o=n.now()-u;if(400<o&&o<600){const[o,n]=m();if(o<0||n<0)return;const i=s.getMainCell(w(o,n)),r=s.getCell(...E(i));if(r&&r.error){p.isOpen=!0,p.text=r.error,a=o,l=n;const s=t(),[i,c,h,u]=e.getters.getRect({left:o,top:n,right:o,bottom:n},s),d=i+h+200<s.width?"left":"right",g="left"===d?i+h:s.width-i+17,f=c+120<s.height?"top":"bottom",m="top"===f?c:s.height-c-u+17;p.style=`${d}:${g}px;${f}:${m}px`}}}}return rc((()=>{d.el.addEventListener("mousemove",f),g=i(v,200)})),ac((()=>{d.el.removeEventListener("mousemove",f),r(g)})),p}(this.env,(()=>this.snappedViewport)),this.keyDownMapping={ENTER:()=>this.dispatch("START_EDITION"),TAB:()=>this.dispatch("MOVE_POSITION",{deltaX:1,deltaY:0}),"SHIFT+TAB":()=>this.dispatch("MOVE_POSITION",{deltaX:-1,deltaY:0}),F2:()=>this.dispatch("START_EDITION"),DELETE:()=>{this.dispatch("DELETE_CONTENT",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones()})},"CTRL+A":()=>this.dispatch("SELECT_ALL"),"CTRL+S":()=>{this.trigger("save-requested")},"CTRL+Z":()=>this.dispatch("UNDO"),"CTRL+Y":()=>this.dispatch("REDO")},this.vScrollbar=new ec(this.vScrollbarRef.el,"vertical"),this.hScrollbar=new ec(this.hScrollbarRef.el,"horizontal"),function(e,t){const o=ic("canvas");let s=null,n=null;function i(e){1===e.touches.length&&(s=e.touches[0].clientX,n=e.touches[0].clientY)}function r(){s=null,n=null}function a(o){if(1!==o.touches.length)return;t()&&(o.preventDefault(),o.stopPropagation());const i=o.touches[0].clientX,r=o.touches[0].clientY;e(s-i,n-r),s=i,n=r}rc((()=>{o.el.addEventListener("touchstart",i),o.el.addEventListener("touchend",r),o.el.addEventListener("touchmove",a)})),ac((()=>{o.el.removeEventListener("touchstart",i),o.el.removeEventListener("touchend",r),o.el.removeEventListener("touchmove",a)}))}(this.moveCanvas.bind(this),(()=>this.vScrollbar.scroll>0))}mounted(){this.vScrollbar.el=this.vScrollbarRef.el,this.hScrollbar.el=this.hScrollbarRef.el,this.focus(),this.drawGrid()}async willUpdateProps(){const e=this.getters.getActiveSheet();this.currentSheet!==e&&(this.currentPositionInViewport=!0,this.viewport.offsetX=0,this.viewport.offsetY=0,this.hScrollbar.scroll=0,this.vScrollbar.scroll=0,this.viewport=this.getters.adjustViewportZone(this.viewport),this.viewport=this.getters.adjustViewportPosition(this.viewport),this.snappedViewport=this.getters.snapViewportToCell(this.viewport))}patched(){this.drawGrid()}focus(){"selecting"===this.getters.getEditionMode()||this.getters.getSelectedFigureId()||this.canvas.el.focus()}onScroll(){this.viewport.offsetX=this.hScrollbar.scroll,this.viewport.offsetY=this.vScrollbar.scroll;const e=this.getters.adjustViewportZone(this.viewport);y(e,this.viewport)||(this.viewport=e,this.render()),this.snappedViewport=this.getters.snapViewportToCell(this.viewport)}checkChanges(){const[e,t]=this.getters.getPosition(),[o,s]=this.currentPosition,n=this.getters.getActiveSheet(),i=n!==this.currentSheet||e!==o||t!==s;return i&&(this.currentPosition=[e,t]),n!==this.currentSheet&&(this.focus(),this.currentSheet=n),i}getAutofillPosition(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheet();return{left:this.getters.getCol(t,e.right).end-4+h-this.snappedViewport.offsetX,top:this.getters.getRow(t,e.bottom).end-4+c-this.snappedViewport.offsetY}}drawGrid(){this.viewport.width=this.el.clientWidth-p,this.viewport.height=this.el.clientHeight-p,this.viewport.offsetX=this.hScrollbar.scroll,this.viewport.offsetY=this.vScrollbar.scroll,this.viewport=this.getters.adjustViewportZone(this.viewport),this.checkChanges()&&this.currentPositionInViewport&&(this.currentPositionInViewport=!1,this.viewport=this.getters.adjustViewportPosition(this.viewport),this.hScrollbar.scroll=this.viewport.offsetX,this.vScrollbar.scroll=this.viewport.offsetY),this.snappedViewport=this.getters.snapViewportToCell(this.viewport);const e=this.canvas.el,t=window.devicePixelRatio||1,o=e.getContext("2d",{alpha:!1}),s=.4*t,n={ctx:o,viewport:this.viewport,dpr:t,thinLineWidth:s},{width:i,height:r}=this.viewport;e.style.width=`${i}px`,e.style.height=`${r}px`,e.width=i*t,e.height=r*t,e.setAttribute("style",`width:${i}px;height:${r}px;`),o.translate(-.5,-.5),o.scale(t,t),this.props.model.drawGrid(n)}moveCanvas(e,t){this.vScrollbar.scroll=this.vScrollbar.scroll+t,this.hScrollbar.scroll=this.hScrollbar.scroll+e}onMouseWheel(e){function t(t){return t*(0===e.deltaMode?1:d)}this.moveCanvas(t(e.deltaX),t(e.deltaY))}getCartesianCoordinates(e){const t=this.el.getBoundingClientRect(),o=e.pageX-t.left,s=e.pageY-t.top;return[this.getters.getColIndex(o,this.snappedViewport.left),this.getters.getRowIndex(s,this.snappedViewport.top)]}onMouseDown(e){if(e.button>0)return;const[t,o]=this.getCartesianCoordinates(e);if(t<0||o<0)return;this.clickedCol=t,this.clickedRow=o,this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this.dispatch("ALTER_SELECTION",{cell:[t,o]}):(this.dispatch("SELECT_CELL",{col:t,row:o}),this.checkChanges());let s=t,n=o;const i=e=>{const[t,o]=this.getCartesianCoordinates(e);t<0||o<0||t===s&&o===n||(s=t,n=o,this.dispatch("ALTER_SELECTION",{cell:[t,o]}))};hl(i,(e=>{this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION"),"selecting"===this.getters.getEditionMode()&&this.composer.comp&&this.composer.comp.addTextFromSelection(),this.canvas.el.removeEventListener("mousemove",i),this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}))}onDoubleClick(e){const[t,o]=this.getCartesianCoordinates(e);this.clickedCol===t&&this.clickedRow===o&&this.dispatch("START_EDITION")}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.currentPositionInViewport=!0;const t={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}[e.key];e.shiftKey?this.dispatch("ALTER_SELECTION",{delta:t}):this.dispatch("MOVE_POSITION",{deltaX:t[0],deltaY:t[1]}),"selecting"===this.getters.getEditionMode()&&this.composer.comp?this.composer.comp.addTextFromSelection():this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";e.ctrlKey&&(t+="CTRL+"),e.metaKey&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let o=this.keyDownMapping[t];if(o)return e.preventDefault(),e.stopPropagation(),void o();cc.includes(t)||1!==e.key.length||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),e.stopPropagation(),this.dispatch("START_EDITION",{text:e.key}))}onCanvasContextMenu(e){e.preventDefault();const[t,o]=this.getCartesianCoordinates(e);if(t<0||o<0)return;const s=this.getters.getSelectedZones();let n="CELL";x(t,o,s[s.length-1])?this.getters.getActiveCols().has(t)?n="COL":this.getters.getActiveRows().has(o)&&(n="ROW"):this.dispatch("SELECT_CELL",{col:t,row:o}),this.toggleContextMenu(n,e.offsetX,e.offsetY)}onOverlayContextMenu(e){const t=e.detail.type,o=e.detail.x,s=e.detail.y;this.toggleContextMenu(t,o,s)}toggleContextMenu(e,t,o){this.menuState.isOpen=!0,this.menuState.position={x:t,y:o,width:this.el.clientWidth,height:this.el.clientHeight},this.menuState.menuItems=lc[e].getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}}dc.template=hc,dc.style=uc,dc.components={Composer:Pl,Overlay:Ql,Menu:ol,Autofill:vl,FiguresContainer:Vl};const pc=s.Component,{xml:gc,css:fc}=s.tags,{useState:mc}=s.hooks,vc=gc`
1034
+ `;class gc extends nc{constructor(){super(...arguments),this.menuState=sc({isOpen:!1,position:null,menuItems:[]}),this.composer=ac("composer"),this.vScrollbarRef=ac("vscrollbar"),this.hScrollbarRef=ac("hscrollbar"),this.canvas=ac("canvas"),this.getters=this.env.getters,this.dispatch=this.env.dispatch,this.currentPosition=this.getters.getPosition(),this.currentSheet=this.getters.getActiveSheet(),this.currentPositionInViewport=!1,this.clickedCol=0,this.clickedRow=0,this.viewport={width:0,height:0,offsetX:0,offsetY:0,left:0,top:0,right:0,bottom:0},this.snappedViewport=this.viewport,this.errorTooltip=function(e,t){const{browser:o,getters:s}=e,{Date:n,setInterval:i,clearInterval:r}=o;let a,l,c=0,h=0,u=0;const d=ac("canvas"),p=sc({isOpen:!1,text:"",style:""});let g;function f(e){c=e.offsetX,h=e.offsetY,u=n.now()}function m(){const e=t();return[s.getColIndex(c,e.left),s.getRowIndex(h,e.top)]}function v(){if(p.isOpen){const[e,t]=m();e===a&&t===l||(p.isOpen=!1)}else{const o=n.now()-u;if(400<o&&o<600){const[o,n]=m();if(o<0||n<0)return;const i=s.getMainCell(w(o,n)),r=s.getCell(...E(i));if(r&&r.error){p.isOpen=!0,p.text=r.error,a=o,l=n;const s=t(),[i,c,h,u]=e.getters.getRect({left:o,top:n,right:o,bottom:n},s),d=i+h+200<s.width?"left":"right",g="left"===d?i+h:s.width-i+17,f=c+120<s.height?"top":"bottom",m="top"===f?c:s.height-c-u+17;p.style=`${d}:${g}px;${f}:${m}px`}}}}return lc((()=>{d.el.addEventListener("mousemove",f),g=i(v,200)})),cc((()=>{d.el.removeEventListener("mousemove",f),r(g)})),p}(this.env,(()=>this.snappedViewport)),this.keyDownMapping={ENTER:()=>this.dispatch("START_EDITION"),TAB:()=>this.dispatch("MOVE_POSITION",{deltaX:1,deltaY:0}),"SHIFT+TAB":()=>this.dispatch("MOVE_POSITION",{deltaX:-1,deltaY:0}),F2:()=>this.dispatch("START_EDITION"),DELETE:()=>{this.dispatch("DELETE_CONTENT",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones()})},"CTRL+A":()=>this.dispatch("SELECT_ALL"),"CTRL+S":()=>{this.trigger("save-requested")},"CTRL+Z":()=>this.dispatch("UNDO"),"CTRL+Y":()=>this.dispatch("REDO")},this.vScrollbar=new oc(this.vScrollbarRef.el,"vertical"),this.hScrollbar=new oc(this.hScrollbarRef.el,"horizontal"),function(e,t){const o=ac("canvas");let s=null,n=null;function i(e){1===e.touches.length&&(s=e.touches[0].clientX,n=e.touches[0].clientY)}function r(){s=null,n=null}function a(o){if(1!==o.touches.length)return;t()&&(o.preventDefault(),o.stopPropagation());const i=o.touches[0].clientX,r=o.touches[0].clientY;e(s-i,n-r),s=i,n=r}lc((()=>{o.el.addEventListener("touchstart",i),o.el.addEventListener("touchend",r),o.el.addEventListener("touchmove",a)})),cc((()=>{o.el.removeEventListener("touchstart",i),o.el.removeEventListener("touchend",r),o.el.removeEventListener("touchmove",a)}))}(this.moveCanvas.bind(this),(()=>this.vScrollbar.scroll>0))}mounted(){this.vScrollbar.el=this.vScrollbarRef.el,this.hScrollbar.el=this.hScrollbarRef.el,this.focus(),this.drawGrid()}async willUpdateProps(){const e=this.getters.getActiveSheet();this.currentSheet!==e&&(this.currentPositionInViewport=!0,this.viewport.offsetX=0,this.viewport.offsetY=0,this.hScrollbar.scroll=0,this.vScrollbar.scroll=0,this.viewport=this.getters.adjustViewportZone(this.viewport),this.viewport=this.getters.adjustViewportPosition(this.viewport),this.snappedViewport=this.getters.snapViewportToCell(this.viewport))}patched(){this.drawGrid()}focus(){"selecting"===this.getters.getEditionMode()||this.getters.getSelectedFigureId()||this.canvas.el.focus()}onScroll(){this.viewport.offsetX=this.hScrollbar.scroll,this.viewport.offsetY=this.vScrollbar.scroll;const e=this.getters.adjustViewportZone(this.viewport);y(e,this.viewport)||(this.viewport=e,this.render()),this.snappedViewport=this.getters.snapViewportToCell(this.viewport)}checkChanges(){const[e,t]=this.getters.getPosition(),[o,s]=this.currentPosition,n=this.getters.getActiveSheet(),i=n!==this.currentSheet||e!==o||t!==s;return i&&(this.currentPosition=[e,t]),n!==this.currentSheet&&(this.focus(),this.currentSheet=n),i}getAutofillPosition(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheet();return{left:this.getters.getCol(t,e.right).end-4+h-this.snappedViewport.offsetX,top:this.getters.getRow(t,e.bottom).end-4+c-this.snappedViewport.offsetY}}drawGrid(){this.viewport.width=this.el.clientWidth-p,this.viewport.height=this.el.clientHeight-p,this.viewport.offsetX=this.hScrollbar.scroll,this.viewport.offsetY=this.vScrollbar.scroll,this.viewport=this.getters.adjustViewportZone(this.viewport),this.checkChanges()&&this.currentPositionInViewport&&(this.currentPositionInViewport=!1,this.viewport=this.getters.adjustViewportPosition(this.viewport),this.hScrollbar.scroll=this.viewport.offsetX,this.vScrollbar.scroll=this.viewport.offsetY),this.snappedViewport=this.getters.snapViewportToCell(this.viewport);const e=this.canvas.el,t=window.devicePixelRatio||1,o=e.getContext("2d",{alpha:!1}),s=.4*t,n={ctx:o,viewport:this.viewport,dpr:t,thinLineWidth:s},{width:i,height:r}=this.viewport;e.style.width=`${i}px`,e.style.height=`${r}px`,e.width=i*t,e.height=r*t,e.setAttribute("style",`width:${i}px;height:${r}px;`),o.translate(-.5,-.5),o.scale(t,t),this.props.model.drawGrid(n)}moveCanvas(e,t){this.vScrollbar.scroll=this.vScrollbar.scroll+t,this.hScrollbar.scroll=this.hScrollbar.scroll+e}onMouseWheel(e){function t(t){return t*(0===e.deltaMode?1:d)}this.moveCanvas(t(e.deltaX),t(e.deltaY))}getCartesianCoordinates(e){const t=this.el.getBoundingClientRect(),o=e.pageX-t.left,s=e.pageY-t.top;return[this.getters.getColIndex(o,this.snappedViewport.left),this.getters.getRowIndex(s,this.snappedViewport.top)]}onMouseDown(e){if(e.button>0)return;const[t,o]=this.getCartesianCoordinates(e);if(t<0||o<0)return;this.clickedCol=t,this.clickedRow=o,this.dispatch(e.ctrlKey?"START_SELECTION_EXPANSION":"START_SELECTION"),e.shiftKey?this.dispatch("ALTER_SELECTION",{cell:[t,o]}):(this.dispatch("SELECT_CELL",{col:t,row:o}),this.checkChanges());let s=t,n=o;const i=e=>{const[t,o]=this.getCartesianCoordinates(e);t<0||o<0||t===s&&o===n||(s=t,n=o,this.dispatch("ALTER_SELECTION",{cell:[t,o]}))};dl(i,(e=>{this.dispatch(e.ctrlKey?"PREPARE_SELECTION_EXPANSION":"STOP_SELECTION"),"selecting"===this.getters.getEditionMode()&&this.composer.comp&&this.composer.comp.addTextFromSelection(),this.canvas.el.removeEventListener("mousemove",i),this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}))}onDoubleClick(e){const[t,o]=this.getCartesianCoordinates(e);this.clickedCol===t&&this.clickedRow===o&&this.dispatch("START_EDITION")}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.currentPositionInViewport=!0;const t={ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1]}[e.key];e.shiftKey?this.dispatch("ALTER_SELECTION",{delta:t}):this.dispatch("MOVE_POSITION",{deltaX:t[0],deltaY:t[1]}),"selecting"===this.getters.getEditionMode()&&this.composer.comp?this.composer.comp.addTextFromSelection():this.getters.isPaintingFormat()&&this.dispatch("PASTE",{target:this.getters.getSelectedZones()})}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";e.ctrlKey&&(t+="CTRL+"),e.metaKey&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let o=this.keyDownMapping[t];if(o)return e.preventDefault(),e.stopPropagation(),void o();uc.includes(t)||1!==e.key.length||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),e.stopPropagation(),this.dispatch("START_EDITION",{text:e.key}))}onCanvasContextMenu(e){e.preventDefault();const[t,o]=this.getCartesianCoordinates(e);if(t<0||o<0)return;const s=this.getters.getSelectedZones();let n="CELL";x(t,o,s[s.length-1])?this.getters.getActiveCols().has(t)?n="COL":this.getters.getActiveRows().has(o)&&(n="ROW"):this.dispatch("SELECT_CELL",{col:t,row:o}),this.toggleContextMenu(n,e.offsetX,e.offsetY)}onOverlayContextMenu(e){const t=e.detail.type,o=e.detail.x,s=e.detail.y;this.toggleContextMenu(t,o,s)}toggleContextMenu(e,t,o){this.menuState.isOpen=!0,this.menuState.position={x:t,y:o,width:this.el.clientWidth,height:this.el.clientHeight},this.menuState.menuItems=hc[e].getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}}gc.template=dc,gc.style=pc,gc.components={Composer:Zl,Overlay:tc,Menu:nl,Autofill:El,FiguresContainer:ql};const fc=s.Component,{xml:mc,css:vc}=s.tags,{useState:bc}=s.hooks,Ec=mc`
1029
1035
  <div class="o-sidePanel" >
1030
1036
  <div class="o-sidePanelHeader">
1031
1037
  <div class="o-sidePanelTitle" t-esc="getTitle()"/>
@@ -1037,7 +1043,7 @@
1037
1043
  <div class="o-sidePanelFooter" t-if="state.panel.Footer">
1038
1044
  <t t-component="state.panel.Footer" t-props="props.panelProps" t-key="'Footer_' + props.component"/>
1039
1045
  </div>
1040
- </div>`,bc=fc`
1046
+ </div>`,wc=vc`
1041
1047
  .o-sidePanel {
1042
1048
  display: flex;
1043
1049
  flex-direction: column;
@@ -1117,7 +1123,7 @@
1117
1123
  }
1118
1124
  }
1119
1125
  }
1120
- `;class Ec extends pc{constructor(){super(...arguments),this.state=mc({panel:Cr.get(this.props.component)})}async willUpdateProps(e){this.state.panel=Cr.get(e.component)}getTitle(){return"function"==typeof this.state.panel.title?this.state.panel.title(this.env):this.state.panel.title}}Ec.template=vc,Ec.style=bc;const{useState:wc,hooks:Lc}=s,Sc=s.Component,{xml:Cc,css:yc}=s.tags,{useExternalListener:Tc,useRef:xc}=Lc,Rc=[{name:"auto",text:"Automatic"},{name:"number",text:"Number (1,000.12)",value:"#,##0.00"},{name:"percent",text:"Percent (10.12%)",value:"0.00%"},{name:"date",text:"Date (9/26/2008)",value:"m/d/yyyy"},{name:"time",text:"Time (10:43:00 PM)",value:"hh:mm:ss a"},{name:"datetime",text:"Date time (9/26/2008 22:43:00)",value:"m/d/yyyy hh:mm:ss"},{name:"duration",text:"Duration (27:51:38)",value:"hhhh:mm:ss"}];class Mc extends Sc{constructor(){super(...arguments),this.formats=Rc,this.currentFormat="auto",this.fontSizes=Jn,this.dispatch=this.env.dispatch,this.getters=this.env.getters,this.style={},this.state=wc({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=xc("menuRef"),Tc(window,"click",this.onClick)}get topbarComponents(){return yr.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}async willStart(){this.updateCellState()}async willUpdateProps(){this.updateCellState()}onClick(e){this.openedEl&&qa(this.openedEl,e)||this.closeMenus()}toogleStyle(e){_n(this.env,{[e]:!this.style[e]})}toogleFormat(e){const t=Rc.find((t=>t.name===e)),o=t&&t.value||"";kn(this.env,o)}toggleAlign(e){_n(this.env,{align:e})}onMenuMouseOver(e,t){this.isSelectingMenu&&this.toggleContextMenu(e,t)}toggleDropdownTool(e,t){const o=this.state.activeTool===e;this.closeMenus(),this.state.activeTool=o?"":e,this.openedEl=o?null:t.target}toggleContextMenu(e,t){this.closeMenus();const o=t.target.offsetLeft,s=t.target.clientHeight+t.target.offsetTop;this.state.menuState.isOpen=!0;const n=this.el.clientWidth,i=this.el.parentElement.clientHeight;this.state.menuState.position={x:o,y:s,width:n,height:i},this.state.menuState.menuItems=ei.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:o,right:s,bottom:n}=e[0];if(this.cannotMerge=e.length>1||t===n&&o===s,this.inMerge=!1,!this.cannotMerge){const[t,o]=this.getters.getPosition(),s=this.getters.expandZone({left:t,right:t,top:o,bottom:o});this.inMerge=y(e[0],s)}this.undoTool=this.getters.canUndo(),this.redoTool=this.getters.canRedo(),this.paintFormatTool=this.getters.isPaintingFormat();const i=this.getters.getActiveCell();if(i&&i.format){const e=this.formats.find((e=>e.value===i.format));this.currentFormat=e?e.name:""}else this.currentFormat="auto";this.menus=ei.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}getMenuName(e){return ei.getName(e,this.env)}toggleMerge(){const e=this.getters.getSelectedZones(),t=e[e.length-1],o=this.getters.getActiveSheet();this.inMerge?this.dispatch("REMOVE_MERGE",{sheet:o,zone:t}):this.dispatch("ADD_MERGE",{sheet:o,zone:t,interactive:!0})}setColor(e,t){_n(this.env,{[e]:t.detail.color})}setBorder(e){this.dispatch("SET_FORMATTING",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones(),border:e})}setFormat(e){const t=e.target.dataset.format;t&&this.toogleFormat(t)}setDecimal(e){this.dispatch("SET_DECIMAL",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones(),step:e})}paintFormat(){this.dispatch("ACTIVATE_PAINT_FORMAT",{target:this.getters.getSelectedZones()})}clearFormatting(){this.dispatch("CLEAR_FORMATTING",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones()})}setSize(e){const t=parseFloat(e.target.dataset.size);_n(this.env,{fontSize:t})}doAction(e){e(this.env),this.closeMenus()}undo(){this.dispatch("UNDO")}redo(){this.dispatch("REDO")}}Mc.template=Cc`
1126
+ `;class Lc extends fc{constructor(){super(...arguments),this.state=bc({panel:Tr.get(this.props.component)})}async willUpdateProps(e){this.state.panel=Tr.get(e.component)}getTitle(){return"function"==typeof this.state.panel.title?this.state.panel.title(this.env):this.state.panel.title}}Lc.template=Ec,Lc.style=wc;const{useState:Sc,hooks:Cc}=s,yc=s.Component,{xml:Tc,css:xc}=s.tags,{useExternalListener:Rc,useRef:Mc}=Cc,Ac=[{name:"auto",text:"Automatic"},{name:"number",text:"Number (1,000.12)",value:"#,##0.00"},{name:"percent",text:"Percent (10.12%)",value:"0.00%"},{name:"date",text:"Date (9/26/2008)",value:"m/d/yyyy"},{name:"time",text:"Time (10:43:00 PM)",value:"hh:mm:ss a"},{name:"datetime",text:"Date time (9/26/2008 22:43:00)",value:"m/d/yyyy hh:mm:ss"},{name:"duration",text:"Duration (27:51:38)",value:"hhhh:mm:ss"}];class Nc extends yc{constructor(){super(...arguments),this.formats=Ac,this.currentFormat="auto",this.fontSizes=Jn,this.dispatch=this.env.dispatch,this.getters=this.env.getters,this.style={},this.state=Sc({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=Mc("menuRef"),Rc(window,"click",this.onClick)}get topbarComponents(){return xr.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}async willStart(){this.updateCellState()}async willUpdateProps(){this.updateCellState()}onClick(e){this.openedEl&&Ya(this.openedEl,e)||this.closeMenus()}toogleStyle(e){_n(this.env,{[e]:!this.style[e]})}toogleFormat(e){const t=Ac.find((t=>t.name===e)),o=t&&t.value||"";kn(this.env,o)}toggleAlign(e){_n(this.env,{align:e})}onMenuMouseOver(e,t){this.isSelectingMenu&&this.toggleContextMenu(e,t)}toggleDropdownTool(e,t){const o=this.state.activeTool===e;this.closeMenus(),this.state.activeTool=o?"":e,this.openedEl=o?null:t.target}toggleContextMenu(e,t){this.closeMenus();const o=t.target.offsetLeft,s=t.target.clientHeight+t.target.offsetTop;this.state.menuState.isOpen=!0;const n=this.el.clientWidth,i=this.el.parentElement.clientHeight;this.state.menuState.position={x:o,y:s,width:n,height:i},this.state.menuState.menuItems=ei.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:o,right:s,bottom:n}=e[0];if(this.cannotMerge=e.length>1||t===n&&o===s,this.inMerge=!1,!this.cannotMerge){const[t,o]=this.getters.getPosition(),s=this.getters.expandZone({left:t,right:t,top:o,bottom:o});this.inMerge=y(e[0],s)}this.undoTool=this.getters.canUndo(),this.redoTool=this.getters.canRedo(),this.paintFormatTool=this.getters.isPaintingFormat();const i=this.getters.getActiveCell();if(i&&i.format){const e=this.formats.find((e=>e.value===i.format));this.currentFormat=e?e.name:""}else this.currentFormat="auto";this.menus=ei.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}getMenuName(e){return ei.getName(e,this.env)}toggleMerge(){const e=this.getters.getSelectedZones(),t=e[e.length-1],o=this.getters.getActiveSheet();this.inMerge?this.dispatch("REMOVE_MERGE",{sheet:o,zone:t}):this.dispatch("ADD_MERGE",{sheet:o,zone:t,interactive:!0})}setColor(e,t){_n(this.env,{[e]:t.detail.color})}setBorder(e){this.dispatch("SET_FORMATTING",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones(),border:e})}setFormat(e){const t=e.target.dataset.format;t&&this.toogleFormat(t)}setDecimal(e){this.dispatch("SET_DECIMAL",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones(),step:e})}paintFormat(){this.dispatch("ACTIVATE_PAINT_FORMAT",{target:this.getters.getSelectedZones()})}clearFormatting(){this.dispatch("CLEAR_FORMATTING",{sheet:this.getters.getActiveSheet(),target:this.getters.getSelectedZones()})}setSize(e){const t=parseFloat(e.target.dataset.size);_n(this.env,{fontSize:t})}doAction(e){e(this.env),this.closeMenus()}undo(){this.dispatch("UNDO")}redo(){this.dispatch("REDO")}}Nc.template=Tc`
1121
1127
  <div class="o-spreadsheet-topbar">
1122
1128
  <div class="o-topbar-top">
1123
1129
  <!-- Menus -->
@@ -1156,7 +1162,7 @@
1156
1162
  <div class="o-tool" title="Decrease decimal places" t-on-click="setDecimal(-1)">.0</div>
1157
1163
  <div class="o-tool" title="Increase decimal places" t-on-click="setDecimal(+1)">.00</div>
1158
1164
  <div class="o-tool o-dropdown" title="More formats" t-on-click="toggleDropdownTool('formatTool')">
1159
- <div class="o-text-icon">123${zi}</div>
1165
+ <div class="o-text-icon">123${Hi}</div>
1160
1166
  <div class="o-dropdown-content o-text-options o-format-tool " t-if="state.activeTool === 'formatTool'" t-on-click="setFormat">
1161
1167
  <t t-foreach="formats" t-as="format" t-key="format.name">
1162
1168
  <div t-att-data-format="format.name" t-att-class="{active: currentFormat === format.name}"><t t-esc="format.text"/></div>
@@ -1164,9 +1170,9 @@
1164
1170
  </div>
1165
1171
  </div>
1166
1172
  <div class="o-divider"/>
1167
- <!-- <div class="o-tool" title="Font"><span>Roboto</span> ${zi}</div> -->
1173
+ <!-- <div class="o-tool" title="Font"><span>Roboto</span> ${Hi}</div> -->
1168
1174
  <div class="o-tool o-dropdown" title="Font Size" t-on-click="toggleDropdownTool('fontSizeTool')">
1169
- <div class="o-text-icon"><t t-esc="style.fontSize || ${10}"/> ${zi}</div>
1175
+ <div class="o-text-icon"><t t-esc="style.fontSize || ${10}"/> ${Hi}</div>
1170
1176
  <div class="o-dropdown-content o-text-options " t-if="state.activeTool === 'fontSizeTool'" t-on-click="setSize">
1171
1177
  <t t-foreach="fontSizes" t-as="font" t-key="font_index">
1172
1178
  <div t-esc="font.pt" t-att-data-size="font.pt"/>
@@ -1174,23 +1180,23 @@
1174
1180
  </div>
1175
1181
  </div>
1176
1182
  <div class="o-divider"/>
1177
- <div class="o-tool" title="Bold" t-att-class="{active:style.bold}" t-on-click="toogleStyle('bold')">${Zi}</div>
1178
- <div class="o-tool" title="Italic" t-att-class="{active:style.italic}" t-on-click="toogleStyle('italic')">${Hi}</div>
1179
- <div class="o-tool" title="Strikethrough" t-att-class="{active:style.strikethrough}" t-on-click="toogleStyle('strikethrough')">${Gi}</div>
1183
+ <div class="o-tool" title="Bold" t-att-class="{active:style.bold}" t-on-click="toogleStyle('bold')">${Gi}</div>
1184
+ <div class="o-tool" title="Italic" t-att-class="{active:style.italic}" t-on-click="toogleStyle('italic')">${Vi}</div>
1185
+ <div class="o-tool" title="Strikethrough" t-att-class="{active:style.strikethrough}" t-on-click="toogleStyle('strikethrough')">${ji}</div>
1180
1186
  <div class="o-tool o-dropdown o-with-color">
1181
- <span t-attf-style="border-color:{{textColor}}" title="Text Color" t-on-click="toggleDropdownTool('textColorTool')">${Vi}</span>
1187
+ <span t-attf-style="border-color:{{textColor}}" title="Text Color" t-on-click="toggleDropdownTool('textColorTool')">${qi}</span>
1182
1188
  <ColorPicker t-if="state.activeTool === 'textColorTool'" t-on-color-picked="setColor('textColor')" t-key="textColor"/>
1183
1189
  </div>
1184
1190
  <div class="o-divider"/>
1185
1191
  <div class="o-tool o-dropdown o-with-color">
1186
- <span t-attf-style="border-color:{{fillColor}}" title="Fill Color" t-on-click="toggleDropdownTool('fillColorTool')">${ji}</span>
1192
+ <span t-attf-style="border-color:{{fillColor}}" title="Fill Color" t-on-click="toggleDropdownTool('fillColorTool')">${Wi}</span>
1187
1193
  <ColorPicker t-if="state.activeTool === 'fillColorTool'" t-on-color-picked="setColor('fillColor')" t-key="fillColor"/>
1188
1194
  </div>
1189
1195
  <div class="o-tool o-dropdown">
1190
- <span title="Borders" t-on-click="toggleDropdownTool('borderTool')">${Xi}</span>
1196
+ <span title="Borders" t-on-click="toggleDropdownTool('borderTool')">${Ji}</span>
1191
1197
  <div class="o-dropdown-content o-border" t-if="state.activeTool === 'borderTool'">
1192
1198
  <div class="o-dropdown-line">
1193
- <span class="o-line-item" t-on-click="setBorder('all')">${Xi}</span>
1199
+ <span class="o-line-item" t-on-click="setBorder('all')">${Ji}</span>
1194
1200
  <span class="o-line-item" t-on-click="setBorder('hv')">${'<svg class="o-icon"><g fill="#000000"><path d="M0,14 L2,14 L2,12 L0,12 L0,14 L0,14 Z M2,3 L0,3 L0,5 L2,5 L2,3 L2,3 Z M3,14 L5,14 L5,12 L3,12 L3,14 L3,14 Z M11,0 L9,0 L9,2 L11,2 L11,0 L11,0 Z M2,0 L0,0 L0,2 L2,2 L2,0 L2,0 Z M5,0 L3,0 L3,2 L5,2 L5,0 L5,0 Z M0,11 L2,11 L2,9 L0,9 L0,11 L0,11 Z M9,14 L11,14 L11,12 L9,12 L9,14 L9,14 Z M12,0 L12,2 L14,2 L14,0 L12,0 L12,0 Z M12,5 L14,5 L14,3 L12,3 L12,5 L12,5 Z M12,14 L14,14 L14,12 L12,12 L12,14 L12,14 Z M12,11 L14,11 L14,9 L12,9 L12,11 L12,11 Z" opacity=".54"/><polygon points="8 0 6 0 6 6 0 6 0 8 6 8 6 14 8 14 8 8 14 8 14 6 8 6"/></g></svg>'}</span>
1195
1201
  <span class="o-line-item" t-on-click="setBorder('h')">${'<svg class="o-icon"><g fill="#000000"><path d="M6,14 L8,14 L8,12 L6,12 L6,14 L6,14 Z M3,2 L5,2 L5,0 L3,0 L3,2 L3,2 Z M6,11 L8,11 L8,9 L6,9 L6,11 L6,11 Z M3,14 L5,14 L5,12 L3,12 L3,14 L3,14 Z M0,5 L2,5 L2,3 L0,3 L0,5 L0,5 Z M0,14 L2,14 L2,12 L0,12 L0,14 L0,14 Z M0,2 L2,2 L2,0 L0,0 L0,2 L0,2 Z M0,11 L2,11 L2,9 L0,9 L0,11 L0,11 Z M12,11 L14,11 L14,9 L12,9 L12,11 L12,11 Z M12,14 L14,14 L14,12 L12,12 L12,14 L12,14 Z M12,5 L14,5 L14,3 L12,3 L12,5 L12,5 Z M12,0 L12,2 L14,2 L14,0 L12,0 L12,0 Z M6,2 L8,2 L8,0 L6,0 L6,2 L6,2 Z M9,2 L11,2 L11,0 L9,0 L9,2 L9,2 Z M6,5 L8,5 L8,3 L6,3 L6,5 L6,5 Z M9,14 L11,14 L11,12 L9,12 L9,14 L9,14 Z" opacity=".54"/><polygon points="0 8 14 8 14 6 0 6"/></g></svg>'}</span>
1196
1202
  <span class="o-line-item" t-on-click="setBorder('v')">${'<svg class="o-icon"><g fill="#000000"><path d="M3,14 L5,14 L5,12 L3,12 L3,14 L3,14 Z M0,5 L2,5 L2,3 L0,3 L0,5 L0,5 Z M0,2 L2,2 L2,0 L0,0 L0,2 L0,2 Z M3,8 L5,8 L5,6 L3,6 L3,8 L3,8 Z M3,2 L5,2 L5,0 L3,0 L3,2 L3,2 Z M0,14 L2,14 L2,12 L0,12 L0,14 L0,14 Z M0,8 L2,8 L2,6 L0,6 L0,8 L0,8 Z M0,11 L2,11 L2,9 L0,9 L0,11 L0,11 Z M12,0 L12,2 L14,2 L14,0 L12,0 L12,0 Z M12,8 L14,8 L14,6 L12,6 L12,8 L12,8 Z M12,14 L14,14 L14,12 L12,12 L12,14 L12,14 Z M12,5 L14,5 L14,3 L12,3 L12,5 L12,5 Z M12,11 L14,11 L14,9 L12,9 L12,11 L12,11 Z M9,14 L11,14 L11,12 L9,12 L9,14 L9,14 Z M9,8 L11,8 L11,6 L9,6 L9,8 L9,8 Z M9,2 L11,2 L11,0 L9,0 L9,2 L9,2 Z" opacity=".54"/><polygon points="6 14 8 14 8 0 6 0"/></g></svg>'}</span>
@@ -1209,18 +1215,18 @@
1209
1215
  <div class="o-divider"/>
1210
1216
  <div class="o-tool o-dropdown" title="Horizontal align" t-on-click="toggleDropdownTool('alignTool')">
1211
1217
  <span>
1212
- <t t-if="style.align === 'right'">${Yi}</t>
1213
- <t t-elif="style.align === 'center'">${Wi}</t>
1214
- <t t-else="">${qi}</t>
1215
- ${zi}
1218
+ <t t-if="style.align === 'right'">${Ki}</t>
1219
+ <t t-elif="style.align === 'center'">${Xi}</t>
1220
+ <t t-else="">${Yi}</t>
1221
+ ${Hi}
1216
1222
  </span>
1217
1223
  <div t-if="state.activeTool === 'alignTool'" class="o-dropdown-content">
1218
- <div class="o-dropdown-item" t-on-click="toggleAlign('left')">${qi}</div>
1219
- <div class="o-dropdown-item" t-on-click="toggleAlign('center')">${Wi}</div>
1220
- <div class="o-dropdown-item" t-on-click="toggleAlign('right')">${Yi}</div>
1224
+ <div class="o-dropdown-item" t-on-click="toggleAlign('left')">${Yi}</div>
1225
+ <div class="o-dropdown-item" t-on-click="toggleAlign('center')">${Xi}</div>
1226
+ <div class="o-dropdown-item" t-on-click="toggleAlign('right')">${Ki}</div>
1221
1227
  </div>
1222
1228
  </div>
1223
- <!-- <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> ${zi}</div> -->
1229
+ <!-- <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> ${Hi}</div> -->
1224
1230
  <!-- <div class="o-tool" title="Text Wrapping">${'<svg class="o-icon"><path fill="#000000" d="M14,0 L0,0 L0,2 L14,2 L14,0 Z M0,12 L4,12 L4,10 L0,10 L0,12 Z M11.5,5 L0,5 L0,7 L11.75,7 C12.58,7 13.25,7.67 13.25,8.5 C13.25,9.33 12.58,10 11.75,10 L9,10 L9,8 L6,11 L9,14 L9,12 L11.5,12 C13.43,12 15,10.43 15,8.5 C15,6.57 13.43,5 11.5,5 Z" transform="translate(2 3)"/></svg>'}</div> -->
1225
1231
  <div class="o-divider"/>
1226
1232
  </div>
@@ -1232,7 +1238,7 @@
1232
1238
  </div>
1233
1239
 
1234
1240
  </div>
1235
- </div>`,Mc.style=yc`
1241
+ </div>`,Nc.style=xc`
1236
1242
  .o-spreadsheet-topbar {
1237
1243
  background-color: white;
1238
1244
  display: flex;
@@ -1403,7 +1409,7 @@
1403
1409
  }
1404
1410
  }
1405
1411
  }
1406
- `,Mc.components={ColorPicker:Bi,Menu:ol};const{useState:Ac}=s,Nc=s.Component,{useRef:kc,useExternalListener:_c}=s.hooks,{xml:Ic,css:Oc}=s.tags,{useSubEnv:Dc}=s.hooks,$c=Ic`
1412
+ `,Nc.components={ColorPicker:zi,Menu:nl};const{useState:kc}=s,_c=s.Component,{useRef:Ic,useExternalListener:Oc}=s.hooks,{xml:Dc,css:$c}=s.tags,{useSubEnv:Uc}=s.hooks,Fc=Dc`
1407
1413
  <div class="o-spreadsheet" t-on-save-requested="save" t-on-keydown="onKeydown">
1408
1414
  <TopBar t-on-click="focusGrid" class="o-two-columns"/>
1409
1415
  <Grid model="model" t-ref="grid" t-att-class="{'o-two-columns': !sidePanel.isOpen}"/>
@@ -1412,7 +1418,7 @@
1412
1418
  component="sidePanel.component"
1413
1419
  panelProps="sidePanel.panelProps"/>
1414
1420
  <BottomBar t-on-click="focusGrid" class="o-two-columns"/>
1415
- </div>`,Uc=Oc`
1421
+ </div>`,Pc=$c`
1416
1422
  .o-spreadsheet {
1417
1423
  display: grid;
1418
1424
  grid-template-rows: ${63}px auto ${37}px;
@@ -1437,4 +1443,4 @@
1437
1443
  height: 18px;
1438
1444
  opacity: 0.6;
1439
1445
  }
1440
- `;class Fc extends Nc{constructor(){super(...arguments),this.model=new ja(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,o)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:o}),editText:(e,t,o)=>this.trigger("edit-text",{title:e,placeholder:t,callback:o}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env}}),this.grid=kc("grid"),this.sidePanel=Ac({isOpen:!1,panelProps:{}}),this.clipBoardString="",Dc({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,_t:Fc._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model)}),_c(window,"resize",this.render),_c(document.body,"cut",this.copy.bind(this,!0)),_c(document.body,"copy",this.copy.bind(this,!1)),_c(document.body,"paste",this.paste),_c(document.body,"keyup",this.onKeyup.bind(this))}mounted(){this.model.on("update",this,this.render)}willUnmount(){this.model.off("update",this)}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?this.sidePanel.isOpen=!1:this.openSidePanel(e,t)}focusGrid(){this.grid.comp.focus()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const o=e?"CUT":"COPY",s=this.model.getters.getSelectedZones();this.model.dispatch(o,{target:s});const n=this.model.getters.getClipboardContent();this.clipBoardString=n,t.clipboardData.setData("text/plain",n),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"),o=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:o,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:o,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==$a.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===$a.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION")}}Fc.template=$c,Fc.style=Uc,Fc.components={TopBar:Mc,Grid:dc,BottomBar:cl,SidePanel:Ec},Fc._t=e=>e;const Pc={},Bc={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:c,HEADER_WIDTH:h,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:u,DEFAULT_CELL_HEIGHT:d,SCROLLBAR_WIDTH:p},zc={autofillModifiersRegistry:pn,autofillRulesRegistry:gn,cellMenuRegistry:Wn,colMenuRegistry:Yn,functionRegistry:un,pluginRegistry:Pa,rowMenuRegistry:Xn,sidePanelRegistry:Cr,sheetMenuRegistry:Kn,topbarMenuRegistry:ei,topbarComponentRegistry:yr},Zc={args:De,toBoolean:ye,toNumber:me,toString:Se,toXC:w,toZone:L,toCartesian:E,numberToLetters:b,createFullMenuItem:Rn,uuidv4:K,formatDecimal:W};e.BasePlugin=dn,e.Model=ja,e.SPREADSHEET_DIMENSIONS=Bc,e.Spreadsheet=Fc,e.__DEBUG__=P,e.__info__=Pc,e.astToFormula=function e(t,o){switch(t.type){case"FUNCALL":case"ASYNC_FUNCALL":const s=t.args.map((t=>e(t,o)));return`${t.value}(${s.join(",")})`;case"NUMBER":return t.value.toString();case"NORMALIZED_STRING":return`"${o[t.value]}"`;case"NORMALIZED_NUMBER":case"REFERENCE":return o[t.value].toString();case"STRING":default:return t.value;case"BOOLEAN":return t.value?"TRUE":"FALSE";case"UNARY_OPERATION":return t.value+e(t.right,o);case"BIN_OPERATION":return e(t.left,o)+t.value+e(t.right,o)}},e.functionCache=ra,e.helpers=Zc,e.normalize=da,e.parse=Jr,e.registries=zc,e.setTranslationMethod=function(e){J=e},Object.defineProperty(e,"__esModule",{value:!0}),Pc.version="14.0.2",Pc.date="2023-02-20T14:59:39.824Z",Pc.hash="5eac8d8"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
1446
+ `;class Bc extends _c{constructor(){super(...arguments),this.model=new Wa(this.props.data,{notifyUser:e=>this.trigger("notify-user",{content:e}),askConfirmation:(e,t,o)=>this.trigger("ask-confirmation",{content:e,confirm:t,cancel:o}),editText:(e,t,o)=>this.trigger("edit-text",{title:e,placeholder:t,callback:o}),openSidePanel:(e,t={})=>this.openSidePanel(e,t),evalContext:{env:this.env}}),this.grid=Ic("grid"),this.sidePanel=kc({isOpen:!1,panelProps:{}}),this.clipBoardString="",Uc({openSidePanel:(e,t={})=>this.openSidePanel(e,t),toggleSidePanel:(e,t={})=>this.toggleSidePanel(e,t),dispatch:this.model.dispatch,getters:this.model.getters,_t:Bc._t,clipboard:navigator.clipboard,export:this.model.exportData.bind(this.model)}),Oc(window,"resize",this.render),Oc(document.body,"cut",this.copy.bind(this,!0)),Oc(document.body,"copy",this.copy.bind(this,!1)),Oc(document.body,"paste",this.paste),Oc(document.body,"keyup",this.onKeyup.bind(this))}mounted(){this.model.on("update",this,this.render)}willUnmount(){this.model.off("update",this)}destroy(){this.model.destroy(),super.destroy()}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?this.sidePanel.isOpen=!1:this.openSidePanel(e,t)}focusGrid(){this.grid.comp.focus()}copy(e,t){if(!this.grid.el.contains(document.activeElement))return;if("inactive"!==this.model.getters.getEditionMode())return;const o=e?"CUT":"COPY",s=this.model.getters.getSelectedZones();this.model.dispatch(o,{target:s});const n=this.model.getters.getClipboardContent();this.clipBoardString=n,t.clipboardData.setData("text/plain",n),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"),o=this.model.getters.getSelectedZones();this.clipBoardString===e?this.model.dispatch("PASTE",{target:o,interactive:!0}):this.model.dispatch("PASTE_FROM_OS_CLIPBOARD",{target:o,text:e})}}save(){this.trigger("save-content",{data:this.model.exportData()})}onKeyup(e){"Control"===e.key&&this.model.getters.getSelectionMode()!==Fa.expanding&&this.model.dispatch("STOP_SELECTION")}onKeydown(e){"Control"!==e.key||e.repeat||this.model.dispatch(this.model.getters.getSelectionMode()===Fa.idle?"PREPARE_SELECTION_EXPANSION":"START_SELECTION_EXPANSION")}}Bc.template=Fc,Bc.style=Pc,Bc.components={TopBar:Nc,Grid:gc,BottomBar:ul,SidePanel:Lc},Bc._t=e=>e;const Zc={},zc={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:c,HEADER_WIDTH:h,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:u,DEFAULT_CELL_HEIGHT:d,SCROLLBAR_WIDTH:p},Hc={autofillModifiersRegistry:pn,autofillRulesRegistry:gn,cellMenuRegistry:Wn,colMenuRegistry:Yn,functionRegistry:un,pluginRegistry:Za,rowMenuRegistry:Xn,sidePanelRegistry:Tr,sheetMenuRegistry:Kn,topbarMenuRegistry:ei,topbarComponentRegistry:xr},Gc={args:De,toBoolean:ye,toNumber:me,toString:Se,toXC:w,toZone:L,toCartesian:E,numberToLetters:b,createFullMenuItem:Rn,uuidv4:K,formatDecimal:W};e.BasePlugin=dn,e.Model=Wa,e.SPREADSHEET_DIMENSIONS=zc,e.Spreadsheet=Bc,e.__DEBUG__=P,e.__info__=Zc,e.astToFormula=function e(t,o){switch(t.type){case"FUNCALL":case"ASYNC_FUNCALL":const s=t.args.map((t=>e(t,o)));return`${t.value}(${s.join(",")})`;case"NUMBER":return t.value.toString();case"NORMALIZED_STRING":return`"${o[t.value]}"`;case"NORMALIZED_NUMBER":case"REFERENCE":return o[t.value].toString();case"STRING":default:return t.value;case"BOOLEAN":return t.value?"TRUE":"FALSE";case"UNARY_OPERATION":return t.value+e(t.right,o);case"BIN_OPERATION":return e(t.left,o)+t.value+e(t.right,o)}},e.functionCache=la,e.helpers=Gc,e.normalize=ga,e.parse=ea,e.registries=Hc,e.setTranslationMethod=function(e){J=e},Object.defineProperty(e,"__esModule",{value:!0}),Zc.version="14.0.3",Zc.date="2023-04-21T07:27:17.798Z",Zc.hash="32b98aa"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);