hyperformula
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
60 lines • 537 kB
JavaScript
/*!
* Copyright (c) HANDSONCODE sp. z o. o.
*
* HYPERFORMULA is a software distributed by HANDSONCODE sp. z o. o., a
* Polish corporation based in Gdynia, Poland, at Aleja Zwyciestwa 96-98,
* registered by the District Court in Gdansk under number 538651,
* EU VAT: PL5862294002, share capital: PLN 62,800.00.
*
* This software is dual-licensed, giving you the option to use it under
* either a proprietary license or the GNU General Public License version 3
* (GPLv3). The specific license under which you use the software is
* determined by the license key you apply. Each licensing option comes with
* its own terms and conditions as specified below.
*
* 1. PROPRIETARY LICENSE:
*
* Your use of this software is subject to the terms included in an
* applicable proprietary license agreement between you and HANDSONCODE.
* The proprietary license can be purchased from HANDSONCODE or an
* authorized reseller.
*
* 2. GNU GENERAL PUBLIC LICENSE v3:
*
* This software is also available under the terms of the GNU General
* Public License v3. You are permitted to run, modify, and distribute
* this software under the terms of the GPLv3, as published by the Free
* Software Foundation. The full text of the GPLv3 can be found at
* https://www.gnu.org/licenses/.
*
* UNLESS EXPRESSLY AGREED OTHERWISE, HANDSONCODE PROVIDES THIS SOFTWARE ON
* AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, AND IN NO
* EVENT AND UNDER NO LEGAL THEORY, SHALL HANDSONCODE BE LIABLE TO YOU FOR
* DAMAGES, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM USE OR INABILITY TO
* USE THIS SOFTWARE.
*
* Version: 2.7.1
* Release date: 18/07/2024 (built at 18/07/2024 11:23:26)
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("chevrotain"),require("tiny-emitter")):"function"==typeof define&&define.amd?define("HyperFormula",["chevrotain","tiny-emitter"],t):"object"==typeof exports?exports.HyperFormula=t(require("chevrotain"),require("tiny-emitter")):e.HyperFormula=t(e.chevrotain,e.TinyEmitter)}("undefined"!=typeof self?self:this,(function(e,t){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";t.__esModule=!0,t.default=void 0;var n=r(1);t.ArraySize=n.ArraySize;var s=r(73);t.CellError=s.CellError,t.CellType=s.CellType,t.CellValueDetailedType=s.CellValueDetailedType,t.CellValueType=s.CellValueType,t.ErrorType=s.ErrorType;var a=r(128);t.DetailedCellError=a.DetailedCellError;var o=r(129),i=r(133);t.AlwaysDense=i.AlwaysDense,t.AlwaysSparse=i.AlwaysSparse,t.DenseSparseChooseBasedOnThreshold=i.DenseSparseChooseBasedOnThreshold;var u=r(105);t.ConfigValueTooBigError=u.ConfigValueTooBigError,t.ConfigValueTooSmallError=u.ConfigValueTooSmallError,t.EvaluationSuspendedError=u.EvaluationSuspendedError,t.ExpectedOneOfValuesError=u.ExpectedOneOfValuesError,t.ExpectedValueOfTypeError=u.ExpectedValueOfTypeError,t.FunctionPluginValidationError=u.FunctionPluginValidationError,t.InvalidAddressError=u.InvalidAddressError,t.InvalidArgumentsError=u.InvalidArgumentsError,t.LanguageAlreadyRegisteredError=u.LanguageAlreadyRegisteredError,t.LanguageNotRegisteredError=u.LanguageNotRegisteredError,t.MissingTranslationError=u.MissingTranslationError,t.NamedExpressionDoesNotExistError=u.NamedExpressionDoesNotExistError,t.NamedExpressionNameIsAlreadyTakenError=u.NamedExpressionNameIsAlreadyTakenError,t.NamedExpressionNameIsInvalidError=u.NamedExpressionNameIsInvalidError,t.NoOperationToRedoError=u.NoOperationToRedoError,t.NoOperationToUndoError=u.NoOperationToUndoError,t.NoRelativeAddressesAllowedError=u.NoRelativeAddressesAllowedError,t.NoSheetWithIdError=u.NoSheetWithIdError,t.NoSheetWithNameError=u.NoSheetWithNameError,t.NotAFormulaError=u.NotAFormulaError,t.NothingToPasteError=u.NothingToPasteError,t.ProtectedFunctionTranslationError=u.ProtectedFunctionTranslationError,t.SheetNameAlreadyTakenError=u.SheetNameAlreadyTakenError,t.SheetSizeLimitExceededError=u.SheetSizeLimitExceededError,t.SourceLocationHasArrayError=u.SourceLocationHasArrayError,t.TargetLocationHasArrayError=u.TargetLocationHasArrayError,t.UnableToParseError=u.UnableToParseError;var l=r(156);t.ExportedCellChange=l.ExportedCellChange,t.ExportedNamedExpressionChange=l.ExportedNamedExpressionChange;var h=r(138);t.HyperFormula=h.HyperFormula;var d,c=(d=r(174))&&d.__esModule?d:{default:d},p=r(124);t.FunctionPlugin=p.FunctionPlugin,t.FunctionArgumentType=p.FunctionArgumentType,t.EmptyValue=p.EmptyValue;var m=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var r=E(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},s=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if("default"!==a&&{}.hasOwnProperty.call(e,a)){var o=s?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(n,a,o):n[a]=e[a]}return n.default=e,r&&r.set(e,n),n}(r(175)),g=r(97);function E(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(E=function(e){return e?r:t})(e)}t.SimpleRangeValue=g.SimpleRangeValue;
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class T extends h.HyperFormula{}T.HyperFormula=h.HyperFormula,T.ErrorType=s.ErrorType,T.CellError=s.CellError,T.CellType=s.CellType,T.CellValueType=s.CellValueType,T.CellValueDetailedType=s.CellValueDetailedType,T.DetailedCellError=a.DetailedCellError,T.ExportedCellChange=l.ExportedCellChange,T.ExportedNamedExpressionChange=l.ExportedNamedExpressionChange,T.ConfigValueTooBigError=u.ConfigValueTooBigError,T.ConfigValueTooSmallError=u.ConfigValueTooSmallError,T.EvaluationSuspendedError=u.EvaluationSuspendedError,T.ExpectedOneOfValuesError=u.ExpectedOneOfValuesError,T.ExpectedValueOfTypeError=u.ExpectedValueOfTypeError,T.ArraySize=n.ArraySize,T.SimpleRangeValue=g.SimpleRangeValue,T.EmptyValue=p.EmptyValue,T.FunctionPlugin=p.FunctionPlugin,T.FunctionArgumentType=p.FunctionArgumentType,T.FunctionPluginValidationError=u.FunctionPluginValidationError,T.InvalidAddressError=u.InvalidAddressError,T.InvalidArgumentsError=u.InvalidArgumentsError,T.LanguageNotRegisteredError=u.LanguageNotRegisteredError,T.LanguageAlreadyRegisteredError=u.LanguageAlreadyRegisteredError,T.MissingTranslationError=u.MissingTranslationError,T.NamedExpressionDoesNotExistError=u.NamedExpressionDoesNotExistError,T.NamedExpressionNameIsAlreadyTakenError=u.NamedExpressionNameIsAlreadyTakenError,T.NamedExpressionNameIsInvalidError=u.NamedExpressionNameIsInvalidError,T.NoOperationToRedoError=u.NoOperationToRedoError,T.NoOperationToUndoError=u.NoOperationToUndoError,T.NoRelativeAddressesAllowedError=u.NoRelativeAddressesAllowedError,T.NoSheetWithIdError=u.NoSheetWithIdError,T.NoSheetWithNameError=u.NoSheetWithNameError,T.NotAFormulaError=u.NotAFormulaError,T.NothingToPasteError=u.NothingToPasteError,T.ProtectedFunctionTranslationError=u.ProtectedFunctionTranslationError,T.SheetNameAlreadyTakenError=u.SheetNameAlreadyTakenError,T.SheetSizeLimitExceededError=u.SheetSizeLimitExceededError,T.SourceLocationHasArrayError=u.SourceLocationHasArrayError,T.TargetLocationHasArrayError=u.TargetLocationHasArrayError,T.UnableToParseError=u.UnableToParseError;const y=o.Config.defaultConfig.language;h.HyperFormula.registerLanguage(y,c.default),h.HyperFormula.languages[c.default.langCode]=c.default;for(const e of Object.getOwnPropertyNames(m))e.startsWith("_")||h.HyperFormula.registerFunctionPlugin(m[e]);t.default=T},function(e,t,r){"use strict";t.__esModule=!0,t.ArraySizePredictor=t.ArraySize=void 0,r(2);var n=r(72),s=r(123),a=r(124),o=r(77);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class i{constructor(e,t,r=!1){this.width=e,this.height=t,this.isRef=r}static error(){return new i(1,1,!0)}static scalar(){return new i(1,1,!1)}isScalar(){return 1===this.width&&1===this.height||this.isRef}}t.ArraySize=i;t.ArraySizePredictor=class{constructor(e,t){this.config=e,this.functionRegistry=t}checkArraySize(e,t){return this.checkArraySizeForAst(e,{formulaAddress:t,arraysFlag:this.config.useArrayArithmetic})}checkArraySizeForAst(e,t){switch(e.type){case o.AstNodeType.FUNCTION_CALL:return this.checkArraySizeForFunction(e,t);case o.AstNodeType.COLUMN_RANGE:case o.AstNodeType.ROW_RANGE:case o.AstNodeType.CELL_RANGE:{const r=n.AbsoluteCellRange.fromAstOrUndef(e,t.formulaAddress);return void 0===r?i.error():new i(r.width(),r.height(),!0)}case o.AstNodeType.ARRAY:{const r=[],n=[];for(const s of e.args){const e=s.map(e=>this.checkArraySizeForAst(e,t)),a=Math.min(...e.map(e=>e.height)),o=e.reduce((e,t)=>e+t.width,0);r.push(a),n.push(o)}const s=r.reduce((e,t)=>e+t,0),a=Math.min(...n);return new i(a,s)}case o.AstNodeType.STRING:case o.AstNodeType.NUMBER:return i.scalar();case o.AstNodeType.CELL_REFERENCE:return new i(1,1,!0);case o.AstNodeType.DIV_OP:case o.AstNodeType.CONCATENATE_OP:case o.AstNodeType.EQUALS_OP:case o.AstNodeType.GREATER_THAN_OP:case o.AstNodeType.GREATER_THAN_OR_EQUAL_OP:case o.AstNodeType.LESS_THAN_OP:case o.AstNodeType.LESS_THAN_OR_EQUAL_OP:case o.AstNodeType.MINUS_OP:case o.AstNodeType.NOT_EQUAL_OP:case o.AstNodeType.PLUS_OP:case o.AstNodeType.POWER_OP:case o.AstNodeType.TIMES_OP:{const r=this.checkArraySizeForAst(e.left,t),n=this.checkArraySizeForAst(e.right,t);return!t.arraysFlag&&(r.height>1||r.width>1||n.height>1||n.width>1)?i.error():(s=r,a=n,new i(Math.max(s.width,a.width),Math.max(s.height,a.height)))}case o.AstNodeType.MINUS_UNARY_OP:case o.AstNodeType.PLUS_UNARY_OP:case o.AstNodeType.PERCENT_OP:{const n=this.checkArraySizeForAst(e.value,t);return!t.arraysFlag&&(n.height>1||n.width>1)?i.error():new i((r=n).width,r.height)}case o.AstNodeType.PARENTHESIS:return this.checkArraySizeForAst(e.expression,t);case o.AstNodeType.EMPTY:default:return i.error()}var r,s,a}checkArraySizeForFunction(e,t){const r=this.functionRegistry.getArraySizeFunction(e.procedureName);if(void 0!==r)return r(e,t);const n=this.functionRegistry.getMetadata(e.procedureName);if(void 0===n||n.expandRanges||!t.arraysFlag||n.vectorizationForbidden||void 0===n.parameters)return new i(1,1);const o=e.args.map(e=>{var r;return this.checkArraySizeForAst(e,new s.InterpreterState(t.formulaAddress,t.arraysFlag||null!==(r=null==n?void 0:n.arrayFunction)&&void 0!==r&&r))}),u=[...n.parameters];if(void 0!==n.repeatLastArgs&&u.length<o.length&&(o.length-u.length)%n.repeatLastArgs!=0)return i.error();for(;u.length<o.length;){if(void 0===n.repeatLastArgs)return i.error();u.push(...u.slice(u.length-n.repeatLastArgs))}let l=1,h=1;for(let e=0;e<o.length;e++)u[e].argumentType!==a.FunctionArgumentType.RANGE&&u[e].argumentType!==a.FunctionArgumentType.ANY&&(h=Math.max(h,o[e].height),l=Math.max(l,o[e].width));return new i(l,h)}}},function(e,t,r){"use strict";var n=r(3),s=r(40),a=r(64),o=r(69),i=r(71);n({target:"Array",proto:!0,arity:1,forced:r(8)((function(){return 4294967297!==[].push.call({length:4294967296},1)}))||!function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(e){return e instanceof TypeError}}()},{push:function(e){var t=s(this),r=a(t),n=arguments.length;i(r+n);for(var u=0;u<n;u++)t[r]=arguments[u],r++;return o(t,r),r}})},function(e,t,r){"use strict";var n=r(4),s=r(6).f,a=r(44),o=r(48),i=r(38),u=r(56),l=r(68);e.exports=function(e,t){var r,h,d,c,p,m=e.target,g=e.global,E=e.stat;if(r=g?n:E?n[m]||i(m,{}):n[m]&&n[m].prototype)for(h in t){if(c=t[h],d=e.dontCallGetSet?(p=s(r,h))&&p.value:r[h],!l(g?h:m+(E?".":"#")+h,e.forced)&&void 0!==d){if(typeof c==typeof d)continue;u(c,d)}(e.sham||d&&d.sham)&&a(c,"sham",!0),o(r,h,c,e)}}},function(e,t,r){"use strict";(function(t){var r=function(e){return e&&e.Math===Math&&e};e.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||r("object"==typeof this&&this)||function(){return this}()||Function("return this")()}).call(this,r(5))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";var n=r(7),s=r(9),a=r(11),o=r(12),i=r(13),u=r(19),l=r(39),h=r(42),d=Object.getOwnPropertyDescriptor;t.f=n?d:function(e,t){if(e=i(e),t=u(t),h)try{return d(e,t)}catch(e){}if(l(e,t))return o(!s(a.f,e,t),e[t])}},function(e,t,r){"use strict";var n=r(8);e.exports=!n((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))},function(e,t,r){"use strict";e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t,r){"use strict";var n=r(10),s=Function.prototype.call;e.exports=n?s.bind(s):function(){return s.apply(s,arguments)}},function(e,t,r){"use strict";var n=r(8);e.exports=!n((function(){var e=function(){}.bind();return"function"!=typeof e||e.hasOwnProperty("prototype")}))},function(e,t,r){"use strict";var n={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,a=s&&!n.call({1:2},1);t.f=a?function(e){var t=s(this,e);return!!t&&t.enumerable}:n},function(e,t,r){"use strict";e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,r){"use strict";var n=r(14),s=r(17);e.exports=function(e){return n(s(e))}},function(e,t,r){"use strict";var n=r(15),s=r(8),a=r(16),o=Object,i=n("".split);e.exports=s((function(){return!o("z").propertyIsEnumerable(0)}))?function(e){return"String"===a(e)?i(e,""):o(e)}:o},function(e,t,r){"use strict";var n=r(10),s=Function.prototype,a=s.call,o=n&&s.bind.bind(a,a);e.exports=n?o:function(e){return function(){return a.apply(e,arguments)}}},function(e,t,r){"use strict";var n=r(15),s=n({}.toString),a=n("".slice);e.exports=function(e){return a(s(e),8,-1)}},function(e,t,r){"use strict";var n=r(18),s=TypeError;e.exports=function(e){if(n(e))throw new s("Can't call method on "+e);return e}},function(e,t,r){"use strict";e.exports=function(e){return null==e}},function(e,t,r){"use strict";var n=r(20),s=r(23);e.exports=function(e){var t=n(e,"string");return s(t)?t:t+""}},function(e,t,r){"use strict";var n=r(9),s=r(21),a=r(23),o=r(30),i=r(33),u=r(34),l=TypeError,h=u("toPrimitive");e.exports=function(e,t){if(!s(e)||a(e))return e;var r,u=o(e,h);if(u){if(void 0===t&&(t="default"),r=n(u,e,t),!s(r)||a(r))return r;throw new l("Can't convert object to primitive value")}return void 0===t&&(t="number"),i(e,t)}},function(e,t,r){"use strict";var n=r(22);e.exports=function(e){return"object"==typeof e?null!==e:n(e)}},function(e,t,r){"use strict";var n="object"==typeof document&&document.all;e.exports=void 0===n&&void 0!==n?function(e){return"function"==typeof e||e===n}:function(e){return"function"==typeof e}},function(e,t,r){"use strict";var n=r(24),s=r(22),a=r(25),o=r(26),i=Object;e.exports=o?function(e){return"symbol"==typeof e}:function(e){var t=n("Symbol");return s(t)&&a(t.prototype,i(e))}},function(e,t,r){"use strict";var n=r(4),s=r(22),a=function(e){return s(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?a(n[e]):n[e]&&n[e][t]}},function(e,t,r){"use strict";var n=r(15);e.exports=n({}.isPrototypeOf)},function(e,t,r){"use strict";var n=r(27);e.exports=n&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},function(e,t,r){"use strict";var n=r(28),s=r(8),a=r(4).String;e.exports=!!Object.getOwnPropertySymbols&&!s((function(){var e=Symbol("symbol detection");return!a(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&n&&n<41}))},function(e,t,r){"use strict";var n,s,a=r(4),o=r(29),i=a.process,u=a.Deno,l=i&&i.versions||u&&u.version,h=l&&l.v8;h&&(s=(n=h.split("."))[0]>0&&n[0]<4?1:+(n[0]+n[1])),!s&&o&&(!(n=o.match(/Edge\/(\d+)/))||n[1]>=74)&&(n=o.match(/Chrome\/(\d+)/))&&(s=+n[1]),e.exports=s},function(e,t,r){"use strict";e.exports="undefined"!=typeof navigator&&String(navigator.userAgent)||""},function(e,t,r){"use strict";var n=r(31),s=r(18);e.exports=function(e,t){var r=e[t];return s(r)?void 0:n(r)}},function(e,t,r){"use strict";var n=r(22),s=r(32),a=TypeError;e.exports=function(e){if(n(e))return e;throw new a(s(e)+" is not a function")}},function(e,t,r){"use strict";var n=String;e.exports=function(e){try{return n(e)}catch(e){return"Object"}}},function(e,t,r){"use strict";var n=r(9),s=r(22),a=r(21),o=TypeError;e.exports=function(e,t){var r,i;if("string"===t&&s(r=e.toString)&&!a(i=n(r,e)))return i;if(s(r=e.valueOf)&&!a(i=n(r,e)))return i;if("string"!==t&&s(r=e.toString)&&!a(i=n(r,e)))return i;throw new o("Can't convert object to primitive value")}},function(e,t,r){"use strict";var n=r(4),s=r(35),a=r(39),o=r(41),i=r(27),u=r(26),l=n.Symbol,h=s("wks"),d=u?l.for||l:l&&l.withoutSetter||o;e.exports=function(e){return a(h,e)||(h[e]=i&&a(l,e)?l[e]:d("Symbol."+e)),h[e]}},function(e,t,r){"use strict";var n=r(36);e.exports=function(e,t){return n[e]||(n[e]=t||{})}},function(e,t,r){"use strict";var n=r(37),s=r(4),a=r(38),o=e.exports=s["__core-js_shared__"]||a("__core-js_shared__",{});(o.versions||(o.versions=[])).push({version:"3.37.1",mode:n?"pure":"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE",source:"https://github.com/zloirock/core-js"})},function(e,t,r){"use strict";e.exports=!1},function(e,t,r){"use strict";var n=r(4),s=Object.defineProperty;e.exports=function(e,t){try{s(n,e,{value:t,configurable:!0,writable:!0})}catch(r){n[e]=t}return t}},function(e,t,r){"use strict";var n=r(15),s=r(40),a=n({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(s(e),t)}},function(e,t,r){"use strict";var n=r(17),s=Object;e.exports=function(e){return s(n(e))}},function(e,t,r){"use strict";var n=r(15),s=0,a=Math.random(),o=n(1..toString);e.exports=function(e){return"Symbol("+(void 0===e?"":e)+")_"+o(++s+a,36)}},function(e,t,r){"use strict";var n=r(7),s=r(8),a=r(43);e.exports=!n&&!s((function(){return 7!==Object.defineProperty(a("div"),"a",{get:function(){return 7}}).a}))},function(e,t,r){"use strict";var n=r(4),s=r(21),a=n.document,o=s(a)&&s(a.createElement);e.exports=function(e){return o?a.createElement(e):{}}},function(e,t,r){"use strict";var n=r(7),s=r(45),a=r(12);e.exports=n?function(e,t,r){return s.f(e,t,a(1,r))}:function(e,t,r){return e[t]=r,e}},function(e,t,r){"use strict";var n=r(7),s=r(42),a=r(46),o=r(47),i=r(19),u=TypeError,l=Object.defineProperty,h=Object.getOwnPropertyDescriptor;t.f=n?a?function(e,t,r){if(o(e),t=i(t),o(r),"function"==typeof e&&"prototype"===t&&"value"in r&&"writable"in r&&!r.writable){var n=h(e,t);n&&n.writable&&(e[t]=r.value,r={configurable:"configurable"in r?r.configurable:n.configurable,enumerable:"enumerable"in r?r.enumerable:n.enumerable,writable:!1})}return l(e,t,r)}:l:function(e,t,r){if(o(e),t=i(t),o(r),s)try{return l(e,t,r)}catch(e){}if("get"in r||"set"in r)throw new u("Accessors not supported");return"value"in r&&(e[t]=r.value),e}},function(e,t,r){"use strict";var n=r(7),s=r(8);e.exports=n&&s((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))},function(e,t,r){"use strict";var n=r(21),s=String,a=TypeError;e.exports=function(e){if(n(e))return e;throw new a(s(e)+" is not an object")}},function(e,t,r){"use strict";var n=r(22),s=r(45),a=r(49),o=r(38);e.exports=function(e,t,r,i){i||(i={});var u=i.enumerable,l=void 0!==i.name?i.name:t;if(n(r)&&a(r,l,i),i.global)u?e[t]=r:o(t,r);else{try{i.unsafe?e[t]&&(u=!0):delete e[t]}catch(e){}u?e[t]=r:s.f(e,t,{value:r,enumerable:!1,configurable:!i.nonConfigurable,writable:!i.nonWritable})}return e}},function(e,t,r){"use strict";var n=r(15),s=r(8),a=r(22),o=r(39),i=r(7),u=r(50).CONFIGURABLE,l=r(51),h=r(52),d=h.enforce,c=h.get,p=String,m=Object.defineProperty,g=n("".slice),E=n("".replace),T=n([].join),y=i&&!s((function(){return 8!==m((function(){}),"length",{value:8}).length})),f=String(String).split("String"),A=e.exports=function(e,t,r){"Symbol("===g(p(t),0,7)&&(t="["+E(p(t),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),r&&r.getter&&(t="get "+t),r&&r.setter&&(t="set "+t),(!o(e,"name")||u&&e.name!==t)&&(i?m(e,"name",{value:t,configurable:!0}):e.name=t),y&&r&&o(r,"arity")&&e.length!==r.arity&&m(e,"length",{value:r.arity});try{r&&o(r,"constructor")&&r.constructor?i&&m(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch(e){}var n=d(e);return o(n,"source")||(n.source=T(f,"string"==typeof t?t:"")),e};Function.prototype.toString=A((function(){return a(this)&&c(this).source||l(this)}),"toString")},function(e,t,r){"use strict";var n=r(7),s=r(39),a=Function.prototype,o=n&&Object.getOwnPropertyDescriptor,i=s(a,"name"),u=i&&"something"===function(){}.name,l=i&&(!n||n&&o(a,"name").configurable);e.exports={EXISTS:i,PROPER:u,CONFIGURABLE:l}},function(e,t,r){"use strict";var n=r(15),s=r(22),a=r(36),o=n(Function.toString);s(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},function(e,t,r){"use strict";var n,s,a,o=r(53),i=r(4),u=r(21),l=r(44),h=r(39),d=r(36),c=r(54),p=r(55),m=i.TypeError,g=i.WeakMap;if(o||d.state){var E=d.state||(d.state=new g);E.get=E.get,E.has=E.has,E.set=E.set,n=function(e,t){if(E.has(e))throw new m("Object already initialized");return t.facade=e,E.set(e,t),t},s=function(e){return E.get(e)||{}},a=function(e){return E.has(e)}}else{var T=c("state");p[T]=!0,n=function(e,t){if(h(e,T))throw new m("Object already initialized");return t.facade=e,l(e,T,t),t},s=function(e){return h(e,T)?e[T]:{}},a=function(e){return h(e,T)}}e.exports={set:n,get:s,has:a,enforce:function(e){return a(e)?s(e):n(e,{})},getterFor:function(e){return function(t){var r;if(!u(t)||(r=s(t)).type!==e)throw new m("Incompatible receiver, "+e+" required");return r}}}},function(e,t,r){"use strict";var n=r(4),s=r(22),a=n.WeakMap;e.exports=s(a)&&/native code/.test(String(a))},function(e,t,r){"use strict";var n=r(35),s=r(41),a=n("keys");e.exports=function(e){return a[e]||(a[e]=s(e))}},function(e,t,r){"use strict";e.exports={}},function(e,t,r){"use strict";var n=r(39),s=r(57),a=r(6),o=r(45);e.exports=function(e,t,r){for(var i=s(t),u=o.f,l=a.f,h=0;h<i.length;h++){var d=i[h];n(e,d)||r&&n(r,d)||u(e,d,l(t,d))}}},function(e,t,r){"use strict";var n=r(24),s=r(15),a=r(58),o=r(67),i=r(47),u=s([].concat);e.exports=n("Reflect","ownKeys")||function(e){var t=a.f(i(e)),r=o.f;return r?u(t,r(e)):t}},function(e,t,r){"use strict";var n=r(59),s=r(66).concat("length","prototype");t.f=Object.getOwnPropertyNames||function(e){return n(e,s)}},function(e,t,r){"use strict";var n=r(15),s=r(39),a=r(13),o=r(60).indexOf,i=r(55),u=n([].push);e.exports=function(e,t){var r,n=a(e),l=0,h=[];for(r in n)!s(i,r)&&s(n,r)&&u(h,r);for(;t.length>l;)s(n,r=t[l++])&&(~o(h,r)||u(h,r));return h}},function(e,t,r){"use strict";var n=r(13),s=r(61),a=r(64),o=function(e){return function(t,r,o){var i=n(t),u=a(i);if(0===u)return!e&&-1;var l,h=s(o,u);if(e&&r!=r){for(;u>h;)if((l=i[h++])!=l)return!0}else for(;u>h;h++)if((e||h in i)&&i[h]===r)return e||h||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},function(e,t,r){"use strict";var n=r(62),s=Math.max,a=Math.min;e.exports=function(e,t){var r=n(e);return r<0?s(r+t,0):a(r,t)}},function(e,t,r){"use strict";var n=r(63);e.exports=function(e){var t=+e;return t!=t||0===t?0:n(t)}},function(e,t,r){"use strict";var n=Math.ceil,s=Math.floor;e.exports=Math.trunc||function(e){var t=+e;return(t>0?s:n)(t)}},function(e,t,r){"use strict";var n=r(65);e.exports=function(e){return n(e.length)}},function(e,t,r){"use strict";var n=r(62),s=Math.min;e.exports=function(e){var t=n(e);return t>0?s(t,9007199254740991):0}},function(e,t,r){"use strict";e.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},function(e,t,r){"use strict";t.f=Object.getOwnPropertySymbols},function(e,t,r){"use strict";var n=r(8),s=r(22),a=/#|\.prototype\./,o=function(e,t){var r=u[i(e)];return r===h||r!==l&&(s(t)?n(t):!!t)},i=o.normalize=function(e){return String(e).replace(a,".").toLowerCase()},u=o.data={},l=o.NATIVE="N",h=o.POLYFILL="P";e.exports=o},function(e,t,r){"use strict";var n=r(7),s=r(70),a=TypeError,o=Object.getOwnPropertyDescriptor,i=n&&!function(){if(void 0!==this)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}();e.exports=i?function(e,t){if(s(e)&&!o(e,"length").writable)throw new a("Cannot set read only .length");return e.length=t}:function(e,t){return e.length=t}},function(e,t,r){"use strict";var n=r(16);e.exports=Array.isArray||function(e){return"Array"===n(e)}},function(e,t,r){"use strict";var n=TypeError;e.exports=function(e){if(e>9007199254740991)throw n("Maximum allowed index exceeded");return e}},function(e,t,r){"use strict";t.__esModule=!0,t.WRONG_RANGE_SIZE=t.AbsoluteRowRange=t.AbsoluteColumnRange=t.AbsoluteCellRange=void 0,t.isSimpleCellRange=function(e){return!(!e||"object"!=typeof e&&"function"!=typeof e)&&("start"in e&&(0,n.isSimpleCellAddress)(e.start)&&"end"in e&&(0,n.isSimpleCellAddress)(e.end))},t.simpleCellRange=void 0,r(2);var n=r(73),s=r(105),a=r(77),o=r(99);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
const i=t.WRONG_RANGE_SIZE="AbsoluteCellRange: Wrong range size";t.simpleCellRange=(e,t)=>({start:e,end:t});class u{constructor(e,t){if(e.sheet!==t.sheet)throw new s.SheetsNotEqual(e.sheet,t.sheet);this.start=(0,n.simpleCellAddress)(e.sheet,e.col,e.row),this.end=(0,n.simpleCellAddress)(t.sheet,t.col,t.row)}get sheet(){return this.start.sheet}static fromSimpleCellAddresses(e,t){if(e.sheet!==t.sheet)throw new s.SheetsNotEqual(e.sheet,t.sheet);const r=t.col-e.col,n=t.row-e.row;return Number.isFinite(n)&&Number.isFinite(r)?new u(e,t):Number.isFinite(n)?new h(e.sheet,e.row,t.row):new l(e.sheet,e.col,t.col)}static fromAst(e,t){return e.type===a.AstNodeType.CELL_RANGE?u.fromCellRange(e,t):e.type===a.AstNodeType.COLUMN_RANGE?l.fromColumnRange(e,t):h.fromRowRangeAst(e,t)}static fromAstOrUndef(e,t){try{return u.fromAst(e,t)}catch(e){return}}static fromCellRange(e,t){return new u(e.start.toSimpleCellAddress(t),e.end.toSimpleCellAddress(t))}static spanFrom(e,t,r){const n=u.spanFromOrUndef(e,t,r);if(void 0===n)throw new Error(i);return n}static spanFromOrUndef(e,t,r){if(!Number.isFinite(t)&&Number.isFinite(r)){if(0!==e.col)return;return new h(e.sheet,e.row,e.row+r-1)}if(!Number.isFinite(r)&&Number.isFinite(t)){if(0!==e.row)return;return new l(e.sheet,e.col,e.col+t-1)}if(Number.isFinite(r)&&Number.isFinite(t))return new u(e,(0,n.simpleCellAddress)(e.sheet,e.col+t-1,e.row+r-1))}static fromCoordinates(e,t,r,s,a){return new u((0,n.simpleCellAddress)(e,t,r),(0,n.simpleCellAddress)(e,s,a))}isFinite(){return Number.isFinite(this.size())}doesOverlap(e){return this.start.sheet==e.start.sheet&&(!(this.end.row<e.start.row||this.start.row>e.end.row)&&!(this.end.col<e.start.col||this.start.col>e.end.col))}addressInRange(e){return this.sheet===e.sheet&&(this.start.row<=e.row&&this.end.row>=e.row&&this.start.col<=e.col&&this.end.col>=e.col)}columnInRange(e){return this.sheet===e.sheet&&(this.start.col<=e.col&&this.end.col>=e.col)}rowInRange(e){return this.sheet===e.sheet&&(this.start.row<=e.row&&this.end.row>=e.row)}containsRange(e){return this.addressInRange(e.start)&&this.addressInRange(e.end)}intersectionWith(e){if(this.sheet!==e.start.sheet)return;const t=Math.max(this.start.row,e.start.row),r=Math.min(this.end.row,e.end.row),s=Math.max(this.start.col,e.start.col),a=Math.min(this.end.col,e.end.col);return t>r||s>a?void 0:new u((0,n.simpleCellAddress)(this.sheet,s,t),(0,n.simpleCellAddress)(this.sheet,a,r))}includesRow(e){return this.start.row<e&&this.end.row>=e}includesColumn(e){return this.start.col<e&&this.end.col>=e}shiftByRows(e){this.start.row+=e,this.end.row+=e}expandByRows(e){this.end.row+=e}shiftByColumns(e){this.start.col+=e,this.end.col+=e}shifted(e,t){return u.spanFrom((0,n.simpleCellAddress)(this.sheet,this.start.col+e,this.start.row+t),this.width(),this.height())}expandByColumns(e){this.end.col+=e}moveToSheet(e){this.start.sheet=e,this.end.sheet=e}removeSpan(e){e instanceof o.RowsSpan?this.removeRows(e.start,e.end):this.removeColumns(e.start,e.end)}shouldBeRemoved(){return this.width()<=0||this.height()<=0}rangeWithSameWidth(e,t){return u.spanFrom((0,n.simpleCellAddress)(this.sheet,this.start.col,e),this.width(),t)}rangeWithSameHeight(e,t){return u.spanFrom((0,n.simpleCellAddress)(this.sheet,e,this.start.row),t,this.height())}toString(){return`${this.start.sheet},${this.start.col},${this.start.row},${this.end.col},${this.end.row}`}width(){return this.end.col-this.start.col+1}height(){return this.end.row-this.start.row+1}size(){return this.height()*this.width()}arrayOfAddressesInRange(){const e=[];for(let t=0;t<this.height();++t){e[t]=[];for(let r=0;r<this.width();++r){const s=(0,n.simpleCellAddress)(this.sheet,this.start.col+r,this.start.row+t);e[t].push(s)}}return e}withStart(e){return new u(e,this.end)}sameDimensionsAs(e){return this.width()===e.width()&&this.height()===e.height()}sameAs(e){return(0,n.equalSimpleCellAddress)(this.start,e.start)&&(0,n.equalSimpleCellAddress)(this.end,e.end)}addressesArrayMap(e,t){const r=[];let s=this.start.row;for(;s<=this.effectiveEndRow(e);){let a=this.start.col;const o=[];for(;a<=this.effectiveEndColumn(e);)o.push(t((0,n.simpleCellAddress)(this.start.sheet,a,s))),a++;r.push(o),s++}return r}addresses(e){const t=[];let r=this.start.row;const s=this.effectiveEndRow(e),a=this.effectiveEndColumn(e);for(;r<=s;){let e=this.start.col;for(;e<=a;)t.push((0,n.simpleCellAddress)(this.start.sheet,e,r)),e++;r++}return t}*addressesWithDirection(e,t,r){if(e>0)if(t>0){let e=this.effectiveEndRow(r);for(;e>=this.start.row;){let t=this.effectiveEndColumn(r);for(;t>=this.start.col;)yield(0,n.simpleCellAddress)(this.start.sheet,t,e),t-=1;e-=1}}else{let e=this.start.row;for(;e<=this.effectiveEndRow(r);){let t=this.effectiveEndColumn(r);for(;t>=this.start.col;)yield(0,n.simpleCellAddress)(this.start.sheet,t,e),t-=1;e+=1}}else if(t>0){let e=this.effectiveEndRow(r);for(;e>=this.start.row;){let t=this.start.col;for(;t<=this.effectiveEndColumn(r);)yield(0,n.simpleCellAddress)(this.start.sheet,t,e),t+=1;e-=1}}else{let e=this.start.row;for(;e<=this.effectiveEndRow(r);){let t=this.start.col;for(;t<=this.effectiveEndColumn(r);)yield(0,n.simpleCellAddress)(this.start.sheet,t,e),t+=1;e+=1}}}getAddress(e,t){if(e<0||t<0||t>this.height()-1||e>this.width()-1)throw Error("Index out of bound");return(0,n.simpleCellAddress)(this.start.sheet,this.start.col+e,this.start.row+t)}exceedsSheetSizeLimits(e,t){return this.end.col>=e||this.end.row>=t}effectiveEndColumn(e){return this.end.col}effectiveEndRow(e){return this.end.row}effectiveWidth(e){return this.width()}effectiveHeight(e){return this.height()}removeRows(e,t){if(!(e>this.end.row)){if(t<this.start.row){const r=t-e+1;return this.shiftByRows(-r)}e<=this.start.row&&(this.start.row=e),this.end.row-=Math.min(t,this.end.row)-e+1}}removeColumns(e,t){if(!(e>this.end.col)){if(t<this.start.col){const r=t-e+1;return this.shiftByColumns(-r)}e<=this.start.col&&(this.start.col=e),this.end.col-=Math.min(t,this.end.col)-e+1}}}t.AbsoluteCellRange=u;class l extends u{constructor(e,t,r){super((0,n.simpleCellAddress)(e,t,0),(0,n.simpleCellAddress)(e,r,Number.POSITIVE_INFINITY))}static fromColumnRange(e,t){const r=e.start.toSimpleColumnAddress(t),n=e.end.toSimpleColumnAddress(t);if(r.sheet!==n.sheet)throw new s.SheetsNotEqual(r.sheet,n.sheet);return new l(r.sheet,r.col,n.col)}shouldBeRemoved(){return this.width()<=0}shiftByRows(e){}expandByRows(e){}shifted(e,t){return new l(this.sheet,this.start.col+e,this.end.col+e)}rangeWithSameHeight(e,t){return new l(this.sheet,e,e+t-1)}exceedsSheetSizeLimits(e,t){return this.end.col>=e}effectiveEndRow(e){return this.effectiveHeight(e)-1}effectiveHeight(e){return e.getSheetHeight(this.sheet)}removeRows(e,t){}}t.AbsoluteColumnRange=l;class h extends u{constructor(e,t,r){super((0,n.simpleCellAddress)(e,0,t),(0,n.simpleCellAddress)(e,Number.POSITIVE_INFINITY,r))}static fromRowRangeAst(e,t){const r=e.start.toSimpleRowAddress(t),n=e.end.toSimpleRowAddress(t);if(r.sheet!==n.sheet)throw new s.SheetsNotEqual(r.sheet,n.sheet);return new h(r.sheet,r.row,n.row)}shouldBeRemoved(){return this.height()<=0}shiftByColumns(e){}expandByColumns(e){}shifted(e,t){return new h(this.sheet,this.start.row+t,this.end.row+t)}rangeWithSameWidth(e,t){return new h(this.sheet,e,e+t-1)}exceedsSheetSizeLimits(e,t){return this.end.row>=t}effectiveEndColumn(e){return this.effectiveWidth(e)-1}effectiveWidth(e){return e.getSheetWidth(this.sheet)}removeColumns(e,t){}}t.AbsoluteRowRange=h},function(e,t,r){"use strict";t.__esModule=!0,t.invalidSimpleRowAddress=t.invalidSimpleColumnAddress=t.invalidSimpleCellAddress=t.getCellValueType=t.getCellValueFormat=t.getCellValueDetailedType=t.getCellType=t.equalSimpleCellAddress=t.addressKey=t.absoluteSheetReference=t.ErrorType=t.CellValueTypeOrd=t.CellValueType=t.CellValueNoNumber=t.CellValueJustNumber=t.CellValueDetailedType=t.CellType=t.CellError=void 0,t.isSimpleCellAddress=function(e){var t,r,n;return e&&("object"==typeof e||"function"==typeof e)&&"number"==typeof(null===(t=e)||void 0===t?void 0:t.sheet)&&"number"==typeof(null===(r=e)||void 0===r?void 0:r.col)&&"number"==typeof(null===(n=e)||void 0===n?void 0:n.row)},t.simpleRowAddress=t.simpleColumnAddress=t.simpleCellAddress=t.movedSimpleCellAddress=void 0;var n,s,a=r(74),o=r(89),i=r(98),u=r(97);!function(e){e.DIV_BY_ZERO="DIV_BY_ZERO",e.NAME="NAME",e.VALUE="VALUE",e.NUM="NUM",e.NA="NA",e.CYCLE="CYCLE",e.REF="REF",e.SPILL="SPILL",e.LIC="LIC",e.ERROR="ERROR"}(n||(t.ErrorType=n={})),function(e){e.FORMULA="FORMULA",e.VALUE="VALUE",e.ARRAY="ARRAY",e.EMPTY="EMPTY",e.ARRAYFORMULA="ARRAYFORMULA"}(s||(t.CellType=s={}));var l,h;t.getCellType=(e,t)=>e instanceof a.ArrayVertex?e.isLeftCorner(t)?s.ARRAYFORMULA:s.ARRAY:e instanceof a.FormulaCellVertex||e instanceof a.ParsingErrorVertex?s.FORMULA:e instanceof a.ValueCellVertex?s.VALUE:s.EMPTY,function(e){e.EMPTY="EMPTY",e.NUMBER="NUMBER",e.STRING="STRING",e.BOOLEAN="BOOLEAN",e.ERROR="ERROR"}(l||(t.CellValueNoNumber=l={})),function(e){e.NUMBER="NUMBER"}(h||(t.CellValueJustNumber=h={}));const d=t.CellValueType=Object.assign(Object.assign({},l),h);t.CellValueDetailedType=Object.assign(Object.assign({},l),i.NumberType);t.CellValueTypeOrd=e=>{switch(e){case d.EMPTY:return 0;case d.NUMBER:return 1;case d.STRING:return 2;case d.BOOLEAN:return 3;case d.ERROR:return 4}throw new Error("Cell value not computed")};const c=e=>{if(e===i.EmptyValue)return d.EMPTY;if(e instanceof p||e instanceof u.SimpleRangeValue)return d.ERROR;if("string"==typeof e)return d.STRING;if((0,i.isExtendedNumber)(e))return d.NUMBER;if("boolean"==typeof e)return d.BOOLEAN;throw new Error("Cell value not computed")};t.getCellValueType=c;t.getCellValueDetailedType=e=>(0,i.isExtendedNumber)(e)?(0,i.getTypeOfExtendedNumber)(e):c(e);t.getCellValueFormat=e=>(0,i.isExtendedNumber)(e)?(0,i.getFormatOfExtendedNumber)(e):void 0;class p{constructor(e,t,r){this.type=e,this.message=t,this.root=r}static parsingError(e){return new p(n.ERROR,`${o.ErrorMessage.ParseError}${e?" "+e:""}`)}attachRootVertex(e){return void 0===this.root?new p(this.type,this.message,e):this}}t.CellError=p;t.simpleRowAddress=(e,t)=>({sheet:e,row:t});t.invalidSimpleRowAddress=e=>e.row<0;t.simpleColumnAddress=(e,t)=>({sheet:e,col:t});t.invalidSimpleColumnAddress=e=>e.col<0;const m=(e,t,r)=>({sheet:e,col:t,row:r});t.simpleCellAddress=m;t.invalidSimpleCellAddress=e=>e.col<0||e.row<0;t.movedSimpleCellAddress=(e,t,r,n)=>m(t,e.col+r,e.row+n);t.addressKey=e=>`${e.sheet},${e.row},${e.col}`;t.absoluteSheetReference=(e,t)=>{var r;return null!==(r=e.sheet)&&void 0!==r?r:t.sheet};t.equalSimpleCellAddress=(e,t)=>e.sheet===t.sheet&&e.col===t.col&&e.row===t.row},function(e,t,r){"use strict";t.__esModule=!0,t.ValueCellVertex=t.TopSort=t.SparseStrategy=t.SheetMapping=t.RangeVertex=t.RangeMapping=t.ParsingErrorVertex=t.Graph=t.FormulaCellVertex=t.EmptyCellVertex=t.DependencyGraph=t.DenseStrategy=t.ArrayVertex=t.ArrayMapping=t.AddressMapping=void 0;var n=r(75);t.DependencyGraph=n.DependencyGraph;var s=r(104);t.AddressMapping=s.AddressMapping;var a=r(111);t.Graph=a.Graph;var o=r(112);t.TopSort=o.TopSort;var i=r(114);t.RangeMapping=i.RangeMapping;var u=r(115);t.SheetMapping=u.SheetMapping;var l=r(106);t.ArrayMapping=l.ArrayMapping;var h=r(108);t.FormulaCellVertex=h.FormulaCellVertex,t.ArrayVertex=h.ArrayVertex;var d=r(118);t.EmptyCellVertex=d.EmptyCellVertex;var c=r(119);t.ValueCellVertex=c.ValueCellVertex;var p=r(120);t.ParsingErrorVertex=p.ParsingErrorVertex;var m=r(110);t.RangeVertex=m.RangeVertex;var g=r(121);t.SparseStrategy=g.SparseStrategy;var E=r(122);t.DenseStrategy=E.DenseStrategy},function(e,t,r){"use strict";t.__esModule=!0,t.DependencyGraph=void 0,r(2);var n=r(72),s=r(76),a=r(73),o=r(96),i=r(89),u=r(98),l=r(97),h=r(77),d=r(99),c=r(100),p=r(74),m=r(104),g=r(106),E=r(107),T=r(108),y=r(111),f=r(114),A=r(115);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class R{constructor(e,t,r,i,u,l,d,c){this.addressMapping=e,this.rangeMapping=t,this.sheetMapping=r,this.arrayMapping=i,this.stats=u,this.lazilyTransformingAstService=l,this.functionRegistry=d,this.namedExpressions=c,this.changes=o.ContentChanges.empty(),this.dependencyQueryAddresses=e=>{if(e instanceof p.RangeVertex)return this.rangeDependencyQuery(e).map(([e,t])=>e);{const t=this.formulaDependencyQuery(e);if(void 0!==t){const[e,r]=t;return r.map(t=>t instanceof h.NamedExpressionDependency?this.namedExpressions.namedExpressionOrPlaceholder(t.name,e.sheet).address:(0,a.isSimpleCellAddress)(t)?t:(0,n.simpleCellRange)(t.start,t.end))}return[]}},this.dependencyQueryVertices=e=>{if(e instanceof p.RangeVertex)return this.rangeDependencyQuery(e);{const t=this.formulaDependencyQuery(e);if(void 0!==t){const[e,r]=t;return r.map(t=>{if(t instanceof n.AbsoluteCellRange)return[t.start,this.rangeMapping.fetchRange(t.start,t.end)];if(t instanceof h.NamedExpressionDependency){const r=this.namedExpressions.namedExpressionOrPlaceholder(t.name,e.sheet);return[r.address,this.addressMapping.fetchCell(r.address)]}return[t,this.addressMapping.fetchCell(t)]})}return[]}},this.rangeDependencyQuery=e=>{const t=[],{smallerRangeVertex:r,restRange:s}=this.rangeMapping.findSmallerRange(e.range);let a;void 0!==r&&this.graph.adjacentNodes(r).has(e)?(a=s,t.push([new n.AbsoluteCellRange(r.start,r.end),r])):a=e.range;for(const e of a.addresses(this)){const r=this.addressMapping.getCell(e);void 0!==r&&t.push([e,r])}return t},this.formulaDependencyQuery=e=>{let t,r;if(!(e instanceof T.FormulaVertex))return;r=e.getAddress(this.lazilyTransformingAstService),t=e.getFormula(this.lazilyTransformingAstService);const n=(0,h.collectDependencies)(t,this.functionRegistry);return[r,(0,s.absolutizeDependencies)(n,r)]},this.graph=new y.Graph(this.dependencyQueryVertices)}static buildEmpty(e,t,r,n,s){return new R(new m.AddressMapping(t.chooseAddressMappingPolicy),new f.RangeMapping,new A.SheetMapping(t.translationPackage),new g.ArrayMapping,s,e,r,n)}setFormulaToCell(e,t,r,n,s,a){const o=T.FormulaVertex.fromAst(t,e,n,this.lazilyTransformingAstService.version());return this.exchangeOrAddFormulaVertex(o),this.processCellDependencies(r,o),this.graph.markNodeAsDirty(o),s&&this.markAsVolatile(o),a&&this.markAsDependentOnStructureChange(o),this.correctInfiniteRangesDependency(e),this.getAndClearContentChanges()}setParsingErrorToCell(e,t){const r=this.shrinkPossibleArrayAndGetCell(e);return this.exchangeOrAddGraphNode(r,t),this.addressMapping.setCell(e,t),this.graph.markNodeAsDirty(t),this.correctInfiniteRangesDependency(e),this.getAndClearContentChanges()}setValueToCell(e,t){const r=this.shrinkPossibleArrayAndGetCell(e);if(r instanceof p.ArrayVertex&&this.arrayMapping.removeArray(r.getRange()),r instanceof p.ValueCellVertex){r.getValues().rawValue!==t.rawValue&&(r.setValues(t),this.graph.markNodeAsDirty(r))}else{const n=new p.ValueCellVertex(t.parsedValue,t.rawValue);this.exchangeOrAddGraphNode(r,n),this.addressMapping.setCell(e,n),this.graph.markNodeAsDirty(n)}return this.correctInfiniteRangesDependency(e),this.getAndClearContentChanges()}setCellEmpty(e){const t=this.shrinkPossibleArrayAndGetCell(e);if(void 0===t)return o.ContentChanges.empty();if(this.graph.adjacentNodes(t).size>0){const r=new p.EmptyCellVertex;this.exchangeGraphNode(t,r),0===this.graph.adjacentNodesCount(r)?(this.removeVertex(r),this.addressMapping.removeCell(e)):(this.graph.markNodeAsDirty(r),this.addressMapping.setCell(e,r))}else this.removeVertex(t),this.addressMapping.removeCell(e);return this.getAndClearContentChanges()}clearDirtyVertices(){this.graph.clearDirtyNodes()}verticesToRecompute(){return this.graph.getDirtyAndVolatileNodes()}processCellDependencies(e,t){const r=this.graph.getNodeId(t);e.forEach(e=>{if(e instanceof n.AbsoluteCellRange){const t=e;let n=this.getRange(t.start,t.end);void 0===n&&(n=new p.RangeVertex(t),this.rangeMapping.setRange(n)),this.graph.addNodeAndReturnId(n);const s=this.graph.getNodeId(n);t.isFinite()||this.graph.markNodeAsInfiniteRange(s);const{smallerRangeVertex:a,restRange:o}=this.rangeMapping.findSmallerRange(t);if(void 0!==a){if(this.graph.addEdge(a,s),n.bruteForce){n.bruteForce=!1;for(const e of t.addresses(this))this.graph.removeEdge(this.fetchCell(e),s)}}else n.bruteForce=!0;const i=this.arrayMapping.getArray(o);if(void 0!==i)this.graph.addEdge(i,s);else for(const e of o.addresses(this)){const{vertex:t,id:r}=this.fetchCellOrCreateEmpty(e);this.graph.addEdge(null!=r?r:t,s)}this.graph.addEdge(s,r),t.isFinite()&&this.correctInfiniteRangesDependenciesByRangeVertex(n)}else if(e instanceof h.NamedExpressionDependency){const n=t.getAddress(this.lazilyTransformingAstService).sheet,{vertex:s,id:a}=this.fetchNamedExpressionVertex(e.name,n);this.graph.addEdge(null!=a?a:s,r)}else{const{vertex:t,id:n}=this.fetchCellOrCreateEmpty(e);this.graph.addEdge(null!=n?n:t,r)}})}fetchNamedExpressionVertex(e,t){const r=this.namedExpressions.namedExpressionOrPlaceholder(e,t);return this.fetchCellOrCreateEmpty(r.address)}exchangeNode(e,t){const r=this.fetchCellOrCreateEmpty(e).vertex,n=this.fetchCellOrCreateEmpty(t).vertex;this.addressMapping.removeCell(e),this.exchangeGraphNode(r,n)}fetchCellOrCreateEmpty(e){const t=this.addressMapping.getCell(e);if(void 0!==t)return{vertex:t,id:void 0};const r=new p.EmptyCellVertex,n=this.graph.addNodeAndReturnId(r);return this.addressMapping.setCell(e,r),{vertex:r,id:n}}removeRows(e){this.stats.measure(c.StatType.ADJUSTING_GRAPH,()=>{for(const[t,r]of this.addressMapping.entriesFromRowsSpan(e)){for(const e of this.graph.adjacentNodes(r))this.graph.markNodeAsDirty(e);if(r instanceof p.ArrayVertex){if(!r.isLeftCorner(t))continue;this.shrinkArrayToCorner(r),this.arrayMapping.removeArray(r.getRange())}this.removeVertex(r)}}),this.stats.measure(c.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.removeRows(e)});const t=this.stats.measure(c.StatType.ADJUSTING_RANGES,()=>{const t=this.truncateRanges(e,e=>e.row);return this.getArrayVerticesRelatedToRanges(t)});return this.stats.measure(c.StatType.ADJUSTING_ARRAY_MAPPING,()=>{this.fixArraysAfterRemovingRows(e.sheet,e.rowStart,e.numberOfRows)}),this.addStructuralNodesToChangeSet(),{affectedArrays:t,contentChanges:this.getAndClearContentChanges()}}removeSheet(e){this.clearSheet(e);for(const[t,r]of this.addressMapping.sheetEntries(e)){for(const e of this.graph.adjacentNodes(r))this.graph.markNodeAsDirty(e);this.removeVertex(r),this.addressMapping.removeCell(t)}this.stats.measure(c.StatType.ADJUSTING_RANGES,()=>{const t=this.rangeMapping.removeRangesInSheet(e);for(const e of t)this.removeVertex(e);this.stats.measure(c.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.removeSheet(e)})})}clearSheet(e){const t=new Set;for(const[r,n]of this.addressMapping.sheetEntries(e))n instanceof p.ArrayVertex?t.add(n):this.setCellEmpty(r);for(const e of t.values())this.setArrayEmpty(e);this.addStructuralNodesToChangeSet()}removeColumns(e){this.stats.measure(c.StatType.ADJUSTING_GRAPH,()=>{for(const[t,r]of this.addressMapping.entriesFromColumnsSpan(e)){for(const e of this.graph.adjacentNodes(r))this.graph.markNodeAsDirty(e);if(r instanceof p.ArrayVertex){if(!r.isLeftCorner(t))continue;this.shrinkArrayToCorner(r),this.arrayMapping.removeArray(r.getRange())}this.removeVertex(r)}}),this.stats.measure(c.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.removeColumns(e)});const t=this.stats.measure(c.StatType.ADJUSTING_RANGES,()=>{const t=this.truncateRanges(e,e=>e.col);return this.getArrayVerticesRelatedToRanges(t)});return this.stats.measure(c.StatType.ADJUSTING_ARRAY_MAPPING,()=>this.fixArraysAfterRemovingColumns(e.sheet,e.columnStart,e.numberOfColumns)),this.addStructuralNodesToChangeSet(),{affectedArrays:t,contentChanges:this.getAndClearContentChanges()}}addRows(e){this.stats.measure(c.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.addRows(e.sheet,e.rowStart,e.numberOfRows)});const t=this.stats.measure(c.StatType.ADJUSTING_RANGES,()=>{const t=this.rangeMapping.moveAllRangesInSheetAfterRowByRows(e.sheet,e.rowStart,e.numberOfRows);return this.fixRangesWhenAddingRows(e.sheet,e.rowStart,e.numberOfRows),this.getArrayVerticesRelatedToRanges(t.verticesWithChangedSize)});this.stats.measure(c.StatType.ADJUSTING_ARRAY_MAPPING,()=>{this.fixArraysAfterAddingRow(e.sheet,e.rowStart,e.numberOfRows)});for(const t of this.addressMapping.verticesFromRowsSpan(e))this.graph.markNodeAsDirty(t);return this.addStructuralNodesToChangeSet(),{affectedArrays:t}}addColumns(e){this.stats.measure(c.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.addColumns(e.sheet,e.columnStart,e.numberOfColumns)});const t=this.stats.measure(c.StatType.ADJUSTING_RANGES,()=>{const t=this.rangeMapping.moveAllRangesInSheetAfterColumnByColumns(e.sheet,e.columnStart,e.numberOfColumns);return this.fixRangesWhenAddingColumns(e.sheet,e.columnStart,e.numberOfColumns),this.getArrayVerticesRelatedToRanges(t.verticesWithChangedSize)});this.stats.measure(c.StatType.ADJUSTING_ARRAY_MAPPING,()=>this.fixArraysAfterAddingColumn(e.sheet,e.columnStart,e.numberOfColumns));for(const t of this.addressMapping.verticesFromColumnsSpan(e))this.graph.markNodeAsDirty(t);return this.addStructuralNodesToChangeSet(),{affectedArrays:t,contentChanges:this.getAndClearContentChanges()}}isThereSpaceForArray(e){const t=e.getRangeOrUndef();if(void 0===t)return!1;for(const r of t.addresses(this)){const t=this.addressMapping.getCell(r);if(void 0!==t&&!(t instanceof p.EmptyCellVertex)&&t!==e)return!1}return!0}moveCells(e,t,r,n){for(const s of e.addressesWithDirection(t,r,this)){const o=(0,a.simpleCellAddress)(n,s.col+t,s.row+r);let i=this.addressMapping.getCell(s);const u=this.addressMapping.getCell(o);if(this.addressMapping.removeCell(s),void 0!==i){this.graph.markNodeAsDirty(i),this.addressMapping.setCell(o,i);let t=void 0;for(const r of this.graph.adjacentNodes(i))r instanceof p.RangeVertex&&!e.containsRange(r.range)&&(t=null!=t?t:this.fetchCellOrCreateEmpty(s).vertex,this.graph.addEdge(t,r),this.graph.removeEdge(i,r));t&&(this.graph.markNodeAsDirty(t),this.addressMapping.setCell(s,t))}if(void 0!==u){void 0===i&&this.addressMapping.removeCell(o);for(const e of this.graph.adjacentNodes(u))i=null!=i?i:this.fetchCellOrCreateEmpty(o).vertex,this.graph.addEdge(i,e),this.graph.markNodeAsDirty(i);this.removeVertex(u)}}for(const t of this.rangeMapping.rangeVerticesContainedInRange(e))for(const r of this.graph.adjacentNodes(t))if(r instanceof p.RangeVertex&&!e.containsRange(r.range)){this.graph.removeEdge(t,r);for(const e of t.range.addresses(this)){const{vertex:t,id:n}=this.fetchCellOrCreateEmpty(e);this.graph.addEdge(null!=n?n:t,r),this.addressMapping.setCell(e,t),this.graph.markNodeAsDirty(t)}}this.rangeMapping.moveRangesInsideSourceRange(e,t,r,n)}setArrayEmpty(e){const t=n.AbsoluteCellRange.spanFrom(e.getAddress(this.lazilyTransformingAstService),e.width,e.height),r=this.graph.adjacentNodes(e);for(const e of t.addresses(this))this.addressMapping.removeCell(e);for(const t of r.values()){const r=(0,E.collectAddressesDependentToRange)(this.functionRegistry,t,e.getRange(),this.lazilyTransformingAstService,this);for(const e of r){const{vertex:r,id:n}=this.fetchCellOrCreateEmpty(e);this.graph.addEdge(null!=n?n:r,t)}r.length>0&&this.graph.markNodeAsDirty(t)}this.removeVertex(e),this.arrayMapping.removeArray(e.getRange())}addVertex(e,t){this.graph.addNodeAndReturnId(t),this.addressMapping.setCell(e,t)}addArrayVertex(e,t){this.graph.addNodeAndReturnId(t),this.setAddressMappingForArrayVertex(t,e)}*arrayFormulaNodes(){for(const e of this.graph.getNodes())e instanceof p.ArrayVertex&&(yield e)}*entriesFromRowsSpan(e){yield*this.addressMapping.entriesFromRowsSpan(e)}*entriesFromColumnsSpan(e){yield*this.addressMapping.entriesFromColumnsSpan(e)}fetchCell(e){return this.addressMapping.fetchCell(e)}getCell(e){return this.addressMapping.getCell(e)}getCellValue(e){return this.addressMapping.getCellValue(e)}getRawValue(e){return this.addressMapping.getRawValue(e)}getScalarValue(e){const t=this.addressMapping.getCellValue(e);return t instanceof l.SimpleRangeValue?new a.CellError(a.ErrorType.VALUE,i.ErrorM