@borgar/fx 4.10.0 → 4.10.1

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.
package/dist/fx.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";const e="operator",t="error",n="context",l="range_beam",r="range_ternary",o="range_named",s="structured",u="unknown",a="UnaryExpression",i="BinaryExpression",c="ReferenceIdentifier",f="CallExpression",p="LetExpression";function h(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!1,l="";const r=[],o=()=>{l&&r.push(t?l:{value:l,braced:n}),l=""};for(let t=0;t<e.length;t++){const r=e[t];"["===r?(o(),n=!0):"]"===r?(o(),n=!1):l+=r}return o(),r}function g(e){return{context:h(e,!0)}}function d(e){const t={},n=h(e);if(n.length>1)t.workbookName=n[n.length-2].value,t.sheetName=n[n.length-1].value;else if(1===n.length){const e=n[0];e.braced?t.workbookName=e.value:t.sheetName=e.value}return t}const m=e=>e&&(":"===e.value||".:"===e.value||":."===e.value||".:."===e.value)&&{operator:e.value},x=e=>e&&"range"===e.type&&{r0:e.value},y=e=>e&&e.type===r&&{r0:e.value},v=e=>e&&"range"===e.type&&{r1:e.value},$=t=>t&&t.type===e&&"!"===t.value&&{},w=e=>e&&e.type===l&&{r0:e.value},N=e=>e&&e.type===s&&{struct:e.value},E=(e,t)=>{const l=t.xlsx?d:g;return e&&e.type===n?l(e.value):e&&"context_quote"===e.type?l(e.value.slice(1,-1).replace(/''/g,"'")):void 0},R=e=>e&&e.type===o&&{name:e.value},b=[[y],[x,m,v],[x],[w],[E,$,y],[E,$,x,m,v],[E,$,x],[E,$,w]],A=b.concat([[R],[E,$,R],[N],[R,N],[E,$,R,N]]);function C(e,t){const n={withLocation:!1,mergeRefs:!1,allowTernary:!1,allowNamed:!0,r1c1:!1,xlsx:!1,...t},l=je(e,Le,n),r=n.xlsx?{workbookName:"",sheetName:"",r0:"",r1:"",name:"",operator:""}:{context:[],r0:"",r1:"",name:"",operator:""};l.length&&"fx_prefix"===l[0].type&&l.shift();const o=n.allowNamed?A:b;for(let e=0;e<o.length;e++){const t={...r};if(o[e].length===l.length){const r=o[e].every(((e,r)=>{const o=e(l[r],n);return Object.assign(t,o),o}));if(r)return t}}return null}const T=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;function k(e){let t="",n=0,l=0;const r=e.context||[];for(let e=r.length;e>-1;e--){const o=r[e];if(o){t=(l%2?"["+o+"]":o)+t,n+=+T.test(o),l++}}return n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}function L(e){let t="",n=0;const{workbookName:l,sheetName:r}=e;return l&&(t+="["+l+"]",n+=+T.test(l)),r&&(t+=r,n+=+T.test(r)),n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}const I=(e,t,n)=>Math.min(Math.max(t,e),n),_=(e,t)=>(t?"$":"")+S(e),O=(e,t)=>(t?"$":"")+String(e+1),U=String.fromCharCode;function F(e){const t=e||"",n=t.length;let l=0;if(n>2){const e=t.charCodeAt(n-3);l+=676*(1+e-(e>95?32:0)-65)}if(n>1){const e=t.charCodeAt(n-2);l+=26*(1+e-(e>95?32:0)-65)}if(n){const e=t.charCodeAt(n-1);l+=e-(e>95?32:0)-65}return l}function S(e){return(e>=702?U(((e-702)/676-0)%26+65):"")+(e>=26?U((e/26-1)%26+65):"")+U(e%26+65)}function M(e){return"both"===e?".:.":"head"===e?".:":"tail"===e?":.":":"}function D(e,t){return e&&t?"both":e?"head":t?"tail":void 0}function z(e){let{top:t,left:n,bottom:l,right:r,trim:o}=e;const{$left:s,$right:u,$top:a,$bottom:i}=e,c=null==n,f=null==r,p=null==t,h=null==l;t=I(0,0|t,1048575),n=I(0,0|n,16383),!c&&!p&&f&&h?(l=t,r=n):(l=I(0,0|l,1048575),r=I(0,0|r,16383));const g=M(o);if(0===t&&l>=1048575&&!c&&!f&&(!(s&&!c||u&&!f)||n===r)||p&&h)return _(n,s)+g+_(r,u);return 0===n&&r>=16383&&!p&&!h&&(!(a&&!p||i&&!h)||t===l)||c&&f?O(t,a)+g+O(l,i):c||p||f||!h?c||!p||f||h?c||p||!f||h?!c||p||f||h?r!==n||l!==t||u!==s||i!==a?_(n,s)+O(t,a)+g+_(r,u)+O(l,i):_(n,s)+O(t,a):_(r,u)+O(t,a)+g+O(l,i):_(n,s)+O(t,a)+g+O(l,i):_(n,s)+O(l,i)+g+_(r,u):_(n,s)+O(t,a)+g+_(r,u)}function j(e){const t=/^(?=.)(\$(?=\D))?([A-Za-z]{0,3})?(\$)?([1-9][0-9]{0,6})?$/.exec(e);return t&&(t[2]||t[4])?[t[4]?(n=t[4],+n-1):null,t[2]?F(t[2]):null,!!t[3],!!t[1]]:null;var n}function q(e){let t=null,n=null,l=null,r=null,o=!1,s=!1,u=!1,a=!1;const[i,c,f,p,h]=e.split(/(\.?:\.?)/);if(p||h)return null;const g=D(!!c&&"."===c.at(0),!!c&&"."===c.at(-1)),d=j(i),m=f?j(f):null;if(!d||f&&!m)return null;if(null!=d[0]&&null!=d[1]?[t,n,o,s]=d:null==d[0]&&null!=d[1]?[,n,,s]=d:null!=d[0]&&null==d[1]&&([t,,o]=d),f)null!=m[0]&&null!=m[1]?[l,r,u,a]=m:null==m[0]&&null!=m[1]?[,r,,a]=m:null!=m[0]&&null==m[1]&&([l,,u]=m);else{if(null==t||null==n)return null;l=t,r=n,u=o,a=s}null!=r&&(null==n||null!=n&&r<n)&&([n,r,s,a]=[r,n,a,s]),null!=l&&(null==t||null!=t&&l<t)&&([t,l,o,u]=[l,t,u,o]);const x={top:t,left:n,bottom:l,right:r,$top:o,$left:s,$bottom:u,$right:a};return g&&(x.trim=g),x}function B(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=C(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!1});if(r&&(r.r0||r.name)){let e=null;return r.r0&&(e=q(r.r1?r.r0+r.operator+r.r1:r.r0)),e?l?{workbookName:r.workbookName,sheetName:r.sheetName,range:e}:{context:r.context,range:e}:r.name?l?{workbookName:r.workbookName,sheetName:r.sheetName,name:r.name}:{context:r.context,name:r.name}:null}return null}function Z(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?L(e):k(e);return n+(e.name?e.name:z(e.range))}function P(e){return null==e.top&&(e.top=0,e.$top=!1),null==e.bottom&&(e.bottom=1048575,e.$bottom=!1),null==e.left&&(e.left=0,e.$left=!1),null==e.right&&(e.right=16383,e.$right=!1),e}const X=/^\[('['#@[\]]|[^'#@[\]])+\]/i,W=/^([^#@[\]:]+)/i,G={headers:1,data:2,totals:4,all:8,"this row":16,"@":16},H=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.freeze(t)},Y={0:H(),1:H("headers"),2:H("data"),4:H("totals"),8:H("all"),16:H("this row"),3:H("headers","data"),6:H("data","totals")},K=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=X.exec(e);if(n){const e=n[0].slice(1,-1).replace(/'(['#@[\]])/g,"$1");return[n[0],e]}return t&&(n=W.exec(e),n)?[n[0],n[0]]:null};function V(e){const t=[];let n,l,r=0,o=e,s=0;if(!(n=/^(\[\s*)/.exec(o)))return null;if(l=/^\[#([a-z ]+)\]/i.exec(o)){const e=l[1].toLowerCase();if(r+=l[0].length,!G[e])return null;s|=G[e]}else if(l=K(o,!1))r+=l[0].length,t.push(l[1]);else{let l=!0;for(o=o.slice(n[1].length),r+=n[1].length;l&&(n=/^\[#([a-z ]+)\](\s*,\s*)?/i.exec(o));){const e=n[1].toLowerCase();if(!G[e])return null;s|=G[e],o=o.slice(n[0].length),r+=n[0].length,l=!!n[2]}if(l&&(n=/^@/.exec(o))&&(s|=G["@"],o=o.slice(1),r+=1,l="]"!==o[0]),!(s in Y))return null;const u=l?K(e.slice(r)):null;if(u){if(r+=u[0].length,t.push(u[1]),o=e.slice(r),":"===o[0]){o=o.slice(1),r++;const e=K(o);if(!e)return null;r+=e[0].length,t.push(e[1])}l=!1}for(;" "===e[r];)r++;if(l||"]"!==e[r])return null;r++}const u=Y[s];return{columns:t,sections:u?u.concat():u,length:r,token:e.slice(0,r)}}function Q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{xlsx:!1};const n=C(e,t);if(n&&n.struct){const e=V(n.struct);if(e&&e.length===n.struct.length)return t.xlsx?{workbookName:n.workbookName,sheetName:n.sheetName,table:n.name,columns:e.columns,sections:e.sections}:{context:n.context,table:n.name,columns:e.columns,sections:e.sections}}return null}function J(e){return e.replace(/([[\]#'@])/g,"'$1")}function ee(e){return!/^[a-zA-Z0-9\u00a1-\uffff]+$/.test(e)}function te(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()}function ne(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{xlsx:n,thisRow:l}=t;let r=n?L(e):k(e);e.table&&(r+=e.table);const o=e.columns?.length??0,s=e.sections?.length??0;if(1!==s||o)if(s||1!==o){r+="[";const t=!l&&1===s&&"this row"===e.sections[0].toLowerCase();t?r+="@":s&&(r+=e.sections.map((e=>`[#${te(e)}]`)).join(","),o&&(r+=",")),t&&1===e.columns.length&&!ee(e.columns[0])?r+=J(e.columns[0]):o&&(r+=e.columns.slice(0,2).map((e=>`[${J(e)}]`)).join(":")),r+="]"}else r+=`[${J(e.columns[0])}]`;else r+=`[#${te(e.sections[0])}]`;return r}const le=/^(?!!)(\[(?:[^\]])+\])?([0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]+)?(?=!)/,re=/^'(?:''|[^'])*('|$)(?=!)/,oe="\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}",se="\\$?[A-Z]{1,3}",ue="\\$?[1-9][0-9]{0,6}",ae="(?![a-z0-9_\\u00a1-\\uffff])",ie=new RegExp(`^${se}\\.?:\\.?${se}${ae}`,"i"),ce=new RegExp(`^${ue}\\.?:\\.?${ue}${ae}`,"i"),fe=new RegExp(`^${oe}${ae}`,"i"),pe=new RegExp(`^((${se}|${ue})\\.?:\\.?${oe}|${oe}\\.?:\\.?(${se}|${ue}))(?![\\w($.])`,"i"),he="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",ge="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",de=new RegExp(`^${ge}(\\.?:\\.?${ge})?${ae}`,"i"),me=new RegExp(`^${he}(\\.?:\\.?${he})?${ae}`,"i"),xe=new RegExp(`^(?:(?=[RC])${he}${ge})${ae}`,"i"),ye=new RegExp(`^(${he}${ge}(\\.?:\\.?${ge}|\\.?:\\.?${he})(?![[\\d])|(${he}|${ge})(\\.?:\\.?${he}${ge}))${ae}`,"i"),ve=/^[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;function $e(e,t){return n=>{const l=t.exec(n);if(l)return{type:e,value:l[0]}}}function we(e){const t=ve.exec(e);if(t){const e=t[0].toLowerCase();return"\\"===e[0]&&t[0].length<3||("r"===e||"c"===e)?null:{type:o,value:t[0]}}}const Ne=/^'(?:[^[\]]+?)?(?:\[(.+?)\])?(?:[^[\]]+?)'$/,Ee=/^'\[(.+?)\]'$/;function Re(e,t){const l=re.exec(e);if(l){const e=l[0];if(t.xlsx&&Ee.test(e)||Ne.test(e))return{type:"context_quote",value:e}}const r=le.exec(e);if(r){const[,e,l]=r;if(e&&l||l||e&&!l&&t.xlsx)return{type:n,value:r[0]}}}function be(e){const t=V(e);if(t){let n=t.length;for(;" "===e[n];)n++;if("!"!==e[n])return{type:s,value:t.token}}return null}const Ae=/([RC])(\[?)(-?\d+)/gi,Ce=/(\d+|[a-zA-Z]+)/gi;function Te(e,t){let n,o;if(t.r1c1){if(t.allowTernary&&(n=ye.exec(e))?o={type:r,value:n[0]}:(n=xe.exec(e))?o={type:"range",value:n[0]}:((n=me.exec(e))||(n=de.exec(e)))&&(o={type:l,value:n[0]}),o){for(Ae.lastIndex=0;null!==(n=Ae.exec(o.value));){const e=("R"===n[1]?1048575:16383)+(n[2]?0:1),t=parseInt(n[3],10);if(t>e||t<-e)return null}return o}}else if(t.allowTernary&&(n=pe.exec(e))?o={type:r,value:n[0]}:(n=ie.exec(e))||(n=ce.exec(e))?o={type:l,value:n[0]}:(n=fe.exec(e))&&(o={type:"range",value:n[0]}),o){for(Ce.lastIndex=0;null!==(n=Ce.exec(o.value));)if(/^\d/.test(n[1])){if(parseInt(n[1],10)-1>1048575)return null}else if(F(n[1])>16383)return null;return o}}const ke=[$e(t,/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!|CONNECT!|BLOCKED!|EXTERNAL!)/i),$e("operator-trim",/^(\.:\.|\.:|:\.)/),$e(e,/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/),$e("func",/^[A-Z_]+[A-Z\d_.]*(?=\()/i),$e("bool",/^(TRUE|FALSE)\b/i),$e("newline",/^\n+/),$e("whitespace",/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/),$e("string",/^"(?:""|[^"])*("|$)/),Re,Te,be,$e("number",/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/),we],Le=[function(t,n){if(n.r1c1)return"!"===t[0]?{type:e,value:t[0]}:null;const l=/^(!|\.?:\.?)/.exec(t);return l?{type:e,value:l[1]}:null},Re,Te,be,we],Ie={};function _e(e,t){if(e.length){const n=e[0];t[n]=t[n]||{},_e(e.slice(1),t[n])}else t.$=!0}[["range",":","range"],["range",".:","range"],["range",":.","range"],["range",".:.","range"],["range"],[l],[r],[n,"!","range",":","range"],[n,"!","range",".:","range"],[n,"!","range",":.","range"],[n,"!","range",".:.","range"],[n,"!","range"],[n,"!",l],[n,"!",r],["context_quote","!","range",":","range"],["context_quote","!","range",".:","range"],["context_quote","!","range",":.","range"],["context_quote","!","range",".:.","range"],["context_quote","!","range"],["context_quote","!",l],["context_quote","!",r],[o],[n,"!",o],["context_quote","!",o],[s],[o,s],[n,"!",o,s],["context_quote","!",o,s]].forEach((e=>_e(e.concat().reverse(),Ie)));const Oe=function(t,n,l){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=t[l-r];if(o){const s=o.type===e?o.value:o.type;if(s in n)return Oe(t,n[s],l,r+1)}return n.$?r:0};function Ue(e){const t=[];for(let n=e.length-1;n>=0;n--){let l=e[n];const r=Oe(e,Ie,n);if(r){const t=e.slice(n-r+1,n+1);l={...l},l.value=t.map((e=>e.value)).join(""),l.loc&&t[0].loc&&(l.loc[0]=t[0].loc[0]),n-=r-1}t.unshift(l)}return t}const Fe=(e,t)=>e&&e.type===t,Se={withLocation:!1,mergeRefs:!0,allowTernary:!1,negativeNumbers:!0,r1c1:!1},Me=e=>e.type===o||"func"===e.type,De=t=>!Fe(t,e)||"%"===t.value||"}"===t.value||")"===t.value||"#"===t.value;function ze(t){let n,l=0,r=0;for(const s of t){if(s.type===e)if("("===s.value){if(r++,"func"===n.type){const e=n.value.toLowerCase();"lambda"!==e&&"let"!==e||(l=r)}}else")"===s.value&&(r--,r<l&&(l=0));else l&&s.type===u&&/^[rc]$/.test(s.value)&&(s.type=o);n=s}return t}function je(t,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=Object.assign({},Se,l),{withLocation:o,mergeRefs:s,negativeNumbers:a}=r,i=[];let c=0,f=0,p=0;const h=[];let g=null,d=null,m=null;const x=e=>{const t=e.type===u,n=m&&m.type===u;m&&(t&&n||t&&Me(m)||n&&Me(e))?(m.value+=e.value,m.type=u,o&&(m.loc[1]=e.loc[1])):("operator-trim"===e.type&&(h.push(i.length),e.type=u),i.push(e),m=e,"whitespace"!==e.type&&"newline"!==e.type&&(d=g,g=e))};if("="===t.at(0)){c++,x({type:"fx_prefix",value:"=",...o?{loc:[0,1]}:{}})}for(;c<t.length;){const l=c,s=t.slice(c);let h="",y="";for(let e=0;e<n.length;e++){const t=n[e](s,r);if(t){h=t.type,y=t.value,c+=y.length;break}}h||(h=u,y=t[c],c++);const v={type:h,value:y,...o?{loc:[l,c]}:{}};if(m&&"func"===m.type&&"("===y){const e=m.value.toLowerCase();"lambda"!==e&&"let"!==e||f++}if(h===u){const e=y.toLowerCase();p+="r"===e||"c"===e?1:0}if("string"===h){const e=y.length;if('""'===y);else if('"'===y||'"'!==y[e-1])v.unterminated=!0;else if('""'!==y&&'"'===y[e-2]){let t=e-1;for(;'"'===y[t];)t--;!(t+1)^(e-t+1)%2==0&&(v.unterminated=!0)}}if(a&&"number"===h){const t=m;if(t&&Fe(t,e)&&"-"===t.value&&(!d||Fe(d,"fx_prefix")||!De(d))){const e=i.pop();v.value="-"+y,o&&(v.loc[0]=e.loc[0]),g=d,m=i[i.length-1]}}x(v)}p&&f&&ze(i);for(const t of h){const n=i[t-1],l=i[t-1];n&&"range"===n.type&&l&&"range"===l.type?i[t].type=e:i[t].type=u}return s?Ue(i):i}function qe(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return je(e,ke,t)}function Be(e){return!!e&&("range"===e.type||e.type===l||e.type===r)}function Ze(e){return!!e&&("range"===e.type||e.type===l||e.type===r||e.type===s||e.type===o)}function Pe(e){return!!e&&("bool"===e.type||e.type===t||"number"===e.type||"string"===e.type)}function Xe(e){return!!e&&e.type===t}function We(e){return!!e&&("whitespace"===e.type||"newline"===e.type)}function Ge(e){return!!e&&"func"===e.type}function He(e){return!!e&&"fx_prefix"===e.type}function Ye(t){return!!t&&t.type===e}const Ke="(END)",Ve=["ANCHORARRAY","CHOOSE","DROP","IF","IFS","INDEX","INDIRECT","LAMBDA","LET","OFFSET","REDUCE","SINGLE","SWITCH","TAKE","TRIMRANGE","XLOOKUP"],Qe=e=>Ve.includes(e.toUpperCase()),Je=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=(e&&e.value)+"";return!!Ze(e)||(!(!t||!Ye(e)||":"!==n&&","!==n&&n.trim())||(!(!Ge(e)||!Qe(n))||!(!Xe(e)||"#REF!"!==n)))},et=e=>!!e&&(e.type===c||("ErrorLiteral"===e.type||e.type===t)&&"#REF!"===e.value||e.type===i&&(":"===e.operator||" "===e.operator||","===e.operator)||Ze(e)||e.type===f&&Qe(e.callee.name)),tt={};let nt,lt,rt,ot=!1,st=!1;function ut(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const n=new Error(e);throw n.source=lt.map((e=>e.value)).join(""),n.sourceOffset=lt.slice(0,t??rt).reduce(((e,t)=>e+t.value.length),0),n}function at(){let e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=rt;do{e=lt[++n]}while(e&&(We(e)||Ye(e)&&"("===e.value));return Je(e,t)}function it(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(e&&e!==nt.id&&ut(`Expected ${e} but got ${nt.id}`),We(lt[rt])){const e=et(t),n=e&&at(!1),l=e&&"("===lt[rt+1].value;if(!n&&!l)for(;We(lt[rt]);)rt++}if(rt>=lt.length)return void(nt=tt[Ke]);const n=lt[rt];let l;return rt+=1,n.unterminated&&ut("Encountered an unterminated token"),Ye(n)?(l=tt[n.value],l||ut(`Unknown operator ${n.value}`)):We(n)?l=tt["(WHITESPACE)"]:Pe(n)?l=tt.Literal:Ze(n)?l=tt[c]:Ge(n)?l=tt["(FUNCTION)"]:ut(`Unexpected ${n.type} token: ${n.value}`),nt=Object.create(l),nt.type=n.type,nt.value=n.value,n.loc&&(nt.loc=[...n.loc]),nt}function ct(e){let t=nt;it(null,t);let n=t.nud();for(;e<nt.lbp;)t=nt,it(null,t),n=t.led(n);return n}const ft={nud:()=>ut("Invalid syntax"),led:()=>ut("Missing operator")};function pt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=tt[e];return n?t>=n.lbp&&(n.lbp=t):(n={...ft},n.id=e,n.value=e,n.lbp=t,tt[e]=n),n}function ht(e,t,n){const l=pt(e,t);return l.led=n||function(e){this.type=i,this.operator=this.value,delete this.value;const n=ct(t);return this.arguments=[e,n],this.loc&&(this.loc=[e.loc[0],n.loc[1]]),this},l}function gt(e,t){const n=pt(e,0);return n.lbp=70,n.led=t||function(e){return this.type=a,this.operator=this.value,delete this.value,this.arguments=[e],this.loc&&(this.loc[0]=e.loc[0]),this},n}function dt(e,t){const n=pt(e);return n.nud=t||function(){this.type=a,this.operator=this.value,delete this.value;const e=ct(70);return this.arguments=[e],this.loc&&(this.loc[1]=e.loc[1]),this},n}function mt(e,t){return ht(e,t,(function(n){et(n)||ut(`Unexpected ${e} operator`);const l=ct(t);return et(l)||ut(`Unexpected ${nt.type} following ${this.id}`),this.type=i,this.operator=this.value.trim()?this.value:" ",delete this.value,this.arguments=[n,l],this.loc&&(this.loc=[n.loc[0],l.loc[1]]),this}))}pt(Ke),mt(":",80);const xt=mt(",",80);mt("(WHITESPACE)",80);const yt=e=>{const t=xt.lbp>0;return null!=e&&(xt.lbp=e?80:0),t};function vt(e){const t=[],n={};let l,r=!1;const o=yt(!1);if(")"!==nt.id)for(;!r;){We(nt)&&it();const e=rt,o=ct(0);if(","===nt.id){if(o.type===c&&"name"===o.kind){const e=o.value.toLowerCase();e in n&&ut("Duplicate name: "+o.value),n[e]=1;const l={type:"Identifier",name:o.value};o.loc&&(l.loc=o.loc),t.push(l)}else rt=e,ut("LAMBDA argument is not a name");it(",")}else l=o,r=!0}return yt(o),delete this.value,this.type="LambdaExpression",this.params=t,this.body=l||null,e.loc&&(this.loc=[e.loc[0],nt.loc[1]]),it(")",this),this}function $t(e){const t=[],n=[],l={};let r,o=0;const s=(e,s)=>{if(r&&ut("Unexpected argument following calculation"),s&&o>=2)r=e;else{if(!(o%2))if(e&&e.type===c&&"name"===e.kind){const n=e.value.toLowerCase();n in l&&ut("Duplicate name: "+e.value),l[n]=1,t.push({type:"Identifier",name:e.value,loc:e.loc})}else o>=2?r=e:ut("Argument is not a name");else n.push(e)}o++},u=yt(!1);let a=!1;if(")"!==nt.id){for(;")"!==nt.id;)if(We(nt)&&it(),","===nt.id)s(null),a=!0,it();else{s(ct(0),","!==nt.id),a=!1,","===nt.id&&(it(","),a=!0)}yt(u)}a&&s(null,!0),void 0===r&&ut("Unexpected end of arguments"),yt(u),delete this.value,this.type=p,this.declarations=[],t.length||ut("Unexpected end of arguments");for(let e=0;e<t.length;e++){const l={type:"LetDeclarator",id:t[e],init:n[e],loc:t[e].loc&&[t[e].loc[0],n[e].loc[1]]};this.declarations.push(l)}return this.body=r,e.loc&&(this.loc=[e.loc[0],nt.loc[1]]),it(")",this),this}function wt(){let e=1;return()=>"fxg"+e++}function Nt(e,t){return null==e&&null==t||e===t}function Et(e,t){if(Array.isArray(e)!==Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Nt(e[n],t[n]))return!1;return!0}function Rt(e,t){return!e&&!t||String(e).toLowerCase()===String(t).toLowerCase()}function bt(e,t){if((e.name||t.name)&&e.name!==t.name)return!1;if(e.columns||t.columns){if(e.table!==t.table)return!1;if(!Et(e.columns,t.columns))return!1;if(!Et(e.sections,t.sections))return!1}return!!(!e.range&&!t.range||Nt(e.range.top,t.range.top)&&Nt(e.range.bottom,t.range.bottom)&&Nt(e.range.left,t.range.left)&&Nt(e.range.right,t.range.right))&&!(!Rt(e.workbookName,t.workbookName)||!Rt(e.sheetName,t.sheetName))}function At(e,t,n){return e.sheetName||(e.sheetName=t),e.workbookName||(e.workbookName=n),e}gt("%"),gt("#",(function(e){return et(e)||ut("# expects a reference"),this.type=a,this.operator=this.value,delete this.value,this.arguments=[e],this})),dt("+"),dt("-"),dt("@"),ht("^",50),ht("*",40),ht("/",40),ht("+",30),ht("-",30),ht("&",20),ht("=",10),ht("<",10),ht(">",10),ht("<=",10),ht(">=",10),ht("<>",10),pt("Literal").nud=function(){const{type:e,value:n}=this;if(this.type="Literal",this.raw=n,"number"===e)this.value=+n;else if("bool"===e)this.value="TRUE"===n.toUpperCase();else if(e===t)this.type="ErrorLiteral",this.value=n.toUpperCase();else{if("string"!==e)throw new Error("Unsupported literal type: "+e);this.value=n.slice(1,-1).replace(/""/g,'"')}return this},pt(c).nud=function(){return this.type===o?this.kind="name":this.type===s?this.kind="table":this.type===l?this.kind="beam":this.kind="range",this.type=c,this},pt(")"),dt("(",(function(){const e=yt(!0),t=ct(0);return it(")",t),yt(e),t})),pt("(FUNCTION)").nud=function(){return this},ht("(",90,(function(e){let t={type:"Identifier",name:e.value};"(FUNCTION)"!==e.id&&("LambdaExpression"===e.type||e.type===f||e.type===p||e.type===c||e.type===a&&"#"===e.value||"ErrorLiteral"===e.type&&"#REF!"===e.value?t=e:ut("Unexpected call",rt-1));const n=e.value.toLowerCase();if("lambda"===n)return vt.call(this,e);if("let"===n)return $t.call(this,e);const l=[];let r=!1;if(")"!==nt.id){const e=yt(!1);for(;")"!==nt.id;)if(We(nt)&&it(),","===nt.id)l.push(null),r=!0,it();else{const e=ct(0);l.push(e),r=!1,","===nt.id&&(it(","),r=!0)}yt(e)}r&&l.push(null);const o=nt;return delete this.value,this.type=f,this.callee=t,e.loc&&(this.callee.loc=[...e.loc]),this.arguments=l,e.loc&&(this.loc=[e.loc[0],o.loc[1]]),it(")",this),this})),pt("}"),pt(";"),dt("{",(function(){"}"===nt.id&&ut("Unexpected empty array");let e=[],t=!1;const n=[e],l=yt(!1);for(;!t;){if(We(nt)&&it(),Pe(nt))e.push(tt.Literal.nud.call(nt)),it();else if(ot&&et(nt))e.push(tt[c].nud.call(nt)),it();else if(st&&Ge(nt)){const t=ct(0);e.push(t)}else ut(`Unexpected ${nt.type} in array: ${nt.value}`);","===nt.id?it(","):";"===nt.id?(it(";"),e=[],n.push(e)):t=!0}const r=nt;return it("}"),yt(l),this.type="ArrayExpression",this.elements=n,this.loc&&(this.loc[1]=r.loc[1]),delete this.value,this}));const Ct=(e,t,n)=>Math.min(Math.max(t,e),n);function Tt(e,t){return t?String(e+1):e?"["+e+"]":""}function kt(e){let{r0:t,c0:n,r1:l,c1:r}=e;const{$c0:o,$c1:s,$r0:u,$r1:a}=e,i=null==t,c=null==n;let f=null==l,p=null==r;const h=M(e.trim),g=!!e.trim;t=Ct(u?0:-1048575,0|t,1048575),n=Ct(o?0:-16383,0|n,16383),!i&&f&&!c&&p?(l=t,f=!1,r=n,p=!1):(l=Ct(a?0:-1048575,0|l,1048575),r=Ct(s?0:-16383,0|r,16383));if(0===t&&l>=1048575&&!c&&!p||i&&f){const e=Tt(n,o),t=Tt(r,s);return"C"+(e!==t||g?e+h+"C"+t:e)}if(0===n&&r>=16383&&!i&&!f||c&&p){const e=Tt(t,u),n=Tt(l,a);return"R"+(e!==n||g?e+h+"R"+n:e)}const d=Tt(t,u),m=Tt(l,a),x=Tt(n,o),y=Tt(r,s);return i||f||c||p?(i?"":"R"+d)+(c?"":"C"+x)+h+(f?"":"R"+m)+(p?"":"C"+y):d!==m||x!==y?"R"+d+"C"+x+h+"R"+m+"C"+y:"R"+d+"C"+x}function Lt(e){let t=null,n=null,l=null,r=null;const o=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);o&&(o[1]?(t=parseInt(o[1],10),l=!1):o[2]?(t=parseInt(o[2],10)-1,l=!0):(t=0,l=!1),e=e.slice(o[0].length));const s=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);return s&&(s[1]?(n=parseInt(s[1],10),r=!1):s[2]?(n=parseInt(s[2],10)-1,r=!0):(n=0,r=!1),e=e.slice(s[0].length)),!o&&!s||e.length?null:[t,n,l,r]}function It(e){let t=null;const[n,l,r,o]=e.split(/(\.?:\.?)/);if(o)return null;const s=Lt(n),u=D(!!l&&"."===l.at(0),!!l&&"."===l.at(-1));if(s){const[e,n,l,o]=s;if(r){const s=Lt(r);if(!s)return null;{t={};const[r,u,a,i]=s;null!=e&&null!=r?(t.r0=l===a?Math.min(e,r):e,t.$r0=l,t.r1=l===a?Math.max(e,r):r,t.$r1=a):null!=e&&null==r?(t.r0=e,t.$r0=l,t.r1=null,t.$r1=l):null==e&&null!=r?(t.r0=r,t.$r0=a,t.r1=null,t.$r1=a):null==e&&null==r&&(t.r0=null,t.$r0=!1,t.r1=null,t.$r1=!1),null!=n&&null!=u?(t.c0=o===i?Math.min(n,u):n,t.$c0=o,t.c1=o===i?Math.max(n,u):u,t.$c1=i):null!=n&&null==u?(t.c0=n,t.$c0=o,t.c1=null,t.$c1=o):null==n&&null!=u?(t.c0=u,t.$c0=i,t.c1=null,t.$c1=i):null==n&&null==u&&(t.c0=null,t.$c0=!1,t.c1=null,t.$c1=!1)}}else t=null!=e&&null==n?{r0:e,c0:null,r1:e,c1:null,$r0:l,$c0:!1,$r1:l,$c1:!1}:null==e&&null!=n?{r0:null,c0:n,r1:null,c1:n,$r0:!1,$c0:o,$r1:!1,$c1:o}:{r0:e||0,c0:n||0,r1:e||0,c1:n||0,$r0:l||!1,$c0:o||!1,$r1:l||!1,$c1:o||!1}}return t&&u&&(t.trim=u),t}function _t(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=C(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!0});if(r&&(r.r0||r.name)){const e=r.r1?It(r.r0+r.operator+r.r1):It(r.r0);return e?l?{workbookName:r.workbookName,sheetName:r.sheetName,range:e}:{context:r.context,range:e}:r.name?l?{workbookName:r.workbookName,sheetName:r.sheetName,name:r.name}:{context:r.context,name:r.name}:null}return null}function Ot(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?L(e):k(e);return n+(e.name?e.name:kt(e.range))}const Ut=(e,t,n)=>null==t?null:e?t:t-n,Ft={withLocation:!1,mergeRefs:!1,allowTernary:!0,r1c1:!1};function St(e,t,n,l){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=e;if(null!=o&&!t){if(o=n+e,o<0){if(!r)return NaN;o=l+o+1}if(o>l){if(!r)return NaN;o-=l+1}}return o}const Mt={wrapEdges:!0,mergeRefs:!0,allowTernary:!0,xlsx:!1};const Dt=Object.freeze({OPERATOR:e,BOOLEAN:"bool",ERROR:t,NUMBER:"number",FUNCTION:"func",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",CONTEXT:n,CONTEXT_QUOTE:"context_quote",REF_RANGE:"range",REF_BEAM:l,REF_TERNARY:r,REF_NAMED:o,REF_STRUCT:s,FX_PREFIX:"fx_prefix",UNKNOWN:u}),zt=Object.freeze({UNARY:a,BINARY:i,REFERENCE:c,LITERAL:"Literal",ERROR:"ErrorLiteral",CALL:f,ARRAY:"ArrayExpression",IDENTIFIER:"Identifier"});exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.addA1RangeBounds=P,exports.addTokenMeta=function(e){let{sheetName:t="",workbookName:n=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[];let a=null;const i=wt(),c=[],f=()=>o.length+(a?1:0);return e.forEach(((e,p)=>{if(e.index=p,e.depth=f(),"("===e.value)o.push(e),e.depth=f();else if(")"===e.value){const t=o.pop();if(t){const n=i();e.groupId=n,e.depth=t.depth,t.groupId=n}else e.error=!0}else if("{"===e.value)a?e.error=!0:(a=e,e.depth=f());else if("}"===e.value){if(a){const t=i();e.groupId=t,e.depth=a.depth,a.groupId=t}else e.error=!0;a=null}else if("range"===e.type||e.type===l||e.type===r||e.type===s){const l=e.type===s?Q(e.value,{xlsx:!0}):B(e.value,{allowTernary:!0,xlsx:!0});if(l&&(l.range||l.columns)){l.source=e.value,At(l,t,n);const r=c.find((e=>bt(e,l)));r?e.groupId=r.groupId:(l.groupId=i(),e.groupId=l.groupId,c.push(l))}}else e.type===u&&(e.error=!0)})),e},exports.fixRanges=function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{addBounds:!1};if("string"==typeof t)return e(qe(t,n),n).map((e=>e.value)).join("");if(!Array.isArray(t))throw new Error("fixRanges expects an array of tokens");const{addBounds:l,r1c1:r,xlsx:o,thisRow:u}=n;if(r)throw new Error("fixRanges does not have an R1C1 mode");let a=0;return t.map((e=>{const t={...e};e.loc&&(t.loc=[...e.loc]);let n=0;if(t.type===s){const e=ne(Q(t.value,{xlsx:o}),{xlsx:o,thisRow:u});n=e.length-t.value.length,t.value=e}else if(Be(t)){const e=B(t.value,{xlsx:o,allowTernary:!0}),r=e.range;l&&P(r);const s=Z(e,{xlsx:o});n=s.length-t.value.length,t.value=s}return a||n?(t.loc&&(t.loc[0]+=a),a+=n,t.loc&&(t.loc[1]+=a)):a+=n,t}))},exports.fromCol=F,exports.isError=Xe,exports.isFunction=Ge,exports.isFxPrefix=He,exports.isLiteral=Pe,exports.isOperator=Ye,exports.isRange=Be,exports.isReference=Ze,exports.isWhitespace=We,exports.mergeRefTokens=Ue,exports.nodeTypes=zt,exports.parse=function(e,t){if("string"==typeof e)lt=qe(e,{withLocation:!1,...t,mergeRefs:!0});else{if(!Array.isArray(e))throw new Error("Parse requires a string or array of tokens.");lt=e}for(ot=t?.permitArrayRanges,st=t?.permitArrayCalls,rt=0;We(lt[rt])||He(lt[rt]);)rt++;it(),yt(!0);const n=ct(0);return it(Ke),n},exports.parseA1Ref=B,exports.parseR1C1Ref=_t,exports.parseStructRef=Q,exports.stringifyA1Ref=Z,exports.stringifyR1C1Ref=Ot,exports.stringifyStructRef=ne,exports.toCol=S,exports.tokenTypes=Dt,exports.tokenize=qe,exports.translateToA1=function(e,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Mt;const r=q(n),o="string"==typeof e,s={...Mt,...l},u=o?qe(e,{withLocation:!1,mergeRefs:s.mergeRefs,xlsx:s.xlsx,allowTernary:s.allowTernary,r1c1:!0}):e;let a=0;const i={xlsx:s.xlsx,allowTernary:s.allowTernary};return u.forEach((e=>{if(Be(e)){const n=e.value,l=_t(n,i),o=l.range,u={},c=St(o.r0,o.$r0,r.top,1048575,s.wrapEdges),f=St(o.r1,o.$r1,r.top,1048575,s.wrapEdges);c>f?(u.top=f,u.$top=o.$r1,u.bottom=c,u.$bottom=o.$r0):(u.top=c,u.$top=o.$r0,u.bottom=f,u.$bottom=o.$r1);const p=St(o.c0,o.$c0,r.left,16383,s.wrapEdges),h=St(o.c1,o.$c1,r.left,16383,s.wrapEdges);p>h?(u.left=h,u.$left=o.$c1,u.right=p,u.$right=o.$c0):(u.left=p,u.$left=o.$c0,u.right=h,u.$right=o.$c1),o.trim&&(u.trim=o.trim),isNaN(c)||isNaN(f)||isNaN(p)||isNaN(h)?(e.type=t,e.value="#REF!",delete e.groupId):(l.range=u,e.value=Z(l,i)),e.loc&&(e.loc[0]+=a,a+=e.value.length-n.length,e.loc[1]+=a)}else a&&e.loc&&(e.loc[0]+=a,e.loc[1]+=a)})),o?u.map((e=>e.value)).join(""):u},exports.translateToR1C1=function(e,t){let{xlsx:n=!1,allowTernary:l=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{top:r,left:o}=q(t),s="string"==typeof e,u=s?qe(e,{...Ft,xlsx:n,allowTernary:l}):e;let a=0;const i={xlsx:n,allowTernary:l};return u.forEach((e=>{if(Be(e)){const t=e.value,n=B(t,i),l=n.range,s={};s.r0=Ut(l.$top,l.top,r),s.r1=Ut(l.$bottom,l.bottom,r),s.c0=Ut(l.$left,l.left,o),s.c1=Ut(l.$right,l.right,o),s.$r0=l.$top,s.$r1=l.$bottom,s.$c0=l.$left,s.$c1=l.$right,l.trim&&(s.trim=l.trim),n.range=s,e.value=Ot(n,i),e.loc&&(e.loc[0]+=a,a+=e.value.length-t.length,e.loc[1]+=a)}else a&&e.loc&&(e.loc[0]+=a,e.loc[1]+=a)})),s?u.map((e=>e.value)).join(""):u};
1
+ "use strict";const e="operator",t="error",n="context",l="range_beam",r="range_ternary",o="range_named",s="structured",u="unknown",a="UnaryExpression",i="BinaryExpression",c="ReferenceIdentifier",f="CallExpression",p="LetExpression";function h(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!1,l="";const r=[],o=()=>{l&&r.push(t?l:{value:l,braced:n}),l=""};for(let t=0;t<e.length;t++){const r=e[t];"["===r?(o(),n=!0):"]"===r?(o(),n=!1):l+=r}return o(),r}function g(e){return{context:h(e,!0)}}function d(e){const t={},n=h(e);if(n.length>1)t.workbookName=n[n.length-2].value,t.sheetName=n[n.length-1].value;else if(1===n.length){const e=n[0];e.braced?t.workbookName=e.value:t.sheetName=e.value}return t}const m=e=>e&&(":"===e.value||".:"===e.value||":."===e.value||".:."===e.value)&&{operator:e.value},x=e=>e&&"range"===e.type&&{r0:e.value},y=e=>e&&e.type===r&&{r0:e.value},v=e=>e&&"range"===e.type&&{r1:e.value},$=t=>t&&t.type===e&&"!"===t.value&&{},w=e=>e&&e.type===l&&{r0:e.value},N=e=>e&&e.type===s&&{struct:e.value},E=(e,t)=>{const l=t.xlsx?d:g;return e&&e.type===n?l(e.value):e&&"context_quote"===e.type?l(e.value.slice(1,-1).replace(/''/g,"'")):void 0},R=e=>e&&e.type===o&&{name:e.value},b=[[y],[x,m,v],[x],[w],[E,$,y],[E,$,x,m,v],[E,$,x],[E,$,w]],A=b.concat([[R],[E,$,R],[N],[R,N],[E,$,R,N]]);function C(e,t){const n={withLocation:!1,mergeRefs:!1,allowTernary:!1,allowNamed:!0,r1c1:!1,xlsx:!1,...t},l=je(e,Le,n),r=n.xlsx?{workbookName:"",sheetName:"",r0:"",r1:"",name:"",operator:""}:{context:[],r0:"",r1:"",name:"",operator:""};l.length&&"fx_prefix"===l[0].type&&l.shift();const o=n.allowNamed?A:b;for(let e=0;e<o.length;e++){const t={...r};if(o[e].length===l.length){const r=o[e].every(((e,r)=>{const o=e(l[r],n);return Object.assign(t,o),o}));if(r)return t}}return null}const T=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;function k(e){let t="",n=0,l=0;const r=e.context||[];for(let e=r.length;e>-1;e--){const o=r[e];if(o){t=(l%2?"["+o+"]":o)+t,n+=+T.test(o),l++}}return n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}function L(e){let t="",n=0;const{workbookName:l,sheetName:r}=e;return l&&(t+="["+l+"]",n+=+T.test(l)),r&&(t+=r,n+=+T.test(r)),n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}const I=(e,t,n)=>Math.min(Math.max(t,e),n),_=(e,t)=>(t?"$":"")+S(e),O=(e,t)=>(t?"$":"")+String(e+1),U=String.fromCharCode;function F(e){const t=e||"",n=t.length;let l=0;if(n>2){const e=t.charCodeAt(n-3);l+=676*(1+e-(e>95?32:0)-65)}if(n>1){const e=t.charCodeAt(n-2);l+=26*(1+e-(e>95?32:0)-65)}if(n){const e=t.charCodeAt(n-1);l+=e-(e>95?32:0)-65}return l}function S(e){return(e>=702?U(((e-702)/676-0)%26+65):"")+(e>=26?U((e/26-1)%26+65):"")+U(e%26+65)}function M(e){return"both"===e?".:.":"head"===e?".:":"tail"===e?":.":":"}function D(e,t){return e&&t?"both":e?"head":t?"tail":void 0}function z(e){let{top:t,left:n,bottom:l,right:r,trim:o}=e;const{$left:s,$right:u,$top:a,$bottom:i}=e,c=null==n,f=null==r,p=null==t,h=null==l;t=I(0,0|t,1048575),n=I(0,0|n,16383),!c&&!p&&f&&h?(l=t,r=n):(l=I(0,0|l,1048575),r=I(0,0|r,16383));const g=M(o);if(0===t&&l>=1048575&&!c&&!f&&(!(s&&!c||u&&!f)||n===r)||p&&h)return _(n,s)+g+_(r,u);return 0===n&&r>=16383&&!p&&!h&&(!(a&&!p||i&&!h)||t===l)||c&&f?O(t,a)+g+O(l,i):c||p||f||!h?c||!p||f||h?c||p||!f||h?!c||p||f||h?r!==n||l!==t||u!==s||i!==a?_(n,s)+O(t,a)+g+_(r,u)+O(l,i):_(n,s)+O(t,a):_(r,u)+O(t,a)+g+O(l,i):_(n,s)+O(t,a)+g+O(l,i):_(n,s)+O(l,i)+g+_(r,u):_(n,s)+O(t,a)+g+_(r,u)}function j(e){const t=/^(?=.)(\$(?=\D))?([A-Za-z]{0,3})?(\$)?([1-9][0-9]{0,6})?$/.exec(e);return t&&(t[2]||t[4])?[t[4]?(n=t[4],+n-1):null,t[2]?F(t[2]):null,!!t[3],!!t[1]]:null;var n}function q(e){let t=null,n=null,l=null,r=null,o=!1,s=!1,u=!1,a=!1;const[i,c,f,p,h]=e.split(/(\.?:\.?)/);if(p||h)return null;const g=D(!!c&&"."===c.at(0),!!c&&"."===c.at(-1)),d=j(i),m=f?j(f):null;if(!d||f&&!m)return null;if(null!=d[0]&&null!=d[1]?[t,n,o,s]=d:null==d[0]&&null!=d[1]?[,n,,s]=d:null!=d[0]&&null==d[1]&&([t,,o]=d),f)null!=m[0]&&null!=m[1]?[l,r,u,a]=m:null==m[0]&&null!=m[1]?[,r,,a]=m:null!=m[0]&&null==m[1]&&([l,,u]=m);else{if(null==t||null==n)return null;l=t,r=n,u=o,a=s}null!=r&&(null==n||null!=n&&r<n)&&([n,r,s,a]=[r,n,a,s]),null!=l&&(null==t||null!=t&&l<t)&&([t,l,o,u]=[l,t,u,o]);const x={top:t,left:n,bottom:l,right:r,$top:o,$left:s,$bottom:u,$right:a};return g&&(x.trim=g),x}function B(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=C(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!1});if(r&&(r.r0||r.name)){let e=null;return r.r0&&(e=q(r.r1?r.r0+r.operator+r.r1:r.r0)),e?l?{workbookName:r.workbookName,sheetName:r.sheetName,range:e}:{context:r.context,range:e}:r.name?l?{workbookName:r.workbookName,sheetName:r.sheetName,name:r.name}:{context:r.context,name:r.name}:null}return null}function Z(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?L(e):k(e);return n+(e.name?e.name:z(e.range))}function P(e){return null==e.top&&(e.top=0,e.$top=!1),null==e.bottom&&(e.bottom=1048575,e.$bottom=!1),null==e.left&&(e.left=0,e.$left=!1),null==e.right&&(e.right=16383,e.$right=!1),e}const X=/^\[('['#@[\]]|[^'#@[\]])+\]/i,W=/^([^#@[\]:]+)/i,G={headers:1,data:2,totals:4,all:8,"this row":16,"@":16},H=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.freeze(t)},Y={0:H(),1:H("headers"),2:H("data"),4:H("totals"),8:H("all"),16:H("this row"),3:H("headers","data"),6:H("data","totals")},K=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=X.exec(e);if(n){const e=n[0].slice(1,-1).replace(/'(['#@[\]])/g,"$1");return[n[0],e]}return t&&(n=W.exec(e),n)?[n[0],n[0]]:null};function V(e){const t=[];let n,l,r=0,o=e,s=0;if(!(n=/^(\[\s*)/.exec(o)))return null;if(l=/^\[#([a-z ]+)\]/i.exec(o)){const e=l[1].toLowerCase();if(r+=l[0].length,!G[e])return null;s|=G[e]}else if(l=K(o,!1))r+=l[0].length,t.push(l[1]);else{let l=!0;for(o=o.slice(n[1].length),r+=n[1].length;l&&(n=/^\[#([a-z ]+)\](\s*,\s*)?/i.exec(o));){const e=n[1].toLowerCase();if(!G[e])return null;s|=G[e],o=o.slice(n[0].length),r+=n[0].length,l=!!n[2]}if(l&&(n=/^@/.exec(o))&&(s|=G["@"],o=o.slice(1),r+=1,l="]"!==o[0]),!(s in Y))return null;const u=l?K(e.slice(r)):null;if(u){if(r+=u[0].length,t.push(u[1]),o=e.slice(r),":"===o[0]){o=o.slice(1),r++;const e=K(o);if(!e)return null;r+=e[0].length,t.push(e[1])}l=!1}for(;" "===e[r];)r++;if(l||"]"!==e[r])return null;r++}const u=Y[s];return{columns:t,sections:u?u.concat():u,length:r,token:e.slice(0,r)}}function Q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{xlsx:!1};const n=C(e,t);if(n&&n.struct){const e=V(n.struct);if(e&&e.length===n.struct.length)return t.xlsx?{workbookName:n.workbookName,sheetName:n.sheetName,table:n.name,columns:e.columns,sections:e.sections}:{context:n.context,table:n.name,columns:e.columns,sections:e.sections}}return null}function J(e){return e.replace(/([[\]#'@])/g,"'$1")}function ee(e){return!/^[a-zA-Z0-9\u00a1-\uffff]+$/.test(e)}function te(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()}function ne(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{xlsx:n,thisRow:l}=t;let r=n?L(e):k(e);e.table&&(r+=e.table);const o=e.columns?.length??0,s=e.sections?.length??0;if(1!==s||o)if(s||1!==o){r+="[";const t=!l&&1===s&&"this row"===e.sections[0].toLowerCase();t?r+="@":s&&(r+=e.sections.map((e=>`[#${te(e)}]`)).join(","),o&&(r+=",")),t&&1===e.columns.length&&!ee(e.columns[0])?r+=J(e.columns[0]):o&&(r+=e.columns.slice(0,2).map((e=>`[${J(e)}]`)).join(":")),r+="]"}else r+=`[${J(e.columns[0])}]`;else r+=`[#${te(e.sections[0])}]`;return r}const le=/^(?!!)(\[(?:[^\]])+\])?([0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]+)?(?=!)/,re=/^'(?:''|[^'])*('|$)(?=!)/,oe="\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}",se="\\$?[A-Z]{1,3}",ue="\\$?[1-9][0-9]{0,6}",ae="(?![a-z0-9_\\u00a1-\\uffff])",ie=new RegExp(`^${se}\\.?:\\.?${se}${ae}`,"i"),ce=new RegExp(`^${ue}\\.?:\\.?${ue}${ae}`,"i"),fe=new RegExp(`^${oe}${ae}`,"i"),pe=new RegExp(`^((${se}|${ue})\\.?:\\.?${oe}|${oe}\\.?:\\.?(${se}|${ue}))(?![\\w($.])`,"i"),he="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",ge="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",de=new RegExp(`^${ge}(\\.?:\\.?${ge})?${ae}`,"i"),me=new RegExp(`^${he}(\\.?:\\.?${he})?${ae}`,"i"),xe=new RegExp(`^(?:(?=[RC])${he}${ge})${ae}`,"i"),ye=new RegExp(`^(${he}${ge}(\\.?:\\.?${ge}|\\.?:\\.?${he})(?![[\\d])|(${he}|${ge})(\\.?:\\.?${he}${ge}))${ae}`,"i"),ve=/^[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;function $e(e,t){return n=>{const l=t.exec(n);if(l)return{type:e,value:l[0]}}}function we(e){const t=ve.exec(e);if(t){const e=t[0].toLowerCase();return"\\"===e[0]&&t[0].length<3||("r"===e||"c"===e)?null:{type:o,value:t[0]}}}const Ne=/^'(?:[^[\]]+?)?(?:\[(.+?)\])?(?:[^[\]]+?)'$/,Ee=/^'\[(.+?)\]'$/;function Re(e,t){const l=re.exec(e);if(l){const e=l[0];if(t.xlsx&&Ee.test(e)||Ne.test(e))return{type:"context_quote",value:e}}const r=le.exec(e);if(r){const[,e,l]=r;if(e&&l||l||e&&!l&&t.xlsx)return{type:n,value:r[0]}}}function be(e){const t=V(e);if(t){let n=t.length;for(;" "===e[n];)n++;if("!"!==e[n])return{type:s,value:t.token}}return null}const Ae=/([RC])(\[?)(-?\d+)/gi,Ce=/(\d+|[a-zA-Z]+)/gi;function Te(e,t){let n,o;if(t.r1c1){if(t.allowTernary&&(n=ye.exec(e))?o={type:r,value:n[0]}:(n=xe.exec(e))?o={type:"range",value:n[0]}:((n=me.exec(e))||(n=de.exec(e)))&&(o={type:l,value:n[0]}),o){for(Ae.lastIndex=0;null!==(n=Ae.exec(o.value));){const e=("R"===n[1]?1048575:16383)+(n[2]?0:1),t=parseInt(n[3],10);if(t>e||t<-e)return null}return o}}else if(t.allowTernary&&(n=pe.exec(e))?o={type:r,value:n[0]}:(n=ie.exec(e))||(n=ce.exec(e))?o={type:l,value:n[0]}:(n=fe.exec(e))&&(o={type:"range",value:n[0]}),o){for(Ce.lastIndex=0;null!==(n=Ce.exec(o.value));)if(/^\d/.test(n[1])){if(parseInt(n[1],10)-1>1048575)return null}else if(F(n[1])>16383)return null;return o}}const ke=[$e(t,/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!|CONNECT!|BLOCKED!|EXTERNAL!)/i),$e("operator-trim",/^(\.:\.|\.:|:\.)/),$e(e,/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/),$e("func",/^[A-Z_]+[A-Z\d_.]*(?=\()/i),$e("bool",/^(TRUE|FALSE)\b/i),$e("newline",/^\n+/),$e("whitespace",/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/),$e("string",/^"(?:""|[^"])*("|$)/),Re,Te,be,$e("number",/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/),we],Le=[function(t,n){if(n.r1c1)return"!"===t[0]?{type:e,value:t[0]}:null;const l=/^(!|\.?:\.?)/.exec(t);return l?{type:e,value:l[1]}:null},Re,Te,be,we],Ie={};function _e(e,t){if(e.length){const n=e[0];t[n]=t[n]||{},_e(e.slice(1),t[n])}else t.$=!0}[["range",":","range"],["range",".:","range"],["range",":.","range"],["range",".:.","range"],["range"],[l],[r],[n,"!","range",":","range"],[n,"!","range",".:","range"],[n,"!","range",":.","range"],[n,"!","range",".:.","range"],[n,"!","range"],[n,"!",l],[n,"!",r],["context_quote","!","range",":","range"],["context_quote","!","range",".:","range"],["context_quote","!","range",":.","range"],["context_quote","!","range",".:.","range"],["context_quote","!","range"],["context_quote","!",l],["context_quote","!",r],[o],[n,"!",o],["context_quote","!",o],[s],[o,s],[n,"!",o,s],["context_quote","!",o,s]].forEach((e=>_e(e.concat().reverse(),Ie)));const Oe=function(t,n,l){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=t[l-r];if(o){const s=o.type===e?o.value:o.type;if(s in n)return Oe(t,n[s],l,r+1)}return n.$?r:0};function Ue(e){const t=[];for(let n=e.length-1;n>=0;n--){let l=e[n];const r=Oe(e,Ie,n);if(r){const t=e.slice(n-r+1,n+1);l={...l},l.value=t.map((e=>e.value)).join(""),l.loc&&t[0].loc&&(l.loc[0]=t[0].loc[0]),n-=r-1}t.unshift(l)}return t}const Fe=(e,t)=>e&&e.type===t,Se={withLocation:!1,mergeRefs:!0,allowTernary:!1,negativeNumbers:!0,r1c1:!1},Me=e=>e.type===o||"func"===e.type,De=t=>!Fe(t,e)||"%"===t.value||"}"===t.value||")"===t.value||"#"===t.value;function ze(t){let n,l=0,r=0;for(const s of t){if(s.type===e)if("("===s.value){if(r++,"func"===n.type){const e=n.value.toLowerCase();"lambda"!==e&&"let"!==e||(l=r)}}else")"===s.value&&(r--,r<l&&(l=0));else l&&s.type===u&&/^[rc]$/.test(s.value)&&(s.type=o);n=s}return t}function je(t,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=Object.assign({},Se,l),{withLocation:o,mergeRefs:s,negativeNumbers:a}=r,i=[];let c=0,f=0,p=0;const h=[];let g=null,d=null,m=null;const x=e=>{const t=e.type===u,n=m&&m.type===u;m&&(t&&n||t&&Me(m)||n&&Me(e))?(m.value+=e.value,m.type=u,o&&(m.loc[1]=e.loc[1])):("operator-trim"===e.type&&(h.push(i.length),e.type=u),i.push(e),m=e,"whitespace"!==e.type&&"newline"!==e.type&&(d=g,g=e))};if("="===t.at(0)){c++,x({type:"fx_prefix",value:"=",...o?{loc:[0,1]}:{}})}for(;c<t.length;){const l=c,s=t.slice(c);let h="",y="";for(let e=0;e<n.length;e++){const t=n[e](s,r);if(t){h=t.type,y=t.value,c+=y.length;break}}h||(h=u,y=t[c],c++);const v={type:h,value:y,...o?{loc:[l,c]}:{}};if(m&&"func"===m.type&&"("===y){const e=m.value.toLowerCase();"lambda"!==e&&"let"!==e||f++}if(h===u){const e=y.toLowerCase();p+="r"===e||"c"===e?1:0}if("string"===h){const e=y.length;if('""'===y);else if('"'===y||'"'!==y[e-1])v.unterminated=!0;else if('""'!==y&&'"'===y[e-2]){let t=e-1;for(;'"'===y[t];)t--;!(t+1)^(e-t+1)%2==0&&(v.unterminated=!0)}}if(a&&"number"===h){const t=m;if(t&&Fe(t,e)&&"-"===t.value&&(!d||Fe(d,"fx_prefix")||!De(d))){const e=i.pop();v.value="-"+y,o&&(v.loc[0]=e.loc[0]),g=d,m=i[i.length-1]}}x(v)}p&&f&&ze(i);for(const t of h){const n=i[t-1],l=i[t-1];n&&"range"===n.type&&l&&"range"===l.type?i[t].type=e:i[t].type=u}return s?Ue(i):i}function qe(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return je(e,ke,t)}function Be(e){return!!e&&("range"===e.type||e.type===l||e.type===r)}function Ze(e){return!!e&&("range"===e.type||e.type===l||e.type===r||e.type===s||e.type===o)}function Pe(e){return!!e&&("bool"===e.type||e.type===t||"number"===e.type||"string"===e.type)}function Xe(e){return!!e&&e.type===t}function We(e){return!!e&&("whitespace"===e.type||"newline"===e.type)}function Ge(e){return!!e&&"func"===e.type}function He(e){return!!e&&"fx_prefix"===e.type}function Ye(t){return!!t&&t.type===e}const Ke="(END)",Ve=["ANCHORARRAY","CHOOSE","DROP","IF","IFS","INDEX","INDIRECT","LAMBDA","LET","OFFSET","REDUCE","SINGLE","SWITCH","TAKE","TRIMRANGE","XLOOKUP"],Qe=e=>Ve.includes(e.toUpperCase()),Je=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=(e&&e.value)+"";return!!Ze(e)||(!(!t||!Ye(e)||":"!==n&&","!==n&&n.trim())||(!(!Ge(e)||!Qe(n))||!(!Xe(e)||"#REF!"!==n)))},et=e=>!!e&&(e.type===c||("ErrorLiteral"===e.type||e.type===t)&&"#REF!"===e.value||e.type===i&&(":"===e.operator||" "===e.operator||","===e.operator)||Ze(e)||e.type===f&&Qe(e.callee.name)),tt={};let nt,lt,rt,ot=!1,st=!1;function ut(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const n=new Error(e);throw n.source=lt.map((e=>e.value)).join(""),n.sourceOffset=lt.slice(0,t??rt).reduce(((e,t)=>e+t.value.length),0),n}function at(){let e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=rt;do{e=lt[++n]}while(e&&(We(e)||Ye(e)&&"("===e.value));return Je(e,t)}function it(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(e&&e!==nt.id&&ut(`Expected ${e} but got ${nt.id}`),We(lt[rt])){const e=et(t),n=e&&at(!1),l=e&&lt[rt+1]&&"("===lt[rt+1].value;if(!n&&!l)for(;We(lt[rt]);)rt++}if(rt>=lt.length)return void(nt=tt[Ke]);const n=lt[rt];let l;return rt+=1,n.unterminated&&ut("Encountered an unterminated token"),Ye(n)?(l=tt[n.value],l||ut(`Unknown operator ${n.value}`)):We(n)?l=tt["(WHITESPACE)"]:Pe(n)?l=tt.Literal:Ze(n)?l=tt[c]:Ge(n)?l=tt["(FUNCTION)"]:ut(`Unexpected ${n.type} token: ${n.value}`),nt=Object.create(l),nt.type=n.type,nt.value=n.value,n.loc&&(nt.loc=[...n.loc]),nt}function ct(e){let t=nt;it(null,t);let n=t.nud();for(;e<nt.lbp;)t=nt,it(null,t),n=t.led(n);return n}const ft={nud:()=>ut("Invalid syntax"),led:()=>ut("Missing operator")};function pt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=tt[e];return n?t>=n.lbp&&(n.lbp=t):(n={...ft},n.id=e,n.value=e,n.lbp=t,tt[e]=n),n}function ht(e,t,n){const l=pt(e,t);return l.led=n||function(e){this.type=i,this.operator=this.value,delete this.value;const n=ct(t);return this.arguments=[e,n],this.loc&&(this.loc=[e.loc[0],n.loc[1]]),this},l}function gt(e,t){const n=pt(e,0);return n.lbp=70,n.led=t||function(e){return this.type=a,this.operator=this.value,delete this.value,this.arguments=[e],this.loc&&(this.loc[0]=e.loc[0]),this},n}function dt(e,t){const n=pt(e);return n.nud=t||function(){this.type=a,this.operator=this.value,delete this.value;const e=ct(70);return this.arguments=[e],this.loc&&(this.loc[1]=e.loc[1]),this},n}function mt(e,t){return ht(e,t,(function(n){et(n)||ut(`Unexpected ${e} operator`);const l=ct(t);return et(l)||ut(`Unexpected ${nt.type} following ${this.id}`),this.type=i,this.operator=this.value.trim()?this.value:" ",delete this.value,this.arguments=[n,l],this.loc&&(this.loc=[n.loc[0],l.loc[1]]),this}))}pt(Ke),mt(":",80);const xt=mt(",",80);mt("(WHITESPACE)",80);const yt=e=>{const t=xt.lbp>0;return null!=e&&(xt.lbp=e?80:0),t};function vt(e){const t=[],n={};let l,r=!1;const o=yt(!1);if(")"!==nt.id)for(;!r;){We(nt)&&it();const e=rt,o=ct(0);if(","===nt.id){if(o.type===c&&"name"===o.kind){const e=o.value.toLowerCase();e in n&&ut("Duplicate name: "+o.value),n[e]=1;const l={type:"Identifier",name:o.value};o.loc&&(l.loc=o.loc),t.push(l)}else rt=e,ut("LAMBDA argument is not a name");it(",")}else l=o,r=!0}return yt(o),delete this.value,this.type="LambdaExpression",this.params=t,this.body=l||null,e.loc&&(this.loc=[e.loc[0],nt.loc[1]]),it(")",this),this}function $t(e){const t=[],n=[],l={};let r,o=0;const s=(e,s)=>{if(r&&ut("Unexpected argument following calculation"),s&&o>=2)r=e;else{if(!(o%2))if(e&&e.type===c&&"name"===e.kind){const n=e.value.toLowerCase();n in l&&ut("Duplicate name: "+e.value),l[n]=1,t.push({type:"Identifier",name:e.value,loc:e.loc})}else o>=2?r=e:ut("Argument is not a name");else n.push(e)}o++},u=yt(!1);let a=!1;if(")"!==nt.id){for(;")"!==nt.id;)if(We(nt)&&it(),","===nt.id)s(null),a=!0,it();else{s(ct(0),","!==nt.id),a=!1,","===nt.id&&(it(","),a=!0)}yt(u)}a&&s(null,!0),void 0===r&&ut("Unexpected end of arguments"),yt(u),delete this.value,this.type=p,this.declarations=[],t.length||ut("Unexpected end of arguments");for(let e=0;e<t.length;e++){const l={type:"LetDeclarator",id:t[e],init:n[e],loc:t[e].loc&&[t[e].loc[0],n[e].loc[1]]};this.declarations.push(l)}return this.body=r,e.loc&&(this.loc=[e.loc[0],nt.loc[1]]),it(")",this),this}function wt(){let e=1;return()=>"fxg"+e++}function Nt(e,t){return null==e&&null==t||e===t}function Et(e,t){if(Array.isArray(e)!==Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Nt(e[n],t[n]))return!1;return!0}function Rt(e,t){return!e&&!t||String(e).toLowerCase()===String(t).toLowerCase()}function bt(e,t){if((e.name||t.name)&&e.name!==t.name)return!1;if(e.columns||t.columns){if(e.table!==t.table)return!1;if(!Et(e.columns,t.columns))return!1;if(!Et(e.sections,t.sections))return!1}return!!(!e.range&&!t.range||Nt(e.range.top,t.range.top)&&Nt(e.range.bottom,t.range.bottom)&&Nt(e.range.left,t.range.left)&&Nt(e.range.right,t.range.right))&&!(!Rt(e.workbookName,t.workbookName)||!Rt(e.sheetName,t.sheetName))}function At(e,t,n){return e.sheetName||(e.sheetName=t),e.workbookName||(e.workbookName=n),e}gt("%"),gt("#",(function(e){return et(e)||ut("# expects a reference"),this.type=a,this.operator=this.value,delete this.value,this.arguments=[e],this})),dt("+"),dt("-"),dt("@"),ht("^",50),ht("*",40),ht("/",40),ht("+",30),ht("-",30),ht("&",20),ht("=",10),ht("<",10),ht(">",10),ht("<=",10),ht(">=",10),ht("<>",10),pt("Literal").nud=function(){const{type:e,value:n}=this;if(this.type="Literal",this.raw=n,"number"===e)this.value=+n;else if("bool"===e)this.value="TRUE"===n.toUpperCase();else if(e===t)this.type="ErrorLiteral",this.value=n.toUpperCase();else{if("string"!==e)throw new Error("Unsupported literal type: "+e);this.value=n.slice(1,-1).replace(/""/g,'"')}return this},pt(c).nud=function(){return this.type===o?this.kind="name":this.type===s?this.kind="table":this.type===l?this.kind="beam":this.kind="range",this.type=c,this},pt(")"),dt("(",(function(){const e=yt(!0),t=ct(0);return it(")",t),yt(e),t})),pt("(FUNCTION)").nud=function(){return this},ht("(",90,(function(e){let t={type:"Identifier",name:e.value};"(FUNCTION)"!==e.id&&("LambdaExpression"===e.type||e.type===f||e.type===p||e.type===c||e.type===a&&"#"===e.value||"ErrorLiteral"===e.type&&"#REF!"===e.value?t=e:ut("Unexpected call",rt-1));const n=e.value.toLowerCase();if("lambda"===n)return vt.call(this,e);if("let"===n)return $t.call(this,e);const l=[];let r=!1;if(")"!==nt.id){const e=yt(!1);for(;")"!==nt.id;)if(We(nt)&&it(),","===nt.id)l.push(null),r=!0,it();else{const e=ct(0);l.push(e),r=!1,","===nt.id&&(it(","),r=!0)}yt(e)}r&&l.push(null);const o=nt;return delete this.value,this.type=f,this.callee=t,e.loc&&(this.callee.loc=[...e.loc]),this.arguments=l,e.loc&&(this.loc=[e.loc[0],o.loc[1]]),it(")",this),this})),pt("}"),pt(";"),dt("{",(function(){"}"===nt.id&&ut("Unexpected empty array");let e=[],t=!1;const n=[e],l=yt(!1);for(;!t;){if(We(nt)&&it(),Pe(nt))e.push(tt.Literal.nud.call(nt)),it();else if(ot&&et(nt))e.push(tt[c].nud.call(nt)),it();else if(st&&Ge(nt)){const t=ct(0);e.push(t)}else ut(`Unexpected ${nt.type} in array: ${nt.value}`);","===nt.id?it(","):";"===nt.id?(it(";"),e=[],n.push(e)):t=!0}const r=nt;return it("}"),yt(l),this.type="ArrayExpression",this.elements=n,this.loc&&(this.loc[1]=r.loc[1]),delete this.value,this}));const Ct=(e,t,n)=>Math.min(Math.max(t,e),n);function Tt(e,t){return t?String(e+1):e?"["+e+"]":""}function kt(e){let{r0:t,c0:n,r1:l,c1:r}=e;const{$c0:o,$c1:s,$r0:u,$r1:a}=e,i=null==t,c=null==n;let f=null==l,p=null==r;const h=M(e.trim),g=!!e.trim;t=Ct(u?0:-1048575,0|t,1048575),n=Ct(o?0:-16383,0|n,16383),!i&&f&&!c&&p?(l=t,f=!1,r=n,p=!1):(l=Ct(a?0:-1048575,0|l,1048575),r=Ct(s?0:-16383,0|r,16383));if(0===t&&l>=1048575&&!c&&!p||i&&f){const e=Tt(n,o),t=Tt(r,s);return"C"+(e!==t||g?e+h+"C"+t:e)}if(0===n&&r>=16383&&!i&&!f||c&&p){const e=Tt(t,u),n=Tt(l,a);return"R"+(e!==n||g?e+h+"R"+n:e)}const d=Tt(t,u),m=Tt(l,a),x=Tt(n,o),y=Tt(r,s);return i||f||c||p?(i?"":"R"+d)+(c?"":"C"+x)+h+(f?"":"R"+m)+(p?"":"C"+y):d!==m||x!==y?"R"+d+"C"+x+h+"R"+m+"C"+y:"R"+d+"C"+x}function Lt(e){let t=null,n=null,l=null,r=null;const o=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);o&&(o[1]?(t=parseInt(o[1],10),l=!1):o[2]?(t=parseInt(o[2],10)-1,l=!0):(t=0,l=!1),e=e.slice(o[0].length));const s=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);return s&&(s[1]?(n=parseInt(s[1],10),r=!1):s[2]?(n=parseInt(s[2],10)-1,r=!0):(n=0,r=!1),e=e.slice(s[0].length)),!o&&!s||e.length?null:[t,n,l,r]}function It(e){let t=null;const[n,l,r,o]=e.split(/(\.?:\.?)/);if(o)return null;const s=Lt(n),u=D(!!l&&"."===l.at(0),!!l&&"."===l.at(-1));if(s){const[e,n,l,o]=s;if(r){const s=Lt(r);if(!s)return null;{t={};const[r,u,a,i]=s;null!=e&&null!=r?(t.r0=l===a?Math.min(e,r):e,t.$r0=l,t.r1=l===a?Math.max(e,r):r,t.$r1=a):null!=e&&null==r?(t.r0=e,t.$r0=l,t.r1=null,t.$r1=l):null==e&&null!=r?(t.r0=r,t.$r0=a,t.r1=null,t.$r1=a):null==e&&null==r&&(t.r0=null,t.$r0=!1,t.r1=null,t.$r1=!1),null!=n&&null!=u?(t.c0=o===i?Math.min(n,u):n,t.$c0=o,t.c1=o===i?Math.max(n,u):u,t.$c1=i):null!=n&&null==u?(t.c0=n,t.$c0=o,t.c1=null,t.$c1=o):null==n&&null!=u?(t.c0=u,t.$c0=i,t.c1=null,t.$c1=i):null==n&&null==u&&(t.c0=null,t.$c0=!1,t.c1=null,t.$c1=!1)}}else t=null!=e&&null==n?{r0:e,c0:null,r1:e,c1:null,$r0:l,$c0:!1,$r1:l,$c1:!1}:null==e&&null!=n?{r0:null,c0:n,r1:null,c1:n,$r0:!1,$c0:o,$r1:!1,$c1:o}:{r0:e||0,c0:n||0,r1:e||0,c1:n||0,$r0:l||!1,$c0:o||!1,$r1:l||!1,$c1:o||!1}}return t&&u&&(t.trim=u),t}function _t(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=C(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!0});if(r&&(r.r0||r.name)){const e=r.r1?It(r.r0+r.operator+r.r1):It(r.r0);return e?l?{workbookName:r.workbookName,sheetName:r.sheetName,range:e}:{context:r.context,range:e}:r.name?l?{workbookName:r.workbookName,sheetName:r.sheetName,name:r.name}:{context:r.context,name:r.name}:null}return null}function Ot(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?L(e):k(e);return n+(e.name?e.name:kt(e.range))}const Ut=(e,t,n)=>null==t?null:e?t:t-n,Ft={withLocation:!1,mergeRefs:!1,allowTernary:!0,r1c1:!1};function St(e,t,n,l){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=e;if(null!=o&&!t){if(o=n+e,o<0){if(!r)return NaN;o=l+o+1}if(o>l){if(!r)return NaN;o-=l+1}}return o}const Mt={wrapEdges:!0,mergeRefs:!0,allowTernary:!0,xlsx:!1};const Dt=Object.freeze({OPERATOR:e,BOOLEAN:"bool",ERROR:t,NUMBER:"number",FUNCTION:"func",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",CONTEXT:n,CONTEXT_QUOTE:"context_quote",REF_RANGE:"range",REF_BEAM:l,REF_TERNARY:r,REF_NAMED:o,REF_STRUCT:s,FX_PREFIX:"fx_prefix",UNKNOWN:u}),zt=Object.freeze({UNARY:a,BINARY:i,REFERENCE:c,LITERAL:"Literal",ERROR:"ErrorLiteral",CALL:f,ARRAY:"ArrayExpression",IDENTIFIER:"Identifier"});exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.addA1RangeBounds=P,exports.addTokenMeta=function(e){let{sheetName:t="",workbookName:n=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[];let a=null;const i=wt(),c=[],f=()=>o.length+(a?1:0);return e.forEach(((e,p)=>{if(e.index=p,e.depth=f(),"("===e.value)o.push(e),e.depth=f();else if(")"===e.value){const t=o.pop();if(t){const n=i();e.groupId=n,e.depth=t.depth,t.groupId=n}else e.error=!0}else if("{"===e.value)a?e.error=!0:(a=e,e.depth=f());else if("}"===e.value){if(a){const t=i();e.groupId=t,e.depth=a.depth,a.groupId=t}else e.error=!0;a=null}else if("range"===e.type||e.type===l||e.type===r||e.type===s){const l=e.type===s?Q(e.value,{xlsx:!0}):B(e.value,{allowTernary:!0,xlsx:!0});if(l&&(l.range||l.columns)){l.source=e.value,At(l,t,n);const r=c.find((e=>bt(e,l)));r?e.groupId=r.groupId:(l.groupId=i(),e.groupId=l.groupId,c.push(l))}}else e.type===u&&(e.error=!0)})),e},exports.fixRanges=function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{addBounds:!1};if("string"==typeof t)return e(qe(t,n),n).map((e=>e.value)).join("");if(!Array.isArray(t))throw new Error("fixRanges expects an array of tokens");const{addBounds:l,r1c1:r,xlsx:o,thisRow:u}=n;if(r)throw new Error("fixRanges does not have an R1C1 mode");let a=0;return t.map((e=>{const t={...e};e.loc&&(t.loc=[...e.loc]);let n=0;if(t.type===s){const e=ne(Q(t.value,{xlsx:o}),{xlsx:o,thisRow:u});n=e.length-t.value.length,t.value=e}else if(Be(t)){const e=B(t.value,{xlsx:o,allowTernary:!0}),r=e.range;l&&P(r);const s=Z(e,{xlsx:o});n=s.length-t.value.length,t.value=s}return a||n?(t.loc&&(t.loc[0]+=a),a+=n,t.loc&&(t.loc[1]+=a)):a+=n,t}))},exports.fromCol=F,exports.isError=Xe,exports.isFunction=Ge,exports.isFxPrefix=He,exports.isLiteral=Pe,exports.isOperator=Ye,exports.isRange=Be,exports.isReference=Ze,exports.isWhitespace=We,exports.mergeRefTokens=Ue,exports.nodeTypes=zt,exports.parse=function(e,t){if("string"==typeof e)lt=qe(e,{withLocation:!1,...t,mergeRefs:!0});else{if(!Array.isArray(e))throw new Error("Parse requires a string or array of tokens.");lt=e}for(ot=t?.permitArrayRanges,st=t?.permitArrayCalls,rt=0;We(lt[rt])||He(lt[rt]);)rt++;it(),yt(!0);const n=ct(0);return it(Ke),n},exports.parseA1Ref=B,exports.parseR1C1Ref=_t,exports.parseStructRef=Q,exports.stringifyA1Ref=Z,exports.stringifyR1C1Ref=Ot,exports.stringifyStructRef=ne,exports.toCol=S,exports.tokenTypes=Dt,exports.tokenize=qe,exports.translateToA1=function(e,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Mt;const r=q(n),o="string"==typeof e,s={...Mt,...l},u=o?qe(e,{withLocation:!1,mergeRefs:s.mergeRefs,xlsx:s.xlsx,allowTernary:s.allowTernary,r1c1:!0}):e;let a=0;const i={xlsx:s.xlsx,allowTernary:s.allowTernary};return u.forEach((e=>{if(Be(e)){const n=e.value,l=_t(n,i),o=l.range,u={},c=St(o.r0,o.$r0,r.top,1048575,s.wrapEdges),f=St(o.r1,o.$r1,r.top,1048575,s.wrapEdges);c>f?(u.top=f,u.$top=o.$r1,u.bottom=c,u.$bottom=o.$r0):(u.top=c,u.$top=o.$r0,u.bottom=f,u.$bottom=o.$r1);const p=St(o.c0,o.$c0,r.left,16383,s.wrapEdges),h=St(o.c1,o.$c1,r.left,16383,s.wrapEdges);p>h?(u.left=h,u.$left=o.$c1,u.right=p,u.$right=o.$c0):(u.left=p,u.$left=o.$c0,u.right=h,u.$right=o.$c1),o.trim&&(u.trim=o.trim),isNaN(c)||isNaN(f)||isNaN(p)||isNaN(h)?(e.type=t,e.value="#REF!",delete e.groupId):(l.range=u,e.value=Z(l,i)),e.loc&&(e.loc[0]+=a,a+=e.value.length-n.length,e.loc[1]+=a)}else a&&e.loc&&(e.loc[0]+=a,e.loc[1]+=a)})),o?u.map((e=>e.value)).join(""):u},exports.translateToR1C1=function(e,t){let{xlsx:n=!1,allowTernary:l=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{top:r,left:o}=q(t),s="string"==typeof e,u=s?qe(e,{...Ft,xlsx:n,allowTernary:l}):e;let a=0;const i={xlsx:n,allowTernary:l};return u.forEach((e=>{if(Be(e)){const t=e.value,n=B(t,i),l=n.range,s={};s.r0=Ut(l.$top,l.top,r),s.r1=Ut(l.$bottom,l.bottom,r),s.c0=Ut(l.$left,l.left,o),s.c1=Ut(l.$right,l.right,o),s.$r0=l.$top,s.$r1=l.$bottom,s.$c0=l.$left,s.$c1=l.$right,l.trim&&(s.trim=l.trim),n.range=s,e.value=Ot(n,i),e.loc&&(e.loc[0]+=a,a+=e.value.length-t.length,e.loc[1]+=a)}else a&&e.loc&&(e.loc[0]+=a,e.loc[1]+=a)})),s?u.map((e=>e.value)).join(""):u};
2
2
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
package/lib/lexer.spec.js CHANGED
@@ -1916,25 +1916,38 @@ test('trim operators are not valid outside literal ranges', t => {
1916
1916
  ]);
1917
1917
 
1918
1918
  t.isTokens('=name1.:.name2', [
1919
- { type: 'fx_prefix', value: '=' },
1919
+ { type: FX_PREFIX, value: '=' },
1920
1920
  { type: REF_NAMED, value: 'name1.' },
1921
- { type: 'unknown', value: ':.name2' }
1921
+ { type: UNKNOWN, value: ':.name2' }
1922
1922
  ]);
1923
1923
 
1924
1924
  t.isTokens('=OFFSET(A1,1,1).:.INDIRECT("A1")', [
1925
- { type: 'fx_prefix', value: '=' },
1926
- { type: 'func', value: 'OFFSET' },
1927
- { type: 'operator', value: '(' },
1928
- { type: 'range', value: 'A1' },
1929
- { type: 'operator', value: ',' },
1930
- { type: 'number', value: '1' },
1931
- { type: 'operator', value: ',' },
1932
- { type: 'number', value: '1' },
1933
- { type: 'operator', value: ')' },
1934
- { type: 'unknown', value: '.:.INDIRECT' },
1935
- { type: 'operator', value: '(' },
1936
- { type: 'string', value: '"A1"' },
1937
- { type: 'operator', value: ')' }
1925
+ { type: FX_PREFIX, value: '=' },
1926
+ { type: FUNCTION, value: 'OFFSET' },
1927
+ { type: OPERATOR, value: '(' },
1928
+ { type: REF_RANGE, value: 'A1' },
1929
+ { type: OPERATOR, value: ',' },
1930
+ { type: NUMBER, value: '1' },
1931
+ { type: OPERATOR, value: ',' },
1932
+ { type: NUMBER, value: '1' },
1933
+ { type: OPERATOR, value: ')' },
1934
+ { type: UNKNOWN, value: '.:.INDIRECT' },
1935
+ { type: OPERATOR, value: '(' },
1936
+ { type: STRING, value: '"A1"' },
1937
+ { type: OPERATOR, value: ')' }
1938
+ ]);
1939
+ t.end();
1940
+ });
1941
+
1942
+ test('whitespace handling', t => {
1943
+ t.isTokens('\tA1\u00a0+\nB2\r', [
1944
+ { type: WHITESPACE, value: '\t' },
1945
+ { type: REF_RANGE, value: 'A1' },
1946
+ { type: WHITESPACE, value: '\u00a0' },
1947
+ { type: OPERATOR, value: '+' },
1948
+ { type: NEWLINE, value: '\n' },
1949
+ { type: REF_RANGE, value: 'B2' },
1950
+ { type: WHITESPACE, value: '\r' }
1938
1951
  ]);
1939
1952
  t.end();
1940
1953
  });
package/lib/parser.js CHANGED
@@ -139,7 +139,7 @@ function advance (expectNext = null, leftNode = null) {
139
139
  // potential intersection operation (so don't allow operators as upcoming)
140
140
  const haveRef = isReferenceNode(leftNode);
141
141
  const possibleWSOp = haveRef && refIsUpcoming(false);
142
- const nextIsCall = haveRef && tokens[tokenIndex + 1].value === '(';
142
+ const nextIsCall = haveRef && tokens[tokenIndex + 1] && tokens[tokenIndex + 1].value === '(';
143
143
  if (!possibleWSOp && !nextIsCall) {
144
144
  // ignore whitespace
145
145
  while (isWhitespace(tokens[tokenIndex])) {
@@ -1182,3 +1182,15 @@ test('parser supports LET expressions', t => {
1182
1182
  });
1183
1183
  t.end();
1184
1184
  });
1185
+
1186
+ test('parser whitespace handling', t => {
1187
+ t.isParsed('\tA1\u00a0+\nB2\r', {
1188
+ type: 'BinaryExpression',
1189
+ operator: '+',
1190
+ arguments: [
1191
+ { type: 'ReferenceIdentifier', value: 'A1', kind: 'range' },
1192
+ { type: 'ReferenceIdentifier', value: 'B2', kind: 'range' }
1193
+ ]
1194
+ });
1195
+ t.end();
1196
+ });
package/lib/sr.spec.js CHANGED
@@ -278,7 +278,7 @@ test('structured references parse and serialize in xlsx mode', t => {
278
278
  t.end();
279
279
  });
280
280
 
281
- test.only('longform serialize (in xlsx mode)', t => {
281
+ test('longform serialize (in xlsx mode)', t => {
282
282
  // thisRow should have no effect when parsing
283
283
  t.isSREqual('Table2[[#This Row],[col1]]', {
284
284
  table: 'Table2',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borgar/fx",
3
- "version": "4.10.0",
3
+ "version": "4.10.1",
4
4
  "description": "Utilities for working with Excel formulas",
5
5
  "main": "dist/fx.js",
6
6
  "types": "dist/fx.d.ts",