UNPKG

@odoo/o-spreadsheet

Version:
9 lines (8 loc) 1.6 MB
(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let n={};for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t||r(n,Symbol.toStringTag,{value:`Module`}),n},u=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},d=(e,t,i)=>(i=e==null?{}:n(o(e)),u(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e));if(globalThis.OffscreenCanvas===void 0){class e{constructor(){return f(this)}save(){}restore(){}measureText(e){return{width:e.length}}}class t{constructor(e,t){return f(this)}getContext(t){return t===`2d`?new e:null}}function f(e){return new Proxy(e,{get:function(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t,n);throw Error(`OffscreenCanvas mock: "${String(t)}" is not implemented.\nAdd it to MockOffscreenCanvas or MockOffscreenCanvasRenderingContext2D if needed.`)}})}globalThis.OffscreenCanvas=t}if(globalThis.DOMParser===void 0&&(globalThis.DOMParser=class{parseFromString(){return{querySelector(){return null},querySelectorAll(){return[]},body:{}}}}),globalThis.document===void 0){let e=function(){};globalThis.document={implementation:{createDocument(){return{}}},addEventListener:e,removeEventListener:e,querySelectorAll(){return[]},querySelector(){return null},createElement(){return{setAttribute(){},getBoundingClientRect(){return{width:0,height:0}}}},createTextNode(){return{}},cookie:``,head:{querySelectorAll(){return[]}},body:{classList:{add:e,remove:e,contains:e},contains(){return!1},appendChild(){},removeChild(){}}}}function p(e){return e.map(h).sort((e,t)=>e.sequence-t.sequence)}let m=1;function h(e){let t=e.name,n=e.children,r=e.description,i=e.shortcut,a=e.icon,o=e.secondaryIcon,s=e.id||m++,c=e.isEnabled?e.isEnabled:()=>!0;return{id:s.toString(),name:typeof t==`function`?t:()=>t,isVisible:e.isVisible?e.isVisible:()=>!0,isEnabled:c,isActive:e.isActive,execute:e.execute?(t,n)=>{if(c(t))return e.execute(t,n)}:void 0,children:n?e=>n.map(t=>typeof t==`function`?t(e):t).flat().map(h).sort((e,t)=>e.sequence-t.sequence):()=>[],isReadonlyAllowed:e.isReadonlyAllowed||!1,isEnabledOnLockedSheet:e.isEnabledOnLockedSheet||!1,separator:e.separator||!1,icon:typeof a==`function`?a:()=>a||``,iconColor:e.iconColor,secondaryIcon:typeof o==`function`?o:()=>o||``,description:typeof r==`function`?r:()=>r||``,shortcut:i||``,textColor:e.textColor,sequence:e.sequence||0,onStartHover:e.onStartHover,onStopHover:e.onStopHover}}function g(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r];i.isVisible(e)&&(!_(i)||v(e,i))&&n.push(i),i.separator&&r!==t.length-1&&n[n.length-1]!==`separator`&&n.push(`separator`)}return n[n.length-1]===`separator`&&n.pop(),n.length===1&&n[0]===`separator`?[]:n}function _(e){return!e.execute}function v(e,t){return t.children(e).some(t=>t.isVisible(e))}function y(e,t){let n=t.children?.(e);return n.length?n.some(t=>y(e,t)):t.isEnabled(e)?e.model.getters.isReadonly()?t.isReadonlyAllowed:!0:!1}let b=.5,ee=`#017E84`,te=`#F8F9FA`,ne=`#E8EAED`,re=`#595959`,ie=`#666666`,ae=`#3266ca`,oe=`#FFFFFF`,se=11982760,ce=ee,le=`#188038`,ue=`light-dark(#9B359B, #B972A6)`,de=`#00000000`,fe=`#111827`,pe=`#ced4da`,me=`#D8DADD`,he=`#374151`;he+``;let ge=ee,_e={minColor:`#FFF5EB`,midColor:`#FD8D3C`,maxColor:`#7F2704`},ve=`#F28C28`,ye=`#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`.split(`.`),be=[50,75,100,125,150,200],xe={align:`left`,verticalAlign:`bottom`,wrapping:`overflow`,bold:!1,italic:!1,strikethrough:!1,underline:!1,fontSize:10,fillColor:``,textColor:``,rotation:0,hideGridLines:!1},Se=.001,Ce={...xe,align:`right`},we=xe.verticalAlign,Te=xe.wrapping,Ee=xe.fontSize,De=`'Roboto', arial`,Oe={style:`thin`,color:`#000000`},ke=`START_REVISION`,Ae=`difference`,je=`#43C5B1`,Me=`#EA6175`,Ne=.4,Pe=[`'`,`*`,`?`,`/`,`\\`,`[`,`]`],Fe=/'|\*|\?|\/|\\|\[|\]/,Ie=0;function Le(){return Ie}function Re(e){Ie=e}let ze=[6,7,8,9,10,11,12,14,18,24,36],Be={hasFilters:!1,totalRow:!1,firstColumn:!0,lastColumn:!1,numberOfHeaders:1,bandedRows:!0,bandedColumns:!1,styleId:`TableStyleMedium5`,automaticAutofill:!1},Ve=`PivotTableStyleMedium12`,He={symbol:`$`,position:`before`,decimalPlaces:2,code:``,name:`Dollar`},Ue={fontSize:16,color:he},We=`light-dark(#000000, #ffffff)`,Ge=`#3da4ab`,Ke={OPERATOR:Ge,NUMBER:`#02c39a`,STRING:`#00a82d`,FUNCTION:We,DEBUGGER:Ge,LEFT_PAREN:We,RIGHT_PAREN:We,ARG_SEPARATOR:We,ORPHAN_RIGHT_PAREN:`#ff0000`},qe=[`thin`,`medium`,`thick`,`dashed`,`dotted`];function Je(e){return Array.isArray(e)&&Array.isArray(e[0])}let Ye=new RegExp(Fe,`g`);function Xe(e){return`clone`in e&&e.clone instanceof Function}function Ze(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function x(e){switch(typeof e){case`object`:{if(e===null)return e;if(Xe(e))return e.clone();if(!(Qe(e)||e instanceof Array))throw Error(`Unsupported type: only objects and arrays are supported`);let t=Array.isArray(e)?Array(e.length):{};if(Array.isArray(e))for(let n=0,r=e.length;n<r;n++)n in e&&(t[n]=x(e[n]));else for(let n in e)t[n]=x(e[n]);return t}case`number`:case`string`:case`boolean`:case`function`:case`undefined`:return e;default:throw Error(`Unsupported type: ${typeof e}`)}}function Qe(e){return typeof e==`object`&&!!e&&(e?.constructor===Object||e?.constructor===void 0)}function $e(e){return et(e,`'`)}function et(e,t=`"`){return e.startsWith(t)&&(e=e.slice(1)),e.endsWith(t)&&(e=e.slice(0,-1)),e}function tt(e){return e.match(/\w/g)?.length!==e.length&&(e=`'${e}'`),e}function nt(e,t=` `){return e.replace(Ye,t)}function S(e,t,n){return e<t?t:e>n?n:e}function C(e,t,n=1){if(t<=e&&n>0)return[];if(n===0)throw Error(`range() step must not be zero`);let r=Math.ceil(Math.abs((t-e)/n)),i=Array(r);for(let t=0;t<r;t++)i[t]=e+t*n;return i}function rt(e){return e.reduce((e,t,n,r)=>(Math.abs(t-r[n-1])===1?e[e.length-1].push(t):e.push([t]),e),[])}function*it(e,t){t.next();for(let n of e){let e=t.next();yield{...n,next:e.done?void 0:e.value}}}function at(e){let t=e.toUpperCase();return t===`TRUE`||t===`FALSE`}let ot=/^\[(.+)\]\((.+)\)$/,st=/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;function ct(e){return ot.test(e)}function lt(e){return st.test(e)}function ut(e,t){return`[${e}](${t})`}function dt(e){let t=e.match(ot)||[],n=t[1],r=t[2];if(!n||!r)throw Error(`Could not parse markdown link ${e}.`);return{label:n,url:r}}let ft=`o-spreadsheet://`;function pt(e){return e.startsWith(ft)}function mt(e){return`${ft}${e}`}function ht(e){if(e.startsWith(ft))return e.slice(16);throw Error(`${e} is not a valid sheet link`)}function w(e){return e!==void 0}function gt(e){return e===void 0?!0:Object.values(e).every(e=>typeof e==`object`?gt(e):!e)}function _t(e,t,n){let r,i=!1,a=function(){let a=this,o=Array.from(arguments);if(!i&&n)return i=!0,e.apply(a,o);function s(){r=void 0,i=!1,e.apply(a,o)}clearTimeout(r),r=setTimeout(s,t)};return a.isDebouncePending=()=>r!==void 0,a.stopDebounce=()=>{clearTimeout(r)},a}function vt(e){let t=!1;return async(...n)=>{t||(t=!0,await Promise.resolve(),t=!1,e(...n))}}function yt(e,t){let n=0;return function(...r){let i=Date.now();if(i-n>=t)return n=i,e(...r)}}function bt(e){let t=``;for(let n=0,r=e.length;n<r;n++)t+=e[n];return t}function xt(e){let t=!1,n,r=()=>(t||=(n=e instanceof Function?e():e,!0),n);return r.map=e=>xt(()=>e(r())),r}function St(e,t){let n=e.slice(t).find(e=>e);return n||=e.slice(0,t).reverse().find(e=>e),n||``}function Ct(e,t){return e===`after`?t+1:t}function T(...e){if(e.length<=1)return!0;for(let t=1;t<e.length;t++)if(!wt(e[0],e[t]))return!1;return!0}function wt(e,t){if(e===t)return!0;if(e&&!t||t&&!e||typeof e!=typeof t||typeof e!=`object`)return!1;for(let n in t)if(!(n in e)&&t[n]!==void 0)return!1;for(let n in e){if(typeof e[n]!=typeof t[n])return!1;if(typeof e[n]==`object`){if(!wt(e[n],t[n]))return!1}else if(e[n]!==t[n])return!1}return!0}function Tt(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!T(e[n],t[n]))return!1;return!0}function Et(e,t){if(e.length<t.length)return!1;let n=new Set(e);return t.every(e=>n.has(e))}function Dt(e){if(!e)return e;let t={...e};return Object.keys(t).forEach(e=>!t[e]&&delete t[e]),t}let Ot=[` `,`\f`,`\v`,`\xA0`,` `,` `,` `,`\u2028`,`\u2029`,` `,` `,` `,``],kt=new RegExp(Ot.join(`|`),`g`),At=/(\r\n|\r)/g,jt=Ot.concat([` `]);function Mt(e){return e?e.replace(At,` `):``}function Nt(e){let t=Array.from(e).sort((e,t)=>e-t);for(let e=1;e<t.length;e++)if(t[e]-t[e-1]!==1)return!1;return!0}function Pt(e){let t=new Map,n=e.name?e.name+` (memoized)`:`memoized`;return{[n](...n){return t.has(n[0])||t.set(n[0],e(...n)),t.get(n[0])}}[n]}function Ft(e,t){let n=new Set(t),r=[];for(let t=0;t<e.length;t++)n.has(t)||r.push(e[t]);return r}function It(e,t,n){return e.slice(0,n).concat(t).concat(e.slice(n))}function Lt(e,t,n){let r=[...e];return r[n]=t,r}function Rt(e){return e.split(` `).map(e=>e.replace(/\s+/g,` `).trim()).join(` `)}function zt(e,t,n){return t>n?zt(e,n,t):e>=t&&e<=n}function Bt(e,t){let n=Ze(e),r=t.matchCase?``:`i`;return t.exactMatch&&(n=`^${n}$`),RegExp(n,r)}function Vt(e){let t=e.length;if(t<1e5)return Math.max(...e);let n=-1/0;for(;t--;)n=e[t]>n?e[t]:n;return n}function Ht(e){let t=e.length;if(t<1e5)return Math.min(...e);let n=1/0;for(;t--;)n=e[t]<n?e[t]:n;return n}var Ut=class{text;currentIndex=0;current;constructor(e){this.text=e,this.current=e[0]}shift(){let e=this.current,t=this.text[++this.currentIndex];return this.current=t,e}advanceBy(e){this.currentIndex+=e,this.current=this.text[this.currentIndex]}isOver(){return this.currentIndex>=this.text.length}remaining(){return this.text.substring(this.currentIndex)}currentStartsWith(e){if(this.current!==e[0])return!1;for(let t=1;t<e.length;t++)if(this.text[this.currentIndex+t]!==e[t])return!1;return!0}};function Wt(e,t=e=>e){let n=new Set;return e.filter(e=>{let r=t(e);return n.has(r)?!1:(n.add(r),!0)})}function Gt(e){let t={};for(let n in e)for(let r in e[n])t[r]||(t[r]={}),t[r][n]=e[n][r];return t}function Kt(e,t,n={}){let r=n.compute??((e,t)=>`${e} (${t})`),i=n.computeFirstOne??!1,a=n.start??1,o=i?r(e,a):e;for(;t.includes(o);)o=r(e,a++);return o}function qt(e){return e.startsWith(`=`)||e.startsWith(`+`)}function Jt(e){return{bold:e.bold,italic:e.italic,fontSize:e.fontSize,textColor:e.color,align:e.align}}function Yt(e,t){return e.isFormula&&e.compiledFormula.usesSymbol(t)}function Xt(e,t,n){let{sheetId:r,col:i,row:a}=t;if(!qt(n))return;let o=e.evaluateFormula(r,n,{sheetId:r,col:i,row:a});if(!Je(o))return;let s=e.getNumberRows(r),c=e.getNumberCols(r);return{missingRows:a+o[0].length-s,missingCols:i+o.length-c}}function Zt(e){if(e<0)throw Error(`number must be positive. Got ${e}`);return e<26?String.fromCharCode(65+e):Zt(Math.floor(e/26)-1)+Zt(e%26)}function Qt(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=$t(e[r]);t=t*26+n}return t-1}function $t(e){let t=e.charCodeAt(0);return t>=65&&t<=90?t-64:t-96}function en(e){return e>=`A`&&e<=`Z`||e>=`a`&&e<=`z`}function tn(e){return e>=`0`&&e<=`9`}let nn=Qt(`ZZZ`);function rn(e){for(;e.current===` `;)e.advanceBy(1)}function an(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!en(e.current))return-1;let t=0;for(;e.current&&en(e.current);)t=t*26+$t(e.shift());return t}function on(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!tn(e.current))return-1;let t=0;for(;e.current&&tn(e.current);)t=t*10+Number(e.shift());return t}function sn(e){let t=new Ut(e);rn(t);let n=an(t);if(n===-1||!t.current)throw Error(`Invalid cell description: ${e}`);let r=on(t);rn(t);let i=n-1,a=r-1;if(!t.isOver()||i>nn||a>9999998)throw Error(`Invalid cell description: ${e}`);return{col:i,row:a}}function E(e,t,n={colFixed:!1,rowFixed:!1}){return(n.colFixed?`$`:``)+Zt(e)+(n.rowFixed?`$`:``)+String(t+1)}function cn(e,t=[]){if(e.length<=1&&t.length===0)return e;let n=[0],r=new Map([[0,[]]]);return ln(n,r,e,!1),ln(n,r,t,!0),mn(n,r)}function ln(e,t,n,r=!1){for(let i of n){let n=i.left,a=i.right===void 0?void 0:i.right+1,o=dn(e,t,n,!0,0),s=dn(e,t,a,!1,o);for(let n=o;n<=s;n++)fn(t.get(e[n]),i,r);pn(e,t,o,s)}}function un(e,t,n){let r=n.left,i=n.right,a=hn(e,r,0),o=i===void 0?e.length-1:hn(e,i,a),s=n.top,c=n.bottom===void 0?void 0:n.bottom+1;for(let n=a;n<=o;n++){let r=t.get(e[n]),i=hn(r,s,0);if(i===-1||i%2!=0)return!1;let a=c===void 0?r.length:gn(r,c,0);if(i+1!==a)return!1}return!0}function dn(e,t,n,r,i){if(n===void 0)return e.length-1;let a=hn(e,n,i);return n===e[a]?r?a:a-1:(e.splice(a+1,0,n),t.set(n,[...t.get(e[a])]),r?a+1:a)}function fn(e,t,n=!1){let r=t.top,i=t.bottom===void 0?void 0:t.bottom+1,a=[],o=hn(e,r,0,!1);if((o%2!=0&&!n||o%2==0&&n)&&a.push(r),i===void 0){e.splice(o+1),e.push(...a);return}let s=gn(e,i,0,!1);(s%2==0&&!n||s%2!=0&&n)&&a.push(i);let c=s-o-1,l=a.length,u=o+1;u===e.length-1&&c===1&&l===1?e[u]=a[0]??a[1]:e.splice(u,c,...a)}function pn(e,t,n,r){let i=n-1==-1?0:n-1,a=r===e.length-1?r:r+1;for(let n=a;n>i;n--)Tt(t.get(e[n]),t.get(e[n-1]))&&(t.delete(e[n]),e.splice(n,1))}function mn(e,t){let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=t.get(a);if(!o||o.length===0){n.push(...r),r=[];continue}let s=e[i+1];s!==void 0&&s--;let c=[];for(let e=0;e<o.length;e+=2){let t=o[e],n=o[e+1];n!==void 0&&n--;let i={top:t,left:a,bottom:n,right:s};(n===void 0&&t!==0||s===void 0&&a!==0)&&(i.hasHeader=!0);let l=!1;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t.top===i.top&&t.bottom===i.bottom){t.right=i.right,r.splice(e,1),c.push(t),l=!0;break}}l||c.push(i)}n.push(...r),r=c}return n.push(...r),n}function hn(e,t,n=0,r=!0){let i=e.length-1,a=-1;for(;n<=i;){let o=n+(i-n>>1);if(e[o]===t&&r)return o;e[o]<t?(a=o,n=o+1):i=o-1}return a}function gn(e,t,n=0,r=!0){let i=e.length-1,a=e.length;for(;n<=i;){let o=n+(i-n>>1);if(e[o]===t&&r)return o;e[o]>t?(a=o,i=o-1):n=o+1}return a}function _n(e){let t=new Ut(e);rn(t);let n=e.indexOf(`!`);n!==-1&&t.advanceBy(n+1);let r=an(t),i=on(t),a,o,s,c,l=!1,u=!1,d=!1;if(i===-1?(s=c=r-1,a=o=0,l=!0):r===-1?(a=o=i-1,s=c=0,u=!0):(s=c=r-1,a=o=i-1,d=!0),rn(t),t.current===`:`){t.advanceBy(1),rn(t);let e=an(t),n=on(t);n===-1?(c=e-1,l=!0):e===-1?(o=n-1,u=!0):(c=e-1,o=n-1,a=l?o:a,s=u?c:s,d=!0)}let f={top:a,left:s,bottom:l?void 0:o,right:u?void 0:c};return d&&=u||l,d&&(f.hasHeader=d),f}function vn(e){let t=Hn(_n(e)),n=t.bottom,r=t.right;if(n!==void 0&&n>9999998||r!==void 0&&r>nn)throw Error(`Range string out of bounds: ${e}`);if(n===void 0&&r===void 0)throw Error(`Wrong zone xc. The zone cannot be at the same time a full column and a full row`);return t}function yn(e){let t=vn(e);if(t.bottom===void 0||t.right===void 0)throw Error(`This does not support unbounded ranges`);return t}function bn(e){return Sn(vn(e))}function xn(e){try{return bn(e)}catch{return!1}}function Sn(e){let{bottom:t,top:n,left:r,right:i}=e;return t!==void 0&&isNaN(t)||isNaN(n)||isNaN(r)||i!==void 0&&isNaN(i)?!1:Cn(e)&&e.top>=0&&e.left>=0}function Cn(e){return(e.bottom===void 0||e.bottom>=e.top&&e.bottom>=0)&&(e.right===void 0||e.right>=e.left&&e.right>=0)}function wn(e){let{top:t,bottom:n,left:r,right:i}=e,a=`hasHeader`in e?e.hasHeader:!1,o=t===n&&r===i;if(n===void 0&&i!==void 0)return t===0&&!a?`${Zt(r)}:${Zt(i)}`:`${E(r,t)}:${Zt(i)}`;if(i===void 0&&n!==void 0)return r===0&&!a?`${t+1}:${n+1}`:`${E(r,t)}:${n+1}`;if(n!==void 0&&i!==void 0)return o?E(r,t):`${E(r,t)}:${E(i,n)}`;throw Error(`Bad zone format`)}function Tn(e,t,n,r,i){let a=t===`left`?`columns`:`rows`,o=r===`before`?n-1:n,s=e[t===`left`?`right`:`bottom`];return e[t]<=o&&s&&s>o?Un(e,a,`RESIZE`,i):o<e[t]?Un(e,a,`MOVE`,i):{...e}}function En(e,t,n,r,i){let a=t===`left`?`columns`:`rows`,o=r===`before`?n-1:n,s=t===`left`?`right`:`bottom`;return e[t]<=o&&e[s]>o?Un(e,a,`RESIZE`,i):o<e[t]?Un(e,a,`MOVE`,i):{...e}}function Dn(e,t,n){let r=t===`left`?`right`:`bottom`,i=e[t],a=e[r];for(let o of n.sort((e,t)=>t-e))e[t]>o&&(i--,a--),e[t]<o&&e[r]>=o&&a--;return{...e,[t]:i,[r]:a}}function On(e,t,n){let r=t===`left`?`right`:`bottom`,i=e[t],a=e[r],o=e[r];for(let r of n.sort((e,t)=>t-e))e[t]>r&&(i--,a!==void 0&&a--),o!==void 0&&a!==void 0&&e[t]<=r&&o>=r&&a--;if(!(a!==void 0&&i>a))return{...e,[t]:i,[r]:a}}function kn(...e){return{top:Math.min(...e.map(e=>e.top)),left:Math.min(...e.map(e=>e.left)),bottom:Math.max(...e.map(e=>e.bottom)),right:Math.max(...e.map(e=>e.right))}}function An(...e){return{top:Math.min(...e.map(e=>e.top)),left:Math.min(...e.map(e=>e.left)),bottom:e.some(e=>e.bottom===void 0)?void 0:Math.max(...e.map(e=>e.bottom)),right:e.some(e=>e.right===void 0)?void 0:Math.max(...e.map(e=>e.right))}}function jn(e,t){if(Nn(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom??9999998,t.bottom),right:Math.min(e.right??nn,t.right)}}function Mn(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function Nn(e,t){return!(e.bottom===void 0||e.bottom<t.top||t.bottom<e.top||e.right===void 0||e.right<t.left||t.right<e.left)}function Pn(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length;n++)if(Nn(e[t],e[n]))return!0;return!1}function Fn(e,t,n){let{left:r,right:i,top:a,bottom:o}=n;return e>=r&&e<=i&&t>=a&&t<=o}function In(e,t){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom}function Ln(e){return{numberOfRows:e.bottom-e.top+1,numberOfCols:e.right-e.left+1}}function Rn(e){let{numberOfCols:t,numberOfRows:n}=Ln(e);return t===1||n===1}function zn(e){let{top:t,left:n,bottom:r,right:i}=e;if(Xn(e)===1)return[];let a={top:t+1,bottom:r,left:n,right:n};if(i===n)return[a];let o={top:t,bottom:r,left:n+1,right:i};return t===r?[o]:[a,o]}function Bn(e){let t=[],{left:n,right:r,top:i,bottom:a}=Hn(e);for(let e of C(n,r+1))for(let n of C(i,a+1))t.push({col:e,row:n});return t}function Vn(e,t){let n=[],{left:r,right:i,top:a,bottom:o}=Hn(t);for(let t of C(r,i+1))for(let r of C(a,o+1))n.push({sheetId:e,col:t,row:r});return n}function Hn(e){return e.right!==void 0&&e.left>e.right&&(e={...e,left:e.right,right:e.left}),e.bottom!==void 0&&e.top>e.bottom&&(e={...e,top:e.bottom,bottom:e.top}),e}function Un(e,t,n,r){let i=t===`both`?r[0]:t===`columns`?r:0,a=t===`both`?r[1]:t===`rows`?r:0,o=`hasHeader`in e?e.hasHeader:!1,s;s=Yn(e)&&!o?t!==`rows`:Jn(e)&&!o?t!==`columns`:!0;let c={...e};return s&&n===`MOVE`&&(c.left+=i,c.top+=a),c.right!==void 0&&(c.right+=i),c.bottom!==void 0&&(c.bottom+=a),c}function Wn(e){return e.reverse().filter((e,t,n)=>t===n.findIndex(t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)).reverse()}function Gn(e){return e.reduce((e,t)=>{let n=e.length;for(let r=0;r<n;r++)if(Nn(e[r],t))return e[r]=kn(e[r],t),e;return e[n]=t,e},[])}function Kn(e,t){let n,r,{left:i,right:a,top:o,bottom:s}=e,{left:c,right:l,top:u,bottom:d}=t;return n=c===i?l===a?c:l:c,r=u===o?d===s?u:d:u,{col:n,row:r}}function D(e){return{left:e.col,right:e.col,top:e.row,bottom:e.row}}function qn(e){return{...e,right:e.left,bottom:e.top}}function Jn(e){return e.right===void 0}function Yn(e){return e.bottom===void 0}function Xn(e){return(e.bottom-e.top+1)*(e.right-e.left+1)}function Zn(e,t,n){return e.left<t&&t<=e.right||e.top<n&&n<=e.bottom}function Qn(e,t,n){return e.some(e=>Zn(e,t,n))}function $n(e,t){let{left:n,top:r,bottom:i,right:a}=e;if(a!==void 0&&i!==void 0)return e;if(i===void 0&&a!==void 0)return{right:a,top:r,left:n,bottom:t.numberOfRows-1};if(a===void 0&&i!==void 0)return{bottom:i,left:n,top:r,right:t.numberOfCols-1};throw Error(`Bad zone format`)}function er(e){return e.length<2?!0:cn(e).length===1}function tr(e){let t=new Set;for(let n of cn(e))for(let e of C(n.left,n.right+1))t.add(e);return t}function nr(e){let t=new Map;for(let n of e)for(let e=n.left;e<=n.right;e++){let r=t.get(e);r?(r.top=Math.min(r.top,n.top),r.bottom=Math.max(r.bottom,n.bottom)):t.set(e,{left:e,right:e,top:n.top,bottom:n.bottom})}return Array.from(t.values())}function rr(e){let t=new Set;for(let n of cn(e))for(let e of C(n.top,n.bottom+1))t.add(e);return t}function ir(e,t){return e.right+1===t.left||e.left===t.right+1?e.top<=t.bottom&&e.top>=t.top||t.top<=e.bottom&&t.top>=e.top:e.bottom+1===t.top||e.top===t.bottom+1?e.left<=t.right&&e.left>=t.left||t.left<=e.right&&t.left>=e.left:!1}function ar(e){let t=[...e],n=!0;for(;n;){n=!1;for(let e=0;e<t.length;e++){let r=t[e],i=t.findIndex((t,n)=>e!==n&&(ir(t,r)||Nn(t,r)));if(i!==-1){t[e]=kn(t[i],r),t.splice(i,1),n=!0;break}}}return t}function or(e,t){let n=[];return e.bottom<t.bottom&&n.push({...t,top:e.bottom+1}),e.right<t.right&&n.push({...t,left:e.right+1,top:e.top,bottom:e.bottom}),e.left>t.left&&n.push({...t,right:e.left-1,top:e.top,bottom:e.bottom}),e.top>t.top&&n.push({...t,bottom:e.top-1}),n}function sr(e,t){return t.type===`REMOVE_COLUMNS_ROWS`?On(e,t.dimension===`COL`?`left`:`top`,t.elements):t.type===`ADD_COLUMNS_ROWS`?Tn(e,t.dimension===`COL`?`left`:`top`,t.base,t.position,t.quantity):e}function cr(e,t){let n=t.type===`DELETE_SHEET`&&t.sheetId;if(`sheetId`in t&&e._sheetId!==t.sheetId)return e;{let r=sr(e._zone,t);if(r&&n!==e._sheetId)return{...e,_zone:r}}}var lr=class{subscriptions={};on(e,t,n){if(!n)throw Error(`Missing callback`);this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:n})}trigger(e,t){let n=this.subscriptions[e]||[];for(let e=0,r=n.length;e<r;e++){let r=n[e];r.callback.call(r.owner,t)}}off(e,t){let n=this.subscriptions[e];n&&(this.subscriptions[e]=n.filter(e=>e.owner!==t))}clear(){this.subscriptions={}}},ur=class extends lr{dependencies=new Map;factory=new dr(this.get.bind(this));inject(e,t){if(this.dependencies.has(e)&&this.dependencies.get(e)!==t)throw Error(`Store ${e.name} already has an instance`);this.dependencies.set(e,t)}get(e){return this.dependencies.has(e)||this.dependencies.set(e,this.instantiate(e)),this.dependencies.get(e)}instantiate(e,...t){return this.factory.build(e,...t)}resetStores(){this.dependencies.clear()}dispose(){for(let e of this.dependencies.values())`dispose`in e&&typeof e.dispose==`function`&&e.dispose()}},dr=class{get;pendingBuilds=new Set;constructor(e){this.get=e}build(e,...t){if(this.pendingBuilds.has(e))throw Error(`Circular dependency detected: ${[...this.pendingBuilds,e].map(e=>e.name).join(` -> `)}`);this.pendingBuilds.add(e);let n=new e(this.get,...t);return this.pendingBuilds.delete(e),n}};function fr(e){class t{constructor(t){throw Error(`This is a abstract store for ${e}, it cannot be instantiated. Did you forget to inject your store instance? const stores = useStoreProvider(); stores.inject(MyMetaStore, storeInstance); `)}}return t}var pr=class{get;disposeCallbacks=[];constructor(e){this.get=e}onDispose(e){this.disposeCallbacks.push(e)}dispose(){this.disposeCallbacks.forEach(e=>e())}};function mr(){let e=(0,t.useEnv)();if(e.__spreadsheet_stores__ instanceof ur)return e.__spreadsheet_stores__;let n=new ur;return(0,t.useSubEnv)({__spreadsheet_stores__:n,getStore:e=>_r(n.get(e),()=>n.trigger(`store-updated`))}),(0,t.onWillUnmount)(()=>n.dispose()),n}function O(e){let n=vr((0,t.useEnv)());return gr(n,n.get(e))}function hr(e,...n){let r=vr((0,t.useEnv)()),i=r.instantiate(e,...n);return(0,t.onWillUnmount)(()=>i.dispose()),gr(r,i)}function gr(e,n){let r=(0,t.useComponent)();return _r(n,()=>{(0,t.status)(r)===`mounted`&&e.trigger(`store-updated`)})}function _r(e,t){return new Proxy(e,{get(n,r,i){let a=n,o=Reflect.get(n,r,a);return e.mutators?.includes(r)?new Proxy(o,{apply(e,n,r){Reflect.apply(e,a,r)!==`noStateChange`&&t()}}):o}})}function vr(e){let t=e.__spreadsheet_stores__;if(!(t instanceof ur))throw Error(`No store provider found. Did you forget to call useStoreProvider()?`);return t}let yr=fr(`Model`),br={Background:0,Highlights:1,Clipboard:2,Chart:4,Autofill:5,Selection:6,Headers:100},xr=Pt(()=>Object.keys(br).sort((e,t)=>br[e]-br[t]));function Sr(e,t){if(br[e])throw Error(`Layer ${e} already exists`);br[e]=t}var Cr=class{layers;mutators=[`register`,`unRegister`,`draw`,`startAnimation`,`stopAnimation`];renderers={};model;context=void 0;animationFrameId=null;registeredAnimations=new Set;constructor(e,t=xr()){this.layers=t,this.model=e(yr)}register(e){if(e.renderingLayers.length)for(let t of e.renderingLayers)this.renderers[t]||(this.renderers[t]=[]),this.renderers[t].push(e)}unRegister(e){for(let t of Object.keys(this.renderers))this.renderers[t]=this.renderers[t].filter(t=>t!==e)}drawLayer(e,t,n){let r=this.renderers[t];if(r)for(let i of r)e.ctx.save(),i.drawLayer(e,t,n),e.ctx.restore();return`noStateChange`}draw(e,t){if(e||=this.context,!e)throw Error(`Rendering context is not defined`);this.context=e;for(let n of this.layers)this.model.drawLayer(e,n),this.drawLayer(e,n,t);return`noStateChange`}startAnimation(e){if(this.registeredAnimations.add(e),!this.animationFrameId){let e=t=>{this.animationFrameId=requestAnimationFrame(e),this.draw(void 0,t)};this.animationFrameId=requestAnimationFrame(e)}return`noStateChange`}stopAnimation(e){return this.registeredAnimations.delete(e),this.registeredAnimations.size===0&&this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),`noStateChange`}dispose(){this.animationFrameId&&=(cancelAnimationFrame(this.animationFrameId),null)}},wr=class extends pr{model=this.get(yr);getters=this.model.getters;renderer=this.get(Cr);constructor(e){super(e),this.model.on(`command-dispatched`,this,this.handle),this.model.on(`command-finalized`,this,this.finalize),this.renderer.register(this),this.onDispose(()=>{this.model.off(`command-dispatched`,this),this.model.off(`command-finalized`,this),this.renderer.unRegister(this)})}get renderingLayers(){return[]}handle(e){}finalize(){}drawLayer(e,t,n){}};let Tr={id:`void-composer`,get editionMode(){return`inactive`},startEdition:()=>{throw Error(`No composer is registered`)},stopEdition:()=>{throw Error(`No composer is registered`)},setCurrentContent:()=>{throw Error(`No composer is registered`)}};var Er=class extends wr{mutators=[`focusComposer`,`focusActiveComposer`];activeComposer=Tr;_focusMode=`inactive`;get focusMode(){return this.activeComposer.editionMode===`inactive`?`inactive`:this._focusMode}focusComposer(e,t){if(this.activeComposer=e,this.getters.isReadonly())return`noStateChange`;this._focusMode=t.focusMode||`contentFocus`,this._focusMode!==`inactive`&&this.setComposerContent(t)}focusActiveComposer(e){if(this.getters.isReadonly())return`noStateChange`;if(!this.activeComposer)throw Error(`No composer is registered`);this._focusMode=e.focusMode||`contentFocus`,this._focusMode!==`inactive`&&this.setComposerContent(e)}setComposerContent({content:e,selection:t}){this.activeComposer.editionMode===`inactive`?this.activeComposer.startEdition(e,t):e&&this.activeComposer.setCurrentContent(e,t)}};let Dr=/rgba?\(|\s+|\)/gi,Or=/^#([A-F\d]{2}){3,4}$/,kr=/^light-dark\(\s*(rgba?\([0-9.,\s]+\)|#[a-f0-9]+)\s*,\s*(rgba?\([0-9.,\s]+\)|#[a-f0-9]+)\s*\)$/i,Ar=[`#eb6d00`,`#0074d9`,`#ad8e00`,`#169ed4`,`#b10dc9`,`#00a82d`,`#00a3a3`,`#f012be`,`#3d9970`,`#62A300`,`#ff4136`,`#949494`,`#ff5c9d`];function jr(e,t=1){let n=t===1?``:Math.round(t*255).toString(16).padStart(2,`0`);return Nr(e.toString(16).padStart(6,`0`))+n}function Mr(e){return typeof e==`number`?e:Number.parseInt(Nr(e).slice(1,7),16)}function Nr(e){let t=e;if(e.startsWith(`light-dark`)){let t=e.match(kr);if(!t)throw Error(`Invalid light-dark color: ${e}`);return`light-dark(${Nr(t[1])}, ${Nr(t[2])})`}if(e.startsWith(`rgb`)?t=zr(e):(t=e.replace(`#`,``).toUpperCase(),(t.length===3||t.length===4)&&(t=t.split(``).reduce((e,t)=>e+t+t,``)),t=`#${t}`),!Or.test(t))throw Error(`invalid color input: ${e}`);return t}function Pr(e){try{return Nr(e),!0}catch{return!1}}function Fr(e){try{return Wr(e),!0}catch{return!1}}let Ir=e=>e>=0&&e<=255;function Lr(e,t,n,r=1){if(!Ir(e)||!Ir(t)||!Ir(n)||r<0||r>1)throw Error(`Invalid RGBA values ${[e,t,n,r]}`);return{a:r,b:n,g:t,r:e}}function Rr(e){let{r:t,g:n,b:r}=Vr(e);t/=255,n/=255,r/=255;let i=e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4,a=i(t),o=i(n),s=i(r);return .2126*a+.7152*o+.0722*s}function zr(e){let t=e.replace(Dr,``).split(`,`),n=255;if(t.length!==3&&t.length!==4)throw Error(`invalid color`);if(t.length===4){let e=parseFloat(t.pop()||`1`);if(isNaN(e))throw Error(`invalid alpha value`);n=Math.round(e*255)}let r=t.map(e=>parseInt(e,10));return n!==255&&r.push(n),`#`+bt(r.map(e=>e.toString(16).padStart(2,`0`))).toUpperCase()}function Br(e){let t=e.r.toString(16),n=e.g.toString(16),r=e.b.toString(16),i=Math.round(e.a*255).toString(16);return t.length===1&&(t=`0`+t),n.length===1&&(n=`0`+n),r.length===1&&(r=`0`+r),i.length===1&&(i=`0`+i),i===`ff`&&(i=``),(`#`+t+n+r+i).toUpperCase()}function Vr(e){e=Nr(e);let t,n,r,i;if(e.length===7)t=parseInt(e[1]+e[2],16),n=parseInt(e[3]+e[4],16),r=parseInt(e[5]+e[6],16),i=255;else if(e.length===9)t=parseInt(e[1]+e[2],16),n=parseInt(e[3]+e[4],16),r=parseInt(e[5]+e[6],16),i=parseInt(e[7]+e[8],16);else throw Error(`Invalid color`);return i=+(i/255).toFixed(3),{a:i,r:t,g:n,b:r}}function Hr(e){e={...e},e.s/=100,e.l/=100;let t=(1-Math.abs(2*e.l-1))*e.s,n=t*(1-Math.abs(e.h/60%2-1)),r=e.l-t/2,i=0,a=0,o=0;return 0<=e.h&&e.h<60?(i=t,a=n,o=0):60<=e.h&&e.h<120?(i=n,a=t,o=0):120<=e.h&&e.h<180?(i=0,a=t,o=n):180<=e.h&&e.h<240?(i=0,a=n,o=t):240<=e.h&&e.h<300?(i=n,a=0,o=t):300<=e.h&&e.h<360&&(i=t,a=0,o=n),i=Math.round((i+r)*255),a=Math.round((a+r)*255),o=Math.round((o+r)*255),{a:e.a,r:i,g:a,b:o}}function Ur(e){let t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=a-i,s=0,c=0,l=0;return s=o===0?0:a===t?(n-r)/o%6:a===n?(r-t)/o+2:(t-n)/o+4,s=Math.round(s*60),s<0&&(s+=360),l=(a+i)/2,c=o===0?0:o/(1-Math.abs(2*l-1)),c=+(c*100).toFixed(1),l=+(l*100).toFixed(1),{a:e.a,h:s,s:c,l}}function Wr(e){return Br(Hr(e))}function Gr(e){return Ur(Vr(e))}function Kr(e,t){let n=Vr(t),r=Vr(e),i=n.a+r.a*(1-n.a);return Br({r:Math.round((n.r*n.a+r.r*r.a*(1-n.a))/i),g:Math.round((n.g*n.a+r.g*r.a*(1-n.a))/i),b:Math.round((n.b*n.a+r.b*r.a*(1-n.a))/i),a:i})}function qr(e){return Vr(typeof e==`number`?jr(e):e)}function Jr(e,t,n=0){if(!(Pr(e)&&Pr(t)))return!1;let r=Vr(e),i=Vr(t);return r.a===i.a?Math.sqrt(((r.r-i.r)/255)**2+((r.g-i.g)/255)**2+((r.b-i.b)/255)**2)<=n:!1}function Yr(e,t){if(e.startsWith(`light-dark`)){let n=e.match(kr);if(!n)throw Error(`Invalid light-dark color: ${e}`);return`light-dark(${Yr(n[1],t)}, ${Yr(n[2],t)})`}return t===1?Nr(e).slice(0,7):Br({...Vr(e),a:t})}function Xr(e,t){let n=Gr(e);return t===1?`#fff`:(n.l=t*(100-n.l)+n.l,Wr(n))}function Zr(e,t){let n=Gr(e);return t===1?`#000`:(n.s=Math.min(100,t*n.s+n.s),n.l-=t*n.l,Wr(n))}function Qr(e){return Rr(e)<.6?Xr(e,.9):Zr(e,.75)}let $r=`#4EA7F2`,ei=[$r,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#FFD86D`],ti=[$r,`#3188E6`,`#43C5B1`,`#00A78D`,`#EA6175`,`#CE4257`,`#F4A261`,`#F48935`,`#8481DD`,`#5752D1`,`#FFD86D`,`#FFBC2C`],ni=[$r,`#3188E6`,`#056BD9`,`#A76DBC`,`#7F4295`,`#6D2387`,`#EA6175`,`#CE4257`,`#982738`,`#43C5B1`,`#00A78D`,`#0E8270`,`#F4A261`,`#F48935`,`#BE5D10`,`#8481DD`,`#5752D1`,`#3A3580`,`#A4A8B6`,`#7E8290`,`#545B70`,`#FFD86D`,`#FFBC2C`,`#C08A16`],ri=[$r,`#3188E6`,`#056BD9`,`#155193`,`#A76DBC`,`#7F4295`,`#6D2387`,`#4F1565`,`#EA6175`,`#CE4257`,`#982738`,`#791B29`,`#43C5B1`,`#00A78D`,`#0E8270`,`#105F53`,`#F4A261`,`#F48935`,`#BE5D10`,`#7D380D`,`#8481DD`,`#5752D1`,`#3A3580`,`#26235F`,`#A4A8B6`,`#7E8290`,`#545B70`,`#3F4250`,`#FFD86D`,`#FFBC2C`,`#C08A16`,`#936A12`],ii=[$r,`#43C5B1`,`#EA6175`,`#F4A261`,`#8481DD`,`#FFD86D`,`#3188E6`,`#00A78D`,`#CE4257`,`#F48935`,`#5752D1`,`#FFBC2C`],ai=[$r,`#A76DBC`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#A4A8B6`,`#FFD86D`,`#3188E6`,`#7F4295`,`#CE4257`,`#00A78D`,`#F48935`,`#5752D1`,`#7E8290`,`#FFBC2C`,`#056BD9`,`#6D2387`,`#982738`,`#0E8270`,`#BE5D10`,`#3A3580`,`#545B70`,`#C08A16`],oi=[$r,`#A76DBC`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#A4A8B6`,`#FFD86D`,`#3188E6`,`#7F4295`,`#CE4257`,`#00A78D`,`#F48935`,`#5752D1`,`#7E8290`,`#FFBC2C`,`#056BD9`,`#6D2387`,`#982738`,`#0E8270`,`#BE5D10`,`#3A3580`,`#545B70`,`#C08A16`,`#155193`,`#4F1565`,`#791B29`,`#105F53`,`#7D380D`,`#26235F`,`#3F4250`,`#936A12`];function si(e,t){return t[e%t.length]}function ci(e){return e<=6?ei:e<=12?ti:e<=24?ni:ri}function li(e){return e<=6?ei:e<=12?ii:e<=24?ai:oi}var ui=class{preferredColors;currentColorIndex=0;palette;constructor(e,t=[]){this.preferredColors=t,this.palette=ci(e).filter(e=>!t.includes(e))}next(){return this.preferredColors?.[this.currentColorIndex]?this.preferredColors[this.currentColorIndex++]:si(this.currentColorIndex++,this.palette)}},di=class extends ui{constructor(e,t=[]){super(e,t),this.palette=li(e).filter(e=>!t.includes(e))}},fi=class{availableColors;colors={};constructor(e=12){this.availableColors=new di(e)}get(e){return this.colors[e]||(this.colors[e]=this.availableColors.next()),this.colors[e]}};let pi={greys:[`#ffffff`,`#808080`,`#000000`],blues:[`#f7fbff`,`#6aaed6`,`#08306b`],reds:[`#fff5f0`,`#fb694a`,`#67000d`],greens:[`#f7fcf5`,`#73c476`,`#00441b`],oranges:[`#fff5eb`,`#fd8c3b`,`#7f2704`],purples:[`#fcfbfd`,`#9e9ac8`,`#3f007d`],viridis:[`#440154`,`#21918c`,`#fde725`],cividis:[`#00224e`,`#7d7c78`,`#fee838`],rainbow:[`#B41DB4`,`#FFFF00`,`#00FFFF`]},mi=Object.keys(pi);function hi(e){if(e.length<2)throw Error(`Color scale must have at least 2 points`);let t=[...e.sort((e,t)=>e.value-t.value)],n=[];for(let e=1;e<t.length;e++){let r=qr(t[e-1].color).a,i=qr(t[e].color).a,a=Mr(t[e-1].color),o=Mr(t[e].color);n.push({min:t[e-1].value,max:t[e].value,minColor:a,maxColor:o,minColorAlpha:r,maxColorAlpha:i,colorDiff:gi(t[e-1].value,t[e].value,a,o)})}return e=>{if(e<n[0].min)return jr(n[0].minColor,n[0].minColorAlpha);for(let t of n)if(e>=t.min&&e<=t.max)return jr(_i(e,t.min,t.minColor,t.colorDiff),t.maxColorAlpha);return jr(n[n.length-1].maxColor,n[n.length-1].maxColorAlpha)}}function gi(e,t,n,r){let i=t-e,a=(n>>16)%256-(r>>16)%256,o=(n>>8)%256-(r>>8)%256,s=n%256-r%256;return[a/i,o/i,s/i]}function _i(e,t,n,r){let[i,a,o]=r,s=Math.round((n>>16)%256-i*(e-t)),c=Math.round((n>>8)%256-a*(e-t)),l=Math.round(n%256-o*(e-t));return s<<16|c<<8|l}let vi=/(.*?)\((.*?)\)(.*)/,yi=[`ANY`,`BOOLEAN`,`DATE`,`NUMBER`,`STRING`,`RANGE`,`RANGE<BOOLEAN>`,`RANGE<DATE>`,`RANGE<NUMBER>`,`RANGE<STRING>`];function k(e,t=``,n){return bi(e,t,n)}function bi(e,t,n){let r=e.match(vi),i=r[1].trim();if(!i)throw Error(`Function argument definition is missing a name: '${e}'.`);let a=[],o=!1,s=!1,c;for(let e of r[2].split(`,`)){let t=e.trim().toUpperCase(),n=yi.find(e=>t===e);n?a.push(n):t===`RANGE<ANY>`?a.push(`RANGE`):t===`OPTIONAL`?o=!0:t===`REPEATING`?s=!0:t.startsWith(`DEFAULT=`)&&(c=e.trim().slice(8))}let l={name:i,description:t,type:a};return(a.includes(`ANY`)||a.includes(`RANGE`))&&(l.acceptErrors=!0),o&&(l.optional=!0),s&&(l.repeating=!0),c!==void 0&&(l.default=!0,l.defaultValue=c),a.some(e=>e.startsWith(`RANGE`))&&(l.acceptMatrix=!0),a.every(e=>e.startsWith(`RANGE`))&&(l.acceptMatrixOnly=!0),n&&n.length>0&&(l.proposalValues=n),l}function xi(e,t){let n=0,r=0,i=0,a=0;for(let e of t.args)n++,!e.optional&&!e.default&&r++,e.repeating&&i++,(e.optional||e.default)&&!e.repeating&&a++;let o=t;return o.minArgRequired=r,o.maxArgPossible=i?1/0:n,o.nbrArgRepeating=i,o.nbrOptionalNonRepeatingArgs=a,o.hidden=t.hidden||!1,o.name=e,o}let Si={};function Ci(e,t){let n=e.name;return Si[n]?.[t]||(Si[n]||(Si[n]={}),Si[n][t]||(Si[n][t]=wi(e,t)),Si[n][t])}function wi(e,t){let n={},r=e.nbrArgRepeating?Math.floor((t-e.minArgRequired)/e.nbrArgRepeating):0,i=e.nbrArgRepeating*r,a=t-e.minArgRequired-i,o=0,s=0;for(let t=0;t<e.args.length;t++){let i=e.args[t];if((i.optional||i.default)&&!i.repeating){s<a&&(n[o]={index:t},o++),s++;continue}if(i.repeating){let a=+!i.optional;for(let i=0;i<r+a;i++)for(let r=0;r<e.nbrArgRepeating;r++)n[o]={index:t+r,repeatingGroupIndex:i},o++;t+=e.nbrArgRepeating-1;continue}n[o]={index:t},o++}return n}function Ti(e){if(e.nbrArgRepeating&&e.nbrOptionalNonRepeatingArgs>=e.nbrArgRepeating)throw Error(`Function ${e.name} has more optional arguments than repeatable ones.`);let t=!1,n=!1;for(let r of e.args)if(r.repeating){if(!n&&t)throw Error(`Function ${e.name} has non-consecutive repeating arguments. All repeating arguments must be declared consecutively.`);t=!0,n=!0}else n=!1}var Ei=class{content={};add(e,t){if(e in this.content)throw Error(`${e} is already present in this registry!`);return this.replace(e,t)}replace(e,t){return this.content[e]=t,this}get(e){let t=this.content[e];if(!t&&!(e in this.content))throw Error(`Cannot find ${e} in this registry!`);return t}contains(e){return e in this.content}getAll(){return Object.values(this.content)}getKeys(){return Object.keys(this.content)}remove(e){delete this.content[e]}};let Di=e=>e,Oi=()=>!1,ki=Di,Ai=Oi;function ji(e,...t){if(t.length===1&&typeof t[0]==`object`&&!(t[0]instanceof String)){let n=t[0];e=e.replace(/\%\(([^\)]+)\)s/g,(e,t)=>n[t])}else t.length>0&&(e=e.replace(/\%s/g,()=>t.shift()));return e}function Mi(e,t=()=>!0){ki=e,Ai=t}function Ni(){ki===Di&&Ai===Oi&&(Ai=()=>!0)}let A=function(e,...t){return Ai()?ji(ki(e),...t):new Pi(e,t)};var Pi=class extends String{values;constructor(e,t){super(e),this.values=t}valueOf(){let e=super.valueOf();return Ai()?ji(ki(e),...this.values):ji(e,...this.values)}toString(){return this.valueOf()}};let j={NotAvailable:`#N/A`,InvalidReference:`#REF`,BadExpression:`#BAD_EXPR`,CircularDependency:`#CYCLE`,UnknownFunction:`#NAME?`,DivisionByZero:`#DIV/0!`,InvalidNumber:`#NUM!`,SpilledBlocked:`#SPILL!`,GenericError:`#ERROR`,NullError:`#NULL!`},Fi=new Set(Object.values(j));var M=class{message;value;constructor(e=A(`Error`),t=j.GenericError){this.message=e,this.value=t,this.message=e.toString()}},Ii=class extends M{constructor(e=A(`Invalid expression`)){super(e,j.BadExpression)}},Li=class extends M{constructor(e=A(`Circular reference`)){super(e,j.CircularDependency)}},Ri=class extends M{constructor(e=A(`Invalid reference`)){super(e,j.InvalidReference)}},zi=class extends M{constructor(e=A(`Data not available`)){super(e,j.NotAvailable)}},Bi=class extends M{constructor(e=A(`Unknown function`)){super(e,j.UnknownFunction)}},Vi=class extends M{errorOriginPosition;constructor(e=A(`Spill range is not empty`),t){super(e,j.SpilledBlocked),this.errorOriginPosition=t}},Hi=class extends M{constructor(e=A(`Division by zero`)){super(e,j.DivisionByZero)}},Ui=class extends M{constructor(e=A(`Number too large`)){super(e,j.InvalidNumber)}},N=class e{jsDate;constructor(e,t,n,r=0,i=0,a=0){this.jsDate=new Date(Date.UTC(e,t,n,r,i,a,0))}static fromTimestamp(t){let n=new Date(t);return new e(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds())}static now(){let t=new Date;return new e(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds())}toString(){return this.jsDate.toString()}toLocaleDateString(){return this.jsDate.toLocaleDateString()}getTime(){return this.jsDate.getTime()}getFullYear(){return this.jsDate.getUTCFullYear()}getMonth(){return this.jsDate.getUTCMonth()}getQuarter(){return Math.floor(this.getMonth()/3)+1}getDate(){return this.jsDate.getUTCDate()}getDay(){return this.jsDate.getUTCDay()}getHours(){return this.jsDate.getUTCHours()}getMinutes(){return this.jsDate.getUTCMinutes()}getSeconds(){return this.jsDate.getUTCSeconds()}getIsoWeek(){let e=new Date(this.jsDate.getTime()),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1));return Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7)}setFullYear(e){return this.jsDate.setUTCFullYear(e)}setMonth(e){return this.jsDate.setUTCMonth(e)}setDate(e){return this.jsDate.setUTCDate(e)}setHours(e){return this.jsDate.setUTCHours(e)}setMinutes(e){return this.jsDate.setUTCMinutes(e)}setSeconds(e){return this.jsDate.setUTCSeconds(e)}};let Wi=new N(1899,11,30),Gi=1440*60*1e3,Ki=2e3,qi=N.now().getFullYear(),Ji=N.now().getMonth(),Yi=N.fromTimestamp(0).getTime()-Wi.getTime(),Xi=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,Zi=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,Qi=jt.join(``),$i=RegExp(`\/|-|${jt.join(`|`)}`),ea=RegExp(`^(\\d{1,4})[\/${Qi}\-](\\d{1,4})([\/${Qi}\-](\\d{1,4}))?$`),ta=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function na(e,t){switch(typeof e){case`number`:return e;case`string`:return ra(e,t)?aa(e,t)?.value:!e||isNaN(Number(e))?void 0:Number(e);default:return}}function ra(e,t){return aa(e,t)!==null}let ia=new Map;function aa(e,t){return ia.has(t)||ia.set(t,new Map),ia.get(t).has(e)||ia.get(t).set(e,oa(e,t)),ia.get(t).get(e)}function oa(e,t){e=e.trim();let n=null,r=e.match(ta);if(r){if(n=ma(r[0]),n===null)return null;e=e.replace(r[0],``).trim()}let i=null,a=sa(e,t);if(a){let t=a.dateString.match($i)[0];if(i=la(a,t),i===null)return null;e=e.replace(a.dateString,``).trim()}return e!==``||!(i||n)?null:i&&i.jsDate&&n&&n.jsDate?{value:i.value+n.value,format:i.format+` `+(n.format===`hhhh:mm:ss`?`hh:mm:ss`:n.format),jsDate:new N(i.jsDate.getFullYear()+n.jsDate.getFullYear()-1899,i.jsDate.getMonth()+n.jsDate.getMonth()-11,i.jsDate.getDate()+n.jsDate.getDate()-30,i.jsDate.getHours()+n.jsDate.getHours(),i.jsDate.getMinutes()+n.jsDate.getMinutes(),i.jsDate.getSeconds()+n.jsDate.getSeconds())}:i||n}function sa(e,t){let n=e.match(ea);if(!n)return null;let[,r,i,,a]=n;if(r.length>2&&a&&a.length>2)return null;if(r.length>2)return{year:r,month:i,day:a,dateString:e,type:`ymd`};let o=ca(t);return a?a.length>2?o===`mdy`?{month:r,day:i,year:a,dateString:e,type:`mdy`}:{day:r,month:i,year:a,dateString:e,type:`dmy`}:o===`mdy`?{month:r,day:i,year:a,dateString:e,type:`mdy`}:o===`ymd`?{year:r,month:i,day:a,dateString:e,type:`ymd`}:o===`dmy`?{day:r,month:i,year:a,dateString:e,type:`dmy`}:null:i.length>2?{month:r,year:i,day:void 0,dateString:e,type:o}:o===`dmy`?{day:r,month:i,year:a,dateString:e,type:`dmy`}:{month:r,day:i,year:a,dateString:e,type:`mdy`}}function ca(e){switch(e.dateFormat[0]){case`d`:return`dmy`;case`m`:return`mdy`;case`y`:return`ymd`}throw Error(`Invalid date format in locale`)}function la(e,t){let{year:n,month:r,day:i}=e,a=fa(r),o=pa(i),s=da(n);if(s===null||a===null||o===null)return null;let c=r?.length===2&&a+1<10||i?.length===2&&o<10,l=n?.length!==2,u=new N(s,a,o);if(u.getMonth()!==a||u.getDate()!==o)return null;let d=u.getTime()-Wi.getTime(),f=ua(e,t,c,l);return{value:Math.round(d/Gi),format:f,jsDate:u}}function ua(e,t,n,r){let i=e.year?r?`yyyy`:`yy`:void 0,a=e.month?n?`mm`:`m`:void 0,o=e.day?n?`dd`:`d`:void 0;switch(e.type){case`mdy`:return[a,o,i].filter(w).join(t);case`ymd`:return[i,a,o].filter(w).join(t);case`dmy`:return[o,a,i].filter(w).join(t)}}function da(e){if(!e)return qi;let t=Number(e);switch(e.length){case 1:return Ki+t;case 2:return Ki+(Ki+t>qi+10?-100:0)+t;case 3:case 4:return t}return null}function fa(e){if(!e)return Ji;let t=Number(e);return t>=1&&t<=12?t-1:null}function pa(e){if(!e)return 1;let t=Number(e);return t>=0&&t<=31?t:null}function ma(e){if(e=e.trim(),ta.test(e)){let t=/AM/i.test(e),n=/PM/i.test(e),r=(t||n?e.substring(0,e.length-2).trim():e).split(/:/),i=r.length>=2,a=r.length===3,o=Number(r[0]),s=i?Number(r[1]):0,c=a?Number(r[2]):0,l=a?`hh:mm:ss`:`hh:mm`;if(t||n)l+=` a`;else if(!i)return null;o>=12&&t?o-=12:o<12&&n&&(o+=12),s+=Math.floor(c/60),c%=60,o+=Math.floor(s/60),s%=60,o>=24&&(l=`hhhh:mm:ss`);let u=new N(1899,11,30,o,s,c);return{value:o/24+s/1440+c/86400,format:l,jsDate:u}}return null}function ha(e){let t=Math.trunc(e),n=N.fromTimestamp(t*Gi-Yi),r=e-t;r=r<0?1+r:r;let i=Math.round(r*24),a=Math.round((r-i/24)*24*60),o=Math.round((r-i/24-a/24/60)*24*60*60);return n.setHours(i),n.setMinutes(a),n.setSeconds(o),n}function ga(e){return Math.round(_a(e))}function _a(e){return(e.getTime()-Wi.getTime())/Gi}function va(e){return new N(e.getFullYear(),e.getMonth()+1,0).getDate()}function ya(e){return va(e)===e.getDate()}function ba(e,t,n){let r=e.getFullYear(),i=e.getMonth(),a=e.getDate(),o=new N(r,i+t,1);return n&&a===va(e)||a>va(o)?o.setDate(va(o)):o.setDate(a),o}function xa(e){let t=Math.trunc(e);return t%4==0&&t%100!=0||t%400==0}function Sa(e,t,n){if(e===t)return 0;if(e>t){let n=t;t=e,e=n}let r=ha(e),i=ha(t),a=r.getDate(),o=i.getDate(),s=r.getMonth(),c=i.getMonth(),l=r.getFullYear(),u=i.getFullYear(),d=0,f=0;switch(n){case 0:a===31&&(a=30),a===30&&o===31&&(o=30),s===1&&a===(xa(l)?29:28)&&(a=30,c===1&&o===(xa(u)?29:28)&&(o=30)),d=l+(s*30+a)/360,f=u+(c*30+o)/360;break;case 1:let n=365,r=l===u,i=l+1===u;if(!r&&!i||!r&&s<c||!r&&s===c&&a<o){let e=0,t=0;for(let n=l;n<=u;n++)e++,t+=xa(n)?366:365;n=t/e}else r?xa(l)&&(n=366):(xa(l)&&s<2&&(n=366),xa(u)&&(c>1||c===1&&o===29)&&(n=366));d=e/n,f=t/n;break;case 2:d=e/360,f=t/360;break;case 3:d=e/365,f=t/365;break;case 4:a===31&&(a=30),o===31&&(o=30),d=l+(s*30+a)/360,f=u+(c*30+o)/360;break}return f-d}function Ca(e,t){let n=(t.getFullYear()-e.getFullYear())*12+t.getMonth()-e.getMonth();return e.getDate()>t.getDate()?n-1:n}function wa(e,t){let n=e.getTime(),r=t.getTime();return Math.floor((r-n)/Gi)}function Ta(e,t){let n=t.getFullYear()-e.getFullYear(),r=e.getMonth(),i=t.getMonth(),a=e.getDate(),o=t.getDate();return i>r||i===r&&o>=a?n:n-1}function Ea(e,t){return Sa(e,t,1)<1}function Da(e,t){return Math.trunc(e)===Math.trunc(t)}function Oa(e,t,n){return t>n?Oa(e,n,t):(e=Math.trunc(e),t=Math.trunc(t),n=Math.trunc(n),e>=t&&e<=n)}function ka(e,t){return Math.trunc(e)<Math.trunc(t)}function Aa(e,t){return Math.trunc(e)<=Math.trunc(t)}function ja(e,t){return Math.trunc(e)>Math.trunc(t)}function Ma(e,t){return Math.trunc(e)>=Math.trunc(t)}let Na=Pt(function(e){return e=Ze(e),RegExp(`(?:^-?\\d+(?:${e}?\\d*(?:(E|e)(\\+|-)?\\d+)?)?|^-?${e}\\d+)(?!\\w|!)`)}),Pa=Pt(function(e){let t=Ze(e.decimalSeparator),n=`(?:\\d+(?:${Ze(e.thousandsSeparator||``)}\\d{3,})*(?:${t}\\d*)?)`,r=`(?:${t}\\d+)`,i=`(?:\\s*`+n+`|`+r+`)(?:(e|E)(?:\\+|-)?(?:[0-9]|[0-9][0-9]|[12][0-9]{2}|30[0-7]))?(?:\\s*%)?`,a=`(?:\\s*-)?`,o=`(?:\\s*[\\$€])?`,s=`^(?:(?:`+[a+o+i,a+i+o,o+a+i].join(`)|(?:`)+`))$`;return new RegExp(s,`i`)});function Fa(e,t){return e?Pa(t).test(e.trim()):!1}let Ia=Pt(function(e){return RegExp(`[\$€${Ze(e.thousandsSeparator||``)}]`,`g`)});function La(e,t){e=e.replace(Ia(t),``),t.decimalSeparator!==`.`&&(e=e.replace(t.decimalSeparator,`.`));let n=Number(e);return isNaN(n)&&e.includes(`%`)&&(n=Number(e.split(`%`)[0]),!isNaN(n))?n/100:n}function Ra(e,t,n){let r=[...e].sort((e,t)=>e-t),i=(r.length+(n?-1:1))*t;if(n||i--,Number.isInteger(i))return r[i];let a=Math.ceil(i),o=Math.floor(i);return r[a]*(i-o)+r[o]*(a-i)}let za=[`number`,`string`,`boolean`,`undefined`];function Ba(e){if(e!==void 0)return Je(e)?e[0][0]?.format:e.format}function P(e){return typeof e==`string`&&Fi.has(e)}function Va(e){return{value:j.NotAvailable,message:A(`Did not find value '%s' in [[FUNCTION_NAME]] evaluation.`,I(e))}}let Ha=e=>A(`The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.`,e),Ua=A(`The function [[FUNCTION_NAME]] expects a reference to a cell or range.`),Wa=(e,t,n)=>A(`The function [[FUNCTION_NAME]] expects a number value between %s and %s inclusive, but receives %s.`,e.toString(),t.toString(),n.toString()),Ga=(e,t)=>A(`The function [[FUNCTION_NAME]] has an argument with value '%s'. It should be one of: %s.`,t,e.map(e=>`'${e}'`).join(`, `));function F(e,t){let n=eo(e);switch(typeof n){case`number`:return n;case`boolean`:return+!!n;case`string`:if(Fa(n,t)||n===``)return La(n,t);let e=aa(n,t);if(e)return e.value;throw new M(Ha(n));default:return 0}}function Ka(e,t){try{return F(e,t)}catch{return}}function qa(e,t){return z(e).map(e=>e.map(e=>{if(typeof e.value!=`number`){let n=``;throw typeof e==`object`?n=A(`Function [[FUNCTION_NAME]] expects number values for %s, but got an empty value.`,t):typeof e==`string`?n=A(`Function [[FUNCTION_NAME]] expects number values for %s, but got a string.`,t):typeof e==`boolean`&&(n=A(`Function [[FUNCTION_NAME]] expects number values for %s, but got a boolean.`,t)),new M(n)}return e.value}))}function Ja(e,t){let n=eo(e);if(n===``)throw new M(Ha(n));return F(n,t)}function Ya(e,t){return Math.trunc(F(e,t))}function Xa(e,t){return Math.trunc(Ja(e,t))}function I(e){let t=eo(e);switch(typeof t){case`string`:return t;case`number`:return t.toString();case`boolean`:return t?`TRUE`:`FALSE`;default:return``}}let Za=Pt(function(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``)}),Qa=e=>A(`The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a boolean.`,e);function L(e){let t=eo(e);switch(typeof t){case`boolean`:return t;case`string`:if(t){let e=t.toUpperCase();if(e===`TRUE`)return!0;if(e===`FALSE`)return!1;throw new M(Qa(t))}else return!1;case`number`:return!!t;default:return!1}}function $a(e){let t=eo(e);if(t===``)throw new M(Qa(t));return L(t)}function R(e,t){return ha(F(eo(e),t))}function eo(e){if(typeof e==`object`&&e&&`value`in e){if(P(e.value))throw e;return e.value}if(P(e))throw new M(``,e);return e}function to(e,t,n){for(let r of e)if(Je(r)){let e=r.length,n=r[0].length;for(let i=0;i<n;i++)for(let n=0;n<e;n++)t(r[n][i])}else n(r)}function no(e,t){to(e,e=>{if(P(e.value))throw e;t(e)},e=>{if(P(e?.value))throw e;t(e)})}function ro(e,t,n){to(e,e=>{if(typeof e?.value==`number`&&t(e),P(e?.value))throw e},e=>{t({value:Ja(e,n),format:e?.format})})}function io(e,t,n,r,i=`rowFirst`){let a=r;for(let r of e)if(Je(r)){let e=r.length,n=r[0].length;if(i===`rowFirst`)for(let i=0;i<n;i++)for(let n=0;n<e;n++)a=t(a,r[n][