@odoo/o-spreadsheet 19.0.36 → 19.0.37
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,7 +1,7 @@
|
|
|
1
1
|
(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));function f(e){return e.map(m).sort((e,t)=>e.sequence-t.sequence)}let p=1;function m(e){let t=e.name,n=e.children,r=e.description,i=e.icon,a=e.secondaryIcon,o=e.id||p++,s=e.isEnabled?e.isEnabled:()=>!0;return{id:o.toString(),name:typeof t==`function`?t:()=>t,isVisible:e.isVisible?e.isVisible:()=>!0,isEnabled:s,isActive:e.isActive,execute:e.execute?(t,n)=>{if(s(t))return e.execute(t,n)}:void 0,children:n?e=>n.map(t=>typeof t==`function`?t(e):t).flat().map(m).sort((e,t)=>e.sequence-t.sequence):()=>[],isReadonlyAllowed:e.isReadonlyAllowed||!1,separator:e.separator||!1,icon:typeof i==`function`?i:()=>i||``,iconColor:e.iconColor,secondaryIcon:typeof a==`function`?a:()=>a||``,description:typeof r==`function`?r:()=>r||``,textColor:e.textColor,sequence:e.sequence||0,onStartHover:e.onStartHover,onStopHover:e.onStopHover}}function h(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r];i.isVisible(e)&&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}var g=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 _=.5,v=`#017E84`,y=`#f5f5f5`,ee=`#F8F9FA`,te=`#E8EAED`,ne=`#595959`,re=`#666666`,ie=`#c9ccd2`,ae=`#3266ca`,oe=`#FFFFFF`,se=`#CACACA`,ce=11982760,le=v,ue=`#188038`,de=`#E0E2E4`,fe=`#4A4F59`,pe=`#999`,me=`#E2E3E3`,he=`#BCBCBC`,ge=`#9B359B`,_e=`#00000000`,ve=`#111827`,ye=`#D8DADD`,be=`#E7E9ED`,xe=`#F9FAFB`,Se=`#374151`,Ce=Se+`C2`,we=`#111827`,Te=`#714B67`,Ee=ye,De=`#111827`,Oe=`#e6f2f3`,ke=`#111827`,Ae=v,je=`#D44C591A`,Me=`#C34A41`,Ne=`#98DBE2`,Pe=`#E6F2F3`,Fe=`#F28C28`,Ie=`#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(`.`),Le={align:`left`,verticalAlign:`bottom`,wrapping:`overflow`,bold:!1,italic:!1,strikethrough:!1,underline:!1,fontSize:10,fillColor:``,textColor:``},Re={...Le,align:`right`},ze=Le.verticalAlign,Be=Le.wrapping,Ve=Le.fontSize,He=`'Roboto', arial`,Ue={style:`thin`,color:`#000000`},We=`START_REVISION`,Ge=`difference`,Ke=`#43C5B1`,qe=`#EA6175`,Je=.4,Ye=[`'`,`*`,`?`,`/`,`\\`,`[`,`]`],Xe=/'|\*|\?|\/|\\|\[|\]/,Ze=0;function Qe(){return Ze}function $e(e){Ze=e}let et=[6,7,8,9,10,11,12,14,18,24,36],tt={hasFilters:!1,totalRow:!1,firstColumn:!0,lastColumn:!1,numberOfHeaders:1,bandedRows:!0,bandedColumns:!1,styleId:`TableStyleMedium5`,automaticAutofill:!1},nt={symbol:`$`,position:`before`,decimalPlaces:2,code:``,name:`Dollar`},rt={fontSize:16,color:Se},it=`#000000`,at=`#3da4ab`,ot={OPERATOR:at,NUMBER:`#02c39a`,STRING:`#00a82d`,FUNCTION:it,DEBUGGER:at,LEFT_PAREN:it,RIGHT_PAREN:it,ARG_SEPARATOR:it,ORPHAN_RIGHT_PAREN:`#ff0000`},st=new RegExp(Xe,`g`);function ct(e){return e[0]===`"`&&(e=e.slice(1)),e[e.length-1]===`"`&&e[e.length-2]!==`\\`?e.slice(0,e.length-1):e}function lt(e){return`clone`in e&&e.clone instanceof Function}function ut(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function b(e){switch(typeof e){case`object`:{if(e===null)return e;if(lt(e))return e.clone();if(!(dt(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]=b(e[n]));else for(let n in e)t[n]=b(e[n]);return t}case`number`:case`string`:case`boolean`:case`function`:case`undefined`:return e;default:throw Error(`Unsupported type: ${typeof e}`)}}function dt(e){return typeof e==`object`&&!!e&&(e?.constructor===Object||e?.constructor===void 0)}function ft(e){return pt(e,`'`)}function pt(e,t=`"`){return e.startsWith(t)&&(e=e.slice(1)),e.endsWith(t)&&(e=e.slice(0,-1)),e}function mt(e){return e.match(/\w/g)?.length!==e.length&&(e=`'${e}'`),e}function ht(e,t=` `){return e.replace(st,t)}function x(e,t,n){return e<t?t:e>n?n:e}function S(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 gt(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*_t(e,t){t.next();for(let n of e){let e=t.next();yield{...n,next:e.done?void 0:e.value}}}function vt(e){let t=e.toUpperCase();return t===`TRUE`||t===`FALSE`}let yt=/^\[(.+)\]\((.+)\)$/,bt=/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;function xt(e){return yt.test(e)}function St(e){return bt.test(e)}function Ct(e,t){return`[${e}](${t})`}function wt(e){let t=e.match(yt)||[],n=t[1],r=t[2];if(!n||!r)throw Error(`Could not parse markdown link ${e}.`);return{label:n,url:r}}let Tt=`o-spreadsheet://`;function Et(e){return e.startsWith(Tt)}function Dt(e){return`${Tt}${e}`}function Ot(e){if(e.startsWith(Tt))return e.slice(16);throw Error(`${e} is not a valid sheet link`)}function C(e){return e!==void 0}function kt(e){return e===void 0?!0:Object.values(e).every(e=>typeof e==`object`?kt(e):!e)}function At(e,t,n){let r,i=function(){let i=this,a=Array.from(arguments);function o(){r=void 0,n||e.apply(i,a)}let s=n&&!r;clearTimeout(r),r=setTimeout(o,t),s&&e.apply(i,a)};return i.isDebouncePending=()=>r!==void 0,i.stopDebounce=()=>{clearTimeout(r)},i}function jt(e){let t=!1;return async(...n)=>{t||(t=!0,await Promise.resolve(),t=!1,e(...n))}}function Mt(e){let t=``;for(let n=0,r=e.length;n<r;n++)t+=e[n];return t}function Nt(e){let t=!1,n,r=()=>(t||=(n=e instanceof Function?e():e,!0),n);return r.map=e=>Nt(()=>e(r())),r}function Pt(e,t){let n=e.slice(t).find(e=>e);return n||=e.slice(0,t).reverse().find(e=>e),n||``}function Ft(e,t){return e===`after`?t+1:t}function w(...e){if(e.length<=1)return!0;for(let t=1;t<e.length;t++)if(!It(e[0],e[t]))return!1;return!0}function It(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(!It(e[n],t[n]))return!1}else if(e[n]!==t[n])return!1}return!0}function Lt(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!w(e[n],t[n]))return!1;return!0}function Rt(e,t){if(e.length<t.length)return!1;let n=new Set(e);return t.every(e=>n.has(e))}function zt(e){if(!e)return e;let t={...e};return Object.keys(t).forEach(e=>!t[e]&&delete t[e]),t}let Bt=[` `,`\f`,`\v`,`\xA0`,` `,` `,` `,`\u2028`,`\u2029`,` `,` `,` `,``],Vt=new RegExp(Bt.join(`|`),`g`),Ht=/(\r\n|\r)/g,Ut=Bt.concat([` `]);function Wt(e){return e?e.replace(Ht,`
|
|
2
2
|
`):``}function Gt(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 Kt(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 qt(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 Jt(e,t,n){return e.slice(0,n).concat(t).concat(e.slice(n))}function Yt(e,t,n){let r=[...e];return r[n]=t,r}function Xt(e){return e.split(`
|
|
3
3
|
`).map(e=>e.replace(/\s+/g,` `).trim()).join(`
|
|
4
|
-
`)}function Zt(e,t,n){return t>n?Zt(e,n,t):e>=t&&e<=n}function Qt(e,t){let n=ut(e),r=t.matchCase?``:`i`;return t.exactMatch&&(n=`^${n}$`),RegExp(n,r)}function $t(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 en(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 tn=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 nn(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 rn(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 an(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 on(e){return e.startsWith(`=`)||e.startsWith(`+`)}function sn(e){return{bold:e.bold,italic:e.italic,fontSize:e.fontSize,textColor:e.color,align:e.align}}let cn=/rgba?\(|\s+|\)/gi,ln=/^#([A-F\d]{2}){3,4}$/,un=[`#eb6d00`,`#0074d9`,`#ad8e00`,`#169ed4`,`#b10dc9`,`#00a82d`,`#00a3a3`,`#f012be`,`#3d9970`,`#111111`,`#62A300`,`#ff4136`,`#949494`,`#85144b`,`#001f3f`];function dn(e,t=1){let n=t===1?``:Math.round(t*255).toString(16).padStart(2,`0`);return pn(e.toString(16).padStart(6,`0`))+n}function fn(e){return typeof e==`number`?e:Number.parseInt(pn(e).slice(1,7),16)}function pn(e){let t=e;if(e.startsWith(`rgb`)?t=yn(e):(t=e.replace(`#`,``).toUpperCase(),(t.length===3||t.length===4)&&(t=t.split(``).reduce((e,t)=>e+t+t,``)),t=`#${t}`),!ln.test(t))throw Error(`invalid color input: ${e}`);return t}function mn(e){try{return pn(e),!0}catch{return!1}}function hn(e){try{return wn(e),!0}catch{return!1}}let gn=e=>e>=0&&e<=255;function _n(e,t,n,r=1){if(!gn(e)||!gn(t)||!gn(n)||r<0||r>1)throw Error(`Invalid RGBA values ${[e,t,n,r]}`);return{a:r,b:n,g:t,r:e}}function vn(e){let{r:t,g:n,b:r}=xn(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 yn(e){let t=e.replace(cn,``).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),`#`+Mt(r.map(e=>e.toString(16).padStart(2,`0`))).toUpperCase()}function bn(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 xn(e){e=pn(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 Sn(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 Cn(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 wn(e){return bn(Sn(e))}function Tn(e){return Cn(xn(e))}function En(e,t){let n=xn(t),r=xn(e),i=n.a+r.a*(1-n.a);return bn({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 Dn(e){return xn(typeof e==`number`?dn(e):e)}function On(e,t,n=0){if(!(mn(e)&&mn(t)))return!1;let r=xn(e),i=xn(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 kn(e,t){return t===1?pn(e).slice(0,7):bn({...xn(e),a:t})}function An(e,t){let n=Tn(e);return t===1?`#fff`:(n.l=t*(100-n.l)+n.l,wn(n))}function jn(e,t){let n=Tn(e);return t===1?`#000`:(n.s=Math.min(100,t*n.s+n.s),n.l-=t*n.l,wn(n))}function Mn(e){return vn(e)<.6?An(e,.9):jn(e,.75)}let Nn=[`#4EA7F2`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#FFD86D`],Pn=[`#4EA7F2`,`#3188E6`,`#43C5B1`,`#00A78D`,`#EA6175`,`#CE4257`,`#F4A261`,`#F48935`,`#8481DD`,`#5752D1`,`#FFD86D`,`#FFBC2C`],Fn=[`#4EA7F2`,`#3188E6`,`#056BD9`,`#A76DBC`,`#7F4295`,`#6D2387`,`#EA6175`,`#CE4257`,`#982738`,`#43C5B1`,`#00A78D`,`#0E8270`,`#F4A261`,`#F48935`,`#BE5D10`,`#8481DD`,`#5752D1`,`#3A3580`,`#A4A8B6`,`#7E8290`,`#545B70`,`#FFD86D`,`#FFBC2C`,`#C08A16`],In=`#4EA7F2.#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`.split(`.`),Ln=[`#4EA7F2`,`#43C5B1`,`#EA6175`,`#F4A261`,`#8481DD`,`#FFD86D`,`#3188E6`,`#00A78D`,`#CE4257`,`#F48935`,`#5752D1`,`#FFBC2C`],Rn=[`#4EA7F2`,`#A76DBC`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#A4A8B6`,`#FFD86D`,`#3188E6`,`#7F4295`,`#CE4257`,`#00A78D`,`#F48935`,`#5752D1`,`#7E8290`,`#FFBC2C`,`#056BD9`,`#6D2387`,`#982738`,`#0E8270`,`#BE5D10`,`#3A3580`,`#545B70`,`#C08A16`],zn=`#4EA7F2.#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`.split(`.`);function Bn(e,t){return t[e%t.length]}function Vn(e){return e<=6?Nn:e<=12?Pn:e<=24?Fn:In}function Hn(e){return e<=6?Nn:e<=12?Ln:e<=24?Rn:zn}var Un=class{preferredColors;currentColorIndex=0;palette;constructor(e,t=[]){this.preferredColors=t,this.palette=Vn(e).filter(e=>!t.includes(e))}next(){return this.preferredColors?.[this.currentColorIndex]?this.preferredColors[this.currentColorIndex++]:Bn(this.currentColorIndex++,this.palette)}},Wn=class extends Un{constructor(e,t=[]){super(e,t),this.palette=Hn(e).filter(e=>!t.includes(e))}},Gn=class{availableColors;colors={};constructor(e=12){this.availableColors=new Wn(e)}get(e){return this.colors[e]||(this.colors[e]=this.availableColors.next()),this.colors[e]}};function Kn(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=Dn(t[e-1].color).a,i=Dn(t[e].color).a,a=fn(t[e-1].color),o=fn(t[e].color);n.push({min:t[e-1].value,max:t[e].value,minColor:a,maxColor:o,minColorAlpha:r,maxColorAlpha:i,colorDiff:qn(t[e-1].value,t[e].value,a,o)})}return e=>{if(e<n[0].min)return dn(n[0].minColor,n[0].minColorAlpha);for(let t of n)if(e>=t.min&&e<=t.max)return dn(Jn(e,t.min,t.minColor,t.colorDiff),t.maxColorAlpha);return dn(n[n.length-1].maxColor,n[n.length-1].maxColorAlpha)}}function qn(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 Jn(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}function Yn(e){if(e<0)throw Error(`number must be positive. Got ${e}`);return e<26?String.fromCharCode(65+e):Yn(Math.floor(e/26)-1)+Yn(e%26)}function Xn(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=Zn(e[r]);t=t*26+n}return t-1}function Zn(e){let t=e.charCodeAt(0);return t>=65&&t<=90?t-64:t-96}function Qn(e){return e>=`A`&&e<=`Z`||e>=`a`&&e<=`z`}function $n(e){return e>=`0`&&e<=`9`}let er=Xn(`ZZZ`);function tr(e){for(;e.current===` `;)e.advanceBy(1)}function nr(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!Qn(e.current))return-1;let t=0;for(;e.current&&Qn(e.current);)t=t*26+Zn(e.shift());return t}function rr(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!$n(e.current))return-1;let t=0;for(;e.current&&$n(e.current);)t=t*10+Number(e.shift());return t}function ir(e){let t=new tn(e);tr(t);let n=nr(t);if(n===-1||!t.current)throw Error(`Invalid cell description: ${e}`);let r=rr(t);tr(t);let i=n-1,a=r-1;if(!t.isOver()||i>er||a>9999998)throw Error(`Invalid cell description: ${e}`);return{col:i,row:a}}function T(e,t,n={colFixed:!1,rowFixed:!1}){return(n.colFixed?`$`:``)+Yn(e)+(n.rowFixed?`$`:``)+String(t+1)}let ar=e=>e,or=()=>!1,sr=ar,cr=or;function lr(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 ur(e,t=()=>!0){sr=e,cr=t}function dr(){sr===ar&&cr===or&&(cr=()=>!0)}let E=function(e,...t){return cr()?lr(sr(e),...t):new fr(e,t)};var fr=class extends String{values;constructor(e,t){super(e),this.values=t}valueOf(){let e=super.valueOf();return cr()?lr(sr(e),...this.values):lr(e,...this.values)}toString(){return this.valueOf()}};function pr(e){return`sheetId`in e}function mr(e){return`dimension`in e&&`sheetId`in e&&`elements`in e}function hr(e){return`target`in e&&`sheetId`in e}function gr(e){return`ranges`in e}function _r(e){return`col`in e&&`row`in e&&`sheetId`in e}function vr(e){return`sheetId`in e&&`zone`in e}let yr=new Set([`RENAME_SHEET`,`DELETE_SHEET`,`CREATE_SHEET`,`DUPLICATE_SHEET`,`ADD_COLUMNS_ROWS`,`REMOVE_COLUMNS_ROWS`,`UNDO`,`REDO`,`ADD_MERGE`,`REMOVE_MERGE`,`UPDATE_LOCALE`,`ADD_PIVOT`,`UPDATE_PIVOT`,`INSERT_PIVOT`,`RENAME_PIVOT`,`REMOVE_PIVOT`,`DUPLICATE_PIVOT`]),br=new Set([`EVALUATE_CELLS`,`EVALUATE_CHARTS`,`UPDATE_CELL`,`UNHIDE_COLUMNS_ROWS`,`HIDE_COLUMNS_ROWS`,`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUP`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_ALL_HEADER_GROUPS`,`UNFOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`UPDATE_TABLE`,`UPDATE_FILTER`,`UNDO`,`REDO`]),xr=new Set([`MOVE_RANGES`]),Sr=new Set([`EVALUATE_CELLS`,`ADD_CONDITIONAL_FORMAT`,`REMOVE_CONDITIONAL_FORMAT`,`CHANGE_CONDITIONAL_FORMAT_PRIORITY`]),Cr=new Set([`AUTOFILL_CELL`,`SET_BORDER`,`SET_ZONE_BORDERS`,`SET_BORDERS_ON_TARGET`]),wr=new Set([`UNHIDE_COLUMNS_ROWS`,`HIDE_COLUMNS_ROWS`,`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUP`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_ALL_HEADER_GROUPS`,`UNFOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`UPDATE_TABLE`,`UPDATE_FILTER`]),Tr=new Set([`START`,`ACTIVATE_SHEET`,`COPY`,`RESIZE_SHEETVIEW`,`SET_VIEWPORT_OFFSET`,`EVALUATE_CELLS`,`EVALUATE_CHARTS`,`SET_FORMULA_VISIBILITY`,`UPDATE_FILTER`,`UPDATE_CHART`,`UPDATE_CAROUSEL_ACTIVE_ITEM`,`UPDATE_PIVOT`]),Er=new Set(`UPDATE_CELL.UPDATE_CELL_POSITION.CLEAR_CELL.CLEAR_CELLS.DELETE_CONTENT.ADD_COLUMNS_ROWS.REMOVE_COLUMNS_ROWS.RESIZE_COLUMNS_ROWS.HIDE_COLUMNS_ROWS.UNHIDE_COLUMNS_ROWS.SET_GRID_LINES_VISIBILITY.UNFREEZE_COLUMNS.UNFREEZE_ROWS.FREEZE_COLUMNS.FREEZE_ROWS.UNFREEZE_COLUMNS_ROWS.ADD_MERGE.REMOVE_MERGE.CREATE_SHEET.DELETE_SHEET.DUPLICATE_SHEET.MOVE_SHEET.RENAME_SHEET.COLOR_SHEET.HIDE_SHEET.SHOW_SHEET.MOVE_RANGES.ADD_CONDITIONAL_FORMAT.REMOVE_CONDITIONAL_FORMAT.CHANGE_CONDITIONAL_FORMAT_PRIORITY.CREATE_FIGURE.DELETE_FIGURE.UPDATE_FIGURE.CREATE_CAROUSEL.UPDATE_CAROUSEL.SET_FORMATTING.CLEAR_FORMATTING.SET_BORDER.SET_ZONE_BORDERS.SET_BORDERS_ON_TARGET.CREATE_CHART.UPDATE_CHART.DELETE_CHART.CREATE_TABLE.REMOVE_TABLE.UPDATE_TABLE.CREATE_TABLE_STYLE.REMOVE_TABLE_STYLE.CREATE_IMAGE.GROUP_HEADERS.UNGROUP_HEADERS.UNFOLD_HEADER_GROUP.FOLD_HEADER_GROUP.FOLD_ALL_HEADER_GROUPS.UNFOLD_ALL_HEADER_GROUPS.UNFOLD_HEADER_GROUPS_IN_ZONE.FOLD_HEADER_GROUPS_IN_ZONE.ADD_DATA_VALIDATION_RULE.REMOVE_DATA_VALIDATION_RULE.UPDATE_LOCALE.ADD_PIVOT.UPDATE_PIVOT.INSERT_PIVOT.RENAME_PIVOT.REMOVE_PIVOT.DUPLICATE_PIVOT`.split(`.`));function Dr(e){return Er.has(e.type)}function Or(e){return Tr.has(e.type)}var kr=class{reasons;constructor(e=[]){Array.isArray(e)||(e=[e]),e=[...new Set(e)],this.reasons=e.filter(e=>e!==`Success`)}static get Success(){return Ar}get isSuccessful(){return this.reasons.length===0}isCancelledBecause(e){return this.reasons.includes(e)}};let Ar=new kr,jr=function(e){return e.Success=`Success`,e.CancelledForUnknownReason=`CancelledForUnknownReason`,e.WillRemoveExistingMerge=`WillRemoveExistingMerge`,e.CannotMoveTableHeader=`CannotMoveTableHeader`,e.MergeIsDestructive=`MergeIsDestructive`,e.CellIsMerged=`CellIsMerged`,e.InvalidTarget=`InvalidTarget`,e.EmptyUndoStack=`EmptyUndoStack`,e.EmptyRedoStack=`EmptyRedoStack`,e.NotEnoughElements=`NotEnoughElements`,e.NotEnoughSheets=`NotEnoughSheets`,e.MissingSheetName=`MissingSheetName`,e.UnchangedSheetName=`UnchangedSheetName`,e.DuplicatedSheetName=`DuplicatedSheetName`,e.DuplicatedSheetId=`DuplicatedSheetId`,e.ForbiddenCharactersInSheetName=`ForbiddenCharactersInSheetName`,e.WrongSheetMove=`WrongSheetMove`,e.WrongSheetPosition=`WrongSheetPosition`,e.InvalidAnchorZone=`InvalidAnchorZone`,e.SelectionOutOfBound=`SelectionOutOfBound`,e.TargetOutOfSheet=`TargetOutOfSheet`,e.WrongCutSelection=`WrongCutSelection`,e.WrongPasteSelection=`WrongPasteSelection`,e.WrongPasteOption=`WrongPasteOption`,e.WrongFigurePasteOption=`WrongFigurePasteOption`,e.EmptyClipboard=`EmptyClipboard`,e.EmptyRange=`EmptyRange`,e.InvalidRange=`InvalidRange`,e.InvalidZones=`InvalidZones`,e.InvalidSheetId=`InvalidSheetId`,e.InvalidCellId=`InvalidCellId`,e.InvalidFigureId=`InvalidFigureId`,e.InputAlreadyFocused=`InputAlreadyFocused`,e.MaximumRangesReached=`MaximumRangesReached`,e.MinimumRangesReached=`MinimumRangesReached`,e.InvalidChartDefinition=`InvalidChartDefinition`,e.InvalidDataSet=`InvalidDataSet`,e.InvalidLabelRange=`InvalidLabelRange`,e.InvalidScorecardKeyValue=`InvalidScorecardKeyValue`,e.InvalidScorecardBaseline=`InvalidScorecardBaseline`,e.InvalidGaugeDataRange=`InvalidGaugeDataRange`,e.EmptyGaugeRangeMin=`EmptyGaugeRangeMin`,e.GaugeRangeMinNaN=`GaugeRangeMinNaN`,e.EmptyGaugeRangeMax=`EmptyGaugeRangeMax`,e.GaugeRangeMaxNaN=`GaugeRangeMaxNaN`,e.GaugeLowerInflectionPointNaN=`GaugeLowerInflectionPointNaN`,e.GaugeUpperInflectionPointNaN=`GaugeUpperInflectionPointNaN`,e.InvalidAutofillSelection=`InvalidAutofillSelection`,e.MinBiggerThanMax=`MinBiggerThanMax`,e.LowerBiggerThanUpper=`LowerBiggerThanUpper`,e.MidBiggerThanMax=`MidBiggerThanMax`,e.MinBiggerThanMid=`MinBiggerThanMid`,e.FirstArgMissing=`FirstArgMissing`,e.SecondArgMissing=`SecondArgMissing`,e.MinNaN=`MinNaN`,e.MidNaN=`MidNaN`,e.MaxNaN=`MaxNaN`,e.ValueUpperInflectionNaN=`ValueUpperInflectionNaN`,e.ValueLowerInflectionNaN=`ValueLowerInflectionNaN`,e.MinInvalidFormula=`MinInvalidFormula`,e.MidInvalidFormula=`MidInvalidFormula`,e.MaxInvalidFormula=`MaxInvalidFormula`,e.ValueUpperInvalidFormula=`ValueUpperInvalidFormula`,e.ValueLowerInvalidFormula=`ValueLowerInvalidFormula`,e.InvalidSortAnchor=`InvalidSortAnchor`,e.InvalidSortZone=`InvalidSortZone`,e.SortZoneWithArrayFormulas=`SortZoneWithArrayFormulas`,e.WaitingSessionConfirmation=`WaitingSessionConfirmation`,e.MergeOverlap=`MergeOverlap`,e.TooManyHiddenElements=`TooManyHiddenElements`,e.Readonly=`Readonly`,e.InvalidViewportSize=`InvalidViewportSize`,e.InvalidScrollingDirection=`InvalidScrollingDirection`,e.ViewportScrollLimitsReached=`ViewportScrollLimitsReached`,e.FigureDoesNotExist=`FigureDoesNotExist`,e.InvalidConditionalFormatId=`InvalidConditionalFormatId`,e.InvalidConditionalFormatType=`InvalidConditionalFormatType`,e.InvalidCellPopover=`InvalidCellPopover`,e.EmptyTarget=`EmptyTarget`,e.InvalidFreezeQuantity=`InvalidFreezeQuantity`,e.FrozenPaneOverlap=`FrozenPaneOverlap`,e.ValuesNotChanged=`ValuesNotChanged`,e.InvalidFilterZone=`InvalidFilterZone`,e.TableNotFound=`TableNotFound`,e.TableOverlap=`TableOverlap`,e.InvalidTableConfig=`InvalidTableConfig`,e.InvalidTableStyle=`InvalidTableStyle`,e.FilterNotFound=`FilterNotFound`,e.MergeInTable=`MergeInTable`,e.NonContinuousTargets=`NonContinuousTargets`,e.DuplicatedFigureId=`DuplicatedFigureId`,e.InvalidSelectionStep=`InvalidSelectionStep`,e.DuplicatedChartId=`DuplicatedChartId`,e.ChartDoesNotExist=`ChartDoesNotExist`,e.InvalidHeaderIndex=`InvalidHeaderIndex`,e.InvalidQuantity=`InvalidQuantity`,e.MoreThanOneColumnSelected=`MoreThanOneColumnSelected`,e.EmptySplitSeparator=`EmptySplitSeparator`,e.SplitWillOverwriteContent=`SplitWillOverwriteContent`,e.NoSplitSeparatorInSelection=`NoSplitSeparatorInSelection`,e.NoActiveSheet=`NoActiveSheet`,e.InvalidLocale=`InvalidLocale`,e.MoreThanOneRangeSelected=`MoreThanOneRangeSelected`,e.NoColumnsProvided=`NoColumnsProvided`,e.ColumnsNotIncludedInZone=`ColumnsNotIncludedInZone`,e.DuplicatesColumnsSelected=`DuplicatesColumnsSelected`,e.InvalidHeaderGroupStartEnd=`InvalidHeaderGroupStartEnd`,e.HeaderGroupAlreadyExists=`HeaderGroupAlreadyExists`,e.UnknownHeaderGroup=`UnknownHeaderGroup`,e.UnknownDataValidationRule=`UnknownDataValidationRule`,e.UnknownDataValidationCriterionType=`UnknownDataValidationCriterionType`,e.InvalidDataValidationCriterionValue=`InvalidDataValidationCriterionValue`,e.InvalidNumberOfCriterionValues=`InvalidNumberOfCriterionValues`,e.InvalidCopyPasteSelection=`InvalidCopyPasteSelection`,e.NoChanges=`NoChanges`,e.InvalidInputId=`InvalidInputId`,e.SheetIsHidden=`SheetIsHidden`,e.InvalidTableResize=`InvalidTableResize`,e.PivotIdNotFound=`PivotIdNotFound`,e.PivotInError=`PivotInError`,e.EmptyName=`EmptyName`,e.ValueCellIsInvalidFormula=`ValueCellIsInvalidFormula`,e.InvalidDefinition=`InvalidDefinition`,e.InvalidColor=`InvalidColor`,e.InvalidPivotDataSet=`InvalidPivotDataSet`,e.InvalidPivotCustomField=`InvalidPivotCustomField`,e.MissingFigureArguments=`MissingFigureArguments`,e.InvalidCarouselItem=`InvalidCarouselItem`,e}({}),Mr=new Set([`containsText`,`notContainsText`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`beginsWithText`,`endsWithText`,`isNotEmpty`,`isEmpty`,`isNotEqual`,`isEqual`,`customFormula`]),Nr=new Set([`containsText`,`notContainsText`,`isEqualText`,`isEmail`,`isLink`,`dateIs`,`dateIsBefore`,`dateIsOnOrBefore`,`dateIsAfter`,`dateIsOnOrAfter`,`dateIsBetween`,`dateIsNotBetween`,`dateIsValid`,`isEqual`,`isNotEqual`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`isBoolean`,`isValueInList`,`isValueInRange`,`customFormula`]),Pr=[{name:`English (US)`,code:`en_US`,thousandsSeparator:`,`,decimalSeparator:`.`,weekStart:7,dateFormat:`m/d/yyyy`,timeFormat:`hh:mm:ss a`,formulaArgSeparator:`,`},{name:`French`,code:`fr_FR`,thousandsSeparator:` `,decimalSeparator:`,`,weekStart:1,dateFormat:`dd/mm/yyyy`,timeFormat:`hh:mm:ss`,formulaArgSeparator:`;`}],D=Pr[0],Fr=[`thin`,`medium`,`thick`,`dashed`,`dotted`];function Ir(e){return Array.isArray(e)&&Array.isArray(e[0])}let Lr={Background:0,Highlights:1,Clipboard:2,Chart:4,Autofill:5,Selection:6,Headers:100},Rr=Kt(()=>Object.keys(Lr).sort((e,t)=>Lr[e]-Lr[t]));function zr(e,t){if(Lr[e])throw Error(`Layer ${e} already exists`);Lr[e]=t}let Br=[`containsText`,`notContainsText`,`isEqualText`,`isEmpty`,`isNotEmpty`,`beginsWithText`,`endsWithText`],Vr=[`isEqual`,`isNotEqual`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`isEmpty`,`isNotEmpty`],Hr=[`dateIs`,`dateIsBefore`,`dateIsOnOrBefore`,`dateIsAfter`,`dateIsOnOrAfter`,`dateIsBetween`,`dateIsNotBetween`,`isEmpty`,`isNotEmpty`];function Ur(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}let Wr=new g;function Gr(e,t){return e=Ur(e),{url:e,label:t||e,isExternal:!0,isUrlEditable:!0}}Wr.add(`sheet_URL`,{match:e=>Et(e),createLink:(e,t)=>({label:t,url:e,isExternal:!1,isUrlEditable:!1}),urlRepresentation(e,t){let n=Ot(e);return t.tryGetSheetName(n)||E(`Invalid sheet`)},open(e,t){let n=Ot(e);t.model.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:t.model.getters.getActiveSheetId(),sheetIdTo:n}).isCancelledBecause(`SheetIsHidden`)&&t.notifyUser({type:`warning`,sticky:!1,text:E(`Cannot open the link because the linked sheet is hidden.`)})},sequence:0});let Kr={createLink:Gr,match:e=>St(e),open:e=>window.open(e,`_blank`),urlRepresentation:e=>e,sequence:0};function qr(e){return Wr.getAll().sort((e,t)=>e.sequence-t.sequence).find(t=>t.match(e))||Kr}function Jr(e,t){return qr(e.url).urlRepresentation(e.url,t)}function Yr(e,t,n){qr(e.url).open(e.url,t,n)}function Xr(e){if(typeof e==`string`){if(xt(e)){let{label:t,url:n}=wt(e);return qr(n).createLink(n,t)}else if(St(e))return Gr(e)}}var O=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 Zr=new O(1899,11,30),Qr=1440*60*1e3,$r=2e3,ei=O.now().getFullYear(),ti=O.now().getMonth(),ni=O.fromTimestamp(0).getTime()-Zr.getTime(),ri=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,ii=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,ai=Ut.join(``),oi=RegExp(`\/|-|${Ut.join(`|`)}`),si=RegExp(`^(\\d{1,4})[\/${ai}\-](\\d{1,4})([\/${ai}\-](\\d{1,4}))?$`),ci=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function li(e,t){switch(typeof e){case`number`:return e;case`string`:return ui(e,t)?fi(e,t)?.value:!e||isNaN(Number(e))?void 0:Number(e);default:return}}function ui(e,t){return fi(e,t)!==null}let di=new Map;function fi(e,t){return di.has(t)||di.set(t,new Map),di.get(t).has(e)||di.get(t).set(e,pi(e,t)),di.get(t).get(e)}function pi(e,t){e=e.trim();let n=null,r=e.match(ci);if(r){if(n=xi(r[0]),n===null)return null;e=e.replace(r[0],``).trim()}let i=null,a=mi(e,t);if(a){let t=a.dateString.match(oi)[0];if(i=gi(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 O(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 mi(e,t){let n=e.match(si);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=hi(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 hi(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 gi(e,t){let{year:n,month:r,day:i}=e,a=yi(r),o=bi(i),s=vi(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 O(s,a,o);if(u.getMonth()!==a||u.getDate()!==o)return null;let d=u.getTime()-Zr.getTime(),f=_i(e,t,c,l);return{value:Math.round(d/Qr),format:f,jsDate:u}}function _i(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(C).join(t);case`ymd`:return[i,a,o].filter(C).join(t);case`dmy`:return[o,a,i].filter(C).join(t)}}function vi(e){if(!e)return ei;let t=Number(e);switch(e.length){case 1:return $r+t;case 2:return $r+($r+t>ei+10?-100:0)+t;case 3:case 4:return t}return null}function yi(e){if(!e)return ti;let t=Number(e);return t>=1&&t<=12?t-1:null}function bi(e){if(!e)return 1;let t=Number(e);return t>=0&&t<=31?t:null}function xi(e){if(e=e.trim(),ci.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 O(1899,11,30,o,s,c);return{value:o/24+s/1440+c/86400,format:l,jsDate:u}}return null}function Si(e){let t=Math.trunc(e),n=O.fromTimestamp(t*Qr-ni),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 Ci(e){return Math.round(wi(e))}function wi(e){return(e.getTime()-Zr.getTime())/Qr}function Ti(e){return new O(e.getFullYear(),e.getMonth()+1,0).getDate()}function Ei(e){return Ti(e)===e.getDate()}function Di(e,t,n){let r=e.getFullYear(),i=e.getMonth(),a=e.getDate(),o=new O(r,i+t,1);return n&&a===Ti(e)||a>Ti(o)?o.setDate(Ti(o)):o.setDate(a),o}function Oi(e){let t=Math.trunc(e);return t%4==0&&t%100!=0||t%400==0}function ki(e,t,n){if(e===t)return 0;if(e>t){let n=t;t=e,e=n}let r=Si(e),i=Si(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===(Oi(l)?29:28)&&(a=30,c===1&&o===(Oi(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+=Oi(n)?366:365;n=t/e}else r?Oi(l)&&(n=366):(Oi(l)&&s<2&&(n=366),Oi(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 Ai(e,t){let n=(t.getFullYear()-e.getFullYear())*12+t.getMonth()-e.getMonth();return e.getDate()>t.getDate()?n-1:n}function ji(e,t){let n=e.getTime(),r=t.getTime();return Math.floor((r-n)/Qr)}function Mi(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 Ni(e,t){return ki(e,t,1)<1}function Pi(e,t){return Math.trunc(e)===Math.trunc(t)}function Fi(e,t,n){return t>n?Fi(e,n,t):(e=Math.trunc(e),t=Math.trunc(t),n=Math.trunc(n),e>=t&&e<=n)}function Ii(e,t){return Math.trunc(e)<Math.trunc(t)}function Li(e,t){return Math.trunc(e)<=Math.trunc(t)}function Ri(e,t){return Math.trunc(e)>Math.trunc(t)}function zi(e,t){return Math.trunc(e)>=Math.trunc(t)}let Bi=Kt(function(e){return e=ut(e),RegExp(`(?:^-?\\d+(?:${e}?\\d*(?:e(\\+|-)?\\d+)?)?|^-?${e}\\d+)(?!\\w|!)`)}),Vi=Kt(function(e){let t=ut(e.decimalSeparator),n=`(?:\\d+(?:${ut(e.thousandsSeparator||``)}\\d{3,})*(?:${t}\\d*)?)`,r=`(?:${t}\\d+)`,i=`(?:\\s*`+n+`|`+r+`)(?:e(?:\\+|-)?\\d+)?(?:\\s*%)?`,a=`(?:\\s*-)?`,o=`(?:\\s*[\\$€])?`,s=`^(?:(?:`+[a+o+i,a+i+o,o+a+i].join(`)|(?:`)+`))$`;return new RegExp(s,`i`)});function Hi(e,t){return e?Vi(t).test(e.trim()):!1}let Ui=Kt(function(e){return RegExp(`[\$€${ut(e.thousandsSeparator||``)}]`,`g`)});function Wi(e,t){e=e.replace(Ui(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 Gi(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 k={NotAvailable:`#N/A`,InvalidReference:`#REF`,BadExpression:`#BAD_EXPR`,CircularDependency:`#CYCLE`,UnknownFunction:`#NAME?`,DivisionByZero:`#DIV/0!`,SpilledBlocked:`#SPILL!`,GenericError:`#ERROR`,NullError:`#NULL!`},Ki=new Set(Object.values(k));var A=class{message;value;constructor(e=E(`Error`),t=k.GenericError){this.message=e,this.value=t,this.message=e.toString()}},qi=class extends A{constructor(e=E(`Invalid expression`)){super(e,k.BadExpression)}},Ji=class extends A{constructor(e=E(`Circular reference`)){super(e,k.CircularDependency)}},Yi=class extends A{constructor(e=E(`Invalid reference`)){super(e,k.InvalidReference)}},Xi=class extends A{constructor(e=E(`Data not available`)){super(e,k.NotAvailable)}},Zi=class extends A{constructor(e=E(`Unknown function`)){super(e,k.UnknownFunction)}},Qi=class extends A{errorOriginPosition;constructor(e=E(`Spill range is not empty`),t){super(e,k.SpilledBlocked),this.errorOriginPosition=t}},$i=class extends A{constructor(e=E(`Division by zero`)){super(e,k.DivisionByZero)}};let ea=[`number`,`string`,`boolean`,`undefined`];function ta(e){if(e!==void 0)return Ir(e)?e[0][0]?.format:e.format}function j(e){return typeof e==`string`&&Ki.has(e)}function na(e){return{value:k.NotAvailable,message:E(`Did not find value '%s' in [[FUNCTION_NAME]] evaluation.`,N(e))}}let ra=e=>E(`The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.`,e),ia=(e,t,n)=>E(`The function [[FUNCTION_NAME]] expects a number value between %s and %s inclusive, but receives %s.`,e.toString(),t.toString(),n.toString()),aa=(e,t)=>E(`The function [[FUNCTION_NAME]] has an argument with value '%s'. It should be one of: %s.`,t,e.map(e=>`'${e}'`).join(`, `));function M(e,t){let n=ma(e);switch(typeof n){case`number`:return n;case`boolean`:return+!!n;case`string`:if(Hi(n,t)||n===``)return Wi(n,t);let e=fi(n,t);if(e)return e.value;throw new A(ra(n));default:return 0}}function oa(e,t){try{return M(e,t)}catch{return}}function sa(e,t){return I(e).map(e=>e.map(e=>{if(typeof e.value!=`number`){let n=``;throw typeof e==`object`?n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got an empty value.`,t):typeof e==`string`?n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got a string.`,t):typeof e==`boolean`&&(n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got a boolean.`,t)),new A(n)}return e.value}))}function ca(e,t){let n=ma(e);if(n===``)throw new A(ra(n));return M(n,t)}function la(e,t){return Math.trunc(M(e,t))}function ua(e,t){return Math.trunc(ca(e,t))}function N(e){let t=ma(e);switch(typeof t){case`string`:return t;case`number`:return t.toString();case`boolean`:return t?`TRUE`:`FALSE`;default:return``}}let da=Kt(function(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``)}),fa=e=>E(`The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a boolean.`,e);function P(e){let t=ma(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 A(fa(t))}else return!1;case`number`:return!!t;default:return!1}}function pa(e){let t=ma(e);if(t===``)throw new A(fa(t));return P(t)}function F(e,t){return Si(M(ma(e),t))}function ma(e){if(typeof e==`object`&&e&&`value`in e){if(j(e.value))throw e;return e.value}if(j(e))throw new A(``,e);return e}function ha(e,t,n){for(let r of e)if(Ir(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 ga(e,t){ha(e,e=>{if(j(e.value))throw e;t(e)},e=>{if(j(e?.value))throw e;t(e)})}function _a(e,t,n){ha(e,e=>{if(typeof e?.value==`number`&&t(e),j(e?.value))throw e},e=>{t({value:ca(e,n),format:e?.format})})}function va(e,t,n,r,i=`rowFirst`){let a=r;for(let r of e)if(Ir(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][i]);else for(let i=0;i<e;i++)for(let e=0;e<n;e++)a=t(a,r[i][e])}else a=n(a,r);return a}function ya(e,t,n,r=`rowFirst`){return va(e,t,t,n,r)}function ba(e,t,n,r){return va(e,(e,n)=>{let r=n?.value;if(typeof r==`number`)return t(e,r);if(j(r))throw n;return e},(e,n)=>t(e,ca(n,r)),n)}function xa(e,t,n,r){return va(e,(e,n)=>{let i=n?.value;if(i!=null){if(typeof i==`number`)return t(e,i);if(typeof i==`boolean`)return t(e,M(i,r));if(j(i))throw n;return t(e,0)}return e},(e,n)=>t(e,M(n,r)),n)}function Sa(e,t,n){let r=Array(e);for(let i=0;i<e;i++){r[i]=Array(t);for(let e=0;e<t;e++)r[i][e]=n(i,e)}return r}function Ca(e,t){return e.length===0?[]:Sa(e.length,e[0].length,(n,r)=>t(e[n][r]))}function wa(e,t){let n=e.length,r=e[0]?.length??0;for(let i=0;i<n;i++)for(let n=0;n<r;n++)t(e[i][n])}function Ta(e){return e.length?Sa(e[0].length,e.length,(t,n)=>e[n][t]):[]}function Ea(e,t,n=void 0){let r=1,i=1,a=1/0,o=1/0,s;for(let e=0;e<t.length;e++){let c=t[e];if(Ir(c)&&(n===void 0||n[e])){let n=c.length,l=c[0].length;n!==1||l!==1?(s??=Array(t.length),n!==1&&l!==1?(s[e]=`matrix`,r=Math.max(r,n),i=Math.max(i,l),a=Math.min(a,n),o=Math.min(o,l)):n===1?l!==1&&(s[e]=`vertical`,i=Math.max(i,l),o=Math.min(o,l)):(s[e]=`horizontal`,r=Math.max(r,n),a=Math.min(a,n))):t[e]=c[0][0]}}if(r===1&&i===1)return e(...t);let c=(e,n)=>t.map((t,r)=>{switch(s?.[r]){case`matrix`:return t[e][n];case`horizontal`:return t[e][0];case`vertical`:return t[0][n];case void 0:return t}});return Sa(r,i,(t,n)=>{if(t>a-1||n>o-1)return new Xi(E(`Array arguments to [[FUNCTION_NAME]] are of different size.`));let r=e(...c(t,n));return Ir(r)?r[0][0]:r})}function Da(e,t,n){for(let r of e)if(Ir(r)){let e=r.length,n=r[0].length;for(let i=0;i<n;i++)for(let n=0;n<e;n++)if(!t(r[n][i]??void 0))return}else if(!n(r))return}function Oa(e,t){return Da(e,e=>{let n=e?.value;if(typeof n==`boolean`)return t(n);if(typeof n==`number`)return t(!!n);if(j(n))throw e;return!0},e=>e!==void 0&&e.value!==null?t(pa(e)):!0)}function ka(e,t){let n,r,i=e.substring(0,2);return i===`<=`||i===`>=`||i===`<>`?(n=i,r=e.substring(2)):(i=e.substring(0,1),i===`<`||i===`>`||i===`=`?(n=i,r=e.substring(1)):(n=`=`,r=e)),Hi(r,t)||ui(r,t)?r=M(r,t):(r===`TRUE`||r===`FALSE`)&&(r=P(r)),{operator:n,operand:r}}let Aa=Kt(function(e){if(e===`*`)return/.+/;let t=``,n=``;for(let r of e)r===`?`&&n!==`~`?t+=`.`:r===`*`&&n!==`~`?t+=`.*`:((r===`*`||r===`?`)&&(t=t.slice(0,-1)),[`^`,`.`,`[`,`]`,`$`,`(`,`)`,`*`,`+`,`?`,`|`,`{`,`}`,`\\`].includes(r)&&(t+=`\\`),t+=r),n=r;return RegExp(`^`+t+`$`,`i`)});function ja(e=``,t,n){let{operator:r,operand:i}=t;if(i===void 0||e===null||i===null)return!1;if(typeof i==`number`&&r===`=`)return typeof e==`string`&&(Hi(e,n)||ui(e,n))?M(e,n)===i:e===i;if(r===`<>`||r===`=`){let t;return t=typeof e==typeof i?e===``&&i===``?!0:typeof e==`string`&&typeof i==`string`?Aa(i).test(e):e===i:!1,r===`=`?t:!t}if(typeof e==typeof i)switch(r){case`<`:return e<i;case`>`:return e>i;case`<=`:return e<=i;case`>=`:return e>=i}return!1}function Ma(e,t,n,r=!1){let i=e.length;if(i%2==1)throw new A(E(`Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs.`));let a=I(e[0]),o=a.length,s=a[0].length,c=[];for(let t=0;t<i-1;t+=2){let i=I(e[t]);if(i.length!==o||i[0].length!==s)throw new A(E(`Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension`));let a=ka(N(e[t+1]),n);r&&typeof a.operand==`string`&&(a.operand+=`*`),c.push(a)}for(let r=0;r<o;r++)for(let a=0;a<s;a++){let o=!0;for(let t=0;t<i-1;t+=2){let i=I(e[t])[r][a].value,s=c[t/2];if(o=ja(i??void 0,s,n),!o)break}o&&t(r,a)}}function Na(e,t,n,r,i,a){if(t===void 0||t.value===null)return-1;if(j(t.value))throw t;let o=Ia(t.value),s=typeof o,c,l,u=0,d=i-1,f,p,m,h,g=r===`desc`?t=>Ia(a(e,i-t-1)):t=>Ia(a(e,t));for(;d-u>=0;){for(f=Math.floor((u+d)/2),p=f,m=g(p),h=typeof m;u<p&&s!==h;)p--,m=g(p),h=typeof m;if(h!==s||m==null){u=f+1;continue}n===`strict`&&m===o?(c=m,l=p):n===`nextSmaller`&&m<=o?(c==null||c<m||c===m&&l<p)&&(c=m,l=p):n===`nextGreater`&&m>=o&&(c===void 0||c>m||c===m&&l<p)&&(c=m,l=p),m>o||n===`strict`&&m===o?d=p-1:u=f+1}return l===void 0?-1:r===`desc`?i-l-1:l}function Pa(e,t,n,r,i,a,o=!1){if(t===void 0||t.value===null)return-1;if(j(t.value))throw t;let s=Ia(t.value),c=o?(e,t)=>Ia(i(e,r-t-1)):(e,t)=>Ia(i(e,t)),l=n!==`wildcard`||typeof s!=`string`||!(s.includes(`*`)||s.includes(`?`));if(a&&l){let t=o?`reverseSearch`:`forwardSearch`,i=a[t].get(e);if(i===void 0){i=new Map;for(let t=0;t<r;t++){let n=c(e,t)??null;i.has(n)||i.set(n,t)}a[t].set(e,i)}if(i.has(s)){let e=i.get(s);return o?r-e-1:e}if(n===`strict`||n===`wildcard`)return-1}let u=Fa(e,s,n,r,c);return o&&u!==-1?r-u-1:u}function Fa(e,t,n,r,i){let a=n=>i(e,n)===t;if(n===`wildcard`&&typeof t==`string`&&(t.includes(`*`)||t.includes(`?`))){let n=Aa(t);a=t=>{let r=i(e,t);return typeof r==`string`?n.test(r):!1}}let o,s=-1;n===`nextSmaller`&&(a=n=>{let r=i(e,n);return(!o&&La(t,r)>=0||La(t,r)>=0&&La(r,o)>0)&&(o=r,s=n),r===t}),n===`nextGreater`&&(a=n=>{let r=i(e,n);return(!o&&La(t,r)<=0||La(t,r)<=0&&La(r,o)<0)&&(o=r,s=n),r===t});for(let e=0;e<r;e++)if(a(e))return e;return s}function Ia(e){return typeof e==`string`?da(e):e}function La(e,t){let n=ea.indexOf(typeof e)-ea.indexOf(typeof t);return n===0&&(typeof e==`string`&&typeof t==`string`?n=e.localeCompare(t):typeof e==`number`&&typeof t==`number`?n=e-t:typeof e==`boolean`&&typeof t==`boolean`&&(n=Number(e)-Number(t))),n}function I(e){return e===void 0?[[]]:Ir(e)?e:[[e]]}function Ra(e,t){return ya(e,(e,n)=>(e.push(t(n)),e),[],`rowFirst`)}function za(e){if(e===void 0)return!1;let{value:t}=e;return!(t===null||t===``)}let Ba=E(`[[FUNCTION_NAME]] has no valid input data.`);function Va(e){return E(`[[FUNCTION_NAME]] expects the provided values of %(argName)s to be a non-empty matrix.`,{argName:e})}function Ha(e){let t=new tn(e),n=[],r=[];for(n.push(r);!t.isOver();){if(t.current===`;`){r=[],n.push(r),t.shift();continue}let e=Xa(t)||Ua(t)||Ga(t)||Ka(t)||Ja(t)||Ya(t)||Qa(t)||qa(t)||$a(t);if(!e)throw Error(`Unknown token at `+t.remaining());r.push(e)}return n}function Ua(e){let t;if(e.current===`"`?(e.shift(),t=`"`):e.currentStartsWith(`[$`)&&(e.advanceBy(2),t=`]`),!t)return null;let n=``;for(;e.current&&e.current!==t;)n+=e.shift();if(e.current===t)e.shift();else throw Error(`Unterminated string in format`);return{type:`STRING`,value:n}}let Wa=new Set(`$+-/():!^&~{}<>= `);function Ga(e){if(e.current===`\\`){e.shift();let t=e.shift();if(!t)throw Error(`Unexpected end of format string`);return{type:`CHAR`,value:t}}return Wa.has(e.current)?{type:`CHAR`,value:e.shift()}:null}function Ka(e){return e.current===`,`?(e.shift(),{type:`THOUSANDS_SEPARATOR`,value:`,`}):null}function qa(e){return e.current===`@`?(e.shift(),{type:`TEXT_PLACEHOLDER`,value:`@`}):null}function Ja(e){return e.current===`.`?(e.shift(),{type:`DECIMAL_POINT`,value:`.`}):null}function Ya(e){return e.current===`%`?(e.shift(),{type:`PERCENT`,value:`%`}):null}function Xa(e){if(e.current===`0`||e.current===`#`){let t=e.current;return e.shift(),{type:`DIGIT`,value:t}}return null}let Za=new Set(`dmqyhsa`);function Qa(e){if(!Za.has(e.current))return null;let t=e.current,n=``;for(;e.current===t;)n+=e.shift();return{type:`DATE_PART`,value:n}}function $a(e){if(e.current!==`*`)return null;e.shift();let t=e.shift();if(!t)throw Error(`Unexpected end of format string`);return{type:`REPEATED_CHAR`,value:t}}let eo={};function to(e){let t=eo[e];return t===void 0&&(t=no(e),eo[e]=t),t}function no(e){let t=Ha(e);for(let e of t){let t=e.filter(e=>e.type===`REPEATED_CHAR`);for(let e of t.slice(1))e.type=`CHAR`}let n=so(t[0])||oo(t[0])||co(t[0]);if(!n)throw Error(`Invalid first format part of: `+e);if(t.length>1&&n.type===`text`)throw Error(`The first format in a multi-part format must be a number format: `+e);let r=so(t[1])||oo(t[1]);if(t[1]?.length&&!r)throw Error(`Invalid second format part of: `+e);let i=so(t[2])||oo(t[2]);if(t[2]?.length&&!i)throw Error(`Invalid third format part of: `+e);let a=co(t[3]);if(t[3]?.length&&!a)throw Error(`Invalid fourth format part of: `+e);return{positive:n,negative:r,zero:i,text:a}}function ro(e){return e.every(e=>e.type===`DATE_PART`||e.type===`DECIMAL_POINT`||e.type===`THOUSANDS_SEPARATOR`||e.type===`STRING`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function io(e){return e.every(e=>e.type===`DIGIT`||e.type===`DECIMAL_POINT`||e.type===`THOUSANDS_SEPARATOR`||e.type===`PERCENT`||e.type===`STRING`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function ao(e){return e.every(e=>e.type===`STRING`||e.type===`TEXT_PLACEHOLDER`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function oo(e){if(!e||!io(e))return;let t=[],n,r=t,i=0,a=0,o=e.findLastIndex(e=>e.type===`DIGIT`),s=!1,c=0;for(let l=0;l<e.length;l++){let u=e[l];switch(u.type){case`DIGIT`:r===t?r.push(u):c<20&&(r.push(u),c++);break;case`DECIMAL_POINT`:if(r===t)n=[],r=n;else throw Error(`Multiple decimal points in a number format`);break;case`REPEATED_CHAR`:case`CHAR`:case`STRING`:r.push(u);break;case`PERCENT`:i++,r.push(u);break;case`THOUSANDS_SEPARATOR`:l-1===o?(a+=1,o++,r.push(u)):e[l+1]?.type===`DIGIT`&&e[l-1]?.type===`DIGIT`?(r===t&&(s=!0),r.push(u)):r.push({type:`CHAR`,value:`,`});break}}return{type:`number`,integerPart:t,decimalPart:n,percentSymbols:i,thousandsSeparator:s,magnitude:a}}function so(e){let t=e&&ro(e)?{type:`date`,tokens:e}:void 0;if(t){if(t.tokens.length&&t.tokens.every(e=>e.type===`DATE_PART`&&e.value===`a`))throw Error(`Invalid date format`);return{type:`date`,tokens:lo(t.tokens.map(e=>e.type===`THOUSANDS_SEPARATOR`||e.type===`DECIMAL_POINT`?{type:`CHAR`,value:e.value}:e))}}}function co(e){return e&&ao(e)?{type:`text`,tokens:e}:void 0}function lo(e){let t=e.filter(e=>e.type===`DATE_PART`);for(let e=0;e<t.length;e++)!t[e].value.startsWith(`m`)||t[e].value.length>2||(t[e-1]?.value.startsWith(`h`)||t[e+1]?.value.startsWith(`s`))&&(t[e].value=t[e].value.replaceAll(`m`,`M`));return e}function uo(e){return[fo(e.positive),fo(e.negative),fo(e.zero),fo(e.text)].filter(C).join(`;`)}function fo(e){if(!e)return;let t=``,n=e.type===`number`?po(e):e.tokens;for(let e of n)switch(e.type){case`STRING`:t+=`[$${e.value}]`;break;case`CHAR`:t+=mo(e.value)?`\\${e.value}`:e.value;break;case`REPEATED_CHAR`:t+=`*`+e.value;break;case`DATE_PART`:t+=e.value===`MM`?`mm`:e.value;break;default:t+=e.value}return t}function po(e){let t=[...e.integerPart];return e.decimalPart&&(t.push({type:`DECIMAL_POINT`,value:`.`}),t.push(...e.decimalPart)),t}function mo(e){return!Wa.has(e)}let ho=`REPEATED_CHAR_PLACEHOLDER_`,go={0:E(`January`),1:E(`February`),2:E(`March`),3:E(`April`),4:E(`May`),5:E(`June`),6:E(`July`),7:E(`August`),8:E(`September`),9:E(`October`),10:E(`November`),11:E(`December`)},_o={0:E(`Sunday`),1:E(`Monday`),2:E(`Tuesday`),3:E(`Wednesday`),4:E(`Thursday`),5:E(`Friday`),6:E(`Saturday`)};function vo(e,t,n,r=!1){return r?Wo({value:e,format:t},n):L(e,{format:t,locale:n})}function L(e,{format:t,locale:n,formatWidth:r}){switch(typeof e==`boolean`&&(e=e?`TRUE`:`FALSE`),typeof e){case`string`:{if(e.includes(`\\"`)&&(e=e.replaceAll(/\\"/g,`"`)),!t)return e;let n=to(t),i=n.text||n.positive;return!i||i.type!==`text`?e:yo(e,i,r)}case`number`:t||=Fo(e);let i=to(t);if(i.positive.type===`text`)return yo(e.toString(),i.positive,r);let a=i.positive;if(e<0&&i.negative?(a=i.negative,e=-e):e===0&&i.zero&&(a=i.zero),a.type===`date`)return bo(Mo(e,a),r);let o=e<0,s=bo(xo(Math.abs(e),a,n),r);return o?`-`+s:s;case`object`:return``}}function yo(e,t,n){let r=``;for(let n of t.tokens)switch(n.type){case`TEXT_PLACEHOLDER`:r+=e;break;case`CHAR`:case`STRING`:r+=n.value;break;case`REPEATED_CHAR`:r+=ho+n.value;break}return bo(r,n)}function bo(e,t){let n=e.indexOf(ho);if(n===-1)return e;let r=e.slice(0,n),i=e.slice(n+26+1),a=e[n+26];function o(){if(!t)return{timesToRepeat:0,padding:``};let e=t.measureText(r+i),n=t.measureText(a),o=t.availableWidth-e;if(o<=0)return{timesToRepeat:0,padding:``};let s=Math.floor(o/n),c=o-s*n,l=t.measureText(` `);return{timesToRepeat:s,padding:` `.repeat(Math.floor(c/l))}}let{timesToRepeat:s,padding:c}=o();return r+a.repeat(s)+c+i}function xo(e,t,n){if(e===1/0)return`∞`+(t.percentSymbols?`%`:``);let r=t.percentSymbols*2-t.magnitude*3;e*=10**r;let i=0;t.decimalPart!==void 0&&(i=t.decimalPart.filter(e=>e.type===`DIGIT`).length);let{integerDigits:a,decimalDigits:o}=To(Math.abs(e),i),s=So(a,t,t.thousandsSeparator?n.thousandsSeparator:void 0);return t.decimalPart!==void 0&&(s+=n.decimalSeparator+Co(o||``,t)),s}function So(e,t,n){let r=t.integerPart;r.some(e=>e.type===`DIGIT`)||(r=[...r,{type:`DIGIT`,value:`#`}]),e===`0`&&(e=``);let i=``,a=r.findIndex(e=>e.type===`DIGIT`),o=e.length-1;function s(t,r){if(r===`0`&&(t||=`0`),!t)return;let a=e.length-1-o;i=n&&a>0&&a%3==0?t+n+i:t+i}for(let t=r.length-1;t>=0;t--){let n=r[t];switch(n.type){case`DIGIT`:let r=e[o];if(s(r,n.value),o--,a===t)for(;o>=0;)s(e[o],`0`),o--;break;case`THOUSANDS_SEPARATOR`:break;case`REPEATED_CHAR`:i=ho+n.value+i;break;default:i=n.value+i;break}}return i}function Co(e,t){if(!t.decimalPart)return``;let n=``,r=0;for(let i of t.decimalPart)switch(i.type){case`DIGIT`:let t=i.value===`#`?e[r]||``:e[r]||`0`;n+=t,r++;break;case`THOUSANDS_SEPARATOR`:break;case`REPEATED_CHAR`:n+=ho+i.value;break;default:n+=i.value;break}return n}let wo=[];function To(e,t=20){let n=e.toString();if(n.includes(`e`))return ko(e,t);if(Number.isInteger(e))return{integerDigits:n,decimalDigits:void 0};let r=n.indexOf(`.`),i=n.substring(0,r),a=n.substring(r+1);if(t===0)return Number(a[0])>=5&&(i=(Number(i)+1).toString()),{integerDigits:i,decimalDigits:void 0};if(a.length>t){let{integerDigits:e,decimalDigits:n}=Oo(a,t);a=n,e!==`0`&&(i=(Number(i)+Number(e)).toString())}return{integerDigits:i,decimalDigits:Eo(a||``)}}function Eo(e){let t=e.length-1;for(;t>=0&&e[t]===`0`;)t--;return e.slice(0,t+1)||void 0}let Do=/^0+/;function Oo(e,t){let n=`0`,r=e,i=e.slice(0,t);if(Number(e[t])<5)return{integerDigits:n,decimalDigits:i};let a=i.match(Do)?.[0]||``,o=(Number(i)+1).toString(),s=i.slice(a.length),c=o.length>s.length;return c&&!a?(n=`1`,r=void 0):r=c?a.slice(0,-1)+o:a+o,{integerDigits:n,decimalDigits:r}}function ko(e,t=20){let n=wo[t];n||(n=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:t,useGrouping:!1}),wo[t]=n);let[r,i]=n.format(e).split(`.`);return{integerDigits:r,decimalDigits:i}}function Ao(e,t){let{integerDigits:n,decimalDigits:r}=To(e,20);return r?n+t+r:n}let jo=Kt(function(e){if(!e)return!1;try{return to(e).positive.type===`date`}catch{return!1}});function Mo(e,t){let n=Si(e);if(isNaN(n.getTime()))return e.toString();let r=t.tokens.some(e=>e.type===`DATE_PART`&&e.value===`a`),i=``;for(let e of t.tokens)switch(e.type){case`DATE_PART`:i+=No(n,e.value,r);break;case`REPEATED_CHAR`:i+=ho+e.value;break;default:i+=e.value;break}return i}function No(e,t,n){switch(t){case`d`:return e.getDate();case`dd`:return e.getDate().toString().padStart(2,`0`);case`ddd`:return _o[e.getDay()].slice(0,3);case`dddd`:return _o[e.getDay()].toString();case`m`:return e.getMonth()+1;case`mm`:return String(e.getMonth()+1).padStart(2,`0`);case`mmm`:return go[e.getMonth()].slice(0,3);case`mmmm`:return go[e.getMonth()].toString();case`mmmmm`:return go[e.getMonth()].slice(0,1);case`qq`:return E(`Q%(quarter)s`,{quarter:e.getQuarter()}).toString();case`qqqq`:return E(`Quarter %(quarter)s`,{quarter:e.getQuarter()}).toString();case`yy`:let r=String(e.getFullYear()).replace(`-`,``).padStart(2,`0`);return r.slice(r.length-2);case`yyyy`:return String(e.getFullYear()).replace(`-`,``).padStart(4,`0`);case`hhhh`:return Math.floor((e.getTime()-Zr.getTime())/(3600*1e3)).toString();case`hh`:let i=e.getHours();return n&&(i=i===0?12:i>12?i-12:i),i.toString().padStart(2,`0`);case`MM`:return e.getMinutes().toString().padStart(2,`0`);case`ss`:return e.getSeconds().toString().padStart(2,`0`);case`a`:return e.getHours()>=12?`PM`:`AM`;default:throw Error(`invalid date format token: ${t}`)}}let Po=Kt(function(e){return RegExp(`[0-9]+${ut(e.decimalSeparator)}[0-9]`)});function Fo(e){let{integerDigits:t,decimalDigits:n}=To(e);if(!n)return`0`;let r=t.replace(`-`,``).length;if(r+2>11)return`0`;let i=11-r-1;return{decimalDigits:n}=To(e,Math.min(i,n.length)),n?`0.`+`0`.repeat(n.length):`0`}function Io(e,t){if(ui(e,t))return fi(e,t).format}function Lo(e){let t=e.includes(`.`)?`0.00`:`0`,n=e.match(/[\$€]/);if(n){let r=e.match(/[\d]/),i=`[$`+n.values().next().value+`]`;return r.index<n.index?`#,##`+t+i:i+`#,##`+t}if(e.includes(`%`))return t+`%`}function Ro(e){let t=e.decimalPlaces??2,n=e.position??`before`,r=e.code??``,i=e.symbol??``,a=`#,##0`+(t?`.`+`0`.repeat(t):``),o=`${r} ${i}`.trim();return n===`after`&&r&&(o=` `+o),Vo(o,n,a)}function zo(e){let t=e.decimalPlaces??2,n=e.position??`before`,r=e.code??``,i=e.symbol??``,a=`#,##0`+(t?`.`+`0`.repeat(t):``),o=`${r} ${i}`.trim();return n===`after`&&r&&(o=` `+o),[Bo(o,n,` ${a} `),Bo(o,n,`(${a})`),Bo(o,n,` - `)].join(`;`)}function Bo(e,t,n){let r=`[$${e}]`;return t===`before`?r+`* `+n:n+`* `+r}function Vo(e,t,n){let r=`[$${e}]`;return t===`before`?r+n:n+r}function Ho(e){let t=to(e);return uo({positive:Uo(t.positive),negative:t.negative?Uo(t.negative):void 0,zero:t.zero?Uo(t.zero):void 0,text:t.text})}function Uo(e){if(e.type!==`number`||!e.decimalPart)return e;let t=e.decimalPart.filter(e=>e.type!==`DIGIT`);return{...e,decimalPart:void 0,integerPart:[...e.integerPart,...t]}}function Wo({value:e,format:t},n){let r=oa(e,n);if(r===void 0)return``;let i=t;if(Math.abs(r)<1e3){let e=r%1!=0;i=!t&&e?`0.####`:t}else i=Go({value:e,format:t},void 0,n);return L(e,{format:i,locale:n})}function Go(e,t,n){let r=0;try{r=Math.abs(M(e?.value,n))}catch{return``}let i=e?.format;if(t!==void 0)switch(t?.value){case`k`:return Ko(i,1,`k`,n);case`m`:return Ko(i,2,`m`,n);case`b`:return Ko(i,3,`b`,n);default:throw new A(E(`The formatting unit should be 'k', 'm' or 'b'.`))}return r<1e5?Ko(i,0,``,n):r<1e8?Ko(i,1,`k`,n):r<1e11?Ko(i,2,`m`,n):Ko(i,3,`b`,n)}function Ko(e,t,n,r){let i=to(e||`#,##0`);return uo({positive:qo(i.positive,t,n),negative:i.negative?qo(i.negative,t,n):void 0,zero:i.zero?qo(i.zero,t,n):void 0,text:i.text})}function qo(e,t,n){if(e.type!==`number`)return e;let r=Uo(e),i={type:`STRING`,value:n},a=[...r.integerPart],o=a.findLastIndex(e=>e.type===`DIGIT`);if(o===-1)throw Error(`Cannot create a large number format from a format with no digit.`);for(;a[o+1]?.type===`THOUSANDS_SEPARATOR`;)a=qt(a,[o+1]);let s=a[o+1];a=s?.type===`STRING`&&[`m`,`k`,`b`].includes(s.value)?Yt(a,i,o+1):Jt(a,[i],o+1),t>0&&(a=Jt(a,Array(t).fill({type:`THOUSANDS_SEPARATOR`,value:`,`}),o+1));let c=r.percentSymbols-a.filter(e=>e.type===`PERCENT`).length;return a.push(...Array(c).fill({type:`PERCENT`,value:`%`})),{...r,integerPart:a,magnitude:t}}function Jo(e,t){let n=to(e);return uo(to(uo({positive:Yo(n.positive,t),negative:n.negative?Yo(n.negative,t):void 0,zero:n.zero?Yo(n.zero,t):void 0,text:n.text})))}function Yo(e,t){return e.type===`number`?t>0?Zo(e,t):Xo(e,Math.abs(t)):e}function Xo(e,t){let n=e.decimalPart;if(!n)return e;let r=[],i=0;for(let e=n.length-1;e>=0&&!(i>=Math.abs(t));e--)n[e].type===`DIGIT`&&(i++,r.push(e));return n=qt(n,r),n.some(e=>e.type===`DIGIT`)?{...e,decimalPart:n}:{...e,decimalPart:void 0,integerPart:[...e.integerPart,...n]}}function Zo(e,t){let n=e.integerPart,r=e.decimalPart;if(!r){let e=n.findLastIndex(e=>e.type===`DIGIT`);r=n.slice(e+1),n=n.slice(0,e+1)}let i=S(0,t).map(()=>({type:`DIGIT`,value:`0`})),a=r.findLastIndex(e=>e.type===`DIGIT`);return r=a===-1?[...i,...r]:Jt(r,i,a+1),{...e,decimalPart:r,integerPart:n}}function Qo(e){let t=to(e);for(let e of[t.positive,t.negative,t.zero])if(e&&e.type===`date`&&e.tokens.some(e=>e.type===`DATE_PART`&&e.value.includes(`q`)))return!1;return!0}function $o(e){if(!e)return!1;try{return to(e).positive.type===`text`}catch{return!1}}function es(e,t,n){return ns({value:$o(t.format)&&e.parsedValue!==null?e.content:e.parsedValue,format:t.format,origin:n},t.locale)}function ts(e,t){if(e.startsWith(`=`))throw Error(`Cannot parse "${e}" because it's not a literal value. It's a formula`);if(e===``)return null;if(e.includes(`
|
|
4
|
+
`)}function Zt(e,t,n){return t>n?Zt(e,n,t):e>=t&&e<=n}function Qt(e,t){let n=ut(e),r=t.matchCase?``:`i`;return t.exactMatch&&(n=`^${n}$`),RegExp(n,r)}function $t(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 en(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 tn=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 nn(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 rn(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 an(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 on(e){return e.startsWith(`=`)||e.startsWith(`+`)}function sn(e){return{bold:e.bold,italic:e.italic,fontSize:e.fontSize,textColor:e.color,align:e.align}}let cn=/rgba?\(|\s+|\)/gi,ln=/^#([A-F\d]{2}){3,4}$/,un=[`#eb6d00`,`#0074d9`,`#ad8e00`,`#169ed4`,`#b10dc9`,`#00a82d`,`#00a3a3`,`#f012be`,`#3d9970`,`#111111`,`#62A300`,`#ff4136`,`#949494`,`#85144b`,`#001f3f`];function dn(e,t=1){let n=t===1?``:Math.round(t*255).toString(16).padStart(2,`0`);return pn(e.toString(16).padStart(6,`0`))+n}function fn(e){return typeof e==`number`?e:Number.parseInt(pn(e).slice(1,7),16)}function pn(e){let t=e;if(e.startsWith(`rgb`)?t=yn(e):(t=e.replace(`#`,``).toUpperCase(),(t.length===3||t.length===4)&&(t=t.split(``).reduce((e,t)=>e+t+t,``)),t=`#${t}`),!ln.test(t))throw Error(`invalid color input: ${e}`);return t}function mn(e){try{return pn(e),!0}catch{return!1}}function hn(e){try{return wn(e),!0}catch{return!1}}let gn=e=>e>=0&&e<=255;function _n(e,t,n,r=1){if(!gn(e)||!gn(t)||!gn(n)||r<0||r>1)throw Error(`Invalid RGBA values ${[e,t,n,r]}`);return{a:r,b:n,g:t,r:e}}function vn(e){let{r:t,g:n,b:r}=xn(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 yn(e){let t=e.replace(cn,``).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),`#`+Mt(r.map(e=>e.toString(16).padStart(2,`0`))).toUpperCase()}function bn(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 xn(e){e=pn(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 Sn(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 Cn(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 wn(e){return bn(Sn(e))}function Tn(e){return Cn(xn(e))}function En(e,t){let n=xn(t),r=xn(e),i=n.a+r.a*(1-n.a);return bn({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 Dn(e){return xn(typeof e==`number`?dn(e):e)}function On(e,t,n=0){if(!(mn(e)&&mn(t)))return!1;let r=xn(e),i=xn(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 kn(e,t){return t===1?pn(e).slice(0,7):bn({...xn(e),a:t})}function An(e,t){let n=Tn(e);return t===1?`#fff`:(n.l=t*(100-n.l)+n.l,wn(n))}function jn(e,t){let n=Tn(e);return t===1?`#000`:(n.s=Math.min(100,t*n.s+n.s),n.l-=t*n.l,wn(n))}function Mn(e){return vn(e)<.6?An(e,.9):jn(e,.75)}let Nn=[`#4EA7F2`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#FFD86D`],Pn=[`#4EA7F2`,`#3188E6`,`#43C5B1`,`#00A78D`,`#EA6175`,`#CE4257`,`#F4A261`,`#F48935`,`#8481DD`,`#5752D1`,`#FFD86D`,`#FFBC2C`],Fn=[`#4EA7F2`,`#3188E6`,`#056BD9`,`#A76DBC`,`#7F4295`,`#6D2387`,`#EA6175`,`#CE4257`,`#982738`,`#43C5B1`,`#00A78D`,`#0E8270`,`#F4A261`,`#F48935`,`#BE5D10`,`#8481DD`,`#5752D1`,`#3A3580`,`#A4A8B6`,`#7E8290`,`#545B70`,`#FFD86D`,`#FFBC2C`,`#C08A16`],In=`#4EA7F2.#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`.split(`.`),Ln=[`#4EA7F2`,`#43C5B1`,`#EA6175`,`#F4A261`,`#8481DD`,`#FFD86D`,`#3188E6`,`#00A78D`,`#CE4257`,`#F48935`,`#5752D1`,`#FFBC2C`],Rn=[`#4EA7F2`,`#A76DBC`,`#EA6175`,`#43C5B1`,`#F4A261`,`#8481DD`,`#A4A8B6`,`#FFD86D`,`#3188E6`,`#7F4295`,`#CE4257`,`#00A78D`,`#F48935`,`#5752D1`,`#7E8290`,`#FFBC2C`,`#056BD9`,`#6D2387`,`#982738`,`#0E8270`,`#BE5D10`,`#3A3580`,`#545B70`,`#C08A16`],zn=`#4EA7F2.#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`.split(`.`);function Bn(e,t){return t[e%t.length]}function Vn(e){return e<=6?Nn:e<=12?Pn:e<=24?Fn:In}function Hn(e){return e<=6?Nn:e<=12?Ln:e<=24?Rn:zn}var Un=class{preferredColors;currentColorIndex=0;palette;constructor(e,t=[]){this.preferredColors=t,this.palette=Vn(e).filter(e=>!t.includes(e))}next(){return this.preferredColors?.[this.currentColorIndex]?this.preferredColors[this.currentColorIndex++]:Bn(this.currentColorIndex++,this.palette)}},Wn=class extends Un{constructor(e,t=[]){super(e,t),this.palette=Hn(e).filter(e=>!t.includes(e))}},Gn=class{availableColors;colors={};constructor(e=12){this.availableColors=new Wn(e)}get(e){return this.colors[e]||(this.colors[e]=this.availableColors.next()),this.colors[e]}};function Kn(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=Dn(t[e-1].color).a,i=Dn(t[e].color).a,a=fn(t[e-1].color),o=fn(t[e].color);n.push({min:t[e-1].value,max:t[e].value,minColor:a,maxColor:o,minColorAlpha:r,maxColorAlpha:i,colorDiff:qn(t[e-1].value,t[e].value,a,o)})}return e=>{if(e<n[0].min)return dn(n[0].minColor,n[0].minColorAlpha);for(let t of n)if(e>=t.min&&e<=t.max)return dn(Jn(e,t.min,t.minColor,t.colorDiff),t.maxColorAlpha);return dn(n[n.length-1].maxColor,n[n.length-1].maxColorAlpha)}}function qn(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 Jn(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}function Yn(e){if(e<0)throw Error(`number must be positive. Got ${e}`);return e<26?String.fromCharCode(65+e):Yn(Math.floor(e/26)-1)+Yn(e%26)}function Xn(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=Zn(e[r]);t=t*26+n}return t-1}function Zn(e){let t=e.charCodeAt(0);return t>=65&&t<=90?t-64:t-96}function Qn(e){return e>=`A`&&e<=`Z`||e>=`a`&&e<=`z`}function $n(e){return e>=`0`&&e<=`9`}let er=Xn(`ZZZ`);function tr(e){for(;e.current===` `;)e.advanceBy(1)}function nr(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!Qn(e.current))return-1;let t=0;for(;e.current&&Qn(e.current);)t=t*26+Zn(e.shift());return t}function rr(e){if(e.current===`$`&&e.advanceBy(1),!e.current||!$n(e.current))return-1;let t=0;for(;e.current&&$n(e.current);)t=t*10+Number(e.shift());return t}function ir(e){let t=new tn(e);tr(t);let n=nr(t);if(n===-1||!t.current)throw Error(`Invalid cell description: ${e}`);let r=rr(t);tr(t);let i=n-1,a=r-1;if(!t.isOver()||i>er||a>9999998)throw Error(`Invalid cell description: ${e}`);return{col:i,row:a}}function T(e,t,n={colFixed:!1,rowFixed:!1}){return(n.colFixed?`$`:``)+Yn(e)+(n.rowFixed?`$`:``)+String(t+1)}let ar=e=>e,or=()=>!1,sr=ar,cr=or;function lr(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 ur(e,t=()=>!0){sr=e,cr=t}function dr(){sr===ar&&cr===or&&(cr=()=>!0)}let E=function(e,...t){return cr()?lr(sr(e),...t):new fr(e,t)};var fr=class extends String{values;constructor(e,t){super(e),this.values=t}valueOf(){let e=super.valueOf();return cr()?lr(sr(e),...this.values):lr(e,...this.values)}toString(){return this.valueOf()}};function pr(e){return`sheetId`in e}function mr(e){return`dimension`in e&&`sheetId`in e&&`elements`in e}function hr(e){return`target`in e&&`sheetId`in e}function gr(e){return`ranges`in e}function _r(e){return`col`in e&&`row`in e&&`sheetId`in e}function vr(e){return`sheetId`in e&&`zone`in e}let yr=new Set([`RENAME_SHEET`,`DELETE_SHEET`,`CREATE_SHEET`,`DUPLICATE_SHEET`,`ADD_COLUMNS_ROWS`,`REMOVE_COLUMNS_ROWS`,`UNDO`,`REDO`,`ADD_MERGE`,`REMOVE_MERGE`,`UPDATE_LOCALE`,`ADD_PIVOT`,`UPDATE_PIVOT`,`INSERT_PIVOT`,`RENAME_PIVOT`,`REMOVE_PIVOT`,`DUPLICATE_PIVOT`]),br=new Set([`EVALUATE_CELLS`,`EVALUATE_CHARTS`,`UPDATE_CELL`,`UNHIDE_COLUMNS_ROWS`,`HIDE_COLUMNS_ROWS`,`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUP`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_ALL_HEADER_GROUPS`,`UNFOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`UPDATE_TABLE`,`UPDATE_FILTER`,`UNDO`,`REDO`]),xr=new Set([`MOVE_RANGES`]),Sr=new Set([`EVALUATE_CELLS`,`ADD_CONDITIONAL_FORMAT`,`REMOVE_CONDITIONAL_FORMAT`,`CHANGE_CONDITIONAL_FORMAT_PRIORITY`]),Cr=new Set([`AUTOFILL_CELL`,`SET_BORDER`,`SET_ZONE_BORDERS`,`SET_BORDERS_ON_TARGET`]),wr=new Set([`UNHIDE_COLUMNS_ROWS`,`HIDE_COLUMNS_ROWS`,`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUP`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_ALL_HEADER_GROUPS`,`UNFOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`UPDATE_TABLE`,`UPDATE_FILTER`]),Tr=new Set([`START`,`ACTIVATE_SHEET`,`COPY`,`RESIZE_SHEETVIEW`,`SET_VIEWPORT_OFFSET`,`EVALUATE_CELLS`,`EVALUATE_CHARTS`,`SET_FORMULA_VISIBILITY`,`UPDATE_FILTER`,`UPDATE_CHART`,`UPDATE_CAROUSEL_ACTIVE_ITEM`,`UPDATE_PIVOT`]),Er=new Set(`UPDATE_CELL.UPDATE_CELL_POSITION.CLEAR_CELL.CLEAR_CELLS.DELETE_CONTENT.ADD_COLUMNS_ROWS.REMOVE_COLUMNS_ROWS.RESIZE_COLUMNS_ROWS.HIDE_COLUMNS_ROWS.UNHIDE_COLUMNS_ROWS.SET_GRID_LINES_VISIBILITY.UNFREEZE_COLUMNS.UNFREEZE_ROWS.FREEZE_COLUMNS.FREEZE_ROWS.UNFREEZE_COLUMNS_ROWS.ADD_MERGE.REMOVE_MERGE.CREATE_SHEET.DELETE_SHEET.DUPLICATE_SHEET.MOVE_SHEET.RENAME_SHEET.COLOR_SHEET.HIDE_SHEET.SHOW_SHEET.MOVE_RANGES.ADD_CONDITIONAL_FORMAT.REMOVE_CONDITIONAL_FORMAT.CHANGE_CONDITIONAL_FORMAT_PRIORITY.CREATE_FIGURE.DELETE_FIGURE.UPDATE_FIGURE.CREATE_CAROUSEL.UPDATE_CAROUSEL.SET_FORMATTING.CLEAR_FORMATTING.SET_BORDER.SET_ZONE_BORDERS.SET_BORDERS_ON_TARGET.CREATE_CHART.UPDATE_CHART.DELETE_CHART.CREATE_TABLE.REMOVE_TABLE.UPDATE_TABLE.CREATE_TABLE_STYLE.REMOVE_TABLE_STYLE.CREATE_IMAGE.GROUP_HEADERS.UNGROUP_HEADERS.UNFOLD_HEADER_GROUP.FOLD_HEADER_GROUP.FOLD_ALL_HEADER_GROUPS.UNFOLD_ALL_HEADER_GROUPS.UNFOLD_HEADER_GROUPS_IN_ZONE.FOLD_HEADER_GROUPS_IN_ZONE.ADD_DATA_VALIDATION_RULE.REMOVE_DATA_VALIDATION_RULE.UPDATE_LOCALE.ADD_PIVOT.UPDATE_PIVOT.INSERT_PIVOT.RENAME_PIVOT.REMOVE_PIVOT.DUPLICATE_PIVOT`.split(`.`));function Dr(e){return Er.has(e.type)}function Or(e){return Tr.has(e.type)}var kr=class{reasons;constructor(e=[]){Array.isArray(e)||(e=[e]),e=[...new Set(e)],this.reasons=e.filter(e=>e!==`Success`)}static get Success(){return Ar}get isSuccessful(){return this.reasons.length===0}isCancelledBecause(e){return this.reasons.includes(e)}};let Ar=new kr,jr=function(e){return e.Success=`Success`,e.CancelledForUnknownReason=`CancelledForUnknownReason`,e.WillRemoveExistingMerge=`WillRemoveExistingMerge`,e.CannotMoveTableHeader=`CannotMoveTableHeader`,e.MergeIsDestructive=`MergeIsDestructive`,e.CellIsMerged=`CellIsMerged`,e.InvalidTarget=`InvalidTarget`,e.EmptyUndoStack=`EmptyUndoStack`,e.EmptyRedoStack=`EmptyRedoStack`,e.NotEnoughElements=`NotEnoughElements`,e.NotEnoughSheets=`NotEnoughSheets`,e.MissingSheetName=`MissingSheetName`,e.UnchangedSheetName=`UnchangedSheetName`,e.DuplicatedSheetName=`DuplicatedSheetName`,e.DuplicatedSheetId=`DuplicatedSheetId`,e.ForbiddenCharactersInSheetName=`ForbiddenCharactersInSheetName`,e.WrongSheetMove=`WrongSheetMove`,e.WrongSheetPosition=`WrongSheetPosition`,e.InvalidAnchorZone=`InvalidAnchorZone`,e.SelectionOutOfBound=`SelectionOutOfBound`,e.TargetOutOfSheet=`TargetOutOfSheet`,e.WrongCutSelection=`WrongCutSelection`,e.WrongPasteSelection=`WrongPasteSelection`,e.WrongPasteOption=`WrongPasteOption`,e.WrongFigurePasteOption=`WrongFigurePasteOption`,e.EmptyClipboard=`EmptyClipboard`,e.EmptyRange=`EmptyRange`,e.InvalidRange=`InvalidRange`,e.InvalidZones=`InvalidZones`,e.InvalidSheetId=`InvalidSheetId`,e.InvalidCellId=`InvalidCellId`,e.InvalidFigureId=`InvalidFigureId`,e.InputAlreadyFocused=`InputAlreadyFocused`,e.MaximumRangesReached=`MaximumRangesReached`,e.MinimumRangesReached=`MinimumRangesReached`,e.InvalidChartDefinition=`InvalidChartDefinition`,e.InvalidDataSet=`InvalidDataSet`,e.InvalidLabelRange=`InvalidLabelRange`,e.InvalidScorecardKeyValue=`InvalidScorecardKeyValue`,e.InvalidScorecardBaseline=`InvalidScorecardBaseline`,e.InvalidGaugeDataRange=`InvalidGaugeDataRange`,e.EmptyGaugeRangeMin=`EmptyGaugeRangeMin`,e.GaugeRangeMinNaN=`GaugeRangeMinNaN`,e.EmptyGaugeRangeMax=`EmptyGaugeRangeMax`,e.GaugeRangeMaxNaN=`GaugeRangeMaxNaN`,e.GaugeLowerInflectionPointNaN=`GaugeLowerInflectionPointNaN`,e.GaugeUpperInflectionPointNaN=`GaugeUpperInflectionPointNaN`,e.InvalidAutofillSelection=`InvalidAutofillSelection`,e.MinBiggerThanMax=`MinBiggerThanMax`,e.LowerBiggerThanUpper=`LowerBiggerThanUpper`,e.MidBiggerThanMax=`MidBiggerThanMax`,e.MinBiggerThanMid=`MinBiggerThanMid`,e.FirstArgMissing=`FirstArgMissing`,e.SecondArgMissing=`SecondArgMissing`,e.MinNaN=`MinNaN`,e.MidNaN=`MidNaN`,e.MaxNaN=`MaxNaN`,e.ValueUpperInflectionNaN=`ValueUpperInflectionNaN`,e.ValueLowerInflectionNaN=`ValueLowerInflectionNaN`,e.MinInvalidFormula=`MinInvalidFormula`,e.MidInvalidFormula=`MidInvalidFormula`,e.MaxInvalidFormula=`MaxInvalidFormula`,e.ValueUpperInvalidFormula=`ValueUpperInvalidFormula`,e.ValueLowerInvalidFormula=`ValueLowerInvalidFormula`,e.InvalidSortAnchor=`InvalidSortAnchor`,e.InvalidSortZone=`InvalidSortZone`,e.SortZoneWithArrayFormulas=`SortZoneWithArrayFormulas`,e.WaitingSessionConfirmation=`WaitingSessionConfirmation`,e.MergeOverlap=`MergeOverlap`,e.TooManyHiddenElements=`TooManyHiddenElements`,e.Readonly=`Readonly`,e.InvalidViewportSize=`InvalidViewportSize`,e.InvalidScrollingDirection=`InvalidScrollingDirection`,e.ViewportScrollLimitsReached=`ViewportScrollLimitsReached`,e.FigureDoesNotExist=`FigureDoesNotExist`,e.InvalidConditionalFormatId=`InvalidConditionalFormatId`,e.InvalidConditionalFormatType=`InvalidConditionalFormatType`,e.InvalidCellPopover=`InvalidCellPopover`,e.EmptyTarget=`EmptyTarget`,e.InvalidFreezeQuantity=`InvalidFreezeQuantity`,e.FrozenPaneOverlap=`FrozenPaneOverlap`,e.ValuesNotChanged=`ValuesNotChanged`,e.InvalidFilterZone=`InvalidFilterZone`,e.TableNotFound=`TableNotFound`,e.TableOverlap=`TableOverlap`,e.InvalidTableConfig=`InvalidTableConfig`,e.InvalidTableStyle=`InvalidTableStyle`,e.FilterNotFound=`FilterNotFound`,e.MergeInTable=`MergeInTable`,e.NonContinuousTargets=`NonContinuousTargets`,e.DuplicatedFigureId=`DuplicatedFigureId`,e.InvalidSelectionStep=`InvalidSelectionStep`,e.DuplicatedChartId=`DuplicatedChartId`,e.ChartDoesNotExist=`ChartDoesNotExist`,e.InvalidHeaderIndex=`InvalidHeaderIndex`,e.InvalidQuantity=`InvalidQuantity`,e.MoreThanOneColumnSelected=`MoreThanOneColumnSelected`,e.EmptySplitSeparator=`EmptySplitSeparator`,e.SplitWillOverwriteContent=`SplitWillOverwriteContent`,e.NoSplitSeparatorInSelection=`NoSplitSeparatorInSelection`,e.NoActiveSheet=`NoActiveSheet`,e.InvalidLocale=`InvalidLocale`,e.MoreThanOneRangeSelected=`MoreThanOneRangeSelected`,e.NoColumnsProvided=`NoColumnsProvided`,e.ColumnsNotIncludedInZone=`ColumnsNotIncludedInZone`,e.DuplicatesColumnsSelected=`DuplicatesColumnsSelected`,e.InvalidHeaderGroupStartEnd=`InvalidHeaderGroupStartEnd`,e.HeaderGroupAlreadyExists=`HeaderGroupAlreadyExists`,e.UnknownHeaderGroup=`UnknownHeaderGroup`,e.UnknownDataValidationRule=`UnknownDataValidationRule`,e.UnknownDataValidationCriterionType=`UnknownDataValidationCriterionType`,e.InvalidDataValidationCriterionValue=`InvalidDataValidationCriterionValue`,e.InvalidNumberOfCriterionValues=`InvalidNumberOfCriterionValues`,e.InvalidCopyPasteSelection=`InvalidCopyPasteSelection`,e.NoChanges=`NoChanges`,e.InvalidInputId=`InvalidInputId`,e.SheetIsHidden=`SheetIsHidden`,e.InvalidTableResize=`InvalidTableResize`,e.PivotIdNotFound=`PivotIdNotFound`,e.PivotInError=`PivotInError`,e.EmptyName=`EmptyName`,e.ValueCellIsInvalidFormula=`ValueCellIsInvalidFormula`,e.InvalidDefinition=`InvalidDefinition`,e.InvalidColor=`InvalidColor`,e.InvalidPivotDataSet=`InvalidPivotDataSet`,e.InvalidPivotCustomField=`InvalidPivotCustomField`,e.MissingFigureArguments=`MissingFigureArguments`,e.InvalidCarouselItem=`InvalidCarouselItem`,e}({}),Mr=new Set([`containsText`,`notContainsText`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`beginsWithText`,`endsWithText`,`isNotEmpty`,`isEmpty`,`isNotEqual`,`isEqual`,`customFormula`]),Nr=new Set([`containsText`,`notContainsText`,`isEqualText`,`isEmail`,`isLink`,`dateIs`,`dateIsBefore`,`dateIsOnOrBefore`,`dateIsAfter`,`dateIsOnOrAfter`,`dateIsBetween`,`dateIsNotBetween`,`dateIsValid`,`isEqual`,`isNotEqual`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`isBoolean`,`isValueInList`,`isValueInRange`,`customFormula`]),Pr=[{name:`English (US)`,code:`en_US`,thousandsSeparator:`,`,decimalSeparator:`.`,weekStart:7,dateFormat:`m/d/yyyy`,timeFormat:`hh:mm:ss a`,formulaArgSeparator:`,`},{name:`French`,code:`fr_FR`,thousandsSeparator:` `,decimalSeparator:`,`,weekStart:1,dateFormat:`dd/mm/yyyy`,timeFormat:`hh:mm:ss`,formulaArgSeparator:`;`}],D=Pr[0],Fr=[`thin`,`medium`,`thick`,`dashed`,`dotted`];function Ir(e){return Array.isArray(e)&&Array.isArray(e[0])}let Lr={Background:0,Highlights:1,Clipboard:2,Chart:4,Autofill:5,Selection:6,Headers:100},Rr=Kt(()=>Object.keys(Lr).sort((e,t)=>Lr[e]-Lr[t]));function zr(e,t){if(Lr[e])throw Error(`Layer ${e} already exists`);Lr[e]=t}let Br=[`containsText`,`notContainsText`,`isEqualText`,`isEmpty`,`isNotEmpty`,`beginsWithText`,`endsWithText`],Vr=[`isEqual`,`isNotEqual`,`isGreaterThan`,`isGreaterOrEqualTo`,`isLessThan`,`isLessOrEqualTo`,`isBetween`,`isNotBetween`,`isEmpty`,`isNotEmpty`],Hr=[`dateIs`,`dateIsBefore`,`dateIsOnOrBefore`,`dateIsAfter`,`dateIsOnOrAfter`,`dateIsBetween`,`dateIsNotBetween`,`isEmpty`,`isNotEmpty`];function Ur(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}let Wr=new g;function Gr(e,t){return e=Ur(e),{url:e,label:t||e,isExternal:!0,isUrlEditable:!0}}Wr.add(`sheet_URL`,{match:e=>Et(e),createLink:(e,t)=>({label:t,url:e,isExternal:!1,isUrlEditable:!1}),urlRepresentation(e,t){let n=Ot(e);return t.tryGetSheetName(n)||E(`Invalid sheet`)},open(e,t){let n=Ot(e);t.model.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:t.model.getters.getActiveSheetId(),sheetIdTo:n}).isCancelledBecause(`SheetIsHidden`)&&t.notifyUser({type:`warning`,sticky:!1,text:E(`Cannot open the link because the linked sheet is hidden.`)})},sequence:0});let Kr={createLink:Gr,match:e=>St(e),open:e=>window.open(e,`_blank`),urlRepresentation:e=>e,sequence:0};function qr(e){return Wr.getAll().sort((e,t)=>e.sequence-t.sequence).find(t=>t.match(e))||Kr}function Jr(e,t){return qr(e.url).urlRepresentation(e.url,t)}function Yr(e,t,n){qr(e.url).open(e.url,t,n)}function Xr(e){if(typeof e==`string`){if(xt(e)){let{label:t,url:n}=wt(e);return qr(n).createLink(n,t)}else if(St(e))return Gr(e)}}var O=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 Zr=new O(1899,11,30),Qr=1440*60*1e3,$r=2e3,ei=O.now().getFullYear(),ti=O.now().getMonth(),ni=O.fromTimestamp(0).getTime()-Zr.getTime(),ri=/^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/,ii=/^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/,ai=Ut.join(``),oi=RegExp(`\/|-|${Ut.join(`|`)}`),si=RegExp(`^(\\d{1,4})[\/${ai}\-](\\d{1,4})([\/${ai}\-](\\d{1,4}))?$`),ci=/((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;function li(e,t){switch(typeof e){case`number`:return e;case`string`:return ui(e,t)?fi(e,t)?.value:!e||isNaN(Number(e))?void 0:Number(e);default:return}}function ui(e,t){return fi(e,t)!==null}let di=new Map;function fi(e,t){return di.has(t)||di.set(t,new Map),di.get(t).has(e)||di.get(t).set(e,pi(e,t)),di.get(t).get(e)}function pi(e,t){e=e.trim();let n=null,r=e.match(ci);if(r){if(n=xi(r[0]),n===null)return null;e=e.replace(r[0],``).trim()}let i=null,a=mi(e,t);if(a){let t=a.dateString.match(oi)[0];if(i=gi(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 O(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 mi(e,t){let n=e.match(si);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=hi(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 hi(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 gi(e,t){let{year:n,month:r,day:i}=e,a=yi(r),o=bi(i),s=vi(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 O(s,a,o);if(u.getMonth()!==a||u.getDate()!==o)return null;let d=u.getTime()-Zr.getTime(),f=_i(e,t,c,l);return{value:Math.round(d/Qr),format:f,jsDate:u}}function _i(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(C).join(t);case`ymd`:return[i,a,o].filter(C).join(t);case`dmy`:return[o,a,i].filter(C).join(t)}}function vi(e){if(!e)return ei;let t=Number(e);switch(e.length){case 1:return $r+t;case 2:return $r+($r+t>ei+10?-100:0)+t;case 3:case 4:return t}return null}function yi(e){if(!e)return ti;let t=Number(e);return t>=1&&t<=12?t-1:null}function bi(e){if(!e)return 1;let t=Number(e);return t>=0&&t<=31?t:null}function xi(e){if(e=e.trim(),ci.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 O(1899,11,30,o,s,c);return{value:o/24+s/1440+c/86400,format:l,jsDate:u}}return null}function Si(e){let t=Math.trunc(e),n=O.fromTimestamp(t*Qr-ni),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 Ci(e){return Math.round(wi(e))}function wi(e){return(e.getTime()-Zr.getTime())/Qr}function Ti(e){return new O(e.getFullYear(),e.getMonth()+1,0).getDate()}function Ei(e){return Ti(e)===e.getDate()}function Di(e,t,n){let r=e.getFullYear(),i=e.getMonth(),a=e.getDate(),o=new O(r,i+t,1);return n&&a===Ti(e)||a>Ti(o)?o.setDate(Ti(o)):o.setDate(a),o}function Oi(e){let t=Math.trunc(e);return t%4==0&&t%100!=0||t%400==0}function ki(e,t,n){if(e===t)return 0;if(e>t){let n=t;t=e,e=n}let r=Si(e),i=Si(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===(Oi(l)?29:28)&&(a=30,c===1&&o===(Oi(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+=Oi(n)?366:365;n=t/e}else r?Oi(l)&&(n=366):(Oi(l)&&s<2&&(n=366),Oi(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 Ai(e,t){let n=(t.getFullYear()-e.getFullYear())*12+t.getMonth()-e.getMonth();return e.getDate()>t.getDate()?n-1:n}function ji(e,t){let n=e.getTime(),r=t.getTime();return Math.floor((r-n)/Qr)}function Mi(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 Ni(e,t){return ki(e,t,1)<1}function Pi(e,t){return Math.trunc(e)===Math.trunc(t)}function Fi(e,t,n){return t>n?Fi(e,n,t):(e=Math.trunc(e),t=Math.trunc(t),n=Math.trunc(n),e>=t&&e<=n)}function Ii(e,t){return Math.trunc(e)<Math.trunc(t)}function Li(e,t){return Math.trunc(e)<=Math.trunc(t)}function Ri(e,t){return Math.trunc(e)>Math.trunc(t)}function zi(e,t){return Math.trunc(e)>=Math.trunc(t)}let Bi=Kt(function(e){return e=ut(e),RegExp(`(?:^-?\\d+(?:${e}?\\d*(?:e(\\+|-)?\\d+)?)?|^-?${e}\\d+)(?!\\w|!)`)}),Vi=Kt(function(e){let t=ut(e.decimalSeparator),n=`(?:\\d+(?:${ut(e.thousandsSeparator||``)}\\d{3,})*(?:${t}\\d*)?)`,r=`(?:${t}\\d+)`,i=`(?:\\s*`+n+`|`+r+`)(?:e(?:\\+|-)?\\d+)?(?:\\s*%)?`,a=`(?:\\s*-)?`,o=`(?:\\s*[\\$€])?`,s=`^(?:(?:`+[a+o+i,a+i+o,o+a+i].join(`)|(?:`)+`))$`;return new RegExp(s,`i`)});function Hi(e,t){return e?Vi(t).test(e.trim()):!1}let Ui=Kt(function(e){return RegExp(`[\$€${ut(e.thousandsSeparator||``)}]`,`g`)});function Wi(e,t){e=e.replace(Ui(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 Gi(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 k={NotAvailable:`#N/A`,InvalidReference:`#REF`,BadExpression:`#BAD_EXPR`,CircularDependency:`#CYCLE`,UnknownFunction:`#NAME?`,DivisionByZero:`#DIV/0!`,SpilledBlocked:`#SPILL!`,GenericError:`#ERROR`,NullError:`#NULL!`},Ki=new Set(Object.values(k));var A=class{message;value;constructor(e=E(`Error`),t=k.GenericError){this.message=e,this.value=t,this.message=e.toString()}},qi=class extends A{constructor(e=E(`Invalid expression`)){super(e,k.BadExpression)}},Ji=class extends A{constructor(e=E(`Circular reference`)){super(e,k.CircularDependency)}},Yi=class extends A{constructor(e=E(`Invalid reference`)){super(e,k.InvalidReference)}},Xi=class extends A{constructor(e=E(`Data not available`)){super(e,k.NotAvailable)}},Zi=class extends A{constructor(e=E(`Unknown function`)){super(e,k.UnknownFunction)}},Qi=class extends A{errorOriginPosition;constructor(e=E(`Spill range is not empty`),t){super(e,k.SpilledBlocked),this.errorOriginPosition=t}},$i=class extends A{constructor(e=E(`Division by zero`)){super(e,k.DivisionByZero)}};let ea=[`number`,`string`,`boolean`,`undefined`];function ta(e){if(e!==void 0)return Ir(e)?e[0][0]?.format:e.format}function j(e){return typeof e==`string`&&Ki.has(e)}function na(e){return{value:k.NotAvailable,message:E(`Did not find value '%s' in [[FUNCTION_NAME]] evaluation.`,N(e))}}let ra=e=>E(`The function [[FUNCTION_NAME]] expects a number value, but '%s' is a string, and cannot be coerced to a number.`,e),ia=(e,t,n)=>E(`The function [[FUNCTION_NAME]] expects a number value between %s and %s inclusive, but receives %s.`,e.toString(),t.toString(),n.toString()),aa=(e,t)=>E(`The function [[FUNCTION_NAME]] has an argument with value '%s'. It should be one of: %s.`,t,e.map(e=>`'${e}'`).join(`, `));function M(e,t){let n=ma(e);switch(typeof n){case`number`:return n;case`boolean`:return+!!n;case`string`:if(Hi(n,t)||n===``)return Wi(n,t);let e=fi(n,t);if(e)return e.value;throw new A(ra(n));default:return 0}}function oa(e,t){try{return M(e,t)}catch{return}}function sa(e,t){return I(e).map(e=>e.map(e=>{if(typeof e.value!=`number`){let n=``;throw typeof e==`object`?n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got an empty value.`,t):typeof e==`string`?n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got a string.`,t):typeof e==`boolean`&&(n=E(`Function [[FUNCTION_NAME]] expects number values for %s, but got a boolean.`,t)),new A(n)}return e.value}))}function ca(e,t){let n=ma(e);if(n===``)throw new A(ra(n));return M(n,t)}function la(e,t){return Math.trunc(M(e,t))}function ua(e,t){return Math.trunc(ca(e,t))}function N(e){let t=ma(e);switch(typeof t){case`string`:return t;case`number`:return t.toString();case`boolean`:return t?`TRUE`:`FALSE`;default:return``}}let da=Kt(function(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``)}),fa=e=>E(`The function [[FUNCTION_NAME]] expects a boolean value, but '%s' is a text, and cannot be coerced to a boolean.`,e);function P(e){let t=ma(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 A(fa(t))}else return!1;case`number`:return!!t;default:return!1}}function pa(e){let t=ma(e);if(t===``)throw new A(fa(t));return P(t)}function F(e,t){return Si(M(ma(e),t))}function ma(e){if(typeof e==`object`&&e&&`value`in e){if(j(e.value))throw e;return e.value}if(j(e))throw new A(``,e);return e}function ha(e,t,n){for(let r of e)if(Ir(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 ga(e,t){ha(e,e=>{if(j(e.value))throw e;t(e)},e=>{if(j(e?.value))throw e;t(e)})}function _a(e,t,n){ha(e,e=>{if(typeof e?.value==`number`&&t(e),j(e?.value))throw e},e=>{t({value:ca(e,n),format:e?.format})})}function va(e,t,n,r,i=`rowFirst`){let a=r;for(let r of e)if(Ir(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][i]);else for(let i=0;i<e;i++)for(let e=0;e<n;e++)a=t(a,r[i][e])}else a=n(a,r);return a}function ya(e,t,n,r=`rowFirst`){return va(e,t,t,n,r)}function ba(e,t,n,r){return va(e,(e,n)=>{let r=n?.value;if(typeof r==`number`)return t(e,r);if(j(r))throw n;return e},(e,n)=>t(e,ca(n,r)),n)}function xa(e,t,n,r){return va(e,(e,n)=>{let i=n?.value;if(i!=null){if(typeof i==`number`)return t(e,i);if(typeof i==`boolean`)return t(e,M(i,r));if(j(i))throw n;return t(e,0)}return e},(e,n)=>t(e,M(n,r)),n)}function Sa(e,t,n){let r=Array(e);for(let i=0;i<e;i++){r[i]=Array(t);for(let e=0;e<t;e++)r[i][e]=n(i,e)}return r}function Ca(e,t){return e.length===0?[]:Sa(e.length,e[0].length,(n,r)=>t(e[n][r]))}function wa(e,t){let n=e.length,r=e[0]?.length??0;for(let i=0;i<n;i++)for(let n=0;n<r;n++)t(e[i][n])}function Ta(e){return e.length?Sa(e[0].length,e.length,(t,n)=>e[n][t]):[]}function Ea(e,t,n=void 0){let r=1,i=1,a=1/0,o=1/0,s;for(let e=0;e<t.length;e++){let c=t[e];if(Ir(c)&&(n===void 0||n[e])){let n=c.length,l=c[0].length;n!==1||l!==1?(s??=Array(t.length),n!==1&&l!==1?(s[e]=`matrix`,r=Math.max(r,n),i=Math.max(i,l),a=Math.min(a,n),o=Math.min(o,l)):n===1?l!==1&&(s[e]=`vertical`,i=Math.max(i,l),o=Math.min(o,l)):(s[e]=`horizontal`,r=Math.max(r,n),a=Math.min(a,n))):t[e]=c[0][0]}}if(r===1&&i===1)return e(...t);let c=(e,n)=>t.map((t,r)=>{switch(s?.[r]){case`matrix`:return t[e][n];case`horizontal`:return t[e][0];case`vertical`:return t[0][n];case void 0:return t}});return Sa(r,i,(t,n)=>{if(t>a-1||n>o-1)return new Xi(E(`Array arguments to [[FUNCTION_NAME]] are of different size.`));let r=e(...c(t,n));return Ir(r)?r[0][0]:r})}function Da(e,t,n){for(let r of e)if(Ir(r)){let e=r.length,n=r[0].length;for(let i=0;i<n;i++)for(let n=0;n<e;n++)if(!t(r[n][i]??void 0))return}else if(!n(r))return}function Oa(e,t){return Da(e,e=>{let n=e?.value;if(typeof n==`boolean`)return t(n);if(typeof n==`number`)return t(!!n);if(j(n))throw e;return!0},e=>e!==void 0&&e.value!==null?t(pa(e)):!0)}function ka(e,t){let n,r,i=e.substring(0,2);return i===`<=`||i===`>=`||i===`<>`?(n=i,r=e.substring(2)):(i=e.substring(0,1),i===`<`||i===`>`||i===`=`?(n=i,r=e.substring(1)):(n=`=`,r=e)),Hi(r,t)||ui(r,t)?r=M(r,t):(r===`TRUE`||r===`FALSE`)&&(r=P(r)),{operator:n,operand:r}}let Aa=Kt(function(e){if(e===`*`)return/.+/;let t=``,n=``;for(let r of e)r===`?`&&n!==`~`?t+=`.`:r===`*`&&n!==`~`?t+=`.*`:((r===`*`||r===`?`)&&(t=t.slice(0,-1)),[`^`,`.`,`[`,`]`,`$`,`(`,`)`,`*`,`+`,`?`,`|`,`{`,`}`,`\\`].includes(r)&&(t+=`\\`),t+=r),n=r;return RegExp(`^`+t+`$`,`i`)});function ja(e=``,t,n){let{operator:r,operand:i}=t;if(i===void 0||e===null||i===null)return!1;if(typeof i==`number`&&r===`=`)return typeof e==`string`&&(Hi(e,n)||ui(e,n))?M(e,n)===i:e===i;if(r===`<>`||r===`=`){let t;return t=typeof e==typeof i?e===``&&i===``?!0:typeof e==`string`&&typeof i==`string`?Aa(i).test(e):e===i:!1,r===`=`?t:!t}if(typeof e==typeof i)switch(r){case`<`:return e<i;case`>`:return e>i;case`<=`:return e<=i;case`>=`:return e>=i}return!1}function Ma(e,t,n,r=!1){let i=e.length;if(i%2==1)throw new A(E(`Function [[FUNCTION_NAME]] expects criteria_range and criterion to be in pairs.`));let a=I(e[0]),o=a.length,s=a[0].length,c=[];for(let t=0;t<i-1;t+=2){let i=I(e[t]);if(i.length!==o||i[0].length!==s)throw new A(E(`Function [[FUNCTION_NAME]] expects criteria_range to have the same dimension`));let a=ka(N(e[t+1]),n);r&&typeof a.operand==`string`&&(a.operand+=`*`),c.push(a)}for(let r=0;r<o;r++)for(let a=0;a<s;a++){let o=!0;for(let t=0;t<i-1;t+=2){let i=I(e[t])[r][a].value,s=c[t/2];if(o=ja(i??void 0,s,n),!o)break}o&&t(r,a)}}function Na(e,t,n,r,i,a){if(t===void 0||t.value===null)return-1;if(j(t.value))throw t;let o=Ia(t.value),s=typeof o,c,l,u=0,d=i-1,f,p,m,h,g=r===`desc`?t=>Ia(a(e,i-t-1)):t=>Ia(a(e,t));for(;d-u>=0;){for(f=Math.floor((u+d)/2),p=f,m=g(p),h=typeof m;u<p&&s!==h;)p--,m=g(p),h=typeof m;if(h!==s||m==null){u=f+1;continue}n===`strict`&&m===o?(c=m,l=p):n===`nextSmaller`&&m<=o?(c==null||c<m||c===m&&l<p)&&(c=m,l=p):n===`nextGreater`&&m>=o&&(c===void 0||c>m||c===m&&l<p)&&(c=m,l=p),m>o||n===`strict`&&m===o?d=p-1:u=f+1}return l===void 0?-1:r===`desc`?i-l-1:l}function Pa(e,t,n,r,i,a,o=!1){if(t===void 0||t.value===null)return-1;if(j(t.value))throw t;let s=Ia(t.value),c=o?(e,t)=>Ia(i(e,r-t-1)):(e,t)=>Ia(i(e,t)),l=n!==`wildcard`||typeof s!=`string`||!(s.includes(`*`)||s.includes(`?`));if(a&&l){let t=o?`reverseSearch`:`forwardSearch`,i=a[t].get(e);if(i===void 0){i=new Map;for(let t=0;t<r;t++){let n=c(e,t)??null;i.has(n)||i.set(n,t)}a[t].set(e,i)}if(i.has(s)){let e=i.get(s);return o?r-e-1:e}if(n===`strict`||n===`wildcard`)return-1}let u=Fa(e,s,n,r,c);return o&&u!==-1?r-u-1:u}function Fa(e,t,n,r,i){let a=n=>i(e,n)===t;if(n===`wildcard`&&typeof t==`string`&&(t.includes(`*`)||t.includes(`?`))){let n=Aa(t);a=t=>{let r=i(e,t);return typeof r==`string`?n.test(r):!1}}let o,s=-1;n===`nextSmaller`&&(a=n=>{let r=i(e,n);return(!o&&La(t,r)>=0||La(t,r)>=0&&La(r,o)>0)&&(o=r,s=n),r===t}),n===`nextGreater`&&(a=n=>{let r=i(e,n);return(!o&&La(t,r)<=0||La(t,r)<=0&&La(r,o)<0)&&(o=r,s=n),r===t});for(let e=0;e<r;e++)if(a(e))return e;return s}function Ia(e){return typeof e==`string`?da(e):e}function La(e,t){let n=ea.indexOf(typeof e)-ea.indexOf(typeof t);return n===0&&(typeof e==`string`&&typeof t==`string`?n=e.localeCompare(t):typeof e==`number`&&typeof t==`number`?n=e-t:typeof e==`boolean`&&typeof t==`boolean`&&(n=Number(e)-Number(t))),n}function I(e){return e===void 0?[[]]:Ir(e)?e:[[e]]}function Ra(e,t){return ya(e,(e,n)=>(e.push(t(n)),e),[],`rowFirst`)}function za(e){if(e===void 0)return!1;let{value:t}=e;return!(t===null||t===``)}let Ba=E(`[[FUNCTION_NAME]] has no valid input data.`);function Va(e){return E(`[[FUNCTION_NAME]] expects the provided values of %(argName)s to be a non-empty matrix.`,{argName:e})}function Ha(e){e=e.replace(/\s/g,` `);let t=new tn(e),n=[],r=[];for(n.push(r);!t.isOver();){if(t.current===`;`){r=[],n.push(r),t.shift();continue}let e=Xa(t)||Ua(t)||Ga(t)||Ka(t)||Ja(t)||Ya(t)||Qa(t)||qa(t)||$a(t);if(!e)throw Error(`Unknown token at `+t.remaining());r.push(e)}return n}function Ua(e){let t;if(e.current===`"`?(e.shift(),t=`"`):e.currentStartsWith(`[$`)&&(e.advanceBy(2),t=`]`),!t)return null;let n=``;for(;e.current&&e.current!==t;)n+=e.shift();if(e.current===t)e.shift();else throw Error(`Unterminated string in format`);return{type:`STRING`,value:n}}let Wa=new Set(`$+-/():!^&~{}<>= `);function Ga(e){if(e.current===`\\`){e.shift();let t=e.shift();if(!t)throw Error(`Unexpected end of format string`);return{type:`CHAR`,value:t}}return Wa.has(e.current)?{type:`CHAR`,value:e.shift()}:null}function Ka(e){return e.current===`,`?(e.shift(),{type:`THOUSANDS_SEPARATOR`,value:`,`}):null}function qa(e){return e.current===`@`?(e.shift(),{type:`TEXT_PLACEHOLDER`,value:`@`}):null}function Ja(e){return e.current===`.`?(e.shift(),{type:`DECIMAL_POINT`,value:`.`}):null}function Ya(e){return e.current===`%`?(e.shift(),{type:`PERCENT`,value:`%`}):null}function Xa(e){if(e.current===`0`||e.current===`#`){let t=e.current;return e.shift(),{type:`DIGIT`,value:t}}return null}let Za=new Set(`dmqyhsa`);function Qa(e){if(!Za.has(e.current))return null;let t=e.current,n=``;for(;e.current===t;)n+=e.shift();return{type:`DATE_PART`,value:n}}function $a(e){if(e.current!==`*`)return null;e.shift();let t=e.shift();if(!t)throw Error(`Unexpected end of format string`);return{type:`REPEATED_CHAR`,value:t}}let eo={};function to(e){let t=eo[e];return t===void 0&&(t=no(e),eo[e]=t),t}function no(e){let t=Ha(e);for(let e of t){let t=e.filter(e=>e.type===`REPEATED_CHAR`);for(let e of t.slice(1))e.type=`CHAR`}let n=so(t[0])||oo(t[0])||co(t[0]);if(!n)throw Error(`Invalid first format part of: `+e);if(t.length>1&&n.type===`text`)throw Error(`The first format in a multi-part format must be a number format: `+e);let r=so(t[1])||oo(t[1]);if(t[1]?.length&&!r)throw Error(`Invalid second format part of: `+e);let i=so(t[2])||oo(t[2]);if(t[2]?.length&&!i)throw Error(`Invalid third format part of: `+e);let a=co(t[3]);if(t[3]?.length&&!a)throw Error(`Invalid fourth format part of: `+e);return{positive:n,negative:r,zero:i,text:a}}function ro(e){return e.every(e=>e.type===`DATE_PART`||e.type===`DECIMAL_POINT`||e.type===`THOUSANDS_SEPARATOR`||e.type===`STRING`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function io(e){return e.every(e=>e.type===`DIGIT`||e.type===`DECIMAL_POINT`||e.type===`THOUSANDS_SEPARATOR`||e.type===`PERCENT`||e.type===`STRING`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function ao(e){return e.every(e=>e.type===`STRING`||e.type===`TEXT_PLACEHOLDER`||e.type===`CHAR`||e.type===`REPEATED_CHAR`)}function oo(e){if(!e||!io(e))return;let t=[],n,r=t,i=0,a=0,o=e.findLastIndex(e=>e.type===`DIGIT`),s=!1,c=0;for(let l=0;l<e.length;l++){let u=e[l];switch(u.type){case`DIGIT`:r===t?r.push(u):c<20&&(r.push(u),c++);break;case`DECIMAL_POINT`:if(r===t)n=[],r=n;else throw Error(`Multiple decimal points in a number format`);break;case`REPEATED_CHAR`:case`CHAR`:case`STRING`:r.push(u);break;case`PERCENT`:i++,r.push(u);break;case`THOUSANDS_SEPARATOR`:l-1===o?(a+=1,o++,r.push(u)):e[l+1]?.type===`DIGIT`&&e[l-1]?.type===`DIGIT`?(r===t&&(s=!0),r.push(u)):r.push({type:`CHAR`,value:`,`});break}}return{type:`number`,integerPart:t,decimalPart:n,percentSymbols:i,thousandsSeparator:s,magnitude:a}}function so(e){let t=e&&ro(e)?{type:`date`,tokens:e}:void 0;if(t){if(t.tokens.length&&t.tokens.every(e=>e.type===`DATE_PART`&&e.value===`a`))throw Error(`Invalid date format`);return{type:`date`,tokens:lo(t.tokens.map(e=>e.type===`THOUSANDS_SEPARATOR`||e.type===`DECIMAL_POINT`?{type:`CHAR`,value:e.value}:e))}}}function co(e){return e&&ao(e)?{type:`text`,tokens:e}:void 0}function lo(e){let t=e.filter(e=>e.type===`DATE_PART`);for(let e=0;e<t.length;e++)!t[e].value.startsWith(`m`)||t[e].value.length>2||(t[e-1]?.value.startsWith(`h`)||t[e+1]?.value.startsWith(`s`))&&(t[e].value=t[e].value.replaceAll(`m`,`M`));return e}function uo(e){return[fo(e.positive),fo(e.negative),fo(e.zero),fo(e.text)].filter(C).join(`;`)}function fo(e){if(!e)return;let t=``,n=e.type===`number`?po(e):e.tokens;for(let e of n)switch(e.type){case`STRING`:t+=`[$${e.value}]`;break;case`CHAR`:t+=mo(e.value)?`\\${e.value}`:e.value;break;case`REPEATED_CHAR`:t+=`*`+e.value;break;case`DATE_PART`:t+=e.value===`MM`?`mm`:e.value;break;default:t+=e.value}return t}function po(e){let t=[...e.integerPart];return e.decimalPart&&(t.push({type:`DECIMAL_POINT`,value:`.`}),t.push(...e.decimalPart)),t}function mo(e){return!Wa.has(e)}let ho=`REPEATED_CHAR_PLACEHOLDER_`,go={0:E(`January`),1:E(`February`),2:E(`March`),3:E(`April`),4:E(`May`),5:E(`June`),6:E(`July`),7:E(`August`),8:E(`September`),9:E(`October`),10:E(`November`),11:E(`December`)},_o={0:E(`Sunday`),1:E(`Monday`),2:E(`Tuesday`),3:E(`Wednesday`),4:E(`Thursday`),5:E(`Friday`),6:E(`Saturday`)};function vo(e,t,n,r=!1){return r?Wo({value:e,format:t},n):L(e,{format:t,locale:n})}function L(e,{format:t,locale:n,formatWidth:r}){switch(typeof e==`boolean`&&(e=e?`TRUE`:`FALSE`),typeof e){case`string`:{if(e.includes(`\\"`)&&(e=e.replaceAll(/\\"/g,`"`)),!t)return e;let n=to(t),i=n.text||n.positive;return!i||i.type!==`text`?e:yo(e,i,r)}case`number`:t||=Fo(e);let i=to(t);if(i.positive.type===`text`)return yo(e.toString(),i.positive,r);let a=i.positive;if(e<0&&i.negative?(a=i.negative,e=-e):e===0&&i.zero&&(a=i.zero),a.type===`date`)return bo(Mo(e,a),r);let o=e<0,s=bo(xo(Math.abs(e),a,n),r);return o?`-`+s:s;case`object`:return``}}function yo(e,t,n){let r=``;for(let n of t.tokens)switch(n.type){case`TEXT_PLACEHOLDER`:r+=e;break;case`CHAR`:case`STRING`:r+=n.value;break;case`REPEATED_CHAR`:r+=ho+n.value;break}return bo(r,n)}function bo(e,t){let n=e.indexOf(ho);if(n===-1)return e;let r=e.slice(0,n),i=e.slice(n+26+1),a=e[n+26];function o(){if(!t)return{timesToRepeat:0,padding:``};let e=t.measureText(r+i),n=t.measureText(a),o=t.availableWidth-e;if(o<=0)return{timesToRepeat:0,padding:``};let s=Math.floor(o/n),c=o-s*n,l=t.measureText(` `);return{timesToRepeat:s,padding:` `.repeat(Math.floor(c/l))}}let{timesToRepeat:s,padding:c}=o();return r+a.repeat(s)+c+i}function xo(e,t,n){if(e===1/0)return`∞`+(t.percentSymbols?`%`:``);let r=t.percentSymbols*2-t.magnitude*3;e*=10**r;let i=0;t.decimalPart!==void 0&&(i=t.decimalPart.filter(e=>e.type===`DIGIT`).length);let{integerDigits:a,decimalDigits:o}=To(Math.abs(e),i),s=So(a,t,t.thousandsSeparator?n.thousandsSeparator:void 0);return t.decimalPart!==void 0&&(s+=n.decimalSeparator+Co(o||``,t)),s}function So(e,t,n){let r=t.integerPart;r.some(e=>e.type===`DIGIT`)||(r=[...r,{type:`DIGIT`,value:`#`}]),e===`0`&&(e=``);let i=``,a=r.findIndex(e=>e.type===`DIGIT`),o=e.length-1;function s(t,r){if(r===`0`&&(t||=`0`),!t)return;let a=e.length-1-o;i=n&&a>0&&a%3==0?t+n+i:t+i}for(let t=r.length-1;t>=0;t--){let n=r[t];switch(n.type){case`DIGIT`:let r=e[o];if(s(r,n.value),o--,a===t)for(;o>=0;)s(e[o],`0`),o--;break;case`THOUSANDS_SEPARATOR`:break;case`REPEATED_CHAR`:i=ho+n.value+i;break;default:i=n.value+i;break}}return i}function Co(e,t){if(!t.decimalPart)return``;let n=``,r=0;for(let i of t.decimalPart)switch(i.type){case`DIGIT`:let t=i.value===`#`?e[r]||``:e[r]||`0`;n+=t,r++;break;case`THOUSANDS_SEPARATOR`:break;case`REPEATED_CHAR`:n+=ho+i.value;break;default:n+=i.value;break}return n}let wo=[];function To(e,t=20){let n=e.toString();if(n.includes(`e`))return ko(e,t);if(Number.isInteger(e))return{integerDigits:n,decimalDigits:void 0};let r=n.indexOf(`.`),i=n.substring(0,r),a=n.substring(r+1);if(t===0)return Number(a[0])>=5&&(i=(Number(i)+1).toString()),{integerDigits:i,decimalDigits:void 0};if(a.length>t){let{integerDigits:e,decimalDigits:n}=Oo(a,t);a=n,e!==`0`&&(i=(Number(i)+Number(e)).toString())}return{integerDigits:i,decimalDigits:Eo(a||``)}}function Eo(e){let t=e.length-1;for(;t>=0&&e[t]===`0`;)t--;return e.slice(0,t+1)||void 0}let Do=/^0+/;function Oo(e,t){let n=`0`,r=e,i=e.slice(0,t);if(Number(e[t])<5)return{integerDigits:n,decimalDigits:i};let a=i.match(Do)?.[0]||``,o=(Number(i)+1).toString(),s=i.slice(a.length),c=o.length>s.length;return c&&!a?(n=`1`,r=void 0):r=c?a.slice(0,-1)+o:a+o,{integerDigits:n,decimalDigits:r}}function ko(e,t=20){let n=wo[t];n||(n=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:t,useGrouping:!1}),wo[t]=n);let[r,i]=n.format(e).split(`.`);return{integerDigits:r,decimalDigits:i}}function Ao(e,t){let{integerDigits:n,decimalDigits:r}=To(e,20);return r?n+t+r:n}let jo=Kt(function(e){if(!e)return!1;try{return to(e).positive.type===`date`}catch{return!1}});function Mo(e,t){let n=Si(e);if(isNaN(n.getTime()))return e.toString();let r=t.tokens.some(e=>e.type===`DATE_PART`&&e.value===`a`),i=``;for(let e of t.tokens)switch(e.type){case`DATE_PART`:i+=No(n,e.value,r);break;case`REPEATED_CHAR`:i+=ho+e.value;break;default:i+=e.value;break}return i}function No(e,t,n){switch(t){case`d`:return e.getDate();case`dd`:return e.getDate().toString().padStart(2,`0`);case`ddd`:return _o[e.getDay()].slice(0,3);case`dddd`:return _o[e.getDay()].toString();case`m`:return e.getMonth()+1;case`mm`:return String(e.getMonth()+1).padStart(2,`0`);case`mmm`:return go[e.getMonth()].slice(0,3);case`mmmm`:return go[e.getMonth()].toString();case`mmmmm`:return go[e.getMonth()].slice(0,1);case`qq`:return E(`Q%(quarter)s`,{quarter:e.getQuarter()}).toString();case`qqqq`:return E(`Quarter %(quarter)s`,{quarter:e.getQuarter()}).toString();case`yy`:let r=String(e.getFullYear()).replace(`-`,``).padStart(2,`0`);return r.slice(r.length-2);case`yyyy`:return String(e.getFullYear()).replace(`-`,``).padStart(4,`0`);case`hhhh`:return Math.floor((e.getTime()-Zr.getTime())/(3600*1e3)).toString();case`hh`:let i=e.getHours();return n&&(i=i===0?12:i>12?i-12:i),i.toString().padStart(2,`0`);case`MM`:return e.getMinutes().toString().padStart(2,`0`);case`ss`:return e.getSeconds().toString().padStart(2,`0`);case`a`:return e.getHours()>=12?`PM`:`AM`;default:throw Error(`invalid date format token: ${t}`)}}let Po=Kt(function(e){return RegExp(`[0-9]+${ut(e.decimalSeparator)}[0-9]`)});function Fo(e){let{integerDigits:t,decimalDigits:n}=To(e);if(!n)return`0`;let r=t.replace(`-`,``).length;if(r+2>11)return`0`;let i=11-r-1;return{decimalDigits:n}=To(e,Math.min(i,n.length)),n?`0.`+`0`.repeat(n.length):`0`}function Io(e,t){if(ui(e,t))return fi(e,t).format}function Lo(e){let t=e.includes(`.`)?`0.00`:`0`,n=e.match(/[\$€]/);if(n){let r=e.match(/[\d]/),i=`[$`+n.values().next().value+`]`;return r.index<n.index?`#,##`+t+i:i+`#,##`+t}if(e.includes(`%`))return t+`%`}function Ro(e){let t=e.decimalPlaces??2,n=e.position??`before`,r=e.code??``,i=e.symbol??``,a=`#,##0`+(t?`.`+`0`.repeat(t):``),o=`${r} ${i}`.trim();return n===`after`&&r&&(o=` `+o),Vo(o,n,a)}function zo(e){let t=e.decimalPlaces??2,n=e.position??`before`,r=e.code??``,i=e.symbol??``,a=`#,##0`+(t?`.`+`0`.repeat(t):``),o=`${r} ${i}`.trim();return n===`after`&&r&&(o=` `+o),[Bo(o,n,` ${a} `),Bo(o,n,`(${a})`),Bo(o,n,` - `)].join(`;`)}function Bo(e,t,n){let r=`[$${e}]`;return t===`before`?r+`* `+n:n+`* `+r}function Vo(e,t,n){let r=`[$${e}]`;return t===`before`?r+n:n+r}function Ho(e){let t=to(e);return uo({positive:Uo(t.positive),negative:t.negative?Uo(t.negative):void 0,zero:t.zero?Uo(t.zero):void 0,text:t.text})}function Uo(e){if(e.type!==`number`||!e.decimalPart)return e;let t=e.decimalPart.filter(e=>e.type!==`DIGIT`);return{...e,decimalPart:void 0,integerPart:[...e.integerPart,...t]}}function Wo({value:e,format:t},n){let r=oa(e,n);if(r===void 0)return``;let i=t;if(Math.abs(r)<1e3){let e=r%1!=0;i=!t&&e?`0.####`:t}else i=Go({value:e,format:t},void 0,n);return L(e,{format:i,locale:n})}function Go(e,t,n){let r=0;try{r=Math.abs(M(e?.value,n))}catch{return``}let i=e?.format;if(t!==void 0)switch(t?.value){case`k`:return Ko(i,1,`k`,n);case`m`:return Ko(i,2,`m`,n);case`b`:return Ko(i,3,`b`,n);default:throw new A(E(`The formatting unit should be 'k', 'm' or 'b'.`))}return r<1e5?Ko(i,0,``,n):r<1e8?Ko(i,1,`k`,n):r<1e11?Ko(i,2,`m`,n):Ko(i,3,`b`,n)}function Ko(e,t,n,r){let i=to(e||`#,##0`);return uo({positive:qo(i.positive,t,n),negative:i.negative?qo(i.negative,t,n):void 0,zero:i.zero?qo(i.zero,t,n):void 0,text:i.text})}function qo(e,t,n){if(e.type!==`number`)return e;let r=Uo(e),i={type:`STRING`,value:n},a=[...r.integerPart],o=a.findLastIndex(e=>e.type===`DIGIT`);if(o===-1)throw Error(`Cannot create a large number format from a format with no digit.`);for(;a[o+1]?.type===`THOUSANDS_SEPARATOR`;)a=qt(a,[o+1]);let s=a[o+1];a=s?.type===`STRING`&&[`m`,`k`,`b`].includes(s.value)?Yt(a,i,o+1):Jt(a,[i],o+1),t>0&&(a=Jt(a,Array(t).fill({type:`THOUSANDS_SEPARATOR`,value:`,`}),o+1));let c=r.percentSymbols-a.filter(e=>e.type===`PERCENT`).length;return a.push(...Array(c).fill({type:`PERCENT`,value:`%`})),{...r,integerPart:a,magnitude:t}}function Jo(e,t){let n=to(e);return uo(to(uo({positive:Yo(n.positive,t),negative:n.negative?Yo(n.negative,t):void 0,zero:n.zero?Yo(n.zero,t):void 0,text:n.text})))}function Yo(e,t){return e.type===`number`?t>0?Zo(e,t):Xo(e,Math.abs(t)):e}function Xo(e,t){let n=e.decimalPart;if(!n)return e;let r=[],i=0;for(let e=n.length-1;e>=0&&!(i>=Math.abs(t));e--)n[e].type===`DIGIT`&&(i++,r.push(e));return n=qt(n,r),n.some(e=>e.type===`DIGIT`)?{...e,decimalPart:n}:{...e,decimalPart:void 0,integerPart:[...e.integerPart,...n]}}function Zo(e,t){let n=e.integerPart,r=e.decimalPart;if(!r){let e=n.findLastIndex(e=>e.type===`DIGIT`);r=n.slice(e+1),n=n.slice(0,e+1)}let i=S(0,t).map(()=>({type:`DIGIT`,value:`0`})),a=r.findLastIndex(e=>e.type===`DIGIT`);return r=a===-1?[...i,...r]:Jt(r,i,a+1),{...e,decimalPart:r,integerPart:n}}function Qo(e){let t=to(e);for(let e of[t.positive,t.negative,t.zero])if(e&&e.type===`date`&&e.tokens.some(e=>e.type===`DATE_PART`&&e.value.includes(`q`)))return!1;return!0}function $o(e){if(!e)return!1;try{return to(e).positive.type===`text`}catch{return!1}}function es(e,t,n){return ns({value:$o(t.format)&&e.parsedValue!==null?e.content:e.parsedValue,format:t.format,origin:n},t.locale)}function ts(e,t){if(e.startsWith(`=`))throw Error(`Cannot parse "${e}" because it's not a literal value. It's a formula`);if(e===``)return null;if(e.includes(`
|
|
5
5
|
`))return e;if(Hi(e,D))return Wi(e,D);let n=fi(e,t);return n?n.value:vt(e)?e.toUpperCase()===`TRUE`:e}function ns(e,t=D,n,r){let i=Xr(e.value);if(!i)return us(rs(e,t,n),e.origin??r);let a=ts(i.label,t);return us({...rs({value:a,format:e.format||(typeof a==`number`?Io(i.label,t)||Lo(i.label):void 0)},t,n),link:i},e.origin??r)}function rs(e,t,n){let{value:r,format:i,message:a,errorOriginPosition:o}=e;i=n?.format||i;let s=L(r,{format:i,locale:t});return j(r)?ls(r,a,o):r===null?os(i):$o(i)?is(N(r),i,s):typeof r==`number`?jo(i||``)?ss(r,i,s):as(r,i,s):typeof r==`boolean`?cs(r,i,s):is(r,i,s)}function is(e,t,n){return{value:e,format:t,formattedValue:n,type:`text`,isAutoSummable:!0,defaultAlign:`left`}}function as(e,t,n){return{value:e||0,format:t,formattedValue:n,type:`number`,isAutoSummable:!0,defaultAlign:`right`}}let os=Kt(function(e){return{value:null,format:e,formattedValue:``,type:`empty`,isAutoSummable:!0,defaultAlign:`left`}});function ss(e,t,n){return{value:e,format:t,formattedValue:n,type:`number`,isAutoSummable:!1,defaultAlign:`right`}}function cs(e,t,n){return{value:e,format:t,formattedValue:n,type:`boolean`,isAutoSummable:!1,defaultAlign:`center`}}function ls(e,t,n){return{value:e,formattedValue:e,message:t,type:`error`,isAutoSummable:!1,defaultAlign:`center`,errorOriginPosition:n}}function us(e,t){return e.value===null||`origin`in e||(e.origin=t),e}function ds(e){let t=O.now();switch(e){case`today`:return Math.floor(wi(t));case`yesterday`:return t.setDate(t.getDate()-1),Math.floor(wi(t));case`tomorrow`:return t.setDate(t.getDate()+1),Math.floor(wi(t));case`lastWeek`:return t.setDate(t.getDate()-6),Math.floor(wi(t));case`lastMonth`:{let e=t.getMonth()===0?11:t.getMonth()-1,n=new O(t.getFullYear(),e,1);return t.getDate()>Ti(n)?t.setDate(1):(t.setDate(t.getDate()+1),t.setMonth(t.getMonth()-1)),Math.floor(wi(t))}case`lastYear`:return t.getMonth()===1&&t.getDate()===29?(t.setDate(28),t.setFullYear(t.getFullYear()-1)):(t.setDate(t.getDate()+1),t.setFullYear(t.getFullYear()-1)),Math.floor(wi(t))}}function fs(e,t){return`dateValue`in e&&e.dateValue!==`exactDate`?[ds(e.dateValue)]:e.values.map(e=>li(e,t))}function ps(e,t){return e.map(e=>{if(e.startsWith(`=`))return e;let n=ts(e,t);return typeof n==`number`?L(n,{format:t.dateFormat,locale:t}):``})}function ms(e,t=[]){if(e.length<=1&&t.length===0)return e;let n=[0],r=new Map([[0,[]]]);return hs(n,r,e,!1),hs(n,r,t,!0),bs(n,r)}function hs(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=_s(e,t,n,!0,0),s=_s(e,t,a,!1,o);for(let n=o;n<=s;n++)vs(t.get(e[n]),i,r);ys(e,t,o,s)}}function gs(e,t,n){let r=n.left,i=n.right,a=xs(e,r,0),o=i===void 0?e.length-1:xs(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=xs(r,s,0);if(i===-1||i%2!=0)return!1;let a=c===void 0?r.length:Ss(r,c,0);if(i+1!==a)return!1}return!0}function _s(e,t,n,r,i){if(n===void 0)return e.length-1;let a=xs(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 vs(e,t,n=!1){let r=t.top,i=t.bottom===void 0?void 0:t.bottom+1,a=[],o=xs(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=Ss(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 ys(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--)Lt(t.get(e[n]),t.get(e[n-1]))&&(t.delete(e[n]),e.splice(n,1))}function bs(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 xs(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 Ss(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 Cs(e){let t=new tn(e);tr(t);let n=e.indexOf(`!`);n!==-1&&t.advanceBy(n+1);let r=nr(t),i=rr(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),tr(t),t.current===`:`){t.advanceBy(1),tr(t);let e=nr(t),n=rr(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 ws(e){let t=Js(Cs(e)),n=t.bottom,r=t.right;if(n!==void 0&&n>9999998||r!==void 0&&r>er)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 Ts(e){let t=ws(e);if(t.bottom===void 0||t.right===void 0)throw Error(`This does not support unbounded ranges`);return t}function Es(e){return Os(ws(e))}function Ds(e){try{return Es(e)}catch{return!1}}function Os(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:ks(e)&&e.top>=0&&e.left>=0}function ks(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 As(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?`${Yn(r)}:${Yn(i)}`:`${T(r,t)}:${Yn(i)}`;if(i===void 0&&n!==void 0)return r===0&&!a?`${t+1}:${n+1}`:`${T(r,t)}:${n+1}`;if(n!==void 0&&i!==void 0)return o?T(r,t):`${T(r,t)}:${T(i,n)}`;throw Error(`Bad zone format`)}function js(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?Ys(e,a,`RESIZE`,i):o<e[t]?Ys(e,a,`MOVE`,i):{...e}}function Ms(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?Ys(e,a,`RESIZE`,i):o<e[t]?Ys(e,a,`MOVE`,i):{...e}}function Ns(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 Ps(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 Fs(...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 Is(...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 Ls(e,t){if(zs(e,t))return{top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),bottom:Math.min(e.bottom,t.bottom),right:Math.min(e.right,t.right)}}function Rs(e,t){return e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function zs(e,t){return!(e.bottom<t.top||t.bottom<e.top||e.right<t.left||t.right<e.left)}function Bs(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length;n++)if(zs(e[t],e[n]))return!0;return!1}function Vs(e,t,n){let{left:r,right:i,top:a,bottom:o}=n;return e>=r&&e<=i&&t>=a&&t<=o}function Hs(e,t){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom}function Us(e){return{numberOfRows:e.bottom-e.top+1,numberOfCols:e.right-e.left+1}}function Ws(e){let{numberOfCols:t,numberOfRows:n}=Us(e);return t===1||n===1}function Gs(e){let{top:t,left:n,bottom:r,right:i}=e;if(nc(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 Ks(e){let t=[],{left:n,right:r,top:i,bottom:a}=Js(e);for(let e of S(n,r+1))for(let n of S(i,a+1))t.push({col:e,row:n});return t}function qs(e,t){let n=[],{left:r,right:i,top:a,bottom:o}=Js(t);for(let t of S(r,i+1))for(let r of S(a,o+1))n.push({sheetId:e,col:t,row:r});return n}function Js(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 Ys(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=tc(e)&&!o?t!==`rows`:ec(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 Xs(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 Zs(e){return e.reduce((e,t)=>{let n=e.length;for(let r=0;r<n;r++)if(zs(e[r],t))return e[r]=Fs(e[r],t),e;return e[n]=t,e},[])}function Qs(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 R(e){return{left:e.col,right:e.col,top:e.row,bottom:e.row}}function $s(e){return{...e,right:e.left,bottom:e.top}}function ec(e){return e.right===void 0}function tc(e){return e.bottom===void 0}function nc(e){return(e.bottom-e.top+1)*(e.right-e.left+1)}function rc(e,t,n){return e.left<t&&t<=e.right||e.top<n&&n<=e.bottom}function ic(e,t,n){return e.some(e=>rc(e,t,n))}function ac(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 oc(e){return e.length<2?!0:ms(e).length===1}function sc(e){let t=new Set;for(let n of ms(e))for(let e of S(n.left,n.right+1))t.add(e);return t}function cc(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 lc(e){let t=new Set;for(let n of ms(e))for(let e of S(n.top,n.bottom+1))t.add(e);return t}function uc(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 dc(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&&(uc(t,r)||zs(t,r)));if(i!==-1){t[e]=Fs(t[i],r),t.splice(i,1),n=!0;break}}}return t}let fc=new WeakMap,pc=new WeakMap;function mc(e,t){fc.has(t)||(fc.set(t,new Map),pc.set(t,0));let n=fc.get(t),r=_c(e);if(n.has(r)){let i=n.get(r);return t[i]=e,i}let i=pc.get(t)+1;return n.set(r,i),pc.set(t,i),t[i]=e,i}function hc(e){let t={};for(let n in e){let r=ms(e[n].map(R));for(let e of r)t[As(e)]=Number(n)}return t}function*gc(e,t){for(let n in t){let r=Ts(n),i=t[n];for(let t=r.top;t<=r.bottom;t++)for(let n=r.left;n<=r.right;n++)yield[{sheetId:e,col:n,row:t},i]}}function _c(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e!=`object`)return String(e);if(Array.isArray(e)){let t=e.length,n=`[`;for(let r=0;r<t;r++)r>0&&(n+=`,`),n+=_c(e[r]);return n+`]`}let t=Object.keys(e).sort(),n=`{`;for(let r of t)e[r]!==void 0&&(n+=`"${r}":${_c(e[r])},`);return n+=`}`,n}function vc(e){return 20+120*Math.exp(-.035*(e-1))}let yc=new RegExp(/\$?([A-Z]{1,3})\$?([0-9]{1,7})/,`i`),bc=new RegExp(/^\$?([A-Z]{1,3})\$?([0-9]{1,7})$/,`i`),xc=new RegExp(/^\$?([A-Z]{1,3})+$/,`i`),Sc=new RegExp(/^\$?([0-9]{1,7})+$/,`i`),Cc=new RegExp(/^\s*('.+'!|[^']+!)?\$?([A-Z]{1,3})$/,`i`),wc=new RegExp(/^\s*('.+'!|[^']+!)?\$?([0-9]{1,7})$/,`i`),Tc=RegExp(`^\\s*('.+'!|[^']+!)?(`+[yc.source,`(\\$?[A-Z]{1,3})?\\$?[0-9]{1,7}\\s*:\\s*(\\$?[A-Z]{1,3})?\\$?[0-9]{1,7}\\s*`,`\\$?[A-Z]{1,3}(\\$?[0-9]{1,7})?\\s*:\\s*\\$?[A-Z]{1,3}(\\$?[0-9]{1,7})?\\s*`].join(`|`)+`)$`,`i`);function Ec(e){return Cc.test(e)}function Dc(e){return wc.test(e)}function Oc(e){return xc.test(e)}function kc(e){return Sc.test(e)}function Ac(e){return bc.test(e)}function jc(e){if(!e.includes(`!`))return{xc:e};let t=e.split(`!`),n=t.pop();return{sheetName:ft(t.join(`!`))||void 0,xc:n}}function Mc(e,t){return e===void 0?t:`${mt(e)}!${t}`}function Nc(e,t){let n=e.zone,r=ac(n,t(e.sheetId)),i=e.parts;return e.parts.length===1&&nc(r)>1?i=[e.parts[0],e.parts[0]]:e.parts.length===2&&nc(r)===1&&(i=[e.parts[0]]),{unboundedZone:n,zone:r,parts:i,prefixSheet:e.prefixSheet,invalidSheetName:e.invalidSheetName,sheetId:e.sheetId}}function Pc(e,t){let n=e.xc,{xc:r,sheetName:i}=jc(n),a=ws(r);return Nc({zone:a,parts:Hc(r,a),sheetId:e.sheetId,prefixSheet:!!i,invalidSheetName:e.invalidSheetName},t)}function Fc(e){let t={left:-1,top:-1,right:-1,bottom:-1};return{sheetId:``,zone:t,unboundedZone:t,parts:[],invalidXc:e,prefixSheet:!1}}function Ic(e){return tc(e.unboundedZone)}function Lc(e){return ec(e.unboundedZone)}function Rc(e,t,n,r={useBoundedReference:!1,useFixedReference:!1}){if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0||e.zone.left<0||e.zone.top<0)return k.InvalidReference;let i=e.sheetId!==t||e.invalidSheetName||e.prefixSheet,a=``;if(i&&(a=e.invalidSheetName?mt(e.invalidSheetName):mt(n(e.sheetId))),i&&!a)return k.InvalidReference;let o=$c(e,0,r);return e.parts&&e.parts.length===2&&(e.zone.top!==e.zone.bottom||e.zone.left!==e.zone.right||e.parts[0].rowFixed||e.parts[0].colFixed||e.parts[1].rowFixed||e.parts[1].colFixed)&&(o+=`:`,o+=$c(e,1,r)),`${i?a+`!`:``}${o}`}function zc(e,t,n){let r=n.sheetId===e?t:n.sheetId;return{...n,sheetId:r}}function Bc(e,t,n){if(!n)return;let r=e.getRangeFromSheetXC(t,n);return r.invalidSheetName||r.invalidXc?void 0:r}function Vc(e){let t=[];for(let n of e)for(let e of Ks(n.zone))t.push({...e,sheetId:n.sheetId});return t}function Hc(e,t){let n=e.split(`:`).map(e=>{let t=Dc(e);return{colFixed:t?!1:e.startsWith(`$`),rowFixed:t?e.startsWith(`$`):e.includes(`$`,1)}}),r=t.bottom===void 0,i=t.right===void 0;return r&&(n[0].rowFixed=n[0].rowFixed||n[1].rowFixed,n[1].rowFixed=n[0].rowFixed||n[1].rowFixed),i&&(n[0].colFixed=n[0].colFixed||n[1].colFixed,n[1].colFixed=n[0].colFixed||n[1].colFixed),n}function Uc(e){let t={left:e.col,top:e.row,right:e.col,bottom:e.row};return{sheetId:e.sheetId,zone:t}}function Wc(e){if(ks(e.zone))return e;let t={...e.unboundedZone},n={...e.zone},r=e.parts;if(t.right!==void 0&&t.right<t.left){let e=t.right;t.right=t.left,t.left=e,n.right=n.left,n.left=e,r=[{colFixed:r[1]?.colFixed||!1,rowFixed:r[0]?.rowFixed||!1},{colFixed:r[0]?.colFixed||!1,rowFixed:r[1]?.rowFixed||!1}]}if(t.bottom!==void 0&&t.bottom<t.top){let e=t.bottom;t.bottom=t.top,t.top=e,n.bottom=n.top,n.top=e,r=[{colFixed:r[0]?.colFixed||!1,rowFixed:r[1]?.rowFixed||!1},{colFixed:r[1]?.colFixed||!1,rowFixed:r[0]?.rowFixed||!1}]}return{unboundedZone:t,zone:n,parts:r,invalidXc:e.invalidXc,prefixSheet:e.prefixSheet,invalidSheetName:e.invalidSheetName,sheetId:e.sheetId}}function Gc(e){return Kc.get(e.type)?.(e)}let Kc=new class extends g{add(e,t){return super.add(e,t),this}get(e){return this.content[e]}};Kc.add(`REMOVE_COLUMNS_ROWS`,e=>({applyChange:qc(e),sheetId:e.sheetId,sheetName:{old:e.sheetName,current:e.sheetName}})).add(`ADD_COLUMNS_ROWS`,e=>({applyChange:Jc(e),sheetId:e.sheetId,sheetName:{old:e.sheetName,current:e.sheetName}})).add(`DELETE_SHEET`,e=>({applyChange:Yc(e),sheetId:e.sheetId,sheetName:{old:e.sheetName,current:e.sheetName}})).add(`RENAME_SHEET`,e=>({applyChange:Xc(e),sheetId:e.sheetId,sheetName:{old:e.oldName,current:e.newName}})).add(`MOVE_RANGES`,e=>({applyChange:Zc(e),sheetId:e.sheetId,sheetName:{old:e.sheetName,current:e.sheetName}}));function qc(e){let t=e.dimension===`COL`?`left`:`top`,n=e.dimension===`COL`?`right`:`bottom`,r=e.dimension===`COL`?`columns`:`rows`,i=[...e.elements];i.sort((e,t)=>t-e);let a=gt(i);return i=>{if(i.sheetId!==e.sheetId)return{changeType:`NONE`,range:i};let o=i,s=`NONE`;for(let e of a){let a=en(e),c=$t(e);if(i.zone[t]<=a&&a<=i.zone[n]){let e=Math.min(i.zone[n],c)-a+1;s=`RESIZE`,o=Qc(o,r,s,-e)}else if(i.zone[t]>=a&&i.zone[n]<=c)s=`REMOVE`,o=Fc(k.InvalidReference);else if(i.zone[t]<=c&&i.zone[n]>=c){let e=c-i.zone[t]+1;s=`RESIZE`,o=Qc(o,r,s,-e),o=Qc(o,r,`MOVE`,-(i.zone[t]-a))}else a<i.zone[t]&&(s=`MOVE`,o=Qc(o,r,s,-(c-a+1)))}return{changeType:s,range:o}}}function Jc(e){let t=e.dimension===`COL`?`left`:`top`,n=e.dimension===`COL`?`right`:`bottom`,r=e.dimension===`COL`?`columns`:`rows`;return i=>{if(i.sheetId!==e.sheetId)return{changeType:`NONE`,range:i};let a=i.unboundedZone[n]===void 0;if(a&&!i.unboundedZone.hasHeader)return{changeType:`RESIZE`,range:Qc(i,r,`RESIZE`,e.quantity)};if(e.position===`after`){if(i.zone[t]<=e.base&&(e.base<i.zone[n]||a))return{changeType:`RESIZE`,range:Qc(i,r,`RESIZE`,e.quantity)};if(e.base<i.zone[t])return{changeType:`MOVE`,range:Qc(i,r,`MOVE`,e.quantity)}}else{if(i.zone[t]<e.base&&e.base<=i.zone[n])return{changeType:`RESIZE`,range:Qc(i,r,`RESIZE`,e.quantity)};if(e.base<=i.zone[t])return{changeType:`MOVE`,range:Qc(i,r,`MOVE`,e.quantity)}}return{changeType:`NONE`,range:i}}}function Yc(e){return t=>{if(t.sheetId!==e.sheetId&&t.invalidSheetName!==e.sheetName)return{changeType:`NONE`,range:t};let n=e.sheetName;return t={...Fc(k.InvalidReference),invalidSheetName:n},{changeType:`REMOVE`,range:t}}}function Xc(e){return t=>{if(t.sheetId===e.sheetId)return{changeType:`CHANGE`,range:t};if(e.newName&&t.invalidSheetName===e.newName){let n=e.sheetId;return{changeType:`CHANGE`,range:{...t,sheetId:n,invalidSheetName:void 0}}}if(e.oldName&&t.invalidSheetName===e.oldName){let n=e.sheetId;return{changeType:`CHANGE`,range:{...t,sheetId:n,invalidSheetName:void 0}}}return{changeType:`NONE`,range:t}}}function Zc(e){let t=e.target[0];return n=>{if(n.sheetId!==e.sheetId||!Hs(n.zone,t))return{changeType:`NONE`,range:n};let r=e.targetSheetId,i=Qc(n,`both`,`MOVE`,[e.col-t.left,e.row-t.top]),a=e.sheetId===r?i.prefixSheet:!0;return{changeType:`MOVE`,range:{...i,sheetId:r,prefixSheet:a}}}}function Qc(e,t,n,r){return{...e,unboundedZone:Ys(e.unboundedZone,t,n,r),zone:Ys(e.zone,t,n,r)}}function $c(e,t,n={useBoundedReference:!1,useFixedReference:!1}){let r=e.parts[t]?.colFixed||n.useFixedReference?`$`:``,i=Yn(t===0?e.zone.left:e.zone.right),a=e.parts[t]?.rowFixed||n.useFixedReference?`$`:``,o=String(t===0?e.zone.top+1:e.zone.bottom+1),s=``;return s=tc(e.unboundedZone)&&!n.useBoundedReference?t===0&&e.unboundedZone.hasHeader?r+i+a+o:r+i:ec(e.unboundedZone)&&!n.useBoundedReference?t===0&&e.unboundedZone.hasHeader?r+i+a+o:a+o:r+i+a+o,s}function el(e,t){e=e.toLocaleLowerCase(),t=t.toLocaleLowerCase();let n=0,r=0,i=t.length,a=0;for(let o=0;o<i;o++)t[o]===e[a]?(a++,r+=100+r-o/200):r=0,n+=r;return a===e.length?n:0}function tl(e,t,n){let r=[];return t.forEach(t=>{let i=el(e,n(t));i>0&&r.push({score:i,elem:t})}),r.sort((e,t)=>t.score-e.score),r.map(e=>e.elem)}function nl(e){let t=[];for(let n=0;n<e;n++)t.push({cells:{}});return t}function rl(e,t,n){return n.map(n=>n>=e?n+t:n)}function il(e,t){return e=[...e].sort((e,t)=>t-e),t.map(t=>{for(let n of e)if(t>n)t--;else if(t===n)return;return t}).filter(C)}function al(e,t=`Sheet`){let n=1,r=`${t}${n}`;for(;e.includes(r);)r=`${t}${n}`,n++;return r}function ol(e,t){let n=1,r=E(`Copy of %s`,e),i=r.toString();for(;t.includes(i);)i=`${r} (${n})`,n++;return i}let sl=Kt(function(e){return ft(e.trim().toUpperCase())});function cl(e,t){return e===void 0||t===void 0?!1:sl(e)===sl(t)}function ll(e,t=1){return t*(e+4)-4}function ul(e,t,n,r){if(!t||!t.isFormula&&!t.content)return 23;let i=``;try{if(!t.isFormula){let e={format:t.format,locale:n};i=L(ts(t.content,n),e)}}catch{i=k.GenericError}return dl(e,i,t.style,r)}function dl(e,t,n,r){let i=Cl(e,t,n,n?.wrapping===`wrap`?r-8:void 0).length;return ll(xl(n),i)+6}function fl(e,t=!1,n=!1){return`${n?`italic`:``} ${t?`bold`:``} ${e}px ${He}`}let pl={};function ml(e,t,n,r=`pt`){return hl(e,t,bl(n,r))}function hl(e,t,n){if(pl[n]||(pl[n]={}),pl[n][t]===void 0){let r=e.font;e.font=n,pl[n][t]=e.measureText(t).width,e.font=r}return pl[n][t]}let gl={};function _l(e,t,n,r=`pt`){let i=bl(n,r);e.save(),e.font=i;let a=vl(e,t);return e.restore(),a}function vl(e,t){let n=e.font;if(gl[n]||(gl[n]={}),gl[n][t]===void 0){let r=e.measureText(t),i=r.width,a=r.fontBoundingBoxAscent+r.fontBoundingBoxDescent;gl[n][t]={width:i,height:a}}return gl[n][t]}function yl(e){return Math.round(e*96/72)}function bl(e,t=`pt`){return`${e.italic?`italic `:``}${e.bold?`bold`:`400`} ${(t===`pt`?xl(e):e.fontSize)??Ve}px ${He}`}function xl(e){return yl(e?.fontSize||Ve)}function Sl(e,t,n,r){if(ml(e,t,r)<=n)return[t];let i=[],a=``;for(let o of t)ml(e,a+o,r)>n?(i.push(a),a=o):a+=o;return i.push(a),i}function Cl(e,t,n,r){n||={},xt(t)&&(t=wt(t).label);let i=[],a=t.includes(`
|
|
6
6
|
`)?t.split(`
|
|
7
7
|
`):[t];for(let t of a){let a=t.includes(` `)?t.split(` `):[t];if(!r){i.push(t);continue}let o=``,s=r;for(let t of a){let a=Sl(e,t,r,n),c=a.pop(),l=ml(e,c,n);if(a.length)o!==``&&(i.push(o),o=``,s=r),a.forEach(e=>{i.push(e)}),o=c,s=r-l;else{let t=o===``?c:` `+c,a=ml(e,t,n);a<=s?(o+=t,s-=a):(i.push(o),o=c,s=r-l)}}o!==``&&i.push(o)}return i}function wl(e,t,n,r=.25){let i=1;if(n(i)>e)return i;if(n(t)<e)return t;let a=(i+t)/2,o=n(a),s=0;for(;Math.abs(o-e)>r&&s<20;)o>=e?t=(i+t)/2:i=(i+t)/2,a=(i+t)/2,o=n(a),s++;return a}function Tl(e){return e?e.toLowerCase():``}let El=/([0-9\.]*)px/;function Dl(e){return Number(e.match(El)?.[1])}function Ol(e,t,n){let r=hl(e,t,e.font);if(r<=n)return t;let i=hl(e,`…`,e.font);if(r<=i)return t;let a=t.length;for(;r>=n-i&&a-- >0;)t=t.substring(0,a),r=hl(e,t,e.font);return t+`…`}function kl(e,t,n,r=!1,i=!1,a=Dl(e.font)/10){if(e.fillText(t,n.x,n.y),!r&&!i)return;let o=e.measureText(t),s=o.width,c=o.actualBoundingBoxAscent+o.actualBoundingBoxDescent,l=o.fontBoundingBoxAscent+o.fontBoundingBoxDescent,{x:u,y:d}=n,f=d,p=d;switch(e.textAlign){case`center`:u-=s/2;break;case`right`:u-=s;break}switch(e.textBaseline){case`top`:p+=l-2*a,f+=l/2-a;break;case`middle`:p+=l/2-a;break;case`alphabetic`:p+=2*a,f-=3*a;break;case`bottom`:p=d,f-=c/2-a/2;break}r&&(e.lineWidth=a,e.strokeStyle=e.fillStyle,e.beginPath(),e.moveTo(u,p),e.lineTo(u+s,p),e.stroke()),i&&(e.lineWidth=a,e.strokeStyle=e.fillStyle,e.beginPath(),e.moveTo(u,f),e.lineTo(u+s,f),e.stroke())}function Al(e,t,n,r,i=`pt`){if(ml(e,n,r,i)<=t)return n;let a=ml(e,`...`,r,i);if(a>=t)return``;let o=1,s=n.length,c;for(;o<=s;){let l=Math.floor((o+s)/2);c=ml(e,n.slice(0,l),r,i),c+a>t?s=l-1:o=l+1}let l=n.slice(0,Math.max(0,o-1));return l?l+`...`:``}var jl=class{smallUuid(){return window.crypto?`10000000-1000`.replace(/[01]/g,e=>{let t=Number(e);return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}):`xxxxxxxx-xxxx`.replace(/[xy]/g,function(e){let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}uuidv4(){return window.crypto?`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>{let t=Number(e);return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}):`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}};let Ml=[`image/avif`,`image/bmp`,`image/gif`,`image/vnd.microsoft.icon`,`image/jpeg`,`image/png`,`image/tiff`,`image/webp`];function Nl(e,t){let n=new Set(t.map(e=>e.left)),r=new Set(t.map(e=>e.right)),i=new Set(t.map(e=>e.top)),a=new Set(t.map(e=>e.bottom)),o=i.size===1&&a.size===1||n.size===1&&r.size===1?Zs(t):[t[t.length-1]],s=o.map(e=>Ks(e)).flat();return{sheetId:e,zones:t,clippedZones:o,columnsIndexes:[...new Set(s.map(e=>e.col))].sort((e,t)=>e-t),rowsIndexes:[...new Set(s.map(e=>e.row))].sort((e,t)=>e-t)}}function Pl(e,t,n){let r=Math.max(e.right-t+1,e.left),i=Math.max(e.bottom-n+1,e.top),a=[];for(let o=e.left;o<=r;o+=t)for(let r=e.top;r<=i;r+=n)a.push({left:o,top:r,bottom:r+n-1,right:o+t-1});return a}function Fl(e,t){if(!t.length||!t[0].length)return e;let n=t[0].length,r=t.length;return e.map(e=>Pl(e,n,r)).flat()}function Il(e){let t;e[`text/html`]&&(t=Ll(new DOMParser().parseFromString(e[`text/html`],`text/html`)));let n=e[`text/plain`]||``,r;if(!n.trim()){for(let t of Ml)if(e[t]){r=e[t];break}}return{text:n,data:t,imageBlob:r}}function Ll(e){if([...e.documentElement.attributes].some(e=>e.value.includes(`microsoft`)))return;let t=e.querySelector(`div`)?.getAttribute(`data-osheet-clipboard`);return t&&JSON.parse(t)}let Rl=(e,t,n,r)=>{e.forEach(({handlerName:e,handler:i})=>{let a=t[e];a&&i.paste(n,a,r)})};function zl(e,t,n,r,i){let a,o=[],s={sheetId:e,zones:t};for(let{handlerName:c,handler:l}of r){let r=n[c];if(!r)continue;let u=l.getPasteTarget(e,t,r,i);u.figureId&&(s.figureId=u.figureId);for(let e of u.zones){if(o.push(e),a===void 0){a=e;continue}a=Fs(a,e)}}return{target:s,zone:a,selectedZones:o}}let Bl=(e,t,n)=>{let r={col:t[0].left,row:t[0].top};e.getBackToDefault(),e.selectZone({cell:r,zone:Fs(...n)},{scrollIntoView:!1})};var Vl=class{getters;dispatch;constructor(e,t){this.getters=e,this.dispatch=t}copy(e,t,n=`copyPaste`){}paste(e,t,n){}isPasteAllowed(e,t,n,r){return`Success`}isCutAllowed(e){return`Success`}getPasteTarget(e,t,n,r){return{zones:[],sheetId:e}}convertTextToClipboardData(e){}},Hl=class extends Vl{copy(e,t,n=`copyPaste`){}pasteFromCopy(e,t,n,r){if(t.length===1)for(let i of Fl(t,n))this.pasteZone(e,i.left,i.top,n,r);else for(let i of ms(t))for(let t=i.left;t<=i.right;t++)for(let a=i.top;a<=i.bottom;a++)this.pasteZone(e,t,a,n,r)}pasteZone(e,t,n,r,i){}},Ul=class extends Hl{queuedBordersToAdd={};copy(e){let t=e.sheetId;if(e.zones.length===0)return;let{rowsIndexes:n,columnsIndexes:r}=e,i=[];for(let e of n){let n=[];for(let i of r){let r={col:i,row:e,sheetId:t};n.push(this.getters.getCellBorder(r))}i.push(n)}return{borders:i}}paste(e,t,n){let r=e.sheetId;if(n.pasteOption===`asValue`)return;let i=e.zones;if(!n.isCutOperation)this.pasteFromCopy(r,i,t.borders);else{let{left:e,top:n}=i[0];this.pasteZone(r,e,n,t.borders)}this.executeQueuedChanges(r)}pasteZone(e,t,n,r){for(let[i,a]of r.entries())for(let[r,o]of a.entries()){let a={col:t+r,row:n+i,sheetId:e};this.pasteBorder(o,a)}}pasteBorder(e,t){let n={...this.getters.getCellBorder(t),...e},r=JSON.stringify(n);this.queuedBordersToAdd[r]||(this.queuedBordersToAdd[r]=[]),this.queuedBordersToAdd[r].push(R(t))}executeQueuedChanges(e){for(let t in this.queuedBordersToAdd){let n=this.queuedBordersToAdd[t],r=JSON.parse(t),i=ms(n,[]);this.dispatch(`SET_BORDERS_ON_TARGET`,{sheetId:e,target:i,border:r})}this.queuedBordersToAdd={}}},Wl=class extends Vl{copy(e){}},Gl=class extends Wl{copy(e){let t=e.sheetId,n=this.getters.getFigure(t,e.figureId);if(!n)throw Error(`No figure for the given id: ${e.figureId}`);if(n.tag!==`carousel`)return;let r={...n},i=this.getters.getCarousel(e.figureId),a={};for(let e of i.items)if(e.type===`chart`){let n=this.getters.getChart(e.chartId);if(!n)throw Error(`No chart for the given id: ${e.chartId}`);a[e.chartId]=n.copyInSheetId(t)}return{figureId:e.figureId,copiedFigure:r,copiedCarousel:i,copiedCharts:a,copiedSheetId:t}}getPasteTarget(e){return{zones:[],figureId:new jl().smallUuid(),sheetId:e}}paste(e,t,n){if(!e.figureId)return;let{zones:r,figureId:i}=e,a=e.sheetId,{width:o,height:s}=t.copiedFigure,c=this.getters.getMaxAnchorOffset(a,s,o),{left:l,top:u}=r[0],d={x:0,y:0};l>c.col&&(l=c.col,d.x=c.offset.x),u>c.row&&(u=c.row,d.y=c.offset.y),this.dispatch(`CREATE_CAROUSEL`,{figureId:i,sheetId:a,definition:{items:[]},col:l,row:u,offset:d,size:{height:s,width:o}});let f=new jl,p=b(t.copiedCarousel.items);for(let e of p){if(e.type!==`chart`)continue;let n=t.copiedCharts[e.chartId],r=f.smallUuid(),o=n.copyInSheetId(a).getDefinition();this.dispatch(`CREATE_CHART`,{figureId:i,chartId:r,sheetId:a,definition:o}),e.chartId=r}this.dispatch(`UPDATE_CAROUSEL`,{sheetId:a,figureId:i,definition:{...t.copiedCarousel,items:p}}),n.isCutOperation&&this.dispatch(`DELETE_FIGURE`,{sheetId:t.copiedSheetId,figureId:t.copiedFigure.id}),this.dispatch(`SELECT_FIGURE`,{figureId:i})}isPasteAllowed(e,t,n,r){return t.length===0?`EmptyTarget`:r?.pasteOption===void 0?`Success`:`WrongFigurePasteOption`}};let Kl=[`%`],ql=`+,-,*,/,:,=,<>,>=,>,<=,<,^,&`.split(`,`).concat(Kl);function Jl(e,t=D){e=Wt(e);let n=new tn(e),r=[],i=Vt.test(e)?ou:su;for(;!n.isOver();){let e=cu(n)||i(n)||Ql(n,t)||Zl(n)||$l(n)||nu(n)||Yl(n)||lu(n)||tu(n,t)||au(n);e||={type:`UNKNOWN`,value:n.shift()},r.push(e)}return r}function Yl(e){return e.current===`?`?(e.shift(),{type:`DEBUGGER`,value:`?`}):null}let Xl={"(":{type:`LEFT_PAREN`,value:`(`},")":{type:`RIGHT_PAREN`,value:`)`}};function Zl(e){return e.current===`(`||e.current===`)`?Xl[e.shift()]:null}function Ql(e,t){return e.current===t.formulaArgSeparator?{type:`ARG_SEPARATOR`,value:e.shift()}:null}function $l(e){for(let t of ql)if(e.currentStartsWith(t))return e.advanceBy(t.length),{type:`OPERATOR`,value:t};return null}let eu=new Set(`0123456789`);function tu(e,t){if(!eu.has(e.current)&&e.current!==t.decimalSeparator)return null;let n=e.remaining().match(Bi(t.decimalSeparator));return n?(e.advanceBy(n[0].length),{type:`NUMBER`,value:n[0]}):null}function nu(e){if(e.current===`"`){let t=e.shift(),n=t;for(;e.current&&(e.current!==t||n[n.length-1]===`\\`);)n+=e.shift();return e.current===`"`&&(n+=e.shift()),{type:`STRING`,value:n}}return null}let ru=/\p{L}|\p{N}|_|\.|!|\$/u,iu=new Set(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.!$`);function au(e){let t=``;if(e.current===`'`){let n=e.shift();for(t+=n;e.current;)if(n=e.shift(),t+=n,n===`'`)if(e.current&&e.current===`'`)n=e.shift(),t+=n;else break;if(n!==`'`)return{type:`UNKNOWN`,value:t}}for(;e.current&&(iu.has(e.current)||e.current.match(ru));)t+=e.shift();if(t.length){let e=t;return Tc.test(e)?{type:`REFERENCE`,value:e}:{type:`SYMBOL`,value:e}}return null}function ou(e){let t=``;for(;e.current===` `||e.current&&e.current.match(Vt);)t+=e.shift();return t?{type:`SPACE`,value:t}:null}function su(e){let t=``;for(;e.current===` `;)t+=e.shift();return t?{type:`SPACE`,value:t}:null}function cu(e){let t=0;for(;e.current===`
|
|
@@ -833,7 +833,7 @@ stores.inject(MyMetaStore, storeInstance);
|
|
|
833
833
|
}
|
|
834
834
|
`;let hj={name:`ARROW_DOWN`,width:448,height:512,paths:[{fillColor:`#E06666`,path:`M413.1 222.5l22.2 22.2c9.4 9.4 9.4 24.6 0 33.9L241 473c-9.4 9.4-24.6 9.4-33.9 0L12.7 278.6c-9.4-9.4-9.4-24.6 0-33.9l22.2-22.2c9.5-9.5 25-9.3 34.3.4L184 343.4V56c0-13.3 10.7-24 24-24h32c13.3 0 24 10.7 24 24v287.4l114.8-120.5c9.3-9.8 24.8-10 34.3-.4z`}]},gj={name:`ARROW_UP`,width:448,height:512,paths:[{fillColor:`#6AA84F`,path:`M34.9 289.5l-22.2-22.2c-9.4-9.4-9.4-24.6 0-33.9L207 39c9.4-9.4 24.6-9.4 33.9 0l194.3 194.3c9.4 9.4 9.4 24.6 0 33.9L413 289.4c-9.5 9.5-25 9.3-34.3-.4L264 168.6V456c0 13.3-10.7 24-24 24h-32c-13.3 0-24-10.7-24-24V168.6L69.2 289.1c-9.3 9.8-24.8 10-34.3.4z`}]},_j={name:`ARROW_RIGHT`,width:448,height:512,paths:[{fillColor:`#F0AD4E`,path:`M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z`}]},vj={name:`SMILE`,width:496,height:512,paths:[{fillColor:`#6AA84F`,path:`M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160 0c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm4 72.6c-20.8 25-51.5 39.4-84 39.4s-63.2-14.3-84-39.4c-8.5-10.2-23.7-11.5-33.8-3.1-10.2 8.5-11.5 23.6-3.1 33.8 30 36 74.1 56.6 120.9 56.6s90.9-20.6 120.9-56.6c8.5-10.2 7.1-25.3-3.1-33.8-10.1-8.4-25.3-7.1-33.8 3.1z`}]},yj={name:`MEH`,width:496,height:512,paths:[{fillColor:`#F0AD4E`,path:`M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160-64c-17.7 0-32 14.3-32 32s14.3 32 32 32 32-14.3 32-32-14.3-32-32-32zm8 144H160c-13.2 0-24 10.8-24 24s10.8 24 24 24h176c13.2 0 24-10.8 24-24s-10.8-24-24-24z`}]},bj={name:`FROWN`,width:496,height:512,paths:[{fillColor:`#E06666`,path:`M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm-80-216c17.7 0 32-14.3 32-32s-14.3-32-32-32-32 14.3-32 32 14.3 32 32 32zm160-64c-17.7 0-32 14.3-32 32s14.3 32 32 32 32-14.3 32-32-14.3-32-32-32zm-80 128c-40.2 0-78 17.7-103.8 48.6-8.5 10.2-7.1 25.3 3.1 33.8 10.2 8.4 25.3 7.1 33.8-3.1 16.6-19.9 41-31.4 66.9-31.4s50.3 11.4 66.9 31.4c8.1 9.7 23.1 11.9 33.8 3.1 10.2-8.5 11.5-23.6 3.1-33.8C326 321.7 288.2 304 248 304z`}]},xj=`M256 9 a247 247 0 1 0.1 0 0`,Sj={name:`GREEN_DOT`,width:512,height:512,paths:[{fillColor:`#6AA84F`,path:xj}]},Cj={name:`YELLOW_DOT`,width:512,height:512,paths:[{fillColor:`#F0AD4E`,path:xj}]},wj={name:`RED_DOT`,width:512,height:512,paths:[{fillColor:`#E06666`,path:xj}]};function Tj(e){return{name:`CARET_DOWN`,width:512,height:512,paths:[{fillColor:e.textColor||`#374151C2`,path:`M120 195 h270 l-135 130`}]}}function Ej(e){return{name:`CARET_UP`,width:512,height:512,paths:[{fillColor:e.textColor||`#374151C2`,path:`M120 325 h270 l-135 -130`}]}}function Dj(e){return{name:`CARET_DOWN`,width:512,height:512,paths:[{fillColor:e.textColor||`#374151C2`,path:`M15 15 h482 v482 h-482`},{fillColor:e.fillColor||`#fff`,path:`M120 195 h270 l-135 130`}]}}let Oj=`M40 185 h270 l-135 128`;function kj(e){return{name:`CHIP`,width:512,height:512,paths:[{fillColor:e.textColor||`#374151C2`,path:Oj}]}}function Aj(e){return{name:`CHIP`,width:512,height:512,paths:[{fillColor:e.textColor||`#374151C2`,path:`M0,225 A175,175 0 1,0 350,225 A175,175 0 1,0 0,225`},{fillColor:e.fillColor||`#374151C2`,path:Oj}]}}let jj={name:`CHECKBOX_UNCHECKED`,width:512,height:512,paths:[{fillColor:ye,path:`M45,45 h422 v422 h-422 v-422 m30,30 v362 h362 v-362`}]},Mj={name:`CHECKBOX_UNCHECKED`,width:512,height:512,paths:[{fillColor:Ae,path:`M45,45 h422 v422 h-422 v-422 m30,30 v362 h362 v-362`}]},Nj={name:`CHECKBOX_CHECKED`,width:512,height:512,paths:[{fillColor:Ae,path:`M45,45 h422 v422 h-422 v-422`},{fillColor:`#FFF`,path:`M165,240 l45,45 l135,-135 h60 l-195,195 l-105,-105`}]};function Pj(e,t){return{name:`PIVOT_ICON`,width:512,height:512,paths:[{path:`M21,21 h469 v469 h-469`,fillColor:t?ve:`#777`},{path:`M64,64 v384 h384 v-384`,fillColor:t?be:`#eee`},{path:e?`M149,235 h213 v43 h-213 M235,149 h43 v213 h-43`:`M149,235 h213 v43 h-213`,fillColor:t?ve:`#777`}]}}function Fj(e,t,n){let r=e?`M18.6 3.5H4.29c-.7 0-1.06.85-.56 1.35l6.1 6.1v6.8c0 .26.13.5.34.65l2.64 1.85a.79.79 0 0 0 1.25-.65v-8.64l6.1-6.1a.79.79 0 0 0-.56-1.35`:`M 339.667 681 L 510.333 681 L 510.333 595.667 L 339.667 595.667 L 339.667 681 Z M 41 169 L 41 254.333 L 809 254.333 L 809 169 L 41 169 Z M 169 467.667 L 681 467.667 L 681 382.333 L 169 382.333 L 169 467.667 Z`,i=e?`M0,0 h24 v24 h-24`:`M0,0 h850 v850 h-850`,a={iconColor:ue,hoverBackgroundColor:ue};return n&&!t?a.iconColor=`#fff`:!n&&t?a.iconColor=`#defade`:n&&t&&(a.iconColor=ue,a.hoverBackgroundColor=`#fff`),{name:`DATA_FILTER_ICON`,width:e?24:850,height:e?24:850,paths:[n?{path:i,fillColor:a.hoverBackgroundColor}:void 0,{path:r,fillColor:a.iconColor}].filter(C)}}let Ij={arrowGood:{template:`ARROW_UP`,svg:gj},arrowNeutral:{template:`ARROW_RIGHT`,svg:_j},arrowBad:{template:`ARROW_DOWN`,svg:hj},smileyGood:{template:`SMILE`,svg:vj},smileyNeutral:{template:`MEH`,svg:yj},smileyBad:{template:`FROWN`,svg:bj},dotGood:{template:`GREEN_DOT`,svg:Sj},dotNeutral:{template:`YELLOW_DOT`,svg:Cj},dotBad:{template:`RED_DOT`,svg:wj}},Lj={arrows:{good:`arrowGood`,neutral:`arrowNeutral`,bad:`arrowBad`},smiley:{good:`smileyGood`,neutral:`smileyNeutral`,bad:`smileyBad`},dots:{good:`dotGood`,neutral:`dotNeutral`,bad:`dotBad`}},Rj={};function zj(e){if(Rj[e])return Rj[e];let t=new Path2D(e);return Rj[e]=t,t}function Bj(e,t){let n=e.split(`/`),r=t.split(`/`),i=``,a=0;for(let e=0;e<n.length-1;e++)n[e]===r[e]?a++:i+=`../`;return i+=r.slice(a).join(`/`),i}function Vj(e,t=0){let n={};for(let r=0;r<e.length;r++)e[r]&&(n[r+t]=e[r]);return n}function Hj(e){return e.replace(/_x([0-9a-zA-Z]{4})_/g,(e,t)=>String.fromCharCode(parseInt(t,16)))}function Uj(e,t,n){return t===`COL`?(e.cols[n]||(e.cols[n]={}),e.cols[n]):(e.rows[n]||(e.rows[n]={}),e.rows[n])}function Wj(e){if(e[0]===`=`)return e;let t=Jl(e);return t.length===1&&t[0].type!==`REFERENCE`?e:`=`+e}var Gj=class{_parsingWarnings=new Set;_conversionWarnings=new Set;addParsingWarning(e){this._parsingWarnings.add(e)}addConversionWarning(e){this._conversionWarnings.add(e)}get warnings(){return[...this._parsingWarnings,...this._conversionWarnings]}generateNotSupportedWarning(e,t,n){let r=`${e} ${t?`"`+t+`" is`:`are`} not yet supported. `;n&&(r+=`Only ${n.join(`, `)} are currently supported.`),this._conversionWarnings.has(r)||this._conversionWarnings.add(r)}};let Kj=[`thin`,`medium`,`thick`,`dashed`,`dotted`],qj=[`general`,`left`,`center`,`right`],Jj=[`top`,`center`,`bottom`],Yj=[`Arial`],Xj=[`solid`,`none`],Zj=[`expression`,`cellIs`,`colorScale`,`iconSet`,`containsText`,`notContainsText`,`beginsWith`,`endsWithText`,`containsBlanks`,`notContainsBlanks`],Qj={b:`boolean`,d:`date`,e:`error`,inlineStr:`inlineStr`,n:`number`,s:`sharedString`,str:`str`},$j={dashDot:`thin`,dashDotDot:`thin`,dashed:`dashed`,dotted:`dotted`,double:`thin`,hair:`thin`,medium:`medium`,mediumDashDot:`thin`,mediumDashDotDot:`thin`,mediumDashed:`thin`,none:void 0,slantDashDot:`thin`,thick:`thick`,thin:`thin`},eM={general:void 0,left:`left`,center:`center`,right:`right`,fill:`left`,justify:`left`,centerContinuous:`center`,distributed:`center`},tM={top:`top`,center:`middle`,bottom:`bottom`,justify:`middle`,distributed:`middle`},nM={top:`top`,middle:`center`,bottom:`bottom`},rM={beginsWith:`beginsWithText`,endsWith:`endsWithText`,containsText:`containsText`,notContains:`notContainsText`,between:`isBetween`,notBetween:`isNotBetween`,equal:`isEqual`,notEqual:`isNotEqual`,greaterThan:`isGreaterThan`,greaterThanOrEqual:`isGreaterOrEqualTo`,lessThan:`isLessThan`,lessThanOrEqual:`isLessOrEqualTo`},iM={aboveAverage:void 0,expression:`customFormula`,cellIs:void 0,colorScale:void 0,dataBar:void 0,iconSet:void 0,top10:void 0,uniqueValues:void 0,duplicateValues:void 0,containsText:`containsText`,notContainsText:`notContainsText`,beginsWith:`beginsWithText`,endsWith:`endsWithText`,containsBlanks:`isEmpty`,notContainsBlanks:`isNotEmpty`,containsErrors:void 0,notContainsErrors:void 0,timePeriod:void 0},aM={num:`number`,percent:`percentage`,max:`value`,min:`value`,percentile:`percentile`,formula:`formula`},oM={NoIcons:void 0,"3Arrows":`arrows`,"3ArrowsGray":`arrows`,"3Symbols":`smiley`,"3Symbols2":`smiley`,"3Signs":`dots`,"3Flags":`dots`,"3TrafficLights1":`dots`,"3TrafficLights2":`dots`,"4Arrows":`arrows`,"4ArrowsGray":`arrows`,"4RedToBlack":`dots`,"4Rating":`smiley`,"4TrafficLights":`dots`,"5Arrows":`arrows`,"5ArrowsGray":`arrows`,"5Rating":`smiley`,"5Quarters":`dots`,"3Stars":`smiley`,"3Triangles":`arrows`,"5Boxes":`dots`},sM={none:`none`,b:`bottom`,t:`top`,l:`left`,r:`right`,tr:`right`},cM={areaChart:void 0,area3DChart:void 0,lineChart:`line`,line3DChart:void 0,stockChart:void 0,radarChart:`radar`,scatterChart:`scatter`,pieChart:`pie`,pie3DChart:void 0,doughnutChart:`pie`,barChart:`bar`,bar3DChart:void 0,ofPieChart:void 0,surfaceChart:void 0,surface3DChart:void 0,bubbleChart:void 0,comboChart:`combo`},lM={exp:`exponential`,log:`logarithmic`,poly:`polynomial`,movingAvg:`trailingMovingAverage`},uM={1:`AVERAGE`,2:`COUNT`,3:`COUNTA`,4:`MAX`,5:`MIN`,6:`PRODUCT`,7:`STDEV`,8:`STDEVP`,9:`SUM`,10:`VAR`,11:`VARP`,101:`AVERAGE`,102:`COUNT`,103:`COUNTA`,104:`MAX`,105:`MIN`,106:`PRODUCT`,107:`STDEV`,108:`STDEVP`,109:`SUM`,110:`VAR`,111:`VARP`},dM={0:`General`,1:`0`,2:`0.00`,3:`#,#00`,4:`#,##0.00`,9:`0%`,10:`0.00%`,11:void 0,12:void 0,13:void 0,14:`m/d/yyyy`,15:`m/d/yyyy`,16:`m/d/yyyy`,17:`m/d/yyyy`,18:`hh:mm:ss a`,19:`hh:mm:ss a`,20:`hhhh:mm:ss`,21:`hhhh:mm:ss`,22:`m/d/yy h:mm`,37:void 0,38:void 0,39:void 0,40:void 0,45:`hhhh:mm:ss`,46:`hhhh:mm:ss`,47:`hhhh:mm:ss`,48:void 0,49:`@`},fM={0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},pM={0:`000000`,1:`FFFFFF`,2:`FF0000`,3:`00FF00`,4:`0000FF`,5:`FFFF00`,6:`FF00FF`,7:`00FFFF`,8:`000000`,9:`FFFFFF`,10:`FF0000`,11:`00FF00`,12:`0000FF`,13:`FFFF00`,14:`FF00FF`,15:`00FFFF`,16:`800000`,17:`008000`,18:`000080`,19:`808000`,20:`800080`,21:`008080`,22:`C0C0C0`,23:`808080`,24:`9999FF`,25:`993366`,26:`FFFFCC`,27:`CCFFFF`,28:`660066`,29:`FF8080`,30:`0066CC`,31:`CCCCFF`,32:`000080`,33:`FF00FF`,34:`FFFF00`,35:`00FFFF`,36:`800080`,37:`800000`,38:`008080`,39:`0000FF`,40:`00CCFF`,41:`CCFFFF`,42:`CCFFCC`,43:`FFFF99`,44:`99CCFF`,45:`FF99CC`,46:`CC99FF`,47:`FFCC99`,48:`3366FF`,49:`33CCCC`,50:`99CC00`,51:`FFCC00`,52:`FF9900`,53:`FF6600`,54:`666699`,55:`969696`,56:`003366`,57:`339966`,58:`003300`,59:`333300`,60:`993300`,61:`993366`,62:`333399`,63:`333333`,64:`000000`,65:`FFFFFF`},mM={"image/avif":`avif`,"image/bmp":`bmp`,"image/gif":`gif`,"image/vnd.microsoft.icon":`ico`,"image/jpeg":`jpeg`,"image/png":`png`,"image/tiff":`tiff`,"image/webp":`webp`},hM={avif:`image/avif`,bmp:`image/bmp`,gif:`image/gif`,ico:`image/vnd.microsoft.icon`,jpeg:`image/jpeg`,png:`image/png`,tiff:`image/tiff`,webp:`image/webp`,jpg:`image/jpeg`},gM={between:`isBetween`,notBetween:`isNotBetween`,equal:`isEqual`,notEqual:`isNotEqual`,greaterThan:`isGreaterThan`,greaterThanOrEqual:`isGreaterOrEqualTo`,lessThan:`isLessThan`,lessThanOrEqual:`isLessOrEqualTo`},_M={between:`dateIsBetween`,notBetween:`dateIsNotBetween`,equal:`dateIs`,greaterThan:`dateIsAfter`,greaterThanOrEqual:`dateIsOnOrAfter`,lessThan:`dateIsBefore`,lessThanOrEqual:`dateIsOnOrBefore`};function vM(e){if(!e)return;let t;if(e.rgb)t=e.rgb;else if(e.auto)t=Vf;else if(e.indexed)t=pM[e.indexed];else return;return t=yM(t),e.tint&&(t=bM(t,e.tint)),t=t.toUpperCase(),t.length===9&&t.endsWith(`FF`)&&(t=t.slice(0,7)),t}function yM(e){return e.length===6?`#`+e+`FF`:`#`+e.slice(2)+e.slice(0,2)}function bM(e,t){let n=Cn(xn(e));return t<0&&(n.l*=1+t),t>0&&(n.l=n.l*(1-t)+(100-100*(1-t))),bn(Sn(n))}function xM(e){return e.length===9&&(e=e.slice(0,7)),parseInt(e.replace(`#`,``),16)}let SM=/^(yy|yyyy|m{1,5}|d{1,4}|h{1,2}|s{1,2}|am\/pm|a\/m|\s|-|\/|\.|:)+$/i;function CM(e,t,n){let r=dM[e]||t.find(t=>t.id===e)?.format;if(r!==`General`){if(r)try{let e=r.replace(/\[(.*)-[A-Z0-9]{3}\]/g,`[$1]`);if(e=e.replace(/\[\$\]/g,``),e=e.replace(/_.{1}/g,``),e=e.replace(/\*.{1}/g,``),TM(e)&&(e=EM(e)),wM(e))return e}catch{}n.generateNotSupportedWarning(`Number format`,r||`nmFmtId ${e}`)}}function wM(e){try{return L(0,{format:e,locale:D}),!0}catch{return!1}}function TM(e){return SM.test(e)}function EM(e){return e=e.toLowerCase(),e=e.replace(/mmmmm/g,`mmm`),e=e.replace(/am\/pm|a\/m/g,`a`),e=e.replace(/hhhh/g,`hh`),e=e.replace(/\bh\b/g,`hh`),e}function DM(e,t){return Vj(e.borders.map(e=>{PM(e,t);let n={top:OM(e.top,t),bottom:OM(e.bottom,t),left:OM(e.left,t),right:OM(e.right,t)};return Object.keys(n).forEach(e=>n[e]===void 0&&delete n[e]),n}),1)}function OM(e,t){if(!e)return;NM(e,t);let n=$j[e.style];return n?{style:n,color:vM(e.color)}:void 0}function kM(e,t){return Vj(e.styles.map(n=>AM({fontStyle:e.fonts[n.fontId],fillStyle:e.fills[n.fillId],alignment:n.alignment},t)),1)}function AM(e,t){return MM(e?.fontStyle,e?.fillStyle,t),FM(e?.alignment?.horizontal,t),IM(e?.alignment?.vertical,t),{bold:e.fontStyle?.bold,italic:e.fontStyle?.italic,strikethrough:e.fontStyle?.strike,underline:e.fontStyle?.underline,verticalAlign:e.alignment?.vertical?tM[e.alignment.vertical]:void 0,align:e.alignment?.horizontal?eM[e.alignment.horizontal]:void 0,fillColor:e.fillStyle?.patternType===`solid`?vM(e.fillStyle?.fgColor):vM(e.fillStyle?.bgColor),textColor:vM(e.fontStyle?.color),fontSize:e.fontStyle?.size,wrapping:e.alignment?.wrapText?`wrap`:`overflow`}}function jM(e,t){let n=[];for(let r of e.styles){let i=CM(r.numFmtId,e.numFmts,t);i&&(n[r.numFmtId]=i)}return Vj(n,1)}function MM(e,t,n){e&&e.name&&!Yj.includes(e.name)&&n.generateNotSupportedWarning(`Font`,e.name,Yj),t&&t.patternType&&!Xj.includes(t.patternType)&&n.generateNotSupportedWarning(`Fill Style`,t.patternType,Xj)}function NM(e,t){Kj.includes(e.style)||t.generateNotSupportedWarning(`Border style`,e.style,Kj)}function PM(e,t){e.diagonal&&t.generateNotSupportedWarning(`Diagonal Borders`)}function FM(e,t){e&&!qj.includes(e)&&t.generateNotSupportedWarning(`Horizontal Alignment`,e,qj)}function IM(e,t){e&&!Jj.includes(e)&&t.generateNotSupportedWarning(`Vertical Alignments`,e,Jj)}function LM(e,t,n){let r=[],i=1;for(let a of e){if(a.cfRules.length===0)continue;HM(a,t,n);let e=a.cfRules[0],o,s=[];if(!(e.dxfId===void 0&&!(e.type===`colorScale`||e.type===`iconSet`||e.type===`dataBar`))){switch(e.type){case`aboveAverage`:case`containsErrors`:case`notContainsErrors`:case`duplicateValues`:case`top10`:case`uniqueValues`:case`timePeriod`:continue;case`dataBar`:let t=RM(i++,a);t&&r.push(t);continue;case`colorScale`:let c=zM(i++,a);c&&r.push(c);continue;case`iconSet`:let l=BM(i++,a,n);l&&r.push(l);continue;case`containsText`:case`notContainsText`:case`beginsWith`:case`endsWith`:if(!e.text)continue;o=iM[e.type],s.push(e.text);break;case`expression`:if(!e.formula?.length)continue;o=iM[e.type],s.push(`=${e.formula[0]}`);break;case`containsBlanks`:case`notContainsBlanks`:o=iM[e.type];break;case`cellIs`:if(!e.operator||!e.formula||e.formula.length===0)continue;o=rM[e.operator],s.push(Wj(e.formula[0])),e.formula.length===2&&s.push(Wj(e.formula[1]));break}o&&e.dxfId!==void 0&&r.push({id:(i++).toString(),ranges:a.sqref,stopIfTrue:e.stopIfTrue,rule:{type:`CellIsRule`,operator:o,values:s,style:AM({fontStyle:t[e.dxfId].font,fillStyle:t[e.dxfId].fill},n)}})}}return r}function RM(e,t){let n=t.cfRules[0].dataBar;if(!n)return;let r=xM(vM(n.color)||`#FFFFFF`);return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:`DataBarRule`,color:r}}}function zM(e,t){let n=t.cfRules[0].colorScale;if(!n||n.cfvos.length!==n.colors.length||n.cfvos.length<2||n.cfvos.length>3)return;let r=[];for(let e=0;e<n.cfvos.length;e++)r.push({color:xM(vM(n.colors[e])||`#FFFFFF`),type:aM[n.cfvos[e].type],value:n.cfvos[e].value});let i=r[0],a=r.length===2?r[1]:r[2],o=r.length===3?r[1]:void 0;return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:`ColorScaleRule`,minimum:i,midpoint:o,maximum:a}}}function BM(e,t,n){let r=t.cfRules[0].iconSet;if(!r)return;let i=r.cfvos,a=r.cfIcons;if(i.length<3||a&&a.length<3)return;i.length>3&&(i=[i[0],i[Math.floor(i.length/2)],i[i.length-1]]),a&&a.length>3&&(a=[a[0],a[Math.floor(a.length/2)],a[a.length-1]]);let o=[];for(let e=1;e<=2;e++){let t=aM[i[e].type];if(t===`value`)return;o.push({value:i[e].value||``,operator:i[e].gte?`ge`:`gt`,type:t})}let s={lower:a?VM(a[0].iconSet,a[0].iconId):VM(r.iconSet,0),middle:a?VM(a[1].iconSet,a[1].iconId):VM(r.iconSet,1),upper:a?VM(a[2].iconSet,a[2].iconId):VM(r.iconSet,2)};r.reverse&&(s={upper:s.lower,middle:s.middle,lower:s.upper});for(let e of Object.keys(s))if(!s[e])switch(n.generateNotSupportedWarning(`IconSets with empty icons`),e){case`upper`:s[e]=Lj.dots.good;break;case`middle`:s[e]=Lj.dots.neutral;break;case`lower`:s[e]=Lj.dots.bad;break}return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:`IconSetRule`,icons:s,upperInflectionPoint:o[1],lowerInflectionPoint:o[0]}}}function VM(e,t){let n=oM[e];return n?t===0?Lj[n].bad:t===1?Lj[n].neutral:Lj[n].good:``}function HM(e,t,n){if(e.cfRules.length>1&&n.generateNotSupportedWarning(`Multiple rules conditional formats`),Zj.includes(e.cfRules[0].type)||n.generateNotSupportedWarning(`Conditional format type`,e.cfRules[0].type),e.cfRules[0].dxfId){let r=t[e.cfRules[0].dxfId];r.border&&n.generateNotSupportedWarning(`Borders in conditional formats`),r.alignment&&n.generateNotSupportedWarning(`Alignment in conditional formats`),r.numFmt&&n.generateNotSupportedWarning(`Num formats in conditional formats`)}}function UM(e){switch(e){case`isNotEmpty`:return`notContainsBlanks`;case`isEmpty`:return`containsBlanks`;case`notContainsText`:return`notContainsBlanks`;case`containsText`:return`containsText`;case`beginsWithText`:return`beginsWith`;case`endsWithText`:return`endsWith`;case`isGreaterThan`:return`greaterThan`;case`isGreaterOrEqualTo`:return`greaterThanOrEqual`;case`isLessThan`:return`lessThan`;case`isLessOrEqualTo`:return`lessThanOrEqual`;case`isBetween`:return`between`;case`isNotBetween`:return`notBetween`;case`isEqual`:return`equal`;case`isNotEqual`:return`notEqual`;case`customFormula`:return``}}function WM(e){switch(typeof e){case`boolean`:return`b`;case`string`:return`str`;case`number`:return`n`;default:return}}function GM(e){return Math.round(Yf*e*100)/100}function KM(e){return Math.round(Xf*e*100)/100}function qM(e){return e&&Math.round(e/Yf*100)/100}function JM(e){return e&&Math.round(e/Xf*100)/100}function YM(e,t,n,r,i){let a=n?e.styles[n]:{},o=r?e.formats[r]:void 0,s={font:{size:a?.fontSize||Ve,color:{rgb:a?.textColor?a.textColor:`000000`},family:2,name:`Arial`},fill:a?.fillColor?{fgColor:{rgb:a.fillColor}}:{reservedAttribute:`none`},numFmt:o?{format:o,id:0}:void 0,border:i||0,alignment:{horizontal:a.align,vertical:a.verticalAlign?nM[a.verticalAlign]:void 0,wrapText:a.wrapping===`wrap`||t?.includes(`
|
|
835
835
|
`)?!0:void 0,shrinkToFit:a.wrapping===`clip`?!0:void 0}};return s.font.strike=!!a?.strikethrough||void 0,s.font.underline=!!a?.underline||void 0,s.font.bold=!!a?.bold||void 0,s.font.italic=!!a?.italic||void 0,s}function XM(e,t){let n=ZM(t.numFmt,e.numFmts);return eN({fontId:eN(t.font,e.fonts),fillId:eN(t.fill,e.fills),borderId:t.border,numFmtId:n,alignment:{vertical:t.alignment.vertical,horizontal:t.alignment.horizontal,wrapText:t.alignment.wrapText,shrinkToFit:t.alignment.shrinkToFit}},e.styles)}function ZM(e,t){if(!e)return 0;let n=fM[e.format];return n||=eN(e,t)+164,n}function QM(e,t,n){let r=e.find(e=>e.path===t),i;return r?(i=`rId${(r.rels.length+1).toString()}`,r.rels.push({...n,id:i})):(i=`rId1`,e.push({path:t,rels:[{...n,id:i}]})),i}let $M=new WeakMap;function eN(e,t){let n=$M.get(t);if(!n){n=new Map;for(let e=0;e<t.length;e++){let r=_c(t[e]);n.set(r,e)}$M.set(t,n)}let r=_c(e);if(n.has(r))return n.get(r);let i=t.length;return t.push(e),n.set(r,i),i}function tN(e,t){let n=t.chartIds.findIndex(t=>t===e);return n===-1?(t.chartIds.push(e),t.chartIds.length):n+1}let nN=[];function rN(e){let t=nN.findIndex(t=>t===e);return t===-1?(nN.push(e),nN.length):t+1}function iN(e){return Math.round(e*914400/96)}function aN(e,t,n){let r=e,i;({xc:r,sheetName:i}=jc(e));let a;if(i){let e=n.sheets.findIndex(e=>cl(e.name,i));if(e<0)throw Error(`Unable to find a sheet with the name `+i);a=e}else a=Number(t);let o=ws(r);return o.right===void 0&&(o.right=n.sheets[a].colNumber),o.bottom===void 0&&(o.bottom=n.sheets[a].rowNumber),(o.right-o.left+1)*(o.bottom-o.top+1)}function oN(e){return Math.round(e*96/914400)}function sN(e,t){let n=0;for(let r=0;r<e;r++){let e=t.cols.find(e=>r>=e.min&&r<=e.max);e?.width?n+=e.width:t.sheetFormat?.defaultColWidth?n+=t.sheetFormat.defaultColWidth:n+=Zf}return n/Xf}function cN(e,t){let n=0;for(let r=0;r<e;r++){let e=t.rows.find(e=>e.index-1===r);e?.height?n+=e.height:t.sheetFormat?.defaultRowHeight?n+=t.sheetFormat.defaultRowHeight:n+=Qf}return n/Yf}function lN(e){return Object.keys(gM).find(t=>gM[t]===e)}function uN(e){return Object.keys(_M).find(t=>_M[t]===e)}function dN(e){let t=1;return e.figures.map(n=>fN(n,(t++).toString(),e)).filter(C)}function fN(e,t,n){let r,i,a,o,s;if(e.anchors.length===1)({col:r,row:i,offset:a}=vN(e.anchors[0])),s=oN(e.figureSize.cx),o=oN(e.figureSize.cy);else{({col:r,row:i,offset:a}=vN(e.anchors[0]));let{x:t,y:c}=yN(e.anchors[0],n),{x:l,y:u}=yN(e.anchors[1],n);s=l-t,o=u-c}let c={id:t,col:r,row:i,offset:a};if(pN(e.data))return{...c,width:s,height:o,tag:`chart`,data:hN(e.data)};if(mN(e.data))return{...c,width:oN(e.data.size.cx),height:oN(e.data.size.cy),tag:`image`,data:{path:e.data.imageSrc,mimetype:e.data.mimetype}}}function pN(e){return`dataSets`in e&&e.dataSets.length>0}function mN(e){return`imageSrc`in e}function hN(e){let t=e.dataSets.some(e=>`reference`in(e.label??{})),n=e.labelRange?gN(e.labelRange,t):void 0,r=e.dataSets.map(e=>{let n;return e.label&&`text`in e.label&&(n=e.label.text),{dataRange:gN(e.range,t),label:n,backgroundColor:e.backgroundColor,trend:_N(e.trend)}});e.type===`pie`&&r.reverse();let i={range:r,dataSetsHaveTitle:t,auxiliaryRange:n,title:e.title??{text:``},background:vM({rgb:e.backgroundColor})||`#FFFFFF`,legendPosition:e.legendPosition,stacked:e.stacked||!1,aggregated:!1,cumulative:e.cumulative||!1,labelsAsText:!1,horizontal:e.horizontal,isDoughnut:e.isDoughnut,pieHolePercentage:e.pieHolePercentage};try{return fO.get(e.type).getChartDefinitionFromContextCreation(i)}catch{return}}function gN(e,t){let{sheetName:n,xc:r}=jc(e),i=ws(r);if(t&&i.bottom!==void 0&&i.right!==void 0){let e=i.bottom-i.top+1,t=i.right-i.left+1;e===1?i={...i,left:i.left-1}:t===1&&(i={...i,top:i.top-1})}return Mc(n,As(i))}function _N(e){if(!(!e||!e.type))return{type:e.type===`linear`?`polynomial`:lM[e.type],order:e.type===`linear`?1:e.order,color:e.color,window:e.window||2,display:!0}}function vN(e){let t={x:oN(e.colOffset)-1,y:oN(e.rowOffset)-1};return{col:e.col,row:e.row,offset:t}}function yN(e,t){return{x:sN(e.col,t)+oN(e.colOffset),y:cN(e.row,t)+oN(e.rowOffset)}}function bN(e,t){let n=[],r=1;for(let i of e)if(i)switch(i.type){case`time`:t.generateNotSupportedWarning(`Time data validation rules`);break;case`textLength`:t.generateNotSupportedWarning(`Text length data validation rules`);break;case`whole`:t.generateNotSupportedWarning(`Whole number data validation rules`);break;case`decimal`:let e=xN(r++,i);n.push(e);break;case`list`:let a=SN(r++,i);n.push(a);break;case`date`:if(i.operator===`notEqual`){t.generateNotSupportedWarning(`Not equal date data validation rules`);break}let o=CN(r++,i);n.push(o);break;case`custom`:let s=wN(r++,i);n.push(s);break}return n}function xN(e,t){let n=[Wj(t.formula1.toString())];return t.formula2&&n.push(Wj(t.formula2.toString())),{id:e.toString(),ranges:t.sqref,isBlocking:t.errorStyle!==`warning`,criterion:{type:gM[t.operator],values:n}}}function SN(e,t){let n=t.formula1.toString(),r=Tc.test(n);return{id:e.toString(),ranges:t.sqref,isBlocking:t.errorStyle!==`warning`,criterion:{type:r?`isValueInRange`:`isValueInList`,values:r?[n]:n.replaceAll(`"`,``).split(`,`),displayStyle:`arrow`}}}function CN(e,t){let n,r=[Wj(t.formula1.toString())];return t.formula2?(r.push(Wj(t.formula2.toString())),n={type:_M[t.operator],values:ps(r,D)}):n={type:_M[t.operator],values:ps(r,D),dateValue:`exactDate`},{id:e.toString(),ranges:t.sqref,isBlocking:t.errorStyle!==`warning`,criterion:n}}function wN(e,t){return{id:e.toString(),ranges:t.sqref,isBlocking:t.errorStyle!==`warning`,criterion:{type:`customFormula`,values:[Wj(t.formula1.toString())]}}}let TN=new RegExp(/'?\[([0-9]*)\](.*)'?!(\$?[a-zA-Z]*\$?[0-9]*)/g),EN=new RegExp(/SUBTOTAL\(([0-9]*),/g),DN=new RegExp(yc.source,`ig`);function ON(e,t){let n=kN(e);for(let r of e.rows.map(e=>e.cells).flat())r?.formula&&(r.formula.content=r.formula.sharedIndex!==void 0&&!r.formula.content?`=`+jN(r.xc,n[r.formula.sharedIndex]):`=`+r.formula.content,r.formula.content=AN(r.formula.content,t))}function kN(e){let t={};for(let n of e.rows)for(let e of n.cells)e.formula&&e.formula.sharedIndex!==void 0&&e.formula.content&&(t[e.formula.sharedIndex]={refCellXc:e.xc,formula:e.formula.content});return t}function AN(e,t){return e=e.replace(`_xlfn.`,``),e=e.replace(/#REF!/g,`#REF`),e=e.replace(EN,(e,t)=>{let n=uM[t];return n?n+`(`:e}),e=e.replace(TN,(e,n,r,i)=>{n=Number(n)-1,i=i.replace(/\$/g,``);let a=t.externalBooks[n]?.sheetNames.findIndex(e=>cl(e,r))??-1;if(a===-1)return e;let o=t.externalBooks[n].datasets.find(e=>e.sheetId===a)?.data;if(!o)return e;let s=o&&o[i];return(Number(s)?s:`"${s}"`)||e}),e}function jN(e,t){let n=ir(t.refCellXc),r=t.formula.slice(),i;do if(i=DN.exec(r),i){let t=ir(i[0].replace(`$`,``)),a=ir(e),o={colFixed:i[0].startsWith(`$`),rowFixed:i[0].includes(`$`,1)},s={col:a.col-n.col,row:a.row-n.row},c={col:o.colFixed?t.col:t.col+s.col,row:o.rowFixed?t.row:t.row+s.row};r=r.slice(0,i.index)+T(c.col,c.row,o)+r.slice(i.index+i[0].length)}while(i);return r}function MN(e,t){return e.sheets.map(n=>{ON(n,e);let r=zN(n),i=n.sheetViews[0],a=BN(n,`ROW`,r[1]),o=BN(n,`COL`,r[0]);return{id:n.sheetName,areGridLinesVisible:i?i.showGridLines:!0,name:n.sheetName,colNumber:r[0],rowNumber:r[1],...IN(n,e,r,t),merges:n.merges,cols:NN(n,r[0],o),rows:PN(n,r[1],a),conditionalFormats:LM(n.cfs,e.dxfs,t),dataValidationRules:bN(n.dataValidations,t),figures:dN(n),isVisible:n.isVisible,panes:i?{xSplit:i.pane.xSplit,ySplit:i.pane.ySplit}:{xSplit:0,ySplit:0},tables:[],headerGroups:{COL:o,ROW:a},color:vM(n.sheetProperties?.tabColor)}})}function NN(e,t,n){let r={};for(let i=1;i<t+1;i++){let t=e.cols.find(e=>e.min<=i&&i<=e.max),a;a=t&&t.width?t.width:e.sheetFormat?.defaultColWidth?e.sheetFormat.defaultColWidth:Zf;let o=i-1,s=n.some(e=>e.isFolded&&e.start<=o&&o<=e.end);r[o]={size:JM(a),isHidden:!s&&t?.hidden}}return r}function PN(e,t,n){let r={};for(let i=1;i<t+1;i++){let t=e.rows.find(e=>e.index===i),a;a=t&&t.height?t.height:e.sheetFormat?.defaultRowHeight?e.sheetFormat.defaultRowHeight:Qf;let o=i-1,s=n.some(e=>e.isFolded&&e.start<=o&&o<=e.end);r[o]={size:qM(a),isHidden:!s&&t?.hidden}}return r}function FN(e){return e.map(Wt)}function IN(e,t,n,r){let i={},a={},o={},s={},c=FN(t.sharedStrings),l=e.hyperlinks.reduce((e,t)=>(e[t.xc]=t,e),{});for(let n of e.rows)for(let e of n.cells)i[e.xc]=LN(e,l,c,r),e.styleIndex&&(a[e.xc]=e.styleIndex+1,o[e.xc]=t.styles[e.styleIndex].numFmtId+1,s[e.xc]=t.styles[e.styleIndex].borderId+1);for(let r of e.rows.filter(e=>e.styleIndex))for(let e=1;e<=n[0];e++){let n=T(e-1,r.index-1);a[n]??=r.styleIndex+1,s[n]??=t.styles[r.styleIndex].borderId+1,o[n]??=t.styles[r.styleIndex].numFmtId+1}for(let r of e.cols.filter(e=>e.styleIndex))for(let e=r.min;e<=Math.min(r.max,n[0]);e++)for(let i=1;i<=n[1];i++){let n=T(e-1,i-1);a[n]??=r.styleIndex+1,s[n]??=t.styles[r.styleIndex].borderId+1,o[n]??=t.styles[r.styleIndex].numFmtId+1}return{cells:i,styles:a,formats:o,borders:s}}function LN(e,t,n,r){let i;switch(e.type){case`sharedString`:i=n[parseInt(e.value,10)];break;case`boolean`:i=Number(e.value)?`TRUE`:`FALSE`;break;case`date`:case`error`:case`inlineStr`:case`number`:case`str`:i=e.value;break}return i&&t[e.xc]&&(i=RN(t[e.xc],i,r)),e.formula&&(i=e.formula.content),i}function RN(e,t,n){let r=e.display||t;return!e.relTarget&&!e.location&&n.generateNotSupportedWarning(`Badly formatted hyperlink`),Ct(r,e.relTarget?e.relTarget:Dt(jc(e.location).sheetName))}function zN(e){let t=[0,0];for(let n of e.rows)t[0]=Math.max(t[0],$t(n.cells.map(e=>ir(e.xc).col))),t[1]=Math.max(t[1],n.index);for(let n of e.figures)t[0]=Math.max(t[0],n.anchors[n.anchors.length-1]?.col??0),t[1]=Math.max(t[1],n.anchors[n.anchors.length-1]?.row??0);return t[0]=Math.max(t[0]+5,30),t[1]=Math.max(t[1]+5,100),t}function BN(e,t,n){let r=e?.sheetProperties?.outlinePr,i=[],a=0;for(let o=0;o<n;o++){let n=HN(e,t,o)?.outlineLevel||0;if(n>a){let n=(t===`ROW`?r?.summaryBelow:r?.summaryRight)??!0,a=VN(e,t,o,n);a&&i.push(a)}a=n}return i}function VN(e,t,n,r){let i=HN(e,t,n),a=i?.outlineLevel;if(!a||!a)return;let o=a,s=n,c=i;for(;c&&o>=a;)s++,c=HN(e,t,s),o=c?.outlineLevel||0;let l=n,u=s-1,d=(r?HN(e,t,u+1):HN(e,t,l-1))?.collapsed||!1;return{start:l-1,end:u-1,isFolded:d}}function HN(e,t,n){return t===`COL`?e.cols.find(e=>e.min<=n&&n<=e.max):e.rows.find(e=>e.index===n)}function UN(e,t){for(let n of t.sheets){let t=e.sheets.find(e=>e.name===n.sheetName);if(t){t.tables||=[];for(let e of n.tables)t.tables.push({range:e.ref,config:WN(e)});for(let e of n.pivotTables)t.tables.push({range:e.location.ref,config:GN(e)})}}KN(e.sheets,t.sheets)}function WN(e){let t=e.style?.name||``;return{hasFilters:e.autoFilter!==void 0,numberOfHeaders:e.headerRowCount,totalRow:e.totalsRowCount>0,firstColumn:e.style?.showFirstColumn||!1,lastColumn:e.style?.showLastColumn||!1,bandedRows:e.style?.showRowStripes||!1,bandedColumns:e.style?.showColumnStripes||!1,styleId:fj[t]?t:QA.styleId}}function GN(e){return{hasFilters:!1,numberOfHeaders:e.location.firstDataRow,totalRow:e.rowGrandTotals,firstColumn:!0,lastColumn:e.style?.showLastColumn||!1,bandedRows:e.style?.showRowStripes||!1,bandedColumns:e.style?.showColStripes||!1,styleId:QA.styleId}}function KN(e,t){let n=null;for(let r of e){let i=t.find(e=>cl(e.sheetName,r.name)).tables;if(!(!i||i.length===0)){n||=qN(e);for(let t of i)for(let i in n){let a=e.find(e=>e.id===i);for(let e in n[i]){let o=n[i][e];for(let s=o.length-3;s>=0;s-=2){let o=n[i][e][s];if(!o.endsWith(t.name))continue;let c=n[i][e][s+1],l=JN(r.id===a.id?``:r.name+`!`,c,t,e);n[i][e][s+2]=o.slice(0,o.indexOf(t.name))+l+n[i][e][s+2],n[i][e].splice(s,2)}}}}}if(n)for(let t in n){let r=e.find(e=>e.id===t);for(let e in n[t]){let i=n[t][e];if(i.length===1){r.cells[e]=i[0];continue}let a=``;for(let e=0;e<i.length;e+=2)a+=i[e]+`[`+i[e+1]+`]`;a+=i[i.length-1],r.cells[e]=a}}}function qN(e){let t={};for(let n of e)for(let e in n.cells){let r=n.cells[e];if(!r||!r.startsWith(`=`))continue;let i=r.indexOf(`[`);if(i===-1)continue;let a=[],o=r.slice(0,i),s=``,c=1,l=0,u=i;for(let e=i+1;e<r.length;e++){if(r[e]===`[`){c===0&&(o=r.slice(l,e),u=e),c++;continue}r[e]===`]`&&(c--,c===0&&(s=r.slice(u+1,e),a.push(o),a.push(s),l=e+1))}a.length&&(t[n.id]||(t[n.id]={}),a.push(r.slice(l)),t[n.id][e]=[...a])}return t}function JN(e,t,n,r){let i=t.split(`,`).map(e=>e.trim()),a=Ts(n.ref),o=[],s=[],c=[];for(let e of i)if(YN(e).startsWith(`#`)){let t=YN(e);switch(c.push(t),t){case`#All`:s.push(a.top,a.bottom);break;case`#Data`:let e=n.headerRowCount?a.top+n.headerRowCount:a.top,t=n.totalsRowCount?a.bottom-n.totalsRowCount:a.bottom;s.push(e,t);break;case`#This Row`:s.push(ir(r).row);break;case`#Headers`:if(!n.headerRowCount)return k.InvalidReference;s.push(a.top);break;case`#Totals`:if(!n.totalsRowCount)return k.InvalidReference;s.push(a.bottom);break}}else{let t=e.split(`:`).map(e=>e.trim()).map(YN);if(o.length)return k.InvalidReference;let r=n.cols.findIndex(e=>e.name===t[0]);if(r===-1)return k.InvalidReference;if(o.push(r+a.left),t[1]){let e=n.cols.findIndex(e=>e.name===t[1]);if(e===-1)return k.InvalidReference;o.push(e+a.left)}}if(!XN(c))return k.InvalidReference;if(s.length===0){let e=n.headerRowCount?a.top+n.headerRowCount:a.top,t=n.totalsRowCount?a.bottom-n.totalsRowCount:a.bottom;s.push(e,t)}return o.length===0&&o.push(a.left,a.right),e+As({top:Math.min(...s),left:Math.min(...o),bottom:Math.max(...s),right:Math.max(...o)})}function YN(e){return e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,e.length-1):e}function XN(e){return e.length<2?!0:e.length>2?!1:e.includes(`#Data`)&&e.includes(`#Totals`)?!0:!!(e.includes(`#Headers`)&&e.includes(`#Data`))}var ZN=class{value;constructor(e){this.value=e}asString(){return Hj(String(this.value))}asBool(){return this.value===`true`?!0:this.value===`false`?!1:!!Number(this.value)}asNum(){return Number(this.value)}},QN=class{rootFile;xlsxFileStructure;warningManager;relationships;currentFile=void 0;constructor(e,t,n){this.rootFile=e,this.currentFile=e.file.fileName,this.xlsxFileStructure=t,this.warningManager=n,this.relationships={},e.rels&&this.extractRelationships(e.rels).map(e=>{this.relationships[e.id]=e})}extractRelationships(e){return this.mapOnElements({parent:e.xml,query:`Relationship`},e=>({id:this.extractAttr(e,`Id`,{required:!0}).asString(),target:this.extractAttr(e,`Target`,{required:!0}).asString(),type:this.extractAttr(e,`Type`,{required:!0}).asString()}))}getListOfXMLFiles(){return Object.entries(this.xlsxFileStructure).filter(([e])=>e!==`images`).map(([e,t])=>t).flat().filter(C)}mapOnElements(e,t){let n=[],r=this.currentFile,i;if(i=e.children?this.querySelector(e.parent,e.query)?.children||[]:this.querySelectorAll(e.parent,e.query),i)for(let e of i)try{n.push(t(e))}catch(t){this.catchErrorOnElement(t,e)}return this.currentFile=r,n}catchErrorOnElement(e,t){let n=t?`Error when parsing an element <${t.tagName}> of file ${this.currentFile}, skip this element. \n${e.stack}`:`Error when parsing file ${this.currentFile}.`;this.warningManager.addParsingWarning([n,e.message].join(`
|
|
836
|
-
`))}extractAttr(e,t,n){let r=e.attributes[t];r||this.handleMissingValue(e,`attribute "${t}"`,n);let i=r?.value?r.value:n?.default;return i===void 0?void 0:new ZN(i)}extractTextContent(e,t){if(t?.default!==void 0&&typeof t.default!=`string`)throw Error(`extractTextContent default value should be a string`);let n=e?.attributes[`xml:space`]?.value===`preserve`,r=e?.textContent;return(!e||r===null)&&this.handleMissingValue(e,`text content`,t),r&&=n?r:r.trim(),r?Hj(r):t?.default}extractChildAttr(e,t,n,r){let i;i=typeof t==`number`?e.children[t]:this.querySelector(e,t),i||this.handleMissingValue(e,typeof t==`number`?`child at index ${t}`:`child <${t}>`,r);let a=i?this.extractAttr(i,n,r)?.asString():r?.default;return a===void 0?void 0:new ZN(a)}extractChildTextContent(e,t,n){if(n?.default!==void 0&&typeof n.default!=`string`)throw Error(`extractTextContent default value should be a string`);let r=this.querySelector(e,t);return r||this.handleMissingValue(e,`child <${t}>`,n),r?this.extractTextContent(r,n):n?.default}handleMissingValue(e,t,n){if(n?.required)if(n?.default!==void 0)this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${n.default}`);else throw Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`)}extractColor(e,t,n){if(!e)return n?{rgb:n}:void 0;let r=this.extractAttr(e,`theme`)?.asString(),i;if(r!==void 0){if(!t||!t.clrScheme)throw Error(`Color referencing a theme but no theme was provided`);i=this.getThemeColor(r,t.clrScheme)}else i=this.extractAttr(e,`rgb`)?.asString(),i=i===`FF000000`?void 0:i;return{rgb:i||n,auto:this.extractAttr(e,`auto`)?.asBool(),indexed:this.extractAttr(e,`indexed`)?.asNum(),tint:this.extractAttr(e,`tint`)?.asNum()}}getTargetXmlFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.getListOfXMLFiles().find(e=>e.file.fileName.endsWith(t));if(!n||!n.file)throw Error(`Cannot find target file`);return n}getTargetImageFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.xlsxFileStructure.images.find(e=>e.fileName.endsWith(t));if(!n)throw Error(`Cannot find target file`);return n}querySelector(e,t){let n=FO(t);return e.querySelector(n)}querySelectorAll(e,t){let n=FO(t);return e.querySelectorAll(n)}getThemeColor(e,t){switch(e){case`0`:return`FFFFFF`;case`1`:return`000000`;case`2`:return t[3].value;case`3`:return t[2].value;default:return t[e].value}}processRelationshipTargetName(e){return e.replace(/\.+\//,``)}},$N=class extends QN{getTheme(){return{clrScheme:this.mapOnElements({query:`a:clrScheme`,parent:this.rootFile.file.xml,children:!0},e=>({name:e.tagName,value:this.extractChildAttr(e,0,`val`,{required:!0,default:Vf}).asString(),lastClr:this.extractChildAttr(e,0,`lastClr`,{default:Vf}).asString()}))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`si`},e=>this.mapOnElements({parent:e,query:`t`},e=>this.extractTextContent(e)||``).join(``))}},eP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}extractConditionalFormattings(){let e=this.mapOnElements({parent:this.rootFile.file.xml,query:`worksheet > conditionalFormatting`},e=>({sqref:this.extractAttr(e,`sqref`,{required:!0}).asString().split(` `),pivot:this.extractAttr(e,`pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:`extLst x14:conditionalFormatting`},e=>({sqref:this.extractChildTextContent(e,`xm:sqref`,{required:!0}).split(` `),pivot:this.extractAttr(e,`xm:pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:`cfRule, x14:cfRule`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),priority:this.extractAttr(e,`priority`,{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:this.extractAttr(e,`dxfId`)?.asNum(),stopIfTrue:this.extractAttr(e,`stopIfTrue`)?.asBool(),aboveAverage:this.extractAttr(e,`aboveAverage`)?.asBool(),percent:this.extractAttr(e,`percent`)?.asBool(),bottom:this.extractAttr(e,`bottom`)?.asBool(),operator:this.extractAttr(e,`operator`)?.asString(),text:this.extractAttr(e,`text`)?.asString(),timePeriod:this.extractAttr(e,`timePeriod`)?.asString(),rank:this.extractAttr(e,`rank`)?.asNum(),stdDev:this.extractAttr(e,`stdDev`)?.asNum(),equalAverage:this.extractAttr(e,`equalAverage`)?.asBool(),dataBar:this.extractCfDataBar(e,t)}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:`formula`},e=>this.extractTextContent(e,{required:!0}))}extractCfColorScale(e,t){let n=this.querySelector(e,`colorScale`);if(n)return{colors:this.mapOnElements({parent:n,query:`color`},e=>this.extractColor(e,t,`ffffff`)),cfvos:this.extractCFVos(n)}}extractCfDataBar(e,t){let n=this.querySelector(e,`dataBar`);if(n)return{color:this.extractColor(n.querySelector(`color`),t,`EFF7FF`),cfvos:this.extractCFVos(n)}}extractCfIconSet(e){let t=this.querySelector(e,`iconSet, x14:iconSet`);if(t)return{iconSet:this.extractAttr(t,`iconSet`,{default:`3TrafficLights1`}).asString(),showValue:this.extractAttr(t,`showValue`,{default:!0}).asBool(),percent:this.extractAttr(t,`percent`,{default:!0}).asBool(),reverse:this.extractAttr(t,`reverse`)?.asBool(),custom:this.extractAttr(t,`custom`)?.asBool(),cfvos:this.extractCFVos(t),cfIcons:this.extractCfIcons(t)}}extractCfIcons(e){let t=this.mapOnElements({parent:e,query:`cfIcon, x14:cfIcon`},e=>({iconSet:this.extractAttr(e,`iconSet`,{required:!0}).asString(),iconId:this.extractAttr(e,`iconId`,{required:!0}).asNum()}));return t.length===0?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:`cfvo, x14:cfvo`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),gte:this.extractAttr(e,`gte`,{default:!0})?.asBool(),value:e.attributes.val?this.extractAttr(e,`val`)?.asString():this.extractChildTextContent(e,`f, xm:f`)}))}},tP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}extractDataValidations(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`worksheet > dataValidations > dataValidation`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),operator:this.extractAttr(e,`operator`,{default:`between`})?.asString(),sqref:this.extractAttr(e,`sqref`,{required:!0}).asString().split(` `),errorStyle:this.extractAttr(e,`errorStyle`)?.asString(),formula1:this.extractDataValidationFormula(e,1)[0],formula2:this.extractDataValidationFormula(e,2)[0],showErrorMessage:this.extractAttr(e,`showErrorMessage`)?.asBool(),errorTitle:this.extractAttr(e,`errorTitle`)?.asString(),error:this.extractAttr(e,`error`)?.asString(),showInputMessage:this.extractAttr(e,`showInputMessage`)?.asBool(),promptTitle:this.extractAttr(e,`promptTitle`)?.asString(),prompt:this.extractAttr(e,`prompt`)?.asString(),allowBlank:this.extractAttr(e,`allowBlank`)?.asBool()}))}extractDataValidationFormula(e,t){return this.mapOnElements({parent:e,query:`formula${t}`},e=>this.extractTextContent(e,{required:!0}))}},nP=class extends QN{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`c:chartSpace`},e=>{let t=this.getChartType(e);if(!cM[t])throw Error(`Unsupported chart type ${t}`);if(cM[t]===`combo`)return this.extractComboChart(e);let n=this.mapOnElements({parent:e,query:`c:chart > c:title a:t`},e=>e.textContent||``).join(``),r=this.extractChildAttr(e,`c:grouping`,`val`,{default:`clustered`}).asString(),i=this.extractChildAttr(e,`c:barDir`,`val`,{default:`col`}).asString(),a=this.extractChildAttr(e,`c:holeSize`,`val`,{default:`0`}).asNum();return{title:{text:n},type:cM[t],dataSets:this.extractChartDatasets(this.querySelectorAll(e,`c:${t}`),t),labelRange:this.extractLabelRange(t,e),backgroundColor:this.extractChildAttr(e,`c:chartSpace > c:spPr a:srgbClr`,`val`,{default:`ffffff`}).asString(),legendPosition:sM[this.extractChildAttr(e,`c:legendPos`,`val`,{default:`none`}).asString()],stacked:r===`stacked`,fontColor:`000000`,horizontal:i===`bar`,isDoughnut:a>0,pieHolePercentage:a}})[0]}extractLabelRange(e,t){return e===`scatterChart`?this.extractChildTextContent(t,`c:ser c:strRef c:f`)||this.extractChildTextContent(t,`c:ser c:numRef c:f`):this.extractChildTextContent(t,`c:ser c:cat c:f`)}extractComboChart(e){let t=this.mapOnElements({parent:e,query:`c:title a:t`},e=>e.textContent||``).join(``),n=this.extractChildAttr(e,`c:grouping`,`val`,{default:`clustered`}).asString();return{title:{text:t},type:`combo`,dataSets:[...this.extractChartDatasets(this.querySelectorAll(e,`c:barChart`),`comboChart`),...this.extractChartDatasets(this.querySelectorAll(e,`c:lineChart`),`comboChart`)],labelRange:this.extractChildTextContent(e,`c:ser c:cat c:f`),backgroundColor:this.extractChildAttr(e,`c:chartSpace > c:spPr a:srgbClr`,`val`,{default:`ffffff`}).asString(),legendPosition:sM[this.extractChildAttr(e,`c:legendPos`,`val`,{default:`none`}).asString()],stacked:n===`stacked`,fontColor:`000000`}}extractChartDatasets(e,t){return Array.from(e).map(e=>t===`scatterChart`?this.extractScatterChartDatasets(e):this.mapOnElements({parent:e,query:`c:ser`},e=>{let t={},n=this.extractChildTextContent(e,`c:tx c:f`);if(n)t={reference:n};else{let n=this.extractChildTextContent(e,`c:tx c:v`);n&&(t={text:n})}let r=this.querySelectorAll(e,`c:spPr a:solidFill`),i=r.length?this.querySelector(r[0],`a:srgbClr`):void 0,a=i?i.getAttribute(`val`):void 0;return{label:t,range:this.extractChildTextContent(e,`c:val c:f`,{required:!0}),backgroundColor:a&&mn(a)?`${pn(a)}`:void 0,trend:this.extractChartTrendline(e)}})).flat()}extractChartTrendline(e){let t=this.querySelector(e,`c:trendline`);if(!t)return;let n=this.extractChildAttr(t,`c:trendlineType`,`val`),r=this.extractChildAttr(t,`a:solidFill a:srgbClr`,`val`);return{type:n?n.asString():void 0,order:this.extractChildAttr(t,`c:order`,`val`)?.asNum(),window:this.extractChildAttr(t,`c:period`,`val`)?.asNum(),color:r&&mn(r.asString())?`${pn(r.asString())}`:void 0}}extractScatterChartDatasets(e){return this.mapOnElements({parent:e,query:`c:ser`},e=>{let t={},n=this.querySelectorAll(e,`c:spPr a:solidFill a:srgbClr`),r=n.length?n[0].getAttribute(`val`):void 0,i=this.extractChildTextContent(e,`c:tx c:f`);if(i)t={reference:i};else{let n=this.extractChildTextContent(e,`c:tx c:v`);n&&(t={text:n})}return{label:t,range:this.extractChildTextContent(e,`c:yVal c:f`,{required:!0}),trend:this.extractChartTrendline(e),backgroundColor:r&&mn(r)?`${pn(r)}`:void 0}})}getChartType(e){let t=this.querySelector(e,`c:plotArea`);if(!t)throw Error(`Missing plot area in the chart definition.`);let n;for(let e of t.children){let t=NO(e.tagName);TO.some(e=>e===t)&&(n?n!==t&&(n=`comboChart`):n=t)}if(n)return n;throw Error(`Unknown chart type`)}};let rP=`oneCellAnchor`,iP=`twoCellAnchor`;var aP=class extends QN{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`xdr:wsDr`,children:!0},e=>{let t=NO(e.tagName),n=this.extractFigureAnchorsByType(e,t),r=this.querySelector(e,`c:chart`),i=this.querySelector(e,`a:blip`);if(!r&&!i)throw Error(`Only chart and image figures are currently supported.`);return{anchors:n,data:r?this.extractChart(r):this.extractImage(e),figureSize:t===rP?this.extractFigureSizeFromSizeTag(e,`xdr:ext`):void 0}})}extractFigureAnchorsByType(e,t){switch(t){case rP:return[this.extractFigureAnchor(`xdr:from`,e)];case iP:return[this.extractFigureAnchor(`xdr:from`,e),this.extractFigureAnchor(`xdr:to`,e)];default:throw Error(`${t} is not supported for xlsx drawings. `)}}extractFigureSizeFromSizeTag(e,t){let n=this.querySelector(e,t);if(!n)throw Error(`Missing size element '${t}'`);return{cx:this.extractAttr(n,`cx`,{required:!0}).asNum(),cy:this.extractAttr(n,`cy`,{required:!0}).asNum()}}extractFigureAnchor(e,t){let n=this.querySelector(t,e);if(!n)throw Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(n,`xdr:col`,{required:!0})),colOffset:Number(this.extractChildTextContent(n,`xdr:colOff`,{required:!0})),row:Number(this.extractChildTextContent(n,`xdr:row`,{required:!0})),rowOffset:Number(this.extractChildTextContent(n,`xdr:rowOff`,{required:!0}))}}extractChart(e){let t=this.extractAttr(e,`r:id`,{required:!0}).asString(),n=new nP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractChart();if(!n)throw Error(`Unable to extract chart definition`);return n}extractImage(e){let t=this.querySelector(e,`a:blip`),n=this.extractAttr(t,`r:embed`,{required:!0}).asString(),r=this.getTargetImageFile(this.relationships[n]);if(!r)throw Error(`Unable to extract image`);let i=r.fileName.split(`.`).at(-1),a=NO(e.tagName),o=a===iP?this.querySelector(e,`a:xfrm`):e,s=a===iP?`a:ext`:`xdr:ext`,c=this.extractFigureSizeFromSizeTag(o,s);return{imageSrc:r.imageSrc,mimetype:i?hM[i]:void 0,size:c}}},oP=class extends QN{getPivotTable(){return this.mapOnElements({query:`:root`,parent:this.rootFile.file.xml},e=>({name:this.extractAttr(e,`name`,{required:!0}).asString(),rowGrandTotals:this.extractAttr(e,`rowGrandTotals`,{default:!0}).asBool(),location:this.extractPivotLocation(e),style:this.extractPivotStyleInfo(e)}))[0]}extractPivotLocation(e){return this.mapOnElements({query:`location`,parent:e},e=>({ref:this.extractAttr(e,`ref`,{required:!0}).asString(),firstHeaderRow:this.extractAttr(e,`firstHeaderRow`,{required:!0}).asNum(),firstDataRow:this.extractAttr(e,`firstDataRow`,{required:!0}).asNum(),firstDataCol:this.extractAttr(e,`firstDataCol`,{required:!0}).asNum()}))[0]}extractPivotStyleInfo(e){return this.mapOnElements({query:`pivotTableStyleInfo`,parent:e},e=>({name:this.extractAttr(e,`name`,{required:!0}).asString(),showRowHeaders:this.extractAttr(e,`showRowHeaders`,{required:!0}).asBool(),showColHeaders:this.extractAttr(e,`showColHeaders`,{required:!0}).asBool(),showRowStripes:this.extractAttr(e,`showRowStripes`,{required:!0}).asBool(),showColStripes:this.extractAttr(e,`showColStripes`,{required:!0}).asBool(),showLastColumn:this.extractAttr(e,`showLastColumn`)?.asBool()}))[0]}},sP=class extends QN{getTable(){return this.mapOnElements({query:`table`,parent:this.rootFile.file.xml},e=>({displayName:this.extractAttr(e,`displayName`,{required:!0}).asString(),name:this.extractAttr(e,`name`)?.asString(),id:this.extractAttr(e,`id`,{required:!0}).asString(),ref:this.extractAttr(e,`ref`,{required:!0}).asString(),headerRowCount:this.extractAttr(e,`headerRowCount`,{default:1}).asNum(),totalsRowCount:this.extractAttr(e,`totalsRowCount`,{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}))[0]}extractTableCols(e){return this.mapOnElements({query:`tableColumn`,parent:e},e=>({id:this.extractAttr(e,`id`,{required:!0}).asString(),name:this.extractAttr(e,`name`,{required:!0}).asString(),colFormula:this.extractChildTextContent(e,`calculatedColumnFormula`)}))}extractTableStyleInfo(e){return this.mapOnElements({query:`tableStyleInfo`,parent:e},e=>({name:this.extractAttr(e,`name`)?.asString(),showFirstColumn:this.extractAttr(e,`showFirstColumn`)?.asBool(),showLastColumn:this.extractAttr(e,`showLastColumn`)?.asBool(),showRowStripes:this.extractAttr(e,`showRowStripes`)?.asBool(),showColumnStripes:this.extractAttr(e,`showColumnStripes`)?.asBool()}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:`autoFilter`,parent:e},e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,`ref`,{required:!0}).asString()}))[0]}extractFilterColumns(e){return this.mapOnElements({query:`tableColumn`,parent:e},t=>({colId:this.extractAttr(e,`colId`,{required:!0}).asNum(),hiddenButton:this.extractAttr(e,`hiddenButton`,{default:!1}).asBool(),filters:this.extractSimpleFilter(t)}))}extractSimpleFilter(e){return this.mapOnElements({query:`filter`,parent:e},e=>({val:this.extractAttr(e,`val`,{required:!0}).asString()}))}},cP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}getSheet(){return this.mapOnElements({query:`worksheet`,parent:this.rootFile.file.xml},e=>{let t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),sheetProperties:this.extractSheetProperties(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),dataValidations:this.extractDataValidations(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:this.extractTables(e),pivotTables:this.extractPivotTables(),isVisible:t.state===`visible`}})[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:`sheetView`},e=>{let t=this.querySelector(e,`pane`);return{tabSelected:this.extractAttr(e,`tabSelected`,{default:!1}).asBool(),showFormulas:this.extractAttr(e,`showFormulas`,{default:!1}).asBool(),showGridLines:this.extractAttr(e,`showGridLines`,{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,`showRowColHeaders`,{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,`xSplit`,{default:0}).asNum():0,ySplit:t?this.extractAttr(t,`ySplit`,{default:0}).asNum():0}}})}extractSheetName(){let e=Bj(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find(t=>t.target===e).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,`sheet`))if(e.attributes[`r:id`].value===t)return e.attributes.name.value;throw Error(`Missing sheet name`)}getSheetWorkbookInfo(){let e=Bj(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find(t=>t.target===e).id,n=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:`sheet`},e=>({relationshipId:this.extractAttr(e,`r:id`,{required:!0}).asString(),sheetId:this.extractAttr(e,`sheetId`,{required:!0}).asString(),sheetName:this.extractAttr(e,`name`,{required:!0}).asString(),state:this.extractAttr(e,`state`,{default:`visible`}).asString()})).find(e=>e.relationshipId===t);if(!n)throw Error(`Cannot find corresponding workbook sheet`);return n}extractConditionalFormats(){return new eP(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractDataValidations(){return new tP(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractDataValidations()}extractFigures(e){return this.mapOnElements({parent:e,query:`drawing`},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new aP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractFigures()})[0]||[]}extractTables(e){return this.mapOnElements({query:`tablePart`,parent:e},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new sP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).getTable()})}extractPivotTables(){try{return Object.values(this.relationships).filter(e=>e.type.endsWith(`pivotTable`)).map(e=>new oP(this.getTargetXmlFile(e),this.xlsxFileStructure,this.warningManager).getPivotTable())}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:`mergeCell`},e=>this.extractAttr(e,`ref`,{required:!0}).asString())}extractSheetFormat(e){let t=this.querySelector(e,`sheetFormatPr`);if(t)return{defaultColWidth:this.extractAttr(t,`defaultColWidth`,{default:`8.43`}).asNum(),defaultRowHeight:this.extractAttr(t,`defaultRowHeight`,{default:`12.75`}).asNum()}}extractSheetProperties(e){let t=this.querySelector(e,`sheetPr`);if(t)return{outlinePr:this.extractSheetOutlineProperties(t),tabColor:this.extractColor(this.querySelector(t,`tabColor`),this.theme)}}extractSheetOutlineProperties(e){let t=this.querySelector(e,`outlinePr`);if(t)return{summaryBelow:this.extractAttr(t,`summaryBelow`,{default:!0}).asBool(),summaryRight:this.extractAttr(t,`summaryRight`,{default:!0}).asBool()}}extractCols(e){return this.mapOnElements({parent:e,query:`cols col`},e=>({width:this.extractAttr(e,`width`)?.asNum(),customWidth:this.extractAttr(e,`customWidth`)?.asBool(),bestFit:this.extractAttr(e,`bestFit`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),min:this.extractAttr(e,`min`,{required:!0})?.asNum(),max:this.extractAttr(e,`max`,{required:!0})?.asNum(),styleIndex:this.extractAttr(e,`style`)?.asNum(),outlineLevel:this.extractAttr(e,`outlineLevel`)?.asNum(),collapsed:this.extractAttr(e,`collapsed`)?.asBool()}))}extractRows(e){let t=new Set;return this.mapOnElements({parent:e,query:`sheetData row`},e=>({index:this.extractAttr(e,`r`,{required:!0})?.asNum(),cells:this.extractCells(e,t),height:this.extractAttr(e,`ht`)?.asNum(),customHeight:this.extractAttr(e,`customHeight`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),styleIndex:this.extractAttr(e,`s`)?.asNum(),outlineLevel:this.extractAttr(e,`outlineLevel`)?.asNum(),collapsed:this.extractAttr(e,`collapsed`)?.asBool()}))}extractCells(e,t){return this.mapOnElements({parent:e,query:`c`},e=>{let n=this.extractAttr(e,`r`,{required:!0})?.asString(),r=this.extractCellFormula(e);if(r?.ref&&r.sharedIndex===void 0){let e=Ts(r.ref);for(let{col:r,row:i}of Ks(e)){let e=T(r,i);e!==n&&t.add(e)}}let i=t.has(n);return{xc:n,styleIndex:this.extractAttr(e,`s`)?.asNum(),type:Qj[this.extractAttr(e,`t`,{default:`n`})?.asString()],value:i?void 0:this.extractChildTextContent(e,`v`)??void 0,formula:i?void 0:r}})}extractCellFormula(e){let t=this.querySelector(e,`f`);if(!t)return;let n=this.extractTextContent(t),r=this.extractAttr(t,`si`)?.asNum(),i=this.extractAttr(t,`ref`)?.asString();if(!((n===void 0||n.trim()===``)&&r===void 0))return{content:n,sharedIndex:r,ref:i}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:`hyperlink`},e=>{let t=this.extractAttr(e,`r:id`)?.asString();return{xc:this.extractAttr(e,`ref`,{required:!0})?.asString(),location:this.extractAttr(e,`location`)?.asString(),display:this.extractAttr(e,`display`)?.asString(),relTarget:t?this.relationships[t].target:void 0}})}extractSharedFormulas(e){let t=this.querySelectorAll(e,`f[si][ref]`),n={};for(let e of t){let t=this.extractAttr(e,`si`,{required:!0}).asNum();n[t]=this.extractTextContent(e,{required:!0})}let r=[];for(let e=0;e<Object.keys(n).length;e++)n[e]?r.push(n[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),r.push(``));return r}},lP=class extends QN{theme;constructor(e,t,n){super(e.styles,e,t),this.theme=n}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`numFmt`},e=>this.extractNumFormats(e))}extractNumFormats(e){return{id:this.extractAttr(e,`numFmtId`,{required:!0}).asNum(),format:this.extractAttr(e,`formatCode`,{required:!0,default:``}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`font`},e=>this.extractFont(e))}extractFont(e){let t=this.extractChildAttr(e,`name`,`val`,{default:`Arial`}).asString(),n=this.extractChildAttr(e,`sz`,`val`,{default:Ve.toString()}).asNum(),r=this.extractColor(this.querySelector(e,`color`),this.theme),i=this.querySelector(e,`i`)||void 0,a=i&&i.attributes.val?.value!==`0`,o=this.querySelector(e,`b`)||void 0,s=o&&o.attributes.val?.value!==`0`,c=this.querySelector(e,`strike`)||void 0,l=c&&c.attributes.val?.value!==`0`,u=this.querySelector(e,`u`)||void 0;return{name:t,size:n,color:r,italic:a,bold:s,underline:u&&u.attributes.val?.value!==`none`,strike:l}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`fill`},e=>this.extractFill(e))}extractFill(e){let t=e.children[0];return t.tagName===`patternFill`?{patternType:t.attributes.patternType?.value,bgColor:this.extractColor(this.querySelector(t,`bgColor`),this.theme),fgColor:this.extractColor(this.querySelector(t,`fgColor`),this.theme)}:{patternType:`solid`,fgColor:this.extractColor(this.querySelectorAll(t,`color`)[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`border`},e=>this.extractBorder(e))}extractBorder(e){let t={left:this.extractSingleBorder(e,`left`,this.theme),right:this.extractSingleBorder(e,`right`,this.theme),top:this.extractSingleBorder(e,`top`,this.theme),bottom:this.extractSingleBorder(e,`bottom`,this.theme),diagonal:this.extractSingleBorder(e,`diagonal`,this.theme)};return t.diagonal&&(t.diagonalUp=this.extractAttr(e,`diagonalUp`)?.asBool(),t.diagonalDown=this.extractAttr(e,`diagonalDown`)?.asBool()),t}extractSingleBorder(e,t,n){let r=this.querySelector(e,t);if(!(!r||!r.attributes.style))return{style:this.extractAttr(r,`style`,{required:!0,default:`thin`}).asString(),color:this.extractColor(r.children[0],n,`000000`)}}extractAlignment(e){return{horizontal:this.extractAttr(e,`horizontal`,{default:`general`}).asString(),vertical:this.extractAttr(e,`vertical`,{default:`bottom`}).asString(),textRotation:this.extractAttr(e,`textRotation`)?.asNum(),wrapText:this.extractAttr(e,`wrapText`)?.asBool(),indent:this.extractAttr(e,`indent`)?.asNum(),relativeIndent:this.extractAttr(e,`relativeIndent`)?.asNum(),justifyLastLine:this.extractAttr(e,`justifyLastLine`)?.asBool(),shrinkToFit:this.extractAttr(e,`shrinkToFit`)?.asBool(),readingOrder:this.extractAttr(e,`readingOrder`)?.asNum()}}getDxfs(){return this.mapOnElements({query:`dxf`,parent:this.rootFile.file.xml},e=>{let t=this.querySelector(e,`font`),n=this.querySelector(e,`fill`),r=this.querySelector(e,`border`),i=this.querySelector(e,`numFmt`),a=this.querySelector(e,`alignment`);return{font:t?this.extractFont(t):void 0,fill:n?this.extractFill(n):void 0,numFmt:i?this.extractNumFormats(i):void 0,alignment:a?this.extractAlignment(a):void 0,border:r?this.extractBorder(r):void 0}})}getStyles(){return this.mapOnElements({query:`cellXfs xf`,parent:this.rootFile.file.xml},e=>{let t=this.querySelector(e,`alignment`);return{fontId:this.extractAttr(e,`fontId`,{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,`fillId`,{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,`borderId`,{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,`numFmtId`,{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}})}},uP=class extends QN{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`externalBook`},e=>({rId:this.extractAttr(e,`r:id`,{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:`sheetName`},e=>this.extractAttr(e,`val`,{required:!0}).asString()),datasets:this.extractExternalSheetData(e)}))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:`sheetData`},e=>{let t=this.mapOnElements({parent:e,query:`cell`},e=>({xc:this.extractAttr(e,`r`,{required:!0}).asString(),value:this.extractChildTextContent(e,`v`,{required:!0})})),n={};for(let e of t)n[e.xc]=e.value;return{sheetId:this.extractAttr(e,`sheetId`,{required:!0}).asNum(),data:n}})}};function dP(e,t){return fP(pP(e,t),t)}function fP(e,t){let n=[];for(let r of e){let e=mP(r,t);n.push({file:{fileName:r,xml:t[r]},rels:e?{fileName:e,xml:t[e]}:void 0})}return n}function pP(e,t){let n=t[`[Content_Types].xml`].querySelectorAll(`Override[ContentType="${e}"]`),r=[];for(let e of n){let t=e?.attributes.PartName.value;r.push(t.substring(1))}return r}function mP(e,t){if(e===`[Content_Types].xml`)return`_rels/.rels`;let n=``,r=e.split(`/`);for(let e=0;e<r.length-1;e++)n+=r[e]+`/`;return n+=`_rels/`,n+=r[r.length-1]+`.rels`,t[n]||(n=void 0),n}var hP=class{warningManager;xmls;images;constructor(e){this.warningManager=new Gj,this.xmls={},this.images=[];for(let t of Object.keys(e))if(t.endsWith(`.xml`)||t.endsWith(`.rels`)){let n=PO(e[t]);this.xmls[t]=OO(new wO(n))}else t.includes(`media/image`)&&this.images.push({fileName:t,imageSrc:e[t].imageSrc})}convertXlsx(){let e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){let e=this.buildXlsxFileStructure(),t=e.theme?new $N(e.theme,e,this.warningManager).getTheme():void 0,n=e.sharedStrings?new $N(e.sharedStrings,e,this.warningManager).getSharedStrings():[],r=e.sheets.sort((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0})).map(n=>new cP(n,e,this.warningManager,t).getSheet()),i=e.externalLinks.map(t=>new uP(t,e,this.warningManager).getExternalBook()),a=new lP(e,this.warningManager,t);return{fonts:a.getFonts(),fills:a.getFills(),borders:a.getBorders(),dxfs:a.getDxfs(),numFmts:a.getNumFormats(),styles:a.getStyles(),sheets:r,sharedStrings:n,externalBooks:i,chartIds:[],imageIds:[]}}buildXlsxFileStructure(){let e={sheets:dP(Kf.sheet,this.xmls),workbook:dP(Kf.workbook,this.xmls)[0]||dP(Kf.macroEnabledWorkbook,this.xmls)[0]||dP(Kf.templateWorkbook,this.xmls)[0]||dP(Kf.macroEnabledTemplateWorkbook,this.xmls)[0]||dP(Kf.excelAddInWorkbook,this.xmls)[0],styles:dP(Kf.styles,this.xmls)[0],sharedStrings:dP(Kf.sharedStrings,this.xmls)[0],theme:dP(Kf.themes,this.xmls)[0],charts:dP(Kf.chart,this.xmls),figures:dP(Kf.drawing,this.xmls),tables:dP(Kf.table,this.xmls),pivots:dP(Kf.pivot,this.xmls),externalLinks:dP(Kf.externalLink,this.xmls),images:this.images};if(!e.workbook.rels)throw Error(E(`Cannot find workbook relations file`));return e}convertImportedData(e){let t={version:`18.4.2`,sheets:MN(e,this.warningManager),styles:kM(e,this.warningManager),formats:jM(e,this.warningManager),borders:DM(e,this.warningManager),revisionId:We};return UN(t,e),Object.keys(e.styles).map(t=>{e.styles[t]=zt(e.styles[t])}),t}};function gP(e){let t=By(e),n=[];return{text:``.concat(...t.map(e=>{if(e.type===`REFERENCE`&&yc.test(e.value)){let t=e.value.trim();return n.includes(t)||n.push(t),`|${n.indexOf(t)}|`}else return e.value})),dependencies:n}}let _P={am_ET:7,ar_001:6,ar_SY:6,az_AZ:1,eu_ES:1,be_BY:1,bn_IN:1,bs_BA:1,bg_BG:1,ca_ES:1,zh_CN:7,zh_HK:7,zh_TW:7,hr_HR:1,cs_CZ:1,da_DK:1,nl_BE:1,nl_NL:1,en_AU:7,en_CA:7,en_GB:1,en_IN:7,en_NZ:7,et_EE:1,fi_FI:1,fr_BE:1,fr_CA:7,fr_CH:1,fr_FR:1,gl_ES:1,ka_GE:1,de_DE:1,de_CH:1,el_GR:1,gu_IN:7,he_IL:7,hi_IN:7,hu_HU:1,id_ID:7,it_IT:1,ja_JP:7,kab_DZ:6,km_KH:7,ko_KP:1,ko_KR:7,lo_LA:7,lv_LV:1,lt_LT:1,lb_LU:1,mk_MK:1,ml_IN:1,mn_MN:7,ms_MY:1,nb_NO:1,fa_IR:6,pl_PL:1,pt_AO:1,pt_BR:7,pt_PT:1,ro_RO:1,ru_RU:1,sr_RS:7,"sr@latin":7,sk_SK:1,sl_SI:1,es_AR:7,es_BO:1,es_CL:1,es_CO:7,es_CR:1,es_DO:1,es_EC:1,es_GT:7,es_MX:7,es_PA:7,es_PE:7,es_PY:7,es_UY:1,es_VE:7,sw:1,sv_SE:1,th_TH:7,tl_PH:1,tr_TR:1,uk_UA:1,vi_VN:1,sq_AL:1,te_IN:7,en_US:7,my_MM:7,es_ES:1,es_419:1},vP=new g;vP.add(`0.1`,{migrate(e){return e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e}}).add(`0.2`,{migrate(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}}).add(`0.3`,{migrate(e){return e.sheets&&e.activeSheet&&(e.activeSheet=e.sheets.find(t=>t.name===e.activeSheet).id),e}}).add(`0.4`,{migrate(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}}).add(`0.5`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells||[]){let n=t.cells[e];n.content&&n.content.startsWith(`=`)&&(n.formula=gP(n.content))}return e}}).add(`0.6`,{migrate(e){for(let t of e.sheets||[])for(let e in t.figures||[]){let{dataSets:n,...r}=t.figures[e].data,i=[];for(let e of n)if(e.labelCell){let t=Ts(e.dataRange),n=e.labelCell+`:`+T(t.right,t.bottom);i.push(n)}else i.push(e.dataRange);r.dataSetsHaveTitle=!!n[0].labelCell,r.dataSets=i,t.figures[e].data=r}return e}}).add(`0.7`,{migrate(e){let t=[];for(let n of e.sheets||[]){if(!n.name)continue;let e=n.name,r=an(ht(e,`_`),t,{compute:(e,t)=>`${e}${t}`});n.name=r,t.push(r);let i=t=>{if(t===void 0)return t;let n=t.replace(e,r),i=t;for(;i!==n;)i=n,n=i.replace(e,r);return i};for(let e in n.cells){let t=n.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(i))}for(let e of n.figures||[])if(e.tag===`chart`){let t=e.data.dataSets.map(i),n=i(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:n}}for(let e of n.conditionalFormats||[]){e.ranges=e.ranges.map(i);for(let t of[`minimum`,`maximum`,`midpoint`,`upperInflectionPoint`,`lowerInflectionPoint`])e.rule[t]?.type===`formula`&&(e.rule[t].value=i(e.rule[t].value))}}return e}}).add(`0.8`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[])e.data.background=oe,e.data.verticalAxisPosition=`left`,e.data.legendPosition=`top`,e.data.stacked=!1;return e}}).add(`0.9`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells||[]){let n=t.cells[e];if(n.formula){let{text:e,dependencies:t}=n.formula;for(let[n,r]of Object.entries(t)){let t=`\\|${n}\\|`;e=e.replace(new RegExp(t,`g`),r)}n.content=e,delete n.formula}}return e}}).add(`0.10`,{migrate(e){let t={};for(let n of e.sheets||[])for(let e in n.cells||[]){let r=n.cells[e];r.format&&=mc(r.format,t)}return e.formats=t,e}}).add(`15.4`,{migrate(e){for(let t of e.sheets||[])t.isVisible=!0;return e}}).add(`15.4.1`,{migrate(e){return yP(e)}}).add(`16.3`,{migrate(e){for(let t in e.borders){let n=e.borders[t];for(let e in n)Array.isArray(n[e])&&(n[e]={style:n[e][0],color:n[e][1]})}return e}}).add(`16.4`,{migrate(e){return e.settings||={},e.settings.locale||(e.settings.locale=D),e}}).add(`16.4.1`,{migrate(e){return yP(e)}}).add(`17.2`,{migrate(e){for(let t of e.sheets||[])t.tables=t.tables||t.filterTables||[],delete t.filterTables;return e}}).add(`17.3`,{migrate(e){return e.pivots||={},e.pivotNextId||=Td(e.pivots)+1,e}}).add(`17.4`,{migrate(e){for(let t of e.sheets||[])for(let e in t.figures||[]){let n=t.figures[e];`title`in n.data&&typeof n.data.title==`string`&&(n.data.title={text:n.data.title});let r=n.data.type;if(![`line`,`bar`,`pie`,`scatter`,`waterfall`,`combo`].includes(r))continue;let{dataSets:i,...a}=t.figures[e].data;a.dataSets=i.map(e=>({dataRange:e})),t.figures[e].data=a}return e}}).add(`18.0`,{migrate(e){return e}}).add(`18.0.1`,{migrate(e){for(let t of Object.values(e.pivots||{}))t.measures=t.measures.map(e=>({id:e.name,fieldName:e.name,aggregator:e.aggregator})),t.columns=t.columns.map(e=>({fieldName:e.name,order:e.order,granularity:e.granularity})),t.rows=t.rows.map(e=>({fieldName:e.name,order:e.order,granularity:e.granularity}));return e}}).add(`18.0.2`,{migrate(e){let t=e.settings?.locale;return t&&(t.weekStart=_P[t.code]||1),e}}).add(`18.0.3`,{migrate(e){for(let t of e.sheets||[]){t.styles={},t.formats={},t.borders={};for(let e in t.cells)t.styles[e]=t.cells[e].style,t.formats[e]=t.cells[e].format,t.borders[e]=t.cells[e].border,delete t.cells[e].style,delete t.cells[e].format,delete t.cells[e].border}return e}}).add(`18.0.4`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){if(e.tag!==`chart`||e.data.type!==`gauge`)continue;let t=e.data;t?.sectionRule?.lowerInflectionPoint&&(t.sectionRule.lowerInflectionPoint.operator=`<=`),t?.sectionRule?.upperInflectionPoint&&(t.sectionRule.upperInflectionPoint.operator=`<=`)}return e}}).add(`18.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.tables||[])e.config||={...QA,hasFilters:!0};return e}}).add(`18.1.1`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells){let n=t.cells[e];n&&(t.cells[e]=n.content)}return e}}).add(`18.2`,{migrate(e){return e}}).add(`18.3`,{migrate(e){if(!e.pivots)return e;for(let t of Object.values(e.pivots))t.sortedColumn&&(t.measures.map(e=>e.id).includes(t.sortedColumn.measure)||delete t.sortedColumn);return e}}).add(`18.3.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){let t=e;e.offset={x:t.x||0,y:t.y||0},e.col=0,e.row=0,delete e.x,delete e.y}return e}}).add(`18.4.1`,{migrate(e){let t={textContains:`containsText`,textNotContains:`notContainsText`,textIs:`isEqualText`,textIsEmail:`isEmail`,textIsLink:`isLink`},n={BeginsWith:`beginsWithText`,Between:`isBetween`,ContainsText:`containsText`,EndsWith:`endsWithText`,Equal:`isEqual`,GreaterThan:`isGreaterThan`,GreaterThanOrEqual:`isGreaterOrEqualTo`,IsEmpty:`isEmpty`,IsNotEmpty:`isNotEmpty`,LessThan:`isLessThan`,LessThanOrEqual:`isLessOrEqualTo`,NotBetween:`isNotBetween`,NotContains:`notContainsText`,NotEqual:`isNotEqual`};for(let t of e.sheets||[])for(let e of t.conditionalFormats||[])e.rule.type===`CellIsRule`&&(e.rule.operator=n[e.rule.operator]);for(let n of e.sheets||[])for(let e of n.dataValidationRules||[])e.criterion.type in t&&(e.criterion.type=t[e.criterion.type]);return e}}).add(`18.4.2`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){if(e.tag!==`chart`||e.data.type!==`scorecard`)continue;let t=e.data;t.baselineDescr&&={text:t.baselineDescr}}return e}}).add(`18.4.3`,{migrate(e){if(!e.pivots)return e;for(let t in e.pivots){let n=e.pivots[t];if(n.sortedColumn){let e=n.measures.find(e=>e.fieldName===n.sortedColumn?.measure);e&&(n.sortedColumn.measure=e.id)}}return e}}).add(`18.5.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[])e.tag===`chart`&&(e.data.chartId=e.id);return e}});function yP(e){for(let t of e.sheets||[]){let e=[];for(let n of t.filterTables||[]){let t=Ts(n.range),r=e.findIndex(e=>zs(e,t));r===-1?e.push(t):e[r]=t}t.filterTables=e.map(e=>({range:As(e)}))}return e}function bP(){return xP().at(-1)}function xP(){return vP.getKeys().sort(EP)}let SP=`Sheet1`;function CP(e,t){if(!e)return RP();console.debug(`### Loading data ###`);let n=performance.now();if(e[`[Content_Types].xml`]){let n=new hP(e);if(e=n.convertXlsx(),t)for(let e of n.warningManager.warnings.sort())console.warn(e)}return`version`in e&&(TP(e)&&(e.version=wP[e.version]),e.version!==bP()&&(console.debug(`Migrating data from version`,e.version),e=DP(e))),e=OP(e),console.debug(`Data loaded in`,performance.now()-n,`ms`),console.debug(`###`),e}let wP={25:`18.2`,24:`18.1.1`,23:`18.1`,22:`18.0.4`,21:`18.0.3`,20:`18.0.2`,19:`18.0.1`,18:`18.0`,17:`17.4`,16:`17.3`,15:`17.2`,"14.5":`16.4.1`,14:`16.4`,13:`16.3`,"12.5":`15.4.1`,12:`15.4`,11:`0.10`,10:`0.9`,9:`0.8`,8:`0.7`,7:`0.6`,6:`0.5`,5:`0.4`,4:`0.3`,3:`0.2`,2:`0.1`,1:`0`};function TP(e){return typeof e.version==`number`}function EP(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<Math.max(n.length,r.length);e++){let t=n[e]||0,i=r[e]||0;if(t>i)return 1;if(t<i)return-1}return 0}function DP(e){let t=performance.now(),n=xP(),r=n.findIndex(t=>EP(t,e.version)>=0);if(r===-1)throw Error(`Data version ${e.version} postdates the current version of o-spreadsheet (version ${bP()}). It cannot be loaded.`);for(let t=r+1;t<n.length;t++){let r=n[t];e=vP.get(r).migrate(e)}return console.debug(`Data migrated in`,performance.now()-t,`ms`),e}function OP(e){return e=kP(e),e=AP(e),e}function kP(e){if(e.uniqueFigureIds)return e;let t=new Set,n=new Set,r=new jl;for(let i of e.sheets||[])for(let e of i.figures||[])t.has(e.id)&&(e.id+=r.smallUuid()),t.add(e.id),e.tag===`chart`&&(n.has(e.data?.chartId)&&(e.data.chartId+=r.smallUuid()),n.add(e.data?.chartId));return e.uniqueFigureIds=!0,e}function AP(e){let t=Object.assign(RP(),e,{version:bP()});return t.sheets=t.sheets?t.sheets.map((e,t)=>Object.assign(LP(`Sheet${t+1}`,`Sheet${t+1}`),e)):[],t.sheets.length===0&&t.sheets.push(LP(SP,`Sheet1`)),uu(t.settings.locale)||(t.settings.locale=D),t}function jP(e,t){return t=MP(e,t),t=NP(t,`SORT_CELLS`),t=NP(t,`SET_DECIMAL`),t=PP(e,t),t=FP(e,t),t=IP(e,t),t}function MP(e,t){if(Object.keys(e).length!==0)return t;let n=[],r=[],i=e=>{if(e.type===`CREATE_SHEET`)n.push(e.sheetId);else if(`sheetId`in e&&!n.includes(e.sheetId))return{...e,sheetId:SP};return e};for(let e of t)e.type===`REMOTE_REVISION`?r.push({...e,commands:e.commands.map(i)}):r.push(e);return r}function NP(e,t){let n=[];for(let r of e)r.type===`REMOTE_REVISION`?n.push({...r,commands:r.commands.filter(e=>e.type!==t)}):n.push(r);return n}function PP(e,t){if(!e.version||EP(String(e.version),`18.5.1`)>=0)return t;let n=[],r={};for(let t of e.sheets||[])t.figures?.forEach(e=>{e.tag===`chart`&&(r[e.id]=e.data)});for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let n of e.commands){let e=n;switch(n.type){case`CREATE_CHART`:r[n.chartId]=n.definition;break;case`UPDATE_CHART`:if(!r[n.chartId]){console.log(`Fix chart definition: chart with id ${n.chartId} not found.`);continue}let t={...r[n.chartId],...n.definition};e={...n,definition:t},r[n.chartId]=t;break}t.push(e)}n.push({...e,commands:t})}else n.push(e);return n}function FP(e,t){let n={};for(let t of e.sheets||[])t.figures?.forEach(e=>{n[e.id]=e.offset});for(let e of t)if(e.type===`REMOTE_REVISION`)for(let t of e.commands)switch(t.type){case`UPDATE_FIGURE`:t.offset&&(t.offset.x===void 0&&(t.offset.x=n[t.figureId]||0),t.offset.y===void 0&&(t.offset.y=n[t.figureId]||0),n[t.figureId]=n);break;case`CREATE_IMAGE`:case`CREATE_CHART`:case`CREATE_FIGURE`:n[t.figureId]=t.offset;break}return t}function IP(e,t){let n={};for(let t of e.sheets||[])n[t.id]=t.name;let r=[];for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let r of e.commands){switch(r.type){case`DUPLICATE_SHEET`:r.sheetNameTo=r.sheetNameTo??ol(n[r.sheetId],Object.values(n));break;case`CREATE_SHEET`:n[r.sheetId]=r.name||al(Object.values(n));break;case`RENAME_SHEET`:n[r.sheetId]=r.newName||al(Object.values(n));break}t.push(r)}r.push({...e,commands:t})}else r.push(e);return t}function LP(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},styles:{},formats:{},borders:{},cols:{},rows:{},merges:[],conditionalFormats:[],dataValidationRules:[],figures:[],tables:[],isVisible:!0}}function RP(e=`Sheet1`){return{version:bP(),sheets:[LP(SP,e)],styles:{},formats:{},borders:{},revisionId:We,uniqueFigureIds:!0,settings:{locale:D},pivots:{},pivotNextId:1,customTableStyles:{}}}function zP(e,t){return{...LP(e,t),charts:[],images:[],cellValues:{}}}function BP(){return{...RP(),sheets:[zP(SP,`Sheet1`)]}}let VP={wrongPasteSelection:E(`This operation is not allowed with multiple selections.`),willRemoveExistingMerge:Jb.Errors.WillRemoveExistingMerge,wrongFigurePasteOption:E(`Cannot do a special paste of a figure.`),frozenPaneOverlap:E(`This operation is not allowed due to an overlapping frozen pane.`)};function HP(e,t){t.isSuccessful||(t.reasons.includes(`WrongPasteSelection`)?e.raiseError(VP.wrongPasteSelection):t.reasons.includes(`WillRemoveExistingMerge`)?e.raiseError(VP.willRemoveExistingMerge):t.reasons.includes(`WrongFigurePasteOption`)?e.raiseError(VP.wrongFigurePasteOption):t.reasons.includes(`FrozenPaneOverlap`)&&e.raiseError(VP.frozenPaneOverlap))}function UP(e,t,n){HP(e,e.model.dispatch(`PASTE`,{target:t,pasteOption:n}))}async function WP(e,t,n,r){if(n.data&&n.data.version!==bP()&&e.notifyUser({type:`warning`,text:E(`You copied content from a different version of the application. Only text and image content will be pasted.`),sticky:!1}),n.imageBlob){let t=n;try{t.imageData=await e.imageProvider?.uploadFile(n.imageBlob)}catch(t){let n=E(`An error occurred while uploading the image. %s`,t.message);console.error(t),e.raiseError(n)}delete n.imageBlob}HP(e,e.model.dispatch(`PASTE_FROM_OS_CLIPBOARD`,{target:t,clipboardContent:n,pasteOption:r}))}function GP(e,t,n=QA){let r=e.model.getters.getSelectedZones(),i=e.model.getters.canCreateDynamicTableOnZones(t,r);r.length===1&&!i&&nc(r[0])===1&&(e.model.selection.selectTableAroundSelection(),r=e.model.getters.getSelectedZones(),i=e.model.getters.canCreateDynamicTableOnZones(t,r));let a=r.map(n=>e.model.getters.getRangeDataFromZone(t,n)),o=e.model.dispatch(`CREATE_TABLE`,{ranges:a,sheetId:t,config:n,tableType:i?`dynamic`:`static`});return o.isCancelledBecause(`TableOverlap`)?e.raiseError(Yb.Errors.TableOverlap):o.isCancelledBecause(`NonContinuousTargets`)&&e.raiseError(Yb.Errors.NonContinuousTargets),o}function KP(e,t){e.model.dispatch(`SET_FORMATTING_WITH_PIVOT`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),format:t})}function qP(e,t){e.model.dispatch(`SET_FORMATTING`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),style:t})}let JP=async e=>XP(e),YP=async e=>XP(e,`asValue`);async function XP(e,t){let n=await e.clipboard.read();switch(n.status){case`ok`:let r=e.model.getters.getClipboardId(),i=Il(n.content),a=i.data?.clipboardId,o=e.model.getters.getSelectedZones();r===a?UP(e,o,t):await WP(e,o,i,t),e.model.getters.isCutOperation()&&t!==`asValue`&&await e.clipboard.write({"text/plain":``});break;case`notImplemented`:e.raiseError(E(`Pasting from the context menu is not supported in this browser. Use keyboard shortcuts ctrl+c / ctrl+v instead.`));break;case`permissionDenied`:e.raiseError(E(`Access to the clipboard denied by the browser. Please enable clipboard permission for this page in your browser settings.`));break}}let ZP=e=>XP(e,`onlyFormat`),QP=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Clear rows`);let t,n,r=e.model.getters.getActiveRows();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.top,n=r.bottom}return t===n?E(`Clear row %s`,(t+1).toString()):E(`Clear rows %s - %s`,(t+1).toString(),(n+1).toString())},$P=e=>{let t=e.model.getters.getActiveSheetId(),n=[...e.model.getters.getActiveRows()].map(n=>e.model.getters.getRowsZone(t,n,n));e.model.dispatch(`DELETE_CONTENT`,{target:n,sheetId:e.model.getters.getActiveSheetId()})},eF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Clear columns`);let t,n,r=e.model.getters.getActiveCols();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.left,n=r.right}return t===n?E(`Clear column %s`,Yn(t)):E(`Clear columns %s - %s`,Yn(t),Yn(n))},tF=e=>{let t=e.model.getters.getActiveSheetId(),n=[...e.model.getters.getActiveCols()].map(n=>e.model.getters.getColsZone(t,n,n));e.model.dispatch(`DELETE_CONTENT`,{target:n,sheetId:e.model.getters.getActiveSheetId()})},nF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Delete rows`);let t,n,r=e.model.getters.getActiveRows();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.top,n=r.bottom}return t===n?E(`Delete row %s`,(t+1).toString()):E(`Delete rows %s - %s`,(t+1).toString(),(n+1).toString())},rF=e=>{let t=[...e.model.getters.getActiveRows()];if(!t.length){let n=e.model.getters.getSelectedZones()[0];for(let e=n.top;e<=n.bottom;e++)t.push(e)}e.model.dispatch(`REMOVE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),dimension:`ROW`,elements:t})},iF=(e,t)=>{if(e===`COL`&&t.model.getters.getActiveRows().size>0||e===`ROW`&&t.model.getters.getActiveCols().size>0)return!1;let n=t.model.getters.getActiveSheetId(),r=t.model.getters.getElementsFromSelection(e),i=t.model.getters.checkElementsIncludeAllVisibleHeaders(n,e,r),a=t.model.getters.checkElementsIncludeAllNonFrozenHeaders(n,e,r);return!i&&!a},aF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Delete columns`);let t,n,r=e.model.getters.getActiveCols();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.left,n=r.right}return t===n?E(`Delete column %s`,Yn(t)):E(`Delete columns %s - %s`,Yn(t),Yn(n))},oF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getElementsFromSelection(`ROW`);return!e.model.getters.checkElementsIncludeAllVisibleHeaders(t,`ROW`,n)},sF=e=>{let t=[...e.model.getters.getActiveCols()];if(!t.length){let n=e.model.getters.getSelectedZones()[0];for(let e=n.left;e<=n.right;e++)t.push(e)}e.model.dispatch(`REMOVE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),dimension:`COL`,elements:t})},cF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getElementsFromSelection(`COL`);return!e.model.getters.checkElementsIncludeAllVisibleHeaders(t,`COL`,n)},lF=e=>{let t=e.model.getters.getActiveRows(),n,r;if(t.size)n=en([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.top,r=t.bottom-t.top+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`before`,base:n,quantity:r,dimension:`ROW`})},uF=e=>{let t=e.model.getters.getActiveRows(),n,r;if(t.size)n=$t([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.bottom,r=t.bottom-t.top+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`after`,base:n,quantity:r,dimension:`ROW`})},dF=e=>{let t=e.model.getters.getActiveCols(),n,r;if(t.size)n=en([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.left,r=t.right-t.left+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`before`,dimension:`COL`,base:n,quantity:r})},fF=e=>{let t=e.model.getters.getActiveCols(),n,r;if(t.size)n=$t([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.right,r=t.right-t.left+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`after`,dimension:`COL`,base:n,quantity:r})},pF=e=>{let t=e.model.getters.getElementsFromSelection(`COL`),n=t[0],r=t[t.length-1];return t.length===1?E(`Hide column %s`,Yn(n).toString()):r-n+1===t.length?E(`Hide columns %s - %s`,Yn(n).toString(),Yn(r).toString()):E(`Hide columns`)},mF=e=>{let t=e.model.getters.getElementsFromSelection(`ROW`),n=t[0],r=t[t.length-1];return t.length===1?E(`Hide row %s`,(n+1).toString()):r-n+1===t.length?E(`Hide rows %s - %s`,(n+1).toString(),(r+1).toString()):E(`Hide rows`)},hF=e=>{let t=e.model.getters,n=e.model.uuidGenerator.smallUuid(),r=t.getActiveSheetId(),i=t.getSelectedZones();i.length===1&&nc(i[0])===1&&(e.model.selection.selectTableAroundSelection(),i=t.getSelectedZones());let a={width:536,height:335},{col:o,row:s,offset:c}=SO(t,a);e.model.dispatch(`CREATE_CHART`,{sheetId:r,figureId:n,chartId:e.model.uuidGenerator.smallUuid(),col:o,row:s,offset:c,size:a,definition:XA(i,e.model.getters)}).isSuccessful&&(e.model.dispatch(`SELECT_FIGURE`,{figureId:n}),e.openSidePanel(`ChartPanel`))},gF=e=>{let t=e.model.getters,n=e.model.uuidGenerator.smallUuid(),r=t.getActiveSheetId(),i={width:536,height:335},{col:a,row:o,offset:s}=SO(t,i);e.model.dispatch(`CREATE_CAROUSEL`,{sheetId:r,figureId:n,col:a,row:o,offset:s,size:i,definition:{items:[]}}).isSuccessful&&(e.model.dispatch(`SELECT_FIGURE`,{figureId:n}),e.openSidePanel(`CarouselPanel`,{figureId:n}))},_F=e=>{let t=e.model.uuidGenerator.smallUuid(),n=e.model.uuidGenerator.smallUuid();e.model.dispatch(`INSERT_NEW_PIVOT`,{pivotId:t,newSheetId:n}).isSuccessful&&e.openSidePanel(`PivotSidePanel`,{pivotId:t})},vF=e=>e.model.getters.getPivotIds().map((t,n)=>({id:`reinsert_dynamic_pivot_${e.model.getters.getPivotFormulaId(t)}`,name:e.model.getters.getPivotDisplayName(t),sequence:n,execute:e=>{let n=e.model.getters.getSelectedZone(),r=e.model.getters.getPivot(t).getCollapsedTableStructure().export();e.model.dispatch(`INSERT_PIVOT_WITH_TABLE`,{pivotId:t,table:r,col:n.left,row:n.top,sheetId:e.model.getters.getActiveSheetId(),pivotMode:`dynamic`}),e.model.dispatch(`REFRESH_PIVOT`,{id:t})},isVisible:e=>e.model.getters.getPivot(t).isValid()})),yF=e=>e.model.getters.getPivotIds().map((t,n)=>({id:`reinsert_static_pivot_${e.model.getters.getPivotFormulaId(t)}`,name:e.model.getters.getPivotDisplayName(t),sequence:n,execute:e=>{let n=e.model.getters.getSelectedZone(),r=e.model.getters.getPivot(t).getExpandedTableStructure();if(r.numberOfCells>5e5){e.notifyUser({type:`warning`,text:Zb(r.numberOfCells,e.model.getters.getLocale()),sticky:!0});return}e.model.dispatch(`INSERT_PIVOT_WITH_TABLE`,{pivotId:t,table:r.export(),col:n.left,row:n.top,sheetId:e.model.getters.getActiveSheetId(),pivotMode:`static`}),e.model.dispatch(`REFRESH_PIVOT`,{id:t})},isVisible:e=>e.model.getters.getPivot(t).isValid()}));async function bF(e){try{return await e.imageProvider.requestImage()}catch{e.raiseError(E(`An unexpected error occurred during the image transfer`));return}}let xF=async e=>{if(e.imageProvider){let t=e.model.getters.getActiveSheetId(),n=e.model.uuidGenerator.smallUuid(),r=await bF(e);if(!r)return;let i=CO(e.model.getters,r.size),{col:a,row:o,offset:s}=SO(e.model.getters,i);e.model.dispatch(`CREATE_IMAGE`,{sheetId:t,figureId:n,col:a,row:o,offset:s,size:i,definition:r})}},SF=e=>KP(e,`0.00%`),CF=e=>{e.openSidePanel(`ConditionalFormatting`,{selection:e.model.getters.getSelectedZones()})},wF=e=>{let{col:t,row:n}=e.model.getters.getActivePosition();e.getStore(TA).open({col:t,row:n},`LinkEditor`)},TF=e=>{let t=e.model.getters.getActiveSheetId(),{col:n,row:r}=e.model.getters.getActivePosition(),i=e.model.getters.getEvaluatedCell({sheetId:t,col:n,row:r});return i&&i.link?E(`Edit link`):E(`Insert link`)},EF=e=>e.model.getters.getFirstTableInSelection()?.config.hasFilters||!1,DF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZones();return e.model.getters.getTablesOverlappingZones(t,n).length===1},OF=e=>oc(e.model.getters.getSelectedZones()),kF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getFirstTableInSelection();n?e.model.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{hasFilters:!0}}):GP(e,t,{...QA,hasFilters:!0,bandedRows:!1,styleId:`TableStyleLight11`})},AF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getFirstTableInSelection();n&&e.model.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{hasFilters:!1}})},jF=e=>{GP(e,e.model.getters.getActiveSheetId()).isSuccessful&&e.openSidePanel(`TableSidePanel`,{})},MF=e=>{let t=e.model.getters.getActivePosition(),n=e.model.getters.getTable(t);n&&e.model.dispatch(`REMOVE_TABLE`,{sheetId:t.sheetId,target:[n.range.zone]})},NF=e=>e.model.getters.getSelectedZones().length===1,PF=(e,t)=>{if(!NF(e))return!1;let n=t===`COL`?e.model.getters.getActiveCols():e.model.getters.getActiveRows(),r=t===`COL`?e.model.getters.getActiveRows():e.model.getters.getActiveCols(),i=e.model.getters.getActiveSheetId(),a=Rs(e.model.getters.getSelectedZone(),e.model.getters.getSheetZone(i));return Gt(n)&&(r.size===0||a)},FF={name:e=>EF(e)?E(`Remove selected filters`):E(`Add filters`),isEnabled:e=>OF(e),execute:e=>EF(e)?AF(e):kF(e),icon:`o-spreadsheet-Icon.FILTER_ICON_ACTIVE`};function IF(e,t,n){let r=e.model.getters.getActiveSheetId(),i=t===`COL`?`FREEZE_COLUMNS`:`FREEZE_ROWS`;e.model.dispatch(i,{sheetId:r,quantity:n}).isCancelledBecause(`MergeOverlap`)&&e.raiseError(Gb)}var LF=class{map={};constructor(e=[]){for(let[t,n]of e)this.set(t,n)}set({sheetId:e,col:t,row:n},r){let i=this.map;i[e]||(i[e]={}),i[e][t]||(i[e][t]={}),i[e][t][n]=r}setMany(e){for(let[t,n]of e)this.set(t,n)}get({sheetId:e,col:t,row:n}){return this.map[e]?.[t]?.[n]}getSheet(e){return this.map[e]}clearSheet(e){delete this.map[e]}has({sheetId:e,col:t,row:n}){return this.map[e]?.[t]?.[n]!==void 0}delete({sheetId:e,col:t,row:n}){delete this.map[e]?.[t]?.[n]}keys(){let e=this.map,t=[];for(let n in e)for(let r in e[n])for(let i in e[n][r])t.push({sheetId:n,col:parseInt(r),row:parseInt(i)});return t}keysForSheet(e){let t=this.map[e];if(!t)return[];let n=[];for(let r in t)for(let i in t[r])n.push({sheetId:e,col:parseInt(r),row:parseInt(i)});return n}*entries(){let e=this.map;for(let t of this.keys()){let{sheetId:n,col:r,row:i}=t;yield[t,e[n][r][i]]}}},RF=class extends bf{mutators=[`enable`,`disable`];isInvalidated=!1;fingerprintColors={[BF]:`#D9D9D9`};isEnabled=!1;colors=new LF;handle(e){switch(Dr(e)&&this.isEnabled&&(this.isInvalidated=!0),e.type){case`UNDO`:case`REDO`:case`ACTIVATE_SHEET`:this.isEnabled&&(this.isInvalidated=!0);break}}finalize(){this.isInvalidated&&(this.isInvalidated=!1,this.computeFingerprints())}enable(){this.isEnabled=!0,this.computeFingerprints()}disable(){this.isEnabled=!1,this.colors=new LF}computeFingerprints(){this.colors=new LF;let e=new LF,t=new Set,n=this.getters.getActiveSheetId(),r=this.getters.getCells(n);for(let n in r){let i=this.computeFingerprint(r[n]);if(!i)continue;t.add(i);let a=this.getters.getCellPosition(n);e.set(a,i)}this.assignColors(t);for(let[t,n]of e.entries()){let e=this.fingerprintColors[n];this.colors.set(t,e),this.colorSpreadZone(t,e)}}colorSpreadZone(e,t){let n=this.getters.getSpreadZone(e);if(!n)return;let r=e.sheetId;for(let e=n.top;e<=n.bottom;e++)for(let i=n.left;i<=n.right;i++){let n={sheetId:r,col:i,row:e};this.colors.set(n,t)}}assignColors(e){let t=new Wn(e.size);Object.keys(this.fingerprintColors).forEach(()=>t.next());for(let n of e)this.fingerprintColors[n]||(this.fingerprintColors[n]=kn(t.next(),.8))}computeFingerprint(e){let t=this.getters.getCellPosition(e.id);return e.isFormula?this.computeFormulaFingerprint(t,e):this.getLiteralFingerprint(t)}computeFormulaFingerprint(e,t){let n=t.compiledFormula.dependencies,r=e.col,i=e.row,a=this.getters.getSheetIds().indexOf(e.sheetId),o={dx:0,dy:0,dSheet:0};for(let e of n){let t=e.zone,[n,s]=e.parts;o.dSheet=this.getters.getSheetIds().indexOf(e.sheetId)-a;let c=Lc(e)&&!e.unboundedZone.hasHeader,l=Ic(e)&&!e.unboundedZone.hasHeader,u=c||n?.colFixed?0:r,d=l||n?.rowFixed?0:i,f=!s&&n?.colFixed||s?.colFixed,p=!s&&n?.rowFixed||s?.rowFixed,m=e.unboundedZone.right===void 0,h=e.unboundedZone.bottom===void 0,g=m||f?0:r,_=h||p?0:i,v=Js({top:t.top-d,left:t.left-u,right:t.right-g,bottom:t.bottom-_});for(let e=v.top;e<=v.bottom;e++)for(let t=v.left;t<=v.right;t++)o.dx+=t,o.dy+=e}let s=t.compiledFormula.normalizedFormula;return zF(o)+s}getLiteralFingerprint(e){switch(this.getters.getEvaluatedCell(e).type){case`number`:case`boolean`:return BF;case`text`:case`empty`:case`error`:return}}};function zF(e){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t).join(`,`)}let BF=`DATA_FINGERPRINT`,VF={name:pF,execute:e=>{let t=e.model.getters.getElementsFromSelection(`COL`);e.model.dispatch(`HIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`COL`,elements:t})},isVisible:cF,icon:`o-spreadsheet-Icon.HIDE_COL`},HF={name:E(`Unhide columns`),execute:e=>{let t=e.model.getters.getElementsFromSelection(`COL`);e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`COL`,elements:t})},isVisible:e=>{let t=e.model.getters.getHiddenColsGroups(e.model.getters.getActiveSheetId()).flat();return e.model.getters.getElementsFromSelection(`COL`).some(e=>t.includes(e))},icon:`o-spreadsheet-Icon.UNHIDE_COL`},UF={name:E(`Unhide all columns`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:t,dimension:`COL`,elements:Array.from(Array(e.model.getters.getNumberCols(t)).keys())})},isVisible:e=>e.model.getters.getHiddenColsGroups(e.model.getters.getActiveSheetId()).length>0,icon:`o-spreadsheet-Icon.UNHIDE_COL`},WF={name:mF,execute:e=>{let t=e.model.getters.getElementsFromSelection(`ROW`);e.model.dispatch(`HIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`ROW`,elements:t})},isVisible:oF,icon:`o-spreadsheet-Icon.HIDE_ROW`},GF={name:E(`Unhide rows`),execute:e=>{let t=e.model.getters.getElementsFromSelection(`ROW`);e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`ROW`,elements:t})},isVisible:e=>{let t=e.model.getters.getHiddenRowsGroups(e.model.getters.getActiveSheetId()).flat();return e.model.getters.getElementsFromSelection(`ROW`).some(e=>t.includes(e))},icon:`o-spreadsheet-Icon.UNHIDE_ROW`},KF={name:E(`Unhide all rows`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:t,dimension:`ROW`,elements:Array.from(Array(e.model.getters.getNumberRows(t)).keys())})},isVisible:e=>e.model.getters.getHiddenRowsGroups(e.model.getters.getActiveSheetId()).length>0,icon:`o-spreadsheet-Icon.UNHIDE_ROW`},qF={name:E(`Unfreeze`),isVisible:e=>{let{xSplit:t,ySplit:n}=e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId());return t+n>0},execute:e=>e.model.dispatch(`UNFREEZE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId()}),icon:`o-spreadsheet-Icon.UNFREEZE`},JF={name:E(`Freeze`),icon:`o-spreadsheet-Icon.FREEZE`},YF={name:E(`No rows`),execute:e=>e.model.dispatch(`UNFREEZE_ROWS`,{sheetId:e.model.getters.getActiveSheetId()}),isReadonlyAllowed:!0,isVisible:e=>!!e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId()).ySplit},XF={name:E(`1 row`),execute:e=>IF(e,`ROW`,1),isReadonlyAllowed:!0},ZF={name:E(`2 rows`),execute:e=>IF(e,`ROW`,2),isReadonlyAllowed:!0},QF={name:E(`Up to current row`),execute:e=>{let{bottom:t}=e.model.getters.getSelectedZone();IF(e,`ROW`,t+1)},isReadonlyAllowed:!0},$F={name:E(`No columns`),execute:e=>e.model.dispatch(`UNFREEZE_COLUMNS`,{sheetId:e.model.getters.getActiveSheetId()}),isReadonlyAllowed:!0,isVisible:e=>!!e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId()).xSplit},eI={name:E(`1 column`),execute:e=>IF(e,`COL`,1),isReadonlyAllowed:!0},tI={name:E(`2 columns`),execute:e=>IF(e,`COL`,2),isReadonlyAllowed:!0},nI={name:E(`Up to current column`),execute:e=>{let{right:t}=e.model.getters.getSelectedZone();IF(e,`COL`,t+1)},isReadonlyAllowed:!0},rI={name:E(`Gridlines`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`SET_GRID_LINES_VISIBILITY`,{sheetId:t,areGridLinesVisible:!e.model.getters.getGridLinesVisibility(t)})},isActive:e=>{let t=e.model.getters.getActiveSheetId();return e.model.getters.getGridLinesVisibility(t)}},iI={name:E(`Irregularity map`),execute:e=>{let t=e.getStore(RF);t.isEnabled?t.disable():t.enable()},isReadonlyAllowed:!0,icon:`o-spreadsheet-Icon.IRREGULARITY_MAP`},aI={name:E(`Formulas`),isActive:e=>e.model.getters.shouldShowFormulas(),execute:e=>e.model.dispatch(`SET_FORMULA_VISIBILITY`,{show:!e.model.getters.shouldShowFormulas()}),isReadonlyAllowed:!0},oI={name:e=>{let t=e.model.getters.getSelectedZone();return t.left===t.right?E(`Group column %s`,Yn(t.left)):E(`Group columns %s - %s`,Yn(t.left),Yn(t.right))},execute:e=>uI(e,`COL`),isVisible:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZone(),r=e.model.getters.getHeaderGroupsInZone(t,`COL`,n);return NF(e)&&!r.some(e=>e.start===n.left&&e.end===n.right)},icon:`o-spreadsheet-Icon.GROUP_COLUMNS`},sI={name:e=>{let t=e.model.getters.getSelectedZone();return t.top===t.bottom?E(`Group row %s`,String(t.top+1)):E(`Group rows %s - %s`,String(t.top+1),String(t.bottom+1))},execute:e=>uI(e,`ROW`),isVisible:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZone(),r=e.model.getters.getHeaderGroupsInZone(t,`ROW`,n);return NF(e)&&!r.some(e=>e.start===n.top&&e.end===n.bottom)},icon:`o-spreadsheet-Icon.GROUP_ROWS`},cI={name:e=>{let t=e.model.getters.getSelectedZone();return t.left===t.right?E(`Ungroup column %s`,Yn(t.left)):E(`Ungroup columns %s - %s`,Yn(t.left),Yn(t.right))},execute:e=>dI(e,`COL`),icon:`o-spreadsheet-Icon.UNGROUP_COLUMNS`},lI={name:e=>{let t=e.model.getters.getSelectedZone();return t.top===t.bottom?E(`Ungroup row %s`,String(t.top+1)):E(`Ungroup rows %s - %s`,String(t.top+1),String(t.bottom+1))},execute:e=>dI(e,`ROW`),icon:`o-spreadsheet-Icon.UNGROUP_ROWS`};function uI(e,t){let n=e.model.getters.getSelectedZone(),r=e.model.getters.getActiveSheetId();e.model.dispatch(`GROUP_HEADERS`,{sheetId:r,dimension:t,start:t===`COL`?n.left:n.top,end:t===`COL`?n.right:n.bottom})}function dI(e,t){let n=e.model.getters.getSelectedZone(),r=e.model.getters.getActiveSheetId();e.model.dispatch(`UNGROUP_HEADERS`,{sheetId:r,dimension:t,start:t===`COL`?n.left:n.top,end:t===`COL`?n.right:n.bottom})}function fI(e,t){let n=e.model.getters.getActiveSheetId(),r=e.model.getters.getSelectedZones();return r.length===1&&e.model.getters.getHeaderGroupsInZone(n,t,r[0]).length>0}let pI=[`wholeTable`,`firstColumnStripe`,`secondColumnStripe`,`firstRowStripe`,`secondRowStripe`,`firstColumn`,`lastColumn`,`headerRow`,`totalRow`];function mI(e,t){let n=t.numberOfHeaders,r={...e,top:e.top+n};return r.top<=r.bottom?r:void 0}function hI(e){let t=e.range;return{row:t.zone.top,col:t.zone.left,sheetId:t.sheetId}}function gI(e,t,n,r){let i=t.zone;if(i.left!==i.right)throw Error(`Can only define a filter on a single column`);let a={...i,top:i.top+n.numberOfHeaders},o=r(t.sheetId,a);return{id:e,rangeWithHeaders:t,col:i.left,filteredRange:a.top>a.bottom?void 0:o}}function _I(e){return e.type===`static`||e.type===`forceStatic`}function vI(e,t,n,r){return{borders:yI(e,t,n,r),styles:xI(e,t,n,r)}}function yI(e,t,n,r){let i=Sa(n,r,()=>({}));for(let a of pI){let o=t[a]?.border;if(!o)continue;let s=CI(a,e,n,r);for(let t of s)for(let s=t.left;s<=t.right;s++)for(let c=t.top;c<=t.bottom;c++){let l=a===`wholeTable`&&c<=e.numberOfHeaders-1;c===t.top&&o?.top?bI(i,`top`,o.top,s,c,n,r):c!==t.top&&!l&&o?.horizontal&&bI(i,`top`,o.horizontal,s,c,n,r),c===t.bottom&&o?.bottom&&bI(i,`bottom`,o.bottom,s,c,n,r),s===t.left&&o?.left&&bI(i,`left`,o.left,s,c,n,r),s===t.right&&o?.right?bI(i,`right`,o.right,s,c,n,r):s!==t.right&&!l&&o?.vertical&&bI(i,`right`,o.vertical,s,c,n,r)}}return i}function bI(e,t,n,r,i,a,o){switch(t){case`top`:e[r][i].top=n,i!==0&&(e[r][i-1].bottom=n);return;case`bottom`:e[r][i].bottom=n,i!==o-1&&(e[r][i+1].top=n);return;case`left`:e[r][i].left=n,r!==0&&(e[r-1][i].right=n);return;case`right`:e[r][i].right=n,r!==a-1&&(e[r+1][i].left=n);return}}function xI(e,t,n,r){let i=Sa(n,r,()=>({}));for(let a of pI){let o=t[a],s=SI(a);if(!o&&!s)continue;let c=CI(a,e,n,r);for(let e of c)for(let t=e.left;t<=e.right;t++)for(let n=e.top;n<=e.bottom;n++)i[t][n]||(i[t][n]={}),i[t][n]={...i[t][n],...o?.style},s&&(i[t][n].bold=!0)}return i}function SI(e){return e===`firstColumn`||e===`lastColumn`||e===`headerRow`||e===`totalRow`}function CI(e,t,n,r){let i=[],a=Math.min(t.numberOfHeaders,r),o=+!!t.totalRow,s=n-1,c=r-1;switch(e){case`wholeTable`:i.push({top:0,left:0,bottom:c,right:s});break;case`firstColumn`:if(!t.firstColumn)break;i.push({top:0,left:0,bottom:c,right:0});break;case`lastColumn`:if(!t.lastColumn)break;i.push({top:0,left:s,bottom:c,right:s});break;case`headerRow`:if(!t.numberOfHeaders)break;i.push({top:0,left:0,bottom:a-1,right:s});break;case`totalRow`:if(!t.totalRow)break;i.push({top:c,left:0,bottom:c,right:s});break;case`firstRowStripe`:if(!t.bandedRows)break;for(let e=a;e<r-o;e+=2)i.push({top:e,left:0,bottom:e,right:s});break;case`secondRowStripe`:if(!t.bandedRows)break;for(let e=a+1;e<r-o;e+=2)i.push({top:e,left:0,bottom:e,right:s});break;case`firstColumnStripe`:if(!t.bandedColumns)break;for(let e=0;e<n;e+=2)i.push({top:a,left:e,bottom:c-o,right:e});break;case`secondColumnStripe`:if(!t.bandedColumns)break;for(let e=1;e<n;e+=2)i.push({top:a,left:e,bottom:c-o,right:e});break}return i}function wI(e){let t=e.model.dispatch(`CUT`);t.isSuccessful||t.isCancelledBecause(`WrongCutSelection`)&&e.raiseError(E(`This operation is not allowed with multiple selections.`))}let TI={MergeIsDestructive:E(`Merging these cells will only preserve the top-leftmost value. Merge anyway?`),MergeInFilter:E(`You can't merge cells inside of an existing filter.`)};function EI(e,t,n){let r=e.model.dispatch(`ADD_MERGE`,{sheetId:t,target:n});r.isCancelledBecause(`MergeInTable`)?e.raiseError(TI.MergeInFilter):r.isCancelledBecause(`MergeIsDestructive`)&&e.askConfirmation(TI.MergeIsDestructive,()=>{e.model.dispatch(`ADD_MERGE`,{sheetId:t,target:n,force:!0})})}let DI={name:E(`Undo`),description:`Ctrl+Z`,execute:e=>e.model.dispatch(`REQUEST_UNDO`),isEnabled:e=>e.model.getters.canUndo(),icon:`o-spreadsheet-Icon.UNDO`},OI={name:E(`Redo`),description:`Ctrl+Y`,execute:e=>e.model.dispatch(`REQUEST_REDO`),isEnabled:e=>e.model.getters.canRedo(),icon:`o-spreadsheet-Icon.REDO`},kI={name:E(`Copy`),description:`Ctrl+C`,isReadonlyAllowed:!0,execute:async e=>{e.model.dispatch(`COPY`),await e.clipboard.write(await e.model.getters.getClipboardTextAndImageContent())},icon:`o-spreadsheet-Icon.CLIPBOARD`},AI={name:E(`Cut`),description:`Ctrl+X`,execute:async e=>{wI(e),await e.clipboard.write(await e.model.getters.getClipboardTextAndImageContent())},icon:`o-spreadsheet-Icon.CUT`},jI={name:E(`Paste`),description:`Ctrl+V`,execute:JP,icon:`o-spreadsheet-Icon.PASTE`},MI={name:E(`Paste special`),isVisible:e=>!e.model.getters.isCutOperation(),icon:`o-spreadsheet-Icon.PASTE`},NI={name:E(`Paste as value`),description:`Ctrl+Shift+V`,execute:YP},PI={name:E(`Paste format only`),execute:ZP},FI={name:E(`Find and replace`),description:`Ctrl+H`,isReadonlyAllowed:!0,execute:e=>{e.openSidePanel(`FindAndReplace`,{})},isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.SEARCH`},II={name:E(`Delete values`),execute:e=>e.model.dispatch(`DELETE_UNFILTERED_CONTENT`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones()})},LI={name:nF,execute:rF,isVisible:e=>iF(`ROW`,e)},RI={...LI,isVisible:NF},zI={name:QP,execute:$P},BI={name:aF,execute:sF,isVisible:e=>iF(`COL`,e)},VI={...BI,isVisible:NF},HI={name:eF,execute:tF},UI={name:E(`Delete cells`),isVisible:NF},WI={name:E(`Delete cell and shift up`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`DELETE_CELL`,{zone:t,shiftDimension:`ROW`}))}},GI={name:E(`Delete cell and shift left`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`DELETE_CELL`,{zone:t,shiftDimension:`COL`}))}},KI={name:E(`Merge cells`),isEnabled:e=>!YI(e),isActive:e=>XI(e),execute:e=>ZI(e),icon:`o-spreadsheet-Icon.MERGE_CELL`},qI={name:()=>E(`Edit table`),execute:e=>e.openSidePanel(`TableSidePanel`,{}),icon:`o-spreadsheet-Icon.EDIT_TABLE`},JI={name:()=>E(`Delete table`),execute:MF,icon:`o-spreadsheet-Icon.DELETE_TABLE`};function YI(e){let t=e.model.getters.getSelectedZones(),{sheetId:n}=e.model.getters.getActivePosition(),{xSplit:r,ySplit:i}=e.model.getters.getPaneDivisions(n);return t.every(e=>nc(e)===1)||ic(t,r,i)||Bs(t)}function XI(e){if(YI(e))return!1;let t=e.model.getters.getActiveSheetId();return e.model.getters.getSelectedZones().some(n=>e.model.getters.getMergesInZone(t,n).length>0)}function ZI(e){if(YI(e))return;let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId();if(XI(e)){let r=t.flatMap(t=>e.model.getters.getMergesInZone(n,t));e.model.dispatch(`REMOVE_MERGE`,{sheetId:n,target:r})}else EI(e,n,t)}let QI={name:e=>{let t=ML(e);return t===1?E(`Insert row`):E(`Insert %s rows`,t.toString())},isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW`},$I={name:e=>{let t=ML(e);return t===1?E(`Insert row above`):E(`Insert %s rows above`,t.toString())},execute:lF,isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW_BEFORE`},eL={...$I,name:e=>{let t=ML(e);return t===1?E(`Row above`):E(`%s Rows above`,t.toString())}},tL={...$I,name:e=>{let t=ML(e);return t===1?E(`Insert row`):E(`Insert %s rows`,t.toString())},isVisible:NF,icon:`o-spreadsheet-Icon.INSERT_ROW_BEFORE`},nL={execute:uF,name:e=>{let t=ML(e);return t===1?E(`Insert row below`):E(`Insert %s rows below`,t.toString())},isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW_AFTER`},rL={...nL,name:e=>{let t=ML(e);return t===1?E(`Row below`):E(`%s Rows below`,t.toString())}},iL={name:e=>{let t=NL(e);return t===1?E(`Insert column`):E(`Insert %s columns`,t.toString())},isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL`},aL={name:e=>{let t=NL(e);return t===1?E(`Insert column left`):E(`Insert %s columns left`,t.toString())},execute:dF,isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL_BEFORE`},oL={...aL,name:e=>{let t=NL(e);return t===1?E(`Column left`):E(`%s Columns left`,t.toString())}},sL={...aL,name:e=>{let t=NL(e);return t===1?E(`Insert column`):E(`Insert %s columns`,t.toString())},isVisible:NF,icon:`o-spreadsheet-Icon.INSERT_COL_BEFORE`},cL={name:e=>{let t=NL(e);return t===1?E(`Insert column right`):E(`Insert %s columns right`,t.toString())},execute:fF,isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL_AFTER`},lL={...cL,name:e=>{let t=NL(e);return t===1?E(`Column right`):E(`%s Columns right`,t.toString())},execute:fF},uL={name:E(`Insert cells`),isVisible:e=>NF(e)&&e.model.getters.getActiveCols().size===0&&e.model.getters.getActiveRows().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL`},dL={name:E(`Insert cells and shift down`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`INSERT_CELL`,{zone:t,shiftDimension:`ROW`}))},isVisible:e=>e.model.getters.getActiveRows().size===0&&e.model.getters.getActiveCols().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL_SHIFT_DOWN`},fL={name:E(`Insert cells and shift right`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`INSERT_CELL`,{zone:t,shiftDimension:`COL`}))},isVisible:e=>e.model.getters.getActiveRows().size===0&&e.model.getters.getActiveCols().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL_SHIFT_RIGHT`},pL={name:E(`Chart`),execute:hF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_CHART`},mL={name:E(`Carousel`),execute:gF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.CAROUSEL`},hL={name:E(`Pivot table`),execute:_F,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.PIVOT`},gL={name:E(`Image`),description:`Ctrl+O`,execute:xF,isVisible:e=>e.imageProvider!==void 0,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_IMAGE`},_L={name:()=>E(`Table`),execute:jF,isVisible:e=>OF(e)&&!e.model.getters.getFirstTableInSelection(),isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.PAINT_TABLE`},vL={name:E(`Function`),icon:`o-spreadsheet-Icon.FORMULA`},yL={name:E(`SUM`),execute:e=>e.startCellEdition(`=SUM(`)},bL={name:E(`AVERAGE`),execute:e=>e.startCellEdition(`=AVERAGE(`)},xL={name:E(`COUNT`),execute:e=>e.startCellEdition(`=COUNT(`)},SL={name:E(`MAX`),execute:e=>e.startCellEdition(`=MAX(`)},CL={name:E(`MIN`),execute:e=>e.startCellEdition(`=MIN(`)},wL={name:E(`All`),children:[TL]};function TL(){return jL(zS.getKeys().filter(e=>!zS.get(e).hidden))}let EL=()=>{let e=zS.content;return[...new Set(zS.getAll().filter(e=>!e.hidden).map(e=>e.category))].filter(C).sort().map((t,n)=>({name:t,children:jL(Object.keys(e).filter(n=>e[n].category===t&&!e[n].hidden))}))},DL={name:E(`Link`),execute:wF,icon:`o-spreadsheet-Icon.INSERT_LINK`},OL={name:E(`Checkbox`),execute:e=>{let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId(),r=t.map(t=>e.model.getters.getRangeDataFromZone(n,t));e.model.dispatch(`ADD_DATA_VALIDATION_RULE`,{ranges:r,sheetId:n,rule:{id:e.model.uuidGenerator.smallUuid(),criterion:{type:`isBoolean`,values:[]}}})},icon:`o-spreadsheet-Icon.INSERT_CHECKBOX`},kL={name:E(`Dropdown list`),execute:e=>{let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId(),r=t.map(t=>e.model.getters.getRangeDataFromZone(n,t)),i=e.model.uuidGenerator.smallUuid();e.model.dispatch(`ADD_DATA_VALIDATION_RULE`,{ranges:r,sheetId:n,rule:{id:i,criterion:{type:`isValueInList`,values:[],displayStyle:`chip`}}});let a=e.model.getters.getDataValidationRule(n,i);a&&e.openSidePanel(`DataValidationEditor`,{rule:wu(a,e.model.getters.getLocale()),onExit:()=>{e.replaceSidePanel(`DataValidation`,`DataValidationEditor`)}})},isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_DROPDOWN`},AL={name:E(`Insert sheet`),execute:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSheetIds().indexOf(t)+1,r=e.model.uuidGenerator.smallUuid();e.model.dispatch(`CREATE_SHEET`,{sheetId:r,position:n,name:e.model.getters.getNextSheetName()}),e.model.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:t,sheetIdTo:r})},icon:`o-spreadsheet-Icon.INSERT_SHEET`};function jL(e){return e.sort().map((e,t)=>({name:e,sequence:t*10,execute:t=>t.startCellEdition(`=${e}(`)}))}function ML(e){let t=e.model.getters.getActiveRows();if(t.size)return t.size;{let t=e.model.getters.getSelectedZones()[0];return t.bottom-t.top+1}}function NL(e){let t=e.model.getters.getActiveCols();if(t.size)return t.size;{let t=e.model.getters.getSelectedZones()[0];return t.right-t.left+1}}let PL=`(previous)`;function FL(e,t){let{colDomain:n,rowDomain:r}=LL(e,t);return[...n,...r.slice(0,r.length-1)]}function IL(e,t){let{colDomain:n,rowDomain:r}=LL(e,t);return[...n.slice(0,n.length-1),...r]}function LL(e,t){let n=e.definition.rows.map(e=>e.nameWithGranularity),r=t.filter(e=>n.includes(e.field)),i=e.definition.columns.map(e=>e.nameWithGranularity);return{colDomain:t.filter(e=>i.includes(e.field)),rowDomain:r}}function RL(e,t,n){return t===`column`?LL(e,n).colDomain:LL(e,n).rowDomain}function zL(e,t){return t.find(t=>t.field===e)?.value}function BL(e,t){for(let n of t)if(e.definition.rows.find(e=>e.nameWithGranularity===n.field)===void 0&&e.definition.columns.find(e=>e.nameWithGranularity===n.field)===void 0)return!1;let{rowDomain:n,colDomain:r}=LL(e,t);return VL(n,e.getExpandedTableStructure().getRowTree())&&VL(r,e.getExpandedTableStructure().getColTree())}function VL(e,t){return HL(e,t)!==void 0}function HL(e,t,n){let r=t;for(let t of e){let e=r.find(e=>e.value===t.value);if(!e)return;if(e.field===n)return r;r=e.children}return r}function UL(e,t,n){let{rowDomain:r,colDomain:i}=LL(e,n);if(KL(e,t)===`row`){let e=r.findIndex(e=>e.field===t);if(e===-1)return n;r=r.slice(0,e+1)}else{let e=i.findIndex(e=>e.field===t);if(e===-1)return n;i=i.slice(0,e+1)}return[...r,...i]}function WL(e,t,n){e=b(e);let r=e.find(e=>e.field===t);return r&&(r.value=n),e}function GL(e,t){return t.some(t=>t.field===e)}function KL(e,t){if(e.definition.rows.map(e=>e.nameWithGranularity).includes(t))return`row`;if(e.definition.columns.map(e=>e.nameWithGranularity).includes(t))return`column`;throw Error(`Field ${t} not found in pivot`)}function qL(e,t,n,r){let i=KL(e,n),a=i===`row`?e.getExpandedTableStructure().getRowTree():e.getExpandedTableStructure().getColTree(),o=HL(RL(e,i,t),a,n)?.map(e=>e.value)??[],s=zL(n,t);if(s===void 0)return;let c=o.indexOf(s);if(!(s===void 0||c===-1))return WL(t,n,o[x(c+(r===`(previous)`?-1:1),0,o.length-1)])}function JL(e){return e?e.map(YL).join(`, `):``}function YL(e){return e?`${e.field}=${e.value}`:``}function XL(e,t){let n=e.findIndex(e=>e.field===t);if(n===-1)return``;let r=e.slice(0,n),i=e.at(-1);return JL(i.field===t?r:[...r,i])}function ZL(e,t){let n=e.findIndex(e=>e.field===t);return n===-1?``:JL([...e.slice(0,n),...e.slice(n+1)])}function QL(e,t,n){let r=[...e],i=[...t];r.sort((e,t)=>n([...i,e],[...i,t]));for(let t of e)t.children=QL(t.children,[...i,t],n);return r}function $L(e,t){return e.length>t.length&&t.every((t,n)=>w(t,e[n]))}var eR=class{measures;columns;rows;sortedColumn;collapsedDomains;customFields;constructor(e,t){this.columns=e.columns.map(e=>this.createPivotDimension(t,e)),this.rows=e.rows.map(e=>this.createPivotDimension(t,e)),this.measures=e.measures.map(e=>this.createMeasure(t,e)),this.sortedColumn=e.sortedColumn,this.collapsedDomains=e.collapsedDomains,this.customFields=e.customFields}getDimension(e){let t=this.columns.find(t=>t.nameWithGranularity===e)||this.rows.find(t=>t.nameWithGranularity===e);if(!t)throw new A(E(`Dimension %s does not exist`,e));return t}getMeasure(e){let t=this.measures.find(t=>t.id===e);if(!t)throw new A(E(`Field %s is not a measure`,e));return t}get invalidAggregatorsForCustomField(){return[]}createMeasure(e,t){let n=t.fieldName,r=n===`__count`?{name:`__count`,string:E(`Count`),type:`integer`,aggregator:`sum`}:e[n],i=t.aggregator,a=!!(r||t.computedBy);for(let t of[...this.rows,...this.columns])if(e[t.fieldName]?.isCustomField&&this.invalidAggregatorsForCustomField.includes(i)){a=!1;break}return{id:t.id,get displayName(){return t.userDefinedName??r?.string??t.fieldName},userDefinedName:t.userDefinedName,fieldName:n,aggregator:i,type:n===`__count`?`integer`:r?.type??`integer`,isValid:a,isHidden:t.isHidden,format:t.format,computedBy:t.computedBy,display:t.display}}createPivotDimension(e,t){let n=e[t.fieldName],r=n?.type??`integer`,i=n&&kd(n)?t.granularity:void 0;return{displayName:n?.string??t.fieldName,nameWithGranularity:t.fieldName+(i?`:${i}`:``),fieldName:t.fieldName,granularity:i,type:n?.isCustomField?`custom`:r,order:t.order,isValid:!!n,isCustomField:!!n?.isCustomField,customGroups:n?.customGroups,parentField:n?.parentField}}},tR=class extends eR{range;constructor(e,t,n){if(super(e,t),e.dataSet){let{sheetId:t,zone:r}=e.dataSet;this.range=n.getRangeFromZone(t,r)}}},nR=class{columns;rows;measures;fieldsType;maxIndent;pivotCells={};rowTree;colTree;isSorted=!1;constructor(e,t,n,r,i={COL:[],ROW:[]}){this.measures=n,this.fieldsType=r,i.COL.length&&(e=this.removeCollapsedColumns(e,n,i.COL)),this.columns=e.map(e=>{let t=1;return e.map(e=>(e={...e,offset:t},t+=e.width,e))}),this.rows=t.filter(e=>!this.isParentCollapsed(i.ROW,e)),this.maxIndent=Math.max(...this.rows.map(e=>e.indent)),this.rowTree=Nt(()=>this.buildRowsTree()),this.colTree=Nt(()=>this.buildColumnsTree())}removeCollapsedColumns(e,t,n){let r=(n,r)=>{let i=this.getDomain(n),a=e[r],o=a.findIndex(e=>$L(this.getDomain(e),i)),s=a.findLastIndex(e=>$L(this.getDomain(e),i)),c=r===e.length-1,l=t.map(e=>({fields:c?[...n.fields,`measure`]:[],values:c?[...n.values,e]:[],width:1,offset:0,collapsedHeader:!c}));a.splice(o,s-o+1,...l)};return e.map((i,a)=>{for(let o of i){if(a>=e.length-2)return i;let s=this.getDomain(o);if(n.some(e=>w(s,e))){o.width=t.length;for(let t=a+1;t<e.length;t++)r(o,t)}}return i})}isParentCollapsed(e,t){let n=this.getDomain(t);return e.some(e=>$L(n,e))}getNumberOfDataColumns(){return this.columns.at(-1)?.length||0}getSkippedRows(e){let t=new Set;if(!e.displayColumnHeaders)for(let e=0;e<this.columns.length-1;e++)t.add(e);return e.displayMeasuresRow||t.add(this.columns.length-1),t}getPivotCells(e={displayColumnHeaders:!0,displayTotals:!0,displayMeasuresRow:!0}){let t=JSON.stringify(e);if(!this.pivotCells[t]){let{displayTotals:n}=e,r=this.rows.length,i=this.getNumberOfDataColumns(),a=this.columns.length+r,o=1+i;!n&&r!==1&&--a,!n&&i!==this.measures.length&&(o-=this.measures.length);let s=[],c=this.getSkippedRows(e);for(let e=0;e<o;e++){s.push([]);for(let t=0;t<a;t++)c.has(t)||s[e].push(this.getPivotCell(e,t,n))}this.pivotCells[t]=s}return this.pivotCells[t]}getRowTree(){return this.rowTree()}getColTree(){return this.colTree()}isTotalRow(e){return this.rows[e].indent!==this.maxIndent}getPivotCell(e,t,n=!0){let r=this.columns.length;if(e>0&&t===r-1){let n=this.getColHeaderDomain(e,t);if(!n)return rR;let r=n.at(-1)?.value?.toString()||``;return{type:`MEASURE_HEADER`,domain:n.slice(0,-1),measure:r}}else if(t<=r-1){let n=this.getColHeaderDomain(e,t);return n?{type:`HEADER`,domain:n,dimension:`COL`}:rR}else if(e===0){let e=t-r;return{type:`HEADER`,domain:this.getDomain(this.rows[e]),dimension:`ROW`}}else{let i=t-r;return!n&&this.isTotalRow(i)?rR:{type:`VALUE`,domain:[...this.getDomain(this.rows[i]),...this.getColDomain(e)],measure:this.getColMeasure(e)}}}getColHeaderDomain(e,t){if(e===0)return;let n=this.columns[t].find(t=>t.offset===e);if(!(!n||n.collapsedHeader))return this.getDomain(n)}getDomain(e){return e.fields.map((t,n)=>{if(t===`measure`)return{type:`char`,field:t,value:Nd({displayName:`measure`,type:`char`},e.values[n])};{let{fieldName:r,granularity:i}=Od(t),a=this.fieldsType[r]||`char`;return{type:a,field:t,value:Nd({displayName:r,type:a,granularity:i},e.values[n])}}})}getColDomain(e){let t=this.getColHeaderDomain(e,this.columns.length-1);return t?t.slice(0,-1):[]}getColMeasure(e){let t=this.getColHeaderDomain(e,this.columns.length-1)?.at(-1)?.value;if(t==null)throw Error(`Measure is missing`);return t.toString()}buildRowsTree(){let e=[],t=0,n={};n[0]=e;for(let r of this.rows){if(r.fields.length===0||r.values.length===0)return e;let i=r.fields.length-1,a=r.fields[i],{fieldName:o,granularity:s}=Od(a),c=Nd({displayName:o,type:this.fieldsType[o]??`char`,granularity:s},r.values[i]);if(i>t){t=i,n[t]=[];let e=n[t-1].at(-1);e&&(e.children=n[t])}t=i;let l={value:c,field:r.fields[i],children:[],type:this.fieldsType[o]||`char`,width:0};n[t].push(l)}return e}buildColumnsTree(){let e=[],t=this.columns.at(-2)||[],n={};n[0]=e;for(let e of t)for(let t=0;t<e.fields.length;t++){let r=e.fields[t],{fieldName:i,granularity:a}=Od(r),o=Nd({displayName:i,type:this.fieldsType[i]??`char`,granularity:a},e.values[t]),s={value:o,field:e.fields[t],children:[],width:e.width,type:this.fieldsType[i]||`char`};n[t]?.at(-1)?.value!==o&&(n[t+1]=[],s.children=n[t+1],n[t].push(s))}return e}export(){return{cols:this.columns,rows:this.rows,measures:this.measures,fieldsType:this.fieldsType}}sort(e,t,n){if(this.isSorted)return;let r=(e,t)=>{let r=n(e,t).value;return typeof r==`number`?r:-1/0},i=t.domain,a=QL(this.rowTree(),[],(n,a)=>{let o=r(e,[...n,...i]),s=r(e,[...a,...i]);return t.order===`asc`?o-s:s-o});this.rowTree=Nt(a),this.rows=[...this.rowTreeToRows(a),this.rows[this.rows.length-1]],this.isSorted=!0}rowTreeToRows(e,t){return e.flatMap(e=>{let n={indent:t?t.indent+1:1,fields:[...t?.fields||[],e.field],values:[...t?.values||[],e.value]};return[n,...this.rowTreeToRows(e.children,n)]})}get numberOfCells(){return this.rows.length*this.getNumberOfDataColumns()}};let rR={type:`EMPTY`};function iR(e,t,n){let r=t.measures.filter(e=>!e.isHidden).map(e=>e.id),i=oR(e,t.columns,0);sR(i,r.length);let a=cR(i,t),o=aR(e,0,t.rows,[],[]);o.push({fields:[],values:[],indent:0});let s={};for(let e of t.columns)s[e.fieldName]=e.type;for(let e of t.rows)s[e.fieldName]=e.type;return new nR(a,o,r,s,n===`collapsed`?t.collapsedDomains:void 0)}function aR(e,t,n,r,i){if(t>=n.length)return[];let a=n[t],o=a.nameWithGranularity,s=lR(e,a),c=dR(s,a),l=[],u=r.concat(o);for(let e of c){let r=i.concat(e);l.push({fields:u,values:r,indent:t+1});let a=s[e];a&&l.push(...aR(a,t+1,n,u,r))}return l}function oR(e,t,n){if(n>=t.length)return[];let r=t[n],i=t[n].nameWithGranularity,a=lR(e,r);return dR(a,t[n]).map(e=>({value:a[e]?.[0]?.[r.nameWithGranularity]?.value??null,field:i,children:oR(a[e]||[],t,n+1),type:r.type,width:0}))}function sR(e,t){for(let n in e){let r=e[n];r.children.length===0?r.width=t:(sR(r.children,t),r.width=r.children.reduce((e,t)=>e+t.width,0))}}function cR(e,t){let n=t.columns.map(e=>e.nameWithGranularity),r=n.length,i=t.measures.filter(e=>!e.isHidden),a=i.length,o=Array(r).fill(0).map(()=>[]);function s(e,t,i){let a=o[t];for(let o of e){let e=i.concat([o.value]),c={fields:n.slice(0,t+1),values:e,width:o.width,offset:0};a.push(c),t<=r-1&&s(o.children,t+1,e)}}s(e,0,[]);let c=n.length>0,l=[];return c&&o[o.length-1].forEach(e=>{i.forEach(t=>{let n={fields:[...e.fields,`measure`],values:[...e.values,t.id],width:1,offset:0};l.push(n)})}),i.forEach(e=>{let t={fields:[`measure`],values:[e.id],width:1,offset:0};l.push(t)}),o.push(l),o.length===1&&o.unshift([]),o[o.length-2].push({fields:[],values:[],width:a,offset:0}),o}function lR(e,t){return Object.groupBy(e,uR(t))}function uR(e){let t=e.nameWithGranularity;return e=>`${e[t]?.value??null}`}function dR(e,t){let n=t.order,r=t.customGroups?.find(e=>e.isOtherGroup);return!n&&!r?Object.keys(e):Object.keys(e).sort((e,i)=>r&&e===r.name?1:r&&i===r.name?-1:n?fR(t,e,i):0)}function fR(e,t,n){return t===`null`?e.order===`asc`?1:-1:n===`null`?e.order===`asc`?-1:1:e.type===`integer`||e.type===`datetime`?e.order===`asc`?M(t,D)-M(n,D):M(n,D)-M(t,D):e.order===`asc`?t.localeCompare(n):n.localeCompare(t)}let pR=Symbol(`NULL`);function mR(e,t,n){let r=e.granularity||`month`;if(!(r in hR))throw Error(`Unknown date granularity: ${r}`);let i=typeof t==`number`||typeof t==`string`?t:pR;if(!hR[r].set.has(t)){hR[r].set.add(t);let a=null;if(typeof t==`number`||typeof t==`string`){let e=F(t,n);switch(r){case`year`:a=e.getFullYear();break;case`quarter_number`:a=Math.floor(e.getMonth()/3)+1;break;case`month_number`:a=e.getMonth()+1;break;case`month`:a=Math.floor(M(t,n));break;case`iso_week_number`:a=e.getIsoWeek();break;case`day_of_month`:a=e.getDate();break;case`day`:a=Math.floor(M(t,n));break;case`day_of_week`:a=(e.getDay()+7-n.weekStart)%7+1;break;case`hour_number`:a=e.getHours();break;case`minute_number`:a=e.getMinutes();break;case`second_number`:a=e.getSeconds();break}}hR[r].values[i]=Nd(e,a)}return hR[r].values[i]}let hR={year:{set:new Set,values:{}},quarter_number:{set:new Set,values:{}},month_number:{set:new Set,values:{}},month:{set:new Set,values:{}},iso_week_number:{set:new Set,values:{}},day_of_month:{set:new Set,values:{}},day:{set:new Set,values:{}},day_of_week:{set:new Set,values:{}},hour_number:{set:new Set,values:{}},minute_number:{set:new Set,values:{}},second_number:{set:new Set,values:{}}};function gR(){for(let e in hR)hR[e].set.clear(),hR[e].values={}}var _R=class{type=`SPREADSHEET`;getters;_definition;coreDefinition;metaData={fields:{},fieldKeys:[]};dataEntries=[];collapsedTable;expandedTable;invalidRangeError;needsReevaluation=!0;constructor(e,t){this.getters=t.getters,this.coreDefinition=t.definition}init(e={}){(!this._definition||e.reload)&&(this.reload(4),this.needsReevaluation=!1)}reload(e){e===4&&(this.metaData=this.loadMetaData()),e>=3&&(this._definition=this.loadRuntimeDefinition()),e>=2&&(this.dataEntries=this.loadData()),e>=1&&(this.collapsedTable=void 0,this.expandedTable=void 0)}onDefinitionChange(e){let t=this.coreDefinition;if(this.coreDefinition=e,this._definition){let n=Math.max(this.computeShouldReload(t,e),0);this.reload(n)}}computeShouldReload(e,t){return w(e.dataSet,t.dataSet)?3:4}get isInvalidRange(){return!!this.invalidRangeError}get invalidRangeMessage(){return this.invalidRangeError?.message}get definition(){if(this._definition||this.init(),!this._definition)throw Error(`Pivot definition should be defined at this point.`);return this._definition}isValid(){if(this.invalidRangeError||!this.definition)return!1;for(let e of this.definition.measures)if(!e.isValid)return!1;for(let e of this.definition.columns)if(!e.isValid)return!1;for(let e of this.definition.rows)if(!e.isValid)return!1;return!0}assertIsValid({throwOnError:e}){if(!this.isValid()){if(e)throw this.invalidRangeError?this.invalidRangeError:new A(E(`At least one measure and/or dimension is not correct.`));return{value:k.GenericError,message:this.invalidRangeError?.message??E(`At least one measure and/or dimension is not correct.`)}}}areDomainArgsFieldsValid(e){let t=e.filter((e,t)=>t%2==0).map(N);return t.length&&t.at(-1)===`measure`&&(t=t.slice(0,-1)),jd(t,this.definition)}parseArgsToPivotDomain(e){let t=[];for(let n=0;n<e.length-1;n+=2){let r=N(e[n]),i=this.getTypeOfDimension(r),a=r===`measure`?N(e[n+1]):Nd(this.getDimension(r),e[n+1]);t.push({field:r,value:a,type:i})}return t}markAsDirtyForEvaluation(){this.needsReevaluation=!0}getMeasure(e){return this.definition.getMeasure(e)}getPivotMeasureValue(e){return{value:this.getMeasure(e).displayName}}getPivotHeaderValueAndFormat(e){let t=e.at(-1);if(!t)return{value:E(`Total`)};let n=this.getDimension(t.field),r=this.filterDataEntriesFromDomain(this.dataEntries,e)[0]?.[n.nameWithGranularity];return n.type===`datetime`?sd(n.granularity||`month`).toValueAndFormat(t.value,this.getters.getLocale()):r?r.value===null?{value:E(`(Undefined)`)}:r:{value:``}}getPivotCellValueAndFormat(e,t){let n=this.filterDataEntriesFromDomain(this.dataEntries,t);if(n.length===0)return{value:``};let r=this.getMeasure(e),i=n.map(e=>e[r.fieldName]).filter(C),a=i.filter(e=>e.type!==`empty`),o=r.aggregator,s=wd[o];if(!s)throw Error(`Aggregator ${o} does not exist`);try{let e=s([i],this.getters.getLocale());return a.length===0?{...e,value:``}:e}catch(e){return VS(e,o.toUpperCase())}}getPossibleFieldValues(e){let t=[],n=lR(this.dataEntries,e),r=dR(n,e);for(let i of r)t.push({value:n[i]?.[0]?.[e.nameWithGranularity]?.value??``,label:n[i]?.[0]?.[e.nameWithGranularity]?.formattedValue||``});return t}getCollapsedTableStructure(){if(!this.isValid())throw Error(`Pivot is not valid !`);return this.collapsedTable||=iR(this.dataEntries,this.definition,`collapsed`),this.collapsedTable}getExpandedTableStructure(){if(!this.isValid())throw Error(`Pivot is not valid !`);return this.expandedTable||=iR(this.dataEntries,this.definition,`expanded`),this.expandedTable}getFields(){return this.metaData.fields}get fields(){return this.getFields()}loadMetaData(){if(this.invalidRangeError=void 0,this.coreDefinition.dataSet){let{zone:e,sheetId:t}=this.coreDefinition.dataSet,n=this.getters.getRangeFromZone(t,e);try{let e=this.extractFieldsFromRange(n),t=Wd(this.coreDefinition,e.fields);return{...e,fields:{...e.fields,...t}}}catch(e){return this.invalidRangeError=e,{fields:{},fieldKeys:[]}}}else return this.invalidRangeError=new A(E(`The pivot cannot be created because the dataset is missing.`)),{fields:{},fieldKeys:[]}}loadRuntimeDefinition(){return new tR(this.coreDefinition,this.fields,this.getters)}loadData(){let e=this._definition?.range;return this.isValid()&&e?this.extractDataEntriesFromRange(e):[]}getTypeOfDimension(e){if(e===`measure`)return`char`;let{fieldName:t}=Od(e),n=this.fields[t]?.type;if(!n)throw Error(`Field ${t} does not exist`);return n}filterDataEntriesFromDomain(e,t){return t.reduce((e,t)=>this.filterDataEntriesFromDomainNode(e,t),e)}filterDataEntriesFromDomainNode(e,t){let{field:n,value:r,type:i}=t,{nameWithGranularity:a}=this.getDimension(n);return e.filter(e=>{let t=e[a]?.value;return i===`char`?String(t)===String(r):t===r})}getDimension(e){return this.definition.getDimension(e)}getTypeFromZone(e,t){let n=this.getters.getEvaluatedCellsInZone(e,t).filter(e=>!(e.type===`empty`||e.value===``));return n.length===0?`integer`:n.every(e=>e.type===`number`&&e.format&&jo(e.format))?`datetime`:n.every(e=>e.type===`boolean`)?`boolean`:n.every(e=>e.type===`number`)?`integer`:`char`}assertCellIsValidField(e,t,n){if(n.type===`error`)throw new A(E(`The pivot cannot be created because cell %s contains an error`,T(e,t)));if(n.type===`empty`||n.value===``)throw new A(E(`The pivot cannot be created because cell %s is empty`,T(e,t)));if(n.value===`__count`)throw new A(E(`The pivot cannot be created because cell %s contains a reserved value`,T(e,t)))}extractFieldsFromRange(e){let t={},n=[],r=e.sheetId,i=e.zone.top;for(let a=e.zone.left;a<=e.zone.right;a++){let o=this.getters.getEvaluatedCell({sheetId:r,col:a,row:i});this.assertCellIsValidField(a,i,o);let s=o.value?.toString();if(s){let i=this.getTypeFromZone(r,{top:e.zone.top+1,left:a,bottom:e.zone.bottom,right:a}),o=Ud(s,t);t[o]={name:o,type:i,string:o,aggregator:i===`integer`?`sum`:`count`},n.push(o)}}return{fields:t,fieldKeys:n}}extractDataEntriesFromRange(e){let t=[];for(let n=e.zone.top+1;n<=e.zone.bottom;n++){let r={top:n,bottom:n,left:e.zone.left,right:e.zone.right},i=this.getters.getEvaluatedCellsInZone(e.sheetId,r),a={};for(let e in i){let t=i[e],n=this.fields[this.metaData.fieldKeys[e]];if(!n)throw Error(`Field ${this.metaData.fieldKeys[e]} does not exist`);t.value===``?a[n.name]={value:null,type:`empty`,formattedValue:``}:a[n.name]=t}for(let e in this.definition.customFields||{}){let t=this.definition.customFields?.[e];if(!t)continue;let n=a[t.parentField],r=this.fields[t.parentField];if(!n||!r){a[e]={value:null,type:`empty`,formattedValue:``};continue}let i=t.groups.find(e=>e.values.some(e=>e===n?.value))||t.groups.find(e=>e.isOtherGroup);a[e]={...n,value:i?i.name:n.value}}a.__count={value:1,type:`number`,formattedValue:`1`},t.push(a)}let n=this.definition.columns.concat(this.definition.rows).filter(e=>e.type===`datetime`);if(n.length){let e=this.getters.getLocale();for(let r of t)for(let t of n){let n=mR(t,r[t.fieldName]?.value||null,this.getters.getLocale()),{format:i,value:a}=sd(t.granularity||`month`).toValueAndFormat(n,e);r[t.nameWithGranularity]={value:n,type:r[t.fieldName]?.type||`empty`,format:r[t.fieldName]?.format,formattedValue:L(a,{locale:e,format:i})}}}return t}};let vR=new g,yR=[`year`,`quarter_number`,`month_number`,`month`,`iso_week_number`,`day_of_month`,`day`,`day_of_week`],bR=[...yR,`hour_number`,`minute_number`,`second_number`];vR.add(`SPREADSHEET`,{ui:_R,definition:tR,dateGranularities:[...yR],isMeasureCandidate:e=>e.type!==`boolean`,datetimeGranularities:[...bR],isGroupable:()=>!0,canHaveCustomGroup:e=>e.type===`char`&&!e.isCustomField,adaptRanges:(e,t,n)=>{if(t.type!==`SPREADSHEET`||!t.dataSet)return t;let{sheetId:r,zone:i}=t.dataSet,a=e.getRangeFromZone(r,i),o=xR(a,n);if(o===a)return t;let s=o&&{sheetId:o.sheetId,zone:o.zone};return{...t,dataSet:s}}});function xR(e,t){if(!e)return;let n=t(e);switch(n.changeType){case`REMOVE`:return;default:return n.range}}let SR={name:E(`See pivot properties`),execute(e){let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);e.openSidePanel(`PivotSidePanel`,{pivotId:n})},isVisible:e=>{let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);return!e.isSmall&&n&&e.model.getters.isExistingPivot(n)||!1},isReadonlyAllowed:!0,icon:`o-spreadsheet-Icon.PIVOT`},CR={name:E(`Ascending`),execute:e=>jR(e,e.model.getters.getActivePosition(),`asc`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`asc`},wR={name:E(`Descending`),execute:e=>jR(e,e.model.getters.getActivePosition(),`desc`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`desc`},TR={name:E(`No sorting`),execute:e=>jR(e,e.model.getters.getActivePosition(),`none`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`none`},ER={name:E(`Convert to individual formulas`),execute(e){let t=e.model.getters.getActivePosition(),n=e.model.getters.getCorrespondingFormulaCell(t),r=e.model.getters.getPivotIdFromPosition(t);if(!n||!r)return;let{sheetId:i,col:a,row:o}=e.model.getters.getCellPosition(n.id),s=e.model.getters.getPivot(r);s.init(),s.isValid()&&e.model.dispatch(`SPLIT_PIVOT_FORMULA`,{sheetId:i,col:a,row:o,pivotId:r})},isVisible:e=>{let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);if(!n)return!1;let r=e.model.getters.getPivot(n),i=e.model.getters.getEvaluatedCell(t);return r.isValid()&&e.model.getters.isSpillPivotFormula(t)&&i.type!==`error`},icon:`o-spreadsheet-Icon.PIVOT`},DR={name:E(`Group pivot dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=b(e.model.getters.getPivotCoreDefinition(n));if(!i.isCustomField)NR(o,r,i,a.getFields());else{let e=(o.customFields||{})[i.name];if(!e)return;PR(e,r)}e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:o})},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n);return r.length>1&&(i.isCustomField||vR.get(a.type).canHaveCustomGroup(i))}},OR={name:E(`Group all remaining dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,field:r}=t,i=e.model.getters.getPivot(n),a=b(e.model.getters.getPivotCoreDefinition(n)),o=r.isCustomField?(a.customFields||{})[r.name]:qd(a,r,i.getFields());o&&(o.groups.push({name:Hd(E(`Others`),o),values:[],isOtherGroup:!0}),Kd(a,r.name,o.name),e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:a}))},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,field:r,values:i}=t;return LR(e,n,i,r)}},kR={name:E(`Ungroup pivot dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=b(e.model.getters.getPivotCoreDefinition(n));FR(o,r,i,a.getFields()),e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:o})},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=e.model.getters.getPivotCoreDefinition(n);if(!i.isCustomField){let e=qd(o,i,a.getFields());if(![...o.rows,...o.columns].some(t=>t.fieldName===e.name))return!1}return IR(o,r,i,a.getFields())}};function AR(e,t){let n=e.getPivotIdFromPosition(t);if(!n||!e.isExistingPivot(n)||!e.isSpillPivotFormula(t)||!e.getPivot(n).isValid())return!1;let r=e.getPivotCellFromPosition(t);return r.type===`VALUE`||r.type===`MEASURE_HEADER`}function jR(e,t,n){let r=e.model.getters.getPivotIdFromPosition(t),i=e.model.getters.getPivotCellFromPosition(t);if(i.type===`EMPTY`||i.type===`HEADER`||!r)return;if(n===`none`){e.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...e.model.getters.getPivotCoreDefinition(r),sortedColumn:void 0}});return}let a=LL(e.model.getters.getPivot(r),i.domain).colDomain;e.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...e.model.getters.getPivotCoreDefinition(r),sortedColumn:{domain:a,order:n,measure:i.measure}}})}function MR(e){let t,n,r=[];for(let i of e.model.getters.getSelectedZones()){let a=e.model.getters.getActiveSheetId();for(let o of qs(a,i)){let i=e.model.getters.getPivotIdFromPosition(o);if(!t)t=i;else if(i&&t!==i)return;if(!t)continue;let a=e.model.getters.getPivotCellFromPosition(o);if(a.type!==`HEADER`||!e.model.getters.isSpillPivotFormula(o))continue;let s=a.domain.at(-1)?.field;if(!n&&s)n=s;else if(n&&s&&n!==s)return;r.push(a)}}if(!t||!n||r.length===0)return;let i=e.model.getters.getPivot(t).getFields()[n];if(!i)return;let a=r.map(e=>e.domain.at(-1)?.value).filter(e=>e!==void 0);return{pivotId:t,values:a,field:i}}function NR(e,t,n,r){let i=qd(e,n,r);Gd(t,i);let a={name:Hd(E(`Group`),i),values:t};i.groups.push(a),e.customFields||={},e.customFields[i.name]=i,Kd(e,n.name,i.name)}function PR(e,t){let n=new Set,r=[];for(let i of t){let t=e.groups.find(e=>e.name===i);t?(r.push(t),t.values.forEach(e=>n.add(e))):n.add(i)}if(r.some(e=>e.isOtherGroup))e.groups=e.groups.filter(e=>e.isOtherGroup||!r.includes(e));else if(r.length===0){let n={name:Hd(E(`Group`),e),values:t};e.groups.push(n)}else{let t=r.slice(1);e.groups=e.groups.filter(e=>!t.includes(e)),r[0].values=Array.from(n)}}function FR(e,t,n,r){let i;if(!n.isCustomField)i=qd(e,n,r),i.groups.some(e=>e.isOtherGroup)&&t.some(e=>!i?.groups.some(t=>t.values.includes(e)))&&(i.groups=i.groups.filter(e=>!e.isOtherGroup)),Gd(t,i);else{if(i=(e.customFields||{})[n.name],!i)return;i.groups=i.groups.filter(e=>!t.includes(e.name))}i.groups.every(e=>e.values.length===0&&!e.isOtherGroup)&&(RR(e,i.name),delete e.customFields?.[i.name])}function IR(e,t,n,r){if(n.isCustomField){let r=(e.customFields||{})[n.name];return r?r.groups.some(e=>t.includes(e.name)):!1}else return qd(e,n,r).groups.some(e=>e.isOtherGroup||t.some(t=>e.values.includes(t)))}function LR(e,t,n,r){let i=e.model.getters.getPivot(t),a=e.model.getters.getPivotCoreDefinition(t),o=r.isCustomField?(a.customFields||{})[r.name]:Object.values(a.customFields||{}).find(e=>e.parentField===r.name),s=i.definition.getDimension(r.name);if(!s||!o||IR(a,n,r,i.getFields()))return!1;let c=new Set(i.getPossibleFieldValues(s).map(e=>e.value)),l=r.isCustomField?o.groups.map(e=>e.name):o.groups.flatMap(e=>e.values);for(let e of[...n,...l])c.delete(e);return c.size===0}function RR(e,t){let n=e.customFields?.[t];if(!n)return;let r=[...e.rows,...e.columns].some(e=>e.fieldName===n.parentField);for(let i of[e.rows,e.columns]){let e=i.findIndex(e=>e.fieldName===t);e!==-1&&(r?i.splice(e,1):i.splice(e,1,{fieldName:n.parentField}))}}let zR=new IA;zR.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`add_row_before`,{...tL,sequence:70}).add(`add_column_before`,{...sL,sequence:90}).add(`insert_cell`,{...uL,sequence:100,separator:!0}).addChild(`insert_cell_down`,[`insert_cell`],{...dL,name:E(`Shift down`),sequence:10}).addChild(`insert_cell_right`,[`insert_cell`],{...fL,name:E(`Shift right`),sequence:20}).add(`delete_row`,{...RI,sequence:110,icon:`o-spreadsheet-Icon.TRASH`}).add(`delete_column`,{...VI,sequence:120,icon:`o-spreadsheet-Icon.TRASH`}).add(`delete_cell`,{...UI,sequence:130,separator:!0,icon:`o-spreadsheet-Icon.TRASH`}).addChild(`delete_cell_up`,[`delete_cell`],{...WI,name:E(`Shift up`),sequence:10,icon:`o-spreadsheet-Icon.DELETE_CELL_SHIFT_UP`}).addChild(`delete_cell_left`,[`delete_cell`],{...GI,name:E(`Shift left`),sequence:20,icon:`o-spreadsheet-Icon.DELETE_CELL_SHIFT_LEFT`}).add(`edit_table`,{...qI,isVisible:DF,isEnabled:e=>!e.isSmall,sequence:140}).add(`delete_table`,{...JI,isVisible:DF,sequence:145,separator:!0}).add(`insert_link`,{...DL,name:TF,sequence:150,separator:!0}).add(`pivot_headers_group`,{sequence:155,icon:`o-spreadsheet-Icon.PLUS_IN_BOX`,...DR}).add(`pivot_group_remaining`,{sequence:155,icon:`o-spreadsheet-Icon.PLUS_IN_BOX`,...OR}).add(`pivot_headers_ungroup`,{sequence:155,icon:`o-spreadsheet-Icon.MINUS_IN_BOX`,...kR}).add(`pivot_sorting`,{name:E(`Sort pivot`),sequence:155,icon:`o-spreadsheet-Icon.SORT_RANGE`,isVisible:e=>{let t=e.model.getters.getActivePosition();return AR(e.model.getters,t)}}).add(`pivot_fix_formulas`,{...ER,sequence:160}).add(`pivot_properties`,{...SR,sequence:170,separator:!0}).addChild(`pivot_sorting_asc`,[`pivot_sorting`],{...CR,sequence:10}).addChild(`pivot_sorting_desc`,[`pivot_sorting`],{...wR,sequence:20}).addChild(`pivot_sorting_none`,[`pivot_sorting`],{...TR,sequence:30});let BR={name:E(`Sort range`),isVisible:NF,icon:`o-spreadsheet-Icon.SORT_RANGE`},VR={name:E(`Ascending (A ⟶ Z)`),execute:e=>{let{anchor:t,zones:n}=e.model.getters.getSelection();yv(e,e.model.getters.getActiveSheetId(),t.cell,n[0],`asc`)},icon:`o-spreadsheet-Icon.SORT_ASCENDING`},HR={name:E(`Data cleanup`),icon:`o-spreadsheet-Icon.DATA_CLEANUP`},UR={name:E(`Remove duplicates`),execute:e=>{nc(e.model.getters.getSelectedZone())===1&&e.model.selection.selectTableAroundSelection(),e.openSidePanel(`RemoveDuplicates`,{})},isEnabled:e=>!e.isSmall},WR={name:E(`Trim whitespace`),execute:e=>{e.model.dispatch(`TRIM_WHITESPACE`)}},GR={name:E(`Descending (Z ⟶ A)`),execute:e=>{let{anchor:t,zones:n}=e.model.getters.getSelection();yv(e,e.model.getters.getActiveSheetId(),t.cell,n[0],`desc`)},icon:`o-spreadsheet-Icon.SORT_DESCENDING`},KR={...FF},qR={...FF,isActive:e=>EF(e)},JR={name:E(`Split text to columns`),sequence:1,execute:e=>e.openSidePanel(`SplitToColumns`,{}),isEnabled:e=>!e.isSmall&&e.model.getters.isSingleColSelected(),icon:`o-spreadsheet-Icon.SPLIT_TEXT`},YR={id:`reinsert_dynamic_pivot`,name:E(`Re-insert dynamic pivot`),sequence:60,icon:`o-spreadsheet-Icon.INSERT_PIVOT`,children:[vF],isVisible:e=>e.model.getters.getPivotIds().some(t=>e.model.getters.getPivot(t).isValid())},XR={id:`reinsert_static_pivot`,name:E(`Re-insert static pivot`),sequence:70,icon:`o-spreadsheet-Icon.INSERT_PIVOT`,children:[yF],isVisible:e=>e.model.getters.getPivotIds().some(t=>e.model.getters.getPivot(t).isValid())};function ZR({name:e,format:t,descriptionValue:n}){let r=typeof t==`function`?t:()=>t;return{name:e,description:e=>L(n,{format:r(e),locale:e.model.getters.getLocale()}),execute:e=>KP(e,r(e)),isActive:e=>Yz(e,r(e)),format:t}}let QR={name:E(`Automatic`),execute:e=>KP(e,``),isActive:e=>Jz(e)},$R={name:E(`Plain text`),execute:e=>KP(e,`@`),isActive:e=>Yz(e,`@`)},ez=ZR({name:E(`Number`),descriptionValue:1000.12,format:`#,##0.00`}),tz={name:E(`Format as percent`),execute:SF,icon:`o-spreadsheet-Icon.PERCENT`},nz=ZR({name:E(`Percent`),descriptionValue:.1012,format:`0.00%`}),rz=ZR({name:E(`Currency`),descriptionValue:1000.12,format:e=>Ro(e.model.config.defaultCurrency||nt)}),iz={...ZR({name:E(`Currency rounded`),descriptionValue:1e3,format:e=>Ho(Ro(e.model.config.defaultCurrency||nt))}),isVisible:e=>{let t=Ro(e.model.config.defaultCurrency||nt);return t!==Ho(t)}},az=ZR({name:E(`Accounting`),descriptionValue:-1000.12,format:e=>zo(e.model.config.defaultCurrency||nt)}),oz=ts(`2023/09/26 10:43:00 PM`,D),sz={name:E(`Custom currency`),isVisible:e=>e.loadCurrencies!==void 0&&!e.isSmall,execute:e=>e.openSidePanel(`CustomCurrency`,{})},cz=ZR({name:E(`Date`),descriptionValue:oz,format:e=>e.model.getters.getLocale().dateFormat}),lz=ZR({name:E(`Time`),descriptionValue:oz,format:e=>e.model.getters.getLocale().timeFormat}),uz=ZR({name:E(`Date time`),descriptionValue:oz,format:e=>Du(e.model.getters.getLocale())}),dz=ZR({name:E(`Duration`),descriptionValue:`27:51:38`,format:`hhhh:mm:ss`}),fz=ZR({name:E(`Quarter`),descriptionValue:oz,format:`qq yyyy`}),pz=ZR({name:E(`Full quarter`),descriptionValue:oz,format:`qqqq yyyy`}),mz={name:E(`More date formats`),execute:e=>e.openSidePanel(`MoreFormats`,{})},hz=ZR({name:E(`Full date time`),format:`dddd d mmmm yyyy hh:mm:ss a`,descriptionValue:oz}),gz=ZR({name:E(`ISO Date`),format:`yyyy-mm-dd`,descriptionValue:oz}),_z=ZR({name:E(`ISO Date time`),format:`yyyy-mm-dd hh:mm:ss`,descriptionValue:oz}),vz=ZR({name:E(`Full week day and month`),format:`dddd d mmmm yyyy`,descriptionValue:oz}),yz=ZR({name:E(`Day and full month`),format:`d mmmm yyyy`,descriptionValue:oz}),bz=ZR({name:E(`Short week day`),format:`ddd d mmm yyyy`,descriptionValue:oz}),xz=ZR({name:E(`Day and short month`),format:`d mmm yyyy`,descriptionValue:oz}),Sz=ZR({name:E(`Full month`),format:`mmmm yyyy`,descriptionValue:oz}),Cz=ZR({name:E(`Short month`),format:`mmm yyyy`,descriptionValue:oz}),wz={name:E(`Increase decimal places`),icon:`o-spreadsheet-Icon.INCREASE_DECIMAL`,execute:e=>e.model.dispatch(`SET_DECIMAL`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),step:1})},Tz={name:E(`Decrease decimal places`),icon:`o-spreadsheet-Icon.DECRASE_DECIMAL`,execute:e=>e.model.dispatch(`SET_DECIMAL`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),step:-1})},Ez={name:E(`Bold`),description:`Ctrl+B`,execute:e=>qP(e,{bold:!e.model.getters.getCurrentStyle().bold}),icon:`o-spreadsheet-Icon.BOLD`,isActive:e=>!!e.model.getters.getCurrentStyle().bold},Dz={name:E(`Italic`),description:`Ctrl+I`,execute:e=>qP(e,{italic:!e.model.getters.getCurrentStyle().italic}),icon:`o-spreadsheet-Icon.ITALIC`,isActive:e=>!!e.model.getters.getCurrentStyle().italic},Oz={name:E(`Underline`),description:`Ctrl+U`,execute:e=>qP(e,{underline:!e.model.getters.getCurrentStyle().underline}),icon:`o-spreadsheet-Icon.UNDERLINE`,isActive:e=>!!e.model.getters.getCurrentStyle().underline},kz={name:E(`Strikethrough`),execute:e=>qP(e,{strikethrough:!e.model.getters.getCurrentStyle().strikethrough}),icon:`o-spreadsheet-Icon.STRIKE`,isActive:e=>!!e.model.getters.getCurrentStyle().strikethrough},Az={name:E(`Font size`),children:qz(),icon:`o-spreadsheet-Icon.FONT_SIZE`},jz={name:E(`Alignment`),icon:`o-spreadsheet-Icon.ALIGN_LEFT`},Mz={name:E(`Horizontal align`),icon:e=>eB(e)},Nz={name:E(`Left`),description:`Ctrl+Shift+L`,execute:e=>qP(e,{align:`left`}),isActive:e=>Zz(e)===`left`,icon:`o-spreadsheet-Icon.ALIGN_LEFT`},Pz={name:E(`Center`),description:`Ctrl+Shift+E`,execute:e=>qP(e,{align:`center`}),isActive:e=>Zz(e)===`center`,icon:`o-spreadsheet-Icon.ALIGN_CENTER`},Fz={name:E(`Right`),description:`Ctrl+Shift+R`,execute:e=>qP(e,{align:`right`}),isActive:e=>Zz(e)===`right`,icon:`o-spreadsheet-Icon.ALIGN_RIGHT`},Iz={name:E(`Vertical align`),icon:e=>tB(e)},Lz={name:E(`Top`),execute:e=>qP(e,{verticalAlign:`top`}),isActive:e=>Qz(e)===`top`,icon:`o-spreadsheet-Icon.ALIGN_TOP`},Rz={name:E(`Middle`),execute:e=>qP(e,{verticalAlign:`middle`}),isActive:e=>Qz(e)===`middle`,icon:`o-spreadsheet-Icon.ALIGN_MIDDLE`},zz={name:E(`Bottom`),execute:e=>qP(e,{verticalAlign:`bottom`}),isActive:e=>Qz(e)===`bottom`,icon:`o-spreadsheet-Icon.ALIGN_BOTTOM`},Bz={name:E(`Wrapping`),icon:`o-spreadsheet-Icon.WRAPPING_OVERFLOW`},Vz={name:E(`Wrapping`),icon:e=>nB(e)},Hz={name:E(`Overflow`),execute:e=>qP(e,{wrapping:`overflow`}),isActive:e=>$z(e)===`overflow`,icon:`o-spreadsheet-Icon.WRAPPING_OVERFLOW`},Uz={name:E(`Wrap`),execute:e=>qP(e,{wrapping:`wrap`}),isActive:e=>$z(e)===`wrap`,icon:`o-spreadsheet-Icon.WRAPPING_WRAP`},Wz={name:E(`Clip`),execute:e=>qP(e,{wrapping:`clip`}),isActive:e=>$z(e)===`clip`,icon:`o-spreadsheet-Icon.WRAPPING_CLIP`};E(`Text Color`),E(`Fill Color`);let Gz={name:E(`Conditional formatting`),execute:CF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.CONDITIONAL_FORMAT`},Kz={name:E(`Clear formatting`),description:`Ctrl+<`,execute:e=>e.model.dispatch(`CLEAR_FORMATTING`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones()}),icon:`o-spreadsheet-Icon.CLEAR_FORMAT`};function qz(){return et.map(e=>({name:e.toString(),sequence:e,id:`font_size_${e}`,execute:t=>qP(t,{fontSize:e}),isActive:t=>Xz(t,e)}))}function Jz(e){let t=e.model.getters.getActivePosition();return e.model.getters.getPivotCellFromPosition(t).type===`VALUE`?!e.model.getters.getEvaluatedCell(t).format:!e.model.getters.getCell(t)?.format}function Yz(e,t){let n=e.model.getters.getActivePosition();return e.model.getters.getPivotCellFromPosition(n).type===`VALUE`?e.model.getters.getEvaluatedCell(n).format===t:e.model.getters.getCell(n)?.format===t}function Xz(e,t){return(e.model.getters.getCurrentStyle().fontSize||Ve)===t}function Zz(e){let t=e.model.getters.getCurrentStyle();return t.align?t.align:e.model.getters.getActiveCell().defaultAlign}function Qz(e){let t=e.model.getters.getCurrentStyle();return t.verticalAlign?t.verticalAlign:ze}function $z(e){let t=e.model.getters.getCurrentStyle();return t.wrapping?t.wrapping:Be}function eB(e){switch(Zz(e)){case`right`:return`o-spreadsheet-Icon.ALIGN_RIGHT`;case`center`:return`o-spreadsheet-Icon.ALIGN_CENTER`;default:return`o-spreadsheet-Icon.ALIGN_LEFT`}}function tB(e){switch(Qz(e)){case`top`:return`o-spreadsheet-Icon.ALIGN_TOP`;case`middle`:return`o-spreadsheet-Icon.ALIGN_MIDDLE`;default:return`o-spreadsheet-Icon.ALIGN_BOTTOM`}}function nB(e){switch($z(e)){case`wrap`:return`o-spreadsheet-Icon.WRAPPING_WRAP`;case`clip`:return`o-spreadsheet-Icon.WRAPPING_CLIP`;default:return`o-spreadsheet-Icon.WRAPPING_OVERFLOW`}}let rB=new IA;rB.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`sort_columns`,{...BR,name:e=>e.model.getters.getActiveCols().size>1?E(`Sort columns`):E(`Sort column`),sequence:50,separator:!0}).addChild(`sort_ascending`,[`sort_columns`],{...VR,sequence:10}).addChild(`sort_descending`,[`sort_columns`],{...GR,sequence:20}).add(`add_column_before`,{...aL,sequence:70}).add(`add_column_after`,{...cL,sequence:80}).add(`delete_column`,{...BI,sequence:90,icon:`o-spreadsheet-Icon.TRASH`}).add(`clear_column`,{...HI,sequence:100,icon:`o-spreadsheet-Icon.CLEAR`}).add(`hide_columns`,{...VF,sequence:105,separator:!0}).add(`unhide_columns`,{...HF,sequence:106,separator:!0}).add(`conditional_formatting`,{...Gz,sequence:110,separator:!0}).add(`edit_table`,{...qI,isVisible:DF,sequence:120}).add(`delete_table`,{...JI,isVisible:DF,sequence:125,separator:!0}).add(`group_columns`,{sequence:150,...oI}).add(`ungroup_columns`,{sequence:155,...cI,isVisible:e=>fI(e,`COL`)});let iB={CannotHideAllRows:E(`Cannot hide all the rows of a sheet.`),CannotHideAllColumns:E(`Cannot hide all the columns of a sheet.`)};function aB(e,t,n,r,i){let a=e.model.getters.getHeaderGroup(t,n,r,i);if(!a)return;let o=a.isFolded?`UNFOLD_HEADER_GROUP`:`FOLD_HEADER_GROUP`,s=e.model.dispatch(o,{sheetId:t,dimension:n,start:a.start,end:a.end});if(!s.isSuccessful&&s.isCancelledBecause(`NotEnoughElements`)){let t=n===`ROW`?iB.CannotHideAllRows:iB.CannotHideAllColumns;e.raiseError(t)}}function oB(e,t){return f([{id:`unfold_all`,name:E(t===`ROW`?`Expand all row groups`:`Expand all column groups`),execute:n=>{n.model.dispatch(`UNFOLD_ALL_HEADER_GROUPS`,{sheetId:e,dimension:t})}},{id:`fold_all`,name:E(t===`ROW`?`Collapse all row groups`:`Collapse all column groups`),execute:n=>{n.model.dispatch(`FOLD_ALL_HEADER_GROUPS`,{sheetId:e,dimension:t})}}])}function sB(e,t,n,r){return[...f([{id:`toggle_group`,name:e=>{let i=e.model.getters.getActiveSheetId();return e.model.getters.isGroupFolded(i,t,n,r)?E(t===`ROW`?`Expand row group`:`Expand column group`):E(t===`ROW`?`Collapse row group`:`Collapse column group`)},execute:e=>{aB(e,e.model.getters.getActiveSheetId(),t,n,r)}},{id:`remove_group`,name:E(t===`ROW`?`Remove row group`:`Remove column group`),execute:e=>{let i=e.model.getters.getActiveSheetId();e.model.dispatch(`UNGROUP_HEADERS`,{sheetId:i,dimension:t,start:n,end:r})},separator:!0}]),...oB(e,t)]}let cB=new IA;cB.add(`group_columns`,{sequence:10,...oI,isVisible:()=>!0,isEnabled:oI.isVisible}).add(`group_rows`,{sequence:20,...sI,isVisible:()=>!0,isEnabled:sI.isVisible});let lB=new IA;lB.add(`ungroup_columns`,{sequence:10,...cI,isEnabled:e=>fI(e,`COL`)}).add(`ungroup_rows`,{sequence:20,...lI,isEnabled:e=>fI(e,`ROW`)});let uB=new IA;uB.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`add_row_before`,{...$I,sequence:50}).add(`add_row_after`,{...nL,sequence:60}).add(`delete_row`,{...LI,sequence:70,icon:`o-spreadsheet-Icon.TRASH`}).add(`clear_row`,{...zI,sequence:80,icon:`o-spreadsheet-Icon.CLEAR`}).add(`hide_rows`,{...WF,sequence:85,separator:!0}).add(`unhide_rows`,{...GF,sequence:86,separator:!0}).add(`conditional_formatting`,{...Gz,sequence:90,separator:!0}).add(`group_rows`,{sequence:100,...sI}).add(`ungroup_rows`,{sequence:110,...lI,isVisible:e=>fI(e,`ROW`)});var dB=class extends bf{highlightStore=this.get(Kk);constructor(e){super(e),this.highlightStore.register(this)}get highlights(){let e=this.model.getters.getActivePosition(),t=this.model.getters.getArrayFormulaSpreadingOn(e),n=t?this.model.getters.getSpreadZone(t,{ignoreSpillError:!0}):this.model.getters.getSpreadZone(e,{ignoreSpillError:!0});if(!n)return[];let r=this.model.getters.isArrayFormulaSpillBlocked(t??e);return[{range:this.model.getters.getRangeFromZone(e.sheetId,n),dashed:r,color:`#17A2B8`,noFill:!0,thinLine:!0}]}},fB=class extends bf{mutators=[`focusClient`,`unfocusClient`,`showClientTag`,`hideClientTag`,`jumpToClient`];_showClientTag=!1;clientFocusTimeout={};constructor(e){super(e),this.onDispose(()=>{for(let e in this.clientFocusTimeout)this.unfocusClient(e)})}get focusedClients(){let e=new Set;return this.model.getters.getConnectedClients().forEach(t=>{(this._showClientTag||this.clientFocusTimeout[t.id]!==void 0)&&e.add(t.id)}),e}jumpToClient(e){let t=this.model.getters.getClient(e);this.focusClient(e),t.position&&(this.model.dispatch(`ACTIVATE_SHEET`,{sheetIdTo:t.position.sheetId,sheetIdFrom:this.getters.getActiveSheetId()}),this.model.dispatch(`SCROLL_TO_CELL`,{col:t.position.col,row:t.position.row}))}showClientTag(){this._showClientTag=!0}hideClientTag(){this._showClientTag=!1}focusClient(e){this.clientFocusTimeout[e]&&clearTimeout(this.clientFocusTimeout[e]),this.clientFocusTimeout[e]=setTimeout(()=>this.unfocusClient(e),3e3)}unfocusClient(e){this.clientFocusTimeout[e]&&clearTimeout(this.clientFocusTimeout[e]),this.clientFocusTimeout[e]=void 0}};function pB(e){let n=null,r,i,a,o,s=`all`,c=e.model.getters,l=[],u=()=>{clearTimeout(n),n=null,l.forEach(e=>e()),l=[]},d,f,p=t=>{if(r=t,n)return;let l=c.getActiveSheetId(),u=qw(),{x:f,y:m}=c.getMainViewportCoordinates(),{top:h,left:g,bottom:_,right:v}=c.getActiveMainViewport(),{scrollX:y,scrollY:ee}=c.getActiveSheetScrollInfo(),{xSplit:te,ySplit:ne}=c.getPaneDivisions(l),re=!1,ie=140,ae=r.clientX-u.left,oe=c.getColIndex(ae);if(s!==`vertical`){let t=i.clientX-u.left,n=c.getEdgeScrollCol(ae,t,a);if(n.canEdgeScroll){re=!0,ie=Math.min(ie,n.delay);let t=oe;switch(n.direction){case`reset`:oe=t=te;break;case 1:oe=v,t=g+1;break;case-1:for(oe=g-1;e.model.getters.isColHidden(l,oe);)oe--;t=oe;break}y=c.getColDimensions(l,t).start-f}}let se=r.clientY-u.top,ce=c.getRowIndex(se);if(s!==`horizontal`){let t=i.clientY-u.top,n=c.getEdgeScrollRow(se,t,o);if(n.canEdgeScroll){re=!0,ie=Math.min(ie,n.delay);let t=ce;switch(n.direction){case`reset`:ce=t=ne;break;case 1:ce=_,t=h+1;break;case-1:for(ce=h-1;e.model.getters.isRowHidden(l,ce);)ce--;t=ce;break}ee=e.model.getters.getRowDimensions(l,t).start-m}}re||(oe=mB(oe,ae,c.getNumberCols(l)-1),ce=mB(ce,se,c.getNumberRows(l)-1)),d?.(oe,ce,r),re&&(e.model.dispatch(`SET_VIEWPORT_OFFSET`,{offsetX:y,offsetY:ee}),n=setTimeout(()=>{n=null,p(r)},Math.round(ie))),i={clientX:r.clientX,clientY:r.clientY}},m=()=>{f?.(),u()};return(0,t.onWillUnmount)(()=>{u()}),(0,t.useEffect)(()=>{u()},()=>[c.getActiveSheetId()]),{start:(e,t,n,r=`all`)=>{u();let c=qw();s=r,a=e.clientX-c.left,o=e.clientY-c.top,i={clientX:e.clientX,clientY:e.clientY},d=t,f=n,l.push(rA(p,m))}}}function mB(e,t,n){return e===-1?t<0?0:n:e}B`
|
|
836
|
+
`))}extractAttr(e,t,n){let r=e.attributes[t];r||this.handleMissingValue(e,`attribute "${t}"`,n);let i=r?.value?r.value:n?.default;return i===void 0?void 0:new ZN(i)}extractTextContent(e,t){if(t?.default!==void 0&&typeof t.default!=`string`)throw Error(`extractTextContent default value should be a string`);let n=e?.attributes[`xml:space`]?.value===`preserve`,r=e?.textContent;return(!e||r===null)&&this.handleMissingValue(e,`text content`,t),r&&=n?r:r.trim(),r?Hj(r):t?.default}extractChildAttr(e,t,n,r){let i;i=typeof t==`number`?e.children[t]:this.querySelector(e,t),i||this.handleMissingValue(e,typeof t==`number`?`child at index ${t}`:`child <${t}>`,r);let a=i?this.extractAttr(i,n,r)?.asString():r?.default;return a===void 0?void 0:new ZN(a)}extractChildTextContent(e,t,n){if(n?.default!==void 0&&typeof n.default!=`string`)throw Error(`extractTextContent default value should be a string`);let r=this.querySelector(e,t);return r||this.handleMissingValue(e,`child <${t}>`,n),r?this.extractTextContent(r,n):n?.default}handleMissingValue(e,t,n){if(n?.required)if(n?.default!==void 0)this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${n.default}`);else throw Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`)}extractColor(e,t,n){if(!e)return n?{rgb:n}:void 0;let r=this.extractAttr(e,`theme`)?.asString(),i;if(r!==void 0){if(!t||!t.clrScheme)throw Error(`Color referencing a theme but no theme was provided`);i=this.getThemeColor(r,t.clrScheme)}else i=this.extractAttr(e,`rgb`)?.asString(),i=i===`FF000000`?void 0:i;return{rgb:i||n,auto:this.extractAttr(e,`auto`)?.asBool(),indexed:this.extractAttr(e,`indexed`)?.asNum(),tint:this.extractAttr(e,`tint`)?.asNum()}}getTargetXmlFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.getListOfXMLFiles().find(e=>e.file.fileName.endsWith(t));if(!n||!n.file)throw Error(`Cannot find target file`);return n}getTargetImageFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.xlsxFileStructure.images.find(e=>e.fileName.endsWith(t));if(!n)throw Error(`Cannot find target file`);return n}querySelector(e,t){let n=FO(t);return e.querySelector(n)}querySelectorAll(e,t){let n=FO(t);return e.querySelectorAll(n)}getThemeColor(e,t){switch(e){case`0`:return`FFFFFF`;case`1`:return`000000`;case`2`:return t[3].value;case`3`:return t[2].value;default:return t[e].value}}processRelationshipTargetName(e){return e.replace(/\.+\//,``)}},$N=class extends QN{getTheme(){return{clrScheme:this.mapOnElements({query:`a:clrScheme`,parent:this.rootFile.file.xml,children:!0},e=>({name:e.tagName,value:this.extractChildAttr(e,0,`val`,{required:!0,default:Vf}).asString(),lastClr:this.extractChildAttr(e,0,`lastClr`,{default:Vf}).asString()}))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`si`},e=>this.mapOnElements({parent:e,query:`t`},e=>this.extractTextContent(e)||``).join(``))}},eP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}extractConditionalFormattings(){let e=this.mapOnElements({parent:this.rootFile.file.xml,query:`worksheet > conditionalFormatting`},e=>({sqref:this.extractAttr(e,`sqref`,{required:!0}).asString().split(` `),pivot:this.extractAttr(e,`pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:`extLst x14:conditionalFormatting`},e=>({sqref:this.extractChildTextContent(e,`xm:sqref`,{required:!0}).split(` `),pivot:this.extractAttr(e,`xm:pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:`cfRule, x14:cfRule`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),priority:this.extractAttr(e,`priority`,{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:this.extractAttr(e,`dxfId`)?.asNum(),stopIfTrue:this.extractAttr(e,`stopIfTrue`)?.asBool(),aboveAverage:this.extractAttr(e,`aboveAverage`)?.asBool(),percent:this.extractAttr(e,`percent`)?.asBool(),bottom:this.extractAttr(e,`bottom`)?.asBool(),operator:this.extractAttr(e,`operator`)?.asString(),text:this.extractAttr(e,`text`)?.asString(),timePeriod:this.extractAttr(e,`timePeriod`)?.asString(),rank:this.extractAttr(e,`rank`)?.asNum(),stdDev:this.extractAttr(e,`stdDev`)?.asNum(),equalAverage:this.extractAttr(e,`equalAverage`)?.asBool(),dataBar:this.extractCfDataBar(e,t)}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:`formula`},e=>this.extractTextContent(e,{required:!0}))}extractCfColorScale(e,t){let n=this.querySelector(e,`colorScale`);if(n)return{colors:this.mapOnElements({parent:n,query:`color`},e=>this.extractColor(e,t,`ffffff`)),cfvos:this.extractCFVos(n)}}extractCfDataBar(e,t){let n=this.querySelector(e,`dataBar`);if(n)return{color:this.extractColor(n.querySelector(`color`),t,`EFF7FF`),cfvos:this.extractCFVos(n)}}extractCfIconSet(e){let t=this.querySelector(e,`iconSet, x14:iconSet`);if(t)return{iconSet:this.extractAttr(t,`iconSet`,{default:`3TrafficLights1`}).asString(),showValue:this.extractAttr(t,`showValue`,{default:!0}).asBool(),percent:this.extractAttr(t,`percent`,{default:!0}).asBool(),reverse:this.extractAttr(t,`reverse`)?.asBool(),custom:this.extractAttr(t,`custom`)?.asBool(),cfvos:this.extractCFVos(t),cfIcons:this.extractCfIcons(t)}}extractCfIcons(e){let t=this.mapOnElements({parent:e,query:`cfIcon, x14:cfIcon`},e=>({iconSet:this.extractAttr(e,`iconSet`,{required:!0}).asString(),iconId:this.extractAttr(e,`iconId`,{required:!0}).asNum()}));return t.length===0?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:`cfvo, x14:cfvo`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),gte:this.extractAttr(e,`gte`,{default:!0})?.asBool(),value:e.attributes.val?this.extractAttr(e,`val`)?.asString():this.extractChildTextContent(e,`f, xm:f`)}))}},tP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}extractDataValidations(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`worksheet > dataValidations > dataValidation`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),operator:this.extractAttr(e,`operator`,{default:`between`})?.asString(),sqref:this.extractAttr(e,`sqref`,{required:!0}).asString().split(` `),errorStyle:this.extractAttr(e,`errorStyle`)?.asString(),formula1:this.extractDataValidationFormula(e,1)[0],formula2:this.extractDataValidationFormula(e,2)[0],showErrorMessage:this.extractAttr(e,`showErrorMessage`)?.asBool(),errorTitle:this.extractAttr(e,`errorTitle`)?.asString(),error:this.extractAttr(e,`error`)?.asString(),showInputMessage:this.extractAttr(e,`showInputMessage`)?.asBool(),promptTitle:this.extractAttr(e,`promptTitle`)?.asString(),prompt:this.extractAttr(e,`prompt`)?.asString(),allowBlank:this.extractAttr(e,`allowBlank`)?.asBool()}))}extractDataValidationFormula(e,t){return this.mapOnElements({parent:e,query:`formula${t}`},e=>this.extractTextContent(e,{required:!0}))}},nP=class extends QN{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`c:chartSpace`},e=>{let t=this.getChartType(e);if(!cM[t])throw Error(`Unsupported chart type ${t}`);if(cM[t]===`combo`)return this.extractComboChart(e);let n=this.mapOnElements({parent:e,query:`c:chart > c:title a:t`},e=>e.textContent||``).join(``),r=this.extractChildAttr(e,`c:grouping`,`val`,{default:`clustered`}).asString(),i=this.extractChildAttr(e,`c:barDir`,`val`,{default:`col`}).asString(),a=this.extractChildAttr(e,`c:holeSize`,`val`,{default:`0`}).asNum();return{title:{text:n},type:cM[t],dataSets:this.extractChartDatasets(this.querySelectorAll(e,`c:${t}`),t),labelRange:this.extractLabelRange(t,e),backgroundColor:this.extractChildAttr(e,`c:chartSpace > c:spPr a:srgbClr`,`val`,{default:`ffffff`}).asString(),legendPosition:sM[this.extractChildAttr(e,`c:legendPos`,`val`,{default:`none`}).asString()],stacked:r===`stacked`,fontColor:`000000`,horizontal:i===`bar`,isDoughnut:a>0,pieHolePercentage:a}})[0]}extractLabelRange(e,t){return e===`scatterChart`?this.extractChildTextContent(t,`c:ser c:strRef c:f`)||this.extractChildTextContent(t,`c:ser c:numRef c:f`):this.extractChildTextContent(t,`c:ser c:cat c:f`)}extractComboChart(e){let t=this.mapOnElements({parent:e,query:`c:title a:t`},e=>e.textContent||``).join(``),n=this.extractChildAttr(e,`c:grouping`,`val`,{default:`clustered`}).asString();return{title:{text:t},type:`combo`,dataSets:[...this.extractChartDatasets(this.querySelectorAll(e,`c:barChart`),`comboChart`),...this.extractChartDatasets(this.querySelectorAll(e,`c:lineChart`),`comboChart`)],labelRange:this.extractChildTextContent(e,`c:ser c:cat c:f`),backgroundColor:this.extractChildAttr(e,`c:chartSpace > c:spPr a:srgbClr`,`val`,{default:`ffffff`}).asString(),legendPosition:sM[this.extractChildAttr(e,`c:legendPos`,`val`,{default:`none`}).asString()],stacked:n===`stacked`,fontColor:`000000`}}extractChartDatasets(e,t){return Array.from(e).map(e=>t===`scatterChart`?this.extractScatterChartDatasets(e):this.mapOnElements({parent:e,query:`c:ser`},e=>{let t={},n=this.extractChildTextContent(e,`c:tx c:f`);if(n)t={reference:n};else{let n=this.extractChildTextContent(e,`c:tx c:v`);n&&(t={text:n})}let r=this.querySelectorAll(e,`c:spPr a:solidFill`),i=r.length?this.querySelector(r[0],`a:srgbClr`):void 0,a=i?i.getAttribute(`val`):void 0;return{label:t,range:this.extractChildTextContent(e,`c:val c:f`,{required:!0}),backgroundColor:a&&mn(a)?`${pn(a)}`:void 0,trend:this.extractChartTrendline(e)}})).flat()}extractChartTrendline(e){let t=this.querySelector(e,`c:trendline`);if(!t)return;let n=this.extractChildAttr(t,`c:trendlineType`,`val`),r=this.extractChildAttr(t,`a:solidFill a:srgbClr`,`val`);return{type:n?n.asString():void 0,order:this.extractChildAttr(t,`c:order`,`val`)?.asNum(),window:this.extractChildAttr(t,`c:period`,`val`)?.asNum(),color:r&&mn(r.asString())?`${pn(r.asString())}`:void 0}}extractScatterChartDatasets(e){return this.mapOnElements({parent:e,query:`c:ser`},e=>{let t={},n=this.querySelectorAll(e,`c:spPr a:solidFill a:srgbClr`),r=n.length?n[0].getAttribute(`val`):void 0,i=this.extractChildTextContent(e,`c:tx c:f`);if(i)t={reference:i};else{let n=this.extractChildTextContent(e,`c:tx c:v`);n&&(t={text:n})}return{label:t,range:this.extractChildTextContent(e,`c:yVal c:f`,{required:!0}),trend:this.extractChartTrendline(e),backgroundColor:r&&mn(r)?`${pn(r)}`:void 0}})}getChartType(e){let t=this.querySelector(e,`c:plotArea`);if(!t)throw Error(`Missing plot area in the chart definition.`);let n;for(let e of t.children){let t=NO(e.tagName);TO.some(e=>e===t)&&(n?n!==t&&(n=`comboChart`):n=t)}if(n)return n;throw Error(`Unknown chart type`)}};let rP=`oneCellAnchor`,iP=`twoCellAnchor`;var aP=class extends QN{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`xdr:wsDr`,children:!0},e=>{let t=NO(e.tagName),n=this.extractFigureAnchorsByType(e,t),r=this.querySelector(e,`c:chart`),i=this.querySelector(e,`a:blip`);if(!r&&!i)throw Error(`Only chart and image figures are currently supported.`);return{anchors:n,data:r?this.extractChart(r):this.extractImage(e),figureSize:t===rP?this.extractFigureSizeFromSizeTag(e,`xdr:ext`):void 0}})}extractFigureAnchorsByType(e,t){switch(t){case rP:return[this.extractFigureAnchor(`xdr:from`,e)];case iP:return[this.extractFigureAnchor(`xdr:from`,e),this.extractFigureAnchor(`xdr:to`,e)];default:throw Error(`${t} is not supported for xlsx drawings. `)}}extractFigureSizeFromSizeTag(e,t){let n=this.querySelector(e,t);if(!n)throw Error(`Missing size element '${t}'`);return{cx:this.extractAttr(n,`cx`,{required:!0}).asNum(),cy:this.extractAttr(n,`cy`,{required:!0}).asNum()}}extractFigureAnchor(e,t){let n=this.querySelector(t,e);if(!n)throw Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(n,`xdr:col`,{required:!0})),colOffset:Number(this.extractChildTextContent(n,`xdr:colOff`,{required:!0})),row:Number(this.extractChildTextContent(n,`xdr:row`,{required:!0})),rowOffset:Number(this.extractChildTextContent(n,`xdr:rowOff`,{required:!0}))}}extractChart(e){let t=this.extractAttr(e,`r:id`,{required:!0}).asString(),n=new nP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractChart();if(!n)throw Error(`Unable to extract chart definition`);return n}extractImage(e){let t=this.querySelector(e,`a:blip`),n=this.extractAttr(t,`r:embed`,{required:!0}).asString(),r=this.getTargetImageFile(this.relationships[n]);if(!r)throw Error(`Unable to extract image`);let i=r.fileName.split(`.`).at(-1),a=NO(e.tagName),o=a===iP?this.querySelector(e,`a:xfrm`):e,s=a===iP?`a:ext`:`xdr:ext`,c=this.extractFigureSizeFromSizeTag(o,s);return{imageSrc:r.imageSrc,mimetype:i?hM[i]:void 0,size:c}}},oP=class extends QN{getPivotTable(){return this.mapOnElements({query:`:root`,parent:this.rootFile.file.xml},e=>({name:this.extractAttr(e,`name`,{required:!0}).asString(),rowGrandTotals:this.extractAttr(e,`rowGrandTotals`,{default:!0}).asBool(),location:this.extractPivotLocation(e),style:this.extractPivotStyleInfo(e)}))[0]}extractPivotLocation(e){return this.mapOnElements({query:`location`,parent:e},e=>({ref:this.extractAttr(e,`ref`,{required:!0}).asString(),firstHeaderRow:this.extractAttr(e,`firstHeaderRow`,{required:!0}).asNum(),firstDataRow:this.extractAttr(e,`firstDataRow`,{required:!0}).asNum(),firstDataCol:this.extractAttr(e,`firstDataCol`,{required:!0}).asNum()}))[0]}extractPivotStyleInfo(e){return this.mapOnElements({query:`pivotTableStyleInfo`,parent:e},e=>({name:this.extractAttr(e,`name`,{required:!0}).asString(),showRowHeaders:this.extractAttr(e,`showRowHeaders`,{required:!0}).asBool(),showColHeaders:this.extractAttr(e,`showColHeaders`,{required:!0}).asBool(),showRowStripes:this.extractAttr(e,`showRowStripes`,{required:!0}).asBool(),showColStripes:this.extractAttr(e,`showColStripes`,{required:!0}).asBool(),showLastColumn:this.extractAttr(e,`showLastColumn`)?.asBool()}))[0]}},sP=class extends QN{getTable(){return this.mapOnElements({query:`table`,parent:this.rootFile.file.xml},e=>({displayName:this.extractAttr(e,`displayName`,{required:!0}).asString(),name:this.extractAttr(e,`name`)?.asString(),id:this.extractAttr(e,`id`,{required:!0}).asString(),ref:this.extractAttr(e,`ref`,{required:!0}).asString(),headerRowCount:this.extractAttr(e,`headerRowCount`,{default:1}).asNum(),totalsRowCount:this.extractAttr(e,`totalsRowCount`,{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}))[0]}extractTableCols(e){return this.mapOnElements({query:`tableColumn`,parent:e},e=>({id:this.extractAttr(e,`id`,{required:!0}).asString(),name:this.extractAttr(e,`name`,{required:!0}).asString(),colFormula:this.extractChildTextContent(e,`calculatedColumnFormula`)}))}extractTableStyleInfo(e){return this.mapOnElements({query:`tableStyleInfo`,parent:e},e=>({name:this.extractAttr(e,`name`)?.asString(),showFirstColumn:this.extractAttr(e,`showFirstColumn`)?.asBool(),showLastColumn:this.extractAttr(e,`showLastColumn`)?.asBool(),showRowStripes:this.extractAttr(e,`showRowStripes`)?.asBool(),showColumnStripes:this.extractAttr(e,`showColumnStripes`)?.asBool()}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:`autoFilter`,parent:e},e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,`ref`,{required:!0}).asString()}))[0]}extractFilterColumns(e){return this.mapOnElements({query:`tableColumn`,parent:e},t=>({colId:this.extractAttr(e,`colId`,{required:!0}).asNum(),hiddenButton:this.extractAttr(e,`hiddenButton`,{default:!1}).asBool(),filters:this.extractSimpleFilter(t)}))}extractSimpleFilter(e){return this.mapOnElements({query:`filter`,parent:e},e=>({val:this.extractAttr(e,`val`,{required:!0}).asString()}))}},cP=class extends QN{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}getSheet(){return this.mapOnElements({query:`worksheet`,parent:this.rootFile.file.xml},e=>{let t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),sheetProperties:this.extractSheetProperties(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),dataValidations:this.extractDataValidations(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:this.extractTables(e),pivotTables:this.extractPivotTables(),isVisible:t.state===`visible`}})[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:`sheetView`},e=>{let t=this.querySelector(e,`pane`);return{tabSelected:this.extractAttr(e,`tabSelected`,{default:!1}).asBool(),showFormulas:this.extractAttr(e,`showFormulas`,{default:!1}).asBool(),showGridLines:this.extractAttr(e,`showGridLines`,{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,`showRowColHeaders`,{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,`xSplit`,{default:0}).asNum():0,ySplit:t?this.extractAttr(t,`ySplit`,{default:0}).asNum():0}}})}extractSheetName(){let e=Bj(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find(t=>t.target===e).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,`sheet`))if(e.attributes[`r:id`].value===t)return e.attributes.name.value;throw Error(`Missing sheet name`)}getSheetWorkbookInfo(){let e=Bj(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find(t=>t.target===e).id,n=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:`sheet`},e=>({relationshipId:this.extractAttr(e,`r:id`,{required:!0}).asString(),sheetId:this.extractAttr(e,`sheetId`,{required:!0}).asString(),sheetName:this.extractAttr(e,`name`,{required:!0}).asString(),state:this.extractAttr(e,`state`,{default:`visible`}).asString()})).find(e=>e.relationshipId===t);if(!n)throw Error(`Cannot find corresponding workbook sheet`);return n}extractConditionalFormats(){return new eP(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractDataValidations(){return new tP(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractDataValidations()}extractFigures(e){return this.mapOnElements({parent:e,query:`drawing`},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new aP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractFigures()})[0]||[]}extractTables(e){return this.mapOnElements({query:`tablePart`,parent:e},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new sP(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).getTable()})}extractPivotTables(){try{return Object.values(this.relationships).filter(e=>e.type.endsWith(`pivotTable`)).map(e=>new oP(this.getTargetXmlFile(e),this.xlsxFileStructure,this.warningManager).getPivotTable())}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:`mergeCell`},e=>this.extractAttr(e,`ref`,{required:!0}).asString())}extractSheetFormat(e){let t=this.querySelector(e,`sheetFormatPr`);if(t)return{defaultColWidth:this.extractAttr(t,`defaultColWidth`,{default:`8.43`}).asNum(),defaultRowHeight:this.extractAttr(t,`defaultRowHeight`,{default:`12.75`}).asNum()}}extractSheetProperties(e){let t=this.querySelector(e,`sheetPr`);if(t)return{outlinePr:this.extractSheetOutlineProperties(t),tabColor:this.extractColor(this.querySelector(t,`tabColor`),this.theme)}}extractSheetOutlineProperties(e){let t=this.querySelector(e,`outlinePr`);if(t)return{summaryBelow:this.extractAttr(t,`summaryBelow`,{default:!0}).asBool(),summaryRight:this.extractAttr(t,`summaryRight`,{default:!0}).asBool()}}extractCols(e){return this.mapOnElements({parent:e,query:`cols col`},e=>({width:this.extractAttr(e,`width`)?.asNum(),customWidth:this.extractAttr(e,`customWidth`)?.asBool(),bestFit:this.extractAttr(e,`bestFit`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),min:this.extractAttr(e,`min`,{required:!0})?.asNum(),max:this.extractAttr(e,`max`,{required:!0})?.asNum(),styleIndex:this.extractAttr(e,`style`)?.asNum(),outlineLevel:this.extractAttr(e,`outlineLevel`)?.asNum(),collapsed:this.extractAttr(e,`collapsed`)?.asBool()}))}extractRows(e){let t=new Set;return this.mapOnElements({parent:e,query:`sheetData row`},e=>({index:this.extractAttr(e,`r`,{required:!0})?.asNum(),cells:this.extractCells(e,t),height:this.extractAttr(e,`ht`)?.asNum(),customHeight:this.extractAttr(e,`customHeight`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),styleIndex:this.extractAttr(e,`s`)?.asNum(),outlineLevel:this.extractAttr(e,`outlineLevel`)?.asNum(),collapsed:this.extractAttr(e,`collapsed`)?.asBool()}))}extractCells(e,t){return this.mapOnElements({parent:e,query:`c`},e=>{let n=this.extractAttr(e,`r`,{required:!0})?.asString(),r=this.extractCellFormula(e);if(r?.ref&&r.sharedIndex===void 0){let e=Ts(r.ref);for(let{col:r,row:i}of Ks(e)){let e=T(r,i);e!==n&&t.add(e)}}let i=t.has(n);return{xc:n,styleIndex:this.extractAttr(e,`s`)?.asNum(),type:Qj[this.extractAttr(e,`t`,{default:`n`})?.asString()],value:i?void 0:this.extractChildTextContent(e,`v`)??void 0,formula:i?void 0:r}})}extractCellFormula(e){let t=this.querySelector(e,`f`);if(!t)return;let n=this.extractTextContent(t),r=this.extractAttr(t,`si`)?.asNum(),i=this.extractAttr(t,`ref`)?.asString();if(!((n===void 0||n.trim()===``)&&r===void 0))return{content:n,sharedIndex:r,ref:i}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:`hyperlink`},e=>{let t=this.extractAttr(e,`r:id`)?.asString();return{xc:this.extractAttr(e,`ref`,{required:!0})?.asString(),location:this.extractAttr(e,`location`)?.asString(),display:this.extractAttr(e,`display`)?.asString(),relTarget:t?this.relationships[t].target:void 0}})}extractSharedFormulas(e){let t=this.querySelectorAll(e,`f[si][ref]`),n={};for(let e of t){let t=this.extractAttr(e,`si`,{required:!0}).asNum();n[t]=this.extractTextContent(e,{required:!0})}let r=[];for(let e=0;e<Object.keys(n).length;e++)n[e]?r.push(n[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),r.push(``));return r}},lP=class extends QN{theme;constructor(e,t,n){super(e.styles,e,t),this.theme=n}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`numFmt`},e=>this.extractNumFormats(e))}extractNumFormats(e){return{id:this.extractAttr(e,`numFmtId`,{required:!0}).asNum(),format:this.extractAttr(e,`formatCode`,{required:!0,default:``}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`font`},e=>this.extractFont(e))}extractFont(e){let t=this.extractChildAttr(e,`name`,`val`,{default:`Arial`}).asString(),n=this.extractChildAttr(e,`sz`,`val`,{default:Ve.toString()}).asNum(),r=this.extractColor(this.querySelector(e,`color`),this.theme),i=this.querySelector(e,`i`)||void 0,a=i&&i.attributes.val?.value!==`0`,o=this.querySelector(e,`b`)||void 0,s=o&&o.attributes.val?.value!==`0`,c=this.querySelector(e,`strike`)||void 0,l=c&&c.attributes.val?.value!==`0`,u=this.querySelector(e,`u`)||void 0;return{name:t,size:n,color:r,italic:a,bold:s,underline:u&&u.attributes.val?.value!==`none`,strike:l}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`fill`},e=>this.extractFill(e))}extractFill(e){let t=e.children[0];return t.tagName===`patternFill`?{patternType:t.attributes.patternType?.value,bgColor:this.extractColor(this.querySelector(t,`bgColor`),this.theme),fgColor:this.extractColor(this.querySelector(t,`fgColor`),this.theme)}:{patternType:`solid`,fgColor:this.extractColor(this.querySelectorAll(t,`color`)[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`border`},e=>this.extractBorder(e))}extractBorder(e){let t={left:this.extractSingleBorder(e,`left`,this.theme),right:this.extractSingleBorder(e,`right`,this.theme),top:this.extractSingleBorder(e,`top`,this.theme),bottom:this.extractSingleBorder(e,`bottom`,this.theme),diagonal:this.extractSingleBorder(e,`diagonal`,this.theme)};return t.diagonal&&(t.diagonalUp=this.extractAttr(e,`diagonalUp`)?.asBool(),t.diagonalDown=this.extractAttr(e,`diagonalDown`)?.asBool()),t}extractSingleBorder(e,t,n){let r=this.querySelector(e,t);if(!(!r||!r.attributes.style))return{style:this.extractAttr(r,`style`,{required:!0,default:`thin`}).asString(),color:this.extractColor(r.children[0],n,`000000`)}}extractAlignment(e){return{horizontal:this.extractAttr(e,`horizontal`,{default:`general`}).asString(),vertical:this.extractAttr(e,`vertical`,{default:`bottom`}).asString(),textRotation:this.extractAttr(e,`textRotation`)?.asNum(),wrapText:this.extractAttr(e,`wrapText`)?.asBool(),indent:this.extractAttr(e,`indent`)?.asNum(),relativeIndent:this.extractAttr(e,`relativeIndent`)?.asNum(),justifyLastLine:this.extractAttr(e,`justifyLastLine`)?.asBool(),shrinkToFit:this.extractAttr(e,`shrinkToFit`)?.asBool(),readingOrder:this.extractAttr(e,`readingOrder`)?.asNum()}}getDxfs(){return this.mapOnElements({query:`dxf`,parent:this.rootFile.file.xml},e=>{let t=this.querySelector(e,`font`),n=this.querySelector(e,`fill`),r=this.querySelector(e,`border`),i=this.querySelector(e,`numFmt`),a=this.querySelector(e,`alignment`);return{font:t?this.extractFont(t):void 0,fill:n?this.extractFill(n):void 0,numFmt:i?this.extractNumFormats(i):void 0,alignment:a?this.extractAlignment(a):void 0,border:r?this.extractBorder(r):void 0}})}getStyles(){return this.mapOnElements({query:`cellXfs xf`,parent:this.rootFile.file.xml},e=>{let t=this.querySelector(e,`alignment`);return{fontId:this.extractAttr(e,`fontId`,{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,`fillId`,{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,`borderId`,{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,`numFmtId`,{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}})}},uP=class extends QN{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`externalBook`},e=>({rId:this.extractAttr(e,`r:id`,{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:`sheetName`},e=>this.extractAttr(e,`val`,{required:!0}).asString()),datasets:this.extractExternalSheetData(e)}))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:`sheetData`},e=>{let t=this.mapOnElements({parent:e,query:`cell`},e=>({xc:this.extractAttr(e,`r`,{required:!0}).asString(),value:this.extractChildTextContent(e,`v`,{required:!0})})),n={};for(let e of t)n[e.xc]=e.value;return{sheetId:this.extractAttr(e,`sheetId`,{required:!0}).asNum(),data:n}})}};function dP(e,t){return fP(pP(e,t),t)}function fP(e,t){let n=[];for(let r of e){let e=mP(r,t);n.push({file:{fileName:r,xml:t[r]},rels:e?{fileName:e,xml:t[e]}:void 0})}return n}function pP(e,t){let n=t[`[Content_Types].xml`].querySelectorAll(`Override[ContentType="${e}"]`),r=[];for(let e of n){let t=e?.attributes.PartName.value;r.push(t.substring(1))}return r}function mP(e,t){if(e===`[Content_Types].xml`)return`_rels/.rels`;let n=``,r=e.split(`/`);for(let e=0;e<r.length-1;e++)n+=r[e]+`/`;return n+=`_rels/`,n+=r[r.length-1]+`.rels`,t[n]||(n=void 0),n}var hP=class{warningManager;xmls;images;constructor(e){this.warningManager=new Gj,this.xmls={},this.images=[];for(let t of Object.keys(e))if(t.endsWith(`.xml`)||t.endsWith(`.rels`)){let n=PO(e[t]);this.xmls[t]=OO(new wO(n))}else t.includes(`media/image`)&&this.images.push({fileName:t,imageSrc:e[t].imageSrc})}convertXlsx(){let e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){let e=this.buildXlsxFileStructure(),t=e.theme?new $N(e.theme,e,this.warningManager).getTheme():void 0,n=e.sharedStrings?new $N(e.sharedStrings,e,this.warningManager).getSharedStrings():[],r=e.sheets.sort((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0})).map(n=>new cP(n,e,this.warningManager,t).getSheet()),i=e.externalLinks.map(t=>new uP(t,e,this.warningManager).getExternalBook()),a=new lP(e,this.warningManager,t);return{fonts:a.getFonts(),fills:a.getFills(),borders:a.getBorders(),dxfs:a.getDxfs(),numFmts:a.getNumFormats(),styles:a.getStyles(),sheets:r,sharedStrings:n,externalBooks:i,chartIds:[],imageIds:[]}}buildXlsxFileStructure(){let e={sheets:dP(Kf.sheet,this.xmls),workbook:dP(Kf.workbook,this.xmls)[0]||dP(Kf.macroEnabledWorkbook,this.xmls)[0]||dP(Kf.templateWorkbook,this.xmls)[0]||dP(Kf.macroEnabledTemplateWorkbook,this.xmls)[0]||dP(Kf.excelAddInWorkbook,this.xmls)[0],styles:dP(Kf.styles,this.xmls)[0],sharedStrings:dP(Kf.sharedStrings,this.xmls)[0],theme:dP(Kf.themes,this.xmls)[0],charts:dP(Kf.chart,this.xmls),figures:dP(Kf.drawing,this.xmls),tables:dP(Kf.table,this.xmls),pivots:dP(Kf.pivot,this.xmls),externalLinks:dP(Kf.externalLink,this.xmls),images:this.images};if(!e.workbook.rels)throw Error(E(`Cannot find workbook relations file`));return e}convertImportedData(e){let t={version:`18.4.2`,sheets:MN(e,this.warningManager),styles:kM(e,this.warningManager),formats:jM(e,this.warningManager),borders:DM(e,this.warningManager),revisionId:We};return UN(t,e),Object.keys(e.styles).map(t=>{e.styles[t]=zt(e.styles[t])}),t}};function gP(e){let t=By(e),n=[];return{text:``.concat(...t.map(e=>{if(e.type===`REFERENCE`&&yc.test(e.value)){let t=e.value.trim();return n.includes(t)||n.push(t),`|${n.indexOf(t)}|`}else return e.value})),dependencies:n}}let _P={am_ET:7,ar_001:6,ar_SY:6,az_AZ:1,eu_ES:1,be_BY:1,bn_IN:1,bs_BA:1,bg_BG:1,ca_ES:1,zh_CN:7,zh_HK:7,zh_TW:7,hr_HR:1,cs_CZ:1,da_DK:1,nl_BE:1,nl_NL:1,en_AU:7,en_CA:7,en_GB:1,en_IN:7,en_NZ:7,et_EE:1,fi_FI:1,fr_BE:1,fr_CA:7,fr_CH:1,fr_FR:1,gl_ES:1,ka_GE:1,de_DE:1,de_CH:1,el_GR:1,gu_IN:7,he_IL:7,hi_IN:7,hu_HU:1,id_ID:7,it_IT:1,ja_JP:7,kab_DZ:6,km_KH:7,ko_KP:1,ko_KR:7,lo_LA:7,lv_LV:1,lt_LT:1,lb_LU:1,mk_MK:1,ml_IN:1,mn_MN:7,ms_MY:1,nb_NO:1,fa_IR:6,pl_PL:1,pt_AO:1,pt_BR:7,pt_PT:1,ro_RO:1,ru_RU:1,sr_RS:7,"sr@latin":7,sk_SK:1,sl_SI:1,es_AR:7,es_BO:1,es_CL:1,es_CO:7,es_CR:1,es_DO:1,es_EC:1,es_GT:7,es_MX:7,es_PA:7,es_PE:7,es_PY:7,es_UY:1,es_VE:7,sw:1,sv_SE:1,th_TH:7,tl_PH:1,tr_TR:1,uk_UA:1,vi_VN:1,sq_AL:1,te_IN:7,en_US:7,my_MM:7,es_ES:1,es_419:1},vP=new g;vP.add(`0.1`,{migrate(e){return e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e}}).add(`0.2`,{migrate(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}}).add(`0.3`,{migrate(e){return e.sheets&&e.activeSheet&&(e.activeSheet=e.sheets.find(t=>t.name===e.activeSheet).id),e}}).add(`0.4`,{migrate(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}}).add(`0.5`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells||[]){let n=t.cells[e];n.content&&n.content.startsWith(`=`)&&(n.formula=gP(n.content))}return e}}).add(`0.6`,{migrate(e){for(let t of e.sheets||[])for(let e in t.figures||[]){let{dataSets:n,...r}=t.figures[e].data,i=[];for(let e of n)if(e.labelCell){let t=Ts(e.dataRange),n=e.labelCell+`:`+T(t.right,t.bottom);i.push(n)}else i.push(e.dataRange);r.dataSetsHaveTitle=!!n[0].labelCell,r.dataSets=i,t.figures[e].data=r}return e}}).add(`0.7`,{migrate(e){let t=[];for(let n of e.sheets||[]){if(!n.name)continue;let e=n.name,r=an(ht(e,`_`),t,{compute:(e,t)=>`${e}${t}`});n.name=r,t.push(r);let i=t=>{if(t===void 0)return t;let n=t.replace(e,r),i=t;for(;i!==n;)i=n,n=i.replace(e,r);return i};for(let e in n.cells){let t=n.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(i))}for(let e of n.figures||[])if(e.tag===`chart`){let t=e.data.dataSets.map(i),n=i(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:n}}for(let e of n.conditionalFormats||[]){e.ranges=e.ranges.map(i);for(let t of[`minimum`,`maximum`,`midpoint`,`upperInflectionPoint`,`lowerInflectionPoint`])e.rule[t]?.type===`formula`&&(e.rule[t].value=i(e.rule[t].value))}}return e}}).add(`0.8`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[])e.data.background=oe,e.data.verticalAxisPosition=`left`,e.data.legendPosition=`top`,e.data.stacked=!1;return e}}).add(`0.9`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells||[]){let n=t.cells[e];if(n.formula){let{text:e,dependencies:t}=n.formula;for(let[n,r]of Object.entries(t)){let t=`\\|${n}\\|`;e=e.replace(new RegExp(t,`g`),r)}n.content=e,delete n.formula}}return e}}).add(`0.10`,{migrate(e){let t={};for(let n of e.sheets||[])for(let e in n.cells||[]){let r=n.cells[e];r.format&&=mc(r.format,t)}return e.formats=t,e}}).add(`15.4`,{migrate(e){for(let t of e.sheets||[])t.isVisible=!0;return e}}).add(`15.4.1`,{migrate(e){return yP(e)}}).add(`16.3`,{migrate(e){for(let t in e.borders){let n=e.borders[t];for(let e in n)Array.isArray(n[e])&&(n[e]={style:n[e][0],color:n[e][1]})}return e}}).add(`16.4`,{migrate(e){return e.settings||={},e.settings.locale||(e.settings.locale=D),e}}).add(`16.4.1`,{migrate(e){return yP(e)}}).add(`17.2`,{migrate(e){for(let t of e.sheets||[])t.tables=t.tables||t.filterTables||[],delete t.filterTables;return e}}).add(`17.3`,{migrate(e){return e.pivots||={},e.pivotNextId||=Td(e.pivots)+1,e}}).add(`17.4`,{migrate(e){for(let t of e.sheets||[])for(let e in t.figures||[]){let n=t.figures[e];`title`in n.data&&typeof n.data.title==`string`&&(n.data.title={text:n.data.title});let r=n.data.type;if(![`line`,`bar`,`pie`,`scatter`,`waterfall`,`combo`].includes(r))continue;let{dataSets:i,...a}=t.figures[e].data;a.dataSets=i.map(e=>({dataRange:e})),t.figures[e].data=a}return e}}).add(`18.0`,{migrate(e){return e}}).add(`18.0.1`,{migrate(e){for(let t of Object.values(e.pivots||{}))t.measures=t.measures.map(e=>({id:e.name,fieldName:e.name,aggregator:e.aggregator})),t.columns=t.columns.map(e=>({fieldName:e.name,order:e.order,granularity:e.granularity})),t.rows=t.rows.map(e=>({fieldName:e.name,order:e.order,granularity:e.granularity}));return e}}).add(`18.0.2`,{migrate(e){let t=e.settings?.locale;return t&&(t.weekStart=_P[t.code]||1),e}}).add(`18.0.3`,{migrate(e){for(let t of e.sheets||[]){t.styles={},t.formats={},t.borders={};for(let e in t.cells)t.styles[e]=t.cells[e].style,t.formats[e]=t.cells[e].format,t.borders[e]=t.cells[e].border,delete t.cells[e].style,delete t.cells[e].format,delete t.cells[e].border}return e}}).add(`18.0.4`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){if(e.tag!==`chart`||e.data.type!==`gauge`)continue;let t=e.data;t?.sectionRule?.lowerInflectionPoint&&(t.sectionRule.lowerInflectionPoint.operator=`<=`),t?.sectionRule?.upperInflectionPoint&&(t.sectionRule.upperInflectionPoint.operator=`<=`)}return e}}).add(`18.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.tables||[])e.config||={...QA,hasFilters:!0};return e}}).add(`18.1.1`,{migrate(e){for(let t of e.sheets||[])for(let e in t.cells){let n=t.cells[e];n&&(t.cells[e]=n.content)}return e}}).add(`18.2`,{migrate(e){return e}}).add(`18.3`,{migrate(e){if(!e.pivots)return e;for(let t of Object.values(e.pivots))t.sortedColumn&&(t.measures.map(e=>e.id).includes(t.sortedColumn.measure)||delete t.sortedColumn);return e}}).add(`18.3.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){let t=e;e.offset={x:t.x||0,y:t.y||0},e.col=0,e.row=0,delete e.x,delete e.y}return e}}).add(`18.4.1`,{migrate(e){let t={textContains:`containsText`,textNotContains:`notContainsText`,textIs:`isEqualText`,textIsEmail:`isEmail`,textIsLink:`isLink`},n={BeginsWith:`beginsWithText`,Between:`isBetween`,ContainsText:`containsText`,EndsWith:`endsWithText`,Equal:`isEqual`,GreaterThan:`isGreaterThan`,GreaterThanOrEqual:`isGreaterOrEqualTo`,IsEmpty:`isEmpty`,IsNotEmpty:`isNotEmpty`,LessThan:`isLessThan`,LessThanOrEqual:`isLessOrEqualTo`,NotBetween:`isNotBetween`,NotContains:`notContainsText`,NotEqual:`isNotEqual`};for(let t of e.sheets||[])for(let e of t.conditionalFormats||[])e.rule.type===`CellIsRule`&&(e.rule.operator=n[e.rule.operator]);for(let n of e.sheets||[])for(let e of n.dataValidationRules||[])e.criterion.type in t&&(e.criterion.type=t[e.criterion.type]);return e}}).add(`18.4.2`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[]){if(e.tag!==`chart`||e.data.type!==`scorecard`)continue;let t=e.data;t.baselineDescr&&={text:t.baselineDescr}}return e}}).add(`18.4.3`,{migrate(e){if(!e.pivots)return e;for(let t in e.pivots){let n=e.pivots[t];if(n.sortedColumn){let e=n.measures.find(e=>e.fieldName===n.sortedColumn?.measure);e&&(n.sortedColumn.measure=e.id)}}return e}}).add(`18.5.1`,{migrate(e){for(let t of e.sheets||[])for(let e of t.figures||[])e.tag===`chart`&&(e.data.chartId=e.id);return e}});function yP(e){for(let t of e.sheets||[]){let e=[];for(let n of t.filterTables||[]){let t=Ts(n.range),r=e.findIndex(e=>zs(e,t));r===-1?e.push(t):e[r]=t}t.filterTables=e.map(e=>({range:As(e)}))}return e}function bP(){return xP().at(-1)}function xP(){return vP.getKeys().sort(EP)}let SP=`Sheet1`;function CP(e,t){if(!e)return RP();console.debug(`### Loading data ###`);let n=performance.now();if(e[`[Content_Types].xml`]){let n=new hP(e);if(e=n.convertXlsx(),t)for(let e of n.warningManager.warnings.sort())console.warn(e)}return`version`in e&&(TP(e)&&(e.version=wP[e.version]),e.version!==bP()&&(console.debug(`Migrating data from version`,e.version),e=DP(e))),e=OP(e),console.debug(`Data loaded in`,performance.now()-n,`ms`),console.debug(`###`),e}let wP={25:`18.2`,24:`18.1.1`,23:`18.1`,22:`18.0.4`,21:`18.0.3`,20:`18.0.2`,19:`18.0.1`,18:`18.0`,17:`17.4`,16:`17.3`,15:`17.2`,"14.5":`16.4.1`,14:`16.4`,13:`16.3`,"12.5":`15.4.1`,12:`15.4`,11:`0.10`,10:`0.9`,9:`0.8`,8:`0.7`,7:`0.6`,6:`0.5`,5:`0.4`,4:`0.3`,3:`0.2`,2:`0.1`,1:`0`};function TP(e){return typeof e.version==`number`}function EP(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<Math.max(n.length,r.length);e++){let t=n[e]||0,i=r[e]||0;if(t>i)return 1;if(t<i)return-1}return 0}function DP(e){let t=performance.now(),n=xP(),r=n.findIndex(t=>EP(t,e.version)>=0);if(r===-1)throw Error(`Data version ${e.version} postdates the current version of o-spreadsheet (version ${bP()}). It cannot be loaded.`);for(let t=r+1;t<n.length;t++){let r=n[t];e=vP.get(r).migrate(e)}return console.debug(`Data migrated in`,performance.now()-t,`ms`),e}function OP(e){return e=kP(e),e=AP(e),e}function kP(e){if(e.uniqueFigureIds)return e;let t=new Set,n=new Set,r=new jl;for(let i of e.sheets||[])for(let e of i.figures||[])t.has(e.id)&&(e.id+=r.smallUuid()),t.add(e.id),e.tag===`chart`&&(n.has(e.data?.chartId)&&(e.data.chartId+=r.smallUuid()),n.add(e.data?.chartId));return e.uniqueFigureIds=!0,e}function AP(e){let t=Object.assign(RP(),e,{version:bP()});return t.sheets=t.sheets?t.sheets.map((e,t)=>Object.assign(LP(`Sheet${t+1}`,`Sheet${t+1}`),e)):[],t.sheets.length===0&&t.sheets.push(LP(SP,`Sheet1`)),uu(t.settings.locale)||(t.settings.locale=D),t}function jP(e,t){return t=MP(e,t),t=NP(t,`SORT_CELLS`),t=NP(t,`SET_DECIMAL`),t=PP(e,t),t=FP(e,t),t=IP(e,t),t}function MP(e,t){if(Object.keys(e).length!==0)return t;let n=[],r=[],i=e=>{if(e.type===`CREATE_SHEET`)n.push(e.sheetId);else if(`sheetId`in e&&!n.includes(e.sheetId))return{...e,sheetId:SP};return e};for(let e of t)e.type===`REMOTE_REVISION`?r.push({...e,commands:e.commands.map(i)}):r.push(e);return r}function NP(e,t){let n=[];for(let r of e)r.type===`REMOTE_REVISION`?n.push({...r,commands:r.commands.filter(e=>e.type!==t)}):n.push(r);return n}function PP(e,t){if(!e.version||EP(String(e.version),`18.5.1`)>=0)return t;let n=[],r={};for(let t of e.sheets||[])t.figures?.forEach(e=>{e.tag===`chart`&&(r[e.id]=e.data)});for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let n of e.commands){let e=n;switch(n.type){case`CREATE_CHART`:r[n.chartId]=n.definition;break;case`UPDATE_CHART`:if(!r[n.chartId]){console.log(`Fix chart definition: chart with id ${n.chartId} not found.`);continue}let t={...r[n.chartId],...n.definition};e={...n,definition:t},r[n.chartId]=t;break}t.push(e)}n.push({...e,commands:t})}else n.push(e);return n}function FP(e,t){let n={};for(let t of e.sheets||[])t.figures?.forEach(e=>{n[e.id]=e.offset});for(let e of t)if(e.type===`REMOTE_REVISION`)for(let t of e.commands)switch(t.type){case`UPDATE_FIGURE`:t.offset&&(t.offset.x===void 0&&(t.offset.x=n[t.figureId]||0),t.offset.y===void 0&&(t.offset.y=n[t.figureId]||0),n[t.figureId]=n);break;case`CREATE_IMAGE`:case`CREATE_CHART`:case`CREATE_FIGURE`:n[t.figureId]=t.offset;break}return t}function IP(e,t){let n={};for(let t of e.sheets||[])n[t.id]=t.name;let r=[];for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let r of e.commands){switch(r.type){case`DUPLICATE_SHEET`:r.sheetNameTo=r.sheetNameTo??ol(n[r.sheetId],Object.values(n));break;case`CREATE_SHEET`:n[r.sheetId]=r.name||al(Object.values(n));break;case`RENAME_SHEET`:n[r.sheetId]=r.newName||al(Object.values(n));break}t.push(r)}r.push({...e,commands:t})}else r.push(e);return t}function LP(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},styles:{},formats:{},borders:{},cols:{},rows:{},merges:[],conditionalFormats:[],dataValidationRules:[],figures:[],tables:[],isVisible:!0}}function RP(e=`Sheet1`){return{version:bP(),sheets:[LP(SP,e)],styles:{},formats:{},borders:{},revisionId:We,uniqueFigureIds:!0,settings:{locale:D},pivots:{},pivotNextId:1,customTableStyles:{}}}function zP(e,t){return{...LP(e,t),charts:[],images:[],cellValues:{}}}function BP(){return{...RP(),sheets:[zP(SP,`Sheet1`)]}}let VP={wrongPasteSelection:E(`This operation is not allowed with multiple selections.`),willRemoveExistingMerge:Jb.Errors.WillRemoveExistingMerge,wrongFigurePasteOption:E(`Cannot do a special paste of a figure.`),frozenPaneOverlap:E(`This operation is not allowed due to an overlapping frozen pane.`)};function HP(e,t){t.isSuccessful||(t.reasons.includes(`WrongPasteSelection`)?e.raiseError(VP.wrongPasteSelection):t.reasons.includes(`WillRemoveExistingMerge`)?e.raiseError(VP.willRemoveExistingMerge):t.reasons.includes(`WrongFigurePasteOption`)?e.raiseError(VP.wrongFigurePasteOption):t.reasons.includes(`FrozenPaneOverlap`)&&e.raiseError(VP.frozenPaneOverlap))}function UP(e,t,n){HP(e,e.model.dispatch(`PASTE`,{target:t,pasteOption:n}))}async function WP(e,t,n,r){if(n.data&&n.data.version!==bP()&&e.notifyUser({type:`warning`,text:E(`You copied content from a different version of the application. Only text and image content will be pasted.`),sticky:!1}),n.imageBlob){let t=n;try{t.imageData=await e.imageProvider?.uploadFile(n.imageBlob)}catch(t){let n=E(`An error occurred while uploading the image. %s`,t.message);console.error(t),e.raiseError(n)}delete n.imageBlob}HP(e,e.model.dispatch(`PASTE_FROM_OS_CLIPBOARD`,{target:t,clipboardContent:n,pasteOption:r}))}function GP(e,t,n=QA){let r=e.model.getters.getSelectedZones(),i=e.model.getters.canCreateDynamicTableOnZones(t,r);r.length===1&&!i&&nc(r[0])===1&&(e.model.selection.selectTableAroundSelection(),r=e.model.getters.getSelectedZones(),i=e.model.getters.canCreateDynamicTableOnZones(t,r));let a=r.map(n=>e.model.getters.getRangeDataFromZone(t,n)),o=e.model.dispatch(`CREATE_TABLE`,{ranges:a,sheetId:t,config:n,tableType:i?`dynamic`:`static`});return o.isCancelledBecause(`TableOverlap`)?e.raiseError(Yb.Errors.TableOverlap):o.isCancelledBecause(`NonContinuousTargets`)&&e.raiseError(Yb.Errors.NonContinuousTargets),o}function KP(e,t){e.model.dispatch(`SET_FORMATTING_WITH_PIVOT`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),format:t})}function qP(e,t){e.model.dispatch(`SET_FORMATTING`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),style:t})}let JP=async e=>XP(e),YP=async e=>XP(e,`asValue`);async function XP(e,t){let n=await e.clipboard.read();switch(n.status){case`ok`:let r=e.model.getters.getClipboardId(),i=Il(n.content),a=i.data?.clipboardId,o=e.model.getters.getSelectedZones();r===a?UP(e,o,t):await WP(e,o,i,t),e.model.getters.isCutOperation()&&t!==`asValue`&&await e.clipboard.write({"text/plain":``});break;case`notImplemented`:e.raiseError(E(`Pasting from the context menu is not supported in this browser. Use keyboard shortcuts ctrl+c / ctrl+v instead.`));break;case`permissionDenied`:e.raiseError(E(`Access to the clipboard denied by the browser. Please enable clipboard permission for this page in your browser settings.`));break}}let ZP=e=>XP(e,`onlyFormat`),QP=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Clear rows`);let t,n,r=e.model.getters.getActiveRows();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.top,n=r.bottom}return t===n?E(`Clear row %s`,(t+1).toString()):E(`Clear rows %s - %s`,(t+1).toString(),(n+1).toString())},$P=e=>{let t=e.model.getters.getActiveSheetId(),n=[...e.model.getters.getActiveRows()].map(n=>e.model.getters.getRowsZone(t,n,n));e.model.dispatch(`DELETE_CONTENT`,{target:n,sheetId:e.model.getters.getActiveSheetId()})},eF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Clear columns`);let t,n,r=e.model.getters.getActiveCols();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.left,n=r.right}return t===n?E(`Clear column %s`,Yn(t)):E(`Clear columns %s - %s`,Yn(t),Yn(n))},tF=e=>{let t=e.model.getters.getActiveSheetId(),n=[...e.model.getters.getActiveCols()].map(n=>e.model.getters.getColsZone(t,n,n));e.model.dispatch(`DELETE_CONTENT`,{target:n,sheetId:e.model.getters.getActiveSheetId()})},nF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Delete rows`);let t,n,r=e.model.getters.getActiveRows();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.top,n=r.bottom}return t===n?E(`Delete row %s`,(t+1).toString()):E(`Delete rows %s - %s`,(t+1).toString(),(n+1).toString())},rF=e=>{let t=[...e.model.getters.getActiveRows()];if(!t.length){let n=e.model.getters.getSelectedZones()[0];for(let e=n.top;e<=n.bottom;e++)t.push(e)}e.model.dispatch(`REMOVE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),dimension:`ROW`,elements:t})},iF=(e,t)=>{if(e===`COL`&&t.model.getters.getActiveRows().size>0||e===`ROW`&&t.model.getters.getActiveCols().size>0)return!1;let n=t.model.getters.getActiveSheetId(),r=t.model.getters.getElementsFromSelection(e),i=t.model.getters.checkElementsIncludeAllVisibleHeaders(n,e,r),a=t.model.getters.checkElementsIncludeAllNonFrozenHeaders(n,e,r);return!i&&!a},aF=e=>{if(e.model.getters.getSelectedZones().length>1)return E(`Delete columns`);let t,n,r=e.model.getters.getActiveCols();if(r.size!==0)t=en([...r]),n=$t([...r]);else{let r=e.model.getters.getSelectedZones()[0];t=r.left,n=r.right}return t===n?E(`Delete column %s`,Yn(t)):E(`Delete columns %s - %s`,Yn(t),Yn(n))},oF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getElementsFromSelection(`ROW`);return!e.model.getters.checkElementsIncludeAllVisibleHeaders(t,`ROW`,n)},sF=e=>{let t=[...e.model.getters.getActiveCols()];if(!t.length){let n=e.model.getters.getSelectedZones()[0];for(let e=n.left;e<=n.right;e++)t.push(e)}e.model.dispatch(`REMOVE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),dimension:`COL`,elements:t})},cF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getElementsFromSelection(`COL`);return!e.model.getters.checkElementsIncludeAllVisibleHeaders(t,`COL`,n)},lF=e=>{let t=e.model.getters.getActiveRows(),n,r;if(t.size)n=en([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.top,r=t.bottom-t.top+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`before`,base:n,quantity:r,dimension:`ROW`})},uF=e=>{let t=e.model.getters.getActiveRows(),n,r;if(t.size)n=$t([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.bottom,r=t.bottom-t.top+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`after`,base:n,quantity:r,dimension:`ROW`})},dF=e=>{let t=e.model.getters.getActiveCols(),n,r;if(t.size)n=en([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.left,r=t.right-t.left+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`before`,dimension:`COL`,base:n,quantity:r})},fF=e=>{let t=e.model.getters.getActiveCols(),n,r;if(t.size)n=$t([...t]),r=t.size;else{let t=e.model.getters.getSelectedZones()[0];n=t.right,r=t.right-t.left+1}e.model.dispatch(`ADD_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),sheetName:e.model.getters.getActiveSheetName(),position:`after`,dimension:`COL`,base:n,quantity:r})},pF=e=>{let t=e.model.getters.getElementsFromSelection(`COL`),n=t[0],r=t[t.length-1];return t.length===1?E(`Hide column %s`,Yn(n).toString()):r-n+1===t.length?E(`Hide columns %s - %s`,Yn(n).toString(),Yn(r).toString()):E(`Hide columns`)},mF=e=>{let t=e.model.getters.getElementsFromSelection(`ROW`),n=t[0],r=t[t.length-1];return t.length===1?E(`Hide row %s`,(n+1).toString()):r-n+1===t.length?E(`Hide rows %s - %s`,(n+1).toString(),(r+1).toString()):E(`Hide rows`)},hF=e=>{let t=e.model.getters,n=e.model.uuidGenerator.smallUuid(),r=t.getActiveSheetId(),i=t.getSelectedZones();i.length===1&&nc(i[0])===1&&(e.model.selection.selectTableAroundSelection(),i=t.getSelectedZones());let a={width:536,height:335},{col:o,row:s,offset:c}=SO(t,a);e.model.dispatch(`CREATE_CHART`,{sheetId:r,figureId:n,chartId:e.model.uuidGenerator.smallUuid(),col:o,row:s,offset:c,size:a,definition:XA(i,e.model.getters)}).isSuccessful&&(e.model.dispatch(`SELECT_FIGURE`,{figureId:n}),e.openSidePanel(`ChartPanel`))},gF=e=>{let t=e.model.getters,n=e.model.uuidGenerator.smallUuid(),r=t.getActiveSheetId(),i={width:536,height:335},{col:a,row:o,offset:s}=SO(t,i);e.model.dispatch(`CREATE_CAROUSEL`,{sheetId:r,figureId:n,col:a,row:o,offset:s,size:i,definition:{items:[]}}).isSuccessful&&(e.model.dispatch(`SELECT_FIGURE`,{figureId:n}),e.openSidePanel(`CarouselPanel`,{figureId:n}))},_F=e=>{let t=e.model.uuidGenerator.smallUuid(),n=e.model.uuidGenerator.smallUuid();e.model.dispatch(`INSERT_NEW_PIVOT`,{pivotId:t,newSheetId:n}).isSuccessful&&e.openSidePanel(`PivotSidePanel`,{pivotId:t})},vF=e=>e.model.getters.getPivotIds().map((t,n)=>({id:`reinsert_dynamic_pivot_${e.model.getters.getPivotFormulaId(t)}`,name:e.model.getters.getPivotDisplayName(t),sequence:n,execute:e=>{let n=e.model.getters.getSelectedZone(),r=e.model.getters.getPivot(t).getCollapsedTableStructure().export();e.model.dispatch(`INSERT_PIVOT_WITH_TABLE`,{pivotId:t,table:r,col:n.left,row:n.top,sheetId:e.model.getters.getActiveSheetId(),pivotMode:`dynamic`}),e.model.dispatch(`REFRESH_PIVOT`,{id:t})},isVisible:e=>e.model.getters.getPivot(t).isValid()})),yF=e=>e.model.getters.getPivotIds().map((t,n)=>({id:`reinsert_static_pivot_${e.model.getters.getPivotFormulaId(t)}`,name:e.model.getters.getPivotDisplayName(t),sequence:n,execute:e=>{let n=e.model.getters.getSelectedZone(),r=e.model.getters.getPivot(t).getExpandedTableStructure();if(r.numberOfCells>5e5){e.notifyUser({type:`warning`,text:Zb(r.numberOfCells,e.model.getters.getLocale()),sticky:!0});return}e.model.dispatch(`INSERT_PIVOT_WITH_TABLE`,{pivotId:t,table:r.export(),col:n.left,row:n.top,sheetId:e.model.getters.getActiveSheetId(),pivotMode:`static`}),e.model.dispatch(`REFRESH_PIVOT`,{id:t})},isVisible:e=>e.model.getters.getPivot(t).isValid()}));async function bF(e){try{return await e.imageProvider.requestImage()}catch{e.raiseError(E(`An unexpected error occurred during the image transfer`));return}}let xF=async e=>{if(e.imageProvider){let t=e.model.getters.getActiveSheetId(),n=e.model.uuidGenerator.smallUuid(),r=await bF(e);if(!r)return;let i=CO(e.model.getters,r.size),{col:a,row:o,offset:s}=SO(e.model.getters,i);e.model.dispatch(`CREATE_IMAGE`,{sheetId:t,figureId:n,col:a,row:o,offset:s,size:i,definition:r})}},SF=e=>KP(e,`0.00%`),CF=e=>{e.openSidePanel(`ConditionalFormatting`,{selection:e.model.getters.getSelectedZones()})},wF=e=>{let{col:t,row:n}=e.model.getters.getActivePosition();e.getStore(TA).open({col:t,row:n},`LinkEditor`)},TF=e=>{let t=e.model.getters.getActiveSheetId(),{col:n,row:r}=e.model.getters.getActivePosition(),i=e.model.getters.getEvaluatedCell({sheetId:t,col:n,row:r});return i&&i.link?E(`Edit link`):E(`Insert link`)},EF=e=>e.model.getters.getFirstTableInSelection()?.config.hasFilters||!1,DF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZones();return e.model.getters.getTablesOverlappingZones(t,n).length===1},OF=e=>oc(e.model.getters.getSelectedZones()),kF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getFirstTableInSelection();n?e.model.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{hasFilters:!0}}):GP(e,t,{...QA,hasFilters:!0,bandedRows:!1,styleId:`TableStyleLight11`})},AF=e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getFirstTableInSelection();n&&e.model.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{hasFilters:!1}})},jF=e=>{GP(e,e.model.getters.getActiveSheetId()).isSuccessful&&e.openSidePanel(`TableSidePanel`,{})},MF=e=>{let t=e.model.getters.getFirstTableInSelection();t&&e.model.dispatch(`REMOVE_TABLE`,{sheetId:e.model.getters.getActiveSheetId(),target:[t.range.zone]})},NF=e=>e.model.getters.getSelectedZones().length===1,PF=(e,t)=>{if(!NF(e))return!1;let n=t===`COL`?e.model.getters.getActiveCols():e.model.getters.getActiveRows(),r=t===`COL`?e.model.getters.getActiveRows():e.model.getters.getActiveCols(),i=e.model.getters.getActiveSheetId(),a=Rs(e.model.getters.getSelectedZone(),e.model.getters.getSheetZone(i));return Gt(n)&&(r.size===0||a)},FF={name:e=>EF(e)?E(`Remove selected filters`):E(`Add filters`),isEnabled:e=>OF(e),execute:e=>EF(e)?AF(e):kF(e),icon:`o-spreadsheet-Icon.FILTER_ICON_ACTIVE`};function IF(e,t,n){let r=e.model.getters.getActiveSheetId(),i=t===`COL`?`FREEZE_COLUMNS`:`FREEZE_ROWS`;e.model.dispatch(i,{sheetId:r,quantity:n}).isCancelledBecause(`MergeOverlap`)&&e.raiseError(Gb)}var LF=class{map={};constructor(e=[]){for(let[t,n]of e)this.set(t,n)}set({sheetId:e,col:t,row:n},r){let i=this.map;i[e]||(i[e]={}),i[e][t]||(i[e][t]={}),i[e][t][n]=r}setMany(e){for(let[t,n]of e)this.set(t,n)}get({sheetId:e,col:t,row:n}){return this.map[e]?.[t]?.[n]}getSheet(e){return this.map[e]}clearSheet(e){delete this.map[e]}has({sheetId:e,col:t,row:n}){return this.map[e]?.[t]?.[n]!==void 0}delete({sheetId:e,col:t,row:n}){delete this.map[e]?.[t]?.[n]}keys(){let e=this.map,t=[];for(let n in e)for(let r in e[n])for(let i in e[n][r])t.push({sheetId:n,col:parseInt(r),row:parseInt(i)});return t}keysForSheet(e){let t=this.map[e];if(!t)return[];let n=[];for(let r in t)for(let i in t[r])n.push({sheetId:e,col:parseInt(r),row:parseInt(i)});return n}*entries(){let e=this.map;for(let t of this.keys()){let{sheetId:n,col:r,row:i}=t;yield[t,e[n][r][i]]}}},RF=class extends bf{mutators=[`enable`,`disable`];isInvalidated=!1;fingerprintColors={[BF]:`#D9D9D9`};isEnabled=!1;colors=new LF;handle(e){switch(Dr(e)&&this.isEnabled&&(this.isInvalidated=!0),e.type){case`UNDO`:case`REDO`:case`ACTIVATE_SHEET`:this.isEnabled&&(this.isInvalidated=!0);break}}finalize(){this.isInvalidated&&(this.isInvalidated=!1,this.computeFingerprints())}enable(){this.isEnabled=!0,this.computeFingerprints()}disable(){this.isEnabled=!1,this.colors=new LF}computeFingerprints(){this.colors=new LF;let e=new LF,t=new Set,n=this.getters.getActiveSheetId(),r=this.getters.getCells(n);for(let n in r){let i=this.computeFingerprint(r[n]);if(!i)continue;t.add(i);let a=this.getters.getCellPosition(n);e.set(a,i)}this.assignColors(t);for(let[t,n]of e.entries()){let e=this.fingerprintColors[n];this.colors.set(t,e),this.colorSpreadZone(t,e)}}colorSpreadZone(e,t){let n=this.getters.getSpreadZone(e);if(!n)return;let r=e.sheetId;for(let e=n.top;e<=n.bottom;e++)for(let i=n.left;i<=n.right;i++){let n={sheetId:r,col:i,row:e};this.colors.set(n,t)}}assignColors(e){let t=new Wn(e.size);Object.keys(this.fingerprintColors).forEach(()=>t.next());for(let n of e)this.fingerprintColors[n]||(this.fingerprintColors[n]=kn(t.next(),.8))}computeFingerprint(e){let t=this.getters.getCellPosition(e.id);return e.isFormula?this.computeFormulaFingerprint(t,e):this.getLiteralFingerprint(t)}computeFormulaFingerprint(e,t){let n=t.compiledFormula.dependencies,r=e.col,i=e.row,a=this.getters.getSheetIds().indexOf(e.sheetId),o={dx:0,dy:0,dSheet:0};for(let e of n){let t=e.zone,[n,s]=e.parts;o.dSheet=this.getters.getSheetIds().indexOf(e.sheetId)-a;let c=Lc(e)&&!e.unboundedZone.hasHeader,l=Ic(e)&&!e.unboundedZone.hasHeader,u=c||n?.colFixed?0:r,d=l||n?.rowFixed?0:i,f=!s&&n?.colFixed||s?.colFixed,p=!s&&n?.rowFixed||s?.rowFixed,m=e.unboundedZone.right===void 0,h=e.unboundedZone.bottom===void 0,g=m||f?0:r,_=h||p?0:i,v=Js({top:t.top-d,left:t.left-u,right:t.right-g,bottom:t.bottom-_});for(let e=v.top;e<=v.bottom;e++)for(let t=v.left;t<=v.right;t++)o.dx+=t,o.dy+=e}let s=t.compiledFormula.normalizedFormula;return zF(o)+s}getLiteralFingerprint(e){switch(this.getters.getEvaluatedCell(e).type){case`number`:case`boolean`:return BF;case`text`:case`empty`:case`error`:return}}};function zF(e){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t).join(`,`)}let BF=`DATA_FINGERPRINT`,VF={name:pF,execute:e=>{let t=e.model.getters.getElementsFromSelection(`COL`);e.model.dispatch(`HIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`COL`,elements:t})},isVisible:cF,icon:`o-spreadsheet-Icon.HIDE_COL`},HF={name:E(`Unhide columns`),execute:e=>{let t=e.model.getters.getElementsFromSelection(`COL`);e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`COL`,elements:t})},isVisible:e=>{let t=e.model.getters.getHiddenColsGroups(e.model.getters.getActiveSheetId()).flat();return e.model.getters.getElementsFromSelection(`COL`).some(e=>t.includes(e))},icon:`o-spreadsheet-Icon.UNHIDE_COL`},UF={name:E(`Unhide all columns`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:t,dimension:`COL`,elements:Array.from(Array(e.model.getters.getNumberCols(t)).keys())})},isVisible:e=>e.model.getters.getHiddenColsGroups(e.model.getters.getActiveSheetId()).length>0,icon:`o-spreadsheet-Icon.UNHIDE_COL`},WF={name:mF,execute:e=>{let t=e.model.getters.getElementsFromSelection(`ROW`);e.model.dispatch(`HIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`ROW`,elements:t})},isVisible:oF,icon:`o-spreadsheet-Icon.HIDE_ROW`},GF={name:E(`Unhide rows`),execute:e=>{let t=e.model.getters.getElementsFromSelection(`ROW`);e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId(),dimension:`ROW`,elements:t})},isVisible:e=>{let t=e.model.getters.getHiddenRowsGroups(e.model.getters.getActiveSheetId()).flat();return e.model.getters.getElementsFromSelection(`ROW`).some(e=>t.includes(e))},icon:`o-spreadsheet-Icon.UNHIDE_ROW`},KF={name:E(`Unhide all rows`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`UNHIDE_COLUMNS_ROWS`,{sheetId:t,dimension:`ROW`,elements:Array.from(Array(e.model.getters.getNumberRows(t)).keys())})},isVisible:e=>e.model.getters.getHiddenRowsGroups(e.model.getters.getActiveSheetId()).length>0,icon:`o-spreadsheet-Icon.UNHIDE_ROW`},qF={name:E(`Unfreeze`),isVisible:e=>{let{xSplit:t,ySplit:n}=e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId());return t+n>0},execute:e=>e.model.dispatch(`UNFREEZE_COLUMNS_ROWS`,{sheetId:e.model.getters.getActiveSheetId()}),icon:`o-spreadsheet-Icon.UNFREEZE`},JF={name:E(`Freeze`),icon:`o-spreadsheet-Icon.FREEZE`},YF={name:E(`No rows`),execute:e=>e.model.dispatch(`UNFREEZE_ROWS`,{sheetId:e.model.getters.getActiveSheetId()}),isReadonlyAllowed:!0,isVisible:e=>!!e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId()).ySplit},XF={name:E(`1 row`),execute:e=>IF(e,`ROW`,1),isReadonlyAllowed:!0},ZF={name:E(`2 rows`),execute:e=>IF(e,`ROW`,2),isReadonlyAllowed:!0},QF={name:E(`Up to current row`),execute:e=>{let{bottom:t}=e.model.getters.getSelectedZone();IF(e,`ROW`,t+1)},isReadonlyAllowed:!0},$F={name:E(`No columns`),execute:e=>e.model.dispatch(`UNFREEZE_COLUMNS`,{sheetId:e.model.getters.getActiveSheetId()}),isReadonlyAllowed:!0,isVisible:e=>!!e.model.getters.getPaneDivisions(e.model.getters.getActiveSheetId()).xSplit},eI={name:E(`1 column`),execute:e=>IF(e,`COL`,1),isReadonlyAllowed:!0},tI={name:E(`2 columns`),execute:e=>IF(e,`COL`,2),isReadonlyAllowed:!0},nI={name:E(`Up to current column`),execute:e=>{let{right:t}=e.model.getters.getSelectedZone();IF(e,`COL`,t+1)},isReadonlyAllowed:!0},rI={name:E(`Gridlines`),execute:e=>{let t=e.model.getters.getActiveSheetId();e.model.dispatch(`SET_GRID_LINES_VISIBILITY`,{sheetId:t,areGridLinesVisible:!e.model.getters.getGridLinesVisibility(t)})},isActive:e=>{let t=e.model.getters.getActiveSheetId();return e.model.getters.getGridLinesVisibility(t)}},iI={name:E(`Irregularity map`),execute:e=>{let t=e.getStore(RF);t.isEnabled?t.disable():t.enable()},isReadonlyAllowed:!0,icon:`o-spreadsheet-Icon.IRREGULARITY_MAP`},aI={name:E(`Formulas`),isActive:e=>e.model.getters.shouldShowFormulas(),execute:e=>e.model.dispatch(`SET_FORMULA_VISIBILITY`,{show:!e.model.getters.shouldShowFormulas()}),isReadonlyAllowed:!0},oI={name:e=>{let t=e.model.getters.getSelectedZone();return t.left===t.right?E(`Group column %s`,Yn(t.left)):E(`Group columns %s - %s`,Yn(t.left),Yn(t.right))},execute:e=>uI(e,`COL`),isVisible:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZone(),r=e.model.getters.getHeaderGroupsInZone(t,`COL`,n);return NF(e)&&!r.some(e=>e.start===n.left&&e.end===n.right)},icon:`o-spreadsheet-Icon.GROUP_COLUMNS`},sI={name:e=>{let t=e.model.getters.getSelectedZone();return t.top===t.bottom?E(`Group row %s`,String(t.top+1)):E(`Group rows %s - %s`,String(t.top+1),String(t.bottom+1))},execute:e=>uI(e,`ROW`),isVisible:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSelectedZone(),r=e.model.getters.getHeaderGroupsInZone(t,`ROW`,n);return NF(e)&&!r.some(e=>e.start===n.top&&e.end===n.bottom)},icon:`o-spreadsheet-Icon.GROUP_ROWS`},cI={name:e=>{let t=e.model.getters.getSelectedZone();return t.left===t.right?E(`Ungroup column %s`,Yn(t.left)):E(`Ungroup columns %s - %s`,Yn(t.left),Yn(t.right))},execute:e=>dI(e,`COL`),icon:`o-spreadsheet-Icon.UNGROUP_COLUMNS`},lI={name:e=>{let t=e.model.getters.getSelectedZone();return t.top===t.bottom?E(`Ungroup row %s`,String(t.top+1)):E(`Ungroup rows %s - %s`,String(t.top+1),String(t.bottom+1))},execute:e=>dI(e,`ROW`),icon:`o-spreadsheet-Icon.UNGROUP_ROWS`};function uI(e,t){let n=e.model.getters.getSelectedZone(),r=e.model.getters.getActiveSheetId();e.model.dispatch(`GROUP_HEADERS`,{sheetId:r,dimension:t,start:t===`COL`?n.left:n.top,end:t===`COL`?n.right:n.bottom})}function dI(e,t){let n=e.model.getters.getSelectedZone(),r=e.model.getters.getActiveSheetId();e.model.dispatch(`UNGROUP_HEADERS`,{sheetId:r,dimension:t,start:t===`COL`?n.left:n.top,end:t===`COL`?n.right:n.bottom})}function fI(e,t){let n=e.model.getters.getActiveSheetId(),r=e.model.getters.getSelectedZones();return r.length===1&&e.model.getters.getHeaderGroupsInZone(n,t,r[0]).length>0}let pI=[`wholeTable`,`firstColumnStripe`,`secondColumnStripe`,`firstRowStripe`,`secondRowStripe`,`firstColumn`,`lastColumn`,`headerRow`,`totalRow`];function mI(e,t){let n=t.numberOfHeaders,r={...e,top:e.top+n};return r.top<=r.bottom?r:void 0}function hI(e){let t=e.range;return{row:t.zone.top,col:t.zone.left,sheetId:t.sheetId}}function gI(e,t,n,r){let i=t.zone;if(i.left!==i.right)throw Error(`Can only define a filter on a single column`);let a={...i,top:i.top+n.numberOfHeaders},o=r(t.sheetId,a);return{id:e,rangeWithHeaders:t,col:i.left,filteredRange:a.top>a.bottom?void 0:o}}function _I(e){return e.type===`static`||e.type===`forceStatic`}function vI(e,t,n,r){return{borders:yI(e,t,n,r),styles:xI(e,t,n,r)}}function yI(e,t,n,r){let i=Sa(n,r,()=>({}));for(let a of pI){let o=t[a]?.border;if(!o)continue;let s=CI(a,e,n,r);for(let t of s)for(let s=t.left;s<=t.right;s++)for(let c=t.top;c<=t.bottom;c++){let l=a===`wholeTable`&&c<=e.numberOfHeaders-1;c===t.top&&o?.top?bI(i,`top`,o.top,s,c,n,r):c!==t.top&&!l&&o?.horizontal&&bI(i,`top`,o.horizontal,s,c,n,r),c===t.bottom&&o?.bottom&&bI(i,`bottom`,o.bottom,s,c,n,r),s===t.left&&o?.left&&bI(i,`left`,o.left,s,c,n,r),s===t.right&&o?.right?bI(i,`right`,o.right,s,c,n,r):s!==t.right&&!l&&o?.vertical&&bI(i,`right`,o.vertical,s,c,n,r)}}return i}function bI(e,t,n,r,i,a,o){switch(t){case`top`:e[r][i].top=n,i!==0&&(e[r][i-1].bottom=n);return;case`bottom`:e[r][i].bottom=n,i!==o-1&&(e[r][i+1].top=n);return;case`left`:e[r][i].left=n,r!==0&&(e[r-1][i].right=n);return;case`right`:e[r][i].right=n,r!==a-1&&(e[r+1][i].left=n);return}}function xI(e,t,n,r){let i=Sa(n,r,()=>({}));for(let a of pI){let o=t[a],s=SI(a);if(!o&&!s)continue;let c=CI(a,e,n,r);for(let e of c)for(let t=e.left;t<=e.right;t++)for(let n=e.top;n<=e.bottom;n++)i[t][n]||(i[t][n]={}),i[t][n]={...i[t][n],...o?.style},s&&(i[t][n].bold=!0)}return i}function SI(e){return e===`firstColumn`||e===`lastColumn`||e===`headerRow`||e===`totalRow`}function CI(e,t,n,r){let i=[],a=Math.min(t.numberOfHeaders,r),o=+!!t.totalRow,s=n-1,c=r-1;switch(e){case`wholeTable`:i.push({top:0,left:0,bottom:c,right:s});break;case`firstColumn`:if(!t.firstColumn)break;i.push({top:0,left:0,bottom:c,right:0});break;case`lastColumn`:if(!t.lastColumn)break;i.push({top:0,left:s,bottom:c,right:s});break;case`headerRow`:if(!t.numberOfHeaders)break;i.push({top:0,left:0,bottom:a-1,right:s});break;case`totalRow`:if(!t.totalRow)break;i.push({top:c,left:0,bottom:c,right:s});break;case`firstRowStripe`:if(!t.bandedRows)break;for(let e=a;e<r-o;e+=2)i.push({top:e,left:0,bottom:e,right:s});break;case`secondRowStripe`:if(!t.bandedRows)break;for(let e=a+1;e<r-o;e+=2)i.push({top:e,left:0,bottom:e,right:s});break;case`firstColumnStripe`:if(!t.bandedColumns)break;for(let e=0;e<n;e+=2)i.push({top:a,left:e,bottom:c-o,right:e});break;case`secondColumnStripe`:if(!t.bandedColumns)break;for(let e=1;e<n;e+=2)i.push({top:a,left:e,bottom:c-o,right:e});break}return i}function wI(e){let t=e.model.dispatch(`CUT`);t.isSuccessful||t.isCancelledBecause(`WrongCutSelection`)&&e.raiseError(E(`This operation is not allowed with multiple selections.`))}let TI={MergeIsDestructive:E(`Merging these cells will only preserve the top-leftmost value. Merge anyway?`),MergeInFilter:E(`You can't merge cells inside of an existing filter.`)};function EI(e,t,n){let r=e.model.dispatch(`ADD_MERGE`,{sheetId:t,target:n});r.isCancelledBecause(`MergeInTable`)?e.raiseError(TI.MergeInFilter):r.isCancelledBecause(`MergeIsDestructive`)&&e.askConfirmation(TI.MergeIsDestructive,()=>{e.model.dispatch(`ADD_MERGE`,{sheetId:t,target:n,force:!0})})}let DI={name:E(`Undo`),description:`Ctrl+Z`,execute:e=>e.model.dispatch(`REQUEST_UNDO`),isEnabled:e=>e.model.getters.canUndo(),icon:`o-spreadsheet-Icon.UNDO`},OI={name:E(`Redo`),description:`Ctrl+Y`,execute:e=>e.model.dispatch(`REQUEST_REDO`),isEnabled:e=>e.model.getters.canRedo(),icon:`o-spreadsheet-Icon.REDO`},kI={name:E(`Copy`),description:`Ctrl+C`,isReadonlyAllowed:!0,execute:async e=>{e.model.dispatch(`COPY`),await e.clipboard.write(await e.model.getters.getClipboardTextAndImageContent())},icon:`o-spreadsheet-Icon.CLIPBOARD`},AI={name:E(`Cut`),description:`Ctrl+X`,execute:async e=>{wI(e),await e.clipboard.write(await e.model.getters.getClipboardTextAndImageContent())},icon:`o-spreadsheet-Icon.CUT`},jI={name:E(`Paste`),description:`Ctrl+V`,execute:JP,icon:`o-spreadsheet-Icon.PASTE`},MI={name:E(`Paste special`),isVisible:e=>!e.model.getters.isCutOperation(),icon:`o-spreadsheet-Icon.PASTE`},NI={name:E(`Paste as value`),description:`Ctrl+Shift+V`,execute:YP},PI={name:E(`Paste format only`),execute:ZP},FI={name:E(`Find and replace`),description:`Ctrl+H`,isReadonlyAllowed:!0,execute:e=>{e.openSidePanel(`FindAndReplace`,{})},isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.SEARCH`},II={name:E(`Delete values`),execute:e=>e.model.dispatch(`DELETE_UNFILTERED_CONTENT`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones()})},LI={name:nF,execute:rF,isVisible:e=>iF(`ROW`,e)},RI={...LI,isVisible:NF},zI={name:QP,execute:$P},BI={name:aF,execute:sF,isVisible:e=>iF(`COL`,e)},VI={...BI,isVisible:NF},HI={name:eF,execute:tF},UI={name:E(`Delete cells`),isVisible:NF},WI={name:E(`Delete cell and shift up`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`DELETE_CELL`,{zone:t,shiftDimension:`ROW`}))}},GI={name:E(`Delete cell and shift left`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`DELETE_CELL`,{zone:t,shiftDimension:`COL`}))}},KI={name:E(`Merge cells`),isEnabled:e=>!YI(e),isActive:e=>XI(e),execute:e=>ZI(e),icon:`o-spreadsheet-Icon.MERGE_CELL`},qI={name:()=>E(`Edit table`),execute:e=>e.openSidePanel(`TableSidePanel`,{}),icon:`o-spreadsheet-Icon.EDIT_TABLE`},JI={name:()=>E(`Delete table`),execute:MF,icon:`o-spreadsheet-Icon.DELETE_TABLE`};function YI(e){let t=e.model.getters.getSelectedZones(),{sheetId:n}=e.model.getters.getActivePosition(),{xSplit:r,ySplit:i}=e.model.getters.getPaneDivisions(n);return t.every(e=>nc(e)===1)||ic(t,r,i)||Bs(t)}function XI(e){if(YI(e))return!1;let t=e.model.getters.getActiveSheetId();return e.model.getters.getSelectedZones().some(n=>e.model.getters.getMergesInZone(t,n).length>0)}function ZI(e){if(YI(e))return;let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId();if(XI(e)){let r=t.flatMap(t=>e.model.getters.getMergesInZone(n,t));e.model.dispatch(`REMOVE_MERGE`,{sheetId:n,target:r})}else EI(e,n,t)}let QI={name:e=>{let t=ML(e);return t===1?E(`Insert row`):E(`Insert %s rows`,t.toString())},isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW`},$I={name:e=>{let t=ML(e);return t===1?E(`Insert row above`):E(`Insert %s rows above`,t.toString())},execute:lF,isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW_BEFORE`},eL={...$I,name:e=>{let t=ML(e);return t===1?E(`Row above`):E(`%s Rows above`,t.toString())}},tL={...$I,name:e=>{let t=ML(e);return t===1?E(`Insert row`):E(`Insert %s rows`,t.toString())},isVisible:NF,icon:`o-spreadsheet-Icon.INSERT_ROW_BEFORE`},nL={execute:uF,name:e=>{let t=ML(e);return t===1?E(`Insert row below`):E(`Insert %s rows below`,t.toString())},isVisible:e=>PF(e,`ROW`),icon:`o-spreadsheet-Icon.INSERT_ROW_AFTER`},rL={...nL,name:e=>{let t=ML(e);return t===1?E(`Row below`):E(`%s Rows below`,t.toString())}},iL={name:e=>{let t=NL(e);return t===1?E(`Insert column`):E(`Insert %s columns`,t.toString())},isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL`},aL={name:e=>{let t=NL(e);return t===1?E(`Insert column left`):E(`Insert %s columns left`,t.toString())},execute:dF,isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL_BEFORE`},oL={...aL,name:e=>{let t=NL(e);return t===1?E(`Column left`):E(`%s Columns left`,t.toString())}},sL={...aL,name:e=>{let t=NL(e);return t===1?E(`Insert column`):E(`Insert %s columns`,t.toString())},isVisible:NF,icon:`o-spreadsheet-Icon.INSERT_COL_BEFORE`},cL={name:e=>{let t=NL(e);return t===1?E(`Insert column right`):E(`Insert %s columns right`,t.toString())},execute:fF,isVisible:e=>PF(e,`COL`),icon:`o-spreadsheet-Icon.INSERT_COL_AFTER`},lL={...cL,name:e=>{let t=NL(e);return t===1?E(`Column right`):E(`%s Columns right`,t.toString())},execute:fF},uL={name:E(`Insert cells`),isVisible:e=>NF(e)&&e.model.getters.getActiveCols().size===0&&e.model.getters.getActiveRows().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL`},dL={name:E(`Insert cells and shift down`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`INSERT_CELL`,{zone:t,shiftDimension:`ROW`}))},isVisible:e=>e.model.getters.getActiveRows().size===0&&e.model.getters.getActiveCols().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL_SHIFT_DOWN`},fL={name:E(`Insert cells and shift right`),execute:e=>{let t=e.model.getters.getSelectedZone();HP(e,e.model.dispatch(`INSERT_CELL`,{zone:t,shiftDimension:`COL`}))},isVisible:e=>e.model.getters.getActiveRows().size===0&&e.model.getters.getActiveCols().size===0,icon:`o-spreadsheet-Icon.INSERT_CELL_SHIFT_RIGHT`},pL={name:E(`Chart`),execute:hF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_CHART`},mL={name:E(`Carousel`),execute:gF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.CAROUSEL`},hL={name:E(`Pivot table`),execute:_F,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.PIVOT`},gL={name:E(`Image`),description:`Ctrl+O`,execute:xF,isVisible:e=>e.imageProvider!==void 0,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_IMAGE`},_L={name:()=>E(`Table`),execute:jF,isVisible:e=>OF(e)&&!e.model.getters.getFirstTableInSelection(),isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.PAINT_TABLE`},vL={name:E(`Function`),icon:`o-spreadsheet-Icon.FORMULA`},yL={name:E(`SUM`),execute:e=>e.startCellEdition(`=SUM(`)},bL={name:E(`AVERAGE`),execute:e=>e.startCellEdition(`=AVERAGE(`)},xL={name:E(`COUNT`),execute:e=>e.startCellEdition(`=COUNT(`)},SL={name:E(`MAX`),execute:e=>e.startCellEdition(`=MAX(`)},CL={name:E(`MIN`),execute:e=>e.startCellEdition(`=MIN(`)},wL={name:E(`All`),children:[TL]};function TL(){return jL(zS.getKeys().filter(e=>!zS.get(e).hidden))}let EL=()=>{let e=zS.content;return[...new Set(zS.getAll().filter(e=>!e.hidden).map(e=>e.category))].filter(C).sort().map((t,n)=>({name:t,children:jL(Object.keys(e).filter(n=>e[n].category===t&&!e[n].hidden))}))},DL={name:E(`Link`),execute:wF,icon:`o-spreadsheet-Icon.INSERT_LINK`},OL={name:E(`Checkbox`),execute:e=>{let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId(),r=t.map(t=>e.model.getters.getRangeDataFromZone(n,t));e.model.dispatch(`ADD_DATA_VALIDATION_RULE`,{ranges:r,sheetId:n,rule:{id:e.model.uuidGenerator.smallUuid(),criterion:{type:`isBoolean`,values:[]}}})},icon:`o-spreadsheet-Icon.INSERT_CHECKBOX`},kL={name:E(`Dropdown list`),execute:e=>{let t=e.model.getters.getSelectedZones(),n=e.model.getters.getActiveSheetId(),r=t.map(t=>e.model.getters.getRangeDataFromZone(n,t)),i=e.model.uuidGenerator.smallUuid();e.model.dispatch(`ADD_DATA_VALIDATION_RULE`,{ranges:r,sheetId:n,rule:{id:i,criterion:{type:`isValueInList`,values:[],displayStyle:`chip`}}});let a=e.model.getters.getDataValidationRule(n,i);a&&e.openSidePanel(`DataValidationEditor`,{rule:wu(a,e.model.getters.getLocale()),onExit:()=>{e.replaceSidePanel(`DataValidation`,`DataValidationEditor`)}})},isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.INSERT_DROPDOWN`},AL={name:E(`Insert sheet`),execute:e=>{let t=e.model.getters.getActiveSheetId(),n=e.model.getters.getSheetIds().indexOf(t)+1,r=e.model.uuidGenerator.smallUuid();e.model.dispatch(`CREATE_SHEET`,{sheetId:r,position:n,name:e.model.getters.getNextSheetName()}),e.model.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:t,sheetIdTo:r})},icon:`o-spreadsheet-Icon.INSERT_SHEET`};function jL(e){return e.sort().map((e,t)=>({name:e,sequence:t*10,execute:t=>t.startCellEdition(`=${e}(`)}))}function ML(e){let t=e.model.getters.getActiveRows();if(t.size)return t.size;{let t=e.model.getters.getSelectedZones()[0];return t.bottom-t.top+1}}function NL(e){let t=e.model.getters.getActiveCols();if(t.size)return t.size;{let t=e.model.getters.getSelectedZones()[0];return t.right-t.left+1}}let PL=`(previous)`;function FL(e,t){let{colDomain:n,rowDomain:r}=LL(e,t);return[...n,...r.slice(0,r.length-1)]}function IL(e,t){let{colDomain:n,rowDomain:r}=LL(e,t);return[...n.slice(0,n.length-1),...r]}function LL(e,t){let n=e.definition.rows.map(e=>e.nameWithGranularity),r=t.filter(e=>n.includes(e.field)),i=e.definition.columns.map(e=>e.nameWithGranularity);return{colDomain:t.filter(e=>i.includes(e.field)),rowDomain:r}}function RL(e,t,n){return t===`column`?LL(e,n).colDomain:LL(e,n).rowDomain}function zL(e,t){return t.find(t=>t.field===e)?.value}function BL(e,t){for(let n of t)if(e.definition.rows.find(e=>e.nameWithGranularity===n.field)===void 0&&e.definition.columns.find(e=>e.nameWithGranularity===n.field)===void 0)return!1;let{rowDomain:n,colDomain:r}=LL(e,t);return VL(n,e.getExpandedTableStructure().getRowTree())&&VL(r,e.getExpandedTableStructure().getColTree())}function VL(e,t){return HL(e,t)!==void 0}function HL(e,t,n){let r=t;for(let t of e){let e=r.find(e=>e.value===t.value);if(!e)return;if(e.field===n)return r;r=e.children}return r}function UL(e,t,n){let{rowDomain:r,colDomain:i}=LL(e,n);if(KL(e,t)===`row`){let e=r.findIndex(e=>e.field===t);if(e===-1)return n;r=r.slice(0,e+1)}else{let e=i.findIndex(e=>e.field===t);if(e===-1)return n;i=i.slice(0,e+1)}return[...r,...i]}function WL(e,t,n){e=b(e);let r=e.find(e=>e.field===t);return r&&(r.value=n),e}function GL(e,t){return t.some(t=>t.field===e)}function KL(e,t){if(e.definition.rows.map(e=>e.nameWithGranularity).includes(t))return`row`;if(e.definition.columns.map(e=>e.nameWithGranularity).includes(t))return`column`;throw Error(`Field ${t} not found in pivot`)}function qL(e,t,n,r){let i=KL(e,n),a=i===`row`?e.getExpandedTableStructure().getRowTree():e.getExpandedTableStructure().getColTree(),o=HL(RL(e,i,t),a,n)?.map(e=>e.value)??[],s=zL(n,t);if(s===void 0)return;let c=o.indexOf(s);if(!(s===void 0||c===-1))return WL(t,n,o[x(c+(r===`(previous)`?-1:1),0,o.length-1)])}function JL(e){return e?e.map(YL).join(`, `):``}function YL(e){return e?`${e.field}=${e.value}`:``}function XL(e,t){let n=e.findIndex(e=>e.field===t);if(n===-1)return``;let r=e.slice(0,n),i=e.at(-1);return JL(i.field===t?r:[...r,i])}function ZL(e,t){let n=e.findIndex(e=>e.field===t);return n===-1?``:JL([...e.slice(0,n),...e.slice(n+1)])}function QL(e,t,n){let r=[...e],i=[...t];r.sort((e,t)=>n([...i,e],[...i,t]));for(let t of e)t.children=QL(t.children,[...i,t],n);return r}function $L(e,t){return e.length>t.length&&t.every((t,n)=>w(t,e[n]))}var eR=class{measures;columns;rows;sortedColumn;collapsedDomains;customFields;constructor(e,t){this.columns=e.columns.map(e=>this.createPivotDimension(t,e)),this.rows=e.rows.map(e=>this.createPivotDimension(t,e)),this.measures=e.measures.map(e=>this.createMeasure(t,e)),this.sortedColumn=e.sortedColumn,this.collapsedDomains=e.collapsedDomains,this.customFields=e.customFields}getDimension(e){let t=this.columns.find(t=>t.nameWithGranularity===e)||this.rows.find(t=>t.nameWithGranularity===e);if(!t)throw new A(E(`Dimension %s does not exist`,e));return t}getMeasure(e){let t=this.measures.find(t=>t.id===e);if(!t)throw new A(E(`Field %s is not a measure`,e));return t}get invalidAggregatorsForCustomField(){return[]}createMeasure(e,t){let n=t.fieldName,r=n===`__count`?{name:`__count`,string:E(`Count`),type:`integer`,aggregator:`sum`}:e[n],i=t.aggregator,a=!!(r||t.computedBy);for(let t of[...this.rows,...this.columns])if(e[t.fieldName]?.isCustomField&&this.invalidAggregatorsForCustomField.includes(i)){a=!1;break}return{id:t.id,get displayName(){return t.userDefinedName??r?.string??t.fieldName},userDefinedName:t.userDefinedName,fieldName:n,aggregator:i,type:n===`__count`?`integer`:r?.type??`integer`,isValid:a,isHidden:t.isHidden,format:t.format,computedBy:t.computedBy,display:t.display}}createPivotDimension(e,t){let n=e[t.fieldName],r=n?.type??`integer`,i=n&&kd(n)?t.granularity:void 0;return{displayName:n?.string??t.fieldName,nameWithGranularity:t.fieldName+(i?`:${i}`:``),fieldName:t.fieldName,granularity:i,type:n?.isCustomField?`custom`:r,order:t.order,isValid:!!n,isCustomField:!!n?.isCustomField,customGroups:n?.customGroups,parentField:n?.parentField}}},tR=class extends eR{range;constructor(e,t,n){if(super(e,t),e.dataSet){let{sheetId:t,zone:r}=e.dataSet;this.range=n.getRangeFromZone(t,r)}}},nR=class{columns;rows;measures;fieldsType;maxIndent;pivotCells={};rowTree;colTree;isSorted=!1;constructor(e,t,n,r,i={COL:[],ROW:[]}){this.measures=n,this.fieldsType=r,i.COL.length&&(e=this.removeCollapsedColumns(e,n,i.COL)),this.columns=e.map(e=>{let t=1;return e.map(e=>(e={...e,offset:t},t+=e.width,e))}),this.rows=t.filter(e=>!this.isParentCollapsed(i.ROW,e)),this.maxIndent=Math.max(...this.rows.map(e=>e.indent)),this.rowTree=Nt(()=>this.buildRowsTree()),this.colTree=Nt(()=>this.buildColumnsTree())}removeCollapsedColumns(e,t,n){let r=(n,r)=>{let i=this.getDomain(n),a=e[r],o=a.findIndex(e=>$L(this.getDomain(e),i)),s=a.findLastIndex(e=>$L(this.getDomain(e),i)),c=r===e.length-1,l=t.map(e=>({fields:c?[...n.fields,`measure`]:[],values:c?[...n.values,e]:[],width:1,offset:0,collapsedHeader:!c}));a.splice(o,s-o+1,...l)};return e.map((i,a)=>{for(let o of i){if(a>=e.length-2)return i;let s=this.getDomain(o);if(n.some(e=>w(s,e))){o.width=t.length;for(let t=a+1;t<e.length;t++)r(o,t)}}return i})}isParentCollapsed(e,t){let n=this.getDomain(t);return e.some(e=>$L(n,e))}getNumberOfDataColumns(){return this.columns.at(-1)?.length||0}getSkippedRows(e){let t=new Set;if(!e.displayColumnHeaders)for(let e=0;e<this.columns.length-1;e++)t.add(e);return e.displayMeasuresRow||t.add(this.columns.length-1),t}getPivotCells(e={displayColumnHeaders:!0,displayTotals:!0,displayMeasuresRow:!0}){let t=JSON.stringify(e);if(!this.pivotCells[t]){let{displayTotals:n}=e,r=this.rows.length,i=this.getNumberOfDataColumns(),a=this.columns.length+r,o=1+i;!n&&r!==1&&--a,!n&&i!==this.measures.length&&(o-=this.measures.length);let s=[],c=this.getSkippedRows(e);for(let e=0;e<o;e++){s.push([]);for(let t=0;t<a;t++)c.has(t)||s[e].push(this.getPivotCell(e,t,n))}this.pivotCells[t]=s}return this.pivotCells[t]}getRowTree(){return this.rowTree()}getColTree(){return this.colTree()}isTotalRow(e){return this.rows[e].indent!==this.maxIndent}getPivotCell(e,t,n=!0){let r=this.columns.length;if(e>0&&t===r-1){let n=this.getColHeaderDomain(e,t);if(!n)return rR;let r=n.at(-1)?.value?.toString()||``;return{type:`MEASURE_HEADER`,domain:n.slice(0,-1),measure:r}}else if(t<=r-1){let n=this.getColHeaderDomain(e,t);return n?{type:`HEADER`,domain:n,dimension:`COL`}:rR}else if(e===0){let e=t-r;return{type:`HEADER`,domain:this.getDomain(this.rows[e]),dimension:`ROW`}}else{let i=t-r;return!n&&this.isTotalRow(i)?rR:{type:`VALUE`,domain:[...this.getDomain(this.rows[i]),...this.getColDomain(e)],measure:this.getColMeasure(e)}}}getColHeaderDomain(e,t){if(e===0)return;let n=this.columns[t].find(t=>t.offset===e);if(!(!n||n.collapsedHeader))return this.getDomain(n)}getDomain(e){return e.fields.map((t,n)=>{if(t===`measure`)return{type:`char`,field:t,value:Nd({displayName:`measure`,type:`char`},e.values[n])};{let{fieldName:r,granularity:i}=Od(t),a=this.fieldsType[r]||`char`;return{type:a,field:t,value:Nd({displayName:r,type:a,granularity:i},e.values[n])}}})}getColDomain(e){let t=this.getColHeaderDomain(e,this.columns.length-1);return t?t.slice(0,-1):[]}getColMeasure(e){let t=this.getColHeaderDomain(e,this.columns.length-1)?.at(-1)?.value;if(t==null)throw Error(`Measure is missing`);return t.toString()}buildRowsTree(){let e=[],t=0,n={};n[0]=e;for(let r of this.rows){if(r.fields.length===0||r.values.length===0)return e;let i=r.fields.length-1,a=r.fields[i],{fieldName:o,granularity:s}=Od(a),c=Nd({displayName:o,type:this.fieldsType[o]??`char`,granularity:s},r.values[i]);if(i>t){t=i,n[t]=[];let e=n[t-1].at(-1);e&&(e.children=n[t])}t=i;let l={value:c,field:r.fields[i],children:[],type:this.fieldsType[o]||`char`,width:0};n[t].push(l)}return e}buildColumnsTree(){let e=[],t=this.columns.at(-2)||[],n={};n[0]=e;for(let e of t)for(let t=0;t<e.fields.length;t++){let r=e.fields[t],{fieldName:i,granularity:a}=Od(r),o=Nd({displayName:i,type:this.fieldsType[i]??`char`,granularity:a},e.values[t]),s={value:o,field:e.fields[t],children:[],width:e.width,type:this.fieldsType[i]||`char`};n[t]?.at(-1)?.value!==o&&(n[t+1]=[],s.children=n[t+1],n[t].push(s))}return e}export(){return{cols:this.columns,rows:this.rows,measures:this.measures,fieldsType:this.fieldsType}}sort(e,t,n){if(this.isSorted)return;let r=(e,t)=>{let r=n(e,t).value;return typeof r==`number`?r:-1/0},i=t.domain,a=QL(this.rowTree(),[],(n,a)=>{let o=r(e,[...n,...i]),s=r(e,[...a,...i]);return t.order===`asc`?o-s:s-o});this.rowTree=Nt(a),this.rows=[...this.rowTreeToRows(a),this.rows[this.rows.length-1]],this.isSorted=!0}rowTreeToRows(e,t){return e.flatMap(e=>{let n={indent:t?t.indent+1:1,fields:[...t?.fields||[],e.field],values:[...t?.values||[],e.value]};return[n,...this.rowTreeToRows(e.children,n)]})}get numberOfCells(){return this.rows.length*this.getNumberOfDataColumns()}};let rR={type:`EMPTY`};function iR(e,t,n){let r=t.measures.filter(e=>!e.isHidden).map(e=>e.id),i=oR(e,t.columns,0);sR(i,r.length);let a=cR(i,t),o=aR(e,0,t.rows,[],[]);o.push({fields:[],values:[],indent:0});let s={};for(let e of t.columns)s[e.fieldName]=e.type;for(let e of t.rows)s[e.fieldName]=e.type;return new nR(a,o,r,s,n===`collapsed`?t.collapsedDomains:void 0)}function aR(e,t,n,r,i){if(t>=n.length)return[];let a=n[t],o=a.nameWithGranularity,s=lR(e,a),c=dR(s,a),l=[],u=r.concat(o);for(let e of c){let r=i.concat(e);l.push({fields:u,values:r,indent:t+1});let a=s[e];a&&l.push(...aR(a,t+1,n,u,r))}return l}function oR(e,t,n){if(n>=t.length)return[];let r=t[n],i=t[n].nameWithGranularity,a=lR(e,r);return dR(a,t[n]).map(e=>({value:a[e]?.[0]?.[r.nameWithGranularity]?.value??null,field:i,children:oR(a[e]||[],t,n+1),type:r.type,width:0}))}function sR(e,t){for(let n in e){let r=e[n];r.children.length===0?r.width=t:(sR(r.children,t),r.width=r.children.reduce((e,t)=>e+t.width,0))}}function cR(e,t){let n=t.columns.map(e=>e.nameWithGranularity),r=n.length,i=t.measures.filter(e=>!e.isHidden),a=i.length,o=Array(r).fill(0).map(()=>[]);function s(e,t,i){let a=o[t];for(let o of e){let e=i.concat([o.value]),c={fields:n.slice(0,t+1),values:e,width:o.width,offset:0};a.push(c),t<=r-1&&s(o.children,t+1,e)}}s(e,0,[]);let c=n.length>0,l=[];return c&&o[o.length-1].forEach(e=>{i.forEach(t=>{let n={fields:[...e.fields,`measure`],values:[...e.values,t.id],width:1,offset:0};l.push(n)})}),i.forEach(e=>{let t={fields:[`measure`],values:[e.id],width:1,offset:0};l.push(t)}),o.push(l),o.length===1&&o.unshift([]),o[o.length-2].push({fields:[],values:[],width:a,offset:0}),o}function lR(e,t){return Object.groupBy(e,uR(t))}function uR(e){let t=e.nameWithGranularity;return e=>`${e[t]?.value??null}`}function dR(e,t){let n=t.order,r=t.customGroups?.find(e=>e.isOtherGroup);return!n&&!r?Object.keys(e):Object.keys(e).sort((e,i)=>r&&e===r.name?1:r&&i===r.name?-1:n?fR(t,e,i):0)}function fR(e,t,n){return t===`null`?e.order===`asc`?1:-1:n===`null`?e.order===`asc`?-1:1:e.type===`integer`||e.type===`datetime`?e.order===`asc`?M(t,D)-M(n,D):M(n,D)-M(t,D):e.order===`asc`?t.localeCompare(n):n.localeCompare(t)}let pR=Symbol(`NULL`);function mR(e,t,n){let r=e.granularity||`month`;if(!(r in hR))throw Error(`Unknown date granularity: ${r}`);let i=typeof t==`number`||typeof t==`string`?t:pR;if(!hR[r].set.has(t)){hR[r].set.add(t);let a=null;if(typeof t==`number`||typeof t==`string`){let e=F(t,n);switch(r){case`year`:a=e.getFullYear();break;case`quarter_number`:a=Math.floor(e.getMonth()/3)+1;break;case`month_number`:a=e.getMonth()+1;break;case`month`:a=Math.floor(M(t,n));break;case`iso_week_number`:a=e.getIsoWeek();break;case`day_of_month`:a=e.getDate();break;case`day`:a=Math.floor(M(t,n));break;case`day_of_week`:a=(e.getDay()+7-n.weekStart)%7+1;break;case`hour_number`:a=e.getHours();break;case`minute_number`:a=e.getMinutes();break;case`second_number`:a=e.getSeconds();break}}hR[r].values[i]=Nd(e,a)}return hR[r].values[i]}let hR={year:{set:new Set,values:{}},quarter_number:{set:new Set,values:{}},month_number:{set:new Set,values:{}},month:{set:new Set,values:{}},iso_week_number:{set:new Set,values:{}},day_of_month:{set:new Set,values:{}},day:{set:new Set,values:{}},day_of_week:{set:new Set,values:{}},hour_number:{set:new Set,values:{}},minute_number:{set:new Set,values:{}},second_number:{set:new Set,values:{}}};function gR(){for(let e in hR)hR[e].set.clear(),hR[e].values={}}var _R=class{type=`SPREADSHEET`;getters;_definition;coreDefinition;metaData={fields:{},fieldKeys:[]};dataEntries=[];collapsedTable;expandedTable;invalidRangeError;needsReevaluation=!0;constructor(e,t){this.getters=t.getters,this.coreDefinition=t.definition}init(e={}){(!this._definition||e.reload)&&(this.reload(4),this.needsReevaluation=!1)}reload(e){e===4&&(this.metaData=this.loadMetaData()),e>=3&&(this._definition=this.loadRuntimeDefinition()),e>=2&&(this.dataEntries=this.loadData()),e>=1&&(this.collapsedTable=void 0,this.expandedTable=void 0)}onDefinitionChange(e){let t=this.coreDefinition;if(this.coreDefinition=e,this._definition){let n=Math.max(this.computeShouldReload(t,e),0);this.reload(n)}}computeShouldReload(e,t){return w(e.dataSet,t.dataSet)?3:4}get isInvalidRange(){return!!this.invalidRangeError}get invalidRangeMessage(){return this.invalidRangeError?.message}get definition(){if(this._definition||this.init(),!this._definition)throw Error(`Pivot definition should be defined at this point.`);return this._definition}isValid(){if(this.invalidRangeError||!this.definition)return!1;for(let e of this.definition.measures)if(!e.isValid)return!1;for(let e of this.definition.columns)if(!e.isValid)return!1;for(let e of this.definition.rows)if(!e.isValid)return!1;return!0}assertIsValid({throwOnError:e}){if(!this.isValid()){if(e)throw this.invalidRangeError?this.invalidRangeError:new A(E(`At least one measure and/or dimension is not correct.`));return{value:k.GenericError,message:this.invalidRangeError?.message??E(`At least one measure and/or dimension is not correct.`)}}}areDomainArgsFieldsValid(e){let t=e.filter((e,t)=>t%2==0).map(N);return t.length&&t.at(-1)===`measure`&&(t=t.slice(0,-1)),jd(t,this.definition)}parseArgsToPivotDomain(e){let t=[];for(let n=0;n<e.length-1;n+=2){let r=N(e[n]),i=this.getTypeOfDimension(r),a=r===`measure`?N(e[n+1]):Nd(this.getDimension(r),e[n+1]);t.push({field:r,value:a,type:i})}return t}markAsDirtyForEvaluation(){this.needsReevaluation=!0}getMeasure(e){return this.definition.getMeasure(e)}getPivotMeasureValue(e){return{value:this.getMeasure(e).displayName}}getPivotHeaderValueAndFormat(e){let t=e.at(-1);if(!t)return{value:E(`Total`)};let n=this.getDimension(t.field),r=this.filterDataEntriesFromDomain(this.dataEntries,e)[0]?.[n.nameWithGranularity];return n.type===`datetime`?sd(n.granularity||`month`).toValueAndFormat(t.value,this.getters.getLocale()):r?r.value===null?{value:E(`(Undefined)`)}:r:{value:``}}getPivotCellValueAndFormat(e,t){let n=this.filterDataEntriesFromDomain(this.dataEntries,t);if(n.length===0)return{value:``};let r=this.getMeasure(e),i=n.map(e=>e[r.fieldName]).filter(C),a=i.filter(e=>e.type!==`empty`),o=r.aggregator,s=wd[o];if(!s)throw Error(`Aggregator ${o} does not exist`);try{let e=s([i],this.getters.getLocale());return a.length===0?{...e,value:``}:e}catch(e){return VS(e,o.toUpperCase())}}getPossibleFieldValues(e){let t=[],n=lR(this.dataEntries,e),r=dR(n,e);for(let i of r)t.push({value:n[i]?.[0]?.[e.nameWithGranularity]?.value??``,label:n[i]?.[0]?.[e.nameWithGranularity]?.formattedValue||``});return t}getCollapsedTableStructure(){if(!this.isValid())throw Error(`Pivot is not valid !`);return this.collapsedTable||=iR(this.dataEntries,this.definition,`collapsed`),this.collapsedTable}getExpandedTableStructure(){if(!this.isValid())throw Error(`Pivot is not valid !`);return this.expandedTable||=iR(this.dataEntries,this.definition,`expanded`),this.expandedTable}getFields(){return this.metaData.fields}get fields(){return this.getFields()}loadMetaData(){if(this.invalidRangeError=void 0,this.coreDefinition.dataSet){let{zone:e,sheetId:t}=this.coreDefinition.dataSet,n=this.getters.getRangeFromZone(t,e);try{let e=this.extractFieldsFromRange(n),t=Wd(this.coreDefinition,e.fields);return{...e,fields:{...e.fields,...t}}}catch(e){return this.invalidRangeError=e,{fields:{},fieldKeys:[]}}}else return this.invalidRangeError=new A(E(`The pivot cannot be created because the dataset is missing.`)),{fields:{},fieldKeys:[]}}loadRuntimeDefinition(){return new tR(this.coreDefinition,this.fields,this.getters)}loadData(){let e=this._definition?.range;return this.isValid()&&e?this.extractDataEntriesFromRange(e):[]}getTypeOfDimension(e){if(e===`measure`)return`char`;let{fieldName:t}=Od(e),n=this.fields[t]?.type;if(!n)throw Error(`Field ${t} does not exist`);return n}filterDataEntriesFromDomain(e,t){return t.reduce((e,t)=>this.filterDataEntriesFromDomainNode(e,t),e)}filterDataEntriesFromDomainNode(e,t){let{field:n,value:r,type:i}=t,{nameWithGranularity:a}=this.getDimension(n);return e.filter(e=>{let t=e[a]?.value;return i===`char`?String(t)===String(r):t===r})}getDimension(e){return this.definition.getDimension(e)}getTypeFromZone(e,t){let n=this.getters.getEvaluatedCellsInZone(e,t).filter(e=>!(e.type===`empty`||e.value===``));return n.length===0?`integer`:n.every(e=>e.type===`number`&&e.format&&jo(e.format))?`datetime`:n.every(e=>e.type===`boolean`)?`boolean`:n.every(e=>e.type===`number`)?`integer`:`char`}assertCellIsValidField(e,t,n){if(n.type===`error`)throw new A(E(`The pivot cannot be created because cell %s contains an error`,T(e,t)));if(n.type===`empty`||n.value===``)throw new A(E(`The pivot cannot be created because cell %s is empty`,T(e,t)));if(n.value===`__count`)throw new A(E(`The pivot cannot be created because cell %s contains a reserved value`,T(e,t)))}extractFieldsFromRange(e){let t={},n=[],r=e.sheetId,i=e.zone.top;for(let a=e.zone.left;a<=e.zone.right;a++){let o=this.getters.getEvaluatedCell({sheetId:r,col:a,row:i});this.assertCellIsValidField(a,i,o);let s=o.value?.toString();if(s){let i=this.getTypeFromZone(r,{top:e.zone.top+1,left:a,bottom:e.zone.bottom,right:a}),o=Ud(s,t);t[o]={name:o,type:i,string:o,aggregator:i===`integer`?`sum`:`count`},n.push(o)}}return{fields:t,fieldKeys:n}}extractDataEntriesFromRange(e){let t=[];for(let n=e.zone.top+1;n<=e.zone.bottom;n++){let r={top:n,bottom:n,left:e.zone.left,right:e.zone.right},i=this.getters.getEvaluatedCellsInZone(e.sheetId,r),a={};for(let e in i){let t=i[e],n=this.fields[this.metaData.fieldKeys[e]];if(!n)throw Error(`Field ${this.metaData.fieldKeys[e]} does not exist`);t.value===``?a[n.name]={value:null,type:`empty`,formattedValue:``}:a[n.name]=t}for(let e in this.definition.customFields||{}){let t=this.definition.customFields?.[e];if(!t)continue;let n=a[t.parentField],r=this.fields[t.parentField];if(!n||!r){a[e]={value:null,type:`empty`,formattedValue:``};continue}let i=t.groups.find(e=>e.values.some(e=>e===n?.value))||t.groups.find(e=>e.isOtherGroup);a[e]={...n,value:i?i.name:n.value}}a.__count={value:1,type:`number`,formattedValue:`1`},t.push(a)}let n=this.definition.columns.concat(this.definition.rows).filter(e=>e.type===`datetime`);if(n.length){let e=this.getters.getLocale();for(let r of t)for(let t of n){let n=mR(t,r[t.fieldName]?.value||null,this.getters.getLocale()),{format:i,value:a}=sd(t.granularity||`month`).toValueAndFormat(n,e);r[t.nameWithGranularity]={value:n,type:r[t.fieldName]?.type||`empty`,format:r[t.fieldName]?.format,formattedValue:L(a,{locale:e,format:i})}}}return t}};let vR=new g,yR=[`year`,`quarter_number`,`month_number`,`month`,`iso_week_number`,`day_of_month`,`day`,`day_of_week`],bR=[...yR,`hour_number`,`minute_number`,`second_number`];vR.add(`SPREADSHEET`,{ui:_R,definition:tR,dateGranularities:[...yR],isMeasureCandidate:e=>e.type!==`boolean`,datetimeGranularities:[...bR],isGroupable:()=>!0,canHaveCustomGroup:e=>e.type===`char`&&!e.isCustomField,adaptRanges:(e,t,n)=>{if(t.type!==`SPREADSHEET`||!t.dataSet)return t;let{sheetId:r,zone:i}=t.dataSet,a=e.getRangeFromZone(r,i),o=xR(a,n);if(o===a)return t;let s=o&&{sheetId:o.sheetId,zone:o.zone};return{...t,dataSet:s}}});function xR(e,t){if(!e)return;let n=t(e);switch(n.changeType){case`REMOVE`:return;default:return n.range}}let SR={name:E(`See pivot properties`),execute(e){let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);e.openSidePanel(`PivotSidePanel`,{pivotId:n})},isVisible:e=>{let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);return!e.isSmall&&n&&e.model.getters.isExistingPivot(n)||!1},isReadonlyAllowed:!0,icon:`o-spreadsheet-Icon.PIVOT`},CR={name:E(`Ascending`),execute:e=>jR(e,e.model.getters.getActivePosition(),`asc`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`asc`},wR={name:E(`Descending`),execute:e=>jR(e,e.model.getters.getActivePosition(),`desc`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`desc`},TR={name:E(`No sorting`),execute:e=>jR(e,e.model.getters.getActivePosition(),`none`),isActive:e=>e.model.getters.getPivotCellSortDirection(e.model.getters.getActivePosition())===`none`},ER={name:E(`Convert to individual formulas`),execute(e){let t=e.model.getters.getActivePosition(),n=e.model.getters.getCorrespondingFormulaCell(t),r=e.model.getters.getPivotIdFromPosition(t);if(!n||!r)return;let{sheetId:i,col:a,row:o}=e.model.getters.getCellPosition(n.id),s=e.model.getters.getPivot(r);s.init(),s.isValid()&&e.model.dispatch(`SPLIT_PIVOT_FORMULA`,{sheetId:i,col:a,row:o,pivotId:r})},isVisible:e=>{let t=e.model.getters.getActivePosition(),n=e.model.getters.getPivotIdFromPosition(t);if(!n)return!1;let r=e.model.getters.getPivot(n),i=e.model.getters.getEvaluatedCell(t);return r.isValid()&&e.model.getters.isSpillPivotFormula(t)&&i.type!==`error`},icon:`o-spreadsheet-Icon.PIVOT`},DR={name:E(`Group pivot dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=b(e.model.getters.getPivotCoreDefinition(n));if(!i.isCustomField)NR(o,r,i,a.getFields());else{let e=(o.customFields||{})[i.name];if(!e)return;PR(e,r)}e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:o})},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n);return r.length>1&&(i.isCustomField||vR.get(a.type).canHaveCustomGroup(i))}},OR={name:E(`Group all remaining dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,field:r}=t,i=e.model.getters.getPivot(n),a=b(e.model.getters.getPivotCoreDefinition(n)),o=r.isCustomField?(a.customFields||{})[r.name]:qd(a,r,i.getFields());o&&(o.groups.push({name:Hd(E(`Others`),o),values:[],isOtherGroup:!0}),Kd(a,r.name,o.name),e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:a}))},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,field:r,values:i}=t;return LR(e,n,i,r)}},kR={name:E(`Ungroup pivot dimensions`),execute:e=>{let t=MR(e);if(!t)return;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=b(e.model.getters.getPivotCoreDefinition(n));FR(o,r,i,a.getFields()),e.model.dispatch(`UPDATE_PIVOT`,{pivotId:n,pivot:o})},isVisible:e=>{let t=MR(e);if(!t)return!1;let{pivotId:n,values:r,field:i}=t,a=e.model.getters.getPivot(n),o=e.model.getters.getPivotCoreDefinition(n);if(!i.isCustomField){let e=qd(o,i,a.getFields());if(![...o.rows,...o.columns].some(t=>t.fieldName===e.name))return!1}return IR(o,r,i,a.getFields())}};function AR(e,t){let n=e.getPivotIdFromPosition(t);if(!n||!e.isExistingPivot(n)||!e.isSpillPivotFormula(t)||!e.getPivot(n).isValid())return!1;let r=e.getPivotCellFromPosition(t);return r.type===`VALUE`||r.type===`MEASURE_HEADER`}function jR(e,t,n){let r=e.model.getters.getPivotIdFromPosition(t),i=e.model.getters.getPivotCellFromPosition(t);if(i.type===`EMPTY`||i.type===`HEADER`||!r)return;if(n===`none`){e.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...e.model.getters.getPivotCoreDefinition(r),sortedColumn:void 0}});return}let a=LL(e.model.getters.getPivot(r),i.domain).colDomain;e.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...e.model.getters.getPivotCoreDefinition(r),sortedColumn:{domain:a,order:n,measure:i.measure}}})}function MR(e){let t,n,r=[];for(let i of e.model.getters.getSelectedZones()){let a=e.model.getters.getActiveSheetId();for(let o of qs(a,i)){let i=e.model.getters.getPivotIdFromPosition(o);if(!t)t=i;else if(i&&t!==i)return;if(!t)continue;let a=e.model.getters.getPivotCellFromPosition(o);if(a.type!==`HEADER`||!e.model.getters.isSpillPivotFormula(o))continue;let s=a.domain.at(-1)?.field;if(!n&&s)n=s;else if(n&&s&&n!==s)return;r.push(a)}}if(!t||!n||r.length===0)return;let i=e.model.getters.getPivot(t).getFields()[n];if(!i)return;let a=r.map(e=>e.domain.at(-1)?.value).filter(e=>e!==void 0);return{pivotId:t,values:a,field:i}}function NR(e,t,n,r){let i=qd(e,n,r);Gd(t,i);let a={name:Hd(E(`Group`),i),values:t};i.groups.push(a),e.customFields||={},e.customFields[i.name]=i,Kd(e,n.name,i.name)}function PR(e,t){let n=new Set,r=[];for(let i of t){let t=e.groups.find(e=>e.name===i);t?(r.push(t),t.values.forEach(e=>n.add(e))):n.add(i)}if(r.some(e=>e.isOtherGroup))e.groups=e.groups.filter(e=>e.isOtherGroup||!r.includes(e));else if(r.length===0){let n={name:Hd(E(`Group`),e),values:t};e.groups.push(n)}else{let t=r.slice(1);e.groups=e.groups.filter(e=>!t.includes(e)),r[0].values=Array.from(n)}}function FR(e,t,n,r){let i;if(!n.isCustomField)i=qd(e,n,r),i.groups.some(e=>e.isOtherGroup)&&t.some(e=>!i?.groups.some(t=>t.values.includes(e)))&&(i.groups=i.groups.filter(e=>!e.isOtherGroup)),Gd(t,i);else{if(i=(e.customFields||{})[n.name],!i)return;i.groups=i.groups.filter(e=>!t.includes(e.name))}i.groups.every(e=>e.values.length===0&&!e.isOtherGroup)&&(RR(e,i.name),delete e.customFields?.[i.name])}function IR(e,t,n,r){if(n.isCustomField){let r=(e.customFields||{})[n.name];return r?r.groups.some(e=>t.includes(e.name)):!1}else return qd(e,n,r).groups.some(e=>e.isOtherGroup||t.some(t=>e.values.includes(t)))}function LR(e,t,n,r){let i=e.model.getters.getPivot(t),a=e.model.getters.getPivotCoreDefinition(t),o=r.isCustomField?(a.customFields||{})[r.name]:Object.values(a.customFields||{}).find(e=>e.parentField===r.name),s=i.definition.getDimension(r.name);if(!s||!o||IR(a,n,r,i.getFields()))return!1;let c=new Set(i.getPossibleFieldValues(s).map(e=>e.value)),l=r.isCustomField?o.groups.map(e=>e.name):o.groups.flatMap(e=>e.values);for(let e of[...n,...l])c.delete(e);return c.size===0}function RR(e,t){let n=e.customFields?.[t];if(!n)return;let r=[...e.rows,...e.columns].some(e=>e.fieldName===n.parentField);for(let i of[e.rows,e.columns]){let e=i.findIndex(e=>e.fieldName===t);e!==-1&&(r?i.splice(e,1):i.splice(e,1,{fieldName:n.parentField}))}}let zR=new IA;zR.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`add_row_before`,{...tL,sequence:70}).add(`add_column_before`,{...sL,sequence:90}).add(`insert_cell`,{...uL,sequence:100,separator:!0}).addChild(`insert_cell_down`,[`insert_cell`],{...dL,name:E(`Shift down`),sequence:10}).addChild(`insert_cell_right`,[`insert_cell`],{...fL,name:E(`Shift right`),sequence:20}).add(`delete_row`,{...RI,sequence:110,icon:`o-spreadsheet-Icon.TRASH`}).add(`delete_column`,{...VI,sequence:120,icon:`o-spreadsheet-Icon.TRASH`}).add(`delete_cell`,{...UI,sequence:130,separator:!0,icon:`o-spreadsheet-Icon.TRASH`}).addChild(`delete_cell_up`,[`delete_cell`],{...WI,name:E(`Shift up`),sequence:10,icon:`o-spreadsheet-Icon.DELETE_CELL_SHIFT_UP`}).addChild(`delete_cell_left`,[`delete_cell`],{...GI,name:E(`Shift left`),sequence:20,icon:`o-spreadsheet-Icon.DELETE_CELL_SHIFT_LEFT`}).add(`edit_table`,{...qI,isVisible:DF,isEnabled:e=>!e.isSmall,sequence:140}).add(`delete_table`,{...JI,isVisible:DF,sequence:145,separator:!0}).add(`insert_link`,{...DL,name:TF,sequence:150,separator:!0}).add(`pivot_headers_group`,{sequence:155,icon:`o-spreadsheet-Icon.PLUS_IN_BOX`,...DR}).add(`pivot_group_remaining`,{sequence:155,icon:`o-spreadsheet-Icon.PLUS_IN_BOX`,...OR}).add(`pivot_headers_ungroup`,{sequence:155,icon:`o-spreadsheet-Icon.MINUS_IN_BOX`,...kR}).add(`pivot_sorting`,{name:E(`Sort pivot`),sequence:155,icon:`o-spreadsheet-Icon.SORT_RANGE`,isVisible:e=>{let t=e.model.getters.getActivePosition();return AR(e.model.getters,t)}}).add(`pivot_fix_formulas`,{...ER,sequence:160}).add(`pivot_properties`,{...SR,sequence:170,separator:!0}).addChild(`pivot_sorting_asc`,[`pivot_sorting`],{...CR,sequence:10}).addChild(`pivot_sorting_desc`,[`pivot_sorting`],{...wR,sequence:20}).addChild(`pivot_sorting_none`,[`pivot_sorting`],{...TR,sequence:30});let BR={name:E(`Sort range`),isVisible:NF,icon:`o-spreadsheet-Icon.SORT_RANGE`},VR={name:E(`Ascending (A ⟶ Z)`),execute:e=>{let{anchor:t,zones:n}=e.model.getters.getSelection();yv(e,e.model.getters.getActiveSheetId(),t.cell,n[0],`asc`)},icon:`o-spreadsheet-Icon.SORT_ASCENDING`},HR={name:E(`Data cleanup`),icon:`o-spreadsheet-Icon.DATA_CLEANUP`},UR={name:E(`Remove duplicates`),execute:e=>{nc(e.model.getters.getSelectedZone())===1&&e.model.selection.selectTableAroundSelection(),e.openSidePanel(`RemoveDuplicates`,{})},isEnabled:e=>!e.isSmall},WR={name:E(`Trim whitespace`),execute:e=>{e.model.dispatch(`TRIM_WHITESPACE`)}},GR={name:E(`Descending (Z ⟶ A)`),execute:e=>{let{anchor:t,zones:n}=e.model.getters.getSelection();yv(e,e.model.getters.getActiveSheetId(),t.cell,n[0],`desc`)},icon:`o-spreadsheet-Icon.SORT_DESCENDING`},KR={...FF},qR={...FF,isActive:e=>EF(e)},JR={name:E(`Split text to columns`),sequence:1,execute:e=>e.openSidePanel(`SplitToColumns`,{}),isEnabled:e=>!e.isSmall&&e.model.getters.isSingleColSelected(),icon:`o-spreadsheet-Icon.SPLIT_TEXT`},YR={id:`reinsert_dynamic_pivot`,name:E(`Re-insert dynamic pivot`),sequence:60,icon:`o-spreadsheet-Icon.INSERT_PIVOT`,children:[vF],isVisible:e=>e.model.getters.getPivotIds().some(t=>e.model.getters.getPivot(t).isValid())},XR={id:`reinsert_static_pivot`,name:E(`Re-insert static pivot`),sequence:70,icon:`o-spreadsheet-Icon.INSERT_PIVOT`,children:[yF],isVisible:e=>e.model.getters.getPivotIds().some(t=>e.model.getters.getPivot(t).isValid())};function ZR({name:e,format:t,descriptionValue:n}){let r=typeof t==`function`?t:()=>t;return{name:e,description:e=>L(n,{format:r(e),locale:e.model.getters.getLocale()}),execute:e=>KP(e,r(e)),isActive:e=>Yz(e,r(e)),format:t}}let QR={name:E(`Automatic`),execute:e=>KP(e,``),isActive:e=>Jz(e)},$R={name:E(`Plain text`),execute:e=>KP(e,`@`),isActive:e=>Yz(e,`@`)},ez=ZR({name:E(`Number`),descriptionValue:1000.12,format:`#,##0.00`}),tz={name:E(`Format as percent`),execute:SF,icon:`o-spreadsheet-Icon.PERCENT`},nz=ZR({name:E(`Percent`),descriptionValue:.1012,format:`0.00%`}),rz=ZR({name:E(`Currency`),descriptionValue:1000.12,format:e=>Ro(e.model.config.defaultCurrency||nt)}),iz={...ZR({name:E(`Currency rounded`),descriptionValue:1e3,format:e=>Ho(Ro(e.model.config.defaultCurrency||nt))}),isVisible:e=>{let t=Ro(e.model.config.defaultCurrency||nt);return t!==Ho(t)}},az=ZR({name:E(`Accounting`),descriptionValue:-1000.12,format:e=>zo(e.model.config.defaultCurrency||nt)}),oz=ts(`2023/09/26 10:43:00 PM`,D),sz={name:E(`Custom currency`),isVisible:e=>e.loadCurrencies!==void 0&&!e.isSmall,execute:e=>e.openSidePanel(`CustomCurrency`,{})},cz=ZR({name:E(`Date`),descriptionValue:oz,format:e=>e.model.getters.getLocale().dateFormat}),lz=ZR({name:E(`Time`),descriptionValue:oz,format:e=>e.model.getters.getLocale().timeFormat}),uz=ZR({name:E(`Date time`),descriptionValue:oz,format:e=>Du(e.model.getters.getLocale())}),dz=ZR({name:E(`Duration`),descriptionValue:`27:51:38`,format:`hhhh:mm:ss`}),fz=ZR({name:E(`Quarter`),descriptionValue:oz,format:`qq yyyy`}),pz=ZR({name:E(`Full quarter`),descriptionValue:oz,format:`qqqq yyyy`}),mz={name:E(`More date formats`),execute:e=>e.openSidePanel(`MoreFormats`,{})},hz=ZR({name:E(`Full date time`),format:`dddd d mmmm yyyy hh:mm:ss a`,descriptionValue:oz}),gz=ZR({name:E(`ISO Date`),format:`yyyy-mm-dd`,descriptionValue:oz}),_z=ZR({name:E(`ISO Date time`),format:`yyyy-mm-dd hh:mm:ss`,descriptionValue:oz}),vz=ZR({name:E(`Full week day and month`),format:`dddd d mmmm yyyy`,descriptionValue:oz}),yz=ZR({name:E(`Day and full month`),format:`d mmmm yyyy`,descriptionValue:oz}),bz=ZR({name:E(`Short week day`),format:`ddd d mmm yyyy`,descriptionValue:oz}),xz=ZR({name:E(`Day and short month`),format:`d mmm yyyy`,descriptionValue:oz}),Sz=ZR({name:E(`Full month`),format:`mmmm yyyy`,descriptionValue:oz}),Cz=ZR({name:E(`Short month`),format:`mmm yyyy`,descriptionValue:oz}),wz={name:E(`Increase decimal places`),icon:`o-spreadsheet-Icon.INCREASE_DECIMAL`,execute:e=>e.model.dispatch(`SET_DECIMAL`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),step:1})},Tz={name:E(`Decrease decimal places`),icon:`o-spreadsheet-Icon.DECRASE_DECIMAL`,execute:e=>e.model.dispatch(`SET_DECIMAL`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones(),step:-1})},Ez={name:E(`Bold`),description:`Ctrl+B`,execute:e=>qP(e,{bold:!e.model.getters.getCurrentStyle().bold}),icon:`o-spreadsheet-Icon.BOLD`,isActive:e=>!!e.model.getters.getCurrentStyle().bold},Dz={name:E(`Italic`),description:`Ctrl+I`,execute:e=>qP(e,{italic:!e.model.getters.getCurrentStyle().italic}),icon:`o-spreadsheet-Icon.ITALIC`,isActive:e=>!!e.model.getters.getCurrentStyle().italic},Oz={name:E(`Underline`),description:`Ctrl+U`,execute:e=>qP(e,{underline:!e.model.getters.getCurrentStyle().underline}),icon:`o-spreadsheet-Icon.UNDERLINE`,isActive:e=>!!e.model.getters.getCurrentStyle().underline},kz={name:E(`Strikethrough`),execute:e=>qP(e,{strikethrough:!e.model.getters.getCurrentStyle().strikethrough}),icon:`o-spreadsheet-Icon.STRIKE`,isActive:e=>!!e.model.getters.getCurrentStyle().strikethrough},Az={name:E(`Font size`),children:qz(),icon:`o-spreadsheet-Icon.FONT_SIZE`},jz={name:E(`Alignment`),icon:`o-spreadsheet-Icon.ALIGN_LEFT`},Mz={name:E(`Horizontal align`),icon:e=>eB(e)},Nz={name:E(`Left`),description:`Ctrl+Shift+L`,execute:e=>qP(e,{align:`left`}),isActive:e=>Zz(e)===`left`,icon:`o-spreadsheet-Icon.ALIGN_LEFT`},Pz={name:E(`Center`),description:`Ctrl+Shift+E`,execute:e=>qP(e,{align:`center`}),isActive:e=>Zz(e)===`center`,icon:`o-spreadsheet-Icon.ALIGN_CENTER`},Fz={name:E(`Right`),description:`Ctrl+Shift+R`,execute:e=>qP(e,{align:`right`}),isActive:e=>Zz(e)===`right`,icon:`o-spreadsheet-Icon.ALIGN_RIGHT`},Iz={name:E(`Vertical align`),icon:e=>tB(e)},Lz={name:E(`Top`),execute:e=>qP(e,{verticalAlign:`top`}),isActive:e=>Qz(e)===`top`,icon:`o-spreadsheet-Icon.ALIGN_TOP`},Rz={name:E(`Middle`),execute:e=>qP(e,{verticalAlign:`middle`}),isActive:e=>Qz(e)===`middle`,icon:`o-spreadsheet-Icon.ALIGN_MIDDLE`},zz={name:E(`Bottom`),execute:e=>qP(e,{verticalAlign:`bottom`}),isActive:e=>Qz(e)===`bottom`,icon:`o-spreadsheet-Icon.ALIGN_BOTTOM`},Bz={name:E(`Wrapping`),icon:`o-spreadsheet-Icon.WRAPPING_OVERFLOW`},Vz={name:E(`Wrapping`),icon:e=>nB(e)},Hz={name:E(`Overflow`),execute:e=>qP(e,{wrapping:`overflow`}),isActive:e=>$z(e)===`overflow`,icon:`o-spreadsheet-Icon.WRAPPING_OVERFLOW`},Uz={name:E(`Wrap`),execute:e=>qP(e,{wrapping:`wrap`}),isActive:e=>$z(e)===`wrap`,icon:`o-spreadsheet-Icon.WRAPPING_WRAP`},Wz={name:E(`Clip`),execute:e=>qP(e,{wrapping:`clip`}),isActive:e=>$z(e)===`clip`,icon:`o-spreadsheet-Icon.WRAPPING_CLIP`};E(`Text Color`),E(`Fill Color`);let Gz={name:E(`Conditional formatting`),execute:CF,isEnabled:e=>!e.isSmall,icon:`o-spreadsheet-Icon.CONDITIONAL_FORMAT`},Kz={name:E(`Clear formatting`),description:`Ctrl+<`,execute:e=>e.model.dispatch(`CLEAR_FORMATTING`,{sheetId:e.model.getters.getActiveSheetId(),target:e.model.getters.getSelectedZones()}),icon:`o-spreadsheet-Icon.CLEAR_FORMAT`};function qz(){return et.map(e=>({name:e.toString(),sequence:e,id:`font_size_${e}`,execute:t=>qP(t,{fontSize:e}),isActive:t=>Xz(t,e)}))}function Jz(e){let t=e.model.getters.getActivePosition();return e.model.getters.getPivotCellFromPosition(t).type===`VALUE`?!e.model.getters.getEvaluatedCell(t).format:!e.model.getters.getCell(t)?.format}function Yz(e,t){let n=e.model.getters.getActivePosition();return e.model.getters.getPivotCellFromPosition(n).type===`VALUE`?e.model.getters.getEvaluatedCell(n).format===t:e.model.getters.getCell(n)?.format===t}function Xz(e,t){return(e.model.getters.getCurrentStyle().fontSize||Ve)===t}function Zz(e){let t=e.model.getters.getCurrentStyle();return t.align?t.align:e.model.getters.getActiveCell().defaultAlign}function Qz(e){let t=e.model.getters.getCurrentStyle();return t.verticalAlign?t.verticalAlign:ze}function $z(e){let t=e.model.getters.getCurrentStyle();return t.wrapping?t.wrapping:Be}function eB(e){switch(Zz(e)){case`right`:return`o-spreadsheet-Icon.ALIGN_RIGHT`;case`center`:return`o-spreadsheet-Icon.ALIGN_CENTER`;default:return`o-spreadsheet-Icon.ALIGN_LEFT`}}function tB(e){switch(Qz(e)){case`top`:return`o-spreadsheet-Icon.ALIGN_TOP`;case`middle`:return`o-spreadsheet-Icon.ALIGN_MIDDLE`;default:return`o-spreadsheet-Icon.ALIGN_BOTTOM`}}function nB(e){switch($z(e)){case`wrap`:return`o-spreadsheet-Icon.WRAPPING_WRAP`;case`clip`:return`o-spreadsheet-Icon.WRAPPING_CLIP`;default:return`o-spreadsheet-Icon.WRAPPING_OVERFLOW`}}let rB=new IA;rB.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`sort_columns`,{...BR,name:e=>e.model.getters.getActiveCols().size>1?E(`Sort columns`):E(`Sort column`),sequence:50,separator:!0}).addChild(`sort_ascending`,[`sort_columns`],{...VR,sequence:10}).addChild(`sort_descending`,[`sort_columns`],{...GR,sequence:20}).add(`add_column_before`,{...aL,sequence:70}).add(`add_column_after`,{...cL,sequence:80}).add(`delete_column`,{...BI,sequence:90,icon:`o-spreadsheet-Icon.TRASH`}).add(`clear_column`,{...HI,sequence:100,icon:`o-spreadsheet-Icon.CLEAR`}).add(`hide_columns`,{...VF,sequence:105,separator:!0}).add(`unhide_columns`,{...HF,sequence:106,separator:!0}).add(`conditional_formatting`,{...Gz,sequence:110,separator:!0}).add(`edit_table`,{...qI,isVisible:DF,sequence:120}).add(`delete_table`,{...JI,isVisible:DF,sequence:125,separator:!0}).add(`group_columns`,{sequence:150,...oI}).add(`ungroup_columns`,{sequence:155,...cI,isVisible:e=>fI(e,`COL`)});let iB={CannotHideAllRows:E(`Cannot hide all the rows of a sheet.`),CannotHideAllColumns:E(`Cannot hide all the columns of a sheet.`)};function aB(e,t,n,r,i){let a=e.model.getters.getHeaderGroup(t,n,r,i);if(!a)return;let o=a.isFolded?`UNFOLD_HEADER_GROUP`:`FOLD_HEADER_GROUP`,s=e.model.dispatch(o,{sheetId:t,dimension:n,start:a.start,end:a.end});if(!s.isSuccessful&&s.isCancelledBecause(`NotEnoughElements`)){let t=n===`ROW`?iB.CannotHideAllRows:iB.CannotHideAllColumns;e.raiseError(t)}}function oB(e,t){return f([{id:`unfold_all`,name:E(t===`ROW`?`Expand all row groups`:`Expand all column groups`),execute:n=>{n.model.dispatch(`UNFOLD_ALL_HEADER_GROUPS`,{sheetId:e,dimension:t})}},{id:`fold_all`,name:E(t===`ROW`?`Collapse all row groups`:`Collapse all column groups`),execute:n=>{n.model.dispatch(`FOLD_ALL_HEADER_GROUPS`,{sheetId:e,dimension:t})}}])}function sB(e,t,n,r){return[...f([{id:`toggle_group`,name:e=>{let i=e.model.getters.getActiveSheetId();return e.model.getters.isGroupFolded(i,t,n,r)?E(t===`ROW`?`Expand row group`:`Expand column group`):E(t===`ROW`?`Collapse row group`:`Collapse column group`)},execute:e=>{aB(e,e.model.getters.getActiveSheetId(),t,n,r)}},{id:`remove_group`,name:E(t===`ROW`?`Remove row group`:`Remove column group`),execute:e=>{let i=e.model.getters.getActiveSheetId();e.model.dispatch(`UNGROUP_HEADERS`,{sheetId:i,dimension:t,start:n,end:r})},separator:!0}]),...oB(e,t)]}let cB=new IA;cB.add(`group_columns`,{sequence:10,...oI,isVisible:()=>!0,isEnabled:oI.isVisible}).add(`group_rows`,{sequence:20,...sI,isVisible:()=>!0,isEnabled:sI.isVisible});let lB=new IA;lB.add(`ungroup_columns`,{sequence:10,...cI,isEnabled:e=>fI(e,`COL`)}).add(`ungroup_rows`,{sequence:20,...lI,isEnabled:e=>fI(e,`ROW`)});let uB=new IA;uB.add(`cut`,{...AI,sequence:10}).add(`copy`,{...kI,sequence:20}).add(`paste`,{...jI,sequence:30}).add(`paste_special`,{...MI,sequence:40,separator:!0}).addChild(`paste_value_only`,[`paste_special`],{...NI,sequence:10}).addChild(`paste_format_only`,[`paste_special`],{...PI,sequence:20}).add(`add_row_before`,{...$I,sequence:50}).add(`add_row_after`,{...nL,sequence:60}).add(`delete_row`,{...LI,sequence:70,icon:`o-spreadsheet-Icon.TRASH`}).add(`clear_row`,{...zI,sequence:80,icon:`o-spreadsheet-Icon.CLEAR`}).add(`hide_rows`,{...WF,sequence:85,separator:!0}).add(`unhide_rows`,{...GF,sequence:86,separator:!0}).add(`conditional_formatting`,{...Gz,sequence:90,separator:!0}).add(`group_rows`,{sequence:100,...sI}).add(`ungroup_rows`,{sequence:110,...lI,isVisible:e=>fI(e,`ROW`)});var dB=class extends bf{highlightStore=this.get(Kk);constructor(e){super(e),this.highlightStore.register(this)}get highlights(){let e=this.model.getters.getActivePosition(),t=this.model.getters.getArrayFormulaSpreadingOn(e),n=t?this.model.getters.getSpreadZone(t,{ignoreSpillError:!0}):this.model.getters.getSpreadZone(e,{ignoreSpillError:!0});if(!n)return[];let r=this.model.getters.isArrayFormulaSpillBlocked(t??e);return[{range:this.model.getters.getRangeFromZone(e.sheetId,n),dashed:r,color:`#17A2B8`,noFill:!0,thinLine:!0}]}},fB=class extends bf{mutators=[`focusClient`,`unfocusClient`,`showClientTag`,`hideClientTag`,`jumpToClient`];_showClientTag=!1;clientFocusTimeout={};constructor(e){super(e),this.onDispose(()=>{for(let e in this.clientFocusTimeout)this.unfocusClient(e)})}get focusedClients(){let e=new Set;return this.model.getters.getConnectedClients().forEach(t=>{(this._showClientTag||this.clientFocusTimeout[t.id]!==void 0)&&e.add(t.id)}),e}jumpToClient(e){let t=this.model.getters.getClient(e);this.focusClient(e),t.position&&(this.model.dispatch(`ACTIVATE_SHEET`,{sheetIdTo:t.position.sheetId,sheetIdFrom:this.getters.getActiveSheetId()}),this.model.dispatch(`SCROLL_TO_CELL`,{col:t.position.col,row:t.position.row}))}showClientTag(){this._showClientTag=!0}hideClientTag(){this._showClientTag=!1}focusClient(e){this.clientFocusTimeout[e]&&clearTimeout(this.clientFocusTimeout[e]),this.clientFocusTimeout[e]=setTimeout(()=>this.unfocusClient(e),3e3)}unfocusClient(e){this.clientFocusTimeout[e]&&clearTimeout(this.clientFocusTimeout[e]),this.clientFocusTimeout[e]=void 0}};function pB(e){let n=null,r,i,a,o,s=`all`,c=e.model.getters,l=[],u=()=>{clearTimeout(n),n=null,l.forEach(e=>e()),l=[]},d,f,p=t=>{if(r=t,n)return;let l=c.getActiveSheetId(),u=qw(),{x:f,y:m}=c.getMainViewportCoordinates(),{top:h,left:g,bottom:_,right:v}=c.getActiveMainViewport(),{scrollX:y,scrollY:ee}=c.getActiveSheetScrollInfo(),{xSplit:te,ySplit:ne}=c.getPaneDivisions(l),re=!1,ie=140,ae=r.clientX-u.left,oe=c.getColIndex(ae);if(s!==`vertical`){let t=i.clientX-u.left,n=c.getEdgeScrollCol(ae,t,a);if(n.canEdgeScroll){re=!0,ie=Math.min(ie,n.delay);let t=oe;switch(n.direction){case`reset`:oe=t=te;break;case 1:oe=v,t=g+1;break;case-1:for(oe=g-1;e.model.getters.isColHidden(l,oe);)oe--;t=oe;break}y=c.getColDimensions(l,t).start-f}}let se=r.clientY-u.top,ce=c.getRowIndex(se);if(s!==`horizontal`){let t=i.clientY-u.top,n=c.getEdgeScrollRow(se,t,o);if(n.canEdgeScroll){re=!0,ie=Math.min(ie,n.delay);let t=ce;switch(n.direction){case`reset`:ce=t=ne;break;case 1:ce=_,t=h+1;break;case-1:for(ce=h-1;e.model.getters.isRowHidden(l,ce);)ce--;t=ce;break}ee=e.model.getters.getRowDimensions(l,t).start-m}}re||(oe=mB(oe,ae,c.getNumberCols(l)-1),ce=mB(ce,se,c.getNumberRows(l)-1)),d?.(oe,ce,r),re&&(e.model.dispatch(`SET_VIEWPORT_OFFSET`,{offsetX:y,offsetY:ee}),n=setTimeout(()=>{n=null,p(r)},Math.round(ie))),i={clientX:r.clientX,clientY:r.clientY}},m=()=>{f?.(),u()};return(0,t.onWillUnmount)(()=>{u()}),(0,t.useEffect)(()=>{u()},()=>[c.getActiveSheetId()]),{start:(e,t,n,r=`all`)=>{u();let c=qw();s=r,a=e.clientX-c.left,o=e.clientY-c.top,i={clientX:e.clientX,clientY:e.clientY},d=t,f=n,l.push(rA(p,m))}}}function mB(e,t,n){return e===-1?t<0?0:n:e}B`
|
|
837
837
|
.o-autofill {
|
|
838
838
|
position: absolute;
|
|
839
839
|
height: ${8}px;
|
|
@@ -1926,9 +1926,9 @@ stores.inject(MyMetaStore, storeInstance);
|
|
|
1926
1926
|
background: #e7f2f6;
|
|
1927
1927
|
}
|
|
1928
1928
|
}
|
|
1929
|
-
`;var YU=class extends t.Component{static template=`o_spreadsheet.PivotHTMLRenderer`;static components={Checkbox:bA};static props={pivotId:String,onCellClicked:Function};pivot=this.env.model.getters.getPivot(this.props.pivotId);data={columns:[],rows:[],values:[]};state=(0,t.useState)({showMissingValuesOnly:!1});setup(){let e=this.pivot.getExpandedTableStructure(),t=this.env.model.getters.getPivotFormulaId(this.props.pivotId);this.data={columns:this._buildColHeaders(t,e),rows:this._buildRowHeaders(t,e),values:this._buildValues(t,e)}}get tracker(){return this.env.model.getters.getPivotPresenceTracker(this.props.pivotId)}getTableData(){if(!this.state.showMissingValuesOnly)return this.data;let e=this.getColumnsIndexes(),t=this.getRowsIndexes();return{columns:this.buildColumnsMissing(e),rows:this.buildRowsMissing(t),values:this.buildValuesMissing(e,t)}}addRecursiveRow(e){let t=this.pivot.getExpandedTableStructure().rows,n=[...t[e].values];if(n.length<=1)return[e];n.pop();let r=t.findIndex(e=>JSON.stringify(e.values)===JSON.stringify(n));return[e].concat(this.addRecursiveRow(r))}buildColumnsMissing(e){let t=[];for(let e of this.data.columns){let n=[];for(let t in e)for(let r=0;r<e[t].span;r++)n.push(parseInt(t,10));t.push(n)}for(let n=t[t.length-1].length;n>=0;n--)if(!e.includes(n))for(let e of t)e.splice(n,1);let n=[];for(let e in t){let r=[],i,a=1;for(let n=0;n<t[e].length;n++)i===t[e][n]?a++:(i!==void 0&&r.push(Object.assign({},this.data.columns[e][i],{span:a})),i=t[e][n],a=1);i!==void 0&&r.push(Object.assign({},this.data.columns[e][i],{span:a})),n.push(r)}return n}buildRowsMissing(e){return e.map(e=>this.data.rows[e])}buildValuesMissing(e,t){let n=e.map(()=>[]);for(let r of t)for(let t in e)n[t].push(this.data.values[e[t]][r]);return n}getColumnsIndexes(){let e=new Set;for(let t=0;t<this.data.columns.length;t++){let n=[];for(let e=0;e<this.data.columns[t].length;e++)for(let r=0;r<this.data.columns[t][e].span;r++)n.push(this.data.columns[t][e]);for(let t=0;t<n.length;t++)n[t].isMissing&&e.add(t)}for(let t=0;t<this.data.columns[this.data.columns.length-1].length;t++)this.data.values[t].find(e=>e.isMissing)&&e.add(t);return Array.from(e).sort((e,t)=>e-t)}getRowsIndexes(){let e=new Set;for(let t=0;t<this.data.rows.length;t++){this.data.rows[t].isMissing&&e.add(t);for(let n of this.data.values)n[t].isMissing&&this.addRecursiveRow(t).forEach(t=>e.add(t))}return Array.from(e).sort((e,t)=>e-t)}_buildColHeaders(e,t){let n=[];for(let r of t.columns){let t=[];for(let n of r){let r=[];for(let e=0;e<n.fields.length;e++)r.push({value:n.fields[e]},{value:n.values[e]});let i=this.pivot.parseArgsToPivotDomain(r),a=this.env.model.getters.getLocale();if(i.at(-1)?.field===`measure`){let{value:r,format:o}=this.pivot.getPivotMeasureValue(N(i.at(-1).value),i);t.push({formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(r,{format:o,locale:a}),span:n.width,isMissing:!this.tracker?.isHeaderPresent(i)})}else{let{value:r,format:o}=this.pivot.getPivotHeaderValueAndFormat(i);t.push({formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(r,{format:o,locale:a}),span:n.width,isMissing:!this.tracker?.isHeaderPresent(i)})}}n.push(t)}let r=n[n.length-1];return n[n.length-1]=r.map(e=>(e.isMissing||(e.style=`color: #756f6f;`),e)),n}_buildRowHeaders(e,t){let n=[];for(let r of t.rows){let t=[];for(let e=0;e<r.fields.length;e++)t.push({value:r.fields[e]},{value:r.values[e]});let i=this.pivot.parseArgsToPivotDomain(t),{value:a,format:o}=this.pivot.getPivotHeaderValueAndFormat(i),s=this.env.model.getters.getLocale(),c={formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(a,{format:o,locale:s}),isMissing:!this.tracker?.isHeaderPresent(i)};r.indent>1&&(c.style=`padding-left: ${r.indent-10}px`),n.push(c)}return n}_buildValues(e,t){let n=[];for(let r of t.columns.at(-1)||[]){let i=[],a=N(r.values[r.values.length-1]);for(let n of t.rows){let t=[];for(let e=0;e<n.fields.length;e++)t.push({value:n.fields[e]},{value:n.values[e]});for(let e=0;e<r.fields.length-1;e++)t.push({value:r.fields[e]},{value:r.values[e]});let o=this.pivot.parseArgsToPivotDomain(t),{value:s,format:c}=this.pivot.getPivotCellValueAndFormat(a,o),l=this.env.model.getters.getLocale();i.push({formula:`=PIVOT.VALUE(${Ad(e,o,a).join(`,`)})`,value:L(s,{format:c,locale:l}),isMissing:!this.tracker?.isValuePresent(a,o)})}n.push(i)}return n}},XU=class extends Lp{getters;dispatch;canDispatch;constructor({getters:e,stateObserver:t,range:n,dispatch:r,canDispatch:i}){super(t),n.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.dispatch=r,this.canDispatch=i}import(e){}export(e){}adaptRanges(e,t,n){}garbageCollectExternalResources(){}},ZU=class extends XU{static getters=[`getCellBorder`,`getBordersColors`];borders={};allowDispatch(e){switch(e.type){case`SET_BORDER`:return this.checkBordersUnchanged(e);default:return`Success`}}handle(e){switch(e.type){case`ADD_MERGE`:for(let t of e.target)this.addBordersToMerge(e.sheetId,t);break;case`DUPLICATE_SHEET`:let t=this.borders[e.sheetId];if(t){let n=t.slice().map(e=>e?.slice().map(e=>b(e)));this.history.update(`borders`,e.sheetIdTo,n)}break;case`DELETE_SHEET`:let n={...this.borders};delete n[e.sheetId],this.history.update(`borders`,n);break;case`SET_BORDER`:this.setBorder(e.sheetId,e.col,e.row,e.border);break;case`SET_BORDERS_ON_TARGET`:for(let t of e.target)for(let n=t.top;n<=t.bottom;n++)for(let r=t.left;r<=t.right;r++)this.setBorder(e.sheetId,r,n,e.border);break;case`SET_ZONE_BORDERS`:if(e.border){let t=e.target.map(t=>this.getters.expandZone(e.sheetId,t));this.setBorders(e.sheetId,t,e.border.position,e.border.color===``?void 0:{style:e.border.style||Ue.style,color:e.border.color||Ue.color})}break;case`CLEAR_FORMATTING`:this.clearBorders(e.sheetId,e.target);break;case`REMOVE_COLUMNS_ROWS`:let r=[...e.elements].sort((e,t)=>t-e);for(let t of gt(r))if(e.dimension===`COL`){let n=this.getters.getColsZone(e.sheetId,t[t.length-1],t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersHorizontally(e.sheetId,t[0]+1,-t.length)}else{let n=this.getters.getRowsZone(e.sheetId,t[t.length-1],t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersVertically(e.sheetId,t[0]+1,-t.length)}break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.handleAddColumns(e):this.handleAddRows(e);break}}handleAddColumns(e){let t,n;e.position===`before`?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity),t=e.base,n=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,n)}handleAddRows(e){let t,n;e.position===`before`?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity),t=e.base,n=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,n)}getCellBorder({sheetId:e,col:t,row:n}){let r=this.borders[e]?.[t]?.[n];return r?.top||r?.bottom||r?.left||r?.right?b(r):null}getBordersColors(e){let t=[],n=this.borders[e];if(n){for(let e of n.filter(C))for(let n of e)if(n)for(let e of[`top`,`bottom`,`left`,`right`]){let r=n[e]?.color;r&&t.push(r)}}return t}ensureColumnBorderContinuity(e,t,n){let r=S(t+1,n);for(let i=0;i<this.getters.getNumberRows(e);i++){let a=this.getCellBorder({sheetId:e,col:t,row:i}),o=this.getCellBorder({sheetId:e,col:n,row:i});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,n,i,t)}}}ensureRowBorderContinuity(e,t,n){let r=S(t+1,n);for(let i=0;i<this.getters.getNumberCols(e);i++){let a=this.getCellBorder({sheetId:e,col:i,row:t}),o=this.getCellBorder({sheetId:e,col:i,row:n});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,i,n,t)}}}getCommonSides(e,t){let n={};for(let r of[`top`,`bottom`,`left`,`right`])e[r]&&w(e[r],t[r])&&(n[r]=e[r]);return n}getColumnsWithBorders(e){let t=this.borders[e];return t?Object.keys(t).map(e=>parseInt(e,10)):[]}getRowsWithBorders(e){let t=this.borders[e]?.filter(C);if(!t)return[];let n=new Set;for(let e of t)for(let t in e)n.add(parseInt(t,10));return Array.from(n)}getRowsRange(e){return this.borders[e]?S(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,n){this.borders[e]&&this.getColumnsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(t=>{this.moveBordersOfColumn(e,t,n)})}shiftBordersVertically(e,t,n){this.borders[e]&&(n<0&&this.moveBordersOfRow(e,t,n,{destructive:!1}),this.getRowsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(t=>{this.moveBordersOfRow(e,t,n)}))}moveBordersOfRow(e,t,n,{destructive:r}={destructive:!0}){let i=this.borders[e];i&&this.getColumnsWithBorders(e).forEach(a=>{let o=i[a]?.[t+n],s=i[a]?.[t];this.history.update(`borders`,e,a,t+n,r?s:s||o),this.history.update(`borders`,e,a,t,void 0)})}moveBordersOfColumn(e,t,n,{destructive:r}={destructive:!0}){let i=this.borders[e];i&&this.getRowsRange(e).forEach(a=>{let o=i[t+n]?.[a],s=i[t]?.[a];this.history.update(`borders`,e,t+n,a,r?s:s||o),r&&this.history.update(`borders`,e,t,a,void 0)})}setBorder(e,t,n,r,i=!0){let a=this.getters.getNumberCols(e)-1,o=this.getters.getNumberRows(e)-1;(i||!this.borders[e]?.[t]?.[n]?.left)&&(this.history.update(`borders`,e,t,n,`left`,r?.left),r?.left&&t>0&&!w(this.borders[e]?.[t-1]?.[n]?.right,r?.left)&&this.history.update(`borders`,e,t-1,n,`right`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.top)&&(this.history.update(`borders`,e,t,n,`top`,r?.top),r?.top&&n>0&&!w(this.borders[e]?.[t]?.[n-1]?.bottom,r?.top)&&this.history.update(`borders`,e,t,n-1,`bottom`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.right)&&(this.history.update(`borders`,e,t,n,`right`,r?.right),r?.right&&t<a&&!w(this.borders[e]?.[t+1]?.[n]?.left,r?.right)&&this.history.update(`borders`,e,t+1,n,`left`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.bottom)&&(this.history.update(`borders`,e,t,n,`bottom`,r?.bottom),r?.bottom&&n<o&&!w(this.borders[e]?.[t]?.[n+1]?.top,r?.bottom)&&this.history.update(`borders`,e,t,n+1,`top`,void 0))}clearBorders(e,t,n=!1){let r=this.getters.getNumberCols(e)-1,i=this.getters.getNumberRows(e)-1;for(let a of ms(t))for(let t=a.top;t<=a.bottom;t++){n&&(a.left>0&&this.history.update(`borders`,e,a.left-1,t,`right`,void 0),a.right<r&&this.history.update(`borders`,e,a.right+1,t,`left`,void 0));for(let r=a.left;r<=a.right;r++)this.history.update(`borders`,e,r,t,void 0),n&&(a.top>0&&this.history.update(`borders`,e,r,a.top-1,`bottom`,void 0),a.bottom<i&&this.history.update(`borders`,e,r,a.bottom+1,`top`,void 0))}}clearInsideBorders(e,t){for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let r=n.left;r<=n.right;r++)this.history.update(`borders`,e,r,t,void 0)}addBorder(e,t,n,r){this.setBorder(e,t,n,{...this.getCellBorder({sheetId:e,col:t,row:n}),...r})}setBorders(e,t,n,r){if(n===`clear`)return this.clearBorders(e,t,!0);for(let i of ms(t)){if(n===`all`)for(let t=i.top;t<=i.bottom;t++)for(let n=i.left;n<=i.right;n++)this.addBorder(e,n,t,{top:r,right:r,bottom:r,left:r});if(n===`h`||n===`hv`){if(i.top===i.bottom)continue;for(let t=i.left;t<=i.right;t++){this.addBorder(e,t,i.top,{bottom:r});for(let n=i.top+1;n<i.bottom;n++)this.addBorder(e,t,n,{top:r,bottom:r});this.addBorder(e,t,i.bottom,{top:r})}}if(n===`v`||n===`hv`){if(i.left===i.right)continue;for(let t=i.top;t<=i.bottom;t++){this.addBorder(e,i.left,t,{right:r});for(let n=i.left+1;n<i.right;n++)this.addBorder(e,n,t,{left:r,right:r});this.addBorder(e,i.right,t,{left:r})}}if(n===`left`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.left,t,{left:r});if(n===`right`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.right,t,{right:r});if(n===`top`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.top,{top:r});if(n===`bottom`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.bottom,{bottom:r})}}addBordersToMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t,o=this.getCellBorder({sheetId:e,col:n,row:i}),s=this.getCellBorder({sheetId:e,col:r,row:a});this.clearBorders(e,[t]),o?.top&&this.setBorders(e,[{...t,bottom:i}],`top`,o.top),o?.left&&this.setBorders(e,[{...t,right:n}],`left`,o.left),s?.bottom?this.setBorders(e,[{...t,top:a}],`bottom`,s.bottom):o?.bottom&&this.setBorders(e,[{...t,top:a}],`bottom`,o.bottom),s?.right?this.setBorders(e,[{...t,left:r}],`right`,s.right):o?.right&&this.setBorders(e,[{...t,left:r}],`right`,o.right)}checkBordersUnchanged(e){let t=this.getCellBorder(e),n=!e.border?.bottom&&!e.border?.left&&!e.border?.right&&!e.border?.top;return!t&&n||w(t,e.border)?`NoChanges`:`Success`}import(e){if(Object.keys(e.borders||{}).length)for(let t of e.sheets)for(let[n,r]of gc(t.id,t.borders)){let{sheetId:t,col:i,row:a}=n,o=e.borders[r];this.setBorder(t,i,a,o,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,Ts(e))}export(e){let t={};for(let n of e.sheets){let e={};for(let r=0;r<n.colNumber;r++)for(let i=0;i<n.rowNumber;i++){let a=this.getCellBorder({sheetId:n.id,col:r,row:i});if(a){let o=mc(a,t),s={sheetId:n.id,col:r,row:i};e[o]??=[],e[o].push(s)}}n.borders=hc(e)}e.borders=t}exportForExcel(e){this.export(e)}},QU=class extends XU{static getters=[`zoneToXC`,`getCells`,`getTranslatedCellFormula`,`getCellStyle`,`getCellById`,`getFormulaString`,`getFormulaMovedInSheet`];nextId=1;cells={};adaptRanges({applyChange:e},t,n){for(let r of Object.keys(this.cells))for(let i of Object.values(this.cells[r]||{}))if(i.isFormula){for(let a of i.compiledFormula.dependencies)if(a.sheetId===t||a.invalidSheetName===n.old){let t=e(a);t.changeType!==`NONE`&&this.history.update(`cells`,r,i.id,`compiledFormula`,`dependencies`,i.compiledFormula.dependencies.indexOf(a),t.range)}}}allowDispatch(e){switch(e.type){case`UPDATE_CELL`:return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessUpdateCell);case`CLEAR_CELL`:return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessClearCell);case`UPDATE_CELL_POSITION`:return!e.cellId||this.cells[e.sheetId]?.[e.cellId]?`Success`:`InvalidCellId`;default:return`Success`}}handle(e){switch(e.type){case`SET_FORMATTING`:`style`in e&&this.setStyle(e.sheetId,e.target,e.style),`format`in e&&e.format!==void 0&&this.setFormatter(e.sheetId,e.target,e.format);break;case`CLEAR_FORMATTING`:this.clearFormatting(e.sheetId,e.target);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case`UPDATE_CELL`:this.updateCell(e.sheetId,e.col,e.row,e);break;case`CLEAR_CELL`:this.dispatch(`UPDATE_CELL`,{sheetId:e.sheetId,col:e.col,row:e.row,content:``,style:null,format:``});break;case`CLEAR_CELLS`:this.clearCells(e.sheetId,e.target);break;case`DELETE_CONTENT`:this.clearZones(e.sheetId,e.target);break;case`DELETE_SHEET`:this.history.update(`cells`,e.sheetId,void 0)}}clearZones(e,t){for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++){let n=this.getters.getCell({sheetId:e,col:t,row:r});(n?.isFormula||n?.content)&&this.dispatch(`UPDATE_CELL`,{sheetId:e,content:``,col:t,row:r})}}setFormatter(e,t,n){for(let r of ms(t))for(let t=r.top;t<=r.bottom;t++)for(let i=r.left;i<=r.right;i++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:i,row:t,format:n})}clearFormatting(e,t){for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,style:null,format:``})}clearCells(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:``,style:null,format:``})}handleAddColumnsRows(e,t){let n,r;e.position===`before`?(n=S(e.base,e.base+e.quantity),r=e.base+e.quantity):(n=S(e.base+1,e.base+e.quantity+1),r=e.base),t(e.sheetId,r,n)}import(e){for(let t of e.sheets){let n=t.id,r=new LF;for(let e in t.cells)if(t.cells[e]){let{col:n,row:i}=ir(e),a={sheetId:t.id,col:n,row:i};r.set(a,{content:t.cells[e]})}for(let[e,n]of[[`style`,t.styles],[`format`,t.formats]])for(let[i,a]of gc(t.id,n)){let t=r.get(i);t?t[e]=a:r.set(i,{[e]:a})}for(let i of r.keysForSheet(n)){let n=r.get(i);if(n?.content||n?.format||n?.style){let r=this.importCell(t.id,n?.content,n?.style?e.styles[n?.style]:void 0,n?.format?e.formats[n?.format]:void 0);this.history.update(`cells`,t.id,r.id,r),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:r.id,...i})}}}}export(e){let t={},n={};for(let r of e.sheets){let e=[],i=[],a={},o=Object.keys(this.cells[r.id]||{}).map(e=>this.getters.getCellPosition(e)).sort((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col);for(let r of o){let o=this.getters.getCell(r),s=T(r.col,r.row),c=this.extractCustomStyle(o);if(Object.keys(c).length){let n=mc(c,t);e[n]??=[],e[n].push(r)}if(o.format){let e=mc(o.format,n);i[e]??=[],i[e].push(r)}o.content&&(a[s]=o.content)}r.styles=hc(e),r.formats=hc(i),r.cells=a}e.styles=t,e.formats=n}importCell(e,t,n,r){let i=this.getNextUid();return this.createCell(i,t||``,r,n,e)}exportForExcel(e){this.export(e);let t=[];for(let n in e.formats||[])Qo(e.formats[n])||(t.push(Number(n)),delete e.formats[n]);if(t.length)for(let n of e.sheets)for(let e in n.formats){let r=n.formats[e];r&&t.includes(r)&&delete n.formats[e]}}extractCustomStyle(e){let t={...e.style},n=Hi(e.content,D)?Re:Le;for(let r in t)(r!==`align`||!e.isFormula)&&t[r]===n[r]&&delete t[r];return t}getCells(e){return this.cells[e]||{}}getCellById(e){let t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}getFormulaString(e,t,n,r=!1){if(!n.length)return Mt(t.map(e=>e.value));let i=0;return Mt(t.map(t=>{if(t.type===`REFERENCE`){let t=n[i++];return this.getters.getRangeString(t,e,{useBoundedReference:r})}return t.value}))}getTranslatedCellFormula(e,t,n,r){let i=this.getters.createAdaptedRanges(iC(r).dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t)),t,n,e);return this.getFormulaString(e,r,i)}getFormulaMovedInSheet(e,t,n){let r=iC(n).dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t)),i=this.getters.removeRangesSheetPrefix(t,r);return this.getFormulaString(t,n,i)}getCellStyle(e){return this.getters.getCell(e)?.style||{}}zoneToXC(e,t,n=[{colFixed:!1,rowFixed:!1}]){t=this.getters.expandZone(e,t);let r=T(t.left,t.top,n[0]),i=T(t.right,t.bottom,n.length>1?n[1]:n[0]),a=this.getters.getMainCellPosition({sheetId:e,col:t.left,row:t.top}),o=this.getters.getMainCellPosition({sheetId:e,col:t.right,row:t.bottom}),s=a.col===o.col&&a.row===o.row;return r!==i&&!s?r+`:`+i:r}setStyle(e,t,n){for(let r of ms(t))for(let t=r.left;t<=r.right;t++)for(let i=r.top;i<=r.bottom;i++){let r=this.getters.getCell({sheetId:e,col:t,row:i});this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:i,style:n?{...r?.style,...n}:void 0})}}copyColumnStyle(e,t,n){for(let r=0;r<this.getters.getNumberRows(e);r++){let i=this.getFormat(e,t,r);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,...i})}}copyRowStyle(e,t,n){for(let r=0;r<this.getters.getNumberCols(e);r++){let i=this.getFormat(e,r,t);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:r,row:t,...i})}}getFormat(e,t,n){let r={},i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.getters.getCell(i);return a&&(a.style&&(r.style=a.style),a.format&&(r.format=a.format)),r}getNextUid(){let e=this.nextId.toString();return this.history.update(`nextId`,this.nextId+1),e}updateCell(e,t,n,r){let i=this.getters.getCell({sheetId:e,col:t,row:n}),a=r.content!==void 0||`formula`in r,o=a?Wt(r?.content||void 0):i?.content||``,s;s=r.style===void 0?i?i.style:void 0:r.style||void 0;let c=r.format===void 0?i&&i.format:r.format;if((a&&!o&&!r.formula||!a&&(!i||i.content===``))&&!s&&!c){i&&(this.history.update(`cells`,e,i.id,void 0),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:void 0,col:t,row:n,sheetId:e}));return}let l=i?.id||this.getNextUid(),u=this.createCell(l,o,c,s,e);this.history.update(`cells`,e,u.id,u),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:u.id,col:t,row:n,sheetId:e})}createCell(e,t,n,r,i){return t.startsWith(`=`)?this.createFormulaCell(e,t,n,r,i):this.createLiteralCell(e,t,n,r)}createLiteralCell(e,t,n,r){let i=this.getters.getLocale(),a=ts(t,i);return n||=typeof a==`number`?Io(t,i)||Lo(t):void 0,!$o(n)&&!j(t)&&(t=N(a)),{id:e,content:t,style:r,format:n,isFormula:!1,parsedValue:a}}createFormulaCell(e,t,n,r,i){let a=rC(t);return a.dependencies.length?this.createFormulaCellWithDependencies(e,a,n,r,i):{id:e,content:t,style:r,format:n,isFormula:!0,compiledFormula:{...a,dependencies:[]}}}createFormulaCellWithDependencies(e,t,n,r,i){let a=[];for(let e of t.dependencies)a.push(this.getters.getRangeFromSheetXC(i,e));return new $U(e,t,n,r,a,i,this.getters.getRangeString)}checkCellOutOfSheet(e){let{sheetId:t,col:n,row:r}=e;return this.getters.tryGetSheet(t)?Vs(n,r,this.getters.getSheetZone(t))?`Success`:`TargetOutOfSheet`:`InvalidSheetId`}checkUselessClearCell(e){let t=this.getters.getCell(e);return!t||!t.content&&!t.style&&!t.format?`NoChanges`:`Success`}checkUselessUpdateCell(e){let t=this.getters.getCell(e),n=`content`in e||`formula`in e,r=`style`in e,i=`format`in e;return(!n||t?.content===e.content)&&(!r||w(t?.style,e.style))&&(!i||t?.format===e.format)?`NoChanges`:`Success`}},$U=class{id;format;style;sheetId;getRangeString;isFormula=!0;compiledFormula;constructor(e,t,n,r,i,a,o){this.id=e,this.format=n,this.style=r,this.sheetId=a,this.getRangeString=o;let s=0,c=t.tokens.map(e=>e.type===`REFERENCE`?new eW(i,s++,this.sheetId,this.getRangeString):e);this.compiledFormula={...t,dependencies:i,tokens:c}}get content(){return Mt(this.compiledFormula.tokens.map(e=>e.value))}get contentWithFixedReferences(){let e=0;return Mt(this.compiledFormula.tokens.map(t=>{if(t.type===`REFERENCE`){let t=e++;return this.getRangeString(this.compiledFormula.dependencies[t],this.sheetId,{useBoundedReference:!0})}return t.value}))}},eW=class{ranges;rangeIndex;sheetId;getRangeString;type=`REFERENCE`;constructor(e,t,n,r){this.ranges=e,this.rangeIndex=t,this.sheetId=n,this.getRangeString=r}get value(){let e=this.ranges[this.rangeIndex];return this.getRangeString(e,this.sheetId)}},tW=class extends XU{static getters=[`isChartDefined`,`getChartDefinition`,`getChartType`,`getChartIds`,`getChart`,`getFigureIdFromChartId`,`getContextCreationChart`];charts={};createChart=_O(this.getters);validateChartDefinition=e=>yO(this,e.definition);adaptRanges(e){for(let[t,n]of Object.entries(this.charts)){if(!n)continue;let r=n.chart.updateRanges(e);this.history.update(`charts`,t,r?{figureId:n.figureId,chart:r}:void 0)}}allowDispatch(e){switch(e.type){case`CREATE_CHART`:return this.checkValidations(e,this.chainValidations(this.checkFigureArguments,this.validateChartDefinition,this.checkChartDuplicate));case`UPDATE_CHART`:return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists,this.checkChartChanged));case`DELETE_CHART`:return this.checkChartExists(e);default:return`Success`}}handle(e){switch(e.type){case`CREATE_CHART`:let{col:t,row:n,offset:r,size:i,sheetId:a,figureId:o}=e;!this.getters.getFigure(a,o)&&r!==void 0&&t!==void 0&&n!==void 0&&this.addFigure(o,a,t,n,r,i),this.addChart(e.figureId,e.chartId,e.definition);break;case`UPDATE_CHART`:this.addChart(e.figureId,e.chartId,e.definition);break;case`DUPLICATE_SHEET`:for(let t of this.getChartIds(e.sheetId)){let{chart:n,figureId:r}=this.charts[t]||{};if(!n||!r)continue;let i=this.getters.getFigure(e.sheetId,r);if(!i)continue;let a=r.split(`??`).pop(),o=`${e.sheetIdTo}??${a}`,s=t.split(`??`).pop(),c=`${e.sheetIdTo}??${s}`,l=n.duplicateInDuplicatedSheet(e.sheetIdTo);l&&this.dispatch(`CREATE_CHART`,{figureId:o,chartId:c,col:i.col,row:i.row,offset:i.offset,size:{width:i.width,height:i.height},definition:l.getDefinition(),sheetId:e.sheetIdTo})}break;case`DELETE_FIGURE`:for(let t in this.charts)this.charts[t]?.figureId===e.figureId&&this.dispatch(`DELETE_CHART`,{chartId:t,sheetId:e.sheetId});break;case`DELETE_CHART`:this.isChartDefined(e.chartId)&&this.history.update(`charts`,e.chartId,void 0);break;case`DELETE_SHEET`:for(let t of this.getChartIds(e.sheetId))this.history.update(`charts`,t,void 0);break}}getContextCreationChart(e){return this.charts[e]?.chart.getContextCreation()}getChart(e){return this.charts[e]?.chart}getFigureIdFromChartId(e){if(!this.charts[e])throw Error(`Chart with id ${e} does not exist.`);return this.charts[e].figureId}getChartType(e){let t=this.charts[e]?.chart.type;if(!t)throw Error(`Chart not defined.`);return t}isChartDefined(e){return e in this.charts&&this.charts!==void 0}getChartIds(e){return Object.entries(this.charts).filter(([,t])=>t?.chart.sheetId===e).map(([e])=>e)}getChartDefinition(e){let t=this.charts[e]?.chart.getDefinition();if(!t)throw Error(`There is no chart with the given id: ${e}`);return t}import(e){for(let t of e.sheets)if(t.figures){for(let e of t.figures)if(e.tag===`chart`){let n=e.data.chartId,r=this.createChart(e.id,e.data,t.id);this.charts[n]={chart:r,figureId:e.id}}else if(e.tag===`carousel`)for(let n in e.data.chartDefinitions||{}){let r=e.data.chartDefinitions[n],i=this.createChart(e.id,r,t.id);this.charts[n]={chart:i,figureId:e.id}}}}export(e){if(e.sheets)for(let t of e.sheets){let e=this.getters.getFigures(t.id),n=[];for(let t of e){let e=t,r=Object.keys(this.charts).find(e=>this.charts[e]?.figureId===t.id);if(e&&e.tag===`chart`&&r){let t=this.charts[r]?.chart.getDefinition();t&&(e.data={...t,chartId:r},n.push(e))}else if(e&&e.tag===`carousel`){let r=Object.keys(this.charts).filter(e=>this.charts[e]?.figureId===t.id),i={};for(let e of r)i[e]=this.charts[e]?.chart.getDefinition();e.data={chartDefinitions:i},n.push(e)}else n.push(e)}t.figures=n}}addFigure(e,t,n,r,i,a={width:536,height:335}){this.dispatch(`CREATE_FIGURE`,{sheetId:t,figureId:e,col:n,row:r,offset:i,size:a,tag:`chart`})}addChart(e,t,n){let r=this.getters.getFigureSheetId(e);if(r){let i=this.createChart(e,n,r);this.history.update(`charts`,t,{figureId:e,chart:i})}}checkChartDuplicate(e){return this.isChartDefined(e.chartId)?`DuplicatedChartId`:`Success`}checkChartExists(e){return this.isChartDefined(e.chartId)?`Success`:`ChartDoesNotExist`}checkChartChanged(e){return e.figureId===this.charts[e.chartId]?.figureId&&w(this.getChartDefinition(e.chartId),e.definition)?`NoChanges`:`Success`}checkFigureArguments(e){return this.getters.getFigure(e.sheetId,e.figureId)||e.offset!==void 0&&e.col!==void 0&&e.row!==void 0?`Success`:`MissingFigureArguments`}};function nW(e){return e===``?NaN:Number(e)}var rW=class extends XU{static getters=[`getConditionalFormats`,`getRulesSelection`,`getRulesByCell`,`getAdaptedCfRanges`];cfRules={};adaptCFFormulas({applyChange:e,adaptFormulaString:t}){for(let n in this.cfRules)for(let r of this.cfRules[n])if(r.rule.type===`DataBarRule`&&r.rule.rangeValues){let t=e(r.rule.rangeValues);switch(t.changeType){case`REMOVE`:this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`rangeValues`,void 0);break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`rangeValues`,t.range);break}}else if(r.rule.type===`CellIsRule`)for(let e=0;e<r.rule.values.length;e++)this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`values`,e,t(n,r.rule.values[e]));else if(r.rule.type===`IconSetRule`)for(let e of[`lowerInflectionPoint`,`upperInflectionPoint`])r.rule[e].type===`formula`&&this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,e,`value`,t(n,r.rule[e].value));else if(r.rule.type===`ColorScaleRule`)for(let e of[`minimum`,`maximum`,`midpoint`]){let i=r.rule[e];i?.type===`formula`&&i?.value&&this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,e,`value`,t(n,i.value))}}adaptCFRanges(e,{applyChange:t}){for(let n of this.cfRules[e])for(let r of n.ranges){let i=t(r);switch(i.changeType){case`REMOVE`:let t=n.ranges.slice();t.splice(n.ranges.indexOf(r),1),t.length>=1?this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,t):this.removeConditionalFormatting(n.id,e);break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,n.ranges.indexOf(r),i.range);break}}}adaptRanges(e,t){let n=t?[t]:Object.keys(this.cfRules);for(let t of n)this.adaptCFRanges(t,e);this.adaptCFFormulas(e)}allowDispatch(e){switch(e.type){case`ADD_CONDITIONAL_FORMAT`:return e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkValidations(e,this.checkCFRule,this.checkEmptyRange,this.checkCFHasChanged);case`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:return this.checkValidPriorityChange(e.cfId,e.delta,e.sheetId)}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.cfRules[e.sheetId]=[];break;case`DUPLICATE_SHEET`:this.history.update(`cfRules`,e.sheetIdTo,[]);for(let t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case`DELETE_SHEET`:let t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update(`cfRules`,t);break;case`ADD_CONDITIONAL_FORMAT`:let n={...e.cf,ranges:e.ranges.map(t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId))};this.addConditionalFormatting(n,e.sheetId);break;case`REMOVE_CONDITIONAL_FORMAT`:this.removeConditionalFormatting(e.id,e.sheetId);break;case`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:this.changeCFPriority(e.cfId,e.delta,e.sheetId);break}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map(e=>this.mapToConditionalFormatInternal(t.id,e))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map(e=>this.mapToConditionalFormat(t.id,e)))}exportForExcel(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map(e=>this.mapToConditionalFormat(t.id,e,{useBoundedReference:!0})))}getConditionalFormats(e){return this.cfRules[e]?.map(t=>this.mapToConditionalFormat(e,t))||[]}getRulesSelection(e,t){let n=new Set;return t.forEach(t=>{this.getRulesByZone(e,t).forEach(e=>{n.add(e)})}),Array.from(n)}getRulesByZone(e,t){let n=new Set;for(let r=t.top;r<=t.bottom;r++)for(let i=t.left;i<=t.right;i++)this.getRulesByCell(e,i,r).forEach(e=>{n.add(e.id)});return n}getRulesByCell(e,t,n){let r=[];for(let i of this.cfRules[e])for(let e of i.ranges)Vs(t,n,e.zone)&&r.push(i);return new Set(r.map(t=>this.mapToConditionalFormat(e,t)))}getAdaptedCfRanges(e,t,n,r){if(n.length===0&&r.length===0)return;let i=this.getters.getConditionalFormats(e),a=i.findIndex(e=>e.id===t.id),o=[];a>-1&&(o=i[a].ranges.map(ws));let s=ms(o,r);return ms([...n,...s],[]).map(t=>this.getters.getRangeDataFromZone(e,t))}mapToConditionalFormat(e,t,{useBoundedReference:n}={useBoundedReference:!1}){let r=t.ranges.map(t=>this.getters.getRangeString(t,e,{useBoundedReference:n}));return t.rule.type===`DataBarRule`?{...t,rule:{...t.rule,rangeValues:t.rule.rangeValues&&this.getters.getRangeString(t.rule.rangeValues,e,{useBoundedReference:n})},ranges:r}:{...t,rule:{...t.rule},ranges:r}}mapToConditionalFormatInternal(e,t){let n=t.ranges.map(t=>this.getters.getRangeFromSheetXC(e,t));return t.rule.type===`DataBarRule`?{...t,rule:{...t.rule,rangeValues:t.rule.rangeValues?this.getters.getRangeFromSheetXC(e,t.rule.rangeValues):void 0},ranges:n}:{...t,rule:{...t.rule},ranges:n}}addConditionalFormatting(e,t){let n=this.cfRules[t].slice(),r=n.findIndex(t=>t.id===e.id),i=this.mapToConditionalFormatInternal(t,e);r>-1?n.splice(r,1,i):n.push(i),this.history.update(`cfRules`,t,n)}checkValidPriorityChange(e,t,n){if(!this.cfRules[n])return`InvalidSheetId`;let r=this.cfRules[n].findIndex(t=>t.id===e);if(r===-1)return`InvalidConditionalFormatId`;let i=r-t;return i<0||i>=this.cfRules[n].length?`InvalidConditionalFormatId`:`Success`}checkEmptyRange(e){return e.ranges.length?`Success`:`EmptyRange`}checkCFRule(e){let t=e.cf.rule;switch(t.type){case`CellIsRule`:return Mr.has(t.operator)?this.checkValidations(t,this.checkOperatorArgsNumber,this.checkCFValues):`InvalidConditionalFormatType`;case`ColorScaleRule`:return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case`IconSetRule`:return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)));case`DataBarRule`:return`Success`}return`InvalidConditionalFormatType`}checkCFHasChanged(e){let t=this.mapToConditionalFormatInternal(e.sheetId,{...e.cf,ranges:e.ranges.map(t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId))}),n=this.cfRules[e.sheetId]?.find(t=>t.id===e.cf.id);return n&&w(t,n)?`NoChanges`:`Success`}checkOperatorArgsNumber(e){let t=Y.get(e.operator).numberOfValues({type:e.operator,values:e.values});if(t===void 0||t>2)throw Error(`Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.`);let n=[],r=e=>e===void 0||e===``;return t>=1&&r(e.values[0])&&n.push(`FirstArgMissing`),t>=2&&r(e.values[1])&&n.push(`SecondArgMissing`),n.length?n:`Success`}checkNaN(e,t){if([`number`,`percentage`,`percentile`].includes(e.type)&&(e.value===``||isNaN(e.value)))switch(t){case`min`:return`MinNaN`;case`max`:return`MaxNaN`;case`mid`:return`MidNaN`;case`upperInflectionPoint`:return`ValueUpperInflectionNaN`;case`lowerInflectionPoint`:return`ValueLowerInflectionNaN`}return`Success`}checkFormulaCompilation(e,t){if(e.type!==`formula`)return`Success`;if(rC(e.value||``).isBadExpression)switch(t){case`min`:return`MinInvalidFormula`;case`max`:return`MaxInvalidFormula`;case`mid`:return`MidInvalidFormula`;case`upperInflectionPoint`:return`ValueUpperInvalidFormula`;case`lowerInflectionPoint`:return`ValueLowerInvalidFormula`}return`Success`}checkThresholds(e){return this.batchValidations(t=>e(t.minimum,`min`),t=>e(t.maximum,`max`),t=>t.midpoint?e(t.midpoint,`mid`):`Success`)}checkInflectionPoints(e){return this.batchValidations(t=>e(t.lowerInflectionPoint,`lowerInflectionPoint`),t=>e(t.upperInflectionPoint,`upperInflectionPoint`))}checkLowerBiggerThanUpper(e){let t=e.lowerInflectionPoint.value,n=e.upperInflectionPoint.value;return[`number`,`percentage`,`percentile`].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(n)?`LowerBiggerThanUpper`:`Success`}checkMinBiggerThanMax(e){let t=e.minimum.value,n=e.maximum.value;return[`number`,`percentage`,`percentile`].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&nW(t)>=nW(n)?`MinBiggerThanMax`:`Success`}checkMidBiggerThanMax(e){let t=e.midpoint?.value,n=e.maximum.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&nW(t)>=nW(n)?`MidBiggerThanMax`:`Success`}checkMinBiggerThanMid(e){let t=e.minimum.value,n=e.midpoint?.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&nW(t)>=nW(n)?`MinBiggerThanMid`:`Success`}checkCFValues(e){for(let t of e.values)if(t.startsWith(`=`)&&rC(t||``).isBadExpression)return`ValueCellIsInvalidFormula`;return`Success`}removeConditionalFormatting(e,t){let n=this.cfRules[t].findIndex(t=>t.id===e);if(n!==-1){let e=this.cfRules[t].slice();e.splice(n,1),this.history.update(`cfRules`,t,e)}}changeCFPriority(e,t,n){let r=this.cfRules[n].findIndex(t=>t.id===e),i=this.cfRules[n][r],a=r-t,o=[...this.cfRules[n]];o.splice(r,1),o.splice(a,0,i),this.history.update(`cfRules`,n,o)}},iW=class extends XU{static getters=[`cellHasListDataValidationIcon`,`getDataValidationRule`,`getDataValidationRules`,`getValidationRuleForCell`];rules={};adaptRanges(e,t){this.adaptDVRanges(t,e),this.adaptDVFormulas(e)}adaptDVFormulas({adaptFormulaString:e}){for(let t in this.rules){let n=this.rules[t];for(let r=n.length-1;r>=0;r--){let n=this.rules[t][r];for(let i=0;i<n.criterion.values.length;i++){let a=e(t,n.criterion.values[i]);this.history.update(`rules`,t,r,`criterion`,`values`,i,a)}}}}adaptDVRanges(e,{applyChange:t}){let n=this.rules[e];for(let r=n.length-1;r>=0;r--){let n=this.rules[e][r];for(let i=n.ranges.length-1;i>=0;i--){let a=n.ranges[i],o=t(a);switch(o.changeType){case`REMOVE`:if(n.ranges.length===1)this.removeDataValidationRule(e,n.id);else{let t=n.ranges.slice();t.splice(i,1),this.history.update(`rules`,e,r,`ranges`,t)}break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`rules`,e,r,`ranges`,i,o.range);break}}}}allowDispatch(e){switch(e.type){case`ADD_DATA_VALIDATION_RULE`:return!this.getters.tryGetSheet(e.sheetId)||e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkValidations(e,this.chainValidations(this.checkEmptyRange,this.checkValidRange,this.checkCriterionTypeIsValid,this.checkCriterionHasValidNumberOfValues,this.checkCriterionValuesAreValid));case`REMOVE_DATA_VALIDATION_RULE`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;if(!this.rules[e.sheetId].find(t=>t.id===e.id))return`UnknownDataValidationRule`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`rules`,e.sheetId,[]);break;case`DUPLICATE_SHEET`:{let t=b(this.rules[e.sheetId]).map(t=>({...t,ranges:t.ranges.map(t=>zc(e.sheetId,e.sheetIdTo,t))}));this.history.update(`rules`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.rules};delete t[e.sheetId],this.history.update(`rules`,t);break}case`REMOVE_DATA_VALIDATION_RULE`:this.removeDataValidationRule(e.sheetId,e.id);break;case`ADD_DATA_VALIDATION_RULE`:{let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e));this.addDataValidationRule(e.sheetId,{...e.rule,ranges:t});break}case`DELETE_CONTENT`:{let t=ms(e.target),n=e.sheetId;for(let e of t)for(let t=e.top;t<=e.bottom;t++)for(let r=e.left;r<=e.right;r++){let e=this.getValidationRuleForCell({sheetId:n,col:r,row:t});if(e&&(e.criterion.type===`isBoolean`||e.criterion.type===`isValueInList`&&!this.getters.getCell({sheetId:n,col:r,row:t})?.content)){let e=this.rules[n],i=[this.getters.getRangeFromSheetXC(n,T(r,t))],a=this.removeRangesFromRules(n,i,e);this.history.update(`rules`,n,a)}}}}}getDataValidationRules(e){return this.rules[e]}getDataValidationRule(e,t){return this.rules[e].find(e=>e.id===t)}getValidationRuleForCell({sheetId:e,col:t,row:n}){if(this.rules[e]){for(let r of this.rules[e])for(let e of r.ranges)if(Vs(t,n,e.zone))return r}}cellHasListDataValidationIcon(e){let t=this.getValidationRuleForCell(e);return t?(t.criterion.type===`isValueInList`||t.criterion.type===`isValueInRange`)&&(t.criterion.displayStyle===`arrow`||t.criterion.displayStyle===`chip`):!1}addDataValidationRule(e,t){let n=this.rules[e];t.criterion.type===`isBoolean`?this.setCenterStyleToBooleanCells(t):t.criterion.type===`isValueInList`&&(t.criterion.values=Array.from(new Set(t.criterion.values)));let r=this.removeRangesFromRules(e,t.ranges,n,t.id),i=r.findIndex(e=>e.id===t.id);i===-1?this.history.update(`rules`,e,[...r,t]):(r[i]=t,this.history.update(`rules`,e,r))}removeRangesFromRules(e,t,n,r){n=b(n);for(let e of n)e.id!==r&&(e.ranges=this.getters.recomputeRanges(e.ranges,t));return n.filter(e=>e.ranges.length>0)}removeDataValidationRule(e,t){let n=this.rules[e].filter(e=>e.id!==t);this.history.update(`rules`,e,n)}setCenterStyleToBooleanCells(e){for(let t of Vc(e.ranges)){let e=this.getters.getCell(t),n={...e?.style,align:e?.style?.align??`center`,verticalAlign:e?.style?.verticalAlign??`middle`};this.dispatch(`UPDATE_CELL`,{...t,style:n})}}checkEmptyRange(e){return e.ranges.length?`Success`:`EmptyRange`}import(e){for(let t of e.sheets)if(this.rules[t.id]=[],t.dataValidationRules)for(let e of t.dataValidationRules)this.rules[t.id].push({...e,ranges:e.ranges.map(e=>this.getters.getRangeFromSheetXC(t.id,e))})}export(e){if(e.sheets)for(let t of e.sheets){t.dataValidationRules=[];for(let e of this.rules[t.id])t.dataValidationRules.push({...e,ranges:e.ranges.map(e=>this.getters.getRangeString(e,t.id))})}}exportForExcel(e){if(e.sheets)for(let t of e.sheets){t.dataValidationRules=[];for(let e of this.rules[t.id]){let n={...b(e),ranges:e.ranges.map(e=>this.getters.getRangeString(e,t.id,{useBoundedReference:!0}))};e.criterion.type===`isValueInRange`&&(n.criterion.values=e.criterion.values.map(e=>{let n=this.getters.getRangeFromSheetXC(t.id,e);return this.getters.getRangeString(n,t.id,{useBoundedReference:!0,useFixedReference:!0})})),t.dataValidationRules.push(n)}}}checkCriterionTypeIsValid(e){return Y.contains(e.rule.criterion.type)?`Success`:`UnknownDataValidationCriterionType`}checkCriterionHasValidNumberOfValues(e){let t=e.rule.criterion,n=Y.get(t.type).numberOfValues(t);return n!==void 0&&t.values.length!==n?`InvalidNumberOfCriterionValues`:`Success`}checkCriterionValuesAreValid(e){let t=e.rule.criterion,n=Y.get(t.type);return t.values.some(e=>n.allowedValues===`onlyFormulas`&&!e.startsWith(`=`)?!0:e.startsWith(`=`)?n.allowedValues===`onlyLiterals`||rC(e).isBadExpression:!n.isCriterionValueValid(e))?`InvalidDataValidationCriterionValue`:`Success`}checkValidRange(e){return e.ranges.map(e=>this.getters.getRangeFromRangeData(e)).map(t=>this.getters.getRangeString(t,e.sheetId)).some(e=>!this.getters.isRangeValid(e))?`InvalidRange`:`Success`}},aW=class extends XU{static getters=[`getFigures`,`getFigure`,`getFigureSheetId`];figures={};insertionOrders=[];adaptRanges({applyChange:e},t){for(let n of this.getFigures(t)){let r=e(this.getters.getRangeFromZone(t,{left:n.col,right:n.col,top:n.row,bottom:n.row}));if(r.changeType===`MOVE`)this.history.update(`figures`,t,n.id,`col`,r.range.zone.right),this.history.update(`figures`,t,n.id,`row`,r.range.zone.bottom);else if(r.changeType===`REMOVE`){let r=e(this.getters.getRangeFromZone(t,{left:0,right:n.col-1,top:0,bottom:n.row-1})),{offset:i,col:a,row:o}=n;r.changeType!==`NONE`&&(a=r.range.zone.right+1,o=r.range.zone.bottom+1),{offset:i,col:a,row:o}=this.getPositionInSheet(t,{...n,col:a,row:o}),this.history.update(`figures`,t,n.id,`offset`,i),this.history.update(`figures`,t,n.id,`col`,a),this.history.update(`figures`,t,n.id,`row`,o)}}}allowDispatch(e){switch(e.type){case`CREATE_FIGURE`:return this.checkValidations(e,this.checkFigureDuplicate,this.checkFigureAnchorOffset);case`UPDATE_FIGURE`:return this.checkValidations(e,this.checkFigureExists,this.checkFigureAnchorOffset);case`DELETE_FIGURE`:return this.checkFigureExists(e);default:return`Success`}}beforeHandle(e){switch(e.type){case`DELETE_SHEET`:this.getters.getFigures(e.sheetId).forEach(t=>{this.dispatch(`DELETE_FIGURE`,{figureId:t.id,sheetId:e.sheetId})});break}}handle(e){switch(e.type){case`CREATE_SHEET`:this.figures[e.sheetId]={};break;case`DELETE_SHEET`:this.deleteSheet(e.sheetId);break;case`CREATE_FIGURE`:let t={id:e.figureId,col:e.col,row:e.row,offset:e.offset,width:e.size.width,height:e.size.height,tag:e.tag};this.addFigure(t,e.sheetId);break;case`UPDATE_FIGURE`:this.updateFigure(e);break;case`DELETE_FIGURE`:this.removeFigure(e.figureId,e.sheetId);break;case`REMOVE_COLUMNS_ROWS`:e.dimension===`COL`?this.onColRemove(e.sheetId):this.onRowRemove(e.sheetId);break;case`DUPLICATE_SHEET`:for(let t of this.getFigures(e.sheetId)){let n=t.id,r=this.figures[e.sheetId]?.[n];if(!r)continue;let i=n.split(`??`).pop(),a=`${e.sheetIdTo}??${i}`;this.dispatch(`CREATE_FIGURE`,{figureId:a,...r,size:{width:r.width,height:r.height},sheetId:e.sheetIdTo})}break}}onColRemove(e){let t=this.getters.getNumberCols(e),n=Array(t+1);n[t]=0;for(let r=t-1;r>=0;r--)n[r]=n[r+1]+this.getters.getColSize(e,r);for(let t of this.getFigures(e))if(t.offset.x+t.width>n[t.col]){let r=t.offset.x,i=t.col;for(r=Math.min(r,n[i]-t.width);r<0&&i>0;)i--,r=n[i]-t.width;r!==t.offset.x&&this.history.update(`figures`,e,t.id,`offset`,{x:Math.max(r,0),y:t.offset.y}),i!==t.col&&this.history.update(`figures`,e,t.id,`col`,i)}}onRowRemove(e){let t=this.getters.getNumberRows(e),n=Array(t+1);n[t]=0;for(let r=t-1;r>=0;r--)n[r]=n[r+1]+(this.getters.getUserRowSize(e,r)??23);for(let t of this.getFigures(e))if(t.offset.y+t.height>n[t.row]){let r=t.offset.y,i=t.row;for(let t=this.getters.getUserRowSize(e,i)??23;t<r;t=this.getters.getUserRowSize(e,i)??23)i+=1,r-=t;for(r=Math.min(r,n[i]-t.height);r<0&&i>0;)i--,r=n[i]-t.height;r!==t.offset.y&&this.history.update(`figures`,e,t.id,`offset`,{x:t.offset.x,y:Math.max(0,r)}),i!==t.row&&this.history.update(`figures`,e,t.id,`row`,i)}else t.offset.y+t.height>n[0]&&this.history.update(`figures`,e,t.id,`offset`,{x:t.offset.x,y:Math.max(n[0]-t.height,0)})}getPositionInSheet(e,t){let{numberOfRows:n,numberOfCols:r}=this.getters.getSheetSize(e),i=0,a=0,o,s,{col:c,row:l}=t,u={...t.offset};for(o=n;i<t.height&&o>0;o--)i+=this.getters.getUserRowSize(e,o-1)??23;for(l>o?(l=o,u.y=Math.max(i-t.height,0)):l===o&&(u.y=x(u.y,0,Math.max(i-t.height,0))),s=r;a<t.width&&s>0;s--)a+=this.getters.getColSize(e,s-1);return c>s?(c=s,u.x=Math.max(a-t.width,0)):s===c&&(u.x=x(u.x,0,Math.max(a-t.width,0))),{col:c,row:l,offset:u}}updateFigure(e){if(!(`figureId`in e)||!(`sheetId`in e))return;let{figureId:t,sheetId:n,...r}=e,i={...this.getFigure(n,t),...r};for(let[e,t]of Object.entries(r))switch(e){case`tag`:this.history.update(`figures`,n,i.id,e,t);break;case`offset`:this.history.update(`figures`,n,i.id,e,t);break;case`col`:case`row`:case`width`:case`height`:t!==void 0&&this.history.update(`figures`,n,i.id,e,t);break}}addFigure(e,t){this.history.update(`figures`,t,e.id,e),this.history.update(`insertionOrders`,this.insertionOrders.length,e.id)}deleteSheet(e){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>!this.figures[e]?.[t])),this.history.update(`figures`,e,void 0)}removeFigure(e,t){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>t!==e)),this.history.update(`figures`,t,e,void 0)}checkFigureExists(e){return this.figures[e.sheetId]?.[e.figureId]===void 0?`FigureDoesNotExist`:`Success`}checkFigureDuplicate(e){return Object.values(this.figures).find(t=>t?.[e.figureId])?`DuplicatedFigureId`:`Success`}checkFigureAnchorOffset(e){return e.col<0||e.row<0||e.offset&&(e.offset.x<0||e.offset.y<0)?`WrongSheetPosition`:`Success`}getFigures(e){let t=[];for(let n of this.insertionOrders){let r=this.figures[e]?.[n];r&&t.push(r)}return t}getFigure(e,t){return this.figures[e]?.[t]}getFigureSheetId(e){return Object.keys(this.figures).find(t=>this.figures[t]?.[e]!==void 0)}import(e){for(let t of e.sheets)for(let e of t.figures)this.addFigure(e,t.id)}export(e){for(let t of e.sheets)for(let e of this.getFigures(t.id))t.figures.push({...e,data:void 0})}exportForExcel(e){return this.export(e)}},oW=class extends XU{static getters=[`getUserRowSize`,`getColSize`];sizes={};handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`sizes`,e.sheetId,{COL:Array(this.getters.getNumberCols(e.sheetId)).fill(void 0),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(void 0)});break;case`DUPLICATE_SHEET`:this.history.update(`sizes`,e.sheetIdTo,b(this.sizes[e.sheetId]));break;case`DELETE_SHEET`:let t={...this.sizes};delete t[e.sheetId],this.history.update(`sizes`,t);break;case`REMOVE_COLUMNS_ROWS`:{let t=this.sizes[e.sheetId][e.dimension],n=qt(t,e.elements);this.history.update(`sizes`,e.sheetId,e.dimension,n);break}case`ADD_COLUMNS_ROWS`:{let t=this.sizes[e.sheetId][e.dimension],n=Ft(e.position,e.base),r=t[e.base],i=Jt(t,Array(e.quantity).fill(r),n);this.history.update(`sizes`,e.sheetId,e.dimension,i);break}case`RESIZE_COLUMNS_ROWS`:if(e.dimension===`ROW`)for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);else for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);break}}getColSize(e,t){return Math.round(this.sizes[e]?.COL[t]||96)}getUserRowSize(e,t){let n=this.sizes[e]?.ROW[t];return n?Math.round(n):void 0}import(e){for(let t of e.sheets){let e={COL:Array(t.colNumber).fill(void 0),ROW:Array(t.rowNumber).fill(void 0)};for(let[n,r]of Object.entries(t.rows))r.size&&(e.ROW[n]=r.size);for(let[n,r]of Object.entries(t.cols))r.size&&(e.COL[n]=r.size);this.sizes[t.id]=e}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e of S(0,this.getters.getNumberRows(n.id)))(t||this.sizes[n.id].ROW[e])&&(n.rows[e]={...n.rows[e],size:this.getUserRowSize(n.id,e)??23});n.cols===void 0&&(n.cols={});for(let e of S(0,this.getters.getNumberCols(n.id)))(t||this.sizes[n.id].COL[e])&&(n.cols[e]={...n.cols[e],size:this.getColSize(n.id,e)})}}},sW=class extends XU{static getters=[`checkElementsIncludeAllVisibleHeaders`,`getHiddenColsGroups`,`getHiddenRowsGroups`,`isHeaderHiddenByUser`,`isRowHiddenByUser`,`isColHiddenByUser`];hiddenHeaders={};allowDispatch(e){switch(e.type){case`HIDE_COLUMNS_ROWS`:{if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=e.dimension===`COL`?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),n=e.dimension===`COL`?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=n?`TooManyHiddenElements`:en(e.elements)<0||$t(e.elements)>n?`InvalidHeaderIndex`:`Success`}case`REMOVE_COLUMNS_ROWS`:return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`:`InvalidSheetId`}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:let t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update(`hiddenHeaders`,e.sheetId,t);break;case`DUPLICATE_SHEET`:this.history.update(`hiddenHeaders`,e.sheetIdTo,b(this.hiddenHeaders[e.sheetId]));break;case`DELETE_SHEET`:this.history.update(`hiddenHeaders`,e.sheetId,void 0);break;case`REMOVE_COLUMNS_ROWS`:{let t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let n of[...e.elements].sort((e,t)=>t-e))t.splice(n,1);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t);break}case`ADD_COLUMNS_ROWS`:{let t=Ft(e.position,e.base),n=Jt([...this.hiddenHeaders[e.sheetId][e.dimension]],Array(e.quantity).fill(!1),t);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,n);break}case`HIDE_COLUMNS_ROWS`:for(let t of e.elements)this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t,!0);break;case`UNHIDE_COLUMNS_ROWS`:for(let t of e.elements)this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t,!1);break}}checkElementsIncludeAllVisibleHeaders(e,t,n){return Rt(n,this.getAllVisibleHeaders(e,t))}isHeaderHiddenByUser(e,t,n){return t===`COL`?this.isColHiddenByUser(e,n):this.isRowHiddenByUser(e,n)}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]||this.getters.isRowFolded(e,t)}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]||this.getters.isColFolded(e,t)}getHiddenColsGroups(e){let t=[[]],n=this.hiddenHeaders[e].COL;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getHiddenRowsGroups(e){let t=[[]],n=this.hiddenHeaders[e].ROW;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getAllVisibleHeaders(e,t){let n=S(0,this.getters.getNumberHeaders(e,t)),r=[];return this.getters.getHeaderGroups(e,t).forEach(e=>{e.isFolded&&r.push(...S(e.start,e.end+1))}),n.filter(n=>!this.hiddenHeaders[e][t][n]&&!r.includes(n))}import(e){for(let t of e.sheets){this.hiddenHeaders[t.id]={COL:[],ROW:[]};for(let e=0;e<t.rowNumber;e++)this.hiddenHeaders[t.id].ROW[e]=!!t.rows[e]?.isHidden;for(let e=0;e<t.colNumber;e++)this.hiddenHeaders[t.id].COL[e]=!!t.cols[e]?.isHidden}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e=0;e<this.getters.getNumberRows(n.id);e++)(t||this.hiddenHeaders[n.id].ROW[e])&&(n.rows[e]===void 0&&(n.rows[e]={}),n.rows[e].isHidden||=this.hiddenHeaders[n.id].ROW[e]);n.cols===void 0&&(n.cols={});for(let e=0;e<this.getters.getNumberCols(n.id);e++)(t||this.hiddenHeaders[n.id].COL[e])&&(n.cols[e]===void 0&&(n.cols[e]={}),n.cols[e].isHidden||=this.hiddenHeaders[n.id].COL[e])}}},cW=class extends XU{static getters=[`getImage`,`getImagePath`,`getImageSize`];fileStore;images={};syncedImages=new Set;constructor(e){super(e),this.fileStore=e.external.fileStore}allowDispatch(e){switch(e.type){case`CREATE_IMAGE`:return this.getters.getFigure(e.sheetId,e.figureId)?`InvalidFigureId`:`Success`;default:return`Success`}}handle(e){switch(e.type){case`CREATE_IMAGE`:this.getters.getFigure(e.sheetId,e.figureId)||this.addFigure(e.figureId,e.sheetId,e.col,e.row,e.offset,e.size),this.history.update(`images`,e.sheetId,e.figureId,e.definition),this.syncedImages.add(e.definition.path);break;case`DUPLICATE_SHEET`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`image`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.getImage(n.id);if(i){let t={width:n.width,height:n.height};this.dispatch(`CREATE_IMAGE`,{sheetId:e.sheetIdTo,figureId:r,offset:n.offset,col:n.col,row:n.row,size:t,definition:b(i)})}}break}case`DELETE_FIGURE`:this.history.update(`images`,e.sheetId,e.figureId,void 0);break;case`DELETE_SHEET`:this.history.update(`images`,e.sheetId,void 0);break}}garbageCollectExternalResources(){let e=new Set(this.getAllImages().map(e=>e.path));for(let t of this.syncedImages)e.has(t)||this.fileStore?.delete(t)}getImage(e){for(let t of Object.values(this.images))if(t&&t[e])return t[e];throw Error(`There is no image with the given figureId: ${e}`)}getImagePath(e){return this.getImage(e).path}getImageSize(e){return this.getImage(e).size}addFigure(e,t,n,r,i,a){this.dispatch(`CREATE_FIGURE`,{sheetId:t,figureId:e,col:n,row:r,offset:i,size:a,tag:`image`})}import(e){for(let t of e.sheets){let e=(t.figures||[]).filter(e=>e.tag===`image`);for(let n of e)this.history.update(`images`,t.id,n.id,n.data),this.syncedImages.add(n.data.path)}}export(e){for(let t of e.sheets){let e=t.figures.filter(e=>e.tag===`image`);for(let n of e)n.data=this.images[t.id]?.[n.id]}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let t of e)if(t?.tag===`image`){let e=this.getImage(t.id);e&&n.push({...t,data:b(e)})}t.images=[...t.images,...n]}}getAllImages(){let e=[];for(let t in this.images)e.push(...Object.values(this.images[t]||{}).filter(C));return e}},lW=class extends XU{static getters=[`isInMerge`,`isInSameMerge`,`isMergeHidden`,`getMainCellPosition`,`expandZone`,`doesIntersectMerge`,`doesColumnsHaveCommonMerges`,`doesRowsHaveCommonMerges`,`getMerges`,`getMerge`,`getMergesInZone`,`isSingleCellOrMerge`,`getSelectionRangeString`,`isMainCellPosition`];nextId=1;merges={};mergeCellMap={};allowDispatch(e){let t=`force`in e?!!e.force:!1;switch(e.type){case`ADD_MERGE`:return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case`UPDATE_CELL`:return this.checkMergedContentUpdate(e);case`REMOVE_MERGE`:return this.checkMergeExists(e);default:return`Success`}}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DELETE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DUPLICATE_SHEET`:let t=this.merges[e.sheetId];if(!t)break;for(let n of Object.values(t).filter(C))this.addMerge(e.sheetIdTo,n.zone);break;case`ADD_MERGE`:for(let t of e.target)this.addMerge(e.sheetId,t);break;case`REMOVE_MERGE`:for(let t of e.target)this.removeMerge(e.sheetId,t);break}}adaptRanges(e,t){this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map(t=>this.getMergeById(e,parseInt(t,10))).filter(C)}getMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e],i=r?t in r&&r[t]?.[n]:void 0;return i?this.getMergeById(e,i):void 0}getMergesInZone(e,t){let n=this.mergeCellMap[e];if(!n)return[];let r=new Set;for(let e=t.left;e<=t.right;e++)for(let i=t.top;i<=t.bottom;i++){let t=n[e]?.[i];t&&r.add(t)}return Array.from(r).map(t=>this.getMergeById(e,t)).filter(C)}getSelectionRangeString(e,t){let n=this.getters.expandZone(e.sheetId,e.zone),r=Nc({...e,zone:{...n,bottom:Ic(e)?void 0:n.bottom,right:Lc(e)?void 0:n.right}},this.getters.getSheetSize),i=this.getters.getRangeString(r,t);if(this.isSingleCellOrMerge(e.sheetId,e.zone)){let{sheetName:e,xc:t}=jc(i);return Mc(e,t.split(`:`)[0])}return i}doesIntersectMerge(e,t){for(let n of this.getMerges(e))if(zs(t,n))return!0;return!1}doesColumnsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<this.getters.getNumberRows(e);i++)if(this.isInSameMerge(r.id,t,i,n,i))return!0;return!1}doesRowsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<=this.getters.getNumberCols(e);i++)if(this.isInSameMerge(r.id,i,t,i,n))return!0;return!1}expandZone(e,t){let{left:n,right:r,top:i,bottom:a}=t,o={left:n,right:r,top:i,bottom:a};for(let t in this.merges[e]){let n=this.getMergeById(e,parseInt(t));n&&zs(n,o)&&(o=Fs(n,o))}return Rs(o,t)?o:this.expandZone(e,o)}isInSameMerge(e,t,n,r,i){let a=this.getMerge({sheetId:e,col:t,row:n}),o=this.getMerge({sheetId:e,col:r,row:i});return!a||!o?!1:Rs(a,o)}isInMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e];return r?t in r&&!!r[t]?.[n]:!1}getMainCellPosition(e){let t=this.getMerge(e);return t?{sheetId:e.sheetId,col:t.left,row:t.top}:e}isMergeHidden(e,t){let n=this.getters.getHiddenColsGroups(e),r=this.getters.getHiddenRowsGroups(e);for(let e of n)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of r)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){let n=this.getMerge({sheetId:e,col:t.left,row:t.top});if(n)return Rs(t,n);let{numberOfCols:r,numberOfRows:i}=Us(t);return r===1&&i===1}isMainCellPosition(e){return w(this.getMainCellPosition(e),e)}isMergeDestructive(e,t){let{left:n,right:r,top:i,bottom:a}=t;r=x(r,0,this.getters.getNumberCols(e)-1),a=x(a,0,this.getters.getNumberRows(e)-1);for(let t=i;t<=a;t++)for(let a=n;a<=r;a++)if(a!==n||t!==i){let n=this.getters.getCell({sheetId:e,col:a,row:t});if(n&&n.content!==``)return!0}return!1}getMergeById(e,t){let n=this.merges[e]?.[t];return n===void 0?void 0:dW(t,n)}checkDestructiveMerge({sheetId:e,target:t}){return this.getters.tryGetSheet(e)&&t.some(t=>this.isMergeDestructive(e,t))?`MergeIsDestructive`:`Success`}checkOverlap({target:e}){for(let t of e)for(let n of e)if(t!==n&&zs(t,n))return`MergeOverlap`;return`Success`}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return`Success`;let{xSplit:n,ySplit:r}=this.getters.getPaneDivisions(e);return ic(t,n,r)?`FrozenPaneOverlap`:`Success`}checkMergedContentUpdate(e){let{col:t,row:n,content:r}=e;if(r===void 0)return`Success`;let{col:i,row:a}=this.getMainCellPosition(e);return i===t&&a===n?`Success`:`CellIsMerged`}checkMergeExists(e){let{sheetId:t,target:n}=e;for(let e of n){let{left:n,top:r}=e,i=this.getMerge({sheetId:t,col:n,row:r});if(i===void 0||!Rs(e,i))return`InvalidTarget`}return`Success`}addMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t;if(r=x(r,0,this.getters.getNumberCols(e)-1),a=x(a,0,this.getters.getNumberRows(e)-1),T(n,i)===T(r,a))return;let o=this.getters.getCell({sheetId:e,col:n,row:i}),s=this.nextId++;this.history.update(`merges`,e,s,this.getters.getRangeFromSheetXC(e,As({left:n,top:i,right:r,bottom:a})));let c=new Set;for(let t=i;t<=a;t++)for(let a=n;a<=r;a++){(a!==n||t!==i)&&this.dispatch(`UPDATE_CELL`,{sheetId:e,col:a,row:t,style:o?o.style:null,content:``});let r=this.getMerge({sheetId:e,col:a,row:t});r&&c.add(r.id),this.history.update(`mergeCellMap`,e,a,t,s)}for(let t of c){let{top:n,bottom:r,left:i,right:a}=this.getMergeById(e,t);for(let t=n;t<=r;t++)for(let n=i;n<=a;n++){let r={sheetId:e,col:n,row:t},i=this.getMerge(r);(!i||i.id!==s)&&(this.history.update(`mergeCellMap`,e,n,t,void 0),this.dispatch(`CLEAR_CELL`,r))}this.history.update(`merges`,e,t,void 0)}}removeMerge(e,t){let{left:n,top:r,bottom:i,right:a}=t,o=this.getMerge({sheetId:e,col:n,row:r});if(!(o===void 0||!Rs(t,o))){this.history.update(`merges`,e,o.id,void 0);for(let t=r;t<=i;t++)for(let r=n;r<=a;r++)this.history.update(`mergeCellMap`,e,r,t,void 0)}}applyRangeChangeOnSheet(e,{applyChange:t}){let n=Object.entries(this.merges[e]||{});for(let[r,i]of n)if(i){let n=i.zone,a=t(i);switch(a.changeType){case`NONE`:break;case`REMOVE`:this.removeMerge(e,n);break;default:let{numberOfCols:t,numberOfRows:i}=Us(a.range.zone);t===1&&i===1?this.removeMerge(e,n):this.history.update(`merges`,e,parseInt(r,10),a.range);break}}this.history.update(`mergeCellMap`,e,{});for(let t of this.getMerges(e))for(let{col:n,row:r}of Ks(t))this.history.update(`mergeCellMap`,e,n,r,t.id)}import(e){let t=e.sheets||[];for(let e of t)this.history.update(`merges`,e.id,{}),this.history.update(`mergeCellMap`,e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let n of t)this.addMerge(e,Ts(n))}export(e){for(let t of e.sheets){let e=this.merges[t.id];e&&t.merges.push(...uW(e))}}exportForExcel(e){this.export(e)}};function uW(e){return Object.entries(e).map(([e,t])=>t?dW(parseInt(e,10),t):void 0).filter(C).map(e=>T(e.left,e.top)+`:`+T(e.right,e.bottom))}function dW(e,t){return{...t.zone,id:e}}var fW=class{getters;providers=[];isAdaptingRanges=!1;constructor(e){this.getters=e}static getters=[`copyFormulaStringForSheet`,`extendRange`,`getRangeString`,`getRangeFromSheetXC`,`createAdaptedRanges`,`getRangeData`,`getRangeDataFromXc`,`getRangeDataFromZone`,`getRangeFromRangeData`,`getRangeFromZone`,`getRangesUnion`,`recomputeRanges`,`isRangeValid`,`removeRangesSheetPrefix`];allowDispatch(e){return e.type===`MOVE_RANGES`?e.target.length===1?`Success`:`InvalidZones`:`Success`}beforeHandle(e){}handle(e){if(this.isAdaptingRanges)throw Error(`Plugins cannot dispatch commands during adaptRanges phase`);let t=Gc(e);t&&this.executeOnAllRanges(t)}finalize(){}verifyRangeRemoved(e){return t=>{let n=e(t);return n.changeType!==`NONE`&&!Os(n.range.zone)?{range:n.range,changeType:`REMOVE`}:n}}executeOnAllRanges(e){this.isAdaptingRanges=!0;let t={applyChange:this.verifyRangeRemoved(e.applyChange),adaptRangeString:(t,n)=>hC(t,n,e),adaptFormulaString:(t,n)=>mC(t,n,e)};for(let n of this.providers)n(t,e.sheetId,e.sheetName);this.isAdaptingRanges=!1}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,n,r){return e.map(e=>{if(!Os(e.zone))return e;let i=e.prefixSheet?e.sheetId:r,a=Lc(e),o=Ic(e),s={...e.unboundedZone,left:a&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:a?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:o&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:n),bottom:o?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:n)};return Wc(Nc({...e,sheetId:i,zone:s},this.getters.getSheetSize))})}removeRangesSheetPrefix(e,t){return t.map(t=>t.prefixSheet&&t.sheetId===e?{...t,prefixSheet:!1}:t)}extendRange(e,t,n){let r=t===`COL`?e.zone.right+n:e.zone.right,i=t===`ROW`?e.zone.bottom+n:e.zone.bottom,a={left:e.zone.left,top:e.zone.top,right:Lc(e)?void 0:r,bottom:Ic(e)?void 0:i};return Nc({...e,zone:a},this.getters.getSheetSize)}getRangeFromSheetXC(e,t){if(!Tc.test(t)||!this.getters.tryGetSheet(e))return Fc(t);let{sheetName:n}=jc(t);return Pc({xc:t,sheetId:this.getters.getSheetIdByName(n)||e,invalidSheetName:n&&!this.getters.getSheetIdByName(n)?n:void 0},this.getters.getSheetSize)}getRangeString(e,t,n={useBoundedReference:!1,useFixedReference:!1}){return e?e.invalidXc?e.invalidXc:this.getters.tryGetSheet(e.sheetId)?Rc(e,t,this.getters.getSheetName,n):k.InvalidReference:k.InvalidReference}getRangeDataFromXc(e,t){let n=this.getters.getRangeFromSheetXC(e,t);return this.getRangeDataFromZone(n.sheetId,n.unboundedZone)}getRangeDataFromZone(e,t){return t=this.getters.getUnboundedZone(e,t),{_sheetId:e,_zone:t}}getRangeData(e){return this.getRangeDataFromZone(e.sheetId,e.unboundedZone)}getRangeFromZone(e,t){return Nc({sheetId:e,zone:t,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}],prefixSheet:!1},this.getters.getSheetSize)}recomputeRanges(e,t){return ms(e.map(e=>e.unboundedZone),t.map(e=>e.unboundedZone)).map(t=>this.getRangeFromZone(e[0].sheetId,t))}getRangeFromRangeData(e){return this.getters.tryGetSheet(e._sheetId)?Nc({prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]},this.getters.getSheetSize):Fc(k.InvalidReference)}isRangeValid(e){if(!e)return!1;let{xc:t,sheetName:n}=jc(e);return t.match(Tc)!==null&&(!n||this.getters.getSheetIdByName(n)!==void 0)}getRangesUnion(e){let t=Is(...e.map(e=>e.unboundedZone));return this.getRangeFromZone(e[0].sheetId,t)}copyFormulaStringForSheet(e,t,n,r){if(!n.startsWith(`=`))return n;let i=rC(n),a=i.dependencies.map(n=>{let i=this.getters.getRangeFromSheetXC(e,n);return r===`keepSameReference`?i:zc(e,t,i)});return this.getters.getFormulaString(t,i.tokens,a)}},pW=class extends XU{static getters=`getSheetName.tryGetSheetName.getSheet.tryGetSheet.getSheetIdByName.getSheetIds.getVisibleSheetIds.isSheetVisible.doesHeaderExist.doesHeadersExist.getCell.getCellPosition.getColsZone.getRowCells.getRowsZone.getNumberCols.getNumberRows.getNumberHeaders.getGridLinesVisibility.getNextSheetName.getSheetSize.getSheetZone.getPaneDivisions.checkZonesExistInSheet.getCommandZones.getUnboundedZone.checkElementsIncludeAllNonFrozenHeaders.getDuplicateSheetName`.split(`.`);sheetIdsMapName={};orderedSheetIds=[];sheets={};cellPosition={};allowDispatch(e){let t=this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e);if(t!==`Success`)return t;switch(e.type){case`HIDE_SHEET`:return this.getVisibleSheetIds().length===1?`NotEnoughSheets`:`Success`;case`CREATE_SHEET`:return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case`DUPLICATE_SHEET`:return this.sheets[e.sheetIdTo]?`DuplicatedSheetId`:this.orderedSheetIds.map(this.getSheetName.bind(this)).includes(e.sheetNameTo)?`DuplicatedSheetName`:`Success`;case`MOVE_SHEET`:try{let t=this.orderedSheetIds.findIndex(t=>t===e.sheetId);return this.findIndexOfTargetSheet(t,e.delta),`Success`}catch{return`WrongSheetMove`}case`RENAME_SHEET`:return this.isRenameAllowed(e);case`COLOR_SHEET`:return!e.color||mn(e.color)?`Success`:`InvalidColor`;case`DELETE_SHEET`:return this.getVisibleSheetIds().length>1?`Success`:`NotEnoughSheets`;case`ADD_COLUMNS_ROWS`:return this.doesHeaderExist(e.sheetId,e.dimension,e.base)?e.quantity<=0?`InvalidQuantity`:`Success`:`InvalidHeaderIndex`;case`REMOVE_COLUMNS_ROWS`:{let t=en(e.elements),n=$t(e.elements);return t<0||!this.doesHeaderExist(e.sheetId,e.dimension,n)?`InvalidHeaderIndex`:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`}case`FREEZE_ROWS`:return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case`FREEZE_COLUMNS`:return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return`Success`}}handle(e){switch(e.type){case`SET_GRID_LINES_VISIBILITY`:this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case`CREATE_SHEET`:let t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update(`sheetIdsMapName`,sl(t.name),t.id);break;case`MOVE_SHEET`:this.moveSheet(e.sheetId,e.delta);break;case`RENAME_SHEET`:this.renameSheet(this.sheets[e.sheetId],e.newName);break;case`COLOR_SHEET`:this.history.update(`sheets`,e.sheetId,`color`,e.color);break;case`HIDE_SHEET`:this.hideSheet(e.sheetId);break;case`SHOW_SHEET`:this.showSheet(e.sheetId);break;case`DUPLICATE_SHEET`:this.duplicateSheet(e.sheetId,e.sheetIdTo,e.sheetNameTo);break;case`DELETE_SHEET`:this.deleteSheet(this.sheets[e.sheetId]);break;case`REMOVE_COLUMNS_ROWS`:e.dimension===`COL`?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case`UPDATE_CELL_POSITION`:this.updateCellPosition(e);break;case`FREEZE_COLUMNS`:this.setPaneDivisions(e.sheetId,e.quantity,`COL`);break;case`FREEZE_ROWS`:this.setPaneDivisions(e.sheetId,e.quantity,`ROW`);break;case`UNFREEZE_ROWS`:this.setPaneDivisions(e.sheetId,0,`ROW`);break;case`UNFREEZE_COLUMNS`:this.setPaneDivisions(e.sheetId,0,`COL`);break;case`UNFREEZE_COLUMNS_ROWS`:this.setPaneDivisions(e.sheetId,0,`COL`),this.setPaneDivisions(e.sheetId,0,`ROW`)}}import(e){for(let t of e.sheets)this.sheetIdsMapName[sl(t.name)]=t.id;for(let t of e.sheets){let e=t.name||`Sheet`+(Object.keys(this.sheets).length+1),{colNumber:n,rowNumber:r}=this.getImportedSheetSize(t),i={id:t.id,name:e,numberOfCols:n,rows:nl(r),areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible,panes:{xSplit:t.panes?.xSplit||0,ySplit:t.panes?.ySplit||0},color:t.color};this.orderedSheetIds.push(i.id),this.sheets[i.id]=i}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(C).map(e=>{let t=this.sheets[e],n={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},styles:{},formats:{},borders:{},conditionalFormats:[],dataValidationRules:[],figures:[],tables:[],areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible,color:t.color};return(t.panes.xSplit||t.panes.ySplit)&&(n.panes=t.panes),n})}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){let t=this.sheets[e];if(!t)throw Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){return this.tryGetSheet(e)?.name}getSheetIdByName(e){if(e)return this.sheetIdsMapName[sl(e)]}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}doesHeaderExist(e,t,n){return t===`COL`?n>=0&&n<this.getNumberCols(e):n>=0&&n<this.getNumberRows(e)}doesHeadersExist(e,t,n){return n.every(n=>this.doesHeaderExist(e,t,n))}getCell({sheetId:e,col:t,row:n}){let r=this.tryGetSheet(e)?.rows[n]?.cells[t];if(r!==void 0)return this.getters.getCellById(r)}getColsZone(e,t,n){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:n}}getRowCells(e,t){return Object.values(this.getSheet(e).rows[t]?.cells).filter(C)}getRowsZone(e,t,n){return{top:t,bottom:n,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){let t=this.cellPosition[e];if(!t)throw Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return t===`COL`?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e=`Sheet`){return al(this.orderedSheetIds.map(this.getSheetName.bind(this)),e)}getSheetSize(e){return{numberOfRows:this.getNumberRows(e),numberOfCols:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getUnboundedZone(e,t){if(t.bottom===void 0||t.right===void 0)return t;let n=t.left===0&&t.right===this.getNumberCols(e)-1,r=t.top===0&&t.bottom===this.getNumberRows(e)-1;return{...t,bottom:r?void 0:t.bottom,right:n&&!r?void 0:t.right}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,n){let r={...this.getPaneDivisions(e)};n===`COL`?r.xSplit=t:n===`ROW`&&(r.ySplit=t),this.history.update(`sheets`,e,`panes`,r)}checkElementsIncludeAllNonFrozenHeaders(e,t,n){let r=this.getters.getPaneDivisions(e),i=t===`ROW`?r.ySplit:r.xSplit,a=this.getters.getNumberHeaders(e,t);return i?Rt(n,S(i,a)):!1}getCommandZones(e){let t=[];return`zone`in e&&t.push(e.zone),`target`in e&&t.push(...e.target),`ranges`in e&&t.push(...e.ranges.map(e=>this.getters.getRangeFromRangeData(e).zone)),`col`in e&&e.col!==void 0&&`row`in e&&e.row!==void 0&&t.push({top:e.row,left:e.col,bottom:e.row,right:e.col}),t}checkZonesExistInSheet(e,t){if(!t.every(Os))return`InvalidRange`;if(t.length){let n=this.getSheetZone(e);return t.every(e=>Hs(e,n))?`Success`:`TargetOutOfSheet`}return`Success`}updateCellPosition(e){let{sheetId:t,cellId:n,col:r,row:i}=e;n?this.setNewPosition(n,t,r,i):this.clearPosition(t,r,i)}setNewPosition(e,t,n,r){let i=this.cellPosition[e];i&&this.clearPosition(t,i.col,i.row),this.history.update(`cellPosition`,e,{row:r,col:n,sheetId:t}),this.history.update(`sheets`,t,`rows`,r,`cells`,n,e)}clearPosition(e,t,n){let r=this.sheets[e]?.rows[n].cells[t];r&&(this.history.update(`cellPosition`,r,void 0),this.history.update(`sheets`,e,`rows`,n,`cells`,t,void 0))}setGridLinesVisibility(e,t){this.history.update(`sheets`,e,`areGridLinesVisible`,t)}createSheet(e,t,n,r,i){let a={id:e,name:t,numberOfCols:n,rows:nl(r),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},o=this.orderedSheetIds.slice();o.splice(i,0,a.id);let s=this.sheets;return this.history.update(`orderedSheetIds`,o),this.history.update(`sheets`,Object.assign({},s,{[a.id]:a})),a}moveSheet(e,t){let n=this.orderedSheetIds.slice(),r=n.findIndex(t=>t===e),i=n.splice(r,1),a=this.findIndexOfTargetSheet(r,t);n.splice(a,0,i[0]),this.history.update(`orderedSheetIds`,n)}findIndexOfTargetSheet(e,t){for(;t!==0&&0<=e&&e<=this.orderedSheetIds.length;)t>0?(e++,this.isSheetVisible(this.orderedSheetIds[e])&&t--):t<0&&(e--,this.isSheetVisible(this.orderedSheetIds[e])&&t++);if(t===0)return e;throw Error(`There is not enough visible sheets`)}checkSheetName(e){let t=this.getters.tryGetSheetName(e.sheetId),n=e.type===`RENAME_SHEET`?e.newName:e.name;if(t!==void 0&&n===t)return`UnchangedSheetName`;let{orderedSheetIds:r,sheets:i}=this,a=n&&n.trim().toLowerCase();return r.find(t=>cl(i[t]?.name,a)&&t!==e.sheetId)?`DuplicatedSheetName`:Xe.test(a)?`ForbiddenCharactersInSheetName`:`Success`}checkSheetPosition(e){let{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?`WrongSheetPosition`:`Success`}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkRowFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.top<e.quantity&&e.quantity<=n.bottom)return`MergeOverlap`;return`Success`}checkColFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.left<e.quantity&&e.quantity<=n.right)return`MergeOverlap`;return`Success`}isRenameAllowed(e){return e.newName&&e.newName.trim().toLowerCase()?this.checkSheetName(e):`MissingSheetName`}renameSheet(e,t){let n=e.name;this.history.update(`sheets`,e.id,`name`,t.trim());let r=Object.assign({},this.sheetIdsMapName);delete r[sl(n)],r[sl(t)]=e.id,this.history.update(`sheetIdsMapName`,r)}hideSheet(e){this.history.update(`sheets`,e,`isVisible`,!1)}showSheet(e){this.history.update(`sheets`,e,`isVisible`,!0)}duplicateSheet(e,t,n){let r=b(this.getSheet(e));r.id=t,r.name=n;for(let e=0;e<=r.numberOfCols;e++)for(let t=0;t<=r.rows.length;t++)r.rows[t]&&(r.rows[t].cells[e]=void 0);let i=this.orderedSheetIds.slice(),a=i.indexOf(e);i.splice(a+1,0,r.id),this.history.update(`orderedSheetIds`,i),this.history.update(`sheets`,Object.assign({},this.sheets,{[r.id]:r}));for(let t of Object.values(this.getters.getCells(e))){let{col:e,row:n}=this.getCellPosition(t.id);this.dispatch(`UPDATE_CELL`,{sheetId:r.id,col:e,row:n,content:t.content,format:t.format,style:t.style})}let o=Object.assign({},this.sheetIdsMapName);o[sl(r.name)]=r.id,this.history.update(`sheetIdsMapName`,o)}getDuplicateSheetName(e){return ol(e,this.orderedSheetIds.map(this.getSheetName.bind(this)))}deleteSheet(e){let t=e.name,n=Object.assign({},this.sheets);delete n[e.id],this.history.update(`sheets`,n);let r=this.orderedSheetIds.slice(),i=r.indexOf(e.id);r.splice(i,1),this.history.update(`orderedSheetIds`,r);let a=Object.assign({},this.sheetIdsMapName);delete a[sl(t)],this.history.update(`sheetIdsMapName`,a)}removeColumns(e,t){t.sort((e,t)=>t-e);for(let n of t)this.moveCellOnColumnsDeletion(e,n);let n=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,n-t.length);let r=t.filter(t=>t<e.panes.xSplit).length;r&&this.setPaneDivisions(e.id,e.panes.xSplit-r,`COL`)}removeRows(e,t){t.sort((e,t)=>t-e);for(let n of gt(t)){let t=n[n.length-1],r=n[0];this.moveCellOnRowsDeletion(e,t,r),this.updateRowsStructureOnDeletion(e,t,r)}let n=t.filter(t=>t<e.panes.ySplit).length;n&&this.setPaneDivisions(e.id,e.panes.ySplit-n,`ROW`)}addColumns(e,t,n,r){let i=n===`before`?t:t+1;this.moveCellsOnAddition(e,i,r,`columns`);let a=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,a+r),i<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+r,`COL`)}addRows(e,t,n,r){let i=n===`before`?t:t+1;this.addEmptyRows(e,r),this.moveCellsOnAddition(e,i,r,`rows`),i<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+r,`ROW`)}moveCellOnColumnsDeletion(e,t){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:t,top:0,right:t,bottom:e.rows.length-1}]});for(let n=0;n<e.rows.length;n++){let r=e.rows[n];for(let i in r.cells){let a=Number(i),o=r.cells[i];o&&a>t&&this.setNewPosition(o,e.id,a-1,n)}}}moveCellsOnAddition(e,t,n,r){let i=[];for(let a=0;a<e.rows.length;a++){let o=e.rows[a];if(r!==`rows`||a>=t)for(let s in o.cells){let c=Number(s),l=o.cells[s];l&&(r===`rows`||c>=t)&&i.push({sheetId:e.id,cellId:l,col:c+(r===`columns`?n:0),row:a+(r===`rows`?n:0),type:`UPDATE_CELL_POSITION`})}}for(let e of i.reverse())this.updateCellPosition(e)}moveCellOnRowsDeletion(e,t,n){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:0,top:t,right:this.getters.getNumberCols(e.id),bottom:n}]});let r=n-t+1;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(t>n)for(let n in i.cells){let a=Number(n),o=i.cells[n];o&&this.setNewPosition(o,e.id,a,t-r)}}}updateRowsStructureOnDeletion(e,t,n){let r=[],i=e.rows.map(e=>e.cells).reverse();for(let a in e.rows){let e=Number(a);e>=t&&e<=n||r.push({cells:i.pop()})}this.history.update(`sheets`,e.id,`rows`,r)}addEmptyRows(e,t){let n=e.rows.slice();for(let e=0;e<t;e++)n.push({cells:{}});this.history.update(`sheets`,e.id,`rows`,n)}getImportedSheetSize(e){let t=Object.keys(e.cells).map(ir),n=e.rowNumber,r=e.colNumber;for(let{col:e,row:i}of t)n=Math.max(n,i+1),r=Math.max(r,e+1);return{rowNumber:n,colNumber:r}}checkSheetExists(e){return e.type!==`CREATE_SHEET`&&`sheetId`in e&&this.sheets[e.sheetId]===void 0?`InvalidSheetId`:e.type===`CREATE_SHEET`&&this.sheets[e.sheetId]!==void 0?`DuplicatedSheetId`:`Success`}checkZonesAreInSheet(e){return`sheetId`in e?`ranges`in e&&e.ranges.some(e=>e._sheetId!==``&&!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkZonesExistInSheet(e.sheetId,this.getCommandZones(e)):`Success`}},mW=class extends XU{static getters=[`getCoreTable`,`getCoreTables`,`getCoreTableMatchingTopLeft`];tables={};nextTableId=1;adaptRanges({applyChange:e},t){for(let n of this.getCoreTables(t))this.applyRangeChangeOnTable(t,n,e)}allowDispatch(e){switch(e.type){case`CREATE_TABLE`:if(e.ranges.some(t=>!this.getters.tryGetSheet(t._sheetId)||t._sheetId!==e.sheetId))return`InvalidSheetId`;let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e).zone);return oc(t)?this.checkValidations(e,e=>this.getTablesOverlappingZones(e.sheetId,t).length?`TableOverlap`:`Success`,e=>this.checkTableConfigUpdateIsValid(e.config)):`NonContinuousTargets`;case`UPDATE_TABLE`:return this.getCoreTableMatchingTopLeft(e.sheetId,e.zone)?this.checkValidations(e,this.checkUpdatedTableZoneIsValid,e=>this.checkTableConfigUpdateIsValid(e.config)):`TableNotFound`;case`ADD_MERGE`:for(let t of this.getCoreTables(e.sheetId)){let n=t.range.zone;for(let t of e.target)if(zs(n,t))return`MergeInTable`}break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`tables`,e.sheetId,{});break;case`DELETE_SHEET`:{let t={...this.tables};delete t[e.sheetId],this.history.update(`tables`,t);break}case`DUPLICATE_SHEET`:{let t={};for(let n of this.getCoreTables(e.sheetId))t[n.id]=n.type===`dynamic`?this.copyDynamicTableForSheet(e.sheetIdTo,n):this.copyStaticTableForSheet(e.sheetIdTo,n);this.history.update(`tables`,e.sheetIdTo,t);break}case`CREATE_TABLE`:{let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e)),n=this.getters.getRangesUnion(t),r=this.getters.getMergesInZone(e.sheetId,n.zone);r.length&&this.dispatch(`REMOVE_MERGE`,{sheetId:e.sheetId,target:r});let i=this.consumeNextId(),a=e.config||QA,o=e.tableType===`dynamic`?this.createDynamicTable(i,n,a):this.createStaticTable(i,e.tableType,n,a);this.history.update(`tables`,e.sheetId,o.id,o);break}case`REMOVE_TABLE`:{let t={};for(let n of this.getCoreTables(e.sheetId))e.target.every(e=>!Ls(n.range.zone,e))&&(t[n.id]=n);this.history.update(`tables`,e.sheetId,t);break}case`UPDATE_TABLE`:this.updateTable(e);break;case`UPDATE_CELL`:{let t=e.sheetId;for(let n of this.getCoreTables(t)){if(n.type===`dynamic`)continue;let r=this.canUpdateCellCmdExtendTable(e,n);r===`down`?this.extendTableDown(t,n):r===`right`&&this.extendTableRight(t,n)}break}case`DELETE_CONTENT`:{let t={...this.tables[e.sheetId]};for(let n in t){let r=t[n];r&&e.target.some(e=>Hs(r.range.zone,e))&&this.dispatch(`REMOVE_TABLE`,{sheetId:e.sheetId,target:[r.range.zone]})}break}}}getCoreTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(C):[]}getCoreTable({sheetId:e,col:t,row:n}){return this.getCoreTables(e).find(e=>Vs(t,n,e.range.zone))}getTablesOverlappingZones(e,t){return this.getCoreTables(e).filter(e=>t.some(t=>zs(e.range.zone,t)))}extendTableDown(e,t){let n=this.getters.extendRange(t.range,`ROW`,1);this.history.update(`tables`,e,t.id,this.updateStaticTable(t,n))}extendTableRight(e,t){let n=this.getters.extendRange(t.range,`COL`,1);this.history.update(`tables`,e,t.id,this.updateStaticTable(t,n))}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:n,row:r},i){if(!e)return`none`;let a=i.range.zone,o=`none`;if(a.bottom+1===r&&n>=a.left&&n<=a.right?o=`down`:a.right+1===n&&r>=a.top&&r<=a.bottom&&(o=`right`),o===`none`)return`none`;let s=o===`down`?{...a,bottom:a.bottom+1,top:a.bottom+1}:{...a,right:a.right+1,left:a.right+1};for(let e=s.top;e<=s.bottom;e++)for(let n=s.left;n<=s.right;n++){let r={sheetId:t,col:n,row:e};if(this.getters.getCell(r)?.content||this.getters.isInMerge(r)||this.getTablesOverlappingZones(t,[R(r)]).length)return`none`}return o}getCoreTableMatchingTopLeft(e,t){for(let n of this.getCoreTables(e)){let e=n.range.zone;if(e.left===t.left&&e.top===t.top)return n}}checkUpdatedTableZoneIsValid(e){if(!e.newTableRange)return`Success`;let t=this.getters.getRangeFromRangeData(e.newTableRange).zone,n=this.getters.checkZonesExistInSheet(e.sheetId,[t]);if(n!==`Success`)return n;let r=this.getCoreTableMatchingTopLeft(e.sheetId,e.zone);return r?this.getTablesOverlappingZones(e.sheetId,[t]).filter(e=>e.id!==r.id).length?`TableOverlap`:`Success`:`TableNotFound`}checkTableConfigUpdateIsValid(e){return e&&(e.numberOfHeaders!==void 0&&e.numberOfHeaders<0||e.hasFilters&&e.numberOfHeaders===0)?`InvalidTableConfig`:`Success`}createStaticTable(e,t,n,r,i){let a=n.zone;if(!i){i=[];for(let e of S(a.left,a.right+1)){let t={...a,left:e,right:e},o=this.consumeNextId();i.push(this.createFilterFromZone(o,n.sheetId,t,r))}}return{id:e,range:n,filters:i,config:r,type:t}}createDynamicTable(e,t,n){let r=$s(t.zone);return{id:e,range:this.getters.getRangeFromZone(t.sheetId,r),config:n,type:`dynamic`}}updateTable(e){let t=this.getCoreTableMatchingTopLeft(e.sheetId,e.zone);if(!t)return;let n=e.newTableRange?this.getters.getRangeFromRangeData(e.newTableRange):void 0;if(n){let t=this.getters.getMergesInZone(e.sheetId,n.zone);this.dispatch(`REMOVE_MERGE`,{sheetId:e.sheetId,target:t})}let r=n||t.range,i=this.updateTableConfig(e.config,t.config),a=e.tableType??t.type;if(a===`dynamic`&&t.type!==`dynamic`||a!==`dynamic`&&t.type===`dynamic`){let n=a===`dynamic`?this.createDynamicTable(t.id,r,i):this.createStaticTable(t.id,a,r,i);this.history.update(`tables`,e.sheetId,t.id,n)}else{let n=t.type===`dynamic`?this.updateDynamicTable(t,r,i):this.updateStaticTable(t,r,i,a);this.history.update(`tables`,e.sheetId,t.id,n)}}updateStaticTable(e,t,n,r=e.type){if(r===`dynamic`)throw Error(`Cannot use updateStaticTable to update a dynamic table`);let i=t||e.range,a=i.zone,o=this.updateTableConfig(n,e.config),s=o||e.config,c=[];if(t||o&&`numberOfHeaders`in o)for(let t of S(a.left,a.right+1)){let n=a.top===e.range.zone.top?e.filters.find(e=>e.col===t):void 0,r={...a,left:t,right:t},o=n?.id||this.consumeNextId();c.push(this.createFilterFromZone(o,i.sheetId,r,s))}return{...e,range:i,config:s,filters:c.length?c:e.filters,type:r}}updateDynamicTable(e,t,n){let r=t?this.getters.getRangeFromZone(t.sheetId,$s(t.zone)):e.range,i=n||e.config;return{...e,range:r,config:i}}updateTableConfig(e,t){if(!e)return t;let n={...t,...e};return e.numberOfHeaders===0?n.hasFilters=!1:e.hasFilters===!0&&(n.numberOfHeaders||=1),n}createFilterFromZone(e,t,n,r){return gI(e,this.getters.getRangeFromZone(t,n),r,this.getters.getRangeFromZone)}copyStaticTableForSheet(e,t){let n=this.getters.getRangeFromZone(e,t.range.zone),r=t.filters.map(n=>{let r=this.getters.getRangeFromZone(e,n.rangeWithHeaders.zone);return gI(n.id,r,t.config,this.getters.getRangeFromZone)});return{id:t.id,range:n,filters:r,config:b(t.config),type:t.type}}copyDynamicTableForSheet(e,t){let n=this.getters.getRangeFromZone(e,t.range.zone);return{id:t.id,range:n,config:b(t.config),type:`dynamic`}}applyRangeChangeOnTable(e,t,n){let r=n(t.range),i;switch(r.changeType){case`REMOVE`:this.history.update(`tables`,e,t.id,void 0);return;case`NONE`:return;default:i=r.range}if(t.type===`dynamic`){let n=this.updateDynamicTable(t,i);this.history.update(`tables`,e,t.id,n);return}let a=[];for(let e of t.filters){let r=n(e.rangeWithHeaders);switch(r.changeType){case`REMOVE`:continue;case`NONE`:a.push(e);break;default:let n=r.range,i=gI(e.id,n,t.config,this.getters.getRangeFromZone);a.push(i)}}let o=i.zone;if(a.length<Us(o).numberOfCols){for(let n=o.left;n<=o.right;n++)if(!a.find(e=>e.col===n)){let r=this.consumeNextId(),i={...o,left:n,right:n};a.push(this.createFilterFromZone(r,e,i,t.config))}a.sort((e,t)=>e.col-t.col)}let s=this.createStaticTable(t.id,t.type,i,t.config,a);this.history.update(`tables`,e,t.id,s)}consumeNextId(){let e=`${this.nextTableId}`;return this.history.update(`nextTableId`,this.nextTableId+1),e}import(e){for(let t of e.sheets)for(let e of t.tables||[]){let n=this.consumeNextId(),r=e.config||QA,i=this.getters.getRangeFromSheetXC(t.id,e.range),a=e.type||`static`,o=a===`dynamic`?this.createDynamicTable(n,i,r):this.createStaticTable(n,a,i,r);this.history.update(`tables`,t.id,o.id,o)}}export(e){for(let t of e.sheets)for(let e of this.getCoreTables(t.id)){let n={range:As(e.range.zone),type:e.type};w(e.config,QA)||(n.config=e.config),t.tables.push(n)}}exportForExcel(e){for(let t of e.sheets)for(let e of this.getCoreTables(t.id)){let n=As(e.range.zone);t.tables.push({range:n,filters:[],config:e.config})}}},hW=class extends XU{static getters=[`getCarousel`,`doesCarouselExist`];carousels={};allowDispatch(e){switch(e.type){case`CREATE_CAROUSEL`:return this.getters.getFigure(e.sheetId,e.figureId)?`DuplicatedFigureId`:`Success`;case`UPDATE_CAROUSEL`:return this.carousels[e.sheetId]?.[e.figureId]?`Success`:`InvalidFigureId`}return`Success`}handle(e){switch(e.type){case`CREATE_CAROUSEL`:this.getters.getFigure(e.sheetId,e.figureId)||this.dispatch(`CREATE_FIGURE`,{...e,tag:`carousel`}),this.history.update(`carousels`,e.sheetId,e.figureId,e.definition);break;case`UPDATE_CAROUSEL`:this.removeDeletedCharts(e,this.getters.getCarousel(e.figureId).items),this.history.update(`carousels`,e.sheetId,e.figureId,e.definition);break;case`DUPLICATE_SHEET`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`carousel`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.getCarousel(n.id);if(i){let t={width:n.width,height:n.height};this.dispatch(`CREATE_CAROUSEL`,{sheetId:e.sheetIdTo,figureId:r,offset:n.offset,col:n.col,row:n.row,size:t,definition:{items:i.items.map(t=>{if(t.type===`carouselDataView`)return{...t};let n=t.chartId.split(`??`).pop(),r=`${e.sheetIdTo}??${n}`;return{...t,chartId:r}})}})}}break}case`DELETE_FIGURE`:this.history.update(`carousels`,e.sheetId,e.figureId,void 0);break;case`DELETE_SHEET`:this.history.update(`carousels`,e.sheetId,void 0);break}}doesCarouselExist(e){for(let t in this.carousels)if(this.carousels[t]?.[e])return!0;return!1}getCarousel(e){for(let t in this.carousels)if(this.carousels[t]?.[e])return this.carousels[t][e];throw Error(`There is no carousel with the given figureId: ${e}`)}removeDeletedCharts(e,t){let n=new Set(e.definition.items.filter(e=>e.type===`chart`).map(e=>e.chartId));for(let r of t)r.type===`chart`&&!n.has(r.chartId)&&this.dispatch(`DELETE_CHART`,{chartId:r.chartId,sheetId:e.sheetId})}import(e){for(let t of e.sheets){let e=(t.figures||[]).filter(e=>e.tag===`carousel`);for(let n of e)this.history.update(`carousels`,t.id,n.id,{items:n.data.items,title:n.data.title})}}export(e){for(let t of e.sheets){let e=t.figures.filter(e=>e.tag===`carousel`);for(let n of e)this.carousels[t.id]?.[n.id]&&(n.data={...n.data,...this.carousels[t.id]?.[n.id]})}}},gW=class extends XU{static getters=[`getHeaderGroups`,`getGroupsLayers`,`getVisibleGroupLayers`,`getHeaderGroup`,`getHeaderGroupsInZone`,`isGroupFolded`,`isRowFolded`,`isColFolded`];groups={};allowDispatch(e){switch(e.type){case`GROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;if(this.findGroupWithStartEnd(e.sheetId,e.dimension,t,n))return`HeaderGroupAlreadyExists`;break}case`UNGROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;break}case`UNFOLD_HEADER_GROUP`:case`FOLD_HEADER_GROUP`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);if(!t)return`UnknownHeaderGroup`;if(S(0,this.getters.getNumberHeaders(e.sheetId,e.dimension)).every(n=>n>=t.start&&n<=t.end||this.getters.isHeaderHiddenByUser(e.sheetId,e.dimension,n)))return`NotEnoughElements`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`groups`,e.sheetId,{ROW:[],COL:[]});break;case`GROUP_HEADERS`:this.groupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`UNGROUP_HEADERS`:this.unGroupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`DUPLICATE_SHEET`:{let t=b(this.groups[e.sheetId]);this.history.update(`groups`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.groups};delete t[e.sheetId],this.history.update(`groups`,t);break}case`ADD_COLUMNS_ROWS`:let t=Ft(e.position,e.base);this.moveGroupsOnHeaderInsertion(e.sheetId,e.dimension,t,e.quantity);break;case`REMOVE_COLUMNS_ROWS`:this.moveGroupsOnHeaderDeletion(e.sheetId,e.dimension,e.elements);break;case`UNFOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.unfoldHeaderGroup(e.sheetId,e.dimension,t);break}case`FOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.foldHeaderGroup(e.sheetId,e.dimension,t);break}case`UNFOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.unfoldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.foldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_HEADER_GROUPS_IN_ZONE`:{let t=e.type===`UNFOLD_HEADER_GROUPS_IN_ZONE`?`unfold`:`fold`,n=this.getGroupsLayers(e.sheetId,e.dimension);t===`fold`&&n.reverse();let r=n.flat(),i=e.dimension===`ROW`?e.zone.top:e.zone.left,a=e.dimension===`ROW`?e.zone.bottom:e.zone.right,o=new Set;for(let e=i;e<=a;e++){let n=r.filter(t=>t.start-1<=e&&e<=t.end);for(let e of n)if(!(t===`fold`&&e.isFolded||t===`unfold`&&!e.isFolded)){o.add(e);break}}for(let n of o)t===`unfold`?this.unfoldHeaderGroup(e.sheetId,e.dimension,n):this.foldHeaderGroup(e.sheetId,e.dimension,n);break}}}getHeaderGroups(e,t){return this.groups[e][t]}getHeaderGroup(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}getHeaderGroupsInZone(e,t,n){return this.getHeaderGroups(e,t).filter(e=>{let r=t===`ROW`?n.top:n.left,i=t===`ROW`?n.bottom:n.right;return this.doGroupOverlap(e,r,i)})}getGroupsLayers(e,t){let n=this.getHeaderGroups(e,t);return this.bricksFallingAlgorithm(n,0,0)}getVisibleGroupLayers(e,t){let n=this.getGroupsLayers(e,t);for(let r of n)for(let n=r.length-1;n>=0;n--){let i=r[n];i.start!==0&&S(i.start-1,i.end+1).every(n=>this.getters.isHeaderHiddenByUser(e,t,n))&&r.splice(n,1)}return n.filter(e=>e.length>0)}isGroupFolded(e,t,n,r){return this.getHeaderGroup(e,t,n,r)?.isFolded||!1}isRowFolded(e,t){return this.getters.getHeaderGroups(e,`ROW`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}isColFolded(e,t){return this.getters.getHeaderGroups(e,`COL`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}getGroupId(e){return`${e.start}-${e.end}}`}bricksFallingAlgorithm(e,t,n,r=0){let i={};for(let t of e)i[this.getGroupId(t)]=t.isFolded;let a={};for(let t of e)for(let e=t.start;e<=t.end;e++)a[e]=a[e]?a[e]+1:1;for(let e=t;e<=n;e++)a[e]=a[e]?a[e]+r:r;let o=Math.max(...Object.values(a),0),s=Array.from({length:o},()=>[]),c=Math.max(n,...e.map(e=>e.end)),l=Math.min(t,...e.map(e=>e.start));for(let e=l;e<=c;e++){let t=a[e]||0;for(let n=0;n<t;n++){let t=s[n].at(-1);if(t&&Gt([t.end,e]))t.end++;else{let t={start:e,end:e};s[n].push(t)}}}for(let e of s)for(let t of e)t.isFolded=i[this.getGroupId(t)];return s}groupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}unGroupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,-1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}moveGroupsOnHeaderInsertion(e,t,n,r){let i=this.groups[e][t];for(let a=0;a<i.length;a++){let o=i[a],[s,c]=rl(n,r,[o.start,o.end]);(s!==o.start||c!==o.end)&&this.history.update(`groups`,e,t,a,{...o,start:s,end:c})}}moveGroupsOnHeaderDeletion(e,t,n){let r=this.getHeaderGroups(e,t),i=[];for(let e of r){let t=il(n,S(e.start,e.end+1));t.length!==0&&i.push({...e,start:Math.min(...t),end:Math.max(...t)})}this.history.update(`groups`,e,t,this.bricksFallingAlgorithm(i,0,0).flat())}doGroupOverlap(e,t,n){return e.start<=n&&e.end>=t}removeDuplicateGroups(e){let t={};for(let n of e)t[this.getGroupId(n)]=n;return Object.values(t)}findGroupWithStartEnd(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}foldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!0);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end<=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!0)}}unfoldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!1);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end>=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!1)}}getGroupIndex(e,t,n,r){let i=this.groups[e][t].findIndex(e=>e.start===n&&e.end===r);return i===-1?void 0:i}import(e){for(let t of e.sheets)if(this.groups[t.id]={ROW:[],COL:[]},t.headerGroups)for(let e of[`ROW`,`COL`])for(let n of t.headerGroups[e]||[])this.groups[t.id][e].push({...n})}export(e){for(let t of e.sheets)t.headerGroups=this.groups[t.id]}exportForExcel(e){for(let t of e.sheets)for(let e of[`ROW`,`COL`]){let n=this.getGroupsLayers(t.id,e);for(let r=0;r<n.length;r++){let i=n[r];for(let n of i){for(let i=n.start;i<=n.end;i++){let a=Uj(t,e,i);a.outlineLevel=r+1,n.isFolded&&(a.isHidden=!0)}if(n.isFolded){let r=Uj(t,e,n.end+1);r.collapsed=!0}}}}}},_W=class extends XU{static getters=[`getPivotCoreDefinition`,`getPivotDisplayName`,`getPivotId`,`getPivotFormulaId`,`getPivotIds`,`getMeasureCompiledFormula`,`getPivotName`,`isExistingPivot`,`getMeasureFullDependencies`];nextFormulaId=1;pivots={};formulaIds={};compiledMeasureFormulas={};allowDispatch(e){switch(e.type){case`ADD_PIVOT`:return this.checkValidations(e.pivot,this.checkDuplicatedMeasureIds,this.checkSortedColumnInMeasures,this.checkCustomFieldsAreValid);case`UPDATE_PIVOT`:return e.pivotId in this.pivots?w(e.pivot,this.pivots[e.pivotId]?.definition)?`NoChanges`:e.pivot.name===``?`EmptyName`:this.checkValidations(e.pivot,this.checkDuplicatedMeasureIds,this.checkSortedColumnInMeasures,this.checkCustomFieldsAreValid):`PivotIdNotFound`;case`RENAME_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`;if(e.name===``)return`EmptyName`;break;case`REMOVE_PIVOT`:case`DUPLICATE_PIVOT`:case`INSERT_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`;break;case`DUPLICATE_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`}return`Success`}handle(e){switch(e.type){case`ADD_PIVOT`:{let{pivotId:t,pivot:n}=e;this.addPivot(t,n);break}case`INSERT_PIVOT`:{let{sheetId:t,col:n,row:r,pivotId:i,table:a}=e,o={sheetId:t,col:n,row:r},{cols:s,rows:c,measures:l,fieldsType:u}=a,d=new nR(s,c,l,u||{}),f=this.getPivotFormulaId(i);this.insertPivot(o,f,d);break}case`RENAME_PIVOT`:this.history.update(`pivots`,e.pivotId,`definition`,`name`,e.name);break;case`REMOVE_PIVOT`:{let t={...this.pivots};delete t[e.pivotId];let n=this.getPivotFormulaId(e.pivotId);this.history.update(`formulaIds`,n,void 0),this.history.update(`pivots`,t);break}case`DUPLICATE_PIVOT`:{let{pivotId:t,newPivotId:n}=e,r=b(this.getPivotCore(t).definition);r.name=e.duplicatedPivotName??r.name+` (copy)`,this.addPivot(n,r);break}case`UPDATE_PIVOT`:this.history.update(`pivots`,e.pivotId,`definition`,b(e.pivot)),this.compileCalculatedMeasures(e.pivotId,e.pivot.measures);break}}adaptRanges({applyChange:e,adaptFormulaString:t}){for(let t in this.pivots){let n=b(this.pivots[t]?.definition);if(!n)continue;let r=vR.get(n.type)?.adaptRanges?.(this.getters,n,e);r&&!w(n,r)&&this.history.update(`pivots`,t,`definition`,r)}for(let n in this.compiledMeasureFormulas)for(let r in this.compiledMeasureFormulas[n]){let i=this.pivots[n]?.definition.measures.find(e=>e.id===r);if(!i||!i.computedBy)continue;let a=i.computedBy.sheetId,{formula:o,dependencies:s}=this.compiledMeasureFormulas[n][r];this.history.update(`compiledMeasureFormulas`,n,r,`formula`,`dependencies`,o.dependencies.map(t=>e(t).range)),this.history.update(`compiledMeasureFormulas`,n,i.id,`dependencies`,s.map(t=>e(t).range));let c=i.computedBy.formula,l=t(a,c);l!==c&&this.replaceMeasureFormula(n,i,l)}}getPivotDisplayName(e){return`(#${this.getPivotFormulaId(e)}) ${this.getPivotName(e)}`}getPivotName(e){return this.getPivotCore(e).definition.name}getPivotCoreDefinition(e){return this.getPivotCore(e).definition}getPivotId(e){return this.formulaIds[e]}getPivotFormulaId(e){return this.getPivotCore(e).formulaId}getPivotIds(){return Object.keys(this.pivots)}isExistingPivot(e){return e in this.pivots}getMeasureCompiledFormula(e,t){if(!t.computedBy)throw Error(`Measure ${t.fieldName} is not computed by formula`);return this.compiledMeasureFormulas[e][t.id].formula}getMeasureFullDependencies(e,t){if(!t.computedBy)throw Error(`Measure ${t.fieldName} is not computed by formula`);return this.compiledMeasureFormulas[e][t.id].dependencies}addPivot(e,t,n=this.nextFormulaId.toString()){this.history.update(`pivots`,e,{definition:b(t),formulaId:n}),this.compileCalculatedMeasures(e,t.measures),this.history.update(`formulaIds`,n,e),this.history.update(`nextFormulaId`,this.nextFormulaId+1)}compileCalculatedMeasures(e,t){for(let n of t)if(n.computedBy){let t=this.compileMeasureFormula(n.computedBy.sheetId,n.computedBy.formula);this.history.update(`compiledMeasureFormulas`,e,n.id,`formula`,t)}for(let n of t)if(n.computedBy){let t=this.computeMeasureFullDependencies(e,n);this.history.update(`compiledMeasureFormulas`,e,n.id,`dependencies`,t)}}computeMeasureFullDependencies(e,t,n=new Set){let r=[],i=this.getPivotCoreDefinition(e),a=this.getMeasureCompiledFormula(e,t);n.add(t.id);for(let o of a.tokens){if(o.type!==`SYMBOL`)continue;let a=i.measures.find(e=>mt(e.id)===o.value&&t.id!==e.id);!a||n.has(a.id)||!a.computedBy||r.push(...this.computeMeasureFullDependencies(e,a,n))}return r.push(...a.dependencies.filter(e=>!e.invalidXc)),r}insertPivot(e,t,n){this.resizeSheet(e.sheetId,e,n);let r=n.getPivotCells();for(let n=0;n<r.length;n++)for(let i=0;i<r[n].length;i++){let a=r[n][i];this.dispatch(`UPDATE_CELL`,{sheetId:e.sheetId,col:e.col+n,row:e.row+i,content:Md(t,a)})}}resizeSheet(e,{col:t,row:n},r){let i=r.getNumberOfDataColumns()+1,a=this.getters.getNumberCols(e),o=a-t;o<i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:a-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:i-o,position:`after`});let s=r.columns.length+r.rows.length,c=this.getters.getNumberRows(e),l=c-n;l<s&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:c-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:s-l,position:`after`})}getPivotCore(e){let t=this.pivots[e];if(!t)throw Error(`Pivot with id ${e} not found`);return t}compileMeasureFormula(e,t){let n=rC(t),r=n.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t));return{...n,dependencies:r}}replaceMeasureFormula(e,t,n){let r=this.pivots[e];if(!r)return;let i=r.definition.measures.indexOf(t);this.history.update(`pivots`,e,`definition`,`measures`,i,`computedBy`,{formula:n,sheetId:t.computedBy.sheetId})}checkSortedColumnInMeasures(e){let t=e.measures.map(e=>e.id);return e.sortedColumn&&!t.includes(e.sortedColumn.measure)?`InvalidDefinition`:`Success`}checkDuplicatedMeasureIds(e){let t=new Set(e.measures.map(e=>e.id));return e.measures.length===t.size?`Success`:`InvalidDefinition`}checkCustomFieldsAreValid(e){for(let t in e.customFields){let n=e.customFields[t],r=new Set,i=new Set,a=!1;for(let e of n.groups){if(!e.name||i.has(e.name)||e.values.some(e=>r.has(e))||e.isOtherGroup&&a)return`InvalidPivotCustomField`;e.values.forEach(e=>r.add(e)),i.add(e.name),a||=!!e.isOtherGroup}}return`Success`}import(e){if(e.pivots)for(let[t,n]of Object.entries(e.pivots))this.addPivot(t,n,n.formulaId);this.history.update(`nextFormulaId`,e.pivotNextId||Td(this.pivots)+1)}export(e){e.pivots={};for(let t in this.pivots)e.pivots[t]={...this.getPivotCoreDefinition(t),formulaId:this.getPivotFormulaId(t)};e.pivotNextId=this.nextFormulaId}},vW=class extends XU{static getters=[`getLocale`];locale=D;allowDispatch(e){switch(e.type){case`UPDATE_LOCALE`:return uu(e.locale)?`Success`:`InvalidLocale`}return`Success`}handle(e){switch(e.type){case`UPDATE_LOCALE`:let t=this.locale,n=e.locale;this.history.update(`locale`,n),this.changeCellsDateFormatWithLocale(t,n);break}}getLocale(){return this.locale}changeCellsDateFormatWithLocale(e,t){for(let n of this.getters.getSheetIds())for(let[r,i]of Object.entries(this.getters.getCells(n))){let n;if(i.format===e.dateFormat&&(n=t.dateFormat),i.format===e.timeFormat&&(n=t.timeFormat),i.format===Du(e)&&(n=Du(t)),n){let{col:e,row:t,sheetId:i}=this.getters.getCellPosition(r);this.dispatch(`UPDATE_CELL`,{col:e,row:t,sheetId:i,format:n})}}}import(e){this.locale=e.settings?.locale??D}export(e){e.settings={locale:this.locale}}},yW=class extends XU{allowDispatch(e){switch(e.type){case`ADD_PIVOT`:case`UPDATE_PIVOT`:let t=e.pivot;return this.checkDataSetValidity(t)}return`Success`}checkDataSetValidity(e){if(e.type===`SPREADSHEET`&&e.dataSet){let{zone:t,sheetId:n}=e.dataSet;return!n||!this.getters.tryGetSheet(n)||!t||!Os(t)?`InvalidDataSet`:this.getters.checkZonesExistInSheet(n,[t])}return`Success`}},bW=class extends XU{static getters=[`getNewCustomTableStyleName`,`getTableStyle`,`getTableStyles`,`isTableStyleEditable`];styles={};allowDispatch(e){switch(e.type){case`CREATE_TABLE`:case`UPDATE_TABLE`:if(e.config?.styleId&&!this.styles[e.config.styleId])return`InvalidTableConfig`;break;case`CREATE_TABLE_STYLE`:if(!pj[e.templateName])return`InvalidTableStyle`;try{pn(e.primaryColor)}catch{return`InvalidTableStyle`}break}return`Success`}handle(e){switch(e.type){case`CREATE_TABLE_STYLE`:let t=mj(e.tableStyleName,e.templateName,e.primaryColor);this.history.update(`styles`,e.tableStyleId,t);break;case`REMOVE_TABLE_STYLE`:let n={...this.styles};delete n[e.tableStyleId],this.history.update(`styles`,n);for(let t of this.getters.getSheetIds())for(let n of this.getters.getCoreTables(t))n.config.styleId===e.tableStyleId&&this.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{styleId:QA.styleId}});break}}getTableStyle(e){if(!this.styles[e])throw Error(`Table style ${e} does not exist`);return this.styles[e]}getTableStyles(){return this.styles}getNewCustomTableStyleName(){return an(E(`Custom Table Style`),Object.values(this.styles).map(e=>e.displayName),{compute:(e,t)=>`${e} ${t}`,start:2})}isTableStyleEditable(e){return!fj[e]}import(e){for(let e in fj)this.styles[e]=fj[e];for(let t in e.customTableStyles){let n=e.customTableStyles[t];this.styles[t]=mj(n.displayName,n.templateName,n.primaryColor)}}export(e){let t={};for(let e in this.styles)fj[e]||(t[e]={displayName:this.styles[e].displayName,templateName:this.styles[e].templateName,primaryColor:this.styles[e].primaryColor});e.customTableStyles=t}},xW=class extends Lp{getters;constructor({getters:e,stateObserver:t}){super(t),this.getters=e}};let SW=new g;SW.add(`pivots`,e=>{for(let t of e.getPivotIds())e.getPivot(t).markAsDirtyForEvaluation?.()});let CW=zS.mapping;function wW(e,t,n){return new TW(e,t,n).getParameters()}var TW=class{getters;computeCell;evalContext;rangeCache={};constructor(e,t,n){this.getters=t,this.computeCell=n,this.evalContext=Object.assign(Object.create(CW),e,{getters:this.getters,locale:this.getters.getLocale()})}getParameters(){return{referenceDenormalizer:this.refFn.bind(this),ensureRange:this.range.bind(this),evalContext:this.evalContext}}refFn(e,t){let n=this.getRangeError(e);if(n)return n;let r={sheetId:e.sheetId,col:e.zone.left,row:e.zone.top};return t?(this.computeCell(r),{value:Mc(this.getters.getSheetName(e.sheetId),As(e.zone))}):this.computeCell(r)}range(e,t){let n=this.getRangeError(e);if(n)return[[n]];let r=e.sheetId,i=e.zone,a=Ls(i,this.getters.getSheetZone(r));if(!a)return[[]];let{top:o,left:s,bottom:c,right:l}=i,u=`${r}-${o}-${s}-${c}-${l}-${t}`;if(u in this.rangeCache)return this.rangeCache[u];let d=a.bottom-a.top+1,f=a.right-a.left+1,p=Array(f),m=this.getters.getSheetName(e.sheetId);for(let e=a.left;e<=a.right;e++){let n=e-a.left;p[n]=Array(d);for(let i=a.top;i<=a.bottom;i++){let o=i-a.top,s=this.computeCell({sheetId:r,col:e,row:i});p[n][o]=t?{value:Mc(m,T(e,i))}:s}}return this.rangeCache[u]=p,p}getRangeError(e){if(!Os(e.zone))return new Yi;if(e.invalidSheetName)return new Yi(E(`Invalid sheet name: %s`,e.invalidSheetName))}},EW=d(c(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self).RBush=r()})(e,function(){"use strict";function e(e,r,i,a,o){(function e(n,r,i,a,o){for(;a>i;){if(a-i>600){var s=a-i+1,c=r-i+1,l=Math.log(s),u=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*u*(s-u)/s)*(c-s/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-c*u/s+d)),Math.min(a,Math.floor(r+(s-c)*u/s+d)),o)}var f=n[r],p=i,m=a;for(t(n,i,r),o(n[a],f)>0&&t(n,i,a);p<m;){for(t(n,p,m),p++,m--;o(n[p],f)<0;)p++;for(;o(n[m],f)>0;)m--}o(n[i],f)===0?t(n,i,m):t(n,++m,a),m<=r&&(i=m+1),r<=m&&(a=m-1)}})(e,r,i||0,a||e.length-1,o||n)}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return e<t?-1:+(e>t)}var r=function(e){e===void 0&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function i(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function a(e,t){o(e,0,e.children.length,t,e)}function o(e,t,n,r,i){i||=m(null),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var a=t;a<n;a++){var o=e.children[a];s(i,e.leaf?r(o):o)}return i}function s(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function c(e,t){return e.minX-t.minX}function l(e,t){return e.minY-t.minY}function u(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function d(e){return e.maxX-e.minX+(e.maxY-e.minY)}function f(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function p(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function m(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function h(t,n,r,i,a){for(var o=[n,r];o.length;)if(!((r=o.pop())-(n=o.pop())<=i)){var s=n+Math.ceil((r-n)/i/2)*i;e(t,s,n,r,a),o.push(n,s,s,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(e){var t=this.data,n=[];if(!p(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var a=0;a<t.children.length;a++){var o=t.children[a],s=t.leaf?r(o):o;p(e,s)&&(t.leaf?n.push(o):f(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n},r.prototype.collides=function(e){var t=this.data;if(!p(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],a=t.leaf?this.toBBox(i):i;if(p(e,a)){if(t.leaf||f(e,a))return!0;n.push(i)}}t=n.pop()}return!1},r.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},r.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(e,t){if(!e)return this;for(var n,r,a,o=this.data,s=this.toBBox(e),c=[],l=[];o||c.length;){if(o||(o=c.pop(),r=c[c.length-1],n=l.pop(),a=!0),o.leaf){var u=i(e,o.children,t);if(u!==-1)return o.children.splice(u,1),c.push(o),this._condense(c),this}a||o.leaf||!f(o,s)?r?(n++,o=r.children[n],a=!1):o=null:(c.push(o),l.push(n),n=0,r=o,o=o.children[0])}return this},r.prototype.toBBox=function(e){return e},r.prototype.compareMinX=function(e,t){return e.minX-t.minX},r.prototype.compareMinY=function(e,t){return e.minY-t.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(e){return this.data=e,this},r.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},r.prototype._build=function(e,t,n,r){var i,o=n-t+1,s=this._maxEntries;if(o<=s)return a(i=m(e.slice(t,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/s**(r-1))),(i=m([])).leaf=!1,i.height=r;var c=Math.ceil(o/s),l=c*Math.ceil(Math.sqrt(s));h(e,t,n,l,this.compareMinX);for(var u=t;u<=n;u+=l){var d=Math.min(u+l-1,n);h(e,u,d,c,this.compareMinY);for(var f=u;f<=d;f+=c){var p=Math.min(f+c-1,d);i.children.push(this._build(e,f,p,r-1))}}return a(i,this.toBBox),i},r.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,a=1/0,o=void 0,s=0;s<t.children.length;s++){var c=t.children[s],l=u(c),d=(f=e,p=c,(Math.max(p.maxX,f.maxX)-Math.min(p.minX,f.minX))*(Math.max(p.maxY,f.maxY)-Math.min(p.minY,f.minY))-l);d<a?(a=d,i=l<i?l:i,o=c):d===a&&l<i&&(i=l,o=c)}t=o||t.children[0]}var f,p;return t},r.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),s(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},r.prototype._split=function(e,t){var n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var o=this._chooseSplitIndex(n,i,r),s=m(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,a(n,this.toBBox),a(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)},r.prototype._splitRoot=function(e,t){this.data=m([e,t]),this.data.height=e.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(e,t,n){for(var r,i,a,s,c,l,d,f=1/0,p=1/0,m=t;m<=n-t;m++){var h=o(e,0,m,this.toBBox),g=o(e,m,n,this.toBBox),_=(i=h,a=g,s=void 0,c=void 0,l=void 0,d=void 0,s=Math.max(i.minX,a.minX),c=Math.max(i.minY,a.minY),l=Math.min(i.maxX,a.maxX),d=Math.min(i.maxY,a.maxY),Math.max(0,l-s)*Math.max(0,d-c)),v=u(h)+u(g);_<f?(f=_,r=m,p=v<p?v:p):_===f&&v<p&&(p=v,r=m)}return r||n-t},r.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:c,i=e.leaf?this.compareMinY:l;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},r.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var i=this.toBBox,a=o(e,0,t,i),c=o(e,n-t,n,i),l=d(a)+d(c),u=t;u<n-t;u++){var f=e.children[u];s(a,e.leaf?i(f):f),l+=d(a)}for(var p=n-t-1;p>=t;p--){var m=e.children[p];s(c,e.leaf?i(m):m),l+=d(c)}return l},r.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)s(t[r],e)},r.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():a(e[t],this.toBBox)},r})}))(),1),DW=class{rTrees={};constructor(e=[]){let t={};for(let n of e){let e=n.boundingBox.sheetId;t[e]||(t[e]=[]),t[e].push(n)}for(let e in t)this.rTrees[e]=new OW,this.rTrees[e].load(t[e])}insert(e){let t=e.boundingBox.sheetId;this.rTrees[t]||(this.rTrees[t]=new OW),this.rTrees[t].insert(e)}search({zone:e,sheetId:t}){return this.rTrees[t]?this.rTrees[t].search({minX:e.left,minY:e.top,maxX:e.right,maxY:e.bottom}):[]}remove(e){let t=e.boundingBox.sheetId;this.rTrees[t]&&this.rTrees[t].remove(e,this.rtreeItemComparer)}rtreeItemComparer(e,t){return e.boundingBox.sheetId===t.boundingBox.sheetId&&e.boundingBox?.zone.left===t.boundingBox.zone.left&&e.boundingBox?.zone.top===t.boundingBox.zone.top&&e.boundingBox?.zone.right===t.boundingBox.zone.right&&e.boundingBox?.zone.bottom===t.boundingBox.zone.bottom&&w(e.data,t.data)}},OW=class extends EW.default{toBBox({boundingBox:e}){let t=e.zone;return{minX:t.left,minY:t.top,maxX:t.right,maxY:t.bottom}}compareMinX(e,t){return e.boundingBox.zone.left-t.boundingBox.zone.left}compareMinY(e,t){return e.boundingBox.zone.top-t.boundingBox.zone.top}},kW=class e{profilesStartingPosition=[0];profiles=new Map([[0,[]]]);constructor(e=[]){for(let t of e)this.add(t)}isEmpty(){return this.profiles.size===1&&this.profiles.get(0)?.length===0}add(e){hs(this.profilesStartingPosition,this.profiles,[e])}delete(e){hs(this.profilesStartingPosition,this.profiles,[e],!0)}has(e){return gs(this.profilesStartingPosition,this.profiles,e)}difference(e){let t=this.copy();for(let n of e)t.delete(n);return t}copy(){let t=new e;t.profilesStartingPosition=[...this.profilesStartingPosition],t.profiles=new Map;for(let[e,n]of this.profiles)t.profiles.set(e,[...n]);return t}[Symbol.iterator](){return bs(this.profilesStartingPosition,this.profiles)[Symbol.iterator]()}},AW=class e{setsBySheetId={};constructor(e=[]){for(let t of e)this.add(t)}add(e){this.setsBySheetId[e.sheetId]||(this.setsBySheetId[e.sheetId]=new kW),this.setsBySheetId[e.sheetId].add(e.zone)}addMany(e){for(let t of e)this.add(t)}addPosition(e){this.add(Uc(e))}addManyPositions(e){for(let t of e)this.addPosition(t)}has(e){return this.setsBySheetId[e.sheetId]?this.setsBySheetId[e.sheetId].has(e.zone):!1}hasPosition(e){return this.has(Uc(e))}delete(e){this.setsBySheetId[e.sheetId]&&this.setsBySheetId[e.sheetId].delete(e.zone)}deleteMany(e){for(let t of e)this.delete(t)}deleteManyPositions(e){for(let t of e)this.delete(Uc(t))}difference(t){let n=new e;for(let e in this.setsBySheetId)n.setsBySheetId[e]=this.setsBySheetId[e];for(let e in t.setsBySheetId)n.setsBySheetId[e]&&(n.setsBySheetId[e]=n.setsBySheetId[e].difference(t.setsBySheetId[e]));return n}copy(){let t=new e;for(let e in this.setsBySheetId)t.setsBySheetId[e]=this.setsBySheetId[e].copy();return t}clear(){this.setsBySheetId={}}isEmpty(){for(let e in this.setsBySheetId)if(!this.setsBySheetId[e].isEmpty())return!1;return!0}[Symbol.iterator](){let e=[];for(let t in this.setsBySheetId)for(let n of this.setsBySheetId[t])e.push({sheetId:t,zone:n});return e[Symbol.iterator]()}},jW=class{rTree;constructor(e=[]){let t=MW(e);this.rTree=new DW(t)}insert(e){let t=this.rTree.search(e.boundingBox),n=e.boundingBox,r=t.find(({boundingBox:e})=>e.sheetId===n.sheetId&&e.zone.left===n.zone.left&&e.zone.top===n.zone.top&&e.zone.right===n.zone.right&&e.zone.bottom===n.zone.bottom);r?r.data.add(e.data):this.rTree.insert({...e,data:new AW([e.data])})}search({zone:e,sheetId:t}){let n=new AW;for(let{data:r}of this.rTree.search({zone:e,sheetId:t}))n.addMany(r);return n}remove(e){let t=this.rTree.search(e.boundingBox),n=e.boundingBox,r=t.find(({boundingBox:e})=>e.sheetId===n.sheetId&&e.zone.left===n.zone.left&&e.zone.top===n.zone.top&&e.zone.right===n.zone.right&&e.zone.bottom===n.zone.bottom);r?r.data.delete(e.data):this.rTree.remove({...e,data:new AW([e.data])})}};function MW(e){let t=0,n=0;for(let r=0;r<e.length;r++){let i=e[r].boundingBox.zone;i.right>t&&(t=i.right),i.bottom>n&&(n=i.bottom)}t+=1,n+=1;let r=(((n+1)*t+1)*n+1)*t<=2**53-1;r||console.warn(`Max col/row size exceeded, using slow zone key`);let i={};for(let a of e){let e=a.boundingBox.sheetId;i[e]||(i[e]={});let o=a.boundingBox.zone,s=0;s=r?o.left+o.top*t+o.right*t*n+o.bottom*t*n*t:`${o.left},${o.top},${o.right},${o.bottom}`,i[e][s]?i[e][s].data.add(a.data):i[e][s]={boundingBox:a.boundingBox,data:new AW([a.data])}}let a=[];for(let e in i){let t=i[e];for(let e in t)a.push(t[e])}return a}var NW=class{dependencies=new LF;rTree;constructor(e=[]){this.rTree=new jW(e)}removeAllDependencies(e){let t=this.dependencies.get(e);if(t){for(let e of t)this.rTree.remove(e);this.dependencies.delete(e)}}addDependencies(e,t){let n=t.map(({sheetId:t,zone:n})=>({data:{sheetId:e.sheetId,zone:R(e)},boundingBox:{zone:n,sheetId:t}}));for(let e of n)this.rTree.insert(e);let r=this.dependencies.get(e);r?r.push(...n):this.dependencies.set(e,n)}getCellsDependingOn(e,t=new AW){t=t.copy();let n=Array.from(e).reverse();for(;n.length>0;){let e=n.pop();t.add(e);let r=this.rTree.search(e);n.push(...r.difference(t))}for(let n of e)t.delete(n);return t}},PW=class extends Uint32Array{columnOffset=0;cols=0;rows=0;static create(e,t){let n=FW(t),r=e<<n>>5,i=new this(r+1);return i.columnOffset=n,i.cols=t,i.rows=e,i}getValue(e){let[t,n]=this.getCoordinates(e);return this[t]>>n&1}setValue(e,t){let[n,r]=this.getCoordinates(e),i=(this[n]>>r&1)==0&&t===1;return this[n]=this[n]&~(1<<r)|t<<r,i}isEmpty(){return!this.some(e=>e!==0)}fillAllPositions(){this.fill(-1>>>0)}clear(){this.fill(0)}getCoordinates(e){let{row:t,col:n}=e,r=(t<<this.columnOffset)+n,i=r>>5;return[i,r-(i<<5)]}};function FW(e){return e===0?-1/0:e<0?NaN:32-Math.clz32(--e)}var IW=class{sheets={};insertions=[];maxSize=0;constructor(e){for(let t in e){let n=e[t].cols,r=e[t].rows;this.maxSize+=n*r,this.sheets[t]=PW.create(r,n)}}add(e){this.sheets[e.sheetId].setValue(e,1)&&this.insertions.push(e)}addMany(e){for(let t of e)this.add(t)}delete(e){this.sheets[e.sheetId].setValue(e,0)}deleteMany(e){for(let t of e)this.delete(t)}has(e){return this.sheets[e.sheetId].getValue(e)===1}clear(){let e=[...this];this.insertions=[];for(let e in this.sheets)this.sheets[e].clear();return e}isEmpty(){if(this.insertions.length===0)return!0;for(let e in this.sheets)if(!this.sheets[e].isEmpty())return!1;return!0}fillAllPositions(){this.insertions=Array(this.maxSize);let e=0;for(let t in this.sheets){let n=this.sheets[t];n.fillAllPositions();for(let r=0;r<n.rows;r++)for(let i=0;i<n.cols;i++)this.insertions[e++]={sheetId:t,row:r,col:i}}}*[Symbol.iterator](){for(let e of this.insertions)this.sheets[e.sheetId].getValue(e)===1&&(yield e)}},LW=class{resultsToArrayFormulas=new DW;arrayFormulasToResults=new LF;searchFormulaPositionsSpreadingOn(e,t){return this.resultsToArrayFormulas.search({sheetId:e,zone:t}).map(e=>e.data)||RW}getArrayResultZone(e){return this.arrayFormulasToResults.get(e)}removeNode(e){let t=this.arrayFormulasToResults.get(e);t&&(this.resultsToArrayFormulas.remove({boundingBox:{sheetId:e.sheetId,zone:t},data:e}),this.arrayFormulasToResults.delete(e))}addRelation({arrayFormulaPosition:e,resultZone:t}){this.resultsToArrayFormulas.insert({boundingBox:{sheetId:e.sheetId,zone:t},data:e}),this.arrayFormulasToResults.set(e,t)}isArrayFormula(e){return this.arrayFormulasToResults.has(e)}};let RW=[],zW=Object.freeze(ns({...new Ji,origin:void 0})),BW=Object.freeze(ns({value:null}));var VW=class{context;getters;compilationParams;evaluatedCells=new LF;formulaDependencies=Nt(new NW);blockedArrayFormulas=new IW({});spreadingRelations=new LW;constructor(e,t){this.context=e,this.getters=t,this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this))}getEvaluatedCell(e){return this.evaluatedCells.get(e)||BW}getSpreadZone(e,t={ignoreSpillError:!1}){let n=this.spreadingRelations.getArrayResultZone(e);if(!n)return;let r=this.evaluatedCells.get(e);return r?.type===`error`&&!(t.ignoreSpillError&&r?.value===k.SpilledBlocked)?R(e):Fs(R(e),n)}getEvaluatedPositions(){return this.evaluatedCells.keys()}getEvaluatedPositionsInSheet(e){return this.evaluatedCells.keysForSheet(e)}getArrayFormulaSpreadingOn(e){if(this.getEvaluatedCell(e).type!==`empty`)return this.spreadingRelations.searchFormulaPositionsSpreadingOn(e.sheetId,R(e)).find(e=>!this.blockedArrayFormulas.has(e))}isArrayFormulaSpillBlocked(e){return this.blockedArrayFormulas.has(e)}updateDependencies(e){this.formulaDependencies().removeAllDependencies(e);let t=this.getDirectDependencies(e);this.formulaDependencies().addDependencies(e,t)}addDependencies(e,t){this.formulaDependencies().addDependencies(e,t);for(let e of t)this.compilationParams.ensureRange(e,!1)}updateCompilationParametersForIsolatedFormula(e){this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this)),this.compilationParams.evalContext.__originCellPosition=e,this.compilationParams.evalContext.updateDependencies=void 0,this.compilationParams.evalContext.addDependencies=void 0,this.compilationParams.evalContext.lookupCaches=this.compilationParams.evalContext.lookupCaches||{forwardSearch:new Map,reverseSearch:new Map}}updateCompilationParameters(){this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this)),this.compilationParams.evalContext.updateDependencies=this.updateDependencies.bind(this),this.compilationParams.evalContext.addDependencies=this.addDependencies.bind(this),this.compilationParams.evalContext.lookupCaches={forwardSearch:new Map,reverseSearch:new Map}}createEmptyPositionSet(){let e={};for(let t of this.getters.getSheetIds())e[t]={rows:this.getters.getNumberRows(t),cols:this.getters.getNumberCols(t)};return new IW(e)}evaluateCells(e){let t=performance.now(),n=new AW;n.addManyPositions(e);let r=this.getArrayFormulasImpactedByChangesOf(e);n.addMany(this.getCellsDependingOn(n)),n.addMany(r),n.addMany(this.getCellsDependingOn(r)),this.evaluate(n),console.debug(`evaluate Cells`,performance.now()-t,`ms`)}getArrayFormulasImpactedByChangesOf(e){let t=new AW;for(let n of e){let e=this.getters.getCell(n)?.content,r=this.getArrayFormulaSpreadingOn(n);r!==void 0&&t.addPosition(r),e||t.addPosition(n)}for(let e of[...t])t.addMany(this.getArrayFormulasBlockedBy(e.sheetId,e.zone));return t}buildDependencyGraph(){this.blockedArrayFormulas=this.createEmptyPositionSet(),this.spreadingRelations=new LW,this.formulaDependencies=Nt(()=>{let e=[];for(let t of this.getters.getSheetIds()){let n=this.getters.getCells(t);for(let r in n){let i=n[r];if(i.isFormula){let n=i.compiledFormula.dependencies;for(let i of n)i.invalidSheetName||i.invalidXc||e.push({data:{sheetId:t,zone:R(this.getters.getCellPosition(r))},boundingBox:{sheetId:i.sheetId,zone:i.zone}})}}}return new NW(e)})}evaluateAllCells(){let e=performance.now();this.evaluatedCells=new LF;let t=[];for(let e of this.getters.getSheetIds()){let n=this.getters.getSheetZone(e);t.push({sheetId:e,zone:n})}this.evaluate(t),console.debug(`evaluate all cells`,performance.now()-e,`ms`)}evaluateFormulaResult(e,t,n){let r=rC(t),i=r.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t));return this.updateCompilationParametersForIsolatedFormula(n),this.evaluateCompiledFormula(e,{...r,dependencies:i})}evaluateCompiledFormula(e,t,n){try{let r=WW(t,this.compilationParams,e,this.buildSafeGetSymbolValue(n),this.compilationParams.evalContext.__originCellPosition);return Ir(r)?Ca(r,UW):UW(r)}catch(e){return VS(e,``)}}getArrayFormulasBlockedBy(e,t){let n=new AW,r=this.spreadingRelations.searchFormulaPositionsSpreadingOn(e,t);n.addManyPositions(r);let i=[...r].filter(e=>!this.blockedArrayFormulas.has(e));return i.length&&n.deleteManyPositions(i),n.addMany(this.getCellsDependingOn(n)),n}nextRangesToUpdate=new AW;cellsBeingComputed=new Set;symbolsBeingComputed=new Set;evaluate(e){this.cellsBeingComputed=new Set,this.nextRangesToUpdate=new AW(e);let t=0;for(;!this.nextRangesToUpdate.isEmpty()&&t++<30;){this.updateCompilationParameters();let e=[...this.nextRangesToUpdate];this.nextRangesToUpdate.clear(),this.clearEvaluatedRanges(e);for(let t of e){let{left:e,bottom:n,right:r,top:i}=t.zone;for(let a=e;a<=r;a++)for(let e=i;e<=n;e++){let n={sheetId:t.sheetId,col:a,row:e};if(this.nextRangesToUpdate.hasPosition(n))continue;let r=this.computeCell(n);r!==BW&&this.evaluatedCells.set(n,r)}}SW.getAll().forEach(e=>e(this.getters))}t>=30&&console.warn(`Maximum iteration reached while evaluating cells`)}clearEvaluatedRanges(e){for(let t of e){let{left:e,bottom:n,right:r,top:i}=t.zone;for(let a=e;a<=r;a++)for(let e=i;e<=n;e++)this.evaluatedCells.delete({sheetId:t.sheetId,col:a,row:e})}}computeCell(e){let t=this.evaluatedCells.get(e);if(t)return t;this.blockedArrayFormulas.has(e)||this.invalidateSpreading(e),this.spreadingRelations.isArrayFormula(e)&&this.spreadingRelations.removeNode(e);let n=this.getters.getCell(e);if(n===void 0)return BW;let r=n.id,i={format:n.format,locale:this.getters.getLocale()};try{return this.cellsBeingComputed.has(r)?zW:(this.cellsBeingComputed.add(r),n.isFormula?this.computeFormulaCell(e,n):es(n,i,e))}catch(t){return t.value=t?.value||k.GenericError,t.message=t?.message||WS,t.origin=e,t.errorOriginPosition=t?.errorOriginPosition,ns(t)}finally{this.cellsBeingComputed.delete(r)}}computeAndSave(e){let t=this.computeCell(e);return this.evaluatedCells.has(e)||this.evaluatedCells.set(e,t),t}computeFormulaCell(e,t){let n=WW(t.compiledFormula,this.compilationParams,e.sheetId,this.buildSafeGetSymbolValue(),e);if(!Ir(n)){let r=ns(UW(n),this.getters.getLocale(),t,e);return r.type===`error`&&(r.errorOriginPosition=n.errorOriginPosition??e),r}this.assertSheetHasEnoughSpaceToSpreadFormulaResult(e,n);let r=n.length,i=n[0].length;if(i===0)return ns({value:0},this.getters.getLocale(),t);if(i===1&&r===1)return ns(UW(n[0][0]),this.getters.getLocale(),t);let a={top:e.row,bottom:e.row+i-1,left:e.col,right:e.col+r-1};return this.spreadingRelations.addRelation({resultZone:a,arrayFormulaPosition:e}),this.assertNoMergedCellsInSpreadZone(e,n),HW(r,i,this.checkCollision(e)),HW(r,i,this.spreadValues(e,n)),this.invalidatePositionsDependingOnSpread(e.sheetId,a),ns(UW(n[0][0]),this.getters.getLocale(),t)}invalidatePositionsDependingOnSpread(e,t){let n=this.getCellsDependingOn(Gs(t).map(t=>({sheetId:e,zone:t})));n.delete({sheetId:e,zone:t}),this.nextRangesToUpdate.addMany(n)}assertSheetHasEnoughSpaceToSpreadFormulaResult({sheetId:e,col:t,row:n},r){let i=this.getters.getNumberCols(e),a=this.getters.getNumberRows(e),o=t+r.length<=i,s=n+r[0].length<=a;if(!(o&&s))throw o?new Qi(E(`Result couldn't be automatically expanded. Please insert more rows.`)):s?new Qi(E(`Result couldn't be automatically expanded. Please insert more columns.`)):new Qi(E(`Result couldn't be automatically expanded. Please insert more columns and rows.`))}assertNoMergedCellsInSpreadZone({sheetId:e,col:t,row:n},r){if(this.getters.getMergesInZone(e,{top:n,bottom:n+r[0].length-1,left:t,right:t+r.length-1}).length!==0)throw new Qi(E(`Merged cells found in the spill zone. Please unmerge cells before using array formulas.`))}checkCollision(e){let{sheetId:t,col:n,row:r}=e;return(i,a)=>{let o={sheetId:t,col:i+n,row:a+r};if(this.getters.getCell(o)?.content||this.getters.getEvaluatedCell(o).type!==`empty`)throw this.blockedArrayFormulas.add(e),new Qi(E(`Array result was not expanded because it would overwrite data.`),o);this.blockedArrayFormulas.delete(e)}}spreadValues({sheetId:e,col:t,row:n},r){return(i,a)=>{let o={sheetId:e,col:i+t,row:a+n},s=this.getters.getCell(o),c=ns(UW(r[i][a]),this.getters.getLocale(),s,o);c.type===`error`&&(c.errorOriginPosition=r[i][a].errorOriginPosition??o),this.evaluatedCells.set(o,c)}}invalidateSpreading(e){let t=this.spreadingRelations.getArrayResultZone(e);if(!t)return;for(let n=t.left;n<=t.right;n++)for(let r=t.top;r<=t.bottom;r++){let t={sheetId:e.sheetId,col:n,row:r};this.getters.getCell(t)?.content||this.evaluatedCells.delete(t)}let n=e.sheetId;this.invalidatePositionsDependingOnSpread(n,t),this.nextRangesToUpdate.addMany(this.getArrayFormulasBlockedBy(n,t))}buildSafeGetSymbolValue(e){return t=>{if(this.symbolsBeingComputed.has(t))return zW;this.symbolsBeingComputed.add(t);try{return e?.(t)||new qi(E(`Invalid formula`))}finally{this.symbolsBeingComputed.delete(t)}}}getDirectDependencies(e){let t=this.getters.getCell(e);return t?.isFormula?t.compiledFormula.dependencies:[]}getCellsDependingOn(e){return this.formulaDependencies().getCellsDependingOn(e,this.nextRangesToUpdate)}};function HW(e,t,n){for(let r=0;r<e;++r)for(let e=0;e<t;++e)r===0&&e===0||n(r,e)}function UW(e){return e.value===null||e.value===void 0?{...e,value:0}:e}function WW(e,t,n,r,i){let a=t.evalContext,o=a.__originCellPosition,s=a.__originSheetId;a.__originCellPosition=i,a.__originSheetId=n;let c=e.execute(e.dependencies,t.referenceDenormalizer,t.ensureRange,r,a);return a.__originCellPosition=o,a.__originSheetId=s,c}var GW=class extends xW{static getters=[`evaluateFormula`,`evaluateFormulaResult`,`evaluateCompiledFormula`,`getCorrespondingFormulaCell`,`getRangeFormattedValues`,`getRangeValues`,`getRangeFormats`,`getEvaluatedCell`,`getEvaluatedCells`,`getEvaluatedCellsInZone`,`getEvaluatedCellsPositions`,`getSpreadZone`,`getArrayFormulaSpreadingOn`,`isArrayFormulaSpillBlocked`,`isEmpty`];shouldRebuildDependenciesGraph=!0;evaluator;positionsToUpdate=[];constructor(e){super(e),this.evaluator=new VW(e.custom,this.getters)}beforeHandle(e){(yr.has(e.type)||xr.has(e.type))&&(this.shouldRebuildDependenciesGraph=!0)}handle(e){switch(e.type){case`UPDATE_CELL`:if(!(`content`in e||`format`in e)||this.shouldRebuildDependenciesGraph)return;let t={sheetId:e.sheetId,row:e.row,col:e.col};this.positionsToUpdate.push(t),`content`in e&&this.evaluator.updateDependencies(t);break;case`EVALUATE_CELLS`:if(e.cellIds)for(let t=0;t<e.cellIds.length;t++)this.positionsToUpdate.push(this.getters.getCellPosition(e.cellIds[t]));else this.evaluator.evaluateAllCells();break}}finalize(){this.shouldRebuildDependenciesGraph?(this.evaluator.buildDependencyGraph(),this.evaluator.evaluateAllCells(),this.shouldRebuildDependenciesGraph=!1):this.positionsToUpdate.length&&this.evaluator.evaluateCells(this.positionsToUpdate),this.positionsToUpdate=[]}evaluateFormula(e,t,n){let r=this.evaluateFormulaResult(e,t,n);return Ir(r)?Ca(r,e=>e.value):r.value}evaluateFormulaResult(e,t,n){return this.evaluator.evaluateFormulaResult(e,t,n)}evaluateCompiledFormula(e,t,n){return this.evaluator.evaluateCompiledFormula(e,t,n)}getRangeFormattedValues(e){return this.getters.tryGetSheet(e.sheetId)===void 0?[]:this.mapVisiblePositions(e,e=>this.getters.getEvaluatedCell(e).formattedValue)}getRangeValues(e){return this.getters.tryGetSheet(e.sheetId)===void 0?[]:this.mapVisiblePositions(e,e=>this.getters.getEvaluatedCell(e).value)}getRangeFormats(e){let t=this.getters.tryGetSheet(e.sheetId);return t===void 0?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map(e=>e.format)}getEvaluatedCell(e){return this.evaluator.getEvaluatedCell(e)}getEvaluatedCells(e){return this.evaluator.getEvaluatedPositionsInSheet(e).map(e=>this.getEvaluatedCell(e))}getEvaluatedCellsPositions(e){return this.evaluator.getEvaluatedPositionsInSheet(e)}getEvaluatedCellsInZone(e,t){return Ks(t).map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}))}getSpreadZone(e,t={ignoreSpillError:!1}){return this.evaluator.getSpreadZone(e,t)}getArrayFormulaSpreadingOn(e){return this.evaluator.getArrayFormulaSpreadingOn(e)}isArrayFormulaSpillBlocked(e){return this.evaluator.isArrayFormulaSpillBlocked(e)}isEmpty(e,t){return Ks(t).map(({col:t,row:n})=>this.getEvaluatedCell({sheetId:e,col:t,row:n})).every(e=>e.type===`empty`)}mapVisiblePositions(e,t){let{sheetId:n,zone:r}=e;return Ks(r).reduce((e,r)=>{let{col:i,row:a}=r;return!this.getters.isColHidden(n,i)&&!this.getters.isRowHidden(n,a)&&e.push(t({sheetId:n,...r})),e},[])}exportForExcel(e){for(let t of e.sheets)t.cellValues={},t.formulaSpillRanges={};for(let t of this.evaluator.getEvaluatedPositions()){let n=this.evaluator.getEvaluatedCell(t),r=T(t.col,t.row),i=n.value,a=!1,o,s=!0,c=e.sheets.find(e=>e.id===t.sheetId),l=this.getCorrespondingFormulaCell(t);if(l){let u=this.getters.getCell(t);if(s=dC(l.compiledFormula.tokens),a=s&&u?.content===l.content,!s&&i!==``){o=(i??``).toString();let t=n.format;if(t){let n=mc(t,e.formats);c.formats[r]=n}}}let u=c.cells[r],d;d=s&&a&&l instanceof $U?l.contentWithFixedReferences:s?u:o,c.cells[r]=d,c.cellValues[r]=i===k.BadExpression?void 0:i;let f=this.getSpreadZone(t);f&&(c.formulaSpillRanges[r]=this.getters.getRangeString(this.getters.getRangeFromZone(t.sheetId,f),t.sheetId))}}getCorrespondingFormulaCell(e){let t=this.getters.getCell(e);if(t&&t.isFormula)return t.compiledFormula.isBadExpression?void 0:t;if(t&&t.content)return;let n=this.getArrayFormulaSpreadingOn(e);if(n===void 0)return;let r=this.getters.getCell(n);if(r?.isFormula)return r}};let KW=/"(#[0-9a-fA-F]{6})"/g;function qW(e){let t=[{leadColor:_n(255,0,0),colors:[]},{leadColor:_n(255,128,0),colors:[]},{leadColor:_n(128,128,0),colors:[]},{leadColor:_n(128,255,0),colors:[]},{leadColor:_n(0,255,0),colors:[]},{leadColor:_n(0,255,128),colors:[]},{leadColor:_n(0,255,255),colors:[]},{leadColor:_n(0,127,255),colors:[]},{leadColor:_n(0,0,255),colors:[]},{leadColor:_n(127,0,255),colors:[]},{leadColor:_n(128,0,128),colors:[]},{leadColor:_n(255,0,128),colors:[]}];for(let n of e.map(xn)){let e=500,r=0;t.forEach((t,i)=>{let a=JW(n,t.leadColor);e>a&&(e=a,r=i)}),t[r].colors.push(n)}return t.map(e=>e.colors.sort((e,t)=>Cn(e).s-Cn(t).s)).flat().map(bn)}function JW(e,t){return Math.sqrt((e.r-t.r)**2+(e.g-t.g)**2+(e.b-t.b)**2)}var YW=class extends xW{customColors={};shouldUpdateColors=!0;static getters=[`getCustomColors`];constructor(e){super(e),this.tryToAddColors(e.customColors??[])}handle(e){switch(e.type){case`START`:for(let e of this.getters.getSheetIds())for(let t of this.getters.getChartIds(e))this.tryToAddColors(this.getChartColors(t));break;case`UPDATE_CHART`:case`CREATE_CHART`:this.tryToAddColors(this.getChartColors(e.chartId));break;case`UPDATE_CELL`:case`ADD_CONDITIONAL_FORMAT`:case`SET_BORDER`:case`SET_ZONE_BORDERS`:case`SET_FORMATTING`:case`CREATE_TABLE`:case`UPDATE_TABLE`:this.history.update(`shouldUpdateColors`,!0);break}}finalize(){this.shouldUpdateColors&&(this.history.update(`shouldUpdateColors`,!1),this.tryToAddColors(this.computeCustomColors()))}getCustomColors(){return qW(Object.keys(this.customColors))}computeCustomColors(){let e=[];for(let t of this.getters.getSheetIds())e=e.concat(this.getColorsFromCells(t),this.getFormattingColors(t),this.getTableColors(t));return[...new Set([...e])]}getColorsFromCells(e){let t=Object.values(this.getters.getCells(e)),n=new Set;for(let e of t)e.style?.textColor&&n.add(e.style.textColor),e.style?.fillColor&&n.add(e.style.fillColor);for(let t of this.getters.getBordersColors(e))n.add(t);return[...n]}getFormattingColors(e){let t=this.getters.getConditionalFormats(e),n=[];for(let e of t){let t=e.rule;t.type===`CellIsRule`?(n.push(t.style.textColor),n.push(t.style.fillColor)):t.type===`ColorScaleRule`&&(n.push(dn(t.minimum.color)),n.push(t.midpoint?dn(t.midpoint.color):void 0),n.push(dn(t.maximum.color)))}return n.filter(C)}getChartColors(e){let t=this.getters.getChart(e);return t===void 0?[]:[...JSON.stringify(t.getDefinition()).matchAll(KW)].map(e=>e[1])}getTableColors(e){return this.getters.getTables(e).flatMap(e=>{let t=e.config,n=this.getters.getTableStyle(t.styleId);return[this.getTableStyleElementColors(n.wholeTable),t.numberOfHeaders>0?this.getTableStyleElementColors(n.headerRow):[],t.totalRow?this.getTableStyleElementColors(n.totalRow):[],t.bandedColumns?this.getTableStyleElementColors(n.firstColumnStripe):[],t.bandedColumns?this.getTableStyleElementColors(n.secondColumnStripe):[],t.bandedRows?this.getTableStyleElementColors(n.firstRowStripe):[],t.bandedRows?this.getTableStyleElementColors(n.secondRowStripe):[],t.firstColumn?this.getTableStyleElementColors(n.firstColumn):[],t.lastColumn?this.getTableStyleElementColors(n.lastColumn):[]].flat()})}getTableStyleElementColors(e){return e?[e.style?.fillColor,e.style?.textColor,e.border?.bottom?.color,e.border?.top?.color,e.border?.left?.color,e.border?.right?.color,e.border?.horizontal?.color,e.border?.vertical?.color].filter(C):[]}tryToAddColors(e){for(let t of e){if(!mn(t))continue;let e=pn(t);t&&!Ie.includes(e)&&this.history.update(`customColors`,e,!0)}}},XW=class extends xW{static getters=[`getChartRuntime`,`getStyleOfSingleCellChart`];charts={};createRuntimeChart=vO(this.getters);handle(e){if(yr.has(e.type)||Sr.has(e.type)||br.has(e.type))for(let e in this.charts)this.charts[e]=void 0;switch(e.type){case`UPDATE_CHART`:case`CREATE_CHART`:this.charts[e.chartId]=void 0;break;case`DELETE_CHART`:this.charts[e.chartId]=void 0;break;case`DELETE_SHEET`:for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0);break}}getChartRuntime(e){if(!this.charts[e]){let t=this.getters.getChart(e);if(!t)throw Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getStyleOfSingleCellChart(e,t){if(e)return{background:e,fontColor:AC(e)};if(!t)return{background:oe,fontColor:AC(oe)};let n=t.zone.left,r=t.zone.top,i=t.sheetId,a=this.getters.getCellComputedStyle({sheetId:i,col:n,row:r}),o=a.fillColor||`#FFFFFF`;return{background:o,fontColor:a.textColor||AC(o)}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let r of e){if(!r||r.tag!==`chart`)continue;let e=this.getters.getChartIds(t.id).find(e=>this.getters.getFigureIdFromChartId(e)===r.id);if(!e)continue;let i=this.getters.getChart(e),a=i?.getDefinitionForExcel(this.getters);if(a)n.push({...r,data:a});else{if(!i)continue;let n=this.getters.getChartType(e),a=jT(this.getters.getChartRuntime(e),r,n);a&&t.images.push({...r,tag:`image`,data:{mimetype:`image/png`,path:a,size:{width:r.width,height:r.height}}})}}t.charts=n}}},ZW=class extends xW{static getters=[`getConditionalIcon`,`getCellConditionalFormatStyle`,`getConditionalDataBar`];isStale=!0;computedStyles={};computedIcons={};computedDataBars={};handle(e){(yr.has(e.type)||Sr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e))&&(this.isStale=!0)}finalize(){if(this.isStale){for(let e of this.getters.getSheetIds())this.computedStyles[e]=Nt(()=>this.getComputedStyles(e)),this.computedIcons[e]=Nt(()=>this.getComputedIcons(e)),this.computedDataBars[e]=Nt(()=>this.getComputedDataBars(e));this.isStale=!1}}getCellConditionalFormatStyle(e){let{sheetId:t,col:n,row:r}=e,i=this.computedStyles[t]();return i&&i[n]?.[r]}getConditionalIcon({sheetId:e,col:t,row:n}){let r=this.computedIcons[e]();return r&&r[t]?.[n]}getConditionalDataBar({sheetId:e,col:t,row:n}){let r=this.computedDataBars[e]();return r&&r[t]?.[n]}getComputedStyles(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())switch(n.rule.type){case`ColorScaleRule`:for(let r of n.ranges)this.applyColorScale(e,r,n.rule,t);break;case`CellIsRule`:let r=n.rule.values.map(e=>e.startsWith(`=`)?rC(e):void 0);for(let i of n.ranges){let a=this.getters.getRangeFromSheetXC(e,i).zone;for(let i=a.top;i<=a.bottom;i++)for(let o=a.left;o<=a.right;o++){let s={sheetId:e,col:o,row:i},c=n.rule.values.map((t,n)=>{let s=r[n];return s?this.getters.getTranslatedCellFormula(e,o-a.left,i-a.top,s.tokens):t});this.getRuleResultForTarget(s,{...n.rule,values:c})&&(t[o]||(t[o]=[]),t[o][i]=Object.assign(t[o]?.[i]||{},n.rule.style))}}break}return t}getComputedIcons(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())if(n.rule.type===`IconSetRule`)for(let r of n.ranges)this.applyIcon(e,r,n.rule,t);return t}getComputedDataBars(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())if(n.rule.type===`DataBarRule`)for(let r of n.ranges)this.applyDataBar(e,r,n.rule,t);return t}parsePoint(e,t,n,r){let i=this.getters.getRangeFromSheetXC(e,t).zone,a=this.getters.getEvaluatedCellsInZone(e,i).filter(e=>e.type===`number`).map(e=>e.value);switch(n.type){case`value`:return r===`max`?$t(a):en(a);case`number`:return Number(n.value);case`percentage`:let t=en(a);return t+($t(a)-t)*Number(n.value)/100;case`percentile`:return Gi(a,Number(n.value)/100,!0);case`formula`:let i=n.value&&this.getters.evaluateFormula(e,n.value);return typeof i==`number`?i:null;default:return null}}applyIcon(e,t,n,r){let i=this.parsePoint(e,t,n.lowerInflectionPoint),a=this.parsePoint(e,t,n.upperInflectionPoint);if(i===null||a===null||i>a)return;let o=this.getters.getRangeFromSheetXC(e,t).zone,s=[n.icons.upper,n.icons.middle,n.icons.lower];for(let t=o.top;t<=o.bottom;t++)for(let c=o.left;c<=o.right;c++){let o=this.getters.getEvaluatedCell({sheetId:e,col:c,row:t});if(o.type!==`number`)continue;let l=this.computeIcon(o.value,a,n.upperInflectionPoint.operator,i,n.lowerInflectionPoint.operator,s);r[c]||(r[c]=[]),r[c][t]=l}}computeIcon(e,t,n,r,i,a){return n===`ge`&&e>=t||n===`gt`&&e>t?a[0]:i===`ge`&&e>=r||i===`gt`&&e>r?a[1]:a[2]}applyDataBar(e,t,n,r){let i=this.getters.getRangeFromSheetXC(e,n.rangeValues||t),a=$t(this.getters.getEvaluatedCellsInZone(e,i.zone).filter(e=>e.type===`number`).map(e=>e.value));if(a<=0)return;let o=n.color,s=this.getters.getRangeFromSheetXC(e,t).zone,c=i.zone;for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++){let i=n-s.left+c.left,l=t-s.top+c.top,u=this.getters.getEvaluatedCell({sheetId:e,col:i,row:l});!Vs(i,l,c)||u.type!==`number`||u.value<=0||(r[n]||(r[n]=[]),r[n][t]={color:dn(o),percentage:u.value*100/a})}}applyColorScale(e,t,n,r){let i=this.parsePoint(e,t,n.minimum,`min`),a=n.midpoint?this.parsePoint(e,t,n.midpoint):null,o=this.parsePoint(e,t,n.maximum,`max`);if(i===null||o===null||i>=o||a&&(i>=a||a>=o))return;let s=this.getters.getRangeFromSheetXC(e,t).zone,c=[{value:i,color:n.minimum.color}];n.midpoint&&a&&c.push({value:a,color:n.midpoint.color}),c.push({value:o,color:n.maximum.color});let l=Kn(c);for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++){let a=this.getters.getEvaluatedCell({sheetId:e,col:n,row:t});if(a.type===`number`){let e=x(a.value,i,o);r[n]||(r[n]=[]),r[n][t]=r[n]?.[t]||{},r[n][t].fillColor=l(e)}}}getRuleResultForTarget(e,t){let n=this.getters.getEvaluatedCell(e);if(n.type===`error`)return!1;let{sheetId:r}=e,i=Y.get(t.operator),a=t.values.map(t=>t.startsWith(`=`)?this.getters.evaluateFormula(r,t,e)??``:ts(t,D));if(a.some(Wu))return!1;let o={type:t.operator,values:a.map(Hu)};return i.isValueValid(n.value??``,o,this.getters,r)}};let QW={isValid:!0};var $W=class extends xW{static getters=[`getDataValidationInvalidCriterionValueMessage`,`getInvalidDataValidationMessage`,`getValidationResultForCellValue`,`getDataValidationRangeValues`,`isCellValidCheckbox`,`getDataValidationCellStyle`,`getDataValidationChipStyle`,`isDataValidationInvalid`];validationResults={};handle(e){if(yr.has(e.type)||e.type===`EVALUATE_CELLS`||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)){this.validationResults={};return}switch(e.type){case`ADD_DATA_VALIDATION_RULE`:case`REMOVE_DATA_VALIDATION_RULE`:delete this.validationResults[e.sheetId];break}}isDataValidationInvalid(e){return!this.getValidationResultForCell(e).isValid}getDataValidationCellStyle(e){if(!this.hasChip(e))return this.getDataValidationStyle(e)}getDataValidationChipStyle(e){if(this.hasChip(e))return this.getDataValidationStyle(e)??{fillColor:`#E7E9ED`}}getInvalidDataValidationMessage(e){let t=this.getValidationResultForCell(e);return t.isValid?void 0:t.error}getDataValidationInvalidCriterionValueMessage(e,t){let n=Y.get(e);return t.startsWith(`=`)?n.allowedValues===`onlyLiterals`?E(`The value must not be a formula`):this.isValidFormula(t)?void 0:U.CriterionError.validFormula:n.allowedValues===`onlyFormulas`?E(`The value must be a formula`):n.isCriterionValueValid(t)?void 0:n.criterionValueErrorString}getDataValidationRangeValues(e,t){let n=this.getters.getRangeFromSheetXC(e,String(t.values[0])),r=[],i=new Set;for(let e of Ks(n.zone)){let t=this.getters.getEvaluatedCell({...e,sheetId:n.sheetId});t.formattedValue&&!i.has(t.formattedValue)&&(i.add(t.formattedValue),r.push({label:t.formattedValue,value:t.value?.toString()||``}))}return r}isCellValidCheckbox(e){if(!this.getters.isMainCellPosition(e))return!1;let t=this.getters.getValidationRuleForCell(e);return!t||t.criterion.type!==`isBoolean`?!1:this.getValidationResultForCell(e).isValid}getValidationResultForCellValue(e,t){let n=this.getters.getValidationRuleForCell(t);if(!n)return QW;let r=this.getRuleErrorForCellValue(e,t,n);return r?{error:r,rule:n,isValid:!1}:QW}hasChip(e){let t=this.getters.getValidationRuleForCell(e);return(t?.criterion.type===`isValueInList`||t?.criterion.type===`isValueInRange`)&&t.criterion.displayStyle===`chip`}getDataValidationStyle(e){let t=this.getters.getValidationRuleForCell(e);if(!t||this.isDataValidationInvalid(e))return;let n=this.getters.getEvaluatedCell(e),r=this.getValueColor(t,n.value);if(r)return{fillColor:r,textColor:Mn(r)}}getValueColor(e,t){if(!(e.criterion.type!==`isValueInList`&&e.criterion.type!==`isValueInRange`)){for(let n in e.criterion.colors)if(n.toLowerCase()===String(t).toLowerCase())return e.criterion.colors[n]}}isValidFormula(e){return!rC(e).isBadExpression}getValidationResultForCell(e){let{col:t,row:n,sheetId:r}=e;return this.validationResults[r]||(this.validationResults[r]=this.computeSheetValidationResults(r)),this.validationResults[r][t]?.[n]?.()||QW}computeSheetValidationResults(e){let t={},n=this.getters.getDataValidationRules(e).map(e=>e.ranges);for(let e of Vc(n.flat())){let{col:n,row:r}=e;t[n]||(t[n]=[]),t[n][r]=Nt(()=>{let t=this.getters.getEvaluatedCell(e);return t.type===`empty`?QW:this.getValidationResultForCellValue(t.value,e)})}return t}getRuleErrorForCellValue(e,t,n){let{sheetId:r}=t,i=n.criterion,a=Y.get(i.type),o=this.getCellOffsetInRule(t,n),s=this.getEvaluatedCriterionValues(r,t,o,i);if(s.some(Wu))return;let c={...i,values:s.map(Hu)};if(!a.isValueValid(e,c,this.getters,r))return a.getErrorString(c,this.getters,r)}getCellOffsetInRule(e,t){let n=t.ranges.find(t=>Vs(e.col,e.row,t.zone));if(!n)throw Error(`The cell is not in any range of the rule`);return{col:e.col-n.zone.left,row:e.row-n.zone.top}}getEvaluatedCriterionValues(e,t,n,r){return r.values.map(r=>{if(!r.startsWith(`=`))return ts(r,D);let i=rC(r),a=this.getters.getTranslatedCellFormula(e,n.col,n.row,i.tokens);return this.getters.evaluateFormula(e,a,t)})}};let eG=new g;eG.add(`data_validation_checkbox`,(e,t)=>{if(e.isCellValidCheckbox(t)){let n=!!e.getEvaluatedCell(t).value;return{svg:n?Nj:jj,hoverSvg:n?Nj:Mj,priority:2,horizontalAlign:`center`,size:17,margin:2,position:t,type:`data_validation_checkbox`,onClick:(e,t)=>{let r=t.model.getters.getCell(e);if(t.model.getters.isReadonly()||r?.isFormula)return;let i=n?`FALSE`:`TRUE`;t.model.dispatch(`UPDATE_CELL`,{...e,content:i})}}}}),eG.add(`data_validation_chip_icon`,(e,t)=>{let n=e.getDataValidationChipStyle(t);if(n){let r=e.getCellComputedStyle(t);return{svg:kj(n),hoverSvg:Aj(n),priority:10,horizontalAlign:`right`,size:xl(r),margin:4,position:t,onClick:(e,t)=>{let{col:n,row:r}=e;t.model.selection.selectCell(n,r),t.startCellEdition()},type:`data_validation_chip_icon`}}}),eG.add(`data_validation_list_icon`,(e,t)=>{if(!e.isReadonly()&&e.cellHasListDataValidationIcon(t)){let n=e.getCellComputedStyle(t);return{svg:Tj(n),hoverSvg:Dj(n),priority:2,horizontalAlign:`right`,size:17,margin:2,position:t,onClick:(e,t)=>{let{col:n,row:r}=e;t.model.selection.selectCell(n,r),t.startCellEdition()},type:`data_validation_list_icon`}}}),eG.add(`filter_icon`,(e,t)=>{if(e.isFilterHeader(t)){let n=e.isFilterActive(t),r=vn(e.getCellComputedStyle(t).fillColor||`#fff`)<.45;return{type:`filter_icon`,svg:Fj(n,r,!1),hoverSvg:Fj(n,r,!0),priority:3,horizontalAlign:`right`,size:17,margin:2,position:t,onClick:(e,t)=>{let n=t.getStore(TA),r=n.persistentCellPopover;if(r.isOpen&&r.col===e.col&&r.row===e.row&&r.type===`FilterMenu`){n.close();return}n.open(e,`FilterMenu`)}}}}),eG.add(`conditional_formatting`,(e,t)=>{let n=e.getConditionalIcon(t);if(n){let r=e.getCellStyle(t);return{type:`conditional_formatting`,svg:Ij[n].svg,priority:1,horizontalAlign:`left`,size:xl(r),margin:4,position:t}}}),eG.add(`pivot_collapse`,(e,t)=>{if(!e.isSpillPivotFormula(t))return;let n=e.getPivotCellFromPosition(t),r=e.getPivotIdFromPosition(t);if(n.type===`HEADER`&&r&&n.domain.length){let i=e.getPivotCoreDefinition(r),a=e.isDashboard(),o=n.dimension===`COL`?i.columns:i.rows,s=!a&&n.domain.length!==o.length,c=(i.collapsedDomains?.[n.dimension]??[]).some(e=>w(e,n.domain)),l=n.dimension===`ROW`?(n.domain.length-1)*15:0;return{type:`pivot_collapse`,priority:4,horizontalAlign:`left`,size:s||!a&&n.dimension===`ROW`&&i.rows.length>1?12:0,margin:s?4+l:l,svg:s?Pj(c,!1):void 0,hoverSvg:s?Pj(c,!0):void 0,position:t,onClick:tG}}});function tG(e,t){let n=t.model.getters.getPivotCellFromPosition(e),r=t.model.getters.getPivotIdFromPosition(e);if(!r||n.type!==`HEADER`)return;let i=t.model.getters.getPivotCoreDefinition(r),a=i.collapsedDomains?.[n.dimension]?[...i.collapsedDomains[n.dimension]]:[],o=a.findIndex(e=>w(e,n.domain));o===-1?a.push(n.domain):a.splice(o,1);let s=i.collapsedDomains?{...i.collapsedDomains}:{COL:[],ROW:[]};s[n.dimension]=a,t.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...i,collapsedDomains:s}})}eG.add(`pivot_dashboard_sorting`,(e,t)=>{if(!e.isDashboard()||e.getPivotCellFromPosition(t).type!==`MEASURE_HEADER`)return;let n=e.getPivotCellSortDirection(t);if(n!==`asc`&&n!==`desc`)return;let r=e.getCellComputedStyle(t);return{type:`pivot_dashboard_sorting_${n}`,priority:5,horizontalAlign:`right`,size:17,margin:2,svg:n===`asc`?Ej(r):Tj(r),position:t,onClick:void 0}});var nG=class extends xW{static getters=[`doesCellHaveGridIcon`,`getCellIcons`,`getCellIconRect`];cellIconsCache={};handle(e){e.type!==`SET_VIEWPORT_OFFSET`&&(this.cellIconsCache={})}getCellIcons(e){return this.cellIconsCache[e.sheetId]||(this.cellIconsCache[e.sheetId]={}),this.cellIconsCache[e.sheetId][e.col]||(this.cellIconsCache[e.sheetId][e.col]={}),this.cellIconsCache[e.sheetId][e.col][e.row]||(this.cellIconsCache[e.sheetId][e.col][e.row]=this.computeCellIcons(e)),this.cellIconsCache[e.sheetId][e.col][e.row]}getCellIconRect(e,t){let n=e.position,r=this.getters.getCell(n);return{x:this.getIconHorizontalPosition(t,e.horizontalAlign,e),y:this.getters.computeTextYCoordinate(t,e.size,r?.style?.verticalAlign),width:e.size,height:e.size}}getIconHorizontalPosition(e,t,n){let r=e.x,i=e.x+e.width;switch(t){case`right`:return i-n.margin-n.size;case`left`:return r+n.margin;default:let e=Math.floor((i-r-n.size)/2);return i-n.size-e}}computeCellIcons(e){let t={left:void 0,right:void 0,center:void 0},n=eG.getAll();for(let r of n){let n=r(this.getters,e);n&&(!t[n.horizontalAlign]||n.priority>t[n.horizontalAlign].priority)&&(t[n.horizontalAlign]=n)}if(t.center&&(t.left||t.right)){let e=Math.max(t.left?.priority||0,t.right?.priority||0);t.center.priority<e?t.center=void 0:(t.left=void 0,t.right=void 0)}return Object.values(t).filter(C)}doesCellHaveGridIcon(e){return!!this.getCellIcons(e).length}},rG=class extends xW{static getters=[`canCreateDynamicTableOnZones`,`doesZonesContainFilter`,`getFilter`,`getFilters`,`getTable`,`getTables`,`getTablesOverlappingZones`,`getFilterId`,`getFilterHeaders`,`isFilterHeader`];tables={};handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)||e.type===`EVALUATE_CELLS`){this.tables={};return}switch(e.type){case`CREATE_TABLE`:case`REMOVE_TABLE`:case`UPDATE_TABLE`:case`DELETE_CONTENT`:this.tables={};break}}finalize(){for(let e of this.getters.getSheetIds())this.tables[e]||(this.tables[e]=this.computeTables(e))}computeTables(e){let t=[],n=this.getters.getCoreTables(e);for(let e of n)e.type!==`dynamic`&&t.push(e);let r=[...t];for(let i of n){if(i.type!==`dynamic`)continue;let n=this.coreTableToTable(e,i),a=n.range.zone;for(let e of r){let t=e.range.zone;zs(a,t)&&(a=t.left>a.left?{...a,right:Math.min(a.right,t.left-1)}:{...a,bottom:Math.min(a.bottom,t.top-1)})}t.push({...n,range:this.getters.getRangeFromZone(e,a)})}return t}getFilters(e){return this.getTables(e).filter(e=>e.config.hasFilters).map(e=>e.filters).flat()}getTables(e){return this.tables[e]||[]}getFilter(e){let t=this.getTable(e);if(!(!t||!t.config.hasFilters))return t.filters.find(t=>t.col===e.col)}getFilterId(e){return this.getFilter(e)?.id}getTable({sheetId:e,col:t,row:n}){return this.getTables(e).find(e=>Vs(t,n,e.range.zone))}getTablesOverlappingZones(e,t){return this.getTables(e).filter(e=>t.some(t=>zs(e.range.zone,t)))}doesZonesContainFilter(e,t){return this.getTablesOverlappingZones(e,t).some(e=>e.config.hasFilters)}getFilterHeaders(e){let t=[];for(let n of this.getTables(e)){if(!n.config.hasFilters)continue;let r=n.range.zone,i=r.top;for(let n=r.left;n<=r.right;n++)t.push({sheetId:e,col:n,row:i})}return t}isFilterHeader({sheetId:e,col:t,row:n}){return this.getFilterHeaders(e).some(e=>e.col===t&&e.row===n)}canCreateDynamicTableOnZones(e,t){if(!oc(t))return!1;let n=Fs(...t),r={col:n.left,row:n.top,sheetId:e},i=this.getters.getArrayFormulaSpreadingOn(r);if(!i){let e=this.getters.getEvaluatedCell(r);return e.value===k.SpilledBlocked&&!e.errorOriginPosition}else if(w(i,r)&&nc(n)===1)return!0;return w(n,this.getters.getSpreadZone(i))}coreTableToTable(e,t){if(t.type!==`dynamic`)return t;let n=t.range.zone,r={sheetId:e,col:n.left,row:n.top},i=this.getters.getSpreadZone(r)??t.range.zone,a=this.getters.getRangeFromZone(e,i),o=this.getDynamicTableFilters(e,t,i);return{id:t.id,range:a,filters:o,config:t.config}}getDynamicTableFilters(e,t,n){let r=[],{top:i,bottom:a,left:o,right:s}=n;for(let n=o;n<=s;n++){let s=n-o,c={left:n,right:n,top:i,bottom:a},l=gI(this.getDynamicTableFilterId(t.id,s),this.getters.getRangeFromZone(e,c),t.config,this.getters.getRangeFromZone);r.push(l)}return r}getDynamicTableFilterId(e,t){return e+`_`+t}isTableExcelExportable(e,t){return t.type===`dynamic`?!1:!Ks(t.range.zone).some(t=>this.getters.getArrayFormulaSpreadingOn({sheetId:e,...t}))}exportForExcel(e){for(let t of e.sheets){let n=[];for(let r of t.tables){let i=Ts(r.range),a={sheetId:t.id,col:i.left,row:i.top},o=this.getters.getCoreTable(a),s=this.getTable(a);if(!o||!s||this.isTableExcelExportable(t.id,o)){n.push(r);continue}t.styles=t.styles||{},t.borders=t.borders||{};for(let n of Ks(s.range.zone)){let r={sheetId:t.id,...n},i=this.getters.getCellComputedStyle(r),a=this.getters.getCellComputedBorder(r),o=T(n.col,n.row);if(!kt(i)){let n=mc(i,e.styles);t.styles[o]=n}if(a){let n=mc(a,e.borders);t.borders[o]=n}}}t.tables=n}}},iG=class extends xW{static getters=[`getRowSize`,`getHeaderSize`,`getMaxAnchorOffset`];tallestCellInRow={};ctx=document.createElement(`canvas`).getContext(`2d`);beforeHandle(e){switch(e.type){case`ADD_COLUMNS_ROWS`:if(e.dimension===`COL`)return;let t=Ft(e.position,e.base),n=Array(e.quantity).fill(void 0),r=Jt(this.tallestCellInRow[e.sheetId],n,t);this.history.update(`tallestCellInRow`,e.sheetId,r);break}}handle(e){switch(e.type){case`START`:case`UPDATE_LOCALE`:for(let e of this.getters.getSheetIds())this.initializeSheet(e);break;case`CREATE_SHEET`:this.initializeSheet(e.sheetId);break;case`DUPLICATE_SHEET`:{let t=b(this.tallestCellInRow[e.sheetId]);this.history.update(`tallestCellInRow`,e.sheetIdTo,t);break}case`DELETE_SHEET`:let t={...this.tallestCellInRow};delete t[e.sheetId],this.history.update(`tallestCellInRow`,t);break;case`REMOVE_COLUMNS_ROWS`:{if(e.dimension===`COL`)return;let t=qt(this.tallestCellInRow[e.sheetId],e.elements);this.history.update(`tallestCellInRow`,e.sheetId,t);break}case`RESIZE_COLUMNS_ROWS`:{let t=e.sheetId;if(e.dimension===`ROW`)for(let n of e.elements){let e=this.getRowTallestCell(t,n);this.history.update(`tallestCellInRow`,t,n,e)}else for(let n of S(0,this.getters.getNumberRows(t)))for(let r of e.elements)this.updateRowSizeForCellChange(t,n,r)}break;case`UPDATE_CELL`:this.updateRowSizeForCellChange(e.sheetId,e.row,e.col);break;case`ADD_MERGE`:case`REMOVE_MERGE`:for(let t of e.target)for(let n of Ks(t))this.updateRowSizeForCellChange(e.sheetId,n.row,n.col)}}getRowSize(e,t){return Math.round(this.getters.getUserRowSize(e,t)??this.tallestCellInRow[e][t]?.size??23)}getMaxAnchorOffset(e,t,n){let{numberOfRows:r,numberOfCols:i}=this.getters.getSheetSize(e),a=0;for(;a<t&&r>0;r--)a+=this.getRowSize(e,r-1);let o=0;for(;o<n&&i>0;i--)o+=this.getters.getColSize(e,i-1);return{col:i,row:r,offset:{x:o-n,y:a-t}}}getHeaderSize(e,t,n){return this.getters.isHeaderHidden(e,t,n)?0:t===`ROW`?this.getRowSize(e,n):this.getters.getColSize(e,n)}updateRowSizeForCellChange(e,t,n){let r=this.tallestCellInRow[e]?.[t];if(r?.cell.col===n){let n=this.getRowTallestCell(e,t);this.history.update(`tallestCellInRow`,e,t,n)}let i=this.getCellHeight({sheetId:e,col:n,row:t});if(!(i<=23)&&(!r&&i>23||r&&i>r.size)){let r={cell:{sheetId:e,col:n,row:t},size:i};this.history.update(`tallestCellInRow`,e,t,r)}}initializeSheet(e){let t=[];for(let n=0;n<this.getters.getNumberRows(e);n++){let r=this.getRowTallestCell(e,n);t.push(r)}this.history.update(`tallestCellInRow`,e,t)}getCellHeight(e){if(this.isInMultiRowMerge(e))return 23;let t=this.getters.getCell(e),n=this.getters.getColSize(e.sheetId,e.col);return ul(this.ctx,t,this.getters.getLocale(),n)}isInMultiRowMerge(e){let t=this.getters.getMerge(e);return!!t&&t.bottom!==t.top}getRowTallestCell(e,t){if(this.getters.getUserRowSize(e,t)!==void 0)return;let n=this.getters.getRowCells(e,t),r=0,i;for(let e=0;e<n.length;e++){let t=this.getters.getCellById(n[e]);if(!t)continue;let a=this.getters.getCellPosition(t.id),o=this.getCellHeight(a);o>r&&o>23&&(r=o,i={cell:a,size:o})}if(i&&i.size>23)return i}};let aG=`0.00%`;function oG(e){class t extends e{getters;pivotId;cache={};rankAsc={};rankDesc={};runningTotal={};runningTotalInPercent={};constructor(e,t,n){super(t,n),this.getters=n.getters,this.pivotId=e}markAsDirtyForEvaluation(){this.cache={},this.rankAsc={},this.rankDesc={},this.runningTotal={},this.runningTotalInPercent={},super.markAsDirtyForEvaluation?.()}getPivotCellValueAndFormat(e,t){return this.getMeasureDisplayValue(e,t)}_getPivotCellValueAndFormat(e,t){let n=`${e}-${t.map(e=>e.field+`=`+e.value).join(`,`)}`;if(this.cache[n])return this.cache[n];let r=this.getMeasure(e),i=r.computedBy?this.computeMeasure(r,t):super.getPivotCellValueAndFormat(e,t);return r.format?this.cache[n]={...i,format:r.format}:this.cache[n]=i,this.cache[n]}computeMeasure(e,t){if(!e.computedBy)return{value:0};let{columns:n,rows:r}=super.definition;if(e.aggregator&&n.length+r.length!==t.length){let n=this.getValuesToAggregate(e,t),r=wd[e.aggregator];if(!r)return{value:0};try{return r([n],this.getters.getLocale())}catch(t){return VS(t,e.aggregator.toUpperCase())}}let i=this.getters.getMeasureCompiledFormula(this.pivotId,e),a=this.getters.evaluateCompiledFormula(e.computedBy.sheetId,i,e=>{let{columns:n,rows:r}=this.definition;if(n.find(t=>t.nameWithGranularity===e)){let{colDomain:n}=LL(this,t),r=n.findIndex(t=>t.field===e);return r===-1?new Xi:this.getPivotHeaderValueAndFormat(n.slice(0,r+1))}if(r.find(t=>t.nameWithGranularity===e)){let{rowDomain:n}=LL(this,t),r=n.findIndex(t=>t.field===e);return r===-1?new Xi:this.getPivotHeaderValueAndFormat(n.slice(0,r+1))}return this.getPivotCellValueAndFormat(e,t)});return Ir(a)?a[0][0]:a}getValuesToAggregate(e,t){let{rowDomain:n,colDomain:r}=LL(this,t),i=super.getExpandedTableStructure(),a=[];if(r.length===0&&n.length<this.definition.rows.length&&this.definition.rows.length&&this.definition.columns.length){let t=this.treeToLeafDomains(i.getColTree()),r=this.getSubTreeMatchingDomain(i.getRowTree(),n),o=this.treeToLeafDomains(r);for(let r of t)for(let t of o)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t).concat(r)));return a}else if(n.length===this.definition.rows.length&&r.length===0){let t=i.getColTree(),o=this.getSubTreeMatchingDomain(t,r),s=this.treeToLeafDomains(o,r);for(let t of s)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t)));return a}else if(n.length===this.definition.rows.length&&r.length&&r.length<this.definition.columns.length){let t=this.getSubTreeMatchingDomain(i.getColTree(),r),o=this.treeToLeafDomains(t,r);for(let t of o)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t)));return a}else{let t=i.getRowTree(),o=this.getSubTreeMatchingDomain(t,n),s=this.treeToLeafDomains(o,n);for(let t of s)a.push(this._getPivotCellValueAndFormat(e.id,t.concat(r)));return a}}getSubTreeMatchingDomain(e,t,n=0){if(n>t.length)return[];if(t.length===n)return e;for(let r of e){let e=Nd(this.definition.getDimension(r.field),t[n]?.value);if(r.field===t[n]?.field&&r.value===e)return this.getSubTreeMatchingDomain(r.children,t,n+1)}return[]}treeToLeafDomains(e,t=[]){let n=[];for(let r of e){let e=this.definition.getDimension(r.field),i=[...t,{field:r.field,value:r.value,type:e.type}];r.children.length===0?n.push(i):n.push(...this.treeToLeafDomains(r.children,i))}return n}getMeasureDisplayValue(e,t){let n=this.getMeasure(e),r=this._getPivotCellValueAndFormat(e,t);if(!n.display||n.display.type===`no_calculations`||r.message)return r;let i=n.display.fieldNameWithGranularity;if(i&&!this.isFieldInPivot(i))return{value:k.NotAvailable,message:E(`Field "%s" not found in pivot for measure display calculation`,i)};try{let e=n.display;switch(e.type){case`%_of_grand_total`:return this.asPercentOfGrandTotal(r,n);case`%_of_col_total`:return this.asPercentOfColumnTotal(r,n,t);case`%_of_row_total`:return this.asPercentOfRowTotal(r,n,t);case`%_of_parent_row_total`:return this.asPercentOfParentRowTotal(r,n,t);case`%_of_parent_col_total`:return this.asPercentOfParentColumnTotal(r,n,t);case`index`:return this.asIndex(r,n,t);case`%_of_parent_total`:return this.asPercentOfParentTotal(r,n,t,e);case`running_total`:return this.asRunningTotal(r,n,t,e,`running_total`);case`%_running_total`:return this.asRunningTotal(r,n,t,e,`%_running_total`);case`rank_asc`:return this.asRank(r,n,t,e,`asc`);case`rank_desc`:return this.asRank(r,n,t,e,`desc`);case`%_of`:return this.asPercentOf(r,n,t,e);case`difference_from`:return this.asDifferenceFrom(r,n,t,e);case`%_difference_from`:return this.asDifferenceFromInPercent(r,n,t,e)}return r}catch(e){return VS(e,`COMPUTE_MEASURE_DISPLAY_VALUE`)}}asPercentOfGrandTotal(e,t){let n=this.getGrandTotal(t.id);return n===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/n,format:aG}}asPercentOfRowTotal(e,t,n){let r=this.getRowTotal(t.id,n);return r===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/r,format:aG}}asPercentOfColumnTotal(e,t,n){let r=this.getColumnTotal(t.id,n);return r===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/r,format:aG}}asPercentOfParentRowTotal(e,t,n){let r=FL(this,n),i=this.measureValueToNumber(this._getPivotCellValueAndFormat(t.id,r));return i===0?{value:``}:{value:this.measureValueToNumber(e)/i,format:aG}}asPercentOfParentColumnTotal(e,t,n){let r=IL(this,n),i=this.measureValueToNumber(this._getPivotCellValueAndFormat(t.id,r));return i===0?{value:``}:{value:this.measureValueToNumber(e)/i,format:aG}}asPercentOfParentTotal(e,t,n,r){let{fieldNameWithGranularity:i}=r;if(!i)return e;if(!GL(i,n))return{value:``};let a=UL(this,i,n),o=this._getPivotCellValueAndFormat(t.id,a),s=this.measureValueToNumber(o);return s===0?{value:``}:{value:this.measureValueToNumber(e)/s,format:aG}}asIndex(e,t,n){let r=this.measureValueToNumber(e),i=this.getRowTotal(t.id,n),a=this.getColumnTotal(t.id,n),o=this.getGrandTotal(t.id);return i===0||a===0?{value:k.DivisionByZero}:{value:r*o/(a*i),format:void 0}}asRunningTotal(e,t,n,r,i){let{fieldNameWithGranularity:a}=r;if(!a)return e;let o=i===`running_total`?this.runningTotal:this.runningTotalInPercent,s=o[t.id]?.[a];s||(s=this.computeRunningTotal(t,a,i),o[t.id]||(o[t.id]={}),o[t.id][a]=s);let{rowDomain:c,colDomain:l}=LL(this,n),u=JL(l),d=JL(c);return{value:s[u]?.[d]??``,format:i===`running_total`?e.format:aG}}asPercentOf(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a),s=this.strictMeasureValueToNumber(e);return o===0||o===`sameValue`&&s===0?{value:k.DivisionByZero}:!o||o===`sameValue`&&!s?{value:``}:o===`sameValue`?{value:1,format:aG}:s===void 0?{value:k.NullError}:{value:s/o,format:aG}}asDifferenceFrom(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a)||0;return o===`sameValue`?{value:``}:{value:this.measureValueToNumber(e)-o,format:e.format}}asDifferenceFromInPercent(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a),s=this.strictMeasureValueToNumber(e);return o===0?{value:k.DivisionByZero}:!o||o===`sameValue`?{value:``}:s===void 0?{value:k.NullError}:{value:(s-o)/o,format:aG}}asRank(e,t,n,r,i){let{fieldNameWithGranularity:a}=r;if(!a)return e;if(!GL(a,n))return{value:``};let o=i===`asc`?this.rankAsc:this.rankDesc,s=o[t.id]?.[a];s||(s=this.computeRank(t,a,i),o[t.id]||(o[t.id]={}),o[t.id][a]=s);let{rowDomain:c,colDomain:l}=LL(this,n),u=JL(l),d=JL(c);return{value:s[u]?.[d]??``}}computeRank(e,t,n){let r={},i=KL(this,t),a=i===`row`?`column`:`row`,o=this.getPivotValueCells(e.id);i===`column`&&(o=Ta(o));for(let s of o){let o=JL(RL(this,a,s[0].domain)),c=s.map(t=>({...t,value:this.strictMeasureValueToNumber(this._getPivotCellValueAndFormat(e.id,t.domain)),rowDomain:RL(this,i,t.domain)})).filter(e=>GL(t,e.rowDomain)),l=Object.groupBy(c,e=>XL(e.rowDomain,t));for(let e in l)l[e]=nn(l[e]||[],e=>e.value).filter(e=>e.value!==void 0).sort((e,t)=>n===`asc`?e.value-t.value:t.value-e.value);r[o]={};for(let e of c){let n=JL(RL(this,i,e.domain)),a=l[XL(e.rowDomain,t)];if(!a)continue;let s=a.findIndex(t=>t.value===e.value);s!==-1&&(r[o][n]=s+1)}}return i===`row`?r:rn(r)}computeRunningTotal(e,t,n){let r={},i=KL(this,t),a=i===`row`?`column`:`row`,o=this.getPivotValueCells(e.id);i===`column`&&(o=Ta(o));for(let s of o){let o=JL(RL(this,a,s[0].domain));r[o]={};let c={},l=s.map(t=>({...t,rowDomain:RL(this,i,t.domain),value:this.measureValueToNumber(this._getPivotCellValueAndFormat(e.id,t.domain))})).filter(e=>GL(t,e.rowDomain));for(let e of l){let n=JL(e.rowDomain),i=ZL(e.rowDomain,t),a=(c[i]||0)+e.value;c[i]=a,r[o][n]=a}if(n===`%_running_total`)for(let e of l){let n=e.rowDomain,i=JL(n),a=ZL(n,t),s=r[o][i]||0,l=c[a];r[o][i]=l?s/l:void 0}}return i===`row`?r:rn(r)}getGrandTotal(e){let t=this._getPivotCellValueAndFormat(e,[]);return this.measureValueToNumber(t)}getRowTotal(e,t){let n=LL(this,t).rowDomain,r=this._getPivotCellValueAndFormat(e,n);return this.measureValueToNumber(r)}getColumnTotal(e,t){let n=LL(this,t).colDomain,r=this._getPivotCellValueAndFormat(e,n);return this.measureValueToNumber(r)}isFieldInPivot(e){return this.definition.columns.some(t=>t.nameWithGranularity===e)||this.definition.rows.some(t=>t.nameWithGranularity===e)}getComparisonValue(e,t,n,r){let i=r===`(previous)`||r===`(next)`?qL(this,t,n,r):WL(t,n,r);if(w(i,t))return`sameValue`;if(!i||!BL(this,i))throw new Xi;let a=this._getPivotCellValueAndFormat(e.id,i);return this.strictMeasureValueToNumber(a)}getPivotValueCells(e){return this.getCollapsedTableStructure().getPivotCells().map(t=>t.filter(t=>t.type===`VALUE`&&t.measure===e)).filter(e=>e.length>0)}measureValueToNumber(e){if(typeof e.value==`number`)return e.value;if(!e.value)return 0;throw Error(`Value ${e.value} is not a number`)}strictMeasureValueToNumber(e){if(typeof e.value==`number`)return e.value;if(e.value)throw Error(`Value ${e.value} is not a number`)}getCollapsedTableStructure(){let e=super.getCollapsedTableStructure();return this.sortTableStructure(e),e}getExpandedTableStructure(){let e=super.getExpandedTableStructure();return this.sortTableStructure(e),e}sortTableStructure(e){if(!this.definition.sortedColumn||e.isSorted)return;let t=this.definition.sortedColumn.measure;Vd(this.definition.sortedColumn,this)&&e.sort(t,this.definition.sortedColumn,(e,t)=>this._getPivotCellValueAndFormat(e,t))}}return t}let sG=[`ADD_PIVOT`,`UPDATE_PIVOT`,`REMOVE_PIVOT`];function cG(e){return sG.includes(e.type)}var lG=class extends xW{static getters=[`getPivot`,`getFirstPivotFunction`,`getPivotCellSortDirection`,`getPivotIdFromPosition`,`getPivotIdsFromPosition`,`getPivotCellFromPosition`,`generateNewCalculatedMeasureName`,`isPivotUnused`,`isSpillPivotFormula`];pivots={};unusedPivots;custom;constructor(e){super(e),this.custom=e.custom}beforeHandle(e){switch(e.type){case`START`:for(let e of this.getters.getPivotIds())this.setupPivot(e)}}handle(e){if(yr.has(e.type))for(let e of this.getters.getPivotIds())this.setupPivot(e,{recreate:!0});switch(e.type){case`REFRESH_PIVOT`:this.refreshPivot(e.id);break;case`ADD_PIVOT`:this.setupPivot(e.pivotId);break;case`DUPLICATE_PIVOT`:this.setupPivot(e.newPivotId);break;case`UPDATE_PIVOT`:this.setupPivot(e.pivotId,{recreate:!0});break;case`DELETE_SHEET`:case`UPDATE_CELL`:this.unusedPivots=void 0;break;case`UNDO`:case`REDO`:{this.unusedPivots=void 0;let t=e.commands.filter(cG);for(let e of t){let t=e.pivotId;this.getters.isExistingPivot(t)&&this.setupPivot(t,{recreate:!0})}break}case`UPDATE_LOCALE`:gR();break}}getPivotIdFromPosition(e){return this.getPivotIdsFromPosition(e)[0]}getPivotIdsFromPosition(e){let t=this.getters.getCorrespondingFormulaCell(e);return t&&t.isFormula?this.getPivotIdsFromFormula(e.sheetId,t.compiledFormula):[]}getPivotIdsFromFormula(e,t){return this.getPivotFunctions(e,t.tokens).map(e=>{let t=e.args[0]?.toString();return t&&this.getters.getPivotId(t)}).filter(C)}isSpillPivotFormula(e){let t=this.getters.getCorrespondingFormulaCell(e);return t&&t.isFormula?this.getFirstPivotFunction(e.sheetId,t.compiledFormula.tokens)?.functionName===`PIVOT`:!1}getPivotFunctions(e,t){let n=gU(t);if(!n.length)return[];let r=[];for(let t of n){let{functionName:n,args:i}=t,a=i.map(t=>{if(t.type===`EMPTY`)return;if(t.type===`STRING`||t.type===`BOOLEAN`||t.type===`NUMBER`)return t.value;let n=PB(t);return this.getters.evaluateFormula(e,n)});r.push({functionName:n,args:a})}return r}getFirstPivotFunction(e,t){return this.getPivotFunctions(e,t)[0]}getPivotCellFromPosition(e){let t=this.getters.getCorrespondingFormulaCell(e);if(!t||!t.isFormula||_U(t.compiledFormula.tokens)===0)return rR;let n=this.getters.getCellPosition(t.id),r=this.getters.getFirstPivotFunction(e.sheetId,t.compiledFormula.tokens);if(!r)return rR;let{functionName:i,args:a}=r,o=a[0];if(!o)return rR;let s=this.getters.getPivotId(o.toString());if(!s)return rR;let c=this.getPivot(s);if(!c.isValid()||i===`PIVOT`&&!t.content.replaceAll(` `,``).toUpperCase().startsWith(`=PIVOT`))return rR;try{if(i===`PIVOT`){let t=Hu(a[2]),r=t===void 0?!0:P(t),i=Hu(a[3]),o=Hu(a[5]),s=o===void 0?!0:P(o),l={displayColumnHeaders:i===void 0?!0:P(i),displayTotals:r,displayMeasuresRow:s},u=c.getCollapsedTableStructure().getPivotCells(l),d=e.col-n.col,f=e.row-n.row;return u[d][f]}let t=e.row-n.row,r=e.col-n.col;if(a=a.map(e=>Ir(e)?e[r][t]:e),i===`PIVOT.HEADER`&&a.at(-2)===`measure`)return{type:`MEASURE_HEADER`,domain:c.parseArgsToPivotDomain(a.slice(1,-2).map(e=>({value:e}))),measure:a.at(-1)?.toString()||``};if(i===`PIVOT.HEADER`){let e=c.parseArgsToPivotDomain(a.slice(1).map(e=>({value:e})));return{type:`HEADER`,domain:e,dimension:LL(c,e).colDomain.length?`COL`:`ROW`}}let[o,...s]=a.slice(1);return{type:`VALUE`,domain:c.parseArgsToPivotDomain(s.map(e=>({value:e}))),measure:o?.toString()||``}}catch{return rR}}generateNewCalculatedMeasureName(e){let t=e.map(e=>e.fieldName);return an(E(`Calculated measure 1`),t,{compute:(e,t)=>E(`Calculated measure %s`,t)})}getPivot(e){if(!this.getters.isExistingPivot(e))throw Error(`pivot ${e} not found`);return this.pivots[e]}isPivotUnused(e){return this._getUnusedPivots().includes(e)}getPivotCellSortDirection(e){let t=this.getters.getPivotIdFromPosition(e),n=this.getters.getPivotCellFromPosition(e);if(n.type===`EMPTY`||n.type===`HEADER`||!t)return;let r=this.getters.getPivot(t),i=LL(r,n.domain).colDomain,a=r.definition.sortedColumn;return a?.measure===n.measure&&w(a.domain,i)?a.order:`none`}refreshPivot(e){this.getters.getPivot(e).init({reload:!0})}setupPivot(e,{recreate:t}={recreate:!1}){let n=b(this.getters.getPivotCoreDefinition(e));if(e in this.pivots)t&&this.pivots[e].onDefinitionChange(n);else{let t=oG(vR.get(n.type).ui);this.pivots[e]=new t(e,this.custom,{definition:n,getters:this.getters})}}_getUnusedPivots(){if(this.unusedPivots!==void 0)return this.unusedPivots;let e=new Set(this.getters.getPivotIds());for(let t of this.getters.getSheetIds())for(let n in this.getters.getCells(t)){let t=this.getters.getCellPosition(n),r=this.getPivotIdsFromPosition(t);for(let t of r)if(e.delete(t),!e.size)return this.unusedPivots=[],[]}for(let t of this.getters.getPivotIds()){let n=this.getters.getPivot(t);for(let r of n.definition.measures)if(r.computedBy){let{sheetId:n}=r.computedBy,i=this.getters.getMeasureCompiledFormula(t,r),a=this.getPivotIdsFromFormula(n,i);for(let t of a)if(e.delete(t),!e.size)return this.unusedPivots=[],[]}}return this.unusedPivots=[...e],this.unusedPivots}};let uG=new g;uG.add(`ALPHANUMERIC_INCREMENT_MODIFIER`,{apply:(e,t)=>{e.current+=e.increment;let n=Math.abs(e.current).toString();n=`0`.repeat(Math.max(e.numberPostfixLength-n.length,0))+n;let r=`${e.prefix}${n}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:{props:{content:r}}}}}).add(`INCREMENT_MODIFIER`,{apply:(e,t,n)=>{e.current+=e.increment;let r=e.current.toString(),i=n.getLocale(),a=L(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:r?{props:{content:a}}:void 0}}}).add(`DATE_INCREMENT_MODIFIER`,{apply:(e,t,n)=>{let r=F(e.current,n.getLocale());r.setFullYear(r.getFullYear()+e.increment.years||0),r.setMonth(r.getMonth()+e.increment.months||0),r.setDate(r.getDate()+e.increment.days||0);let i=wi(r);e.current=i;let a=n.getLocale(),o=L(i,{format:t.cell?.format,locale:a});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i.toString()},tooltip:i?{props:{content:o}}:void 0}}}).add(`COPY_MODIFIER`,{apply:(e,t,n)=>{let r=t.cell?.content||``,i={locale:n.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:r?{props:{content:t.cell?es(t.cell,i).formattedValue:``}}:void 0}}}).add(`FORMULA_MODIFIER`,{apply:(e,t,n,r)=>{e.current+=e.increment;let i=0,a=0;switch(r){case`up`:i=0,a=-e.current;break;case`down`:i=0,a=e.current;break;case`left`:i=-e.current,a=0;break;case`right`:i=e.current,a=0;break}let o=t.cell;if(!o||!o.isFormula)return{cellData:{}};let s=t.sheetId,c=n.getTranslatedCellFormula(s,i,a,o.compiledFormula.tokens);return{cellData:{border:t.border,style:o.style,format:o.format,content:c},tooltip:c?{props:{content:c}}:void 0}}});let dG=new g,fG=/(\d+)$/,pG=/^(.*\D+)/,mG=/^(.*\D+)(\d+)$/,hG=/^0*/;function gG(e,t,n){let r=[],i=!1;for(let a of t){a===e&&(i=!0);let t=a===void 0||a.isFormula?void 0:es(a,{locale:D,format:a.format});if(t&&n(t))r.push(t);else{if(i)return r;r=[]}}return r}function _G(e){let t=[],n=e[0];for(let r=1;r<e.length;r++){let i=e[r];t.push(i-n),n=i}return t.reduce((e,t)=>e+t,0)/t.length}function vG(e){let t=1;return e.length>=2&&(t=_G(e)*e.length),t}function yG(e){return e.length<2?e[0]||{years:0,months:0,days:0}:e.every(t=>t.years===e[0].years&&t.months===e[0].months&&t.days===e[0].days)?e[0]:void 0}function bG(e){if(e.length<2)return 1;let t=e.map(e=>F(e,D)),n=yG(xG(t));if(n===void 0)return;let r=Object.values(n).filter(e=>e!==0).length===1,i=Object.values(n).every(e=>e===0);if(!r||i){let n=t.map((e,n)=>{if(n===0)return 0;let r=t[n-1];return Math.floor(e.getTime())-Math.floor(r.getTime())}).slice(1);if(n.every(e=>e===n[0]))return e.length*(e[1]-e[0])}return{years:n.years*e.length,months:n.months*e.length,days:n.days*e.length}}dG.add(`simple_value_copy`,{condition:(e,t)=>t.length===1&&!e.isFormula&&!(e.format&&jo(e.format)),generateRule:()=>({type:`COPY_MODIFIER`}),sequence:10}).add(`increment_alphanumeric_value`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`text`&&mG.test(e.content),generateRule:(e,t,n)=>{let r=parseInt(e.content.match(fG)[0]),i=e.content.match(pG)[0],a=gG(e,t,e=>e.type===`text`&&mG.test(e.value)).filter(e=>i===(e.value??``).toString().match(pG)[0]).map(e=>(e.value??``).toString().match(fG)[0]),o=a.reduce((e,t)=>{let n=t.match(hG)[0].length;return n>e[1]?[t,n]:e},[a[0],0]),s=o[1]?o[0].length:0,c=vG(a.map(e=>parseInt(e)));return[`up`,`left`].includes(n)&&a.length===1&&(c=-c),{type:`ALPHANUMERIC_INCREMENT_MODIFIER`,prefix:i,current:r,increment:c,numberPostfixLength:s}},sequence:15}).add(`copy_text`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`text`,generateRule:()=>({type:`COPY_MODIFIER`}),sequence:20}).add(`update_formula`,{condition:e=>e.isFormula,generateRule:(e,t)=>({type:`FORMULA_MODIFIER`,increment:t.length,current:0}),sequence:30}).add(`increment_dates`,{condition:(e,t)=>!e.isFormula&&es(e,{locale:D}).type===`number`&&!!e.format&&jo(e.format),generateRule:(e,t)=>{let n=bG(gG(e,t,e=>e.type===`number`&&!!e.format&&jo(e.format)).map(e=>Number(e.value)));if(n===void 0)return{type:`COPY_MODIFIER`};let r=es(e,{locale:D});return typeof n==`object`?{type:`DATE_INCREMENT_MODIFIER`,increment:n,current:r.type===`number`?r.value:0}:{type:`INCREMENT_MODIFIER`,increment:n,current:r.type===`number`?r.value:0}},sequence:25}).add(`increment_number`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`number`,generateRule:(e,t,n)=>{let r=gG(e,t,e=>e.type===`number`&&!jo(e.format||``)).map(e=>Number(e.value)),i=vG(r);[`up`,`left`].includes(n)&&r.length===1&&(i=-i);let a=es(e,{locale:D});return{type:`INCREMENT_MODIFIER`,increment:i,current:a.type===`number`?a.value:0}},sequence:40});function xG(e){return e.length<2?[{years:0,months:0,days:0}]:e.map((t,n)=>{if(n===0)return{years:0,months:0,days:0};let r=O.fromTimestamp(e[n-1].getTime()),i=Mi(r,t),a=Ai(r,t)%12;return r.setFullYear(r.getFullYear()+i),r.setMonth(r.getMonth()+a),{years:i,months:a,days:ji(r,t)}}).slice(1)}var SG=class{cells;getters;index=0;direction;constructor(e,t,n){this.cells=e,this.getters=t,this.direction=n}next(){let e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:n,tooltip:r}=uG.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:n,tooltip:r,origin:{col:e.data.col,row:e.data.row}}}},CG=class extends Rp{static layers=[`Autofill`];static getters=[`getAutofillTooltip`];autofillZone;steps;lastCellSelected={};direction;tooltip;allowDispatch(e){switch(e.type){case`AUTOFILL_SELECT`:let t=this.getters.getActiveSheetId();return this.lastCellSelected.col=e.col===-1?this.lastCellSelected.col:x(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=e.row===-1?this.lastCellSelected.row:x(e.row,0,this.getters.getNumberRows(t)),this.lastCellSelected.col!==void 0&&this.lastCellSelected.row!==void 0?`Success`:`InvalidAutofillSelection`}return`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}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||this.direction===void 0){this.tooltip=void 0;return}let t=this.getters.getSelectedZone(),n=this.autofillZone,r=[];switch(this.direction){case`down`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.top;n<=t.bottom;n++)i.push(T(e,n));let a=this.createGenerator(i);for(let t=n.top;t<=n.bottom;t++)r.push(this.computeNewCell(a,e,t))}break;case`up`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.bottom;n>=t.top;n--)i.push(T(e,n));let a=this.createGenerator(i);for(let t=n.bottom;t>=n.top;t--)r.push(this.computeNewCell(a,e,t))}break;case`left`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.right;n>=t.left;n--)i.push(T(n,e));let a=this.createGenerator(i);for(let t=n.right;t>=n.left;t--)r.push(this.computeNewCell(a,t,e))}break;case`right`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.left;n<=t.right;n++)i.push(T(n,e));let a=this.createGenerator(i);for(let t=n.left;t<=n.right;t++)r.push(this.computeNewCell(a,t,e))}break}if(e){let e={},t={},n={},i=this.getters.getActiveSheetId();for(let a of r)this.collectBordersData(a,e),this.autofillMerge(i,a),this.autofillCell(i,a),this.collectConditionalFormatsData(i,a,t),this.collectDataValidationsData(i,a,n);this.autofillBorders(i,e),this.autofillConditionalFormats(i,t),this.autofillDataValidations(i,n),this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0}}collectBordersData(e,t){let n=JSON.stringify(e.border);n in t||(t[n]=[]),t[n].push(R({col:e.col,row:e.row}))}collectConditionalFormatsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s=this.getters.getRulesByCell(e,r,i),c=T(a,o);for(let e of s)e.id in n||(n[e.id]=[]),n[e.id].push(c)}collectDataValidationsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s={sheetId:e,col:r,row:i},c=this.getters.getValidationRuleForCell(s);c&&(c.id in n||(n[c.id]=[]),n[c.id].push(R({col:a,row:o})))}autofillCell(e,t){this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t.col,row:t.row,content:t.content||``,style:t.style||null,format:t.format||``}),this.dispatch(`AUTOFILL_CELL`,t)}autofillBorders(e,t){for(let n in t){let r=n===`undefined`?void 0:JSON.parse(n);this.dispatch(`SET_BORDERS_ON_TARGET`,{sheetId:e,border:r,target:ms(t[n])})}}autofillConditionalFormats(e,t){for(let n in t){let r=t[n],i=this.getters.getConditionalFormats(e).find(e=>e.id===n);if(!i)continue;let a=this.getters.getAdaptedCfRanges(e,i,r.map(Ts),[]);a&&this.dispatch(`ADD_CONDITIONAL_FORMAT`,{cf:{id:i.id,rule:i.rule,stopIfTrue:i.stopIfTrue},ranges:a,sheetId:e})}}autofillDataValidations(e,t){for(let n in t){let r=t[n],i=this.getters.getDataValidationRule(e,n);if(!i)continue;let a=ms(i.ranges.map(e=>e.zone).concat(r),[]);this.dispatch(`ADD_DATA_VALIDATION_RULE`,{rule:i,ranges:a.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}}select(e,t){let n=this.getters.getSelectedZone();if(Vs(e,t,n)){this.autofillZone=void 0;return}switch(this.direction=this.getDirection(e,t),this.direction){case`up`:this.saveZone(t,n.top-1,n.left,n.right),this.steps=n.top-t;break;case`down`:this.saveZone(n.bottom+1,t,n.left,n.right),this.steps=t-n.bottom;break;case`left`:this.saveZone(n.top,n.bottom,e,n.left-1),this.steps=n.left-e;break;case`right`:this.saveZone(n.top,n.bottom,n.right+1,e),this.steps=e-n.right;break}this.autofill(!1)}autofillAuto(){let e=this.getters.getActivePosition(),t=this.getters.getTable(e),n=t?t.range.zone.bottom:this.getAutofillAutoLastRow(),r=this.getters.getSelectedZone();for(let t=r.bottom+1;t<=n;t++)if(this.getters.getEvaluatedCell({...e,row:t}).type!==`empty`){n=t-1;break}n>r.bottom&&(this.select(e.col,n),this.autofill(!0))}getAutofillAutoLastRow(){let e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId(),n=e.left,r=e.bottom;if(n>0){let e={sheetId:t,col:n-1,row:r};for(;this.getters.getEvaluatedCell(e).type!==`empty`;)r+=1,e={sheetId:t,col:n-1,row:r}}if(r===e.bottom&&(n=e.right,n<=this.getters.getNumberCols(t))){let e={sheetId:t,col:n+1,row:r};for(;this.getters.getEvaluatedCell(e).type!==`empty`;)r+=1,e={sheetId:t,col:n+1,row:r}}return r-1}computeNewCell(e,t,n){let{cellData:r,tooltip:i,origin:a}=e.next(),{content:o,style:s,border:c,format:l}=r;return this.tooltip=i,{originCol:a.col,originRow:a.row,col:t,row:n,content:o,style:s,border:c,format:l}}getRule(e,t){let n=dG.getAll().sort((e,t)=>e.sequence-t.sequence).find(n=>n.condition(e,t));return n&&this.direction&&n.generateRule(e,t,this.direction)}createGenerator(e){let t=[],n=[],r=this.getters.getActiveSheetId();for(let t of e){let{col:e,row:i}=ir(t),a=this.getters.getCell({sheetId:r,col:e,row:i});n.push({col:e,row:i,cell:a,sheetId:r})}let i=n.map(e=>e.cell);for(let e of n){let n={type:`COPY_MODIFIER`};e&&e.cell&&(n=this.getRule(e.cell,i)||n);let r=this.getters.getCellBorder(e)||void 0;t.push({data:{...e,border:r},rule:n})}return new SG(t,this.getters,this.direction)}saveZone(e,t,n,r){this.autofillZone={top:e,bottom:t,left:n,right:r}}getDirection(e,t){let n=this.getters.getSelectedZone(),r={up:{number:n.top-t,value:`up`},down:{number:t-n.bottom,value:`down`},left:{number:n.left-e,value:`left`},right:{number:e-n.right,value:`right`}};if(Object.values(r).map(e=>+(e.number>0)).reduce((e,t)=>e+t)===1)return Object.values(r).find(e=>+(e.number>0)).value;let i=r.up.number>0?`up`:`down`,a=r.left.number>0?`left`:`right`;return Math.abs(r[i].number)>=Math.abs(r[a].number)?r[i].value:r[a].value}autofillMerge(e,t){let{originCol:n,originRow:r,col:i,row:a}=t,o={sheetId:e,col:i,row:a},s={sheetId:e,col:n,row:r};if(this.getters.isInMerge(o)&&!this.getters.isInMerge(s)){let t=this.getters.getMerge(o);t&&this.dispatch(`REMOVE_MERGE`,{sheetId:e,target:[t]})}let c=this.getters.getMerge(s);c?.left===n&&c?.top===r&&this.dispatch(`ADD_MERGE`,{sheetId:e,target:[{top:a,bottom:a+c.bottom-c.top,left:i,right:i+c.right-c.left}]})}drawLayer(e){if(!this.autofillZone)return;let{ctx:t,thinLineWidth:n}=e,{x:r,y:i,width:a,height:o}=this.getters.getVisibleRect(this.autofillZone);a>0&&o>0&&(t.strokeStyle=`black`,t.lineWidth=n,t.setLineDash([3]),t.strokeRect(r,i,a,o),t.setLineDash([]))}},wG=class extends Rp{static getters=[`getAutomaticSums`];handle(e){switch(e.type){case`SUM_SELECTION`:let e=this.getters.getActiveSheetId(),{zones:t,anchor:n}=this.getters.getSelection();for(let r of t){let t=this.getAutomaticSums(e,r,n.cell);this.dispatchCellUpdates(e,t)}break}}getAutomaticSums(e,t,n){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,n):this.sumData(e,t)}sumData(e,t){let n=this.dimensionsToSum(e,t),r=this.sumDimensions(e,t,n).filter(({zone:t})=>!this.getters.isEmpty(e,t));return n.has(`ROW`)&&n.has(`COL`)&&r.push(this.sumTotal(t)),r}sumAdjacentData(e,t,n){let{col:r,row:i}=Vs(n.col,n.row,t)?n:{col:t.left,row:t.top},a=this.findAdjacentData(e,r,i);return a?this.getters.isSingleCellOrMerge(e,t)||Ws(Fs(a,t))?[{position:{col:r,row:i},zone:a}]:this.sumDimensions(e,Fs(a,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,n){let r=this.getters.getSheet(e),i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.findSuitableZoneToSum(r,i.col,i.row);if(a)return this.getters.expandZone(e,a)}findSuitableZoneToSum(e,t,n){let r=this.getters.getEvaluatedCell({sheetId:e.id,col:t,row:n-1}),i=this.getters.getEvaluatedCell({sheetId:e.id,col:t-1,row:n});if(this.isNumber(i)&&!this.isNumber(r))return this.findHorizontalZone(e,t,n);let a=this.findVerticalZone(e,t,n);if(this.isZoneValid(a))return a;let o=this.findHorizontalZone(e,t,n);if(this.isZoneValid(o))return o}findVerticalZone(e,t,n){let r={top:0,bottom:n-1,left:t,right:t},i=this.reduceZoneStart(e,r,r.bottom);return{...r,top:i}}findHorizontalZone(e,t,n){let r={top:n,bottom:n,left:0,right:t-1},i=this.reduceZoneStart(e,r,r.right);return{...r,left:i}}reduceZoneStart(e,t,n){let r=this.getters.getEvaluatedCellsInZone(e.id,t),i=S(n,-1,-1),a=$t(i.filter(e=>r[e]&&!r[e].isAutoSummable)),o=gt(i.filter(e=>this.isNumber(r[e])))[0]||[];return $t(o)<a?1/0:en(o)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){return e.type===`number`&&!(e.format&&jo(e.format))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){let n=new Set;return Ws(t)?(n.add(Us(t).numberOfCols===1?`COL`:`ROW`),n):(this.lastColIsEmpty(e,t)&&n.add(`ROW`),this.lastRowIsEmpty(e,t)&&n.add(`COL`),n.size===0&&n.add(`COL`),n)}sumDimensions(e,t,n){return[...n.has(`COL`)?this.sumColumns(t,e):[],...n.has(`ROW`)?this.sumRows(t,e):[]]}sumTotal(e){let{bottom:t,right:n}=e;return{position:{col:n,row:t},zone:{...e,top:t,right:n-1}}}sumColumns(e,t){let n=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,n.bottom-1)},Ks(n).map(t=>({position:t,zone:{...e,right:t.col,left:t.col}}))}sumRows(e,t){let n=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,n.right-1)},Ks(n).map(t=>({position:t,zone:{...e,top:t.row,bottom:t.row}}))}dispatchCellUpdates(e,t){for(let n of t){let{col:t,row:r}=n.position;this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:`=SUM(${this.getters.zoneToXC(e,n.zone)})`})}}nextEmptyRow(e,t){let n=t.bottom+1,{left:r,right:i}=t;for(;!this.getters.isEmpty(e,{bottom:n,top:n,left:r,right:i});)n++;return{...t,top:n,bottom:n}}nextEmptyCol(e,t){let n=t.right+1,{top:r,bottom:i}=t;for(;!this.getters.isEmpty(e,{left:n,right:n,top:r,bottom:i});)n++;return{...t,left:n,right:n}}transpose(e){return new Set([...e.values()].map(e=>e===`COL`?`ROW`:`COL`))}};let TG=new class extends g{addTransformation(e,t,n){this.content[e]||(this.content[e]=new Map);for(let r of t)this.content[e].set(r,n);return this}getTransformation(e,t){return this.content[t]&&this.content[t].get(e)}},EG=new class extends g{add(e,t){return super.add(e,t),this}replace(e,t){return super.replace(e,t),this}get(e){return this.content[e]}};TG.addTransformation(`ADD_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],zG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],zG),TG.addTransformation(`DELETE_SHEET`,[`MOVE_RANGES`],AG),TG.addTransformation(`DELETE_FIGURE`,[`UPDATE_FIGURE`,`UPDATE_CHART`,`UPDATE_CAROUSEL`],jG),TG.addTransformation(`DELETE_CHART`,[`UPDATE_CHART`],MG),TG.addTransformation(`DELETE_CHART`,[`UPDATE_CAROUSEL`],NG),TG.addTransformation(`CREATE_SHEET`,[`CREATE_SHEET`],PG),TG.addTransformation(`ADD_MERGE`,[`ADD_MERGE`,`REMOVE_MERGE`],FG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],IG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],IG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`UPDATE_TABLE`],LG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`UPDATE_TABLE`],LG),TG.addTransformation(`REMOVE_TABLE_STYLE`,[`CREATE_TABLE`,`UPDATE_TABLE`],RG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],BG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],BG),TG.addTransformation(`REMOVE_PIVOT`,[`RENAME_PIVOT`,`DUPLICATE_PIVOT`,`INSERT_PIVOT`,`UPDATE_PIVOT`],kG),TG.addTransformation(`DELETE_SHEET`,[`ADD_PIVOT`,`UPDATE_PIVOT`],OG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`ADD_PIVOT`,`UPDATE_PIVOT`],DG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`ADD_PIVOT`,`UPDATE_PIVOT`],DG);function DG(e,t){if(e.pivot.type!==`SPREADSHEET`||e.pivot.dataSet?.sheetId!==t.sheetId)return e;let n=of(e.pivot.dataSet.zone,t),r=n?{...e.pivot.dataSet,zone:n}:void 0;return{...e,pivot:{...e.pivot,dataSet:r}}}function OG(e,t){return e.pivot.type===`SPREADSHEET`&&e.pivot.dataSet?.sheetId===t.sheetId?{...e,pivot:{...e.pivot,dataSet:void 0}}:e}function kG(e,t){if(e.pivotId!==t.pivotId)return e}function AG(e,t){let n=t.sheetId;if(!(e.targetSheetId===n||e.sheetId===n))return e}function jG(e,t){if(e.figureId!==t.figureId)return e}function MG(e,t){if(e.chartId!==t.chartId)return e}function NG(e,t){return{...e,definition:{...e.definition,items:e.definition.items.filter(e=>!(e.type===`chart`&&e.chartId===t.chartId))}}}function PG(e,t){return e.sheetId===t.sheetId&&(e={...e,sheetId:`${e.sheetId}~`}),e.name===t.name?{...e,name:e.name?.match(/\d+/)?e.name.replace(/\d+/,e=>(parseInt(e)+1).toString()):`${e.name}~`,position:e.position+1}:e}function FG(e,t){if(e.sheetId!==t.sheetId)return e;let n=[];for(let r of e.target)t.target.every(e=>!zs(r,e))&&n.push(r);if(n.length)return{...e,target:n}}function IG(e,t){if(e.sheetId!==t.sheetId||(e.type===`FREEZE_COLUMNS`?`COL`:`ROW`)!==t.dimension)return e;let n=e.quantity;if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);for(let t of e)n>t&&n--}if(t.type===`ADD_COLUMNS_ROWS`){let e=t.position===`before`?t.base-1:t.base;n=n>e?n+t.quantity:n}return n>0?{...e,quantity:n}:void 0}function LG(e,t){if(e.sheetId!==t.sheetId)return e;let n=of(e.zone,t);if(!n)return;let r=e.newTableRange?sf(e.newTableRange,t):void 0;return{...e,newTableRange:r,zone:n}}function RG(e,t){return e.config?.styleId===t.tableStyleId?{...e,config:{...e.config,styleId:QA.styleId}}:e}function zG(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n;if(t.type===`REMOVE_COLUMNS_ROWS`?n=il(t.elements,[e.base])[0]:t.type===`ADD_COLUMNS_ROWS`&&(n=rl(Ft(t.position,t.base),t.quantity,[e.base])[0]),n!==void 0)return{...e,base:n}}function BG(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n=S(e.start,e.end+1),r=[];if(t.type===`REMOVE_COLUMNS_ROWS`?r=il(t.elements,n):t.type===`ADD_COLUMNS_ROWS`&&(r=rl(Ft(t.position,t.base),t.quantity,n)),r.length!==0)return{...e,start:Math.min(...r),end:Math.max(...r)}}function VG(e,t){let n=e.content&&mC(e.sheetId,e.content,t);return{...e,content:n}}EG.add(`UPDATE_CELL`,VG);function HG(e,t){let n=e.cf.rule;if(e={...e,cf:{...e.cf}},n.type===`CellIsRule`)e.cf.rule={...n,values:n.values.map(n=>mC(e.sheetId,n,t))};else if(n.type===`ColorScaleRule`){let{minimum:r,maximum:i,midpoint:a}=n;e.cf.rule={...n,minimum:{...r,value:r.value&&mC(e.sheetId,r.value,t)},maximum:{...i,value:i.value&&mC(e.sheetId,i.value,t)},midpoint:a?{...a,value:mC(e.sheetId,a.value,t)}:void 0}}else if(n.type===`IconSetRule`){let{upperInflectionPoint:r,lowerInflectionPoint:i}=n;e.cf.rule={...n,upperInflectionPoint:{...r,value:mC(e.sheetId,r.value,t)},lowerInflectionPoint:{...i,value:mC(e.sheetId,i.value,t)}}}else n.type===`DataBarRule`&&(e.cf.rule={...n,rangeValues:n.rangeValues?hC(e.sheetId,n.rangeValues,t).range:void 0});return e}EG.add(`ADD_CONDITIONAL_FORMAT`,HG);function UG(e,t){return e={...e,rule:{...e.rule,criterion:{...e.rule.criterion}}},e.rule.criterion.values=e.rule.criterion.values.map(n=>mC(e.sheetId,n,t)),e}EG.add(`ADD_DATA_VALIDATION_RULE`,UG);function WG(e,t){return e=b(e),e.pivot.measures.map(e=>{e.computedBy&&(e.computedBy.formula=mC(e.computedBy.sheetId,e.computedBy.formula,t))}),e}EG.add(`ADD_PIVOT`,WG),EG.add(`UPDATE_PIVOT`,WG),EG.add(`CREATE_CHART`,GG),EG.add(`UPDATE_CHART`,GG);function GG(e,t){return{...e,definition:bO(e.sheetId,e.definition,t)}}let KG=[{match:pr,fn:ZG},{match:hr,fn:QG},{match:vr,fn:$G},{match:_r,fn:nK},{match:mr,fn:tK},{match:gr,fn:eK}];function qG(e,t){let n=TG.getTransformation(e.type,t.type),r=n?n(e,t):XG(e,t);return r&&JG(r,t)}function JG(e,t){let n=EG.get(e.type);if(!n)return e;let r=Gc(t);return r?n(e,r):e}function YG(e,t){let n=[...e],r=new Set(TG.getKeys());for(let e of t)(r.has(e.type)||Kc.contains(e.type))&&(n=n.reduce((t,n)=>{let r=qG(n,e);return r&&t.push(r),t},[]));return n}function XG(e,t){for(let{match:n,fn:r}of KG)if(n(e)){let n=r(e,t);if(n===`SKIP_TRANSFORMATION`)continue;if(n===`IGNORE_COMMAND`)return;e=n}return e}function ZG(e,t){if(!(`sheetId`in t))return e;let n=t.type===`DELETE_SHEET`&&t.sheetId;return e.sheetId===n?`IGNORE_COMMAND`:e.type===`CREATE_SHEET`||t.type===`CREATE_SHEET`||e.sheetId!==t.sheetId?e:`SKIP_TRANSFORMATION`}function QG(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=[];for(let n of e.target){let e=of(n,t);e&&r.push(e)}return r.length?{...e,target:r}:`IGNORE_COMMAND`}function $G(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=of(e.zone,t);return r?{...e,zone:r}:`IGNORE_COMMAND`}function eK(e,t){if(!(`sheetId`in t))return e;let n=e.ranges.map(e=>sf(e,t)).filter(C);return n.length?{...e,ranges:n}:`IGNORE_COMMAND`}function tK(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;if(t.type!==`ADD_COLUMNS_ROWS`&&t.type!==`REMOVE_COLUMNS_ROWS`)return`SKIP_TRANSFORMATION`;if(t.dimension!==e.dimension)return e;let r=[];return t.type===`REMOVE_COLUMNS_ROWS`?r=il(t.elements,e.elements):t.type===`ADD_COLUMNS_ROWS`&&(r=rl(Ft(t.position,t.base),t.quantity,e.elements)),r.length===0?`IGNORE_COMMAND`:{...e,elements:r}}function nK(e,t){let n=ZG(e,t);return n===`SKIP_TRANSFORMATION`?t.type===`ADD_COLUMNS_ROWS`||t.type===`REMOVE_COLUMNS_ROWS`?rK(e,t):t.type===`ADD_MERGE`?iK(e,t):`SKIP_TRANSFORMATION`:n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e}function rK(e,t){let n=t.dimension===`COL`?`col`:`row`,r=e[n];if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);if(e.includes(r))return`IGNORE_COMMAND`;for(let t of e)r>=t&&r--}return t.type===`ADD_COLUMNS_ROWS`&&(r>t.base||r===t.base&&t.position===`before`)&&(r+=t.quantity),{...e,[n]:r}}function iK(e,t){for(let n of t.target)if(!(e.col===n.left&&e.row===n.top)&&Vs(e.col,e.row,n))return`IGNORE_COMMAND`;return e}var aK=class{rootCommand;timestamp;id;clientId;_commands=[];_changes=[];constructor(e,t,n,r,i,a){this.rootCommand=r,this.timestamp=a,this.id=e,this.clientId=t,this._commands=[...n],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}},oK=class extends Error{},sK=class extends cf{revisions;transportService;serverRevisionId;clients={};clientId=`local`;debouncedMove;pendingMessages=[];awaitingClientPosition;waitingAck=!1;waitingUndoRedoAck=!1;isReplayingInitialRevisions=!1;processedRevisions=new Set;lastRevisionMessage=void 0;uuidGenerator=new jl;lastLocalOperation;constructor(e,t,n=We){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=n,this.debouncedMove=At(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t,n){if(!t.length||!n.length||!this.canApplyOptimisticUpdate())return;let r=new aK(this.uuidGenerator.uuidv4(),this.clientId,t,e,n,Date.now());this.revisions.append(r.id,r),e.type!==`REQUEST_REDO`&&(this.lastLocalOperation=r),this.trigger(`new-local-state-update`,{id:r.id}),this.sendUpdateMessage({type:`REMOTE_REVISION`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:r.id,clientId:r.clientId,commands:r.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:`REVISION_UNDONE`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:`REVISION_REDONE`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:`local`,name:`local`},this.clientId=`local`),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this)),this.awaitingClientPosition&&=(this._move(this.awaitingClientPosition),void 0)}loadInitialMessages(e){let t=performance.now(),n=e.reduce((e,t)=>e+(t.type===`REMOTE_REVISION`?t.commands.length:1),0);this.isReplayingInitialRevisions=!0;for(let t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1,console.debug(`Replayed`,n,`commands in`,performance.now()-t,`ms`)}async leave(e){e&&Object.keys(this.clients).length===1&&this.lastRevisionMessage&&this.lastRevisionMessage?.type!==`SNAPSHOT_CREATED`&&await this.snapshot(e()),delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.sendToTransport({type:`CLIENT_LEFT`,clientId:this.clientId,version:1})}async snapshot(e){if(this.pendingMessages.length!==0)return;let t=this.uuidGenerator.uuidv4();await this.sendToTransport({type:`SNAPSHOT`,nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getCurrentClient(){return this.getClient(this.clientId)}getClient(e){let t=this.clients[e];if(!t)throw new oK(`The client left the session`);return t}getConnectedClients(){return new Set(Object.values(this.clients).filter(C))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return this.pendingMessages.length===0}getLastLocalNonEmptyRevision(){return this.lastLocalOperation}_move(e){if(!this.clients[this.clientId]){this.awaitingClientPosition=e;return}let t=this.clients[this.clientId]?.position;if(t?.col===e.col&&t.row===e.row&&t.sheetId===e.sheetId)return;let n=t?`CLIENT_MOVED`:`CLIENT_JOINED`,r=this.getCurrentClient();this.clients[this.clientId]={...r,position:e},this.sendToTransport({type:n,version:1,client:{...r,position:e}}).then(()=>{this.pendingMessages.length>0&&!this.waitingAck&&this.sendPendingMessage()})}onMessageReceived(e){if(!this.isAlreadyProcessed(e)){if(this.isWrongServerRevisionId(e)){this.trigger(`unexpected-revision-id`);return}switch(e.type){case`CLIENT_MOVED`:this.onClientMoved(e);break;case`CLIENT_JOINED`:this.onClientJoined(e);break;case`CLIENT_LEFT`:this.onClientLeft(e);break;case`REVISION_REDONE`:this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger(`revision-redone`,{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case`REVISION_UNDONE`:this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger(`revision-undone`,{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case`REMOTE_REVISION`:let{clientId:t,commands:n,timestamp:r}=e,i=new aK(e.nextRevisionId,t,n,void 0,void 0,r);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);let t=this.pendingMessages.filter(e=>e.type===`REMOTE_REVISION`).map(e=>e.commands).flat();this.trigger(`remote-revision-received`,{commands:YG(n,t)})}break;case`SNAPSHOT_CREATED`:{let t=new aK(e.nextRevisionId,`server`,[],void 0,void 0,Date.now());this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger(`snapshot`),this.lastLocalOperation=void 0;break}}this.acknowledge(e),this.trigger(`collaborative-event-received`)}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;let t=this.clients[this.clientId];if(t){let{position:e}=t;e&&this.sendToTransport({type:`CLIENT_MOVED`,version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),!this.waitingAck&&this.sendPendingMessage()}async sendToTransport(e){return this.transportService.sendMessage(e)}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if(e.type===`REMOTE_REVISION`){let t=this.revisions.get(e.nextRevisionId);t.commands.length===0&&(this.revisions.rebase(t.id),t=this.revisions.get(e.nextRevisionId)),e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.
|
|
1929
|
+
`;var YU=class extends t.Component{static template=`o_spreadsheet.PivotHTMLRenderer`;static components={Checkbox:bA};static props={pivotId:String,onCellClicked:Function};pivot=this.env.model.getters.getPivot(this.props.pivotId);data={columns:[],rows:[],values:[]};state=(0,t.useState)({showMissingValuesOnly:!1});setup(){let e=this.pivot.getExpandedTableStructure(),t=this.env.model.getters.getPivotFormulaId(this.props.pivotId);this.data={columns:this._buildColHeaders(t,e),rows:this._buildRowHeaders(t,e),values:this._buildValues(t,e)}}get tracker(){return this.env.model.getters.getPivotPresenceTracker(this.props.pivotId)}getTableData(){if(!this.state.showMissingValuesOnly)return this.data;let e=this.getColumnsIndexes(),t=this.getRowsIndexes();return{columns:this.buildColumnsMissing(e),rows:this.buildRowsMissing(t),values:this.buildValuesMissing(e,t)}}addRecursiveRow(e){let t=this.pivot.getExpandedTableStructure().rows,n=[...t[e].values];if(n.length<=1)return[e];n.pop();let r=t.findIndex(e=>JSON.stringify(e.values)===JSON.stringify(n));return[e].concat(this.addRecursiveRow(r))}buildColumnsMissing(e){let t=[];for(let e of this.data.columns){let n=[];for(let t in e)for(let r=0;r<e[t].span;r++)n.push(parseInt(t,10));t.push(n)}for(let n=t[t.length-1].length;n>=0;n--)if(!e.includes(n))for(let e of t)e.splice(n,1);let n=[];for(let e in t){let r=[],i,a=1;for(let n=0;n<t[e].length;n++)i===t[e][n]?a++:(i!==void 0&&r.push(Object.assign({},this.data.columns[e][i],{span:a})),i=t[e][n],a=1);i!==void 0&&r.push(Object.assign({},this.data.columns[e][i],{span:a})),n.push(r)}return n}buildRowsMissing(e){return e.map(e=>this.data.rows[e])}buildValuesMissing(e,t){let n=e.map(()=>[]);for(let r of t)for(let t in e)n[t].push(this.data.values[e[t]][r]);return n}getColumnsIndexes(){let e=new Set;for(let t=0;t<this.data.columns.length;t++){let n=[];for(let e=0;e<this.data.columns[t].length;e++)for(let r=0;r<this.data.columns[t][e].span;r++)n.push(this.data.columns[t][e]);for(let t=0;t<n.length;t++)n[t].isMissing&&e.add(t)}for(let t=0;t<this.data.columns[this.data.columns.length-1].length;t++)this.data.values[t].find(e=>e.isMissing)&&e.add(t);return Array.from(e).sort((e,t)=>e-t)}getRowsIndexes(){let e=new Set;for(let t=0;t<this.data.rows.length;t++){this.data.rows[t].isMissing&&e.add(t);for(let n of this.data.values)n[t].isMissing&&this.addRecursiveRow(t).forEach(t=>e.add(t))}return Array.from(e).sort((e,t)=>e-t)}_buildColHeaders(e,t){let n=[];for(let r of t.columns){let t=[];for(let n of r){let r=[];for(let e=0;e<n.fields.length;e++)r.push({value:n.fields[e]},{value:n.values[e]});let i=this.pivot.parseArgsToPivotDomain(r),a=this.env.model.getters.getLocale();if(i.at(-1)?.field===`measure`){let{value:r,format:o}=this.pivot.getPivotMeasureValue(N(i.at(-1).value),i);t.push({formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(r,{format:o,locale:a}),span:n.width,isMissing:!this.tracker?.isHeaderPresent(i)})}else{let{value:r,format:o}=this.pivot.getPivotHeaderValueAndFormat(i);t.push({formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(r,{format:o,locale:a}),span:n.width,isMissing:!this.tracker?.isHeaderPresent(i)})}}n.push(t)}let r=n[n.length-1];return n[n.length-1]=r.map(e=>(e.isMissing||(e.style=`color: #756f6f;`),e)),n}_buildRowHeaders(e,t){let n=[];for(let r of t.rows){let t=[];for(let e=0;e<r.fields.length;e++)t.push({value:r.fields[e]},{value:r.values[e]});let i=this.pivot.parseArgsToPivotDomain(t),{value:a,format:o}=this.pivot.getPivotHeaderValueAndFormat(i),s=this.env.model.getters.getLocale(),c={formula:`=PIVOT.HEADER(${Ad(e,i).join(`,`)})`,value:L(a,{format:o,locale:s}),isMissing:!this.tracker?.isHeaderPresent(i)};r.indent>1&&(c.style=`padding-left: ${r.indent-10}px`),n.push(c)}return n}_buildValues(e,t){let n=[];for(let r of t.columns.at(-1)||[]){let i=[],a=N(r.values[r.values.length-1]);for(let n of t.rows){let t=[];for(let e=0;e<n.fields.length;e++)t.push({value:n.fields[e]},{value:n.values[e]});for(let e=0;e<r.fields.length-1;e++)t.push({value:r.fields[e]},{value:r.values[e]});let o=this.pivot.parseArgsToPivotDomain(t),{value:s,format:c}=this.pivot.getPivotCellValueAndFormat(a,o),l=this.env.model.getters.getLocale();i.push({formula:`=PIVOT.VALUE(${Ad(e,o,a).join(`,`)})`,value:L(s,{format:c,locale:l}),isMissing:!this.tracker?.isValuePresent(a,o)})}n.push(i)}return n}},XU=class extends Lp{getters;dispatch;canDispatch;constructor({getters:e,stateObserver:t,range:n,dispatch:r,canDispatch:i}){super(t),n.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.dispatch=r,this.canDispatch=i}import(e){}export(e){}adaptRanges(e,t,n){}garbageCollectExternalResources(){}},ZU=class extends XU{static getters=[`getCellBorder`,`getBordersColors`];borders={};allowDispatch(e){switch(e.type){case`SET_BORDER`:return this.checkBordersUnchanged(e);default:return`Success`}}handle(e){switch(e.type){case`ADD_MERGE`:for(let t of e.target)this.addBordersToMerge(e.sheetId,t);break;case`DUPLICATE_SHEET`:let t=this.borders[e.sheetId];if(t){let n=t.slice().map(e=>e?.slice().map(e=>b(e)));this.history.update(`borders`,e.sheetIdTo,n)}break;case`DELETE_SHEET`:let n={...this.borders};delete n[e.sheetId],this.history.update(`borders`,n);break;case`SET_BORDER`:this.setBorder(e.sheetId,e.col,e.row,e.border);break;case`SET_BORDERS_ON_TARGET`:for(let t of e.target)for(let n=t.top;n<=t.bottom;n++)for(let r=t.left;r<=t.right;r++)this.setBorder(e.sheetId,r,n,e.border);break;case`SET_ZONE_BORDERS`:if(e.border){let t=e.target.map(t=>this.getters.expandZone(e.sheetId,t));this.setBorders(e.sheetId,t,e.border.position,e.border.color===``?void 0:{style:e.border.style||Ue.style,color:e.border.color||Ue.color})}break;case`CLEAR_FORMATTING`:this.clearBorders(e.sheetId,e.target);break;case`REMOVE_COLUMNS_ROWS`:let r=[...e.elements].sort((e,t)=>t-e);for(let t of gt(r))if(e.dimension===`COL`){let n=this.getters.getColsZone(e.sheetId,t[t.length-1],t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersHorizontally(e.sheetId,t[0]+1,-t.length)}else{let n=this.getters.getRowsZone(e.sheetId,t[t.length-1],t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersVertically(e.sheetId,t[0]+1,-t.length)}break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.handleAddColumns(e):this.handleAddRows(e);break}}handleAddColumns(e){let t,n;e.position===`before`?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity),t=e.base,n=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,n)}handleAddRows(e){let t,n;e.position===`before`?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity),t=e.base,n=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,n)}getCellBorder({sheetId:e,col:t,row:n}){let r=this.borders[e]?.[t]?.[n];return r?.top||r?.bottom||r?.left||r?.right?b(r):null}getBordersColors(e){let t=[],n=this.borders[e];if(n){for(let e of n.filter(C))for(let n of e)if(n)for(let e of[`top`,`bottom`,`left`,`right`]){let r=n[e]?.color;r&&t.push(r)}}return t}ensureColumnBorderContinuity(e,t,n){let r=S(t+1,n);for(let i=0;i<this.getters.getNumberRows(e);i++){let a=this.getCellBorder({sheetId:e,col:t,row:i}),o=this.getCellBorder({sheetId:e,col:n,row:i});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,n,i,t)}}}ensureRowBorderContinuity(e,t,n){let r=S(t+1,n);for(let i=0;i<this.getters.getNumberCols(e);i++){let a=this.getCellBorder({sheetId:e,col:i,row:t}),o=this.getCellBorder({sheetId:e,col:i,row:n});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,i,n,t)}}}getCommonSides(e,t){let n={};for(let r of[`top`,`bottom`,`left`,`right`])e[r]&&w(e[r],t[r])&&(n[r]=e[r]);return n}getColumnsWithBorders(e){let t=this.borders[e];return t?Object.keys(t).map(e=>parseInt(e,10)):[]}getRowsWithBorders(e){let t=this.borders[e]?.filter(C);if(!t)return[];let n=new Set;for(let e of t)for(let t in e)n.add(parseInt(t,10));return Array.from(n)}getRowsRange(e){return this.borders[e]?S(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,n){this.borders[e]&&this.getColumnsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(t=>{this.moveBordersOfColumn(e,t,n)})}shiftBordersVertically(e,t,n){this.borders[e]&&(n<0&&this.moveBordersOfRow(e,t,n,{destructive:!1}),this.getRowsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(t=>{this.moveBordersOfRow(e,t,n)}))}moveBordersOfRow(e,t,n,{destructive:r}={destructive:!0}){let i=this.borders[e];i&&this.getColumnsWithBorders(e).forEach(a=>{let o=i[a]?.[t+n],s=i[a]?.[t];this.history.update(`borders`,e,a,t+n,r?s:s||o),this.history.update(`borders`,e,a,t,void 0)})}moveBordersOfColumn(e,t,n,{destructive:r}={destructive:!0}){let i=this.borders[e];i&&this.getRowsRange(e).forEach(a=>{let o=i[t+n]?.[a],s=i[t]?.[a];this.history.update(`borders`,e,t+n,a,r?s:s||o),r&&this.history.update(`borders`,e,t,a,void 0)})}setBorder(e,t,n,r,i=!0){let a=this.getters.getNumberCols(e)-1,o=this.getters.getNumberRows(e)-1;(i||!this.borders[e]?.[t]?.[n]?.left)&&(this.history.update(`borders`,e,t,n,`left`,r?.left),r?.left&&t>0&&!w(this.borders[e]?.[t-1]?.[n]?.right,r?.left)&&this.history.update(`borders`,e,t-1,n,`right`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.top)&&(this.history.update(`borders`,e,t,n,`top`,r?.top),r?.top&&n>0&&!w(this.borders[e]?.[t]?.[n-1]?.bottom,r?.top)&&this.history.update(`borders`,e,t,n-1,`bottom`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.right)&&(this.history.update(`borders`,e,t,n,`right`,r?.right),r?.right&&t<a&&!w(this.borders[e]?.[t+1]?.[n]?.left,r?.right)&&this.history.update(`borders`,e,t+1,n,`left`,void 0)),(i||!this.borders[e]?.[t]?.[n]?.bottom)&&(this.history.update(`borders`,e,t,n,`bottom`,r?.bottom),r?.bottom&&n<o&&!w(this.borders[e]?.[t]?.[n+1]?.top,r?.bottom)&&this.history.update(`borders`,e,t,n+1,`top`,void 0))}clearBorders(e,t,n=!1){let r=this.getters.getNumberCols(e)-1,i=this.getters.getNumberRows(e)-1;for(let a of ms(t))for(let t=a.top;t<=a.bottom;t++){n&&(a.left>0&&this.history.update(`borders`,e,a.left-1,t,`right`,void 0),a.right<r&&this.history.update(`borders`,e,a.right+1,t,`left`,void 0));for(let r=a.left;r<=a.right;r++)this.history.update(`borders`,e,r,t,void 0),n&&(a.top>0&&this.history.update(`borders`,e,r,a.top-1,`bottom`,void 0),a.bottom<i&&this.history.update(`borders`,e,r,a.bottom+1,`top`,void 0))}}clearInsideBorders(e,t){for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let r=n.left;r<=n.right;r++)this.history.update(`borders`,e,r,t,void 0)}addBorder(e,t,n,r){this.setBorder(e,t,n,{...this.getCellBorder({sheetId:e,col:t,row:n}),...r})}setBorders(e,t,n,r){if(n===`clear`)return this.clearBorders(e,t,!0);for(let i of ms(t)){if(n===`all`)for(let t=i.top;t<=i.bottom;t++)for(let n=i.left;n<=i.right;n++)this.addBorder(e,n,t,{top:r,right:r,bottom:r,left:r});if(n===`h`||n===`hv`){if(i.top===i.bottom)continue;for(let t=i.left;t<=i.right;t++){this.addBorder(e,t,i.top,{bottom:r});for(let n=i.top+1;n<i.bottom;n++)this.addBorder(e,t,n,{top:r,bottom:r});this.addBorder(e,t,i.bottom,{top:r})}}if(n===`v`||n===`hv`){if(i.left===i.right)continue;for(let t=i.top;t<=i.bottom;t++){this.addBorder(e,i.left,t,{right:r});for(let n=i.left+1;n<i.right;n++)this.addBorder(e,n,t,{left:r,right:r});this.addBorder(e,i.right,t,{left:r})}}if(n===`left`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.left,t,{left:r});if(n===`right`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.right,t,{right:r});if(n===`top`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.top,{top:r});if(n===`bottom`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.bottom,{bottom:r})}}addBordersToMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t,o=this.getCellBorder({sheetId:e,col:n,row:i}),s=this.getCellBorder({sheetId:e,col:r,row:a});this.clearBorders(e,[t]),o?.top&&this.setBorders(e,[{...t,bottom:i}],`top`,o.top),o?.left&&this.setBorders(e,[{...t,right:n}],`left`,o.left),s?.bottom?this.setBorders(e,[{...t,top:a}],`bottom`,s.bottom):o?.bottom&&this.setBorders(e,[{...t,top:a}],`bottom`,o.bottom),s?.right?this.setBorders(e,[{...t,left:r}],`right`,s.right):o?.right&&this.setBorders(e,[{...t,left:r}],`right`,o.right)}checkBordersUnchanged(e){let t=this.getCellBorder(e),n=!e.border?.bottom&&!e.border?.left&&!e.border?.right&&!e.border?.top;return!t&&n||w(t,e.border)?`NoChanges`:`Success`}import(e){if(Object.keys(e.borders||{}).length)for(let t of e.sheets)for(let[n,r]of gc(t.id,t.borders)){let{sheetId:t,col:i,row:a}=n,o=e.borders[r];this.setBorder(t,i,a,o,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,Ts(e))}export(e){let t={};for(let n of e.sheets){let e={};for(let r=0;r<n.colNumber;r++)for(let i=0;i<n.rowNumber;i++){let a=this.getCellBorder({sheetId:n.id,col:r,row:i});if(a){let o=mc(a,t),s={sheetId:n.id,col:r,row:i};e[o]??=[],e[o].push(s)}}n.borders=hc(e)}e.borders=t}exportForExcel(e){this.export(e)}},QU=class extends XU{static getters=[`zoneToXC`,`getCells`,`getTranslatedCellFormula`,`getCellStyle`,`getCellById`,`getFormulaString`,`getFormulaMovedInSheet`];nextId=1;cells={};adaptRanges({applyChange:e},t,n){for(let r of Object.keys(this.cells))for(let i of Object.values(this.cells[r]||{}))if(i.isFormula){for(let a of i.compiledFormula.dependencies)if(a.sheetId===t||a.invalidSheetName===n.old){let t=e(a);t.changeType!==`NONE`&&this.history.update(`cells`,r,i.id,`compiledFormula`,`dependencies`,i.compiledFormula.dependencies.indexOf(a),t.range)}}}allowDispatch(e){switch(e.type){case`UPDATE_CELL`:return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessUpdateCell);case`CLEAR_CELL`:return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessClearCell);case`UPDATE_CELL_POSITION`:return!e.cellId||this.cells[e.sheetId]?.[e.cellId]?`Success`:`InvalidCellId`;default:return`Success`}}handle(e){switch(e.type){case`SET_FORMATTING`:`style`in e&&this.setStyle(e.sheetId,e.target,e.style),`format`in e&&e.format!==void 0&&this.setFormatter(e.sheetId,e.target,e.format);break;case`CLEAR_FORMATTING`:this.clearFormatting(e.sheetId,e.target);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case`UPDATE_CELL`:this.updateCell(e.sheetId,e.col,e.row,e);break;case`CLEAR_CELL`:this.dispatch(`UPDATE_CELL`,{sheetId:e.sheetId,col:e.col,row:e.row,content:``,style:null,format:``});break;case`CLEAR_CELLS`:this.clearCells(e.sheetId,e.target);break;case`DELETE_CONTENT`:this.clearZones(e.sheetId,e.target);break;case`DELETE_SHEET`:this.history.update(`cells`,e.sheetId,void 0)}}clearZones(e,t){for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++){let n=this.getters.getCell({sheetId:e,col:t,row:r});(n?.isFormula||n?.content)&&this.dispatch(`UPDATE_CELL`,{sheetId:e,content:``,col:t,row:r})}}setFormatter(e,t,n){for(let r of ms(t))for(let t=r.top;t<=r.bottom;t++)for(let i=r.left;i<=r.right;i++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:i,row:t,format:n})}clearFormatting(e,t){for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,style:null,format:``})}clearCells(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:``,style:null,format:``})}handleAddColumnsRows(e,t){let n,r;e.position===`before`?(n=S(e.base,e.base+e.quantity),r=e.base+e.quantity):(n=S(e.base+1,e.base+e.quantity+1),r=e.base),t(e.sheetId,r,n)}import(e){for(let t of e.sheets){let n=t.id,r=new LF;for(let e in t.cells)if(t.cells[e]){let{col:n,row:i}=ir(e),a={sheetId:t.id,col:n,row:i};r.set(a,{content:t.cells[e]})}for(let[e,n]of[[`style`,t.styles],[`format`,t.formats]])for(let[i,a]of gc(t.id,n)){let t=r.get(i);t?t[e]=a:r.set(i,{[e]:a})}for(let i of r.keysForSheet(n)){let n=r.get(i);if(n?.content||n?.format||n?.style){let r=this.importCell(t.id,n?.content,n?.style?e.styles[n?.style]:void 0,n?.format?e.formats[n?.format]:void 0);this.history.update(`cells`,t.id,r.id,r),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:r.id,...i})}}}}export(e){let t={},n={};for(let r of e.sheets){let e=[],i=[],a={},o=Object.keys(this.cells[r.id]||{}).map(e=>this.getters.getCellPosition(e)).sort((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col);for(let r of o){let o=this.getters.getCell(r),s=T(r.col,r.row),c=this.extractCustomStyle(o);if(Object.keys(c).length){let n=mc(c,t);e[n]??=[],e[n].push(r)}if(o.format){let e=mc(o.format,n);i[e]??=[],i[e].push(r)}o.content&&(a[s]=o.content)}r.styles=hc(e),r.formats=hc(i),r.cells=a}e.styles=t,e.formats=n}importCell(e,t,n,r){let i=this.getNextUid();return this.createCell(i,t||``,r,n,e)}exportForExcel(e){this.export(e);let t=[];for(let n in e.formats||[])Qo(e.formats[n])||(t.push(Number(n)),delete e.formats[n]);if(t.length)for(let n of e.sheets)for(let e in n.formats){let r=n.formats[e];r&&t.includes(r)&&delete n.formats[e]}}extractCustomStyle(e){let t={...e.style},n=Hi(e.content,D)?Re:Le;for(let r in t)(r!==`align`||!e.isFormula)&&t[r]===n[r]&&delete t[r];return t}getCells(e){return this.cells[e]||{}}getCellById(e){let t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}getFormulaString(e,t,n,r=!1){if(!n.length)return Mt(t.map(e=>e.value));let i=0;return Mt(t.map(t=>{if(t.type===`REFERENCE`){let t=n[i++];return this.getters.getRangeString(t,e,{useBoundedReference:r})}return t.value}))}getTranslatedCellFormula(e,t,n,r){let i=this.getters.createAdaptedRanges(iC(r).dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t)),t,n,e);return this.getFormulaString(e,r,i)}getFormulaMovedInSheet(e,t,n){let r=iC(n).dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t)),i=this.getters.removeRangesSheetPrefix(t,r);return this.getFormulaString(t,n,i)}getCellStyle(e){return this.getters.getCell(e)?.style||{}}zoneToXC(e,t,n=[{colFixed:!1,rowFixed:!1}]){t=this.getters.expandZone(e,t);let r=T(t.left,t.top,n[0]),i=T(t.right,t.bottom,n.length>1?n[1]:n[0]),a=this.getters.getMainCellPosition({sheetId:e,col:t.left,row:t.top}),o=this.getters.getMainCellPosition({sheetId:e,col:t.right,row:t.bottom}),s=a.col===o.col&&a.row===o.row;return r!==i&&!s?r+`:`+i:r}setStyle(e,t,n){for(let r of ms(t))for(let t=r.left;t<=r.right;t++)for(let i=r.top;i<=r.bottom;i++){let r=this.getters.getCell({sheetId:e,col:t,row:i});this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:i,style:n?{...r?.style,...n}:void 0})}}copyColumnStyle(e,t,n){for(let r=0;r<this.getters.getNumberRows(e);r++){let i=this.getFormat(e,t,r);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,...i})}}copyRowStyle(e,t,n){for(let r=0;r<this.getters.getNumberCols(e);r++){let i=this.getFormat(e,r,t);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:r,row:t,...i})}}getFormat(e,t,n){let r={},i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.getters.getCell(i);return a&&(a.style&&(r.style=a.style),a.format&&(r.format=a.format)),r}getNextUid(){let e=this.nextId.toString();return this.history.update(`nextId`,this.nextId+1),e}updateCell(e,t,n,r){let i=this.getters.getCell({sheetId:e,col:t,row:n}),a=r.content!==void 0||`formula`in r,o=a?Wt(r?.content||void 0):i?.content||``,s;s=r.style===void 0?i?i.style:void 0:r.style||void 0;let c=r.format===void 0?i&&i.format:r.format;if((a&&!o&&!r.formula||!a&&(!i||i.content===``))&&!s&&!c){i&&(this.history.update(`cells`,e,i.id,void 0),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:void 0,col:t,row:n,sheetId:e}));return}let l=i?.id||this.getNextUid(),u=this.createCell(l,o,c,s,e);this.history.update(`cells`,e,u.id,u),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:u.id,col:t,row:n,sheetId:e})}createCell(e,t,n,r,i){return t.startsWith(`=`)?this.createFormulaCell(e,t,n,r,i):this.createLiteralCell(e,t,n,r)}createLiteralCell(e,t,n,r){let i=this.getters.getLocale(),a=ts(t,i);return n||=typeof a==`number`?Io(t,i)||Lo(t):void 0,!$o(n)&&!j(t)&&(t=N(a)),{id:e,content:t,style:r,format:n,isFormula:!1,parsedValue:a}}createFormulaCell(e,t,n,r,i){let a=rC(t);return a.dependencies.length?this.createFormulaCellWithDependencies(e,a,n,r,i):{id:e,content:t,style:r,format:n,isFormula:!0,compiledFormula:{...a,dependencies:[]}}}createFormulaCellWithDependencies(e,t,n,r,i){let a=[];for(let e of t.dependencies)a.push(this.getters.getRangeFromSheetXC(i,e));return new $U(e,t,n,r,a,i,this.getters.getRangeString)}checkCellOutOfSheet(e){let{sheetId:t,col:n,row:r}=e;return this.getters.tryGetSheet(t)?Vs(n,r,this.getters.getSheetZone(t))?`Success`:`TargetOutOfSheet`:`InvalidSheetId`}checkUselessClearCell(e){let t=this.getters.getCell(e);return!t||!t.content&&!t.style&&!t.format?`NoChanges`:`Success`}checkUselessUpdateCell(e){let t=this.getters.getCell(e),n=`content`in e||`formula`in e,r=`style`in e,i=`format`in e;return(!n||t?.content===e.content)&&(!r||w(t?.style,e.style))&&(!i||t?.format===e.format)?`NoChanges`:`Success`}},$U=class{id;format;style;sheetId;getRangeString;isFormula=!0;compiledFormula;constructor(e,t,n,r,i,a,o){this.id=e,this.format=n,this.style=r,this.sheetId=a,this.getRangeString=o;let s=0,c=t.tokens.map(e=>e.type===`REFERENCE`?new eW(i,s++,this.sheetId,this.getRangeString):e);this.compiledFormula={...t,dependencies:i,tokens:c}}get content(){return Mt(this.compiledFormula.tokens.map(e=>e.value))}get contentWithFixedReferences(){let e=0;return Mt(this.compiledFormula.tokens.map(t=>{if(t.type===`REFERENCE`){let t=e++;return this.getRangeString(this.compiledFormula.dependencies[t],this.sheetId,{useBoundedReference:!0})}return t.value}))}},eW=class{ranges;rangeIndex;sheetId;getRangeString;type=`REFERENCE`;constructor(e,t,n,r){this.ranges=e,this.rangeIndex=t,this.sheetId=n,this.getRangeString=r}get value(){let e=this.ranges[this.rangeIndex];return this.getRangeString(e,this.sheetId)}},tW=class extends XU{static getters=[`isChartDefined`,`getChartDefinition`,`getChartType`,`getChartIds`,`getChart`,`getFigureIdFromChartId`,`getContextCreationChart`];charts={};createChart=_O(this.getters);validateChartDefinition=e=>yO(this,e.definition);adaptRanges(e){for(let[t,n]of Object.entries(this.charts)){if(!n)continue;let r=n.chart.updateRanges(e);this.history.update(`charts`,t,r?{figureId:n.figureId,chart:r}:void 0)}}allowDispatch(e){switch(e.type){case`CREATE_CHART`:return this.checkValidations(e,this.chainValidations(this.checkFigureArguments,this.validateChartDefinition,this.checkChartDuplicate));case`UPDATE_CHART`:return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists,this.checkChartChanged));case`DELETE_CHART`:return this.checkChartExists(e);default:return`Success`}}handle(e){switch(e.type){case`CREATE_CHART`:let{col:t,row:n,offset:r,size:i,sheetId:a,figureId:o}=e;!this.getters.getFigure(a,o)&&r!==void 0&&t!==void 0&&n!==void 0&&this.addFigure(o,a,t,n,r,i),this.addChart(e.figureId,e.chartId,e.definition);break;case`UPDATE_CHART`:this.addChart(e.figureId,e.chartId,e.definition);break;case`DUPLICATE_SHEET`:for(let t of this.getChartIds(e.sheetId)){let{chart:n,figureId:r}=this.charts[t]||{};if(!n||!r)continue;let i=this.getters.getFigure(e.sheetId,r);if(!i)continue;let a=r.split(`??`).pop(),o=`${e.sheetIdTo}??${a}`,s=t.split(`??`).pop(),c=`${e.sheetIdTo}??${s}`,l=n.duplicateInDuplicatedSheet(e.sheetIdTo);l&&this.dispatch(`CREATE_CHART`,{figureId:o,chartId:c,col:i.col,row:i.row,offset:i.offset,size:{width:i.width,height:i.height},definition:l.getDefinition(),sheetId:e.sheetIdTo})}break;case`DELETE_FIGURE`:for(let t in this.charts)this.charts[t]?.figureId===e.figureId&&this.dispatch(`DELETE_CHART`,{chartId:t,sheetId:e.sheetId});break;case`DELETE_CHART`:this.isChartDefined(e.chartId)&&this.history.update(`charts`,e.chartId,void 0);break;case`DELETE_SHEET`:for(let t of this.getChartIds(e.sheetId))this.history.update(`charts`,t,void 0);break}}getContextCreationChart(e){return this.charts[e]?.chart.getContextCreation()}getChart(e){return this.charts[e]?.chart}getFigureIdFromChartId(e){if(!this.charts[e])throw Error(`Chart with id ${e} does not exist.`);return this.charts[e].figureId}getChartType(e){let t=this.charts[e]?.chart.type;if(!t)throw Error(`Chart not defined.`);return t}isChartDefined(e){return e in this.charts&&this.charts!==void 0}getChartIds(e){return Object.entries(this.charts).filter(([,t])=>t?.chart.sheetId===e).map(([e])=>e)}getChartDefinition(e){let t=this.charts[e]?.chart.getDefinition();if(!t)throw Error(`There is no chart with the given id: ${e}`);return t}import(e){for(let t of e.sheets)if(t.figures){for(let e of t.figures)if(e.tag===`chart`){let n=e.data.chartId,r=this.createChart(e.id,e.data,t.id);this.charts[n]={chart:r,figureId:e.id}}else if(e.tag===`carousel`)for(let n in e.data.chartDefinitions||{}){let r=e.data.chartDefinitions[n],i=this.createChart(e.id,r,t.id);this.charts[n]={chart:i,figureId:e.id}}}}export(e){if(e.sheets)for(let t of e.sheets){let e=this.getters.getFigures(t.id),n=[];for(let t of e){let e=t,r=Object.keys(this.charts).find(e=>this.charts[e]?.figureId===t.id);if(e&&e.tag===`chart`&&r){let t=this.charts[r]?.chart.getDefinition();t&&(e.data={...t,chartId:r},n.push(e))}else if(e&&e.tag===`carousel`){let r=Object.keys(this.charts).filter(e=>this.charts[e]?.figureId===t.id),i={};for(let e of r)i[e]=this.charts[e]?.chart.getDefinition();e.data={chartDefinitions:i},n.push(e)}else n.push(e)}t.figures=n}}addFigure(e,t,n,r,i,a={width:536,height:335}){this.dispatch(`CREATE_FIGURE`,{sheetId:t,figureId:e,col:n,row:r,offset:i,size:a,tag:`chart`})}addChart(e,t,n){let r=this.getters.getFigureSheetId(e);if(r){let i=this.createChart(e,n,r);this.history.update(`charts`,t,{figureId:e,chart:i})}}checkChartDuplicate(e){return this.isChartDefined(e.chartId)?`DuplicatedChartId`:`Success`}checkChartExists(e){return this.isChartDefined(e.chartId)?`Success`:`ChartDoesNotExist`}checkChartChanged(e){return e.figureId===this.charts[e.chartId]?.figureId&&w(this.getChartDefinition(e.chartId),e.definition)?`NoChanges`:`Success`}checkFigureArguments(e){return this.getters.getFigure(e.sheetId,e.figureId)||e.offset!==void 0&&e.col!==void 0&&e.row!==void 0?`Success`:`MissingFigureArguments`}};function nW(e){return e===``?NaN:Number(e)}var rW=class extends XU{static getters=[`getConditionalFormats`,`getRulesSelection`,`getRulesByCell`,`getAdaptedCfRanges`];cfRules={};adaptCFFormulas({applyChange:e,adaptFormulaString:t}){for(let n in this.cfRules)for(let r of this.cfRules[n])if(r.rule.type===`DataBarRule`&&r.rule.rangeValues){let t=e(r.rule.rangeValues);switch(t.changeType){case`REMOVE`:this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`rangeValues`,void 0);break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`rangeValues`,t.range);break}}else if(r.rule.type===`CellIsRule`)for(let e=0;e<r.rule.values.length;e++)this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,`values`,e,t(n,r.rule.values[e]));else if(r.rule.type===`IconSetRule`)for(let e of[`lowerInflectionPoint`,`upperInflectionPoint`])r.rule[e].type===`formula`&&this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,e,`value`,t(n,r.rule[e].value));else if(r.rule.type===`ColorScaleRule`)for(let e of[`minimum`,`maximum`,`midpoint`]){let i=r.rule[e];i?.type===`formula`&&i?.value&&this.history.update(`cfRules`,n,this.cfRules[n].indexOf(r),`rule`,e,`value`,t(n,i.value))}}adaptCFRanges(e,{applyChange:t}){for(let n of this.cfRules[e])for(let r of n.ranges){let i=t(r);switch(i.changeType){case`REMOVE`:let t=n.ranges.slice();t.splice(n.ranges.indexOf(r),1),t.length>=1?this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,t):this.removeConditionalFormatting(n.id,e);break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,n.ranges.indexOf(r),i.range);break}}}adaptRanges(e,t){let n=t?[t]:Object.keys(this.cfRules);for(let t of n)this.adaptCFRanges(t,e);this.adaptCFFormulas(e)}allowDispatch(e){switch(e.type){case`ADD_CONDITIONAL_FORMAT`:return e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkValidations(e,this.checkCFRule,this.checkEmptyRange,this.checkCFHasChanged);case`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:return this.checkValidPriorityChange(e.cfId,e.delta,e.sheetId)}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.cfRules[e.sheetId]=[];break;case`DUPLICATE_SHEET`:this.history.update(`cfRules`,e.sheetIdTo,[]);for(let t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case`DELETE_SHEET`:let t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update(`cfRules`,t);break;case`ADD_CONDITIONAL_FORMAT`:let n={...e.cf,ranges:e.ranges.map(t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId))};this.addConditionalFormatting(n,e.sheetId);break;case`REMOVE_CONDITIONAL_FORMAT`:this.removeConditionalFormatting(e.id,e.sheetId);break;case`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:this.changeCFPriority(e.cfId,e.delta,e.sheetId);break}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map(e=>this.mapToConditionalFormatInternal(t.id,e))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map(e=>this.mapToConditionalFormat(t.id,e)))}exportForExcel(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map(e=>this.mapToConditionalFormat(t.id,e,{useBoundedReference:!0})))}getConditionalFormats(e){return this.cfRules[e]?.map(t=>this.mapToConditionalFormat(e,t))||[]}getRulesSelection(e,t){let n=new Set;return t.forEach(t=>{this.getRulesByZone(e,t).forEach(e=>{n.add(e)})}),Array.from(n)}getRulesByZone(e,t){let n=new Set;for(let r=t.top;r<=t.bottom;r++)for(let i=t.left;i<=t.right;i++)this.getRulesByCell(e,i,r).forEach(e=>{n.add(e.id)});return n}getRulesByCell(e,t,n){let r=[];for(let i of this.cfRules[e])for(let e of i.ranges)Vs(t,n,e.zone)&&r.push(i);return new Set(r.map(t=>this.mapToConditionalFormat(e,t)))}getAdaptedCfRanges(e,t,n,r){if(n.length===0&&r.length===0)return;let i=this.getters.getConditionalFormats(e),a=i.findIndex(e=>e.id===t.id),o=[];a>-1&&(o=i[a].ranges.map(ws));let s=ms(o,r);return ms([...n,...s],[]).map(t=>this.getters.getRangeDataFromZone(e,t))}mapToConditionalFormat(e,t,{useBoundedReference:n}={useBoundedReference:!1}){let r=t.ranges.map(t=>this.getters.getRangeString(t,e,{useBoundedReference:n}));return t.rule.type===`DataBarRule`?{...t,rule:{...t.rule,rangeValues:t.rule.rangeValues&&this.getters.getRangeString(t.rule.rangeValues,e,{useBoundedReference:n})},ranges:r}:{...t,rule:{...t.rule},ranges:r}}mapToConditionalFormatInternal(e,t){let n=t.ranges.map(t=>this.getters.getRangeFromSheetXC(e,t));return t.rule.type===`DataBarRule`?{...t,rule:{...t.rule,rangeValues:t.rule.rangeValues?this.getters.getRangeFromSheetXC(e,t.rule.rangeValues):void 0},ranges:n}:{...t,rule:{...t.rule},ranges:n}}addConditionalFormatting(e,t){let n=this.cfRules[t].slice(),r=n.findIndex(t=>t.id===e.id),i=this.mapToConditionalFormatInternal(t,e);r>-1?n.splice(r,1,i):n.push(i),this.history.update(`cfRules`,t,n)}checkValidPriorityChange(e,t,n){if(!this.cfRules[n])return`InvalidSheetId`;let r=this.cfRules[n].findIndex(t=>t.id===e);if(r===-1)return`InvalidConditionalFormatId`;let i=r-t;return i<0||i>=this.cfRules[n].length?`InvalidConditionalFormatId`:`Success`}checkEmptyRange(e){return e.ranges.length?`Success`:`EmptyRange`}checkCFRule(e){let t=e.cf.rule;switch(t.type){case`CellIsRule`:return Mr.has(t.operator)?this.checkValidations(t,this.checkOperatorArgsNumber,this.checkCFValues):`InvalidConditionalFormatType`;case`ColorScaleRule`:return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case`IconSetRule`:return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)));case`DataBarRule`:return`Success`}return`InvalidConditionalFormatType`}checkCFHasChanged(e){let t=this.mapToConditionalFormatInternal(e.sheetId,{...e.cf,ranges:e.ranges.map(t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId))}),n=this.cfRules[e.sheetId]?.find(t=>t.id===e.cf.id);return n&&w(t,n)?`NoChanges`:`Success`}checkOperatorArgsNumber(e){let t=Y.get(e.operator).numberOfValues({type:e.operator,values:e.values});if(t===void 0||t>2)throw Error(`Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.`);let n=[],r=e=>e===void 0||e===``;return t>=1&&r(e.values[0])&&n.push(`FirstArgMissing`),t>=2&&r(e.values[1])&&n.push(`SecondArgMissing`),n.length?n:`Success`}checkNaN(e,t){if([`number`,`percentage`,`percentile`].includes(e.type)&&(e.value===``||isNaN(e.value)))switch(t){case`min`:return`MinNaN`;case`max`:return`MaxNaN`;case`mid`:return`MidNaN`;case`upperInflectionPoint`:return`ValueUpperInflectionNaN`;case`lowerInflectionPoint`:return`ValueLowerInflectionNaN`}return`Success`}checkFormulaCompilation(e,t){if(e.type!==`formula`)return`Success`;if(rC(e.value||``).isBadExpression)switch(t){case`min`:return`MinInvalidFormula`;case`max`:return`MaxInvalidFormula`;case`mid`:return`MidInvalidFormula`;case`upperInflectionPoint`:return`ValueUpperInvalidFormula`;case`lowerInflectionPoint`:return`ValueLowerInvalidFormula`}return`Success`}checkThresholds(e){return this.batchValidations(t=>e(t.minimum,`min`),t=>e(t.maximum,`max`),t=>t.midpoint?e(t.midpoint,`mid`):`Success`)}checkInflectionPoints(e){return this.batchValidations(t=>e(t.lowerInflectionPoint,`lowerInflectionPoint`),t=>e(t.upperInflectionPoint,`upperInflectionPoint`))}checkLowerBiggerThanUpper(e){let t=e.lowerInflectionPoint.value,n=e.upperInflectionPoint.value;return[`number`,`percentage`,`percentile`].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(n)?`LowerBiggerThanUpper`:`Success`}checkMinBiggerThanMax(e){let t=e.minimum.value,n=e.maximum.value;return[`number`,`percentage`,`percentile`].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&nW(t)>=nW(n)?`MinBiggerThanMax`:`Success`}checkMidBiggerThanMax(e){let t=e.midpoint?.value,n=e.maximum.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&nW(t)>=nW(n)?`MidBiggerThanMax`:`Success`}checkMinBiggerThanMid(e){let t=e.minimum.value,n=e.midpoint?.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&nW(t)>=nW(n)?`MinBiggerThanMid`:`Success`}checkCFValues(e){for(let t of e.values)if(t.startsWith(`=`)&&rC(t||``).isBadExpression)return`ValueCellIsInvalidFormula`;return`Success`}removeConditionalFormatting(e,t){let n=this.cfRules[t].findIndex(t=>t.id===e);if(n!==-1){let e=this.cfRules[t].slice();e.splice(n,1),this.history.update(`cfRules`,t,e)}}changeCFPriority(e,t,n){let r=this.cfRules[n].findIndex(t=>t.id===e),i=this.cfRules[n][r],a=r-t,o=[...this.cfRules[n]];o.splice(r,1),o.splice(a,0,i),this.history.update(`cfRules`,n,o)}},iW=class extends XU{static getters=[`cellHasListDataValidationIcon`,`getDataValidationRule`,`getDataValidationRules`,`getValidationRuleForCell`];rules={};adaptRanges(e,t){this.adaptDVRanges(t,e),this.adaptDVFormulas(e)}adaptDVFormulas({adaptFormulaString:e}){for(let t in this.rules){let n=this.rules[t];for(let r=n.length-1;r>=0;r--){let n=this.rules[t][r];for(let i=0;i<n.criterion.values.length;i++){let a=e(t,n.criterion.values[i]);this.history.update(`rules`,t,r,`criterion`,`values`,i,a)}}}}adaptDVRanges(e,{applyChange:t}){let n=this.rules[e];for(let r=n.length-1;r>=0;r--){let n=this.rules[e][r];for(let i=n.ranges.length-1;i>=0;i--){let a=n.ranges[i],o=t(a);switch(o.changeType){case`REMOVE`:if(n.ranges.length===1)this.removeDataValidationRule(e,n.id);else{let t=n.ranges.slice();t.splice(i,1),this.history.update(`rules`,e,r,`ranges`,t)}break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`rules`,e,r,`ranges`,i,o.range);break}}}}allowDispatch(e){switch(e.type){case`ADD_DATA_VALIDATION_RULE`:return!this.getters.tryGetSheet(e.sheetId)||e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkValidations(e,this.chainValidations(this.checkEmptyRange,this.checkValidRange,this.checkCriterionTypeIsValid,this.checkCriterionHasValidNumberOfValues,this.checkCriterionValuesAreValid));case`REMOVE_DATA_VALIDATION_RULE`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;if(!this.rules[e.sheetId].find(t=>t.id===e.id))return`UnknownDataValidationRule`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`rules`,e.sheetId,[]);break;case`DUPLICATE_SHEET`:{let t=b(this.rules[e.sheetId]).map(t=>({...t,ranges:t.ranges.map(t=>zc(e.sheetId,e.sheetIdTo,t))}));this.history.update(`rules`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.rules};delete t[e.sheetId],this.history.update(`rules`,t);break}case`REMOVE_DATA_VALIDATION_RULE`:this.removeDataValidationRule(e.sheetId,e.id);break;case`ADD_DATA_VALIDATION_RULE`:{let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e));this.addDataValidationRule(e.sheetId,{...e.rule,ranges:t});break}case`DELETE_CONTENT`:{let t=ms(e.target),n=e.sheetId;for(let e of t)for(let t=e.top;t<=e.bottom;t++)for(let r=e.left;r<=e.right;r++){let e=this.getValidationRuleForCell({sheetId:n,col:r,row:t});if(e&&(e.criterion.type===`isBoolean`||e.criterion.type===`isValueInList`&&!this.getters.getCell({sheetId:n,col:r,row:t})?.content)){let e=this.rules[n],i=[this.getters.getRangeFromSheetXC(n,T(r,t))],a=this.removeRangesFromRules(n,i,e);this.history.update(`rules`,n,a)}}}}}getDataValidationRules(e){return this.rules[e]}getDataValidationRule(e,t){return this.rules[e].find(e=>e.id===t)}getValidationRuleForCell({sheetId:e,col:t,row:n}){if(this.rules[e]){for(let r of this.rules[e])for(let e of r.ranges)if(Vs(t,n,e.zone))return r}}cellHasListDataValidationIcon(e){let t=this.getValidationRuleForCell(e);return t?(t.criterion.type===`isValueInList`||t.criterion.type===`isValueInRange`)&&(t.criterion.displayStyle===`arrow`||t.criterion.displayStyle===`chip`):!1}addDataValidationRule(e,t){let n=this.rules[e];t.criterion.type===`isBoolean`?this.setCenterStyleToBooleanCells(t):t.criterion.type===`isValueInList`&&(t.criterion.values=Array.from(new Set(t.criterion.values)));let r=this.removeRangesFromRules(e,t.ranges,n,t.id),i=r.findIndex(e=>e.id===t.id);i===-1?this.history.update(`rules`,e,[...r,t]):(r[i]=t,this.history.update(`rules`,e,r))}removeRangesFromRules(e,t,n,r){n=b(n);for(let e of n)e.id!==r&&(e.ranges=this.getters.recomputeRanges(e.ranges,t));return n.filter(e=>e.ranges.length>0)}removeDataValidationRule(e,t){let n=this.rules[e].filter(e=>e.id!==t);this.history.update(`rules`,e,n)}setCenterStyleToBooleanCells(e){for(let t of Vc(e.ranges)){let e=this.getters.getCell(t),n={...e?.style,align:e?.style?.align??`center`,verticalAlign:e?.style?.verticalAlign??`middle`};this.dispatch(`UPDATE_CELL`,{...t,style:n})}}checkEmptyRange(e){return e.ranges.length?`Success`:`EmptyRange`}import(e){for(let t of e.sheets)if(this.rules[t.id]=[],t.dataValidationRules)for(let e of t.dataValidationRules)this.rules[t.id].push({...e,ranges:e.ranges.map(e=>this.getters.getRangeFromSheetXC(t.id,e))})}export(e){if(e.sheets)for(let t of e.sheets){t.dataValidationRules=[];for(let e of this.rules[t.id])t.dataValidationRules.push({...e,ranges:e.ranges.map(e=>this.getters.getRangeString(e,t.id))})}}exportForExcel(e){if(e.sheets)for(let t of e.sheets){t.dataValidationRules=[];for(let e of this.rules[t.id]){let n={...b(e),ranges:e.ranges.map(e=>this.getters.getRangeString(e,t.id,{useBoundedReference:!0}))};e.criterion.type===`isValueInRange`&&(n.criterion.values=e.criterion.values.map(e=>{let n=this.getters.getRangeFromSheetXC(t.id,e);return this.getters.getRangeString(n,t.id,{useBoundedReference:!0,useFixedReference:!0})})),t.dataValidationRules.push(n)}}}checkCriterionTypeIsValid(e){return Y.contains(e.rule.criterion.type)?`Success`:`UnknownDataValidationCriterionType`}checkCriterionHasValidNumberOfValues(e){let t=e.rule.criterion,n=Y.get(t.type).numberOfValues(t);return n!==void 0&&t.values.length!==n?`InvalidNumberOfCriterionValues`:`Success`}checkCriterionValuesAreValid(e){let t=e.rule.criterion,n=Y.get(t.type);return t.values.some(e=>n.allowedValues===`onlyFormulas`&&!e.startsWith(`=`)?!0:e.startsWith(`=`)?n.allowedValues===`onlyLiterals`||rC(e).isBadExpression:!n.isCriterionValueValid(e))?`InvalidDataValidationCriterionValue`:`Success`}checkValidRange(e){return e.ranges.map(e=>this.getters.getRangeFromRangeData(e)).map(t=>this.getters.getRangeString(t,e.sheetId)).some(e=>!this.getters.isRangeValid(e))?`InvalidRange`:`Success`}},aW=class extends XU{static getters=[`getFigures`,`getFigure`,`getFigureSheetId`];figures={};insertionOrders=[];adaptRanges({applyChange:e},t){for(let n of this.getFigures(t)){let r=e(this.getters.getRangeFromZone(t,{left:n.col,right:n.col,top:n.row,bottom:n.row}));if(r.changeType===`MOVE`)this.history.update(`figures`,t,n.id,`col`,r.range.zone.right),this.history.update(`figures`,t,n.id,`row`,r.range.zone.bottom);else if(r.changeType===`REMOVE`){let r=e(this.getters.getRangeFromZone(t,{left:0,right:n.col-1,top:0,bottom:n.row-1})),{offset:i,col:a,row:o}=n;r.changeType!==`NONE`&&(a=r.range.zone.right+1,o=r.range.zone.bottom+1),{offset:i,col:a,row:o}=this.getPositionInSheet(t,{...n,col:a,row:o}),this.history.update(`figures`,t,n.id,`offset`,i),this.history.update(`figures`,t,n.id,`col`,a),this.history.update(`figures`,t,n.id,`row`,o)}}}allowDispatch(e){switch(e.type){case`CREATE_FIGURE`:return this.checkValidations(e,this.checkFigureDuplicate,this.checkFigureAnchorOffset);case`UPDATE_FIGURE`:return this.checkValidations(e,this.checkFigureExists,this.checkFigureAnchorOffset);case`DELETE_FIGURE`:return this.checkFigureExists(e);default:return`Success`}}beforeHandle(e){switch(e.type){case`DELETE_SHEET`:this.getters.getFigures(e.sheetId).forEach(t=>{this.dispatch(`DELETE_FIGURE`,{figureId:t.id,sheetId:e.sheetId})});break}}handle(e){switch(e.type){case`CREATE_SHEET`:this.figures[e.sheetId]={};break;case`DELETE_SHEET`:this.deleteSheet(e.sheetId);break;case`CREATE_FIGURE`:let t={id:e.figureId,col:e.col,row:e.row,offset:e.offset,width:e.size.width,height:e.size.height,tag:e.tag};this.addFigure(t,e.sheetId);break;case`UPDATE_FIGURE`:this.updateFigure(e);break;case`DELETE_FIGURE`:this.removeFigure(e.figureId,e.sheetId);break;case`REMOVE_COLUMNS_ROWS`:e.dimension===`COL`?this.onColRemove(e.sheetId):this.onRowRemove(e.sheetId);break;case`DUPLICATE_SHEET`:for(let t of this.getFigures(e.sheetId)){let n=t.id,r=this.figures[e.sheetId]?.[n];if(!r)continue;let i=n.split(`??`).pop(),a=`${e.sheetIdTo}??${i}`;this.dispatch(`CREATE_FIGURE`,{figureId:a,...r,size:{width:r.width,height:r.height},sheetId:e.sheetIdTo})}break}}onColRemove(e){let t=this.getters.getNumberCols(e),n=Array(t+1);n[t]=0;for(let r=t-1;r>=0;r--)n[r]=n[r+1]+this.getters.getColSize(e,r);for(let t of this.getFigures(e))if(t.offset.x+t.width>n[t.col]){let r=t.offset.x,i=t.col;for(r=Math.min(r,n[i]-t.width);r<0&&i>0;)i--,r=n[i]-t.width;r!==t.offset.x&&this.history.update(`figures`,e,t.id,`offset`,{x:Math.max(r,0),y:t.offset.y}),i!==t.col&&this.history.update(`figures`,e,t.id,`col`,i)}}onRowRemove(e){let t=this.getters.getNumberRows(e),n=Array(t+1);n[t]=0;for(let r=t-1;r>=0;r--)n[r]=n[r+1]+(this.getters.getUserRowSize(e,r)??23);for(let t of this.getFigures(e))if(t.offset.y+t.height>n[t.row]){let r=t.offset.y,i=t.row;for(let t=this.getters.getUserRowSize(e,i)??23;t<r;t=this.getters.getUserRowSize(e,i)??23)i+=1,r-=t;for(r=Math.min(r,n[i]-t.height);r<0&&i>0;)i--,r=n[i]-t.height;r!==t.offset.y&&this.history.update(`figures`,e,t.id,`offset`,{x:t.offset.x,y:Math.max(0,r)}),i!==t.row&&this.history.update(`figures`,e,t.id,`row`,i)}else t.offset.y+t.height>n[0]&&this.history.update(`figures`,e,t.id,`offset`,{x:t.offset.x,y:Math.max(n[0]-t.height,0)})}getPositionInSheet(e,t){let{numberOfRows:n,numberOfCols:r}=this.getters.getSheetSize(e),i=0,a=0,o,s,{col:c,row:l}=t,u={...t.offset};for(o=n;i<t.height&&o>0;o--)i+=this.getters.getUserRowSize(e,o-1)??23;for(l>o?(l=o,u.y=Math.max(i-t.height,0)):l===o&&(u.y=x(u.y,0,Math.max(i-t.height,0))),s=r;a<t.width&&s>0;s--)a+=this.getters.getColSize(e,s-1);return c>s?(c=s,u.x=Math.max(a-t.width,0)):s===c&&(u.x=x(u.x,0,Math.max(a-t.width,0))),{col:c,row:l,offset:u}}updateFigure(e){if(!(`figureId`in e)||!(`sheetId`in e))return;let{figureId:t,sheetId:n,...r}=e,i={...this.getFigure(n,t),...r};for(let[e,t]of Object.entries(r))switch(e){case`tag`:this.history.update(`figures`,n,i.id,e,t);break;case`offset`:this.history.update(`figures`,n,i.id,e,t);break;case`col`:case`row`:case`width`:case`height`:t!==void 0&&this.history.update(`figures`,n,i.id,e,t);break}}addFigure(e,t){this.history.update(`figures`,t,e.id,e),this.history.update(`insertionOrders`,this.insertionOrders.length,e.id)}deleteSheet(e){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>!this.figures[e]?.[t])),this.history.update(`figures`,e,void 0)}removeFigure(e,t){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>t!==e)),this.history.update(`figures`,t,e,void 0)}checkFigureExists(e){return this.figures[e.sheetId]?.[e.figureId]===void 0?`FigureDoesNotExist`:`Success`}checkFigureDuplicate(e){return Object.values(this.figures).find(t=>t?.[e.figureId])?`DuplicatedFigureId`:`Success`}checkFigureAnchorOffset(e){return e.col<0||e.row<0||e.offset&&(e.offset.x<0||e.offset.y<0)?`WrongSheetPosition`:`Success`}getFigures(e){let t=[];for(let n of this.insertionOrders){let r=this.figures[e]?.[n];r&&t.push(r)}return t}getFigure(e,t){return this.figures[e]?.[t]}getFigureSheetId(e){return Object.keys(this.figures).find(t=>this.figures[t]?.[e]!==void 0)}import(e){for(let t of e.sheets)for(let e of t.figures)this.addFigure(e,t.id)}export(e){for(let t of e.sheets)for(let e of this.getFigures(t.id))t.figures.push({...e,data:void 0})}exportForExcel(e){return this.export(e)}},oW=class extends XU{static getters=[`getUserRowSize`,`getColSize`];sizes={};handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`sizes`,e.sheetId,{COL:Array(this.getters.getNumberCols(e.sheetId)).fill(void 0),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(void 0)});break;case`DUPLICATE_SHEET`:this.history.update(`sizes`,e.sheetIdTo,b(this.sizes[e.sheetId]));break;case`DELETE_SHEET`:let t={...this.sizes};delete t[e.sheetId],this.history.update(`sizes`,t);break;case`REMOVE_COLUMNS_ROWS`:{let t=this.sizes[e.sheetId][e.dimension],n=qt(t,e.elements);this.history.update(`sizes`,e.sheetId,e.dimension,n);break}case`ADD_COLUMNS_ROWS`:{let t=this.sizes[e.sheetId][e.dimension],n=Ft(e.position,e.base),r=t[e.base],i=Jt(t,Array(e.quantity).fill(r),n);this.history.update(`sizes`,e.sheetId,e.dimension,i);break}case`RESIZE_COLUMNS_ROWS`:if(e.dimension===`ROW`)for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);else for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);break}}getColSize(e,t){return Math.round(this.sizes[e]?.COL[t]||96)}getUserRowSize(e,t){let n=this.sizes[e]?.ROW[t];return n?Math.round(n):void 0}import(e){for(let t of e.sheets){let e={COL:Array(t.colNumber).fill(void 0),ROW:Array(t.rowNumber).fill(void 0)};for(let[n,r]of Object.entries(t.rows))r.size&&(e.ROW[n]=r.size);for(let[n,r]of Object.entries(t.cols))r.size&&(e.COL[n]=r.size);this.sizes[t.id]=e}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e of S(0,this.getters.getNumberRows(n.id)))(t||this.sizes[n.id].ROW[e])&&(n.rows[e]={...n.rows[e],size:this.getUserRowSize(n.id,e)??23});n.cols===void 0&&(n.cols={});for(let e of S(0,this.getters.getNumberCols(n.id)))(t||this.sizes[n.id].COL[e])&&(n.cols[e]={...n.cols[e],size:this.getColSize(n.id,e)})}}},sW=class extends XU{static getters=[`checkElementsIncludeAllVisibleHeaders`,`getHiddenColsGroups`,`getHiddenRowsGroups`,`isHeaderHiddenByUser`,`isRowHiddenByUser`,`isColHiddenByUser`];hiddenHeaders={};allowDispatch(e){switch(e.type){case`HIDE_COLUMNS_ROWS`:{if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=e.dimension===`COL`?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),n=e.dimension===`COL`?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=n?`TooManyHiddenElements`:en(e.elements)<0||$t(e.elements)>n?`InvalidHeaderIndex`:`Success`}case`REMOVE_COLUMNS_ROWS`:return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`:`InvalidSheetId`}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:let t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update(`hiddenHeaders`,e.sheetId,t);break;case`DUPLICATE_SHEET`:this.history.update(`hiddenHeaders`,e.sheetIdTo,b(this.hiddenHeaders[e.sheetId]));break;case`DELETE_SHEET`:this.history.update(`hiddenHeaders`,e.sheetId,void 0);break;case`REMOVE_COLUMNS_ROWS`:{let t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let n of[...e.elements].sort((e,t)=>t-e))t.splice(n,1);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t);break}case`ADD_COLUMNS_ROWS`:{let t=Ft(e.position,e.base),n=Jt([...this.hiddenHeaders[e.sheetId][e.dimension]],Array(e.quantity).fill(!1),t);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,n);break}case`HIDE_COLUMNS_ROWS`:for(let t of e.elements)this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t,!0);break;case`UNHIDE_COLUMNS_ROWS`:for(let t of e.elements)this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t,!1);break}}checkElementsIncludeAllVisibleHeaders(e,t,n){return Rt(n,this.getAllVisibleHeaders(e,t))}isHeaderHiddenByUser(e,t,n){return t===`COL`?this.isColHiddenByUser(e,n):this.isRowHiddenByUser(e,n)}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]||this.getters.isRowFolded(e,t)}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]||this.getters.isColFolded(e,t)}getHiddenColsGroups(e){let t=[[]],n=this.hiddenHeaders[e].COL;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getHiddenRowsGroups(e){let t=[[]],n=this.hiddenHeaders[e].ROW;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getAllVisibleHeaders(e,t){let n=S(0,this.getters.getNumberHeaders(e,t)),r=[];return this.getters.getHeaderGroups(e,t).forEach(e=>{e.isFolded&&r.push(...S(e.start,e.end+1))}),n.filter(n=>!this.hiddenHeaders[e][t][n]&&!r.includes(n))}import(e){for(let t of e.sheets){this.hiddenHeaders[t.id]={COL:[],ROW:[]};for(let e=0;e<t.rowNumber;e++)this.hiddenHeaders[t.id].ROW[e]=!!t.rows[e]?.isHidden;for(let e=0;e<t.colNumber;e++)this.hiddenHeaders[t.id].COL[e]=!!t.cols[e]?.isHidden}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e=0;e<this.getters.getNumberRows(n.id);e++)(t||this.hiddenHeaders[n.id].ROW[e])&&(n.rows[e]===void 0&&(n.rows[e]={}),n.rows[e].isHidden||=this.hiddenHeaders[n.id].ROW[e]);n.cols===void 0&&(n.cols={});for(let e=0;e<this.getters.getNumberCols(n.id);e++)(t||this.hiddenHeaders[n.id].COL[e])&&(n.cols[e]===void 0&&(n.cols[e]={}),n.cols[e].isHidden||=this.hiddenHeaders[n.id].COL[e])}}},cW=class extends XU{static getters=[`getImage`,`getImagePath`,`getImageSize`];fileStore;images={};syncedImages=new Set;constructor(e){super(e),this.fileStore=e.external.fileStore}allowDispatch(e){switch(e.type){case`CREATE_IMAGE`:return this.getters.getFigure(e.sheetId,e.figureId)?`InvalidFigureId`:`Success`;default:return`Success`}}handle(e){switch(e.type){case`CREATE_IMAGE`:this.getters.getFigure(e.sheetId,e.figureId)||this.addFigure(e.figureId,e.sheetId,e.col,e.row,e.offset,e.size),this.history.update(`images`,e.sheetId,e.figureId,e.definition),this.syncedImages.add(e.definition.path);break;case`DUPLICATE_SHEET`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`image`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.getImage(n.id);if(i){let t={width:n.width,height:n.height};this.dispatch(`CREATE_IMAGE`,{sheetId:e.sheetIdTo,figureId:r,offset:n.offset,col:n.col,row:n.row,size:t,definition:b(i)})}}break}case`DELETE_FIGURE`:this.history.update(`images`,e.sheetId,e.figureId,void 0);break;case`DELETE_SHEET`:this.history.update(`images`,e.sheetId,void 0);break}}garbageCollectExternalResources(){let e=new Set(this.getAllImages().map(e=>e.path));for(let t of this.syncedImages)e.has(t)||this.fileStore?.delete(t)}getImage(e){for(let t of Object.values(this.images))if(t&&t[e])return t[e];throw Error(`There is no image with the given figureId: ${e}`)}getImagePath(e){return this.getImage(e).path}getImageSize(e){return this.getImage(e).size}addFigure(e,t,n,r,i,a){this.dispatch(`CREATE_FIGURE`,{sheetId:t,figureId:e,col:n,row:r,offset:i,size:a,tag:`image`})}import(e){for(let t of e.sheets){let e=(t.figures||[]).filter(e=>e.tag===`image`);for(let n of e)this.history.update(`images`,t.id,n.id,n.data),this.syncedImages.add(n.data.path)}}export(e){for(let t of e.sheets){let e=t.figures.filter(e=>e.tag===`image`);for(let n of e)n.data=this.images[t.id]?.[n.id]}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let t of e)if(t?.tag===`image`){let e=this.getImage(t.id);e&&n.push({...t,data:b(e)})}t.images=[...t.images,...n]}}getAllImages(){let e=[];for(let t in this.images)e.push(...Object.values(this.images[t]||{}).filter(C));return e}},lW=class extends XU{static getters=[`isInMerge`,`isInSameMerge`,`isMergeHidden`,`getMainCellPosition`,`expandZone`,`doesIntersectMerge`,`doesColumnsHaveCommonMerges`,`doesRowsHaveCommonMerges`,`getMerges`,`getMerge`,`getMergesInZone`,`isSingleCellOrMerge`,`getSelectionRangeString`,`isMainCellPosition`];nextId=1;merges={};mergeCellMap={};allowDispatch(e){let t=`force`in e?!!e.force:!1;switch(e.type){case`ADD_MERGE`:return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case`UPDATE_CELL`:return this.checkMergedContentUpdate(e);case`REMOVE_MERGE`:return this.checkMergeExists(e);default:return`Success`}}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DELETE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DUPLICATE_SHEET`:let t=this.merges[e.sheetId];if(!t)break;for(let n of Object.values(t).filter(C))this.addMerge(e.sheetIdTo,n.zone);break;case`ADD_MERGE`:for(let t of e.target)this.addMerge(e.sheetId,t);break;case`REMOVE_MERGE`:for(let t of e.target)this.removeMerge(e.sheetId,t);break}}adaptRanges(e,t){this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map(t=>this.getMergeById(e,parseInt(t,10))).filter(C)}getMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e],i=r?t in r&&r[t]?.[n]:void 0;return i?this.getMergeById(e,i):void 0}getMergesInZone(e,t){let n=this.mergeCellMap[e];if(!n)return[];let r=new Set;for(let e=t.left;e<=t.right;e++)for(let i=t.top;i<=t.bottom;i++){let t=n[e]?.[i];t&&r.add(t)}return Array.from(r).map(t=>this.getMergeById(e,t)).filter(C)}getSelectionRangeString(e,t){let n=this.getters.expandZone(e.sheetId,e.zone),r=Nc({...e,zone:{...n,bottom:Ic(e)?void 0:n.bottom,right:Lc(e)?void 0:n.right}},this.getters.getSheetSize),i=this.getters.getRangeString(r,t);if(this.isSingleCellOrMerge(e.sheetId,e.zone)){let{sheetName:e,xc:t}=jc(i);return Mc(e,t.split(`:`)[0])}return i}doesIntersectMerge(e,t){for(let n of this.getMerges(e))if(zs(t,n))return!0;return!1}doesColumnsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<this.getters.getNumberRows(e);i++)if(this.isInSameMerge(r.id,t,i,n,i))return!0;return!1}doesRowsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<=this.getters.getNumberCols(e);i++)if(this.isInSameMerge(r.id,i,t,i,n))return!0;return!1}expandZone(e,t){let{left:n,right:r,top:i,bottom:a}=t,o={left:n,right:r,top:i,bottom:a};for(let t in this.merges[e]){let n=this.getMergeById(e,parseInt(t));n&&zs(n,o)&&(o=Fs(n,o))}return Rs(o,t)?o:this.expandZone(e,o)}isInSameMerge(e,t,n,r,i){let a=this.getMerge({sheetId:e,col:t,row:n}),o=this.getMerge({sheetId:e,col:r,row:i});return!a||!o?!1:Rs(a,o)}isInMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e];return r?t in r&&!!r[t]?.[n]:!1}getMainCellPosition(e){let t=this.getMerge(e);return t?{sheetId:e.sheetId,col:t.left,row:t.top}:e}isMergeHidden(e,t){let n=this.getters.getHiddenColsGroups(e),r=this.getters.getHiddenRowsGroups(e);for(let e of n)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of r)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){let n=this.getMerge({sheetId:e,col:t.left,row:t.top});if(n)return Rs(t,n);let{numberOfCols:r,numberOfRows:i}=Us(t);return r===1&&i===1}isMainCellPosition(e){return w(this.getMainCellPosition(e),e)}isMergeDestructive(e,t){let{left:n,right:r,top:i,bottom:a}=t;r=x(r,0,this.getters.getNumberCols(e)-1),a=x(a,0,this.getters.getNumberRows(e)-1);for(let t=i;t<=a;t++)for(let a=n;a<=r;a++)if(a!==n||t!==i){let n=this.getters.getCell({sheetId:e,col:a,row:t});if(n&&n.content!==``)return!0}return!1}getMergeById(e,t){let n=this.merges[e]?.[t];return n===void 0?void 0:dW(t,n)}checkDestructiveMerge({sheetId:e,target:t}){return this.getters.tryGetSheet(e)&&t.some(t=>this.isMergeDestructive(e,t))?`MergeIsDestructive`:`Success`}checkOverlap({target:e}){for(let t of e)for(let n of e)if(t!==n&&zs(t,n))return`MergeOverlap`;return`Success`}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return`Success`;let{xSplit:n,ySplit:r}=this.getters.getPaneDivisions(e);return ic(t,n,r)?`FrozenPaneOverlap`:`Success`}checkMergedContentUpdate(e){let{col:t,row:n,content:r}=e;if(r===void 0)return`Success`;let{col:i,row:a}=this.getMainCellPosition(e);return i===t&&a===n?`Success`:`CellIsMerged`}checkMergeExists(e){let{sheetId:t,target:n}=e;for(let e of n){let{left:n,top:r}=e,i=this.getMerge({sheetId:t,col:n,row:r});if(i===void 0||!Rs(e,i))return`InvalidTarget`}return`Success`}addMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t;if(r=x(r,0,this.getters.getNumberCols(e)-1),a=x(a,0,this.getters.getNumberRows(e)-1),T(n,i)===T(r,a))return;let o=this.getters.getCell({sheetId:e,col:n,row:i}),s=this.nextId++;this.history.update(`merges`,e,s,this.getters.getRangeFromSheetXC(e,As({left:n,top:i,right:r,bottom:a})));let c=new Set;for(let t=i;t<=a;t++)for(let a=n;a<=r;a++){(a!==n||t!==i)&&this.dispatch(`UPDATE_CELL`,{sheetId:e,col:a,row:t,style:o?o.style:null,content:``});let r=this.getMerge({sheetId:e,col:a,row:t});r&&c.add(r.id),this.history.update(`mergeCellMap`,e,a,t,s)}for(let t of c){let{top:n,bottom:r,left:i,right:a}=this.getMergeById(e,t);for(let t=n;t<=r;t++)for(let n=i;n<=a;n++){let r={sheetId:e,col:n,row:t},i=this.getMerge(r);(!i||i.id!==s)&&(this.history.update(`mergeCellMap`,e,n,t,void 0),this.dispatch(`CLEAR_CELL`,r))}this.history.update(`merges`,e,t,void 0)}}removeMerge(e,t){let{left:n,top:r,bottom:i,right:a}=t,o=this.getMerge({sheetId:e,col:n,row:r});if(!(o===void 0||!Rs(t,o))){this.history.update(`merges`,e,o.id,void 0);for(let t=r;t<=i;t++)for(let r=n;r<=a;r++)this.history.update(`mergeCellMap`,e,r,t,void 0)}}applyRangeChangeOnSheet(e,{applyChange:t}){let n=Object.entries(this.merges[e]||{});for(let[r,i]of n)if(i){let n=i.zone,a=t(i);switch(a.changeType){case`NONE`:break;case`REMOVE`:this.removeMerge(e,n);break;default:let{numberOfCols:t,numberOfRows:i}=Us(a.range.zone);t===1&&i===1?this.removeMerge(e,n):this.history.update(`merges`,e,parseInt(r,10),a.range);break}}this.history.update(`mergeCellMap`,e,{});for(let t of this.getMerges(e))for(let{col:n,row:r}of Ks(t))this.history.update(`mergeCellMap`,e,n,r,t.id)}import(e){let t=e.sheets||[];for(let e of t)this.history.update(`merges`,e.id,{}),this.history.update(`mergeCellMap`,e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let n of t)this.addMerge(e,Ts(n))}export(e){for(let t of e.sheets){let e=this.merges[t.id];e&&t.merges.push(...uW(e))}}exportForExcel(e){this.export(e)}};function uW(e){return Object.entries(e).map(([e,t])=>t?dW(parseInt(e,10),t):void 0).filter(C).map(e=>T(e.left,e.top)+`:`+T(e.right,e.bottom))}function dW(e,t){return{...t.zone,id:e}}var fW=class{getters;providers=[];isAdaptingRanges=!1;constructor(e){this.getters=e}static getters=[`copyFormulaStringForSheet`,`extendRange`,`getRangeString`,`getRangeFromSheetXC`,`createAdaptedRanges`,`getRangeData`,`getRangeDataFromXc`,`getRangeDataFromZone`,`getRangeFromRangeData`,`getRangeFromZone`,`getRangesUnion`,`recomputeRanges`,`isRangeValid`,`removeRangesSheetPrefix`];allowDispatch(e){return e.type===`MOVE_RANGES`?e.target.length===1?`Success`:`InvalidZones`:`Success`}beforeHandle(e){}handle(e){if(this.isAdaptingRanges)throw Error(`Plugins cannot dispatch commands during adaptRanges phase`);let t=Gc(e);t&&this.executeOnAllRanges(t)}finalize(){}verifyRangeRemoved(e){return t=>{let n=e(t);return n.changeType!==`NONE`&&!Os(n.range.zone)?{range:n.range,changeType:`REMOVE`}:n}}executeOnAllRanges(e){this.isAdaptingRanges=!0;let t={applyChange:this.verifyRangeRemoved(e.applyChange),adaptRangeString:(t,n)=>hC(t,n,e),adaptFormulaString:(t,n)=>mC(t,n,e)};for(let n of this.providers)n(t,e.sheetId,e.sheetName);this.isAdaptingRanges=!1}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,n,r){return e.map(e=>{if(!Os(e.zone))return e;let i=e.prefixSheet?e.sheetId:r,a=Lc(e),o=Ic(e),s={...e.unboundedZone,left:a&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:a?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:o&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:n),bottom:o?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:n)};return Wc(Nc({...e,sheetId:i,zone:s},this.getters.getSheetSize))})}removeRangesSheetPrefix(e,t){return t.map(t=>t.prefixSheet&&t.sheetId===e?{...t,prefixSheet:!1}:t)}extendRange(e,t,n){let r=t===`COL`?e.zone.right+n:e.zone.right,i=t===`ROW`?e.zone.bottom+n:e.zone.bottom,a={left:e.zone.left,top:e.zone.top,right:Lc(e)?void 0:r,bottom:Ic(e)?void 0:i};return Nc({...e,zone:a},this.getters.getSheetSize)}getRangeFromSheetXC(e,t){if(!Tc.test(t)||!this.getters.tryGetSheet(e))return Fc(t);let{sheetName:n}=jc(t);return Pc({xc:t,sheetId:this.getters.getSheetIdByName(n)||e,invalidSheetName:n&&!this.getters.getSheetIdByName(n)?n:void 0},this.getters.getSheetSize)}getRangeString(e,t,n={useBoundedReference:!1,useFixedReference:!1}){return e?e.invalidXc?e.invalidXc:this.getters.tryGetSheet(e.sheetId)?Rc(e,t,this.getters.getSheetName,n):k.InvalidReference:k.InvalidReference}getRangeDataFromXc(e,t){let n=this.getters.getRangeFromSheetXC(e,t);return this.getRangeDataFromZone(n.sheetId,n.unboundedZone)}getRangeDataFromZone(e,t){return t=this.getters.getUnboundedZone(e,t),{_sheetId:e,_zone:t}}getRangeData(e){return this.getRangeDataFromZone(e.sheetId,e.unboundedZone)}getRangeFromZone(e,t){return Nc({sheetId:e,zone:t,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}],prefixSheet:!1},this.getters.getSheetSize)}recomputeRanges(e,t){return ms(e.map(e=>e.unboundedZone),t.map(e=>e.unboundedZone)).map(t=>this.getRangeFromZone(e[0].sheetId,t))}getRangeFromRangeData(e){return this.getters.tryGetSheet(e._sheetId)?Nc({prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]},this.getters.getSheetSize):Fc(k.InvalidReference)}isRangeValid(e){if(!e)return!1;let{xc:t,sheetName:n}=jc(e);return t.match(Tc)!==null&&(!n||this.getters.getSheetIdByName(n)!==void 0)}getRangesUnion(e){let t=Is(...e.map(e=>e.unboundedZone));return this.getRangeFromZone(e[0].sheetId,t)}copyFormulaStringForSheet(e,t,n,r){if(!n.startsWith(`=`))return n;let i=rC(n),a=i.dependencies.map(n=>{let i=this.getters.getRangeFromSheetXC(e,n);return r===`keepSameReference`?i:zc(e,t,i)});return this.getters.getFormulaString(t,i.tokens,a)}},pW=class extends XU{static getters=`getSheetName.tryGetSheetName.getSheet.tryGetSheet.getSheetIdByName.getSheetIds.getVisibleSheetIds.isSheetVisible.doesHeaderExist.doesHeadersExist.getCell.getCellPosition.getColsZone.getRowCells.getRowsZone.getNumberCols.getNumberRows.getNumberHeaders.getGridLinesVisibility.getNextSheetName.getSheetSize.getSheetZone.getPaneDivisions.checkZonesExistInSheet.getCommandZones.getUnboundedZone.checkElementsIncludeAllNonFrozenHeaders.getDuplicateSheetName`.split(`.`);sheetIdsMapName={};orderedSheetIds=[];sheets={};cellPosition={};allowDispatch(e){let t=this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e);if(t!==`Success`)return t;switch(e.type){case`HIDE_SHEET`:return this.getVisibleSheetIds().length===1?`NotEnoughSheets`:`Success`;case`CREATE_SHEET`:return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case`DUPLICATE_SHEET`:return this.sheets[e.sheetIdTo]?`DuplicatedSheetId`:this.orderedSheetIds.map(this.getSheetName.bind(this)).includes(e.sheetNameTo)?`DuplicatedSheetName`:`Success`;case`MOVE_SHEET`:try{let t=this.orderedSheetIds.findIndex(t=>t===e.sheetId);return this.findIndexOfTargetSheet(t,e.delta),`Success`}catch{return`WrongSheetMove`}case`RENAME_SHEET`:return this.isRenameAllowed(e);case`COLOR_SHEET`:return!e.color||mn(e.color)?`Success`:`InvalidColor`;case`DELETE_SHEET`:return this.getVisibleSheetIds().length>1?`Success`:`NotEnoughSheets`;case`ADD_COLUMNS_ROWS`:return this.doesHeaderExist(e.sheetId,e.dimension,e.base)?e.quantity<=0?`InvalidQuantity`:`Success`:`InvalidHeaderIndex`;case`REMOVE_COLUMNS_ROWS`:{let t=en(e.elements),n=$t(e.elements);return t<0||!this.doesHeaderExist(e.sheetId,e.dimension,n)?`InvalidHeaderIndex`:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`}case`FREEZE_ROWS`:return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case`FREEZE_COLUMNS`:return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return`Success`}}handle(e){switch(e.type){case`SET_GRID_LINES_VISIBILITY`:this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case`CREATE_SHEET`:let t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update(`sheetIdsMapName`,sl(t.name),t.id);break;case`MOVE_SHEET`:this.moveSheet(e.sheetId,e.delta);break;case`RENAME_SHEET`:this.renameSheet(this.sheets[e.sheetId],e.newName);break;case`COLOR_SHEET`:this.history.update(`sheets`,e.sheetId,`color`,e.color);break;case`HIDE_SHEET`:this.hideSheet(e.sheetId);break;case`SHOW_SHEET`:this.showSheet(e.sheetId);break;case`DUPLICATE_SHEET`:this.duplicateSheet(e.sheetId,e.sheetIdTo,e.sheetNameTo);break;case`DELETE_SHEET`:this.deleteSheet(this.sheets[e.sheetId]);break;case`REMOVE_COLUMNS_ROWS`:e.dimension===`COL`?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case`UPDATE_CELL_POSITION`:this.updateCellPosition(e);break;case`FREEZE_COLUMNS`:this.setPaneDivisions(e.sheetId,e.quantity,`COL`);break;case`FREEZE_ROWS`:this.setPaneDivisions(e.sheetId,e.quantity,`ROW`);break;case`UNFREEZE_ROWS`:this.setPaneDivisions(e.sheetId,0,`ROW`);break;case`UNFREEZE_COLUMNS`:this.setPaneDivisions(e.sheetId,0,`COL`);break;case`UNFREEZE_COLUMNS_ROWS`:this.setPaneDivisions(e.sheetId,0,`COL`),this.setPaneDivisions(e.sheetId,0,`ROW`)}}import(e){for(let t of e.sheets)this.sheetIdsMapName[sl(t.name)]=t.id;for(let t of e.sheets){let e=t.name||`Sheet`+(Object.keys(this.sheets).length+1),{colNumber:n,rowNumber:r}=this.getImportedSheetSize(t),i={id:t.id,name:e,numberOfCols:n,rows:nl(r),areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible,panes:{xSplit:t.panes?.xSplit||0,ySplit:t.panes?.ySplit||0},color:t.color};this.orderedSheetIds.push(i.id),this.sheets[i.id]=i}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(C).map(e=>{let t=this.sheets[e],n={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},styles:{},formats:{},borders:{},conditionalFormats:[],dataValidationRules:[],figures:[],tables:[],areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible,color:t.color};return(t.panes.xSplit||t.panes.ySplit)&&(n.panes=t.panes),n})}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){let t=this.sheets[e];if(!t)throw Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){return this.tryGetSheet(e)?.name}getSheetIdByName(e){if(e)return this.sheetIdsMapName[sl(e)]}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}doesHeaderExist(e,t,n){return t===`COL`?n>=0&&n<this.getNumberCols(e):n>=0&&n<this.getNumberRows(e)}doesHeadersExist(e,t,n){return n.every(n=>this.doesHeaderExist(e,t,n))}getCell({sheetId:e,col:t,row:n}){let r=this.tryGetSheet(e)?.rows[n]?.cells[t];if(r!==void 0)return this.getters.getCellById(r)}getColsZone(e,t,n){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:n}}getRowCells(e,t){return Object.values(this.getSheet(e).rows[t]?.cells).filter(C)}getRowsZone(e,t,n){return{top:t,bottom:n,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){let t=this.cellPosition[e];if(!t)throw Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return t===`COL`?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e=`Sheet`){return al(this.orderedSheetIds.map(this.getSheetName.bind(this)),e)}getSheetSize(e){return{numberOfRows:this.getNumberRows(e),numberOfCols:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getUnboundedZone(e,t){if(t.bottom===void 0||t.right===void 0)return t;let n=t.left===0&&t.right===this.getNumberCols(e)-1,r=t.top===0&&t.bottom===this.getNumberRows(e)-1;return{...t,bottom:r?void 0:t.bottom,right:n&&!r?void 0:t.right}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,n){let r={...this.getPaneDivisions(e)};n===`COL`?r.xSplit=t:n===`ROW`&&(r.ySplit=t),this.history.update(`sheets`,e,`panes`,r)}checkElementsIncludeAllNonFrozenHeaders(e,t,n){let r=this.getters.getPaneDivisions(e),i=t===`ROW`?r.ySplit:r.xSplit,a=this.getters.getNumberHeaders(e,t);return i?Rt(n,S(i,a)):!1}getCommandZones(e){let t=[];return`zone`in e&&t.push(e.zone),`target`in e&&t.push(...e.target),`ranges`in e&&t.push(...e.ranges.map(e=>this.getters.getRangeFromRangeData(e).zone)),`col`in e&&e.col!==void 0&&`row`in e&&e.row!==void 0&&t.push({top:e.row,left:e.col,bottom:e.row,right:e.col}),t}checkZonesExistInSheet(e,t){if(!t.every(Os))return`InvalidRange`;if(t.length){let n=this.getSheetZone(e);return t.every(e=>Hs(e,n))?`Success`:`TargetOutOfSheet`}return`Success`}updateCellPosition(e){let{sheetId:t,cellId:n,col:r,row:i}=e;n?this.setNewPosition(n,t,r,i):this.clearPosition(t,r,i)}setNewPosition(e,t,n,r){let i=this.cellPosition[e];i&&this.clearPosition(t,i.col,i.row),this.history.update(`cellPosition`,e,{row:r,col:n,sheetId:t}),this.history.update(`sheets`,t,`rows`,r,`cells`,n,e)}clearPosition(e,t,n){let r=this.sheets[e]?.rows[n].cells[t];r&&(this.history.update(`cellPosition`,r,void 0),this.history.update(`sheets`,e,`rows`,n,`cells`,t,void 0))}setGridLinesVisibility(e,t){this.history.update(`sheets`,e,`areGridLinesVisible`,t)}createSheet(e,t,n,r,i){let a={id:e,name:t,numberOfCols:n,rows:nl(r),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},o=this.orderedSheetIds.slice();o.splice(i,0,a.id);let s=this.sheets;return this.history.update(`orderedSheetIds`,o),this.history.update(`sheets`,Object.assign({},s,{[a.id]:a})),a}moveSheet(e,t){let n=this.orderedSheetIds.slice(),r=n.findIndex(t=>t===e),i=n.splice(r,1),a=this.findIndexOfTargetSheet(r,t);n.splice(a,0,i[0]),this.history.update(`orderedSheetIds`,n)}findIndexOfTargetSheet(e,t){for(;t!==0&&0<=e&&e<=this.orderedSheetIds.length;)t>0?(e++,this.isSheetVisible(this.orderedSheetIds[e])&&t--):t<0&&(e--,this.isSheetVisible(this.orderedSheetIds[e])&&t++);if(t===0)return e;throw Error(`There is not enough visible sheets`)}checkSheetName(e){let t=this.getters.tryGetSheetName(e.sheetId),n=e.type===`RENAME_SHEET`?e.newName:e.name;if(t!==void 0&&n===t)return`UnchangedSheetName`;let{orderedSheetIds:r,sheets:i}=this,a=n&&n.trim().toLowerCase();return r.find(t=>cl(i[t]?.name,a)&&t!==e.sheetId)?`DuplicatedSheetName`:Xe.test(a)?`ForbiddenCharactersInSheetName`:`Success`}checkSheetPosition(e){let{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?`WrongSheetPosition`:`Success`}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkRowFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.top<e.quantity&&e.quantity<=n.bottom)return`MergeOverlap`;return`Success`}checkColFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.left<e.quantity&&e.quantity<=n.right)return`MergeOverlap`;return`Success`}isRenameAllowed(e){return e.newName&&e.newName.trim().toLowerCase()?this.checkSheetName(e):`MissingSheetName`}renameSheet(e,t){let n=e.name;this.history.update(`sheets`,e.id,`name`,t.trim());let r=Object.assign({},this.sheetIdsMapName);delete r[sl(n)],r[sl(t)]=e.id,this.history.update(`sheetIdsMapName`,r)}hideSheet(e){this.history.update(`sheets`,e,`isVisible`,!1)}showSheet(e){this.history.update(`sheets`,e,`isVisible`,!0)}duplicateSheet(e,t,n){let r=b(this.getSheet(e));r.id=t,r.name=n;for(let e=0;e<=r.numberOfCols;e++)for(let t=0;t<=r.rows.length;t++)r.rows[t]&&(r.rows[t].cells[e]=void 0);let i=this.orderedSheetIds.slice(),a=i.indexOf(e);i.splice(a+1,0,r.id),this.history.update(`orderedSheetIds`,i),this.history.update(`sheets`,Object.assign({},this.sheets,{[r.id]:r}));for(let t of Object.values(this.getters.getCells(e))){let{col:e,row:n}=this.getCellPosition(t.id);this.dispatch(`UPDATE_CELL`,{sheetId:r.id,col:e,row:n,content:t.content,format:t.format,style:t.style})}let o=Object.assign({},this.sheetIdsMapName);o[sl(r.name)]=r.id,this.history.update(`sheetIdsMapName`,o)}getDuplicateSheetName(e){return ol(e,this.orderedSheetIds.map(this.getSheetName.bind(this)))}deleteSheet(e){let t=e.name,n=Object.assign({},this.sheets);delete n[e.id],this.history.update(`sheets`,n);let r=this.orderedSheetIds.slice(),i=r.indexOf(e.id);r.splice(i,1),this.history.update(`orderedSheetIds`,r);let a=Object.assign({},this.sheetIdsMapName);delete a[sl(t)],this.history.update(`sheetIdsMapName`,a)}removeColumns(e,t){t.sort((e,t)=>t-e);for(let n of t)this.moveCellOnColumnsDeletion(e,n);let n=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,n-t.length);let r=t.filter(t=>t<e.panes.xSplit).length;r&&this.setPaneDivisions(e.id,e.panes.xSplit-r,`COL`)}removeRows(e,t){t.sort((e,t)=>t-e);for(let n of gt(t)){let t=n[n.length-1],r=n[0];this.moveCellOnRowsDeletion(e,t,r),this.updateRowsStructureOnDeletion(e,t,r)}let n=t.filter(t=>t<e.panes.ySplit).length;n&&this.setPaneDivisions(e.id,e.panes.ySplit-n,`ROW`)}addColumns(e,t,n,r){let i=n===`before`?t:t+1;this.moveCellsOnAddition(e,i,r,`columns`);let a=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,a+r),i<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+r,`COL`)}addRows(e,t,n,r){let i=n===`before`?t:t+1;this.addEmptyRows(e,r),this.moveCellsOnAddition(e,i,r,`rows`),i<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+r,`ROW`)}moveCellOnColumnsDeletion(e,t){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:t,top:0,right:t,bottom:e.rows.length-1}]});for(let n=0;n<e.rows.length;n++){let r=e.rows[n];for(let i in r.cells){let a=Number(i),o=r.cells[i];o&&a>t&&this.setNewPosition(o,e.id,a-1,n)}}}moveCellsOnAddition(e,t,n,r){let i=[];for(let a=0;a<e.rows.length;a++){let o=e.rows[a];if(r!==`rows`||a>=t)for(let s in o.cells){let c=Number(s),l=o.cells[s];l&&(r===`rows`||c>=t)&&i.push({sheetId:e.id,cellId:l,col:c+(r===`columns`?n:0),row:a+(r===`rows`?n:0),type:`UPDATE_CELL_POSITION`})}}for(let e of i.reverse())this.updateCellPosition(e)}moveCellOnRowsDeletion(e,t,n){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:0,top:t,right:this.getters.getNumberCols(e.id),bottom:n}]});let r=n-t+1;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(t>n)for(let n in i.cells){let a=Number(n),o=i.cells[n];o&&this.setNewPosition(o,e.id,a,t-r)}}}updateRowsStructureOnDeletion(e,t,n){let r=[],i=e.rows.map(e=>e.cells).reverse();for(let a in e.rows){let e=Number(a);e>=t&&e<=n||r.push({cells:i.pop()})}this.history.update(`sheets`,e.id,`rows`,r)}addEmptyRows(e,t){let n=e.rows.slice();for(let e=0;e<t;e++)n.push({cells:{}});this.history.update(`sheets`,e.id,`rows`,n)}getImportedSheetSize(e){let t=Object.keys(e.cells).map(ir),n=e.rowNumber,r=e.colNumber;for(let{col:e,row:i}of t)n=Math.max(n,i+1),r=Math.max(r,e+1);return{rowNumber:n,colNumber:r}}checkSheetExists(e){return e.type!==`CREATE_SHEET`&&`sheetId`in e&&this.sheets[e.sheetId]===void 0?`InvalidSheetId`:e.type===`CREATE_SHEET`&&this.sheets[e.sheetId]!==void 0?`DuplicatedSheetId`:`Success`}checkZonesAreInSheet(e){return`sheetId`in e?`ranges`in e&&e.ranges.some(e=>e._sheetId!==``&&!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkZonesExistInSheet(e.sheetId,this.getCommandZones(e)):`Success`}},mW=class extends XU{static getters=[`getCoreTable`,`getCoreTables`,`getCoreTableMatchingTopLeft`];tables={};nextTableId=1;adaptRanges({applyChange:e},t){for(let n of this.getCoreTables(t))this.applyRangeChangeOnTable(t,n,e)}allowDispatch(e){switch(e.type){case`CREATE_TABLE`:if(e.ranges.some(t=>!this.getters.tryGetSheet(t._sheetId)||t._sheetId!==e.sheetId))return`InvalidSheetId`;let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e).zone);return oc(t)?this.checkValidations(e,e=>this.getTablesOverlappingZones(e.sheetId,t).length?`TableOverlap`:`Success`,e=>this.checkTableConfigUpdateIsValid(e.config)):`NonContinuousTargets`;case`UPDATE_TABLE`:return this.getCoreTableMatchingTopLeft(e.sheetId,e.zone)?this.checkValidations(e,this.checkUpdatedTableZoneIsValid,e=>this.checkTableConfigUpdateIsValid(e.config)):`TableNotFound`;case`ADD_MERGE`:for(let t of this.getCoreTables(e.sheetId)){let n=t.range.zone;for(let t of e.target)if(zs(n,t))return`MergeInTable`}break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`tables`,e.sheetId,{});break;case`DELETE_SHEET`:{let t={...this.tables};delete t[e.sheetId],this.history.update(`tables`,t);break}case`DUPLICATE_SHEET`:{let t={};for(let n of this.getCoreTables(e.sheetId))t[n.id]=n.type===`dynamic`?this.copyDynamicTableForSheet(e.sheetIdTo,n):this.copyStaticTableForSheet(e.sheetIdTo,n);this.history.update(`tables`,e.sheetIdTo,t);break}case`CREATE_TABLE`:{let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e)),n=this.getters.getRangesUnion(t),r=this.getters.getMergesInZone(e.sheetId,n.zone);r.length&&this.dispatch(`REMOVE_MERGE`,{sheetId:e.sheetId,target:r});let i=this.consumeNextId(),a=e.config||QA,o=e.tableType===`dynamic`?this.createDynamicTable(i,n,a):this.createStaticTable(i,e.tableType,n,a);this.history.update(`tables`,e.sheetId,o.id,o);break}case`REMOVE_TABLE`:{let t={};for(let n of this.getCoreTables(e.sheetId))e.target.every(e=>!Ls(n.range.zone,e))&&(t[n.id]=n);this.history.update(`tables`,e.sheetId,t);break}case`UPDATE_TABLE`:this.updateTable(e);break;case`UPDATE_CELL`:{let t=e.sheetId;for(let n of this.getCoreTables(t)){if(n.type===`dynamic`)continue;let r=this.canUpdateCellCmdExtendTable(e,n);r===`down`?this.extendTableDown(t,n):r===`right`&&this.extendTableRight(t,n)}break}case`DELETE_CONTENT`:{let t={...this.tables[e.sheetId]};for(let n in t){let r=t[n];r&&e.target.some(e=>Hs(r.range.zone,e))&&this.dispatch(`REMOVE_TABLE`,{sheetId:e.sheetId,target:[r.range.zone]})}break}}}getCoreTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(C):[]}getCoreTable({sheetId:e,col:t,row:n}){return this.getCoreTables(e).find(e=>Vs(t,n,e.range.zone))}getTablesOverlappingZones(e,t){return this.getCoreTables(e).filter(e=>t.some(t=>zs(e.range.zone,t)))}extendTableDown(e,t){let n=this.getters.extendRange(t.range,`ROW`,1);this.history.update(`tables`,e,t.id,this.updateStaticTable(t,n))}extendTableRight(e,t){let n=this.getters.extendRange(t.range,`COL`,1);this.history.update(`tables`,e,t.id,this.updateStaticTable(t,n))}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:n,row:r},i){if(!e)return`none`;let a=i.range.zone,o=`none`;if(a.bottom+1===r&&n>=a.left&&n<=a.right?o=`down`:a.right+1===n&&r>=a.top&&r<=a.bottom&&(o=`right`),o===`none`)return`none`;let s=o===`down`?{...a,bottom:a.bottom+1,top:a.bottom+1}:{...a,right:a.right+1,left:a.right+1};for(let e=s.top;e<=s.bottom;e++)for(let n=s.left;n<=s.right;n++){let r={sheetId:t,col:n,row:e};if(this.getters.getCell(r)?.content||this.getters.isInMerge(r)||this.getTablesOverlappingZones(t,[R(r)]).length)return`none`}return o}getCoreTableMatchingTopLeft(e,t){for(let n of this.getCoreTables(e)){let e=n.range.zone;if(e.left===t.left&&e.top===t.top)return n}}checkUpdatedTableZoneIsValid(e){if(!e.newTableRange)return`Success`;let t=this.getters.getRangeFromRangeData(e.newTableRange).zone,n=this.getters.checkZonesExistInSheet(e.sheetId,[t]);if(n!==`Success`)return n;let r=this.getCoreTableMatchingTopLeft(e.sheetId,e.zone);return r?this.getTablesOverlappingZones(e.sheetId,[t]).filter(e=>e.id!==r.id).length?`TableOverlap`:`Success`:`TableNotFound`}checkTableConfigUpdateIsValid(e){return e&&(e.numberOfHeaders!==void 0&&e.numberOfHeaders<0||e.hasFilters&&e.numberOfHeaders===0)?`InvalidTableConfig`:`Success`}createStaticTable(e,t,n,r,i){let a=n.zone;if(!i){i=[];for(let e of S(a.left,a.right+1)){let t={...a,left:e,right:e},o=this.consumeNextId();i.push(this.createFilterFromZone(o,n.sheetId,t,r))}}return{id:e,range:n,filters:i,config:r,type:t}}createDynamicTable(e,t,n){let r=$s(t.zone);return{id:e,range:this.getters.getRangeFromZone(t.sheetId,r),config:n,type:`dynamic`}}updateTable(e){let t=this.getCoreTableMatchingTopLeft(e.sheetId,e.zone);if(!t)return;let n=e.newTableRange?this.getters.getRangeFromRangeData(e.newTableRange):void 0;if(n){let t=this.getters.getMergesInZone(e.sheetId,n.zone);this.dispatch(`REMOVE_MERGE`,{sheetId:e.sheetId,target:t})}let r=n||t.range,i=this.updateTableConfig(e.config,t.config),a=e.tableType??t.type;if(a===`dynamic`&&t.type!==`dynamic`||a!==`dynamic`&&t.type===`dynamic`){let n=a===`dynamic`?this.createDynamicTable(t.id,r,i):this.createStaticTable(t.id,a,r,i);this.history.update(`tables`,e.sheetId,t.id,n)}else{let n=t.type===`dynamic`?this.updateDynamicTable(t,r,i):this.updateStaticTable(t,r,i,a);this.history.update(`tables`,e.sheetId,t.id,n)}}updateStaticTable(e,t,n,r=e.type){if(r===`dynamic`)throw Error(`Cannot use updateStaticTable to update a dynamic table`);let i=t||e.range,a=i.zone,o=this.updateTableConfig(n,e.config),s=o||e.config,c=[];if(t||o&&`numberOfHeaders`in o)for(let t of S(a.left,a.right+1)){let n=a.top===e.range.zone.top?e.filters.find(e=>e.col===t):void 0,r={...a,left:t,right:t},o=n?.id||this.consumeNextId();c.push(this.createFilterFromZone(o,i.sheetId,r,s))}return{...e,range:i,config:s,filters:c.length?c:e.filters,type:r}}updateDynamicTable(e,t,n){let r=t?this.getters.getRangeFromZone(t.sheetId,$s(t.zone)):e.range,i=n||e.config;return{...e,range:r,config:i}}updateTableConfig(e,t){if(!e)return t;let n={...t,...e};return e.numberOfHeaders===0?n.hasFilters=!1:e.hasFilters===!0&&(n.numberOfHeaders||=1),n}createFilterFromZone(e,t,n,r){return gI(e,this.getters.getRangeFromZone(t,n),r,this.getters.getRangeFromZone)}copyStaticTableForSheet(e,t){let n=this.getters.getRangeFromZone(e,t.range.zone),r=t.filters.map(n=>{let r=this.getters.getRangeFromZone(e,n.rangeWithHeaders.zone);return gI(n.id,r,t.config,this.getters.getRangeFromZone)});return{id:t.id,range:n,filters:r,config:b(t.config),type:t.type}}copyDynamicTableForSheet(e,t){let n=this.getters.getRangeFromZone(e,t.range.zone);return{id:t.id,range:n,config:b(t.config),type:`dynamic`}}applyRangeChangeOnTable(e,t,n){let r=n(t.range),i;switch(r.changeType){case`REMOVE`:this.history.update(`tables`,e,t.id,void 0);return;case`NONE`:return;default:i=r.range}if(t.type===`dynamic`){let n=this.updateDynamicTable(t,i);this.history.update(`tables`,e,t.id,n);return}let a=[];for(let e of t.filters){let r=n(e.rangeWithHeaders);switch(r.changeType){case`REMOVE`:continue;case`NONE`:a.push(e);break;default:let n=r.range,i=gI(e.id,n,t.config,this.getters.getRangeFromZone);a.push(i)}}let o=i.zone;if(a.length<Us(o).numberOfCols){for(let n=o.left;n<=o.right;n++)if(!a.find(e=>e.col===n)){let r=this.consumeNextId(),i={...o,left:n,right:n};a.push(this.createFilterFromZone(r,e,i,t.config))}a.sort((e,t)=>e.col-t.col)}let s=this.createStaticTable(t.id,t.type,i,t.config,a);this.history.update(`tables`,e,t.id,s)}consumeNextId(){let e=`${this.nextTableId}`;return this.history.update(`nextTableId`,this.nextTableId+1),e}import(e){for(let t of e.sheets)for(let e of t.tables||[]){let n=this.consumeNextId(),r=e.config||QA,i=this.getters.getRangeFromSheetXC(t.id,e.range),a=e.type||`static`,o=a===`dynamic`?this.createDynamicTable(n,i,r):this.createStaticTable(n,a,i,r);this.history.update(`tables`,t.id,o.id,o)}}export(e){for(let t of e.sheets)for(let e of this.getCoreTables(t.id)){let n={range:As(e.range.zone),type:e.type};w(e.config,QA)||(n.config=e.config),t.tables.push(n)}}exportForExcel(e){for(let t of e.sheets)for(let e of this.getCoreTables(t.id)){let n=As(e.range.zone);t.tables.push({range:n,filters:[],config:e.config})}}},hW=class extends XU{static getters=[`getCarousel`,`doesCarouselExist`];carousels={};allowDispatch(e){switch(e.type){case`CREATE_CAROUSEL`:return this.getters.getFigure(e.sheetId,e.figureId)?`DuplicatedFigureId`:`Success`;case`UPDATE_CAROUSEL`:return this.carousels[e.sheetId]?.[e.figureId]?`Success`:`InvalidFigureId`}return`Success`}handle(e){switch(e.type){case`CREATE_CAROUSEL`:this.getters.getFigure(e.sheetId,e.figureId)||this.dispatch(`CREATE_FIGURE`,{...e,tag:`carousel`}),this.history.update(`carousels`,e.sheetId,e.figureId,e.definition);break;case`UPDATE_CAROUSEL`:this.removeDeletedCharts(e,this.getters.getCarousel(e.figureId).items),this.history.update(`carousels`,e.sheetId,e.figureId,e.definition);break;case`DUPLICATE_SHEET`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`carousel`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.getCarousel(n.id);if(i){let t={width:n.width,height:n.height};this.dispatch(`CREATE_CAROUSEL`,{sheetId:e.sheetIdTo,figureId:r,offset:n.offset,col:n.col,row:n.row,size:t,definition:{items:i.items.map(t=>{if(t.type===`carouselDataView`)return{...t};let n=t.chartId.split(`??`).pop(),r=`${e.sheetIdTo}??${n}`;return{...t,chartId:r}})}})}}break}case`DELETE_FIGURE`:this.history.update(`carousels`,e.sheetId,e.figureId,void 0);break;case`DELETE_SHEET`:this.history.update(`carousels`,e.sheetId,void 0);break}}doesCarouselExist(e){for(let t in this.carousels)if(this.carousels[t]?.[e])return!0;return!1}getCarousel(e){for(let t in this.carousels)if(this.carousels[t]?.[e])return this.carousels[t][e];throw Error(`There is no carousel with the given figureId: ${e}`)}removeDeletedCharts(e,t){let n=new Set(e.definition.items.filter(e=>e.type===`chart`).map(e=>e.chartId));for(let r of t)r.type===`chart`&&!n.has(r.chartId)&&this.dispatch(`DELETE_CHART`,{chartId:r.chartId,sheetId:e.sheetId})}import(e){for(let t of e.sheets){let e=(t.figures||[]).filter(e=>e.tag===`carousel`);for(let n of e)this.history.update(`carousels`,t.id,n.id,{items:n.data.items,title:n.data.title})}}export(e){for(let t of e.sheets){let e=t.figures.filter(e=>e.tag===`carousel`);for(let n of e)this.carousels[t.id]?.[n.id]&&(n.data={...n.data,...this.carousels[t.id]?.[n.id]})}}},gW=class extends XU{static getters=[`getHeaderGroups`,`getGroupsLayers`,`getVisibleGroupLayers`,`getHeaderGroup`,`getHeaderGroupsInZone`,`isGroupFolded`,`isRowFolded`,`isColFolded`];groups={};allowDispatch(e){switch(e.type){case`GROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;if(this.findGroupWithStartEnd(e.sheetId,e.dimension,t,n))return`HeaderGroupAlreadyExists`;break}case`UNGROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;break}case`UNFOLD_HEADER_GROUP`:case`FOLD_HEADER_GROUP`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);if(!t)return`UnknownHeaderGroup`;if(S(0,this.getters.getNumberHeaders(e.sheetId,e.dimension)).every(n=>n>=t.start&&n<=t.end||this.getters.isHeaderHiddenByUser(e.sheetId,e.dimension,n)))return`NotEnoughElements`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`groups`,e.sheetId,{ROW:[],COL:[]});break;case`GROUP_HEADERS`:this.groupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`UNGROUP_HEADERS`:this.unGroupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`DUPLICATE_SHEET`:{let t=b(this.groups[e.sheetId]);this.history.update(`groups`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.groups};delete t[e.sheetId],this.history.update(`groups`,t);break}case`ADD_COLUMNS_ROWS`:let t=Ft(e.position,e.base);this.moveGroupsOnHeaderInsertion(e.sheetId,e.dimension,t,e.quantity);break;case`REMOVE_COLUMNS_ROWS`:this.moveGroupsOnHeaderDeletion(e.sheetId,e.dimension,e.elements);break;case`UNFOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.unfoldHeaderGroup(e.sheetId,e.dimension,t);break}case`FOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.foldHeaderGroup(e.sheetId,e.dimension,t);break}case`UNFOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.unfoldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.foldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_HEADER_GROUPS_IN_ZONE`:{let t=e.type===`UNFOLD_HEADER_GROUPS_IN_ZONE`?`unfold`:`fold`,n=this.getGroupsLayers(e.sheetId,e.dimension);t===`fold`&&n.reverse();let r=n.flat(),i=e.dimension===`ROW`?e.zone.top:e.zone.left,a=e.dimension===`ROW`?e.zone.bottom:e.zone.right,o=new Set;for(let e=i;e<=a;e++){let n=r.filter(t=>t.start-1<=e&&e<=t.end);for(let e of n)if(!(t===`fold`&&e.isFolded||t===`unfold`&&!e.isFolded)){o.add(e);break}}for(let n of o)t===`unfold`?this.unfoldHeaderGroup(e.sheetId,e.dimension,n):this.foldHeaderGroup(e.sheetId,e.dimension,n);break}}}getHeaderGroups(e,t){return this.groups[e][t]}getHeaderGroup(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}getHeaderGroupsInZone(e,t,n){return this.getHeaderGroups(e,t).filter(e=>{let r=t===`ROW`?n.top:n.left,i=t===`ROW`?n.bottom:n.right;return this.doGroupOverlap(e,r,i)})}getGroupsLayers(e,t){let n=this.getHeaderGroups(e,t);return this.bricksFallingAlgorithm(n,0,0)}getVisibleGroupLayers(e,t){let n=this.getGroupsLayers(e,t);for(let r of n)for(let n=r.length-1;n>=0;n--){let i=r[n];i.start!==0&&S(i.start-1,i.end+1).every(n=>this.getters.isHeaderHiddenByUser(e,t,n))&&r.splice(n,1)}return n.filter(e=>e.length>0)}isGroupFolded(e,t,n,r){return this.getHeaderGroup(e,t,n,r)?.isFolded||!1}isRowFolded(e,t){return this.getters.getHeaderGroups(e,`ROW`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}isColFolded(e,t){return this.getters.getHeaderGroups(e,`COL`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}getGroupId(e){return`${e.start}-${e.end}}`}bricksFallingAlgorithm(e,t,n,r=0){let i={};for(let t of e)i[this.getGroupId(t)]=t.isFolded;let a={};for(let t of e)for(let e=t.start;e<=t.end;e++)a[e]=a[e]?a[e]+1:1;for(let e=t;e<=n;e++)a[e]=a[e]?a[e]+r:r;let o=Math.max(...Object.values(a),0),s=Array.from({length:o},()=>[]),c=Math.max(n,...e.map(e=>e.end)),l=Math.min(t,...e.map(e=>e.start));for(let e=l;e<=c;e++){let t=a[e]||0;for(let n=0;n<t;n++){let t=s[n].at(-1);if(t&&Gt([t.end,e]))t.end++;else{let t={start:e,end:e};s[n].push(t)}}}for(let e of s)for(let t of e)t.isFolded=i[this.getGroupId(t)];return s}groupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}unGroupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,-1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}moveGroupsOnHeaderInsertion(e,t,n,r){let i=this.groups[e][t];for(let a=0;a<i.length;a++){let o=i[a],[s,c]=rl(n,r,[o.start,o.end]);(s!==o.start||c!==o.end)&&this.history.update(`groups`,e,t,a,{...o,start:s,end:c})}}moveGroupsOnHeaderDeletion(e,t,n){let r=this.getHeaderGroups(e,t),i=[];for(let e of r){let t=il(n,S(e.start,e.end+1));t.length!==0&&i.push({...e,start:Math.min(...t),end:Math.max(...t)})}this.history.update(`groups`,e,t,this.bricksFallingAlgorithm(i,0,0).flat())}doGroupOverlap(e,t,n){return e.start<=n&&e.end>=t}removeDuplicateGroups(e){let t={};for(let n of e)t[this.getGroupId(n)]=n;return Object.values(t)}findGroupWithStartEnd(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}foldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!0);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end<=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!0)}}unfoldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!1);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end>=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!1)}}getGroupIndex(e,t,n,r){let i=this.groups[e][t].findIndex(e=>e.start===n&&e.end===r);return i===-1?void 0:i}import(e){for(let t of e.sheets)if(this.groups[t.id]={ROW:[],COL:[]},t.headerGroups)for(let e of[`ROW`,`COL`])for(let n of t.headerGroups[e]||[])this.groups[t.id][e].push({...n})}export(e){for(let t of e.sheets)t.headerGroups=this.groups[t.id]}exportForExcel(e){for(let t of e.sheets)for(let e of[`ROW`,`COL`]){let n=this.getGroupsLayers(t.id,e);for(let r=0;r<n.length;r++){let i=n[r];for(let n of i){for(let i=n.start;i<=n.end;i++){let a=Uj(t,e,i);a.outlineLevel=r+1,n.isFolded&&(a.isHidden=!0)}if(n.isFolded){let r=Uj(t,e,n.end+1);r.collapsed=!0}}}}}},_W=class extends XU{static getters=[`getPivotCoreDefinition`,`getPivotDisplayName`,`getPivotId`,`getPivotFormulaId`,`getPivotIds`,`getMeasureCompiledFormula`,`getPivotName`,`isExistingPivot`,`getMeasureFullDependencies`];nextFormulaId=1;pivots={};formulaIds={};compiledMeasureFormulas={};allowDispatch(e){switch(e.type){case`ADD_PIVOT`:return this.checkValidations(e.pivot,this.checkDuplicatedMeasureIds,this.checkSortedColumnInMeasures,this.checkCustomFieldsAreValid);case`UPDATE_PIVOT`:return e.pivotId in this.pivots?w(e.pivot,this.pivots[e.pivotId]?.definition)?`NoChanges`:e.pivot.name===``?`EmptyName`:this.checkValidations(e.pivot,this.checkDuplicatedMeasureIds,this.checkSortedColumnInMeasures,this.checkCustomFieldsAreValid):`PivotIdNotFound`;case`RENAME_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`;if(e.name===``)return`EmptyName`;break;case`REMOVE_PIVOT`:case`DUPLICATE_PIVOT`:case`INSERT_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`;break;case`DUPLICATE_PIVOT`:if(!(e.pivotId in this.pivots))return`PivotIdNotFound`}return`Success`}handle(e){switch(e.type){case`ADD_PIVOT`:{let{pivotId:t,pivot:n}=e;this.addPivot(t,n);break}case`INSERT_PIVOT`:{let{sheetId:t,col:n,row:r,pivotId:i,table:a}=e,o={sheetId:t,col:n,row:r},{cols:s,rows:c,measures:l,fieldsType:u}=a,d=new nR(s,c,l,u||{}),f=this.getPivotFormulaId(i);this.insertPivot(o,f,d);break}case`RENAME_PIVOT`:this.history.update(`pivots`,e.pivotId,`definition`,`name`,e.name);break;case`REMOVE_PIVOT`:{let t={...this.pivots};delete t[e.pivotId];let n=this.getPivotFormulaId(e.pivotId);this.history.update(`formulaIds`,n,void 0),this.history.update(`pivots`,t);break}case`DUPLICATE_PIVOT`:{let{pivotId:t,newPivotId:n}=e,r=b(this.getPivotCore(t).definition);r.name=e.duplicatedPivotName??r.name+` (copy)`,this.addPivot(n,r);break}case`UPDATE_PIVOT`:this.history.update(`pivots`,e.pivotId,`definition`,b(e.pivot)),this.compileCalculatedMeasures(e.pivotId,e.pivot.measures);break}}adaptRanges({applyChange:e,adaptFormulaString:t}){for(let t in this.pivots){let n=b(this.pivots[t]?.definition);if(!n)continue;let r=vR.get(n.type)?.adaptRanges?.(this.getters,n,e);r&&!w(n,r)&&this.history.update(`pivots`,t,`definition`,r)}for(let n in this.compiledMeasureFormulas)for(let r in this.compiledMeasureFormulas[n]){let i=this.pivots[n]?.definition.measures.find(e=>e.id===r);if(!i||!i.computedBy)continue;let a=i.computedBy.sheetId,{formula:o,dependencies:s}=this.compiledMeasureFormulas[n][r];this.history.update(`compiledMeasureFormulas`,n,r,`formula`,`dependencies`,o.dependencies.map(t=>e(t).range)),this.history.update(`compiledMeasureFormulas`,n,i.id,`dependencies`,s.map(t=>e(t).range));let c=i.computedBy.formula,l=t(a,c);l!==c&&this.replaceMeasureFormula(n,i,l)}}getPivotDisplayName(e){return`(#${this.getPivotFormulaId(e)}) ${this.getPivotName(e)}`}getPivotName(e){return this.getPivotCore(e).definition.name}getPivotCoreDefinition(e){return this.getPivotCore(e).definition}getPivotId(e){return this.formulaIds[e]}getPivotFormulaId(e){return this.getPivotCore(e).formulaId}getPivotIds(){return Object.keys(this.pivots)}isExistingPivot(e){return e in this.pivots}getMeasureCompiledFormula(e,t){if(!t.computedBy)throw Error(`Measure ${t.fieldName} is not computed by formula`);return this.compiledMeasureFormulas[e][t.id].formula}getMeasureFullDependencies(e,t){if(!t.computedBy)throw Error(`Measure ${t.fieldName} is not computed by formula`);return this.compiledMeasureFormulas[e][t.id].dependencies}addPivot(e,t,n=this.nextFormulaId.toString()){this.history.update(`pivots`,e,{definition:b(t),formulaId:n}),this.compileCalculatedMeasures(e,t.measures),this.history.update(`formulaIds`,n,e),this.history.update(`nextFormulaId`,this.nextFormulaId+1)}compileCalculatedMeasures(e,t){for(let n of t)if(n.computedBy){let t=this.compileMeasureFormula(n.computedBy.sheetId,n.computedBy.formula);this.history.update(`compiledMeasureFormulas`,e,n.id,`formula`,t)}for(let n of t)if(n.computedBy){let t=this.computeMeasureFullDependencies(e,n);this.history.update(`compiledMeasureFormulas`,e,n.id,`dependencies`,t)}}computeMeasureFullDependencies(e,t,n=new Set){let r=[],i=this.getPivotCoreDefinition(e),a=this.getMeasureCompiledFormula(e,t);n.add(t.id);for(let o of a.tokens){if(o.type!==`SYMBOL`)continue;let a=i.measures.find(e=>mt(e.id)===o.value&&t.id!==e.id);!a||n.has(a.id)||!a.computedBy||r.push(...this.computeMeasureFullDependencies(e,a,n))}return r.push(...a.dependencies.filter(e=>!e.invalidXc)),r}insertPivot(e,t,n){this.resizeSheet(e.sheetId,e,n);let r=n.getPivotCells();for(let n=0;n<r.length;n++)for(let i=0;i<r[n].length;i++){let a=r[n][i];this.dispatch(`UPDATE_CELL`,{sheetId:e.sheetId,col:e.col+n,row:e.row+i,content:Md(t,a)})}}resizeSheet(e,{col:t,row:n},r){let i=r.getNumberOfDataColumns()+1,a=this.getters.getNumberCols(e),o=a-t;o<i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:a-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:i-o,position:`after`});let s=r.columns.length+r.rows.length,c=this.getters.getNumberRows(e),l=c-n;l<s&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:c-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:s-l,position:`after`})}getPivotCore(e){let t=this.pivots[e];if(!t)throw Error(`Pivot with id ${e} not found`);return t}compileMeasureFormula(e,t){let n=rC(t),r=n.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t));return{...n,dependencies:r}}replaceMeasureFormula(e,t,n){let r=this.pivots[e];if(!r)return;let i=r.definition.measures.indexOf(t);this.history.update(`pivots`,e,`definition`,`measures`,i,`computedBy`,{formula:n,sheetId:t.computedBy.sheetId})}checkSortedColumnInMeasures(e){let t=e.measures.map(e=>e.id);return e.sortedColumn&&!t.includes(e.sortedColumn.measure)?`InvalidDefinition`:`Success`}checkDuplicatedMeasureIds(e){let t=new Set(e.measures.map(e=>e.id));return e.measures.length===t.size?`Success`:`InvalidDefinition`}checkCustomFieldsAreValid(e){for(let t in e.customFields){let n=e.customFields[t],r=new Set,i=new Set,a=!1;for(let e of n.groups){if(!e.name||i.has(e.name)||e.values.some(e=>r.has(e))||e.isOtherGroup&&a)return`InvalidPivotCustomField`;e.values.forEach(e=>r.add(e)),i.add(e.name),a||=!!e.isOtherGroup}}return`Success`}import(e){if(e.pivots)for(let[t,n]of Object.entries(e.pivots))this.addPivot(t,n,n.formulaId);this.history.update(`nextFormulaId`,e.pivotNextId||Td(this.pivots)+1)}export(e){e.pivots={};for(let t in this.pivots)e.pivots[t]={...this.getPivotCoreDefinition(t),formulaId:this.getPivotFormulaId(t)};e.pivotNextId=this.nextFormulaId}},vW=class extends XU{static getters=[`getLocale`];locale=D;allowDispatch(e){switch(e.type){case`UPDATE_LOCALE`:return uu(e.locale)?`Success`:`InvalidLocale`}return`Success`}handle(e){switch(e.type){case`UPDATE_LOCALE`:let t=this.locale,n=e.locale;this.history.update(`locale`,n),this.changeCellsDateFormatWithLocale(t,n);break}}getLocale(){return this.locale}changeCellsDateFormatWithLocale(e,t){for(let n of this.getters.getSheetIds())for(let[r,i]of Object.entries(this.getters.getCells(n))){let n;if(i.format===e.dateFormat&&(n=t.dateFormat),i.format===e.timeFormat&&(n=t.timeFormat),i.format===Du(e)&&(n=Du(t)),n){let{col:e,row:t,sheetId:i}=this.getters.getCellPosition(r);this.dispatch(`UPDATE_CELL`,{col:e,row:t,sheetId:i,format:n})}}}import(e){this.locale=e.settings?.locale??D}export(e){e.settings={locale:this.locale}}},yW=class extends XU{allowDispatch(e){switch(e.type){case`ADD_PIVOT`:case`UPDATE_PIVOT`:let t=e.pivot;return this.checkDataSetValidity(t)}return`Success`}checkDataSetValidity(e){if(e.type===`SPREADSHEET`&&e.dataSet){let{zone:t,sheetId:n}=e.dataSet;return!n||!this.getters.tryGetSheet(n)||!t||!Os(t)?`InvalidDataSet`:this.getters.checkZonesExistInSheet(n,[t])}return`Success`}},bW=class extends XU{static getters=[`getNewCustomTableStyleName`,`getTableStyle`,`getTableStyles`,`isTableStyleEditable`];styles={};allowDispatch(e){switch(e.type){case`CREATE_TABLE`:case`UPDATE_TABLE`:if(e.config?.styleId&&!this.styles[e.config.styleId])return`InvalidTableConfig`;break;case`CREATE_TABLE_STYLE`:if(!pj[e.templateName])return`InvalidTableStyle`;try{pn(e.primaryColor)}catch{return`InvalidTableStyle`}break}return`Success`}handle(e){switch(e.type){case`CREATE_TABLE_STYLE`:let t=mj(e.tableStyleName,e.templateName,e.primaryColor);this.history.update(`styles`,e.tableStyleId,t);break;case`REMOVE_TABLE_STYLE`:let n={...this.styles};delete n[e.tableStyleId],this.history.update(`styles`,n);for(let t of this.getters.getSheetIds())for(let n of this.getters.getCoreTables(t))n.config.styleId===e.tableStyleId&&this.dispatch(`UPDATE_TABLE`,{sheetId:t,zone:n.range.zone,config:{styleId:QA.styleId}});break}}getTableStyle(e){if(!this.styles[e])throw Error(`Table style ${e} does not exist`);return this.styles[e]}getTableStyles(){return this.styles}getNewCustomTableStyleName(){return an(E(`Custom Table Style`),Object.values(this.styles).map(e=>e.displayName),{compute:(e,t)=>`${e} ${t}`,start:2})}isTableStyleEditable(e){return!fj[e]}import(e){for(let e in fj)this.styles[e]=fj[e];for(let t in e.customTableStyles){let n=e.customTableStyles[t];this.styles[t]=mj(n.displayName,n.templateName,n.primaryColor)}}export(e){let t={};for(let e in this.styles)fj[e]||(t[e]={displayName:this.styles[e].displayName,templateName:this.styles[e].templateName,primaryColor:this.styles[e].primaryColor});e.customTableStyles=t}},xW=class extends Lp{getters;constructor({getters:e,stateObserver:t}){super(t),this.getters=e}};let SW=new g;SW.add(`pivots`,e=>{for(let t of e.getPivotIds())e.getPivot(t).markAsDirtyForEvaluation?.()});let CW=zS.mapping;function wW(e,t,n){return new TW(e,t,n).getParameters()}var TW=class{getters;computeCell;evalContext;rangeCache={};constructor(e,t,n){this.getters=t,this.computeCell=n,this.evalContext=Object.assign(Object.create(CW),e,{getters:this.getters,locale:this.getters.getLocale()})}getParameters(){return{referenceDenormalizer:this.refFn.bind(this),ensureRange:this.range.bind(this),evalContext:this.evalContext}}refFn(e,t){let n=this.getRangeError(e);if(n)return n;let r={sheetId:e.sheetId,col:e.zone.left,row:e.zone.top};return t?(this.computeCell(r),{value:Mc(this.getters.getSheetName(e.sheetId),As(e.zone))}):this.computeCell(r)}range(e,t){let n=this.getRangeError(e);if(n)return[[n]];let r=e.sheetId,i=e.zone,a=Ls(i,this.getters.getSheetZone(r));if(!a)return[[]];let{top:o,left:s,bottom:c,right:l}=i,u=`${r}-${o}-${s}-${c}-${l}-${t}`;if(u in this.rangeCache)return this.rangeCache[u];let d=a.bottom-a.top+1,f=a.right-a.left+1,p=Array(f),m=this.getters.getSheetName(e.sheetId);for(let e=a.left;e<=a.right;e++){let n=e-a.left;p[n]=Array(d);for(let i=a.top;i<=a.bottom;i++){let o=i-a.top,s=this.computeCell({sheetId:r,col:e,row:i});p[n][o]=t?{value:Mc(m,T(e,i))}:s}}return this.rangeCache[u]=p,p}getRangeError(e){if(!Os(e.zone))return new Yi;if(e.invalidSheetName)return new Yi(E(`Invalid sheet name: %s`,e.invalidSheetName))}},EW=d(c(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self).RBush=r()})(e,function(){"use strict";function e(e,r,i,a,o){(function e(n,r,i,a,o){for(;a>i;){if(a-i>600){var s=a-i+1,c=r-i+1,l=Math.log(s),u=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*u*(s-u)/s)*(c-s/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-c*u/s+d)),Math.min(a,Math.floor(r+(s-c)*u/s+d)),o)}var f=n[r],p=i,m=a;for(t(n,i,r),o(n[a],f)>0&&t(n,i,a);p<m;){for(t(n,p,m),p++,m--;o(n[p],f)<0;)p++;for(;o(n[m],f)>0;)m--}o(n[i],f)===0?t(n,i,m):t(n,++m,a),m<=r&&(i=m+1),r<=m&&(a=m-1)}})(e,r,i||0,a||e.length-1,o||n)}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return e<t?-1:+(e>t)}var r=function(e){e===void 0&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function i(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function a(e,t){o(e,0,e.children.length,t,e)}function o(e,t,n,r,i){i||=m(null),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var a=t;a<n;a++){var o=e.children[a];s(i,e.leaf?r(o):o)}return i}function s(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function c(e,t){return e.minX-t.minX}function l(e,t){return e.minY-t.minY}function u(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function d(e){return e.maxX-e.minX+(e.maxY-e.minY)}function f(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function p(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function m(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function h(t,n,r,i,a){for(var o=[n,r];o.length;)if(!((r=o.pop())-(n=o.pop())<=i)){var s=n+Math.ceil((r-n)/i/2)*i;e(t,s,n,r,a),o.push(n,s,s,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(e){var t=this.data,n=[];if(!p(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var a=0;a<t.children.length;a++){var o=t.children[a],s=t.leaf?r(o):o;p(e,s)&&(t.leaf?n.push(o):f(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n},r.prototype.collides=function(e){var t=this.data;if(!p(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],a=t.leaf?this.toBBox(i):i;if(p(e,a)){if(t.leaf||f(e,a))return!0;n.push(i)}}t=n.pop()}return!1},r.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},r.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(e,t){if(!e)return this;for(var n,r,a,o=this.data,s=this.toBBox(e),c=[],l=[];o||c.length;){if(o||(o=c.pop(),r=c[c.length-1],n=l.pop(),a=!0),o.leaf){var u=i(e,o.children,t);if(u!==-1)return o.children.splice(u,1),c.push(o),this._condense(c),this}a||o.leaf||!f(o,s)?r?(n++,o=r.children[n],a=!1):o=null:(c.push(o),l.push(n),n=0,r=o,o=o.children[0])}return this},r.prototype.toBBox=function(e){return e},r.prototype.compareMinX=function(e,t){return e.minX-t.minX},r.prototype.compareMinY=function(e,t){return e.minY-t.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(e){return this.data=e,this},r.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},r.prototype._build=function(e,t,n,r){var i,o=n-t+1,s=this._maxEntries;if(o<=s)return a(i=m(e.slice(t,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/s**(r-1))),(i=m([])).leaf=!1,i.height=r;var c=Math.ceil(o/s),l=c*Math.ceil(Math.sqrt(s));h(e,t,n,l,this.compareMinX);for(var u=t;u<=n;u+=l){var d=Math.min(u+l-1,n);h(e,u,d,c,this.compareMinY);for(var f=u;f<=d;f+=c){var p=Math.min(f+c-1,d);i.children.push(this._build(e,f,p,r-1))}}return a(i,this.toBBox),i},r.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,a=1/0,o=void 0,s=0;s<t.children.length;s++){var c=t.children[s],l=u(c),d=(f=e,p=c,(Math.max(p.maxX,f.maxX)-Math.min(p.minX,f.minX))*(Math.max(p.maxY,f.maxY)-Math.min(p.minY,f.minY))-l);d<a?(a=d,i=l<i?l:i,o=c):d===a&&l<i&&(i=l,o=c)}t=o||t.children[0]}var f,p;return t},r.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),s(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},r.prototype._split=function(e,t){var n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var o=this._chooseSplitIndex(n,i,r),s=m(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,a(n,this.toBBox),a(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)},r.prototype._splitRoot=function(e,t){this.data=m([e,t]),this.data.height=e.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(e,t,n){for(var r,i,a,s,c,l,d,f=1/0,p=1/0,m=t;m<=n-t;m++){var h=o(e,0,m,this.toBBox),g=o(e,m,n,this.toBBox),_=(i=h,a=g,s=void 0,c=void 0,l=void 0,d=void 0,s=Math.max(i.minX,a.minX),c=Math.max(i.minY,a.minY),l=Math.min(i.maxX,a.maxX),d=Math.min(i.maxY,a.maxY),Math.max(0,l-s)*Math.max(0,d-c)),v=u(h)+u(g);_<f?(f=_,r=m,p=v<p?v:p):_===f&&v<p&&(p=v,r=m)}return r||n-t},r.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:c,i=e.leaf?this.compareMinY:l;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},r.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var i=this.toBBox,a=o(e,0,t,i),c=o(e,n-t,n,i),l=d(a)+d(c),u=t;u<n-t;u++){var f=e.children[u];s(a,e.leaf?i(f):f),l+=d(a)}for(var p=n-t-1;p>=t;p--){var m=e.children[p];s(c,e.leaf?i(m):m),l+=d(c)}return l},r.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)s(t[r],e)},r.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():a(e[t],this.toBBox)},r})}))(),1),DW=class{rTrees={};constructor(e=[]){let t={};for(let n of e){let e=n.boundingBox.sheetId;t[e]||(t[e]=[]),t[e].push(n)}for(let e in t)this.rTrees[e]=new OW,this.rTrees[e].load(t[e])}insert(e){let t=e.boundingBox.sheetId;this.rTrees[t]||(this.rTrees[t]=new OW),this.rTrees[t].insert(e)}search({zone:e,sheetId:t}){return this.rTrees[t]?this.rTrees[t].search({minX:e.left,minY:e.top,maxX:e.right,maxY:e.bottom}):[]}remove(e){let t=e.boundingBox.sheetId;this.rTrees[t]&&this.rTrees[t].remove(e,this.rtreeItemComparer)}rtreeItemComparer(e,t){return e.boundingBox.sheetId===t.boundingBox.sheetId&&e.boundingBox?.zone.left===t.boundingBox.zone.left&&e.boundingBox?.zone.top===t.boundingBox.zone.top&&e.boundingBox?.zone.right===t.boundingBox.zone.right&&e.boundingBox?.zone.bottom===t.boundingBox.zone.bottom&&w(e.data,t.data)}},OW=class extends EW.default{toBBox({boundingBox:e}){let t=e.zone;return{minX:t.left,minY:t.top,maxX:t.right,maxY:t.bottom}}compareMinX(e,t){return e.boundingBox.zone.left-t.boundingBox.zone.left}compareMinY(e,t){return e.boundingBox.zone.top-t.boundingBox.zone.top}},kW=class e{profilesStartingPosition=[0];profiles=new Map([[0,[]]]);constructor(e=[]){for(let t of e)this.add(t)}isEmpty(){return this.profiles.size===1&&this.profiles.get(0)?.length===0}add(e){hs(this.profilesStartingPosition,this.profiles,[e])}delete(e){hs(this.profilesStartingPosition,this.profiles,[e],!0)}has(e){return gs(this.profilesStartingPosition,this.profiles,e)}difference(e){let t=this.copy();for(let n of e)t.delete(n);return t}copy(){let t=new e;t.profilesStartingPosition=[...this.profilesStartingPosition],t.profiles=new Map;for(let[e,n]of this.profiles)t.profiles.set(e,[...n]);return t}[Symbol.iterator](){return bs(this.profilesStartingPosition,this.profiles)[Symbol.iterator]()}},AW=class e{setsBySheetId={};constructor(e=[]){for(let t of e)this.add(t)}add(e){this.setsBySheetId[e.sheetId]||(this.setsBySheetId[e.sheetId]=new kW),this.setsBySheetId[e.sheetId].add(e.zone)}addMany(e){for(let t of e)this.add(t)}addPosition(e){this.add(Uc(e))}addManyPositions(e){for(let t of e)this.addPosition(t)}has(e){return this.setsBySheetId[e.sheetId]?this.setsBySheetId[e.sheetId].has(e.zone):!1}hasPosition(e){return this.has(Uc(e))}delete(e){this.setsBySheetId[e.sheetId]&&this.setsBySheetId[e.sheetId].delete(e.zone)}deleteMany(e){for(let t of e)this.delete(t)}deleteManyPositions(e){for(let t of e)this.delete(Uc(t))}difference(t){let n=new e;for(let e in this.setsBySheetId)n.setsBySheetId[e]=this.setsBySheetId[e];for(let e in t.setsBySheetId)n.setsBySheetId[e]&&(n.setsBySheetId[e]=n.setsBySheetId[e].difference(t.setsBySheetId[e]));return n}copy(){let t=new e;for(let e in this.setsBySheetId)t.setsBySheetId[e]=this.setsBySheetId[e].copy();return t}clear(){this.setsBySheetId={}}isEmpty(){for(let e in this.setsBySheetId)if(!this.setsBySheetId[e].isEmpty())return!1;return!0}[Symbol.iterator](){let e=[];for(let t in this.setsBySheetId)for(let n of this.setsBySheetId[t])e.push({sheetId:t,zone:n});return e[Symbol.iterator]()}},jW=class{rTree;constructor(e=[]){let t=MW(e);this.rTree=new DW(t)}insert(e){let t=this.rTree.search(e.boundingBox),n=e.boundingBox,r=t.find(({boundingBox:e})=>e.sheetId===n.sheetId&&e.zone.left===n.zone.left&&e.zone.top===n.zone.top&&e.zone.right===n.zone.right&&e.zone.bottom===n.zone.bottom);r?r.data.add(e.data):this.rTree.insert({...e,data:new AW([e.data])})}search({zone:e,sheetId:t}){let n=new AW;for(let{data:r}of this.rTree.search({zone:e,sheetId:t}))n.addMany(r);return n}remove(e){let t=this.rTree.search(e.boundingBox),n=e.boundingBox,r=t.find(({boundingBox:e})=>e.sheetId===n.sheetId&&e.zone.left===n.zone.left&&e.zone.top===n.zone.top&&e.zone.right===n.zone.right&&e.zone.bottom===n.zone.bottom);r?r.data.delete(e.data):this.rTree.remove({...e,data:new AW([e.data])})}};function MW(e){let t=0,n=0;for(let r=0;r<e.length;r++){let i=e[r].boundingBox.zone;i.right>t&&(t=i.right),i.bottom>n&&(n=i.bottom)}t+=1,n+=1;let r=(((n+1)*t+1)*n+1)*t<=2**53-1;r||console.warn(`Max col/row size exceeded, using slow zone key`);let i={};for(let a of e){let e=a.boundingBox.sheetId;i[e]||(i[e]={});let o=a.boundingBox.zone,s=0;s=r?o.left+o.top*t+o.right*t*n+o.bottom*t*n*t:`${o.left},${o.top},${o.right},${o.bottom}`,i[e][s]?i[e][s].data.add(a.data):i[e][s]={boundingBox:a.boundingBox,data:new AW([a.data])}}let a=[];for(let e in i){let t=i[e];for(let e in t)a.push(t[e])}return a}var NW=class{dependencies=new LF;rTree;constructor(e=[]){this.rTree=new jW(e)}removeAllDependencies(e){let t=this.dependencies.get(e);if(t){for(let e of t)this.rTree.remove(e);this.dependencies.delete(e)}}addDependencies(e,t){let n=t.map(({sheetId:t,zone:n})=>({data:{sheetId:e.sheetId,zone:R(e)},boundingBox:{zone:n,sheetId:t}}));for(let e of n)this.rTree.insert(e);let r=this.dependencies.get(e);r?r.push(...n):this.dependencies.set(e,n)}getCellsDependingOn(e,t=new AW){t=t.copy();let n=Array.from(e).reverse();for(;n.length>0;){let e=n.pop();t.add(e);let r=this.rTree.search(e);n.push(...r.difference(t))}for(let n of e)t.delete(n);return t}},PW=class extends Uint32Array{columnOffset=0;cols=0;rows=0;static create(e,t){let n=FW(t),r=e<<n>>5,i=new this(r+1);return i.columnOffset=n,i.cols=t,i.rows=e,i}getValue(e){let[t,n]=this.getCoordinates(e);return this[t]>>n&1}setValue(e,t){let[n,r]=this.getCoordinates(e),i=(this[n]>>r&1)==0&&t===1;return this[n]=this[n]&~(1<<r)|t<<r,i}isEmpty(){return!this.some(e=>e!==0)}fillAllPositions(){this.fill(-1>>>0)}clear(){this.fill(0)}getCoordinates(e){let{row:t,col:n}=e,r=(t<<this.columnOffset)+n,i=r>>5;return[i,r-(i<<5)]}};function FW(e){return e===0?-1/0:e<0?NaN:32-Math.clz32(--e)}var IW=class{sheets={};insertions=[];maxSize=0;constructor(e){for(let t in e){let n=e[t].cols,r=e[t].rows;this.maxSize+=n*r,this.sheets[t]=PW.create(r,n)}}add(e){this.sheets[e.sheetId].setValue(e,1)&&this.insertions.push(e)}addMany(e){for(let t of e)this.add(t)}delete(e){this.sheets[e.sheetId].setValue(e,0)}deleteMany(e){for(let t of e)this.delete(t)}has(e){return this.sheets[e.sheetId].getValue(e)===1}clear(){let e=[...this];this.insertions=[];for(let e in this.sheets)this.sheets[e].clear();return e}isEmpty(){if(this.insertions.length===0)return!0;for(let e in this.sheets)if(!this.sheets[e].isEmpty())return!1;return!0}fillAllPositions(){this.insertions=Array(this.maxSize);let e=0;for(let t in this.sheets){let n=this.sheets[t];n.fillAllPositions();for(let r=0;r<n.rows;r++)for(let i=0;i<n.cols;i++)this.insertions[e++]={sheetId:t,row:r,col:i}}}*[Symbol.iterator](){for(let e of this.insertions)this.sheets[e.sheetId].getValue(e)===1&&(yield e)}},LW=class{resultsToArrayFormulas=new DW;arrayFormulasToResults=new LF;searchFormulaPositionsSpreadingOn(e,t){return this.resultsToArrayFormulas.search({sheetId:e,zone:t}).map(e=>e.data)||RW}getArrayResultZone(e){return this.arrayFormulasToResults.get(e)}removeNode(e){let t=this.arrayFormulasToResults.get(e);t&&(this.resultsToArrayFormulas.remove({boundingBox:{sheetId:e.sheetId,zone:t},data:e}),this.arrayFormulasToResults.delete(e))}addRelation({arrayFormulaPosition:e,resultZone:t}){this.resultsToArrayFormulas.insert({boundingBox:{sheetId:e.sheetId,zone:t},data:e}),this.arrayFormulasToResults.set(e,t)}isArrayFormula(e){return this.arrayFormulasToResults.has(e)}};let RW=[],zW=Object.freeze(ns({...new Ji,origin:void 0})),BW=Object.freeze(ns({value:null}));var VW=class{context;getters;compilationParams;evaluatedCells=new LF;formulaDependencies=Nt(new NW);blockedArrayFormulas=new IW({});spreadingRelations=new LW;constructor(e,t){this.context=e,this.getters=t,this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this))}getEvaluatedCell(e){return this.evaluatedCells.get(e)||BW}getSpreadZone(e,t={ignoreSpillError:!1}){let n=this.spreadingRelations.getArrayResultZone(e);if(!n)return;let r=this.evaluatedCells.get(e);return r?.type===`error`&&!(t.ignoreSpillError&&r?.value===k.SpilledBlocked)?R(e):Fs(R(e),n)}getEvaluatedPositions(){return this.evaluatedCells.keys()}getEvaluatedPositionsInSheet(e){return this.evaluatedCells.keysForSheet(e)}getArrayFormulaSpreadingOn(e){if(this.getEvaluatedCell(e).type!==`empty`)return this.spreadingRelations.searchFormulaPositionsSpreadingOn(e.sheetId,R(e)).find(e=>!this.blockedArrayFormulas.has(e))}isArrayFormulaSpillBlocked(e){return this.blockedArrayFormulas.has(e)}updateDependencies(e){this.formulaDependencies().removeAllDependencies(e);let t=this.getDirectDependencies(e);this.formulaDependencies().addDependencies(e,t)}addDependencies(e,t){this.formulaDependencies().addDependencies(e,t);for(let e of t)this.compilationParams.ensureRange(e,!1)}updateCompilationParametersForIsolatedFormula(e){this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this)),this.compilationParams.evalContext.__originCellPosition=e,this.compilationParams.evalContext.updateDependencies=void 0,this.compilationParams.evalContext.addDependencies=void 0,this.compilationParams.evalContext.lookupCaches=this.compilationParams.evalContext.lookupCaches||{forwardSearch:new Map,reverseSearch:new Map}}updateCompilationParameters(){this.compilationParams=wW(this.context,this.getters,this.computeAndSave.bind(this)),this.compilationParams.evalContext.updateDependencies=this.updateDependencies.bind(this),this.compilationParams.evalContext.addDependencies=this.addDependencies.bind(this),this.compilationParams.evalContext.lookupCaches={forwardSearch:new Map,reverseSearch:new Map}}createEmptyPositionSet(){let e={};for(let t of this.getters.getSheetIds())e[t]={rows:this.getters.getNumberRows(t),cols:this.getters.getNumberCols(t)};return new IW(e)}evaluateCells(e){let t=performance.now(),n=new AW;n.addManyPositions(e);let r=this.getArrayFormulasImpactedByChangesOf(e);n.addMany(this.getCellsDependingOn(n)),n.addMany(r),n.addMany(this.getCellsDependingOn(r)),this.evaluate(n),console.debug(`evaluate Cells`,performance.now()-t,`ms`)}getArrayFormulasImpactedByChangesOf(e){let t=new AW;for(let n of e){let e=this.getters.getCell(n)?.content,r=this.getArrayFormulaSpreadingOn(n);r!==void 0&&t.addPosition(r),e||t.addPosition(n)}for(let e of[...t])t.addMany(this.getArrayFormulasBlockedBy(e.sheetId,e.zone));return t}buildDependencyGraph(){this.blockedArrayFormulas=this.createEmptyPositionSet(),this.spreadingRelations=new LW,this.formulaDependencies=Nt(()=>{let e=[];for(let t of this.getters.getSheetIds()){let n=this.getters.getCells(t);for(let r in n){let i=n[r];if(i.isFormula){let n=i.compiledFormula.dependencies;for(let i of n)i.invalidSheetName||i.invalidXc||e.push({data:{sheetId:t,zone:R(this.getters.getCellPosition(r))},boundingBox:{sheetId:i.sheetId,zone:i.zone}})}}}return new NW(e)})}evaluateAllCells(){let e=performance.now();this.evaluatedCells=new LF;let t=[];for(let e of this.getters.getSheetIds()){let n=this.getters.getSheetZone(e);t.push({sheetId:e,zone:n})}this.evaluate(t),console.debug(`evaluate all cells`,performance.now()-e,`ms`)}evaluateFormulaResult(e,t,n){let r=rC(t),i=r.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t));return this.updateCompilationParametersForIsolatedFormula(n),this.evaluateCompiledFormula(e,{...r,dependencies:i})}evaluateCompiledFormula(e,t,n){try{let r=WW(t,this.compilationParams,e,this.buildSafeGetSymbolValue(n),this.compilationParams.evalContext.__originCellPosition);return Ir(r)?Ca(r,UW):UW(r)}catch(e){return VS(e,``)}}getArrayFormulasBlockedBy(e,t){let n=new AW,r=this.spreadingRelations.searchFormulaPositionsSpreadingOn(e,t);n.addManyPositions(r);let i=[...r].filter(e=>!this.blockedArrayFormulas.has(e));return i.length&&n.deleteManyPositions(i),n.addMany(this.getCellsDependingOn(n)),n}nextRangesToUpdate=new AW;cellsBeingComputed=new Set;symbolsBeingComputed=new Set;evaluate(e){this.cellsBeingComputed=new Set,this.nextRangesToUpdate=new AW(e);let t=0;for(;!this.nextRangesToUpdate.isEmpty()&&t++<30;){this.updateCompilationParameters();let e=[...this.nextRangesToUpdate];this.nextRangesToUpdate.clear(),this.clearEvaluatedRanges(e);for(let t of e){let{left:e,bottom:n,right:r,top:i}=t.zone;for(let a=e;a<=r;a++)for(let e=i;e<=n;e++){let n={sheetId:t.sheetId,col:a,row:e};if(this.nextRangesToUpdate.hasPosition(n))continue;let r=this.computeCell(n);r!==BW&&this.evaluatedCells.set(n,r)}}SW.getAll().forEach(e=>e(this.getters))}t>=30&&console.warn(`Maximum iteration reached while evaluating cells`)}clearEvaluatedRanges(e){for(let t of e){let{left:e,bottom:n,right:r,top:i}=t.zone;for(let a=e;a<=r;a++)for(let e=i;e<=n;e++)this.evaluatedCells.delete({sheetId:t.sheetId,col:a,row:e})}}computeCell(e){let t=this.evaluatedCells.get(e);if(t)return t;this.blockedArrayFormulas.has(e)||this.invalidateSpreading(e),this.spreadingRelations.isArrayFormula(e)&&this.spreadingRelations.removeNode(e);let n=this.getters.getCell(e);if(n===void 0)return BW;let r=n.id,i={format:n.format,locale:this.getters.getLocale()};try{return this.cellsBeingComputed.has(r)?zW:(this.cellsBeingComputed.add(r),n.isFormula?this.computeFormulaCell(e,n):es(n,i,e))}catch(t){return t.value=t?.value||k.GenericError,t.message=t?.message||WS,t.origin=e,t.errorOriginPosition=t?.errorOriginPosition,ns(t)}finally{this.cellsBeingComputed.delete(r)}}computeAndSave(e){let t=this.computeCell(e);return this.evaluatedCells.has(e)||this.evaluatedCells.set(e,t),t}computeFormulaCell(e,t){let n=WW(t.compiledFormula,this.compilationParams,e.sheetId,this.buildSafeGetSymbolValue(),e);if(!Ir(n)){let r=ns(UW(n),this.getters.getLocale(),t,e);return r.type===`error`&&(r.errorOriginPosition=n.errorOriginPosition??e),r}this.assertSheetHasEnoughSpaceToSpreadFormulaResult(e,n);let r=n.length,i=n[0].length;if(i===0)return ns({value:0},this.getters.getLocale(),t);if(i===1&&r===1)return ns(UW(n[0][0]),this.getters.getLocale(),t);let a={top:e.row,bottom:e.row+i-1,left:e.col,right:e.col+r-1};return this.spreadingRelations.addRelation({resultZone:a,arrayFormulaPosition:e}),this.assertNoMergedCellsInSpreadZone(e,n),HW(r,i,this.checkCollision(e)),HW(r,i,this.spreadValues(e,n)),this.invalidatePositionsDependingOnSpread(e.sheetId,a),ns(UW(n[0][0]),this.getters.getLocale(),t)}invalidatePositionsDependingOnSpread(e,t){let n=this.getCellsDependingOn(Gs(t).map(t=>({sheetId:e,zone:t})));n.delete({sheetId:e,zone:t}),this.nextRangesToUpdate.addMany(n)}assertSheetHasEnoughSpaceToSpreadFormulaResult({sheetId:e,col:t,row:n},r){let i=this.getters.getNumberCols(e),a=this.getters.getNumberRows(e),o=t+r.length<=i,s=n+r[0].length<=a;if(!(o&&s))throw o?new Qi(E(`Result couldn't be automatically expanded. Please insert more rows.`)):s?new Qi(E(`Result couldn't be automatically expanded. Please insert more columns.`)):new Qi(E(`Result couldn't be automatically expanded. Please insert more columns and rows.`))}assertNoMergedCellsInSpreadZone({sheetId:e,col:t,row:n},r){if(this.getters.getMergesInZone(e,{top:n,bottom:n+r[0].length-1,left:t,right:t+r.length-1}).length!==0)throw new Qi(E(`Merged cells found in the spill zone. Please unmerge cells before using array formulas.`))}checkCollision(e){let{sheetId:t,col:n,row:r}=e;return(i,a)=>{let o={sheetId:t,col:i+n,row:a+r};if(this.getters.getCell(o)?.content||this.getters.getEvaluatedCell(o).type!==`empty`)throw this.blockedArrayFormulas.add(e),new Qi(E(`Array result was not expanded because it would overwrite data.`),o);this.blockedArrayFormulas.delete(e)}}spreadValues({sheetId:e,col:t,row:n},r){return(i,a)=>{let o={sheetId:e,col:i+t,row:a+n},s=this.getters.getCell(o),c=ns(UW(r[i][a]),this.getters.getLocale(),s,o);c.type===`error`&&(c.errorOriginPosition=r[i][a].errorOriginPosition??o),this.evaluatedCells.set(o,c)}}invalidateSpreading(e){let t=this.spreadingRelations.getArrayResultZone(e);if(!t)return;for(let n=t.left;n<=t.right;n++)for(let r=t.top;r<=t.bottom;r++){let t={sheetId:e.sheetId,col:n,row:r};this.getters.getCell(t)?.content||this.evaluatedCells.delete(t)}let n=e.sheetId;this.invalidatePositionsDependingOnSpread(n,t),this.nextRangesToUpdate.addMany(this.getArrayFormulasBlockedBy(n,t))}buildSafeGetSymbolValue(e){return t=>{if(this.symbolsBeingComputed.has(t))return zW;this.symbolsBeingComputed.add(t);try{return e?.(t)||new qi(E(`Invalid formula`))}finally{this.symbolsBeingComputed.delete(t)}}}getDirectDependencies(e){let t=this.getters.getCell(e);return t?.isFormula?t.compiledFormula.dependencies:[]}getCellsDependingOn(e){return this.formulaDependencies().getCellsDependingOn(e,this.nextRangesToUpdate)}};function HW(e,t,n){for(let r=0;r<e;++r)for(let e=0;e<t;++e)r===0&&e===0||n(r,e)}function UW(e){return e.value===null||e.value===void 0?{...e,value:0}:e}function WW(e,t,n,r,i){let a=t.evalContext,o=a.__originCellPosition,s=a.__originSheetId;a.__originCellPosition=i,a.__originSheetId=n;let c=e.execute(e.dependencies,t.referenceDenormalizer,t.ensureRange,r,a);return a.__originCellPosition=o,a.__originSheetId=s,c}var GW=class extends xW{static getters=[`evaluateFormula`,`evaluateFormulaResult`,`evaluateCompiledFormula`,`getCorrespondingFormulaCell`,`getRangeFormattedValues`,`getRangeValues`,`getRangeFormats`,`getEvaluatedCell`,`getEvaluatedCells`,`getEvaluatedCellsInZone`,`getEvaluatedCellsPositions`,`getSpreadZone`,`getArrayFormulaSpreadingOn`,`isArrayFormulaSpillBlocked`,`isEmpty`];shouldRebuildDependenciesGraph=!0;evaluator;positionsToUpdate=[];constructor(e){super(e),this.evaluator=new VW(e.custom,this.getters)}beforeHandle(e){(yr.has(e.type)||xr.has(e.type))&&(this.shouldRebuildDependenciesGraph=!0)}handle(e){switch(e.type){case`UPDATE_CELL`:if(!(`content`in e||`format`in e)||this.shouldRebuildDependenciesGraph)return;let t={sheetId:e.sheetId,row:e.row,col:e.col};this.positionsToUpdate.push(t),`content`in e&&this.evaluator.updateDependencies(t);break;case`EVALUATE_CELLS`:if(e.cellIds)for(let t=0;t<e.cellIds.length;t++)this.positionsToUpdate.push(this.getters.getCellPosition(e.cellIds[t]));else this.evaluator.evaluateAllCells();break}}finalize(){this.shouldRebuildDependenciesGraph?(this.evaluator.buildDependencyGraph(),this.evaluator.evaluateAllCells(),this.shouldRebuildDependenciesGraph=!1):this.positionsToUpdate.length&&this.evaluator.evaluateCells(this.positionsToUpdate),this.positionsToUpdate=[]}evaluateFormula(e,t,n){let r=this.evaluateFormulaResult(e,t,n);return Ir(r)?Ca(r,e=>e.value):r.value}evaluateFormulaResult(e,t,n){return this.evaluator.evaluateFormulaResult(e,t,n)}evaluateCompiledFormula(e,t,n){return this.evaluator.evaluateCompiledFormula(e,t,n)}getRangeFormattedValues(e){return this.getters.tryGetSheet(e.sheetId)===void 0?[]:this.mapVisiblePositions(e,e=>this.getters.getEvaluatedCell(e).formattedValue)}getRangeValues(e){return this.getters.tryGetSheet(e.sheetId)===void 0?[]:this.mapVisiblePositions(e,e=>this.getters.getEvaluatedCell(e).value)}getRangeFormats(e){let t=this.getters.tryGetSheet(e.sheetId);return t===void 0?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map(e=>e.format)}getEvaluatedCell(e){return this.evaluator.getEvaluatedCell(e)}getEvaluatedCells(e){return this.evaluator.getEvaluatedPositionsInSheet(e).map(e=>this.getEvaluatedCell(e))}getEvaluatedCellsPositions(e){return this.evaluator.getEvaluatedPositionsInSheet(e)}getEvaluatedCellsInZone(e,t){return Ks(t).map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}))}getSpreadZone(e,t={ignoreSpillError:!1}){return this.evaluator.getSpreadZone(e,t)}getArrayFormulaSpreadingOn(e){return this.evaluator.getArrayFormulaSpreadingOn(e)}isArrayFormulaSpillBlocked(e){return this.evaluator.isArrayFormulaSpillBlocked(e)}isEmpty(e,t){return Ks(t).map(({col:t,row:n})=>this.getEvaluatedCell({sheetId:e,col:t,row:n})).every(e=>e.type===`empty`)}mapVisiblePositions(e,t){let{sheetId:n,zone:r}=e;return Ks(r).reduce((e,r)=>{let{col:i,row:a}=r;return!this.getters.isColHidden(n,i)&&!this.getters.isRowHidden(n,a)&&e.push(t({sheetId:n,...r})),e},[])}exportForExcel(e){for(let t of e.sheets)t.cellValues={},t.formulaSpillRanges={};for(let t of this.evaluator.getEvaluatedPositions()){let n=this.evaluator.getEvaluatedCell(t),r=T(t.col,t.row),i=n.value,a=!1,o,s=!0,c=e.sheets.find(e=>e.id===t.sheetId),l=this.getCorrespondingFormulaCell(t);if(l){let u=this.getters.getCell(t);if(s=dC(l.compiledFormula.tokens),a=s&&u?.content===l.content,!s&&i!==``){o=(i??``).toString();let t=n.format;if(t){let n=mc(t,e.formats);c.formats[r]=n}}}let u=c.cells[r],d;d=s&&a&&l instanceof $U?l.contentWithFixedReferences:s?u:o,c.cells[r]=d,c.cellValues[r]=i===k.BadExpression?void 0:i;let f=this.getSpreadZone(t);f&&(c.formulaSpillRanges[r]=this.getters.getRangeString(this.getters.getRangeFromZone(t.sheetId,f),t.sheetId))}}getCorrespondingFormulaCell(e){let t=this.getters.getCell(e);if(t&&t.isFormula)return t.compiledFormula.isBadExpression?void 0:t;if(t&&t.content)return;let n=this.getArrayFormulaSpreadingOn(e);if(n===void 0)return;let r=this.getters.getCell(n);if(r?.isFormula)return r}};let KW=/"(#[0-9a-fA-F]{6})"/g;function qW(e){let t=[{leadColor:_n(255,0,0),colors:[]},{leadColor:_n(255,128,0),colors:[]},{leadColor:_n(128,128,0),colors:[]},{leadColor:_n(128,255,0),colors:[]},{leadColor:_n(0,255,0),colors:[]},{leadColor:_n(0,255,128),colors:[]},{leadColor:_n(0,255,255),colors:[]},{leadColor:_n(0,127,255),colors:[]},{leadColor:_n(0,0,255),colors:[]},{leadColor:_n(127,0,255),colors:[]},{leadColor:_n(128,0,128),colors:[]},{leadColor:_n(255,0,128),colors:[]}];for(let n of e.map(xn)){let e=500,r=0;t.forEach((t,i)=>{let a=JW(n,t.leadColor);e>a&&(e=a,r=i)}),t[r].colors.push(n)}return t.map(e=>e.colors.sort((e,t)=>Cn(e).s-Cn(t).s)).flat().map(bn)}function JW(e,t){return Math.sqrt((e.r-t.r)**2+(e.g-t.g)**2+(e.b-t.b)**2)}var YW=class extends xW{customColors={};shouldUpdateColors=!0;static getters=[`getCustomColors`];constructor(e){super(e),this.tryToAddColors(e.customColors??[])}handle(e){switch(e.type){case`START`:for(let e of this.getters.getSheetIds())for(let t of this.getters.getChartIds(e))this.tryToAddColors(this.getChartColors(t));break;case`UPDATE_CHART`:case`CREATE_CHART`:this.tryToAddColors(this.getChartColors(e.chartId));break;case`UPDATE_CELL`:case`ADD_CONDITIONAL_FORMAT`:case`SET_BORDER`:case`SET_ZONE_BORDERS`:case`SET_FORMATTING`:case`CREATE_TABLE`:case`UPDATE_TABLE`:this.history.update(`shouldUpdateColors`,!0);break}}finalize(){this.shouldUpdateColors&&(this.history.update(`shouldUpdateColors`,!1),this.tryToAddColors(this.computeCustomColors()))}getCustomColors(){return qW(Object.keys(this.customColors))}computeCustomColors(){let e=[];for(let t of this.getters.getSheetIds())e=e.concat(this.getColorsFromCells(t),this.getFormattingColors(t),this.getTableColors(t));return[...new Set([...e])]}getColorsFromCells(e){let t=Object.values(this.getters.getCells(e)),n=new Set;for(let e of t)e.style?.textColor&&n.add(e.style.textColor),e.style?.fillColor&&n.add(e.style.fillColor);for(let t of this.getters.getBordersColors(e))n.add(t);return[...n]}getFormattingColors(e){let t=this.getters.getConditionalFormats(e),n=[];for(let e of t){let t=e.rule;t.type===`CellIsRule`?(n.push(t.style.textColor),n.push(t.style.fillColor)):t.type===`ColorScaleRule`&&(n.push(dn(t.minimum.color)),n.push(t.midpoint?dn(t.midpoint.color):void 0),n.push(dn(t.maximum.color)))}return n.filter(C)}getChartColors(e){let t=this.getters.getChart(e);return t===void 0?[]:[...JSON.stringify(t.getDefinition()).matchAll(KW)].map(e=>e[1])}getTableColors(e){return this.getters.getTables(e).flatMap(e=>{let t=e.config,n=this.getters.getTableStyle(t.styleId);return[this.getTableStyleElementColors(n.wholeTable),t.numberOfHeaders>0?this.getTableStyleElementColors(n.headerRow):[],t.totalRow?this.getTableStyleElementColors(n.totalRow):[],t.bandedColumns?this.getTableStyleElementColors(n.firstColumnStripe):[],t.bandedColumns?this.getTableStyleElementColors(n.secondColumnStripe):[],t.bandedRows?this.getTableStyleElementColors(n.firstRowStripe):[],t.bandedRows?this.getTableStyleElementColors(n.secondRowStripe):[],t.firstColumn?this.getTableStyleElementColors(n.firstColumn):[],t.lastColumn?this.getTableStyleElementColors(n.lastColumn):[]].flat()})}getTableStyleElementColors(e){return e?[e.style?.fillColor,e.style?.textColor,e.border?.bottom?.color,e.border?.top?.color,e.border?.left?.color,e.border?.right?.color,e.border?.horizontal?.color,e.border?.vertical?.color].filter(C):[]}tryToAddColors(e){for(let t of e){if(!mn(t))continue;let e=pn(t);t&&!Ie.includes(e)&&this.history.update(`customColors`,e,!0)}}},XW=class extends xW{static getters=[`getChartRuntime`,`getStyleOfSingleCellChart`];charts={};createRuntimeChart=vO(this.getters);handle(e){if(yr.has(e.type)||Sr.has(e.type)||br.has(e.type))for(let e in this.charts)this.charts[e]=void 0;switch(e.type){case`UPDATE_CHART`:case`CREATE_CHART`:this.charts[e.chartId]=void 0;break;case`DELETE_CHART`:this.charts[e.chartId]=void 0;break;case`DELETE_SHEET`:for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0);break}}getChartRuntime(e){if(!this.charts[e]){let t=this.getters.getChart(e);if(!t)throw Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getStyleOfSingleCellChart(e,t){if(e)return{background:e,fontColor:AC(e)};if(!t)return{background:oe,fontColor:AC(oe)};let n=t.zone.left,r=t.zone.top,i=t.sheetId,a=this.getters.getCellComputedStyle({sheetId:i,col:n,row:r}),o=a.fillColor||`#FFFFFF`;return{background:o,fontColor:a.textColor||AC(o)}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let r of e){if(!r||r.tag!==`chart`)continue;let e=this.getters.getChartIds(t.id).find(e=>this.getters.getFigureIdFromChartId(e)===r.id);if(!e)continue;let i=this.getters.getChart(e),a=i?.getDefinitionForExcel(this.getters);if(a)n.push({...r,data:a});else{if(!i)continue;let n=this.getters.getChartType(e),a=jT(this.getters.getChartRuntime(e),r,n);a&&t.images.push({...r,tag:`image`,data:{mimetype:`image/png`,path:a,size:{width:r.width,height:r.height}}})}}t.charts=n}}},ZW=class extends xW{static getters=[`getConditionalIcon`,`getCellConditionalFormatStyle`,`getConditionalDataBar`];isStale=!0;computedStyles={};computedIcons={};computedDataBars={};handle(e){(yr.has(e.type)||Sr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e))&&(this.isStale=!0)}finalize(){if(this.isStale){for(let e of this.getters.getSheetIds())this.computedStyles[e]=Nt(()=>this.getComputedStyles(e)),this.computedIcons[e]=Nt(()=>this.getComputedIcons(e)),this.computedDataBars[e]=Nt(()=>this.getComputedDataBars(e));this.isStale=!1}}getCellConditionalFormatStyle(e){let{sheetId:t,col:n,row:r}=e,i=this.computedStyles[t]();return i&&i[n]?.[r]}getConditionalIcon({sheetId:e,col:t,row:n}){let r=this.computedIcons[e]();return r&&r[t]?.[n]}getConditionalDataBar({sheetId:e,col:t,row:n}){let r=this.computedDataBars[e]();return r&&r[t]?.[n]}getComputedStyles(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())switch(n.rule.type){case`ColorScaleRule`:for(let r of n.ranges)this.applyColorScale(e,r,n.rule,t);break;case`CellIsRule`:let r=n.rule.values.map(e=>e.startsWith(`=`)?rC(e):void 0);for(let i of n.ranges){let a=this.getters.getRangeFromSheetXC(e,i).zone;for(let i=a.top;i<=a.bottom;i++)for(let o=a.left;o<=a.right;o++){let s={sheetId:e,col:o,row:i},c=n.rule.values.map((t,n)=>{let s=r[n];return s?this.getters.getTranslatedCellFormula(e,o-a.left,i-a.top,s.tokens):t});this.getRuleResultForTarget(s,{...n.rule,values:c})&&(t[o]||(t[o]=[]),t[o][i]=Object.assign(t[o]?.[i]||{},n.rule.style))}}break}return t}getComputedIcons(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())if(n.rule.type===`IconSetRule`)for(let r of n.ranges)this.applyIcon(e,r,n.rule,t);return t}getComputedDataBars(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())if(n.rule.type===`DataBarRule`)for(let r of n.ranges)this.applyDataBar(e,r,n.rule,t);return t}parsePoint(e,t,n,r){let i=this.getters.getRangeFromSheetXC(e,t).zone,a=this.getters.getEvaluatedCellsInZone(e,i).filter(e=>e.type===`number`).map(e=>e.value);switch(n.type){case`value`:return r===`max`?$t(a):en(a);case`number`:return Number(n.value);case`percentage`:let t=en(a);return t+($t(a)-t)*Number(n.value)/100;case`percentile`:return Gi(a,Number(n.value)/100,!0);case`formula`:let i=n.value&&this.getters.evaluateFormula(e,n.value);return typeof i==`number`?i:null;default:return null}}applyIcon(e,t,n,r){let i=this.parsePoint(e,t,n.lowerInflectionPoint),a=this.parsePoint(e,t,n.upperInflectionPoint);if(i===null||a===null||i>a)return;let o=this.getters.getRangeFromSheetXC(e,t).zone,s=[n.icons.upper,n.icons.middle,n.icons.lower];for(let t=o.top;t<=o.bottom;t++)for(let c=o.left;c<=o.right;c++){let o=this.getters.getEvaluatedCell({sheetId:e,col:c,row:t});if(o.type!==`number`)continue;let l=this.computeIcon(o.value,a,n.upperInflectionPoint.operator,i,n.lowerInflectionPoint.operator,s);r[c]||(r[c]=[]),r[c][t]=l}}computeIcon(e,t,n,r,i,a){return n===`ge`&&e>=t||n===`gt`&&e>t?a[0]:i===`ge`&&e>=r||i===`gt`&&e>r?a[1]:a[2]}applyDataBar(e,t,n,r){let i=this.getters.getRangeFromSheetXC(e,n.rangeValues||t),a=$t(this.getters.getEvaluatedCellsInZone(e,i.zone).filter(e=>e.type===`number`).map(e=>e.value));if(a<=0)return;let o=n.color,s=this.getters.getRangeFromSheetXC(e,t).zone,c=i.zone;for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++){let i=n-s.left+c.left,l=t-s.top+c.top,u=this.getters.getEvaluatedCell({sheetId:e,col:i,row:l});!Vs(i,l,c)||u.type!==`number`||u.value<=0||(r[n]||(r[n]=[]),r[n][t]={color:dn(o),percentage:u.value*100/a})}}applyColorScale(e,t,n,r){let i=this.parsePoint(e,t,n.minimum,`min`),a=n.midpoint?this.parsePoint(e,t,n.midpoint):null,o=this.parsePoint(e,t,n.maximum,`max`);if(i===null||o===null||i>=o||a&&(i>=a||a>=o))return;let s=this.getters.getRangeFromSheetXC(e,t).zone,c=[{value:i,color:n.minimum.color}];n.midpoint&&a&&c.push({value:a,color:n.midpoint.color}),c.push({value:o,color:n.maximum.color});let l=Kn(c);for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++){let a=this.getters.getEvaluatedCell({sheetId:e,col:n,row:t});if(a.type===`number`){let e=x(a.value,i,o);r[n]||(r[n]=[]),r[n][t]=r[n]?.[t]||{},r[n][t].fillColor=l(e)}}}getRuleResultForTarget(e,t){let n=this.getters.getEvaluatedCell(e);if(n.type===`error`)return!1;let{sheetId:r}=e,i=Y.get(t.operator),a=t.values.map(t=>t.startsWith(`=`)?this.getters.evaluateFormula(r,t,e)??``:ts(t,D));if(a.some(Wu))return!1;let o={type:t.operator,values:a.map(Hu)};return i.isValueValid(n.value??``,o,this.getters,r)}};let QW={isValid:!0};var $W=class extends xW{static getters=[`getDataValidationInvalidCriterionValueMessage`,`getInvalidDataValidationMessage`,`getValidationResultForCellValue`,`getDataValidationRangeValues`,`isCellValidCheckbox`,`getDataValidationCellStyle`,`getDataValidationChipStyle`,`isDataValidationInvalid`];validationResults={};handle(e){if(yr.has(e.type)||e.type===`EVALUATE_CELLS`||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)){this.validationResults={};return}switch(e.type){case`ADD_DATA_VALIDATION_RULE`:case`REMOVE_DATA_VALIDATION_RULE`:delete this.validationResults[e.sheetId];break}}isDataValidationInvalid(e){return!this.getValidationResultForCell(e).isValid}getDataValidationCellStyle(e){if(!this.hasChip(e))return this.getDataValidationStyle(e)}getDataValidationChipStyle(e){if(this.hasChip(e))return this.getDataValidationStyle(e)??{fillColor:`#E7E9ED`}}getInvalidDataValidationMessage(e){let t=this.getValidationResultForCell(e);return t.isValid?void 0:t.error}getDataValidationInvalidCriterionValueMessage(e,t){let n=Y.get(e);return t.startsWith(`=`)?n.allowedValues===`onlyLiterals`?E(`The value must not be a formula`):this.isValidFormula(t)?void 0:U.CriterionError.validFormula:n.allowedValues===`onlyFormulas`?E(`The value must be a formula`):n.isCriterionValueValid(t)?void 0:n.criterionValueErrorString}getDataValidationRangeValues(e,t){let n=this.getters.getRangeFromSheetXC(e,String(t.values[0])),r=[],i=new Set;for(let e of Ks(n.zone)){let t=this.getters.getEvaluatedCell({...e,sheetId:n.sheetId});t.formattedValue&&!i.has(t.formattedValue)&&(i.add(t.formattedValue),r.push({label:t.formattedValue,value:t.value?.toString()||``}))}return r}isCellValidCheckbox(e){if(!this.getters.isMainCellPosition(e))return!1;let t=this.getters.getValidationRuleForCell(e);return!t||t.criterion.type!==`isBoolean`?!1:this.getValidationResultForCell(e).isValid}getValidationResultForCellValue(e,t){let n=this.getters.getValidationRuleForCell(t);if(!n)return QW;let r=this.getRuleErrorForCellValue(e,t,n);return r?{error:r,rule:n,isValid:!1}:QW}hasChip(e){let t=this.getters.getValidationRuleForCell(e);return(t?.criterion.type===`isValueInList`||t?.criterion.type===`isValueInRange`)&&t.criterion.displayStyle===`chip`}getDataValidationStyle(e){let t=this.getters.getValidationRuleForCell(e);if(!t||this.isDataValidationInvalid(e))return;let n=this.getters.getEvaluatedCell(e),r=this.getValueColor(t,n.value);if(r)return{fillColor:r,textColor:Mn(r)}}getValueColor(e,t){if(!(e.criterion.type!==`isValueInList`&&e.criterion.type!==`isValueInRange`)){for(let n in e.criterion.colors)if(n.toLowerCase()===String(t).toLowerCase())return e.criterion.colors[n]}}isValidFormula(e){return!rC(e).isBadExpression}getValidationResultForCell(e){let{col:t,row:n,sheetId:r}=e;return this.validationResults[r]||(this.validationResults[r]=this.computeSheetValidationResults(r)),this.validationResults[r][t]?.[n]?.()||QW}computeSheetValidationResults(e){let t={},n=this.getters.getDataValidationRules(e).map(e=>e.ranges);for(let e of Vc(n.flat())){let{col:n,row:r}=e;t[n]||(t[n]=[]),t[n][r]=Nt(()=>{let t=this.getters.getEvaluatedCell(e);return t.type===`empty`?QW:this.getValidationResultForCellValue(t.value,e)})}return t}getRuleErrorForCellValue(e,t,n){let{sheetId:r}=t,i=n.criterion,a=Y.get(i.type),o=this.getCellOffsetInRule(t,n),s=this.getEvaluatedCriterionValues(r,t,o,i);if(s.some(Wu))return;let c={...i,values:s.map(Hu)};if(!a.isValueValid(e,c,this.getters,r))return a.getErrorString(c,this.getters,r)}getCellOffsetInRule(e,t){let n=t.ranges.find(t=>Vs(e.col,e.row,t.zone));if(!n)throw Error(`The cell is not in any range of the rule`);return{col:e.col-n.zone.left,row:e.row-n.zone.top}}getEvaluatedCriterionValues(e,t,n,r){return r.values.map(r=>{if(!r.startsWith(`=`))return ts(r,D);let i=rC(r),a=this.getters.getTranslatedCellFormula(e,n.col,n.row,i.tokens);return this.getters.evaluateFormula(e,a,t)})}};let eG=new g;eG.add(`data_validation_checkbox`,(e,t)=>{if(e.isCellValidCheckbox(t)){let n=!!e.getEvaluatedCell(t).value;return{svg:n?Nj:jj,hoverSvg:n?Nj:Mj,priority:2,horizontalAlign:`center`,size:17,margin:2,position:t,type:`data_validation_checkbox`,onClick:(e,t)=>{let r=t.model.getters.getCell(e);if(t.model.getters.isReadonly()||r?.isFormula)return;let i=n?`FALSE`:`TRUE`;t.model.dispatch(`UPDATE_CELL`,{...e,content:i})}}}}),eG.add(`data_validation_chip_icon`,(e,t)=>{let n=e.getDataValidationChipStyle(t);if(n){let r=e.getCellComputedStyle(t);return{svg:kj(n),hoverSvg:Aj(n),priority:10,horizontalAlign:`right`,size:xl(r),margin:4,position:t,onClick:(e,t)=>{let{col:n,row:r}=e;t.model.selection.selectCell(n,r),t.startCellEdition()},type:`data_validation_chip_icon`}}}),eG.add(`data_validation_list_icon`,(e,t)=>{if(!e.isReadonly()&&e.cellHasListDataValidationIcon(t)){let n=e.getCellComputedStyle(t);return{svg:Tj(n),hoverSvg:Dj(n),priority:2,horizontalAlign:`right`,size:17,margin:2,position:t,onClick:(e,t)=>{let{col:n,row:r}=e;t.model.selection.selectCell(n,r),t.startCellEdition()},type:`data_validation_list_icon`}}}),eG.add(`filter_icon`,(e,t)=>{if(e.isFilterHeader(t)){let n=e.isFilterActive(t),r=vn(e.getCellComputedStyle(t).fillColor||`#fff`)<.45;return{type:`filter_icon`,svg:Fj(n,r,!1),hoverSvg:Fj(n,r,!0),priority:3,horizontalAlign:`right`,size:17,margin:2,position:t,onClick:(e,t)=>{let n=t.getStore(TA),r=n.persistentCellPopover;if(r.isOpen&&r.col===e.col&&r.row===e.row&&r.type===`FilterMenu`){n.close();return}n.open(e,`FilterMenu`)}}}}),eG.add(`conditional_formatting`,(e,t)=>{let n=e.getConditionalIcon(t);if(n){let r=e.getCellStyle(t);return{type:`conditional_formatting`,svg:Ij[n].svg,priority:1,horizontalAlign:`left`,size:xl(r),margin:4,position:t}}}),eG.add(`pivot_collapse`,(e,t)=>{if(!e.isSpillPivotFormula(t))return;let n=e.getPivotCellFromPosition(t),r=e.getPivotIdFromPosition(t);if(n.type===`HEADER`&&r&&n.domain.length){let i=e.getPivotCoreDefinition(r),a=e.isDashboard(),o=n.dimension===`COL`?i.columns:i.rows,s=!a&&n.domain.length!==o.length,c=(i.collapsedDomains?.[n.dimension]??[]).some(e=>w(e,n.domain)),l=n.dimension===`ROW`?(n.domain.length-1)*15:0;return{type:`pivot_collapse`,priority:4,horizontalAlign:`left`,size:s||!a&&n.dimension===`ROW`&&i.rows.length>1?12:0,margin:s?4+l:l,svg:s?Pj(c,!1):void 0,hoverSvg:s?Pj(c,!0):void 0,position:t,onClick:tG}}});function tG(e,t){let n=t.model.getters.getPivotCellFromPosition(e),r=t.model.getters.getPivotIdFromPosition(e);if(!r||n.type!==`HEADER`)return;let i=t.model.getters.getPivotCoreDefinition(r),a=i.collapsedDomains?.[n.dimension]?[...i.collapsedDomains[n.dimension]]:[],o=a.findIndex(e=>w(e,n.domain));o===-1?a.push(n.domain):a.splice(o,1);let s=i.collapsedDomains?{...i.collapsedDomains}:{COL:[],ROW:[]};s[n.dimension]=a,t.model.dispatch(`UPDATE_PIVOT`,{pivotId:r,pivot:{...i,collapsedDomains:s}})}eG.add(`pivot_dashboard_sorting`,(e,t)=>{if(!e.isDashboard()||e.getPivotCellFromPosition(t).type!==`MEASURE_HEADER`)return;let n=e.getPivotCellSortDirection(t);if(n!==`asc`&&n!==`desc`)return;let r=e.getCellComputedStyle(t);return{type:`pivot_dashboard_sorting_${n}`,priority:5,horizontalAlign:`right`,size:17,margin:2,svg:n===`asc`?Ej(r):Tj(r),position:t,onClick:void 0}});var nG=class extends xW{static getters=[`doesCellHaveGridIcon`,`getCellIcons`,`getCellIconRect`];cellIconsCache={};handle(e){e.type!==`SET_VIEWPORT_OFFSET`&&(this.cellIconsCache={})}getCellIcons(e){return this.cellIconsCache[e.sheetId]||(this.cellIconsCache[e.sheetId]={}),this.cellIconsCache[e.sheetId][e.col]||(this.cellIconsCache[e.sheetId][e.col]={}),this.cellIconsCache[e.sheetId][e.col][e.row]||(this.cellIconsCache[e.sheetId][e.col][e.row]=this.computeCellIcons(e)),this.cellIconsCache[e.sheetId][e.col][e.row]}getCellIconRect(e,t){let n=e.position,r=this.getters.getCell(n);return{x:this.getIconHorizontalPosition(t,e.horizontalAlign,e),y:this.getters.computeTextYCoordinate(t,e.size,r?.style?.verticalAlign),width:e.size,height:e.size}}getIconHorizontalPosition(e,t,n){let r=e.x,i=e.x+e.width;switch(t){case`right`:return i-n.margin-n.size;case`left`:return r+n.margin;default:let e=Math.floor((i-r-n.size)/2);return i-n.size-e}}computeCellIcons(e){let t={left:void 0,right:void 0,center:void 0},n=eG.getAll();for(let r of n){let n=r(this.getters,e);n&&(!t[n.horizontalAlign]||n.priority>t[n.horizontalAlign].priority)&&(t[n.horizontalAlign]=n)}if(t.center&&(t.left||t.right)){let e=Math.max(t.left?.priority||0,t.right?.priority||0);t.center.priority<e?t.center=void 0:(t.left=void 0,t.right=void 0)}return Object.values(t).filter(C)}doesCellHaveGridIcon(e){return!!this.getCellIcons(e).length}},rG=class extends xW{static getters=[`canCreateDynamicTableOnZones`,`doesZonesContainFilter`,`getFilter`,`getFilters`,`getTable`,`getTables`,`getTablesOverlappingZones`,`getFilterId`,`getFilterHeaders`,`isFilterHeader`];tables={};handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)||e.type===`EVALUATE_CELLS`){this.tables={};return}switch(e.type){case`CREATE_TABLE`:case`REMOVE_TABLE`:case`UPDATE_TABLE`:case`DELETE_CONTENT`:this.tables={};break}}finalize(){for(let e of this.getters.getSheetIds())this.tables[e]||(this.tables[e]=this.computeTables(e))}computeTables(e){let t=[],n=this.getters.getCoreTables(e);for(let e of n)e.type!==`dynamic`&&t.push(e);let r=[...t];for(let i of n){if(i.type!==`dynamic`)continue;let n=this.coreTableToTable(e,i),a=n.range.zone;for(let e of r){let t=e.range.zone;zs(a,t)&&(a=t.left>a.left?{...a,right:Math.min(a.right,t.left-1)}:{...a,bottom:Math.min(a.bottom,t.top-1)})}t.push({...n,range:this.getters.getRangeFromZone(e,a)})}return t}getFilters(e){return this.getTables(e).filter(e=>e.config.hasFilters).map(e=>e.filters).flat()}getTables(e){return this.tables[e]||[]}getFilter(e){let t=this.getTable(e);if(!(!t||!t.config.hasFilters))return t.filters.find(t=>t.col===e.col)}getFilterId(e){return this.getFilter(e)?.id}getTable({sheetId:e,col:t,row:n}){return this.getTables(e).find(e=>Vs(t,n,e.range.zone))}getTablesOverlappingZones(e,t){return this.getTables(e).filter(e=>t.some(t=>zs(e.range.zone,t)))}doesZonesContainFilter(e,t){return this.getTablesOverlappingZones(e,t).some(e=>e.config.hasFilters)}getFilterHeaders(e){let t=[];for(let n of this.getTables(e)){if(!n.config.hasFilters)continue;let r=n.range.zone,i=r.top;for(let n=r.left;n<=r.right;n++)t.push({sheetId:e,col:n,row:i})}return t}isFilterHeader({sheetId:e,col:t,row:n}){return this.getFilterHeaders(e).some(e=>e.col===t&&e.row===n)}canCreateDynamicTableOnZones(e,t){if(!oc(t))return!1;let n=Fs(...t),r={col:n.left,row:n.top,sheetId:e},i=this.getters.getArrayFormulaSpreadingOn(r);if(!i){let e=this.getters.getEvaluatedCell(r);return e.value===k.SpilledBlocked&&!e.errorOriginPosition}else if(w(i,r)&&nc(n)===1)return!0;return w(n,this.getters.getSpreadZone(i))}coreTableToTable(e,t){if(t.type!==`dynamic`)return t;let n=t.range.zone,r={sheetId:e,col:n.left,row:n.top},i=this.getters.getSpreadZone(r)??t.range.zone,a=this.getters.getRangeFromZone(e,i),o=this.getDynamicTableFilters(e,t,i);return{id:t.id,range:a,filters:o,config:t.config}}getDynamicTableFilters(e,t,n){let r=[],{top:i,bottom:a,left:o,right:s}=n;for(let n=o;n<=s;n++){let s=n-o,c={left:n,right:n,top:i,bottom:a},l=gI(this.getDynamicTableFilterId(t.id,s),this.getters.getRangeFromZone(e,c),t.config,this.getters.getRangeFromZone);r.push(l)}return r}getDynamicTableFilterId(e,t){return e+`_`+t}isTableExcelExportable(e,t){return t.type===`dynamic`?!1:!Ks(t.range.zone).some(t=>this.getters.getArrayFormulaSpreadingOn({sheetId:e,...t}))}exportForExcel(e){for(let t of e.sheets){let n=[];for(let r of t.tables){let i=Ts(r.range),a={sheetId:t.id,col:i.left,row:i.top},o=this.getters.getCoreTable(a),s=this.getTable(a);if(!o||!s||this.isTableExcelExportable(t.id,o)){n.push(r);continue}t.styles=t.styles||{},t.borders=t.borders||{};for(let n of Ks(s.range.zone)){let r={sheetId:t.id,...n},i=this.getters.getCellComputedStyle(r),a=this.getters.getCellComputedBorder(r),o=T(n.col,n.row);if(!kt(i)){let n=mc(i,e.styles);t.styles[o]=n}if(a){let n=mc(a,e.borders);t.borders[o]=n}}}t.tables=n}}},iG=class extends xW{static getters=[`getRowSize`,`getHeaderSize`,`getMaxAnchorOffset`];tallestCellInRow={};ctx=document.createElement(`canvas`).getContext(`2d`);beforeHandle(e){switch(e.type){case`ADD_COLUMNS_ROWS`:if(e.dimension===`COL`)return;let t=Ft(e.position,e.base),n=Array(e.quantity).fill(void 0),r=Jt(this.tallestCellInRow[e.sheetId],n,t);this.history.update(`tallestCellInRow`,e.sheetId,r);break}}handle(e){switch(e.type){case`START`:case`UPDATE_LOCALE`:for(let e of this.getters.getSheetIds())this.initializeSheet(e);break;case`CREATE_SHEET`:this.initializeSheet(e.sheetId);break;case`DUPLICATE_SHEET`:{let t=b(this.tallestCellInRow[e.sheetId]);this.history.update(`tallestCellInRow`,e.sheetIdTo,t);break}case`DELETE_SHEET`:let t={...this.tallestCellInRow};delete t[e.sheetId],this.history.update(`tallestCellInRow`,t);break;case`REMOVE_COLUMNS_ROWS`:{if(e.dimension===`COL`)return;let t=qt(this.tallestCellInRow[e.sheetId],e.elements);this.history.update(`tallestCellInRow`,e.sheetId,t);break}case`RESIZE_COLUMNS_ROWS`:{let t=e.sheetId;if(e.dimension===`ROW`)for(let n of e.elements){let e=this.getRowTallestCell(t,n);this.history.update(`tallestCellInRow`,t,n,e)}else for(let n of S(0,this.getters.getNumberRows(t)))for(let r of e.elements)this.updateRowSizeForCellChange(t,n,r)}break;case`UPDATE_CELL`:this.updateRowSizeForCellChange(e.sheetId,e.row,e.col);break;case`ADD_MERGE`:case`REMOVE_MERGE`:for(let t of e.target)for(let n of Ks(t))this.updateRowSizeForCellChange(e.sheetId,n.row,n.col)}}getRowSize(e,t){return Math.round(this.getters.getUserRowSize(e,t)??this.tallestCellInRow[e][t]?.size??23)}getMaxAnchorOffset(e,t,n){let{numberOfRows:r,numberOfCols:i}=this.getters.getSheetSize(e),a=0;for(;a<t&&r>0;r--)a+=this.getRowSize(e,r-1);let o=0;for(;o<n&&i>0;i--)o+=this.getters.getColSize(e,i-1);return{col:i,row:r,offset:{x:o-n,y:a-t}}}getHeaderSize(e,t,n){return this.getters.isHeaderHidden(e,t,n)?0:t===`ROW`?this.getRowSize(e,n):this.getters.getColSize(e,n)}updateRowSizeForCellChange(e,t,n){let r=this.tallestCellInRow[e]?.[t];if(r?.cell.col===n){let n=this.getRowTallestCell(e,t);this.history.update(`tallestCellInRow`,e,t,n)}let i=this.getCellHeight({sheetId:e,col:n,row:t});if(!(i<=23)&&(!r&&i>23||r&&i>r.size)){let r={cell:{sheetId:e,col:n,row:t},size:i};this.history.update(`tallestCellInRow`,e,t,r)}}initializeSheet(e){let t=[];for(let n=0;n<this.getters.getNumberRows(e);n++){let r=this.getRowTallestCell(e,n);t.push(r)}this.history.update(`tallestCellInRow`,e,t)}getCellHeight(e){if(this.isInMultiRowMerge(e))return 23;let t=this.getters.getCell(e),n=this.getters.getColSize(e.sheetId,e.col);return ul(this.ctx,t,this.getters.getLocale(),n)}isInMultiRowMerge(e){let t=this.getters.getMerge(e);return!!t&&t.bottom!==t.top}getRowTallestCell(e,t){if(this.getters.getUserRowSize(e,t)!==void 0)return;let n=this.getters.getRowCells(e,t),r=0,i;for(let e=0;e<n.length;e++){let t=this.getters.getCellById(n[e]);if(!t)continue;let a=this.getters.getCellPosition(t.id),o=this.getCellHeight(a);o>r&&o>23&&(r=o,i={cell:a,size:o})}if(i&&i.size>23)return i}};let aG=`0.00%`;function oG(e){class t extends e{getters;pivotId;cache={};rankAsc={};rankDesc={};runningTotal={};runningTotalInPercent={};constructor(e,t,n){super(t,n),this.getters=n.getters,this.pivotId=e}markAsDirtyForEvaluation(){this.cache={},this.rankAsc={},this.rankDesc={},this.runningTotal={},this.runningTotalInPercent={},super.markAsDirtyForEvaluation?.()}getPivotCellValueAndFormat(e,t){return this.getMeasureDisplayValue(e,t)}_getPivotCellValueAndFormat(e,t){let n=`${e}-${t.map(e=>e.field+`=`+e.value).join(`,`)}`;if(this.cache[n])return this.cache[n];let r=this.getMeasure(e),i=r.computedBy?this.computeMeasure(r,t):super.getPivotCellValueAndFormat(e,t);return r.format?this.cache[n]={...i,format:r.format}:this.cache[n]=i,this.cache[n]}computeMeasure(e,t){if(!e.computedBy)return{value:0};let{columns:n,rows:r}=super.definition;if(e.aggregator&&n.length+r.length!==t.length){let n=this.getValuesToAggregate(e,t),r=wd[e.aggregator];if(!r)return{value:0};try{return r([n],this.getters.getLocale())}catch(t){return VS(t,e.aggregator.toUpperCase())}}let i=this.getters.getMeasureCompiledFormula(this.pivotId,e),a=this.getters.evaluateCompiledFormula(e.computedBy.sheetId,i,e=>{let{columns:n,rows:r}=this.definition;if(n.find(t=>t.nameWithGranularity===e)){let{colDomain:n}=LL(this,t),r=n.findIndex(t=>t.field===e);return r===-1?new Xi:this.getPivotHeaderValueAndFormat(n.slice(0,r+1))}if(r.find(t=>t.nameWithGranularity===e)){let{rowDomain:n}=LL(this,t),r=n.findIndex(t=>t.field===e);return r===-1?new Xi:this.getPivotHeaderValueAndFormat(n.slice(0,r+1))}return this.getPivotCellValueAndFormat(e,t)});return Ir(a)?a[0][0]:a}getValuesToAggregate(e,t){let{rowDomain:n,colDomain:r}=LL(this,t),i=super.getExpandedTableStructure(),a=[];if(r.length===0&&n.length<this.definition.rows.length&&this.definition.rows.length&&this.definition.columns.length){let t=this.treeToLeafDomains(i.getColTree()),r=this.getSubTreeMatchingDomain(i.getRowTree(),n),o=this.treeToLeafDomains(r);for(let r of t)for(let t of o)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t).concat(r)));return a}else if(n.length===this.definition.rows.length&&r.length===0){let t=i.getColTree(),o=this.getSubTreeMatchingDomain(t,r),s=this.treeToLeafDomains(o,r);for(let t of s)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t)));return a}else if(n.length===this.definition.rows.length&&r.length&&r.length<this.definition.columns.length){let t=this.getSubTreeMatchingDomain(i.getColTree(),r),o=this.treeToLeafDomains(t,r);for(let t of o)a.push(this._getPivotCellValueAndFormat(e.id,n.concat(t)));return a}else{let t=i.getRowTree(),o=this.getSubTreeMatchingDomain(t,n),s=this.treeToLeafDomains(o,n);for(let t of s)a.push(this._getPivotCellValueAndFormat(e.id,t.concat(r)));return a}}getSubTreeMatchingDomain(e,t,n=0){if(n>t.length)return[];if(t.length===n)return e;for(let r of e){let e=Nd(this.definition.getDimension(r.field),t[n]?.value);if(r.field===t[n]?.field&&r.value===e)return this.getSubTreeMatchingDomain(r.children,t,n+1)}return[]}treeToLeafDomains(e,t=[]){let n=[];for(let r of e){let e=this.definition.getDimension(r.field),i=[...t,{field:r.field,value:r.value,type:e.type}];r.children.length===0?n.push(i):n.push(...this.treeToLeafDomains(r.children,i))}return n}getMeasureDisplayValue(e,t){let n=this.getMeasure(e),r=this._getPivotCellValueAndFormat(e,t);if(!n.display||n.display.type===`no_calculations`||r.message)return r;let i=n.display.fieldNameWithGranularity;if(i&&!this.isFieldInPivot(i))return{value:k.NotAvailable,message:E(`Field "%s" not found in pivot for measure display calculation`,i)};try{let e=n.display;switch(e.type){case`%_of_grand_total`:return this.asPercentOfGrandTotal(r,n);case`%_of_col_total`:return this.asPercentOfColumnTotal(r,n,t);case`%_of_row_total`:return this.asPercentOfRowTotal(r,n,t);case`%_of_parent_row_total`:return this.asPercentOfParentRowTotal(r,n,t);case`%_of_parent_col_total`:return this.asPercentOfParentColumnTotal(r,n,t);case`index`:return this.asIndex(r,n,t);case`%_of_parent_total`:return this.asPercentOfParentTotal(r,n,t,e);case`running_total`:return this.asRunningTotal(r,n,t,e,`running_total`);case`%_running_total`:return this.asRunningTotal(r,n,t,e,`%_running_total`);case`rank_asc`:return this.asRank(r,n,t,e,`asc`);case`rank_desc`:return this.asRank(r,n,t,e,`desc`);case`%_of`:return this.asPercentOf(r,n,t,e);case`difference_from`:return this.asDifferenceFrom(r,n,t,e);case`%_difference_from`:return this.asDifferenceFromInPercent(r,n,t,e)}return r}catch(e){return VS(e,`COMPUTE_MEASURE_DISPLAY_VALUE`)}}asPercentOfGrandTotal(e,t){let n=this.getGrandTotal(t.id);return n===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/n,format:aG}}asPercentOfRowTotal(e,t,n){let r=this.getRowTotal(t.id,n);return r===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/r,format:aG}}asPercentOfColumnTotal(e,t,n){let r=this.getColumnTotal(t.id,n);return r===0?{value:k.DivisionByZero}:{value:this.measureValueToNumber(e)/r,format:aG}}asPercentOfParentRowTotal(e,t,n){let r=FL(this,n),i=this.measureValueToNumber(this._getPivotCellValueAndFormat(t.id,r));return i===0?{value:``}:{value:this.measureValueToNumber(e)/i,format:aG}}asPercentOfParentColumnTotal(e,t,n){let r=IL(this,n),i=this.measureValueToNumber(this._getPivotCellValueAndFormat(t.id,r));return i===0?{value:``}:{value:this.measureValueToNumber(e)/i,format:aG}}asPercentOfParentTotal(e,t,n,r){let{fieldNameWithGranularity:i}=r;if(!i)return e;if(!GL(i,n))return{value:``};let a=UL(this,i,n),o=this._getPivotCellValueAndFormat(t.id,a),s=this.measureValueToNumber(o);return s===0?{value:``}:{value:this.measureValueToNumber(e)/s,format:aG}}asIndex(e,t,n){let r=this.measureValueToNumber(e),i=this.getRowTotal(t.id,n),a=this.getColumnTotal(t.id,n),o=this.getGrandTotal(t.id);return i===0||a===0?{value:k.DivisionByZero}:{value:r*o/(a*i),format:void 0}}asRunningTotal(e,t,n,r,i){let{fieldNameWithGranularity:a}=r;if(!a)return e;let o=i===`running_total`?this.runningTotal:this.runningTotalInPercent,s=o[t.id]?.[a];s||(s=this.computeRunningTotal(t,a,i),o[t.id]||(o[t.id]={}),o[t.id][a]=s);let{rowDomain:c,colDomain:l}=LL(this,n),u=JL(l),d=JL(c);return{value:s[u]?.[d]??``,format:i===`running_total`?e.format:aG}}asPercentOf(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a),s=this.strictMeasureValueToNumber(e);return o===0||o===`sameValue`&&s===0?{value:k.DivisionByZero}:!o||o===`sameValue`&&!s?{value:``}:o===`sameValue`?{value:1,format:aG}:s===void 0?{value:k.NullError}:{value:s/o,format:aG}}asDifferenceFrom(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a)||0;return o===`sameValue`?{value:``}:{value:this.measureValueToNumber(e)-o,format:e.format}}asDifferenceFromInPercent(e,t,n,r){let{fieldNameWithGranularity:i,value:a}=r;if(a===void 0||!i)return e;if(!GL(i,n))return{value:``};let o=this.getComparisonValue(t,n,i,a),s=this.strictMeasureValueToNumber(e);return o===0?{value:k.DivisionByZero}:!o||o===`sameValue`?{value:``}:s===void 0?{value:k.NullError}:{value:(s-o)/o,format:aG}}asRank(e,t,n,r,i){let{fieldNameWithGranularity:a}=r;if(!a)return e;if(!GL(a,n))return{value:``};let o=i===`asc`?this.rankAsc:this.rankDesc,s=o[t.id]?.[a];s||(s=this.computeRank(t,a,i),o[t.id]||(o[t.id]={}),o[t.id][a]=s);let{rowDomain:c,colDomain:l}=LL(this,n),u=JL(l),d=JL(c);return{value:s[u]?.[d]??``}}computeRank(e,t,n){let r={},i=KL(this,t),a=i===`row`?`column`:`row`,o=this.getPivotValueCells(e.id);i===`column`&&(o=Ta(o));for(let s of o){let o=JL(RL(this,a,s[0].domain)),c=s.map(t=>({...t,value:this.strictMeasureValueToNumber(this._getPivotCellValueAndFormat(e.id,t.domain)),rowDomain:RL(this,i,t.domain)})).filter(e=>GL(t,e.rowDomain)),l=Object.groupBy(c,e=>XL(e.rowDomain,t));for(let e in l)l[e]=nn(l[e]||[],e=>e.value).filter(e=>e.value!==void 0).sort((e,t)=>n===`asc`?e.value-t.value:t.value-e.value);r[o]={};for(let e of c){let n=JL(RL(this,i,e.domain)),a=l[XL(e.rowDomain,t)];if(!a)continue;let s=a.findIndex(t=>t.value===e.value);s!==-1&&(r[o][n]=s+1)}}return i===`row`?r:rn(r)}computeRunningTotal(e,t,n){let r={},i=KL(this,t),a=i===`row`?`column`:`row`,o=this.getPivotValueCells(e.id);i===`column`&&(o=Ta(o));for(let s of o){let o=JL(RL(this,a,s[0].domain));r[o]={};let c={},l=s.map(t=>({...t,rowDomain:RL(this,i,t.domain),value:this.measureValueToNumber(this._getPivotCellValueAndFormat(e.id,t.domain))})).filter(e=>GL(t,e.rowDomain));for(let e of l){let n=JL(e.rowDomain),i=ZL(e.rowDomain,t),a=(c[i]||0)+e.value;c[i]=a,r[o][n]=a}if(n===`%_running_total`)for(let e of l){let n=e.rowDomain,i=JL(n),a=ZL(n,t),s=r[o][i]||0,l=c[a];r[o][i]=l?s/l:void 0}}return i===`row`?r:rn(r)}getGrandTotal(e){let t=this._getPivotCellValueAndFormat(e,[]);return this.measureValueToNumber(t)}getRowTotal(e,t){let n=LL(this,t).rowDomain,r=this._getPivotCellValueAndFormat(e,n);return this.measureValueToNumber(r)}getColumnTotal(e,t){let n=LL(this,t).colDomain,r=this._getPivotCellValueAndFormat(e,n);return this.measureValueToNumber(r)}isFieldInPivot(e){return this.definition.columns.some(t=>t.nameWithGranularity===e)||this.definition.rows.some(t=>t.nameWithGranularity===e)}getComparisonValue(e,t,n,r){let i=r===`(previous)`||r===`(next)`?qL(this,t,n,r):WL(t,n,r);if(w(i,t))return`sameValue`;if(!i||!BL(this,i))throw new Xi;let a=this._getPivotCellValueAndFormat(e.id,i);return this.strictMeasureValueToNumber(a)}getPivotValueCells(e){return this.getCollapsedTableStructure().getPivotCells().map(t=>t.filter(t=>t.type===`VALUE`&&t.measure===e)).filter(e=>e.length>0)}measureValueToNumber(e){if(typeof e.value==`number`)return e.value;if(!e.value)return 0;throw Error(`Value ${e.value} is not a number`)}strictMeasureValueToNumber(e){if(typeof e.value==`number`)return e.value;if(e.value)throw Error(`Value ${e.value} is not a number`)}getCollapsedTableStructure(){let e=super.getCollapsedTableStructure();return this.sortTableStructure(e),e}getExpandedTableStructure(){let e=super.getExpandedTableStructure();return this.sortTableStructure(e),e}sortTableStructure(e){if(!this.definition.sortedColumn||e.isSorted)return;let t=this.definition.sortedColumn.measure;Vd(this.definition.sortedColumn,this)&&e.sort(t,this.definition.sortedColumn,(e,t)=>this._getPivotCellValueAndFormat(e,t))}}return t}let sG=[`ADD_PIVOT`,`UPDATE_PIVOT`,`REMOVE_PIVOT`];function cG(e){return sG.includes(e.type)}var lG=class extends xW{static getters=[`getPivot`,`getFirstPivotFunction`,`getPivotCellSortDirection`,`getPivotIdFromPosition`,`getPivotIdsFromPosition`,`getPivotCellFromPosition`,`generateNewCalculatedMeasureName`,`isPivotUnused`,`isSpillPivotFormula`];pivots={};unusedPivots;custom;constructor(e){super(e),this.custom=e.custom}beforeHandle(e){switch(e.type){case`START`:for(let e of this.getters.getPivotIds())this.setupPivot(e)}}handle(e){if(yr.has(e.type))for(let e of this.getters.getPivotIds())this.setupPivot(e,{recreate:!0});switch(e.type){case`REFRESH_PIVOT`:this.refreshPivot(e.id);break;case`ADD_PIVOT`:this.unusedPivots?.push(e.pivotId),this.setupPivot(e.pivotId);break;case`DUPLICATE_PIVOT`:this.unusedPivots?.push(e.newPivotId),this.setupPivot(e.newPivotId);break;case`UPDATE_PIVOT`:this.setupPivot(e.pivotId,{recreate:!0});break;case`DELETE_SHEET`:case`UPDATE_CELL`:this.unusedPivots=void 0;break;case`UNDO`:case`REDO`:{this.unusedPivots=void 0;let t=e.commands.filter(cG);for(let e of t){let t=e.pivotId;this.getters.isExistingPivot(t)&&this.setupPivot(t,{recreate:!0})}break}case`UPDATE_LOCALE`:gR();break}}getPivotIdFromPosition(e){return this.getPivotIdsFromPosition(e)[0]}getPivotIdsFromPosition(e){let t=this.getters.getCorrespondingFormulaCell(e);return t&&t.isFormula?this.getPivotIdsFromFormula(e.sheetId,t.compiledFormula):[]}getPivotIdsFromFormula(e,t){return this.getPivotFunctions(e,t.tokens).map(e=>{let t=e.args[0]?.toString();return t&&this.getters.getPivotId(t)}).filter(C)}isSpillPivotFormula(e){let t=this.getters.getCorrespondingFormulaCell(e);return t&&t.isFormula?this.getFirstPivotFunction(e.sheetId,t.compiledFormula.tokens)?.functionName===`PIVOT`:!1}getPivotFunctions(e,t){let n=gU(t);if(!n.length)return[];let r=[];for(let t of n){let{functionName:n,args:i}=t,a=i.map(t=>{if(t.type===`EMPTY`)return;if(t.type===`STRING`||t.type===`BOOLEAN`||t.type===`NUMBER`)return t.value;let n=PB(t);return this.getters.evaluateFormula(e,n)});r.push({functionName:n,args:a})}return r}getFirstPivotFunction(e,t){return this.getPivotFunctions(e,t)[0]}getPivotCellFromPosition(e){let t=this.getters.getCorrespondingFormulaCell(e);if(!t||!t.isFormula||_U(t.compiledFormula.tokens)===0)return rR;let n=this.getters.getCellPosition(t.id),r=this.getters.getFirstPivotFunction(e.sheetId,t.compiledFormula.tokens);if(!r)return rR;let{functionName:i,args:a}=r,o=a[0];if(!o)return rR;let s=this.getters.getPivotId(o.toString());if(!s)return rR;let c=this.getPivot(s);if(!c.isValid()||i===`PIVOT`&&!t.content.replaceAll(` `,``).toUpperCase().startsWith(`=PIVOT`))return rR;try{if(i===`PIVOT`){let t=Hu(a[2]),r=t===void 0?!0:P(t),i=Hu(a[3]),o=Hu(a[5]),s=o===void 0?!0:P(o),l={displayColumnHeaders:i===void 0?!0:P(i),displayTotals:r,displayMeasuresRow:s},u=c.getCollapsedTableStructure().getPivotCells(l),d=e.col-n.col,f=e.row-n.row;return u[d][f]}let t=e.row-n.row,r=e.col-n.col;if(a=a.map(e=>Ir(e)?e[r][t]:e),i===`PIVOT.HEADER`&&a.at(-2)===`measure`)return{type:`MEASURE_HEADER`,domain:c.parseArgsToPivotDomain(a.slice(1,-2).map(e=>({value:e}))),measure:a.at(-1)?.toString()||``};if(i===`PIVOT.HEADER`){let e=c.parseArgsToPivotDomain(a.slice(1).map(e=>({value:e})));return{type:`HEADER`,domain:e,dimension:LL(c,e).colDomain.length?`COL`:`ROW`}}let[o,...s]=a.slice(1);return{type:`VALUE`,domain:c.parseArgsToPivotDomain(s.map(e=>({value:e}))),measure:o?.toString()||``}}catch{return rR}}generateNewCalculatedMeasureName(e){let t=e.map(e=>e.fieldName);return an(E(`Calculated measure 1`),t,{compute:(e,t)=>E(`Calculated measure %s`,t)})}getPivot(e){if(!this.getters.isExistingPivot(e))throw Error(`pivot ${e} not found`);return this.pivots[e]}isPivotUnused(e){return this._getUnusedPivots().includes(e)}getPivotCellSortDirection(e){let t=this.getters.getPivotIdFromPosition(e),n=this.getters.getPivotCellFromPosition(e);if(n.type===`EMPTY`||n.type===`HEADER`||!t)return;let r=this.getters.getPivot(t),i=LL(r,n.domain).colDomain,a=r.definition.sortedColumn;return a?.measure===n.measure&&w(a.domain,i)?a.order:`none`}refreshPivot(e){this.getters.getPivot(e).init({reload:!0})}setupPivot(e,{recreate:t}={recreate:!1}){let n=b(this.getters.getPivotCoreDefinition(e));if(e in this.pivots)t&&this.pivots[e].onDefinitionChange(n);else{let t=oG(vR.get(n.type).ui);this.pivots[e]=new t(e,this.custom,{definition:n,getters:this.getters})}}_getUnusedPivots(){if(this.unusedPivots!==void 0)return this.unusedPivots;let e=new Set(this.getters.getPivotIds());for(let t of this.getters.getSheetIds())for(let n in this.getters.getCells(t)){let t=this.getters.getCellPosition(n),r=this.getPivotIdsFromPosition(t);for(let t of r)if(e.delete(t),!e.size)return this.unusedPivots=[],[]}for(let t of this.getters.getPivotIds()){let n=this.getters.getPivotCoreDefinition(t);for(let r of n.measures)if(r.computedBy){let{sheetId:n}=r.computedBy,i=this.getters.getMeasureCompiledFormula(t,r),a=this.getPivotIdsFromFormula(n,i);for(let t of a)if(e.delete(t),!e.size)return this.unusedPivots=[],[]}}return this.unusedPivots=[...e],this.unusedPivots}};let uG=new g;uG.add(`ALPHANUMERIC_INCREMENT_MODIFIER`,{apply:(e,t)=>{e.current+=e.increment;let n=Math.abs(e.current).toString();n=`0`.repeat(Math.max(e.numberPostfixLength-n.length,0))+n;let r=`${e.prefix}${n}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:{props:{content:r}}}}}).add(`INCREMENT_MODIFIER`,{apply:(e,t,n)=>{e.current+=e.increment;let r=e.current.toString(),i=n.getLocale(),a=L(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:r?{props:{content:a}}:void 0}}}).add(`DATE_INCREMENT_MODIFIER`,{apply:(e,t,n)=>{let r=F(e.current,n.getLocale());r.setFullYear(r.getFullYear()+e.increment.years||0),r.setMonth(r.getMonth()+e.increment.months||0),r.setDate(r.getDate()+e.increment.days||0);let i=wi(r);e.current=i;let a=n.getLocale(),o=L(i,{format:t.cell?.format,locale:a});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i.toString()},tooltip:i?{props:{content:o}}:void 0}}}).add(`COPY_MODIFIER`,{apply:(e,t,n)=>{let r=t.cell?.content||``,i={locale:n.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:r},tooltip:r?{props:{content:t.cell?es(t.cell,i).formattedValue:``}}:void 0}}}).add(`FORMULA_MODIFIER`,{apply:(e,t,n,r)=>{e.current+=e.increment;let i=0,a=0;switch(r){case`up`:i=0,a=-e.current;break;case`down`:i=0,a=e.current;break;case`left`:i=-e.current,a=0;break;case`right`:i=e.current,a=0;break}let o=t.cell;if(!o||!o.isFormula)return{cellData:{}};let s=t.sheetId,c=n.getTranslatedCellFormula(s,i,a,o.compiledFormula.tokens);return{cellData:{border:t.border,style:o.style,format:o.format,content:c},tooltip:c?{props:{content:c}}:void 0}}});let dG=new g,fG=/(\d+)$/,pG=/^(.*\D+)/,mG=/^(.*\D+)(\d+)$/,hG=/^0*/;function gG(e,t,n){let r=[],i=!1;for(let a of t){a===e&&(i=!0);let t=a===void 0||a.isFormula?void 0:es(a,{locale:D,format:a.format});if(t&&n(t))r.push(t);else{if(i)return r;r=[]}}return r}function _G(e){let t=[],n=e[0];for(let r=1;r<e.length;r++){let i=e[r];t.push(i-n),n=i}return t.reduce((e,t)=>e+t,0)/t.length}function vG(e){let t=1;return e.length>=2&&(t=_G(e)*e.length),t}function yG(e){return e.length<2?e[0]||{years:0,months:0,days:0}:e.every(t=>t.years===e[0].years&&t.months===e[0].months&&t.days===e[0].days)?e[0]:void 0}function bG(e){if(e.length<2)return 1;let t=e.map(e=>F(e,D)),n=yG(xG(t));if(n===void 0)return;let r=Object.values(n).filter(e=>e!==0).length===1,i=Object.values(n).every(e=>e===0);if(!r||i){let n=t.map((e,n)=>{if(n===0)return 0;let r=t[n-1];return Math.floor(e.getTime())-Math.floor(r.getTime())}).slice(1);if(n.every(e=>e===n[0]))return e.length*(e[1]-e[0])}return{years:n.years*e.length,months:n.months*e.length,days:n.days*e.length}}dG.add(`simple_value_copy`,{condition:(e,t)=>t.length===1&&!e.isFormula&&!(e.format&&jo(e.format)),generateRule:()=>({type:`COPY_MODIFIER`}),sequence:10}).add(`increment_alphanumeric_value`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`text`&&mG.test(e.content),generateRule:(e,t,n)=>{let r=parseInt(e.content.match(fG)[0]),i=e.content.match(pG)[0],a=gG(e,t,e=>e.type===`text`&&mG.test(e.value)).filter(e=>i===(e.value??``).toString().match(pG)[0]).map(e=>(e.value??``).toString().match(fG)[0]),o=a.reduce((e,t)=>{let n=t.match(hG)[0].length;return n>e[1]?[t,n]:e},[a[0],0]),s=o[1]?o[0].length:0,c=vG(a.map(e=>parseInt(e)));return[`up`,`left`].includes(n)&&a.length===1&&(c=-c),{type:`ALPHANUMERIC_INCREMENT_MODIFIER`,prefix:i,current:r,increment:c,numberPostfixLength:s}},sequence:15}).add(`copy_text`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`text`,generateRule:()=>({type:`COPY_MODIFIER`}),sequence:20}).add(`update_formula`,{condition:e=>e.isFormula,generateRule:(e,t)=>({type:`FORMULA_MODIFIER`,increment:t.length,current:0}),sequence:30}).add(`increment_dates`,{condition:(e,t)=>!e.isFormula&&es(e,{locale:D}).type===`number`&&!!e.format&&jo(e.format),generateRule:(e,t)=>{let n=bG(gG(e,t,e=>e.type===`number`&&!!e.format&&jo(e.format)).map(e=>Number(e.value)));if(n===void 0)return{type:`COPY_MODIFIER`};let r=es(e,{locale:D});return typeof n==`object`?{type:`DATE_INCREMENT_MODIFIER`,increment:n,current:r.type===`number`?r.value:0}:{type:`INCREMENT_MODIFIER`,increment:n,current:r.type===`number`?r.value:0}},sequence:25}).add(`increment_number`,{condition:e=>!e.isFormula&&es(e,{locale:D}).type===`number`,generateRule:(e,t,n)=>{let r=gG(e,t,e=>e.type===`number`&&!jo(e.format||``)).map(e=>Number(e.value)),i=vG(r);[`up`,`left`].includes(n)&&r.length===1&&(i=-i);let a=es(e,{locale:D});return{type:`INCREMENT_MODIFIER`,increment:i,current:a.type===`number`?a.value:0}},sequence:40});function xG(e){return e.length<2?[{years:0,months:0,days:0}]:e.map((t,n)=>{if(n===0)return{years:0,months:0,days:0};let r=O.fromTimestamp(e[n-1].getTime()),i=Mi(r,t),a=Ai(r,t)%12;return r.setFullYear(r.getFullYear()+i),r.setMonth(r.getMonth()+a),{years:i,months:a,days:ji(r,t)}}).slice(1)}var SG=class{cells;getters;index=0;direction;constructor(e,t,n){this.cells=e,this.getters=t,this.direction=n}next(){let e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:n,tooltip:r}=uG.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:n,tooltip:r,origin:{col:e.data.col,row:e.data.row}}}},CG=class extends Rp{static layers=[`Autofill`];static getters=[`getAutofillTooltip`];autofillZone;steps;lastCellSelected={};direction;tooltip;allowDispatch(e){switch(e.type){case`AUTOFILL_SELECT`:let t=this.getters.getActiveSheetId();return this.lastCellSelected.col=e.col===-1?this.lastCellSelected.col:x(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=e.row===-1?this.lastCellSelected.row:x(e.row,0,this.getters.getNumberRows(t)),this.lastCellSelected.col!==void 0&&this.lastCellSelected.row!==void 0?`Success`:`InvalidAutofillSelection`}return`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}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||this.direction===void 0){this.tooltip=void 0;return}let t=this.getters.getSelectedZone(),n=this.autofillZone,r=[];switch(this.direction){case`down`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.top;n<=t.bottom;n++)i.push(T(e,n));let a=this.createGenerator(i);for(let t=n.top;t<=n.bottom;t++)r.push(this.computeNewCell(a,e,t))}break;case`up`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.bottom;n>=t.top;n--)i.push(T(e,n));let a=this.createGenerator(i);for(let t=n.bottom;t>=n.top;t--)r.push(this.computeNewCell(a,e,t))}break;case`left`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.right;n>=t.left;n--)i.push(T(n,e));let a=this.createGenerator(i);for(let t=n.right;t>=n.left;t--)r.push(this.computeNewCell(a,t,e))}break;case`right`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.left;n<=t.right;n++)i.push(T(n,e));let a=this.createGenerator(i);for(let t=n.left;t<=n.right;t++)r.push(this.computeNewCell(a,t,e))}break}if(e){let e={},t={},n={},i=this.getters.getActiveSheetId();for(let a of r)this.collectBordersData(a,e),this.autofillMerge(i,a),this.autofillCell(i,a),this.collectConditionalFormatsData(i,a,t),this.collectDataValidationsData(i,a,n);this.autofillBorders(i,e),this.autofillConditionalFormats(i,t),this.autofillDataValidations(i,n),this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0}}collectBordersData(e,t){let n=JSON.stringify(e.border);n in t||(t[n]=[]),t[n].push(R({col:e.col,row:e.row}))}collectConditionalFormatsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s=this.getters.getRulesByCell(e,r,i),c=T(a,o);for(let e of s)e.id in n||(n[e.id]=[]),n[e.id].push(c)}collectDataValidationsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s={sheetId:e,col:r,row:i},c=this.getters.getValidationRuleForCell(s);c&&(c.id in n||(n[c.id]=[]),n[c.id].push(R({col:a,row:o})))}autofillCell(e,t){this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t.col,row:t.row,content:t.content||``,style:t.style||null,format:t.format||``}),this.dispatch(`AUTOFILL_CELL`,t)}autofillBorders(e,t){for(let n in t){let r=n===`undefined`?void 0:JSON.parse(n);this.dispatch(`SET_BORDERS_ON_TARGET`,{sheetId:e,border:r,target:ms(t[n])})}}autofillConditionalFormats(e,t){for(let n in t){let r=t[n],i=this.getters.getConditionalFormats(e).find(e=>e.id===n);if(!i)continue;let a=this.getters.getAdaptedCfRanges(e,i,r.map(Ts),[]);a&&this.dispatch(`ADD_CONDITIONAL_FORMAT`,{cf:{id:i.id,rule:i.rule,stopIfTrue:i.stopIfTrue},ranges:a,sheetId:e})}}autofillDataValidations(e,t){for(let n in t){let r=t[n],i=this.getters.getDataValidationRule(e,n);if(!i)continue;let a=ms(i.ranges.map(e=>e.zone).concat(r),[]);this.dispatch(`ADD_DATA_VALIDATION_RULE`,{rule:i,ranges:a.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}}select(e,t){let n=this.getters.getSelectedZone();if(Vs(e,t,n)){this.autofillZone=void 0;return}switch(this.direction=this.getDirection(e,t),this.direction){case`up`:this.saveZone(t,n.top-1,n.left,n.right),this.steps=n.top-t;break;case`down`:this.saveZone(n.bottom+1,t,n.left,n.right),this.steps=t-n.bottom;break;case`left`:this.saveZone(n.top,n.bottom,e,n.left-1),this.steps=n.left-e;break;case`right`:this.saveZone(n.top,n.bottom,n.right+1,e),this.steps=e-n.right;break}this.autofill(!1)}autofillAuto(){let e=this.getters.getActivePosition(),t=this.getters.getTable(e),n=t?t.range.zone.bottom:this.getAutofillAutoLastRow(),r=this.getters.getSelectedZone();for(let t=r.bottom+1;t<=n;t++)if(this.getters.getEvaluatedCell({...e,row:t}).type!==`empty`){n=t-1;break}n>r.bottom&&(this.select(e.col,n),this.autofill(!0))}getAutofillAutoLastRow(){let e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId(),n=e.left,r=e.bottom;if(n>0){let e={sheetId:t,col:n-1,row:r};for(;this.getters.getEvaluatedCell(e).type!==`empty`;)r+=1,e={sheetId:t,col:n-1,row:r}}if(r===e.bottom&&(n=e.right,n<=this.getters.getNumberCols(t))){let e={sheetId:t,col:n+1,row:r};for(;this.getters.getEvaluatedCell(e).type!==`empty`;)r+=1,e={sheetId:t,col:n+1,row:r}}return r-1}computeNewCell(e,t,n){let{cellData:r,tooltip:i,origin:a}=e.next(),{content:o,style:s,border:c,format:l}=r;return this.tooltip=i,{originCol:a.col,originRow:a.row,col:t,row:n,content:o,style:s,border:c,format:l}}getRule(e,t){let n=dG.getAll().sort((e,t)=>e.sequence-t.sequence).find(n=>n.condition(e,t));return n&&this.direction&&n.generateRule(e,t,this.direction)}createGenerator(e){let t=[],n=[],r=this.getters.getActiveSheetId();for(let t of e){let{col:e,row:i}=ir(t),a=this.getters.getCell({sheetId:r,col:e,row:i});n.push({col:e,row:i,cell:a,sheetId:r})}let i=n.map(e=>e.cell);for(let e of n){let n={type:`COPY_MODIFIER`};e&&e.cell&&(n=this.getRule(e.cell,i)||n);let r=this.getters.getCellBorder(e)||void 0;t.push({data:{...e,border:r},rule:n})}return new SG(t,this.getters,this.direction)}saveZone(e,t,n,r){this.autofillZone={top:e,bottom:t,left:n,right:r}}getDirection(e,t){let n=this.getters.getSelectedZone(),r={up:{number:n.top-t,value:`up`},down:{number:t-n.bottom,value:`down`},left:{number:n.left-e,value:`left`},right:{number:e-n.right,value:`right`}};if(Object.values(r).map(e=>+(e.number>0)).reduce((e,t)=>e+t)===1)return Object.values(r).find(e=>+(e.number>0)).value;let i=r.up.number>0?`up`:`down`,a=r.left.number>0?`left`:`right`;return Math.abs(r[i].number)>=Math.abs(r[a].number)?r[i].value:r[a].value}autofillMerge(e,t){let{originCol:n,originRow:r,col:i,row:a}=t,o={sheetId:e,col:i,row:a},s={sheetId:e,col:n,row:r};if(this.getters.isInMerge(o)&&!this.getters.isInMerge(s)){let t=this.getters.getMerge(o);t&&this.dispatch(`REMOVE_MERGE`,{sheetId:e,target:[t]})}let c=this.getters.getMerge(s);c?.left===n&&c?.top===r&&this.dispatch(`ADD_MERGE`,{sheetId:e,target:[{top:a,bottom:a+c.bottom-c.top,left:i,right:i+c.right-c.left}]})}drawLayer(e){if(!this.autofillZone)return;let{ctx:t,thinLineWidth:n}=e,{x:r,y:i,width:a,height:o}=this.getters.getVisibleRect(this.autofillZone);a>0&&o>0&&(t.strokeStyle=`black`,t.lineWidth=n,t.setLineDash([3]),t.strokeRect(r,i,a,o),t.setLineDash([]))}},wG=class extends Rp{static getters=[`getAutomaticSums`];handle(e){switch(e.type){case`SUM_SELECTION`:let e=this.getters.getActiveSheetId(),{zones:t,anchor:n}=this.getters.getSelection();for(let r of t){let t=this.getAutomaticSums(e,r,n.cell);this.dispatchCellUpdates(e,t)}break}}getAutomaticSums(e,t,n){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,n):this.sumData(e,t)}sumData(e,t){let n=this.dimensionsToSum(e,t),r=this.sumDimensions(e,t,n).filter(({zone:t})=>!this.getters.isEmpty(e,t));return n.has(`ROW`)&&n.has(`COL`)&&r.push(this.sumTotal(t)),r}sumAdjacentData(e,t,n){let{col:r,row:i}=Vs(n.col,n.row,t)?n:{col:t.left,row:t.top},a=this.findAdjacentData(e,r,i);return a?this.getters.isSingleCellOrMerge(e,t)||Ws(Fs(a,t))?[{position:{col:r,row:i},zone:a}]:this.sumDimensions(e,Fs(a,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,n){let r=this.getters.getSheet(e),i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.findSuitableZoneToSum(r,i.col,i.row);if(a)return this.getters.expandZone(e,a)}findSuitableZoneToSum(e,t,n){let r=this.getters.getEvaluatedCell({sheetId:e.id,col:t,row:n-1}),i=this.getters.getEvaluatedCell({sheetId:e.id,col:t-1,row:n});if(this.isNumber(i)&&!this.isNumber(r))return this.findHorizontalZone(e,t,n);let a=this.findVerticalZone(e,t,n);if(this.isZoneValid(a))return a;let o=this.findHorizontalZone(e,t,n);if(this.isZoneValid(o))return o}findVerticalZone(e,t,n){let r={top:0,bottom:n-1,left:t,right:t},i=this.reduceZoneStart(e,r,r.bottom);return{...r,top:i}}findHorizontalZone(e,t,n){let r={top:n,bottom:n,left:0,right:t-1},i=this.reduceZoneStart(e,r,r.right);return{...r,left:i}}reduceZoneStart(e,t,n){let r=this.getters.getEvaluatedCellsInZone(e.id,t),i=S(n,-1,-1),a=$t(i.filter(e=>r[e]&&!r[e].isAutoSummable)),o=gt(i.filter(e=>this.isNumber(r[e])))[0]||[];return $t(o)<a?1/0:en(o)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){return e.type===`number`&&!(e.format&&jo(e.format))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){let n=new Set;return Ws(t)?(n.add(Us(t).numberOfCols===1?`COL`:`ROW`),n):(this.lastColIsEmpty(e,t)&&n.add(`ROW`),this.lastRowIsEmpty(e,t)&&n.add(`COL`),n.size===0&&n.add(`COL`),n)}sumDimensions(e,t,n){return[...n.has(`COL`)?this.sumColumns(t,e):[],...n.has(`ROW`)?this.sumRows(t,e):[]]}sumTotal(e){let{bottom:t,right:n}=e;return{position:{col:n,row:t},zone:{...e,top:t,right:n-1}}}sumColumns(e,t){let n=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,n.bottom-1)},Ks(n).map(t=>({position:t,zone:{...e,right:t.col,left:t.col}}))}sumRows(e,t){let n=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,n.right-1)},Ks(n).map(t=>({position:t,zone:{...e,top:t.row,bottom:t.row}}))}dispatchCellUpdates(e,t){for(let n of t){let{col:t,row:r}=n.position;this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:`=SUM(${this.getters.zoneToXC(e,n.zone)})`})}}nextEmptyRow(e,t){let n=t.bottom+1,{left:r,right:i}=t;for(;!this.getters.isEmpty(e,{bottom:n,top:n,left:r,right:i});)n++;return{...t,top:n,bottom:n}}nextEmptyCol(e,t){let n=t.right+1,{top:r,bottom:i}=t;for(;!this.getters.isEmpty(e,{left:n,right:n,top:r,bottom:i});)n++;return{...t,left:n,right:n}}transpose(e){return new Set([...e.values()].map(e=>e===`COL`?`ROW`:`COL`))}};let TG=new class extends g{addTransformation(e,t,n){this.content[e]||(this.content[e]=new Map);for(let r of t)this.content[e].set(r,n);return this}getTransformation(e,t){return this.content[t]&&this.content[t].get(e)}},EG=new class extends g{add(e,t){return super.add(e,t),this}replace(e,t){return super.replace(e,t),this}get(e){return this.content[e]}};TG.addTransformation(`ADD_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],zG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],zG),TG.addTransformation(`DELETE_SHEET`,[`MOVE_RANGES`],AG),TG.addTransformation(`DELETE_FIGURE`,[`UPDATE_FIGURE`,`UPDATE_CHART`,`UPDATE_CAROUSEL`],jG),TG.addTransformation(`DELETE_CHART`,[`UPDATE_CHART`],MG),TG.addTransformation(`DELETE_CHART`,[`UPDATE_CAROUSEL`],NG),TG.addTransformation(`CREATE_SHEET`,[`CREATE_SHEET`],PG),TG.addTransformation(`ADD_MERGE`,[`ADD_MERGE`,`REMOVE_MERGE`],FG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],IG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],IG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`UPDATE_TABLE`],LG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`UPDATE_TABLE`],LG),TG.addTransformation(`REMOVE_TABLE_STYLE`,[`CREATE_TABLE`,`UPDATE_TABLE`],RG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],BG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],BG),TG.addTransformation(`REMOVE_PIVOT`,[`RENAME_PIVOT`,`DUPLICATE_PIVOT`,`INSERT_PIVOT`,`UPDATE_PIVOT`],kG),TG.addTransformation(`DELETE_SHEET`,[`ADD_PIVOT`,`UPDATE_PIVOT`],OG),TG.addTransformation(`ADD_COLUMNS_ROWS`,[`ADD_PIVOT`,`UPDATE_PIVOT`],DG),TG.addTransformation(`REMOVE_COLUMNS_ROWS`,[`ADD_PIVOT`,`UPDATE_PIVOT`],DG);function DG(e,t){if(e.pivot.type!==`SPREADSHEET`||e.pivot.dataSet?.sheetId!==t.sheetId)return e;let n=of(e.pivot.dataSet.zone,t),r=n?{...e.pivot.dataSet,zone:n}:void 0;return{...e,pivot:{...e.pivot,dataSet:r}}}function OG(e,t){return e.pivot.type===`SPREADSHEET`&&e.pivot.dataSet?.sheetId===t.sheetId?{...e,pivot:{...e.pivot,dataSet:void 0}}:e}function kG(e,t){if(e.pivotId!==t.pivotId)return e}function AG(e,t){let n=t.sheetId;if(!(e.targetSheetId===n||e.sheetId===n))return e}function jG(e,t){if(e.figureId!==t.figureId)return e}function MG(e,t){if(e.chartId!==t.chartId)return e}function NG(e,t){return{...e,definition:{...e.definition,items:e.definition.items.filter(e=>!(e.type===`chart`&&e.chartId===t.chartId))}}}function PG(e,t){return e.sheetId===t.sheetId&&(e={...e,sheetId:`${e.sheetId}~`}),e.name===t.name?{...e,name:e.name?.match(/\d+/)?e.name.replace(/\d+/,e=>(parseInt(e)+1).toString()):`${e.name}~`,position:e.position+1}:e}function FG(e,t){if(e.sheetId!==t.sheetId)return e;let n=[];for(let r of e.target)t.target.every(e=>!zs(r,e))&&n.push(r);if(n.length)return{...e,target:n}}function IG(e,t){if(e.sheetId!==t.sheetId||(e.type===`FREEZE_COLUMNS`?`COL`:`ROW`)!==t.dimension)return e;let n=e.quantity;if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);for(let t of e)n>t&&n--}if(t.type===`ADD_COLUMNS_ROWS`){let e=t.position===`before`?t.base-1:t.base;n=n>e?n+t.quantity:n}return n>0?{...e,quantity:n}:void 0}function LG(e,t){if(e.sheetId!==t.sheetId)return e;let n=of(e.zone,t);if(!n)return;let r=e.newTableRange?sf(e.newTableRange,t):void 0;return{...e,newTableRange:r,zone:n}}function RG(e,t){return e.config?.styleId===t.tableStyleId?{...e,config:{...e.config,styleId:QA.styleId}}:e}function zG(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n;if(t.type===`REMOVE_COLUMNS_ROWS`?n=il(t.elements,[e.base])[0]:t.type===`ADD_COLUMNS_ROWS`&&(n=rl(Ft(t.position,t.base),t.quantity,[e.base])[0]),n!==void 0)return{...e,base:n}}function BG(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n=S(e.start,e.end+1),r=[];if(t.type===`REMOVE_COLUMNS_ROWS`?r=il(t.elements,n):t.type===`ADD_COLUMNS_ROWS`&&(r=rl(Ft(t.position,t.base),t.quantity,n)),r.length!==0)return{...e,start:Math.min(...r),end:Math.max(...r)}}function VG(e,t){let n=e.content&&mC(e.sheetId,e.content,t);return{...e,content:n}}EG.add(`UPDATE_CELL`,VG);function HG(e,t){let n=e.cf.rule;if(e={...e,cf:{...e.cf}},n.type===`CellIsRule`)e.cf.rule={...n,values:n.values.map(n=>mC(e.sheetId,n,t))};else if(n.type===`ColorScaleRule`){let{minimum:r,maximum:i,midpoint:a}=n;e.cf.rule={...n,minimum:{...r,value:r.value&&mC(e.sheetId,r.value,t)},maximum:{...i,value:i.value&&mC(e.sheetId,i.value,t)},midpoint:a?{...a,value:mC(e.sheetId,a.value,t)}:void 0}}else if(n.type===`IconSetRule`){let{upperInflectionPoint:r,lowerInflectionPoint:i}=n;e.cf.rule={...n,upperInflectionPoint:{...r,value:mC(e.sheetId,r.value,t)},lowerInflectionPoint:{...i,value:mC(e.sheetId,i.value,t)}}}else n.type===`DataBarRule`&&(e.cf.rule={...n,rangeValues:n.rangeValues?hC(e.sheetId,n.rangeValues,t).range:void 0});return e}EG.add(`ADD_CONDITIONAL_FORMAT`,HG);function UG(e,t){return e={...e,rule:{...e.rule,criterion:{...e.rule.criterion}}},e.rule.criterion.values=e.rule.criterion.values.map(n=>mC(e.sheetId,n,t)),e}EG.add(`ADD_DATA_VALIDATION_RULE`,UG);function WG(e,t){return e=b(e),e.pivot.measures.map(e=>{e.computedBy&&(e.computedBy.formula=mC(e.computedBy.sheetId,e.computedBy.formula,t))}),e}EG.add(`ADD_PIVOT`,WG),EG.add(`UPDATE_PIVOT`,WG),EG.add(`CREATE_CHART`,GG),EG.add(`UPDATE_CHART`,GG);function GG(e,t){return{...e,definition:bO(e.sheetId,e.definition,t)}}let KG=[{match:pr,fn:ZG},{match:hr,fn:QG},{match:vr,fn:$G},{match:_r,fn:nK},{match:mr,fn:tK},{match:gr,fn:eK}];function qG(e,t){let n=TG.getTransformation(e.type,t.type),r=n?n(e,t):XG(e,t);return r&&JG(r,t)}function JG(e,t){let n=EG.get(e.type);if(!n)return e;let r=Gc(t);return r?n(e,r):e}function YG(e,t){let n=[...e],r=new Set(TG.getKeys());for(let e of t)(r.has(e.type)||Kc.contains(e.type))&&(n=n.reduce((t,n)=>{let r=qG(n,e);return r&&t.push(r),t},[]));return n}function XG(e,t){for(let{match:n,fn:r}of KG)if(n(e)){let n=r(e,t);if(n===`SKIP_TRANSFORMATION`)continue;if(n===`IGNORE_COMMAND`)return;e=n}return e}function ZG(e,t){if(!(`sheetId`in t))return e;let n=t.type===`DELETE_SHEET`&&t.sheetId;return e.sheetId===n?`IGNORE_COMMAND`:e.type===`CREATE_SHEET`||t.type===`CREATE_SHEET`||e.sheetId!==t.sheetId?e:`SKIP_TRANSFORMATION`}function QG(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=[];for(let n of e.target){let e=of(n,t);e&&r.push(e)}return r.length?{...e,target:r}:`IGNORE_COMMAND`}function $G(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=of(e.zone,t);return r?{...e,zone:r}:`IGNORE_COMMAND`}function eK(e,t){if(!(`sheetId`in t))return e;let n=e.ranges.map(e=>sf(e,t)).filter(C);return n.length?{...e,ranges:n}:`IGNORE_COMMAND`}function tK(e,t){let n=ZG(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;if(t.type!==`ADD_COLUMNS_ROWS`&&t.type!==`REMOVE_COLUMNS_ROWS`)return`SKIP_TRANSFORMATION`;if(t.dimension!==e.dimension)return e;let r=[];return t.type===`REMOVE_COLUMNS_ROWS`?r=il(t.elements,e.elements):t.type===`ADD_COLUMNS_ROWS`&&(r=rl(Ft(t.position,t.base),t.quantity,e.elements)),r.length===0?`IGNORE_COMMAND`:{...e,elements:r}}function nK(e,t){let n=ZG(e,t);return n===`SKIP_TRANSFORMATION`?t.type===`ADD_COLUMNS_ROWS`||t.type===`REMOVE_COLUMNS_ROWS`?rK(e,t):t.type===`ADD_MERGE`?iK(e,t):`SKIP_TRANSFORMATION`:n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e}function rK(e,t){let n=t.dimension===`COL`?`col`:`row`,r=e[n];if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);if(e.includes(r))return`IGNORE_COMMAND`;for(let t of e)r>=t&&r--}return t.type===`ADD_COLUMNS_ROWS`&&(r>t.base||r===t.base&&t.position===`before`)&&(r+=t.quantity),{...e,[n]:r}}function iK(e,t){for(let n of t.target)if(!(e.col===n.left&&e.row===n.top)&&Vs(e.col,e.row,n))return`IGNORE_COMMAND`;return e}var aK=class{rootCommand;timestamp;id;clientId;_commands=[];_changes=[];constructor(e,t,n,r,i,a){this.rootCommand=r,this.timestamp=a,this.id=e,this.clientId=t,this._commands=[...n],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}},oK=class extends Error{},sK=class extends cf{revisions;transportService;serverRevisionId;clients={};clientId=`local`;debouncedMove;pendingMessages=[];awaitingClientPosition;waitingAck=!1;waitingUndoRedoAck=!1;isReplayingInitialRevisions=!1;processedRevisions=new Set;lastRevisionMessage=void 0;uuidGenerator=new jl;lastLocalOperation;constructor(e,t,n=We){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=n,this.debouncedMove=At(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t,n){if(!t.length||!n.length||!this.canApplyOptimisticUpdate())return;let r=new aK(this.uuidGenerator.uuidv4(),this.clientId,t,e,n,Date.now());this.revisions.append(r.id,r),e.type!==`REQUEST_REDO`&&(this.lastLocalOperation=r),this.trigger(`new-local-state-update`,{id:r.id}),this.sendUpdateMessage({type:`REMOTE_REVISION`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:r.id,clientId:r.clientId,commands:r.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:`REVISION_UNDONE`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:`REVISION_REDONE`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:`local`,name:`local`},this.clientId=`local`),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this)),this.awaitingClientPosition&&=(this._move(this.awaitingClientPosition),void 0)}loadInitialMessages(e){let t=performance.now(),n=e.reduce((e,t)=>e+(t.type===`REMOTE_REVISION`?t.commands.length:1),0);this.isReplayingInitialRevisions=!0;for(let t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1,console.debug(`Replayed`,n,`commands in`,performance.now()-t,`ms`)}async leave(e){e&&Object.keys(this.clients).length===1&&this.lastRevisionMessage&&this.lastRevisionMessage?.type!==`SNAPSHOT_CREATED`&&await this.snapshot(e()),delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.sendToTransport({type:`CLIENT_LEFT`,clientId:this.clientId,version:1})}async snapshot(e){if(this.pendingMessages.length!==0)return;let t=this.uuidGenerator.uuidv4();await this.sendToTransport({type:`SNAPSHOT`,nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getCurrentClient(){return this.getClient(this.clientId)}getClient(e){let t=this.clients[e];if(!t)throw new oK(`The client left the session`);return t}getConnectedClients(){return new Set(Object.values(this.clients).filter(C))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return this.pendingMessages.length===0}getLastLocalNonEmptyRevision(){return this.lastLocalOperation}_move(e){if(!this.clients[this.clientId]){this.awaitingClientPosition=e;return}let t=this.clients[this.clientId]?.position;if(t?.col===e.col&&t.row===e.row&&t.sheetId===e.sheetId)return;let n=t?`CLIENT_MOVED`:`CLIENT_JOINED`,r=this.getCurrentClient();this.clients[this.clientId]={...r,position:e},this.sendToTransport({type:n,version:1,client:{...r,position:e}}).then(()=>{this.pendingMessages.length>0&&!this.waitingAck&&this.sendPendingMessage()})}onMessageReceived(e){if(!this.isAlreadyProcessed(e)){if(this.isWrongServerRevisionId(e)){this.trigger(`unexpected-revision-id`);return}switch(e.type){case`CLIENT_MOVED`:this.onClientMoved(e);break;case`CLIENT_JOINED`:this.onClientJoined(e);break;case`CLIENT_LEFT`:this.onClientLeft(e);break;case`REVISION_REDONE`:this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger(`revision-redone`,{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case`REVISION_UNDONE`:this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger(`revision-undone`,{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case`REMOTE_REVISION`:let{clientId:t,commands:n,timestamp:r}=e,i=new aK(e.nextRevisionId,t,n,void 0,void 0,r);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);let t=this.pendingMessages.filter(e=>e.type===`REMOTE_REVISION`).map(e=>e.commands).flat();this.trigger(`remote-revision-received`,{commands:YG(n,t)})}break;case`SNAPSHOT_CREATED`:{let t=new aK(e.nextRevisionId,`server`,[],void 0,void 0,Date.now());this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger(`snapshot`),this.lastLocalOperation=void 0;break}}this.acknowledge(e),this.trigger(`collaborative-event-received`)}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;let t=this.clients[this.clientId];if(t){let{position:e}=t;e&&this.sendToTransport({type:`CLIENT_MOVED`,version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),!this.waitingAck&&this.sendPendingMessage()}async sendToTransport(e){return this.transportService.sendMessage(e)}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if(e.type===`REMOTE_REVISION`){let t=this.revisions.get(e.nextRevisionId);t.commands.length===0&&(this.revisions.rebase(t.id),t=this.revisions.get(e.nextRevisionId)),e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.
|
|
1930
1930
|
${JSON.stringify(e)}`);this.waitingAck=!0,this.sendToTransport({...e,serverRevisionId:this.serverRevisionId}).catch(e=>{if(!(e instanceof oK))throw e.cause||e;this.waitingAck=!1})}}acknowledge(e){switch((e.type===`REVISION_UNDONE`||e.type===`REVISION_REDONE`)&&(this.waitingUndoRedoAck=!1),e.type){case`REMOTE_REVISION`:case`REVISION_REDONE`:case`SNAPSHOT_CREATED`:this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter(t=>t.nextRevisionId!==e.nextRevisionId),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.lastRevisionMessage=e,this.sendPendingMessage();break;case`REVISION_UNDONE`:{this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter(t=>t.nextRevisionId!==e.nextRevisionId);let t=this.pendingMessages.findIndex(e=>e.type===`REMOTE_REVISION`);t!==-1&&this.revisions.rebase(this.pendingMessages[t].nextRevisionId),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break}}}isAlreadyProcessed(e){if(e.type===`CLIENT_MOVED`&&e.client.id===this.clientId)return!0;switch(e.type){case`REMOTE_REVISION`:case`REVISION_REDONE`:case`REVISION_UNDONE`:case`SNAPSHOT_CREATED`:return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case`REMOTE_REVISION`:case`REVISION_REDONE`:case`REVISION_UNDONE`:case`SNAPSHOT_CREATED`:return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter(({type:e})=>e!==`REVISION_REDONE`&&e!==`REVISION_UNDONE`)}},cK=class extends Rp{static getters=[`getClientsToDisplay`,`getClient`,`getCurrentClient`,`getConnectedClients`,`isFullySynchronized`];static layers=[`Selection`];colors=new Gn(12);session;constructor(e){super(e),this.session=e.session}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}getClient(e){return this.session.getClient(e)}getCurrentClient(){return this.session.getCurrentClient()}getConnectedClients(){return[...this.session.getConnectedClients()].map(e=>({...e,color:this.colors.get(e.id)}))}isFullySynchronized(){return this.session.isFullySynchronized()}getClientsToDisplay(){try{this.getters.getCurrentClient()}catch(e){if(e instanceof oK)return[];throw e}let e=this.getters.getActiveSheetId(),t=[];for(let n of this.getters.getConnectedClients())n.id!==this.getters.getCurrentClient().id&&n.position&&n.position.sheetId===e&&this.isPositionValid(n.position)&&t.push({...n,position:n.position});return t}drawLayer(e){if(this.getters.isDashboard())return;let{ctx:t,thinLineWidth:n}=e,r=this.getters.getActiveSheetId();for(let e of this.getClientsToDisplay()){let{row:i,col:a}=e.position,o=this.getters.expandZone(r,{top:i,bottom:i,left:a,right:a}),{x:s,y:c,width:l,height:u}=this.getters.getVisibleRect(o);if(l<=0||u<=0)continue;let d=e.color;t.fillStyle=`${d}10`,t.lineWidth=4*n,t.strokeStyle=d,t.globalCompositeOperation=`multiply`,t.fillRect(s,c,l,u),t.globalCompositeOperation=`source-over`,t.strokeRect(s,c,l,u),t.font=`bold ${Ve+1}px ${He}`}}},lK=class extends Rp{allowDispatch(e){switch(e.type){case`REMOVE_DUPLICATES`:return this.checkValidations(e,this.chainValidations(this.checkSingleRangeSelected,this.checkNoMergeInZone,this.checkRangeContainsValues,this.checkColumnsIncludedInZone),this.chainValidations(this.checkNoColumnProvided,this.checkColumnsAreUnique))}return`Success`}handle(e){switch(e.type){case`REMOVE_DUPLICATES`:this.removeDuplicates(e.columns,e.hasHeader);break;case`TRIM_WHITESPACE`:this.trimWhitespace();break}}removeDuplicates(e,t){let n=this.getters.getActiveSheetId(),r=this.getters.getSelectedZone();t&&(r.top+=1);let i=this.getUniqueRowsIndexes(n,r.top,r.bottom,e),a=i.length;if(a===Us(r).numberOfRows){this.notifyRowsRemovedAndRemaining(0,a);return}let o=i.map(e=>({left:r.left,top:e,right:r.right,bottom:e})),s=new Yd(this.getters,this.dispatch),c=s.copy(Nl(n,o),!1);if(!c)return;this.dispatch(`CLEAR_CELLS`,{target:[r],sheetId:n});let l={left:r.left,top:r.top,right:r.left,bottom:r.top};s.paste({zones:[l],sheetId:n},c,{isCutOperation:!1});let u={left:r.left,top:r.top-+!!t,right:r.right,bottom:r.top+a-1};this.selection.selectZone({cell:{col:u.left,row:u.top},zone:u});let d=r.bottom-r.top+1-a;this.notifyRowsRemovedAndRemaining(d,a)}getUniqueRowsIndexes(e,t,n,r){let i=new Map;for(let a of S(t,n+1)){let t=r.map(t=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:a}).value);Object.values(i).some(e=>w(e,t))||(i[a]=t)}return Object.keys(i).map(e=>parseInt(e))}notifyRowsRemovedAndRemaining(e,t){this.ui.notifyUI({type:`info`,text:E(`%s duplicate rows found and removed.
|
|
1931
|
-
%s unique rows remain.`,e.toString(),t.toString()),sticky:!1})}checkSingleRangeSelected(){return this.getters.getSelectedZones().length===1?`Success`:`MoreThanOneRangeSelected`}checkNoMergeInZone(){let e=this.getters.getActiveSheetId(),t=this.getters.getSelectedZone();return this.getters.getMergesInZone(e,t).length>0?`WillRemoveExistingMerge`:`Success`}checkRangeContainsValues(e){let t=this.getters.getActiveSheetId(),n=this.getters.getSelectedZone();return e.hasHeader&&(n.top+=1),this.getters.getEvaluatedCellsInZone(t,n).every(e=>e.type===`empty`)?`EmptyTarget`:`Success`}checkNoColumnProvided(e){return e.columns.length===0?`NoColumnsProvided`:`Success`}checkColumnsIncludedInZone(e){let t=this.getters.getSelectedZone();return e.columns.some(e=>e<t.left||e>t.right)?`ColumnsNotIncludedInZone`:`Success`}checkColumnsAreUnique(e){return e.columns.length===new Set(e.columns).size?`Success`:`DuplicatesColumnsSelected`}trimWhitespace(){let e=ms(this.getters.getSelectedZones()),t=this.getters.getActiveSheetId(),n=0;for(let{col:r,row:i}of e.map(Ks).flat()){let e=this.getters.getCell({col:r,row:i,sheetId:t});if(!e)continue;let a=Xt(e.content);a!==e.content&&(n+=1,this.dispatch(`UPDATE_CELL`,{sheetId:t,col:r,row:i,content:a}))}let r=n?E(`Trimmed whitespace from %s cells.`,n):E(`No selected cells had whitespace trimmed.`);this.ui.notifyUI({type:`info`,text:r,sticky:!1})}},uK=class extends Rp{handle(e){switch(e.type){case`SET_DECIMAL`:this.setDecimal(e.sheetId,e.target,e.step);break;case`SET_FORMATTING_WITH_PIVOT`:this.setContextualFormat(e.sheetId,e.target,e.format);break}}setContextualFormat(e,t,n){let r=[],i={};for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let a=n.top;a<=n.bottom;a++){let n={sheetId:e,col:t,row:a},o=this.getters.getPivotCellFromPosition(n);if(this.isSpilledPivotValueFormula(n,o)){r.push(n);let e=this.getters.getPivotIdFromPosition(n)||``;i[e]??=new Set,i[e].add(o.measure)}}let a=ms(r.map(R));for(let e in i){let t=i[e],r=this.getters.getPivotCoreDefinition(e);this.dispatch(`UPDATE_PIVOT`,{pivotId:e,pivot:{...r,measures:r.measures.map(e=>t.has(e.id)?{...e,format:n}:e)}})}this.dispatch(`SET_FORMATTING`,{sheetId:e,target:a,format:``}),this.dispatch(`SET_FORMATTING`,{sheetId:e,target:ms(t,a),format:n})}isSpilledPivotValueFormula(e,t){let n=this.getters.getCell(e);return t.type===`VALUE`&&!n?.isFormula}setDecimal(e,t,n){let r={};for(let i of ms(t))for(let t of Ks(i)){let i=this.getCellNumberFormat({sheetId:e,...t});if(i!==void 0){let e=Jo(i,n);r[e]=r[e]||[],r[e].push(t)}}for(let t in r){let n=ms(r[t].map(e=>R(e)));this.setContextualFormat(e,n,t)}}getCellNumberFormat(e){for(let t of[e]){let e=this.getters.getEvaluatedCell(t);if(e.type===`number`&&!(e.format&&jo(e.format)))return e.format||Fo(e.value)}}},dK=class extends Rp{static getters=[`getGeoJsonFeatures`,`geoFeatureNameToId`,`getGeoChartAvailableRegions`];geoJsonService;geoJsonCache={};constructor(e){super(e),this.geoJsonService=e.external.geoJsonService}getGeoChartAvailableRegions(){return this.geoJsonService?this.geoJsonService.getAvailableRegions()||[]:(console.error(`No geoJsonService provided to the model`),[])}getGeoJsonFeatures(e){if(!this.geoJsonService){console.error(`No geoJsonService provided to the model`);return}let t=this.geoJsonCache[e];if(!(t instanceof Promise)){if(t!==void 0)return t??void 0;this.geoJsonCache[e]=new Promise(async t=>{let n=await this.geoJsonService?.getTopoJson(e);this.geoJsonCache[e]=this.convertToGeoJson(n),this.dispatch(`EVALUATE_CHARTS`),t()})}}geoFeatureNameToId(e,t){if(!this.geoJsonService){console.error(`No geoJsonService provided to the model`);return}return this.geoJsonService.geoFeatureNameToId(e,t)}convertToGeoJson(e){if(!e)return null;if(e.type===`Topology`){let t=window.ChartGeo.topojson.feature(e,Object.values(e.objects)[0]);return t.type===`FeatureCollection`?t.features:[t]}else if(e.type===`FeatureCollection`)return e.features;throw Error(`Invalid TopoJSON`)}},fK=class extends Rp{static getters=[`getNextVisibleCellPosition`,`findVisibleHeader`,`findLastVisibleColRowIndex`,`findFirstVisibleColRowIndex`,`isRowHidden`,`isColHidden`,`isHeaderHidden`];isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,n){return t===`COL`?this.isColHidden(e,n):this.isRowHidden(e,n)}getNextVisibleCellPosition({sheetId:e,col:t,row:n}){return{sheetId:e,col:this.findVisibleHeader(e,`COL`,t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,`ROW`,n,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,n,r){if(n<=r){for(let i=n;i<=r;i++)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}if(n>r){for(let i=n;i>=r;i--)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}}findLastVisibleColRowIndex(e,t,{last:n,first:r}){return S(n,r,-1).find(n=>!this.isHeaderHidden(e,t,n))||r}findFirstVisibleColRowIndex(e,t){let n=this.getters.getNumberHeaders(e,t);for(let r=0;r<n;r++)if(t===`COL`&&!this.isColHidden(e,r)||t===`ROW`&&!this.isRowHidden(e,r))return r}exportForExcel(e){for(let t of e.sheets)for(let[e,n]of Object.entries(t.rows))n.isHidden=this.isRowHidden(t.id,Number(e))}},pK=class extends Rp{static getters=[];allowDispatch(e){switch(e.type){case`DUPLICATE_PIVOT_IN_NEW_SHEET`:if(!this.getters.isExistingPivot(e.pivotId))return`PivotIdNotFound`;if(!this.getters.getPivot(e.pivotId).isValid())return`PivotInError`;break}return`Success`}handle(e){switch(e.type){case`INSERT_NEW_PIVOT`:this.insertNewPivot(e.pivotId,e.newSheetId);break;case`DUPLICATE_PIVOT_IN_NEW_SHEET`:this.duplicatePivotInNewSheet(e.pivotId,e.newPivotId,e.newSheetId);break;case`INSERT_PIVOT_WITH_TABLE`:this.insertPivotWithTable(e.sheetId,e.col,e.row,e.pivotId,e.table,e.pivotMode);break;case`SPLIT_PIVOT_FORMULA`:this.splitPivotFormula(e.sheetId,e.col,e.row,e.pivotId)}}insertNewPivot(e,t){nc(this.getters.getSelectedZone())===1&&this.selection.selectTableAroundSelection();let n=this.getters.getActiveSheetId();this.dispatch(`ADD_PIVOT`,{pivotId:e,pivot:{dataSet:{zone:this.getters.getSelectedZone(),sheetId:n},columns:[],rows:[],measures:[],name:E(`New pivot`),type:`SPREADSHEET`}});let r=this.getters.getSheetIds().findIndex(e=>e===n)+1,i=this.getters.getPivotFormulaId(e);this.dispatch(`CREATE_SHEET`,{sheetId:t,name:E(`Pivot #%(formulaId)s`,{formulaId:i}),position:r}),this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:n,sheetIdTo:t});let a=this.getters.getPivot(e);this.insertPivotWithTable(t,0,0,e,a.getCollapsedTableStructure().export(),`dynamic`)}duplicatePivotInNewSheet(e,t,n){this.dispatch(`DUPLICATE_PIVOT`,{pivotId:e,newPivotId:t,duplicatedPivotName:E(`%s (copy)`,this.getters.getPivotCoreDefinition(e).name)});let r=this.getters.getActiveSheetId(),i=this.getters.getSheetIds().indexOf(r)+1,a=this.getters.getPivotFormulaId(t),o=this.getters.getPivotName(t);if(this.dispatch(`CREATE_SHEET`,{sheetId:n,name:this.getPivotDuplicateSheetName(E(`%(newPivotName)s (Pivot #%(formulaId)s)`,{newPivotName:o,formulaId:a})),position:i}).isSuccessful){this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:r,sheetIdTo:n});let i=this.getters.getPivot(e);this.insertPivotWithTable(n,0,0,t,i.getCollapsedTableStructure().export(),`dynamic`)}}getPivotDuplicateSheetName(e){let t=this.getters.getSheetIds().map(e=>this.getters.getSheetName(e));return an(ht(e),t)}insertPivotWithTable(e,t,n,r,i,a){let{cols:o,rows:s,measures:c,fieldsType:l}=i,u=new nR(o,s,c,l||{}),d=u.columns.length-1;this.resizeSheet(e,t,n,u);let f=this.getters.getPivotFormulaId(r),p;a===`dynamic`?(this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:n,content:`=PIVOT(${f})`}),p={left:t,right:t,top:n,bottom:n}):(this.dispatch(`INSERT_PIVOT`,{sheetId:e,col:t,row:n,pivotId:r,table:u.export()}),p={left:t,right:t+u.getNumberOfDataColumns(),top:n,bottom:n+d+u.rows.length}),this.dispatch(`CREATE_TABLE`,{tableType:a,sheetId:e,ranges:[this.getters.getRangeDataFromZone(e,p)],config:{...tt,numberOfHeaders:d}})}resizeSheet(e,t,n,r){let i=r.getNumberOfDataColumns()+1,a=this.getters.getNumberCols(e),o=a-t;o<i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:a-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:i-o,position:`after`});let s=r.columns.length+r.rows.length,c=this.getters.getNumberRows(e),l=c-n;l<s&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:c-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:s-l,position:`after`})}splitPivotFormula(e,t,n,r){let i=this.getters.getSpreadZone({sheetId:e,col:t,row:n});if(!i)return;let a=this.getters.getPivotFormulaId(r),o=new Map;for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++){let r={sheetId:e,col:t,row:n};o.set(r,this.getters.getPivotCellFromPosition(r))}for(let[e,t]of o)this.dispatch(`UPDATE_CELL`,{...e,content:Md(a,t)});if(this.getters.getCoreTable({sheetId:e,col:t,row:n})?.type===`dynamic`){let r=R({col:t,row:n}),a=this.getters.getRangeDataFromZone(e,i);this.dispatch(`UPDATE_TABLE`,{sheetId:e,zone:r,newTableRange:a,tableType:`static`})}}},mK=class extends Rp{allowDispatch(e){switch(e.type){case`SORT_CELLS`:return Vs(e.col,e.row,e.zone)?this.checkValidations(e,this.checkMerge,this.checkMergeSizes,this.checkArrayFormulaInSortZone):`InvalidSortAnchor`}return`Success`}handle(e){switch(e.type){case`SORT_CELLS`:this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{});break}}checkMerge({sheetId:e,zone:t}){return this.getters.doesIntersectMerge(e,t)&&Ks(t).some(({col:t,row:n})=>!this.getters.isInMerge({sheetId:e,col:t,row:n}))?`InvalidSortZone`:`Success`}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return`Success`;let n=this.getters.getMerges(e).filter(e=>zs(e,t)),r=Us(n[0]),[i,a]=[r.numberOfCols,r.numberOfRows];return n.every(e=>{let[t,n]=[e.right-e.left+1,e.bottom-e.top+1];return t===i&&n===a})?`Success`:`InvalidSortZone`}checkArrayFormulaInSortZone({sheetId:e,zone:t}){return Ks(t).some(({col:t,row:n})=>{let r=this.getters.getArrayFormulaSpreadingOn({sheetId:e,col:t,row:n});return r&&!w(r,{sheetId:e,col:t,row:n})})?`SortZoneWithArrayFormulas`:`Success`}hasHeader(e,t){if(t[0].length===1)return!1;let n=t.map(t=>t.map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}).type));return n[0][0]===`empty`&&(n=n.slice(1)),n.some(e=>e[0]===`empty`)?!1:!!n.some(e=>e[1]!==`empty`&&e[0]!==e[1])}sortZone(e,t,n,r,i){let[a,o]=this.mainCellsSteps(e,n),s=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,c=Object.assign({},n),l=this.mainCells(e,n);!i.sortHeaders&&this.hasHeader(e,l)&&(c.top+=o),l=this.mainCells(e,c);let u=l[s-c.left],d=vv(u.map(e=>this.getters.getEvaluatedCell(e)),r,!!i.emptyCellAsZero).map(e=>e.index),[f,p]=[l.length,l[0].length],m=[];for(let e=0;e<f;e++)for(let t=0;t<p;t++){let{col:n,row:r,sheetId:i}=l[e][d[t]],s=this.getters.getCell({sheetId:i,col:n,row:r}),u=c.left+e*a,f=c.top+t*o,p={sheetId:i,col:u,row:f,content:``};if(s){let e=s.content;if(s.isFormula){let t=this.getters.getCellPosition(s.id);e=this.getters.getTranslatedCellFormula(i,0,f-t.row,s.compiledFormula.tokens)}p.style=s.style,p.content=e,p.format=s.format}m.push(p)}m.forEach(e=>this.dispatch(`UPDATE_CELL`,e))}mainCellsSteps(e,t){let n=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[n?n.right-n.left+1:1,n?n.bottom-n.top+1:1]}mainCells(e,t){let[n,r]=this.mainCellsSteps(e,t),i=[],a=S(t.left,t.right+1,n),o=S(t.top,t.bottom+1,r);for(let t of a){let n=[];i.push(n);for(let r of o)n.push({sheetId:e,col:t,row:r})}return i}},hK=class extends Rp{static getters=[`shouldShowFormulas`];showFormulas=!1;handle(e){switch(e.type){case`SET_FORMULA_VISIBILITY`:this.showFormulas=e.show;break}}shouldShowFormulas(){return this.showFormulas}},gK=class extends Rp{static getters=[`getCellWidth`,`getTextWidth`,`getCellText`,`getCellMultiLineText`,`getContiguousZone`,`computeTextYCoordinate`];ctx=document.createElement(`canvas`).getContext(`2d`);allowDispatch(e){return this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e)}handle(e){switch(e.type){case`AUTORESIZE_COLUMNS`:for(let t of e.cols){let n=this.getColMaxWidth(e.sheetId,t);n!==0&&this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:[t],dimension:`COL`,size:n,sheetId:e.sheetId})}break;case`AUTORESIZE_ROWS`:this.autoResizeRows(e.sheetId,e.rows);break;case`DELETE_UNFILTERED_CONTENT`:let t=[];for(let n of e.target){let r=gt(S(n.top,n.bottom+1).filter(t=>!this.getters.isRowFiltered(e.sheetId,t)));for(let e of r)t.push({...n,top:e[0],bottom:e[e.length-1]})}this.dispatch(`DELETE_CONTENT`,{sheetId:e.sheetId,target:t});break}}getCellWidth(e){let t=this.getters.getCellComputedStyle(e),n=0,r=this.getters.getEvaluatedCell(e).formattedValue;if(r){let e=Cl(this.ctx,r,t,void 0);n+=Math.max(...e.map(e=>ml(this.ctx,e,t)))}for(let t of this.getters.getCellIcons(e))n+=t.margin+t.size;if(this.getters.getDataValidationChipStyle(e)&&(n+=10),n===0)return 0;if(n+=8,t.wrapping===`wrap`){let t=this.getters.getColSize(this.getters.getActiveSheetId(),e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return ml(this.ctx,e,t)}getCellText(e,t){let n=this.getters.getCell(e),r=this.getters.getLocale();if(t?.showFormula&&n?.isFormula)return gu(n.content,r);if(t?.showFormula&&!n?.content)return``;{let i=this.getters.getEvaluatedCell(e),a=t?.availableWidth?{availableWidth:t.availableWidth,measureText:e=>ml(this.ctx,e,n?.style||{})}:void 0;return L(i.value,{format:i.format,locale:r,formatWidth:a})}}getCellMultiLineText(e,t){let n=this.getters.getCellStyle(e),r=this.getters.getCellText(e,{showFormula:this.getters.shouldShowFormulas(),availableWidth:t.formatWidth});return Cl(this.ctx,r,n,t.wrapText?t.maxWidth:void 0)}computeTextYCoordinate(e,t,n=ze,r=1){let i=e.y+1,a=ll(t,r);if(e.height>a+8){if(n===`middle`)return Math.ceil(i+(e.height-a)/2);if(n===`bottom`)return i+e.height-a-4}return i+4}getContiguousZone(e,t){let n=t=>{for(let n of S(t.left,t.right+1)){if(!this.isCellEmpty({sheetId:e,col:n,row:t.top-1}))return{...t,top:t.top-1};if(!this.isCellEmpty({sheetId:e,col:n,row:t.bottom+1}))return{...t,bottom:t.bottom+1}}for(let n of S(t.top,t.bottom+1)){if(!this.isCellEmpty({sheetId:e,col:t.left-1,row:n}))return{...t,left:t.left-1};if(!this.isCellEmpty({sheetId:e,col:t.right+1,row:n}))return{...t,right:t.right+1}}return t},r=!1,i=t;do{r=!1;let e=n(i);Rs(i,e)||(r=!0,i=e)}while(r);return i}isCellEmpty(e){let t=this.getters.getMainCellPosition(e);return this.getters.getEvaluatedCell(t).type===`empty`}getColMaxWidth(e,t){let n=Ks(this.getters.getColsZone(e,t,t)).map(t=>this.getCellWidth({sheetId:e,...t}));return Math.max(0,$t(n))}checkSheetExists(e){return`sheetId`in e&&this.getters.tryGetSheet(e.sheetId)===void 0?`InvalidSheetId`:`Success`}checkZonesAreInSheet(e){let t=`sheetId`in e?e.sheetId:this.getters.tryGetActiveSheetId();if(`ranges`in e&&e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId)))return`InvalidSheetId`;let n=this.getters.getCommandZones(e);return!t&&n.length>0?`NoActiveSheet`:t&&n.length>0?this.getters.checkZonesExistInSheet(t,n):`Success`}autoResizeRows(e,t){let n=[];for(let r of t){let t=0;for(let n of this.getters.getRowCells(e,r)){let r=this.getters.getCellById(n);if(!r)continue;let i=this.getters.getCellPosition(r.id),a=this.getters.getColSize(e,i.col);if(r.isFormula||this.getters.getArrayFormulaSpreadingOn(i)){let e=this.getters.getEvaluatedCell(i).formattedValue,n=dl(this.ctx,e,r?.style,a);n>t&&n>23&&(t=n)}else{let e=r.content,n=dl(this.ctx,e,r?.style,a);n>=t&&n>23&&(t=0)}}n.push(t||null)}let r=new Map(n.map(e=>[e,[]]));for(let e=0;e<n.length;e++)r.get(n[e])?.push(t[e]);for(let[t,n]of r)this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:n,dimension:`ROW`,size:t,sheetId:e})}},_K=class extends Rp{static getters=[`getCellTableStyle`,`getCellTableBorder`];tableStyles={};handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)||e.type===`EVALUATE_CELLS`){this.tableStyles={};return}if(yK(e)){`sheetId`in e?delete this.tableStyles[e.sheetId]:this.tableStyles={};return}}finalize(){for(let e of this.getters.getSheetIds()){this.tableStyles[e]||(this.tableStyles[e]={});for(let t of this.getters.getTables(e))this.tableStyles[e][t.id]||(this.tableStyles[e][t.id]=this.computeTableStyle(e,t))}}getCellTableStyle(e){let t=this.getters.getTable(e);if(t)return this.tableStyles[e.sheetId][t.id]().styles[e.col]?.[e.row]}getCellTableBorder(e){let t=this.getters.getTable(e);if(t)return this.tableStyles[e.sheetId][t.id]().borders[e.col]?.[e.row]}computeTableStyle(e,t){return Nt(()=>{let{config:n,numberOfCols:r,numberOfRows:i}=this.getTableRuntimeConfig(e,t),a=vI(n,this.getters.getTableStyle(t.config.styleId),r,i),o=this.getTableMapping(e,t),s={borders:{},styles:{}};for(let e=0;e<r;e++){let t=o.colMapping[e];s.borders[t]={},s.styles[t]={};for(let n=0;n<i;n++){let r=o.rowMapping[n];s.borders[t][r]=a.borders[e][n],s.styles[t][r]=a.styles[e][n]}}return s})}getTableRuntimeConfig(e,t){let n=t.range.zone,r={...t.config},i=n.right-n.left+1,a=n.bottom-n.top+1;for(let i=n.top;i<=n.bottom;i++)this.getters.isRowHidden(e,i)&&(a--,i-n.top<t.config.numberOfHeaders&&(r.numberOfHeaders--,r.numberOfHeaders<0&&(r.numberOfHeaders=0)),i===n.bottom&&(r.totalRow=!1));for(let t=n.left;t<=n.right;t++)this.getters.isColHidden(e,t)&&(i--,t===n.left&&(r.firstColumn=!1),t===n.right&&(r.lastColumn=!1));return{config:r,numberOfCols:i,numberOfRows:a}}getTableMapping(e,t){let n={},r={},i=0,a=0,o=t.range.zone;for(let t=o.left;t<=o.right;t++)if(!this.getters.isColHidden(e,t)){n[i]=t,i++;for(let t=o.top;t<=o.bottom;t++)this.getters.isRowHidden(e,t)||(r[a]=t,a++)}return{colMapping:n,rowMapping:r}}};let vK=new Set([`HIDE_COLUMNS_ROWS`,`UNHIDE_COLUMNS_ROWS`,`UNFOLD_HEADER_GROUP`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`FOLD_ALL_HEADER_GROUPS`,`UNFOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`CREATE_TABLE`,`UPDATE_TABLE`,`UPDATE_FILTER`,`REMOVE_TABLE`,`RESIZE_TABLE`,`CREATE_TABLE_STYLE`,`REMOVE_TABLE_STYLE`]);function yK(e){return vK.has(e.type)}var bK=class extends Rp{static getters=[`getCellComputedBorder`,`getCellComputedStyle`];styles=new LF;borders=new LF;handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`||e.type===`SET_FORMATTING`||e.type===`CLEAR_FORMATTING`||e.type===`ADD_DATA_VALIDATION_RULE`||e.type===`REMOVE_DATA_VALIDATION_RULE`||e.type===`EVALUATE_CELLS`){this.styles=new LF,this.borders=new LF;return}if(yK(e)){`sheetId`in e?(this.styles.clearSheet(e.sheetId),this.borders.clearSheet(e.sheetId)):(this.styles=new LF,this.borders=new LF);return}if(Sr.has(e.type)){this.styles=new LF;return}if(Cr.has(e.type)){this.borders=new LF;return}}getCellComputedBorder(e){let t=this.borders.get(e);return t===void 0&&(t=this.computeCellBorder(e),this.borders.set(e,t)),t}getCellComputedStyle(e){let t=this.styles.get(e);return t===void 0&&(t=this.computeCellStyle(e),this.styles.set(e,t)),t}computeCellBorder(e){let t=this.getters.getCellBorder(e)||{},n={...zt(this.getters.getCellTableBorder(e)||{}),...zt(t)};return kt(n)?null:n}computeCellStyle(e){let t=this.getters.getCell(e),n=this.getters.getCellConditionalFormatStyle(e),r=this.getters.getCellTableStyle(e),i=this.getters.getDataValidationCellStyle(e),a={...zt(r),...zt(i),...zt(t?.style),...zt(n)};return this.getters.getEvaluatedCell(e).link&&!a.textColor&&(a.textColor=le),a}},xK=class extends Rp{static getters=[`hasBooleanValidationInZones`];handle(e){switch(e.type){case`TOGGLE_CHECKBOX`:this.toggleCheckbox(e.sheetId,e.target);break}}hasBooleanValidationInZones(e){let t=this.getters.getActiveSheetId();for(let n of e)for(let e=n.left;e<=n.right;e++)for(let r=n.top;r<=n.bottom;r++)if(this.getters.isCellValidCheckbox({col:e,row:r,sheetId:t}))return!0;return!1}toggleCheckbox(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++){let n={col:t,row:r,sheetId:e};if(this.getters.isCellValidCheckbox(n)){let e=this.getters.getEvaluatedCell(n).value?`FALSE`:`TRUE`;this.dispatch(`UPDATE_CELL`,{...n,content:e})}}}},SK=class extends Rp{handle(e){switch(e.type){case`ADD_DATA_VALIDATION_RULE`:if(e.rule.criterion.type===`isBoolean`){let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e));for(let e of Vc(t)){let t=this.getters.getCell(e),n=this.getters.getEvaluatedCell(e);if(!t?.content)this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`});else if(t?.content&&n.type===`empty`){let n;if(t.content.startsWith(`=`)){let r=this.getters.evaluateFormula(e.sheetId,t.content);n=(Ir(r)?r[0][0]:r)?.toString()}else n=t.content;(!n||!vt(n))&&this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`})}else n.type!==`boolean`&&this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`})}}}}},CK=class extends Rp{static getters=[`dynamicTranslate`];dynamicTranslate(e){return e}};let wK=[TK,EK,OK,kK];function TK(e,t){return`sheetId`in t?{...b(t),sheetId:e.getActiveSheetId()}:t}function EK(e,t){return!(`target`in t)||!Array.isArray(t.target)?t:{...b(t),target:e.getSelectedZones()}}function DK(e,t){return`zone`in t?{...b(t),zone:e.getSelectedZone()}:t}function OK(e,t){if(!(`row`in t)||!(`col`in t))return t;let{col:n,row:r}=e.getActivePosition();return{...b(t),col:n,row:r}}function kK(e,t){return`ranges`in t?{...b(t),ranges:e.getSelectedZones().map(t=>e.getRangeDataFromZone(e.getActiveSheetId(),t))}:t}let AK=new jl;function jK(e,t){let n=AK.smallUuid();return{...TK(e,t),figureId:n,chartId:n}}function MK(e,t){return{...TK(e,t),figureId:AK.smallUuid()}}function NK(e,t){let n=OK(e,TK(e,t));return n.figureId=AK.smallUuid(),n}function PK(e,t){let n=b(t);n.sheetId=AK.smallUuid();let r=t.name||e.getSheet(e.getActiveSheetId()).name,i=r.match(/(.+?)\d*$/)?.[1]||r;return n.name=e.getNextSheetName(i),n}function FK(e,t){let n=e.getActivePosition();return{...TK(e,t),base:t.dimension===`COL`?n.col:n.row}}function IK(e,t){let n=e.getSelectedZone();return{...TK(e,t),elements:t.dimension===`COL`?S(n.left,n.right+1):S(n.top,n.bottom+1)}}function LK(e,t){let n=e.getSelectedZone();return{...b(t),zone:n}}function RK(e,t){let n=b(t),{top:r,bottom:i,left:a,right:o}=e.getSelectedZone();return`cols`in n?n.cols=S(a,o+1):`rows`in n&&(n.rows=S(r,i+1)),n}function zK(e,t){let n=e.getSelectedZone();return{...TK(e,t),col:n.left,row:n.top,zone:n}}function BK(e,t){return{type:`REPEAT_PASTE`,pasteOption:b(t.pasteOption),target:e.getSelectedZones()}}function VK(e,t){let n=e.getSelectedZone();return{...TK(e,t),start:t.dimension===`COL`?n.left:n.top,end:t.dimension===`COL`?n.right:n.bottom}}let HK=new g;HK.add(`UPDATE_CELL`,WK),HK.add(`CLEAR_CELL`,WK),HK.add(`CLEAR_CELLS`,WK),HK.add(`DELETE_CONTENT`,WK),HK.add(`ADD_MERGE`,WK),HK.add(`REMOVE_MERGE`,WK),HK.add(`SET_FORMATTING`,WK),HK.add(`CLEAR_FORMATTING`,WK),HK.add(`SET_BORDER`,WK),HK.add(`CREATE_TABLE`,WK),HK.add(`REMOVE_TABLE`,WK),HK.add(`HIDE_SHEET`,WK),HK.add(`ADD_COLUMNS_ROWS`,FK),HK.add(`REMOVE_COLUMNS_ROWS`,IK),HK.add(`HIDE_COLUMNS_ROWS`,IK),HK.add(`RESIZE_COLUMNS_ROWS`,IK),HK.add(`CREATE_SHEET`,PK),HK.add(`CREATE_FIGURE`,NK),HK.add(`CREATE_CHART`,jK),HK.add(`CREATE_IMAGE`,MK),HK.add(`GROUP_HEADERS`,VK),HK.add(`UNGROUP_HEADERS`,VK),HK.add(`UNFOLD_HEADER_GROUPS_IN_ZONE`,DK),HK.add(`FOLD_HEADER_GROUPS_IN_ZONE`,DK);let UK=new g;UK.add(`PASTE`,BK),UK.add(`INSERT_CELL`,LK),UK.add(`DELETE_CELL`,LK),UK.add(`AUTORESIZE_COLUMNS`,RK),UK.add(`AUTORESIZE_ROWS`,RK),UK.add(`SORT_CELLS`,zK),UK.add(`SUM_SELECTION`,WK),UK.add(`SET_DECIMAL`,WK),UK.add(`DELETE_UNFILTERED_CONTENT`,WK);function WK(e,t){let n=b(t);for(let t of wK)n=t(e,n);return n}function GK(e,t){if(t&&HK.contains(t.type))return HK.get(t.type)(e,t)}function KK(e,t,n){if(UK.contains(t.type))return UK.get(t.type)(e,t,n)}function qK(e){return!e||!e.rootCommand||typeof e.rootCommand!=`object`?!1:Dr(e.rootCommand)?HK.contains(e.rootCommand.type):UK.contains(e.rootCommand.type)}function JK(e,t){if(!(!e.rootCommand||typeof e.rootCommand!=`object`))return Dr(e.rootCommand)?GK(t,e.rootCommand):KK(t,e.rootCommand,e.commands)}var YK=class extends Rp{static getters=[`canUndo`,`canRedo`];undoStack=[];redoStack=[];session;constructor(e){super(e),this.session=e.session,this.session.on(`new-local-state-update`,this,this.onNewLocalStateUpdate),this.session.on(`snapshot`,this,()=>{this.undoStack=[],this.redoStack=[]})}allowDispatch(e){switch(e.type){case`REQUEST_UNDO`:if(!this.canUndo())return`EmptyUndoStack`;break;case`REQUEST_REDO`:if(!this.canRedo())return`EmptyRedoStack`;break}return`Success`}handle(e){switch(e.type){case`REQUEST_UNDO`:case`REQUEST_REDO`:this.requestHistoryChange(e.type===`REQUEST_UNDO`?`UNDO`:`REDO`)}}finalize(){}requestHistoryChange(e){let t=e===`UNDO`?this.undoStack.pop():this.redoStack.pop();if(!t){let e=this.getPossibleRevisionToRepeat();if(!e)return;let t=JK(e,this.getters);if(!t)return;if(!Array.isArray(t)){this.dispatch(t.type,t);return}for(let e of t)this.dispatch(e.type,e);return}e===`UNDO`?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0?!0:qK(this.getPossibleRevisionToRepeat())}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}getPossibleRevisionToRepeat(){return this.session.getLastLocalNonEmptyRevision()}},XK=class{trackedValues=new Set;domainToArray(e){return e.flatMap(e=>[e.field,N(e.value)])}isValuePresent(e,t){let n=JSON.stringify({measure:e,domain:this.domainToArray(t)});return this.trackedValues.has(n)}isHeaderPresent(e){let t=JSON.stringify({domain:this.domainToArray(e)});return this.trackedValues.has(t)}trackValue(e,t){let n=JSON.stringify({measure:e,domain:this.domainToArray(t)});this.trackedValues.add(n)}trackHeader(e){let t=JSON.stringify({domain:this.domainToArray(e)});this.trackedValues.add(t)}},ZK=class extends Rp{static getters=[`getPivotPresenceTracker`];trackPresencePivotId;tracker;handle(e){switch(e.type){case`PIVOT_START_PRESENCE_TRACKING`:this.tracker=new XK,this.trackPresencePivotId=e.pivotId;break;case`PIVOT_STOP_PRESENCE_TRACKING`:this.trackPresencePivotId=void 0;break}}getPivotPresenceTracker(e){if(this.trackPresencePivotId===e){if(!this.tracker)throw Error(`Tracker not initialized`);return this.tracker}}},QK=class extends Rp{static getters=[`getAutomaticSeparator`];allowDispatch(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:return this.chainValidations(this.batchValidations(this.checkSingleColSelected,this.checkNonEmptySelector),this.batchValidations(this.checkNotOverwritingContent,this.checkSeparatorInSelection))(e)}return`Success`}handle(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:this.splitIntoColumns(e);break}}getAutomaticSeparator(){let e=this.getters.getSelectedCells();for(let t of e)if(t.value&&t.type===`text`){let e=this.getAutoSeparatorForString(t.value);if(e)return e}return` `}getAutoSeparatorForString(e){for(let t of[`
|
|
1931
|
+
%s unique rows remain.`,e.toString(),t.toString()),sticky:!1})}checkSingleRangeSelected(){return this.getters.getSelectedZones().length===1?`Success`:`MoreThanOneRangeSelected`}checkNoMergeInZone(){let e=this.getters.getActiveSheetId(),t=this.getters.getSelectedZone();return this.getters.getMergesInZone(e,t).length>0?`WillRemoveExistingMerge`:`Success`}checkRangeContainsValues(e){let t=this.getters.getActiveSheetId(),n=this.getters.getSelectedZone();return e.hasHeader&&(n.top+=1),this.getters.getEvaluatedCellsInZone(t,n).every(e=>e.type===`empty`)?`EmptyTarget`:`Success`}checkNoColumnProvided(e){return e.columns.length===0?`NoColumnsProvided`:`Success`}checkColumnsIncludedInZone(e){let t=this.getters.getSelectedZone();return e.columns.some(e=>e<t.left||e>t.right)?`ColumnsNotIncludedInZone`:`Success`}checkColumnsAreUnique(e){return e.columns.length===new Set(e.columns).size?`Success`:`DuplicatesColumnsSelected`}trimWhitespace(){let e=ms(this.getters.getSelectedZones()),t=this.getters.getActiveSheetId(),n=0;for(let{col:r,row:i}of e.map(Ks).flat()){let e=this.getters.getCell({col:r,row:i,sheetId:t});if(!e)continue;let a=Xt(e.content);a!==e.content&&(n+=1,this.dispatch(`UPDATE_CELL`,{sheetId:t,col:r,row:i,content:a}))}let r=n?E(`Trimmed whitespace from %s cells.`,n):E(`No selected cells had whitespace trimmed.`);this.ui.notifyUI({type:`info`,text:r,sticky:!1})}},uK=class extends Rp{handle(e){switch(e.type){case`SET_DECIMAL`:this.setDecimal(e.sheetId,e.target,e.step);break;case`SET_FORMATTING_WITH_PIVOT`:this.setContextualFormat(e.sheetId,e.target,e.format);break}}setContextualFormat(e,t,n){let r=[],i={};for(let n of ms(t))for(let t=n.left;t<=n.right;t++)for(let a=n.top;a<=n.bottom;a++){let n={sheetId:e,col:t,row:a},o=this.getters.getPivotCellFromPosition(n);if(this.isSpilledPivotValueFormula(n,o)){r.push(n);let e=this.getters.getPivotIdFromPosition(n)||``;i[e]??=new Set,i[e].add(o.measure)}}let a=ms(r.map(R));for(let e in i){let t=i[e],r=this.getters.getPivotCoreDefinition(e);this.dispatch(`UPDATE_PIVOT`,{pivotId:e,pivot:{...r,measures:r.measures.map(e=>t.has(e.id)?{...e,format:n}:e)}})}this.dispatch(`SET_FORMATTING`,{sheetId:e,target:a,format:``}),this.dispatch(`SET_FORMATTING`,{sheetId:e,target:ms(t,a),format:n})}isSpilledPivotValueFormula(e,t){let n=this.getters.getCell(e);return t.type===`VALUE`&&!n?.isFormula}setDecimal(e,t,n){let r={};for(let i of ms(t))for(let t of Ks(i)){let i=this.getCellNumberFormat({sheetId:e,...t});if(i!==void 0){let e=Jo(i,n);r[e]=r[e]||[],r[e].push(t)}}for(let t in r){let n=ms(r[t].map(e=>R(e)));this.setContextualFormat(e,n,t)}}getCellNumberFormat(e){for(let t of[e]){let e=this.getters.getEvaluatedCell(t);if(e.type===`number`&&!(e.format&&jo(e.format)))return e.format||Fo(e.value)}}},dK=class extends Rp{static getters=[`getGeoJsonFeatures`,`geoFeatureNameToId`,`getGeoChartAvailableRegions`];geoJsonService;geoJsonCache={};constructor(e){super(e),this.geoJsonService=e.external.geoJsonService}getGeoChartAvailableRegions(){return this.geoJsonService?this.geoJsonService.getAvailableRegions()||[]:(console.error(`No geoJsonService provided to the model`),[])}getGeoJsonFeatures(e){if(!this.geoJsonService){console.error(`No geoJsonService provided to the model`);return}let t=this.geoJsonCache[e];if(!(t instanceof Promise)){if(t!==void 0)return t??void 0;this.geoJsonCache[e]=new Promise(async t=>{let n=await this.geoJsonService?.getTopoJson(e);this.geoJsonCache[e]=this.convertToGeoJson(n),this.dispatch(`EVALUATE_CHARTS`),t()})}}geoFeatureNameToId(e,t){if(!this.geoJsonService){console.error(`No geoJsonService provided to the model`);return}return this.geoJsonService.geoFeatureNameToId(e,t)}convertToGeoJson(e){if(!e)return null;if(e.type===`Topology`){let t=window.ChartGeo.topojson.feature(e,Object.values(e.objects)[0]);return t.type===`FeatureCollection`?t.features:[t]}else if(e.type===`FeatureCollection`)return e.features;throw Error(`Invalid TopoJSON`)}},fK=class extends Rp{static getters=[`getNextVisibleCellPosition`,`findVisibleHeader`,`findLastVisibleColRowIndex`,`findFirstVisibleColRowIndex`,`isRowHidden`,`isColHidden`,`isHeaderHidden`];isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,n){return t===`COL`?this.isColHidden(e,n):this.isRowHidden(e,n)}getNextVisibleCellPosition({sheetId:e,col:t,row:n}){return{sheetId:e,col:this.findVisibleHeader(e,`COL`,t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,`ROW`,n,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,n,r){if(n<=r){for(let i=n;i<=r;i++)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}if(n>r){for(let i=n;i>=r;i--)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}}findLastVisibleColRowIndex(e,t,{last:n,first:r}){return S(n,r,-1).find(n=>!this.isHeaderHidden(e,t,n))||r}findFirstVisibleColRowIndex(e,t){let n=this.getters.getNumberHeaders(e,t);for(let r=0;r<n;r++)if(t===`COL`&&!this.isColHidden(e,r)||t===`ROW`&&!this.isRowHidden(e,r))return r}exportForExcel(e){for(let t of e.sheets)for(let[e,n]of Object.entries(t.rows))n.isHidden=this.isRowHidden(t.id,Number(e))}},pK=class extends Rp{static getters=[];allowDispatch(e){switch(e.type){case`DUPLICATE_PIVOT_IN_NEW_SHEET`:if(!this.getters.isExistingPivot(e.pivotId))return`PivotIdNotFound`;if(!this.getters.getPivot(e.pivotId).isValid())return`PivotInError`;break}return`Success`}handle(e){switch(e.type){case`INSERT_NEW_PIVOT`:this.insertNewPivot(e.pivotId,e.newSheetId);break;case`DUPLICATE_PIVOT_IN_NEW_SHEET`:this.duplicatePivotInNewSheet(e.pivotId,e.newPivotId,e.newSheetId);break;case`INSERT_PIVOT_WITH_TABLE`:this.insertPivotWithTable(e.sheetId,e.col,e.row,e.pivotId,e.table,e.pivotMode);break;case`SPLIT_PIVOT_FORMULA`:this.splitPivotFormula(e.sheetId,e.col,e.row,e.pivotId)}}insertNewPivot(e,t){nc(this.getters.getSelectedZone())===1&&this.selection.selectTableAroundSelection();let n=this.getters.getActiveSheetId();this.dispatch(`ADD_PIVOT`,{pivotId:e,pivot:{dataSet:{zone:this.getters.getSelectedZone(),sheetId:n},columns:[],rows:[],measures:[],name:E(`New pivot`),type:`SPREADSHEET`}});let r=this.getters.getSheetIds().findIndex(e=>e===n)+1,i=this.getters.getPivotFormulaId(e);this.dispatch(`CREATE_SHEET`,{sheetId:t,name:E(`Pivot #%(formulaId)s`,{formulaId:i}),position:r}),this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:n,sheetIdTo:t});let a=this.getters.getPivot(e);this.insertPivotWithTable(t,0,0,e,a.getCollapsedTableStructure().export(),`dynamic`)}duplicatePivotInNewSheet(e,t,n){this.dispatch(`DUPLICATE_PIVOT`,{pivotId:e,newPivotId:t,duplicatedPivotName:E(`%s (copy)`,this.getters.getPivotCoreDefinition(e).name)});let r=this.getters.getActiveSheetId(),i=this.getters.getSheetIds().indexOf(r)+1,a=this.getters.getPivotFormulaId(t),o=this.getters.getPivotName(t);if(this.dispatch(`CREATE_SHEET`,{sheetId:n,name:this.getPivotDuplicateSheetName(E(`%(newPivotName)s (Pivot #%(formulaId)s)`,{newPivotName:o,formulaId:a})),position:i}).isSuccessful){this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:r,sheetIdTo:n});let i=this.getters.getPivot(e);this.insertPivotWithTable(n,0,0,t,i.getCollapsedTableStructure().export(),`dynamic`)}}getPivotDuplicateSheetName(e){let t=this.getters.getSheetIds().map(e=>this.getters.getSheetName(e));return an(ht(e),t)}insertPivotWithTable(e,t,n,r,i,a){let{cols:o,rows:s,measures:c,fieldsType:l}=i,u=new nR(o,s,c,l||{}),d=u.columns.length-1;this.resizeSheet(e,t,n,u);let f=this.getters.getPivotFormulaId(r),p;a===`dynamic`?(this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:n,content:`=PIVOT(${f})`}),p={left:t,right:t,top:n,bottom:n}):(this.dispatch(`INSERT_PIVOT`,{sheetId:e,col:t,row:n,pivotId:r,table:u.export()}),p={left:t,right:t+u.getNumberOfDataColumns(),top:n,bottom:n+d+u.rows.length}),this.dispatch(`CREATE_TABLE`,{tableType:a,sheetId:e,ranges:[this.getters.getRangeDataFromZone(e,p)],config:{...tt,numberOfHeaders:d}})}resizeSheet(e,t,n,r){let i=r.getNumberOfDataColumns()+1,a=this.getters.getNumberCols(e),o=a-t;o<i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:a-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:i-o,position:`after`});let s=r.columns.length+r.rows.length,c=this.getters.getNumberRows(e),l=c-n;l<s&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:c-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:s-l,position:`after`})}splitPivotFormula(e,t,n,r){let i=this.getters.getSpreadZone({sheetId:e,col:t,row:n});if(!i)return;let a=this.getters.getPivotFormulaId(r),o=new Map;for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++){let r={sheetId:e,col:t,row:n};o.set(r,this.getters.getPivotCellFromPosition(r))}for(let[e,t]of o)this.dispatch(`UPDATE_CELL`,{...e,content:Md(a,t)});if(this.getters.getCoreTable({sheetId:e,col:t,row:n})?.type===`dynamic`){let r=R({col:t,row:n}),a=this.getters.getRangeDataFromZone(e,i);this.dispatch(`UPDATE_TABLE`,{sheetId:e,zone:r,newTableRange:a,tableType:`static`})}}},mK=class extends Rp{allowDispatch(e){switch(e.type){case`SORT_CELLS`:return Vs(e.col,e.row,e.zone)?this.checkValidations(e,this.checkMerge,this.checkMergeSizes,this.checkArrayFormulaInSortZone):`InvalidSortAnchor`}return`Success`}handle(e){switch(e.type){case`SORT_CELLS`:this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{});break}}checkMerge({sheetId:e,zone:t}){return this.getters.doesIntersectMerge(e,t)&&Ks(t).some(({col:t,row:n})=>!this.getters.isInMerge({sheetId:e,col:t,row:n}))?`InvalidSortZone`:`Success`}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return`Success`;let n=this.getters.getMerges(e).filter(e=>zs(e,t)),r=Us(n[0]),[i,a]=[r.numberOfCols,r.numberOfRows];return n.every(e=>{let[t,n]=[e.right-e.left+1,e.bottom-e.top+1];return t===i&&n===a})?`Success`:`InvalidSortZone`}checkArrayFormulaInSortZone({sheetId:e,zone:t}){return Ks(t).some(({col:t,row:n})=>{let r=this.getters.getArrayFormulaSpreadingOn({sheetId:e,col:t,row:n});return r&&!w(r,{sheetId:e,col:t,row:n})})?`SortZoneWithArrayFormulas`:`Success`}hasHeader(e,t){if(t[0].length===1)return!1;let n=t.map(t=>t.map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}).type));return n[0][0]===`empty`&&(n=n.slice(1)),n.some(e=>e[0]===`empty`)?!1:!!n.some(e=>e[1]!==`empty`&&e[0]!==e[1])}sortZone(e,t,n,r,i){let[a,o]=this.mainCellsSteps(e,n),s=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,c=Object.assign({},n),l=this.mainCells(e,n);!i.sortHeaders&&this.hasHeader(e,l)&&(c.top+=o),l=this.mainCells(e,c);let u=l[s-c.left],d=vv(u.map(e=>this.getters.getEvaluatedCell(e)),r,!!i.emptyCellAsZero).map(e=>e.index),[f,p]=[l.length,l[0].length],m=[];for(let e=0;e<f;e++)for(let t=0;t<p;t++){let{col:n,row:r,sheetId:i}=l[e][d[t]],s=this.getters.getCell({sheetId:i,col:n,row:r}),u=c.left+e*a,f=c.top+t*o,p={sheetId:i,col:u,row:f,content:``};if(s){let e=s.content;if(s.isFormula){let t=this.getters.getCellPosition(s.id);e=this.getters.getTranslatedCellFormula(i,0,f-t.row,s.compiledFormula.tokens)}p.style=s.style,p.content=e,p.format=s.format}m.push(p)}m.forEach(e=>this.dispatch(`UPDATE_CELL`,e))}mainCellsSteps(e,t){let n=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[n?n.right-n.left+1:1,n?n.bottom-n.top+1:1]}mainCells(e,t){let[n,r]=this.mainCellsSteps(e,t),i=[],a=S(t.left,t.right+1,n),o=S(t.top,t.bottom+1,r);for(let t of a){let n=[];i.push(n);for(let r of o)n.push({sheetId:e,col:t,row:r})}return i}},hK=class extends Rp{static getters=[`shouldShowFormulas`];showFormulas=!1;handle(e){switch(e.type){case`SET_FORMULA_VISIBILITY`:this.showFormulas=e.show;break}}shouldShowFormulas(){return this.showFormulas}},gK=class extends Rp{static getters=[`getCellWidth`,`getTextWidth`,`getCellText`,`getCellMultiLineText`,`getContiguousZone`,`computeTextYCoordinate`];ctx=document.createElement(`canvas`).getContext(`2d`);allowDispatch(e){return this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e)}handle(e){switch(e.type){case`AUTORESIZE_COLUMNS`:for(let t of e.cols){let n=this.getColMaxWidth(e.sheetId,t);n!==0&&this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:[t],dimension:`COL`,size:n,sheetId:e.sheetId})}break;case`AUTORESIZE_ROWS`:this.autoResizeRows(e.sheetId,e.rows);break;case`DELETE_UNFILTERED_CONTENT`:let t=[];for(let n of e.target){let r=gt(S(n.top,n.bottom+1).filter(t=>!this.getters.isRowFiltered(e.sheetId,t)));for(let e of r)t.push({...n,top:e[0],bottom:e[e.length-1]})}this.dispatch(`DELETE_CONTENT`,{sheetId:e.sheetId,target:t});break}}getCellWidth(e){let t=this.getters.getCellComputedStyle(e),n=0,r=this.getters.getEvaluatedCell(e).formattedValue;if(r){let e=Cl(this.ctx,r,t,void 0);n+=Math.max(...e.map(e=>ml(this.ctx,e,t)))}for(let t of this.getters.getCellIcons(e))n+=t.margin+t.size;if(this.getters.getDataValidationChipStyle(e)&&(n+=10),n===0)return 0;if(n+=8,t.wrapping===`wrap`){let t=this.getters.getColSize(this.getters.getActiveSheetId(),e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return ml(this.ctx,e,t)}getCellText(e,t){let n=this.getters.getCell(e),r=this.getters.getLocale();if(t?.showFormula&&n?.isFormula)return gu(n.content,r);if(t?.showFormula&&!n?.content)return``;{let i=this.getters.getEvaluatedCell(e),a=t?.availableWidth?{availableWidth:t.availableWidth,measureText:e=>ml(this.ctx,e,n?.style||{})}:void 0;return L(i.value,{format:i.format,locale:r,formatWidth:a})}}getCellMultiLineText(e,t){let n=this.getters.getCellStyle(e),r=this.getters.getCellText(e,{showFormula:this.getters.shouldShowFormulas(),availableWidth:t.formatWidth});return Cl(this.ctx,r,n,t.wrapText?t.maxWidth:void 0)}computeTextYCoordinate(e,t,n=ze,r=1){let i=e.y+1,a=ll(t,r);if(e.height>a+8){if(n===`middle`)return Math.ceil(i+(e.height-a)/2);if(n===`bottom`)return i+e.height-a-4}return i+4}getContiguousZone(e,t){let n=t=>{for(let n of S(t.left,t.right+1)){if(!this.isCellEmpty({sheetId:e,col:n,row:t.top-1}))return{...t,top:t.top-1};if(!this.isCellEmpty({sheetId:e,col:n,row:t.bottom+1}))return{...t,bottom:t.bottom+1}}for(let n of S(t.top,t.bottom+1)){if(!this.isCellEmpty({sheetId:e,col:t.left-1,row:n}))return{...t,left:t.left-1};if(!this.isCellEmpty({sheetId:e,col:t.right+1,row:n}))return{...t,right:t.right+1}}return t},r=!1,i=t;do{r=!1;let e=n(i);Rs(i,e)||(r=!0,i=e)}while(r);return i}isCellEmpty(e){let t=this.getters.getMainCellPosition(e);return this.getters.getEvaluatedCell(t).type===`empty`}getColMaxWidth(e,t){let n=Ks(this.getters.getColsZone(e,t,t)).map(t=>this.getCellWidth({sheetId:e,...t}));return Math.max(0,$t(n))}checkSheetExists(e){return`sheetId`in e&&this.getters.tryGetSheet(e.sheetId)===void 0?`InvalidSheetId`:`Success`}checkZonesAreInSheet(e){let t=`sheetId`in e?e.sheetId:this.getters.tryGetActiveSheetId();if(`ranges`in e&&e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId)))return`InvalidSheetId`;let n=this.getters.getCommandZones(e);return!t&&n.length>0?`NoActiveSheet`:t&&n.length>0?this.getters.checkZonesExistInSheet(t,n):`Success`}autoResizeRows(e,t){let n=[];for(let r of t){let t=0;for(let n of this.getters.getRowCells(e,r)){let r=this.getters.getCellById(n);if(!r)continue;let i=this.getters.getCellPosition(r.id),a=this.getters.getColSize(e,i.col);if(r.isFormula||this.getters.getArrayFormulaSpreadingOn(i)){let e=this.getters.getEvaluatedCell(i).formattedValue,n=dl(this.ctx,e,r?.style,a);n>t&&n>23&&(t=n)}else{let e=r.content,n=dl(this.ctx,e,r?.style,a);n>=t&&n>23&&(t=0)}}n.push(t||null)}let r=new Map(n.map(e=>[e,[]]));for(let e=0;e<n.length;e++)r.get(n[e])?.push(t[e]);for(let[t,n]of r)this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:n,dimension:`ROW`,size:t,sheetId:e})}},_K=class extends Rp{static getters=[`getCellTableStyle`,`getCellTableBorder`];tableStyles={};handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`&&(`content`in e||`format`in e)||e.type===`EVALUATE_CELLS`){this.tableStyles={};return}if(yK(e)){`sheetId`in e?delete this.tableStyles[e.sheetId]:this.tableStyles={};return}}finalize(){for(let e of this.getters.getSheetIds()){this.tableStyles[e]||(this.tableStyles[e]={});for(let t of this.getters.getTables(e))this.tableStyles[e][t.id]||(this.tableStyles[e][t.id]=this.computeTableStyle(e,t))}}getCellTableStyle(e){let t=this.getters.getTable(e);if(t)return this.tableStyles[e.sheetId][t.id]().styles[e.col]?.[e.row]}getCellTableBorder(e){let t=this.getters.getTable(e);if(t)return this.tableStyles[e.sheetId][t.id]().borders[e.col]?.[e.row]}computeTableStyle(e,t){return Nt(()=>{let{config:n,numberOfCols:r,numberOfRows:i}=this.getTableRuntimeConfig(e,t),a=vI(n,this.getters.getTableStyle(t.config.styleId),r,i),o=this.getTableMapping(e,t),s={borders:{},styles:{}};for(let e=0;e<r;e++){let t=o.colMapping[e];s.borders[t]={},s.styles[t]={};for(let n=0;n<i;n++){let r=o.rowMapping[n];s.borders[t][r]=a.borders[e][n],s.styles[t][r]=a.styles[e][n]}}return s})}getTableRuntimeConfig(e,t){let n=t.range.zone,r={...t.config},i=n.right-n.left+1,a=n.bottom-n.top+1;for(let i=n.top;i<=n.bottom;i++)this.getters.isRowHidden(e,i)&&(a--,i-n.top<t.config.numberOfHeaders&&(r.numberOfHeaders--,r.numberOfHeaders<0&&(r.numberOfHeaders=0)),i===n.bottom&&(r.totalRow=!1));for(let t=n.left;t<=n.right;t++)this.getters.isColHidden(e,t)&&(i--,t===n.left&&(r.firstColumn=!1),t===n.right&&(r.lastColumn=!1));return{config:r,numberOfCols:i,numberOfRows:a}}getTableMapping(e,t){let n={},r={},i=0,a=0,o=t.range.zone;for(let t=o.left;t<=o.right;t++)if(!this.getters.isColHidden(e,t)){n[i]=t,i++;for(let t=o.top;t<=o.bottom;t++)this.getters.isRowHidden(e,t)||(r[a]=t,a++)}return{colMapping:n,rowMapping:r}}};let vK=new Set([`HIDE_COLUMNS_ROWS`,`UNHIDE_COLUMNS_ROWS`,`UNFOLD_HEADER_GROUP`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`FOLD_ALL_HEADER_GROUPS`,`UNFOLD_ALL_HEADER_GROUPS`,`FOLD_HEADER_GROUPS_IN_ZONE`,`UNFOLD_HEADER_GROUPS_IN_ZONE`,`CREATE_TABLE`,`UPDATE_TABLE`,`UPDATE_FILTER`,`REMOVE_TABLE`,`RESIZE_TABLE`,`CREATE_TABLE_STYLE`,`REMOVE_TABLE_STYLE`,`DELETE_CONTENT`]);function yK(e){return vK.has(e.type)}var bK=class extends Rp{static getters=[`getCellComputedBorder`,`getCellComputedStyle`];styles=new LF;borders=new LF;handle(e){if(yr.has(e.type)||e.type===`UPDATE_CELL`||e.type===`SET_FORMATTING`||e.type===`CLEAR_FORMATTING`||e.type===`ADD_DATA_VALIDATION_RULE`||e.type===`REMOVE_DATA_VALIDATION_RULE`||e.type===`EVALUATE_CELLS`){this.styles=new LF,this.borders=new LF;return}if(yK(e)){`sheetId`in e?(this.styles.clearSheet(e.sheetId),this.borders.clearSheet(e.sheetId)):(this.styles=new LF,this.borders=new LF);return}if(Sr.has(e.type)){this.styles=new LF;return}if(Cr.has(e.type)){this.borders=new LF;return}}getCellComputedBorder(e){let t=this.borders.get(e);return t===void 0&&(t=this.computeCellBorder(e),this.borders.set(e,t)),t}getCellComputedStyle(e){let t=this.styles.get(e);return t===void 0&&(t=this.computeCellStyle(e),this.styles.set(e,t)),t}computeCellBorder(e){let t=this.getters.getCellBorder(e)||{},n={...zt(this.getters.getCellTableBorder(e)||{}),...zt(t)};return kt(n)?null:n}computeCellStyle(e){let t=this.getters.getCell(e),n=this.getters.getCellConditionalFormatStyle(e),r=this.getters.getCellTableStyle(e),i=this.getters.getDataValidationCellStyle(e),a={...zt(r),...zt(i),...zt(t?.style),...zt(n)};return this.getters.getEvaluatedCell(e).link&&!a.textColor&&(a.textColor=le),a}},xK=class extends Rp{static getters=[`hasBooleanValidationInZones`];handle(e){switch(e.type){case`TOGGLE_CHECKBOX`:this.toggleCheckbox(e.sheetId,e.target);break}}hasBooleanValidationInZones(e){let t=this.getters.getActiveSheetId();for(let n of e)for(let e=n.left;e<=n.right;e++)for(let r=n.top;r<=n.bottom;r++)if(this.getters.isCellValidCheckbox({col:e,row:r,sheetId:t}))return!0;return!1}toggleCheckbox(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++){let n={col:t,row:r,sheetId:e};if(this.getters.isCellValidCheckbox(n)){let e=this.getters.getEvaluatedCell(n).value?`FALSE`:`TRUE`;this.dispatch(`UPDATE_CELL`,{...n,content:e})}}}},SK=class extends Rp{handle(e){switch(e.type){case`ADD_DATA_VALIDATION_RULE`:if(e.rule.criterion.type===`isBoolean`){let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e));for(let e of Vc(t)){let t=this.getters.getCell(e),n=this.getters.getEvaluatedCell(e);if(!t?.content)this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`});else if(t?.content&&n.type===`empty`){let n;if(t.content.startsWith(`=`)){let r=this.getters.evaluateFormula(e.sheetId,t.content);n=(Ir(r)?r[0][0]:r)?.toString()}else n=t.content;(!n||!vt(n))&&this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`})}else n.type!==`boolean`&&this.dispatch(`UPDATE_CELL`,{...e,content:`FALSE`})}}}}},CK=class extends Rp{static getters=[`dynamicTranslate`];dynamicTranslate(e){return e}};let wK=[TK,EK,OK,kK];function TK(e,t){return`sheetId`in t?{...b(t),sheetId:e.getActiveSheetId()}:t}function EK(e,t){return!(`target`in t)||!Array.isArray(t.target)?t:{...b(t),target:e.getSelectedZones()}}function DK(e,t){return`zone`in t?{...b(t),zone:e.getSelectedZone()}:t}function OK(e,t){if(!(`row`in t)||!(`col`in t))return t;let{col:n,row:r}=e.getActivePosition();return{...b(t),col:n,row:r}}function kK(e,t){return`ranges`in t?{...b(t),ranges:e.getSelectedZones().map(t=>e.getRangeDataFromZone(e.getActiveSheetId(),t))}:t}let AK=new jl;function jK(e,t){let n=AK.smallUuid();return{...TK(e,t),figureId:n,chartId:n}}function MK(e,t){return{...TK(e,t),figureId:AK.smallUuid()}}function NK(e,t){let n=OK(e,TK(e,t));return n.figureId=AK.smallUuid(),n}function PK(e,t){let n=b(t);n.sheetId=AK.smallUuid();let r=t.name||e.getSheet(e.getActiveSheetId()).name,i=r.match(/(.+?)\d*$/)?.[1]||r;return n.name=e.getNextSheetName(i),n}function FK(e,t){let n=e.getActivePosition();return{...TK(e,t),base:t.dimension===`COL`?n.col:n.row}}function IK(e,t){let n=e.getSelectedZone();return{...TK(e,t),elements:t.dimension===`COL`?S(n.left,n.right+1):S(n.top,n.bottom+1)}}function LK(e,t){let n=e.getSelectedZone();return{...b(t),zone:n}}function RK(e,t){let n=b(t),{top:r,bottom:i,left:a,right:o}=e.getSelectedZone();return`cols`in n?n.cols=S(a,o+1):`rows`in n&&(n.rows=S(r,i+1)),n}function zK(e,t){let n=e.getSelectedZone();return{...TK(e,t),col:n.left,row:n.top,zone:n}}function BK(e,t){return{type:`REPEAT_PASTE`,pasteOption:b(t.pasteOption),target:e.getSelectedZones()}}function VK(e,t){let n=e.getSelectedZone();return{...TK(e,t),start:t.dimension===`COL`?n.left:n.top,end:t.dimension===`COL`?n.right:n.bottom}}let HK=new g;HK.add(`UPDATE_CELL`,WK),HK.add(`CLEAR_CELL`,WK),HK.add(`CLEAR_CELLS`,WK),HK.add(`DELETE_CONTENT`,WK),HK.add(`ADD_MERGE`,WK),HK.add(`REMOVE_MERGE`,WK),HK.add(`SET_FORMATTING`,WK),HK.add(`CLEAR_FORMATTING`,WK),HK.add(`SET_BORDER`,WK),HK.add(`CREATE_TABLE`,WK),HK.add(`REMOVE_TABLE`,WK),HK.add(`HIDE_SHEET`,WK),HK.add(`ADD_COLUMNS_ROWS`,FK),HK.add(`REMOVE_COLUMNS_ROWS`,IK),HK.add(`HIDE_COLUMNS_ROWS`,IK),HK.add(`RESIZE_COLUMNS_ROWS`,IK),HK.add(`CREATE_SHEET`,PK),HK.add(`CREATE_FIGURE`,NK),HK.add(`CREATE_CHART`,jK),HK.add(`CREATE_IMAGE`,MK),HK.add(`GROUP_HEADERS`,VK),HK.add(`UNGROUP_HEADERS`,VK),HK.add(`UNFOLD_HEADER_GROUPS_IN_ZONE`,DK),HK.add(`FOLD_HEADER_GROUPS_IN_ZONE`,DK);let UK=new g;UK.add(`PASTE`,BK),UK.add(`INSERT_CELL`,LK),UK.add(`DELETE_CELL`,LK),UK.add(`AUTORESIZE_COLUMNS`,RK),UK.add(`AUTORESIZE_ROWS`,RK),UK.add(`SORT_CELLS`,zK),UK.add(`SUM_SELECTION`,WK),UK.add(`SET_DECIMAL`,WK),UK.add(`DELETE_UNFILTERED_CONTENT`,WK);function WK(e,t){let n=b(t);for(let t of wK)n=t(e,n);return n}function GK(e,t){if(t&&HK.contains(t.type))return HK.get(t.type)(e,t)}function KK(e,t,n){if(UK.contains(t.type))return UK.get(t.type)(e,t,n)}function qK(e){return!e||!e.rootCommand||typeof e.rootCommand!=`object`?!1:Dr(e.rootCommand)?HK.contains(e.rootCommand.type):UK.contains(e.rootCommand.type)}function JK(e,t){if(!(!e.rootCommand||typeof e.rootCommand!=`object`))return Dr(e.rootCommand)?GK(t,e.rootCommand):KK(t,e.rootCommand,e.commands)}var YK=class extends Rp{static getters=[`canUndo`,`canRedo`];undoStack=[];redoStack=[];session;constructor(e){super(e),this.session=e.session,this.session.on(`new-local-state-update`,this,this.onNewLocalStateUpdate),this.session.on(`snapshot`,this,()=>{this.undoStack=[],this.redoStack=[]})}allowDispatch(e){switch(e.type){case`REQUEST_UNDO`:if(!this.canUndo())return`EmptyUndoStack`;break;case`REQUEST_REDO`:if(!this.canRedo())return`EmptyRedoStack`;break}return`Success`}handle(e){switch(e.type){case`REQUEST_UNDO`:case`REQUEST_REDO`:this.requestHistoryChange(e.type===`REQUEST_UNDO`?`UNDO`:`REDO`)}}finalize(){}requestHistoryChange(e){let t=e===`UNDO`?this.undoStack.pop():this.redoStack.pop();if(!t){let e=this.getPossibleRevisionToRepeat();if(!e)return;let t=JK(e,this.getters);if(!t)return;if(!Array.isArray(t)){this.dispatch(t.type,t);return}for(let e of t)this.dispatch(e.type,e);return}e===`UNDO`?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0?!0:qK(this.getPossibleRevisionToRepeat())}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}getPossibleRevisionToRepeat(){return this.session.getLastLocalNonEmptyRevision()}},XK=class{trackedValues=new Set;domainToArray(e){return e.flatMap(e=>[e.field,N(e.value)])}isValuePresent(e,t){let n=JSON.stringify({measure:e,domain:this.domainToArray(t)});return this.trackedValues.has(n)}isHeaderPresent(e){let t=JSON.stringify({domain:this.domainToArray(e)});return this.trackedValues.has(t)}trackValue(e,t){let n=JSON.stringify({measure:e,domain:this.domainToArray(t)});this.trackedValues.add(n)}trackHeader(e){let t=JSON.stringify({domain:this.domainToArray(e)});this.trackedValues.add(t)}},ZK=class extends Rp{static getters=[`getPivotPresenceTracker`];trackPresencePivotId;tracker;handle(e){switch(e.type){case`PIVOT_START_PRESENCE_TRACKING`:this.tracker=new XK,this.trackPresencePivotId=e.pivotId;break;case`PIVOT_STOP_PRESENCE_TRACKING`:this.trackPresencePivotId=void 0;break}}getPivotPresenceTracker(e){if(this.trackPresencePivotId===e){if(!this.tracker)throw Error(`Tracker not initialized`);return this.tracker}}},QK=class extends Rp{static getters=[`getAutomaticSeparator`];allowDispatch(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:return this.chainValidations(this.batchValidations(this.checkSingleColSelected,this.checkNonEmptySelector),this.batchValidations(this.checkNotOverwritingContent,this.checkSeparatorInSelection))(e)}return`Success`}handle(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:this.splitIntoColumns(e);break}}getAutomaticSeparator(){let e=this.getters.getSelectedCells();for(let t of e)if(t.value&&t.type===`text`){let e=this.getAutoSeparatorForString(t.value);if(e)return e}return` `}getAutoSeparatorForString(e){for(let t of[`
|
|
1932
1932
|
`,`;`,`,`,` `,`.`])if(e.includes(t))return t}splitIntoColumns({separator:e,addNewColumns:t}){let n=this.getters.getSelectedZone(),r=this.getters.getActiveSheetId(),i=this.getSplittedCols(n,e);t&&this.addColsToAvoidCollisions(n,i),this.removeMergesInSplitZone(n,i),this.addColumnsToNotOverflowSheet(n,i);for(let e=0;e<i.length;e++){let t=n.top+e,a=i[e],o=n.left,s=this.getters.getCell({sheetId:r,col:o,row:t});if(!(a.length===1&&a[0]===s?.content))for(let[e,n]of a.entries())this.dispatch(`UPDATE_CELL`,{sheetId:r,col:o+e,row:t,content:du(n,this.getters.getLocale()),format:``,style:s?.style||null})}}getSplittedCols(e,t){if(!t)throw Error(`Separator cannot be empty`);let n=this.getters.getActiveSheetId(),r=[];for(let i of S(e.top,e.bottom+1)){let a=this.getters.getEvaluatedCell({sheetId:n,col:e.left,row:i}).formattedValue;r.push(this.splitAndRemoveTrailingEmpty(a,t))}return r}splitAndRemoveTrailingEmpty(e,t){let n=e.split(t);for(;n.length>1&&n[n.length-1]===``;)n.pop();return n}willSplittedColsOverwriteContent(e,t){let n=this.getters.getActiveSheetId();for(let r of S(e.top,e.bottom+1)){let i=t[r-e.top];for(let t=1;t<i.length;t++){let i=this.getters.getCell({sheetId:n,col:e.left+t,row:r});if(i&&i.content)return!0}}return!1}removeMergesInSplitZone(e,t){let n=this.getters.getActiveSheetId(),r=Math.max(...t.map(e=>e.length)),i={...e,right:e.left+r-1},a=this.getters.getMergesInZone(n,i);this.dispatch(`REMOVE_MERGE`,{sheetId:n,target:a})}addColsToAvoidCollisions(e,t){let n=this.getters.getActiveSheetId(),r=0;for(let i of S(e.top,e.bottom+1)){let a={sheetId:n,col:e.left,row:i},o=t[i-e.top],s=this.getColsToAddToAvoidCollision(a,o);r=Math.max(r,s)}r&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:e.left,sheetId:n,sheetName:this.getters.getSheetName(n),quantity:r,position:`after`})}getColsToAddToAvoidCollision(e,t){let n=t.length;for(let t=1;t<n;t++){let r=e.col+t,i=this.getters.getCell({...e,col:r});if(i&&i.content)return n-t}return 0}addColumnsToNotOverflowSheet(e,t){let n=this.getters.getActiveSheetId(),r=Math.max(...t.map(e=>e.length-1)),i=this.getters.getNumberCols(n)-1;e.left+r>i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:i,sheetId:n,sheetName:this.getters.getSheetName(n),quantity:e.left+r-i,position:`after`})}checkSingleColSelected(){return this.getters.isSingleColSelected()?`Success`:`MoreThanOneColumnSelected`}checkNonEmptySelector(e){return e.separator===``?`EmptySplitSeparator`:`Success`}checkNotOverwritingContent(e){if(e.addNewColumns||e.force)return`Success`;let t=this.getters.getSelectedZones()[0],n=this.getSplittedCols(t,e.separator);return this.willSplittedColsOverwriteContent(t,n)?`SplitWillOverwriteContent`:`Success`}checkSeparatorInSelection({separator:e}){let t=this.getters.getSelectedCells();for(let n of t)if(n.formattedValue.includes(e))return`Success`;return`NoSplitSeparatorInSelection`}},$K=class extends Rp{handle(e){switch(e.type){case`AUTOFILL_TABLE_COLUMN`:let t=this.getters.getCoreTable(e),n=this.getters.getCell(e);if(!t?.config.automaticAutofill||t.type===`dynamic`||!n?.isFormula)return;let{col:r,row:i}=e,a=mI(t.range.zone,t.config);if(a&&Vs(r,i,a)){let t=e.autofillRowStart??a.top,n=e.autofillRowEnd??a.bottom,r={...a,top:t,bottom:n};this.autofillTableZone(e,r)}break}}autofillTableZone(e,t){if(t.top===t.bottom)return;let{col:n,row:r,sheetId:i}=e;for(let e=t.top;e<=t.bottom;e++)if(e!==r&&this.getters.getEvaluatedCell({col:n,row:e,sheetId:i}).type!==`empty`)return;let a={zone:this.getters.getSelectedZone(),cell:this.getters.getActivePosition()};this.selection.selectCell(n,r),this.dispatch(`AUTOFILL_SELECT`,{col:n,row:t.bottom}),this.dispatch(`AUTOFILL`),this.selection.selectCell(n,r),this.dispatch(`AUTOFILL_SELECT`,{col:n,row:t.top}),this.dispatch(`AUTOFILL`),this.selection.selectZone(a)}},eq=class extends Rp{allowDispatch(e){switch(e.type){case`RESIZE_TABLE`:let t=this.getters.getCoreTableMatchingTopLeft(e.sheetId,e.zone);if(!t)return`TableNotFound`;let n=t.range.zone,r=this.getters.getRangeFromRangeData(e.newTableRange).zone;return r.top!==n.top||r.left!==n.left?`InvalidTableResize`:this.canDispatch(`UPDATE_TABLE`,{...e}).reasons}return`Success`}handle(e){switch(e.type){case`RESIZE_TABLE`:{let t=this.getters.getCoreTableMatchingTopLeft(e.sheetId,e.zone);if(this.dispatch(`UPDATE_TABLE`,{...e}),!t)return;let n=this.getters.getRangeFromRangeData(e.newTableRange).zone;if(this.selection.selectCell(n.right,n.bottom),!t.config.automaticAutofill)return;let r=t.range.zone;if(n.bottom>=r.bottom){for(let t=n.left;t<=n.right;t++){let i={col:t,row:r.bottom,sheetId:e.sheetId};this.getters.getCell(i)?.content.startsWith(`=`)&&this.dispatch(`AUTOFILL_TABLE_COLUMN`,{...i,autofillRowStart:r.bottom,autofillRowEnd:n.bottom})}break}}}}},tq=class extends Rp{static layers=[`Clipboard`];static getters=[`getClipboardTextAndImageContent`,`getClipboardId`,`getClipboardTextContent`,`isCutOperation`];status=`invisible`;originSheetId;copiedData;_isCutOperation=!1;clipboardId=new jl().uuidv4();fileStore;uuidGenerator;constructor(e){super(e),this.fileStore=e.external.fileStore,this.uuidGenerator=new jl}allowDispatch(e){switch(e.type){case`CUT`:let t=this.getters.getSelectedZones();return this.isCutAllowedOn(t);case`PASTE_FROM_OS_CLIPBOARD`:{let t=this.convertTextToClipboardData(e.clipboardContent.text??``),n=e.pasteOption;return this.isPasteAllowed(e.target,t,{pasteOption:n,isCutOperation:!1})}case`PASTE`:{if(!this.copiedData)return`EmptyClipboard`;let t=e.pasteOption;return this.isPasteAllowed(e.target,this.copiedData,{pasteOption:t,isCutOperation:this._isCutOperation})}case`COPY_PASTE_CELLS_ABOVE`:{let e=this.getters.getSelectedZones();if(e.length>1||e[0].top===0&&e[0].bottom===0)return`InvalidCopyPasteSelection`;break}case`COPY_PASTE_CELLS_ON_LEFT`:{let e=this.getters.getSelectedZones();if(e.length>1||e[0].left===0&&e[0].right===0)return`InvalidCopyPasteSelection`;break}case`INSERT_CELL`:{let{cut:t,paste:n}=this.getInsertCellsTargets(e.zone,e.shiftDimension),r=this.copy(t,`shiftCells`);return this.isPasteAllowed(n,r,{isCutOperation:!0})}case`DELETE_CELL`:{let{cut:t,paste:n}=this.getDeleteCellsTargets(e.zone,e.shiftDimension),r=this.copy(t,`shiftCells`);return this.isPasteAllowed(n,r,{isCutOperation:!0})}}return`Success`}handle(e){switch(e.type){case`COPY`:case`CUT`:let t=this.getters.getSelectedZones();this.status=`visible`,this.originSheetId=this.getters.getActiveSheetId(),this._isCutOperation=e.type===`CUT`,this.copiedData=this.copy(t);break;case`PASTE_FROM_OS_CLIPBOARD`:{this._isCutOperation=!1;let t=e.clipboardContent;if(t.data?.version!==bP()&&(t={...t},delete t.data),t.imageData){let n=this.getters.getActiveSheetId(),r=this.uuidGenerator.uuidv4(),i=t.imageData,a=CO(this.getters,i.size);this.dispatch(`CREATE_IMAGE`,{definition:i,size:a,col:e.target[0].left,row:e.target[0].top,offset:{x:0,y:0},sheetId:n,figureId:r})}t.data?this.copiedData=t.data:this.copiedData=this.convertTextToClipboardData(t.text??``);let n=e.pasteOption;this.paste(e.target,this.copiedData,{pasteOption:n,selectTarget:!0,isCutOperation:!1}),this.status=`invisible`,this.copiedData=void 0;break}case`PASTE`:{let t=e.pasteOption;this.paste(e.target,this.copiedData,{pasteOption:t,selectTarget:!0,isCutOperation:this._isCutOperation}),this.status=`invisible`,this._isCutOperation&&=(this.copiedData=void 0,!1);break}case`COPY_PASTE_CELLS_ABOVE`:{let e=this.getters.getSelectedZone(),t=e.top!==e.bottom,n={...e,bottom:t?e.top:e.top-1,top:t?e.top:e.top-1};this.originSheetId=this.getters.getActiveSheetId();let r=this.copy([n]);this.paste([e],r,{isCutOperation:!1,selectTarget:!0})}break;case`COPY_PASTE_CELLS_ON_LEFT`:{let e=this.getters.getSelectedZone(),t=e.left!==e.right,n={...e,right:t?e.left:e.left-1,left:t?e.left:e.left-1};this.originSheetId=this.getters.getActiveSheetId();let r=this.copy([n]);this.paste([e],r,{isCutOperation:!1,selectTarget:!0})}break;case`CLEAN_CLIPBOARD_HIGHLIGHT`:this.status=`invisible`;break;case`DELETE_CELL`:{let{cut:t,paste:n}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Os(t[0])){this.dispatch(`CLEAR_CELLS`,{target:[e.zone],sheetId:this.getters.getActiveSheetId()});break}let r=this.copy(t,`shiftCells`);this.paste(n,r,{isCutOperation:!0});break}case`INSERT_CELL`:{let{cut:t,paste:n}=this.getInsertCellsTargets(e.zone,e.shiftDimension),r=this.copy(t,`shiftCells`);this.paste(n,r,{isCutOperation:!0});break}case`ADD_COLUMNS_ROWS`:if(this.status=`invisible`,!this._isCutOperation||e.sheetId!==this.copiedData?.sheetId)return;this.isColRowDirtyingClipboard(e.position===`before`?e.base:e.base+1,e.dimension)&&(this.copiedData=void 0);break;case`REMOVE_COLUMNS_ROWS`:if(this.status=`invisible`,!this._isCutOperation||e.sheetId!==this.copiedData?.sheetId)return;for(let t of e.elements)if(this.isColRowDirtyingClipboard(t,e.dimension)){this.copiedData=void 0;break}this.status=`invisible`;break;case`REPEAT_PASTE`:this.paste(e.target,this.copiedData,{isCutOperation:!1,pasteOption:e.pasteOption,selectTarget:!0});break;case`DELETE_SHEET`:if(!this._isCutOperation)return;this.originSheetId===e.sheetId&&(this.copiedData=void 0,this.status=`invisible`);break;default:Dr(e)&&(this.status=`invisible`)}}convertTextToClipboardData(e){let t=this.selectClipboardHandlers({figureId:!0}).concat(this.selectClipboardHandlers({})),n={};for(let{handlerName:r,handler:i}of t){let t=i.convertTextToClipboardData(e);n[r]=t;for(let e of[`sheetId`,`cells`,`zones`,`figureId`])t&&e in t&&(n[e]=t[e])}return n}selectClipboardHandlers(e){let t=`figureId`in e?af.figureHandlers:af.cellHandlers;return t.getKeys().map(e=>({handlerName:e,handler:new(t.get(e))(this.getters,this.dispatch)}))}isCutAllowedOn(e){let t=this.getClipboardData(e);for(let{handler:e}of this.selectClipboardHandlers(t)){let n=e.isCutAllowed(t);if(n!==`Success`)return n}return`Success`}isPasteAllowed(e,t,n){for(let{handler:r}of this.selectClipboardHandlers(t)){let i=r.isPasteAllowed(this.getters.getActiveSheetId(),e,t,{...n});if(i!==`Success`)return i}return`Success`}isColRowDirtyingClipboard(e,t){if(!this.copiedData||!this.copiedData.zones)return!1;let{zones:n}=this.copiedData;for(let r of n)if(t===`COL`&&e<=r.right||t===`ROW`&&e<=r.bottom)return!0;return!1}copy(e,t=`copyPaste`){let n={},r=this.getClipboardData(e);for(let{handlerName:e,handler:i}of this.selectClipboardHandlers(r)){let a=i.copy(r,this._isCutOperation,t);n[e]=a;for(let e of[`sheetId`,`cells`,`zones`,`figureId`])a&&e in a&&(n[e]=a[e])}return n}paste(e,t,n){if(!t)return;let r=this.getters.getActiveSheetId(),i=this.selectClipboardHandlers(t),{target:a,zone:o,selectedZones:s}=zl(r,e,t,i,n);o!==void 0&&this.addMissingDimensions(r,o.right-o.left+1,o.bottom-o.top+1,o.left,o.top),Rl(i,t,a,n),n?.selectTarget&&Bl(this.selection,e,s)}addMissingDimensions(e,t,n,r,i){let a=n+i-this.getters.getNumberRows(e);a>0&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:this.getters.getNumberRows(e)-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:a,position:`after`});let o=t+r-this.getters.getNumberCols(e);o>0&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:this.getters.getNumberCols(e)-1,sheetId:e,sheetName:this.getters.getSheetName(e),quantity:o,position:`after`})}getClipboardTextContent(){return this.getPlainTextContent()}getClipboardId(){return this.clipboardId}async getClipboardTextAndImageContent(){let e=await this.getImageContent(),t=e?.type,n={"text/plain":this.getPlainTextContent(),"text/html":await this.getHTMLContent()};return t&&e&&(n[t]=e),n}getSheetData(){let e={version:bP(),clipboardId:this.clipboardId};return this.copiedData&&`figureId`in this.copiedData?e:{...e,...this.copiedData}}getPlainTextContent(){return this.copiedData?.cells&&this.copiedData.cells.map(e=>e.map(e=>this.getters.shouldShowFormulas()&&e?.tokens?.length?e?.content||``:e.evaluatedCell?.formattedValue||``).join(` `)).join(`
|
|
1933
1933
|
`)||` `}async getHTMLContent(){let e=``,t=this.copiedData?.cells;if(!t)if(this.copiedData?.figureId){let t=this.copiedData.figureId,n=this.getters.getFigureSheetId(t);e=this.getters.getFigure(n,t).tag===`image`?await this.craftImageHTML(t):` `}else e=` `;else if(t.length===1&&t[0].length===1)e=`${this.getters.getCellText(t[0][0].position)}`;else if(t[0][0]){let n=`<table border="1" style="border-collapse:collapse">`;for(let e of t){n+=`<tr>`;for(let t of e){if(!t)continue;let e=V(kf(this.getters.getCellComputedStyle(t.position))),r=this.getters.getCellText(t.position);n+=`<td style="${e}">`+DO(r)+`</td>`}n+=`</tr>`}n+=`</table>`,e=n}else return``;return`<div data-osheet-clipboard='${DO(JSON.stringify(this.getSheetData()))}'>${e}</div>`}readFileAsDataURL(e){return new Promise(t=>{let n=new FileReader;n.onload=()=>t(n.result),n.readAsDataURL(e)})}async craftImageHTML(e){if(!this.fileStore)return` `;let t=this.getters.getImage(e).path,n=await this.fileStore?.getFile(t)||null;return n?`<img src="${DO(await this.readFileAsDataURL(n))}" />`:` `}async getImageContent(){let e=this.copiedData?.figureId;if(!e)return;let t=this.getters.getFigureSheetId(e),n=this.getters.getFigure(t,e),r;if(n.tag===`image`){if(!this.fileStore)return;let t=this.getters.getImage(e).path;if(r=await this.fileStore?.getFile(t),r.type!==`image/png`){if(r.size>5242880){this.ui.notifyUI({text:E(`The file you are trying to copy is too large (>%sMB).
|
|
1934
1934
|
It will not be added to your OS clipboard.
|
|
@@ -2670,20 +2670,20 @@ You can download it directly instead.`,5),sticky:!1,type:`warning`});return}r=aw
|
|
|
2670
2670
|
${XJ(e.color)}
|
|
2671
2671
|
${n}
|
|
2672
2672
|
</a:ln>
|
|
2673
|
-
`}function QJ(e,t=`000000`,n=16,r={}){return J`
|
|
2673
|
+
`}function QJ(e,t=`000000`,n=16,r={}){let i=[[`b`,r.bold?`1`:`0`],[`i`,r.italic?`1`:`0`],[`sz`,n*100]];return J`
|
|
2674
2674
|
<c:tx>
|
|
2675
2675
|
<c:rich>
|
|
2676
2676
|
<a:bodyPr />
|
|
2677
2677
|
<a:lstStyle />
|
|
2678
2678
|
<a:p>
|
|
2679
2679
|
<a:pPr lvl="0">
|
|
2680
|
-
<a:defRPr
|
|
2680
|
+
<a:defRPr ${K(i)}>
|
|
2681
2681
|
${XJ(t)}
|
|
2682
2682
|
<a:latin typeface="+mn-lt"/>
|
|
2683
2683
|
</a:defRPr>
|
|
2684
2684
|
</a:pPr>
|
|
2685
2685
|
<a:r> <!-- Runs -->
|
|
2686
|
-
<a:rPr
|
|
2686
|
+
<a:rPr ${K(i)}/>
|
|
2687
2687
|
<a:t>${e}</a:t>
|
|
2688
2688
|
</a:r>
|
|
2689
2689
|
</a:p>
|
|
@@ -3446,4 +3446,4 @@ You can download it directly instead.`,5),sticky:!1,type:`warning`});return}r=aw
|
|
|
3446
3446
|
<Relationships xmlns="${Uf.Relationships}">
|
|
3447
3447
|
<Relationship ${K(e)} />
|
|
3448
3448
|
</Relationships>
|
|
3449
|
-
`),`_rels/.rels`)}function DX(e){let t={},n=[];for(let r of e.sheets){let e=r.name.slice(0,31);e=an(e,n,{compute:(e,t)=>e.slice(0,31-String(t).length)+t}),n.push(e),e!==r.name&&(t[r.name]=e,r.name=e)}if(!Object.keys(t).length)return e;let r=Object.keys(t).sort((e,t)=>t.length-e.length),i=JSON.stringify(e);for(let e of r){let n=RegExp(`'?${ut(e)}'?!`,`g`);i=i.replaceAll(n,n=>{let r=t[e];return n.replace(e,r)})}return JSON.parse(i)}function OX(e){for(let t of e.sheets)t.tables=t.tables.filter(e=>Us(Ts(e.range)).numberOfRows>1);return e}var kX=class extends cf{corePlugins=[];statefulUIPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;coreViewPluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},n={},r=[],i=new jl,a=!1){let o=performance.now();console.debug(`##### Model creation #####`),super(),dr(),r=jP(e,r);let s=CP(e,a);this.state=new UJ,this.uuidGenerator=i,this.config=this.setupConfig(n),this.session=this.setupSession(s.revisionId),this.coreGetters={},this.range=new fW(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeData=this.range.getRangeData.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.coreGetters.copyFormulaStringForSheet=this.range.copyFormulaStringForSheet.bind(this.range),this.getters={isReadonly:()=>this.config.mode===`readonly`||this.config.mode===`dashboard`,isDashboard:()=>this.config.mode===`dashboard`},this.selection=new VJ(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.coreViewPluginConfig=this.setupCoreViewPluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of lq.getAll())this.setupCorePlugin(e,s);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(r);for(let e of fq.getAll()){let t=this.setupCoreViewPlugin(e);this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of dq.getAll()){let t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of uq.getAll()){let t=this.setupUiPlugin(e);this.handlers.push(t),this.uiHandlers.push(t)}if(this.dispatch(`START`),this.selection.observe(this,{handleEvent:()=>this.trigger(`update`)}),this.setupSessionEvents(),this.joinSession(),n.snapshotRequested||e[`[Content_Types].xml`]&&!this.getters.isReadonly()){let e=performance.now();console.debug(`Snapshot requested`),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.debug(`Snapshot taken in`,performance.now()-e,`ms`)}(0,t.markRaw)(this),console.debug(`Model created in`,performance.now()-o,`ms`),console.debug(`######`)}joinSession(){this.session.join(this.config.client)}async leaveSession(){let e=this.getters.isReadonly()?void 0:Nt(()=>this.exportData());await this.session.leave(e)}setupUiPlugin(e){let t=new e(this.uiPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}for(let n of e.layers)this.renderers[n]||(this.renderers[n]=[]),this.renderers[n].push(t);return t}setupCoreViewPlugin(e){let t=new e(this.coreViewPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}return t}setupCorePlugin(e,t){let n=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in n))throw Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);if(t in this.coreGetters)throw Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=n[t].bind(n)}n.import(t),this.corePlugins.push(n),this.coreHandlers.push(n),this.handlers.push(n)}onRemoteRevisionReceived({commands:e}){for(let t of e){let e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new sK(LJ({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{if(!this.checkDispatchAllowed(e).isSuccessful){this.dispatchToHandlers(this.coreHandlers,{type:`UNDO`,commands:[e]});return}this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1}}),this.config.transportService,e)}setupSessionEvents(){this.session.on(`remote-revision-received`,this,this.onRemoteRevisionReceived),this.session.on(`revision-undone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`UNDO`,{commands:e}),this.finalize()}),this.session.on(`revision-redone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`REDO`,{commands:e}),this.finalize()}),this.session.on(`unexpected-revision-id`,this,()=>this.trigger(`unexpected-revision-id`)),this.session.on(`collaborative-event-received`,this,()=>{this.trigger(`update`)})}setupConfig(e){let t=e.client||{id:this.uuidGenerator.smallUuid(),name:E(`Anonymous`).toString()},n=e.transportService||new Uq,r=e.mode===`readonly`||e.mode===`dashboard`;return{...e,mode:e.mode||`normal`,custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:r?new kJ(n):n,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger(`notify-ui`,e),raiseBlockingErrorUI:e=>this.trigger(`raise-error-ui`,{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){let t=e.loadLocales||(()=>Promise.resolve(Pr));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,custom:this.config.custom,external:this.config.external}}setupCoreViewPluginConfig(){return{getters:this.getters,stateObserver:this.state,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}checkDispatchAllowed(e){let t=Dr(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some(e=>e!==`Success`)?new kr(t.flat()):kr.Success}checkDispatchAllowedCoreCommand(e){let t=this.corePlugins.map(t=>t.allowDispatch(e));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map(t=>t.allowDispatch(e))}finalize(){this.status=3;for(let e of this.handlers)e.finalize();this.status=0,this.trigger(`command-finalized`)}canDispatch=(e,t)=>this.checkDispatchAllowed(AX(e,t));dispatch=(e,t)=>{let n=AX(e,t),r=this.status;if(this.getters.isReadonly()&&!Or(n))return new kr(`Readonly`);if(!this.session.canApplyOptimisticUpdate())return new kr(`WaitingSessionConfirmation`);switch(r){case 0:let t=this.checkDispatchAllowed(n);if(!t.isSuccessful)return this.trigger(`update`),t;this.status=1;let{changes:r,commands:i}=this.state.recordChanges(()=>{let t=performance.now();Dr(n)&&this.state.addCommand(n),this.dispatchToHandlers(this.handlers,n),this.finalize();let r=performance.now()-t;r>5&&console.debug(e,r,`ms`)});this.session.save(n,i,r),this.status=0,this.trigger(`update`);break;case 1:if(Dr(n)){let e=this.checkDispatchAllowed(n);if(!e.isSuccessful)return e;this.state.addCommand(n)}this.dispatchToHandlers(this.handlers,n);break;case 3:throw Error(`Cannot dispatch commands in the finalize state`);case 2:if(Dr(n))throw Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,n)}return kr.Success};dispatchFromCorePlugin=(e,t)=>{let n=AX(e,t),r=this.status;this.status=2;let i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,n),this.status=r,kr.Success};dispatchToHandlers(e,t){let n=Dr(t);for(let r of e)!n&&r instanceof XU||r.beforeHandle(t);for(let r of e)!n&&r instanceof XU||r.handle(t);this.trigger(`command-dispatched`,t)}drawLayer(e,t){let n=this.renderers[t];if(n)for(let r of n)e.ctx.save(),r.drawLayer(e,t),e.ctx.restore()}exportData(){let e=RP();for(let t of this.handlers)t instanceof XU&&t.export(e);return e.revisionId=this.session.getRevisionId()||`START_REVISION`,e=b(e),e}updateMode(e){this.config.mode=e,this.trigger(`update`)}exportXLSX(){this.dispatch(`EVALUATE_CELLS`);let e=BP();for(let t of this.handlers)t instanceof Lp&&t.exportForExcel(e);return e=b(e),vX(e)}garbageCollectExternalResources(){for(let e of this.corePlugins)e.garbageCollectExternalResources()}};function AX(e,t={}){let n=b(t);return n.type=e,n}let jX={},MX={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:26,HEADER_WIDTH:48,DESKTOP_BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:96,DEFAULT_CELL_HEIGHT:23,SCROLLBAR_WIDTH:15},NX={autoCompleteProviders:up,autofillModifiersRegistry:uG,autofillRulesRegistry:dG,cellMenuRegistry:zR,colMenuRegistry:rB,errorTypes:Ki,linkMenuRegistry:LA,functionRegistry:zS,featurePluginRegistry:uq,iconsOnCellRegistry:eG,statefulUIPluginRegistry:dq,coreViewsPluginRegistry:fq,corePluginRegistry:lq,rowMenuRegistry:uB,sidePanelRegistry:zU,figureRegistry:pk,chartSidePanelComponentRegistry:EH,chartComponentRegistry:pO,chartRegistry:fO,chartSubtypeRegistry:hO,topbarMenuRegistry:Vq,topbarComponentRegistry:Hq,clickableCellRegistry:_q,otRegistry:TG,inverseCommandRegistry:bq,urlRegistry:Wr,cellPopoverRegistry:gk,numberFormatMenuRegistry:Iq,repeatLocalCommandTransformRegistry:UK,repeatCommandTransformRegistry:HK,clipboardHandlersRegistries:af,pivotRegistry:vR,pivotTimeAdapterRegistry:od,pivotSidePanelRegistry:bU,pivotNormalizationValueRegistry:Ld,supportedPivotPositionalFormulaRegistry:KU,pivotToFunctionValueRegistry:Rd,migrationStepRegistry:vP,chartJsExtensionRegistry:Mf},PX={arg:H,isEvaluationError:j,toBoolean:P,toJsDate:F,toNumber:M,toString:N,toNormalizedPivotValue:Nd,toFunctionPivotValue:Fd,toXC:T,toZone:Ts,toUnboundedZone:ws,toCartesian:ir,numberToLetters:Yn,lettersToNumber:Xn,UuidGenerator:jl,formatValue:L,createCurrencyFormat:Ro,ColorGenerator:Un,computeTextWidth:ml,createEmptyWorkbookData:RP,createEmptySheet:LP,createEmptyExcelSheet:zP,rgbaToHex:bn,colorToRGBA:xn,positionToZone:R,isDefined:C,isMatrix:Ir,lazy:Nt,genericRepeat:WK,createAction:m,createActions:f,transformRangeData:sf,deepEquals:w,overlap:zs,union:Fs,isInside:Vs,deepCopy:b,expandZoneOnInsertion:js,reduceZoneOnDeletion:Ps,unquote:pt,getMaxObjectId:Td,getFunctionsFromTokens:fC,getFirstPivotFunction:hU,getNumberOfPivotFunctions:_U,parseDimension:Od,isDateOrDatetimeField:kd,makeFieldProposal:uU,insertTokenAfterArgSeparator:fU,insertTokenAfterLeftParenthesis:pU,mergeContiguousZones:dc,getPivotHighlights:YH,pivotTimeAdapter:sd,UNDO_REDO_PIVOT_COMMANDS:sG,createPivotFormula:Md,areDomainArgsFieldsValid:jd,splitReference:jc,sanitizeSheetName:ht,getUniqueText:an,isNumber:Hi,isDateTime:ui,createCustomFields:Wd},FX={isMarkdownLink:xt,parseMarkdownLink:wt,markdownLink:Ct,openLink:Yr,urlRepresentation:Jr},IX={Checkbox:bA,Section:X,RoundColorPicker:aA,ChartDataSeries:IV,ChartErrorSection:LV,ChartLabelRange:RV,ChartTitle:HV,ChartPanel:kH,ChartFigure:dk,ChartJsComponent:Ew,ClickableCellSortIcon:qU,ZoomableChartJsComponent:TD,Grid:GU,GridOverlay:oV,ScorecardChart:Uw,GaugeChartComponent:jD,LineConfigPanel:dH,BarConfigPanel:BV,PieChartDesignPanel:mH,GenericChartConfigPanel:zV,ChartWithAxisDesignPanel:ZV,GenericZoomableChartDesignPanel:QV,LineChartDesignPanel:fH,GaugeChartConfigPanel:iH,GaugeChartDesignPanel:aH,ScorecardChartConfigPanel:_H,ScorecardChartDesignPanel:vH,GeoChartDesignPanel:lH,RadarChartDesignPanel:hH,WaterfallChartDesignPanel:TH,ComboChartDesignPanel:tH,FunnelChartDesignPanel:rH,SunburstChartDesignPanel:yH,TreeMapChartDesignPanel:wH,ChartTypePicker:DH,FigureComponent:mk,MenuPopover:ck,Popover:ik,SelectionInput:mA,ValidationMessages:ZB,AddDimensionButton:eU,PivotDimensionGranularity:nU,PivotDimensionOrder:rU,PivotDimension:tU,PivotLayoutConfigurator:sU,PivotHTMLRenderer:YU,PivotDeferUpdate:ZH,PivotTitleSection:cU,CogWheelMenu:PV,TextInput:kV,SidePanelCollapsible:bk,RadioSelection:WV,GeoChartRegionSelectSection:oH,ChartDashboardMenu:lk,FullScreenFigure:JU},LX={useDragAndDropListItems:sA,useHighlights:MH,useHighlightsOnHover:jH},RX={useStoreProvider:pf,DependencyContainer:lf,CellPopoverStore:TA,ComposerFocusStore:Sf,CellComposerStore:RB,FindAndReplaceStore:UH,HighlightStore:Kk,DelayedHoveredCellStore:hk,HoveredTableStore:rV,ModelStore:vf,NotificationStore:qk,RendererStore:yf,SelectionInputStore:pA,SpreadsheetStore:bf,useStore:z,useLocalStore:mf,SidePanelStore:VU,PivotSidePanelStore:vU,PivotMeasureDisplayPanelStore:qH,ClientFocusStore:fB,GridRenderer:mV};function zX(e,t){return zS.add(e,t),{addFunction:(e,t)=>zX(e,t)}}let BX={DEFAULT_LOCALE:D,HIGHLIGHT_COLOR:v,PIVOT_TABLE_CONFIG:tt,ChartTerms:Ub,FIGURE_ID_SPLITTER:`??`,GRID_ICON_EDGE_LENGTH:17,GRID_ICON_MARGIN:2},VX={...xO,...vD};e.AbstractCellClipboardHandler=Hl,e.AbstractChart=Dw,e.AbstractFigureClipboardHandler=Wl,e.CellErrorType=k,e.ClientDisconnectedError=oK,e.CommandResult=jr,e.CorePlugin=XU,e.CoreViewPlugin=xW,e.DispatchResult=kr,e.EvaluationError=A,e.LocalTransportService=Uq,e.Model=kX,e.PivotRuntimeDefinition=eR,e.Registry=g,e.Revision=aK,e.SPREADSHEET_DIMENSIONS=MX,e.Spreadsheet=OJ,e.SpreadsheetPivotTable=nR,e.UIPlugin=Rp,e.__info__=jX,e.addFunction=zX,e.addRenderingLayer=zr,e.astToFormula=PB,e.chartHelpers=VX,e.compile=rC,e.compileTokens=iC,e.components=IX,e.constants=BX,e.convertAstNodes=$y,e.coreTypes=Er,e.findCellInNewZone=Qs,e.functionCache=nC,e.getCaretDownSvg=Tj,e.getCaretUpSvg=Ej,e.helpers=PX,e.hooks=LX,e.invalidateCFEvaluationCommands=Sr,e.invalidateChartEvaluationCommands=br,e.invalidateDependenciesCommands=xr,e.invalidateEvaluationCommands=yr,e.iterateAstNodes=eb,e.links=FX,e.load=CP,e.parse=Zy,e.parseTokens=Qy,e.readonlyAllowedCommands=Tr,e.registries=NX,e.setDefaultSheetViewSize=$e,e.setTranslationMethod=ur,e.stores=RX,e.tokenColors=ot,e.tokenize=Jl,jX.version=`19.0.36`,jX.date=`2026-05-27T05:57:35.932Z`,jX.hash=`3f73c94`})(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|
|
3449
|
+
`),`_rels/.rels`)}function DX(e){let t={},n=[];for(let r of e.sheets){let e=r.name.slice(0,31);e=an(e,n,{compute:(e,t)=>e.slice(0,31-String(t).length)+t}),n.push(e),e!==r.name&&(t[r.name]=e,r.name=e)}if(!Object.keys(t).length)return e;let r=Object.keys(t).sort((e,t)=>t.length-e.length),i=JSON.stringify(e);for(let e of r){let n=RegExp(`'?${ut(e)}'?!`,`g`);i=i.replaceAll(n,n=>{let r=t[e];return n.replace(e,r)})}return JSON.parse(i)}function OX(e){for(let t of e.sheets)t.tables=t.tables.filter(e=>Us(Ts(e.range)).numberOfRows>1);return e}var kX=class extends cf{corePlugins=[];statefulUIPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;coreViewPluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},n={},r=[],i=new jl,a=!1){let o=performance.now();console.debug(`##### Model creation #####`),super(),dr(),r=jP(e,r);let s=CP(e,a);this.state=new UJ,this.uuidGenerator=i,this.config=this.setupConfig(n),this.session=this.setupSession(s.revisionId),this.coreGetters={},this.range=new fW(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeData=this.range.getRangeData.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.coreGetters.copyFormulaStringForSheet=this.range.copyFormulaStringForSheet.bind(this.range),this.getters={isReadonly:()=>this.config.mode===`readonly`||this.config.mode===`dashboard`,isDashboard:()=>this.config.mode===`dashboard`},this.selection=new VJ(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.coreViewPluginConfig=this.setupCoreViewPluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of lq.getAll())this.setupCorePlugin(e,s);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(r);for(let e of fq.getAll()){let t=this.setupCoreViewPlugin(e);this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of dq.getAll()){let t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of uq.getAll()){let t=this.setupUiPlugin(e);this.handlers.push(t),this.uiHandlers.push(t)}if(this.dispatch(`START`),this.selection.observe(this,{handleEvent:()=>this.trigger(`update`)}),this.setupSessionEvents(),this.joinSession(),n.snapshotRequested||e[`[Content_Types].xml`]&&!this.getters.isReadonly()){let e=performance.now();console.debug(`Snapshot requested`),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.debug(`Snapshot taken in`,performance.now()-e,`ms`)}(0,t.markRaw)(this),console.debug(`Model created in`,performance.now()-o,`ms`),console.debug(`######`)}joinSession(){this.session.join(this.config.client)}async leaveSession(){let e=this.getters.isReadonly()?void 0:Nt(()=>this.exportData());await this.session.leave(e)}setupUiPlugin(e){let t=new e(this.uiPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}for(let n of e.layers)this.renderers[n]||(this.renderers[n]=[]),this.renderers[n].push(t);return t}setupCoreViewPlugin(e){let t=new e(this.coreViewPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}return t}setupCorePlugin(e,t){let n=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in n))throw Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);if(t in this.coreGetters)throw Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=n[t].bind(n)}n.import(t),this.corePlugins.push(n),this.coreHandlers.push(n),this.handlers.push(n)}onRemoteRevisionReceived({commands:e}){for(let t of e){let e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new sK(LJ({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{if(!this.checkDispatchAllowed(e).isSuccessful){this.dispatchToHandlers(this.coreHandlers,{type:`UNDO`,commands:[e]});return}this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1}}),this.config.transportService,e)}setupSessionEvents(){this.session.on(`remote-revision-received`,this,this.onRemoteRevisionReceived),this.session.on(`revision-undone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`UNDO`,{commands:e}),this.finalize()}),this.session.on(`revision-redone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`REDO`,{commands:e}),this.finalize()}),this.session.on(`unexpected-revision-id`,this,()=>this.trigger(`unexpected-revision-id`)),this.session.on(`collaborative-event-received`,this,()=>{this.trigger(`update`)})}setupConfig(e){let t=e.client||{id:this.uuidGenerator.smallUuid(),name:E(`Anonymous`).toString()},n=e.transportService||new Uq,r=e.mode===`readonly`||e.mode===`dashboard`;return{...e,mode:e.mode||`normal`,custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:r?new kJ(n):n,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger(`notify-ui`,e),raiseBlockingErrorUI:e=>this.trigger(`raise-error-ui`,{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){let t=e.loadLocales||(()=>Promise.resolve(Pr));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,custom:this.config.custom,external:this.config.external}}setupCoreViewPluginConfig(){return{getters:this.getters,stateObserver:this.state,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}checkDispatchAllowed(e){let t=Dr(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some(e=>e!==`Success`)?new kr(t.flat()):kr.Success}checkDispatchAllowedCoreCommand(e){let t=this.corePlugins.map(t=>t.allowDispatch(e));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map(t=>t.allowDispatch(e))}finalize(){this.status=3;for(let e of this.handlers)e.finalize();this.status=0,this.trigger(`command-finalized`)}canDispatch=(e,t)=>this.checkDispatchAllowed(AX(e,t));dispatch=(e,t)=>{let n=AX(e,t),r=this.status;if(this.getters.isReadonly()&&!Or(n))return new kr(`Readonly`);if(!this.session.canApplyOptimisticUpdate())return new kr(`WaitingSessionConfirmation`);switch(r){case 0:let t=this.checkDispatchAllowed(n);if(!t.isSuccessful)return this.trigger(`update`),t;this.status=1;let{changes:r,commands:i}=this.state.recordChanges(()=>{let t=performance.now();Dr(n)&&this.state.addCommand(n),this.dispatchToHandlers(this.handlers,n),this.finalize();let r=performance.now()-t;r>5&&console.debug(e,r,`ms`)});this.session.save(n,i,r),this.status=0,this.trigger(`update`);break;case 1:if(Dr(n)){let e=this.checkDispatchAllowed(n);if(!e.isSuccessful)return e;this.state.addCommand(n)}this.dispatchToHandlers(this.handlers,n);break;case 3:throw Error(`Cannot dispatch commands in the finalize state`);case 2:if(Dr(n))throw Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,n)}return kr.Success};dispatchFromCorePlugin=(e,t)=>{let n=AX(e,t),r=this.status;this.status=2;let i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,n),this.status=r,kr.Success};dispatchToHandlers(e,t){let n=Dr(t);for(let r of e)!n&&r instanceof XU||r.beforeHandle(t);for(let r of e)!n&&r instanceof XU||r.handle(t);this.trigger(`command-dispatched`,t)}drawLayer(e,t){let n=this.renderers[t];if(n)for(let r of n)e.ctx.save(),r.drawLayer(e,t),e.ctx.restore()}exportData(){let e=RP();for(let t of this.handlers)t instanceof XU&&t.export(e);return e.revisionId=this.session.getRevisionId()||`START_REVISION`,e=b(e),e}updateMode(e){this.config.mode=e,this.trigger(`update`)}exportXLSX(){this.dispatch(`EVALUATE_CELLS`);let e=BP();for(let t of this.handlers)t instanceof Lp&&t.exportForExcel(e);return e=b(e),vX(e)}garbageCollectExternalResources(){for(let e of this.corePlugins)e.garbageCollectExternalResources()}};function AX(e,t={}){let n=b(t);return n.type=e,n}let jX={},MX={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:26,HEADER_WIDTH:48,DESKTOP_BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:96,DEFAULT_CELL_HEIGHT:23,SCROLLBAR_WIDTH:15},NX={autoCompleteProviders:up,autofillModifiersRegistry:uG,autofillRulesRegistry:dG,cellMenuRegistry:zR,colMenuRegistry:rB,errorTypes:Ki,linkMenuRegistry:LA,functionRegistry:zS,featurePluginRegistry:uq,iconsOnCellRegistry:eG,statefulUIPluginRegistry:dq,coreViewsPluginRegistry:fq,corePluginRegistry:lq,rowMenuRegistry:uB,sidePanelRegistry:zU,figureRegistry:pk,chartSidePanelComponentRegistry:EH,chartComponentRegistry:pO,chartRegistry:fO,chartSubtypeRegistry:hO,topbarMenuRegistry:Vq,topbarComponentRegistry:Hq,clickableCellRegistry:_q,otRegistry:TG,inverseCommandRegistry:bq,urlRegistry:Wr,cellPopoverRegistry:gk,numberFormatMenuRegistry:Iq,repeatLocalCommandTransformRegistry:UK,repeatCommandTransformRegistry:HK,clipboardHandlersRegistries:af,pivotRegistry:vR,pivotTimeAdapterRegistry:od,pivotSidePanelRegistry:bU,pivotNormalizationValueRegistry:Ld,supportedPivotPositionalFormulaRegistry:KU,pivotToFunctionValueRegistry:Rd,migrationStepRegistry:vP,chartJsExtensionRegistry:Mf},PX={arg:H,isEvaluationError:j,toBoolean:P,toJsDate:F,toNumber:M,toString:N,toNormalizedPivotValue:Nd,toFunctionPivotValue:Fd,toXC:T,toZone:Ts,toUnboundedZone:ws,toCartesian:ir,numberToLetters:Yn,lettersToNumber:Xn,UuidGenerator:jl,formatValue:L,createCurrencyFormat:Ro,ColorGenerator:Un,computeTextWidth:ml,createEmptyWorkbookData:RP,createEmptySheet:LP,createEmptyExcelSheet:zP,rgbaToHex:bn,colorToRGBA:xn,positionToZone:R,isDefined:C,isMatrix:Ir,lazy:Nt,genericRepeat:WK,createAction:m,createActions:f,transformRangeData:sf,deepEquals:w,overlap:zs,union:Fs,isInside:Vs,deepCopy:b,expandZoneOnInsertion:js,reduceZoneOnDeletion:Ps,unquote:pt,getMaxObjectId:Td,getFunctionsFromTokens:fC,getFirstPivotFunction:hU,getNumberOfPivotFunctions:_U,parseDimension:Od,isDateOrDatetimeField:kd,makeFieldProposal:uU,insertTokenAfterArgSeparator:fU,insertTokenAfterLeftParenthesis:pU,mergeContiguousZones:dc,getPivotHighlights:YH,pivotTimeAdapter:sd,UNDO_REDO_PIVOT_COMMANDS:sG,createPivotFormula:Md,areDomainArgsFieldsValid:jd,splitReference:jc,sanitizeSheetName:ht,getUniqueText:an,isNumber:Hi,isDateTime:ui,createCustomFields:Wd},FX={isMarkdownLink:xt,parseMarkdownLink:wt,markdownLink:Ct,openLink:Yr,urlRepresentation:Jr},IX={Checkbox:bA,Section:X,RoundColorPicker:aA,ChartDataSeries:IV,ChartErrorSection:LV,ChartLabelRange:RV,ChartTitle:HV,ChartPanel:kH,ChartFigure:dk,ChartJsComponent:Ew,ClickableCellSortIcon:qU,ZoomableChartJsComponent:TD,Grid:GU,GridOverlay:oV,ScorecardChart:Uw,GaugeChartComponent:jD,LineConfigPanel:dH,BarConfigPanel:BV,PieChartDesignPanel:mH,GenericChartConfigPanel:zV,ChartWithAxisDesignPanel:ZV,GenericZoomableChartDesignPanel:QV,LineChartDesignPanel:fH,GaugeChartConfigPanel:iH,GaugeChartDesignPanel:aH,ScorecardChartConfigPanel:_H,ScorecardChartDesignPanel:vH,GeoChartDesignPanel:lH,RadarChartDesignPanel:hH,WaterfallChartDesignPanel:TH,ComboChartDesignPanel:tH,FunnelChartDesignPanel:rH,SunburstChartDesignPanel:yH,TreeMapChartDesignPanel:wH,ChartTypePicker:DH,FigureComponent:mk,MenuPopover:ck,Popover:ik,SelectionInput:mA,ValidationMessages:ZB,AddDimensionButton:eU,PivotDimensionGranularity:nU,PivotDimensionOrder:rU,PivotDimension:tU,PivotLayoutConfigurator:sU,PivotHTMLRenderer:YU,PivotDeferUpdate:ZH,PivotTitleSection:cU,CogWheelMenu:PV,TextInput:kV,SidePanelCollapsible:bk,RadioSelection:WV,GeoChartRegionSelectSection:oH,ChartDashboardMenu:lk,FullScreenFigure:JU},LX={useDragAndDropListItems:sA,useHighlights:MH,useHighlightsOnHover:jH},RX={useStoreProvider:pf,DependencyContainer:lf,CellPopoverStore:TA,ComposerFocusStore:Sf,CellComposerStore:RB,FindAndReplaceStore:UH,HighlightStore:Kk,DelayedHoveredCellStore:hk,HoveredTableStore:rV,ModelStore:vf,NotificationStore:qk,RendererStore:yf,SelectionInputStore:pA,SpreadsheetStore:bf,useStore:z,useLocalStore:mf,SidePanelStore:VU,PivotSidePanelStore:vU,PivotMeasureDisplayPanelStore:qH,ClientFocusStore:fB,GridRenderer:mV};function zX(e,t){return zS.add(e,t),{addFunction:(e,t)=>zX(e,t)}}let BX={DEFAULT_LOCALE:D,HIGHLIGHT_COLOR:v,PIVOT_TABLE_CONFIG:tt,ChartTerms:Ub,FIGURE_ID_SPLITTER:`??`,GRID_ICON_EDGE_LENGTH:17,GRID_ICON_MARGIN:2},VX={...xO,...vD};e.AbstractCellClipboardHandler=Hl,e.AbstractChart=Dw,e.AbstractFigureClipboardHandler=Wl,e.CellErrorType=k,e.ClientDisconnectedError=oK,e.CommandResult=jr,e.CorePlugin=XU,e.CoreViewPlugin=xW,e.DispatchResult=kr,e.EvaluationError=A,e.LocalTransportService=Uq,e.Model=kX,e.PivotRuntimeDefinition=eR,e.Registry=g,e.Revision=aK,e.SPREADSHEET_DIMENSIONS=MX,e.Spreadsheet=OJ,e.SpreadsheetPivotTable=nR,e.UIPlugin=Rp,e.__info__=jX,e.addFunction=zX,e.addRenderingLayer=zr,e.astToFormula=PB,e.chartHelpers=VX,e.compile=rC,e.compileTokens=iC,e.components=IX,e.constants=BX,e.convertAstNodes=$y,e.coreTypes=Er,e.findCellInNewZone=Qs,e.functionCache=nC,e.getCaretDownSvg=Tj,e.getCaretUpSvg=Ej,e.helpers=PX,e.hooks=LX,e.invalidateCFEvaluationCommands=Sr,e.invalidateChartEvaluationCommands=br,e.invalidateDependenciesCommands=xr,e.invalidateEvaluationCommands=yr,e.iterateAstNodes=eb,e.links=FX,e.load=CP,e.parse=Zy,e.parseTokens=Qy,e.readonlyAllowedCommands=Tr,e.registries=NX,e.setDefaultSheetViewSize=$e,e.setTranslationMethod=ur,e.stores=RX,e.tokenColors=ot,e.tokenize=Jl,jX.version=`19.0.37`,jX.date=`2026-06-06T06:22:21.404Z`,jX.hash=`41aace0`})(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|