hyperformula
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
60 lines • 705 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():"function"==typeof define&&define.amd?define("HyperFormula",[],t):"object"==typeof exports?exports.HyperFormula=t():e.HyperFormula=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));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 o=r(73);t.CellError=o.CellError,t.CellType=o.CellType,t.CellValueDetailedType=o.CellValueDetailedType,t.CellValueType=o.CellValueType,t.ErrorType=o.ErrorType;var s=r(170);t.DetailedCellError=s.DetailedCellError;var i=r(171),a=r(175);t.AlwaysDense=a.AlwaysDense,t.AlwaysSparse=a.AlwaysSparse,t.DenseSparseChooseBasedOnThreshold=a.DenseSparseChooseBasedOnThreshold;var u=r(147);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 c=r(198);t.ExportedCellChange=c.ExportedCellChange,t.ExportedNamedExpressionChange=c.ExportedNamedExpressionChange;var l=r(180);t.HyperFormula=l.HyperFormula;var h,d=(h=r(216))&&h.__esModule?h:{default:h},p=r(166);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=f(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if("default"!==s&&{}.hasOwnProperty.call(e,s)){var i=o?Object.getOwnPropertyDescriptor(e,s):null;i&&(i.get||i.set)?Object.defineProperty(n,s,i):n[s]=e[s]}return n.default=e,r&&r.set(e,n),n}(r(217)),g=r(139);function f(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(f=function(e){return e?r:t})(e)}t.SimpleRangeValue=g.SimpleRangeValue;
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class E extends l.HyperFormula{}E.HyperFormula=l.HyperFormula,E.ErrorType=o.ErrorType,E.CellError=o.CellError,E.CellType=o.CellType,E.CellValueType=o.CellValueType,E.CellValueDetailedType=o.CellValueDetailedType,E.DetailedCellError=s.DetailedCellError,E.ExportedCellChange=c.ExportedCellChange,E.ExportedNamedExpressionChange=c.ExportedNamedExpressionChange,E.ConfigValueTooBigError=u.ConfigValueTooBigError,E.ConfigValueTooSmallError=u.ConfigValueTooSmallError,E.EvaluationSuspendedError=u.EvaluationSuspendedError,E.ExpectedOneOfValuesError=u.ExpectedOneOfValuesError,E.ExpectedValueOfTypeError=u.ExpectedValueOfTypeError,E.ArraySize=n.ArraySize,E.SimpleRangeValue=g.SimpleRangeValue,E.EmptyValue=p.EmptyValue,E.FunctionPlugin=p.FunctionPlugin,E.FunctionArgumentType=p.FunctionArgumentType,E.FunctionPluginValidationError=u.FunctionPluginValidationError,E.InvalidAddressError=u.InvalidAddressError,E.InvalidArgumentsError=u.InvalidArgumentsError,E.LanguageNotRegisteredError=u.LanguageNotRegisteredError,E.LanguageAlreadyRegisteredError=u.LanguageAlreadyRegisteredError,E.MissingTranslationError=u.MissingTranslationError,E.NamedExpressionDoesNotExistError=u.NamedExpressionDoesNotExistError,E.NamedExpressionNameIsAlreadyTakenError=u.NamedExpressionNameIsAlreadyTakenError,E.NamedExpressionNameIsInvalidError=u.NamedExpressionNameIsInvalidError,E.NoOperationToRedoError=u.NoOperationToRedoError,E.NoOperationToUndoError=u.NoOperationToUndoError,E.NoRelativeAddressesAllowedError=u.NoRelativeAddressesAllowedError,E.NoSheetWithIdError=u.NoSheetWithIdError,E.NoSheetWithNameError=u.NoSheetWithNameError,E.NotAFormulaError=u.NotAFormulaError,E.NothingToPasteError=u.NothingToPasteError,E.ProtectedFunctionTranslationError=u.ProtectedFunctionTranslationError,E.SheetNameAlreadyTakenError=u.SheetNameAlreadyTakenError,E.SheetSizeLimitExceededError=u.SheetSizeLimitExceededError,E.SourceLocationHasArrayError=u.SourceLocationHasArrayError,E.TargetLocationHasArrayError=u.TargetLocationHasArrayError,E.UnableToParseError=u.UnableToParseError;const T=i.Config.defaultConfig.language;l.HyperFormula.registerLanguage(T,d.default),l.HyperFormula.languages[d.default.langCode]=d.default;for(const e of Object.getOwnPropertyNames(m))e.startsWith("_")||l.HyperFormula.registerFunctionPlugin(m[e]);t.default=E},function(e,t,r){"use strict";t.__esModule=!0,t.ArraySizePredictor=t.ArraySize=void 0,r(2);var n=r(72),o=r(165),s=r(166),i=r(77);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class a{constructor(e,t,r=!1){this.width=e,this.height=t,this.isRef=r}static error(){return new a(1,1,!0)}static scalar(){return new a(1,1,!1)}isScalar(){return 1===this.width&&1===this.height||this.isRef}}t.ArraySize=a;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 i.AstNodeType.FUNCTION_CALL:return this.checkArraySizeForFunction(e,t);case i.AstNodeType.COLUMN_RANGE:case i.AstNodeType.ROW_RANGE:case i.AstNodeType.CELL_RANGE:{const r=n.AbsoluteCellRange.fromAstOrUndef(e,t.formulaAddress);return void 0===r?a.error():new a(r.width(),r.height(),!0)}case i.AstNodeType.ARRAY:{const r=[],n=[];for(const o of e.args){const e=o.map(e=>this.checkArraySizeForAst(e,t)),s=Math.min(...e.map(e=>e.height)),i=e.reduce((e,t)=>e+t.width,0);r.push(s),n.push(i)}const o=r.reduce((e,t)=>e+t,0),s=Math.min(...n);return new a(s,o)}case i.AstNodeType.STRING:case i.AstNodeType.NUMBER:return a.scalar();case i.AstNodeType.CELL_REFERENCE:return new a(1,1,!0);case i.AstNodeType.DIV_OP:case i.AstNodeType.CONCATENATE_OP:case i.AstNodeType.EQUALS_OP:case i.AstNodeType.GREATER_THAN_OP:case i.AstNodeType.GREATER_THAN_OR_EQUAL_OP:case i.AstNodeType.LESS_THAN_OP:case i.AstNodeType.LESS_THAN_OR_EQUAL_OP:case i.AstNodeType.MINUS_OP:case i.AstNodeType.NOT_EQUAL_OP:case i.AstNodeType.PLUS_OP:case i.AstNodeType.POWER_OP:case i.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)?a.error():(o=r,s=n,new a(Math.max(o.width,s.width),Math.max(o.height,s.height)))}case i.AstNodeType.MINUS_UNARY_OP:case i.AstNodeType.PLUS_UNARY_OP:case i.AstNodeType.PERCENT_OP:{const n=this.checkArraySizeForAst(e.value,t);return!t.arraysFlag&&(n.height>1||n.width>1)?a.error():new a((r=n).width,r.height)}case i.AstNodeType.PARENTHESIS:return this.checkArraySizeForAst(e.expression,t);case i.AstNodeType.EMPTY:default:return a.error()}var r,o,s}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 a(1,1);const i=e.args.map(e=>{var r;return this.checkArraySizeForAst(e,new o.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<i.length&&(i.length-u.length)%n.repeatLastArgs!=0)return a.error();for(;u.length<i.length;){if(void 0===n.repeatLastArgs)return a.error();u.push(...u.slice(u.length-n.repeatLastArgs))}let c=1,l=1;for(let e=0;e<i.length;e++)u[e].argumentType!==s.FunctionArgumentType.RANGE&&u[e].argumentType!==s.FunctionArgumentType.ANY&&(l=Math.max(l,i[e].height),c=Math.max(c,i[e].width));return new a(c,l)}}},function(e,t,r){"use strict";var n=r(3),o=r(40),s=r(64),i=r(69),a=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=o(this),r=s(t),n=arguments.length;a(r+n);for(var u=0;u<n;u++)t[r]=arguments[u],r++;return i(t,r),r}})},function(e,t,r){"use strict";var n=r(4),o=r(6).f,s=r(44),i=r(48),a=r(38),u=r(56),c=r(68);e.exports=function(e,t){var r,l,h,d,p,m=e.target,g=e.global,f=e.stat;if(r=g?n:f?n[m]||a(m,{}):n[m]&&n[m].prototype)for(l in t){if(d=t[l],h=e.dontCallGetSet?(p=o(r,l))&&p.value:r[l],!c(g?l:m+(f?".":"#")+l,e.forced)&&void 0!==h){if(typeof d==typeof h)continue;u(d,h)}(e.sham||h&&h.sham)&&s(d,"sham",!0),i(r,l,d,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),o=r(9),s=r(11),i=r(12),a=r(13),u=r(19),c=r(39),l=r(42),h=Object.getOwnPropertyDescriptor;t.f=n?h:function(e,t){if(e=a(e),t=u(t),l)try{return h(e,t)}catch(e){}if(c(e,t))return i(!o(s.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),o=Function.prototype.call;e.exports=n?o.bind(o):function(){return o.apply(o,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,o=Object.getOwnPropertyDescriptor,s=o&&!n.call({1:2},1);t.f=s?function(e){var t=o(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),o=r(17);e.exports=function(e){return n(o(e))}},function(e,t,r){"use strict";var n=r(15),o=r(8),s=r(16),i=Object,a=n("".split);e.exports=o((function(){return!i("z").propertyIsEnumerable(0)}))?function(e){return"String"===s(e)?a(e,""):i(e)}:i},function(e,t,r){"use strict";var n=r(10),o=Function.prototype,s=o.call,i=n&&o.bind.bind(s,s);e.exports=n?i:function(e){return function(){return s.apply(e,arguments)}}},function(e,t,r){"use strict";var n=r(15),o=n({}.toString),s=n("".slice);e.exports=function(e){return s(o(e),8,-1)}},function(e,t,r){"use strict";var n=r(18),o=TypeError;e.exports=function(e){if(n(e))throw new o("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),o=r(23);e.exports=function(e){var t=n(e,"string");return o(t)?t:t+""}},function(e,t,r){"use strict";var n=r(9),o=r(21),s=r(23),i=r(30),a=r(33),u=r(34),c=TypeError,l=u("toPrimitive");e.exports=function(e,t){if(!o(e)||s(e))return e;var r,u=i(e,l);if(u){if(void 0===t&&(t="default"),r=n(u,e,t),!o(r)||s(r))return r;throw new c("Can't convert object to primitive value")}return void 0===t&&(t="number"),a(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),o=r(22),s=r(25),i=r(26),a=Object;e.exports=i?function(e){return"symbol"==typeof e}:function(e){var t=n("Symbol");return o(t)&&s(t.prototype,a(e))}},function(e,t,r){"use strict";var n=r(4),o=r(22),s=function(e){return o(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?s(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),o=r(8),s=r(4).String;e.exports=!!Object.getOwnPropertySymbols&&!o((function(){var e=Symbol("symbol detection");return!s(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&n&&n<41}))},function(e,t,r){"use strict";var n,o,s=r(4),i=r(29),a=s.process,u=s.Deno,c=a&&a.versions||u&&u.version,l=c&&c.v8;l&&(o=(n=l.split("."))[0]>0&&n[0]<4?1:+(n[0]+n[1])),!o&&i&&(!(n=i.match(/Edge\/(\d+)/))||n[1]>=74)&&(n=i.match(/Chrome\/(\d+)/))&&(o=+n[1]),e.exports=o},function(e,t,r){"use strict";e.exports="undefined"!=typeof navigator&&String(navigator.userAgent)||""},function(e,t,r){"use strict";var n=r(31),o=r(18);e.exports=function(e,t){var r=e[t];return o(r)?void 0:n(r)}},function(e,t,r){"use strict";var n=r(22),o=r(32),s=TypeError;e.exports=function(e){if(n(e))return e;throw new s(o(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),o=r(22),s=r(21),i=TypeError;e.exports=function(e,t){var r,a;if("string"===t&&o(r=e.toString)&&!s(a=n(r,e)))return a;if(o(r=e.valueOf)&&!s(a=n(r,e)))return a;if("string"!==t&&o(r=e.toString)&&!s(a=n(r,e)))return a;throw new i("Can't convert object to primitive value")}},function(e,t,r){"use strict";var n=r(4),o=r(35),s=r(39),i=r(41),a=r(27),u=r(26),c=n.Symbol,l=o("wks"),h=u?c.for||c:c&&c.withoutSetter||i;e.exports=function(e){return s(l,e)||(l[e]=a&&s(c,e)?c[e]:h("Symbol."+e)),l[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),o=r(4),s=r(38),i=e.exports=o["__core-js_shared__"]||s("__core-js_shared__",{});(i.versions||(i.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),o=Object.defineProperty;e.exports=function(e,t){try{o(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),o=r(40),s=n({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return s(o(e),t)}},function(e,t,r){"use strict";var n=r(17),o=Object;e.exports=function(e){return o(n(e))}},function(e,t,r){"use strict";var n=r(15),o=0,s=Math.random(),i=n(1..toString);e.exports=function(e){return"Symbol("+(void 0===e?"":e)+")_"+i(++o+s,36)}},function(e,t,r){"use strict";var n=r(7),o=r(8),s=r(43);e.exports=!n&&!o((function(){return 7!==Object.defineProperty(s("div"),"a",{get:function(){return 7}}).a}))},function(e,t,r){"use strict";var n=r(4),o=r(21),s=n.document,i=o(s)&&o(s.createElement);e.exports=function(e){return i?s.createElement(e):{}}},function(e,t,r){"use strict";var n=r(7),o=r(45),s=r(12);e.exports=n?function(e,t,r){return o.f(e,t,s(1,r))}:function(e,t,r){return e[t]=r,e}},function(e,t,r){"use strict";var n=r(7),o=r(42),s=r(46),i=r(47),a=r(19),u=TypeError,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor;t.f=n?s?function(e,t,r){if(i(e),t=a(t),i(r),"function"==typeof e&&"prototype"===t&&"value"in r&&"writable"in r&&!r.writable){var n=l(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 c(e,t,r)}:c:function(e,t,r){if(i(e),t=a(t),i(r),o)try{return c(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),o=r(8);e.exports=n&&o((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))},function(e,t,r){"use strict";var n=r(21),o=String,s=TypeError;e.exports=function(e){if(n(e))return e;throw new s(o(e)+" is not an object")}},function(e,t,r){"use strict";var n=r(22),o=r(45),s=r(49),i=r(38);e.exports=function(e,t,r,a){a||(a={});var u=a.enumerable,c=void 0!==a.name?a.name:t;if(n(r)&&s(r,c,a),a.global)u?e[t]=r:i(t,r);else{try{a.unsafe?e[t]&&(u=!0):delete e[t]}catch(e){}u?e[t]=r:o.f(e,t,{value:r,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return e}},function(e,t,r){"use strict";var n=r(15),o=r(8),s=r(22),i=r(39),a=r(7),u=r(50).CONFIGURABLE,c=r(51),l=r(52),h=l.enforce,d=l.get,p=String,m=Object.defineProperty,g=n("".slice),f=n("".replace),E=n([].join),T=a&&!o((function(){return 8!==m((function(){}),"length",{value:8}).length})),y=String(String).split("String"),A=e.exports=function(e,t,r){"Symbol("===g(p(t),0,7)&&(t="["+f(p(t),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),r&&r.getter&&(t="get "+t),r&&r.setter&&(t="set "+t),(!i(e,"name")||u&&e.name!==t)&&(a?m(e,"name",{value:t,configurable:!0}):e.name=t),T&&r&&i(r,"arity")&&e.length!==r.arity&&m(e,"length",{value:r.arity});try{r&&i(r,"constructor")&&r.constructor?a&&m(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch(e){}var n=h(e);return i(n,"source")||(n.source=E(y,"string"==typeof t?t:"")),e};Function.prototype.toString=A((function(){return s(this)&&d(this).source||c(this)}),"toString")},function(e,t,r){"use strict";var n=r(7),o=r(39),s=Function.prototype,i=n&&Object.getOwnPropertyDescriptor,a=o(s,"name"),u=a&&"something"===function(){}.name,c=a&&(!n||n&&i(s,"name").configurable);e.exports={EXISTS:a,PROPER:u,CONFIGURABLE:c}},function(e,t,r){"use strict";var n=r(15),o=r(22),s=r(36),i=n(Function.toString);o(s.inspectSource)||(s.inspectSource=function(e){return i(e)}),e.exports=s.inspectSource},function(e,t,r){"use strict";var n,o,s,i=r(53),a=r(4),u=r(21),c=r(44),l=r(39),h=r(36),d=r(54),p=r(55),m=a.TypeError,g=a.WeakMap;if(i||h.state){var f=h.state||(h.state=new g);f.get=f.get,f.has=f.has,f.set=f.set,n=function(e,t){if(f.has(e))throw new m("Object already initialized");return t.facade=e,f.set(e,t),t},o=function(e){return f.get(e)||{}},s=function(e){return f.has(e)}}else{var E=d("state");p[E]=!0,n=function(e,t){if(l(e,E))throw new m("Object already initialized");return t.facade=e,c(e,E,t),t},o=function(e){return l(e,E)?e[E]:{}},s=function(e){return l(e,E)}}e.exports={set:n,get:o,has:s,enforce:function(e){return s(e)?o(e):n(e,{})},getterFor:function(e){return function(t){var r;if(!u(t)||(r=o(t)).type!==e)throw new m("Incompatible receiver, "+e+" required");return r}}}},function(e,t,r){"use strict";var n=r(4),o=r(22),s=n.WeakMap;e.exports=o(s)&&/native code/.test(String(s))},function(e,t,r){"use strict";var n=r(35),o=r(41),s=n("keys");e.exports=function(e){return s[e]||(s[e]=o(e))}},function(e,t,r){"use strict";e.exports={}},function(e,t,r){"use strict";var n=r(39),o=r(57),s=r(6),i=r(45);e.exports=function(e,t,r){for(var a=o(t),u=i.f,c=s.f,l=0;l<a.length;l++){var h=a[l];n(e,h)||r&&n(r,h)||u(e,h,c(t,h))}}},function(e,t,r){"use strict";var n=r(24),o=r(15),s=r(58),i=r(67),a=r(47),u=o([].concat);e.exports=n("Reflect","ownKeys")||function(e){var t=s.f(a(e)),r=i.f;return r?u(t,r(e)):t}},function(e,t,r){"use strict";var n=r(59),o=r(66).concat("length","prototype");t.f=Object.getOwnPropertyNames||function(e){return n(e,o)}},function(e,t,r){"use strict";var n=r(15),o=r(39),s=r(13),i=r(60).indexOf,a=r(55),u=n([].push);e.exports=function(e,t){var r,n=s(e),c=0,l=[];for(r in n)!o(a,r)&&o(n,r)&&u(l,r);for(;t.length>c;)o(n,r=t[c++])&&(~i(l,r)||u(l,r));return l}},function(e,t,r){"use strict";var n=r(13),o=r(61),s=r(64),i=function(e){return function(t,r,i){var a=n(t),u=s(a);if(0===u)return!e&&-1;var c,l=o(i,u);if(e&&r!=r){for(;u>l;)if((c=a[l++])!=c)return!0}else for(;u>l;l++)if((e||l in a)&&a[l]===r)return e||l||0;return!e&&-1}};e.exports={includes:i(!0),indexOf:i(!1)}},function(e,t,r){"use strict";var n=r(62),o=Math.max,s=Math.min;e.exports=function(e,t){var r=n(e);return r<0?o(r+t,0):s(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,o=Math.floor;e.exports=Math.trunc||function(e){var t=+e;return(t>0?o: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),o=Math.min;e.exports=function(e){var t=n(e);return t>0?o(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),o=r(22),s=/#|\.prototype\./,i=function(e,t){var r=u[a(e)];return r===l||r!==c&&(o(t)?n(t):!!t)},a=i.normalize=function(e){return String(e).replace(s,".").toLowerCase()},u=i.data={},c=i.NATIVE="N",l=i.POLYFILL="P";e.exports=i},function(e,t,r){"use strict";var n=r(7),o=r(70),s=TypeError,i=Object.getOwnPropertyDescriptor,a=n&&!function(){if(void 0!==this)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}();e.exports=a?function(e,t){if(o(e)&&!i(e,"length").writable)throw new s("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),o=r(147),s=r(77),i=r(141);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
const a=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 o.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 o.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 l(e.sheet,e.row,t.row):new c(e.sheet,e.col,t.col)}static fromAst(e,t){return e.type===s.AstNodeType.CELL_RANGE?u.fromCellRange(e,t):e.type===s.AstNodeType.COLUMN_RANGE?c.fromColumnRange(e,t):l.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(a);return n}static spanFromOrUndef(e,t,r){if(!Number.isFinite(t)&&Number.isFinite(r)){if(0!==e.col)return;return new l(e.sheet,e.row,e.row+r-1)}if(!Number.isFinite(r)&&Number.isFinite(t)){if(0!==e.row)return;return new c(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,o,s){return new u((0,n.simpleCellAddress)(e,t,r),(0,n.simpleCellAddress)(e,o,s))}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),o=Math.max(this.start.col,e.start.col),s=Math.min(this.end.col,e.end.col);return t>r||o>s?void 0:new u((0,n.simpleCellAddress)(this.sheet,o,t),(0,n.simpleCellAddress)(this.sheet,s,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 i.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 o=(0,n.simpleCellAddress)(this.sheet,this.start.col+r,this.start.row+t);e[t].push(o)}}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 o=this.start.row;for(;o<=this.effectiveEndRow(e);){let s=this.start.col;const i=[];for(;s<=this.effectiveEndColumn(e);)i.push(t((0,n.simpleCellAddress)(this.start.sheet,s,o))),s++;r.push(i),o++}return r}addresses(e){const t=[];let r=this.start.row;const o=this.effectiveEndRow(e),s=this.effectiveEndColumn(e);for(;r<=o;){let e=this.start.col;for(;e<=s;)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 c 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 o.SheetsNotEqual(r.sheet,n.sheet);return new c(r.sheet,r.col,n.col)}shouldBeRemoved(){return this.width()<=0}shiftByRows(e){}expandByRows(e){}shifted(e,t){return new c(this.sheet,this.start.col+e,this.end.col+e)}rangeWithSameHeight(e,t){return new c(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=c;class l 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 o.SheetsNotEqual(r.sheet,n.sheet);return new l(r.sheet,r.row,n.row)}shouldBeRemoved(){return this.height()<=0}shiftByColumns(e){}expandByColumns(e){}shifted(e,t){return new l(this.sheet,this.start.row+t,this.end.row+t)}rangeWithSameWidth(e,t){return new l(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=l},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,o,s=r(74),i=r(131),a=r(140),u=r(139);!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"}(o||(t.CellType=o={}));var c,l;t.getCellType=(e,t)=>e instanceof s.ArrayVertex?e.isLeftCorner(t)?o.ARRAYFORMULA:o.ARRAY:e instanceof s.FormulaCellVertex||e instanceof s.ParsingErrorVertex?o.FORMULA:e instanceof s.ValueCellVertex?o.VALUE:o.EMPTY,function(e){e.EMPTY="EMPTY",e.NUMBER="NUMBER",e.STRING="STRING",e.BOOLEAN="BOOLEAN",e.ERROR="ERROR"}(c||(t.CellValueNoNumber=c={})),function(e){e.NUMBER="NUMBER"}(l||(t.CellValueJustNumber=l={}));const h=t.CellValueType=Object.assign(Object.assign({},c),l);t.CellValueDetailedType=Object.assign(Object.assign({},c),a.NumberType);t.CellValueTypeOrd=e=>{switch(e){case h.EMPTY:return 0;case h.NUMBER:return 1;case h.STRING:return 2;case h.BOOLEAN:return 3;case h.ERROR:return 4}throw new Error("Cell value not computed")};const d=e=>{if(e===a.EmptyValue)return h.EMPTY;if(e instanceof p||e instanceof u.SimpleRangeValue)return h.ERROR;if("string"==typeof e)return h.STRING;if((0,a.isExtendedNumber)(e))return h.NUMBER;if("boolean"==typeof e)return h.BOOLEAN;throw new Error("Cell value not computed")};t.getCellValueType=d;t.getCellValueDetailedType=e=>(0,a.isExtendedNumber)(e)?(0,a.getTypeOfExtendedNumber)(e):d(e);t.getCellValueFormat=e=>(0,a.isExtendedNumber)(e)?(0,a.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,`${i.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 o=r(146);t.AddressMapping=o.AddressMapping;var s=r(153);t.Graph=s.Graph;var i=r(154);t.TopSort=i.TopSort;var a=r(156);t.RangeMapping=a.RangeMapping;var u=r(157);t.SheetMapping=u.SheetMapping;var c=r(148);t.ArrayMapping=c.ArrayMapping;var l=r(150);t.FormulaCellVertex=l.FormulaCellVertex,t.ArrayVertex=l.ArrayVertex;var h=r(160);t.EmptyCellVertex=h.EmptyCellVertex;var d=r(161);t.ValueCellVertex=d.ValueCellVertex;var p=r(162);t.ParsingErrorVertex=p.ParsingErrorVertex;var m=r(152);t.RangeVertex=m.RangeVertex;var g=r(163);t.SparseStrategy=g.SparseStrategy;var f=r(164);t.DenseStrategy=f.DenseStrategy},function(e,t,r){"use strict";t.__esModule=!0,t.DependencyGraph=void 0,r(2);var n=r(72),o=r(76),s=r(73),i=r(138),a=r(131),u=r(140),c=r(139),l=r(77),h=r(141),d=r(142),p=r(74),m=r(146),g=r(148),f=r(149),E=r(150),T=r(153),y=r(156),A=r(157);
/**
* @license
* Copyright (c) 2024 Handsoncode. All rights reserved.
*/
class R{constructor(e,t,r,a,u,c,h,d){this.addressMapping=e,this.rangeMapping=t,this.sheetMapping=r,this.arrayMapping=a,this.stats=u,this.lazilyTransformingAstService=c,this.functionRegistry=h,this.namedExpressions=d,this.changes=i.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 l.NamedExpressionDependency?this.namedExpressions.namedExpressionOrPlaceholder(t.name,e.sheet).address:(0,s.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 l.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:o}=this.rangeMapping.findSmallerRange(e.range);let s;void 0!==r&&this.graph.adjacentNodes(r).has(e)?(s=o,t.push([new n.AbsoluteCellRange(r.start,r.end),r])):s=e.range;for(const e of s.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 E.FormulaVertex))return;r=e.getAddress(this.lazilyTransformingAstService),t=e.getFormula(this.lazilyTransformingAstService);const n=(0,l.collectDependencies)(t,this.functionRegistry);return[r,(0,o.absolutizeDependencies)(n,r)]},this.graph=new T.Graph(this.dependencyQueryVertices)}static buildEmpty(e,t,r,n,o){return new R(new m.AddressMapping(t.chooseAddressMappingPolicy),new y.RangeMapping,new A.SheetMapping(t.translationPackage),new g.ArrayMapping,o,e,r,n)}setFormulaToCell(e,t,r,n,o,s){const i=E.FormulaVertex.fromAst(t,e,n,this.lazilyTransformingAstService.version());return this.exchangeOrAddFormulaVertex(i),this.processCellDependencies(r,i),this.graph.markNodeAsDirty(i),o&&this.markAsVolatile(i),s&&this.markAsDependentOnStructureChange(i),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 i.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 o=this.graph.getNodeId(n);t.isFinite()||this.graph.markNodeAsInfiniteRange(o);const{smallerRangeVertex:s,restRange:i}=this.rangeMapping.findSmallerRange(t);if(void 0!==s){if(this.graph.addEdge(s,o),n.bruteForce){n.bruteForce=!1;for(const e of t.addresses(this))this.graph.removeEdge(this.fetchCell(e),o)}}else n.bruteForce=!0;const a=this.arrayMapping.getArray(i);if(void 0!==a)this.graph.addEdge(a,o);else for(const e of i.addresses(this)){const{vertex:t,id:r}=this.fetchCellOrCreateEmpty(e);this.graph.addEdge(null!=r?r:t,o)}this.graph.addEdge(o,r),t.isFinite()&&this.correctInfiniteRangesDependenciesByRangeVertex(n)}else if(e instanceof l.NamedExpressionDependency){const n=t.getAddress(this.lazilyTransformingAstService).sheet,{vertex:o,id:s}=this.fetchNamedExpressionVertex(e.name,n);this.graph.addEdge(null!=s?s:o,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(d.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(d.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.removeRows(e)});const t=this.stats.measure(d.StatType.ADJUSTING_RANGES,()=>{const t=this.truncateRanges(e,e=>e.row);return this.getArrayVerticesRelatedToRanges(t)});return this.stats.measure(d.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(d.StatType.ADJUSTING_RANGES,()=>{const t=this.rangeMapping.removeRangesInSheet(e);for(const e of t)this.removeVertex(e);this.stats.measure(d.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(d.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(d.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.removeColumns(e)});const t=this.stats.measure(d.StatType.ADJUSTING_RANGES,()=>{const t=this.truncateRanges(e,e=>e.col);return this.getArrayVerticesRelatedToRanges(t)});return this.stats.measure(d.StatType.ADJUSTING_ARRAY_MAPPING,()=>this.fixArraysAfterRemovingColumns(e.sheet,e.columnStart,e.numberOfColumns)),this.addStructuralNodesToChangeSet(),{affectedArrays:t,contentChanges:this.getAndClearContentChanges()}}addRows(e){this.stats.measure(d.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.addRows(e.sheet,e.rowStart,e.numberOfRows)});const t=this.stats.measure(d.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(d.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(d.StatType.ADJUSTING_ADDRESS_MAPPING,()=>{this.addressMapping.addColumns(e.sheet,e.columnStart,e.numberOfColumns)});const t=this.stats.measure(d.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(d.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 o of e.addressesWithDirection(t,r,this)){const i=(0,s.simpleCellAddress)(n,o.col+t,o.row+r);let a=this.addressMapping.getCell(o);const u=this.addressMapping.getCell(i);if(this.addressMapping.removeCell(o),void 0!==a){this.graph.markNodeAsDirty(a),this.addressMapping.setCell(i,a);let t=void 0;for(const r of this.graph.adjacentNodes(a))r instanceof p.RangeVertex&&!e.containsRange(r.range)&&(t=null!=t?t:this.fetchCellOrCreateEmpty(o).vertex,this.graph.addEdge(t,r),this.graph.removeEdge(a,r));t&&(this.graph.markNodeAsDirty(t),this.addressMapping.setCell(o,t))}if(void 0!==u){void 0===a&&this.addressMapping.removeCell(i);for(const e of this.graph.adjacentNodes(u))a=null!=a?a:this.fetchCellOrCreateEmpty(i).vertex,this.graph.addEdge(a,e),this.graph.markNodeAsDirty(a);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,f.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 c.SimpleRangeValue?new s.CellError(s.ErrorType.VALUE,a.ErrorMessage.ScalarExpected):t}existsEdge(e,t){return this.graph.existsEdge(e,t)}getSheetId(e){return this.sheetMapping.fetch(e)}getSheetHeigh