@sheetxl/sdk 0.7.28-beta.2 → 0.7.28-beta.4

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.
Files changed (64) hide show
  1. package/browser/cjs/{BREMLtxkQhtNSVra.cjs → BF14ZEAnaqxXroSj.cjs} +1 -1
  2. package/browser/cjs/{BG7YDVxiC4ErxvF1.cjs → BXtvdT1Z-MsB_o5F.cjs} +1 -1
  3. package/browser/cjs/Bc4JjVVZfFo3R4He.cjs +33 -0
  4. package/browser/cjs/{CQf4zxkBmheTVbjX.cjs → CD2RXdnfqSYNc6gX.cjs} +2 -2
  5. package/browser/cjs/DcLpXGexEtOxi-dD.cjs +1 -0
  6. package/browser/cjs/index.cjs +2 -2
  7. package/browser/esm/{DN4d5bDBkti28wuc.mjs → 0Mj5WKM362q6CECb.mjs} +213 -207
  8. package/browser/esm/{BxIOX1TojvA-1ZZP.mjs → CHSahmMFYNB0Ajkf.mjs} +2 -2
  9. package/browser/esm/{CZO1RubmqnJV96rq.mjs → CKk58ZLcrllMzfou.mjs} +2 -2
  10. package/browser/esm/{DRWu3TmcE9JFf78V.mjs → CPTtL2f6_4iblmFM.mjs} +2 -2
  11. package/browser/esm/{DPOelA1J3WHbMXyh.mjs → CoA-sUxjiIUIpTUF.mjs} +2 -2
  12. package/browser/esm/{vHWuKF-ftK7LM1uw.mjs → DBIu6NUHIcxOOBQp.mjs} +1 -1
  13. package/browser/esm/{CB_4gdPPPruwremH.mjs → Dy4Sdpju1T2icURu.mjs} +4748 -3883
  14. package/browser/esm/index.mjs +419 -411
  15. package/node/esm/{XQhP3dYwF_tEuswB.mjs → BtGxbEbBm79YvF_k.mjs} +303 -297
  16. package/node/esm/{B-tgcZihStNV9CbZ.mjs → DUYP6faJJHCaW1Xf.mjs} +1 -1
  17. package/node/esm/{C8tfYGL3wHy9IDDc.mjs → DqgWsVXROpSgKq6c.mjs} +2 -2
  18. package/node/esm/index.mjs +8686 -7802
  19. package/package.json +6 -6
  20. package/resources/locales/de/model.msg.json +12 -0
  21. package/resources/locales/en/model.msg.json +12 -0
  22. package/types/scripting-enums.json +2 -0
  23. package/types/scripting.d.ts +341 -15
  24. package/types/src/anchored/IAnchored.d.ts +27 -0
  25. package/types/src/calculation/Calculation.d.ts +21 -12
  26. package/types/src/calculation/ICalculation.d.ts +183 -0
  27. package/types/src/calculation/compiler/CompilerUtils.d.ts +20 -0
  28. package/types/src/calculation/compiler/FormulaParser.d.ts +32 -6
  29. package/types/src/calculation/executor/CalcExecutor.d.ts +204 -13
  30. package/types/src/calculation/executor/CalcExecutorUtils.d.ts +31 -0
  31. package/types/src/calculation/executor/CircularReference.d.ts +81 -0
  32. package/types/src/calculation/functions/Operators.d.ts +1 -1
  33. package/types/src/calculation/grid/CalcGrid.d.ts +5 -1
  34. package/types/src/calculation/grid/CalcGridUtils.d.ts +3 -2
  35. package/types/src/calculation/grid/ICalcGrid.d.ts +23 -1
  36. package/types/src/calculation/spatial/CircularEntry.d.ts +18 -0
  37. package/types/src/calculation/spatial/index.d.ts +1 -0
  38. package/types/src/calculation/state/CalcNode.d.ts +24 -17
  39. package/types/src/calculation/state/CalcState.d.ts +78 -15
  40. package/types/src/calculation/state/CalculationContext.d.ts +39 -0
  41. package/types/src/calculation/state/_ReadObservedGrid.d.ts +90 -0
  42. package/types/src/cell/ICell.d.ts +16 -0
  43. package/types/src/cellRange/ICellRange.d.ts +72 -6
  44. package/types/src/condition/AnchoredConditional.d.ts +26 -6
  45. package/types/src/conditionalFormat/ConditionalFormat.d.ts +8 -1
  46. package/types/src/conditionalFormat/IConditionalFormat.d.ts +4 -1
  47. package/types/src/conditionalFormat/IConditionalFormatCollection.d.ts +6 -2
  48. package/types/src/dataValidation/IDataValidationCollection.d.ts +6 -2
  49. package/types/src/hyperlink/IHyperlink.d.ts +3 -1
  50. package/types/src/hyperlink/_Hyperlink.d.ts +6 -0
  51. package/types/src/lib/utils/utils.browser.d.ts +5 -0
  52. package/types/src/license/LicenseDetails.d.ts +5 -0
  53. package/types/src/primitives/CalcSignal.d.ts +20 -0
  54. package/types/src/protectedRange/IProtectedRangeCollection.d.ts +7 -2
  55. package/types/src/scripting/_ScriptUtils.d.ts +13 -0
  56. package/types/src/sheet/Sheet.d.ts +33 -2
  57. package/types/src/sheet/SheetCell.d.ts +2 -0
  58. package/types/src/sheet/SheetRange.d.ts +12 -1
  59. package/types/src/sheet/_SheetStateTypes.d.ts +14 -1
  60. package/types/src/style/IStyle.d.ts +5 -0
  61. package/types/src/table/AnchoredTable.d.ts +17 -1
  62. package/types/src/text/TextUtils.d.ts +18 -0
  63. package/browser/cjs/DoemwsUQoGCk0vBK.cjs +0 -33
  64. package/browser/cjs/_c2uwwpr03Y7lzIj.cjs +0 -1
@@ -1 +0,0 @@
1
- const e=require("./DoemwsUQoGCk0vBK.cjs"),t=require("./CQf4zxkBmheTVbjX.cjs");let n=require("@sheetxl/primitives"),r=require("@sheetxl/utils");var i=[`All`,`Data`,`Headers`,`Totals`,`This Row`],a=class{constructor(n=e.tt){let r=function(e){let t=[...i];if(e)for(let n of Object.values(e)){let e=n?.trim();e&&!t.some(t=>t.toLowerCase()===e.toLowerCase())&&t.push(e)}return t.sort((e,t)=>t.length-e.length),t.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`)}(n.specifiers),a=t.a({name:`WhiteSpace`,pattern:/\s+/,group:t.o.SKIPPED}),o=t.a({name:`TableSpecifier`,pattern:RegExp(`\\[#(?:${r})\\]`,`i`)}),s=[a,o,t.a({name:`BracketedColumn`,pattern:/\[([^[\]]*)\]/,longer_alt:[o]}),t.a({name:`BareSpecifier`,pattern:RegExp(`#(?:${r})`,`i`)}),t.a({name:`ColumnSep`,pattern:/:/}),t.a({name:`ListSep`,pattern:new RegExp(n.separators.separatorFunction.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`))})];this._lexer=new t.o(s,{ensureOptimizations:!0});let c={};s.forEach(e=>{c[e.name]=e}),this._vocabulary=c}getVocabulary(){return this._vocabulary}tokenize(e){return this._lexer.tokenize(e)}},o=class extends t.n{constructor(t=e.tt){let n=new a(t),r=n.getVocabulary();super(r,{nodeLocationTracking:`none`,maxLookahead:2,skipValidations:!0,recoveryEnabled:!1}),this._lexer=n;let{TableSpecifier:i,BracketedColumn:o,BareSpecifier:s,ColumnSep:c,ListSep:l}=r,u=this;u.RULE(`ruleContent`,()=>{let e=[],t=u.SUBRULE(u.ruleItem);return u.ACTION(()=>{t&&e.push(t)}),u.MANY(()=>{u.CONSUME(l),u.OPTION(()=>{let t=u.SUBRULE2(u.ruleItem);u.ACTION(()=>{t&&e.push(t)})})}),e}),u.RULE(`ruleItem`,()=>u.OR([{ALT:()=>u.SUBRULE(u.ruleSpecifier)},{ALT:()=>u.SUBRULE(u.ruleColumnOrRange)}])),u.RULE(`ruleSpecifier`,()=>u.OR([{ALT:()=>{let n=u.CONSUME(i);return u.ACTION(()=>{let r=e.Z(n.image,t);return r.image=n.image,r})}},{ALT:()=>{let n=u.CONSUME(s);return u.ACTION(()=>{let r=e.Z(n.image,t);return r.image=n.image,r})}}])),u.RULE(`ruleColumnOrRange`,()=>{let t=u.CONSUME(o),n,r;return u.OPTION(()=>{n=u.CONSUME(c),r=u.CONSUME2(o)}),u.ACTION(()=>{let i=e.Y(t.image);if(i.image=t.image,!r)return i;let a=e.Y(r.image);a.image=r.image;let o=e.L(`:`,i,a,!0);return o.image=n?.image??`:`,o})}),u.performSelfAnalysis()}_parseInner(e){let t=this._lexer.tokenize(e);return t.errors.length>0||t.tokens.length===0?[]:(this.input=t.tokens,this.reset(),this.ruleContent()??[])}_parseContent(t){if(!t)return[];let n=t.trim();if(!n)return[];let r=n[0];if(r===`@`){let t=n.slice(1).trim();if(!t){let t=e.W(`@`,null,!0);return t.image=`@`,[t]}let r=e.Y(t);r.image=t;let i=e.W(`@`,r,!0);return i.image=`@`,[i]}if(r!==`[`&&r!==`#`){let n=e.Y(t);return n.image=t,[n]}return this._parseInner(n)}parse(t,n,r){let i=()=>({root:e.X(``,[]),errors:[]});if(!r)return i();let a=r.indexOf(`[`);if(a===-1)return i();let o=r.slice(0,a),s=r.slice(a+1,-1),c=this._parseContent(s);return{root:e.X(o,c),errors:this.errors.length>0?[...this.errors]:[]}}},s=new Set([`:`,`.:.`,`.:`,`:.`]),c=new Set([`.:.`,`.:`,`:.`]),l=t=>{if(!t)return null;if(t.type===e.et.Cell){let e=t.value;return e.rowIndex===-(2**53-1)?`col`:e.colIndex===-(2**53-1)?`row`:null}return Number.isInteger(t.value)?`row`:null},u=(e,t)=>{let n=parseInt(e.charCodeAt(0)===36?e.substring(1):e,10);return n>=1&&n<=t},d=`A formula must not be empty`;function f(e,t){let n=e?.[0]?.image;if(!n){let e=t?.image;return e?`Expected a value after '${e}'`:`Expected a value`}return`Unexpected '${n}'`}var p={...t.r,buildNoViableAltMessage:e=>f(e.actual,e.previous),buildEarlyExitMessage:e=>f(e.actual,e.previous),buildNotAllInputParsedMessage:e=>{let n=e.firstRedundant?.image;return n?`Unexpected '${n}'`:t.r.buildNotAllInputParsedMessage(e)},buildMismatchTokenMessage:e=>{let n=e.actual?.image;return e.expected===t.i&&n?`Unexpected '${n}'`:t.r.buildMismatchTokenMessage(e)}},m=class extends t.n{constructor(n){let r=n?.lexer??t.t.shared(n?.lexerOptions),i=r.getVocabulary();super(i,{skipValidations:!0,recoveryEnabled:!0,...n,nodeLocationTracking:`full`,errorMessageProvider:p,maxLookahead:1}),this._ruleInfixOp=this.RULE(`ruleInfixOp`,()=>{let{PlusOp:t,MinOp:n,MulOp:r,DivOp:i,ExOp:a,ConcatOp:o,GtOp:s,EqOp:c,LtOp:l,NeqOp:u,GteOp:d,LteOp:f}=this._vocab,p=[];return p.push({node:this.SUBRULE(this._rulePostfixOp)}),this.MANY(()=>{let m=this.OR(this._c1||=[{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image},{ALT:()=>this.CONSUME(r).image},{ALT:()=>this.CONSUME(i).image},{ALT:()=>this.CONSUME(a).image},{ALT:()=>this.CONSUME(o).image},{ALT:()=>this.CONSUME(s).image},{ALT:()=>this.CONSUME(c).image},{ALT:()=>this.CONSUME(l).image},{ALT:()=>this.CONSUME(u).image},{ALT:()=>this.CONSUME(d).image},{ALT:()=>this.CONSUME(f).image}]),h={value:m,index:this.getLexerPosition(),isRange:e.Q.includes(m)},g=this.SUBRULE2(this._rulePostfixOp);p.push({op:h,node:g})}),this.ACTION(()=>{let t=p.length-1,n=e.k.length;for(let r=0;t>0&&r<n;r++){let n=e.k[r],i=1;for(;i<p.length;){let r=p[i].op;if(n.includes(r.value)){let n=p[i-1].node,a=p[i].node,o=e.L(r.value,n,a,r.isRange);o=this._tag(o,r.index),p[i-1].node=o,p.splice(i,1),t--}else i++}}}),p[0].node}),this._rulePlusMinusOp=this.RULE(`rulePlusMinusOp`,()=>{let{PlusOp:e,MinOp:t}=this._vocab;return this.OR([{ALT:()=>this.CONSUME(e)},{ALT:()=>this.CONSUME(t)}])}),this._rulePostfixOp=this.RULE(`rulePostfixOp`,()=>{let{PercentOp:t,ArrayAnchorOp:n}=this._vocab,r=this.SUBRULE(this._rulePrefixOp),i=[];return this.MANY(()=>{let e=this.OR([{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image}]);this.ACTION(()=>{i.push([e,this.getLexerPosition()])})}),this.ACTION(()=>{let t=i.length;if(t!==0)for(let n=0;n<t;n++){let t=i[n],a=t[0],o=t[1],s=e.Q.includes(a);r=e.U(a,r,s),r=this._tag(r,o)}}),r}),this._rulePrefixOp=this.RULE(`rulePrefixOp`,()=>{let{PlusOp:t,MinOp:n,ImplicitIntersectOp:r}=this._vocab,i=[];this.MANY(()=>{let e=this.OR([{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image},{ALT:()=>this.CONSUME(r).image}]);this.ACTION(()=>{i.push([e,this.getLexerPosition()])})});let a=this.SUBRULE(this._ruleRangeOp);return this.ACTION(()=>{let t=i.length;if(t!==0)for(let n=t-1;n>=0;n--){let t=i[n],r=t[0],o=t[1],s=e.Q.includes(r);a=e.W(r,a,s),a=this._tag(a,o)}}),a}),this._ruleRangeOp=this.RULE(`ruleRangeOp`,()=>{let{RangeOp:t,RangeTrimFullOp:n,RangeTrimLeadingOp:r,RangeTrimTrailingOp:i}=this._vocab,a=[];return a.push({node:this.SUBRULE(this._ruleCallOp)}),this.MANY(()=>{let e={value:this.OR(this._c2||=[{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image},{ALT:()=>this.CONSUME(r).image},{ALT:()=>this.CONSUME(i).image}]),index:this.getLexerPosition()},o=this.SUBRULE2(this._ruleCallOp);a.push({op:e,node:o})}),this.ACTION(()=>{for(let t=1;t<a.length;t++){let n=a[t].op,r=e.L(n.value,a[0].node,a[t].node,!0);r=this._tag(r,n.index),a[0].node=r}}),a[0].node}),this._ruleCallOp=this.RULE(`ruleCallOp`,()=>{let{OpenParen:t,CloseParen:n}=this._vocab,r=this.SUBRULE(this._ruleFormula);return this.MANY({GATE:()=>{let e=this.LA(0),n=this.LA(1);return!(!e||!n||n.tokenType!==t)&&n.startOffset===e.endOffset+1},DEF:()=>{this.CONSUME(t);let i=this.getLexerPosition(),a=this.SUBRULE(this._ruleFunctionArguments),o=r,s=this.ACTION(()=>this._tag(e.M(o,a),i)),c=this.OPTION(()=>this.CONSUME(n));this.ACTION(()=>{c||this._reportError(s,`Missing closing parenthesis ')'`,i),this._tagClose(s,this.getLexerPosition()),r=s})}}),r}),this._ruleIntersectOp=this.RULE(`ruleIntersectOp`,()=>{let t=[this.SUBRULE(this._ruleInfixOp)];return this.MANY(()=>{this.OPTION({GATE:()=>{let e=this.LA(0);return this.LA(1).startOffset>e.endOffset+1},DEF:()=>{t.push(this.SUBRULE3(this._ruleInfixOp))}})}),this.ACTION(()=>{for(;t.length>1;){let n=t.length-1;for(let r=0;r<n;r++){let i=t[r],a=t[r+1],o=e.L(` `,i,a,!0),s=this._tokenMap.get(i);s&&delete s.tokenIndexClose;let c=this._tokenMap.get(a),l=c?.tokenIndex;if(l!==void 0){let e=this.input[l],t=this.input[l-1]?.endOffset??-1,n=this._inputText.slice(t+1,e.startOffset).slice(0,-1);n.length>0&&(o.wsBefore=n)}c&&delete c.tokenIndex,r+1<n&&c&&delete c.tokenIndexClose,t.splice(r,2,o),r--,n--}}}),t[0]}),this._ruleFormula=this.RULE(`ruleFormula`,()=>this.OR9([{ALT:()=>this.SUBRULE(this._ruleLiteral)},{ALT:()=>this.SUBRULE(this._ruleReference)},{ALT:()=>this.SUBRULE(this._ruleFunction)},{ALT:()=>this.SUBRULE(this._ruleParen)},{ALT:()=>this.SUBRULE(this._ruleTableReference)},{ALT:()=>this.SUBRULE(this._ruleBracketedString)},{ALT:()=>this.SUBRULE(this._ruleLiteralArray)}])),this._ruleGroup=this.RULE(`ruleGroup`,()=>{let{ArgSeparator:e}=this._vocab,t=[];return this.MANY(()=>{this.CONSUME(e);let n=this.SUBRULE2(this._ruleIntersectOp);this.ACTION(()=>{t.push(n)})}),t}),this._ruleParen=this.RULE(`ruleParen`,()=>{let{OpenParen:t,CloseParen:n}=this._vocab;return this._processParen(e.et.Paren,t,n)}),this._ruleLiteralArray=this.RULE(`ruleLiteralArray`,()=>{let{OpenCurlyParen:t,CloseCurlyParen:n,ColSeparator:r,RowSeparator:i}=this._vocab,a=e.B();this.CONSUME(t);let o=this.getLexerPosition(),s=this.ACTION(()=>this._tag(e.R(a),o)),c=this.SUBRULE(this._ruleLiteralForArray);this.ACTION(()=>{a.value.push(c)}),this.MANY(()=>{let t=!1;this.OR([{ALT:()=>{this.CONSUME(r),t=!0}},{ALT:()=>this.CONSUME(i)}]);let n=this.SUBRULE2(this._ruleLiteralForArray);this.ACTION(()=>{t||(a=e.B(),s.value.push(a)),a.value.push(n)})});let l=this.OPTION(()=>this.CONSUME(n));return s=this.ACTION(()=>(l||this._reportError(s,`Missing closing parenthesis '}'`,o),this._tagClose(s,this.getLexerPosition()))),s}),this._ruleLiteralForArray=this.RULE(`ruleLiteralForArray`,()=>{let{StringToken:t,BooleanToken:n,LiteralError:r,RefError:i}=this._vocab;return this.OR([{ALT:()=>{let t=this.OPTION(()=>this.SUBRULE(this._rulePlusMinusOp)),n=this.SUBRULE(this._ruleNumber),r=this.ACTION(()=>this._tag(e.H(n.image,this._locale),this.getLexerPosition()));return this.ACTION(()=>t?e.G(t.image,r):r)}},{ALT:()=>{let n=this.CONSUME(t);return this.ACTION(()=>this._tag(e.J(n.image),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(n);return this.ACTION(()=>this._tag(e.j(t.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(r);return this.ACTION(()=>this._tag(e.z(t.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(i);return this.ACTION(()=>this._tag(e.K(t.image,this._locale),this.getLexerPosition()))}}])}),this._ruleLiteral=this.RULE(`ruleLiteral`,()=>{let{StringToken:t,BooleanToken:n,LiteralError:r,RefError:i}=this._vocab;return this.OR([{ALT:()=>{let t=this.SUBRULE(this._ruleNumber);return this.ACTION(()=>this._tag(e.H(t.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let n=this.CONSUME(t);return this.ACTION(()=>this._tag(e.J(n.image),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(n);return this.ACTION(()=>this._tag(e.j(t.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(r);return this.ACTION(()=>this._tag(e.z(t.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(i);return this.ACTION(()=>this._tag(e.K(t.image,this._locale),this.getLexerPosition()))}}])}),this._ruleFunction=this.RULE(`ruleFunction`,()=>{let{FunctionToken:t,OpenParen:n,CloseParen:r}=this._vocab,i=this.CONSUME(t).image,a=this.getLexerPosition();this.CONSUME(n);let o=this.SUBRULE(this._ruleFunctionArguments),s=this.ACTION(()=>this._tag(e.I(i,o),a)),c=this.OPTION(()=>this.CONSUME(r));return s=this.ACTION(()=>(c||this._reportError(s,`Missing closing parenthesis ')'`,a),this._tagClose(s,this.getLexerPosition()))),s}),this._ruleFunctionArguments=this.RULE(`ruleFunctionArguments`,()=>{let{ArgSeparator:t,CloseParen:n}=this._vocab,r=[];return this.OPTION({GATE:()=>this.LA(1).tokenType!==n,DEF:()=>{let n;this.OPTION2(()=>{n=this.SUBRULE(this._ruleIntersectOp)}),n=this.ACTION(()=>n??this._tagClose(e.F(),this.getLexerPosition())),r.push(n),this.MANY(()=>{let n;this.CONSUME(t),this.OPTION3(()=>{n=this.SUBRULE2(this._ruleIntersectOp)}),n=this.ACTION(()=>n??this._tagClose(e.F(),this.getLexerPosition())),r.push(n)})}}),r}),this._ruleBracketedString=this.RULE(`ruleBracketedString`,()=>{let{BracketedString:e}=this._vocab,t=this.CONSUME(e),n=this.getLexerPosition();return this.ACTION(()=>{let e=this._srParser.parse(this.rowIndex,this.colIndex,t.image);for(let t of e.errors)this._astErrors.push(t);return this._tag(e.root,n)})}),this._ruleTableReference=this.RULE(`ruleTableReference`,()=>{let{TableReference:e}=this._vocab,t=this.CONSUME(e),n=this.getLexerPosition();return this.ACTION(()=>{let e=this._srParser.parse(this.rowIndex,this.colIndex,t.image);for(let t of e.errors)this._astErrors.push(t);return this._tag(e.root,n)})}),this._ruleReference=this.RULE(`ruleReference`,()=>{let{Sheet:t,SheetQuoted:n,DivOp:r,MulOp:i,PlusOp:a,MinOp:o,ArgSeparator:s,Cell:c,ArrayAnchorOp:l,NamedToken:u,SingleQuotedString:d,Column:f,AbsRow:p,DigitToken:m,RefError:h}=this._vocab,g;this.OPTION2({GATE:()=>{for(let e=1;e<6;e++){let c=this.LA(e);if(c.tokenType===t||c.tokenType===n)return!0;if(c.image===``||c.image===`)`||c.tokenType===r||c.tokenType===i||c.tokenType===a||c.tokenType===o||c.tokenType===s)break}return!1},DEF:()=>{g=this.SUBRULE(this._rulePrefixSheetName)}});let _=this.OR([{ALT:()=>{let t=this.CONSUME(c),n=this.getLexerPosition(),r=this.OPTION(()=>this.CONSUME(l));return this.ACTION(()=>{let i=this._tag(e.N(t.image,this.rowIndex,this.colIndex),n);return r?this._tag(e.U(`#`,i,!0),n):i})}},{ALT:()=>{let t=this.OR2([{ALT:()=>this.CONSUME(u)},{ALT:()=>this.CONSUME(d)}]);return this.ACTION(()=>this._tag(e.V(t.image),this.getLexerPosition()))}},{ALT:()=>this.SUBRULE(this._ruleBracketedString)},{ALT:()=>this.SUBRULE(this._ruleFunction)},{ALT:()=>{let t=this.CONSUME(f);return this.ACTION(()=>this._tag(e.P(t.image,this.colIndex),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(p);return this.ACTION(()=>this._tag(e.q(t.image,this.rowIndex),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(m);return this.ACTION(()=>this._tag(e.q(t.image,this.rowIndex),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(h);return this.ACTION(()=>this._tag(e.K(t.image,this._locale),this.getLexerPosition()))}}]);return this.ACTION(()=>{if(g&&_){if(g.name===``)return void this._reportError(_,`'${g.image}' is not a valid sheet reference — a '!' needs a sheet name before it`);let t=_;_.type===e.et.Postfix&&_.inputs?.[0]&&(t=_.inputs[0]),t.type!==e.et.Cell&&t.type!==e.et.Named&&t.type!==e.et.Row&&t.type!==e.et.TableColumn&&t.type!==e.et.Error||(t.value.scope=g.name,t.value.scopeImage=g.image)}}),_}),this._rulePrefixSheetName=this.RULE(`rulePrefixSheetName`,()=>{let{SheetQuoted:e,BracketedString:t,NamedToken:n,RangeOp:r,Sheet:i}=this._vocab;return this.OR([{ALT:()=>{let t=this.CONSUME(e).image;return{name:t.slice(1,-2).replace(/''/g,`'`),image:t}}},{ALT:()=>{let e=``;this.OPTION(()=>{e+=this.CONSUME(t).image}),this.OPTION2({GATE:()=>this.LA(2).tokenType===r,DEF:()=>{e+=this.CONSUME(n).image,this.CONSUME(r),e+=`:`}});let a=this.CONSUME(i).image;return{name:e+a.slice(0,-1),image:e+a}}}])}),this._ruleNumber=this.RULE(`ruleNumber`,()=>{let{NumberToken:e,ScientificDigit:t,DigitToken:n}=this._vocab;return this.OR([{ALT:()=>this.CONSUME(e)},{ALT:()=>this.CONSUME(t)},{ALT:()=>this.CONSUME(n)}])}),this._ruleRoot=this.RULE(`ruleRoot`,()=>{let{ArgSeparator:t}=this._vocab,n=this.SUBRULE(this._ruleIntersectOp),r=[];return this.MANY(()=>{this.CONSUME(t),r.push(this.SUBRULE2(this._ruleIntersectOp))}),this.ACTION(()=>r.length===0?n:{type:e.et.List,value:`,`,inputs:[n,...r],isReference:!0})}),this._lexer=r,this._locale=r.getLocale(),this._vocab=i,this._srParser=n?.srParser??new o(this._locale),this.performSelfAnalysis()}getLexer(){return this._lexer}parse(t,r,i,a){let o=this._lexer.tokenize(i),f;if(!o)return{root:{type:e.et.Unparsed,value:i},errors:[]};let p=o.tokens;if(p.length===0)throw new n.FormulaError.Parse(d);return this.input=p,this._inputText=i,this._inputTextLength=i.length,this.rowIndex=t,this.colIndex=r,this._astErrors=[],this._tokenMap=new Map,this.reset(),f=this._ruleRoot(),f&&this._bindAllWhitespace(f),f=e.$(f,(n,r)=>{let i=n.type,a=r?.isReference?r.value:void 0,o=typeof a==`string`&&s.has(a),d=typeof a==`string`&&c.has(a),f=o?r.inputs:void 0,p=f?f[0]===n?f[1]:f[0]:void 0,m=this._lexer.getMaxRow();if(o&&i!==e.et.Cell&&Number.isInteger(n.value)){let r=e.q(n.image,t);return e.A(r,n),l(p)===`row`?u(n.image,m)||this._reportError(r,`'${n.image}' is not a valid row — rows run from 1 to ${m}`):this._reportError(r,`'${n.image}' is not a valid reference — a whole row can only pair with another row (as in ${n.image}:${n.image})`),r}if(d&&i===e.et.Named)return this._reportError(n,`'${n.image??n.value?.nameId}' is a name — '${a}' needs a cell or range on both sides`),n;if(i===e.et.Cell){let t=n.value,r=t.colIndex===-(2**53-1),i=t.rowIndex===-(2**53-1);if((r||i)&&l(p)===(r?`row`:`col`))return r&&!u(n.image,m)&&this._reportError(n,`'${n.image}' is not a valid row — rows run from 1 to ${m}`),n;if(r||i||t.colIndex>=16384){let o=e.V(n.image);e.A(o,n);let s=t.scope;return s&&(o.value.scope=s,o.value.scopeImage=t.scopeImage),r?this._reportError(o,`'${n.image}' is not a valid reference — a row needs a column (use ${n.image}:${n.image} for the whole row)`):i&&n.image.includes(`$`)?this._reportError(o,`'${n.image}' is not a valid reference — a whole column can only pair with another column (as in ${n.image}:${n.image})`):d&&this._reportError(o,`'${n.image}' is a name — '${a}' needs a cell or range on both sides`),o}}return n}),a&&f&&(f=e.g(f,a,null)),{root:f,errors:[...this.errors,...this._astErrors]}}_processParen(e,t,n){let r;this.CONSUME(t);let i=this.getLexerPosition();r=this.ACTION(()=>(r={type:e,value:null,inputs:null},this._tag(r,i)));let a=[],o=this.SUBRULE(this._ruleIntersectOp);o&&a.push(o);let s=this.SUBRULE(this._ruleGroup),c=this.OPTION(()=>this.CONSUME(n));return r=this.ACTION(()=>{if(s)for(let e=0;e<s.length;e++)a.push(s[e]);return r&&(c||this._reportError(r,`Missing closing parenthesis`,i),r.inputs=a),this._tagClose(r,this.getLexerPosition())}),r}_reportError(e,t,n=void 0,r=`SyntaxError`){n===void 0&&(n=this.getLexerPosition()),e.error=!0,this._astErrors.push({name:r,message:t,previousToken:this.input[n],ast:e})}_tag(e,t){return e?(e.image??=this.input[t].image,this._tokenMap.set(e,{tokenIndex:t,tokenIndexClose:t}),e):(console.warn(`node is null`),e)}_tagClose(e,t){let n=this._tokenMap.get(e);return n?n.tokenIndexClose=t:this._tokenMap.set(e,{tokenIndexClose:t}),e}_bindNodeWhitespace(e){let t=this._tokenMap.get(e);if(!t)return;let n=this.input,r=this._inputText,i=t.tokenIndex;if(i!==void 0){let t=n[i],a=n[i-1]?.endOffset??-1;a+1<t.startOffset&&(e.wsBefore=r.slice(a+1,t.startOffset))}let a=t.tokenIndexClose;if(a!==void 0){let t=n[a],i=n[a+1]?.startOffset??this._inputTextLength;t.endOffset+1<i&&(e.wsAfter=r.slice(t.endOffset+1,i))}}_bindAllWhitespace(t){if(t){if(this._bindNodeWhitespace(t),t.inputs)for(let e of t.inputs)e&&this._bindAllWhitespace(e);if(t.type===e.et.Array&&Array.isArray(t.value)){for(let e of t.value)if(e&&Array.isArray(e.value))for(let t of e.value)t&&this._bindAllWhitespace(t)}}}};exports.FormulaCompiler=class{constructor(e){e={...e},this._editing=e.profile===`editing`,this._parser=new m(e)}compile(t,r,i,a,o,s,c,l){if(a.length===0){let e=new n.FormulaError.Parse(d);return this._compileUnparsed(t,o,a,{input:a,cause:e,causes:[e]})}if(a.length>e.nt.MAX_EXPRESSION_LENGTH){let r=new n.FormulaError.Parse((u=a.length,`A formula must not be longer than ${e.nt.MAX_EXPRESSION_LENGTH} characters (this one is ${u})`));return this._compileUnparsed(t,o,a,{input:a,cause:r,causes:[r]})}var u;let f,p,m=[];try{let e=this._parser.parse(r,i,a,l);f=e.root,m=e.errors}catch(e){p=n.FormulaError.isError(e,n.FormulaError.Code.Parse)?e:new n.FormulaError.Parse(e.message,e)}let h=[];for(let t of m)h.push(e.T(t));if(f){e.C(f,s??null)&&h.push(new n.FormulaError.Parse(`The implicit intersection operator ' ' requires a cell or range on both sides`)),e.w(f,s??null)&&h.push(new n.FormulaError.Parse(`Expected a reference; a value cannot be converted to one.`));let t=e.y(f,s??null);t&&h.push(new n.FormulaError.Parse(t));let r=e.b(f,s??null);r&&h.push(new n.FormulaError.Parse(r));let i=e.x(f,s??null);i&&h.push(new n.FormulaError.Parse(i));let a=e.S(f);a&&h.push(new n.FormulaError.Parse(a))}h.length>0&&!p&&(p=h[0]);let g=null;if(p&&(g={input:a,cause:p,causes:h.length>0?h:[p]}),!f){if(this._editing){let e=this._recoverCompiled(t,r,i,a,o,g,c);if(e)return e}return this._compileUnparsed(t,o,a,g)}f=e.D(f,s??null),f=e._(f,s??null),o&&(f=e.E(f,o,c));let _=e.v(t,o,f,this._editing,g,s??null);return this._editing&&g&&e.O(_.getTokens(),o)!==a?this._recoverCompiled(t,r,i,a,o,g,c)||this._compileUnparsed(t,o,a,g):_}autoCorrect(e){let t;try{let n=this._parser.getLexer().tokenize(e,!1);if(n.errors.length>0)return null;t=n.tokens}catch{return null}let n=[];for(let e of t){let t=e.tokenType?.name;if(t===`OpenParen`)n.push(`)`);else if(t===`OpenCurlyParen`)n.push(`}`);else if((t===`CloseParen`||t===`CloseCurlyParen`)&&n.pop()!==(t===`CloseParen`?`)`:`}`))return null}return n.length===0?null:e+n.reverse().join(``)}_compileUnparsed(t,n,i,a){let o={runtime:t,symbols:n,getFunction:null,ast:null,evaluations:r.CommonUtils.EmptyArray,executions:r.CommonUtils.EmptyArray,bindings:r.CommonUtils.EmptyArray,referencesAbsolute:r.CommonUtils.EmptyArray,referencesExecute:r.CommonUtils.EmptyArray,referencesRelative:r.CommonUtils.EmptyArray,referencesRoot:r.CommonUtils.EmptyArray,referenceIndices:r.CommonUtils.EmptyArray,getTokens:()=>[{type:e.et.Unparsed,value:i,text:i}],namedIds:r.CommonUtils.EmptyArray,symbolIds:r.CommonUtils.EmptyArray,hasTotals:!1,isReferenceOnly:!1,error:a,transform:()=>o};return o}_recoverCompiled(t,n,r,i,a,o,s){let c,l=i.length;try{let e=this._parser.getLexer().tokenize(i,!1);c=e.tokens,e.errors.length>0&&(l=Math.min(l,e.errors[0].offset))}catch{return null}let u=[];for(let e=c.length-1;e>=0&&u.length<24;e--){let t=(c[e].endOffset??-1)+1;t>0&&t<i.length&&t<=l&&u.push(t)}for(let c of u){let l=i.slice(0,c),u,d;try{u=this._parser.parse(n,r,l).root}catch{continue}if(!u||u.type===e.et.Unparsed)continue;try{let n=e._(u,null),r=a?e.E(n,a,s):n;d=e.v(t,a,r,!0,o)}catch{continue}if(e.O(d.getTokens(),a)!==l)continue;let f=i.slice(c);if(f.length===0)return d;let p,m={...d,getTokens:()=>(p||(p=[...d.getTokens()],this._appendUnparsedTail(p,f)),p),transform:()=>m};return m}return null}_appendUnparsedTail(t,n){let r=[];for(let n of t)n.type===e.et.Paren&&n.text===`(`?r.push({ctx:n.context,argIndex:0}):n.type===e.et.Paren&&n.text===`)`?r.pop():n.type===e.et.Separator&&r.length>0&&r[r.length-1].argIndex++;let i=r.length>0?r[r.length-1]:void 0,a=i?.ctx?{...i.ctx,argIndex:i.ctx.argIndex===-1?i.argIndex:i.ctx.argIndex}:void 0,o=(n,r)=>{let i={type:e.et.Unparsed,value:n,text:n};a&&(i.context=a),r&&(i.isLookup=!0),t.push(i)},s=/[A-Za-z_][A-Za-z0-9_]*$/.exec(n),c=s?s.index:-1;c>=0&&(c===0||!/[A-Za-z0-9_.]/.test(n[c-1]))?(c>0&&o(n.slice(0,c)),o(n.slice(c),!0)):o(n)}};