@sheetxl/sdk 0.8.0-beta.7 → 0.8.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/cjs/BAtZ8a7H7zsRvWqe.cjs +90 -0
- package/browser/cjs/CQPMWBxBUmkORmxV.cjs +1 -0
- package/browser/cjs/{E08wpSuqr-UadjSZ.cjs → CvQ1tIq7wZ7HIGPq.cjs} +1 -1
- package/browser/cjs/CwvGOe42j8KpAF0v.cjs +1 -0
- package/browser/cjs/{O6F5xVsoF2hTiprv.cjs → DCOqoH-T4Ux_1dQj.cjs} +1 -1
- package/browser/cjs/index.cjs +2 -2
- package/browser/esm/{tBEZ_r7Bkp7CrFLF.mjs → BdHD3v-u8irI1XhZ.mjs} +2 -2
- package/browser/esm/{bSQdR4WlmM40WWFR.mjs → C8btlUQcQwNyzHY3.mjs} +2 -2
- package/browser/esm/{B7v0PdbyuBlceMLG.mjs → CF3VfWX7bJu8kO_Z.mjs} +2 -2
- package/browser/esm/{BADV_AABAw-3U9iO.mjs → D3ll0ybMQOP4uPyW.mjs} +1 -1
- package/browser/esm/{DRpWwH6CWI0QaNlp.mjs → DXmFrSnh3xSBfoD7.mjs} +8146 -7694
- package/browser/esm/{CFDfAmU2o5HFRTu4.mjs → DzgIc4oyekwA-fkl.mjs} +96 -96
- package/browser/esm/{DkHfJEJlvjDJnXEU.mjs → Iw280tlGmTHKDqzd.mjs} +2 -2
- package/browser/esm/index.mjs +919 -593
- package/node/esm/{CWJELJxqO-1z0tJU.mjs → B_FOXd5PSfVcg0ED.mjs} +1 -1
- package/node/esm/{HMR0po5avaUU1XUZ.mjs → BzgnLKSVfN-mrMSW.mjs} +1 -1
- package/node/esm/{BShIHUY7pxerJVT8.mjs → D4PsEIRHxAahp5kn.mjs} +1 -1
- package/node/esm/{DbAKZ-Ythj1VwgyS.mjs → dinqlP3jU8gDOjso.mjs} +1 -1
- package/node/esm/index.mjs +11373 -10575
- package/package.json +7 -6
- package/resources/locales/de/model.msg.json +19 -0
- package/resources/locales/en/model.msg.json +25 -0
- package/types/scripting-api.json +6847 -6401
- package/types/scripting-enums.json +101 -21
- package/types/scripting.d.ts +1949 -457
- package/types/src/calculation/Calculation.d.ts +37 -45
- package/types/src/calculation/grid/CalcGrid.d.ts +12 -4
- package/types/src/calculation/grid/CalcGridBackend.d.ts +0 -6
- package/types/src/calculation/grid/CalcGridProxy.d.ts +1 -6
- package/types/src/calculation/grid/ICalcGrid.d.ts +12 -4
- package/types/src/calculation/grid/_CalcRequest.d.ts +4 -9
- package/types/src/cell/ICell.d.ts +3 -3
- package/types/src/cell/ICellHeader.d.ts +24 -2
- package/types/src/cellRange/ICellRange.d.ts +67 -3
- package/types/src/cellRange/ICellRanges.d.ts +12 -12
- package/types/src/chart/Chart.d.ts +2 -13
- package/types/src/condition/AnchoredConditional.d.ts +2 -0
- package/types/src/condition/BuiltInOperators/ColorOperator.d.ts +4 -0
- package/types/src/condition/BuiltInOperators/IconOperator.d.ts +4 -0
- package/types/src/condition/ICondition.d.ts +36 -28
- package/types/src/condition/_ConditionUtils.d.ts +32 -8
- package/types/src/fill/IFill.d.ts +46 -11
- package/types/src/fill/IStroke.d.ts +34 -42
- package/types/src/filter/IFilter.d.ts +51 -6
- package/types/src/hyperlink/IHyperlink.d.ts +8 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/movable/AbstractMovableContent.d.ts +6 -0
- package/types/src/movable/FormControl.d.ts +206 -0
- package/types/src/movable/IFormControl.d.ts +424 -0
- package/types/src/movable/IMovable.d.ts +37 -8
- package/types/src/movable/IMovableCollection.d.ts +19 -1
- package/types/src/movable/Movable.d.ts +20 -0
- package/types/src/movable/MovableContentRegistry.d.ts +64 -0
- package/types/src/movable/_BuiltInContents.d.ts +2 -0
- package/types/src/movable/_DrawnBounds.d.ts +33 -0
- package/types/src/movable/_RotatedFrame.d.ts +20 -0
- package/types/src/movable/index.d.ts +6 -4
- package/types/src/numFmt/BuiltInFormats.d.ts +5 -0
- package/types/src/numFmt/_NumFmtUtils.d.ts +0 -1
- package/types/src/numFmt/vendor/numfmt/_sheetxl.d.ts +6 -0
- package/types/src/outline/IOutline.d.ts +186 -0
- package/types/src/outline/Outline.d.ts +157 -0
- package/types/src/outline/index.d.ts +2 -0
- package/types/src/shape/GeometryPreset.d.ts +197 -0
- package/types/src/shape/IGeometry.d.ts +398 -0
- package/types/src/shape/IShape.d.ts +177 -204
- package/types/src/shape/Shape.d.ts +39 -13
- package/types/src/shape/ShapeStyleUtils.d.ts +48 -0
- package/types/src/shape/_Geometry.d.ts +14 -0
- package/types/src/shape/_GeometryLoader.d.ts +21 -0
- package/types/src/shape/_builtIn/_BuiltInChunks.d.ts +10 -0
- package/types/src/shape/_builtIn/_BuiltInDef.d.ts +9 -0
- package/types/src/shape/_builtIn/arrows.d.ts +6 -0
- package/types/src/shape/_builtIn/basic.d.ts +6 -0
- package/types/src/shape/_builtIn/callouts.d.ts +6 -0
- package/types/src/shape/_builtIn/flowchart.d.ts +6 -0
- package/types/src/shape/_builtIn/lines.d.ts +6 -0
- package/types/src/shape/_builtIn/math.d.ts +6 -0
- package/types/src/shape/_builtIn/other.d.ts +6 -0
- package/types/src/shape/_builtIn/rectangles.d.ts +6 -0
- package/types/src/shape/_builtIn/starsBanners.d.ts +6 -0
- package/types/src/shape/geometry/_strokeEnds.d.ts +7 -0
- package/types/src/shape/geometry/format.d.ts +3 -0
- package/types/src/shape/geometry/geometry.d.ts +84 -0
- package/types/src/shape/geometry/guides.d.ts +54 -0
- package/types/src/shape/geometry/handles.d.ts +14 -0
- package/types/src/shape/geometry/index.d.ts +7 -0
- package/types/src/shape/geometry/lineEnds.d.ts +53 -0
- package/types/src/shape/geometry/paths.d.ts +35 -0
- package/types/src/shape/geometry/segments.d.ts +114 -0
- package/types/src/shape/index.d.ts +2 -0
- package/types/src/sheet/ISheet.d.ts +10 -45
- package/types/src/sheet/Sheet.d.ts +19 -5
- package/types/src/sheet/SheetRange.d.ts +16 -1
- package/types/src/sheet/_SheetUtils.d.ts +10 -2
- package/types/src/sheetHeader/ISheetHeader.d.ts +4 -0
- package/types/src/sheetHeader/SheetCellHeader.d.ts +4 -0
- package/types/src/sheetHeader/SheetHeader.d.ts +10 -0
- package/types/src/sheetHeader/_HeaderUtils.d.ts +3 -1
- package/types/src/sheetView/ISheetView.d.ts +17 -0
- package/types/src/sheetView/SheetView.d.ts +4 -0
- package/types/src/table/AnchoredTable.d.ts +7 -2
- package/types/src/text/IText.d.ts +182 -0
- package/types/src/text/ITextFrame.d.ts +85 -0
- package/types/src/text/TextRotation.d.ts +3 -3
- package/types/src/text/TextStacked.d.ts +2 -2
- package/types/src/theme/ITheme.d.ts +24 -0
- package/types/src/workbook/Workbook.d.ts +16 -5
- package/browser/cjs/CrcmEew-dr51xpf9.cjs +0 -1
- package/browser/cjs/CwzIjMpnMKeypivl.cjs +0 -1
- package/browser/cjs/D3Vlh9UOBKtvlXBL.cjs +0 -93
- package/types/src/movable/Control.d.ts +0 -55
- package/types/src/movable/IControl.d.ts +0 -86
- package/types/src/movable/IGroup.d.ts +0 -30
- package/types/src/shape/_ShapeXml.d.ts +0 -28
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const e=require("./B7_pDFYCVzt-3hUs.cjs");let t=require("@sheetxl/primitives"),n=require("@sheetxl/utils"),r=require("@sheetxl/formulas");r=e.r(r,1);let i=require("@sheetxl/formulas-extended");i=e.r(i,1);let a=require("@sheetxl/scripting");var o,s,c,l,u=(e,t)=>{let n=new Map;return e.forEach((e,r)=>{t.get(r)!==e&&n.set(r,e)}),n},d=!1,f=0,p=e=>{if(typeof e!=`string`)throw Error(`A stateId (string) is required. Register with 'ITransaction.IStore.create'.`);return e},m=class extends Error{constructor(e,t,n){super(e===`open`?`Transaction conflict: a transaction is already open (expected commit '${t}').`:`Transaction conflict: expected commit '${t}' but current is '${n}'.`),this.name=`TransactionConflictError`,this.reason=e,this.expectedCommitId=t,this.actualCommitId=n}},h=class{constructor(e){this._record=e}getId(){return this._record.id}getDescription(){return this._record.description}getMeta(){return Object.freeze(this._record.meta)}getAuthor(){return this._record.author}getTimestamp(){return this._record.timestamp}getOperation(){return this._record.operation}getIntents(){return Object.freeze({...this._record.intents})}},g=class{constructor(e){this._listeners=new Set,this._listenersState=new Map,this._commits=new Map,this._locked=!1,this._pending=null,this._versionCounter=0,this._flushOnRead=0,this._isSync=e?.sync??d,this._isTransient=e?.transient??!1,this._author=e?.author,this._maxCommits=e?.maxCommits??1e3;let t={id:`0`,description:`initial`,meta:{},author:this._author,timestamp:Date.now(),states:new Map,intents:{},intentWrites:[],version:0,previousId:null},n={record:t,commit:new h(t)};this._current=n,this._cacheId=null,this._cacheState=null,this._states=t.states,this._transactionStack=[],this._restoring=!1;let r=new Map;r.set(t.id,n),this._commits=r,this._tipId=t.id}static{this.setDefaultSync=e=>{d=e}}getLog(e,t=100){let n=[],r=e;do{let e=this._commits.get(r);if(!e)throw Error(`Invalid commit id: '${r}'`);if(n.push(e.commit),r=e.record.previousId,!r)return n}while(n.length<t);return n}getCommitCount(){return this._commits.size}isOpenTransaction(){return this._transactionStack.length>0}isRestoring(){return this._restoring}isAmendingOtherCommit(){let e=this._transactionStack[0];return e instanceof v&&e._isRetargeted()}getPendingTransaction(){return this._transactionStack[0]??null}getCurrentTransaction(){let e=this._transactionStack;return e[e.length-1]??null}amend(e,t){let n=this.beginCommit(),r=n.getDepth()===0?this._commits.get(e):void 0;n.getDepth()===0&&(n._setAmendOf(e),r&&r!==this._current&&n._retarget(r));try{let e=t(r?r.commit:this._current.commit);return n.commit(),e}catch(e){throw n.rollback(),e}}_squashTip(e){if(this._transactionStack.length>0)return!1;let t=this._commits.get(this._tipId),n=t?.record.previousId;if(!t||!n)return!1;let r=this._commits.get(n);return!!r&&(r.record.states=t.record.states,r.record.intents=e(r.record.intents,t.record.intents),r.record.timestamp=t.record.timestamp,this._commits.delete(t.record.id),this._tipId=n,this._current===t&&(this._current=r,this._states=r.record.states,this._cacheId=null,this._cacheState=null),!0)}create(e){let t=n.CommonUtils.uuidV4();if(e!==void 0){let n=this.beginCommit();try{n.updateState(t,e),n.commit()}catch(e){throw n.rollback(),e}}return t}getStateAt(e,t){return p(t),this._commits.get(e)?.record.states.get(t)}getState(e){p(e);let t=this._transactionStack;if(t.length===0){if(this._cacheId===e)return this._cacheState;let t=this._states.get(e);return this._cacheId=e,this._cacheState=t,t}if(this._flushOnRead>0)for(let n=t.length-1;n>=0;n--)t[n]._isFlushedBy(e)&&t[n]._flush();return t[t.length-1].getState(e)}getCurrentCommit(e=!0){return(e?this._pending?.commit:null)??this._current.commit}getTipCommit(){return this._commits.get(this._tipId).commit}getVersionId(e){return p(e),this._states.get(e)?.version??0}restore(e,t){let n=this._getCommitContainer(e,t);if(this._current.commit.getId()===n.commit.getId())return n.commit;let r=u(n.record.states,this._current.record.states);this._notifyStates(`onBeforeCommitStart`,this._current,r,!0,!1,!1,n),this._current=n,this._states=this._current.record.states,this._cacheId=null,this._cacheState=null,this._notifyStates(`onAfterStateChange`,n,r,!1,!0,!0),this._notify(`onCommitChange`,n.commit,!0),this._restoring=!0;try{this._notifyStates(`onRestoreOrRevert`,n,n.record.states,!1,!0)}finally{this._restoring=!1}return n.commit}revert(e,t){let n=this._getCommitContainer(e,t),r=this._commits.get(n.record.previousId);if(!r)throw Error(`Invalid commit id: '${n.record.previousId}'`);let i=u(r.record.states,this._current.record.states);this._notifyStates(`onBeforeCommitStart`,this._current,i,!0,!1,!1,n),this._current=r,this._states=this._current.record.states,this._cacheId=null,this._cacheState=null,this._notifyStates(`onAfterStateChange`,r,i,!0,!1,!0,n),this._notify(`onCommitChange`,r.commit,!0),this._restoring=!0;try{this._notifyStates(`onRestoreOrRevert`,r,r.record.states,!0,!0,!1,n)}finally{this._restoring=!1}return r.commit}_getCommitContainer(e,t){let n=this._commits.get(e);if(!n)throw Error(`Invalid commit id: '${e}'`);if(this._isTransient)throw Error(`Cannot revert transient store`);if(t?.force&&this._transactionStack.length>0&&this._transactionStack[0].rollback(),this._transactionStack.length!==0)throw Error(`Open transactions.`);return n}_pruneForwards(e){let t=this._tipId;for(;t&&t!==e;){let e=this._commits.get(t);if(!e)break;this._commits.delete(t),t=e.record.previousId}}_trimOldest(){if(this._commits.size<=this._maxCommits)return;let e=this._commits.keys();for(;this._commits.size>this._maxCommits;)this._commits.delete(e.next().value);let t=this._commits.get(e.next().value);t&&(t.record.previousId=null)}beginCommit(e,t){let r=this._transactionStack;r.length>0&&r[r.length-1]._flush();let i=r.length;typeof e==`string`&&(e={description:e});let a=e?.expectedCommitId;if(a!==void 0){let e=this._current.record.id;if(i>0||this._restoring)throw new m(`open`,a,e);if(e!==a)throw new m(`stale`,a,e)}if(this._locked)throw console.warn(`TransactionStore locked`,r),Error(`TransactionStore is locked by '${r[i-1].getDescription()}`);let o=e?.preventFurtherTransactions,s=this,c=(e,n,r)=>{let a=s._transactionStack;i!==a.length-1&&console.warn(`Transaction stack out of sync`,i,a.length,a),o&&(this._locked=!1),a.pop(),e._isFlushedOnRead()&&s._flushOnRead--,t?.(e,n,r),a.length===0&&(s._pending=null,s._notifyClose(e._getCommit(),n,e._isElided(),e._isAmendClose()))},l;if(r.length===0){let t=this._current.record,r={states:new Map,id:n.CommonUtils.uuidV4(),description:typeof e==`string`?e:e?.description??null,meta:{},timestamp:Date.now(),author:(typeof e==`object`?e?.author:void 0)??this._author??null,version:t.version+1,previousId:t.id,intents:{},intentWrites:[],operation:e?.operation},i={record:r,commit:new h(r)};this._pending=i,this._notify(`onCommitStart`,i.commit),l=new v(this,i,t?.states,e,c)}else l=r[r.length-1].beginTransaction(e,c);return o&&(this._locked=!0),this._transactionStack.push(l),l._isFlushedOnRead()&&this._flushOnRead++,l}doBatch(e,t,n){let r,i=this.beginCommit(t,n),a=this.getCurrentCommit();try{r=e?.(a);let n=()=>{i.commit(t)};if(r&&typeof r.then==`function`)return new Promise((e,t)=>{r.then(r=>{try{n(),e(r)}catch(e){t(e)}}).catch(e=>{i.rollback(),t(e)})});n()}catch(e){throw i.rollback(),e}return r}remove(e){p(e);let t=!1,n=this._listenersState.get(e);if(n){let r=this.getCurrentCommit();n.forEach(e=>{e.onClose?.(r)}),this._listenersState.delete(e),t=!0}this._current.record.states.delete(e)&&(t=!0),this._commits.forEach(n=>{n.record.states.delete(e)&&(t=!0)});let r=this._transactionStack;return r.length>0&&r[0]._purgeState(e),this._cacheId=null,this._cacheState=null,t}addListener(e){let t=this._listeners;return t.add(e),()=>{t.delete(e)}}addStateListener(e,t){if(p(e),!t)throw Error(`Listener is required`);let n=this._listenersState.get(e);return n||(n=new Set,this._listenersState.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&this._listenersState.delete(e)}}dispatchEvents(e,t=!1){!t||this._isSync?e():setTimeout(e,0)}_commitRecord(e,t,r){let i=e.record,a=e.commit,o=e,s=++this._versionCounter;if(t.forEach((e,t)=>{e!=null&&((e,t,n)=>{Object.defineProperty(e,"id",{value:t,enumerable:!1,configurable:!0,writable:!1}),Object.defineProperty(e,"version",{value:n,enumerable:!1,configurable:!0,writable:!1})})(e,t,s)}),!this._isTransient){let t=!1;if(r!==null){let s=this._current,c=this._commits.get(r)??s,l=c.record,u=c!==s,d=u?l.states:s.record.states;if(i.states.forEach((e,t)=>{d.set(t,e)}),((e,t)=>{for(let n=0;n<t.length;n++){let[r,i]=t[n];e[r]=typeof i==`function`?i(e[r]):i}})(l.intents,i.intentWrites),l.meta={...l.meta,...i.meta},l.timestamp=i.timestamp,t=!0,u)return void(o.record.intentWrites=n.CommonUtils.EmptyArray);i=s.record,a=s.commit,e=s}this._commits.set(i.id,e),t||(i.previousId!==this._tipId&&this._pruneForwards(i.previousId),this._tipId=i.id,this._trimOldest())}this._current=e,this._states=this._current.record.states,this._cacheId=null,this._cacheState=null,o.record.intentWrites=n.CommonUtils.EmptyArray,r===null&&this._notify(`onCommitChange`,a),this._notifyStates(`onAfterStateChange`,e,t,!1,!1,!0,o),this._notify(r===null?`onCommitEnd`:`onAmendEnd`,a,!0)}_notifyStates(e,t,n,r=!1,i=!1,a=!1,o=t){let s=t.commit,c=o.record.intents,l=this._listenersState;n.forEach((t,n)=>{let o=l.get(n);o&&this.dispatchEvents(()=>{o.forEach(n=>{n[e]?.(t,s,r,i,c)})},a)})}_notifyClose(e,t,n=!1,r=!1){this._listeners.forEach(i=>{i.onCommitClose?.(e,t,n,r)})}_notify(e,t,n=!1){return this.dispatchEvents(()=>{this._listeners.forEach(n=>{n[e]?.(t)})},n)}},_=class{constructor(e,t,n){if(this._children=new Set,this._depth=0,this._closed=!1,this._isAmend=!1,this._readOnly=!1,this._hooks=null,this._flushing=!1,this._outcomes=null,this._store=e,this._container=t,n=typeof n==`string`?{description:n}:n,this._description=n?.description??``,this._operation=n?.operation??null,this._readOnly=n?.readOnly??!1,n?.flush||n?.onCommit||n?.onRollback){let e={flush:n.flush,writes:n.writes,onCommit:n.onCommit,onRollback:n.onRollback};this._hooks=e,(e.onCommit||e.onRollback)&&(this._outcomes=[e])}}_isFlushedOnRead(){return!(!this._hooks?.flush||!this._hooks.writes?.length)}_isFlushedBy(e){let t=this._hooks?.writes;return!!t&&t.includes(e)}_flush(){let e=this._hooks?.flush;if(e&&!this._flushing){this._flushing=!0;try{e()}finally{this._flushing=!1}}}_settle(e){let t=this._children;for(;t.size>0;)t.values().next().value.commit(e);this._flush()}_adoptOutcomes(e){let t=e._outcomes;if(t)if(this._outcomes)for(let e=0;e<t.length;e++)this._outcomes.push(t[e]);else this._outcomes=t}_notifyOutcome(e){let t=this._outcomes;if(t){this._outcomes=null;for(let n=0;n<t.length;n++)try{e?t[n].onCommit?.(e):t[n].onRollback?.()}catch(e){console.warn(e)}}}_getCommit(){return this._container.commit}_isElided(){return!1}_setAmendOf(e){this._container.amendOf=e}_isAmendClose(){return this._isAmend||this._container.amendOf!==void 0}getIntent(e){return this._container.record.intents?.[e]}setIntent(e,t){let n=this._container.record,r=n.intents??={};r[e]=typeof t==`function`?t(r[e]):t,(n.intentWrites??=[]).push([e,t])}getDepth(){return this._depth}getDescription(){return this._description}getOperation(){return this._operation}getStates(){return this._states}beginTransaction(e,t){this._ensureOpen();let n=new y(this._store,this,this._container,typeof e==`string`?{description:e}:e,t);return this._children||this._children,this._children.add(n),n}isReadOnly(){return this._readOnly}updateState(e,t){if(this._ensureOpen(),p(e),this._readOnly)throw Error(`Transaction is read-only`+(this._description?`: '${this._description}'`:``));let n=this.getState(e),r;if(typeof t==`function`){if(r=t(n),r===n)return n;r&&={...r}}else{if(t===void 0)return n;r={...n,...t}}if(r){let t=this._states;t||(t=new Map,this._states=t),t.set(e,r)}return r}amend(e){return this._isAmend=!0,this.commit(e)}commit(e){return this._ensureOpen(),typeof e==`string`&&(e={description:e}),e&&(e.description&&(this._description=e.description),e.meta&&(this._meta=n.CommonUtils.mergeContentful(e.meta,this._meta))),this._children&&this._children.forEach(t=>{t.commit(e)}),this}isClose(){return this._closed}_ensureOpen(){if(this._closed)throw this._descriptions?console.warn(`stack: [${this._descriptions.join(`,`)}]`):this._description&&console.warn(`description: [${this._description}]`),Error(`Transaction already closed`)}_removeChild(e,t=!1){this._children.delete(e),t||this._mergeStates(e._states)}_purgeState(e){this._states?.delete(e),this._children.forEach(t=>{t._purgeState(e)})}_mergeStates(e){if(!e||e.size===0)return;let t=this._states;return t?(e.forEach((e,n)=>{t.set(n,e)}),t):(this._states=e,e)}get isITransaction(){return!0}},v=class extends _{constructor(e,t,n,r,i){super(e,t,r),this._retargeted=!1,this._elided=!1,this._prevStates=n,this._onClose=i,this._states=new Map,this._meta=t.record.meta}_isElided(){return this._elided}_retarget(e){this._prevStates=e.record.states,this._retargeted=!0}_isRetargeted(){return this._retargeted}getId(){return this._container.commit.getId()}getSavepointId(){return this.getId()}getParent(){return this}commit(e){this._ensureOpen(),this._settle(e);let t=this._states,n=this._container;if(this._store._notifyStates(`onBeforeCommitStart`,n,t,!1,!1),super.commit(e),this._states.size===0)return this._closed=!0,this._elided=!0,this._onClose?.(this,!1,e),this._notifyOutcome(n.commit),this;this._store._notifyStates(`onBeforeCommitEnd`,n,t,!1,!1),this._settle(e);let r=new Map(this._prevStates);this._states.forEach((e,t)=>{e===null?r.delete(t):r.set(t,e)}),this._states=r,this._description&&(n.record.description=this._description),this._meta&&(n.record.meta=this._meta),n.record.states=r,this._closed=!0,this._onClose?.(this,!1,e);let i=n.amendOf??(this._isAmend?n.record.previousId:null);return this._store._commitRecord(n,t,i),this._notifyOutcome(n.commit),this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(e=>{e.rollback()}),this._notifyOutcome(null),this._closed=!0,this._onClose?.(this,!0,null),this}updateState(e,t){let n=this.getState(e),r=super.updateState(e,t);return r===n||this._states.set(e,r),r}getState(e){p(e);let t=this._states.get(e);return t||=this._prevStates.get(e),t}},y=class extends _{constructor(e,t,n,r,i){if(super(e,n,r),this._savepointId=null,!t)throw Error(`Parent transaction required`);this._parent=t,this._depth=this._parent.getDepth()+1,!1!==(typeof r==`string`?void 0:r?.savepoint)&&(this._savepointId=`${t.getId()}:${++f}`),t.isReadOnly()&&(this._readOnly=!0),this._onClose=i}getId(){return this._parent.getId()}getSavepointId(){return this._savepointId??this._parent.getSavepointId()}getParent(){return this._parent}getState(e){if(this._states){let t=this._states.get(e);if(t!==void 0)return t}return this._parent.getState(e)}commit(e){return this._ensureOpen(),this._settle(e),super.commit(e),this._parent._removeChild(this),this._parent._adoptOutcomes(this),this._closed=!0,this._onClose?.(this,!1,e),this._parent??this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(e=>{e.rollback()}),this._notifyOutcome(null),this._parent._removeChild(this,!0),this._closed=!0,this._onClose?.(this,!0,null),this._parent??this}},b=(e,t,...n)=>{let r=globalThis.__SXL_LOG_EVENTS;r&&(typeof r!=`string`||e.includes(r))&&console.log(`[sxl:${e}] ${t}`,...n)},x=class{constructor(e,t){this._listeners=new Set,this._pending=null,this._landing=null,this._listeners=new Set,this._transactions=t??new g({transient:!0}),this._stateId=this._transactions.create(),this._src=e;let n=this,r=()=>{let e=n._landing;if(b(n._label(),`drain landing=${e?e.length:`null`}`),!e)return;n._landing=null;let t=new Set,r=e.length;for(let i=0;i<r;i++){let r=e[i];n._doNotify(r.listeners,r.removes,r.options,t)}};this._transactionsRemoveListener=this._transactions.addListener({onCommitClose(e,t,i){let a=n._pending;b(n._label(),`commitClose rollback=${t} elided=${i} pending=${a?a.length:`null`}`),n._pending=null,t||(a&&(n._landing?n._landing.push(...a):n._landing=a),i&&r())},onCommitEnd:r,onAmendEnd:r})}_label(){return this._src?.constructor?.name??`unknown`}_inOperation(){return this._transactions.isOpenTransaction()||this._transactions.isRestoring()}addListeners(e,t){let n=t?.transactional??this._inOperation(),r={listeners:e},i=this,a=()=>{n?i._updateEntries(e=>{e.delete(r)}):i._listeners.delete(r)};return r.remove=t?.once?a:null,n?i._updateEntries(e=>{e.add(r)}):i._listeners.add(r),a}_updateEntries(e){let t=this._transactions,n=t.getState(this._stateId)?.listeners,r=new Set(n);e(r);let i=t.beginCommit();try{i.updateState(this._stateId,{listeners:r}),i.amend()}catch(e){throw i.rollback(),e}}async _doNotify(e,t=null,n,r){let i=n?.source??this._src,a=[],o=n?.params,s=e.length;for(let t=0;t<s;t++){let n=e[t];r&&r.has(n)||(r?.add(n),a.push(n(i,o)))}let c=null;if(t&&(c=()=>{let e=t.length;for(let n=0;n<e;n++)t[n]()}),n?.async)return new Promise(async(e,t)=>{try{let t=await Promise.all(a);c?.(),e(t)}catch(e){c?.(),t(e)}});c?.()}_collect(e,t){if(!e)return null;let n=null,r=null;return e.forEach(e=>{let i=e.listeners[t];i&&((n??=[]).push(i),e.remove&&(r??=[]).push(e.remove))}),n?{listeners:n,removes:r}:null}notify(e,t){let n=this._transactions,r=t?.transactional??this._inOperation();if(r){let r=this._collect(n.getState(this._stateId)?.listeners,e);r&&this._doNotify(r.listeners,r.removes,t)}let i=this._collect(this._listeners,e);if(i)return!r||n.isRestoring()||t?.async?(b(this._label(),`notify ${String(e)} delivered to ${i.listeners.length}`),this._doNotify(i.listeners,i.removes,t)):((this._pending??=[]).push({listeners:i.listeners,removes:i.removes,options:t}),void b(this._label(),`notify ${String(e)} QUEUED (open transaction) pending=${this._pending.length}`));b(this._label(),`notify ${String(e)} inOperation=${r} listeners=0`)}close(){this._transactions.remove(this._stateId),this._transactionsRemoveListener(),this._listeners.clear(),this._pending=null,this._landing=null}},S=class{constructor(e){this._collectionEmitter=null,this._closed=!1,this._transactions=e}isClosed(){return this._closed}_close(){this._closed||(this._closed=!0,this._collectionEmitter?.notify(`onClose`))}*[Symbol.iterator](){yield*this._getItems()}getItems(e){return this._getItems(e)}getCount(){return this._getItems().length}at(e){return this._getItems().at(e)}indexOf(e){return this._getItems().indexOf(e)}find(e){return this._getItems().find(e)}findIndex(e){return this._getItems().findIndex(e)}filter(e){return this._getItems().filter(e)}map(e){return this._getItems().map(e)}forEach(e){this._getItems().forEach(e)}some(e){return this._getItems().some(e)}every(e){return this._getItems().every(e)}toArray(){return this._getItems()}addListeners(e,t){return this._getCollectionEmitter().addListeners(e,t)}_getCollectionEmitter(){return this._collectionEmitter??=new x(this,this._transactions)}_notifyCollectionChange(){this._collectionEmitter?.notify(`onCollectionChange`)}_notifyInvalidated(){this._collectionEmitter?.notify(`onInvalidated`)}get isICollection(){return!0}},C=class{constructor(e){this._items=new Map;let t=this._items;for(let n of Object.values(e))t.set(n.getName().toLowerCase(),n)}register(e){let t=e.getName().toLowerCase();this._items.set(t,e)}get(e){if(e)return this._items.get(e.toLowerCase())}getAll(){return Array.from(this._items.values())}has(e){return!!e&&this._items.has(e.toLowerCase())}};(s=o||={}).SmallCaps={None:`none`,Small:`small`,All:`all`},s.StrikeStyle={None:`none`,Single:`single`,Double:`double`},(l=c||={}).TabStop=class{},l.HorizontalAlignment={General:`general`,Left:`left`,Center:`center`,Right:`right`,Justify:`justify`,Distributed:`distributed`,CenterContinuous:`centerContinuous`,Fill:`fill`},l.VerticalAlignment={Top:`top`,Center:`center`,Bottom:`bottom`,Justify:`justify`,Distributed:`distributed`},l.Orientation={Horizontal:`horizontal`,Vertical:`90`,Vertical270:`270`,Stacked:`stacked`},l.ReadingDirection={Auto:`auto`,LeftToRight:`ltr`,RightToLeft:`rtl`},l.Overflow={Visible:`visible`,Wrap:`wrap`,Clip:`clip`,Shrink:`shrink`,Ellipsis:`ellipsis`},l.Autofit={None:`none`,Normal:`normal`,Shape:`shape`},l.TabStopAlignment={Default:`default`,Left:`left`,Right:`right`,Center:`center`},l.toCSSHorizontalTextAlign=e=>e?e.toLowerCase():null;var w=e.n({DefaultUnQuoteRegEx:()=>I,camelToSnake:()=>A,capitalize:()=>E,clampString:()=>j,countDecimals:()=>M,findValidTextValue:()=>T,getBaseName:()=>O,getFileNameExtension:()=>D,isQuoted:()=>L,isValidEmail:()=>ie,isValidHttpUrl:()=>ne,numberToAlphabet:()=>oe,quote:()=>ee,snakeToCamel:()=>k,splitUnquoted:()=>te,toHyperlinkAddress:()=>ae,unquote:()=>R});function T(e,t,n=1e3){if(!e)throw Error(`A template string must be specified.`);if(t(e))return e;let r,i=new RegExp(/\d+/,`g`).exec(e),a=0;i===null?(a=1,r=`${e}_${a}`):(r=e,a=parseFloat(i[0]),isNaN(a)&&(a=0));let o=isNaN(a)?0:a;for(;a<o+n;)try{let e=r.replace(/\d+/g,()=>``+a++);if(t(e))return e}catch{}throw Error(`Unable to find valid name for '${e}'.`)}function E(e,t=!1){if(!e||e.length===0)return e;let n=e.charAt(0);if(n>=`a`&&n<=`z`){let r=String.fromCharCode(n.charCodeAt(0)-32);return t?r+e.slice(1).toLowerCase():r+e.slice(1)}return e}function D(e){if(!e||typeof e!=`string`)return``;let t=e.split(/[\\/]/).pop()||``,n=t.lastIndexOf(`.`);return t===``||n<1?``:t.slice(n+1)}function O(e,t=!1){if(!e||typeof e!=`string`)return``;let n=e.split(/[\\/]/).pop()||``;if(n===``)return``;let r=D(n),i=r.length===0?n:n.slice(0,n.length-r.length-1);return t?E(i,!0):i}function k(e){return e.toLowerCase().replace(/([-_][a-z])/g,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}function A(e){return e&&e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}function j(e,t=36){return e.substring(0,36)+(e.length>t?`…`:``)}function M(e){if(e===void 0)return 0;let t=e.toString().split(`.`);return t.length<=1?0:t[1].length||0}var N=new RegExp(/^["|'|`](.*)["|'|`]$/),P=RegExp(`^([a-zA-Z]+:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$`,`i`),F=(e=`,`,t=`'`)=>RegExp(`\\s*${e}\\s*(?=(?:[^${t}]*${t}[^${t}]*${t})*[^${t}]*$)`,`g`),I=F();function L(e){return!!e&&e.length>1&&N.test(e)&&e[0]===e[e.length-1]}function R(e){return e.replace(N,`$1`)}function ee(e,t=`'`){return`${t}${e}${t}`}function te(e,t,n){let r=I;return t===void 0&&n===void 0||(r=F(t,n)),e.split(r)}function ne(e){if(e.indexOf(`:`)===-1||!P.test(e))return!1;let t;try{t=new URL(e)}catch{return!1}return t.protocol===`http:`||t.protocol===`https:`}var re=new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/i);function ie(e){return e.length>7&&e.substring(0,7).toLowerCase()===`mailto:`?!/\s/.test(e):re.test(e)}function ae(e){if(ne(e))return e;if(e.length>4&&e.substring(0,4).toLowerCase()===`www.`){let t=`http://${e}`;return ne(t)?t:null}return ie(e)?e.substring(0,7).toLowerCase()===`mailto:`?e:`mailto:${e}`:null}function oe(e){return((e>=26?oe((e/26|0)-1):``)+`abcdefghijklmnopqrstuvwxyz`[e%26|0]).toUpperCase()}var se=e.n({getAdvance:()=>pe,getLineLength:()=>fe,isRotatedLayout:()=>de,layoutLines:()=>me,normalizeAngle:()=>ue}),ce=Math.PI/180,le=1e-6;function ue(e){let t=e%360;return t<0?t+360:t}function de(e){return Math.abs(Math.sin(ue(e)*ce))>=le}function fe(e,t,n){let r=ue(n)*ce,i=Math.abs(Math.sin(r));return i<le?2**53-1:Math.max(1,(e-t*Math.abs(Math.cos(r)))/i)}function pe(e,t){let n=Math.sin(ue(t)*ce);return Math.abs(n)<le?2**53-1:-e/n}function me(e,t,n,r,i){let a=ue(t),o=a*ce,s=Math.cos(o),l=Math.sin(o),u=e[0]?.height??0,d=fe(n.height,u,a),f=pe(u,a),p=Math.abs(s)<le,m=0;if(p){let e=l<0;i===c.VerticalAlignment.Top?m=+!!e:i===c.VerticalAlignment.Center?m=.5:i===c.VerticalAlignment.Bottom&&(m=+!e)}else r===c.HorizontalAlignment.Right?m=1:r!==c.HorizontalAlignment.Center&&r!==c.HorizontalAlignment.CenterContinuous||(m=.5);let h=e.length,g=Array(h),_=0,v=0,y=0,b=0;for(let t=0;t<h;t++){let n=e[t],r=(d-n.width)*m,i={x:t*f+r*s,y:r*l},a=n.width*s,o=n.width*l,c=-n.height*l,u=n.height*s,p={x:i.x+Math.min(0,a)+Math.min(0,c),y:i.y+Math.min(0,o)+Math.min(0,u),width:Math.abs(a)+Math.abs(c),height:Math.abs(o)+Math.abs(u)};g[t]={origin:i,size:n,bounds:p},t===0?(_=p.x,v=p.y,y=p.x+p.width,b=p.y+p.height):(_=Math.min(_,p.x),v=Math.min(v,p.y),y=Math.max(y,p.x+p.width),b=Math.max(b,p.y+p.height))}let x,S=n.x-_;r===c.HorizontalAlignment.Right?S=n.x+n.width-y:r!==c.HorizontalAlignment.Center&&r!==c.HorizontalAlignment.CenterContinuous||(S=n.x+(n.width-(y-_))/2-_),x=p?l<0?n.y+n.height:n.y:i===c.VerticalAlignment.Top?n.y-v:i===c.VerticalAlignment.Center?n.y+(n.height-(b-v))/2-v:n.y+n.height-b;for(let e=0;e<h;e++){let t=g[e];t.origin.x+=S,t.origin.y+=x,t.bounds.x+=S,t.bounds.y+=x}return{angle:a,lineLength:d,advance:f,lines:g,bounds:{x:_+S,y:v+x,width:y-_,height:b-v}}}var he=e.n({layoutColumns:()=>xe,slotCount:()=>ye,splitGlyphs:()=>ge,toColumns:()=>ve});function ge(e){return Array.from(e)}var _e=(e,t)=>{if(e.length<=t)return[e.slice()];let n=[],r=[],i=0,a=e.length;for(;i<a;){let o=i;for(;o<a&&e[o]!==` `;)o++;let s=e.slice(i,o),c=o<a;if(r.length>0&&(r.length+1+s.length<=t?r.push(` `,...s):(n.push(r),r=[])),r.length===0){let e=0;for(;s.length-e>t;)n.push(s.slice(e,e+t)),e+=t;r=s.slice(e)}i=c?o+1:o,r.length>=t&&(n.push(r),r=[])}return(r.length>0||n.length===0)&&n.push(r),n};function ve(e,t,n){if(!t)return[ge(e.replace(/\r?\n/g,` `))];let r=e.split(/\r?\n/),i=Math.max(1,Math.floor(n)),a=[];for(let e=0;e<r.length;e++){let t=_e(ge(r[e]),i);for(let e=0;e<t.length;e++)a.push(t[e])}return a}function ye(e){let t=0;for(let n=0;n<e.length;n++)t=Math.max(t,e[n].length);return t}var be=e=>{let t=0,n=e.length;for(;t<n&&e[t]===` `;)t++;for(;n>t&&e[n-1]===` `;)n--;return t===0&&n===e.length?e:e.slice(t,n)};function xe(e,t,n,r,i){let a=e.length,o=a*t,s=n.x+(n.width-o)/2;r===c.HorizontalAlignment.Left||r===c.HorizontalAlignment.Justify?s=n.x:r===c.HorizontalAlignment.Right&&(s=n.x+n.width-o);let l=Array(a),u=0,d=0;for(let r=0;r<a;r++){let a=be(e[r]),o=a.length*t,f=n.y+n.height-o;i===c.VerticalAlignment.Top||i===c.VerticalAlignment.Justify?f=n.y:i!==c.VerticalAlignment.Center&&i!==c.VerticalAlignment.Distributed||(f=n.y+(n.height-o)/2),l[r]={glyphs:a,bounds:{x:s+r*t,y:f,width:t,height:o}},r===0?(u=f,d=f+o):(u=Math.min(u,f),d=Math.max(d,f+o))}return{pitch:t,columns:l,bounds:{x:s,y:u,width:o,height:d-u}}}var Se=e.n({getBuildDate:()=>Te,getBuildLabel:()=>Ee,getBuildVersion:()=>we,isPlaceholderLicenseKey:()=>Ce});function Ce(e){if(!e)return!0;let t=e.toLowerCase();return t.startsWith(`eval`)||t.startsWith(`trial`)||t.startsWith(`visit `)||t.startsWith(`email `)}function we(){try{return`0.8.0-beta.7`}catch{return``}}function Te(){try{return`2026-10-02T16:56:23.154Z`}catch{return``}}function Ee(){let e=we();if(e&&e!==`local`)return e;let t=new Date(Te());if(Number.isNaN(t.getTime()))return`local`;let n=e=>String(e).padStart(2,`0`);return`local ${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function De(e,t){e-=243;let n=je(),r=n[e];De.cxtOAl===void 0&&(De.WQDrQJ=function(e,t){let n,r,i=[],a=0,o=``;for(e=function(e){let t=``,n=``;for(let n,r,i=0,a=0;r=e.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)&&(t+=String.fromCharCode(255&n>>(-2*i&6))))r=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=`.indexOf(r);for(let e=0,r=t.length;e<r;e++)n+=`%`+(`00`+t.charCodeAt(e).toString(16)).slice(-2);return decodeURIComponent(n)}(e),r=0;r<256;r++)i[r]=r;for(r=0;r<256;r++)a=(a+i[r]+t.charCodeAt(r%t.length))%256,n=i[r],i[r]=i[a],i[a]=n;r=0,a=0;for(let t=0;t<e.length;t++)r=(r+1)%256,a=(a+i[r])%256,n=i[r],i[r]=i[a],i[a]=n,o+=String.fromCharCode(e.charCodeAt(t)^i[(i[r]+i[a])%256]);return o},De.QUzSgn={},De.cxtOAl=!0);let i=e+n[0],a=De.QUzSgn[i];return a?r=a:(De.iWYXFt===void 0&&(De.iWYXFt=!0),r=De.WQDrQJ(r,t),De.QUzSgn[i]=r),r}function Oe(e,t,n,r,i){return De(i-108,t)}(function(){function e(e,t,n,r,i){return De(t-130,e)}let t=je();function n(e,t,n,r,i){return De(i- -801,n)}function r(e,t,n,r,i){return De(i-137,n)}function i(e,t,n,r,i){return De(n-883,i)}for(;;)try{if(-parseInt(i(0,0,1131,0,`nU15`))/1*(parseInt(i(0,0,1148,0,`UV93`))/2)+parseInt(r(0,0,`*xV)`,0,392))/3*(-parseInt(e(`%U5q`,374))/4)+-parseInt(e(`ETm&`,394))/5*(parseInt(i(0,0,1129,0,`]8ui`))/6)+-parseInt(r(0,0,`o&zu`,0,386))/7*(parseInt(n(0,0,`C4Oi`,0,-543))/8)+-parseInt(i(0,0,1137,0,`pHYH`))/9*(-parseInt(r(0,0,`RYA3`,0,397))/10)+parseInt(e(`jpHO`,400))/11+parseInt(r(0,0,`R#W%`,0,388))/12==762388)break;t.push(t.shift())}catch{t.push(t.shift())}})();var ke=Oe(0,`Pp1%`,0,0,360);function Ae(e,t,n,r,i){return De(r-3,i)}function je(){let e=`W6tdMaexW4uHWR0dWRirtwu.nx7cJmo4ySk9BCoVDCkr.W71/hYtcIupdIJ5IWQu.zqBcK8k6WRpdRSkNW78d.W68jyfpdRtBcLG.lKiPlvCMDW.a8khoceOW6/cNX0PWO5NmcOKWQ53gWrFWPPCqCkJWRNcKcBcSG.W7hcP1JcLLnLWO8YlSoP.swpcRLJdSmomhG.W4FcTCkSWOztW73dTCo/WRlcTmkEW6BcRdO.xSkcFCojz8ogW63dVeFdGmo8.i8kODSohvbFcOdy.WQ8agGhcIa/cTSoNcSoMDuy.DG/cQrOUDwFcMmodW57dQvu+.W6xcH8oBqcKIW7O.W6CLW7b+WRNcGCkUEs5hoGtcHG.W5D0Cb9gW6zdfW.WQfrWQRcISoIWPxdTr50W5bIha.W5RcSvFdRmkfCWDaW6tcJCo8.wmkSW79OhSkxW6TBsW.WQjNy8ktW5mqW5BcTJxcR8keWQm.W6W3oCohW5FcRCkVWRxcKffB.W5qws8kkWOZdMb7cHCkbWPxdNW.WRzLW4ZdH8k6avZcSCo0m8kpW6RdOMG.x+kvREkxL+kxI+kvK+kwMokwVokxVokwOokxHEkxMUkwVHtdK+kwIUkvLokvHokvVokuQ+kwPUkvOUkuQokwNEkwIEkxL+kwH+kvU+kvRUkuMokuLokwOokuQokxRUkuQokuUEkxJUkvR+kwMEkwREkvUokvIEkxICkW4Ps44PwY4Pw1fZBILRNILBBIL4/ILRlILipILzldN+kuUUkwMokwLEkuQUkuGokuSEkxU+kuUUkuR+kwP+kvUCkkWRtIL7/ILlpILAZILOZILRRILlpILP3ILzNILQdILklIL7RILiJILjVILABILQRIL6JILBFIL4hILjpIL4ZILihIL6VIL7FIL5JIL5NILBhIL7FILPddS+kuG+kwGokwMUkuGokuNUkuTEkwP+kuUokuSEkuH+kwTfNILkNIL57ILi3ILzhILP7ILiVILAhILONIL4pIL4VIL67IL73ILRVIL7dILAlILidIL7NILz/IL5dIL4RIL6dILRynAokxMokwMUkwPUkuIUkwL+kvMSkjC1/dPsBIL4hILzNILitcMhHDW5VdJEkxG+kvHokwR+kxI+kuLUkuUCkd4Pwg4PAu4PwLfokvSEkwS+kwKokxT+kxMokxQEkwKEkxG+kxTokwL+kvGUkuPUkuOUkxPokvHokvVokwOokuS+kuO+kuNUkxSUkxM8kmmEkwVEkwMUkwVokxIUkuG+kxMu3dUCo9WPSQ4PsC4Ps54PExqvCOW4X94PEv4PAu4PEa4Pwk4PAg4PA2g+kuKokwUokuLYBILQFILPlILjtILjVIL5RILR3IL6lILkNIL7lIL7tILjaBfUkxP+kuI+kvHUkxKEkwQEkvM+kxNokuPEkuLEkwLEkuN+kuUUkvOokxVUkuPEkwTEkvUUkuNUkvNCkNW7Tp4PEr4PEh4PwKW7SZuqVILzZILABILRNILzFdR+kvKEkxTUkxQokuMEkwM+kwIokuQEkxMUkwJ+kxIEkxOhpILiRIL7VILkNILzJILRNILzZIL7lILQdILRZILRtILyGhWOhIL6dILPdILO/IL4xILBJILjlIL6lILjhIL77IL4pILP7IL4pILzxILB3IL7ZILABILkBIL7VILOyOe8oF4PwB4PsC4PwLhWmTbUkvHUkwI+kwPKhcV+kuGokuVokvSokwNokvKUkxOEkuU+kxRUkuSokvHokvKq.WQX+WRVdGxBcRvhdRdhcTa.W4tcTmkLWOjtW7JcImkyWPNcPCkbW7W.nmk3WRuRW6DzWQRcTCkEtSkGda.WOG2WPlcGchdMby`.split(`.`);return(je=function(){return e})()}var Me=Ae(0,0,0,266,`@9G!`)+Ee(),Ne=Oe(0,`D[lr`,0,0,379),Pe=De(262,`l79F`),Fe=Ae(0,0,0,264,`O4qD`),Ie=e.n({claimFullLicensePrint:()=>Ze,findLicenseKey:()=>Ke,getHostDetails:()=>Be,getKey:()=>Je,getLocation:()=>He,getOS:()=>Ue,isDevEnv:()=>Ve,printBanner:()=>Xe,printDetails:()=>et,printLicenseNotice:()=>Qe,setKey:()=>qe});(function(){function e(e,t,n,r,i){return Ye(e-914,t)}function t(e,t,n,r,i){return Ye(i- -123,r)}let n=Re();function r(e,t,n,r,i){return Ye(r- -495,t)}function i(e,t,n,r,i){return Ye(r- -763,t)}function a(e,t,n,r,i){return Ye(n-552,t)}for(;;)try{if(parseInt(t(0,0,0,`(hcl`,27))/1+parseInt(r(0,`Z5qf`,0,-289))/2+-parseInt(a(0,`ba#4`,674))/3+parseInt(t(0,0,0,`LeGO`,15))/4+parseInt(r(0,`(ZP6`,0,-340))/5*(parseInt(r(0,`LqL#`,0,-319))/6)+-parseInt(i(0,`29xd`,0,-604))/7*(-parseInt(t(0,0,0,`T6b%`,16))/8)+-parseInt(e(1060,`(ZP6`))/9*(parseInt(i(0,`Z5qf`,0,-571))/10)==764607)break;n.push(n.shift())}catch{n.push(n.shift())}})();var Le=new Set([Ge(1005,1017,966,1043,`dG$Z`),ze(-519,-563,-514,-562,`M#l^`),ze(-588,-614,-615,-580,`Ca(t`)]);function Re(){let e=`WO7dR14.W7LJf0jVWRDsjmoj.WRhcH8o7W7W.WQmMWR7dO8kDv8k3chOqW4NcG1y.FbvYW69VW7yXCwjKpmoHCCk/vSkz.FH4idSoTW5T0ASo0WQf3W57dH8kXWRW.WQKZb8oSlMVcJNpcO8k3W70.acXlr8oYWP8cW43dT8kRuG7dSCobi8oDba.W5rdW6mYg8kd.WPf+WOCZcfGTW4HWWR4.d8oscuasaHWmnKNdHcLaqCosd1hdTIejW7irW40nb8kMW7lcIsTcW5xdPbH2zadcGmk7cNHvWPpcReBcSCocymox.W7bGjmot.iH0t.kHOnbCo6WOi.uMnNWQK.WRycnZqHcmoyW5xcPG.WQ7dHXVcRCkDnSkiWOfdda.ASo1WR7cK8kFW5lcOmoqlhpcVa.uqpdPSkkrXS.DeaOWReJW6jWtNTpD8kzfa.WOdcUdabcbBdHW.W5VcQL8.AY7dSCkPWR5kW4iSW5tcK1ldSa.WQdcPSooxYpdJXPr4Oc4iKZdItqOw8kwWOxdQqeLkZe2WO97smoToYrnWRtdQdOBC8kmWQ5lWR3cVmoznsnwsCkdW69/qCoEWPddRshcHfyix27dRSkhW6tcP8kuhfqKaCoPDCkqBCo4cIa.W6m5WOZdOWpcICkwWQdcHvlcTbJdL8oBW6O.WQBdOXddI18UW6jmku0E.WOSZW7ZcK8khW5ePA8k6gvbNq8ojW4ZdR8oUAW.W6DhW4RcHmk0kCokW49GW4xdI1ag.sNn1WQxdSColWP0.W7f6W6lcO8oedSoLkMCTW7FcVL05WOSwWOySW60.W4FdRxVcTSo6W4xcICo/W4/cQa.kv/cMq.WPONw2JdVa7dNwVcMSkjWP3cSmo+WPJdJW.v0ddVe/dVmoG.W5VdUmkjvSkFWRSSqKebW6RcK3S.W4pdQxfzv1dcMSo9cSkHW5OtpG.W6/cGKZdQSoFp8klWQjveCkV.dCkwWRRcHKy.lWnHuSoYWOCEW4pdRCo4huC.p8kLW7NdQSodWOxdVCozghhcJCocna.sNDNWOtdRmoAWOSsr8odfSkUWOi.ebGdW6NcImki.AGfUtYBcJa19u8o0utNdRSo9WPpcPZWzsG8GWPSCte7cOmoUfmkyomkPWPGZsSoSamogWOZcQgi6W5FcPbnXaSoxWRDDW6G/.vmkCaCkUeCoXWQz5uKn5W7FdPq.nCofW6ZcMxFdQCo0WRfFWOuX.W6NdRmoAAYBcImkcpftcLh0.qxL6WRxdSCoxWPPpr8otcCkL.hh49aCkRW4mCW6tdJmk3zY8.W7f6W6dcV8ozwa.kv/cNwr0iHHE.WPmZW5C.WOWSW5ZcLCkq.vmkBbSkPeSkWW510CurO.W4e/j3i.WRW0wbG.jGWhCZ/cJqL9.W5hcTG/dRSo6Emoeo0Cx.W5JdJYZdKvTXWRa.W7FdISoykG.W6DhW4RcHCkJnmocW5rVW4i.W5yNW71KkvanW7PcWRNdUa.WO05W5tcICkhW5u.W7zxDbGmf8ow.WR7dOZ/dHvWIW79H.W4jAoZq5D8oQW5bYW6j6dvqxWRvth2BcO8o6W6RdUdOFWQz4W7Hx.fSoBuSoVu8k3W4zLuMi.W5/cMCobWP3dK8o6.WRTeW5hcR8k4DmoqW5r7W5tcMa5ArCoZW7S.WRBcI8kEDIO+wZpcKhldLG.W7xdT8oIDa.W5rjW640a8kdWPpdTCoM.WPxcUdC+cahdLSowfSkEW7W.amoydN8zgLea.pmkNW7ldP8kqW5pcGSoYe3i.W4eImwddQ3/cU8km.jbXXW65PW6e.FCoLWRNcTW.W64lWOuy.WRFcKmoIW73dUSouqa.dmoyegOEfq.W5VdUmkjwmkcWQepqfOf.r0ZdPNVdV8o2EH5Kfwq.lqWtemoQ.W6fLW6dcUCoF.WORdJCkCW4RcN8kIW77dRSoubZhcQG.WQxdIxa.yCo/WQNcVSkcW5JcQSoq.WO52AbObcmoDW4FdUhe.W77cK8o9W7/dR8kAvSkxW5RcL2fKgmoVWPi.W7yjn8owl8k9W6ddJmob.dmo8mNW.WRCbmKDywmkbW6lcOr/dVZ8p.kaCqxdRcNc9Hq8k6uW.WQmIWRtdQmonamohmui9.gmofeN8ygfmj.WQHOWPeR.WQBdPCo5AIxdGmkdfK/cGIldLCozWRbM.WPtcUdCndeJcHCkEvG.W41gedz1Fq.ECkNWPi7tSkCj8ool8kQWPDaW4NcMqbCW5v+WOZdUCooWPFdU8kc.bqmmW6NdKmkDiuz1WQlcO0lcM17dPSk1W7PTcmkoW6OjWR/cNCoBWRruW40.W75WW6lcT8oFcG.W5pcTaVdOCkFjCkUb2CUsGKr.W7ymnmkGw8oGWRpdISoIpMFdSGC.n8klCCkSWQyRCmoMW5RcLgW`.split(`.`);return(Re=function(){return e})()}function ze(e,t,n,r,i){return Ye(e- -728,i)}async function Be(){let e=globalThis[i(`Aw^Q`,846,807,849,851)];if(!e)return{protocol:null,domain:null};let t=e[a(472,`@oPf`,495,494,470)][i(`wRhE`,823,822,806,807)](/:$/,``)[a(436,`$tXR`,410,460,509)]();function n(e,t,n,r,i){return ze(e-184,0,0,0,t)}let r=e[n(-367,`N#MJ`)][a(488,`RqAS`,461,445,430)]();function i(e,t,n,r,i){return ze(n-1369,0,0,0,e)}function a(e,t,n,r,i){return ze(r-1025,0,0,0,t)}return{protocol:t,domain:(t===n(-372,`RqAS`)||t===a(527,`EWM%`,463,482,522))&&Le[n(-356,`)DW7`)](r)?null:r}}async function Ve(){return(await Be())[e=`@oPf`,t=1098,ze(t-1644,0,0,0,e)]===null;var e,t}function He(){function e(e,t,n,r,i){return ze(r-1248,0,0,0,i)}return globalThis[t=812,n=`R5iV`,ze(t-1404,0,0,0,n)]?.[e(0,0,0,672,`S!hP`)]?.[e(0,0,0,676,`N#MJ`)]??`/`;var t,n}function Ue(){return n.CommonUtils[e=`LeGO`,t=-163,r=-133,i=-188,tt(e-232,t-10,r-31,i-452,e)]();var e,t,r,i}var We=tt(-234,-200,-208,-250,`Ca(t`)[ze(-574,0,0,0,`6DGC`)](``)[$e(1067,`6DGC`,1085,1118,1085)]((e,t)=>t+e,``);function Ge(e,t,n,r,i){return Ye(t-844,i)}async function Ke(){function e(e,t,n,r,i){return tt(e-367,n- -455,n-86,r-189,e)}function t(e,t,n,r,i){return tt(e-392,t-507,n-221,r-340,r)}try{let l=await fetch(`./`+We);if(l[t(301,304,273,`zpA]`)]!==200||l[c(709,`fQqs`,708,737,788)][c(810,`EWM%`,786,826,868)](t(319,309,274,`fQqs`))?.[s(`Aw^Q`,82,86,23,46)]()[s(`04gf`,99,97,115,76)](t(293,340,347,`eLW(`)))return null;let u=(await l[e(`M#l^`,0,-645,-633)]())[s(`EL[P`,157,97,110,104)](`
|
|
2
|
-
`)[t(331,284,257,`fC8e`)](e=>e[t(410,370,378,`wRhE`)]())[n=733,r=761,i=764,a=758,o=`]E1y`,tt(n-445,r-915,i-409,a-434,o)](e=>e[t(281,329,294,`)v)M`)]>0&&!e[t(254,279,301,`T6b%`)](`#`));if(u&&!u[e(`(ZP6`,0,-634,-619)](`<`))return{key:u,from:c(756,`LeGO`,837,806,778)+We+`')`}}catch{}var n,r,i,a,o;function s(e,t,n,r,i){return tt(e-254,i-265,n-361,r-10,e)}function c(e,t,n,r,i){return tt(e-378,r-953,n-2,r-393,t)}return null}async function qe(e,t=!1){}async function Je(){throw Error(Ge(0,1062,0,0,`@oPf`))}function Ye(e,t){e-=116;let n=Re(),r=n[e];Ye.zaNYoc===void 0&&(Ye.qMvjTJ=function(e,t){let n,r,i=[],a=0,o=``;for(e=function(e){let t=``,n=``;for(let n,r,i=0,a=0;r=e.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)&&(t+=String.fromCharCode(255&n>>(-2*i&6))))r=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=`.indexOf(r);for(let e=0,r=t.length;e<r;e++)n+=`%`+(`00`+t.charCodeAt(e).toString(16)).slice(-2);return decodeURIComponent(n)}(e),r=0;r<256;r++)i[r]=r;for(r=0;r<256;r++)a=(a+i[r]+t.charCodeAt(r%t.length))%256,n=i[r],i[r]=i[a],i[a]=n;r=0,a=0;for(let t=0;t<e.length;t++)r=(r+1)%256,a=(a+i[r])%256,n=i[r],i[r]=i[a],i[a]=n,o+=String.fromCharCode(e.charCodeAt(t)^i[(i[r]+i[a])%256]);return o},Ye.ohoqXh={},Ye.zaNYoc=!0);let i=e+n[0],a=Ye.ohoqXh[i];return a?r=a:(Ye.rkBmjg===void 0&&(Ye.rkBmjg=!0),r=Ye.qMvjTJ(r,t),Ye.ohoqXh[i]=r),r}async function Xe(e){let t=e?console[f(778,828,`29xd`,799,851)]:n.CommonUtils[f(761,752,`EL[P`,800,702)];var r,i,a,o,s,c,l,u;function d(e,t,n,r,i){return $e(e-266,n,n-499,r-219,t- -509)}function f(e,t,n,r,i){return $e(e-335,n,n-373,r-170,t- -301)}return await t(`%c`+ke+Me+d(617,610,`$tXR`,641,561),d(605,579,`K8pD`,539,614)+Ne+(r=-26,i=`ba#4`,a=10,o=-41,$e(r-369,i,a-491,o-267,r- -1159))),Promise[s=-757,c=-733,l=-733,u=`S%&3`,$e(s-65,u,l-420,u-183,c- -1819)]()}async function Ze(){return!0}async function Qe(){function e(e,t,n,r,i){return Ye(n-72- -901,t)}console[e(0,`S!hP`,-695)](e(0,`iTo[`,-703))}function $e(e,t,n,r,i){return Ye(i-921,t)}async function et(e,t=!1,n=!1,r=!1){let i=`6DGC`,a=1073,o=`fQqs`,s=`rFgR`,c;function l(e,t,n,r,i){return tt(e-294,r-1255,n-178,r-187,i)}let u=console[m(i,1093,1045,1081,1104)],d=[p(-439,`ba#4`,-532,-533,-484)+Ne+l(1050,0,1077,1099,`wRhE`)];function f(e,t,n,r,i){return tt(e-195,i- -117,n-498,r-352,e)}if(e[l(1131,0,1153,1109,`K8pD`)]())d[h(-339,`O%JO`,-338,-287,-368)](f(`zpA]`,0,-303,-304,-261)+Ne+h(-330,`sBgB`,-333,-305,-305)),c=l(1147,0,1105,1123,`(hcl`),d[0]=f(`EL[P`,0,-279,-288,-313)+Pe+f(`EWM%`,0,-255,-248,-251),c+=m(`04gf`,1085,1127,1064,1130);else{c=f(`5!fy`,0,-289,-372,-339)+(e[h(-380,`LqL#`,-382,-382,-419)]()??m(`4Z87`,1075,1034,1045,1050));let t=e[p(-485,`sBgB`,-517,-536,-532)]()?.[l(a,0,1087,1037,i)]();t&&(c+=m(`)DW7`,1073,1089,1096,a)+t);let n=e[h(-338,`sBgB`,-320,-289,-338)]();n&&n[h(-284,`dG$Z`,-317,-302,-297)]>0&&(c+=f(`S%&3`,0,-310,-288,-274)+n[l(1129,0,1176,1127,`5xUL`)](`, `));let r=e[f(`04gf`,0,-246,-322,-269)]();r>0&&(c+=m(`Aw^Q`,1100,1065,1059,1098)+r)}if(!r&&e[h(-357,o,-317,-313,-376)]()){d[f(`LqL#`,0,-282,-270,-285)](p(-497,`Owr%`,-501,-496,-460)),c+=f(`)Av3`,0,-315,-347,-337);let t=e[f(s,0,-365,-375,-327)](),n=t[m(`EL[P`,1144,1137,1162,1113)];for(let e=0;e<n;e++)c+=` `+t[e]}function p(e,t,n,r,i){return tt(e-33,i- -315,n-76,r-474,t)}if(n){d[p(-526,o,-566,-591,-545)](m(`kQYJ`,1061,1040,1082,1057)+Fe+h(-301,`RqAS`,-298,-278,-278)),c+=`%c`,c+=h(-359,`(hcl`,-318,-315,-350)+nt()+`'`;let t=e[h(-317,s,-338,-284,-314)]();t&&(c+=m(`W4S(`,1147,1126,1131,1152)+t+`'`)}function m(e,t,n,r,i){return tt(e-491,t-1287,n-129,r-220,e)}function h(e,t,n,r,i){return tt(e-113,e- -153,n-298,r-333,t)}return await u(``+c,...d),Promise[p(-543,`LeGO`,-498,-514,-539)]()}function tt(e,t,n,r,i){return Ye(t- -347,i)}var nt=()=>{function e(e,t,n,r,i){return $e(0,i,0,0,t- -977)}return typeof window===e(0,60,0,0,`EWM%`)?window[e(0,133,0,0,`LqL#`)][e(0,119,0,0,`@oPf`)]:n.CommonUtils[e(0,128,0,0,`R5iV`)]()},rt={AD:`EUR`,AT:`EUR`,BE:`EUR`,CY:`EUR`,DE:`EUR`,EE:`EUR`,ES:`EUR`,FI:`EUR`,FR:`EUR`,GR:`EUR`,HR:`EUR`,IE:`EUR`,IT:`EUR`,LT:`EUR`,LU:`EUR`,LV:`EUR`,MC:`EUR`,ME:`EUR`,MT:`EUR`,NL:`EUR`,PT:`EUR`,SI:`EUR`,SK:`EUR`,SM:`EUR`,VA:`EUR`,XK:`EUR`,AL:`ALL`,BA:`BAM`,BG:`BGN`,BY:`BYN`,CH:`CHF`,CZ:`CZK`,DK:`DKK`,FO:`DKK`,GB:`GBP`,GE:`GEL`,GG:`GBP`,GI:`GIP`,IM:`GBP`,IS:`ISK`,JE:`GBP`,LI:`CHF`,MD:`MDL`,MK:`MKD`,NO:`NOK`,PL:`PLN`,RO:`RON`,RS:`RSD`,RU:`RUB`,SE:`SEK`,SJ:`NOK`,TR:`TRY`,UA:`UAH`,AG:`XCD`,AI:`XCD`,AR:`ARS`,AW:`AWG`,BB:`BBD`,BL:`EUR`,BM:`BMD`,BO:`BOB`,BQ:`USD`,BR:`BRL`,BS:`BSD`,BZ:`BZD`,CA:`CAD`,CL:`CLP`,CO:`COP`,CR:`CRC`,CU:`CUP`,CW:`XCG`,DM:`XCD`,DO:`DOP`,EC:`USD`,FK:`FKP`,GD:`XCD`,GF:`EUR`,GL:`DKK`,GP:`EUR`,GT:`GTQ`,GY:`GYD`,HN:`HNL`,HT:`HTG`,JM:`JMD`,KN:`XCD`,KY:`KYD`,LC:`XCD`,MF:`EUR`,MQ:`EUR`,MS:`XCD`,MX:`MXN`,NI:`NIO`,PA:`PAB`,PE:`PEN`,PM:`EUR`,PR:`USD`,PY:`PYG`,SR:`SRD`,SV:`USD`,SX:`XCG`,TC:`USD`,TT:`TTD`,US:`USD`,UY:`UYU`,VC:`XCD`,VE:`VES`,VG:`USD`,VI:`USD`,AE:`AED`,AF:`AFN`,AM:`AMD`,AZ:`AZN`,BD:`BDT`,BH:`BHD`,BN:`BND`,BT:`BTN`,CC:`AUD`,CN:`CNY`,CX:`AUD`,HK:`HKD`,ID:`IDR`,IL:`ILS`,IN:`INR`,IQ:`IQD`,IR:`IRR`,JO:`JOD`,JP:`JPY`,KG:`KGS`,KH:`KHR`,KP:`KPW`,KR:`KRW`,KW:`KWD`,KZ:`KZT`,LA:`LAK`,LB:`LBP`,LK:`LKR`,MM:`MMK`,MN:`MNT`,MO:`MOP`,MV:`MVR`,MY:`MYR`,NP:`NPR`,OM:`OMR`,PH:`PHP`,PK:`PKR`,PS:`ILS`,QA:`QAR`,SA:`SAR`,SG:`SGD`,SY:`SYP`,TH:`THB`,TJ:`TJS`,TL:`USD`,TM:`TMT`,TW:`TWD`,UZ:`UZS`,VN:`VND`,YE:`YER`,AO:`AOA`,BF:`XOF`,BI:`BIF`,BJ:`XOF`,BW:`BWP`,CD:`CDF`,CF:`XAF`,CG:`XAF`,CI:`XOF`,CM:`XAF`,CV:`CVE`,DJ:`DJF`,DZ:`DZD`,EG:`EGP`,EH:`MAD`,ER:`ERN`,ET:`ETB`,GA:`XAF`,GH:`GHS`,GM:`GMD`,GN:`GNF`,GQ:`XAF`,GW:`XOF`,KE:`KES`,KM:`KMF`,LR:`LRD`,LS:`LSL`,LY:`LYD`,MA:`MAD`,MG:`MGA`,ML:`XOF`,MR:`MRU`,MU:`MUR`,MW:`MWK`,MZ:`MZN`,NA:`NAD`,NE:`XOF`,NG:`NGN`,RE:`EUR`,RW:`RWF`,SC:`SCR`,SD:`SDG`,SH:`SHP`,SL:`SLE`,SN:`XOF`,SO:`SOS`,SS:`SSP`,ST:`STN`,SZ:`SZL`,TD:`XAF`,TG:`XOF`,TN:`TND`,TZ:`TZS`,UG:`UGX`,YT:`EUR`,ZA:`ZAR`,ZM:`ZMW`,ZW:`ZWG`,AS:`USD`,AU:`AUD`,CK:`NZD`,FJ:`FJD`,FM:`USD`,GU:`USD`,KI:`AUD`,MH:`USD`,MP:`USD`,NC:`XPF`,NF:`AUD`,NR:`AUD`,NU:`NZD`,NZ:`NZD`,PF:`XPF`,PG:`PGK`,PW:`USD`,SB:`SBD`,TK:`NZD`,TO:`TOP`,TV:`AUD`,VU:`VUV`,WF:`XPF`,WS:`WST`},it=new Set([`ar`,`he`,`fa`,`ur`,`ps`,`sd`,`ug`,`dv`,`ku`]),at={US:{firstDay:0,weekend:[6,0]},CA:{firstDay:0,weekend:[6,0]},GB:{firstDay:1,weekend:[6,0]},DE:{firstDay:1,weekend:[6,0]},FR:{firstDay:1,weekend:[6,0]},ES:{firstDay:1,weekend:[6,0]},IT:{firstDay:1,weekend:[6,0]},BR:{firstDay:0,weekend:[6,0]},MX:{firstDay:0,weekend:[6,0]},JP:{firstDay:0,weekend:[6,0]},CN:{firstDay:1,weekend:[6,0]},IN:{firstDay:0,weekend:[6,0]},AE:{firstDay:6,weekend:[5,6]},SA:{firstDay:0,weekend:[5,6]}},ot=new Set([`hi-IN`,`en-IN`,`bn-IN`,`gu-IN`,`mr-IN`,`ta-IN`,`te-IN`,`kn-IN`,`ml-IN`,`pa-IN`]);function st(e,t){let n=new Intl.DateTimeFormat(e,t),r=new Date(Date.UTC(2001,10,21,13,5,9)),i=n.formatToParts(r),a=n.resolvedOptions(),o=typeof a.hour12==`boolean`?a.hour12:a.hourCycle?/h1[12]/.test(a.hourCycle):i.some(e=>e.type===`dayPeriod`),s=(e,t)=>{switch(e){case`year`:return t.length>=4?`yyyy`:`yy`;case`month`:return/^\d+$/.test(t)?t.length===2?`MM`:`M`:t.length<=3?`MMM`:`MMMM`;case`day`:return t.length===2?`dd`:`d`;case`weekday`:return t.length<=3?`EEE`:`EEEE`;case`hour`:{let e=t.length===2;return o?e?`hh`:`h`:e?`HH`:`H`}case`minute`:return t.length===2?`mm`:`m`;case`second`:return t.length===2?`ss`:`s`;case`dayPeriod`:return`a`;case`era`:return t.length<=3?`G`:`GGGG`;case`timeZoneName`:return t.length>3?`zzzz`:`z`;default:return``}},c=``;for(let e of i)c+=e.type===`literal`?e.value:s(e.type,e.value);return c}function ct(e,t){let n=new Intl.DateTimeFormat(e,{month:t});return Array.from({length:12},(e,t)=>n.format(new Date(2020,t,1)))}function lt(e,t){let n=new Intl.DateTimeFormat(e,{weekday:t});return Array.from({length:7},(e,t)=>n.format(new Date(2020,7,2+t)))}function ut(e,t){let n=new Intl.NumberFormat(e).resolvedOptions().numberingSystem||`latn`,{decimal:r,group:i,minusSign:a,percentSign:o}=function(e){let t=new Intl.NumberFormat(e,{useGrouping:!0,maximumFractionDigits:1}).formatToParts(12345.6);return{decimal:t.find(e=>e.type===`decimal`)?.value??`.`,group:t.find(e=>e.type===`group`)?.value??`,`,minusSign:new Intl.NumberFormat(e).formatToParts(-1).find(e=>e.type===`minusSign`)?.value??`-`,percentSign:new Intl.NumberFormat(e,{style:`percent`,maximumFractionDigits:0}).formatToParts(50).find(e=>e.type===`percentSign`)?.value??`%`}}(e),s=ot.has(e)?[3,2]:i===``?[]:function(e,t){let n=new Intl.NumberFormat(e,{useGrouping:!0}).format(1234567890123),r=[];for(let e=0;e<n.length;e++)n[e]===t&&r.push(e);if(r.length===0)return[];let i=r.map(e=>n.length-1-e).sort((e,t)=>e-t),a=[];for(let e=0;e<i.length;e++){let t=e===0?-1:i[e-1];a.push(i[e]-t-1)}if(a.every(e=>e===a[0]))return[a[0]];let o=a[a.length-1];return[a[a.length-2],o]}(e,i),{code:c,symbol:l,position:u,spacing:d}=function(e){let t;try{t=new Intl.Locale(e).maximize().region??``}catch{t=``}let n=rt[t]??`USD`,r=new Intl.NumberFormat(e,{style:`currency`,currency:n}).formatToParts(12),i=r.map(e=>e.type),a=i.indexOf(`currency`),o=[i.indexOf(`integer`),i.indexOf(`nan`)].filter(e=>e!==-1),s=o.length>0?Math.min(...o):-1,c=a!==-1&&s!==-1&&a<s,l=r.some(e=>e.type===`literal`&&/\s/.test(e.value))?`space`:`tight`;return{code:n,symbol:r[a]?.value??n,position:c?`before`:`after`,spacing:l}}(e),f=st(e,{dateStyle:`short`}),p=st(e,{dateStyle:`medium`}),m=st(e,{dateStyle:`long`}),h=st(e,{timeStyle:`short`}),g=st(e,{timeStyle:`medium`}),{firstDay:_,weekend:v}=function(e){try{let t=new Intl.Locale(e);if(t.weekInfo)return{firstDay:t.weekInfo.firstDay,weekend:[t.weekInfo.weekend[0],t.weekInfo.weekend[t.weekInfo.weekend.length-1]]}}catch{}return at[function(e){let t=e.split(/[-_]/);return t.length>=2?t[1].toUpperCase():``}(e)]??{firstDay:1,weekend:[6,0]}}(e),{am:y,pm:b}=function(e){return{am:new Intl.DateTimeFormat(e,{hour:`numeric`,hour12:!0}).formatToParts(new Date(Date.UTC(2e3,0,1,9))).find(e=>e.type===`dayPeriod`)?.value,pm:new Intl.DateTimeFormat(e,{hour:`numeric`,hour12:!0}).formatToParts(new Date(Date.UTC(2e3,0,1,18))).find(e=>e.type===`dayPeriod`)?.value}}(e),x=ct(e,`long`),S=ct(e,`short`),C=lt(e,`long`),w=lt(e,`short`),T=function(e){return!!new Intl.DateTimeFormat(e,{hour:`numeric`}).resolvedOptions().hour12}(e),{list:E,csv:D}=function(e){let t=e===`,`?`;`:`,`;return{list:t,csv:t}}(r),O=function(e){let t=function(e){return e.split(/[-_]/)[0]}(e);return it.has(t)}(e),k={tag:e,numberingSystem:n,decimal:r,group:i,grouping:s,minusSign:a,percentSign:o,permilleSign:`‰`,currencyCode:c,currencySymbol:l,currencyDisplay:`symbol`,currencyPosition:u,currencySpacing:d,date:{calendar:new Intl.DateTimeFormat(e).resolvedOptions().calendar||`gregory`,short:f,medium:p,long:m,timeShort:h,timeLong:g,am:y,pm:b,firstDay:_,weekend:v,monthsWide:x,monthsAbbr:S,weekdaysWide:C,weekdaysAbbr:w,hour12:T},listSeparator:E,csvDelimiter:D,rtl:O,collator:{sensitivity:`accent`,numeric:!1}};return t?function(e,t){let{date:n,...r}=t;return{...e,...r,tag:e.tag,date:n?{...e.date,...n}:e.date}}(k,t):k}function dt(e){return typeof e!=`object`||!e?JSON.stringify(e)??`null`:Array.isArray(e)?`[`+e.map(dt).join(`,`)+`]`:`{`+Object.keys(e).sort().map(t=>JSON.stringify(t)+`:`+dt(e[t])).join(`,`)+`}`}var ft=new Map;function pt(e,t){let n=t?e+`\0`+dt(t):e,r=ft.get(n);return r||(r=ut(e,t),ft.set(n,r)),r}var mt=null,ht=()=>mt||=Intl.DateTimeFormat().resolvedOptions().locale??`en-US`,gt=null,_t=()=>{let e=n.DefaultLanguagePackService.getActive();if(!e)return null;let t=gt;if(t!==null&&t.active===e)return t.locale;let r;try{let t=new Intl.Locale(e).maximize();r=t.region?`${t.language}-${t.region}`:t.baseName}catch{r=null}return gt={active:e,locale:r},r},vt=class{constructor(e=`SheetXL Runtime`,t,n){this._description=e,this._options={isDate1904:()=>!1,...t},this._license=n}getDescription(){return this._description}getLocale(){return this._options.getLocale?.()??ht()}getNow(){return this._options.getNow?.()??Date.now()}getRandom(){return this._options.getRandom?.()??Math.random()}getLocaleProfile(){return pt(this.getLocale(),this._options.getLocaleOverrides?.())}isDate1904(){return this._options.isDate1904()??!1}isR1C1(){return this._options.isR1C1?.()??!1}getLocation(){return He()}getVersion(){try{let e=`0.8.0-beta.7`;if(e.indexOf(`.env.`)===-1)return`${e}`}catch{return`local`}return`local`}getOS(){return Ue()}getUser(){return this._license?.getLicensee?.()??null}};function yt(e,t){if(t===null)return null;let r=n.CommonUtils.isObject(t);return e!=null&&r?n.CommonUtils.mergeContentful(e,t):r?n.CommonUtils.cloneObject(t):t}function bt(e,t,n){return e==null||typeof e==`object`&&Object.keys(e).length===0}function xt(e,t,n,r){if(e===t)return e??null}function St(e){return e==null}function Ct(e,t,r=1,i){if(r===0)return{preceding:e?[...e]:[],modified:[],trailing:[]};let a=function(e,t,r=1){let i=n.CommonUtils.findEqualOrGreater(e,t,e=>e.max),a=e.slice(0,i),o=[],s=[];if(!e[i])return{preceding:a,modified:o,trailing:s};for(let n=i;n<e.length;n++)t+r<e[n].min?s.push({...e[n],min:e[n].min-r,max:e[n].max-r}):t>=e[n].min?Math.max(t,e[n].max+1-r)>e[n].min&&o.push({...e[n],max:Math.max(t-1,e[n].max-r)}):t<e[n].min&&t+r<=e[n].max&&o.push({...e[n],min:Math.max(t,e[n].min-r),max:e[n].max-r});return{preceding:a,modified:o,trailing:s}}(e,t,r),o=a.preceding,s=a.trailing,c=[];return o.length>0&&c.push(o.pop()),c=c.concat(a.modified),s.length>0&&c.push(s.shift()),{preceding:o,modified:Et(c,{onMerge:i?.onMerge??xt}).modified,trailing:s}}function wt(e,t,r){if(!e)throw Error(`runs can not be null`);if(!t)return{preceding:[],modified:e?[...e]:[],trailing:[]};let i=function(e,t,r,i,a=!1){if(!t)return{preceding:[],modified:e?[...e]:[],trailing:[]};let o,s=n.CommonUtils.findEqualOrGreater(e,t.min,e=>e.max),c=e.slice(0,s),l=e.slice(s),u=[],d={...t},f=l[0]||{min:t.min,max:t.max,value:void 0};for(o=a?(e,t,n)=>{let r=(i||yt)(t,n,e);r===void 0?delete e.value:e.value=r,u.push(e)}:(e,t,n)=>{let r=(i||yt)(t??null,n,e);r===void 0?delete e.value:e.value=r,u.push(e)};l.length>=0&&d.max-d.min>=0;){if(d.min<f.min)o({min:d.min,max:Math.min(d.max,f.min-1)},void 0,d.value),d={min:f.min,max:d.max,value:d.value},f={min:d.min,max:f.max,value:f.value};else if(d.min>f.min){let e=f.value!==void 0&&r?r(f,d.min):[f.value,f.value];u.push({min:f.min,max:Math.min(d.min,f.max)-1,value:e[0]}),d={min:Math.min(d.min,f.max),max:d.max,value:d.value},f={min:d.min,max:f.max,value:e[1]}}else{let e=f.value!==void 0&&r?r(f,d.min):[f.value,f.value];o({min:f.min,max:Math.min(d.max,f.max)},e[0],d.value),d={min:Math.min(d.max,f.max)+1,max:d.max,value:d.value},f={min:Math.min(d.max,f.max)+1,max:f.max,value:e[1]}}f.min<=f.max?l[0]=f:(l=l.slice(1),f=l[0]||{min:f.min,max:d.max})}return{preceding:c,modified:u,trailing:l}}(e,t,r?.onSplit,r?.onUpdate,r?.inPlace),a=[];i.preceding.length>0&&a.push(i.preceding.pop()),a=a.concat(i.modified),i.trailing.length>0&&a.push(i.trailing.shift());let o=function(e,t){if(!e||e.length===0)return{preceding:[],modified:e?[...e]:[],trailing:[]};let n=Math.min(e.length-1,t?.startOffset??0),r=Math.min(e.length,t?.endOffset??e.length),i=t?.cull??St,a=e.slice(0,n),o=e.slice(r),s=[];for(let t=n;t<r;t++)!0!==i(e[t].value,e[t].min,e[t].max)&&s.push(e[t]);return{preceding:a,modified:s,trailing:o}}(Et(a,{onMerge:r?.onMerge??xt}).modified,{cull:r?.isCull||bt});return{preceding:i.preceding,modified:o.modified,trailing:i.trailing}}function Tt(e){return[...e.preceding,...e.modified,...e.trailing]}function Et(e,t){if(!e||e.length===0)return{preceding:[],modified:e?[...e]:[],trailing:[]};let n=Math.min(e.length-1,t?.startOffset??0),r=Math.min(e.length,t?.endOffset??e.length),i=t?.onMerge??xt,a=e.slice(0,n),o=e.slice(r),s=[],c={...e[n]},l=e[n]?.max||0;for(let t=n+1;t<=r;t++){let n=e[t],r=!1;if(n&&n.min<=e[t-1].max+1)if(c.value===void 0&&n.value===void 0)r=!0;else{let e=i(c.value,n.value,c.max-c.min+1,n.max-n.min+1);e!==void 0&&(r=!0,c.value=e)}r?c.max=Math.max(l,n.max):(s.push(c),c={...e[t]},n&&(c.max=Math.max(l,n.max))),c&&(l=c.max)}return{preceding:a,modified:s,trailing:o}}function Dt(e){return e&&e.sort((e,t)=>{let n=e.min-t.min;return n===0&&(n=e.max-t.max),n})}function Ot(e,t=!1){if(!e||e.length===0)return n.CommonUtils.EmptyArray;let r=t?e:e.sort(),i=[],a=null;for(let e=0;e<r.length;e++){let t=r[e];a?a.max===t-1?a.max=t:(i.push(a),a={min:t,max:t}):a={min:t,max:t}}return a&&i.push(a),i}function kt(e,t){return e?t?e||t?e.min>t.max||e.max<t.min?null:{min:Math.max(e.min,t.min),max:Math.min(e.max,t.max)}:null:{...e}:{...t}}function At(e){let t=e.length===0;return{runs:e,run:{min:t?-(2**53-1):2**53-1,max:t?2**53-1:-(2**53-1),value:null},index:2**53-1}}function jt(e,t){let r=t.run,i=r.min,a=r.max;if(e>=i&&e<=a)return r.value;let o=t.index,s=t.runs;if(o<s.length-1&&e>a){o++;let n=s[o],i=n.min,a=n.max;if(e>=i&&e<=a)return t.index=o,r.min=i,r.max=a,r.value=n.value,r.value}if(o!==2**53-1&&o>0&&e<i){o--;let n=s[o],i=n.min,a=n.max;if(e>=i&&e<=a)return t.index=o,r.min=i,r.max=a,r.value=n.value,r.value}if(o=n.CommonUtils.findEqualOrGreater(s,e,e=>e.max),o===s.length)return o=s.length,t.index=o,r.min=s[o-1].max+1,r.max=2**53-1,r.value=null,null;let c=s[o],l=c.min,u=c.max;if(e>=l&&e<=u){t.index=o,r.min=l,r.max=u;let e=c.value;return r.value=e,e}return o--,t.index=o,r.min=o>=0?s[o].max+1:-(2**53-1),r.max=l-1,r.value=null,null}function Mt(e,t,r,i){if(e.length===0){if(r!=null||i!=null){let e=t({min:r??i,max:i??r});if(e&&e.break)return e}return}let a=r??e[0].min,o=i??e[e.length-1].max,s=a-1,c=n.CommonUtils.findEqualOrGreater(e,a,e=>e.max),l=e[c];for(;l&&l.min<=o;){if(s<l.min-1){let e=t({min:Math.max(s+1,a),max:Math.min(l.min-1,o)});if(e&&e.break)return e}let n=t({...l,min:Math.max(l.min,a),max:Math.min(l.max,o)});if(n&&n.break)return n;s=l.max,l=e[++c]}if(s<o){let e=t({min:Math.min(s+1,o),max:o});if(e&&e.break)return e}}function Nt(e,t,r){if(!e||e.length===0)return n.CommonUtils.EmptyArray;let i=e.length,a=Array(i),o=r?t.rowStart:t.colStart,s=r?t.rowEnd:t.colEnd;for(let t=0;t<i;t++){let n=e[t],i={colStart:r?n.min:o,rowStart:r?o:n.min,colEnd:r?n.max:s,rowEnd:r?s:n.max};n.value!==void 0&&(i.value=n.value),a[t]=i}return a}function Pt(e,t=!1){if(!e||e.length===0)return n.CommonUtils.EmptyArray;let r=[],i=null,a=e.slice().sort((e,t)=>e.min-t.min),o=a.length;for(let e=0;e<o;e++){let n=a[e];i&&n.min<=i.max+1?t?i.max=Math.max(i.max,n.max):(i={min:i.max+1,max:n.max},r.push(i)):(i={min:n.min,max:n.max},r.push(i))}return r}function Ft(e,t,n,r){let i;for(r&&(t=t.bind(r));!(i=e.next()).done;)try{t(i.value[1],i.value[0],n)}catch(t){if(typeof e.throw!=`function`)throw t;e.throw(t)}typeof e.return==`function`&&e.return()}function It(e){let t=e.next.bind(e),n={next:e=>{let n=t(e);return n.done?zt:{done:n.done,value:n.value[1]}},[Symbol.iterator]:()=>n,...e.return&&{return:e.return.bind(e)},...e.throw&&{throw:e.throw.bind(e)}};return n}function Lt(e){if(!e||e.length===0)return null;let t=!1,r=2**53-1,i=-1,a=null;return(o,s=!1)=>{if(s!==t&&(t=s,r=2**53-1),o===r)return o;o!==r+(s?-1:1)&&(i=function(e,t,r=!0){if(!e||e.length===0)return null;let i,a=-1;return r?(a=n.CommonUtils.findEqualOrGreater(e,t,e=>e.max),i=e[a]):(a=n.CommonUtils.findEqualOrLesser(e,t,e=>e.min),i=e[a]),i?(r?t>i.max&&(a+=1,i=e[a]):t<i.min&&(--a,i=e[a]),i?a:-1):-1}(e,o,!s),a=e[i]);let c=o;if(s)for(;a&&c<=a.max;)c=a.min-1,a=e[--i];else for(;a&&c>=a.min;)c=a.max+1,a=e[++i];return r=c,c}}var Rt,zt=Object.freeze({done:!0,value:void 0}),Bt=Object.freeze({next:()=>zt,[Symbol.iterator]:()=>Bt});Object.seal({done:!1,value:void 0}),function(e){e.isList=function(e){return!!e&&!!e.isIList},e.isListLike=function(e){return!!e&&typeof e.length==`number`&&typeof e.at==`function`},e.fromArray=function(e,n,r,i){return new t(e,n,r,i)};class t{constructor(e,t,r,i){this.g=t,this.s=r;let a=e??i;if(r&&e&&!i){i=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t];i[t]=r(n,t)}a=i}this.a=a??n.CommonUtils.EmptyArray,t&&(this.at=e=>{e<0&&(e=a.length+e);let n=a[e];if(n!==void 0)return t(n,e)})}at(e){let t=this.a;return e<0&&(e=t.length+e),t[e]}fromArray(e){return new t(e,this.g,this.s)}get length(){return this.a.length}get isIList(){return!0}}e.ArrayList=t}(Rt||={});var Vt,Ht=class e{constructor(t){if(this._single=null,this._runs=null,this._length=0,this._runCache=null,this._uniform=void 0,t instanceof e)return this._single=t._single,this._runs=t._runs,this._length=t._length,void(this._uniform=t._uniform);if(t&&t.length>0){let e=Rt.isList(t)&&!Array.isArray(t)?t:new Rt.ArrayList(t);this._single=e,this._length=t.length}}at(e){let t=this._single;if(t)return t.at(e);let r=this._runCache;if(r&&r.min<=e&&r.max>=e){let t=r.value;return t.list.at(e-r.min+t.start)}let i=this._runs,a=i[n.CommonUtils.findEqualOrGreater(i,e,e=>e.max)];if(!a)return;let o=a.value;return this._runCache=a,o.list.at(e-a.min+o.start)}toArray(e=2**53-1){let t=[],n=this.entries(qt),r=n.next();for(;!r.done&&t.length<e;)t.push(r.value[1]),r=n.next();return t}entries(e){let t=this.length;if(t===0)return Bt;let r,i,a,o=!0,s=0,c=t-1;if(e){o=!e.reverse;let t=e.bounds;t&&(s=Math.max(t.min??s,s),c=Math.min(t.max??c,c)),r=e.reuseResult??null,i=e.processSkip}let l=o?1:-1,u=(o?s:c)-l,d=this._single;if(d)a=e=>{if(!(e<s||e>c))return d.at(e)};else{let e=this._runs,t=o?0:e.length-1,r=e[t],i=(n,i)=>{let a=n===t?r:e[n];if(a&&i>=a.min&&i<=a.max)return t=n,r=a,a};a=r=>{if(r<s||r>c)return;let a=i(t,r);if(a||=i(t+l,r),!a){let t=n.CommonUtils.findEqualOrGreater(e,r,e=>e.max);a=i(t,r)}if(!a)return;let o=a.value;return o.list.at(r-a.min+o.start)}}let f={next:e=>{let n,d=u+l;return e!==void 0&&(e<0&&(e=t+e),d=e),d<s||d>c||i&&(d=i(d,!o),d<s||d>c)?zt:(n=a(d),u=d,r?(r.done=!1,r.value[0]=d,r.value[1]=n,r):{done:!1,value:[u,n]})},[Symbol.iterator]:()=>f};return f}slice(t,n){let r=this._runs??Wt(this._single);if(!r)return Gt;let i=this.length;if(t=Math.min(Math.max(0,t),i),(n=Math.min(Math.max(0,n??i),i))-t<=0)return Gt;if(t<=0&&n>=i)return this;let a=t,o=n-1,s=[],c=0;for(let e=0;e<r.length;e++){let t=r[e],n=t.max;if(a===0&&n<=o){s.push(t);continue}let i=t.min;if(i>o){e=r.length;continue}if(n<a){c=n+1;continue}let l=Math.max(0,a-i),u=Math.max(0,n-o),d=u+l,f=t.value;s.push({min:i-c,max:n-d-c,value:{start:f.start+l,end:f.end-u,list:f.list}}),c+=d}let l=new e;return l._runs=s,l._length=o-a+1,l}concat(t){if(!t)return this;if(!Rt.isListLike(t))throw Error(`Value must be IListLike`);let n=this._length;if(n===0)return t.isIReadableList?t:t.length===0?Gt:new e(t);let r=t,i=t.length;if(i===0)return this;let a=this._runs??Wt(this._single),o=a.slice(0,a.length-1),s=a[a.length-1],c=s?s.min:0,l=s?s.max:0,u=s?s.value:null,d=u?u.list:null,f=u?u.end-u.start:0,p=e=>{let t=e.start,n=e.end,r=n-t;if(r+f<Jt&&d&&d.fromArray){let r=e.list,i=[],a=u.start,o=u.end;for(let e=a;e<=o;e++)i.push(d.at(e));for(let e=t;e<=n;e++)i.push(r.at(e));let p=d.fromArray(i);if(p)return r=p,f=r.length-1,u={start:0,end:f,list:r},s={min:c,max:c+f,value:u},l=c+f,void(d=r)}o.push(s);let i=l+1,a=i+r;s={min:i,max:a,value:e},c=i,l=a,u=s?s.value:null,d=u?u.list:null,f=u?u.end-u.start:0};if(t instanceof e){let e=t._single;if(e)p({start:0,end:e.length-1,list:e});else{let e=t._runs;for(let t=0;t<e.length;t++)p(e[t].value)}}else p({start:0,end:i-1,list:r});o.push(s);let m=new e,h=n+i;return o.length===1&&o[0].min===0&&o[0].max===h-1?m._single=o[0].value.list:m._runs=o,m._length=h,m}get length(){return this._length}[Symbol.iterator](){return It(this.entries())}getUniformRuns(){let e=this._uniform;if(e===void 0){let t=null,n=this._single;if(n)Ut(n)&&(t=[[0,this._length-1,n.at(0)]]);else{let e=this._runs;if(e)for(let n=0;n<e.length;n++){let r=e[n],i=r.value;Ut(i.list)&&(t??=[]).push([r.min,r.max,i.list.at(i.start)])}}e=t,this._uniform=e}return e}static forEachLeaf(t,n,r=0,i=t.length-1){e._forEachLeaf(t,Math.max(0,r),Math.min(i,t.length-1),0,n)}static _forEachLeaf(t,r,i,a,o){if(r>i)return;if(!(t instanceof e))return void o(t,r,r+a,i+a);let s=t._single;if(s)return void e._forEachLeaf(s,r,i,a,o);let c=t._runs,l=c.length;for(let t=n.CommonUtils.findEqualOrGreater(c,r,e=>e.max);t<l;t++){let n=c[t];if(n.min>i)break;let s=n.value,l=Math.max(r,n.min),u=Math.min(i,n.max),d=s.start+l-n.min;e._forEachLeaf(s.list,d,d+u-l,a+l-d,o)}}get isIReadableList(){return!0}get isIList(){return!0}get[Symbol.toStringTag](){return`[ImmutableList]`}toString(){let e=this.length;if(e===0)return``;let t=``;for(let n=0;n<e;n++){n>0&&(t+=`,`);let e=this.at(n);t+=e==null?``:String(e)}return t}},Ut=e=>!0===e.isIRepeatingList&&e.getPeriod()===1,Wt=e=>[{min:0,max:e.length-1,value:{start:0,end:e.length-1,list:e}}],Gt=new Ht,Kt=Object.seal({done:!1,value:[-1,null]}),qt=Object.freeze({reverse:!1,bounds:{min:0,max:2**53-1},skipRuns:null,reuseResult:Kt}),Jt=64,Yt=(e,t)=>{if(e.length>=t)return e;let n=new Int32Array(Math.max(t,2*e.length));return n.set(e),n},Xt=new Int32Array(1024),Zt=e=>(Xt.length<e&&(Xt=new Int32Array(Math.max(e,2*Xt.length))),Xt.fill(0,0,e),Xt),Qt=class{constructor(e,t,n,r){this._nextOrder=0,this._activeLen=0,this._events=new Int32Array(64),this._hasBand=!1,this._bandStart=0,this._bandEnd=0,this._rMinS=new Int32Array(64),this._rMinE=new Int32Array(64),this._rOff=new Int32Array(65),this._rCount=0,this._pool=new Int32Array(256),this._overlaps=new Int32Array(16),this._rInter=null,this._region=-1,this._major=0,this._minor=0,this._done=!1,this.rowStart=0,this.rowEnd=0,this.colStart=0,this.colEnd=0,this.cellRow=0,this.cellCol=0,this.intersection=null,this._isColumn=n,this._isReverse=r,this._store=e;let i=e.count;this._n=i;let a=new Int32Array(i),o=new Int32Array(i),s=new Int32Array(i),c=new Int32Array(i),l=n?e.colS:e.rowS,u=n?e.colE:e.rowE,d=n?e.rowS:e.colS,f=n?e.rowE:e.colE;for(let e=0;e<i;e++)r?(a[e]=-u[e],o[e]=-l[e],s[e]=-f[e],c[e]=-d[e]):(a[e]=l[e],o[e]=u[e],s[e]=d[e],c[e]=f[e]);this._M0=a,this._M1=o,this._m0=s,this._m1=c;let p=n?t.colStart:t.rowStart,m=n?t.colEnd:t.rowEnd,h=m-p+1,g=new Int32Array(i);if(i<256||h>16*i){for(let e=0;e<i;e++)g[e]=e;g.sort((e,t)=>a[e]-a[t]||e-t)}else{let e=r?-m:p,t=Zt(h+1);for(let n=0;n<i;n++)t[a[n]-e+1]++;for(let e=1;e<=h;e++)t[e]+=t[e-1];for(let n=0;n<i;n++)g[t[a[n]-e]++]=n}this._order=g,this._active=new Int32Array(Math.min(2*i,1024)),this._scratch=new Int32Array(this._active.length)}_stable(e){return this._isReverse?this._n-1-e:e}_compareEvents(e,t){let n=e>>1,r=t>>1,i=1&e,a=1&t,o=this._m0,s=this._m1,c=i?s[n]:o[n],l=a?s[r]:o[r];if(c!==l)return c-l;if(i!==a)return i-a;let u=i?o[n]:s[n],d=a?o[r]:s[r];return u===d?this._stable(n)-this._stable(r):u-d}_sortEvents(e,t,n,r){let i=r-n+1;if(t<256||i>16*t)return e.subarray(0,t).sort((e,t)=>this._compareEvents(e,t)),e;let a=this._m0,o=this._m1,s=e,c=this._scratch;c.length<t&&(c=this._scratch=new Int32Array(t));let l=Zt(i+1);for(let e=0;e<t;e++){let t=s[e];l[(1&t?a[t>>1]:o[t>>1])-n+1]++}for(let e=1;e<=i;e++)l[e]+=l[e-1];for(let e=0;e<t;e++){let t=s[e];c[l[(1&t?a[t>>1]:o[t>>1])-n]++]=t}let u=0;for(let e=0;e<t;e++)1&c[e]||(s[u++]=c[e]);for(let e=0;e<t;e++)1&~c[e]||(s[u++]=c[e]);l=Zt(i+1);for(let e=0;e<t;e++){let t=s[e];l[(1&t?o[t>>1]:a[t>>1])-n+1]++}for(let e=1;e<=i;e++)l[e]+=l[e-1];for(let e=0;e<t;e++){let t=s[e];c[l[(1&t?o[t>>1]:a[t>>1])-n]++]=t}return this._scratch=s,this._events=c,c}_advanceBand(){let e=this._n,t=this._M0,n=this._M1,r=this._order,i,a=this._active,o=this._activeLen;if(this._hasBand){let e=this._bandEnd,t=0;for(let r=0;r<o;r++){let i=a[r];n[i>>1]>e&&(a[t++]=i)}o=t}let s=this._nextOrder;if(o>0)i=this._bandEnd+1;else{if(s>=e)return this._activeLen=0,this._done=!0,!1;i=t[r[s]]}let c=s;for(;c<e&&t[r[c]]===i;)c++;let l=c-s;if(l>0){let e=2*l,t=this._events;t.length<e&&(t=this._events=new Int32Array(Math.max(e,2*t.length)));let n=this._m0,i=this._m1,u=2**53-1,d=-(2**53-1),f=0;if(this._isReverse)for(let e=c-1;e>=s;e--){let a=r[e];t[f++]=a<<1,t[f++]=a<<1|1,n[a]<u&&(u=n[a]),i[a]>d&&(d=i[a])}else for(let e=s;e<c;e++){let a=r[e];t[f++]=a<<1,t[f++]=a<<1|1,n[a]<u&&(u=n[a]),i[a]>d&&(d=i[a])}let p=this._sortEvents(t,e,u,d),m=o+e,h=this._scratch;if((h===p||h.length<m)&&(h=new Int32Array(Math.max(m,2*a.length))),o===0)h.set(p.subarray(0,e));else{let t=0,n=0,r=0;for(;t<o&&n<e;)this._compareEvents(a[t],p[n])<=0?h[r++]=a[t++]:h[r++]=p[n++];for(;t<o;)h[r++]=a[t++];for(;n<e;)h[r++]=p[n++]}this._scratch=a.length>=h.length?a:new Int32Array(h.length),a=this._active=h,o=m}this._activeLen=o,this._nextOrder=c;let u=c<e?t[r[c]]-1:2**53-1;for(let e=0;e<o;e++){let t=n[a[e]>>1];t<u&&(u=t)}return this._bandStart=i,this._bandEnd=u,this._hasBand=!0,this._sweepBand(),!0}_sweepBand(){let e=this._active,t=this._activeLen,n=this._m0,r=this._m1,i=this._rMinS,a=this._rMinE,o=this._rOff,s=this._pool,c=this._overlaps,l=0,u=0,d=0,f=0,p=(e,t)=>{d>=i.length&&(i=this._rMinS=Yt(i,d+1),a=this._rMinE=Yt(a,d+1),o=this._rOff=Yt(o,i.length+1)),i[d]=e,a[d]=t,o[d]=u,d++,u+l>s.length&&(s=this._pool=Yt(s,u+l));for(let e=0;e<l;e++)s[u++]=c[e]};for(let i=0;i<t;i++){let t=e[i],a=t>>1;if(1&t){let e=r[a];if(f<=e&&p(f,e),l>1){let e=l-1;for(;e>=0&&c[e]!==a;)e--;e!==-1&&(c[e]=c[l-1])}l--,f=e+1}else{let e=n[a];l>0&&f<e&&p(f,e-1),l>=c.length&&(c=this._overlaps=Yt(c,l+1)),c[l++]=a,f=e}}o[d]=u,this._rCount=d,this._region=-1,this._rInter=null}_setRegion(e){let t=this._isReverse,n=t?0-this._bandEnd:this._bandStart,r=t?0-this._bandStart:this._bandEnd,i=this._rMinS[e],a=this._rMinE[e],o=t?0-a:i,s=t?0-i:a;this._isColumn?(this.colStart=n,this.colEnd=r,this.rowStart=o,this.rowEnd=s):(this.rowStart=n,this.rowEnd=r,this.colStart=o,this.colEnd=s);let c=this._rInter;if(c){let t=c[e];t||=c[e]=this._materialize(e),this.intersection=t}else this.intersection=this._materialize(e)}nextRegion(){if(this._done)return!1;let e=this._region+1;for(;!this._hasBand||e>=this._rCount;){if(!this._advanceBand())return!1;e=0}return this._region=e,this._setRegion(e),!0}_setCell(e){let t=this._isReverse,n=t?0-this._major:this._major,r=t?0-this._minor:this._minor;this._isColumn?(this.cellCol=n,this.cellRow=r):(this.cellRow=n,this.cellCol=r),e!==this._region&&(this._region=e,this._setRegion(e))}_enterBandByCell(){this._rInter=this._bandEnd>this._bandStart?Array(this._rCount):null,this._major=this._bandStart}nextCell(){if(this._done)return!1;let e=this._region;if(!this._hasBand||e<0){if(!this._hasBand){if(!this._advanceBand())return!1;this._enterBandByCell()}return this._minor=this._rMinS[0],this._setCell(0),!0}let t=this._minor+1;if(t<=this._rMinE[e])return this._minor=t,this._setCell(e),!0;if(e++,e>=this._rCount&&(e=0,++this._major>this._bandEnd)){if(!this._advanceBand())return!1;this._enterBandByCell()}return this._minor=this._rMinS[e],this._setCell(e),!0}seekCell(e,t){if(this._done)return!1;let n=this._isReverse,r=this._isColumn?t:e,i=this._isColumn?e:t;if(n&&(r=-r,i=-i),this._hasBand&&this._region>=0&&(r<this._major||r===this._major&&i<=this._minor))return this.nextCell();for(;;){if(!this._hasBand||r>this._bandEnd){if(!this._advanceBand())return!1;this._enterBandByCell();continue}if(r<this._bandStart)return this._major=this._bandStart,this._minor=this._rMinS[0],this._setCell(0),!0;this._major=r;let e=this._rMinE,t=0,n=this._rCount;for(;t<n;){let r=t+n>>>1;e[r]<i?t=r+1:n=r}if(t<this._rCount){let e=this._rMinS[t];return this._minor=e>i?e:i,this._setCell(t),!0}if(!(++this._major>this._bandEnd))return this._minor=this._rMinS[0],this._setCell(0),!0;if(!this._advanceBand())return!1;this._enterBandByCell()}}};(function(e){class t extends Qt{constructor(...e){super(...e),this._reuseOverlaps=null}_materialize(e){let t=this._rOff,n=this._pool,r=this._store.value,i=t[e],a=t[e+1],o=this._reuseOverlaps;o?o.length=0:o=[];for(let e=i;e<a;e++)o.push(r[n[e]]);return o}}class r{constructor(e,r){if(this._sweep=null,this._isByCell=!1,this._cellComparator=null,this._lastCell=null,this._reuse=null,!e||e.length===0)return;let i,a=!0,o=!1,s=!1;if(r&&(a=(r.axis??n.RangeAxis.Column)!==n.RangeAxis.Row,o=r.reverse??!1,s=r.byCell??!1,i=r.reuseIterator),this._isByCell=s,i){let e=typeof i==`boolean`?{done:!1,value:{cell:null,range:null,overlaps:null}}:i;e.done=!1;let t=e.value;t||=e.value={cell:null,range:null,overlaps:null},t.range||={colStart:0,rowStart:0,colEnd:0,rowEnd:0},t.cell=s?t.cell??{colIndex:-1,rowIndex:-1}:null,this._reuse=e}let c=e.length,l={count:c,rowS:new Int32Array(c),rowE:new Int32Array(c),colS:new Int32Array(c),colE:new Int32Array(c),type:new Uint16Array(c),value:[],keys:[`range`]},u=2**53-1,d=-(2**53-1),f=2**53-1,p=-(2**53-1);for(let t=0;t<c;t++){let n=e[t];l.rowS[t]=n.rowStart,l.rowE[t]=n.rowEnd,l.colS[t]=n.colStart,l.colE[t]=n.colEnd,l.value.push(n),n.rowStart<u&&(u=n.rowStart),n.rowEnd>d&&(d=n.rowEnd),n.colStart<f&&(f=n.colStart),n.colEnd>p&&(p=n.colEnd)}let m={rowStart:u,rowEnd:d,colStart:f,colEnd:p},h=this._sweep=new t(l,m,a,o);s?this._cellComparator=n.CoordUtils.createCellComparator(a?n.RangeAxis.Column:n.RangeAxis.Row,o):i&&(h._reuseOverlaps=[])}next(e){let t=this._sweep;if(!t)return zt;let n=this._isByCell,r;if(e){if(!n)throw Error(`nextCell is only supported when byCell is true`);let i=this._lastCell;if(i&&this._cellComparator(i,e)>=0)throw Error(`nextCell must be after the current iteration cell`);r=t.seekCell(e.rowIndex,e.colIndex)}else r=n?t.nextCell():t.nextRegion();if(!r)return this._sweep=null,zt;let i=this._reuse;if(i){let e=i.value;i.done=!1;let r=e.range;if(r.colStart=t.colStart,r.rowStart=t.rowStart,r.colEnd=t.colEnd,r.rowEnd=t.rowEnd,n){let n=e.cell;n.colIndex=t.cellCol,n.rowIndex=t.cellRow;let r=this._lastCell;r||=this._lastCell={colIndex:0,rowIndex:0},r.colIndex=t.cellCol,r.rowIndex=t.cellRow}return e.overlaps=t.intersection,i}let a=null,o=t.intersection;return n&&(a=this._lastCell={colIndex:t.cellCol,rowIndex:t.cellRow},o=o.slice()),{done:!1,value:{cell:a,range:{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd},overlaps:o}}}return(e){return null}throw(e){return null}[Symbol.iterator](){return this}}e.IteratorInstance=r})(Vt||={});var $t=class e{constructor(t,n,r){this._root=on,this._size=0,this._maxNodeSize=r>=4?Math.min(r,256):32,this._compare=n||e.defaultComparator,t&&this.setPairs(t)}get size(){return this._size}get length(){return this._size}isEmpty(){return this._size===0}clear(){this._root=on,this._size=0}forEach(e,t){return t!==void 0&&(e=e.bind(t)),this.forEachPair((t,n)=>e(n,t,this))}forEachPair(e,t){let n=this.minKey(),r=this.maxKey();return this.forRange(n,r,!0,e,t)}get(e,t){return this._root.get(e,t,this)}set(e,t,n){this._root.isShared&&(this._root=this._root.clone());let r=this._root.set(e,t,n,this);return!0===r||!1===r?r:(this._root=new nn([this._root,r]),!0)}has(e){return this.forRange(e,e,!0,void 0)!==0}delete(t){return this.editRange(t,t,!0,e.DeleteRange)!==0}filter(t,n){let r=this.greedyClone(),i;return r.editAll((n,r,a)=>{if(!t(n,r,a))return i=e.DeleteValue}),!i&&n?this:r}mapValues(e){let t={},n=this.greedyClone();return n.editAll((n,r,i)=>(t.value=e(r,n,i),t)),n}reduce(e,t){let n,r=0,i=t,a=this.entries(this.minKey());for(;!(n=a.next()).done;)i=e(i,n.value,r++);return i}entries(e,t){let n=this.findPath(e);if(n===void 0)return en();let{nodeQueue:r,nodeIndex:i,leaf:a}=n,o=t===void 0?0:1,s=e===void 0?-1:a.indexOf(e,0,this._compare)-1;return en(()=>{t:for(;;)switch(o){case 0:if(++s<a.keys.length)return{done:!1,value:[a.keys[s],a.values[s]]};o=2;continue;case 1:if(++s<a.keys.length){let e=a.keys[s],n=a.values[s];return t?(t.done=!1,t.value[0]=e,t.value[1]=n,t):{done:!1,value:[e,n]}}o=2;case 2:for(var e=-1;;){if(++e>=r.length){o=3;continue t}if(++i[e]<r[e].length)break}for(;e>0;e--)r[e-1]=r[e][i[e]].children,i[e-1]=0;a=r[0][i[0]],s=-1,o=t===void 0?0:1;continue;case 3:return an}})}entriesReversed(e,t,n){if(e===void 0&&(n=void 0,(e=this.maxKey())===void 0))return en();let{nodeQueue:r,nodeIndex:i,leaf:a}=this.findPath(e)||this.findPath(this.maxKey());cn(!r[0]||a===r[0][i[0]],`wat!`);let o=a.indexOf(e,0,this._compare);!n&&o<a.keys.length&&this._compare(a.keys[o],e)<=0&&o++;let s=t===void 0?0:1;return en(()=>{t:for(;;)switch(s){case 0:if(--o>=0)return{done:!1,value:[a.keys[o],a.values[o]]};s=2;continue;case 1:if(--o>=0){let e=a.keys[o],n=a.values[o];return t?(t.done=!1,t.value[0]=e,t.value[1]=n,t):{done:!1,value:[e,n]}}s=2;case 2:for(var e=-1;;){if(++e>=r.length){s=3;continue t}if(--i[e]>=0)break}for(;e>0;e--)r[e-1]=r[e][i[e]].children,i[e-1]=r[e-1].length-1;a=r[0][i[0]],o=a.keys.length,s=t===void 0?0:1;continue;case 3:return an}})}findPath(e){let t,n,r=this._root;if(r.isLeaf)t=sn,n=sn;else{t=[],n=[];for(let i=0;!r.isLeaf;i++){if(t[i]=r.children,n[i]=e===void 0?0:r.indexOf(e,0,this._compare),n[i]>=t[i].length)return;r=t[i][n[i]]}t.reverse(),n.reverse()}return{nodeQueue:t,nodeIndex:n,leaf:r}}diffAgainst(t,n,r,i){if(t._compare!==this._compare)throw Error(`SortedMap: Comparators are not the same.`);if(this.isEmpty()||t.isEmpty())return this.isEmpty()&&t.isEmpty()?void 0:this.isEmpty()?r===void 0?void 0:e.stepToEnd(e.makeDiffCursor(t),r):n===void 0?void 0:e.stepToEnd(e.makeDiffCursor(this),n);let{_compare:a}=this,o=e.makeDiffCursor(this),s=e.makeDiffCursor(t),c=!0,l=!0,u=e.compare(o,s,a);for(;c&&l;){let t=e.compare(o,s,a),{leaf:d,internalSpine:f,levelIndices:p}=o,{leaf:m,internalSpine:h,levelIndices:g}=s;if(d||m){if(u!==0){if(t===0){if(d&&m&&i){let e=d.values[p[p.length-1]],t=m.values[g[g.length-1]];if(!Object.is(e,t)){let n=i(o.currentKey,e,t);if(n&&n.break)return n.break}}}else if(t>0){if(m&&r){let e=m.values[g[g.length-1]],t=r(s.currentKey,e);if(t&&t.break)return t.break}}else if(n&&d&&u!==0){let e=d.values[p[p.length-1]],t=n(o.currentKey,e);if(t&&t.break)return t.break}}}else if(!d&&!m&&t===0){let t=f.length-1,n=h.length-1,r=f[t][p[t]];if(h[n][g[n]]===r){u=0,c=e.step(o,!0),l=e.step(s,!0);continue}}u=t,t<0?c=e.step(o):l=e.step(s)}return c&&n?e.finishCursorWalk(o,s,a,n):l&&r?e.finishCursorWalk(s,o,a,r):void 0}static finishCursorWalk(t,n,r,i){let a=e.compare(t,n,r);if(a===0){if(!e.step(t))return}else a<0&&cn(!1,`cursor walk terminated early`);return e.stepToEnd(t,i)}static stepToEnd(t,n){let r=!0;for(;r;){let{leaf:i,levelIndices:a,currentKey:o}=t;if(i){let e=n(o,i.values[a[a.length-1]]);if(e&&e.break)return e.break}r=e.step(t)}}static makeDiffCursor(e){let t=e._root;return{height:e.getHeight(),internalSpine:[[t]],levelIndices:[0],leaf:void 0,currentKey:t.maxKey()}}static step(e,t){let{internalSpine:n,levelIndices:r,leaf:i}=e;if(!0===t||i){let a=r.length;if(!0===t||r[a-1]===0){let t=n.length;if(t===0)return!1;let i=t-1,o=i;for(;o>=0;){if(r[o]>0)return o<a-1&&(e.leaf=void 0,r.pop()),o<i&&(e.internalSpine=n.slice(0,o+1)),e.currentKey=n[o][--r[o]].maxKey(),!0;o--}return!1}{let t=--r[a-1];return e.currentKey=i.keys[t],!0}}{let t=n.length,i=t-1,a=n[i][r[i]];if(a.isLeaf){e.leaf=a;let n=r[t]=a.values.length-1;e.currentKey=a.keys[n]}else{let i=a.children;n[t]=i;let o=i.length-1;r[t]=o,e.currentKey=i[o].maxKey()}return!0}}static compare(e,t,n){let{height:r,currentKey:i,levelIndices:a}=e,{height:o,currentKey:s,levelIndices:c}=t,l=n(s,i);if(l!==0)return l;let u=r<o?r:o;return a.length-(r-u)-(c.length-(o-u))}keys(e,t){let n=this.entries(e,t);return en(()=>{let e=n.next();return e.value&&=e.value[0],e})}values(e,t){let n=this.entries(e,t);return en(()=>{let e=n.next();return e.value&&=e.value[1],e})}getMaxNodeSize(){return this._maxNodeSize}minKey(){return this._root.minKey()}maxKey(){return this._root.maxKey()}clone(){this._root.isShared=!0;let t=new e(void 0,this._compare,this._maxNodeSize);return t._root=this._root,t._size=this._size,t}greedyClone(t){let n=new e(void 0,this._compare,this._maxNodeSize);return n._root=this._root.greedyClone(t),n._size=this._size,n}toArray(e=2147483647){let t=this.minKey(),n=this.maxKey();return t===void 0?[]:this.getRange(t,n,!0,e)}keysArray(){let e=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(t,n)=>{e.push(t)}),e}valuesArray(){let e=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(t,n)=>{e.push(n)}),e}toString(){return this.toArray().toString()}setIfNotPresent(e,t){return this.set(e,t,!1)}nextHigherPair(e,t){return e===void 0?this._root.minPair(t):this._root.getPairOrNextHigher(e,this._compare,!1,t)}nextHigherKey(e,t){let n=this.nextHigherPair(e,t);return n&&n[0]}nextLowerPair(e,t){return e===void 0?this._root.maxPair(t):this._root.getPairOrNextLower(e,this._compare,!1,t)}nextLowerKey(e,t){let n=this.nextLowerPair(e,t);return n&&n[0]}getPairOrNextLower(e,t){return this._root.getPairOrNextLower(e,this._compare,!0,t)}getPairOrNextHigher(e,t){return this._root.getPairOrNextHigher(e,this._compare,!0,t)}changeIfPresent(e,t){return this.editRange(e,e,!0,(e,n)=>({value:t}))!==0}getRange(t,n,r,i=67108863){let a=[];return this._root.forRange(t,n,r,!1,this,0,(t,n)=>(a.push([t,n]),a.length>i?e.Break:void 0)),a}setPairs(e,t){let n=0;for(let r=0;r<e.length;r++)this.set(e[r][0],e[r][1],t)&&n++;return n}forRange(e,t,n,r,i){let a=this._root.forRange(e,t,n,!1,this,i||0,r);return typeof a==`number`?a:a.break}editRange(e,t,n,r,i){let a=this._root;a.isShared&&(this._root=a=a.clone());try{let o=a.forRange(e,t,n,!0,this,i||0,r);return typeof o==`number`?o:o.break}finally{let e;for(;a.keys.length<=1&&!a.isLeaf;)e||=a.isShared,this._root=a=a.keys.length===0?on:a.children[0];e&&(a.isShared=!0)}}editAll(e,t){return this.editRange(this.minKey(),this.maxKey(),!0,e,t)}deleteRange(t,n,r){return this.editRange(t,n,r,e.DeleteRange)}deleteKeys(e){let t=0;for(let n=0;n<e.length;n++)this.delete(e[n])&&t++;return t}getHeight(){let e=this._root,t=-1;for(;e;)t++,e=e.isLeaf?void 0:e.children[0];return t}freeze(){let e=this;e.clear=e.set=e.editRange=function(){throw Error(`SortedMap: Attempted to modify when frozen.`)}}unfreeze(){delete this.clear,delete this.set,delete this.editRange}isFrozen(){return this.hasOwnProperty(`editRange`)}checkValid(){let e=this._root.checkValid(0,this,0);cn(e===this.size,`size mismatch: counted `,e,`but stored`,this.size)}};function en(e=()=>an){let t={next:e};return Symbol&&Symbol.iterator&&(t[Symbol.iterator]=function(){return this}),t}Symbol&&Symbol.iterator&&($t.prototype[Symbol.iterator]=$t.prototype.entries),$t.prototype.where=$t.prototype.filter,$t.prototype.setRange=$t.prototype.setPairs,$t.prototype.add=$t.prototype.set;var tn=class e{constructor(e,t=[],n){this.keys=t,this.values=n||rn,this.isShared=void 0,this.isLeaf=e}maxKey(){return this.keys[this.keys.length-1]}indexOf(e,t,n){let r=this.keys,i=0,a=r.length,o=a>>1;for(;i<a;){let t=n(r[o],e);if(t<0)i=o+1;else{if(!(t>0)){if(t===0)return o;if(e==e)return r.length;throw Error(`SortedMap: NaN was used as a key.`)}a=o}o=i+a>>1}return o^t}minKey(){return this.keys[0]}minPair(e){if(this.keys.length!==0)return(e??=[null,null])[0]=this.keys[0],e[1]=this.values[0],e}maxPair(e){if(this.keys.length===0)return;let t=this.keys.length-1;return(e??=[null,null])[0]=this.keys[t],e[1]=this.values[t],e}clone(){let t=this.values,n=t===rn?t:t.slice(0),r=this.keys.slice(0);return new e(!0,r,n)}greedyClone(e){return this.isShared&&!e?this:this.clone()}get(e,t,n){let r=this.indexOf(e,-1,n._compare);return r<0?t:this.values[r]}getPairOrNextLower(e,t,n,r){let i=this.indexOf(e,-1,t),a=i<0?~i-1:n?i:i-1;if(a>=0){let e=this.keys[a],t=this.values[a];return r?(r[0]=e,r[1]=t,r):[e,t]}}getPairOrNextHigher(e,t,n,r){let i=this.indexOf(e,-1,t),a=i<0?~i:n?i:i+1,o=this.keys;if(a<o.length){let e=o[a],t=this.values[a];return r?(r[0]=e,r[1]=t,r):[e,t]}}checkValid(e,t,n){let r=this.keys.length,i=this.values.length;return cn(this.values===rn?r<=i:r===i,`keys/values length mismatch: depth`,e,`with lengths`,r,i,`and baseIndex`,n),cn(e===0||r>0,`empty leaf at depth`,e,`and baseIndex`,n),r}set(e,t,n,r){let i=this.indexOf(e,-1,r._compare);if(i<0){if(i=~i,r._size++,this.keys.length<r._maxNodeSize)return this.insertInLeaf(i,e,t,n,r);{let a=this.splitOffRightSide(),o=this;return i>this.keys.length&&(i-=this.keys.length,o=a),o.insertInLeaf(i,e,t,n,r),a}}if(!1!==n){t!==void 0&&this.reifyValues(),this.keys[i]=e;let r=t;if(typeof n==`function`){let a=n(this.values[i],e,t);a!==void 0&&(r=a)}this.values[i]=r}return!1}reifyValues(){return this.values===rn?this.values=this.values.slice(0,this.keys.length):this.values}insertInLeaf(e,t,n,r,i){if(this.keys.splice(e,0,t),this.values===rn){for(;rn.length<i._maxNodeSize;)rn.push(void 0);if(n===void 0)return!0;this.values=rn.slice(0,this.keys.length-1)}let a=n;if(typeof r==`function`){let e=r(void 0,t,n);e!==void 0&&(a=e)}return this.values.splice(e,0,a),!0}takeFromRight(e){let t=this.values;e.values===rn?t!==rn&&t.push(void 0):(t=this.reifyValues(),t.push(e.values.shift())),this.keys.push(e.keys.shift())}takeFromLeft(e){let t=this.values;e.values===rn?t!==rn&&t.unshift(void 0):(t=this.reifyValues(),t.unshift(e.values.pop())),this.keys.unshift(e.keys.pop())}splitOffRightSide(){let t=this.keys.length>>1,n=this.keys.splice(t),r=this.values===rn?rn:this.values.splice(t);return new e(!0,n,r)}forRange(e,t,n,r,i,a,o){let s=i._compare,c,l;if(t===e){if(!n||(l=(c=this.indexOf(e,-1,s))+1,c<0))return a}else c=this.indexOf(e,0,s),l=this.indexOf(t,-1,s),l<0?l=~l:!0===n&&l++;let u=this.keys,d=this.values;if(o!==void 0)for(let e=c;e<l;e++){let t=u[e],n=o(t,d[e],a++);if(n!==void 0){if(n.break!==void 0)return n;if(!0===r){if(t!==u[e]&&i._compare(t,u[e])!==0||!0===this.isShared)throw Error(`SortedMap: illegally changed or cloned in editRange.`);n.delete?(this.keys.splice(e,1),this.values!==rn&&this.values.splice(e,1),i._size--,e--,l--):n.hasOwnProperty(`value`)&&(d[e]=n.value)}}}else a+=l-c;return a}mergeSibling(e,t){if(this.keys.push.apply(this.keys,e.keys),this.values===rn){if(e.values===rn)return;this.values=this.values.slice(0,this.keys.length)}this.values.push.apply(this.values,e.reifyValues())}},nn=class e extends tn{constructor(e,t){if(!t){t=[];let n=e.length;for(let r=0;r<n;r++)t[r]=e[r].maxKey()}super(!1,t),this.children=e}clone(){let t=this.children.slice(0),n=t.length;for(let e=0;e<n;e++)t[e].isShared=!0;return new e(t,this.keys.slice(0))}greedyClone(t){if(this.isShared&&!t)return this;let n=new e(this.children.slice(0),this.keys.slice(0)),r=n.children,i=r.length;for(let e=0;e<i;e++)r[e]=r[e].greedyClone(t);return n}minKey(){return this.children[0].minKey()}minPair(e){return this.children[0].minPair(e)}maxPair(e){return this.children[this.children.length-1].maxPair(e)}get(e,t,n){let r=this.indexOf(e,0,n._compare),i=this.children;return r<i.length?i[r].get(e,t,n):void 0}getPairOrNextLower(e,t,n,r){let i=this.indexOf(e,0,t),a=this.children;if(i>=a.length)return this.maxPair(r);let o=a[i].getPairOrNextLower(e,t,n,r);return o===void 0&&i>0?a[i-1].maxPair(r):o}getPairOrNextHigher(e,t,n,r){let i=this.indexOf(e,0,t),a=this.children,o=a.length;if(i>=o)return;let s=a[i].getPairOrNextHigher(e,t,n,r);return s===void 0&&i<o-1?a[i+1].minPair(r):s}checkValid(e,t,n){let r=this.keys.length,i=this.children.length;cn(r===i,`keys/children length mismatch: depth`,e,`lengths`,r,i,`baseIndex`,n),cn(r>1||e>0,`internal node has length`,r,`at depth`,e,`baseIndex`,n);let a=0,o=this.children,s=this.keys,c=0;for(let r=0;r<i;r++)a+=o[r].checkValid(e+1,t,n+a),c+=o[r].keys.length,cn(a>=c,`wtf`,n),cn(r===0||o[r-1].constructor===o[r].constructor,`type mismatch, baseIndex:`,n),o[r].maxKey()!==s[r]&&cn(!1,`keys[`,r,`] =`,s[r],`is wrong, should be `,o[r].maxKey(),`at depth`,e,`baseIndex`,n),r===0||t._compare(s[r-1],s[r])<0||cn(!1,`sort violation at depth`,e,`index`,r,`keys`,s[r-1],s[r]);let l=c===0;return(l||c>t.getMaxNodeSize()*i)&&cn(!1,l?`too few`:`too many`,`children (`,c,a,`) at depth`,e,`maxNodeSize:`,t.getMaxNodeSize(),`children.length:`,i,`baseIndex:`,n),a}set(e,t,n,r){let i=this.children,a=r._maxNodeSize,o=r._compare,s=Math.min(this.indexOf(e,0,o),i.length-1),c=i[s];if(c.isShared&&(i[s]=c=c.clone()),c.keys.length>=a){let t;s>0&&(t=i[s-1]).keys.length<a&&o(c.keys[0],e)<0?(t.isShared&&(i[s-1]=t=t.clone()),t.takeFromRight(c),this.keys[s-1]=t.maxKey()):(t=i[s+1])!==void 0&&t.keys.length<a&&o(c.maxKey(),e)<0&&(t.isShared&&(i[s+1]=t=t.clone()),t.takeFromLeft(c),this.keys[s]=i[s].maxKey())}let l=c.set(e,t,n,r);if(!1===l)return!1;if(this.keys[s]=c.maxKey(),!0===l)return!0;if(this.keys.length<a)return this.insert(s+1,l),!0;{let e=this.splitOffRightSide(),t=this;return o(l.maxKey(),this.maxKey())>0&&(t=e,s-=this.keys.length),t.insert(s+1,l),e}}insert(e,t){this.children.splice(e,0,t),this.keys.splice(e,0,t.maxKey())}splitOffRightSide(){let t=this.children.length>>1;return new e(this.children.splice(t),this.keys.splice(t))}takeFromRight(e){this.keys.push(e.keys.shift()),this.children.push(e.children.shift())}takeFromLeft(e){this.keys.unshift(e.keys.pop()),this.children.unshift(e.children.pop())}forRange(e,t,n,r,i,a,o){let s=i._compare,c=this.keys,l=this.children,u=this.indexOf(e,0,s),d=u,f=Math.min(t===e?u:this.indexOf(t,0,s),c.length-1);if(r){if(d<=f)try{for(;d<=f;d++){l[d].isShared&&(l[d]=l[d].clone());let s=l[d].forRange(e,t,n,r,i,a,o);if(c[d]=l[d].maxKey(),typeof s!=`number`)return s;a=s}}finally{let e=i._maxNodeSize>>1;for(u>0&&u--,d=f;d>=u;d--)l[d].keys.length<=e&&(l[d].keys.length===0?(c.splice(d,1),l.splice(d,1)):this.tryMerge(d,i._maxNodeSize));l.length!==0&&l[0].keys.length===0&&cn(!1,`emptiness bug`)}}else for(;d<=f;d++){let s=l[d].forRange(e,t,n,r,i,a,o);if(typeof s!=`number`)return s;a=s}return a}tryMerge(e,t){let n=this.children,r=n.length;return e>=0&&e+1<r&&n[e].keys.length+n[e+1].keys.length<=t&&(n[e].isShared&&(n[e]=n[e].clone()),n[e].mergeSibling(n[e+1],t),n.splice(e+1,1),this.keys.splice(e+1,1),this.keys[e]=n[e].maxKey(),!0)}mergeSibling(e,t){let n=this.keys.length;this.keys.push.apply(this.keys,e.keys);let r=e.children;if(this.children.push.apply(this.children,r),e.isShared&&!this.isShared)for(let e=0;e<r.length;e++)r[e].isShared=!0;this.tryMerge(n-1,t)}},rn=[],an=Object.freeze({done:!0,value:void 0}),on=function(){let e=new tn(!0);return e.isShared=!0,e}(),sn=[],cn=(e,...t)=>{if(!e)throw t.unshift(`SortedMap:`),Error(t.join(` `))};(function(e){let t=e.DeleteValue=Object.freeze({delete:!0});e.Break=Object.freeze({break:!0}),e.DeleteRange=()=>t,e.EmptySortedMap=(()=>{let e=new $t;return e.freeze(),e})(),e.defaultComparator=function(e,t){if(Number.isFinite(e)&&Number.isFinite(t))return e-t;let n=typeof e,r=typeof t;if(n!==r)return n<r?-1:1;if(n===`object`){if(e===null)return t===null?0:-1;if(t===null)return 1;if(n=typeof(e=e.valueOf()),r=typeof(t=t.valueOf()),n!==r)return n<r?-1:1}return e<t?-1:e>t?1:e===t?0:Number.isNaN(e)?Number.isNaN(t)?0:-1:Number.isNaN(t)?1:Array.isArray(e)?0:NaN},e.simpleComparator=function(e,t){return e>t?1:e<t?-1:0}})($t||={});var z,ln=class{constructor(e,t){this._l=0,e&&t>0&&(this._u=e,this._l=t)}at(e){if(e>=this._l||e<0||!this._u)return;let t=e%this._u.length;return this._u.at(t)}toArray(e){let t=[],n=this._u,r=n.length,i=Math.min(e??this._l,this._l);for(let e=0;e<i;e++){let i=e%r;t.push(n.at(i))}return t}get length(){return this._l}getPeriod(){return this._u?.length??0}get[Symbol.toStringTag](){return`[RepeatingList]`}get isIList(){return!0}get isIRepeatingList(){return!0}};(function(e){e.Hint={Blank:1,False:2,True:4,Int32:8,Float64:16,String:32,Object:128,KindMask:255,NotUniform:256,NotFinite:512};let t=e.hintOf=e=>typeof e==`number`?(0|e)===e?pn:e-e===0?mn:mn|vn:typeof e==`string`?hn:e==null?un:!0===e?fn:!1===e?dn:gn,r=(e,t,n=-1)=>{let r=e.length-1;if(r<0)return;if(e[r][0]>t){let n=0,i=r-1;for(r=-1;n<=i;){let a=n+i>>>1;e[a][0]<=t?(r=a,n=a+1):i=a-1}if(r<0)return}let i=e[r],a=t-i[0],o=i[1];return a>=(n>=0&&r===e.length-1?n:o.length)?void 0:Array.isArray(o)?o[a]:o.at(a)};e.Builder=class{constructor(e,t=0,n=0,r=!1){this._tuples=[],this._minors=null,this._values=null,this._minorMin=2**53-1,this._minorMax=0,this._majorIndex=-(2**53-1),this._minorIndex=-(2**53-1),this._lastMajor=-(2**53-1),this._lastMinor=-(2**53-1),this._readIndex=0,this._run=null,this._runMinors=null,this._scratch=[],this._filled=0,this._offsetMajor=0,this._offsetMinor=0,this._absentValue=void 0,this._gaps=null,this._skips=null,this._blanks=null,this._createList=e??void 0,this._track=e!=null,this._offsetMajor=t,this._offsetMinor=n,this._trackAbsent=r}setAbsentValue(e){if(this._absentValue!==void 0&&this._absentValue!==e)throw Error(`The absent value is already set.`);return this._absentValue=e,this}pushAbsentAt(e,t,n){return n<=0||(e+=this._offsetMajor,t+=this._offsetMinor,this._advance(e,t,t+n-1),this._gaps=yn(this._gaps,e,t,n)),this}pushMultipleAt(e,n,r){if(r&&r.isIList)return this.pushAt(e,n,r);let i=Array.isArray(r)?r:[r],a=i.length;if(this._trackAbsent){for(let t=0;t<a;t++)this.pushAt(e,n+t,i[t]);return this}if(this.pushAt(e,n,i[0]),this._track){let e=this._run,n=this._scratch,r=n[0],o=this._filled,s=e[2];for(let e=1;e<a;e++){let a=i[e];n[o++]=a,s|=t(a)|(a===r?0:_n)}this._filled=o,e[2]=s}else{let e=this._values;for(let t=1;t<a;t++)e.push(i[t])}return this._minorIndex+=a-1,this._lastMinor=this._minorIndex,this}pushAt(e,n,r){e+=this._offsetMajor,n+=this._offsetMinor;let i=!!r&&!0===r.isIList,a=i?r.length:1;if(this._advance(e,n,n+a-1),this._trackAbsent&&a>0){let t=i?!0===r.isIRepeatingList?r.at(0):void 0:r;if(t===null)return this._blanks=yn(this._blanks,e,n,a),this;if(t!==void 0&&t===this._absentValue)return this._skips=yn(this._skips,e,n,a),this}let o=this._minors,s=e===this._majorIndex&&n===this._minorIndex+1;if(e!==this._majorIndex){if(o){this._run&&this._closeRun(),this._minorMin=Math.min(this._minorMin,o[0][0]);let e=o[o.length-1];this._minorMax=Math.max(this._minorMax,e[0]+e[1].length-1)}this._minors=o=[],this._tuples.push([e,o]),this._majorIndex=e}if(i)this._run&&this._closeRun(),o.push([n,r]),this._values=null;else if(this._track){let e=this._filled;if(this._run===null||!s){this._run&&this._closeRun();let t=[n,this._scratch,0];o.push(t),this._run=t,this._runMinors=o,e=0}let i=this._scratch;i[e]=r,this._filled=e+1,this._run[2]|=t(r)|(r===i[0]?0:_n)}else{let e=this._values;e&&s||(this._values=e=[],o.push([n,e])),e.push(r)}return this._minorIndex=n+a-1,this}_closeRun(){let e=this._run,t=this._runMinors;t[t.length-1]=[e[0],this._createList(e[1],this._filled,e[2])],this._run=null,this._filled=0}getAt(e,t){if(e+=this._offsetMajor,t+=this._offsetMinor,e===this._majorIndex)return r(this._minors,t,this._run?this._filled:-1);let n=this._tuples,i=n.length,a=0,o=i-1,s=this._readIndex;if(s<i){let c=n[s][0];if(c===e)return r(n[s][1],t);if(c>e)o=s-1;else if(a=s+1,a<i){let i=n[a][0];if(i===e)return this._readIndex=a,r(n[a][1],t);if(i>e)return;a++}}for(;a<=o;){let i=a+o>>>1,s=n[i][0];if(s===e)return this._readIndex=i,r(n[i][1],t);s<e?a=i+1:o=i-1}this._readIndex=o<0?0:o}_advance(e,t,n){let r=this._lastMajor,a=this._lastMinor;if(e<r||e===r&&t<=a)throw new i(`major: ${e}, minor: ${t}, prevMajor: ${r}, prevMinor: ${a}`);this._lastMajor=e,this._lastMinor=n}build(){if(this._trackAbsent)return this._buildTracked();let e=this._tuples;if(e.length===0)return null;this._run&&this._closeRun();let t=this._minors;this._minorMin=Math.min(this._minorMin,t[0][0]);let n=t[t.length-1];return this._minorMax=Math.max(this._minorMax,n[0]+n[1].length-1),this._values=null,{tuples:e,bounds:{majorStart:e[0][0],minorStart:this._minorMin,majorEnd:e[e.length-1][0],minorEnd:this._minorMax}}}_buildTracked(){this._run&&this._closeRun(),this._values=null;let e=this._tuples,t=this._blanks??[],n,r=this._absentValue??null;if(r!==null&&t.length>0){let i=(this._gaps??[]).concat(this._skips??[]).sort(bn);e=xn(e,i,r),r=null,n=t}else n=this._skips?t.concat(this._skips):t;return{tuples:e,bounds:Sn(e),absentValue:r,clears:n}}},e.TransposedBuilder=class{constructor(e,t=0,n=0){this._lines=[],this._base=0,this._majorMin=2**53-1,this._majorMax=0,this._majorIndex=-(2**53-1),this._minorIndex=-(2**53-1),this._offsetMajor=0,this._offsetMinor=0,this._createList=e??void 0,this._track=e!=null,this._offsetMajor=t,this._offsetMinor=n}pushMultipleAt(e,t,n){if(n&&n.isIList){let r=n,i=r.length;for(let n=0;n<i;n++)this.pushAt(e,t+n,r.at(n));return this}let r=Array.isArray(n)?n:[n],i=r.length;for(let n=0;n<i;n++)this.pushAt(e,t+n,r[n]);return this}pushAt(e,n,r){e+=this._offsetMajor,n+=this._offsetMinor;let a=this._majorIndex;if(e!==a){if(e<a)throw new i(`major: ${e}, minor: ${n}, prevMajor: ${a}, prevMinor: ${this._minorIndex}`);this._majorIndex=e,a===-(2**53-1)&&(this._majorMin=e,this._base=n)}else if(n<=this._minorIndex)throw new i(`major: ${e}, minor: ${n}, prevMajor: ${a}, prevMinor: ${this._minorIndex}`);this._minorIndex=n,this._majorMax=e,n<this._base&&this._rebase(n);let o=this._lines,s=n-this._base,c,l=o[s];if(l===void 0)c=this._track?[e,[],0]:[e,[]],o[s]=l=[n,[c]];else{let t=l[1];c=t[t.length-1],c[0]+c[1].length!==e&&(c=this._track?[e,[],0]:[e,[]],t.push(c))}let u=c[1];return u.push(r),this._track&&(c[2]|=t(r)|(r===u[0]?0:_n)),this}_rebase(e){let t=this._base-e,n=this._lines,r=Array(n.length+t);for(let e=0;e<n.length;e++)r[e+t]=n[e];this._lines=r,this._base=e}getAt(e,t){let n=this._lines[t+this._offsetMinor-this._base];return n?r(n[1],e+this._offsetMajor):void 0}build(){let e=[],t=this._createList,n=this._lines,r=n.length;for(let i=0;i<r;i++){let r=n[i];if(r!==void 0){if(t){let e=r[1],n=e.length;for(let r=0;r<n;r++){let n=e[r];Array.isArray(n[1])&&(e[r]=[n[0],t(n[1],n[1].length,n[2])])}}e.push(r)}}return e.length===0?null:{tuples:e,bounds:{majorStart:e[0][0],minorStart:this._majorMin,majorEnd:e[e.length-1][0],minorEnd:this._majorMax}}}};class i extends n.ChainedError{constructor(e=`Out of order`,t=null){super(e,t),this.name=`OutOfOrderError`}}e.OutOfOrderError=i})(z||={});var un=z.Hint.Blank,dn=z.Hint.False,fn=z.Hint.True,pn=z.Hint.Int32,mn=z.Hint.Float64,hn=z.Hint.String,gn=z.Hint.Object,_n=z.Hint.NotUniform,vn=z.Hint.NotFinite;z.hintOf;var yn=(e,t,n,r)=>{if(!e)return[[t,n,r]];let i=e[e.length-1];return i[0]===t&&i[1]+i[2]===n?i[2]+=r:e.push([t,n,r]),e},bn=(e,t)=>e[0]-t[0]||e[1]-t[1],xn=(e,t,n)=>{let r=[],i=0,a=0;for(;i<e.length||a<t.length;){let o=i<e.length?e[i][0]:2**53-1,s=a<t.length?t[a][0]:2**53-1;if(o<s){r.push(e[i++]);continue}let c=[];for(;a<t.length&&t[a][0]===s;)c.push([t[a][1],new ln([n],t[a][2])]),a++;if(o!==s){r.push([s,c]);continue}let l=e[i++][1],u=[],d=0,f=0;for(;d<l.length||f<c.length;)f>=c.length||d<l.length&&l[d][0]<c[f][0]?u.push(l[d++]):u.push(c[f++]);r.push([s,u])}return r},Sn=e=>{if(e.length===0)return{majorStart:0,minorStart:0,majorEnd:-1,minorEnd:-1};let t=2**53-1,n=-(2**53-1);for(let r=0;r<e.length;r++){let i=e[r][1];t=Math.min(t,i[0][0]);let a=i[i.length-1];n=Math.max(n,a[0]+a[1].length-1)}return{majorStart:e[0][0],minorStart:t,majorEnd:e[e.length-1][0],minorEnd:n}};function Cn(e,t=n.Direction.Right,r=null){if(!e)return e;if(e.length===0)return[];let i=t===n.Direction.Right,a=t===n.Direction.Left,o=t===n.Direction.Up,s=t===n.Direction.Down;return e.sort((e,t)=>{if(!e&&!t)return 0;if(e&&!t)return-1;if(t&&!e)return 1;let n=r?.(e,t)??0;return n===0?i?e.rowStart===t.rowStart?e.colStart-t.colStart:e.rowStart-t.rowStart:s?e.colStart===t.colStart?e.rowStart-t.rowStart:e.colStart-t.colStart:a?e.rowStart===t.rowStart?t.colStart-e.colStart:t.rowStart-e.rowStart:o?e.colStart===t.colStart?t.rowStart-e.rowStart:t.colStart-e.colStart:0:n})}function wn(e,t){let n=t.min,r=e.min;if(t.max===2**53-1){let i=n,a=e.max;return r<=i&&i<=a?0:a<i?-1:r>i?1:(console.warn(`coords are not inserted correctly`,e,t),0)}return r-n}var Tn=class e{constructor(e){this._dataCoords=null,this._count=0,this._length=0,this._maxCoords=null,this._options=e,e?.maxCoords&&(this._maxCoords=Object.freeze({...e.maxCoords})),this._runs=new $t(void 0,wn,e?.nodeSize),this._reuseRunsIterator={done:!1,value:[null,null]},this._reuseRunsEntry=[null,null]}_validateBounds(e=-(2**53-1),t=2**53-1){let r=this._maxCoords,i=r?.min??-(2**53-1),a=r?.max??2**53-1;if(e<i||t>a)throw new n.OutOfBoundsError}entries(e){let t,r,i=-(2**53-1),a=2**53-1,o=!0;e&&(e?.bounds&&(i=e.bounds?.min??-(2**53-1),a=e.bounds?.max??2**53-1,this._validateBounds(i,a)),o=!e.reverse,t=En(e.reuseResult),r=e.processSkip);let s=this._dataCoords;if(!s)return Bt;i=Math.max(s.min,i),a=Math.min(s.max,a);let c=null,l=null,u=2**53-1,d=-(2**53-1);if(r){let e=r;r=(t,n)=>e(t+u,n)-u}let f=e=>{let t;e!==-(2**53-1)&&e!==2**53-1&&(Fn.min=e,t=Fn),c=o?this._runs.entries(t,this._reuseRunsIterator):this._runs.entriesReversed(t,this._reuseRunsIterator),u=2**53-1,d=-(2**53-1),l=null},p=e=>{if(e!==void 0){if(e<u||e>d)return void(l=void 0);e-=u}if(!l)return;let n=l.next(e);if(!l)return;let r=n.value,i=r?.[1];if(!n.done)return Dn(r[0]+u,i,t);l=void 0},m=e=>{let n;return n=p(e),n||(n=(e=>{let n;do{if(e!==void 0&&f(e),!c)return;if(n=c.next(),n.done)return void(c=void 0);let s=n.value,m=s[0],h=s[1],g=m.min,_=m.max,v=Math.max(g,i)-g,y=Math.max(v,Math.min(_,a))-g;Nn.bounds.min=v,Nn.bounds.max=y,Nn.reverse=!o,Nn.processSkip=r,Nn.reuseResult=t,u=g,d=_,l=h.entries(Nn);let b=p(e);if(b)return b;e=void 0}while(!n.done);c=void 0})(e),n||zt)};return f(o?i:a),{next(e){if(e!==void 0&&(e<0||e>a))throw new n.OutOfBoundsError;return m(e)},return:e=>null,throw:e=>null}}runs(e){let t,r=-(2**53-1),i=2**53-1,a=!0,o=!1;e&&(e.bounds&&(r=e.bounds?.min??-(2**53-1),i=e.bounds?.max??2**53-1,this._validateBounds(r,i),e.overflowRun&&(o=!0)),a=!e.reverse,t=On(e.reuseResult));let s=this._dataCoords;if(!s)return Bt;r=Math.max(s.min,r),i=Math.min(s.max,i);let c=null,l=e=>{let t;e!==-(2**53-1)&&e!==2**53-1&&(Fn.min=e,t=Fn),c=a?this._runs.entries(t,this._reuseRunsIterator):this._runs.entriesReversed(t,this._reuseRunsIterator)};return l(a?r:i),{next(e){if(e!==void 0){if(e<r||e>i)throw new n.OutOfBoundsError;l(e)}if(!c)return zt;let s=c.next();if(s.done)return c=void 0,zt;let u=s.value,d=u[0],f=d,p=f.min,m=f.max;if(a&&p>i||!a&&m<r)return zt;let h=u[1];return o||(m>i&&(h=h.slice(0,h.length-(m-i)),f={...f},f.max=i),p<r&&(h=h.slice(r-p),f===d&&(f={...f}),f.min=r)),kn(f,h,t)},return:e=>null,throw:e=>null}}slice(t,n){let r=this._runs;if(this._count===0)return this.clone();let i=r.minKey().min,a=r.maxKey().max;if(n===void 0&&(n=a+1),t<=i&&n-1>=a)return this.clone();let o=Math.max(i,t),s=Math.min(a,n-1),c=s-o,l=[],u=0;Rn.bounds.min=o,Rn.bounds.max=s;let d=this.runs(Rn),f=d.next();for(;!f.done;){let e=f.value,t=e[0],n=e[1];t={min:t.min-o,max:t.max-o},t.min<0&&(n=n.slice(-t.min),t.min=0),t.max>=c&&(n=n.slice(0,n.length-(t.max-c)),t.max=c),u+=n.length,l.push([t,n]),f=d.next()}let p=new e(this._options);return p._runs.setPairs(l),p._updateCount(u),p}concat(e){let t=this.clone();if(!e||e.length===0)return t;let n=this._runs;if(this._count===0){let n=[],r=0;if(e.isISparseList){let t=e.runs(),i=t.next();for(;!i.done;){let e=i.value;n.push([{min:e[0].min,max:e[0].max},e[1]]),r+=e[1].length,i=t.next()}}else n.push([{min:0,max:e.length-1},e]),r+=e.length;return t._runs.setPairs(n),t._updateCount(r),t}let r=n.nextLowerPair(void 0,this._reuseRunsEntry),i=r[0],a=r[1],o=i.max+1,s=!1,c=0,l=[];if(e.isISparseList){let t=e.runs(),n=t.next();for(;!n.done;){let e=n.value,r=e[0],u={min:r.min+o,max:r.max+o},d=e[1];if(r.min===0){s=!0,c-=a.length,d=a.concat(d);let e=i.min;u.min=e,u.max=d.length-1+e}c+=d.length,l.push([u,d]),n=t.next()}}else{let t=e.length,n={min:i.min,max:t-1+o};e=a.concat(e),s=!0,c+=t,l.push([n,e])}return s&&t._runs.delete(i),t._runs.setPairs(l),t._updateCount(c),t}toArray(e=2**53-1,t=!0){if(this.length===0)return n.CommonUtils.EmptyArray;let r=t?0:-(2**53-1),i=Math.min(this._runs.maxKey().max,e);return Pn.bounds.min=-(2**53-1),Pn.bounds.max=i,An(this.entries(Pn),t,i,r)}get isIReadableList(){return!0}get length(){return this._length}getCoords(){return this._dataCoords}clear(){this._runs.clear(),this._dataCoords=null,this._lastRunsRead=void 0,this._lastListRead=void 0,this._count=0,this._length=0}get isISparseList(){return!0}get isIList(){return!0}_updateCount(e){if(this._count+=e,this._lastRunsRead=void 0,this._lastListRead=void 0,this._count>0){let e=this._runs,t=Object.freeze({min:e.minKey().min,max:e.maxKey().max});this._dataCoords=t,this._length=t.max+1}else this._dataCoords=null,this._length=0}_update(e,t,n=null,r=void 0){let i=e,a=i+t-1,o=0,s=a,c=a,l=null,u=null;Fn.min=i,In.min=a,(n||r)&&(--Fn.min,In.min+=1);let d=this._runs,f=!1;if(d.editRange(Fn,In,!0,(e,t,n)=>{let r=e.min,d=e.max;return r<i&&d+1>=i&&(s=r,l=t),r-1<=a&&d>a&&(c=r,u=t),o-=d-r+1,f=!0,$t.DeleteValue}),n||r===void 0||(n=new Ht([r])),n){let e=n;f=!0;let t=i;l&&(l=l.slice(0,i-s),e=l.concat(e),t=s),u&&(u=u.slice(a+1-c),e=e.concat(u)),o+=e.length,d.set({min:t,max:t+e.length-1},e)}else l&&(l=l.slice(0,i-s),o+=l.length,d.set({min:s,max:s+l.length-1},l)),u&&(u=u.slice(a+1-c),o+=u.length,d.set({min:a+1,max:a+u.length},u));return this._updateCount(o),f}setAt(e,t){if(e===void 0)throw new n.NullNotAllowedError;return this._validateBounds(e,e),this._update(e,1,null,t)}setRunAt(e,t){if(!t||t.length===0)return!1;if(e===void 0||!t.length)throw new n.NullNotAllowedError;let r=t.length;return this._validateBounds(e,e+r-1),this._update(e,r,t)}delete(e,t){if(t===void 0){let n=this.getCoords();if(!n)return!1;t=Math.max(n.max-e+1,0)}return!(t<=0)&&(this._validateBounds(e,e),this._update(e,t,null))}shift(e,t){if(t===0)return!1;let n=e,r=e;t<0&&(r=e-t-1),this._validateBounds(n,r);let i=this._runs;if(this._count===0)return!1;let a=i.maxKey();if(t<0&&r>=a.max&&n<=i.minKey().min)return this._runs.clear(),this._dataCoords=null,this._count=0,this._length=0,!0;let o=0,s=n,c=r,l=null,u=null;Fn.min=s,In.min=a.min,t<0&&(--Fn.min,In.min+=1);let d=!1,f=[];if(i.editRange(Fn,In,!0,(e,i,a)=>{let p=e.min,m=e.max;return p<n&&m+1>=n&&(s=p,l=i),(p<n||t<0)&&p-1<=r&&e.max>r&&(c=p,u=i),t>0&&p>=n||t<0&&p-1>r?f.push([{min:p+t,max:m+t},i]):o-=m-p+1,d=!0,$t.DeleteValue}),t>0){let r=l||u;r&&(l=r.slice(0,n-s),c=e+t,u=r.slice(n-s))}else l&&=l.slice(0,n-s),u&&(u=u.slice(r+1-c),c=e),l&&u&&s+l.length===c&&(l=l.concat(u),u=null);return l&&l.length>0&&(o+=l.length,i.set({min:s,max:s+l.length-1},l)),u&&(o+=u.length,i.set({min:c,max:c+u.length-1},u)),f.length>0&&i.setPairs(f),this._updateCount(o),d}at(e){Fn.min=e;let t=this._lastRunsRead;if(t){let n=t.min;if(n<=e&&t.max>=e)return this._lastListRead.at(e-n)}let n,r,i=this._runs.getPairOrNextHigher(Fn,Ln);if(i&&(n=i[0],r=i[1]),this._lastRunsRead=n,this._lastListRead=r,!(!n||e<n.min||e>n.max))return r.at(e-n.min)}[Symbol.iterator](){return It(this.entries())}clone(){let t=new e(this._options);return t._runs=this._runs.clone(),t._count=this._count,t._dataCoords=this._dataCoords,t._length=this._length,t}getMaxCoords(){return this._maxCoords||null}getCount(){return this._count}getRunsCount(){return this._runs.size}get[Symbol.toStringTag](){return`[SparseList]`}};Tn||={};var En=e=>typeof e==`boolean`?!0===e?Mn:void 0:(e&&!e.value&&(e.value=[-1,null]),e),Dn=(e,t,n)=>{let r=n??{done:!1,value:[-1,null]},i=r.value;return i[0]=e,i[1]=t,r},On=e=>typeof e==`boolean`?!0===e?jn:void 0:(e&&!e.value&&(e.value=[null,null]),e),kn=(e,t,n)=>{let r=n??{done:!1,value:[null,null]},i=r.value;return i[0]=e,i[1]=t,r},An=(e,t=!1,n=-(2**53-1),r=2**53-1)=>{let i=[],a=e.next(),o=Math.max(r,0)-1;for(;!a.done;){if(t){let e=a.value[0];for(let t=o;t<e-1;t++)i.push(void 0);o=e}i.push(a.value[1]),a=e.next()}if(t)for(let e=o;e<n;e++)i.push(void 0);return i},jn=Object.seal({done:!1,value:[{min:-(2**53-1),max:2**53-1},null]}),Mn=Object.seal({done:!1,value:[-1,null]}),Nn={reverse:!1,bounds:{min:-(2**53-1),max:2**53-1},processSkip:null,reuseResult:Mn},Pn=Object.freeze({reverse:!1,bounds:{min:-(2**53-1),max:2**53-1},processSkip:null,reuseResult:Mn}),Fn={min:0,max:2**53-1},In={min:0,max:2**53-1},Ln=[null,null],Rn={bounds:{min:0,max:0},overflowRun:!0},zn=class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(e){return this.isEmpty()?e??n.CommonUtils.EmptyArray:this._all(this._data,e??[])}search(e,t){if(this.isEmpty()||!ar(e,this._data.range))return t??n.CommonUtils.EmptyArray;let r=t??[],i=dr,a=this._data;for(;a;){let t=a.children;if(t!==null){let n=t.length;for(let i=0;i<n;i++){let n=t[i];ar(e,n.range)&&(n.children===null?r.push(n.range):ir(e,n.range)?this._all(n,r):ur[dr++]=n)}}a=dr>i?ur[--dr]:void 0}return dr=i,r}collides(e){if(this.isEmpty()||!ar(e,this._data.range))return!1;let t=dr,n=this._data;for(;n;){let r=n.children;if(r!==null){let n=r.length;for(let i=0;i<n;i++){let n=r[i],a=n.range;if(ar(e,a)){if(n.children===null||ir(e,a))return dr=t,!0;ur[dr++]=n}}}n=dr>t?ur[--dr]:void 0}return dr=t,!1}isEmpty(){let e=this._data.children;return e!==null&&e.length===0}getBoundingRange(){let e=this._data,t=e.children;if(t!==null&&t.length===0)return null;let n=e.range;return{colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd}}load(e){if(!e||!e.length)return this;let t=e.length;if(t<this._minEntries){for(let n=0;n<t;n++)this.insert(e[n]);return this}let n=this._build(e.slice(),0,e.length-1,0);if(this.isEmpty())this._data=n;else if(this._data.height===n.height)this._splitRoot(this._data,n);else{if(this._data.height<n.height){let e=this._data;this._data=n,n=e}this._insert(n,this._data.height-n.height-1)}return this}removeAll(e,t){let n=e?e.length:0;if(n===0||this.isEmpty())return this;let r=hr;r.colStart=Un,r.rowStart=Un,r.colEnd=Wn,r.rowEnd=Wn;for(let t=0;t<n;t++)Yn(r,e[t]);let i;if(t)i=r=>{for(let i=0;i<n;i++)if(t(r,e[i]))return!0;return!1};else{let t=new Set(e);i=e=>t.has(e)}return Vn(this._data,i,r)&&this.clear(),this}clear(){return this._data=Kn([]),this}insert(e){return e&&this._insert(Hn(e),this._data.height-1),this}remove(e,t){if(!e)return this;let n=e,r=pr,i=mr,a=0,o=this._data,s=0,c=null,l=!1;for(;o||a>0;){if(!o){let e=--a;o=r[e],r[e]=lr,c=a>0?r[a-1]:null,s=i[a],l=!0}if(o.height===1){let n=Bn(e,o.children,t);if(n!==-1){o.children.splice(n,1),r[a++]=o;for(let e=a-1;e>=0;e--)if(r[e].children.length===0)if(e>0){let t=r[e-1].children;t.splice(t.indexOf(r[e]),1)}else this.clear();else qn(r[e]);return this}}!l&&o.height>1&&ir(o.range,n)?(r[a]=o,i[a]=s,a++,s=0,c=o,o=o.children[0]):c?(s++,o=c.children[s]??null,l=!1):o=null}return this}_all(e,t){let n=dr,r=e;for(;r;){if(r.children===null)t.push(r.range);else{let e=r.children,t=e.length;for(let n=0;n<t;n++)ur[dr++]=e[n]}r=dr>n?ur[--dr]:void 0}return dr=n,t}_build(e,t,n,r){let i=n-t+1,a=this._maxEntries;if(i<=a){let n=i,r=[];for(let i=0;i<n;i++)r.push(Hn(e[t+i]));let a=Kn(r);return a.height=1,qn(a),a}r||(r=Math.ceil(Math.log(i)/Math.log(a)),a=Math.ceil(i/a**(r-1)));let o=Kn([]);o.height=r;let s=Math.ceil(i/a),c=s*Math.ceil(Math.sqrt(a));or(e,t,n,c,Qn);for(let i=t;i<=n;i+=c){let t=Math.min(i+c-1,n);or(e,i,t,s,$n);for(let n=i;n<=t;n+=s)o.children.push(this._build(e,n,Math.min(n+s-1,t),r-1))}return qn(o),o}_chooseSubtree(e,t,n,r){let i=0;for(;r[i++]=t,t.children!==null&&i-1!==n;){let n,r=1/0,i=1/0,a=t.children,o=a.length;for(let t=0;t<o;t++){let o=a[t],s=o.range,c=er(s),l=nr(e,s)-c;l<i?(i=l,r=c<r?c:r,n=o):l===i&&c<r&&(r=c,n=o)}t=n??a[0]}return t}_insert(e,t){let n=fr;n.length=0;let r=e.range,i=this._chooseSubtree(r,this._data,t,n);i.children.push(e),Yn(i.range,r);let a=t,o=this._maxEntries;for(;a>=0&&n[a].children.length>o;)this._split(n,a),a--;for(let e=a;e>=0;e--)Yn(n[e].range,r)}_split(e,t){let n=e[t],r=n.children,i=r.length,a=this._minEntries;this._chooseSplitAxis(n,a,i);let o=this._chooseSplitIndex(n,a,i),s=Kn(r.splice(o,i-o));s.height=n.height,qn(n),qn(s),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this._data=Kn([e,t]),this._data.height=e.height+1,qn(this._data)}_chooseSplitIndex(e,t,n){let r=-1,i=1/0,a=1/0;for(let o=t;o<=n-t;o++){let t=Jn(e,0,o,gr),s=Jn(e,o,n,_r),c=rr(t,s),l=er(t)+er(s);c<i?(i=c,r=o,a=l<a?l:a):c===i&&l<a&&(a=l,r=o)}return r||n-t}_chooseSplitAxis(e,t,n){this._allDistMargin(e,t,n,Xn)>=this._allDistMargin(e,t,n,Zn)||e.children.sort(Xn)}_allDistMargin(e,t,n,r){let i=e.children;i.sort(r);let a=Jn(e,0,t,gr),o=Jn(e,n-t,n,_r),s=tr(a)+tr(o);for(let e=t;e<n-t;e++)Yn(a,i[e].range),s+=tr(a);for(let e=n-t-1;e>=t;e--)Yn(o,i[e].range),s+=tr(o);return s}};function Bn(e,t,n){let r=t.length;for(let i=0;i<r;i++){let r=t[i].range;if(n?n(e,r):e===r)return i}return-1}function Vn(e,t,n){if(e.height===1){let n=e.children,r=n.length;for(let e=n.length-1;e>=0;e--)t(n[e].range)&&n.splice(e,1);return n.length!==r&&n.length>0&&qn(e),n.length===0}let r=e.children,i=!1;for(let e=r.length-1;e>=0;e--){let a=r[e];ar(a.range,n)&&Vn(a,t,n)&&(r.splice(e,1),i=!0)}return i&&r.length>0&&qn(e),r.length===0}function Hn(e){return{range:e,children:null,height:0}}var Un=1073741823,Wn=-1073741824;function Gn(){return{colStart:Un,rowStart:Un,colEnd:Wn,rowEnd:Wn,value:null}}function Kn(e){return{range:Gn(),children:e,height:1}}function qn(e){let t=e.range;t.colStart=Un,t.rowStart=Un,t.colEnd=Wn,t.rowEnd=Wn;let n=e.children;if(n){let e=n.length;for(let r=0;r<e;r++)Yn(t,n[r].range)}}function Jn(e,t,n,r){let i=r??Gn();i.colStart=Un,i.rowStart=Un,i.colEnd=Wn,i.rowEnd=Wn;let a=e.children;for(let e=t;e<n;e++)Yn(i,a[e].range);return i}function Yn(e,t){let n=e.colStart,r=e.colEnd,i=e.rowStart,a=e.rowEnd;return e.colStart=n<t.colStart?n:t.colStart,e.rowStart=i<t.rowStart?i:t.rowStart,e.colEnd=r>t.colEnd?r:t.colEnd,e.rowEnd=a>t.rowEnd?a:t.rowEnd,e}function Xn(e,t){return e.range.colStart-t.range.colStart}function Zn(e,t){return e.range.rowStart-t.range.rowStart}function Qn(e,t){return e.colStart-t.colStart}function $n(e,t){return e.rowStart-t.rowStart}function er(e){return(e.colEnd-e.colStart+1)*(e.rowEnd-e.rowStart+1)}function tr(e){return e.colEnd-e.colStart+1+(e.rowEnd-e.rowStart+1)}function nr(e,t){let n=e.colStart,r=e.colEnd,i=e.rowStart,a=e.rowEnd;return((t.colEnd>r?t.colEnd:r)-(t.colStart<n?t.colStart:n)+1)*((t.rowEnd>a?t.rowEnd:a)-(t.rowStart<i?t.rowStart:i)+1)}function rr(e,t){let n=e.colStart,r=e.colEnd,i=n>t.colStart?n:t.colStart,a=(r<t.colEnd?r:t.colEnd)-i+1;if(a<=0)return 0;let o=e.rowStart,s=e.rowEnd,c=o>t.rowStart?o:t.rowStart,l=(s<t.rowEnd?s:t.rowEnd)-c+1;return l<=0?0:a*l}function ir(e,t){return e.colStart<=t.colStart&&e.rowStart<=t.rowStart&&t.colEnd<=e.colEnd&&t.rowEnd<=e.rowEnd}function ar(e,t){return t.colStart<=e.colEnd&&t.rowStart<=e.rowEnd&&t.colEnd>=e.colStart&&t.rowEnd>=e.rowStart}function or(e,t,n,r,i){let a=0;for(vr[a++]=t,vr[a++]=n;a>0;){if((n=vr[--a])-(t=vr[--a])<=r)continue;let o=t+Math.ceil((n-t)/r/2)*r;sr(e,o,t,n,i),vr[a++]=t,vr[a++]=o,vr[a++]=o,vr[a++]=n}}function sr(e,t,n,r,i){let a=n,o=r,s=i;for(;o>a;){if(o-a>600){let n=o-a+1,r=t-a+1,i=Math.log(n),c=.5*Math.exp(2*i/3),l=.5*Math.sqrt(i*c*(n-c)/n)*(r-n/2<0?-1:1),u=Math.floor(t-r*c/n+l),d=u>a?u:a,f=Math.floor(t+(n-r)*c/n+l);sr(e,t,d,f<o?f:o,s)}let n=e[t],r=a,i=o;for(cr(e,a,t),s(e[o],n)>0&&cr(e,a,o);r<i;){for(cr(e,r,i),r++,i--;s(e[r],n)<0;)r++;for(;s(e[i],n)>0;)i--}s(e[a],n)===0?cr(e,a,i):(i++,cr(e,i,o)),i<=t&&(a=i+1),t<=i&&(o=i-1)}}function cr(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}var lr={range:Gn(),children:null,height:0},ur=[];for(let e=0;e<128;e++)ur.push(lr);var dr=0,fr=[];for(let e=0;e<4;e++)fr.push(lr);var pr=[],mr=[];for(let e=0;e<8;e++)pr.push(lr),mr.push(0);var hr=Gn(),gr=Gn(),_r=Gn(),vr=[];for(let e=0;e<64;e++)vr.push(0);var yr=class e{constructor(e){this._shared=null,this._cloneKey=null,this._lastMiss={colStart:2**53-1,rowStart:0,colEnd:0,rowEnd:0},this._lastSingle={colStart:2**53-1,rowStart:0,colEnd:0,rowEnd:0},this._lastSingleResult=null,this._options=e,this._rTree=new br(e?.maxNodeEntries??16)}visitRanges(e,t,n=null){let r,i=this.search(e);n&&(i=Cn(i,n));let a=[],o=null,s=i.length;for(let e=0;!o&&e<s;e++){let n=i[e],s=t?.(n);s&&(!0===s.delete?a.push(n):s.update!==void 0&&(a.push(n),r||=[],r.push(s.update)),s&&!0===s.break&&(o=s))}return a.length>0&&this._getWritableTree().removeAll(a),r&&this.load(r),this._onModified(),o}getBoundingRange(){return this._getReadTree().getBoundingRange()}size(){return this._getReadTree().all().length}isEmpty(){return this._getReadTree().isEmpty()}search(e,t=!1,r=!1,i){let a=this._getReadTree();if(a.isEmpty())return n.CommonUtils.EmptyArray;let o=!t&&!r&&!i;if(o){let t=this._lastMiss;if(t.colStart!==2**53-1&&n.CoordUtils.isRangeWithinRange(e,t))return n.CommonUtils.EmptyArray;let r=this._lastSingle;if(r.colStart!==2**53-1&&r.colStart===e.colStart&&r.colEnd===e.colEnd&&r.rowStart===e.rowStart&&r.rowEnd===e.rowEnd)return this._lastSingleResult;if(r.colStart!==2**53-1&&this._lastSingleResult?.length===1&&n.CoordUtils.isRangeWithinRange(e,r)){let r=this._lastSingleResult[0];return r.colStart<=e.colEnd&&r.colEnd>=e.colStart&&r.rowStart<=e.rowEnd&&r.rowEnd>=e.rowStart?this._lastSingleResult:(t.colStart=e.colStart,t.rowStart=e.rowStart,t.colEnd=e.colEnd,t.rowEnd=e.rowEnd,n.CommonUtils.EmptyArray)}}let s=a.searchRange(e,t,i);return o&&(s.length===0?(this._lastMiss.colStart=e.colStart,this._lastMiss.rowStart=e.rowStart,this._lastMiss.colEnd=e.colEnd,this._lastMiss.rowEnd=e.rowEnd,this._lastSingle.colStart=2**53-1,this._lastSingleResult=null):(this._lastMiss.colStart=2**53-1,this._lastSingle.colStart=e.colStart,this._lastSingle.rowStart=e.rowStart,this._lastSingle.colEnd=e.colEnd,this._lastSingle.rowEnd=e.rowEnd,this._lastSingleResult=s)),r&&s.sort(n.CoordUtils.columnFirstRangeComparator),s}has(e){return this._getReadTree().collides(e)}all(e){return this._getReadTree().all(e)}shift(e){let t=e.range,r=e.direction,i=e.cloneIfUpdate??!1,a=e.coordValidator??null,o=e.onShift??null,s=r===n.Direction.Left||r===n.Direction.Right,c=s?n.RangeAxis.Column:n.RangeAxis.Row,l=r===n.Direction.Up||r===n.Direction.Left?-1:1,u=(s?t.colEnd-t.colStart+1:t.rowEnd-t.rowStart+1)*l,d=[],f=[],p=null,m=this.getBoundingRange();if(!m)return this;let h=r===n.Direction.Up||r===n.Direction.Left?n.Direction.Right:n.Direction.Left,g=this._options?.updateEntryOptions,_=g?.isMergeOnShift??!1,v=g?.isSplittable??!0,y=v&&(g?.isSplitOnExpand??!1),b=g?.isTrailingEdge??!1,x=r===n.Direction.Left||r===n.Direction.Up,S=g?.getSplit??Ar,C=g?.getShifted,w=g?.onShifted,T=g?.onRemoved,E=g?.onMerged,D=g?.onUpdated,O=w?[]:null,k=T?[]:null,A=D?[]:null,j;this.visitRanges({colStart:t.colStart-+!!s,rowStart:t.rowStart-+!s,colEnd:s?m.colEnd:t.colEnd,rowEnd:s?t.rowEnd:m.rowEnd},e=>{if((s?e.colEnd<t.colStart:e.rowEnd<t.rowStart)&&!b)return;let i=v&&Nr(t,e,s?n.AxisSelection.Column:n.AxisSelection.Row);if(x&&t.colStart<=e.colStart&&t.rowStart<=e.rowStart&&t.colEnd>=e.colEnd&&t.rowEnd>=e.rowEnd){let r=Pr(e,null,{after:null,before:e,intersect:t,isSplit:i,axis:c,amount:u},C,S,o,!1);if(r===void 0)return;if(r===null)return p=n.CoordUtils.unionRanges(p,e),k&&k.push(e),void d.push(e)}let l={...e};r===n.Direction.Right?(t.colStart<=l.colStart&&(l.colStart+=u),l.colEnd+=u):r===n.Direction.Left?t.colStart<l.colStart?(l.colStart=Math.max(l.colStart+u,t.colStart),l.colEnd=Math.max(l.colEnd+u,l.colStart-1)):l.colEnd+=Math.max(u,t.colStart-l.colEnd-1):r===n.Direction.Down?(t.rowStart<=l.rowStart&&(l.rowStart+=u),l.rowEnd+=u):r===n.Direction.Up&&(t.rowStart<l.rowStart?(l.rowStart=Math.max(l.rowStart+u,t.rowStart),l.rowEnd=Math.max(l.rowEnd+u,t.rowStart-1)):l.rowEnd+=Math.max(u,t.rowStart-l.rowEnd-1)),(l.colEnd<l.colStart||l.rowEnd<l.rowStart)&&(l=null);let m=Pr(e,l,{after:l,before:e,intersect:t,isSplit:i,axis:c,amount:u},C,S,o,y&&u>0);if(m===void 0)return;let h=m===null?[]:m,g=h.length;if(h[0]!==e||g!==1){if(a)for(let e=0;e<g;e++){let t=h[e];t&&a(t)}d.push(e);for(let t=0;t<g;t++){let r=h[t];p=n.CoordUtils.unionRanges(p,r),f.push(r),O&&O.push(r),A&&A.push(e)}}},h),j=i&&(d.length>0||f.length>0)?this.clone():this,j._updateNodes(f,d),e?.onUpdates&&e.onUpdates(f,d,j);let M=n.CommonUtils.EmptyArray;if(_&&m&&p){let e=!0;if(u>0&&(e=s?t.rowStart>m.rowStart||t.rowEnd<m.rowEnd:t.colStart>m.colStart||t.colEnd<m.colEnd),e){let e=xr(p,n.CoordUtils.unionRanges(m,p),+!s,+!!s);E&&(M=j._mergeNodes(e,!1))}}return D&&A.length>0&&D(A),w&&O.length>0&&w(O),E&&M.length>0&&E(M),T&&k.length>0&&T(k),this._onModified(),j}insertNonOverlapping(e,t){return this._insertOneNonOverlapping(e,t)&&this._mergeAdjacent(e,t),this._onModified(),this}insertAllNonOverlapping(e,t){let n=e.length;if(n===0)return this;if(n===1)return this.insertNonOverlapping(e[0],t);let r=e[0],i={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:r.scope},a=this._insertOneNonOverlapping(r,t);for(let r=1;r<n;r++){let n=e[r];this._insertOneNonOverlapping(n,t)&&(a=!0),n.colStart<i.colStart&&(i.colStart=n.colStart),n.rowStart<i.rowStart&&(i.rowStart=n.rowStart),n.colEnd>i.colEnd&&(i.colEnd=n.colEnd),n.rowEnd>i.rowEnd&&(i.rowEnd=n.rowEnd)}return a&&this._mergeAdjacent(i,t),this._onModified(),this}_insertOneNonOverlapping(e,t){let r=t?.onIntersect??((e,t)=>({...e,value:t.value})),i=this.search(e),a=this._options?.updateEntryOptions,o=a?.onUpdated,s=a?.onRemoved,c=a?.getSplit,l=a?.getIntersect,u=a?.getUpdate,d=null,f=null,p=i;if(!(e.value!==null||t?.onIntersect||l||u||s)){let t=null,r=i.length;for(let a=0;a<r;a++){let r=i[a];n.CoordUtils.isRangeWithinRange(r,e)?r.value?.onRemove?.(r):(t??=[]).push(r)}p=t??n.CommonUtils.EmptyArray}let m=Dr(p,e,{getSplit:(e,t,n,r)=>{let i;return c?(i=c(e,t,n,r),i):(i=Ar(e,t,n,r),i)},getIntersect:(e,t)=>{l&&(t=l(e,t));let n=r(e,t);return n===void 0||n!==null&&n.value!==null||e.value?.onRemove?.(e),n},getUpdate:e=>{let t=e;if(u&&(t=u(e)),t&&t.value!==null)o&&(d||=[],d.push(t));else if(s&&!f){f=[];let n=t&&t.value===null?t:{...e,value:null};f.push(n)}return t}}),h=this.getBoundingRange()===null;return this._updateNodes(m,i,t?.onUpdates),d&&o(d),f&&s(f),(m.length>0||i.length>0)&&!h&&!a?.noMerge&&!t?.noMerge}_mergeAdjacent(e,t){let r=this.getBoundingRange();if(!r)return;let i=this._options?.updateEntryOptions,a=xr(e,n.CoordUtils.unionRanges(r,e)),o=this.search(a);if(o.length<=1)return;let s=i?.getMerged??jr,c=o;if(c=Or(c,n.RangeAxis.Column,1,s),c=Or(c,n.RangeAxis.Row,1,s),o.length===c.length)return;this._updateNodes(c,o,t?.onUpdates);let l=i?.onMerged;l&&c.length>0&&l(c)}createCopiedEntries(e,t,r,i,a){let o=this._options?.updateEntryOptions;return function(e,t,r,i,a,o,s){let c=r.colEnd-r.colStart+1,l=r.rowEnd-r.rowStart+1,u=r.colStart-t.colStart,d=r.rowStart-t.rowStart,f=i?.transpose??!1,p=1,m=1;f?(p=t.rowEnd-t.rowStart+1,m=t.colEnd-t.colStart+1):(p=t.colEnd-t.colStart+1,m=t.rowEnd-t.rowStart+1);let h=Math.ceil(c/p),g=Math.ceil(l/m),_=r.scope,v=a??[],y=o??n.CommonUtils.EmptyArray,b=r.colEnd,x=r.rowEnd;return e.visitRanges(t,e=>{let a=e.value;if(!a.copyTo)return;let o=e;if(!n.CoordUtils.isRangeWithinRange(o,t)){if(!s)return;let e=Tr(o,t,s);o=e[e.length-1]}a=o.value;let y=o.colEnd-o.colStart+1,S=o.rowEnd-o.rowStart+1,C=u+o.colStart,w=d+o.rowStart;if(f){C=o.rowStart-t.rowStart+r.colStart,w=o.colStart-t.colStart+r.rowStart;let e=y;y=S,S=e}let T=h,E=g,D=c<=T*y,O=l<=E*S;if(D||O){let e=a?.canTile?.({colStart:C,rowStart:w,colEnd:Math.min(C+(D?c:y)-1,b),rowEnd:Math.min(w+(O?l:S)-1,x)},i);!D||!0!==e&&e!==n.RangeAxis.Column||(y=c,T=1),!O||!0!==e&&e!==n.RangeAxis.Row||(S=l,E=1)}for(let e=0;e<T;e++){let t=C+e*p;for(let e=0;e<E;e++){let n=w+e*m,r=Math.min(t+y-1,b),o=Math.min(n+S-1,x),s={colStart:t,rowStart:n,colEnd:r,rowEnd:o,scope:_};if(t>r||n>o)continue;let c=a.copyTo(s,i);c&&v.push(c)}}},n.Direction.Right),{inserts:v,removes:y}}(this,e,t,r,i,a,o?.isSplittable??1?o?.getSplit??Ar:null)}remove(e,t){return e&&(this._getWritableTree().remove(e,t??wr),this._onModified()),this}removeAll(e,t){return e&&e.length>0&&this._getWritableTree().removeAll(e,t),this._onModified(),this}insert(e){return e&&this._getWritableTree().insert(e),this._onModified(),this}load(e){return e&&e.length>0&&this._getWritableTree(e),this._onModified(),this}clear(){return this.isEmpty()||this._getWritableTree().clear(),this._onModified(),this}delete(e){if(this.isEmpty())return this;if(!e)return this.clear();let t=this.search(e);return t.length===0||(this._getWritableTree().removeAll(t),this._onModified()),this}clone(e=null){if(e!==null&&this._cloneKey===e)return this;let t=this._shared;t||(t={rTree:this._rTree,refCount:1},this._shared=t),t.refCount++;let n=this._createClone(this._options);return n._shared=t,n._cloneKey=e,n}_copy(e,t){let n=e.rTree.all([]),r=new br(this._options?.maxNodeEntries);return t&&(n=n.concat(t)),n.length>0&&r.load(n),{refCount:1,rTree:r}}_updateNodes(e,t,n){if(!(e&&e.length!==0||t&&t.length!==0))return;let r=this._getWritableTree();if(t){let e=t.length;for(let n=0;n<e;n++){let e=t[n],r=e.value;r&&r.onRemove&&r.onRemove(e)}e===1?r.remove(t[0]):e>1&&r.removeAll(t)}e.length>0&&r.load(e),n?.(e,t,this),this._options?.updateEntryOptions?.onUpdates?.(e,t,this)}_mergeNodes(e,t){let r=this.search(e,t),i=n.CommonUtils.EmptyArray;if(r.length>1){let e=this._options?.updateEntryOptions?.getMerged??jr,t=r;t.length>1&&(t=Or(t,n.RangeAxis.Column,1,e)),t.length>1&&(t=Or(t,n.RangeAxis.Row,1,e)),r.length!==t.length&&(i=t,this._updateNodes(t,r))}return i}_getReadTree(){return this._shared?.rTree??this._rTree}_ensureWritable(e){let t=this._shared;if(!t)return;if(t.refCount--,t.refCount===0)return this._shared=null,void(e&&this._rTree.load(e));let n=this._copy(t,e);this._shared=null,this._rTree=n.rTree}_getWritableTree(e){return this._lastMiss.colStart=2**53-1,this._lastSingle.colStart=2**53-1,this._lastSingleResult=null,this._shared?(this._ensureWritable(e),this._rTree):(e&&this._rTree.load(e),this._rTree)}_onModified(){}_createClone(t){return new e(t)}},br=class extends zn{isEmpty(){return super.isEmpty()}searchRange(e,t=!1,r){if(this.isEmpty())return n.CommonUtils.EmptyArray;let i=this.search(e,r);return t?i.filter(t=>t.colStart>=e.colStart&&t.rowStart>=e.rowStart&&t.colEnd<=e.colEnd&&t.rowEnd<=e.rowEnd):i}};function xr(e,t=e,n=1,r=1){return{...e,colStart:Math.max(e.colStart-n,t.colStart),rowStart:Math.max(e.rowStart-r,t.rowStart),colEnd:Math.min(e.colEnd+n,t.colEnd),rowEnd:Math.min(e.rowEnd+r,t.rowEnd)}}function Sr(e,t,n,r){return[{...t[0],value:e.value},{...t[0],value:e.value}]}function Cr(e,t){return{...e}}function wr(e,t){return e===t||!(!e||!t)&&e.rowStart===t.rowStart&&e.rowEnd===t.rowEnd&&e.colStart===t.colStart&&e.colEnd===t.colEnd}function Tr(e,t,r=null){if(wr(e,t))return[{...e}];let i=n.CoordUtils.intersectRanges(e,t,Lr);if(!i)return null;let a=[],o=e.uuid,s=e;if(s.rowStart<i.rowStart){let e={...s,colStart:s.colStart,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:i.rowStart-1};o&&(e.uuid=n.CommonUtils.uuidV4());let t={...s,colStart:s.colStart,rowStart:i.rowStart,colEnd:s.colEnd,rowEnd:s.rowEnd};o&&(t.uuid=n.CommonUtils.uuidV4());let c=t.rowStart-e.rowStart;Ir[0]=e,Ir[1]=t;let l=r(s,Ir,n.RangeAxis.Row,c);l!==void 0&&(a.push(l[0]),s=l[1])}if(s.rowEnd>i.rowEnd){let e={...s,colStart:s.colStart,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:i.rowEnd};o&&(e.uuid=n.CommonUtils.uuidV4());let t={...s,colStart:s.colStart,rowStart:i.rowEnd+1,colEnd:s.colEnd,rowEnd:s.rowEnd};o&&(t.uuid=n.CommonUtils.uuidV4());let c=t.rowStart-e.rowStart;Ir[0]=e,Ir[1]=t;let l=r(s,Ir,n.RangeAxis.Row,c);l!==void 0&&(a.push(l[1]),s=l[0])}if(s.colStart<i.colStart){let e={...s,colStart:s.colStart,rowStart:s.rowStart,colEnd:i.colStart-1,rowEnd:s.rowEnd};o&&(e.uuid=n.CommonUtils.uuidV4());let t={...s,colStart:i.colStart,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:s.rowEnd};o&&(t.uuid=n.CommonUtils.uuidV4());let c=t.colStart-e.colStart;Ir[0]=e,Ir[1]=t;let l=r(s,Ir,n.RangeAxis.Column,c);l!==void 0&&(a.push(l[0]),s=l[1])}if(s.colEnd>i.colEnd){let e={...s,colStart:s.colStart,rowStart:s.rowStart,colEnd:i.colEnd,rowEnd:s.rowEnd};o&&(e.uuid=n.CommonUtils.uuidV4());let t={...s,colStart:i.colEnd+1,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:s.rowEnd};o&&(t.uuid=n.CommonUtils.uuidV4());let c=t.colStart-e.colStart;Ir[0]=e,Ir[1]=t;let l=r(s,Ir,n.RangeAxis.Column,c);l!==void 0&&(a.push(l[1]),s=l[0])}return s===e&&(s={...e}),a.push(s),a}function Er(e){return e.value===null?null:e}function Dr(e,t,r){let i=r?.getIntersect??Cr,a=r?.getUpdate??Er;if(e.length===0){let e=t;if(i){let n=i({...t,value:null},t);e=n&&n.value!==null?{...n}:null}if(a){let t=a(e);t!==void 0&&(e=t)}return e?[e]:n.CommonUtils.EmptyArray}let o=r?.getSplit??Sr,s=(e,t)=>{let n=t.search(e),r=n.length;for(let i=0;i<r;i++){let r=n[i];if(wr(r,e))continue;t?.remove(r);let a=Tr(r,e,o);for(let e=0;e<a.length;e++){let n=a[e];t.insert(n),s(n,t)}}},c=new yr;c.load(e),s(t,c);let l=new yr;l.load([t]);let u=c.search(t);for(let e=0;e<u.length;e++)s(u[e],l);let d=(e,t,n)=>{let r=t.search(e);console.assert(r.length<=1,`intersecting incorrect ranges`);let a=r[0]??{...e,value:null};if(wr(a,e)){let r=i(a,e);t.remove(a),n.insert(r)}else{t.remove(a);let r=Tr(a,e,o),s=r.length;for(let a=0;a<s;a++){let o=r[a];if(wr(o,e)){let t=i(o,e);n.insert(t)}else t.insert(o)}}},f=new yr,p=l.all([]),m=p.length;for(let e=0;e<m;e++)d(p[e],c,f);let h=c.all([]);return((e,t)=>{let n=e.all([]),r=n.length;for(let e=0;e<r;e++){let r=n[e];if(a){let e=a(r);e!==void 0&&(r=e)}r!==null&&r.value!==null&&t.push(r)}})(f,h),h}function Or(e,t=n.RangeAxis.Column,r=2,i,a){let o=[...e];if(r<=0||e.length<=1)return o;let s=t===n.RangeAxis.Column,c=0,l=0;do{let e=o.sort(n.CoordUtils.createRangeComparator(s?n.RangeAxis.Row:n.RangeAxis.Column));o=[];let t=!1;o.push(e[0]);let r=e.length;for(let c=1;c<r;c++){let r=e[c],l=o[o.length-1],u=!1;if(u=s?l&&l.rowStart===r.rowStart&&l.rowEnd===r.rowEnd&&l.colEnd+1===r.colStart&&l.scope===r.scope:l&&l.colStart===r.colStart&&l.colEnd===r.colEnd&&l.rowEnd+1===r.rowStart&&l.scope===r.scope,u){let e={...l};if(e.colEnd=s?r.colEnd:l.colEnd,e.rowEnd=s?l.rowEnd:r.rowEnd,i){let t=a??[null,null];t[0]=l,t[1]=r,e=i(t,e,s?n.RangeAxis.Column:n.RangeAxis.Row)}if(e){o[o.length-1]=e,t=!0;continue}}o.push(r)}l=t?0:l+1,c++,s=!s}while(c<r&&l<2&&o.length>1);return o}function kr(e,t=2,r=n.RangeAxis.Row,i,a,o){if(e.length<=1)return[...e];let s=function(e){let t=e[0]?.scope??null,n=!1;for(let r=1;r<e.length;r++)if((e[r]?.scope??null)!==t){n=!0;break}if(!n)return null;let r=new Map;for(let t=0;t<e.length;t++){let n=e[t],i=n?.scope??null,a=r.get(i);a?a.push(n):r.set(i,[n])}return Array.from(r.values())}(e);if(s){let e=[];for(let n=0;n<s.length;n++){let c=kr(s[n],t,r,i,a,o);for(let t=0;t<c.length;t++)e.push(c[t])}return e}let c=e[0]?.scope??void 0,l=[],u=r===n.RangeAxis.Column,d=new Vt.IteratorInstance(e,{axis:u?n.RangeAxis.Row:n.RangeAxis.Column}),f=d.next();for(;!f.done;){let e=f.value;f=d.next();let r=e.range;if(a&&e.overlaps.length>1&&a(r,e.overlaps),t>0){let e=l[l.length-1],t=!1;if(t=u?e&&e.rowStart===r.rowStart&&e.rowEnd===r.rowEnd&&e.colEnd+1===r.colStart:e&&e.colStart===r.colStart&&e.colEnd===r.colEnd&&e.rowEnd+1===r.rowStart,t){let t={...e,colEnd:u?r.colEnd:e.colEnd,rowEnd:u?e.rowEnd:r.rowEnd};if(i){let a=o??[null,null];a[0]=e,a[1]=r,t=i(a,t,u?n.RangeAxis.Column:n.RangeAxis.Row)}if(t){l[l.length-1]=t;continue}}}l.push(r)}if(t>1&&(l=Or(l,u?n.RangeAxis.Row:n.RangeAxis.Column,t,i,o)),c!==void 0)for(let e=0;e<l.length;e++)l[e].scope===void 0&&(l[e]={...l[e],scope:c});return l}function Ar(e,t,n,r){let i=e.value;if(i?.getSplit){let e=i.getSplit(t,n,r);if(e===void 0)return;t[0].value=e[0],t[1].value=e[1]}return t}function jr(e,t,r){let i=e[0].value,a=e[1].value;if(a){let o;if(i?.getMerged?o=i.getMerged(e[1].value,n.CoordUtils.sanitizeRange(t),r):i&&(o=i===a?a:void 0),o===void 0)return;t.value=o}return t}function Mr(e,t,r,i){let a=t,o=!0;for(;o;){o=!1;for(let t=0;t<4&&!o;t++){let s=t<2,c=t%2==0,l=s?{colStart:a.colStart,colEnd:a.colEnd,rowStart:c?a.rowStart-1:a.rowEnd+1,rowEnd:c?a.rowStart-1:a.rowEnd+1,scope:a.scope}:{rowStart:a.rowStart,rowEnd:a.rowEnd,colStart:c?a.colStart-1:a.colEnd+1,colEnd:c?a.colStart-1:a.colEnd+1,scope:a.scope};if(l.rowStart<0||l.colStart<0)continue;let u=e(l);if(u.length!==1)continue;let d=u[0];if(!(s?d.colStart===a.colStart&&d.colEnd===a.colEnd:d.rowStart===a.rowStart&&d.rowEnd===a.rowEnd)||d.value===a.value)continue;let f=c?d:a,p=c?a:d,m={colStart:f.colStart,rowStart:f.rowStart,colEnd:p.colEnd,rowEnd:p.rowEnd,scope:a.scope},h=r(f,p,m,s?n.RangeAxis.Row:n.RangeAxis.Column);if(h===void 0)continue;let g={...m,value:h};i([a,d],g),a=g,o=!0}}return a}function Nr(e,t,r=n.AxisSelection.Both){let i=n=>n?e.rowStart>t.rowStart&&e.rowStart<=t.rowEnd||e.rowEnd<t.rowEnd&&e.rowEnd>=t.rowStart:e.colStart>t.colStart&&e.colStart<=t.colEnd||e.colEnd<t.colEnd&&e.colEnd>=t.colStart,a=r===n.AxisSelection.Column,o=r===n.AxisSelection.Row;return r===n.AxisSelection.Both&&(a=o=!0),!(!a||!i(!0))||!(!o||!i(!1))}function Pr(e,t,r,i,a,o,s){let c=r.axis===n.RangeAxis.Column,l=r.intersect,u=(t,u)=>{let d=t.value,f=null,p=u.after;if(s){let r=null,i=0,o=0;if(c&&l.colStart>t.colStart?(r={...t,colEnd:l.colStart-1},o=u.amount):!c&&l.rowStart>t.rowStart&&(r={...t,rowEnd:l.rowStart-1},i=u.amount),r){let t=Tr(e,r,a);if(t.length>1)for(let e=0;e<t.length;e++){let a=t[e];wr(a,r)?(f??=[],f.push(a)):(p=a,d=a.value,u={...u,after:{...a,colStart:a.colStart+o,rowStart:a.rowStart+i,colEnd:a.colEnd+o,rowEnd:a.rowEnd+i,uuid:n.CommonUtils.uuidV4()},before:a,isSplit:!0})}}}if(i?p=i(u.before,u.after,u):d&&d.getShifted?p=d.getShifted(u):u.after&&(p={...u.after,value:t.value}),p!==void 0)return o&&(p!==u.after&&(u={...u,after:p}),o(u)),p=(t=>{if(!t){let t=e.value;return t.onRemove&&t.onRemove(r.before),null}return t})(p),p&&(f??=[],f.push(p)),f};if(r.isSplit){let n;n=c?{...e,rowStart:Math.max(l.rowStart,r.before.rowStart),rowEnd:Math.min(l.rowEnd,r.before.rowEnd)}:{...e,colStart:Math.max(l.colStart,r.before.colStart),colEnd:Math.min(l.colEnd,r.before.colEnd)};let i=Tr(e,n,a),o=[];for(let e=0;e<i.length;e++){let a=i[e];if(wr(a,n)){let e=null;t&&(e=c?{colStart:t.colStart,rowStart:n.rowStart,colEnd:t.colEnd,rowEnd:n.rowEnd,value:a.value}:{colStart:n.colStart,rowStart:t.rowStart,colEnd:n.colEnd,rowEnd:t.rowEnd,value:a.value});let i=u(a,{...r,before:a,after:e});if(i)for(let e=0;e<i.length;e++)o.push(i[e])}else o.push(a)}return o}return u(e,r)}function Fr(e,t){let r=e=>`${e.scope??``}!${e.rowStart},${e.colStart},${e.rowEnd},${e.colEnd}`,i=new Set,a=[],o=kr(t(e),2,n.RangeAxis.Row);for(;o.length>0;){let e=[];for(let n of o){let o=r(n);i.has(o)||(i.add(o),a.push(n),e.push(...t(n)))}o=kr(e,2,n.RangeAxis.Row)}return kr(a,2,n.RangeAxis.Row)}var Ir=[null,null],Lr={colStart:0,rowStart:0,colEnd:0,rowEnd:0};function Rr(e=-(2**53-1),t=-(2**53-1),r=2**53-1,i=2**53-1,a,o,s){if(o&&(e!==-(2**53-1)&&e<o.colStart||t!==-(2**53-1)&&t<o.rowStart||r!==2**53-1&&r>o.colEnd||i!==2**53-1&&i>o.rowEnd))throw new n.OutOfBoundsError;return s&&(e=Math.max(s.colStart,e),t=Math.max(s.rowStart,t),r=Math.min(s.colEnd,r),i=Math.min(s.rowEnd,i),r<e||i<t)?null:(Hr.majorStart=a?e:t,Hr.majorEnd=a?r:i,Hr.minorStart=a?t:e,Hr.minorEnd=a?i:r,Hr)}function zr(e,t,n){let r=n??{colStart:0,rowStart:0,colEnd:0,rowEnd:0};return r.colStart=t?e.majorStart:e.minorStart,r.rowStart=t?e.minorStart:e.majorStart,r.colEnd=t?e.majorEnd:e.minorEnd,r.rowEnd=t?e.minorEnd:e.majorEnd,r}function Br(e,t,n,r,i){let a=i??{done:!1,value:[{colIndex:-1,rowIndex:-1},null]},o=a.value,s=o[0];return s.colIndex=r?e:t,s.rowIndex=r?t:e,o[1]=n,a}function Vr(e){if(typeof e==`boolean`){if(!0===e)return{done:!1,value:[{colIndex:-1,rowIndex:-1},null]}}else if(e)return e}var Hr={majorStart:0,majorEnd:0,minorStart:0,minorEnd:0};function Ur(e,t){return e[0]-t[0]}var Wr=class{constructor(e,t){this._isColumn=!0,this._isReverse=!1,this._skipMajors=!1,this._majorMin=2**53-1,this._majorMax=-(2**53-1),this._minorMin=2**53-1,this._minorMax=-(2**53-1),this._majorIndex=-(2**53-1),this._minorIndex=-(2**53-1),this._delegateMajorIndex=-(2**53-1),this._delegateMinorIndex=-(2**53-1),this._delegate=e;let r=(t.axis??n.RangeAxis.Column)===n.RangeAxis.Column;this._isColumn=r,this._isReverse=t.reverse??!1,this._skipMajors=t.skipMajors??!1;let i=t.bounds,a=i.colStart,o=i.rowStart,s=i.colEnd,c=i.rowEnd;this._majorMin=r?a:o,this._majorMax=r?s:c,this._minorMin=r?o:a,this._minorMax=r?c:s,this._processMajorSkip=r?t.processColumnSkip:t.processRowSkip,this._processMinorSkip=r?t.processRowSkip:t.processColumnSkip;let l=e.next();this._delegateResult=l,this._initialize()}_initialize(){let e=this._isColumn,t=this._isReverse,n=t?-1:1,r=t?this._majorMax:this._majorMin,i=(t?this._minorMax:this._minorMin)-n,a=this._processMinorSkip;a&&(i=a(i,t));let o=this._processMajorSkip;o&&(r=o(r,t)),this._majorIndex=r,this._minorIndex=i;let s=this._delegateResult;if(s.done)this._delegateMajorIndex=this._majorMax,this._delegateMinorIndex=this._minorMax+n;else{let t=s.value[0];this._delegateMajorIndex=e?t.colIndex:t.rowIndex,this._delegateMinorIndex=e?t.rowIndex:t.colIndex}}next(e){e!==void 0&&(this._delegateResult=this._delegate.next(e),this._initialize());let t=this._isReverse,n=this._isColumn,r=this._majorMin,i=this._majorMax,a=this._majorIndex,o=this._minorIndex;if(a>i||a<r)return zt;let s=this._delegateMajorIndex,c=this._delegateMinorIndex,l=this._delegateResult.done;if(a===s&&o===c){let e=this._delegate.next();if(this._delegateResult=e,l=e.done,l)s=t?r:i,s=t?this._minorMin:this._minorMax;else{let t=e.value[0];s=n?t.colIndex:t.rowIndex,c=n?t.rowIndex:t.colIndex}this._delegateMajorIndex=s,this._delegateMinorIndex=c}let u=t?-1:1;if(this._minorIndex=o+=u,a===s&&o===c&&!l)return this._delegateResult;let d=this._processMinorSkip;if(d&&(o=d(o,t)),o>this._minorMax||o<this._minorMin){a+=u;let e=this._processMajorSkip;e&&(a=e(a,t)),this._skipMajors&&(!t&&a<s||t&&a>s)&&(a=s),this._majorIndex=a,o=t?this._minorMax:this._minorMin}return this._minorIndex=o,a!==s||o!==c||l?a>i||a<r?zt:{done:!1,value:[{colIndex:n?a:o,rowIndex:n?o:a},void 0]}:this._delegateResult}return(e){return null}throw(e){return null}[Symbol.iterator](){return this}},Gr=class{constructor(e){this._isColumn=!0,this._majorSize=2**53-1,this._minorSize=2**53-1,this._majorMin=2**53-1,this._majorMax=-(2**53-1),this._minorMin=2**53-1,this._minorMax=-(2**53-1),this._majorIndex=2**53-1,this._minorIndex=2**53-1,this._minorOffset=0,this._minorRepeat=0,this._majorOffset=-1,this._majorRepeat=1,this._pattern=[];let t=e.delegate;this._delegate=t;let r=(e.axis??n.RangeAxis.Column)===n.RangeAxis.Column;this._isColumn=r;let i=e.dims,a=e.bounds,o=a.colStart,s=a.rowStart,c=a.colEnd,l=a.rowEnd;if(this._majorSize=1+(r?c-o:l-s),this._minorSize=1+(r?l-s:c-o),this._majorMin=r?o:s,this._minorMin=r?s:o,this._majorMax=(r?o+i.major:s+i.major)-1,this._minorMax=(r?s+i.minor:o+i.minor)-1,this._majorSize>this._majorMax+1||this._minorSize>this._minorMax+1)throw Error(`The dimensions must be larger than the bounds.`);let u=t.next();this._nextDelegateResult=u,this._initialize()}_initialize(){let e=this._isColumn,t=this._nextDelegateResult;if(t.done)this._nextResult=zt;else{let n=t.value[0],r=e?n.colIndex:n.rowIndex,i=e?n.rowIndex:n.colIndex,a=[[i,t.value[1]]];this._minorSpan=a,this._majorIndex=r,this._minorIndex=i,this._pattern.push([r,a]),this._nextResult=t}}next(e){if(e!==void 0)throw new n.NotImplementedError;let t=this._nextResult,r=this._isColumn,i=this._majorIndex,a=this._nextDelegateResult;if(!a.done){let e=a.value[0];if((r?e.colIndex:e.rowIndex)===i&&(a=this._delegate.next(),this._nextDelegateResult=a,!a.done)){let e=a.value,n=e[0],o=r?n.colIndex:n.rowIndex,s=r?n.rowIndex:n.colIndex;if(o===i)return this._minorSpan.push([s,e[1]]),this._minorOffset=this._minorSpan.length-1,this._minorIndex=s,this._nextResult=a,t}}let o=this._minorMax,s=this._minorIndex;if(s<o){let e=this._minorOffset;e++;let n=this._minorSpan;e>=n.length&&(e=0,this._minorRepeat++);let a=n[e],c=this._minorMin;if(s=c+(a[0]-c+this._minorSize*this._minorRepeat),this._minorIndex=s,this._minorOffset=e,s<=o){let e=[{colIndex:r?i:s,rowIndex:r?s:i},a[1]];return this._nextResult={done:!1,value:e},t}}if(!a.done){let e=a.value,n=e[0],i=r?n.colIndex:n.rowIndex,o=r?n.rowIndex:n.colIndex,s=[[o,e[1]]];return this._pattern.push([i,s]),this._majorIndex=i,this._minorSpan=s,this._minorOffset=0,this._minorIndex=o,this._minorRepeat=0,this._nextResult=a,t}let c=this._majorMax;if(i<c){let e=this._majorOffset;e++;let n=this._pattern;e>=n.length&&(e=0,this._majorRepeat++);let a=n[e],o=a[1],l=o[0],u=this._majorMin;if(i=u+(a[0]-u+this._majorSize*this._majorRepeat),this._majorIndex=i,this._majorOffset=e,i<=c){this._minorSpan=o,this._minorOffset=0,s=l[0],this._minorIndex=s,this._minorRepeat=0;let e=[{colIndex:r?i:s,rowIndex:r?s:i},l[1]];return this._nextResult={done:!1,value:e},t}}return t.done||(this._nextResult=zt),t}return(e){return null}throw(e){return null}[Symbol.iterator](){return this}},Kr=class{constructor(e,t,r){this._comparator=e?.comparator??n.CoordUtils.createCellComparator(e.axis??n.RangeAxis.Column,e.reverse??!1),this._iterator1=t,this._iterator2=r;let i=t.next();this._nextResult1=i;let a=r.next();this._nextResult2=a,e?.reuseResult&&(!0===e.reuseResult?this._reuseResult={done:!1,value:[void 0,void 0,void 0,void 0]}:this._reuseResult=e.reuseResult)}next(e){let t=this._nextResult1,n=this._nextResult2;if(t.done&&n.done)return t;if(t.done){let e=n;this._nextResult2=this._iterator2.next();let t=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};t.done=!1;let r=t.value,i=e.value;return r[2]=i[0],r[3]=i[1],r[0]=void 0,r[1]=void 0,t}if(n.done){let e=t;this._nextResult1=this._iterator1.next();let n=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};n.done=!1;let r=n.value,i=e.value;return r[0]=i[0],r[1]=i[1],r[2]=void 0,r[3]=void 0,n}let r=(0,this._comparator)(t.value[0],n.value[0]);if(r<0){let e=t;this._nextResult1=this._iterator1.next();let n=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};n.done=!1;let r=n.value,i=e.value;return r[0]=i[0],r[1]=i[1],r[2]=void 0,r[3]=void 0,n}if(r>0){let e=n;this._nextResult2=this._iterator2.next();let t=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};t.done=!1;let r=t.value,i=e.value;return r[2]=i[0],r[3]=i[1],r[0]=void 0,r[1]=void 0,t}this._nextResult1=this._iterator1.next(),this._nextResult2=this._iterator2.next();let i=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};i.done=!1;let a=i.value;return a[0]=t.value[0],a[1]=t.value[1],a[2]=n.value[0],a[3]=n.value[1],i}return(e){return null}throw(e){return null}[Symbol.iterator](){return this}},qr=`Must be an array of arrays.`;function Jr(e,t,n){let r=t.majorStart,i=t.minorStart,a=t.majorEnd,o=[],s=t.minorEnd-i+1,c=typeof e==`function`;for(let t=r;t<=a;t++){let r;if(c)if(r=[],n){let n=i;for(let i=0;i<s;i++)r.push(e(n++,t))}else{let n=i;for(let i=0;i<s;i++)r.push(e(t,n++))}else s<=ti?(r=Array(s),r.fill(e,0,s)):r=new ln([e],s);let a=[[i,r]];o.push([t,a])}return{tuples:o,bounds:t}}function Yr(e,t=!1,r=null,i=!1){let a=0,o=0,s=2**53-1,c=2**53-1;if(r&&(a=r.majorStart??0,o=r.minorStart??0,s=(r.majorEnd??2**53-1)-a+1,c=(r.minorEnd??2**53-1)-o+1),t){let e=a;a=o,o=e;let t=s;s=c,c=t}if(!Array.isArray(e))throw Error(qr);if(e.length>s)throw new n.OutOfBoundsError;if(t)return Xr(e,a,o,c,i);let l=new z.Builder;for(let t=0;t<e.length;t++){let r=e[t];if(r!=null&&r.length!==0){if(!Array.isArray(r))throw Error(qr);if(r.length>c)throw new n.OutOfBoundsError;if(i){let e=-1;for(let n=0;n<r.length;n++)r[n]==null?e!==-1&&(l.pushMultipleAt(t+a,o+e,r.slice(e,n)),e=-1):e===-1&&(e=n);e!==-1&&l.pushMultipleAt(t+a,o+e,r.slice(e))}else l.pushMultipleAt(t+a,o,r)}}return l.build()}var Xr=(e,t,r,i,a)=>{let o=e.length,s=-1,c=!a;for(let t=0;t<o;t++){let r=e[t];if(r!=null&&r.length!==0){if(!Array.isArray(r))throw Error(qr);if(r.length>i)throw new n.OutOfBoundsError;s===-1?s=r.length:r.length!==s&&(c=!1)}else c=!1}if(s===-1)return null;if(c){let n=Array(s);for(let i=0;i<s;i++){let a=Array(o);for(let t=0;t<o;t++)a[t]=e[t][i];n[i]=[r+i,[[t,a]]]}return{tuples:n,bounds:{majorStart:r,minorStart:t,majorEnd:r+s-1,minorEnd:t+o-1}}}let l=[],u=[],d=[],f=-1,p=-1;for(let n=0;n<o;n++){let r=e[n];if(r==null)continue;let i=r.length;for(let e=0;e<i;e++){let i=r[e];if(a&&i==null)continue;let o=l[e];if(o===void 0||u[e]!==n-1){l[e]=o=[];let r=[t+n,o],i=d[e];i?i.push(r):d[e]=[r],f===-1&&(f=n)}o.push(i),u[e]=n,p=n}}let m=[];for(let e=0;e<d.length;e++){let t=d[e];t&&m.push([r+e,t])}return m.length===0?null:{tuples:m,bounds:{majorStart:m[0][0],minorStart:t+f,majorEnd:m[m.length-1][0],minorEnd:t+p}}},Zr=(e,t,n)=>{if(e===t)return t},Qr=(e,t,n)=>{if(e[0].value===e[1].value)return t},$r=[null,null];function ei(e=!0,t=Zr,r){let i=[],a,o,s=-(2**53-1),c=-(2**53-1),l=0,u=(t,n,r)=>{let i=e?t.colStart:t.rowStart;return n===i?r<(e?t.rowStart:t.colStart)?-1:+(r>(e?t.rowEnd:t.colEnd)):n<i?-1:1};return{append:(n,l,u)=>{if(r&&a&&n===s&&l===c){let t=r(o,u);(e?a.rowStart===l:a.colStart===l)?a.value=t:(e?a.rowEnd=l-1:a.colEnd=l-1,i.push(a),a=e?{colStart:n,rowStart:l,colEnd:n,rowEnd:l,value:t}:{colStart:l,rowStart:n,colEnd:l,rowEnd:n,value:t}),o=t;return}let d,f=!0;if(u!==void 0&&(d=o===void 0?u:t(o,u,e),d===void 0&&(f=!1)),f&&l===c+1&&n===s)return u!==void 0&&(u=d),e?a.rowEnd=l:a.colEnd=l,c=l,void(o=u);a&&i.push(a);let p=e?n:l,m=e?l:n;a={colStart:p,rowStart:m,colEnd:p,rowEnd:m,value:u},s=n,c=l,o=u},done:(t=!1)=>(a&&=(i.push(a),null),t?Or(i,e?n.RangeAxis.Column:n.RangeAxis.Row,2,Qr,$r):i),find:(e,t)=>{if(a){let n=u(a,e,t);if(n===0)return a;if(n>0)return}let n=i.length,r=0,o=n-1;if(l<n){let a=u(i[l],e,t);if(a===0)return i[l];if(a<0)o=l-1;else if(r=l+1,r<n){let n=u(i[r],e,t);if(n===0)return l=r,i[r];if(n<0)return;r++}}for(;r<=o;){let n=r+o>>>1,a=u(i[n],e,t);if(a===0)return l=n,i[n];a<0?o=n-1:r=n+1}l=o<0?0:o}}}var ti=4,ni=class e{constructor(e){this._dataCoords=null,this._count=0,this._isColumn=!0,this._lastMajor=-(2**53-1),this._lastMinorSpan=null,this._maxCoords=void 0,this._isShared=!1,this._options={axis:n.RangeAxis.Row,...e},this._isColumn=(this._options?.axis??n.RangeAxis.Column)===n.RangeAxis.Column,e?.maxCoords&&(this._maxCoords=Object.freeze({colStart:Math.max(0,e.maxCoords.colStart??0),rowStart:Math.max(0,e.maxCoords.rowStart??0),colEnd:Math.min(2**53-1,e.maxCoords.colEnd??2**53-1),rowEnd:Math.min(2**53-1,e.maxCoords.rowEnd??2**53-1)})),this._createRun=e?.createRun??(e=>new Ht(e)),this._optionsMinor={},this._major=new Tn({nodeSize:ri})}getRuns(e){let t=this._isColumn,n=this._maxCoords,r=this.getCoords();if(!r)return Bt;let i=e?.bounds,a,o;if(i){let s=Rr(i?.colStart??-(2**53-1),i?.rowStart??-(2**53-1),i?.colEnd??2**53-1,i?.rowEnd??2**53-1,t,n,r);if(!s)return Bt;a={bounds:{min:s.majorStart,max:s.majorEnd}},o={bounds:{min:s.minorStart,max:s.minorEnd},overflowRun:e?.overflowRun}}let s=this._major.entries(a),c,l,u,d;do{if(c=s.next(),c.done)return Bt;l=c.value[1],u=l.runs(o),d=u.next()}while(d.done);let f=c.value[0],p=d.value[0].min,m=d.value[1];return{[Symbol.iterator](){return this},next(){if(c.done)return zt;let e={done:!1,value:[f,p,m]};for(d=u.next();d.done&&!c.done;)c=s.next(),c.done||(f=c.value[0],l=c.value[1],u=l.runs(o),d=u.next());return d.done||(p=d.value[0].min,m=d.value[1]),e}}}getAxis(){return this._isColumn?n.RangeAxis.Column:n.RangeAxis.Row}entries(e){let t=this._isColumn,r=t,i=!0,a=this._maxCoords,o=this.getCoords(),s=Rr(-(2**53-1),-(2**53-1),2**53-1,2**53-1,t,a,o??void 0);if(!s)return Bt;let c,l,u,d=s.majorStart,f=s.majorEnd,p=s.minorStart,m=s.minorEnd,h=!1;if(e){e?.axis&&(r=e?.axis===n.RangeAxis.Column,i=t===r);let s=e?.bounds;if(s){let e=Rr(s.colStart,s.rowStart,s.colEnd,s.rowEnd,t,a,o??void 0);if(!e)return Bt;d=e.majorStart,f=e.majorEnd,p=e.minorStart,m=e.minorEnd}h=e.reverse??!1,u=Vr(e.reuseResult),c=t?e.processColumnSkip:e.processRowSkip,c&&(h?f=c(f,h):d=c(d,h)),l=t?e.processRowSkip:e.processColumnSkip,l&&(h?m=l(f,h):p=l(p,h))}if(!o)return Bt;i||d!==f||(i=!0),ci.bounds.min=d,ci.bounds.max=f,ci.reverse=h,ci.processSkip=c,ci.reuseResult=oi;let g=this._major.entries(ci),_=li(),v=e=>{if(!e.nextActive)return;let t=t=>{let n=e.nextMinorIndex,r=e.nextMinorValue,i=e.nextActive;return t?(e.nextMinorIndex=t[0],e.nextMinorValue=t[1],e.nextActive=!0):(e.nextActive=!1,e.nextMinorIndex=h?-(2**53-1):2**53-1,e.nextMinorValue=null),e.value=r,e.minorIndex=n,e.active=i,ii[0]=e.majorIndex,ii[1]=n,ii[2]=r,ii},n=e.minorIterator;if(!n)return t();let r=n.next();return r.done&&(e.minorIterator=null),t(r.value)},y=e=>{if(g)for(;;){let t=g.next();if(t.done)return void(g=void 0);let n=t.value,r=n[1];e.majorIndex=n[0],e.active=!0,e.nextActive=!1,si.bounds.min=p,si.bounds.max=m,si.reverse=h,si.processSkip=l,si.reuseResult=ai;let i=r.entries(si),a=i.next();if(!a.done){let t=a.value;return e.nextMinorIndex=t[0],e.nextMinorValue=t[1],e.minorIterator=i,e.nextActive=!0,v(e)}}},b=null;if(i)b=()=>{let e;return e=v(_),e||(e=y(_),e||void 0)};else{let e=h?m:p,t=h?p:m,n,r=e,i=t,a=!0,o=()=>{let e=_.nextMajorCursor;if(e)return _=e,_;_=n,(r<p||r>m||r===i)&&(_=null),r=i,i=t};b=()=>{for(;_;){let s=null;if(a){let t=n?li():_;if(s=y(t),s){n?(t.prevMajorCursor=_,_.nextMajorCursor=t,_=t):n=_,i=h?Math.max(i,_.nextMinorIndex):Math.min(i,_.nextMinorIndex);let r=_.minorIndex;r!==e&&(i=h?Math.max(i,r):Math.min(i,r),s=null)}else a=!1,o()}else{let e=_.minorIndex,a=_.nextMinorIndex;e===r?(ii[0]=_.majorIndex,ii[1]=e,ii[2]=_.value,s=ii):!h&&e>r||h&&e<r?i=h?Math.max(i,e):Math.min(i,e):!h&&a>r||h&&a<r?i=h?Math.max(i,a):Math.min(i,a):s=v(_),_.active&&(i=h?Math.max(i,_.nextMinorIndex):Math.min(i,_.nextMinorIndex)),t===r||_.active||(_.prevMajorCursor?_.prevMajorCursor.nextMajorCursor=_.nextMajorCursor:n=_.nextMajorCursor,_.nextMajorCursor&&(_.nextMajorCursor.prevMajorCursor=_.prevMajorCursor)),o()}if(s)return s}}}return{next(e){if(e)throw new n.NotImplementedError(`Iterator with next argument is not supported.`);let r=b();return r?Br(r[0],r[1],r[2],t,u):zt},[Symbol.iterator](){return this},return:e=>null,throw:e=>null}}values(e){let t=this.entries(e),n;return e?.reuseResult&&(n=!0===e.reuseResult?{done:!1,value:null}:e.reuseResult),{next(e){let r=t.next(e);return r.done?zt:n?(n.value=r.value[1],n):{done:!1,value:r.value[1]}},[Symbol.iterator](){return this},return:e=>null,throw:e=>null}}keys(e){let t=this.entries(e),n;return e?.reuseResult&&(n=!0===e.reuseResult?{done:!1,value:null}:e.reuseResult),{next(e){let r=t.next(e);return r.done?zt:n?(n.value=r.value[0],n):{done:!1,value:r.value[0]}},[Symbol.iterator](){return this},return:e=>null,throw:e=>null}}_updateMajorSpan(e,t=!1){if(!e||e.length===0)return;t&&e.sort((e,t)=>e[0]-t[0]);let n=this._major,r=e[0],i=r[0],a=i,o=[r[1]];for(let t=1;t<e.length;t++){let r=e[t],s=r[0],c=r[1];s===a+1?o.push(c):(n.setRunAt(i,new Ht(o)),i=s,o=[c]),a=s}o.length>0&&n.setRunAt(i,new Ht(o))}setValues(e){if(!e)throw new n.NullNotAllowedError;if(e.length===0)return this;let t=(e=e.sort(Ur))[0][0],r=e[e.length-1][0],i=-(2**53-1),a=2**53-1,o=this._isColumn,s=this._maxCoords;if(s){let e=o?s.colStart:s.rowStart,c=o?s.colEnd:s.rowEnd;if(t<e||r>c)throw new n.OutOfBoundsError;i=o?s.rowStart:s.colStart,a=o?s.rowEnd:s.colEnd}if(!e||e.length===0)return this;let c=2**53-1,l=-(2**53-1),u=0,d=t-1,f=[],p=(e,t,r)=>{if(d===r)throw new z.OutOfOrderError(`Duplicate major Indices: {${r}}.`);d=r,t=t.sort(Ur),e=e.clone();let o=-(2**53-1),s=t.length;for(let d=0;d<s;d++){let s=t[d],f=s[0],p=s[1],h=f+p.length-1;if(o>=f)throw new z.OutOfOrderError(`Overlapping minor Indices: {${r}, ${f}}.`);if(f<i||h>a)throw new n.OutOfBoundsError;if(p&&p.length>0){let t=e.getCount();e.setRunAt(f,m(p));let n=e.getCount();u+=n-t,c=Math.min(c,e.getCoords().min),l=Math.max(l,e.getCoords().max)}o=h}g++,f.push([r,e])},m=this._createRun,h=this._optionsMinor,g=0,_=()=>{let t=e[g],n=t[0],r=t[1],i=new Tn(h);p(i,r,n)},v=this._major;ci.bounds.min=t,ci.bounds.max=r,ci.reverse=!1,ci.processSkip=null,ci.reuseResult=oi;let y=v.entries(ci),b=y.next();for(;!b.done;){let t=b.value,n=t[0],r=e[g],i=r[0];if(i>n)b=y.next();else{for(;i<n;)_(),r=e[g],i=r[0];if(i===n){let e=r[1],i=t[1];p(i,e,n)}b=y.next()}}for(;e[g];)_();return this._updateMajorSpan(f),this._updateCountAndCoords(u,t,c,r,l),this}getValues(e){let t=this.getRuns(e?{bounds:e}:void 0),n=t.next();if(n.done)return null;let r=new z.Builder;for(;!n.done;){let e=n.value[0],i=n.value[1],a=n.value[2];r.pushMultipleAt(e,i,a),n=t.next()}return r.build()}_updateCountAndCoords(e,t,n,r,i,a=!1){let o=this._count+e;if(this._count=o,this._lastMajor=-(2**53-1),!this._dataCoords)return;let s=this._isColumn,c=s?t:n,l=s?n:t,u=s?r:i,d=s?i:r;if(o===0)this._dataCoords=null;else{let e=this._dataCoords;e&&(c=(a?Math.max:Math.min)(c,e.colStart),l=(a?Math.max:Math.min)(l,e.rowStart),u=(a?Math.min:Math.max)(u,e.colEnd),d=(a?Math.min:Math.max)(d,e.rowEnd));let t={colStart:c,rowStart:l,colEnd:u,rowEnd:d};this._dataCoords=t}}clear(){this._major.clear(),this._dataCoords=null,this._count=0,this._lastMajor=-(2**53-1)}delete(e){let t=this._count;if(!e)return this.clear(),t>0;let r=this._isColumn,i=this._maxCoords,a=this.getCoords(),o=Rr(e.colStart,e.rowStart,e.colEnd,e.rowEnd,r,i,a);if(!o||t===0)return!1;if(n.CoordUtils.isRangeWithinRange(a,e))return this.clear(),t>0;let s=o.majorStart,c=o.majorEnd,l=o.minorStart,u=o.minorEnd,d=r?a.colStart:a.rowStart,f=r?a.colEnd:a.rowEnd,p=r?a.rowStart:a.colStart,m=r?a.rowEnd:a.colEnd,h=!1,g=0,_=this._major;if(this._lastMajor=-(2**53-1),l<=p&&u>=m){ci.bounds.min=s,ci.bounds.max=c;let e=_.entries(ci),t=e.next();for(;!t.done;)g-=t.value[1].getCount(),t=e.next();return _.delete(s,c-s+1),this._count+=g,this._dataCoords=null,g!==0}let v=[],y=this._isShared,b=[];ci.bounds.min=s,ci.bounds.max=c,si.reverse=!1,si.processSkip=null,si.reuseResult=oi;let x=_.entries(ci),S=x.next();for(;!S.done;){let e=S.value,t=e[0],n=e[1],r=n.getCoords(),i=r.min,a=r.max;if(l<=i&&u>=i||l<=a&&u<=a)if((i===p&&l<=p||a===m&&u>=m)&&(h=!0),i>=l&&a<=u)v.push(t),g-=n.getCount();else{let e=n.getCount();y&&(n=n.clone(),b.push([t,n])),n.delete(l,u-l+1),g+=n.getCount()-e}S=x.next()}this._updateMajorSpan(b);let C=v.length;if(C>0){let e=Ot(v,!0);for(let t=0;t<e.length;t++){let n=e[t];_.delete(n.min,n.max-n.min+1)}let t=_.getCoords();if(!t)return this.clear(),!0;d=t.min,f=t.max}return h?(this._count+=g,this._dataCoords=null,!0):C===0?(this._count+=g,g!==0):(this._updateCountAndCoords(g,d,p,f,m,!0),g!==0)}shift(e,t){if(!e||!t)throw new n.NullNotAllowedError;let r=this._isColumn,i=this._maxCoords,a=t===n.Direction.Right||t===n.Direction.Down,o=t===n.Direction.Left||t===n.Direction.Right,s=Rr(e.colStart,e.rowStart,e.colEnd,e.rowEnd,r,i,e);if(!s)return!1;let c=s.majorStart,l=s.majorEnd,u=s.minorStart,d=s.minorEnd,f=this.getCoords();if(!f)return!1;let p=r?f.colStart:f.rowStart,m=r?f.colEnd:f.rowEnd,h=r?f.rowStart:f.colStart,g=r?f.rowEnd:f.colEnd,_=u<=h&&d>=g,v=r===o;if((v&&_||!v&&c<=p&&l>=m)&&!Rr(f.colStart,f.rowStart,f.colEnd+(a&&o?e.colEnd-e.colStart+1:0),f.rowEnd+(a&&!o?e.rowEnd-e.rowStart+1:0),r,i)||v&&c>m||!v&&u>g)return!1;let y=v?l-c+1:d-u+1;if(!a&&(y*=-1,n.CoordUtils.isRangeWithinRange(f,e)))return this.clear(),!0;let b=0,x=this._major,S=[];if(ci.bounds.min=c,ci.bounds.max=v?2**53-1:l,si.reverse=!a,si.processSkip=null,si.reuseResult=oi,v&&_){if(!a){ci.bounds.max=l;let e=x.entries(ci),t=e.next();for(;!t.done;)b-=t.value[1].getCount(),t=e.next()}x.shift(c,y);let e=x.getCoords();return this._dataCoords=null,this._updateCountAndCoords(b,e?.min??0,h,e?.max??0,g),!0}let C=r?f.colStart:f.rowStart,w=r?f.colEnd:f.rowEnd,T=r?f.rowStart:f.colStart,E=r?f.rowEnd:f.colEnd;a||(T=2**53-1,E=-(2**53-1));let D=2**53-1;i&&(D=o?i.colEnd:i.rowEnd);let O=new Set,k=v?new Map:null,A=[],j=x.entries(ci),M={bounds:{min:u,max:d}},N=j.next();for(;!N.done;){let e=N.value,t=e[0],r=e[1].clone(),i=r.getCoords(),a=i.min,o=i.max;if(v&&k.set(t,r),u<=o){let e=r.getCount();v?(t>=c-y&&Ft(r.runs(M),(e,n)=>{let r=n.min,i=n.max,a=e;r-1<=d&&i>d&&(a=a.slice(0,d+1-r)),r<u&&i+1>=u&&(a=a.slice(u-r)),A.push({majorIndex:t+y,minorIndex:Math.max(r,u),run:a})}),r.delete(u,d-u+1)):r.shift(u,y);let i=r.getCount();if(i===0)O.add(t),T=Math.min(T,o),E=Math.max(E,a);else{let e=r.getCoords();if(T=Math.min(T,e.min),E=Math.max(E,e.max),E>D)throw new n.OutOfBoundsError}b+=i-e,S.push([t,r])}N=j.next()}let P=this._optionsMinor,F=!1;for(let e=0;e<A.length;e++){let t=A[e],n=t.majorIndex,r=t.run,i=k.get(n);i||(i=new Tn(P),k.set(n,i),S.push([n,i]),F=!0),i.setRunAt(t.minorIndex,r),b+=r.length,C=Math.min(C,n),w=Math.max(w,n),O&&O.delete(n)}if(this._updateMajorSpan(S,F),O&&O.size>0){let e=Ot(Array.from(O.values()));for(let t=0;t<e.length;t++){let n=e[t];x.delete(n.min,n.max-n.min+1)}let t=x.getCoords();if(!t)return this.clear(),!0;C=t.min,w=t.max}if(E!==g||T!==h)return this._count+=b,this._dataCoords=null,!0;{let e=this._count+b;this._count=e,this._dataCoords=e===0?null:Object.freeze({colStart:r?C:T,rowStart:r?T:C,colEnd:r?w:E,rowEnd:r?E:w})}return b!==0||!n.CoordUtils.isEqualRanges(f,this.getCoords())}getCount(){return this._count}getValueAt(e,t){let n=this._isColumn,r=n?t:e,i=n?e:t,a=this._lastMajor,o;if(a===r&&a!==-(2**53-1)?o=this._lastMinorSpan:(o=this._major.at(r),this._lastMajor=r,this._lastMinorSpan=o),o)return o.at(i)}setValueAt(e,t,n){let r=this._isColumn,i=[r?t:e,[[r?e:t,[n]]]];this.setValues([i])}copyTo(e,t,r){if(this.getCount()===0)return;let i=this.getAxis(),a=e.getAxis(),o=this.getRuns({bounds:r}),s=o.next(),c=n.CoordUtils.cellToRange(t);c.colEnd=r.colEnd-r.colStart+t.colIndex,c.rowEnd=r.rowEnd-r.rowStart+t.rowIndex;let l=this._isColumn,u=this._maxCoords,d=this.getCoords(),f,p=Rr(r.colStart??-(2**53-1),r.rowStart??-(2**53-1),r.colEnd??2**53-1,r.rowEnd??2**53-1,l,u,d);p={...p};let m=a!==n.RangeAxis.Row,h=e.getMaxCoords()??void 0;f=Rr(c?.colStart??-(2**53-1),c?.rowStart??-(2**53-1),c?.colEnd??2**53-1,c?.rowEnd??2**53-1,m,h),f={...f};let g=l?r.colStart:r.rowStart,_=l?r.rowStart:r.colStart,v=l===m,y=v?f.majorStart:f.minorStart,b=v?f.minorStart:f.majorStart,x=y-(g??p.majorStart),S=b-(_??p.minorStart),C=i===a?new z.Builder:new z.TransposedBuilder;for(;!s.done;){let e=s.value[0],t=s.value[1],n=s.value[2];t+n.length>p.minorEnd&&(n=n.slice(0,p.minorEnd-t+1)),t<p.minorStart&&(n=n.slice(p.minorStart-t),t=p.minorStart),C.pushMultipleAt(e+x,t+S,n),s=o.next()}let w=C.build();e.delete(c),w&&e.setValues(w.tuples)}getCoords(){if(this._dataCoords)return this._dataCoords;if(this._major.getCount()===0)return null;let e=2**53-1,t=-(2**53-1),n=2**53-1,r=-(2**53-1),i=this._major.entries(),a=i.next();for(;!a.done;){let o=a.value,s=o[0];e=Math.min(s,e),t=Math.max(s,t);let c=o[1].getCoords();n=Math.min(c.min,n),r=Math.max(c.max,r),a=i.next()}let o=this._isColumn,s=Object.freeze({colStart:o?e:n,rowStart:o?n:e,colEnd:o?t:r,rowEnd:o?r:t});return this._dataCoords=s,s}clone(t){this._isShared=!0;let n=new e(this._options);return n._isShared=!0,n._major=this._major.clone(),n._dataCoords=this._dataCoords,n._count=this._count,n}cloneEmpty(t){return new e(this._options)}getMaxCoords(){return this._maxCoords||null}get[Symbol.toStringTag](){let e=``,t=this.getCoords();if(t){let n=t.colEnd-t.colStart+1,r=t.rowEnd-t.rowStart+1;e=`${this.getCount()}-${this._isColumn?n:r}x${this._isColumn?r:n}`}return`[SparseGrid:${e}]`}};ni||={};var ri=12;Object.seal({done:!1,value:null});var ii=[-1,-1,null],ai=Object.seal({done:!1,value:[-1,null]}),oi=Object.seal({done:!1,value:[-1,null]}),si={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:ai},ci={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:oi},li=()=>({majorIndex:-1,minorIndex:-1,value:null,active:!1,nextMinorIndex:-1,nextActive:!1,nextMinorValue:null,minorIterator:null,nextMajorCursor:null,prevMajorCursor:null}),ui=class e{constructor(e,t){this._grid=null,this._value=e,this._axis=t?.axis??n.RangeAxis.Row,this._maxCoords=t?.maxCoords}_materialize(){let e=this._grid;if(!e){e=new ni({axis:this._axis,maxCoords:this._maxCoords});let t=this._value;t!=null&&e.setValueAt(0,0,t),this._grid=e}return e}getValueAt(e,t){let n=this._grid;return n?n.getValueAt(e,t):e===0&&t===0?this._value:void 0}getCount(){let e=this._grid;return e?e.getCount():this._value==null?0:1}getCoords(){let e=this._grid;return e?e.getCoords():this.getCount()===0?null:{colStart:0,rowStart:0,colEnd:0,rowEnd:0}}getAxis(){return this._axis}getMaxCoords(){return this._maxCoords??null}clone(t){let n=this._grid;return n?n.clone(t):new e(this._value,{axis:this._axis,maxCoords:this._maxCoords})}cloneEmpty(e){return this._materialize().cloneEmpty(e)}setValues(e){return this._materialize().setValues(e),this}setValueAt(e,t,n){this._materialize().setValueAt(e,t,n)}getValues(e){return this._materialize().getValues(e)}entries(e){let t=this._grid;if(t)return t.entries(e);if(e?.processRowSkip||e?.processColumnSkip)return this._materialize().entries(e);let r=this._value;if(r==null)return Bt;let i=e?.bounds;if(i&&((i.colStart??0)>0||(i.rowStart??0)>0||(i.colEnd??0)<0||(i.rowEnd??0)<0))return Bt;let a=e?.axis?e.axis===n.RangeAxis.Column:this._axis===n.RangeAxis.Column,o=e?Vr(e.reuseResult):void 0,s=this,c=!1,l=null;return{next:t=>l?l.next(t):t?(l=s._materialize().entries(e),l.next(t)):c?zt:(c=!0,Br(0,0,r,a,o)),[Symbol.iterator](){return this},return:e=>null,throw:e=>null}}keys(e){return this._materialize().keys(e)}values(e){return this._materialize().values(e)}getRuns(e){return this._materialize().getRuns(e)}delete(e){return this._materialize().delete(e)}clear(){this._materialize().clear()}shift(e,t){return this._materialize().shift(e,t)}copyTo(e,t,n){this._materialize().copyTo(e,t,n)}},di=class e{constructor(e){this._mapScopeTo2Ds=new Map,this._last2DKey=void 0,this._last2DMap=void 0,this._options=e,this._options2D=e;let t=e?.updateEntryOptions?.onUpdates;t&&(this._options2D={...e},this._options2D.updateEntryOptions={...e.updateEntryOptions},this._options2D.updateEntryOptions.onUpdates=(e,n,r)=>{t(e,n,this)})}all3D(e){e||=[];let t=e.length,n=this._mapScopeTo2Ds;for(let[r,i]of n){i.all(e);let n=e.length;for(let i=t;i<n;i++){let t=e[i];t.scope||(t={...t},t.scope=r,e[i]=t)}t=n}return e}getSpatialAt(e){if(e===this._last2DKey)return this._last2DMap;let t=this._mapScopeTo2Ds.get(e);return this._last2DKey=e,this._last2DMap=t,t}getScopeEntries(){return this._mapScopeTo2Ds.entries()}getScopeKeys(){return this._mapScopeTo2Ds.keys()}getScopeValues(){return this._mapScopeTo2Ds.values()}getBoundingRange(){throw Error(fi)}isEmpty(){for(let e of this._mapScopeTo2Ds.values())if(!e.isEmpty())return!1;return!0}search(e,t=!1,r=!1,i){return e.scope,this.getSpatialAt(e.scope)?.search(e,t,r,i)??n.CommonUtils.EmptyArray}has(e){return e.scope,this.getSpatialAt(e.scope)?.has(e)??!1}shift(e){let t=this.getSpatialAt(e?.range?.scope),n=t?.shift(e),r=this;return n!==t&&(r=this.clone(),r._mapScopeTo2Ds.set(this._last2DKey,n)),r}insertNonOverlapping(e,t){return this._getOrCreate2D(e.scope)?.insertNonOverlapping(e,t),this}createCopiedEntries(e,t,r,i,a){!e.scope||t.scope;let o=e.scope,s=this.getSpatialAt(o)?.createCopiedEntries(e,t,r,i,a)??{inserts:n.CommonUtils.EmptyArray,removes:n.CommonUtils.EmptyArray},c=s.inserts,l=c?c.length:0;for(let e=0;e<l;e++){let t=c[e];t.scope||=o}let u=s.removes,d=u?u.length:0;for(let e=0;e<d;e++){let t=u[e];t.scope||=o}return s}remove(e,t){e.scope;let n=this.getSpatialAt(e.scope);return n?.remove(e,t),this._cleanupEmpty2D(this._last2DKey,n),this}removeAll(e,t){let n=e?e.length:0;if(n===0)return this;let r=new Map,i,a;for(let t=0;t<n;t++){let n=e[t],o=n.scope;o!==i&&(i=o,a=r.get(o),a||r.set(o,a=[])),a.push(n)}for(let[e,n]of r){let r=this.getSpatialAt(e);r&&(r.removeAll(n,t),this._cleanupEmpty2D(e,r))}return this}insert(e){return this._getOrCreate2D(e.scope).insert(e),this}load(e){let t=e?e.length:0;if(t===0)return this;let n=new Map,r,i;for(let a=0;a<t;a++){let t=e[a],o=t.scope;if(!o)throw Error(pi);o!==r&&(r=o,i=n.get(o),i||n.set(o,i=[])),i.push(t)}for(let[e,t]of n)this._getOrCreate2D(e).load(t);return this}delete(e){if(!e)throw Error(fi);let t=this.getSpatialAt(e?.scope);return t?.delete(e),this._cleanupEmpty2D(this._last2DKey,t),this}clone(e=null){let t=this._createClone(this._options),n=new Map;for(let[t,r]of this._mapScopeTo2Ds)n.set(t,r.clone(e));return t._mapScopeTo2Ds=n,t}_getOrCreate2D(e){if(!e)throw Error(pi);let t=this._mapScopeTo2Ds.get(e);return t||(t=new yr(this._options2D),this._mapScopeTo2Ds.set(e,t),this._last2DKey=e,this._last2DMap=t),t}_cleanupEmpty2D(e,t){t?.isEmpty()&&(this._mapScopeTo2Ds.delete(e),this._last2DKey===e&&(this._last2DKey=void 0,this._last2DMap=void 0))}_createClone(t){return new e(t)}},fi=`Not supported on SpatialMap3D`,pi=`SpatialMap3D: a valid scope key is required`,mi=[`blank`,`false`,`true`,`int32`,`float64`,`string`,`error`,`rich`],hi=n.BufferUtils.isLittleEndian,gi=n.BufferUtils.isSharedArrayBufferSupported,_i=class e{constructor(e,t=null){this._v=null;let n=e.length,r=e.width,i=e.hasTypes,a=e.defaultType,o=e.buffer,s=i?e.hasSlots:!(7>>>a&1),c=+(r===8);this._l=n,this._w=r,this._sh=c,this._lo=c!==1||hi?0:1,this._dt=a,this._m=i?e.typeMask:1<<a,this._buf=o,this._vi=new Int32Array(o,0,s?n<<c:0),this._vf=s&&c===1?new Float64Array(o,0,n):null,this._t=i?new Uint8Array(o,s?n*r:0,n):null,this._c=t,i||(this.at=bi[a])}at(e){if(!(e>>>0>=this._l))switch(this._t[e]){case 3:return this._vi[(e<<this._sh)+this._lo];case 4:return this._vf[e];case 5:return this._c.decodeString(this._vi[(e<<this._sh)+this._lo]);case 0:return null;case 2:return!0;case 1:return!1;case 6:return this._c.decodeError(this._vi[(e<<this._sh)+this._lo])}}typeAt(e){if(e>>>0>=this._l)return-1;let t=this._t;return t?t[e]:this._dt}get typeMask(){return this._m}getViews(){return this._v??=Object.freeze({types:this._t,defaultType:this._dt,ints:this._vi,doubles:this._vf,intShift:this._sh,intOffset:this._lo})}get length(){return this._l}get isIList(){return!0}fromArray(e){return new Rt.ArrayList(e)}get width(){return this._w}get isShared(){return gi&&this._buf instanceof SharedArrayBuffer}toArray(e=2**53-1){let t=Math.min(e,this._l),n=Array(t);for(let e=0;e<t;e++)n[e]=this.at(e);return n}getHandle(){return{buffer:this._buf,length:this._l,width:this._w,defaultType:this._dt,typeMask:this._m,hasTypes:this._t!==null,hasSlots:this._vi.length>0}}get[Symbol.toStringTag](){return`[MixedTypedArrayList]`}toString(){return`{${8*this._w}${this._t?``:`:${mi[this._dt]}`}${this.isShared?`:shared`:``}}:${this._l}`}static get isSharedSupported(){return gi}static fromArray(t,n=null,r){let i=r?.length??t.length,a=r?.seen??0,o=null;if(a===0){o=new Uint8Array(i);for(let e=0;e<i;e++){let r=yi(t[e],n);o[e]=r,a|=1<<r}}if(i===0&&(a=1),128&a||n===null&&96&a)return null;let s=16&a?8:4,c=+(s===8),l=c!==1||hi?0:1,u=!(a&a-1),d=u?31-Math.clz32(a):0,f=!u,p=!!(-8&a),m=p?i*s:0,h=vi(m+(f?i:0),!0===r?.shared),g=new Int32Array(h,0,p?i<<c:0),_=p&&c===1?new Float64Array(h,0,i):null;if(u)switch(d){case 3:for(let e=0;e<i;e++)g[(e<<c)+l]=t[e];break;case 4:for(let e=0;e<i;e++)_[e]=t[e];break;case 5:for(let e=0;e<i;e++)g[(e<<c)+l]=n.encodeString(t[e]);break;case 6:for(let e=0;e<i;e++)g[(e<<c)+l]=n.encodeError(t[e])}else{let e=new Uint8Array(h,m,i);o&&e.set(o);for(let r=0;r<i;r++){let i=t[r];switch(o?e[r]:e[r]=yi(i,n)){case 3:g[(r<<c)+l]=i;break;case 4:_[r]=i;break;case 5:g[(r<<c)+l]=n.encodeString(i);break;case 6:g[(r<<c)+l]=n.encodeError(i)}}}return new e({buffer:h,length:i,width:s,defaultType:d,typeMask:a,hasTypes:f,hasSlots:p},n)}static fromEncoded(t,n,r=null,i){let a=i?.length??t.length,o=i?.seen??0;if(o===0)for(let e=0;e<a;e++)o|=1<<t[e];a===0&&(o=1);let s=16&o?8:4,c=+(s===8),l=c!==1||hi?0:1,u=!(o&o-1),d=u?31-Math.clz32(o):0,f=!u,p=!!(-8&o),m=p?a*s:0,h=vi(m+(f?a:0),!0===i?.shared);if(f&&new Uint8Array(h,m,a).set(t.length===a?t:t.subarray(0,a)),p){let e=new Int32Array(h,0,a<<c);if(c===1){let r=new Float64Array(h,0,a);for(let i=0;i<a;i++)t[i]===4?r[i]=n[i]:e[(i<<1)+l]=n[i]}else for(let t=0;t<a;t++)e[t]=n[t]}return new e({buffer:h,length:a,width:s,defaultType:d,typeMask:o,hasTypes:f,hasSlots:p},r)}};(_i||={}).Type={Blank:0,False:1,True:2,Int32:3,Float64:4,String:5,Error:6,Rich:7};var vi=(e,t)=>t&&gi?new SharedArrayBuffer(e):new ArrayBuffer(e),yi=(e,t)=>typeof e==`number`?(0|e)===e?3:4:typeof e==`string`?5:e==null?0:!0===e?2:!1===e?1:typeof e==`object`&&t!==null&&t.isError(e)?6:7,bi=[function(e){return e>>>0<this._l?null:void 0},function(e){return!(e>>>0<this._l)&&void 0},function(e){return e>>>0<this._l||void 0},function(e){return e>>>0<this._l?this._vi[(e<<this._sh)+this._lo]:void 0},function(e){return e>>>0<this._l?this._vf[e]:void 0},function(e){return e>>>0<this._l?this._c.decodeString(this._vi[(e<<this._sh)+this._lo]):void 0},function(e){return e>>>0<this._l?this._c.decodeError(this._vi[(e<<this._sh)+this._lo]):void 0},function(){}];function xi(e){let t=e??n.DefaultLanguagePackService.getActive(),r=n.DefaultLanguagePackService.getPacks(e).filter(Di),i=Oi.get(t);if(i&&function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(i.packs,r))return i.merged;let a=function(e,t){if(t.length===0)return;let n={},r={},i,a,o=[],s=!1,c=!1;for(let e of t)e.functions&&(Object.assign(n,e.functions),s=!0),e.errors&&(Object.assign(r,e.errors),c=!0),e.booleans&&(i={...i??{},...e.booleans}),e.specifiers&&(a={...a??{},...e.specifiers}),e.functionHelp&&o.push(e.functionHelp);let l={tag:e};return s&&(l.functions=n),c&&(l.errors=r),i&&(l.booleans=i),a&&(l.specifiers=a),o.length===1?l.functionHelp=o[0]:o.length>1&&(l.functionHelp=()=>Promise.all(o.map(e=>e())).then(e=>{let t=e=>e&&typeof e==`object`&&`default`in e;return{default:Object.assign({},...e.map(e=>t(e)?e.default:e)),enums:Object.assign({},...e.map(e=>t(e)?e.enums:void 0))}})),l}(t,r);return Oi.set(t,{packs:r,merged:a}),a}var Si={};for(let[e,n]of Object.entries(t.FormulaError.Code))Si[n]=e;function Ci(e,t){let n=xi(t)?.booleans;return e?n?.true??`TRUE`:n?.false??`FALSE`}function wi(e,n){let r=e?.getLabel?.()??t.FormulaError.Label.Unknown,i=e?.getCode?.(),a=i===void 0?void 0:Si[i];return(a&&xi(n)?.errors?.[a])??r}function Ti(e,t){let n=e.toUpperCase();if(n===`TRUE`)return!0;if(n===`FALSE`)return!1;let r=xi(t)?.booleans;if(r){if(r.true&&n===r.true.toUpperCase())return!0;if(r.false&&n===r.false.toUpperCase())return!1}}function Ei(e,n){let r=e.toUpperCase(),i=t.FormulaError.getBuiltInByLabel(r);if(i)return i;let a=xi(n)?.errors;if(a){for(let e in a)if(a[e]?.toUpperCase()===r)return t.FormulaError.BuiltIn[e]}}function Di(e){return!!(e.functions&&Object.keys(e.functions).length>0||e.errors&&Object.keys(e.errors).length>0||e.booleans||e.specifiers||e.functionHelp)}var Oi=new Map,ki={"condition.anySelector":`Any`,"condition.error.boundsRequired":`Enter both a minimum and a maximum`,"condition.error.boundsReversed":`The maximum must be greater than or equal to the minimum`,"condition.error.dateRequired":`Enter a date`,"condition.error.formulaInvalid":`The formula is not valid`,"condition.error.formulaRequired":`Enter a formula`,"condition.error.listRequired":`Enter the list items or a range`,"condition.error.numberRequired":`Enter a number`,"condition.error.operandRequired":`Enter a value`,"condition.error.periodRequired":`Choose a time period`,"condition.error.stdDevs":`Enter a whole number of standard deviations, 0 or more`,"condition.error.textLength":`Enter a whole number of characters, 0 or more`,"condition.error.textRequired":`Enter the text to look for`,"condition.error.timeRequired":`Enter a time`,"condition.error.topNItems":`Enter a number of items from 1 to 1000`,"condition.error.topNPercent":`Enter a percent from 1 to 100`,"condition.error.wholeNumber":`Enter a whole number`,"condition.operator.after.title":`After`,"condition.operator.afterEqualTo.title":`After or On`,"condition.operator.and.desc":`Checks if all params are met`,"condition.operator.and.title":`And`,"condition.operator.average.desc":`Check if value is above or below the average`,"condition.operator.average.title":`Average`,"condition.operator.average.toString":`{dir, select, above{{eq, select, yes{Above or Equal} other{Above}}} other{{eq, select, yes{Below or Equal} other{Below}}}} Average{stdDevs, plural, =0{} one{ (# Std Dev)} other{ (# Std Devs)}}`,"condition.operator.before.title":`Before`,"condition.operator.beforeEqualTo.title":`Before or On`,"condition.operator.between.desc":`Check if value is between 2 numbers`,"condition.operator.between.title":`Between`,"condition.operator.between.toString":`Between {from} and {to}`,"condition.operator.blank.title":`Blank`,"condition.operator.color.desc":`Check if value has a specific color`,"condition.operator.color.title":`Color`,"condition.operator.equalTo.title":`Equal To`,"condition.operator.error.title":`Error`,"condition.operator.expression.desc":`Evaluates a formula expression against the value of the cell`,"condition.operator.expression.title":`Formula`,"condition.operator.greaterThan.title":`Greater Than`,"condition.operator.greaterThanEqualTo.title":`Greater Than or Equal To`,"condition.operator.icon.desc":`Check if value has a matching icon`,"condition.operator.icon.title":`Icon`,"condition.operator.inSet.dateGroups":`{title} {count, plural, one{# Date Group} other{# Date Groups}}`,"condition.operator.inSet.desc":`Check if value is in a list of items`,"condition.operator.inSet.items":`{title} {count, plural, one{# Item} other{# Items}}`,"condition.operator.inSet.title":`In`,"condition.operator.lessThan.title":`Less Than`,"condition.operator.lessThanEqualTo.title":`Less Than Or Equal To`,"condition.operator.not.desc":`Check if value does not meet a condition`,"condition.operator.not.title":`Not`,"condition.operator.not.toString":`{title} {condition}`,"condition.operator.or.desc":`Checks if any params are met`,"condition.operator.or.title":`Or`,"condition.operator.textContains.title":`Contains`,"condition.operator.textEmail.title":`Is Email`,"condition.operator.textEndsWith.title":`Ends With`,"condition.operator.textIsUrl.title":`Is URL`,"condition.operator.textStartsWith.title":`Starts With`,"condition.operator.timePeriod.desc":`Check if value falls within a time period`,"condition.operator.timePeriod.title":`Time Period`,"condition.operator.timePeriod.toString":`{title} {period}`,"condition.operator.titleWithParam":`{title} {param}`,"condition.operator.topN.desc":`Check if value is in the top or bottom N`,"condition.operator.topN.title":`Top N`,"condition.operator.topN.toString":`{edge, select, top{Top} other{Bottom}} {limit} {unit, select, percent{Percent} other{Items}}`,"condition.operator.unique.desc":`Check if value is unique`,"condition.operator.unique.title":`Unique`,"condition.selector.date.desc":`The date portion of a date time`,"condition.selector.date.title":`Date`,"condition.selector.dateTime.desc":`DateTime`,"condition.selector.dateTime.title":`Date Time`,"condition.selector.list.desc":`List`,"condition.selector.list.title":`List`,"condition.selector.logical.desc":`Logical`,"condition.selector.logical.title":`Logical`,"condition.selector.number.desc":`Number`,"condition.selector.number.title":`Number`,"condition.selector.ruleDescription":`{title} Rule`,"condition.selector.text.desc":`Text`,"condition.selector.text.title":`Text`,"condition.selector.textLength.desc":`The length of text`,"condition.selector.textLength.title":`Text Length`,"condition.selector.time.desc":`The time portion of a date time`,"condition.selector.time.title":`Time`,"condition.selector.whole.desc":`The whole portion of a number`,"condition.selector.whole.title":`Whole`,"condition.selectorWithOperator":`{selector}: {operator}`,"copy.columnCopy":`Column Copy`,"copy.columnHeaders":`Column Headers`,"copy.drawings":`Drawings`,"copy.rowCopy":`Row Copy`,"copy.rowHeaders":`Row Headers`,"error.address.invalidAddress":`Invalid cell address: {address}`,"error.address.invalidAddressCoords":`Invalid cell address: invalid coords`,"error.address.invalidArguments":`Invalid arguments.`,"error.address.invalidCell":`Invalid cell.`,"error.address.invalidRange":`Invalid range. The Range must be at a size of at least 1x1.`,"error.address.invalidRangeAddress":`Invalid address. Can not parse ''{address}'' as an address or named item.`,"error.address.invalidRangeAddressAny":`Invalid address. Can not parse as an address or named item.`,"error.address.invalidRangeCoords":`Invalid range. All points must be valid integers.`,"error.address.invalidRangeEmpty":`Invalid range.`,"error.address.invalidRangeHeader":`Invalid header range.`,"error.address.invalidRangeInverted":`Invalid range. The Range must be specified as '{ TOP_LEFT:BOTTOM_RIGHT }'.`,"error.address.invalidRangeRelative":`Invalid address. Relative ranges as not allowed: {address}`,"error.address.noAddress":`Must specify an address.`,"error.address.noRange":`Must specify a range.`,"error.address.removeDuplicatesColumn":`Invalid column ''{column}''. The column must be within the range.`,"error.address.removeDuplicatesNoData":`Can not remove duplicates. The range does not contain any data.`,"error.address.singleCellOnly":`Only a single cell is allowed.`,"error.address.singleRangeOnly":`Only a single range is allowed for this operation.`,"error.address.singleRangeOnlyAlt":`Only a single range is allowed for this operation. Use ''getRanges'' instead.`,"error.address.textToColumnsMulti":`The range must be a single column range.`,"error.address.textToColumnsOverwrite":`The destination range has data.`,"error.anchor.protected":`Unable to {description}. The item is protected.`,"error.comment.addOnSheet":`Comments are added on a sheet, not on the workbook.`,"error.comment.cellHasComment":`The cell already has a comment.`,"error.comment.replyDeleted":`The reply has been deleted.`,"error.comment.singleCell":`A comment is added to a single cell.`,"error.function.builtInName":`''{name}'' is a built-in function. Choose a different name.`,"error.hyperlink.invalidHyperlink":`Invalid hyperlink`,"error.io.encryptionUnavailable":`Password protection is not available, so this workbook cannot be saved with a password.`,"error.io.openElsewhere":`Unable to save to ''{name}'' — it is open in another workbook. Close it there first, or save under a different name.`,"error.io.passwordIncorrect":`The password is incorrect.`,"error.io.passwordRequired":`''{name}'' is password protected. A password is required to open it.`,"error.io.passwordRequiredSave":`''{name}'' is password protected. Supply the password to save it, or save it without protection.`,"error.io.passwordRequiredSaveUnnamed":`This file is password protected. Supply the password to save it, or save it without protection.`,"error.io.passwordRequiredUnnamed":`This file is password protected. A password is required to open it.`,"error.io.readFailed":`Unable to read {format} — {reason}`,"error.io.readFormatUnavailable":`Unable to open ''{format}'' — that file type is not supported.`,"error.io.writeFailed":`Unable to save the workbook — {reason}`,"error.io.writeFormatMismatch":`Unable to save ''{file}'' as ''{format}'' — its extension is for a different file type. Save a copy with a new file name instead.`,"error.io.writeFormatUnavailable":`Unable to save as ''{format}'' — that file type is not supported.`,"error.io.writeFormatUnresolved":`Unable to determine the file type to save as. Choose a file type, or use a file name with a known extension.`,"error.model.modelClosed":`Model has been closed. No further operations are allowed.`,"error.model.nameRequired":`Name is required`,"error.named.containsSpaces":`Name must not contain any spaces.`,"error.named.invalidFirstChar":`First letter must be either a letter, an underscore, or a backslash.`,"error.named.invalidInvalidCellAddress":`Name can not be an address.`,"error.named.invalidSpecialRC":`Name can not be 'r' or 'c'.`,"error.named.invalidTrailingChar":`Name must be either letters, numbers, periods or underscores.`,"error.named.nameEmpty":`Name must be a non-empty string`,"error.named.nameExists":`''{name}'' already exists.`,"error.named.nameExistsInScope":`''{name}'' already exists in ''{scope}''.`,"error.named.nameMaxLength":`Name must not exceed 255 characters.`,"error.named.nameReadonly":`Names are read-only.`,"error.named.templateRequired":`A template string must be specified.`,"error.protectedRange.noName":`Protected range must have a name.`,"error.protectedRange.uniqueName":`A protected range named ''{name}'' already exists.`,"error.sheet.addressInvalidScope":`When using addresses directly from the sheet do not include the sheet name.`,"error.sheet.arrayFixedFormula":`An array formula must be a single formula.`,"error.sheet.autofillInvalidDestination":`AutoFill destination ({destination}) must extend or shrink the source range ({template}) in a single direction.`,"error.sheet.autofillMultiple":`When filling with merged cells the amount to fill must be a multiple of the input range [{modulus}].`,"error.sheet.autofillOverlapMerge":`Unable to partially fill over merged cells.`,"error.sheet.changePartOfArray":`You can't change part of an array.`,"error.sheet.clearUnsupported":`Unsupported clear type: {type}`,"error.sheet.copyInvalidSource":`Unable to determine source.`,"error.sheet.copyMissingArgs":`Both a source and a destination are required to copy.`,"error.sheet.copyMultipleRanges":`Multiple selection ranges can not be copied.`,"error.sheet.copyNoSource":`The source has no range.`,"error.sheet.deleteOverlapping":`We can't delete cells with overlapping selections.`,"error.sheet.emptyView":`View can not be empty.`,"error.sheet.insertCopyMultipleRanges":`Only a single selection is supported when using 'Insert Copy'.`,"error.sheet.insertCutInside":`We can't paste the cut cells inside the cut area itself.`,"error.sheet.insertCutOverlap":`We can't paste here because the insert would move only part of the cut area. Line the two areas up, or paste clear of the cut area.`,"error.sheet.insertItemOob":`We can't insert cells because this would push items off the end of the worksheet.`,"error.sheet.insertItemProtected":`We can't insert items. The sheet is protected.`,"error.sheet.insertMergeThrough":`We can't insert through merges. Unmerge and try again.`,"error.sheet.insertOob":`We can't insert cells because this would push values off the end of the worksheet. These cells may appear empty but they have some formatting or formulas. Delete enough rows or columns and try again.`,"error.sheet.insertOobFreeze":`We can't insert cells because this would push the frozen panes off the end of the worksheet. Unfreeze the panes and try again.`,"error.sheet.insertOverlapping":`We can't insert cells with overlapping selections.`,"error.sheet.invalidCellType":`Invalid cell type: {type}. See documentation for information on valid built in cell types and creating custom cell types.`,"error.sheet.invalidScopedRangeAddress":`Invalid sheet address. Can not parse ''{address}'' as a sheet address or items scope to ''{scope}''. Sheet address must not include the sheet name.`,"error.sheet.invalidScopedRangeArguments":`Invalid sheet address. Can not parse arguments as a sheet address or items scope to ''{scope}''. Sheet address must not include the sheet name.`,"error.sheet.itemOverlapping":`We can't create a {type} that overlaps with another table or merge.`,"error.sheet.iteratorClosed":`IteratorContext can only be used during visit.`,"error.sheet.listenerNull":`Listener can not be null`,"error.sheet.maxValues":`Unable to return more than {max} values. To access values in a more scalable solution use ''ICellRange.forEach'' or an iterator.`,"error.sheet.mergeMultipleValues":`Merging cells would cause some values to be discarded. Use 'discardMultipleValues' option if desired.`,"error.sheet.mergeOob":`We can't merge outside of the maximum cell location.`,"error.sheet.mergeOverlapping":`Overlapping ranges can not be merged.`,"error.sheet.modelClosed":`Sheet has been closed. No further operations are allowed.`,"error.sheet.modelDelete":`Unable to delete.`,"error.sheet.noImageProvided":`An image must be provided as a string or a resource option.`,"error.sheet.oobCell":`The cell is outside of the bounds of the range.`,"error.sheet.oobRange":`The range is outside of the bounds of the sheet.`,"error.sheet.paste":`Unable to paste: {message}`,"error.sheet.pasteOob":`We can't paste outside of the sheet bounds.`,"error.sheet.previewRange":`This range is an autoFill preview and cannot be modified. Run 'autoFill' without 'preview' to apply it.`,"error.sheet.protectedField":`Unable to {description}, this sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,"error.sheet.protectedRangeLocked":`This range is protected with a password. Enter the password to make a change.`,"error.sheet.protectedSheet":`This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,"error.sheet.readonlyRange":`Readonly sheet`,"error.sheet.readonlySheet":`Unable to {description}, this sheet is readonly.`,"error.sheet.setValuesType":`'setValues' expects a 2d array; when working with a single value use 'setValue'.`,"error.sheet.setValueType":`'setValue' expects a single value; when working with an array use 'setValues'.`,"error.sheet.snapshotDone":`Unable to use a snapshot multiple times.`,"error.sheet.sortMergeSize":`Unable to sort merged cells unless they are all the same size.`,"error.sheet.table1By1":`A table must have a least two rows; one for the table header and one for data.`,"error.sheet.tableEmpty":`An autotable must have data to be created.`,"error.sheet.uniqueName":`Name must be unique: ''{name}'' is already in use.`,"error.sheet.unmergeOverlapping":`We can't unmerge intersecting ranges.`,"error.sheet.unmergePartial":`We can't unmerge partial cells.`,"error.sheet.unsupportedFloatingType":`Unsupported float type: {type}`,"error.sheetHeader.protectedColumns":`The columns are protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,"error.sheetHeader.protectedRows":`The rows are protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,"error.sort.sortOobRange":`The sort offset is outside of the bounds of the sort.`,"error.table.autoTableInvalidOperation":`That operation is not valid for an AutoTable.`,"error.table.columnValuesNotArray":`Column values must be a one-dimensional array.`,"error.table.columnValuesOverflow":`{count} values were provided but the table has only {max} rows.`,"error.table.convertToRangeLimit":`The table has {count} cells, which is more than the limit of {max}.`,"error.table.tableBodyRows":`Select rows within the table body.`,"error.table.tableNoBody":`A table must have a least one row and one column for the data.`,"error.table.tableNoName":`Table must have a name.`,"error.table.tableRemoveHeader":`We can not remove rows that contain table headers. Remove the table header.`,"error.table.tableResizeInvalidBounds":`The top of the table must not change and the new table location must overlap with the original table.`,"error.table.tableSplit":`We can not partially insert or remove cells as this would split a table.`,"error.workbook.deleteKey":`Invalid reference for delete: {key}`,"error.workbook.invalidId":`Invalid id: {id}`,"error.workbook.invalidLocale":`Invalid locale: ''{locale}''. Expected a BCP 47 tag such as ''de-DE''.`,"error.workbook.invalidSheetKey":`Invalid SheetKey: {key}`,"error.workbook.modelClosed":`Workbook has been closed. No further operations are allowed.`,"error.workbook.nameDuplicate":`The sheet name ''{sheetName}'' already exist in workbook.`,"error.workbook.nameTaken":`That name is already taken. Try a different one.`,"error.workbook.notSetValue":`A value must be provided.`,"error.workbook.noVisibleRefs":`Internal error no visible sheetRefs`,"error.workbook.protection":`This workbook structure is protected. To make a change, unprotect the workbook. You might be requested to enter a password.`,"error.workbook.sheetIndexNotFound":`No sheet found at {index}.`,"error.workbook.sheetNameBlank":`A sheet name can not be blank.`,"error.workbook.sheetNameInvalidChars":`A sheet name can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`,"error.workbook.sheetNameInvalidCharsNamed":`''{sheetName}'' can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`,"error.workbook.sheetNameNotFound":`''{sheetName}'' not found.`,"error.workbook.sheetNameNotProvided":`Sheet name not provided. If you are trying to reference the active sheet, use getSelectedSheet() instead.`,"error.workbook.sheetNameQuotes":`A sheet name can not begin or end with a "'" (single quote).`,"error.workbook.sheetNameTooLong":`A sheet name can not be longer than 31 characters.`,"error.workbook.sheetOne":`A workbook must contain at least one visible worksheet.`,"movable.copySuffix":`{name} (Copy)`,"name.dataValidation":`Data Validation`,"op.addColumns":`Add Columns`,"op.addComment":`Add Comment`,"op.addCommentReply":`Reply to Comment`,"op.addDataValidation":`Add Data Validation`,"op.addExternalBook":`Add Link to ''{name}''`,"op.addNamedFormulaNamed":`Add Named Formula ''{name}''`,"op.addProtectedRange":`Add Protected Range`,"op.addScript":`Add Script`,"op.addSheet":`Add Sheet`,"op.addSheetNamed":`Add Sheet ''{name}''`,"op.addTable":`Add Table`,"op.addTableColumn":`Add Table Column`,"op.addTableColumns":`Add Table Columns`,"op.addTableRow":`Add Table Row`,"op.addTableRows":`Add Table Rows`,"op.applyFilters":`Apply Filters`,"op.applySort":`Apply Sort`,"op.autoFill":`Auto Fill`,"op.autofit":`Autofit`,"op.autofitAll":`Autofit All`,"op.autofitColumns":`Autofit Columns`,"op.autofitRows":`Autofit Rows`,"op.breakExternalLink":`Break Link to ''{name}''`,"op.breakExternalLinks":`Break All Links`,"op.clear":`Clear`,"op.clearAll":`Clear All`,"op.clearColumnHeaders":`Clear Column Headers`,"op.clearComments":`Clear Comments`,"op.clearDataValidations":`Clear Data Validation`,"op.clearFormats":`Clear Formats`,"op.clearFormulas":`Clear Formulas`,"op.clearHyperlinks":`Clear Hyperlinks`,"op.clearNotes":`Clear Notes`,"op.clearRowHeaders":`Clear Row Headers`,"op.clearSort":`Clear Sort`,"op.clearStyle":`Clear Style`,"op.clearTables":`Clear Tables`,"op.clearValues":`Clear Values`,"op.convertToRange":`Convert to Range`,"op.copyImageFromClipboard":`Copy Image from Clipboard`,"op.copyMovable":`Copy Movable`,"op.copyNamed":`Copy {name}`,"op.createAnchoredItem":`Create Anchored Item`,"op.createItem":`Create Item`,"op.createItemNamed":`Create Item ''{name}''`,"op.cutNamed":`Cut {name}`,"op.darkerPercent":`Darker {percent}%`,"op.delete":`Delete`,"op.deleteCells":`Delete Cells`,"op.deleteColumnNamed":`Delete Column ''{name}''`,"op.deleteColumns":`Delete Columns`,"op.deleteComment":`Delete Comment`,"op.deleteCommentReply":`Delete Reply`,"op.deleteConditionalFormat":`Delete Conditional Format`,"op.deleteConditionalFormatNamed":`Delete Conditional Format ''{name}''`,"op.deleteDataValidation":`Delete Data Validation`,"op.deleteDataValidationNamed":`Delete Data Validation ''{name}''`,"op.deleteDrawing":`Delete Drawing`,"op.deleteFilter":`Delete Filter`,"op.deleteFilters":`Delete Filters`,"op.deleteModule":`Delete Module`,"op.deleteNamedItem":`Delete Named Item ''{name}''`,"op.deletePicture":`Delete Picture`,"op.deleteProtectedRange":`Delete Protected Range`,"op.deleteProtectedRangeNamed":`Delete Protected Range ''{name}''`,"op.deleteRows":`Delete Rows`,"op.deleteSheet":`Delete Sheet ''{name}''`,"op.deleteSorts":`Delete Sorts`,"op.deleteSortsAndFilters":`Delete Sorts and Filters`,"op.deleteTableColumn":`Delete Table Column`,"op.deleteTableColumns":`Delete Table Columns`,"op.deleteTableNamed":`Delete Table ''{name}''`,"op.deleteTableRow":`Delete Table Row`,"op.deleteTableRows":`Delete Table Rows`,"op.duplicateNamed":`Duplicate ''{name}''`,"op.filter":`Filter`,"op.filterColumn":`Filter {name}`,"op.filterTable":`Filter Table`,"op.hideBandedColumns":`Hide Banded Columns`,"op.hideBandedRows":`Hide Banded Rows`,"op.hideColumns":`Hide Columns`,"op.hideHeaders":`Hide Headers`,"op.hideHighlightFirstColumn":`Hide Highlight First Column`,"op.hideHighlightLastColumn":`Hide Highlight Last Column`,"op.hideRows":`Hide Rows`,"op.hideSheet":`Hide Sheet`,"op.hideTotals":`Hide Totals`,"op.initialize":`Initialize`,"op.initializeComment":`Initialize Comment`,"op.initializeConditionalFormat":`Initialize Conditional Format`,"op.initializeDataValidation":`Initialize Data Validation`,"op.initializeProtectedRange":`Initialize Protected Range`,"op.initializeTable":`Initialize Table`,"op.insertAutoTable":`Insert AutoTable`,"op.insertCells":`Insert Cells`,"op.insertColumns":`Insert Columns`,"op.insertConditionalFormat":`Insert Conditional Format`,"op.insertCopiedCells":`Insert Copied Cells`,"op.insertDataValidation":`Insert Data Validation`,"op.insertDrawing":`Insert Drawing`,"op.insertImage":`Insert Image`,"op.insertProtectedRange":`Insert Protected Range`,"op.insertRows":`Insert Rows`,"op.insertTable":`Insert Table`,"op.lighterPercent":`Lighter {percent}%`,"op.loadMovable":`Load Movable`,"op.loadSheet":`Load Sheet`,"op.merge":`Merge`,"op.moveBackwards":`Move Backwards`,"op.moveForward":`Move Forward`,"op.moveSheetNamed":`Move Sheet ''{name}''`,"op.moveToBack":`Move to Back`,"op.moveToFront":`Move to Front`,"op.newSheet":`New Sheet`,"op.newWorkbook":`New Workbook`,"op.openWorkbook":`Open Workbook`,"op.paste":`Paste`,"op.pasteNamed":`Paste {name}`,"op.range":`Range`,"op.rangesUpdate":`Ranges Update`,"op.rangeUpdate":`Range Update`,"op.refreshExternalLink":`Refresh Link to ''{name}''`,"op.refreshSortsAndFilters":`Refresh Sorts and Filters`,"op.removeDuplicates":`Remove Duplicates`,"op.removeExternalBook":`Remove Link to ''{name}''`,"op.removeNamedFormula":`Remove Named Formula`,"op.removePicture":`Remove Picture`,"op.removeScript":`Remove Script`,"op.renameSheet":`Rename Sheet`,"op.reopenComment":`Reopen Comment`,"op.reorderConditionalFormat":`Reorder Conditional Format`,"op.reorderDataValidations":`Reorder Data Validations`,"op.reorderProtectedRange":`Reorder Protected Range`,"op.replace":`Replace`,"op.replaceAll":`Replace All`,"op.replaceAllWith":`Replace All with ''{value}''`,"op.replaceAt":`Replace {address}`,"op.replaceAtWith":`Replace {address} with ''{value}''`,"op.replaceWith":`Replace with ''{value}''`,"op.resizeColumns":`Resize Columns`,"op.resizeRows":`Resize Rows`,"op.resizeTable":`Resize Table`,"op.resolveComment":`Resolve Comment`,"op.saveScripts":`Save Scripts`,"op.setAlertMessage":`Set Alert Message`,"op.setAlertStyle":`Set Alert Style`,"op.setAlertTitle":`Set Alert Title`,"op.setAlignment":`Set Alignment`,"op.setAlwaysUnlocked":`Set Always Unlocked`,"op.setAngle":`Set Angle`,"op.setAutoExpand":`Set Auto Expand`,"op.setBackgroundColor":`Set Background Color`,"op.setBorders":`Set Borders`,"op.setBottomBorder":`Set Bottom Border`,"op.setBottomBorderColor":`Set Bottom Border Color`,"op.setBottomBorderStyle":`Set Bottom Border Style`,"op.setCellAddress":`Set Cell {address}`,"op.setColumnName":`Set Column Name`,"op.setComment":`Set Comment`,"op.setCommentContent":`Edit Comment`,"op.setComments":`Set Comments`,"op.setComputedValues":`Set Computed Values`,"op.setCondition":`Set Condition`,"op.setDiagonalDownBorder":`Set Diagonal Down Border`,"op.setDiagonalDownBorderColor":`Set Diagonal Down Border Color`,"op.setDiagonalDownBorderStyle":`Set Diagonal Down Border Style`,"op.setDiagonalUpBorder":`Set Diagonal Up Border`,"op.setDiagonalUpBorderColor":`Set Diagonal Up Border Color`,"op.setDiagonalUpBorderStyle":`Set Diagonal Up Border Style`,"op.setDisabledColumnFill":`Set Disabled Column Fill`,"op.setEntireSize":`Set Entire Size`,"op.setFill":`Set Fill`,"op.setFillColor":`Set Fill Color`,"op.setFillGradient":`Set Fill Gradient`,"op.setFillNone":`Set Fill None`,"op.setFillPattern":`Set Fill Pattern`,"op.setFillSolid":`Set Fill Solid`,"op.setFocus":`Set Focus`,"op.setFont":`Set Font`,"op.setFontBold":`Set Font Bold`,"op.setFontCharset":`Set Font Charset`,"op.setFontColor":`Set Font Color`,"op.setFontExtend":`Set Font Extend`,"op.setFontFallbacks":`Set Font Fallbacks`,"op.setFontFamily":`Set Font Family`,"op.setFontItalic":`Set Font Italic`,"op.setFontLetterSpacing":`Set Font Letter Spacing`,"op.setFontOutline":`Set Font Outline`,"op.setFontScheme":`Set Font Scheme`,"op.setFontShadow":`Set Font Shadow`,"op.setFontSize":`Set Font Size`,"op.setFontStrike":`Set Font Strike`,"op.setFontStyle":`Set Font Style`,"op.setFontUnderline":`Set Font Underline`,"op.setFontVerticalAlignment":`Set Font Vertical Alignment`,"op.setFontWeight":`Set Font Weight`,"op.setForegroundColor":`Set Foreground Color`,"op.setFormulaBelow":`Set Formula Below`,"op.setGradientType":`Set Gradient Type`,"op.setHidden":`Set Hidden`,"op.setHiddenButtons":`Set Hidden Buttons`,"op.setHideDropdown":`Set Hide Dropdown`,"op.setHorizontalAlignment":`Set Horizontal Alignment`,"op.setHorizontalBorder":`Set Horizontal Border`,"op.setHorizontalBorderColor":`Set Horizontal Border Color`,"op.setHorizontalBorderStyle":`Set Horizontal Border Style`,"op.setHyperlink":`Set Hyperlink`,"op.setIncludeBlanks":`Set Include Blanks`,"op.setIndent":`Set Indent`,"op.setIndex":`Set Index`,"op.setJustifyLastLine":`Set Justify Last Line`,"op.setLeftBorder":`Set Left Border`,"op.setLeftBorderColor":`Set Left Border Color`,"op.setLeftBorderStyle":`Set Left Border Style`,"op.setLockAspectRatio":`Set Lock Aspect Ratio`,"op.setMovableBounds":`Set Movable Bounds`,"op.setMovableDescription":`Set Movable Description`,"op.setMovableName":`Set Movable Name`,"op.setMovableResizeBehavior":`Set Movable Resize Behavior`,"op.setMovableRotation":`Set Movable Rotation`,"op.setMovableVisibility":`Set Movable Visibility`,"op.setName":`Set Name`,"op.setNamedStyle":`Set Named Style`,"op.setNumberFormat":`Set Number Format`,"op.setOutlineBorder":`Set Outline Border`,"op.setOverflow":`Set Overflow`,"op.setPatternType":`Set Pattern Type`,"op.setPicture":`Set Picture`,"op.setPromptMessage":`Set Prompt Message`,"op.setPromptTitle":`Set Prompt Title`,"op.setProtectedRangeName":`Set Protected Range Name`,"op.setProtectedRangePassword":`Set Protected Range Password`,"op.setProtectedRangePermissions":`Set Protected Range Permissions`,"op.setProtection":`Set Protection`,"op.setQuotePrefix":`Set Quote Prefix`,"op.setRangeAddress":`Set Range {address}`,"op.setRanges":`Set Ranges`,"op.setReadingDirection":`Set Reading Direction`,"op.setRelativeIndent":`Set Relative Indent`,"op.setRightBorder":`Set Right Border`,"op.setRightBorderColor":`Set Right Border Color`,"op.setRightBorderStyle":`Set Right Border Style`,"op.setRotation":`Set Rotation`,"op.setShowErrorMessage":`Set Show Error Message`,"op.setShowFormulas":`Set Show Formulas`,"op.setShowPromptMessage":`Set Show Prompt Message`,"op.setStacked":`Set Stacked`,"op.setStopFalse":`Clear Stop If True`,"op.setStops":`Set Stops`,"op.setStopTrue":`Set Stop If True`,"op.setTableDescription":`Set Table Description`,"op.setTableName":`Set Table Name`,"op.setTableNameNamed":`Set Table Name ''{name}''`,"op.setTopBorder":`Set Top Border`,"op.setTopBorderColor":`Set Top Border Color`,"op.setTopBorderStyle":`Set Top Border Style`,"op.setTotalsRowFormula":`Set Totals Row Formula`,"op.setTotalsRowLabel":`Set Totals Row Label`,"op.setValue":`Set Value`,"op.setValueAddress":`Set Value {address}`,"op.setValuesAddress":`Set Values {address}`,"op.setVerticalAlignment":`Set Vertical Alignment`,"op.setVerticalBorder":`Set Vertical Border`,"op.setVerticalBorderColor":`Set Vertical Border Color`,"op.setVerticalBorderStyle":`Set Vertical Border Style`,"op.shiftingMovableBounds":`Shifting Movable Bounds`,"op.showBandedColumns":`Show Banded Columns`,"op.showBandedRows":`Show Banded Rows`,"op.showHeaders":`Show Headers`,"op.showHighlightFirstColumn":`Show Highlight First Column`,"op.showHighlightLastColumn":`Show Highlight Last Column`,"op.showTotals":`Show Totals`,"op.sortAscending":`Sort Ascending`,"op.sortColumn":`Sort {name}`,"op.sortDescending":`Sort Descending`,"op.sortTable":`Sort Table`,"op.syncColumnsFromSheet":`Sync Columns From Sheet`,"op.syncColumnsToSheet":`Sync Columns To Sheet`,"op.tableAutoExpansion":`Table Auto Expansion`,"op.tableColumnFill":`Fill`,"op.textToColumns":`Text to Columns`,"op.unhideColumns":`Unhide Columns`,"op.unhideRows":`Unhide Rows`,"op.unhideSheet":`Unhide Sheet`,"op.unmerge":`Unmerge`,"op.update":`Update`,"op.updateAnchor":`Update Anchor`,"op.updateCalculations":`Update Calculations`,"op.updateCells":`Update Cells`,"op.updateColumnNamed":`Update Column ''{name}''`,"op.updateColumns":`Update Columns`,"op.updateColumnsFromSheet":`Update Columns From Sheet`,"op.updateColumnsRange":`Update Columns {range}`,"op.updateComment":`Update Comment`,"op.updateConditionalFormat":`Update Conditional Format`,"op.updateConditionalFormatListener":`Update Conditional Format Listener`,"op.updateDataValidation":`Update Data Validation`,"op.updateDataValidationListener":`Update Data Validation Listener`,"op.updateDataValidations":`Update Data Validations`,"op.updateDrawing":`Update Drawing`,"op.updateFormulaAt":`Update Formula at {address}`,"op.updateHeader":`Update Header`,"op.updateListener":`Update Listener`,"op.updateMovableBounds":`Update Movable Bounds`,"op.updateMovables":`Update Movables`,"op.updateNamed":`Update Named ''{name}''`,"op.updateProtectedRange":`Update Protected Range`,"op.updateProtectedRanges":`Update Protected Ranges`,"op.updateReferenceStyle":`Update Reference Style`,"op.updateReferenceStyleAt":`Update Reference Style at {address}`,"op.updateRows":`Update Rows`,"op.updateRowsRange":`Update Rows {range}`,"op.updateSheet":`Update Sheet`,"op.updateStyle":`Update Style`,"op.updateStyleInfo":`Update Style Info`,"op.updateWorkbook":`Update Workbook`,"op.updatingMovableBounds":`Updating Movable Bounds`,"op.veryHideSheet":`Very Hide Sheet`,"style.builtin.accent":`Accent{n}`,"style.builtin.accentTint":`{pct}% - Accent{n}`,"style.builtin.bad":`Bad`,"style.builtin.calculation":`Calculation`,"style.builtin.checkCell":`Check Cell`,"style.builtin.comma":`Comma`,"style.builtin.comma0":`Comma [0]`,"style.builtin.currency":`Currency`,"style.builtin.currency0":`Currency [0]`,"style.builtin.explanatoryText":`Explanatory Text`,"style.builtin.followedHyperlink":`Followed Hyperlink`,"style.builtin.good":`Good`,"style.builtin.heading":`Heading {n}`,"style.builtin.hyperlink":`Hyperlink`,"style.builtin.input":`Input`,"style.builtin.linkedCell":`Linked Cell`,"style.builtin.neutral":`Neutral`,"style.builtin.normal":`Normal`,"style.builtin.note":`Note`,"style.builtin.output":`Output`,"style.builtin.percent":`Percent`,"style.builtin.title":`Title`,"style.builtin.total":`Total`,"style.builtin.warningText":`Warning Text`,"table.autoTableDescription":`AutoTable created for filtering and sorting`,"table.autoTableName":`AutoTable`,"table.defaultName":`Table{n}`,"table.emptyColumnName":`Column`,"table.totalsRowLabel":`Total`,"workbook.defaultName":`Workbook`,"workbook.defaultSheetName":`Sheet{n}`};function Ai(){return(0,n.registerPackageMessages)(`@sheetxl/sdk`,{}.url,ki)}var ji=(e,t,n,r=null)=>{let i=t||11*B.getDeviceScale(),a=r?.letterSpacing||0,o=e.length,s=.68*i*o-(e.match(/[il.,;!|]/g)||[]).length*i*.15+(e.match(/[mwMW]/g)||[]).length*i*.1+(o>0?(o-1)*a:0),c=Math.ceil(.8*i),l=Math.ceil(1.2*i)-c,u=c+l+2,d=Math.floor((u-(c+l))/2)+c,f=Math.ceil(.2*i),p=Math.ceil(.45*i),m=Math.ceil(1.1*i),h=Math.max(1,Math.ceil(.08*i));return{width:s,lineHeight:u,baseline:d,ascent:c,descent:l,lineGap:f,strikePosition:p,underlinePosition:m,strikeThickness:h,underlineThickness:h,actualBoundingBoxLeft:0,actualBoundingBoxRight:s,actualBoundingBoxAscent:c,actualBoundingBoxDescent:l,fontBoundingBoxAscent:c,fontBoundingBoxDescent:l,emHeightAscent:c,emHeightDescent:l,hangingBaseline:.8*d,alphabeticBaseline:d,ideographicBaseline:u}},Mi=e.n({CanvasFontMeasurer:()=>Ui,getDeviceScale:()=>Ki,getInstance:()=>Gi}),Ni={},Pi=` `,Fi=`px `,Ii=(e,t)=>{let n=`normal`;return e&&t?n=`bold italic`:e?n=`bold`:t&&(n=`italic`),n},Li=e=>e.split(`,`).map(e=>{let t=(e=e.trim()).indexOf(` `)>=0,n=e.indexOf(`"`)>=0||e.indexOf(`'`)>=0;return t&&!n&&(e=`"${e}"`),e}).join(`, `),Ri=new Map,zi=new Map,Bi=.6,Vi=null,Hi=(e,t,n,r,i,a)=>e+Math.round(100*t)/100+n+r+i+a;function Ui(e,t,r,i=null){let a=i?.letterSpacing||0;typeof window>`u`||Ni.contextMeasure||(Ni.canvasMeasure=document?document.createElement(`canvas`):null,Ni.contextMeasure=Ni.canvasMeasure.getContext(`2d`),Ni.contextMeasure.letterSpacing=`${a}px`,Ni.contextMeasure.textRendering=`geometricPrecision`,Ni.contextMeasure.textBaseline=`alphabetic`,Ni.contextMeasure.textAlign=`left`);let o=r||`calibri`,s=t||11*B.getDeviceScale(),c=i?.isBold||!1,l=i?.isItalic||!1,u=null;if(e===`#`||e===`0`||e===`M`||e===``||e===`_`||e===`-`){u=Hi(e,s,o,c,l,a);let t=Ri.get(u);if(t)return t}if(Vi&&Vi.text===e&&Vi.size===t&&Vi.family===r&&Vi.options?.isBold===i?.isBold&&Vi.options?.isItalic===i?.isItalic&&Vi.options?.letterSpacing===i?.letterSpacing)return Vi.metrics;let d={},f=Ii(c,l)+Pi+n.CommonUtils.roundAccurately(s,2)+Fi+Li(o);Ni.contextMeasure?(Ni.contextMeasure.font=f,Ni.contextMeasure.letterSpacing=`${i?.letterSpacing??0}px`,d=Ni.contextMeasure.measureText(e)):d.width=e.length*n.CommonUtils.roundAccurately(Bi*(s/B.getDeviceScale()),2);let p=zi.get(f);if(!p&&typeof window<`u`){let e=document.createElement(`div`);e.style.visibility=`hidden`,e.style.position=`absolute`;let t=document.createElement(`span`);t.textContent=`Mj`,t.style.fontSize=`100px`,t.style.fontWeight=i?.isBold?`bold`:`normal`,t.style.fontStyle=i?.isItalic?`italic`:`normal`,t.style.fontFamily=`'${o}'`,t.style.lineHeight=`1.2`,e.appendChild(t),document.body.appendChild(e);let r=e.getBoundingClientRect(),a=t.getBoundingClientRect();document.body.removeChild(e),Ni.contextMeasure.font=Ii(c,l)+Pi+n.CommonUtils.roundAccurately(100,2)+Fi+Li(o);let u=Ni.contextMeasure.measureText(`M`),d=r.bottom-r.top;u.fontBoundingBoxAscent,u.fontBoundingBoxDescent;let m=u.fontBoundingBoxAscent+a.top,h=Ni.contextMeasure.measureText(`_`),g=m-h.actualBoundingBoxAscent,_=Math.max(1,Math.abs(h.actualBoundingBoxAscent+h.actualBoundingBoxDescent)),v=Ni.contextMeasure.measureText(`-`),y=n.CommonUtils.roundAccurately(m-v.actualBoundingBoxAscent+Math.max(1,.05*d,0)),b=_,x=s/100;Ni.contextMeasure.font=f;let S=Ni.contextMeasure.measureText(`M`),C=Math.round(S.fontBoundingBoxAscent??u.fontBoundingBoxAscent*x),w=Math.round(S.fontBoundingBoxDescent??u.fontBoundingBoxDescent*x),T=C+w+2,E=Math.floor((T-(C+w))/2)+C;p={lineHeight:T,baseline:E,ascent:C,descent:w,lineGap:2,strikePosition:Math.ceil(E+(y-m)*x),underlinePosition:Math.ceil(E+(g-m)*x),strikeThickness:Math.ceil(b*x),underlineThickness:Math.ceil(_*x)},Ni.contextMeasure.font=f,zi.set(f,p)}if(!p){let e=Math.round(.93*s),t=Math.round(.25*s),n=e+t+2;p={lineHeight:n,baseline:Math.floor((n-(e+t))/2)+e,ascent:e,descent:t,lineGap:2,strikePosition:Math.ceil(.55*s)+Math.floor(.1*s),strikeThickness:1,underlinePosition:Math.ceil(1.1*s),underlineThickness:1},zi.set(f,p)}let m={...d,width:d.width,...p};return u!==null&&Ri.set(u,m),Vi={text:e,size:t,family:r,options:i,metrics:m},m}var Wi=null;function Gi(){if(Wi)return Wi;try{let e=document.createElement(`canvas`),t=e.getContext&&e.getContext(`2d`);t&&typeof t.fillText==`function`&&(Wi=Ui)}catch{}return Wi||=(console.warn(`⚠️ CanvasFontMeasurer not available, falling back to SimpleFontMeasurer`),ji),Wi}function Ki(){return 96/72*1}var B,qi,V,Ji,Yi=null,Xi=Mi;(qi=B||={}).Style={Normal:`normal`,Italic:`italic`},qi.Scheme={Major:`major`,Minor:`minor`,None:`none`},qi.Charset={Ansi:0,Default:1,Symbol:2,Mac:77,ShiftJIS:128,Hangul:129,Johab:130,GB2312:134,ChineseBig5:136,Greek:161,Turkish:162,Vietnamese:163,Hebrew:177,Arabic:178,Baltic:186,Russian:204,Thai:222,EastEurope:238,Oem:255},qi.UnderlineStyle={None:`none`,Double:`double`,DoubleAccounting:`doubleAccounting`,Single:`single`,SingleAccounting:`singleAccounting`},qi.VerticalAlignment={Baseline:`baseline`,Sub:`sub`,Super:`super`},qi.setSharedMeasurer=function(e){Yi=e},qi.getSharedMeasurer=function(){return Yi||=Xi.getInstance()},qi.getDeviceScale=function(){return Xi.getDeviceScale()},qi.getPanoseFallback=function(e){let t=[],n=e.length;for(let r=0;r<n;r+=2)t.push(parseInt(e.substring(r,r+2),16));let r=t[0],i=t[1],a=t[3];switch(r){case 2:return a===9?`monospace`:i>=2&&i<=8?`serif`:`sans-serif`;case 3:return`cursive`;case 4:return`fantasy`;case 5:return`monospace`;default:return`sans-serif`}},qi.GenericName={Serif:`serif`,SanSerif:`sans-serif`,MonoSpace:`monospace`,Cursive:`cursive`,Fantasy:`fantasy`,SystemUI:`system-ui`,UISystem:`ui-system`,UISerif:`ui-serif`,UISanSerif:`ui-sans-serif`,UIMonoSpace:`ui-monospace`,UIRounded:`ui-rounded`,Math:`math`,Emoji:`emoji`,Fangsong:`fangsong`},(Ji=V||={}).StrokeStyle={None:`none`,DashDot:`dashDot`,MediumDashDot:`mediumDashDot`,Dotted:`dotted`,Hair:`hair`,Thin:`thin`,Medium:`medium`,Thick:`thick`,MediumDashDotDot:`mediumDashDotDot`,DashDotDot:`dashDotDot`,Dashed:`dashed`,MediumDashed:`mediumDashed`,SlantDashDot:`slantDashDot`,Double:`double`},Ji.Edge={Left:`left`,Top:`top`,Right:`right`,Bottom:`bottom`,Horizontal:`horizontal`,Vertical:`vertical`,DiagonalUp:`diagonalUp`,DiagonalDown:`diagonalDown`};var Zi,Qi=[],$i=new Map,ea=Object.freeze([[V.StrokeStyle.Thin,`Thin`,1,null],[V.StrokeStyle.Hair,`Hair`,1,[1,1]],[V.StrokeStyle.Dotted,`Dotted`,1,[2,2]],[V.StrokeStyle.Dashed,`Dashed`,1,[3,1]],[V.StrokeStyle.DashDot,`Dash Dot`,1,[3,3,9,3]],[V.StrokeStyle.DashDotDot,`Dash Dot Dot`,1,[3,3,3,3,9,3]],[V.StrokeStyle.Double,`Double`,3,null],[V.StrokeStyle.Medium,`Medium`,2,null],[V.StrokeStyle.MediumDashed,`Medium Dashed`,2,[9,3]],[V.StrokeStyle.MediumDashDot,`Medium Dash Dot`,2,[3,3,9,3]],[V.StrokeStyle.MediumDashDotDot,`Medium Dash Dot Dot`,2,[3,3,3,3,9,3]],[V.StrokeStyle.SlantDashDot,`Slant Dash Dot`,2,[5,1,11,1]],[V.StrokeStyle.Thick,`Thick`,3,null],[V.StrokeStyle.None,`None`,0,null]]);for(let e=0;e<ea.length;e++){let t=ea[e],n=t[0],r=Object.freeze({style:n,description:t[1],width:t[2],pattern:t[3]});Qi.push(r),$i.set(n,r)}(Zi=V||={}).isEqualStrokes=function(e,t){return!(e&&!t||t&&!e)&&(e===t||e.getStyle()===t.getStyle()&&e.getColor().isEqual(t.getColor()))},Zi.oppositeEdge=function(e){return e===V.Edge.Left?V.Edge.Right:e===V.Edge.Right?V.Edge.Left:e===V.Edge.Top?V.Edge.Bottom:e===V.Edge.Bottom?V.Edge.Top:e},Zi.BuiltInDefinitionsArray=Qi,Zi.BuiltInDefinitions=$i;var ta=Object.freeze({ß:`ss`,ẞ:`SS`,æ:`ae`,Æ:`AE`,œ:`oe`,Œ:`OE`,þ:`th`,Þ:`TH`,ij:`ij`,IJ:`IJ`,ff:`ff`,fi:`fi`,fl:`fl`,ffi:`ffi`,ffl:`ffl`,st:`st`,LJ:`LJ`,Lj:`Lj`,lj:`lj`,NJ:`NJ`,Nj:`Nj`,nj:`nj`,DZ:`DZ`,Dz:`Dz`,dz:`dz`,ȸ:`db`}),na=/[ßẞæÆœŒþÞijIJff-fflstLJ-njDZ-dzȸ]/g;function ra(e,t=!0){let n=e.replace(na,e=>ta[e]);return t?n.toLowerCase():n}function ia(e){return ra(e.normalize(`NFC`),!0)}function aa(e){return e.toLowerCase()}var oa,sa={Options:Object.freeze({sensitivity:`variant`,numeric:!1,ignorePunctuation:!1}),isCaseInsensitive:e=>{let t=e?.sensitivity;return t===void 0||t===`accent`||t===`base`},collator:e=>{let t=ca.get(e);return t||(t=new Intl.Collator(e.tag,sa.Options),ca.set(e,t)),t},collatorFor:(e,t)=>{let n=`${e}|${t?.numeric??``}|${t?.caseFirst??``}|${t?.ignorePunctuation??``}`,r=la.get(n);return r||(r=new Intl.Collator(e,{...sa.Options,...t,sensitivity:`variant`}),la.set(n,r)),r},compareTextWith:(e,t,n,r=!0)=>{if(e===t)return 0;let i=ra(e,r),a=ra(t,r),o=da(i),s=da(a);if(o===i&&s===a)return fa(i,a,n);let c=fa(o,s,n);return c===0?Sa(i,a,n):c},compare:(e,t,n,r)=>{if(e==null){if(t==null)return 0;e=wa(t)}else t??=wa(e);let i=Ca(e),a=Ca(t);if(i!==a)return i<a?-1:1;switch(i){case 0:return Ta(e,t);case 1:return sa.compareTextWith(e,t,r?sa.collatorFor(n.tag,r):sa.collator(n),sa.isCaseInsensitive(r));case 2:return e===t?0:e?1:-1;case 3:{let n=e.getCode(),r=t.getCode();return n===r?0:n<r?-1:1}default:return 0}}},ca=new WeakMap,la=new Map,ua=new Map([[39,1],[65287,2],[45,3],[65123,3],[65293,5],[8722,6],[8208,7],[8209,8],[8210,9],[8211,10],[8212,11],[65112,11],[8213,13],[700,14]]),da=e=>{let t=e.length,n=0;for(;n<t&&!ua.has(e.charCodeAt(n));)n++;if(n===t)return e;let r=e.slice(0,n);for(;n<t;n++)ua.has(e.charCodeAt(n))||(r+=e[n]);return r},fa=(e,t,n)=>{let r=e.length<t.length?e.length:t.length,i=0;for(;i<r&&e.charCodeAt(i)===t.charCodeAt(i);)i++;if(i===r)return n.compare(e,t);let a=e.codePointAt(i),o=t.codePointAt(i);if(ba(a)||ba(o))return n.compare(e,t);let s=ga(a),c=ga(o);return s===c?s===2?n.compare(e,t):a<o?-1:1:s<c?-1:1},pa=new Set([43,60,61,62]),ma=/[\p{P}\p{S}\p{Z}]/u,ha=/\p{Cf}/u,ga=e=>{if(e<128){let t=va[e];return t===void 0&&(t=va[e]=_a(e)),t}let t=ya.get(e);return t===void 0&&(t=_a(e),ya.set(e,t)),t},_a=e=>pa.has(e)?1:ma.test(String.fromCodePoint(e))?0:2,va=Array(128),ya=new Map,ba=e=>{let t=xa.get(e);return t===void 0&&(t=e>=128&&ha.test(String.fromCodePoint(e)),xa.set(e,t)),t},xa=new Map,Sa=(e,t,n)=>{let r=0,i=0;for(;r<e.length&&i<t.length;){let n=e.charCodeAt(r),a=t.charCodeAt(i),o=ua.get(n),s=ua.get(a);if(o===void 0!=(s===void 0))return o===void 0?-1:1;if(o!==void 0&&o!==s)return o<s?-1:1;r++,i++}return r<e.length?1:i<t.length?-1:0},Ca=e=>{switch(typeof e){case`number`:return 0;case`string`:return 1;case`boolean`:return 2;default:return t.FormulaError.isError(e)?3:4}},wa=e=>{switch(typeof e){case`string`:return``;case`boolean`:return!1;default:return 0}},Ta=(e,t)=>{if(e===t)return 0;if(!Number.isFinite(e)||!Number.isFinite(t))return e<t?-1:+(e>t);let n=e-t;if(Math.abs(n)>1e-14*Math.max(Math.abs(e),Math.abs(t)))return n<0?-1:1;let r=Ea(e),i=Ea(t);return r===i?0:r<i?-1:1},Ea=e=>Number(e.toPrecision(15));(function(e){e.CaseInsensitiveOptions={sensitivity:`accent`},e.CaseSensitiveOptions={sensitivity:`variant`};let n=e.NumberCollator=Object.freeze({type:t.ScalarType.Number,compare:(e,t,n)=>e===t?0:e<t?-1:1}),r=e.StringCollator=Object.freeze({type:t.ScalarType.String,compare:(e,t,n)=>sa.compareTextWith(e,t,sa.collatorFor(n?.locale??`en`,n),sa.isCaseInsensitive(n)),defaultOptions:oa.CaseInsensitiveOptions}),i=e.ErrorCollator=Object.freeze({type:t.ScalarType.Error,compare:(e,t,n)=>e.getCode()-t.getCode()}),a=e.NullCollator=Object.freeze({type:t.ScalarType.Null,compare:(e,t,n)=>0}),o=e.RichDataCollator=Object.freeze({type:t.ScalarType.RichData,compare:(e,t,n)=>e.getType().localeCompare(t.getType(),n?.locale??`en`)}),s=e.BooleanCollator=Object.freeze({type:t.ScalarType.Boolean,compare:(e,t,n)=>e===t?0:e?1:-1});e.DefaultRangeOptions=Object.freeze({hasHeader:!1,reverse:!1,includeHidden:!1,collatorOptions:oa.CaseInsensitiveOptions,axis:t.IRange.Axis.Row}),e.DefaultCollators=Object.freeze([n,r,s,o,i,a])})(oa||={});var Da={General:`General`,Number:`Number`,Currency:`Currency`,Accounting:`Accounting`,ShortDate:`Short Date`,LongDate:`Long Date`,MediumDate:`Medium Date`,ShortTime:`Short Time`,MediumTime:`Medium Time`,LongTime:`Long Time`,Comma:`Comma`,Percentage:`Percentage`,Fraction:`Fraction`,Scientific:`Scientific`,Text:`Text`,Special:`Special`,Custom:`Custom`},Oa=`general`,ka=`hash`,Aa=`zero`,ja=`qmark`,Ma=`slash`,Na=`group`,Pa=`scale`,Fa=`comma`,Ia=`break`,La=`text`,Ra=`plus`,za=`minus`,Ba=`point`,Va=`space`,Ha=`percent`,Ua=`digit`,Wa=`calendar`,Ga=`error`,Ka=`datetime`,qa=`duration`,Ja=`condition`,Ya=`dbnum`,Xa=`natnum`,Za=`locale`,Qa=`color`,$a=`modifier`,eo=`ampm`,to=`escaped`,no=`string`,ro=`skip`,io=`fill`,ao=`paren`,oo=`char`,so=`#000000.#FFFFFF.#FF0000.#00FF00.#0000FF.#FFFF00.#FF00FF.#00FFFF.#800000.#008000.#000080.#808000.#800080.#008080.#C0C0C0.#808080.#9999FF.#993366.#FFFFCC.#CCFFFF.#660066.#FF8080.#0066CC.#CCCCFF.#000080.#FF00FF.#FFFF00.#00FFFF.#800080.#800000.#008080.#0000FF.#00CCFF.#CCFFFF.#CCFFCC.#FFFF99.#99CCFF.#FF99CC.#CC99FF.#FFCC99.#3366FF.#33CCCC.#99CC00.#FFCC00.#FF9900.#FF6600.#666699.#969696.#003366.#339966.#003300.#333300.#993300.#993366.#333399.#333333`.split(`.`),co=`¤.$.£.¥.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿`.split(`.`),lo=RegExp(`[`+co.join(``)+`]`),uo=Object.freeze({1078:`af`,1052:`sq`,1118:`am`,5121:`ar_DZ`,15361:`ar_BH`,3073:`ar_EG`,2049:`ar_IQ`,11265:`ar_JO`,13313:`ar_KW`,12289:`ar_LB`,4097:`ar_LY`,6145:`ar_MA`,8193:`ar_OM`,16385:`ar_QA`,1025:`ar_SA`,10241:`ar_SY`,7169:`ar_TN`,14337:`ar_AE`,9217:`ar_YE`,1067:`hy`,1101:`as`,2092:`az_AZ`,1068:`az_AZ`,1069:`eu`,1059:`be`,2117:`bn`,1093:`bn_IN`,5146:`bs`,1026:`bg`,1109:`my`,1027:`ca`,2052:`zh_CN`,3076:`zh_HK`,5124:`zh_MO`,4100:`zh_SG`,1028:`zh_TW`,1050:`hr`,1029:`cs`,1030:`da`,1125:`dv`,2067:`nl_BE`,1043:`nl_NL`,1126:`bin`,3081:`en_AU`,10249:`en_BZ`,4105:`en_CA`,9225:`en_CB`,2057:`en_GB`,16393:`en_IN`,6153:`en_IE`,8201:`en_JM`,5129:`en_NZ`,13321:`en_PH`,7177:`en_ZA`,11273:`en_TT`,1033:`en_US`,12297:`en_ZW`,1061:`et`,1071:`mk`,1080:`fo`,1065:`fa`,1124:`fil`,1035:`fi`,2060:`fr_BE`,11276:`fr_CM`,3084:`fr_CA`,9228:`fr_CG`,12300:`fr_CI`,1036:`fr_FR`,5132:`fr_LU`,13324:`fr_ML`,6156:`fr_MC`,14348:`fr_MA`,10252:`fr_SN`,4108:`fr_CH`,7180:`fr`,1122:`fy_NL`,2108:`gd_IE`,1084:`gd`,1110:`gl`,1079:`ka`,3079:`de_AT`,1031:`de_DE`,5127:`de_LI`,4103:`de_LU`,2055:`de_CH`,1032:`el`,1140:`gn`,1095:`gu`,1279:`en`,1037:`he`,1081:`hi`,1038:`hu`,1039:`is`,1136:`ig_NG`,1057:`id`,1040:`it_IT`,2064:`it_CH`,1041:`ja`,1099:`kn`,1120:`ks`,1087:`kk`,1107:`km`,1111:`kok`,1042:`ko`,1088:`ky`,1108:`lo`,1142:`la`,1062:`lv`,1063:`lt`,2110:`ms_BN`,1086:`ms_MY`,1100:`ml`,1082:`mt`,1112:`mni`,1153:`mi`,1102:`mr`,1104:`mn`,2128:`mn`,1121:`ne`,1044:`no_NO`,2068:`no_NO`,1096:`or`,1045:`pl`,1046:`pt_BR`,2070:`pt_PT`,1094:`pa`,1047:`rm`,2072:`ro_MO`,1048:`ro_RO`,1049:`ru`,2073:`ru_MO`,1083:`se`,1103:`sa`,3098:`sr_SP`,2074:`sr_SP`,1072:`st`,1074:`tn`,1113:`sd`,1115:`si`,1051:`sk`,1060:`sl`,1143:`so`,1070:`sb`,11274:`es_AR`,16394:`es_BO`,13322:`es_CL`,9226:`es_CO`,5130:`es_CR`,7178:`es_DO`,12298:`es_EC`,17418:`es_SV`,4106:`es_GT`,18442:`es_HN`,2058:`es_MX`,19466:`es_NI`,6154:`es_PA`,15370:`es_PY`,10250:`es_PE`,20490:`es_PR`,1034:`es_ES`,14346:`es_UY`,8202:`es_VE`,1089:`sw`,2077:`sv_FI`,1053:`sv_SE`,1114:`syc`,1064:`tg`,1097:`ta`,1092:`tt`,1098:`te`,1054:`th`,1105:`bo`,1073:`ts`,1055:`tr`,1090:`tk`,1058:`uk`,1056:`ur`,2115:`uz_UZ`,1091:`uz_UZ`,1075:`ve`,1066:`vi`,1106:`cy`,1076:`xh`,1085:`yi`,1077:`zu`}),fo=/^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i,po={},H=(e,t=``)=>e.replace(/~/g,t).split(`;`),mo=(e,t=0,n=0)=>(e.mmm||=t<1?e.mmmm.concat():e.mmmm.map(e=>{let n=e.slice(0,t%10);return n+(t<10||e===n?``:`.`)}),e.ddd||=n<1?e.dddd.concat():e.dddd.map(e=>{let t=e.slice(0,n%10);return t+(n<10||e===t?``:`.`)}),!e.mmm6&&e.mmmm6&&(e.mmm6=e.mmmm6),e),ho={group:`\xA0`,decimal:`.`,positive:`+`,negative:`-`,percent:`%`,exponent:`E`,nan:`NaN`,infinity:`∞`,ampm:H(`AM;PM`),mmmm6:H(`Muharram;Safar;Rabiʻ I;Rabiʻ II;Jumada I;Jumada II;Rajab;Shaʻban;Ramadan;Shawwal;Dhuʻl-Qiʻdah;Dhuʻl-Hijjah`),mmm6:H(`Muh.;Saf.;Rab. I;Rab. II;Jum. I;Jum. II;Raj.;Sha.;Ram.;Shaw.;Dhuʻl-Q.;Dhuʻl-H.`),mmmm:H(`January;February;March;April;May;June;July;August;September;October;November;December`),mmm:H(`Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec`),dddd:H(`Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday`),ddd:H(`Sun;Mon;Tue;Wed;Thu;Fri;Sat`),bool:H(`TRUE;FALSE`),preferMDY:!1};function go(e){let t=fo.exec(e);if(!t)throw SyntaxError(`Malformed locale: ${e}`);return{lang:t[1]+(t[2]?`_`+t[2]:``),language:t[1],territory:t[2]||``}}function _o(e){if(typeof e==`number`)return uo[65535&e]||null;let t=parseInt(e,16);return isFinite(t)&&uo[65535&t]?uo[65535&t]||null:fo.test(e)?e:null}function vo(e){let t=_o(e),n=null;if(t){let e=go(t);n=po[e.lang]||po[e.language]||null}return n}function yo(e){return Object.assign({},ho,e)}function U(e,t){let n=typeof t==`object`?t:go(t);return po[n.lang]=yo(e),n.language===n.lang||po[n.language]||(po[n.language]=yo(e)),po[n.lang]}var bo=yo({group:`,`,preferMDY:!0});bo.isDefault=!0,U({group:`,`,ampm:H(`上午;下午`),mmmm:H(`一月;二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月`),mmm:H(`1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月`),dddd:H(`~日;~一;~二;~三;~四;~五;~六`,`星期`),ddd:H(`周日;周一;周二;周三;周四;周五;周六`)},`zh_CN`);var xo={group:`,`,ampm:H(`上午;下午`),mmmm:H(`1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月`),mmm:H(`1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月`),dddd:H(`~日;~一;~二;~三;~四;~五;~六`,`星期`),ddd:H(`周日;周一;周二;周三;周四;周五;周六`)};U({...xo,nan:`非數值`,dddd:H(`~日;~一;~二;~三;~四;~五;~六`,`星期`)},`zh_TW`),U({...xo,dddd:H(`~日;~一;~二;~三;~四;~五;~六`,`星期`)},`zh_HK`),U({...xo,ampm:H(`午前;午後`),dddd:H(`日~;月~;火~;水~;木~;金~;土~`,`曜日`),ddd:H(`日;月;火;水;木;金;土`)},`ja`),U({group:`,`,ampm:H(`오전;오후`),mmmm:H(`1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월`),mmm:H(`1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월`),dddd:H(`일요일;월요일;화요일;수요일;목요일;금요일;토요일`),ddd:H(`일;월;화;수;목;금;토`)},`ko`),U({group:`,`,ampm:H(`ก่อนเที่ยง;หลังเที่ยง`),mmmm:H(`มกร~;กุมภาพันธ์;มีน~;เมษายน;พฤษภ~;มิถุนายน;กรกฎ~;สิงห~;กันยายน;ตุล~;พฤศจิกายน;ธันว~`,`าคม`),mmm:H(`ม.ค.;ก.พ.;มี.ค.;เม.ย.;พ.ค.;มิ.ย.;ก.ค.;ส.ค.;ก.ย.;ต.ค.;พ.ย.;ธ.ค.`),dddd:H(`วันอาทิตย์;วันจันทร์;วันอังคาร;วันพุธ;วันพฤหัสบดี;วันศุกร์;วันเสาร์`),ddd:H(`อา.;จ.;อ.;พ.;พฤ.;ศ.;ส.`)},`th`),U(mo({decimal:`,`,ampm:H(`dop.;odp.`),mmmm:H(`ledna;února;března;dubna;května;června;července;srpna;září;října;listopadu;prosince`),mmm:H(`I;II;III;IV;V;VI;VII;VIII;IX;X;XI;XII`),dddd:H(`neděle;pondělí;úterý;středa;čtvrtek;pátek;sobota`),bool:H(`PRAVDA;NEPRAVDA`)},-1,2),`cs`),U(mo({group:`.`,decimal:`,`,mmmm:H(`januar;februar;marts;april;maj;juni;juli;august;september;oktober;november;december`),dddd:H(`søn~;man~;tirs~;ons~;tors~;fre~;lør~`,`dag`),bool:H(`SAND;FALSK`)},13,13),`da`),U(mo({group:`.`,decimal:`,`,ampm:H(`a.m.;p.m.`),mmmm:H(`januari;februari;maart;april;mei;juni;juli;augustus;september;oktober;november;december`),mmm:H(`jan.;feb.;mrt.;apr.;mei;jun.;jul.;aug.;sep.;okt.;nov.;dec.`),dddd:H(`zondag;maandag;dinsdag;woensdag;donderdag;vrijdag;zaterdag`),bool:H(`WAAR;ONWAAR`)},-1,2),`nl`),U({group:`,`,preferMDY:!0},`en`),U({group:`,`,preferMDY:!0},`en_US`),U({group:`,`},`en_AU`),U({group:`,`},`en_CA`),U({group:`,`},`en_GB`),U({group:`,`,mmm:H(`Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sept;Oct;Nov;Dec`)},`en_IE`),U(mo({decimal:`,`,nan:`epäluku`,ampm:H(`ap.;ip.`),mmmm:H(`tammi~;helmi~;maalis~;huhti~;touko~;kesä~;heinä~;elo~;syys~;loka~;marras~;joulu~`,`kuuta`),mmm:H(`tammik.;helmik.;maalisk.;huhtik.;toukok.;kesäk.;heinäk.;elok.;syysk.;lokak.;marrask.;jouluk.`),dddd:H(`sunnun~;maanan~;tiis~;keskiviikkona;tors~;perjan~;lauan~`,`taina`),bool:H(`TOSI;EPÄTOSI`)},-1,2),`fi`);var So=mo({group:` `,decimal:`,`,mmmm:H(`janvier;février;mars;avril;mai;juin;juillet;août;septembre;octobre;novembre;décembre`),mmm:H(`janv.;févr.;mars;avr.;mai;juin;juil.;août;sept.;oct.;nov.;déc.`),dddd:H(`~manche;lun~;mar~;mercre~;jeu~;vendre~;same~`,`di`),bool:H(`VRAI;FAUX`)},-1,13);U({...So},`fr`),U({...So,mmm:H(`janv.;févr.;mars;avr.;mai;juin;juill.;août;sept.;oct.;nov.;déc.`)},`fr_CA`),U({group:`'`,decimal:`.`,...So},`fr_CH`);var Co=mo({mmmm:H(`Januar;Februar;März;April;Mai;Juni;Juli;August;September;Oktober;November;Dezember`),mmm:H(`Jan.;Feb.;März;Apr.;Mai;Juni;Juli;Aug.;Sept.;Okt.;Nov.;Dez.`),dddd:H(`Sonn~;Mon~;Diens~;Mittwoch;Donners~;Frei~;Sams~`,`tag`),bool:H(`WAHR;FALSCH`)},-1,12);U({group:`.`,decimal:`,`,...Co},`de`),U({group:`'`,decimal:`.`,...Co},`de_CH`),U(mo({group:`.`,decimal:`,`,ampm:H(`π.μ.;μ.μ.`),mmmm:H(`Ιανουαρ~;Φεβρουαρ~;Μαρτ~;Απριλ~;Μαΐου;Ιουν~;Ιουλ~;Αυγούστου;Σεπτεμβρ~;Οκτωβρ~;Νοεμβρ~;Δεκεμβρ~`,`ίου`),mmm:H(`Ιαν;Φεβ;Μαρ;Απρ;Μαΐ;Ιουν;Ιουλ;Αυγ;Σεπ;Οκτ;Νοε;Δεκ`),dddd:H(`Κυριακή;Δευτέρα;Τρίτη;Τετάρτη;Πέμπτη;Παρασκευή;Σάββατο`)},-1,3),`el`),U({decimal:`,`,ampm:H(`de.;du.`),mmmm:H(`január;február;március;április;május;június;július;augusztus;szeptember;október;november;december`),mmm:H(`jan.;febr.;márc.;ápr.;máj.;jún.;júl.;aug.;szept.;okt.;nov.;dec.`),dddd:H(`vasárnap;hétfő;kedd;szerda;csütörtök;péntek;szombat`),ddd:H(`V;H;K;Sze;Cs;P;Szo`),bool:H(`IGAZ;HAMIS`)},`hu`),U(mo({group:`.`,decimal:`,`,ampm:H(`f.h.;e.h.`),mmmm:H(`janúar;febrúar;mars;apríl;maí;júní;júlí;ágúst;september;október;nóvember;desember`),dddd:H(`sunnu~;mánu~;þriðju~;miðviku~;fimmtu~;föstu~;laugar~`,`dagur`)},13,13),`is`),U(mo({group:`.`,decimal:`,`,mmmm:H(`Januari;Februari;Maret;April;Mei;Juni;Juli;Agustus;September;Oktober;November;Desember`),dddd:H(`Minggu;Senin;Selasa;Rabu;Kamis;Jumat;Sabtu`)},3,3),`id`);var wo=mo({mmmm:H(`gennaio;febbraio;marzo;aprile;maggio;giugno;luglio;agosto;settembre;ottobre;novembre;dicembre`),dddd:H(`domenica;lunedì;martedì;mercoledì;giovedì;venerdì;sabato`),bool:H(`VERO;FALSO`)},3,3);U({group:`.`,decimal:`,`,...wo},`it`),U({group:`'`,decimal:`.`,...wo},`it_CH`);var To={decimal:`,`,ampm:H(`a.m.;p.m.`),mmmm:H(`januar;februar;mars;april;mai;juni;juli;august;september;oktober;november;desember`),mmm:H(`jan.;feb.;mar.;apr.;mai;jun.;jul.;aug.;sep.;okt.;nov.;des.`),dddd:H(`søn~;man~;tirs~;ons~;tors~;fre~;lør~`,`dag`),bool:H(`SANN;USANN`)};U(mo({...To},-1,13),`nb`),U(mo({...To},-1,13),`no`),U(mo({decimal:`,`,mmmm:H(`stycznia;lutego;marca;kwietnia;maja;czerwca;lipca;sierpnia;września;października;listopada;grudnia`),dddd:H(`niedziela;poniedziałek;wtorek;środa;czwartek;piątek;sobota`),ddd:H(`niedz.;pon.;wt.;śr.;czw.;pt.;sob.`),bool:H(`PRAWDA;FAŁSZ`)},3,-1),`pl`);var Eo={group:`.`,decimal:`,`,mmmm:H(`janeiro;fevereiro;março;abril;maio;junho;julho;agosto;setembro;outubro;novembro;dezembro`),dddd:H(`domingo;segunda-feira;terça-feira;quarta-feira;quinta-feira;sexta-feira;sábado`),bool:H(`VERDADEIRO;FALSO`)};U(mo(Eo,13,13),`pt`),U(mo(Eo,13,13),`pt_BR`),U({decimal:`,`,nan:`не\xA0число`,mmmm:H(`января;февраля;марта;апреля;мая;июня;июля;августа;сентября;октября;ноября;декабря`),mmm:H(`янв.;февр.;мар.;апр.;мая;июн.;июл.;авг.;сент.;окт.;нояб.;дек.`),dddd:H(`воскресенье;понедельник;вторник;среда;четверг;пятница;суббота`),ddd:H(`вс;пн;вт;ср;чт;пт;сб`),mmmm6:H(`рамадан;шавваль;зуль-каада;зуль-хиджжа;мухаррам;раби-уль-авваль;раби-уль-ахир;джумад-уль-авваль;джумад-уль-ахир;раджаб;шаабан;рамадан`),mmm6:H(`рам.;шав.;зуль-к.;зуль-х.;мух.;раб. I;раб. II;джум. I;джум. II;радж.;шааб.;рам.`),bool:H(`ИСТИНА;ЛОЖЬ`)},`ru`),U(mo({decimal:`,`,mmmm:H(`januára;februára;marca;apríla;mája;júna;júla;augusta;septembra;októbra;novembra;decembra`),dddd:H(`nedeľa;pondelok;utorok;streda;štvrtok;piatok;sobota`)},3,2),`sk`);var Do={group:`.`,decimal:`,`,ampm:H(`a.\xA0m.;p.\xA0m.`),mmmm:H(`enero;febrero;marzo;abril;mayo;junio;julio;agosto;septiem~;octu~;noviem~;diciem~`,`bre`),mmm:H(`ene;feb;mar;abr;may;jun;jul;ago;sept;oct;nov;dic`),dddd:H(`domingo;lunes;martes;miércoles;jueves;viernes;sábado`),ddd:H(`dom;lun;mar;mié;jue;vie;sáb`),bool:H(`VERDADERO;FALSO`)},Oo=H(`ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic`),ko=H(`ene.;feb.;mar.;abr.;may.;jun.;jul.;ago.;sept.;oct.;nov.;dic.`);U({...Do},`es`),U({...Do},`es_AR`),U({...Do},`es_BO`),U({...Do},`es_CL`),U({...Do},`es_CO`),U({...Do},`es_EC`),U({...Do,mmm:Oo,ampm:H(`a.m.;p.m.`)},`es_MX`),U({...Do,mmm:ko},`es_PY`),U({...Do,mmm:ko},`es_UY`),U({...Do,mmm:ko,mmmm:H(`enero;febrero;marzo;abril;mayo;junio;julio;agosto;setiembre;octubre;noviembre;diciembre`)},`es_VE`),U({decimal:`,`,ampm:H(`fm;em`),mmmm:H(`januari;februari;mars;april;maj;juni;juli;augusti;september;oktober;november;december`),mmm:H(`jan.;feb.;mars;apr.;maj;juni;juli;aug.;sep.;okt.;nov.;dec.`),dddd:H(`sön~;mån~;tis~;ons~;tors~;fre~;lör~`,`dag`),ddd:H(`sön;mån;tis;ons;tors;fre;lör`)},`sv`),U(mo({group:`.`,decimal:`,`,ampm:H(`ÖÖ;ÖS`),mmmm:H(`Ocak;Şubat;Mart;Nisan;Mayıs;Haziran;Temmuz;Ağustos;Eylül;Ekim;Kasım;Aralık`),mmm:H(`Oca;Şub;Mar;Nis;May;Haz;Tem;Ağu;Eyl;Eki;Kas;Ara`),dddd:H(`Pazar;Pazartesi;Salı;Çarşamba;Perşembe;Cuma;Cumartesi`),ddd:H(`Paz;Pzt;Sal;Çar;Per;Cum;Cmt`),bool:H(`DOĞRU;YANLIŞ`)},3,-1),`tr`),U({group:`,`,ampm:H(`yb;yh`),mmmm:H(`Ionawr;Chwefror;Mawrth;Ebrill;Mai;Mehefin;Gorffennaf;Awst;Medi;Hydref;Tachwedd;Rhagfyr`),mmm:H(`Ion;Chwef;Maw;Ebr;Mai;Meh;Gorff;Awst;Medi;Hyd;Tach;Rhag`),dddd:H(`Dydd Sul;Dydd Llun;Dydd Mawrth;Dydd Mercher;Dydd Iau;Dydd Gwener;Dydd Sadwrn`),ddd:H(`Sul;Llun;Maw;Mer;Iau;Gwen;Sad`)},`cy`),U({group:`.`,decimal:`,`,mmmm:H(`yanvar;fevral;mart;aprel;may;iyun;iyul;avqust;sentyabr;oktyabr;noyabr;dekabr`),mmm:H(`yan;fev;mar;apr;may;iyn;iyl;avq;sen;okt;noy;dek`),dddd:H(`bazar;bazar ertəsi;çərşənbə axşamı;çərşənbə;cümə axşamı;cümə;şənbə`),ddd:H(`B.;B.e.;Ç.a.;Ç.;C.a.;C.;Ş.`)},`az`),U(mo({decimal:`,`,mmmm:H(`студзеня;лютага;сакавіка;красавіка;мая;чэрвеня;ліпеня;жніўня;верасня;кастрычніка;лістапада;снежня`),dddd:H(`нядзеля;панядзелак;аўторак;серада;чацвер;пятніца;субота`),ddd:H(`нд;пн;аў;ср;чц;пт;сб`)},3,-1),`be`),U({decimal:`,`,ampm:H(`пр.об.;сл.об.`),mmmm:H(`януари;февруари;март;април;май;юни;юли;август;септември;октомври;ноември;декември`),mmm:H(`яну;фев;март;апр;май;юни;юли;авг;сеп;окт;ное;дек`),dddd:H(`неделя;понеделник;вторник;сряда;четвъртък;петък;събота`),ddd:H(`нд;пн;вт;ср;чт;пт;сб`),bool:H(`ИСТИНА;ЛОЖЬ`)},`bg`),U({group:`.`,decimal:`,`,mmmm:H(`de gener;de febrer;de març;d’abril;de maig;de juny;de juliol;d’agost;de setembre;d’octubre;de novembre;de desembre`),mmm:H(`de gen.;de febr.;de març;d’abr.;de maig;de juny;de jul.;d’ag.;de set.;d’oct.;de nov.;de des.`),dddd:H(`diumenge;dilluns;dimarts;dimecres;dijous;divendres;dissabte`),ddd:H(`dg.;dl.;dt.;dc.;dj.;dv.;ds.`),ampm:H(`a.\xA0m.;p.\xA0m.`)},`ca`),U(mo({group:`,`,decimal:`.`,mmmm:H(`Enero;Pebrero;Marso;Abril;Mayo;Hunyo;Hulyo;Agosto;Setyembre;Oktubre;Nobyembre;Disyembre`),dddd:H(`Linggo;Lunes;Martes;Miyerkules;Huwebes;Biyernes;Sabado`)},3,3),`fil`),U({group:`,`,decimal:`.`,mmmm:H(`જાન્યુઆરી;ફેબ્રુઆરી;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટેમ્બર;ઑક્ટોબર;નવેમ્બર;ડિસેમ્બર`),mmm:H(`જાન્યુ;ફેબ્રુ;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટે;ઑક્ટો;નવે;ડિસે`),dddd:H(`રવિ~;સોમ~;મંગળ~;બુધ~;ગુરુ~;શુક્ર~;શનિ~`,`વાર`),ddd:H(`રવિ;સોમ;મંગળ;બુધ;ગુરુ;શુક્ર;શનિ`)},`gu`),U({group:`,`,decimal:`.`,ampm:H(`לפנה״צ;אחה״צ`),dddd:H(`~ראשון;~שני;~שלישי;~רביעי;~חמישי;~שישי;~שבת`,`יום `),ddd:H(`~א׳;~ב׳;~ג׳;~ד׳;~ה׳;~ו׳;שבת`,`יום `),mmmm:H(`ינואר;פברואר;מרץ;אפריל;מאי;יוני;יולי;אוגוסט;ספטמבר;אוקטובר;נובמבר;דצמבר`),mmm:H(`ינו׳;פבר׳;מרץ;אפר׳;מאי;יוני;יולי;אוג׳;ספט׳;אוק׳;נוב׳;דצמ׳`),mmmm6:H(`רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע אל־אוול;רביע א־ת׳אני;ג׳ומאדא אל־אולא;ג׳ומאדא א־ת׳אניה;רג׳ב;שעבאן;רמדאן`),mmm6:H(`רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע א׳;רביע ב׳;ג׳ומאדא א׳;ג׳ומאדא ב׳;רג׳ב;שעבאן;רמדאן`)},`he`),U(mo({group:`.`,decimal:`,`,mmmm:H(`siječnja;veljače;ožujka;travnja;svibnja;lipnja;srpnja;kolovoza;rujna;listopada;studenoga;prosinca`),mmm:H(`sij;velj;ožu;tra;svi;lip;srp;kol;ruj;lis;stu;pro`),dddd:H(`nedjelja;ponedjeljak;utorak;srijeda;četvrtak;petak;subota`)},-1,3),`hr`),U({decimal:`,`,mmmm:H(`հունվարի;փետրվարի;մարտի;ապրիլի;մայիսի;հունիսի;հուլիսի;օգոստոսի;սեպտեմբերի;հոկտեմբերի;նոյեմբերի;դեկտեմբերի`),mmm:H(`հնվ;փտվ;մրտ;ապր;մյս;հնս;հլս;օգս;սեպ;հոկ;նոյ;դեկ`),dddd:H(`կիրակի;երկուշաբթի;երեքշաբթի;չորեքշաբթի;հինգշաբթի;ուրբաթ;շաբաթ`),ddd:H(`կիր;երկ;երք;չրք;հնգ;ուր;շբթ`)},`hy`),U(mo({decimal:`,`,mmmm:H(`იანვარი;თებერვალი;მარტი;აპრილი;მაისი;ივნისი;ივლისი;აგვისტო;სექტემბერი;ოქტომბერი;ნოემბერი;დეკემბერი`),dddd:H(`კვირა;ორშაბათი;სამშაბათი;ოთხშაბათი;ხუთშაბათი;პარასკევი;შაბათი`)},3,3),`ka`),U(mo({decimal:`,`,mmmm:H(`қаңтар;ақпан;наурыз;сәуір;мамыр;маусым;шілде;тамыз;қыркүйек;қазан;қараша;желтоқсан`),dddd:H(`жексенбі;дүйсенбі;сейсенбі;сәрсенбі;бейсенбі;жұма;сенбі`),ddd:H(`жс;дс;сс;ср;бс;жм;сб`)},13,-1),`kk`),U({group:`,`,mmmm:H(`ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿಲ್;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂಬರ್;ಅಕ್ಟೋಬರ್;ನವೆಂಬರ್;ಡಿಸೆಂಬರ್`),mmm:H(`ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿ;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂ;ಅಕ್ಟೋ;ನವೆಂ;ಡಿಸೆಂ`),dddd:H(`ಭಾನು~;ಸೋಮ~;ಮಂಗಳ~;ಬುಧ~;ಗುರು~;ಶುಕ್ರ~;ಶನಿ~`,`ವಾರ`),ddd:H(`ಭಾನು;ಸೋಮ;ಮಂಗಳ;ಬುಧ;ಗುರು;ಶುಕ್ರ;ಶನಿ`),ampm:H(`ಪೂರ್ವಾಹ್ನ;ಅಪರಾಹ್ನ`)},`kn`),U({decimal:`,`,mmmm:H(`sausio;vasario;kovo;balandžio;gegužės;birželio;liepos;rugpjūčio;rugsėjo;spalio;lapkričio;gruodžio`),mmm:H(`saus.;vas.;kov.;bal.;geg.;birž.;liep.;rugp.;rugs.;spal.;lapkr.;gruod.`),dddd:H(`sekmadienis;pirmadienis;antradienis;trečiadienis;ketvirtadienis;penktadienis;šeštadienis`),ddd:H(`sk;pr;an;tr;kt;pn;št`),ampm:H(`priešpiet;popiet`)},`lt`),U({decimal:`,`,mmmm:H(`janvāris;februāris;marts;aprīlis;maijs;jūnijs;jūlijs;augusts;septembris;oktobris;novembris;decembris`),mmm:H(`janv.;febr.;marts;apr.;maijs;jūn.;jūl.;aug.;sept.;okt.;nov.;dec.`),dddd:H(`svētdiena;pirmdiena;otrdiena;trešdiena;ceturtdiena;piektdiena;sestdiena`),ddd:H(`svētd.;pirmd.;otrd.;trešd.;ceturtd.;piektd.;sestd.`),ampm:H(`priekšpusdienā;pēcpusdienā`)},`lv`),U({group:`,`,decimal:`.`,mmmm:H(`ജനുവരി;ഫെബ്രുവരി;മാർച്ച്;ഏപ്രിൽ;മേയ്;ജൂൺ;ജൂലൈ;ഓഗസ്റ്റ്;സെപ്റ്റംബർ;ഒക്ടോബർ;നവംബർ;ഡിസംബർ`),mmm:H(`ജനു;ഫെബ്രു;മാർ;ഏപ്രി;മേയ്;ജൂൺ;ജൂലൈ;ഓഗ;സെപ്റ്റം;ഒക്ടോ;നവം;ഡിസം`),dddd:H(`ഞായറാഴ്ച;തിങ്കളാഴ്ച;ചൊവ്വാഴ്ച;ബുധനാഴ്ച;വ്യാഴാഴ്ച;വെള്ളിയാഴ്ച;ശനിയാഴ്ച`),ddd:H(`ഞായർ;തിങ്കൾ;ചൊവ്വ;ബുധൻ;വ്യാഴം;വെള്ളി;ശനി`)},`ml`),U({group:`,`,decimal:`.`,mmmm:H(`нэгдүгээ~;хоёрдугаа~;гуравдугаа~;дөрөвдүгээ~;тавдугаа~;зургаадугаа~;долоодугаа~;наймдугаа~;есдүгээ~;аравдугаа~;арван нэгдүгээ~;арван хоёрдугаа~`,`р сар`),mmm:H(`1~;2~;3~;4~;5~;6~;7~;8~;9~;10~;11~;12~`,`-р сар`),dddd:H(`ням;даваа;мягмар;лхагва;пүрэв;баасан;бямба`),ddd:H(`Ня;Да;Мя;Лх;Пү;Ба;Бя`),ampm:H(`ү.ө.;ү.х.`)},`mn`),U({group:`,`,decimal:`.`,mmmm:H(`जानेवारी;फेब्रुवारी;मार्च;एप्रिल;मे;जून;जुलै;ऑगस्ट;सप्टेंबर;ऑक्टोबर;नोव्हेंबर;डिसेंबर`),mmm:H(`जाने;फेब्रु;मार्च;एप्रि;मे;जून;जुलै;ऑग;सप्टें;ऑक्टो;नोव्हें;डिसें`),dddd:H(`रविवार;सोमवार;मंगळवार;बुधवार;गुरुवार;शुक्रवार;शनिवार`),ddd:H(`रवि;सोम;मंगळ;बुध;गुरु;शुक्र;शनि`)},`mr`),U(mo({group:`,`,decimal:`.`,mmmm:H(`ဇန်နဝါရီ;ဖေဖော်ဝါရီ;မတ်;ဧပြီ;မေ;ဇွန်;ဇူလိုင်;ဩဂုတ်;စက်တင်ဘာ;အောက်တိုဘာ;နိုဝင်ဘာ;ဒီဇင်ဘာ`),mmm:H(`ဇန်;ဖေ;မတ်;ဧ;မေ;ဇွန်;ဇူ;ဩ;စက်;အောက်;နို;ဒီ`),dddd:H(`တနင်္ဂနွေ;တနင်္လာ;အင်္ဂါ;ဗုဒ္ဓဟူး;ကြာသပတေး;သောကြာ;စနေ`),ampm:H(`နံနက်;ညနေ`)},-1,0),`my`),U({group:`,`,decimal:`.`,mmmm:H(`ਜਨਵਰੀ;ਫ਼ਰਵਰੀ;ਮਾਰਚ;ਅਪ੍ਰੈਲ;ਮਈ;ਜੂਨ;ਜੁਲਾਈ;ਅਗਸਤ;ਸਤੰਬਰ;ਅਕਤੂਬਰ;ਨਵੰਬਰ;ਦਸੰਬਰ`),mmm:H(`ਜਨ;ਫ਼ਰ;ਮਾਰਚ;ਅਪ੍ਰੈ;ਮਈ;ਜੂਨ;ਜੁਲਾ;ਅਗ;ਸਤੰ;ਅਕਤੂ;ਨਵੰ;ਦਸੰ`),dddd:H(`ਐਤਵਾਰ;ਸੋਮਵਾਰ;ਮੰਗਲਵਾਰ;ਬੁੱਧਵਾਰ;ਵੀਰਵਾਰ;ਸ਼ੁੱਕਰਵਾਰ;ਸ਼ਨਿੱਚਰਵਾਰ`),ddd:H(`ਐਤ;ਸੋਮ;ਮੰਗਲ;ਬੁੱਧ;ਵੀਰ;ਸ਼ੁੱਕਰ;ਸ਼ਨਿੱਚਰ`),ampm:H(`ਪੂ.ਦੁ.;ਬਾ.ਦੁ.`)},`pa`),U({group:`.`,decimal:`,`,mmmm:H(`ianuarie;februarie;martie;aprilie;mai;iunie;iulie;august;septem~;octom~;noiem~;decem~`,`brie`),mmm:H(`ian.;feb.;mar.;apr.;mai;iun.;iul.;aug.;sept.;oct.;nov.;dec.`),dddd:H(`duminică;luni;marți;miercuri;joi;vineri;sâmbătă`),ddd:H(`dum.;lun.;mar.;mie.;joi;vin.;sâm.`),ampm:H(`a.m.;p.m.`)},`ro`),U(mo({group:`.`,decimal:`,`,mmmm:H(`januar;februar;marec;april;maj;junij;julij;avgust;september;oktober;november;december`),mmm:H(`jan.;feb.;mar.;apr.;maj;jun.;jul.;avg.;sep.;okt.;nov.;dec.`),dddd:H(`nedelja;ponedeljek;torek;sreda;četrtek;petek;sobota`),ampm:H(`dop.;pop.`)},-1,13),`sl`),U(mo({group:`.`,decimal:`,`,mmmm:H(`јануар;фебруар;март;април;мај;јун;јул;август;септембар;октобар;новембар;децембар`),dddd:H(`недеља;понедељак;уторак;среда;четвртак;петак;субота`)},3,3),`sr`),U({group:`,`,decimal:`.`,mmmm:H(`ஜனவரி;பிப்ரவரி;மார்ச்;ஏப்ரல்;மே;ஜூன்;ஜூலை;ஆகஸ்ட்;செப்டம்பர்;அக்டோபர்;நவம்பர்;டிசம்பர்`),mmm:H(`ஜன.;பிப்.;மார்.;ஏப்.;மே;ஜூன்;ஜூலை;ஆக.;செப்.;அக்.;நவ.;டிச.`),dddd:H(`ஞாயிறு;திங்கள்;செவ்வாய்;புதன்;வியாழன்;வெள்ளி;சனி`),ddd:H(`ஞாயி.;திங்.;செவ்.;புத.;வியா.;வெள்.;சனி`)},`ta`),U({group:`,`,decimal:`.`,mmmm:H(`జనవరి;ఫిబ్రవరి;మార్చి;ఏప్రిల్;మే;జూన్;జులై;ఆగస్టు;సెప్టెంబర్;అక్టోబర్;నవంబర్;డిసెంబర్`),mmm:H(`జన;ఫిబ్ర;మార్చి;ఏప్రి;మే;జూన్;జులై;ఆగ;సెప్టెం;అక్టో;నవం;డిసెం`),dddd:H(`ఆదివారం;సోమవారం;మంగళవారం;బుధవారం;గురువారం;శుక్రవారం;శనివారం`),ddd:H(`ఆది;సోమ;మంగళ;బుధ;గురు;శుక్ర;శని`)},`te`),U({decimal:`,`,mmmm:H(`січня;лютого;березня;квітня;травня;червня;липня;серпня;вересня;жовтня;листопада;грудня`),mmm:H(`січ.;лют.;бер.;квіт.;трав.;черв.;лип.;серп.;вер.;жовт.;лист.;груд.`),dddd:H(`неділю;понеділок;вівторок;середу;четвер;пʼятницю;суботу`),ddd:H(`нд;пн;вт;ср;чт;пт;сб`),ampm:H(`дп;пп`)},`uk`),U({group:`.`,decimal:`,`,mmmm:H(`~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12`,`tháng `),mmm:H(`~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12`,`thg `),dddd:H(`Chủ Nhật;Thứ Hai;Thứ Ba;Thứ Tư;Thứ Năm;Thứ Sáu;Thứ Bảy`),ddd:H(`CN;Th 2;Th 3;Th 4;Th 5;Th 6;Th 7`),ampm:H(`SA;CH`)},`vi`),U(mo({group:`٬`,decimal:`٫`,ampm:H(`ص;م`),mmmm:H(`يناير;فبراير;مارس;أبريل;مايو;يونيو;يوليو;أغسطس;سبتمبر;أكتوبر;نوفمبر;ديسمبر`),dddd:H(`الأحد;الاثنين;الثلاثاء;الأربعاء;الخميس;الجمعة;السبت`),mmmm6:H(`رمضان;شوال;ذو القعدة;ذو الحجة;محرم;ربيع الأول;ربيع الآخرة;جمادى الأولى;جمادى الآخرة;رجب;شعبان;رمضان`)},0,0),`ar`),U({group:`,`,decimal:`.`,mmmm:H(`জানুয়ারী;ফেব্রুয়ারী;মার্চ;এপ্রিল;মে;জুন;জুলাই;আগস্ট;সেপ্টেম্বর;অক্টোবর;নভেম্বর;ডিসেম্বর`),mmm:H(`জানু;ফেব;মার্চ;এপ্রি;মে;জুন;জুল;আগ;সেপ্টেঃ;অক্টোঃ;নভেঃ;ডিসেঃ`),dddd:H(`রবিবার;সোমবার;মঙ্গলবার;বুধবার;বৃহস্পতিবার;শুক্রবার;শনিবার`),ddd:H(`রবি;সোম;মঙ্গল;বুধ;বৃহস্পতি;শুক্র;শনি`)},`bn`),U({group:`,`,decimal:`.`,mmmm:H(`जनवरी;फ़रवरी;मार्च;अप्रैल;मई;जून;जुलाई;अगस्त;सितंबर;अक्तूबर;नवंबर;दिसंबर`),mmm:H(`जन॰;फ़र॰;मार्च;अप्रैल;मई;जून;जुल॰;अग॰;सित॰;अक्तू॰;नव॰;दिस॰`),dddd:H(`रविवार;सोमवार;मंगलवार;बुधवार;गुरुवार;शुक्रवार;शनिवार`),ddd:H(`रवि;सोम;मंगल;बुध;गुरु;शुक्र;शनि`),ampm:H(`am;pm`)},`hi`);var Ao={overflow:`######`,dateErrorThrows:!1,dateErrorNumber:!0,bigintErrorNumber:!1,dateSpanLarge:!0,leap1900:!0,nbsp:!1,throws:!0,invalid:`######`,locale:``,ignoreTimezone:!1,grouping:[3,3],indexColors:!0,skipChar:``,repeatChar:``,digitChar:``};function jo(e,t=0){if(typeof e!=`number`)return e;if(e<0)return-jo(-e,t);if(t){let n=10**t||1;return jo(e*n,0)/n}return Math.round(e)}var Mo=Math.floor;function No(e,t=!0){if(t&&e>=0){if(e===0)return[1900,1,0];if(e===60)return[1900,2,29];if(e<60)return[1900,e<32?1:2,(e-1)%31+1]}let n=e+68569+2415019,r=Mo(4*n/146097);n-=Mo((146097*r+3)/4);let i=Mo(4e3*(n+1)/1461001);n=n-Mo(1461*i/4)+31;let a=Mo(80*n/2447),o=n-Mo(2447*a/80);return n=Mo(a/11),[100*(r-49)+i+n|0,0|a+2-12*n,0|o]}function Po(e,t=0,n=!0){let r=Mo(e);return t===6?function(e){if(e===60)throw Error(`#VALUE!`);if(e<=1)return[1317,8,29];if(e<60)return[1317,e<32?9:10,1+(e-2)%30];let t=10631/30,n=.1335,r=e+466935,i=Mo(r/10631);r-=10631*i;let a=Mo((r-n)/t);r-=Mo(a*t+n);let o=Mo((r+28.5001)/29.5);return o===13?[30*i+a,12,30]:[30*i+a,o,r-Mo(29.5001*o-29)]}(r):t===-1?function(e){return No(e+1462)}(r):No(r,n)}var Fo=Math.floor,Io=86400;function Lo(e,t){let n=null;if(Array.isArray(e)){let[t,r,i,a,o,s]=e;n=Date.UTC(t,r==null?0:r-1,i??1,a||0,o||0,s||0)}else if(e instanceof Date&&(n=1*e,!t?.ignoreTimezone)){let t=new Date;t.setUTCFullYear(e.getFullYear(),e.getMonth(),e.getDate()),t.setUTCHours(e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()),n=1*t}if(n!=null&&isFinite(n)){let e=n/864e5;return e-(e<=-25509?-25568:-25569)}return null}function Ro(e,t){let n=0|e,r=Io*(e-n),i=Fo(r);r-i>.9999&&(i+=1,i===Io&&(i=0,n+=1));let a=i<0?Io+i:i,[o,s,c]=Po(e,0,t?.leap1900);return[o,s,c,Fo(a/60/60)%60,Fo(a/60)%60,Fo(a)%60]}var zo={},Bo={};function Vo(e,t,n=1){if(e){let r=e[0],i=e.slice(1);r===`!`?Vo(i,t,4):r===`?`?Vo(i,t,2):(t[r]=t[r]||{},Vo(i,t[r],n))}else t.$=n}function Ho(e,t){Vo(e,t),Vo(e+` x`,t),Vo(e+` l`,t),Vo(e+` l x`,t),Vo(`l `+e,t),Vo(`l `+e+` x`,t),Vo(e+` D`,t),Vo(e+` D x`,t),Vo(`D `+e,t),Vo(`D `+e+` x`,t)}`!d-m-y.!d-m-Y.!j-m-y.!j-m-Y.!d-n-y.!d-n-Y.!j-n-y.!j-n-Y.?m-d-y.?m-d-Y.?m-j-y.?m-j-Y.?n-d-y.?n-d-Y.?n-j-y.?n-j-Y.d-M-y.d-M-Y.j-M-y.j-M-Y.M-d-y.M-d-Y.M-j-y.M-j-Y.d-F-y.d-F-Y.F-d-y.F-d-Y.F-j-y.F-j-Y.j-F-y.j-F-Y.y-F-d.y-F-j.y-M-d.y-M-j.Y-F-d.Y-F-j.Y-M-d.Y-m-d.Y-M-j.Y-m-j.Y-n-d.Y-n-j.j-F.j-M.d-F.d-M.n-d.n-j.n-Y.m-d.m-j.m-Y.M-Y.M-y.F-y.F-Y.Y-M.Y-n.Y-m.Y-F.Y-M`.split(`.`).forEach(e=>{e.startsWith(`?`)||Ho(e,zo),e.startsWith(`!`)||Ho(e,Bo)}),new Date().getUTCFullYear();var Uo=` `,Wo=`\xA0`,Go=` `,Ko=`'`,qo=`٬`,Jo={".":[`,`,Wo,Go,Ko,qo],",":[`.`,Wo,Go,Ko,qo],"٫":[`.`,Wo,Go,Ko,qo]},Yo=e=>e?.length===1&&e>=`0`&&e<=`9`;function Xo(e,t,n){return t[n+`_max`]=e.length,t[n+`_min`]=e.replace(/#/g,``).length,t}function Zo(e,t){typeof e==`string`?t.push({type:`string`,value:e}):t.push(e)}function Qo(e,t){let n=e?.type;return n===`hash`||n===`zero`||n===`qmark`||n===`digit`&&t===`den`}function $o(e){let t=[],n={scale:1,percent:!1,text:!1,date:0,date_eval:!1,date_system:1,sec_decimals:0,general:!1,clock:24,int_pattern:[],frac_pattern:[],man_pattern:[],den_pattern:[],num_pattern:[],tokens:t},r=`int`,i=null,a=[],o,s=!1,c=-1,l=!1,u=``,d=!1;for(;++c<e.length&&!l;){let f=e[c],p=f.type||`error`;if(u+=f.raw,p===`general`)n.general=!0,Zo(f,t);else if(Qo(f,r)){let e=n[r+`_pattern`];Qo(o,r)||o?.type===`group`?(e.push((e.pop()||``)+f.value),i.num+=f.value):(e.push(f.value),i={type:r,num:f.value},Zo(i,t))}else if(p===`paren`)f.value===`(`&&(n.parens=!0),Zo(f.value,t);else if(p===`digit`)Zo(f.value,t);else if(p===`slash`)if(d=!0,n[r+`_pattern`].length){if(!i)throw SyntaxError(`Format pattern is missing a numerator`);n.fractions=!0,n.num_pattern.push(n[r+`_pattern`].pop()),i.type=`num`,r=`den`,Zo({type:`div`},t)}else Zo(f.value,t);else if(p===`comma`)Zo(`,`,t);else if(p===`scale`)n.scale*=.001**f.raw.length;else if(p===`group`){if(r===`int`&&(n.grouping=!0),r===`den`)throw SyntaxError(`Cannot group denominator digits`)}else if(p===`space`)Zo(f,t);else{if(p===`break`){l=!0;break}if(p===`text`)n.text=!0,Zo(f,t);else if(p===`plus`||p===`minus`)Zo(f,t);else if(p===`duration`){let e=f.value.toLowerCase(),r=e[0],i={type:``,size:0,date:1,pad:e.length};r===`h`?(i.size=16,i.type=`hour-elap`):r===`m`?(i.size=32,i.type=`min-elap`):(i.size=64,i.type=`sec-elap`),n.date|=i.size,a.push(i),Zo(i,t)}else if(n.date&&p===`point`&&e[c+1]?.type===`zero`){let r=1;c++;let i=`0`;e[c+1]?.type===`zero`&&(i+=`0`,r=2,c++),e[c+1]?.type===`zero`&&(i+=`0`,r=3,c++),u+=i;let a=[64,128,256,512][r];n.date|=a,n.date_eval=!0,n.sec_decimals=Math.max(n.sec_decimals,r),Zo({type:`subsec`,size:a,decimals:r,date:1},t)}else if(p===`calendar`)s||(f.value===`B2`||f.value===`b2`?n.date_system=6:n.date_system=1);else if(p===`datetime`){let e={type:``,size:0,date:1},r=f.value.toLowerCase(),i=r[0];if(r===`y`||r===`yy`)e.size=2,e.type=`year-short`;else if(i===`y`||i===`e`)e.size=2,e.type=`year`;else if(r===`b`||r===`bb`)e.size=2,e.type=`b-year-short`;else if(i===`b`)e.size=2,e.type=`b-year`;else if(r===`d`||r===`dd`)e.size=8,e.type=`day`,e.pad=/dd/.test(r);else if(r===`ddd`||r===`aaa`)e.size=8,e.type=`weekday-short`;else if(i===`d`||i===`a`)e.size=8,e.type=`weekday`;else if(i===`h`)e.size=16,e.type=`hour`,e.pad=/hh/i.test(r);else if(i===`m`){r.length===3?(e.size=4,e.type=`monthname-short`):r.length===5?(e.size=4,e.type=`monthname-single`):r.length>=4&&(e.size=4,e.type=`monthname`);let t=a[a.length-1];!e.type&&t&&!t.used&&80&t.size&&(t.used=!0,e.size=32,e.type=`min`,e.pad=/mm/.test(r)),e.type||(e.size=4,e.type=`month`,e.pad=/mm/.test(r),e.indeterminate=!0)}else if(i===`s`){e.size=64,e.type=`sec`,e.pad=/ss/.test(r);let t=a[a.length-1];t&&32&t.size?e.used=!0:t?.indeterminate&&(delete t.indeterminate,t.size=32,t.type=`min`,e.used=!0)}n.date|=e.size,n.date_eval=!0,a.push(e),Zo(e,t)}else if(p===`ampm`)n.clock=12,n.date=16|n.date,n.date_eval=!0,f.short=f.value===`A/P`,Zo(f,t);else if(p===`string`||p===`escaped`||p===`char`)Zo(f.value,t);else if(p===`condition`)n.condition=[f.value[0],parseFloat(f.value[1]??`0`)];else if(p===`locale`){let e=f.value.split(`-`),r=e.length<2?``:e.slice(1).join(`-`),i=e[0];i&&Zo(i,t);let a=_o(r);a&&(n.locale=a);let o=parseInt(r,16);isFinite(o)&&16711680&o&&(o>>16&255)==6&&(n.date_system=6),s=!0}else if(p===`color`){let e,t=f.value.toLowerCase();(e=/^color\s*(\d+)$/i.exec(t))&&(t=parseInt(e[1],10)),n.color=t}else if(p===`percent`)n.scale*=100,n.percent=!0,Zo(`%`,t);else if(p===`point`)Zo(f,t),n.date||(n.dec_fractions=!0,r=`frac`);else if(p===`exp`)n.exponential=!0,n.exp_plus=f.value.includes(`+`),r=`man`,Zo({type:`exp`,plus:n.exp_plus},t);else if(p===`skip`)Zo(f,t);else if(p===`fill`)Zo(f,t);else if(p!==`dbnum`&&p!==`natnum`)throw SyntaxError(p===`error`?`Illegal character: ${u}`:`Unknown token ${p} in ${u}`)}o=f}if(n.tokensUsed=c,n.pattern=u,/^((?:\[[^\]]+\])+)(;|$)/.test(n.pattern)&&!/^\[(?:h+|m+|s+)\]/.test(n.pattern)&&Zo({type:`text`},t),n.fractions&&n.dec_fractions||n.grouping&&!n.int_pattern.length||n.fractions&&n.exponential||n.fractions&&n.den_pattern.length*n.num_pattern.length===0||d&&!n.fractions&&!n.date||n.exponential&&(n.int_pattern.length||n.frac_pattern.length)*n.man_pattern.length===0)throw SyntaxError(`Invalid pattern: ${u}`);let f=n.int_pattern.join(``),p=n.man_pattern.join(``),m=n.frac_pattern.join(``);Xo(f,n,`int`);let h=0;for(let e=0;e<f.length;e++){let t=f[f.length-1-e];/^[0-9?]/.test(t)&&(h=e+1)}n.int_min=h,Xo(m,n,`frac`),Xo(p,n,`man`);let g=n.num_pattern.join(``),_=n.den_pattern[0]||``;if(_.includes(`?`)||g.includes(`?`)?(_=_.replace(/\d/g,`?`),_=_.replace(/#$/g,`?`),Xo(g,n,`num`),Xo(_,n,`den`),g=g.replace(/#$/g,`?`)):(Xo(g,n,`num`),Xo(_,n,`den`)),n.int_p=f,n.man_p=p,n.num_p=g,n.den_p=_,n.den_pattern.length&&(n.denominator=parseInt(n.den_pattern.join(``).replace(/\D/g,``),10)),n.integer=!!f.length,!n.integer&&!n.exponential&&m.length){let e=n.tokens.findIndex(e=>e.type===`point`);n.tokens.splice(e,0,{type:`int`,value:`#`}),n.integer=!0,n.int_pattern=[`#`],n.int_p=`#`}if(n.fractions)for(let e=0;e<t.length-1;e++){let n=t[e];if(n.type!==`string`&&n.type!==`space`)continue;let r=t[e+1].type;r===`num`?n.rule=`num+int`:r===`div`?n.rule=`num`:r===`den`&&(n.rule=`den`)}return n.grouping&&n.int_pattern.length>1&&(n.grouping=!1),n}function es(e,t=0){let n=Math.floor(Math.log10(e));return t>1?Math.floor(n/t)*t:n}function ts(e,t=1){return t<-300?parseFloat(e.toExponential().split(`e`)[0]):e*10**-t}var ns={total:1,sign:0,period:0,int:1,frac:0},rs=(e,t)=>e.replace(/\./,t.decimal),is=(e,t,n)=>{let r=Math.abs(t),i;return i=e===1?e:jo(e,5),[rs(i+``,n),n.exponent,t<0?n.negative:n.positive,r<10?`0`:``,r]};function as(e,t,n,r){let i=0|n;if(typeof n==`string`)e.push(n);else if(n===i)e.push(Math.abs(i));else{let t=Math.abs(n),i=es(t),a=ts(t,i);a===10&&(a=1,i++);let o=function(e,t=!0){let n=Math.abs(e);if(!n)return ns;let r=t&&e<0?1:0,i=Math.floor(n),a=Math.floor(Math.log10(n)+1),o=0,s=0;if(i!==n){o=1;let e=String(jo(n*10**-a,15)),t=e.length,r=!0,i=0;for(;i<=e.length;){if(e[i]===`.`){t--;break}e[i]===`0`&&r?t--:r=!1,i++}s=t-a,s<0&&(s=0,o=0)}return{total:r+Math.max(a,1)+o+s,digits:Math.max(a,0)+s,sign:r,period:o,int:Math.max(a,1),frac:s}}(t);if(i>=-4&&i<=-1){let n=t.toPrecision(10+i).replace(/\.?0+$/,``);e.push(rs(n,r))}else if(i===10){let n=t.toFixed(10).slice(0,12).replace(/\.$/,``);e.push(rs(n,r))}else if(Math.abs(i)<=9)if(o.total<=11){let n=jo(t,9).toFixed(o.frac);e.push(rs(n,r))}else i===9?e.push(Math.floor(t)):i>=0&&i<9?e.push(rs(String(jo(t,9-i)),r)):e.push(...is(a,i,r));else o.total>=12?e.push(...is(a,i,r)):e.push(rs(jo(t,9).toFixed(o.frac),r))}return e}function os(e,t=!1){return e===`0`?`0`:e===`?`?t?`\xA0`:` `:``}function ss(e){return typeof e==`number`&&isFinite(e)&&e!==0?Number(e.toPrecision(15)):e}function cs(e,t){return ss(jo(e,t))}function ls(e){let t=String(e),n=/^(-?)(\d)(?:\.(\d+))?e([+-]\d+)$/.exec(t);if(!n)return t;let r=n[1],i=n[2],a=n[3]||``,o=+n[4];if(o>=0){let e=o-a.length;return e>=0?r+i+a+`0`.repeat(e):r+i+a.slice(0,o)+`.`+a.slice(o)}return r+`0.`+`0`.repeat(-o-1)+i+a}var us=86400;function ds(e,t,n,r){let i=``,a=``,o=``,s=``,c=``,l=``,u=0,d=0;if(typeof e==`bigint`){if(!(e<=2**53-1&&e>=-(2**53-1)))return n.bigintErrorNumber?String(e):n.overflow;d=e=Number(e)}else d=Math.trunc(e);let f=0,p=0,m=1,h=0,g=0,_=0,v=0,y=0,b=0,x=0,S=r||bo;if(!t.text&&isFinite(t.scale)&&t.scale!==1&&(e=function(e){if(e===0)return e;let t=Math.ceil(Math.log10(e<0?-e:e)),n=10**(16-Math.floor(t));return isFinite(n)?Math.round(e*n)/n:0}(e*t.scale)),t.exponential){let n=Math.abs(e);n&&(u=es(n,t.int_max)),e&&!t.integer&&u++,n=ts(n,u),t.int_max===1&&jo(n,t.frac_max)===10&&(n=1,u++),e=e<0?-n:n,i+=Math.abs(u)}if(e=ss(e),t.integer){let n=Math.abs(cs(e,t.fractions?1:t.frac_max));l+=n<1?``:ls(Math.floor(n))}let C=n.grouping[0]??3,w=n.grouping[1]??C;t.dec_fractions&&(c=ls(cs(e,t.frac_max)).split(`.`)[1]||``);let T=!t.error&&(t.num_p.includes(`0`)||t.den_p.includes(`0`)),E=T;if(t.fractions){E=T||!!(e%1);let n=Math.abs(t.integer?e%1:e);if(n)if(E=!0,t.denominator&&isFinite(t.denominator))s+=t.denominator,o+=jo(n*t.denominator),o===`0`&&(o=``,s=``,E=T);else{let e=function(e,t=2,n=2){let r=e<0?-1:1,i=10**(t||2),a=10**(n||2),o,s,c=Math.abs(e),l=0,u=0,d=0,f=1;if((e=c)%1==0)s=[e*r,1];else if(e<1e-19)s=[r,0x8ac7230489e80000];else if(e>0x8ac7230489e80000)s=[0x8ac7230489e80000*r,1];else{do if(c=1/(c-Math.floor(c)),o=f,f=f*Math.floor(c)+l,l=o,u=d,d=Math.floor(e*f+.5),d>=i||f>=a)return[r*u,l];while(Math.abs(e-d/f)>=1e-13&&c!==Math.floor(c));s=[r*d,f]}return s}(n,1/0,t.den_max);o+=e[0],s+=e[1],t.integer&&o===`0`&&(o=``,s=``,E=T)}else e||t.integer||(E=!0,o=`0`,s=`1`);!t.integer||E||Math.trunc(e)||(l=`0`)}if(t.date){d=Math.trunc(e);let r=us*(e-d);if(f=Math.floor(r),b=r-f,Math.abs(b)<1e-6?b=0:b>.9999&&(b=0,f+=1,f===us&&(f=0,d+=1,x=1)),b){let e=512&t.date||256&t.date||128&t.date;(e===512&&b>.9995||e===256&&b>.995||e===128&&b>.95||!e&&b>=.5)&&(f++,b=0,f===us&&(f=0,d+=1,x=1))}if(d||t.date_system){let r=Po(x?d:e,t.date_system,n.leap1900);p=r[0],m=r[1],h=r[2]}if(f){let e=f<0?us+f:f;y=Math.floor(e)%60,v=Math.floor(e/60)%60,_=Math.floor(e/60/60)%60}if(g=(6+d)%7,t.date_eval&&(D=e,O=d+f/us,n.dateSpanLarge?D<-694324||O>=35830291:D<0||O>=2958466)){if(n.dateErrorThrows)throw Error(`Date out of bounds`);return n.dateErrorNumber?as(e<0?[S.negative]:[],0,e,S).join(``):n.overflow}}var D,O;let k=os(`?`,n.nbsp),A=e=>n.digitChar?n.digitChar+e:k,j=e=>n.digitChar&&e===`?`?n.digitChar+`0`:os(e,n.nbsp);u<0?a=`-`:t.exp_plus&&(a=`+`);let M=[],N=(e,t,n,r)=>{let i=!r&&e.length>t.length?n.length+e.length-t.length:n.length;e.length<t.length&&(r+=e.length-t.length);for(let t=0;t<i;t++)M.push(e[t+r]||j(n[t]));return i},P=!1,F=-1;for(let e=0,n=t.tokens.length;e<n;e++){let n=t.tokens[e];if(n.date&&/^(?:year|b-year|month|weekday|day)/.test(n.type||``)){F=e;break}}let I={int:0,frac:0,man:0,num:0,den:0};for(let u=0,x=t.tokens.length;u<x;u++){let x=t.tokens[u],T=x.type,D=x.num?x.num.length:0;if(T===`string`)x.rule?x.rule===`num`?E?M.push(x.value.replace(/ /g,k)):(t.num_min>0||t.den_min>0)&&M.push(x.value.replace(/./g,e=>A(e))):x.rule===`num+int`?E&&l?M.push(x.value.replace(/ /g,k)):t.den_min>0&&(l||t.num_min)&&M.push(x.value.replace(/./g,e=>A(e))):x.rule===`den`&&(E?M.push(x.value.replace(/ /g,k)):(t.den_min>0||t.den_min>0)&&M.push(x.value.replace(/./g,e=>A(e)))):M.push(x.value.replace(/ /g,k));else if(T===`space`)x.rule===`num+int`?(E||t.num_min||t.den_min)&&(l||t.num_min)&&M.push(k):M.push(k);else if(T===`error`)M.push(n.invalid);else if(T===`point`)M.push(t.date?x.value:S.decimal);else if(T===`general`)as(M,0,e,S);else if(T===`exp`)M.push(S.exponent);else if(T===`minus`)x.volatile&&t.date||x.volatile&&(e>=0||typeof e!=`number`)||(x.volatile&&!t.fractions&&(t.integer||t.dec_fractions)?(e<0&&l&&l!==`0`||c)&&M.push(S.negative):M.push(S.negative));else if(T===`plus`)M.push(S.positive);else if(T===`text`)M.push(e);else if(T===`fill`)n.fillChar&&M.push(n.fillChar,x.value);else if(T===`skip`)n.skipChar?M.push(n.skipChar,x.value):M.push(n.nbsp?`\xA0`:` `);else if(T===`div`)E?M.push(`/`):t.num_min>0||t.den_min>0?M.push(A(`/`)):M.push(os(`#`,n.nbsp));else if(T===`int`)if(t.int_pattern.length===1){let e=t.int_p,n=``;for(let r=Math.max(t.int_min,l.length);r>0;r--){let i=l.charAt(l.length-r),a=i?``:e.charAt(e.length-r)||e[0],o=``;if(t.grouping){let e=r-1-C;e>=0&&!(e%w)&&(o=i||a===`0`?S.group:A(S.group))}n+=(i||j(a))+o}M.push(n)}else I.int+=N(l,t.int_p,x.num,I.int);else if(T===`frac`){let e=I.frac;for(let t=0;t<D;t++)M.push(c[t+e]||j(x.num[t]));I.frac+=D}else if(T===`man`)I[T]||I.man||M.push(a),I.man+=N(i,t.man_p,x.num,I.man);else if(T===`num`)I.num+=N(o,t.num_p,x.num,I.num);else if(T===`den`){let e=I.den;for(let t=0;t<D;t++){let n=s[t+e];if(!n){let e=x.num[t];`123456789`.includes(e)||P&&e===`0`?(P=!0,n=A(e)):n=P||t!==D-1||e!==`0`||s?j(e):`1`}M.push(n)}I.den+=D}else if(T===`year`)p<0&&M.push(S.negative),M.push(String(Math.abs(p)).padStart(4,`0`));else if(T===`year-short`){let e=p%100;M.push(e<10?`0`:``,e)}else if(T===`month`)M.push(x.pad&&m<10?`0`:``,m);else if(T===`monthname-single`)t.date_system===6?M.push(S.mmmm6[m-1].charAt(0)):M.push(S.mmmm[m-1].charAt(0));else if(T===`monthname-short`)t.date_system===6?M.push(S.mmm6[m-1]):M.push(S.mmm[m-1]);else if(T===`monthname`)t.date_system===6?M.push(S.mmmm6[m-1]):M.push(S.mmmm[m-1]);else if(x.type===`weekday-short`)M.push(S.ddd[g]);else if(T===`weekday`)M.push(S.dddd[g]);else if(T===`day`)M.push(x.pad&&h<10?`0`:``,h);else if(T===`hour`){let e=_%t.clock||(t.clock<24?t.clock:0);M.push(x.pad&&e<10?`0`:``,e)}else if(T===`min`)M.push(x.pad&&v<10?`0`:``,v);else if(T===`sec`)M.push(x.pad&&y<10?`0`:``,y);else if(T===`subsec`){M.push(S.decimal);let e=b.toFixed(t.sec_decimals);M.push(e.slice(2,2+x.decimals))}else if(T===`ampm`){let e=_<12?0:1;x.short&&!r?M.push(`AP`[e]):M.push(S.ampm[e])}else if(T===`hour-elap`){e<0&&M.push(S.negative);let t=F!==-1&&u>F?12:24*d+Math.floor(Math.abs(f)/3600);M.push(String(Math.abs(t)).padStart(x.pad,`0`))}else if(T===`min-elap`){e<0&&M.push(S.negative);let t=F!==-1&&u>F?720:1440*d+Math.floor(Math.abs(f)/60);M.push(String(Math.abs(t)).padStart(x.pad,`0`))}else if(T===`sec-elap`){e<0&&M.push(S.negative);let t=F!==-1&&u>F?43200:d*us+Math.abs(f);M.push(String(Math.abs(t)).padStart(x.pad,`0`))}else if(T===`b-year`)M.push(p+543);else if(T===`b-year-short`){let e=(p+543)%100;M.push(e<10?`0`:``,e)}}return M.join(``)}var fs=$o([{type:La,value:`@`,raw:`@`}]);function ps(e,t){for(let n=0;n<3;n++){let r=t[n];if(r){let t;if(r.condition){let n=r.condition[0],i=r.condition[1];n===`=`?t=e===i:n===`>`?t=e>i:n===`<`?t=e<i:n===`>=`?t=e>=i:n===`<=`?t=e<=i:n===`<>`&&(t=e!==i)}else t=!0;if(t)return r}}}function ms(e){return!!(e[0]?.percent||e[1]?.percent||e[2]?.percent||e[3]?.percent)}function hs(e){return!!(e[0]?.date||e[1]?.date||e[2]?.date||e[3]?.date)}function gs(e){let[t,n,r,i]=e;return!(t&&!t.generated||n&&!n.generated||r&&!r.generated||!i?.text||i.generated)}var _s={text:15,datetime:10.8,date:10.8,time:10.8,percent:10.6,currency:10.4,grouped:10.2,scientific:6,number:4,fraction:2,general:0,error:0},vs=[[`DMY`,1],[`DM`,2],[`MY`,3],[`MDY`,4],[`MD`,5],[`hmsa`,6],[`hma`,7],[`hms`,8],[`hm`,9]],ys=[[Oa,/^General/i,0],[ka,/^#/,0],[Aa,/^0/,0],[ja,/^\?/,0],[Ma,/^\//,0],[Ia,/^;/,0],[La,/^@/,0],[Ra,/^\+/,0],[za,/^-/,0],[Ba,/^\./,0],[Va,/^ /,0],[Ha,/^%/,0],[Ua,/^[1-9]/,0],[Wa,/^(?:B[12])/i,0],[Ga,/^B$/,0],[Ka,/^(?:[hH]+|[mM]+|[sS]+|[yY]+|[bB]+|[dD]+|[gG]+|[aA]{3,}|e+)/,0],[qa,/^(?:\[(h+|m+|s+)\])/i,1],[Ja,/^\[(<[=>]?|>=?|=)\s*(-?[.\d]+(?:[eE][+-]?\d+)?)?\]/,[1,2]],[Ya,/^\[(DBNum[0-4]?\d)\]/i,1],[Xa,/^\[(NatNum[0-4]?\d)\]/i,1],[Za,/^\[\$([^\]]+)\]/,1],[Qa,/^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*\d+)\]/i,1],[$a,/^\[([^\]]+)\]/,1],[eo,/^(?:AM\/PM|am\/pm|A\/P)/,0],[to,/^\\(.)/,1],[no,/^"([^"]*?)"/,1],[ro,/^_(\\.|.)/,1],[`exp`,/^[Ee]([+-])/,1],[io,/^\*(\\.|.)/,1],[ao,/^[()]/,0],[Ga,/^[EÈÉÊËèéêëĒēĔĕĖėĘęĚěȄȅȆȇȨȩNnÑñŃńŅņŇňǸǹ["*/\\_]/,0],[oo,/^./,0]],bs=e=>{let t=(e||`\0`).charCodeAt(0);return t===63||t===35||t>=48&&t<=57};function xs(e){let t=0,n=[],r=[];for(;t<e.length;){let i=e.slice(t),a=0,o=/^(,+)(.)?/.exec(i);if(o){let i=o[1];a=i.length;let s=e[t-1]||``,c=!1,l=!1;bs(s)?(c=!0,l=!0):s===`.`&&(l=!0);let u=o[2]||``;if(!c||u&&u!==`;`||(c=!1),l&&bs(u)&&(l=!1),c&&!l)n.push({type:Na,value:`,`,raw:i});else if(!c&&l)n.push({type:Pa,value:`,`,raw:i});else if(c&&l){let e={type:Pa,value:`,`,raw:i};n.push(e),r.push(e)}else n.push({type:Fa,value:`,`,raw:i})}else{let e;for(let[t,r,o]of ys){let s=r.exec(i);if(s){e={type:t,value:Array.isArray(o)?o.map(e=>s[e]):s[o||0],raw:s[0]},n.push(e),a=s[0].length;break}}r.length&&e.raw===`;`&&(r.length=0),r.length&&e.raw===`.`&&(r.length=0),r.length&&bs(e.raw)&&(r.forEach(e=>e.type=Na),r.length=0)}if(!a){let e=i[0];a=1,n.push({type:oo,value:e,raw:e})}t+=a}return n}var Ss=e=>{let[t,n]=e.condition??[];n<0&&(t===`<`||t===`<=`||t===`=`)||n===0&&t===`<`||e.tokens.unshift({type:`minus`,volatile:!0})},Cs=(e,t=null)=>{let n={};for(let t in e)Array.isArray(e[t])?n[t]=[...e[t]]:n[t]=e[t];return t&&n.tokens.unshift(t),n.generated=!0,n},ws=Object.create({});function Ts(e,t=!1){e||=`General`;let n=ws[e];if(!n)try{n=function(e){let t=[],n,r=!1,i=null,a=0,o=!1,s=0,c=0,l=xs(e);do{if(o=$o(l),(o.date||o.general)&&(o.int_pattern.length||o.frac_pattern.length||o.scale!==1||o.text))throw Error(`Illegal format`);if(o.condition&&(c++,r=!0),o.text){if(i)throw Error(`Unexpected partition`);i=o}o.locale&&(n=_o(o.locale)),t.push(o),a=+(l[o.tokensUsed]?.type===`break`),l=l.slice(o.tokensUsed+a),s++}while(a&&s<4&&c<3);if(a)throw Error(`Unexpected partition`);if(c>2)throw Error(`Unexpected condition`);let u=t[3];if(u&&(u.int_pattern.length||u.frac_pattern.length||u.date))throw Error(`Unexpected partition`);if(r){t[0].condition||(t[0].condition=[`>`,0]);let e=t.length;if(e===1&&(t[1]=$o(xs(`General`)),t[1].generated=!0),e<3){let e=t[0],n=t[1];if(Ss(e),n.condition)Ss(n);else{let t=e.condition;(t[0]===`=`||t[1]>=0&&(t[0]===`>`||t[0]===`>=`))&&n.tokens.unshift({type:`minus`,volatile:!0})}}else t.forEach(Ss)}else{if(t.length<4&&i)for(let e=0,n=t.length;e<n;e++)t[e]===i&&t.splice(e,1);t.length<1&&i&&(t[0]=$o(xs(`General`)),t[0].generated=!0);let e=t.length===1?t[0].color:void 0;if(t.length<2&&t.push(Cs(t[0],{type:`minus`,volatile:!0})),t.length<3&&t.push(Cs(t[0])),t.length<4)if(i)t.push(i);else{let n=$o(xs(`@`));n.generated=!0,n.color=e,t.push(n)}t[0].condition=[`>`,0],t[1].condition=[`<`,0],t[2].condition=null}return{pattern:e,partitions:t,locale:n}}(e),ws[e]=n}catch(r){if(t)throw r;let i={tokens:[{type:`error`}],error:r.message};n={pattern:e,partitions:[i,i,i,i],error:r.message,locale:null}}return n}function Es(e,t,n={}){let r=Object.assign({},Ao,n),i=Ts(e,r.throws);return function(e,t,n){let r=t.partitions,i=vo(t.locale||n.locale),a=r[3]?r[3]:fs;if(typeof e==`boolean`&&(e=(i||bo).bool[+!e]),e==null)return``;let o=typeof e==`bigint`;if(typeof e!=`number`&&!o)return ds(e,a,n,i);if(!o&&!isFinite(e)){let t=i||bo;return isNaN(e)?t.nan:(e<0?t.negative:``)+t.infinity}let s=ps(e,r);return s?ds(e,s,n,i):n.overflow}(Lo(t,r)??t,i,r)}function Ds(e,t,n){let r=Object.assign({},Ao,n),i=Ts(e,r.throws);return function(e,t,n){let r=t.partitions,i=r[3],a=null;return typeof e!=`number`&&typeof e!=`bigint`||!isFinite(e)||(i=ps(e,r)),i?.color&&(a=i.color),a&&typeof a==`number`&&n.indexColors&&(a=so[a-1]||`#000`),a}(Lo(t,r)??t,i,r)}function Os(e,t={}){let n=Ts(e,!1);return n.info||=function(e,t=null){let[n,r]=e,i=n.frac_max,a={type:`general`,isDate:hs(e),isText:gs(e),isPercent:ms(e),maxDecimals:n.general?9:i,scale:n.scale??1,color:0,parentheses:0,grouped:+!!n.grouping},o=!a.isDate&&!a.isText&&!n.error&&n.tokens.some(e=>e.type===`string`&&(t?e.value===t:lo.test(e.value))),s=`G`,c=i>=0?Math.min(15,i):``,l=``,u=``;if(r?.color&&(u=`-`,a.color=1),n.parens&&(l=`()`,a.parentheses=1),o)s=`C`,a.type=`currency`;else if(n.error)a.type=`error`,a.maxDecimals=0;else if(a.isDate){let e=0,t=0,r=``;n.tokens.forEach(n=>{let i=n.type;/^(b-)?year/.test(i)?(r+=`Y`,t++):i.startsWith(`month`)?(r+=`M`,t++):/^(week)?day/.test(i)?(r+=`D`,t++):i!==`hour`&&i!==`min`&&i!==`sec`&&i!==`ampm`||(r+=i[0],e++)}),a.type=`date`,t&&e?a.type=`datetime`:!t&&e&&(a.type=`time`);let i=vs.find(e=>r.startsWith(e[0]));s=i?`D`:`G`,c=i?i[1]:``}else a.isText?(s=`G`,a.type=`text`,c=``,a.maxDecimals=0):n.general?(s=`G`,a.type=`general`,c=``):n.fractions?(s=`G`,a.type=`fraction`,c=``):n.exponential?(s=`S`,a.type=`scientific`):a.isPercent?(s=`P`,a.type=`percent`):n.grouping?(s=`,`,a.type=`grouped`):(n.int_max||i)&&(s=`F`,a.type=`number`);return a.code=s+c+u+l,a.level=_s[a.type],Object.freeze(a)}(n.partitions,t?.currency),n.info}Object.freeze({AMPM:eo,BREAK:Ia,CALENDAR:Wa,CHAR:oo,COLOR:Qa,COMMA:Fa,CONDITION:Ja,DATETIME:Ka,DBNUM:Ya,DIGIT:Ua,DURATION:qa,ERROR:Ga,ESCAPED:to,EXP:`exp`,FILL:io,GENERAL:Oa,GROUP:Na,HASH:ka,LOCALE:Za,MINUS:za,MODIFIER:$a,NATNUM:Xa,PAREN:ao,PERCENT:Ha,PLUS:Ra,POINT:Ba,QMARK:ja,SCALE:Pa,SKIP:ro,SLASH:Ma,SPACE:Va,STRING:no,TEXT:La,ZERO:Aa});var ks,As=`\\s*([-]?[0-9e]*[.]?[0-9]+)`,js=RegExp(`^rgb\\(${As},${As},${As}\\)$`,`i`),Ms=RegExp(`^rgba\\(${As},${As},${As},${As}\\)$`,`i`),Ns=RegExp(`^lrgb\\(${As},${As},${As}\\)$`,`i`),Ps=RegExp(`^lrgba\\(${As},${As},${As},${As}\\)$`,`i`),Fs=RegExp(`^hsl\\(${As},${As},${As}\\)$`,`i`),Is=RegExp(`^hsla\\(${As},${As},${As},${As}\\)$`,`i`),Ls=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),Rs=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),zs=RegExp(`^index(\\d+)$`,`i`),Bs=(e,t,n)=>[parseFloat(e),parseFloat(t),parseFloat(n)],Vs=(e,t=255)=>{let n=[...e];for(var r=0;r<e.length;r++)n[r]=e[r]/t;return n},Hs=(e,t=255)=>{let n=[...e];for(var r=0;r<e.length;r++)n[r]=e[r]*t;return n},Us=(e,t=0)=>{let r=[...e];for(var i=0;i<e.length;i++)n.CommonUtils.roundAccurately(e[i],t+8)%1==.5?r[i]=Math.floor(e[i]):r[i]=n.CommonUtils.roundAccurately(e[i],t);return r},Ws=(e,t=!0)=>{let n=[...e],r=t?1:255;for(var i=0;i<e.length;i++)n[i]=Math.max(0,Math.min(r,e[i]));return n},Gs=e=>Math.max(0,Math.min(1,e)),Ks=e=>((e%=360)<0&&(e-=360),e),qs=e=>{let t=[...e];for(var n=0;n<e.length;n++)t[n]=Ys(e[n]);return t},Js=e=>{let t=[...e];for(var n=0;n<e.length;n++)t[n]=Xs(e[n]);return t},Ys=e=>e<.04045?e/12.92:((e+.055)/1.055)**2.4,Xs=e=>e<.0031308?12.92*e:1.055*e**(1/2.4)-.055,Zs=e=>{let t=e[0],n=e[1],r=e[2];t%=360,t/=360,n/=100,r/=100;let i=r<.5?r*(1+n):r+n-n*r,a=2*r-i;return[Math.max(0,Qs(a,i,t+1/3)),Math.max(0,Qs(a,i,t)),Math.max(0,Qs(a,i,t-1/3))]},Qs=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,6*n<1?e+6*(t-e)*n:2*n<1?t:3*n<2?e+6*(t-e)*(2/3-n):e),$s=e=>{let t=e[0],n=e[1],r=e[2],i=Math.min(t,Math.min(n,r)),a=Math.max(t,Math.max(n,r)),o=0;a===i?o=0:a===t?o=(60*(n-r)/(a-i)+360)%360:a===n?o=60*(r-t)/(a-i)+120:a===r&&(o=60*(t-n)/(a-i)+240);let s=(a+i)/2,c=0;return c=a===i?0:s<=.5?(a-i)/(a+i):(a-i)/(2-a-i),[o,100*c,100*s]},ec=0,tc=1,nc=2,rc=0,ic=1,ac=2,oc=0,sc=1,cc=2,lc=(e,t)=>{let n=t/100;return((e,t)=>{let n=qs(e);n[0]=t(n[0],n),n[1]=t(n[1],n),n[2]=t(n[2],n);let r=Js(n);return r=Ws(r),r})(e,(e,t)=>e*n)},uc=2.55,dc=(e,t)=>{let r=$s(e),i=r[2];var a,o;r[2]=n.CommonUtils.roundAccurately((a=i,(o=t)>0?(a*uc*(1-o)+(255-255*(1-o)))/uc:o<0?a*uc*(1+o)/uc:a),3);let s=Zs(r);return s=Ws(s),s},fc=(e,t)=>{let n=qs(e),r=t/100;for(var i=0;i<3;i++)n[i]=n[i]*r+(1-r);let a=Js(n);return a=Ws(a),a},pc=(e,t,n)=>{let r=$s(t),i=n/1;e===ec&&(i=Ks(n)),r[e]=i;let a=Zs(r);return a=Ws(a),a},mc=(e,t,n)=>{let r=$s(t);if(e===ec){let e=n/360;r[ec]=360*(r[ec]/360+e),r[ec]%=360,r[ec]<0&&(r[ec]-=360)}else{let t=n/.1;r[e]=.1*(r[e]/.1+t)}let i=Zs(r);return i=Ws(i),i},hc=(e,t,n)=>{let r=$s(t),i=n/100;r[e]=r[e]*i,e===ec&&(r[ec]=Ks(r[ec]));let a=Zs(r);return a=Ws(a),a},gc=(e,t,n,r)=>{let i=qs(t),a=n/100;r===oc?i[e]=a:r===sc?i[e]+=a:r===cc&&(i[e]*=a);let o=Js(i);return o=Ws(o),o},_c=e=>{let t=qs(e),n=.213*t[rc]+.715*t[ic]+.072*t[ac];t[0]=n,t[1]=n,t[2]=n;let r=Js(t);return r=Ws(r),r},vc=e=>{let t=$s(e);t[ec]+=180,t[ec]%=360,t[ec]<0&&(t[ec]-=360);let n=Zs(t);return n=Ws(n),n},yc=(e,t=!0)=>{let n=t?qs(e):[...e],r=t?1:255;return n[0]=r-n[0],n[1]=r-n[1],n[2]=r-n[2],t&&(n=Js(n)),n=Ws(n,t),n},bc=e=>{let t=[0,0,0];return t[0]=Xs(e[0]),t[1]=Xs(e[1]),t[2]=Xs(e[2]),Ws(t)},xc=e=>{let t=[0,0,0];return t[0]=Ys(e[0]),t[1]=Ys(e[1]),t[2]=Ys(e[2]),Ws(t)},Sc=(e,t,n,r=null)=>{let i=e=>{let t=e.toString(16);return t.length===1?`0`+t:t};return(r===null?``:i(Math.round(255*r)))+i(Number(e)).toUpperCase()+i(Number(t)).toUpperCase()+i(Number(n)).toUpperCase()},Cc=.2126,wc=.7152,Tc=.0722;(function(e){e.RGBA=class{constructor(e,t,n,r=1){this._private={red:e,green:t,blue:n,alpha:r}}get red(){return this._private.red}get green(){return this._private.green}get blue(){return this._private.blue}get alpha(){return this._private.alpha??1}toString(e=!0){return e&&this._private.alpha!==null?`rgba(${this.red},${this.green},${this.blue},${this.alpha})`:`rgb(${this.red},${this.green},${this.blue})`}isEqual(e){return!!e&&e.red===this.red&&e.green===this.green&&e.blue===this.blue&&e.alpha===this.alpha}isAlmostEqual(e){if(!e)return!1;let t=1.5;return!(Math.abs(e.red-this.red)>t)&&!(Math.abs(e.green-this.green)>t)&&!(Math.abs(e.blue-this.blue)>t)&&!(Math.abs(e.alpha-this.alpha)>t)}},e.HSLA=class{constructor(e,t,n,r){this._private={hue:e,sat:t,lum:n,alpha:r}}get hue(){return this._private.hue}get sat(){return this._private.sat}get lum(){return this._private.lum}get alpha(){return this._private.alpha??1}toString(e=!0){return e&&this._private.alpha!==null?`hsla(${this.hue},${this.sat},${this.lum},${this.alpha})`:`hsl(${this.hue},${this.sat},${this.lum})`}isEqual(e){return!!e&&e.hue===this.hue&&e.sat===this.sat&&e.lum===this.lum&&e.alpha===this.alpha}isAlmostEqual(e){if(!e)return!1;let t=1.5;return!(Math.abs(e.hue-this.hue)>t)&&!(Math.abs(e.sat-this.sat)>t)&&!(Math.abs(e.lum-this.lum)>t)&&!(Math.abs(e.alpha-this.alpha)>t)}};class t extends ks.RGBA{toString(e=!0){return e&&this._private.alpha!==null?`#`+Sc(this.red,this.green,this.blue,this.alpha??1).toUpperCase():`#`+Sc(this.red,this.green,this.blue).toUpperCase()}}e.HEX=t})(ks||={});var Ec=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,Dc=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,Oc=function(e){if(!e)return null;e=e.replace(Ec,function(e,t,n,r){return t+t+n+n+r+r});let t=Dc.exec(e);return t?new ks.RGBA(parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)):null},kc=`000000.FFFFFF.FF0000.00FF00.0000FF.FFFF00.FF00FF.00FFFF.000000.FFFFFF.FF0000.00FF00.0000FF.FFFF00.FF00FF.00FFFF.800000.008000.000080.808000.800080.008080.C0C0C0.808080.9999FF.993366.FFFFCC.CCFFFF.660066.FF8080.0066CC.CCCCFF.000080.FF00FF.FFFF00.00FFFF.800080.800000.008080.0000FF.00CCFF.CCFFFF.CCFFCC.FFFF99.99CCFF.FF99CC.CC99FF.FFCC99.3366FF.33CCCC.99CC00.FFCC00.FF9900.FF6600.666699.969696.003366.339966.003300.333300.993300.993366.333399.333333`.split(`.`),Ac=new Map;for(let e=0;e<kc.length;e++)Ac.set(e,Oc(kc[e]));var jc=new Map([[64,`windowText`],[65,`window`],[80,`infoBk`],[81,`infoText`]]);function Mc(e){return jc.get(e)??null}function Nc(e){return Ac.get(e)??null}var Pc=Object.freeze({0:`General`,1:`0`,2:`0.00`,3:`#,##0`,4:`#,##0.00`,5:`$#,##0_);($#,##0)`,6:`$#,##0_);[Red]($#,##0)`,7:`$#,##0.00_);($#,##0.00)`,8:`$#,##0.00_);[Red]($#,##0.00)`,9:`0%`,10:`0.00%`,11:`0.00E+00`,12:`# ?/?`,13:`# ??/??`,14:`m/d/yy`,15:`d-mmm-yy`,16:`d-mmm`,17:`mmm-yy`,18:`h:mm AM/PM`,19:`h:mm:ss AM/PM`,20:`h:mm`,21:`h:mm:ss`,22:`m/d/yy h:mm`,23:`General`,24:`General`,25:`General`,26:`General`,27:`m/d/yyyy`,28:`m/d/yyyy`,29:`m/d/yyyy`,30:`m/d/yyyy`,31:`m/d/yyyy`,32:`h:mm:ss`,33:`h:mm:ss`,34:`h:mm:ss`,35:`h:mm:ss`,36:`m/d/yyyy`,37:`#,##0_);(#,##0)`,38:`#,##0_);[Red](#,##0)`,39:`#,##0.00_);(#,##0.00)`,40:`#,##0.00_);[Red](#,##0.00)`,41:`_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)`,42:`_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)`,43:`_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)`,44:`_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)`,45:`mm:ss`,46:`[h]:mm:ss`,47:`mm:ss.0`,48:`##0.0E+0`,49:`@`,50:`m/d/yyyy`,51:`m/d/yyyy`,52:`m/d/yyyy`,53:`m/d/yyyy`,54:`m/d/yyyy`,55:`m/d/yyyy`,56:`m/d/yyyy`,57:`m/d/yyyy`,58:`m/d/yyyy`,59:`00000`,60:`0.00`,61:`#,##0`,62:`#,##0.00`,63:`$#,##0_);($#,##0)`,64:`$#,##0_);[Red]($#,##0)`,65:`$#,##0.00_);($#,##0.00)`,66:`$#,##0.00_);[Red]($#,##0.00)`,67:`0%`,68:`0.00%`,69:`# ?/?`,70:`# ??/??`,71:`m/d/yyyy`,72:`m/d/yyyy`,73:`d-mmm-yy`,74:`d-mmm`,75:`mmm-yy`,76:`h:mm`,77:`h:mm:ss`,78:`m/d/yyyy h:mm`,79:`mm:ss`,80:`[h]:mm:ss`,81:`mm:ss.0`}),Fc=Object.freeze({"en-US":{14:`m/d/yyyy`,22:`m/d/yyyy h:mm`},"en-GB":{14:`dd/mm/yyyy`,15:`dd-mmm-yy`,16:`dd-mmm`,20:`hh:mm`,21:`hh:mm:ss`,22:`dd/mm/yyyy hh:mm`},"de-DE":{14:`dd.mm.yyyy`,15:`dd. mmm yy`,16:`dd. mmm`,17:`mmm yy`,20:`hh:mm`,21:`hh:mm:ss`,22:`dd.mm.yyyy hh:mm`},"fr-FR":{14:`dd/mm/yyyy`,15:`dd-mmm-yy`,16:`dd-mmm`,20:`hh:mm`,21:`hh:mm:ss`,22:`dd/mm/yyyy hh:mm`},"es-ES":{14:`dd/mm/yyyy`,15:`dd-mmm-yy`,16:`dd-mmm`,22:`dd/mm/yyyy h:mm`},"ja-JP":{14:`yyyy/mm/dd`,15:`dd-mmm-yy`,16:`dd-mmm`,22:`yyyy/mm/dd h:mm`}}),Ic=(()=>{let e=new Map;for(let t of Object.keys(Fc)){let n=t.split(`-`)[0];e.has(n)||e.set(n,t)}return e})();function Lc(e,t){let n=t??`en-US`;return(Fc[n]??Fc[Ic.get(n.split(`-`)[0])??``])?.[e]}function Rc(e){return Pc[e]}function zc(e){return typeof e==`number`?Pc[e]??`General`:e}var Bc=(()=>{let e=new Map;for(let[t,n]of[[0,13],[15,21],[37,49]])for(let r=t;r<=n;r++)e.set(Pc[r],r);return e.set(`m/d/yyyy`,14),e.set(`m/d/yyyy h:mm`,22),e})(),Vc=e.n({DateUnit:()=>Hc,nowWithPrecision:()=>Uc}),Hc={Day:`d`,Weekday:`wd`,Month:`m`,Year:`y`};function Uc(e=6e4){return new Date(Math.floor(Date.now()/e)*e)}var Wc=1462;function Gc(e){let t=(6+Math.floor(e))%7;return t===0?7:t}function Kc(e,t,n){let r=function(e,t,n){let r=Math.floor((14-t)/12),i=e+4800-r,a=t+12*r-3;return n+Math.floor((153*a+2)/5)+365*i+Math.floor(i/4)-Math.floor(i/100)+Math.floor(i/400)-32045}(e,t,1)-2415019;return(r<=60?r-1:r)+n-1}function qc(e,t,n,r=0,i=0,a=0,o=0){let s=3600*r+60*i+a+o/1e3,c=Math.floor(s/86400);return Kc(e,t,n)+c+(s-86400*c)/86400}function Jc(e){let t=86400*(e-Math.floor(e)),n=t-Math.floor(t);return(n>.9999||n<1e-6)&&(n=0),Math.round(1e3*n)}var Yc=.5/86400;function Xc(e,t=!1){return typeof e==`object`&&e&&(e instanceof Date||Object.prototype.toString.call(e)===`[object Date]`)?!isNaN(e.getTime()):!t&&typeof e==`number`&&!(e<0||e>2958465)}function Zc(e,t){return t===2?e%4!=0||e%100==0&&e%400!=0?28:29:t===4||t===6||t===9||t===11?30:31}var Qc={year:0,month:0,day:0,hour:0,minute:0,second:0,millis:0,dow:0,serial:0};function $c(e,t=!1){let n=cl(e,t,Qc);return n?12*n.year+(n.month-1):NaN}function el(e,t=!1){let n=cl(e,t,Qc);return n?n.day:NaN}function tl(e,t=!1){let n=cl(e,t,Qc);return!!n&&n.day===Zc(n.year,n.month)}function nl(e,t,n=!1,r=!1){let i=cl(e,r,Qc);if(!i)return NaN;let a=12*i.year+(i.month-1)+t,o=Math.floor(a/12),s=a-12*o+1,c=Zc(o,s),l=Kc(o,s,n?c:Math.min(i.day,c));return(r?l-Wc:l)+(e-Math.floor(e))}var rl=e=>((e-1)%7+7)%7,il=e=>{let t=rl(e);return t===0||t===6};function al(e,t=!1){return il(Math.floor(e)+(t?Wc:0))}function ol(e,t=!1){let n=Math.floor(e)+(t?Wc:0);for(;il(n);)n++;let r=rl(n)-1;return(n-r-2)/7*5+r}function sl(e,t,n=!1){let r=Math.floor(e),i=r+(n?Wc:0);if(t>0)for(;il(i);)i--;else for(;il(i);)i++;let a=rl(i)-1,o=(i-a-2)/7*5+a+t,s=Math.floor(o/5);return 7*s+2+(o-5*s)-(n?Wc:0)+(e-r)}function cl(e,t=!1,n){if(typeof e!=`number`||isNaN(e)||e<0)return null;let r=t?e+Wc:e,i=r+Yc,a=Math.floor(i);if(a>2958465)return null;let[o,s,c]=Ro(a,{leap1900:!0}),l=Math.floor(86400*(i-a)),u=l/3600|0,d=(l/60|0)%60,f=l%60,p=Jc(r),m=Gc(a),h=!0===n?ll:n||void 0;return h?(h.year=o,h.month=s,h.day=c,h.hour=u,h.minute=d,h.second=f,h.millis=p,h.dow=m,h.serial=e,h):{year:o,month:s,day:c,hour:u,minute:d,second:f,millis:p,dow:m,serial:e}}var ll={year:0,month:0,day:0,hour:0,minute:0,second:0,millis:0,dow:0,serial:0};function ul(e,t=!1){if(!e)return null;let n=qc(e.year,e.month,e.day,e.hour,e.minute,e.second,e.millis);return t?n-Wc:n}function dl(e,t=!1){if(typeof e!=`number`||isNaN(e)||e<0)return null;let n=t?e+Wc:e;if(n>2958465)return null;let[r,i,a,o,s,c]=Ro(n,{leap1900:!0});return new Date(r,i-1,a,o,s,c,Jc(n))}function fl(e,t=!1){if(isNaN(e))return null;let n=qc(e.getFullYear(),e.getMonth()+1,e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds());return t?n-Wc:n}var pl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),ml=e=>e.map(pl).join(`|`),hl=/MMMM|MMM|MM|M|dd|d|yyyy|yyy|EEEE|EEE|[^MdyE]+/g,gl=``;function _l(e,t,n){let r=t.regex.exec(e);if(!r)return null;let i={};for(let e=0;e<t.fields.length;e++){let a=r[e+1];switch(t.fields[e]){case`monthName`:{let e=n.get(a.toLowerCase());if(!e)return null;i.month=e;break}case`monthNum`:{let e=parseInt(a,10);if(e<1||e>12)return null;i.month=e;break}case`day`:{let e=parseInt(a,10);if(e<1||e>31)return null;i.day=e;break}case`year`:i.year=parseInt(a,10)}}return i.month===void 0?null:i}var vl=new Map;function yl(e){let t=vl.get(e);if(t)return t;let{date:n}=pt(e),r=new Map,i=[];for(let e=0;e<12;e++){let t=n.monthsWide[e],a=[n.monthsAbbr[e],t];for(let e=3;e<t.length;e++)a.push(t.slice(0,e));for(let t of a){let n=t.toLowerCase();r.has(n)||(r.set(n,e+1),i.push(t))}}i.sort((e,t)=>t.length-e.length);let a={mmm:i,mmmm:i,ddd:n.weekdaysAbbr,dddd:n.weekdaysWide},o=function(e){let t=e,n=[];for(let e=0;e<t.length;e++){let r=t[e][0],i=!r.startsWith(`~`);i||(r=r.slice(1));let a=/yyy(?!y)/.test(r),o=r.indexOf(`yyyy`)>-1,s=r.indexOf(`.`)>-1,c=r.indexOf(`-`)>-1;n.push({parseFormat:r,numberFormat:t[e][1],todaysYear:!a&&!o,windowYear:!o,excelOnly:i,containsDot:s,containsDash:c}),a&&n.push({parseFormat:r.replace(/yyy/g,`yyyy`),numberFormat:t[e][1],todaysYear:!1,windowYear:!1,excelOnly:i,containsDot:s,containsDash:c})}return n}([(s=function(e){let t=[];for(let n of e){let e=n===`d`||n===`D`?`d`:n===`M`||n===`L`?`M`:n===`y`||n===`Y`?`y`:null;e&&!t.includes(e)&&t.push(e)}let n=t.indexOf(`d`),r=t.indexOf(`M`);return{dayFirst:n!==-1&&r!==-1&&n<r,yearFirst:t[0]===`y`}}(n.short)).dayFirst?[`d-MM`,`d-mmm`]:[`MM-d`,`d-mmm`],[`MM-yyy`,`mmm-yy`],[`M-yyy`,`mmm-yy`],s.dayFirst?[`d-M-yyy`,`Short Date`]:[`M-d-yyy`,`Short Date`],[`yyyy-M-d`,`Short Date`],[`d.MMM`,`d-mmm`],[`d.MMMM`,`d-mmm`],[`d.MMM.yyy`,`d-mmm-yy`],[`d.MMMM.yyy`,`d-mmm-yy`],[`MMM.d`,`d-mmm`],[`MMMM.d`,`d-mmm`],[`MMM.yyy`,`mmm-yy`],[`MMMM.yyy`,`mmm-yy`],[`MMM dd, yyy`,`d-mmm-yy`],[`MMMM dd, yyy`,`d-mmm-yy`],[`~EEE, MMMM dd, yyy`,`[$-x-sysdate]ddd, mmmm dd, yyyy`],[`~EEEE, MMMM dd, yyy`,`[$-x-sysdate]dddd, mmmm dd, yyyy`]]);var s;let c=o.map(e=>function(e,t){let n=[],r=`^`;for(let i of e.match(hl)??[])switch(i){case`MMMM`:n.push(`monthName`),r+=`(${ml(t.mmmm)})`;break;case`MMM`:n.push(`monthName`),r+=`(${ml(t.mmm)})`;break;case`MM`:case`M`:n.push(`monthNum`),r+=`(\\d{1,2})`;break;case`dd`:case`d`:n.push(`day`),r+=`(\\d{1,2})`;break;case`yyyy`:n.push(`year`),r+=`(\\d{3,4})`;break;case`yyy`:n.push(`year`),r+=`(\\d{1,2})`;break;case`EEEE`:n.push(`weekday`),r+=`(${ml(t.dddd)})`;break;case`EEE`:n.push(`weekday`),r+=`(${ml(t.ddd)})`;break;default:r+=pl(i.replaceAll(`.`,gl))}return{regex:RegExp(r+`$`,`i`),fields:n}}(e.parseFormat,a)),l=function(e){let t=e.match(/[^a-zA-Z]/);return t?t[0]:`/`}(n.short),u=l===`/`||l===`-`?``:pl(l),d=RegExp(`[/${u}]`,`g`),f=RegExp(`[-/ ${u}]`,`g`);return t={formats:o,compiled:c,monthByName:r,weekdaysAbbr:n.weekdaysAbbr,weekdaysWide:n.weekdaysWide,numericSep:d,wildcardSep:f},vl.set(e,t),t}var bl={year:0,month:1,day:0,hour:0,minute:0,second:0,millis:0};function xl(e,t){let n={...bl,...t},r=e.isDate1904();return n.year=r?1904:1900,r&&t.day===void 0&&(n.day=1),n.serial=ul(n,r),n.dow=Gc(r?n.serial+Wc:n.serial),n}var Sl=RegExp(`([0-9]{1,2})\\s*(P[M]?|A[M]?)\\s*$`,`i`),Cl=RegExp(`([0-9]+)\\s*\\:$`,`i`),wl=RegExp(`(\\s*[0-9]{1,2})\\s+(P[M]?|A[M]?)\\s*$`,`i`),Tl=new Map;function El(e,t,n=!1,r=!1){if(!t||t.trim().length<2||t.indexOf(`:`)===-1&&t.match(wl)===null)return null;let{mid:i,last:a,lastMeridiem:o,split:s}=function(e){let t=Tl.get(e);if(t)return t;let n=pl(e);return t={mid:RegExp(`(\\s*[0-9]{1,4})\\s*(${n}\\s*[0-9]+)?\\s*\\:`,`i`),last:RegExp(`(\\s*[0-9]{1,4})\\s*(${n}\\s*[0-9]*)?\\s*$`,`i`),lastMeridiem:RegExp(`(\\s*[0-9]{1,4})\\s*(${n}\\s*[0-9]*)?\\s+(P[M]?|A[M]?)\\s*$`,`i`),split:RegExp(`^(\\s*[0-9]{1,4}\\s*(?:${n}\\s*[0-9]*)?(?:\\s+[AP]M?)?)\\s+(\\S.*)$`,`i`)},Tl.set(e,t),t}(e.getLocaleProfile().decimal),c=null,l=null,u=null,d=!1,f=!1,p=`h:mm AM/PM`,m=[],h=t,g=null;do{let e=h.indexOf(`:`);e===-1?(m.push(h),h=null):(m.push(h.substring(0,e+1)),h=h.substring(e+1,h.length))}while(m.length<3&&h&&h.length>0);if((h?.length??0)>0)return null;let _=(e,t,n,r=!1)=>{let i=e.match(t);if(!i||r&&(i.index!==0||i[0].length!==e.length))return null;g===null&&(g=e.substring(0,i.index));let a=parseInt(i[1]);if(i[2]&&u===null){if(n){let e=parseFloat(i[2].substring(1,i[2].length));isNaN(e)||(l=e)}let e=parseFloat(`.`+i[2].substring(1,i[2].length).trim());isNaN(e)||(c=e),u=n}return a},v=(e,t,n=!1)=>{let r=e.match(t);if(!r||r.length!==3||n&&(r.index!==0||r[0].length!==e.length))return null;g===null&&(g=e.substring(0,r.index)),d=!0;let i=parseInt(r[1]);return f=r[2].charAt(0)===`p`||r[2].charAt(0)===`P`,i};m[m.length-1].trim().length===0&&m.pop();let y=[];if(m.length>0){let e=_(m[0],Cl,!1);if(e===null&&(e=v(m[0],Sl)),e===null)return null;y.push(e)}if(m.length>2){let e=_(m[1],i,!0,!0);if(e===null&&(e=v(m[0],wl)),e===null)return null;y.push(e)}let b=``;if(m.length>1){let e=m[m.length-1],t=e=>{let t=_(e,i,!1,!0);return t===null&&(t=_(e,a,!1,!0)),t===null&&(t=v(e,wl,!0)),t===null&&(t=(e=>{let t=e.match(o);if(!t||t.index!==0||t[0].length!==e.length)return null;if(g===null&&(g=``),d=!0,f=t[3].charAt(0)===`p`||t[3].charAt(0)===`P`,t[2]&&u===null){let e=parseFloat(`.`+t[2].substring(1).trim());isNaN(e)||(c=e),u=!1}return parseInt(t[1])})(e)),t},n=t(e);if(n===null&&r){let r=e.match(s);r&&(n=t(r[1]),n!==null&&(b=r[2]))}if(n===null)return null;y.push(n)}if((g??``).length>0&&!n)return null;if(!0===u&&(y.length===2&&y.splice(1,0,0),y[2]=l||0),y.length===2&&c!==null&&!0!==u&&y.unshift(0),d){if(y[0]>12||y[1]>=60||y[2]>=60)return null;y[0]===12?y[0]=f?12:0:f&&(y[0]+=12),c!==null&&(p=`mm:ss.0`)}else p=m.length>2?`h:mm:ss`:`h:mm`,y[0]>23&&(p=`[h]:mm:ss`),c!==null&&(p=`mm:ss.0`),y[1]>=60&&(p=`General`),y[2]>=60&&(p=`General`);return p!==`General`&&(y.length===1&&y.push(0),y.length===2&&(c===null?y.push(0):y.unshift(0))),{numberFormat:p,parsed:xl(e,{hour:y[0]??0,minute:y[1]??0,second:y[2]??0,millis:1e3*(c??0)}),leadingText:g,trailingText:b}}var Dl=(e,t,n=null,r=!1,i=!1)=>{let a=new Date(n??Date.now()).getFullYear(),{formats:o,compiled:s,monthByName:c,weekdaysAbbr:l,weekdaysWide:u,numericSep:d,wildcardSep:f}=yl(e.getLocale()),p=t.replaceAll(/^ +| +$/g,``).replaceAll(/ +/g,` `);p=p.replaceAll(/ *([-/]) */g,`$1`);let m=p.replaceAll(f,gl),h=p.replaceAll(d,`-`),g=e.isDate1904();for(let e=0;e<o.length;e++){if(!o[e].excelOnly&&!i)continue;let t=p;o[e].containsDot?t=m:o[e].containsDash&&(t=h);let n=_l(t,s[e],c);if(!n)continue;let r=n.year??a;o[e].windowYear&&n.year!==void 0&&(r=r<=29?2e3+r:1900+r),o[e].todaysYear&&(r=a);let d=n.day??1,f=r===1900&&n.month===2&&d===29,_=new Date(0);if(_.setFullYear(r,n.month-1,d),_.setHours(0,0,0,0),!f&&(_.getMonth()!==n.month-1||_.getDate()!==d))continue;let v=f?Kc(1900,2,29)-(g?Wc:0):fl(_,g),y=+!g;if(o[e].windowYear||v>=y){if(o[e].parseFormat.indexOf(`EEE`)>-1){let e=_.getDay(),n=t.toLowerCase();if(!n.includes(l[e].toLowerCase())&&!n.includes(u[e].toLowerCase()))return null}return{asSerialDate:v,asJSDate:_,numberFormat:o[e].numberFormat}}}if(!r){let r=t.replace(Ol,`$1 $2`).replace(kl,`$1 $2`);if(r!==t)return Dl(e,r,n,!0,i)}return null},Ol=/(\d)(\p{L})/gu,kl=/(\p{L})(\d)/gu,Al=Object.freeze({isDate:!1,isTime:!1}),jl=new Map;function Ml(e){if(!e&&e!==0)return Al;let t=jl.get(e);if(t)return t;let n=zc(e).replaceAll(/\[([^)]+)\]/g,``).toLowerCase();n=n.replaceAll(/".*"/g,``),n=n.replaceAll(/\\./g,``),n=n.replace(/[_*]./g,``);let r=Object.freeze({isDate:Nl(n),isTime:Pl(n)});return jl.set(e,r),r}function Nl(e){return!!e.includes(`datetime`)||!e.includes(`time`)&&!!(e.includes(`d`)||e.includes(`m`)&&!e.includes(`h`)&&!e.includes(`s`)||e.includes(`y`)||e===`short date`||e===`medium date`||e===`long date`)}function Pl(e){return!!e.includes(`datetime`)||!e.includes(`date`)&&!(!e.includes(`h`)&&!e.includes(`s`)&&e!==`short time`&&e!==`medium time`&&e!==`long time`)}function Fl(e){return Ml(e).isDate}function Il(e){return Ml(e).isTime}function Ll(e,t,n=!1){let r=t,i=El(e,t,!0,!0);if(i){let e=i.leadingText.trim(),t=i.trailingText.trim();if(e.length>0&&t.length>0)return null;r=e.length>0?e:t}let a=null;if(r.trim().length>0&&(a=Dl(e,r),!a&&n)||(!a&&i&&(i.leadingText.trim().length>0||i.trailingText.trim().length>0)&&(i=null),!a&&!i))return null;let o=0;return a&&(o+=a.asSerialDate),i&&(o+=i.parsed.serial),o}function Rl(e){if(typeof e==`number`)return Rc(e)??`General`;let t=Yl[e];return t===void 0?e:typeof t==`number`?Rc(t)??`General`:t}var zl=Object.freeze({leap1900:!0,dateSpanLarge:!1,dateErrorThrows:!0,dateErrorNumber:!1,throws:!0,indexColors:!1}),Bl=class{constructor(){this.key=`numfmt`}format(e,t,n){let r=n?.date1904??!1,i=n?.locale,a=e;if(Yl[a]!==void 0&&(a=Yl[a]),typeof a==`number`&&(a=Lc(a,i)??a),typeof t==`number`){let e=Jl(a,t,{date1904:r,locale:i});if(e!==null)return{text:e.fmt,color:null,fills:null,skips:null}}typeof a==`number`&&(a=Rc(a)??`General`);let o=this.isDateFormat(a)||this.isTimeFormat(a),s=t;if(o&&typeof s==`number`){if(s<0||s>=2958466)return{text:null,color:null,fills:null,skips:null};r&&(s+=1462)}let c={...zl,locale:i},l,u=null,d=null;try{if(n?.placeholders){let e=Es(a,s,{...c,nbsp:!0,skipChar:``,fillChar:``,digitChar:``}),t=``;for(let n=0;n<e.length;n++){let r=e[n];r===``||r===``?((d??=[]).push({offset:t.length,char:e[n+1]??` `}),n++):r===``?((u??=[]).push({offset:t.length,char:e[n+1]??` `}),n++):t+=r}l=t}else l=Es(a,s,c)}catch(e){if(o&&this.isValidFormat(a))return{text:null,color:null,fills:null,skips:null};throw e}let f=null;if(n?.placeholders){let e=Ds(a,s,c);e!=null&&(f=Zl(typeof e==`number`?`color${e}`:String(e)))}return{text:l,color:f,fills:u,skips:d}}isDateFormat(e){return Fl(e)}isTimeFormat(e){return Il(e)}isFractionFormat(e){return au(zc(e))}adjustDecimalPlaces(e,t){return function(e,t){if(!e&&e!==0)return``;let n=zc(e),r=(e,t)=>{let n=e||``,r=n.length,i=r===0||n.endsWith(`.`)?`0`:n.charAt(r-1);return t<0?(n=n.substring(0,Math.max(0,r+t)),n===`.`&&(n=``)):(n.startsWith(`.`)||(n+=`.`),n+=i.repeat(t)),n},i=(e,t)=>{if(e===`General`)return t>0?`0`+r(``,t):e;if(au(e))return e;let n=e,i=-1,a=-1,o=n.indexOf(`E`);if(o>=0&&(n=n.substring(0,o)),i=n.indexOf(`.`),i>=0){n=n.substring(i,n.length);let t=n&&n.match(/([.]{1}[0,#]+)/);if(!t)return e;n=t[1],a=i+n.length}else{if(t<=0)return e;i=n.lastIndexOf(`0`),i<0&&(i=n.lastIndexOf(`#`)),i>=0&&(i+=1),a=i,n=``}return i===-1?e:(n=r(n,t),e.substring(0,i)+n+e.substring(a,e.length))},a=[],o=Gl(n);for(let e=0;e<o.length;e++)a.push(i(o[e].trim(),t));return a.join(`;`)}(e,t)}getFormatInfo(e){try{return Os(Rl(e))}catch{return null}}getFormatDateInfo(e){try{let t=Rl(e);return Os(t).isDate?function(e){let t=Ts(e,!1);return t.dateInfo||=function(e){let[t]=e;return{year:!!(2&t.date),month:!!(4&t.date),day:!!(8&t.date),hours:!!(16&t.date),minutes:!!(32&t.date),seconds:!!(64&t.date),clockType:t.clock===12?12:24}}(t.partitions),t.dateInfo}(t):null}catch{return null}}isValidFormat(e){try{return function(e){try{return Ts(e,!0),!0}catch{return!1}}(Rl(e))}catch{return!1}}get isIFormatEngine(){return!0}},Vl=null;function Hl(){return Vl??=new Bl}var Ul=/^\[\$-(.*?)\]/i,Wl=1462;function Gl(e){let t=[],n=``;for(let r=0;r<e.length;r++){let i=e[r];if(i===`"`){for(n+=i,r++;r<e.length&&e[r]!==`"`;)n+=e[r++];r<e.length&&(n+=e[r])}else if(i===`[`){for(n+=i,r++;r<e.length&&e[r]!==`]`;)n+=e[r++];r<e.length&&(n+=e[r])}else i===`\\`?(n+=i,r+1<e.length&&(n+=e[++r])):i===`;`?(t.push(n),n=``):n+=i}return t.push(n),t}function Kl(e,t,n){return Es(Lc(e,n?.locale)??Rc(e)??`General`,n?.date1904?t+Wl:t,{leap1900:!0,locale:n?.locale})}function ql(e,t,n,r){return Jl(t,n,{...r,date1904:e?.isDate1904()??!1,locale:e?.getLocale()??void 0})}function Jl(e,t,n){if(typeof t!=`number`||t>2958465||t<0)return null;let r=dl(t,n?.date1904??!1),i=n?.locale??`en-US`,a=!1,o=e,s=-1;if(o===`Short DateTime`&&(o=22),typeof o==`number`)switch(o){case 14:o=Lc(14,i)===void 0?new Intl.DateTimeFormat(i).format(r):Kl(14,t,{...n,locale:i}),a=!0;break;case 22:o=Lc(22,i)===void 0?new Intl.DateTimeFormat(i).format(r)+` `+Kl(20,t,n):Kl(22,t,{...n,locale:i}),a=!0}else{let e=Ul.exec(o);if(e&&e[1]){let t=e[1].toUpperCase();t===`F800`?o=`Long Date`:t===`F400`&&(o=`Long Time`)}if((s=o.indexOf(`Short Date`))!==-1){let e=Lc(14,i)===void 0?new Intl.DateTimeFormat(i).format(r):Kl(14,t,{...n,locale:i});o=o.substring(0,s)+e+o.substring(s+10),a=!0}if((s=o.indexOf(`Medium Date`))!==-1){let e=Kl(15,t,n);o=o.substring(0,s)+e+o.substring(s+11),a=!0}if((s=o.indexOf(`Long Date`))!==-1){let e=new Intl.DateTimeFormat(i,{dateStyle:`full`}).format(r);o=o.substring(0,s)+e+o.substring(s+9),a=!0}if((s=o.indexOf(`Short Time`))!==-1){let e=Kl(20,t,n);o=o.substring(0,s)+e+o.substring(s+10),a=!0}if((s=o.indexOf(`Medium Time`))!==-1){let e=Kl(18,t,n);o=o.substring(0,s)+e+o.substring(s+11),a=!0}if((s=o.indexOf(`Long Time`))!==-1){let e=new Intl.DateTimeFormat(i,{timeStyle:`medium`}).format(r);o=o.substring(0,s)+e+o.substring(s+9),a=!0}}return a?{fmt:o,date:r}:null}var Yl=Object.freeze({"General Number":`General`,"General Date":`m/d/yyyy h:mm`,"Short Date":14,"Medium Date":15,"Long Date":`[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy`,"Short Time":20,"Medium Time":18,"Long Time":`[$-F400]h:mm:ss\\ AM/PM;@`,"Short DateTime":22,Currency:`"$"#,##0.00_);[Red]\\("$"#,##0.00\\)`,Fixed:2,Standard:4,Percent:10,Scientific:11,"Yes/No":`"Yes";"Yes";"No";@`,"True/False":`"True";"True";"False";@`,"On/Off":`"Yes";"Yes";"No";@`}),Xl=Object.freeze({black:0,white:1,red:2,green:3,blue:4,yellow:5,magenta:6,cyan:7});function Zl(e){let t=null;if((e=e.toLowerCase()).startsWith(`color`)){let n=parseInt(e.substring(5));n>=0&&n<=56&&(t=`Index${n+7}`)}if(!t){let n=Xl[e];n!==void 0&&(t=Nc(n).toString())}return t}var Ql=`=`,$l=`<>`,eu=`>`,tu=`<`,nu=`>=`,ru=`<=`,iu=new Map;iu.set(Ql,(e,t)=>e===t),iu.set($l,(e,t)=>e!==t),iu.set(eu,(e,t)=>e>t),iu.set(tu,(e,t)=>e<t),iu.set(nu,(e,t)=>e>=t),iu.set(ru,(e,t)=>e<=t),Object.freeze({op:nu,comp:0}),Object.freeze({op:tu,comp:0}),Object.freeze({op:eu,comp:0}),Object.freeze({op:Ql,comp:0});function au(e){return!(!e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)&&!e.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))}var ou={Text:`text`,Repeat:`repeat`,Spacing:`spacing`},su=Object.freeze({formatValue:function(e,t,n,r){return function(e,t,n){let r=!(!n||!n.onSpacingChar&&!n.onRepeatChar&&n.spacingCharacter===void 0),i=Hl().format(e,t,{date1904:n?.date1904??!1,locale:n?.locale,placeholders:r});if(!r)return i.text??``;let a=i.skips??[],o=i.fills??[];if(n.onRepeatChar)for(let e of o)n.onRepeatChar(e.offset,e.char);let s=i.text??``;if(n.spacingCharacter!==``&&a.length){let e=``,t=0;for(let r=0;r<a.length;r++){let i=a[r];e+=s.slice(t,i.offset)+(n.spacingCharacter??` `),t=i.offset,n.onSpacingChar&&n.onSpacingChar(i.offset+r,i.char)}s=e+s.slice(t)}else if(n.onSpacingChar)for(let e of a)n.onSpacingChar(e.offset,e.char);return s}(t,n,{...r,date1904:e?.isDate1904()??!1,locale:e?.getLocale()??void 0})},isFractionFormat:e=>Hl().isFractionFormat(e),adjustDecimalPlaces:(e,t)=>Hl().adjustDecimalPlaces(e,t),getFormatInfo:e=>Hl().getFormatInfo(e),getFormatDateInfo:e=>Hl().getFormatDateInfo(e),isValidFormat:e=>Hl().isValidFormat(e)});function cu(e){return e===14?`Short Date`:e===22?`Short DateTime`:Pc[e]??null}function lu(e){if(typeof e==`number`)return e;let t=e,n=Yl[e];return n&&(t=n),typeof t==`number`?t:(r=t,Bc.get(r)??t);var r}var uu=[{numberFormat:`General`,formatType:Da.General,primary:1},{numberFormat:`0`,formatType:Da.Number,regMatch:/^0[.]{0,1}[0]*$/,args:{decimalPlaces:0,separator:!1}},{numberFormat:`0.00`,formatType:Da.Number,primary:2,args:{decimalPlaces:2,separator:!1}},{numberFormat:`#,##0.00`,formatType:Da.Number,regMatch:/^#,##0[.]{0,1}[0]*$/,args:{decimalPlaces:2,separator:!0}},{numberFormat:`#,##0_);(#,##0)`,formatType:Da.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:`#,##0_);[Red](#,##0)`,formatType:Da.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:`#,##0.00_);(#,##0.00)`,formatType:Da.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:`#,##0.00_);[Red](#,##0.00)`,formatType:Da.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:`$#,##0.00`,formatType:Da.Currency,primary:3,args:{decimalPlaces:2,currencySymbol:`$`}},{numberFormat:`$#,##0_);($#,##0)`,formatType:Da.Currency,args:{decimalPlaces:0,currencySymbol:`$`}},{numberFormat:`$#,##0_);[Red]($#,##0)`,formatType:Da.Currency,args:{decimalPlaces:0,currencySymbol:`$`}},{numberFormat:`$#,##0.00_);($#,##0.00)`,formatType:Da.Currency,args:{decimalPlaces:2,currencySymbol:`$`}},{numberFormat:`$#,##0.00_);[Red]($#,##0.00)`,formatType:Da.Currency,args:{decimalPlaces:2,currencySymbol:`$`}},{numberFormat:`_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)`,primary:4,formatType:Da.Accounting},{numberFormat:`_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)`,formatType:Da.Accounting},{numberFormat:`_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)`,formatType:Da.Accounting},{numberFormat:`_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)`,formatType:Da.Accounting},{numberFormat:`Short Date`,formatType:Da.ShortDate,primary:5},{numberFormat:`d-mmm-yy`,formatType:Da.MediumDate,primary:5.5},{numberFormat:`Long Date`,formatType:Da.LongDate,primary:6},{numberFormat:`h:mm`,formatType:Da.ShortTime,primary:7},{numberFormat:`h:mm AM/PM`,formatType:Da.MediumTime,primary:7.5},{numberFormat:`Long Time`,formatType:Da.LongTime,primary:8},{numberFormat:`_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)`,formatType:Da.Comma,primary:9},{numberFormat:`0.00%`,formatType:Da.Percentage,primary:10,args:{decimalPlaces:2},regMatch:/^^[0#?]*[.]{0,1}[0#?]*%*$/},{numberFormat:`0%`,formatType:Da.Percentage,args:{decimalPlaces:0}},{numberFormat:`# ?/?`,formatType:Da.Fraction,primary:11},{numberFormat:`# ??/??`,formatType:Da.Fraction},{numberFormat:`0.00E+00`,formatType:Da.Scientific,primary:12,args:{decimalPlaces:2},regMatch:/^[0#?]*[.]{0,1}[0#?]*E\+[0#?]*$/},{numberFormat:`##0.0E+0`,formatType:Da.Custom,args:{decimalPlaces:0}},{numberFormat:`@`,formatType:Da.Text,primary:13},{numberFormat:`d-mmm`,formatType:Da.Custom},{numberFormat:`mmm-yy`,formatType:Da.Custom},{numberFormat:`h:mm:ss`,formatType:Da.Custom},{numberFormat:`m/d/yyyy h:mm`,formatType:Da.Custom},{numberFormat:`Short DateTime`,formatType:Da.Custom},{numberFormat:`mm:ss`,formatType:Da.Custom},{numberFormat:`mm:ss.0`,formatType:Da.Custom},{numberFormat:`[h]:mm:ss`,formatType:Da.Custom}],du=[{numberFormat:`00000`,formatType:Da.Special,primary:11},{numberFormat:`00000-0000`,formatType:Da.Special},{numberFormat:`[<=9999999]###-####;(###) ###-####`,formatType:Da.Special},{numberFormat:`000-00-0000`,formatType:Da.Special}],fu=[...uu,...du],pu=new Map,mu=[];for(let e=0;e<uu.length;e++){let t=uu[e].numberFormat.toLowerCase();pu.set(t,uu[e]),uu[e].regMatch&&mu.unshift(uu[e])}for(let e=0;e<du.length;e++){let t=du[e].numberFormat.toLowerCase();pu.set(t,du[e])}var hu=[],gu=new Map;pu.forEach(function(e,t,r){e.primary&&(hu.push(e),gu.set(n.CommonUtils.textToKey(e.formatType),e.numberFormat))}),hu.sort(function(e,t){return e.primary-t.primary});var _u=pu.get(Da.General.toLowerCase()),vu=class{lookupStyle(e){if(!e)return _u;if(typeof e==`number`&&(e=cu(e)),!e.toLowerCase)return console.warn(`Invalid numberFormat`,e),_u;e=e.toLowerCase();let t=pu.get(e);if(t)return t;for(let n=0;!t&&n<mu.length;n++)mu[n].regMatch&&e.match(mu[n].regMatch)&&(t=mu[n]);return t||{numberFormat:e,formatType:Da.Custom}}lookupPrimary(){return hu}lookupByType(e){return fu.filter(t=>t.formatType===e)}lookupDefault(e){return gu.get(n.CommonUtils.textToKey(e))}},yu=e.n({CATEGORIES:()=>xu,CURRENCY_SYMBOLS:()=>Ou,DATE_PRESETS:()=>ku,FRACTION_PRESETS:()=>ju,NEGATIVE_STYLES:()=>Du,SPECIAL_PRESETS:()=>Mu,TIME_PRESETS:()=>Au,build:()=>Iu,defaultCodeForCategory:()=>Nu,isParametricCategory:()=>Cu,parse:()=>Bu}),bu=new vu,xu=Object.freeze([`General`,`Number`,`Currency`,`Accounting`,`Date`,`Time`,`Percentage`,`Fraction`,`Scientific`,`Text`,`Special`,`Custom`]),Su=new Set([`Number`,`Currency`,`Accounting`,`Percentage`,`Scientific`]);function Cu(e){return Su.has(e)}var wu,Tu,Eu,Du=Object.freeze([{key:`minus`,label:`Minus sign`,red:!1,parens:!1},{key:`red`,label:`Red`,red:!0,parens:!1},{key:`parens`,label:`Parentheses`,red:!1,parens:!0},{key:`redParens`,label:`Red parentheses`,red:!0,parens:!0}]),Ou=Object.freeze([`$`,`€`,`£`,`¥`,`₹`,`₩`,`₽`,`₺`,`R$`,`CHF`,`kr`,`฿`]),ku=Object.freeze([`Short Date`,`Long Date`,`m/d/yyyy`,`d-mmm-yy`,`d-mmm`,`mmm-yy`,`mmmm d, yyyy`,`m/d/yy h:mm`]),Au=Object.freeze([`h:mm AM/PM`,`h:mm:ss AM/PM`,`h:mm`,`h:mm:ss`,`Long Time`,`[h]:mm:ss`,`mm:ss`,`mm:ss.0`]),ju=Object.freeze([`# ?/?`,`# ??/??`,`# ???/???`,`# ?/2`,`# ?/4`,`# ?/8`,`# ??/16`,`# ?/10`,`# ??/100`]),Mu=Object.freeze([`00000`,`00000-0000`,`[<=9999999]###-####;(###) ###-####`,`000-00-0000`]);function Nu(e){switch(e){case`General`:case`Custom`:return`General`;case`Text`:return`@`;case`Number`:return Iu({category:`Number`,decimalPlaces:2,useSeparator:!1,negativeStyle:0});case`Currency`:return Iu({category:`Currency`,decimalPlaces:2,currencySymbol:`$`,negativeStyle:0});case`Accounting`:return Iu({category:`Accounting`,decimalPlaces:2,currencySymbol:`$`});case`Percentage`:return`0.00%`;case`Scientific`:return`0.00E+00`;case`Date`:return ku[0];case`Time`:return Au[0];case`Fraction`:return ju[0];case`Special`:return Mu[0]}}function Pu(e){let t=e??`$`;return t===`$`?`$`:`"${t}"`}function Fu(e,t){let n=Du[t??0]??Du[0];return n.parens?n.red?`${e}_);[Red](${e})`:`${e}_);(${e})`:n.red?`${e};[Red]${e}`:e}function Iu(e){let{category:t,decimalPlaces:n,useSeparator:r,currencySymbol:i,negativeStyle:a,code:o}=e,s=function(e){let t=Math.max(0,Math.min(30,e??0));return t>0?`.`+`0`.repeat(t):``}(n??0);switch(t){case`General`:return`General`;case`Text`:return`@`;case`Number`:return Fu((r?`#,##0`:`0`)+s,a);case`Currency`:return Fu(Pu(i)+`#,##0`+s,a);case`Accounting`:{let e=Pu(i);return`_(${e}* #,##0${s}_);_(${e}* (#,##0${s});_(${e}* ${(n??0)>0?`"-"`+`?`.repeat(n):`"-"`}_);_(@_)`}case`Percentage`:return`0`+s+`%`;case`Scientific`:return`0`+s+`E+00`;case`Date`:case`Time`:case`Fraction`:case`Special`:case`Custom`:return o||Nu(t)}}function Lu(e,t){if(bu.lookupStyle(e).formatType===Da.Special)return`Special`;switch(t){case`general`:return`General`;case`text`:return`Text`;case`percent`:return`Percentage`;case`scientific`:return`Scientific`;case`fraction`:return`Fraction`;case`date`:return`Date`;case`time`:return`Time`;case`datetime`:default:return`Custom`;case`currency`:return function(e){return e.includes(`_(`)&&e.includes(`* `)}(e)?`Accounting`:`Currency`;case`number`:case`grouped`:return function(e){return bu.lookupStyle(e).formatType===Da.Special}(e)?`Special`:`Number`}}function Ru(e){let t=e.match(/\[\$([^\]-]+)(?:-[^\]]*)?\]/);if(t)return t[1];let n=e.match(/"([^"]+)"/);return n&&n[1]!==`-`?n[1]:(e.includes(`$`),`$`)}function zu(e){let t=Gl(e);if(t.length<2)return 0;let n=t[1],r=/\[red\]/i.test(n);return n.includes(`(`)?r?3:2:+!!r}function Bu(e){if(e==null||e===``)return{category:`General`};let t=Hl().getFormatInfo(e),n=Lu(e,t?.type),r={category:n};switch(n){case`Number`:r.decimalPlaces=t?.maxDecimals??0,r.useSeparator=!!t?.grouped,r.negativeStyle=zu(e);break;case`Currency`:r.decimalPlaces=t?.maxDecimals??2,r.currencySymbol=Ru(e),r.negativeStyle=zu(e);break;case`Accounting`:r.decimalPlaces=t?.maxDecimals??2,r.currencySymbol=Ru(e);break;case`Percentage`:case`Scientific`:r.decimalPlaces=t?.maxDecimals??2;break;default:r.code=e}return r}(Tu=wu||={}).Type=Da,Tu.Parser=su,Tu.Styles=new vu,Tu.ParseRunType=ou,Tu.toBuiltInID=lu,Tu.resolve=zc,Tu.builtInFormat=Rc,Tu.getEngine=Hl,Tu.Builder=yu,(Eu||={}).Visibility={Visible:`visible`,Hidden:`hidden`,VeryHidden:`veryHidden`};var Vu,Hu,Uu,Wu,Gu=new RegExp(/^([$]?[a-zA-Z]*[$]?[0-9]*)(?::([$]?[a-zA-Z]*[$]?[0-9]*))?$/),Ku=new RegExp(/^(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?)(?::(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?))?$/,`i`),qu=new RegExp(/^(R?)(\[?[-+]?\d+\]?|\d+)?(C?)(\[?[-+]?\d+\]?|\d+)?$/,`i`),Ju=RegExp(`(?:(?:'(?:[^']|'')+'|\\[[^\\]]+\\][A-Za-z0-9_.]*(?::[A-Za-z0-9_.]+)?|[A-Za-z0-9_.]+(?::[A-Za-z0-9_.]+)?)!)?(\\$?[A-Za-z]+\\$?\\d+(?::\\$?[A-Za-z]+\\$?\\d+)?|\\$?[A-Za-z]+:\\$?[A-Za-z]+|\\$?\\d+:\\$?\\d+)`,`g`),Yu=/\s+/g,Xu=/"(?:[^"]|"")*"|\[[^[\]]+\](?![A-Za-z0-9_.]*(?::[A-Za-z0-9_.]+)?!)/g,Zu=/[\uE000-\uF8FF]/g,Qu=`#REF!`,$u=2**14,ed=2**20,td=$u,nd=ed;function rd(e){return Vu===e?Hu:(Vu=e,Hu=``+(e+1))}function id(e){if(Uu===e)return Wu;Uu=e,e<0&&console.warn(`invalid column `+e);let t=``;for(++e;e;e=Math.floor((e-1)/26))t=String.fromCharCode((e-1)%26+65)+t;return Wu=t}var ad=/[^A-Za-z_.\d\u007F-\uFFFF[\]:]/,od=/^\d/,sd=/^\[[^\]]*\]/;function cd(e){return e?id(e.colIndex)+rd(e.rowIndex):null}function ld(e){if(!e)return Qu;let t=id(e.colIndex),n=rd(e.rowIndex);return(e.$colIndex?`$`+t:t)+(e.$rowIndex?`$`+n:n)}function ud(e,t){let n=e??t;if(n){n=R(n),n=n.replace(/'/g,`''`);let e=ad.test(n);if(!e){let t=n.replace(sd,``).split(`:`);for(let n=0;n<t.length&&!e;n++)e=od.test(t[n])}e&&(n=ee(n))}return n}function dd(e,t){return e?e+(e.endsWith(`!`)?``:`!`)+t:Qu}function fd(e,n,r=cd){if(!e)return null;if(typeof e==`string`)return e;if(t.FormulaError.isError(e))return e.toString();let i=e,a=i.colStart,o=i.rowStart,s=i.colEnd,c=i.rowEnd;if(a===s&&o===c)return r({colIndex:a,rowIndex:o});n&&(i={...n,...i});let l=a===-(2**53-1)||n&&a<=n.colStart&&s>=n.colEnd,u=o===-(2**53-1)||n&&o<=n.rowStart&&c>=n.rowEnd,d,f;return d=u?id(a):l?rd(o):r({colIndex:a,rowIndex:o}),f=u?id(s):l?rd(c):r({colIndex:s,rowIndex:c}),d+`:`+f}function pd(e,t){if(!e||!t)return null;let n=e.rowStart===-(2**53-1)||e.rowStart<=t.rowStart&&e.rowEnd>=t.rowEnd,r=e.colStart===-(2**53-1)||e.colStart<=t.colStart&&e.colEnd>=t.colEnd;return n&&!r?(e.$colStart?`$`:``)+id(e.colStart)+`:`+((e.$colEnd?`$`:``)+id(e.colEnd)):r&&!n?(e.$rowStart?`$`:``)+rd(e.rowStart)+`:`+((e.$rowEnd?`$`:``)+rd(e.rowEnd)):null}function md(e,t,n=ld){if(!e)return Qu;let r=e.colIndex,i=e.rowIndex,a=r===-(2**53-1),o;return i===-(2**53-1)?(o=id(r),e.$colIndex&&(o=`$`+o)):a?(o=rd(i),e.$rowIndex&&(o=`$`+o)):o=n(e),(e.scope||t)&&(o=dd(ud(e.scope,t),o)),o}function hd(e,t,n=ld,r){if(!e)return Qu;let i=e.rowStart!==void 0&&e.rowStart===e.rowEnd,a=e.colStart!==void 0&&e.colStart===e.colEnd&&i;if(!r&&a)return n({colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart,$rowIndex:e.$rowStart});e={...t,...e};let o=!r&&t&&e.rowStart<=t.rowStart&&e.rowEnd>=t.rowEnd,s=!r&&t&&e.colStart<=t.colStart&&e.colEnd>=t.colEnd,c,l;return o?(c=id(e.colStart),c=e.$colStart?`$`+c:c):s?(c=rd(e.rowStart),c=e.$rowStart?`$`+c:c):c=n({colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart,$rowIndex:e.$rowStart}),o?(l=id(e.colEnd),l=e.$colEnd?`$`+l:l):s?(l=rd(e.rowEnd),l=e.$rowEnd?`$`+l:l):l=n({colIndex:e.colEnd,rowIndex:e.rowEnd,$colIndex:e.$colEnd,$rowIndex:e.$rowEnd}),c+`:`+l}function gd(e,t,n=ld){let r=hd(e,t,n),i=ud(e?.scope,t?.scope);return i?dd(i,r):r}function _d(e,t=!1){if(!e)return null;let n=0,r=0,i=!1,a=!1,o=e.length;for(let s=0;s<o;++s){let o=e.charCodeAt(s);if(o>=48&&o<=57){if(r=10*r+(o-48),n===0&&!t)return}else if(o>=65&&o<=90){if(n=26*n+(o-64),r!==0)return}else if(o>=97&&o<=122){if(n=26*n+(o-96),r!==0)return}else{if(o!==36)return;if(n!==0||i){if(r!==0||a)return;a=!0}else i=!0}}let s={};return t||r!==0&&n!==0?(n>0&&(s.colIndex=n-1,i&&(s.$colIndex=i)),r>0&&(s.rowIndex=r-1,(a||t&&i)&&(s.$rowIndex=a||t&&i)),s):null}var vd=e=>{let t=e.lastIndexOf(`!`);if(t===-1)return null;let n=e.slice(0,t);return n=R(n),n=n.replace(/''/g,`'`),[n,e.slice(t+1)]};function yd(e,t=MH,n=!1){if(!e)return null;let r=jd(e.toUpperCase(),n),i=null,a=null;if(r?.[1]){let e=!!r[2],t=n?Dd:_d;i=t(r[1],e),a=t(r[2]??r[1],e)}if(!i&&!a||i&&a&&(i.rowIndex===void 0&&a.rowIndex!==void 0||i.rowIndex!==void 0&&a.rowIndex===void 0||i.colIndex===void 0&&a.colIndex!==void 0||i.colIndex!==void 0&&a.colIndex===void 0))return null;let o={};return i&&(i.colIndex!==void 0&&(o.colStart=i.colIndex),i.rowIndex!==void 0&&(o.rowStart=i.rowIndex),i.$colIndex!==void 0&&(o.$colStart=i.$colIndex),i.$rowIndex!==void 0&&(o.$rowStart=i.$rowIndex),o?.colStart!==void 0&&o?.colStart>t?.colEnd)?null:(a&&(a.colIndex!==void 0&&(o.colEnd=a.colIndex),a.rowIndex!==void 0&&(o.rowEnd=a.rowIndex),a.$colIndex!==void 0&&(o.$colEnd=a.$colIndex),a.$rowIndex!==void 0&&(o.$rowEnd=a.$rowIndex)),o.colStart===void 0&&(o.colStart=t.colStart),o.colEnd===void 0&&(o.colEnd=t.colEnd),o.rowStart===void 0&&(o.rowStart=t.rowStart),o.rowEnd===void 0&&(o.rowEnd=t.rowEnd),t.scope&&(o.scope=t.scope),o)}function bd(e,t,n=!1){let r,i=vd(e);if(i){let a=e.lastIndexOf(`!`),o=e.indexOf(`:`);if(o!==-1&&o<a){let t=e.indexOf(`!`),n=e.indexOf(`:`,t),r=vd(e.slice(0,n)),a=vd(e.slice(n+1));if(!r||!a||r[0].toUpperCase()!==a[0].toUpperCase())return null;i=[r[0],`${r[1]}:${a[1]}`]}if(r=yd(i[1],t,n),!r)return null;r.scope=i[0]}else r=yd(e,t,n);return r||null}function xd(e,n,r=hd,i=ld,a=!1){if(!e||e.length===0)return null;let o=[],s=e.length;for(let a=0;a<s;a++){let s=e[a],c=null;s?s.rowIndex!==void 0||s.colIndex!==void 0?c=i(s):s.rowStart!==void 0||s.colStart!==void 0?c=r(s,n,i):typeof s==`string`?c=s:`nameId`in s?c=s.nameId:t.FormulaError.isError(s)&&(c=s.toString()):c=Qu,c&&o.push(c)}return o}function Sd(e,t,n=gd,r=ld,i=!1){let a=xd(e,t,n,r,i);return a?a.join(`,`):Qu}var Cd=e=>e!==void 0&&e!==-(2**53-1)&&e!==2**53-1,wd=(e,t,r,i=bd,a,o=!1)=>{if(t!==null){if(typeof t==`string`){let n=i(t,r,o);if(!n){let n=a?.(t);if(n){let t=n.length;for(let s=0;s<t;s++){let t=n[s];wd(e,t,r,i,a,o)}}return}t=n}else t.isICellRange?t=t.getCoords():t.isICell&&(t=n.CoordUtils.cellToRange(t.getCoords()));if(t!==null){if(t.rowStart!==void 0||t.colStart!==void 0||t.colEnd!==void 0||t.rowEnd!==void 0){let n=t;e.push({...r,...n,colStart:Cd(n.colStart)?n.colStart:r.colStart,rowStart:Cd(n.rowStart)?n.rowStart:r.rowStart,colEnd:Cd(n.colEnd)?n.colEnd:r.colEnd,rowEnd:Cd(n.rowEnd)?n.rowEnd:r.rowEnd})}else if(t.rowIndex!==void 0||t.colIndex!==void 0){let n=t,i={...r,...n,colStart:n.colIndex,rowStart:n.rowIndex,colEnd:n.colIndex,rowEnd:n.rowIndex};i.scope===null&&r.scope&&(i.scope=r.scope),delete i.colIndex,delete i.rowIndex,e.push(i)}}else e.push(null)}else e.push(null)};function Td(e,t,n=bd,r,i=!1){if(!e)return[t];let a;a=typeof e==`string`?te(e):e.isICellRanges?e.getCoords():e.isIReferenceRange?[e.getCoords()]:Array.isArray(e)?e:[e];let o=[],s=a.length;for(let e=0;e<s;e++){let s=a[e];wd(o,s,t,n,r,i)}return o}function Ed(e,t){let n=0,r=0,i=e.length;for(let t=0;t<i;++t){let i=e.charCodeAt(t);if(i>=48&&i<=57){if(n=10*n+(i-48),r===0)return}else if(i>=65&&i<=90){if(r=26*r+(i-64),n!==0)return}else if(!(i>=97&&i<=122)||(r=26*r+(i-96),n!==0))return}return t?(t.colIndex=r-1,t.rowIndex=n-1,t):{colIndex:r-1,rowIndex:n-1}}function Dd(e,t=!1,n){n?(n.colIndex=-(2**53-1),n.rowIndex=-(2**53-1),n.$colIndex=!1,n.$rowIndex=!1):n={colIndex:-(2**53-1),rowIndex:-(2**53-1),$colIndex:!1,$rowIndex:!1};let r=qu.exec(e);if(!r)return null;let i=r[1],a=r[3];if(!(t||i&&a))return null;if(i){let e=r[2];e?e&&(e.startsWith(`[`)?(n.rowIndex=parseInt(e.slice(1,-1)),n.$rowIndex=!1):(n.rowIndex=parseInt(e)-1,n.$rowIndex=!0)):(n.rowIndex=0,n.$rowIndex=!1)}if(a){let e=r[4];e?e.startsWith(`[`)?(n.colIndex=parseInt(e.slice(1,-1)),n.$colIndex=!1):(n.colIndex=parseInt(e)-1,n.$colIndex=!0):(n.colIndex=0,n.$colIndex=!1)}return n}function Od(e,t){let n=0,r=0,i=!1,a=!1,o=e.length;for(let t=0;t<o;++t){let o=e.charCodeAt(t);o>=48&&o<=57?n=10*n+(o-48):o>=65&&o<=90?r=26*r+(o-64):o>=97&&o<=122?r=26*r+(o-96):o===36&&(t===0?i=!0:a=!0)}return r--,n--,t.colIndex=r,t.rowIndex=n,n===-1?(t.$colIndex=i,t.$rowIndex=!1,t):r===-1?(t.$colIndex=!1,t.$rowIndex=i,t):(t.$colIndex=i,t.$rowIndex=a,t)}function kd(e){let t=0,n=e.length;for(let r=0;r<n;++r){let n=e.charCodeAt(r);if(n>=65&&n<=90)t=26*t+(n-64);else{if(!(n>=97&&n<=122))return t-1;t=26*t+(n-96)}}return t-1}function Ad(e,t){let n=t;n?(n.rowStart=0,n.colStart=0,n.rowEnd=0,n.colEnd=0):n={rowStart:0,colStart:0,rowEnd:0,colEnd:0};let r=0,i=0,a=0,o=e.length;for(r=0;i<o&&(a=e.charCodeAt(i),a>96&&a<123&&(a-=32),!(a<65||a>91));++i)r=26*r+(a-64);for(n.colStart=--r,r=0;i<o;++i){let t=e.charCodeAt(i)-48;if(t<0||t>9)break;r=10*r+t}if(n.rowStart=--r,i===o||e.charCodeAt(++i)===58)return n.colEnd=n.colStart,n.rowEnd=n.rowStart,n;for(r=0;i!==o&&(a=e.charCodeAt(i),a>96&&a<123&&(a-=32),!(a<65||a>91));++i)r=26*r+(a-64);for(n.colEnd=--r,r=0;i!==o;++i){let t=e.charCodeAt(i)-48;if(t<0||t>9)break;r=10*r+t}return n.rowEnd=--r,n}function jd(e,t=!1){let n=e.match(t?Ku:Gu);return e.endsWith(`:`)?null:n}var Md={rowIndex:-1,colIndex:-1,$colIndex:!1,$rowIndex:!1};function Nd(e,t,n,r=$u){let i=e,a,o=e.lastIndexOf(`!`),s=``;o!==-1&&(s=e.slice(0,o)+`!`,e=e.slice(o+1));let c=()=>{let e=``,r=a.rowIndex;if(r!==-1)if(a.$rowIndex)e+=`R${r+1}`;else{let n=r-t;e+=n===0?`R`:`R[${n}]`}let i=``,o=a.colIndex;if(o!==-1)if(a.$colIndex)i+=`C${o+1}`;else{let e=o-n;i+=e===0?`C`:`C[${e}]`}s+=e+i};o=e.lastIndexOf(`:`);let l=o!==-1;if(l){let t=e.slice(0,o);e=e.slice(o+1),a=Od(t,Md),a.colIndex!==-1&&a.rowIndex!==-1&&(c(),s+=`:`)}return a=Od(e,Md),!l&&a.colIndex>r?i:(c(),s)}var Pd=[],Fd=e=>(Pd.push(e),String.fromCharCode(57344+Pd.length-1)),Id=e=>Pd[e.charCodeAt(0)-57344];function Ld(e,t,n){let r=``,i=e.length;for(let a=0;a<i;a++){let i=e[a];r+=typeof i==`string`?i:zd(i,t,n)}return r}function Rd(e,t){let n=``,r=e.rowIndex;r!==-(2**53-1)&&(e.$rowIndex?n+=`R${r+1}`:n+=r===0?`R`:`R[${r}]`);let i=``,a=e.colIndex;return a!==-(2**53-1)&&(e.$colIndex?i+=`C${a+1}`:i+=a===0?`C`:`C[${a}]`),e.scope&&(n=ud(e.scope,t)+`!`+n),n+i}function zd(e,t,n){let r,i=e.scope;r=i?ud(i)+`!`:``;let a=e.colIndex;a!==-(2**53-1)&&(e.$colIndex?r+=`$`+id(a):r+=id(a+n));let o=e.rowIndex;return o!==-(2**53-1)&&(e.$rowIndex?r+=`$`+rd(o):r+=rd(o+t)),r}function Bd(e,t,n,r){let i=e.colStart,a=e.rowStart,o=e.colEnd,s=e.rowEnd,c=e.$colStart??!1,l=e.$rowStart??!1,u=e.$colEnd??!1,d=e.$rowEnd??!1;if(c||i===-(2**53-1)||(i+=n),l||a===-(2**53-1)||(a+=t),u||o===2**53-1||(o+=n),d||s===2**53-1||(s+=t),i>o){let e=i;i=o,o=e}if(a>s){let e=a;a=s,s=e}let f;return r?(f=r,f.colStart=i,f.rowStart=a,f.colEnd=o,f.rowEnd=s,f.$colStart=c,f.$rowStart=l,f.$colEnd=u,f.$rowEnd=d):f={colStart:i,rowStart:a,colEnd:o,rowEnd:s,$colStart:c,$rowStart:l,$colEnd:u,$rowEnd:d},e.scope?f.scope=e.scope:f.scope&&=null,f}function Vd(e,t,n){let r=e.$colStart??!1,i=e.$rowStart??!1,a=e.$colEnd??!1,o=e.$rowEnd??!1,s={colStart:r?e.colStart:e.colStart-n,rowStart:i?e.rowStart:e.rowStart-t,colEnd:a?e.colEnd:e.colEnd-n,rowEnd:o?e.rowEnd:e.rowEnd-t,$colStart:r,$rowStart:i,$colEnd:a,$rowEnd:o};return e.scope&&(s.scope=e.scope),s}function Hd(e,t,n,r){Pd.length=0;let i=e.replace(Xu,Fd),a=0,o=i.replace(Ju,(e,o,s)=>{let c=Nd(e,t,n);if(r){if(s>a){let e=i.slice(a,s);r.push(e.replace(Zu,Id))}let o,l=e,u=l.lastIndexOf(`!`);u!==-1&&(o=l.slice(0,u).replace(Zu,Id),l=l.slice(u+1));let d=l.lastIndexOf(`:`),f;if(d!==-1){let e=l.slice(0,d),i=l.slice(d+1),a=Nd(e,t,n),o=Nd(i,t,n);f=Dd(a,!0),r.push(f??a),r.push(`:`),r.push(Dd(o,!0)??o)}else f=Dd(Nd(l,t,n),!0),r.push(f??c.replace(Zu,Id));o&&f&&(f.scope=o)}return a=s+e.length,c});if(r&&a<i.length){let e=i.slice(a);r.push(e.replace(Zu,Id))}return o=o.toUpperCase().replace(Yu,``),o.replace(Zu,Id)}function Ud(e,t){let r,i,a;return Array.isArray(e)?(r=e[0],i=e[1]):e.r===void 0?r=e:(r=e.r,i=e.v),Array.isArray(r)&&(r=r[0]),a=typeof r==`string`?yd(r,t):n.CoordUtils.sanitizeRange(r,t),i!==void 0&&a&&(a.value=i),a}function Wd(e,t){let r,i;Array.isArray(e)?(r=e[0],i=e[1]):e.r===void 0?r=e:(r=e.r,i=e.v);let a=[],o=e=>{let r=typeof e==`string`?yd(e,t):n.CoordUtils.sanitizeRange(e,t);r&&a.push(r)};if(typeof r==`string`){let e=te(r),t=e.length;for(let n=0;n<t;n++)o(e[n])}else if(Array.isArray(r)){let e=r.length;for(let t=0;t<e;t++)o(r[t])}else o(r);return a.length===0?null:{coords:a,value:i}}var Gd=/^\$?([A-Z]+)(?::\$?([A-Z]+))?$/,Kd=/^\$?(\d+)(?::\$?(\d+))?$/;function qd(e,t,n){let r=n?id:rd,i=r(e);return e===t?`${i}:${i}`:`${i}:${r(t)}`}function Jd(e,t){if(!e)return null;let n=e.trim().toUpperCase(),r,i,a=Gd.exec(n);if(a)r=kd(a[1]),i=a[2]===void 0?r:kd(a[2]);else if(a=Kd.exec(n))r=parseInt(a[1])-1,i=a[2]===void 0?r:parseInt(a[2])-1;else{let e=yd(n);if(!e)return null;r=t?e.colStart:e.rowStart,i=t?e.colEnd:e.rowEnd}return r===void 0||i===void 0||Number.isNaN(r)||Number.isNaN(i)?null:r<=i?{min:r,max:i}:{min:i,max:r}}function Yd(e,t){return{r:qd(e.min,e.max,t),v:e.value}}function Xd(e,t){let n,r;Array.isArray(e)?(n=e[0],r=e[1]):(n=e?.r,r=e?.v),Array.isArray(n)&&(n=n[0]);let i=null;if(typeof n==`string`)i=Jd(n,t);else if(n){let e=n,r=t?e.colStart:e.rowStart,a=t?e.colEnd:e.rowEnd;r!==void 0&&a!==void 0&&(i=r<=a?{min:r,max:a}:{min:a,max:r})}return i?(i.value=r,i):null}function Zd(e,t){let n=e?e.length:0,r=Array(n);for(let i=0;i<n;i++)r[i]=Yd(e[i],t);return r}function Qd(e,t){let n=e?e.length:0,r=[];for(let i=0;i<n;i++){let n=Xd(e[i],t);n&&r.push(n)}return r}function $d(e,t,n=cd){let r=e?e.length:0;if(r===0)return null;let i=[];for(let a=0;a<r;a++){let r=fd(e[a],t,n);r&&i.push(r)}return i.length===0?null:i.join(`,`)}function ef(e,t){return typeof e==`string`?yd(e,t):n.CoordUtils.sanitizeRange(e,t)}function tf(e,t){return typeof e==`string`?e:hd(e,t)}function nf(e,r,i){let a=n.CoordUtils.intersectRanges(e,r,i);if(!a)return null;let o=e.scope,s=r.scope;if(o&&s){if(o!==s)return t.FormulaError.BuiltIn.Value;a.scope=o}else o||s?a.scope=o||s:a.scope&&=null;return a}function rf(e,r,i){let a=n.CoordUtils.unionRanges(e,r,i);if(!a)return null;let o=e.scope,s=r.scope;if(o&&s){if(o!==s)return t.FormulaError.BuiltIn.Value;a.scope=o}else o||s?a.scope=o||s:a.scope&&=null;return a}var W,af=Object.freeze({break:!0});(W||={}).Type={BorderStyle:`borderStyle`,FillStyle:`fillStyle`,ContentStyle:`contentStyle`,Continuous:`continuous`,DateFormat:`dateFormat`,Table:`table`,AutoTable:`autoTable`,DataValidations:`dataValidations`,Merge:`merge`,Hyperlink:`hyperlink`,Comments:`comments`,Unlock:`unlock`,Contentful:`contentful`,Conditionals:`conditionals`,Formula:`formula`,Spills:`spills`,Pending:`pending`,CalcError:`calcError`,Circular:`circular`,Error:`error`,Validation:`dataValidation`};var of=Object.freeze({contentful:W.Type.Contentful,dateFormat:W.Type.DateFormat,error:W.Type.Error,formula:W.Type.Formula,spills:W.Type.Spills,calcError:W.Type.CalcError,circular:W.Type.Circular,fill:W.Type.FillStyle,borders:W.Type.BorderStyle,numberFormat:W.Type.ContentStyle,alignment:W.Type.ContentStyle,font:W.Type.ContentStyle,protection:W.Type.ContentStyle,merge:W.Type.Merge,table:W.Type.Table,autoTable:W.Type.AutoTable,hyperlink:W.Type.Hyperlink,comments:W.Type.Comments,unlock:W.Type.Unlock,conditionals:W.Type.Conditionals,dataValidations:W.Type.DataValidations});function sf(e){let t=function(e){if(e===void 0)return!0;let t=typeof e==`string`?[e]:e;if(t.length===0)return!1;let n={};for(let e=0;e<t.length;e++){let r=of[t[e]];r&&(n[r]=!1)}return n}(e);if(typeof t==`boolean`)return t;let n={...t};return delete n[W.Type.Contentful],n[W.Type.ContentStyle]!==void 0&&(n[W.Type.Continuous]=!1),n[W.Type.Formula]===void 0&&n[W.Type.CalcError]===void 0||(n[W.Type.Pending]=!1),n}function cf(e,t,n){switch(n){case`contentful`:case`error`:return null;case`borders`:return e.borderSpatial.getContentfulCoords();case`fill`:return e.fillSpatial.getContentfulCoords();case`numberFormat`:case`alignment`:case`font`:case`protection`:return e.contentSpatial.getContentfulCoords();case`dateFormat`:return e.dateFormatSpatial.getBoundingRange();case`merge`:return e.mergeSpatial.getContentfulCoords();case`formula`:return t.getFormulas().getBoundingRange();case`calcError`:return t.getCalcErrors().getBoundingRange();case`circular`:return t.getCirculars().getBoundingRange();case`spills`:return t.getSpills().getBoundingRange();case`table`:return e.tables.getBoundingRange();case`autoTable`:return e.autoTables.getBoundingRange();case`hyperlink`:return e.hyperlinkSpatial.getBoundingRange();case`comments`:return e.comments.getBoundingRange();case`unlock`:{let t=e.protectedRanges.getBoundingRange(),n=e.contentSpatial.getContentfulCoords();return t&&n?{colStart:Math.min(t.colStart,n.colStart),rowStart:Math.min(t.rowStart,n.rowStart),colEnd:Math.max(t.colEnd,n.colEnd),rowEnd:Math.max(t.rowEnd,n.rowEnd)}:t??n}case`conditionals`:return e.conditionalFormats.getBoundingRange();case`dataValidations`:return e.dataValidations.getBoundingRange()}}var G,lf,uf=Object.freeze({[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.DateFormat]:!1,[W.Type.AutoTable]:!1,[W.Type.Table]:!1,[W.Type.Merge]:!1,[W.Type.Hyperlink]:!1,[W.Type.Comments]:!1,[W.Type.Unlock]:!1,[W.Type.Formula]:!1,[W.Type.Spills]:!1,[W.Type.Pending]:!1,[W.Type.CalcError]:!1,[W.Type.Circular]:!1,[W.Type.Contentful]:!1,[W.Type.DataValidations]:!1,[W.Type.Conditionals]:!1,[W.Type.Continuous]:!1}),df=Object.freeze({[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.DateFormat]:!1,[W.Type.AutoTable]:!1,[W.Type.Table]:!1,[W.Type.Merge]:!1,[W.Type.Hyperlink]:!1,[W.Type.Comments]:!1,[W.Type.Unlock]:!1,[W.Type.Formula]:!1,[W.Type.Spills]:!1,[W.Type.Pending]:!1,[W.Type.CalcError]:!1,[W.Type.Circular]:!1,[W.Type.DataValidations]:!1,[W.Type.Conditionals]:!1,[W.Type.Continuous]:!1}),ff=Object.freeze({[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.DateFormat]:!1,[W.Type.Table]:!0,[W.Type.DataValidations]:!1,[W.Type.Merge]:!1,[W.Type.Hyperlink]:!1,[W.Type.Comments]:!1,[W.Type.Unlock]:!1,[W.Type.Formula]:!1}),pf=(Object.freeze({[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.DateFormat]:!1,[W.Type.Table]:!1,[W.Type.AutoTable]:!1,[W.Type.DataValidations]:!1,[W.Type.Hyperlink]:!1,[W.Type.Comments]:!1,[W.Type.Unlock]:!1,[W.Type.Contentful]:!1,[W.Type.Formula]:!1}),Object.freeze({[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.Hyperlink]:!1,[W.Type.Continuous]:!1,[W.Type.Merge]:!1,[W.Type.Contentful]:!1}));(lf=G||={}).AdjustmentType={Alpha:`alpha`,AlphaOff:`alphaOff`,AlphaMod:`alphaMod`,Hue:`hue`,Sat:`sat`,Lum:`lum`,HueOff:`hueOff`,SatOff:`satOff`,LumOff:`lumOff`,HueMod:`hueMod`,SatMod:`satMod`,LumMod:`lumMod`,Red:`red`,Green:`green`,Blue:`blue`,RedOff:`redOff`,GreenOff:`greenOff`,BlueOff:`blueOff`,RedMod:`redMod`,GreenMod:`greenMod`,BlueMod:`blueMod`,Shade:`shade`,Tint:`tint`,ETint:`eTint`,Gray:`gray`,Comp:`comp`,Inv:`inv`,Gamma:`gamma`,InvGamma:`invGamma`},lf.Named={ActiveBorder:`activeBorder`,ActiveCaption:`activeCaption`,CaptionText:`captionText`,AppWorkspace:`appWorkspace`,BtnFace:`btnFace`,BtnShadow:`btnShadow`,DkShadow3d:`3dDkShadow`,BtnHighlight:`btnHighlight`,Light3d:`3dLight`,BtnText:`btnText`,Background:`background`,GrayText:`grayText`,Highlight:`highlight`,HighlightText:`highlightText`,HotLight:`hotLight`,InactiveBorder:`inactiveBorder`,InactiveCaption:`inactiveCaption`,InactiveCaptionText:`inactiveCaptionText`,InfoBk:`infoBk`,InfoText:`infoText`,Menu:`menu`,MenuText:`menuText`,ScrollBar:`scrollBar`,Window:`window`,WindowFrame:`windowFrame`,WindowText:`windowText`,Transparent:`transparent`,AliceBlue:`aliceBlue`,AntiqueWhite:`antiqueWhite`,Aqua:`aqua`,Aquamarine:`aquamarine`,Azure:`azure`,Beige:`beige`,Bisque:`bisque`,Black:`black`,BlanchedAlmond:`blanchedAlmond`,Blue:`blue`,BlueViolet:`blueViolet`,Brown:`brown`,BurlyWood:`burlyWood`,CadetBlue:`cadetBlue`,Chartreuse:`chartreuse`,Chocolate:`chocolate`,Coral:`coral`,CornflowerBlue:`cornflowerBlue`,Cornsilk:`cornsilk`,Crimson:`crimson`,Cyan:`cyan`,DkBlue:`dkBlue`,DkCyan:`dkCyan`,DkGoldenrod:`dkGoldenrod`,DkGray:`dkGray`,DkGreen:`dkGreen`,DkKhaki:`dkKhaki`,DkMagenta:`dkMagenta`,DkOliveGreen:`dkOliveGreen`,DkOrange:`dkOrange`,DkOrchid:`dkOrchid`,DkRed:`dkRed`,DkSalmon:`dkSalmon`,DkSeaGreen:`dkSeaGreen`,DkSlateBlue:`dkSlateBlue`,DkSlateGray:`dkSlateGray`,DkTurquoise:`dkTurquoise`,DkViolet:`dkViolet`,DeepPink:`deepPink`,DeepSkyBlue:`deepSkyBlue`,DimGray:`dimGray`,DodgerBlue:`dodgerBlue`,Firebrick:`firebrick`,FloralWhite:`floralWhite`,ForestGreen:`forestGreen`,Fuchsia:`fuchsia`,Gainsboro:`gainsboro`,GhostWhite:`ghostWhite`,Gold:`gold`,Goldenrod:`goldenrod`,Gray:`gray`,Grey:`grey`,Green:`green`,GreenYellow:`greenYellow`,Honeydew:`honeydew`,HotPink:`hotPink`,IndianRed:`indianRed`,Indigo:`indigo`,Ivory:`ivory`,Khaki:`khaki`,Lavender:`lavender`,LavenderBlush:`lavenderBlush`,LawnGreen:`lawnGreen`,LemonChiffon:`lemonChiffon`,LtBlue:`ltBlue`,LtCoral:`ltCoral`,LtCyan:`ltCyan`,LtGoldenrodYellow:`ltGoldenrodYellow`,LtGray:`ltGray`,LtGreen:`ltGreen`,LtPink:`ltPink`,LtSalmon:`ltSalmon`,LtSeaGreen:`ltSeaGreen`,LtSkyBlue:`ltSkyBlue`,LtSlateGray:`ltSlateGray`,LtSteelBlue:`ltSteelBlue`,LtYellow:`ltYellow`,Lime:`lime`,LimeGreen:`limeGreen`,Linen:`linen`,Magenta:`magenta`,Maroon:`maroon`,MedAquamarine:`medAquamarine`,MedBlue:`medBlue`,MedOrchid:`medOrchid`,MedPurple:`medPurple`,MedSeaGreen:`medSeaGreen`,MedSlateBlue:`medSlateBlue`,MedSpringGreen:`medSpringGreen`,MedTurquoise:`medTurquoise`,MedVioletRed:`medVioletRed`,MidnightBlue:`midnightBlue`,MintCream:`mintCream`,MistyRose:`mistyRose`,Moccasin:`moccasin`,NavajoWhite:`navajoWhite`,Navy:`navy`,OldLace:`oldLace`,Olive:`olive`,OliveDrab:`oliveDrab`,Orange:`orange`,OrangeRed:`orangeRed`,Orchid:`orchid`,PaleGoldenrod:`paleGoldenrod`,PaleGreen:`paleGreen`,PaleTurquoise:`paleTurquoise`,PaleVioletRed:`paleVioletRed`,PapayaWhip:`papayaWhip`,PeachPuff:`peachPuff`,Peru:`peru`,Pink:`pink`,Plum:`plum`,PowderBlue:`powderBlue`,Purple:`purple`,Red:`red`,RosyBrown:`rosyBrown`,RoyalBlue:`royalBlue`,SaddleBrown:`saddleBrown`,Salmon:`salmon`,SandyBrown:`sandyBrown`,SeaGreen:`seaGreen`,SeaShell:`seaShell`,Sienna:`sienna`,Silver:`silver`,SkyBlue:`skyBlue`,SlateBlue:`slateBlue`,SlateGray:`slateGray`,Snow:`snow`,SpringGreen:`springGreen`,SteelBlue:`steelBlue`,Tan:`tan`,Teal:`teal`,Thistle:`thistle`,Tomato:`tomato`,Turquoise:`turquoise`,Violet:`violet`,Wheat:`wheat`,White:`white`,WhiteSmoke:`whiteSmoke`,Yellow:`yellow`,YellowGreen:`yellowGreen`,ButtonFace:`buttonFace`,ButtonHighlight:`buttonHighlight`,ButtonShadow:`buttonShadow`,GradientActiveCaption:`gradientActiveCaption`,GradientInactiveCaption:`gradientInactiveCaption`,MenuBar:`menuBar`,MenuHighlight:`menuHighlight`},lf.Scheme={Bg1:`bg1`,Bg2:`bg2`,Tx1:`tx1`,Tx2:`tx2`,Accent1:`accent1`,Accent2:`accent2`,Accent3:`accent3`,Accent4:`accent4`,Accent5:`accent5`,Accent6:`accent6`,Hlink:`hlink`,FolHlink:`folHlink`},lf.Type={Scheme:`scheme`,Named:`named`,Index:`index`,Auto:`auto`,HSL:`hsl`,RGB:`rgb`,LRGB:`lrgb`,Hex:`hex`};var mf=[[16777215,G.Named.Transparent,!0],[4290032820,G.Named.ActiveBorder,!0],[4288263377,G.Named.ActiveCaption,!0],[4278190080,G.Named.CaptionText,!0],[4289440683,G.Named.AppWorkspace,!0],[4293980400,G.Named.BtnFace,!0],[4285098345,G.Named.BtnShadow,!0],[4278190080,G.Named.DkShadow3d,!0],[4293125091,G.Named.BtnHighlight,!0],[4293125091,G.Named.Light3d,!0],[4278190080,G.Named.BtnText,!0],[4278190080,G.Named.Background,!0],[4285361517,G.Named.GrayText,!0],[4281571839,G.Named.Highlight,!0],[4294967295,G.Named.HighlightText,!0],[4278216396,G.Named.HotLight,!0],[4294244348,G.Named.InactiveBorder,!0],[4290760155,G.Named.InactiveCaption,!0],[4278190080,G.Named.InactiveCaptionText,!0],[4294967265,G.Named.InfoBk,!0],[4278190080,G.Named.InfoText,!0],[4293980400,G.Named.Menu,!0],[4278190080,G.Named.MenuText,!0],[4291348680,G.Named.ScrollBar,!0],[4294967295,G.Named.Window,!0],[4284769380,G.Named.WindowFrame,!0],[4278190080,G.Named.WindowText,!0],[16777215,G.Named.Transparent],[4293982463,G.Named.AliceBlue],[4294634455,G.Named.AntiqueWhite],[4278255615,G.Named.Aqua],[4286578644,G.Named.Aquamarine],[4293984255,G.Named.Azure],[4294309340,G.Named.Beige],[4294960324,G.Named.Bisque],[4278190080,G.Named.Black],[4294962125,G.Named.BlanchedAlmond],[4278190335,G.Named.Blue],[4287245282,G.Named.BlueViolet],[4289014314,G.Named.Brown],[4292786311,G.Named.BurlyWood],[4284456608,G.Named.CadetBlue],[4286578432,G.Named.Chartreuse],[4291979550,G.Named.Chocolate],[4294934352,G.Named.Coral],[4284782061,G.Named.CornflowerBlue],[4294965468,G.Named.Cornsilk],[4292613180,G.Named.Crimson],[4278255615,G.Named.Cyan],[4278190219,G.Named.DkBlue],[4278225803,G.Named.DkCyan],[4290283019,G.Named.DkGoldenrod],[4289309097,G.Named.DkGray],[4278215680,G.Named.DkGreen],[4290623339,G.Named.DkKhaki],[4287299723,G.Named.DkMagenta],[4283788079,G.Named.DkOliveGreen],[4294937600,G.Named.DkOrange],[4288230092,G.Named.DkOrchid],[4287299584,G.Named.DkRed],[4293498490,G.Named.DkSalmon],[4287609995,G.Named.DkSeaGreen],[4282924427,G.Named.DkSlateBlue],[4281290575,G.Named.DkSlateGray],[4278243025,G.Named.DkTurquoise],[4287889619,G.Named.DkViolet],[4294907027,G.Named.DeepPink],[4278239231,G.Named.DeepSkyBlue],[4285098345,G.Named.DimGray],[4280193279,G.Named.DodgerBlue],[4289864226,G.Named.Firebrick],[4294966e3,G.Named.FloralWhite],[4280453922,G.Named.ForestGreen],[4294902015,G.Named.Fuchsia],[4292664540,G.Named.Gainsboro],[4294506751,G.Named.GhostWhite],[4294956800,G.Named.Gold],[4292519200,G.Named.Goldenrod],[4286611584,G.Named.Gray],[4278222848,G.Named.Green],[4289593135,G.Named.GreenYellow],[4293984240,G.Named.Honeydew],[4294928820,G.Named.HotPink],[4291648604,G.Named.IndianRed],[4283105410,G.Named.Indigo],[4294967280,G.Named.Ivory],[4293977740,G.Named.Khaki],[4293322490,G.Named.Lavender],[4294963445,G.Named.LavenderBlush],[4286381056,G.Named.LawnGreen],[4294965965,G.Named.LemonChiffon],[4289583334,G.Named.LtBlue],[4293951616,G.Named.LtCoral],[4292935679,G.Named.LtCyan],[4294638200,G.Named.LtGoldenrodYellow],[4292072403,G.Named.LtGray],[4287688336,G.Named.LtGreen],[4294948545,G.Named.LtPink],[4294942842,G.Named.LtSalmon],[4280332970,G.Named.LtSeaGreen],[4287090426,G.Named.LtSkyBlue],[4286023833,G.Named.LtSlateGray],[4289774814,G.Named.LtSteelBlue],[4294967264,G.Named.LtYellow],[4278255360,G.Named.Lime],[4281519410,G.Named.LimeGreen],[4294635750,G.Named.Linen],[4294902015,G.Named.Magenta],[4286578688,G.Named.Maroon],[4284927402,G.Named.MedAquamarine],[4278190285,G.Named.MedBlue],[4290401747,G.Named.MedOrchid],[4287852763,G.Named.MedPurple],[4282168177,G.Named.MedSeaGreen],[4286277870,G.Named.MedSlateBlue],[4278254234,G.Named.MedSpringGreen],[4282962380,G.Named.MedTurquoise],[4291237253,G.Named.MedVioletRed],[4279834992,G.Named.MidnightBlue],[4294311930,G.Named.MintCream],[4294960353,G.Named.MistyRose],[4294960309,G.Named.Moccasin],[4294958765,G.Named.NavajoWhite],[4278190208,G.Named.Navy],[4294833638,G.Named.OldLace],[4286611456,G.Named.Olive],[4285238819,G.Named.OliveDrab],[4294944e3,G.Named.Orange],[4294919424,G.Named.OrangeRed],[4292505814,G.Named.Orchid],[4293847210,G.Named.PaleGoldenrod],[4288215960,G.Named.PaleGreen],[4289720046,G.Named.PaleTurquoise],[4292571283,G.Named.PaleVioletRed],[4294963157,G.Named.PapayaWhip],[4294957753,G.Named.PeachPuff],[4291659071,G.Named.Peru],[4294951115,G.Named.Pink],[4292714717,G.Named.Plum],[4289781990,G.Named.PowderBlue],[4286578816,G.Named.Purple],[4294901760,G.Named.Red],[4290547599,G.Named.RosyBrown],[4282477025,G.Named.RoyalBlue],[4287317267,G.Named.SaddleBrown],[4294606962,G.Named.Salmon],[4294222944,G.Named.SandyBrown],[4281240407,G.Named.SeaGreen],[4294964718,G.Named.SeaShell],[4288696877,G.Named.Sienna],[4290822336,G.Named.Silver],[4287090411,G.Named.SkyBlue],[4285160141,G.Named.SlateBlue],[4285563024,G.Named.SlateGray],[4294966010,G.Named.Snow],[4278255487,G.Named.SpringGreen],[4282811060,G.Named.SteelBlue],[4291998860,G.Named.Tan],[4278222976,G.Named.Teal],[4292394968,G.Named.Thistle],[4294927175,G.Named.Tomato],[4282441936,G.Named.Turquoise],[4293821166,G.Named.Violet],[4294303411,G.Named.Wheat],[4294967295,G.Named.White],[4294309365,G.Named.WhiteSmoke],[4294967040,G.Named.Yellow],[4288335154,G.Named.YellowGreen],[4293980400,G.Named.ButtonFace],[4294967295,G.Named.ButtonHighlight],[4288716960,G.Named.ButtonShadow],[4290367978,G.Named.GradientActiveCaption],[4292338930,G.Named.GradientInactiveCaption],[4293980400,G.Named.MenuBar],[4281571839,G.Named.MenuHighlight],[4286611584,G.Named.Grey]],hf=new class{constructor(){this._lookupByName=new Map;let e=mf.length;for(let t=0;t<e;t++){let e=mf[t],n=e[0],r=(n>>24&255)/255,i=n>>16&255,a=n>>8&255,o=255&n,s={id:t,name:e[1],rgbaColor:{r:i,g:a,b:o,a:r},system:e.length>2};this._lookupByName.set(s.name.toLowerCase(),s)}}valueOfName(e){return this._lookupByName.get(e?e.toLowerCase():`transparent`)}getSystemColorDefaults(){let e=e=>e.toString(16).padStart(2,`0`).toUpperCase(),t={};return this._lookupByName.forEach((n,r)=>{if(!n.system)return;let{r:i,g:a,b:o}=n.rgbaColor;t[r]=`#${e(i)}${e(a)}${e(o)}`}),t}},gf=[{scheme:G.Scheme.Tx1,description:`First Text Color`},{scheme:G.Scheme.Tx2,description:`Second Text Color`},{scheme:G.Scheme.Bg1,description:`First Background Color`},{scheme:G.Scheme.Bg2,description:`Second Background Color`},{scheme:G.Scheme.Accent1,description:`Accent 1`},{scheme:G.Scheme.Accent2,description:`Accent 2`},{scheme:G.Scheme.Accent3,description:`Accent 3`},{scheme:G.Scheme.Accent4,description:`Accent 4`},{scheme:G.Scheme.Accent5,description:`Accent 5`},{scheme:G.Scheme.Accent6,description:`Accent 6`},{scheme:G.Scheme.Hlink,description:`Hyperlink`},{scheme:G.Scheme.FolHlink,description:`Followed Hyperlink`},{scheme:`dk1`,description:`Text/Background - Dark 1`},{scheme:`lt1`,description:`Text/Background - Light 1`},{scheme:`dk2`,description:`Text/Background - Dark 2`},{scheme:`lt2`,description:`Text/Background - Light 2`}],_f=new Map;for(let e=0;e<gf.length;e++)_f.set(gf[e].scheme.toLowerCase(),gf[e]);var vf=`lastclr`,yf=e=>{if(!e)return null;let t=e.replace(`#`,``);if(t.length<6)return null;let n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return isNaN(n)||isNaN(r)||isNaN(i)?null:new ks.RGBA(n,r,i,1)},bf=e=>new ks.HEX(e.red,e.green,e.blue,1).toString(!1).replace(`#`,``),xf=e=>new ks.RGBA(e.rgbaColor.r,e.rgbaColor.g,e.rgbaColor.b,e.rgbaColor.a),Sf=(e,t,n)=>{let r=hf.valueOfName(e);if(!r)return null;if(r.system){let e=r.name;return{rgba:(t?t(e,!1):null)?.toRGBA()??n??xf(r),systemName:e}}return{rgba:xf(r),systemName:null}},Cf=e=>{if(!e)return null;let t=e.getAdjustments();if(t&&t.length>0)return null;let n=e.getType();return n===G.Type.Auto?G.Named.WindowText:n===G.Type.Named&&zf.isSystem(e.getVal())?e.getVal():null},wf=e=>e?{srgb:[e.red/255,e.green/255,e.blue/255],alpha:e.alpha===void 0?1:e.alpha}:null,Tf=function(e,t,n,r,i){let a,o=null,s=null,c=null,l=G.Type.Named;if(e.toLowerCase()===`auto`){let e=Sf(G.Named.WindowText,r,i);a=wf(e.rgba),o=e.systemName,l=G.Type.Auto}else{let t=Sf(e,r,i);a=wf(t?.rgba??null),o=t?.systemName??null}if(a===null&&((u=e)===`phClr`&&(u=`dk1`),_f.get(u.toLowerCase()))){if(!t)throw Error(`a scheme val was used but a schemeLookup was not provided`);s=e;let n=t(s);c=n.toRGBA(),a=wf(c),o=Cf(n),l=G.Type.Scheme}var u;if(a===null){let t=e.match(Ls)||e.match(Rs);if(t){let e,n=1;t.length===4?e=[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:(e=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16)],n=Gs(parseInt(t[1],16)/255)),e=Vs(e),e=Ws(e),a={srgb:e,alpha:n},l=G.Type.Hex}}if(a===null){let t=e.match(js)||e.match(Ms);if(t){let e=Bs(t[1],t[2],t[3]);e=Vs(e),e=Ws(e),a={srgb:e,alpha:t[4]?Gs(parseFloat(t[4])):1},l=G.Type.RGB}}if(a===null){let t=e.match(Ns)||e.match(Ps);if(t){let e=Bs(t[1],t[2],t[3]);e=Vs(e,100),e=Js(e),e=Ws(e),a={srgb:e,alpha:t[4]?Gs(parseFloat(t[4])):1},l=G.Type.LRGB}}if(a===null){let t=e.match(Fs)||e.match(Is);if(t){let e=Bs(t[1],t[2],t[3]);e=Zs(e),e=Ws(e),a={srgb:e,alpha:t[4]?Gs(parseFloat(t[4])):1},l=G.Type.HSL}}if(a===null){let t=e.match(zs);if(t){let e=parseInt(t[1]),s=n?.(e),c=s?null:Mc(e),u=s?s.toRGBA():c?Sf(c,r,i).rgba:Nc(e);u&&(a={srgb:[u.red/255,u.green/255,u.blue/255],alpha:u.alpha},o=s?Cf(s):c,l=G.Type.Index)}}if(a===null)throw Error(`Not a valid color format: `+e);return{srgbAlpha:a,key:s,color:c,type:l,systemName:o}},Ef=(e,t)=>{let n=[...e.srgb],r=e.alpha===void 0?1:e.alpha,i=t?t.length:0;for(var a=0;a<i;a++){let e=t[a],i=Object.keys(e)[0],o=e[i];i===G.AdjustmentType.Alpha?(r=o/100,r=Math.max(0,Math.min(1,r))):i===G.AdjustmentType.AlphaOff?(r+=o/100,r=Math.max(0,Math.min(1,r))):i===G.AdjustmentType.AlphaMod?(r*=o/100,r=Math.max(0,Math.min(1,r))):i===G.AdjustmentType.Hue?n=pc(ec,n,o):i===G.AdjustmentType.Sat?n=pc(tc,n,o):i===G.AdjustmentType.Lum?n=pc(nc,n,o):i===G.AdjustmentType.HueOff?n=mc(ec,n,o):i===G.AdjustmentType.SatOff?n=mc(tc,n,o):i===G.AdjustmentType.LumOff?n=mc(nc,n,o):i===G.AdjustmentType.HueMod?n=hc(ec,n,o):i===G.AdjustmentType.SatMod?n=hc(tc,n,o):i===G.AdjustmentType.LumMod?n=hc(nc,n,o):i===G.AdjustmentType.Red?n=gc(rc,n,o,oc):i===G.AdjustmentType.Green?n=gc(ic,n,o,oc):i===G.AdjustmentType.Blue?n=gc(ac,n,o,oc):i===G.AdjustmentType.RedOff?n=gc(rc,n,o,sc):i===G.AdjustmentType.GreenOff?n=gc(ic,n,o,sc):i===G.AdjustmentType.BlueOff?n=gc(ac,n,o,sc):i===G.AdjustmentType.RedMod?n=gc(rc,n,o,cc):i===G.AdjustmentType.GreenMod?n=gc(ic,n,o,cc):i===G.AdjustmentType.BlueMod?n=gc(ac,n,o,cc):i===G.AdjustmentType.Shade?n=lc(n,o):i===G.AdjustmentType.Tint?n=fc(n,o):i===G.AdjustmentType.ETint?n=dc(n,o):i===G.AdjustmentType.Gray?n=_c(n):i===G.AdjustmentType.Comp?n=vc(n):i===G.AdjustmentType.Inv?n=yc(n,o):i===G.AdjustmentType.Gamma?n=bc(n):i===G.AdjustmentType.InvGamma?n=xc(n):console.warn(`unknown adjustmentType: `+i)}return{srgb:n,alpha:r}},Df=new Map,Of=Object.keys(G.AdjustmentType),kf=Of.length;for(let e=0;e<kf;e++){let t=Of[e];Df.set(G.AdjustmentType[t].toLowerCase(),G.AdjustmentType[t])}var K,Af,q,jf,Mf=RegExp(`\\s+\\s*(?![^()]*\\))|,\\s*(?![^()]*\\))`),Nf=RegExp(`\\s*[,]\\s*|\\s+`),Pf=null,Ff=null,If=`--sxl-sys-color-`,Lf=0,Rf={[G.Scheme.Bg1]:`window`,[G.Scheme.Bg2]:`E8E8E8`,[G.Scheme.Tx1]:`windowText`,[G.Scheme.Tx2]:`0E2841`,[G.Scheme.Accent1]:`156082`,[G.Scheme.Accent2]:`E97132`,[G.Scheme.Accent3]:`196B24`,[G.Scheme.Accent4]:`0F9ED5`,[G.Scheme.Accent5]:`A02B93`,[G.Scheme.Accent6]:`4EA72E`,[G.Scheme.Hlink]:`467886`,[G.Scheme.FolHlink]:`96607D`},zf=class e{constructor(t,n,r,i=null,a){let o=null,s=null,c=i;if(t instanceof e)o=t.getVal(),t.getAdjustments()&&(s=[...t.getAdjustments()]),c??=t._private.last;else if(typeof t==`string`){let e=this._parse(t);o=e.val,s=e.adjs,e.last&&(c=yf(e.last))}else if(t?.val){o=t.val,s=t.adjs;let e=t.last;e&&(c=yf(e))}if(!o)throw Error(`Unable to determine color value`);let l=a??Ff;this._private={val:o,last:c,adjs:s,schemeLookup:n,indexedLookup:r,systemLookup:a,parsedVal:Tf(o,n,r,l,c),adjusted:null,resolved:null,resolvedEpoch:Lf}}_parse(e){let t=null,n=e.trim(),r=n.split(Mf);if(r&&(t=r[0],n=n.substring(t.length,n.length).trim()),!t)throw Error(`no color key found`);let i=[],a=null,o=n.split(Nf),s=o.length;for(let e=0;e<s;e++){let t=o[e];if(!t)continue;if(t.toLowerCase()===vf){e++,a=o[e];continue}let n=Df.get(t.toLowerCase());if(!n)throw Error(`Invalid adjustment type:`+t);let r=null;if(n!==G.AdjustmentType.Gray&&n!==G.AdjustmentType.Comp&&n!==G.AdjustmentType.Inv&&n!==G.AdjustmentType.Gamma&&n!==G.AdjustmentType.InvGamma){e++;let n=o[e];if(r=parseFloat(n),r==null)throw Error(`Invalid adjustment value: missing value for'${t}'`);if(isNaN(r))throw Error(`Invalid adjustment value:`+n)}i.push({[n]:r})}return{val:t,last:a,adjs:i}}_forceDark(e=!0){this._resolve();let t=this._private.parsedVal,n=this._private.systemLookup??Ff;if(t.systemName&&n){let r=n(t.systemName,!0);if(r){let t=Ef(wf(r.toRGBA()),this._private.adjs),n=Gs(t.alpha);if(e){let e=Us(Hs([...t.srgb]));return new ks.RGBA(e[0],e[1],e[2],n)}let i=$s(t.srgb);return new ks.HSLA(i[0],i[1],i[2],n)}}let r=this._private.resolved,i=[r.red,r.green,r.blue];i=((e,t)=>{t=(t%360+360)%360;let n=[1,0,0,0,1,0,0,0,1],r=Math.cos(t*Math.PI/180),i=Math.sin(t*Math.PI/180);n[0]=Cc+.7874*r-Cc*i,n[1]=wc-wc*r-wc*i,n[2]=Tc-Tc*r+.9278*i,n[3]=Cc-Cc*r+.143*i,n[4]=wc+(1-wc)*r+.14*i,n[5]=Tc-Tc*r-.283*i,n[6]=Cc-Cc*r-.7874*i,n[7]=wc-wc*r+wc*i,n[8]=Tc+.9278*r+Tc*i;let a=e=>Math.round(Math.max(0,Math.min(255,e))),o=e[0],s=e[1],c=e[2];return[a(n[0]*o+n[1]*s+n[2]*c),a(n[3]*o+n[4]*s+n[5]*c),a(n[6]*o+n[7]*s+n[8]*c)]})(i,180),i=yc(i,!1);let a=qs(i),o=$s(a);if(o[nc]=.95*o[nc],a=Zs(o),i=Js(a),i=Us(i),i=Ws(i,!1),e)return new ks.RGBA(i[0],i[1],i[2],r.alpha);let s=$s(qs(i));return new ks.HSLA(s[0],s[1],s[2],r.alpha)}_resolve(){if(this._private.resolved){let e=this._private.parsedVal;if(!e.key&&!e.systemName)return;if(e.systemName){if(this._private.resolvedEpoch===Lf)return}else{let t=this._private.schemeLookup(e.key)?.toRGBA();if(t===e.color||t?.isEqual(e.color))return}}let e=this._private.systemLookup??Ff,t=Tf(this._private.val,this._private.schemeLookup,this._private.indexedLookup,e,this._private.last),n=t.srgbAlpha,r=Ef(n,this._private.adjs),i=Hs(r.srgb);i=Us(i);let a=Gs(r.alpha);this._private.adjusted=r,this._private.parsedVal=t,this._private.resolved=new ks.RGBA(i[0],i[1],i[2],a),this._private.resolvedEpoch=Lf}static parse(t,n,r,i=null,a){if(t instanceof e)return t;let o=t,s=null,c=o?.trim(),l=null;try{if(!s){let e=c?.split(Mf);e&&(s=e[0],c=c.substring(s.length,c.length).trim())}if(!s)throw Error(`no color found`);let t=[],o=null,u=c.split(Nf),d=u.length;for(let e=0;e<d;e++){let n=u[e];if(!n)continue;if(n.toLowerCase()===vf){e++,o=u[e];continue}let r=Df.get(n.toLowerCase());if(!r)throw Error(`Invalid adjustment type:`+n);let i=null;if(r!==G.AdjustmentType.Gray&&r!==G.AdjustmentType.Comp&&r!==G.AdjustmentType.Inv&&r!==G.AdjustmentType.Gamma&&r!==G.AdjustmentType.InvGamma){e++;let t=u[e];if(i=parseFloat(t),i==null)throw Error(`Invalid adjustment value: missing value for'${n}'`);if(isNaN(i))throw Error(`Invalid adjustment value:`+t)}t.push({[r]:i})}l=new e({val:s,adjs:t,last:o},n,r,i,a)}catch(e){throw e}return l}static isSystem(e){return!!e&&!0===hf.valueOfName(e)?.system}static getDefaultSystemLookup(){return Ff}static setDefaultSystemLookup(e){let t=Ff;return Ff=e??null,Lf++,t}static getSystemEpoch(){return Lf}static invalidateSystemColors(){Lf++}static getSystemColorDefaults(){return hf.getSystemColorDefaults()}static getDefaultSchemeLookup(){if(!Pf){let t=new Map,n=Object.keys(Rf),r=n.length;for(let i=0;i<r;i++){let r=n[i];t.set(r.toLowerCase(),e.parse(Rf[r],null))}Pf=e=>t.get(e.toLowerCase())}return Pf}isEqual(t){return t instanceof e&&this.toString().toLowerCase()===t.toString().toLowerCase()}getVal(){return this._private.val}getAdjustments(){return this._private.adjs}getBaseColor(){return new e({val:this._private.val,adjs:null},this._private.schemeLookup,this._private.indexedLookup,this._private.last,this._private.systemLookup)}getLastColor(){return this._private.last&&this._private.parsedVal.systemName?bf(this._private.last):null}getType(){return this._resolve(),this._private.parsedVal.type??null}adjust(t){return new e({val:this._private.val,adjs:this._private.adjs?this._private.adjs.concat(t):t},this._private.schemeLookup,this._private.indexedLookup,this._private.last,this._private.systemLookup)}_systemCSSVar(e){this._resolve();let t=this._private.parsedVal;if(!t.systemName||this._private.adjs&&this._private.adjs.length>0)return null;let n=t.systemName.toLowerCase(),r=Sf(t.systemName,null,this._private.last).rgba,i=`#`+bf(r),a=`${If}${n}`;return e?`var(${a}-dark, var(${a}, ${i}))`:`var(${a}, ${i})`}toCSS(e=!1,t=!1){if(e===`adaptive`){let e=this.toCSS(!1,t),n=this.toCSS(!0,t);return e===n?e:`light-dark(${e}, ${n})`}let n=!0===e,r=this._systemCSSVar(n);if(r)return r;let i=n?this._forceDark():this.toRGBA();return i.alpha===0?`none`:i.toString(t)}toRGBA(e=!1){return this._resolve(),e?this._forceDark():this._private.resolved}toHSLA(e=!1){if(this._resolve(),e)return this._forceDark(!1);let t=$s(this._private.adjusted.srgb);return new ks.HSLA(t[0],t[1],t[2],Gs(this._private.adjusted.alpha??1))}toHex(e=!1){this._resolve();let t=e?this._forceDark():this._private.resolved;return new ks.HEX(t.red,t.green,t.blue,t.alpha??1)}toBlackOrWhite(t=!1,n=157){let r=this.toRGBA(t),i=.299*r.red+.587*r.green+.114*r.blue>n;return new e(i?`#000000`:`#FFFFFF`,this._private.schemeLookup,this._private.indexedLookup,this._private.last,this._private.systemLookup)}get[Symbol.toStringTag](){return this.toString()}toString(){let e=this._private.val,t=this._private.adjs,n=t?t.length:0;for(let r=0;r<n;r++){let i=t[r];if(!i)continue;let a=Object.keys(i)[0];e+=` `+a;let o=i[a];typeof o==`number`&&(e+=` `+o),r<n-1&&(e+=`,`)}let r=this.getLastColor();return r&&(e+=` lastClr `+r),e}get isIColor(){return!0}};(Af=K||={}).Type={None:`none`,Solid:`solid`,Gradient:`gradient`,Pattern:`pattern`,Image:`pattern`,Background:`background`,Group:`group`,Custom:`custom`},Af.GradientType={Linear:`linear`,Path:`path`,Rect:`rect`,Shape:`shape`},Af.TileMirror={None:`none`,Vertical:`v`,Horizontal:`h`,Both:`b`},Af.BuiltInSheetPattern={None:`none`,Solid:`solid`,DarkGray:`darkGray`,MediumGray:`mediumGray`,LightGray:`lightGray`,Gray0625:`gray0625`,Gray125:`gray125`,DarkHorizontal:`darkHorizontal`,DarkVertical:`darkVertical`,DarkDown:`darkDown`,DarkUp:`darkUp`,DarkGrid:`darkGrid`,DarkTrellis:`darkTrellis`,LightHorizontal:`lightHorizontal`,LightVertical:`lightVertical`,LightDown:`lightDown`,LightUp:`lightUp`,LightGrid:`lightGrid`,LightTrellis:`lightTrellis`,Custom:`custom`},function(e){let t=e.BuiltInName={Normal:`Normal`,RowLevel:`RowLevel_#`,ColLevel:`ColLevel_#`,Comma:`Comma`,Currency:`Currency`,Percent:`Percent`,Comma0:`Comma [0]`,Currency0:`Currency [0]`,Hyperlink:`Hyperlink`,FollowedHyperlink:`Followed Hyperlink`,Note:`Note`,WarningText:`Warning Text`,Unknown12:`??-12`,Unknown13:`??-13`,Unknown14:`??-14`,Title:`Title`,Heading1:`Heading 1`,Heading2:`Heading 2`,Heading3:`Heading 3`,Heading4:`Heading 4`,Input:`Input`,Output:`Output`,Calculation:`Calculation`,CheckCell:`Check Cell`,LinkedCell:`Linked Cell`,Total:`Total`,Good:`Good`,Bad:`Bad`,Neutral:`Neutral`,Accent1:`Accent1`,Accent1_20:`20% - Accent1`,Accent1_40:`40% - Accent1`,Accent1_60:`60% - Accent1`,Accent2:`Accent2`,Accent2_20:`20% - Accent2`,Accent2_40:`40% - Accent2`,Accent2_60:`60% - Accent2`,Accent3:`Accent3`,Accent3_20:`20% - Accent3`,Accent3_40:`40% - Accent3`,Accent3_60:`60% - Accent3`,Accent4:`Accent4`,Accent4_20:`20% - Accent4`,Accent4_40:`40% - Accent4`,Accent4_60:`60% - Accent4`,Accent5:`Accent5`,Accent5_20:`20% - Accent5`,Accent5_40:`40% - Accent5`,Accent5_60:`60% - Accent5`,Accent6:`Accent6`,Accent6_20:`20% - Accent6`,Accent6_40:`40% - Accent6`,Accent6_60:`60% - Accent6`,ExplanatoryText:`Explanatory Text`},n=Object.values(t);e.builtInNameFromId=function(e){return n[e]},e.IconSet={Arrows3:`3Arrows`,ArrowsGray3:`3ArrowsGray`,Flags3:`3Flags`,Signs3:`3Signs`,Symbols3:`3Symbols`,Symbols3_2:`3Symbols2`,TrafficLights3:`3TrafficLights1`,TrafficLights3_2:`3TrafficLights2`,Triangles3:`3Triangles`,Stars3:`3Stars`,Arrows4:`4Arrows`,ArrowsGray4:`4ArrowsGray`,Rating4:`4Rating`,RedToBlack4:`4RedToBlack`,TrafficLights4:`4TrafficLights`,Arrows5:`5Arrows`,ArrowsGray5:`5ArrowsGray`,Quarters5:`5Quarters`,Rating5:`5Rating`,Boxes5:`5Boxes`,NoIcons:`NoIcons`}}(q||={}),(jf||={}).BuiltInFilterType={BuiltIn:`builtIn`,All:`all`,Custom:`custom`};var Bf,Vf,Hf,Uf=[[`Office`,`windowText`,`window`,`0E2841`,`E8E8E8`,`156082`,`E97132`,`196B24`,`0F9ED5`,`A02B93`,`4EA72E`,`467886`,`96607D`],[`Office 2013-2022`,`windowText`,`window`,`44546A`,`E7E6E6`,`4472C4`,`ED7D31`,`A5A5A5`,`FFC000`,`5B9BD5`,`70AD47`,`0563C1`,`954F72`],[`Office 2007-2010`,`windowText`,`window`,`1F497D`,`EEECE1`,`4F81BD`,`C0504D`,`9BBB59`,`8064A2`,`4BACC6`,`F79646`,`0000FF`,`800080`],[`Grayscale`,`windowText`,`window`,`000000`,`F8F8F8`,`DDDDDD`,`B2B2B2`,`969696`,`808080`,`5F5F5F`,`4D4D4D`,`5F5F5F`,`919191`],[`Atlas`,`windowText`,`window`,`454545`,`E0E0E0`,`F81B02`,`FC7715`,`AFBF41`,`50C49F`,`3B95C4`,`B560D4`,`FC5A1A`,`B49E74`],[`Banded`,`2C2C2C`,`FFFFFF`,`099BDD`,`F2F2F2`,`FFC000`,`A5D028`,`08CC78`,`F24099`,`828288`,`F56617`,`005DBA`,`6C606A`],[`Basis`,`000000`,`FFFFFF`,`565349`,`DDDDDD`,`A6B727`,`DF5327`,`FE9E00`,`418AB3`,`D7D447`,`818183`,`F59E00`,`B2B2B2`],[`Berlin`,`windowText`,`window`,`9D360E`,`E7E6E6`,`F09415`,`C1B56B`,`4BAF73`,`5AA6C0`,`D17DF9`,`FA7E5C`,`FFAE3E`,`FCC77E`],[`Celestial`,`windowText`,`window`,`18276C`,`EBEBEB`,`AC3EC1`,`477BD1`,`46B298`,`90BA4C`,`DD9D31`,`E25247`,`C573D2`,`CCAEE8`],[`Circuit`,`windowText`,`window`,`134770`,`82FFFF`,`9ACD4C`,`FAA93A`,`D35940`,`B258D3`,`63A0CC`,`8AC4A7`,`B8FA56`,`7AF8CC`],[`Damask`,`windowText`,`window`,`2A5B7F`,`ABDAFC`,`9EC544`,`50BEA3`,`4A9CCC`,`9A66CA`,`C54F71`,`DE9C3C`,`6BA9DA`,`A0BCD3`],[`Depth`,`windowText`,`window`,`455F51`,`94D7E4`,`41AEBD`,`97E9D5`,`A2CF49`,`608F3D`,`F4DE3A`,`FCB11C`,`FBCA98`,`D3B86D`],[`Dividend`,`windowText`,`window`,`3D3D3D`,`EBEBEB`,`4D1434`,`903163`,`B2324B`,`969FA7`,`66B1CE`,`40619D`,`828282`,`A5A5A5`],[`Droplet`,`windowText`,`window`,`355071`,`AABED7`,`2FA3EE`,`4BCAAD`,`86C157`,`D99C3F`,`CE6633`,`A35DD1`,`56BCFE`,`97C5E3`],[`Facet`,`windowText`,`window`,`2C3C43`,`EBEBEB`,`90C226`,`54A021`,`E6B91E`,`E76618`,`C42F1A`,`918655`,`99CA3C`,`B9D181`],[`Frame`,`000000`,`FFFFFF`,`545454`,`BFBFBF`,`40BAD2`,`FAB900`,`90BB23`,`EE7008`,`1AB39F`,`D5393D`,`90BB23`,`EE7008`],[`Gallery`,`windowText`,`window`,`454545`,`DFDBD5`,`B71E42`,`DE478E`,`BC72F0`,`795FAF`,`586EA6`,`6892A0`,`FA2B5C`,`BC658E`],[`Integral`,`windowText`,`window`,`335B74`,`DFE3E5`,`1CADE4`,`2683C6`,`27CED7`,`42BA97`,`3E8853`,`62A39F`,`6B9F25`,`B26B02`],[`Ion Boardroom`,`windowText`,`window`,`3B3059`,`EBEBEB`,`B31166`,`E33D6F`,`E45F3C`,`E9943A`,`9B6BF2`,`D53DD0`,`8F8F8F`,`A5A5A5`],[`Ion`,`windowText`,`window`,`1E5155`,`EBEBEB`,`B01513`,`EA6312`,`E6B729`,`6AAC90`,`54849A`,`9E5E9B`,`58C1BA`,`9DFFCB`],[`Madison`,`windowText`,`window`,`1F2D29`,`C5FAEB`,`A1D68B`,`5EC795`,`4DADCF`,`CDB756`,`E29C36`,`8EC0C1`,`6D9D9B`,`6D8583`],[`Main Event`,`windowText`,`window`,`424242`,`C8C8C8`,`B80E0F`,`A6987D`,`7F9A71`,`64969F`,`9B75B2`,`80737A`,`F21213`,`B6A394`],[`Mesh`,`windowText`,`window`,`363D46`,`EBEBEB`,`6F6F6F`,`BFBFA5`,`DCD084`,`E7BF5F`,`E9A039`,`CF7133`,`F28943`,`F1B76C`],[`Metropolitan`,`windowText`,`window`,`162F33`,`EAF0E0`,`50B4C8`,`A8B97F`,`9B9256`,`657689`,`7A855D`,`84AC9D`,`2370CD`,`877589`],[`Organic`,`windowText`,`window`,`212121`,`DADADA`,`83992A`,`3C9770`,`44709D`,`A23C33`,`D97828`,`DEB340`,`A8BF4D`,`B4CA80`],[`Parallax`,`windowText`,`window`,`212121`,`CDD0D1`,`30ACEC`,`80C34F`,`E29D3E`,`D64A3B`,`D64787`,`A666E1`,`3085ED`,`82B6F4`],[`Parcel`,`000000`,`FFFFFF`,`4A5356`,`E8E3CE`,`F6A21D`,`9BAFB5`,`C96731`,`9CA383`,`87795D`,`A0988C`,`00B0F0`,`738F97`],[`Quotable`,`windowText`,`window`,`212121`,`636363`,`00C6BB`,`6FEBA0`,`B6DF5E`,`EFB251`,`EF755F`,`ED515C`,`8F8F8F`,`A5A5A5`],[`Retrospect`,`000000`,`window`,`637052`,`CCDDEA`,`E48312`,`BD582C`,`865640`,`9B8357`,`C2BC80`,`94A088`,`2998E3`,`8C8C8C`],[`Savon`,`windowText`,`window`,`1485A4`,`E3DED1`,`1CADE4`,`2683C6`,`27CED7`,`42BA97`,`3E8853`,`62A39F`,`F49100`,`739D9B`],[`Slate`,`windowText`,`window`,`212123`,`DADADA`,`BC451B`,`D3BA68`,`BB8640`,`AD9277`,`A55A43`,`AD9D7B`,`E98052`,`F4B69B`],[`Slice`,`windowText`,`window`,`146194`,`76DBF4`,`052F61`,`A50E82`,`14967C`,`6A9E1F`,`E87D37`,`C62324`,`0D2E46`,`356A95`],[`Vapor Trail`,`windowText`,`window`,`454545`,`DADADA`,`DF2E28`,`FE801A`,`E9BF35`,`81BB42`,`32C7A9`,`4A9BDC`,`F0532B`,`F38B53`],[`View`,`000000`,`FFFFFF`,`46464A`,`D6D3CC`,`6F6F74`,`92A9B9`,`A7B789`,`B9A489`,`8D6374`,`9B7362`,`67AABF`,`ABAFA5`],[`Wisp`,`windowText`,`window`,`766F54`,`E3EACF`,`A53010`,`DE7E18`,`9F8351`,`728653`,`92AA4C`,`6AAC91`,`FB4A18`,`FB9318`],[`Wood Type`,`windowText`,`window`,`696464`,`E9E5DC`,`D34817`,`9B2D1F`,`A28E6A`,`956251`,`918485`,`855D5D`,`CC9900`,`96A9A9`]],Wf=[[`Office`,`Calibri Light`,`Calibri`],[`Office 2013-2022`,`Calibri Light`,`Calibri`],[`Office 2007-2010`,`Calibri Light`,`Calibri`],[`Grayscale`,`Calibri Light`,`Calibri`],[`Atlas`,`Calibri Light`,`Rockwell`],[`Banded`,`Corbel`,`Corbel`],[`Basis`,`Corbel`,`Corbel`],[`Berlin`,`Trebuchet MS`,`Trebuchet MS`],[`Celestial`,`Calibri Light`,`Calibri`],[`Circuit`,`Tw Cen MT`,`Tw Cen MT`],[`Damask`,`Bookman Old Style`,`Rockwell`],[`Depth`,`Corbel`,`Corbel`],[`Madison`,`Arial`,`Arial`],[`Main Event`,`Impact`,`Impact`],[`Mesh`,`Century Gothic`,`Century Gothic`],[`Metropolitan`,`Calibri Light`,`Calibri Light`],[`Organic`,`Garamond`,`Garamond`],[`Parallax`,`Corbel`,`Corbel`],[`Parcel`,`Gill Sans MT`,`Gill Sans MT`],[`Quotable`,`Century Gothic`,`Century Gothic`],[`Retrospect`,`Calibri Light`,`Calibri`],[`Savon`,`Century Gothic`,`Century Gothic`],[`Slate`,`Calisto MT`,`Calisto MT`],[`Slice`,`Century Gothic`,`Century Gothic`],[`Vapor Trail`,`Century Gothic`,`Century Gothic`],[`View`,`Century Schoolbook`,`Century Schoolbook`],[`Wisp`,`Century Gothic`,`Century Gothic`],[`Wood Type`,`Rockwell Condensed`,`Rockwell`]],Gf=[[`Office`,`Office`,`Office`],[`2013-2022`,`Office 2013-2022`,`Office 2013-2022`],[`Atlas`,`Atlas`,`Atlas`],[`Banded`,`Banded`,`Banded`],[`Basis`,`Basis`,`Basis`],[`Berlin`,`Berlin`,`Berlin`],[`Celestial`,`Celestial`,`Celestial`],[`Circuit`,`Circuit`,`Circuit`],[`Damask`,`Damask`,`Damask`],[`Depth`,`Depth`,`Depth`],[`Dividend`,`Dividend`,`Dividend`],[`Droplet`,`Droplet`,`Droplet`],[`Facet`,`Facet`,`Facet`],[`Frame`,`Frame`,`Frame`],[`Gallery`,`Gallery`,`Gallery`],[`Grayscale`,`Grayscale`,`Grayscale`],[`Integral`,`Integral`,`Integral`],[`Ion Boardroom`,`Ion Boardroom`,`Ion Boardroom`],[`Ion`,`Ion`,`Ion`],[`Madison`,`Madison`,`Madison`],[`Main Event`,`Main Event`,`Main Event`],[`Mesh`,`Mesh`,`Mesh`],[`Metropolitan`,`Metropolitan`,`Metropolitan`],[`Organic`,`Organic`,`Organic`],[`Parallax`,`Parallax`,`Parallax`],[`Parcel`,`Parcel`,`Parcel`],[`Quotable`,`Quotable`,`Quotable`],[`Retrospect`,`Retrospect`,`Retrospect`],[`Savon`,`Savon`,`Savon`],[`Slate`,`Slate`,`Slate`],[`Slice`,`Slice`,`Slice`],[`Vapor Trail`,`Vapor Trail`,`Vapor Trail`],[`View`,`View`,`View`],[`Wisp`,`Wisp`,`Wisp`],[`Wood Type`,`Wood Type`,`Wood Type`],[`Office 2007-2010`,`Office 2007-2010`,`Office 2007-2010`]],Kf=`Themes is readonly. To make modifications create a new DocsThemes instance.`,qf={[G.Scheme.Bg1]:`lt1`,[G.Scheme.Bg2]:`lt2`,[G.Scheme.Tx1]:`dk1`,[G.Scheme.Tx2]:`dk2`,[G.Scheme.Accent1]:`accent1`,[G.Scheme.Accent2]:`accent2`,[G.Scheme.Accent3]:`accent3`,[G.Scheme.Accent4]:`accent4`,[G.Scheme.Accent5]:`accent5`,[G.Scheme.Accent6]:`accent6`,[G.Scheme.Hlink]:`hlink`,[G.Scheme.FolHlink]:`folHlink`},Jf=`Office`,Yf=[Jf,`Calibri Light`,`Calibri`],Xf=[`dk1`,`lt1`,`dk2`,`lt2`,`accent1`,`accent2`,`accent3`,`accent4`,`accent5`,`accent6`,`hlink`,`folHlink`],Zf=e=>{let t={},n=e.length;for(let r=0;r<n;r++){let n=e[r],i=n[0],a={name:i};t[i]=a;let o=Xf.length;for(let e=0;e<o;e++){let t=Xf[e],r=n[e+1];if(!r)continue;let i=zf.parse(r);i&&(a[t]=i.toString())}}return t},Qf=e=>{let t={},n=e.length;for(let r=0;r<n;r++){let n=e[r],i=n[0],a={name:i};t[i]=a,a.majorFont=n[1]??Yf[1],a.minorFont=n[2]??Yf[2]}return t},$f=Zf([[Jf,`windowText`,`window`,`0E2841`,`E8E8E8`,`156082`,`E97132`,`196B24`,`0F9ED5`,`A02B93`,`4EA72E`,`467886`,`96607D`]]),ep=Qf([Yf]),tp=$f[Jf],np=ep[Jf],rp=null,ip=new class{constructor(){this._colors={};let e=Xf.length;for(let t=0;t<e;t++){let e=Xf[t],n=zf.parse(tp[e]);this._colors[e]=n}}getName(){return tp.name}getDk1(){return this._colors.dk1}getLt1(){return this._colors.lt1}getDk2(){return this._colors.dk2}getLt2(){return this._colors.lt2}getAccent1(){return this._colors.accent1}getAccent2(){return this._colors.accent2}getAccent3(){return this._colors.accent3}getAccent4(){return this._colors.accent4}getAccent5(){return this._colors.accent5}getAccent6(){return this._colors.accent6}getHlink(){return this._colors.hlink}getFolHlink(){return this._colors.folHlink}toJSON(){return null}},ap=class{constructor(e,t=ip){this._delegate=t,this._fromJSON(e)}_fromJSON(e){if(this._overrides={},!e)return;let t=Object.keys(e),n=t.length;if(n!==0)for(let r=0;r<n;r++){let n=t[r];this._overrides[n]=n===`name`?e[n]:zf.parse(e[n])}}_value(e,t){return this._overrides&&this._overrides[e]!==null&&this._overrides[e]!==void 0?this._overrides[e]:this._delegate?.[t]?.()}getName(){return this._value(`name`,`getName`)}getDk1(){return this._value(`dk1`,`getDk1`)}getLt1(){return this._value(`lt1`,`getLt1`)}getDk2(){return this._value(`dk2`,`getDk2`)}getLt2(){return this._value(`lt2`,`getLt2`)}getAccent1(){return this._value(`accent1`,`getAccent1`)}getAccent2(){return this._value(`accent2`,`getAccent2`)}getAccent3(){return this._value(`accent3`,`getAccent3`)}getAccent4(){return this._value(`accent4`,`getAccent4`)}getAccent5(){return this._value(`accent5`,`getAccent5`)}getAccent6(){return this._value(`accent6`,`getAccent6`)}getHlink(){return this._value(`hlink`,`getHlink`)}getFolHlink(){return this._value(`folHlink`,`getFolHlink`)}toJSON(){let e=n.CommonUtils.toSafeJSON(this._overrides),t=this.getName();return t&&(e.name=t),e}},op=new class{constructor(){this._colors={};let e=Xf.length;for(let t=0;t<e;t++){let e=Xf[t],n=zf.parse(tp[e]);this._colors[e]=n}}getName(){return np.name}getMajorFont(){return np.majorFont}getMinorFont(){return np.minorFont}getMajorFallbacks(){return np.majorFallbacks}getMinorFallbacks(){return np.minorFallbacks}},sp=class{constructor(e,t=op){this._delegate=t,this._fromJSON(e)}_fromJSON(e){if(this._overrides={},!e)return;let t=Object.keys(e),n=t.length;if(n!==0)for(let r=0;r<n;r++){let n=t[r];this._overrides[n]=e[n]}}_value(e,t){return this._overrides&&this._overrides[e]!==null&&this._overrides[e]!==void 0?this._overrides[e]:this._delegate?.[t]?.()}getName(){return this._value(`name`,`getName`)}getMajorFont(){return this._value(`majorFont`,`getMajorFont`)}getMinorFont(){return this._value(`minorFont`,`getMinorFont`)}getMajorFallbacks(){return this._value(`majorFallbacks`,`getMajorFallbacks`)}getMinorFallbacks(){return this._value(`minorFallbacks`,`getMinorFallbacks`)}toJSON(){let e=n.CommonUtils.toSafeJSON(this._overrides),t=this.getName();return t&&(e.name=t),e}},cp=class{constructor(e,t=null,n=null){if(this._cacheColors=new Map,this._cacheEpoch=zf.getSystemEpoch(),!t&&e?.name){let n=rp?rp.get(e.name.toLowerCase()):null;n&&(t=n)}!t&&rp&&(t=rp.get(Jf.toLowerCase())??null),this._name=e?.name??t?.getName(),this._builtInID=n,this._delegate=t,this._formatSchemeXml=e?.formatSchemeXml,this._fillStyleLst=e?.fillStyleLst,this._lnStyleLst=e?.lnStyleLst,this._effectStyleLst=e?.effectStyleLst,this._bgFillStyleLst=e?.bgFillStyleLst,this._colors=new ap(e?.colors,this._delegate?.getColorScheme()),this._fonts=new sp(e?.fonts,this._delegate?.getFontScheme());let r=qf,i={},a=Object.keys(r),o=a.length;for(let e=0;e<o;e++){let t=a[e];i[t]=`get${E(r[t])}`}i.dk1=`getDk1`,i.dk2=`getDk2`,i.lt1=`getLt1`,i.lt2=`getLt2`,i.folhlink=`getFolHlink`,this._colorMap=i;let s=this;this._schemeLookup=e=>{let t=zf.getSystemEpoch();s._cacheEpoch!==t&&(s._cacheColors=new Map,s._cacheEpoch=t);let n=s._cacheColors.get(e);if(n)return n;e===`phClr`&&(e=G.Scheme.Tx1);let r=s._colorMap[e];if(!r)throw Error(`Invalid color scheme key: ${e}`);let i=s.getColorScheme(),a=i[r].bind(i)();return a||=tp[qf[e]??e],n=new zf(a),s._cacheColors.set(e,n),n}}get builtInID(){return this._builtInID??null}getName(){return(this._name??this._delegate?.getName())||`Custom`}isCustom(){return this._builtInID!==null&&this._builtInID!==void 0}getColorScheme(){return this._colors}getFontScheme(){return this._fonts}schemeLookup(){return this._schemeLookup}parseColor(e){return zf.parse(e,this._schemeLookup)}toJSON(){let e={name:this.getName()},t=this._colors.toJSON();t&&(Object.keys(t).length>1||t.name&&t.name!==e.name)&&(e.colors=t);let n=this._fonts.toJSON();return n&&(Object.keys(n).length>1||n.name&&n.name!==e.name)&&(e.fonts=n),this._fillStyleLst&&(e.fillStyleLst=this._fillStyleLst),this._lnStyleLst&&(e.lnStyleLst=this._lnStyleLst),this._effectStyleLst&&(e.effectStyleLst=this._effectStyleLst),this._bgFillStyleLst&&(e.bgFillStyleLst=this._bgFillStyleLst),this._formatSchemeXml&&(e.formatSchemeXml=this._formatSchemeXml),Object.keys(e).length===1&&e.name===Jf?null:e}get isITheme(){return!0}},lp=()=>{if(rp)return rp;let e=((e,t,n)=>{let r=[],i=e.length;for(let a=0;a<i;a++){let i=e[a],o=i[0],s=t[i[1]]??tp,c=n[i[2]]??np;r.push({name:o,colors:s,fonts:c})}return r})(Gf,Zf(Uf),Qf(Wf)),t=new Map,n=e.length;for(let r=0;r<n;r++){let n=new cp(null,new cp(e[r]),r+1);t.set(n.getName().toLowerCase(),n)}return rp=t,t},up=class extends S{constructor(e=null,t=!1){super(),lp(),this._isReadOnly=t,this._customMap=new Map,this._defaultTheme=this.getByName(`Office`)}getDefaultTheme(){return this._defaultTheme}setDefaultTheme(e){if(this._isReadOnly)throw Error(Kf);if(!e)throw Error(`Theme cannot be null.`);let t=this.getDefaultTheme();return this.getByName(e.getName())||this.setCustomTheme(e),this._defaultTheme=e,t}getByName(e){return e=e.toLowerCase(),this._customMap.get(e)||(rp.get(e)??null)}_getItems(e){let t=e?.type??jf.BuiltInFilterType.All,r=new Map;return t!==jf.BuiltInFilterType.BuiltIn&&t!==jf.BuiltInFilterType.All||rp.forEach((e,t)=>r.set(t,e)),t!==jf.BuiltInFilterType.Custom&&t!==jf.BuiltInFilterType.All||this._customMap.forEach((e,t)=>r.set(t,e)),e?.selected&&r.set(e.selected.getName().toLowerCase(),e.selected),(e=>{let t=[...e];return t.sort((e,t)=>n.CommonUtils.isDefined(e.builtInID)&&!n.CommonUtils.isDefined(t.builtInID)?1:!n.CommonUtils.isDefined(e.builtInID)&&n.CommonUtils.isDefined(t.builtInID)?-1:n.CommonUtils.isDefined(e.builtInID)&&n.CommonUtils.isDefined(t.builtInID)?e.builtInID-t.builtInID:e.getName().localeCompare(t.getName())),t})(Array.from(r.values()))}setCustomTheme(e){if(this._isReadOnly)throw Error(Kf);let t=e.getName().toLowerCase(),n=this._customMap.get(t);return this._customMap.set(t,e),this._notifyCollectionChange(),n??null}deleteCustomTheme(e){if(this._isReadOnly)throw Error(Kf);let t=null;t=typeof e==`string`?e.toLowerCase():e.getName().toLowerCase();let n=this._customMap.get(t);return n?(this._customMap.delete(t),this._notifyCollectionChange(),n):null}get isIThemeCollection(){return!0}};(Vf=Bf||={}).AutoExpand={Both:`both`,Rows:`rows`,Columns:`columns`,None:`none`},Vf.FormulaBelow={TotalsRow:`totalsRow`,InsideTable:`insideTable`,BelowTable:`belowTable`},(Hf||={}).ElementType={WholeTable:`wholeTable`,FirstColumnStripe:`firstColumnStripe`,SecondColumnStripe:`secondColumnStripe`,FirstRowStripe:`firstRowStripe`,SecondRowStripe:`secondRowStripe`,LastColumn:`lastColumn`,FirstColumn:`firstColumn`,HeaderRow:`headerRow`,TotalRow:`totalRow`,FirstHeaderCell:`firstHeaderCell`,LastHeaderCell:`lastHeaderCell`,FirstTotalCell:`firstTotalCell`,LastTotalCell:`lastTotalCell`},(Hf||={}).Empty=class{constructor(e){this._normalStyle=e}getName(){return`None`}isShownInTableStyles(){return!1}isShownInPivotStyles(){return!1}getRanged(e){return null}getProperties(){return n.CommonUtils.EmptyObject}isBuiltIn(){return!0}delete(){}toJSON(){return null}get isITableStyle(){return!0}};var dp=(e,t)=>{let n=e.getName().toLowerCase(),r=t.getName().toLowerCase();return n<r?-1:+(n>r)},fp=class extends S{constructor(e){super(),this._host=e}_getItems(e){let t=e?.type??jf.BuiltInFilterType.All,n=e?.includeHidden??!1,r=this._host.builtIns(),i=this._host.customs(),a=[];if(t!==jf.BuiltInFilterType.Custom&&r.forEach((e,t)=>{let r=i.get(t)??e;!n&&r.isHidden()||a.push(r)}),t!==jf.BuiltInFilterType.BuiltIn){let e=[];i.forEach((i,a)=>{t===jf.BuiltInFilterType.All&&r.has(a)||!n&&i.isHidden()||e.push(i)}),e.sort(dp),a.push(...e)}return a}getByName(e){if(typeof e!=`string`||!e)return null;let t=e.toLowerCase();return this._host.customs().get(t)??this._host.builtIns().get(t)??null}set(e,t=!1){let n=this._host.set(e,t);return this._notifyCollectionChange(),n}_announceChange(){this._notifyCollectionChange()}get isINamedStyleCollection(){return!0}},pp=(e,t)=>{let n=e.getName().toLowerCase(),r=t.getName().toLowerCase();return n<r?-1:+(n>r)},mp=class extends S{constructor(e){super(),this._host=e}_getItems(e){let t=e?.type??jf.BuiltInFilterType.All,n=e?.shownIn,r=e=>n===`table`?e.isShownInTableStyles():n!==`pivot`||e.isShownInPivotStyles(),i=this._host.builtIns(),a=this._host.customs(),o=[];if(t!==jf.BuiltInFilterType.Custom&&i.forEach((e,t)=>{let n=a.get(t)??e;r(n)&&o.push(n)}),t!==jf.BuiltInFilterType.BuiltIn){let e=[];a.forEach((n,a)=>{t===jf.BuiltInFilterType.All&&i.has(a)||r(n)&&e.push(n)}),e.sort(pp),o.push(...e)}return o}getByName(e){if(typeof e!=`string`||!e)return null;let t=e.toLowerCase();return this._host.customs().get(t)??this._host.builtIns().get(t)??null}set(e,t){let n=this._host.set(e,t);return this._notifyCollectionChange(),n}getDefault(){return this._host.getDefault()}setDefault(e){let t=this._host.setDefault(e);return this._notifyCollectionChange(),t}getNone(){return this._host.getNone()}_announceChange(){this._notifyCollectionChange()}get isITableStyleCollection(){return!0}},hp=Object.freeze({fallbacks:n.CommonUtils.EmptyArray,weight:400,style:B.Style.Normal,color:G.Scheme.Tx1,letterSpacing:null,underline:B.UnderlineStyle.None,strike:!1,scheme:B.Scheme.None,verticalAlign:B.VerticalAlignment.Baseline,shadow:!1,outline:!1,extend:!1}),gp=Object.freeze({style:V.StrokeStyle.None,color:G.Scheme.Tx1}),_p=Object.freeze({[V.Edge.Top]:gp,[V.Edge.Left]:gp,[V.Edge.Bottom]:gp,[V.Edge.Right]:gp,[V.Edge.Horizontal]:gp,[V.Edge.Vertical]:gp,[V.Edge.DiagonalUp]:gp,[V.Edge.DiagonalDown]:gp}),vp=Object.freeze({horizontal:c.HorizontalAlignment.General,vertical:c.VerticalAlignment.Bottom,indent:0,relativeIndent:0,overflow:c.Overflow.Visible,rotation:0,stacked:!1,justifyLastLine:!1,readingDirection:c.ReadingDirection.Auto}),yp=Object.freeze({alwaysUnlocked:!1,showFormulas:!1}),bp=Object.freeze({fill:Object.freeze({type:K.Type.None}),numberFormat:`General`,alignment:vp,font:hp,borders:_p,protection:yp,quotePrefix:!1,namedStyle:null}),xp=(()=>{let e=[{named:q.BuiltInName.Normal},{named:q.BuiltInName.RowLevel},{named:q.BuiltInName.ColLevel},{named:q.BuiltInName.Comma,numberFormat:`_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)`},{named:q.BuiltInName.Currency,numberFormat:`_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)`},{named:q.BuiltInName.Percent,numberFormat:`0%`},{named:q.BuiltInName.Comma0,numberFormat:`_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)`},{named:q.BuiltInName.Currency0,numberFormat:`_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)`},{named:q.BuiltInName.Hyperlink,font:{color:G.Scheme.Hlink,underline:B.UnderlineStyle.Single}},{named:q.BuiltInName.FollowedHyperlink,font:{color:G.Scheme.FolHlink,underline:B.UnderlineStyle.Single}},{named:q.BuiltInName.Note,fill:`FFFFFFCC`,font:{style:B.Style.Normal,color:G.Scheme.Tx1},borders:{left:{style:V.StrokeStyle.Thin,color:`FFB2B2B2`},top:{style:V.StrokeStyle.Thin,color:`FFB2B2B2`},right:{style:V.StrokeStyle.Thin,color:`FFB2B2B2`},bottom:{style:V.StrokeStyle.Thin,color:`FFB2B2B2`}}},{named:q.BuiltInName.WarningText,font:{color:`FFFF0000`}},{named:q.BuiltInName.Unknown12},{named:q.BuiltInName.Unknown13},{named:q.BuiltInName.Unknown14},{named:q.BuiltInName.Title,font:{size:18,color:G.Scheme.Tx2}},{named:q.BuiltInName.Heading1,font:{size:15,weight:700,color:G.Scheme.Tx2},borders:{bottom:{style:V.StrokeStyle.Thick,color:G.Scheme.Accent1}}},{named:q.BuiltInName.Heading2,font:{size:13,weight:700,color:G.Scheme.Tx2},borders:{bottom:{style:V.StrokeStyle.Thick,color:`accent1 lumMod 40, lumOff 60`}}},{named:q.BuiltInName.Heading3,font:{weight:700,color:G.Scheme.Tx2},borders:{bottom:{style:V.StrokeStyle.Medium,color:`accent1 lumMod 40, lumOff 60`}}},{named:q.BuiltInName.Heading4,font:{weight:700,color:G.Scheme.Tx2}},{named:q.BuiltInName.Input,fill:`FFFFCC99`,font:{color:`FF3F3F76`},borders:{left:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},top:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},right:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},bottom:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`}}},{named:q.BuiltInName.Output,fill:`FFF2F2F2`,font:{color:`FF3F3F3F`},borders:{left:{style:V.StrokeStyle.Thin,color:`FF3F3F3F`},top:{style:V.StrokeStyle.Thin,color:`FF3F3F3F`},right:{style:V.StrokeStyle.Thin,color:`FF3F3F3F`},bottom:{style:V.StrokeStyle.Thin,color:`FF3F3F3F`}}},{named:q.BuiltInName.Calculation,fill:`FFF2F2F2`,font:{color:`FFFA7D00`},borders:{left:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},top:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},right:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`},bottom:{style:V.StrokeStyle.Thin,color:`FF7F7F7F`}}},{named:q.BuiltInName.CheckCell,fill:`FFA5A5A5`,font:{color:G.Scheme.Bg1},borders:{left:{style:V.StrokeStyle.Double,color:`FF3F3F3F`},top:{style:V.StrokeStyle.Double,color:`FF3F3F3F`},right:{style:V.StrokeStyle.Double,color:`FF3F3F3F`},bottom:{style:V.StrokeStyle.Double,color:`FF3F3F3F`}}},{named:q.BuiltInName.LinkedCell,font:{color:`FFFA7D00`},borders:{bottom:{style:V.StrokeStyle.Double,color:`FFFF8001`}}},{named:q.BuiltInName.Total,font:{weight:700,color:G.Scheme.Tx1},borders:{top:{style:V.StrokeStyle.Thin,color:G.Scheme.Accent1},bottom:{style:V.StrokeStyle.Double,color:G.Scheme.Accent1}}},{named:q.BuiltInName.Good,fill:`FFC6EFCE`,font:{color:`FF006100`}},{named:q.BuiltInName.Bad,fill:`FFFFC7CE`,font:{color:`FF9C0006`}},{named:q.BuiltInName.Neutral,fill:`FFFFEB9C`,font:{color:`FF9C5700`}},{named:q.BuiltInName.Accent1},{named:q.BuiltInName.Accent1_20},{named:q.BuiltInName.Accent1_40},{named:q.BuiltInName.Accent1_60},{named:q.BuiltInName.Accent2},{named:q.BuiltInName.Accent2_20},{named:q.BuiltInName.Accent2_40},{named:q.BuiltInName.Accent2_60},{named:q.BuiltInName.Accent3},{named:q.BuiltInName.Accent3_20},{named:q.BuiltInName.Accent3_40},{named:q.BuiltInName.Accent3_60},{named:q.BuiltInName.Accent4},{named:q.BuiltInName.Accent4_20},{named:q.BuiltInName.Accent4_40},{named:q.BuiltInName.Accent4_60},{named:q.BuiltInName.Accent5},{named:q.BuiltInName.Accent5_20},{named:q.BuiltInName.Accent5_40},{named:q.BuiltInName.Accent5_60},{named:q.BuiltInName.Accent6},{named:q.BuiltInName.Accent6_20},{named:q.BuiltInName.Accent6_40},{named:q.BuiltInName.Accent6_60},{named:q.BuiltInName.ExplanatoryText,font:{style:B.Style.Italic,color:`FF7F7F7F`}}];for(let t=29;t<=52;t++){let n=(t-29)%4,r=Math.floor((t-29)/4),i=``;n===1?i=` lumMod 20, lumOff 80`:n===2?i=` lumMod 40, lumOff 60`:n===3&&(i=` lumMod 60, lumOff 40`),e[t].fill=`accent${r+1}${i}`,e[t].font={color:n===0?G.Scheme.Bg1:G.Scheme.Tx1}}return n.CommonUtils.deepFreeze(e)})(),Sp=null,Cp=`TableStyleMedium2`;function wp(e){return!/^(-?\d|--)/.test(e)}function Tp(e){let t=[],n=``,r=``,i=7;for(let a,o=0;a=e.charAt(o);o++)if(/[a-zA-Z\d\xa0-\uffff_-]/.test(a)&&i===7)n+=a;else if(a===`\\`&&i===7)i=6;else if(a===` `&&i===7){if(n!==``){if(!wp(n))return null;t.push(n),n=``}}else if(i===6)/[0-9a-f]/i.test(a)?(r+=a,i=8):(n+=a,i=7);else{if(i!==8)return null;/[0-9a-f]/i.test(a)&&r.length<6?r+=a:(n+=String.fromCodePoint(parseInt(r,16)),n+=a,r=``,i=7)}if(n!==``){if(!wp(n))return null;t.push(n)}return t.join(` `)}function Ep(e,t){let n=t,r=``,i={"font-family":[]};for(let t,a=0;t=e.charAt(a);a+=1)if(n!==4||t!==`"`&&t!==`'`)if(n===3&&t===`,`)n=4,r=``;else if(n===4&&t===`,`){let e=Tp(r);e&&i[`font-family`].push(e),r=``}else if(n===5&&t===` `)/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:deg|grad|rad|turn)$/.test(r)?(i[`font-style`]+=` `+r,r=``):--a,n=1;else if(n!==1||t!==` `&&t!==`/`)n===2&&t===` `?(/^(?:\+|-)?([0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)?$/.test(r)&&(i[`line-height`]=r),n=4,r=``):r+=t;else{if(/^(?:(?:xx|x)-large|(?:xx|s)-small|small|large|medium)$/.test(r)||/^(?:larg|small)er$/.test(r)||/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)$/.test(r))n=t===`/`?2:4,i[`font-size`]=r;else if(/^italic$/.test(r))i[`font-style`]=r;else if(/^oblique$/.test(r))i[`font-style`]=r,n=5;else if(/^small-caps$/.test(r))i[`font-variant`]=r;else if(/^(?:bold(?:er)?|lighter|normal)$/.test(r))i[`font-weight`]=r;else if(/^[+-]?(?:[0-9]*\.)?[0-9]+(?:e[+-]?(?:0|[1-9][0-9]*))?$/.test(r)){let e=parseFloat(r);e>=1&&e<=1e3&&(i[`font-weight`]=r)}else/^(?:(?:ultra|extra|semi)-)?(?:condensed|expanded)$/.test(r)&&(i[`font-stretch`]=r);r=``}else{let o=a+1;do if(o=e.indexOf(t,o)+1,!o)return null;while(e.charAt(o-2)===`\\`);i[`font-family`].push(e.slice(a+1,o-1).replace(/\\('|")/g,`$1`)),a=o-1,n=3,r=``}if(n===3&&!/^\s*$/.test(r))return null;if(n===4){let e=Tp(r);e&&i[`font-family`].push(e)}return i}function Dp(e){let t=parseFloat(e);return isNaN(t)||(t%=360,t>0?t=360-t:t<0&&(t*=-1)),t}function Op(e){if(typeof e!=`string`)return null;let t=function(e){let t=Ep(e,4);return t===null?null:t[`font-family`]}(e);Array.isArray(t)&&t.length===0&&(t=null),t=t?{"font-family":t}:function(e){let t=Ep(e,1);return t!==null&&t[`font-size`]&&t[`font-family`].length?t:null}(e);let n=null,r=null,i=null;if(t){let e=t[`font-family`],a=e.shift();a&&(n=a),e.length>0&&(r=e),t[`font-size`]!==void 0&&(i=t[`font-size`])}return{family:n,fallbacks:r,size:i}}function kp(e,t=!1){return t===`adaptive`?e?.toCSS(`adaptive`)??null:function(e,t=!1){return e?.toHex(t)?.toString(!1).toLowerCase()??null}(e,t)}function Ap(e){return e==null?null:n.CommonUtils.roundAccurately(e,2)+`pt`}function jp(e,t){let n=``,r=e&&e!==B.UnderlineStyle.None;return t&&(n+=`line-through`),r&&t&&(n+=` `),r&&(n+=`underline`,!0!==e&&e!==B.UnderlineStyle.Single&&e!==B.UnderlineStyle.SingleAccounting||(n+=` solid`),e!==B.UnderlineStyle.Double&&e!==B.UnderlineStyle.DoubleAccounting||(n+=` double`)),n}var Mp=Object.freeze({underline:B.UnderlineStyle.None,strike:!1});function Np(e){if(!e)return Mp;let t=B.UnderlineStyle.None,n=!1;return(e=e.toLowerCase()).includes(`underline`)&&(t=B.UnderlineStyle.Single),(e.includes(`line-through`)||e.includes(`linethrough`))&&(n=!0),{underline:t,strike:n}}function Pp(e){return e?(e=e.toLowerCase())===`single`?B.UnderlineStyle.Single:e===`double`?B.UnderlineStyle.Double:e===`single-accounting`||e===`singleaccounting`?B.UnderlineStyle.SingleAccounting:e===`double-accounting`||e===`doubleaccounting`?B.UnderlineStyle.DoubleAccounting:B.UnderlineStyle.None:B.UnderlineStyle.None}function Fp(e){return e?e.toLowerCase():null}function Ip(e){return e?e===c.Overflow.Visible||e===c.Overflow.Clip||e===c.Overflow.Shrink?`nowrap`:e===c.Overflow.Wrap?`normal`:void 0:null}function Lp(e,t){let n=``;if(e&&(e.includes(` `)&&(e=`"`+e+`"`),n=e),t)for(let e=0;e<t.length;e++)n.length>0&&(n+=`, `),n+=t[e];return n}function Rp(e){let t=``,n=!1,r=``;for(let i=0;i<e.length;i++){let a=e.charAt(i);n&&a!==`]`&&a!==`"`?t+=a:a===`"`?(t+=`\\0022`,n=!n):[`[`,`]`,`,`,`#`,`.`,`@`,`/`,`:`,`;`,`-`,` `].includes(a)?(t+=`\\`+a,a===`[`?n=!0:a===`]`&&(n=!1)):[`(`,`)`].includes(a)?t+=r===`_`?`\\`+a:`\\\\\\`+a:[`$`].includes(a)?t+=`\\0022`+a+`\\0022`:t+=a,r=a}return`"`+t+`"`}function zp(e){let t=e.replace(/(\\[0-9]{4})/g,e=>String.fromCharCode(parseInt(e.replace(/\\/g,``),16)));return t=t.replace(/(\\.{1})/g,e=>e.substring(e.length-1,e.length)),t.includes(`\\`)&&(t=t.replace(/(\\.{1})/g,e=>e.substring(e.length-1,e.length))),t=t.replace(/^"(.*)"$/,`$1`),t}var Bp=`Thin`,Vp=`Hairline`,Hp=`Extra Light`,Up=`Ultra Light`,Wp=`Light`,Gp=`Normal`,Kp=`Regular`,qp=`Medium`,Jp=`Semi Bold`,Yp=`Demi Bold`,Xp=`Bold`,Zp=`Extra Bold`,Qp=`Ultra Bold`,$p=`Black`,em=`Heavy`,tm=`Extra Black`,nm=`Ultra Black`,rm=`lighter`,im=`normal`,am=`bold`,om=`bolder`,sm=new Map;function cm(e){let t=400;if(t=typeof e==`number`?e:parseFloat(e),!isNaN(t))return t;if(typeof e==`string`){let t=n.CommonUtils.textToKey(e),r=sm.get(t);if(r)return r}return t}sm.set(n.CommonUtils.textToKey(Bp),100),sm.set(n.CommonUtils.textToKey(Vp),100),sm.set(n.CommonUtils.textToKey(Hp),200),sm.set(n.CommonUtils.textToKey(Up),200),sm.set(n.CommonUtils.textToKey(Wp),300),sm.set(n.CommonUtils.textToKey(Gp),400),sm.set(n.CommonUtils.textToKey(Kp),400),sm.set(n.CommonUtils.textToKey(qp),500),sm.set(n.CommonUtils.textToKey(Jp),600),sm.set(n.CommonUtils.textToKey(Yp),600),sm.set(n.CommonUtils.textToKey(Gp),400),sm.set(n.CommonUtils.textToKey(Xp),700),sm.set(n.CommonUtils.textToKey(Zp),800),sm.set(n.CommonUtils.textToKey(Qp),800),sm.set(n.CommonUtils.textToKey($p),900),sm.set(n.CommonUtils.textToKey(em),900),sm.set(n.CommonUtils.textToKey(tm),950),sm.set(n.CommonUtils.textToKey(nm),950),sm.set(n.CommonUtils.textToKey(rm),100),sm.set(n.CommonUtils.textToKey(im),400),sm.set(n.CommonUtils.textToKey(am),700),sm.set(n.CommonUtils.textToKey(om),700);var lm=`xx-small`,um=`x-small`,dm=`small`,fm=`medium`,pm=`large`,mm=`x-large`,hm=`xx-large`,gm=`xxx-large`,_m=`smaller`,vm=`larger`,ym=`math`,bm=RegExp(`^[0-9]*[.]?[0-9]+$`,`g`),xm=new Map;function Sm(e,t=11,r=`pt`){if(!e)return null;let i=t;e=e.trim().toLowerCase();let a=r===`pt`?B.getDeviceScale():1,o=r===`pt`?1:B.getDeviceScale();if(bm.test(e)){let t=parseFloat(e);isNaN(t)||(e=t+r)}if(e.endsWith(`pt`))i=parseFloat(e.substring(0,e.length-2).trim())*o;else if(e.endsWith(`px`))i=parseFloat(e.substring(0,e.length-2).trim())/a;else if(e.endsWith(`em`))i=parseFloat(e.substring(0,e.length-2).trim())*t;else if(e.endsWith(`rem`))i=parseFloat(e.substring(0,e.length-3).trim())*t;else if(e.endsWith(`%`))i=parseFloat(e.substring(0,e.length-1).trim())/100*t;else if(typeof e==`string`){let r=n.CommonUtils.textToKey(e),i=xm.get(r);if(i)return i(t)}return isNaN(i)?null:i}xm.set(n.CommonUtils.textToKey(lm),e=>.4*e),xm.set(n.CommonUtils.textToKey(um),e=>.5*e),xm.set(n.CommonUtils.textToKey(dm),e=>.6*e),xm.set(n.CommonUtils.textToKey(fm),e=>e),xm.set(n.CommonUtils.textToKey(pm),e=>1.1*e),xm.set(n.CommonUtils.textToKey(mm),e=>1.25*e),xm.set(n.CommonUtils.textToKey(hm),e=>1.5*e),xm.set(n.CommonUtils.textToKey(gm),e=>2*e),xm.set(n.CommonUtils.textToKey(_m),e=>.9*e),xm.set(n.CommonUtils.textToKey(vm),e=>1.1*e),xm.set(n.CommonUtils.textToKey(ym),e=>e);var Cm=new Map;Cm.set(K.BuiltInSheetPattern.None,{description:`None`,cssKey:`none`}),Cm.set(K.BuiltInSheetPattern.Solid,{description:`Solid`,cssKey:`solid`}),Cm.set(K.BuiltInSheetPattern.DarkGray,{description:`75% gray`,cssKey:`gray-75`}),Cm.set(K.BuiltInSheetPattern.MediumGray,{description:`50% gray`,cssKey:`gray-50`}),Cm.set(K.BuiltInSheetPattern.LightGray,{description:`25% gray`,cssKey:`gray-25`}),Cm.set(K.BuiltInSheetPattern.Gray125,{description:`12.5% Gray`,cssKey:`gray-125`}),Cm.set(K.BuiltInSheetPattern.Gray0625,{description:`6.25% Gray`,cssKey:`gray-0625`}),Cm.set(K.BuiltInSheetPattern.DarkHorizontal,{description:`Horizontal Strip`,cssKey:`horz-stripe`}),Cm.set(K.BuiltInSheetPattern.DarkVertical,{description:`Vertical Strip`,cssKey:`vert-stripe`}),Cm.set(K.BuiltInSheetPattern.DarkDown,{description:`Reverse Diagonal Stripe`,cssKey:`reverse-diag-stripe`}),Cm.set(K.BuiltInSheetPattern.DarkUp,{description:`Diagonal Strip`,cssKey:`diag-stripe`}),Cm.set(K.BuiltInSheetPattern.DarkGrid,{description:`Diagonal Crosshatch`,cssKey:`diag-cross`}),Cm.set(K.BuiltInSheetPattern.DarkTrellis,{description:`Thick Diagonal Crosshatch`,cssKey:`thick-diag-cross`}),Cm.set(K.BuiltInSheetPattern.LightHorizontal,{description:`Thin Horizontal Stripe`,cssKey:`thin-horz-stripe`}),Cm.set(K.BuiltInSheetPattern.LightVertical,{description:`Thin Vertical Stripe`,cssKey:`thin-vert-stripe`}),Cm.set(K.BuiltInSheetPattern.LightDown,{description:`Thin Reverse Diagonal Stripe`,cssKey:`thin-reverse-diag-stripe`}),Cm.set(K.BuiltInSheetPattern.LightUp,{description:`Thin Diagonal Stripe`,cssKey:`thin-diag-stripe`}),Cm.set(K.BuiltInSheetPattern.LightGrid,{description:`Thin Horizontal Cross`,cssKey:`thin-horz-cross`}),Cm.set(K.BuiltInSheetPattern.LightTrellis,{description:`Thin Diagonal Cross`,cssKey:`thin-diag-cross`});var wm=``,Tm=new Map;Cm.forEach((e,t)=>{wm.length>0&&(wm+=`|`),wm+=`\\b`+e.cssKey+`\\b`,Tm.set(e.cssKey,t)});var Em=RegExp(`(\\s*(?:${wm}))`,`g`);function Dm(e){if(!e)return null;let t=e.toLowerCase();t=t.replace(/;/,``);let n=t.match(Em);if(!n)return null;let r=null;n&&n.length>0&&(r=(e=>{if(!e)return null;let n=t.indexOf(e);return t=t.substring(0,n)+t.substring(n+e.length,t.length),e.trim()})(n[0])),t=t.trim();let i=t?t.trim():null;return r||i?{patternType:Tm.get(r??`solid`),foreground:i}:null}var Om=(e,t=!1,n=null)=>{if(!e)return null;let r=e.getStops();if(!r||r.length<1)return null;let i=r.length;if(i===1)return kp(r[0].getColor(),t);let a=``;for(let e=0;e<i;e++){let n=r[e],o=n.getOffset(),s=o===void 0?e/(i-1)*100:100*o;a+=`${kp(n.getColor(),t)} ${s}%${e<i-1?`, `:``}`}if(e.getGradientType()===K.GradientType.Linear){let t=e.getAngle()??0;if(n&&n.width>0&&n.height>0&&t%90!=0){let e=n.width,r=n.height,i=(90-t)*(Math.PI/180),a=Math.cos(i)*r,o=Math.sin(i)*e;t=(90-180*Math.atan2(o,a)/Math.PI+360)%360}return`linear-gradient(${t}deg, ${a})`}return e.getGradientType()===K.GradientType.Path||e.getGradientType()===K.GradientType.Rect||e.getGradientType()===K.GradientType.Shape?function(e,t,n){let r=t??sh,i=km(r.left??0),a=km(r.right??0),o=km(r.top??0),s=km(r.bottom??0);if(i>a||o>s)return null;let c=(i+a)/2,l=(o+s)/2,u=(100*c).toFixed(3),d=(100*l).toFixed(3);if(!n||n.width<=0||n.height<=0)return`radial-gradient(ellipse farthest-corner at ${u}% ${d}%, ${e})`;let f=n.width,p=n.height,m=Math.max(c,1-c),h=Math.max(l,1-l),g=Math.sqrt(m*m+h*h);return`radial-gradient(ellipse ${(g*f).toFixed(3)}px ${(g*p).toFixed(3)}px at ${u}% ${d}%, ${e})`}(a,e.getFocus(),n)||kp((r[i-1]??r[0]).getColor(),t):null},km=e=>Math.max(0,Math.min(1,e)),Am=new Map;function jm(e){if(!e)return`none`;let t=Am.get(e.getStyle());if(!t)return null;if(t.cssKey===`none`)return t.cssKey;let n=function(e,t=!1){return e?.toRGBA(t).toString(!1)??null}(e?.getColor());return n=n?` `+n:``,`${t.size===null?``:`${t.size}pt `}${t.cssKey}${n}`}Am.set(V.StrokeStyle.None,{size:null,cssKey:`none`}),Am.set(V.StrokeStyle.DashDot,{size:.5,cssKey:`dot-dash`}),Am.set(V.StrokeStyle.DashDotDot,{size:.5,cssKey:`dot-dot-dash`}),Am.set(V.StrokeStyle.Dashed,{size:.5,cssKey:`dashed`}),Am.set(V.StrokeStyle.MediumDashed,{size:1,cssKey:`dashed`}),Am.set(V.StrokeStyle.Dotted,{size:.5,cssKey:`dotted`}),Am.set(V.StrokeStyle.MediumDashDot,{size:1,cssKey:`dot-dash`}),Am.set(V.StrokeStyle.MediumDashDotDot,{size:1,cssKey:`dot-dot-dash`}),Am.set(V.StrokeStyle.Hair,{size:.5,cssKey:`hairline`}),Am.set(V.StrokeStyle.Thin,{size:.5,cssKey:`solid`}),Am.set(V.StrokeStyle.Thick,{size:1.5,cssKey:`solid`}),Am.set(V.StrokeStyle.Medium,{size:1,cssKey:`solid`}),Am.set(V.StrokeStyle.Double,{size:2,cssKey:`double`}),Am.set(V.StrokeStyle.SlantDashDot,{size:1,cssKey:`dot-dash-slanted`});var Mm=[],Nm=new Set,Pm=new Map,Fm=(e,t)=>{let n=e.size===null?e.cssKey:`${e.size.toString()} ${e.cssKey}`;Pm.set(n,t),Nm.has(e.cssKey)||(Mm.push(e.cssKey),Nm.add(e.cssKey))};Am.forEach(Fm);var Im=Object.keys(V.StrokeStyle);for(let e=0;e<Im.length;e++)Fm({size:null,cssKey:Im[e].toLowerCase()},V.StrokeStyle[Im[e]]);Fm({size:null,cssKey:`double`},V.StrokeStyle.Double),Fm({size:null,cssKey:`solid`},V.StrokeStyle.Medium),Fm({size:null,cssKey:`hidden`},V.StrokeStyle.None),Mm.sort((e,t)=>t.length-e.length);var Lm=``,Rm=Mm.length;for(let e=0;e<Rm;e++)Lm.length>0&&(Lm+=`|`),Lm+=`\\b`+Mm[e]+`\\b`;var zm=RegExp(`(\\s*(?:${Lm}))`,`g`),Bm=RegExp(`(\\s*[0-9]*[.]?[0-9]+(?:pt|px){0,1})`,`g`);function Vm(e,t){if(!e)return null;let n=e.toLowerCase(),r=n.match(zm);if(!r){let e=t?.(n);return e?{color:e,style:V.StrokeStyle.Medium}:null}let i=e=>{if(!e)return null;let t=n.indexOf(e);return n=n.substring(0,t)+n.substring(t+e.length,n.length).trim(),e.trim()},a=null;if(r&&r.length>0&&(a=i(r[0])),!a)return null;let o=null;if(r=n.match(Bm),r&&r.length>0){let e=i(r[0]);o=parseFloat(e.substring(0,e.length-2))}n=n.trim();let s=n?n.trim():null,c=o===null?a:`${o.toString()} ${a}`,l=Pm.get(c);return l||=Pm.get(a),l?{color:s,style:l}:null}var Hm=`start`,Um=`end`,Wm=`left`,Gm=`right`,Km=`center`,qm=`justify`,Jm=`justify-all`,Ym=`baseline`,Xm=`top`,Zm=`middle`,Qm=`bottom`,$m=`sub`,eh=`text-top`,th=`justify`,nh=`distributed`,rh=new Map;function ih(e){let t=n.CommonUtils.textToKey(e);return rh.get(t)||null}rh.set(n.CommonUtils.textToKey(Hm),c.HorizontalAlignment.Left),rh.set(n.CommonUtils.textToKey(Wm),c.HorizontalAlignment.Left),rh.set(n.CommonUtils.textToKey(Um),c.HorizontalAlignment.Right),rh.set(n.CommonUtils.textToKey(Gm),c.HorizontalAlignment.Right),rh.set(n.CommonUtils.textToKey(Km),c.HorizontalAlignment.Center),rh.set(n.CommonUtils.textToKey(qm),c.HorizontalAlignment.Justify),rh.set(n.CommonUtils.textToKey(Jm),c.HorizontalAlignment.Justify);var ah=new Map;ah.set(n.CommonUtils.textToKey(Ym),c.VerticalAlignment.Bottom),ah.set(n.CommonUtils.textToKey(Xm),c.VerticalAlignment.Top),ah.set(n.CommonUtils.textToKey(Zm),c.VerticalAlignment.Center),ah.set(n.CommonUtils.textToKey(Qm),c.VerticalAlignment.Bottom),ah.set(n.CommonUtils.textToKey($m),c.VerticalAlignment.Bottom),ah.set(n.CommonUtils.textToKey(eh),c.VerticalAlignment.Top),ah.set(n.CommonUtils.textToKey(th),c.VerticalAlignment.Justify),ah.set(n.CommonUtils.textToKey(nh),c.VerticalAlignment.Distributed);var oh=e=>{let t=n.CommonUtils.textToKey(e);return ah.get(t)||null},sh=Object.freeze({left:0,right:0,top:0,bottom:0}),ch=e=>{if(e instanceof zf)return{color:e.toString()};if(typeof e==`string`)try{return{color:e===`none`||e===`transparent`?null:e}}catch(e){throw e}return e},lh=n.TypedObject.PassThrough,uh={shorthand:(e,t)=>{if(!e||e===`none`||e===`transparent`)return null;try{return t.parseColor(e).toString()}catch(e){console.warn(`error`,e)}return e},merge:(e,t,n)=>e},dh={shorthand:(e,t)=>{if(e.isIStroke)return e.getProperties();if(typeof e==`string`&&(e=Vm(e,e=>{try{return t.parseColor(e).toString()}catch{}return null})),!e)return null;let n={};return e.style&&(n.style=e.style),e.color&&(n.color=e.color),n},properties:{color:uh,style:lh}},fh={shorthand:(e,t)=>{if(e.isIBorders)return e.getProperties();if(typeof e==`string`){let n=Vm(e,e=>{try{return t.parseColor(e).toString()}catch{}return null});return{left:n,right:n,top:n,bottom:n,horizontal:null,vertical:null,diagonalUp:null,diagonalDown:null}}return e},properties:{top:dh,left:dh,right:dh,bottom:dh,horizontal:dh,vertical:dh,diagonalUp:dh,diagonalDown:dh}},ph={shorthand:(e,t)=>{if(typeof e==`string`){let t=wu.Styles.lookupDefault(e)??e,n=wu.toBuiltInID(t);return typeof n==`number`&&n!==0?n:t}return typeof e==`number`?e===0?wu.Type.General:wu.builtInFormat(e)===void 0?null:e:null}},mh={shorthand:(e,t)=>{if(e.isIStyledFont)return e.toJSON();if(typeof e==`string`){let t=Op(e);if(t){let e={};if(t.family&&(e.family=t.family),t.fallbacks&&(e.fallbacks=t.fallbacks),t.size&&(e.size=Sm(t.size)),Object.keys(t).length>0)return e}return e}return e&&(e=>{let{bold:t,italic:n,...r}=e;if(t===void 0&&n===void 0)return e;let i=r;return t!==void 0&&i.weight===void 0&&(i.weight=t===null?null:t?700:400),n!==void 0&&i.style===void 0&&(i.style=n===null?null:n?B.Style.Italic:B.Style.Normal),i})(e)},properties:{family:{shorthand:(e,t)=>Op(e)?.family??null},fallbacks:{shorthand:(e,t)=>{if(typeof e!=`string`)return e;let n=Op(e);if(!n)return null;let r=[n.family];return n.fallbacks&&(r=r.concat(n.fallbacks)),r}},size:{shorthand:(e,t)=>{let r=e;return typeof e==`string`&&(r=Sm(e,t.getNormal().getFont().getSize())),isNaN(r)||typeof r!=`number`?null:(r=Math.max(1,Math.min(n.CommonUtils.roundAccurately(r,1),409)),r)}},weight:{shorthand:(e,t)=>{if(typeof e!=`string`)return e;let n=cm(e);return isNaN(n)||typeof n!=`number`?null:n}},style:lh,color:uh,letterSpacing:lh,underline:{shorthand:(e,t)=>e?!0===e?B.UnderlineStyle.Single:Pp(e):B.UnderlineStyle.None},strike:lh,scheme:lh,verticalAlign:lh,shadow:lh,outline:lh,extend:lh,charset:{shorthand:(e,t)=>{if(e==null)return null;let n=typeof e==`string`?parseInt(e,10):e;return typeof n==`number`&&Number.isFinite(n)?n:null}}}},hh={shorthand:(e,t)=>e&&typeof e==`object`?(e=>{let{rotation:t,stacked:n}=e;return t!=null&&n===void 0?{...e,stacked:!1}:!0===n&&t===void 0?{...e,rotation:0}:e})(e):e,properties:{horizontal:lh,vertical:lh,indent:{shorthand:(e,t)=>{let n=e;return typeof e==`string`&&(n=parseFloat(e)),isNaN(n)||typeof n!=`number`?null:n}},relativeIndent:lh,overflow:lh,rotation:{shorthand:(e,t)=>{let n=e;return typeof e==`string`&&(n=parseFloat(e)),isNaN(n)||typeof n!=`number`?null:(n%=360,n<0&&(n+=360),n)}},stacked:lh,justifyLastLine:lh,readingDirection:lh}},gh={shorthand:(e,t)=>e===`none`||e===`transparent`||typeof e==`object`&&Object.keys(e).length===0?{type:K.Type.None}:(e.getType?.(),K.Type.None,e)},_h={shorthand:e=>{let t=ch(e);return typeof t==`object`&&t.color&&(t.type=K.Type.Solid),t},merge:(e,t)=>{let n=e,r=t;return n&&`color`in n&&n.color===null?{type:K.Type.None}:n.color?n:(r?.toJSON&&(r=r.toJSON()),r?.type===K.Type.Solid?{...r}:r?.type===K.Type.Gradient?{type:K.Type.Solid,color:r?.stops?.[0]?.color??G.Scheme.Bg1}:r?.type===K.Type.Pattern?{type:K.Type.Solid,color:r?.foreground??G.Scheme.Bg1}:n?{...n}:null)},properties:{color:uh,type:lh,isRotatedWithShape:lh}},vh={shorthand:e=>(typeof e==`object`&&e.stops&&(e.type=K.Type.Gradient),e),merge:(e,t,n)=>{let r=e,i=t;return r.stops?r:(i?.toJSON&&(i=i.toJSON()),i?.type===K.Type.Gradient?{...i}:i?.type===K.Type.Solid?{type:K.Type.Gradient,stops:[{offset:0,color:i?.color??G.Scheme.Accent1},{offset:1,color:G.Scheme.Bg1}]}:i?.type===K.Type.Pattern?{type:K.Type.Gradient,stops:[{offset:0,color:i?.foreground??G.Scheme.Bg1},{offset:1,color:i?.background??G.Scheme.Accent1}]}:r?{...r}:null)},properties:{type:lh,stops:{shorthand:e=>(typeof e==`string`&&(e=e.split(`,`).map(e=>e.trim())),Array.isArray(e)?e.map((e,t)=>{if(!e)return;let n=e;return typeof e==`string`&&(n=ch(e)),e.isIColor&&(n={color:e.toString()}),n}):e),arrayType:{shorthand:e=>ch(e),properties:{color:uh,offset:lh}}},gradientType:lh,angle:lh,focus:lh,isRotatedWithShape:lh}},yh={shorthand:(e,t)=>{if(typeof e==`object`){let t=e;(t.foreground||t.background||t.patternType)&&(t.type=K.Type.Pattern,t.patternType=t.patternType??K.BuiltInSheetPattern.Solid)}return e},merge:(e,t,n)=>{let r=e,i=t;if(r.background&&r.foreground)return r;i?.toJSON&&(i=i.toJSON());let a=K.BuiltInSheetPattern.MediumGray;if(i?.type===K.Type.Pattern){let e={type:K.Type.Pattern,patternType:r.patternType??i.patternType};return i.foreground&&(e.foreground=i.foreground),i.background&&(e.background=i.background),r.foreground&&(e.foreground=r.foreground),r.background&&(e.background=r.background),e}return i?.type===K.Type.Solid?{patternType:a,foreground:i?.color??G.Named.WindowText,background:G.Scheme.Bg1,...r}:i?.type===K.Type.Gradient?{patternType:a,foreground:i?.stops?.[0]?.color??G.Named.WindowText,background:i?.stops?.[1]?.color??G.Scheme.Bg1,...r}:r?{type:K.Type.Pattern,patternType:K.BuiltInSheetPattern.Solid,foreground:G.Named.WindowText,background:G.Scheme.Bg1,...r}:null},properties:{type:lh,patternType:lh,foreground:uh,background:uh,isRotatedWithShape:lh}},bh=[gh,_h,vh,yh],xh=[];for(let e=0;e<bh.length;e++){let t=bh[e]?.shorthand;xh.push(t)}var Sh=xh.length,Ch={properties:{font:mh,fill:{shorthand:(e,t)=>{e.isIFill&&(e=e.toJSON());for(let n=0;n<Sh;n++){let r=xh[n](e,t);if(r?.type)return r}return e},getSubType:(e,t)=>{let n=e.type??t?.type;return n===K.Type.None?gh:n===K.Type.Solid?_h:n===K.Type.Gradient?vh:n===K.Type.Pattern?yh:null}},alignment:hh,borders:fh,numberFormat:ph,quotePrefix:lh,protection:{properties:{alwaysUnlocked:lh,showFormulas:lh}},named:lh,insets:lh}},wh=Object.freeze([`font`,`fill`,`alignment`,`borders`,`numberFormat`,`quotePrefix`,`protection`,`insets`]),Th={shorthand:(e,t)=>{if(!e||typeof e!=`object`)return;let n=e.named;if(!n||(n.isINamed&&(n=n.getName()),typeof n!=`string`))return;let r=null;if(n.toLowerCase()===q.BuiltInName.Normal.toLowerCase())r=wh;else{let e=t?.getNamedStyles().getByName(n)?.getRanged().getPropertiesAt(0,0,null);e&&(r=Object.keys(e))}let i={...e,named:n},a=r?r.length:0;for(let e=0;e<a;e++){let t=r[e];t!==`named`&&i[t]===void 0&&(i[t]=null)}return i},properties:Ch.properties},Eh={properties:{style:Th,name:lh,hidden:lh,iLevel:lh}},Dh=(e,t,n)=>{let r=e.borders;if(!r)return e;let i=((e,t,n)=>{if(!e)return e;let r=null;return(e.top||e.horizontal)&&(t.rowIndex!==n.rowStart||t.colIndex<n.colStart||t.colIndex>n.colEnd)&&(r??={...e},delete r.top,e.horizontal&&(r.top=e.horizontal)),(e.bottom||e.horizontal)&&(t.rowIndex!==n.rowEnd||t.colIndex<n.colStart||t.colIndex>n.colEnd)&&(r??={...e},delete r.bottom,e.horizontal&&(r.bottom=e.horizontal)),(e.left||e.vertical)&&(t.colIndex!==n.colStart||t.rowIndex<n.rowStart||t.rowIndex>n.rowEnd)&&(r??={...e},delete r.left,e.vertical&&(r.left=e.vertical)),(e.right||e.vertical)&&(t.colIndex!==n.colEnd||t.rowIndex<n.rowStart||t.rowIndex>n.rowEnd)&&(r??={...e},delete r.right,e.vertical&&(r.right=e.vertical)),e.horizontal&&(r??={...e},delete r.horizontal),e.vertical&&(r??={...e},delete r.vertical),r??e})(r,t,n),a=e;return i!==e.borders&&(a={...e},Object.keys(i).length>0?a.borders=i:delete a.borders),a},Oh=class{constructor(e,t,n){this._permCache=null,this._table=e,this._styles=t,this._properties=n}_resolveProperties(e){let t={name:e.name},r=this._styles,i=Object.values(Hf.ElementType),a=i.length;for(let o=0;o<a;o++){let a=i[o],s=e[a];s&&n.CommonUtils.isObject(s)&&(t[a]=n.TypedObject.resolveTypedUpdates(Object.freeze(s),Ch,r))}return Object.freeze(t)}getCoords(){return this._table.getRange().getCoords()}getPropertiesAt(e,t){let r=this._table,i=this._styles,a=this._properties;Ah.rowIndex=e,Ah.colIndex=t;let o=r.getVisibleCellCoords(Ah),s=r.getVisibleRefRangeCoords();if(!s)return null;let c=Math.max(0,s.colEnd-s.colStart)+1,l=Math.max(0,s.rowEnd-s.rowStart)+1,u=Math.max(0,o.rowIndex-s.rowStart),d=Math.max(0,o.colIndex-s.colStart),f=r.getStyleOptions(),p=!1,m=0;r.isHeaderVisible()&&(m=+!!r.isShowHeaders(),p=m>u);let h=!1,g=0;r.isTotalVisible()&&(g=+!!r.isShowTotals(),h=l-g<=u);let _=d===c-1&&f.showLastColumn;r.isLastColumnVisible()||(_=!1);let v=d===0&&f.showFirstColumn;r.isFirstColumnVisible()||(v=!1);let y=!p&&!h,b=y&&f.showColumnStripes,x=0,S=0,C=0,w=!1,T=0;b&&(x=a.firstColumnStripe?.size??1,S=a.secondColumnStripe?.size??1,C=d%(x+S),w=C<x,w||(C-=x),T=Math.min(c-d,w?x:S));let E=y&&f.showRowStripes,D=0,O=0,k=0,A=!1,j=0;E&&(D=a.firstRowStripe?.size??1,O=a.secondRowStripe?.size??1,k=(u-m)%(D+O),A=k<D,A||(k-=D),j=Math.min(l-u,A?D:O));let M=!1;if(p&&a.headerRow){let e=r.getColumnAt(d);M=!!e&&!e.isHiddenButton()}let N=0;p&&(N|=1),h&&(N|=2),v&&(N|=4),_&&(N|=8),u===0&&(N|=16),u===l-1&&(N|=32),d===0&&(N|=64),d===c-1&&(N|=128),u===m&&(N|=256),u===l-g-1&&(N|=512),M&&(N|=1024),m>0&&(N|=2048),g>0&&(N|=4096);let P=`${N}`+(b?`|c${w?`f`:`s`}${C},${T}`:``)+(E?`|r${A?`f`:`s`}${k},${j}`:``),F=this._permCache?.get(P);if(F!==void 0)return F;let I={rowIndex:u,colIndex:d},L={};if(a.wholeTable&&(L=a.wholeTable,L.borders&&(L=Dh(L,I,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:c-1}))),b){let e=w?a.firstColumnStripe:a.secondColumnStripe;if(e){let t=e,r=e.borders;r&&(t=Dh(t,{rowIndex:u,colIndex:C},{rowStart:m,rowEnd:l-g-1,colStart:0,colEnd:T}),w&&C===0&&d>0&&r?.left&&a.secondColumnStripe?.borders?.right&&(r={...t.borders},t.borders=r,r.left=null),w&&C===x-1&&d<c-1&&r?.right&&a.secondColumnStripe?.borders?.left&&(r={...t.borders},t.borders=r,r.right=null)),L=n.TypedObject.resolveTypedUpdates(t,Ch,i,L)}}if(E){let e=m,t=l-g-1,r=A?a.firstRowStripe:a.secondRowStripe;if(r){let o=r,s=r.borders;if(s){o=Dh(o,{colIndex:d,rowIndex:k},{colStart:0,colEnd:c-1,rowStart:0,rowEnd:j}),A&&k===0&&u>=e&&r.borders?.top&&a.secondRowStripe?.borders?.bottom&&(s={...o.borders},o.borders=s,s.top=null);let n=r.borders?.bottom;(n&&A&&k===D-1&&u<t&&a.secondRowStripe?.borders?.top||n&&u===t)&&(s={...o.borders},o.borders=s,s.bottom=null)}L=n.TypedObject.resolveTypedUpdates(o,Ch,i,L)}}if(_&&a.lastColumn){let e=a.lastColumn;e.borders&&(e=Dh(e,I,{rowStart:0,rowEnd:l-1,colStart:c-1,colEnd:c-1})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(v&&a.firstColumn){let e=a.firstColumn;e.borders&&(e=Dh(e,I,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:0})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(p&&a.headerRow){let e=a.headerRow;e.borders&&(e=Dh(e,I,{rowStart:0,rowEnd:m-1,colStart:0,colEnd:c-1})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(h&&a.totalRow){let e=a.totalRow;e.borders&&(e=Dh(e,I,{rowStart:l-g,rowEnd:l-1,colStart:0,colEnd:c-1})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(p&&v&&a.firstHeaderCell){let e=a.firstHeaderCell;e.borders&&(e=Dh(e,I,{rowStart:0,rowEnd:m-1,colStart:0,colEnd:0})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(p&&_&&a.lastHeaderCell){let e=a.lastHeaderCell;e.borders&&(e=Dh(e,I,{rowStart:0,rowEnd:m-1,colStart:c-1,colEnd:c-1})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(h&&v&&a.firstTotalCell){let e=a.firstTotalCell;e.borders&&(e=Dh(e,I,{rowStart:l-g,rowEnd:l-1,colStart:0,colEnd:0})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}if(h&&_&&a.lastTotalCell){let e=a.lastTotalCell;e.borders&&(e=Dh(e,I,{rowStart:l-g,rowEnd:l-1,colStart:c-1,colEnd:c-1})),L=n.TypedObject.resolveTypedUpdates(e,Ch,i,L)}M&&(L.insets={right:15});let R=this._permCache;return R||=this._permCache=new Map,R.set(P,Object.freeze(L)),L}},kh=class{constructor(e,t,r,i){this._styles=e,this._isBuiltIn=r,this._doDelete=i,this._properties=n.CommonUtils.deepFreeze(this._resolveProperties(t)),this.isShownInTableStyles()}_resolveProperties(e){let t={name:e.name};e.table!==void 0&&(t.table=e.table),e.pivot!==void 0&&(t.pivot=e.pivot);let r=this._styles,i=Object.values(Hf.ElementType),a=i.length;for(let o=0;o<a;o++){let a=i[o],s=e[a];s&&n.CommonUtils.isObject(s)&&(t[a]=n.TypedObject.resolveTypedUpdates(Object.freeze(s),Ch,r))}return Object.freeze(t)}delete(){if(!this._doDelete)throw Error(`Not able to delete builtin style.`);this._doDelete(this._properties.name)}getRanged(e){return new Oh(e,this._styles,this._properties)}getProperties(){return this._properties}getName(){return this._properties.name}isShownInTableStyles(){return!1!==this._properties.table}isShownInPivotStyles(){return this._properties.pivot??!1}isBuiltIn(){return this._isBuiltIn}toJSON(){let e=n.CommonUtils.cloneObject(this._properties);return e.name=this._properties.name,e}get isITableStyle(){return!0}},Ah={rowIndex:0,colIndex:0};function jh(e,t){if(!t||t.rowStart>e.rowEnd||t.rowEnd<e.rowStart||t.colStart>e.colEnd||t.colEnd<e.colStart)return[{...e}];let n=[];t.rowStart>e.rowStart&&n.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:t.rowStart-1}),t.rowEnd<e.rowEnd&&n.push({colStart:e.colStart,rowStart:t.rowEnd+1,colEnd:e.colEnd,rowEnd:e.rowEnd});let r=Math.max(e.rowStart,t.rowStart),i=Math.min(e.rowEnd,t.rowEnd);return t.colStart>e.colStart&&n.push({colStart:e.colStart,rowStart:r,colEnd:t.colStart-1,rowEnd:i}),t.colEnd<e.colEnd&&n.push({colStart:t.colEnd+1,rowStart:r,colEnd:e.colEnd,rowEnd:i}),n}function Mh(e,t){if(!t||t.length===0)return e.map(e=>({...e}));let n=e;for(let e=0;e<t.length&&n.length>0;e++){let r=[];for(let i=0;i<n.length;i++)r.push(...jh(n[i],t[e]));n=r}return n}function Nh(e,t){return e.colStart<=t.colStart&&e.colEnd>=t.colEnd&&e.rowStart<=t.rowStart&&e.rowEnd>=t.rowEnd?{...e}:t.colStart<=e.colStart&&t.colEnd>=e.colEnd&&t.rowStart<=e.rowStart&&t.rowEnd>=e.rowEnd?{...t}:e.colStart===t.colStart&&e.colEnd===t.colEnd&&e.rowStart<=t.rowEnd+1&&t.rowStart<=e.rowEnd+1?{colStart:e.colStart,rowStart:Math.min(e.rowStart,t.rowStart),colEnd:e.colEnd,rowEnd:Math.max(e.rowEnd,t.rowEnd)}:e.rowStart===t.rowStart&&e.rowEnd===t.rowEnd&&e.colStart<=t.colEnd+1&&t.colStart<=e.colEnd+1?{colStart:Math.min(e.colStart,t.colStart),rowStart:e.rowStart,colEnd:Math.max(e.colEnd,t.colEnd),rowEnd:e.rowEnd}:null}var Ph=(e,t)=>e-t;function Fh(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd&&e.colStart<=t.colEnd&&t.colStart<=e.colEnd}var Ih=class{constructor(){this._bands=new Map,this._tall=[],this._isTall=[],this._all=[],this._isKnown=[],this._overlapping=!1}isOverlapping(){return this._overlapping}markOverlapping(){this._overlapping=!0}add(e,t){this._isKnown[e]||(this._isKnown[e]=!0,this._all.push(e));let n=t.rowStart>>5,r=t.rowEnd>>5;if(r-n>64)return void(this._isTall[e]||(this._isTall[e]=!0,this._tall.push(e)));let i=this._bands;for(let t=n;t<=r;t++){let n=i.get(t);n===void 0&&i.set(t,n=[]),n.push(e)}}collectRows(e,t,n,r,i){let a=this._tall;for(let e=0;e<a.length;e++){let t=a[e];n[t]!==r&&(n[t]=r,i.push(t))}let o=e>>5,s=t>>5;if(s-o>64){let e=this._all;for(let t=0;t<e.length;t++){let a=e[t];n[a]!==r&&(n[a]=r,i.push(a))}return}let c=this._bands;for(let e=o;e<=s;e++){let t=c.get(e);if(t!==void 0)for(let e=0;e<t.length;e++){let a=t[e];n[a]!==r&&(n[a]=r,i.push(a))}}}collectNeighbors(e,t,n,r){this.collectRows(e.rowStart-1,e.rowStart-1,t,n,r),this.collectRows(e.rowEnd+1,e.rowEnd+1,t,n,r),(e.rowEnd>>5)-(e.rowStart>>5)>64&&!this._overlapping||this.collectRows(e.rowStart,e.rowEnd,t,n,r)}},Lh=class{constructor(){this._keys=[]}getSize(){return this._keys.length}push(e){let t=this._keys;t.push(e);let n=t.length-1;for(;n>0;){let e=n-1>>1;if(t[e]<=t[n])break;let r=t[e];t[e]=t[n],t[n]=r,n=e}}pop(){let e=this._keys,t=e[0],n=e.pop(),r=e.length;if(r>0){e[0]=n;let t=0;for(;;){let n=2*t+1;if(n>=r)break;let i=n+1,a=i<r&&e[i]<e[n]?i:n;if(e[t]<=e[a])break;let o=e[t];e[t]=e[a],e[a]=o,t=a}}return t}};function Rh(e,t){let n=e.map(e=>({...e})),r=Array(n.length).fill(!1),i=n.length+t.length;return i*i<=256?(function(e,t,n){for(let r=0;r<n.length;r++){let i=[n[r]];for(let t=0;t<e.length&&i.length>0;t++){let n=[];for(let r=0;r<i.length;r++)n.push(...jh(i[r],e[t]));i=n}for(let n=0;n<i.length;n++)e.push(i[n]),t.push(!0)}let r=!0;for(;r;){r=!1;for(let n=0;n<e.length&&!r;n++)for(let i=n+1;i<e.length&&!r;i++){if(!t[n]&&!t[i])continue;let a=Nh(e[n],e[i]);a&&(e[n]=a,t[n]=!0,e.splice(i,1),t.splice(i,1),r=!0)}}}(n,r,t),n):function(e,t,n){let r=e.length,i=Array(r).fill(!0),a=Array(r).fill(-1),o=new Lh,s=[],c=0,l=l=>{s.length=0,n.collectNeighbors(e[l],a,c++,s);for(let n=0;n<s.length;n++){let a=s[n];if(a===l||!i[a]||!t[l]&&!t[a]||!Nh(e[l],e[a]))continue;let c=a<l?a:l,u=a<l?l:a;o.push(c*r+u)}};for(let e=0;e<r;e++)l(e);for(;o.getSize()>0;){let a=o.pop(),s=Math.floor(a/r),c=a-s*r;if(!i[s]||!i[c]||!t[s]&&!t[c])continue;let u=Nh(e[s],e[c]);u&&(e[s]=u,t[s]=!0,i[c]=!1,n.add(s,u),l(s))}let u=[];for(let t=0;t<r;t++)i[t]&&u.push(e[t]);return u}(n,r,function(e,t,n){let r=new Ih,i=[],a=[],o=e.length;for(let t=0;t<o;t++){if(i.push(-1),!r.isOverlapping()){a.length=0,r.collectRows(e[t].rowStart,e[t].rowEnd,i,-2-t,a);for(let n=0;n<a.length;n++)if(Fh(e[t],e[a[n]])){r.markOverlapping();break}}r.add(t,e[t])}for(let o=0;o<n.length;o++){a.length=0,r.collectRows(n[o].rowStart,n[o].rowEnd,i,o,a),a.sort(Ph);let s=[n[o]];for(let t=0;t<a.length&&s.length>0;t++){let r=e[a[t]];if(!Fh(n[o],r))continue;let i=[];for(let e=0;e<s.length;e++)i.push(...jh(s[e],r));s=i}for(let n=0;n<s.length;n++){let a=e.length;e.push(s[n]),t.push(!0),i.push(-1),r.add(a,s[n])}}return r}(n,r,t))}function zh(e,t){let n=t?.protection?.alwaysUnlocked;if(n!==void 0)return n;let r=t?.named;if(r){let t=e.getNamedStyles().getByName(r)?.getRanged().getPropertiesAt(0,0,null)?.protection?.alwaysUnlocked;if(t!==void 0)return t}return e.getNormal().getProtection().isAlwaysUnlocked()}function Bh(e,t){let n=t?.protection?.showFormulas;if(n!==void 0)return n;let r=t?.named;if(r){let t=e.getNamedStyles().getByName(r)?.getRanged().getPropertiesAt(0,0,null)?.protection?.showFormulas;if(t!==void 0)return t}return e.getNormal().getProtection().isShowFormulas()}function Vh(e,t,r,i,a){let o=e.search(r,!1);if(o.length===0||!i?.isLocked()||i.isShowFormulasAllowed())return o;let s=a.getNormal().getProtection().isShowFormulas(),c=[],l=t.search(r,!1);for(let e=0;e<l.length;e++)Bh(a,l[e].value?.getPropertiesAt(0,0,null))!==s&&c.push(l[e]);if(s&&c.length===0)return o;let u=[];for(let e=0;e<o.length;e++){let t=o[e],r;if(s)r=Mh([t],c);else{r=[];for(let e=0;e<c.length;e++){let i=n.CoordUtils.intersectRanges(t,c[e]);i&&r.push(i)}}for(let e=0;e<r.length;e++){let n=r[e];u.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:t.value})}}return u}function Hh(e,t){if(!e||!t)return e===t;if(e===t)return!0;if(e.style!==t.style)return!1;if(e.color===t.color)return!0;let n=e.color;e.color?.isIColor&&(n=e.color.toString());let r=t.color;return t.color?.isIColor&&(r=t.color.toString()),n===r}function Uh(e,t,n,r){let i=r?V.Edge.Left:V.Edge.Top,a=r?V.Edge.Right:V.Edge.Bottom,o=r?V.Edge.Vertical:V.Edge.Horizontal,s=r?t.colStart:t.rowStart,c=r?t.colEnd:t.rowEnd,l=r?n.colStart:n.rowStart,u=r?n.colEnd:n.rowEnd,d=s===l,f=c===u,p={...e};return d&&f?e:(delete p[i],delete p[a],delete p[o],d?e[i]!==void 0&&(p[i]=e[i]):e[o]!==void 0&&(p[i]=e[o]),f?e[a]!==void 0&&(p[a]=e[a]):e[o]!==void 0&&(p[a]=e[o]),u-l>0&&e[o]!==void 0&&(p[o]=e[o]),Object.keys(p).length===0?null:p)}function Wh(e,t,n){let r=e.colEnd-e.colStart+1,i=e.rowEnd-e.rowStart+1,a=t.borders;if(r===1&&i===1||!a)return[[e,t]];let o=n!==void 0&&e.colEnd>=n.colEnd,s=n!==void 0&&e.rowEnd>=n.rowEnd;if((o||s)&&(a={...a},o&&(a[V.Edge.Vertical]===void 0?delete a[V.Edge.Right]:a[V.Edge.Right]=a[V.Edge.Vertical]),s&&(a[V.Edge.Horizontal]===void 0?delete a[V.Edge.Bottom]:a[V.Edge.Bottom]=a[V.Edge.Horizontal]),Object.keys(a).length===0)){let n={...t};return delete n.borders,Object.keys(n).length>0?[[e,n]]:[]}let c=r===1||Hh(a[V.Edge.Left],a[V.Edge.Vertical])&&Hh(a[V.Edge.Right],a[V.Edge.Vertical]),l=i===1||Hh(a[V.Edge.Top],a[V.Edge.Horizontal])&&Hh(a[V.Edge.Bottom],a[V.Edge.Horizontal]);if(c&&l)return[[e,a===t.borders?t:{...t,borders:a}]];let u=[],d=(e,t,n,r,a)=>{let o=Uh(n,e,t,a);if(!o)return;if(!a||i===1){let e={...r};e.borders=o,u.push([t,e]);return}let c={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowStart};if(d(t,c,o,r,!1),i>2||s){let e={colStart:t.colStart,rowStart:t.rowStart+1,colEnd:t.colEnd,rowEnd:s?t.rowEnd:t.rowEnd-1};d(t,e,o,r,!1)}if(!s){let e={colStart:t.colStart,rowStart:t.rowEnd,colEnd:t.colEnd,rowEnd:t.rowEnd};d(t,e,o,r,!1)}};return r===1?d(e,e,a,t,!0):(d(e,{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowEnd},a,t,!0),(r>2||o)&&d(e,{colStart:e.colStart+1,rowStart:e.rowStart,colEnd:o?e.colEnd:e.colEnd-1,rowEnd:e.rowEnd},a,t,!0),o||d(e,{colStart:e.colEnd,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd},a,t,!0)),u}var Gh=[9,99,999,9999,99999,999999],Kh=(e,t)=>{let n=(n,r)=>Math.max(0,Math.min(t,r)-Math.max(e,n)+1);return n(0,25)+2*n(26,701)+3*n(702,16383)},qh=e=>{let t=[];for(let n of e){let e=n.colEnd-n.colStart+1,r=Kh(n.colStart,n.colEnd);t.push([n.rowStart,e,r],[n.rowEnd+1,-e,-r])}t.sort((e,t)=>e[0]-t[0]);let n=[],r=0,i=0,a=t.length;for(let e=0;e<a;){let o=t[e][0];for(;e<a&&t[e][0]===o;)r+=t[e][1],i+=t[e][2],e++;e<a&&r>0&&n.push({min:o,max:t[e][0]-1,count:r,letters:i})}return n},Jh=(e,t,n)=>{let r=qh(e);if(r.length===0)return[];let i=qh(t),a=[...Gh];for(let e of r)a.push(e.min,e.max+1);for(let e of i)a.push(e.min,e.max+1);a.sort((e,t)=>e-t);let o=n.rowEnd-1,s=[],c=0,l=0,u=a.length;for(let e=0;e<u-1;e++){let t=a[e],n=Math.min(a[e+1]-1,o);if(n<t)continue;for(;c<r.length&&r[c].max<t;)c++;if(c>=r.length||r[c].min>t)continue;for(;l<i.length&&i[l].max<t;)l++;let u=l<i.length&&i[l].min<=t?i[l]:null,d=String(t+1).length,f=r[c].count*(7+d)+r[c].letters;if(23+(u?u.count*(17+d)+u.letters:0)>=f)continue;let p=s[s.length-1];p&&p.max+1===t?p.max=n:s.push({min:t,max:n})}return s},Yh=(e,t,n,r)=>{let i=e.rowStart,a=t.length;for(let o=0;o<a&&i<=e.rowEnd;o++){let a=t[o];if(a.max<i||a.min>e.rowEnd)continue;a.min>i&&r?.({...e,rowStart:i,rowEnd:a.min-1});let s=Math.min(a.max,e.rowEnd);n?.({...e,rowStart:Math.max(a.min,i),rowEnd:s}),i=s+1}i<=e.rowEnd&&r?.({...e,rowStart:i})},Xh=(e,t,n,r)=>{let i=t,a=[],o=e[i],s=o.value;for(;o;){if(r){let e=o.rowEnd-o.rowStart+1;a.push({min:o.colStart,max:o.colEnd,value:e,touchMax:o.rowEnd})}else{let e=o.colEnd-o.colStart+1;a.push({min:o.rowStart,max:o.rowEnd,value:e,touchMax:o.colEnd})}i++,o=e[i],o&&o.value!==s&&(o=null)}let c=a.length;if(c===0)return i;if(c===1)return n.push(a[0]),i;a.sort((e,t)=>e.min===t.min?e.max-t.max:e.min-t.min);let l={...a[0]};for(let e=1;e<c;e++){let t=a[e],r=l.max,i=t.min;if(i<=r+1)if(i<=r){let e=t.max,a=t.value,o=l.value,s=l.min,c=Math.min(r,e);i>s&&n.push({min:s,max:i-1,value:o,touchMax:l.touchMax});let u=o+a,d=Math.max(l.touchMax,t.touchMax);c<Math.max(r,e)?(n.push({min:i,max:c,value:u,touchMax:d}),l=e>c?{min:c+1,max:e,value:a,touchMax:t.touchMax}:{min:c+1,max:r,value:o,touchMax:l.touchMax}):l={min:i,max:c,value:u,touchMax:d}}else n.push(l),l={...t};else n.push(l),l={...t}}return n.push(l),i},Zh={onUpdate:(e,t)=>({...e,s:t}),onSplit:e=>[e.value,e.value],onMerge:(e,t,r,i)=>{if(e.s===t.s)return n.CommonUtils.deepEqual(e,t)?e:void 0}},Qh=(e,t,n,r,i)=>{let a=t.colStart,o=t.rowStart,s=t.colEnd,c=t.rowEnd,l=i?c-o+1:s-a+1,u=Math.floor(.5*l),d=i?c:s,f=e.length,p=0;do{let t=e[p].value,a=[];p=Xh(e,p,a,i);let o=a.length;for(let e=0;e<o;e++){let o=a[e];o.value<u||o.touchMax<d||!i&&o.min>=c||(i||n===null||n!==t)&&(r=Tt(wt(r??[],{min:o.min,max:o.max,value:t},Zh)))}}while(p<f);return r};function $h(e,r){let i=e.before,a=e.after;if(i&&r){let o=e.amount,s=e.axis===t.IRange.Axis.Column,c=s?`colStart`:`rowStart`,l=s?`colEnd`:`rowEnd`,u=r[c],d=r[l],f=i[c]<=u,p=i[l]>=d,m=a?a[c]:-1;if(f&&p)return i;if(f&&o>0&&m!==u)a={...a},a[c]=u;else if(p)if(o>0){if(m>d)throw new n.OutOfBoundsError(``);a={...a},a[l]=d}else a?(a={...a},a[l]=d):(a={...i},a[c]=e.intersect[c])}if(!a)return null;if(r&&!n.CoordUtils.isRangeWithinRange(a,r))throw new n.OutOfBoundsError(``);return n.CoordUtils.sanitizeRange(a)}var eg=e=>{if(e==null)return null;let t,n=Object.keys(e),r=n.length;for(let i=0;i<r;i++){let r=n[i],a=e[r],o=a;if(a===null)o=void 0;else if(a&&typeof a==`object`&&!Array.isArray(a)){let e=eg(a);o=e===null?void 0:e}if(o!==a){if(t===void 0){t={};for(let r=0;r<i;r++)t[n[r]]=e[n[r]]}o!==void 0&&(t[r]=o)}else t!==void 0&&(t[r]=a)}return t===void 0?r===0?null:e:Object.keys(t).length===0?null:t},tg=class e{constructor(e,n,r,i,a,o){this._c=e,this._getEntireRange=n,this._r=r,this._p=i??null,this._t=a??null,this._o=o??t.IRange.AxisSelection.Both,this._e=this._p===null||Object.keys(this._p).length===1&&this._p.named===q.BuiltInName.Normal}isEmpty(){return this._e}getProperties(){return this._p}getCoords(){return this._r}getUpdateProperties(){return this._u}getMeasureKey(){let e=this._mk;if(e===void 0){let t=this._p;if(t){let n=t.alignment;e=JSON.stringify([t.named??null,t.numberFormat??null,t.font??null,n?[n.overflow??null,n.rotation??null,n.indent??null]:null,t.insets??null])}else e=``;this._mk=e}return e}static{this.BorderKeys=[`borders`]}static{this.FillKeys=[`fill`]}static{this.ContentKeys=[`font`,`numberFormat`,`alignment`,`quotePrefix`,`protection`,`named`,`insets`]}splitByFeature(){let t=(e,t)=>{if(!e)return;let n;for(let r=0;r<t.length;r++){let i=t[r];e[i]!==void 0&&((n??={})[i]=e[i])}return n},n=n=>{let r=t(this._p,n),i=t(this._u,n);if(r===void 0&&i===void 0)return null;let a=new e(this._c,this._getEntireRange,this._r,r??null,this._t,this._o);return i!==void 0&&(a._u=i),a};return{border:n(e.BorderKeys),fill:n(e.FillKeys),content:n(e.ContentKeys)}}static compose(t,n,r){if(!t&&!n&&!r)return null;if(t&&!n&&!r)return t;if(!t&&n&&!r)return n;if(!t&&!n&&r)return r;let i=t??r??n,a={...r?r._p:null,...n?n._p:null,...t?t._p:null};return new e(i._c,i._getEntireRange,i._r,a,i._t,i._o)}static mergeOverlay(t,n){if(!t)return n??null;if(!n)return t;let r=n._p?.borders?n:t,i={...t._p,...n._p};return new e(r._c,r._getEntireRange,r._r,i,r._t,r._o)}cloneWithUpdate(t,r=!1){if(t===void 0)return this;let i=this._c,a=this._r,o=this._p,s=n.TypedObject.resolveTypedUpdates(t,Th,i,o,r);if(r){let t=eg(s),n=new e(i,this._getEntireRange,a,t,this._t,this._o);return t!==s&&(n._u=s),n}return new e(i,this._getEntireRange,a,s,this._t,this._o)}copyTo(t,r){let i=this._c,a=this._r,o=t.rowStart-a.rowStart,s=t.colStart-a.colStart,c=null;return n.CoordUtils.isEqualRanges(a,this._t)||(c=n.CoordUtils.translateRange(a,o,s)),{...t,value:new e(i,this._getEntireRange,t,this._p,c,this._o)}}canTile(e,t){return!(this._u??this._p)?.borders}_createShifted(t){return new e(this._c,this._getEntireRange,t,this._p,this._t,this._o)}getShifted(e){let t=this._getEntireRange?.(),n=$h(e,t);return n?{...n,value:this._createShifted(n)}:null}getSplit(n,r){let i=this._c,a=this._u,o=a??this._p,s=this._r,c=o,l=n[0],u=o,d=n[1],f=o?o.borders:null;if(f){let e=r===t.IRange.Axis.Column;if(e?f.left!==void 0||f.right!==void 0||f.vertical!==void 0:f.top!==void 0||f.bottom!==void 0||f.horizontal!==void 0){c={...c};let t=Uh(f,s,l,e);t?c.borders=t:t===null&&delete c.borders,u={...u};let n=Uh(f,s,d,e);n?u.borders=n:n===null&&delete u.borders}}let p=this._t,m=this._o,h=this._getEntireRange;if(a){let t=new e(i,h,n[0],eg(c),p,m);t._u=c;let r=new e(i,h,n[1],eg(u),p,m);return r._u=u,[t,r]}return[new e(i,h,n[0],c,p,m),new e(i,h,n[1],u,p,m)]}getMerged(r,i,a){let o=a===t.IRange.Axis.Column,s=this._p,c=r._p;if(s&&!c||c&&!s||!s&&!c)return;let l=Object.keys(s),u=Object.keys(c),d=l.length;if(d!==u.length)return;for(let e=0;e<d;e++){let t=l[e];if(t===`borders`)continue;let r=s[t],i=c[t];if(!n.CommonUtils.deepEqual(r,i))return}let f=s.borders,p=c.borders;if(f&&!p||p&&!f)return;let m=this._c;if(f||p){let t=o?V.Edge.Top:V.Edge.Left,a=o?V.Edge.Bottom:V.Edge.Right;if(!Hh(f[t],p[t])||!Hh(f[a],p[a]))return;let c=this._r,l=r._r,u=1+(o?c.rowEnd-c.rowStart:c.colEnd-c.colStart),d=1+(o?c.colEnd-c.colStart:c.rowEnd-c.rowStart),h=1+(o?l.colEnd-l.colStart:l.rowEnd-l.rowStart),g=o?V.Edge.Horizontal:V.Edge.Vertical;if(u>1&&!Hh(f[g],p[g]))return;let _=o?V.Edge.Right:V.Edge.Bottom,v=o?V.Edge.Left:V.Edge.Top;if(!Hh(f[_],p[v]))return;let y=o?V.Edge.Vertical:V.Edge.Horizontal,b=f[_];if(d>1&&!Hh(b,f[y]))return;let x=h===1?p[v]:p[y];if(h>1&&!Hh(x,p[y])||!Hh(b,x))return;let S={borders:{[t]:f[t],[a]:f[a],[g]:f[g],[y]:b,[v]:f[v],[_]:p[_]}},C=n.TypedObject.resolveTypedUpdates(S,Ch,m,s);return new e(m,this._getEntireRange,i,C,this._t,this._o)}return new e(m,this._getEntireRange,i,this._p,this._t,this._o)}hasTrailingEdge(){return!0}isMergeOnShift(){return!0}getInnerBorder(e){let t=this._p?.borders;if(!t)return null;let r=this._t??this._r;if(!r||!n.CoordUtils.isRangeWithinRange(e,r))return null;let i=this._localizeBorderRange(t,r,e);return i?i.horizontal===void 0&&i.vertical===void 0?null:i:null}_localizeBorderRange(e,t,n){if(!e)return;let r=null,i=t.rowStart,a=t.rowEnd,o=n.rowStart,s=n.rowEnd;e.top&&o===i&&(r??={},r.top=e.top),e.bottom&&s===a&&(r??={},r.bottom=e.bottom),e.horizontal&&(s-o>0&&(r??={},r.horizontal=e.horizontal),o>i&&(r??={},r.top=e.horizontal),s<a&&(r??={},r.bottom=e.horizontal));let c=t.colStart,l=t.colEnd,u=n.colStart,d=n.colEnd;return e.left&&u===c&&(r??={},r.left=e.left),e.right&&d===l&&(r??={},r.right=e.right),e.vertical&&(d-u>0&&(r??={},r.vertical=e.vertical),u>c&&(r??={},r.left=e.vertical),d<l&&(r??={},r.right=e.vertical)),r}_localizeBorder(e,t,n,r){if(!e)return;let i=null,a=t.rowStart,o=t.rowEnd;e.top&&n===a&&(i??={},i.top=e.top),e.bottom&&n===o&&(i??={},i.bottom=e.bottom),e.horizontal&&(n>a&&(i??={},i.top=e.horizontal),n<o&&(i??={},i.bottom=e.horizontal));let s=t.colStart,c=t.colEnd;return e.left&&r===s&&(i??={},i.left=e.left),e.right&&r===c&&(i??={},i.right=e.right),e.vertical&&(r>s&&(i??={},i.left=e.vertical),r<c&&(i??={},i.right=e.vertical)),i}getPropertiesAt(e,t,n){let r=this._p,i=r,a=this._t;if(a){let n=this._r,r=a.colEnd-a.colStart+1,i=a.rowEnd-a.rowStart+1;t=n.colStart+(t-n.colStart+(a.colStart-n.colStart))%r,e=n.rowStart+(e-n.rowStart+(a.rowStart-n.rowStart))%i}let o=i?.borders;if(o&&i){let n=a??this._r,s=this._localizeBorder(o,n,e,t);s!==void 0&&(i===r&&(i={...i}),s===null?delete i.borders:i.borders=s)}return i}toJSON(){let e=n.CommonUtils.toSafeJSON(this._p);if(!e)return e;let t=e.border;return t&&(t.top?.style===V.StrokeStyle.None&&delete t.top,t.bottom?.style===V.StrokeStyle.None&&delete t.bottom,t.left?.style===V.StrokeStyle.None&&delete t.left,t.right?.style===V.StrokeStyle.None&&delete t.right,t.horizontal?.style===V.StrokeStyle.None&&delete t.horizontal,t.vertical?.style===V.StrokeStyle.None&&delete t.vertical,Object.keys(t).length===0&&delete e.borders),e}},ng=class extends tg{constructor(e,t){super(e,null,n.CoordUtils.EmptyRange,t)}isEmpty(){return this._p===null}getCoords(){return this._r}cloneWithUpdate(e){if(e===void 0)return this;let t=this._c,r=this._r;return new tg(t,null,r,n.TypedObject.resolveTypedUpdates(e,Ch,t,this._p))}_createShifted(e){return new tg(this._c,null,e,this._p)}getShifted(e){return e.after?{...e.after,value:this._createShifted(n.CoordUtils.sanitizeRange(e.after))}:null}getSplit(e,t){let n=this._c,r=this._p;return[new tg(n,null,e[0],r),new tg(n,null,e[1],r)]}getMerged(e,t,r){let i=this._p,a=e._p;if(i&&!a||a&&!i||!i&&!a)return;let o=Object.keys(i),s=Object.keys(a);if(i.named===q.BuiltInName.Normal&&(o=o.filter(e=>e.toLowerCase()!==q.BuiltInName.Normal)),a.named===q.BuiltInName.Normal&&(s=s.filter(e=>e.toLowerCase()!==q.BuiltInName.Normal)),o.length!==s.length)return;for(let e=0;e<o.length;e++){let t=o[e],r=i[t],s=a[t];if(!n.CommonUtils.deepEqual(r,s))return}let c=this._c;return new tg(c,null,t,this._p)}getPropertiesAt(e,t){return this._p}toJSON(){return n.CommonUtils.toSafeJSON(this._p)}},rg=class{constructor(e,t,n,r=null){this._name=t.name,this._properties=t,this._rangeStyle=new ng(e,t.style),this._doDelete=n,this._builtInID=r}getRanged(){return this._rangeStyle}getName(){return this._name}isHidden(){return this._properties.hidden??!1}getILevel(){return this._properties.iLevel??null}getBuiltInID(){return this._builtInID}delete(){this._doDelete?.(this)}toJSON(){return this._properties?n.CommonUtils.toSafeJSON(this._properties):null}get isINamed(){return!0}},ig=class{constructor(e,t,r,i,a){this._state=e,this._normalJSON=t??{},this._toJSONInternal=r,this._fromJSONInternal=i,this._onLastEnd=a,this._state.openScopes.add(this),this._isClosed=!1,this._state.byJSONs.set(n.BufferUtils.JSONStableStringify(this._normalJSON),0),this._state.byIds.set(0,this._normalJSON)}endPersist(){if(!this._state.openScopes.delete(this))throw Error(`PersistScope is closed.`);this._isClosed=!0,this._state.openScopes.size===0&&this._onLastEnd()}getElementID(e){if(this._isClosed)throw Error(`PersistScope is closed.`);e??={};let t=n.BufferUtils.JSONStableStringify(e),r=this._state.byJSONs.get(t);return r!==void 0||(r=this._state.byJSONs.size,this._state.byJSONs.set(t,r),this._state.byIds.set(r,e)),r}getElementJSON(e){if(this._isClosed)throw Error(`PersistScope is closed.`);return this._state.byIds.get(e)??null}fromJSON(e){if(this._isClosed)throw Error(`PersistScope is closed.`);let t=JSON.parse(JSON.stringify(e||{}));this._fromJSONInternal(t);let r=t.direct,i=r?r.length:0;for(let e=0;e<i;e++){let t=e,i=r[e],a=n.BufferUtils.JSONStableStringify(i);this._state.byIds.set(t,i),this._state.byJSONs.set(a,t)}}toJSON(){if(this._isClosed)throw Error(`PersistScope is closed.`);let e=[];return this._state.byIds.forEach((t,n)=>{e[n]=t}),e.length===1&&e.splice(0,1),this._toJSONInternal(e)}},ag=class{constructor(e=null,t=null,n=11){this._builtInsCellStylesComplete=!1,this._builtInsTableStyles=null,this._defaultTableStyle=null,this._theme=e??new up().getDefaultTheme(),this._defaultFontSize=n;let r=this;this._emitter=new x(this),this._schemeLookup=e=>r._theme.schemeLookup()(e),this._indexedLookup=e=>this._customIndexedColors[e]??null,this._customCellStyles=new Map,this._customTableStyles=new Map,this._builtInsCellStyles=new Map,this._mruColors=[],this._persistCache=null,this._customIndexedColors=this._fromJSONIndexedColors(t),this._initializeBuiltIns(),this._namedStyles=new fp({builtIns:()=>r._ensureBuiltInCellStyles(),customs:()=>r._customCellStyles,set:(e,t)=>r._setNamedStyle(e,t)}),this._tableStyles=new mp({builtIns:()=>r._ensureBuiltInTableStyles(),customs:()=>r._customTableStyles,set:(e,t)=>r._setCustomTableStyleInternal(e,t),getDefault:()=>r._getDefaultTableStyle(),setDefault:e=>r._setDefaultTableStyle(e),getNone:()=>r._emptyTableStyle}),this._namedStyles.addListeners({onCollectionChange:()=>{r._emitter.notify(`onNamedStylesChange`),r._emitter.notify(`onAnyChange`)}}),this._tableStyles.addListeners({onCollectionChange:()=>{r._emitter.notify(`onTableStylesChange`),r._emitter.notify(`onAnyChange`)}})}getNamedStyles(){return this._namedStyles}getTableStyles(){return this._tableStyles}_initializeNamedStyles(e,t,r=0,i=2**53-1){let a=Math.min(e?e.length:0,i);for(let i=r;i<a;i++){let r=e[i],a={...r},o=r.named;delete a.named;let s=n.TypedObject.resolveTypedUpdates(a,Ch,this),c=new rg(this,{name:o,style:s},this._hideOrRemoveNamed.bind(this),i);o===q.BuiltInName.Normal&&(this._normalRanged=c.getRanged(),this._normalStyle=Yg(void 0,this,null)),t.set(o.toLowerCase(),c)}}_initializeTableStyles(){let e=(()=>{if(Sp)return Sp;let e=new Map;Sp=e;let t=(e,t)=>{if(t===0)return`TableStyleNone`;let n=`Custom`;return e===`l`?n=`Light`:e===`m`?n=`Medium`:e===`d`&&(n=`Dark`),`TableStyle${n}${t}`},n=(e,t=0)=>t>0?`${e} lumMod ${100-t}, lumOff ${t}`:t<0?`${e} lumMod ${100+t}`:e,r=e=>({type:K.Type.Pattern,patternType:K.BuiltInSheetPattern.Solid,foreground:e,background:e}),i=(e,t=!1)=>{let n={color:e};return t&&(n.weight=700),n},a=(e,t=V.StrokeStyle.Thin)=>({style:t,color:e}),o=(e,t)=>{for(let n=0;n<7;n++)e.push(t(`accent${n+1}`))},s=0,c=[];c.push([`dk1`,n(`bg1`,-15),`dk1`]),o(c,e=>[n(e,-25),n(e,80),e]),s=1;for(let n=0;n<7;n++){let o=t(`l`,n+s),l=c[n][0],u=c[n][1]??l,d=c[n][2]??l;e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(l),borders:{top:a(d),bottom:a(d)}},headerRow:{font:i(l,!0),borders:{bottom:a(d)}},totalRow:{font:i(l,!0),borders:{top:a(d)}},firstColumn:{font:i(l,!0)},lastColumn:{font:i(l,!0)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}s+=7,c=[],c.push([`dk1`,`dk1`,`lt1`]),o(c,e=>[`dk1`,e,`lt1`]);for(let n=0;n<7;n++){let o=t(`l`,n+s),l=c[n][0],u=c[n][1],d=c[n][2];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(l),borders:{left:a(u),right:a(u),top:a(u),bottom:a(u)}},headerRow:{font:i(d,!0),fill:r(u)},totalRow:{font:i(l,!0),borders:{top:a(u,V.StrokeStyle.Double)}},firstColumn:{font:i(l,!0)},lastColumn:{font:i(l,!0)},firstRowStripe:{borders:{top:a(u)}},secondRowStripe:{borders:{top:a(u)}},firstColumnStripe:{borders:{left:a(u)}},secondColumnStripe:{borders:{left:a(u)}}}))}s+=7,c=[],c.push([`dk1`,n(`bg1`,-15)]),o(c,e=>[e,n(e,80)]);for(let n=0;n<7;n++){let o=t(`l`,n+s),l=c[n][0],u=c[n][1];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`dk1`),borders:{left:a(l),right:a(l),top:a(l),bottom:a(l),horizontal:a(l),vertical:a(l)}},headerRow:{font:i(`dk1`,!0)},totalRow:{font:i(`dk1`,!0),borders:{top:a(l,V.StrokeStyle.Double)}},firstColumn:{font:i(`dk1`,!0)},lastColumn:{font:i(`dk1`,!0)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}s=1,c=[],c.push([`dk1`,`dk1`,n(`bg1`,-15)]),o(c,e=>[e,n(e,40),n(e,80)]);for(let n=0;n<7;n++){let o=t(`m`,n+s),l=c[n][0],u=c[n][1],d=c[n][2];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`dk1`),borders:{left:a(u),right:a(u),top:a(u),bottom:a(u),horizontal:a(u)}},headerRow:{font:i(`lt1`,!0),fill:r(l)},totalRow:{font:i(`dk1`,!0),borders:{top:a(l,V.StrokeStyle.Double)}},firstColumn:{font:i(`dk1`,!0)},lastColumn:{font:i(`dk1`,!0)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}s+=7,c=[],c.push([`dk1`,n(`bg1`,-15),n(`bg1`,-35)]),o(c,e=>[e,n(e,80),n(e,60)]);for(let n=0;n<7;n++){let o=t(`m`,n+s),l=c[n][0],u=c[n][1],d=c[n][2];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`dk1`),fill:r(u),borders:{horizontal:a(`lt1`),vertical:a(`lt1`)}},headerRow:{font:i(`lt1`,!0),fill:r(l),borders:{bottom:a(`lt1`,V.StrokeStyle.Thick)}},totalRow:{font:i(`lt1`,!0),fill:r(l),borders:{top:a(`lt1`,V.StrokeStyle.Thick)}},firstColumn:{font:i(`lt1`,!0),fill:r(l)},lastColumn:{font:i(`lt1`,!0),fill:r(l)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}s+=7,c=[],c.push([`dk1`,n(`bg1`,-15),n(`bg1`,-35)]),o(c,e=>[e,n(e,80),n(e,60)]);for(let o=0;o<7;o++){let l=t(`m`,o+s),u=c[o][0],d=n(`bg1`,-15);e.set(l.toLocaleLowerCase(),Object.freeze({name:l,wholeTable:{font:i(`dk1`),borders:{top:a(`dk1`,V.StrokeStyle.Medium),bottom:a(`dk1`,V.StrokeStyle.Medium),left:o===0?a(`dk1`,V.StrokeStyle.Thin):void 0,right:o===0?a(`dk1`,V.StrokeStyle.Thin):void 0,horizontal:o===0?a(`dk1`,V.StrokeStyle.Thin):void 0,vertical:o===0?a(`dk1`,V.StrokeStyle.Thin):void 0}},headerRow:{font:i(`lt1`,!0),fill:r(u),borders:{bottom:a(`dk1`,V.StrokeStyle.Medium)}},totalRow:{borders:{top:a(`dk1`,V.StrokeStyle.Double)}},firstColumn:{font:i(`lt1`,!0),fill:r(u)},lastColumn:{font:i(`lt1`,!0),fill:r(u)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}s+=7,c=[],c.push([`dk1`,n(`bg1`,-15),n(`bg1`,-35),`dk1`]),o(c,e=>[e,n(e,80),n(e,60),n(e,40)]);for(let n=0;n<7;n++){let o=t(`m`,n+s),l=c[n][0],u=c[n][1],d=c[n][2],f=c[n][3];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`dk1`),fill:r(u),borders:{top:a(f),right:a(f),left:a(f),bottom:a(f),vertical:a(f),horizontal:a(f)}},headerRow:{font:i(`dk1`),fill:r(u)},totalRow:{font:i(`dk1`),borders:{top:a(l,V.StrokeStyle.Medium)}},firstColumn:{font:i(`dk1`,!0)},lastColumn:{font:i(`dk1`,!0)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}s=1,c=[],c.push([`dk1`,n(`dk1`,15),n(`dk1`,25),n(`dk1`,50)]),o(c,e=>[`dk1`,n(e,-50),n(e,-25),e]);for(let n=0;n<7;n++){let o=t(`d`,n+s),l=c[n][0],u=c[n][1],d=c[n][2],f=c[n][3];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`lt1`),fill:r(f)},headerRow:{font:i(`lt1`,!0),fill:r(l),borders:{bottom:a(`lt1`,V.StrokeStyle.Medium)}},totalRow:{font:i(`lt1`,!0),fill:r(u),borders:{top:a(`lt1`,V.StrokeStyle.Medium)}},firstColumn:{font:i(`lt1`,!0),fill:r(d),borders:{right:a(`lt1`,V.StrokeStyle.Medium)}},lastColumn:{font:i(`lt1`,!0),fill:r(d),borders:{left:a(`lt1`,V.StrokeStyle.Medium)}},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}s+=7,c=[],c.push([n(`bg1`,-15),`dk1`,n(`bg1`,-35)]),c.push([n(`accent1`,80),`accent2`,n(`accent1`,60)]),c.push([n(`accent3`,80),`accent4`,n(`accent3`,60)]),c.push([n(`accent5`,80),`accent6`,n(`accent5`,60)]);for(let n=0;n<4;n++){let o=t(`d`,n+s),l=c[n][0],u=c[n][1],d=c[n][2];e.set(o.toLocaleLowerCase(),Object.freeze({name:o,wholeTable:{font:i(`dk1`),fill:r(l)},headerRow:{font:i(`lt1`,!0),fill:r(u)},totalRow:{font:i(`dk1`,!0),borders:{top:a(`dk1`,V.StrokeStyle.Double)}},firstColumn:{font:i(`dk1`,!0)},lastColumn:{font:i(`dk1`,!0)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}return e})(),t=new Map;return e.forEach((e,n)=>{let r=e.name.toLowerCase(),i=new kh(this,e,!0);t.set(r,i)}),t}_initializeBuiltIns(){this._initializeNamedStyles(xp,this._builtInsCellStyles,0,1),this._emptyTableStyle=new Hf.Empty(this._normalStyle)}_ensureBuiltInCellStyles(){return this._builtInsCellStylesComplete||(this._builtInsCellStylesComplete=!0,this._initializeNamedStyles(xp,this._builtInsCellStyles,1)),this._builtInsCellStyles}_ensureBuiltInTableStyles(){return this._builtInsTableStyles??=this._initializeTableStyles()}getNormal(){return this._normalStyle}getNormalRanged(){return this._normalRanged}setTheme(e){this._theme=e,this._emitter.notify(`onThemeChange`),this._emitter.notify(`onAnyChange`)}getTheme(){return this._theme}setDefaultFontSize(e){this._defaultFontSize=e,this._emitter.notify(`onDefaultFontChange`),this._emitter.notify(`onAnyChange`)}getDefaultFontSize(){return this._defaultFontSize}beginPersist(){return this._persistCache||={byIds:new Map,byJSONs:new Map,openScopes:new Set},new ig(this._persistCache,{},this._toJSONInternal.bind(this),this._fromJSONInternal.bind(this),()=>{this._persistCache=null})}getNamed(e){return this._namedStyles.getByName(e)}getCustomNamed(){return this._namedStyles.getItems({type:jf.BuiltInFilterType.Custom,includeHidden:!0})}setNamed(e,t=!1){return this._namedStyles.set(e,t)}_setNamedStyle(e,t=!1){if(!e||!e.name||!e.style)throw new n.NullNotAllowedError;return this.validateStyleName(e.name,!1),this._setCustomCellStyleInternal(e,t)}_setCustomCellStyleInternal(e,t=!1,r=0){let i=e.name.toLowerCase(),a=this._ensureBuiltInCellStyles().get(i),o=a?.getBuiltInID()??null,s=null;t&&(s=(this._customCellStyles.get(i)??a)?._properties??null);let c=Mg(e.style,this.getNormal());e={...e,style:c};let l=n.TypedObject.resolveTypedUpdates(e,Eh,this,s),u=l.style,d=u?.named;if(typeof d==`string`&&d.toLowerCase()!==i){let e={...u};delete e.named;let t=d.toLowerCase()===q.BuiltInName.Normal.toLowerCase()?null:this.getNamed(d)?.getRanged().getPropertiesAt(0,0,null),r=t?n.TypedObject.resolveTypedUpdates(e,Ch,this,t):e;l={...l,style:r}}let f=new rg(this,l,this._hideOrRemoveNamed.bind(this),o);return l.name===q.BuiltInName.Normal&&(this._normalRanged=f.getRanged(),this._normalStyle=Yg(void 0,this,null)),this._customCellStyles.set(i,f),f}_setCustomTableStyleInternal(e,t){let n=e.toLowerCase(),r=this._customTableStyles.get(n)??this._ensureBuiltInTableStyles().get(n);r&&(e=r.getName());let i=new kh(this,{...t,name:e},!1,this._deleteCustomTableStyle.bind(this));return this._customTableStyles.set(n,i),i}_hideOrRemoveNamed(e){let t=null;if(t=typeof e==`string`?e:e?.getName?.(),!t||(t=t.toLowerCase(),t===q.BuiltInName.Normal.toLowerCase()))return!1;let n=this._ensureBuiltInCellStyles().get(t);if(n&&!n.isHidden())return this._namedStyles.set({...n.toJSON(),hidden:!0}),!0;let r=this._customCellStyles.delete(t);return r&&this._namedStyles._announceChange(),r}getTableStyle(e){return e?this._tableStyles.getByName(e):this._emptyTableStyle}getCustomTableStyles(){return this._tableStyles.getItems({type:jf.BuiltInFilterType.Custom})}setDefaultTableStyle(e){this._tableStyles.setDefault(e)}getDefaultTableStyle(){return this._tableStyles.getDefault()}setCustomTableStyle(e,t){return this._tableStyles.set(e,t)}_setDefaultTableStyle(e){let t=this._getDefaultTableStyle(),n=(typeof e==`string`?e:e?.getName())?.toLowerCase(),r=this._ensureBuiltInTableStyles();return this._defaultTableStyle=(n?this._customTableStyles.get(n)??r.get(n):void 0)??r.get(`tablestylemedium2`),t}_getDefaultTableStyle(){return this._defaultTableStyle||=this._ensureBuiltInTableStyles().get(Cp.toLowerCase()),this._defaultTableStyle}_deleteCustomTableStyle(e){let t=this._customTableStyles.get(e?.toLowerCase());return!!t&&(this._customTableStyles.delete(e.toLowerCase()),this._defaultTableStyle?.getName()===t.getName()&&(this._defaultTableStyle=this._ensureBuiltInTableStyles().get(Cp.toLowerCase())),this._tableStyles._announceChange(),!0)}validateStyleName(e,t=!1){if(!e||e.trim().length===0)throw Error(`Style name cannot be empty.`);if(t&&this.getNamed(e)!==null)throw Error(`Style name is already taken.`)}normalize(e,t){if(!e)return null;let r=n.TypedObject.resolveTypedUpdates(e,Ch,this);if(!r)return null;let i=null,a=t??r.named??q.BuiltInName.Normal;i=a===q.BuiltInName.Normal?this._normalRanged.getPropertiesAt(0,0,null):this.getNamed(a)?.getRanged().getPropertiesAt(0,0,null);let o=this.getTheme().getFontScheme(),s={font:{size:this.getDefaultFontSize(),family:o.getMinorFont(),fallbacks:o.getMinorFallbacks()}};return n.CommonUtils.removeEqualValuesLayered(r,[i,s,bp]),r}resolve(e,t){if(!e)return null;let r=t??e.named??q.BuiltInName.Normal,i=r===q.BuiltInName.Normal?this._normalRanged.getPropertiesAt(0,0,null):this.getNamed(r)?.getRanged().getPropertiesAt(0,0,null),a={...e};delete a.named;let o=n.TypedObject.resolveTypedUpdates(a,Ch,this,i??void 0);return o?(typeof e.named==`string`&&(o.named=e.named),o):null}schemeLookup(){return this._schemeLookup}indexedLookup(){return this._indexedLookup}parseColor(e){return zf.parse(e,this._schemeLookup,this._indexedLookup)}recentColors(){return this._mruColors}addRecentColor(e){if(!e)return this._mruColors;let t=this._mruColors,n=[],r=e.toString(),i=t.length;for(let e=0;e<i&&e<10;e++){let i=t[e];i.toString()!==r&&n.push(i)}return n.unshift(e),this._mruColors=Object.freeze(n),this._mruColors}clearRecentColors(){this._mruColors=n.CommonUtils.EmptyArray}getCustomIndexedColors(){return this._customIndexedColors}setCustomIndexedColors(e){this._customIndexedColors=(e?.length??0)>0?[...e]:[]}getIndexedColors(){let e=this._customIndexedColors,t=Math.max(e?.length,66),n=[];for(let r=0;r<t;r++){let t=e[r];if(t!==null){if(t){n.push(t);continue}let e=Mc(r);if(e){n.push(new zf(e));continue}let i=Nc(r);if(!i)continue;n.push(new zf(i.toString()))}}return n}addListeners(e,t){return this._emitter.addListeners(e,t)}_toJSONInternal(e){let t={};e.length>0&&(t.direct=e);let n=this.getCustomNamed(),r=n.length,i=Array(r);for(let e=0;e<r;e++)i[e]=n[e].toJSON();i.length>0&&(t.named=i);let a={};this._defaultTableStyle&&this._defaultTableStyle.getName()!==`TableStyleMedium2`&&(a.defaultTableStyle=this._defaultTableStyle.getName());let o={},s=this.getCustomTableStyles(),c=s.length;for(let e=0;e<c;e++){let t=s[e],n=t.toJSON();delete n.name,n&&Object.keys(n).length>0&&(o[t.getName()]=n)}Object.keys(o).length>0&&(a.styles=o),Object.keys(a).length>0&&(t.tables=a);let l=this._customIndexedColors,u=l.length??0;if(u>0){let e=Array(u);for(let t=0;t<u;t++)e[t]=l[t].toString();t.indexedColors=e}let d=this._mruColors,f=d.length;if(f>0){let e=Array(f);for(let t=0;t<f;t++)e[t]=d[t].toString();t.mruColors=e}return Object.keys(t).length===0?null:t}_fromJSONIndexedColors(e){if(!e||e.length===0)return n.CommonUtils.EmptyArray;let t=e.length,r=Array(t);if(t>0)for(let n=0;n<t;n++){let t=e[n];try{r[n]=this.parseColor(t)}catch{console.warn(`Unable to parse color: `+t)}}return r}_fromJSONInternal(e){this._customIndexedColors=this._fromJSONIndexedColors(e.indexedColors);let t=e.named,n=t?t.length:0;for(let e=0;e<n;e++)this._setCustomCellStyleInternal(t[e]);let r=this.getNormal().getFont().getSize();r>0&&r!==this._defaultFontSize&&this.setDefaultFontSize(r);let i=e.direct,a=i?i.length:0;for(let e=0;e<a;e++)i[e]=this.normalize(i[e])??{};let o=Cp;if(this._defaultTableStyle=null,e.tables){e.tables.defaultTableStyle&&(o=e.tables.defaultTableStyle);let t=e.tables.styles,n=t?Object.keys(t):null,r=n?n.length:0;for(let e=0;e<r;e++){let r=n[e],i=t[r];this._setCustomTableStyleInternal(r,i)}}this._defaultTableStyle=this.getTableStyle(o),n>0&&this._namedStyles._announceChange(),e.tables&&this._tableStyles._announceChange();let s=e.mruColors,c=s?s.length:0,l=Array(c);if(c>0)for(let e=0;e<c;e++){let t=s[e];try{l[e]=this.parseColor(t)}catch{console.warn(`Unable to parse color: `+t)}}this._mruColors=l}get isIStyleCollection(){return!0}},og=class e{constructor(e,t,r,i=null,a=null,o=null){this._private={wrapped:!0,insets:n.TypesUtils.EmptyRect,orientation:c.Orientation.Horizontal,autoFit:c.Autofit.None,fontScale:1,vertical:!1,columnCount:1,columnSpacing:0,verticalAlignment:c.VerticalAlignment.Center,horizontalCentered:!1,lineReduction:0,isSpaceFirstLastPara:!1,presetTextWarp:null,paragraphs:n.CommonUtils.EmptyArray},this._bounds=null,this._textBounds=null,this._lines=null,this._lastLayoutSize=void 0,this._lastLayout=void 0,this._private=Object.assign(this._private,e||{}),this._defaultFont=t,this._alignment=r,this._lines=i,this._bounds=Object.freeze(a),this._textBounds=Object.freeze(o)}visitParas(e){e?.visitTextFrame?.(this);let t=this.paragraphs,n=t.length;for(let r=0;r<n;r++){let i=t[r];e?.visitTextParagraph?.(i,r,n);let a=i.runs,o=a.length;for(let t=0;t<o;t++)e?.visitTextRun?.(a[t],t,o)}}visitLines(e){e?.visitTextFrame?.(this);let t=this.lines,n=t.length;for(let r=0;r<n;r++){let i=t[r];e?.visitTextLine?.(i,r,n);let a=i.runs,o=a.length;for(let t=0;t<o;t++)e?.visitTextRun?.(a[t],t,o)}}layout(e=null){return this._lastLayout&&this._lastLayoutSize?.width===e?.width&&this._lastLayoutSize?.height===e?.height||(this._lastLayout=Tg(this,this._defaultFont,this._alignment,e),this._lastLayoutSize=e),this._lastLayout}clone(t){let n=t?.visitTextFrame?.(this),r=Object.assign({},this._private,n||{});return delete r.bounds,new e(r,this._defaultFont,this._alignment)}equals(e){return n.CommonUtils.deepEqual(this._private,e._private)}getText(){let e=this.paragraphs.map(e=>e.runs.map(e=>e.text).join(``)),t=0,n=e.length;for(;t<n&&e[t].trim()===``;)t++;for(;n>t&&e[n-1].trim()===``;)n--;return e.slice(t,n).join(`
|
|
3
|
-
`)}createTextFrame(e,t){return Dg(e,this._defaultFont,this._alignment,t??this._private.wrapped)}get bounds(){if(this._bounds===null)throw Error(sg);return this._bounds}get textBounds(){if(this._textBounds===null)throw Error(sg);return this._textBounds}get lines(){return this._lines}get wrapped(){return this._private.wrapped}get insets(){return this._private.insets}get orientation(){return this._private.orientation}get autoFit(){return this._private.autoFit}get fontScale(){return this._private.fontScale}get vertical(){return this._private.vertical}get columnCount(){return this._private.columnCount}get columnSpacing(){return this._private.columnSpacing}get verticalAlignment(){return this._private.verticalAlignment}get horizontalCentered(){return this._private.horizontalCentered}get lineReduction(){return this._private.lineReduction}get isSpaceFirstLastPara(){return this._private.isSpaceFirstLastPara}get presetTextWarp(){return this._private.presetTextWarp??null}get paragraphs(){return this._private.paragraphs}get isITextFrame(){return!0}},sg=`bounds can not be used until layout`,cg=class{static{this.NL=`
|
|
4
|
-
`}static{this.DefaultLineSpacing=100}static{this.DefaultTabWidth=72}},lg=class e{constructor(e){this._private={defaultFontSize:11,defaultTabSize:cg.DefaultTabWidth,tabOverrides:n.CommonUtils.EmptyArray,spacingBefore:0,spacingAfter:0,lineSpacing:cg.DefaultLineSpacing,align:c.HorizontalAlignment.Left,endParagraphSize:0,indentLevel:0,leadingIndent:0,hangingIndent:0,rightMargin:0,bullet:null},this._private=Object.assign(this._private,e||{})}clone(t){let n=t?.visitTextParagraph?.(this,0,1),r=Object.assign({},this._private,n||{});return delete r.bounds,new e(r)}equals(e){return n.CommonUtils.deepEqual(this._private,e._private)}get bounds(){return this._bounds}get defaultFontSize(){return this._private.defaultFontSize}get defaultTabSize(){return this._private.defaultTabSize}get tabOverrides(){return this._private.tabOverrides}get spacingBefore(){return this._private.spacingBefore}get spacingAfter(){return this._private.spacingAfter}get lineSpacing(){return this._private.lineSpacing}get align(){return this._private.align}get endParagraphSize(){return this._private.endParagraphSize}get indentLevel(){return this._private.indentLevel}get leadingIndent(){return this._private.leadingIndent}get hangingIndent(){return this._private.hangingIndent}get rightMargin(){return this._private.rightMargin}get bullet(){return this._private.bullet??null}get runs(){return this._private.runs}get isITextParagraph(){return!0}},ug=class e{constructor(e,t=null){this._private={text:null,fontName:`Arial`,bold:!1,italic:!1,superSub:!1,fontSize:11,letterSpacing:0,kerningMin:10,smallCaps:o.SmallCaps.None,offset:0,strikeStyle:o.StrikeStyle.None},this._private={...this._private,...e},this._bounds=t}clone(t){let n=t?.visitTextRun?.(this,0,1),r=Object.assign({},this._private,n||{});return delete r.bounds,new e(r)}equals(e){return n.CommonUtils.deepEqual(this._private,e._private)}get bounds(){return this._bounds}get text(){return this._private.text}get fontName(){return this._private.fontName}get bold(){return this._private.bold}get italic(){return this._private.italic}get fontSize(){return this._private.fontSize}get superSub(){return this._private.superSub}get letterSpacing(){return this._private.letterSpacing}get kerningMin(){return this._private.kerningMin}get smallCaps(){return this._private.smallCaps}get offset(){return this._private.offset}get strikeStyle(){return this._private.strikeStyle}get isITextRun(){return!0}},dg=class{constructor(e,t,n){this._private={},this._private={bounds:e,baseline:t,runs:n}}get bounds(){return this._private.bounds}get baseline(){return this._private.baseline}get runs(){return this._private.runs}get bullet(){return null}get isITextLine(){return!0}},fg=e.t((e,t)=>{function n(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function r(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new n,this.dtree=new n}var i=new n,a=new n,o=new Uint8Array(30),s=new Uint16Array(30),c=new Uint8Array(30),l=new Uint16Array(30),u=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),d=new n,f=new Uint8Array(320);function p(e,t,n,r){var i,a;for(i=0;i<n;++i)e[i]=0;for(i=0;i<30-n;++i)e[i+n]=i/n|0;for(a=r,i=0;i<30;++i)t[i]=a,a+=1<<e[i]}var m=new Uint16Array(16);function h(e,t,n,r){var i,a;for(i=0;i<16;++i)e.table[i]=0;for(i=0;i<r;++i)e.table[t[n+i]]++;for(e.table[0]=0,a=0,i=0;i<16;++i)m[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[m[t[n+i]]++]=i)}function g(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=1&e.tag;return e.tag>>>=1,t}function _(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var r=e.tag&65535>>>16-t;return e.tag>>>=t,e.bitcount-=t,r+n}function v(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var n=0,r=0,i=0,a=e.tag;do r=2*r+(1&a),a>>>=1,++i,n+=t.table[i],r-=t.table[i];while(r>=0);return e.tag=a,e.bitcount-=i,t.trans[n+r]}function y(e,t,n){var r,i,a,o,s,c;for(r=_(e,5,257),i=_(e,5,1),a=_(e,4,4),o=0;o<19;++o)f[o]=0;for(o=0;o<a;++o){var l=_(e,3,0);f[u[o]]=l}for(h(d,f,0,19),s=0;s<r+i;){var p=v(e,d);switch(p){case 16:var m=f[s-1];for(c=_(e,2,3);c;--c)f[s++]=m;break;case 17:for(c=_(e,3,3);c;--c)f[s++]=0;break;case 18:for(c=_(e,7,11);c;--c)f[s++]=0;break;default:f[s++]=p}}h(t,f,0,r),h(n,f,r,i)}function b(e,t,n){for(;;){var r,i,a,u,d=v(e,t);if(d===256)return 0;if(d<256)e.dest[e.destLen++]=d;else for(r=_(e,o[d-=257],s[d]),i=v(e,n),u=a=e.destLen-_(e,c[i],l[i]);u<a+r;++u)e.dest[e.destLen++]=e.dest[u]}}function x(e){for(var t,n;e.bitcount>8;)e.sourceIndex--,e.bitcount-=8;if((t=256*(t=e.source[e.sourceIndex+1])+e.source[e.sourceIndex])!==(65535&~(256*e.source[e.sourceIndex+3]+e.source[e.sourceIndex+2])))return-3;for(e.sourceIndex+=4,n=t;n;--n)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,0}(function(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n})(i,a),p(o,s,4,3),p(c,l,2,1),o[28]=0,s[28]=258,t.exports=function(e,t){var n,o,s=new r(e,t);do{switch(n=g(s),_(s,2,0)){case 0:o=x(s);break;case 1:o=b(s,i,a);break;case 2:y(s,s.ltree,s.dtree),o=b(s,s.ltree,s.dtree);break;default:o=-3}if(o!==0)throw Error(`Data error`)}while(!n);return s.destLen<s.dest.length?typeof s.dest.slice==`function`?s.dest.slice(0,s.destLen):s.dest.subarray(0,s.destLen):s.dest}}),pg=e.t((e,t)=>{var n=new Uint8Array(new Uint32Array([305419896]).buffer)[0]===18,r=(e,t,n)=>{let r=e[t];e[t]=e[n],e[n]=r};t.exports={swap32LE:e=>{n&&(e=>{let t=e.length;for(let n=0;n<t;n+=4)r(e,n,n+3),r(e,n+1,n+2)})(e)}}}),mg=e.t((e,t)=>{var n=fg(),{swap32LE:r}=pg();t.exports=class{constructor(e){let t=typeof e.readUInt32BE==`function`&&typeof e.slice==`function`;if(t||e instanceof Uint8Array){let i;if(t)this.highStart=e.readUInt32LE(0),this.errorValue=e.readUInt32LE(4),i=e.readUInt32LE(8),e=e.slice(12);else{let t=new DataView(e.buffer);this.highStart=t.getUint32(0,!0),this.errorValue=t.getUint32(4,!0),i=t.getUint32(8,!0),e=e.subarray(12)}e=n(e,new Uint8Array(i)),e=n(e,new Uint8Array(i)),r(e),this.data=new Uint32Array(e.buffer)}else({data:this.data,highStart:this.highStart,errorValue:this.errorValue}=e)}get(e){let t;return e<0||e>1114111?this.errorValue:e<55296||e>56319&&e<=65535?(t=(this.data[e>>5]<<2)+(31&e),this.data[t]):e<=65535?(t=(this.data[2048+(e-55296>>5)]<<2)+(31&e),this.data[t]):e<this.highStart?(t=this.data[2080+(e>>11)],t=this.data[t+(e>>5&63)],t=(t<<2)+(31&e),this.data[t]):this.data[this.data.length-4]}}}),hg=e.t(e=>{(function(e){"use strict";var t=typeof Uint8Array<`u`?Uint8Array:Array,n=43,r=47,i=48,a=97,o=65,s=45,c=95;function l(e){var t=e.charCodeAt(0);return t===n||t===s?62:t===r||t===c?63:t<i?-1:t<i+10?t-i+26+26:t<o+26?t-o:t<a+26?t-a+26:void 0}e.toByteArray=function(e){var n,r,i,a,o,s;if(e.length%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var c=e.length;o=e.charAt(c-2)===`=`?2:+(e.charAt(c-1)===`=`),s=new t(3*e.length/4-o),i=o>0?e.length-4:e.length;var u=0;function d(e){s[u++]=e}for(n=0,r=0;n<i;n+=4,r+=3)d((16711680&(a=l(e.charAt(n))<<18|l(e.charAt(n+1))<<12|l(e.charAt(n+2))<<6|l(e.charAt(n+3))))>>16),d((65280&a)>>8),d(255&a);return o===2?d(255&(a=l(e.charAt(n))<<2|l(e.charAt(n+1))>>4)):o===1&&(d((a=l(e.charAt(n))<<10|l(e.charAt(n+1))<<4|l(e.charAt(n+2))>>2)>>8&255),d(255&a)),s},e.fromByteArray=function(e){var t,n,r,i=e.length%3,a=``;function o(e){return`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.charAt(e)}function s(e){return o(e>>18&63)+o(e>>12&63)+o(e>>6&63)+o(63&e)}for(t=0,r=e.length-i;t<r;t+=3)a+=s(n=(e[t]<<16)+(e[t+1]<<8)+e[t+2]);switch(i){case 1:a+=o((n=e[e.length-1])>>2),a+=o(n<<4&63),a+=`==`;break;case 2:a+=o((n=(e[e.length-2]<<8)+e[e.length-1])>>10),a+=o(n>>4&63),a+=o(n<<2&63),a+=`=`}return a}})(e===void 0?e.base64js={}:e)}),gg=e.r(mg(),1),_g=e.r(hg(),1),vg={},yg=[[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4],[0,4,4,1,1,4,4,4,4,1,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,4,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[4,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,0,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,1,1,1,1,0,0,4,2,4,1,1,1,1,1,0,1,1,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,1,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,4,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,1,1,1,1,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,1,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,1,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0]],bg=new gg.default(_g.default.toByteArray(`AAgOAAAAAAAQ4QAAAQ0P8vDtnQuMXUUZx+eyu7d7797d9m5bHoWltKVUlsjLWE0VJNigQoMVqkStEoNQQUl5GIo1KKmogEgqkKbBRki72lYabZMGKoGAjQRtJJDaCCIRiiigREBQS3z+xzOTnZ3O+3HOhd5NfpkzZx7fN9988zivu2M9hGwB28F94DnwEngd/Asc1EtIs9c/bIPDwCxwLDgezHcodyo4w5C+CCwBS8FnwSXgCnA1uFbI93XwbXAbWAfWgx+CzWAb+An4KfgFeAzsYWWfYuFz4CXwGvgb+Dfo6yNkEEwGh4CZYB44FpwI3g1OY+kfBItZOo2fB84Hy8DF4HJwNbiWpV8PVoO1LH4n2NRXyN+KcAd4kNVP9XsY4aPgcfAbsBfs6SniL4K/sPjfEf6HlanXCRkCw2BGvUh/keWfXS/CY+pFXs7x9XHmM94LTmWIeU2cgbxnS/k/B3kf86jDhU8L9V2E40vAFWAlWFUfb++NOL4F3C7JX4/4GiE+hvgWsF0oS7mXldspnN+F493gyXrh9xTav0cg3EvzgVfBG6wsmVSEkxBOBgdPGpd7JI6PnqRvJ68/xlbHof53gPeA94OzwLngk+ACsAwsByvASrAK3MB0Ws3CtQjvBJvAVrADPMDSHkb4CNijaccTwvnf4fiPEs8Lxy+D18A/QU8/xjgYBjPAbDAKTgYLwOngTHAO+EQ/8wuEF4EvsPiVCFf2+9tsFStzA8LVHuXXBsi6QyqzUYiPMR/7Mc7dAx7oL8bzw/3u/Bw8Bp4Az4AXwCtgHzsmDXP5fiF9iiVvly5d0sHngar16NKlS5cuXbp06fLmYlqHXrcd3ph4P0THUY3iXh49novju4S0tzfs5d+JPKewfAsRntZb3K9ZhOMlrO6lCC8An28U9+OuovcPcPxlVu5rCL/VmHh/iHIrzn3fIPu7SN8Axmg+8AOwEWwCm7tp3bRuWjetm5Y8bSu4B9zbKO6ZVsnORrVU3f4uXTqZ2H3sLoyx3eDXjfDndE9qyj6L838CfwVvgFpzYnof4oNgOhgBc8Fos9DrZIQLmtXPP1MmF6wGj4H+KXoWguvADkXaPil+YpuQy8Am8Ey7ODdtmJDF4HowBp4De6HDTNjhfHAHeBr0DBBy0kDxfPbcgSIusgrcWhtnJ8vL+TPix7UIOQtcBq4C28Cr4KRBnANbwSuDE+s50JgyNNFuXbp06XIgsXjIvPafjvXozKY+fVFz/z0LT1uCtKVSWbrOLWPnztG8e0Xfy7ol8XtZJi7WtG+5od2UFXQ/A12vUeS7jp27yVKHjdsU9lXB869TyNvAzt0lpP2oWbwLdjiO78bx/Sz+EMJHwK9Y/LcIfw+eZ3F67/Hl5vh9xX80J+rwX8SvRDhpgL17iPAQMHNArfPrqHPewLheI+AERV6efwV418B4nOZ/H+IfYHV8GOF5LJ3eAz0fx8sM9S0fUNud39O9CulfGZhY5huI3wzWgNvBelbHZoTbNPVpfYjKQpkHwUNgl0LWblbnk0LbbDxr0OMFpL3iqWdu9nWYPlVAWkXY39LnGdCkDbeqv1YNbfcMQ3t9oe8lzm6NH9N1ZB6Ln4BwfkJZJk7RyFnYKt6b/JDQXx9p5X+eFdqOjzM9P9MB/lUlFzr20aXIdzlY4dmn9F3YqtvoO76/2hp/D/xA5Zue88nNyL8GbFbs075X0tyUig3Qd2MCnf//HjnzpbsR3g9+1kHzzVjdnE71/qVBX9rGPUh/ysNWe1neFzvIDi5zAufV1sT0N0poR22wkFUfTOPfA4N2mbZ5fSrqOHSw+IbkSBbOGSzSRgf91/GTUWYBOB2cIZQ/G8cfBZ8CFwrnL8XxF8FKcA24jqXdiPA7Qr61OF7H4mMItwzuv2/YLth1ISt3Hzu3k4W7EH5JqPdRHD/O4k+z8A8IX5Lq3y7Z4nXE9xn6kX6vQ4bKfy+ok+hH+xf3hq9dnTTHhjKd2GmDuWA242iHMq4cC7A8kJ7i8o1+skSa7Jieo38HCWnoNjKFhdSFBxzpZ7QE6lI8N4S14aASZcryaV/WWHw66f6NHuCoxuQxmvM56GX9QMd8Q4D65ywGP+ZzRJuM+zQvx/MOS2VFeqQ4IXnH26zM9Xe6/E6D+4foAzzuajPZp8Qyw5ayZVDWuH0z0BtYRkeIDqH9KO9VbH1btd/lhNqCzvl8zeLnG0S/hnU6baHfpiuO6yy0rd+DHURo/zYF5H26j03rQsip2ndzz82u1z9N4VjWKWeb68Tedpt95HRVXp7H1R6p+/Wt4FPy/PpWwscOLRJ+PVWF/+W0iVyGzs18TIvXkOJ1Wxm66vSXz+vylenrZcj1ub439W+K8RNCGTJi2p/TJ1K23VaXr35tRpnzmjxequgfcfyk6B/TGBVlyedsNgpdd/h+W1U3P99QyFPNo1X3TwpM/WLTIWYfoBqXrv6iskHZ/RFr79R6hIyHBrH3f1nrUVnjP8SnZZ+rYtzr9Exld5MNbPNErusAPg+77u/eDOPftU9yj39TH7rezxd1LvsZQJlzkWlOirG/79zjMj/mtHUKu7vKy+3/LnXr9okyKedjX5/0He9iP/j63LwOQdarEVlfy8OO/Lqw023j6xcqmwxLiOd6heM2i9cV9LJy8jMJ23yQ+rpbfu7EQ/pXE8KYvUSqvVnb4XzZa6LrHMXHR+zcLvqWbm/Bn0/HzIs6fWPHoat8XfnDKmZGxRxeMbn2UqZ5Q94nmcZRbqqUXbZ8+lcjE+cPX11t814orvvAXNcG8vqj2vvk1MGn3anlj0bIT72v47bvE+Lc98T9b6r7AKn6j+8Duf7D0nnZx/j7Zjn0j9nbpSTndaLr9WNLivP+iN23xF7L+fqv6ZouFyb78jxVXvv5jJ9YUs9/sddO8h7KNg5jrhfaJGztT6G7KF+1d6yCmD5Kdb2fan60rSc552fZr3zeQ9DpnPp+Si5cx5Ktv2QfSzF/mMbWdOm46rFI4XstnU9xeqX4NKb7TKEdcr6pZOK3ID1k/LvFHkVczEuZLEDr499YqvqBym1aEHWgcvoYOtv0M91qQl5TfpO/in6rWx8OVpT1Wedkv3f5xom3T/xeR/6Gx6V86PWAOB4bBpqWdN+yTcVxjIyGRz/FrDGu6w/3d7kPm8StX8RyPu+uuvpNju/vTLJV37GpvoM0oZPnW87VLnL/5pDno1NoW1R6yedU6TyUv3u19a3KFnIbTLYz+ZCLP4T0tU1uivFgso0pnsJ/UtXvarNY28Xq5cvkBDrQP/E5ZaiuQwwfmTlsOiQRU1fMuqrDd/3ISSuwjOwXOfTyGUMpZIXq4GpLn3pUcdfzch2x7XO1u2uZHOPb1G6b3Xg9PH1IIWeEpJlPQtqos2EKW8b0u8rnuP1UeVLoXJb9be0uG9nnbchjU+XTszT5VeNBThPHnc5OKj1U9aj0GTHIVaGy1YhEWT4ixns00DT+XEzWn/7VAsIc63Cov3OdyhwjrnaqQqZvWKXdypRdlq+k8msZ031U+Rm4fA+3TtyeR9hwfW9G9yxDN0fZMN33F+9TE6md4hwoxumfaUzI9fN3PFT3xVV2msrQ3UsnChm6Nulk8TndpS28D3zX9tTIPsF/z7Am5OkTjm1tI1JZW74+4VgsZ0N3L1yXV3WeP5uR7TGHHdvC3JQlxybfpd22tDlk/2eofRK8TzrN/qnar/K/OUTth6I/+jAnEptNbPvFHP2gs40N3+dfMWtwqvVct7/wfd8gtQ7imifial9ZJ9/3IHLYU6eDj3+4PhsNhX+vwvcWLnu6kGfEMe8DuciPfUfGZB8X/7HJy/Gefe5n+VRGFd/wyP2ta7/LO4yh/sbLV/k9lev6kfO9Dt/5U67b1/6u/epqB1U9Me23jfHY9sscAg4tkbLl+e4/U36rJ9ddxfd6sg5vq5ice42Wpk/pb9FOJ36/W9tpv4kbC79nUbZceX8Zu6/qJ+P3WvhvA8v3reh7Jbn2d6rrNC7XNZTLma4Ba0JI9efX2uLzF5scG/w9UNU1ZxW+ymUfzELeTllXlQ1rUuhzjS5fp9c964iFBOqeSz63bU065nZKdU+mDEz3qHIjjifquw0pnb/raRtvrnsYcb46ihT3taoYz6brdNW9l6rWRnE/navdPn1XlR1km7hcz1WlH/elKuSOSvLLuE8U6m8uzwRdfcGl73VyTHuyMvzJ1Sa2cWDTP/Z63Kc94n2B1PYr24dz1JlyHLlcP+S4B6vD1c9EW4q2LWstCvUjeVy63k/LMYdUNd5D1xQfvVTzX1VjkMsUv88N8VH5fReVn/Fjn++/h6X6Q8a6b1/q3g/i/ewi0/Scs8zxXeV6mWIOUPlPzBgdFerW+bZrm2P18dnjuK6HunEp+rHvPMXbr+sHVb/lnL+pTP57jPw9Cvk3PW178JD9qChfzuvTf7Htl38L1QUf/VKu9SFjwWbTWPvFEvu7Uq76y7+31g6QlYPc669pbsm9Xur2LWI9Pu8ypfDXqm3A2z8s1FWGn4ntL9NfQu2oSlftX9uetvTtv7J8Ql4zxfXGZ3zk8PeQ9w59x2uMfqI8/q5eKh/l9cb2rwsu9rSNl06ZP2Pmxtz+rNMx93yno0n2/82rVH7rQ+y9P15H6FyRun9ViH81ATmffI7nJ5r8uXXW6enbP6b/B8/l5OifVHYLnb9S39s2zcc+Ph+rh8+eQgVPS72elzGWY/tUtbbabBpDiI7yN1q6/4th2y+ErAc5+9BVvu/7KamJbWNZeuqI/R4tRf+YyD1HmOZM1bMV3/14Sn10c0Xu+Sj1nOXb5jL73ncdy02uvlXZNde65dOHYl7Vs4KYuS6FzWLn2zJlpZqPXPVPOa5yzKOyn1VhT9lmMfdbfH7D11Wf2PXN5h9y+dD287+qxgSnaYmnIrRtIb8pJe6/Uv9OVer6Whn0zfGO/BEloZI9ojmfAlUflClDd178bTmVHVTpZXOkAlk/lb42UujmI89HH5V+cl7XtowY6vTxLVWok6UrGzoGTHN+bB+6ri05687VNpvfuvRfaP2uMlNQth1D5JjGelm/8yn+9p3p/7qk9gnfeddXZmq/Sm333PJT659Kv1zjNbZ9uv2Oi//67CV8/N1nj1DmviyXDNVeJkaeaX8UsyesYg8cu2+NvdaPfb+lLDu5tvt/`)),xg=function(e){switch(e){case 33:case 39:case 40:case 42:return 12;case 35:return 5;default:return e}},Sg=function(e){switch(e){case 37:case 38:return 34;case 41:return 22;default:return e}},Cg=class{constructor(e,t=!1){this.position=e,this.required=t}};vg=class{nextCodePoint(){let e=this.string.charCodeAt(this.pos++),t=this.string.charCodeAt(this.pos);return 55296<=e&&e<=56319&&56320<=t&&t<=57343?(this.pos++,1024*(e-55296)+(t-56320)+65536):e}nextCharClass(){return xg(bg.get(this.nextCodePoint()))}getSimpleBreak(){switch(this.nextClass){case 41:return!1;case 34:case 37:case 38:return this.curClass=34,!1;case 36:return this.curClass=36,!1}return null}getPairTableBreak(e){let t=!1;switch(yg[this.curClass][this.nextClass]){case 0:t=!0;break;case 1:t=e===41;break;case 2:if(t=e===41,!t)return t=!1,t;break;case 3:if(e!==41)return t}return this.LB8a&&(t=!1),!this.LB21a||this.curClass!==16&&this.curClass!==17?this.LB21a=this.curClass===13:(t=!1,this.LB21a=!1),this.curClass===28?(this.LB30a++,this.LB30a==2&&this.nextClass===28&&(t=!0,this.LB30a=0)):this.LB30a=0,this.curClass=this.nextClass,t}nextBreak(){if(this.curClass==null){let e=this.nextCharClass();this.curClass=Sg(e),this.nextClass=e,this.LB8a=e===31,this.LB30a=0}for(;this.pos<this.string.length;){this.lastPos=this.pos;let e=this.nextClass;if(this.nextClass=this.nextCharClass(),this.curClass===34||this.curClass===36&&this.nextClass!==37)return this.curClass=Sg(xg(this.nextClass)),new Cg(this.lastPos,!0);let t=this.getSimpleBreak();if(t===null&&(t=this.getPairTableBreak(e)),this.LB8a=this.nextClass===31,t)return new Cg(this.lastPos)}return this.lastPos<this.string.length?(this.lastPos=this.string.length,new Cg(this.string.length)):null}constructor(e){this.string=e,this.pos=0,this.lastPos=0,this.curClass=null,this.nextClass=null,this.LB8a=!1,this.LB21a=!1,this.LB30a=0}};var wg=class{constructor(e){this._textMeasurer=e}_measureText(e){let t=this._fontSize,n=this._fontName,r=this._metricOptions;if(this._isSuperSub){let i=this._textMeasurer(e,.6*t,n,r);return{...this._textMeasurer(`M`,t,n,r),width:i.width}}return this._textMeasurer(e,t,n,r)}_breakWord(e,t,n){let r=0;for(;r<e.length;){let i={startPosition:this._charactersRead+r,text:``,x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},a=!1,o=0,s=this._maxWidth;do{a=!1;let t=e.substring(r,r+o+1),n=t.replace(/\s+$/,``),c=this._measureText(n),l=c;t.length!==n.length&&(l=this._measureText(t)),(i.x+c.width<=s||t.length<=1)&&(i.text=t,i.width=c.width,i.widthWhitespace=l.width,i.height=Math.max(i.height,c.lineHeight),i.baseline=Math.max(i.baseline,c.baseline),a=!0,o++)}while(a&&r+o<e.length);if(a){let n=e.substring(r,e.length),i=n.replace(/\s+$/,``),a=this._measureText(i),o=a;n.length!==i.length&&(o=this._measureText(n)),t.startPosition=this._charactersRead+r,t.width=a.width,t.widthWhitespace=o.width,t.height=Math.max(t.height,a.lineHeight),t.baseline=Math.max(t.baseline,a.baseline),t.text=n}else if(!1===n?.(i))return!1;r+=o}}_breakWhiteSpace(e,t=null){for(;e&&this._charactersRead<e.length;){let n={startPosition:this._charactersRead,text:``,x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},r=!1,i=this._maxWidth,a=this._indent,o=this._breaker;do if(r=!1,n.startPosition===0&&n.text.length===0&&(n.x=a,this._lastBreak=o.nextBreak()),this._lastBreak){let a=e.substring(n.startPosition,this._lastBreak.position),s=a.replace(/\s+$/,``),c=this._measureText(s),l=c;a.length!==s.length&&(l=this._measureText(a)),n.x+c.width<=i?(n.text=a,n.width=c.width,n.widthWhitespace=l.width,n.height=Math.max(n.height,c.lineHeight),n.baseline=Math.max(n.baseline,c.baseline),r=!0,this._charactersRead=this._lastBreak.position):n.text.length===0&&!1!==this._breakWord(a,n,t)&&(r=!0,this._charactersRead=this._lastBreak.position),(r||a.indexOf(`
|
|
5
|
-
`)===-1)&&this._lastBreak.required&&(this._lastBreak=o.nextBreak(),r=!1)}while(r&&(this._lastBreak=o.nextBreak()));if(!1===t?.(n))return!1}}wrap(e,t=null){this._breaker=new vg(e),this._linesRead=[],this._charactersRead=0,this._maxXRead=0,this._maxXWhitespaceRead=0,this._maxYRead=0,this._fontName=t?.fontName??`Arial`,this._fontSize=t?.fontSize??12,this._metricOptions={isBold:t?.bold??!1,isItalic:t?.italic??!1,letterSpacing:t?.letterSpacing??0},this._isSuperSub=t?.superSub??!1,this._indent=t?.indent??0,this._maxWidth=t?.maxWidth??2**53-1,this._maxWidth<=0&&(this._maxWidth=2**53-1),this._maxHeight=t?.maxHeight??2**53-1,this._maxHeight<=0&&(this._maxHeight=2**53-1);let n=e=>{if(this._linesRead.length>0){let t=this._linesRead[this._linesRead.length-1];e.y=t.y+t.height}if(e.y+e.height>this._maxHeight)return!1;this._maxXRead=Math.max(this._maxXRead,e.x+e.width),this._maxXWhitespaceRead=Math.max(this._maxXWhitespaceRead,e.x+e.widthWhitespace),this._maxYRead=Math.max(this._maxYRead,e.y+e.height),this._linesRead.push(e)};if(e===``){let t=this._measureText(e);n({startPosition:0,text:``,x:0,y:0,width:0,widthWhitespace:0,height:t.lineHeight,baseline:t.baseline})}else if(this._breakWhiteSpace(e,n),new vg(e.charAt(e.length-1).repeat(2)).nextBreak().required){let t=this._measureText(e);n({startPosition:e.length,text:``,x:0,y:0,width:0,widthWhitespace:0,height:t.lineHeight,baseline:t.baseline})}let r={bounds:{x:0,y:0,width:this._maxXRead,widthWhitespace:this._maxXWhitespaceRead,height:this._maxYRead},lines:this._linesRead};return this._breaker=null,this._linesRead=[],r}};function Tg(e,t,r,i=null,a=B.getSharedMeasurer()){let o=``,s=null,c=null,l=e.paragraphs,u=l.length;for(let e=0;e<u;e++){let t=l[e].runs,n=t.length;for(let e=0;e<n;e++){let n=t[e];o+=n.text,e===0&&(s=n)}e===0&&(c=l[e])}let d=e.insets??n.TypesUtils.EmptyRect,f=new wg(a),p=i?.width?i.width-d.right-d.left:i?.width,m=i?.height?i.height-d.bottom-d.top:void 0,h=f.wrap(o,{fontName:s.fontName,fontSize:s.fontSize*B.getDeviceScale(),bold:s.bold,italic:s.italic,superSub:s.superSub,letterSpacing:s.letterSpacing,maxWidth:e.wrapped&&p?p:void 0,maxHeight:m}),g=[],_=h.lines,v=_.length,y=Array(v);for(let e=0;e<v;e++){let t=_[e],n={x:t.x,y:t.y,width:t.width,height:t.height},r=new ug({text:t.text,fontName:s.fontName,fontSize:s.fontSize,bold:s.bold,italic:s.italic,superSub:s.superSub,letterSpacing:s.letterSpacing},n);g.push(r),y[e]=new dg(n,t.baseline,[r])}return new og({paragraphs:[new lg({runs:g,align:c.align})],wrapped:e.wrapped,verticalAlignment:e.verticalAlignment},t,r,y,{x:h.bounds.x,y:h.bounds.y,width:h.bounds.widthWhitespace,height:h.bounds.height},{x:h.bounds.x,y:h.bounds.y,width:h.bounds.width,height:h.bounds.height})}function Eg(e){let t=!1,n=!1;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i>=65&&i<=90?t=!0:i>=97&&i<=122&&(n=!0),t&&n)return 0}return t?1:n?-1:0}function Dg(e,t,n,r,i=!1){if(e==null)return null;let a=new ug({text:e,fontName:t.toCSS().fontFamily,fontSize:t.getSize(),bold:t.getWeight()>400,italic:t.getStyle()===B.Style.Italic,superSub:!i&&(t.getVerticalAlignment()===B.VerticalAlignment.Sub||t.getVerticalAlignment()===B.VerticalAlignment.Super),letterSpacing:t.getLetterSpacing()}),o=i?c.HorizontalAlignment.Left:n.getHorizontal(),s=n.getVertical(),l=new lg({runs:[a],align:o}),u=[];return u.push(new dg(null,t.getSize(),[a])),new og({paragraphs:[l],wrapped:r&&(n.getOverflow()===c.Overflow.Wrap||o===c.HorizontalAlignment.Justify||o===c.HorizontalAlignment.Distributed||s===c.VerticalAlignment.Justify||s===c.VerticalAlignment.Distributed),verticalAlignment:s},t,n,u)}var Og={[K.BuiltInSheetPattern.Gray0625]:{path:`M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 4.5 2.5 L 4.5 3.5 M 4.5 6.5 L 4.5 7.5`,size:8},[K.BuiltInSheetPattern.LightGray]:{path:`M 0.5 0.5 L 0.5 1.5 M 0.5 2.5 L 0.5 3.5 M 2.5 -0.5 L 2.5 0.5 M 2.5 1.5 L 2.5 2.5 M 2.5 3.5 L 2.5 4.5`,size:4},[K.BuiltInSheetPattern.MediumGray]:{path:`M 0.5 0.5 L 0.5 1.5 M 1.5 1.5 L 1.5 2.5 M 1.5 -0.5 L 1.5 0.5 M -0.5 -0.5 L -0.5 0.5`,size:2},[K.BuiltInSheetPattern.DarkGray]:{path:`M 0 0 L 0 4 M 1 1 L 1 2 M 1 3 L 1 4 M 2 0 L 2 4 M 3 0.5 L 3 1.5 M 3 2.5 L 3 3.5 M 4 0 L 4 4`,size:4},[K.BuiltInSheetPattern.LightHorizontal]:{path:`M 0 2 L 4 2`,size:4},[K.BuiltInSheetPattern.DarkHorizontal]:{path:`M 0 2 L 4 2 M 0 3 L 4 3`,size:4},[K.BuiltInSheetPattern.LightVertical]:{path:`M 2 0 L 2 4`,size:4},[K.BuiltInSheetPattern.DarkVertical]:{path:`M 2 0 L 2 4 M 3 0 L 3 4`,size:4},[K.BuiltInSheetPattern.LightUp]:{path:`M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5`,size:4},[K.BuiltInSheetPattern.DarkUp]:{path:`M 0.5 -0.5 L 0.5 1.5 M 0.5 3.5 L 0.5 4.5 M 1.5 2.5 L 1.5 4.5 M 2.5 1.5 L 2.5 3.5 M 3.5 0.5 L 3.5 2.5 M 1.5 -0.5 L 1.5 0.5`,size:4},[K.BuiltInSheetPattern.LightDown]:{path:`M 0.5 0 L 0.5 1 M 1.5 1 L 1.5 2 M 2.5 2 L 2.5 3 M 3.5 3 L 3.5 4`,size:4},[K.BuiltInSheetPattern.DarkDown]:{path:`M 0.5 -0.5 L 0.5 2 M 1.5 1 L 1.5 3 M 2.5 2 L 2.5 4 M 3.5 3 L 3.5 5 M 3.5 -0.5 L 3.5 1.0`,size:4},[K.BuiltInSheetPattern.LightGrid]:{path:`M 1.5 -0.5 L 1.5 4.5 M -0.5 1.5 L 4.5 1.5`,size:4},[K.BuiltInSheetPattern.DarkGrid]:{path:`M 0.5 -0.5 L 0.5 1.5 M 1.5 -0.5 L 1.5 1.5 M 2.5 1.5 L 2.5 3.5 M 3.5 1.5 L 3.5 3.5 M 0.5 3.5 L 0.5 4.5 M 1.5 3.5 L 1.5 4.5`,size:4},[K.BuiltInSheetPattern.LightTrellis]:{path:`M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5 M 1.5 1.5 L 1.5 2.5 M 3.5 3.5 L 3.5 4.5 M 3.5 -0.5 L 3.5 0.5`,size:4},[K.BuiltInSheetPattern.DarkTrellis]:{path:`M 0 0 L 4 0 M 0 1 L 2 1 M 0 2 L 4 2 M 2 3 L 4 3 M 0 4 L 4 4`,size:4},[K.BuiltInSheetPattern.Gray125]:{path:`M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 2.5 2.5 L 2.5 3.5 M 2.5 6.5 L 2.5 7.5 M 4.5 0.5 L 4.5 1.5 M 4.5 4.5 L 4.5 5.5 M 6.5 2.5 L 6.5 3.5 M 6.5 6.5 L 6.5 7.5`,size:8}},kg=Og[K.BuiltInSheetPattern.Gray125],Ag=(e,t,n)=>`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${t}' height='${t}' viewBox='0 0 ${t} ${t}' shape-rendering='crispEdges' %3E%3Cpath d='${e}' stroke='${n}' %3E%3C/path%3E%3C/svg%3E")`,jg=new class{_svgImage(e,t,n){let{path:r,size:i}=n;return{backgroundImage:Ag(r,i,e),backgroundRepeat:`repeat`,backgroundSize:`${i}px ${i}px`,backgroundPositionX:`0px`,backgroundPositionY:`0px`,backgroundPosition:``+-i,backgroundColor:t}}toCSS(e,t,n){return e&&e!==K.BuiltInSheetPattern.None?e===K.BuiltInSheetPattern.Solid?{background:t}:this._svgImage(t,n,Og[e]??kg):{background:`none`}}toCSSMask(e,t,n){if(!e||e===K.BuiltInSheetPattern.None||e===K.BuiltInSheetPattern.Solid)return null;let{path:r,size:i}=Og[e]??kg;return{base:{backgroundColor:n},marks:{backgroundColor:t,maskImage:Ag(r,i,`black`),maskRepeat:`repeat`,maskSize:`${i}px ${i}px`,maskPosition:`0px 0px`}}}};function Mg(e,t){if(e===void 0)return;if(e===null)return null;if(e.isIStyle)return e.getAuthoredProperties();let n;return n=typeof e==`function`?e(typeof t==`function`?t():t):e,n}var Ng=class{constructor(e){this._p=Object.freeze(Array.isArray(e)?e:[e??null])}value(e){let t=this._p;for(let n=t.length-1;n>=0;n--){let r=t[n];if(!r)continue;let i=r[e];if(i!==void 0)return i}}values(e){let t=this._p,n=t.length,r;for(let i=0;i<n;i++){let n=t[i];if(!n)continue;let a=n[e];a!==void 0&&(r===void 0&&(r=[]),r.push(a))}return r}getProperties(){let e=this._p;return e?e[e.length-1]:null}toJSON(){let e=this._p,t=e.length,r={};for(let i=0;i<t;i++){let t=e[i];r=n.CommonUtils.deepMerge(r,t)}return r}},Pg=class{constructor(e,t){this._o=e,this._c=e.styles,this._p=Object.freeze(t)}_setValue(e,t){let n={[e]:t};this._o.updater(n)}_value(e){let t=this._p;for(let n=t.length-1;n>=0;n--){let r=t[n];if(!r)continue;let i=r[e];if(i!==void 0)return i}}_values(e){let t=this._p,n=t.length,r;for(let i=0;i<n;i++){let n=t[i];if(!n)continue;let a=n[e];a!==void 0&&(r===void 0&&(r=[]),r.push(a))}return r}getProperties(){let e=this._p;return e?e[e.length-1]:null}toJSON(){return null}},Fg=e=>{switch(e){case`top`:return(0,n.messageKey)(`op.setTopBorderStyle`);case`right`:return(0,n.messageKey)(`op.setRightBorderStyle`);case`bottom`:return(0,n.messageKey)(`op.setBottomBorderStyle`);case`horizontal`:return(0,n.messageKey)(`op.setHorizontalBorderStyle`);case`vertical`:return(0,n.messageKey)(`op.setVerticalBorderStyle`);case`diagonalUp`:return(0,n.messageKey)(`op.setDiagonalUpBorderStyle`);case`diagonalDown`:return(0,n.messageKey)(`op.setDiagonalDownBorderStyle`);default:return(0,n.messageKey)(`op.setLeftBorderStyle`)}},Ig=e=>{switch(e){case`top`:return(0,n.messageKey)(`op.setTopBorderColor`);case`right`:return(0,n.messageKey)(`op.setRightBorderColor`);case`bottom`:return(0,n.messageKey)(`op.setBottomBorderColor`);case`horizontal`:return(0,n.messageKey)(`op.setHorizontalBorderColor`);case`vertical`:return(0,n.messageKey)(`op.setVerticalBorderColor`);case`diagonalUp`:return(0,n.messageKey)(`op.setDiagonalUpBorderColor`);case`diagonalDown`:return(0,n.messageKey)(`op.setDiagonalDownBorderColor`);default:return(0,n.messageKey)(`op.setLeftBorderColor`)}},Lg=class extends Pg{constructor(e,t,n){super(t,n),this._edge=e}getStyle(){return this._value(`style`)}setStyle(e,t){let n=this._edge,r=n.charAt(0).toUpperCase()+n.slice(1);return this._o.updater({borders:{[n]:{style:e}}},{description:Fg(n),...t}).getBorders()[`get`+r]()}getColor(){let e=this._value(`color`);return e?this._c.parseColor(e):null}setColor(e,t){let n=this._edge,r=n.charAt(0).toUpperCase()+n.slice(1);return this._o.updater({borders:{[n]:{color:e}}},{description:Ig(n),...t}).getBorders()[`get`+r]()}isNone(){return this.getStyle()===V.StrokeStyle.None}toCSS(){let e=jm(this);switch(this._edge){case V.Edge.Left:return{borderLeft:e};case V.Edge.Right:return{borderRight:e};case V.Edge.Top:return{borderTop:e};case V.Edge.Bottom:return{borderBottom:e};case V.Edge.DiagonalUp:case V.Edge.DiagonalDown:return{borderDiagonalUp:e}}}get[Symbol.toStringTag](){return`[CellBorderStroke]`}toString(){return`[CellBorderStroke]`}get isIStroke(){return!0}},Rg=class extends Pg{getLeft(){return this._left||=new Lg(V.Edge.Left,this._o,this._values(V.Edge.Left)),this._left}setLeft(e,t){return this._o.updater({borders:{left:e}},{description:(0,n.messageKey)(`op.setLeftBorder`),...t}).getBorders()}getRight(){return this._right||=new Lg(V.Edge.Right,this._o,this._values(V.Edge.Right)),this._right}setRight(e,t){return this._o.updater({borders:{right:e}},{description:(0,n.messageKey)(`op.setRightBorder`),...t}).getBorders()}getTop(){return this._top||=new Lg(V.Edge.Top,this._o,this._values(V.Edge.Top)),this._top}setTop(e,t){return this._o.updater({borders:{top:e}},{description:(0,n.messageKey)(`op.setTopBorder`),...t}).getBorders()}getBottom(){return this._bottom||=new Lg(V.Edge.Bottom,this._o,this._values(V.Edge.Bottom)),this._bottom}setBottom(e,t){return this._o.updater({borders:{bottom:e}},{description:(0,n.messageKey)(`op.setBottomBorder`),...t}).getBorders()}getHorizontal(){return this._inner(V.Edge.Horizontal)}getVertical(){return this._inner(V.Edge.Vertical)}_inner(e){let t=this._o.extent;if(!t)return null;let n=this._o.direct;if(!(n instanceof tg))return null;let r=n.getInnerBorder(t)?.[e];return r?new Lg(e,this._o,[r]):null}getDiagonalUp(){return this._diagUp||=new Lg(V.Edge.DiagonalUp,this._o,this._values(V.Edge.DiagonalUp)),this._diagUp}setDiagonalUp(e,t){return this._o.updater({borders:{diagonalUp:e}},{description:(0,n.messageKey)(`op.setDiagonalUpBorder`),...t}).getBorders()}getDiagonalDown(){return this._diagDown||=new Lg(V.Edge.DiagonalDown,this._o,this._values(V.Edge.DiagonalDown)),this._diagDown}setDiagonalDown(e,t){return this._o.updater({borders:{diagonalDown:e}},{description:(0,n.messageKey)(`op.setDiagonalDownBorder`),...t}).getBorders()}setVertical(e,t){return this._o.updater({borders:{vertical:e}},{description:(0,n.messageKey)(`op.setVerticalBorder`),...t}).getBorders()}setHorizontal(e,t){return this._o.updater({borders:{horizontal:e}},{description:(0,n.messageKey)(`op.setHorizontalBorder`),...t}).getBorders()}setOutline(e,t){return this._o.updater({borders:{top:e,bottom:e,left:e,right:e}},{description:(0,n.messageKey)(`op.setOutlineBorder`),...t}).getBorders()}_edgeStyleIsNone(e){let t=this._values(e);if(!t)return!0;for(let e=t.length-1;e>=0;e--){let n=t[e]?.style;if(n!==void 0)return n===V.StrokeStyle.None}return!0}isEmpty(){return this._isEmpty!==void 0||(this._isEmpty=this._edgeStyleIsNone(V.Edge.Top)&&this._edgeStyleIsNone(V.Edge.Bottom)&&this._edgeStyleIsNone(V.Edge.Left)&&this._edgeStyleIsNone(V.Edge.Right)&&this._edgeStyleIsNone(V.Edge.DiagonalUp)&&this._edgeStyleIsNone(V.Edge.DiagonalDown)),this._isEmpty}get[Symbol.toStringTag](){return`[CellBorder]`}toString(){return`[CellBorder]`}get isIBorders(){return!0}},zg=class extends Pg{getHorizontal(){return this._value(`horizontal`)}setHorizontal(e,t){return this._o.updater({alignment:{horizontal:e}},{description:(0,n.messageKey)(`op.setHorizontalAlignment`),...t}).getAlignment()}getVertical(){return this._value(`vertical`)}setVertical(e,t){return this._o.updater({alignment:{vertical:e}},{description:(0,n.messageKey)(`op.setVerticalAlignment`),...t}).getAlignment()}getIndent(){return this._value(`indent`)}setIndent(e,t){return this._o.updater({alignment:{indent:e}},{description:(0,n.messageKey)(`op.setIndent`),...t}).getAlignment()}getRelativeIndent(){return this._value(`relativeIndent`)}setRelativeIndent(e,t){return this._o.updater({alignment:{relativeIndent:e}},{description:(0,n.messageKey)(`op.setRelativeIndent`),...t}).getAlignment()}getOverflow(){return this._value(`overflow`)}setOverflow(e,t){return this._o.updater({alignment:{overflow:e}},{description:(0,n.messageKey)(`op.setOverflow`),...t}).getAlignment()}getRotation(){return this._value(`rotation`)}setRotation(e,t){return this._o.updater({alignment:{rotation:e}},{description:(0,n.messageKey)(`op.setRotation`),...t}).getAlignment()}getStacked(){return this._value(`stacked`)}setStacked(e,t){return this._o.updater({alignment:{stacked:e}},{description:(0,n.messageKey)(`op.setStacked`),...t}).getAlignment()}getJustifyLastLine(){return this._value(`justifyLastLine`)}setJustifyLastLine(e,t){return this._o.updater({alignment:{justifyLastLine:e}},{description:(0,n.messageKey)(`op.setJustifyLastLine`),...t}).getAlignment()}getReadingDirection(){return this._value(`readingDirection`)}setReadingDirection(e,t){return this._o.updater({alignment:{readingDirection:e}},{description:(0,n.messageKey)(`op.setReadingDirection`),...t}).getAlignment()}get[Symbol.toStringTag](){return`[CellAlignment]`}toString(){return`[CellAlignment]`}get isITextBoxAlignment(){return!0}},Bg=class extends Pg{isAlwaysUnlocked(){return this._value(`alwaysUnlocked`)}setAlwaysUnlocked(e,t){return this._o.updater({protection:{alwaysUnlocked:e}},{description:(0,n.messageKey)(`op.setAlwaysUnlocked`),...t}).getProtection()}isShowFormulas(){return this._value(`showFormulas`)}setShowFormulas(e,t){return this._o.updater({protection:{showFormulas:e}},{description:(0,n.messageKey)(`op.setShowFormulas`),...t}).getProtection()}get[Symbol.toStringTag](){return`[CellProtection]`}toString(){return`[CellProtection]`}get isICellProtection(){return!0}},Vg=class extends Pg{isEqualMeasure(e){return!!e&&this.getFamily()===e.getFamily()&&!!n.CommonUtils.isEqualArrays(this.getFallbacks(),e.getFallbacks())&&this.getSize()===e.getSize()&&this.getWeight()===e.getWeight()&&this.getStyle()===e.getStyle()&&this.getStrike()===e.getStrike()&&this.getScheme()===e.getScheme()&&this.getShadow()===e.getShadow()&&this.getOutline()===e.getOutline()&&this.getLetterSpacing()===e.getLetterSpacing()&&this.getVerticalAlignment()===e.getVerticalAlignment()}toCSS(e,t=1,r=!1){let i={fontFamily:Lp(this.getFamily(),this.getFallbacks()),letterSpacing:`${this.getLetterSpacing()}px`,fontWeight:this.getWeight(),fontStyle:this.getStyle(),textDecoration:jp(this.getUnderline(),this.getStrike()),color:this.getColor().toCSS(e),fontSize:`${n.CommonUtils.roundAccurately(this.getSize()*B.getDeviceScale()*t,2)}px`,textRendering:`geometricPrecision`};if(r){let r=this._c.getNormal().getFont().toCSS(e,t,!1),a=i.textDecoration,o=i.fontWeight;n.CommonUtils.removeEqualValues(i,r),a&&(i.textDecoration=a),o&&(i.fontWeight=o)}return i}isSuperSub(){let e=this.getVerticalAlignment();return e===B.VerticalAlignment.Sub||e===B.VerticalAlignment.Super}isSuperScript(){let e=this.getVerticalAlignment();return e===B.VerticalAlignment.Sub||e===B.VerticalAlignment.Super}getSuperSubScale(){return this.getFamily(),this.getSize(),this.getVerticalAlignment(),.6}getSuperSubShift(){return this.getFamily(),e=this.getSize(),(t=this.getVerticalAlignment())===B.VerticalAlignment.Super?-e/3:t===B.VerticalAlignment.Sub?e/5:0;var e,t}_schemeFamily(){let e=this._value(`scheme`);if(e!==B.Scheme.Major&&e!==B.Scheme.Minor)return;let t=this._c.getTheme().getFontScheme();return e===B.Scheme.Major?t.getMajorFont():t.getMinorFont()}getFamily(){return this._schemeFamily()??this._value(`family`)??this._c.getTheme().getFontScheme().getMinorFont()}setFamily(e,t){return this._o.updater({font:{family:e,scheme:e?B.Scheme.None:null}},{description:(0,n.messageKey)(`op.setFontFamily`),...t}).getFont()}getFallbacks(){let e=this._value(`fallbacks`)??this._c.getTheme().getFontScheme().getMinorFallbacks()??n.CommonUtils.EmptyArray,t=this.getFamily();t===`Aptos Narrow`&&(e=[`Calibri`,...e]);let r=this._schemeFamily()?this._value(`family`):void 0;return r&&r!==t&&!e.includes(r)&&(e=[r,...e]),e}setFallbacks(e,t){return this._o.updater({font:{fallbacks:e}},{description:(0,n.messageKey)(`op.setFontFallbacks`),...t}).getFont()}getSize(){return this._value(`size`)??this._c.getDefaultFontSize()??11}setSize(e,t){return this._o.updater({font:{size:e}},{description:(0,n.messageKey)(`op.setFontSize`),...t}).getFont()}getWeight(){return this._value(`weight`)}setWeight(e,t){return this._o.updater({font:{weight:e}},{description:(0,n.messageKey)(`op.setFontWeight`),...t}).getFont()}getBold(){return this.getWeight()>400}setBold(e,t){let r=e===null?null:e?700:400;return this.setWeight(r,{description:(0,n.messageKey)(`op.setFontBold`),...t})}getStyle(){return this._value(`style`)}setStyle(e,t){return this._o.updater({font:{style:e}},{description:(0,n.messageKey)(`op.setFontStyle`),...t}).getFont()}getItalic(){return this.getStyle()===B.Style.Italic}setItalic(e,t){let r=e===null?null:e?B.Style.Italic:B.Style.Normal;return this.setStyle(r,{description:(0,n.messageKey)(`op.setFontItalic`),...t})}getColor(){let e=this._value(`color`);return this._c.parseColor(e??G.Scheme.Bg1)}setColor(e,t){return this._o.updater({font:{color:e}},{description:(0,n.messageKey)(`op.setFontColor`),...t}).getFont()}getLetterSpacing(){return this._value(`letterSpacing`)??this.getSize()/-25}setLetterSpacing(e,t){return this._o.updater({font:{letterSpacing:e}},{description:(0,n.messageKey)(`op.setFontLetterSpacing`),...t}).getFont()}getUnderline(){return this._value(`underline`)}setUnderline(e,t){return this._o.updater({font:{underline:e}},{description:(0,n.messageKey)(`op.setFontUnderline`),...t}).getFont()}getStrike(){return this._value(`strike`)}setStrike(e,t){return this._o.updater({font:{strike:e}},{description:(0,n.messageKey)(`op.setFontStrike`),...t}).getFont()}getScheme(){return this._value(`scheme`)}setScheme(e,t){let r=e===B.Scheme.Major||e===B.Scheme.Minor?{scheme:e,family:null}:{scheme:e};return this._o.updater({font:r},{description:(0,n.messageKey)(`op.setFontScheme`),...t}).getFont()}getVerticalAlignment(){return this._value(`verticalAlign`)}setVerticalAlignment(e,t){return this._o.updater({font:{verticalAlign:e}},{description:(0,n.messageKey)(`op.setFontVerticalAlignment`),...t}).getFont()}getShadow(){return this._value(`shadow`)}setShadow(e,t){return this._o.updater({font:{shadow:e}},{description:(0,n.messageKey)(`op.setFontShadow`),...t}).getFont()}getOutline(){return this._value(`outline`)}setOutline(e,t){return this._o.updater({font:{outline:e}},{description:(0,n.messageKey)(`op.setFontOutline`),...t}).getFont()}getExtend(){return this._value(`extend`)}setExtend(e,t){return this._o.updater({font:{extend:e}},{description:(0,n.messageKey)(`op.setFontExtend`),...t}).getFont()}getCharset(){return this._value(`charset`)??null}setCharset(e,t){return this._o.updater({font:{charset:e}},{description:(0,n.messageKey)(`op.setFontCharset`),...t}).getFont()}get[Symbol.toStringTag](){return`[StyledFont]`}toString(){return`[StyledFont]`}get isIStyledFont(){return!0}},Hg=Object.freeze({background:`none`}),Ug=class extends Pg{getType(){return K.Type.None}getColor(){return null}setColor(e,t){return e===null?this:this._o.updater({fill:{color:e}},{description:(0,n.messageKey)(`op.setFillColor`),...t}).getFill()}toCSS(e){return Hg}hasVisibleStyling(){return!1}isEqual(e){return!!e&&e.getType()===K.Type.None}toJSON(){return{type:K.Type.None}}get[Symbol.toStringTag](){return`[NoneFill]`}toString(){return`[NoneFill]`}get isIFill(){return!0}},Wg=class extends Pg{getType(){return K.Type.Solid}getColor(){return this._c.parseColor(this._value(`color`)??G.Scheme.Bg1)}setColor(e,t){return this._o.updater({fill:{color:e}},{description:(0,n.messageKey)(`op.setFillColor`),...t}).getFill()}toCSS(e){return{background:this.getColor().toCSS(e)}}hasVisibleStyling(){let e=this._o.styles?.getNormal();return!e||!e.getFill().isEqual(this)}isEqual(e){return!!e&&e.getType()===K.Type.Solid&&!!e.getColor().isEqual(this.getColor())}toJSON(){return{type:K.Type.Solid,color:this.getColor()?.toString()??null}}get[Symbol.toStringTag](){return`[SolidFill]`}toString(){return`[SolidFill]`}get isIFill(){return!0}},Gg=class extends Pg{constructor(e,t,n,r){super(n,r),this._i=e,this._l=t}getOffset(){return this._value(`offset`)??(this._l>1?this._i/(this._l-1):0)}getColor(){return this._c.parseColor(this._value(`color`)??G.Scheme.Bg1)}},Kg=class extends Pg{getType(){return K.Type.Gradient}getColor(){let e=this._value(`stops`)??n.CommonUtils.EmptyArray,t=e.length;return t===0?null:new Gg(0,t,this._o,[e[0]]).getColor()}setColor(e,t){let r=this._value(`stops`)??n.CommonUtils.EmptyArray,i=r.length>0?{...r[0]}:{offset:0,color:null},a=[...r];return a[0]=i,i.color=e,this._o.updater({fill:{stops:a}},{description:(0,n.messageKey)(`op.setFillColor`),...t}).getFill()}getStops(){let e=this._value(`stops`)??n.CommonUtils.EmptyArray,t=e.length,r=t===0?n.CommonUtils.EmptyArray:Array(t);for(let n=0;n<t;n++){let i=e[n];r[n]=new Gg(n,t,this._o,[i])}return r}setStops(e,t){return this._o.updater({fill:{stops:e}},{description:(0,n.messageKey)(`op.setStops`),...t}).getFill()}getGradientType(){return this._value(`gradientType`)??K.GradientType.Linear}setGradientType(e,t){return this._o.updater({fill:{gradientType:e}},{description:(0,n.messageKey)(`op.setGradientType`),...t}).getFill()}getAngle(){return this._value(`angle`)??0}setAngle(e,t){return this._o.updater({fill:{angle:e}},{description:(0,n.messageKey)(`op.setAngle`),...t}).getFill()}getFocus(){return this._value(`focus`)??null}setFocus(e,t){return this._o.updater({fill:{focus:e}},{description:(0,n.messageKey)(`op.setFocus`),...t}).getFill()}toCSS(e,t){let n=Om(this,e,t);return n?{background:n}:null}hasVisibleStyling(){return!0}isEqual(e){return!1}toJSON(){let e={type:K.Type.Gradient},t=this._value(`stops`)??n.CommonUtils.EmptyArray,r=t.length;if(r>0){let n=Array(r);for(let e=0;e<r;e++){let r=t[e],i={color:r.color.toString()},a=r.offset;a!==void 0&&(i.offset=a),n[e]=i}e.stops=n}return this.getAngle()!==0&&(e.angle=this.getAngle()),this.getGradientType()!==K.GradientType.Linear&&(e.gradientType=this.getGradientType()),this.getFocus()&&(e.focus=this.getFocus()),e}get[Symbol.toStringTag](){return`[GradientFill]`}toString(){return`[GradientFill]`}get isIFill(){return!0}},qg=class extends Pg{getType(){return K.Type.Pattern}getColor(){return this.getBackground()}setColor(e,t){return this.setBackground(e,t)}getBackground(){let e=this._value(`background`)??G.Named.Window;return this._c.parseColor(e)}setBackground(e,t){return this._o.updater({fill:{background:e}},{description:(0,n.messageKey)(`op.setBackgroundColor`),...t}).getFill()}getForeground(){return this._c.parseColor(this._value(`foreground`)??G.Scheme.Tx1)}setForeground(e,t){return this._o.updater({fill:{foreground:e}},{description:(0,n.messageKey)(`op.setForegroundColor`),...t}).getFill()}getPatternType(){return this._value(`patternType`)??K.BuiltInSheetPattern.None}setPatternType(e,t){return this._o.updater({fill:{patternType:e}},{description:(0,n.messageKey)(`op.setPatternType`),...t}).getFill()}toCSS(e){if(this.getPatternType()===K.BuiltInSheetPattern.None)return{background:`none`};if(this.getPatternType()===K.BuiltInSheetPattern.Solid)return{background:this.getForeground().toCSS(e)};let t=!0===e,n=e=>{let n=e.toRGBA(t);return n.alpha===0?`none`:n.toString(!1)};return jg.toCSS(this.getPatternType(),n(this.getForeground()),n(this.getBackground()))}toCSSMask(e){return jg.toCSSMask(this.getPatternType(),this.getForeground().toCSS(e),this.getBackground().toCSS(e))}hasVisibleStyling(){return!0}isEqual(e){if(!e||e.getType()!==K.Type.Pattern)return!1;let t=e;return t.getPatternType()===this.getPatternType()&&!!t.getForeground().isEqual(this.getForeground())&&!!t.getBackground().isEqual(this.getBackground())}toJSON(){let e={type:K.Type.Pattern};this.getPatternType()!==K.BuiltInSheetPattern.None&&(e.patternType=this.getPatternType());let t=this.getForeground();t&&(e.foreground=t.toString());let n=this.getBackground();return n&&(e.background=n.toString()),e}get[Symbol.toStringTag](){return`[PatternFill]`}toString(){return`[PatternFill]`}get isIFill(){return!0}},Jg=class{constructor(e){this._o=e,this._p=new Ng(e.properties)}toJSON(){let e=this._p.toJSON(),t=e.namedStyle??q.BuiltInName.Normal;return delete e.namedStyle,e.named=t,e}hasVisibleStyling(){if(this._hasVisibleStyling!==void 0)return this._hasVisibleStyling;let e=this.getFill();return this._hasVisibleStyling=!e||e.getType()!==K.Type.None||!this.getBorders().isEmpty(),this._hasVisibleStyling}isNormal(){return!1}getAuthoredProperties(){let e=this._o,t=e.direct;if(!t)return null;let r=e.range,i=r?.rowStart??n.CoordUtils.EmptyCell.rowIndex,a=r?.colStart??n.CoordUtils.EmptyCell.colIndex;return t.getAuthoredPropertiesAt?t.getAuthoredPropertiesAt(i,a,null):t.getPropertiesAt(i,a,null)}createStyle(e){let t=this._o,n=Mg(e,this),r=t.range,i=t.direct.cloneWithUpdate(n);return Yg(void 0,t.styles,i,r)}measureText(e,t=this.getFont().getSize(),n,r){let i=this.getFont();n||=i.getFamily();let a=i.getFallbacks();n===`Aptos Narrow`&&(a=[`Calibri`,...a]);let o=Lp(n,a);return B.getSharedMeasurer()(e,t*B.getDeviceScale(),o,{isBold:i.getWeight()>400,isItalic:i.getStyle().includes(`italic`),letterSpacing:i.getLetterSpacing(),...r})}createTextFrame(e,t=!1){return Dg(e,this.getFont(),this.getAlignment(),t)}update(e,t){return this._o.updater(e,t)}clear(){return this._o.updater(null,{description:(0,n.messageKey)(`op.clearStyle`)})}getBestFit(){if(this._bestFit!==void 0)return this._bestFit;let e=this.getInsets(),t=this.measureText(`My`);return this._bestFit={width:null,height:t.lineHeight+(e.top+e.bottom-2)},this._bestFit}getInsets(){if(this._insets!==void 0)return this._insets;this.getFont().getSize();let e=(t=this.getFont().getSize(),Math.max(3,Math.round(t<225?t/5:t/3.5)));var t;let n={top:1,left:e,bottom:1,right:e},r=this._p?.value(`insets`);return r&&(r.top!==void 0&&(n.top+=r.top),r.left!==void 0&&(n.left+=r.left),r.bottom!==void 0&&(n.bottom+=r.bottom),r.right!==void 0&&(n.right+=r.right)),this._insets=Object.freeze(n),this._insets}getBorders(){return this._border||=new Rg(this._o,this._p.values(`borders`)),this._border}setBorders(e,t){return this._o.updater({borders:e},{description:(0,n.messageKey)(`op.setBorders`),...t})}getFont(){return this._font||=new Vg(this._o,this._p.values(`font`)),this._font}setFont(e,t){return this._o.updater({font:e},{description:(0,n.messageKey)(`op.setFont`),...t})}getFill(){if(this._fill)return this._fill;let e=this._p,t,n=e.values(`fill`);for(let e=n.length-1;t===void 0&&e>=0;e--)t=n[e]?.type;let r=e.value(`fill`);return t===K.Type.None?this._fill=new Ug(this._o,n):t===K.Type.Solid||!t&&r.color?this._fill=new Wg(this._o,n):t===K.Type.Gradient?this._fill=new Kg(this._o,n):t===K.Type.Pattern?this._fill=new qg(this._o,n):this._fill=new Ug(this._o,n)}setFill(e,t){return this._o.updater({fill:e},{description:(0,n.messageKey)(`op.setFill`),...t})}setFillSolid(e){return this._o.updater({fill:{type:K.Type.Solid}},{description:(0,n.messageKey)(`op.setFillSolid`),...e}).getFill()}setFillGradient(e){return this._o.updater({fill:{type:K.Type.Gradient}},{description:(0,n.messageKey)(`op.setFillGradient`),...e}).getFill()}setFillPattern(e){return this._o.updater({fill:{type:K.Type.Pattern}},{description:(0,n.messageKey)(`op.setFillPattern`),...e}).getFill()}setFillNone(e){return this._o.updater({fill:{type:K.Type.None}},{description:(0,n.messageKey)(`op.setFillNone`),...e}).getFill()}getAlignment(){return this._alignment||=new zg(this._o,this._p.values(`alignment`)),this._alignment}setAlignment(e,t){return this._o.updater({alignment:e},{description:(0,n.messageKey)(`op.setAlignment`),...t})}getNumberFormat(){let e=this._p.value(`numberFormat`);return typeof e==`number`?cu(e):e}getNumberFormatRef(){return this._p.value(`numberFormat`)}setNumberFormat(e,t){return this._o.updater({numberFormat:e},{description:(0,n.messageKey)(`op.setNumberFormat`),...t})}getQuotePrefix(){return this._p.value(`quotePrefix`)}setQuotePrefix(e,t){return this._o.updater({quotePrefix:e},{description:(0,n.messageKey)(`op.setQuotePrefix`),...t})}getProtection(){return this._protection||=new Bg(this._o,this._p.values(`protection`)),this._protection}setProtection(e,t){return this._o.updater({protection:e},{description:(0,n.messageKey)(`op.setProtection`),...t})}getNamed(){let e=this._p.value(`named`)??q.BuiltInName.Normal;return this._o.styles.getNamedStyles().getByName(e)}setNamed(e,t){let r=e==null?null:typeof e==`string`?e:e.getName();return this._o.updater({named:r},{description:(0,n.messageKey)(`op.setNamedStyle`),...t})}get[Symbol.toStringTag](){return`[SheetCellStyle]`}toString(){return`Style: ${fd(this._o.range)}`}get isIStyle(){return!0}};function Yg(e,t,r,i,a=Zg,o){let s=i?.rowStart??n.CoordUtils.EmptyCell.rowIndex,c=i?.colStart??n.CoordUtils.EmptyCell.colIndex,l=[bp],u=t.getNormalRanged(),d=u.getPropertiesAt(s,c,e);d&&l.push(d);let f=(e,t)=>a(e,t,i);if(!r)return new Xg({styles:t,range:i,properties:l,direct:u,extent:o,updater:f});let p=r.getPropertiesAt(s,c,e);if(!p)return new Xg({styles:t,range:i,properties:l,direct:u,extent:o,updater:f});let m=p.named;if(m&&m!==q.BuiltInName.Normal&&!r.getAuthoredPropertiesAt){let n=t.getNamedStyles().getByName(m)?.getRanged().getPropertiesAt(s,c,e);n&&l.push(n)}return l.push(p),new Jg({styles:t,range:i,properties:l,direct:r,extent:o,updater:f})}var Xg=class extends Jg{isNormal(){return!0}getAuthoredProperties(){return null}};function Zg(e){throw Error(`Style is read-only and cannot be updated`)}async function Qg(){return globalThis.crypto}var $g=async(e,t,...n)=>{let r=e_(...n);return e.subtle.digest(t,r)},e_=(...e)=>{let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;return e.forEach(e=>{n.set(new Uint8Array(e),r),r+=e.byteLength}),n.buffer},t_=e=>{let t=new Uint8Array(e),n=``,r=t.byteLength;for(let e=0;e<r;e++)n+=String.fromCharCode(t[e]);return btoa(n)},n_=class e{static{this.DefaultAlgo=`SHA-512`}static{this.DefaultSpinCount=1e5}static async generateSaltAndHash(t,n=e.DefaultAlgo,r=e.DefaultSpinCount){if(!t)return null;let i=t_((await Qg()).getRandomValues(new Uint8Array(16)).buffer);return{salt:i,hash:await e._convertPasswordToHash(t,i,n,r)}}static async verifyPassword(t,r,i=e.DefaultAlgo,a=e.DefaultSpinCount){if(!t||!r)throw new n.NullNotAllowedError;return((e,t)=>{let n=e.length,r=t.length,i=n===r?0:1,a=Math.max(n,r);for(let o=0;o<a;o++)i|=e.charCodeAt(o%n)^t.charCodeAt(o%r);return i===0})(await e._convertPasswordToHash(t,r.salt,i,a),r.hash)}static async _convertPasswordToHash(e,t,n,r){let i=await Qg();n=n.toUpperCase();let a=(e=>{let t=e.length,n=new ArrayBuffer(2*t),r=new DataView(n);for(let n=0;n<t;n++)r.setUint16(2*n,e.charCodeAt(n),!0);return new Uint8Array(n)})(e),o=(e=>{let t=atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return r.buffer})(t),s=await $g(i,n,o,a.buffer);for(let e=0;e<r;e++){let t=new Uint32Array([e]).buffer;s=await $g(i,n,s,t)}return t_(s)}},r_=class{constructor(e,t=!1){this._isPaused=!1,this._isDisabled=!1,this._password=null,this._identities=null,this._properties=null,this._emitter=new x(this),this.fromJSON(e),this._isReadOnly=t}async lock(e,t,n,r){if(this._isReadOnly)return this;if(this._properties!==null&&!this._isDisabled)throw Error(`Cannot lock an already locked object. Use unlock first.`);try{this._validatePassword()}catch{throw Error(`A password is already set. Unlock first to change.`)}let i;if(t){let e=await n_.generateSaltAndHash(t,n,r);i={salt:e.salt,hash:e.hash},n&&(i.algorithm=n),r&&(i.spinCount=r)}else i=null;return e=e??this._properties??{},this._updateProperties(e),this._properties=e,this._password=i,this._isDisabled=!1,this._emitter.notify(`onLockChange`),this._emitter.notify(`onChange`),this}async unlock(e){if(this._isReadOnly)throw Error(`Cannot unlock a readonly workbook.`);return await this._validatePassword(e),this._isDisabled=this._properties!==null,this._password=null,this._identities=null,this._isPaused=!1,this._emitter.notify(`onLockChange`),this._emitter.notify(`onChange`),this}checkPassword(e){return this._validatePassword(e)}hasPassword(){return this._password!==null}async pause(e){if(this._isPaused)return this;if(this._properties===null||this._isDisabled)throw Error(`Cannot pause an object that is not locked.`);return await this._validatePassword(e),this._isPaused=!0,this._emitter.notify(`onLockChange`),this._emitter.notify(`onChange`),this}resume(){return this._isPaused?(this._isPaused=!1,this._emitter.notify(`onLockChange`),this._emitter.notify(`onChange`),this):this}async setProperties(e){if(this._isReadOnly)throw Error(`Cannot change the properties of a readonly object.`);if(this.isLocked())throw Error(`Cannot change the properties of a locked object. Use unlock first.`);let t=this._properties===null||this._isDisabled;return this._clearProperties(),this._updateProperties(e??{}),this._isDisabled=t,this._emitter.notify(`onChange`),this}isPaused(){return this._isPaused}isLocked(){return this._properties!==null&&!this._isDisabled&&!this._isPaused}isReadOnly(){return this._isReadOnly}async _validatePassword(e){let t=this._password;if(!t||!t.hash)return!0;if(!e||e.length===0)throw Error(`Password is required.`);if(!await n_.verifyPassword(e,{salt:t.salt,hash:t.hash},t.algorithm,t.spinCount))throw Error(`Invalid password.`);return!0}getProperties(){return this._properties}_isPropertyAllowed(e){if(this._isReadOnly)return!1;if(!this.isLocked())return!0;let t=this._properties[e];return typeof t==`boolean`&&t}_updateProperties(e){this._properties={...e,...this._properties??{}}}_clearProperties(){this._properties=null}addListeners(e,t){return this._emitter.addListeners(e,t)}fromJSON(e){if(this._password=null,this._identities=null,this._isPaused=!1,this._isDisabled=!1,this._properties=null,!e)return void this._fromJSON(null);let{password:t,identities:n,...r}=e,i=this._getAllowedKey();this._isDisabled=!0===r[i],delete r[i],this._fromJSON(r),t&&!this._isDisabled&&(this._password=t),n&&(this._identities=n)}_fromJSON(e){}_toJSON(e){return e}toJSON(){if(!this._properties)return null;let e={};return e=this._toJSON(e)??{},this._isDisabled?Object.keys(e).length===0?null:(e[this._getAllowedKey()]=!0,e):(this._password&&(e.password=this._password),this._identities&&(e.identities=this._identities),e)}get isIProtection(){return!0}},i_=Object.freeze({selectLockedCells:!0,selectUnlockedCells:!0,showFormulas:!0,autoTable:!1,deleteColumns:!1,deleteRows:!1,formatCells:!1,formatColumns:!1,formatRows:!1,insertColumns:!1,insertHyperlinks:!1,insertRows:!1,objects:!1,pivotTables:!1,scenarios:!1,sort:!1}),a_=class extends r_{isAutoTableAllowed(){return this._isPropertyAllowed(`autoTable`)}isDeleteColumnsAllowed(){return this._isPropertyAllowed(`deleteColumns`)}isDeleteRowsAllowed(){return this._isPropertyAllowed(`deleteRows`)}isFormatCellsAllowed(){return this._isPropertyAllowed(`formatCells`)}isFormatColumnsAllowed(){return this._isPropertyAllowed(`formatColumns`)}isFormatRowsAllowed(){return this._isPropertyAllowed(`formatRows`)}isInsertColumnsAllowed(){return this._isPropertyAllowed(`insertColumns`)}isInsertHyperlinksAllowed(){return this._isPropertyAllowed(`insertHyperlinks`)}isInsertRowsAllowed(){return this._isPropertyAllowed(`insertRows`)}isObjectsAllowed(){return this._isPropertyAllowed(`objects`)}isPivotTablesAllowed(){return this._isPropertyAllowed(`pivotTables`)}isScenariosAllowed(){return this._isPropertyAllowed(`scenarios`)}isSortAllowed(){return this._isPropertyAllowed(`sort`)}isShowFormulasAllowed(){return this._isPropertyAllowedByDefault(`showFormulas`)}isSelectLockedCellsAllowed(){return this._isPropertyAllowedByDefault(`selectLockedCells`)}isSelectUnlockedCellsAllowed(){return this._isPropertyAllowedByDefault(`selectUnlockedCells`)}_isPropertyAllowedByDefault(e){return!this.isLocked()||!1!==this._properties[e]}_getAllowedKey(){return`sheet`}_updateProperties(e){super._updateProperties(e),this._properties=e}_clearProperties(){super._clearProperties(),this._properties=null}_fromJSON(e){super._fromJSON(e),this._properties=e}_toJSON(e){let t=this._properties;if(t){let n=Object.keys(t);for(let r=0;r<n.length;r++){let i=t[n[r]];i!=null&&i!==i_[n[r]]&&(e[n[r]]=i)}}return super._toJSON(e)}get[Symbol.toStringTag](){return`[SheetProtection]`}toString(){return null}get isISheetProtection(){return!0}},o_=e=>typeof e==`string`?(0,n.t)(`error.address.invalidRangeAddress`,{address:e}):(0,n.t)(`error.address.invalidRangeAddressAny`),J=()=>{throw Error((0,n.t)(`error.address.invalidRangeEmpty`))},s_={hasSubscribers:!1},c_=s_,l_=s_,u_=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,d_=()=>c_.hasSubscribers||l_.hasSubscribers,f_=new Set,p_=typeof process==`object`&&process?process:{},m_=e=>!!e&&e===Math.floor(e)&&e>0&&isFinite(e),h_=e=>m_(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?g_:null:null,g_=class extends Array{constructor(e){super(e),this.fill(0)}},__=class e{heap;length;static#e=!1;static create(t){let n=h_(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},v_=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;#E;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,autopurgeTimers:e.#S,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g},free:e.#_,isBackgroundFetch:t=>e.#W(t),backgroundFetch:(t,n,r,i)=>e.#U(t,n,r,i),moveToTail:t=>e.#X(t),indexes:t=>e.#I(t),rindexes:t=>e.#L(t),isStale:t=>e.#j(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:s,allowStale:c,dispose:l,onInsert:u,disposeAfter:d,noDisposeOnSet:f,noUpdateTTL:p,maxSize:m=0,maxEntrySize:h=0,sizeCalculation:g,fetchMethod:_,memoMethod:v,noDeleteOnFetchRejection:y,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:x,allowStaleOnFetchAbort:S,ignoreFetchAbort:C,backgroundFetchSize:w=1,perf:T}=t;if(this.backgroundFetchSize=w,T!==void 0&&typeof T?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=T??u_,n!==0&&!m_(n))throw TypeError(`max option must be a nonnegative integer`);let E=n?h_(n):Array;if(!E)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=m,this.maxEntrySize=h||this.#t,this.sizeCalculation=g,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(v!==void 0&&typeof v!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=v,_!==void 0&&typeof _!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=_,this.#w=!!_,this.#u=new Map,this.#d=Array.from({length:n}).fill(void 0),this.#f=Array.from({length:n}).fill(void 0),this.#p=new E(n),this.#m=new E(n),this.#h=0,this.#g=0,this.#_=__.create(n),this.#c=0,this.#l=0,typeof l==`function`&&(this.#n=l),typeof u==`function`&&(this.#r=u),typeof d==`function`?(this.#i=d,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#C=!!this.#n,this.#E=!!this.#r,this.#T=!!this.#i,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!y,this.allowStaleOnFetchRejection=!!x,this.allowStaleOnFetchAbort=!!S,this.ignoreFetchAbort=!!C,this.maxEntrySize!==0){if(this.#t!==0&&!m_(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!m_(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#M()}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!s,this.ttlResolution=m_(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!m_(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#D()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;(e=>!f_.has(e))(t)&&(f_.add(t),((e,t,n,r)=>{typeof p_.emitWarning==`function`?p_.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)})(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#D(){let e=new g_(this.#e),t=new g_(this.#e);this.#x=e,this.#b=t;let n=this.ttlAutopurge?Array.from({length:this.#e}):void 0;this.#S=n,this.#A=(n,i,a=this.#s.now())=>{t[n]=i===0?0:a,e[n]=i,r(n,i)},this.#O=n=>{t[n]=e[n]===0?0:this.#s.now(),r(n,e[n])};let r=this.ttlAutopurge?(e,t)=>{if(n?.[e]&&(clearTimeout(n[e]),n[e]=void 0),t&&t!==0&&n){let i=setTimeout(()=>{this.#j(e)?(this.#Z(this.#d[e],`expire`),n[e]=void 0):r(e,o(e))},t+1);i.unref&&i.unref(),n[e]=i}}:()=>{};this.#k=(n,r)=>{if(e[r]){let o=e[r],s=t[r];if(!o||!s)return;n.ttl=o,n.start=s,n.now=i||a(),n.remainingTTL=o-(n.now-s)}};let i=0,a=()=>{let e=this.#s.now();if(this.ttlResolution>0){i=e;let t=setTimeout(()=>i=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=e=>{let t=this.#u.get(e);return t===void 0?0:o(t)};let o=n=>{let r=e[n],o=t[n];return r&&o?r-((i||a())-o):1/0};this.#j=n=>{let r=t[n],o=e[n];return!!o&&!!r&&(i||a())-r>o}}#O=()=>{};#k=()=>{};#A=()=>{};#j=()=>!1;#M(){let e=new g_(this.#e);this.#l=0,this.#y=e,this.#N=t=>{this.#l-=e[t],e[t]=0},this.#F=(e,t,n,r)=>{if(!m_(n)){if(this.#W(t))return this.backgroundFetchSize;if(!r)throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!m_(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}return n},this.#P=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#B(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#N=e=>{};#P=(e,t,n)=>{};#F=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#h);)t=this.#m[t]}*#L({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#g);)t=this.#p[t]}#R(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#L())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#L()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*values(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#L())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.#J(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}rforEach(e,t=this){for(let n of this.#L()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#L({allowStale:!0}))this.#j(t)&&(this.#Z(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#W(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#I({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#W(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.#z(t,n.value,n)}}set(e,t,n={}){let{status:r=c_.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op=`set`,r.key=e,t!==void 0&&(r.value=t),r.cache=this);let i=this.#z(e,t,n);return r&&c_.hasSubscribers&&c_.publish(r),i}#z(e,t,n,r){let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:s=this.sizeCalculation,status:c}=n,l=this.#W(t);if(t===void 0)return c&&(c.set=`deleted`),this.delete(e),this;let{noUpdateTTL:u=this.noUpdateTTL}=n;c&&!l&&(c.value=t);let d=this.#F(e,t,n.size||0,s,c);if(this.maxEntrySize&&d>this.maxEntrySize)return this.#Z(e,`set`),c&&(c.set=`miss`,c.maxEntrySizeExceeded=!0),this;let f=this.#c===0?void 0:this.#u.get(e);if(f===void 0)f=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#B(!1):this.#c:this.#_.pop(),this.#d[f]=e,this.#f[f]=t,this.#u.set(e,f),this.#p[this.#g]=f,this.#m[f]=this.#g,this.#g=f,this.#c++,this.#P(f,d,c),c&&(c.set=`add`),u=!1,this.#E&&!l&&this.#r?.(t,e,`add`);else{this.#X(f);let n=this.#f[f];if(t!==n){if(!o)if(this.#W(n)){n!==r&&n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:i}=n;i!==void 0&&i!==t&&(this.#C&&this.#n?.(i,e,`set`),this.#T&&this.#v?.push([i,e,`set`]))}else this.#C&&this.#n?.(n,e,`set`),this.#T&&this.#v?.push([n,e,`set`]);if(this.#N(f),this.#P(f,d,c),this.#f[f]=t,!l){let r=n&&this.#W(n)?n.__staleWhileFetching:n,i=r===void 0?`add`:t===r?`update`:`replace`;c&&(c.set=i,r!==void 0&&(c.oldValue=r)),this.#E&&this.onInsert?.(t,e,i)}}else l||(c&&(c.set=`update`),this.#E&&this.onInsert?.(t,e,`update`))}if(i!==0&&!this.#x&&this.#D(),this.#x&&(u||this.#A(f,i,a),c&&this.#k(c,f)),!o&&this.#T&&this.#v){let e,t=this.#v;for(;e=t?.shift();)this.#i?.(...e)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#B(!0),this.#W(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#T&&this.#v){let e,t=this.#v;for(;e=t?.shift();)this.#i?.(...e)}}}#B(e){let t=this.#h,n=this.#d[t],r=this.#f[t],i=this.#W(r);i&&r.__abortController.abort(Error(`evicted`));let a=i?r.__staleWhileFetching:r;return(this.#C||this.#T)&&a!==void 0&&(this.#C&&this.#n?.(a,n,`evict`),this.#T&&this.#v?.push([a,n,`evict`])),this.#N(t),this.#S?.[t]&&(clearTimeout(this.#S[t]),this.#S[t]=void 0),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{status:n=c_.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`has`,n.key=e,n.cache=this);let r=this.#V(e,t);return c_.hasSubscribers&&c_.publish(n),r}#V(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#W(e)&&e.__staleWhileFetching===void 0)return!1;if(!this.#j(i))return n&&this.#O(i),r&&(r.has=`hit`,this.#k(r,i)),!0;r&&(r.has=`stale`,this.#k(r,i))}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{status:n=d_()?{}:void 0}=t;n&&(n.op=`peek`,n.key=e,n.cache=this),t.status=n;let r=this.#H(e,t);return c_.hasSubscribers&&c_.publish(n),r}#H(e,t){let{status:n,allowStale:r=this.allowStale}=t,i=this.#u.get(e);if(i===void 0||!r&&this.#j(i))return void(n&&(n.peek=i===void 0?`miss`:`stale`));let a=this.#f[i],o=this.#W(a)?a.__staleWhileFetching:a;return n&&(o===void 0?n.peek=`miss`:(n.peek=`hit`,n.value=o)),o}#U(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#W(i))return i;let a=new AbortController,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0,d=n.ignoreFetchAbort||!(!n.allowStaleOnFetchAbort||r===void 0);if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return l(a.signal.reason,d);let f=u,p=this.#f[t];return(p===u||p===void 0&&c&&i)&&(r===void 0?f.__staleWhileFetching===void 0?this.#Z(e,`fetch`):this.#f[t]=f.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.#z(e,r,s.options,f))),r},l=(r,i)=>{let{aborted:o}=a.signal,s=o&&n.allowStaleOnFetchAbort,c=s||n.allowStaleOnFetchRejection,l=c||n.noDeleteOnFetchRejection,d=u;if(this.#f[t]===u&&(!l||!i&&d.__staleWhileFetching===void 0?this.#Z(e,`fetch`):s||(this.#f[t]=d.__staleWhileFetching)),c)return n.status&&d.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),d.__staleWhileFetching;if(d.__returned===d)throw r};n.status&&(n.status.fetchDispatched=!0);let u=new Promise((t,r)=>{let o=this.#a?.(e,i,s);a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))}),o&&o instanceof Promise?o.then(e=>t(e===void 0?void 0:e),r):o!==void 0&&t(o)}).then(c,e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),l(e,!1))),d=Object.assign(u,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.#z(e,d,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=d,d}#W(e){if(!this.#w)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof AbortController}fetch(e,t={}){let n=l_.hasSubscribers,{status:r=d_()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let i=this.#G(e,t);return r&&n&&(r.trace=!0,l_.tracePromise(()=>i,r).catch(()=>{})),i}async#G(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(g&&(g.op=`fetch`,g.key=e,h&&(g.forceRefresh=!0),g.cache=this),!this.#w)return g&&(g.fetch=`get`),this.#J(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#U(e,y,v,m);return t.__returned=t}{let t=this.#f[y];if(this.#W(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#j(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#X(y),r&&this.#O(y),g&&this.#k(g,y),t;let a=this.#U(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}forceFetch(e,t={}){let n=l_.hasSubscribers,{status:r=d_()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let i=this.#K(e,t);return r&&n&&(r.trace=!0,l_.tracePromise(()=>i,r).catch(()=>{})),i}async#K(e,t={}){let n=await this.#G(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let{status:n=c_.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`memo`,n.key=e,t.context&&(n.context=t.context),n.cache=this);let r=this.#q(e,t);return n&&(n.value=r),c_.hasSubscribers&&c_.publish(n),r}#q(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,status:i,forceRefresh:a,...o}=t;i&&a&&(i.forceRefresh=!0);let s=this.#J(e,o),c=a||s===void 0;if(i&&(i.memo=c?`miss`:`hit`,c||(i.value=s)),!c)return s;let l=n(e,s,{options:o,context:r});return i&&(i.value=l),this.#z(e,l,o),l}get(e,t={}){let{status:n=c_.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`get`,n.key=e,n.cache=this);let r=this.#J(e,t);return n&&(r!==void 0&&(n.value=r),c_.hasSubscribers&&c_.publish(n)),r}#J(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o===void 0)return void(a&&(a.get=`miss`));let s=this.#f[o],c=this.#W(s);return a&&this.#k(a,o),this.#j(o)?c?(a&&(a.get=`stale-fetching`),n&&s.__staleWhileFetching!==void 0?(a&&(a.returnedStale=!0),s.__staleWhileFetching):void 0):(i||this.#Z(e,`expire`),a&&(a.get=`stale`),n?(a&&(a.returnedStale=!0),s):void 0):(a&&(a.get=c?`fetching`:`hit`),this.#X(o),r&&this.#O(o),c?s.__staleWhileFetching:s)}#Y(e,t){this.#m[t]=e,this.#p[e]=t}#X(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#Y(this.#m[e],this.#p[e]),this.#Y(this.#g,e),this.#g=e)}delete(e){return this.#Z(e,`delete`)}#Z(e,t){c_.hasSubscribers&&c_.publish({op:`delete`,delete:t,key:e,cache:this});let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0)if(this.#S?.[r]&&(clearTimeout(this.#S[r]),this.#S[r]=void 0),n=!0,this.#c===1)this.#Q(t);else{this.#N(r);let n=this.#f[r];if(this.#W(n)?n.__abortController.abort(Error(`deleted`)):(this.#C||this.#T)&&(this.#C&&this.#n?.(n,e,t),this.#T&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}if(this.#T&&this.#v?.length){let e,t=this.#v;for(;e=t?.shift();)this.#i?.(...e)}return n}clear(){return this.#Q(`delete`)}#Q(e){for(let t of this.#L({allowStale:!0})){let n=this.#f[t];if(this.#W(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#C&&this.#n?.(n,r,e),this.#T&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b){this.#x.fill(0),this.#b.fill(0);for(let e of this.#S??[])e!==void 0&&clearTimeout(e);this.#S?.fill(void 0)}if(this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#T&&this.#v){let e,t=this.#v;for(;e=t?.shift();)this.#i?.(...e)}}};function y_(e,t,n,r,i){return F_(e- -832,r)}function b_(e,t,n,r,i){return F_(t-122,e)}(function(){let e=S_();function t(e,t,n,r,i){return F_(t-485,e)}function n(e,t,n,r,i){return F_(e- -496,r)}function r(e,t,n,r,i){return F_(r-521,e)}function i(e,t,n,r,i){return F_(t-684,e)}for(;;)try{if(-parseInt(r(`afnn`,0,0,928))/1+-parseInt(n(21,0,0,`JLDz`))/2*(-parseInt(t(`b3*K`,886))/3)+-parseInt(r(`afnn`,0,0,975))/4+parseInt(r(`O1Ck`,0,0,1025))/5+-parseInt(n(4,0,0,`CL*u`))/6*(-parseInt(t(`FjdC`,937))/7)+-parseInt(i(`*F&]`,1130))/8*(-parseInt(i(`JLDz`,1087))/9)+-parseInt(i(`LAF[`,1199))/10==148704)break;e.push(e.shift())}catch{e.push(e.shift())}})(),Object[y_(-298,0,0,`cz!j`)]([b_(`Aftf`,555),b_(`FjdC`,611)]);function x_(e){if(e[t(-497,`]DTD`,-497,-548,-569)])return e[a(266,`b3*K`,375,356,342)];function t(e,t,n,r,i){return y_(r- -125,0,0,t)}let n=[];var r,i;function a(e,t,n,r,i){return y_(i-705,0,0,t)}return(e[t(0,`afnn`,0,-539)]?.[a(401,`imE1`,249,336,322)]??0)>0&&n[t(0,`HM@7`,0,-461)](y_(-299,0,0,`CL*u`)),((e[a(315,`^qS1`,224,198,273)]??0)>0||(e[r=49,i=`!xFM`,y_(r-453,0,0,i)]??0)>0)&&n[a(435,`NBPI`,417,423,423)](y_(-302,0,0,`z*V%`)),n}function S_(){let e=`vmo9W4VdLmofW4NcMW.W4/dTLlcUCkJWPFcMJJdMSkm.Cf50WQ8xfSkYBJ8.h2/cG2zRWPpdNW.W57dLmkKlNhcVmk0qmksa8ky.eCoJzmoRDw3dOmkUW5JdIe4.WPLQfsmYWQWHoG.vCkRW4ZdPCkYzCozlG.tXHlWPS3W70.h2ZcJCoGESonq8kx.sSk+jCk4k07dSCoPW5JdH0v9WRqaWPnfDSotnxu.mM9mWP0.W60BCeK.W4RcUcddKCkhvsDb.W5xcPsldHSkDvrvnb0e.WQ8ojt8MW5eubmkVmCkUWRHlW4VcIXWhW6JcK8k2cqXbW63cJmo9W7HZW55DoxHvWPpcTdhdOHFdJYawnmo8WO0.r8k/pSk4lKNdPG.W4ddLmkblW.W61AW4xcQq.mH0MW6qzjSkXtrVdIW.c3lcGxnTWP7dG3O.kNHlWPFcOqC.iCodW54oW5zTWQePWQ0k.ASoyWOiwWRtdQclcJq.vCo9W4NdVmoyW5tcIKG.W7hdI1zMW7H6imkS.WR8/EfiBkq.W7FdKxr9W6zYn8kCzSkicW.W49CivGphW.WQSiWO/dRMFdLSk3W6mTFa.o8oYW7SM.WPBdJgv0osZdPW.EmoyW6xcVH/dIa.vmkRW4ddOSkVESovm2C.nXfdC8k1WPO1xfhdImoIW4RdILZcMfrsW4T7W4vU.WOChWOL5.z8ojgZi.gM1sW54.W45AWRFdGv/dNXhcNW.WPm8W6qLgmoDW7PQWP8.oCoEiMS.zSoyW7VcVaRdLa.W7ddM0XwW7bJia.W6GTWPqp.WO3dSdNcULm/W6fdW5BcNa.C8kzW5i.gIpcSG.W4evsCogdaG.d3lcH2O.W4PoymoaECoFumom.WPSzFq4qlSkbsCkSW4y.mGuMW7jt.eSoGASoHCrFdNCkqW4/dHMjQ.WPldO3FcHCoCfxjHpNJdVIzA.sSk+jCk4k07dSCoPW4ZdM0vUWRGFWOyFBmkuE2/cRSoB.vgpdKCkoxcFdHMRcLmkqWQ0.AmojW7RcUG.WRO1zKK.W61nW5/cSa.jmocW5eBW7bWWRu+WOuqW4C.Dc4sW4ldPYxdJmktmmksWPu.k3HiWP/cPXy.vmowW7JdLmk5W5lcTeHTWP0.W7brW5lcUhRdJCkg.jxveWOlcLGddNCkra8kC.e8kUeCosW5FcQhpdTt7dIa.W4pdQ8opWO3dImod.WP0DWPr5WQNdSqPu.W4boB8otEmof.WOuhWPnJ.k8oyW74oW6DJWRW.W4XrWQFdTMNdGGa.WQlcUeddV8oGmIHFea.W6OkW5ycW4f5.W5xcPchdH8kDvcTkfa.W63dQmokWRa.hgVcH8o0smowr8kni3tdJq.F8oeWOKrWOZdOJNcIq.W6aDW5CiW7z5W6FcNLfJW4rm.WQGlWOddQLxdOCk0W7Cbua.vCk/W4ZdTCk0zq.jaS7W7WghmkRztVdSqtdTCksr8kLjffLpu7cV8kGW5yLs8kTWOKtWOpcRmo2W4XoWQ1SW5ddPJNcOmkdoCoXWRtdKmkvW7PeW7bxkg1pE0zggMKkWP0lW7WltCktWROQkLxdOu07W6pcRmo9WRDvWPFdQCkWW61XpCo6cCoqWQCpbY09W7ZcSuTfW7Ld.tgNdS8kgxYO.W4vfD8ovymoeuCkFW78pAmoGrb5pESkl.yvL5WQSqaCkP.W4xcJJm7FhNdNwpdNSkGWQOn.qJRcIxpdRSoqWPNcOJjqWRe/qcddMCo+FmkaeYPWySkLWPrAaNhdMczcWPpcKmkuWOOQW4Tdn8oEWQ3cQ8o6WPFdKSovpCohpCoqWPGyWRldV8k4W4pcOti8vaKEW6NdKZSgWRpcQCoGerpdImoDW4jqWQdcV8oSDJhdPmkKWQ43WOSnbcm4W6ZdOCoWWReiWPFcNcmRymktu1tdVSkeW6GhW4K.W5PlnKSqca.WRSjWRSwf8kxW6LrWP1lW47cRxye.WPpdOrhdNrC.WPeslrBcSby.nN/dJdBdUSojWP/cPcHgWRa/.FCotWPaaWPhdSJm.shJdQCkr.W7yAW4Sn.zCozWO8l.W4RcOhRdUG.y8otW7BcTWVdMmoAW4q.W6ddUXlcTmoUaIT8nmoP.W59BBCoDEa.WPZcRq/dOSkx.W54vvCoxhri.W49cCeNdSe7dGa/dPCoDW5VcOq.zSkQWRPMW7RcKsj6fCom.W4RcTc3dK8kDtG.E8odgZi.W4CFtSop.DslcMrddRComWPtcSW.W4DrWR3dLxZdNG.WOxdSGZdGZhdG8ojW50wv3tdJG.tSo3W47dHq.oSoSWRhcLSoNn8oaWOJcOxlcIa.jCouiMS.WQ3cQmkxW6XFW5dcKmozBJZcLbLE.WOFdI2HWpJVdVftdNa.W43dT1JdUSkCWPtcOHJdNW.WPuymau.WOBcLmkwo23cTq.W6OzDu1k.cxxcGhnRWPddIwu.W78aDvbBW4G.FIBcMcpdSq.WOK7W5C+bmoBW6O.qmk/pSk0mKNdVmk9W5m.gmkPa8ou.p8o4W6y1W4JcMa.t8k1pCk+m08.W5WPqYaIWQmDiKm.u2NdR8kxtJa.rmoQW5ldHSoeW5/cJa.f8kJbmoTW7VcQwpdUa.WRpcV03dU8oNjtm.BbpcLgCKyG.WQpcN8kopxxcTmkijIrUB8oEF0vOrXddQ8kyW40.Fmowbc8e.W7fqW4xcQq.W5ldVKhcOmomWQ3cUL7dKCkEvbddMCofomotWO08tmkiymk0WOjAWRFcM8kDjSk7.W7ZdN8oHW6ddNSoaW6Czn8khoSomW4ZcKW.WORdRGddGGFdJ8onW5W.W5lcOgFdQwmA.fmkwWQRcK8kjW63cLKDa.uh7dSSkvrchdM0u.W6pdUbhcTmkGCbnqomofWRuW.W6OmBwjlW5BcQXirWPVdUW.W4GEq8oslWNcK8kN.E8ozWQOkWPtdPctcPSojomoP.WOuWW6yLbmoBW6DLWOKx.W7pdTCokWRm.W4hdVhVcVa.d2bnW5K.WP7cNSkXd1BcJSkyDcfPAW.F8odWPun.FmogWOOmWPC.W63dTCoVWRiDWOBdKSoFqH7cLq.WOD6ftaVWQK.qCo9W4NdT8ocW5BcKNNdUSoAWPy.WP7cQNVcRG.gxlcNmoqqSorwCkl.W55CW4W6WPFdVZTLW4JdLq`.split(`.`);return(S_=function(){return e})()}var C_=(e,t,n=126)=>function(e,t,n=126){let r=e[a(-232,-271,-184,-236,`sNIJ`)](``);function i(e,t,n,r,i){return b_(t,n-603)}for(let e=0;e<r[a(-225,-286,-299,-298,`4AOX`)];e++)r[e][i(0,`^KFF`,1191)](0)<=n&&(r[e]=String[i(0,`1%og`,1236)]((r[e][a(-285,-284,-220,-333,`UJtv`)](0)+t)%n));function a(e,t,n,r,i){return b_(i,e- -874)}return r[o=632,s=`imE1`,b_(s,o-2)](``);var o,s}(e,n-t);function w_(e,t,n,r,i){return F_(i-786,r)}var T_=e=>{return globalThis[t=`tgQf`,n=-324,y_(n-69,0,0,t)](e);var t,n},E_=y_(-294,0,0,`JLDz`),D_=y_(-342,0,0,`Tk!C`),O_=RegExp(`^`+E_+E_+D_),k_=RegExp(`^`+E_+D_),A_=/^[a-z][a-z0-9+.-]*$/,j_=/^[a-z0-9-]+(\.[a-z0-9-]+)*$/;function M_(e){let t=e[o(`c[I9`,1045,1093,1018,972)](i(`z*V%`,1402,1305,1323,1380));if(t<=0)return null;let n=e[o(`Aftf`,1096,1077,1046,1080)](0,t)[a(-505,-567,-504,`c[I9`,-548)]()[o(`SwPN`,986,997,987,990)]();if(!A_[a(-584,-544,-544,`c[I9`,-617)](n))return null;function r(e,t,n,r,i){return w_(0,0,0,t,e- -453)}function i(e,t,n,r,i){return w_(0,0,0,e,i-146)}function a(e,t,n,r,i){return w_(0,0,0,r,n- -1750)}function o(e,t,n,r,i){return w_(0,0,0,e,t- -206)}return{protocol:n,host:e[i(`]DTD`,0,0,0,1367)](t+3)[r(747,`sNIJ`)]()[r(762,`vx(Y`)]()}}function N_(e,t,n,r,i){return F_(e- -181,r)}function P_(e,t=!1){function n(e,t,n,r,i){return N_(i-1165,0,0,t)}let r=M_(e);function i(e,t,n,r,i){return N_(e-364,0,0,r)}if(!r)return!1;function a(e,t,n,r,i){return N_(r-845,0,0,t)}return r[a(0,`4AOX`,0,1096)]===`*`||r[n(0,`!xFM`,0,0,1443)]===``||(r[a(0,`pn*N`,0,1086)]===i(678,0,0,`z*V%`)||r[n(0,`z*V%`,0,0,1527)]===N_(342,0,0,`2$[e`)?function(e,t=!1){function n(e,t,n,r,i){return w_(0,0,0,e,t- -356)}return!(e[n(`*F&]`,971)]>255)&&(!!O_[r=`*F&]`,i=-391,w_(0,0,0,r,i- -1675)](e)||!(!t||!k_[n(`Ax9E`,937)](e)));var r,i}(r[o=-310,s=`nPV]`,N_(o- -643,0,0,s)],t):r[n(0,`c[I9`,0,0,1521)][i(693,0,0,`7jO2`)]<=255&&j_[n(0,`nPV]`,0,0,1426)](r[n(0,`O1Ck`,0,0,1502)]));var o,s}function F_(e,t){e-=397;let n=S_(),r=n[e];F_.UievBC===void 0&&(F_.ISeMGA=function(e,t){let n,r,i=[],a=0,o=``;for(e=function(e){let t=``,n=``;for(let n,r,i=0,a=0;r=e.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)&&(t+=String.fromCharCode(255&n>>(-2*i&6))))r=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=`.indexOf(r);for(let e=0,r=t.length;e<r;e++)n+=`%`+(`00`+t.charCodeAt(e).toString(16)).slice(-2);return decodeURIComponent(n)}(e),r=0;r<256;r++)i[r]=r;for(r=0;r<256;r++)a=(a+i[r]+t.charCodeAt(r%t.length))%256,n=i[r],i[r]=i[a],i[a]=n;r=0,a=0;for(let t=0;t<e.length;t++)r=(r+1)%256,a=(a+i[r])%256,n=i[r],i[r]=i[a],i[a]=n,o+=String.fromCharCode(e.charCodeAt(t)^i[(i[r]+i[a])%256]);return o},F_.PtIclv={},F_.UievBC=!0);let i=e+n[0],a=F_.PtIclv[i];return a?r=a:(F_.CqQfTm===void 0&&(F_.CqQfTm=!0),r=F_.ISeMGA(r,t),F_.PtIclv[i]=r),r}function I_(e,t){e-=484;let n=X_(),r=n[e];I_.bkPypI===void 0&&(I_.LwtLrM=function(e,t){let n,r,i=[],a=0,o=``;for(e=function(e){let t=``,n=``;for(let n,r,i=0,a=0;r=e.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)&&(t+=String.fromCharCode(255&n>>(-2*i&6))))r=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=`.indexOf(r);for(let e=0,r=t.length;e<r;e++)n+=`%`+(`00`+t.charCodeAt(e).toString(16)).slice(-2);return decodeURIComponent(n)}(e),r=0;r<256;r++)i[r]=r;for(r=0;r<256;r++)a=(a+i[r]+t.charCodeAt(r%t.length))%256,n=i[r],i[r]=i[a],i[a]=n;r=0,a=0;for(let t=0;t<e.length;t++)r=(r+1)%256,a=(a+i[r])%256,n=i[r],i[r]=i[a],i[a]=n,o+=String.fromCharCode(e.charCodeAt(t)^i[(i[r]+i[a])%256]);return o},I_.xGJPrF={},I_.bkPypI=!0);let i=e+n[0],a=I_.xGJPrF[i];return a?r=a:(I_.VzxQCE===void 0&&(I_.VzxQCE=!0),r=I_.LwtLrM(r,t),I_.xGJPrF[i]=r),r}function L_(e,t,n,r,i){return I_(n- -773,r)}(function(){let e=X_();function t(e,t,n,r,i){return I_(r- -131,i)}function n(e,t,n,r,i){return I_(t-984,i)}function r(e,t,n,r,i){return I_(e-485,t)}function i(e,t,n,r,i){return I_(r-157,e)}for(;;)try{if(-parseInt(n(0,1489,0,0,`*&8y`))/1*(parseInt(n(0,1654,0,0,`oDse`))/2)+parseInt(i(`jOU2`,0,0,717))/3*(-parseInt(t(0,0,0,532,`UXT7`))/4)+parseInt(t(0,0,0,488,`pHe*`))/5+-parseInt(r(1097,`xzA@`))/6+parseInt(n(0,1606,0,0,`W2M1`))/7+-parseInt(r(978,`A$@s`))/8*(parseInt(r(1109,`xzA@`))/9)+parseInt(n(0,1672,0,0,`mR*w`))/10==788175)break;e.push(e.shift())}catch{e.push(e.shift())}})();var R_=async e=>{let t=[],n=e[o(`2PsX`,-130,-137,-225,-225)]?new Date(e[o(`!K6n`,-28,-59,-103,53)]):null;function r(e,t,n,r,i){return I_(i- -186,n)}if(n?isNaN(n)?t[o(`Drwc`,-217,-309,-292,-122)](c(1395,1345,1351,1420,`eC22`)):n<new Date&&t[s(-447,-549,-516,`tkO9`,-449)](l(`A$@s`,-347,-340,-351,-254)+n[r(420,390,`3]Qc`,464,420)]()):t[c(1523,1571,1469,1464,`3Dv$`)](o(`3oVN`,-158,-142,-210,-228)),await Ie[c(1397,1412,1374,1402,`jorh`)]())return t;let i=await Ie[s(-322,-241,-304,`E#9i`,-346)](),a=i[l(`gIrw`,-111,-165,-28,-90)]==null?c(1483,1487,1472,1458,`mR*w`):l(`P6]J`,-67,-245,-152,-167);function o(e,t,n,r,i){return I_(t- -711,e)}if(!x_(e)[r(0,0,`fyCS`,0,375)](a))return t[l(`Fy[G`,-246,-316,-296,-250)](r(0,0,`(gmG`,0,475)+a+s(-437,-415,-446,`!K6n`,-396)),t;if(i[s(-460,-542,-369,`xzA@`,-410)]!=null){let n=e=>{if(!e)return null;function t(e,t,n,r,i){return c(r- -1705,t-316,n-315,r-178,n)}return e[t(0,-273,`Drwc`,-220)]()[t(0,-187,`RPh*`,-294)]()},a=n(e[r(0,0,`E#9i`,0,406)]);if(a){let e=i[s(-468,-422,-397,`b06(`,-423)],r=e&&n(e[s(-368,-448,-364,`F5Cv`,-364)])===a,o=e&&n(e[s(-371,-320,-435,`eC22`,-317)])===a;!r&&!o&&t[c(1506,1492,1485,1559,`Iw$J`)](s(-367,-272,-346,`Rl3%`,-299))}(e[l(`Drwc`,-191,-155,-275,-247)]??0)>0&&i[l(`8uf4`,-130,-178,-228,-187)]>e[c(1536,1521,1459,1491,`UXT7`)]&&t[s(-354,-264,-272,`Rl3%`,-326)](i[c(1569,1614,1607,1594,`E#9i`)]+`/`+e[s(-319,-378,-218,`%ilq`,-321)]+o(`DzRr`,-34)),(e[c(1513,1530,1518,1598,`DzRr`)]??0)>0&&i[c(1504,1492,1398,1594,`E$Om`)]>e[l(`n@qP`,-13,36,-29,-68)]&&t[c(1467,1561,1374,1519,`t8E7`)](i[r(0,0,`jorh`,0,511)]+`/`+e[l(`oDse`,-138,-218,-247,-218)]+l(`]OVh`,-76,-80,-30,-85))}function s(e,t,n,r,i){return I_(e- -969,r)}function c(e,t,n,r,i){return I_(e-874,i)}if(i[r(0,0,`gIrw`,0,340)]!=null){let n=e[l(`E$Om`,-266,-156,-178,-194)],r=e[l(`3oVN`,-13,-37,-142,-86)]?.[o(`Drwc`,-74)];if(n&&n[c(1477,0,0,0,`vNuK`)]!==0){let e=i[o(`mR*w`,-43)]??``,a=i[c(1534,0,0,0,`W2M1`)],u=n[s(-390,0,0,`(AAt`)](e=>M_(e)!==null);u[c(1360,0,0,0,`DzRr`)]===0?t[s(-471,0,0,`pHe*`)](l(`jOU2`,-164,-155,-10,-80)):!u[s(-315,0,0,`9wT%`)](t=>P_(t,r)&&function(e,t,n){function r(e,t,n,r,i){return y_(e-636,0,0,i)}let i=M_(e);function a(e,t,n,r,i){return y_(r-1560,0,0,n)}if(!i)return!1;function o(e,t,n,r,i){return y_(t-1670,0,0,r)}if(i[r(283,0,0,0,`ScYj`)]!==t[a(0,0,`pn*N`,1178)]()[r(261,0,0,0,`z*V%`)]())return!1;if(i[a(0,0,`Ax9E`,1166)]===`*`)return!0;let s=n[a(0,0,`^KFF`,1141)]()[o(0,1351,0,`sGCa`)]();return i[a(0,0,`D%ew`,1240)]===``?s===``:s===i[o(0,1364,0,`UJtv`)]||s[r(244,0,0,0,`7jO2`)](`.`+i[c=`b3*K`,l=833,y_(l-1228,0,0,c)]);var c,l}(t,e,a))&&t[l(`DzRr`,-2,-4,-53,-94)](o(`jOU2`,-227))}else t[l(`3]Qc`,-158,-345,-311,-237)](o(`t8E7`,-91))}function l(e,t,n,r,i){return I_(i- -761,e)}return t};function z_(e,t,n,r,i){return I_(n-581,e)}function B_(e,t,n,r,i){return I_(n-663,r)}var V_=async e=>{function t(e,t,n,r,i){return I_(e- -998,r)}let r=n.CommonUtils[l(`Iw$J`,-135,-197,-206,-149)],i=await Ie[u(75,`jorh`,52,120,18)]();function a(e,t,n,r,i){return I_(i- -595,t)}let o=Se[u(291,`A$@s`,330,255,148)](),s=new Date(o),c=new Date;function l(e,t,n,r,i){return I_(i- -840,e)}function u(e,t,n,r,i){return I_(r- -403,t)}function d(e,t,n,r,i){return I_(e-690,i)}return Math[t(-427,0,0,`Drwc`)]((c[a(0,`A$@s`,0,0,31)]()-s[l(`2PsX`,0,0,0,-257)]())/864e5)>=120&&(r=[a(0,`%ilq`,0,0,-92)]),Object[d(1198,0,0,0,`3]Qc`)]({getLicensee:()=>d(1206,0,0,0,`Wpzc`),getExpiration:()=>null,getRuntimes:()=>[],getDomains:()=>[],getDeveloperCount:()=>1,getCpuCount:()=>0,getMemory:()=>0,getType:()=>a(0,`A$@s`,0,0,1),isEval:()=>!0,getExceptions:()=>r,hasExceptions:()=>r[t(-403,0,0,`9wT%`)]>0,isValidFor:()=>r[t(-381,0,0,`W2M1`)]===0&&i,isValid:()=>!1,getFeatures:()=>Object[a(0,`(AAt`,0,0,71)]({}),getKeyFrom:()=>e,getBuildVersion:Se[a(0,`Wpzc`,0,0,-107)],getBuildDate:Se[d(1287,0,0,0,`(AAt`)]})},H_=()=>{function e(e,t,n,r,i){return I_(i-441,t)}return Object[e(0,`E$Om`,0,0,1141)]({getLicensee:()=>null,getExpiration:()=>null,getRuntimes:()=>[],getDomains:()=>[],getDeveloperCount:()=>0,getCpuCount:()=>0,getMemory:()=>0,getType:()=>null,isEval:()=>!1,getExceptions:()=>[e(0,`vNuK`,0,0,1011)],hasExceptions:()=>!0,isValidFor:e=>!1,isValid:()=>!1,getFeatures:()=>Object[e(0,`oDse`,0,0,1026)]({}),getKeyFrom:()=>I_(492,`8tX]`),getBuildVersion:Se[e(0,`I#6&`,0,0,1040)],getBuildDate:Se[e(0,`I#6&`,0,0,1079)]})},U_=async e=>{function t(e,t,n,r,i){return I_(r- -745,e)}if(W_[n=`n@qP`,r=947,I_(r-249,n)]&&W_[o(52,144,21,`3nMq`,92)])return!1;var n,r,i,a;function o(e,t,n,r,i){return I_(e- -454,r)}return!!(e[o(203,185,193,`]OVh`,182)]()||e[t(`(gmG`,0,0,-207)]()||e[i=272,a=`E#9i`,I_(i- -335,a)]()?.pb||await Ie[t(`t8E7`,0,0,-73)]())},W_={promise:null,printNeeded:!1,details:null,bannerPrinted:!1,detailsPrinted:!1,licenseKey:null,keyFrom:null},G_=!1,K_=!1;function q_(e,t,n,r,i){return I_(n-343,e)}function J_(e,t,n,r,i){return I_(n-635,t)}var Y_=new class{constructor(){function e(e,t,n,r,i){return I_(n-444,t)}this[e(0,`8tX]`,931)][e(0,`I#6&`,978)]=null}async[q_(`(gmG`,1016,991,1020,922)](e,t=!1){if(e=e?.[i(455,456,536,`W2M1`,347)](),Se[i(575,677,629,`wuL$`,568)](e))return G_=!0,await Ie[o(-99,`3nMq`,32,-54,-6)](e,t),W_[o(123,`8uf4`,27,160,116)]=null,W_[o(39,`3nMq`,145,117,55)]=a(`3nMq`,1448,1484,1470,1388),W_[o(-61,`3nMq`,17,29,-40)]=null,W_[o(177,`P6]J`,94,84,118)]=null,await this[r(706,`d8%W`,720,790,806)](!0);function n(e,t,n,r,i){return q_(t,t-457,r- -1340,r-486,i-442)}function r(e,t,n,r,i){return q_(t,t-469,e- -133,r-205,i-4)}if(G_=!1,!t&&W_[i(439,504,405,`b06(`,364)]){let e=await this[o(-18,`igRq`,-52,-65,25)]();if(e[a(`mR*w`,1419,1335,1285,1383)]()&&!e[n(0,`Wpzc`,0,-305,-233)]())return e}function i(e,t,n,r,i){return q_(r,t-22,e- -450,r-360,i-55)}function a(e,t,n,r,i){return q_(e,t-397,i-400,r-44,i-473)}function o(e,t,n,r,i){return q_(t,t-234,i- -868,r-164,i-332)}W_[a(`gIrw`,1202,1297,1244,1282)]=e,W_[a(`2PsX`,1484,1479,1376,1378)]=r(774,`Iw$J`,0,681,820),W_[i(557,453,0,`b06(`,487)]=null,W_[r(728,`2PsX`,0,659,732)]=null;let s=await this[n(0,`3Dv$`,0,-363,-256)]();if(!s[i(450,386,0,`d8%W`,498)]())throw await this[n(0,`(gmG`,0,-342,-434)](s,!0,void 0,t),Error(i(506,600,0,`%ilq`,599));return await Ie[n(0,`Wpzc`,0,-424,-395)](e,t),s}async[q_(`%ilq`,876,885,968,818)](e=!1){if(W_[n(85,122,176,`3]Qc`,205)])return W_[n(86,90,104,`jorh`,76)];function t(e,t,n,r,i){return L_(0,0,r- -214,n)}function n(e,t,n,r,i){return L_(0,0,t-281,r)}!this[n(118,57,112,`eC22`,-1)][t(0,0,`3Dv$`,-341)]&&(this[s(394,270,293,328,`I#6&`)][t(0,0,`oDse`,-421)]=Error(`FV`));let r=null;W_[n(0,198,0,`igRq`)]=new Promise(e=>{r=e});let i,a=null,o=async(e,n)=>{try{let o=function(e){let t=e,n=t[t[l(-345,`k&tU`,-408,-349,-282)]-1],r=n[l(-318,`ZS15`,-312,-356,-256)](0)-52;function i(e,t,n,r,i){return N_(t-774,0,0,i)}function a(e,t,n,r,i){return N_(e-398,0,0,i)}function o(e,t,n,r,i){return N_(e-495,0,0,i)}var s,c;function l(e,t,n,r,i){return N_(e- -561,0,0,t)}if(t=t[a(759,701,753,692,`OJGH`)](0,t[l(-272,`HTnY`,-232,-214,-270)]-1),t=t[i(0,1129,1197,0,`Ax9E`)](``)[l(-248,`ScYj`,-223,-248,-230)]()[s=1040,c=`ScYj`,N_(s-724,0,0,c)](``),t=T_(t),t=t[o(791,734,715,0,`LAF[`)](),t[t[o(820,744,817,0,`k]OD`)]-1]!==n)throw Error();t=t[i(0,1069,1056,0,`k]OD`)](0,t[i(0,1077,1147,0,`z*V%`)]-1),t=C_(t,r);try{!t[o(730,801,804,0,`k]OD`)](`{`)&&(t=`{`+t);let e=JSON[l(-251,`1%og`,-325,0,-227)](t),n={licensee:e.l,expiry:e.e,developerCount:e.dc,type:e.t,domains:e.d??[],cpuCount:e.cc??0,memory:e.m??0,features:e.f??{}};return e.n&&(n[a(678,612,653,0,`ZS15`)]=e.n),Array[l(-270,`ZS15`,-224,0,-244)](e.r)&&(n[l(-334,`k&tU`,-385,0,-278)]=e.r),n}catch{throw Error(l(-207,`Hc2*`,-185,0,-151))}}(n),s=((e,t,n)=>{function r(e,t,n,r,i){return I_(t-692,n)}function i(e,t,n,r,i){return I_(i-492,n)}function a(e,t,n,r,i){return I_(t-136,e)}function o(e,t,n,r,i){return I_(e-225,i)}function s(e,t,n,r,i){return I_(t-525,r)}return Object[i(0,0,`E$Om`,0,1192)]({getLicensee:()=>e[i(0,0,`9wT%`,0,1020)]??null,getExpiration:()=>new Date(e[o(905,0,0,0,`Fy[G`)]),getRuntimes:()=>x_(e),getDomains:()=>e[a(`jorh`,684)]??[],getDeveloperCount:()=>e[i(0,0,`E#9i`,0,1079)]??1,getCpuCount:()=>e[r(0,1348,`wuL$`)]??0,getMemory:()=>e[s(0,1184,0,`3oVN`)]??0,getType:()=>e[a(`DzRr`,814)]??i(0,0,`P6]J`,0,1145),getExceptions:()=>t,hasExceptions(){return!!t&&t[e=1259,n=`Q4DG`,s(0,e-60,0,n)]>0;var e,n},isValidFor:e=>{return!(t?.[n=438,r=`t8E7`,i(0,0,r,0,n- -609)]>0);var n,r},isValid:()=>!0,isEval:()=>!1,getFeatures:()=>Object[r(0,1325,`E$Om`)](e[a(`8uf4`,701)]??{}),getKeyFrom:()=>n,getBuildVersion:Se[a(`8uf4`,704)],getBuildDate:Se[o(825,0,0,0,`!K6n`)]})})(o,await R_(o),e);return s[r=1575,a=`vNuK`,t(0,0,a,r-1946)]()&&(i=s),s}catch{return(e=>{function t(e,t,n,r,i){return I_(n- -810,e)}function n(e,t,n,r,i){return I_(n- -809,i)}return Object[n(0,0,-273,0,`vNuK`)]({getLicensee:()=>null,getExpiration:()=>null,getRuntimes:()=>[],getDomains:()=>[],getDeveloperCount:()=>0,getCpuCount:()=>0,getMemory:()=>0,getType:()=>t(`3Dv$`,0,-179),getExceptions:()=>{return[(n=`3oVN`,r=176,t(n,0,r-434)+e+`'`)];var n,r},hasExceptions:()=>!0,isValidFor:e=>!1,isValid:()=>!1,isEval:()=>!1,getFeatures:()=>Object[n(0,0,-181,0,`wuL$`)]({}),getKeyFrom:()=>e,getBuildVersion:Se[t(`RPh*`,0,-111)],getBuildDate:Se[r=1271,i=`F5Cv`,I_(r-648,i)]});var r,i})(e)}var r,a};function s(e,t,n,r,i){return L_(0,0,r-554,i)}W_[t(0,0,`[wkw`,-498)]&&(a=await o(W_[l(806,736,815,`Rl3%`,742)],W_[l(698,750,805,`*&8y`,813)]));let c=!1;if(G_&&(c=!0,a=await V_(s(0,0,0,312,`Drwc`))),!a){let e=await Ie[t(0,0,`]OVh`,-415)]();e&&(a=await o(e[s(0,0,0,425,`W2M1`)],e[s(0,0,0,340,`RPh*`)])),!a&&(c=!0)}function l(e,t,n,r,i){return L_(0,0,t-994,r)}function u(e,t,n,r,i){return L_(0,0,i-1406,n)}return!a&&c&&(a=await V_(l(792,825,929,`jorh`,926))),!a&&i&&(a=i),!a&&(a=H_()),W_[t(0,0,`EmQk`,-360)]=a,W_[s(0,0,0,370,`3]Qc`)]=e&&await U_(a),r(a),W_[t(0,0,`mR*w`,-382)]&&await this[u(0,0,`9wT%`,0,1262)](a),W_[u(0,0,`W2M1`,0,1217)]}async[L_(0,0,-152,`jorh`)](e,t=!1,n=!1,r=!1){let i=e[a(-236,`P6]J`,-150,-136,-215)]();function a(e,t,n,r,i){return L_(0,0,i-33,t)}function o(e,t,n,r,i){return L_(0,0,t-1175,i)}if(!t&&!W_[a(0,`A$@s`,0,0,-55)]&&(e[a(0,`%ilq`,0,0,-238)]()||i))return W_[a(0,`E$Om`,0,0,-89)]=!0,void await Ie[o(0,929,0,0,`igRq`)](!1);function s(e,t,n,r,i){return L_(0,0,e-1128,r)}var c,l;(t||!t&&(i||!await Ie[s(888,0,0,`b06(`)]())&&!W_[s(1049,0,0,`[wkw`)])&&(W_[c=`igRq`,l=506,L_(0,0,l-627,c)]=!0,await Ie[o(0,912,0,0,`J(Ze`)](e,t,n,r))}async[B_(0,0,1251,`J(Ze`)](e){if(await U_(e)){if(K_)return void setTimeout(()=>{var t,n;this[t=`]OVh`,n=9,I_(n- -554,t)](e,!1,!1)},8e3);await this[t=`J(Ze`,n=-421,L_(0,0,n- -199,t)](e,!1,!1)}var t,n}async[B_(0,0,1352,`Wpzc`)](e,t,n,r=!1){if(!t&&W_[a(141,21,104,97,`wuL$`)]&&W_[a(95,79,75,25,`gIrw`)])return;let i=e[a(94,109,140,182,`Drwc`)]()||e[a(308,100,205,167,`3nMq`)]();function a(e,t,n,r,i){return J_(e-105,i,n- -1072,r-108,i-254)}function o(e,t,n,r,i){return J_(e-284,r,t- -35,r-221,i-336)}function s(e,t,n,r,i){return J_(e-188,e,i- -1286,r-416,i-236)}if(!t&&i&&!await Ie[s(`W2M1`,0,0,-60,36)]())return W_[a(5,0,80,153,`DzRr`)]=!0,W_[c=1026,l=`(AAt`,u=1096,d=1106,J_(c-105,l,c- -305,u-316,d-308)]=!0,Ie[s(`W2M1`,0,0,-74,-131)]();var c,l,u,d,f,p,m,h;(!W_[s(`jorh`,0,0,-126,-161)]||t)&&(W_[o(1035,1104,0,`mR*w`,1e3)]=!0,await Ie[a(183,0,173,201,`P6]J`)](!1)),t||!e[a(178,0,220,193,`]OVh`)]()||e[f=348,p=`(AAt`,m=221,h=304,J_(f-239,p,h- -967,m-340,h-21)]()?await this[o(1287,1284,0,`P6]J`,1379)](e,t,n,r):W_[a(212,0,141,221,`xzA@`)]=!0,!t&&i&&await Ie[o(1179,1145,0,`eC22`,1154)]()}[z_(`wuL$`,0,1267)](){return this[e=`d8%W`,t=995,z_(e,0,t- -82)](!0);var e,t}async[q_(`!K6n`,1015,918,966,958)](e){let t=await this[n=231,r=`n@qP`,i=209,a=315,J_(n-30,r,a- -928,i-29,a-190)]();var n,r,i,a,o,s,c,l;return this[o=981,s=`DzRr`,c=1077,l=993,J_(o-116,s,l- -172,c-288,l-156)](t,!0,e)}[z_(`[wkw`,0,1139)](){return W_[n=`Iw$J`,r=1532,z_(n,0,r-282)]||W_[e=`pHe*`,t=878,z_(e,0,t- -294)];var e,t,n,r}[L_(0,0,-219,`]OVh`)](e){K_=!0}async[z_(`(gmG`,0,1199)](){var e,t,n,r;W_[e=`(AAt`,t=279,L_(0,0,t-561,e)]=!0,await Ie[n=410,r=`UXT7`,L_(0,0,n-614,r)](!0)}async[L_(0,0,-100,`Iw$J`)](e,t){let n=await this[r=`3oVN`,i=28,B_(0,0,i- -1132,r)]();var r,i,a,o;return await this[a=672,o=`EmQk`,B_(0,0,a- -526,o)](n,!0,e,t),n}async[q_(`xzA@`,869,838,934,839)](){let e=await Ie[t(927,`3Dv$`,873,963,901)]();function t(e,t,n,r,i){return J_(e-27,t,n- -387,r-219,i-418)}return e[t(761,`Rl3%`,834,807,836)]?.[n=1183,r=1084,i=1192,a=`[wkw`,J_(n-94,a,r- -141,i-306,a-448)]??``;var n,r,i,a}};function X_(){let e=`v8kAcWTSra.i0WDWR7dJaHIgSoZWQPasIa.WQr8gCkIWQJdOK01W4fqcCkyWRxdImowjKdcVW.WQLvWQpcLSk8jmoSWRBcVte.WRdcGbnfW4JdHNvddG.pCkqeXRdJt7cNq.WOTramk+WRpdMKSjW7S.vYrsACkekmktWRvx.WOlcHSk8WPnuEq.WR4DWR/dG8o2W5hcKur1WO44lCoxWRhdSSomkmkHpgqsymoRhCkzC8kP.WRKCW6NdH8oIW4JcNbzyWPmYj8ox.W67dVuW6W4BdKNbfW5i7W6L7Cq.EXHlW6/cIvG.W4BdTmkxBtr9egFdNhldSSkfzq.W6/cM2KVW7ahWRq.fmoyxmohhCkseCoejK8.W5BcRmkN.W7JdQq7cVYRcHJO.WPJcR8obn3COtey.W6zeW64j.W4ldUe4JW5RdGW.W6ZcOHKmsLf6jvhcH0q2rq.W5ldRXqedSoCW5xcPG.tmkEcHf7E2q.D8obWOHPgmooW7W.W5pdRWeYdSohW5ZcSxddMuXdW7qTlq.W6e/u2DNWQWlrSofu8kx.WPnWv8o/B37dLSoalmoYqr50pmobyCkPBuW.dCkKW47dNqS.W7VdOviUW7JdNMbtW6W6W6vEyfq.WRtcJmkdW4iClW.W5FdUGad.c8k+tCo8sq.hJlcL8kNW5jCACkH.aSk7W6tdHbGj.DXpdNeHwWOWJFCoLW64MwCoTja.W7/cImkZhSoUha.lSoLc8o7ybBdTG.ErtcUmoUW7aq.kCknerBdJspcIW.EWNcVmotW6SeW6i.W7ztW7mfamkLWQO.xmknaWfKwa.W4tdKctdOGGgcmopWRZcR00.fgBcRmoFnd3cUSkGW68JWQVdJmkywa.WOlcKSkHWQPizdBcPW.W40ZuaxdRCoUW6rdku3cJG.emontSo1a8kE.W6npWP8JpmkRbCkgWORdVCo8iqaq.fMRcTmoDpsdcUSk3W7qoWRa.zWHwW6a.W4igzq3cSmoP.W5qUD8oIWRi6.W6qvWQXQ.W77cHmkRkmo+bYHJtSoJA04.WRj7hmkG.WOJcUHD1W5ldM3z4b8o7WRNcJSkwW4ddNq.hmkPumoqsbehzmk7W4LYpa.bdaKDCk1W6K.W6VdLZZdPaeDhmkDWRVcRL3dPSo3mmowmmkOytBdMW.WRf6gCo0CNu.f8kqxJFdJtpcI3mHWOOmW6Droa.WQFcLCkzumkQEe7dUCoqWOjJ.W4KUDqtdUSobW61dcuNcNSkCW4SWCmo8WOq1.f2BcRSo8ptpcVSkWW68fWRC.aI0sW4hcNLX4WQm1gq.WRxcLCkFsCkTu1K.W4erFHxcOCozf8kyj8oSW6i.h8k6W4JdNW.jKxcMbSlW5vOx8osW7aNrSoy.zMtcL8keW4HSqmoVW7OdaLqcWO3cQffaW6tdUXC.W40ZvGBdSmotW6q.W5ldJdNdRq.WRv+bmowFN7dLSoEk8o+dGb1.W75tW6KdhCkH.W4HTqCk8W7xdMmoKvIdcO8oV.WRaCW5T7BmoYrSkmWRtdOSobfWC.wrifW6ZcKL03b8oAWQaXBZ8ZWPFdKbtcG8kggG.bSkpdbldIItcQNGMWO5fW4bh.WQudWRjsx8o4W6bDDfvmWRrE.eceXvCkSW6v7nmovW6jPWQu.iK7dNMTjWRKDqW.a8khW5uwBCoCjmkPW4vzWPCDWQLF.W6ygWRLsBmoxxW.WQfzW7m0abRcUa.jxdcVrvQW4C.W6CVDSovWRq7W5q+.FSolWOHNa8ozW4Hx.dCkmW5C/BSogna.W6/cSH4O.DCoCWObTc8of.o8kuW4aYA8olmCkzW4u.DWNcSCobW7agW6O.W7hcGmkSl8oZdsf3FSoRCexcKW.d8kNW4ZdKXal.WOJcUHD1W5ldM3z4fCo/WR/cMa.W4vbD8kzsKy.WR7cLmkMx8kYx08.W5JdOXyvfCoDW5xcNKpdHq.lCoHaCo4AHRdVGRdVsnshJ4.W4erEbBcVmoOeW.W7reW6Gj.nSoLbSoXEXRdVHtdUI92ftq.eSkdW40Rz8oPjG.f2BcRSoYnYhcVSkbW7GuWQxdKmkAxW.W4T6xmkEW6JdUCoGvJ3cO8owhsO.fmkxW5i2.thRcLmkMW4TWsSk7.CCopWOTMfmosW59NoComW5LnW7O.BdDhzmkeimkbWPfaW6CWyKBdNa.W7imEHBcOmo1h8kcma.W4SKDmoG.W6DVwSk7W6/dRG.ihlcRtn/W5DJW40.W7tdU3K8W5xdMW.W6ygWRLeCmotvJJdOSo+WODB.WPOwWQtdJCoOW4e.W7zzW6OfamkN.W7r2s8k3W6/dQCoGgcRcQCo4c3mxW4musJSvnSoBWRhcIq.W7i9t0P8WPSexa.WQj/cdKQW59yB8omz8kIW4OS.WQfzWRtcKSk7o8o6.W4bfW7NcM8kJWO3dHt51WPeicSoB.W7/cK8k6d8oXcW.W5HrACkE.WQFcLCkFsSkXvutdSa.W73cPGmUrKbpouVcJhS2wa.d8ojdYblwwdcPW.W587umkY.FG5HW63cI3u4ga.W6/cTqqUv3z6p0pcI2mG.f1tdTCkaW7jP.WPewWQJdLSoVW4RcKbC.WR3dJ35QW6BdTK4.WOHNsSkJsW.W5XDASkt.jSkCW5a/qmo4W6vJomorW6S.WQldSCodW51wEa.WOxdR0RcVXBcGdFdGmkcj8ogWRPxkSoIjMdcH2pcOau.kNhcIbXXW4fOW5hdVmk7vgZdLNVdSSk2FGiEWRC0W6aF.hSk0vmo7tWe.W64tzrlcU8oVmSktpCoOW7Kxbq.W6mcWQnOymoiAI7dJ8oXWODBmW.jgFcRdr1W5zSW5ddV8kK.W7fAW6ynbmkpWQXJChjUWQbuvmoLASk0W48yWO3dVa.W6xdLmojcSoVarJcRmoCWRDrv8oiAa.WPJcMCkfW6axiG.EcbCAmkep8kx.W5RcQH00wNnToupcMW.WQ7cMSkYW78yoG.cc0lW6RcIve.b8oCw8o2bSkxdmoGmulcLMJcR8kM.e3pcR8oj.W73cHmkRc8oIaJDxEmoRCv/cHCku.nmkAeXtdLINcQv8.bYKiW6VcNLPjWRGWbea7WO0.W5RcRmkQW7VcKmkDsSo6hSoZAg3cHHldUW.ymolWOrK.WOldRHZcRGJcHIFcJ8kfj8ohW7Tnna.iCoLbSoCEXxdQa.W4rbDmkrtfC.W7JcNGBcO2VdV8k2aCkP.WQdcJmkdW4Smp8oVmmo8DuxdN8oOW5xcHG.d8oqtmoYaCkigSo7jLi.o8kEebxdGslcVM87WOfyW4Lq.W7VcGmkXbmoUhbr1y8oSA07cHa.W6NcRLBcUMhdSG.WRvsW7uWnmkcdIJdOCoMWQjOoa.g8k9W5ldMG.DbpdNg9wWO43smoLW7C6rmoMna.W5NcNL4IW7ukWRflba.WPawWR3dPSo/W4ZcLa1vWPq.W7DFWPGQ.wmo6WPpcGKbuWQRcG8k5nmoXrJ4.W7lcUSkdWOyqneylx8kgWOxcJCoX.WQnvWQ7cLmk3jCo5WO/cSsBcJq.rNNcPmktW4vP.ANZcGmkjW5fKumkMW7KequejWOZcPb5pWQhdP0hdQCoiWQ3dRJm.WRxcHSkEumk7rhVdRSoDWOLZrCoK.W45HjCogW5FcGNhcNmoqWORdRW.iCoLbSoCEXxdQcRdUYntbcGr.W40kWQ5JA8ojx3ZdG8oNWOnxjtrJW4vMWONdIq.W44KwaC.CaBdNvO.WQ3cHmkNWProst3cP244vLi.WRFdVmoaW5W.W5GUuCkGjZmCW7asB8ktWPBdG8oZ.WPldTX/cLvhdR8kRgq.cmk4W5tdSryqW7BcSa.W4NdNdpdGX8Bfq.WOlcN8kwW6umn8o3pCofFHFdOmoOW5NcJCooWRpdNq.W4PfDmkyxu3cT8oHW4rbW4bzmG.Bb7cP8oQW6SAW6i.nSoLbSo2DWa.W6jeW64khCkfWRbSEvb0WQz/vCoIzSkhW5G.WP1GbSkTWRddH0b2W4fgcSkuWONdHSowjKZcTa.WONcHhFcHa.mmkmoH7dKHxcGgS.W400sGm.W5Kczd7cRCo4e8kgpCoGW78vbq.W5GKsmkGjZe.EcbAA8kzdSktWQ9CW6SS.W5qIESoGWQGHW58V.WPC6C8kuWOJcQx7cOCoDWOa.W7DuAmkFvKS.lSk+W4ddNLKPW7hcP8k7c8ofqKJcK08O.w8k5v8o3.WQXpWOtcLSkKeSoNWOS.WPNcVG9cW4ldTgW.WPPmW7u8bWlcJ33cSXpcR8oWDW.WQ56fSo/.W4NcPSksW5BcKSkrvmoDkCoLFW.W5b+w8kxW7NdUCoGsdRcR8oYfIa.W5aIrSkKicWkW6SfFW.W652e8oJshtdIG.iwpcTH51W5bDW4VdUSk5rgZdGa.ChZcGmkjW41HrCk7W7m`.split(`.`);return(X_=function(){return e})()}var Z_=`Resource is closed.`,Q_=class{constructor(e){if(this._listeners=new Set,this._arrayBuffer=null,this._type=null,this._sourceResolved=null,this._externalURI=null,this._name=e?.name??null,this._source=e.source,!e.source)throw Error(`Source undefined`);this._refs=new Set,this._isClosed=!1}async _resolveSource(){let e=this._sourceResolved;return e||(e=this._source,typeof e==`function`&&(e=e()),e&&typeof e==`object`&&typeof e.then==`function`&&(e=await Promise.resolve(e)),this._sourceResolved=e,e)}async _resolveArrayBuffer(){let e=await this._resolveSource();if(e.base64){let t=e.base64;return n.BufferUtils.base64ToArrayBuffer(t)}if(e.fetch||e.external){let t=e.fetch??e.external,n,r,i;if(typeof t==`string`)n=t;else{let e=t;n=e.input,r=e.init,i=e.timeout}let a=i||3e4,o=new AbortController,s=setTimeout(()=>o.abort(),a);try{let e=await fetch(n,{...r,signal:o.signal});if(!e.ok)throw Error(`${e.status} ${e.statusText}`.trim());let t=await e.arrayBuffer(),i=e.headers.get(`Content-Type`);if(i){let e=await $_(t);e&&(this._type={mime:i,ext:e.ext},e.mime!==i&&console.warn(`Resource fetch detected mime type ${e.mime} does not match response mime type ${i}. Using response mime type.`))}return t}catch(e){let t=e?.name===`AbortError`?`Timed out after ${a}ms`:e.message;throw Error(`Unable to fetch '${n}'`,{cause:t})}finally{clearTimeout(s)}}if(e.buffer)return e.buffer;if(e.file)return await e.file.arrayBuffer();throw Error(`BinaryResource must have an initial data value.`)}getName(){return this._name}async toJSONAsync(){let e={},t=await this.getExternalURI();if(t)e.uri=t;else{let t=await this.toBuffer();e.base64=n.BufferUtils.arrayBufferToBase64(t)}return this._name&&(e.name=this._name),e}async toBuffer(){if(this._arrayBuffer)return this._arrayBuffer;try{this._arrayBuffer=this._resolveArrayBuffer()}catch(e){throw e}return this._arrayBuffer}async getType(){if(this._type)return this._type;let e=await $_(await this.toBuffer());return this._type=e,e}async getExternalURI(){if(this._externalURI)return this._externalURI;let e=await this._resolveSource(),t=Promise.resolve(null),n=e.fetch??e.external;if(n)if(typeof n==`string`)t=Promise.resolve(n);else{let e=n.input;typeof e==`string`?t=Promise.resolve(e):e instanceof URL?t=Promise.resolve(e.href):e instanceof Request&&(t=Promise.resolve(e.url))}return this._externalURI=t,t}addReference(e){if(this._isClosed)throw Error(Z_);this._refs.add(e)}deleteReference(e){if(this._isClosed)throw Error(Z_);if(this._refs.size===0||!this._refs.has(e))return;this._refs.delete(e);let t=this;if(this._refs.size===0){let e=this._listeners;e.forEach(n=>{n.onUnload?.(t),e.delete(n)}),this._arrayBuffer=null,this._isClosed=!0}}addUnloadListener(e){if(this._isClosed)throw Error(Z_);this._listeners.add(e)}get isIResource(){return!0}isClosed(){return this._isClosed}};async function $_(e){return function(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;if(t.length<4)return null;if(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return{mime:`image/png`,ext:`png`};if(t[0]===255&&t[1]===216&&t[2]===255)return{mime:`image/jpeg`,ext:`jpeg`};if(t[0]===71&&t[1]===73&&t[2]===70&&t[3]===56)return{mime:`image/gif`,ext:`gif`};if(t[0]===66&&t[1]===77)return{mime:`image/bmp`,ext:`bmp`};if(t[0]===73&&t[1]===73&&t[2]===42&&t[3]===0||t[0]===77&&t[1]===77&&t[2]===0&&t[3]===42)return{mime:`image/tiff`,ext:`tif`};if(t.length>=44&&t[0]===1&&t[1]===0&&t[2]===0&&t[3]===0&&t[40]===32&&t[41]===69&&t[42]===77&&t[43]===70)return{mime:`image/x-emf`,ext:`emf`};if(t[0]===215&&t[1]===205&&t[2]===198&&t[3]===154||t[0]===1&&t[1]===0&&t[2]===9&&t[3]===0)return{mime:`image/x-wmf`,ext:`wmf`};if(t.length>=100){let e=new TextDecoder(`utf-8`,{fatal:!1}).decode(t.slice(0,100));if(e.includes(`<svg`)||e.includes(`<?xml`)&&e.includes(`svg`))return{mime:`image/svg+xml`,ext:`svg`}}return null}(e)||null}var ev,tv=class{constructor(e,t,n){this._state=e,this._fromJSON=t,this._onLastEnd=n,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw Error(`PersistScope is closed.`);this._isClosed=!0,this._state.openScopes.size===0&&this._onLastEnd()}toResourceId(e){if(this._isClosed)throw Error(`PersistScope is closed.`);let t=this._state.byRefs.get(e);return t!==void 0||(t=this._state.byRefs.size,this._state.byRefs.set(e,t),this._state.byIds.set(t,e)),t}fromResourceId(e){return this._state.byIds.get(e)??null}fromJSON(e){if(this._isClosed)throw Error(`PersistScope is closed.`);if(!e||e.length===0)return;let t=this._state.byRefs.size;for(let n=0;n<e.length;n++){let r=e[n],i=this._fromJSON(r);this._state.byRefs.set(i,t+n),this._state.byIds.set(t+n,i)}}async toJSONAsync(e){if(this._isClosed)throw Error(`PersistScope is closed.`);let t=[];this._state.byRefs.forEach((n,r)=>{t[n]=e?e(r,n):r.toJSONAsync()});let n=await Promise.all(t);if(!e)return n;let r=!1;for(let e=0;e<n.length;e++)if(n[e]){r=!0;break}return r?n.map(e=>e??{}):[]}},nv=class extends S{constructor(){super(),this._persistOpen=null,this._resources=new Set}add(e){if(typeof e==`string`){let t=!1;this._resources.forEach(n=>{n.getName()===e&&(t=!0,e=n)}),t||(e=new Q_({name:e,source:{fetch:e}}))}let t;t=e instanceof Q_?e:new Q_({...e});let n=this;return this._resources.has(t)||(t.addUnloadListener({onUnload:e=>{n._resources.delete(t)&&n._notifyCollectionChange()}}),this._resources.add(t),this._notifyCollectionChange()),t}_getItems(e){return Array.from(this._resources)}getCount(){return this._resources.size}beginPersist(){this._persistOpen||={byRefs:new Map,byIds:new Map,openScopes:new Set};let e={},t=new Set,n=this;return new tv(this._persistOpen,r=>{let i=r.base64,a=r.uri,o={};i?o.base64=i:a&&(o.external=a);let s=n.add({name:r.name,source:o});return s.addReference(e),t.add(s),s},()=>{t.forEach(t=>{t.deleteReference(e)}),n._persistOpen=null})}get isIResourceCollection(){return!0}},rv=class extends S{constructor(){super(),this._persistOpen=null,this._nextId=0,this._lastReadId=-1,this._lastReadValue=null,this._stringsByText=new Map,this._stringsById=new Map}addMultiple(e,t=!1){let n=this._stringsByText,r=this._stringsById,i=e.length,a=this._nextId;for(let o=0;o<i;o++){let i=e[o];n.get(i)!==void 0&&t||(n.set(i,a),r.set(a,i),a++)}this._lastReadId=-1,a!==this._nextId&&(this._nextId=a,this._notifyCollectionChange())}add(e){let t=this._stringsByText,n=t.get(e);if(n!==void 0)return n;let r=this._nextId++;return t.set(e,r),this._stringsById.set(r,e),this._lastReadId=-1,this._notifyCollectionChange(),r}_getItems(e){if(e?.id!==void 0){let t=this.getById(e.id);return t?[t]:[]}return Array.from(this._stringsById.values())}getById(e){if(this._lastReadId===e)return this._lastReadValue;let t=this._stringsById.get(e)??null;return this._lastReadId=e,this._lastReadValue=t,t}getCount(){return this._stringsById.size}beginPersist(){this._persistOpen||={byRefs:new Map,byIds:new Map,openScopes:new Set};let e=this;return new iv(this._persistOpen,t=>(Array.isArray(t)?e.addMultiple(t):e.add(t),t),()=>{e._persistOpen=null})}get isIStringCollection(){return!0}},iv=class{constructor(e,t,n){this._state=e,this._fromJSON=t,this._onLastEnd=n,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw Error(`PersistScope is closed.`);this._isClosed=!0,this._state.openScopes.size===0&&this._onLastEnd()}add(e){if(this._isClosed)throw Error(`PersistScope is closed.`);let t=this._state.byRefs.get(e);return t!==void 0||(t=this._state.byRefs.size,this._state.byRefs.set(e,t),this._state.byIds.set(t,e)),t}at(e){return this._state.byIds.get(e)??null}fromJSON(e){if(this._isClosed)throw Error(`PersistScope is closed.`);e&&e.length!==0&&this._fromJSON(e)}toJSONAsync(){if(this._isClosed)throw Error(`PersistScope is closed.`);let e=[];return this._state.byRefs.forEach((t,n)=>{e[t]=Promise.resolve(n.toJSONAsync?n.toJSONAsync():n)}),Promise.all(e)}},av=/^(mailto|tel|sms):/i,ov=e=>av.test(e),sv=class{constructor(e,t,r){if(!r)throw new n.NullNotAllowedError;if(typeof r==`string`&&(r={address:r}),typeof r.address!=`string`)throw Error((0,n.t)(`error.hyperlink.invalidHyperlink`));this._t=e,this._r=t,this._p=r}open(e,t){return this._r(this.getAddress(),null,e??this.getTarget(),t)}getTarget(){let e=this._p.target;if(e)return e;let t=this._p.address;return t.startsWith(`#`)||ov(t)?`_self`:`_blank`}getTextToDisplay(){return this._t()||this.getAddress()}getAddress(){return this._p.address??``}getScreenTip(){return this._p.screenTip??null}get isIHyperlink(){return!0}};(ev||={}).Type={Absolute:`absolute`,OneCell:`oneCell`,TwoCell:`twoCell`};var cv,lv=class e{constructor(e){this._cacheSearchRange={colStart:0,rowStart:0,colEnd:0,rowEnd:0},this._cacheSearchFullyContained=!1,this._cacheSearchResults=null,this._init(e)}_init(e){this._options=Object.freeze({getEntireCoords:NH,...e}),this._isEmpty=!0;let t=e.shiftEntry,n=e.isSplittable??!0;this._spatial=new yr(t||!n?{updateEntryOptions:{isSplittable:n,getShifted:t?(e,n,r)=>{let i=t(e.value.model,r);return i===void 0?n:i===null?null:{...n??e,...i}}:void 0}}:void 0),this._mapModelToEntries=new Map,this._setIndexToModel([]),this._mapNameToModel=new Map,this._nextOrder=0,this._createEntry=null,this._mapModelToMeta=new Map}_allocateOrder(){let e=this._nextOrder;return this._nextOrder=e+dv,e}_createSpatialEntry(e,t){let n=(this._createEntry??yv)(e,t);return n.order=this._allocateOrder(),n.orderSpan=dv,n.getSplit||=mv,n.copyTo||=hv,{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,value:n}}_entriesOf(e){return this._mapModelToEntries.get(e)??n.CommonUtils.EmptyArray}all(){return this._indexToModel}_setIndexToModel(e){this._indexToModel=Object.freeze(e)}search(e,t=!1,r,i){if(this._isEmpty)return i??n.CommonUtils.EmptyArray;let a=this._cacheSearchRange,o=this._cacheSearchResults;if(o!==null&&n.CoordUtils.isEqualRanges(e,a)&&t===this._cacheSearchFullyContained||(this._cacheSearchFullyContained=t,a.colStart=e.colStart,a.rowStart=e.rowStart,a.colEnd=e.colEnd,a.rowEnd=e.rowEnd,o=this._searchModels(e,t),this._cacheSearchResults=o),!i)return o;let s=o.length;for(let e=0;e<s;e++)i.push(o[e]);return i}_searchModels(e,t){let r=this._spatial.search(e,t),i=r.length;if(i===0)return n.CommonUtils.EmptyArray;let a=this._mapModelToMeta,o=i>1?[...r].sort((e,t)=>{let n=a.get(e.value.model).index,r=a.get(t.value.model).index;return n===r?e.value.order-t.value.order:n-r}):r,s=Array(i);for(let e=0;e<i;e++){let t=o[e];s[e]={...t,value:t.value.model}}return s}getByName(e){if(this._isEmpty)return null;let t=e.toLocaleLowerCase();return this._mapNameToModel.get(t)??null}setName(e,t){let n=this._mapModelToMeta,r=n.get(e);if(!r)return this;let i=new Map(n),a=new Map(this._mapNameToModel),o=r?.name;o&&a.delete(o.toLocaleLowerCase());let s={...r};s.name=t,i.set(e,s);let c=t.toLocaleLowerCase();a.set(c,e);let l=this._shallowClone();return l._mapNameToModel=a,l._mapModelToMeta=i,l}getByIndex(e){return this._isEmpty?null:this._indexToModel[e]||null}setIndex(e,t){let n=this._indexToModel,r=n.length;t<0?t=0:t>r-1&&(t=r-1);let i=this._mapModelToMeta,a=i.get(e);if(a.index===t)return this;let o=[...n],s=new Map(i),c=a.index;o.splice(c,1),o.splice(t,0,e);let l=Math.min(c,t);this._reIndexMeta(o,s,l);let u=this._shallowClone();return u._mapModelToMeta=s,u._setIndexToModel(o),u}getIndex(e){let t=this._mapModelToMeta.get(e);return t?t.index:-1}getCoords(e){let t=this._entriesOf(e);return t.length===0?null:n.CoordUtils.sanitizeRangeArray(t)}setCoords(e,t){let r=this._mapModelToEntries,i=this._entriesOf(e);if(i.length===0)return this;let a=t?t.length:0;if(a===0)return this.deleteModel(e);let o=this._spatial.clone(),s=i.length;for(let e=0;e<s;e++)o.remove(i[e],fv);let c=this._shallowClone(),l=Array(a);for(let n=0;n<a;n++)l[n]=c._createSpatialEntry(e,t[n]);o.load(l);let u=new Map(r);u.set(e,l),c._spatial=o,c._mapModelToEntries=u;let d=n.CoordUtils.sanitizeRangeArray(i),f=n.CoordUtils.sanitizeRangeArray(l);return vv(d,f)||this._mapModelToMeta.get(e)?.callbacks?.processAfterShift?.(d,f),c}clone(){let t=new e(n.CommonUtils.EmptyObject);return t._options=this._options,t._spatial=this._spatial.clone(),t._mapModelToEntries=new Map(this._mapModelToEntries),t._mapModelToMeta=new Map(this._mapModelToMeta),t._mapNameToModel=new Map(this._mapNameToModel),t._setIndexToModel([...this._indexToModel]),t._isEmpty=this._isEmpty,t._nextOrder=this._nextOrder,t._createEntry=this._createEntry,t}size(){return this._mapModelToEntries.size}isEmpty(){return this._isEmpty}has(e){return!this._isEmpty&&this._spatial.has(e)}shift(e){if(this._isEmpty)return this;let t=e?.ranges,r=e?.direction,i=e?.coordValidator,a=t.length,o=this._spatial,s=o,c=this._mapModelToEntries,l=c,u=this._mapModelToMeta,d=u,f=this._mapNameToModel,p=f,m=new Set,h=new Map,g=e=>{let t=h.get(e);return t||(t=[...c.get(e)??n.CommonUtils.EmptyArray],h.set(e,t)),t},_=(e,t)=>{let n=t?t.length:0;for(let e=0;e<n;e++){let n=t[e],r=n.value.model;m.add(r);let i=g(r),a=i.indexOf(n);a>=0&&i.splice(a,1)}let r=e?e.length:0;for(let t=0;t<r;t++){let n=e[t],r=n.value.model;m.add(r),g(r).push(n)}},v=e=>{let t=e.before.value.model;m.add(t),u.get(t)?.callbacks?.processShift?.(e)};for(let e=0;e<a;e++){let n=t[e];s=s.shift({range:n,direction:r,cloneIfUpdate:s===o,coordValidator:i,onShift:v,onUpdates:_})}if(m.size===0)return this;l=new Map(c),d=new Map(u),p=new Map(f);let y=[...this._indexToModel];this._applyEntryDeltas(h,c,l,d,p,y);let b=this._shallowClone();return b._spatial=s,b._mapModelToEntries=l,b._mapNameToModel=p,b._setIndexToModel(y),b._mapModelToMeta=d,b._isEmpty=l.size===0,b}copyTo(e,t,r){if(this._isEmpty||e.colIndex===t.colStart&&e.rowIndex===t.rowStart)return this;let i={colStart:e.colIndex,rowStart:e.rowIndex,colEnd:e.colIndex+(t.colEnd-t.colStart),rowEnd:e.rowIndex+(t.rowEnd-t.rowStart)},a=this._spatial.createCopiedEntries(t,i).inserts;if(a.length===0)return this;let o=this._mapModelToEntries,s=new Map,c=e=>{let t=s.get(e);return t||(t=[...o.get(e)??n.CommonUtils.EmptyArray],s.set(e,t)),t},l=e=>{let t=c(e.value.model),n=t.indexOf(e);n>=0&&t.splice(n,1)},u=this._shallowClone(),d=this._spatial.clone();if(r)if(this._options.isSplittable??1)d.insertNonOverlapping({...t,value:null},{onUpdates:(e,t)=>{let n=t?t.length:0;for(let e=0;e<n;e++)l(t[e]);let r=e?e.length:0;for(let t=0;t<r;t++)c(e[t].value.model).push(e[t])}});else{let e=new Set;for(let t=0;t<a.length;t++)e.add(a[t].value);let n=this._spatial.search(t);for(let t=0;t<n.length;t++){let r=n[t];e.has(r.value)&&(d.remove(r,fv),l(r))}}for(let e=0;e<a.length;e++){let t=a[e];r||(t={...t,value:{...t.value,order:u._allocateOrder(),orderSpan:dv}},a[e]=t),c(t.value.model).push(t)}d.load(a);let f=new Map(o),p=new Map(this._mapModelToMeta),m=new Map(this._mapNameToModel),h=[...this._indexToModel];return this._applyEntryDeltas(s,o,f,p,m,h),u._spatial=d,u._mapModelToEntries=f,u._mapNameToModel=m,u._setIndexToModel(h),u._mapModelToMeta=p,u._isEmpty=f.size===0,u}_applyEntryDeltas(e,t,r,i,a,o){let s=2**53-1;e.forEach((e,c)=>{let l=i.get(c);if(!l)return;let u=t.get(c),d=u?n.CoordUtils.sanitizeRangeArray(u):null,f;if(e.length===0){f=null,r.delete(c),i.delete(c);let e=l.name;e&&a.delete(e.toLocaleLowerCase()),s=Math.min(s,l.index),o[l.index]=null}else e.sort(pv),r.set(c,e),f=n.CoordUtils.sanitizeRangeArray(e);vv(d,f)||l.callbacks.processAfterShift?.(d,f),f||l.callbacks.processDelete?.()}),s!==2**53-1&&this._reIndexMeta(o,i,s,!0)}deleteRanges(e,t=!1){if(this._isEmpty)return this;let n=this._spatial,r=e.length,i=[];for(let a=0;a<r;a++){let r=e[a];n.search(r,t,!1,i)}if(i.length===0)return this;let a=this._shallowClone(),o=this._spatial.clone(),s=this._mapModelToEntries,c=new Map(s),l=new Map(this._mapNameToModel),u=new Map(this._mapModelToMeta),d=[...this._indexToModel],f=new Map,p=i.length;for(let e=0;e<p;e++){let t=i[e],n=t.value.model,r=f.get(n);r||(r=new Set,f.set(n,r)),r.add(t),o.remove(t,fv)}let m=new Map;return f.forEach((e,t)=>{let n=s.get(t);n&&m.set(t,n.filter(t=>!e.has(t)))}),this._applyEntryDeltas(m,s,c,u,l,d),a._spatial=o,a._mapModelToEntries=c,a._mapNameToModel=l,a._setIndexToModel(d),a._mapModelToMeta=u,a._isEmpty=c.size===0,a}_reIndexMeta(e,t,n=0,r=!1){if(r)for(let t=e.length-1;t>=n;t--)e[t]||e.splice(t,1);let i=e.length;for(let r=n;r<i;r++){let n=e[r],i=t.get(n);if(i.index===r)continue;let a={...i};a.index=r,t.set(n,a)}}deleteModel(e){if(this._isEmpty)return this;let t=new Map(this._mapModelToEntries),n=this._mapNameToModel,r=new Map(this._mapModelToMeta),i=r.get(e);i.callbacks.processDelete?.();let a=i?.name;a&&(n=new Map(n),n.delete(a.toLocaleLowerCase()));let o=t.get(e),s=o?o.length:0,c=this._spatial;if(o&&s>0){c=this._spatial.clone();for(let e=0;e<s;e++){let t=o[e];c.remove(t,fv)}}r.delete(e),t.delete(e);let l=[...this._indexToModel],u=i.index;l[u]=null,this._reIndexMeta(l,r,u,!0);let d=this._shallowClone();return d._spatial=c,d._mapModelToEntries=t,d._mapNameToModel=n,d._mapModelToMeta=r,d._setIndexToModel(l),d._isEmpty=t.size===0,d}_onLoadFailure(e,t){let r=t?.message??(t?String(t):void 0);if(uv)throw Error(r?`${e} ${r}`:e);n.Notifier.warn(e,{meta:{type:`error`,detail:r}})}load(e,t){let r=e?e.length:0;if(r===0)return this;let i=this._options.getRanges,a=this._options.getEntireRange,o=t.createModel,s=t.addListeners,c=t.setContainerCoords,l=t.setContainerName,u=t.setContainerIndex,d=t.getContainerIndex,f=t.deleteFromContainer,p=t.invalidate,m=new Map(this._mapModelToEntries),h=new Map(this._mapModelToMeta),g=new Map(this._mapNameToModel),_=[],v=this._shallowClone();v._createEntry=t.createEntry??this._createEntry;let y=(e,t,r)=>{let m={model:null,callbacks:n.CommonUtils.EmptyObject,name:null,index:t},h,g=null,_=e,y=!1,b={getRanges:i,getEntireRange:a,invalidate:p,setContainerCallbacks:e=>{if(g)throw Error(`Cannot set container callbacks after model creation.`);m.callbacks={...m.callbacks,...e}},setContainerCoords:(e,t)=>{let n=i(e).getCoords();if(g)return c?.(g,n,t),n;_=[...n]},setContainerName:(e,t)=>{g?l?.(g,e,t):m.name=e},setContainerIndex:(e,t)=>{if(!g)throw Error(`Cannot set container index curring initializations.`);u?.(g,e,t)},getContainerIndex:()=>g?d?.(g):m.index,deleteFromContainer:e=>{g?(f?.(g,e),h?.()):y=!0},coords:e,json:r};if(y)return null;if(g=o(b),m.model=g,!m.name){let e=g.getName?.();e&&(m.name=e)}m.index;let x=[],S=_.length;for(let e=0;e<S;e++)x.push(v._createSpatialEntry(g,_[e]));return s&&(h=s(g)),{entries:x,meta:m}},b=[...this._indexToModel],x=b.length,S=a().getCoords();for(let t=0;t<r;t++){let n=e[t],r=Wd(n,S);if(!r){this._onLoadFailure(`Invalid ref '${n?.r}'.`,null);continue}let i;try{i=y(r.coords,t+x,r.value)}catch(e){this._onLoadFailure(`Unable to load anchored item at '${n?.r}'.`,e)}if(!i)continue;let a=i.entries,o=i.meta,s=o.model;m.set(s,a);let c=o.name;c&&g.set(c.toLocaleLowerCase(),s),h.set(s,o),b.push(s);let l=a.length;for(let e=0;e<l;e++)_.push(a[e])}let C=this._spatial.clone();return C.load(_),v._spatial=C,v._mapModelToEntries=m,v._mapNameToModel=g,v._mapModelToMeta=h,v._setIndexToModel(b),v._isEmpty=m.size===0,v}getBoundingRange(){return this._spatial.getBoundingRange()}toJSON(){let e=this.all(),t=e.length;if(t===0)return null;let n=this._options.getEntireRange().getCoords(),r=[];for(let i=0;i<t;i++){let t=e[i];if(t.toJSON===void 0)continue;let a=this._entriesOf(t);if(a.length===0)continue;let o=t.toJSON();r.push({r:$d(a,n),v:o})}return r}processCallbacks(e){this._mapModelToMeta.forEach((t,n)=>{e(n,t.callbacks)})}close(){let e=this._mapModelToMeta.keys();for(let t of e)t.close()}_shallowClone(){let t=new e(n.CommonUtils.EmptyObject);return t._options=this._options,t._spatial=this._spatial,t._mapModelToEntries=this._mapModelToEntries,t._mapModelToMeta=this._mapModelToMeta,t._mapNameToModel=this._mapNameToModel,t._indexToModel=this._indexToModel,t._isEmpty=this._isEmpty,t._nextOrder=this._nextOrder,t._createEntry=this._createEntry,t}},uv=!1;(cv=lv||={}).setStrictLoad=function(e){uv=e},cv.isStrictLoad=function(){return uv};var dv=1024,fv=(e,t)=>{let n=e.value,r=t.value;return n.model===r.model&&n.order===r.order},pv=(e,t)=>e.value.order-t.value.order;function mv(e,t,n){let r=this.order,i=this.orderSpan,a=i/2>0?i/2:0;return[{...this,order:r,orderSpan:a},{...this,order:r+a,orderSpan:i-a}]}function hv(e){return{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:this}}var gv,Y,_v,vv=(e,t)=>{let r=e?e.length:0;if(r!==(t?t.length:0))return!1;for(let i=0;i<r;i++)if(!n.CoordUtils.isEqualRanges(e[i],t[i]))return!1;return!0},yv=(e,t)=>({model:e,order:0,orderSpan:dv}),bv=class{constructor(e){this._subscriptions=[],this._getSheets=e.getSheets,this._addSheetsListener=e.addSheetsListener??null}getItems(){this._syncSubscriptions();let e=this._getSheets()??n.CommonUtils.EmptyArray,t=e.length;if(t===0)return n.CommonUtils.EmptyArray;let r=null;for(let i=0;i<t;i++){let t=e[i]?.getTables().getItems()??n.CommonUtils.EmptyArray,a=t.length;for(let e=0;e<a;e++){let n=t[e]?.getNamed?.();n&&(r||=[],r.push(n))}}return r??n.CommonUtils.EmptyArray}addListeners(e,t){let r=()=>{e.onCollectionChange?.()},i={notify:r,notifyInvalidated:()=>{e.onInvalidated?.()},sheets:n.CommonUtils.EmptyArray,removes:[],options:t};this._subscriptions.push(i),this._syncSubscription(i);let a=this._addSheetsListener?.(()=>{this._syncSubscription(i),r()},t);return()=>{for(let e=0;e<i.removes.length;e++)i.removes[e]?.();i.removes=[],i.sheets=n.CommonUtils.EmptyArray,this._subscriptions=this._subscriptions.filter(e=>e!==i),a?.()}}_syncSubscription(e){let t=this._getSheets()??n.CommonUtils.EmptyArray,r=e.sheets;if(t.length===r.length){let e=!0;for(let n=0;n<t.length;n++)if(t[n]!==r[n]){e=!1;break}if(e)return}for(let t=0;t<e.removes.length;t++)e.removes[t]?.();e.removes=[],e.sheets=t;for(let n=0;n<t.length;n++){let r=t[n];r&&e.removes.push(r.addListeners({onTablesChange:e.notify,onInvalidated:e.notifyInvalidated},e.options))}}_syncSubscriptions(){for(let e=0;e<this._subscriptions.length;e++)this._syncSubscription(this._subscriptions[e])}};(gv||={}).Feature={Contentful:`contentful`,DateFormat:`dateFormat`,Error:`error`,Formula:`formula`,Spills:`spills`,CalcError:`calcError`,Circular:`circular`,Fill:`fill`,Borders:`borders`,NumberFormat:`numberFormat`,Alignment:`alignment`,Font:`font`,Protection:`protection`,Merge:`merge`,Table:`table`,AutoTable:`autoTable`,Hyperlink:`hyperlink`,Comments:`comments`,Unlock:`unlock`,Conditionals:`conditionals`,DataValidations:`dataValidations`},(_v=Y||={}).BuiltInSelectorNames={List:`list`,Logical:`logical`,Date:`date`,DateTime:`dateTime`,Time:`time`,Text:`text`,TextLength:`textLength`,Number:`number`,Whole:`wholeNumber`},_v.BuiltInOperatorNames={And:`and`,Average:`average`,Between:`between`,Color:`color`,EqualTo:`equalTo`,GreaterThan:`greaterThan`,GreaterThanEqualTo:`greaterThanEqualTo`,LessThan:`lessThan`,LessThanEqualTo:`lessThanEqualTo`,After:`after`,AfterEqualTo:`afterEqualTo`,Before:`before`,BeforeEqualTo:`beforeEqualTo`,Unique:`unique`,Blank:`blank`,Error:`error`,InSet:`inSet`,Icon:`icon`,Not:`not`,TextEmail:`textEmail`,TextIsUrl:`textUrl`,TextStartsWith:`textStartsWith`,TextEndsWith:`textEndsWith`,TextContains:`textContains`,Expression:`expression`,TimePeriod:`timePeriod`,TopN:`topN`,Or:`or`},_v.AverageType={Above:`above`,Below:`below`,AboveOrEqual:`aboveOrEqual`,BelowOrEqual:`belowOrEqual`},_v.TimePeriodType={Last7Days:`last7Days`,LastMonth:`lastMonth`,LastQuarter:`lastQuarter`,LastWeek:`lastWeek`,LastYear:`lastYear`,M1:`M1`,M2:`M2`,M3:`M3`,M4:`M4`,M5:`M5`,M6:`M6`,M7:`M7`,M8:`M8`,M9:`M9`,M10:`M10`,M11:`M11`,M12:`M12`,NextMonth:`nextMonth`,NextQuarter:`nextQuarter`,NextWeek:`nextWeek`,Null:`null`,Q1:`Q1`,Q2:`Q2`,Q3:`Q3`,Q4:`Q4`,ThisMonth:`thisMonth`,ThisQuarter:`thisQuarter`,ThisWeek:`thisWeek`,Today:`today`,Tomorrow:`tomorrow`,YearToDate:`yearToDate`,Yesterday:`yesterday`},_v.DateItemGroupingType={Day:`day`,Hour:`hour`,Minute:`minute`,Month:`month`,Second:`second`,Year:`year`},Ai();var xv=class{constructor(e){this._name=e.name,this._title=e.title,this._description=e.description,e.acceptTypes&&e.acceptTypes.length>0?this._acceptTypes=Object.freeze([...e.acceptTypes]):this._acceptTypes=null,this._paramType=e.paramType}getName(){return this._name}getAcceptsTypes(){return this._acceptTypes}acceptsList(){return!1}getParamType(e){if(this._paramType!==void 0)return this._paramType;if(e)return e.getName();let n=this._acceptTypes;if(!n)return null;for(let e of n)switch(e){case t.InteropScalarType.Number:return`number`;case t.InteropScalarType.String:return`text`;case t.InteropScalarType.Date:return`dateTime`;case t.InteropScalarType.Boolean:return`logical`}return null}isCombinator(){return!1}createDefaultParam(e){return null}getTitle(){return this._title?(0,n.t)(this._title):n.CommonUtils.camelToPrettyCase(this.getName())}getDescription(){return this._description?(0,n.t)(this._description):null}doBatch(e,t,n){return null}async _resolveOperand(e,r){let i;if(e?.isIFormula)i=e;else{if(typeof e!=`string`||!e.startsWith(`=`))return()=>e;i=e.slice(1)}let a=typeof i==`string`?i:i.getExpression(),o=await r.watchFormula(i);if(!o)return null;let s=r.getCoords(),c=!1,l=this.getName();return e=>{let r=e.getPosition(),i;try{i=o.getValueAt(r.rowIndex-s.rowStart,r.colIndex-s.colStart)}catch(e){if(!t.FormulaError.isError(e))throw e;i=e}return t.FormulaError.isError(i)&&!c&&(c=!0,n.Notifier.warn(`Condition operand '=${a}' resolves to ${i.getLabel()}; '${l}' matches nothing there.`,{onceKey:`condition.operand.error.${a}`,meta:{type:`condition`}})),i}}_isMissingOperand(e){return e==null||typeof e==`string`&&e.trim().length===0}_validateOperand(e,r,i=!1){if(i?e==null:this._isMissingOperand(e))return(0,n.messageKey)(`condition.error.operandRequired`);if(e?.isIFormula)return e.isValid()?null:(0,n.messageKey)(`condition.error.formulaInvalid`);if(typeof e==`string`&&e.startsWith(`=`)||!r||t.FormulaError.isError(e))return null;let a=r.getName(),o=Y.BuiltInSelectorNames,s=a===o.Date||a===o.DateTime||a===o.Time;return r.getSelectType()!==t.InteropScalarType.Number&&r.getSelectType()!==t.InteropScalarType.Date?null:typeof e==`number`?a!==o.Whole||Number.isInteger(e)?a===o.TextLength&&(!Number.isInteger(e)||e<0)?(0,n.messageKey)(`condition.error.textLength`):a===o.Time&&(e<0||e>=1)?(0,n.messageKey)(`condition.error.timeRequired`):s&&e<0?(0,n.messageKey)(`condition.error.dateRequired`):null:(0,n.messageKey)(`condition.error.wholeNumber`):a===o.Time?(0,n.messageKey)(`condition.error.timeRequired`):s?(0,n.messageKey)(`condition.error.dateRequired`):(0,n.messageKey)(`condition.error.numberRequired`)}async _createComparePredicate(e,n,r){if(this._isMissingOperand(e))return null;let i=await this._resolveOperand(e,n);return i?(e,n)=>{let a=i(n);return!t.FormulaError.isError(a)&&r(e,a)}:null}toString(e,t){let r=this.getTitle(),i=e;return i==null?r:(0,n.t)(`condition.operator.titleWithParam`,{title:r,param:i})}},Sv=()=>!1,Cv=class e{constructor(e,t,n,r,i,a,o){this._groups=e,this._keyFn=t,this._compareFn=n,this._reverseBuild=r,this._visitedCount=i,this._totalCount=a,this._truncated=o}*getUniqueValues(){let e=this._groups,t=this._getValueOrderAscending();if(this._reverseBuild)for(let n=t.length-1;n>=0;n--)yield e.get(t[n]).value;else for(let n=0;n<t.length;n++)yield e.get(t[n]).value}getFrequency(e){return this._groups.get(this._keyFn(e))?.count??0}*getValueCounts(e){let t=this._groups,n=e?.sortBy??`frequency`,r=e?.descending??!0,i;if(n===`value`)i=this._getValueOrderAscending().slice(),r&&i.reverse();else{let e=r?-1:1;i=Array.from(t.keys()),i.sort((n,r)=>e*(t.get(n).count-t.get(r).count))}for(let e=0;e<i.length;e++){let n=t.get(i[e]);yield[n.value,n.count]}}getUniqueCount(){return this._groups.size}getVisitedCount(){return this._visitedCount}getTotalCount(){return this._totalCount}isTruncated(){return this._truncated}getExtent(e){let t=this._groups.get(this._keyFn(e))?.extent;return t?{...t}:null}_getValueOrderAscending(){let e=this._valueOrderAscending;if(!e){let t=this._groups,n=this._compareFn,r=Array.from(t.keys());r.sort((e,r)=>n(t.get(e).value,t.get(r).value)),e=Object.freeze(r),this._valueOrderAscending=e}return e}static fromGrid(n,r,i,a,o,s,c,l){let u=a?.keyFn??wv,d=a?.filterFn,f=a?.limit,p=new Map,m=0,h=!1;if(n.getCount()!==0){let e=n.getAxis()===t.IRange.Axis.Column,a=r.length,o=uU(i,e,l),s=o?.major??null,c=o?.minor??null,g=i?{...Ev,...i}:Ev,_=g.bounds;t:for(let t=0;t<a;t++){let i=r[t];if(!i)continue;let a=e?i.colStart:i.rowStart,o=e?i.rowStart:i.colStart,l=e?i.colEnd:i.rowEnd,v=e?i.rowEnd:i.colEnd;_.colStart=e?a:o,_.rowStart=e?o:a,_.colEnd=e?l:v,_.rowEnd=e?v:l;let y=n.getRuns(g),b=y.next();for(;!b.done;){let[t,n,r]=b.value;if(b=y.next(),s&&dU(s,t))continue;let i=r.length,a=Math.max(0,o-n),l=Math.min(i-1,v-n);if(!(a>l))for(let i=a;i<=l;i++){if(c){let e=fU(c,n+i)-n;if(e!==i){e>i&&(i=e-1);continue}}let a=r.at(i);if(d&&!d(a))continue;let o=n+i,s=e?o:t,l=e?t:o,g=u(a),_=p.get(g);if(_){_.count++;let e=_.extent;s<e.rowStart?e.rowStart=s:s>e.rowEnd&&(e.rowEnd=s),l<e.colStart?e.colStart=l:l>e.colEnd&&(e.colEnd=l)}else{if(f!==void 0&&p.size>=f){h=!0;break t}p.set(g,{value:a,count:1,extent:{rowStart:s,colStart:l,rowEnd:s,colEnd:l}})}m++}}}}return s>0&&p.set(u(null),{value:null,count:s}),new e(p,u,a?.compareFn??o,a?.reverse??!1,m,c??m+s,h)}static fromGroups(t,n,r,i,a,o,s){return new e(t,n,r?.compareFn??i,r?.reverse??!1,a,o,s)}};function wv(e){if(e===null)return`\0`;let n=typeof e;return n===`number`?``+e.toString():n===`string`?``+ia(e):n===`boolean`?``+(e?`1`:`0`):t.FormulaError.isError(e)?``+e.getCode():``+String(e)}var X,Tv,Ev={bounds:{colStart:0,rowStart:0,colEnd:0,rowEnd:0},overflowRun:!0};(Tv=X||={}).MAX_EXPRESSION_LENGTH=8192,Tv.Status={Running:`running`,Error:`error`,Starting:`starting`,Stopping:`stopping`,Off:`off`},Tv.CalculationState={Done:`done`,Calculating:`calculating`,Pending:`pending`},Tv.CalculationMode={Automatic:`auto`,Manual:`manual`,AutomaticExceptTables:`automaticExceptTables`},Tv.ResultStatus={Ready:`ready`,Stale:`stale`,Pending:`pending`,Streaming:`streaming`};var Z={Unparsed:`unparsed`,Paren:`paren`,Infix:`infix`,Prefix:`prefix`,Postfix:`postfix`,Function:`function`,Call:`call`,Error:`error`,Number:`number`,Boolean:`boolean`,String:`string`,Separator:`separator`,List:`list`,Type:`type`,Array:`array`,Row:`row`,Cell:`cell`,Named:`named`,Parameter:`parameter`,TableReference:`tableReference`,TableSpecifier:`tableSpecifier`,TableColumn:`tableColumn`,ExternalReference:`externalReference`,Empty:`empty`,Whitespace:`whitespace`};function Dv(e){console&&console.error&&console.error(`Error: ${e}`)}function Ov(e){console&&console.warn&&console.warn(`Warning: ${e}`)}function kv(e){let t=new Date().getTime(),n=e();return{time:new Date().getTime()-t,value:n}}function Av(e){function t(){}t.prototype=e;let n=new t;function r(){return typeof n.bar}return r(),r(),e}var jv=class{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){this._definition=e}accept(e){e.visit(this),this.definition.forEach(t=>{t.accept(e)})}},Mv=class extends jv{constructor(e){super([]),this.idx=1,Object.assign(this,Uv(e))}set definition(e){}get definition(){return this.referencedRule===void 0?[]:this.referencedRule.definition}accept(e){e.visit(this)}},Nv=class extends jv{constructor(e){super(e.definition),this.orgText=``,Object.assign(this,Uv(e))}},Pv=class extends jv{constructor(e){super(e.definition),this.ignoreAmbiguities=!1,Object.assign(this,Uv(e))}},Fv=class extends jv{constructor(e){super(e.definition),this.idx=1,Object.assign(this,Uv(e))}},Iv=class extends jv{constructor(e){super(e.definition),this.idx=1,Object.assign(this,Uv(e))}},Lv=class extends jv{constructor(e){super(e.definition),this.idx=1,Object.assign(this,Uv(e))}},Rv=class extends jv{constructor(e){super(e.definition),this.idx=1,Object.assign(this,Uv(e))}},zv=class extends jv{constructor(e){super(e.definition),this.idx=1,Object.assign(this,Uv(e))}},Bv=class extends jv{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){super(e.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Object.assign(this,Uv(e))}},Vv=class{constructor(e){this.idx=1,Object.assign(this,Uv(e))}accept(e){e.visit(this)}};function Hv(e){function t(e){return e.map(Hv)}if(e instanceof Mv){let t={type:`NonTerminal`,name:e.nonTerminalName,idx:e.idx};return typeof e.label==`string`&&(t.label=e.label),t}if(e instanceof Pv)return{type:`Alternative`,definition:t(e.definition)};if(e instanceof Fv)return{type:`Option`,idx:e.idx,definition:t(e.definition)};if(e instanceof Iv)return{type:`RepetitionMandatory`,idx:e.idx,definition:t(e.definition)};if(e instanceof Lv)return{type:`RepetitionMandatoryWithSeparator`,idx:e.idx,separator:Hv(new Vv({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof zv)return{type:`RepetitionWithSeparator`,idx:e.idx,separator:Hv(new Vv({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof Rv)return{type:`Repetition`,idx:e.idx,definition:t(e.definition)};if(e instanceof Bv)return{type:`Alternation`,idx:e.idx,definition:t(e.definition)};if(e instanceof Vv){let t={type:`Terminal`,name:e.terminalType.name,label:(n=e.terminalType,typeof(r=n).LABEL==`string`&&r.LABEL!==``?n.LABEL:n.name),idx:e.idx};typeof e.label==`string`&&(t.terminalLabel=e.label);let i=e.terminalType.PATTERN;return e.terminalType.PATTERN&&(t.pattern=i instanceof RegExp?i.source:i),t}if(e instanceof Nv)return{type:`Rule`,name:e.name,orgText:e.orgText,definition:t(e.definition)};throw Error(`non exhaustive match`);var n,r}function Uv(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}var Wv=class{visit(e){let t=e;switch(t.constructor){case Mv:return this.visitNonTerminal(t);case Pv:return this.visitAlternative(t);case Fv:return this.visitOption(t);case Iv:return this.visitRepetitionMandatory(t);case Lv:return this.visitRepetitionMandatoryWithSeparator(t);case zv:return this.visitRepetitionWithSeparator(t);case Rv:return this.visitRepetition(t);case Bv:return this.visitAlternation(t);case Vv:return this.visitTerminal(t);case Nv:return this.visitRule(t);default:throw Error(`non exhaustive match`)}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}};function Gv(e,t=[]){return e instanceof Fv||e instanceof Rv||e instanceof zv||(e instanceof Bv?e.definition.some(e=>Gv(e,t)):!(e instanceof Mv&&t.includes(e))&&e instanceof jv&&(e instanceof Mv&&t.push(e),e.definition.every(e=>Gv(e,t))))}function Kv(e){if(e instanceof Mv)return`SUBRULE`;if(e instanceof Fv)return`OPTION`;if(e instanceof Bv)return`OR`;if(e instanceof Iv)return`AT_LEAST_ONE`;if(e instanceof Lv)return`AT_LEAST_ONE_SEP`;if(e instanceof zv)return`MANY_SEP`;if(e instanceof Rv)return`MANY`;if(e instanceof Vv)return`CONSUME`;throw Error(`non exhaustive match`)}var qv=class{walk(e,t=[]){e.definition.forEach((n,r)=>{let i=e.definition.slice(r+1);if(n instanceof Mv)this.walkProdRef(n,i,t);else if(n instanceof Vv)this.walkTerminal(n,i,t);else if(n instanceof Pv)this.walkFlat(n,i,t);else if(n instanceof Fv)this.walkOption(n,i,t);else if(n instanceof Iv)this.walkAtLeastOne(n,i,t);else if(n instanceof Lv)this.walkAtLeastOneSep(n,i,t);else if(n instanceof zv)this.walkManySep(n,i,t);else if(n instanceof Rv)this.walkMany(n,i,t);else{if(!(n instanceof Bv))throw Error(`non exhaustive match`);this.walkOr(n,i,t)}})}walkTerminal(e,t,n){}walkProdRef(e,t,n){}walkFlat(e,t,n){let r=t.concat(n);this.walk(e,r)}walkOption(e,t,n){let r=t.concat(n);this.walk(e,r)}walkAtLeastOne(e,t,n){let r=[new Fv({definition:e.definition})].concat(t,n);this.walk(e,r)}walkAtLeastOneSep(e,t,n){let r=Jv(e,t,n);this.walk(e,r)}walkMany(e,t,n){let r=[new Fv({definition:e.definition})].concat(t,n);this.walk(e,r)}walkManySep(e,t,n){let r=Jv(e,t,n);this.walk(e,r)}walkOr(e,t,n){let r=t.concat(n);e.definition.forEach(e=>{let t=new Pv({definition:[e]});this.walk(t,r)})}};function Jv(e,t,n){return[new Fv({definition:[new Vv({terminalType:e.separator})].concat(e.definition)})].concat(t,n)}function Yv(e){if(e instanceof Mv)return Yv(e.referencedRule);if(e instanceof Vv)return[e.terminalType];if(function(e){return e instanceof Pv||e instanceof Fv||e instanceof Rv||e instanceof Iv||e instanceof Lv||e instanceof zv||e instanceof Vv||e instanceof Nv}(e))return function(e){let t=[],n=e.definition,r,i=0,a=n.length>i,o=!0;for(;a&&o;)r=n[i],o=Gv(r),t=t.concat(Yv(r)),i+=1,a=n.length>i;return[...new Set(t)]}(e);if(function(e){return e instanceof Bv}(e))return function(e){let t=e.definition.map(e=>Yv(e));return[...new Set(t.flat())]}(e);throw Error(`non exhaustive match`)}var Xv=`_~IN~_`,Zv=class extends qv{constructor(e){super(),this.topProd=e,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(e,t,n){}walkProdRef(e,t,n){let r=(i=e.referencedRule,a=e.idx,i.name+a+Xv+this.topProd.name);var i,a;let o=Yv(new Pv({definition:t.concat(n)}));this.follows[r]=o}};function Qv(e){return e.charCodeAt(0)}function $v(e,t){Array.isArray(e)?e.forEach(function(e){t.push(e)}):t.push(e)}function ey(e,t){if(!0===e[t])throw`duplicate flag `+t;e[t],e[t]=!0}function ty(e){if(e===void 0)throw Error(`Internal Error - Should never get here!`);return!0}function ny(){throw Error(`Internal Error - Should never get here!`)}function ry(e){return e.type===`Character`}var iy=[];for(let e=Qv(`0`);e<=Qv(`9`);e++)iy.push(e);var ay=[Qv(`_`)].concat(iy);for(let e=Qv(`a`);e<=Qv(`z`);e++)ay.push(e);for(let e=Qv(`A`);e<=Qv(`Z`);e++)ay.push(e);var oy=[Qv(` `),Qv(`\f`),Qv(`
|
|
6
|
-
`),Qv(`\r`),Qv(` `),Qv(`\v`),Qv(` `),Qv(`\xA0`),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(` `),Qv(`\u2028`),Qv(`\u2029`),Qv(` `),Qv(` `),Qv(` `),Qv(``)],sy=/[0-9a-fA-F]/,cy=/[0-9]/,ly=/[1-9]/,uy=class{visitChildren(e){for(let t in e){let n=e[t];e.hasOwnProperty(t)&&(n.type===void 0?Array.isArray(n)&&n.forEach(e=>{this.visit(e)},this):this.visit(n))}}visit(e){switch(e.type){case`Pattern`:this.visitPattern(e);break;case`Flags`:this.visitFlags(e);break;case`Disjunction`:this.visitDisjunction(e);break;case`Alternative`:this.visitAlternative(e);break;case`StartAnchor`:this.visitStartAnchor(e);break;case`EndAnchor`:this.visitEndAnchor(e);break;case`WordBoundary`:this.visitWordBoundary(e);break;case`NonWordBoundary`:this.visitNonWordBoundary(e);break;case`Lookahead`:this.visitLookahead(e);break;case`NegativeLookahead`:this.visitNegativeLookahead(e);break;case`Lookbehind`:this.visitLookbehind(e);break;case`NegativeLookbehind`:this.visitNegativeLookbehind(e);break;case`Character`:this.visitCharacter(e);break;case`Set`:this.visitSet(e);break;case`Group`:this.visitGroup(e);break;case`GroupBackReference`:this.visitGroupBackReference(e);break;case`Quantifier`:this.visitQuantifier(e)}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitLookbehind(e){}visitNegativeLookbehind(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}},dy={},fy=new class{constructor(){this.idx=0,this.input=``,this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx}pattern(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar(`/`);let t=this.disjunction();this.consumeChar(`/`);let n={type:`Flags`,loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case`g`:ey(n,`global`);break;case`i`:ey(n,`ignoreCase`);break;case`m`:ey(n,`multiLine`);break;case`u`:ey(n,`unicode`);break;case`y`:ey(n,`sticky`)}if(this.idx!==this.input.length)throw Error(`Redundant input: `+this.input.substring(this.idx));return{type:`Pattern`,flags:n,value:t,loc:this.loc(0)}}disjunction(){let e=[],t=this.idx;for(e.push(this.alternative());this.peekChar()===`|`;)this.consumeChar(`|`),e.push(this.alternative());return{type:`Disjunction`,value:e,loc:this.loc(t)}}alternative(){let e=[],t=this.idx;for(;this.isTerm();)e.push(this.term());return{type:`Alternative`,value:e,loc:this.loc(t)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){let e=this.idx;switch(this.popChar()){case`^`:return{type:`StartAnchor`,loc:this.loc(e)};case`$`:return{type:`EndAnchor`,loc:this.loc(e)};case`\\`:switch(this.popChar()){case`b`:return{type:`WordBoundary`,loc:this.loc(e)};case`B`:return{type:`NonWordBoundary`,loc:this.loc(e)}}throw Error(`Invalid Assertion Escape`);case`(`:let t;switch(this.consumeChar(`?`),this.popChar()){case`=`:t=`Lookahead`;break;case`!`:t=`NegativeLookahead`;break;case`<`:switch(this.popChar()){case`=`:t=`Lookbehind`;break;case`!`:t=`NegativeLookbehind`}}ty(t);let n=this.disjunction();return this.consumeChar(`)`),{type:t,value:n,loc:this.loc(e)}}return ny()}quantifier(e=!1){let t,n=this.idx;switch(this.popChar()){case`*`:t={atLeast:0,atMost:1/0};break;case`+`:t={atLeast:1,atMost:1/0};break;case`?`:t={atLeast:0,atMost:1};break;case`{`:let n=this.integerIncludingZero();switch(this.popChar()){case`}`:t={atLeast:n,atMost:n};break;case`,`:let e;this.isDigit()?(e=this.integerIncludingZero(),t={atLeast:n,atMost:e}):t={atLeast:n,atMost:1/0},this.consumeChar(`}`)}if(!0===e&&t===void 0)return;ty(t)}if(!0!==e||t!==void 0)return ty(t)?(this.peekChar(0)===`?`?(this.consumeChar(`?`),t.greedy=!1):t.greedy=!0,t.type=`Quantifier`,t.loc=this.loc(n),t):void 0}atom(){let e,t=this.idx;switch(this.peekChar()){case`.`:e=this.dotAll();break;case`\\`:e=this.atomEscape();break;case`[`:e=this.characterClass();break;case`(`:e=this.group()}return e===void 0&&this.isPatternCharacter()&&(e=this.patternCharacter()),ty(e)?(e.loc=this.loc(t),this.isQuantifier()&&(e.quantifier=this.quantifier()),e):ny()}dotAll(){return this.consumeChar(`.`),{type:`Set`,complement:!0,value:[Qv(`
|
|
7
|
-
`),Qv(`\r`),Qv(`\u2028`),Qv(`\u2029`)]}}atomEscape(){switch(this.consumeChar(`\\`),this.peekChar()){case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:return this.decimalEscapeAtom();case`d`:case`D`:case`s`:case`S`:case`w`:case`W`:return this.characterClassEscape();case`f`:case`n`:case`r`:case`t`:case`v`:return this.controlEscapeAtom();case`c`:return this.controlLetterEscapeAtom();case`0`:return this.nulCharacterAtom();case`x`:return this.hexEscapeSequenceAtom();case`u`:return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:`GroupBackReference`,value:this.positiveInteger()}}characterClassEscape(){let e,t=!1;switch(this.popChar()){case`d`:e=iy;break;case`D`:e=iy,t=!0;break;case`s`:e=oy;break;case`S`:e=oy,t=!0;break;case`w`:e=ay;break;case`W`:e=ay,t=!0}return ty(e)?{type:`Set`,value:e,complement:t}:ny()}controlEscapeAtom(){let e;switch(this.popChar()){case`f`:e=Qv(`\f`);break;case`n`:e=Qv(`
|
|
8
|
-
`);break;case`r`:e=Qv(`\r`);break;case`t`:e=Qv(` `);break;case`v`:e=Qv(`\v`)}return ty(e)?{type:`Character`,value:e}:ny()}controlLetterEscapeAtom(){this.consumeChar(`c`);let e=this.popChar();if(!1===/[a-zA-Z]/.test(e))throw Error(`Invalid `);return{type:`Character`,value:e.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar(`0`),{type:`Character`,value:Qv(`\0`)}}hexEscapeSequenceAtom(){return this.consumeChar(`x`),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar(`u`),this.parseHexDigits(4)}identityEscapeAtom(){return{type:`Character`,value:Qv(this.popChar())}}classPatternCharacterAtom(){switch(this.peekChar()){case`
|
|
9
|
-
`:case`\r`:case`\u2028`:case`\u2029`:case`\\`:case`]`:throw Error(`TBD`);default:return{type:`Character`,value:Qv(this.popChar())}}}characterClass(){let e=[],t=!1;for(this.consumeChar(`[`),this.peekChar(0)===`^`&&(this.consumeChar(`^`),t=!0);this.isClassAtom();){let t=this.classAtom();if(t.type,ry(t)&&this.isRangeDash()){this.consumeChar(`-`);let n=this.classAtom();if(n.type,ry(n)){if(n.value<t.value)throw Error(`Range out of order in character class`);e.push({from:t.value,to:n.value})}else $v(t.value,e),e.push(Qv(`-`)),$v(n.value,e)}else $v(t.value,e)}return this.consumeChar(`]`),{type:`Set`,complement:t,value:e}}classAtom(){switch(this.peekChar()){case`]`:case`
|
|
10
|
-
`:case`\r`:case`\u2028`:case`\u2029`:throw Error(`TBD`);case`\\`:return this.classEscape();default:return this.classPatternCharacterAtom()}}classEscape(){switch(this.consumeChar(`\\`),this.peekChar()){case`b`:return this.consumeChar(`b`),{type:`Character`,value:Qv(`\b`)};case`d`:case`D`:case`s`:case`S`:case`w`:case`W`:return this.characterClassEscape();case`f`:case`n`:case`r`:case`t`:case`v`:return this.controlEscapeAtom();case`c`:return this.controlLetterEscapeAtom();case`0`:return this.nulCharacterAtom();case`x`:return this.hexEscapeSequenceAtom();case`u`:return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}group(){let e=!0;this.consumeChar(`(`),this.peekChar(0)===`?`?(this.consumeChar(`?`),this.consumeChar(`:`),e=!1):this.groupIdx++;let t=this.disjunction();this.consumeChar(`)`);let n={type:`Group`,capturing:e,value:t};return e&&(n.idx=this.groupIdx),n}positiveInteger(){let e=this.popChar();if(!1===ly.test(e))throw Error(`Expecting a positive integer`);for(;cy.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}integerIncludingZero(){let e=this.popChar();if(!1===cy.test(e))throw Error(`Expecting an integer`);for(;cy.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}patternCharacter(){let e=this.popChar();switch(e){case`
|
|
11
|
-
`:case`\r`:case`\u2028`:case`\u2029`:case`^`:case`$`:case`\\`:case`.`:case`*`:case`+`:case`?`:case`(`:case`)`:case`[`:case`|`:throw Error(`TBD`);default:return{type:`Character`,value:Qv(e)}}}isRegExpFlag(){switch(this.peekChar(0)){case`g`:case`i`:case`m`:case`u`:case`y`:return!0;default:return!1}}isRangeDash(){return this.peekChar()===`-`&&this.isClassAtom(1)}isDigit(){return cy.test(this.peekChar(0))}isClassAtom(e=0){switch(this.peekChar(e)){case`]`:case`
|
|
12
|
-
`:case`\r`:case`\u2028`:case`\u2029`:return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case`.`:case`\\`:case`[`:case`(`:return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case`^`:case`$`:return!0;case`\\`:switch(this.peekChar(1)){case`b`:case`B`:return!0;default:return!1}case`(`:return this.peekChar(1)===`?`&&(this.peekChar(2)===`=`||this.peekChar(2)===`!`||this.peekChar(2)===`<`&&(this.peekChar(3)===`=`||this.peekChar(3)===`!`));default:return!1}}isQuantifier(){let e=this.saveState();try{return this.quantifier(!0)!==void 0}catch{return!1}finally{this.restoreState(e)}}isPatternCharacter(){switch(this.peekChar()){case`^`:case`$`:case`\\`:case`.`:case`*`:case`+`:case`?`:case`(`:case`)`:case`[`:case`|`:case`/`:case`
|
|
13
|
-
`:case`\r`:case`\u2028`:case`\u2029`:return!1;default:return!0}}parseHexDigits(e){let t=``;for(let n=0;n<e;n++){let e=this.popChar();if(!1===sy.test(e))throw Error(`Expecting a HexDecimal digits`);t+=e}return{type:`Character`,value:parseInt(t,16)}}peekChar(e=0){return this.input[this.idx+e]}popChar(){let e=this.peekChar(0);return this.consumeChar(void 0),e}consumeChar(e){if(e!==void 0&&this.input[this.idx]!==e)throw Error(`Expected: '`+e+`' but found: '`+this.input[this.idx]+`' at offset: `+this.idx);if(this.idx>=this.input.length)throw Error(`Unexpected end of input`);this.idx++}loc(e){return{begin:e,end:this.idx}}};function py(e){let t=e.toString();if(dy.hasOwnProperty(t))return dy[t];{let e=fy.pattern(t);return dy[t]=e,e}}var my=`Complement Sets are not supported for first char optimization`,hy=`Unable to use "first char" lexer optimizations:
|
|
14
|
-
`;function gy(e,t=!1){try{let t=py(e);return _y(t.value,{},t.flags.ignoreCase)}catch(n){if(n.message===my)t&&Ov(`${hy}\tUnable to optimize: < ${e.toString()} >\n\tComplement Sets cannot be automatically optimized.\n\tThis will disable the lexer's first char optimizations.\n\tSee: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let n=``;t&&(n=`
|
|
15
|
-
This will disable the lexer's first char optimizations.
|
|
16
|
-
See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),Dv(`${hy}\n\tFailed parsing: < ${e.toString()} >\n\tUsing the @chevrotain/regexp-to-ast library\n\tPlease open an issue at: https://github.com/chevrotain/chevrotain/issues`+n)}}return[]}function _y(e,t,n){switch(e.type){case`Disjunction`:for(let r=0;r<e.value.length;r++)_y(e.value[r],t,n);break;case`Alternative`:let r=e.value;for(let e=0;e<r.length;e++){let i=r[e];switch(i.type){case`EndAnchor`:case`GroupBackReference`:case`Lookahead`:case`NegativeLookahead`:case`Lookbehind`:case`NegativeLookbehind`:case`StartAnchor`:case`WordBoundary`:case`NonWordBoundary`:continue}let a=i;switch(a.type){case`Character`:vy(a.value,t,n);break;case`Set`:if(!0===a.complement)throw Error(my);a.value.forEach(e=>{if(typeof e==`number`)vy(e,t,n);else{let r=e;if(!0===n)for(let e=r.from;e<=r.to;e++)vy(e,t,n);else{for(let e=r.from;e<=r.to&&e<256;e++)vy(e,t,n);if(r.to>=256){let e=r.from>=256?r.from:256,n=r.to,i=Ry(e),a=Ry(n);for(let e=i;e<=a;e++)t[e]=e}}}});break;case`Group`:_y(a.value,t,n);break;default:throw Error(`Non Exhaustive Match`)}let o=a.quantifier!==void 0&&a.quantifier.atLeast===0;if(a.type===`Group`&&!1===by(a)||a.type!==`Group`&&!1===o)break}break;default:throw Error(`non exhaustive match!`)}return Object.values(t)}function vy(e,t,n){let r=Ry(e);t[r]=r,!0===n&&function(e,t){let n=String.fromCharCode(e),r=n.toUpperCase();if(r!==n){let e=Ry(r.charCodeAt(0));t[e]=e}else{let e=n.toLowerCase();if(e!==n){let n=Ry(e.charCodeAt(0));t[n]=n}}}(e,t)}function yy(e,t){return e.value.find(e=>{if(typeof e==`number`)return t.includes(e);{let n=e;return t.find(e=>n.from<=e&&e<=n.to)!==void 0}})}function by(e){let t=e.quantifier;return!(!t||t.atLeast!==0)||!!e.value&&(Array.isArray(e.value)?e.value.every(by):by(e.value))}var xy=class extends uy{constructor(e){super(),this.targetCharCodes=e,this.found=!1}visitChildren(e){if(!0!==this.found){switch(e.type){case`Lookahead`:this.visitLookahead(e);return;case`NegativeLookahead`:this.visitNegativeLookahead(e);return;case`Lookbehind`:this.visitLookbehind(e);return;case`NegativeLookbehind`:this.visitNegativeLookbehind(e);return}super.visitChildren(e)}}visitCharacter(e){this.targetCharCodes.includes(e.value)&&(this.found=!0)}visitSet(e){e.complement?yy(e,this.targetCharCodes)===void 0&&(this.found=!0):yy(e,this.targetCharCodes)!==void 0&&(this.found=!0)}};function Sy(e,t){if(t instanceof RegExp){let n=py(t),r=new xy(e);return r.visit(n),r.found}for(let n of t){let t=n.charCodeAt(0);if(e.includes(t))return!0}return!1}var Cy=`PATTERN`,wy=`defaultMode`;function Ty(e,t){let n=(t=Object.assign({safeMode:!1,positionTracking:`full`,lineTerminatorCharacters:[`\r`,`
|
|
17
|
-
`],tracer:(e,t)=>t()},t)).tracer,r;n(`initCharCodeToOptimizedIndexMap`,()=>{(function(){if(Ly.length===0){Ly=Array(65536);for(let e=0;e<65536;e++)Ly[e]=e>255?255+~~(e/255):e}})()}),n(`Reject Lexer.NA`,()=>{r=e.filter(e=>e[Cy]!==Zy.NA)});let i,a,o,s,c,l,u,d,f,p,m,h=!1;n(`Transform Patterns`,()=>{h=!1,i=r.map(e=>{let t=e[Cy];if(t instanceof RegExp){let e=t.source;return e.length!==1||e===`^`||e===`$`||e===`.`||t.ignoreCase?e.length!==2||e[0]!==`\\`||[`d`,`D`,`s`,`S`,`t`,`r`,`n`,`t`,`0`,`c`,`b`,`B`,`f`,`v`,`w`,`W`].includes(e[1])?ky(t):e[1]:e}if(typeof t==`function`)return h=!0,{exec:t};if(typeof t==`object`)return h=!0,t;if(typeof t==`string`){if(t.length===1)return t;{let e=t.replace(/[\\^$.*+?()[\]{}|]/g,`\\$&`);return ky(new RegExp(e))}}throw Error(`non exhaustive match`)})}),n(`misc mapping`,()=>{a=r.map(e=>e.tokenTypeIdx),o=r.map(e=>{let t=e.GROUP;if(t!==Zy.SKIPPED){if(typeof t==`string`)return t;if(t===void 0)return!1;throw Error(`non exhaustive match`)}}),s=r.map(e=>{let t=e.LONGER_ALT;if(t)return Array.isArray(t)?t.map(e=>r.indexOf(e)):[r.indexOf(t)]}),c=r.map(e=>e.PUSH_MODE),l=r.map(e=>Object.hasOwn(e,`POP_MODE`))}),n(`Line Terminator Handling`,()=>{let e=Fy(t.lineTerminatorCharacters);u=r.map(e=>!1),t.positionTracking!==`onlyOffset`&&(u=r.map(t=>Object.hasOwn(t,`LINE_BREAKS`)?!!t.LINE_BREAKS:!1===Ny(t,e)&&Sy(e,t.PATTERN)))}),n(`Misc Mapping #2`,()=>{d=r.map(Ay),f=i.map(jy),p=r.reduce((e,t)=>{let n=t.GROUP;return typeof n==`string`&&n!==Zy.SKIPPED&&(e[n]=[]),e},{}),m=i.map((e,t)=>({pattern:i[t],longerAlt:s[t],canLineTerminator:u[t],isCustom:d[t],short:f[t],group:o[t],push:c[t],pop:l[t],tokenTypeIdx:a[t],tokenType:r[t]}))});let g=!0,_=[];return t.safeMode||n(`First Char Optimization`,()=>{_=r.reduce((e,n,r)=>{if(typeof n.PATTERN==`string`)Iy(e,Ry(n.PATTERN.charCodeAt(0)),m[r]);else if(Array.isArray(n.START_CHARS_HINT)){let t;n.START_CHARS_HINT.forEach(n=>{let i=Ry(typeof n==`string`?n.charCodeAt(0):n);t!==i&&(t=i,Iy(e,i,m[r]))})}else if(n.PATTERN instanceof RegExp)if(n.PATTERN.unicode)g=!1,t.ensureOptimizations&&Dv(`${hy}\tUnable to analyze < ${n.PATTERN.toString()} > pattern.\n\tThe regexp unicode flag is not currently supported by the regexp-to-ast library.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{let i=gy(n.PATTERN,t.ensureOptimizations);i.length===0&&(g=!1),i.forEach(t=>{Iy(e,t,m[r])})}else t.ensureOptimizations&&Dv(`${hy}\tTokenType: <${n.name}> is using a custom token pattern without providing <start_chars_hint> parameter.\n\tThis will disable the lexer's first char optimizations.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),g=!1;return e},[])}),{emptyGroups:p,patternIdxToConfig:m,charCodeToPatternIdxToConfig:_,hasCustom:h,canBeOptimized:g}}function Ey(e,t){let n=[],r=function(e){let t=e.filter(e=>!Object.hasOwn(e,Cy));return{errors:t.map(e=>({message:`Token Type: ->`+e.name+`<- missing static 'PATTERN' property`,type:Jy.MISSING_PATTERN,tokenTypes:[e]})),valid:e.filter(e=>!t.includes(e))}}(e);n=n.concat(r.errors);let i=function(e){let t=e.filter(e=>{let t=e[Cy];return!(t instanceof RegExp||typeof t==`function`||Object.hasOwn(t,`exec`)||typeof t==`string`)});return{errors:t.map(e=>({message:`Token Type: ->`+e.name+`<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.`,type:Jy.INVALID_PATTERN,tokenTypes:[e]})),valid:e.filter(e=>!t.includes(e))}}(r.valid),a=i.valid;return n=n.concat(i.errors),n=n.concat(function(e){let t=[],n=e.filter(e=>e[Cy]instanceof RegExp);return t=t.concat(function(e){class t extends uy{constructor(){super(...arguments),this.found=!1}visitEndAnchor(e){this.found=!0}}return e.filter(e=>{let n=e.PATTERN;try{let e=py(n),r=new t;return r.visit(e),r.found}catch{return Dy.test(n.source)}}).map(e=>({message:`Unexpected RegExp Anchor Error:
|
|
18
|
-
Token Type: ->`+e.name+`<- static 'PATTERN' cannot contain end of input anchor '$'
|
|
19
|
-
See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:Jy.EOI_ANCHOR_FOUND,tokenTypes:[e]}))}(n)),t=t.concat(function(e){class t extends uy{constructor(){super(...arguments),this.found=!1}visitStartAnchor(e){this.found=!0}}return e.filter(e=>{let n=e.PATTERN;try{let e=py(n),r=new t;return r.visit(e),r.found}catch{return Oy.test(n.source)}}).map(e=>({message:`Unexpected RegExp Anchor Error:
|
|
20
|
-
Token Type: ->`+e.name+`<- static 'PATTERN' cannot contain start of input anchor '^'
|
|
21
|
-
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:Jy.SOI_ANCHOR_FOUND,tokenTypes:[e]}))}(n)),t=t.concat(function(e){return e.filter(e=>{let t=e[Cy];return t instanceof RegExp&&(t.multiline||t.global)}).map(e=>({message:`Token Type: ->`+e.name+`<- static 'PATTERN' may NOT contain global('g') or multiline('m')`,type:Jy.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[e]}))}(n)),t=t.concat(function(e){let t=[],n=e.map(n=>e.reduce((e,r)=>(n.PATTERN.source!==r.PATTERN.source||t.includes(r)||r.PATTERN===Zy.NA||(t.push(r),e.push(r)),e),[]));return n=n.filter(Boolean),n.filter(e=>e.length>1).map(e=>{let t=e.map(e=>e.name);return{message:`The same RegExp pattern ->${e[0].PATTERN}<-has been used in all of the following Token Types: ${t.join(`, `)} <-`,type:Jy.DUPLICATE_PATTERNS_FOUND,tokenTypes:e}})}(n)),t=t.concat(function(e){return e.filter(e=>e.PATTERN.test(``)).map(e=>({message:`Token Type: ->`+e.name+`<- static 'PATTERN' must not match an empty string`,type:Jy.EMPTY_MATCH_PATTERN,tokenTypes:[e]}))}(n)),t}(a)),n=n.concat(function(e){return e.filter(e=>{if(!Object.hasOwn(e,`GROUP`))return!1;let t=e.GROUP;return t!==Zy.SKIPPED&&t!==Zy.NA&&typeof t!=`string`}).map(e=>({message:`Token Type: ->`+e.name+`<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String`,type:Jy.INVALID_GROUP_TYPE_FOUND,tokenTypes:[e]}))}(a)),n=n.concat(function(e,t){return e.filter(e=>e.PUSH_MODE!==void 0&&!t.includes(e.PUSH_MODE)).map(e=>({message:`Token Type: ->${e.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${e.PUSH_MODE}<-which does not exist`,type:Jy.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[e]}))}(a,t)),n=n.concat(function(e){let t=[],n=e.reduce((e,t,n)=>{let r=t.PATTERN;return r===Zy.NA||(typeof r==`string`?e.push({str:r,idx:n,tokenType:t}):r instanceof RegExp&&(i=r,[`.`,`\\`,`[`,`]`,`|`,`^`,`$`,`(`,`)`,`?`,`*`,`+`,`{`].find(e=>i.source.indexOf(e)!==-1)===void 0)&&e.push({str:r.source,idx:n,tokenType:t})),e;var i},[]);return e.forEach((e,r)=>{n.forEach(({str:n,idx:i,tokenType:a})=>{if(r<i&&function(e,t){if(t instanceof RegExp){if(/(\(\?=)|(\(\?!)|(\(\?<=)|(\(\?<!)/.test(t.source))return!1;let n=t.exec(e);return n!==null&&n.index===0}if(typeof t==`function`)return t(e,0,[],{});if(Object.hasOwn(t,`exec`))return t.exec(e,0,[],{});if(typeof t==`string`)return t===e;throw Error(`non exhaustive match`)}(n,e.PATTERN)){let n=`Token: ->${a.name}<- can never be matched.\nBecause it appears AFTER the Token Type ->${e.name}<-in the lexer's definition.\nSee https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;t.push({message:n,type:Jy.UNREACHABLE_PATTERN,tokenTypes:[e,a]})}})}),t}(a)),n}var Dy=/[^\\][$]/,Oy=/[^\\[][\^]|^\^/;function ky(e){let t=e.ignoreCase?`iy`:`y`;return RegExp(`${e.source}`,t)}function Ay(e){let t=e.PATTERN;if(t instanceof RegExp)return!1;if(typeof t==`function`||Object.hasOwn(t,`exec`))return!0;if(typeof t==`string`)return!1;throw Error(`non exhaustive match`)}function jy(e){return typeof e==`string`&&e.length===1&&e.charCodeAt(0)}var My={test:function(e){let t=e.length;for(let n=this.lastIndex;n<t;n++){let t=e.charCodeAt(n);if(t===10)return this.lastIndex=n+1,!0;if(t===13)return e.charCodeAt(n+1)===10?this.lastIndex=n+2:this.lastIndex=n+1,!0}return!1},lastIndex:0};function Ny(e,t){if(Object.hasOwn(e,`LINE_BREAKS`))return!1;if(e.PATTERN instanceof RegExp){try{Sy(t,e.PATTERN)}catch(e){return{issue:Jy.IDENTIFY_TERMINATOR,errMsg:e.message}}return!1}if(typeof e.PATTERN==`string`)return!1;if(Ay(e))return{issue:Jy.CUSTOM_LINE_BREAK};throw Error(`non exhaustive match`)}function Py(e,t){if(t.issue===Jy.IDENTIFY_TERMINATOR)return`Warning: unable to identify line terminator usage in pattern.\n\tThe problem is in the <${e.name}> Token Type\n\t Root cause: ${t.errMsg}.\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(t.issue===Jy.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the <line_breaks> option.\n\tThe problem is in the <${e.name}> Token Type\n\tFor details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error(`non exhaustive match`)}function Fy(e){return e.map(e=>typeof e==`string`?e.charCodeAt(0):e)}function Iy(e,t,n){e[t]===void 0?e[t]=[n]:e[t].push(n)}var Ly=[];function Ry(e){return e<256?e:Ly[e]}function zy(e,t){let n=e.tokenTypeIdx;return n===t.tokenTypeIdx||!0===t.isParent&&!0===t.categoryMatchesMap[n]}function By(e,t){return e.tokenTypeIdx===t.tokenTypeIdx}var Vy=1,Hy={};function Uy(e){let t=function(e){let t=[...e],n=e,r=!0;for(;r;){n=n.map(e=>e.CATEGORIES).flat().filter(Boolean);let e=n.filter(e=>!t.includes(e));t=t.concat(e),e.length===0?r=!1:n=e}return t}(e);(function(e){e.forEach(e=>{var t;Gy(e)||(Hy[Vy]=e,e.tokenTypeIdx=Vy++),Ky(e)&&!Array.isArray(e.CATEGORIES)&&(e.CATEGORIES=[e.CATEGORIES]),Ky(e)||(e.CATEGORIES=[]),t=e,Object.hasOwn(t??{},`categoryMatches`)||(e.categoryMatches=[]),function(e){return Object.hasOwn(e??{},`categoryMatchesMap`)}(e)||(e.categoryMatchesMap={})})})(t),function(e){e.forEach(e=>{Wy([],e)})}(t),function(e){e.forEach(e=>{e.categoryMatches=[],Object.keys(e.categoryMatchesMap).forEach(t=>{e.categoryMatches.push(Hy[t].tokenTypeIdx)})})}(t),t.forEach(e=>{e.isParent=e.categoryMatches.length>0})}function Wy(e,t){e.forEach(e=>{t.categoryMatchesMap[e.tokenTypeIdx]=!0}),t.CATEGORIES.forEach(n=>{let r=e.concat(t);r.includes(n)||Wy(r,n)})}function Gy(e){return Object.hasOwn(e??{},`tokenTypeIdx`)}function Ky(e){return Object.hasOwn(e??{},`CATEGORIES`)}function qy(e){return Object.hasOwn(e??{},`tokenTypeIdx`)}var Jy,Yy={buildUnableToPopLexerModeMessage:e=>`Unable to pop Lexer Mode after encountering Token ->${e.image}<- The Mode Stack is empty`,buildUnexpectedCharactersMessage:(e,t,n,r,i,a)=>`unexpected character: ->${e.charAt(t)}<- at offset: ${t}, skipped ${n} characters.`};(function(e){e[e.MISSING_PATTERN=0]=`MISSING_PATTERN`,e[e.INVALID_PATTERN=1]=`INVALID_PATTERN`,e[e.EOI_ANCHOR_FOUND=2]=`EOI_ANCHOR_FOUND`,e[e.UNSUPPORTED_FLAGS_FOUND=3]=`UNSUPPORTED_FLAGS_FOUND`,e[e.DUPLICATE_PATTERNS_FOUND=4]=`DUPLICATE_PATTERNS_FOUND`,e[e.INVALID_GROUP_TYPE_FOUND=5]=`INVALID_GROUP_TYPE_FOUND`,e[e.PUSH_MODE_DOES_NOT_EXIST=6]=`PUSH_MODE_DOES_NOT_EXIST`,e[e.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]=`MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE`,e[e.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]=`MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY`,e[e.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]=`MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST`,e[e.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]=`LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED`,e[e.SOI_ANCHOR_FOUND=11]=`SOI_ANCHOR_FOUND`,e[e.EMPTY_MATCH_PATTERN=12]=`EMPTY_MATCH_PATTERN`,e[e.NO_LINE_BREAKS_FLAGS=13]=`NO_LINE_BREAKS_FLAGS`,e[e.UNREACHABLE_PATTERN=14]=`UNREACHABLE_PATTERN`,e[e.IDENTIFY_TERMINATOR=15]=`IDENTIFY_TERMINATOR`,e[e.CUSTOM_LINE_BREAK=16]=`CUSTOM_LINE_BREAK`,e[e.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]=`MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE`})(Jy||={});var Xy={deferDefinitionErrorsHandling:!1,positionTracking:`full`,lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
|
|
22
|
-
`,`\r`],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:Yy,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(Xy);var Zy=class{constructor(e,t=Xy){if(this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.cachedGroupKeys=[],this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(e,t)=>{if(!0===this.traceInitPerf){this.traceInitIndent++;let n=Array(this.traceInitIndent+1).join(` `);this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${n}--\x3e <${e}>`);let{time:r,value:i}=kv(t),a=r>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&a(`${n}<-- <${e}> time: ${r}ms`),this.traceInitIndent--,i}return t()},typeof t==`boolean`)throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
|
|
23
|
-
a boolean 2nd argument is no longer supported`);this.config=Object.assign({},Xy,t);let n=this.config.traceInitPerf;!0===n?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof n==`number`&&(this.traceInitMaxIdent=n,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT(`Lexer Constructor`,()=>{let n,r=!0;this.TRACE_INIT(`Lexer Config handling`,()=>{if(this.config.lineTerminatorsPattern===Xy.lineTerminatorsPattern)this.config.lineTerminatorsPattern=My;else if(this.config.lineTerminatorCharacters===Xy.lineTerminatorCharacters)throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
|
|
24
|
-
For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(t.safeMode&&t.ensureOptimizations)throw Error(`"safeMode" and "ensureOptimizations" flags are mutually exclusive.`);this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),Array.isArray(e)?n={modes:{defaultMode:[...e]},defaultMode:wy}:(r=!1,n=Object.assign({},e))}),!1===this.config.skipValidations&&(this.TRACE_INIT(`performRuntimeChecks`,()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(function(e){let t=[];return Object.hasOwn(e,`defaultMode`)||t.push({message:`A MultiMode Lexer cannot be initialized without a <defaultMode> property in its definition
|
|
25
|
-
`,type:Jy.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),Object.hasOwn(e,`modes`)||t.push({message:`A MultiMode Lexer cannot be initialized without a <modes> property in its definition
|
|
26
|
-
`,type:Jy.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),Object.hasOwn(e,`modes`)&&Object.hasOwn(e,`defaultMode`)&&!Object.hasOwn(e.modes,e.defaultMode)&&t.push({message:`A MultiMode Lexer cannot be initialized with a ${wy}: <${e.defaultMode}>which does not exist\n`,type:Jy.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),Object.hasOwn(e,`modes`)&&Object.keys(e.modes).forEach(n=>{let r=e.modes[n];r.forEach((e,i)=>{e===void 0?t.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${n}> at index: <${i}>\n`,type:Jy.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED}):Object.hasOwn(e,`LONGER_ALT`)&&(Array.isArray(e.LONGER_ALT)?e.LONGER_ALT:[e.LONGER_ALT]).forEach(i=>{i===void 0||r.includes(i)||t.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${i.name}> on token <${e.name}> outside of mode <${n}>\n`,type:Jy.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})})}),t}(n,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT(`performWarningRuntimeChecks`,()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(function(e,t,n){let r=[],i=!1,a=Object.values(e.modes||{}).flat().filter(Boolean).filter(e=>e[Cy]!==Zy.NA),o=Fy(n);return t&&a.forEach(e=>{let t=Ny(e,o);if(!1!==t){let n={message:Py(e,t),type:t.issue,tokenType:e};r.push(n)}else Object.hasOwn(e,`LINE_BREAKS`)?!0===e.LINE_BREAKS&&(i=!0):Sy(o,e.PATTERN)&&(i=!0)}),t&&!i&&r.push({message:`Warning: No LINE_BREAKS Found.
|
|
27
|
-
This Lexer has been defined to track line and column information,
|
|
28
|
-
But none of the Token Types can be identified as matching a line terminator.
|
|
29
|
-
See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS
|
|
30
|
-
for details.`,type:Jy.NO_LINE_BREAKS_FLAGS}),r}(n,this.trackStartLines,this.config.lineTerminatorCharacters))})),n.modes=n.modes?n.modes:{},Object.entries(n.modes).forEach(([e,t])=>{n.modes[e]=t.filter(e=>e!==void 0)});let i=Object.keys(n.modes);if(Object.entries(n.modes).forEach(([e,n])=>{this.TRACE_INIT(`Mode: <${e}> processing`,()=>{if(this.modes.push(e),!1===this.config.skipValidations&&this.TRACE_INIT(`validatePatterns`,()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Ey(n,i))}),this.lexerDefinitionErrors.length===0){let r;Uy(n),this.TRACE_INIT(`analyzeTokenTypes`,()=>{r=Ty(n,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:t.positionTracking,ensureOptimizations:t.ensureOptimizations,safeMode:t.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[e]=r.patternIdxToConfig,this.charCodeToPatternIdxToConfig[e]=r.charCodeToPatternIdxToConfig,this.emptyGroups=Object.assign({},this.emptyGroups,r.emptyGroups),this.hasCustom=r.hasCustom||this.hasCustom,this.canModeBeOptimized[e]=r.canBeOptimized}})}),this.defaultMode=n.defaultMode,this.cachedGroupKeys=Object.keys(this.emptyGroups),this.lexerDefinitionErrors.length>0&&!this.config.deferDefinitionErrorsHandling){let e=this.lexerDefinitionErrors.map(e=>e.message).join(`-----------------------
|
|
31
|
-
`);throw Error(`Errors detected in definition of Lexer:
|
|
32
|
-
`+e)}this.lexerDefinitionWarning.forEach(e=>{Ov(e.message)}),this.TRACE_INIT(`Choosing sub-methods implementations`,()=>{if(r&&(this.handleModes=()=>{}),!1===this.trackStartLines&&(this.computeNewColumn=e=>e),!1===this.trackEndLines&&(this.updateTokenEndLineColumnLocation=()=>{}),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else{if(!/onlyOffset/i.test(this.config.positionTracking))throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);this.createTokenInstance=this.createOffsetOnlyToken}this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT(`Failed Optimization Warnings`,()=>{let e=Object.entries(this.canModeBeOptimized).reduce((e,[t,n])=>(!1===n&&e.push(t),e),[]);if(t.ensureOptimizations&&e.length>0)throw Error(`Lexer Modes: < ${e.join(`, `)} > cannot be optimized.\n\t Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.\n\t Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT(`clearRegExpParserCache`,()=>{dy={}}),this.TRACE_INIT(`toFastProperties`,()=>{Av(this)})})}tokenize(e,t=this.defaultMode){if(this.lexerDefinitionErrors.length>0){let e=this.lexerDefinitionErrors.map(e=>e.message).join(`-----------------------
|
|
33
|
-
`);throw Error(`Unable to Tokenize because Errors detected in definition of Lexer:
|
|
34
|
-
`+e)}return this.tokenizeInternal(e,t)}tokenizeInternal(e,t){let n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_=e,v=_.length,y=0,b=0,x=this.hasCustom?0:Math.floor(e.length/10),S=Array(x),C=[],w=this.trackStartLines?1:void 0,T=this.trackStartLines?1:void 0,E={};for(let e=0;e<this.cachedGroupKeys.length;e++)E[this.cachedGroupKeys[e]]=[];let D=this.trackStartLines,O=this.config.lineTerminatorsPattern,k=0,A=[],j=[],M=[],N=[];Object.freeze(N);let P=!1,F=e=>{if(M.length===1&&e.tokenType.PUSH_MODE===void 0){let t=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(e);C.push({offset:e.startOffset,line:e.startLine,column:e.startColumn,length:e.image.length,message:t})}else{M.pop();let e=M.at(-1);A=this.patternIdxToConfig[e],j=this.charCodeToPatternIdxToConfig[e],k=A.length;let t=this.canModeBeOptimized[e]&&!1===this.config.safeMode;P=!(!j||!t)}};function I(e){M.push(e),j=this.charCodeToPatternIdxToConfig[e],A=this.patternIdxToConfig[e],k=A.length;let t=this.canModeBeOptimized[e]&&!1===this.config.safeMode;P=!(!j||!t)}let L;I.call(this,t);let R=this.config.recoveryEnabled;for(;y<v;){s=null,u=-1;let t=_.charCodeAt(y),x;if(P){let e=Ry(t),n=j[e];x=n===void 0?N:n}else x=A;let ee=x.length;for(n=0;n<ee;n++){L=x[n];let r=L.pattern;c=null;let d=L.short;if(!1===d?!0===L.isCustom?(g=r.exec(_,y,S,E),g===null?s=null:(s=g[0],u=s.length,g.payload!==void 0&&(c=g.payload))):(r.lastIndex=y,u=this.matchLength(r,e,y)):t===d&&(u=1,s=r),u!==-1){if(o=L.longerAlt,o!==void 0){s=e.substring(y,y+u);let t=o.length;for(i=0;i<t;i++){let t=A[o[i]],n=t.pattern;if(l=null,!0===t.isCustom?(g=n.exec(_,y,S,E),g===null?a=null:(a=g[0],g.payload!==void 0&&(l=g.payload))):(n.lastIndex=y,a=this.match(n,e,y)),a&&a.length>s.length){s=a,u=a.length,c=l,L=t;break}}}break}}if(u!==-1){if(d=L.group,d!==void 0&&(s=s===null?e.substring(y,y+u):s,f=L.tokenTypeIdx,p=this.createTokenInstance(s,y,f,L.tokenType,w,T,u),this.handlePayload(p,c),!1===d?b=this.addToken(S,b,p):E[d].push(p)),!0===D&&!0===L.canLineTerminator){let t,n,r=0;O.lastIndex=0;do s=s===null?e.substring(y,y+u):s,t=O.test(s),!0===t&&(n=O.lastIndex-1,r++);while(!0===t);r===0?T=this.computeNewColumn(T,u):(w+=r,T=u-n,this.updateTokenEndLineColumnLocation(p,d,n,r,w,T,u))}else T=this.computeNewColumn(T,u);y+=u,this.handleModes(L,F,I,p)}else{let t=y,n=w,i=T,a=!1===R;for(;!1===a&&y<v;)for(y++,r=0;r<k;r++){let t=A[r],n=t.pattern,i=t.short;if(!1===i?!0===t.isCustom?a=n.exec(_,y,S,E)!==null:(n.lastIndex=y,a=n.exec(e)!==null):_.charCodeAt(y)===i&&(a=!0),!0===a)break}if(m=y-t,T=this.computeNewColumn(T,m),h=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(_,t,m,n,i,M.at(-1)),C.push({offset:t,line:n,column:i,length:m,message:h}),!1===R)break}}return this.hasCustom||(S.length=b),{tokens:S,groups:E,errors:C}}handleModes(e,t,n,r){if(!0===e.pop){let i=e.push;t(r),i!==void 0&&n.call(this,i)}else e.push!==void 0&&n.call(this,e.push)}updateTokenEndLineColumnLocation(e,t,n,r,i,a,o){let s,c;t!==void 0&&(s=n===o-1,c=s?-1:0,r===1&&!0===s||(e.endLine=i+c,e.endColumn=a-1-c))}computeNewColumn(e,t){return e+t}createOffsetOnlyToken(e,t,n,r){return{image:e,startOffset:t,tokenTypeIdx:n,tokenType:r}}createStartOnlyToken(e,t,n,r,i,a){return{image:e,startOffset:t,startLine:i,startColumn:a,tokenTypeIdx:n,tokenType:r}}createFullToken(e,t,n,r,i,a,o){return{image:e,startOffset:t,endOffset:t+o-1,startLine:i,endLine:i,startColumn:a,endColumn:a+o-1,tokenTypeIdx:n,tokenType:r}}addTokenUsingPush(e,t,n){return e.push(n),t}addTokenUsingMemberAccess(e,t,n){return e[t]=n,++t}handlePayloadNoCustom(e,t){}handlePayloadWithCustom(e,t){t!==null&&(e.payload=t)}match(e,t,n){return!0===e.test(t)?t.substring(n,e.lastIndex):null}matchLength(e,t,n){return!0===e.test(t)?e.lastIndex-n:-1}};function Qy(e){return $y(e)?e.LABEL:e.name}function $y(e){return typeof e.LABEL==`string`&&e.LABEL!==``}Zy.SKIPPED=`This marks a skipped Token pattern, this means each token identified by it will be consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.`,Zy.NA=/NOT_APPLICABLE/;var eb=`parent`,tb=`categories`,nb=`label`,rb=`group`,ib=`push_mode`,ab=`pop_mode`,ob=`longer_alt`,sb=`line_breaks`,cb=`start_chars_hint`;function Q(e){return function(e){let t=e.pattern,n={};if(n.name=e.name,t!==void 0&&(n.PATTERN=t),Object.hasOwn(e,eb))throw`The parent property is no longer supported.
|
|
35
|
-
See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;return Object.hasOwn(e,tb)&&(n.CATEGORIES=e[tb]),Uy([n]),Object.hasOwn(e,nb)&&(n.LABEL=e[nb]),Object.hasOwn(e,rb)&&(n.GROUP=e[rb]),Object.hasOwn(e,ab)&&(n.POP_MODE=e[ab]),Object.hasOwn(e,ib)&&(n.PUSH_MODE=e[ib]),Object.hasOwn(e,ob)&&(n.LONGER_ALT=e[ob]),Object.hasOwn(e,sb)&&(n.LINE_BREAKS=e[sb]),Object.hasOwn(e,cb)&&(n.START_CHARS_HINT=e[cb]),n}(e)}var lb=Q({name:`EOF`,pattern:Zy.NA});function ub(e,t,n,r,i,a,o,s){return{image:t,startOffset:n,endOffset:r,startLine:i,endLine:a,startColumn:o,endColumn:s,tokenTypeIdx:e.tokenTypeIdx,tokenType:e}}Uy([lb]);var db={buildMismatchTokenMessage:({expected:e,actual:t,previous:n,ruleName:r})=>`Expecting ${$y(e)?`--\x3e ${Qy(e)} <--`:`token of type --\x3e ${e.name} <--`} but found --\x3e '${t.image}' <--`,buildNotAllInputParsedMessage:({firstRedundant:e,ruleName:t})=>`Redundant input, expecting EOF but found: `+e.image,buildNoViableAltMessage({expectedPathsPerAlt:e,actual:t,previous:n,customUserDescription:r,ruleName:i}){let a=`
|
|
36
|
-
but found: '`+t[0].image+`'`;return r?`Expecting: `+r+a:`Expecting: one of these possible Token sequences:\n${e.reduce((e,t)=>e.concat(t),[]).map(e=>`[${e.map(e=>Qy(e)).join(`, `)}]`).map((e,t)=>` ${t+1}. ${e}`).join(`
|
|
37
|
-
`)}`+a},buildEarlyExitMessage({expectedIterationPaths:e,actual:t,customUserDescription:n,ruleName:r}){let i=`
|
|
38
|
-
but found: '`+t[0].image+`'`;return n?`Expecting: `+n+i:`Expecting: expecting at least one iteration which starts with one of these possible Token sequences::\n <${e.map(e=>`[${e.map(e=>Qy(e)).join(`,`)}]`).join(` ,`)}>`+i}};Object.freeze(db);var fb={buildRuleNotFoundError:(e,t)=>`Invalid grammar, reference to a rule which is not defined: ->`+t.nonTerminalName+`<-
|
|
39
|
-
inside top level rule: ->`+e.name+`<-`},pb={buildDuplicateFoundError(e,t){let n=e.name,r=t[0],i=r.idx,a=Kv(r),o=(s=r)instanceof Vv?s.terminalType.name:s instanceof Mv?s.nonTerminalName:``;var s;let c=`->${a}${i>0?i:``}<- ${o?`with argument: ->${o}<-`:``}\n appears more than once (${t.length} times) in the top level rule: ->${n}<-. \n For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES \n `;return c=c.replace(/[ \t]+/g,` `),c=c.replace(/\s\s+/g,`
|
|
40
|
-
`),c},buildNamespaceConflictError:e=>`Namespace conflict found in grammar.\nThe grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${e.name}>.\nTo resolve this make sure each Terminal and Non-Terminal names are unique\nThis is easy to accomplish by using the convention that Terminal names start with an uppercase letter\nand Non-Terminal names start with a lower case letter.`,buildAlternationPrefixAmbiguityError(e){let t=e.prefixPath.map(e=>Qy(e)).join(`, `),n=e.alternation.idx===0?``:e.alternation.idx;return`Ambiguous alternatives: <${e.ambiguityIndices.join(` ,`)}> due to common lookahead prefix\nin <OR${n}> inside <${e.topLevelRule.name}> Rule,\n<${t}> may appears as a prefix path in all these alternatives.\nSee: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX\nFor Further details.`},buildAlternationAmbiguityError(e){let t=e.alternation.idx===0?``:e.alternation.idx,n=e.prefixPath.length===0,r=`Ambiguous Alternatives Detected: <${e.ambiguityIndices.join(` ,`)}> in <OR${t}> inside <${e.topLevelRule.name}> Rule,\n`;return n?r+=`These alternatives are all empty (match no tokens), making them indistinguishable.
|
|
41
|
-
Only the last alternative may be empty.
|
|
42
|
-
`:r+=`<${e.prefixPath.map(e=>Qy(e)).join(`, `)}> may appears as a prefix path in all these alternatives.\n`,r+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
|
|
43
|
-
For Further details.`,r},buildEmptyRepetitionError(e){let t=Kv(e.repetition);return e.repetition.idx!==0&&(t+=e.repetition.idx),`The repetition <${t}> within Rule <${e.topLevelRule.name}> can never consume any tokens.\nThis could lead to an infinite loop.`},buildTokenNameError:e=>`deprecated`,buildEmptyAlternationError:e=>`Ambiguous empty alternative: <${e.emptyChoiceIdx+1}> in <OR${e.alternation.idx}> inside <${e.topLevelRule.name}> Rule.\nOnly the last alternative may be an empty alternative.`,buildTooManyAlternativesError:e=>`An Alternation cannot have more than 256 alternatives:\n<OR${e.alternation.idx}> inside <${e.topLevelRule.name}> Rule.\n has ${e.alternation.definition.length+1} alternatives.`,buildLeftRecursionError(e){let t=e.topLevelRule.name;return`Left Recursion found in grammar.\nrule: <${t}> can be invoked from itself (directly or indirectly)\nwithout consuming any Tokens. The grammar path that causes this is: \n ${t} --\x3e ${e.leftRecursionPath.map(e=>e.name).concat([t]).join(` --> `)}\n To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError:e=>`deprecated`,buildDuplicateRuleNameError(e){let t;return t=e.topLevelRule instanceof Nv?e.topLevelRule.name:e.topLevelRule,`Duplicate definition, rule: ->${t}<- is already defined in the grammar: ->${e.grammarName}<-`}},mb,hb=class extends Wv{constructor(e,t){super(),this.nameToTopRule=e,this.errMsgProvider=t,this.errors=[]}resolveRefs(){Object.values(this.nameToTopRule).forEach(e=>{this.currTopLevel=e,e.accept(this)})}visitNonTerminal(e){let t=this.nameToTopRule[e.nonTerminalName];if(t)e.referencedRule=t;else{let t=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:t,type:Mx.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}}},gb=class extends qv{constructor(e,t){super(),this.topProd=e,this.path=t,this.possibleTokTypes=[],this.nextProductionName=``,this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error(`The path does not start with the walker's top Rule!`);return this.ruleStack=[...this.path.ruleStack].reverse(),this.occurrenceStack=[...this.path.occurrenceStack].reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(e,t=[]){this.found||super.walk(e,t)}walkProdRef(e,t,n){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){let r=t.concat(n);this.updateExpectedNext(),this.walk(e.referencedRule,r)}}updateExpectedNext(){this.ruleStack.length===0?(this.nextProductionName=``,this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}},_b=class extends gb{constructor(e,t){super(e,t),this.path=t,this.nextTerminalName=``,this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(e,t,n){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){let e=new Pv({definition:t.concat(n)});this.possibleTokTypes=Yv(e),this.found=!0}}},vb=class extends qv{constructor(e,t){super(),this.topRule=e,this.occurrence=t,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}},yb=class extends vb{walkMany(e,t,n){if(e.idx===this.occurrence){let e=t.concat(n)[0];this.result.isEndOfRule=e===void 0,e instanceof Vv&&(this.result.token=e.terminalType,this.result.occurrence=e.idx)}else super.walkMany(e,t,n)}},bb=class extends vb{walkManySep(e,t,n){if(e.idx===this.occurrence){let e=t.concat(n)[0];this.result.isEndOfRule=e===void 0,e instanceof Vv&&(this.result.token=e.terminalType,this.result.occurrence=e.idx)}else super.walkManySep(e,t,n)}},xb=class extends vb{walkAtLeastOne(e,t,n){if(e.idx===this.occurrence){let e=t.concat(n)[0];this.result.isEndOfRule=e===void 0,e instanceof Vv&&(this.result.token=e.terminalType,this.result.occurrence=e.idx)}else super.walkAtLeastOne(e,t,n)}},Sb=class extends vb{walkAtLeastOneSep(e,t,n){if(e.idx===this.occurrence){let e=t.concat(n)[0];this.result.isEndOfRule=e===void 0,e instanceof Vv&&(this.result.token=e.terminalType,this.result.occurrence=e.idx)}else super.walkAtLeastOneSep(e,t,n)}};function Cb(e,t,n=[]){n=[...n];let r=[],i=0;function a(a){let o=Cb(a.concat(e.slice(i+1)),t,n);return r.concat(o)}for(;n.length<t&&i<e.length;){let t=e[i];if(t instanceof Pv||t instanceof Mv)return a(t.definition);if(t instanceof Fv)r=a(t.definition);else{if(t instanceof Iv)return a(t.definition.concat([new Rv({definition:t.definition})]));if(t instanceof Lv)return a([new Pv({definition:t.definition}),new Rv({definition:[new Vv({terminalType:t.separator})].concat(t.definition)})]);if(t instanceof zv)r=a(t.definition.concat([new Rv({definition:[new Vv({terminalType:t.separator})].concat(t.definition)})]));else if(t instanceof Rv)r=a(t.definition.concat([new Rv({definition:t.definition})]));else{if(t instanceof Bv)return t.definition.forEach(e=>{e.definition.length!==0&&(r=a(e.definition))}),r;if(!(t instanceof Vv))throw Error(`non exhaustive match`);n.push(t.terminalType)}}i++}return r.push({partialPath:n,suffixDef:e.slice(i)}),r}function wb(e,t,n,r){let i=[...n];i.push(e.name);let a=[...r];return a.push(1),{idx:t,def:e.definition,ruleStack:i,occurrenceStack:a}}function Tb(e){if(e instanceof Fv||e===`Option`)return mb.OPTION;if(e instanceof Rv||e===`Repetition`)return mb.REPETITION;if(e instanceof Iv||e===`RepetitionMandatory`)return mb.REPETITION_MANDATORY;if(e instanceof Lv||e===`RepetitionMandatoryWithSeparator`)return mb.REPETITION_MANDATORY_WITH_SEPARATOR;if(e instanceof zv||e===`RepetitionWithSeparator`)return mb.REPETITION_WITH_SEPARATOR;if(e instanceof Bv||e===`Alternation`)return mb.ALTERNATION;throw Error(`non exhaustive match`)}function Eb(e,t,n,r){let i=e.length,a=e.every(e=>e.every(e=>e.length===1));if(t)return function(t){let r=t.map(e=>e.GATE);for(let t=0;t<i;t++){let i=e[t],a=i.length,o=r[t];if(o===void 0||!1!==o.call(this))t:for(let e=0;e<a;e++){let r=i[e],a=r.length;for(let e=0;e<a;e++)if(!1===n(this.LA_FAST(e+1),r[e]))continue t;return t}}};if(a&&!r){let t=e.map(e=>e.flat()).reduce((e,t,n)=>(t.forEach(t=>{t.tokenTypeIdx in e||(e[t.tokenTypeIdx]=n),t.categoryMatches.forEach(t=>{Object.hasOwn(e,t)||(e[t]=n)})}),e),{});return function(){let e=this.LA_FAST(1);return t[e.tokenTypeIdx]}}return function(){for(let t=0;t<i;t++){let r=e[t],i=r.length;t:for(let e=0;e<i;e++){let i=r[e],a=i.length;for(let e=0;e<a;e++)if(!1===n(this.LA_FAST(e+1),i[e]))continue t;return t}}}}function Db(e,t,n){let r=e.every(e=>e.length===1),i=e.length;if(r&&!n){let t=e.flat();if(t.length===1&&t[0].categoryMatches.length===0){let e=t[0].tokenTypeIdx;return function(){return this.LA_FAST(1).tokenTypeIdx===e}}{let e=t.reduce((e,t,n)=>(e[t.tokenTypeIdx]=!0,t.categoryMatches.forEach(t=>{e[t]=!0}),e),[]);return function(){let t=this.LA_FAST(1);return!0===e[t.tokenTypeIdx]}}}return function(){t:for(let n=0;n<i;n++){let r=e[n],i=r.length;for(let e=0;e<i;e++)if(!1===t(this.LA_FAST(e+1),r[e]))continue t;return!0}return!1}}(function(e){e[e.OPTION=0]=`OPTION`,e[e.REPETITION=1]=`REPETITION`,e[e.REPETITION_MANDATORY=2]=`REPETITION_MANDATORY`,e[e.REPETITION_MANDATORY_WITH_SEPARATOR=3]=`REPETITION_MANDATORY_WITH_SEPARATOR`,e[e.REPETITION_WITH_SEPARATOR=4]=`REPETITION_WITH_SEPARATOR`,e[e.ALTERNATION=5]=`ALTERNATION`})(mb||={});var Ob=class extends qv{constructor(e,t,n){super(),this.topProd=e,this.targetOccurrence=t,this.targetProdType=n}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(e,t,n,r){return e.idx===this.targetOccurrence&&this.targetProdType===t&&(this.restDef=n.concat(r),!0)}walkOption(e,t,n){this.checkIsTarget(e,mb.OPTION,t,n)||super.walkOption(e,t,n)}walkAtLeastOne(e,t,n){this.checkIsTarget(e,mb.REPETITION_MANDATORY,t,n)||super.walkOption(e,t,n)}walkAtLeastOneSep(e,t,n){this.checkIsTarget(e,mb.REPETITION_MANDATORY_WITH_SEPARATOR,t,n)||super.walkOption(e,t,n)}walkMany(e,t,n){this.checkIsTarget(e,mb.REPETITION,t,n)||super.walkOption(e,t,n)}walkManySep(e,t,n){this.checkIsTarget(e,mb.REPETITION_WITH_SEPARATOR,t,n)||super.walkOption(e,t,n)}},kb=class extends Wv{constructor(e,t,n){super(),this.targetOccurrence=e,this.targetProdType=t,this.targetRef=n,this.result=[]}checkIsTarget(e,t){e.idx!==this.targetOccurrence||this.targetProdType!==t||this.targetRef!==void 0&&e!==this.targetRef||(this.result=e.definition)}visitOption(e){this.checkIsTarget(e,mb.OPTION)}visitRepetition(e){this.checkIsTarget(e,mb.REPETITION)}visitRepetitionMandatory(e){this.checkIsTarget(e,mb.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(e){this.checkIsTarget(e,mb.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(e){this.checkIsTarget(e,mb.REPETITION_WITH_SEPARATOR)}visitAlternation(e){this.checkIsTarget(e,mb.ALTERNATION)}};function Ab(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=[];return t}function jb(e){let t=[``];for(let n=0;n<e.length;n++){let r=e[n],i=[];for(let e=0;e<t.length;e++){let n=t[e];i.push(n+`_`+r.tokenTypeIdx);for(let e=0;e<r.categoryMatches.length;e++){let t=`_`+r.categoryMatches[e];i.push(n+t)}}t=i}return t}function Mb(e,t,n){for(let r=0;r<e.length;r++){if(r===n)continue;let i=e[r];for(let e=0;e<t.length;e++)if(!0===i[t[e]])return!1}return!0}function Nb(e,t){let n=e.map(e=>Cb([e],1)),r=Ab(n.length),i=n.map(e=>{let t={};return e.forEach(e=>{jb(e.partialPath).forEach(e=>{t[e]=!0})}),t}),a=n;for(let e=1;e<=t;e++){let n=a;a=Ab(n.length);for(let o=0;o<n.length;o++){let s=n[o];for(let n=0;n<s.length;n++){let c=s[n].partialPath,l=s[n].suffixDef,u=jb(c);if(Mb(i,u,o)||l.length===0||c.length===t){let e=r[o];if(!1===Ib(e,c)){e.push(c);for(let e=0;e<u.length;e++){let t=u[e];i[o][t]=!0}}}else{let t=Cb(l,e+1,c);a[o]=a[o].concat(t),t.forEach(e=>{jb(e.partialPath).forEach(e=>{i[o][e]=!0})})}}}}return r}function Pb(e,t,n,r){let i=new kb(e,mb.ALTERNATION,r);return t.accept(i),Nb(i.result,n)}function Fb(e,t,n,r){let i=new kb(e,n);t.accept(i);let a=i.result,o=new Ob(t,e,n).startWalking();return Nb([new Pv({definition:a}),new Pv({definition:o})],r)}function Ib(e,t){t:for(let n=0;n<e.length;n++){let r=e[n];if(r.length===t.length){for(let e=0;e<r.length;e++){let n=t[e],i=r[e];if((n===i||i.categoryMatchesMap[n.tokenTypeIdx]!==void 0)==0)continue t}return!0}}return!1}function Lb(e){return e.every(e=>e.every(e=>e.every(e=>e.categoryMatches.length===0)))}function Rb(e,t,n,r){let i=e.flatMap(e=>function(e,t){let n=new Vb;e.accept(n);let r=n.allProductions,i=Object.groupBy(r,zb),a=Object.fromEntries(Object.entries(i).filter(([e,t])=>t.length>1));return Object.values(a).map(n=>{let r=n[0],i=t.buildDuplicateFoundError(e,n),a=Kv(r),o={message:i,type:Mx.DUPLICATE_PRODUCTIONS,ruleName:e.name,dslName:a,occurrence:r.idx},s=Bb(r);return s&&(o.parameter=s),o})}(e,n)),a=function(e,t,n){let r=[],i=t.map(e=>e.name);return e.forEach(e=>{let t=e.name;if(i.includes(t)){let i=n.buildNamespaceConflictError(e);r.push({message:i,type:Mx.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:t})}}),r}(e,t,n),o=e.flatMap(e=>function(e,t){let n=new Wb;return e.accept(n),n.alternations.flatMap(n=>n.definition.length>255?[{message:t.buildTooManyAlternativesError({topLevelRule:e,alternation:n}),type:Mx.TOO_MANY_ALTS,ruleName:e.name,occurrence:n.idx}]:[])}(e,n)),s=e.flatMap(t=>function(e,t,n,r){let i=[];if(t.reduce((t,n)=>n.name===e.name?t+1:t,0)>1){let t=r.buildDuplicateRuleNameError({topLevelRule:e,grammarName:n});i.push({message:t,type:Mx.DUPLICATE_RULE_NAME,ruleName:e.name})}return i}(t,e,r,n));return i.concat(a,o,s)}function zb(e){return`${Kv(e)}_#_${e.idx}_#_${Bb(e)}`}function Bb(e){return e instanceof Vv?e.terminalType.name:e instanceof Mv?e.nonTerminalName:``}var Vb=class extends Wv{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(e){this.allProductions.push(e)}visitOption(e){this.allProductions.push(e)}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}visitAlternation(e){this.allProductions.push(e)}visitTerminal(e){this.allProductions.push(e)}};function Hb(e,t,n,r=[]){let i=[],a=Ub(t.definition);if(a.length===0)return[];{let t=e.name;a.includes(e)&&i.push({message:n.buildLeftRecursionError({topLevelRule:e,leftRecursionPath:r}),type:Mx.LEFT_RECURSION,ruleName:t});let o=r.concat([e]),s=a.filter(e=>!o.includes(e)).flatMap(t=>{let i=[...r];return i.push(t),Hb(e,t,n,i)});return i.concat(s)}}function Ub(e){let t=[];if(e.length===0)return t;let n=e[0];if(n instanceof Mv)t.push(n.referencedRule);else if(n instanceof Pv||n instanceof Fv||n instanceof Iv||n instanceof Lv||n instanceof zv||n instanceof Rv)t=t.concat(Ub(n.definition));else if(n instanceof Bv)t=n.definition.map(e=>Ub(e.definition)).flat();else if(!(n instanceof Vv))throw Error(`non exhaustive match`);let r=Gv(n),i=e.length>1;if(r&&i){let n=e.slice(1);return t.concat(Ub(n))}return t}var Wb=class extends Wv{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}};function Gb(e,t){let n=new Wb;return e.accept(n),n.alternations.flatMap(n=>n.definition.slice(0,-1).flatMap((r,i)=>function(e,t,n,r){let i=`EXIT_NONE_TERMINAL`,a=[i],o=`EXIT_ALTERNATIVE`,s=!1,c=t.length,l=c-r-1,u=[],d=[];for(d.push({idx:-1,def:e,ruleStack:[],occurrenceStack:[]});d.length!==0;){let e=d.pop();if(e===o){s&&d.at(-1).idx<=l&&d.pop();continue}let r=e.def,f=e.idx,p=e.ruleStack,m=e.occurrenceStack;if(r.length===0)continue;let h=r[0];if(h===i){let e={idx:f,def:r.slice(1),ruleStack:p.slice(0,-1),occurrenceStack:m.slice(0,-1)};d.push(e)}else if(h instanceof Vv)if(f<c-1){let e=f+1;if(n(t[e],h.terminalType)){let t={idx:e,def:r.slice(1),ruleStack:p,occurrenceStack:m};d.push(t)}}else{if(f!==c-1)throw Error(`non exhaustive match`);u.push({nextTokenType:h.terminalType,nextTokenOccurrence:h.idx,ruleStack:p,occurrenceStack:m}),s=!0}else if(h instanceof Mv){let e=[...p];e.push(h.nonTerminalName);let t=[...m];t.push(h.idx);let n={idx:f,def:h.definition.concat(a,r.slice(1)),ruleStack:e,occurrenceStack:t};d.push(n)}else if(h instanceof Fv){let e={idx:f,def:r.slice(1),ruleStack:p,occurrenceStack:m};d.push(e),d.push(o);let t={idx:f,def:h.definition.concat(r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(t)}else if(h instanceof Iv){let e=new Rv({definition:h.definition,idx:h.idx}),t={idx:f,def:h.definition.concat([e],r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(t)}else if(h instanceof Lv){let e=new Rv({definition:[new Vv({terminalType:h.separator})].concat(h.definition),idx:h.idx}),t={idx:f,def:h.definition.concat([e],r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(t)}else if(h instanceof zv){let e={idx:f,def:r.slice(1),ruleStack:p,occurrenceStack:m};d.push(e),d.push(o);let t=new Rv({definition:[new Vv({terminalType:h.separator})].concat(h.definition),idx:h.idx}),n={idx:f,def:h.definition.concat([t],r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(n)}else if(h instanceof Rv){let e={idx:f,def:r.slice(1),ruleStack:p,occurrenceStack:m};d.push(e),d.push(o);let t=new Rv({definition:h.definition,idx:h.idx}),n={idx:f,def:h.definition.concat([t],r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(n)}else if(h instanceof Bv)for(let e=h.definition.length-1;e>=0;e--){let t={idx:f,def:h.definition[e].definition.concat(r.slice(1)),ruleStack:p,occurrenceStack:m};d.push(t),d.push(o)}else if(h instanceof Pv)d.push({idx:f,def:h.definition.concat(r.slice(1)),ruleStack:p,occurrenceStack:m});else{if(!(h instanceof Nv))throw Error(`non exhaustive match`);d.push(wb(h,f,p,m))}}return u}([r],[],zy,1).length===0?[{message:t.buildEmptyAlternationError({topLevelRule:e,alternation:n,emptyChoiceIdx:i}),type:Mx.NONE_LAST_EMPTY_ALT,ruleName:e.name,occurrence:n.idx,alternative:i+1}]:[]))}function Kb(e,t,n){let r=new Wb;e.accept(r);let i=r.alternations;return i=i.filter(e=>!0!==e.ignoreAmbiguities),i.flatMap(r=>{let i=Pb(r.idx,e,r.maxLookahead||t,r),a=function(e,t,n,r){let i=[];return e.reduce((n,r,a)=>(!0===t.definition[a].ignoreAmbiguities||r.forEach(r=>{let o=[a];e.forEach((e,n)=>{a!==n&&Ib(e,r)&&!0!==t.definition[n].ignoreAmbiguities&&o.push(n)}),o.length>1&&!Ib(i,r)&&(i.push(r),n.push({alts:o,path:r}))}),n),[]).map(e=>{let i=e.alts.map(e=>e+1);return{message:r.buildAlternationAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:i,prefixPath:e.path}),type:Mx.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:t.idx,alternatives:e.alts}})}(i,r,e,n),o=function(e,t,n,r){let i=e.reduce((e,t,n)=>{let r=t.map(e=>({idx:n,path:e}));return e.concat(r)},[]);return i.flatMap(e=>{if(!0===t.definition[e.idx].ignoreAmbiguities)return[];let a=e.idx,o=e.path;return i.filter(e=>{return!0!==t.definition[e.idx].ignoreAmbiguities&&e.idx<a&&(n=e.path,r=o,n.length<r.length&&n.every((e,t)=>{let n=r[t];return e===n||n.categoryMatchesMap[e.tokenTypeIdx]}));var n,r}).map(e=>{let i=[e.idx+1,a+1],o=t.idx===0?``:t.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:i,prefixPath:e.path}),type:Mx.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:o,alternatives:i}})})}(i,r,e,n);return a.concat(o)})}var qb=class extends Wv{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}};function Jb(e){let t=Object.assign({errMsgProvider:fb},e),n={};return e.rules.forEach(e=>{n[e.name]=e}),function(e,t){let n=new hb(e,t);return n.resolveRefs(),n.errors}(n,t.errMsgProvider)}var Yb=`MismatchedTokenException`,Xb=`NoViableAltException`,Zb=`EarlyExitException`,Qb=`NotAllInputParsedException`,$b=[Yb,Xb,Zb,Qb];function ex(e){return $b.includes(e.name)}Object.freeze($b);var tx=class extends Error{constructor(e,t){super(e),this.token=t,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},nx=class extends tx{constructor(e,t,n){super(e,t),this.previousToken=n,this.name=Yb}},rx=class extends tx{constructor(e,t,n){super(e,t),this.previousToken=n,this.name=Xb}},ix=class extends tx{constructor(e,t){super(e,t),this.name=Qb}},ax=class extends tx{constructor(e,t,n){super(e,t),this.previousToken=n,this.name=Zb}},ox={},sx=class extends Error{constructor(e){super(e),this.name=`InRuleRecoveryException`}};function cx(e,t,n,r,i,a,o){let s=this.getKeyForAutomaticLookahead(r,i),c=this.firstAfterRepMap[s];if(c===void 0){let e=this.getCurrRuleFullName();c=new a(this.getGAstProductions()[e],i).startWalking(),this.firstAfterRepMap[s]=c}let l=c.token,u=c.occurrence,d=c.isEndOfRule;this.RULE_STACK_IDX===0&&d&&l===void 0&&(l=lb,u=1),l!==void 0&&u!==void 0&&this.shouldInRepetitionRecoveryBeTried(l,u,o)&&this.tryInRepetitionRecovery(e,t,n,l)}var lx=1024,ux=1280,dx=1536;function fx(e,t,n){return n|t|e}var px=class{constructor(e){this.maxLookahead=e?.maxLookahead??Nx.maxLookahead}validate(e){let t=this.validateNoLeftRecursion(e.rules);if(t.length===0){let n=this.validateEmptyOrAlternatives(e.rules),r=this.validateAmbiguousAlternationAlternatives(e.rules,this.maxLookahead),i=this.validateSomeNonEmptyLookaheadPath(e.rules,this.maxLookahead);return[...t,...n,...r,...i]}return t}validateNoLeftRecursion(e){return e.flatMap(e=>Hb(e,e,pb))}validateEmptyOrAlternatives(e){return e.flatMap(e=>Gb(e,pb))}validateAmbiguousAlternationAlternatives(e,t){return e.flatMap(e=>Kb(e,t,pb))}validateSomeNonEmptyLookaheadPath(e,t){return function(e,t,n){let r=[];return e.forEach(e=>{let i=new qb;e.accept(i),i.allProductions.forEach(i=>{let a=Tb(i),o=i.maxLookahead||t;if(Fb(i.idx,e,a,o)[0].flat().length===0){let t=n.buildEmptyRepetitionError({topLevelRule:e,repetition:i});r.push({message:t,type:Mx.NO_NON_EMPTY_LOOKAHEAD,ruleName:e.name})}})}),r}(e,t,pb)}buildLookaheadForAlternation(e){return function(e,t,n,r,i,a){let o=Pb(e,t,n);return a(o,r,Lb(o)?By:zy,i)}(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,Eb)}buildLookaheadForOptional(e){return function(e,t,n,r,i,a){let o=Fb(e,t,i,n),s=Lb(o)?By:zy;return a(o[0],s,r)}(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,Tb(e.prodType),Db)}},mx=new class extends Wv{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(e){this.dslMethods.option.push(e)}visitRepetitionWithSeparator(e){this.dslMethods.repetitionWithSeparator.push(e)}visitRepetitionMandatory(e){this.dslMethods.repetitionMandatory.push(e)}visitRepetitionMandatoryWithSeparator(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)}visitRepetition(e){this.dslMethods.repetition.push(e)}visitAlternation(e){this.dslMethods.alternation.push(e)}};function hx(e,t){e.startOffset===-1?(e.startOffset=t.startOffset,e.endOffset=t.endOffset):e.endOffset<t.endOffset==1&&(e.endOffset=t.endOffset)}function gx(e,t){e.startOffset===-1?(e.startOffset=t.startOffset,e.startColumn=t.startColumn,e.startLine=t.startLine,e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine):e.endOffset<t.endOffset==1&&(e.endOffset=t.endOffset,e.endColumn=t.endColumn,e.endLine=t.endLine)}var _x;function vx(e,t){Object.defineProperty(e,"name",{enumerable:!1,configurable:!0,writable:!1,value:t})}function yx(e,t){let n=Object.keys(e),r=n.length;for(let i=0;i<r;i++){let r=e[n[i]],a=r.length;for(let e=0;e<a;e++){let n=r[e];n.tokenTypeIdx===void 0&&this[n.name](n.children,t)}}}function bx(e,t){let n=function(){};return vx(n,e+`BaseSemantics`),n.prototype={visit:function(e,t){if(Array.isArray(e)&&(e=e[0]),e!==void 0)return this[e.name](e.children,t)},validateVisitor:function(){let e=function(e,t){return function(e,t){return t.filter(t=>typeof e[t]==`function`==0).map(t=>({msg:`Missing visitor method: <${t}> on ${e.constructor.name} CST Visitor.`,type:_x.MISSING_METHOD,methodName:t})).filter(Boolean)}(e,t)}(this,t);if(e.length!==0){let t=e.map(e=>e.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:\n\t${t.join(`
|
|
44
|
-
|
|
45
|
-
`).replace(/\n/g,`
|
|
46
|
-
`)}`)}}},n.prototype.constructor=n,n._RULE_NAMES=t,n}(function(e){e[e.REDUNDANT_METHOD=0]=`REDUNDANT_METHOD`,e[e.MISSING_METHOD=1]=`MISSING_METHOD`})(_x||={});var xx={description:`This Object indicates the Parser is during Recording Phase`};Object.freeze(xx);var Sx=!0,Cx=2**8-1,wx=Q({name:`RECORDING_PHASE_TOKEN`,pattern:Zy.NA});Uy([wx]);var Tx=ub(wx,`This IToken indicates the Parser is in Recording Phase
|
|
47
|
-
See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(Tx);var Ex={name:`This CSTNode indicates the Parser is in Recording Phase
|
|
48
|
-
See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};function Dx(e,t,n,r=!1){Ax(n);let i=this.recordingProdStack.at(-1),a=typeof t==`function`?t:t.DEF,o=new e({definition:[],idx:n});return r&&(o.separator=t.SEP),Object.hasOwn(t,`MAX_LOOKAHEAD`)&&(o.maxLookahead=t.MAX_LOOKAHEAD),this.recordingProdStack.push(o),a.call(this),i.definition.push(o),this.recordingProdStack.pop(),xx}function Ox(e,t){Ax(t);let n=this.recordingProdStack.at(-1),r=!1===Array.isArray(e),i=!1===r?e:e.DEF,a=new Bv({definition:[],idx:t,ignoreAmbiguities:r&&!0===e.IGNORE_AMBIGUITIES});return Object.hasOwn(e,`MAX_LOOKAHEAD`)&&(a.maxLookahead=e.MAX_LOOKAHEAD),a.hasPredicates=i.some(e=>typeof e.GATE==`function`),n.definition.push(a),i.forEach(e=>{let t=new Pv({definition:[]});a.definition.push(t),Object.hasOwn(e,`IGNORE_AMBIGUITIES`)?t.ignoreAmbiguities=e.IGNORE_AMBIGUITIES:Object.hasOwn(e,`GATE`)&&(t.ignoreAmbiguities=!0),this.recordingProdStack.push(t),e.ALT.call(this),this.recordingProdStack.pop()}),xx}function kx(e){return e===0?``:`${e}`}function Ax(e){if(e<0||e>Cx){let t=Error(`Invalid DSL Method idx value: <${e}>\n\tIdx value must be a none negative value smaller than ${Cx+1}`);throw t.KNOWN_RECORDER_ERROR=!0,t}}var jx=ub(lb,``,-1,-1,-1,-1,-1,-1);Object.freeze(jx);var Mx,Nx=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:db,nodeLocationTracking:`none`,traceInitPerf:!1,skipValidations:!1}),Px=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0});(function(e){e[e.INVALID_RULE_NAME=0]=`INVALID_RULE_NAME`,e[e.DUPLICATE_RULE_NAME=1]=`DUPLICATE_RULE_NAME`,e[e.INVALID_RULE_OVERRIDE=2]=`INVALID_RULE_OVERRIDE`,e[e.DUPLICATE_PRODUCTIONS=3]=`DUPLICATE_PRODUCTIONS`,e[e.UNRESOLVED_SUBRULE_REF=4]=`UNRESOLVED_SUBRULE_REF`,e[e.LEFT_RECURSION=5]=`LEFT_RECURSION`,e[e.NONE_LAST_EMPTY_ALT=6]=`NONE_LAST_EMPTY_ALT`,e[e.AMBIGUOUS_ALTS=7]=`AMBIGUOUS_ALTS`,e[e.CONFLICT_TOKENS_RULES_NAMESPACE=8]=`CONFLICT_TOKENS_RULES_NAMESPACE`,e[e.INVALID_TOKEN_NAME=9]=`INVALID_TOKEN_NAME`,e[e.NO_NON_EMPTY_LOOKAHEAD=10]=`NO_NON_EMPTY_LOOKAHEAD`,e[e.AMBIGUOUS_PREFIX_ALTS=11]=`AMBIGUOUS_PREFIX_ALTS`,e[e.TOO_MANY_ALTS=12]=`TOO_MANY_ALTS`,e[e.CUSTOM_LOOKAHEAD_VALIDATION=13]=`CUSTOM_LOOKAHEAD_VALIDATION`})(Mx||={});var Fx,Ix,Lx=class e{static performSelfAnalysis(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT(`performSelfAnalysis`,()=>{let t;this.selfAnalysisDone=!0;let n=this.className;this.TRACE_INIT(`toFastProps`,()=>{Av(this)}),this.TRACE_INIT(`Grammar Recording`,()=>{try{this.enableRecording(),this.definedRulesNames.forEach(e=>{let t=this[e].originalGrammarAction,n;this.TRACE_INIT(`${e} Rule`,()=>{n=this.topLevelRuleRecord(e,t)}),this.gastProductionsCache[e]=n})}finally{this.disableRecording()}});let r=[];if(this.TRACE_INIT(`Grammar Resolving`,()=>{r=Jb({rules:Object.values(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT(`Grammar Validations`,()=>{if(r.length===0&&!1===this.skipValidations){let t=function(e){let t=e.errMsgProvider??pb;return Rb(e.rules,e.tokenTypes,t,e.grammarName)}({rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),errMsgProvider:pb,grammarName:n}),r=(e={lookaheadStrategy:this.lookaheadStrategy,rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),grammarName:n}).lookaheadStrategy.validate({rules:e.rules,tokenTypes:e.tokenTypes,grammarName:e.grammarName}).map(e=>Object.assign({type:Mx.CUSTOM_LOOKAHEAD_VALIDATION},e));this.definitionErrors=this.definitionErrors.concat(t,r)}var e}),this.definitionErrors.length===0&&(this.recoveryEnabled&&this.TRACE_INIT(`computeAllProdsFollows`,()=>{let e=function(e){let t={};return e.forEach(e=>{let n=new Zv(e).startWalking();Object.assign(t,n)}),t}(Object.values(this.gastProductionsCache));this.resyncFollows=e}),this.TRACE_INIT(`ComputeLookaheadFunctions`,()=>{var e,t;(t=(e=this.lookaheadStrategy).initialize)==null||t.call(e,{rules:Object.values(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(Object.values(this.gastProductionsCache))})),!e.DEFER_DEFINITION_ERRORS_HANDLING&&this.definitionErrors.length!==0)throw t=this.definitionErrors.map(e=>e.message),Error(`Parser Definition Errors detected:\n ${t.join(`
|
|
49
|
-
-------------------------------
|
|
50
|
-
`)}`)})}constructor(e,t){this.definitionErrors=[],this.selfAnalysisDone=!1;let n=this;if(n.initErrorHandler(t),n.initLexerAdapter(),n.initLooksAhead(t),n.initRecognizerEngine(e,t),n.initRecoverable(t),n.initTreeBuilder(t),n.initGastRecorder(t),n.initPerformanceTracer(t),Object.hasOwn(t,`ignoredIssues`))throw Error(`The <ignoredIssues> IParserConfig property has been deprecated.
|
|
51
|
-
Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
|
|
52
|
-
See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
|
|
53
|
-
For further details.`);this.skipValidations=Object.hasOwn(t,`skipValidations`)?t.skipValidations:Nx.skipValidations}};Lx.DEFER_DEFINITION_ERRORS_HANDLING=!1,Fx=Lx,Ix=[class{initRecoverable(e){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=Object.hasOwn(e,`recoveryEnabled`)?e.recoveryEnabled:Nx.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=cx)}getTokenToInsert(e){let t=ub(e,``,-1,-1,-1,-1,-1,-1);return t.isInsertedInRecovery=!0,t}canTokenTypeBeInsertedInRecovery(e){return!0}canTokenTypeBeDeletedInRecovery(e){return!0}tryInRepetitionRecovery(e,t,n,r){let i=this.findReSyncTokenType(),a=this.exportLexerState(),o=[],s=!1,c=this.LA_FAST(1),l=this.LA_FAST(1),u=()=>{let e=this.LA(0),t=new nx(this.errorMessageProvider.buildMismatchTokenMessage({expected:r,actual:c,previous:e,ruleName:this.getCurrRuleFullName()}),c,this.LA(0));t.resyncedTokens=o.slice(0,-1),this.SAVE_ERROR(t)};for(;!s;){if(this.tokenMatcher(l,r))return void u();if(n.call(this))return u(),void e.apply(this,t);this.tokenMatcher(l,i)?s=!0:(l=this.SKIP_TOKEN(),this.addToResyncTokens(l,o))}this.importLexerState(a)}shouldInRepetitionRecoveryBeTried(e,t,n){return!1!==n&&!this.tokenMatcher(this.LA_FAST(1),e)&&!this.isBackTracking()&&!this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,t))}getNextPossibleTokenTypes(e){let t=e.ruleStack[0],n=this.getGAstProductions()[t];return new _b(n,e).startWalking()}getFollowsForInRuleRecovery(e,t){let n=this.getCurrentGrammarPath(e,t);return this.getNextPossibleTokenTypes(n)}tryInRuleRecovery(e,t){if(this.canRecoverWithSingleTokenInsertion(e,t))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){let e=this.SKIP_TOKEN();return this.consumeToken(),e}throw new sx(`sad sad panda`)}canPerformInRuleRecovery(e,t){return this.canRecoverWithSingleTokenInsertion(e,t)||this.canRecoverWithSingleTokenDeletion(e)}canRecoverWithSingleTokenInsertion(e,t){if(!this.canTokenTypeBeInsertedInRecovery(e)||t.length===0)return!1;let n=this.LA_FAST(1);return t.find(e=>this.tokenMatcher(n,e))!==void 0}canRecoverWithSingleTokenDeletion(e){return!!this.canTokenTypeBeDeletedInRecovery(e)&&this.tokenMatcher(this.LA(2),e)}isInCurrentRuleReSyncSet(e){let t=this.getCurrFollowKey();return this.getFollowSetFromFollowKey(t).includes(e)}findReSyncTokenType(){let e=this.flattenFollowSet(),t=this.LA_FAST(1),n=2;for(;;){let r=e.find(e=>zy(t,e));if(r!==void 0)return r;t=this.LA(n),n++}}getCurrFollowKey(){if(this.RULE_STACK_IDX===0)return ox;let e=this.currRuleShortName,t=this.getLastExplicitRuleOccurrenceIndex(),n=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(e),idxInCallingRule:t,inRule:this.shortRuleNameToFullName(n)}}buildFullFollowKeyStack(){let e=this.RULE_STACK,t=this.RULE_OCCURRENCE_STACK,n=this.RULE_STACK_IDX+1,r=Array(n);for(let i=0;i<n;i++)r[i]=i===0?ox:{ruleName:this.shortRuleNameToFullName(e[i]),idxInCallingRule:t[i],inRule:this.shortRuleNameToFullName(e[i-1])};return r}flattenFollowSet(){return this.buildFullFollowKeyStack().map(e=>this.getFollowSetFromFollowKey(e)).flat()}getFollowSetFromFollowKey(e){if(e===ox)return[lb];let t=e.ruleName+e.idxInCallingRule+Xv+e.inRule;return this.resyncFollows[t]}addToResyncTokens(e,t){return this.tokenMatcher(e,lb)||t.push(e),t}reSyncTo(e){let t=[],n=this.LA_FAST(1);for(;!1===this.tokenMatcher(n,e);)n=this.SKIP_TOKEN(),this.addToResyncTokens(n,t);return t.slice(0,-1)}attemptInRepetitionRecovery(e,t,n,r,i,a,o){}getCurrentGrammarPath(e,t){return{ruleStack:this.getHumanReadableRuleStack(),occurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1),lastTok:e,lastTokOccurrence:t}}getHumanReadableRuleStack(){let e=this.RULE_STACK_IDX+1,t=Array(e);for(let n=0;n<e;n++)t[n]=this.shortRuleNameToFullName(this.RULE_STACK[n]);return t}},class{initLooksAhead(e){this.dynamicTokensEnabled=Object.hasOwn(e,`dynamicTokensEnabled`)?e.dynamicTokensEnabled:Nx.dynamicTokensEnabled,this.maxLookahead=Object.hasOwn(e,`maxLookahead`)?e.maxLookahead:Nx.maxLookahead,this.lookaheadStrategy=Object.hasOwn(e,`lookaheadStrategy`)?e.lookaheadStrategy:new px({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=new Map}preComputeLookaheadFunctions(e){e.forEach(e=>{this.TRACE_INIT(`${e.name} Rule Lookahead`,()=>{let{alternation:t,repetition:n,option:r,repetitionMandatory:i,repetitionMandatoryWithSeparator:a,repetitionWithSeparator:o}=function(e){mx.reset(),e.accept(mx);let t=mx.dslMethods;return mx.reset(),t}(e);t.forEach(t=>{let n=t.idx===0?``:t.idx;this.TRACE_INIT(`${Kv(t)}${n}`,()=>{let n=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:t.idx,rule:e,maxLookahead:t.maxLookahead||this.maxLookahead,hasPredicates:t.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled}),r=fx(this.fullRuleNameToShort[e.name],256,t.idx);this.setLaFuncCache(r,n)})}),n.forEach(t=>{this.computeLookaheadFunc(e,t.idx,768,`Repetition`,t.maxLookahead,Kv(t))}),r.forEach(t=>{this.computeLookaheadFunc(e,t.idx,512,`Option`,t.maxLookahead,Kv(t))}),i.forEach(t=>{this.computeLookaheadFunc(e,t.idx,lx,`RepetitionMandatory`,t.maxLookahead,Kv(t))}),a.forEach(t=>{this.computeLookaheadFunc(e,t.idx,dx,`RepetitionMandatoryWithSeparator`,t.maxLookahead,Kv(t))}),o.forEach(t=>{this.computeLookaheadFunc(e,t.idx,ux,`RepetitionWithSeparator`,t.maxLookahead,Kv(t))})})})}computeLookaheadFunc(e,t,n,r,i,a){this.TRACE_INIT(`${a}${t===0?``:t}`,()=>{let a=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:t,rule:e,maxLookahead:i||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:r}),o=fx(this.fullRuleNameToShort[e.name],n,t);this.setLaFuncCache(o,a)})}getKeyForAutomaticLookahead(e,t){return fx(this.currRuleShortName,e,t)}getLaFuncFromCache(e){return this.lookAheadFuncsCache.get(e)}setLaFuncCache(e,t){this.lookAheadFuncsCache.set(e,t)}},class{initTreeBuilder(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=Object.hasOwn(e,`nodeLocationTracking`)?e.nodeLocationTracking:Nx.nodeLocationTracking,this.outputCst)if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=gx,this.setNodeLocationFromNode=gx,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=hx,this.setNodeLocationFromNode=hx,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else{if(!/none/i.test(this.nodeLocationTracking))throw Error(`Invalid <nodeLocationTracking> config option: "${e.nodeLocationTracking}"`);this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=()=>{},this.setInitialNodeLocation=()=>{}}else this.cstInvocationStateUpdate=()=>{},this.cstFinallyStateUpdate=()=>{},this.cstPostTerminal=()=>{},this.cstPostNonTerminal=()=>{},this.cstPostRule=()=>{}}setInitialNodeLocationOnlyOffsetRecovery(e){e.location={startOffset:-1,endOffset:-1}}setInitialNodeLocationOnlyOffsetRegular(e){e.location={startOffset:this.LA_FAST(1).startOffset,endOffset:-1}}setInitialNodeLocationFullRecovery(e){e.location={startOffset:-1,startLine:-1,startColumn:-1,endOffset:-1,endLine:-1,endColumn:-1}}setInitialNodeLocationFullRegular(e){let t=this.LA_FAST(1);e.location={startOffset:t.startOffset,startLine:t.startLine,startColumn:t.startColumn,endOffset:-1,endLine:-1,endColumn:-1}}cstInvocationStateUpdate(e){let t={name:e,children:Object.create(null)};this.setInitialNodeLocation(t),this.CST_STACK.push(t)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(e){let t=this.LA(0),n=e.location;n.startOffset!==-1&&n.startOffset<=t.startOffset==1?(n.endOffset=t.endOffset,n.endLine=t.endLine,n.endColumn=t.endColumn):(n.startOffset=-1,n.startLine=-1,n.startColumn=-1)}cstPostRuleOnlyOffset(e){let t=this.LA(0),n=e.location;n.startOffset!==-1&&n.startOffset<=t.startOffset==1?n.endOffset=t.endOffset:n.startOffset=-1}cstPostTerminal(e,t){let n=this.CST_STACK[this.CST_STACK.length-1];var r,i=t,a=e;(r=n).children[a]===void 0?r.children[a]=[i]:r.children[a].push(i),this.setNodeLocationFromToken(n.location,t)}cstPostNonTerminal(e,t){let n=this.CST_STACK[this.CST_STACK.length-1];(function(e,t,n){e.children[t]===void 0?e.children[t]=[n]:e.children[t].push(n)})(n,t,e),this.setNodeLocationFromNode(n.location,e.location)}get currCSTNode(){return this.CST_STACK[this.CST_STACK.length-1]}getBaseCstVisitorConstructor(){if(this.baseCstVisitorConstructor===void 0){let e=bx(this.className,Object.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(this.baseCstVisitorWithDefaultsConstructor===void 0){let e=function(e,t,n){let r=function(){};vx(r,e+`BaseSemanticsWithDefaults`);let i=Object.create(n.prototype);return t.forEach(e=>{i[e]=yx}),(r.prototype=i).constructor=r,r}(this.className,Object.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor}getPreviousExplicitRuleShortName(){return this.RULE_STACK[this.RULE_STACK_IDX-1]}getLastExplicitRuleOccurrenceIndex(){return this.RULE_OCCURRENCE_STACK[this.RULE_OCCURRENCE_STACK_IDX]}},class{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(e){if(!0!==this.selfAnalysisDone)throw Error(`Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.`);this.reset(),this.tokVector=e,this.tokVectorLength=e.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVectorLength-2?(this.consumeToken(),this.LA_FAST(1)):jx}LA_FAST(e){let t=this.currIdx+e;return this.tokVector[t]}LA(e){let t=this.currIdx+e;return t<0||this.tokVectorLength<=t?jx:this.tokVector[t]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(e){this.currIdx=e}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVectorLength-1}getLexerPosition(){return this.exportLexerState()}},class{initRecognizerEngine(e,t){if(this.className=this.constructor.name,this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=By,this.subruleIdx=0,this.currRuleShortName=0,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK=[],this.RULE_OCCURRENCE_STACK_IDX=-1,this.gastProductionsCache={},Object.hasOwn(t,`serializedGrammar`))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
|
|
54
|
-
See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
|
|
55
|
-
For Further details.`);if(Array.isArray(e)){if(e.length===0)throw Error(`A Token Vocabulary cannot be empty.
|
|
56
|
-
Note that the first argument for the parser constructor
|
|
57
|
-
is no longer a Token vector (since v4.0).`);if(typeof e[0].startOffset==`number`)throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
|
|
58
|
-
See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
|
|
59
|
-
For Further details.`)}if(Array.isArray(e))this.tokensMap=e.reduce((e,t)=>(e[t.name]=t,e),{});else if(Object.hasOwn(e,`modes`)&&Object.values(e.modes).flat().every(qy)){let t=Object.values(e.modes).flat(),n=[...new Set(t)];this.tokensMap=n.reduce((e,t)=>(e[t.name]=t,e),{})}else{if(typeof e!=`object`||!e)throw Error(`<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition`);this.tokensMap=Object.assign({},e)}this.tokensMap.EOF=lb;let n=(Object.hasOwn(e,`modes`)?Object.values(e.modes).flat():Object.values(e)).every(e=>e.categoryMatches?.length==0);this.tokenMatcher=n?By:zy,Uy(Object.values(this.tokensMap))}defineRule(e,t,n){if(this.selfAnalysisDone)throw Error(`Grammar rule <${e}> may not be defined after the 'performSelfAnalysis' method has been called'\nMake sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);let r=Object.hasOwn(n,`resyncEnabled`)?n.resyncEnabled:Px.resyncEnabled,i=Object.hasOwn(n,`recoveryValueFunc`)?n.recoveryValueFunc:Px.recoveryValueFunc,a=this.ruleShortNameIdx<<12,o;return this.ruleShortNameIdx++,this.shortRuleNameToFull[a]=e,this.fullRuleNameToShort[e]=a,o=!0===this.outputCst?function(...n){try{this.ruleInvocationStateUpdate(a,e,this.subruleIdx),t.apply(this,n);let r=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(r),r}catch(e){return this.invokeRuleCatch(e,r,i)}finally{this.ruleFinallyStateUpdate()}}:function(...n){try{return this.ruleInvocationStateUpdate(a,e,this.subruleIdx),t.apply(this,n)}catch(e){return this.invokeRuleCatch(e,r,i)}finally{this.ruleFinallyStateUpdate()}},Object.assign(function(...t){this.onBeforeParse(e);try{return o.apply(this,t)}finally{this.onAfterParse(e)}},{ruleName:e,originalGrammarAction:t,coreRule:o})}invokeRuleCatch(e,t,n){let r=this.RULE_STACK_IDX===0,i=t&&!this.isBackTracking()&&this.recoveryEnabled;if(ex(e)){let t=e;if(i){let r=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(r)){if(t.resyncedTokens=this.reSyncTo(r),this.outputCst){let e=this.CST_STACK[this.CST_STACK.length-1];return e.recoveredNode=!0,e}return n(e)}if(this.outputCst){let e=this.CST_STACK[this.CST_STACK.length-1];e.recoveredNode=!0,t.partialCstResult=e}throw t}if(r)return this.moveToTerminatedState(),n(e);throw t}throw e}optionInternal(e,t){let n=this.getKeyForAutomaticLookahead(512,t);return this.optionInternalLogic(e,t,n)}optionInternalLogic(e,t,n){let r,i=this.getLaFuncFromCache(n);if(typeof e!=`function`){r=e.DEF;let t=e.GATE;if(t!==void 0){let e=i;i=()=>t.call(this)&&e.call(this)}}else r=e;if(!0===i.call(this))return r.call(this)}atLeastOneInternal(e,t){let n=this.getKeyForAutomaticLookahead(lx,e);return this.atLeastOneInternalLogic(e,t,n)}atLeastOneInternalLogic(e,t,n){let r,i=this.getLaFuncFromCache(n);if(typeof t!=`function`){r=t.DEF;let e=t.GATE;if(e!==void 0){let t=i;i=()=>e.call(this)&&t.call(this)}}else r=t;if(!0!==i.call(this))throw this.raiseEarlyExitException(e,mb.REPETITION_MANDATORY,t.ERR_MSG);{let e=this.doSingleRepetition(r);for(;!0===i.call(this)&&!0===e;)e=this.doSingleRepetition(r)}this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,t],i,lx,e,xb)}atLeastOneSepFirstInternal(e,t){let n=this.getKeyForAutomaticLookahead(dx,e);this.atLeastOneSepFirstInternalLogic(e,t,n)}atLeastOneSepFirstInternalLogic(e,t,n){let r=t.DEF,i=t.SEP;if(!0!==this.getLaFuncFromCache(n).call(this))throw this.raiseEarlyExitException(e,mb.REPETITION_MANDATORY_WITH_SEPARATOR,t.ERR_MSG);{r.call(this);let t=()=>this.tokenMatcher(this.LA_FAST(1),i);for(;!0===this.tokenMatcher(this.LA_FAST(1),i);)this.CONSUME(i),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,i,t,r,Sb],t,dx,e,Sb)}}manyInternal(e,t){let n=this.getKeyForAutomaticLookahead(768,e);return this.manyInternalLogic(e,t,n)}manyInternalLogic(e,t,n){let r,i=this.getLaFuncFromCache(n);if(typeof t!=`function`){r=t.DEF;let e=t.GATE;if(e!==void 0){let t=i;i=()=>e.call(this)&&t.call(this)}}else r=t;let a=!0;for(;!0===i.call(this)&&!0===a;)a=this.doSingleRepetition(r);this.attemptInRepetitionRecovery(this.manyInternal,[e,t],i,768,e,yb,a)}manySepFirstInternal(e,t){let n=this.getKeyForAutomaticLookahead(ux,e);this.manySepFirstInternalLogic(e,t,n)}manySepFirstInternalLogic(e,t,n){let r=t.DEF,i=t.SEP;if(!0===this.getLaFuncFromCache(n).call(this)){r.call(this);let t=()=>this.tokenMatcher(this.LA_FAST(1),i);for(;!0===this.tokenMatcher(this.LA_FAST(1),i);)this.CONSUME(i),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,i,t,r,bb],t,ux,e,bb)}}repetitionSepSecondInternal(e,t,n,r,i){for(;n();)this.CONSUME(t),r.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,t,n,r,i],n,dx,e,i)}doSingleRepetition(e){let t=this.getLexerPosition();return e.call(this),this.getLexerPosition()>t}orInternal(e,t){let n=this.getKeyForAutomaticLookahead(256,t),r=Array.isArray(e)?e:e.DEF,i=this.getLaFuncFromCache(n).call(this,r);if(i!==void 0)return r[i].ALT.call(this);this.raiseNoAltException(t,e.ERR_MSG)}ruleFinallyStateUpdate(){this.RULE_STACK_IDX--,this.RULE_OCCURRENCE_STACK_IDX--,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX]),this.cstFinallyStateUpdate()}subruleInternal(e,t,n){let r;try{let i=n===void 0?void 0:n.ARGS;return this.subruleIdx=t,r=e.coreRule.apply(this,i),this.cstPostNonTerminal(r,n!==void 0&&n.LABEL!==void 0?n.LABEL:e.ruleName),r}catch(t){throw this.subruleInternalError(t,n,e.ruleName)}}subruleInternalError(e,t,n){throw ex(e)&&e.partialCstResult!==void 0&&(this.cstPostNonTerminal(e.partialCstResult,t!==void 0&&t.LABEL!==void 0?t.LABEL:n),delete e.partialCstResult),e}consumeInternal(e,t,n){let r;try{let t=this.LA_FAST(1);!0===this.tokenMatcher(t,e)?(this.consumeToken(),r=t):this.consumeInternalError(e,t,n)}catch(n){r=this.consumeInternalRecovery(e,t,n)}return this.cstPostTerminal(n!==void 0&&n.LABEL!==void 0?n.LABEL:e.name,r),r}consumeInternalError(e,t,n){let r,i=this.LA(0);throw r=n!==void 0&&n.ERR_MSG?n.ERR_MSG:this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:t,previous:i,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new nx(r,t,i))}consumeInternalRecovery(e,t,n){if(!this.recoveryEnabled||n.name!==`MismatchedTokenException`||this.isBackTracking())throw n;{let r=this.getFollowsForInRuleRecovery(e,t);try{return this.tryInRuleRecovery(e,r)}catch(e){throw e.name===`InRuleRecoveryException`?n:e}}}saveRecogState(){let e=this.errors,t=this.RULE_STACK.slice(0,this.RULE_STACK_IDX+1);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:t,CST_STACK:this.CST_STACK}}reloadRecogState(e){this.errors=e.errors,this.importLexerState(e.lexerState);let t=e.RULE_STACK;for(let e=0;e<t.length;e++)this.RULE_STACK[e]=t[e];this.RULE_STACK_IDX=t.length-1,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX])}ruleInvocationStateUpdate(e,t,n){this.RULE_OCCURRENCE_STACK[++this.RULE_OCCURRENCE_STACK_IDX]=n,this.RULE_STACK[++this.RULE_STACK_IDX]=e,this.currRuleShortName=e,this.cstInvocationStateUpdate(t)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){let e=this.currRuleShortName;return this.shortRuleNameToFull[e]}shortRuleNameToFullName(e){return this.shortRuleNameToFull[e]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),lb)}reset(){this.resetLexerState(),this.subruleIdx=0,this.currRuleShortName=0,this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK_IDX=-1,this.CST_STACK=[]}onBeforeParse(e){for(let e=0;e<this.maxLookahead+1;e++)this.tokVector.push(jx)}onAfterParse(e){if(!1===this.isAtEndOfInput()){let e=this.LA(1),t=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:e,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new ix(t,e))}for(;this.tokVector.at(-1)===jx;)this.tokVector.pop()}},class{ACTION(e){return e.call(this)}consume(e,t,n){return this.consumeInternal(t,e,n)}subrule(e,t,n){return this.subruleInternal(t,e,n)}option(e,t){return this.optionInternal(t,e)}or(e,t){return this.orInternal(t,e)}many(e,t){return this.manyInternal(e,t)}atLeastOne(e,t){return this.atLeastOneInternal(e,t)}CONSUME(e,t){return this.consumeInternal(e,0,t)}CONSUME1(e,t){return this.consumeInternal(e,1,t)}CONSUME2(e,t){return this.consumeInternal(e,2,t)}CONSUME3(e,t){return this.consumeInternal(e,3,t)}CONSUME4(e,t){return this.consumeInternal(e,4,t)}CONSUME5(e,t){return this.consumeInternal(e,5,t)}CONSUME6(e,t){return this.consumeInternal(e,6,t)}CONSUME7(e,t){return this.consumeInternal(e,7,t)}CONSUME8(e,t){return this.consumeInternal(e,8,t)}CONSUME9(e,t){return this.consumeInternal(e,9,t)}SUBRULE(e,t){return this.subruleInternal(e,0,t)}SUBRULE1(e,t){return this.subruleInternal(e,1,t)}SUBRULE2(e,t){return this.subruleInternal(e,2,t)}SUBRULE3(e,t){return this.subruleInternal(e,3,t)}SUBRULE4(e,t){return this.subruleInternal(e,4,t)}SUBRULE5(e,t){return this.subruleInternal(e,5,t)}SUBRULE6(e,t){return this.subruleInternal(e,6,t)}SUBRULE7(e,t){return this.subruleInternal(e,7,t)}SUBRULE8(e,t){return this.subruleInternal(e,8,t)}SUBRULE9(e,t){return this.subruleInternal(e,9,t)}OPTION(e){return this.optionInternal(e,0)}OPTION1(e){return this.optionInternal(e,1)}OPTION2(e){return this.optionInternal(e,2)}OPTION3(e){return this.optionInternal(e,3)}OPTION4(e){return this.optionInternal(e,4)}OPTION5(e){return this.optionInternal(e,5)}OPTION6(e){return this.optionInternal(e,6)}OPTION7(e){return this.optionInternal(e,7)}OPTION8(e){return this.optionInternal(e,8)}OPTION9(e){return this.optionInternal(e,9)}OR(e){return this.orInternal(e,0)}OR1(e){return this.orInternal(e,1)}OR2(e){return this.orInternal(e,2)}OR3(e){return this.orInternal(e,3)}OR4(e){return this.orInternal(e,4)}OR5(e){return this.orInternal(e,5)}OR6(e){return this.orInternal(e,6)}OR7(e){return this.orInternal(e,7)}OR8(e){return this.orInternal(e,8)}OR9(e){return this.orInternal(e,9)}MANY(e){this.manyInternal(0,e)}MANY1(e){this.manyInternal(1,e)}MANY2(e){this.manyInternal(2,e)}MANY3(e){this.manyInternal(3,e)}MANY4(e){this.manyInternal(4,e)}MANY5(e){this.manyInternal(5,e)}MANY6(e){this.manyInternal(6,e)}MANY7(e){this.manyInternal(7,e)}MANY8(e){this.manyInternal(8,e)}MANY9(e){this.manyInternal(9,e)}MANY_SEP(e){this.manySepFirstInternal(0,e)}MANY_SEP1(e){this.manySepFirstInternal(1,e)}MANY_SEP2(e){this.manySepFirstInternal(2,e)}MANY_SEP3(e){this.manySepFirstInternal(3,e)}MANY_SEP4(e){this.manySepFirstInternal(4,e)}MANY_SEP5(e){this.manySepFirstInternal(5,e)}MANY_SEP6(e){this.manySepFirstInternal(6,e)}MANY_SEP7(e){this.manySepFirstInternal(7,e)}MANY_SEP8(e){this.manySepFirstInternal(8,e)}MANY_SEP9(e){this.manySepFirstInternal(9,e)}AT_LEAST_ONE(e){this.atLeastOneInternal(0,e)}AT_LEAST_ONE1(e){return this.atLeastOneInternal(1,e)}AT_LEAST_ONE2(e){this.atLeastOneInternal(2,e)}AT_LEAST_ONE3(e){this.atLeastOneInternal(3,e)}AT_LEAST_ONE4(e){this.atLeastOneInternal(4,e)}AT_LEAST_ONE5(e){this.atLeastOneInternal(5,e)}AT_LEAST_ONE6(e){this.atLeastOneInternal(6,e)}AT_LEAST_ONE7(e){this.atLeastOneInternal(7,e)}AT_LEAST_ONE8(e){this.atLeastOneInternal(8,e)}AT_LEAST_ONE9(e){this.atLeastOneInternal(9,e)}AT_LEAST_ONE_SEP(e){this.atLeastOneSepFirstInternal(0,e)}AT_LEAST_ONE_SEP1(e){this.atLeastOneSepFirstInternal(1,e)}AT_LEAST_ONE_SEP2(e){this.atLeastOneSepFirstInternal(2,e)}AT_LEAST_ONE_SEP3(e){this.atLeastOneSepFirstInternal(3,e)}AT_LEAST_ONE_SEP4(e){this.atLeastOneSepFirstInternal(4,e)}AT_LEAST_ONE_SEP5(e){this.atLeastOneSepFirstInternal(5,e)}AT_LEAST_ONE_SEP6(e){this.atLeastOneSepFirstInternal(6,e)}AT_LEAST_ONE_SEP7(e){this.atLeastOneSepFirstInternal(7,e)}AT_LEAST_ONE_SEP8(e){this.atLeastOneSepFirstInternal(8,e)}AT_LEAST_ONE_SEP9(e){this.atLeastOneSepFirstInternal(9,e)}RULE(e,t,n=Px){if(this.definedRulesNames.includes(e)){let t={message:pb.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:Mx.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(t)}this.definedRulesNames.push(e);let r=this.defineRule(e,t,n);return this[e]=r,r}OVERRIDE_RULE(e,t,n=Px){let r=function(e,t,n){let r=[],i;return t.includes(e)||(i=`Invalid rule override, rule: ->${e}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,r.push({message:i,type:Mx.INVALID_RULE_OVERRIDE,ruleName:e})),r}(e,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(r);let i=this.defineRule(e,t,n);return this[e]=i,i}BACKTRACK(e,t){let n=e.coreRule??e;return function(){this.isBackTrackingStack.push(1);let e=this.saveRecogState();try{return n.apply(this,t),!0}catch(e){if(ex(e))return!1;throw e}finally{this.reloadRecogState(e),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return Object.values(this.gastProductionsCache).map(Hv)}},class{initErrorHandler(e){this._errors=[],this.errorMessageProvider=Object.hasOwn(e,`errorMessageProvider`)?e.errorMessageProvider:Nx.errorMessageProvider}SAVE_ERROR(e){if(ex(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1)},this._errors.push(e),e;throw Error(`Trying to save an Error which is not a RecognitionException`)}get errors(){return[...this._errors]}set errors(e){this._errors=e}raiseEarlyExitException(e,t,n){let r=this.getCurrRuleFullName(),i=Fb(e,this.getGAstProductions()[r],t,this.maxLookahead)[0],a=[];for(let e=1;e<=this.maxLookahead;e++)a.push(this.LA(e));let o=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:i,actual:a,previous:this.LA(0),customUserDescription:n,ruleName:r});throw this.SAVE_ERROR(new ax(o,this.LA(1),this.LA(0)))}raiseNoAltException(e,t){let n=this.getCurrRuleFullName(),r=Pb(e,this.getGAstProductions()[n],this.maxLookahead),i=[];for(let e=1;e<=this.maxLookahead;e++)i.push(this.LA(e));let a=this.LA(0),o=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:r,actual:i,previous:a,customUserDescription:t,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new rx(o,this.LA(1),a))}},class{initGastRecorder(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT(`Enable Recording`,()=>{for(let e=0;e<10;e++){let t=e>0?e:``;this[`CONSUME${t}`]=function(t,n){return this.consumeInternalRecord(t,e,n)},this[`SUBRULE${t}`]=function(t,n){return this.subruleInternalRecord(t,e,n)},this[`OPTION${t}`]=function(t){return this.optionInternalRecord(t,e)},this[`OR${t}`]=function(t){return this.orInternalRecord(t,e)},this[`MANY${t}`]=function(t){this.manyInternalRecord(e,t)},this[`MANY_SEP${t}`]=function(t){this.manySepFirstInternalRecord(e,t)},this[`AT_LEAST_ONE${t}`]=function(t){this.atLeastOneInternalRecord(e,t)},this[`AT_LEAST_ONE_SEP${t}`]=function(t){this.atLeastOneSepFirstInternalRecord(e,t)}}this.consume=function(e,t,n){return this.consumeInternalRecord(t,e,n)},this.subrule=function(e,t,n){return this.subruleInternalRecord(t,e,n)},this.option=function(e,t){return this.optionInternalRecord(t,e)},this.or=function(e,t){return this.orInternalRecord(t,e)},this.many=function(e,t){this.manyInternalRecord(e,t)},this.atLeastOne=function(e,t){this.atLeastOneInternalRecord(e,t)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT(`Deleting Recording methods`,()=>{let e=this;for(let t=0;t<10;t++){let n=t>0?t:``;delete e[`CONSUME${n}`],delete e[`SUBRULE${n}`],delete e[`OPTION${n}`],delete e[`OR${n}`],delete e[`MANY${n}`],delete e[`MANY_SEP${n}`],delete e[`AT_LEAST_ONE${n}`],delete e[`AT_LEAST_ONE_SEP${n}`]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})}ACTION_RECORD(e){}BACKTRACK_RECORD(e,t){return()=>!0}LA_RECORD(e){return jx}topLevelRuleRecord(e,t){try{let n=new Nv({definition:[],name:e});return n.name=e,this.recordingProdStack.push(n),t.call(this),this.recordingProdStack.pop(),n}catch(e){if(!0!==e.KNOWN_RECORDER_ERROR)try{e.message+=`
|
|
60
|
-
This error was thrown during the "grammar recording phase" For more info see:
|
|
61
|
-
https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw e}throw e}}optionInternalRecord(e,t){return Dx.call(this,Fv,e,t)}atLeastOneInternalRecord(e,t){Dx.call(this,Iv,t,e)}atLeastOneSepFirstInternalRecord(e,t){Dx.call(this,Lv,t,e,Sx)}manyInternalRecord(e,t){Dx.call(this,Rv,t,e)}manySepFirstInternalRecord(e,t){Dx.call(this,zv,t,e,Sx)}orInternalRecord(e,t){return Ox.call(this,e,t)}subruleInternalRecord(e,t,n){if(Ax(t),!e||!Object.hasOwn(e,`ruleName`)){let n=Error(`<SUBRULE${kx(t)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(e)}>\n inside top level rule: <${this.recordingProdStack[0].name}>`);throw n.KNOWN_RECORDER_ERROR=!0,n}let r=this.recordingProdStack.at(-1),i=e.ruleName,a=new Mv({idx:t,nonTerminalName:i,label:n?.LABEL,referencedRule:void 0});return r.definition.push(a),this.outputCst?Ex:xx}consumeInternalRecord(e,t,n){if(Ax(t),!Gy(e)){let n=Error(`<CONSUME${kx(t)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(e)}>\n inside top level rule: <${this.recordingProdStack[0].name}>`);throw n.KNOWN_RECORDER_ERROR=!0,n}let r=this.recordingProdStack.at(-1),i=new Vv({idx:t,terminalType:e,label:n?.LABEL});return r.definition.push(i),Tx}},class{initPerformanceTracer(e){if(Object.hasOwn(e,`traceInitPerf`)){let t=e.traceInitPerf,n=typeof t==`number`;this.traceInitMaxIdent=n?t:1/0,this.traceInitPerf=n?t>0:t}else this.traceInitMaxIdent=0,this.traceInitPerf=Nx.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(e,t){if(!0===this.traceInitPerf){this.traceInitIndent++;let n=Array(this.traceInitIndent+1).join(` `);this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${n}--\x3e <${e}>`);let{time:r,value:i}=kv(t),a=r>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&a(`${n}<-- <${e}> time: ${r}ms`),this.traceInitIndent--,i}return t()}}],Ix.forEach(e=>{let t=e.prototype;Object.getOwnPropertyNames(t).forEach(n=>{if(n===`constructor`)return;let r=Object.getOwnPropertyDescriptor(t,n);r&&(r.get||r.set)?Object.defineProperty(Fx.prototype,n,r):Fx.prototype[n]=e.prototype[n]})});var Rx=class extends Lx{constructor(e,t=Nx){let n=Object.assign({},t);n.outputCst=!1,super(e,n)}},zx={separatorFunction:`,`,separatorColumn:`,`,separatorRow:`;`,separatorDecimal:`.`};function Bx(e){return e===`,`?{separatorDecimal:`,`,separatorFunction:`;`,separatorColumn:`;`,separatorRow:`|`}:zx}var Vx=[[`All`,`all`],[`Data`,`data`],[`Headers`,`headers`],[`Totals`,`totals`],[`This Row`,`thisRow`]];function Hx(e,t){let n=e.trim().toUpperCase();for(let[e,r]of Vx)if(e.toUpperCase()===n||t?.[r]?.trim().toUpperCase()===n)return e}var Ux={separators:zx,booleanTrue:`TRUE`,booleanFalse:`FALSE`,errorLiterals:[],errorRefs:[],parseBoolean:e=>{let t=e.toUpperCase();return t===`TRUE`||t!==`FALSE`&&void 0},parseError:e=>t.FormulaError.getBuiltInByLabel(e.toUpperCase())??void 0,parseSpecifier:e=>Hx(e),localizeBoolean:e=>e?`TRUE`:`FALSE`,localizeError:e=>e?.getLabel?.()??String(e),localizeSpecifier:e=>e};function Wx(e=zx,t){let n=xi(t),r=n?.booleans?.true??`TRUE`,i=n?.booleans?.false??`FALSE`,a=[],o=[],s=n?.errors;if(s)for(let e in s)(e===`Ref`||e===`Name`?o:a).push(s[e]);let c=n?.specifiers;return{separators:e,booleanTrue:r,booleanFalse:i,errorLiterals:a,errorRefs:o,specifiers:c,parseBoolean:e=>Ti(e,t),parseError:e=>Ei(e,t),parseSpecifier:e=>Hx(e,c),localizeBoolean:e=>e?r:i,localizeError:e=>wi(e,t),localizeSpecifier:e=>function(e,t){if(!t)return e;let n=e.trim().toUpperCase();for(let[r,i]of Vx)if(r.toUpperCase()===n)return t[i]?.trim()||e;return e}(e,c)}}var Gx=class e{static shared(t){let n=t?.locale??Ux,r=t?.maxColumn??Yx,i=t?.maxRow??Xx,a=Jx.get(n);a||(a=new Map,Jx.set(n,a));let o=`${r}:${i}`,s=a.get(o);return s||(s=new e({locale:n,maxColumn:r,maxRow:i}),a.set(o,s)),s}constructor(e){let t=e?.maxColumn??Yx,n=e?.maxRow??Xx,r=e?.locale??Ux;this._locale=r,this._maxColumn=t,this._maxRow=n;let{separatorFunction:i,separatorColumn:a,separatorRow:o,separatorDecimal:s}=r.separators;if(a===o)throw Error(`FormulaLexer: separatorColumn and separatorRow must differ (both '${a}')`);let c=Q({name:`WhiteSpace`,pattern:/\s+/,group:Zy.SKIPPED}),l=Q({name:`StringToken`,pattern:/"(""|[^"])*"/}),u=Q({name:`FunctionToken`,pattern:/[a-zA-Z_\u007F-\uFFFF]+[a-zA-Z0-9_.\u007F-\uFFFF]*(?=\()/}),d=Q({name:`TableReference`,pattern:{exec:eS},line_breaks:!1,start_chars_hint:qx}),f=Q({name:`BracketedString`,pattern:{exec:rS},line_breaks:!1,start_chars_hint:[91],longer_alt:[d,l]}),p=e=>(e??[]).map(e=>e?.trim()).filter(Boolean).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).map(e=>e+`|`).join(``),m=Q({name:`LiteralError`,pattern:RegExp(p(r.errorLiterals)+`#PARSE!|#NULL!|#DIV\\/0!|#VALUE!|#NUM!|#FIELD!|#N\\/A|#GETTING_DATA|#SPILL!|#CONNECT!|#BLOCKED!|#UNKNOWN!|#CALC!|#BUSY!|#PYTHON!|#TIMEOUT!`)}),h=Q({name:`RefError`,pattern:RegExp(p(r.errorRefs)+`#REF!|#NAME\\?`)}),g=Q({name:`SingleQuotedString`,pattern:/'(''|[^'])*'/}),_=Q({name:`SheetQuoted`,pattern:/'(?:''|[^'])*?'!/}),v=Q({name:`Sheet`,pattern:/[A-Za-z_.\d\u007F-\uFFFF]*!/}),y=/[a-zA-Z_\\\u007F-\uFFFF][a-zA-Z0-9_.?\\\u007F-\uFFFF]*:?/y,b=Q({name:`NamedToken`,pattern:{exec:(e,t)=>{y.lastIndex=t;let n=y.exec(e);if(!n)return null;let r=n[0],i=r.indexOf(`.:`);return i===-1?r.endsWith(`:`)&&(r=r.slice(0,-1)):r=r.substring(0,i),[r]}},line_breaks:!1,start_chars_hint:qx}),x=Q({name:`Cell`,pattern:{exec:$x(t,n)},line_breaks:!1,start_chars_hint:[36,...Kx],longer_alt:b}),S=Q({name:`Column`,pattern:{exec:Qx(t)},line_breaks:!1,start_chars_hint:[36,...Kx],longer_alt:b}),C=Q({name:`AbsRow`,pattern:/[$][0-9]+/}),w=s===`.`?`\\.`:s,T=Q({name:`NumberToken`,pattern:RegExp(`[0-9]+${w}(?!:)[0-9]*([eE][+-]?[0-9]+|\\*\\*[+-]?[0-9]+)?|${w}[0-9]+([eE][+-]?[0-9]+|\\*\\*[+-]?[0-9]+)?|[0-9]+[eE][+-]?[0-9]+`)}),E=Q({name:`ScientificDigit`,pattern:/[0-9]+\*\*[+-]?[0-9]+/}),D=Q({name:`DigitToken`,pattern:/[0-9]+/}),O=[`TRUE`,`FALSE`];for(let e of[r.booleanTrue,r.booleanFalse]){let t=e?.trim();t&&!O.some(e=>e.toLowerCase()===t.toLowerCase())&&O.push(t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`))}let k=Q({name:`BooleanToken`,pattern:new RegExp(O.join(`|`),`i`)}),A=Q({name:`ArgSeparator`,pattern:nS(i)}),j=Q({name:`ColSeparator`,pattern:nS(a)}),M=Q({name:`RowSeparator`,pattern:nS(o)}),N=Q({name:`RangeOp`,pattern:/:/}),P=Q({name:`RangeTrimFullOp`,pattern:/\.:\./}),F=Q({name:`RangeTrimLeadingOp`,pattern:/\.:/}),I=Q({name:`RangeTrimTrailingOp`,pattern:/:\./}),L=Q({name:`OpenParen`,pattern:/\(/}),R=Q({name:`CloseParen`,pattern:/\)/}),ee=Q({name:`OpenCurlyParen`,pattern:/{/}),te=Q({name:`CloseCurlyParen`,pattern:/}/}),ne=Q({name:`QuoteS`,pattern:/'/}),re=Q({name:`MulOp`,pattern:/\*(?!\*)/}),ie=Q({name:`PlusOp`,pattern:/\+/}),ae=Q({name:`DivOp`,pattern:/\//}),oe=Q({name:`MinOp`,pattern:/-/}),se=Q({name:`ImplicitIntersectOp`,pattern:/@/}),ce=Q({name:`ConcatOp`,pattern:/&/}),le=Q({name:`ExOp`,pattern:/\^/}),ue=Q({name:`PercentOp`,pattern:/%/}),de=Q({name:`ArrayAnchorOp`,pattern:/#/,longer_alt:[m,h]}),fe=Q({name:`GtOp`,pattern:/>/}),pe=Q({name:`EqOp`,pattern:/=/}),me=Q({name:`LtOp`,pattern:/</}),he=[c,l,_,g,v,u,d,f,m,h,A,...a===i?[]:[j],M,P,F,I,N,x,k,S,C,T,E,D,de,se,b,L,R,ee,te,ne,re,ie,ae,oe,ce,le,ue,Q({name:`NeqOp`,pattern:/<>/}),Q({name:`GteOp`,pattern:/>=/}),Q({name:`LteOp`,pattern:/<=/}),fe,pe,me];this._lexer=new Zy(he,{ensureOptimizations:!0});let ge={};he.forEach(e=>{ge[e.name]=e}),a===i&&(ge.ColSeparator=A),this._vocabulary=ge}tokenize(e,n=!0){let r=this._lexer.tokenize(e);if(n&&r.errors.length>0){let n=r.errors[0],i=n.line,a=n.column,o=e.substr(n.offset,n.length||1),s=o?`Unexpected character '${o}'`:n.message;throw new t.FormulaError.Parse(s,{line:i,column:a,offset:n.offset,length:n.length})}return r}getVocabulary(){return this._vocabulary}getLocale(){return this._locale}getMaxColumn(){return this._maxColumn}getMaxRow(){return this._maxRow}getSeparators(){return this._locale.separators}},Kx=(()=>{let e=[];for(let t=65;t<=90;t++)e.push(t);for(let t=97;t<=122;t++)e.push(t);for(let t=48;t<=57;t++)e.push(t);return e})().filter(e=>e<48||e>57),qx=(()=>{let e=[...Kx,95,92];for(let t=127;t<=65535;t++)e.push(t);return e})(),Jx=new WeakMap,Yx=16384,Xx=1048576;function Zx(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);r=26*r+(t>=97?t-96:t-64)}return r}function Qx(e){return(t,n)=>{let r=n;t.charCodeAt(r)===36&&r++;let i=r;for(;r<t.length&&r-i<3;){let e=t.charCodeAt(r);if(!(e>=65&&e<=90||e>=97&&e<=122))break;r++}if(r-i===0||Zx(t,i,r)>e)return null;if(r<t.length){let e=t.charCodeAt(r);if(e>=48&&e<=57)return null}return[t.substring(n,r)]}}function $x(e,t){return(n,r)=>{let i=r;n.charCodeAt(i)===36&&i++;let a=i;for(;i<n.length&&i-a<3;){let e=n.charCodeAt(i);if(!(e>=65&&e<=90||e>=97&&e<=122))break;i++}if(i-a===0||Zx(n,a,i)>e)return null;i<n.length&&n.charCodeAt(i)===36&&i++;let o=i;if(i>=n.length)return null;let s=n.charCodeAt(i);if(s<49||s>57)return null;for(i++;i<n.length;){let e=n.charCodeAt(i);if(!(e>=48&&e<=57))break;i++}return parseInt(n.substring(o,i),10)>t?null:[n.substring(r,i)]}}function eS(e,t){let n=t;if(e.charCodeAt(n)===91){let t=e.indexOf(`]`,n+1);if(t===-1||e.charCodeAt(t+1)!==33)return null;n=t+2}let r=e.charCodeAt(n);if(!(r>=65&&r<=90||r>=97&&r<=122||r===95||r>=127&&r<=65535))return null;let i=n+1;for(;i<e.length;){let t=e.charCodeAt(i);if(!(t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57||t===95||t===46||t>=127&&t<=65535))break;i++}if(i>=e.length||e.charCodeAt(i)!==91)return null;let a=0;for(;i<e.length;){let n=e.charCodeAt(i);if(n===39&&tS(e,i))i+=2;else{if(n===91)a++;else if(n===93&&(a--,a===0))return[e.substring(t,i+1)];i++}}return null}function tS(e,t){let n=e.charCodeAt(t+1);return n===91||n===93||n===35||n===39}function nS(e){return new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`))}function rS(e,t){if(e.charCodeAt(t)!==91)return null;let n=0,r=t;for(;r<e.length;){let i=e.charCodeAt(r);if(i===39&&tS(e,r))r+=2;else{if(i===91)n++;else if(i===93&&(n--,n===0))return[e.substring(t,r+1)];r++}}return null}function iS(e){let t=(e=e.toUpperCase()).length,n=0;for(let r=0;r<t;r++){let i=e.charCodeAt(r);isNaN(i)||(n+=(i-64)*26**(t-r-1))}return n}function aS(e){return{type:Z.Cell,value:{colIndex:e.colIndex,rowIndex:e.rowIndex,$colIndex:e.$colIndex||!1,$rowIndex:e.$rowIndex||!1,scope:null},inputs:null,isReference:!0}}function oS(e,t){let n=e.startsWith(`$`);n&&(e=e.substring(1));let r=parseInt(e)-1;return n||r===-(2**53-1)||(r-=t),{type:Z.Cell,value:{colIndex:-(2**53-1),$colIndex:!1,rowIndex:r,$rowIndex:n,scope:null},inputs:null,isReference:!0}}function sS(e,t){return{type:Z.Function,value:e,inputs:t}}function cS(e,t){return{type:Z.TableReference,value:e,inputs:t,isReference:!0}}function lS(e,t=Ux){let n=e.startsWith(`[`)?e.slice(1,-1):e;if(n.startsWith(`#`)&&t.parseSpecifier){let e=t.parseSpecifier(n.slice(1));e&&(n=`#`+e)}return{type:Z.TableSpecifier,value:n,inputs:null,isReference:!0}}var uS=/['#[\]]/g,dS=/'(['#[\]])/g;function fS(e){return e.replace(uS,`'$&`)}function pS(e){return e.indexOf(`'`)===-1?e:e.replace(dS,`$1`)}function mS(e){let t=e;return t=e.startsWith(`[`)&&e.endsWith(`]`)?pS(e.slice(1,-1)):e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1).replace(/''/g,`'`):pS(e),{type:Z.TableColumn,value:t,inputs:null,isReference:!0}}function hS(e,t,n,r=!1){let i={type:Z.Infix,value:e,inputs:[t,n]};return r&&(i.isReference=!0),i}function gS(e,t,n=!1){let r={type:Z.Postfix,value:e,inputs:t?[t]:null};return n&&(r.isReference=!0),r}function _S(e,t,n=!1){let r={type:Z.Prefix,value:e,inputs:t?[t]:null};return n&&(r.isReference=!0),r}function vS(e){return{type:Z.Named,value:{nameId:e,scope:null},inputs:null,isReference:!0}}function yS(e,n=Ux){let r=n.separators.separatorDecimal,i=e;r!==`.`&&(i=i.split(r).join(`.`)),i.includes(`**`)&&(i=i.replace(`**`,`e`));let a=Number(t.Scalar.truncateNumberText(i));if(!(a>=-999999999999999e293&&a<=999999999999999e293))throw new t.FormulaError.Parse(`Number out of range: ${e}`);return{type:Z.Number,value:a,image:e,isLiteral:!0}}function bS(e){return{type:Z.String,value:e.length>1?e.substring(1,e.length-1).replace(/""/g,`"`):e,isLiteral:!0}}function xS(){return{type:Z.Row,value:[],isLiteral:!0}}function SS(e,t=Ux){return{type:Z.Boolean,value:t.parseBoolean(e)??!1,image:e,isLiteral:!0}}function CS(e,n=Ux){return{type:Z.Error,value:n.parseError(e)??t.FormulaError.getBuiltInByLabel(e.toUpperCase()),image:e,isLiteral:!0}}function wS(e,n=Ux,r){let i=e?n.parseError(e)??t.FormulaError.getBuiltInByLabel(e.toUpperCase()):t.FormulaError.BuiltIn.Ref;return{type:Z.Error,value:r?{error:i,scope:r}:{error:i},image:e,inputs:null,isReference:!0}}function TS(e){return t.FormulaError.isError(e)?e:e?.error}function ES(e){if(t.FormulaError.isError(e))return e.getLabel();let n=e;if(!n?.error)return;let r=n.error.getLabel();return n.scope?{error:r,scope:n.scope}:{error:r}}function DS(e){let n=typeof e==`string`?e:e?.error;return typeof n==`string`?t.FormulaError.getBuiltInByLabel(n):void 0}function OS(e){return e.indexOf(`#`)>0}function kS(){return{type:Z.Empty,value:void 0,isLiteral:!0}}function AS(e,t){return e&&function e(n,r,i=[]){let a=n.inputs,o;if(a){let t=a.length;for(let r=0;r<t;r++){let t=a[r];if(t===void 0)continue;i.push(n);let s=e(t,n,i);i.pop(),s!==void 0&&s!==t&&(o||=[...a],o[r]=s)}}let s=n;if(o&&(s={...n},s.inputs=o),s===void 0)return s;let c=t(s,r,i);return c===void 0?s:c}(e,void 0,[])}function jS(e,t){return t.wsBefore&&(e.wsBefore=t.wsBefore),t.wsAfter&&(e.wsAfter=t.wsAfter),t.image&&(e.image=t.image),e}var MS=Object.freeze([[`^`],[`*`,`/`],[`+`,`-`],[`&`],[`<`,`>`,`=`,`<>`,`<=`,`>=`]]),NS=(Object.freeze([`:`,`.:.`,`.:`,`:.`]),Object.freeze([`:`,` `,`.:.`,`.:`,`:.`])),PS=Object.freeze([`@`]),FS=Object.freeze([`#`]),IS=(Object.freeze(NS.concat(FS)),Object.freeze(NS.concat(PS).concat(FS))),LS=[`All`,`Data`,`Headers`,`Totals`,`This Row`],RS=class{constructor(e=Ux){let t=function(e){let t=[...LS];if(e)for(let n of Object.values(e)){let e=n?.trim();e&&!t.some(t=>t.toLowerCase()===e.toLowerCase())&&t.push(e)}return t.sort((e,t)=>t.length-e.length),t.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`)}(e.specifiers),n=Q({name:`WhiteSpace`,pattern:/\s+/,group:Zy.SKIPPED}),r=Q({name:`TableSpecifier`,pattern:RegExp(`\\[#(?:${t})\\]`,`i`)}),i=[n,r,Q({name:`BracketedColumn`,pattern:/\[(?:'['#[\]]|'(?!['#[\]])|[^'[\]])*\]/,longer_alt:[r]}),Q({name:`BareSpecifier`,pattern:RegExp(`#(?:${t})`,`i`)}),Q({name:`ColumnSep`,pattern:/:/}),Q({name:`ListSep`,pattern:new RegExp(e.separators.separatorFunction.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`))})];this._lexer=new Zy(i,{ensureOptimizations:!0});let a={};i.forEach(e=>{a[e.name]=e}),this._vocabulary=a}getVocabulary(){return this._vocabulary}tokenize(e){return this._lexer.tokenize(e)}},zS=class extends Rx{constructor(e=Ux){let t=new RS(e),n=t.getVocabulary();super(n,{nodeLocationTracking:`none`,maxLookahead:2,skipValidations:!0,recoveryEnabled:!1}),this._lexer=t;let{TableSpecifier:r,BracketedColumn:i,BareSpecifier:a,ColumnSep:o,ListSep:s}=n,c=this;c.RULE(`ruleContent`,()=>{let e=[],t=c.SUBRULE(c.ruleItem);return c.ACTION(()=>{t&&e.push(t)}),c.MANY(()=>{c.CONSUME(s),c.OPTION(()=>{let t=c.SUBRULE2(c.ruleItem);c.ACTION(()=>{t&&e.push(t)})})}),e}),c.RULE(`ruleItem`,()=>c.OR([{ALT:()=>c.SUBRULE(c.ruleSpecifier)},{ALT:()=>c.SUBRULE(c.ruleColumnOrRange)}])),c.RULE(`ruleSpecifier`,()=>c.OR([{ALT:()=>{let t=c.CONSUME(r);return c.ACTION(()=>{let n=lS(t.image,e);return n.image=t.image,n})}},{ALT:()=>{let t=c.CONSUME(a);return c.ACTION(()=>{let n=lS(t.image,e);return n.image=t.image,n})}}])),c.RULE(`ruleColumnOrRange`,()=>{let e=c.CONSUME(i),t,n;return c.OPTION(()=>{t=c.CONSUME(o),n=c.CONSUME2(i)}),c.ACTION(()=>{let r=mS(e.image);if(r.image=e.image,!n)return r;let i=mS(n.image);i.image=n.image;let a=hS(`:`,r,i,!0);return a.image=t?.image??`:`,a})}),c.performSelfAnalysis()}_parseInner(e){let t=this._lexer.tokenize(e);return t.errors.length>0||t.tokens.length===0?[]:(this.input=t.tokens,this.reset(),this.ruleContent()??[])}_parseContent(e){if(!e)return[];let t=e.trim();if(!t)return[];let n=t[0];if(n===`@`){let e=t.slice(1).trim();if(!e){let e=_S(`@`,null,!0);return e.image=`@`,[e]}if(e.charAt(0)===`[`){let t=this._parseInner(e);if(t.length===1&&t[0].type===`infix`){let e=_S(`@`,t[0],!0);return e.image=`@`,[e]}}let n=mS(e);n.image=e;let r=_S(`@`,n,!0);return r.image=`@`,[r]}if(n!==`[`&&n!==`#`){let t=mS(e);return t.image=e,[t]}return this._parseInner(t)}parse(e,t,n){let r=()=>({root:cS(``,[]),errors:[]});if(!n)return r();let i=0;if(n.charAt(0)===`[`){let e=n.indexOf(`]`);e!==-1&&n.charAt(e+1)===`!`&&(i=e+2)}let a=n.indexOf(`[`,i);if(a===-1)return r();let o=n.slice(0,a),s=n.slice(a+1,-1);return{root:cS(o,this._parseContent(s)),errors:this.errors.length>0?[...this.errors]:[]}}},BS=new Set([`:`,`.:.`,`.:`,`:.`]),VS=new Set([`.:.`,`.:`,`:.`]),HS=e=>{if(!e)return null;if(e.type===Z.Cell){let t=e.value;return t.rowIndex===-(2**53-1)?`col`:t.colIndex===-(2**53-1)?`row`:null}return Number.isInteger(e.value)?`row`:null},US=(e,t)=>{let n=parseInt(e.charCodeAt(0)===36?e.substring(1):e,10);return n>=1&&n<=t},WS=`A formula must not be empty`,GS=(e,t)=>`A formula must not be longer than ${t} characters (this one is ${e})`;function KS(e,t){let n=e?.[0]?.image;if(!n){let e=t?.image;return e?`Expected a value after '${e}'`:`Expected a value`}return`Unexpected '${n}'`}var qS={...db,buildNoViableAltMessage:e=>KS(e.actual,e.previous),buildEarlyExitMessage:e=>KS(e.actual,e.previous),buildNotAllInputParsedMessage:e=>{let t=e.firstRedundant?.image;return t?`Unexpected '${t}'`:db.buildNotAllInputParsedMessage(e)},buildMismatchTokenMessage:e=>{let t=e.actual?.image;return e.expected===lb&&t?`Unexpected '${t}'`:db.buildMismatchTokenMessage(e)}},JS=class extends Rx{constructor(e){let t=e?.lexer??Gx.shared(e?.lexerOptions),n=t.getVocabulary();super(n,{skipValidations:!0,recoveryEnabled:!0,...e,nodeLocationTracking:`full`,errorMessageProvider:qS,maxLookahead:1}),this._ruleInfixOp=this.RULE(`ruleInfixOp`,()=>{let{PlusOp:e,MinOp:t,MulOp:n,DivOp:r,ExOp:i,ConcatOp:a,GtOp:o,EqOp:s,LtOp:c,NeqOp:l,GteOp:u,LteOp:d}=this._vocab,f=[];return f.push({node:this.SUBRULE(this._rulePostfixOp)}),this.MANY(()=>{let p=this.OR(this._c1||=[{ALT:()=>this.CONSUME(e).image},{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image},{ALT:()=>this.CONSUME(r).image},{ALT:()=>this.CONSUME(i).image},{ALT:()=>this.CONSUME(a).image},{ALT:()=>this.CONSUME(o).image},{ALT:()=>this.CONSUME(s).image},{ALT:()=>this.CONSUME(c).image},{ALT:()=>this.CONSUME(l).image},{ALT:()=>this.CONSUME(u).image},{ALT:()=>this.CONSUME(d).image}]),m={value:p,index:this.getLexerPosition(),isRange:IS.includes(p)},h=this.SUBRULE2(this._rulePostfixOp);f.push({op:m,node:h})}),this.ACTION(()=>{let e=f.length-1,t=MS.length;for(let n=0;e>0&&n<t;n++){let t=MS[n],r=1;for(;r<f.length;){let n=f[r].op;if(t.includes(n.value)){let t=f[r-1].node,i=f[r].node,a=hS(n.value,t,i,n.isRange);a=this._tag(a,n.index),f[r-1].node=a,f.splice(r,1),e--}else r++}}}),f[0].node}),this._rulePlusMinusOp=this.RULE(`rulePlusMinusOp`,()=>{let{PlusOp:e,MinOp:t}=this._vocab;return this.OR([{ALT:()=>this.CONSUME(e)},{ALT:()=>this.CONSUME(t)}])}),this._rulePostfixOp=this.RULE(`rulePostfixOp`,()=>{let{PercentOp:e}=this._vocab,t=this.SUBRULE(this._rulePrefixOp),n=[];return this.MANY(()=>{let t=this.CONSUME(e).image;this.ACTION(()=>{n.push([t,this.getLexerPosition()])})}),this.ACTION(()=>{let e=n.length;if(e!==0)for(let r=0;r<e;r++){let e=n[r],i=e[0],a=e[1],o=IS.includes(i);t=gS(i,t,o),t=this._tag(t,a)}}),t}),this._rulePrefixOp=this.RULE(`rulePrefixOp`,()=>{let{PlusOp:e,MinOp:t,ImplicitIntersectOp:n}=this._vocab,r=[];this.MANY(()=>{let i=this.OR([{ALT:()=>this.CONSUME(e).image},{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image}]);this.ACTION(()=>{r.push([i,this.getLexerPosition()])})});let i=this.SUBRULE(this._ruleRangeOp);return this.ACTION(()=>{let e=r.length;if(e!==0)for(let t=e-1;t>=0;t--){let e=r[t],n=e[0],a=e[1],o=IS.includes(n);i=_S(n,i,o),i=this._tag(i,a)}}),i}),this._ruleRangeOp=this.RULE(`ruleRangeOp`,()=>{let{RangeOp:e,RangeTrimFullOp:t,RangeTrimLeadingOp:n,RangeTrimTrailingOp:r,ArrayAnchorOp:i}=this._vocab,a=[];return a.push({node:this.SUBRULE(this._ruleCallOp)}),this.MANY2(()=>{this.CONSUME(i),a.push({anchor:this.getLexerPosition()})}),this.MANY(()=>{let o={value:this.OR(this._c2||=[{ALT:()=>this.CONSUME(e).image},{ALT:()=>this.CONSUME(t).image},{ALT:()=>this.CONSUME(n).image},{ALT:()=>this.CONSUME(r).image}]),index:this.getLexerPosition()},s=this.SUBRULE2(this._ruleCallOp);a.push({op:o,node:s}),this.MANY3(()=>{this.CONSUME2(i),a.push({anchor:this.getLexerPosition()})})}),this.ACTION(()=>{for(let e=1;e<a.length;e++){let t=a[e];if(t.anchor!==void 0){a[0].node=this._tag(gS(`#`,a[0].node,!0),t.anchor);continue}let n=t.op,r=hS(n.value,a[0].node,t.node,!0);r=this._tag(r,n.index),a[0].node=r}}),a[0].node}),this._ruleCallOp=this.RULE(`ruleCallOp`,()=>{let{OpenParen:e,CloseParen:t}=this._vocab,n=this.SUBRULE(this._ruleFormula);return this.MANY({GATE:()=>{let t=this.LA(0),n=this.LA(1);return!(!t||!n||n.tokenType!==e)&&n.startOffset===t.endOffset+1},DEF:()=>{this.CONSUME(e);let r=this.getLexerPosition(),i=this.SUBRULE(this._ruleFunctionArguments),a=n,o=this.ACTION(()=>this._tag(function(e,t){return{type:Z.Call,value:null,inputs:t&&t.length>0?[e,...t]:[e]}}(a,i),r)),s=this.OPTION(()=>this.CONSUME(t));this.ACTION(()=>{s||this._reportError(o,`Missing closing parenthesis ')'`,r),this._tagClose(o,this.getLexerPosition()),n=o})}}),n}),this._ruleIntersectOp=this.RULE(`ruleIntersectOp`,()=>{let e=[this.SUBRULE(this._ruleInfixOp)];return this.MANY(()=>{this.OPTION({GATE:()=>{let e=this.LA(0);return this.LA(1).startOffset>e.endOffset+1},DEF:()=>{e.push(this.SUBRULE3(this._ruleInfixOp))}})}),this.ACTION(()=>{for(;e.length>1;){let t=e.length-1;for(let n=0;n<t;n++){let r=e[n],i=e[n+1],a=hS(` `,r,i,!0),o=this._tokenMap.get(r);o&&delete o.tokenIndexClose;let s=this._tokenMap.get(i),c=s?.tokenIndex;if(c!==void 0){let e=this.input[c],t=this.input[c-1]?.endOffset??-1,n=this._inputText.slice(t+1,e.startOffset).slice(0,-1);n.length>0&&(a.wsBefore=n)}s&&delete s.tokenIndex,n+1<t&&s&&delete s.tokenIndexClose,e.splice(n,2,a),n--,t--}}}),e[0]}),this._ruleFormula=this.RULE(`ruleFormula`,()=>this.OR9([{ALT:()=>this.SUBRULE(this._ruleLiteral)},{ALT:()=>this.SUBRULE(this._ruleReference)},{ALT:()=>this.SUBRULE(this._ruleFunction)},{ALT:()=>this.SUBRULE(this._ruleParen)},{ALT:()=>this.SUBRULE(this._ruleTableReference)},{ALT:()=>this.SUBRULE(this._ruleBracketedString)},{ALT:()=>this.SUBRULE(this._ruleLiteralArray)}])),this._ruleGroup=this.RULE(`ruleGroup`,()=>{let{ArgSeparator:e}=this._vocab,t=[];return this.MANY(()=>{this.CONSUME(e);let n=this.SUBRULE2(this._ruleIntersectOp);this.ACTION(()=>{t.push(n)})}),t}),this._ruleParen=this.RULE(`ruleParen`,()=>{let{OpenParen:e,CloseParen:t}=this._vocab;return this._processParen(Z.Paren,e,t)}),this._ruleLiteralArray=this.RULE(`ruleLiteralArray`,()=>{let{OpenCurlyParen:e,CloseCurlyParen:t,ColSeparator:n,RowSeparator:r}=this._vocab,i=xS();this.CONSUME(e);let a=this.getLexerPosition(),o=this.ACTION(()=>this._tag({type:Z.Array,value:[i],isLiteral:!0},a)),s=this.SUBRULE(this._ruleLiteralForArray);this.ACTION(()=>{i.value.push(s)}),this.MANY(()=>{let e=!1;this.OR([{ALT:()=>{this.CONSUME(n),e=!0}},{ALT:()=>this.CONSUME(r)}]);let t=this.SUBRULE2(this._ruleLiteralForArray);this.ACTION(()=>{e||(i=xS(),o.value.push(i)),i.value.push(t)})});let c=this.OPTION(()=>this.CONSUME(t));return o=this.ACTION(()=>(c||this._reportError(o,`Missing closing parenthesis '}'`,a),this._tagClose(o,this.getLexerPosition()))),o}),this._ruleLiteralForArray=this.RULE(`ruleLiteralForArray`,()=>{let{StringToken:e,BooleanToken:t,LiteralError:n,RefError:r}=this._vocab;return this.OR([{ALT:()=>{let e=this.OPTION(()=>this.SUBRULE(this._rulePlusMinusOp)),t=this.SUBRULE(this._ruleNumber),n=this.ACTION(()=>this._tag(yS(t.image,this._locale),this.getLexerPosition()));return this.ACTION(()=>e?function(e,t){return{type:Z.Prefix,value:e,inputs:[t]}}(e.image,n):n)}},{ALT:()=>{let t=this.CONSUME(e);return this.ACTION(()=>this._tag(bS(t.image),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(t);return this.ACTION(()=>this._tag(SS(e.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(n);return this.ACTION(()=>this._tag(CS(e.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(r);return this.ACTION(()=>this._tag(wS(e.image,this._locale),this.getLexerPosition()))}}])}),this._ruleLiteral=this.RULE(`ruleLiteral`,()=>{let{StringToken:e,BooleanToken:t,LiteralError:n,RefError:r}=this._vocab;return this.OR([{ALT:()=>{let e=this.SUBRULE(this._ruleNumber);return this.ACTION(()=>this._tag(yS(e.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let t=this.CONSUME(e);return this.ACTION(()=>this._tag(bS(t.image),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(t);return this.ACTION(()=>this._tag(SS(e.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(n);return this.ACTION(()=>this._tag(CS(e.image,this._locale),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(r);return this.ACTION(()=>this._tag(wS(e.image,this._locale),this.getLexerPosition()))}}])}),this._ruleFunction=this.RULE(`ruleFunction`,()=>{let{FunctionToken:e,OpenParen:t,CloseParen:n}=this._vocab,r=this.CONSUME(e).image,i=this.getLexerPosition();this.CONSUME(t);let a=this.SUBRULE(this._ruleFunctionArguments),o=this.ACTION(()=>this._tag(sS(r,a),i)),s=this.OPTION(()=>this.CONSUME(n));return o=this.ACTION(()=>(s||this._reportError(o,`Missing closing parenthesis ')'`,i),this._tagClose(o,this.getLexerPosition()))),o}),this._ruleFunctionArguments=this.RULE(`ruleFunctionArguments`,()=>{let{ArgSeparator:e,CloseParen:t}=this._vocab,n=[];return this.OPTION({GATE:()=>this.LA(1).tokenType!==t,DEF:()=>{let t;this.OPTION2(()=>{t=this.SUBRULE(this._ruleIntersectOp)}),t=this.ACTION(()=>t??this._tagClose(kS(),this.getLexerPosition())),n.push(t),this.MANY(()=>{let t;this.CONSUME(e),this.OPTION3(()=>{t=this.SUBRULE2(this._ruleIntersectOp)}),t=this.ACTION(()=>t??this._tagClose(kS(),this.getLexerPosition())),n.push(t)})}}),n}),this._ruleBracketedString=this.RULE(`ruleBracketedString`,()=>{let{BracketedString:e}=this._vocab,t=this.CONSUME(e),n=this.getLexerPosition();return this.ACTION(()=>{let e=this._srParser.parse(this.rowIndex,this.colIndex,t.image);for(let t of e.errors)this._astErrors.push(t);return this._tag(e.root,n)})}),this._ruleTableReference=this.RULE(`ruleTableReference`,()=>{let{TableReference:e}=this._vocab,t=this.CONSUME(e),n=this.getLexerPosition();return this.ACTION(()=>{let e=this._srParser.parse(this.rowIndex,this.colIndex,t.image);for(let t of e.errors)this._astErrors.push(t);return this._tag(e.root,n)})}),this._ruleReference=this.RULE(`ruleReference`,()=>{let{Sheet:e,SheetQuoted:t,DivOp:n,MulOp:r,PlusOp:i,MinOp:a,ArgSeparator:o,Cell:s,NamedToken:c,SingleQuotedString:l,Column:u,AbsRow:d,DigitToken:f,RefError:p}=this._vocab,m;this.OPTION2({GATE:()=>{for(let s=1;s<6;s++){let c=this.LA(s);if(c.tokenType===e||c.tokenType===t)return!0;if(c.image===``||c.image===`)`||c.tokenType===n||c.tokenType===r||c.tokenType===i||c.tokenType===a||c.tokenType===o)break}return!1},DEF:()=>{m=this.SUBRULE(this._rulePrefixSheetName)}});let h=this.OR([{ALT:()=>{let e=this.CONSUME(s),t=this.getLexerPosition();return this.ACTION(()=>this._tag(function(e,t,n){let r=e.match(/([$]?)([A-Za-z]{1,3})([$]?)([1-9][0-9]*)/),i=iS(r[2])-1,a=r[1].length===1,o=r[4]-1,s=r[3].length===1;return a||i===-(2**53-1)||(i-=n),s||o===-(2**53-1)||(o-=t),{type:Z.Cell,value:{colIndex:i,rowIndex:o,$colIndex:a,$rowIndex:s,scope:null},inputs:null,isReference:!0}}(e.image,this.rowIndex,this.colIndex),t))}},{ALT:()=>{let e=this.OR2([{ALT:()=>this.CONSUME(c)},{ALT:()=>this.CONSUME(l)}]);return this.ACTION(()=>this._tag(vS(e.image),this.getLexerPosition()))}},{ALT:()=>this.SUBRULE(this._ruleBracketedString)},{ALT:()=>this.SUBRULE(this._ruleFunction)},{ALT:()=>{let e=this.CONSUME(u);return this.ACTION(()=>this._tag(function(e,t){let n=e.startsWith(`$`);n&&(e=e.substring(1));let r=iS(e)-1;return n||r===-(2**53-1)||(r-=t),{type:Z.Cell,value:{colIndex:r,rowIndex:-(2**53-1),$colIndex:n,$rowIndex:!1,scope:null},inputs:null,isReference:!0}}(e.image,this.colIndex),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(d);return this.ACTION(()=>this._tag(oS(e.image,this.rowIndex),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(f);return this.ACTION(()=>this._tag(oS(e.image,this.rowIndex),this.getLexerPosition()))}},{ALT:()=>{let e=this.CONSUME(p);return this.ACTION(()=>this._tag(wS(e.image,this._locale),this.getLexerPosition()))}}]);return this.ACTION(()=>{if(m&&h){if(m.name===``)return void this._reportError(h,`'${m.image}' is not a valid sheet reference — a '!' needs a sheet name before it`);let e=h;h.type===Z.Postfix&&h.inputs?.[0]&&(e=h.inputs[0]),e.type!==Z.Cell&&e.type!==Z.Named&&e.type!==Z.Row&&e.type!==Z.TableColumn&&e.type!==Z.Error||(e.value.scope=m.name,e.value.scopeImage=m.image)}}),h}),this._rulePrefixSheetName=this.RULE(`rulePrefixSheetName`,()=>{let{SheetQuoted:e,BracketedString:t,NamedToken:n,RangeOp:r,Sheet:i}=this._vocab;return this.OR([{ALT:()=>{let t=this.CONSUME(e).image;return{name:t.slice(1,-2).replace(/''/g,`'`),image:t}}},{ALT:()=>{let e=``;this.OPTION(()=>{e+=this.CONSUME(t).image}),this.OPTION2({GATE:()=>this.LA(2).tokenType===r,DEF:()=>{e+=this.CONSUME(n).image,this.CONSUME(r),e+=`:`}});let a=this.CONSUME(i).image;return{name:e+a.slice(0,-1),image:e+a}}}])}),this._ruleNumber=this.RULE(`ruleNumber`,()=>{let{NumberToken:e,ScientificDigit:t,DigitToken:n}=this._vocab;return this.OR([{ALT:()=>this.CONSUME(e)},{ALT:()=>this.CONSUME(t)},{ALT:()=>this.CONSUME(n)}])}),this._ruleRoot=this.RULE(`ruleRoot`,()=>{let{ArgSeparator:e}=this._vocab,t=this.SUBRULE(this._ruleIntersectOp),n=[];return this.MANY(()=>{this.CONSUME(e),n.push(this.SUBRULE2(this._ruleIntersectOp))}),this.ACTION(()=>n.length===0?t:{type:Z.List,value:`,`,inputs:[t,...n],isReference:!0})}),this._lexer=t,this._locale=t.getLocale(),this._vocab=n,this._srParser=e?.srParser??new zS(this._locale),this.performSelfAnalysis()}getLexer(){return this._lexer}parse(e,n,r){let i=this._lexer.tokenize(r),a;if(!i)return{root:{type:Z.Unparsed,value:r},errors:[]};let o=i.tokens;if(o.length===0)throw new t.FormulaError.Parse(WS);return this.input=o,this._inputText=r,this._inputTextLength=r.length,this.rowIndex=e,this.colIndex=n,this._astErrors=[],this._tokenMap=new Map,this.reset(),a=this._ruleRoot(),a&&this._bindAllWhitespace(a),a=AS(a,(t,n)=>{let r=t.type,i=n?.isReference?n.value:void 0,a=typeof i==`string`&&BS.has(i),o=typeof i==`string`&&VS.has(i),s=a?n.inputs:void 0,c=s?s[0]===t?s[1]:s[0]:void 0,l=this._lexer.getMaxRow();if(a&&r!==Z.Cell&&Number.isInteger(t.value)){let n=oS(t.image,e);return jS(n,t),HS(c)===`row`?US(t.image,l)||this._reportError(n,`'${t.image}' is not a valid row — rows run from 1 to ${l}`):this._reportError(n,`'${t.image}' is not a valid reference — a whole row can only pair with another row (as in ${t.image}:${t.image})`),n}if(o&&r===Z.Named)return this._reportError(t,`'${t.image??t.value?.nameId}' is a name — '${i}' needs a cell or range on both sides`),t;if(r===Z.Cell){let e=t.value,n=e.colIndex===-(2**53-1),r=e.rowIndex===-(2**53-1);if((n||r)&&HS(c)===(n?`row`:`col`))return n&&!US(t.image,l)&&this._reportError(t,`'${t.image}' is not a valid row — rows run from 1 to ${l}`),t;if(n||r||e.colIndex>=16384){let a=vS(t.image);jS(a,t);let s=e.scope;return s&&(a.value.scope=s,a.value.scopeImage=e.scopeImage),n?this._reportError(a,`'${t.image}' is not a valid reference — a row needs a column (use ${t.image}:${t.image} for the whole row)`):r&&t.image.includes(`$`)?this._reportError(a,`'${t.image}' is not a valid reference — a whole column can only pair with another column (as in ${t.image}:${t.image})`):o&&this._reportError(a,`'${t.image}' is a name — '${i}' needs a cell or range on both sides`),a}}return t}),{root:a,errors:[...this.errors,...this._astErrors]}}_processParen(e,t,n){let r;this.CONSUME(t);let i=this.getLexerPosition();r=this.ACTION(()=>(r={type:e,value:null,inputs:null},this._tag(r,i)));let a=[],o=this.SUBRULE(this._ruleIntersectOp);o&&a.push(o);let s=this.SUBRULE(this._ruleGroup),c=this.OPTION(()=>this.CONSUME(n));return r=this.ACTION(()=>{if(s)for(let e=0;e<s.length;e++)a.push(s[e]);return r&&(c||this._reportError(r,`Missing closing parenthesis`,i),r.inputs=a),this._tagClose(r,this.getLexerPosition())}),r}_reportError(e,t,n=void 0,r=`SyntaxError`){n===void 0&&(n=this.getLexerPosition()),e.error=!0,this._astErrors.push({name:r,message:t,previousToken:this.input[n],ast:e})}_tag(e,t){return e?(e.image??=this.input[t].image,this._tokenMap.set(e,{tokenIndex:t,tokenIndexClose:t}),e):(console.warn(`node is null`),e)}_tagClose(e,t){let n=this._tokenMap.get(e);return n?n.tokenIndexClose=t:this._tokenMap.set(e,{tokenIndexClose:t}),e}_bindNodeWhitespace(e){let t=this._tokenMap.get(e);if(!t)return;let n=this.input,r=this._inputText,i=t.tokenIndex;if(i!==void 0){let t=n[i],a=n[i-1]?.endOffset??-1;a+1<t.startOffset&&(e.wsBefore=r.slice(a+1,t.startOffset))}let a=t.tokenIndexClose;if(a!==void 0){let t=n[a],i=n[a+1]?.startOffset??this._inputTextLength;t.endOffset+1<i&&(e.wsAfter=r.slice(t.endOffset+1,i))}}_bindAllWhitespace(e){if(e){if(this._bindNodeWhitespace(e),e.inputs)for(let t of e.inputs)t&&this._bindAllWhitespace(t);if(e.type===Z.Array&&Array.isArray(e.value)){for(let t of e.value)if(t&&Array.isArray(t.value))for(let e of t.value)e&&this._bindAllWhitespace(e)}}}},$={Sheet:`sheet`,NamedFormula:`namedFormula`,Table:`table`,TableColumn:`tableColumn`,Function:`function`},YS=class{constructor(){this._providers=new Map}registerProvider(e,t){this._providers.set(e,t)}bind(e,t,n={}){return this._providers.get(e)?.bind(t,n)??null}resolve(e,t,n={}){return this._providers.get(e)?.resolve(t,n)??null}},XS=class{constructor(e,t){this._base=e,this._overrides=t}registerProvider(e,t){this._base.registerProvider(e,t)}bind(e,t,n={}){let r=this._overrides.get(e);return r?r.bind(t,n):this._base.bind(e,t,n)}resolve(e,t,n={}){let r=this._overrides.get(e);return r?r.resolve(t,n):this._base.resolve(e,t,n)}};function ZS(e){if(!e)return null;let t=e.indexOf(`[`);if(t===-1)return null;let n=e.indexOf(`]`,t+1);if(n===-1)return null;let r=e.substring(t+1,n);if(!r)return null;let i=e.substring(n+1);return{book:r,positional:/^\d+$/.test(r),dir:e.substring(0,t),sheetName:i===``?null:i}}function QS(e){return iC(e).file}function $S(e,t){let{dir:n,file:r}=iC(e);return(n||function(e){let t=e.getSources();for(let e=0;e<t.length;e++){let{dir:n,file:r}=aC(t[e]);if(n&&r)return n}return``}(e))+`[`+r+`]`+(t??``)}var eC=`http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLinkPath`;function tC(e){let t=e;return/^[A-Za-z]:[\\/]/.test(e)?t=`file:///`+encodeURI(e.replace(/\\/g,`/`)):e.startsWith(`\\\\`)&&(t=`file://`+encodeURI(e.substring(2).replace(/\\/g,`/`))),{type:eC,target:t,role:`book`}}function nC(e){let t=e.getSources();for(let e=0;e<t.length;e++){let{dir:n,file:r}=aC(t[e]);if(n&&r)return n+r}return null}function rC(e,t){return`[`+QS(e)+`]`+(t??``)}function iC(e){return aC(e.getSources()[0])}function aC(e){let t=e?.target??``;if(!t)return{dir:``,file:``};let n=!1;if(t.startsWith(`file:///`)?(t=t.substring(8),n=!0):t.startsWith(`file://`)&&(t=`\\\\`+t.substring(7),n=!0),n){try{t=decodeURIComponent(t)}catch{}t=t.replace(/\//g,`\\`)}let r=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return r===-1?{dir:``,file:t}:{dir:t.substring(0,r+1),file:t.substring(r+1)}}var oC=`ext:`,sC=e=>typeof e==`string`&&e.startsWith(`ext:`);function cC(e){if(!sC(e))return null;let t=e.substring(4).split(`:`),n=t[0];if(!n||t.length>3)return null;if(t.length===1)return{bookId:n,sheetIndex:-1,sheetEnd:-1};let r=lC(t[1]),i=t.length===3?lC(t[2]):r;return r<0||i<0?null:{bookId:n,sheetIndex:r,sheetEnd:i}}var lC=e=>{let t=Number(e);return e!==``&&Number.isInteger(t)&&t>=0?t:-1},uC=(e,t,n=t)=>{if(t<0)return oC+e;let r=oC+e+`:`+t;return n===t?r:r+`:`+n},dC=uC;function fC(e,t,n,r){if(!e)return null;if(sC(t))return function(e,t){let n=cC(t);return!(!n||e._getIndexById(n.bookId)===-1)&&(n.sheetIndex<0||n.sheetEnd<(e.getById(n.bookId)?.getSheetNames().length??0))}(e,t)?t:null;let i=ZS(t);if(r)return i?null:pC(e,r,t);if(!i)return null;let a=!n||i.positional||i.sheetName?.includes(`:`)?null:n,o=null;if(i.positional)o=e._getIdByIndex(Number(i.book));else{let t=function(e,t,n){let r=t.book.toLowerCase(),i=t.dir.toLowerCase(),a=null,o=0;for(let t of e.getItems())if(QS(t).toLowerCase()===r){if(i&&$S(t).toLowerCase().startsWith(i+`[`))return t.getId();a=t.getId(),o++}return o===0?null:o>1?i?null:`ambiguous`:i&&n?null:a}(e,i,a!=null);if(t===`ambiguous`)return null;o=t,o===null&&a&&(o=a.addBook(i))}if(o===null)return null;if(i.sheetName===null)return dC(o,-1);let s=pC(e,o,i.sheetName);if(s!==null)return s;if(a){let e=a.addSheet(o,i.sheetName);if(e>=0)return dC(o,e)}return null}function pC(e,t,n){let r=n.indexOf(`:`);if(r===-1){let r=mC(e,t,n);return r===-1?null:dC(t,r)}let i=mC(e,t,n.substring(0,r)),a=mC(e,t,n.substring(r+1));return i===-1||a===-1?null:dC(t,Math.min(i,a),Math.max(i,a))}function mC(e,t,n){let r=e.getById(t);if(!r)return-1;let i=r.getSheetNames(),a=n.toLowerCase();for(let e=0;e<i.length;e++)if(i[e]?.toLowerCase()===a)return e;return-1}function hC(e){return{stableId:e,toString:()=>t.FormulaError.BuiltIn.Ref.toString(),getName:()=>null,getEntireCoords:()=>null}}var gC=class{constructor(e,t,n,r){this._getId=e,this._getById=t,this._external=n,this._getIndexById=r}bind(e,t){let n=t;if(n?.book)return this._external?.bind(e,!1,n.book)??null;let r=this._getById(e);if(r!==null)return r.stableId;let i=this._getId(e);return i===null?_C(e)?this._bindSpan(e):this._external?.bind(e,!0===n?.mint)??null:i}resolve(e,t){let n=this._getById(e);if(n!==null)return n;let r=vC(e);return r?this._resolveSpan(e,r[0],r[1]):this._external?.resolve(e,!0===t?.display)??null}_bindSpan(e){let t=e.indexOf(`:`),n=this._bindEndpoint(e.substring(0,t)),r=this._bindEndpoint(e.substring(t+1));if(n===null||r===null)return null;if(n===r)return n;let i=this._getIndexById?.(n)??-1,a=this._getIndexById?.(r)??-1;if(i>a&&a!==-1){let e=n;n=r,r=e}return n+`:`+r}_bindEndpoint(e){let t=this._getById(e);return t?.getName?t.stableId:this._getId(e)}_resolveSpan(e,n,r){let i=this._getById(n),a=this._getById(r);return i?.getName&&a?.getName?{stableId:e,toString:()=>i.toString()+`:`+a.toString(),getName:()=>{let e=i.getName(),t=a.getName();return e!==null&&t!==null?e+`:`+t:null},getEntireCoords:()=>i.getEntireCoords()}:function(e){return{stableId:e,toString:()=>t.FormulaError.BuiltIn.Ref.toString(),getName:()=>null,getEntireCoords:()=>null}}(e)}},_C=e=>e.includes(`:`)&&!sC(e)&&!/[[\]\\/]/.test(e);function vC(e){if(typeof e!=`string`||sC(e))return null;let t=e.indexOf(`:`);if(t<=0||t===e.length-1)return null;let n=e.substring(0,t),r=e.substring(t+1);return bC.test(n)&&bC.test(r)?[n,r]:null}function yC(e,t,n,r){let i=vC(e);if(!i)return;let[a,o]=i,s=t.indexOf(a),c=t.indexOf(o);if(s===-1||c===-1)return;let l=t.slice(Math.min(s,c),Math.max(s,c)+1),u=e=>n.includes(e),d=!u(a),f=!u(o);if(!d&&!f&&r!==void 0&&n.indexOf(a)>n.indexOf(o)&&(r===a?d=!0:r===o&&(f=!0)),!d&&!f)return;let p=e=>u(e)&&!(e===a&&d)&&!(e===o&&f),m=d?l.find(p):a,h=f?[...l].reverse().find(p):o;return m!==void 0&&h!==void 0?m===h?m:n.indexOf(m)<=n.indexOf(h)?m+`:`+h:h+`:`+m:void 0}var bC=/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;function xC(e){if(typeof e!=`string`)return!1;if(sC(e)){let t=cC(e);return t!==null&&t.sheetEnd!==t.sheetIndex}return vC(e)!==null}var SC=class{constructor(e,t,r,i=null,a=null){this.fakeId=n.CommonUtils.uuidV4(),this.lowerName=e,this.displayName=t,this.lowerScope=i,this.viewScope=a,this._real=r}},CC=(e,t)=>t?`${t}::${e}`:e,wC=e=>e?.getScope?.()?.toLowerCase()??null,TC=class{constructor(e,t,n=e=>e.getName()){this._getByName=e,this._getById=t,this._nameOf=n,this._byName=new Map,this._byId=new Map,this._byRealId=new Map}bind(e,t){let n=e.toLowerCase(),r=(t?.scope)?.toLowerCase()??null,i=!0===t?.own,a,o=null;if(i)a=r;else{if(o=this._getByName(n,r)??null,!o&&!0===t?.existing)return null;a=wC(o)}let s=CC(n,a),c=this._byName.get(s);if(c){c._real||this._adopt(c,o??this._getByName(n,r)??null);let e=c._real??this._getById(c.fakeId);if(!e||this._nameOf(e).toLowerCase()===c.lowerName&&wC(e)===c.lowerScope)return c.fakeId;this._adopt(c,e),this._rekey(c,this._nameOf(e).toLowerCase(),wC(e))}i&&(o=this._getByName(n,r)??null);let l=o&&!i?this._byId.get(o.getId())??this._byRealId.get(o.getId()):void 0;if(l)return this._adopt(l,o),this._rekey(l,n,a),l.fakeId;let u=new SC(n,e,o,a,r);return this._byName.set(s,u),this._byId.set(u.fakeId,u),o&&this._byRealId.set(o.getId(),u),u.fakeId}_adopt(e,t){e._real=t,t&&this._byRealId.set(t.getId(),e)}_rekey(e,t,n){let r=CC(t,n),i=CC(e.lowerName,e.lowerScope);r!==i&&(this._byName.get(i)===e&&this._byName.delete(i),e.lowerName=t,e.lowerScope=n,this._byName.set(r,e))}resolve(e,t){let n=this._byId.get(e);if(!n)return null;if(!n._real){let e=this._getByName(n.lowerName,n.viewScope)??null;e&&this._adopt(n,e)}return{stableId:n.fakeId,toString:()=>(n._real?this._nameOf(n._real):null)??n.displayName}}getRealById(e){let t=this._byId.get(e);if(!t)return null;if(!t._real){let e=this._getByName(t.lowerName,t.viewScope)??null;e&&this._adopt(t,e)}return t._real}reconcile(){let e=[];for(let t of this._byId.values())if(t._real!==null){let n=t._real.getId();if(this._getById(n)){let n=this._nameOf(t._real).toLowerCase(),r=wC(t._real);n===t.lowerName&&r===t.lowerScope||(this._rekey(t,n,r),e.push(t.fakeId))}else this._byRealId.get(n)===t&&this._byRealId.delete(n),t._real=null,e.push(t.fakeId)}else{let n=this._getByName(t.lowerName,t.viewScope)??null;n&&(this._adopt(t,n),this._rekey(t,t.lowerName,wC(n)),e.push(t.fakeId))}return e}cloneMaps(){return{byName:new Map(this._byName),byId:new Map(this._byId),byRealId:new Map(this._byRealId)}}},EC=class{constructor(e,t){this._getId=e,this._getById=t}bind(e,t){let n=this._getById(e);if(n!==null)return n.stableId;let r=t?.tableName;return this._getId(e,r)}resolve(e,t){let n=this._getById(e);return n===null?null:n}},DC=new WeakMap;function OC(e){let t=xi(),n=t?.functions;if(!n)return;let r=DC.get(t);if(!r){r=new Map;for(let e in n)r.set(n[e].toUpperCase(),e);DC.set(t,r)}return r.get(e)}var kC=class{constructor(e){this._deadIds=new Map,this._getCollection=e}bind(e,t){if(this._deadIds.has(e))return e;let r=e.toUpperCase(),i=OC(r)??r,a=this._getCollection()?.getByName(i);if(a&&!a.isLambda())return a.getName();for(let[e,t]of this._deadIds)if(t===r)return e;let o=n.CommonUtils.uuidV4();return this._deadIds.set(o,r),o}resolve(e,t){let n=this._getCollection()?.getByName(e);if(n&&!n.isLambda()){let r=n.getName();return t?.canonical?{stableId:e,toString:()=>r}:{stableId:e,toString:()=>{return e=r,xi()?.functions?.[e]??r;var e}}}let r=this._deadIds.get(e);return r?{stableId:e,toString:()=>r}:null}},AC=Symbol(`sheetxl.formulaNode.internal`),jC=Symbol(`sheetxl.formulaNode.value`),MC=Symbol(`sheetxl.formulaNode.replaced`),NC={canonical:!0},PC=(e,t)=>{let n=e.inputs,r=null;if(n){let e=n.length;r=Array(e);for(let i=0;i<e;i++){let e=n[i];r[i]=e&&PC(e,t)}}let i=((e,t)=>{let n=e.type,r=e.value;if(n===Z.Named){let n=r,i=n?.nameId,a=n?.scope??null;return t&&(i=t.resolve($.NamedFormula,i)?.toString()??i,a&&=t.resolve($.Sheet,a)?.toString()??a),e.binding?.declaration&&e.binding.optional?{name:i,scope:a,optional:!0}:{name:i,scope:a}}if(n===Z.TableReference){let e=typeof r==`string`?r:r?.tableId;return e?t?t.resolve($.Table,e)?.toString()??e:e:``}if(!t)return r;switch(n){case Z.Function:return t.resolve($.Function,r,NC)?.toString()??r;case Z.TableColumn:return t.resolve($.TableColumn,r)?.toString()??r;case Z.Cell:{let e=r;if(e?.scope){let n=t.resolve($.Sheet,e.scope)?.toString()??e.scope;return{...e,scope:n}}return r}case Z.Error:{let e=r;if(e?.scope){let n=t.resolve($.Sheet,e.scope)?.toString()??e.scope;return{...e,scope:n}}return r}default:return r}})(e,t);return{type:e.type,value:i,inputs:r,isReference:e.isReference,[AC]:e,[jC]:i}},FC=(e,t,n)=>{let r=e.inputs,i;if(r){let t=r.length;for(let a=0;a<t;a++){let t=r[a];if(!t)continue;let o=FC(t,e,n);o!==t&&(i||=[...r],i[a]=o)}}let a=e;i&&(a={...e,inputs:i});let o=n(a,t);return o==null||o===a?a:(o[AC]===void 0&&a[AC]!==void 0&&(o[MC]=a[AC]),o)},IC=[`:`,`.:.`,`.:`,`:.`,` `],LC=(e,t)=>{let n=e.type,r=e.value;switch(n){case Z.Function:return sS(String(r),t);case Z.Infix:return hS(r,t[0],t[1],e.isReference??IC.includes(r));case Z.Prefix:return _S(r,t?.[0],e.isReference??r===`@`);case Z.Postfix:return gS(r,t?.[0],e.isReference??r===`#`);case Z.Named:{let e=vS(typeof r==`string`?r:r?.name),t=typeof r==`object`?r?.scope:null;return t&&(e.value={...e.value,scope:t}),typeof r==`object`&&!0===r?.optional&&(e.value={...e.value,optional:!0}),e}case Z.Cell:{let e=r,t=aS(e);return e?.scope&&(t.value.scope=e.scope),t}case Z.TableReference:return{type:Z.TableReference,value:r,inputs:t??null,isReference:!0};case Z.TableSpecifier:return{type:Z.TableSpecifier,value:r,image:`[${r}]`,inputs:null,isReference:!0};case Z.TableColumn:{let e=typeof r==`string`&&r.startsWith(`[`)?r:`[${fS(String(r))}]`;return{type:Z.TableColumn,value:r,image:e,inputs:null,isReference:!0}}case Z.String:case Z.Number:case Z.Boolean:return{type:n,value:r,inputs:null,isLiteral:!0};default:return{type:n,value:r,inputs:t??null,isReference:e.isReference}}},RC=e=>{let t=e[AC],n=e.inputs,r=null;if(n){let e=n.length;r=Array(e);for(let t=0;t<e;t++){let e=n[t];r[t]=e&&RC(e)}}if(t){let n=e.value!==e[jC],i=!1,a=t.inputs;if(r&&a&&r.length===a.length){for(let e=0;e<r.length;e++)if(r[e]!==a[e]){i=!0;break}}else i=r===null!=(a==null)||(r?.length??0)!==(a?.length??0);if(!n&&!i)return t;if(!n)return{...t,inputs:r};let o=LC(e,r);return zC(o,t),o}let i=LC(e,r),a=e[MC];return a&&zC(i,a),i},zC=(e,t)=>{jS(e,t),e.type!==t.type&&e.image!==void 0&&(e.image=void 0)};function BC(e,t){return PC(e,t)}var VC=e=>typeof e==`object`&&!!e&&!0===e.isLambda,HC=(e,t)=>e+t,UC=(e,t)=>e-t,WC=(e,t)=>eU(e*t),GC=(e,n)=>n===0?t.FormulaError.BuiltIn.Div0:eU(e/n),KC=(e,n)=>{if(e===0){if(n<0)return t.FormulaError.BuiltIn.Div0;if(n===0)return NaN}if(e<0){if(Number.isInteger(n)&&Math.abs(n)<=4294967294)return eU(e**n);let t=Number((1/n).toPrecision(15));return Number.isInteger(t)&&Math.abs(t%2)===1?eU(-((-e)**n)):NaN}return eU(e**n)},qC=(e=``,n=``)=>{e===null&&(e=``),n===null&&(n=``);let r=typeof n;typeof e==`boolean`&&(e=Ci(e)),r===`boolean`&&(n=Ci(n));let i=``+e+n;return i.length>t.Scalar.MAX_TEXT_LENGTH?i.slice(0,t.Scalar.MAX_TEXT_LENGTH):i},JC=(e,t=null,n=null)=>e.compare(t,n)===0,YC=(e,t=null,n=null)=>e.compare(t,n)!==0,XC=(e,t=null,n=null)=>e.compare(t,n)>0,ZC=(e,t=null,n=null)=>e.compare(t,n)>=0,QC=(e,t=null,n=null)=>e.compare(t,n)<0,$C=(e,t=null,n=null)=>e.compare(t,n)<=0,ew={type:t.ScalarType.Number,coerce:[t.ScalarType.Boolean,t.ScalarType.String],onError:`value`,misalignValue:t.FormulaError.BuiltIn.NA},tw={type:t.ScalarType.String,coerce:[t.ScalarType.Boolean,t.ScalarType.Number],onError:`value`,misalignValue:t.FormulaError.BuiltIn.NA},nw={onError:`value`,misalignValue:t.FormulaError.BuiltIn.NA},rw=e=>typeof e==`object`&&e&&!0===e.isIReferenceRange&&e.size===1?e.getValueAt(0,0)??null:e,iw=(e,n,r,i)=>{if(n!==null&&n.colStart!==void 0&&(n=e.getValueAt(n.rowStart,n.colStart,n.scope))&&t.FormulaError.isError(n))return n;if(r!==null&&r.colStart!==void 0&&(r=e.getValueAt(r.rowStart,r.colStart,r.scope))&&t.FormulaError.isError(r))return r;if(n=rw(n),r=rw(r),typeof n==`number`&&typeof r==`number`)return i(n,r);let a,o;if(n?.isIRange?a=n:r?.isIRange&&(o=r),!a&&!o){let a=e.getRuntime();return n=KH(a,n,IH(n,!0),t.ScalarType.Number,!0),r=KH(a,r,IH(r,!0),t.ScalarType.Number,!0),n&&t.FormulaError.isError(n)?n:r&&t.FormulaError.isError(r)?r:i(n,r)}let s=!a,c=s?n:r;return(a??o).broadcast(c,(n,r)=>n&&t.FormulaError.isError(n)?n:r&&t.FormulaError.isError(r)?r:tU(s?i(r,n):i(n,r),e),ew).fillEmpty(0)},aw=(e,n,r,i)=>{if(VC(n)||VC(r)||(0,t.isLazyValue)(n)||(0,t.isLazyValue)(r))return t.FormulaError.BuiltIn.Value;if(n!==null&&n.colStart!==void 0&&(n=e.getValueAt(n.rowStart,n.colStart,n.scope))&&t.FormulaError.isError(n))return n;if(r!==null&&r.colStart!==void 0&&(r=e.getValueAt(r.rowStart,r.colStart,r.scope))&&t.FormulaError.isError(r))return r;let a,o;n=rw(n),r=rw(r);let s=!1;return n?.isIRange?(a=n,o=r):r?.isIRange&&(a=r,o=n,s=!0),a?a.broadcast(o,(n,r)=>n&&t.FormulaError.isError(n)?n:r&&t.FormulaError.isError(r)?r:s?i(e,r,n):i(e,n,r),nw):t.FormulaError.isError(n)?n:t.FormulaError.isError(r)?r:i(e,n,r)},ow=(e,n,r)=>{if(r??=0,r!==null&&r.colStart!==void 0&&(r=e.getValueAt(r.rowStart,r.colStart,r.scope))&&t.FormulaError.isError(r))return r;r=rw(r);let i,a=1;if(n===`+`)return r;if(n!==`-`)throw new t.FormulaError.Value(`Unrecognized prefix: ${n}`);return a=-a,r?.isIRange&&(i=r),i?i.broadcast(a,(e,n)=>e&&t.FormulaError.isError(e)?e:n&&t.FormulaError.isError(n)?n:WC(e,n),ew):typeof(r=KH(e.getRuntime(),r,IH(r,!0),t.ScalarType.Number,!0))==`number`?r*a:t.FormulaError.BuiltIn.Value},sw=e=>e.getCode()<=t.FormulaError.Code.NA?e:t.FormulaError.BuiltIn.Value,cw=(e,n,r,i)=>{if(t.FormulaError.isError(n))return sw(n);if(r&&t.FormulaError.isError(r))return sw(r);if(!n)return t.FormulaError.BuiltIn.Ref;if(n.isIReferenceRange&&r&&!r.isIReferenceRange?r=e.getReference(r):r&&r.isIReferenceRange&&n&&!n.isIReferenceRange&&(n=e.getReference(n)),n.isIReferenceRange&&(n=n.getCoords()),n.colStart===void 0||(r.isIReferenceRange&&(r=r.getCoords()),r.colStart===void 0))return t.FormulaError.BuiltIn.Value;let a=i(n,r);return t.FormulaError.isError(a)?a:a?e.getReference(a):t.FormulaError.BuiltIn.Null},lw={"+":(e,t,n)=>iw(e,t,n,HC),"-":(e,t,n)=>iw(e,t,n,UC),"*":(e,t,n)=>iw(e,t,n,WC),"/":(e,t,n)=>iw(e,t,n,GC),"^":(e,t,n)=>iw(e,t,n,KC)," ":(e,t,n,r)=>cw(e,t,n,nf),":":(e,t,n,r)=>cw(e,t,n,rf),".:.":(e,t,n,r)=>{let i=cw(e,t,n,rf);return e.getFunction(`TRIMRANGE`).execute(i,3,3)},".:":(e,t,n,r)=>{let i=cw(e,t,n,rf);return e.getFunction(`TRIMRANGE`).execute(i,1,1)},":.":(e,t,n,r)=>{let i=cw(e,t,n,rf);return e.getFunction(`TRIMRANGE`).execute(i,2,2)},"&":(e,n,r)=>((e,n,r,i)=>{if(n!==null&&n.colStart!==void 0&&(n=e.getValueAt(n.rowStart,n.colStart,n.scope))&&t.FormulaError.isError(n))return n;if(r!==null&&r.colStart!==void 0&&(r=e.getValueAt(r.rowStart,r.colStart,r.scope))&&t.FormulaError.isError(r))return r;if(n=rw(n),r=rw(r),typeof n==`string`&&typeof r==`string`)return i(n,r);let a,o;if(n?.isIRange?a=n:r?.isIRange&&(o=r),!a&&!o){let a=e.getRuntime();return n=KH(a,n,IH(n,!0),t.ScalarType.String,!1),r=KH(a,r,IH(r,!0),t.ScalarType.String,!1),t.FormulaError.isError(n)?n:t.FormulaError.isError(r)?r:i(n,r)}let s=!a,c=s?n:r;return(a??o).broadcast(c,(e,n)=>e&&t.FormulaError.isError(e)?e:n&&t.FormulaError.isError(n)?n:s?i(n,e):i(e,n),tw)})(e,n,r,qC),"=":(e,t,n)=>aw(e,t,n,JC),"<>":(e,t,n)=>aw(e,t,n,YC),">":(e,t,n)=>aw(e,t,n,XC),"<":(e,t,n)=>aw(e,t,n,QC),">=":(e,t,n)=>aw(e,t,n,ZC),"<=":(e,t,n)=>aw(e,t,n,$C)},uw={"-":(e,t)=>ow(e,`-`,t),"+":(e,t)=>ow(e,`+`,t),"@":(e,n)=>{if(!n||!n.isIRange)return n;let r=n;if(!n.isIReferenceRange)return r.getValueAt(0,0);let i=n.getCoords(),a=r.getRowCount(),o=r.getColumnCount(),s=e.getRow()-i.rowStart,c=e.getColumn()-i.colStart,l=s>=0&&s<a,u=c>=0&&c<o;return l&&u?r.getValueAt(s,c):l&&o===1?r.getValueAt(s,0):u&&a===1?r.getValueAt(0,c):a===1&&o===1?r.getValueAt(0,0):t.FormulaError.BuiltIn.Value}},dw={"%":(e,t)=>iw(e,t,100,GC),"#":(e,n)=>t.FormulaError.isError(n)?sw(n):n?(n.isIReferenceRange&&(n=n.getCoords()),n.colStart===void 0?t.FormulaError.BuiltIn.Value:n.rowStart!==n.rowEnd||n.colStart!==n.colEnd?t.FormulaError.BuiltIn.Ref:e.getSpillAt(n.rowStart,n.colStart,n.scope)||t.FormulaError.BuiltIn.Ref):t.FormulaError.BuiltIn.Ref};function fw(e,t){for(let n=e.length-1;n>=0;n--)if(e[n].type===t)return e[n]}var pw=class{constructor(){this.referenceIndices=[],this.rootReferences=new Set,this.cells=new Map,this.references=new Map,this.names=new Map}processNode(e,t){let n=e.type;if(e.isReference){let t={node:e,index:this.references.size,op:null,value:null,inputs:null};if(this.references.set(e,t),n===Z.Cell){let n=e.value;n.$colIndex&&(t.hasHorizontalAbs=!0),n.$rowIndex&&(t.hasVerticalAbs=!0),t.value=this.cells.size,this.cells.set(e,this.cells.size),this.rootReferences.add(t),e.referenceIndex=this.referenceIndices.length,this.referenceIndices.push(t.index);return}if(n===Z.Infix||n===Z.Prefix||n===Z.Postfix||n===Z.List){let n=e.inputs||[],r=n.length,i=e.value;t.op=i;let a=rU(r);t.inputs=a;for(let e=0;e<r;e++){let r=n[e],i=this.references.get(r);i?(i.hasHorizontalAbs&&(t.hasHorizontalAbs=!0),i.hasVerticalAbs&&(t.hasVerticalAbs=!0),a[e]=i.index):a[e]=-1,i&&this.rootReferences.delete(i)}if(this.rootReferences.add(t),Uw.includes(i)){let r=n[0],i=!!r&&r.type===Z.Cell,a=n[1],o=!!a&&a.type===Z.Cell;i&&o&&a.referenceIndex!==void 0&&r.referenceIndex!==void 0&&(this.referenceIndices.splice(a.referenceIndex,1),a.referenceIndex=r.referenceIndex,e.referenceIndex=r.referenceIndex,this.referenceIndices[r.referenceIndex]=t.index)}else i===`#`&&n[0]&&(e.referenceIndex=n[0].referenceIndex);return}if(n===Z.Error||n===Z.Named){let r=n===Z.Named?e.value.nameId:TS(e.value),i=this.names.get(r);t.op=n,i===void 0&&(i=this.names.size,this.names.set(r,i)),t.value=i,this.rootReferences.add(t),e.referenceIndex=this.referenceIndices.length,this.referenceIndices.push(t.index);return}if(n===Z.TableReference)return t.op=n,this.rootReferences.add(t),e.referenceIndex=this.referenceIndices.length,void this.referenceIndices.push(t.index)}else if(t&&t.isReference){let t={node:e,index:this.references.size,op:Z.Function,value:e.value,inputs:null};this.references.set(e,t)}}};function mw(e,t=!1,n=zx){let r=[],i=new Set,a=(e,n,a)=>{let o={type:e.type,value:e.type===Z.Error?ES(e.value):e.value};e.image!==void 0&&(o.text=(e=>{let n=t?e.value?.scopeImage:void 0;return typeof n==`string`?n:``})(e)+e.image);let s=e.evalIndex??a;return s!==void 0&&(o.evalIndex=s),n&&(o.context=n),e.referenceIndex!==void 0&&(o.referenceIndex=e.referenceIndex),e.isReference&&i.add(o),r.push(o),o},o=(e,t,n,i,a)=>{if(t==null||r.length>1&&e===Z.Whitespace&&r[r.length-1].type===Z.Whitespace)return;let o={type:e,value:t,text:a??t};i!==void 0&&(o.evalIndex=i),n&&(o.context=n),r.push(o)};(function e(s,c,l){let u=s.evalIndex??l??0,d=s.type,f=(t,r,i)=>{if(!t)return;let a=t.length;for(let s=0;s<a;s++)e(t[s],r,i),s<a-1&&o(Z.Separator,`,`,r,i,n.separatorFunction)};if(s.isLiteral){if(o(Z.Whitespace,s.wsBefore,c,u),d===Z.Array){o(Z.Type,`{`,c,u);let t=s.value,r=t.length;for(let i=0;i<r;i++){let a=t[i],s=a.value,l=s.length;for(let t=0;t<l;t++){let r=s[t];o(Z.Whitespace,r.wsBefore,c,u),e(r,c,u),o(Z.Whitespace,r.wsAfter,c,u),t<l-1&&o(Z.Separator,`,`,c,u,n.separatorColumn)}i<r-1&&(o(Z.Whitespace,a.wsBefore,c,u),o(Z.Separator,`;`,c,u,n.separatorRow),o(Z.Whitespace,a.wsAfter,c,u))}s.error||o(Z.Type,`}`,c,u)}else d===Z.String&&(s={type:d,value:`"`+`${s.value}`.replace(/"/g,`""`)+`"`,image:s.image}),a(s,c,u);o(Z.Whitespace,s.wsAfter,c,u)}else if(d===Z.Infix)e(s.inputs[0],c,u),o(Z.Whitespace,s.wsBefore,c,u),a(s,c,u),o(Z.Whitespace,s.wsAfter,c,u),e(s.inputs[1],c,u);else if(d===Z.Prefix)o(Z.Whitespace,s.wsBefore,c,u),a(s,c,u),o(Z.Whitespace,s.wsAfter,c,u),s.inputs&&e(s.inputs[0],c,u);else if(d===Z.Postfix){s.inputs?.[0]&&e(s.inputs[0],c,u),o(Z.Whitespace,s.wsBefore,c,u);let t=a(s,c,u),n=r[r.length-2];s.value===`#`&&t.text!==void 0&&!s.wsBefore&&i.has(n)&&(n.text=(n.text??``)+t.text,t.text=``),o(Z.Whitespace,s.wsAfter,c,u)}else{o(Z.Whitespace,s.wsBefore,c,u);let l=s.inputs;switch(d){case Z.Function:{let t=String(s.value),i={type:Z.Function,value:t,text:s.image??t,evalIndex:s.evalIndex};c&&(i.context=c),r.push(i);let a={name:t,argIndex:-1,type:s.binder?.kind??`function`};if(c?.bound&&(a.bound=c.bound),o(Z.Paren,`(`,a,s.evalIndex),l){let t=l.length,r=s.binder?.kind,i=r===`lambda`?1:r===`let`?2:0,c=a.bound;for(let s=0;s<t;s++){let d=i&&s>=i?l[s-i]:void 0;if(d?.binding?.declaration){let e=d.value.nameId,t=r===`let`?hT(l[s-1]):void 0;c=mT(c,t?{name:e,params:t}:{name:e})}let f={...a,argIndex:s};c&&(f.bound=c),e(l[s],f,u),s<t-1&&o(Z.Separator,`,`,f,u,n.separatorFunction)}}s.error||o(Z.Paren,`)`,a,s.evalIndex);break}case Z.Call:{let t=function(e){return e.inputs?.[0]}(s),i=r.length;if(t&&e(t,c,u),t?.type===Z.Named)for(let e=i;e<r.length;e++){let t=r[e];t.type!==Z.Whitespace&&(t.evalIndex=s.evalIndex,t.type===Z.Named&&(t.type=Z.Function,t.value=t.value.name))}let a={name:t?.type===Z.Named?t.value.nameId:``,argIndex:-1,type:`function`};c?.bound&&(a.bound=c.bound),o(Z.Paren,`(`,a,s.evalIndex);let l=function(e){let t=e.inputs;return t&&t.length>1?t.slice(1):[]}(s),d=l.length;for(let t=0;t<d;t++){let r={...a,argIndex:t};e(l[t],r,u),t<d-1&&o(Z.Separator,`,`,r,u,n.separatorFunction)}s.error||o(Z.Paren,`)`,a,s.evalIndex);break}case Z.Cell:a(s,c,u);break;case Z.Paren:o(d,`(`,c,u),f(l,c,u),s.error||o(d,`)`,c,u);break;case Z.TableReference:{let n=s.value?.tableId??``,a={name:n,argIndex:-1,type:`table`},d=r.length,f=s.image,p,m=!1;if(n&&f){let e=0;if(f.charCodeAt(0)===91){let t=f.indexOf(`]`);t!==-1&&f.charCodeAt(t+1)===33&&(e=t+2)}let n=f.indexOf(`[`,e);if(m=n===0&&l!=null,n>0)p=f.slice(0,n);else if(!l){let e=f.lastIndexOf(`!`);p=t||e===-1?f:f.slice(e+1)}}if(!n||m&&t||o(Z.TableReference,n,c,u,p),l&&o(Z.Paren,`[`,a,u),l){let t=l.length;for(let n=0;n<t;n++){let r={...a,argIndex:n};e(l[n],r,u),n<t-1&&o(Z.Separator,`,`,r,u)}}l&&!s.error&&o(Z.Paren,`]`,a,u);let h=s.referenceIndex;for(let e=d;e<r.length;e++)h!==void 0&&(r[e].referenceIndex=h),i.add(r[e]);break}case Z.TableSpecifier:case Z.TableColumn:{let e=s.image,t=e!=null&&e.startsWith(`[`)&&e.endsWith(`]`);t&&o(Z.Paren,`[`,c,u);let n={table:c?.type===`table`?c.name:``,name:s.value},i={type:d,value:n,text:t?e.slice(1,-1):e??n.name};u!==void 0&&(i.evalIndex=u),c&&(i.context=c),r.push(i),t&&o(Z.Paren,`]`,c,u);break}case Z.List:f(l,c,u);break;case Z.Named:{let e=a(s,c,u),t=s.value;e.value=t.scope?{name:t.nameId,scope:t.scope}:{name:t.nameId},s.binding?.declaration&&s.binding.optional&&(e.value.optional=!0),s.binding&&(e.type=Z.Parameter,s.binding.declaration&&(e.value.declaration=!0)),delete e.referenceIndex;break}default:s.value!==void 0&&a(s,c,u),l&&l.forEach(t=>e(t,c,u))}o(Z.Whitespace,s.wsAfter,c,u)}})(e);let s=new Map;for(let e of r)if(e.type===Z.Cell&&e.referenceIndex!==void 0){let t=s.get(e.referenceIndex);t?t.push(e):s.set(e.referenceIndex,[e])}for(let e of s.values())e.length===1?e[0].refSide=`self`:(e[0].refSide=`left`,e[e.length-1].refSide=`right`);let c=new Map;for(let e of r)if(e.referenceIndex!==void 0&&e.evalIndex!==void 0){let t=c.get(e.referenceIndex);(t===void 0||e.evalIndex<t)&&c.set(e.referenceIndex,e.evalIndex)}if(c.size>0){for(let e of r)if(e.referenceIndex!==void 0){let t=c.get(e.referenceIndex);t!==void 0&&(e.evalIndex=t)}}return r}function hw(e,t){let n=``;for(let r=0;r<e.length;r++){let i=e[r],a=i.type;if(a===Z.Cell||a===Z.Named||a===Z.Error){let e=a===Z.Cell?i.value?.scope:i.value?.scope??void 0,r=a===Z.Error?i.text!==void 0&&OS(i.text):i.text?.includes(`!`)??!1;if(e&&i.text!==void 0&&!r){n+=ud(t?.resolve($.Sheet,e)?.toString()??e)+`!`+i.text;continue}if(a===Z.Named){n+=i.text??i.value?.name??``;continue}}if(a===Z.Parameter){n+=i.text??i.value?.name??``;continue}let o=i.text??i.value;typeof o==`string`&&(n+=o)}return n}function gw(e,t){let n;if(AS(e,e=>{e.evalIndex===t&&(n=e)}),!n)return[];let r=mw(n);return r.length>1&&r[0].type===Z.Whitespace&&r.shift(),r.length>1&&r[r.length-1].type===Z.Whitespace&&r.pop(),r}function _w(e){return AS(e,e=>{if(e.type!==Z.TableReference)return;let t=function(e){if(e.value!==null&&typeof e.value==`object`)return e.value;let t=e.value,n=e.inputs,r=!1,i=!1,a=!1,o=!1,s=null,c=null,l=!1,u=e=>{e?.type===Z.TableColumn&&(s=e.value,c=e.value)};if(n)for(let e of n){let t=e.type;if(t===Z.TableSpecifier){let t=e.value.toUpperCase().trim();t===`#ALL`?i=!0:t===`#HEADERS`?a=!0:t===`#TOTALS`?o=!0:t===`#DATA`?r=!0:t!==`@`&&t!==`#THIS ROW`||(l=!0)}else if(t===Z.TableColumn)u(e);else if(t===Z.Infix&&e.value===`:`){let t=e.inputs?.[0],n=e.inputs?.[1];t?.type===Z.TableColumn&&(s=t.value),n?.type===Z.TableColumn&&(c=n.value)}else if(t===Z.Prefix&&e.value===`@`){l=!0;let t=e.inputs?.[0];t?.type===Z.Infix&&t.value===`:`?(t.inputs?.[0]?.type===Z.TableColumn&&(s=t.inputs[0].value),t.inputs?.[1]?.type===Z.TableColumn&&(c=t.inputs[1].value)):u(t)}}let d;return d=i?1:a&&r?4:o&&r?5:a?2:o?3:0,{tableId:t,spec:d,columnFromId:s,columnToId:c,isThisRow:l}}(e);return{...e,value:t}})}function vw(e){return AS(e,e=>{if(e.type!==Z.TableReference)return;let t=e.inputs;if(!t||t.findIndex(e=>e.type===Z.TableSpecifier&&e.value.toUpperCase().trim()===`#THIS ROW`)===-1)return;let n=[],r;for(let e of t)(e.type!==Z.TableSpecifier||e.value.toUpperCase().trim()!==`#THIS ROW`)&&(e.type!==Z.TableColumn&&(e.type!==Z.Infix||e.value!==`:`)||r?n.push(e):r=e);if(!r)return n.push({type:Z.Prefix,value:`@`,inputs:null,isReference:!0}),{...e,inputs:n};let i=r.image??r.value,a=i.startsWith(`[`)&&i.endsWith(`]`)?{...r,image:i.slice(1,-1)}:r;return n.push(_S(`@`,a,!0)),{...e,inputs:n}})}function yw(e){return AS(e,e=>{if(e.type!==Z.TableReference||e.inputs?.length!==0||e.error)return;let t=e.value;return(typeof t==`string`?t:t?.tableId)?{...e,inputs:null}:void 0})}function bw(e){return AS(e,e=>{if(e.type!==Z.TableReference||!e.inputs)return;let t=e.value,n=typeof t==`string`?t:t?.tableId,r=e.image;if(!n||r?.charCodeAt(0)!==91)return;let i=r.indexOf(`]`);if(i!==-1&&r.charCodeAt(i+1)===33)return;let a={...e};return delete a.image,a})}var xw=e=>{if(e?.type!==Z.TableSpecifier)return 4;switch(e.value.toUpperCase().trim()){case`#ALL`:return 0;case`#HEADERS`:return 1;case`#DATA`:return 2;case`#TOTALS`:return 3;default:return 4}};function Sw(e){return AS(e,e=>{if(e.type!==Z.TableReference)return;let t=e.inputs;if(!t||t.length<2)return;let n=t.map((e,t)=>({input:e,index:t,rank:xw(e)})).sort((e,t)=>e.rank-t.rank||e.index-t.index).map(e=>e.input);return n.every((e,n)=>e===t[n])?void 0:{...e,inputs:n}})}function Cw(e){if(!e)return n.CommonUtils.EmptyArray;let t=n.CommonUtils.EmptyArray;return AS(e,e=>{if(e.type!==Z.Named||e.binding)return;let r=e.value.nameId;r&&(t===n.CommonUtils.EmptyArray&&(t=[]),t.includes(r)||t.push(r))}),t}function ww(e,t){if(!e)return n.CommonUtils.EmptyArray;let r=n.CommonUtils.EmptyArray;return AS(e,(e,i,a)=>{if(!e.isReference||i?.isReference)return;let o=e.type;if(o===Z.Named||o===Z.Error||o===Z.TableReference||fw(a,Z.TableReference))return;let s=function(e){let t=e;for(;t;){if(t.referenceIndex!==void 0)return t.referenceIndex;if(!t.isReference)return;t=t.inputs?.[0]}}(e);s!==void 0&&function(e,t,n){let r=e;for(let e=t.length-1;e>=0;e--){let i=t[e];if(i.type===Z.Paren||i.isReference){r=i;continue}if(i.type!==Z.Function)return!0;let a=n?.(String(i.value));if(!a)return!0;let o=i.inputs?i.inputs.indexOf(r):-1;return(o>=0?Pw(a.getDeclaration().getParameters(),o):null)?.getRangeType()!==`p`}return!0}(e,a,t)&&(r===n.CommonUtils.EmptyArray&&(r=[]),r.includes(s)||r.push(s))}),r.length>1&&r.sort((e,t)=>e-t),r}var Tw=new Set([`SUBTOTAL`,`AGGREGATE`]);function Ew(e,t){if(!e||!t)return!1;let n=!1;return AS(e,e=>{if(n||e.type!==Z.Function)return;let r=t(e.value)?.getName();r&&Tw.has(r.toUpperCase())&&(n=!0)}),n}function Dw(e,t){if(!e||!t)return!1;let n=!1;return AS(e,e=>{n||e.type!==Z.Function||!0===t(e.value)?.getDeclaration().getReturnType()?.isVolatile()&&(n=!0)}),n}var Ow=Object.freeze({value:!1,array:!1}),kw=(e,t)=>{let n=function(e,t){if(!e||!t)return Ow;let n=!1,r=!1;return AS(e,e=>{if(n)return;let i=e.type;if(i===Z.Named)return void(e.binding===void 0&&(n=!0));if(i===Z.Prefix)return void(e.value===`@`&&(n=!0));if(i===Z.Call)return void(n=!0);if(i!==Z.Function||e.binder!==void 0)return;let a=t(e.value);if(!a)return void(n=!0);if(r||!0!==e.implicitIntersect)return;let o=a.getDeclaration().getParameters(),s=e.inputs;if(s)for(let e=0;e<s.length;e++){let n=Pw(o,e);if(n!==null&&n.isValueOrRange()&&zw(s[e],t))return void(r=!0)}}),{value:!n&&!r,array:!n}}(e,t);return{isBlankCacheable:n.value,isBlankCacheableArray:n.array}},Aw=(e,t)=>{let n=e.length;if(n===0)return null;if(t<n-1)return e[t];let r=e[n-1],i=r.getRepeatingTypes();return i&&i.length!==0?i[(t-(n-1))%i.length]:t<n?e[t]:r.isRest()?r:null};function jw(e){if(!e)return n.CommonUtils.EmptyArray;let t=n.CommonUtils.EmptyArray,r=e=>{e&&(t===n.CommonUtils.EmptyArray&&(t=[]),t.includes(e)||t.push(e))},i=e=>{typeof e==`string`&&r(cC(e)?.bookId)};return AS(e,e=>{if(e.type===Z.Named){if(e.binding)return;let t=e.value;r(t.nameId),i(t.scope)}else if(e.type===Z.TableReference){let t=e.value;r(typeof t==`string`?t:t?.tableId)}else if(e.type===Z.Cell){let t=e.value?.scope;i(t),vC(t)&&r(t)}else e.type===Z.Error&&i(e.value?.scope)}),t}var Mw=(e,t)=>{if(!0===e.lazyArg)return!0;if(t?.binder?.kind!==`lambda`)return!1;let n=t.inputs;return n[n.length-1]===e},Nw=new Set([`IF`,`IFS`,`SWITCH`,`CHOOSE`,`IFERROR`,`IFNA`]),Pw=(e,t)=>{let n=e.length;if(n===0)return null;if(t<n)return e[t];let r=e[n-1];if(!r.isRest())return null;let i=r.getRepeatingTypes();return i&&i.length!==0?i[(t-(n-1))%i.length]:r},Fw=e=>e.getScalarType()!==null&&e.getRangeType()===null&&e.getLambda()===null&&!e.isValueOrRange(),Iw=(e,t,n)=>!(e.isRest()||!Fw(e)||!zw(t,n))&&!(e.isNoLift()&&Lw(t,n)),Lw=(e,n)=>{if(!e)return!1;let r=e.inputs;switch(e.type){case Z.Cell:case Z.Named:case Z.TableReference:return!0;case Z.Infix:case Z.Prefix:case Z.Postfix:return!0===e.isReference&&e.value!==`@`;case Z.Paren:case Z.List:return!!r&&r.length===1&&Lw(r[0],n);case Z.Function:{if(e.binder!==void 0)return!1;let i=String(e.value).toUpperCase();if(Nw.has(i)){if(!r)return!1;for(let e=0;e<r.length;e++)if(Lw(r[e],n))return!0;return!1}let a=n?.(e.value);return!!a&&a.getDeclaration().getReturnType().getKind()===t.ValueKind.Reference}default:return!1}},Rw=(e,t)=>{if(!e)return!1;for(let n=0;n<e.length;n++)if(zw(e[n],t))return!0;return!1};function zw(e,n){if(!e)return!1;if(e.arrayValued!==void 0)return e.arrayValued;let r,i=e.type,a=e.inputs;switch(i){case Z.Array:r=!0;break;case Z.Cell:{let t=e.value;r=t.rowIndex===-(2**53-1)||t.colIndex===-(2**53-1);break}case Z.Named:case Z.Call:case Z.TableReference:r=!0;break;case Z.Infix:case Z.Prefix:case Z.Postfix:r=e.isReference?e.value!==`@`:Rw(a,n);break;case Z.Paren:case Z.List:r=!a||a.length!==1||zw(a[0],n);break;case Z.Function:{let i=e.binder;if(i!==void 0){r=i.kind===`lambda`||!!a&&zw(a[a.length-1],n);break}let o=String(e.value).toUpperCase();if(Nw.has(o)){r=Rw(a,n);break}if(o===`INDEX`){if(r=!1,a)for(let e=1;e<a.length;e++){let t=a[e];if(!t||t.type===Z.Empty||t.isLiteral&&t.value===0||zw(t,n)){r=!0;break}}break}let s=n?.(e.value);if(!s){r=!0;break}let c=s.getDeclaration().getReturnType(),l=c.getKind();r=l===t.ValueKind.Array||l===t.ValueKind.Reference||l===null&&c.getRangeType()!==null;break}default:r=!1}return e.arrayValued=r,r}var Bw=e=>e.getRangeType()===`*`&&e.getLambda()===null&&e.getArrayDepth()<=+!!e.isRest();function Vw(e,t,n,r=!1,i=null,a=null){let o,s,c=n;c=_w(c),r||(c=vw(c),c=Sw(c),c=yw(c),c=bw(c)),[o,s]=function(e){let t=new Map,n=0,r=[e];for(;r.length>0;){let e=r.shift();if(t.set(e,{...e,evalIndex:n++}),e&&e.inputs)for(let t of e.inputs)r.push(t)}return t.forEach((e,n)=>{n&&n.inputs&&(e.inputs=n.inputs.map(e=>t.get(e)??e))}),[t.get(e),n]}(c);let l=rU(s),u=[],d=[],f=new pw,p,m=!1;(function(e,t){if(!e||!t)return;let n=e=>{if(!e)return;e.inLazy=!0,e.type===Z.Named&&(e.deferredResolve=!0);let t=e.inputs;if(t)for(let e=0;e<t.length;e++)n(t[e])};AS(e,e=>{if(e.type!==Z.Function||e.binder!==void 0)return;let r=e.inputs;if(!r||r.length===0)return;let i=t(e.value)?.getDeclaration().getParameters();if(i)for(let t=0;t<r.length;t++){let a=r[t];a&&a.type!==Z.Empty&&Aw(i,t)?.isLazy()&&(a.lazyArg=!0,e.hasLazyArgs=!0,n(a))}})})(o,a);let h=e=>{p===void 0&&(p=new Map);let t=p.get(e);return t===void 0&&p.set(e,t=[]),t},g=(e,t)=>{e===void 0?u.push(t):h(e).push(t)};o=AS(o,(t,n,r)=>{let i=t.type,a=t.evalIndex;if(l[a]=null,i===Z.TableColumn||i===Z.TableSpecifier||t.isReference&&fw(r,Z.TableReference))return;if(m||=!Jw(t),t.binding?.declaration)return d[t.binding.slot]=-1,void(l[a]=void 0);let o=((e,t,n)=>{if(Mw(e,t))return e;for(let e=n.length-1;e>=0;e--)if(Mw(n[e],n[e-1]))return n[e]})(t,n,r);o===t&&h(t),o!==void 0&&i===Z.Named&&(t.deferredResolve=!0);let s=t.binder;if(s&&s.kind===`let`){let e=t.inputs,n=e?.length??0,r=0;for(let t=0;t+1<n&&r<s.slots.length;t+=2)e[t]?.binding?.declaration&&(d[s.slots[r++]]=e[t+1]?.evalIndex??-1)}if((t.isReference||n&&n.isReference)&&(f.processNode(t,n),t.isReference)){if(i===Z.Named)return void(o!==void 0&&g(o,t));if(i===Z.Cell||i===Z.TableReference||i===Z.Error)return;if(i===Z.Infix||i===Z.Prefix||i===Z.Postfix||i===Z.List)return void g(o,t)}if(t.isLiteral)if(i!==Z.Array)l[a]=t.value;else{let n=t.value,r=n.length,i=rU(r);for(let e=0;e<r;e++){let t=n[e].value,r=t.length,a=rU(r);for(let e=0;e<r;e++){let n=t[e],r=null;if(n&&(r=n.type===Z.Error?TS(n.value):n.value,n.type===Z.Prefix)){let e=n.value;r=n.inputs[0].value,e===`-`&&(r=-r)}a[e]=r}i[e]=a}let o=nU(i);l[a]=new iW(e,o.values,o.coords,void 0,o.isLiteral)}else{if(i!==Z.Empty)return g(o,t),t;l[a]=void 0}}),p?.forEach((e,t)=>{t.deferred=e});let _=rU(f.cells.size);f.cells.forEach((e,t)=>{let n=t.value,r=n.colIndex,i=n.rowIndex,a=n.$colIndex,o=n.$rowIndex,s={colStart:r,rowStart:i,colEnd:r,rowEnd:i,$colStart:a,$rowStart:o,$colEnd:a,$rowEnd:o};r===-(2**53-1)&&(s.colEnd=2**53-1),i===-(2**53-1)&&(s.rowEnd=2**53-1),n.scope&&(s.scope=n.scope),_[e]=s});let v=_.length,y=rU(v);for(let e=0;e<v;e++)y[e]={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null};let b=rU(f.references.size);f.references.forEach(e=>{b[e.index]=e});let x=[];f.rootReferences.forEach(e=>{x.push(e.index)}),function(e,t,n=!1){if(n){let t=e=>{if(!e)return;let n=e.type;n!==Z.Function&&n!==Z.Call||(e.implicitIntersect=!0);let r=e.inputs;if(r)for(let e=0;e<r.length;e++)t(r[e])};t(e);return}let r=e=>zw(e,t),i=(e,n)=>{if(!e)return;let a=e.type;a!==Z.Function&&a!==Z.Call||(e.implicitIntersect=n);let o=e.inputs;if(o){if(a===Z.Infix||a===Z.Prefix||a===Z.Postfix){let t=!e.isReference;for(let e=0;e<o.length;e++)i(o[e],(!t||!r(o[e]))&&n);return}if(a===Z.Function){let r=e.binder;if(r!==void 0){let e=r.kind!==`lambda`&&n;for(let t=0;t<o.length;t++)i(o[t],e);return}let a=t?.(e.value)?.getDeclaration().getParameters(),s=!1;if(a)for(let e=0;e<o.length&&!s;e++){let n=o[e];if(!n)continue;let r=Pw(a,e);r&&Iw(r,n,t)&&(s=!0)}s&&(e.implicitIntersect=!1);for(let e=0;e<o.length;e++)i(o[e],!s&&n);return}for(let e=0;e<o.length;e++)i(o[e],n)}};i(e,!r(e))}(o,a,!0===n.legacyIntersect);let S=e=>{let t=e.length;for(let n=0;n<t;n++){let t=e[n],r=t.type;r===Z.Infix?t.fn=lw[t.value]:r===Z.Prefix?t.fn=uw[t.value]:r===Z.Postfix&&(t.fn=dw[t.value])}},C;S(u),p?.forEach(S);let w=r?Bx(pt(e.getLocale()).decimal):zx,T={runtime:e,symbols:t,getFunction:a,ast:o,evaluations:l,executions:u,bindings:d,referencesAbsolute:y,referencesExecute:b,referencesRelative:_,referencesRoot:x,referenceIndices:f.referenceIndices,formatReferenceIndices:ww(o,a),getTokens:()=>C??=mw(o,r,w),namedIds:Cw(o),symbolIds:jw(o),hasTotals:Ew(o,a),hasVolatile:Dw(o,a),...kw(o,a),isReferenceOnly:!m,error:i,transform:n=>{let s=AS(o,n);return s===o?T:Vw(e,t,s,r,i,a)}};return T}function Hw(e){let n=-1,r=-1;return Number.isSafeInteger(e.previousToken?.startLine)?(n=e.previousToken.startLine,r=e.previousToken.endColumn+1):Number.isSafeInteger(e.token?.startLine)&&(n=e.token.startLine,r=e.token.startColumn),n===-1?new t.FormulaError.Parse(e.message,{cause:e}):(e.errorLocation={line:n,column:r},new t.FormulaError.Parse(e.message,{line:n,column:r,cause:e}))}Object.freeze([[`:`,`.:.`,`.:`,`:.`],[`^`],[`*`,`/`],[`+`,`-`],[`&`],[`<`,`>`,`=`,`<>`,`<=`,`>=`]]);var Uw=Object.freeze([`:`,`.:.`,`.:`,`:.`]),Ww=Object.freeze([`:`,` `,`.:.`,`.:`,`:.`]),Gw=Object.freeze([`@`]),Kw=Object.freeze([`#`]),qw=Object.freeze(Ww.concat(Kw)),Jw=(Object.freeze(Ww.concat(Gw).concat(Kw)),e=>{if(!e)return!1;let t=e.type;if(t===Z.Cell||t===Z.TableReference)return!0;if(t===Z.Infix){if(!Ww.includes(e.value))return!1;let t=e.inputs,n=t[0],r=t[1];return Jw(n)&&Jw(r)}return t===Z.List&&(e.inputs?.every(Jw)??!1)}),Yw=e=>!!e&&(!(e.type!==Z.Infix||!qw.includes(e.value))||!(e.type!==Z.Postfix||!Kw.includes(e.value))||e.type===Z.Array||e.type===Z.TableReference),Xw=Object.freeze([`+`,`-`,`*`,`/`,`^`,`&`,`=`,`<>`,`>`,`<`,`>=`,`<=`]),Zw=Object.freeze([`-`,`+`]),Qw=(e,t)=>{if(!e)return!1;let n=e.type;if(e.isLiteral)return n!==Z.Error;if(n===Z.Paren||n===Z.List){let n=e.inputs;return!(!n||n.length===0)&&n.every(e=>Qw(e,t))}if(n===Z.Infix)return Xw.includes(e.value);if(n===Z.Prefix)return Zw.includes(e.value);if(n===Z.Postfix)return e.value===`%`;if(n===Z.Function){if(!t)return!1;let n=t(e.value);if(!n)return!1;let r=n.getDeclaration().getReturnType(),i=r.getRangeType();return i!==`p`&&(i!==null||r.getLambda()===null&&r.getScalarType()!=null)}return!1},$w=(e,t)=>{if(!e)return null;let n=null,r=e=>{if(n||!e)return;if(e.type===Z.Infix&&e.value===` `){let r=e.inputs,i=r?.[0],a=r?.[1];if(Qw(i,t))return void(n=i);if(Qw(a,t))return void(n=a)}let i=e.inputs;if(i)for(let e=0;e<i.length&&!n;e++)r(i[e])};return r(e),n},eT=(e,t)=>{if(!e)return null;let n=null,r=e=>{if(n||!e)return;if(e.type===Z.Postfix&&e.value===`#`){let r=e.inputs?.[0];if(r&&Qw(r,t))return void(n=r)}let i=e.inputs;if(i)for(let e=0;e<i.length&&!n;e++)r(i[e])};return r(e),n},tT=e=>{for(let t=0;t<e.length;t++)if(e[t].getRepeatingTypes())return t;return-1},nT=(e,t,n)=>{let r=e[t].getRepeatingTypes(),i=r.length,a=t,o=e.length-t-1,s=o;for(;s>0&&e[t+s].isOptional();)s--;let c=+!e[t].isOptional(),l=r[i-1].isOptional();for(let e=s;e<=o;e++){let t=n-a-e;if(t>=0&&t%i===0&&t/i>=c)return{n:t/i,short:!1,variable:t,period:i,prefix:a,suffix:e};if(l&&t===i-1)return{n:1,short:!0,variable:t,period:i,prefix:a,suffix:e}}return null},rT=e=>{if(!e)return null;let t=null,n=e=>{if(t||!e)return;if(e.type===Z.Array&&Array.isArray(e.value)){let n=e.value,r=n[0]?.value?.length??0;for(let e=1;e<n.length&&!t;e++){let i=n[e]?.value?.length??0;i!==r&&(t=`Array rows must all be the same length — row ${e+1} has ${i} value${i===1?``:`s`}, but row 1 has ${r}.`)}}let r=e.inputs;if(r)for(let e=0;e<r.length&&!t;e++)n(r[e])};return n(e),t},iT=(e,t)=>{if(!e||!t)return null;let n=null,r=e=>{if(n||!e)return;if(e.type===Z.Function){let r=e.value,i=t(r);if(i){let t=i.getDeclaration(),a=t.getParameters(),o=e.inputs?.length??0,s=t.getMaxArguments();if(o>s)return void(n=`Too many arguments for ${r}. The most it accepts is ${s}, but got ${o}.`);let c=a.length>0?tT(a):-1,l=a.length>0&&a[a.length-1].isRest();if(c>=0){if(!nT(a,c,o)){let e=a[c].getRepeatingTypes().length,t=a.length-1;n=e===1?`Too few arguments for ${r}. Expected at least ${t+1}, but got ${o}.`:`Wrong number of arguments for ${r}. Expected ${t} plus a multiple of ${e}, but got ${o}.`}}else if(!l&&o>a.length)n=`Too many arguments for ${r}. Expected ${a.length}, but got ${o}.`;else for(let e=o;e<a.length&&!n;e++){let t=a[e];t.isOptional()||t.isRest()||(n=`Parameter ${t.getName()} is missing for ${r}.`)}}}let i=e.inputs;if(i)for(let e=0;e<i.length&&!n;e++)r(i[e])};return r(e),n},aT=(e,t)=>{if(!e||!t)return null;let n=null,r=e=>{if(n||!e)return;if(e.type===Z.Function){let r=t(e.value);if(r){let i=r.getDeclaration().getParameters(),a=e.inputs;if(i.length>0&&a){let e=((e,t)=>{let n=Array(t),r=e.length,i=r>0?tT(e):-1;if(i<0){let i=r>0?e[r-1]:null,a=!!i&&i.isRest();for(let o=0;o<t;o++)n[o]=o<r?e[o]:a?i:null;return n}let a=e[i].getRepeatingTypes(),o=a.length,s=i,c=nT(e,i,t),l=c?c.suffix:r-i-1,u=Math.max(0,t-s-l);for(let c=0;c<t;c++)if(c<s)n[c]=e[c];else if(c<s+u)n[c]=a[(c-s)%o];else{let t=i+1+(c-s-u);n[c]=t<r?e[t]:null}return n})(i,a.length);for(let r=0;r<a.length&&!n;r++){let i=e[r];i&&i.getRangeType()===`p`&&Qw(a[r],t)&&(n=a[r])}}}}let i=e.inputs;if(i)for(let e=0;e<i.length&&!n;e++)r(i[e])};return r(e),n},oT=(e,t)=>{if(!e)return null;let n=null,r=e=>{if(n||!e)return;if(e.type===Z.Call){let r=e.inputs?.[0];if(r&&Qw(r,t))return void(n=`This expression always produces a value, so it cannot be called as a function.`)}let i=e.inputs;if(i)for(let e=0;e<i.length&&!n;e++)r(i[e])};return r(e),n},sT=(e,t)=>{if(e.type!==Z.Function)return;let n=e.value;if(typeof n!=`string`)return;let r=(t?.(n)?.getName()??n).toUpperCase();return r===`LET`?`let`:r===`LAMBDA`?`lambda`:void 0},cT=e=>{if(e?.type!==Z.Named)return;let t=e.value;return t?.nameId&&!t.scope&&!0!==t.optional?t.nameId:void 0},lT=/^[A-Za-z_\\][A-Za-z0-9_\\]*$/,uT=new Set([`TRUE`,`FALSE`]),dT=e=>{if(e?.type===Z.Named){let t=e.value;return!0!==t?.optional||!t.nameId||t.scope?void 0:t.nameId}if(e?.type!==Z.TableReference)return;let t=e.value,n;if(t===null||typeof t==`string`){if(t)return;let r=e.inputs;if(!r||r.length!==1||r[0]?.type!==Z.TableColumn)return;let i=r[0].value;if(typeof i!=`string`)return;n=i}else{let e=t;if(!e||e.tableId!==``||e.spec!==0||!0===e.isThisRow||!e.columnFromId||e.columnFromId!==e.columnToId)return;n=e.columnFromId}return lT.test(n)&&!uT.has(n.toUpperCase())&&e.image===`[${n}]`?n:void 0},fT=e=>{let t=vS(e.image??e.value);t.image=e.image??e.value,t.wsBefore=e.wsBefore;let n={type:Z.Call,value:null,inputs:[t,...e.inputs??[]],wsAfter:e.wsAfter};return e.error&&(n.error=e.error),n};function pT(e,t){return e&&t?AS(e,e=>{if(e.type===Z.Function&&typeof e.value==`string`&&!t(e.value))return fT(e)}):e}function mT(e,t){let n=t.name.toUpperCase(),r=e?e.filter(e=>e.name.toUpperCase()!==n):[];return r.push(t),r}function hT(e){if(e?.type!==Z.Function||e.binder?.kind!==`lambda`)return;let t=e.inputs??[],n=[];for(let e=0;e<t.length-1;e++){let r=t[e];if(!r?.binding?.declaration)return;let i=r.value.nameId;n.push(r.binding.optional?{name:i,optional:!0}:{name:i})}return n}function gT(e,t=null){if(!e)return e;let n=[],r=0,i=e=>{let t=e.inputs;if(!t)return e;let n;for(let e=0;e<t.length;e++){let r=t[e];if(!r)continue;let i=a(r);i!==r&&(n||=[...t],n[e]=i)}return n?{...e,inputs:n}:e},a=e=>{if(!e)return e;let o=sT(e,t);if(o)return((e,t)=>{let o=e.inputs,s=o?.length??0;if(!o||s<1)return i(e);let c=n.length,l=[],u=[...o],d=(e,t=!1)=>{let i=u[e],a=cT(i),o=!1;if(a===void 0&&t){if(a=dT(i),a===void 0)return;o=!0}else if(a===void 0)return;let s=r++;n.push({key:a.toUpperCase(),slot:s,name:a}),l.push(s),u[e]=o?{...i,type:Z.Named,value:{nameId:a,scope:null},inputs:null,binding:{slot:s,declaration:!0,optional:!0},isReference:!1}:{...i,binding:{slot:s,declaration:!0},isReference:!1}};if(t===`lambda`){for(let e=0;e<s-1;e++)d(e,!0);u[s-1]&&(u[s-1]=a(u[s-1]))}else{for(let e=0;e+1<s;e+=2)u[e+1]&&(u[e+1]=a(u[e+1])),d(e);s%2==1&&u[s-1]&&(u[s-1]=a(u[s-1]))}for(;n.length>c;)n.pop();return{...e,inputs:u,binder:{kind:t,slots:l}}})(e,o);if(e.type===Z.Function&&typeof e.value==`string`){let r=e.value.toUpperCase();if(n.some(e=>e.key===r)&&!t?.(e.value))return i(fT(e))}if(n.length>0&&e.isReference&&e.value===`:`&&e.inputs?.length===2){let[t,r]=e.inputs;if(vT(t)&&vT(r)){let a=t.image.toUpperCase(),o=r.image.toUpperCase();if(n.some(e=>e.key===a||e.key===o))return i({...e,inputs:[yT(t),yT(r)]})}}if(e.type===Z.Named){let t=cT(e);if(t!==void 0){let r=t.toUpperCase();for(let i=n.length-1;i>=0;i--){if(n[i].key!==r)continue;let a={...e,binding:{slot:n[i].slot},isReference:!1};return t!==n[i].name&&(a.value={...e.value,nameId:n[i].name}),a}}return e}let s=i(e);if(s.type===Z.Function&&typeof s.value==`string`&&(t?.(s.value)?.getName()??s.value).toUpperCase()===`ISOMITTED`){let e=s.inputs;if(e){let t;for(let n=0;n<e.length;n++){let r=e[n];r?.binding&&!r.binding.declaration&&!0!==r.rawFrameRead&&((t??=[...e])[n]={...r,rawFrameRead:!0})}if(t)return{...s,inputs:t}}}return s};return a(e)}var _T,vT=e=>{if(e?.type!==Z.Cell||e.image===void 0)return!1;let t=e.value;return t.rowIndex===-(2**53-1)&&!0!==t.$colIndex&&!t.scope},yT=e=>{let t=vS(e.image);return jS(t,e),t},bT=e=>e?.type===Z.Cell,xT=(e,t=null)=>{if(!e)return e;let n=!1,r=e=>{if(n||!e)return;let i=sT(e,t),a=e.inputs;if(i&&a){let e=i===`let`?2:1;for(let t=0;t<a.length-1;t+=e)if(bT(a[t]))return void(n=!0)}if(a)for(let e=0;e<a.length&&!n;e++)r(a[e])};if(r(e),!n)return e;let i=null,a=AS(e,e=>{if(e?.type!==Z.Cell)return;let t=e.value,n=e.image;if(!0===t?.$colIndex||!0===t?.$rowIndex)return void(i??=`'${n??`a reference`}' cannot be absolute here. A LET/LAMBDA name that is a cell reference makes every reference in the formula a name, and a name cannot contain '$'.`);if(n===void 0)return;let r=vS(n);jS(r,e);let a=t?.scope;return a&&(r.value.scope=a,r.value.scopeImage=t.scopeImage),r});return i??a},ST=(e,t)=>{if(!e)return null;let n=null,r=e=>{if(n||!e)return;let i=sT(e,t);i&&((e,t)=>{let r=t===`let`?`LET`:`LAMBDA`,i=e.inputs,a=i?.length??0;if(!i||a<2)return;if(t===`let`&&a%2==0)return void(n=`Wrong number of arguments for LET. Expected name/value pairs followed by a calculation, but got ${a}.`);if(t===`lambda`&&i[a-1]?.type===Z.Empty)return void(n=`LAMBDA has no calculation: the last argument is empty.`);let o=new Set,s=t===`let`?2:1,c=!1;for(let e=0;e<a-1;e+=s){let a=cT(i[e]);if(a===void 0&&t===`lambda`)a=dT(i[e]),a!==void 0&&(c=!0);else if(a!==void 0&&c)return void(n=`Required name '${a}' cannot follow an optional name in ${r}.`);if(a===void 0)return void(n=`Expected a name in ${r} argument ${e+1}; a name cannot be the output of a formula.`);if(a.includes(`.`))return void(n=`Expected a name in ${r} argument ${e+1}; a name cannot contain '.'.`);let s=a.toUpperCase();if(o.has(s))return void(n=`Duplicate name '${a}' in ${r}.`);o.add(s)}})(e,i);let a=e.inputs;if(a)for(let e=0;e<a.length&&!n;e++)r(a[e])};return r(e),n};function CT(e,t,n,r,i){let a=r,o,s=()=>(o===void 0&&(o=i&&n?t.bind($.Table,``,{at:{scope:n,rowIndex:i.rowIndex,colIndex:i.colIndex}}):null),o);return AS(e,(e,r,i=[])=>{let o,c=e.type;if(c===Z.Cell){let n=e.value;if(n?.scope){let r=t.bind($.Sheet,n.scope,a);r!==null&&(o||={...e},o.value={...n,scope:r})}}else if(c===Z.Named){let r=e.value;if(r&&!e.binding){let i=function(e,t,n,r){if(t.scope){let e=n.bind($.Sheet,t.scope,r);if(e===null||sC(e))return}let i=n.bind($.Table,t.nameId,{existing:!0});if(i===null)return;let a={type:Z.TableReference,value:i,inputs:null,isReference:!0};jS(a,e);let o=t.scopeImage;return typeof o==`string`&&e.image!==void 0&&(a.image=o+e.image),a}(e,r,t,a);if(i)return i;let s=r.scope?t.bind($.Sheet,r.scope,a):null,c=(s===null?r.scope:sC(s)?s:t.resolve($.Sheet,s)?.toString()??r.scope)??n,l=t.bind($.NamedFormula,r.nameId,c?{scope:c}:void 0);l===null&&s===null||(o||={...e},o.value={...r,nameId:l??r.nameId,...s===null?void 0:{scope:s}})}}else if(c===Z.Error){let n=e.value;if(n?.scope){let r=t.bind($.Sheet,n.scope,a);r!==null&&(o||={...e},o.value={...n,scope:r})}}else if(c===Z.TableReference){let n=e.value;if(n){let r=t.bind($.Table,n);o||={...e},r!==null&&(o.value=r)}else if(typeof n==`string`){let n=s();if(n!==null&&wT(e,t))return{...e,value:n}}}else if(c===Z.TableColumn){let n=e.value;if(n){let r=fw(i,Z.TableReference),a=r?.value||(r?s()??void 0:void 0),c=t.bind($.TableColumn,n,a?{tableName:a}:void 0);o||={...e},c!==null&&(o.value=c)}}else if(c===Z.Function){let n=e.value;if(n){let r=t.bind($.Function,n);o||={...e},r!==null&&(o.value=r)}}return o})}function wT(e,t){let n=!0,r=e.inputs;if(!r)return!0;for(let e=0;e<r.length&&n;e++)AS(r[e],e=>{e.type===Z.TableColumn&&t.resolve($.TableColumn,e.value)===null&&(n=!1)});return n}function TT(e,t){let n=null;return AS(e,e=>{if(n||e.type!==Z.TableReference)return;if(e.value===``)return void(n=`A structured reference without a table name must be in a table that has its columns.`);let r=e.value;if(!t||typeof r!=`string`)return;let i=t.resolve($.Table,r)?.toString()??r;t.bind($.Table,i,{existing:!0})===null?n=`There is no table named '${i}'.`:wT(e,t)||(n=`The table has no such column.`)}),n}function ET(e,t,n){let r=[...e];for(let e=0;e<r.length;e++){let i=r[e];i?.colStart!==void 0&&(r[e]=Bd(i,t,n))}return r}function DT(e,t,n=!1,r=!1,i){if(!t)return e;let a,o=()=>(a===void 0&&(a=r&&i?.scope?t.bind($.Table,``,{at:i}):null),a),s=n?{canonical:!0}:void 0,c=e.length,l=[],u=r?{display:!0}:void 0,d=(e,t,n,i)=>{let a=ud(n);if(r&&sC(t)){let t=a.indexOf(`]`,a.lastIndexOf(`[`));if(t!==-1)return l.push({...e,type:Z.ExternalReference,value:n,text:a.substring(0,t+1)}),void l.push({...e,text:a.substring(t+1)+`!`+i})}l.push({...e,text:a+`!`+i})};for(let n=0;n<c;n++){let r=e[n],a=r.type;if(a===Z.Cell){let e=r.value;if(e?.scope){let n=t.resolve($.Sheet,e.scope,u)?.toString()??e.scope,i={...r,value:{...e,scope:n}};r.text===void 0||r.text.includes(`!`)?l.push(i):d(i,e.scope,n,r.text);continue}l.push(r)}else if(a===Z.Named){let e=r.value,n=e.name,i=t.resolve($.NamedFormula,n)?.toString()??n,a=e.scope;if(a){let n=t.resolve($.Sheet,a,u)?.toString()??a,o={...r,value:{...e,name:i,scope:n}};r.text===void 0||r.text.includes(`!`)?l.push(o):d(o,a,n,r.text)}else l.push(i===n?r:{...r,value:{...e,name:i}})}else if(a===Z.Error){let e=r.value,n=e?.scope;if(n){let i=t.resolve($.Sheet,n,u)?.toString()??n,a={...r,value:{...e,scope:i}};r.text===void 0||OS(r.text)?l.push(a):d(a,n,i,r.text)}else l.push(r)}else if(a===Z.TableReference){let a=r.value;if(i&&a&&a===o()&&OT(e,n+1,a))continue;let s=t.resolve($.Table,a)?.toString()??a,c=r.text===a?s:r.text;l.push(s===a?r:{...r,value:s,text:c})}else if(a===Z.TableColumn||a===Z.TableSpecifier){let e=r.value;if(!e||typeof e!=`object`){l.push(r);continue}let n=e.table?t.resolve($.Table,e.table)?.toString()??e.table:``,i=a===Z.TableColumn?t.resolve($.TableColumn,e.name)?.toString()??e.name:e.name;l.push(n!==e.table||i!==e.name?{...r,value:{...e,table:n,name:i},text:r.text??i}:r)}else if(a===Z.Function){let e=r.value,n=t.resolve($.Function,e,s)?.toString()??t.resolve($.NamedFormula,e)?.toString()??e;l.push(n===e?r:{...r,value:n})}else l.push(r)}return function(e,t,n){let r,i=e.length;for(let a=0;a<i;a++){let i=e[a],o=i.context;if(!o)continue;r??=new Map;let s=r.get(o);if(s===void 0){let e=o.type===`table`?$.Table:$.Function,i=t.resolve(e,o.name,n)?.toString()??(e===$.Function?t.resolve($.NamedFormula,o.name)?.toString():void 0)??o.name;s=i===o.name?o:{...o,name:i},r.set(o,s)}s!==o&&(e[a]={...i,context:s})}return e}(l,t,s)}function OT(e,t,n){let r=0;for(let i=t;i<e.length;i++){let t=e[i],a=t.context;if(a?.type!==`table`||a.name!==n)break;let o=t.type;if(o===Z.TableColumn)r++;else if(o!==Z.Paren&&o!==Z.Prefix&&o!==Z.Whitespace)return!1}return r===1}function kT(e,t,n=!1,r=0,i=0,a=Ux){let o=``,s=zd,c=Rd,l=a.separators,u=e.length;for(let d=0;d<u;d++){let u=e[d],f=u.type;if(f===Z.Cell){let a=u.value;if(!n&&u.refSide===`left`&&!a.scope){let n=e[d+1],s=e[d+2];if(n&&n.value===`:`&&s&&s.type===Z.Cell&&s.referenceIndex===u.referenceIndex){let e=s.value,n=pd(Bd({colStart:a.colIndex,rowStart:a.rowIndex,colEnd:e.colIndex,rowEnd:e.rowIndex,$colStart:a.$colIndex,$rowStart:a.$rowIndex,$colEnd:e.$colIndex,$rowEnd:e.$rowIndex},r,i),t);if(n!==null){o+=n,d+=2;continue}}}let l=a.colIndex;if(!a.$colIndex&&l!==-(2**53-1)&&l!==2**53-1&&!n){let e=l+i;if(e<0||!a.scope&&t&&(e<t.colStart||e>t.colEnd)){o+=`#REF!`;continue}}let f=a.rowIndex;if(!a.$rowIndex&&f!==-(2**53-1)&&f!==2**53-1&&!n){let e=f+r;if(e<0||!a.scope&&t&&(e<t.rowStart||e>t.rowEnd)){o+=`#REF!`;continue}}o+=n?c(a):s(a,r,i)}else if(f===Z.Named||f===Z.Parameter){let e=u.value;e.scope&&(o+=ud(e.scope)+`!`),o+=e.optional?`[${e.name}]`:e.name}else if(f===Z.TableReference)o+=u.value;else if(f===Z.TableColumn)o+=fS(u.value.name);else if(f===Z.TableSpecifier)o+=PT(u.value.name,a);else if(f===Z.Empty)o+=``;else if(f===Z.Boolean)o+=a.localizeBoolean(u.value);else if(f===Z.Function)o+=u.value;else if(f===Z.Separator)o+=u.value===`;`?l.separatorRow:l.separatorFunction;else if(f===Z.Number){let e=String(u.value);o+=l.separatorDecimal===`.`?e:e.replace(`.`,l.separatorDecimal)}else if(f===Z.Error){let e=u.value;e?.scope&&(o+=ud(e.scope)+`!`);let t=DS(u.value);o+=t?a.localizeError(t):String(e?.error??u.value)}else f===Z.ExternalReference||(o+=u.value)}return o}function AT(e,t,n=Ux){return kT(e,t,!0,0,0,n)}function jT(e,t,n=0,r=0,i=Ux){return kT(e,t,!1,n,r,i)}function MT(e,t){let n=e.lastIndexOf(`!`)+1,r=e.endsWith(`#`),i=r?e.length-1:e.length,a=e.substring(n,i);if(!t.$colIndex&&t.colIndex!==-(2**53-1)&&t.colIndex<0||!t.$rowIndex&&t.rowIndex!==-(2**53-1)&&t.rowIndex<0)return`#REF!`;let o=zd({...t,scope:null},0,0);return o.toUpperCase()===a.toUpperCase()?e:e.substring(0,n)+o+(r?`#`:``)}function NT(e,t=0,n=0){let r=e.length,i=[];for(let a=0;a<r;a++){let r=e[a];if(r.type!==`cell`){i[a]=r;continue}let o={...r},s={...o.value};o.value=s,i[a]=o;let c=!1;s.colIndex===-(2**53-1)||s.$colIndex||(s.colIndex+=n,c||=n!==0),s.rowIndex===-(2**53-1)||s.$rowIndex||(s.rowIndex+=t,c||=t!==0),c&&o.text!==void 0&&(o.text=MT(o.text,s))}return i}function PT(e,t){if(!t.localizeSpecifier)return e;let n=e.startsWith(`[`)&&e.endsWith(`]`),r=n?e.slice(1,-1):e;if(!r.startsWith(`#`))return e;let i=`#`+t.localizeSpecifier(r.slice(1));return n?`[${i}]`:i}var FT={FormulaContext:_T,ScalarType:t.ScalarType,IRange:t.IRange,FormulaError:t.FormulaError,Observable:t.Observable,checkRun:a.RunGuard.check},IT=()=>(_T||(_T=t.FormulaContext,FT.FormulaContext=_T),_T),LT=[];function RT(e){LT.push(e),IT()._setScope(e)}function zT(){LT.length>0&<.pop();let e=LT.length;IT()._setScope(e>0?LT[e-1]??null:null)}var BT,VT=class{constructor(){this.isCalcSignal=!0}},HT=e=>!0===e?.isCalcSignal,UT=class e{constructor(){this.isLazy=!0,this._value=void 0,this._forced=!1,this._owner=null,this._node=null,this._regs=null,this._frame=null,this._row=-1,this._col=-1}static{this._pool=[]}static{this._depth=0}static enter(){return e._depth++}static leave(t){e._depth=t}static deferred(t,n,r,i,a,o,s,c){let l=e._pool,u=l[t];u===void 0&&(u=l[t]=[]);let d=u[n];return d===void 0&&(d=u[n]=new e),d._owner=r,d._node=i,d._regs=a,d._frame=o,d._row=s,d._col=c,d._forced=!1,d._value=void 0,d}static of(t){let n=new e;return n._value=t,n._forced=!0,n}_fill(e){this._value=e,this._forced=!0}_force(){return this._forced||(this._forced=!0,this._value=this._owner._valueOfLazy(this._node,this._regs,this._frame,this._row,this._col)),this._value}getValue(){let e=this._force();return e&&typeof e.then==`function`?t.FormulaError.BuiltIn.Value:e}get[Symbol.toStringTag](){return`[LazyValue(${this._forced?`filled`:`deferred`})]`}};(BT||={}).Context={Workbook:`workbook`,Sheet:`sheet`,Ranges:`ranges`,Range:`range`,Script:`script`,Calculation:`calculation`};var WT=class e{constructor(){this._params=null,this._args=GT,this._start=0,this._end=0,this._variadic=-1,this._suffix=0,this._period=1,this._values=null,this._child=null}_bind(e,t,n,r,i){this._params=e??null,this._args=r,this._start=0,this._end=i,this._variadic=t,this._suffix=n,this._period=1,this._values=null}_bindNested(e,t,n,r,i){this._params=e,this._args=t,this._start=n,this._end=r,this._variadic=-1,this._suffix=0,this._period=e.length||1,this._values=i}_setLiftValues(e){this._values=e}_setPrivateArgs(e){this._args=e}_groupEnd(){return this._end-this._suffix}_paramAt(e){let t=this._params;return t?this._period>1?t[e%this._period]??null:t[e]??null:null}_argAt(e){if(e<0)return-1;let t=this._variadic,n;return n=t<0||e<t?this._start+e:e===t?this._start+t:this._groupEnd()+(e-t-1),n>=this._start&&n<this._end?n:-1}_valueAt(e){let t=this._values;return t!==null&&e<t.length?t[e]:this._args[e]}getLength(){let e=this._end-this._start,t=this._variadic;return t<0||e<=t?e:t+ +(this._groupEnd()-this._start-t>0)+this._suffix}getRawAt(e){if(e===this._variadic){let t=this._start+e,n=this._groupEnd(),r=[];for(let e=t;e<n;e++)r.push(qT(this._valueAt(e)));return r}let t=this._argAt(e);if(!(t<0))return qT(this._valueAt(t))}getRepeatingArgsAt(t){if(t!==this._variadic||!this._params)return KT;let n=this._params[t],r=n.repeating??[n],i=this._child??=new e;return i._bindNested(r,this._args,this._start+t,this._groupEnd(),this._values),i}getKindAt(e){let n=this._argAt(e);return n<0||this._args[n]===void 0?t.ValueKind.Omitted:JT(this._valueAt(n))}getAreaCountAt(e){let n=this._argAt(e);if(n<0)return 0;let r=this._valueAt(n);return JH(r)?r.length:+(JT(r)===t.ValueKind.Reference)}isDirectAt(e){let n=this.getKindAt(e);return n!==t.ValueKind.Reference&&n!==t.ValueKind.Array&&n!==t.ValueKind.Lambda&&n!==t.ValueKind.Omitted}},GT=[],KT=new WT,qT=e=>{if(e!==void 0){if(typeof e==`object`&&e&&!0!==e.isIRange&&e.colStart!==void 0)return t.FormulaContext.getReference(e);if(JH(e)){let t=e.map(qT);return e.isSheetSpan&&(t.isSheetSpan=!0),t}if(!0===e?.isIRange&&!0===e._isDirectScalarBox?.())return e.getValueAt(0,0);if(typeof e!=`symbol`)return e}},JT=e=>{if(e===void 0)return t.ValueKind.Omitted;if(e===null)return t.ValueKind.Null;let n=typeof e;return n===`number`?t.ValueKind.Number:n===`string`?t.ValueKind.String:n===`boolean`?t.ValueKind.Boolean:n===`symbol`?t.ValueKind.Omitted:n===`function`||VC(e)?t.ValueKind.Lambda:t.FormulaError.isError(e)?t.ValueKind.Error:!0===e.isIRange?!0===e.isIReferenceRange?t.ValueKind.Reference:!0===e._isDirectScalarBox?.()?JT(e.getValueAt(0,0)):t.ValueKind.Array:e.colStart===void 0?Array.isArray(e)?JH(e)?t.ValueKind.Reference:t.ValueKind.Array:t.ValueKind.RichData:t.ValueKind.Reference},YT=[],XT=0;t.FormulaContext._setArgsProvider(()=>XT>0?YT[XT-1]:null);var ZT=(e,n)=>e.acceptError?`accept`:n===t.ScalarType.Error?null:`reject`,QT=(e,n,r,i)=>{if(r&&i!==0)for(let a=0;a<n;a++){if(!0!==r[a<i?a:i-1]?.lazy)continue;let n=e[a];(0,t.isLazyValue)(n)||(e[a]=UT.of(n))}},$T=e=>{let n=e.checkArity,r=typeof n==`function`,i=(...i)=>{if(r&&!n(i.length))throw t.FormulaError.BuiltIn.Value;return(e=>{let n=e;if(Array.isArray(n)){if(n.length!==1)throw t.FormulaError.BuiltIn.Calc;n=n[0]}if(!0===n?.isIRange){if(n.size!==1)throw t.FormulaError.BuiltIn.Calc;n=n.getValueAt(0,0)}else if(n!==null&&n?.colStart!==void 0){let e=n;if(e.rowStart!==e.rowEnd||e.colStart!==e.colEnd)throw t.FormulaError.BuiltIn.Calc;try{n=t.FormulaContext.getValueAt(e.rowStart,e.colStart,e.scope??void 0)}catch(e){if(!t.FormulaError.isError(e))throw e;n=e}}return VC(n)?t.FormulaError.BuiltIn.Calc:n??null})(e(...i))};return i.isLambdaCallable=e.isLambdaCallable,i.checkArity=n,i.paramCount=e.paramCount,i},eE=Symbol(`enumRefused`),tE=e=>{if(e.type===t.ScalarType.String){let t=new Map;for(let[,n]of e.members)t.set(n.toLowerCase(),n);return{numbers:null,strings:t}}let n=new Set;for(let[,t]of e.members)n.add(t);return{numbers:n,strings:null}},nE=(e,n)=>typeof n==`number`?e.numbers?.has(n)?n:eE:typeof n==`string`?e.strings?.get(n.toLowerCase())??eE:n===void 0||t.FormulaError.isError(n)?n:eE,rE=e=>{let n=e?.length??0,r=Array(n);for(let i=0;i<n;i++){let n=e[i],a=n.scalar??null;a!==t.ScalarType.Null&&a!==`*`||(a=null);let o=n.range===`*`,s=o?`r`:n.range??null,c=n.rest??!1,l=n.lambda!=null,u=!0===n.lazy,d=(n.arrayDepth??0)>0,f=!0===n.acceptError,p=ZT(n,a),m=(a===null||a===t.ScalarType.Error||p===`accept`)&&p!==`reject`,h=!(c||n.range||l||d),g=!n.enum||!0===n.reportType||n.scalar===`*`||n.range&&!0!==n.valueOrRange?null:tE(n.enum);r[i]={scalarType:a,isAny:o,rangeType:s,rest:c,optional:n.optional??!1,isLambda:l,lazy:u,flatten:d,liftTrigger:h,acceptError:f,policy:p,allowError:m,valueOrRange:!0===n.valueOrRange,reportType:!0===n.reportType,wholeReference:h&&!0===n.noLift&&!0===n.reportType,enumGate:g,simple:h&&g===null}}return r},iE=class e{constructor(e,n,r,i=null,a=!1){this._ct=BT.Context.Calculation,this._builtIn=!1,this._lc=!1,this._rlc=!1,this._nl=!1,this._lz=!1,this._nmf=!1,this._rs=null,this._rref=!0,this._rkScalar=!1,this._pj=null,this._gi=-1,this._va=-1,this._gc=null,this._mx=mE,this._json=e,this._n=e.name,this._d=new hE(e),this._mx=this._d.getMaxArguments(),this._ct=e.context??BT.Context.Calculation;let o=e.parameters,s;this._pj=o,this._ps=rE(o),n||=(console.log(`TypeFunction '${e.name}' was not provided a function implementation.`),()=>{}),this._fn=n.bind(this),this._cf=r??oE,this._builtIn=a,this._cfp={argsValues:null,argsLength:0},s=i?typeof i==`function`?i:()=>Promise.resolve(i):aE(e),this._descFn=s;let c=o?.length??0,l=!1,u=!1,d=(e,t)=>{let n=e.repeating;if(n){let e=n.length===1;for(let t=0;t<n.length;t++)d(n[t],e);return}t||e.range||e.lambda!=null||(e.arrayDepth??0)!==0||(l=!0),e.range===`p`&&(u=!0)};for(let e=0;e<c;e++){let t=o[e];t.repeating&&(this._gi=e),d(t,t.rest??!1)}this._lc=l,this._rlc=u;let f=this._gi;f<0&&c>0&&o[c-1].rest&&(f=c-1),this._va=f,this._nl=!0===e.parameters?.some(e=>!0===e.noLift),this._nmf=!0===e.parameters?.some(e=>!0===e.noFilter||!0===e.repeating?.some(e=>!0===e.noFilter)),this._lz=!0===e.parameters?.some(e=>!0===e.lazy||e.repeating?.some(e=>!0===e.lazy));let p=e.returnType?.scalar;p!==t.ScalarType.Null&&p!==`*`||(p=null),this._rs=p??null;let m=e.returnType,h=fE(m);this._rref=!m||h===t.ValueKind.Reference,this._rkScalar=h!==null&&h!==t.ValueKind.Reference&&h!==t.ValueKind.Array&&h!==t.ValueKind.Lambda&&h!==t.ValueKind.Omitted}execute(...e){let t=e,n=t.length,r=this._cfp;if(r.argsLength>0)t=r.argsValues,n=r.argsLength,r.argsValues=null,r.argsLength=0;else for(let e=0;e<n;e++){let n=t[e];if(n==null)continue;let r;if(n.colStart!==void 0)r=n;else if(n.getCoords&&(r=n.getCoords(),r&&r.scope===void 0&&typeof n.getSheet==`function`)){let e=n.getSheet()?.getName?.();e&&(r={...r,scope:e})}r&&(t[e]=r)}let i=this._exec(t,n);if(!0===i?.isIRange){if(!0===i._isDirectScalarBox?.())return i.getValueAt(0,0);if(!this._rref&&!0===i.isIReferenceRange)return i.size===1?i.getValueAt(0,0):i._toValueRange()}return i}_plan(e){let t=this._gc;if(t){if(t.has(e))return t.get(e)}else t=this._gc=new Map;let n=this._pj,r=this._gi,i=n[r].repeating,a=i.length,o=r,s=n.length-r-1,c=s;for(;c>0&&!0===n[r+c].optional;)c--;let l=!0===i[a-1].optional,u=!0===n[r].optional?0:1,d=-1,f=!1,p=s;for(let t=c;t<=s;t++){let n=e-o-t,r=-1,i=!1;if(n>=0&&n%a===0?r=n/a:l&&n===a-1&&(r=1,i=!0),r>=u){d=r,f=i,p=t;break}}if(d<u)return t.set(e,null),null;let m=[];for(let e=0;e<o;e++)m.push(n[e]);if(a===1)m.push(i[0].rest?i[0]:{...i[0],rest:!0});else for(let e=0;e<d;e++){let t=f&&e===d-1?a-1:a;for(let e=0;e<t;e++)m.push(i[e])}for(let e=0;e<p;e++)m.push(n[r+1+e]);let h={params:m,specs:rE(m),prefix:o,period:a,n:d,short:f,tuples:a>1,suffix:p};return t.set(e,h),h}_regroup(e,t,n){let{prefix:r,period:i,n:a,short:o,tuples:s}=n,c=[],l=0;for(;l<r;l++)c.push(e[l]);if(s){let t=Array(a);for(let n=0;n<a;n++){let r=o&&n===a-1?i-1:i,s=Array(r);for(let t=0;t<r;t++)s[t]=e[l++];t[n]=s}c.push(t)}else{let i=t-(n.params.length-r-1),a=[];for(;l<i;)a.push(e[l++]);c.push(a)}for(;l<t;)c.push(e[l++]);return c}_gateDelivered(e,n,r){let i=e.enumGate,a=n.values;for(let o=r;o<n.length;o++){let n=a[o];if(typeof n==`object`&&n&&!0===n.isIRange)continue;let r=nE(i,n);if(r!==eE)a[o]=r;else{if(!e.allowError)return t.FormulaError.BuiltIn.Value;a[o]=t.FormulaError.BuiltIn.Value}}return null}_exec(e,r){if(r>this._mx)throw _E.ARGS_PAST_MAX(this._mx,r,this._n);let i=null;if(this._gi>=0&&(i=this._plan(r),!i)){let e=this._pj,t=e[this._gi].repeating;throw _E.ARGS_REPEAT(e.length-1,t.length,r,this._n)}let a=i?i.params:this._pj,o=i?i.specs:this._ps;vE.length=0;let s=vE,c=this._cf?.();RT(c);let l=c!=null&&!0===c._takeFirstCell?.(),u=null,d=null,f=-1,p=!1,m=a?.length??0,h=this._lc,g=!1,_=m>0&&o[m-1].rest;if(!i&&!_&&r>m)throw _E.ARGS_TOO_MANY(m,r,this._n);if(this._nl&&this._refusesReferenceLift(a,m,e,r,i))return zT(),t.FormulaError.BuiltIn.Value;if(this._rlc&&m>0){let t=null;for(let i=0;i<r;i++){if(a[i<m?i:m-1].range!==`p`)continue;let r=e[i],o=DE(r);if(o){(t??=[]).push({argIndex:i,collapsed:r,elements:o.elements,rows:o.rows,cols:o.cols});continue}let s=r;!0===s?.isIRange&&!s.isIReferenceRange&&s.size>1&&(t??=[]).push({argIndex:i,collapsed:s,elements:n.CommonUtils.EmptyArray,rows:s.getRowCount(),cols:s.getColumnCount()})}if(t)try{return this._refLift(c,e,r,t,l)}finally{zT()}}if(h){let t=!1,n=Math.min(r,m);for(let r=0;r<n;r++){if(!o[r].liftTrigger)continue;let n=e[r];if(typeof n==`object`&&n&&(!o[r].wholeReference||!bE(n))&&CE(n)){t=!0;break}}h=t}let v=((e,t,n,r,i)=>{let a=YT[XT];return a===void 0&&(a=YT[XT]=new WT),a._bind(e,t,n,r,i),XT++,a})(this._pj,this._va,i?i.suffix:0,e,r),y,b=!1;try{for(let n=0;!b&&n<m;n++){let i=a[n],l=o[n],m=l.scalarType,_=s.length,v=l.isAny,y=l.rangeType,x=l.rest,S=l.optional,C=e[n];C=c._expandSheetSpan?.(C)??C;let w=n>=r;if(C===void 0||w){if(w){if(!S&&!x)throw _E.PARAM_MISSING(i.name,this._n);if(l.lazy&&i.defaultValue!==void 0){s.values[s.length++]=UT.of(i.defaultValue);continue}b=!0;continue}if(i.omittable){s.values[s.length++]=i.omittedValue;continue}C=null}if(typeof C==`symbol`){s.values[s.length++]=void 0;continue}if(l.lazy&&!x&&(0,t.isLazyValue)(C)){s.values[s.length++]=C;continue}if(l.isLambda){let e=i.range!=null||i.scalar!=null&&i.scalar!==`l`,n=VC(C)||typeof C==`function`;if(!e||n){if(t.FormulaError.isError(C)){u=t.FormulaError.BuiltIn.Value,b=!0;continue}if(typeof C==`object`&&C&&!VC(C)&&!Array.isArray(C)){let e=C,n=C,r=0,i=0;if(!0===e.isIRange?(r=e.getRowCount(),i=e.getColumnCount()):n.colStart!==void 0&&(r=n.rowEnd-n.rowStart+1,i=n.colEnd-n.colStart+1),r*i>1)return c.createRange(r,i,t.FormulaError.BuiltIn.Value)}if(C!==null){let e=null;if(VC(C)?e=C.makeCallable():typeof C==`function`&&(e=C),e===null){u=t.FormulaError.BuiltIn.Value,b=!0;continue}let n=i.lambdaArity??(i.rest?r-1:null),a=e.checkArity;if(n!==null&&typeof a==`function`&&!a(n)){u=t.FormulaError.BuiltIn.Value,b=!0;continue}g=!0,s.values[s.length++]=i.lambda===`raw`?e:$T(e);continue}u=t.FormulaError.BuiltIn.Value,b=!0;continue}if(C!==null&&sE(C)&&(typeof C==`number`||typeof C==`string`||typeof C==`boolean`)){u=t.FormulaError.BuiltIn.Value,b=!0;continue}}if(l.wholeReference&&xE(C)){s.values[s.length++]=!0===C?.isIRange?C:c.getReference(C);continue}if(l.simple&&!h){let e=C,t=!0,n=!0;if(typeof e==`object`&&e){let r=e;r.colStart!==void 0&&r.colStart===r.colEnd&&r.rowStart===r.rowEnd?(e=c.getValueAt(r.rowStart,r.colStart,r.scope??void 0),t=!1):n=!1}if(n){u=QH(c,s,e,t,m,l.allowError,l.policy),b=!!u,b&&(p=!0);continue}}let T=sE(C),E=l.policy,D=l.allowError;if(VC(C)&&!l.isLambda&&!x){if(v||!i.range&&!m){s.values[s.length++]=C;continue}i.range&&(C=c.getRange(C,null,!0))}if(!x&&v&&this._rref&&JH(C))s.values[s.length++]=C;else{if(!x&&l.reportType&&JH(C)){let e=C.map(e=>!0===e?.isIRange?e:c.getReference(e));C.isSheetSpan&&(e.isSheetSpan=!0),s.values[s.length++]=e;continue}if(!x&&!l.flatten&&!l.isLambda&&!h&&JH(C)){if(!l.acceptError){u=t.FormulaError.BuiltIn.Value,b=!0;continue}C=t.FormulaError.BuiltIn.Value}if(!x&&l.flatten&&C?.isSheetSpan){if(!l.acceptError){u=t.FormulaError.BuiltIn.Value,b=!0;continue}C=t.FormulaError.BuiltIn.Value}if(!x&&l.valueOrRange&&C!==void 0){let e=C,n=!0,r=!0;if(typeof e==`object`&&e){let i=e;i.colStart!==void 0&&i.colStart===i.colEnd&&i.rowStart===i.rowEnd?(e=c.getValueAt(i.rowStart,i.colStart,i.scope??void 0),r=!1):n=t.FormulaError.isError(e)}if(n){let t=s.length;u=QH(c,s,e,r,l.scalarType,l.allowError,l.policy),!u&&l.enumGate&&(u=this._gateDelivered(l,s,t)),b=!!u,b&&(p=!0);continue}}if(x)for(;n<r&&!u;){if(C===void 0&&(C=null),VC(C)&&(l.isLambda?n<r-1:!v&&i.range!=null)&&(C=c.getRange(C,null,!0)),l.isLambda&&(VC(C)||typeof C==`function`)){let e=typeof C==`function`?C:VC(C)?C.makeCallable():null;if(e===null)u=t.FormulaError.BuiltIn.Value;else{let n=i.lambdaArity??r-1,a=e.checkArity;typeof a!=`function`||a(n)?(g=!0,s.values[s.length++]=i.lambda===`raw`?e:$T(e)):u=t.FormulaError.BuiltIn.Value}}else l.isLambda&&C!==null&&sE(C)&&(typeof C==`number`||typeof C==`string`||typeof C==`boolean`)?u=t.FormulaError.BuiltIn.Value:l.lazy&&(0,t.isLazyValue)(C)?s.values[s.length++]=C:VC(C)&&!l.isLambda?v||!i.range&&!m?s.values[s.length++]=C:u=t.FormulaError.BuiltIn.Value:y===`p`&&C?.isSheetSpan?u=t.FormulaError.BuiltIn.Value:v&&this._rref&&JH(C)?s.values[s.length++]=C:u=ZH(c,s,C,sE(C),y,m,D,!0,E,this._nmf);C=e[++n],C=c._expandSheetSpan?.(C)??C}else{let e=l.flatten,t=E,n=SE(C),r=m;!h||i.range||e||n||(y=`r`,e=!1,C!=null&&(C.isIRange||C.colStart!==void 0||Array.isArray(C))&&(t=null,r=null));let a=s,o=!!i.range||e,g=s.length;if(C===void 0||v&&C===null)s.values[s.length++]=null;else if(e){let t=[];(C!==null||y)&&(a=t,u=ZH(c,a,C,T,y,m,D,e,E)),t.length===0&&S?s.values[s.length++]=void 0:s.values[s.length++]=t}else u=ZH(c,a,C,T,y,r,D,e,t);u&&(o&&!T?(d??(d=u,f=g),u=null):o||(p=!0))}!u&&l.enumGate&&(u=this._gateDelivered(l,s,_),u&&(p=!0)),b=!!u}}if(u||d){if(!p){let e=u?s.length:f;for(let t=0;t<e;t++){let e=s.values[t];if(e==null||!0!==e.isIRange)continue;let n=e._optionsIterator;if(n?.type!==void 0&&(n.onError??`throw`)===`throw`&&e.hasError())return e.firstError()}}return u??d}let n=this._fn,_=s.length,S=g?s.values.slice(0,_):s.values;g&&v._setPrivateArgs(e.slice(0,r));let C=i?(e,t)=>n(...this._regroup(e,t,i)):null;if(h){let e=[null],r=(r,i)=>{let a=null;r&&(a=KH(c.getRuntime(),a,t.ScalarType.Null,r,!1));try{let r=o[0].enumGate;if(r&&(a=nE(r,a))===eE)throw t.FormulaError.BuiltIn.Value;e[0]=a,a=C?C(e,1):n(a),(0,t.isLazyValue)(a)&&(a=a.getValue())}catch(e){if(!t.FormulaError.isError(e))throw e;a=e}return i=i.fillEmpty(tU(a,c)??0)};if(l){let e=e=>a[e<m?e:m-1],r=e=>o[e<m?e:m-1],i=Array(_);v._setLiftValues(i);let s=c.getRuntime(),l;for(let n=0;n<_;n++){let a=e(n),o=a.range??null,c=S[n],u=!0===a.lazy;if(!(a.rest?o===`*`&&(a.arrayDepth??0)<=1:(o===null||o===`*`)&&(a.arrayDepth??0)===0)||!0!==c?.isIRange||r(n).wholeReference&&xE(c)){i[n]=u&&!(0,t.isLazyValue)(c)?UT.of(c):c;continue}c=c.getValueAt(0,0)??null;let d=a.scalar,f=null;if(_===1?d!==t.ScalarType.Null&&d!==`*`&&(f=d??null):d!==t.ScalarType.Boolean&&d!==t.ScalarType.Number&&d!==t.ScalarType.String&&d!==t.ScalarType.Error||(f=d),t.FormulaError.isError(c)){if(f!==null&&f!==t.ScalarType.Error||ZT(a,f)===`reject`){l=c;break}}else if(f!==null){let e=IH(c,!0);if(e!==f&&(c=KH(s,c,e,f,!0),t.FormulaError.isError(c))){l=c;break}}let p=r(n).enumGate;if(p&&(c=nE(p,c),c===eE)){l=t.FormulaError.BuiltIn.Value;break}i[n]=u?UT.of(c):c}if(l!==void 0)y=l;else{let e;try{e=C?C(i,_):n(...i),(0,t.isLazyValue)(e)&&(e=e.getValue()),e=Array.isArray(e)||e?.isIRange?tU(OE(e),c):tU(e,c)??0}catch(t){if(HT(t))throw t;e=tU(t,c)??0}y=e}}else if(_===1){let i=S[0],s=a[0],l=s.scalar;l!==t.ScalarType.Null&&l!==`*`||(l=null);let u=0,d=o[0].enumGate,f=ZT(s,l),p=(l===null||l===t.ScalarType.Error)&&f!==`reject`,m=c.getRuntime();v._setLiftValues(e),y=i.map(r=>{if(u++,t.FormulaError.isError(r)){if(!p)return r}else if(l!==null){let e=IH(r,!0);if(e!==l&&(r=KH(m,r,e,l,!0),t.FormulaError.isError(r)))return r}if(d&&(r=nE(d,r))===eE)return t.FormulaError.BuiltIn.Value;let i=r;try{if(e[0]=i,i=C?C(e,1):n(i),(0,t.isLazyValue)(i)&&(i=i.getValue()),Array.isArray(i)||i?.isIRange)return tU(OE(i),c)}catch(e){if(HT(e))throw e;i=e}return tU(i,c)??0}),u<i.size&&(y=r(l,y)),this._rs&&(y=y.toType({type:this._rs,onError:`value`}))}else{let e=1,r=1,i=Array(_),s=Array(_),l=[],u=[],d=e=>a[e<m?e:m-1],f=e=>o[e<m?e:m-1];for(let t=0;t<_;t++){let n=d(t),a=n.range??null;if(i[t]=(n.rest?a===`*`&&(n.arrayDepth??0)<=1:(a===null||a===`*`)&&(n.arrayDepth??0)===0)&&!0===S[t]?.isIRange&&!(f(t).wholeReference&&xE(S[t])),i[t]){let n=S[t];s[t]=n,l.push(t);let i=n.getRowCount(),a=n.getColumnCount();(i>1||a>1)&&u.push(t),i>e&&(e=i),a>r&&(r=a)}}let p=Array(_);v._setLiftValues(p);let h=Array(_),g=Array(_),b=Array(_);for(let e=0;e<_;e++){b[e]=!0===d(e).lazy,i[e]?b[e]&&(p[e]=UT.of(null)):p[e]=b[e]&&!(0,t.isLazyValue)(S[e])?UT.of(S[e]):S[e];let n=d(e).scalar,r=null;n!==t.ScalarType.Boolean&&n!==t.ScalarType.Number&&n!==t.ScalarType.String&&n!==t.ScalarType.String&&n!==t.ScalarType.Error||(r=n),h[e]=r;let a=ZT(d(e),r);g[e]=(r===null||r===t.ScalarType.Error)&&a!==`reject`}let x=c.getRuntime(),w=null,T=(e,n)=>{if(t.FormulaError.isError(n)){if(!g[e])return n}else if(h[e]!==null){let r=IH(n,!0);if(r!==h[e]&&(n=KH(x,n,r,h[e],!0),t.FormulaError.isError(n)))return n}let r=f(e).enumGate;if(r&&(n=nE(r,n))===eE)return t.FormulaError.BuiltIn.Value;b[e]?p[e]._fill(n):p[e]=n},E=(i,a,o)=>{let s;try{if(s=C?C(p,_):n(...p),(0,t.isLazyValue)(s)&&(s=s.getValue()),Array.isArray(s)||s?.isIRange)return o?((w??=Array(e*r))[i*r+a]=s,tU(OE(s),c)):wE}catch(e){if(HT(e))throw e;s=e}return tU(s,c)??0},D=u;for(let e=0;e<l.length;e++){let t=l[e],n=s[t];if(!(n.getRowCount()>1||n.getColumnCount()>1)&&T(t,n.getValueAt(0,0)??null)!==void 0){D=l;break}}let O=null;if(D===u&&u.length===1){let e=u[0],t=s[e],n=!1;O=t.map((t,r)=>{let i=T(e,t??null);if(i!==void 0)return i;if(r.rowIndex<0){let e=E(0,0,!1);return e===wE?(n=!0,null):e}return E(r.rowIndex,r.colIndex,!0)},TE),n&&(O=null)}if(O===null)if(w=null,D.length===0)O=c.createRange(1,1,()=>E(0,0,!0));else{let e=s[D[0]],n=D.slice(1).map(e=>s[e]),r=!1,i=i=>e.zip(n,(e,t)=>{for(let t=0;t<D.length;t++){let n=T(D[t],e[t]??null);if(n!==void 0)return n}if(t.rowIndex<0){let e=E(0,0,!1);return e===wE?(r=!0,null):e}return E(t.rowIndex,t.colIndex,!0)},{type:null,misalignValue:t.FormulaError.BuiltIn.NA,blankRegions:i});O=i(`once`),r&&(w=null,O=i(`each`))}y=O,w!==null&&EE(y,w,e,r)}}else if(C)this._lz&&QT(S,_,a,m),y=C(S,_);else if(this._lz&&QT(S,_,a,m),_<=6)switch(_){case 0:y=n();break;case 1:y=n(S[0]);break;case 2:y=n(S[0],S[1]);break;case 3:y=n(S[0],S[1],S[2]);break;case 4:y=n(S[0],S[1],S[2],S[3]);break;case 5:y=n(S[0],S[1],S[2],S[3],S[4]);break;case 6:y=n(S[0],S[1],S[2],S[3],S[4],S[5])}else{let e=[];for(let t=0;t<_;t++)e.push(S[t]);y=n(...e)}(0,t.isLazyValue)(y)&&(y=typeof(x=y)._force==`function`?x._force():x.getValue()),y=tU(y,c),!h&&this._rkScalar&&!0===y?.isIRange&&y.size===1&&!0!==y.isIReferenceRange&&(y=y.getValueAt(0,0)),c.isValidDate(y,!0)&&(c.formatResults(`Short Date`),y=c.toSerialDate(y))}catch(e){throw e}finally{XT>0&&XT--,zT()}var x;return y}_refusesReferenceLift(e,t,n,r,i){let a=i?i.prefix:-1,o=i?i.params.length-i.suffix:-1,s=Math.min(r,t);for(let t=0;t<s;t++){if(i&&t>=a&&t<o)continue;let r=e[t];if(!r.rest&&!r.range&&r.lambda==null&&(r.arrayDepth??0)===0&&!0===r.noLift&&!0!==r.reportType&&bE(n[t]))return!0}return!1}_refLift(e,n,r,i,a=!1){let o=i.length;if(a){let a=n.slice(0,r);for(let e=0;e<o;e++){let t=i[e],n=t.elements[0];n===void 0&&(n=t.collapsed.getValueAt(0,0)??null),a[t.argIndex]=n}let s;try{s=this._exec(a,r)}catch(e){if(!t.FormulaError.isError(e))throw e;s=e}return Array.isArray(s)||s?.isIRange?tU(OE(s),e):tU(s,e)??0}let s=1,c=1;for(let e=0;e<o;e++){let t=i[e];t.rows>s&&(s=t.rows),t.cols>c&&(c=t.cols)}let l=n.slice(0,r),u=null,d=e.createRange(s,c,(n,a)=>{let d=a.rowIndex,f=a.colIndex;for(let e=0;e<o;e++){let n=i[e],r=n.rows===1?0:d<n.rows?d:-1,a=n.cols===1?0:f<n.cols?f:-1;if(r<0||a<0){l[n.argIndex]=t.FormulaError.BuiltIn.NA;continue}let o=n.elements[r*n.cols+a];o===void 0&&(o=n.collapsed.getValueAt(r,a)??null),l[n.argIndex]=o}let p;try{p=this._exec(l,r)}catch(e){if(!t.FormulaError.isError(e))throw e;p=e}return Array.isArray(p)||p?.isIRange?((u??=Array(s*c))[d*c+f]=p,tU(OE(p),e)):tU(p,e)??0});return u!==null&&EE(d,u,s,c),d}_withContext(t){return new e(this._json,this._fn,t,this._descFn,this._builtIn)}getName(){return this._n}getDeclaration(){return this._d}async getDescriptor(e){let t=e??n.DefaultLanguagePackService.getActive();if(this._desc&&this._descLanguage===t)return this._desc;let r=await Promise.resolve(this._descFn(e));return this._desc=new gE(this,r),this._descLanguage=t,this._desc}isBuiltIn(){return this._builtIn}isLambda(){return!1}getContext(){let e=this._ct;if(e===`sheet`||e===`workbook`||e===`ranges`||e===`range`||e===`script`){let e=this._json;return e&&e.behavior&&e.behavior.default?`autoRun`:`macro`}return`formula`}get[Symbol.toStringTag](){return`[TypedFunction]`}toString(){let e=this._json,t=e.parameters,n=``;if(t.length>0){let e=t=>{let n=t.name;t.rest&&(n=`...`+n),t.optional&&(n+=`?`);let r=t.repeating;return r?`${n}: Repeating<${r.length===1?zH(r[0]):`[${r.map(e).join(`, `)}]`}>`:(n+=`: `+zH(t),n)};n=t.map(e).join(`, `)}let r=`${this.getName()}(${n})`,i=e?.returnType;if(i){let e=zH(i);return i.async?e=`Promise<${e}>`:i.stream&&(e=`Observable<${e}>`),`${r}: ${e}`}return r}get isIFunction(){return!0}get isITypedFunction(){return!0}},aE=e=>async t=>{let r={},i=e.parameters;for(let e=0;e<i.length;e++)r[i[e].name]={description:n.CommonUtils.camelToPrettyCase(i[e].description)};return{summary:n.CommonUtils.camelToPrettyCase(e.name),parameters:r,category:`User Defined`}},oE=()=>null,sE=e=>typeof e!=`object`||!e||e.colStart===void 0&&(!e.isIRange||!0===e._isLiteralArray?.()),cE=class{constructor(e){this._s=e.scalar??null,this._r=e.range??null,this._d=e.arrayDepth??0,this._l=e.lambda??null}getScalarType(){return this._s}getRangeType(){return this._r}getLambda(){return this._l}getArrayDepth(){return this._d}},lE=class e extends cE{constructor(t){super(t),this._n=t.name,this._o=t.optional??!1,this._dv=t.defaultValue,this._rest=t.rest??!1,this._e=t.enum?dE.of(t.enum):null,this._ae=!0===t.acceptError,this._nl=!0===t.noLift,this._nf=!0===t.noFilter,this._lz=!0===t.lazy,this._vr=!0===t.valueOrRange,this._g=t.repeating?Object.freeze(t.repeating.map(t=>new e(t))):null}getName(){return this._n}isAcceptError(){return this._ae}isNoFilter(){return this._nf}isNoLift(){return this._nl}isLazy(){return this._lz}isValueOrRange(){return this._vr}isOptional(){return this._o}getDefaultValue(){return this._dv}isRest(){return this._rest}getRepeatingTypes(){return this._g}getEnum(){return this._e}},uE=class{constructor(e,t,n){this._n=e,this._v=t,this._dp=n??!1}getName(){return this._n}getValue(){return this._v}isDeprecated(){return this._dp}},dE=class e{static{this._byJSON=new WeakMap}static of(t){let n=e._byJSON.get(t);return n||(n=new e(t),e._byJSON.set(t,n)),n}constructor(e){this._id=e.id,this._t=e.type,this._m=Object.freeze(e.members.map(([e,t,n])=>new uE(e,t,n)))}getId(){return this._id}getScalarType(){return this._t}getMembers(){return this._m}},fE=e=>{if(!e)return null;if(e.kind)return e.kind;if(e.lambda!=null)return t.ValueKind.Lambda;let n=e.range;if(n===`p`)return t.ValueKind.Reference;if(n===`r`||n===`m`)return t.ValueKind.Array;let r=e.scalar;return r==null||r===t.ScalarType.Null||r===`*`?null:r},pE=class extends cE{constructor(e){super(e),this._a=e.async??!1,this._stream=e.stream??!1,this._vol=e.volatile??!1,this._kind=fE(e)}getKind(){return this._kind}isAsync(){return this._a}isStreaming(){return this._stream}isVolatile(){return this._vol}},mE=255,hE=class{constructor(e){if(this._n=e.name,this._mx=e.maxArguments??mE,e.parameters){let t=e.parameters.length,n=Array(t);for(let r=0;r<t;r++)n[r]=new lE(e.parameters[r]);this._p=Object.freeze(n)}else this._p=n.CommonUtils.EmptyArray;e.returnType?this._r=new pE(e.returnType):this._r=new pE({scalar:null,arrayDepth:0,range:null})}getName(){return this._n}getParameters(){return this._p}getMaxArguments(){return this._mx}getReturnType(){return this._r}},gE=class{constructor(e,t){if(this._n=t.name??e?.getName(),this._nl=t.nameLocal??this._n,this._fn=e,this._s=t.summary??n.CommonUtils.camelToPrettyCase(this._n),this._c=t.category??`Uncategorized`,this._h=t.deprecated??!1,t.links&&t.links.length>0){let e=t.links.length,n=Array(e);for(let r=0;r<e;r++)n[r]=Object.freeze([t.links[r][0],t.links[r][1]]);this._l=Object.freeze(n)}else this._l=n.CommonUtils.EmptyArray;if(t.parameters){let n={};for(let r in t.parameters)if(Object.prototype.hasOwnProperty.call(t.parameters,r)){let i=t.parameters[r].description,a=t.parameters[r].example,o=t.parameters[r].defaultValue??e?.getDeclaration?.()?.getParameters?.().find(e=>e.getName()===r)?.getDefaultValue(),s={};i&&(s.description=i),a&&(s.example=a),o!==void 0&&(s.defaultValue=o),n[r]=Object.freeze(s)}this._p=Object.freeze(n)}else this._p=n.CommonUtils.EmptyObject;let r=null;for(let i of e?.getDeclaration?.()?.getParameters?.()??n.CommonUtils.EmptyArray)for(let e of[i,...i.getRepeatingTypes()??[]]){let n=e.getEnum();if(!n||r?.[n.getId()])continue;let i=t.enums?.[n.getId()],a={};for(let e of n.getMembers()){let t=i?.members?.[e.getName()];a[e.getName()]=Object.freeze({nameLocal:t?.nameLocal??e.getName(),...t?.description?{description:t.description}:null})}(r??={})[n.getId()]=Object.freeze({nameLocal:i?.nameLocal??n.getId(),...i?.summary?{summary:i.summary}:null,members:Object.freeze(a)})}this._e=r?Object.freeze(r):n.CommonUtils.EmptyObject}getEnums(){return this._e}getName(){return this._n}getNameLocal(){return this._nl}getSummary(){return this._s}getCategory(){return this._c}isDeprecated(){return this._h}getLinks(){return this._l}getParameters(){return this._p}get[Symbol.toStringTag](){return`[Descriptor]`}toString(){let e=this._fn;return`${this.getSummary()}: ${e}`}},_E={PARAM_MISSING:(e,n)=>new t.FormulaError.Parse(`Parameter ${e} is missing${n?` for ${n}`:``}.`),ARGS_TOO_FEW:(e,n)=>new t.FormulaError.Parse(`Argument type ${e.join(`, `)} is missing${n?` for ${n}`:``}.`),ARGS_TOO_MANY:(e,n,r)=>new t.FormulaError.Parse(`Too many arguments${r?` for ${r}`:``}. Expected ${e}, but got ${n}.`),ARGS_PAST_MAX:(e,n,r)=>new t.FormulaError.Parse(`Too many arguments${r?` for ${r}`:``}. The most it accepts is ${e}, but got ${n}.`),ARGS_REPEAT:(e,n,r,i)=>n===1?new t.FormulaError.Parse(`Too few arguments${i?` for ${i}`:``}. Expected at least ${e+1}, but got ${r}.`):new t.FormulaError.Parse(`Wrong number of arguments${i?` for ${i}`:``}. Expected ${e} plus a multiple of ${n}, but got ${r}.`)},vE={values:rU(255),length:0},yE=`_liftedFnResults`,bE=e=>{if(typeof e!=`object`||!e)return!1;let t=e;return t.colStart===void 0?!0===e.isIRange&&!0===e.isIReferenceRange&&e.size>1:t.colStart!==t.colEnd||t.rowStart!==t.rowEnd},xE=e=>typeof e==`object`&&!!e&&(e.colStart!==void 0||!0===e.isIReferenceRange),SE=e=>typeof e==`object`&&!!e&&!0===e.isIRange&&!0===e.isIReferenceRange&&e.size===1,CE=e=>!JH(e)&&(!function(e){let t=e;for(;Array.isArray(t);){if(t.length>1)return!1;t=t[0]}if(!t)return!0;if(t.isIRange&&t.size!==1)return!1;if(t.colStart!==void 0){let e=t;if(e.colStart!==e.colEnd||e.rowStart!==e.rowEnd)return!1}return!0}(e)||typeof e==`object`&&!!e&&!0===e.isIRange&&!0!==e.isIReferenceRange),wE=Symbol(`lift.arrayResult`),TE=Object.freeze({blankRegions:`once`}),EE=(e,t,n,r)=>{Object.defineProperty(e,yE,{value:{elements:t,rows:n,cols:r},enumerable:!1,configurable:!0})},DE=e=>e&&!0===e.isIRange?e[yE]??null:null,OE=e=>{let t=e;for(;Array.isArray(t);)t=t[0];return t?.isIRange&&(t=t.getValueAt(0,0)),t??null},kE=[{pkg:`@sheetxl/formulas`,id:`@sheetxl/formulas`,files:[`functions.json`]},{pkg:`@sheetxl/formulas-extended`,id:`@sheetxl/formulas-extended`,files:[`functions.json`]},{pkg:`@sheetxl/sdk`,id:`@sheetxl/sdk:grammar`,files:[`grammar.json`]}],AE=new Set;function jE(e,t){let r=`${e.id}\0${t}`;AE.has(r)||(AE.add(r),n.DefaultLanguagePackService.registerPack(e.id,t,async()=>{let r={tag:t};return await Promise.all(e.files.map(async i=>{let a=await(0,n.fetchLocaleResource)(e.pkg,`${t}/${i}`).catch(()=>{});a&&(i===`functions.json`?r.functions=a:Object.assign(r,a))})),r}))}function ME(e){if(e&&e!==`en`&&!e.startsWith(`en-`))for(let t of kE)jE(t,e)}var NE=!1,PE=new WeakMap;function FE(){let e=xi(),t=e?.functionHelp;if(!e||!t)return Promise.resolve(null);let n=PE.get(e);return n||(n=t().then(e=>e&&typeof e==`object`?`default`in e?{functions:e.default,enums:e.enums}:{functions:e,enums:void 0}:null).catch(()=>null),PE.set(e,n)),n}function IE(e,t){NE||(NE=!0,ME(n.DefaultLanguagePackService.getActive()),n.DefaultLanguagePackService.addChangeListener(e=>ME(e)));let a=(0,r.default)(e,BE);if((0,i.default)(e,BE,a),t)for(let n of t)n(e,BE,a);return a}function LE(e,n,r){let i=e=>{let n=null;e.s?n=e.s:e.r||e.g||(n=t.ScalarType.Number);let a={name:e.n,scalar:n,range:e.r??null,arrayDepth:e.d??0,optional:e.m===`?`,rest:e.m===`...`};return e.e!==void 0&&(a.enum=r(e.e)),e.l&&(a.lambda=e.l),e.a!==void 0&&(a.lambdaArity=e.a),e.ae&&(a.acceptError=!0),e.v!==void 0&&(a.defaultValue=e.v),e.u&&(a.omittable=!0),e.w!==void 0&&(a.omittedValue=e.w),e.nl&&(a.noLift=!0),e.nf&&(a.noFilter=!0),e.lz&&(a.lazy=!0),e.rt&&(a.reportType=!0),e.vr&&(a.valueOrRange=!0),e.g&&(a.repeating=e.g.map(i)),delete a.dim,a},a=[],o=n.p;if(o)for(let e=0;e<o.length;e++)a.push(i(o[e]));let s=null;n.r&&(s={},n.r.s&&(s.scalar=n.r.s),n.r.r&&(s.range=n.r.r===`p`||n.r.r===`r`||n.r.r===`m`?n.r.r:null),n.r.d&&(s.arrayDepth=n.r.d??0),n.r.l&&(s.lambda=n.r.l||null),n.r.k&&(s.kind=n.r.k),n.r.vol&&(s.volatile=!0));let c={name:e,parameters:a,returnType:s,context:n.c?`calculation`:null,maxArguments:n.mx},l=[];for(let e of a)for(let t of[e,...e.repeating??[]])t.enum&&!l.includes(t.enum.id)&&l.push(t.enum.id);return{decl:c,enumIds:l}}var RE,zE,BE=(e,r,i,a,o,s,c)=>{let l=new Map,u=e=>{let n=l.get(e);if(!n){let r=c?.[e];if(!r)return;n={id:e,type:r.s===`string`?t.ScalarType.String:t.ScalarType.Number,members:r.m},l.set(e,n)}return n},d=Object.keys(a);for(let t of d){let c=a[t],l=t,{decl:d,enumIds:f}=LE(l,c,u),p=i[c.fn??l],m,h,g=new iE(d,p,r,async e=>{if(!o)return null;let t;if(m)t=m;else{let e=await o();t=e.default,m=t,h=e.enums}let r=t?.[l];if(!r)return console.warn(`No descriptor found for built-in function: ${l}`),null;let i=await FE(),a=i?.functions?.[l],c=r.p,u=c?{...c}:n.CommonUtils.EmptyObject,d=Object.keys(u);if(d.length>0)for(let e=0;e<d.length;e++){let t=d[e],n=c[t],r=a?.p?.[t];u[t]={description:r?.d??n.d??``,example:r?.e??n.e,defaultValue:n.v}}let p={name:l,nameLocal:xi()?.functions?.[l]??l,summary:a?.s??r.s??``,category:a?.c??r.c??s??null,parameters:u,deprecated:r.h??!1,links:r.l??n.CommonUtils.EmptyArray};for(let e of f){let t=[i?.enums?.[`${l}:${e}`],i?.enums?.[e],h?.[e]].filter(e=>e!==void 0);if(t.length===0)continue;let n={};for(let e of t)for(let[t,r]of Object.entries(e.m??{})){let e=n[t]??={};e.nameLocal??=r.n,e.description??=r.d}(p.enums??={})[e]={nameLocal:t.find(e=>e.n!==void 0)?.n,summary:t.find(e=>e.s!==void 0)?.s,members:n}}return p},!0);e.set(l,g)}};function VE(e,t,n){if(!n)return e;let r=zE.parse(e,{anchor:t});if(!r)return e;let i=zE.transform(r,n);return i===r?e:zE.image(i,{at:t})}function HE(e){let t=e.toUpperCase();return e=>{if(e.type!==`cell`)return;let n=e.value?.scope;if(typeof n!=`string`||(n.length>1&&n.startsWith(`'`)&&n.endsWith(`'`)?n.slice(1,-1).replace(/''/g,`'`):n).toUpperCase()!==t)return;let{scope:r,...i}=e.value;return{...e,value:i}}}function UE(e,t,n){if(e.getStatus()!==X.Status.Running)return null;try{return e.createFormula(t,n??void 0)}catch{return null}}(function(e){let n=null;function a(e){return n||=(()=>{let e=new Map,n=(n,r,i,a,o,s,c)=>{let l=new Map,u=e=>{let n=l.get(e);if(!n){let r=c?.[e];if(!r)return;n={id:e,type:r.s===`string`?t.ScalarType.String:t.ScalarType.Number,members:r.m},l.set(e,n)}return n};for(let t of Object.keys(a)){let{decl:n}=LE(t,a[t],u),r=new hE(n);e.set(t.toUpperCase(),{getName:()=>t,getDeclaration:()=>r,isBuiltIn:()=>!0})}},a=new Map;return(0,r.default)(()=>null,n,a),(0,i.default)(()=>null,n,a),e})(),n.get(e.toUpperCase())??null}e.get=a,e.has=function(e){return a(e)!==null}})(RE||={}),function(e){let t=null,n=Object.freeze({rowStart:0,colStart:0,rowEnd:nd,colEnd:td}),r=e=>RE.get(e);function i(e,t){let i=mw(gT(_w(function(e){let t=RC(e);return!0===e.legacyIntersect&&(t.legacyIntersect=!0),t}(e)),r)),a=t?.entireCoords??n,o=!0===t?.r1c1;return e=>o?AT(i,a):jT(i,a,e?.rowIndex??0,e?.colIndex??0)}e.parse=function(e,n){if(typeof e!=`string`||e.length===0)return null;t||=new JS;let i=n?.anchor,a;try{let o=t.parse(i?.rowIndex??0,i?.colIndex??0,e);if(o.errors.length>0||!o.root||o.root.type===Z.Unparsed)return null;if(a=o.root,n?.normalize){let e=xT(a,r);typeof e!=`string`&&(a=e),a=pT(a,r),a=gT(a,r),a=_w(a),a=vw(a),a=Sw(a),a=yw(a),a=bw(a)}}catch{return null}return BC(a,null)},e.transform=function(e,t){return function(e,t){return e&&typeof t==`function`?FC(e,void 0,t):e}(e,t)},e.image=function(e,t){return i(e,t)(t?.at)},e.imager=i}(zE||={});var WE=class{constructor(e,t){this._host=null,this._binding=null,this._compiled=null,this._text=e.startsWith(`=`)?e.substring(1):e,this._marked=t}isMarked(){return this._marked}bind(e){this._binding=e}bindHost(e){!e&&this._host&&(this._text=this._readHost(this._host)??this._text),this._host=e}_readHost(e){let t=e.getView(),n=e.getCoords();if(!t||!n)return null;let r=this._binding?.getScope()??null,i=this._binding?.getAnchor()??null,a={rowIndex:i?.rowIndex??n.rowStart,colIndex:i?.colIndex??n.colStart};return VE(t.getTextAt(a.rowIndex,a.colIndex),a,this._readTransform(r))}_readTransform(e){return e?HE(e):void 0}getText(){let e=this._host;return(e?this._readHost(e):null)??this._text}_formula(){let e=this._binding?.getCalculation()??null;if(!e)return null;let t=this._binding.getAnchor(),n=this.getText(),r=`${t?.rowIndex??``}:${t?.colIndex??``}|${n}`;if(this._compiled?.key===r)return this._compiled.formula;let i=UE(e,n,t);return this._compiled=i?{key:r,formula:i}:null,i}evaluate(e){let t=this._formula();return t?t.evaluate(e):Promise.reject(Error(`A condition formula has no calculation to evaluate with.`))}getCalculationStatus(){return this._formula()?.getCalculationStatus()??X.ResultStatus.Pending}isCompiled(){return this._formula()?.isCompiled()??!1}getExpression(e){return e&&(e.target===`display`||e.r1c1||e.cell||e.evalIndex!==void 0)?this._formula()?.getExpression(e)??this.getText():this.getText()}getAnchor(){return this._binding?.getAnchor()??null}shift(e){return this._formula()?.shift(e)??null}getReferences(){return this._formula()?.getReferences()??null}hasRefError(){return this._formula()?.hasRefError()??!1}setReferenceAt(e,t,n){return Promise.reject(Error(`A condition formula is changed by setting the condition.`))}setReferenceModeAt(e,t,n,r){return Promise.reject(Error(`A condition formula is changed by setting the condition.`))}isReferenceOnly(){return this._formula()?.isReferenceOnly()??!1}isVolatile(){return this._formula()?.isVolatile()??Promise.resolve(!1)}getTokens(e){return this._formula()?.getTokens(e)??[]}isValid(){return this._formula()?.isValid()??!0}autoCorrect(){return this._formula()?.autoCorrect()??null}toJSON(){let e=this.getText();return this._marked?`=`+e:e}toString(){let e=this.getExpression();return this._marked?`=`+e:e}get[Symbol.toStringTag](){return`[ConditionFormula]`}get isIFormula(){return!0}},GE=class extends WE{constructor(e){super(e,!1)}getCheckExpression(e){return this.isValid()?`ISNUMBER(MATCH(${cd(e)},${this.getText()},0))`:`FALSE`}bindHost(e){e&&!this.isValid()||super.bindHost(e)}_readTransform(e){let t=e?HE(e):void 0;return(e,n)=>n?t?.(e,n):(e.inputs?.[0])?.inputs?.[1]||void 0}get[Symbol.toStringTag](){return`[ListSourceFormula]`}},KE=class{constructor(e){this._delegate=e,this._types=e.getAcceptsTypes?e.getAcceptsTypes():null}getName(){return this._delegate.getName()}createPredicate(e,t){return this._delegate.createPredicate(e,t)}getAcceptsTypes(){return this._types?this._types:null}acceptsList(){return this._delegate.acceptsList?.()??!1}getParamType(e){return e?e.getName():null}isCombinator(){return!1}getTitle(){return this._delegate.getTitle?.()}getDescription(){return this._delegate.getDescription?.()??null}createDefaultParam(e){return this._delegate.createDefaultParam?.(e)}validateParam(e,t){return this._delegate.validateParam?.(e,t)??null}doBatch(e,t,n){return this._delegate.doBatch?.(e,t,n)}toString(e,t){return this._delegate.toString?.(e,t)}get[Symbol.toStringTag](){return`[Condition]: ${this.getName()}`}};function qE(e){if(t.FormulaError.isError(e))return{t:`e`,v:e.getCode()};if(e instanceof WE)return e.toJSON();if(!e||typeof e!=`object`)return e;if(e.isICondition)return e.toJSON();if(Array.isArray(e)){let t=!1,n=e.map(e=>{let n=YE(e);return n!==e&&(t=!0),n});return t?n:e}if(typeof e.operator==`string`)return YE(e);if(e.items instanceof WE)return{...e,items:e.items.toJSON()};let n=JE(e.from),r=JE(e.to);return n!==e.from||r!==e.to?{...e,from:n,to:r}:e}function JE(e){return t.FormulaError.isError(e)?{t:`e`,v:e.getCode()}:e instanceof WE?e.toJSON():e}function YE(e){if(!e||typeof e!=`object`)return e;if(e.isICondition)return e.toJSON();let t=qE(e.param);return t===e.param?e:{...e,param:t}}function XE(e){if(e&&typeof e==`object`&&e.t===`e`&&typeof e.v==`number`)return t.FormulaError.getBuiltInByCode(e.v)}var ZE=new Set([Y.BuiltInOperatorNames.EqualTo,Y.BuiltInOperatorNames.GreaterThan,Y.BuiltInOperatorNames.GreaterThanEqualTo,Y.BuiltInOperatorNames.LessThan,Y.BuiltInOperatorNames.LessThanEqualTo,Y.BuiltInOperatorNames.After,Y.BuiltInOperatorNames.AfterEqualTo,Y.BuiltInOperatorNames.Before,Y.BuiltInOperatorNames.BeforeEqualTo]);function QE(e,t){let n=Y.BuiltInOperatorNames;switch(e){case n.Expression:return eD(t,!1)??t;case n.Between:{if(!t||typeof t!=`object`||Array.isArray(t))return t;let e=eD(t.from,!0)??t.from,n=eD(t.to,!0)??t.to;return e===t.from&&n===t.to?t:{...t,from:e,to:n}}case n.InSet:{typeof t==`string`&&(t={items:t});let e=t?.items;if(e instanceof GE)return t;let n=e instanceof WE?e.getText():e;return typeof n!=`string`||!n.trim()||tD(n)?t:{...t,items:new GE(n)}}case n.Not:return $E(t);case n.And:case n.Or:return Array.isArray(t)?t.map($E):t;default:return e&&ZE.has(e)?eD(t,!0)??t:t}}function $E(e){if(!e||typeof e!=`object`||e.isICondition)return e;let t=e.operator,n=QE(typeof t==`string`?t:t?.getName?.(),e.param);return n===e.param?e:{...e,param:n}}function eD(e,t){return e instanceof WE?e.isMarked()===t?e:new WE(e.getText(),t):e?.isIFormula?new WE(e.getExpression(),t):typeof e==`string`?t?e.startsWith(`=`)?new WE(e,!0):null:new WE(e,!1):null}function tD(e){let t=e.trim();if(t.length<2||t[0]!==`"`||t[t.length-1]!==`"`)return!1;let n=t.slice(1,-1);for(let e=0;e<n.length;e++)if(n[e]===`"`){if(n[e+1]!==`"`)return!1;e++}return!0}function nD(e){if(!tD(e))return null;let t=e.trim().slice(1,-1).replace(/""/g,`"`);return t===``?[]:t.split(`,`)}function rD(e){for(let t=0;t<e.length;t++)if(e[t].includes(`,`))return null;return`"`+e.join(`,`).replace(/"/g,`""`)+`"`}function iD(e,t){e&&aD(e.getParam(),t)}function aD(e,t){if(e&&typeof e==`object`)if(e instanceof WE)t(e);else if(Array.isArray(e))for(let n=0;n<e.length;n++)aD(e[n],t);else e.isICondition?aD(e.getParam(),t):e.operator===void 0?(aD(e.items,t),aD(e.from,t),aD(e.to,t)):aD(e.param,t)}function oD(e){if(!e)return null;if(e.isICondition)return e;if(typeof e==`function`){let t=e;return new zD(null,new KE({getName:()=>`Predicate`,createPredicate:e=>t}))}if(typeof e==`string`){let t=e.trim(),n=/^(<=|>=|<>|=|<|>)(.*)$/i.exec(t);if(n){let[,e,t]=n,r=t.trim(),i=r===``?NaN:Number(r),a=Number.isFinite(i)?i:r.startsWith(`=`)?new WE(r,!0):r,o={"<":Y.BuiltInOperatorNames.LessThan,"<=":Y.BuiltInOperatorNames.LessThanEqualTo,">":Y.BuiltInOperatorNames.GreaterThan,">=":Y.BuiltInOperatorNames.GreaterThanEqualTo,"=":Y.BuiltInOperatorNames.EqualTo},s=e===`<>`,c=s?Y.BuiltInOperatorNames.Not:o[e],l=zD.Operators.get(c);if(!l)throw Error(`Unknown operator for shorthand: ${e}`);return new zD(null,l,s?{operator:Y.BuiltInOperatorNames.EqualTo,param:a}:a)}}if(typeof e==`object`){let t={...e},n=null,r=t.selector;if(r)if(typeof r==`string`){if(n=zD.Selectors.get(r)??null,!n)throw Error(`Unknown selector name: ${r}`)}else n=r;let i=t.operator;if(typeof i==`function`&&(i=i()),typeof i==`string`){let e=zD.Operators.get(i);if(!e)throw Error(`Unknown operator name: ${i}`);i=e}let a=t.includeBlanks,o=QE(i?.getName?.(),function(e){let t=XE(e);if(t)return t;if(!e||typeof e!=`object`||Array.isArray(e))return e;let n=XE(e.from),r=XE(e.to);return n||r?{...e,from:n??e.from,to:r??e.to}:e}(t.param));if(i||n||a!==void 0)return new zD(n,i,o,a)}return null}var sD=class{constructor(e,t){this._resolved=null,this._json={...e},this._reason=t}resolve(){let e=this._resolved;if(e)return e;try{e=oD(this._json)}catch(e){return this._reason=e?.message??this._reason,null}return this._resolved=e,e}getUnresolvedReason(){return this._reason}getSelector(){return this.resolve()?.getSelector()??null}getOperator(){return this.resolve()?.getOperator()??null}getParam(){return this._json.param??null}isIncludeBlanks(){return this._json.includeBlanks??!1}validate(){return this.resolve()?.validate()??null}toString(){return this.resolve()?.toString()??this._reason}toJSON(){let e=this._resolved;return e?e.toJSON():{...this._json}}get isICondition(){return!0}};function cD(e){if(!e)return null;try{return oD(e)}catch(t){let r=t?.message??`Unresolvable condition.`;return n.Notifier.debug(`Condition kept unresolved: ${r}`,{onceKey:`condition.unresolved.${r}`,meta:{type:`condition`}}),new sD(e,r)}}function lD(e){return e.getOperator()?.getName()===Y.BuiltInOperatorNames.Expression||uD(e.getParam())}function uD(e){return!!e?.isIFormula||(typeof e==`string`?e.startsWith(`=`):!(!e||typeof e!=`object`)&&(Array.isArray(e)?e.some(dD):e.isICondition||e.operator!==void 0?dD(e):!(!e.from?.isIFormula&&!e.to?.isIFormula)||!(typeof e.from!=`string`||!e.from.startsWith(`=`))||!(typeof e.to!=`string`||!e.to.startsWith(`=`))))}function dD(e){if(!e||typeof e!=`object`)return!1;if(e.isICondition)return lD(e);let t=e.operator;return(typeof t==`string`?t:t?.getName?.())===Y.BuiltInOperatorNames.Expression||uD(e.param)}var fD=(e,n)=>e===n||e===t.InteropScalarType.Date&&n===t.InteropScalarType.Number;async function pD(e,n){let r=n.coords,i=n.values,a=n.cellValuesOptions,o=i.entries(a),s={position:null,value:null},c=new vD(n.runtime,s,n.values,r,n.calculation??null,n.visibleCoords);c.setWatchFormula(n.watchFormula??null),e.getSelector()||c.setGetText(n.getText??null);let l=e.getSelector(),u=l?await l.createTransformer(c):null,d=l?.getInputType()??null,f=l?.getSelectType()??null,p=e.getOperator(),m=p?.getAcceptsTypes?.()??null,h=await p?.createPredicate(e.getParam(),c);if(!h)return;c.setBatchCapable(typeof p?.doBatch==`function`);let g=n.onBlank;if(g){let t=e.isIncludeBlanks(),n={rowIndex:0,colIndex:0};g((e,r)=>{if(t)return!0;n.rowIndex=e,n.colIndex=r,s.position=n,s.value=null,c.beginPredicateCall();let i=h(null,c);return!c.wasDeferred()&&!!i})}let _=n.onTrue,v=n.onFalse,y=[],b=o.next();for(;!b.done;){let e=b.value;b=o.next();let t=e[1],n=e[0];if(d!==null&&!fD(d,IH(t))){v&&v(n,t);continue}let r=u?u(t,c):t;if(m!==null){let e=f??IH(r);if(!m.includes(e)){v&&v(n,t);continue}}s.position=n,s.value=t,c.beginPredicateCall();let i=h(r,c);c.wasDeferred()?y.push([n,t]):i?_&&_(n,t):v&&v(n,t)}if(y.length>0){let n=await p.doBatch(c.getDeferredKeys(),e.getParam(),c);for(let[e,i]of y){let a;try{a=n?.getValueAt(e.rowIndex-r.rowStart,e.colIndex-r.colStart)??null}catch(e){if(!t.FormulaError.isError(e))throw e;a=e}!t.FormulaError.isError(a)&&a?_&&_(e,i):v&&v(e,i)}}}async function mD(e){let r=e.coords,i={bounds:r,axis:e.axis??t.IRange.Axis.Column},a=e.getHiddenRuns;if(a){let n=e.includeHidden;!0!==n&&n!==t.IRange.Axis.Row&&(i.processRowSkip=Lt(a(t.IRange.Axis.Row))),!0!==n&&n!==t.IRange.Axis.Column&&(i.processColumnSkip=Lt(a(t.IRange.Axis.Column)))}let o=e.conditions[0];if(!o)return;let s=zD.resolveInput(o);if(!s)return void n.Notifier.debug(`No condition to evaluate.`,{onceKey:`condition.none`,meta:{type:`condition`}});let c=e.calculation;if(c&&lD(s)){let e=c._whenCanCompile;e?await e.call(c):await c.ready()}await pD(s,{runtime:e.runtime,values:e.values,coords:r,cellValuesOptions:i,calculation:e.calculation,watchFormula:e.watchFormula,onTrue:e.onTrue,onFalse:e.onFalse,onBlank:e.onBlank})}function hD(e){return e?typeof e==`object`&&Array.isArray(e.conditions)?e:{conditions:[e]}:{conditions:[]}}function gD(e,t,n){if(t>n)return[];let r=Dt(e.map(e=>({min:e.min,max:e.max,value:!0}))),i=[];return Mt(r,e=>{!0!==e.value&&i.push({min:e.min,max:e.max})},t,n),i}function _D(...e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(let e=0;e<r.length;e++)t.push({min:r[e].min,max:r[e].max})}return t.length===0?[]:Tt(Et(Dt(t)))}var vD=class{constructor(e,t,n,r,i=null,a){this._coords=null,this._values=null,this._range=null,this._watchFormula=null,this._getText=null,this._text=null,this._textRead=!1,this._batchCapable=!1,this._deferredCall=!1,this._deferredKeys=null,this._runtime=e,this._scope=t,this._values=n,this._coords=Object.freeze(r),this._calculation=i,this._visibleCoords=a}setBatchCapable(e){this._batchCapable=e,this._deferredKeys=null}beginPredicateCall(){this._deferredCall=!1,this._textRead=!1}wasDeferred(){return this._deferredCall}getDeferredKeys(){return this._deferredKeys??new Set}getType(e){return IH(e)}getPosition(){return this._scope.position}getCoords(){return this._coords}getRange(){let e=this._range;if(!e){let t=this._visibleCoords;e=t?new aW(this._runtime,this._values,this._coords,t):new iW(this._runtime,this._values,this._coords),this._range=e}return e}toType(e,t){return KH(this._runtime,e,IH(e),t,!1)}setGetText(e){this._getText=e}getText(){let e=this._getText;if(!e)return null;if(!this._textRead){let t=this._scope,n=t.position;this._text=e(n.rowIndex,n.colIndex,t.value),this._textRead=!0}return this._text}async resolveInput(e){return zD.resolveInput(e)}fromSerialDate(e){return dl(e,this._runtime.isDate1904())}getDateParts(e,t){return cl(e,this._runtime.isDate1904(),t)}toSerialDate(e){return fl(e,this._runtime.isDate1904())}getNow(){return fl(new Date(this._runtime.getNow()),this._runtime.isDate1904())}deferBatch(e){if(!this._batchCapable)throw Error(`ICondition.IContext.deferBatch was called but the active operator does not implement doBatch.`);this._deferredCall=!0,(this._deferredKeys??=new Set).add(e)}setWatchFormula(e){this._watchFormula=e}async watchFormula(e){let t=typeof e==`string`?e:e.getExpression();if(!t||!t.trim())return null;let n=this._watchFormula;if(n)return n(e);let r=typeof e==`string`?this.createFormula(e):this._createStored(e instanceof GE?e.getCheckExpression({rowIndex:this._coords.rowStart,colIndex:this._coords.colStart}):t);return r?await r.evaluate({block:this._coords,arrayFirstCell:!0,alwaysReturnRange:!0}):null}createFormula(e,t){return this._calculation?this._calculation.createFormula(e,t??{rowIndex:this._coords.rowStart,colIndex:this._coords.colStart}):null}_createStored(e){return this._calculation?UE(this._calculation,e,{rowIndex:this._coords.rowStart,colIndex:this._coords.colStart}):null}},yD=()=>!1,bD=async(e,t,n)=>{let r=await n.watchFormula(e);if(!r)return null;let i=n.getCoords();return(e,n)=>{if(e===null&&t)return!0;let a=n.getPosition();return!0===r.getValueAt(a.rowIndex-i.rowStart,a.colIndex-i.colStart)}},xD=(e,n,r)=>{let i=function(e){let t=new Set;for(let n=0;n<e.length;n++)t.add(e[n].replace(/^ +/,``));return e=>t.has(e.replace(/^ +| +$/g,``))}(e);return e=>{if(e===null||e===``)return n;if(t.FormulaError.isError(e))return!1;let a=typeof e==`string`?e:r.toType(e,t.InteropScalarType.String);return typeof a==`string`&&i(a)}},SD=(e,t)=>(t.year===void 0||t.year===e.year)&&(t.month===void 0||t.month===e.month)&&(t.day===void 0||t.day===e.day)&&(t.hour===void 0||t.hour===e.hour)&&(t.minute===void 0||t.minute===e.minute)&&(t.second===void 0||t.second===e.second),CD=()=>!1,wD=()=>!0,TD={Blank:new class extends xv{constructor(e){super({name:Y.BuiltInOperatorNames.Blank,title:(0,n.messageKey)(`condition.operator.blank.title`),acceptTypes:[t.InteropScalarType.Null],paramType:null,...e})}createPredicate(e,t){return e=>e===null}},Error:new class extends xv{constructor(e){super({name:Y.BuiltInOperatorNames.Error,title:(0,n.messageKey)(`condition.operator.error.title`),acceptTypes:[t.InteropScalarType.Error],paramType:null,...e})}createPredicate(e,n){return e=>e&&t.FormulaError.isError(e)}},Average:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Average,title:(0,n.messageKey)(`condition.operator.average.title`),acceptTypes:[t.InteropScalarType.Number],paramType:`average`,description:(0,n.messageKey)(`condition.operator.average.desc`)})}async createPredicate(e,t){let n=t.getRange().getStats().getAggregates(),r=n.average,i=n.stdDev;if(r==null)return Sv;let a=Y.AverageType.Above,o=e.type??a,s=e.stdDevs??0,c=s!==0&&i!=null?r+s*i*(o===a?1:-1):r;if(o===a||o===Y.AverageType.AboveOrEqual){let e=o===Y.AverageType.AboveOrEqual;return t=>e?t>=c:t>c}{let e=o===Y.AverageType.BelowOrEqual;return t=>e?t<=c:t<c}}validateParam(e,t){let r=e?.stdDevs??0;return Number.isInteger(r)&&r>=0?null:(0,n.messageKey)(`condition.error.stdDevs`)}createDefaultParam(e){return{type:Y.AverageType.Above,stdDevs:0}}toString(e,t){let r={...this.createDefaultParam(t),...e},i=r.type===Y.AverageType.Above||r.type===Y.AverageType.AboveOrEqual,a=r.type===Y.AverageType.AboveOrEqual||r.type===Y.AverageType.BelowOrEqual;return(0,n.t)(`condition.operator.average.toString`,{dir:i?`above`:`below`,eq:a?`yes`:`no`,stdDevs:r.stdDevs??0})}},Between:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Between,title:(0,n.messageKey)(`condition.operator.between.title`),acceptTypes:[t.InteropScalarType.Number,t.InteropScalarType.Date],paramType:`between`,description:(0,n.messageKey)(`condition.operator.between.desc`)})}async createPredicate(e,n){if(this._isMissingOperand(e?.from)||this._isMissingOperand(e?.to))return null;let r=await this._resolveOperand(e.from,n),i=await this._resolveOperand(e.to,n);return r&&i?(e,n)=>{let a=r(n),o=i(n);return t.FormulaError.isError(a)||t.FormulaError.isError(o)?!1:e>=(a??0)&&e<=(o??0)}:null}createDefaultParam(e){return{from:null,to:null}}validateParam(e,t){let r=e?.from,i=e?.to;return this._isMissingOperand(r)||this._isMissingOperand(i)?(0,n.messageKey)(`condition.error.boundsRequired`):(this._validateOperand(r,t)??this._validateOperand(i,t))||(typeof r==`number`&&typeof i==`number`&&r>i?(0,n.messageKey)(`condition.error.boundsReversed`):null)}toString(e,t){let r=this._isMissingOperand(e?.from),i=this._isMissingOperand(e?.to);return r&&i?this.getTitle():(0,n.t)(`condition.operator.between.toString`,{from:r?`…`:e.from,to:i?`…`:e.to})}},EqualTo:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.EqualTo,acceptTypes:[t.InteropScalarType.String,t.InteropScalarType.Number,t.InteropScalarType.Date,t.InteropScalarType.Boolean],title:(0,n.messageKey)(`condition.operator.equalTo.title`)})}async createPredicate(e,n){if(!(e?.isIFormula||typeof e==`string`&&e.startsWith(`=`))){if(typeof e==`string`){let t=aa(e);return(e,n)=>{if(e===null)return t===``;let r=typeof e==`string`?e:n.getText();return r!==null&&aa(r)===t}}return t=>t===e||t===null&&e===0}let r=await this._resolveOperand(e,n);return r?(e,n)=>{let i=r(n);if(t.FormulaError.isError(i))return!1;if(typeof i==`string`){if(e===null)return i===``;let t=typeof e==`string`?e:n.getText();return t!==null&&aa(t)===aa(i)}return e===i||e===null&&i===0}:null}validateParam(e,t){return this._validateOperand(e,t,!0)}createDefaultParam(e){return e?e.getSelectType()===t.InteropScalarType.String?``:e.getSelectType()===t.InteropScalarType.Number?0:e.getSelectType()===t.InteropScalarType.Boolean||(e.getSelectType()===t.InteropScalarType.Date?0:void 0):null}},GreaterThan:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.GreaterThan,acceptTypes:[t.InteropScalarType.Number],title:(0,n.messageKey)(`condition.operator.greaterThan.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e>t)}validateParam(e,t){return this._validateOperand(e,t)}},GreaterThanEqualTo:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.GreaterThanEqualTo,acceptTypes:[t.InteropScalarType.Number],title:(0,n.messageKey)(`condition.operator.greaterThanEqualTo.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e>=t)}validateParam(e,t){return this._validateOperand(e,t)}},LessThan:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.LessThan,acceptTypes:[t.InteropScalarType.Number],title:(0,n.messageKey)(`condition.operator.lessThan.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e<t)}validateParam(e,t){return this._validateOperand(e,t)}},LessThanEqualTo:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.LessThanEqualTo,acceptTypes:[t.InteropScalarType.Number],title:(0,n.messageKey)(`condition.operator.lessThanEqualTo.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e<=t)}validateParam(e,t){return this._validateOperand(e,t)}},After:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.After,acceptTypes:[t.InteropScalarType.Date],title:(0,n.messageKey)(`condition.operator.after.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e>t)}validateParam(e,t){return this._validateOperand(e,t)}},AfterOrEqualTo:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.AfterEqualTo,acceptTypes:[t.InteropScalarType.Date],title:(0,n.messageKey)(`condition.operator.afterEqualTo.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e>=t)}validateParam(e,t){return this._validateOperand(e,t)}},Before:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Before,acceptTypes:[t.InteropScalarType.Date],title:(0,n.messageKey)(`condition.operator.before.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e<t)}validateParam(e,t){return this._validateOperand(e,t)}},BeforeOrEqualTo:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.BeforeEqualTo,acceptTypes:[t.InteropScalarType.Date],title:(0,n.messageKey)(`condition.operator.beforeEqualTo.title`)})}createPredicate(e,t){return this._createComparePredicate(e,t,(e,t)=>e<=t)}validateParam(e,t){return this._validateOperand(e,t)}},Unique:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Unique,title:(0,n.messageKey)(`condition.operator.unique.title`),paramType:null,acceptTypes:null,description:(0,n.messageKey)(`condition.operator.unique.desc`)})}async createPredicate(e,t){let n=t.getRange().getStats().getFrequencies();return e=>n.getFrequency(e)===1}},Expression:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Expression,title:(0,n.messageKey)(`condition.operator.expression.title`),paramType:Y.BuiltInOperatorNames.Expression,description:(0,n.messageKey)(`condition.operator.expression.desc`)})}validateParam(e,t){if(e?.isIFormula){let t=e;return t.getExpression().trim().length===0?(0,n.messageKey)(`condition.error.formulaRequired`):t.isValid()?null:(0,n.messageKey)(`condition.error.formulaInvalid`)}return typeof e!=`string`||e.trim().length===0?(0,n.messageKey)(`condition.error.formulaRequired`):null}createDefaultParam(e){return``}async createPredicate(e,t){let n=await t.watchFormula(e);if(!n)return null;let r=t.getCoords();return(e,t)=>{let i=t.getPosition(),a=n.getValueAt(i.rowIndex-r.rowStart,i.colIndex-r.colStart);return!0===a||typeof a==`number`&&a!==0}}},InSet:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.InSet,title:(0,n.messageKey)(`condition.operator.inSet.title`),description:(0,n.messageKey)(`condition.operator.inSet.desc`)})}acceptsList(){return!0}createPredicate(e,t){let n=e?.blank??!1,r=e?.items;if(r instanceof GE)return bD(r,n,t);if(typeof r==`string`){let e=nD(r);return e?xD(e,n,t):yD}let i=Array.isArray(e?.items)?e.items:[],a=e?.dateGroups??[],o=a.length;if(i.length===0&&o===0&&!n)return yD;let s=i.length>0?new Set(i.map(wv)):void 0,c=i.some(e=>typeof e==`string`),l=o>0?{year:0,month:0,day:0,hour:0,minute:0,second:0,millis:0,dow:0,serial:0}:void 0;return(e,r)=>{if(e===null||e===``)return n;if(s?.has(wv(e)))return!0;if(c){let t=r.getText();if(t!==null&&t!==e&&s.has(wv(t)))return!0}if(o>0&&typeof e==`number`){let n=t.getDateParts(e,l);for(let e=0;e<o;e++)if(SD(n,a[e]))return!0}return!1}}validateParam(e,t){let r=e?.items;return r instanceof GE?r.isValid()?null:(0,n.messageKey)(`condition.error.formulaInvalid`):typeof r==`string`?r.trim().length>0?null:(0,n.messageKey)(`condition.error.listRequired`):Array.isArray(r)&&r.length>0||(e?.dateGroups?.length??0)>0||e?.blank?null:(0,n.messageKey)(`condition.error.listRequired`)}createDefaultParam(e){return{items:[]}}toString(e,t){let r={...this.createDefaultParam(t),...e},i=this.getTitle(),a=r.items;if(a instanceof GE||typeof a==`string`)return(0,n.t)(`condition.operator.titleWithParam`,{title:i,param:a instanceof GE?a.getText():a});if(Array.isArray(a))return(0,n.t)(`condition.operator.inSet.items`,{title:i,count:a?a.length:0});let o=r.dateGroups;return o?(0,n.t)(`condition.operator.inSet.dateGroups`,{title:i,count:o?o.length:0}):i}},Icon:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Icon,title:(0,n.messageKey)(`condition.operator.icon.title`),description:(0,n.messageKey)(`condition.operator.icon.desc`)})}createPredicate(e,t){return e=>!1}},Color:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Color,title:(0,n.messageKey)(`condition.operator.color.title`),description:(0,n.messageKey)(`condition.operator.color.desc`)})}createPredicate(e,t){return e=>!1}},TextStartsWith:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TextStartsWith,acceptTypes:[t.InteropScalarType.String],title:(0,n.messageKey)(`condition.operator.textStartsWith.title`)})}createPredicate(e,t){let n=aa(e);return e=>typeof e==`string`&&aa(e).startsWith(n)}validateParam(e,t){return typeof e==`string`&&e.length>0?null:(0,n.messageKey)(`condition.error.textRequired`)}},TextEndsWith:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TextEndsWith,acceptTypes:[t.InteropScalarType.String],title:(0,n.messageKey)(`condition.operator.textEndsWith.title`)})}createPredicate(e,t){let n=aa(e);return e=>typeof e==`string`&&aa(e).endsWith(n)}validateParam(e,t){return typeof e==`string`&&e.length>0?null:(0,n.messageKey)(`condition.error.textRequired`)}},TextContains:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TextContains,acceptTypes:[t.InteropScalarType.String],title:(0,n.messageKey)(`condition.operator.textContains.title`)})}createPredicate(e,t){let n=aa(e);return e=>typeof e==`string`&&aa(e).includes(n)}validateParam(e,t){return typeof e==`string`&&e.length>0?null:(0,n.messageKey)(`condition.error.textRequired`)}},TextEmail:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TextEmail,acceptTypes:[t.InteropScalarType.String],paramType:null,title:(0,n.messageKey)(`condition.operator.textEmail.title`)})}createPredicate(e,t){return e=>typeof e==`string`&&ie(e)}},TextIsUrl:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TextIsUrl,acceptTypes:[t.InteropScalarType.String],paramType:null,title:(0,n.messageKey)(`condition.operator.textIsUrl.title`)})}createPredicate(e,t){return e=>typeof e==`string`&&ne(e)}},TimePeriod:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TimePeriod,acceptTypes:[t.InteropScalarType.Date],title:(0,n.messageKey)(`condition.operator.timePeriod.title`),paramType:`timePeriod`,description:(0,n.messageKey)(`condition.operator.timePeriod.desc`)})}async createPredicate(e,t){let{min:n,max:r}=this._computeRange(e,t);return e=>{if(typeof e!=`number`)return!1;let t=Math.floor(e);return t>=n&&t<=r}}validateParam(e,t){let r=e?.type,i=Object.values(Y.TimePeriodType);return r&&i.includes(r)?null:(0,n.messageKey)(`condition.error.periodRequired`)}createDefaultParam(e){return{type:Y.TimePeriodType.Today}}toString(e,t){let r={...this.createDefaultParam(t),...e};return(0,n.t)(`condition.operator.timePeriod.toString`,{title:this.getTitle(),period:n.CommonUtils.camelToPrettyCase(r.type)})}_computeRange(e,t){let n=e.type??Y.TimePeriodType.Today,r=e.anchorDate??t.getNow(),i=Math.floor(r),a=t.fromSerialDate(i),o=a.getFullYear(),s=a.getMonth(),c=a.getDay();switch(n){case`today`:return{min:i,max:i};case`yesterday`:return{min:i-1,max:i-1};case`tomorrow`:return{min:i+1,max:i+1};case`last7Days`:return{min:i-6,max:i};case`thisWeek`:{let e=new Date(a);e.setDate(a.getDate()-c);let n=new Date(e);return n.setDate(e.getDate()+6),{min:t.toSerialDate(e),max:t.toSerialDate(n)}}case`lastWeek`:{let e=new Date(a);e.setDate(a.getDate()-c-7);let n=new Date(e);return n.setDate(e.getDate()+6),{min:t.toSerialDate(e),max:t.toSerialDate(n)}}case`nextWeek`:{let e=new Date(a);e.setDate(a.getDate()-c+7);let n=new Date(e);return n.setDate(e.getDate()+6),{min:t.toSerialDate(e),max:t.toSerialDate(n)}}case`thisMonth`:return{min:t.toSerialDate(new Date(o,s,1)),max:t.toSerialDate(new Date(o,s+1,0))};case`lastMonth`:return{min:t.toSerialDate(new Date(o,s-1,1)),max:t.toSerialDate(new Date(o,s,0))};case`nextMonth`:return{min:t.toSerialDate(new Date(o,s+1,1)),max:t.toSerialDate(new Date(o,s+2,0))};case`M1`:case`M2`:case`M3`:case`M4`:case`M5`:case`M6`:case`M7`:case`M8`:case`M9`:case`M10`:case`M11`:case`M12`:{let e=parseInt(n.substring(1))-1;return{min:t.toSerialDate(new Date(o,e,1)),max:t.toSerialDate(new Date(o,e+1,0))}}case`Q1`:return this._quarterRange(t,o,0);case`Q2`:return this._quarterRange(t,o,1);case`Q3`:return this._quarterRange(t,o,2);case`Q4`:return this._quarterRange(t,o,3);case`thisQuarter`:{let e=Math.floor(s/3);return this._quarterRange(t,o,e)}case`lastQuarter`:{let e=Math.floor(s/3)-1,n=e<0?o-1:o,r=e<0?3:e;return this._quarterRange(t,n,r)}case`nextQuarter`:{let e=Math.floor(s/3)+1,n=e>3?o+1:o,r=e>3?0:e;return this._quarterRange(t,n,r)}case`lastYear`:return{min:t.toSerialDate(new Date(o-1,0,1)),max:t.toSerialDate(new Date(o-1,11,31))};case`yearToDate`:return{min:t.toSerialDate(new Date(o,0,1)),max:i};default:return{min:1/0,max:-1/0}}}_quarterRange(e,t,n){let r=3*n;return{min:e.toSerialDate(new Date(t,r,1)),max:e.toSerialDate(new Date(t,r+3,0))}}},TopN:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.TopN,title:(0,n.messageKey)(`condition.operator.topN.title`),acceptTypes:[t.InteropScalarType.Number],paramType:`topN`,description:(0,n.messageKey)(`condition.operator.topN.desc`)})}createPredicate(e,t){let n=t.getRange().getStats(),r=e?.top??!0,i=e?.limit??10;if(e?.percent){let e=n.getAggregates().numericalCount;if(!e)return CD;i=Math.max(1,Math.floor(i/100*e))}else if(i<1)return CD;let a=n.getSortedNumbers(),o=r?a.getLarge(i):a.getSmall(i);return o===null?wD:r?e=>e>=o:e=>e<=o}validateParam(e,t){let r=e?.limit??10;return e?.percent?Number.isInteger(r)&&r>=1&&r<=100?null:(0,n.messageKey)(`condition.error.topNPercent`):Number.isInteger(r)&&r>=1&&r<=1e3?null:(0,n.messageKey)(`condition.error.topNItems`)}createDefaultParam(e){return{top:!0,limit:10,percent:!1}}toString(e,t){let r={...this.createDefaultParam(t),...e};return(0,n.t)(`condition.operator.topN.toString`,{edge:r.top?`top`:`bottom`,limit:r.limit??10,unit:r.percent?`percent`:`items`})}},And:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.And,title:(0,n.messageKey)(`condition.operator.and.title`),description:(0,n.messageKey)(`condition.operator.and.desc`)})}isCombinator(){return!0}async createPredicate(e,t){let n=e?e.length:0,r=Array(n),i=[];for(let a=0;a<n;a++){let n=e[a],o=await t.resolveInput(n);r[a]=await o.getSelector()?.createTransformer(t);let s=await o.getOperator().createPredicate(o.getParam(),t);s&&i.push(s)}let a=i.length;return n>0&&a===0?null:e=>{for(let n=0;n<a;n++)if(!(0,i[n])(e,t))return!1;return!0}}validateParam(e,t){for(let t of e??[]){let e=zD.resolveInput(t)?.validate()??null;if(e)return e}return null}toString(e,t){let n=this.getTitle();if(!e)return n;let r=``,i=e.length,a=n.toLowerCase();for(let t=0;t<i;t++){let n=e[t],i=zD.resolveInput(n),o=i.getOperator(),s=o.toString(i.getParam(),i.getSelector())??o.getTitle?.()??``;r.length>0&&(r+=` ${a} `),r+=`${s}`}return r}},Or:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Or,title:(0,n.messageKey)(`condition.operator.or.title`),description:(0,n.messageKey)(`condition.operator.or.desc`)})}isCombinator(){return!0}async createPredicate(e,t){let n=e?e.length:0,r=Array(n),i=[];for(let a=0;a<n;a++){let n=e[a],o=await t.resolveInput(n);r[a]=await o.getSelector()?.createTransformer(t);let s=await o.getOperator().createPredicate(o.getParam(),t);s&&i.push(s)}let a=i.length;return n>0&&a===0?null:e=>{for(let n=0;n<a;n++)if((0,i[n])(e,t))return!0;return!1}}validateParam(e,t){for(let t of e??[]){let e=zD.resolveInput(t)?.validate()??null;if(e)return e}return null}toString(e,t){let n=this.getTitle();if(!e)return n;let r=``,i=e.length,a=n.toLowerCase();for(let t=0;t<i;t++){let n=e[t],i=zD.resolveInput(n),o=i.getOperator(),s=o.toString(i.getParam(),i.getSelector())??o.getTitle?.()??``;r.length>0&&(r+=` ${a} `),r+=`${s}`}return r}},Not:new class extends xv{constructor(){super({name:Y.BuiltInOperatorNames.Not,title:(0,n.messageKey)(`condition.operator.not.title`),description:(0,n.messageKey)(`condition.operator.not.desc`)})}isCombinator(){return!0}async createPredicate(e,t){let n=await t.resolveInput(e);await n.getSelector()?.createTransformer(t);let r=await n.getOperator().createPredicate(n.getParam(),t);return r?e=>!r(e,t):null}validateParam(e,t){return e?zD.resolveInput(e)?.validate()??null:null}toString(e,t){let r=this.getTitle();if(!e)return r;let i=zD.resolveInput(e),a=i.getOperator();return(0,n.t)(`condition.operator.not.toString`,{title:r,condition:a.toString(i.getParam(),i.getSelector())??a.getTitle?.()??r})}}};Ai();var ED=class{constructor(e){this._name=e.name,this._title=e.title,this._description=e.description,this._type=e.type??null,this._inputType=e.inputType??this._type,this._defaultCondition=e.defaultCondition??null,this._renderingHints=null,e.renderingHints&&(Array.isArray(e.renderingHints)?this._renderingHints=Object.freeze([...e.renderingHints]):this._renderingHints=Object.freeze([e.renderingHints]))}createTransformer(e){return null}getName(){return this._name}getSelectType(){return this._type}getInputType(){return this._inputType}getTitle(){return this._title?(0,n.t)(this._title):n.CommonUtils.camelToPrettyCase(this.getName())}getDescription(){return this._description?(0,n.t)(this._description):(0,n.t)(`condition.selector.ruleDescription`,{title:this.getTitle()})}getRenderHints(){return this._renderingHints}getDefaultCondition(e){let t=this._defaultCondition;return t?t.param===void 0?{operator:t.operator}:{operator:t.operator,param:structuredClone(t.param)}:null}},DD=new v_({max:16}),OD=null,kD=!1,AD=void 0,jD=null;function MD(e,t,n,r,i){let a=function(e,t,n){if(jD!==null&&e===OD&&t===kD&&n===AD)return jD;let r=`${+!!t}|${n??``}|${typeof e==`number`?`#`+e:e}`,i=DD.get(r);return i||(i=new v_({max:1024}),DD.set(r,i)),OD=e,kD=t,AD=n,jD=i,i}(t,r,i),o=a.get(n);if(o)return o;let s=e.format(t,n,{date1904:r,locale:i,placeholders:!0});return a.set(n,s),s}function ND(e,n,r){if(n==null)return``;let i=typeof n;if(i===`boolean`)return Ci(n);if(i!==`number`&&i!==`string`)return t.FormulaError.isError(n)?wi(n):`(Rich Object)`;if(!r)return``;if(r===`General`){if(i===`string`)return n;if(Number.isInteger(n)&&n>-1e11&&n<1e11)return String(n)}let a=``;try{a=MD(Hl(),r,n,e?.isDate1904()??!1,e?.getLocale()??void 0).text}catch{return``}return a===null?`#####`:i===`string`?a:a.replaceAll(`\xA0`,` `)}var PD=Object.freeze({displayText:``,conditionalColor:null,repeatChars:n.CommonUtils.EmptyArray,spacingChars:n.CommonUtils.EmptyArray,errorPlaceholder:null,formattedRuns:Object.freeze({runs:n.CommonUtils.EmptyArray,length:0,width:0,lastRepeatIndex:-1}),canWrap:!1,asDate:null,isDateFormat:!1,isTimeFormat:!1});function FD(e,r,i,a,o,s){if(r==null)return PD;let l=``,u=null,d=null,f=null,p=null,m=Hl();if(a===t.ScalarType.Error)l=wi(r);else if(a===t.ScalarType.RichData)l=`(Rich Object)`;else if(a===t.ScalarType.Boolean)l=Ci(r);else if(o)try{let t=MD(m,o,r,e?.isDate1904()??!1,e?.getLocale()??void 0);l=t.text,d=t.fills??null,f=t.skips??null,p=t.color}catch(e){console.warn(`Invalid formatCode: `+l,o,e)}let h=m.isDateFormat(o),g=m.isTimeFormat(o),_=h||g?dl(r,e?.isDate1904()??!1):null;l===null&&(u=`#`,l=u.repeat(5));let v=null,y=i.getAlignment(),b=y.getHorizontal(),x=y.getVertical(),S=y.getOverflow(),C=!(a!==t.ScalarType.String||b===c.HorizontalAlignment.Fill||d!==null&&d.length!==0||S!==c.Overflow.Wrap&&b!==c.HorizontalAlignment.Justify&&b!==c.HorizontalAlignment.Distributed&&x!==c.VerticalAlignment.Justify&&x!==c.VerticalAlignment.Distributed),w=l;C||a!==t.ScalarType.String||(w=w.replaceAll(/\n/g,``));let T=f?f.length:0,E=d?d.length:0,D=T>0||E>0;if(S!==c.Overflow.Wrap||D){let e=i.getFont(),t=e.getSize();e.isSuperSub()&&(t*=e.getSuperSubScale());let n=[];for(let e=0;e<T;e++){let r=f[e],a=i.measureText(r.char,t).width;n.push({...r,type:`spacing`,width:a})}if(E>0){let e=d[E-1],r=i.measureText(e.char,t).width;n.push({...e,type:`repeat`,width:r})}n=n.sort((e,t)=>e.offset-t.offset);let r=[],a=0,o=0,s=-1,c=-1,l=e=>{let n={type:`text`,width:i.measureText(e,t).width,text:e};r.push(n),o+=n.width,a+=e.length},u=n.length;for(let e=0;e<u;e++){let t=n[e];if(c!==t.offset){let e=w.substring(a,t.offset);e&&l(e)}let i={type:t.type,width:t.width,text:t.char};t.type===`repeat`?s=r.length:o+=i.width,r.push(i),c=t.offset}if(a<w.length){let e=w.substring(a,w.length);e&&l(e)}v={runs:Object.freeze(r),length:a,width:o,lastRepeatIndex:s}}let O={displayText:l??``,conditionalColor:p?s(p):null,repeatChars:d??n.CommonUtils.EmptyArray,spacingChars:f??n.CommonUtils.EmptyArray,errorPlaceholder:u,formattedRuns:v,canWrap:C,asDate:_,isDateFormat:h,isTimeFormat:g};return Object.freeze(O)}function ID(e){let t=typeof e==`number`?Number(e.toPrecision(15)):e,r=n.CommonUtils.castToString(t),i=r.indexOf(`e`);if(i===-1)return r;let a=r.substring(i+2);return`${r.substring(0,i)}E${r[i+1]}${a.length<2?`0`+a:a}`}function LD(e,n){if(e==null)return``;switch(n){case t.ScalarType.Number:return ID(e);case t.ScalarType.Boolean:return Ci(e);case t.ScalarType.Error:{let n=e;return typeof n?.getLabel==`function`?wi(n):t.FormulaError.Label.Unknown}}return``+e}var RD={List:new class extends ED{constructor(e){super({renderingHints:`list`,...e})}get isList(){return!0}getDefaultCondition(e){let t=Y.BuiltInOperatorNames.InSet,n=e?.ranges;if(!n||n.isInvalid())return{operator:t};let r=n.getStats().getFrequencies({limit:65,filterFn:e=>typeof e==`string`&&e!==``||typeof e==`number`||typeof e==`boolean`});if(r.isTruncated()||r.getUniqueCount()===0||r.getUniqueCount()>64)return{operator:t};let i=[];for(let[e]of r.getValueCounts({sortBy:`value`,descending:!1}))i.push(LD(e,IH(e)));let a=rD(i);return a===null?{operator:t}:{operator:t,param:{items:a}}}}({name:Y.BuiltInSelectorNames.List,title:(0,n.messageKey)(`condition.selector.list.title`),type:null,description:(0,n.messageKey)(`condition.selector.list.desc`)}),Logical:new ED({name:Y.BuiltInSelectorNames.Logical,title:(0,n.messageKey)(`condition.selector.logical.title`),type:t.InteropScalarType.Boolean,description:(0,n.messageKey)(`condition.selector.logical.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.EqualTo,param:!0}}),DateTime:new ED({name:Y.BuiltInSelectorNames.DateTime,title:(0,n.messageKey)(`condition.selector.dateTime.title`),type:t.InteropScalarType.Date,description:(0,n.messageKey)(`condition.selector.dateTime.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.Between}}),Date:new class extends ED{constructor(){super({name:Y.BuiltInSelectorNames.Date,title:(0,n.messageKey)(`condition.selector.date.title`),type:t.InteropScalarType.Date,inputType:t.InteropScalarType.Date,description:(0,n.messageKey)(`condition.selector.date.desc`),renderingHints:[`date`,`calendar`],defaultCondition:{operator:Y.BuiltInOperatorNames.Between}})}createTransformer(e){return e=>Math.floor(e)}},Time:new class extends ED{constructor(){super({name:Y.BuiltInSelectorNames.Time,title:(0,n.messageKey)(`condition.selector.time.title`),type:t.InteropScalarType.Date,inputType:t.InteropScalarType.Date,description:(0,n.messageKey)(`condition.selector.time.desc`),renderingHints:[`time`,`clock`],defaultCondition:{operator:Y.BuiltInOperatorNames.Between}})}createTransformer(e){return e=>e-Math.floor(e)}},Text:new ED({name:Y.BuiltInSelectorNames.Text,title:(0,n.messageKey)(`condition.selector.text.title`),type:t.InteropScalarType.String,description:(0,n.messageKey)(`condition.selector.text.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.TextContains}}),TextLength:new class extends ED{constructor(){super({name:Y.BuiltInSelectorNames.TextLength,title:(0,n.messageKey)(`condition.selector.textLength.title`),type:t.InteropScalarType.Number,inputType:t.InteropScalarType.String,description:(0,n.messageKey)(`condition.selector.textLength.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.Between}})}createTransformer(e){return e=>e?.length??0}},Number:new ED({name:Y.BuiltInSelectorNames.Number,title:(0,n.messageKey)(`condition.selector.number.title`),type:t.InteropScalarType.Number,description:(0,n.messageKey)(`condition.selector.number.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.Between}}),Whole:new class extends ED{constructor(){super({name:Y.BuiltInSelectorNames.Whole,title:(0,n.messageKey)(`condition.selector.whole.title`),type:t.InteropScalarType.Number,inputType:t.InteropScalarType.Number,description:(0,n.messageKey)(`condition.selector.whole.desc`),defaultCondition:{operator:Y.BuiltInOperatorNames.Between}})}createTransformer(e){return e=>Math.floor(e)}}},zD=class{constructor(e,t,n=void 0,r=!1){this._selector=e,this._operator=t,this._param=n,this._includeBlanks=r}getSelector(){return this._selector}getOperator(){return this._operator}getParam(){return this._param??null}isIncludeBlanks(){return this._includeBlanks}validate(){return this._operator?.validateParam?.(this.getParam(),this._selector)??null}toString(){let e=this._selector,t=this._operator,r;if(t&&(r=t.toString?.(this.getParam(),e)??t.getTitle?.()??n.CommonUtils.camelToPrettyCase(t.getName())),!e)return r??(0,n.t)(`condition.anySelector`);let i=e.getTitle();return r?(0,n.t)(`condition.selectorWithOperator`,{selector:i,operator:r}):i}toJSON(){let e=this.getOperator(),t=this.getSelector(),n=this.getParam(),r={};return t&&(r.selector=t.getName()),e&&(r.operator=e.getName()),n!=null&&(typeof n.toJSON==`function`&&(n=n.toJSON()),r.param=qE(n)),this.isIncludeBlanks()&&(r.includeBlanks=!0),r}get isICondition(){return!0}};function BD(e,t,n,r){let i=zE.parse(e,{anchor:t});if(!i)return e;let a=zE.transform(i,function(e,t){let n=e.toLowerCase();return e=>{if(e.type===`tableReference`&&typeof e.value==`string`&&e.value.toLowerCase()===n)return{...e,value:t}}}(n,r));return a===i?e:zE.image(a,{at:t})}(function(e){let t=e.BuiltInSelectors=RD,n=e.BuiltInOperators=TD;e.parseListLiteral=nD,e.formatListLiteral=rD,e.Selectors=new C(t),e.Operators=new C(n),e.resolveInput=oD,e.fromJSON=cD})(zD||={});var VD=`Item has been closed. No further operations are allowed.`,HD=(e=(0,n.messageKey)(`op.update`))=>(0,n.t)(`error.anchor.protected`,{description:(0,n.t)(e)}),UD=class{constructor(e){this._closed=!1,this._range=null,this._ranges=null,this._rangeAnchor=void 0,this._rangesAnchor=void 0,this._options=e,e=this._initializeOptions(e),this._options=e;let t=this;this._transactions=this._options.transactions??new g({transient:!0}),this._id=this._transactions.create(),this._emitter=new x(this,this._transactions);let r=this._options.coords;r=Array.isArray(r)?n.CoordUtils.sanitizeRangeArray(r):n.CoordUtils.sanitizeRange(r),this._options.setContainerCallbacks?.({processShift:e=>t._processContainerShift(e),processAfterShift:(e,n)=>t._processAfterContainerShift(e,n),processDelete(){t._processContainerDelete()},processLayout(){t._processContainerLayout()},processProtection(){t._processContainerProtection()}}),this._transactionsRemoveListener=this._transactions.addStateListener(this._id,{onBeforeCommitStart(e,n){t._processBeforeCommitStart(e,n)},onAfterStateChange(e,n,r,i){t._processAfterStateChange(e,n,r,i)},onRestoreOrRevert(e,n){t._processRestoreOrRevert(e,n)}}),this._updateState({isDeleted:!1,anchorCoords:r},(0,n.messageKey)(`op.createAnchoredItem`)),this._initialize(e)}_initializeOptions(e){if(!e)throw Error(`Anchored.ConstructorOptions is required`);if(!(e={...e}).coords)throw Error(`coords is required`);return e}_initialize(e){}_getEmitter(){return this._emitter}delete(e){this._delete()}isProtected(){return this._options.isProtected?.()??!1}getAnchorCoords(){let e=this._getState()?.anchorCoords;return e?Array.isArray(e)?e.length===0?null:e:[e]:null}getFirstAnchorCoords(){let e=this._getState()?.anchorCoords;return e?Array.isArray(e)?e[0]??null:e:null}_invalidateRangeCache(){this._range=null,this._ranges=null}_isAnchorAbsolute(){return!1}getRanges(e){if(!e&&this._ranges&&(this._closed||this._rangesAnchor===this._getState()?.anchorCoords))return this._ranges;let t=this._getState()?.anchorCoords,n=t?this._options.getRanges(t,e):new HV(null);return t&&this._isAnchorAbsolute()&&(n=n.getFixed(!0)),e||(this._ranges=n,this._rangesAnchor=t),n}getRange(e){if(!e&&this._range&&(this._closed||this._rangeAnchor===this._getState()?.anchorCoords))return this._range;let t=this.getRanges(e),n=t.isInvalid()?VV:t.at(0);return e||(this._range=n,this._rangeAnchor=this._rangesAnchor),n}_setAnchorRanges(e,t){let r=this._options.getRanges(e).getCoords();if(r.length===0)throw new n.ExpectedError((0,n.t)(`error.address.noAddress`));let i=this._options.setContainerCoords;return i?(i(e,t),this):(this._updateState({anchorCoords:[...r]},{description:(0,n.messageKey)(`op.setRanges`),...t}),this._processAnchorCoords(),this._emitter.notify(`onAnchorCoordsChange`),this)}getAnchorType(){return this._getState()?.anchorType??ev.Type.TwoCell}getId(){return this._id}getVersionId(){return this._transactions.getVersionId(this._id)}beginCommit(e){return this._beginCommit(e)}doBatch(e,t){let n=this;return this._transactions.doBatch(e,typeof t==`string`?{description:t}:t,e=>{n._processTransactionDone(e)})}_processTransactionDone(e){}_getState(){if(this._closed)throw Error(VD);return this._transactions.getState(this._id)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_getTransactions(){return this._transactions}_updateState(e,t,r,i=!1){if(this._closed)throw Error(VD);if(!e)return;if(typeof t==`string`&&(t={description:t}),!i&&this.isProtected())throw new n.ProtectedError(HD(t?.description));let a=this._beginCommit(t?.description);e&&`anchorCoords`in e&&this._invalidateRangeCache();try{let t=this._getState(),n=a.updateState(this._id,e);this._notify(r??void 0),this._processUpdateState(t,n),a.commit()}catch(e){throw a.rollback(),e}return this}_notify(e){if(!e)return;Array.isArray(e)||(WD[0]=e,e=WD);let t=e?e.length:0;if(t===0)return;let n=this._isAnyChangeFromState();for(let n=0;n<t;n++){let t=e[n];t!==`onAnyChange`&&this._emitter.notify(t)}n||this._emitter.notify(`onAnyChange`)}_isAnyChangeFromState(){return!1}_processAfterContainerShift(e,t){let r=t?t.length:0;if(!GD(this._getState()?.anchorCoords,t)){let e=null,i={anchorCoords:r===0?null:t};r===0&&(i.isDeleted=!0,e=[`onDelete`]),this._updateState(i,{description:(0,n.messageKey)(`op.updateAnchor`)},e),this._processAnchorCoords()}this._emitter.notify(`onAnchorCoordsChange`)}_processContainerShift(e){let t=this._getState()?.anchorCoords;if(Array.isArray(t)&&t.length>1)return e.after;let r=null,i={anchorCoords:e.after};return e.after||(i.isDeleted=!0,r=[`onDelete`]),this._updateState(i,{description:(0,n.messageKey)(`op.updateAnchor`)},r),this._processAnchorCoords(),e.after}_processBeforeCommitStart(e,t){}_processAfterStateChange(e,t,n=!1,r=!1){}_processUpdateState(e,t){}_processRestoreOrRevert(e,t){this._invalidateRangeCache(),this._emitter.notify(`onInvalidated`)}_processAnchorCoords(){this._invalidateRangeCache()}_processContainerLayout(){}_getActionDescription(e){return null}_delete(){if(this._getState().isDeleted)return;let e={description:this._getActionDescription(`delete`)??(0,n.messageKey)(`op.delete`)},t=this._beginCommit(e?.description);try{this._processDelete(),this._updateState({isDeleted:!0}),this._options.deleteFromContainer?.(e),t.commit()}catch(e){throw t.rollback(),e}}_processContainerDelete(){this._processAnchorCoords(),this._processDelete()}_processDelete(){this._invalidateRangeCache(),this._emitter.notify(`onDelete`)}_processContainerProtection(){this._emitter.notify(`onProtectedChange`)}addListeners(e,t){return this._emitter.addListeners(e,t)}isClosed(){return this._closed}isDeleted(){return this._closed||(this._getState()?.isDeleted??!1)}_processClose(){this._closed=!0,this._invalidateRangeCache(),this._emitter.notify(`onClose`),this._transactionsRemoveListener?.(),this._transactions.remove(this._id)}close(){this._closed||this._processClose()}get isIAnchored(){return!0}},WD=[null],GD=(e,t)=>{let r=t?t.length:0;if(!e)return r===0;let i=Array.isArray(e)?e:[e];if(i.length!==r)return!1;for(let e=0;e<r;e++)if(!n.CoordUtils.isEqualRanges(i[e],t[e]))return!1;return!0};function KD(e,t,r){let i=(0,n.t)(e,r);return i===e?t:i}function qD(e=1){return KD((0,n.messageKey)(`table.defaultName`),`Table${e}`,{n:e})}function JD(){return KD((0,n.messageKey)(`table.emptyColumnName`),`Column`)}function YD(e,t){return`${e}${t+1}`}function XD(e){return e?e.toLocaleLowerCase():null}var ZD=Object.freeze({showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1}),QD=new Map([[`average`,101],[`countnums`,102],[`count`,103],[`max`,104],[`min`,105],[`product`,106],[`stddev`,107],[`stddevp`,108],[`sum`,109],[`var`,110]]);function $D(e){if(e==null)return;if(typeof e==`number`)return Number.isInteger(e)?e:void 0;let t=e.trim();if(t.startsWith(`=`)&&(t=t.substring(1).trim()),!t)return;let n=t.toLowerCase();return n!==`none`&&n!==`custom`?QD.get(n)??t:void 0}function eO(e){return fS(e)}function tO(e,t,n){let r=nO.exec(e);if(!r)return null;let i=parseInt(r[1]);if(!(typeof(a=i)==`number`&&Number.isInteger(a)&&a>=101&&a<=110))return null;var a;let o=r[2].trim().toLocaleLowerCase(),s=new Set([`[${eO(n)}]`.toLocaleLowerCase(),`[${n}]`.toLocaleLowerCase()]);for(let e of s)if(o===e||o===t.toLocaleLowerCase()+e)return i;return null}var nO=/^\s*SUBTOTAL\(\s*(\d{3})\s*,(.+)\)\s*$/i;function rO(e){if(!e)return n.CommonUtils.EmptyArray;let t=e.length,r=e;for(let n=0;n<t;n++){let t=e[n];if(typeof t==`string`){r===e&&(r=[...e]),r[n]={name:t};continue}let i=t?.totalsRowFormula;if(i===void 0)continue;let a=$D(i);if(a===i)continue;r===e&&(r=[...e]);let o={...t};a===void 0?delete o.totalsRowFormula:o.totalsRowFormula=a,r[n]=o}return r}var iO=(e,t=JD(),n=YD)=>{let r=new Set,i=e.length;for(let t=0;t<i;t++){let n=e[t]?.name;if(!n)continue;let i=XD(n);r.add(i)}let a=-1,o=XD(t);return()=>{let e;do a++,e=n(o,a);while(r.has(e));return a}};function aO(e,t,n=0,r,i=JD(),a=YD){let o=e?e.length:0,s=rO(e),c=t?t.length:0,l=rO(t),u=Math.max(c,o),d=Array(u);for(let e=0;e<u;e++){let t=e>=n?l[e-n]:void 0;t===void 0&&(t=s[e]),d[e]=t}let f=0,p=0,m=0,h=0,g=!0,_=iO(d,i),v=new Map;for(let e=0;e<n;e++){let t=d[e]?.name,n=XD(t);n&&v.set(n,1)}let y,b,x=n+c;for(let e=n;e<u;e++){let t=d[e],n=t?.name,o=n,c=XD(o);if(c)h++,y=c,b=n,g=!1;else{if(e>=x&&(h=0,m=0),g||(m=h),r||m<=1){let t=_();o=a(i,t),o!==s[e]?.name&&(p=t+1),c=XD(o)}else f++,c=y,o=b;h=0,g=!0}let l=v.get(c)??0;l===1&&(l+=Math.max(0,Math.max(p+f,m)-1)),l>0&&(o=a(o,l)),l++,v.set(c,l),o!==n&&(d[e]={...t,name:o})}return d}function oO(e,t){return n.CommonUtils.isEqualArrays(e,t,(e,t)=>n.CommonUtils.deepEqual(e,t))}var sO=class{constructor(e,t,n,r,i,a,o){this._table=e,this._id=t,this._getProps=n,this._updateProps=r,this._deleteSelf=i,this._getTotals=a,this._getCalculated=o}_totals(){return this._getTotals?.(this._id)??this._getProps(this._id)}getTable(){return this._table}getName(){return this._getProps(this._id).name??null}setName(e){return this._updateProps(this._id,{name:e},(0,n.messageKey)(`op.setColumnName`)),this}getId(){return this._getProps(this._id).id??null}getIndex(){return this._getProps(this._id).index??-1}setTotalsRowLabel(e){return this._updateProps(this._id,{totalsRowLabel:e},(0,n.messageKey)(`op.setTotalsRowLabel`)),this}getTotalsRowLabel(){return this._totals().totalsRowLabel||null}setTotalsRowFormula(e){return this._updateProps(this._id,{totalsRowFormula:e},(0,n.messageKey)(`op.setTotalsRowFormula`)),this}getTotalsRowFormula(){return this._totals().totalsRowFormula??null}getCalculatedFormula(){return this._getCalculated?this._getCalculated(this._id):this._getProps(this._id).calculatedColumnFormula??null}getSort(){return this._table.getSortAt(this._getProps(this._id).index)}getFilter(){return this._table.getFilterAt(this._getProps(this._id).index)}isHiddenButton(){return this._table.isHiddenButtonAt(this._getProps(this._id).index)}setHiddenButton(e){return this._table.setHiddenButtonAt(this._getProps(this._id).index,e),this}getRange(){let e=this._table.getRange(),t=e?.getCoords(),n=this._getProps(this._id).index;return e.getIntersect({colStart:t.colStart+n,rowStart:t.rowStart,colEnd:t.colStart+n,rowEnd:t.rowEnd})}delete(e){this._deleteSelf(this._id,e)}toJSON(){let e=n.CommonUtils.cloneObject(this._getProps(this._id));delete e.index,delete e.sortProps,delete e.filterProps,delete e.totalsRowLabel,delete e.totalsRowFormula;let t=this._totals();t.totalsRowLabel&&(e.totalsRowLabel=t.totalsRowLabel),t.totalsRowFormula!==void 0&&(e.totalsRowFormula=t.totalsRowFormula),delete e.calculatedColumnFormula;let r=this.getCalculatedFormula();return r&&(e.calculatedColumnFormula=r),e}get[Symbol.toStringTag](){return`[TableColumn]`}toString(){return this.getName()??``}get isIColumn(){return!0}},cO=class{constructor(e){this._closed=!1,this._options={...e};let t=this;this._transactions=this._options?.transactions??new g({transient:!0}),this._id=this._transactions.create({isDeleted:!1}),this._emitter=new x(this,this._transactions),e?.json&&this._fromJSON(e.json),this._options?.setContainerReadOnlyCallback?.(()=>{t._processOnContainerReadOnly()}),this._transactionsRemoveListener=this._transactions.addStateListener(this._id,{onAfterStateChange(e,n){t._processAfterStateChange(e,n)},onRestoreOrRevert(e,n){t._processRestoreOrRevert(e,n)}}),this._processInit()}_fromJSON(e){}isReadOnly(){return this._options.isReadOnly?.()??!1}isDeleted(){return this._getState().isDeleted??!1}getType(){return this._options.type}get isIModel(){return!0}_processTransactionDone(e){}_getActionDescription(e){return null}_getState(){if(this._closed)throw Error((0,n.t)(`error.model.modelClosed`));return this._transactions.getState(this._id)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_getTransactions(){return this._transactions}_updateState(e,t,n){return this._writeState(e,t,n,!1)}_amendState(e,t,n){return this._writeState(e,t,n,!0)}_writeState(e,t,r,i=!1){if(this._closed)throw Error((0,n.t)(`error.model.modelClosed`));if(!e)return this;let a=this._beginCommit(t?.description);try{a.updateState(this._id,e);let n=!1,o=r?r.length:0;for(let e=0;e<o;e++){let t=r[e];n||=t===`onAnyChange`,this._emitter.notify(t)}!n&&r&&o>0&&this._emitter.notify(`onAnyChange`),i?a.amend(t):a.commit(t)}catch(e){throw a.rollback(),e}return this}_getEmitter(){return this._emitter}_processInit(){}_processAfterStateChange(e,t){}_processRestoreOrRevert(e,t){this._emitter.notify(`onInvalidated`)}delete(e){this._getState().isDeleted||this._delete(e)}_delete(e){e={description:this._getActionDescription(`delete`)??(0,n.messageKey)(`op.delete`),...e};let t=this._beginCommit(e?.description);try{this._options.deleteFromContainer&&this._options.deleteFromContainer?.(e),this._processDelete(),t.commit()}catch(e){throw t.rollback(),e}}_processOnContainerDeleted(){this._processDelete()}_processDelete(){this._updateState({isDeleted:!0},void 0,[`onDelete`])}_processOnContainerReadOnly(){this._emitter.notify(`onReadOnlyChange`)}addListeners(e,t){return this._emitter.addListeners(e,t)}getId(){return this._id}getVersionId(){return this._transactions.getVersionId(this._id)}beginCommit(e){return this._beginCommit(e)}doBatch(e,t){let n=this;return this._transactions.doBatch(e,typeof t==`string`?{description:t}:t,e=>{n._processTransactionDone(e)})}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify(`onClose`),this._closed=!0,this._transactionsRemoveListener?.(),this._transactions.remove(this._id))}},lO=class extends cO{_fromJSON(e){let t={};if(t.name=e?.name??null,!t.name)throw Error((0,n.t)(`error.model.nameRequired`));t.comment=e?.comment??null,t.hidden=e?.hidden??!1,t.scope=e?.scope??null,this._updateState(t,{description:t.name?(0,n.t)(`op.createItemNamed`,{name:t.name}):(0,n.messageKey)(`op.createItem`)})}_toJSON(){let e=this._getState(),t={name:e.name};return e.comment&&(t.comment=e.comment),e.hidden&&(t.hidden=e.hidden),e.hidden&&(t.hidden=e.hidden),e.scope&&(t.scope=e.scope),t}getName(){return this._getState().name}setName(e,t){if(!e)throw Error((0,n.t)(`error.model.nameRequired`));return this._updateState({name:e},{description:(0,n.t)(`op.updateNamed`,{name:e}),...t})}getComment(){return this._getState().comment}setComment(e,t){return this._updateState({comment:e},{description:(0,n.messageKey)(`op.setComment`),...t})}isHidden(){return this._getState().hidden}getScope(){return this._getState().scope}get isINamed(){return!0}},uO=class extends lO{constructor(e,t,n){super({...n,type:`namedTable`}),this._sheet=e,this._table=t;let r=this;this._table.addListeners({onDelete:()=>{r._options.deleteFromContainer?r._options.deleteFromContainer?.():r._delete()},onAnyChange:()=>{r._emitter.notify(`onAnyChange`)},onAnchorCoordsChange:()=>{r._emitter.notify(`onAnyChange`)}},{transactional:!0})}async select(e){return await this._table.select(e),this}getRanges(){let e=this._table;return(this._sheet.getWorkbook()??this._sheet).getRanges(e.getDataRange()).getFixed(!0)}getPartReference(e,t){if(e?.length!==1)return null;let n=e[0],r=this._table,i=r.getName(),a=this._sheet.getName();if(n.scope&&n.scope!==a)return null;let o=r.getRange().getCoords(),s=!!t&&(!t.scope||t.scope===a)&&t.rowIndex>=o.rowStart&&t.rowIndex<=o.rowEnd&&t.colIndex>=o.colStart&&t.colIndex<=o.colEnd;if(t&&n.rowStart===t.rowIndex&&n.rowEnd===t.rowIndex){let e=r.getDataRange().getCoords(),t=n.rowStart>=e.rowStart&&n.rowEnd<=e.rowEnd?this._columnSpan(n):null;if(t?.kind===`all`)return`${i}[@]`;if(t?.kind===`one`)return`${s?``:i}[@${eO(t.name)}]`;if(t?.kind===`span`)return`${i}[@[${eO(t.first)}]:[${eO(t.last)}]]`}let c=this._rowBand(n);if(!c)return null;let l=this._columnSpan(n);if(!l||l.kind===`all`&&c.length===1&&c[0]===`#Data`)return null;let u=l.kind!==`all`&&c.length===1&&c[0]===`#Data`?[]:c,d=null,f=null;l.kind===`one`?(d=eO(l.name),f=`[${d}]`):l.kind===`span`&&(d=f=`[${eO(l.first)}]:[${eO(l.last)}]`);let p=u.map(e=>`[${e}]`);return f&&p.push(f),p.length===1?u.length===1?`${i}[${u[0]}]`:`${s&&l.kind===`one`?``:i}[${d}]`:`${i}[${p.join(this._listSeparator())}]`}_rowBand(e){let t=this._table,n=e=>e?.getCoords()??null,r=t=>{let r=n(t);return!!r&&r.rowStart===e.rowStart&&r.rowEnd===e.rowEnd};if(r(t.getDataRange()))return[`#Data`];if(t.isShowHeaders()&&r(t.getHeaderRowRange()))return[`#Headers`];if(t.isShowTotals()&&r(t.getTotalRowRange()))return[`#Totals`];if(r(t.getRange()))return[`#All`];let i=n(t.getDataRange()),a=t.isShowHeaders()?n(t.getHeaderRowRange()):null,o=t.isShowTotals()?n(t.getTotalRowRange()):null;return i&&a&&e.rowStart===a.rowStart&&e.rowEnd===i.rowEnd?[`#Headers`,`#Data`]:i&&o&&e.rowStart===i.rowStart&&e.rowEnd===o.rowEnd?[`#Data`,`#Totals`]:null}_columnSpan(e){let t=this._table,n=t.getRange()?.getCoords();if(n&&e.colStart===n.colStart&&e.colEnd===n.colEnd)return{kind:`all`};let r=t.getColumns(),i=null,a=null;for(let t=0;t<r.length;t++){let n=r[t].getRange()?.getCoords();n&&(n.colStart===e.colStart&&(i=r[t]),n.colEnd===e.colEnd&&(a=r[t]))}return i&&a?i===a?{kind:`one`,name:i.getName()}:{kind:`span`,first:i.getName(),last:a.getName()}:null}_listSeparator(){return pt(this._sheet.getWorkbook()?.getLocale()??`en`).listSeparator}getScope(){return null}getType(){return`table`}getName(){return this._table.getName()}setName(e,t){return this._table.setName(e,t),this}getValue(){return this._table}},dO=class{constructor(e,t,n,r){this._table=e,this._id=t,this._getProps=n,this._getColumnProps=r}sort(e){this.setCriteria({reverse:e??!1},!1)}getCriteria(){return this._getProps(this._id).criteria??null}setCriteria(e,t,r){let i,a={};if(e&&(e.reverse!==void 0&&(a.reverse=e.reverse),e.collatorOptions!==void 0&&(a.collatorOptions=e.collatorOptions),e.sortOn!==void 0&&(a.sortOn=e.sortOn),e.iconSet!==void 0&&(a.iconSet=e.iconSet),e.iconId!==void 0&&(a.iconId=e.iconId),e.dxfId!==void 0&&(a.dxfId=e.dxfId),e.customList!==void 0&&(a.customList=e.customList)),t){let t=this._table.getActiveSorts(),o=t.length,s=this.getIndex(),c=!1,l=[];for(let e=0;e<o;e++){let n=t[e],r=n.getIndex(),i=r===s;c||=i,i||(l[e]={index:r,criteria:n.getCriteria()})}e!==null&&l.push({index:this.getIndex(),criteria:a}),i={sorts:l,description:(0,n.t)(`op.sortColumn`,{name:this._getColumnProps(this._id).name}),...r}}else i={sorts:[{index:this.getIndex(),criteria:a}],description:(0,n.t)(`op.sortColumn`,{name:this._getColumnProps(this._id).name}),...r};this._table.sort(i)}apply(){this._table.applySorts()}getIndex(){return this._getColumnProps(this._id).index}getRange(){let e=this._table,t=e.getRange(),n=t.getCoords(),r=e.isShowTotals(),i=n.colStart+this.getIndex();return t.getIntersect({colStart:i,rowStart:n.rowStart,colEnd:i,rowEnd:n.rowEnd-+!!r})}getLevel(){return this._getProps(this._id).level??-1}delete(e){this.getLevel()!==-1&&this.setCriteria(null,!0,{description:(0,n.messageKey)(`op.clearSort`),...e})}get isISort(){return!0}};function fO(e,t){let n=t.colStart,r=e.getRange({rowStart:t.rowStart,rowEnd:t.rowEnd,colStart:n,colEnd:n}),i=[];for(let e of r.getRegions(gv.Feature.NumberFormat)){let n=e.getCoords(),r=Math.max(n.rowStart,t.rowStart),a=Math.min(n.rowEnd,t.rowEnd);r<=a&&i.push({rowStart:r,rowEnd:a})}i.sort((e,t)=>e.rowStart-t.rowStart);let a=[],o=(t,r)=>{let i=(t=>{let r=e.getRange({rowStart:t,rowEnd:t,colStart:n,colEnd:n}).getCell().getStyle();return r.getNumberFormatRef?.()??r.getNumberFormat()})(t),o=a[a.length-1];o&&o.format===i&&o.rowEnd===t-1?o.rowEnd=r:a.push({rowStart:t,rowEnd:r,format:i})},s=t.rowStart;for(let e=0;e<i.length;e++){let t=i[e];t.rowEnd<s||(t.rowStart>s&&o(s,t.rowStart-1),o(Math.max(t.rowStart,s),t.rowEnd),s=t.rowEnd+1)}return s<=t.rowEnd&&o(s,t.rowEnd),a}function pO(e,t){let n=e.getRuntime(),r=new Map;return(i,a,o)=>{let s=r.get(a);s||(s={runs:fO(e,{...t,colStart:a,colEnd:a}),last:0},r.set(a,s));let c=s.runs,l=s.last;if(i<c[l].rowStart||i>c[l].rowEnd){let e=0,t=c.length-1;for(;e<t;){let n=e+t>>>1;c[n].rowEnd<i?e=n+1:t=n}l=e,s.last=l}return ND(n,o,c[l].format)}}async function mO(e,n,r){let i=hD(r),a=i.axis??t.IRange.Axis.Row,o=[],s=[];return await async function(e){let n=e.coords,r=e.axis??t.IRange.Axis.Row,i=r===t.IRange.Axis.Row,a=i?n.rowStart:n.colStart,o=i?n.rowEnd:n.colEnd;e.hasHeader&&(a+=1);let s=e.conditions,c=s?s.length:0,l=e.match===`value`?null:e.getText??null,u=[],d=e.getHiddenRuns;if(d){let t=e.includeHidden??!0;!0!==t&&t!==r&&(u=d(r).slice())}if(a<=o)for(let r=0;r<c;r++){let c=s[r],d=zD.resolveInput(c);if(!d)continue;let f=c?.index,p=typeof f==`number`?f:r,m=(i?n.colStart:n.rowStart)+p,h=i?{rowStart:a,rowEnd:o,colStart:m,colEnd:m}:{rowStart:m,rowEnd:m,colStart:a,colEnd:o},g=gD(u,a,o).map(e=>i?{rowStart:e.min,rowEnd:e.max,colStart:m,colEnd:m}:{rowStart:m,rowEnd:m,colStart:e.min,colEnd:e.max}),_={bounds:h,axis:i?t.IRange.Axis.Column:t.IRange.Axis.Row};if(u.length>0){let e=Lt(u);i?_.processRowSkip=e:_.processColumnSkip=e}let v=[],y=[],b=(e,t)=>{let n=i?e.rowIndex:e.colIndex;v.push(n),t&&y.push(n)};await pD(d,{runtime:e.runtime,values:e.values,coords:h,cellValuesOptions:_,calculation:e.calculation,visibleCoords:g,getText:l,onTrue:e=>b(e,!1),onFalse:e=>b(e,!0)});let x=Ot(y,!0);if(d.isIncludeBlanks())u=_D(u,x);else{let e=gD(_D(u,Ot(v,!0)),a,o);u=_D(u,x,e)}}if(a<=o){let t=e.onHiddenRun;if(t)for(let e=0;e<u.length;e++)t(u[e]);let n=e.onVisibleRun;if(n){let e=gD(u,a,o);for(let t=0;t<e.length;t++)n(e[t])}}}({runtime:e.getRuntime(),calculation:e._calculation,values:e._calcGrid.getValues(),coords:n,conditions:i.conditions,axis:a,hasHeader:i.hasHeader,includeHidden:i.includeHidden,match:i.match,getText:pO(e,n),getHiddenRuns:n=>uH(n===t.IRange.Axis.Row?e._rowHeaders:e._colHeaders),onVisibleRun:e=>{o.push({...e})},onHiddenRun:e=>{s.push({...e})}}),{axis:a,visibleRuns:o,hiddenRuns:s}}function hO(e,r,i){let a=i?.description??(0,n.messageKey)(`op.filter`),o=r.axis===t.IRange.Axis.Row?e._rowHeaders:e._colHeaders;r.visibleRuns.length>0&&o._setHidden(r.visibleRuns,!1,{description:a}),r.hiddenRuns.length>0&&o._setHidden(r.hiddenRuns,!0,{description:a})}var gO,_O=class{constructor(e,t,n,r,i){this._getHiddenByLevels=i,this._table=e,this._id=t,this._getProps=n,this._getColumnProps=r}filter(e,t){return this.setCondition(e,void 0,t)}getCondition(){return this._getProps(this._id).condition??null}async setCondition(e,t,r){let i=this.getIndex(),a=zD.resolveInput(e),o=a===null?null:{index:i,...a.toJSON()},s=[],c=!1;if(!t){let e=this._table.getActiveFilters(),t=e.length;for(let n=0;n<t;n++){let t=e[n],r=t.getIndex();if(r===i){o&&s.push(o),c=!0;continue}let a=t.getCondition();a&&s.push({index:r,...a.toJSON()})}}return o&&!c&&s.push(o),await this._table.filter({conditions:s},{description:(0,n.t)(`op.filterColumn`,{name:this._getColumnProps(this._id).name}),...r}),this}async apply(e){return await this._table.applyFilters(e),this}getIndex(){return this._getColumnProps(this._id).index}getRange(){let e=this._table.getDataRange(),t=e.getCoords(),n=t.colStart+this.getIndex();return e.getIntersect({...t,colStart:n,colEnd:n})}async getItems(e){let n=e?.limit??1e4,r=this.getRange(),i=r.getSheet(),a=i.getRuntime(),o=e=>e.length>0?{processRowSkip:Lt(e)}:void 0,s,c,l=this.getCondition()!==null;l?(s=o(await this._getHiddenByLevels(this.getIndex())),c=o(await this._getHiddenByLevels(null))):s={ignoreHidden:t.IRange.Axis.Row};let u=r.getCoords(),d=new Map,f=fO(i,u);for(let e=0;e<f.length;e++){let t=f[e],n=d.get(t.format);n||(n=[],d.set(t.format,n)),n.push({...u,rowStart:t.rowStart,rowEnd:t.rowEnd})}let p=[],m=new Map,h=!1,g=!1,_=!1,v=0;for(let[e,t]of d){let r=i.getRanges(t),o=r.getStats(s),u=o.getFrequencies({includeBlanks:!0,limit:n}),d=u;l&&(d=r.getStats(c).getFrequencies(u.isTruncated()?{includeBlanks:!0,filterFn:e=>u.getFrequency(e)>0}:{includeBlanks:!0})),_||=u.isTruncated(),v+=o.getSize();for(let t of u.getUniqueValues()){let n=d.getFrequency(t)>0;if(t===null||t===``){h=!0,g||=n;continue}let r=ND(a,t,e),i=u.getFrequency(t),o=m.get(r);if(o){o.count+=i,o.checked=o.checked||n;continue}let s={text:r,value:t,count:i,checked:n};m.set(r,s),p.push(s)}}if(d.size>1){let e=a.getLocaleProfile();p.sort((t,n)=>sa.compare(t.value,n.value,e))}return p.length>n&&(p.length=n,_=!0),{items:p,hasBlanks:h,blanksChecked:g,truncated:_,total:v}}getLevel(){return this._getProps(this._id).level??-1}async delete(e){return this.getLevel()===-1?this:this.setCondition(null,void 0,{description:(0,n.messageKey)(`op.deleteFilter`),...e})}get isIFilter(){return!0}},vO=`table.ownWrites`,yO=class extends UD{constructor(e){super(e)}_initializeOptions(e){let t=e?.coords;return Array.isArray(t)&&(e={...e,coords:t[0]}),super._initializeOptions(e)}initializeColumnCreator(e,t,n,r,i,a){return o=>new sO(e,o,t,n,r,i,a)}initializeSortCreator(e,t,n){return r=>new dO(e,r,t,n)}initializeFilterCreator(e,t,n){return r=>new _O(e,r,t,n,e=>this._hiddenByLevels(e))}async _hiddenByLevels(e){let t=this._filterLevels().filter(t=>t.index!==e);return t.length===0?[]:(await this._evalFilter({conditions:t}))?.hiddenRuns??[]}_initialize(e){super._initialize(e),this._emptyColumnName=JD(),this._emptyColumnNamer=YD,this._styles=e.styles??e?.sheet?.getStyles()??new ag,this._names=e?.names,this._sheet=e?.sheet,this._processTableUpdate=e?.processTableUpdate,this._symbolsChanged=e?.symbolsChanged,this._filteredChanged=e?.filteredChanged,this._setContainerName=e?.setContainerName,this._releaseReferences=e?.releaseReferences,this._refitBodyRows=e?.refitBodyRows,this._colHeadersSizeUnlistener=null,this._rowHeadersSizeUnlistener=null,this._headerListenerCoords=null,this._expandListenerCoords=null,this._heldTotals=new Map,this._heldCalculated=new Map,this._columnFacades=new Map,this._sortFacades=new Map,this._filterFacades=new Map,this._columnViews=null,this._visibleRange=null,this._isHeaderVisible=!0,this._isTotalVisible=!0,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0,this._styleCache=null,this._stylePropsCache=null,this._stylesRemoveListener=this._styles.getTableStyles().addListeners({onCollectionChange:()=>{this._onTableStylesChange()}});let t=e=>this._columnPropsOf(e);this._createColumn=this.initializeColumnCreator(this,t,(e,t,n)=>{this._updateColumnProps(e,t,n)},(e,t)=>{this._deleteColumn(e,t)},e=>this._totalsOf(e),e=>this._calculatedOf(e)),this._createSort=this.initializeSortCreator(this,e=>this._sortPropsOf(e),t),this._createFilter=this.initializeFilterCreator(this,e=>this._filterPropsOf(e),t),this._updateState({name:qD(),headerRowCount:1,totalsRowCount:0,totalsRowShown:!1,orderedColumnsProps:n.CommonUtils.EmptyArray,mapHiddenButtons:jO,lastColId:0,description:``},(0,n.messageKey)(`op.initializeTable`));let r=e?.sheet;if(r&&e?.syncSheet){let t=this._getState(),n=t.anchorCoords,r=t.headerRowCount,i=t.totalsRowCount;this._ensureHeightForHeaderTotals(n,r,i,e?.json?.headerRowCount||void 0,e?.hasTotals?void 0:e?.json?.totalsRowCount)}try{this._fromJSON(e?.json)}catch(e){throw console.error(`Error creating Table from JSON`,e),e}if(r){e?.syncSheet&&this._syncHeader({from:`sheet`,keepNameOnBlank:!0}),this._processExpandListener(),this._columnListener=e=>{e.isUndo||e.trigger===`data`&&this._getLiveState()&&this._notOwnWrites(e.getFrom().getCoords(),e.getTransactionId()).length!==0&&this._syncHeader({from:`sheet`})},this._processHeaderListener(),this._syncHeldTotals(),this._syncHeldCalculated();let t={onSizesChange:()=>{this._calcVisible()}};this._colHeadersSizeUnlistener=r.getColumnHeaders().addListeners(t),this._rowHeadersSizeUnlistener=r.getRowHeaders().addListeners(t),this._calcVisible()}if(this._names){let t=this._createNamed();t&&e.setContainerName?.(t.getName()),this._namedItem=t,e.symbolsChanged?.(this)}}getNamed(){return this._namedItem??null}_columnPropsOf(e){return this._views().byId.get(e)??NO}_views(){let e=this._getState()?.orderedColumnsProps??n.CommonUtils.EmptyArray,t=this._columnViews;if(t&&t.props===e)return t;let r=e.length,i=new Map,a=Array(r),o=new Map,s=new Map,c=[],l=[];for(let t=0;t<r;t++){let n=e[t];if(!n)continue;let r=n.id;i.set(r,n);let u=this._columnOf(r);a[t]=u,o.set(r,u),s.set(n.name.toLocaleLowerCase(),u),n.sortProps&&c.push(n),n.filterProps&&l.push(n)}c.sort((e,t)=>e.sortProps.level-t.sortProps.level),l.sort((e,t)=>e.filterProps.level-t.filterProps.level);let u={props:e,byId:i,columns:Object.freeze(a),columnsById:o,columnsByName:s,sorts:c.length===0?n.CommonUtils.EmptyArray:Object.freeze(c.map(e=>this._sortOf(e.id))),filters:l.length===0?n.CommonUtils.EmptyArray:Object.freeze(l.map(e=>this._filterOf(e.id)))};return this._columnViews=u,u}_columnOf(e){let t=this._columnFacades.get(e);return t||(t=this._createColumn(e),this._columnFacades.set(e,t)),t}_sortOf(e){let t=this._sortFacades.get(e);return t||(t=this._createSort(e),this._sortFacades.set(e,t)),t}_filterOf(e){let t=this._filterFacades.get(e);return t||(t=this._createFilter(e),this._filterFacades.set(e,t)),t}_sortPropsOf(e){return this._columnPropsOf(e).sortProps??FO}_filterPropsOf(e){return this._columnPropsOf(e).filterProps??IO}_onTableStylesChange(){this._styleCache=null,this._stylePropsCache=null,this._emitter.notify(`onStyleChange`),this._emitter.notify(`onAnyChange`)}_ensureVisible(){this._calcVisible()}_calcVisible(){let e=this.getFirstAnchorCoords(),t=this._sheet,n=0,r=0;e&&t&&(n=t.getColumnHeaders().getVisibleIndex(e.colEnd).min,r=t.getRowHeaders().getVisibleIndex(e.rowEnd).min);let i=this.isShowHeaders(),a=this.isShowTotals();if(e&&t&&(n<e.colEnd||r<e.rowEnd)){let o=t.getColumnHeaders(),s=t.getRowHeaders(),c=o.getVisibleIndex(e.colStart).max,l=s.getVisibleIndex(e.rowStart).max;this._visibleRange={colStart:c,colEnd:n,rowStart:l,rowEnd:r},this._isHeaderVisible=i&&!s.at(e.rowStart).isHidden(),this._isTotalVisible=a&&!s.at(e.rowEnd).isHidden(),this._isFirstColumnVisible=!o.at(e.colStart).isHidden(),this._isLastColumnVisible=!o.at(e.colEnd).isHidden()}else this._visibleRange=null,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0,this._isHeaderVisible=i,this._isTotalVisible=a}getSnapshot(e){let t=this.toJSON(),n=this.getFirstAnchorCoords(),r=this.getName(),i={...t},a=this,o=Object.freeze({...e}),s=!1;return{async copyTo(e,t){let c=e.tables,l=e.range,u={...o,...t},d={colStart:l.colStart,rowStart:l.rowStart,colEnd:n.colEnd-n.colStart+l.colStart,rowEnd:n.rowEnd-n.rowStart+l.rowStart};if(u.isCut&&!s&&!a.isDeleted()&&c===a._sheet?.getTables()){let e=c.getItems({address:d});if(e.length===0||e.length===1&&e[0]===a)return a._moveTo(d),d}return u.isCut&&!s&&(a.isDeleted()||a._remove(),s=!0),c.add(d,{properties:i,disabledAutofit:!0,hasHeader:!0,hasTotals:!0})._adoptPaste(r),d},getCoords:()=>n,getSource:()=>a,getName:()=>r,getMarkOptions:()=>o,isISnapshot:!0}}_adoptPaste(e){let t=this._sheet;t&&this._ownWrite(t.getEntireRange().getCoords(),()=>{this._retargetCopiedFormulas(e)})}_retargetCopiedFormulas(e){let t=this._sheet,n=this.getFirstAnchorCoords(),r=this.getName();if(!t||!n||r.toLowerCase()===e.toLowerCase())return;let i=[];for(let a of t.getRange(n).getRegions(gv.Feature.Formula)){let t=a.getCoords(),n=a.getCell().getFormulaText();if(!n)continue;let o=n.startsWith(`=`)?n.substring(1):n,s=BD(o,{rowIndex:t.rowStart,colIndex:t.colStart},e,r);s!==o&&i.push({coords:{...t},text:s})}for(let e=0;e<i.length;e++){let n=i[e];t.getRange(n.coords).setFormula(`=`+n.text)}}getAnchorType(){return ev.Type.TwoCell}getStyle(){if(this._styleCache)return this._styleCache;let e=this._getState(),t=this._styles.getTableStyles();if(!e)return t.getNone();let n=e.style.name;return this._styleCache=n?t.getByName(n)??t.getDefault():t.getNone(),this._styleCache}addRow(e,t){return this.addRows(e??2**53-1,1,t)}_ensureHeightForHeaderTotals(e,r,i,a,o){let s=this._sheet;if(!s)return!1;let c=e,l=a??r,u=l-r;if(l>r){let e=s.getEntireRange().getCoords().rowStart,r=c.rowStart-u,i={colStart:c.colStart,rowStart:r,colEnd:c.colEnd,rowEnd:c.rowStart-1};if(r<e){let n=e-r;i.rowStart=e,i.rowEnd=n-1,s.getRange(i).insert(t.IRange.Axis.Row),i.rowEnd=c.rowEnd+n,c=i}else{let e=s.getRange(i);if(c=n.CoordUtils.unionRanges(i,c),e.isContentful()){let n=e.getOffsetBy(u,0);n.insert(t.IRange.Axis.Row),i=n.getCoords(),c.rowStart+=u,c.rowEnd+=u}}}else if(u!==0){let e={...c};e.rowEnd=c.rowStart+u+1,this._ownWrite(e,()=>{s.getRange(e).clear()}),c={...c},c.rowStart-=u}let d=o??i,f=d-i;if(d>i){let e={colStart:c.colStart,rowStart:c.rowEnd+1,colEnd:c.colEnd,rowEnd:c.rowEnd+f},r=s.getRange(e);r.isContentful()&&r.insert(t.IRange.Axis.Row),c=n.CoordUtils.unionRanges(e,c)}else if(f!==0){let e={...c};e.rowStart=c.rowEnd+f+1,this._ownWrite(e,()=>{s.getRange(e).clear()}),c={...c},c.rowEnd+=f}let p=!n.CoordUtils.isEqualRanges(c,e);return p&&(this._updateState({anchorCoords:c}),this._options.setContainerCoords?.(c),this._calcVisible(),this._styleCache=null),u!==0&&this._processHeaderListener(),p||u!==0||f!==0}addRows(e,r=1,i){this._requireLive();let a=this._getState(),o={...a.anchorCoords},s=this._sheet,c=o.rowEnd,l=a.headerRowCount,u=a.totalsRowCount,d=c-o.rowStart+1-l-u;e=Math.max(0,Math.min(e??2**53-1,d));let f=o.rowStart+l+e,p=r>1?(0,n.messageKey)(`op.addTableRows`):(0,n.messageKey)(`op.addTableRow`),m=this._beginCommit({description:p,...i});try{if(s){let n={colStart:o.colStart,rowStart:f,colEnd:o.colEnd,rowEnd:f+r-1};s.getRange(n).insert(t.IRange.Axis.Row),e===0&&l===0&&this._setAnchor({...this._getState().anchorCoords,rowStart:o.rowStart},i,p)}(!s||f>c)&&this._resize({colStart:o.colStart,rowStart:o.rowStart,colEnd:o.colEnd,rowEnd:o.rowEnd+r},i),m.commit()}catch(e){throw m.rollback(),e}return this}deleteRowsAt(e,r=1,i){this._requireLive();let a=this._getState(),o={...a.anchorCoords},s=this._sheet,c=a.headerRowCount,l=o.rowStart+c+e,u=o.rowEnd-l+1;if(c>0&&u<0)throw new n.ExpectedError((0,n.t)(`error.table.tableNoBody`));r=Math.max(1,Math.min(r,u));let d=this._beginCommit({description:r>1?(0,n.messageKey)(`op.deleteTableRows`):(0,n.messageKey)(`op.deleteTableRow`),...i});try{if(s){let e={colStart:o.colStart,rowStart:l,colEnd:o.colEnd,rowEnd:l+r-1};s.getRange(e).delete(t.IRange.Axis.Row)}else this._resize({colStart:o.colStart,rowStart:o.rowStart,colEnd:o.colEnd,rowEnd:o.rowEnd-r},i);d.commit()}catch(e){throw d.rollback(),e}return this}_updateColumnProps(e,t,r){this._requireLive();let i=this._getState(),a=this._views().byId.get(e),o;if(r=typeof r==`string`?{description:r}:{description:(0,n.t)(`op.updateColumnNamed`,{name:a.name}),...r},t===null)o={id:a.id,index:a.index,name:a.name,sortProps:null,filterProps:null};else{if(t.id!==void 0&&t.id!==a.id)throw Error(`Table column ID is immutable and can not be changed.`);if(o={...a,...t},`totalsRowLabel`in t&&(t.totalsRowLabel?delete o.totalsRowFormula:delete o.totalsRowLabel),`totalsRowFormula`in t){let e=$D(t.totalsRowFormula);e===void 0?delete o.totalsRowFormula:(o.totalsRowFormula=typeof e==`string`?this._qualified(e,a.index):e,delete o.totalsRowLabel)}}let s=null;if(this._isTotalsOnSheet()){if(t===null||`totalsRowLabel`in t||`totalsRowFormula`in t){let t={};o.totalsRowLabel&&(t.totalsRowLabel=o.totalsRowLabel),o.totalsRowFormula!==void 0&&(t.totalsRowFormula=o.totalsRowFormula),OO(this._totalsOf(e),t)||(s=t)}delete o.totalsRowLabel,delete o.totalsRowFormula}let c=!xO(a,o);if(!c&&!s)return;let l=o.name!==a.name,u=this._beginCommit(r);try{if(c){let e=i.orderedColumnsProps,t=[...e];t[a.index]=o,l&&(t=aO(e,t,0,!0,this._emptyColumnName,this._emptyColumnNamer)),this._updateColumnsState(t)}l&&this._syncHeader({from:`table`}),s&&this._writeTotalsCellAt(a.index,s),this._syncHeldTotals(),this._syncHeldCalculated(),u.commit()}catch(e){throw u.rollback(),e}}_qualified(e,t){let n=this._sheet,r=n?this._getUsedCoords():null;if(!r||e.indexOf(`[`)===-1||n.getCalculation().getStatus()!==X.Status.Running)return e;let i=Math.min(r.colStart+t,r.colEnd);try{return n.getCalculation()._toStoredText(e,{rowIndex:r.rowStart,colIndex:i,scope:n.getId()})||e}catch{return e}}_isTotalsOnSheet(){return!!this._sheet&&this._getTotalCoords()!==null}_totalsOf(e){let t=this._columnPropsOf(e),n=this._sheet?this._getTotalCoords():null;if(!n||t.index===void 0){let n=this._readHeldTotal(e);return n===null?t:{totalsRowFormula:n}}let r=this._totalsCellAt(n,t.index).getCell();return this._readTotalsCell(r,t.name)??PO}_totalsCellAt(e,t){let n=e.colStart+t;return this._sheet.getRange({colStart:n,rowStart:e.rowStart,colEnd:n,rowEnd:e.rowStart})}_readTotalsCell(e,t){if(e.isFormulaHidden()&&e.getValue()!==null)return null;let n=e.getFormula()?.getExpression()??null;if(n)return{totalsRowFormula:tO(n,this.getName(),t)??n};let r=e.getValue();return r===null?PO:{totalsRowLabel:typeof r==`string`?r:e.getText()}}_writeTotalsCellAt(e,t){let n=this._sheet?this._getTotalCoords():null;if(!n)return;let r=this._totalsCellAt(n,e),i=t.totalsRowFormula;this._ownWrite(r.getCoords(),()=>{if(i!==void 0){let t=this._getState().orderedColumnsProps[e].name;r.setFormula(`=`+(typeof i==`number`?(n=i,a=t,`SUBTOTAL(${n},[${eO(a)}])`):i));return}var n,a;r.setValue(t.totalsRowLabel??null,{textParser:!1})})}_holdTotalsFromCells(){let e=this._sheet?this._getTotalCoords():null;if(!e)return;let t=this._getState().orderedColumnsProps,r=t.length,i=[...t],a=!1;for(let n=0;n<r;n++){let r=t[n];if(!r)continue;let o=this._readTotalsCell(this._totalsCellAt(e,n).getCell(),r.name);if(!o||OO(r,o))continue;let{totalsRowLabel:s,totalsRowFormula:c,...l}=r;i[n]={...l,...o},a=!0}a&&this._updateColumnsState(i,(0,n.messageKey)(`op.updateColumnsFromSheet`))}_syncHeldTotals(){let e=this._heldTotals,t=this._sheet,n=t?this._getLiveState():null,r=-1;if(n&&n.totalsRowCount===0&&t.getCalculation().getStatus()!==X.Status.Off){let e=n.anchorCoords.rowEnd+1;e<=t.getEntireRange().getCoords().rowEnd&&(r=e)}let i=null;if(r!==-1){let a=n.orderedColumnsProps,o=a.length;for(let s=0;s<o;s++){let o=a[s],c=o?.totalsRowFormula;if(typeof c!=`string`)continue;let l=o.id;(i??=new Set).add(l);let u=e.get(l),d=u?.text===c;if(u&&d){let e=u.host?u.host.getCoords():u.coords;if(e&&e.rowStart===r)continue}let f=(d?this._readHeldTotal(l):null)??c;u?.remove();let p=n.anchorCoords.colStart+s,m={colStart:p,rowStart:r,colEnd:p,rowEnd:r},h={text:c,coords:m,host:null,remove:null};h.remove=t.getRange(m)._addWatch(f,{onRegistered:e=>{h.host=e}}),e.set(l,h)}}if(e.size!==0)for(let[t,n]of[...e])i?.has(t)||(n.remove(),e.delete(t))}_readHeldTotal(e){let t=this._heldTotals.get(e)?.host,n=t?.getView(),r=t?.getCoords();if(!n||!r)return null;let i={rowIndex:r.rowStart,colIndex:r.colStart};return VE(n.getTextAt(i.rowIndex,i.colIndex),i,HE(this._sheet.getName()))||null}_removeHeldTotals(){for(let e of this._heldTotals.values())e.remove();this._heldTotals.clear()}_syncHeldCalculated(){let e=this._heldCalculated,t=this._sheet,n=t?this._getLiveState():null,r=n?this._getUsedCoords():null,i=null;if(r&&t.getCalculation().getStatus()!==X.Status.Off){let a=n.orderedColumnsProps,o=a.length;for(let n=0;n<o;n++){let o=a[n],s=o?.calculatedColumnFormula;if(!s)continue;let c=o.id;(i??=new Set).add(c);let l=r.colStart+n,u=e.get(c),d=u?.text===s;if(u&&d){let e=u.host?u.host.getCoords():u.coords;if(e&&e.colStart===l&&e.rowStart>=r.rowStart&&e.rowStart<=r.rowEnd)continue}let f=(d?this._readHeldCalculated(c):null)??s;u?.remove();let p={colStart:l,rowStart:r.rowStart,colEnd:l,rowEnd:r.rowStart},m={text:s,coords:p,host:null,remove:null};m.remove=t.getRange(p)._addWatch(f,{onRegistered:e=>{m.host=e}}),e.set(c,m)}}if(e.size!==0)for(let[t,n]of[...e])i?.has(t)||(n.remove(),e.delete(t))}_readHeldCalculated(e){let t=this._heldCalculated.get(e)?.host,n=t?.getView(),r=t?.getCoords(),i=this._getUsedCoords();if(!n||!r||!i)return null;let a={rowIndex:i.rowStart,colIndex:r.colStart};return VE(n.getTextAt(a.rowIndex,a.colIndex),a,HE(this._sheet.getName()))||null}_removeHeldCalculated(){for(let e of this._heldCalculated.values())e.remove();this._heldCalculated.clear()}_calculatedOf(e){let t=this._columnPropsOf(e).calculatedColumnFormula;return t?this._readHeldCalculated(e)??t:null}_calculatedTextAt(e,t){let n=this._sheet,r=this._getUsedCoords(),i=this._getLiveState()?.orderedColumnsProps[e],a=i?this._calculatedOf(i.id):null;if(!n||!r||!a)return null;if(t===r.rowStart)return a;let o={rowIndex:r.rowStart,colIndex:r.colStart+e};try{return n.getRange({colStart:o.colIndex,rowStart:o.rowIndex,colEnd:o.colIndex,rowEnd:o.rowIndex}).createFormula(a).shift({rowIndex:t,colIndex:o.colIndex})?.getExpression()??null}catch{return null}}_holdFirstShowTotals(){let e=this._sheet,r=this._getState(),i=this._getUsedCoords(),a=r.orderedColumnsProps,o=a.length-1,s=a[o];if(this._updateState({totalsRowShown:!0}),!e||!i||!s||s.totalsRowLabel||s.totalsRowFormula!==void 0)return;let c=!1,l=e.getRange({...i,colStart:i.colEnd}).forEach((e,n)=>{if(e!==null)return n.getInteropType()===t.InteropScalarType.Number?void(c=!0):{break:!0}}),u=[...a];u[o]={...s,totalsRowFormula:c&&!l?109:103},this._updateColumnsState(u,(0,n.messageKey)(`op.syncColumnsToSheet`))}_getTraverseRegion(e,r,i){if(r!==t.IRange.Axis.Row)return null;let a=this.getDataRange().getCoords(),o=this._sheet;if(i||!o)return a;let s=this.getAutoExpand();if(s!==Bf.AutoExpand.Both&&s!==Bf.AutoExpand.Rows)return a;let c=a.rowEnd-o.getRowHeaders().hiddenHeadersAt(a.rowEnd,!0),l=a.colEnd-o.getColumnHeaders().hiddenHeadersAt(a.colEnd,!0);if(e.rowIndex!==c||e.colIndex!==l)return a;try{this.addRow()}catch(e){if(!(e instanceof n.ExpectedError))throw e;return a}return this.getDataRange().getCoords()}_showTotalsFromProps(){let e=this._sheet?this._getTotalCoords():null;if(!e)return;this._getState().totalsRowShown||this._holdFirstShowTotals();let t=this._getState().orderedColumnsProps,r=t.length,i=null;for(let e=0;e<r;e++){let n=t[e];if(!n||!n.totalsRowLabel&&n.totalsRowFormula===void 0)continue;i??=[...t];let{totalsRowLabel:r,totalsRowFormula:a,...o}=n;i[e]=o}if(!i)return;let a=this._beginCommit((0,n.messageKey)(`op.syncColumnsToSheet`));try{for(let n=0;n<r;n++){if(i[n]===t[n])continue;let r=this._totalsCellAt(e,n).getCell();if(r.getValue()!==null||r.getFormulaText())continue;let a=t[n];this._writeTotalsCellAt(n,a.totalsRowFormula===void 0?{totalsRowLabel:a.totalsRowLabel}:{totalsRowFormula:this._readHeldTotal(a.id)??a.totalsRowFormula})}this._updateColumnsState(i,(0,n.messageKey)(`op.syncColumnsToSheet`)),a.commit()}catch(e){throw a.rollback(),e}}_deleteColumn(e,r){this._requireLive();let i=this._getState(),a=this._views().byId.get(e);if(!a)return;let o=this._beginCommit({description:(0,n.t)(`op.deleteColumnNamed`,{name:a.name}),...r});try{let n=a.index,s=this._sheet;if(s){let e=i.anchorCoords,r=e.colStart+n,a={colStart:r,rowStart:e.rowStart,colEnd:r,rowEnd:e.rowEnd};s.getRange(a).delete(t.IRange.Axis.Column)}let c=this._views().byId.get(e);if(c){let e=this._getState().orderedColumnsProps,t=[...e.slice(0,c.index),...e.slice(c.index+1)];this._updateColumnsState(t,r)}o.commit()}catch(e){throw o.rollback(),e}}addColumn(e=-1,r,i,a){this._requireLive();let o=this._getState().anchorCoords,s=e,c=o.colEnd-o.colStart+1;s===-1&&(s=c),s=Math.min(Math.max(0,s),c);let l=this._beginCommit({description:(0,n.messageKey)(`op.addTableColumn`),...a});try{let e=o.colStart+s,a=o.rowStart,u=o.rowEnd,d={colStart:e,rowStart:a,colEnd:e,rowEnd:u},f=this._sheet;if(f&&f.getRange(d).insert(t.IRange.Axis.Column),(!f||s===0||s>=c)&&this._resize({colStart:o.colStart,rowStart:o.rowStart,colEnd:o.colEnd+1,rowEnd:o.rowEnd}),i!==void 0){let e=this._getState().orderedColumnsProps,t=[...e];t[s]={...e[s],name:i},t=aO(e,t,0,!0,this._emptyColumnName,this._emptyColumnNamer),this._updateColumnsState(t),this._syncHeader({from:`table`})}if(f&&r&&r.length>0){if(!Array.isArray(r))throw new n.ExpectedError((0,n.t)(`error.table.columnValuesNotArray`));let i=u-a+1;if(r.length>i)throw new n.ExpectedError((0,n.t)(`error.table.columnValuesOverflow`,{count:r.length,max:i}));let o={colStart:e,rowStart:a,colEnd:e,rowEnd:a+r.length-1};this._ownWrite(o,()=>{f.getRange(o).setValues([r],{axis:t.IRange.Axis.Column})})}l.commit()}catch(e){throw l.rollback(),e}return this.getColumnAt(s)}getColumns(){return this._views().columns}getColumn(e){let t=this.getColumnByName(e);return t===null?this.getColumnById(e):t}getColumnById(e){return this._views().columnsById.get(e)??null}getColumnByName(e){return this._views().columnsByName.get(e?.toLocaleLowerCase())??null}delete(e){if(this.isDeleted())return;let t=this.getFirstAnchorCoords();this.doBatch(()=>{this._remove(`error`),this._sheet&&t&&this._sheet.getRange(t).clear()},{description:(0,n.t)(`op.deleteTableNamed`,{name:this.getName()}),...e})}_remove(e=null){this.isDeleted()||(e&&this._releaseReferences?.(this,e),this._delete())}convertToRange(e=2**53-1,r){return this._requireLive(),this.doBatch(()=>{if(this._sheet){let r=this.getFirstAnchorCoords(),i=(r.colEnd-r.colStart+1)*(r.rowEnd-r.rowStart+1);if(i>e)throw new n.ExpectedError((0,n.t)(`error.table.convertToRangeLimit`,{count:i,max:e}));let a=this._sheet.getRange(r),o=a.createSparseBuilder({axis:t.IRange.Axis.Column});a.forEach((e,t)=>{let n=t.getCoords(),r=t.getCell();o.pushAt(n.rowIndex,n.colIndex,{style:r.getStyle(!1)})},{includeEmpty:!0,axis:t.IRange.Axis.Column}),o.apply()}this._remove(`address`)},{description:(0,n.messageKey)(`op.convertToRange`),...r}),this._requireSheet().getRange(this._getState().anchorCoords)}resizeTo(e,t,n){let r=this._getState().anchorCoords,i=r.colStart,a=r.rowStart;return this._resize({colStart:i,rowStart:a,colEnd:i+t-1,rowEnd:a+e-1},n)}resize(e,t){let n=this._getLiveState(),r=this._sheet;if(r&&n&&n.totalsRowCount>0){let i=r.getRange(e).getCoords();if(i&&i.rowEnd<n.anchorCoords.rowEnd)return this._resize({...i,rowEnd:i.rowEnd+n.totalsRowCount},t)}return this._resize(e,t)}_resize(e,t,r=(0,n.messageKey)(`op.resizeTable`)){this._requireLive();let i=this._requireSheet().getRange(e).getCoords();if(!i)throw Error(o_(e));let a=this._getState(),o=a.anchorCoords,s=a.headerRowCount,c=a.totalsRowCount;if(o.rowStart!==i.rowStart||i.colEnd<o.colStart||i.colStart>o.colEnd||i.rowEnd<o.rowStart+s+c+1)throw new n.ExpectedError((0,n.t)(`error.table.tableResizeInvalidBounds`));let l=this._beginCommit({description:r,...t,operation:{name:`table.resize`}});try{n.CoordUtils.isEqualRanges(i,o)||this._setAnchor(i,t,r),l.commit()}catch(e){throw l.rollback(),e}return this._sheet.getRange(i)}getName(){return this._getState()?.name??``}setName(e,t){return this._setProps({name:e},t,(0,n.t)(`op.setTableNameNamed`,{name:e}))}getDescription(){return this._getState()?.description??``}setDescription(e,t){return this._setProps({description:e},t,(0,n.messageKey)(`op.setTableDescription`))}select(e){return this.getDataRange().select(e)}_processRestoreOrRevert(e,t){this._styleCache=null,super._processRestoreOrRevert(e,t),this._syncListenersToAnchor()}_syncListenersToAnchor(){if(!(!this._sheet||!this._columnListener)){if(this.isClosed()||this.isDeleted())return this._removeHeaderListener(),this._removeExpandListener(),this._removeHeldTotals(),void this._removeHeldCalculated();this._syncHeldTotals(),this._syncHeldCalculated(),kO(this._getHeaderListenerCoords(),this._headerListenerCoords)||this._processHeaderListener(),kO(this._getExpandListenerCoords(),this._expandListenerCoords)||this._processExpandListener()}}_moveTo(e){let t=this._getLiveState();t&&!n.CoordUtils.isEqualRanges(t.anchorCoords,e)&&(this._updateState({anchorCoords:e}),this._options.setContainerCoords?.(e),this._calcVisible(),this._styleCache=null,this._syncListenersToAnchor())}_processAnchorCoords(){this._styleCache=null,super._processAnchorCoords()}_processAfterContainerShift(e,t){let r=this._getState(),i=t?.length===1?t[0]:null;r&&i&&!n.CoordUtils.isEqualRanges(r.anchorCoords,i)&&(this._updateState({anchorCoords:i},{description:(0,n.messageKey)(`op.updateAnchor`)}),this._processAnchorCoords()),super._processAfterContainerShift(e,t)}getDataRange(){let e=this._getUsedCoords();return e&&this._sheet?this._sheet.getRange(e):VV}_getUsedCoords(){let e=this._getState();if(!e)return null;let t=e.headerRowCount,n=e.totalsRowCount,r=e.anchorCoords;if(!r)return null;let i={...r,rowStart:r.rowStart+t,rowEnd:r.rowEnd-n};return i.rowEnd<i.rowStart||i.colEnd<i.colStart?null:i}getHeaderRowRange(){let e=this._getHeaderCoords();return e&&this._sheet?this._sheet.getRange(e):VV}_getHeaderCoords(){let e=this._getState();if(!e)return null;let t=e.headerRowCount;if(t<1)return null;let n=e.anchorCoords;return n?{...n,rowEnd:n.rowStart+t-1}:null}getTotalRowRange(){let e=this._getTotalCoords();return e&&this._sheet?this._sheet.getRange(e):VV}_getTotalCoords(){let e=this._getState();if(!e)return null;let t=e.totalsRowCount;if(t<1)return null;let n=e.anchorCoords;return n?{...n,rowStart:n.rowEnd-t+1}:null}getStyleOptions(){return this.isDeleted()?ZD:this._getState()?.style}updateStyleOptions(e,t=(0,n.messageKey)(`op.updateStyleInfo`)){let r=this.getStyleOptions(),i=e?{...r,...e}:ZD;return this._setProps({style:i},void 0,t)}getRangedStyle(){let e=this._stylePropsCache;return e||(e=this.getStyle().getRanged(this),this._stylePropsCache=e),e}getStyleAt(e){return Yg(void 0,this._styles,this.getRangedStyle(),n.CoordUtils.cellToRange(e))}isShowTotals(){return this._getState()?.totalsRowCount>0}setShowTotals(e,t){return this._setBands(void 0,+!!e,t,e?(0,n.messageKey)(`op.showTotals`):(0,n.messageKey)(`op.hideTotals`))}isShowHeaders(){return this._getState()?.headerRowCount>0}setShowHeaders(e,t){return this._setBands(+!!e,void 0,t,e?(0,n.messageKey)(`op.showHeaders`):(0,n.messageKey)(`op.hideHeaders`))}isShowHighlightFirstColumn(){return this._getState()?.style?.showFirstColumn??!1}setShowHighlightFirstColumn(e,t){return this._setProps({style:{...this._getState().style,showFirstColumn:e}},t,e?(0,n.messageKey)(`op.showHighlightFirstColumn`):(0,n.messageKey)(`op.hideHighlightFirstColumn`))}isShowHighlightLastColumn(){return this._getState()?.style?.showLastColumn??!1}setShowHighlightLastColumn(e,t){return this._setProps({style:{...this._getState().style,showLastColumn:e}},t,e?(0,n.messageKey)(`op.showHighlightLastColumn`):(0,n.messageKey)(`op.hideHighlightLastColumn`))}isShowBandedColumns(){return this._getState()?.style?.showColumnStripes??!1}setShowBandedColumns(e,t){return this._setProps({style:{...this._getState().style,showColumnStripes:e}},t,e?(0,n.messageKey)(`op.showBandedColumns`):(0,n.messageKey)(`op.hideBandedColumns`))}isShowBandedRows(){return this._getState()?.style?.showRowStripes??!1}setShowBandedRows(e,t){return this._setProps({style:{...this._getState().style,showRowStripes:e}},t,e?(0,n.messageKey)(`op.showBandedRows`):(0,n.messageKey)(`op.hideBandedRows`))}_getExpandListenerCoords(){let e=this._sheet;if(!e||this.getAutoExpand()===Bf.AutoExpand.None&&this.isDisabledColumnFill())return null;let t=this._getLiveState()?.anchorCoords;if(!t)return null;let n=e.getEntireRange().getCoords();return{...t,colEnd:Math.min(t.colEnd+1,n.colEnd),rowEnd:Math.min(t.rowEnd+1,n.rowEnd)}}_removeExpandListener(){this._expandRemoveListener?.(),this._expandRemoveListener=void 0,this._expandListenerCoords=null}_processExpandListener(){this._removeExpandListener();let e=this._sheet;if(!e)return;let t=this._getExpandListenerCoords();t&&(this._expandRemoveListener=e.getRange(t).addListener(e=>{this._onExpandListenerEvent(e)},{transactional:!1}),this._expandListenerCoords=t)}_onExpandListenerEvent(e){if(!this._getLiveState())return;if(e.trigger!==`data`){let t=this._getExpandListenerCoords(),n=e.getSource();kO(t,n.isInvalid()?null:n.getCoords())||this._processExpandListener();return}if(e.isUndo)return;let t=e.getTransactionId();if(!t)return;let r=this._notOwnWrites(e.getFrom().getCoords(),t);if(r.length===0)return;let i=this._getTransactions();if(i.getCurrentCommit(!1).getId()!==i.getTipCommit().getId())return;let a=this._getUsedCoords(),o=this._getAutoExpandCoords(r),s=this._getLiveState().anchorCoords;if(o&&o.rowEnd>s.rowEnd&&this._sheet.getRange({...o,rowStart:s.rowEnd+1}).isContentful(gv.Feature.Formula)){let e=this.getFormulaBelow();if(e===Bf.FormulaBelow.BelowTable)o=o.colEnd>s.colEnd?{...o,rowEnd:s.rowEnd}:null;else if(e===Bf.FormulaBelow.TotalsRow&&o.rowEnd===s.rowEnd+1&&o.colEnd===s.colEnd){o=null;try{this._takeRowBelowAsTotals()}catch(e){console.warn(`Unable to AutoExpand`,e);return}}}if(o)try{this._resize(o,void 0,(0,n.messageKey)(`op.tableAutoExpansion`))}catch(e){console.warn(`Unable to AutoExpand`,e);return}if(a)try{this._processBodyWrite(r,a,t)}catch(e){console.warn(`Unable to fill the column`,e)}}_takeRowBelowAsTotals(){let e=this._requireLive(),t=this._beginCommit({description:(0,n.messageKey)(`op.tableAutoExpansion`),operation:{name:`table.autoTotals`}});try{if(!e.totalsRowShown){let t=e.orderedColumnsProps,r=t.length,i=null;for(let e=0;e<r;e++){let n=t[e];if(!n||!n.totalsRowLabel&&n.totalsRowFormula===void 0)continue;i??=[...t];let{totalsRowLabel:r,totalsRowFormula:a,...o}=n;i[e]=o}i&&this._updateColumnsState(i,(0,n.messageKey)(`op.tableAutoExpansion`))}let r={...e.anchorCoords,rowEnd:e.anchorCoords.rowEnd+1};this._updateState({totalsRowCount:1,totalsRowShown:!0,anchorCoords:r}),this._options.setContainerCoords?.(r),this._calcVisible(),this._styleCache=null,this._showTotalsFromProps(),this._syncListenersToAnchor(),t.commit()}catch(e){throw t.rollback(),e}}_processBodyWrite(e,t,r){let i=this._sheet,a=this._getLiveState(),o=this._getUsedCoords();if(!i||!a||!o)return;let s={...o,rowEnd:Math.min(o.rowEnd,t.rowEnd)};if(s.rowEnd<s.rowStart)return;let c=o.rowEnd-o.rowStart+1,l=new Map,u=e.length;for(let t=0;t<u;t++){let r=n.CoordUtils.intersectRanges(s,e[t]);if(r)for(let e=r.colStart;e<=r.colEnd;e++){let t=l.get(e);t?(t.rows.push([r.rowStart,r.rowEnd]),t.range=r):l.set(e,{rows:[[r.rowStart,r.rowEnd]],range:r})}}if(l.size===0)return;let d=new Map;for(let[e,t]of l)d.set(e,{count:wO(t.rows),range:t.range});let f=!this.isDisabledColumnFill(),p=null;for(let[e,t]of d){let n=e-o.colStart,r=a.orderedColumnsProps[n];if(!r)continue;let s={...o,colStart:e,colEnd:e},l=!!r.calculatedColumnFormula;if(t.count===1&&c>1){let r={...t.range,colStart:e,colEnd:e},a=i.getRange(r).getCell().getFormulaText({r1c1:!0});if(a!==null&&f){let e=TO(s,r),t=!0;for(let n=0;t&&n<e.length;n++)t=!i.getRange(e[n]).isContentful();if(!t&&l){let n=DO(i,e);t=n!==null&&n!==a}if(t){this._fillColumn(n,r);continue}}}else if(t.count>=c&&DO(i,[s])!==null){let e=i.getRange(s).getCell().getFormula()?.getExpression()??null;e&&e!==this._calculatedOf(r.id)&&(p??=new Map).set(n,e);continue}l&&!i.getRange(s).isContentful(gv.Feature.Formula)&&(p??=new Map).set(n,null)}if(!p)return;let m=p,h=this._getTransactions(),g=h.getCurrentCommit(!1).getId()===r;h.amend(r,()=>{this._rememberCalculated(m,g)})}_detectCalculatedColumns(){let e=this._sheet,t=this._getUsedCoords();if(!e||!t)return;let n=Math.max(t.rowStart,t.rowEnd-4);if(!e.getRange({...t,rowStart:n}).isContentful(gv.Feature.Formula))return;let r=(t,n)=>e.getRange({colStart:n,rowStart:t,colEnd:n,rowEnd:t}).getCell(),i=this._getState().orderedColumnsProps,a=i.length,o=null;for(let e=0;e<a;e++){if(!i[e]||i[e].calculatedColumnFormula)continue;let a=t.colStart+e,s=r(t.rowEnd,a),c=s.getFormulaText({r1c1:!0});if(c===null)continue;let l=0;for(let e=n;l<=1&&e<t.rowEnd;e++)r(e,a).getFormulaText({r1c1:!0})!==c&&l++;if(l>1)continue;let u=s.getFormula()?.getExpression({cell:{rowIndex:t.rowStart,colIndex:a}})??null;u&&(o??=new Map).set(e,u)}o&&this._rememberCalculated(o)}_calculatedTextsAt(e){let t=this._getLiveState()?.orderedColumnsProps;if(!t||!this._sheet)return null;let n=null,r=t.length;for(let i=0;i<r;i++){if(!t[i]?.calculatedColumnFormula)continue;let r=this._calculatedTextAt(i,e);r&&(n??=new Map).set(i,r)}return n}_writeCalculatedRows(e,t,n){let r=this._sheet,i=this._getUsedCoords();if(r&&i&&!(t<e))for(let[a,o]of n){let n=i.colStart+a;if(n>i.colEnd)continue;let s=r.getRange({colStart:n,rowStart:e,colEnd:n,rowEnd:t});s.isContentful()||this._ownWrite(s.getCoords(),()=>{s.setFormula(`=`+o)})}}_fillColumn(e,t){let r=this._sheet,i=this._getUsedCoords(),a=i.colStart+e,o=r.getRange(t).getCell().getFormula()?.getExpression({cell:{rowIndex:i.rowStart,colIndex:a}})??null;if(!o)return;let s=this._beginCommit({description:(0,n.messageKey)(`op.tableColumnFill`),operation:{name:`table.columnFill`}});try{let t={...i,colStart:a,colEnd:a};this._ownWrite(t,()=>{r.getRange(t).setFormula(`=`+o)}),this._rememberCalculated(new Map([[e,o]])),s.commit()}catch(e){throw s.rollback(),e}}_rememberCalculated(e,t=!0){let r=this._getState().orderedColumnsProps,i=[...r];for(let[n,a]of e){let e=r[n];if(!e)continue;let{calculatedColumnFormula:o,...s}=e;if(i[n]=a?{...s,calculatedColumnFormula:this._qualified(a,n)}:s,!t)continue;let c=this._heldCalculated.get(e.id);c&&(c.remove(),this._heldCalculated.delete(e.id))}this._updateColumnsState(i,(0,n.messageKey)(`op.tableColumnFill`)),t&&this._syncHeldCalculated()}_getAutoExpandCoords(e){let t=this._sheet,n=this._getLiveState();if(!t||!n)return null;let r=this._getTransactions();if(r.getCurrentCommit(!1).getId()!==r.getTipCommit().getId())return null;let i=n.anchorCoords,a=t.getEntireRange().getCoords(),o=i.colEnd+1,s=i.rowEnd+1,c=this.getAutoExpand(),l=n.totalsRowCount===0&&(c===Bf.AutoExpand.Both||c===Bf.AutoExpand.Rows),u=c===Bf.AutoExpand.Both||c===Bf.AutoExpand.Columns,d=i.colEnd,f=i.rowEnd,p=e.length;for(let t=0;t<p;t++){let n=e[t];if(n.rowStart>=i.rowStart&&n.rowEnd<=i.rowEnd){if(!u||n.colStart<i.colStart||n.colStart>o)continue;d=Math.max(d,Math.min(n.colEnd,a.colEnd))}else if(l&&n.colStart>=i.colStart&&n.colEnd<=i.colEnd){if(n.rowStart<i.rowStart||n.rowStart>s)continue;f=Math.max(f,Math.min(n.rowEnd,a.rowEnd))}}if(d>i.colEnd&&!EO(t,{...i,colStart:o,colEnd:d},e)&&(d=i.colEnd),f>i.rowEnd&&!EO(t,{...i,rowStart:s,rowEnd:f},e)&&(f=i.rowEnd),d===i.colEnd&&f===i.rowEnd)return null;let m={...i,colEnd:d,rowEnd:f};return t.getRange(m).getMerges().length>0||t.getTables().getItems({address:m}).length!==1?null:m}setAutoExpand(e,t){return this._setProps({autoExpand:e},t,(0,n.messageKey)(`op.setAutoExpand`))}getAutoExpand(){return this._sheet?this._getState()?.autoExpand??Bf.AutoExpand.Both:Bf.AutoExpand.None}setFormulaBelow(e,t){return this._setProps({formulaBelow:e},t,(0,n.messageKey)(`op.setFormulaBelow`))}getFormulaBelow(){return this._getState()?.formulaBelow??Bf.FormulaBelow.TotalsRow}setDisabledColumnFill(e,t){return this._setProps({disabledColumnFill:e},t,(0,n.messageKey)(`op.setDisabledColumnFill`))}isDisabledColumnFill(){return(this._getState()?.disabledColumnFill||!this._sheet)??!1}_filterLevels(){let e=this._views().filters,t=e.length,n=[];for(let r=0;r<t;r++){let t=e[r],i=t.getCondition();i&&n.push({index:t.getIndex(),...i.toJSON()})}return n}async applyFilters(e){this._requireLive();let t=this._filterLevels();if(t.length===0)return this;let r=await this._evalFilter({conditions:t}),i=this._beginCommit({description:(0,n.messageKey)(`op.applyFilters`),...e});try{this._applyFilterRuns(r),i.commit()}catch(e){throw i.rollback(),e}return this}deleteFilters(e){return this.filter({conditions:[]},{description:(0,n.messageKey)(`op.deleteFilters`),...e})}getActiveFilters(){return this._views().filters}getFilterAt(e){let t=this._getState()?.orderedColumnsProps[e];return t?this._filterOf(t.id):null}_updateSorts(e,t){let r=t.length;for(let e=0;e<r;e++){let n=t[e];if(!n||!n.sortProps)continue;let r={...n};delete r.sortProps,t[e]=r}let i=e?e.length:0;for(let r=0;r<i;r++){let i=e[r],a=i.index??r,o=t[a];if(!o)continue;let s={...o};if(t[a]=s,i.criteria===null){s.sortProps=null;continue}let c=n.CommonUtils.cloneObject({...i});delete c.index,s.sortProps={level:r,...c}}}_updateFilters(e,t){let n=t.length;for(let e=0;e<n;e++){let n=t[e];if(!n||!n.filterProps)continue;let r={...n};delete r.filterProps,t[e]=r}let r=e?e.length:0,i=0;for(let n=0;n<r;n++){let r=e[n],a=zD.resolveInput(r),o=r?.index??n,s=t[o];if(!s)continue;let c={...s};t[o]=c,a===null?c.filterProps=null:c.filterProps={level:i++,condition:a}}}async filter(e,t){this._requireLive();let r=hD(e),i=await this._evalFilter(r),a=this._beginCommit({description:(0,n.messageKey)(`op.filterTable`),...t});try{this._writeFilters(r.conditions,i),a.commit()}catch(e){throw a.rollback(),e}return this}sort(e){this._requireLive();let t=this._beginCommit({description:(0,n.messageKey)(`op.sortTable`),...e});try{let n=[...this._getState().orderedColumnsProps];this._updateSorts(e?.sorts,n),this._writeColumnProps(n),e&&e.sorts&&e.sorts.length===0||this._applySorts(e),this._processTableUpdate?.(),this._notify(`onSortChange`),t.commit()}catch(e){throw t.rollback(),e}return this}applySorts(e){this._requireLive();let r=this._views().sorts,i=r.length;if(i===0)return this;let a=Array(i);for(let e=0;e<i;e++){let t=r[e];a[e]={index:t.getIndex(),criteria:t.getCriteria()}}let o={description:(0,n.messageKey)(`op.applySort`),...e,sorts:a,hasHeader:this.isShowHeaders(),axis:t.IRange.Axis.Row};return this._applySorts(o,!0),this}deleteSorts(e){return this.sort({description:(0,n.messageKey)(`op.deleteSorts`),...e,sorts:[]})}async applySortsAndFilters(e){this._requireLive();let t=this._filterLevels(),r=t.length>0?await this._evalFilter({conditions:t}):null,i=this._beginCommit({description:(0,n.messageKey)(`op.refreshSortsAndFilters`),...e});try{r&&this._applyFilterRuns(r),this.applySorts(),i.commit()}catch(e){throw i.rollback(),e}return this}async deleteSortsAndFilters(e){this._requireLive();let t=await this._evalFilter({conditions:[]}),r=this._beginCommit({description:(0,n.messageKey)(`op.deleteSortsAndFilters`),...e});try{this.deleteSorts(),this._writeFilters([],t),r.commit()}catch(e){throw r.rollback(),e}return this}getActiveSorts(){return this._views().sorts}getSortAt(e){let t=this._getState()?.orderedColumnsProps[e];return t?this._sortOf(t.id):null}setHiddenButtonAt(e,t){if(this._requireLive(),this.isHiddenButtonAt(e)===t)return this;let r=this._getState(),i=new Map(r.mapHiddenButtons);return t===(r.hiddenButtons??!1)?i.delete(e):i.set(e,t),this._updateState({mapHiddenButtons:i},(0,n.messageKey)(`op.setHiddenButtons`),[`onHiddenButtonsChange`]),this}isHiddenButtonAt(e){let t=this._getState();return!t||(t.mapHiddenButtons.get(e)??t.hiddenButtons??!1)}setHiddenButtons(e){this._requireLive();let t=this._getState();return(t.hiddenButtons??!1)===e&&t.mapHiddenButtons.size===0||this._updateState({hiddenButtons:e,mapHiddenButtons:AO},(0,n.messageKey)(`op.setHiddenButtons`),[`onHiddenButtonsChange`]),this}isHiddenButtons(){let e=this._getState();return!e||!0===e.hiddenButtons&&e.mapHiddenButtons.size===0}_evalFilter(e){let n=this._sheet;if(!n)return Promise.resolve(null);let r=this._getState(),i=r.anchorCoords,a={...i,rowEnd:i.rowEnd-r.totalsRowCount};return MO(n).evalFilter(a,{...e,hasHeader:r.headerRowCount>0,axis:t.IRange.Axis.Row})}_applyFilterRuns(e){e&&MO(this._sheet).applyFilterRuns(e),this._processTableUpdate?.(),this._notify(`onFilterChange`)}_writeFilters(e,t){let n=[...this._getState().orderedColumnsProps];this._updateFilters(e,n),this._writeColumnProps(n),this._applyFilterRuns(t)}_carryFilters(e){this._writeFilters(e,null)}_applySorts(e,n=!1){this.getRange().sort({...e,hasHeader:this.isShowHeaders(),axis:t.IRange.Axis.Row}),n&&(this._processTableUpdate?.(),this._notify(`onSortChange`))}getColumnAt(e){return this._views().columns[e]??null}_updateColumnsState(e,t){let r=this._getState().lastColId,i=e.length;if(i===0&&!this._sheet)throw Error((0,n.t)(`error.table.tableNoBody`));let a=Array(i),o,s;for(let t=0;t<i;t++){let n={...e[t]};a[t]=n,n.index=t,o=null,n.id!==void 0&&(s=parseInt(n.id),Number.isInteger(s)&&(r=Math.max(r,s),o=n.id)),o===null&&(r++,o=r+``),n.id=o}return this._writeColumnProps(a,t,r),this._views().columns}_writeColumnProps(e,t,n){SO(e);let r={orderedColumnsProps:Object.freeze(e)};n!==void 0&&(r.lastColId=n);let i=this._views().filters.length>0;this._updateState(r,t),this._symbolsChanged?.(this),this._views().filters.length>0!==i&&this._filteredChanged?.(this)}getVisibleRefRangeCoords(){return this._ensureVisible(),this._visibleRange?this._visibleRange:this.getFirstAnchorCoords()}getVisibleCellCoords(e){return this._ensureVisible(),e&&this._visibleRange?{colIndex:Math.min(this._visibleRange.colEnd,Math.max(this._visibleRange.colStart,this._sheet.getColumnHeaders().getVisibleIndex(e.colIndex).min)),rowIndex:Math.min(this._visibleRange.rowEnd,Math.max(this._visibleRange.rowStart,this._sheet.getRowHeaders().getVisibleIndex(e.rowIndex).min))}:e}isHeaderVisible(){return this._ensureVisible(),this._isHeaderVisible}isTotalVisible(){return this._ensureVisible(),this._isTotalVisible}isFirstColumnVisible(){return this._ensureVisible(),this._isFirstColumnVisible}isLastColumnVisible(){return this._ensureVisible(),this._isLastColumnVisible}_syncHeader(e){if(e.from===`table`)return void this._writeHeader();let t=this._readHeader(e.keepNameOnBlank??!1);t&&(!t.converted&&oO(t.columns,this._getState().orderedColumnsProps)||(this._updateColumnsState(t.columns,e.description??(0,n.messageKey)(`op.updateColumnsFromSheet`)),t.converted&&(e.write??1)&&this._writeHeader()))}_readHeader(e){let t=this._sheet;if(!t)return null;let n=this._getState().orderedColumnsProps,r=this.getFirstAnchorCoords();if(!r)return null;let i=this._getHeaderCoords();if(!i)return null;let a=r.colEnd-r.colStart+1,o=Array(a).fill(null),s=!1;if(i){let r=0;t.getRange({...i,rowEnd:i.rowStart}).forEach((t,i)=>{let a,c=n[r];t===null?e?(a=c?.name,s=!0):a=null:typeof t==`string`?a=t:(a=i.getCell().getText(),s=!0),o[r]={...c,name:a},r++},{includeEmpty:!0})}let c=aO(n,o,0,!0,this._emptyColumnName,this._emptyColumnNamer);return s||=!oO(o,c),{columns:c,converted:s}}_writeHeader(){let e=this._sheet;if(!e)return;let r=this._getState().orderedColumnsProps,i=this._getHeaderCoords();if(!i)return;let a=(0,n.messageKey)(`op.syncColumnsToSheet`),o=this._beginCommit(a);try{let n=e.getEntireRange().createSparseBuilder({axis:t.IRange.Axis.Row}),a=r.length,s=i.rowStart,c=i.colStart;for(let e=0;e<a;e++){let t=r[e].name;t&&n.pushAt(s,c+e,t)}this._ownWrite(i,()=>{n.apply({textParser:!1})}),o.commit()}catch(e){throw o.rollback(),e}}_processDelete(){this._removeHeaderListener(),this._removeHeldTotals(),this._removeHeldCalculated(),this._removeExpandListener();let e=this._namedItem;e&&e.delete(),super._processDelete()}_ownWrite(e,t){let n=this.getId(),r={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd},i=this._getTransactions().beginCommit();try{i.setIntent(vO,e=>({...e,[n]:[...e?.[n]??[],r]})),t(),i.commit()}catch(e){throw i.rollback(),e}}_notOwnWrites(e,t){if(!t)return e;let r=this._getTransactions(),i=r.getCurrentCommit(!0);if(i.getId()!==t)try{i=r.getLog(t,1)[0]??null}catch{i=null}let a=i?.getIntents()[vO]?.[this.getId()];return a&&a.length!==0?e.filter(e=>!a.some(t=>n.CoordUtils.isRangeWithinRange(e,t))):e}_refitBody(e,t,n,r,i){let a=r.rowStart,o=r.rowEnd;this._refitBodyRows?.(e,t,n,r,i,()=>{if(!this._getLiveState())return!1;let e=this._getUsedCoords();return!!e&&e.rowStart===a&&e.rowEnd===o})}_processContainerShift(e){if(e.isSplit)throw new n.ExpectedError((0,n.t)(`error.table.tableSplit`));let r=this._getState(),i=e.after,a=e.intersect;if(i&&i.rowStart+r.headerRowCount>=i.rowEnd+1)throw new n.ExpectedError((0,n.t)(`error.table.tableNoBody`));let o=e.axis===t.IRange.Axis.Column;if(e.amount<0&&i&&!o){let e=this._getHeaderCoords();if(e&&a.rowStart<=e.rowEnd&&a.rowEnd>=e.rowStart)throw new n.ExpectedError((0,n.t)(`error.table.tableRemoveHeader`));let t=this._getTotalCoords();t&&a.rowStart<=t.rowEnd&&a.rowEnd>=t.rowStart&&this.setShowTotals(!1)}let s=null;if(!o&&e.amount>0&&i){let t=e.before,n=this._getUsedCoords(),r=i.rowStart===t.rowStart&&i.rowEnd===t.rowEnd+e.amount;if(n&&r&&a.rowStart>=n.rowStart){let t=this._calculatedTextsAt(a.rowStart);t&&(s={rowStart:a.rowStart,rowEnd:a.rowStart+e.amount-1,texts:t})}}let c=null;if(!o&&e.amount>0&&i){let t=e.before,n=this._getUsedCoords(),o=i.rowStart===t.rowStart&&i.rowEnd===t.rowEnd+e.amount;n&&o&&a.rowStart===n.rowStart?c={match:{rowStart:n.rowStart+e.amount,rowEnd:n.rowEnd+e.amount},headerRow:null,afterShift:!0}:n&&o&&a.rowStart>n.rowEnd&&(c={match:{rowStart:n.rowStart,rowEnd:n.rowEnd},headerRow:r.headerRowCount>0?t.rowStart:null,afterShift:!1})}let l=super._processContainerShift(e);if(s&&this._writeCalculatedRows(s.rowStart,s.rowEnd,s.texts),c){let e=this._getUsedCoords();e&&this._refitBody(e,c.match,c.headerRow,e,c.afterShift)}if(o){let t=e.amount,r=a.colStart-e.before.colStart,i=t>0;if(r<=0&&i)return l;r<0&&(t-=r,r=0);let o=[...this._getState().orderedColumnsProps];i?o=function(e,t,n,r=JD(),i=YD){let a=Array(n),o=e.length;t<0&&(t=o),e.splice(t,0,...a);let s=iO(e,r)(),c=s!==0&&s<o,l=0;if(s===0){let t=new Set,n=e.length;for(let r=0;r<n;r++){let n=e[r]?.name;if(!n)continue;let i=XD(n);t.add(i)}for(let e=0;s===0&&e<n;e++){let n=XD(i(r,e));t.has(n)&&(s=e)}s===0&&(s=o-1)}let u=c?null:e[t-1]?.name;(c||s>=o)&&(l=s);for(let e=0;e<n;e++){let t;c||l<s?(t=i(r,l),u=t,l++):t=u,a[e]={...a[e],name:t}}return aO(e,a,t,!1,r,i)}(o,r,t):o.splice(r,-t),this._updateColumnsState(o,i?(0,n.messageKey)(`op.addColumns`):(0,n.messageKey)(`op.deleteColumns`)),i&&this._syncHeader({from:`table`})}else i||this._updateColumnsState([],(0,n.messageKey)(`op.deleteColumns`));return i||this._delete(),this._processAnchorCoords(),l}_setProps(e,t,r){let i=bO(this._requireLive(),e);if(!i)return this;let a=[];i.style!==void 0&&a.push(`onStyleChange`);let o=this._beginCommit(CO(t,r));try{if(this._updateState(i,t),i.name!==void 0){if(!i.name)throw Error((0,n.t)(`error.table.tableNoName`));this._setContainerName?.(i.name)}i.style!==void 0&&(this._styleCache=null,this._stylePropsCache=null),i.autoExpand===void 0&&i.disabledColumnFill===void 0||this._syncListenersToAnchor(),o.commit()}catch(e){throw o.rollback(),e}return this._notify(a),this}_setBands(e,t,n,r){let i=this._requireLive(),a=bO(i,{headerRowCount:e,totalsRowCount:t});if(!a)return this;let o=i.headerRowCount,s=i.totalsRowCount,c=a.totalsRowCount??s,l=this._beginCommit(CO(n,r));try{c<s&&this._holdTotalsFromCells(),this._updateState(a,n),this._ensureHeightForHeaderTotals(i.anchorCoords,o,s,a.headerRowCount,a.totalsRowCount)&&(this._syncHeader({from:`table`}),c>s&&this._showTotalsFromProps()),this._syncListenersToAnchor(),l.commit()}catch(e){throw l.rollback(),e}return this}_setAnchor(e,t,r){let i=this._requireLive().anchorCoords;if(n.CoordUtils.isEqualRanges(e,i))return this;let a=!!this._sheet&&e.rowEnd!==i.rowEnd&&this._getTotalCoords()!==null,o=this._getUsedCoords(),s=o&&e.rowEnd>i.rowEnd&&e.rowStart===i.rowStart&&e.colStart===i.colStart?this._calculatedTextsAt(o.rowEnd+1):null,c=this._beginCommit(CO(t,r));try{if(a&&this._moveTotalsRow(i,e.rowEnd),this._updateState({anchorCoords:e},t),!this._getUsedCoords())throw Error((0,n.t)(`error.table.tableNoBody`));let r=this._spliceColumnsToAnchor(i,e);e.rowStart===i.rowStart&&e.rowEnd===i.rowEnd||this._calcVisible(),this._syncHeader({from:`sheet`,keepNameOnBlank:!0,description:(0,n.messageKey)(`op.syncColumnsFromSheet`),write:!1}),this._options.setContainerCoords?.(e),r&&this._syncHeader({from:`table`}),s&&this._writeCalculatedRows(o.rowEnd+1,this._getUsedCoords().rowEnd,s);let l=this._getUsedCoords();if(o&&l&&l.rowStart===o.rowStart&&l.rowEnd!==o.rowEnd){let t={colStart:Math.max(l.colStart,o.colStart),colEnd:Math.min(l.colEnd,o.colEnd)},n=this._getState().headerRowCount>0?e.rowStart:null;t.colStart<=t.colEnd&&this._refitBody(t,o,n,l,!1)}this._syncListenersToAnchor(),c.commit()}catch(e){throw c.rollback(),e}return this}_moveTotalsRow(e,n){let r=this._sheet,i=this._getState().totalsRowCount,a=n>e.rowEnd,o={...e,rowEnd:Math.min(e.rowEnd,n)-i};this._updateState({anchorCoords:o,totalsRowCount:0}),this._options.setContainerCoords?.(o);let s=t=>({...e,rowStart:t,rowEnd:t});if(a){let a=n-e.rowEnd,o=r.getRange({...e,rowStart:e.rowEnd+1,rowEnd:n}),s=n+a;if(s<=r.getEntireRange().getCoords().rowEnd&&!o.isContentful()&&o.getMerges().length===0)return r.getRange({...e,rowStart:e.rowEnd,rowEnd:n-1}).insert(t.IRange.Axis.Row),r.getRange({...e,rowStart:n+1,rowEnd:s}).delete(t.IRange.Axis.Row),void this._updateState({totalsRowCount:i})}r.getRange(s(a?n+1:n)).insert(t.IRange.Axis.Row);let c=a?e.rowEnd:e.rowEnd+1,l=a?n+1:n,u=r.getEntireRange().createSparseBuilder({axis:t.IRange.Axis.Row}),d=e.colEnd-e.colStart+1,f=Array(d);for(let t=0;t<d;t++){let n=this._totalsCellAt(s(c),t).getCell();f[t]=n,u.pushAt(l,e.colStart+t,{style:n.getStyle(!0)})}this._ownWrite(s(l),()=>{u.apply();for(let e=0;e<d;e++){let t=f[e],n=this._totalsCellAt(s(l),e),r=t.getFormulaText();if(r){n.setFormula(r);continue}let i=t.getValue();i!==null&&n.setValue(i,{textParser:!1})}}),r.getRange(s(c)).delete(t.IRange.Axis.Row),this._updateState({totalsRowCount:i})}_spliceColumnsToAnchor(e,t){if(t.colStart===e.colStart&&t.colEnd===e.colEnd)return!1;let r=this._getState().orderedColumnsProps;if(t.colEnd-t.colStart+1===r.length)return!1;let i=[...r];if(t.colEnd>e.colEnd)i.splice(i.length,0,...Array(t.colEnd-e.colEnd)),i=aO(null,i,0,!0,this._emptyColumnName,this._emptyColumnNamer);else if(t.colEnd<e.colEnd){let n=e.colEnd-t.colEnd;i.splice(i.length-n,n)}return t.colStart<e.colStart?(i.splice(0,0,...Array(e.colStart-t.colStart)),i=aO(null,i,0,!0,this._emptyColumnName,this._emptyColumnNamer)):t.colStart>e.colStart&&i.splice(0,t.colStart-e.colStart),this._updateColumnsState(i,(0,n.messageKey)(`op.updateColumns`)),!0}addListeners(e,t){return this._getEmitter().addListeners(e,t)}_processAfterStateChange(e,t){super._processAfterStateChange(e,t),this._styleCache=null,this._stylePropsCache=null,e&&this._processTableUpdate?.(),this._emitter.notify(`onAnyChange`)}_isAnyChangeFromState(){return!0}_getHeaderListenerCoords(){let e=this._getHeaderCoords();if(e)return e;let t=this._getUsedCoords();return t?{...t,rowEnd:t.rowStart}:null}_removeHeaderListener(){this._headerRemoveListener?.(),this._headerRemoveListener=void 0,this._headerListenerCoords=null}_processHeaderListener(){this._removeHeaderListener();let e=this._sheet;if(!e)return;let t=this._getHeaderListenerCoords();t&&(this._headerRemoveListener=e.getRange(t).addListener(this._columnListener,{transactional:!0}),this._headerListenerCoords=t)}get[Symbol.toStringTag](){return`[Table]`}toString(){return this.getName()??``}toJSON(){let e={},t=this._getState();if(!t)return null;t.name&&(e.name=t.name),t.description&&(e.description=t.description),t.headerRowCount!==1&&(e.headerRowCount=t.headerRowCount),t.totalsRowCount!==0&&(e.totalsRowCount=t.totalsRowCount),t.totalsRowShown&&(e.totalsRowShown=!0),t.autoExpand!==Bf.AutoExpand.Both&&(e.autoExpand=t.autoExpand),t.formulaBelow!==Bf.FormulaBelow.TotalsRow&&(e.formulaBelow=t.formulaBelow),t.disabledColumnFill&&(e.disabledColumnFill=t.disabledColumnFill);let r=this._views().columns;if(r){let t=r.length,n=Array(t);for(let e=0;e<t;e++){let t=r[e]?.toJSON();t&&(n[e]=t)}e.columns=n}if(t.style){let r=n.CommonUtils.diffValues(t.style,{...ZD,name:null});r&&(e.style=r)}let i=this._views().sorts,a=i.length;if(a>0){let n=t.orderedColumnsProps,r=Array(a);for(let e=0;e<a;e++){let t=i[e]?.getIndex(),a=n[t];if(!a)continue;let o={...a.sortProps,index:t};delete o.level,r[e]=o}e.sort={sorts:r}}let o=this._views().filters,s=o.length;if(s>0){let n=t.orderedColumnsProps,r=[];for(let e=0;e<s;e++){let t=o[e]?.getIndex(),i=n[t];if(!i)continue;let a=i.filterProps?.condition;if(!a)continue;let s=a.toJSON();s.index=t,r.push(s)}e.filter={conditions:r}}let c=t.mapHiddenButtons;if(!0===t.hiddenButtons&&c.size===0)e.hiddenButtons=!0;else if(!0===t.hiddenButtons||c.size>0){let n=[],r=t.orderedColumnsProps.length;for(let e=0;e<r;e++)this.isHiddenButtonAt(e)&&n.push(e);n.length>0&&(e.hiddenButtons=n)}return e}getSheet(){return this._sheet??null}_createNamed(){return this._names?new uO(this._sheet,this,{transactions:this._getTransactions(),json:{name:this.getName()}}):null}_fromJSON(e){let t=e??{},r=(0,n.messageKey)(`op.addTable`),i=this.getFirstAnchorCoords(),a=i.colEnd-i.colStart+1,o=function(e,t=JD(),n=YD){let r=Array(e);for(let i=0;i<e;i++)r[i]={name:n(t,i)};return r}(a);a>1&&(o[0].totalsRowLabel=KD((0,n.messageKey)(`table.totalsRowLabel`),`Total`));let s=t.columns;s&&(s.length>a&&(s=s.slice(0,a)),o=rO(s));let c=this._options,l=!!this._sheet&&(!c.syncSheet||!!c.hasTotals)&&(t.totalsRowCount??0)>0,u=t.name??``,d=t.name??this._getState().name;this._names&&(d=this._names.findValidName(d));let f=u!==``&&u.toLowerCase()!==d.toLowerCase(),p=(e,t)=>f?BD(e,{rowIndex:i.rowStart,colIndex:i.colStart+t},u,d):e;o=o.map((e,t)=>{if(!e||e.totalsRowLabel===void 0&&e.totalsRowFormula===void 0)return e;if(l){let{totalsRowLabel:t,totalsRowFormula:n,...r}=e;return r}let n=e.totalsRowFormula;if(typeof n!=`string`)return e;let r=tO(n,u,e.name);return{...e,totalsRowFormula:r??p(n,t)}}),o=o.map((e,t)=>{let n=e?.calculatedColumnFormula;if(typeof n!=`string`)return e;let r=p(n.startsWith(`=`)?n.substring(1):n,t);return r===n?e:{...e,calculatedColumnFormula:r}}),this._updateColumnsState(o,r);let m=this._getState(),h={};d!==m.name&&(h.name=d);let g=t.description??m.description;g&&(h.description=g.trim()),h.headerRowCount=t.headerRowCount??1,h.totalsRowCount=t.totalsRowCount??0,h.totalsRowShown=t.totalsRowShown??l,h.autoExpand=t.autoExpand??Bf.AutoExpand.Both,h.formulaBelow=t.formulaBelow??Bf.FormulaBelow.TotalsRow,h.disabledColumnFill=t.disabledColumnFill??!1;let _=t.style;typeof _==`string`&&(_={name:_}),h.style={...ZD,..._};let v=t.sort,y=t.filter;if(v||y){let e=[...m.orderedColumnsProps];v&&this._updateSorts(v.sorts,e),y&&this._updateFilters(y.conditions,e),SO(e),h.orderedColumnsProps=Object.freeze(e)}let b=t.hiddenButtons;if(b!==void 0)if(Array.isArray(b)){h.hiddenButtons=!1;let e=b.length,t=new Map;for(let n=0;n<e;n++){let e=b[n];t.set(e,!0)}h.mapHiddenButtons=t}else h.hiddenButtons=b,h.mapHiddenButtons=AO;this._updateState(h,r)}close(){super.close(),this.isClosed()||(this._removeExpandListener(),this._removeHeaderListener(),this._removeHeldTotals(),this._removeHeldCalculated(),this._stylesRemoveListener?.(),this._colHeadersSizeUnlistener?.(),this._rowHeadersSizeUnlistener?.())}isDeleted(){if(this.isClosed())return!0;let e=this._getState();return!e||e.isDeleted}_getLiveState(){if(this.isClosed())return null;let e=this._getState();return e&&!e.isDeleted?e:null}_requireLive(){let e=this._getLiveState();if(!e)throw Error(`Table has been deleted. No further operations are allowed.`);return e}_requireSheet(){let e=this._sheet;if(!e)throw Error(`Table is not on a sheet. A preview table has no cells to operate on.`);return e}get isITable(){return!0}},bO=(e,t)=>{let r=null,i=Object.keys(t);for(let a=0;a<i.length;a++){let o=i[a],s=t[o];if(s===void 0)continue;let c=e[o],l=c===s;l||o!==`anchorCoords`?!l&&o===`style`&&c&&s&&(l=n.CommonUtils.diffValues(s,c)===null&&n.CommonUtils.diffValues(c,s)===null):l=kO(c,s),l||(r??={},r[o]=s)}return r},xO=(e,t)=>{let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n)if((e[r]??null)!==(t[r]??null))return!1;return!0},SO=e=>{let t=[],n=[],r=e.length;for(let i=0;i<r;i++){let r=e[i];r&&(r.sortProps&&t.push(i),r.filterProps&&n.push(i))}t.sort((t,n)=>e[t].sortProps.level-e[n].sortProps.level),n.sort((t,n)=>e[t].filterProps.level-e[n].filterProps.level);for(let n=0;n<t.length;n++){let r=e[t[n]];r.sortProps.level!==n&&(e[t[n]]={...r,sortProps:{...r.sortProps,level:n}})}for(let t=0;t<n.length;t++){let r=e[n[t]];r.filterProps.level!==t&&(e[n[t]]={...r,filterProps:{...r.filterProps,level:t}})}},CO=(e,t)=>e?.description?e:{...e,description:t},wO=e=>{e.sort((e,t)=>e[0]-t[0]);let t=0,n=-1,r=e.length;for(let i=0;i<r;i++){let[r,a]=e[i];a<=n||(t+=a-Math.max(r,n+1)+1,n=a)}return t},TO=(e,t)=>{let r=n.CoordUtils.intersectRanges(e,t);if(!r)return[e];let i=[];return r.rowStart>e.rowStart&&i.push({...e,rowEnd:r.rowStart-1}),r.rowEnd<e.rowEnd&&i.push({...e,rowStart:r.rowEnd+1}),r.colStart>e.colStart&&i.push({...r,colStart:e.colStart,colEnd:r.colStart-1}),r.colEnd<e.colEnd&&i.push({...r,colStart:r.colEnd+1,colEnd:e.colEnd}),i},EO=(e,t,r)=>{let i=[t],a=!1,o=r.length;for(let s=0;s<o;s++){let o=n.CoordUtils.intersectRanges(t,r[s]);if(!o)continue;!a&&e.getRange(o).isContentful()&&(a=!0);let c=[];for(let e=0;e<i.length;e++){let t=TO(i[e],o);for(let e=0;e<t.length;e++)c.push(t[e])}i=c}if(!a)return!1;for(let t=0;t<i.length;t++)if(e.getRange(i[t]).isContentful())return!1;return!0},DO=(e,t)=>{let n=null;for(let r=0;r<t.length;r++){let i=t[r],a=e.getRange(i),o=(i.rowEnd-i.rowStart+1)*(i.colEnd-i.colStart+1);if(a.getCounts(gv.Feature.Formula)[gv.Feature.Formula]!==o)return null;for(let e of a.getRegions(gv.Feature.Formula)){let t=e.getCell().getFormulaText({r1c1:!0});if(t===null||n!==null&&n!==t)return null;n=t}}return n},OO=(e,t)=>(e.totalsRowLabel||void 0)===(t.totalsRowLabel||void 0)&&e.totalsRowFormula===t.totalsRowFormula,kO=(e,t)=>e&&t?n.CoordUtils.isEqualRanges(e,t):e===t,AO=new Map,jO=new Map,MO=e=>e._getInternal(),NO=Object.freeze({}),PO=Object.freeze({}),FO=Object.freeze({criteria:null,level:-1}),IO=Object.freeze({condition:null,level:-1}),LO=class extends sO{getName(){let e,t=this.getIndex(),n=this.getTable(),r=n.getSheet();if(r){let i=n.getRange().getCoords().colStart;e=r.getColumnHeaders().getTextAt(i+t)}return e||=`Column ${t+1}`,e}setName(e){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}getId(){return this._getProps(this._id).id??null}getIndex(){return this._getProps(this._id).index??-1}setTotalsRowLabel(e){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}getTotalsRowLabel(){return null}setTotalsRowFormula(e){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}getTotalsRowFormula(){return null}delete(e){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}get[Symbol.toStringTag](){return`[AutoTableColumn]`}toJSON(){return null}},RO=class extends yO{_initialize(e){let t={...e.json};e={...e,json:t},t.autoExpand=Bf.AutoExpand.None,t.disabledColumnFill=!0,t.name=KD((0,n.messageKey)(`table.autoTableName`),`AutoTable`),t.description=KD((0,n.messageKey)(`table.autoTableDescription`),`AutoTable created for filtering and sorting`),e.names=null,e.styles=new ag,e.setContainerName=e=>{throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))},super._initialize(e)}initializeColumnCreator(e,t,n,r){return i=>new LO(e,i,t,n,r)}_processHeaderListener(){}_syncHeader(){}_calcVisible(){}isShowHeaders(){return!1}addRows(e,t=1,r){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}addColumn(e=-1,t,r,i){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}deleteRowsAt(e,t=1,r){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}getColumnByName(e){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}convertToRange(e=2**53-1,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}delete(e){this._remove()}setName(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setDescription(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}updateStyleOptions(e,t=(0,n.messageKey)(`op.updateStyleInfo`)){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowTotals(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowHeaders(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowHighlightFirstColumn(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowHighlightLastColumn(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowBandedColumns(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}setShowBandedRows(e,t){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}_resize(e,t,r=(0,n.messageKey)(`op.resizeTable`)){throw Error((0,n.t)(`error.table.autoTableInvalidOperation`))}get[Symbol.toStringTag](){return`[AutoTable]`}toString(){return this.getRange().toString()}toJSON(){let e=super.toJSON();return e?(delete e.name,delete e.description,delete e.style,delete e.columns,delete e.autoExpand,delete e.formulaBelow,delete e.disabledColumnFill,delete e.totalsRowCount,delete e.headerRowCount,e):null}},zO=class extends S{constructor(e){super(e.transactions),this._options={...e};let t=this;this._transactions=this._options.transactions??new g({transient:!0}),this._stateId=this._transactions.create(),this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onAfterStateChange(e,n){t._notifyCollectionChange()}}),this._initState(e?.initial)}add(e,t,r){let i=this;this._assertWritable(),t&&(t._setBeforeDelete?.(()=>i._assertWritable()),t.addListeners({onDelete:t=>{i._updateState(t=>{if(!t.modules[e])return;let n=t.modules[e];if(n){let r={...t};return i._options.onRemove?.(e,n),i._notifyCollectionChange(),delete r.modules[e],r}return t},(0,n.messageKey)(`op.deleteModule`))}},{once:!0}));let a=this._getState()?.modules,o=a?.[e],s=r?.replace??!1;if(o&&!s)throw Error(`Already existing '${e}'`);let c={...a};t?(c[e]=t,i._options.onAdd?.(e,t),this._updateState({modules:c},s?(0,n.messageKey)(`op.saveScripts`):(0,n.messageKey)(`op.addScript`))):(delete c[e],i._options.onRemove?.(e,null),this._updateState({modules:c},(0,n.messageKey)(`op.removeScript`))),i._notifyCollectionChange()}_getItems(e){let t=this._getState();if(!t)return n.CommonUtils.EmptyArray;let r=t.modules,i=Object.keys(r),a=i.length;if(a===0)return n.CommonUtils.EmptyArray;let o=[],s=e?.name?e.name.toUpperCase():null,c=e&&`language`in e?e.language===null?null:String(e.language).toUpperCase():`TYPESCRIPT`;for(let e=0;e<a;e++){let t=i[e],n=r[t],a=!0;s&&s!==t.toUpperCase()&&(a=!1),a&&c&&n.getLanguage().toUpperCase()!==c&&(a=!1),a&&o.push(n)}return o??n.CommonUtils.EmptyArray}getByName(e){if(!e)return null;let t=this._getState();if(!t)return null;let n=e.toUpperCase(),r=t.modules,i=Object.keys(r),a=i.length;for(let e=0;e<a;e++){let t=i[e];if(n===t.toUpperCase())return r[t]}return null}beginCommit(e){return this._beginCommit(e)}_assertWritable(){if(this._options.isReadOnly?.())throw new n.ProtectedError((0,n.t)(`error.workbook.protection`))}_getState(){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`));return this._transactions.getState(this._stateId)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_updateState(e,t=(0,n.messageKey)(`op.update`),r){if(!e)return;let i=this._beginCommit(t);try{i.updateState(this._stateId,e),i.commit(r)}catch(e){throw i.rollback(),e}}_initState(e){let t=e??{},r=this._beginCommit((0,n.messageKey)(`op.initialize`));try{r.updateState(this._stateId,{modules:t}),r.amend()}catch(e){throw r.rollback(),e}let i=this._options.onAdd;if(i){let e=Object.keys(t),n=e.length;for(let r=0;r<n;r++){let n=e[r];i(n,t[n])}}}addListeners(e,t){return super.addListeners(e,t)}toJSON(){let e=this._getState();if(!e)return n.CommonUtils.EmptyArray;let t=e.modules,r=Object.keys(t),i=r.length,a={};for(let e=0;e<i;e++){let n=r[e];a[n]=t[n].toJSON()}return a}close(){this.isClosed()||(this._close(),this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}get isIModuleCollection(){return!0}},BO=`SheetXL`;function VO(){return gO||=async function(){return(await Promise.resolve().then(()=>require("./O6F5xVsoF2hTiprv.cjs"))).loadEnumManifest()}().then(e=>n.CommonUtils.deepFreeze(e)).catch(e=>{throw gO=void 0,e}),gO}var HO=void 0;async function UO(){let e=await VO();HO=globalThis[BO],globalThis[BO]=e}function WO(){HO?(globalThis[BO]=HO,HO=void 0):delete globalThis[BO]}function GO(){return VO()}async function KO(e){await UO();try{return await e()}finally{WO()}}var qO,JO={debug:e=>console.debug(e),log:e=>console.log(e),info:e=>console.info(e),warn:e=>console.warn(e),error:e=>console.error(e instanceof Error?e.stack??e.message:e)},YO=class extends iE{constructor(e,t,n,r=null,i=!1,a){super(e,a?()=>{}:t,n,r,i),this._fnLoader=a}async _ensureLoaded(){if(!this._fnLoader)return;let e=await this._fnLoader();this._fn=e.bind(this),this._fnLoader=void 0}execute(...e){let t=e[0];if(!t||!t.isIWorkbook)throw Error(`Macro '${this.getName()}' must be called with a valid workbook as the first argument.`);let r=e[1],i=(0,n.createLogChannels)(r?.logger??JO,{render:r?.render}),a={wb:t,log:i.log,warn:i.warn,error:i.error,args:r?.args},o=this._ct;try{let e=[];switch(o){case BT.Context.Script:break;case BT.Context.Workbook:e.push(t);break;case BT.Context.Sheet:e.push(t.getSelectedSheet());break;case BT.Context.Ranges:e.push(t.getSelectedRanges());break;case BT.Context.Range:e.push(t.getSelectedRange());break;default:throw Error(`Function '${this.getName()}' is not a valid macro function.`)}let s=async(e,t)=>{let n=await t;if(n!==void 0)if(n!==null){if(Array.isArray(n)){if(IH(n[0]?.[0]))return void e.setValues(n,{skipBoundsCheck:!0})}else if(IH(n))return void e.setValues([[n]]);n.isICell?e.updateCells(n):n.isICellRange&&await e.copyFrom(n)}else e.clear()},c,l;return(async()=>{await this._ensureLoaded();let o=(await Promise.resolve(this._descFn()))?.summary,u={...r,description:r?.description??o??r?.defaultDescription??n.CommonUtils.camelToPrettyCase(this.getName())};try{await t.doBatch(async n=>{l=n.getId();try{let n=t.getSelectedRange(),i=this._cf();i||=new Proxy({},{set:(e,t,n)=>(console.log(`Adding property "${t}" with value:`,n),e[t]=n,!0),deleteProperty:(e,t)=>(console.log(`Deleting property "${t}"`),delete e[t])});try{RT({getRow:()=>n.getCell().getCoords().rowIndex,getColumn:()=>n.getCell().getCoords().colIndex}),await UO(),c=await this._fn.call(i,...e,a),WO()}catch(e){throw e}finally{zT()}r?.applyResult&&await s(n,c)}catch(e){throw e}},u),l!==void 0&&t.getTransactions().getCurrentCommit().getId()!==l&&(l=void 0)}finally{await i.flush({timeoutMs:(0,n.resolveLogTimeout)(r?.logTimeoutMs)})}return{params:e,results:c,commitId:l}})()}catch(e){throw e}}};(qO||={}).DEFAULT_MODULE=`main.ts`;var XO=1/0,ZO=(e,t)=>e===t?0:e.startsWith(t)?2:e.includes(t)?4:XO,QO=(e,t)=>{let n=ZO(e.name,t);if(n===0)return 0;let r=e.nameLocal===e.name?XO:ZO(e.nameLocal,t),i=Math.min(n,r===XO?XO:r+1);return i===XO?e.summary.includes(t)?6:XO:i},$O=(e,t)=>e.score===t.score?e.name<t.name?-1:+(e.name>t.name):e.score-t.score,ek=(e,t)=>{let n=new Map;for(let r=0;r<e.length;r++){let i=e[r];n.set(i,ZO(i.getName().toUpperCase(),t))}return e.sort((e,t)=>{let r=n.get(e),i=n.get(t);return r===i?0:r<i?-1:1})},tk=(e,t)=>{let n=e.getName().toUpperCase(),r=t?.getCategory()??`Uncategorized`;return{fn:e,name:n,nameLocal:t?.getNameLocal()?.toUpperCase()??n,summary:t?.getSummary()?.toUpperCase()??``,category:r,categoryUpper:r.toUpperCase(),deprecated:!!t?.isDeprecated()}},nk=class{constructor(e){this._entries=null,this._language=null,this._building=null,this._source=e}invalidate(){this._entries=null,this._building=null}entries(){let e=n.DefaultLanguagePackService.getActive();if(this._language===e){if(this._entries)return Promise.resolve(this._entries);if(this._building)return this._building}this._language=e;let t=this._build().then(n=>(this._language===e&&this._building===t&&(this._entries=n,this._building=null),n));return this._building=t,t}async _build(){let e=Array.from(this._source()),t=await Promise.all(e.map(e=>e.getDescriptor().catch(()=>null))),n=[],r=new Set;for(let i=0;i<e.length;i++){let a=e[i],o=a.getName().toUpperCase();r.has(o)||(r.add(o),n.push(tk(a,t[i])))}return Object.freeze(n)}},rk=class extends S{constructor(e){super(e.transactions??void 0),this._readonly=null,this._named=null,this._options={...e};let t=this;this._transactions=this._options.transactions??new g({transient:!0}),this._stateId=this._transactions.create(),this._index=new nk(function*(){let e=t._readonly;e&&(yield*e.values());let n=t.isClosed()?null:t._getState();n&&(yield*n.itemsByKey.values())}),this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onAfterStateChange(e,n){t._index.invalidate(),t._notifyCollectionChange()}}),this._readonly=e?.readonlyFunctions,this._initState()}_getItems(e){let t=this._getState();if(!t)return n.CommonUtils.EmptyArray;let r=Array.from(t.itemsByKey.values()),i=this._readonly;i&&r.push(...Array.from(i.values())),r.push(...this._namedFunctions());let a=e?.type??null,o=e?.name?e.name.toUpperCase():null;return a||o?r.filter(e=>(!a||e.getContext()===a)&&(!o||e.getName().toUpperCase()===o)):r}getByName(e,t){if(!e)return null;let r=this._getState();if(!r)return null;if(!r)return n.CommonUtils.EmptyArray;let i=e.toUpperCase(),a=this._readonly,o=a?.size?a.get(i):void 0;if(o||=r.itemsByKey.get(i),!o)return this._named?.getByName(e,t?.sheet)??null;let s=t?.sheet;if(s!==void 0){let e=this._options.createScopedContext;if(!e)throw Error(`This collection cannot vend sheet-scoped functions (no scoped-context factory).`);if(o instanceof YO||!(o instanceof iE))throw Error(`This function cannot be sheet-scoped.`);let t=e(s);if(!t)throw Error(`Unknown sheet for function scope. ('${s}')`);return o._withContext(()=>t)}return o}_setNamedSource(e){this._named=e}_namedFunctions(){let e=this._named?.getItems();if(!e?.length)return n.CommonUtils.EmptyArray;let t=this._getState(),r=this._readonly;return e.filter(e=>{let n=e.getName().toUpperCase();return!r?.has(n)&&!t?.itemsByKey.has(n)})}async _entries(){let e=await this._index.entries(),t=this._namedFunctions();if(t.length===0)return e;let n=await Promise.all(t.map(e=>e.getDescriptor().catch(()=>null)));return[...e,...t.map((e,t)=>tk(e,n[t]))]}async search(e){let t=await this.searchScored(e),r=t.length;if(r===0)return n.CommonUtils.EmptyArray;let i=Array(r);for(let e=0;e<r;e++)i[e]=t[e].fn;return i}async searchScored(e){let t=this._getState();if(!t)return n.CommonUtils.EmptyArray;let r=e?.name?e.name.toUpperCase():null,i=e?.type?e.type:null,a=e?.category?e.category.toUpperCase():null,o=e?.text?e.text.trim().toUpperCase():null,s=e?.limit;if(s!==void 0&&s<=0)return n.CommonUtils.EmptyArray;let c=e?.includeDeprecated,l=[];if(!(a||o||c!==void 0)){let e=new Set,n=(t,n)=>{r&&n!==r||e.has(n)||(e.add(n),i&&t.getContext()!==i||l.push({fn:t,score:0,name:n}))};return this._readonly?.forEach(n),t.itemsByKey.forEach(n),this._namedFunctions().forEach(e=>n(e,e.getName().toUpperCase())),s!==void 0&&l.length>s?l.slice(0,s):l}let u=await this._entries(),d=u.length;for(let e=0;e<d;e++){let t=u[e];if(r&&t.name!==r||i&&t.fn.getContext()!==i||a&&t.categoryUpper!==a||!c&&t.deprecated)continue;let n=0;o&&(n=QO(t,o),n===XO)||l.push({fn:t.fn,score:n,name:t.name})}return l.sort($O),s!==void 0&&l.length>s?l.slice(0,s):l}async getCategories(e){this._getState();let t=e?.type?e.type:null,n=e?.includeDeprecated??!1,r=await this._entries(),i=new Map,a=r.length;for(let e=0;e<a;e++){let a=r[e];if(t&&a.fn.getContext()!==t||!n&&a.deprecated)continue;let o=i.get(a.categoryUpper);o?o.count++:i.set(a.categoryUpper,{name:a.category,count:1})}let o=Array.from(i.values());return o.sort((e,t)=>e.name.localeCompare(t.name)),o}getCount(){let e=this._getState();if(!e)return 0;let t=e.itemsByKey.size;return this._readonly&&(t+=this._readonly.size),t}validateName(e){return this._validateName(e)}_validateName(e,t=!1){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`))}async add(e){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`));if(!e)throw Error(`Item must be specified.`);return typeof e==`string`?this._addFromSource(e):this._addFunction(e)}async _addFromSource(e){let t=await(await import(`@sheetxl/scripting`)).ScriptCompiler.compile({source:e,builtInNames:this._readonly?Array.from(this._readonly.keys()):void 0});if(!t.module)throw Error(`The script did not compile to a module.`);let r=t.diagnostics.filter(e=>e.severity===`error`);if(r.length>0){let e=Error(`The script has ${r.length} compile error${r.length===1?``:`s`}: `+r.map(e=>`${e.code}: ${e.message}`).join(`; `));throw e.diagnostics=r,e}let{jsonToModule:i}=ak,a=(await i(qO.DEFAULT_MODULE,t.module,!1,t.diagnostics)).getFunctions().getItems();if(a.length===0)throw Error(`The script did not define any exported functions.`);for(let e=0;e<a.length;e++){let t=a[e].getName();if(this._readonly?.has(t.toUpperCase()))throw Error((0,n.t)(`error.function.builtInName`,{name:t}))}let o=null;for(let e=0;e<a.length;e++){let t=this._addFunction(a[e]);o||=t}return o}_addFunction(e){let t;if(e.isIFunction){let n=e,r=n._json;t=new(r.context&&r.context!==BT.Context.Calculation?YO:iE)(r,n._fn,()=>this._options.context,n._descFn)}else{let n=e;t=new iE(n.declaration,n.execute,()=>this._options.context,n.descriptor)}let r=this._getState(),i=t.getName().toUpperCase();if(this._readonly?.has(i))throw Error((0,n.t)(`error.function.builtInName`,{name:t.getName()}));return r.itemsByKey.set(i,t),this._index.invalidate(),t}beginCommit(e){return this._beginCommit(e)}_getState(){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`));return this._transactions.getState(this._stateId)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_updateState(e,t=(0,n.messageKey)(`op.update`),r){if(!e)return;let i=this._beginCommit(t);try{i.updateState(this._stateId,e),i.commit(r)}catch(e){throw i.rollback(),e}}_initState(){let e=this._beginCommit((0,n.messageKey)(`op.initialize`));try{e.updateState(this._stateId,e=>({...e,itemsByKey:new Map})),e.amend()}catch(t){throw e.rollback(),t}}addListeners(e,t){return super.addListeners(e,t)}close(){this.isClosed()||(this._close(),this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}get isIFunctionCollection(){return!0}},ik=class{constructor(e){this._beforeDelete=null;let t=e.json;if(this._json=t,!this._json)throw Error(`Module JSON is required.`);this._diagnostics=e.diagnostics??[],this._name=e.name??null;let n=e.scope??null;this._scope=typeof n==`function`?n:()=>n,this._emitter=new x(this),this._functions=new rk({transactions:null,readonlyFunctions:e.readonlyFunctions})}getName(){return this._name}getFunctions(){return this._functions}getSource(){return this._json.source??null}getLanguage(){return this._json.language||`typescript`}getScope(){return this._scope()}getErrors(){return this._diagnostics.filter(e=>e.severity===`error`)}getDiagnostics(){return this._diagnostics}delete(){this._beforeDelete?.(),this._emitter.notify(`onDelete`)}_setBeforeDelete(e){this._beforeDelete=e}addListeners(e,t){return this._emitter.addListeners(e,t)}toJSON(){return this._json}get isIModule(){return!0}},ak=e.n({jsonToModule:()=>lk,jsonToModuleSync:()=>uk,runAsyncGenerator:()=>dk}),ok=async(e,t,n)=>{let r=null;try{(function(){IT();let e=globalThis;e[a.Constants.GLOBAL_CONTEXT_VARIABLE]!==FT&&(e[a.Constants.GLOBAL_CONTEXT_VARIABLE]=FT)})(),RT(null)}catch(e){console.warn(`Error setting global scope`,e)}try{let t=e.compiled;t=t.replaceAll(a.Constants.GLOBAL_CONTEXT_VARIABLE,`globalThis.`+a.Constants.GLOBAL_CONTEXT_VARIABLE);let{loadCompiledModule:n}=await import(`@sheetxl/scripting`);r=await n(t,{sourceMap:e.sourceMap})}catch(e){throw Error(`Invalid Javascript module.`,{cause:e})}finally{zT()}if(!t)throw Error(`No function available for '${n}'.`);let i=t.name,o=r[i];if(!o&&t.behavior.default&&(o=r.default),!o)throw Error(`Found the descriptor for '${i}' but not the function. The descriptor manifest must be corrupt.`);return o},sk=(e,t,n)=>{let r=t?.name;return!n&&r&&r!==e.name?{...e,name:r}:e};function ck(e){let t=new Map,n=e?.functions;if(!n)return t;for(let e=0;e<n.length;e++){let r=n[e],i=r[0],a=r[1],o=!!i.context&&i.context!==BT.Context.Calculation,s=sk(i,a,o),c=o?new YO(s,()=>{},()=>null,a,!1,void 0):new iE(s,()=>{},()=>null,a);t.set(s.name.toUpperCase(),c)}return t}async function lk(e,t,n=!1,r=[],i){let a=t?.functions,o=r.some(e=>e.severity===`error`)||!t?.compiled;if(n||o)return new ik({json:t,readonlyFunctions:ck(t),name:e,diagnostics:r,scope:i});let s=new Map;if(a)for(let n=0;n<a.length;n++){let r=a[n],i=r[0],o=r[1],c=!!i.context&&i.context!==BT.Context.Calculation,l=sk(i,o,c),u;u=c?new YO(l,()=>{},()=>null,o,!1,()=>ok(t,i,e)):new iE(l,await ok(t,i,e),()=>null,o),s.set(l.name.toUpperCase(),u)}return new ik({json:t,readonlyFunctions:s,name:e,diagnostics:r,scope:i})}function uk(e,t,n,r=[]){return new ik({json:t,readonlyFunctions:ck(t),name:e,diagnostics:r,scope:n})}async function dk(e){let t=await e.next();for(;!t.done;){let n=t.value;try{let r=n instanceof Promise?await n:n;t=await e.next(r)}catch(n){t=await e.throw?.(n)??{done:!0,value:void 0}}}return t.value}var fk,pk=class e extends UD{constructor(e){if(super(e),!e.content)throw Error(`Content type is required`);this._content=e.content,this._optionsMovable=e;let t=this;this._optionsMovable.setContainerCallbacks?.({processZIndex:()=>t._processZIndex(),processSelection:(e,n)=>t._processContainerSelect(e,n)}),e.json&&this._fromJSON(e.json)}getContent(){return this._content}delete(e){this._content.delete(e)}_deleteFromContent(){this._delete()}_processAfterStateChange(e,t){super._processAfterStateChange(e,t),this._getEmitter().notify(`onBoundsChange`),this._getEmitter().notify(`onAnyChange`)}_processZIndex(){this._getEmitter().notify(`onAnyChange`)}_processContainerSelect(e,t){this._getEmitter().notify(`onSelectionChange`)}isSelected(){return this._optionsMovable.isSelected?.()??!1}async scrollIntoView(e){return this._optionsMovable.scrollIntoView?.(e)??!1}async select(e){if(!1===await this._optionsMovable.select?.(e))return!1;if(!1!==e?.autoFocus){let e=await this._getEmitter().notify(`onRequestFocus`,{async:!0});if(!e)return!1;let t=e.length;for(let n=0;n<t;n++)if(!1===e[n])return!1}return!0}unselect(){let e=this._optionsMovable.isSelected?.()??!1;return this._optionsMovable.unselect?.(),e}_clone(){let t=this.isSelected(),n=this.getZIndex(),r=this._optionsMovable.getMaxBounds,i=this._content,a={beginPersistResource:this._optionsMovable.beginPersistResource,getBoundsAtCoords:this._optionsMovable.getBoundsAtCoords,getCoordsAtBounds:this._optionsMovable.getCoordsAtBounds,isSelected:()=>t,getZIndex:()=>n,getContainerIndex:()=>n,getMaxBounds:r,getRanges:e=>this._optionsMovable.getRanges(e),getEntireRange:()=>this._optionsMovable.getEntireRange(),transactions:new g({transient:!0}),json:this.toJSON(),coords:this.getFirstAnchorCoords(),content:i},o=new e(a),s=this._getState();return o._updateState({...s}),o}getSnapshot(e,t){let r=this._optionsMovable.getCoordsAtBounds(e),i=this._getState().offsets,a=this.getFirstAnchorCoords();if((i.br.x>0||i.br.y>0)&&(a={...a},a.colEnd-=+(i.br.x>0),a.rowEnd-=+(i.br.y>0)),!n.CoordUtils.isRangeWithinRange(a,r))return null;let o=this,s=o._clone(),c=Object.freeze({...t}),l=!1;return{async copyTo(e,t){let n={...c,...t};return await s._doCopy(e,n),n.isCut&&!l&&(o._content.delete(),l=!0),e.bounds},getCoords:()=>s.getBounds(),getSource:()=>s,getName:()=>s._content.getName?.()??``,getMarkOptions:()=>c,toText:()=>s._toText(),toHtml:()=>s._toHtml(),toImage:()=>s._toImage(),isISnapshot:!0}}async _doCopy(e,t){let r=this._optionsMovable.beginPersistResource(),i=this.toJSON(r.toResourceId.bind(r)),a=this._content.getName?.()??null,o;if(a){let e=(0,n.t)((0,n.messageKey)(`movable.copySuffix`),{name:a});o=e===`movable.copySuffix`?`${a} (Copy)`:e}let s=i.content.json,c=i.content.description;delete i.content;let l=e.movables;if(!l)throw Error(`Movables is required`);let u=e.bounds??this.getBounds();try{await l.add({...i,...t,fromResourceId:r.fromResourceId.bind(r),bounds:u,type:this.getContent().getType(),json:s,name:o,altText:c,description:(0,n.messageKey)(`op.copyMovable`)})}finally{r.endPersist()}}_toText(){return this.getContent().toText?.()}_toHtml(){return this.getContent().toHtml?.()}_toImage(){return this.getContent().toImage?.()}setHidden(e=!1){return!!e===this.isHidden()||(this._updateState({hidden:!!e},{description:(0,n.messageKey)(`op.setMovableVisibility`)}),this._options.invalidate?.()),this}isHidden(){return this._getState()?.hidden??!1}setLockAspectRatio(e){return this._updateState({lockAspectRatio:e},{description:(0,n.messageKey)(`op.setLockAspectRatio`)}),this}isLockAspectRatio(){return this._getState()?.lockAspectRatio??this._optionsMovable.defaultLockAspectRatio??!1}setRotation(e=0){return this._updateState({rotation:e},{description:(0,n.messageKey)(`op.setMovableRotation`)}),this}getRotation(){return this._getState()?.rotation??0}moveToBack(){return this._optionsMovable.moveToBackOnContainer?.(),this}moveBackward(){return this._optionsMovable.moveBackwardOnContainer?.(),this}moveToFront(){return this._optionsMovable.moveToFrontOnContainer?.(),this}moveForward(){return this._optionsMovable.moveForwardOnContainer?.(),this}getZIndex(){return this._optionsMovable.getZIndex?.()??0}setBounds(e,t){if(!e)return this;let r={...this.getBounds(),...e};if(this._optionsMovable.getMaxBounds&&(r={x:Math.max(r.x,this._optionsMovable.getMaxBounds().x),y:Math.max(r.y,this._optionsMovable.getMaxBounds().y),width:Math.min(r.width,this._optionsMovable.getMaxBounds().width),height:Math.min(r.height,this._optionsMovable.getMaxBounds().height)}),r.width<0||r.height<0)throw new n.OutOfBoundsError;let i=this._updateMovableLocation({bounds:r,anchorType:ev.Type.Absolute}),a=this._beginCommit(t?.description??(0,n.messageKey)(`op.setMovableBounds`));return this._updateState({offsets:i.offsets,anchorCoords:i.anchorCoords,pixelBounds:this.getAnchorType()===ev.Type.TwoCell?null:r},{description:(0,n.messageKey)(`op.updateMovableBounds`)},[`onBoundsChange`]),this._options.setContainerCoords(i.anchorCoords),a.commit(),this}_updateMovableLocation(e){let t=e.offsets??mk(),n=e.anchorCoords??this.getFirstAnchorCoords(),r=e.anchorType??this.getAnchorType();if(r===ev.Type.TwoCell)return n?{anchorCoords:n,offsets:t}:void 0;let i=e.bounds??this.getBounds();if(i){if(r===ev.Type.Absolute){n=this._optionsMovable.getCoordsAtBounds(i);let e=this._optionsMovable.getBoundsAtCoords(n);t={...t,tl:{x:i.x-e.x,y:i.y-e.y}}}if(r===ev.Type.Absolute||r===ev.Type.OneCell){let e=this._optionsMovable.getBoundsAtCoords({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colStart,rowEnd:n.rowStart}),r=this._optionsMovable.getCoordsAtBounds({x:e.x,y:e.y,width:i.width+Math.min(e.width,t.tl.x),height:i.height+Math.min(e.height,t.tl.y)});n={colStart:n.colStart,rowStart:n.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd};let a=this._optionsMovable.getBoundsAtCoords({colStart:n.colEnd,rowStart:n.rowEnd,colEnd:n.colEnd,rowEnd:n.rowEnd}),o=i.width-(a.x-e.x-Math.min(t?.tl.x??0,e.width)),s=i.height-(a.y-e.y-Math.min(t?.tl.y??0,e.height));t={...t,br:{x:o,y:s}}}return t!==e.offsets&&(t.br.y<=0&&(t.br={...t.br,y:0},n.rowEnd--),t.br.x<=0&&(t.br={...t.br,x:0},n.colEnd--)),{anchorCoords:n,offsets:t}}}_calcAbsoluteBounds(e,t=mk()){if(!e)return null;let n=this._optionsMovable.getBoundsAtCoords({rowStart:e.rowStart,colStart:e.colStart,colEnd:e.colStart,rowEnd:e.rowStart}),r=+!t.br.x,i=+!t.br.y,a=this._optionsMovable.getBoundsAtCoords({colStart:e.colEnd+r,rowStart:e.rowEnd+i,colEnd:e.colEnd+r,rowEnd:e.rowEnd+i}),o=Math.min(n.x+(t?.tl.x??0),n.x+n.width),s=Math.min(n.y+(t?.tl.y??0),n.y+n.height);return{x:o,y:s,width:Math.min(a.x+(t?.br.x??0),a.x+a.width)-o,height:Math.min(a.y+(t?.br.y??0),a.y+a.height)-s}}getBounds(){let e=this._getState(),t=this.getFirstAnchorCoords();if(!e||!t)return null;let n=e.pixelBounds,r=this.getAnchorType();if(n&&r===ev.Type.Absolute)return n;let i=this._calcAbsoluteBounds(t,e.offsets);return n&&r===ev.Type.OneCell&&(i.width=n.width,i.height=n.height),i}setAnchorType(e){return n.CommonUtils.validEnumValue(ev.Type,e),this._updateState({anchorType:e,pixelBounds:e===ev.Type.TwoCell?null:this.getBounds()},{description:(0,n.messageKey)(`op.setMovableResizeBehavior`)},[`onAnchorTypeChange`]),this}_processContainerShift(e){let r=this.getAnchorType(),i=this._getState()?.offsets,a=i,o=!1,s=e.before,c=e.axis===t.IRange.Axis.Column,l=e.intersect,u=e.amount,d=e.after;if(r!==ev.Type.Absolute){let e=c?l.colStart:l.rowStart,t=c?s.colStart:s.rowStart;r===ev.Type.TwoCell&&(t=c?s.colEnd:s.rowEnd),o=e<=t}if(o&&(r!==ev.Type.OneCell||d)||(d=s),o&&d&&u<0&&(c?(l.colStart<=s.colStart&&l.colEnd>=s.colStart&&(a={...a,tl:{...a.tl,x:0}}),a.br.x>0&&l.colStart<=s.colEnd&&l.colEnd>=s.colEnd&&(a={...a,br:{...a.br,x:0}},d={...d,colEnd:d.colEnd+1})):(l.rowStart<=s.rowStart&&l.rowEnd>=s.rowStart&&(a={...a,tl:{...a.tl,y:0}}),a.br.y>0&&l.rowStart<=s.rowEnd&&l.rowEnd>=s.rowEnd&&(a={...a,br:{...a.br,y:0}},d={...d,rowEnd:d.rowEnd+1}))),d===null&&!this._content.isDeleted()){let e=this._processContainerRemoved();if(e){let t=this._locationFromAnchor(e);a=t.offsets,d=t.anchorCoords}}if(d!==null){let{offsets:e,anchorCoords:t}=this._updateMovableLocation({anchorCoords:d,offsets:a});a=e,d=t}let f=null,p=this._beginCommit((0,n.messageKey)(`op.shiftingMovableBounds`));try{if(i!==a||!n.CoordUtils.isEqualRanges(s,d)){let e={offsets:a,anchorCoords:d};this._updateState(e)}f=super._processContainerShift({...e,after:d}),d||this._content.isDeleted()||this._content.delete(),p.commit()}catch(e){throw p.rollback(),e}return f}_processContainerRemoved(){return null}_locationFromAnchor(e){let t=e.tl,n=e.br,r={tl:{x:t.x??0,y:t.y??0},br:{x:n.x??0,y:n.y??0}},i=t.c??0,a=t.r??0;return{offsets:r,anchorCoords:{colStart:i,rowStart:a,colEnd:Math.max(i,(n.c??0)+(r.br.x>0?0:-1)),rowEnd:Math.max(a,(n.r??0)+(r.br.y>0?0:-1))}}}_processContainerLayout(){let e=this.getFirstAnchorCoords();if(e){if(this.getAnchorType()!==ev.Type.TwoCell){let t=this._getState()?.offsets,r=this._updateMovableLocation({anchorCoords:e,offsets:t});if(r&&(!n.CoordUtils.isEqualRanges(e,r.anchorCoords)||!hk(t,r.offsets))){let e=this._beginCommit((0,n.messageKey)(`op.updatingMovableBounds`));try{this._updateState({offsets:r.offsets,anchorCoords:r.anchorCoords},null,null,!0),e.amend()}catch(t){throw e.rollback(),t}}}super._processContainerLayout(),this._getEmitter().notify(`onBoundsChange`)}}_processAnchorCoords(){super._processAnchorCoords()}enrichOffset(e,t,r){if(e.r!==void 0&&e.c!==void 0)return e;let i=(e?.x??0)+t,a=(e?.y??0)+r,o=this._optionsMovable.getCoordsAtBounds({x:i,y:a,width:0,height:0}),s=this._optionsMovable.getBoundsAtCoords(o);return(e={...e}).c===void 0&&(e.c=o.colStart,e.x=n.CommonUtils.roundAccurately(i-s.x,1)),e.r===void 0&&(e.r=o.rowStart,e.y=n.CommonUtils.roundAccurately(a-s.y,1)),e}_fromJSON(e){let t=mk(),r={...n.CoordUtils.EmptyRange},i=e.anchor,a=i?.tl??n.CommonUtils.EmptyObject,o=i?.br??n.CommonUtils.EmptyObject,s={c:a.c,r:a.r,x:a.x,y:a.y},c={c:o.c,r:o.r,x:o.x,y:o.y},l=e.anchorType;s.r!=null&&s.c!=null||(l??=ev.Type.Absolute);let u=s.x=s.x??0,d=s.y=s.y??0;if(s=this.enrichOffset(s,0,0),c.x=c.x??0,c.y=c.y??0,c.r==null||c.c==null){l??=ev.Type.OneCell;let e=this._optionsMovable.getBoundsAtCoords({rowStart:s.r,colStart:s.c,colEnd:s.c,rowEnd:s.r}),t=this.enrichOffset(c,e.x+s.x,e.y+s.y);c.r??(c.r=t.r,c.y=t.y),c.c??(c.c=t.c,c.x=t.x)}c=this.enrichOffset(c,u,d),t.tl=s,t.br=c,r.colStart=s.c,r.rowStart=s.r,r.colEnd=Math.max(r.colStart,c.c+(t.br.x>0?0:-1)),r.rowEnd=Math.max(r.rowStart,c.r+(t.br.y>0?0:-1));let f=this._beginCommit((0,n.messageKey)(`op.loadMovable`));l??=ev.Type.TwoCell;let p={offsets:t,hidden:e.hidden??!1,rotation:e.rotation??0,lockAspectRatio:e.lockAspect??null,anchorType:l};l!==ev.Type.TwoCell&&(p.pixelBounds=this._calcAbsoluteBounds(r,t)),this._updateState(p,{description:(0,n.messageKey)(`op.loadMovable`)}),this._optionsMovable.setContainerCoords?.(r),f.commit()}_getAnchorJSON(){let e=this._getState(),t=e.anchorCoords,r=e.offsets,i={tl:{c:t.colStart,r:t.rowStart},br:{c:t.colEnd+ +!r?.br?.x,r:t.rowEnd+ +!r?.br?.y}};return r&&(r.tl?.x&&(i.tl.x=n.CommonUtils.roundAccurately(r.tl.x,1)),r.tl?.y&&(i.tl.y=n.CommonUtils.roundAccurately(r.tl.y,1)),r.br?.x&&(i.br.x=n.CommonUtils.roundAccurately(r.br.x,1)),r.br?.y&&(i.br.y=n.CommonUtils.roundAccurately(r.br.y,1))),i}toJSON(e){let t=this._getState(),r=this._content.toJSON(e)??{},i={anchor:this._getAnchorJSON(),content:{type:this._content.getType(),json:r}},a=this._content.getName?.();a&&(i.content.name=a);let o=this._content.getDescription();o&&(i.content.description=o);let s=t.anchorType;return s&&s!==ev.Type.TwoCell&&(i.anchorType=this.getAnchorType()),t.hidden&&(i.hidden=t.hidden),t.rotation!==void 0&&t.rotation!==0&&(i.rotation=t.rotation),n.CommonUtils.isDefined(t.lockAspectRatio)&&t.lockAspectRatio!==this._optionsMovable.defaultLockAspectRatio&&(i.lockAspect=t.lockAspectRatio),i}get isIMovable(){return!0}},mk=()=>({tl:{x:0,y:0},br:{x:0,y:0}}),hk=(e,t)=>e===t||!(!e||!t)&&e.tl.x===t.tl.x&&e.tl.y===t.tl.y&&e.br.x===t.br.x&&e.br.y===t.br.y,gk=class extends S{constructor(e,t,n,r,i,a){super(),this._add=e,this._getItemsDelegate=t,this._getCount=n,this._updateSelected=r,this._addListeners=i,this._addPicture=a}async add(e){return this._add(e)}_getItems(e){return this._getItemsDelegate(e)}getCount(){return this._getCount()}updateSelected(e,t){return this._updateSelected(e,t)}addListeners(e,t){return this._addListeners(e,t)}addPicture(e,t){return this._addPicture(e,t)}get isIMovableCollection(){return!0}},_k={type:`chart`},vk=class extends S{constructor(e){super(),this._movables=e}_getItems(){return this._movables.getItems(_k).map(e=>e.getContent())}getByName(e){if(typeof e!=`string`)return null;let t=e.toLocaleLowerCase(),n=this._movables.getItems(_k),r=n.length;for(let e=0;e<r;e++){let r=n[e].getContent();if(r.getName?.()?.toLocaleLowerCase()===t)return r}return null}addListeners(e,t){let n=this,r=e.onCollectionChange,i=e.onInvalidated;return this._movables.addListeners({onCollectionChange:r?()=>{r(n)}:void 0,onInvalidated:i?()=>{i(n)}:void 0},t)}get isIChartCollection(){return!0}},yk=/^[^a-zA-Z_\\]+$/,bk=/^[^a-zA-Z0-9_.]+$/,xk=class extends S{constructor(e){super(e.transactions),this._lastLookup=n.CommonUtils.EmptyArray,this._lastLookupAddress=null,this._lastLookupType=null,this._lastIncludeHidden=!1,this._lastAllowExtrudes=!1,this._lastLookupName=void 0,this._lastLookupScope=void 0,this._lastLookupHasScope=!1,this._sources=n.CommonUtils.EmptyArray,this._sourcesRemoveListeners=[],this._options={...e},this._getSources=e.getSources??null,this._transactions=this._options.transactions??new g({transient:!0})}_resolveSources(){if(!this._getSources||this.isClosed())return this._sources;let e=this._getSources()??n.CommonUtils.EmptyArray,t=this._sources;if(e.length===t.length){let n=!0;for(let r=0;r<e.length;r++)if(e[r]!==t[r]){n=!1;break}if(n)return t}let r=this,i=this._sourcesRemoveListeners.length;for(let e=0;e<i;e++)this._sourcesRemoveListeners[e]?.();this._sourcesRemoveListeners=[],this._sources=e;let a=e.length;for(let t=0;t<a;t++)this._sourcesRemoveListeners.push(e[t].addListeners({onCollectionChange:()=>{r.isClosed()||(r._invalidateLookup(),r._notifyCollectionChange())},onInvalidated:()=>{r.isClosed()||(r._invalidateLookup(),r._notifyInvalidated())}},{transactional:!1}));return this._invalidateLookup(),e}_getOwningSource(){let e=this._resolveSources(),t=e.length;for(let n=0;n<t;n++)if(e[n].add)return e[n];return null}_getItems(e){if(this.isClosed())return n.CommonUtils.EmptyArray;let t,r,i,a,o,s=null,c=!1;if(e&&(s=e.address??null,t=e.allowExtrudes??void 0,r=e.type??void 0,i=e.includeHidden??void 0,a=e.name??void 0,c=`scope`in e,o=c?e.scope??null:void 0,s===this._lastLookupAddress&&r===this._lastLookupType&&i===this._lastIncludeHidden&&t===this._lastAllowExtrudes&&a===this._lastLookupName&&o===this._lastLookupScope&&c===this._lastLookupHasScope))return this._lastLookup;this._lastLookupAddress=s,this._lastLookupType=r,this._lastIncludeHidden=i,this._lastAllowExtrudes=t??void 0,this._lastLookupName=a,this._lastLookupScope=o,this._lastLookupHasScope=c;let l=null;if(s){let e=this._options.addressToRanges(s);if(!e)return n.Notifier.debug(`Invalid range`,{meta:{type:`error`,address:s}}),this._lastLookup=null,null;l=e.getCoords()}let u=this._collectCandidates(l,t);if(u.length===0)return this._lastLookup=n.CommonUtils.EmptyArray,n.CommonUtils.EmptyArray;let d=a?.toLowerCase(),f=[],p=u.length;for(let e=0;e<p;e++){let t=u[e];r&&t.getType()!==r||!i&&t.isHidden()||d&&t.getName().toLowerCase()!==d||c&&t.getScope()!==o||f.push(t)}return f=f.sort((e,t)=>{let n=e.getType().localeCompare(t.getType());return n===0?e.getName().localeCompare(t.getName()):n}),this._lastLookup=f,f}getByRanges(e,t){return this._getByRanges(e,t,null)}_getByRanges(e,t,r){if(this.isClosed())return n.CommonUtils.EmptyArray;let i=this._qualifyCoords(e,r);if(!i)return n.CommonUtils.EmptyArray;let a=this.getItems(t),o=a?a.length:0;if(o===0)return n.CommonUtils.EmptyArray;let s=[],c=[];for(let e=0;e<o;e++){let r=a[e],o=null;try{o=r.getRanges?.()?.getCoords()??null}catch{}if(o&&n.CoordUtils.isEqualRangesArrays(o.slice().sort(n.CoordUtils.rowFirstRangeComparator),i)){s.push(r.getName());continue}if(!t?.includeParts)continue;let l=r.getPartReference?.(i,t?.home??null)??null;l&&c.push(l)}for(let e=0;e<c.length;e++)s.push(c[e]);return s}_qualifyCoords(e,t){let r=null;try{r=(t?t.getRanges(e):this._options.addressToRanges(e))?.getCoords()??null}catch{return null}if(!r||r.length===0)return null;let i=t?t.getName():this._currentScope();return r.map(e=>e.scope?e:{...e,scope:i}).sort(n.CoordUtils.rowFirstRangeComparator)}_collectCandidates(e,t){let r=this._resolveSources(),i=r.length;if(i===0)return n.CommonUtils.EmptyArray;let a=[];for(let n=0;n<i;n++){let i=r[n].getItems(),o=i.length;for(let n=0;n<o;n++){let r=i[n];r&&(e&&!this._matchesCoords(r,e,t)||a.push(r))}}return a}_matchesCoords(e,t,r){let i=null;try{i=e.getRanges?.()?.getCoords()??null}catch{return!1}if(!i||i.length===0)return!1;let a=t.length,o=i.length;for(let e=0;e<a;e++){let a=t[e],s=a.scope;for(let e=0;e<o;e++){let t=i[e];if(t&&(!s||!t.scope||t.scope===s)){if(r){if(n.CoordUtils.isRangesIntersect(t,a))return!0}else if(n.CoordUtils.isRangeWithinRange(t,a))return!0}}}return!1}getByName(e,t=!1){return this._getByName(e,t,this._currentScope())}_getByName(e,t=!1,n=null){if(!e||this.isClosed()||typeof e!=`string`)return null;let r=e.toLowerCase();return this._findInSources(e=>e.getName().toLowerCase()===r,t?void 0:n??void 0)}_currentScope(){return this._options.getCurrentScope?.()??null}_scopedTo(e){let t=this,n=new Map;return new Proxy(t,{get:(r,i)=>{if(i===`getItems`)return n=>((e,t)=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i].getScope();a?a===t&&n.push(e[i]):r.push(e[i])}if(n.length===0)return r.slice();let i=new Map;for(let e=0;e<r.length;e++)i.set(r[e].getName().toLowerCase(),r[e]);for(let e=0;e<n.length;e++)i.set(n[e].getName().toLowerCase(),n[e]);return Array.from(i.values())})(t.getItems(n),e.getName());if(i===`getByName`)return(n,r)=>t._getByName(n,r,e.getName());if(i===`getByRanges`)return(n,r)=>t._getByRanges(n,r,e);if(i===`addFormula`)return(n,r,i)=>t._addFormula(n,r,i,e.getName());let a=Reflect.get(t,i,t);if(typeof a!=`function`)return a;let o=n.get(i);return o||(o=a.bind(t),n.set(i,o)),o}})}getById(e){return e?this.isClosed()?null:this._findInSources(t=>t.getId()===e):null}_findInSources(e,t){let n=t?.toLowerCase(),r=null,i=this._resolveSources(),a=i.length;for(let t=0;t<a;t++){let a=i[t].getItems(),o=a.length;for(let t=0;t<o;t++){let i=a[t];if(!i||!e(i))continue;let o=i.getScope();if(o){if(n&&o.toLowerCase()===n)return i}else r||=i}}return r}_findInSourcesByKey(e,t){let n=e.toLowerCase().trim(),r=t?t.toLowerCase():null,i=this._resolveSources(),a=i.length;for(let e=0;e<a;e++){let t=i[e].getItems(),a=t.length;for(let e=0;e<a;e++){let i=t[e];if(!i||i.getName().toLowerCase().trim()!==n)continue;let a=i.getScope();if((a?a.toLowerCase():null)===r)return i}}return null}findValidName(e,t=null,r=!1){if(!e)throw Error((0,n.t)(`error.named.templateRequired`));let i=this,a=e=>{try{return i._validateName(e,t,r),!0}catch{}return!1};return a(e)?e:T(e,a)}validateName(e,t=null,n=!1){return this._validateName(e,t,n)}_validateName(e,t,r=!1){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`));if(!e||e.length===0)throw Error((0,n.t)(`error.named.nameEmpty`));if(e.length>255)throw Error((0,n.t)(`error.named.nameMaxLength`));if(e.indexOf(` `)!==-1)throw Error((0,n.t)(`error.named.containsSpaces`));let i=e.trim().toLowerCase(),a=i.substring(1,e.length-1);if(new RegExp(yk).test(i[0]))throw Error((0,n.t)(`error.named.invalidFirstChar`));if(new RegExp(bk).test(a))throw Error((0,n.t)(`error.named.invalidTrailingChar`));if(i.length===1&&(i[0]===`r`||i[0]===`c`))throw Error((0,n.t)(`error.named.invalidSpecialRC`));if(function(e,t=ed,n=$u,r=!1){let i=jd(e,r);if(!i||i[2]||!i[1])return!1;let a=Od(e,Md);if(!a)return!1;let o=a.rowIndex;if(o<0||o>t)return!1;let s=a.colIndex;return!(s<0||s>=n)}(e))throw Error((0,n.t)(`error.named.invalidInvalidCellAddress`));let o=e.toLowerCase()?.trim();t&&(o=o+`:`+t.toLowerCase());let s=this._findInSourcesByKey(e,t);if(s){let i=s.getRanges?.()??null;if(!r||i&&i.getCount()>0)throw Error(t?(0,n.t)(`error.named.nameExistsInScope`,{name:e,scope:t}):(0,n.t)(`error.named.nameExists`,{name:e}))}}addFormula(e,t,n=!1){return this._addFormula(e,t,n,null)}_addFormula(e,t,r=!1,i=null){let a=this._getOwningSource();if(!a?.add)throw Error(`Cannot define '${e}': no calculation engine is attached to these names.`);if(this._options.isReadOnly?.())throw Error((0,n.t)(`error.named.nameReadonly`));return this._validateName(e,i,r),a.add({name:e,expression:t,replaceExisting:r,scope:i})}beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_invalidateLookup(){this._lastLookup=n.CommonUtils.EmptyArray,this._lastLookupAddress=null,this._lastLookupType=null,this._lastLookupName=void 0,this._lastLookupScope=void 0,this._lastLookupHasScope=!1}addListeners(e,t){return this._resolveSources(),super.addListeners(e,t)}close(){if(this.isClosed())return;this._close();let e=this._sourcesRemoveListeners.length;for(let t=0;t<e;t++)this._sourcesRemoveListeners[t]?.();this._sourcesRemoveListeners=[]}get isINamedCollection(){return!0}},Sk=class e extends cO{static{this.instanceCounter=0}constructor(t){super(t),this._getMovable=t.getMovable??null;let n=t.name??null;!n&&this._getMovable&&(n=`${this.getTypeDescription()} ${++e.instanceCounter}`);let r=t.description??null;n===null&&r===null||this._updateState({name:n,description:r})}getName(){return this._closed?null:this._getState()?.name??null}setName(e){let t={description:(0,n.messageKey)(`op.setMovableName`)};return this._protectionCheck(t.description),this._updateState({name:e},t,[`onAnyChange`]),this}getDescription(){return this._closed?null:this._getState()?.description??null}setDescription(e){let t={description:(0,n.messageKey)(`op.setMovableDescription`)};return this._protectionCheck(t.description),this._updateState({description:e||null},t,[`onAnyChange`]),this}getMovable(){return this._getMovable?.()??null}_protectionCheck(e){if(this.isReadOnly())throw new n.ProtectedError(HD(e))}},Ck=class extends Sk{constructor(e){if(super(e),e.resource)this._resource=e.resource;else{if(!e.json)throw Error(`Resource is required to create Picture.`);this._resource=e.fromResourceId(e.json.resId)}}getType(){return`picture`}toJSON(e){let t={},n=e?.(this._resource);n!==null&&(t.resId=n);let r=this._getState();return r&&r.effects&&(t.effects=r.effects),t}getTypeDescription(){return`Picture`}async _asDataUrl(){if(this._dataUrl)return this._dataUrl;let e=await this.getDetails(),t=await n.ImageUtils.getImageDataUrl(e.asUrl());return this._dataUrl=t.dataUrl,this._dataUrl}toHtml(){return null}async toImage(){let e=await this.toArrayBuffer();return new Blob([e],{type:n.MimeType.Png})}async toArrayBuffer(){let e=(await this._asDataUrl()).substring(n.ImageUtils.DATA_URL_PNG_PREFIX.length);return n.BufferUtils.base64ToArrayBuffer(e)}getResource(){return this._resource}async getDetails(){return this._details||=new Promise(async(e,t)=>{try{let t=await this._resource.toBuffer(),r=await this._resource.getType(),i=await n.ImageUtils.loadImageDetails(t,r?.mime);e({getNaturalSize:()=>i.naturalSize,asUrl:()=>i.asUrl,asSVGText:()=>i.asSVGText})}catch(e){t(e)}}),this._details}_getActionDescription(e){return(0,n.messageKey)(`op.deletePicture`)}_fromDrawingJSON(e,t){this._resource?.deleteReference(this),this._resource=t?.(e.resId),this._resource.addReference(this)}_toDrawingJSON(e){let t={},n=e?.(this._resource);return n!==null&&(t.resId=n),t}_processDelete(){super._processDelete()}get isIPicture(){return!0}};(function(e){let t=e.fromJSON=(e,n)=>{if(!e?.id)return null;let r={id:e.id,type:e.type};if(e.xml!==void 0&&(r.xml=e.xml),e.contentType!==void 0&&(r.contentType=e.contentType),e.name!==void 0&&(r.name=e.name),e.resId!==void 0){let t=n?.(e.resId);t&&(r.resource=t)}let i=e.parts;if(i){let e=[];for(let r=0;r<i.length;r++){let a=t(i[r],n);a&&e.push(a)}e.length>0&&(r.parts=e)}return r},n=e.toJSON=(e,t)=>{if(!e)return null;let r={id:e.id,type:e.type};if(e.xml!==void 0&&(r.xml=e.xml),e.contentType!==void 0&&(r.contentType=e.contentType),e.name!==void 0&&(r.name=e.name),e.resource){let n=t?.(e.resource);n!=null&&(r.resId=n)}let i=e.parts;return i&&i.length>0&&(r.parts=i.map(e=>n(e,t))),r}})(fk||={});var wk,Tk=/<!\[CDATA\[([\s\S]*?)\]\]>|<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<(\/?)([^\s/>]+)((?:\s+[^\s=/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>|([^<]+)/g,Ek={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`},Dk=e=>e.indexOf(`&`)===-1?e:e.replace(/&(#x[0-9a-fA-F]+|#\d+|\w+);/g,(e,t)=>{if(t[0]!==`#`)return Ek[t]??e;let n=t[1]===`x`?parseInt(t.slice(2),16):parseInt(t.slice(1),10);return Number.isFinite(n)?String.fromCodePoint(n):e}),Ok=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`),kk=e=>{let t=e.indexOf(`:`);return t===-1?e:e.slice(t+1)},Ak=e=>{let t={name:``,attrs:``,children:[],contentStart:0,contentEnd:e.length},n=[t];Tk.lastIndex=0;for(let t=Tk.exec(e);t;t=Tk.exec(e)){let e=n[n.length-1];if(t[1]!==void 0)e.children.push(t[1]);else if(t[6]!==void 0)e.children.push(Dk(t[6]));else if(t[3]!==void 0){if(t[2]){n.length>1&&(n.pop().contentEnd=t.index);continue}let r=t.index+t[0].length,i={name:kk(t[3]),attrs:t[4]??``,children:[],contentStart:r,contentEnd:r};e.children.push(i),t[5]||n.push(i)}}return t.children.find(e=>typeof e!=`string`)??null},jk=(e,t)=>{let n=RegExp(`(?:^|\\s)${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(e.attrs);return n?Dk(n[1]??n[2]??``):null},Mk=e=>e.children.filter(e=>typeof e!=`string`),Nk=(e,t)=>Mk(e).find(e=>e.name===t)??null,Pk=(e,...t)=>{let n=e;for(let e=0;n&&e<t.length;e++)n=Nk(n,t[e]);return n},Fk=e=>{let t=``;for(let n of e.children)typeof n==`string`&&(t+=n);return t},Ik=e=>{let t=Nk(e,`Fallback`)??Nk(e,`Choice`);return t?Mk(t):[]},Lk=new Set([`pPr`,`rPr`,`endParaRPr`,`bodyPr`,`lstStyle`]),Rk=e=>{let t=``,n=e=>{if(Lk.has(e.name))return;if(e.name===`br`)return void(t+=`
|
|
62
|
-
`);if(e.name===`t`)return void(t+=Fk(e));let r=e.name===`AlternateContent`?Ik(e):Mk(e);for(let e of r)n(e)};for(let t of Mk(e))n(t);return t},zk=e=>{let t=Mk(e).filter(e=>e.name===`p`).map(Rk),n=0,r=t.length;for(;n<r&&t[n].trim()===``;)n++;for(;r>n&&t[r-1].trim()===``;)r--;return t.slice(n,r).join(`
|
|
63
|
-
`)},Bk=Object.freeze({text:null,slot:null}),Vk=Object.freeze({slot:null,literal:null}),Hk={areaChart:`area`,area3DChart:`area`,barChart:`column`,bar3DChart:`column`,lineChart:`line`,line3DChart:`line`,pieChart:`pie`,pie3DChart:`pie`,doughnutChart:`doughnut`,ofPieChart:`pieOfPie`,scatterChart:`scatter`,bubbleChart:`bubble`,radarChart:`radar`,stockChart:`stock`,surfaceChart:`surface`,surface3DChart:`surface`},Uk={catAx:`category`,valAx:`value`,dateAx:`date`,serAx:`series`},Wk={clusteredColumn:`histogram`,regionMap:`map`},Gk=(e,t)=>{let n=e?Nk(e,t):null;return n?jk(n,`val`):null},Kk=e=>{let t=Hk[e.name];e.name===`barChart`||e.name===`bar3DChart`?Gk(e,`barDir`)===`bar`&&(t=`bar`):e.name===`ofPieChart`&&Gk(e,`ofPieType`)===`bar`&&(t=`barOfPie`);let n=Gk(e,`grouping`);return n===`stacked`?`${t}Stacked`:n===`percentStacked`?`${t}PercentStacked`:t},qk=e=>{let t=Nk(e,`strCache`)??Nk(e,`numCache`),n=t?Pk(t,`pt`,`v`):null;return n?Fk(n):null},Jk=e=>{let t=e.name===`strLit`;return`{${Mk(e).filter(e=>e.name===`pt`).map(e=>{let n=Nk(e,`v`),r=n?Fk(n):``;return t?`"${r.replace(/"/g,`""`)}"`:r}).join(`,`)}}`},Yk=class{constructor(){this.slots=[],this._slotByElement=new Map}collectSlots(e){for(let t of Mk(e))t.name===`f`?t.contentEnd<=t.contentStart||Mk(t).length>0||(this._slotByElement.set(t,this.slots.length),this.slots.push({text:Fk(t),start:t.contentStart,end:t.contentEnd})):this.collectSlots(t)}slotOf(e){let t=e?Nk(e,`f`):null;return t?this._slotByElement.get(t)??null:null}readText(e){let t=e?Nk(e,`tx`):null;if(!t)return Bk;let n=Nk(t,`rich`);if(n)return{text:zk(n)||null,slot:null};let r=Nk(t,`strRef`)??Nk(t,`txData`);if(r){let e=r.name===`txData`?Nk(r,`v`):null;return{text:(e?Fk(e):qk(r))||null,slot:this.slotOf(r)}}let i=Nk(t,`v`);return i?{text:Fk(i)||null,slot:null}:Bk}readSource(e){if(!e)return Vk;for(let t of Mk(e)){if(t.name===`numLit`||t.name===`strLit`)return{slot:null,literal:Jk(t)};let e=this.slotOf(t);if(e!==null)return{slot:e,literal:null}}return Vk}},Xk=(e,t)=>{let n=Nk(t,`chart`),r=n?Nk(n,`plotArea`):null,{axes:i,primaryId:a}=r?((e,t)=>{let n=[],r=null;for(let i of Mk(t)){let t=Uk[i.name];if(!t||(r===null&&(r=Gk(i,`axId`)),Gk(i,`delete`)===`1`))continue;let a=Nk(i,`numFmt`);n.push({kind:t,title:e.readText(Nk(i,`title`)),numberFormat:a?jk(a,`formatCode`):null})}return{axes:n,primaryId:r}})(e,r):{axes:[],primaryId:null},o=[],s=new Set;for(let t of r?Mk(r):[]){if(!Hk[t.name])continue;let n=Kk(t);s.add(n);let r=Mk(t).filter(e=>e.name===`axId`).map(e=>jk(e,`val`)),i=r.length>0&&a!==null&&!r.includes(a);for(let r of Mk(t)){if(r.name!==`ser`)continue;let t=parseInt(Gk(r,`order`)??``,10);o.push({order:Number.isFinite(t)?t:o.length,facts:{type:n,name:e.readText(r),values:e.readSource(Nk(r,`val`)??Nk(r,`yVal`)),categories:e.readSource(Nk(r,`cat`)??Nk(r,`xVal`)),secondary:i}})}}o.sort((e,t)=>e.order-t.order);let c=Pk(t,`pivotSource`,`name`);return{type:s.size===0?`unknown`:s.size===1?[...s][0]:`combo`,title:e.readText(n?Nk(n,`title`):null),series:o.map(e=>e.facts),axes:i,pivotSource:c&&Fk(c)||null}},Zk=(e,t)=>{let n=Nk(t,`chart`),r=n?Nk(n,`plotArea`):null,i=r?Nk(r,`plotAreaRegion`):null,a=new Map,o=Nk(t,`chartData`);for(let e of o?Mk(o):[])e.name===`data`&&a.set(jk(e,`id`)??``,e);let s=(t,n)=>{for(let r of t?Mk(t):[]){if(r.name!==`numDim`&&r.name!==`strDim`||!n.includes(jk(r,`type`)??``))continue;let t=e.slotOf(r);if(t!==null)return{slot:t,literal:null}}return Vk},c=[],l=new Set;for(let t of i?Mk(i):[]){if(t.name!==`series`)continue;let n=jk(t,`layoutId`)??`unknown`,r=Wk[n]??n;l.add(r);let i=a.get(Gk(t,`dataId`)??``);c.push({type:r,name:e.readText(t),values:s(i,[`val`,`size`]),categories:s(i,[`cat`,`x`]),secondary:!1})}l.delete(`paretoLine`)&&l.delete(`histogram`)&&l.add(`pareto`);let u=[];for(let t of r?Mk(r):[]){if(t.name!==`axis`||jk(t,`hidden`)===`1`)continue;let n=Nk(t,`numFmt`);u.push({kind:Nk(t,`catScaling`)?`category`:`value`,title:e.readText(Nk(t,`title`)),numberFormat:n?jk(n,`formatCode`):null})}return{type:l.size===0?`unknown`:l.size===1?[...l][0]:`combo`,title:e.readText(n?Nk(n,`title`):null),series:c,axes:u,pivotSource:null}},Qk=class extends Sk{constructor(e){super(e),this._part=null,this._factsSource=null,this._facts=null,this._series=null,this._axes=null,this._held=null,this._getRange=e.getRange??null,e.json&&(this._part=fk.fromJSON(e.json.part,e.fromResourceId),this._updateState({data:e.json})),this._part?.xml&&e.holdFormulas&&(this._held=e.holdFormulas(()=>this._closed||this.isDeleted()?[]:this._getFacts()?.slots.map(e=>e.text)??[]))}getType(){return`chart`}_getFacts(){let e=this._part?.xml??null;return e!==this._factsSource&&(this._factsSource=e,this._facts=e?(e=>{let t=Ak(e);if(!t||t.name!==`chartSpace`)return null;let n=new Yk;return n.collectSlots(t),{...Nk(t,`chartData`)?Zk(n,t):Xk(n,t),slots:n.slots}})(e):null,this._series=null,this._axes=null),this._facts}_formulaAt(e){return e===null?null:this._held?.getText(e)??this._getFacts()?.slots[e]?.text??null}_formulaOf(e){return e.slot===null?e.literal:this._formulaAt(e.slot)}_rangeAt(e){let t=this._formulaAt(e);if(!t||!this._getRange||!bd(t))return null;try{return this._getRange(t)}catch{return null}}_textOf(e){if(e.slot===null)return e.text;let t=this._rangeAt(e.slot);if(t?.isSingleCell())try{return t.getCell().getText(eA)||null}catch{}return e.text}getChartTitle(){let e=this._getFacts();if(e)return this._textOf(e.title);let t=this._getState()?.data?.title?.text?.runs;if(!Array.isArray(t))return null;let n=``;for(let e=0;e<t.length;e++)typeof t[e]?.text==`string`&&(n+=t[e].text);return n||null}getChartType(){let e=this._getFacts();return e?e.type:(this._getState()?.data)?.types?.[0]?.type??`unknown`}getSeries(){let e=this._getFacts();if(!e)return $k;if(!this._series){let t=this;this._series=Object.freeze(e.series.map(e=>Object.freeze({getName:()=>t._textOf(e.name),getNameFormula:()=>t._formulaAt(e.name.slot),getValuesFormula:()=>t._formulaOf(e.values),getCategoriesFormula:()=>t._formulaOf(e.categories),getNameRange:()=>t._rangeAt(e.name.slot),getValuesRange:()=>t._rangeAt(e.values.slot),getCategoriesRange:()=>t._rangeAt(e.categories.slot),getChartType:()=>e.type,isSecondaryAxis:()=>e.secondary})))}return this._series}getAxes(){let e=this._getFacts();if(!e)return tA;if(!this._axes){let t=this;this._axes=Object.freeze(e.axes.map(e=>Object.freeze({getKind:()=>e.kind,getTitle:()=>t._textOf(e.title),getNumberFormat:()=>e.numberFormat})))}return this._axes}getPivotSource(){return this._getFacts()?.pivotSource??null}getXML(){let e=this._part?.xml??null,t=this._held,n=e&&t?this._getFacts():null;return e&&t&&n?((e,t,n)=>{let r=e;for(let e=t.length-1;e>=0;e--){let i=n[e];i!=null&&i!==t[e].text&&(r=r.slice(0,t[e].start)+Ok(i)+r.slice(t[e].end))}return r})(e,n.slots,n.slots.map((e,n)=>t.getText(n))):e}toJSON(e){let t=this._getState();if(!t?.data)return null;let n={...t.data},r=fk.toJSON(this._part,e);if(r){let e=this.getXML();e!==null&&(r.xml=e),n.part=r}else delete n.part;return n}getTypeDescription(){return`Chart`}_processDelete(){this._held?.release(),super._processDelete()}get isIChart(){return!0}},$k=Object.freeze([]),eA=Object.freeze({hideStringPrefix:!0}),tA=Object.freeze([]),nA=(e,t)=>{if(e.name===`txBody`)return void t.push(e);let n=e.name===`AlternateContent`?Ik(e):Mk(e);for(let e of n)nA(e,t)},rA=e=>{let t=Ak(e);if(!t)return null;let n=null,r=Nk(t,`spPr`);if(r){let e=Nk(r,`prstGeom`);e?n=jk(e,`prst`):Nk(r,`custGeom`)&&(n=`custom`)}let i=[];nA(t,i);let a=null;return i.length>0&&(a=i.map(zk).filter(e=>e!==``).join(`
|
|
64
|
-
`)),{element:t.name,geometry:n,text:a}},iA=class extends Sk{constructor(e){super(e),this._factsSource=null,this._facts=aA,e.json&&this._updateState({data:e.json})}getType(){return`shape`}getShapeType(){let e=this._getState()?.data,t=this._getFacts();if(t.source?.element===`grpSp`)return`group`;let n=e?.geometry;return typeof n==`string`?n:n?.geometry??t.source?.geometry??`rect`}getTextFrame(){return this._getFacts().textFrame}_getFacts(){let e=this._getState()?.data??null;if(e===this._factsSource)return this._facts;let t=e?.xml?rA(e.xml):null,n=t?.text??null;n!==null&&e?.fallbackXml&&(n=rA(e.fallbackXml)?.text||n);let r=n;return this._factsSource=e,this._facts={source:t,textFrame:r===null?null:Object.freeze({getText:()=>r})},this._facts}toJSON(e){let t=this._getState(),n=null;return t&&t.data&&(n=t.data),n}getTypeDescription(){return`Shape`}get[Symbol.toStringTag](){return`[Shape]`}toString(){return this.getTypeDescription()}},aA={source:null,textFrame:null},oA=class extends Sk{constructor(e){super(e),e.json&&this._updateState({data:e.json})}getType(){return`slicer`}toJSON(e){return this._getState(),null}getTypeDescription(){return`Slicer`}get[Symbol.toStringTag](){return`[Slicer]`}toString(){return this.getTypeDescription()}get isISlicer(){return!0}},sA=class extends Sk{constructor(e){super(e),e.json&&this._updateState({data:e.json,type:e.type})}getType(){return this._getState()?.type??`custom`}toJSON(e){let t=this._getState(),n=null;return t&&t.data&&(n=t.data),n}getTypeDescription(){return`CustomElement`}},cA=class extends Sk{constructor(e){super(e),this._part=null,e.json&&(this._part=fk.fromJSON(e.json.part,e.fromResourceId),this._updateState({data:e.json}))}getType(){return`control`}getShapeId(){return this._getState()?.data?.shapeId??null}getXML(){return this._part?.xml??null}toJSON(e){let t=this._getState();if(!t?.data)return null;let n={...t.data},r=fk.toJSON(this._part,e);return r?n.part=r:delete n.part,n}getTypeDescription(){return`Control`}get isIControl(){return!0}},lA=/&(amp|lt|gt|quot|apos|#x[0-9a-fA-F]+|#[0-9]+);/g,uA=(e,t)=>{switch(t){case`amp`:return`&`;case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:return`'`;default:return t.startsWith(`#x`)?String.fromCodePoint(parseInt(t.slice(2),16)):t.startsWith(`#`)?String.fromCodePoint(parseInt(t.slice(1),10)):e}},dA=class{constructor(e){this._name=e.json.name??null,this._sheet=e.sheet,this._cacheId=e.json.cacheId,this._part=fk.fromJSON(e.json.part,e.fromResourceId)}getName(){return this._name??=(e=>{if(!e)return``;let t=/<pivotTableDefinition\b[^>]*?\bname="([^"]*)"/.exec(e)?.[1];return t?t.replace(lA,uA):``})(this._part?.xml)}getSheet(){return this._sheet}getXML(){return this._part?.xml??null}getCacheId(){return this._cacheId}toJSON(e){let t={cacheId:this._cacheId},n=this.getName();n&&(t.name=n);let r=fk.toJSON(this._part,e);return r&&(t.part=r),t}get isIPivotTable(){return!0}},fA=class extends S{constructor(e){super(),this._getItemsDelegate=e}_getItems(){return this._getItemsDelegate()}getByName(e){if(typeof e!=`string`)return null;let t=e.toLocaleLowerCase(),n=this._getItemsDelegate(),r=n.length;for(let e=0;e<r;e++)if(n[e].getName().toLocaleLowerCase()===t)return n[e];return null}get isIPivotTableCollection(){return!0}};(wk||={}).Content={Values:`values`,Formats:`formats`,Formulas:`formulas`,Hyperlinks:`hyperlinks`,Tables:`tables`,Notes:`notes`,Comments:`comments`,DataValidations:`dataValidations`};function pA(e,t,n=!0,r=!0){let i=0,a=0;if(!n&&!r)return{x:i,y:a};let o=!1,s=0;do{let s={x:t.x+i,y:t.y+a,width:0,height:0},c=e.getItems({bounds:s});if(o=!1,c.length>0){for(let e=0;!o&&e<c.length;e++){let t=c[e].getBounds();t.x===s.x&&t.y===s.y&&(o=!0)}o&&(i+=n?16:0,a+=r?16:0)}}while(o&&++s<100);return{x:i,y:a}}function mA(e){if(!e||e.length<=1)return!1;if(e.length===2)return n.CoordUtils.isRangesIntersect(e[0],e[1]);let t=new yr;t.load(e);let r=e.length;for(let n=0;n<r;n++)if(t.search(e[n]).length>1)return!0;return!1}function hA(e,r,i){let a=[];if(n.CoordUtils.isRangesIntersect(e,r)){let o=n.CommonUtils.subtractRect({top:e.rowStart,left:e.colStart,bottom:e.rowEnd+1,right:e.colEnd+1},{top:r.rowStart,left:r.colStart,bottom:r.rowEnd+1,right:r.colEnd+1},i===t.IRange.Axis.Column),s=o.length;for(let e=0;e<s;e++){let t={colStart:o[e].left,rowStart:o[e].top,colEnd:o[e].right-1,rowEnd:o[e].bottom-1};a.push(t)}}else a.push(e);return a}function gA(e,t,r){if(!t||!e?.[0])return;let i=e.length;for(let a=0;a<i;a++){let i=e[a];n.CoordUtils.intersectRanges(i,t)&&r(i,!n.CoordUtils.isRangeWithinRange(i,t),a)}}function _A(e){return e?{colIndex:e.colStart,rowIndex:e.rowStart}:null}function vA(e,t){let n=e.colStart,r=e.rowStart,i=t.colStart,a=t.rowStart;return(e,t)=>{let o=e.colIndex-n,s=t.colIndex-i;return o===s?e.rowIndex-r-(t.rowIndex-a):o-s}}function yA(e,t){let n=e.colStart,r=e.rowStart,i=t.colStart,a=t.rowStart;return(e,t)=>{let o=e.rowIndex-r,s=t.rowIndex-a;return o===s?e.colIndex-n-(t.colIndex-i):o-s}}function bA(e,t,r=!1,i=!1){t||={...e};let a=t.colEnd-t.colStart+1,o=t.rowEnd-t.rowStart+1;if(i){let e=a;a=o,o=e}let s={...e};if(s.colEnd=e.colStart+a-1,s.rowEnd=e.rowStart+o-1,r){if(!n.CoordUtils.isSingleCell(e)){let t=e.colEnd-e.colStart,n=e.rowEnd-e.rowStart;s.colEnd=e.colStart+(i?n:t),s.rowEnd=e.rowStart+(i?t:n)}return s}let c=e.colEnd-e.colStart+1;if(c%a!==0)return s;let l=e.rowEnd-e.rowStart+1;return l%o!==0||(s.colEnd=e.colStart+c-1,s.rowEnd=e.rowStart+l-1),s}var xA,SA,CA=class extends S{constructor(e,t,n,r){super(),this._add=e,this._get=t,this._getByName=n,this._addListeners=r}add(e,t){if(!e)throw Error((0,n.t)(`error.table.tableNoBody`));return this._add(e,t)}_getItems(e){let t;e?.address&&(t=e.address);let n=this._get(t,e?.ignoreHidden,e?.fullyContained);if(e?.name){let t=e.name.toLocaleLowerCase();for(let e=0;e<n.length;e++)if(n[e].getName().toLocaleLowerCase()===t)return[n[e]]}return n}getByName(e){if(typeof e!=`string`)throw Error(`Get by name must take a valid name.`);return this._getByName(e)}addListeners(e,t){return this._addListeners(e,t)}get isITableCollection(){return!0}};function wA(e,r,i){let a=[];r?.ranges&&r.ranges.length>0?a=r.ranges:r?.cell&&(a=[n.CoordUtils.cellToRange(r.cell)]);let o=e===t.IRange.Axis.Column,s=o?i.rowStart:i.colStart,c=o?i.rowEnd:i.colEnd,l=[];for(let e=0;e<a.length;e++){let t=a[e],n=o?t.colStart:t.rowStart,r=o?t.colEnd:t.rowEnd,i=o?t.rowStart:t.colStart,u=o?t.rowEnd:t.colEnd;l=Tt(wt(l,{min:n,max:r,value:i<=s&&u>=c},{onUpdate:(e,t)=>!!e||!!t}))}return l}function TA(e,t,r){if(!e)return n.CoordUtils.EmptySelection;let i=t.cell,a=r.colStart,o=r.rowStart,s=r.colEnd,c=r.rowEnd,l=e?.cell;!l||n.CoordUtils.isEqualCells(i,l)&&l.scope===i?.scope||(i=Object.freeze({...l,colIndex:Math.max(a,Math.min(l.colIndex??t.cell?.colIndex??0,s)),rowIndex:Math.max(o,Math.min(l.rowIndex??t?.cell?.rowIndex??0,c))}));let u=e?.ranges?[...e.ranges]:[],d=!1,f=u.length,p=f===0;for(let e=0;e<f;e++){let t=u[e];t&&(u[e]=Object.freeze({...t,colStart:Math.max(a,Math.min(t.colStart,s)),rowStart:Math.max(o,Math.min(t.rowStart,c)),colEnd:Math.max(a,Math.min(t.colEnd,s)),rowEnd:Math.max(o,Math.min(t.rowEnd,c))}),p||=n.CoordUtils.isCellWithinRange(i,t),d||=Object.keys(t).length>4)}let m=t?.ranges??[];!d&&n.CoordUtils.isEqualRangesArrays(m,u)||(m=u);let h=e?.rangeIndex??t?.rangeIndex??n.CoordUtils.EmptySelection.rangeIndex;if(h=Math.max(-1,Math.min(h,m.length-1)),!p&&h>=0&&m[h]){let e=m[h],t=i.rowIndex;t<e.rowStart?t=e.rowStart:t>e.rowEnd&&(t=e.rowEnd);let n=i.colIndex;n<e.colStart?n=e.colStart:n>e.colEnd&&(n=e.colEnd),i=Object.freeze({...i,colIndex:n,rowIndex:t})}return Object.freeze({cell:i,ranges:m,rangeIndex:h})}function EA(e){if(!e)return null;let t=[];if(e.ranges&&e.ranges.length>0){let n=Math.max(0,Math.min(e.rangeIndex??0,e.ranges.length));for(let r=n;r<e.ranges.length;r++)t.push(e.ranges[r]);for(let r=0;r<n;r++)t.push(e.ranges[r])}else e.cell&&t.push(n.CoordUtils.cellToRange(e.cell));return t}function DA(e,t,r=-1){if(!e||e.length===0)return null;let i=e[0],a=e.length===1&&i.rowStart===i.rowEnd&&i.colStart===i.colEnd,o=r===-1?e.length-1:Math.min(Math.max(0,r),e.length-1);if(!t){let n=e[o];t={rowIndex:n.rowStart,colIndex:n.colStart}}return{cell:t,ranges:a?n.CommonUtils.EmptyArray:[...e],rangeIndex:a?-1:o}}(SA=xA||={}).fastStringToCol=kd,SA.fastStringToCell=Ed,SA.fastStringToRange=Ad,SA.rangeToString=(e,t,n)=>fd(e,t,n),SA.cellToString=ld,SA.normalizeA1ToR1C1=Hd,SA.resolveRelativeToA1=Ld,SA.sheetNameToString=ud,SA.sheetAndRangeToString=dd,SA.runToString=qd,SA.stringToRun=Jd,SA.runToRef=Yd,SA.refToRun=Xd,SA.runsToRefs=Zd,SA.refsToRuns=Qd;var OA,kA,AA=class extends UD{constructor(...e){super(...e),this._conditionWatches=new Map,this._markedValueRange=void 0,this._valueUpdatesScheduled=!1,this._isContainerShifting=!1}_initialize(e){super._initialize(e),this._getValueGrid=e.getGridValues,this._updateState({...NA,...this._getDefaultState(e)},this._getActionDescription(`initialize`)??(0,n.messageKey)(`op.initialize`));try{this._fromJSON(e?.json)}catch(e){throw console.error(`Error creating anchored conditional from JSON`,e),e}let t=this;this._rangeListener=e=>{t._markValueUpdates(e.getTo())},this._processAnchorCoords()}_markValueUpdates(e=null){this._markedValueRange===void 0?this._markedValueRange=e:this._markedValueRange=null,this._valueUpdatesScheduled||(this._valueUpdatesScheduled=!0,queueMicrotask(()=>{this._valueUpdatesScheduled=!1;let e=this._markedValueRange;this._markedValueRange=void 0,e!==void 0&&(this.isClosed()||this.isDeleted()||this._processValueUpdates(e))}))}_watchConditionFormula(e,t,r,i){i.add(t);let a=this._conditionWatches.get(t);if(!a){if(e.getCount()===0)return null;let r=this;a={remove:()=>{},values:[],pending:[]},this._conditionWatches.set(t,a);let i=a,o=(e,t)=>{i.values[t]=e;let n=i.pending[t];if(n&&n.length>0){i.pending[t]=[];for(let t=0;t<n.length;t++)n[t](e)}r._markValueUpdates(null)},s=e;if(t instanceof WE&&s._addWatch)i.remove=s._addWatch(t,(e,n,r)=>e._addWatch(t instanceof GE?t.getCheckExpression(r):t,{onValues:e=>o(e,n),onRegistered:n===0?e=>t.bindHost(e):void 0},r,MA));else if(t instanceof GE){let r=n.CoordUtils.unionRangesArrays(e.getCoords());i.remove=e.addWatch(t.getCheckExpression({rowIndex:r.rowStart,colIndex:r.colStart}),o,MA)}else i.remove=e.addWatch(t,o,MA)}let o=a.values[r];if(o)return o;let s=a;return new Promise(e=>{(s.pending[r]??=[]).push(e)})}_pruneConditionWatches(e){for(let[t,n]of[...this._conditionWatches])e.has(t)||(this._removeConditionWatch(t,n),this._conditionWatches.delete(t))}_removeConditionWatches(){for(let[e,t]of this._conditionWatches)this._removeConditionWatch(e,t);this._conditionWatches.clear()}_removeConditionWatch(e,t){e instanceof WE&&e.bindHost(null),t.remove();for(let e=0;e<t.pending.length;e++){let n=t.pending[e];if(n)for(let e=0;e<n.length;e++)n[e](null)}t.pending.length=0}_processClose(){this._removeConditionWatches(),this._getState().removeListener?.(),super._processClose()}_processAfterStateChange(e,t,n=!1,r=!1){super._processAfterStateChange(e,t,n,r),(n||r)&&this._markValueUpdates(null)}_processAnchorCoords(){let e=this._getState();if(!e)return;let t=this._isContainerShifting;if(t||e.removeListener?.(),super._processAnchorCoords(),this._rangeListener){if(!t){let e=this.getRanges(),t=e.isInvalid()?void 0:e.addListener(this._rangeListener,PA);this._updateState({removeListener:t},this._getActionDescription(`updateListener`)??(0,n.messageKey)(`op.updateListener`))}this._markValueUpdates(null)}}_processContainerDelete(){this._isContainerShifting=!0;try{super._processContainerDelete()}finally{this._isContainerShifting=!1}}_processContainerShift(e){this._isContainerShifting=!0;try{return this._doProcessContainerShift(e)}finally{this._isContainerShifting=!1}}_doProcessContainerShift(e){let t=super._processContainerShift(e);return e.after||this._getState().anchorCoords||this._delete(),this._processAnchorCoords(),t}_isAnchorAbsolute(){return!0}getCoords(){return this.getFirstAnchorCoords()}setRanges(e,t){return this._setAnchorRanges(e,t)}getIndex(){return this._options?.getContainerIndex?.()??-1}setIndex(e){return this._options?.setContainerIndex?.(e),this}getCondition(){let e=this._getState().condition??null;return this._bindConditionFormulas(e),e}_getFormulaBinding(){let e=this._formulaBinding;if(!e){let t=this._options;e={getCalculation:()=>t.getCalculation?.()??null,getAnchor:()=>{let e=this.getAnchorCoords(),t=e?n.CoordUtils.unionRangesArrays(e):null;return t?{rowIndex:t.rowStart,colIndex:t.colStart}:null},getScope:()=>{try{return this.getRanges().getSheet()?.getName()??null}catch{return null}}},this._formulaBinding=e}return e}_bindConditionFormulas(e){if(!e)return;let t=this._getFormulaBinding();iD(e,e=>e.bind(t))}setCondition(e,t){let r=zD.resolveInput(e);return this._updateState({condition:r},{description:(0,n.messageKey)(`op.setCondition`),...t},[`onConditionChange`]),this._markValueUpdates(null),this}_rebaseAnchorFormulas(e,t){if(e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex)return!0;let n=this._getState().condition;if(!n)return!0;let r=JSON.parse(JSON.stringify(n.toJSON())),i=this._rebaseConditionFormulas(r,e,t);return i!==null&&(i&&this.setCondition(r),!0)}_rebaseConditionFormulas(e,t,n){if(!e||typeof e!=`object`)return!1;let r=e.param;if(e.operator===Y.BuiltInOperatorNames.Expression){if(typeof r!=`string`||!r)return!1;let i=this._shiftFormulaText(r,t,n);return i===null?null:i!==r&&(e.param=i,!0)}if(typeof r==`string`){if(!r.startsWith(`=`)||!ZE.has(e.operator))return!1;let i=this._shiftFormulaText(r.slice(1),t,n);return i===null?null:`=`+i!==r&&(e.param=`=`+i,!0)}if(!r||typeof r!=`object`)return!1;if(Array.isArray(r)){let e=!1;for(let i of r){let r=this._rebaseConditionFormulas(i,t,n);if(r===null)return null;e||=r}return e}if(typeof r.operator==`string`)return this._rebaseConditionFormulas(r,t,n);if(e.operator===Y.BuiltInOperatorNames.InSet){let e=r.items;if(typeof e!=`string`||!e.trim()||tD(e))return!1;let i=this._shiftFormulaText(e,t,n);return i===null?null:i!==e&&(r.items=i,!0)}if(e.operator!==Y.BuiltInOperatorNames.Between)return!1;let i=!1;for(let e of[`from`,`to`]){let a=r[e];if(typeof a!=`string`||!a.startsWith(`=`))continue;let o=this._shiftFormulaText(a.slice(1),t,n);if(o===null)return null;`=`+o!==a&&(r[e]=`=`+o,i=!0)}return i}_extendPastedRanges(e,t){if(this.isDeleted()||this.getIndex()<0||JSON.stringify(this.toJSON())!==t)return!1;let r=this.getRanges().getCoords(),i=Rh(r,e);if(!n.CoordUtils.isEqualRangesArrays(r,i)){if(i.length!==1)return!1;let e=n.CoordUtils.unionRangesArrays(r);if(!e||i[0].rowStart!==e.rowStart||i[0].colStart!==e.colStart)return!1}return this._extendRanges(e),!0}_rebaseClonedAnchor(e){let t=n.CoordUtils.unionRangesArrays(this.getRanges().getCoords());t&&this._rebaseAnchorFormulas({rowIndex:e.rowStart,colIndex:e.colStart},{rowIndex:t.rowStart,colIndex:t.colStart})}_extendRanges(e){let t=this.getRanges().getCoords(),r=Rh(t,e);if(n.CoordUtils.isEqualRangesArrays(t,r))return;let i=n.CoordUtils.unionRangesArrays(t),a=n.CoordUtils.unionRangesArrays(r);if((a.rowStart!==i.rowStart||a.colStart!==i.colStart)&&!this._rebaseAnchorFormulas({rowIndex:i.rowStart,colIndex:i.colStart},{rowIndex:a.rowStart,colIndex:a.colStart})){let i=Mh(e,t);if(i.length===0)return;r=t.concat(Rh(n.CoordUtils.EmptyRanges,i))}this.setRanges(r)}_shiftFormulaText(e,t,n){let r=this._options.getCalculation?.()??null;if(!r)return null;try{let i=UE(r,e,t),a=i?.shift(n);return i&&a?a.hasRefError()&&!i.hasRefError()?null:a.getExpression():null}catch{return null}}apply(){}async _evalConditionRanges(e){let t=this._getState().condition;if(!t)return;this._bindConditionFormulas(t);let n=this._options,r=n.getCalculation?.()??null,i=this._getValueGrid(),a=this.getRanges(),o=new Set,s=a.getCount();for(let c=0;c<s;c++){let s=a.at(c).getCoords();if(!s)continue;let l=c;await mD({runtime:n.getRuntime?.(),calculation:r,conditions:[t],values:i,coords:s,watchFormula:e=>this._watchConditionFormula(a,e,l,o),onTrue:e.onTrue?(t,n)=>e.onTrue(t,n,s):void 0,onFalse:e.onFalse?(t,n)=>e.onFalse(t,n,s):void 0,onBlank:e.onBlank?t=>e.onBlank(t,s):void 0})}this._pruneConditionWatches(o)}get[Symbol.toStringTag](){return`[${this._getType()}]`}toString(){let e=this._getState().condition,t=e?.getSelector()?.getName(),n=e?.getOperator()?.getName(),r=this.getRange()?.toString();return`${this._getType()}${t?`:${t}`:``}${n?`:${n}`:``}${r?`:${r}`:``}`}},jA=class{constructor(e){this._regions=[],this._builder=null,this._area=null,this._isColumn=e}push(e,t){t===this._area&&this._builder||(this._flush(),this._builder=new z.Builder,this._area=t);let n=this._isColumn?e.colIndex:e.rowIndex,r=this._isColumn?e.rowIndex:e.colIndex;this._builder.pushAt(n,r,!0)}build(e){this._flush();let t=this._regions;if(t.length===0)return null;let n=new ni({axis:e});for(let e=0;e<t.length;e++)n.setValues(t[e]);return n}_flush(){let e=this._builder?.build();e&&this._regions.push(e.tuples),this._builder=null,this._area=null}},MA=Object.freeze({arrayFirstCell:!0}),NA=Object.freeze({condition:null,removeListener:null}),PA=Object.freeze({transactional:!1});(kA=OA||={}).ScaleType={ColorScale:`colorScale`,DataBar:`dataBar`,IconSet:`iconSet`},kA.ColorStopType={AutoMin:`autoMin`,AutoMax:`autoMax`,Formula:`formula`,Max:`max`,Min:`min`,Num:`num`,Percent:`percent`,Percentile:`percentile`};var FA=class e{constructor(e,t){this._c=e,this._m=t}getModel(){return this._m}getCoords(){return this._c}getPropertiesAt(e,t,n){return this._m.getPropertiesAt(e,t,n)}getDecorationAt(e,t,n){return this._m.getDecorationAt(e,t,n)}getSplit(t){let n=this._m;return[new e(t[0],n),new e(t[1],n)]}},IA=class e extends AA{constructor(...e){super(...e),this._colorScale=null,this._dataBar=null,this._iconSet=null,this._matches=null,this._blankResolvers=null,this._stopValues=new Map,this._stopWatchRemoves=null,this._stopWatchFormulas=null,this._stopWatchKey=null,this._prepareGeneration=0}_initialize(e){if(!e.json)throw Error(`json is required`);this._styles=e.sheet?.getStyles()??new ag,super._initialize(e),this._stylesRemoveListener=this._styles.addListeners({onThemeChange:()=>{this._markValueUpdates(null)}})}_getType(){return`ConditionalFormat`}_getActionDescription(e){return e===`delete`?(0,n.messageKey)(`op.deleteConditionalFormat`):e===`initialize`?(0,n.messageKey)(`op.initializeConditionalFormat`):(0,n.messageKey)(`op.updateConditionalFormatListener`)}_getDefaultState(e){return{...RA}}_processValueUpdates(e=null){let n=this._getState();if(!n)return;let r=this._options,i=this,a=n.scale,o=this.getRanges();this._syncStopWatches(o,a?.stops??null);let s=++this._prepareGeneration,c=a?.type===OA.ScaleType.ColorScale?a.stops:null;c?(async()=>{let e=await i._prepareColorScale(o,c);s===i._prepareGeneration&&(i._colorScale=e,r.invalidate?.())})():this._colorScale=null;let l=a?.type===OA.ScaleType.DataBar?a:null;l?(async()=>{let e=await i._prepareDataBar(o,l);s===i._prepareGeneration&&(i._dataBar=e,r.invalidate?.())})().catch(()=>{s===i._prepareGeneration&&(i._dataBar=null)}):this._dataBar=null;let u=a?.type===OA.ScaleType.IconSet?a:null;u?(async()=>{let e=await i._prepareIconSet(o,u);s===i._prepareGeneration&&(i._iconSet=e,r.invalidate?.())})().catch(()=>{s===i._prepareGeneration&&(i._iconSet=null)}):this._iconSet=null,n.condition&&(n.style||n.stopIfTrue)?(async()=>{let e=i._getValueGrid().getAxis(),n=new jA(e===t.IRange.Axis.Column),a=[];await i._evalConditionRanges({onTrue:(e,t,r)=>{n.push(e,r)},onBlank:(e,t)=>{a.push({area:t,resolve:e})}}),s===i._prepareGeneration&&(i._matches=n.build(e)??new ni({axis:e}),i._blankResolvers=a.length>0?a:null,r.invalidate?.())})().catch(()=>{s===i._prepareGeneration&&(i._matches=null,i._blankResolvers=null)}):(this._matches=null,this._blankResolvers=null)}async _resolveStopValues(e,t){let n=t.some(e=>e.type===OA.ColorStopType.Min||e.type===OA.ColorStopType.Max||e.type===OA.ColorStopType.Percent||e.type===OA.ColorStopType.AutoMin||e.type===OA.ColorStopType.AutoMax),r=null,i=null,a=null;if(n){r=e.getStats();let t=r.getAggregates();i=t.min??null,a=t.max??null}let o=[];for(let n of t){let t=null;switch(n.type??OA.ColorStopType.Num){case OA.ColorStopType.Min:t=i;break;case OA.ColorStopType.Max:t=a;break;case OA.ColorStopType.AutoMin:t=i===null?null:Math.min(0,i);break;case OA.ColorStopType.AutoMax:t=a===null?null:Math.max(0,a);break;case OA.ColorStopType.Num:t=Number(n.value)??0;break;case OA.ColorStopType.Percentile:r??=e.getStats(),t=r.getSortedNumbers().getPercentile((Number(n.value)??0)/100);break;case OA.ColorStopType.Percent:{let e=Math.max(0,Math.min(100,Number(n.value)??0));i!==null&&a!==null&&(t=i+e/100*(a-i));break}case OA.ColorStopType.Formula:{let e=n.value instanceof WE?this._stopValues.get(n.value):void 0;typeof e==`number`&&(t=e);break}default:t=Number(n.value)??0}o.push(t!==null&&Number.isFinite(t)?t:null)}return o}_formulaAnchor(e){let t=e.getCount()>0?n.CoordUtils.unionRangesArrays(e.getCoords()):null;return t?{rowIndex:t.rowStart,colIndex:t.colStart}:null}_syncStopWatches(e,t){let n=[],r=t?t.length:0,i=this._getFormulaBinding();for(let e=0;e<r;e++){let r=t[e];if(r.type!==OA.ColorStopType.Formula)continue;let a=r.value;a instanceof WE&&!n.includes(a)&&(a.bind(i),a.getText().trim().length>0&&n.push(a))}let a=n.map(e=>``+function(e){let t=BA.get(e);return t===void 0&&(t=++VA,BA.set(e,t)),t}(e)),o=n.length>0?this._formulaAnchor(e):null,s=o?`${o.rowIndex}:${o.colIndex}|${a.join(`\0`)}`:null;if(s===this._stopWatchKey||(this._removeStopWatches(),this._stopWatchKey=s,!s||!o))return;let c=e.getSheet().getRange({rowStart:o.rowIndex,rowEnd:o.rowIndex,colStart:o.colIndex,colEnd:o.colIndex}),l=c,u=this,d=[];for(let e=0;e<n.length;e++){let t=n[e],r=e=>{let n=e.getValueAt(0,0),r=typeof n==`number`&&Number.isFinite(n)?n:null;u._stopValues.has(t)&&u._stopValues.get(t)===r||(u._stopValues.set(t,r),u._markValueUpdates(null))};d.push(l._addWatch?l._addWatch(t,{onValues:r,onRegistered:e=>t.bindHost(e)},void 0,zA):c.addWatch(t,r,zA))}this._stopWatchRemoves=d,this._stopWatchFormulas=n}_removeStopWatches(){let e=this._stopWatchRemoves;if(!e)return;let t=this._stopWatchFormulas;if(t)for(let e=0;e<t.length;e++)t[e].bindHost(null);for(let t=0;t<e.length;t++)e[t]();this._stopWatchRemoves=null,this._stopWatchFormulas=null,this._stopValues.clear()}_processClose(){this._removeStopWatches(),this._stopWatchKey=null,this._stylesRemoveListener?.(),this._stylesRemoveListener=null,super._processClose()}async _prepareColorScale(e,t){if(!t||t.length===0)return null;let n=await this._resolveStopValues(e,t),r=this._styles,i=[];for(let e=0;e<t.length;e++){let a=n[e];if(a===null)continue;let o=t[e],s=r.parseColor(o.color).toRGBA(),c=[s.red,s.green,s.blue];i.push({v:a,rgb:c,exclusive:o.exclusive??!1})}return i.length===0?null:(i.sort((e,t)=>e.v-t.v),{stops:i,colorFor:qA(i)})}async _prepareDataBar(e,t){let n=t.stops;if(!n||n.length<2)return null;let r=await this._resolveStopValues(e,n),i=r[0],a=r[r.length-1];if(i===null||a===null||a===i)return null;let o;o=t.axisPosition===`none`?0:t.axisPosition===`middle`?.5:GA((0-i)/(a-i));let s=GA((t.minLength??0)/100),c=GA((t.maxLength??100)/100),l=this._styles,u=e=>e===void 0?void 0:l.parseColor(e).toCSS(`adaptive`,!0),d={type:OA.ScaleType.DataBar,axis:o,color:u(t.color)??UA,negativeColor:u(t.negativeFillColor),borderColor:u(t.borderColor),negativeBorderColor:u(t.negativeBorderColor),axisColor:u(t.axisColor),gradient:t.gradient??!1,direction:t.direction===`rightToLeft`?`rightToLeft`:`leftToRight`,showValue:t.showValue??!0};return{barFor:e=>{let t=GA((e-i)/(a-i))-o,n=t>=0?1-o:o,r;if(n<=0)r=o;else{let e=s+Math.abs(t)/n*(c-s);r=o+(t>=0?1:-1)*e*n}return{...d,value:GA(r)}}}}async _prepareIconSet(e,t){let n=t.stops;if(!n||n.length===0)return null;let r=t.iconSet;if(!r)return null;let i=await this._resolveStopValues(e,n),a=n.length,o=t.icon,s=t.reverse??!1,c=t.showValue??!0;return{iconFor:e=>{let t=0;for(let r=1;r<a;r++){let a=i[r];if(a!==null){if(!(n[r].exclusive?e>a:e>=a))break;t=r}}s&&(t=a-1-t);let l=o?.[t];if(l){let e=function(e){let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:0}(l.set);return l.id<0||l.id>=e?null:{type:OA.ScaleType.IconSet,index:l.id,set:l.set,count:e,showValue:c}}return{type:OA.ScaleType.IconSet,index:t,set:r,count:a,showValue:c}}}}setStopIfTrue(e,t){return this._updateState({stopIfTrue:e},{description:e?(0,n.messageKey)(`op.setStopTrue`):(0,n.messageKey)(`op.setStopFalse`),...t},[`onAnyChange`]),this}isStopIfTrue(){return this._getState().stopIfTrue??!1}getScale(){let e=this._getState().scale??null,t=e?.stops;if(t){let e=this._getFormulaBinding();for(let n=0;n<t.length;n++){let r=t[n].value;r instanceof WE&&r.bind(e)}}return e}getStyle(){return this._getState().style??null}_rebaseAnchorFormulas(e,t){if(!super._rebaseAnchorFormulas(e,t))return!1;if(e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex)return!0;let n=this._getState().scale,r=n?.stops;if(!r||r.length===0)return!0;let i=!1,a=Array(r.length);for(let n=0;n<r.length;n++){let o=r[n];if(a[n]=o,o.type!==OA.ColorStopType.Formula)continue;let s=o.value instanceof WE?o.value.getText():typeof o.value==`string`?o.value:``;if(!s)continue;let c=this._shiftFormulaText(s,e,t);if(c===null)return!1;c!==s&&(i=!0,a[n]={...o,value:c})}return i&&this.update({scale:{...n,stops:a}}),!0}getSnapshot(e){let t={...this.toJSON()},r=JSON.stringify(this.toJSON()),i=this.getRange().getCoords(),a=n.CoordUtils.unionRangesArrays(this.getRanges().getCoords()),o=this,s=Object.freeze({...e});return{async copyTo(e,i){let s=e.ranges??[e.range];return e.extend&&o._extendPastedRanges(s,r)||e.conditionals.add(s,{...t,index:e.index})._rebaseClonedAnchor(a),n.CoordUtils.unionRangesArrays(s)},getCoords:()=>i,getSource:()=>o,getName:()=>`Conditional Format`,getMarkOptions:()=>s,isISnapshot:!0}}_createSpatial(e){return new FA(e,this)}update(t,r){if(this.isDeleted())throw Error(`Table has been closed. No further operations are allowed.`);let i=t.isIConditionalFormat?e.replaceModifiers(t.toJSON()):t,a=this._getState(),o=this._beginCommit(r?.description??(0,n.messageKey)(`op.updateConditionalFormat`));try{let{condition:e,stopIfTrue:t,...n}=i,s={...a,...n,...`stopIfTrue`in i?{stopIfTrue:t??!1}:null,...`condition`in i?{condition:zD.fromJSON(e)}:null};`scale`in i&&(s.scale=HA(s.scale??null)),`condition`in i&&s.condition&&!(`scale`in i)?s.scale=null:`scale`in i&&s.scale&&!(`condition`in i)&&(s.condition=null),this._updateState(s,r),this._getEmitter().notify(`onAnyChange`),o.commit()}catch(e){throw o.rollback(),e}return this._markValueUpdates(null),this}static replaceModifiers(e){return{condition:e?.condition??null,style:e?.style??null,scale:e?.scale??null,stopIfTrue:e?.stopIfTrue??!1}}toJSON(){let e={},t=this._getState();if(t===null)return null;if(t.condition){let n=t.condition.toJSON();n&&(e.condition=n)}return t.style&&(e.style=t.style),t.scale&&(e.scale=function(e){let t=e.stops;return t&&t.some(e=>e.value instanceof WE)?{...e,stops:t.map(e=>e.value instanceof WE?{...e,value:e.value.toJSON()}:e)}:e}(t.scale)),t.stopIfTrue&&(e.stopIfTrue=t.stopIfTrue),t.pivot&&(e.pivot=t.pivot),t.ext&&(e.ext=t.ext),e}_fromJSON(e){let t=e??{},r={...RA,style:t.style??null,scale:HA(t.scale??null),stopIfTrue:t.stopIfTrue??!1,pivot:t.pivot??!1,ext:t.ext??null,condition:zD.fromJSON(t.condition)};this._updateState(r,{description:(0,n.messageKey)(`op.initializeConditionalFormat`)})}getPropertiesAt(e,t,n){let r=this._colorScale;if(r&&typeof n==`number`)return{fill:{type:`solid`,color:r.colorFor(n)}};let i=this._matches;if(i&&i.getValueAt(e,t))return this._getState().style??LA;let a=this._blankResolvers;if(a&&n==null)for(let n=0;n<a.length;n++){let{area:r,resolve:i}=a[n];if(!(e<r.rowStart||e>r.rowEnd||t<r.colStart||t>r.colEnd)&&i(e,t))return this._getState().style??LA}return null}getDecorationAt(e,t,n){if(typeof n!=`number`||!Number.isFinite(n))return null;let r=this._dataBar;if(r)return r.barFor(n);let i=this._iconSet;return i?i.iconFor(n):null}get isIConditionalFormat(){return!0}},LA=Object.freeze({}),RA=Object.freeze({condition:null,removeListener:null,style:null,scale:null,stopIfTrue:!1,pivot:!1,ext:null}),zA=Object.freeze({arrayFirstCell:!0}),BA=new WeakMap,VA=0;function HA(e){let t=e?.stops;if(!t||t.length===0)return e;let n=!1,r=t.map(e=>{if(e.type!==OA.ColorStopType.Formula)return e;let t=e.value;return t instanceof WE?e:t?.isIFormula?(n=!0,{...e,value:new WE(t.getExpression(),!1)}):typeof t==`string`?(n=!0,{...e,value:new WE(t,!1)}):e});return n?{...e,stops:r}:e}var UA=`rgb(99, 142, 198)`;function WA(e,t,n){return e+(t-e)*n}function GA(e){return e<0?0:e>1?1:e}function KA(e){return`rgb(${e[0]}, ${e[1]}, ${e[2]})`}function qA(e){let t=e.length;if(t===0)return e=>``;let n=e[0],r=e[t-1];return i=>{if(!Number.isFinite(i))return``;if(i<=n.v)return KA(n.rgb);if(i>=r.v)return KA(r.rgb);let a=1;for(;a<t;){let t=e[a];if(i<t.v)break;if(i!==t.v)a++;else{if(!t.exclusive)break;a++}}if(a<=0)return KA(n.rgb);if(a>=e.length)return KA(r.rgb);let o=e[a-1],s=e[a],c=s.v-o.v;if(c===0)return KA((s.exclusive?o:s).rgb);let l=(i-o.v)/c;return KA(function(e,t,n){return n=GA(n),[Math.round(WA(e[0],t[0],n)),Math.round(WA(e[1],t[1],n)),Math.round(WA(e[2],t[2],n))]}(o.rgb,s.rgb,l))}}var JA,YA=class extends S{constructor(e,t,n,r){super(),this._add=e,this._get=t,this._createItem=n,this._addListeners=r}add(e,t){if(!e)throw Error((0,n.t)(`error.address.noAddress`));return this._add(e,t)}_getItems(e){return this._get(e?.address,e?.ignoreHidden,e?.fullyContained)}createItem(e){return this._createItem(e)}addListeners(e,t){return this._addListeners(e,t)}get isIConditionalFormatCollection(){return!0}};(JA||={}).AlertStyle={Stop:`stop`,Warning:`warning`,Information:`information`};var XA=class extends AA{constructor(...e){super(...e),this._results=null,this._blankAreas=null,this._blankPerCell=!1,this._blankPieces=null,this._alertCount=null,this._evalGeneration=0}_getType(){return`DataValidation`}_getActionDescription(e){return e===`delete`?(0,n.messageKey)(`op.deleteDataValidation`):e===`initialize`?(0,n.messageKey)(`op.initializeDataValidation`):(0,n.messageKey)(`op.updateDataValidationListener`)}_getDefaultState(e){return{...$A}}_processValueUpdates(e=null){let n=this._getState();if(!n)return;let r=n.condition,i=++this._evalGeneration;if(!r)return void((this._results&&this._results.getCount()>0||this._blankAreas)&&(this._setResults(null,null),this._options.invalidate?.(this.getRange().getCoords())));let a=this._options;(async()=>{let e=this._getValueGrid().getAxis(),n=new jA(e===t.IRange.Axis.Column),o=r.isIncludeBlanks()?null:[];if(await this._evalConditionRanges({onFalse:(e,t,r)=>{n.push(e,r)},onBlank:o?(e,t)=>{o.push({area:t,resolve:e,passes:null})}:void 0}),i!==this._evalGeneration)return;let s=n.build(e),c=(this._results?.getCount()??0)>0||!!this._blankAreas,l=!!o&&o.length>0;if(!s&&!c&&!l)return;let u=!1;iD(r,()=>{u=!0}),this._setResults(s??new ni({axis:e}),l?o:null,u);let d=this.getRanges(),f=d.getCount();for(let e=0;e<f;e++){let t=d.at(e).getCoords();t&&a.invalidate?.(t)}})().catch(()=>{})}_setResults(e,t,n=!1){this._results=e,this._blankAreas=t,this._blankPerCell=n,this._blankPieces=null,this._alertCount=null}_isBlankFailing(e,t,n){for(let r=0;r<e.length;r++){let i=e[r],a=i.area;if(!(t<a.rowStart||t>a.rowEnd||n<a.colStart||n>a.colEnd)&&!this._isBlankPassing(i,t,n))return!0}return!1}_isBlankPassing(e,t,n){if(this._blankPerCell)return e.resolve(t,n);let r=e.passes;return r===null&&(r=e.passes=e.resolve(e.area.rowStart,e.area.colStart)),r}_getBlankPieces(){let e=this._blankPieces;if(e)return e;e=[];let t=this._blankAreas??[];for(let n=0;n<t.length;n++){let r=t[n],i=[],a=[r.area];for(let t=0;t<e.length;t++){let n=e[t],o=ZA(n.coords,r.area);if(!o){i.push(n);continue}i.push({coords:o,areas:[...n.areas,r]});let s=QA(n.coords,o);for(let e=0;e<s.length;e++)i.push({coords:s[e],areas:n.areas});a=a.flatMap(e=>QA(e,o))}for(let e=0;e<a.length;e++)i.push({coords:a[e],areas:[r]});e=i}return this._blankPieces=e,e}_countValues(e){let t=this._getValueGrid(),n=0;for(let r of t.getRuns({bounds:e}))n+=r[2].length;return n}getAlertAt(e,t){if(this._results?.getValueAt(e,t))return!0;let n=this._blankAreas;return n?this._getValueGrid().getValueAt(e,t)==null&&this._isBlankFailing(n,e,t):!1}getAlertEntries(e){let t=this._results,n=e?.axis??this._getValueGrid().getAxis(),r=e?.reverse??!1;if(!this._blankAreas)return(t??new ni({axis:n})).entries({axis:n,reverse:r});let i=this._getBlankPieces(),a=r?[...i].reverse():i;return this._pieceEntries(a,t,n,r)}*_pieceEntries(e,n,r,i){let a=this._getValueGrid(),o=r===t.IRange.Axis.Column;for(let t=0;t<e.length;t++){let s=e[t],c=s.coords,l=this._blankPerCell,u=!1;if(!l){for(let e=0;e<s.areas.length&&!u;e++)u=!this._isBlankPassing(s.areas[e],c.rowStart,c.colStart);if(!u){if(n){let e=n.entries({bounds:c,axis:r,reverse:i});for(let t=e.next();!t.done;t=e.next()){let e=t.value[0];yield[{rowIndex:e.rowIndex,colIndex:e.colIndex},!0]}}continue}}let d=o?c.colStart:c.rowStart,f=o?c.rowStart:c.colStart,p=(o?c.rowEnd:c.colEnd)-f+1,m=((o?c.colEnd:c.rowEnd)-d+1)*p-1,h=e=>{let t=d+Math.floor(e/p),n=f+e%p;return o?{rowIndex:n,colIndex:t}:{rowIndex:t,colIndex:n}},g=i?-1:1,_=i?m:0,v=function*(e,t){for(;_!==t;_+=g){let t=h(_);l&&!e._isBlankFailing(s.areas,t.rowIndex,t.colIndex)||(yield[t,!0])}},y=a.entries({bounds:c,axis:r,reverse:i});for(let e=y.next();!e.done;e=y.next()){let t=e.value[0],r=((o?t.colIndex:t.rowIndex)-d)*p+(o?t.rowIndex:t.colIndex)-f;yield*v(this,r),_=r+g,n?.getValueAt(t.rowIndex,t.colIndex)&&(yield[{rowIndex:t.rowIndex,colIndex:t.colIndex},!0])}yield*v(this,i?-1:m+1)}}getAlertCount(){let e=this._alertCount;if(e!==null)return e;if(e=this._results?.getCount()??0,this._blankAreas){let t=this._getBlankPieces();for(let n=0;n<t.length;n++){let r=t[n],i=r.coords;if(!this._blankPerCell){let t=!1;for(let e=0;e<r.areas.length&&!t;e++)t=!this._isBlankPassing(r.areas[e],i.rowStart,i.colStart);t&&(e+=(i.rowEnd-i.rowStart+1)*(i.colEnd-i.colStart+1)-this._countValues(i));continue}for(let t of this._pieceEntries([r],null,this._getValueGrid().getAxis(),!1))t&&e++}}return this._alertCount=e,e}async getListItemsAt(e,n){let r=this._getState().condition;if(r?.getOperator()?.getName()!==Y.BuiltInOperatorNames.InSet)return[];let i=r.getParam()?.items;if(Array.isArray(i))return i.map(e=>({value:e,text:LD(e,IH(e))}));if(typeof i==`string`)return(nD(i)??[]).map(e=>({value:e,text:e}));if(!(i instanceof GE))return[];this._bindConditionFormulas(r);let a=i.shift({rowIndex:e,colIndex:n});if(!a)return[];let o=[];if(a.isReferenceOnly()){let e=a.getReferences(),t=e?.getCount()??0;for(let n=0;n<t;n++)e.at(n).forEach((e,t)=>{o.push({value:e,text:t.getCell().getText({hideStringPrefix:!0})})});return o}let s;try{s=await a.evaluate({alwaysReturnRange:!0})}catch{return[]}if(!s?.isIRange)return[];for(let e of s.entries({axis:t.IRange.Axis.Row})){let n=e.value;t.FormulaError.isError(n)||o.push({value:n,text:LD(n,IH(n))})}return o}setHideDropdown(e,t){return this._updateState({hideDropdown:e??!1},{description:(0,n.messageKey)(`op.setHideDropdown`),...t},[`onConfigChange`])}isHideDropdown(){return this._getState().hideDropdown}setPromptMessage(e,t){return this._updateState({prompt:e??``},{description:(0,n.messageKey)(`op.setPromptMessage`),...t},[`onConfigChange`])}getPromptMessage(){return this._getState().prompt}setPromptTitle(e,t){return this._updateState({promptTitle:e??``},{description:(0,n.messageKey)(`op.setPromptTitle`),...t},[`onConfigChange`])}getPromptTitle(){return this._getState().promptTitle}setShowPromptMessage(e,t){return this._updateState({showPromptMessage:e??!1},{description:(0,n.messageKey)(`op.setShowPromptMessage`),...t},[`onConfigChange`])}isShowPromptMessage(){return this._getState().showPromptMessage}setAlertMessage(e,t){return this._updateState({alert:e??``},{description:(0,n.messageKey)(`op.setAlertMessage`),...t},[`onConfigChange`])}getAlertMessage(){return this._getState().alert}setAlertTitle(e,t){return this._updateState({alertTitle:e??``},{description:(0,n.messageKey)(`op.setAlertTitle`),...t},[`onConfigChange`])}getAlertTitle(){return this._getState().alertTitle}setShowAlertMessage(e,t){return this._updateState({showAlertMessage:e??!1},{description:(0,n.messageKey)(`op.setShowErrorMessage`),...t},[`onConfigChange`])}isShowAlertMessage(){return this._getState().showAlertMessage}setAlertStyle(e,t){return this._updateState({alertStyle:e??$A.alertStyle},{description:(0,n.messageKey)(`op.setAlertStyle`),...t},[`onConfigChange`])}getAlertStyle(){return this._getState().alertStyle}setIncludeBlanks(e,t){let r=this._getState().condition;return r?(this._updateState({condition:zD.fromJSON({...r.toJSON(),includeBlanks:e??!1})},{description:(0,n.messageKey)(`op.setIncludeBlanks`),...t},[`onConfigChange`]),this._markValueUpdates(null),this):this}isIncludeBlanks(){return this._getState().condition?.isIncludeBlanks()??!1}getRenderHints(){return this._getState().condition?.getSelector()?.getRenderHints?.()??n.CommonUtils.EmptyArray}update(e,t){let r=e&&`isIDataValidation`in e?{condition:null,...e.toJSON()}:{...e};return this.doBatch(()=>{this._fromJSON(r),this._markValueUpdates(),this._notify([`onAnyChange`])},{description:(0,n.messageKey)(`op.updateDataValidation`),...t}),this}getSnapshot(e){let t={...this.toJSON()},r=JSON.stringify(this.toJSON()),i=this.getFirstAnchorCoords(),a=n.CoordUtils.unionRangesArrays(this.getRanges().getCoords()),o=(0,n.t)(`name.dataValidation`),s=this,c=Object.freeze({...e});return{async copyTo(e,i){let o=e.ranges??[e.range];return e.extend&&s._extendPastedRanges(o,r)||e.validations.add(o,{...t,index:e.index})._rebaseClonedAnchor(a),n.CoordUtils.unionRangesArrays(o)},getCoords:()=>i,getSource:()=>s,getName:()=>o,getMarkOptions:()=>c,isISnapshot:!0}}addListeners(e,t){return this._getEmitter().addListeners(e,t)}toJSON(){let e={},t=this._getState();if(!t)return null;if(t.prompt&&(e.prompt=t.prompt),t.promptTitle&&(e.promptTitle=t.promptTitle),t.showPromptMessage&&(e.showPromptMessage=t.showPromptMessage),t.alert&&(e.alert=t.alert),t.alertTitle&&(e.alertTitle=t.alertTitle),t.showAlertMessage&&(e.showAlertMessage=t.showAlertMessage),t.alertStyle&&t.alertStyle!==$A.alertStyle&&(e.alertStyle=t.alertStyle),t.hideDropdown&&(e.hideDropdown=t.hideDropdown),t.imeMode&&(e.imeMode=t.imeMode),t.ext&&(e.ext=t.ext),t.condition){let n=t.condition.toJSON();n&&(e.condition=n)}return e}_fromJSON(e,t){let r=e??{},i={...this._getState()};r.prompt!==void 0&&(i.prompt=r.prompt),r.promptTitle!==void 0&&(i.promptTitle=r.promptTitle),r.showPromptMessage!==void 0&&(i.showPromptMessage=r.showPromptMessage),r.alert!==void 0&&(i.alert=r.alert),r.alertTitle!==void 0&&(i.alertTitle=r.alertTitle),r.showAlertMessage!==void 0&&(i.showAlertMessage=r.showAlertMessage),r.alertStyle!==void 0&&(i.alertStyle=r.alertStyle),r.hideDropdown!==void 0&&(i.hideDropdown=r.hideDropdown),r.imeMode!==void 0&&(i.imeMode=r.imeMode),r.ext!==void 0&&(i.ext=r.ext);let a=r.condition;a===null?i.condition=null:a!==void 0&&(i.condition=zD.fromJSON(a)),this._updateState(i,{description:(0,n.messageKey)(`op.addDataValidation`),...t})}get isIDataValidation(){return!0}},ZA=(e,t)=>{let n=Math.max(e.rowStart,t.rowStart),r=Math.min(e.rowEnd,t.rowEnd),i=Math.max(e.colStart,t.colStart),a=Math.min(e.colEnd,t.colEnd);return n>r||i>a?null:{rowStart:n,rowEnd:r,colStart:i,colEnd:a}},QA=(e,t)=>{let n=ZA(e,t);if(!n)return[e];let r=[];e.rowStart<n.rowStart&&r.push({...e,rowEnd:n.rowStart-1}),n.rowEnd<e.rowEnd&&r.push({...e,rowStart:n.rowEnd+1});let i={rowStart:n.rowStart,rowEnd:n.rowEnd};return e.colStart<n.colStart&&r.push({...i,colStart:e.colStart,colEnd:n.colStart-1}),n.colEnd<e.colEnd&&r.push({...i,colStart:n.colEnd+1,colEnd:e.colEnd}),r},$A=Object.freeze({condition:null,removeListener:null,alertStyle:JA.AlertStyle.Stop,hideDropdown:!1,imeMode:null,ext:null,prompt:``,promptTitle:``,showPromptMessage:!1,alert:``,alertTitle:``,showAlertMessage:!1}),ej=class extends S{constructor(e,t,n,r){super(),this._add=e,this._get=t,this._createItem=n,this._addListeners=r}add(e,t){if(!e)throw Error((0,n.t)(`error.address.invalidRange`));return this._add(e,t)}_getItems(e){return this._get(e?.address,e?.ignoreHidden,e?.fullyContained)}createItem(e){return this._createItem(e)}addListeners(e,t){return this._addListeners(e,t)}get isIDataValidationCollection(){return!0}},tj=class extends UD{constructor(...e){super(...e),this._sessionUnlocked=!1}_initialize(e){super._initialize(e),this._updateState({...nj},(0,n.messageKey)(`op.initializeProtectedRange`)),this._fromJSON(e?.json);let t=this._getState().name;t&&this._options.setContainerName?.(t)}_getActionDescription(e){return e===`delete`?(0,n.messageKey)(`op.deleteProtectedRange`):e===`initialize`?(0,n.messageKey)(`op.initializeProtectedRange`):null}_isAnchorAbsolute(){return!0}_processContainerShift(e){let t=super._processContainerShift(e);return e.after||this._getState().anchorCoords||this._delete(),this._processAnchorCoords(),t}getName(){return this._getState().name}setName(e,t){if(!e)throw new n.ExpectedError((0,n.t)(`error.protectedRange.noName`));if(e===this._getState().name)return this;let r=t?.description??(0,n.messageKey)(`op.setProtectedRangeName`);return this.doBatch(()=>{this._options.setContainerName?.(e,{...t,description:r}),this._updateState({name:e},{...t,description:r},[`onConfigChange`])},{...t,description:r}),this}getIndex(){return this._options?.getContainerIndex?.()??-1}setIndex(e){return this._options?.setContainerIndex?.(e),this}setRanges(e,t){return this._setAnchorRanges(e,t)}getSecurityDescriptor(){return this._getState().securityDescriptor}setSecurityDescriptor(e,t){return this._updateState({securityDescriptor:e||null},{description:(0,n.messageKey)(`op.setProtectedRangePermissions`),...t},[`onConfigChange`])}hasPassword(){return this._getState().password!==null}getEncryptedPassword(){return this._getState().password}async setPassword(e,t){let r=null;if(e){let n=t?.algorithm,i=t?.spinCount,a=await n_.generateSaltAndHash(e,n,i);r={salt:a.salt,hash:a.hash},n&&(r.algorithm=n),i&&(r.spinCount=i)}return this.relock(),this._updateState({password:r},{description:(0,n.messageKey)(`op.setProtectedRangePassword`),...t},[`onConfigChange`])}isUnlocked(){return!this.hasPassword()||this._sessionUnlocked}async unlock(e){return!this.hasPassword()||!!await this.checkPassword(e)&&(this._sessionUnlocked||(this._sessionUnlocked=!0,this._notify([`onUnlockChange`])),!0)}relock(){return this._sessionUnlocked&&(this._sessionUnlocked=!1,this._notify([`onUnlockChange`])),this}async checkPassword(e){let t=this._getState().password;return!t||!t.hash||!!e&&n_.verifyPassword(e,{salt:t.salt,hash:t.hash},t.algorithm,t.spinCount)}update(e,t){let r=e&&`isIProtectedRange`in e?e.toJSON()??{}:{...e};return this.doBatch(()=>{let e=r.name;e!==void 0&&e!==this._getState().name&&this.setName(e,t),this._fromJSON({...r,name:void 0},t),this._notify([`onConfigChange`])},{description:(0,n.messageKey)(`op.updateProtectedRange`),...t}),this}addListeners(e,t){return this._getEmitter().addListeners(e,t)}toJSON(){let e=this._getState();if(!e)return null;let t={};return e.name&&(t.name=e.name),e.securityDescriptor&&(t.securityDescriptor=e.securityDescriptor),e.password&&(t.password={...e.password}),t}_fromJSON(e,t){let r=e??{},i={};r.name!==void 0&&(i.name=r.name),r.securityDescriptor!==void 0&&(i.securityDescriptor=r.securityDescriptor||null),r.password!==void 0&&(i.password=r.password??null),Object.keys(i).length!==0&&this._updateState(i,{description:(0,n.messageKey)(`op.addProtectedRange`),...t})}get[Symbol.toStringTag](){return`[ProtectedRange]`}toString(){return`ProtectedRange:${this.getName()}:${this.getRanges()?.toString()}`}get isIProtectedRange(){return!0}},nj=Object.freeze({name:``,securityDescriptor:null,password:null}),rj=class extends S{constructor(e,t,n,r,i){super(),this._add=e,this._get=t,this._getByName=n,this._createItem=r,this._addListeners=i}add(e,t){if(!e)throw Error((0,n.t)(`error.address.noAddress`));return this._add(e,t)}_getItems(e){if(e?.name){let t=this._getByName(e.name);return t?[t]:[]}return this._get(e?.address,e?.ignoreHidden,e?.fullyContained)}createItem(e){return this._createItem(e)}addListeners(e,t){return this._addListeners(e,t)}get isIProtectedRangeCollection(){return!0}};function ij(e){return e==null?null:typeof e==`string`?{content:e}:{...e}}function aj(e){if(!e)return``;if(typeof e==`string`)return e;let t=e.runs;if(!t)return``;let n=``,r=t.length;for(let e=0;e<r;e++)n+=t[e]?.text??``;return n}function oj(e){if(!e)return``;if(typeof e==`string`)return e;let t=e.runs;if(!Array.isArray(t)||t.length===0)return``;let n=!0,r=Array(t.length);for(let e=0;e<t.length;e++){let i=sj(t[e]);i.font&&(n=!1),r[e]=i}return n?aj(e):{runs:r}}function sj(e){let t=typeof e?.text==`string`?e.text:``,n=e?.font;n!==void 0&&typeof n!=`string`||(n={},e?.font&&(n.family=e.font),e?.size!==void 0&&(n.size=e.size),e?.bold!==void 0&&(n.bold=e.bold),e?.italic!==void 0&&(n.italic=e.italic),e?.color!==void 0&&(n.color=e.color));let r=function(e){if(!e||typeof e!=`object`)return null;let{bold:t,italic:n,weight:r,underline:i,...a}=e,o={};for(let e in a){let t=a[e];t!=null&&(o[e]=Array.isArray(t)?[...t]:t)}if(r!=null){let e=typeof r==`number`?r:cm(r);isNaN(e)||(o.weight=e)}else typeof t==`boolean`&&(o.weight=t?700:400);return o.style===void 0&&typeof n==`boolean`&&(o.style=n?B.Style.Italic:B.Style.Normal),!0===i?o.underline=B.UnderlineStyle.Single:typeof i==`string`&&(o.underline=i),Object.keys(o).length>0?o:null}(n);return r?{text:t,font:r}:{text:t}}function cj(e){return typeof e==`string`?e:{runs:e.runs.map(e=>function(e){if(!e.font)return{text:e.text};let t={...e.font};return t.fallbacks&&=[...t.fallbacks],{text:e.text,font:t}}(e))}}var lj=/<x:Anchor>([\s\d,-]*)<\/x:Anchor>/,uj=/<x:Row>\s*(-?\d+)\s*<\/x:Row>/,dj=/<x:Column>\s*(-?\d+)\s*<\/x:Column>/,fj=/<x:Visible\s*\/>/;function pj(e,t){return e&&typeof e==`object`&&e.isIPerson?e.getId():t?typeof e==`string`&&e?t.add(e).getId():t.getCurrent().getId():null}var mj=(e,t,n)=>e.getBoundsAtCoords({rowStart:t,colStart:n,rowEnd:t,colEnd:n});function hj(e,t){let n=mj(t,e.rowIndex,e.colIndex),r=t.getMaxBounds(),i=n.x+n.width+15;i+144>r.x+r.width&&(i=Math.max(r.x,n.x-15-144));let a=n.y-10;return a+79>r.y+r.height&&(a=n.y+10-79),a=Math.max(r.y+2,a),{x:i,y:a,width:144,height:79}}var gj=(e,t,n)=>{let r=e.getCoordsAtBounds({x:t,y:n,width:0,height:0}),i=mj(e,r.rowStart,r.colStart);return{c:r.colStart,r:r.rowStart,x:t-i.x,y:n-i.y}};function _j(e,t){return{tl:gj(t,e.x,e.y),br:gj(t,e.x+e.width,e.y+e.height)}}function vj(e,t,n){let r=e=>({c:Math.min(n.colEnd,Math.max(n.colStart,t.colIndex+(e.c??0))),r:Math.min(n.rowEnd,Math.max(n.rowStart,t.rowIndex+(e.r??0))),x:e.x??0,y:e.y??0});return{tl:r(e.tl),br:r(e.br)}}var yj=class extends UD{constructor(...e){super(...e),this._replies=new Map}_initialize(e){super._initialize(e),this._boxes=[],this._updateState({...wj,commentId:n.CommonUtils.uuidV4().toUpperCase()},(0,n.messageKey)(`op.initializeComment`)),this._fromJSON(e?.json)}_getActionDescription(e){return e===`delete`?(0,n.messageKey)(`op.deleteComment`):e===`initialize`?(0,n.messageKey)(`op.initializeComment`):null}_isAnchorAbsolute(){return!0}_processContainerShift(e){let t=super._processContainerShift(e);return e.after||this._getState().anchorCoords||this._delete(),this._processAnchorCoords(),t}_processDelete(){super._processDelete(),this._removeBox()}getId(){return this._getState().commentId}getSheet(){return this.getRange().getSheet()}getRange(e){return super.getRange(e)}getContent(){return aj(this._getState().content)}setContent(e,t){return this._updateState({content:oj(e),mentions:null},{description:(0,n.messageKey)(`op.setCommentContent`),...t},[`onContentChange`])}getRichContent(){let e=this._getState().content;return typeof e==`string`?null:cj(e)}getAuthor(){return this._resolvePerson(this._getState().personId)}getCreationDate(){return xj(this._getState().dt)}isResolved(){return this._getState().done}setResolved(e,t){return!!e===this._getState().done?this:this._updateState({done:!!e},{description:e?(0,n.messageKey)(`op.resolveComment`):(0,n.messageKey)(`op.reopenComment`),...t},[`onResolvedChange`])}isNote(){return this._getState().asNote}getReplies(){let e=this._getState().replies,t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=this._replyFor(e[n].id);return t}getReply(e){return typeof e==`string`&&this._findReplyJSON(e)?this._replyFor(e):null}addReply(e,t){let{person:r,...i}=t??{},a={id:n.CommonUtils.uuidV4().toUpperCase(),personId:pj(r,this._getPeople())??void 0,content:aj(e),dt:new Date().toISOString()},o=this._getState(),s=o.asNote,c=this._beginCommit({description:(0,n.messageKey)(`op.addCommentReply`),...i});try{this._updateState({replies:[...o.replies,a],...s?Tj:null},{description:(0,n.messageKey)(`op.addCommentReply`),...i},[`onRepliesChange`]),s&&this._removeBox(),c.commit()}catch(e){throw c.rollback(),e}return this._replyFor(a.id)}update(e,t){let r=e&&`isIComment`in e?function(e){let t={content:e.getRichContent()??e.getContent(),asNote:e.isNote(),resolved:e.isResolved()},n=e.getAuthor();return n&&(t.person=n),t}(e):{...e},i={},a=[];r.content!==void 0&&(i.content=oj(r.content),i.mentions=null,a.push(`onContentChange`)),r.person!==void 0&&(i.personId=pj(r.person,this._getPeople()),a.includes(`onContentChange`)||a.push(`onContentChange`));let o=this._getState().asNote,s=r.asNote===void 0?o:!!r.asNote;if(s!==o&&Object.assign(i,s?{asNote:!0}:Tj),r.resolved!==void 0&&(i.done=!!r.resolved,a.push(`onResolvedChange`)),Object.keys(i).length===0)return this;let c=this._beginCommit({description:(0,n.messageKey)(`op.updateComment`),...t});try{this._updateState(i,{description:(0,n.messageKey)(`op.updateComment`),...t},a),o&&!s?this._removeBox():s&&!o&&this._placeBox(null,!0),c.commit()}catch(e){throw c.rollback(),e}return this}getType(){return this.isNote()?`note`:`comment`}getTypeDescription(){return this.isNote()?`Note`:`Comment`}getDescription(){return this._getState().description}setDescription(e){let t=e||null;return t===this._getState().description||this._updateState({description:t},{description:(0,n.messageKey)(`op.setMovableDescription`)},[`onAnyChange`]),this}getMovable(){return this._getState()?.asNote?this._getBox():null}_getBox(){let e=this._boxes;for(let t=e.length-1;t>=0;t--)if(!e[t].isDeleted())return e[t];return null}_placeBox(e,t){let n=this._options.boxes;n&&!this._getBox()&&this._boxes.push(n.add(this,e,t))}_removeBox(){this._getBox()?._deleteFromContent()}addListeners(e,t){return this._getEmitter().addListeners(e,t)}toJSON(){let e=this._getState();if(!e)return null;let t={id:e.commentId};e.personId&&(t.personId=e.personId);let n=e.content;if(typeof n==`string`?n&&(t.content=n):t.content=cj(n),e.dt&&(t.dt=e.dt),e.done&&(t.done=!0),e.asNote&&(t.asNote=!0),e.mentions&&(t.mentions=e.mentions.map(e=>({...e}))),e.replies.length>0&&(t.replies=e.replies.map(e=>({...e}))),e.asNote){e.description&&(t.description=e.description);let n=this._getBox();n&&!n.isHidden()&&(t.shown=!0);let r=this._options.boxes,i=n&&r&&!r.isDefault(this,n)?n._getAnchorJSON():null;if(i||e.boxXml){let n={};if(i){let e=this.getRange().getCoords();n.anchor=function(e,t){return{tl:{c:(e.tl.c??0)-t.colIndex,r:(e.tl.r??0)-t.rowIndex,x:e.tl.x??0,y:e.tl.y??0},br:{c:(e.br.c??0)-t.colIndex,r:(e.br.r??0)-t.rowIndex,x:e.br.x??0,y:e.br.y??0}}}(i,{rowIndex:e.rowStart,colIndex:e.colStart})}e.boxXml&&(n.xml=e.boxXml),t.box=n}}return t}_fromJSON(e,t){if(!e)return;let r={};e.id&&(r.commentId=e.id),e.personId!==void 0&&(r.personId=e.personId||null),e.content!==void 0&&(r.content=oj(e.content)),e.dt!==void 0&&(r.dt=e.dt||null),e.done!==void 0&&(r.done=!!e.done),e.asNote!==void 0&&(r.asNote=!!e.asNote),e.mentions!==void 0&&(r.mentions=e.mentions?e.mentions.map(e=>({...e})):null),e.replies!==void 0&&(r.replies=(e.replies??[]).filter(e=>!!e).map(e=>({...e,id:e.id||n.CommonUtils.uuidV4().toUpperCase(),content:oj(e.content)})));let i=null,a=!!e.shown;if(e.asNote){e.description!==void 0&&(r.description=e.description||null);let t=e.box;if(r.boxXml=t?.xml||null,i=t?.anchor??null,!i&&t?.xml){let n=function(e){let t=uj.exec(e),n=dj.exec(e),r=lj.exec(e);if(!t||!n||!r)return null;let i=r[1].split(`,`).map(e=>parseInt(e.trim(),10));if(i.length!==8||i.some(e=>isNaN(e)))return null;let a=parseInt(t[1],10),o=parseInt(n[1],10);return{anchor:{tl:{c:i[0]-o,x:i[1],r:i[2]-a,y:i[3]},br:{c:i[4]-o,x:i[5],r:i[6]-a,y:i[7]}},shown:fj.test(e)}}(t.xml);n&&(i=n.anchor,e.shown===void 0&&(a=n.shown))}!i||i.tl&&i.br||(i=null)}Object.keys(r).length>0&&this._updateState(r,{description:(0,n.messageKey)(`op.addComment`),...t}),e.asNote&&this._placeBox(i?{tl:{...i.tl},br:{...i.br}}:null,!a)}_getPeople(){return this._options.getPeople?.()??null}_resolvePerson(e){return e?this._getPeople()?.getById(e)??null:null}_findReplyJSON(e){let t=this._getState()?.replies;if(!t)return null;for(let n=0;n<t.length;n++)if(t[n].id===e)return t[n];return null}_replyFor(e){let t=this._replies.get(e);return t||(t=new bj(this,e),this._replies.set(e,t)),t}_updateReply(e,t,r){let i=this._getState().replies,a=i.findIndex(t=>t.id===e);if(a<0)throw new n.ExpectedError((0,n.t)(`error.comment.replyDeleted`));let o=i.slice(),{mentions:s,...c}=i[a];o[a]={...c,content:aj(t)},this._updateState({replies:o},{description:(0,n.messageKey)(`op.setCommentContent`),...r},[`onRepliesChange`])}_deleteReply(e,t){let r=this._getState().replies;r.some(t=>t.id===e)&&this._updateState({replies:r.filter(t=>t.id!==e)},{description:(0,n.messageKey)(`op.deleteCommentReply`),...t},[`onRepliesChange`])}get[Symbol.toStringTag](){return`[Comment]`}toString(){return`Comment:${this.getRange()?.toString()}:${this.getContent()}`}get isIComment(){return!0}},bj=class{constructor(e,t){this._parent=e,this._id=t}_json(){let e=this._parent._findReplyJSON(this._id);if(!e)throw new n.ExpectedError((0,n.t)(`error.comment.replyDeleted`));return e}getId(){return this._id}getParent(){return this._parent}getRange(e){return this._parent.getRange(e)}getContent(){return aj(this._json().content)}setContent(e,t){return this._parent._updateReply(this._id,e,t),this}getAuthor(){return this._parent._resolvePerson(this._json().personId)}getCreationDate(){return xj(this._json().dt)}isResolved(){return this._parent.isResolved()}delete(e){this._parent._deleteReply(this._id,e)}isDeleted(){return this._parent.isDeleted()||this._parent._findReplyJSON(this._id)===null}toJSON(){return{...this._json()}}get[Symbol.toStringTag](){return`[CommentReply]`}get isICommentReply(){return!0}};function xj(e){if(!e)return null;let t=new Date(e);return isNaN(t.getTime())?null:t}var Sj,Cj,wj=Object.freeze({personId:null,content:``,dt:null,done:!1,asNote:!1,mentions:null,replies:Object.freeze([]),description:null,boxXml:null}),Tj=Object.freeze({asNote:!1,description:null,boxXml:null}),Ej=class extends S{constructor(e,t,n){super(),this._add=e,this._get=t,this._addListeners=n}add(e,t,r){if(!this._add)throw Error((0,n.t)(`error.comment.addOnSheet`));if(!e)throw Error((0,n.t)(`error.address.noAddress`));return this._add(e,t,r)}_getItems(e){let t=this._get(e?.address,e?.ignoreHidden,e?.fullyContained),n=e?.resolved,r=e?.notes;return n===void 0&&r===void 0||(t=t.filter(e=>(r===void 0||e.isNote()===r)&&(n===void 0||e.isResolved()===n))),t}getById(e){return typeof e==`string`?this._get(null).find(t=>t.getId()===e)??null:null}getAt(e){return e?this._get(e)[0]??null:null}getByReplyId(e){return typeof e==`string`?this._get(null).find(t=>t.getReply(e)!==null)??null:null}addListeners(e,t){return this._addListeners(e,t)}get isICommentCollection(){return!0}},Dj=class extends pk{_processContainerRemoved(){let e=this.getContent();if(e.isDeleted())return null;let t=e.getRange().getCoords(),n=this._optionsMovable;if(!n.getMaxBounds)return null;let r={getBoundsAtCoords:n.getBoundsAtCoords,getCoordsAtBounds:n.getCoordsAtBounds,getMaxBounds:n.getMaxBounds};return _j(hj({rowIndex:t.rowStart,colIndex:t.colStart},r),r)}getSnapshot(e,t){return null}get[Symbol.toStringTag](){return`[NoteMovable]`}};(Cj=Sj||={}).HeaderTextStyle={A1:`a1`,Zero:`zero`,One:`one`},Cj.ColumnHeaderTableNames={Sticky:`sticky`,Hidden:`hidden`,None:`none`};var Oj=(e=(0,n.messageKey)(`op.update`))=>(0,n.t)(`error.sheet.protectedField`,{description:(0,n.t)(e)}),kj=e=>(0,n.t)(`error.sheet.unsupportedFloatingType`,{type:e}),Aj=e=>(0,n.t)(`error.sheet.itemOverlapping`,{type:e}),jj=e=>(0,n.t)(`error.sheet.maxValues`,{max:e}),Mj=class e{static{this.TypedThreshold=64}constructor(n){this._codes=new Uint8Array,this._nums=new Float64Array,this.createList=(t,n=t.length,r)=>{if(r===void 0){r=0;let e=t[0];for(let i=0;i<n;i++){let n=t[i];r|=z.hintOf(n)|(n===e?0:z.Hint.NotUniform)}}if((r&z.Hint.NotFinite)!==0)throw Error(`A raw NaN or Infinity reached storage. Numbers are normalized to #NUM! at entry.`);if(n<e.TypedThreshold)return new Rt.ArrayList(t.slice(0,n));if((r&z.Hint.NotUniform)===0)return new ln([t[0]],n);let i=r&z.Hint.KindMask;return((i&z.Hint.Object)===0?_i.fromArray(t,this.codec,{seen:i,length:n}):_i.fromArray(t,this.codec,{length:n}))??new Rt.ArrayList(t.slice(0,n))},this._strings=n,this.codec={isError:e=>!0===e.isFormulaError,encodeString:e=>n.add(e),decodeString:e=>n.getById(e),encodeError:e=>e.getCode(),decodeError:e=>t.FormulaError.getBuiltInByCode(e)??t.FormulaError.BuiltIn.Unknown}}fromJSONRun(e,t){let n=e.length,r=this._codes,i=this._nums;r.length<n&&(r=this._codes=new Uint8Array(n),i=this._nums=new Float64Array(n));let a=0,o=!0;for(let s=0;s<n;s++){let n=e[s],c=Nj,l=0,u=n?.t;if(u!==void 0)switch(l=n.v,u){case`e`:c=zj,t?.(s);break;case`r`:c=Ij;break;case`n`:c=(0|l)===l?Ij:Lj;break;case`s`:c=Rj;break;case`b`:c=l?Fj:Pj}else switch(typeof n){case`number`:l=n,c=(0|l)===l?Ij:Lj;break;case`string`:l=parseInt(n),c=Rj;break;case`boolean`:c=n?Fj:Pj}r[s]=c,i[s]=l,a|=1<<c,(c!==r[0]||c>=Ij&&l!==i[0])&&(o=!1)}return this._fromCodes(r,i,n,a,o)}fromEncoded(e,t){let n=e.length,r=0,i=!0,a=e[0],o=t[0];for(let s=0;s<n;s++){let n=e[s];r|=1<<n,(n!==a||n>=Ij&&t[s]!==o)&&(i=!1)}return this._fromCodes(e,t,n,r,i)}_fromCodes(t,n,r,i,a){if(r<e.TypedThreshold){let e=Array(r);for(let i=0;i<r;i++)e[i]=this._decode(t[i],n[i]);return new Rt.ArrayList(e)}return a?new ln([this._decode(t[0],n[0])],r):_i.fromEncoded(t,n,this.codec,{seen:i,length:r})}_decode(e,t){switch(e){case Ij:case Lj:return t;case Rj:return this.codec.decodeString(t);case zj:return this.codec.decodeError(t);case Fj:return!0;case Pj:return!1}return null}},Nj=_i.Type.Blank,Pj=_i.Type.False,Fj=_i.Type.True,Ij=_i.Type.Int32,Lj=_i.Type.Float64,Rj=_i.Type.String,zj=_i.Type.Error,Bj=Object.freeze([gv.Feature.Contentful]),Vj=e=>{if(e===void 0)return Bj;let t=typeof e==`string`?[e]:e,n=[];for(let e=0;e<t.length;e++){let r=Hj.get(String(t[e]).toLowerCase());if(r===void 0)throw Error(`Unknown feature '${t[e]}'. Features: ${Object.values(gv.Feature).join(`, `)}.`);n.push(r)}return Object.freeze(n)},Hj=new Map(Object.values(gv.Feature).map(e=>[e.toLowerCase(),e])),Uj=class{constructor(e,t,n,r){this._range=null,this._clipped=null,this._coords=Object.freeze(e),this._internal=t,this._features=n,this._bounds=r}getFeatures(){return this._features}getCoords(){return this._coords}getAddress(e){let t=this._internal;return hd(this._coords,t.getSheet().getEntireCoords(),void 0)}getRowCount(){let e=this._coords;return e.rowEnd-e.rowStart+1}getColumnCount(){let e=this._coords;return e.colEnd-e.colStart+1}isClipped(){let e=this._clipped;return e===null&&(e=this._probeClipped(),this._clipped=e),e}_probeClipped(){let e=this._coords,t=this._bounds,n=this._internal.getSheet().getEntireCoords(),r=e=>{let t=new Kj(e,this._internal).getCounts(this._features),n=this._features;for(let e=0;e<n.length;e++)if((t[n[e]]??0)>0)return!0;return!1};return!!(e.rowStart===t.rowStart&&t.rowStart>n.rowStart&&r({rowStart:t.rowStart-1,rowEnd:t.rowStart-1,colStart:e.colStart,colEnd:e.colEnd}))||!!(e.rowEnd===t.rowEnd&&t.rowEnd<n.rowEnd&&r({rowStart:t.rowEnd+1,rowEnd:t.rowEnd+1,colStart:e.colStart,colEnd:e.colEnd}))||!!(e.colStart===t.colStart&&t.colStart>n.colStart&&r({rowStart:e.rowStart,rowEnd:e.rowEnd,colStart:t.colStart-1,colEnd:t.colStart-1}))||!!(e.colEnd===t.colEnd&&t.colEnd<n.colEnd&&r({rowStart:e.rowStart,rowEnd:e.rowEnd,colStart:t.colEnd+1,colEnd:t.colEnd+1}))}getCell(){return this.getRange().getCell()}getRange(){let e=this._range;return e||(e=new Kj(this._coords,this._internal),this._range=e),e}toString(){return this.getAddress()}get[Symbol.toStringTag](){return`[CellRegion: ${this.getAddress()}]`}get isICellRegion(){return!0}},Wj=class{constructor(e,t,n,r){this._regions=null,this._range=null,this._bounds=e,this._internal=t,this._features=n,this._options=r}getFeatures(){return this._features}getRange(){let e=this._range;return e||(e=new Kj(this._bounds,this._internal),this._range=e),e}getCount(){return this._materialize().length}*[Symbol.iterator](){yield*this._materialize()}_materialize(){let e=this._regions;if(!e){let t=this._internal,n=t.featureRegions(this._bounds,this._features,this._options),r=n.length;e=Array(r);for(let i=0;i<r;i++)e[i]=new Uj(n[i],t,this._features,this._bounds);this._regions=e}return e}get[Symbol.toStringTag](){return`[CellRegions: ${this._features.join(`, `)}]`}get isICellRegions(){return!0}},Gj=Object.freeze([]),Kj=class e{constructor(e,t,n){this._coords=Object.freeze(e),this._internal=t,this._readOnly=n?.readOnly??null,this._options=n??void 0}_getStickyOptions(){return this._options?.getOptions}getCoords(){return this._coords}_createRange(t,n){let r=this._internal;if(!t)return XV(r.getSheet(),r.getSheet().getEntireCoords());if(t=this._scopeDerived(t),r.validateCoords(t),r.getSheet().isClosed())return XV(null,r.getSheet().getEntireCoords(),t);let i=this._options;return n&&(i={...this._options,getOptions:xH(this._options?.getOptions,n)}),new e(t,this._internal,i)}_scopeDerived(e){let t=this._coords.scope;return t&&e&&!e.scope?{...e,scope:t}:e}_createRanges(e,t){let n=this._options;return t&&(n={...this._options,getOptions:xH(this._options?.getOptions,t)}),new EV(this._coords.scope?e?.map(e=>this._scopeDerived(e)):e,this._internal,n)}_deriveRanges(e,t){let n=this.getCoords(),r=n;return t&&(r=t(n),!r)?null:this._createRanges(r,e)}_deriveRange(e,t,n){if(!e)return this;let r=this._internal.rangeToCoords(e);if(!r)return this;let i=this.getCoords();if(gH(r,i))return this;if(n){let e=n(r,i);if(!e)return null;r={...i,...e}}return function(e,t){t&&(t.$colStart===void 0?delete e.$colStart:e.$colStart=t.$colStart,t.$rowStart===void 0?delete e.$rowStart:e.$rowStart=t.$rowStart,t.$colEnd===void 0?delete e.$colEnd:e.$colEnd=t.$colEnd,t.$rowEnd===void 0?delete e.$rowEnd:e.$rowEnd=t.$rowEnd)}(r,i),this._createRange(r,xH(this._options?.getOptions,t))}_validateMaxSize(e=5e4){let t=this.getCoords(),r=this._internal,i=r.getUsedCoords(),a=Math.min(t.colEnd,i?.colEnd??t.colEnd),o=Math.min(t.rowEnd,i?.rowEnd??t.rowEnd),s=1;a>=t.colStart&&(s=r.getSheet().getColumnHeaders().getVisibleCount(t.colStart,a));let c=1;if(o>=t.rowStart&&(c=r.getSheet().getRowHeaders().getVisibleCount(t.rowStart,o)),c*s>e)throw new n.ExpectedError(jj(e))}_readSingleCell(e,n){let r=this.getCoords();if(r.rowStart!==r.rowEnd||r.colStart!==r.colEnd||e?.includeMergeOverflow||(e?.maxSize??5e4)<1)return;let i=e?.ignoreHidden;if(i){let e=this._internal.getSheet();if((!0===i||i===t.IRange.Axis.Row)&&e.getRowHeaders().getVisibleCount(r.rowStart,r.rowStart)===0||(!0===i||i===t.IRange.Axis.Column)&&e.getColumnHeaders().getVisibleCount(r.colStart,r.colStart)===0)return[]}return[[n(r.rowStart,r.colStart)]]}entries(e){let t=this.getCoords(),r=t,i=this._internal;if(e?.address){let a=i.rangeToCoords(e?.address);if(!a)throw new n.ExpectedError(o_(e?.address));if(r=n.CoordUtils.intersectRanges(a,t),!r)return Bt}r.colEnd<r.colStart&&(r.colStart=t.colStart,r.colEnd=t.colEnd),r.rowEnd<r.rowStart&&(r.rowStart=t.rowStart,r.rowEnd=t.rowEnd);let a=this._getStickyOptions();return i.cellIterator({ignoreHidden:a?.ignoreHidden??!1,...e,searchTypes:sf(e?.features??a?.features),bounds:r})}[Symbol.iterator](){return this.values()}values(e){let t=this.entries({...e,features:Gj});return{next(){let e=t.next();return e.done?zt:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}forEach(e,t){if(!e)return;let n=this.entries(t),r=n.next();for(;!r.done;){let t=r.value,i=e(t.value,t.context);if(i)return i.break;r=n.next()}}_validateWrite(){let e=this._readOnly;if(e)throw new n.ExpectedError((0,n.t)(e))}updateCells(e,r,i){this._validateWrite();let a=this.getCoords();i||=a;let o=this._internal,s=o.isDataColumn(),c={majorStart:s?a.colStart:a.rowStart,majorEnd:s?a.colEnd:a.rowEnd,minorStart:s?a.rowStart:a.colStart,minorEnd:s?a.rowEnd:a.colEnd},l=(r?.axis??t.IRange.Axis.Row)===t.IRange.Axis.Column!==s,u=Yr(Array.isArray(e)?e:[[e]],l,c);return o.updateTuples(u,{description:r?.description??(n.CoordUtils.isSingleCell(i)?(0,n.t)(`op.setCellAddress`,{address:hd(i,o.getSheet().getEntireCoords())}):(0,n.t)(`op.setRangeAddress`,{address:hd(i,o.getSheet().getEntireCoords())})),...r},null,{isCell:!0}),this}setValues(e,t){if(!e||!Array.isArray(e)&&!e.isIRange)throw new n.ExpectedError((0,n.t)(`error.sheet.setValuesType`));return this._setValueOrValues(e,t)}setValue(e,t){if(e&&(Array.isArray(e)||e.isIRange))throw new n.ExpectedError((0,n.t)(`error.sheet.setValueType`));return this._setValueOrValues(e,t)}setFormula(e,t){if(e&&(Array.isArray(e)||e.isIRange))throw new n.ExpectedError((0,n.t)(`error.sheet.setValueType`));return this._setValueOrValues(e,t)}_setValueOrValues(e,r){this._validateWrite();let i=this.getCoords(),a=this,o=this._internal,s=o.isDataColumn(),c=(r?.axis??t.IRange.Axis.Row)===t.IRange.Axis.Column,l=Array.isArray(e),u=!l&&e?.isIRange;if(r?.skipBoundsCheck??n.CoordUtils.isSingleCell(i)){let t=c?i.colStart:i.rowStart,r=c?i.rowStart:i.colStart,o=0,s=0;if(l){let t=e;o=Math.max(0,t.length-1),s=0;for(let e=0;e<t.length;e++)s=Math.max(s,t[e].length-1)}else if(u){let t=e.getColumnCount(),n=e.getRowCount();o=c?t-1:n-1,s=c?n-1:t-1}let d={...i,colEnd:c?t+o:r+s,rowEnd:c?r+s:t+o};n.CoordUtils.isEqualRanges(d,i)||(i=d,a=this._deriveRange(d)??this)}let d=s?i.colStart:i.rowStart,f=s?i.colEnd:i.rowEnd,p=s?i.rowStart:i.colStart,m={majorStart:d,majorEnd:f,minorStart:p,minorEnd:s?i.rowEnd:i.colEnd},h=null,g=!1,_=null;if(r?.arrayFixed){if(l||u||typeof e!=`string`||e.charAt(0)!==`=`)throw new n.ExpectedError((0,n.t)(`error.sheet.arrayFixedFormula`));let t=i.rowEnd-i.rowStart+1,r=i.colEnd-i.colStart+1,a=Array(t);for(let e=0;e<t;e++)a[e]=Array(r).fill(null);a[0][0]=e,h=Yr(a,s,m),_={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd}}else if(l){let t=c!==s;h=Yr(Array.isArray(e)?e:[[e]],t,m)}else if(u){let r=e._materializeEmpty?.()??e,a=r._values;if(a&&a.getValues&&a.getAxis&&a.getAxis()===(s?t.IRange.Axis.Column:t.IRange.Axis.Row)){let e=r._coords;if(h=a.getValues(e),h){let e=h.bounds;h=function(e,t,n){let r=e.tuples,i=e.bounds,a=t,o=n,s=[];for(let e of r){let t=e[0]+a,n=e[1],r=[];for(let e of n){let t=e[0]+o;r.push([t,e[1]])}s.push([t,r])}return{tuples:s,bounds:{majorStart:i.majorStart+a,minorStart:i.minorStart+o,majorEnd:i.majorEnd+a,minorEnd:i.minorEnd+o}}}(h,d-e.majorStart,p-e.minorStart)}}else{let e=s?t.IRange.Axis.Column:t.IRange.Axis.Row;h=function(e,t,r,i=null){let a=t!==n.RangeAxis.Row,o=i?.colIndex??0,s=i?.rowIndex??0,c=a?o:s,l=a?s:o,u=e.next();for(;!u.done;){let t=u.value,n=t.coords,i=a?n.colIndex:n.rowIndex,o=a?n.rowIndex:n.colIndex;r.pushAt(c+i,l+o,t.value),u=e.next()}return r.build()}(r.entries({axis:e}),e,o.createTupleBuilder(),{colIndex:i.colStart,rowIndex:i.rowStart})}}else h=Jr(e,m,s),g=!0;return o.updateTuples(h,{description:r?.description??(n.CoordUtils.isSingleCell(i)?(0,n.t)(`op.setValueAddress`,{address:hd(i,o.getSheet().getEntireCoords())}):(0,n.t)(`op.setValuesAddress`,{address:hd(i,o.getSheet().getEntireCoords())})),...r},null,_?{arrayFixed:_}:g?{isBroadcast:!0}:null),a}getValues(e){let t=this._internal,n=this._readSingleCell(e,(e,n)=>t.getScalar(e,n,!1));if(n)return n;this._validateMaxSize(e?.maxSize);let r=this.getCoords();return hH(t.cellIterator,r,e,!1,!1)}getValuesRange(){let e=this._internal,t=e.getSheet();return new OW(t.getRuntime(),e.getCalcGrid().getValues(),this.getCoords(),void 0,t.getEntireCoords.bind(t),t.getName.bind(t))}setComputedValues(e,t){let r=this;return r._internal.getSheet().doBatch(()=>{let t=e(r.getValuesRange());r.setValues(t)},{description:(0,n.messageKey)(`op.setComputedValues`),...t}),this}getInteropValues(e){let t=this._internal,n=this._readSingleCell(e,(e,n)=>t.getScalar(e,n,!0));if(n)return n;this._validateMaxSize(e?.maxSize);let r=this.getCoords();return hH(t.cellIterator,r,e,!1,!0)}getValue(){let e=this.getCoords();return this._internal.getScalar(e.rowStart,e.colStart,!1)}getInteropValue(){let e=this.getCoords();return this._internal.getScalar(e.rowStart,e.colStart,!0)}calculate(e){return this._internal.calculate([this.getCoords()],{full:e}),this}getCells(e){let t=this._internal,n=this._readSingleCell(e,(e,n)=>t.getCellAt(e,n));if(n)return n;this._validateMaxSize(e?.maxSize);let r=this.getCoords();return hH(t.cellIterator,r,e,!0,!1)}getCell(e){let t=this.getCoords(),r=t.colStart,i=t.rowStart,a=this._internal;if(e){let o=a.cellToCoords(e);if(!n.CoordUtils.isCellWithinRange(o,t))throw new n.ExpectedError((0,n.t)(`error.sheet.oobCell`));r=o.colIndex,i=o.rowIndex}return a.getCellAt(i,r)}getFormula(e){return this.getCell(e).getFormula()}getFormulas(){let e=this.getCoords(),t=this._createDense(``);for(let n of this.getRegions(gv.Feature.Formula)){let r=n.getRange().entries({features:gv.Feature.Formula,ignoreHidden:!1});for(let n of r){let r=n.context.getCell().getFormulaText();if(!r)continue;let i=n.context.getCoords(),a=t[i.rowIndex-e.rowStart];!a||i.colIndex<e.colStart||i.colIndex>e.colEnd||(a[i.colIndex-e.colStart]=r)}}return t}setFormulas(e,t){return this.setValues(e,t)}getNumberFormat(){return this.getStyle().getNumberFormat()}getNumberFormats(){let e=this.getCoords(),t=this._createDense(this.getSheet().getStyles().getNormal().getNumberFormat());for(let r of this.getRegions(gv.Feature.NumberFormat)){let i=n.CoordUtils.intersectRanges(r.getCoords(),e);if(!i)continue;let a=r.getCell().getStyle().getNumberFormat(),o=i.colStart-e.colStart,s=i.colEnd-e.colStart+1;for(let n=i.rowStart;n<=i.rowEnd;n++)t[n-e.rowStart].fill(a,o,s)}return t}setNumberFormat(e,t){return this.getStyle().setNumberFormat(e,t),this}setNumberFormats(e,t){let n=e.map(e=>e.map(e=>({style:{numberFormat:e}})));return this.updateCells(n,t)}_validateDenseSize(){let e=this.getCoords();if((e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1)>1e4)throw new n.ExpectedError(jj(1e4))}_createDense(e){this._validateDenseSize();let t=this.getCoords(),n=t.rowEnd-t.rowStart+1,r=t.colEnd-t.colStart+1,i=Array(n);for(let t=0;t<n;t++)i[t]=Array(r).fill(e);return i}createFormula(e,t){let n=this.getCoords();return this.getSheet().createFormula(e,{rowIndex:n.rowStart,colIndex:n.colStart},t)}addWatch(e,t,n){return this._addWatch(e,{onValues:t},void 0,n)}_addWatch(e,t,n,r){let i=this.getCoords();if(!n&&typeof e!=`string`){let t=e.getAnchor();if(t&&(t.rowIndex!==i.rowStart||t.colIndex!==i.colStart))throw Error(`ICellRange.addWatch was given a formula anchored outside the range; fill it with IFormula.shift first.`)}return this._internal.addWatch(i,e,t,n,r)}async select(e){let t=await this._internal.autoSelect(e??!0,DA([this.getCoords()]));return this._createRange(t[0])}find(e){return this._internal.find([this.getCoords()],e)}getFixed(e){return this._createRange(vH(this.getCoords(),e))}getRangeAt(e,t,n,r,i){return this._createRange({rowStart:e,colStart:t,rowEnd:n??e,colEnd:r??t},i)}getRowAt(e,t){let n=this.getCoords();return this._createRange({colStart:n.colStart,rowStart:e,colEnd:n.colEnd,rowEnd:e},t)}getRowAfter(e){let t=this.getCoords();if(!t)return this;let n=t.rowEnd;return this._createRange({colStart:t.colStart,rowStart:n+1,colEnd:t.colEnd,rowEnd:n+1},e)}getRowBefore(e){let t=this.getCoords();if(!t)return this;let n=t.rowStart;return this._createRange({colStart:t.colStart,rowStart:n-1,colEnd:t.colEnd,rowEnd:n-1},e)}getRowBy(e,t){let n=this.getCoords(),r=n.rowStart+e;return this._createRange({colStart:n.colStart,rowStart:r,colEnd:n.colEnd,rowEnd:r},t)}getColumnAt(e,t){let n=this.getCoords();return this._createRange({colStart:e,rowStart:n.rowStart,colEnd:e,rowEnd:n.rowEnd},t)}getColumnAfter(e){let t=this.getCoords();if(!t)return this;let n=t.colEnd;return this._createRange({colStart:n+1,rowStart:t.rowStart,colEnd:n+1,rowEnd:t.rowEnd},e)}getColumnBefore(e){let t=this.getCoords();if(!t)return this;let n=t.colStart;return this._createRange({colStart:n-1,rowStart:t.rowStart,colEnd:n-1,rowEnd:t.rowEnd},e)}getColumnBy(e,t){let n=this.getCoords(),r=n.colStart+e;return this._createRange({colStart:r,rowStart:n.rowStart,colEnd:r,rowEnd:n.rowEnd},t)}getTopLeft(e){let t=this.getCoords();if(!t)return this;let n=t.colStart,r=t.rowStart;return this._createRange({colStart:n,rowStart:r,colEnd:n,rowEnd:r},e)}getBottomRight(e){let t=this.getCoords();if(!t)return this;let n=t.colEnd,r=t.rowEnd;return this._createRange({colStart:n,rowStart:r,colEnd:n,rowEnd:r},e)}getSurrounding(e){let t=this._internal;return this._createRange(t.surroundingRegion(this.getCoords(),e))}getExtended(e,r){let i=(r&&typeof r!=`string`&&!r.isICell&&r.rowIndex===void 0?r:void 0)??{cell:r};if(i.basis===`adjacent`)return this._extendedAdjacent(e);let a=null,o=this.getCoords();switch(e){case t.IRange.Direction.Up:a={colIndex:o.colStart,rowIndex:o.rowStart};break;case t.IRange.Direction.Down:a={colIndex:o.colStart,rowIndex:o.rowEnd};break;case t.IRange.Direction.Left:a={colIndex:o.colStart,rowIndex:o.rowStart};break;case t.IRange.Direction.Right:a={colIndex:o.colEnd,rowIndex:o.rowStart}}let s=this._internal,c=i.cell?s.cellToCoords(i.cell):a;if(!n.CoordUtils.isCellWithinRange(c,o))throw new n.ExpectedError((0,n.t)(`error.address.invalidCell`));let l=s.extendRange(e,c);return i.fromBlank===`before`&&(l=this._restBeforeBlock(e,c,l)),l=n.CoordUtils.unionRanges(o,l),this._createRange(l)}_restBeforeBlock(e,r,i){let a=e=>this._createRange(n.CoordUtils.cellToRange(e)).isContentful(gv.Feature.Contentful);if(a(r))return i;let o=e===t.IRange.Direction.Up||e===t.IRange.Direction.Down,s=e===t.IRange.Direction.Up||e===t.IRange.Direction.Left,c=o?{rowIndex:s?i.rowStart:i.rowEnd,colIndex:r.colIndex}:{rowIndex:r.rowIndex,colIndex:s?i.colStart:i.colEnd},l=o?c.rowIndex:c.colIndex;if(l===(o?r.rowIndex:r.colIndex)||!a(c))return i;let u=l+(s?1:-1);return o?{...i,...s?{rowStart:u}:{rowEnd:u}}:{...i,...s?{colStart:u}:{colEnd:u}}}_extendedAdjacent(e){let r=this.getCoords(),i=this._internal,a=i.getSheet().getEntireCoords(),o=e===t.IRange.Direction.Up||e===t.IRange.Direction.Down,s=e===t.IRange.Direction.Up||e===t.IRange.Direction.Left,c=o?r.rowStart:r.colStart,l=o?r.rowEnd:r.colEnd,u=o?r.colStart:r.rowStart,d=o?r.colEnd:r.rowEnd,f=o?a.rowEnd:a.colEnd,p=o?a.colEnd:a.rowEnd,m=(e,t)=>o?{rowIndex:e,colIndex:t}:{rowIndex:t,colIndex:e},h=e=>o?s?e.rowStart:e.rowEnd:s?e.colStart:e.colEnd,g=e=>o?s?e.rowEnd:e.rowStart:s?e.colEnd:e.colStart,_=(e,t)=>s?Math.max(e,t):Math.min(e,t),v=(e,t)=>s?Math.min(e,t):Math.max(e,t),y=s?c-1:l+1;if(y<0||y>f)return this;let b=null;for(let t of[u-1,d+1]){if(t<0||t>p)continue;let r=m(y,t),a=n.CoordUtils.cellToRange(r);if(!this._createRange(a).isContentful(gv.Feature.Contentful))continue;let o=h(i.extendRange(e,r));b=b===null?o:v(b,o)}if(b===null)return this;let x=s?0:y,S=s?y:f,C=o?{rowStart:x,rowEnd:S,colStart:u,colEnd:d}:{rowStart:u,rowEnd:d,colStart:x,colEnd:S};for(let e of this._createRange(C).entries({features:[gv.Feature.Contentful],axis:o?t.IRange.Axis.Row:t.IRange.Axis.Column,reverse:s})){let t=n.CoordUtils.cellToRange(e.context.getCoords());if(s){let e=this._createRange(t).getMerges();e.length>0&&(t=e[0])}b=_(b,g(t)+(s?1:-1));break}if(s?b>=c:b<=l)return this;let w=o?{...r,...s?{rowStart:b}:{rowEnd:b}}:{...r,...s?{colStart:b}:{colEnd:b}};return this._createRange(w)}getEntireRows(e,n){let r=this._internal;return this._createRange(UV([this.getCoords()],r.getSheet().getEntireCoords(),t.IRange.Axis.Column,e)[0],n)}getEntireColumns(e,n){let r=this._internal;return this._createRange(UV([this.getCoords()],r.getSheet().getEntireCoords(),t.IRange.Axis.Row,e)[0],n)}getRowHeaders(e){let t=this.getCoords();return this._internal.getSheet().getRowHeaders().getRange(t,e)}getColumnHeaders(e){let t=this.getCoords();return this._internal.getSheet().getColumnHeaders().getRange(t,e)}getDifferences(e,n){return this._deriveRanges(n,r=>{let i=this._internal,a=hA(r,i.rangeToCoords(e),t.IRange.Axis.Row);return i.getVisible(a,n)})}getIntersect(e,t){return this._deriveRange(e,t,(e,t)=>n.CoordUtils.intersectRanges(e,t))}getUnion(e,t){return this._deriveRange(e,t,(e,t)=>n.CoordUtils.unionRanges(e,t))}getResizeTo(e,t,r){if(t??=0,(e??=0)<0||t<0)throw new n.ExpectedError((0,n.t)(`error.address.invalidRange`));let i=this.getCoords();return this._deriveRange({colStart:i.colStart,rowStart:i.rowStart,colEnd:t+i.colStart-1,rowEnd:e+i.rowStart-1},r)}getResizeBy(e,t,n){e??=0,t??=0;let r=this.getCoords();return this._deriveRange({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd+t,rowEnd:r.rowEnd+e},n)}getOffsetTo(e,t,n){let r=this.getCoords(),i=t,a=e,o={colStart:i,rowStart:a,colEnd:r.colEnd-r.colStart+i,rowEnd:r.rowEnd-r.rowStart+a};return this._deriveRange(o,n)}getOffsetBy(e,t,n){let r=this.getCoords(),i=r.colStart+t,a=r.rowStart+e,o={colStart:i,rowStart:a,colEnd:r.colEnd-r.colStart+i,rowEnd:r.rowEnd-r.rowStart+a};return this._deriveRange(o,n)}getUsedRange(e){let t=this._internal.getUsedCoords(xH(this._getStickyOptions(),e));if(!t)return null;let r=n.CoordUtils.intersectRanges(t,this.getCoords());return r?this._deriveRange(r,e):null}isEmpty(){let e=this._internal.getUsedCoords();return!e||!n.CoordUtils.intersectRanges(e,this.getCoords())}getColumnStart(){return this.getCoords().colStart}getRowStart(){return this.getCoords().rowStart}getColumnEnd(){return this.getCoords().colEnd}getRowEnd(){return this.getCoords().rowEnd}getColumnCount(){let e=this.getCoords();return e.colEnd-e.colStart+1}getRowCount(){let e=this.getCoords();return e.rowEnd-e.rowStart+1}getVisible(e){return this._deriveRanges(e,t=>this._internal.getVisible([t],e))}isContentful(e){let t=this._internal,n=this._getStickyOptions(),r=e??n?.features;if(r===void 0)return t.isContentful([this.getCoords()],n?.ignoreHidden??!1);let i=t.featureCounts([this.getCoords()],r,n?.ignoreHidden??!1),a=typeof r==`string`?[r]:r;for(let e=0;e<a.length;e++)if(i[a[e]]>0)return!0;return!1}getStats(e){return this._internal.getRangeStats([this.getCoords()],e)}getCounts(e){let t=this._internal,n=this._getStickyOptions();return t.featureCounts([this.getCoords()],e??n?.features,n?.ignoreHidden??!1)}getDirectPrecedents(){return this._internal.dependencyRanges(this.getCoords(),`precedents`,!0)}getDirectDependents(){return this._internal.dependencyRanges(this.getCoords(),`dependents`,!0)}getPrecedents(){return this._internal.dependencyRanges(this.getCoords(),`precedents`,!1)}getDependents(){return this._internal.dependencyRanges(this.getCoords(),`dependents`,!1)}getRegions(e,t){let n=this._getStickyOptions(),r=Vj(e??t?.features??n?.features);return new Wj(this.getCoords(),this._internal,r,{...t,ignoreHidden:t?.ignoreHidden??n?.ignoreHidden??!1})}isEntireRows(){let e=this._internal;return WV([this.getCoords()],e.getSheet().getEntireCoords(),!0)}isEntireColumns(){let e=this._internal;return GV([this.getCoords()],e.getSheet().getEntireCoords(),!0)}isEntireRange(){let e=this.getCoords(),t=this._internal;return GV([e],t.getSheet().getEntireCoords(),!0)&&WV([e],t.getSheet().getEntireCoords(),!0)}isSingleCell(){let e=this.getCoords();return n.CoordUtils.isSingleCell(e)}isEqual(e,t){let n=this._internal.rangeToCoords(e);return gH(this.getCoords(),n)}get size(){let e=this._coords;return e.colEnd-e.colStart+1*(e.rowEnd-e.rowStart+1)}getBounds(){return this._internal.getBoundsAtCoords(this.getCoords())}getBestFit(e){return this._internal.getBestFit(this.getCoords(),e)}isInvalid(){return!1}getDefaultShiftAxis(){return this._internal.getDefaultShiftAxis(this.getCoords())}getDefaultSortCriteria(e,t){return this._internal.getDefaultSortCriteria(this.getCoords(),e,t)}getDefaultAutoFillCriteria(e,t){let n=this._internal,r=t===void 0?void 0:n.rangeToCoords(t,()=>[],!0);return n.getDefaultAutoFillCriteria(this.getCoords(),e,r)}getMerges(){return this._internal.getMerges([this.getCoords()],this._getStickyOptions()?.ignoreHidden??!1)}_itemQuery(e){return{ignoreHidden:!!this._getStickyOptions()?.ignoreHidden,...e,address:this.getCoords()}}getUnlocked(e){return this._internal.getSheet().getProtectedRanges().getItems(this._itemQuery(e))}getConditionalFormats(e){return this._internal.getSheet().getConditionalFormats().getItems(this._itemQuery(e))}getDataValidations(e){return this._internal.getSheet().getDataValidations().getItems(this._itemQuery(e))}getComments(e){return this._internal.getSheet().getComments().getItems(this._itemQuery(e))}getTables(e){return this._internal.getSheet().getTables().getItems(this._itemQuery(e))}getMovables(e){return this._internal.getSheet().getMovables().getItems(this._itemQuery(e))}getSnapshot(e){return this._internal.getSnapshot([this.getCoords()],e)}isReadOnly(){return this._readOnly!==null}addListener(e,t){return this._internal.addListenerNode([this.getCoords()],e,t)}getSheet(){return this._internal.getSheet()}autoFill(e,t){t?.preview||this._validateWrite();let n=this._internal,r=n.rangeToCoords(e,()=>[],!0);t?.snap&&(r=n.autoFillRange(this.getCoords(),r));let i=n.autoFill(this.getCoords(),r,t);return t?.preview?new qj(r,n,i,this._getStickyOptions()):i?this._createRange(r):this}autoFit(e){return this._validateWrite(),this._internal.autoFit([this.getCoords()],e),this}clear(e,t){return this._validateWrite(),this._internal.clear([this.getCoords()],e,t),this}setHyperlink(e,t){return this._validateWrite(),this._internal.setHyperlinks([this.getCoords()],e,t),this}setComments(e,t){return this._validateWrite(),this._internal.setComments([this.getCoords()],e,t),this}getStyle(){return this._internal.getStyle([this.getCoords()])}merge(e){return this._validateWrite(),this._internal.merge([this.getCoords()],e),this}unmerge(e){return this._validateWrite(),this._internal.unmerge([this.getCoords()],e),this}textToColumns(e){if(this._validateWrite(),this.getColumnCount()!==1)throw new n.ExpectedError((0,n.t)(`error.address.textToColumnsMulti`));typeof e==`string`&&(e={delimiter:e});let r=function(e,n){let r=n?.textQualifier===void 0?`"`:n.textQualifier,i=n?.preserveEmptyFields??!1,a=n?.delimiter,o=e.sparseBuilder(),s=1,c=e.entries({axis:t.IRange.Axis.Column,onError:`ignore`}),l=c.next();for(;!l.done;){let e=l.value.value,t=l.value.coords.rowIndex;l=c.next();let n=e,u=typeof e;if(u===`string`)a===void 0&&(a=kH(e,r));else{if(u!==`number`)continue;n=e.toString()}if(a===void 0)continue;let d=AH(n,a,r,i);for(let e=0;e<d.length;e++)d[e]!==null&&o.pushAt(t,e,d[e]);s=Math.max(s,d.length)}return s===1?e:o.build()}(this.getValuesRange(),e),i=r.getColumnCount(),a=this,o=!0;if(e?.destination&&(a=this._deriveRange(e.destination),o=a.getTopLeft().isEqual(this.getTopLeft())),i<=1&&o)return this;if(!e?.replaceExisting){let e=a.getCoords(),t=o?e.colStart+1:e.colStart,s=e.colStart+i-1;if(s>=t&&this.getRangeAt(e.rowStart,t,e.rowStart+r.getRowCount()-1,s).isContentful())throw new n.ExpectedError((0,n.t)(`error.address.textToColumnsOverwrite`))}let s=this._internal,c=s.beginCommit({description:e?.description??(0,n.messageKey)(`op.textToColumns`),operation:{name:`textToColumns`}});try{let t=a.setValues(r,{description:(0,n.messageKey)(`op.textToColumns`),...e,skipBoundsCheck:!0});return s.commitWithDirectives(c,DA([t.getCoords()]),{autoSelect:e?.autoSelect,autoSelectRestore:e?.autoSelectRestore},{undo:DA([this.getCoords()])}),t}catch(e){throw c.rollback(),e}}removeDuplicates(e){this._validateWrite();let r=this.getCoords(),i=this.getColumnCount(),a=this.getRowCount(),o=e?.hasHeader??!1,s;Array.isArray(e?.columns)&&(s=e.columns.map(e=>{let t=typeof e==`string`?kd(e)-r.colStart:e;if(!(t>=0&&t<i))throw new n.ExpectedError((0,n.t)(`error.address.removeDuplicatesColumn`,{column:e}));return t}));let c=function(e,n,r){let i=r?new Set(r):null,a=new Map,o=new Set,s=[],c=0,l=(e,t)=>{c+=t-e+1;let n=s[s.length-1];n&&n.rowEnd===e-1?n.rowEnd=t:s.push({rowStart:e,rowEnd:t})},u=(e,t)=>{n&&e===0||(o.has(t)?l(e,e):o.add(t))},d=(e,t)=>{n&&e===0&&(e+=1),e<t&&!o.has(``)&&(o.add(``),e+=1),e<t&&l(e,t-1)},f=-1,p=``,m=e.entries({axis:t.IRange.Axis.Row,includeEmpty:!1}),h=m.next();for(;!h.done;){let{value:e,coords:{rowIndex:t,colIndex:r}}=h.value;t!==f&&(f!==-1&&u(f,p),d(f+1,t),f=t,p=``),n&&t===0||i!==null&&!i.has(r)||(p+=jH(r,e,a)),h=m.next()}return f!==-1&&u(f,p),{runs:s,count:c,isEmpty:f===-1}}(this.getValuesRange(),o,s);if(c.isEmpty)throw new n.ExpectedError((0,n.t)(`error.address.removeDuplicatesNoData`));let l=this._internal,u=this.getResizeTo(a-c.count,i);if(c.count>0){let i=c.runs.map(e=>({colStart:r.colStart,colEnd:r.colEnd,rowStart:r.rowStart+e.rowStart,rowEnd:r.rowStart+e.rowEnd})),a={colStart:r.colStart,colEnd:r.colEnd,rowStart:r.rowEnd-c.count+1,rowEnd:r.rowEnd},o=l.beginCommit({description:(0,n.messageKey)(`op.removeDuplicates`),...e,operation:{name:`removeDuplicates`}});try{l.deleteCells(i,t.IRange.Axis.Row),l.insertCells([a],t.IRange.Axis.Row),l.commitWithDirectives(o,DA([u.getCoords()]),e,{undo:DA([r])})}catch(e){throw o.rollback(),e}}return u}insert(e){return this._validateWrite(),typeof e==`object`&&e?.span?(this._spanShift(e,!0),this):(this._internal.insertCells([this.getCoords()],e),this)}_spanShift(e,r){let{span:i,...a}=e,o=this._internal.getSheet(),s=this.getCoords(),c=e.axis??this.getDefaultShiftAxis(),l=null,u=o.getTables().getItems();for(let e=0;e<u.length;e++){let t=u[e].getRange().getCoords();if(!(s.rowEnd<t.rowStart||s.rowStart>t.rowEnd||s.colEnd<t.colStart||s.colStart>t.colEnd)){if(!(s.rowStart>=t.rowStart&&s.rowEnd<=t.rowEnd&&s.colStart>=t.colStart&&s.colEnd<=t.colEnd))throw new n.ExpectedError((0,n.t)(`error.table.tableSplit`));l=u[e];break}}if(!l){let e=o.getEntireCoords(),n=c===t.IRange.Axis.Row?{...s,colStart:e.colStart,colEnd:e.colEnd}:{...s,rowStart:e.rowStart,rowEnd:e.rowEnd};r?this._internal.insertCells([n],{...a,axis:c}):this._internal.deleteCells([n],{...a,axis:c});return}if(c===t.IRange.Axis.Row){let e=l.getDataRange().getCoords();if(s.rowStart<e.rowStart||s.rowEnd>e.rowEnd)throw new n.ExpectedError((0,n.t)(`error.table.tableBodyRows`));let t=s.rowStart-e.rowStart,i=s.rowEnd-s.rowStart+1;r?l.addRows(t,i,a):l.deleteRowsAt(t,i,a);return}let d=l.getRange().getCoords(),f=s.colStart-d.colStart,p=s.colEnd-s.colStart+1,m=l,h=a.description??(r?p>1?(0,n.messageKey)(`op.addTableColumns`):(0,n.messageKey)(`op.addTableColumn`):p>1?(0,n.messageKey)(`op.deleteTableColumns`):(0,n.messageKey)(`op.deleteTableColumn`));o.doBatch(()=>{if(r)for(let e=0;e<p;e++)m.addColumn(f);else{let e=[];for(let t=0;t<p;t++){let n=m.getColumnAt(f+t);n&&e.push(n)}for(let t=e.length-1;t>=0;t--)e[t].delete()}},{...a,description:h})}addAutoTable(e){return this._validateWrite(),this._internal.getSheet().addAutoTable(this.getCoords(),e)}addTable(e){return this._validateWrite(),this._internal.getSheet().getTables().add(this.getCoords(),e)}async insertFrom(e,t){this._validateWrite();let n=await this._internal.insertFrom([this.getCoords()],e,t);return n?this._createRange(n):null}canInsertFrom(e,t){return this._internal.canInsertFrom([this.getCoords()],e,t)}async copyFrom(e,t){this._validateWrite();let n=await this._internal.copyFrom(this.getCoords(),e,t);return n?this._createRange(n):null}delete(e){return this._validateWrite(),typeof e==`object`&&e?.span?(this._spanShift(e,!1),this):(this._internal.deleteCells([this.getCoords()],e),this)}sort(e){this._validateWrite();let t=this._internal,r=this.getCoords(),i=t.sort(r,e);return n.CoordUtils.isEqualRanges(i,r)?this:this._createRange(i)}sortAt(e,t,n,r){return this.sort({sorts:[{index:e,criteria:{reverse:t,sortOn:n}}],...r})}async filter(e,t){this._validateWrite();let r=this._internal,i=this.getCoords(),a=await r.filter(i,e,t);return n.CoordUtils.isEqualRanges(a,i)?this:this._createRange(a)}doBatch(e,t){return this._internal.getSheet().doBatch(t=>e(t),typeof t==`string`?t:{description:(0,n.messageKey)(`op.rangeUpdate`),...t})}createSparseBuilder(e){return this._internal.createSparseBuilder(e,this)}getAddress(e){let t=this._internal;return gd(this.getCoords(),t.getSheet().getEntireCoords())}toString(){return this.getAddress()}get[Symbol.toStringTag](){return`[SheetRange]`}get isICellRange(){return!0}},qj=class extends Kj{constructor(e,t,r,i){super(e,t,{getOptions:i??{},readOnly:(0,n.messageKey)(`error.sheet.previewRange`)}),this._projection=r}getCell(e){let t=this.getCoords(),r=t.rowStart,i=t.colStart;if(e){let a=this._internal.cellToCoords(e);if(!n.CoordUtils.isCellWithinRange(a,t))throw new n.ExpectedError((0,n.t)(`error.sheet.oobCell`));r=a.rowIndex,i=a.colIndex}return this._projection.getCellAt(r,i)}getCells(e){return this._validateMaxSize(e?.maxSize),this._projectRows(e=>e)}getValues(e){return this._validateMaxSize(e?.maxSize),this._projectRows(e=>e.getValue())}getInteropValues(e){return this._validateMaxSize(e?.maxSize),this._projectRows(e=>e.getInteropValue())}getFormulas(){return this._validateDenseSize(),this._projectRows(e=>e.getFormulaText()??``)}getNumberFormats(){return this._validateDenseSize(),this._projectRows(e=>e.getStyle().getNumberFormat())}getValuesRange(){return Jj()}_projectRows(e){let t=this.getCoords(),n=this._projection,r=[];for(let i=t.rowStart;i<=t.rowEnd;i++){let a=[];for(let r=t.colStart;r<=t.colEnd;r++)a.push(e(n.getCellAt(i,r)));r.push(a)}return r}get[Symbol.toStringTag](){return`[PreviewSheetRange]`}},Jj=()=>{throw new n.ExpectedError((0,n.t)(`error.sheet.previewRange`))},Yj=class extends Kj{constructor(e,t,n,r,i,a){super(n,r,i),this.isINamedRange=!0,this._id=e,this._name=t,this._rangesResolver=a??null}getId(){return this._id}getName(){return this._name}getRanges(){return this._rangesResolver?this._rangesResolver():new EV([this._coords],this._internal,this._options)}toString(){return`${this.getName()} => ${this.getAddress()}`}get[Symbol.toStringTag](){return`[NamedRange: ${this._name}]`}},Xj=class extends Yj{constructor(e,t,n,r){super(e.id,e.name,{rowStart:e.rowIndex,colStart:e.colIndex,rowEnd:e.rowIndex,colEnd:e.colIndex},n,r),this._info=e,this._namedFormulas=t}_named(){return this._namedFormulas?.getById(this._info.id)??null}getRanges(){return this._named()?.getRanges()??null}getDirectPrecedents(){return this._named()?.getDirectPrecedents()??Promise.resolve(null)}getPrecedents(){return this._named()?.getPrecedents()??Promise.resolve(null)}getDirectDependents(){return this._named()?.getDirectDependents()??Promise.resolve(null)}getDependents(){return this._named()?.getDependents()??Promise.resolve(null)}get[Symbol.toStringTag](){return`[NamedCellRange: ${this.getName()} @ ${this.getAddress()}]`}};function Zj(e,r,i){let a=1,o=1,s=!1,c=e._getMerges([r]);if(c.length>0){s=!0;let e=c[0];if(a=e.colEnd-e.colStart+1,o=e.rowEnd-e.rowStart+1,(r.colEnd-r.colStart+1)%a!=0||(r.rowEnd-r.rowStart+1)%o!=0)throw new n.ExpectedError((0,n.t)(`error.sheet.sortMergeSize`));let t=c.length;for(let e=1;e<t;e++){let t=c[e];if(t.colEnd-t.colStart+1!==a||t.rowEnd-t.rowStart+1!==o)throw new n.ExpectedError((0,n.t)(`error.sheet.sortMergeSize`))}}let l=function(e,r,i,a){let o;typeof r==`boolean`?o={sorts:[{index:0,criteria:{reverse:r}}]}:Array.isArray(r)?o={sorts:r}:(o={...r},o.sorts&&o.sorts.length!==0||(o.sorts=[{index:0}]));let s=o?.axis??t.IRange.Axis.Row;o.axis=s,o.hasHeader=o.hasHeader??!1,o.reverse=o.reverse??oa.DefaultRangeOptions.reverse,o.collatorOptions=o.collatorOptions??oa.DefaultRangeOptions.collatorOptions,o.collators=o.collators??oa.DefaultCollators;let c=s===t.IRange.Axis.Row,l=e;o.hasHeader&&(l={...l},c?l.rowStart+=a:l.colStart+=i);let u=c?l.colEnd-l.colStart:l.rowEnd-l.rowStart,d=o.sorts?[...o.sorts]:[];d.length===0&&d.push({index:0});let f=d.length;for(let e=0;e<f;e++){let t=d[e]={index:e,...d[e]};if(t.index<0||t.index>u)throw new n.OutOfBoundsError((0,n.t)(`error.sort.sortOobRange`));let r=t.criteria;r!==null&&(t.criteria={reverse:r?.reverse??o.reverse,collatorOptions:r?.collatorOptions??o.collatorOptions,...r},d[e]=t)}return o.sorts=d,o}(r,i,a,o),u=l.axis,d=u===t.IRange.Axis.Row,f=r;l?.hasHeader&&(f={...f},d?f.rowStart+=o:f.colStart+=a);let p=d?f.colStart:f.rowStart,m=l.sorts,h=m.length;for(let e=0;e<h;e++){let t=m[e];t.index+=p}let g=m[0].criteria,_=l?.description??(g?.reverse?(0,n.messageKey)(`op.sortDescending`):(0,n.messageKey)(`op.sortAscending`));e._protectionCheck(()=>[`sort`],r,_);let v=[],y=[],b=null,x=null,S=null,C=-(2**53-1),w=Array(h),T=new Map;for(let e=0;e<h;e++)T.set(m[e],e);m.sort((e,t)=>e.index-t.index);for(let e=0;e<h;e++)w[T.get(m[e])]=e;let E=null,D=l?.includeHidden??!1;D||(E=Lt(uH(d?e._rowHeaders:e._colHeaders)));let O=e._cellIterator({bounds:f,axis:u,ignoreHidden:!D&&u,searchTypes:{[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.DateFormat]:!1,[W.Type.Continuous]:!1,[W.Type.Merge]:!1,[W.Type.Formula]:!1,[W.Type.Pending]:!1,[W.Type.Hyperlink]:!1,[W.Type.Comments]:!1}}),k=d?o:a,A=(d?f.rowStart:f.colStart)-k,j=O.next();for(;!j.done;){let e=j.value.context,t=e.getCell();if(s&&!t.isTopLeft()){j=O.next();continue}let n=e.getCoords(),r=d?n.rowIndex:n.colIndex,i=d?n.colIndex:n.rowIndex;if(A!==r){for(A+=k,E&&(A=E(A));A<r;)v.push(null),y.push(A),A+=k,E&&(A=E(A));x=[],S=[],b={minorIndex:r,values:x,sortValues:S},v.push(b),y.push(r),A=r,C=m[0].index}for(;i>C;){let e=m[S.length];C=e?e.index:2**53-1,i>C&&S.push(null)}i===C&&S.push(t),x.push(t),j=O.next()}if(!b||v.length===0)return;let M=new Map,N=new Map,P=l.collators,F=P.length;for(let e=0;e<F;e++){let t=P[e];M.set(t.type,t.compare),N.set(t.type,e)}let I=e.getRuntime().getLocaleProfile(),L=I.tag,R=Array(h),ee=(e,t)=>{let n=R[e];n||(R[e]=n=new Map);let r=n.get(t);if(!r){let i=N.get(t);r={...I.collator,...P[i]?.defaultOptions,...m[e].criteria?.collatorOptions,locale:L},n.set(t,r)}return r},te=v.length,ne=Array(te);for(let e=0;e<te;e++)ne[e]=v[e]===null;v.sort((e,n)=>{for(let r=0;r<h;r++){let i=w[r],a=e?e.sortValues[i]:null,o=n?n.sortValues[i]:null,s=a?a.getValue():null,c=o?o.getValue():null;if(s===c)continue;if(c===null)return-1;if(s===null)return 1;let l=a.getType(),u=o.getType();if(l===t.ScalarType.Error&&u===t.ScalarType.Error)return 0;let d;if(l!==u)d=N.get(l)-N.get(u);else{let e=M.get(l);if(!e)continue;d=e(s,c,ee(i,l))}if(d!==0)return m[i].criteria?.reverse?-d:d}return 0});let re=Array(te),ie=!1;for(let e=0;e<te;e++){let t=v[e],n=t?t.minorIndex!==y[e]:!ne[e];re[e]=n,n&&(ie=!0)}if(!ie)return f;let ae=e._beginCommit({description:_}),oe=e._getState().borderSpatial,se=[],ce=-1,le=-1,ue=()=>{ce!==-1&&se.push(d?{rowStart:ce,rowEnd:le,colStart:f.colStart,colEnd:f.colEnd}:{rowStart:f.rowStart,rowEnd:f.rowEnd,colStart:ce,colEnd:le})};for(let e=0;e<te;e++){if(!re[e])continue;let t=y[e];ce!==-1&&t<=le+1?le=Math.max(le,t+k-1):(ue(),ce=t,le=t+k-1)}ue(),e._clear(se,void 0,void 0,!0);let de=e._createSparseBuilder({axis:u});for(let e=0;e<te;e++){if(!re[e])continue;let t=v[e];if(!t)continue;let n=y[e],r=t.values,i=r.length;for(let e=0;e<i;e++){let t=r[e],i=t.getCoords(),a=d?n:i.rowIndex,o=d?i.colIndex:n;de.pushAt(a,o,t)}}return de.apply(),e._updateState({borderSpatial:oe}),ae.commit(),f}function Qj(e,t,n,r){return{x:e*r-t*n,y:e*n+t*r}}function $j(e){let t=0,n=0,r=0,i=0,a=0,o=0,s=0,c=e.length;if(c===0)return{m:0,b:0};if(c===1)return{m:1,b:e[0]};for(let l=0;l<c;l++)o=l+1,s=e[l],s==null||isNaN(s)||(t+=o,n+=s,i+=o*o,r+=o*s,a++);let l=(a*r-t*n)/(a*i-t*t);return{m:l,b:n/a-l*t/a}}var eM=class{constructor(e,t){this._c=e,this._tvTl=t}tvTl(){return this._tvTl(this._c)}getCoords(){return this._c}},tM=class e{constructor(e,t,n){this._tokens=null,this._r1c1=null,this.a1=e,this.ref=t,this.block=n}isCompiled(){return this.block!==null}setBlock(e){if(this.block=e,!e)return;let t=this.imageBlock(e);t!==this.a1&&(this.a1=t,this._tokens=null,this._r1c1=null)}imageBlock(e){let t=this.ref;return e.getTextAt(t.rowStart,t.colStart)}imageAtAnchor(){let e=this.ref;return this.a1=this._emitTextAt(e.rowStart,e.colStart),this}relativeForm(){let e=this._r1c1;return e===null&&(this._tokens=[],e=this._r1c1=Hd(this.a1,this.ref.rowStart,this.ref.colStart,this._tokens)),e}_emitterTokens(){return this._tokens||this.relativeForm(),this._tokens}_emitTextAt(e,t,n){let r=this._emitterTokens(),i=r.length,a=r=>{let i=r.colIndex,a=r.rowIndex,o=i!==-(2**53-1)&&!r.$colIndex&&i+t<0||a!==-(2**53-1)&&!r.$rowIndex&&a+e<0;return o&&n&&(n.oob=!0),o},o=``;for(let n=0;n<i;n++){let i=r[n];if(typeof i==`string`){o+=i;continue}let s=r[n+1]===`:`?r[n+2]:void 0;s===void 0||typeof s==`string`?o+=a(i)?`#REF!`:zd(i,e,t):(n+=2,o+=a(i)||a(s)?`#REF!`:zd(i,e,t)+`:`+zd(s,e,t))}return o}getTextAt(e,t,n,r,i){let a=this.block;return a?a.getTextAt(e,t,n,r,i):n?this.relativeForm():this._emitTextAt(e,t)}getTokensAt(e,t,n){return this.block?.getTokensAt(e,t,n)??[]}isReferenceOnly(){let e=this.block;if(e)return e.isReferenceOnly();let t=this._emitterTokens(),n=0;for(let e=0;e<t.length;e++){let r=t[e];if(typeof r!=`string`){n++;continue}let i=r.trim();if(i!==``&&i!==`:`)return!1}return n>0}getError(){return this.block?.getError()??null}getReferencesAt(e,t){return this.block?.getReferencesAt(e,t)??[]}_pieceAt(t){let r=n.CoordUtils.sanitizeRange(t),i=this.getTextAt(r.rowStart,r.colStart);return new e(i,r,this.block)}getSplit(e,t,n){return[this._pieceAt(e[0]),this._pieceAt(e[1])]}getMerged(t,r,i){if(this.relativeForm()!==t.relativeForm())return;let a=n.CoordUtils.sanitizeRange(r),o=a.rowStart===this.ref.rowStart&&a.colStart===this.ref.colStart?this:t,s=new e(o.a1,a,o.block);return s._r1c1=o._r1c1,s._tokens=o._tokens,s}getShifted(t){let r=t.after;if(!r)return null;let i=n.CoordUtils.sanitizeRange(r);return{...r,value:new e(this.a1,i,null)}}copyTo(t,r){let i=n.CoordUtils.sanitizeRange(t),a;if(r?.cutFrom)a=new e(this.a1,i,null);else if(this.block)a=new e(this.block.getTextAt(i.rowStart,i.colStart),i,null);else{let t={oob:!1};a=new e(this._emitTextAt(i.rowStart,i.colStart,t),i,null),t.oob||(a._r1c1=this.relativeForm(),a._tokens=this._tokens)}return{colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:a}}canTile(e,t){return!0}get[Symbol.toStringTag](){return`[FormulaEntry]`}toString(){return`${fd(this.ref)}: ${this.a1}${this.block?``:` (pending)`}`}},nM=class extends tM{constructor(e,t,n){super(e,t,null),this._made=null,this._isResolved=!1,this._resolve=n}_view(){if(this._isResolved)return this._made;let e=this._resolve();return e===void 0?null:(this._isResolved=!0,this._made=e)}isCompiled(){return this._view()?.isCompiled()??!1}getTextAt(e,t,n,r,i){let a=this._view();return a?a.getTextAt(e,t,n,r,i):super.getTextAt(e,t,n,r,i)}getTokensAt(e,t,n){return this._view()?.getTokensAt(e,t,n)??[]}isReferenceOnly(){let e=this._view();return e?e.isReferenceOnly():super.isReferenceOnly()}getError(){return this._view()?.getError()??null}},rM=class{get _block(){return this._blockOwn}constructor(e,t,n,r){this._coords=e,this._blockOwn=t,this._options=n,this._isCompiled=r??null}isCompiled(){return!this._isCompiled||this._isCompiled()}getTokens(e){let t=this._coords??n.CoordUtils.EmptyCell;return this._block.getTokensAt(t.rowIndex,t.colIndex,e)}isValid(){return!this._block.getError()}autoCorrect(){if(this.isValid())return null;let e=this.getExpression({target:this._options.inputTarget??`storage`});return this._options.autoCorrect?.(e,this._coords??void 0)??null}evaluate(e){let t=this._coords??n.CoordUtils.EmptyCell,r=this._options.getCalcGrid?.();if(!r)return Promise.resolve(null);if(!this.isCompiled()){let e=this._options.getCalculationStatus?.();if(e===X.Status.Off||e===X.Status.Error||e===X.Status.Stopping)return Promise.reject(Error(`The formula is not compiled and the calculation engine is not running.`))}return r.evaluateAt(t.rowIndex,t.colIndex,e)}getCalculationStatus(){return this.isCompiled()?X.ResultStatus.Ready:X.ResultStatus.Pending}getReferences(){return this._resolveReferences(this._referencesAt()??void 0)}hasRefError(){return aM(this._referencesAt())}_referencesAt(){let e=this._coords;return e?this._block.getReferencesAt(e.rowIndex,e.colIndex):null}_resolveReferences(e){if(!e?.length)return null;let n=this._options.resolveSheetScope,r=[];for(let i of e)if(i&&!t.FormulaError.isError(i))if(`nameId`in i)r.push(i.nameId);else{let e=i;if(e.scope&&n){let t=n(e.scope);t&&(e={...e,scope:t})}else if(!e.scope){let t=this._options.getOwnScope?.();t&&(e={...e,scope:t})}r.push(e)}else r.push(null);if(!r.some(e=>e!==null))return null;try{return this._options.getRanges(r)}catch{let e=r.map(e=>{if(e===null)return null;try{return this._options.getRanges([e]),e}catch{return null}});return e.some(e=>e!==null)?this._options.getRanges(e):null}}async setReferenceAt(e,t,r){let i=this._coords,a=this._options,o=a.getCalcGrid?.();if(!i||!o)return this;this._checkCompiled();let s=a.getRange(t),c=s?.isINamedRange?{nameId:s.getId()}:s.getCoords()??null;if(typeof t==`string`&&!t.includes(`:`)&&c?.colStart!==void 0){let e=c,t={colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart??!1,$rowIndex:e.$rowStart??!1};e.scope&&(t.scope=e.scope),c=t}let l=(0,n.t)(`op.updateFormulaAt`,{address:a.getRange(i).getAddress()});r&&typeof r!=`string`&&!r.description&&((r={...r}).description=l);let u=null;return await a.doBatchCalcGrid(async t=>(u=await t.setReferenceAt(i.rowIndex,i.colIndex,e,c),n.CoordUtils.cellToRange(i)),r??l),this._rewritten(u,i)}_rewritten(e,t){return e?this._options.getRange(t).getCell().getFormula()??this:this}async setReferenceModeAt(e,t=`self`,r,i){let a=this._coords??n.CoordUtils.EmptyCell,o=this._options;this._checkCompiled();let s=o.getRange(a),c=s?(0,n.t)(`op.updateReferenceStyleAt`,{address:s.getAddress()}):(0,n.messageKey)(`op.updateReferenceStyle`);i&&typeof i!=`string`&&!i.description&&((i={...i}).description=c);let l=null;return await o.doBatchCalcGrid(async i=>(l=await i.setReferenceModeAt(a.rowIndex,a.colIndex,e,t,r),n.CoordUtils.cellToRange(a)),i??c),this._rewritten(l,a)}_checkCompiled(){if(!this.isCompiled())throw Error(`The formula is not compiled yet; its references cannot be edited.`)}isReferenceOnly(){return this._block.isReferenceOnly()}isVolatile(){let e=this._coords;return e?this._options.getCalcGrid?.()?.isVolatileAt(e.rowIndex,e.colIndex)??Promise.resolve(!1):Promise.resolve(!1)}getExpression(e){let t=e?.cell??this._coords??n.CoordUtils.EmptyCell,r=e?.r1c1??!1,i=e?.target;return this._block.getTextAt(t.rowIndex,t.colIndex,r,e?.evalIndex,i)}getAnchor(){return this._coords}shift(e){let t=this.getExpression({cell:e,target:this._options.inputTarget??`storage`});return this._options.createAt?.(t,e)??null}get[Symbol.toStringTag](){return`[Formula]`}toString(){return this.getExpression()}get isIFormula(){return!0}},iM=class e extends rM{get _block(){return super._block}constructor(e,t,n,r){super(e,t,n),this._doEval=r}evaluate(e){let t=this._block;return this._doEval(t,e)}hasRefError(){let e=this._coords??n.CoordUtils.EmptyCell;return aM(this._block.getReferences(e.rowIndex,e.colIndex))}async setReferenceAt(t,n){let r=this._coords;if(!r)return this;let i=this._options.getRange(n),a=i?.isINamedRange?{nameId:i.getId()}:i.getCoords()??null,o=typeof n==`string`?n.includes(`!`):n?.colStart===void 0||!!n.scope;a?.scope&&!o&&(a={...a,scope:void 0});let s=a?.colStart===void 0?a:Vd(a,r.rowIndex,r.colIndex);if(typeof n==`string`&&!n.includes(`:`)&&s?.colStart!==void 0){let e=s,t={colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart??!1,$rowIndex:e.$rowStart??!1};e.scope&&(t.scope=e.scope),s=t}return new e(r,this._block.setReferenceAt(t,s),this._options,this._doEval)}async setReferenceModeAt(e,t=`self`,n,r){let i=this._coords;if(!i)return this;let a=this._block.getReferences(i.rowIndex,i.colIndex)?.[e];if(!a||`nameId`in a||a.colStart===void 0)return this;let o=a;if(o.scope&&this._options.resolveSheetScope){let e=this._options.resolveSheetScope(o.scope);e&&(a={...o,scope:e})}let s=Bd(a,i.rowIndex,i.colIndex);return this.setReferenceAt(e,oM(s,t,n))}};function aM(e){if(!e?.length)return!1;for(let n=0;n<e.length;n++){let r=e[n];if(!r||t.FormulaError.isError(r))return!0}return!1}var oM=(e,t=`self`,n)=>{let r=t===`right`,i=n;if(i===void 0){let t=r?e.$colEnd:e.$colStart,n=r?e.$rowEnd:e.$rowStart;i=t&&n?0:n&&!t?1:t&&!n?2:3}let a=i+1;(a>3||a<0)&&(a=0);let o=a===0||a===1,s=a===0||a===2,c={...e};return t===`self`?(c.$rowStart=o,c.$colStart=s,c.$rowEnd=o,c.$colEnd=s):t===`right`?(c.$rowEnd=o,c.$colEnd=s):(c.$rowStart=o,c.$colStart=s),c},sM=class{constructor(e,t){this._error=void 0,this.record=e,this._imager=t}getTextAt(e,t,n=!1,r,i){let a=this.record,o=this._imager,s=a.error;if(s?.unparsed)return s.input;let c=i===`display`,l=r===void 0?a.tokens:cM(a.tokens,r);l=DT(l,o.symbols,!c,c,c?{scope:o.gridId,rowIndex:e,colIndex:t}:null);let u=c?o.getDisplayLocale():Ux;return n?AT(l,o.getEntireCoords(),u):jT(l,o.getEntireCoords(),e,t,u)}getTokensAt(e,t,n){let r=this.record,i=n===void 0?r.tokens:cM(r.tokens,n);return i=DT(i,this._imager.symbols,!1,!0),NT(i,e,t)}isReferenceOnly(){return this.record.isReferenceOnly}getError(){let e=this._error;if(e===void 0){let n=this.record.error;e=this._error=n?new t.FormulaError.Parse(n.message,n.details):null}return e}getReferencesAt(e,n){let r=this.record.references;if(!r?.length)return[];let i=this._imager,a=Array(r.length);for(let n=0;n<r.length;n++){let o=r[n];if(o)if(`nameId`in o){let e=o.nameId;a[n]={nameId:i.symbols.resolve($.NamedFormula,e)?.toString()??e}}else if(`table`in o){let r=i.resolveTableReference?.(o.table,e)??null;a[n]=!r||t.FormulaError.isError(r)?null:{...r,tableId:o.table.tableId}}else a[n]={...o};else a[n]=null}return ET(a,e,n)}get[Symbol.toStringTag](){return`[FormulaRecordView]`}};function cM(e,t){let n=-1,r=-1,i=e.length;for(let a=0;a<i;a++){let i=e[a];i.evalIndex===t&&i.type!==Z.Whitespace&&(n<0&&(n=a),r=a)}if(n<0)return[];let a=e=>e.evalIndex!==void 0&&e.evalIndex>=t;for(;n>0&&a(e[n-1]);)n--;for(;r<i-1&&a(e[r+1]);)r++;return e[n].type===Z.Whitespace&&n<r&&n++,e[r].type===Z.Whitespace&&r>n&&r--,e.slice(n,r+1)}var lM=class{constructor(e,t,n,r,i,a,o,s){this.params=e,this.body=t,this.owner=n,this.compiled=r,this.regs=i,this.frame=a,this.anchorRow=o,this.anchorCol=s,this.isLambda=!0,this.active=0}makeCallable(){let e=this.params,t=e.length;for(;t>0&&e[t-1].optional;)t--;let n=(...e)=>this.owner._applyValues(this,e);return n.isLambdaCallable=!0,n.checkArity=n=>n>=t&&n<=e.length,n.paramCount=e.length,n}get[Symbol.toStringTag](){return`[LambdaValue(${this.params.map(e=>e.name).join(`,`)})]`}},uM=class{constructor(e){this.fn=e,this.isLambda=!0}makeCallable(){let e=this.fn,n=(...n)=>{try{return e.execute(...n)}catch(e){if(HT(e))throw e;return t.FormulaError.isError(e)?e:new t.FormulaError.Value(e?.message,{cause:e})}};return n.isLambdaCallable=!0,n.checkArity=()=>!0,n.paramCount=-1,n}get[Symbol.toStringTag](){return`[FunctionValue(${this.fn.getName?.()??``})]`}},dM=Symbol(`sheetxl.lambda.omitted`),fM=class e{constructor(e,t,n,r,i,a){this._gridId=null,this._resolvers=null,this._precedentTemplate=void 0,this._record=null,this._formatReferences=null,this._compiled=e,this._context=t,this._calcScope=n,this._gridId=r,this._getEntireCoords=i,this._resolvers=a??null}getTextAt(e,t,n=!1,r,i){let a=i===`display`,o=this._compiled;if(o.error&&!o.ast)return o.error.input;let s=r===void 0?o.getTokens():gw(o.ast,r);s=DT(s,o.symbols,!a,a,a?{scope:this._gridId,rowIndex:e,colIndex:t}:null);let c=a?this._displayLocale():Ux;return n?AT(s,this._getEntireCoords?.(),c):jT(s,this._getEntireCoords?.(),e,t,c)}_displayLocale(){return Wx(Bx(this._context.getRuntime().getLocaleProfile().decimal))}getRecord(){let e=this._record;if(e)return e;let n=this._compiled,r=n.error,i;if(r){let e=r.cause;i={input:r.input,message:String(e?.message??``),unparsed:!n.ast,details:e instanceof t.FormulaError.Parse?e.getDetails():void 0}}let a={tokens:n.getTokens(),isReferenceOnly:n.isReferenceOnly};i&&(a.error=i);let o=this._recordReferences();return o&&(a.references=o),this._record=a}_recordReferences(){let e=this._compiled,t=e.referenceIndices,n=t.length;if(n===0)return null;let r=e.referencesExecute,i=e.referencesRelative,a=Array(n);for(let e=0;e<n;e++){let n=r[t[e]],o=n.inputs,s=null;if(o&&o.length===2){let e=i[r[o[0]].value],t=i[r[o[1]].value];s={colStart:e.colStart,rowStart:e.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,$colStart:e.$colStart,$rowStart:e.$rowStart,$colEnd:t.$colEnd,$rowEnd:t.$rowEnd,scope:e.scope}}else n.node.type===Z.Cell?s={...i[n.value]}:n.op===Z.Named?s={nameId:n.node.value.nameId}:n.op===Z.TableReference&&(s={table:{...n.node.value}});a[e]=s}return a}getNode(){let e=this._compiled;return e.ast?BC(e.ast,e.symbols):null}getTokensAt(e,t,n){let r=this._compiled,i=n===void 0?r.getTokens():gw(r.ast,n);return i=DT(i,r.symbols,!1,!0),NT(i,e,t)}getError(){return this._compiled.error??null}getNamedIds(){return this._compiled?.namedIds??n.CommonUtils.EmptyArray}getReferencedSymbolIds(){return this._compiled?.symbolIds??n.CommonUtils.EmptyArray}hasTotals(){return this._compiled?.hasTotals??!1}isBlankCacheable(e=!1){let t=this._compiled;return!!t&&(e?t.isBlankCacheableArray:t.isBlankCacheable)}demandFirstCell(){let e=this._compiled;e?.ast&&function(e,t){if(e.firstCell!==void 0)return;let n=(e,r)=>{if(!e)return;e.firstCell=r;let i=e.inputs;if(!i)return;let a=e.type;if(a===Z.Infix||a===Z.Prefix||a===Z.Postfix){let t=r&&!e.isReference;for(let e=0;e<i.length;e++)n(i[e],t);return}if(a===Z.Paren||a===Z.List){let e=r&&i.length===1;for(let t=0;t<i.length;t++)n(i[t],e);return}if(a===Z.Function){let a=e.binder;if(a!==void 0){let e=i.length-1;for(let t=0;t<i.length;t++)n(i[t],r&&a.kind===`let`&&t===e);return}let o=r?t?.(e.value)?.getDeclaration().getParameters():null;for(let e=0;e<i.length;e++){let t=o?Pw(o,e):null;n(i[e],t!==null&&(Fw(t)||Bw(t)))}return}for(let e=0;e<i.length;e++)n(i[e],!1)};n(e,!0)}(e.ast,e.getFunction)}isReferenceOnly(){return this._compiled.isReferenceOnly}isEquals(t){if(!(t&&t instanceof e))return!1;if(this===t)return!0;let n=this._compiled.getTokens(),r=t._compiled.getTokens();if(n.length!==r.length)return!1;let i=this._context.getEntireCoords();return AT(n,i)===AT(r,i)}getReferences(e,r){let i=this._compiled,a=i.referenceIndices,o=a.length;if(o===0)return n.CommonUtils.EmptyArray;let s=i.referencesExecute,c=i.referencesRelative,l=rU(o);for(let n=0;n<o;n++){let i=s[a[n]],o=i.inputs;if(o&&o.length===2){let e=c[s[o[0]].value],t=c[s[o[1]].value];l[n]={colStart:e.colStart,rowStart:e.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,$colStart:e.$colStart,$rowStart:e.$rowStart,$colEnd:t.$colEnd,$rowEnd:t.$rowEnd,scope:e.scope}}else if(i.node.type===Z.Cell)l[n]={...c[i.value]};else if(i.op===Z.Named){let e=i.node.value.nameId;l[n]={nameId:this._compiled.symbols?.resolve($.NamedFormula,e)?.toString()??e}}else if(i.op===Z.TableReference){let a=i.node.value,o=this._resolveStructuredRef(a,e,r);!o||t.FormulaError.isError(o)?l[n]=null:l[n]={...o,tableId:a.tableId}}else i.op===Z.Error&&(l[n]=null)}return l}getReferencesAt(e,t){let r=this.getReferences(e,t);return r.length===0?n.CommonUtils.EmptyArray:ET(r,e,t)}getFormatReferences(){let e=this._formatReferences;if(e)return e;let t,r=this._compiled.formatReferenceIndices,i=r.length;if(i===0)t=n.CommonUtils.EmptyArray;else{let e=this.getReferences(0,0);t=[];for(let n=0;n<i;n++){let i=e[r[n]];i&&i.colStart!==void 0&&t.push(i)}t.length===0&&(t=n.CommonUtils.EmptyArray)}return this._formatReferences=t,t}getReferenceAt(e,t,n){let r=this.getReferences(e,t);return n>=0&&n<r.length?r[n]:null}setReferenceAt(r,i,a){let o=this._compiled,s=o.referenceIndices;if(s.length===0)return null;let c=o.referencesExecute;r<0&&(r=s.length+r);let l=s[r];if(l===void 0)throw Error(`Invalid reference index: ${r}`);let u=c[l],d=u.node,f=d.inputs??n.CommonUtils.EmptyArray,p=u.op===Z.Named,m,h,g=!1;i&&t.FormulaError.isError(i)&&(i=null),i&&`nameId`in i&&!p&&(i=null);let _=i&&`nameId`in i?null:i,v=!!_&&_.colIndex!==void 0;if(_)if(v){let e=_;m={colIndex:e.colIndex,rowIndex:e.rowIndex,$colIndex:e.$colIndex??!1,$rowIndex:e.$rowIndex??!1},e.scope&&(m.scope=e.scope),g=!1}else{let e=_;m={colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart??!1,$rowIndex:e.$rowStart??!1},e.scope&&(m.scope=e.scope),g=!n.CoordUtils.isSingleCell(e),g&&(h={colIndex:e.colEnd,rowIndex:e.rowEnd,$colIndex:e.$colEnd??!1,$rowIndex:e.$rowEnd??!1},e.colEnd===2**53-1&&(h.colIndex=-(2**53-1)),e.rowEnd===2**53-1&&(h.rowIndex=-(2**53-1)))}let y=f.length===2,b=v&&y,x=-1,S=-1,C=-1,w=-1;if(y)x=f[0].evalIndex,S=f[1].evalIndex;else if(d.type===`cell`)x=d.evalIndex;else if(u.op===Z.TableReference)C=d.evalIndex;else{if(!p)throw Error(`Invalidate reference index: ${r}`);w=d.evalIndex}let T=(...e)=>{if(a?.scopeDeleted)return null;let t=this._compiled.symbols;for(let n=0;n<e.length;n++){let r=e[n]?.value?.scope;if(r)return t&&!t.resolve($.Sheet,r)?null:r}return null},E=d,D=this._compiled.ast,O=AS(D,e=>{if(!e||!e.isReference)return;if(b&&e===E){let e=aS(m);return m.scope&&(e.value.scope=m.scope),e}let t=e.type;if(w!==-1&&e.evalIndex===w&&t===Z.Named){if(!i)return wS();if(i&&`nameId`in i){let t=i,n=this._compiled.symbols?.bind($.NamedFormula,t.nameId)??t.nameId,r={...e};return r.value={...e.value,...t,nameId:n},r}return g?hS(`:`,aS(m),aS(h),!0):aS(m)}if(C!==-1&&e.evalIndex===C&&t===Z.TableReference)return i?g?hS(`:`,aS(m),aS(h),!0):aS(m):wS();if(!i&&Uw.includes(e.value)){let t=e.inputs??n.CommonUtils.EmptyArray,r=t[0],i=t[1],a=r.evalIndex===x,o=i.evalIndex===S;if(a||o){let t=wS(void 0,void 0,T(r,i));return t.evalIndex=e.evalIndex,t}}if(t!==`cell`&&t!==`error`)return;let r=e.evalIndex,a,o=r===x;if((o||r===S)&&!b){if(i)if(y===g){let t=o?m:h;a={...e},a.value=t,a.image=null}else a=g?hS(`:`,aS(m),aS(h),!0):aS(m);else a=wS(void 0,void 0,T(e)),a.evalIndex=e.evalIndex;return a}});if(O===D)return this;let k=Vw(o.runtime,o.symbols,O,!1,o.error,o.getFunction);return new e(k,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}reanchorReferences(t,n){let r=this._compiled,i=this._gridId,a=this._compiled.symbols.bind($.Sheet,t),o=r.transform((e,t)=>{if(!e||!e.isReference||e.type!==Z.Cell||Yw(t)&&t.inputs?.[0]!==e)return;let r,o=e.value.scope;return(!o||n&&o===i)&&(r={...e},r.value={...r.value},r.value.scope=a),r});return r===o&&a===i?this:new e(o,this._context,this._calcScope,i,this._getEntireCoords,this._resolvers)}replaceScopeIds(t,n){if(t===n)return this;let r=this._compiled,i=r.transform((e,r)=>{if(!e||!e.isReference||e.type!==Z.Cell||Yw(r)&&r.inputs?.[0]!==e||e.value.scope!==t)return;let i={...e};return i.value={...i.value},i.value.scope=n,i});return r===i?this:new e(i,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}replaceTableReferences(t,n){let r=this._compiled,i=r.transform(e=>{if(e?.type!==Z.TableReference)return;let r=e.value;if(typeof r!=`object`||r?.tableId!==t)return;let i=n(r);return i?(i.evalIndex=e.evalIndex,i):void 0});return r===i?this:new e(i,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}_evaluateNamed(e,n,r){let i=e.nameId,a=this._calcScope;if(a.activeNames.has(i))return t.FormulaError.BuiltIn.Ref;let o=this._resolvers?.getNamedFormulaBlock?.(i);if(!o){let e=this._compiled,n=e.symbols?.resolve($.NamedFormula,i),r=n?n.toString():i,a=e.getFunction?.(r)??null;return a?new uM(a):t.FormulaError.BuiltIn.Name}let s=a.gridId,c=a.rowIndex,l=a.colIndex;a.activeNames.add(i),a.depth++;try{return o.evaluateAt(n,r)}finally{a.depth--,a.activeNames.delete(i),a.gridId=s,a.rowIndex=c,a.colIndex=l}}_resolveNamedPrecedents(e,r,i){let a=e.nameId,o=this._calcScope;if(o.activeNames.has(a))return n.CommonUtils.EmptyArray;let s=this._resolvers?.getNamedFormulaBlock?.(a);if(!s)return t.FormulaError.BuiltIn.Name;o.activeNames.add(a);try{return s.resolvedPrecedentsAt(r,i)}finally{o.activeNames.delete(a)}}_resolveStructuredRef(e,n,r,i){let a=this._resolvers?.getStructureReferenceCoords;return a?a(e,n,r,this._gridId):t.FormulaError.BuiltIn.Name}resolvedPrecedentsAt(e,r,i=!1,a,o){let s=this._compiled,c=s.referencesRoot,l=c.length;if(l===0)return n.CommonUtils.EmptyArray;let u=s.referencesRelative,d=s.referencesAbsolute,f=u.length;for(let t=0;t<f;t++)mM(u[t],e,r,d[t]);let p=s.referencesExecute,m=p.length,h=[];for(let n=0;n<m;n++){let i=p[n],a=i.op;if(!a){let e=d[i.value];h[i.index]=e;continue}if(a===Z.Named){h[i.index]=this._resolveNamedPrecedents(i.node.value,e,r);continue}if(a===Z.Error){h[i.index]=TS(i.node.value);continue}if(a===Z.TableReference){let n=i.node.value,a;n&&(a=this._resolveStructuredRef(n,e,r)),a||=t.FormulaError.BuiltIn.Ref,h[i.index]=a;continue}if(a===`@`||a===`#`){let e=h[i.inputs[0]];h[i.index]=e===void 0?t.FormulaError.BuiltIn.Value:e;continue}let o=i.inputs;if(!o)continue;let s=h[o[0]];if(s===void 0){h[i.index]=t.FormulaError.BuiltIn.Value;continue}if(t.FormulaError.isError(s)){h[i.index]=s;continue}let c,l=h[o[1]];if(l!==void 0)if(t.FormulaError.isError(l))h[i.index]=l;else{if(a===` `)c=nf(s,l);else if(a===`:`||a===`.:.`||a===`:.`||a===`.:`)c=rf(s,l);else if(a===`,`){let e=o.length;for(let n=0;n<e;n++){let e=h[o[n]];e===void 0||Array.isArray(e)||t.FormulaError.isError(e)||(c=c?rf(c,e):e)}}h[i.index]=c??t.FormulaError.BuiltIn.Null}else h[i.index]=t.FormulaError.BuiltIn.Value}let g=[],_=0;for(let e=0;e<l;e++)_=hM(c[e],p,h,g,_,a,o);return g}getPrecedentTemplate(){let e=this._precedentTemplate;if(e!==void 0)return e;e=null;let t=this._compiled,n=t.referencesRoot,r=t.referencesExecute,i=t.referencesRelative,a=n.length,o=Array(a),s=Array(a),c=Array(a),l=Array(a),u=!0;for(let e=0;e<a&&u;e++){let t=r[n[e]];if(t===void 0){u=!1;break}let a=t.op,d,f=null;if(a){if(a===Z.Error)d=TS(t.node.value);else if(a===`:`||a===`.:.`||a===`:.`||a===`.:`){let e=t.inputs;if(e&&e.length===2){let t=r[e[0]],n=r[e[1]];t===void 0||t.op||n===void 0||n.op||(d=i[t.value],f=i[n.value]??null,f===null&&(d=void 0))}}}else d=i[t.value];if(d===void 0){u=!1;break}o[e]=d,s[e]=f,c[e]=!!t.hasVerticalAbs,l[e]=!!t.hasHorizontalAbs}return u&&(e={relative:o,second:s,verticalAbs:c,horizontalAbs:l}),this._precedentTemplate=e,e}evaluateAt(e,n,r){let i=this._calcScope;i.rowIndex=e,i.colIndex=n,i.gridId=this._gridId;let a=this._context,o=this._compiled;if(r!==void 0){let t;if(AS(o.ast,e=>{e.evalIndex===r&&(t=e)}),!t)throw Error(`Invalid evalIndex: ${r}`);if(o.bindings.length>0&&!o.error){let i=this.evaluateAt(e,n),a=o.evaluations,s=()=>a[r]??(!0===t.inLazy?this._valueOfLazy(t,a,null,e,n):void 0);return i&&typeof i.then==`function`?i.then(()=>s()):s()}o=Vw(a.getRuntime(),o.symbols,vM(t),!1)}if(o.error)return o.error.cause;o.hasVolatile&&i.node&&a.markVolatile();let s=o.evaluations,c=o.executions,l;o.bindings;let u=o.referencesExecute,d=o.referencesRelative,f=o.referencesAbsolute,p=u.length;for(let r=0;r<p;r++){let i=u[r],o=i.op,c=i.node;if(o)if(o===Z.Named)if(i.node.deferredResolve)s[i.node.evalIndex]=null;else{let t=i.node.value;s[i.node.evalIndex]=this._evaluateNamed(t,e,n)}else if(o===Z.Error)s[c.evalIndex]=TS(i.node.value);else if(o===Z.TableReference){let r=i.node.value,o;o=r?this._resolveStructuredRef(r,e,n):t.FormulaError.BuiltIn.Ref,t.FormulaError.isError(o)||o?.colStart===void 0?s[c.evalIndex]=o??t.FormulaError.BuiltIn.Ref:s[c.evalIndex]=a.getReference(o)}else o===`structured`&&(s[c.evalIndex]=null);else{let t=mM(d[i.value],e,n,f[i.value]);s[c.evalIndex]=t}}return l=this._runList(c,s,e,n,null),l?l.then(()=>s[o.ast.evalIndex]):s[o.ast.evalIndex]}wrapImplicit(t,n,r){let i=this._compiled,a=i.ast;if(!a||!a.isReference||a.type===`cell`||a.value===`@`||!r)return this;let o=id(n)+rd(t);if(r.has(o))return this;let s=_S(`@`,a,!0),c=Vw(i.runtime,i.symbols,s,!1,i.error,i.getFunction);return new e(c,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}_executeNode(e,n,r,i,a=null){let o=this._context,s=e.inputs,c=s?s.length:0,l=e.type,u;switch(l){case Z.Infix:{let r=e.value,i=n[s[0].evalIndex],a=n[s[1].evalIndex];if(!0===e.firstCell&&!e.isReference&&this._demandsFirstCell()&&(i=pM(i),a=pM(a)),typeof i==`number`&&typeof a==`number`){if(r===`+`)return tU(i+a,null);if(r===`-`)return tU(i-a,null)}if(!e.isReference){if(i&&t.FormulaError.isError(i))return i;if(a&&t.FormulaError.isError(a))return a}let c=e.fn??=lw[e.value];return u=c?c(o,i,a):t.FormulaError.BuiltIn.Value,u=tU(u,null),u}case Z.Function:{let l=e.binder;if(l!==void 0)return l.kind===`let`?n[s[c-1].evalIndex]:this._createLambdaValue(e,n,a,r,i);if(!0===e.hasLazyArgs){let t=UT.enter();try{this._fillLazyArgs(s,c,n,a,r,i,t),u=this._callFunction(e,_M,c),u instanceof UT&&(u=u._force())}finally{UT.leave(t)}}else{for(let e=0;e<c;e++)_M[e]=n[s[e].evalIndex];u=this._callFunction(e,_M,c)}return u&&typeof u.then==`function`&&u.then(t=>{t=tU(t,o),n[e.evalIndex]=t}).catch(r=>{let i=t.FormulaError.isError(r)?r:new t.FormulaError.Value(`Uncaught error`,{cause:r});n[e.evalIndex]=i}),u}case Z.Prefix:case Z.Postfix:{let r=n[s[0].evalIndex];if(!0===e.firstCell&&!e.isReference&&e.value!==`@`&&this._demandsFirstCell()&&(r=pM(r)),r&&t.FormulaError.isError(r))return r;let i=e.fn??=l===Z.Prefix?uw[e.value]:dw[e.value];return u=i?i(o,r):t.FormulaError.BuiltIn.Value,u}case Z.List:case Z.Paren:{if(c===1)return n[s[0].evalIndex];for(let e=0;e<c;e++){let r=n[s[e].evalIndex];if(typeof r==`object`&&r&&xC(r.scope))return t.FormulaError.BuiltIn.Name}let e=!1;for(let t=0;t<c;t++)if(JH(n[s[t].evalIndex])){e=!0;break}if(e){let e=[];for(let t=0;t<c;t++){let r=n[s[t].evalIndex];JH(r)?e.push(...r):e.push(r)}let t=rU(e.length);for(let n=0;n<e.length;n++)t[n]=e[n];return t}let r=rU(c);for(let e=0;e<c;e++)r[e]=n[s[e].evalIndex];return r}case Z.Named:{let o=e.binding;if(o!==void 0){let r=this._compiled.bindings[o.slot];if(r>=0){let t=n[r];return t===void 0?!0===e.rawFrameRead?dM:null:t}if(a!==null&&a.has(o.slot)){let t=a.get(o.slot);return!0===e.rawFrameRead?t:(d=t)===dM?null:d}return t.FormulaError.BuiltIn.Calc}return!0===e.deferredResolve?this._evaluateNamed(e.value,r,i):n[e.evalIndex]??null}case Z.TableReference:return n[e.evalIndex]??null;case Z.Call:{let r=n[s[0].evalIndex];return r&&t.FormulaError.isError(r)?r:(u=this._applyCallee(r,e,n),u&&typeof u.then==`function`&&u.then(t=>{n[e.evalIndex]=tU(t,o)}).catch(r=>{n[e.evalIndex]=t.FormulaError.isError(r)?r:new t.FormulaError.Value(`Uncaught error`,{cause:r})}),u)}case Z.Empty:return}var d}_fillLazyArgs(e,t,n,r,i,a,o){let s,c=!1;for(let r=0;r<t;r++){let t=e[r];if(!0===t?.lazyArg)continue;let i=n[t.evalIndex];!c&&(!0===i?.isIRange?i.size>1:JH(i))&&(c=!0)}if(c){s=[];for(let o=0;o<t;o++){let t=e[o];!0===t?.lazyArg&&(s[o]=this._evaluateSubtree(t,n,r,i,a))}}for(let c=0;c<t;c++){let t=e[c];_M[c]=!0===t?.lazyArg?s?s[c]:UT.deferred(o,c,this,t,n,r,i,a):n[t.evalIndex]}}_createLambdaValue(e,t,n,r,i){let a=e.inputs,o=[];for(let e=0;e<a.length-1;e++){let t=a[e];t?.binding?.declaration&&o.push({slot:t.binding.slot,name:t.value.nameId,optional:!0===t.binding.optional})}return new lM(o,a[a.length-1],this,this._compiled,t.slice(),n,r,i)}_applyCallee(e,n,r){if(e?.isIRange&&!e.isIReferenceRange&&e.size===1&&(e=e.getValueAt(0,0))&&t.FormulaError.isError(e))return e;let i=n.inputs,a=i.length-1;if(e instanceof lM){let n=e.params,o=n.length;for(;o>0&&n[o-1].optional;)o--;if(a>n.length||a<o)return t.FormulaError.BuiltIn.Value;let s=new Map(e.frame??void 0);for(let e=0;e<n.length;e++){let t=n[e],o=e>=a||i[e+1]?.type===Z.Empty;s.set(t.slot,o?dM:r[i[e+1].evalIndex])}return e.owner._evaluateBody(e,s)}if(e instanceof uM){let t=[];for(let e=1;e<i.length;e++)t.push(i[e]?.type===Z.Empty?void 0:r[i[e].evalIndex]);return this._dispatchFunction(e.fn,t,t.length)}return e&&(e.isIRange||e.colStart!==void 0)?t.FormulaError.BuiltIn.Ref:t.FormulaError.BuiltIn.Value}_applyValues(e,n){let r=e.params,i=r.length;for(;i>0&&r[i-1].optional;)i--;if(n.length>r.length||n.length<i)return t.FormulaError.BuiltIn.Value;let a=new Map(e.frame??void 0);for(let e=0;e<r.length;e++){let t=e<n.length?n[e]:void 0;a.set(r[e].slot,t===void 0?dM:t)}let o=this._evaluateBody(e,a);return o&&typeof o.then==`function`?o:tU(o,this._context)}_evaluateBody(e,n){let r=this._calcScope;if(r.depth>=512)return t.FormulaError.BuiltIn.Num;r.depth++;let i=e.active===0,a=i?e.regs:e.regs.slice();e.active++;let o=!1;try{let t=this._evaluateSubtree(e.body,a,n,e.anchorRow,e.anchorCol);if(i&&t&&typeof t.then==`function`){o=!0;let n=()=>{e.active--};t.then(n,n)}return t}finally{r.depth--,o||e.active--}}_valueOfLazy(e,t,n,r,i){let a=this._evaluateSubtree(e,t,n,r,i);return typeof a==`object`&&a&&a.colStart!==void 0&&!0!==a.isIRange?this._context.getReference(a):a}_evaluateSubtree(e,n,r,i,a){try{let t=e.deferred??this._listWithin(e),o=this._runList(t,n,i,a,r);return o?o.then(()=>n[e.evalIndex]):n[e.evalIndex]}catch(e){if(t.FormulaError.isError(e))return e;if(HT(e))throw e;return e instanceof RangeError?t.FormulaError.BuiltIn.Num:new t.FormulaError.Value(e?.message,{cause:e})}}_runList(e,t,n,r,i){let a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(a)a=a.then(()=>{let e=this._executeNode(o,t,n,r,i);return t[o.evalIndex]=e,e});else{let e=this._executeNode(o,t,n,r,i);t[o.evalIndex]=e,e&&typeof e.then==`function`&&(a=e)}}return a}_listWithin(e){let t;AS(this._compiled.ast,(n,r,i)=>{if(n===e){for(let e=i.length-1;e>=0;e--)if(i[e].deferred!==void 0){t=i[e];break}}});let n=new Set;AS(e,e=>{n.add(e)});let r=t?.deferred?.filter(e=>n.has(e))??[];return e.deferred=r,r}_demandsFirstCell(){let e=this._calcScope.node;return e!==null&&e.block.arrayFirstCell}_callFunction(e,n,r){let i=this._context,a=e?.cacheFn??i.getFunction(e.value);if(!a)return t.FormulaError.BuiltIn.Name;a.isBuiltIn()&&(e.cacheFn=a);let o=this._calcScope,s=o.implicitIntersect,c=o.firstCell;o.implicitIntersect=!0===e.implicitIntersect,o.firstCell=!0===e.firstCell&&o.node!==null&&o.node.block.arrayFirstCell;try{return this._dispatchFunction(a,n,r)}finally{o.implicitIntersect=s,o.firstCell=c}}_dispatchFunction(e,n,r){let i,a=e._cfp;if(a){a.argsValues=n,a.argsLength=r;try{i=e.execute()}catch(e){if(HT(e))throw e;i=yM(e)}a.argsValues=null,a.argsLength=0}else try{switch(r){case 0:i=e.execute();break;case 1:i=e.execute(n[0]);break;case 2:i=e.execute(n[0],n[1]);break;case 3:i=e.execute(n[0],n[1],n[2]);break;case 4:i=e.execute(n[0],n[1],n[2],n[3]);break;case 5:i=e.execute(n[0],n[1],n[2],n[3],n[4]);break;default:let t=[];for(let e=0;e<r;e++)t.push(n[e]);i=e.execute(...t)}}catch(e){if(HT(e))throw e;i=yM(e)}return i===void 0?new t.FormulaError.Parse:i}finalizeValue(e){let n=this._context;if(VC(e)||(0,t.isLazyValue)(e))return t.FormulaError.BuiltIn.Calc;if(e&&e.colStart!==void 0)try{if(e.scope){let r=n.getReference(e);if(t.FormulaError.isError(r))return r}e=n.getValueAt(e.rowStart,e.colStart,e.scope)}catch(e){if(HT(e))throw e;return t.FormulaError.isError(e)?e:new t.FormulaError.Value(e?.message,{cause:e})}if(Array.isArray(e)&&e.isSheetSpan)return t.FormulaError.BuiltIn.Ref;if(Array.isArray(e)){if(JH(e)){let t=rU(e.length);for(let n=0;n<e.length;n++)t[n]=this.finalizeValue(e[n]);return t}if(e.length===1&&Array.isArray(e[0])&&e[0].length===1)e=e[0][0];else try{e=n.getRange(e)}catch{e=t.FormulaError.BuiltIn.Value}}return e?.isIRange?e.size<=1?(e=tU(e=e.size===0?null:e.getValueAt(0,0,gM),n))===null&&(e=0):e=e.fillEmpty(0):(e=tU(e,n))===null&&(e=0),e}finalizeValueForCell(e){let n=this.finalizeValue(e);return Array.isArray(n)?t.FormulaError.BuiltIn.Value:n}toString(){let e=this._compiled;if(e.error)return e.error.toString();let t=this._calcScope;return t?.node?this.getTextAt(t.node.rowIndex,t.node.colIndex):AT(e.getTokens(),null)}get[Symbol.toStringTag](){return`[FormulaBlock]`}},pM=e=>typeof e==`object`&&e&&!0===e.isIRange?e.getValueAt(0,0)??null:e;function mM(e,t,n,r){let i=e.colStart,a=e.rowStart,o=e.colEnd,s=e.rowEnd,c=e.$colStart??!1,l=e.$rowStart??!1,u=e.$colEnd??!1,d=e.$rowEnd??!1;if(c||i===-(2**53-1)||(i+=n),l||a===-(2**53-1)||(a+=t),u||o===2**53-1||(o+=n),d||s===2**53-1||(s+=t),i>o){let e=i;i=o,o=e}if(a>s){let e=a;a=s,s=e}let f=r;return f.colStart=i,f.rowStart=a,f.colEnd=o,f.rowEnd=s,f.scope=e.scope??null,f}var hM=(e,n,r,i,a,o,s)=>{let c=n[e],l=c?.inputs;if(c?.op===`,`&&l){let e=l.length;for(let t=0;t<e;t++)a=hM(l[t],n,r,i,a,o,s);return a}let u=c===void 0?t.FormulaError.BuiltIn.Value:r[e]??t.FormulaError.BuiltIn.Value;if(Array.isArray(u)){let e=u.length;for(let t=0;t<e;t++){let e=u[t];i[a]=e?.rowStart===void 0?e:{...e},o&&(o[a]=!(!e?.$rowStart&&!e?.$rowEnd)),s&&(s[a]=!(!e?.$colStart&&!e?.$colEnd)),a++}return a}let d=!!c?.hasVerticalAbs,f=!!c?.hasHorizontalAbs;if(u?.rowStart!==void 0){let e={...u};d&&(e.$rowStart=e.$rowEnd=!0),f&&(e.$colStart=e.$colEnd=!0),i[a]=e}else i[a]=u;return o&&(o[a]=d),s&&(s[a]=f),a+1},gM=Object.freeze({type:null}),_M=Array(255),vM=e=>{let t={...e};return delete t.inLazy,delete t.lazyArg,delete t.hasLazyArgs,delete t.deferred,e.inputs&&(t.inputs=e.inputs.map(e=>e&&vM(e))),t},yM=e=>t.FormulaError.isError(e)?e:e instanceof RangeError?t.FormulaError.BuiltIn.Num:new t.FormulaError.Value(e?.message,{cause:e});function bM(e,t){let n=e.measureText(`M`);return{ascent:n.ascent??t.baseline,descent:n.descent??t.bounds.height-t.baseline}}var xM=Object.freeze({value:null,style:null,impliedStyle:void 0,hyperlink:null,comments:null,formula:null,type:t.ScalarType.Null,stringToParse:null}),SM=Object.seal({value:void 0,style:void 0,impliedStyle:void 0,hyperlink:void 0,comments:void 0,formula:void 0,type:void 0,stringToParse:void 0}),CM=Object.seal({value:void 0,style:void 0,hyperlink:void 0,comments:void 0,formula:void 0}),wM=Object.freeze({width:1,height:1});function TM(e,t,n){let r=e=>{let n=cd(e)??``;return e.scope&&e.scope!==t?`${ud(e.scope)}!${n}`:n};if(e.kind===`downstream`){let t=e.cycle.getRepresentative();return t?`Reads a circular reference at ${r(t)}`:`Reads a circular reference`}let i=e.cycle.getPath({rowIndex:n.rowIndex,colIndex:n.colIndex,scope:t});if(i.length===0)return`Circular reference${EM(e.cycle)}`;let a=i.slice(0,8).map(r),o=i.length-a.length;return`Circular reference: ${a.join(` → `)}${o>0?` → … (+${o} more)`:``} → ${a[0]}${EM(e.cycle)}`}function EM(e){if(!e.isIterative())return``;let t=e.getIterationCount(),n=`${t} iteration${t===1?``:`s`}`;if(e.isConverged())return` (converged after ${n})`;let r=e.getLastChange(),i=Number.isFinite(r)?`, last change ${Number(r.toPrecision(6))}`:``,a=e.getPreviousChange();return` (did not converge after ${n}${i}${Number.isFinite(r)&&Number.isFinite(a)&&r<a?` — still converging, raise max iterations`:``})`}var DM=new v_({max:1e3}),OM=e=>{if(Array.isArray(e))return`array`;let t=typeof e;if(t!==`object`)return t;if(e instanceof Date)return`Date (invalid)`;let n=e?.constructor?.name;return n&&n!==`Object`?n:`object`};function kM(e,r,i=null,a=null,o=!1,s=null){if(r===void 0)return;if(r===null)return xM;if(r&&r.isICell){let e=r,t=SM;return t.value=e.getValue(),t.style=e.getStyle().getAuthoredProperties()??null,t.impliedStyle=void 0,t.formula=(s?e.getExpressionText({cell:s}):e.getExpressionText())||void 0,t.stringToParse=void 0,t.hyperlink=e.getHyperlink(),t.comments=e.getComments()?.toJSON()??null,t.type=e.getType(),t}let c;r.value!==void 0||r.style!==void 0||r.hyperlink!==void 0||r.comments!==void 0?c=r:(c=CM,c.value=r.hasOwnProperty(`value`)?r.value:r,c.style=void 0,c.hyperlink=void 0,c.comments=void 0);let l=SM;l.type=void 0,l.value=void 0,l.style=void 0,l.impliedStyle=void 0,l.formula=void 0,l.hyperlink=void 0,l.comments=void 0,l.stringToParse=void 0;let u,d=c.value,f=!1;if(c.value!==void 0&&(u=IH(d),u||(f=Xc(d,!0),f&&(u=t.ScalarType.Number)),!u))throw new n.ExpectedError((0,n.t)(`error.sheet.invalidCellType`,{type:OM(d)}));let p,m,h=null,g=null,_;if(u===t.ScalarType.String){if(_=c.value,i){let t=a?.get(_),n=_.charAt(0);t||(n===`=`&&_.length>1?(m=_.substring(1),d=null):(t=lH(e,_,i),t!==void 0&&a&&a.set(_,t))),t&&typeof t.value==`string`&&(n===`+`||n===`-`)&&(e=>{for(let t=0;t<e.length;t++){let n=e.charAt(t);if(n!==`+`&&n!==`-`&&n!==` `&&n!==` `)return!0}return!1})(_)&&(m=_,d=null),t&&(t.value!==void 0&&(d=t.value,u=IH(d)),t.style!==void 0&&(h=t.style),t.hyperlink!==void 0&&(p=t.hyperlink)),!o&&i.parse&&(g=_)}}else f?(d=fl(c.value,e.isDate1904()),h=e=>{if(!Fl(e.getNumberFormat()))return{numberFormat:`Short Date`}}):d=c.value;let v=c.style;v&&v.isIStyle&&(v=v.getAuthoredProperties()??null),p=c.hyperlink??p,h&&(l.impliedStyle=h);let y=!1;d!==void 0&&(d===null?(l.value=null,l.type=t.ScalarType.Null):(l.value=d,l.type=u),y=!0),v!==void 0&&(l.style=v,y=!0),p!==void 0&&(l.hyperlink=p,y=!0);let b=c.comments;return b!==void 0&&(l.comments=b,y=!0),m!==void 0&&(l.formula=m,y=!0),o||(l.stringToParse=g,y=!0),y?(l.type=u,l):void 0}var AM=e=>e===c.HorizontalAlignment.Center||e===c.HorizontalAlignment.CenterContinuous?n.AnchorLocation.Center:e===c.HorizontalAlignment.Right?n.AnchorLocation.Right:n.AnchorLocation.Left,jM=(e,n,r)=>n===t.ScalarType.Null?null:Dg(n,e.getFont(),e.getAlignment(),!1,!0),MM=(e,n,r,i,a=!1)=>{if(e===t.ScalarType.Null)return null;let o=``;if(a)o=LD(r,e);else{let t=FD(i.runtime,r,n,e,n.getNumberFormatRef?.()??n.getNumberFormat(),e=>i.styles.parseColor(e));if(t.formattedRuns){let e=t.formattedRuns.runs,n=e.length;for(let t=0;t<n;t++)o+=e[t].text}else o=t.displayText}return Dg(o,n.getFont(),n.getAlignment(),e===t.ScalarType.String,a)},NM=Object.freeze({dataBar:null,iconSet:null}),PM=e=>e.isStopIfTrue()&&!e.getScale(),FM=(e,n)=>{let r=n.getInsets();if(e===t.ScalarType.Null)return r;let i=r,a=RM(e,n),o=n.getAlignment().getStacked()?0:n.getAlignment().getIndent();if(o&&(a===c.HorizontalAlignment.Left||a===c.HorizontalAlignment.Right)){i={...r};let e=n.measureText(` `.repeat(1*o)),t=Math.min(3,Math.max(1,(26-n.getFont().getSize())/2)),s=e.width*t;a===c.HorizontalAlignment.Left?i.left+=s:a===c.HorizontalAlignment.Right&&(i.right+=s)}return Object.freeze(i)};function IM(e,t,n,r,i){if(!e)return NM;let a=Array.isArray(e)?e:[e],o=null,s=null;for(let e=0;e<a.length;e++){let i=a[e],c=i.getDecorationAt(t,n,r);if(c&&(c.type===OA.ScaleType.DataBar?o??=c:s??=c),o&&s||PM(i)&&(c||i.getPropertiesAt(t,n,r)))break}if(s){let e=i().getAlignment();(e.getRotation()!==0||e.getStacked())&&(s=null)}return o||s?Object.freeze({dataBar:o,iconSet:s}):NM}var LM=e=>{let t=e.measureText(``);return(t.ascent??t.lineHeight)+(t.descent??0)+e.getInsets().left},RM=(e,n)=>{let r=n.getAlignment(),i=r.getHorizontal();if(r.getStacked())return i===c.HorizontalAlignment.General||i===c.HorizontalAlignment.Distributed?c.HorizontalAlignment.Center:i===c.HorizontalAlignment.Justify?c.HorizontalAlignment.Left:i;let a=ue(r.getRotation());return a!==0&&i===c.HorizontalAlignment.General?a>0&&a<90||a>180&&a<=270?c.HorizontalAlignment.Right:c.HorizontalAlignment.Left:i===c.HorizontalAlignment.General?e===t.ScalarType.Null?c.HorizontalAlignment.Left:e===t.ScalarType.Boolean||e===t.ScalarType.Error?c.HorizontalAlignment.Center:n.getNumberFormat()===`@`?c.HorizontalAlignment.Left:e===t.ScalarType.Number?c.HorizontalAlignment.Right:c.HorizontalAlignment.Left:i};function zM(e,r,i,a,o,s,l,u,d){if(i===t.ScalarType.Null||o===``)return null;let f=r;if(!function(e,r,i=!1,a=!1){if(e===t.ScalarType.Null)return!1;let o=r.getAlignment(),s=o.getHorizontal();if(s===c.HorizontalAlignment.CenterContinuous||s===c.HorizontalAlignment.Fill)return!0;if(s===c.HorizontalAlignment.Distributed||o.getStacked())return!1;if(de(o.getRotation())){let t=AM(RM(e,r));return!(t===n.AnchorLocation.Right&&i||t===n.AnchorLocation.Center&&i&&a||t===n.AnchorLocation.Left&&a)}if(e!==t.ScalarType.String||o.getOverflow()!==c.Overflow.Visible||s===c.HorizontalAlignment.Right&&i||s===c.HorizontalAlignment.Center&&i&&a||a&&(s===c.HorizontalAlignment.General||s===c.HorizontalAlignment.Left))return!1;let l=o.getVertical();return l!==c.VerticalAlignment.Justify&&l!==c.VerticalAlignment.Distributed}(i,a,s!==null&&s.colIndex+1===f,l!==null&&l.colIndex-1===f))return null;let p=a.getAlignment(),m=p.getHorizontal(),h=!de(p.getRotation())&&(p.getOverflow()===c.Overflow.Wrap||i===t.ScalarType.String&&(m===c.HorizontalAlignment.Justify||m===c.HorizontalAlignment.Distributed||p.getVertical()===c.VerticalAlignment.Justify||p.getVertical()===c.VerticalAlignment.Distributed)),g=m===c.HorizontalAlignment.Fill,_=m===c.HorizontalAlignment.CenterContinuous||g,v=g?null:KM(i,a,o,d,e);if(!v&&!_)return null;let y=AM(RM(i,a)),b=0,x=0,S=0,C=0,w=1;if(_&&o!==null&&u){QM.colIndex=r,QM.rowIndex=e;let t=u.colEnd;w=Math.min(d.nextContentful(QM,t),t)-r+1}let T=d.colHeaders,E=T.getOffset.bind(T),D=T.getIndex.bind(T),O=E(f),k=O,A=E(f+w),j=A-O,M=f,N=f,P={x:0,y:0,width:j,height:v?.height??0},F=f-f+w,I=v?v.width-j:0,L=P;return j>0&&I>0&&!h&&(y===n.AnchorLocation.Center&&(I/=2),y!==n.AnchorLocation.Left&&y!==n.AnchorLocation.Center||(N=D(A+I),l!==null&&(N=Math.min(N,l.colIndex-1)),A=E(N),C=I,x=N-f),y!==n.AnchorLocation.Right&&y!==n.AnchorLocation.Center||(M=D(O-I),s!==null&&(M=Math.max(M,s.colIndex+1)),O=E(M),S=I,b=f-M),P.x=k-O,L.x=P.x),w>1&&(x=y===n.AnchorLocation.Center?Math.max(F-1,x):w-1,A=E(f+1),P.width=A-O,L={...P},L.width=j),{anchorBounds:P,leftIndex:b,rightIndex:x,leftOffset:S,rightOffset:C,colSpan:F,colBounds:L}}var BM=class{constructor(e,t){this._styles=e,this._ri=t;let n=t?.table;n&&(this._table=n.getRangedStyle())}getCoords(){return n.CoordUtils.EmptyRange}_directAt(e,t,n){let r=this._ri,i=r.borderStyle?r.borderStyle.getPropertiesAt(e,t,n):null,a=r.fillStyle?r.fillStyle.getPropertiesAt(e,t,n):null,o=r.contentStyle?r.contentStyle.getPropertiesAt(e,t,n):null;return!i||a||o?i||!a||o?i||a||!o?i||a||o?{...o,...a,...i}:null:o:a:i}getPropertiesAt(e,t,r){let i=this._ri,a=this._styles,o=null,s=this._table?.getPropertiesAt(e,t,r);s&&(o=n.TypedObject.resolveTypedUpdates(s,Ch,a,o));let c=null,l=i.conditionals;l&&!Array.isArray(l)&&(l=[l]);let u=l?l.length:0;if(u>0){let i=null,o=null;for(let n=0;n<u;n++){let a=l[n],s=a.getPropertiesAt(e,t,r);if(s&&(o?(i??=[o]).push(s):o=s),s&&PM(a))break}if(i)for(let e=i.length-1;e>=0;e--)c=c?n.TypedObject.resolveTypedUpdates(i[e],Ch,a,c):i[e];else c=o}let d=this._directAt(e,t,r),f=null;if(d&&d.named){let n=d.named;if(n!==q.BuiltInName.Normal){let i=a.getNamedStyles().getByName(n);i?f=i.getRanged().getPropertiesAt(e,t,r):console.warn(`A named styled was referenced but not found: '${n}'.`)}}let p=null;f&&(p=n.TypedObject.resolveTypedUpdates(f,Ch,a,p)),d&&(p=p?n.TypedObject.resolveTypedUpdates(d,Ch,a,p):d);let m=null;if(o&&p){let e=a.normalize(p,q.BuiltInName.Normal),t=e?.font,r=t?.color;r==null||r!==G.Type.Auto&&!((e,t)=>{let n=e.getNormal().getFont().getColor();if(!n)return!1;try{let r=typeof t==`string`?e.parseColor(t):t;return!!r&&r.toCSS(`adaptive`)===e.parseColor(n).toCSS(`adaptive`)}catch{return!1}})(a,r)||(delete t.color,Object.keys(t).length===0&&delete e.font),m=e?n.TypedObject.resolveTypedUpdates(e,Ch,a,o):o}else m=p??o;return c&&(m=m?n.TypedObject.resolveTypedUpdates(c,Ch,a,m):c),m}cloneWithUpdate(e){let t=this._ri;return(tg.compose(t.borderStyle,t.fillStyle,t.contentStyle)??this._styles.getNormalRanged()).cloneWithUpdate(e)}getAuthoredPropertiesAt(e,t,n){return this._directAt(e,t,n)}};function VM(e,t,n,r,i,a){let o=r.styles,s=null;return n&&(s=i?tg.compose(n.borderStyle,n.fillStyle,n.contentStyle)??null:new BM(o,n)),Yg(e,o,s,t,r.styleUpdater,a)}function HM(e,t){if(!e)return!1;if(!Array.isArray(e)){let n=e.getCoords();return t.colIndex!==n.colStart||t.rowIndex!==n.rowStart}let n=e.length;for(let r=0;r<n;r++){let n=e[r].getCoords();if(t.colIndex===n.colStart&&t.rowIndex===n.rowStart)return!1}return!0}function UM(e,r,i,a,o,s,l,u=0,d=null,f=DM,p){let m=p?.formulaText,h=p?.formulaView??!1;if(i===null&&m===void 0)return r?r.getBestFit():null;let g=m===void 0&&e===t.ScalarType.String,_=r.getFont(),v=_.getWeight(),y=_.getSize(),b=_.getFamily(),x=r.getAlignment(),S=x.getOverflow(),C=x.getStacked(),w=C?0:x.getRotation(),T=x.getVertical(),E=r.getNumberFormat(),D=g&&S===c.Overflow.Visible,O=g&&(S===c.Overflow.Wrap||T===c.VerticalAlignment.Justify||T===c.VerticalAlignment.Distributed),k=FM(e,r),A=k.left+u+k.right+2,j=(d??``)+`\0`+y+b+v+E+w+C+D+O+s+l+A+(d?``:i)+`\0`+h+`\0`+(m??``)+`\0`+(O?o:``)+`\0`+n.DefaultLanguagePackService.getRevision(),M=f.get(j);if(M)return M;let N=null,P=null,F=k.top+k.bottom-2+function(e){let t=e.getFont().getUnderline()===B.UnderlineStyle.SingleAccounting,n=e.getFont().getUnderline()===B.UnderlineStyle.DoubleAccounting,r=0;return(t||n)&&(r=e.measureText(``).underlineThickness+1,n?r*=2:r+=1),r}(r),I=!1,L=!1,R=!1;l&&(R=!0,(w!==0||C||O)&&(R=!1));let ee=R?void 0:m===void 0?MM(e,r,i,a,h):jM(r,m);if(ee){if(!h&&e===t.ScalarType.Number&&E===`General`&&s){let e=i,t=n.CommonUtils.splitNumber(e),a=``;a=Math.abs(e)>=10**12||Math.abs(e)<=10**-12?`0.${`0`.repeat(Math.max(2,Math.min(t.ipLength,5)))}E+00`:Math.abs(t.ipLength)===0?`0.0`:Math.abs(t.fpLength)>0?`0`.repeat(t.ipLength)+`.0`:`0`.repeat(t.ipLength),e<0&&(a=`-`+a),a=`0`.repeat(a.length);let o=r.measureText(a);N=o.width,P=o.lineHeight}else if(m===void 0&&!h&&C){let e=ee.layout({width:1e9}),t=e.lines[0]?.bounds.height??e.bounds.height,n=ve(GM(ee),ee.wrapped,2**53-1);P=ye(n)*t+2,N=n.length*t+(n.length===1?-1:1),L=!0}else if(m===void 0&&!h&&de(w)){let e=ue(w)*Math.PI/180,t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e)),r=ee.layout({width:1e9}),i=r.lines[0]?.bounds.height??r.bounds.height;if(O){let e=Math.max(1,o-A),t=Math.max(1,Math.round(e/(1.5*i)));if(r.lines.length<t||t>1){let e=Math.max(1,r.bounds.width/t);for(let n=0;n<8;n++){let n=ee.layout({width:e});if(n.lines.length<=t){r=n;break}e*=1.25}let n=0;for(let e=0;e<r.lines.length;e++)n=Math.max(n,r.lines[e].bounds.width);let i=ee.layout({width:n});i.lines.length===r.lines.length&&(r=i)}}let a=r.lines,s=0,c=0;for(let e=0;e<a.length;e++){let r=a[e].bounds.width,i=a[e].bounds.height;s=Math.max(s,r*t+i*n),c=Math.max(c,r*n+i*t)}P=s,N=(a.length-1)*(t>0?i/t:0)+c,L=!0}else{let e=null;O&&(e={width:Math.max(1,o-A)});let t=ee.layout(e);if(P=t.bounds.height,O){let e=t.lines,n=e.length,r=0;for(let t=0;t<n;t++){let n=e[t].bounds.width;n>r&&(r=n)}N=r}else N=t.bounds.width}if(N!==null&&(N+=A),P!==null&&(P+=F),I=e===t.ScalarType.String&&!C,w&&(I&&S===c.Overflow.Wrap&&(I=!1),!L)){let e=function(e,t){let{x:n,y:r,width:i,height:a}=e,o=t*Math.PI/180,s=Math.sin(o),c=Math.cos(o),l=i/2,u=a/2,d=Qj(-l,-u,s,c),f=Qj(l,-u,s,c),p=Qj(-l,u,s,c),m=Qj(l,u,s,c),h=Math.min(d.x,f.x,p.x,m.x)+l,g=Math.max(d.x,f.x,p.x,m.x)+l,_=Math.min(d.y,f.y,p.y,m.y)+u;return{x:n+h,y:r+_,width:g-h,height:Math.max(d.y,f.y,p.y,m.y)+u-_}}({x:0,y:0,width:N,height:P},w);N=e.width,P=e.height}O&&N!==null&&(N=Math.ceil(N))}else P=r.getBestFit().height;s&&I&&(N=0);let te=Object.freeze({width:N,height:P});return f.set(j,te),te}var WM=(e,t,n,r)=>{let i=t.getAlignment(),a=i.getHorizontal();if(a===c.HorizontalAlignment.Fill||a===c.HorizontalAlignment.CenterContinuous||i.getStacked())return null;let o=i.getRotation();if(!de(o))return null;let s=FM(e,t),l={x:s.left,y:s.top,width:Math.max(0,r.width-s.left-s.right),height:Math.max(0,r.height-s.top-s.bottom)},u=n.layout({width:1e9}),d=u.lines[0]?.bounds.height??u.bounds.height,f=i.getVertical(),p=n.wrapped?n.layout({width:fe(l.height,d,o)}):u;return{layout:me(p.lines.map(e=>({width:e.bounds.width,height:e.bounds.height})),o,l,RM(e,t),f),frame:p,lineHeight:d,content:l}},GM=e=>{let t=``,n=e.paragraphs;for(let e=0;e<n.length;e++){let r=n[e].runs;for(let e=0;e<r.length;e++)t+=r[e].text}return t},KM=(e,t,n,r,i)=>{if(de(t.getAlignment().getRotation())){let a=r.sheet?.getRowHeaders().getSpanSize(i),o=a?MM(e,t,n,r,!1):null;if(o){let n=WM(e,t,o,{width:0,height:a});if(n)return{width:Math.ceil(n.layout.bounds.width),height:Math.ceil(n.layout.bounds.height)}}}let a=FM(e,t),o=RM(e,t),s=a.left+a.right;o===c.HorizontalAlignment.Left?s=a.right:o===c.HorizontalAlignment.Right?s=a.left:o===c.HorizontalAlignment.Center&&(s=a.left+a.right);let l=UM(e,t,n,r,2**53-1,!1,!1);return{width:Math.ceil(l.width-s),height:Math.ceil(l.height)}},qM={hideStringPrefix:!0},JM=class e{constructor(e,n,r=t.ScalarType.Null,i=null,a=null,o=null,s=null){this._options=e,this._r=e.runtime,this._coords=n??null,this._p=o,this._n=s,this._t=r,this._ri=a,this._v=i,this._dfmt=r===t.ScalarType.Number&&a?.dateFormat?a.dateFormat:null}_getDate(){let e=this._d;if(e!==void 0)return e;let t=this._dfmt;return e=t&&(Fl(t)||Il(t))?dl(this._v,this._r?.isDate1904()??!1)??null:null,this._d=e,e}getRange(){let e=this._coords,t=null,r=this._ri;return t=r&&r.merge?r.merge.getCoords():e?n.CoordUtils.cellToRange(e):null,this._options.getRange(t)}isEqual(e){if(!e)return!1;if(this===e)return!0;let t=e;return!!t.isICell&&this._v===t._v&&!!n.CoordUtils.isEqualCells(this._coords,e.getCoords())&&this._options.sheet===t._options?.sheet}getCoords(){return this._coords}getAddress(e){let t=this._coords;return t?hd(this._options.getRange(t).getCoords()):Qu}getSheet(){return this._options.sheet}select(e){return this._options.opener(`#`+cd(this._coords),e)}getColumn(){let e=this._column;if(e!==void 0)return e;this._column=null;let t=this._ri;if(!t)return null;let r=t.table??t.autoTable;if(!r)return null;let i=r.getHeaderRowRange().getCoords();if(i&&n.CoordUtils.isCellWithinRange(this._coords,i)){let t=this._coords.colIndex-i.colStart;e=r.getColumnAt(t)??null,this._column=e}return e}getTable(){let e=this._ri;return e&&(e.table??e.autoTable)||null}getDataValidation(){let e=this._ri;if(!e)return null;let t=e.dataValidations;return t?Array.isArray(t)?t[0]:t:null}getConditionalDecorations(){let e=this._cd;if(e!==void 0)return e;let t=this._coords;return this._cd=t?IM(this._ri?.conditionals,t.rowIndex,t.colIndex,this._v,()=>this.getStyle()):NM}getProtection(){return this.getStyle().getProtection()}getTextOverflow(){let e=this._to;if(e!==void 0)return e;let n=this._ri;if(n&&n.merge)return this._to=null,null;let r=this._t,i=null;if(r===t.ScalarType.String||n&&n.continuous){let e=this.getStyle(),t=this._coords;i=zM(t.rowIndex,t.colIndex,r,e,this._v,this._p,this._n,n?.continuous?.getCoords()??null,this._options)}return i===null||i.leftIndex===0&&i.rightIndex===0&&i.colSpan<=1?(this._to=null,null):(this._to=i,i)}getRenderHorizontalAlignment(){return RM(this._t,this.getStyle())}isEmpty(){return this._v===null&&!this._ri}getExtrusions(){let e=this._ri;if(!e&&this._to===null)return null;if(e){let t=e.merge;if(t!==void 0)return t.getCoords()}let t=this.getTextOverflow();if(!t)return null;let n=this._coords;return{colStart:n.colIndex-t.leftIndex,rowStart:n.rowIndex,colEnd:n.colIndex+t.rightIndex,rowEnd:n.rowIndex}}isEditAllowed(){let e=this._options;if(!e||!e.getProtection().isLocked()||this.getStyle().getProtection().isAlwaysUnlocked())return!0;let t=this._ri?.unlock;if(t===void 0)return!1;if(Array.isArray(t)){for(let e=0;e<t.length;e++)if(t[e].isUnlocked())return!0;return!1}return t.isUnlocked()}isFormulaHidden(){let e=this._options?.getProtection();return!!e&&!!e.isLocked()&&!e.isShowFormulasAllowed()&&!this.getStyle().getProtection().isShowFormulas()}isContentful(){return this._v!==null}getBestFit(e,t=!1){return e===void 0&&(e=this._options.sheet?.getColumnHeaders().getSpanSize(this._coords.colIndex)??64),UM(this._t,this.getStyle(),this._v,this._options,e,t,!1,this._iconGutter())}getInsets(){if(this._v===null)return this.getStyle().getInsets();let e=FM(this._t,this.getStyle()),t=this._iconGutter();return t===0?e:Object.freeze({...e,left:e.left+t})}_iconGutter(){return this.getConditionalDecorations().iconSet?LM(this.getStyle()):0}getTextFrame(e){let t,n;if(e&&(n=this.getFormulaText({target:`display`})),t=n??this._v,t===null)return null;let r=this.getStyle();return n?jM(r,t,this._options):MM(this._t,r,t,this._options,e)}getTextPlacement(e,t){let n=this.getTextFrame(t),r=n??this.getStyle().createTextFrame(` `);if(!r)return null;if(!t&&n){let t=((e,t,n,r)=>{let i=t.getAlignment();if(!i.getStacked())return null;let a=i.getHorizontal();if(a===c.HorizontalAlignment.Fill||a===c.HorizontalAlignment.CenterContinuous)return null;let o=FM(e,t),s={x:o.left,y:o.top,width:Math.max(0,r.width-o.left-o.right),height:Math.max(0,r.height-o.top-o.bottom)},l=n.layout({width:1e9}),u=l.lines[0]?.bounds.height??l.bounds.height,d=n.wrapped&&u>0?Math.max(1,Math.floor(s.height/u)):2**53-1;return{layout:xe(ve(GM(n),n.wrapped,d),u,s,RM(e,t),i.getVertical()),frame:l,lineHeight:u,content:s}})(this._t,this.getStyle(),n,e);if(t)return{content:Object.freeze(t.content),frame:t.frame,bounds:Object.freeze({...t.layout.bounds}),lineHeight:t.lineHeight,stacked:t.layout};let r=WM(this._t,this.getStyle(),n,e);if(r)return{content:Object.freeze(r.content),frame:r.frame,bounds:Object.freeze({...r.layout.bounds}),lineHeight:r.lineHeight,rotation:r.layout}}let i=this.getInsets(),a={x:i.left,y:i.top,width:Math.max(0,e.width-i.left-i.right),height:Math.max(0,e.height-i.top-i.bottom)},o=r.layout(r.wrapped?{width:a.width}:void 0),s=o.bounds,l=o.lines[0]?.bounds.height??s.height,u=o.lines,d=u[0],f=u[u.length-1],p=this.getStyle().getAlignment().getVertical(),m=a.y;if(d&&f){let{ascent:e,descent:t}=bM(this.getStyle(),d),n=d.bounds.y+d.baseline,r=f.bounds.y+f.baseline,i=a.y,o=a.y+a.height+1;if(p===c.VerticalAlignment.Bottom){let e=bM(this.getSheet().getStyles().getNormal(),d).descent;m=o-Math.max(t,e)-r}else if(p===c.VerticalAlignment.Top)m=i+1+e-n;else if(p===c.VerticalAlignment.Center){let a=r-n+e+t;m=i+Math.ceil((o-i-a)/2)+e-n}}let h=this.getRenderHorizontalAlignment(),g=a.x;return h===c.HorizontalAlignment.Center||h===c.HorizontalAlignment.CenterContinuous?g=a.x+(a.width-s.width)/2:h===c.HorizontalAlignment.Right&&(g=a.x+a.width-s.width),{content:Object.freeze(a),frame:o,bounds:Object.freeze({x:g,y:m,width:s.width,height:s.height}),lineHeight:l}}getFormula(){let e=this._ri?.formula;if(!e)return null;let t=this._coords;return t?new rM(t,e,this._options,()=>e.isCompiled()):null}getFormulaText(e){let t=this.getExpressionText(e);return t===null?null:`=`+t}getExpressionText(e){let t=this._ri?.formula;if(!t)return null;let n=e?.cell??this._coords;return n?t.getTextAt(n.rowIndex,n.colIndex,e?.r1c1,e?.evalIndex,e?.target):null}getCalculationStatus(){let e=this._ri;return e&&e.pending?X.ResultStatus.Pending:X.ResultStatus.Ready}_dependencyRanges(e,t){let r=this._coords;if(!r)return Promise.resolve(null);let i=this._options.dependencyRanges;return i?i(n.CoordUtils.cellToRange(r),e,t):Promise.resolve(null)}getDirectDependents(){return this._dependencyRanges(`dependents`,!0)}getDirectPrecedents(){return this._dependencyRanges(`precedents`,!0)}getDependents(){return this._dependencyRanges(`dependents`,!1)}getPrecedents(){return this._dependencyRanges(`precedents`,!1)}getValue(){return this._v}getType(){return this._t}getInteropValue(){return this._getDate()??this._v}getInteropType(){return this._getDate()?t.InteropScalarType.Date:this._t}getStyle(e=!1){if(!e&&this._s)return this._s;if(e&&this._sd)return this._sd;let t=VM(this._v,n.CoordUtils.cellToRange(this._coords),this._ri,this._options,e);return e?this._sd=t:this._s=t,t}createCell(t,r){if(t===null)return new e(this._options,this._coords);let i=this._r,a=r?.textParser,o=kM(i,t,a?{ignoreQuotePrefix:!1,...!0===a?{}:a}:null),s=this._ri,c=[];o.impliedStyle!==void 0&&c.push(o.impliedStyle),o.style!==void 0&&c.push(o.style);for(let e=0;e<c.length;e++){let t=this._coords??n.CoordUtils.EmptyCell,r=n.CoordUtils.cellToRange(t),i=this._options,a=s,o=Mg(c[e],()=>VM(this._v,r,a,i,!0)),l=(tg.compose(a?.borderStyle,a?.fillStyle,a?.contentStyle)??new tg(i.styles,null,r)).cloneWithUpdate(o),u=l.splitByFeature();s={...s,borderStyle:u.border??void 0,fillStyle:u.fill??void 0,contentStyle:u.content??void 0};let d=l._p?.numberFormat;typeof d!=`string`&&typeof d!=`number`||!Fl(d)&&!Il(d)?s.dateFormat&&delete s.dateFormat:s.dateFormat=typeof d==`number`?cu(d):d}o.comments!==void 0&&(s={...s,comments:void 0});let l=this._t,u=this._v;return o&&o.value!==void 0&&(u=o.value,l=o.type),u===this._v&&l===this._t&&s===this._ri?this:u!==null||s?new XM(this._options,this._coords,l,u,s):new XM(this._options,this._coords)}_withProjectedMerge(e){let t=this._v;return new XM(this._options,this._coords,this._t,t,{...this._ri,merge:new eM(e,()=>t)})}getNumberFormat(e){let t=this._r,n=this._options,r=this._v;if(e!==void 0){let i=lu(e);return FD(t,r,this.getStyle(),this._t,typeof i==`number`&&i!==0?i:e,e=>n.styles?.parseColor(e))}let i=this.getStyle();return FD(t,r,i,this._t,i.getNumberFormatRef(),e=>n.styles.parseColor(e))}getDate(){return this._getDate()}getText(e){let r;if(e?.showFormulas)return this.isSpillOverflow()?``:this.getFormulaText({target:`display`})||LD(this._v,this._t);if(e&&e.useFormattingCategory){let e=this._v;return this.isSpillOverflow()&&(e=null),r=function(e,r,i,a,o){if(i===t.ScalarType.Null||r==null)return``;if(i===t.ScalarType.Number){let t=Hl(),i=r,s=t.isDateFormat(a),c=t.isTimeFormat(a);if(s||c){let t=parseFloat(r),a=t%1!=0,l=t>=1;if(t<0)return n.CommonUtils.castToString(r);if(!s||c||a)if(!c||s||l){let t=ql(e,`Short Date`,i,o),n=ql(e,`Long Time`,i,o);if(t&&n)return t.fmt+` `+n.fmt}else{let t=ql(e,`Long Time`,i,o);if(t)return t.fmt}else{let t=ql(e,`Short Date`,i,o);if(t)return t.fmt}}}if(i===t.ScalarType.Number&&zc(a).endsWith(`%`)){let e=n.CommonUtils.roundAccurately(100*parseFloat(r),14);if(!isNaN(e))return ID(e)+`%`}if(i===t.ScalarType.Boolean)return Ci(r);if(i===t.ScalarType.Error){let e=r;return typeof e?.getLabel==`function`?wi(e):t.FormulaError.Label.Unknown}return i===t.ScalarType.RichData?`(Rich Object)`:i===t.ScalarType.Number?ID(r):n.CommonUtils.castToString(r)}(this._r,e,this._t,this.getStyle().getNumberFormat()),r}r=this.getNumberFormat().displayText,this._t!==t.ScalarType.String&&(r=r.replaceAll(`\xA0`,` `));let i=this._t;return e?.hideStringPrefix||i!==t.ScalarType.String||(r=`'${r}`),r}getComments(){return this._ri?.comments??null}getHyperlink(){let e=this._ri?.hyperlink;return e?new sv(()=>this.getText(qM),this._options.opener,e):null}getErrors(){let e=this._ri;if(e&&e.calcError)return[e.calcError];if(this._t===t.ScalarType.Error)return[this._v];let r=e?.circular;return r&&!r.cycle.isIterative()?[TM(r,this.getSheet().getName(),this.getCoords())]:n.CommonUtils.EmptyArray}getCircularReference(){return this._ri?.circular?.cycle??null}getWarnings(){let e=this._ri?.circular;return e?[TM(e,this.getSheet().getName(),this.getCoords())]:n.CommonUtils.EmptyArray}getSpans(){let e=this._ri?.merge;if(!e)return wM;let t=e.getCoords();return Object.freeze({width:t.colEnd-t.colStart+1,height:t.rowEnd-t.rowStart+1})}isTopLeft(){let e=this._ri?.merge;if(!e)return!0;let t=e.getCoords();return this._coords&&this._coords.colIndex===t.colStart&&this._coords.rowIndex===t.rowStart}getSpill(){let e=this._getSpillEntry();return e?this._options.getRange(e.getCoords()):null}getSpillKind(){return this._getSpillEntry()?.getKind()??null}_getSpillEntry(){let e=this._ri?.spills;if(!e||!this._coords)return null;Array.isArray(e)||(ZM[0]=e,e=ZM);let t=null,n=e?e.length:0;for(let r=0;!t&&r<n;r++){let n=e[r];n.getError()||(t=n)}return t||=Array.isArray(e)?e[0]:e,t??null}isSpillOverflow(){let e=this._ri?.spills;if(!e)return!1;let t=this._coords;return t?HM(e,t):null}get[Symbol.toStringTag](){return`[Cell]`}toString(){let e=`{blank}`;return this._v!==null&&(e=this.getText($M),this.getType()===t.ScalarType.String&&(e=`'${e}'`)),`${this.getAddress()} => ${e}`}get isICell(){return!0}},YM=class extends JM{constructor(e){super(e,null,null,null)}isEmpty(){return!0}isContentful(){return!1}toString(){return`{EMPTY CELL}`}},XM=class extends JM{getAddress(e){return`{TEMPORARY CELL}`+(this._coords?`: ${super.getAddress(e)}`:``)}},ZM=[null],QM={colIndex:-1,rowIndex:-1},$M={useFormattingCategory:!0},eN={colStart:0,rowStart:0,colEnd:0,rowEnd:0},tN={colStart:0,rowStart:0,colEnd:0,rowEnd:0},nN={colStart:0,rowStart:0,colEnd:0,rowEnd:0},rN={size:null,autoSize:!0},iN=(e,t)=>e.sizeSet-t.sizeSet;function aN(e,t){let n=e.getSpanSize(t);if(n>0||!e.hasHidden())return n;let r=e.at(t).getSize();return r>0?r:e.getDefaultSize()}var oN={colStart:0,rowStart:0,colEnd:0,rowEnd:0};function sN(e,t,n){let r=e._colHeaders;if(!r.hasHidden())return n>1?r.getSpanSize(t,t+n):r.getSpanSize(t);let i=0;for(let e=t;e<t+n;e++)i+=aN(r,e);return i}function cN(e,t,n){if(e>t)return null;let r=[],i=e,a=n?n.length:0;for(let e=0;e<a;e++){let t=n[e],a=t.min,o=t.max;if(i>=a){i=o+1;continue}let s={address:{min:i,max:a-1},update:rN};r.push(s),i=o+1}if(i<=t){let e={address:{min:i,max:t},update:rN};r.push(e)}return r}function lN(e,t,n){let r={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd},{isShrinkToFitRow:i,isShrinkToFitColumn:a}=t;if(!i&&!a)return r;let o=e._getUsedCoords();return o&&(i&&(r.colStart=o.colStart,r.colEnd=o.colEnd),a&&(r.rowStart=o.rowStart,r.rowEnd=o.rowEnd)),r}function uN(e){return{searchTypes:{[W.Type.ContentStyle]:!1,[W.Type.Merge]:!1,[W.Type.Continuous]:!1,[W.Type.DateFormat]:!1,[W.Type.Contentful]:!1},ignoreHidden:!1,bounds:{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd},axis:t.IRange.Axis.Column}}function dN(e){let t=typeof e==`string`?Yl[e]:void 0,n=String(zc(t??e)).replaceAll(/\[[^\]]*\]/g,``).replaceAll(/"[^"]*"/g,``).replaceAll(/\\./g,``).replace(/[_*]./g,``).toLowerCase(),r=/am\/pm|a\/p/.test(n);r&&(n=n.replaceAll(/am\/pm|a\/p/g,``));let i=n.match(/y+|m+|d+|h+|s+/g);if(i===null)return null;let a=!1,o=!1,s=!1,c=!1,l=!1,u=i.length;for(let e=0;e<u;e++){let t=i[e],n=t[0];if(n===`m`){if(t.length>=3)return`names`;e>0&&i[e-1][0]===`h`||e<u-1&&i[e+1][0]===`s`?t.length===1&&(c=!0):t.length===1&&(a=!0)}else if(n===`d`){if(t.length>=3)return`names`;t.length===1&&(o=!0)}else n===`h`?t.length===1&&(s=!0):n===`s`&&t.length===1&&(l=!0)}return{monthVar:a,dayVar:o,hourVar:s,minuteVar:c,secondVar:l,clock12:r,maxScore:+!!a+ +!!o+ +!!s+ +!!c+ +!!l}}var fN={year:0,month:0,day:0,hour:0,minute:0,second:0,millis:0,dow:0,serial:0};function pN(e,r,i){let{host:a,cellOptions:o,normalStyle:s,isFormulaView:l}=e,u=[],d=()=>({col:-1,fit:!1,style:s,formula:null,key:``,spanWidth:1,spanHeight:1,colSpan:1,minVal:2**53-1,maxVal:-(2**53-1),hasZero:!1,proxyVal:null,proxyLen:-1,proxyScore:-1,text:``,errorText:``,hasTrue:!1,hasFalse:!1,hasEmpty:!1,minRow:2**53-1,maxRow:-(2**53-1),maxContentRow:-(2**53-1),rowRuns:[],iconGutter:0,lastRow:-1}),f=(e,t,n,r,i,a,o,s,c,l,u)=>{e.col=t,e.fit=a,e.style=r,e.formula=o,e.key=i,e.spanWidth=s,e.spanHeight=c,e.colSpan=l,e.iconGutter=u,e.minVal=2**53-1,e.maxVal=-(2**53-1),e.hasZero=!1,e.proxyVal=null,e.proxyLen=-1,e.proxyScore=-1,e.text=``,e.errorText=``,e.hasTrue=!1,e.hasFalse=!1,e.hasEmpty=!1,e.minRow=n,e.maxRow=n,e.maxContentRow=n,e.rowRuns=[n,n],e.lastRow=n},p=e=>{u.push({col:e.col,style:e.style,spanWidth:e.spanWidth,spanHeight:e.spanHeight,minVal:e.minVal,maxVal:e.maxVal,hasZero:e.hasZero,proxyVal:e.proxyVal,text:e.text,errorText:e.errorText,hasFalse:e.hasFalse,hasTrue:e.hasTrue,hasEmpty:e.hasEmpty,minRow:e.minRow,maxRow:e.maxRow,maxContentRow:e.maxContentRow,rowRuns:e.rowRuns,colWidth:sN(a,e.col,e.colSpan),colSpan:e.colSpan,iconGutter:e.iconGutter,measureWidth:-1,measureHeight:-1,isFit:e.fit,formula:e.formula}),e.col=-1},m=new Map,h=()=>{for(let e of m.values())e.col!==-1&&p(e)},g=null,_=-1,v=-1,y={[W.Type.Merge]:!1,[W.Type.Table]:!1,[W.Type.AutoTable]:!1,[W.Type.ContentStyle]:!1,[W.Type.Continuous]:!1,[W.Type.DateFormat]:!1};l&&(y[W.Type.Formula]=!1,y[W.Type.Spills]=!1);let b=function(e,t){let n=e._getState().conditionalFormats;if(!n||n.isEmpty())return!1;let r=n.search({rowStart:t.rowStart,colStart:t.colStart,rowEnd:t.rowEnd,colEnd:t.colEnd});for(let e=0;e<r.length;e++)if(r[e].value?.getScale()?.type===OA.ScaleType.IconSet)return!0;return!1}(a,i);b&&(y[W.Type.Conditionals]=!1);let x=Hl(),S=o.runtime,C=S?.isDate1904()??!1,w={date1904:C,locale:S?.getLocale()??void 0},T=new Map,E=new Map,D=a._cellStateIterator({...uN(i),searchTypes:y,ignoreEmptyIntersections:!0}),O,k,A=D.next(),j=``,M=new Map,N=new WeakMap,P,F=0,I=`General`,L=!1,R=null,ee=null,te=1,ne=1;for(;!A.done;){let i=A.value,u=i[0],y=i[1],S=i[2],re=s,ie=S?.contentStyle??S?.table?.getStyle()??null;if(ie===O)re=k;else{O=ie;let t=``;if(ie&&(t=ie.getMeasureKey?.(),t===void 0)){let e=N.get(ie);e===void 0&&(e=`!`+ ++F,N.set(ie,e)),t=e}let r=M.get(t);if(r===void 0){let i=ie?VM(y,n.CoordUtils.cellToRange(u,nN),S,o,!1):s,a=i.getNumberFormat(),d=i.getAlignment(),f=d.getVertical(),p=e.isRow&&(d.getOverflow()===c.Overflow.Wrap||f===c.VerticalAlignment.Justify||f===c.VerticalAlignment.Distributed||d.getStacked()||de(d.getRotation())),m=null,h=null;if(!l&&(x.isDateFormat(a)||x.isTimeFormat(a))){let e=T.get(a);if(e===void 0&&(e=dN(a),T.set(a,e)),e===`names`){let e=E.get(a);e===void 0&&(e=new Map,E.set(a,e)),m=e}else h=e}r={style:i,numFmt:a,perCellText:p,lengthCache:m,plan:h},M.set(t,r)}re=k=r.style,j=t,I=r.numFmt,L=r.perCellText,R=r.lengthCache,ee=r.plan}let ae=1,oe=1,se=S?.merge??null;if(se===P)ae=te,oe=ne;else{if(se){let e=se.getCoords();ae=e.colEnd-e.colStart+1,oe=e.rowEnd-e.rowStart+1}else ae=1,oe=1;te=ae,ne=oe}let ce=u.colIndex,le=u.rowIndex,ue=IH(y),fe=n.CoordUtils.isCellWithinRange(u,r),pe=S?.continuous??null,me=pe?pe.getCoords().colEnd-ce+1:1,he=y instanceof t.FormulaError.Parse,ge=S?.formula??null;ge||!he||l||(oN.colStart=oN.colEnd=ce,oN.rowStart=oN.rowEnd=le,ge=a._calcGrid.getFormulas().search(oN)[0]?.value??null);let _e=ge&&(l||he)?ge:null,ve=ue===t.ScalarType.RichData||oe>1||ae>1||l&&HM(S?.spills,u);P=se,ce!==v&&(h(),v=ce,_=-1,g=null);let ye=_;if(_=le,ve){g!==null&&g.col!==-1&&(g.maxRow=le,g.rowRuns[g.rowRuns.length-1]=le,g.lastRow=le),A=D.next();continue}let be=0;b&&S?.conditionals&&IM(S.conditionals,le,ce,y,()=>re).iconSet&&(be=LM(re));let xe=m.get(j);xe===void 0&&(xe=d(),m.set(j,xe));let Se=!1;if((xe.col===-1||ae!==xe.spanWidth||oe!==xe.spanHeight||me!==xe.colSpan||(ue===t.ScalarType.String||ue===t.ScalarType.Error)&&L||_e!==xe.formula||be!==xe.iconGutter||fe!==xe.fit)&&(xe.col!==-1&&p(xe),f(xe,ce,le,re,j,fe,_e,ae,oe,me,be),Se=!0),g=xe,!Se){let e=xe.rowRuns;ye<=xe.lastRow?e[e.length-1]=le:e.push(le,le),xe.lastRow=le,xe.maxRow=le}if(xe.maxContentRow=le,!_e)if(y===null)xe.hasEmpty=!0;else switch(ue){case t.ScalarType.Number:if(y===0&&(xe.hasZero=!0),xe.minVal=Math.min(xe.minVal,y),xe.maxVal=Math.max(xe.maxVal,y),ee!==null){if(xe.proxyScore<ee.maxScore||xe.proxyVal===null){let e=cl(y,C,fN);if(e!==null){let t=0;if(ee.monthVar&&e.month>=10&&t++,ee.dayVar&&e.day>=10&&t++,ee.hourVar){let n=e.hour;(ee.clock12?n%12==0?12:n%12:n)>=10&&t++}ee.minuteVar&&e.minute>=10&&t++,ee.secondVar&&e.second>=10&&t++,t>xe.proxyScore&&(xe.proxyScore=t,xe.proxyVal=y)}}}else if(R!==null){let e=y,t=R.get(e);t===void 0&&(t=x.format(I,e,w).text?.length??0,R.set(e,t)),t>xe.proxyLen&&(xe.proxyLen=t,xe.proxyVal=e)}break;case t.ScalarType.String:{let e=y;e.length>xe.text.length&&(xe.text=e);break}case t.ScalarType.Error:{let e=wi(y);e.length>xe.errorText.length&&(xe.errorText=e);break}case t.ScalarType.Boolean:y?xe.hasTrue=!0:xe.hasFalse=!0}A=D.next()}return h(),u}function mN(e,n,r){let{cellOptions:i,isRowAxis:a,minContent:o,mapCache:s,isFormulaView:c}=e,l=c?{formulaView:!0}:void 0,u={formulaView:c,formulaText:void 0},d=n.length;for(let e=0;e<d;e++){let c=n[e],d=c.col>=r.colStart&&c.col<=r.colEnd,f=a||!d,p=c.style,m=c.colWidth,h=(e,n,r)=>{let a=e===t.ScalarType.String||r?.formulaText!==void 0;return UM(e,p,n,i,m,o,f,c.iconGutter,null,a?s:void 0,r)},g=0,_=0,v=e=>{g=Math.max(g,e.width),_=Math.max(_,e.height)};if(c.formula){u.formulaText=`=`+c.formula.getTextAt(c.maxContentRow,c.col,!1,void 0,`display`);let e=h(t.ScalarType.String,null,u);c.measureWidth=e.width??0,c.measureHeight=e.height??0;continue}let y=c.maxVal;if(y!==-(2**53-1)){v(h(t.ScalarType.Number,y,l));let e=c.minVal;e!==y&&v(h(t.ScalarType.Number,e,l)),c.hasZero&&e!==0&&y!==0&&v(h(t.ScalarType.Number,0,l));let n=c.proxyVal;n!==null&&n!==e&&n!==y&&v(h(t.ScalarType.Number,n,l))}let b=c.text;b.length>0&&v(h(t.ScalarType.String,b,l));let x=c.errorText;x.length>0&&(u.formulaText=x,v(h(t.ScalarType.Error,null,u))),c.hasFalse&&v(h(t.ScalarType.Boolean,!1,l)),c.hasTrue&&v(h(t.ScalarType.Boolean,!0,l)),c.hasEmpty&&v(h(t.ScalarType.Boolean,null,l)),c.measureWidth=g,c.measureHeight=_}}function hN(e,t,n,r){return e===c.Overflow.Wrap||t===c.VerticalAlignment.Justify||t===c.VerticalAlignment.Distributed||!0===r||n!==void 0&&n!==0&&de(n)}function gN(e,t,r){let i=[],a=[];(function(e,t,r,i,a){let{host:o,cellOptions:s,isRow:c,isColumn:l}=e,u=new Map,d=o._rangeStateIterator(uN(r)),f=d.next();for(;!f.done;){let e=f.value,r=e.intersection,o=e.start,p=e.end;tN.colStart=o.colIndex,tN.rowStart=o.rowIndex,tN.colEnd=p.colIndex,tN.rowEnd=p.rowIndex;let m=n.CoordUtils.intersectRanges(tN,t,eN),h;if(!r.table){let e=r.contentStyle;h=e?e.getMeasureKey?.():``}let g=h===void 0?void 0:u.get(h);if(g===void 0&&(g=VM(void 0,m,r,s,!0).getBestFit(),h!==void 0&&u.set(h,g)),c){let e=Math.max(o.rowIndex,t.rowStart),n=Math.min(p.rowIndex,t.rowEnd);e<=n&&i.push({address:{min:e,max:n},sizeSet:g.height??-1})}if(l){let e=Math.max(o.colIndex,t.colStart),n=Math.min(p.colIndex,t.colEnd);e<=n&&a.push({address:{min:e,max:n},sizeSet:g.width??-1})}f=d.next()}})(e,t,r,i,a);let o=pN(e,t,function(e,t,n){if(n.colStart>=t.colStart&&n.colEnd<=t.colEnd)return n;let r=e.normalStyle.getAlignment();if(hN(r.getOverflow(),r.getVertical(),r.getRotation(),r.getStacked()))return n;let i=e.host._getState(),a=[];n.colStart<t.colStart&&a.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:t.colStart-1,rowEnd:n.rowEnd}),n.colEnd>t.colEnd&&a.push({colStart:t.colEnd+1,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd});for(let e=0;e<a.length;e++){let t=a[e];if(i.tables.search(t).length>0)return n;let r=i.contentSpatial.search(t);for(let e=0;e<r.length;e++){let t=r[e].value?._p;if(!t)continue;if(t.named&&t.named!==q.BuiltInName.Normal&&!t.alignment)return n;let i=t.alignment;if(i&&hN(i.overflow,i.vertical,i.rotation,i.stacked))return n}}return{colStart:t.colStart,rowStart:n.rowStart,colEnd:t.colEnd,rowEnd:n.rowEnd}}(e,t,r));return mN(e,o,t),{segments:o,rowFloors:i,colFloors:a}}function _N(e,t){return t?.formulaView??e.getView()?.isShowFormulas()??!1}function vN(e,t){let n=null,r=e.length;for(let i=0;i<r;i++){let r=e[i],a=t(r.col,r.colSpan);a!==r.colWidth&&(r.colWidth=a,(n??=[]).push(r))}return n}function yN(e,t,n){let r=e.length;for(let i=0;i<r;i++){let r=e[i],a=r.col,o=e[i+1],s=r.measureWidth??0;for(;o&&o.col===a;)o.measureWidth&&(s=Math.max(o.measureWidth??0,s)),i++,r=e[i],o=e[i+1];a<t.colStart||a>t.colEnd||(s===0&&(s=null),n(a,s,r.spanWidth))}}function bN(e,t,n){let r=e.length;for(let i=0;i<r;i++){let r=e[i],a=r.measureHeight??0;a===0&&(a=null);let o=r.rowRuns,s=o.length;for(let e=0;e<s;e+=2){let i=Math.max(o[e],t.rowStart),s=Math.min(o[e+1],t.rowEnd);i>s||n(i,s,a,r.spanHeight)}}}function xN(e,t,n,r,i){let{isShrinkToFitColumn:a,updateHeaderOptions:o}=t,s=i.length,c=Array(s);for(let e=0;e<s;e++){let n=i[e];c[e]={address:n.address,update:{size:t.clampWidth(n.sizeSet===-1?void 0:n.sizeSet),autoSize:!0},sizeSet:n.sizeSet}}yN(r,n,(e,n,r)=>{let i=t.clampWidth(n,r);c.push({address:{min:e,max:e},update:{size:i,autoSize:!0},sizeSet:n===null?-1:n})}),c.sort(iN);let l=e._colHeaders.updateHeaderPairs(c,o);if(a){l=Tt(Et(Dt(l)));let t=cN(n.colStart,n.colEnd,l);t&&e._colHeaders.updateHeaderPairs(t,o)}}function SN(e,t,r,i,a){let{isShrinkToFitRow:o,updateHeaderOptions:s}=t,c=2**53-1,l=-1,u=a.length;for(let e=0;e<u;e++){let t=a[e].address;t.min<c&&(c=t.min),t.max>l&&(l=t.max)}bN(i,r,(e,t)=>{e<c&&(c=e),t>l&&(l=t)});let d=[],f=[];if(l>=c){let o=l-c+1,p=new Float64Array(o).fill(-3),m=(e,t,n)=>{for(let r=e-c,i=t-c;r<=i;r++)n>p[r]&&(p[r]=n)};for(let e=0;e<u;e++){let t=a[e];m(t.address.min,t.address.max,t.sizeSet===0?-2:t.sizeSet)}bN(i,r,(e,t,n,r)=>{m(e,t,r>1?-2:n??-1)});let h=e._rowHeaders,g=h.getScaleFactor(),_=h.getDefaultSize(),v=new Float64Array(o).fill(_),y=new Uint8Array(o),b=h._getState().headers;for(let e=n.CommonUtils.findEqualOrGreater(b,c,e=>e.max);e<b.length&&b[e].min<=l;e++){let t=b[e],n=t.value;if(!n)continue;let r=n.sz===void 0?_:n.sz*g,i=!!n.csz|(n.h?2:0);for(let e=Math.max(t.min,c)-c,n=Math.min(t.max,l)-c;e<=n;e++)v[e]=r,y[e]=i}let x=!0===s.skipCustomSize,S=-1,C=-3,w=e=>{if(S===-1||C===-3)return;f.push({min:S+c,max:e-1+c});let r=C===-2?void 0:t.clampHeight(C===-1?null:C),i=-1,a=e=>{i!==-1&&(d.push({address:{min:i+c,max:e-1+c},update:{size:r,autoSize:!0},sizeSet:C}),i=-1)};for(let t=S;t<e;t++){let e;if(y[t]!==0)e=!x;else if(r===void 0)e=!1;else{let i=v[t];e=n.CommonUtils.roundAccurately(r(i))!==n.CommonUtils.roundAccurately(i)}e?i===-1&&(i=t):a(t)}a(e)};for(let e=0;e<o;e++){let t=p[e];t!==C&&(w(e),S=e,C=t)}w(o)}if(e._rowHeaders.updateHeaderPairs(d,s),o){let t=Tt(Et(Dt(f))),n=cN(r.rowStart,r.rowEnd,t);n&&e._rowHeaders.updateHeaderPairs(n,s)}}function CN(e,t,n){let r=e.get(t);(r===void 0||n>r)&&e.set(t,n)}function wN(e,t){let n=e.length;for(let r=0;r<n;r++){let n=e[r],i=n.sizeSet;if(i<=0)continue;let a=n.address;for(let e=a.min;e<=a.max;e++)CN(t,e,i)}}function TN(e,t){return Math.max(e.getMinSize(),Math.min(n.CommonUtils.roundAccurately(t),e.getMaxSize()))}function EN(e,t,n){let r=e.hasHidden(),i=new Map;for(let[a,o]of t)r&&e.getSpanSize(a)===0?i.set(a,0):i.set(a,TN(e,o>0?o:n));return i}function DN(e,t,n,r){let i=0,a=0;for(let e of r.values())i+=e,e>0&&a++;return i+(e.getVisibleCount(t,n)-a)*e.getDefaultSize()}function ON(e,t,n,r,i,a=!1,o=!1){if(r<0&&!a&&!o&&n<=e&&i>=t)return null;let s=e,c=t;return!a&&e>=n&&(s+=Math.max(r,n-e)),!o&&t>=n&&(c+=Math.max(r,n-1-t)),[s,c]}function kN(e,t,n,r=!1,i=!1){return[r?e:e+n,i?t:t+n]}var AN=class{constructor(e){this.isIAnchored=!0,this._deleted=!1,this._closed=!1,this._nodeId=e.nodeId,this._options=e.listenerOptions,this._resolveRanges=e.resolveRanges,this._getContainerCoords=e.getContainerCoords}getNodeId(){return this._nodeId}getContainerCoords(){let e=this._getContainerCoords();return e&&e.length!==0?e:null}getListenerOptions(){return this._options}getRanges(){return this._resolveRanges(this.getContainerCoords())}isProtected(){return!1}addListeners(e,t){return()=>{}}delete(){this._deleted=!0}undelete(){this._deleted=!1}isDeleted(){return this._deleted}close(){this._closed=!0,this._deleted=!0}isClosed(){return this._closed}};(AN||={}).shiftReference=function(e,t){let r=e.before,i=e.intersect;if(e.axis===n.RangeAxis.Column){let n=ON(r.colStart,r.colEnd,i.colStart,e.amount,i.colEnd);return n===null||n[0]<t.colStart||n[1]>t.colEnd?null:{...r,colStart:n[0],colEnd:n[1]}}let a=ON(r.rowStart,r.rowEnd,i.rowStart,e.amount,i.rowEnd);return a===null||a[0]<t.rowStart||a[1]>t.rowEnd?null:{...r,rowStart:a[0],rowEnd:a[1]}};var jN=class extends AN{constructor(e){super(e),this._lastValues=null,this._lastBlank=null,this.host=e.host}deliver(e,t){if(!e.bounds&&!e.isFull)return;let r=this.getContainerCoords()?.[0]??null;if(!r)return;let i=t.onValues;if(!i)return void t.onChange?.();let a=this.host.getValueGrid(),o=this.host.getBlankRegion(),s=this._lastValues;if(s){let t=e.isFull?r:n.CoordUtils.intersectRanges(r,e.bounds);if(!t||MN(o,this._lastBlank)&&!NN(a,s,t)&&!NN(s,a,t))return}this._lastValues=a.clone(),this._lastBlank=o;let c=this.host.getValues(r);if(c)try{i(c)}catch(e){console.warn(e)}}reconcile(){let e=this.host,t=this.getContainerCoords()?.[0]??null,r=e.getCoords();t?r&&!n.CoordUtils.isEqualRanges(r,t)&&e.moveBody(t):r&&e.clear()}},MN=(e,t)=>{if(e===t)return!0;if(!e||!t||(e.value??null)!==(t.value??null)||e.rects.length!==t.rects.length)return!1;for(let r=0;r<e.rects.length;r++)if(!n.CoordUtils.isEqualRanges(e.rects[r],t.rects[r]))return!1;return!0},NN=(e,n,r)=>{let i=e.getAxis()===t.IRange.Axis.Column,a=e.getRuns({bounds:r}),o=n.getRuns({bounds:r}),s=a.next(),c=o.next();for(;!s.done||!c.done;){let t;if(s.done)t=!1;else if(c.done)t=!0;else{let[e,n,r]=s.value,[i,l,u]=c.value;if(r===u&&e===i&&n===l){s=a.next(),c=o.next();continue}t=e<i||e===i&&n<=l}let[r,l,u]=t?s.value:c.value,d=t?n:e,f=u.length;for(let e=0;e<f;e++){let t=l+e,n=i?t:r,a=i?r:t;if((u.at(e)??null)!==(d.getValueAt(n,a)??null))return!0}t?s=a.next():c=o.next()}return!1},PN=`sheet.formulasEntered`,FN=`sheet.selection`,IN=`sheet.batchSelect`,LN=`sheet.autoFit`,RN=`sheet.freezePanes`,zN=`sheet.movableSelection`,BN=`sheet.autoFormat`,VN=new WeakMap,HN=(e,t,n)=>{if(e!==void 0&&VN.get(e)===n){let n=e;for(let e=0;e<t.length;e++)n.push(t[e]);return n}let r=e===void 0?[...t]:[...e,...t];return VN.set(r,n),r},UN=e=>{let t=e;for(;t.getDepth()>0;)if(t=t.getParent(),t.getOperation())return!0;return!1},WN=(e,t,n,r)=>{let i=e?.[FN];if(!i)return null;let a=e?.[IN]?.[t],o=r===`undo`,s=e=>(r===`forward`?e.options:e.restoreOptions)||a||!1,c=null,l=i.length;for(let e=0;e<l;e++){let n=i[o?e:l-1-e];if(n.sheetId===t&&!n.nested&&s(n)){c=n;break}}return c&&c.viewId===n?{selection:(o?c.undo:void 0)??c.selection,options:s(c)}:null},GN=e.n({boundsToPoints:()=>YN,centerPoint:()=>JN,clipToOuterRect:()=>oP,minBoundingRect:()=>XN,rotatePoints:()=>ZN,unionBounds:()=>qN}),KN=(e,t)=>{let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push({x:i.x+t.x,y:i.y+t.y})}return n};function qN(e,t){if(!e)return{...t};if(!t)return{...e};let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,width:Math.max(e.width+e.x,t.width+t.x)-n,height:Math.max(e.height+e.y,t.height+t.y)-r}}function JN(e){return{x:e.width/2+e.x,y:e.height/2+e.y}}function YN(e){return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height}]}function XN(e){let t=2**53-1,n=2**53-1,r=-(2**53-1),i=-(2**53-1);for(let a=0;a<e.length;a++){let o=e[a];t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x),i=Math.max(i,o.y)}return{x:t,y:n,width:r-t,height:i-n}}function ZN(e,t,n){if(!n){let t=XN(e);n={x:t.x+t.width/2,y:t.y+t.height/2}}e=KN(e,{x:-n.x,y:-n.y});let r=t*Math.PI/180,i=Math.sin(r),a=Math.cos(r),o=[];for(let t=0;t<e.length;t++){let n=e[t],r=a*n.x-i*n.y,s=i*n.x+a*n.y;o.push({x:r,y:s})}return e=KN(o,{x:n.x,y:n.y})}var QN=0,$N=1,eP=2,tP=3;function nP(e,t,n=!0){return function(e,t,n,r,i,a,o,s,c=!0){if(e===n&&t===r||i===o&&a===s)return!1;let l=(s-a)*(n-e)-(o-i)*(r-t);if(l===0)return!1;let u=((o-i)*(t-a)-(s-a)*(e-i))/l,d=((n-e)*(t-a)-(r-t)*(e-i))/l;return(!c||!(u<0||u>1||d<0||d>1))&&{x:e+u*(n-e),y:t+u*(r-t)}}(e.p1.x,e.p1.y,e.p2.x,e.p2.y,t.p1.x,t.p1.y,t.p2.x,t.p2.y,n)}var rP=e=>({top:{p1:e[QN],p2:e[$N]},left:{p1:e[tP],p2:e[QN]},right:{p1:e[$N],p2:e[eP]},bottom:{p1:e[eP],p2:e[tP]}}),iP=(e,t,n)=>{let r=n*Math.PI/180,i=Math.sin(r),a=Math.cos(r);return{x:e*a-t*i,y:e*i+t*a}},aP=(e,t)=>{let n=e.p2.x-t.x,r=e.p2.y-t.y,i=iP(n,r,90);n=i.x+t.x,r=i.y+t.y;let a=e.p1.x-t.x,o=e.p1.y-t.y,s=iP(a,o,90);return a=s.x+t.x,o=s.y+t.y,{p1:{x:a,y:o},p2:{x:n,y:r}}};function oP(e,t,n=0){if(n<0&&(n+=360),n>90&&n<=180?n+=180:n>180&&n<=270&&(n-=180),n===0||n===180)return{height:t.height,width:t.width};if(n===90||n===270)return{height:t.width,width:t.height};let r=YN({...t,x:0,y:0}),i=YN({...e,x:0,y:0});i=KN(i,{x:t.width/2-e.width/2,y:t.height/2-e.height/2}),i=ZN(i,n);let a=rP(i),o=rP(r);if(n>90){let e=nP(a.top,o.top);if(e){let t=e,n=nP(a.bottom,o.bottom,!1)||i[tP];i[QN]=nP(a.top,aP(a.bottom,n),!1)||i[QN],i[$N]=t,i[tP]=n,i[eP]=nP(a.bottom,aP(a.top,t),!1)||i[eP],a=rP(i)}let t=nP(a.top,o.left);if(t){let e=t,n=nP(a.bottom,o.right,!1)||i[eP];i[QN]=e,i[$N]=nP(a.top,aP(a.bottom,n),!1)||i[$N],i[tP]=nP(a.bottom,aP(a.top,e),!1)||i[tP],i[eP]=n}}else if(n<90){let e=nP(a.top,o.top);if(e){let t=e,n=nP(a.bottom,o.bottom,!1)||i[eP];i[QN]=t,i[$N]=nP(a.top,aP(a.bottom,n),!1)||i[$N],i[tP]=nP(a.bottom,aP(a.top,t),!1)||i[tP],i[eP]=n,a=rP(i)}let t=nP(a.top,o.right);if(t){let e=t,n=nP(a.bottom,o.left,!1)||i[tP];i[QN]=nP(a.top,aP(a.bottom,n),!1)||i[QN],i[$N]=e,i[tP]=n,i[eP]=nP(a.bottom,aP(a.top,e),!1)||i[eP]}}i=ZN(i,-n);let s=XN(i);return{width:s.width,height:s.height}}var sP=class{constructor(e,t){this._mapStylesByName=new Map,this._arrStyleNames=[],this._mapStylesByName=e,this._arrStyleNames=t}setNode(e){this._node=e}addStyle(e,t){t!=null&&(this._node?.styles||(this._node.styles=new Map),this._node.styles.set(e,t))}addAttribute(e,t){t!=null&&(this._node?.attributes||(this._node.attributes=new Map),this._node.attributes.set(e,t),e.toLowerCase()===`rowspan`&&parseInt(t)>1&&(this._node.rowspan=parseInt(t)),e.toLowerCase()===`colspan`&&parseInt(t)>1&&(this._node.colspan=parseInt(t)))}addSharedStyle(e,t){let n=this._mapStylesByName.get(e);n?n={...t}:(this._arrStyleNames.push(e),n=t),this._mapStylesByName.set(e,n)}setPlainText(e){this._node.plainText=e}setHTMLText(e){this._node.htmlText=e.replace(/(?:\r\n|\r|\n)/g,`<br>`)}};function cP(t,n=` `){return new Promise((r,i)=>{Promise.resolve().then(()=>e.r(require("./Dv3x6zut1ZRUt3IF.cjs").default,1)).then(e=>{try{let i=e.parse(t,{delimiter:n}).data;i.length>1&&(i[i.length-1].length===0||i[i.length-1].length===1&&i[i.length-1][0].length===0)&&i.pop(),r(i)}catch(e){console.warn(e),i(e)}},e=>{i(e)})})}var lP=e=>{let t={};if(!e)return t;e.endsWith(`;`)||(e+=`;`);let n=RegExp(`;(?=([^"]*"[^"]*")*[^"]*$)`,`gsm`),r,i=0;for(;(r=n.exec(e))!==null;){try{let n=e.substring(i,r.index).trim(),a=RegExp(`:(?=([^"]*"[^"]*")*[^"]*$)`,`gsm`),o,s,c;for(;(c=a.exec(n))!==null;)o=unescape(n.substring(0,c.index)).trim(),s=unescape(n.substring(c.index+1,n.length)).trim();o!==void 0&&s!=null&&s!==`null`&&(o=k(o),t[o]=s)}catch(e){console.warn(e)}i=r.index+1}return t},uP=(e,t)=>{let n=[];if(!e)return n;let r=e.children;for(let e=0;e<r.length;e++){let i=r.item(e);if(i.nodeType===1){let e=i.tagName.toUpperCase();t.includes(e)&&n.push(i)}}return n};function dP(e,t,n){try{let r=null,i=null,a=e=>((e,t)=>{if(!e)return{};let n={},r=t.get(e.localName);r&&(n=Object.assign(n,r));let i=e.getAttribute(`class`);if(i){let e=t.get(`.`+i);e&&(n=Object.assign(n,e))}let a=e.getAttribute(`style`);if(a){let e=lP(a);e&&(n=Object.assign(n,e))}return e.getAttribute(`align`)&&!n.textAlign&&(n.textAlign=e.getAttribute(`align`)),n})(e,i);if(e)try{r=[];let o=`P, H1, H2, H3, H4, H5, H6, PRE`,s=e.querySelector(`parsererror`);if(s)return console.warn(`error`,s),!1;let c=e.querySelectorAll(`html`),l=c[c.length-1];i=(e=>{let t=e.querySelectorAll(`style`),n=new Map;if(t.length<=0)return n;for(let e=0;e<t.length;e++){let r=t[e].childNodes;for(let e=0;e<r.length;e++)if(r[e].nodeType===Node.TEXT_NODE){let t=RegExp(`<!--(.*)-->`,`gs`),i=r[e].textContent,a=t.exec(r[e].textContent);if(a&&a.length>1&&(i=a[1]),i=i.replace(/^\s/,``),i?.startsWith(`table`)){let e=RegExp(`{(.*?)}`,`gs`),t,r=0;for(;(t=e.exec(i))!==null;)try{let e=i.substring(r,t.index),a=lP(t[1]);n.set(e.trim(),a),r=t.index+t[0].length}catch(e){console.warn(e)}return n}}}return n})(l);let u=l.querySelectorAll(`body`),d=u[u.length-1],f=d.querySelectorAll(`table`)[0],p=!1;if(!f){let e=d.querySelectorAll(`span`);f=e[0],p=e.length>1}if(f||=uP(d,o)[0],f||=uP(e,o)[0],f?.nodeName.toUpperCase()===`TABLE`){n.onStart?.(i);let e=f;n.onTableStart?.(a,e);let t=uP(e,`COLGROUP`);for(let e=0;t&&e<t.length;e++){let r=uP(t[e],`COL`),i=0;for(let e=0;e<r.length;e++){let t=r[e],o=parseFloat(t.getAttribute(`span`)),s=isNaN(o)?1:o;n.onColumn?.(i,s,a,t),i+=s}}let o=e.rows,s=0;for(let e=0;e<o.length;e++){let t=o[e],i=parseFloat(t.getAttribute(`span`)),c=isNaN(i)?1:i;n.onRowStart?.(s,c,a,t);let l=[];r.push(l);let u=t.cells;for(let e=0;e<u.length;e++){let t=u[e],n=!1;for(let e=0;!n&&e<t.childNodes.length;e++)if(t.childNodes[e].nodeType===8){let r=t.childNodes[e].textContent;if(r!==`[if gte vml 1]`&&r!==`[if !vml]`&&r===`[endif]`){let r=t.childNodes[e+1];r?.querySelectorAll&&r.querySelectorAll(`table, td`).length===2&&(t=r?.querySelectorAll(`table, td`)[1],n=!0)}}l.push({htmlValue:t.textContent?.replace(/^"|"$/gi,``),element:t})}s+=c,n.onRowDow?.(s,c,a,t)}n.onTableDone?.(a,e)}else{if(f?.nodeName.toUpperCase()===`SPAN`){let e=t?t[0]?.[0]:null,r=p&&e?e:f.textContent.replace(/^"|"$/gi,``);return n.onStart?.(i),n.onCell({colStart:0,colEnd:0,rowStart:0,rowEnd:0},t?t[0]?.[0]:null,r,e=>{let t=a(e);return delete t.backgroundColor,t},f),n.onDone?.(),!0}if(f?.textContent){let e=f.textContent.replace(/^"|"$/gi,``);return n.onStart?.(i),n.onNoTable?.(e,a,f),n.onDone?.(),!0}}}catch(e){console.warn(e),r=null}!r||r.length!==0&&(r.length!==1||r[0]!==null&&r[0].length!==0)||(r=null);let o=t&&(t.length===0||t.length===1&&(t[0]===null||t[0].length===0));r&&o&&(t=null);let s=e=>{let n=new Set,i=1,o=1;for(let s=0;s<Math.max(t?t.length:0,r?r.length:0);s++){let c=0,l=0,u=r&&r[s]?r[s].length:t&&t[s]?t[s].length:0;for(;l<u;){let u=s+`-`+c;if(!n.has(u)){i=Math.max(i,c+1),o=Math.max(o,s+1);let u=null,d=r?r[s]?.[l]?.element:void 0;if(d&&(d.getAttribute(`rowspan`)||d.getAttribute(`colspan`))){let e=parseInt(d.getAttribute(`colspan`))||1,t=parseInt(d.getAttribute(`rowspan`))||1;i=Math.max(i,c+e),o=Math.max(o,s+t),u={rowStart:s,colStart:c,rowEnd:s+Math.max(0,t-1),colEnd:c+Math.max(0,e-1)};for(let r=s;r<s+t;r++)for(let t=c;t<c+e;t++)r===s&&t===c||n.add(r+`-`+t)}else u={rowStart:s,colStart:c,rowEnd:s,colEnd:c};e(u,t?t[s]?.[c]:void 0,r?r[s]?.[l]?.htmlValue:null,a,d||null),l++}c++}}};if(r&&t){let e=0,n=0;s(t=>{e=Math.max(e,t.colEnd+1),n=Math.max(n,t.rowEnd+1)}),t&&r&&(t.length!==n||t[0].length!==e)&&(console.warn(`mismatched mimeTypes`,t,r),t=null)}return s(n.onCell.bind(n)),n.onDone?.(),!o||r!==null}catch(e){throw console.warn(e),e}}var fP=(e,t)=>{var n;if(t){if(t.getType()===K.Type.Solid)e.background=kp(t.getColor())||`none`,e[`mso-pattern`]=`black none`;else if(t.getType()===K.Type.Pattern){let r=t;e.background=kp(r.getBackground())||`none`;let i=kp(r.getForeground())||``;if(r.getPatternType()===K.BuiltInSheetPattern.Solid)e[`mso-pattern`]=`${e.background} none`,e.background=i;else{let t=(n=r.getPatternType(),Cm.get(n)?.cssKey??`solid`);e[`mso-pattern`]=i+(t?` `:``)+t}}else if(t.getType()===K.Type.Gradient){let n=t;e.background=kp(n.getStops()?.[0]?.getColor())||`auto`,e[`mso-pattern`]=`${e.background} none`,e.msoGradient=Om(n)||`auto`}}},pP=class{constructor(e,t){if(this._visitedStyles=new Map,this._lastStyleClassId=63,this._wroteTD=!1,!e)throw Error(`Can not create with a null sheet.`);this._sheet=e,this._includeSizeInCell=t?.includeSizeInCell??!1,this._textOptions=t?.showFormulas?hP:mP,this._normalStyle=e.getStyles().getNormal()}_createCSSStyle(e){let t=this._normalStyle,n={},r=(e,t)=>e===t||!(e&&!t)&&!(!e&&t)&&t.isEqual?.(e),i=e.getFont(),a=t.getFont();var o;r(i.getColor(),a.getColor())||(n.color=kp(i.getColor())),r(i.getSize(),a.getSize())||(n[`font-size`]=Ap(i.getSize())),r(i.getWeight(),a.getWeight())||(n[`font-weight`]=i.getWeight()),r(i.getStyle(),a.getStyle())||(n[`font-style`]=i.getStyle()),r(i.getUnderline(),a.getUnderline())||(n[`text-decoration`]=`underline`,n[`text-underline-style`]=(o=i.getUnderline())===B.UnderlineStyle.Single?`single`:o===B.UnderlineStyle.Double?`double`:o===B.UnderlineStyle.SingleAccounting?`single-accounting`:o===B.UnderlineStyle.DoubleAccounting?`double-accounting`:`none`),r(i.getFamily(),a.getFamily())&&r(i.getFallbacks(),a.getFallbacks())||(n[`font-family`]=Lp(i.getFamily(),i.getFallbacks())),r(e.getNumberFormat(),t.getNumberFormat())||(n[`mso-number-format`]=Rp(e.getNumberFormat()));let s=e.getAlignment(),l=t.getAlignment();if(!r(s.getHorizontal(),l.getHorizontal())){let e=s.getHorizontal();e===c.HorizontalAlignment.CenterContinuous?n[`text-align`]=`center-across`:e===c.HorizontalAlignment.Fill?n[`text-align`]=`fill`:e===c.HorizontalAlignment.Distributed?n[`text-align`]=s.getJustifyLastLine()?`121`:`010`:n[`text-align`]=c.toCSSHorizontalTextAlign(e)}if(!r(s.getVertical(),l.getVertical())){let e=s.getVertical();e===c.VerticalAlignment.Distributed?n[`vertical-align`]=`121`:n[`vertical-align`]=Fp(e)}if(!r(s.getOverflow(),l.getOverflow())){let e=s.getOverflow();n[`white-space`]=Ip(e),e===c.Overflow.Shrink&&(n[`mso-text-control`]=`shrinktofit`)}var u;s.getStacked()&&!l.getStacked()?n[`layout-flow`]=`vertical`:s.getStacked()||r(s.getRotation(),l.getRotation())||(n[`mso-rotate`]=(u=s.getRotation(),(u%=360)<0&&(u+=360),u>180?u=360-u:u>1&&(u*=-1),u)),r(s.getIndent(),l.getIndent())||(n[`mso-char-indent-count`]=s.getIndent()),r(e.getFill(),t.getFill())||fP(n,e.getFill());let d=e.getBorders();return d.getTop().isNone()||(n[`border-top`]=jm(d.getTop())),d.getLeft().isNone()||(n[`border-left`]=jm(d.getLeft())),d.getRight().isNone()||(n[`border-right`]=jm(d.getRight())),d.getBottom().isNone()||(n[`border-bottom`]=jm(d.getBottom())),d.getDiagonalUp().isNone()||(n[`border-mso-diagonal-up`]=jm(d.getDiagonalUp())),d.getDiagonalDown().isNone()||(n[`border-mso-diagonal-down`]=jm(d.getDiagonalDown())),Object.keys(n).length===0?null:n}_createCSSNormalStyle(){let e=this._normalStyle,t={"padding-top":`1px`,"padding-left":`1px`,"padding-right":`1px`,"mso-ignore":`padding`},n=e.getFont(),r=e.getAlignment();return t.color=kp(n.getColor()),fP(t,e.getFill()),t[`font-size`]=Ap(n.getSize()),t[`font-weight`]=n.getWeight(),t[`font-style`]=n.getStyle(),t[`text-decoration`]=jp(n.getUnderline(),n.getStrike()),t[`font-family`]=Lp(n.getFamily(),n.getFallbacks()),t[`mso-font-charset`]=`0`,t[`mso-background-source`]=`auto`,t[`mso-number-format`]=Rp(e.getNumberFormat()),t[`text-align`]=c.toCSSHorizontalTextAlign(r.getHorizontal()),t[`vertical-align`]=Fp(r.getVertical()),t.border=`none`,t[`mso-pattern`]=`auto`,t[`white-space`]=Ip(r.getOverflow()),r.getOverflow()===c.Overflow.Shrink&&(t[`mso-text-control`]=`shrinktofit`),t[`mso-rotate`]=`0`,r.getIndent()>0&&(t[`mso-char-indent-count`]=r.getIndent()),t[`mso-protection`]=`locked visible`,t}onCell(e,t,r){let i=e.getSpans();if(i.width>1||i.height>1){if(!e.isTopLeft())return!1;i.height>1&&r.addAttribute(`rowspan`,i.height),i.width>1&&r.addAttribute(`colspan`,i.width)}let a=this._textOptions,o=e.getText(a),s=a.showFormulas?null:e.getNumberFormat().errorPlaceholder;s&&(o=s.repeat(5));let c=a.showFormulas||s?o:e.getText(gP);r.setPlainText(c||``);let l=e.getStyle(),u=l.getFont();if(u.getVerticalAlignment()===B.VerticalAlignment.Super&&(o=`<sup>${o}</sup>`),u.getVerticalAlignment()===B.VerticalAlignment.Sub&&(o=`<sub>${o}</sub>`),u.getStrike()&&(o=`<s>${o}</s>`),e.getHyperlink()&&(o=`<a href="${e.getHyperlink().getAddress()}">${o}</a>`),r.setHTMLText(o||` `),!this._wroteTD){let e=this._createCSSNormalStyle();r.addSharedStyle(`td`,e),this._wroteTD=!0}let d=this._visitedStyles.get(l);if(!d){let e=this._createCSSStyle(l);e&&(d=`xl`+ ++this._lastStyleClassId,this._visitedStyles.set(l,d),r.addSharedStyle(`.`+d,e))}if(d&&r.addAttribute(`class`,d),this._includeSizeInCell){let e=this._sheet.getColumnHeaders().at(t.colIndex).getSize();r.addAttribute(`width`,e),r.addStyle(`width`,n.CommonUtils.roundAccurately(e/B.getDeviceScale(),2)+`pt`);let i=this._sheet.getRowHeaders().at(t.rowIndex).getSize();r.addAttribute(`height`,i),r.addStyle(`height`,n.CommonUtils.roundAccurately(i/B.getDeviceScale(),2)+`pt`)}}onRow(e,t,r,i){let a=e.getSize();i.addAttribute(`height`,a),i.addStyle(`height`,n.CommonUtils.roundAccurately(a/B.getDeviceScale(),2)+`pt`),e.isCustomSize()&&i.addStyle(`mso-height-source`,`userset`)}onColumn(e,t,r,i){let a=e.getSize();i.addAttribute(`width`,a),i.addStyle(`width`,n.CommonUtils.roundAccurately(a/B.getDeviceScale(),2)+`pt`),e.isCustomSize()&&i.addStyle(`mso-width-source`,`userset`),r>1&&i.addAttribute(`colspan`,r)}},mP={useFormattingCategory:!0},hP={showFormulas:!0},gP={hideStringPrefix:!0};function _P(e,t,r,i=!1){let a=t.rowEnd-t.rowStart+1,o=t.colEnd-t.colStart+1,s=i?o:a,c=i?a:o,l=Math.max(1,Math.ceil((r.rowEnd-r.rowStart+1)/s)),u=Math.max(1,Math.ceil((r.colEnd-r.colStart+1)/c)),d=(e,t,n,r,i)=>{if(t-e+1===r)return[[n+e,n+(i-1)*r+t]];let a=[];for(let o=0;o<i;o++)a.push([n+o*r+e,n+o*r+t]);return a},f=[];for(let a=0;a<e.length;a++){let o=e[a],p=o.rowStart-t.rowStart,m=o.rowEnd-t.rowStart,h=o.colStart-t.colStart,g=o.colEnd-t.colStart,_=i?p:h,v=i?m:g,y=d(i?h:p,i?g:m,r.rowStart,s,l),b=d(_,v,r.colStart,c,u);for(let e=0;e<y.length;e++)for(let t=0;t<b.length;t++){let i={rowStart:y[e][0],rowEnd:y[e][1],colStart:b[t][0],colEnd:b[t][1]},a=n.CoordUtils.intersectRanges(i,r);a&&f.push(a)}}return Rh(n.CoordUtils.EmptyRanges,f)}function vP(e,r,i){let a=e.getAxis()===t.IRange.Axis.Column,o=a?(0,n.messageKey)(`copy.columnCopy`):(0,n.messageKey)(`copy.rowCopy`),s=e.getSnapshot(i);return{...s,getName:()=>(0,n.t)(o),getCoords:()=>r,copyTo:async(e,t)=>{let n=a?e.getColumnHeaders():e.getRowHeaders(),o={...i,...t};if(!0===o.includeHeaders){let e=await s.copyTo(n,o);return a?{colStart:e.min,rowStart:r.rowStart,colEnd:e.max,rowEnd:r.rowEnd}:{colStart:r.colStart,rowStart:e.min,colEnd:r.colEnd,rowEnd:e.max}}},getMarkOptions:()=>i}}function yP(e,t,r,i,a,o){let s=r[0],c=e.getView()?.isShowFormulas()??!1,l,u,d=()=>{if(u!==void 0)return;let[e,r]=function(e,t){let r=t.getRowHeaders(),i=t.getColumnHeaders(),a=t.getUsedRange()?.getCoords(),o=r.getUsedRange()?.getCoords(),s=i.getUsedRange()?.getCoords(),c={...n.CoordUtils.EmptyRange,...a,colEnd:Math.max(a?.colEnd??0,s?.max??0),rowEnd:Math.max(a?.rowEnd??0,o?.max??0)},l=new Map,u=[];e.onStart?.();let d={rows:[],cols:[]},f=new sP(l,u);f.setNode(d),e.onTable?.(f,c);let p=0;i.forEachSpan((t,n)=>{let r=n.getCoords();p=p+r.max-r.min+1;let i={};f.setNode(i),e.onColumn?.(n.getCellHeader(),r.min,r.max-r.min+1,f),d.cols.push(i)},{address:c,includeEmpty:!0,includeStyles:!0});let m=0,h=[];if(r.forEachSpan((e,t)=>{let n=t.getCoords();m=m+n.max-n.min+1,h.push({min:n.min,max:n.max,value:t.getCellHeader()})},{address:c,includeEmpty:!0,includeStyles:!0,visibility:`all`}),p*m>5e4)return[null,`The data you've selected is too large. Try selecting a smaller set of data.`];let g=0,_=-1,v=null;t.forEach((t,n)=>{let r=n.getCoords(),i=n.getCell();if(r.rowIndex!==_){r.rowIndex>h[g].max&&++g;let t=h[g];v={cells:[]},f.setNode(v),e.onRow?.(t.value,r.rowIndex,1,f),d.rows.push(v),_=r.rowIndex}let a={};f.setNode(a),!1!==e.onCell(i,r,f)&&v.cells.push(a)},{address:c,includeEmpty:!0,ignoreHidden:!1}),e.onDone?.(),d.rows.length===0&&d.rows.push({cells:[]});let y=[];for(let e=0;e<u.length;e++){let t=u[e],n=l.get(t);y.push(t);let r=``,i=Object.keys(n);for(let e=0;e<i.length;e++){r+=` `,e===0&&(r+=`{`);let t=i[e];r+=`${t}:${n[t]};`,e===i.length-1?r+=`}`:r+=`
|
|
65
|
-
`}y.push(r)}let b=[`<div clipboard-uuid=xxx>
|
|
66
|
-
<html
|
|
67
|
-
xmlns:v="urn:schemas-microsoft-com:vml"
|
|
68
|
-
xmlns:o="urn:schemas-microsoft-com:office:office"
|
|
69
|
-
xmlns:x="urn:schemas-microsoft-com:office:excel"
|
|
70
|
-
xmlns="http://www.w3.org/TR/REC-html40"
|
|
71
|
-
>`];b.push(`<head>
|
|
72
|
-
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
|
|
73
|
-
<meta name=ProgId content=Excel.Sheet>
|
|
74
|
-
<meta name=Generator content="Microsoft Excel 15">`),b.push(`<style>
|
|
75
|
-
table
|
|
76
|
-
{mso-displayed-decimal-separator:"\\.";
|
|
77
|
-
mso-displayed-thousand-separator:"\\,";}
|
|
78
|
-
@page
|
|
79
|
-
{margin:.75in .25in .75in .25in;
|
|
80
|
-
mso-header-margin:.3in;
|
|
81
|
-
mso-footer-margin:.3in;
|
|
82
|
-
mso-horizontal-page-align:center;}
|
|
83
|
-
tr
|
|
84
|
-
{mso-height-source:auto;}
|
|
85
|
-
col
|
|
86
|
-
{mso-width-source:auto;}
|
|
87
|
-
br
|
|
88
|
-
{mso-data-placement:same-cell;}`),y.length>0&&b.push(y.join(`
|
|
89
|
-
`)),b.push(`</style>`),b.push(`</head>`),b.push(`<body>`),b.push(`<table>`),b.push(`<!--StartFragment-->`);let x=e=>{let t=(e=>{let t=``;return e&&e.attributes&&e.attributes.length!==0&&e.attributes.forEach((e,n)=>{t.length>0&&(t+=` `),t+=`${n}=${e}`}),t})(e);t.length>0&&(t=` `+t);let n=(e=>{let t=``;return e&&e.styles&&e.styles.length!==0?(e.styles.forEach((e,n)=>{t.length>0&&(t+=`;`),t+=n+`:`+e}),t.length>0&&(t=`style='${t}'`),t):t})(e);return n.length>0&&(n=` `+n),`${t}${n}`},S=[];return d.cols?.forEach(e=>{b.push(` <col${x(e)}>`)}),d.rows.forEach(e=>{b.push(` <tr${x(e)}>`);let t=[];e.cells.forEach(e=>{b.push(` <td${x(e)}>${e.htmlText??e.plainText??``}</td>`);let r=`${n.CommonUtils.castToString(e.plainText??``)?.replace(/"/g,`""`)}`;t.push(r)}),S.push(t.join(` `)),b.push(` </tr>`)}),b.push(`<!--EndFragment-->`),b.push(`</table>`),b.push(`</body>`),b.push(`</html>`),b.push(`</div>`),[b.join(`
|
|
90
|
-
`),S.join(`
|
|
91
|
-
`).concat(`
|
|
92
|
-
`)]}(new pP(t,{showFormulas:c}),t.getRange(s));l=e??null,u=r??null},f=!1;return{copyTo(e,t){let r={...a,...t};if(t?.isCut&&f)throw f=!0,Error((0,n.t)(`error.sheet.snapshotDone`));return o(e,r)},getMarkOptions:()=>a,getSource:()=>e,getName:()=>(0,n.t)(i),getCoords:()=>s,toText:()=>(d(),u),toHtml:()=>(d(),l),toImage:()=>null,isISnapshot:!0}}var bP=class e{constructor(e,t,n,r,i){this._getColumnAt=void 0,this._index=e,this._sheetHeader=t,this._headerState=n,this._template=r,this._getColumnAt=i}getSize(){let e=this._headerState?.sz;return Math.round(e===void 0?this._sheetHeader.getDefaultSize():e*this._sheetHeader.getScaleFactor())}getText(){return``+this.asCell().getValue()}getAxis(){return this._sheetHeader.getAxis()}isHidden(){return this._headerState?.h??!1}isCustomSize(){return this._headerState?.cs??!1}getSheetHeader(){return this._sheetHeader}getColumn(){return this._getColumnAt?.(this._index)??null}asCell(){return this._cellTemplate||=this._sheetHeader.getSheet().createCell(this._template),this._cellTemplate}getSizeRelative(){return this.getSize()/this._sheetHeader.getScaleFactor()}createCellHeader(t){let n=xP(this._sheetHeader,this._sheetHeader.getSheet().getStyles(),this._headerState,t);return new e(this._index,this._sheetHeader,n,this._template,this._getColumnAt)}isEqual(e){if(!e)return!1;if(e===this)return!0;let t=e;if(!t.isICellHeader)return!1;let n=this._headerState,r=t._headerState;return n===r||!(n&&!r||r&&!n)&&this.getSize()===t.getSize()&&this.isCustomSize()===t.isCustomSize()&&this.isHidden()===t.isHidden()}isEmpty(){let e=this._headerState;return!e||e.sz===void 0&&e.csz===void 0&&!e.cs&&e.h===void 0}get[Symbol.toStringTag](){return`[SheetCellHeader]`}toString(){return`[SheetCellHeader: ${this.getText()}]`}get isICellHeader(){return!0}};function xP(e,t,r,i){if(i!==void 0){if(i===null)return null;if(i?.isICellHeader)return{...i._headerState};if(i){let a=i,o,s=a.hidden;r&&(o={...r});let c,l=a.size;if(a.size!==void 0){if(typeof l==`function`){let t=r?.sz===void 0?e.getDefaultSize():r?.sz*e.getScaleFactor();l=l?.(t)}if(typeof l==`string`&&(l=Sm(l,t.getNormal().getFont().getSize(),`px`)),typeof l==`number`){let t=e.getMinSize(),r=e.getMaxSize();l=Math.max(t,Math.min(n.CommonUtils.roundAccurately(l),r)),!0!==a.relativeSize&&(l/=e.getScaleFactor()),isNaN(l)&&(console.warn(`Invalidate size: '${l}'`),l=void 0),l===0&&(s=!0,l=void 0),c=!a.autoSize}l===null&&(c=!a.autoSize)}return l!==void 0&&r?.sz!==l&&(o||={},l===null?delete o.sz:o&&(o.sz=l)),s===void 0&&a.autoSize&&(s=!1),s!==void 0&&r?.h!==s&&(s?(o||={},o.h=s):o&&delete o.h),c!==void 0&&r?.csz!==c&&(c?(o||={},o.csz=c):o&&delete o.csz),o?Object.keys(o).length===0?null:o:null}}}function SP(e,t){return Math.round(e*t)}function CP(e,t,n,r){if(e==null)return null;let i,a,o={};if(typeof e==`number`)o.colStart=e,o.colEnd=e,o.rowStart=e,o.rowEnd=e;else if(typeof e==`string`){if(t){if(e.match(/[0-9]+/))throw Error(`Invalid range address for header axis`)}else if(e.match(/[a-zA-Z]+/))throw Error(`Invalid range address for header axis`);let r=yd(e,n);if(!r){let t=_d(e.toUpperCase(),!0);t?.colIndex!==void 0&&(o.colStart=t.colIndex,o.colEnd=t.colIndex),t?.rowIndex!==void 0&&(o.rowStart=t.rowIndex,o.rowEnd=t.rowIndex)}o={...o,...r}}return t?(i=e.min??e.colStart??o.colStart,a=e.max??e.colEnd??o.colEnd):(i=e.min??e.rowStart??o.rowStart,a=e.max??e.rowEnd??o.rowEnd),i===void 0||a===void 0?null:{min:i,max:a}}var wP=()=>{},TP=()=>0,EP=()=>!1,DP=class{constructor(e,t){this._header=e,this._coords=t}_forEachSpan(e,t,n){let r=this._header,i=this._coords,a=r._options;n||=a.createCellHeader;let o=i;if(t?.address){let e=r._parseHeaderRangeAddress(t?.address);if(e&&(o=kt(i,e),!o))return}let s=r._scanHeaders(e,this._header._getState(),n,a,o,t);if(s&&s.break)return s.break}forEachSpan(e,t){return this._forEachSpan(e,t)}forEach(e,t){let n,r=2**53-1,i=null,a={getIndex:()=>r,getCellHeader:()=>i.getCellHeader(),getAddress:(e,t)=>i.getAddress(e,t),getCoords:()=>i.getCoords()};return this._forEachSpan((t,o)=>{i=o;let s=this._coords,c=s.max;for(let i=s.min;i<c;i++)r=i,n=i-s.min,e(t,a)},t,()=>this.at(n))}updateHeaders(e,t){let r=this._header;return r.updateHeaderPairs([{address:this._coords,update:e}],{description:t?.description??(r._isColumn?(0,n.t)(`op.updateColumnsRange`,{range:toString()}):(0,n.t)(`op.updateRowsRange`,{range:toString()})),...t}),this}getCoords(){return{...this._coords}}getUsedRange(e){let t=this._header,n=t._headerRunCoords;return!n||n.min<0||n.max>t._maxDataIndex?null:kt(n,this._coords)?t.getRange(n,e):null}getCount(){let e=this._coords;return e.max-e.min+1}getHeaderCount(){let e=this._coords;return e.max-e.min+1}getVisibleCount(){let e=this._coords;return this._header.getVisibleCount(e.min,e.max)}isEntireHeaders(){let e=this._header._entireRunCoords,t=this._coords;return!(t.min>e.min||t.max<e.max)}getSnapshot(e){return this._header._getSnapshot(this._coords,e)}setSize(e,t){return this._header._setSize(this._coords,e,t),this}setHidden(e,t){return this._header._setHidden(this._coords,e,t),this}clear(){return this._header._clear(this._coords),this}at(e){return this._header.at(this._coords.min+e)}getAxis(){return this._header.getAxis()}doBatch(e,t){return this._header.doBatch(t=>e(t),t)}getSheetHeader(){return this._header}getAddress(e){let t=this._coords,n=this._header;return hd(n._isColumn?{colStart:t.min,colEnd:t.max}:{rowStart:t.min,rowEnd:t.max},n._entireRangeCoords)??`#REF!`}get[Symbol.toStringTag](){return`[SheetCellHeaderRange]`}toString(){return this.getAddress()}get isICellHeaderRange(){return!0}},OP=class{constructor(e,t){this._header=e,this._coords=t}updateHeaders(e,t){let r=this._header;return r.updateHeaderPairs([{address:this._coords,update:e}],{description:t?.description??(r._isColumn?(0,n.t)(`op.updateColumnsRange`,{range:toString()}):(0,n.t)(`op.updateRowsRange`,{range:toString()})),...t}),this}getCoords(){return[...this._coords]}setHidden(e,t){return this._header._setHidden(this._coords,e,t),this}setSize(e,t){return this._header._setSize(this._coords,e,t),this}getCount(){return this._coords.length}getHeaderCount(){let e=Pt(this._coords,!0),t=0,n=e.length;for(let r=0;r<n;r++){let n=e[r];t+=n.max-n.min+1}return t}getVisibleCount(){let e=Pt(this._coords,!0),t=0,n=this._header,r=e.length;for(let i=0;i<r;i++){let r=e[i];t+=n.getVisibleCount(r.min,r.max)}return t}isEntireHeaders(){let e=this._header._entireRunCoords,t=this._coords,n=e.min,r=e.max,i=t.length;for(let e=0;e<i;e++){let i=t[e];if(n<i.min||r>i.max)return!1}return!0}isEntireHeadersAny(){let e=this._header._entireRunCoords,t=this._coords,n=e.min,r=e.max,i=t.length;for(let e=0;e<i;e++){let i=t[e];if(i.min<=n&&i.max>=r)return!0}return!1}clear(){return this._header._clear(this._coords),this}at(e){let t=this._coords;return e<0||e>=t.length?null:this._header.getRange(t[e])}getAxis(){return this._header.getAxis()}doBatch(e,t){return this._header.doBatch(t=>e(t),t)}getSheetHeader(){return this._header}getAddress(e){let t=this._coords,n=this._header;return function(e,t,n=hd){if(!e)return Qu;let r=e.length,i=Array(r);for(let a=0;a<r;a++)i[a]=n(e[a],t);return i.join(`,`)}(Nt(t,n._entireRangeCoords,n._isColumn),n._entireRangeCoords)??`#REF!`}get[Symbol.toStringTag](){return`[SheetCellHeaderRanges]`}toString(){return this.getAddress()}get isICellHeaderRanges(){return!0}},kP=class{constructor(e){if(this._closed=!1,this._scaleFactor=1,this._defaultSize=-1,this._defaultCustomSize=-1,this._defaultPxSize=1,this._isColumn=!0,this._indexedSizes=[],this._indexedHidden=[],this._headerRunCoords=null,this._hasHidden=!1,this._hiddenSignature=0,this._lastHeaderRead=null,this._readCache=null,this._lastHeaders=null,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null,this._selectionRuns=null,this._options={isProtected:()=>!1,scaleFactor:()=>1,defaultSize:()=>100,minSize:()=>0,maxSize:()=>500,getEntireSheetCoords:()=>null,axis:t.IRange.Axis.Column,createCellHeader:(t,n,r,i)=>new bP(t,n,r,i,e?.getColumnAt??AP),...e},!this._options.sheet)throw Error(`An ISheet must be provided`);this._emptyHeader=this._options.createCellHeader(0,this,null,null);let n=this._options.axis===t.IRange.Axis.Column;this._isColumn=n;let r=this;this._options.setContainerShiftedCallback&&this._options.setContainerShiftedCallback((e,t)=>{t<0?r._deleteHeaders(e,-t):r._insertHeaders(e,t)}),this._options.sheet&&(this._sheetRemoveListener=this._options.sheet.addListeners({onProtectionChange(){},onSelectionChange(e){r._selection=e.getSelection().getCoords(),r._selectionRuns=null},onStyleChange:()=>{},onViewChange(){let e=r._headers;r._invalidSizes(),r._invalidateMaxIndex(),r._emitter.notify(`onSizesChange`,{params:e})}},{transactional:!1}),r._selection=r._options.sheet.getSelection().getCoords()),this._transactions=this._options.transactions??new g({transient:!0}),this._id=this._transactions.create(),this._emitter=new x(r,this._transactions),this._transactionsRemoveListener=this._transactions.addStateListener(this._id,{onAfterStateChange(e){r._lastHeaders!==e.headers&&r._onHeaderChange(!0)},async onRestoreOrRevert(e){r._onHeaderChange(!0)}}),this.fromJSON(this._options?.json)}addListeners(e,t){return this._emitter.addListeners(e,t)}_invalidateExtent(){this._invalidSizes(),this._invalidateMaxIndex()}_invalidateMaxIndex(){let e=this._options.getEntireSheetCoords()??{colStart:0,rowStart:0,colEnd:2**53-1,rowEnd:2**53-1};this._entireSheetCoords=e;let t=this._isColumn,n=t?e.colEnd:e.rowEnd;this._entireRunMax=n,this._entireRunCoords={min:0,max:n},this._entireHeaderRange=this.getRange(this._entireRunCoords),this._entireRangeCoords={colStart:0,rowStart:0,colEnd:t?n:0,rowEnd:t?0:n}}_invalidSizes(e=!1){let t=this._defaultCustomSize===-1?this._options.defaultSize():this._defaultCustomSize;if(t<0)throw Error(`defaultSize must be greater than 0`);let n=this._options.scaleFactor();if(globalThis.__SXL_LOG_EVENTS){let r=e||t!==this._defaultSize||n!==this._scaleFactor;console.log(`[sxl:SheetHeader:${this._isColumn?`col`:`row`}] _invalidSizes force=${e} scale ${this._scaleFactor}->${n} default ${this._defaultSize}->${t} rebuild=${r}`)}if(e||t!==this._defaultSize||n!==this._scaleFactor){this._defaultSize=t,this._scaleFactor=n,this._defaultPxSize=SP(t,n);let e=function(e,t,n){let r=[],i=[],a=[];if(!e||e.length===0)return{sizes:r,hidden:i};if(!t||!n)return console.warn(`_HeaderUtils:default size and scaleFactor should be available`),{sizes:r,hidden:i};let o=0,s=0,c=0,l=null,u=-2,d=null,f=-2,p=e.length;for(let m=0;m<p;m++){let p=e[m],h=p.min,g=p.max;if(o=r.length===0?0:r[r.length-1].runningOffsetMax,r.length>0&&r[r.length-1].spanSize>0&&o++,s<p.min){r.push({min:s,max:h-1,runningOffsetMin:o,runningOffsetMax:Math.round(o+(h-s)*t*n)-1,runningHiddenRuns:c,spanSize:Math.round(t*n)});let e=s,i=h-1;f+1===e?d.max=i:(d={min:e,max:i,value:!0},a.push(d)),f=i}let _=r.length,v=r[_-1];o=_===0?0:v.runningOffsetMax,_>0&&v.spanSize>0&&o++;let y=p.value,b=y.h?0:SP(y.sz??t,n),x=b===0?0:-1;b===0?(c+=g-h+1,u+1===h?l.max=g:(l={min:h,max:g,value:!0},i.push(l)),u=g):(f+1===h?d.max=g:(d={min:h,max:g,value:!0},a.push(d)),f=g),_>0&&v.spanSize===b&&v.max+1===h?(v.max=g,v.runningHiddenRuns=c,v.runningOffsetMax=v.runningOffsetMin+(g+1-v.min)*b+x):r.push({min:h,max:g,runningOffsetMin:o,runningOffsetMax:Math.round(o+(g+1-h)*b)+x,runningHiddenRuns:c,spanSize:b}),s=g+1}return{sizes:r,hidden:i}}(this._headers,t,n);this._indexedSizes=e.sizes,this._indexedHidden=e.hidden,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null}}invalidate(){this._invalidSizes(!0),this._invalidateMaxIndex(),this._selection=this._options.sheet.getSelection()?.getCoords()}_onHeaderChange(e){this._lastHeaders=null;let t=this._headers,n=this._getState();this._defaultCustomSize=n.defaultCustomSize,this._invalidSizes(!0);let r=this._defaultCustomSize===-1?this._options.defaultSize():this._defaultCustomSize;this._lastHeaderRead=null,this._readCache=At(this._lastHeaders);let i=this._options.sheet.getStyles().getNormal(),a=!1,o=0,s=-1,c=t.length,l=this._entireRunMax;for(let e=c-1;e>=0;e--){let n=t[e],c=n.value,l=c.s,u=c.csz||c.sz!==r;s!==-1||!u&&l===i||(s=n.max),(c.h||c.sz===0)&&(a=!0,o=Math.imul(o,31)+n.min|0,o=Math.imul(o,31)+n.max|0)}s=Math.min(s??0,l);let u=Math.min(t[0]?.min??s,s);this._headerRunCoords=Object.freeze({min:u,max:s}),this._hasHidden=a;let d=this._hiddenSignature!==o;this._hiddenSignature=o,e&&this._emitter.notify(`onSizesChange`),d&&(this._options.hiddenChanged?.(),this._emitter.notify(`onHiddenChange`))}getSheet(){return this._options.sheet}getAxis(){return this._isColumn?t.IRange.Axis.Column:t.IRange.Axis.Row}getTextAt(e){return this._options.getTextAt?.(e)??e+``}_scanHeaders(e,t,r,i,a,o){let s=a?.min??null,c=a?.max??null,l=o?.includeEmpty??!1,u=o?.includeStyles??!1,d=o?.visibility??`all`,f=o?.includeSizes??!1,p=this,m=this._options.sheet.getStyles().getNormal(),h=this._defaultSize,g=this._scaleFactor,_=t.headers,v=this._emptyHeader,y=null,b={getCoords(){if(!y)throw Error((0,n.t)(`error.sheet.iteratorClosed`));return{min:y.min,max:y.max}},getIndex:()=>y.min,getCellHeader(){if(!y)throw Error((0,n.t)(`error.sheet.iteratorClosed`));return y.value?r(s,p,y.value):v},getAddress(e,t=!1){if(!y)throw Error((0,n.t)(`error.sheet.iteratorClosed`));let r=e===void 0?y.min:Math.max(y.min,e),i=e===void 0?y.max:Math.min(y.max,e),a=p._parseHeaderRangeAddress({min:r,max:i}),o=p._entireRangeCoords,s=p._isColumn;return hd({colStart:s?a.min:o.colStart,rowStart:s?o.rowStart:a.min,colEnd:s?a.max:o.colEnd,rowEnd:s?o.rowEnd:a.max},o,void 0,!0)??`#REF!`}},x=t=>{let n=t.value;if(!l&&!n)return;let r=l;if(f&&!r&&n&&(n.csz||n.sz!==h)&&(r=!0),u&&!r&&n&&(n.s&&n.s!==m||n.cs)&&(r=!0),n&&!0===n.h?r=d!==`visible`:d===`hidden`&&(r=!1),!r)return;let i=h;t.value&&(i=t.value.h?0:t.value?.sz??h),i*=g,y=t;let a=e(i,b);return a&&a.break?a:void 0},S;return S=d===`visible`?Mt(this._indexedHidden,e=>{if(!0===e.value)return;let t=s===null?e.min:Math.max(e.min,s),n=c===null?e.max:Math.min(e.max,c),r=Mt(_,x,t,n);return r&&r.break?r:void 0},s,c):Mt(_,x,s,c),y=null,S}getRange(e,t){if(!e)throw Error((0,n.t)(`error.address.noAddress`));let r=this._parseHeaderRangeAddress(e);return r.min<0||r.max>this._entireRunMax?function(e){return Object.freeze({getCoords:()=>null,getAxis:()=>e.getAxis(),toString:()=>Qu,getAddress:()=>Qu,getCount:TP,getHeaderCount:TP,getVisibleCount:TP,isEntireHeaders:EP,forEach:wP,forEachSpan:wP,getUsedRange:J,getSnapshot:J,updateHeaders:J,clear:J,setHidden:J,setSize:J,at:J,doBatch:J,getSheetHeader:()=>e,isICellHeaderRange:!0})}(this):new DP(this,r)}getFilteredRanges(e){if(this._isColumn)return n.CommonUtils.EmptyArray;let t=this._options.sheet._getInternal().filteredTables();if(t.length===0)return n.CommonUtils.EmptyArray;let r=[];for(let n=0;n<t.length;n++){let i=t[n].getDataRange();if(i.isInvalid())continue;let a=i.getCoords();e&&(a.rowEnd<e.min||a.rowStart>e.max)||r.push(new DP(this,{min:a.rowStart,max:a.rowEnd}))}return r}getRanges(e,t){if(!e)throw Error((0,n.t)(`error.address.noAddress`));let r=function(e,t,n){if(typeof e==`string`){let r=Td(e,n),i=r?r.length:0,a=Array(i);for(let e=0;e<i;e++){let n=r[e];a[e]={min:t?n.colStart:n.rowStart,max:t?n.colEnd:n.rowEnd}}return e=a,a}Array.isArray(e)||(e=[e]);let r=e.length,i=Array(r);for(let a=0;a<r;a++)i[a]=CP(e[a],t,n);return i}(e,this._isColumn,this._entireRangeCoords);return new OP(this,r)}getSelectedRange(e){let t=this._options.sheet.getSelection().getRange().getCoords();return this.getRange(t,e)}getSelectedRanges(e){let t=this._options.sheet.getSelection().getRanges().getCoords();return this.getRanges(t,e)}getUsedRange(e){return this.getRange(this._headerRunCoords,e)}getEntireRange(e){return e?this.getRange(this._entireRangeCoords,e):this._entireHeaderRange}at(e){if(e<0||e>this._entireRunMax)return this._emptyHeader;if(this._lastHeaderRead?.offset===e)return this._lastHeaderRead.header;let t=jt(e,this._readCache),n=this._options.getTextAt?.(e)??e+``,r=this._options.createCellHeader(e,this,t,{value:n});return this._lastHeaderRead={offset:e,header:r},r}updateHeaderPairs(e,t){if(this.isProtected())throw new n.ProtectedError(this._isColumn?(0,n.t)(`error.sheetHeader.protectedColumns`):(0,n.t)(`error.sheetHeader.protectedRows`));return this._updatePairsInternal(e,t)}_parseHeaderRangeAddress(e,t){if(e==null)throw Error((0,n.t)(`error.address.noRange`));let r=CP(e,this._isColumn,this._entireRangeCoords);if(!r)throw Error((0,n.t)(`error.address.invalidRangeHeader`));return r}_update(e,t,n){if(!e||(Array.isArray(e)||(e=[e]),e.length===0))return;let r=[],i=e.length;for(let n=0;n<i;n++){let i=this._parseHeaderRangeAddress(e[n]);this.getRange(i).forEachSpan((e,n)=>{let i=n.getCoords();r.push({address:i,update:t})},{includeEmpty:!0})}return this.updateHeaderPairs(r,n),this}_setSize(e,t=null,r){(r?.relativeSize??!1)||typeof t!=`number`||(t+=`px`);let i={size:t,autoSize:r?.autoSize??!1},a=this._isColumn?(0,n.messageKey)(`op.resizeColumns`):(0,n.messageKey)(`op.resizeRows`);return this._update(e,i,{description:a,...r}),this}_setHidden(e,t=null,r){let i={hidden:t},a=this._isColumn?t?(0,n.messageKey)(`op.unhideColumns`):(0,n.messageKey)(`op.hideColumns`):t?(0,n.messageKey)(`op.unhideRows`):(0,n.messageKey)(`op.hideRows`);return this._update(e,i,{description:a,...r}),this}_clear(e,t){let r=this._isColumn?(0,n.messageKey)(`op.clearColumnHeaders`):(0,n.messageKey)(`op.clearRowHeaders`);this.updateHeaderPairs([{address:e,update:null}],{description:r,...t})}_getSnapshot(e,t){if(e.min<0)return n.CommonUtils.EmptyArray;t=Object.freeze({...t});let r=this,i=this._getState(),a=this._isColumn?(0,n.messageKey)(`copy.columnHeaders`):(0,n.messageKey)(`copy.rowHeaders`);return{copyTo(o,s){let c={...t,...s},l=o.getCoords(),u=l.min-e.min,d=[];if(r._scanHeaders((e,t)=>{let n=t.getCoords();d.push({address:{min:n.min+u,max:n.max+u},update:t.getCellHeader()})},i,r._options.createCellHeader,null,e,{includeSizes:!0,includeStyles:!0}),!c.fitDestination){let t=e.max-e.min+1,r=l.max-l.min+1,i=n.CommonUtils.roundAccurately(r/t);if(i>1&&r%t===0){let e=d.length;for(let n=0;n<i;n++)for(let r=0;r<e;r++){let e=d[r],i=e.address,a=(n+1)*t;d.push({address:{min:i.min+a,max:i.max+a},update:e.update})}}}if(o.doBatch(()=>{o.clear(),o.getSheetHeader()._updatePairsInternal(d)},a),c.isCut){let t=r._entireRunCoords;e.min<=t.min&&e.max>=t.max&&r._clear(e)}return l},getCoords:()=>e,toText:()=>null,toHtml:()=>null,toImage:()=>null,getSource:()=>r,getName:()=>a,isISnapshot:!0}}isProtected(){return this._options?.isProtected()??!1}getScaleFactor(){return this._options.scaleFactor()??1}get _headers(){return this._lastHeaders===null&&(this._lastHeaders=this._getState()?.headers),this._lastHeaders}_updatePairsInternal(e,t){if(!e||e.length===0)return null;let r=t?.skipCustomSize??!1,i=this._isColumn,a=this.getSheet().getStyles(),o=this._beginCommit({description:t?.description??(i?(0,n.messageKey)(`op.updateColumns`):(0,n.messageKey)(`op.updateRows`))}),s=[...this._getState().headers],c=!1,l=this,u=this._defaultCustomSize===-1?this._options.defaultSize():this._defaultCustomSize,d=(e,t,i)=>{if(this.isProtected())throw new n.ProtectedError(this._isColumn?(0,n.t)(`error.sheetHeader.protectedColumns`):(0,n.t)(`error.sheetHeader.protectedRows`));return wt(e,{min:t.min,max:t.max,value:i},{onUpdate:(e,t)=>{if(r&&(e?.csz||e?.h))return e;let n=xP(l,a,e,t);return n===void 0?e:n?e?(c||=n.sz!==e.sz,c||=n.h!==e.h,n):(c=!0,n):(e&&(c=!0),n)},onSplit:e=>[e.value,e.value],onMerge:(e,t,n,r)=>{if(!(e&&!t||!e&&t||!e&&!t)&&e.sz===t.sz&&e.csz===t.csz&&e.h===t.h&&e.cs===t.cs)return e},isCull:(e,t,n)=>e===void 0})},f=this._entireRunMax,p=e.length,m=Array(p);for(let t=0;t<p;t++){let r=this._parseHeaderRangeAddress(e[t].address);if(r.min<0||r.max>f)throw new n.OutOfBoundsError((0,n.t)(`error.sheet.oobRange`));m[t]=r}let h=Array(p);for(let e=0;e<p;e++)h[e]=e;h.sort((e,t)=>m[e].min-m[t].min);let g=!1;for(let e=1;!g&&e<p;e++)m[h[e]].min<=m[h[e-1]].max&&(g=!0);if(g)for(let t=0;t<p;t++)s=Tt(d(s,m[t],e[t].update));else{let t=s,n=t.length,r=[],i=[],a=0;for(let o=0;o<p;o++){let s=h[o],c=m[s],l=i;for(i=[];a<n&&t[a].max<c.min;)l.push(t[a++]);let u=0;for(;u<l.length-1&&l[u+1].max<c.min;)u++;for(let e=0;e<u;e++)r.push(l[e]);for(u>0&&l.splice(0,u);a<n&&t[a].min<=c.max;)l.push(t[a++]);a<n&&(l.length===0||l[l.length-1].max<=c.max)&&l.push(t[a++]);let f=d(l,c,e[s].update);for(let e=0;e<f.preceding.length;e++)r.push(f.preceding[e]);i=f.modified.concat(f.trailing)}for(let e=0;e<i.length;e++)r.push(i[e]);for(;a<n;a++)r.push(t[a]);s=r}let _=!1,v=s.length;if(v>0&&s[0].min===0&&s[v-1].max===f){let e=s[0],t=!1,n=-1;for(let r=0;!t&&r<v;r++){let i=s[r],a=i.min;if(n+1!==a){t=!0;continue}let o=i.max;n=o,e.max-e.min<o-a&&(e=i)}t||(this._defaultCustomSize=e.value?.sz??-1,_=!0);let r=[];for(let e=0;e<v;e++){let t=s[e],n=t.value;if(n===null)continue;let i=Object.keys(n).length;if(i===0)continue;let a=n.sz;(i!==1||a===void 0||a!==null&&a!==u)&&r.push(t)}s=r,v=s.length}let y=[];for(let e=0;e<v;e++){let t=s[e],n=t.value;if(n===null)continue;let r=!1;n.sz!==void 0&&n.sz!==u&&(r=!0),n.csz!==void 0&&(r=!0),n.h!==void 0&&(r=!0),n.l!==void 0&&(r=!0),r&&y.push(t)}return _&&l._invalidSizes(!0),this._updateState({headers:y,defaultCustomSize:this._defaultCustomSize},c),o.commit(),m}hasHidden(){return this._hasHidden}getDefaultSize(){return this._defaultPxSize}getDefaultSizeNative(){return this._defaultSize}getMaxSize(){return Math.ceil(this._options.maxSize()*this._options.scaleFactor())}getMinSize(){return Math.floor(this._options.minSize()*this._options.scaleFactor())}getOffset(e){return function(e,t,r){if(t<=0)return 0;let i=e?e.length:0;if(i===0)return t*r;let a=e[i-1];if(t>a.max)return a.runningOffsetMax+Math.round((t-a.max-1)*r+(a.spanSize===0?0:1));let o=e[i===1?0:n.CommonUtils.findEqualOrGreater(e,t,e=>e.max)],s=t-o.min;return o.runningOffsetMin+s*o.spanSize}(this._indexedSizes,e,this._defaultPxSize)}getIndex(e){return Math.min(Math.max(0,function(e,t,r){let i=e?e.length:0;if(i===0)return Math.floor(t/r);let a=e[i-1];if(t>a.runningOffsetMax)return a.max+Math.ceil((t-a.runningOffsetMax)/r);let o=e[i===1?0:n.CommonUtils.findEqualOrGreater(e,t,e=>e.runningOffsetMax)];if(o.spanSize===0)return Math.max(0,o.min-1);let s=t-o.runningOffsetMin;return o.min+Math.floor(s/o.spanSize)}(this._indexedSizes,e,this._defaultPxSize)),this._entireRunMax)}getVisibleIndex(e){return this._lastVisibleRunsRead===e||(this._lastVisibleRunCoords=function(e,t,r=2**53-1){let i=e?e.length:0;if(i===0)return{min:t,max:t};let a=i-1,o=e[a];if(t>o.max){let e=t-o.runningHiddenRuns;return{min:e,max:e}}a=i===1?0:n.CommonUtils.findEqualOrGreater(e,t,e=>e.max),o=e[a];let s=o.spanSize===0?Math.max(-1,o.min-1-(e[a-1]?.runningHiddenRuns??1)):t-o.runningHiddenRuns;return{min:s,max:s+Math.min(r+1,+(o.spanSize===0))}}(this._indexedSizes,e,this._entireRunMax),this._lastVisibleRunsRead=e),this._lastVisibleRunCoords}getSpanSize(e,t=e+1){return this.getOffset(t)-this.getOffset(e)}getVisibleCount(e,t){if(e>t)throw Error((0,n.t)(`error.address.invalidArguments`));if(e<0||t>this._entireRunMax)throw new n.OutOfBoundsError;return this._hasHidden?function(e,t,r){let i=r-t+1;if(e.length===0)return i;let a=e.length-1,o=e[a];if(t>o.max)return i;a=e.length===1?0:n.CommonUtils.findEqualOrGreater(e,t,e=>e.max),o=e[a];let s=o.runningHiddenRuns;if(o.spanSize===0&&t<=o.max){let e=o.max-o.min+1;i-=Math.min(e,o.max-t+1)}r>o.max&&a<e.length&&(a=n.CommonUtils.findEqualOrGreater(e,r,e=>e.max),o=e[Math.min(a,e.length-1)]);let c=o.runningHiddenRuns;if(o.spanSize===0&&o.min<=r){let e=o.max-o.min+1;i-=Math.min(e,r-o.min+1),c-=e}return i-=c-s,i}(this._indexedSizes,e,t):t-e+1}isSelectedAll(e){let t=this.getSelectedRuns();if(t.length===0)return!1;let r=t[n.CommonUtils.findEqualOrGreater(t,e,e=>e.max)];return!(!r||e<r.min||e>r.max)&&r.value}isSelected(e){let t=this.getSelectedRuns();if(t.length===0)return!1;let r=t[n.CommonUtils.findEqualOrGreater(t,e,e=>e.max)];return!(!r||e<r.min||e>r.max)}getSelectedRuns(){let e=this._selectionRuns;return e||(this._selection&&(e=wA(this.getAxis(),this._selection,this._entireSheetCoords)),e||=n.CommonUtils.EmptyArray),this._selectionRuns=e,this._selectionRuns}hiddenHeadersAt(e,t=!1){if(this._indexedSizes.length===0)return 0;let r=this._indexedSizes.length===1?0:n.CommonUtils.findEqualOrGreater(this._indexedSizes,e,e=>e.max),i=this._indexedSizes[r];return!i||i.spanSize!==0||i.min>e||i.max<e?0:t?e-i.min+1:i.max-e+1}_insertHeaders(e,t){if(t<=0)return;let r=this._beginCommit({description:this._isColumn?(0,n.messageKey)(`op.insertColumns`):(0,n.messageKey)(`op.insertRows`)}),i=this._getState().headers,a=i.length,o=e<=(a>0?i[a-1].max:0),s=i;o&&(s=Tt(function(e,t,r=1){let i=n.CommonUtils.findEqualOrGreater(e,t,e=>e.max),a=e.slice(0,i),o=[],s=[];if(!e[i])return{preceding:a,modified:s,trailing:o};e[i].min>=t?o.push({...e[i],min:e[i].min+r,max:e[i].max+r}):s.push({...e[i],min:e[i].min,max:e[i].max+r});for(let t=i+1;t<e.length;t++)o.push({...e[t],min:e[t].min+r,max:e[t].max+r});return{preceding:a,modified:s,trailing:o}}([...s],e,t))),this._updateState({headers:s},o),r.commit()}_deleteHeaders(e,t){let r=this._beginCommit({description:this._isColumn?(0,n.messageKey)(`op.deleteColumns`):(0,n.messageKey)(`op.deleteRows`)}),i=this._getState().headers,a=i.length,o=e<=(a>0?i[a-1].max:0),s=i;o&&(s=Tt(Ct([...s],e,t))),this._updateState({headers:s},o),r.commit()}beginCommit(e){return this._beginCommit(typeof e==`string`?{description:e}:e)}doBatch(e,t){return this._transactions.doBatch(e,typeof t==`string`?{description:t}:{description:(0,n.messageKey)(`op.updateHeader`),...t})}getId(){return this._id}getVersionId(){return this._transactions.getVersionId(this._id)}isClosed(){return this._closed}close(){this._sheetRemoveListener?.(),this._emitter.close(),this._transactionsRemoveListener?.(),this._closed=!0,this._transactions.remove(this._id)}_getState(){return this._transactions.getState(this._id)}_beginCommit(e){return this._transactions.beginCommit(e)}_updateState(e,t=!1){let n=this._transactions.beginCommit();try{n.updateState(this._id,e),this._onHeaderChange(t),n.commit()}catch(e){throw n.rollback(),e}}fromJSON(e){let t=e||{};this._defaultCustomSize=t.defaultSize??-1,this._defaultCustomSize<=0&&(this._defaultCustomSize=-1),this._invalidateMaxIndex();let n=this._options.sheet.getStyles().beginPersist();try{let e=[],n=t.headers,r=n?n.length:0,i=this._entireRunMax??2**53-1,a=this._isColumn;for(let t=0;t<r;t++){let r=Xd(n[t],a);if(!r)continue;let o=r.min;if(o>=i)continue;let s={min:o,max:Math.min(r.max,i)},c=r.value,l={};c.sz!==void 0&&c.sz!==-1&&(l.sz=c.sz),c.h!==void 0&&(l.h=c.h),c.csz!==void 0&&(l.csz=c.csz),Object.keys(l).length===0&&(l.cs=!0),s.value=l,e.push(s)}this._updateState({headers:e,defaultCustomSize:this._defaultCustomSize})}finally{n.endPersist()}}toJSON(){let e=this._headers,t=e.length;if(t===0&&this._defaultCustomSize===-1)return null;let r={headers:[]};if(this._defaultCustomSize!==-1&&(r.defaultSize=n.CommonUtils.roundAccurately(this._defaultCustomSize,8)),t===0)return r;let i=this._defaultCustomSize,a=this._isColumn,o=this.getSheet().getStyles().beginPersist();for(let o=0;o<t;o++){let t=e[o],s=t.value;if(!s)continue;let c={},l=s.sz;l!==void 0&&l!==i&&(c.sz=n.CommonUtils.roundAccurately(l,8)),s.csz!==void 0&&(c.csz=s.csz),!0===s.h&&(c.h=s.h),Object.keys(c).length>0&&r.headers.push({r:qd(t.min,t.max,a),v:c})}return o.endPersist(),r}get[Symbol.toStringTag](){return`[SheetHeader]`}toString(){return`[SheetHeader]`}get isISheetHeader(){return!0}},AP=e=>null,jP=class e extends yr{constructor(e){super(e),this._entireCoords=e?.entireCoords}getContentfulCoords(){let e=this._contentfulCoords;if(e!==void 0)return e;let t=this._entireCoords;if(!t||this.isEmpty())return this._contentfulCoords=null,null;let n=this.all(),r=n.length,i=t.colStart,a=t.rowStart,o=t.colEnd,s=t.rowEnd,c=2**53-1,l=2**53-1,u=-(2**53-1),d=-(2**53-1),f=0,p=0,m=0,h=0;for(let t=0;t<r;t++){let r=n[t];f=r.colStart,m=r.colEnd,m>=o&&(f=Math.max(f-1,i),m=f),p=r.rowStart,h=r.rowEnd,h>=s&&(p=Math.max(p-1,a),h=p),c=Math.min(c,f),u=Math.max(u,m),l=Math.min(l,p),d=Math.max(d,h),e={colStart:c,rowStart:l,colEnd:u,rowEnd:d}}return this._contentfulCoords=e,e}setEntireCoords(e){this._entireCoords=e,this._onModified()}getEntireCoords(){return this._entireCoords??null}clone(e=null){let t=super.clone(e);return t._entireCoords=this._entireCoords,t._contentfulCoords=this._contentfulCoords,t}_onModified(){super._onModified(),this._contentfulCoords=void 0}_createClone(t){return new e(t)}},MP=class e{constructor(e,t,n=`dynamic`){this._c=e,this._cycleId=t,this._k=n}getCycleId(){return this._cycleId}getKind(){return this._k}getError(){return this._k===`error`}isFixed(){return this._k===`fixed`}getCoords(){return this._c}setError(t,n){let r=this._k===`fixed`?`fixed`:t?`error`:`dynamic`,i=r===`error`?{colStart:this._c.colStart,rowStart:this._c.rowStart,colEnd:this._c.colStart,rowEnd:this._c.rowStart,scope:this._c.scope}:this._c;return{...i,value:new e(i,n,r)}}checkShift(e,t,r){if(this._k!==`fixed`)return;let i=this._c,a=t?i.colStart:i.rowStart,o=t?i.colEnd:i.rowEnd,s=t?e.colStart:e.rowStart,c=t?e.colEnd:e.rowEnd;if(o<s)return;let l=t?i.rowStart:i.colStart,u=t?i.rowEnd:i.colEnd,d=t?e.rowStart:e.colStart,f=t?e.rowEnd:e.colEnd;if(u<d||l>f)return;let p;if(p=!(l<d||u>f)&&(r?a>=s:a>c||a>=s&&o<=c),!p)throw new n.ExpectedError((0,n.t)(`error.sheet.changePartOfArray`))}getTranslated(t,n){let r=this._c,i={colStart:r.colStart+n,rowStart:r.rowStart+t,colEnd:r.colEnd+n,rowEnd:r.rowEnd+t,scope:r.scope};return{...i,value:new e(i,this._cycleId,this._k)}}getShifted(r){this.checkShift(r.intersect,r.axis===t.IRange.Axis.Column,r.amount>0);let i=r.after;if(!i)return null;let a=n.CoordUtils.sanitizeRange(i);return{...a,value:new e(a,this._cycleId,this._k)}}getMerged(e,t,n){}getSplit(e,t){if(this._k===`fixed`)throw new n.ExpectedError((0,n.t)(`error.sheet.changePartOfArray`))}},NP=class e{constructor(e,t){this._c=e,this._a=t}getCoords(){return this._c}getAxis(){return this._a}getShifted(t){return t.after?{...t.after,value:new e(t.after,this._a)}:null}getMerged(t,n,r){let i=this._a;return new e(n,i)}getSplit(t,n){let r=this._a;return[new e(t[0],r),new e(t[1],r)]}getState(){return this._c}};function PP(e,r,i){if(!e||e.length===0)return n.CommonUtils.EmptyArray;let a=[],o=r?t.IRange.Axis.Column:t.IRange.Axis.Row;for(let t=0;t<e.length;t++){let n=e[t],s=n[0],c=n[1];for(let e=0;e<c.length;e++){let t=c[e],n=t[0],l=t[1].length-1,u={colStart:r?s:n,rowStart:r?n:s,colEnd:r?s:n+l,rowEnd:r?n+l:s},d={...u,value:new NP({...u},o)};i!==void 0&&(d.scope=i),a.push(d)}}return a}var FP=e=>{let t=e.ext;return t===null&&(t=e.ext={spillDependents:n.CommonUtils.EmptyArray,spillRowEnd:-1,spillColEnd:-1,fixedRef:null,pendingPromise:null,demandValue:void 0,cycleGroup:0,cycleNext:null,shownGroup:0}),t},IP=e=>{let t=e.precedents;return t===null?e.block.getPrecedentsAt(e.rowIndex,e.colIndex):t},LP=e=>{let t=e.precedents;return t===null?e.block.paramLength:t.length},RP=iU(4096),zP=0,BP=()=>RP,VP=(e,t)=>{if(t===0)return void(e.inputsAt=-1);let n=zP,r=n+t;if(r>RP.length){let e=iU(Math.max(r,2*RP.length));for(let t=0;t<n;t++)e[t]=RP[t];RP=e}let i=RP;for(let e=n;e<r;e++)i[e]=void 0;zP=r,e.inputsAt=n},HP=(e,t)=>{let n=e.inputsAt;return n<0?void 0:RP[n+t]},UP=(e,t)=>{let n=e.inputsAt;if(n<0)return;let r=RP;for(let e=0;e<t;e++)r[n+e]=void 0},WP=0,GP=1,KP=4,qP=8,JP=16,YP=32,XP=128,ZP=768,QP=3072,$P=12288,eF=16384,tF=32768,nF=65536,rF=1<<17,iF=233384,aF=0,oF=256,sF=512,cF=768,lF=0,uF=1024,dF=2048,fF=(e,n,r)=>{let i=gF(e,n,r?.anchor===`start`),a=i.value;switch(i.op){case`prefix`:{let t=a;if(t===``)return e=>typeof e==`string`;let n=t.length;return r=>typeof r==`string`&&r.length>=n&&e.compare(r.slice(0,n),t)===0}case`wc`:{let e=a,t=i.match;return n=>typeof n==`string`?t===e.test(n):!t}case`=`:return a===void 0?e=>e==null:a===``?e=>e==null||e===``:typeof a==`string`?t=>typeof t==`string`&&e.compare(t,a)===0:t.FormulaError.isError(a)?e=>!!t.FormulaError.isError(e)&&e.equals(a):typeof a==`number`?t=>typeof t==`number`?e.compare(t,a)===0:typeof t==`string`&&mF(e,t,a):e=>e===a;case`<>`:return a===void 0?e=>e!=null:typeof a==`string`?t=>typeof t!=`string`||e.compare(t,a)!==0:t.FormulaError.isError(a)?e=>!t.FormulaError.isError(e)||!e.equals(a):typeof a==`number`?t=>typeof t!=`number`||e.compare(t,a)!==0:e=>e!==a;case`>`:return pF(e,a,e=>e>0);case`>=`:return pF(e,a,e=>e>=0);case`<`:return pF(e,a,e=>e<0);case`<=`:return pF(e,a,e=>e<=0);default:return()=>!1}},pF=(e,t,n)=>{if(t===void 0)return()=>!1;let r=hF(t);return i=>r(i)&&n(e.compare(i,t))},mF=(e,t,n)=>{try{return e.compare(e.parseAsNumber(t),n)===0}catch{return!1}},hF=e=>{switch(typeof e){case`string`:return e=>typeof e==`string`;case`number`:return e=>typeof e==`number`;case`boolean`:return e=>typeof e==`boolean`;default:return e=>t.FormulaError.isError(e)}},gF=(e,n,r=!1)=>{let i=typeof n;if(i===`string`){let i=n,a=e.parseAsLiteral(i);if(a!==void 0)return{op:`=`,value:a};let o=i.match(/^(<>|>=|<=|>|<|=)([\s\S]*)$/);if(o!==null){let n=o[1],r=o[2];if(r===``)return{op:n,value:void 0};let i;if(typeof r==`string`)try{i=e.parseAsNumber(r)}catch{}if(i===void 0){let a=e.parseAsLiteral(r);if(a!==void 0)i=a;else if(i=r,(n===`=`||n===`<>`)&&t.WildCard.isWildCard(i))return{op:`wc`,value:t.WildCard.toRegex(i,`i`,!0),match:n===`=`}}return{op:n,value:i}}try{let t=e.parseAsNumber(i);if(t!==void 0)return{op:`=`,value:t}}catch{}return t.WildCard.isWildCard(i)?{op:`wc`,value:t.WildCard.toRegex(i,`i`,!r||`start`),match:!0}:{op:r?`prefix`:`=`,value:n}}return i===`boolean`||i===`number`||t.FormulaError.isError(n)?{op:`=`,value:n}:n==null?{op:`=`,value:0}:{op:`err`,value:new t.FormulaError.Value(`Criteria.parse: type ${typeof n} not support`)}},_F=class{constructor(e,t,n,r,i,a,o,s){this._cursor=-1,this._onRead=e,this._gridId=t,this._rowStart=n,this._colStart=r,this._rowEnd=i,this._colEnd=a,this._byColumn=o,this._reverse=s;let c=i-n+1,l=a-r+1;this._minorCount=o?c:l,this._total=c*l}reach(e,t){if(e<this._rowStart||e>this._rowEnd||t<this._colStart||t>this._colEnd)return void this._onRead(this._gridId,e,t,e,t);let n=this._byColumn?(t-this._colStart)*this._minorCount+(e-this._rowStart):(e-this._rowStart)*this._minorCount+(t-this._colStart);this._advance(this._reverse?this._total-1-n:n)}clampMinor(e){let t=this._byColumn?this._rowStart:this._colStart,n=this._byColumn?this._rowEnd:this._colEnd;return e<t?t:e>n?n:e}finish(){this._advance(this._total-1)}_advance(e){let t=this._cursor+1;if(e<t)return;this._cursor=e;let n=this._reverse?this._total-1-e:t,r=this._reverse?this._total-1-t:e,i=this._minorCount,a=Math.floor(n/i),o=n-a*i,s=Math.floor(r/i),c=r-s*i;a===s?this._report(a,o,a,c):(this._report(a,o,a,i-1),s-a>1&&this._report(a+1,0,s-1,i-1),this._report(s,0,s,c))}_report(e,t,n,r){this._byColumn?this._onRead(this._gridId,this._rowStart+t,this._colStart+e,this._rowStart+r,this._colStart+n):this._onRead(this._gridId,this._rowStart+e,this._colStart+t,this._rowStart+n,this._colStart+r)}},vF=class e{static{this.created=0}constructor(t,n,r){this.observesReads=!0,this._inner=t,this._gridId=n,this._onRead=r,e.created++}getInner(){return this._inner}_resolveBounds(e){let t=this._inner,n=e?.rowStart,r=e?.colStart,i=e?.rowEnd,a=e?.colEnd;if(n===void 0||r===void 0||i===void 0||a===void 0||n===-(2**53-1)||r===-(2**53-1)||i===2**53-1||a===2**53-1){let e=t.getMaxCoords?.()??t.getCoords();if(!e)return null;n!==void 0&&n!==-(2**53-1)||(n=e.rowStart),r!==void 0&&r!==-(2**53-1)||(r=e.colStart),i!==void 0&&i!==2**53-1||(i=e.rowEnd),a!==void 0&&a!==2**53-1||(a=e.colEnd)}return{rowStart:n,colStart:r,rowEnd:i,colEnd:a}}_reportBounds(e){let t=this._resolveBounds(e);t!==null&&this._onRead(this._gridId,t.rowStart,t.colStart,t.rowEnd,t.colEnd)}_openSweep(e,n,r){let i=this._resolveBounds(e);return i===null?null:this._onRead(this._gridId,i.rowStart,i.colStart,i.rowEnd,i.colEnd,!0)?new _F(this._onRead,this._gridId,i.rowStart,i.colStart,i.rowEnd,i.colEnd,(n??this._inner.getAxis?.())===t.IRange.Axis.Column,!0===r):null}getValueAt(e,t){return this._onRead(this._gridId,e,t,e,t),this._inner.getValueAt(e,t)}getRuns(e){let n=this._openSweep(e?.bounds,void 0,!1),r=this._inner.getRuns(e);if(n===null)return r;let i=this._inner.getAxis?.()===t.IRange.Axis.Column,a={[Symbol.iterator]:()=>a,next:()=>{let e=r.next();if(e.done)return n.finish(),e;let[t,a,o]=e.value,s=n.clampMinor(a+o.length-1);return i?n.reach(s,t):n.reach(t,s),e},return:e=>r.return?r.return(e):{done:!0,value:e}};return a}entries(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse),n=this._inner.entries(e);if(t===null)return n;let r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);if(r.done)return t.finish(),r;let i=r.value[0];return t.reach(i.rowIndex,i.colIndex),r},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}values(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse);if(t===null)return this._inner.values(e);let n=this._inner.entries(e),r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);if(r.done)return t.finish(),{done:!0,value:void 0};let i=r.value[0];return t.reach(i.rowIndex,i.colIndex),{done:!1,value:r.value[1]}},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}keys(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse),n=this._inner.keys(e);if(t===null)return n;let r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);return r.done?(t.finish(),r):(t.reach(r.value.rowIndex,r.value.colIndex),r)},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}getValues(e){return this._reportBounds(e),this._inner.getValues(e)}copyTo(e,t,n){this._reportBounds(n),this._inner.copyTo(e,t,n)}getAxis(){return this._inner.getAxis()}getCount(){return this._inner.getCount()}getCoords(){return this._inner.getCoords()}getMaxCoords(){return this._inner.getMaxCoords?.()??null}clone(e){return this._inner.clone(e)}cloneEmpty(e){return this._inner.cloneEmpty(e)}setValues(e){return this._inner.setValues(e),this}setValueAt(e,t,n){this._inner.setValueAt(e,t,n)}delete(e){return this._inner.delete?.(e)??!1}clear(){this._inner.clear?.()}shift(e,t){return this._inner.shift?.(e,t)??!1}get[Symbol.toStringTag](){return`[ReadObservedGrid]`}},yF=2**53,bF=(e,t)=>!0===e?.isPendingOverlay?e:t??null,xF=class e{constructor(e,n=t.IRange.Axis.Column,r){this._passSeed=0,this._passCycleId=-1,this._gridKey=0,this._gridKeyId=null,this._onRead=null,this._dynamicRead=null,this._container=e,this._axis=n,this._functionProviders=r,this._positionRead=()=>{this._calcScope.perCellRead=!0}}_setInstanceScope(e){this._instanceScope=e}_setReadHook(e){this._onRead=e}_setDynamicReadHook(e){this._dynamicRead=e}async _initialize(e){let n=await Y_._validate(!0),r=this._container,i=r.getRuntime();this._runtime=new vt(`Calculation Runtime`,{isDate1904:()=>i.isDate1904(),isR1C1:()=>i.isR1C1(),getNow:()=>r.getNow(),getRandom:()=>i.getRandom(),getLocale:()=>i.getLocale()},n),this._calcScope=r.getScope(),this._coerceToNumber=GH(this._runtime,t.ScalarType.Number,lU);let{initializeFunctions:a}=await Promise.resolve().then(()=>require("./CwzIjMpnMKeypivl.cjs")),o=this,s=Object.freeze(a(()=>o,this._functionProviders)),c=new rk({transactions:e??new g({transient:!0}),context:this,readonlyFunctions:s,createScopedContext:e=>o._createScoped(e)});return this._functions=c,{functions:c}}_createScoped(t){let n=this._container,r=n.getSymbols().bind($.Sheet,t);if(!r||!n.getGrid(r))return null;let i=new e(n,this._axis,this._functionProviders);return i._runtime=this._runtime,i._functions=this._functions,i._coerceToNumber=this._coerceToNumber,i._instanceScope=this._instanceScope,i._calcScope={gridId:r,rowIndex:0,colIndex:0,node:null,depth:0,activeNames:new Set,implicitIntersect:!1,firstCell:!1,perCellRead:!1,drawIndex:0},i}getFunction(e){let t=OC(e.toUpperCase());if(t!==void 0){let e=this._functions.getByName(t);if(e&&!e.isLambda())return e}let n=this._functions.getByName(e);return n?.isLambda()?null:n}getNumberFormat(e,t){return wu.getEngine().format(e,t,{date1904:this.getRuntime().isDate1904(),locale:this.getRuntime().getLocale()}).text}getEntireCoords(){return this._container.getGrid(this._calcScope.gridId)?.getEntireCoords()}getFormulaAt(e,t,n){let r=this._container,i;this._calcScope.perCellRead=!0,i=n?r.getSymbols().bind($.Sheet,n):this._calcScope.gridId;let a=r.getFormulas();if(!a)return null;CF.colStart=t,CF.rowStart=e,CF.colEnd=t,CF.rowEnd=e,CF.scope=i;let o=a.search(CF);return o.length===0?null:o[0].value.formula.getTextAt(e,t,!1,void 0,void 0,`display`)??null}markVolatile(){let e=this._container.getVolatiles();e&&e.add(this._calcScope.node)}formatResults(e){let t=this._calcScope.node;t&&(t.numFmt=e)}filterHidden(e,n){if(!(e?.isIReferenceRange&&e instanceof OW))return e;let r=e.getCoords(),i=this._gridIdOf(r),a=i?this._container.getGrid(i):null;if(!a||n?.onlyWhileFiltered&&!a.isFiltered())return e;let o=n?.axes,s=o===t.IRange.AxisSelection.Column?null:a.getHiddenSkip(t.IRange.Axis.Row,r.rowStart,r.rowEnd),c=o===t.IRange.AxisSelection.Column||o===t.IRange.AxisSelection.Both?a.getHiddenSkip(t.IRange.Axis.Column,r.colStart,r.colEnd):null;return s||c?e.clone({processRowSkip:s??void 0,processColumnSkip:c??void 0}):e}_gridIdOf(e){return e.scope?this._container.getSymbols().bind($.Sheet,e.scope):this._calcScope.gridId}filterTotals(e){let t=e;if(!t?.isIReferenceRange)return e;let n=t.getCoords(),r=this._container.getFormulas();if(!r||r.isEmpty())return e;let i=r.search({rowStart:n.rowStart,rowEnd:n.rowEnd,colStart:n.colStart,colEnd:n.colEnd,scope:this._gridIdOf(n)}),a=null;for(let e=0;e<i.length;e++){let t=i[e].value;if(!t?.hasTotals())continue;let r=t.ref;(a??=[]).push({rowStart:r.rowStart-n.rowStart,rowEnd:r.rowEnd-n.rowStart,colStart:r.colStart-n.colStart,colEnd:r.colEnd-n.colStart})}if(!a)return e;let o=a.length;return e.filter((e,t)=>{let n=t.rowIndex,r=t.colIndex;for(let e=0;e<o;e++){let t=a[e];if(n>=t.rowStart&&n<=t.rowEnd&&r>=t.colStart&&r<=t.colEnd)return!1}return!0})}getSheetIndex(e){let t;if(this._calcScope.perCellRead=!0,typeof e==`string`)t=e;else{let n=e?.getCoords()?.scope;if(n)t=n;else{let e=this._container.getSymbols().resolve($.Sheet,this._calcScope.gridId);t=e?e.getName?e.getName()??void 0:e.toString():void 0}}return this._container.getSheetIndex?.(t)??-1}getSheetCount(){return this._container.getSheetCount?.()??1}isValidDate(e,t=!1){return Xc(e,t)}fromSerialDate(e,t=!1){return dl(t?Math.floor(e):e,this.getRuntime().isDate1904())}toSerialDate(e,t=!1){let n=fl(e,this.getRuntime().isDate1904());return t?Math.floor(n):n}getDateParts(e,n){let r=cl(e,this.getRuntime().isDate1904(),n);if(r===null)throw t.FormulaError.BuiltIn.Num;return r}getSerialDate(e,t,n,r=0,i=0,a=0,o=0){return ul({year:e,month:t,day:n,hour:r,minute:i,second:a,millis:o,dow:-1,serial:0},this.getRuntime().isDate1904())}getNow(){return fl(new Date(this.getRuntime().getNow()),this.getRuntime().isDate1904())}getRandom(){let e=this._calcScope;e.perCellRead=!0;let t=e.drawIndex++;if(t===0){let t=this._container.getCycleId();t!==this._passCycleId&&(this._passCycleId=t,this._passSeed=Math.floor(this.getRuntime().getRandom()*yF));let r=e.gridId;if(r!==this._gridKeyId){this._gridKeyId=r;let e=r===null?null:this._container.getSymbols().resolve($.Sheet,r),t=e?.getName?e.getName():null;this._gridKey=t?(0,n.hashText)(t):0}}return(0,n.keyedRandom)(this._passSeed,this._gridKey,e.rowIndex,e.colIndex,t)}compare(e,t,n){return sa.compare(e,t,this.getRuntime().getLocaleProfile(),n)}_fromTuples(e,t=null,n=!1,r=!1){if(!e)return null;let i=zr(e.bounds,!0),a=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),o=new ni({axis:this._axis,maxCoords:a});o.setValues(e.tuples);let s=t?{type:t}:void 0;return new iW(this._runtime,o,i,s,n,r)}getValueAt(e,r,i=null,a){let o=this._container,s=this._calcScope,c,l;if(c=i?o.getSymbols().bind($.Sheet,i):s.gridId,!c||xC(c))return t.FormulaError.BuiltIn.Ref;let u=s.node,d=u?IP(u):n.CommonUtils.EmptyArray,f=d.length;for(let n=0;n<f;n++){let i=d[n];if(!i||t.FormulaError.isError(i))continue;let o=i;if(e<o.rowStart||e>o.rowEnd||r<o.colStart||r>o.colEnd||o.scope&&c!==o.scope)continue;let s=HP(u,n);if(s!==void 0)if(s!==null&&s.isIRange){let t=s,n=e-o.rowStart,i=r-o.colStart;n>=0&&i>=0&&n<t.getRowCount()&&i<t.getColumnCount()&&(l=t.getValueAt(n,i,a))}else l=s;break}return l===void 0&&(this._onRead?.(c,e,r,e,r),l=o.getGridValues(c)?.getValueAt(e,r)??null),a&&a.type,l}getSpillAt(e,t,n){let r=this._container,i=this._calcScope,a;a=n?r.getSymbols().bind($.Sheet,n):i.gridId;let o=a===i.gridId?null:a,s=r.getIncrementalUpdates(a)?.spillSpatial??r.getGrid(a)?.getSpills();if(s){wF.rowStart=e,wF.colStart=t,wF.rowEnd=e,wF.colEnd=t,wF.scope=a;let n=s.search(wF),r=n.length;for(let i=0;i<r;i++){let r=n[i];if(r.rowStart===e&&r.colStart===t)return this.getReference({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:o})}if(r>0)return null}return this.getFormulaAt(e,t,n)===null?null:this.getReference({colStart:t,rowStart:e,colEnd:t,rowEnd:e,scope:o})}createRange(e=0,t=0,n=null){let r=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),i=r&&(e>r.rowEnd+1||t>r.colEnd+1)?{...r,rowEnd:Math.max(r.rowEnd,e-1),colEnd:Math.max(r.colEnd,t-1)}:r,a=new ni({axis:this._axis,maxCoords:i}),o=new iW(this._runtime,a,null,void 0,!1);return e>0&&t>0&&(typeof n==`function`?(o=o.resize(e,t),o=o.map(n,EF)):Array.isArray(n)?(o=o.replace(n),o=o.resize(e,t)):o=n==null?o.resize(e,t):new iW(this._runtime,a,{colStart:0,rowStart:0,colEnd:t-1,rowEnd:e-1},void 0,!1,!1,n)),o}flattenAreas(e){if(!Array.isArray(e))return e;let t=[];for(let n=0;n<e.length;n++){let r=e[n],{rows:i,columns:a}=r.getShape();for(let e=0;e<i;e++)for(let n=0;n<a;n++)t.push(r.getValueAt(e,n))}return this.createRange(t.length,1,(e,n)=>t[n.rowIndex])}getRange(e,r=null,i=!1){if(e===null)return null;if(e?.isIRange){if(r!==e.getType()||i!==e._isLiteralArray()){let t=typeof r==`string`?{type:r}:r;return e.clone(t,i,e._isDirectScalarBox())}return e}let a,o=Array.isArray(e);if(i??=o,!o&&e!==void 0){let t=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords();return new iW(this._runtime,new ui(e,{axis:this._axis,maxCoords:t}),{colStart:0,rowStart:0,colEnd:0,rowEnd:0},r?{type:r}:void 0,i,!0)}if(Array.isArray(e[0]))a=e;else{if(e[0]?.isIRange)throw t.FormulaError.BuiltIn.Value;a=[e]}let s=this._axis,c=s===t.IRange.Axis.Column,l=this._fromTuples(Yr(a,c,Rr(0,0,void 0,void 0,c),!0),r,i,!o);if(l)return l;let u=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),d=new ni({axis:s,maxCoords:u}),f=r?{type:r}:void 0;return new iW(this._runtime,d,n.CoordUtils.EmptyRange,f,i)}getRow(){let e=this._calcScope;return e.perCellRead=!0,e.rowIndex}getColumn(){let e=this._calcScope;return e.perCellRead=!0,e.colIndex}isImplicitIntersect(){let e=this._calcScope;return!e.node?.ext?.fixedRef&&!e.node?.block.arrayFirstCell&&e.implicitIntersect}_takeFirstCell(){let e=this._calcScope,t=e.firstCell;return e.firstCell=!1,t}getReference(e,n){if(!e)throw t.FormulaError.BuiltIn.Ref;let r=this._calcScope,i=this._container,a=r.gridId,o=i.getGrid(a),s=o?.getShadowOf();if(s&&s!==a){let e=i.getGrid(s);e&&(a=s,o=e)}let c=o?.getEntireCoords.bind(o);if(typeof e==`string`){let i=c?.(),a;try{let r=Td(e,i,bd,()=>{throw t.FormulaError.BuiltIn.Ref},n);if(r.length>1)throw t.FormulaError.BuiltIn.Ref;a=r[0]}catch{throw t.FormulaError.BuiltIn.Ref}if(n){let e=r.rowIndex,n=r.colIndex;if(a={rowStart:a.$rowStart?a.rowStart:a.rowStart+e,rowEnd:a.$rowEnd?a.rowEnd:a.rowEnd+e,colStart:a.$colStart?a.colStart:a.colStart+n,colEnd:a.$colEnd?a.colEnd:a.colEnd+n,scope:a.scope},a.rowStart<0||a.colStart<0||a.rowEnd<0||a.colEnd<0||i&&(a.rowEnd>i.rowEnd||a.colEnd>i.colEnd))throw t.FormulaError.BuiltIn.Ref}a.rowStart>a.rowEnd&&(a={...a,rowStart:a.rowEnd,rowEnd:a.rowStart}),a.colStart>a.colEnd&&(a={...a,colStart:a.colEnd,colEnd:a.colStart}),e=a}else e||={colStart:r.colIndex,rowStart:r.rowIndex,colEnd:r.colIndex,rowEnd:r.rowIndex};if(!e)throw t.FormulaError.BuiltIn.Ref;let l=e.scope;if(l){if(l=i.getSymbols().bind($.Sheet,e.scope),!l)return t.FormulaError.BuiltIn.Ref;let n=i.getSheetSpanIds?.(l)??null;if(n){let t=[];for(let r=0;r<n.length;r++)t.push(this.getReference({...e,scope:n[r]}));return t.isSheetSpan=!0,t}if(l!==e.scope&&((e={...e}).scope=l),l!==a){if(a=l,o=i.getGrid(a),!o)return t.FormulaError.BuiltIn.Ref;c=o?.getEntireCoords.bind(o)}}let u=i.getGridValues(a),d,f=r.node,p=-1;if(f&&(p=SF(IP(f),e)),p!==-1){let n=HP(f,p);if(n!=null&&n.isIReferenceRange)d=n;else if(n===void 0||u.isPendingOverlay)d=this._toReference(u,e,c,a,!1,bF(u,o));else{let r=n;r!==null&&r.isIRange&&(r=r.getValueAt(0,0));let i=new ni({axis:this._axis,maxCoords:c?.()});if(r!==null){let n=this._axis===t.IRange.Axis.Column,a=n?e.colStart:e.rowStart,o=n?e.rowStart:e.colStart;i.setValues([[a,[[o,[r]]]]])}d=this._toReference(i,e,c,a,!1,null)}}else{let t=e.scope?e:{...e,scope:a};i.addDynamicPrecedent(f,t,fI.Reference),d=this._toReference(u,e,c,a,!0,bF(u,o))}return d}_expandSheetSpan(e){if(typeof e!=`object`||!e||!0===e.isIRange)return null;let t=e;if(t.colStart===void 0||!xC(t.scope))return null;let n=this._container.getSheetSpanIds?.(t.scope)??null;if(!n)return null;let r=[];for(let e=0;e<n.length;e++)r.push({...t,scope:n[e]});return r.isSheetSpan=!0,r}getResizedReference(e,t,n){let r=this._gridIdOf(e),i=r?this._container.getGrid(r)?.getEntireCoords():void 0,a=e.rowStart+t-1,o=e.colStart+n-1;return this.getReference({rowStart:e.rowStart,rowEnd:i?Math.min(a,i.rowEnd):a,colStart:e.colStart,colEnd:i?Math.min(o,i.colEnd):o,scope:e.scope})}_toReference(e,r,i,a,o,s){let c=this._onRead??(o?this._dynamicRead:null);c&&(e=new vF(e,a,c));try{let t=new OW(this._runtime,e,r,void 0,i,this._container.resolveScope);return t._setCoordsReadHook(this._positionRead),s!==null&&t._setErrorIndex(c===null?s:{hasErrorIn:e=>(c(a,e.rowStart,e.colStart,e.rowEnd,e.colEnd),s.hasErrorIn(e))}),t}catch(e){throw e instanceof n.OutOfBoundsError?t.FormulaError.BuiltIn.Ref:e}}getAddress(e,t=!1){e||=(this._calcScope.perCellRead=!0,TF.rowIndex=this._calcScope.rowIndex,TF.colIndex=this._calcScope.colIndex,TF.scope=null,TF);let n=this.getEntireCoords().scope;return e.colIndex===void 0?function(e,t,n=!1){return(n?Rd({colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart,$rowIndex:e.$rowStart,scope:e.scope},t):md({colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart,$rowIndex:e.$rowStart,scope:e.scope},t))+`:`+(n?Rd({colIndex:e.colEnd,rowIndex:e.rowEnd,$colIndex:e.$colEnd,$rowIndex:e.$rowEnd},null):md({colIndex:e.colEnd,rowIndex:e.rowEnd,$colIndex:e.$colEnd,$rowIndex:e.$rowEnd},null))}(e,n,t):function(e,t,n=!1){return n?Rd(e,t):md(e,t)}(e,n,t)}parseAsSerialDate(e,n){if(e===void 0)return;if(typeof e==`number`)return e;if(t.FormulaError.isError(e))throw e;if(typeof e!=`string`)throw t.FormulaError.BuiltIn.Value;let r=Ll(this._runtime,e,n);if(r===null)throw t.FormulaError.BuiltIn.Value;return r}parseAsDate(e,n){if(e!==void 0){if(t.FormulaError.isError(e))throw e;if(typeof e==`number`)return this.fromSerialDate(e);if(typeof e==`string`)return this.fromSerialDate(this.parseAsSerialDate(e,n));if(e instanceof Date)return e;throw t.FormulaError.BuiltIn.Value}}parseAsNumber(e,n){if(e===void 0)return;if(typeof e==`number`)return e;if(t.FormulaError.isError(e))throw e;if(typeof e!=`string`)throw t.FormulaError.BuiltIn.Value;let r=this._coerceToNumber(e,t.ScalarType.String,n);if(typeof r!=`number`)throw t.FormulaError.BuiltIn.Value;return r}createCriteria(e,t){return fF(this,e,t)}parseAsLiteral(e){return Ti(e)??Ei(e)}toText(e){return function(e,t){return typeof e==`string`?e:e==null?``:typeof e==`boolean`?Ci(e):typeof e==`number`?UH(e,t):e?.isFormulaError?wi(e):String(e)}(e,this._runtime)}getRuntime(){return this._runtime}getArgs(){return t.FormulaContext.getArgs()}get[Symbol.toStringTag](){return`[CalculationContext]`}toString(){let e=``,t=this._instanceScope,n;return t&&(n=t.toString?.()),n&&n&&(e=`${e}:[${n}]`),e}},SF=(e,n)=>{if(!e)return-1;let r=e.length;if(r===0)return-1;let i=n.colStart,a=n.rowStart,o=n.colEnd,s=n.rowEnd,c=n.scope;for(let n=0;n<r;n++){let r=e[n];if(r!=null&&!(t.FormulaError.isError(r)||r.colStart!==i||r.rowStart!==a||r.colEnd!==o||r.rowEnd!==s||c&&r.scope!==c))return n}return-1},CF={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},wF={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},TF={rowIndex:0,colIndex:0,scope:null},EF=Object.freeze({includeEmpty:!0}),DF={a0:0,a1:0,f0:!1,f1:!1},OF={a0:0,a1:0,f0:!1,f1:!1},kF=0,AF=0,jF={colStart:0,rowStart:0,colEnd:0,rowEnd:0},MF={colStart:0,rowStart:0,colEnd:0,rowEnd:0},NF=[],PF=[],FF=[],IF=[],LF=[],RF=[],zF=(e,t)=>!0===t||e===-(2**53-1),BF=(e,t)=>!0===t||e===2**53-1,VF=(e,t,n,r,i,a,o)=>{if(n===i){if(t>r){let e=t;t=r,r=e}}else if(n?r+a<t:t+o>r)return!1;return e.a0=t,e.a1=r,e.f0=n,e.f1=i,!0},HF=(e,t,n,r,i)=>(e.f0&&(t=Math.max(t,e.a0)),e.f1&&(n=Math.min(n,e.a1)),!(t>n)&&(kF=Math.max(r,e.f1?r:t-e.a1),AF=Math.min(i,e.f0?i:n-e.a0),kF<=AF)),UF=(e,t,n)=>{kF=Math.max(0,e.a0+(e.f0?0:t)),AF=Math.max(0,e.a1+(e.f1?0:n))},WF=(e,t,n,r,i)=>{if(!HF(DF,t,r,i.rowStart,i.rowEnd))return;let a=kF,o=AF;HF(OF,e,n,i.colStart,i.colEnd)&&NF.push(kF,a,AF,o)},GF=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}),KF=e=>({touched:[GF(e)],blank:[]});function qF(e,n,r){let i=NF;i.length=0;let a=DF,o=OF,s=e.relative,c=e.second,l=s.length;for(let e=0;e<l;e++){let i=s[e];if(t.FormulaError.isError(i))continue;let l=c[e],u=l??i,d=i.scope??null,f=l===null?null:l.scope??null;if(d!==null&&f!==null&&d!==f)return KF(n);let p=d??f;if(!VF(a,i.rowStart,zF(i.rowStart,i.$rowStart),u.rowEnd,BF(u.rowEnd,u.$rowEnd),n.rowStart,n.rowEnd)||!VF(o,i.colStart,zF(i.colStart,i.$colStart),u.colEnd,BF(u.colEnd,u.$colEnd),n.colStart,n.colEnd))return KF(n);if(a.f0&&a.f1&&o.f0&&o.f1)continue;let m=r(p);if(m===null)return KF(n);let h=jF;UF(a,n.rowStart,n.rowEnd),h.rowStart=kF,h.rowEnd=AF,UF(o,n.colStart,n.colEnd),h.colStart=kF,h.colEnd=AF;let g=m.searchFormulas(h),_=g.length;for(let e=0;e<_;e++){let t=g[e];WF(Math.max(t.colStart,h.colStart),Math.max(t.rowStart,h.rowStart),Math.min(t.colEnd,h.colEnd),Math.min(t.rowEnd,h.rowEnd),n)}let v=m.values,y=v.getCoords();if(!y||!HF(a,y.rowStart,y.rowEnd,n.rowStart,n.rowEnd))continue;let b=kF,x=AF;if(!HF(o,y.colStart,y.colEnd,n.colStart,n.colEnd))continue;let S=kF,C=AF,w=MF;if(UF(a,b,x),w.rowStart=Math.max(kF,y.rowStart),w.rowEnd=Math.min(AF,y.rowEnd),UF(o,S,C),w.colStart=Math.max(kF,y.colStart),w.colEnd=Math.min(AF,y.colEnd),w.colStart>w.colEnd||w.rowStart>w.rowEnd)continue;let T=(v.getAxis?.()??t.IRange.Axis.Row)===t.IRange.Axis.Column,E=v.getRuns({bounds:w}),D=E.next();for(;!D.done;){let[e,t,r]=D.value;D=E.next();let i=t+r.length-1;T?WF(e,t,e,i,n):WF(t,e,i,e,n)}}return function(e,t){let n=e.length/4;if(n===0)return{touched:[],blank:[GF(t)]};let r=PF;r.length=0;for(let e=0;e<n;e++)r.push(e);r.sort(JF);let i=FF;i.length=0,i.push(t.rowStart,t.rowEnd+1);for(let t=0;t<n;t++)i.push(e[4*t+1],e[4*t+3]+1);i.sort(XF);let a=0;for(let e=0;e<i.length;e++)a!==0&&i[e]===i[a-1]||(i[a++]=i[e]);i.length=a;let o=[],s=[],c=IF;c.length=0;let l=0,u=LF,d=RF,f=!1,p=0,m=0,h=a-1;for(let a=0;a<h;a++){let h=i[a],g=i[a+1]-1;for(;l<n&&e[4*r[l]+1]<=h;)c.push(r[l++]);let _=0;for(let t=0;t<c.length;t++)e[4*c[t]+3]>=h&&(c[_++]=c[t]);c.length=_,c.sort(YF),u.length=0;for(let t=0;t<_;t++){let n=4*c[t],r=e[n],i=e[n+2],a=u.length-1;a>=0&&r<=u[a]+1?i>u[a]&&(u[a]=i):u.push(r,i)}if(f&&ZF(d,u)){for(let e=p;e<o.length;e++)o[e].rowEnd=g;for(let e=m;e<s.length;e++)s[e].rowEnd=g;continue}p=o.length,m=s.length;let v=t.colStart;for(let e=0;e<u.length;e+=2){let t=u[e],n=u[e+1];t>v&&s.push({colStart:v,rowStart:h,colEnd:t-1,rowEnd:g}),o.push({colStart:t,rowStart:h,colEnd:n,rowEnd:g}),v=n+1}v<=t.colEnd&&s.push({colStart:v,rowStart:h,colEnd:t.colEnd,rowEnd:g});let y=d;d=u,u=y,f=!0}return LF=u,RF=d,{touched:o,blank:s}}(i,n)}var JF=(e,t)=>NF[4*e+1]-NF[4*t+1],YF=(e,t)=>NF[4*e]-NF[4*t],XF=(e,t)=>e-t,ZF=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},QF=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.rowStart!==i.rowStart||r.rowEnd!==i.rowEnd||r.colStart!==i.colStart||r.colEnd!==i.colEnd)return!1}return!0},$F=(e,t,n)=>{let r=n.length;n.push(e);for(let e=0;e<t.length&&n.length>r;e++){let i=t[e];for(let e=n.length-1;e>=r;e--){let t=n[e];if(i.rowStart>t.rowEnd||i.rowEnd<t.rowStart||i.colStart>t.colEnd||i.colEnd<t.colStart)continue;n.splice(e,1);let r=Math.max(t.rowStart,i.rowStart),a=Math.min(t.rowEnd,i.rowEnd);i.rowStart>t.rowStart&&n.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:i.rowStart-1}),i.rowEnd<t.rowEnd&&n.push({colStart:t.colStart,rowStart:i.rowEnd+1,colEnd:t.colEnd,rowEnd:t.rowEnd}),i.colStart>t.colStart&&n.push({colStart:t.colStart,rowStart:r,colEnd:i.colStart-1,rowEnd:a}),i.colEnd<t.colEnd&&n.push({colStart:i.colEnd+1,rowStart:r,colEnd:t.colEnd,rowEnd:a})}}};function eI(e,t,n=0,r=0){let i=t.ref;e.forEachNode(e=>{let a=e.ext,o=a===null?null:a.fixedRef;if(!o)return;let s=e.rowIndex+r,c=e.colIndex+n;if(s<i.rowStart||s>i.rowEnd||c<i.colStart||c>i.colEnd)return;let l=t.nodeAt(s,c);FP(l).fixedRef=n===0&&r===0?o:{colStart:o.colStart+n,rowStart:o.rowStart+r,colEnd:o.colEnd+n,rowEnd:o.rowEnd+r}})}var tI={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},nI={colStart:0,rowStart:0,colEnd:0,rowEnd:0},rI={bounds:nI,reuseResult:!0},iI=(e,t)=>e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex,aI={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},oI=null,sI=null,cI={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},lI=e=>{let t=oI,n=e??sI;if(n===null)return null;let r=t.getGrid(n);if(r===null)return null;let i=r.getShadowOf();if(i!==null&&i!==n){if(r=t.getGrid(i),r===null)return null;n=i}let a=t.getFormulas();return{values:r.getValues(),searchFormulas:e=>(cI.colStart=e.colStart,cI.rowStart=e.rowStart,cI.colEnd=e.colEnd,cI.rowEnd=e.rowEnd,cI.scope=n,a.search(cI))}},uI=Object.freeze({tokens:Object.freeze([]),isReferenceOnly:!1}),dI=class e{setBlankShared(e){this.blankShared=e,this._blankSharedAgainst=e}constructor(e,t,n,r,i,a){this._nodes=null,this._sparse=!1,this._anchor=null,this.registeredPrecedents=null,this.paramLength=0,this._scratch=null,this._scratchCoords=null,this._scratchRow=-1,this._scratchCol=-1,this._touched=null,this._touchedCycleId=-1,this._touchedMarkId=-1,this._touchedMintedCycleId=-1,this._touchedMintedMarkId=-1,this.representative=null,this.blankValue=void 0,this.blankCycleId=-1,this.blankMarkId=-1,this.blankShared=null,this._blankSharedAgainst=null,this.blankRefused=!1,this.blankFallbackCycleId=-1,this.uncalculated=!1,this.ref=e,this.gridId=t,this._container=r,this.formula=n,this.unanchored=i;let o=t!==null&&!0===r.getGrid(t)?.isArrayFirstCell();this.arrayFirstCell=o,o&&n!==null&&n.demandFirstCell();let s=n?n.getPrecedentTemplate():null;this._template=s;let c=n!==null&&s!==null&&n.isBlankCacheable(o)&&(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1)>64;if(this._sparse=c,this.calcs=null,c){if(this.paramLength=s.relative.length,a){let n=this._newSparseStore();this._cloneSparse(a,t),this._anchor=n.getValueAt(e.rowStart,e.colStart)??null}}else if(a){let e=this._cloneDense(a,t);this.calcs=e,this._anchor=e[0][0]}else this.paramLength=s===null?n?.resolvedPrecedentsAt(e.rowStart,e.colStart)?.length??0:s.relative.length;if(a){for(let e=0;e<a.length;e++)if(a[e].block.uncalculated){this.uncalculated=!0;break}}}getNodeSource(){return[{block:this,originRow:0,originCol:0}]}isSparse(){return this._sparse}getAnchorNode(){let e=this._anchor;if(e!==null)return e;let t=this.ref,n=t.rowStart,r=t.colStart;if(this._sparse){let t=this._nodes??this._newSparseStore();e=t.getValueAt(n,r)??null,e===null&&(e=this._newNode(n,r,this.gridId,null),t.setValueAt(n,r,e))}else e=this.calcs===null?this._newNode(n,r,this.gridId,this._freshPrecedents(n,r)):this.calcs[0][0];return this._anchor=e,e}nodeAtOrNull(e,t){let n=this.ref;if(e<n.rowStart||e>n.rowEnd||t<n.colStart||t>n.colEnd)return null;let r=this._nodes;if(r!==null)return r.getValueAt(e,t)??null;let i=this.calcs;if(i!==null)return i[e-n.rowStart][t-n.colStart];let a=this._anchor;return a!==null&&a.rowIndex===e&&a.colIndex===t?a:null}nodeAt(e,t){let n=this.ref;if(e===n.rowStart&&t===n.colStart)return this.getAnchorNode();if(!this._sparse)return(this.calcs??this._mintDense())[e-n.rowStart][t-n.colStart];let r=this._nodes??this._newSparseStore(),i=r.getValueAt(e,t);return i===void 0&&(i=this._newNode(e,t,this.gridId,null),r.setValueAt(e,t,i)),i}_newSparseStore(){let e=new ni({axis:t.IRange.Axis.Column}),n=this._anchor;return n!==null&&e.setValueAt(n.rowIndex,n.colIndex,n),this._nodes=e,e}_mintDense(){let e=this._createCalcs(this.formula,this.gridId,this.ref),t=this._anchor;return t===null?this._anchor=e[0][0]:e[0][0]=t,this.calcs=e,e}_freshPrecedents(e,t){if(this._template!==null)return null;let r=this.formula;return r===null||this.paramLength===0?n.CommonUtils.EmptyArray:r.resolvedPrecedentsAt(e,t)}release(){this.calcs=null,this._nodes=null,this.representative=null,this._touchedMintedCycleId=-1,this._touchedMintedMarkId=-1}forEachNodeIn(e,t,n,r,i){let a=this.ref,o=Math.max(e,a.rowStart),s=Math.min(t,a.rowEnd);if(o>s)return;let c=Math.max(n,a.colStart),l=Math.min(r,a.colEnd);if(c>l)return;let u=this._nodes;if(u===null){let e=this.calcs;if(e===null){let e=this._anchor;e!==null&&e.rowIndex>=o&&e.rowIndex<=s&&e.colIndex>=c&&e.colIndex<=l&&i(e);return}for(let t=o;t<=s;t++){let n=e[t-a.rowStart];for(let e=c;e<=l;e++)i(n[e-a.colStart])}return}if(o===s&&c===l){let e=u.getValueAt(o,c);e!==void 0&&i(e);return}nI.rowStart=o,nI.rowEnd=s,nI.colStart=c,nI.colEnd=l;let d=u.entries(rI),f=d.next();for(;!f.done;){let e=f.value[1];f=d.next(),i(e)}}mintNodesIn(e,t,n,r,i){if(this._sparse){let i=this._nodes??this._newSparseStore(),a=this.ref,o=Math.max(e,a.rowStart),s=Math.min(t,a.rowEnd),c=Math.max(n,a.colStart),l=Math.min(r,a.colEnd);if(o>s||c>l)return;let u=this.gridId,d=null;for(let e=c;e<=l;e++)for(let t=o;t<=s;t++)i.getValueAt(t,e)===void 0&&(d===null&&(d=new z.Builder),d.pushAt(e,t,this._newNode(t,e,u,null)));if(d!==null){let e=d.build();e&&i.setValues(e.tuples)}}else this.calcs===null&&this._mintDense();this.forEachNodeIn(e,t,n,r,i)}forEachNode(e){let t=this.ref;this.forEachNodeIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,e)}getPrecedentsAt(e,n){let r=this._template,i=this._scratchCoords,a=this._scratch;if(i===null||a===null){let e=r.relative.length;i=Array(e),a=Array(e);for(let t=0;t<e;t++){let e={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null};r.verticalAbs[t]&&(e.$rowStart=e.$rowEnd=!0),r.horizontalAbs[t]&&(e.$colStart=e.$colEnd=!0),i[t]=e}this._scratchCoords=i,this._scratch=a}else if(this._scratchRow===e&&this._scratchCol===n)return a;let o=r.relative,s=r.second,c=o.length;for(let r=0;r<c;r++){let c=o[r];if(t.FormulaError.isError(c)){a[r]=c;continue}let l=i[r],u=s[r];if(u===null){mM(c,e,n,l),a[r]=l;continue}mM(c,e,n,tI),mM(u,e,n,aI);let d=rf(tI,aI,l);a[r]=d??t.FormulaError.BuiltIn.Null}return this._scratchRow=e,this._scratchCol=n,a}isBlankAware(e){if(this.blankRefused||this.blankFallbackCycleId===e||this._template===null)return!1;let t=this.ref;if(t.rowEnd===t.rowStart&&t.colEnd===t.colStart)return!1;let n=this.formula;if(n===null||!n.isBlankCacheable(this.arrayFirstCell))return!1;let r=this.getAnchorNode().ext;return r===null||r.fixedRef===null}getTouched(e,t){let n=this._touched;if(n!==null&&this._touchedCycleId===e&&this._touchedMarkId===t)return n;oI=this._container,sI=this.gridId;try{n=qF(this._template,this.ref,lI)}finally{oI=null,sI=null}this._touched=n,this._touchedCycleId=e,this._touchedMarkId=t;let r=this.blankShared;if(r!==null&&!QF(this._blankSharedAgainst,n.blank)){let e=[];for(let t=0;t<r.length;t++)$F(r[t],n.touched,e);this.blankShared=e,this._blankSharedAgainst=n.blank}let i=n.blank;if(i.length===0)this.representative=null;else{let e=i[0];this.representative=this.nodeAt(e.rowStart,e.colStart)}return n}forEachTouchedNode(e,t,n){let r=this.getTouched(e,t),i=this._touchedMintedCycleId===e&&this._touchedMintedMarkId===t,a=r.touched;for(let e=0;e<a.length;e++){let t=a[e];i?this.forEachNodeIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,n):this.mintNodesIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,n)}this._touchedMintedCycleId=e,this._touchedMintedMarkId=t;let o=this.representative;o!==null&&n(o)}getTouchedCached(){return this._touched}getBlankRegion(){let e=this._touched;return this.blankRefused||this.blankCycleId===-1||e===null||e.blank.length===0?null:{value:this.blankValue,rects:e.blank}}getBlankValueWithin(e){let t=this.getBlankRegion();if(t===null)return null;let n=this.ref;return e.rowStart<n.rowStart||e.rowEnd>n.rowEnd||e.colStart<n.colStart||e.colEnd>n.colEnd?null:t.value??null}densify(){if(!this._sparse||(this._sparse=!1,this._nodes===null))return;let e=this.ref,t=e.rowStart,n=e.colStart,r=e.rowEnd-t+1,i=e.colEnd-n+1,a=rU(r);for(let e=0;e<r;e++)a[e]=rU(i);this.forEachNode(e=>{a[e.rowIndex-t][e.colIndex-n]=e});let o=this.gridId;for(let e=0;e<r;e++){let r=a[e];for(let a=0;a<i;a++)r[a]===null&&(r[a]=this._newNode(e+t,a+n,o,null))}this.calcs=a,this._nodes=null}_createCalcs(e,t,r){let i=r.colStart,a=r.rowStart;if(!e)return[[this._newNode(a,i,t,n.CommonUtils.EmptyArray)]];let o=this._template,s=o!==null,c=s?null:e.resolvedPrecedentsAt(a,i),l=s?o.relative.length:c?.length??0;this.paramLength=l;let u=rU(r.rowEnd-a+1),d=r.colEnd-i+1,f=u.length;for(let r=0;r<f;r++){let o=rU(d),f=o.length;for(let u=0;u<f;u++){let d=r+a,f=u+i,p=s?null:l===0?n.CommonUtils.EmptyArray:r===0&&u===0?c:e.resolvedPrecedentsAt(d,f);o[u]=this._newNode(d,f,t,p)}u[r]=o}return u}_newNode(e,t,r,i){return{block:this,gridId:r,colIndex:t,rowIndex:e,cycleId:0,markId:0,inDegree:0,orderIndex:-1,planId:0,planEpoch:0,dependentsEpoch:0,dependents:n.CommonUtils.EmptyArray,inputsAt:-1,precedents:i,cachedValue:void 0,numFmt:null,state:WP,ext:null}}_clonePrecedents(e,t,r){if(this._template!==null)return null;if(this.paramLength===0)return n.CommonUtils.EmptyArray;let i=this.ref;return e===i.rowStart&&t===i.colStart&&r?r:this.formula.resolvedPrecedentsAt(e,t)}_cloneNode(e,t,r,i,a){let o={...e};o.colIndex=r,o.rowIndex=t,o.block=this;let s=e.ext;if(s!==null){let i=s.fixedRef;if(i){let n=r-e.colIndex,a=t-e.rowIndex;n===0&&a===0||(i={colStart:i.colStart+n,rowStart:i.rowStart+a,colEnd:i.colEnd+n,rowEnd:i.rowEnd+a})}o.ext={spillDependents:n.CommonUtils.EmptyArray,spillRowEnd:-1,spillColEnd:-1,fixedRef:i,pendingPromise:s.pendingPromise,demandValue:s.demandValue,cycleGroup:s.cycleGroup,cycleNext:s.cycleNext,shownGroup:s.shownGroup}}return o.inputsAt=-1,o.precedents=a,o.orderIndex=-1,o.planId=0,o.planEpoch=0,o.dependentsEpoch=0,o.dependents=n.CommonUtils.EmptyArray,i!==void 0&&(o.gridId=i),o}_sourceNodeAt(e,t,n){for(let r=0;r<e.length;r++){let i=e[r],a=i.block.ref,o=i.block.nodeAtOrNull(a.rowStart+i.originRow+t,a.colStart+i.originCol+n);if(o!==null)return o}return null}_cloneDense(e,t){let n=this.formula,r=this.ref,i=r.rowStart,a=r.colStart,o=this._template!==null,s=o?null:n.resolvedPrecedentsAt(i,a);this.paramLength=o?this._template.relative.length:s?.length??0;let c=r.rowEnd-i+1,l=r.colEnd-a+1,u=rU(c),d=t===void 0?this.gridId:t;for(let n=0;n<c;n++){let r=rU(l);u[n]=r;for(let o=0;o<l;o++){let c=n+i,l=o+a,u=this._clonePrecedents(c,l,s),f=this._sourceNodeAt(e,n,o);r[o]=f===null?this._newNode(c,l,d,u):this._cloneNode(f,c,l,t,u)}}return u}_cloneSparse(e,t){let n=this.ref,r=n.rowEnd-n.rowStart+1,i=n.colEnd-n.colStart+1,a=[];for(let o=0;o<e.length;o++){let s=e[o],c=s.block.ref,l=n.rowStart-c.rowStart-s.originRow,u=n.colStart-c.colStart-s.originCol;s.block.forEachNode(e=>{let o=e.rowIndex+l,s=e.colIndex+u,c=o-n.rowStart,d=s-n.colStart;c<0||c>=r||d<0||d>=i||a.push(this._cloneNode(e,o,s,t,null))})}if(a.length===0)return;a.sort(iI);let o=new z.Builder;for(let e=0;e<a.length;e++){let t=a[e];e>0&&a[e-1].rowIndex===t.rowIndex&&a[e-1].colIndex===t.colIndex||o.pushAt(t.colIndex,t.rowIndex,t)}let s=o.build();s&&this._nodes.setValues(s.tuples)}toJSON(e=!1,t=this.ref){let n=t;return[fd(n),this.formula.getTextAt(n.rowStart,n.colStart,e)]}getCoords(){return this.ref}getShifted(r){if(!r.after)return null;let i=n.CoordUtils.sanitizeRange(r.after),a=r.axis!==t.IRange.Axis.Row,o=r.amount,s=r.intersect,c=s.colStart,l=s.rowStart,u=s.colEnd,d=s.rowEnd,f=a?o:0,p=a?0:o,m=this.ref,h=i,g=this._container.getGrid(this.gridId)?.getEntireCoords(),_=this.formula,v=_.getReferences(m.rowStart,m.colStart);for(let e=0;e<v.length;e++){let n=v[e];if(n===null||`nameId`in n||`tableId`in n||t.FormulaError.isError(n))continue;let r=n,i=r.scope!=null&&r.scope!==this.gridId,s=r,y=r.$colStart?r.colStart:m.colStart+r.colStart,b=r.$rowStart?r.rowStart:m.rowStart+r.rowStart;if(!i&&y>u&&!r.$colStart&&!r.$colEnd)continue;let x=r.$colEnd?r.colEnd:m.colStart+r.colEnd,S=r.$rowEnd?r.rowEnd:m.rowStart+r.rowEnd;if(i)f!==0&&(r.$colStart||(s={...r},s.colStart=y-h.colStart),r.$colEnd||(s=s===r?{...r}:s,s.colEnd=x-h.colStart)),p!==0&&(r.$rowStart||(s=s===r?{...r}:s,s.rowStart=b-h.rowStart),r.$rowEnd||(s=s===r?{...r}:s,s.rowEnd=S-h.rowStart)),s!==r&&(_=_.setReferenceAt(e,s));else{if(o<0){if(a){if(y>=c&&x<=u){_=_.setReferenceAt(e,null);continue}}else if(b>=l&&S<=d){_=_.setReferenceAt(e,null);continue}}f!==0&&(r.$colStart?y>=c&&(s=s===r?{...r}:s,s.colStart+=f,y=s.colStart):y<c?(s=s===r?{...r}:s,s.colStart=y-h.colStart,y=h.colStart+s.colStart):f<0&&y<=u&&(s=s===r?{...r}:s,y=Math.max(c,y+f),s.colStart=y-h.colStart,y=h.colStart+s.colStart),r.$colEnd?x>=c&&(s=s===r?{...r}:s,s.colEnd+=f,x=s.colEnd):x<c?(s=s===r?{...r}:s,s.colEnd=x-h.colStart,x=h.colStart+s.colEnd):f<0&&x<=u&&(s=s===r?{...r}:s,x=Math.max(c-1,x+f),s.colEnd=x-h.colStart,x=h.colStart+s.colEnd)),p!==0&&(r.$rowStart?b>=l&&(s=s===r?{...r}:s,s.rowStart+=p,b=s.rowStart):b<l?(s=s===r?{...r}:s,s.rowStart=b-h.rowStart,b=h.rowStart+s.rowStart):p<0&&b<=d&&(s=s===r?{...r}:s,b=Math.max(l,b+p),s.rowStart=b-h.rowStart,b=h.rowStart+s.rowStart),r.$rowEnd?S>=l&&(s=s===r?{...r}:s,s.rowEnd+=p,S=s.rowEnd):S<l?(s=s===r?{...r}:s,s.rowEnd=S-h.rowStart,S=h.rowStart+s.rowEnd):p<0&&S<=d&&(s=s===r?{...r}:s,S=Math.max(l-1,S+p),s.rowEnd=S-h.rowStart,S=h.rowStart+s.rowEnd)),s!==r&&((x<y||S<b||g&&(y<g.colStart||b<g.rowStart||x>g.colEnd||S>g.rowEnd))&&(s=t.FormulaError.BuiltIn.Ref),_=_.setReferenceAt(e,s))}}let y=new e(i,this.gridId,_,this._container,this.unanchored,this.getNodeSource());return{...r.after,value:y}}getMerged(n,r,i){let a=this.formula,o=n.formula;if(!a.isEquals(o))return;let s=this.ref,c=[{block:this,originRow:0,originCol:0},i===t.IRange.Axis.Row?{block:n,originRow:-(s.rowEnd-s.rowStart+1),originCol:0}:{block:n,originRow:0,originCol:-(s.colEnd-s.colStart+1)}];return new e(r,this.gridId,a,this._container,this.unanchored,c)}getSplit(n,r,i){let a=this.formula,o=r===t.IRange.Axis.Column,s=[{block:this,originRow:0,originCol:0}],c=[{block:this,originRow:o?0:i,originCol:o?i:0}];return[new e(n[0],this.gridId,a,this._container,this.unanchored,s),new e(n[1],this.gridId,a,this._container,this.unanchored,c)]}copyTo(n,r){let i=this.formula,a=r?.cutFrom;if(a){let e=this.ref,r=e.colStart-n.colStart,o=e.rowStart-n.rowStart,s=i.getReferences(e.rowStart,e.colStart);for(let n=0;n<s.length;n++){let c=s?s[n]:null;if(!c||`nameId`in c||t.FormulaError.isError(c))continue;let l=c,u,d=l.$colStart?l.colStart:e.colStart+l.colStart,f=l.$rowStart?l.rowStart:e.rowStart+l.rowStart,p=l.$colEnd?l.colEnd:e.colEnd+l.colEnd,m=l.$rowEnd?l.rowEnd:e.rowEnd+l.rowEnd,h=l.scope!=null&&l.scope!==this.gridId,g=!h&&f>=a.rowStart&&m<=a.rowEnd,_=!h&&d>=a.colStart&&p<=a.colEnd;r!==0&&(l.$colStart||g&&d>=a.colStart&&d<=a.colEnd||(u??={...l},u.colStart+=r),l.$colEnd||g&&p>=a.colStart&&p<=a.colEnd||(u??={...l},u.colEnd+=r)),o!==0&&(l.$rowStart||_&&f>=a.rowStart&&f<=a.rowEnd||(u??={...l},u.rowStart+=o),l.$rowEnd||_&&m>=a.rowStart&&m<=a.rowEnd||(u??={...l},u.rowEnd+=o)),u&&(i=i.setReferenceAt(n,u))}}let o=new e(n,this.gridId,i,this._container,this.unanchored);return eI(this,o,n.colStart-this.ref.colStart,n.rowStart-this.ref.rowStart),{colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:n.scope,value:o}}canTile(e,t){return!0}onRemove(e){let t=e.value;t.forEachNode(e=>{let t=e.ext;t!==null&&t.pendingPromise&&(t.pendingPromise.cancelled=!0)}),t.release()}evaluateAt(e,n,r){return this.formula?.evaluateAt(e,n,r)??t.FormulaError.BuiltIn.NA}finalizeValue(e){return this.formula?.finalizeValue(e)??e}finalizeValueForCell(e){return this.formula?.finalizeValueForCell(e)??e}getTokensAt(e,t,r){return this.formula?.getTokensAt(e,t,r)??n.CommonUtils.EmptyArray}getTextAt(e,t,n,r,i){return this.formula?.getTextAt(e,t,n,r,i)??``}getNode(){return this.formula?.getNode()??null}resolvedPrecedentsAt(e,t,r,i,a){return this.formula?.resolvedPrecedentsAt(e,t,r,i,a)??n.CommonUtils.EmptyArray}getPrecedentTemplate(){return this._template}getReferences(e,t){return this.formula?.getReferences(e,t)??n.CommonUtils.EmptyArray}getReferencesAt(e,t){return this.formula?.getReferencesAt(e,t)??n.CommonUtils.EmptyArray}getFormatReferences(){return this.formula?.getFormatReferences()??n.CommonUtils.EmptyArray}getReferenceAt(e,t,n){return this.formula?.getReferenceAt(e,t,n)??null}setReferenceAt(n,r,i){let a=this.ref;if(r&&!t.FormulaError.isError(r)&&!(`nameId`in r)){let e=r,t=a.colStart,n=a.rowStart,i=e.$colStart?e.colStart:t+e.colStart,o=e.$rowStart?e.rowStart:n+e.rowStart,s=e.$colEnd?e.colEnd:t+e.colEnd,c=e.$rowEnd?e.rowEnd:n+e.rowEnd;if(s<i||c<o)r=null;else{let e=this._container.getGrid(this.gridId)?.getEntireCoords();e&&(i<e.colStart||o<e.rowStart||s>e.colEnd||c>e.rowEnd)&&(r=null)}}let o=this.formula.setReferenceAt(n,r,i);return new e(a,this.gridId,o,this._container,this.unanchored,this.getNodeSource())}remint(){return new e(this.ref,this.gridId,this.formula,this._container,this.unanchored,this.getNodeSource())}reanchorReferences(t,n){let r=this.formula,i=r.reanchorReferences(t,n);return r===i&&this.gridId===t?this:new e(this.ref,t,i,this._container,this.unanchored,this.getNodeSource())}replaceScopeIds(t,n){let r=this.formula,i=r.replaceScopeIds(t,n);return r===i?this:new e(this.ref,this.gridId,i,this._container,this.unanchored,this.getNodeSource())}wrapImplicit(t,n,r){let i=this.formula,a=i.wrapImplicit(t,n,r);return i===a?this:new e(this.ref,this.gridId,a,this._container,this.unanchored,this.getNodeSource())}getError(){return this.formula?.getError()??null}getRecord(){return this.formula?.getRecord()??uI}getNamedIds(){return this.formula?.getNamedIds()??n.CommonUtils.EmptyArray}getReferencedSymbolIds(){return this.formula?.getReferencedSymbolIds()??n.CommonUtils.EmptyArray}hasTotals(){return this.formula?.hasTotals()??!1}isBlankCacheable(e=this.arrayFirstCell){return this.formula?.isBlankCacheable(e)??!1}demandFirstCell(){this.formula?.demandFirstCell()}isReferenceOnly(){return this.formula?.isReferenceOnly()??!1}isEquals(e){return this.formula?.isEquals(e)??!1}},fI={Reference:-1,Spill:-2};function pI(e,t){return e.colStart===t.colStart&&e.rowStart===t.rowStart}function mI(e,t,n){return!!n&&e===n.rowStart&&t===n.colStart}function hI(e,t,n){if(!t)return;let r=t.length;for(let i=0;i<r;i++){let[r,a]=t[i],o=a.length;for(let t=0;t<o;t++){let[i,o]=a[t];e.isEmpty()||e.delete(yI(r,i,i+o.length-1,n)),bI(e,r,i,o,n)}}}var gI=(e,t,n,r,i)=>{let a=-1,o=-2;CI(r,(r,s)=>{r===o+1?o=s:(a!==-1&&e.push({...yI(t,n+a,n+o,i),value:!0}),a=r,o=s)}),a!==-1&&e.push({...yI(t,n+a,n+o,i),value:!0})};function _I(e,t){if(!e)return[];let n=[];for(let r=0;r<e.length;r++){let[i,a]=e[r];for(let e=0;e<a.length;e++)gI(n,i,a[e][0],a[e][1],t)}return n}function vI(e,t){e.isEmpty()||e.delete(t)}var yI=(e,t,n,r)=>r?{colStart:e,rowStart:t,colEnd:e,rowEnd:n}:{colStart:t,rowStart:e,colEnd:n,rowEnd:e},bI=(e,t,n,r,i)=>{CI(r,(r,a,o)=>{e.insertNonOverlapping({...yI(t,n+r,n+a,i),value:o})})},xI=_i.Type.Error,SI=1<<xI,CI=(e,n)=>{let r=-1,i=null;Ht.forEachLeaf(e,(e,a,o,s)=>{if(!0===e.isIRepeatingList&&e.getPeriod()===1){let s=e.at(a),c=t.FormulaError.isError(s)?s.getLabel():null;c!==i&&(i!==null&&n(r,o-1,i),r=o,i=c);return}let c=e.typeMask;if(c!==void 0&&(c&SI)===0)return i!==null&&n(r,o-1,i),void(i=null);let l=c===void 0?null:e;for(let c=o;c<=s;c++){let s=a+c-o,u=null;if(l===null||l.typeAt(s)===xI){let n=e.at(s);t.FormulaError.isError(n)&&(u=n.getLabel())}u!==i&&(i!==null&&n(r,c-1,i),r=c,i=u)}}),i!==null&&n(r,e.length-1,i)};function wI(e,r,i,a,o,s,c,l,u,d,f,p,m=!1,h){let g,_,v=null,y=o.size();p===void 0&&(p=s.getAxis()===t.IRange.Axis.Column);let b=r?r.length:0,x=i?i.length:0,S,C=b+x;for(let t=0;t<C&&y>0;t++){let d=t<b?r[t]:i[t-b],f=o.search(d),p=f.length;for(let t=0;t<p;t++){let r=f[t];if(!mI(r.rowStart,r.colStart,d)){if(r.value.getError()||r.value.isFixed())continue;S||=[],S.push(r)}o.remove(r,pI);let i=r.value;e!==-1&&e===i.getCycleId()||u?.(null,r),i.getError()||(s.delete(r),a.insertNonOverlapping({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:null},{onIntersect:(e,t)=>{if(e.value!==null)return c?.(e.colStart,e.rowStart,e.colEnd,e.rowEnd),v=n.CoordUtils.unionRanges(v,e),l?.insertNonOverlapping(e),v=n.CoordUtils.unionRanges(v,e),t}})),y--}}for(let e=0;e<b;e++){let t=r[e],i={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:t.scope,value:null};a.insertNonOverlapping(i,{onIntersect:(e,t)=>{if(e.value===null)return;let r=n.CoordUtils.sanitizeRange(t);return m&&l?.insertNonOverlapping(r),d?.insertNonOverlapping({...t,value:!1}),c?.(r.colStart,r.rowStart,r.colEnd,r.rowEnd),v=n.CoordUtils.unionRanges(v,r),t}}),h?.insertNonOverlapping(i),f?.insertNonOverlapping(i,{onIntersect:(e,t)=>{if(e.value!==null)return c?.(t.colStart,t.rowStart,t.colEnd,t.rowEnd),v=n.CoordUtils.unionRanges(v,t),t},onUpdates:(e,t,r)=>{_||=[];let i=e.length;for(let t=0;t<i;t++){let n=e[t];_.push(n)}g||=[];let a=t.length;for(let e=0;e<a;e++){let r=t[e],i=n.CoordUtils.sanitizeRange(r);g.push(i)}}})}let w=p?t.IRange.Axis.Column:t.IRange.Axis.Row;if(S){let t=S.length,r=rU(t);for(let i=0;i<t;i++){let t=S[i],o=t.value.setError(!0,e);u?.(o,null),r[i]=o,v=n.CoordUtils.unionRanges(v,t),a.insertNonOverlapping({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart,rowEnd:t.rowStart,value:new NP(t,w)}),c?.(t.colStart,t.rowStart,t.colEnd,t.rowEnd)}o.load(r)}for(let e=0;e<x;e++){let t=n.CoordUtils.sanitizeRange(i[e]);a.insertNonOverlapping({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,value:new NP(t,w)}),m&&l?.insertNonOverlapping(t),c?.(t.colStart,t.rowStart,t.colEnd,t.rowEnd),v=n.CoordUtils.unionRanges(v,t)}return v}function TI(e,t,n,r){let i=t?.block;if(!i)return;let a=n?.scope??t.gridId,o,s,c,l;n?(o=n.colStart,s=n.rowStart,c=n.colEnd,l=n.rowEnd):(o=t.colIndex,s=t.rowIndex,c=t.colIndex,l=t.rowIndex);let u=e.get(i);u||(u=[],e.set(i,u));for(let e=0;e<u.length;e++){let t=u[e],n=t.value;if(n.index!==r||t.scope!==a)continue;o<t.colStart&&(t.colStart=o),s<t.rowStart&&(t.rowStart=s),c>t.colEnd&&(t.colEnd=c),l>t.rowEnd&&(t.rowEnd=l);let i=n.formulaEntry;i.colStart=t.colStart,i.rowStart=t.rowStart,i.colEnd=t.colEnd,i.rowEnd=t.rowEnd;return}let d=i.ref;u.push({colStart:o,rowStart:s,colEnd:c,rowEnd:l,scope:a,value:{formulaEntry:{colStart:o,rowStart:s,colEnd:c,rowEnd:l,scope:a,value:i},formulaBlockWidth:d.colEnd-d.colStart+1,formulaBlockHeight:d.rowEnd-d.rowStart+1,index:r,$absColStart:!1,$absColEnd:!1,$absRowStart:!1,$absRowEnd:!1}})}var EI=(e,n,r,i=DI)=>{if(i.$absColStart=i.$absColEnd=n,i.$absRowStart=i.$absRowEnd=r,!n&&!r||!e||t.FormulaError.isError(e)||`nameId`in e)return i;let a=e;return n&&(a.$colStart||a.$colEnd)&&(i.$absColStart=!!a.$colStart,i.$absColEnd=!!a.$colEnd),r&&(a.$rowStart||a.$rowEnd)&&(i.$absRowStart=!!a.$rowStart,i.$absRowEnd=!!a.$rowEnd),i},DI={$absColStart:!1,$absColEnd:!1,$absRowStart:!1,$absRowEnd:!1};function OI(e,n,r=null){let i=e.colEnd-e.colStart,a=e.rowEnd-e.rowStart,o=e.value,s=o.formula,c=o.ref,l=c.rowStart,u=c.colStart,d=s.resolvedPrecedentsAt(l,u,!0,BI,VI),f=d.length,p=s.getReferences(l,u);for(let o=0;o<f;o++){let s=d[o];if(t.FormulaError.isError(s))continue;let c=EI(p[o],VI[o],BI[o]),l=c.$absColEnd,u=c.$absRowEnd,f={colStart:s.colStart,rowStart:s.rowStart,colEnd:s.colEnd+(l?0:i),rowEnd:s.rowEnd+(u?0:a),scope:s.scope??e.scope,value:{formulaEntry:e,formulaBlockWidth:i+1,formulaBlockHeight:a+1,index:o,$absColStart:c.$absColStart,$absColEnd:l,$absRowStart:c.$absRowStart,$absRowEnd:u}};r&&r.push(s),n.push(f)}}var kI=(e,t,n)=>{let r=e.search(t),i=r.length;if(i===0)return null;let a=[],o=[],s=[],c=[],l=new Set;for(let e=0;e<i;e++){let i=r[e],u=i.value,d=u.formulaEntry;if(i.colEnd===i.colStart&&i.rowEnd===i.rowStart||u.index<0)continue;if(l.has(d)){a.push(i);continue}let f=d.colEnd-d.colStart,p=d.rowEnd-d.rowStart,m=i.colStart,h=i.rowStart,g=i.colEnd,_=i.rowEnd,v=n({precedentEntry:i,precedentValue:u,formulaEntry:d,fw:f,fh:p,nw:u.$absColEnd?g-m+1:g-m-f+1,nh:u.$absRowEnd?_-h+1:_-h-p+1},t);if(!v)continue;l.add(d),a.push(i),o.push(d);let y=v.length;for(let e=0;e<y;e++)c.push(v[e]),OI(v[e],s)}return a.length===0?null:{precedents:{inserts:s,removes:a},formulas:{inserts:c,removes:o}}},AI=(e,t)=>{let{precedentEntry:n,precedentValue:r,formulaEntry:i,fw:a,fh:o,nw:s,nh:c}=e,l=[],u=[],d=(e,t,n)=>{t<=0||t>n||e.indexOf(t)===-1&&e.push(t)},f=r.$absColStart,p=r.$absColEnd,m=r.$absRowStart,h=r.$absRowEnd;if(!(a>0)||f&&p||(d(l,t.colStart-i.colStart,a),f||d(l,t.colStart-n.colStart,a),p||d(l,t.colStart-n.colStart-s+1,a)),!(o>0)||m&&h||(d(u,t.rowStart-i.rowStart,o),m||d(u,t.rowStart-n.rowStart,o),h||d(u,t.rowStart-n.rowStart-c+1,o)),l.length===0&&u.length===0)return null;l.sort((e,t)=>e-t),u.sort((e,t)=>e-t);let g=[i];if(u.length>0){g=[];let e=i;for(let t=0;t<u.length;t++){let n=i.rowStart+u[t];if(n<=e.rowStart||n>e.rowEnd)continue;let r=Tr(e,{rowStart:n,colStart:e.colStart,rowEnd:e.rowEnd,colEnd:e.colEnd},Ar);r&&r.length===2&&(g.push(r[0]),e=r[r.length-1])}g.push(e)}if(l.length>0){let e=[];for(let t=0;t<g.length;t++){let n=g[t];for(let t=0;t<l.length;t++){let r=i.colStart+l[t];if(r<=n.colStart||r>n.colEnd)continue;let a=Tr(n,{rowStart:n.rowStart,colStart:r,rowEnd:n.rowEnd,colEnd:n.colEnd},Ar);a&&a.length===2&&(e.push(a[0]),n=a[a.length-1])}e.push(n)}g=e}return g.length>1?g:null},jI=(e,t)=>{let{precedentEntry:n,precedentValue:r,formulaEntry:i,fw:a,fh:o,nh:s,nw:c}=e,l=n.rowStart,u=n.colStart,d=t.rowStart,f=t.rowEnd,p=t.colStart,m=t.colEnd,h=[];if(o>0&&(!r.$absRowStart||!r.$absRowEnd))if(s>1){let e=Math.max(0,d-l-s+1),t=Math.min(o+1,Math.max(0,d-l)),n=Math.min(o+1,Math.max(0,f-l-s+2)),r=Math.min(o+1,Math.max(0,f-l+1));for(let n=e;n<=t;n++)n>0&&n<=o&&h.push(n);for(let e=n;e<=r;e++)e>0&&e<=o&&(h.length!==0&&h[h.length-1]===e||h.push(e))}else{let e=d-l;e>0&&e<=o&&h.push(e);let t=f-l+1;t>0&&t<=o&&t!==e&&h.push(t)}let g=[];if(a>0&&(!r.$absColStart||!r.$absColEnd))if(c>1){let e=Math.max(0,p-u-c+1),t=Math.min(a+1,Math.max(0,p-u)),n=Math.min(a+1,Math.max(0,m-u-c+2)),r=Math.min(a+1,Math.max(0,m-u+1));for(let n=e;n<=t;n++)n>0&&n<=a&&g.push(n);for(let e=n;e<=r;e++)e>0&&e<=a&&(g.length!==0&&g[g.length-1]===e||g.push(e))}else{let e=p-u;e>0&&e<=a&&g.push(e);let t=m-u+1;t>0&&t<=a&&t!==e&&g.push(t)}if(h.length===0&&g.length===0)return null;let _=[i];if(h.length>0){_=[];let e=i;for(let t=0;t<h.length;t++){let n=i.rowStart+h[t];if(n<=e.rowStart||n>e.rowEnd)continue;let r=Tr(e,{rowStart:n,colStart:e.colStart,rowEnd:e.rowEnd,colEnd:e.colEnd},Ar);r&&r.length===2&&(_.push(r[0]),e=r[r.length-1])}_.push(e)}if(g.length>0){let e=[];for(let t=0;t<_.length;t++){let n=_[t];for(let t=0;t<g.length;t++){let r=i.colStart+g[t];if(r<=n.colStart||r>n.colEnd)continue;let a=Tr(n,{rowStart:n.rowStart,colStart:r,rowEnd:n.rowEnd,colEnd:n.colEnd},Ar);a&&a.length===2&&(e.push(a[0]),n=a[a.length-1])}e.push(n)}_=e}return _},MI=(e,t)=>{let{precedentEntry:n,precedentValue:r,formulaEntry:i,fw:a,fh:o,nw:s,nh:c}=e;if(a===0&&o===0)return null;let l=n.colStart,u=n.rowStart,d=r.$absRowStart?u>=t.rowStart?0:o+1:Math.max(0,t.rowStart-u),f=r.$absRowEnd?n.rowEnd<=t.rowEnd?o:-1:Math.min(o,t.rowEnd-u-(c-1)),p=r.$absColStart?l>=t.colStart?0:a+1:Math.max(0,t.colStart-l),m=r.$absColEnd?n.colEnd<=t.colEnd?a:-1:Math.min(a,t.colEnd-l-(s-1));if(d>f||p>m||d===0&&f===o&&p===0&&m===a)return null;let h=d>0?i.rowStart+d:-(2**53-1),g=f<o?i.rowStart+f:2**53-1,_=p>0?i.colStart+p:-(2**53-1),v=m<a?i.colStart+m:2**53-1;return LI.colStart=_,LI.rowStart=h,LI.colEnd=v,LI.rowEnd=g,Tr(i,LI,Ar)},NI=(e,t,n)=>{let r=e.colStart,i=e.rowStart,a=e.colEnd,o=e.rowEnd,s=t.colStart,c=t.rowStart,l=t.colEnd,u=t.rowEnd,d=Math.max(r,s),f=Math.max(i,c),p=Math.min(a,l),m=Math.min(o,u);e.value.mintNodesIn(f,m,d,p,e=>{n(e,e.rowIndex-i,e.colIndex-r)})};function PI(e,t,n,r){if(e.isEmpty())return;let i=e.search(t),a=i.length;for(let e=0;e<a;e++)i[e].value.checkShift(t,n,r)}function FI(e,r,i,a,o,s=!1,c=!1,l,u){if(!e||r.isEmpty())return null;II.colStart=e.colStart,II.rowStart=e.rowStart,II.colEnd=e.colEnd,II.rowEnd=e.rowEnd,II.scope=null;let d=r.search(II),f=d.length;if(!f)return null;let p,m,h;for(let t=0;t<f;t++){let o=d[t];if(zI.colIndex=o.colStart,zI.rowIndex=o.rowStart,zI.scope=o.scope,o.value.getError())continue;let s=n.CoordUtils.isCellWithinRange({colIndex:zI.colIndex,rowIndex:zI.rowIndex,scope:zI.scope},e);s&&c||(p||(m=[],p=[],h=i.clone()),s?p.push(o):m.push(o),i.delete(o),r.remove(o,HI),a.insertNonOverlapping({...o,value:null}))}return f?(e=!1,c,d)=>{let f=s?t.IRange.Axis.Row:t.IRange.Axis.Column,g=m?m.length:0;if(g>0){r.load(m);for(let e=0;e<g;e++){let t=m[e],r=n.CoordUtils.sanitizeRange(t);h.copyTo(i,{colIndex:r.colStart,rowIndex:r.rowStart},r),a.insertNonOverlapping({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:new NP(r,f)}),l?.insertNonOverlapping({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:t.scope,value:null}),u?.(r.colStart,r.rowStart,r.colStart,r.rowStart)}}let _=p?p.length:0;if(o)for(let e=0;e<_;e++)o(null,p[e]);if(!e||c===void 0&&d===void 0||_===0)return;c??=0,d??=0;let v=[];for(let e=0;e<_;e++){let t=p[e],n={colStart:t.colStart+d,rowStart:t.rowStart+c,colEnd:t.colEnd+d,rowEnd:t.rowEnd+c,scope:t.scope},r=t.value.getTranslated(c,d);v.push(t.value.getTranslated(c,d)),o?.(r,null),h.copyTo(i,{colIndex:n.colStart,rowIndex:n.rowStart},t),a.insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:new NP(n,f)})}r.load(v)}:null}var II={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},LI={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},RI={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},zI={colIndex:0,rowIndex:0,scope:null},BI=[],VI=[];function HI(e,t){return e.value===t.value}var UI,WI=e=>e.answer,GI=(e,t)=>{let n=e.formulaInserts;if(!n)return e;let r=Array(n.length);for(let e=0;e<n.length;e++){let i=n[e];r[e]={...i,value:new sM(i.value,t)}}return{...e,formulaInserts:r}},KI=e=>{switch(e.type){case`autoFill`:case`copyTo`:return e.commitId;case`create`:case`requestPass`:case`seed`:case`snapshot`:case`rollback`:case`calculate`:case`markDirty`:case`close`:case`setReference`:case`setReferenceMode`:case`toJSON`:case`evaluate`:case`graph`:case`isVolatile`:case`setBody`:return;case`revert`:return e.options.commitId;default:return e.options?.commitId}},qI=class{constructor(e){this._emitter=null,this._gridId=e.id,this._sendRequest=e.send,this._calculation=e.calculation??null,this._getEntireCoordsOf=e.getEntireCoords??null}_landingId(e){let t=e?.commitId,n=e?.cloneKey;return n!==void 0&&n!==t?n:t===void 0?void 0:`${t}:0`}_send(e,t){return this._sendRequest(this._gridId,e,t)}getId(){return this._gridId}getEntireCoords(){return this._getEntireCoordsOf()}resize(e){let t=this.getEntireCoords();this._send(this._landingId(e),{type:`resize`,entireCoords:{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd},options:e})}setHidden(e,t,n){this._send(this._landingId(n),{type:`hidden`,axis:e,runs:t,options:n})}setFiltered(e,t){this._send(this._landingId(t),{type:`filtered`,filtered:e,options:t})}addListeners(e,t){return this._emitter??=new x(this),this._emitter.addListeners(e,t)}setInputs(e,t,n){return this._setInputs(e,t,void 0,n)}remove(e,t){return this._setInputs(null,[{...e,scope:this._gridId,value:null}],{...e,scope:this._gridId},t)}_setInputs(e,t,n,r){return this._send(this._landingId(r),{type:`setInputs`,values:e,formulas:t,deleteRange:n,options:r})}shift(e){return this._send(this._landingId(e),{type:`shift`,options:e})}autoFill(e,t,n){return typeof e==`string`&&(e=Ad(e)),typeof t==`string`&&(t=Ad(t)),this._send(this._landingId(n),{type:`autoFill`,template:e,destination:t,commitId:n?.commitId})}calculate(e){return this._send(void 0,{type:`calculate`,full:e}).then(()=>this._calculation?.getStatus()??X.Status.Running)}requestPass(){this._send(void 0,{type:`requestPass`})}markDirtyRegions(e){let t=Array(e.length);for(let n=0;n<e.length;n++){let r=e[n];t[n]={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd},r.scope!==void 0&&(t[n].scope=r.scope)}this._send(void 0,{type:`markDirty`,coords:t})}delete(e){this._send(this._landingId(e),{type:`delete`,options:e})}revert(e){return this._send(void 0,{type:`revert`,options:e})}close(){this._send(void 0,{type:`close`})}seed(e,t){return this._send(void 0,{type:`seed`,json:e,options:t})}async toJSON(e){return WI(await this._send(void 0,{type:`toJSON`,options:e}))??null}getSnapshot(e){let t=this,r=`snap`+n.CommonUtils.uuidV4(),i=this._calculation?.getStatus();i!==X.Status.Running&&i!==X.Status.Starting||this._send(void 0,{type:`snapshot`,snapshotId:r});let a=Object.freeze({...e}),o=a.range;return typeof o==`string`&&(o=Ad(o)),o={...o},o.scope=t.getId(),{copyTo(e,n){let i=e.range;return typeof i==`string`&&(i=Ad(i)),t._sendRequest(e.gridId,t._landingId(n),{type:`copyTo`,sourceGridId:t._gridId,snapshotId:r,coords:o,destination:i,isCut:n?.isCut??a.isCut,fitDestination:n?.fitDestination,transpose:n?.transpose,commitId:n?.commitId})},getCoords:()=>o,getSource:()=>t,getName:()=>`Calculation`,getMarkOptions:()=>a,isISnapshot:!0}}async getGraphNeighborsAt(e,t,n){let r={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd};return e.scope!==void 0&&(r.scope=e.scope),WI(await this._send(void 0,{type:`graph`,kind:t,direct:n,coords:r}))??{cells:[],names:[]}}async getNameGraph(e,t){return WI(await this._send(void 0,{type:`graph`,kind:e,direct:t,asName:!0}))??{cells:[],names:[]}}async isVolatileAt(e,t){return WI(await this._send(void 0,{type:`isVolatile`,row:e,column:t}))??!1}async evaluateAt(e,t,n){await this._calculation?.ready();let r=typeof n==`number`?n:n?.evalIndex;return WI(await this._send(void 0,{type:`evaluate`,row:e,column:t,evalIndex:r}))??null}async evaluateScalarAt(e,t,n){return await this._calculation?.ready(),WI(await this._send(void 0,{type:`evaluate`,row:e,column:t,evalIndex:n,coerce:`scalar`}))??null}setBody(e){return this._send(void 0,{type:`setBody`,body:e})}setReferenceAt(e,n,r,i){let a=t.FormulaError.isError(i)?`#REF!`:i;return this._send(void 0,{type:`setReference`,row:e,column:n,index:r,precedent:a}).then(t=>JI(t,e,n))}setReferenceModeAt(e,t,n,r=`self`,i){return this._send(void 0,{type:`setReferenceMode`,row:e,column:t,index:n,side:r,mode:i}).then(n=>JI(n,e,t))}},JI=(e,t,n)=>{let r=e.formulaInserts;if(!r)return null;for(let e=0;e<r.length;e++){let i=r[e];if(t>=i.rowStart&&t<=i.rowEnd&&n>=i.colStart&&n<=i.colEnd)return i.value??null}return null};(function(e){class t extends Error{constructor(e,t,n){super(`The calc clone boundary could not send ${e}: `+(t.length?t.map(e=>`${e.path} is a ${e.type}`).join(`, `):String(n?.message??n))),this.name=`CloneBoundaryError`,this.violations=t}}e.BoundaryError=t;let n=`off`,r=null,i=null;e.setMode=e=>{n=e===`audit`||e===`clone`?e:`off`,n===`off`&&(r=null)},e.getMode=()=>n,e.setListener=e=>{i=e},e.getViolations=()=>r?Array.from(r.values()):[],e.clearViolations=()=>{r=null},e.request=(e,t)=>n===`off`?e:a(e,`request:${t}`,`request`),e.results=(e,t)=>n===`off`?e:a(e,`results:${t}`,`results`);let a=(e,r,i)=>{if(e==null)return e;let a=[];if(s(e,i,r,a,new Set),n===`audit`)return e;try{return structuredClone(e)}catch(e){throw new t(r,a,e)}},o=(e,t,n,a,o)=>{let s=`${t}|${n}|${a}|${o}`,c=r??=new Map;if(c.has(s))return void e.push(c.get(s));let l={where:t,path:n,kind:a,type:o};c.set(s,l),e.push(l),i?.(l)},s=(e,t,n,r,i)=>{if(e==null)return;let a=typeof e;if(a===`function`)return o(r,n,t,`function`,`function`);if(a===`symbol`)return o(r,n,t,`function`,`symbol`);if(a!==`object`)return;let c=e;if(i.has(c))return;if(i.add(c),Array.isArray(c)){for(let e=0;e<c.length;e++)s(c[e],`${t}[]`,n,r,i);return}if(c instanceof Date||c instanceof RegExp||c instanceof ArrayBuffer||ArrayBuffer.isView(c))return;if(c instanceof Map){for(let[e,a]of c)s(e,`${t}<key>`,n,r,i),s(a,`${t}<value>`,n,r,i);return}if(c instanceof Set){for(let e of c)s(e,`${t}<entry>`,n,r,i);return}let l=Object.getPrototypeOf(c);if(l===Object.prototype||l===null){let e=Object.keys(c);for(let a=0;a<e.length;a++)s(c[e[a]],`${t}.${e[a]}`,n,r,i);return}let u=c.constructor?.name??`anonymous`;if(c instanceof Error)return o(r,n,t,`downgraded`,u);o(r,n,t,`live`,u)}})(UI||={});var YI=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}),XI=class extends qI{constructor(e){let r=(e={...e}).container;super({id:e.uuid||`gen`+n.CommonUtils.uuidV4(),send:(e,t,n)=>r.sendRequest(e,t,n),calculation:e.calculation}),this._touchedOthers=null,this._iterationId=0,this._resized=null,this._hiddenRows=null,this._hiddenColumns=null,this._filtered=!1,this._isProcessingJSON=!1,this._snapshots=null,this._options=e,this._context=e.context,this._container=e.container;let i={...MH},a=e.getEntireCoords??(()=>i);if(this._getEntireCoords=a,this._unanchored=!0===e.unanchored,this._shadowOf=e.shadowOf??null,this._arrayFirstCell=!0===e.arrayFirstCell,!this._context||!this._container)throw Error(`Invalid Options`);let o=e?.onCalculated;this._onCalculated=o?e=>{o(GI(UI.results(e,`onCalculated`),this._container.getImager(this._gridId)))}:()=>{},this._values=new ni({axis:t.IRange.Axis.Column}),this._iterationId=0,this._contentfulSpatial=new yr({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}});let s={updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}};this._spillSpatial=new yr(s),this._errorSpatial=new yr(s),this._pendingSpatial=new yr(s),this._circularSpatial=new yr(s),this._notifyValues=new yr,this._notifyBlank=null,this._notifySpillsInsert=[],this._notifySpillsRemove=[],this._notifyFormats=new yr,this._notifyPending=new yr,this._notifyCircular=new yr,this._touchedFormulas=[],this._container.registerGrid(this),this._publishMaps()}_land(e,t){return this._container.landRequest(e,()=>(e!==void 0&&this._versionMaps(e),t()))}_versionMaps(e){this._values=this._values.clone(e),this._contentfulSpatial=this._contentfulSpatial.clone(e),this._spillSpatial=this._spillSpatial.clone(e),this._errorSpatial=this._errorSpatial.clone(e),this._pendingSpatial=this._pendingSpatial.clone(e),this._circularSpatial=this._circularSpatial.clone(e),this._publishMaps()}_publishMaps(){this._container.setGridMaps(this._gridId,{values:this._values,contentful:this._contentfulSpatial,spills:this._spillSpatial,errors:this._errorSpatial,pending:this._pendingSpatial,circular:this._circularSpatial,entireCoords:this._resized,hiddenRows:this._hiddenRows,hiddenColumns:this._hiddenColumns,filtered:this._filtered})}_adoptMaps(e){this._values=e.values,this._contentfulSpatial=e.contentful,this._spillSpatial=e.spills,this._errorSpatial=e.errors,this._pendingSpatial=e.pending,this._circularSpatial=e.circular,this._resized=e.entireCoords??null,this._hiddenRows=e.hiddenRows??null,this._hiddenColumns=e.hiddenColumns??null,this._filtered=e.filtered??!1}_touchFormulas(e){if(!e)return;let t=this._gridId,n=this._container;for(let r=0;r<e.length;r++){let i=e[r],a=i.scope??t,o=a===t?this:n.getGrid(a),s=YI(i);o?._touchedFormulas.push(s),o&&o!==this&&o._holdsBody()&&(this._touchedOthers??=new Set).add(o),n.recordTouched(a,[s])}}_takeFormulaResults(e,t=!1){let r=this._container.getFormulas().getSpatialAt(this._gridId);if(t){this._touchedFormulas=[];let t=r?.all();return t&&t.length>0&&(e.formulaInserts=this._formulaRecords(t)),e}let i=this._touchedFormulas;if(i.length===0)return e;this._touchedFormulas=[];let a=i;if(i.length>1){let e=[...i].sort((e,t)=>(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1)-(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1));a=[];for(let t=0;t<e.length;t++){let r=e[t],i=!1;for(let e=0;e<a.length&&!i;e++)i=n.CoordUtils.isRangeWithinRange(r,a[e]);i||a.push(r)}}if(e.formulaRemoves=a,r){let t=new Set,n=[];for(let e=0;e<a.length;e++){let i=r.search(a[e]);for(let e=0;e<i.length;e++){let r=i[e],a=r.value;t.has(a)||(t.add(a),n.push(r))}}n.length>0&&(e.formulaInserts=this._formulaRecords(n))}if(!e.isFull){let t=n.CoordUtils.unionRangesArrays(a,e.bounds??void 0);e.bounds=t&&YI(t)}return e}_formulaRecords(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r.value?.formula;i&&t.push({...YI(r),value:i.getRecord()})}return t}_mutationResults(e){let t=this._takeFormulaResults({cycleId:this._container.getCycleId()});return e!==void 0&&(t.commitId=e),t}_apply(e,t,n=!1){let r=this._applyNow(e,t,n),i=this._touchedOthers;if(i){this._touchedOthers=null;let e=r instanceof Promise?void 0:r.commitId;for(let t of i)t._pushTouched(e)}return r}_holdsBody(){return this._shadowOf!==null||this._unanchored||this._arrayFirstCell}_pushTouched(e){if(this._touchedFormulas.length===0)return;let t=this._takeFormulaResults({cycleId:this._container.getCycleId()});e!==void 0&&(t.commitId=e),this._onCalculated(t)}_applyNow(e,r,i){switch(e.type){case`seed`:{let t=this._land(r,()=>this._seedNow(e.json,e.options));return this._onCalculated(t),t}case`setInputs`:{let t=i&&e.options?.cloneKey!==void 0?{...e.options,cloneKey:void 0}:e.options;return this._land(r,()=>(this._setInputsNow(e.values,e.formulas,e.deleteRange,t),this._mutationResults(t?.commitId)))}case`shift`:return this._land(r,()=>this._shiftNow(e.options));case`autoFill`:return this._land(r,()=>this._autoFillNow(e.template,e.destination,e.commitId));case`snapshot`:return this._captureSnapshot(e.snapshotId),{cycleId:this._container.getCycleId()};case`copyTo`:{let t=this._container.getGrid(e.sourceGridId)?._snapshots?.get(e.snapshotId);if(!t)return{cycleId:this._container.getCycleId(),commitId:e.commitId};let i=bA(e.destination,e.coords,e.fitDestination,e.transpose);return i.scope=this._gridId,this._land(r,()=>{e.isCut?this._moveTo(t,e.coords,i):this._copyTo(t,e.coords,i);let r=this._mutationResults(e.commitId);return r.bounds=n.CoordUtils.unionRanges(r.bounds??null,YI(e.destination)),r})}case`delete`:return this._land(r,()=>this._deleteNow()),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`calculate`:return this._calculateNow(e.full),{cycleId:this._container.getCycleId()};case`markDirty`:return this._markDirtyRegionsNow(e.coords),{cycleId:this._container.getCycleId()};case`revert`:return this._revertNow(e.options);case`close`:return this._detach(),{cycleId:this._container.getCycleId()};case`resize`:return this._land(r,()=>{this._resized=e.entireCoords,this._publishMaps()}),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`hidden`:return QI(this.getHiddenRuns(e.axis),e.runs)||this._land(r,()=>this._setHiddenNow(e.axis,e.runs)),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`filtered`:return this._filtered!==e.filtered&&this._land(r,()=>this._setFilteredNow(e.filtered)),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`setReference`:return this._setReferenceNow(e.row,e.column,e.index,e.precedent===`#REF!`?t.FormulaError.BuiltIn.Ref:e.precedent);case`setReferenceMode`:return this._setReferenceModeNow(e.row,e.column,e.index,e.side,e.mode);case`toJSON`:return{cycleId:this._container.getCycleId(),answer:this._toJSONNow(e.options)};case`evaluate`:{let t=this._container.getCycleId();return Promise.resolve(this._evaluateNow(e.row,e.column,e.evalIndex,e.coerce)).then(e=>({cycleId:t,answer:e}))}case`graph`:return{cycleId:this._container.getCycleId(),answer:e.asName?this._nameGraphNow(e.kind,e.direct):this._graphNeighborsNow(e.coords,e.kind,e.direct)};case`isVolatile`:return{cycleId:this._container.getCycleId(),answer:this._isVolatileNow(e.row,e.column)};case`setBody`:{let t=e.body,n=this._land(r,()=>{let e=t.coords,n=this._container.createFormulaBlock(t.scopeGridId,this._context,t.expression,t.authoredAt.rowIndex,t.authoredAt.colIndex).reanchorReferences(t.scopeGridId).getTextAt(e.rowStart,e.colStart);return this._setInputsNow(null,[{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:n}]),this._mutationResults(void 0)});return t.recompile&&this._container.recompileNamed(this._gridId),n}}}_captureSnapshot(e){let t=this._container,n=this._snapshots??=new Map;n.set(e,{calcGrid:this,values:this._values.clone(),spillSpatial:this._spillSpatial.clone(),formulaSpatial:t.getFormulas(),precedentSpatial:t.getPrecedents(),volatile:t.getVolatiles()}),n.size>$I&&n.delete(n.keys().next().value)}beginUpdates(){return{gridId:this._gridId,values:this._values,spillSpatial:this._spillSpatial,errorSpatial:this._errorSpatial,pendingSpatial:this._pendingSpatial,circularSpatial:this._circularSpatial,contentfulSpatial:this._contentfulSpatial,notifyValues:this._notifyValues,notifyBlank:e=>this._addNotifyBlank(e),notifySpillsInsert:this._notifySpillsInsert,notifySpillsRemove:this._notifySpillsRemove,notifyFormats:this._notifyFormats,notifyPending:this._notifyPending,notifyCircular:this._notifyCircular,pendingConflating:null,circularConflating:null,errorRemovesConflating:null,errorInsertsConflating:null,formatsConflating:null,done:(e,t)=>this._notifyCalculated(e,t)}}_addNotifyBlank(e){let t=this._notifyBlank;t===null?this._notifyBlank={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}:(e.colStart<t.colStart&&(t.colStart=e.colStart),e.rowStart<t.rowStart&&(t.rowStart=e.rowStart),e.colEnd>t.colEnd&&(t.colEnd=e.colEnd),e.rowEnd>t.rowEnd&&(t.rowEnd=e.rowEnd))}_calculateNow(e){return this._container.calculateGrid(this._gridId,e?lL:void 0)}_shiftNow(e){let r=this,i=this.getId(),a={...e};a.range={...a.range},a.range.scope=i,delete a.onShift;let o=r._values,s=a.range,c=a.direction,l=c===t.IRange.Direction.Left||c===t.IRange.Direction.Right,u=c===t.IRange.Direction.Down||c===t.IRange.Direction.Right,d=u?1:-1,f=r._spillSpatial,p=r._contentfulSpatial;PI(f,s,l,u);let m=FI(s,f,o,p);o.shift(a.range,a.direction),a.onUpdates=(e,t)=>{r._notifySpillsRemove.push(...t),r._notifySpillsInsert.push(...e)},r._spillSpatial=f.shift(a),delete a.onUpdates,r._contentfulSpatial=p.shift(a),r._errorSpatial=r._errorSpatial.shift(a);let h=r._container,g=h.getFormulas().clone(),_=h.getPrecedents().clone(),v=this.getEntireCoords(),y={colStart:s.colStart,rowStart:s.rowStart,colEnd:l&&d===1?v.colEnd:s.colEnd,rowEnd:l||d!==1?s.rowEnd:v.rowEnd,scope:i},b=u?kI(_,y,AI):function(e,t){return kI(e,t,jI)}(_,s);b&&(mL(g,_,b.formulas.inserts,b.formulas.removes),r._touchFormulas(b.formulas.removes),r._touchFormulas(b.formulas.inserts));let x=(l?s.colEnd-s.colStart+1:s.rowEnd-s.rowStart+1)*d,S,C=function(e,r,i,a,o){let s=e(),c=s.search(i),l=c.length;if(l===0)return null;let u=i.colStart,d=i.rowStart,f=a.colIndex,p=a.rowIndex,m=a.scope,h=o?o.colEnd:i.colEnd,g=o?o.rowEnd:i.rowEnd,_=[],v=[],y=[],b=new Map,x=[];for(let e=0;e<l;e++){let r=c[e],a=r.value,o=a.formulaEntry,s=b.get(o)??o,l=s.value,S=l.ref,C=r.colStart,w=r.rowStart,T=r.colEnd,E=r.rowEnd,D=!1;if(a.index<0){x.push(r);continue}if((m===void 0||l.gridId===m)&&n.CoordUtils.isRangeWithinRange(S,i))continue;let O=a.index,k=l.getReferences(S.rowStart,S.colStart),A=k.length>0?k[O]:null;if(!A||t.FormulaError.isError(A)||`nameId`in A)continue;let j=`tableId`in A,M=A,N=l.unanchored,P=N&&!M.$colStart,F=N&&!M.$colEnd,I=N&&!M.$rowStart,L=N&&!M.$rowEnd,R=M;if(f!==0){let e=M.$colStart?M.colStart:S.colStart+M.colStart,t=M.$colEnd?M.colEnd:S.colEnd+M.colEnd,n=ON(e,t,u,f,h,P,F);n===null?R=null:(n[0]!==e&&(R=R===M?{...M}:R,R.colStart+=n[0]-e),n[1]!==t&&(R=R===M?{...M}:R,R.colEnd+=n[1]-t))}if(p!==0){let e=M.$rowStart?M.rowStart:S.rowStart+M.rowStart,t=M.$rowEnd?M.rowEnd:S.rowEnd+M.rowEnd,n=ON(e,t,d,p,g,I,L);n===null?R=null:(n[0]!==e&&(R=R===M?{...M}:R,R.rowStart+=n[0]-e),n[1]!==t&&(R=R===M?{...M}:R,R.rowEnd+=n[1]-t))}if(R!==M){if(R!==null&&(C=R.$colStart?R.colStart:S.colStart+R.colStart,w=R.$rowStart?R.rowStart:S.rowStart+R.rowStart,T=R.$colEnd?R.colEnd:S.colEnd+R.colEnd,E=R.$rowEnd?R.rowEnd:S.rowEnd+R.rowEnd,D=!0),l=j?l.remint():l.setReferenceAt(O,R),_.push(r),D){let e={...r};e.value={...a},e.value.formulaEntry=s,e.colStart=C,e.rowStart=w,e.colEnd=T,e.rowEnd=E,v.push(e),y.push(o)}s={...s},s.value=l,b.set(o,s)}}let S=x.length;if(S>0||b.size>0){let e=r();if(S>0){s.removeAll(x,HI);for(let t=0;t<S;t++){let n=x[t].value.formulaEntry.value,r=e.get(n);r&&(s.removeAll(r,HI),e.delete(n))}}for(let t of b.keys()){let n=t.value;if(!n)continue;let r=e.get(n);r&&(s.removeAll(r,HI),e.delete(n))}}for(let e=0;e<v.length;e++){let t=b.get(y[e]);t&&(v[e].value.formulaEntry=t)}let C=Array.from(b.keys()),w=Array.from(b.values()),T=[];for(let e=0;e<S;e++)T.push(x[e].value.formulaEntry);return{precedents:{inserts:v,removes:_},formulas:{inserts:w,removes:C},dynamicDependents:T}}(()=>_,()=>{let e=h.getDynamics();return S=new Map(e),S},{colStart:s.colStart,rowStart:s.rowStart,colEnd:l?v.colEnd:s.colEnd,rowEnd:l?s.rowEnd:v.rowEnd,scope:i},{colIndex:l?x:0,rowIndex:l?0:x,scope:i},u?void 0:s),w,T;C&&(mL(g,_,C.formulas.inserts,C.formulas.removes),r._touchFormulas(C.formulas.removes),r._touchFormulas(C.formulas.inserts)),a.onUpdates=(e,t)=>{w=e,T=t},g.shift(a),(w||T)&&(gL(_,w,T),r._touchFormulas(T),r._touchFormulas(w)),h.setFormulas(g),h.setPrecedents(_),S&&h.setDynamics(S),h.bumpCalcEpochs(!0),m?.(u,l?0:x,l?x:0);let E=[{...v,scope:this._gridId}];if(C){let e=C.formulas.inserts;for(let t=0;t<e.length;t++){let n=e[t];n.scope!==this._gridId&&E.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:n.scope})}let t=C.dynamicDependents;for(let e=0;e<(t?.length??0);e++){let n=t[e].value,r=n.gridId;r&&r!==this._gridId&&!n.unanchored&&h.getGrid(r)&&E.push({...n.ref,scope:r})}}return h.markDirty(E),r._mutationResults(e.commitId)}_removeNow(e){return this._setInputsNow(null,[{...e,scope:this._gridId,value:null}],{...e,scope:this._gridId})}_autoFillNow(e,t,n){let r=this._gridId,i=this._container,a={calcGrid:this,values:this._values.clone(),spillSpatial:this._spillSpatial.clone(),formulaSpatial:i.getFormulas(),precedentSpatial:i.getPrecedents(),volatile:i.getVolatiles()};return this._copyTo(a,{...e,scope:r},{...t,scope:r}),this._mutationResults(n)}_replaceSheetSpans(e,t,n){let r=this._container,i=r.getFormulas(),a=i.all3D(),o=new Map,s=[],c=[];for(let r=0;r<a.length;r++){let i=a[r],l=i.value,u=l.getReferencedSymbolIds(),d=l;for(let r=0;r<u.length;r++){let i=u[r];if(!vC(i))continue;let a=o.get(i);a===void 0&&(a=yC(i,e,t,n)??null,o.set(i,a)),a!==null&&(d=d.replaceScopeIds(i,a))}d!==l&&(s.push(i),c.push({...i,value:d}))}if(c.length===0)return;let l=i.clone(),u=r.getPrecedents().clone();mL(l,u,c,s);let d=r.getDynamics(),f=null;for(let e=0;e<s.length;e++){let t=s[e].value,n=d.get(t);n&&(f??=new Map(d),u.removeAll(n,dL),f.delete(t))}r.setFormulas(l),r.setPrecedents(u),f&&r.setDynamics(f),this._touchFormulas(s),this._touchFormulas(c);let p=[];for(let e=0;e<c.length;e++){let t=c[e].value;p.push({...t.ref,scope:t.gridId}),pL(r,t,p)}r.markDirty(p)}_deleteNow(){let e=this._container,t=e.getSheetIds?.();if(t){let e=this._gridId;this._replaceSheetSpans(t,t.filter(t=>t!==e))}let n=e.getFormulas(),r=e.getPrecedents(),i=n,a=r,o=this._gridId,s=[];if(i.getSpatialAt(o)&&(i=i.clone(),i.getSpatialAt(o).clear()),a.getSpatialAt(o)){a=a.clone();let t=a.getSpatialAt(o),n=new Map,r=new Map,c=t.all();for(let e=0;e<c.length;e++){let t=c[e].value,i=t.formulaEntry;if(i.scope!==o){let e=t.index,a=i;n.set(a,a);let o=r.get(a)??a;o={...o},o.value=o.value.setReferenceAt(e,null,{scopeDeleted:!0}),r.set(a,o)}}if(t.clear(),r.size>0||n.size>0){let t=Array.from(r.values()),o=Array.from(n.values());mL(i,a,t,o),this._touchFormulas(o),this._touchFormulas(t);for(let n=0;n<t.length;n++){let r=t[n];s.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:r.scope}),pL(e,r.value,s)}}}i!==n&&e.setFormulas(i),a!==r&&e.setPrecedents(a),s.length>0&&e.markDirty(s),this._container.unregisterGrid(this._gridId)}_detach(){let e=this._container,t=this._gridId,n=e.getPrecedents(),r=[];if(n.getSpatialAt(t)){let i=n.clone(),a=i.getSpatialAt(t),o=a.all(),s=new Set;for(let e=0;e<o.length;e++){let n=o[e].value.formulaEntry;n.scope===t||s.has(n)||(s.add(n),r.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:n.scope}))}a.clear(),e.setPrecedents(i)}r.length>0&&e.markDirty(r),e.unregisterGrid(t)}_markDirtyRegionsNow(e){let t=this._gridId,n=Array(e.length);for(let r=0;r<e.length;r++){let i=e[r];n[r]=i.scope===t?i:{...i,scope:i.scope??t}}this._container.markDirty(n)}getHiddenRuns(e){return e===t.IRange.Axis.Column?this._hiddenColumns:this._hiddenRows}isFiltered(){return this._filtered}getHiddenSkip(e,t,n){let r=this.getHiddenRuns(e);if(!r)return null;let i=0,a=r.length;for(;i<a;){let e=i+a>>>1;r[e].max<t?i=e+1:a=e}if(i===r.length||r[i].min>n)return null;let o=ZI.get(r);o||(o=new Map,ZI.set(r,o));let s=o.get(t);if(!s){let e=Lt(r);s=t===0?e:(n,r)=>e(n+t,r)-t,o.set(t,s)}return s}_setHiddenNow(e,n){let r=n.length>0?n:null;e===t.IRange.Axis.Column?this._hiddenColumns=r:this._hiddenRows=r,this._publishMaps(),this._markTotals()}_setFilteredNow(e){this._filtered=e,this._publishMaps(),this._markTotals()}_markTotals(){let e=this._container,t=[];for(let n of e.getFormulas().getScopeValues()){let e=n.all();for(let n=0;n<e.length;n++){let r=e[n];r.value?.hasTotals()&&t.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:r.scope})}}t.length!==0&&(e.markDirty(t),e.requestCalculateGrid(this._gridId))}getShadowOf(){return this._shadowOf}isArrayFirstCell(){return this._arrayFirstCell}getEntireCoords(){return this._resized??this._getEntireCoords()}hasErrorIn(e){return this._errorSpatial.has(e)}getBoundingRange(){let e=null;return e=n.CoordUtils.unionRanges(this._values.getCoords(),e),e=n.CoordUtils.unionRanges(this._container.getFormulas().getSpatialAt(this._gridId)?.getBoundingRange(),e),e}getValues(){return this._values}getDirtyRegions(){return this._container.getDirtyGrid(this._gridId)}getFormulas(){return this._container.getFormulas().getSpatialAt(this._gridId)??oL}getSpills(){return this._spillSpatial}_revertNow(e){let t=this._container.revertTo(e.commitId,this._gridId);if(t)for(let e=0;e<t.length;e++)this._touchedFormulas.push({...t[e],scope:this._gridId});let n=this._takeFormulaResults({cycleId:this._container.getCycleId()});return n.commitId=e.commitId,n}getDirectDependentsAt(e){let t=e.rowStart,r=e.colStart,i=e.rowEnd,a=e.colEnd,o=this._gridId,s=this._container.getPrecedents();aL.colStart=r,aL.rowStart=t,aL.colEnd=a,aL.rowEnd=i,aL.scope=o;let c=s.search(aL);if(c.length===0)return n.CommonUtils.EmptyArray;let l=[];for(let e=0;e<c.length;e++){let n=c[e],s=n.value,u=s.formulaEntry,d=t-n.rowStart,f=r-n.colStart,p=i-n.rowStart,m=a-n.colStart,h=u.rowEnd-u.rowStart,g=u.colEnd-u.colStart,_=s.formulaBlockHeight-1,v=s.formulaBlockWidth-1,y;if(s.index===fI.Reference){let e=u.value,t=e.ref;y={rowStart:t.rowStart,rowEnd:t.rowEnd,colStart:t.colStart,colEnd:t.colEnd,scope:o===e.gridId?void 0:e.gridId??void 0}}else if(s.index===fI.Spill||h>_||g>v)y={rowStart:u.rowStart,rowEnd:u.rowEnd,colStart:u.colStart,colEnd:u.colEnd,scope:o===u.scope?void 0:u.scope};else{let e=n.rowEnd-n.rowStart-_,t=n.colEnd-n.colStart-v,r=s.$absRowEnd?0:Math.max(0,d-e),i=s.$absRowStart?_:Math.min(p,_),a=s.$absColEnd?0:Math.max(0,f-t),c=s.$absColStart?v:Math.min(m,v);y={rowStart:u.rowStart+r,rowEnd:u.rowStart+i,colStart:u.colStart+a,colEnd:u.colStart+c,scope:o===u.scope?void 0:u.scope}}l.push(y)}return l=kr(l,2,n.RangeAxis.Row),l.sort(n.CoordUtils.rowFirstRangeComparator),l}getDirectPrecedentsAt(e){let t=e.rowStart,r=e.colStart,i=e.rowEnd,a=e.colEnd,o=this._container.getFormulas();aL.colStart=r,aL.rowStart=t,aL.colEnd=a,aL.rowEnd=i;let s=this._gridId;aL.scope=s;let c=o.search(aL);if(c.length===0)return n.CommonUtils.EmptyArray;let l=this.getEntireCoords(),u=null,d=e=>{if(!e||e===s)return l;u??=new Map;let t=u.get(e);return t||(t=this._container.getGrid(e)?.getEntireCoords()??l,u.set(e,t)),t},f=[];for(let e=0;e<c.length;e++){let n=c[e],o=n,l=this._container.getDynamics().get(o.value);if(l)for(let e=0;e<l.length;e++){let t=l[e];t.value.index===fI.Reference&&f.push({rowStart:t.rowStart,rowEnd:t.rowEnd,colStart:t.colStart,colEnd:t.colEnd,scope:t.scope===s?void 0:t.scope})}let u=o.value.formula.getReferences(t,r);if(!u)continue;let p=t-n.rowStart,m=r-n.colStart,h=i-n.rowStart,g=a-n.colStart,_=o.rowEnd-o.rowStart,v=o.colEnd-o.colStart,y=n.rowEnd-n.rowStart-_,b=n.colEnd-n.colStart-v,x=Math.max(0,p-y),S=Math.max(0,m-b),C=Math.min(h,_),w=Math.min(g,v),T=[];for(let e=0;e<u.length;e++){let t=u[e];if(t?.colStart===void 0)continue;let n=t.scope,r=d(n),i=Bd(t,o.rowStart+x,o.colStart+S),a=Bd(t,o.rowStart+C,o.colStart+w),c={colStart:Math.max(Math.min(i.colStart,a.colStart),r.colStart),rowStart:Math.max(Math.min(i.rowStart,a.rowStart),r.rowStart),colEnd:Math.min(Math.max(i.colEnd,a.colEnd),r.colEnd),rowEnd:Math.min(Math.max(i.rowEnd,a.rowEnd),r.rowEnd),scope:n===s?void 0:n};T.push(c)}f.push(...T)}return f=kr(f,2,n.RangeAxis.Row),f.sort(n.CoordUtils.rowFirstRangeComparator),f}_directAcrossGrids(e,t){let r=this._gridId,i=e.scope,a=i&&i!==r?this._container.getGrid(i)??null:this;if(!a)return n.CommonUtils.EmptyArray;let o=t?a.getDirectDependentsAt(e):a.getDirectPrecedentsAt(e);if(a===this||o.length===0)return o;let s=Array(o.length);for(let e=0;e<o.length;e++){let t=o[e],n=t.scope??a._gridId;s[e]=n===r?{...t,scope:void 0}:{...t,scope:n}}return s}getDependentsAt(e){let t=Fr(e,e=>this._directAcrossGrids(e,!0));return t.sort(n.CoordUtils.rowFirstRangeComparator),t}getPrecedentsAt(e){let t=Fr(e,e=>this._directAcrossGrids(e,!1));return t.sort(n.CoordUtils.rowFirstRangeComparator),t}_graphNeighborsNow(e,t,n){let r=t===`precedents`?n?this.getDirectPrecedentsAt(e):this.getPrecedentsAt(e):n?this.getDirectDependentsAt(e):this.getDependentsAt(e),i=this._container;if(t===`precedents`){let t=this.getNamedReferencesAt(e),n=[];for(let e=0;e<t.length;e++){let r=i.getNamedNodeInfo(t[e]);r&&n.push(r)}return{cells:r,names:n}}let a=[],o=[],s=new Set;for(let e=0;e<r.length;e++){let t=r[e],n=t.scope;if(!n){a.push(t);continue}if(s.has(n))continue;let c=i.getNamedNodeInfo(n,!0);c?(s.add(n),o.push(c)):a.push(t)}return{cells:a,names:o}}getNamedReferencesAt(e){let t=this.getFormulas().search(e),r=t.length;if(r===0)return n.CommonUtils.EmptyArray;let i=new Set;for(let e=0;e<r;e++){let n=t[e].value?.getNamedIds();if(n)for(let e=0;e<n.length;e++)i.add(n[e])}return i.size>0?[...i]:n.CommonUtils.EmptyArray}_nameGraphNow(e,t){let r=this._container,i=[],a=new Set,o=(e,t)=>{i.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,scope:t})};if(e===`precedents`){let e=[this._gridId],i=new Set(e);for(let s=0;s<e.length;s++){let c=r.getGrid(e[s]);if(!c)continue;let l=t?c.getDirectPrecedentsAt(n.CoordUtils.EmptyRange):c.getPrecedentsAt(n.CoordUtils.EmptyRange);for(let e=0;e<l.length;e++)l[e].scope&&o(l[e],l[e].scope);let u=c.getFormulaBlockAt(0,0)?.getNamedIds()??n.CommonUtils.EmptyArray;for(let n=0;n<u.length;n++){let o=u[n];r.getNamedNodeInfo(o)&&(a.add(o),t||i.has(o)||(i.add(o),e.push(o)))}}}else{let e=new Set(r.getSheetIds?.()??n.CommonUtils.EmptyArray),i=[this._gridId],s=new Set(i),c=e=>{a.add(e),s.has(e)||(s.add(e),i.push(e))},l=e=>{c(e);for(let t of r.getNamedDependentNames(e))c(t)};if(!t)for(let e of r.getNamedDependentNames(this._gridId))c(e);for(let s=0;s<i.length;s++){let c=r.getNamedDependents(i[s]);for(let i=0;i<c.length;i++){let s=c[i],u=s.scope;if(!u)continue;if(!e.has(u)){t&&a.add(u);continue}if(o(s,u),t)continue;let d=r.getGrid(u)?.getDependentsAt(s)??n.CommonUtils.EmptyArray;for(let t=0;t<d.length;t++){let n=d[t],r=n.scope??u;e.has(r)?o(n,r):n.scope&&l(n.scope)}}}}let s=[];for(let e of a){let t=r.getNamedNodeInfo(e);t&&s.push(t)}return{cells:i,names:s}}_blankRegion(){let e=this._container.getFormulas().getSpatialAt(this._gridId)?.all(),t=e&&e.length>0?e[0]:null,n=t?.value?.getBlankRegion()??null;if(!t||!n)return null;let r=Array(n.rects.length);for(let e=0;e<r.length;e++){let t=n.rects[e];r[e]={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}let i={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd};return{value:n.value,rects:r,extent:i}}getFormulaBlockAt(e,t){let n=this._formulaAt(e,t);return n?n.value.formula:null}getReferencesAt(e,t){let r=this._formulaAt(e,t);return r?r.value.formula.getReferencesAt(e,t):n.CommonUtils.EmptyArray}_evaluateNow(e,t,n,r){let i=this._formulaAt(e,t);if(!i)return null;let a=i.value.formula;if(this._container.getScope().node=null,r===`scalar`){let r=tU(a.evaluateAt(e,t,n),this._context);return r===null?0:r}return a.finalizeValue(a.evaluateAt(e,t,n))}_setReferenceNow(e,t,n,r){let i=this._formulaAt(e,t),a=r;r&&r.colStart!==void 0?a=Vd(a,e,t):r&&r.colIndex!==void 0&&(a=function(e,t,n){let r=e.$colIndex??!1,i=e.$rowIndex??!1,a={colIndex:r?e.colIndex:e.colIndex-n,rowIndex:i?e.rowIndex:e.rowIndex-t,$colIndex:r,$rowIndex:i};return e.scope&&(a.scope=e.scope),a}(a,e,t));let o=i.value.formula.setReferenceAt(n,a).getTextAt(e,t);return this._land(void 0,()=>{o?this._setInputsNow(null,[{colStart:t,rowStart:e,colEnd:t,rowEnd:e,scope:this._gridId,value:o}]):this._removeNow({colStart:t,rowStart:e,colEnd:t,rowEnd:e})}),this._mutationResults(void 0)}_setReferenceModeNow(e,t,n,r,i){let a=this.getReferencesAt(e,t)[n];if(!a||`nameId`in a)throw Error(`Reference at index ${n} is not a cell reference and cannot have its style changed.`);return this._setReferenceNow(e,t,n,oM(a,r,i))}_isVolatileNow(e,t){let n=this._formulaAt(e,t);if(!n?.value)return!1;let r=n.value.nodeAtOrNull(e,t);return!!r&&this._container.getVolatiles().has(r)}_formulaAt(e,t){iL.colStart=t,iL.rowStart=e,iL.colEnd=t,iL.rowEnd=e,iL.scope=this._gridId,cL.length=0;let n=this._container.getFormulas().search(iL,!1,!1,cL);return n.length===0?null:n[0]}_createCopySpillEntries(e,t,n,r,i){let a=r??[],o=i??[],s=t.colStart,c=t.rowStart,l=t.colEnd,u=t.rowEnd,d=n.colStart,f=n.rowStart,p=e.search(t),m=p.length;for(let e=0;e<m;e++){let t=p[e];o&&o.push(t);let n=t.rowStart,r=t.colStart;if(n<c||n>u||r<s||r>l||t.value.getError())continue;let i=d+(t.colEnd-r),m=f+(t.rowEnd-n),h={colStart:d,rowStart:f,colEnd:i,rowEnd:m};a.push({colStart:d,rowStart:f,colEnd:i,rowEnd:m,value:new MP(h,0,t.value.getKind())})}return{removes:o,inserts:a}}_reanchorFormulas(e,t,n,r){let i=e?e.length:0;if(i===0)return;let a=this._container,o=n??this._gridId,s=n==null?t??o:o,c=a.getScope();c.gridId=s;let l=t?a.getSymbols().resolve($.Sheet,t)?.toString():void 0,u=this._context;for(let n=0;n<i;n++){let i=e[n],d=i.value,f=d.ref,p=d.formula.getTextAt(f.rowStart,f.colStart);c.colIndex=f.colStart,c.rowIndex=f.rowStart;let m=a.createFormulaBlock(s,u,p,f.rowStart,f.colStart);t&&(m=m.reanchorReferences(l,r));let h=new dI(f,o,m,a,d.unanchored,d.getNodeSource());i.scope=o,i.value=h}}_copyTo(e,t,n){let r=e.calcGrid.getId(),i=this._gridId,a=e.formulaSpatial,o=a.getSpatialAt(r);if(!o||o.isEmpty())return;let s=this.getEntireCoords(),c=s.colStart,l=s.rowStart,u=s.colEnd,d=s.rowEnd,f=a.createCopiedEntries(t,n),p=f.inserts,m=p.length;if(m===0&&(f.removes?.length??0)===0)return;let h=0,g=e.spillSpatial,_=[];for(;h<m;){let e=p[h];e.scope=i;let n=e.value,r=n.ref,a=r.colStart,o=r.rowStart,s=r.colEnd,f=r.rowEnd;this._createCopySpillEntries(g,t,r,_,null);let v=n.formula.getReferences(o,a),y=v.length;for(let t=0;t<y;t++){let i=v[t];if(!i||`nameId`in i||`tableId`in i)continue;let h=i,g=h.colStart,_=h.rowStart,y=h.colEnd,b=h.rowEnd,x=h.$colStart?g:g+a,S=h.$rowStart?_:_+o,C=h.$colEnd?y:y+s,w=h.$rowEnd?b:b+f;if(g===-(2**53-1)&&(x=c,C=u),_===-(2**53-1)&&(S=l,w=d),x<c||C>u||S<l||w>d){let i=c-x,h=l-S,g=u-C,_=d-w;sL.colStart=Math.max(a,a+i),sL.rowStart=Math.max(o,o+h),sL.colEnd=Math.min(s,s+g),sL.rowEnd=Math.min(f,f+_);let y=Tr(e,sL,Ar);if(y){let t=y.length;e=y[t-1],n=e.value,r=n.ref,a=r.colStart,o=r.rowStart,s=r.colEnd,f=r.rowEnd;for(let e=0;e<t-1;e++){let t=y[e];p.push(t),m++}}else n=n.setReferenceAt(t,null),e.value=n,v=n.formula.getReferences(o,a)}}p[h++]=e}let v=this._container,y=v.getFormulas().clone(),b=v.getPrecedents().clone();v.setFormulas(y),v.setPrecedents(b),i!==r&&this._reanchorFormulas(p,void 0,i),mL(y,b,p,f.removes),this._touchFormulas(f.removes),this._touchFormulas(p),_&&this._spillSpatial._updateNodes(_,[]),v.markDirty([{...s,scope:this._gridId}])}_moveTo(e,r,i){let a=e.calcGrid,o=a.getId(),s=e.formulaSpatial;this._removeNow(i);let c=this._container,l=c.getPrecedents().clone(),u=c.getFormulas().clone();c.setPrecedents(l),c.setFormulas(u);let d=kI(l,r,MI);d&&(mL(u,l,d.formulas.inserts,d.formulas.removes),this._touchFormulas(d.formulas.removes),this._touchFormulas(d.formulas.inserts));let f={cutFrom:r},p=s.createCopiedEntries(r,i,f).inserts,m=p.length,h=this._gridId;if(h!==o){let e=i.colStart-r.colStart,a=i.rowStart-r.rowStart,s=[],c=[];for(let i=0;i<m;i++){let l=p[i],u=l.value,d=u.ref,f=u.formula.resolvedPrecedentsAt(d.rowStart,d.colStart),m=!0,g=f?f.length:0;for(let i=0;i<g;i++){let s=f[i];if(t.FormulaError.isError(s)){m=!1;break}let c=s.scope??h,l;if(c===h)l={colStart:s.colStart-e,rowStart:s.rowStart-a,colEnd:s.colEnd-e,rowEnd:s.rowEnd-a};else{if(c!==o){m=!1;break}l=s}if(!n.CoordUtils.isRangeWithinRange(l,r)){m=!1;break}}m?c.push(l):s.push(l)}if(c.length>0){this._reanchorFormulas(c);for(let e of c){let t=e.value.replaceScopeIds(o,h);t!==e.value&&(e.value=t)}}s.length>0&&this._reanchorFormulas(s,o)}let g;mL(u,l,p),this._touchFormulas(p);let _=function(e,r,i,a){let o=e,s=o.search(i),c=s.length;if(c===0)return null;let l=a.colStart-i.colStart,u=a.rowStart-i.rowStart,d=[],f=[],p=new Map,m=new Set;for(let e=0;e<c;e++){let r=s[e],o=r.value,c=o.formulaEntry,h=p.get(c),g=h??c,_=g.value,v=_.ref,y=(v.scope??null)===(i.scope??null)&&n.CoordUtils.isRangeWithinRange(v,i),b=_.getReferences(v.rowStart,v.colStart),x=b?b.length:0;if(x===0)continue;let S=o.index,C=b?b[S]:null;if(!C||t.FormulaError.isError(C)||`nameId`in C)continue;let w=`tableId`in C,T=C;if(!h&&x>1)for(let e=0;e<x;e++){if(e===S)continue;let r=b[e];if(!r||t.FormulaError.isError(r)||`nameId`in r)continue;let a=r;if((a.scope??null)!==(i.scope??null)||!n.CoordUtils.isRangeWithinRange(a,i)){m.add(c);break}}let E=g.colEnd-g.colStart,D=g.rowEnd-g.rowStart,O=r.colStart,k=r.rowStart,A=r.colEnd,j=r.rowEnd,M=o.$absColEnd?A-O+1:A-O-E+1,N=o.$absRowEnd?j-k+1:j-k-D+1,P=o.$absRowStart?k>=i.rowStart?0:D+1:Math.max(0,i.rowStart-k),F=o.$absRowEnd?j<=i.rowEnd?D:-1:Math.min(D,i.rowEnd-k-(N-1)),I=o.$absColStart?O>=i.colStart?0:E+1:Math.max(0,i.colStart-O),L=o.$absColEnd?A<=i.colEnd?E:-1:Math.min(E,i.colEnd-O-(M-1));if(P>F||I>L||P!==0||F!==D||I!==0||L!==E)continue;let R=y||_.unanchored,ee=r.scope!==a.scope,te;if(l!==0){let[e,t]=kN(T.colStart,T.colEnd,l,!T.$colStart&&R,!T.$colEnd&&R);e===T.colStart&&t===T.colEnd||(te??={...T},te.colStart=e,te.colEnd=t)}if(u!==0){let[e,t]=kN(T.rowStart,T.rowEnd,u,!T.$rowStart&&R,!T.$rowEnd&&R);e===T.rowStart&&t===T.rowEnd||(te??={...T},te.rowStart=e,te.rowEnd=t)}if(!te&&!ee)continue;te||={...T},_=w?_.remint():_.setReferenceAt(S,te),g={...g},g.value=_,p.set(c,g),d.push(r);let ne={...r};ne.colStart+=l,ne.rowStart+=u,ne.colEnd+=l,ne.rowEnd+=u,ne.scope=a.scope,ne.value={...o},ne.value.formulaEntry=g,f.push(ne)}if(p.size>0){let t=r();for(let n of p.keys()){let r=n.value;if(!r)continue;let i=t.get(r);i&&(e.removeAll(i,HI),t.delete(r))}}let h=Array.from(p.keys()),g=Array.from(p.values()),_=m.size;if(_>0){let e=Array.from(m);for(let r=0;r<_;r++){let a=e[r],s=a.value,c=s.ref,l=s.getReferences(c.rowStart,c.colStart),u=l?l.length:0;if(u>1){let e=s.ref,r=e.colStart,c=e.rowStart;for(let e=0;e<u;e++){let s=l[e];if(!s||t.FormulaError.isError(s)||`nameId`in s)continue;let u=s;if(RI.colStart=u.$colStart?u.colStart:r+u.colStart,RI.rowStart=u.$rowStart?u.rowStart:c+u.rowStart,RI.colEnd=u.$colEnd?u.colEnd:r+u.colEnd,RI.rowEnd=u.$rowEnd?u.rowEnd:c+u.rowEnd,RI.scope=u.scope??a.scope,(RI.scope??null)===(i.scope??null)&&n.CoordUtils.isRangeWithinRange(RI,i))continue;RI.colEnd=RI.colStart,RI.rowEnd=RI.rowStart;let m=o.search(RI);for(let e=0;e<m.length;e++){let t=m[e];if(t.value.formulaEntry===a){let e=p.get(a);if(e){let n={...t};n.value={...t.value},n.value.formulaEntry=e,d.push(t),f.push(n)}break}}}}}}return{precedents:{inserts:f,removes:d},formulas:{inserts:g,removes:h}}}(l,()=>{let e=c.getDynamics();return g=new Map(e),g},r,i);if(g&&c.setDynamics(g),_){let e=_.formulas.inserts;r.scope!==i.scope&&e.length>0&&this._reanchorFormulas(e,i.scope,r.scope,!0),mL(u,l,_.formulas.inserts,_.formulas.removes),this._touchFormulas(_.formulas.removes),this._touchFormulas(_.formulas.inserts)}let v=this._values;e.values.copyTo(v,{colIndex:i.colStart,rowIndex:i.rowStart},r),function(e,n,r){e.isEmpty()||e.delete(r);let i=n.getAxis()===t.IRange.Axis.Column,a=n.getRuns({bounds:r}),o=a.next();for(;!o.done;){let[t,n,r]=o.value;o=a.next(),bI(e,t,n,r,i)}}(this._errorSpatial,v,i);let y=e.spillSpatial,b=[],x=[];for(let e=0;e<m;e++){let t=p[e];this._createCopySpillEntries(y,r,t,b,x)}let S=[];b.length>0&&(this._spillSpatial._updateNodes(b,[]),a._spillSpatial._updateNodes([],x),wI(c.getCycleId(),x,n.CommonUtils.EmptyArray,a._contentfulSpatial,a._spillSpatial,a._values,(e,t,n,r)=>{S.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:h})},a._notifyValues,(e,t)=>{e&&this._notifySpillsInsert.push(e),t&&this._notifySpillsRemove.push(t)},a._notifyPending,a._errorSpatial,a._values.getAxis()!==t.IRange.Axis.Row,!1,a._circularSpatial));let C=this.getEntireCoords();c.markDirty([{...C,scope:this._gridId}])}_notifyCalculated(e,r){let i,a=!1;a||(typeof r==`boolean`?a=r:r&&(i=r,a=i.full??!1));let o=this._notifyValues,s=o.all(),c=this._notifyPending.all([]);c.length>0&&this._notifyPending.clear();let l=this._notifyCircular.all([]),u,d;l.length>0&&this._notifyCircular.clear(),a?u=this._spillSpatial.all():(u=this._notifySpillsInsert,d=this._notifySpillsRemove),this._notifySpillsInsert=[],this._notifySpillsRemove=[];let f=this._notifyFormats.all();f.length>0&&this._notifyFormats.clear();let p={},m=null,h=s.length;if(h>0){o.clear();let e=s,r=null;for(let e=0;e<h;e++){let t=s[e],n=t.colStart,i=t.colEnd;if(n!==i){r||=[];for(let e=n+1;e<=i;e++)r.push({colStart:e,rowStart:t.rowStart,colEnd:e,rowEnd:t.rowEnd});t.colEnd=n}}r&&(e=s.concat(r)),e.sort(n.CoordUtils.columnFirstRangeComparator);let i=new z.Builder((e,t)=>new Rt.ArrayList(e.slice(0,t))),a,c=this._values,l=c.getAxis()===t.IRange.Axis.Column,u=e.length;for(let t=0;t<u;t++){let r=e[t];m=n.CoordUtils.unionRanges(m,r,eL);let o=c.getRuns({bounds:r}),s=o.next(),u=r.colStart,d=r.rowStart,f=r.colEnd,p=r.rowEnd,h=l?d:u,g=l?f:p,_=l?p:f,v=l?u:d,y=h;for(;!s.done;){let e=s.value,t=e[0];for(;v<t;)a||=[],a.push({colStart:l?v:y,rowStart:l?y:v,colEnd:l?v:_,rowEnd:l?_:v}),v++,y=h;let n=e[1],r=e[2],c=Math.max(n,h),u=Math.min(n+r.length-1,_);i.pushMultipleAt(t,c,r),y<c&&(a||=[],a.push({colStart:l?t:y,rowStart:l?y:t,colEnd:l?t:c-1,rowEnd:l?c-1:t})),y=u+1,u>=_?(v=t+1,y=h):v=t,s=o.next()}for(;v<=g;)y<=_&&(a||=[],a.push({colStart:l?v:y,rowStart:l?y:v,colEnd:l?v:_,rowEnd:l?_:v})),v++,y=h}let d=i.build();d&&(p.valueInserts=d),a&&(p.valueRemoves=a)}if(c.length>0){let e=this._pendingSpatial,t,r=c.length;for(let i=0;i<r;i++){let r=c[i];e.insertNonOverlapping(r,{onIntersect:(e,r)=>(t||=[],t.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:r.value}),m=n.CoordUtils.unionRanges(m,r),!1===r.value&&(r.value=null),r)})}t&&t.length>0&&(p.pendingUpdates=t,m=n.CoordUtils.unionRangesArrays(t,m??void 0,eL))}if(l.length>0){let e=this._circularSpatial,t,r=l.length;for(let i=0;i<r;i++){let r=l[i];e.insertNonOverlapping(r,{onIntersect:(e,r)=>{t||=[];let i=!1===r.value;return t.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:i?null:r.value}),m=n.CoordUtils.unionRanges(m,r),i&&(r.value=null),r}})}t&&t.length>0&&(p.circularUpdates=t,m=n.CoordUtils.unionRangesArrays(t,m??void 0,eL))}let g,_,v=d?d.length:0;if(v>0){g=[];for(let e=0;e<v;e++){let t=d[e];g.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd})}g&&(p.spillRemoves=g,m=n.CoordUtils.unionRangesArrays(g,m??void 0,eL))}let y=u.length;if(y>0){let t=this._spillSpatial,r;for(let n=y-1;n>=0;n--){let i=u[n],o=i.value;if(!a&&o.getCycleId()!==e)continue;let s=t.search(i),c=s.length;for(let t=0;t<c;t++){let n=s[t];if(mI(i.rowStart,i.colStart,n)&&(a||n.value.getCycleId()===e)){_||(_=[],r=new Set);let e=id(n.colStart)+rd(n.rowStart);if(r.has(e))continue;r.add(e),_.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:n.value.getKind()})}}}_&&(p.spillInserts=_,m=n.CoordUtils.unionRangesArrays(_,m??void 0,eL))}f.length>0&&(p.formatInserts=f,m=n.CoordUtils.unionRangesArrays(f,m??void 0,eL)),this._takeFormulaResults(p,a),p.formulaRemoves&&(m=n.CoordUtils.unionRangesArrays(p.formulaRemoves,m??void 0,eL));let b=this._notifyBlank;b!==null&&(m=n.CoordUtils.unionRanges(m,b,eL),this._notifyBlank=null),m&&(p.bounds={colStart:m.colStart,rowStart:m.rowStart,colEnd:m.colEnd,rowEnd:m.rowEnd}),Object.keys(p).length===0?p.cycleId=e-1:p.cycleId=e,a&&(p.isFull=!0);let x=this._container.getCalculatedCommitId();return x!==null&&(p.commitId=x),this._holdsBody()&&(p.blankRegion=this._blankRegion()),this._onCalculated(p),Promise.resolve(p)}_setInputsNow(e,r,i,a){let o=this._gridId,s=this._container,c=this._context,l=s.getFormulas(),u=l.getSpatialAt(o),d=!!u&&!u.isEmpty(),f=r?r.length:0,p=this._values,m=p.getAxis()!==t.IRange.Axis.Row,h=this._spillSpatial,g=this._errorSpatial,_=this._contentfulSpatial,v=[],y,b,x,S=d?[]:null;if(e&&e.tuples){y=e.tuples;let t=e.bounds;if(t?(b=zr(t,m),b.scope=o):b={colStart:-(2**53-1),rowStart:-(2**53-1),colEnd:2**53-1,rowEnd:2**53-1,scope:o},S){d&&v.push(b);let e={majorStart:0,minorStart:0,majorEnd:0,minorEnd:0},t=y.length;for(let n=0;n<t;n++){let t=y[n],r=t[0];e.majorStart=r,e.majorEnd=r;let i=t[1],a=i.length;for(let t=0;t<a;t++){let n=i[t];e.minorStart=n[0];let r=n[1];e.minorEnd=e.minorStart+r.length-1;let a=zr(e,m);a.scope=o,S&&l.search(a).length>0&&S.push(a)}}}x=PP(e.tuples,m,o)}let C=(e,t)=>{e&&this._notifySpillsInsert.push(e),t&&this._notifySpillsRemove.push(t)};if(i||y){let e;i&&(e=FI(i,h,p,_,C,!1,!0,this._notifyValues,(e,t,n,r)=>{v.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:o})})),wI(-1,i?[i]:n.CommonUtils.EmptyArray,x,_,h,p,(e,t,n,r)=>{v.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:o})},this._notifyValues,C,this._notifyPending,g,m,!1,this._circularSpatial),i&&(p.delete(i),vI(g,i)),e?.(),y&&(p.setValues(y),hI(g,y,m))}let w=s.getScope(),T,E,D,O,k,A=(e,t)=>{let n=e.rowStart,r=e.colStart;w&&(w.rowIndex=n,w.colIndex=r);let i=s.createFormulaBlock(o,c,t,n,r),l=new dI(e,o,i,s,this._unanchored),u=a?.arrayFixed;u&&u.colStart===r&&u.rowStart===n&&(FP(l.getAnchorNode()).fixedRef={colStart:u.colStart,rowStart:u.rowStart,colEnd:u.colEnd,rowEnd:u.rowEnd},l.densify());let d={...e,scope:o,value:l};T||=[],T.push(d)},j=e=>{let t={...e,scope:o,value:null};D.insertNonOverlapping(t,{noMerge:!0,onUpdates(e,t,n){E||=[];for(let e=0;e<t.length;e++){let n=t[e];if(E.push(n),k)for(let e=k.length-1;e>=0;e--)k[e].value===n.value&&k.splice(e,1)}let r=e?e.length:0;for(let t=0;t<r;t++){let n=e[t];n.value!==null&&(k||=[],k.push(n))}}})},M=S?S.length:0,N;if(f>0){N=rU(f);for(let e=0;e<f;e++){let t=r[e],i=t.value,a=n.CoordUtils.sanitizeRange(t);N[e]=a,i!==null&&A(a,i)}}let P=a?.cloneKey??null;(M>0||f>0)&&(D=s.getFormulas().clone(P));for(let e=0;e<M;e++)j(S[e]);for(let e=0;e<f;e++)j(N[e]);let F=E?E.length:0;if(F>0){let e=s.getDynamics(),t=null;for(let n=0;n<F;n++){let r=E[n].value,i=e.get(r);i&&(O||=s.getPrecedents().clone(P),O.removeAll(i,dL),t||=new Map(e),t.delete(r))}t&&s.setDynamics(t)}let I=[];if(T||E){O||=s.getPrecedents().clone(P),mL(D,O,T,E),k&&gL(O,k,null);let e=T?this._joinInserted(D,O,T,e=>{v.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,scope:o})}):null;this._touchFormulas(E),this._touchFormulas(T),this._touchFormulas(k),this._touchFormulas(e),wI(-1,E,T,_,h,p,(e,t,n,r)=>{v.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:o})},this._notifyValues,C,this._notifyPending,g,m,!0,this._circularSpatial)}if(O&&s.setPrecedents(O),D&&(T||E||k)&&s.setFormulas(D),T)for(let e=0;e<T.length;e++){let t=T[e];I.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:o})}if(E)for(let e=0;e<E.length;e++){let t=E[e];I.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:o})}return v.length>0&&s.markDirty(v),I}_joinInserted(e,t,n,r){let i=this._container,a=i.getDynamics(),o=a,s=this._pendingSpatial,c=e=>{let t=e.value;return!!t.formula&&!t.getAnchorNode().ext?.fixedRef},l=t=>e.search(t),u=e=>{let t=l(e);for(let n=0;n<t.length;n++)if(t[n].value===e.value)return!0;return!1},d=!1,f=e=>{let n=e.value,r=a.get(n);r&&(t.removeAll(r,dL),a===o&&(a=new Map(a)),a.delete(n),d=!0),!d&&!s.isEmpty()&&s.search(e).length>0&&(d=!0)},p=null;for(let i=0;i<n.length;i++){let a=n[i];if(!c(a)||!u(a))continue;d=!1;let o=Mr(l,a,(e,t,n,r)=>{if(!c(e)||!c(t))return;let i={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd};return e.value.getMerged(t.value,i,r)},(n,r)=>{for(let e=0;e<n.length;e++)f(n[e]);gL(t,null,n),e.removeAll(n,dL),e.load([r]),gL(t,[r],null)});o!==a&&((p??=[]).push(o),d&&r(o))}return a!==o&&i.setDynamics(a),p}_clearAll(){this._contentfulSpatial.clear(),this._values.clear(),this._spillSpatial.clear(),this._errorSpatial.clear(),this._pendingSpatial.clear(),this._circularSpatial.clear(),this._notifyValues.clear(),this._notifyBlank=null,this._notifySpillsInsert=[],this._notifySpillsRemove=[],this._notifyFormats.clear(),this._notifyPending.clear(),this._touchedFormulas=[]}_clearFormulas(){let e=this._container,t=this._gridId,n=e.getFormulas().getSpatialAt(t)?.all();if(!n||n.length===0)return;let r=e.getFormulas().clone(),i=e.getPrecedents().clone();mL(r,i,[],n);let a=e.getDynamics(),o=null;for(let e=0;e<n.length;e++){let t=n[e].value,r=a.get(t);r&&(o??=new Map(a),i.removeAll(r,dL),o.delete(t))}e.setFormulas(r),e.setPrecedents(i),o&&e.setDynamics(o),e.bumpCalcEpochs(!0);let s=e.getVolatiles();if(s&&s.size>0)for(let e of Array.from(s))e.gridId===t&&s.delete(e)}_seedNow(e,n){this._clearFormulas(),this._clearAll();let r=e?.hiddenRows?.length?e.hiddenRows:null,i=e?.hiddenColumns?.length?e.hiddenColumns:null,a=e?.filtered??!1;r===this._hiddenRows&&i===this._hiddenColumns&&a===this._filtered||(this._hiddenRows=r,this._hiddenColumns=i,this._filtered=a,this._publishMaps());let o={cycleId:0,isFull:!0};if(!e)return o;this._isProcessingJSON=!0;let s=n?.full??!1;try{if(e.data){let n=e.data;this._values.setValues(n);let r=this._values.getAxis()===t.IRange.Axis.Column;hI(this._errorSpatial,n,r);let i=PP(n,r,this._gridId);this._contentfulSpatial.load(i)}let n=this._gridId,r=this._container,i=r.getPrecedents(),a=r.getFormulas(),c={...this.getEntireCoords(),scope:n},l=e.formulas;if(l){let u=e.formulaArray,d=new Set,f=new Set;if(u){let e=u.length;for(let t=0;t<e;t++){let e=u[t],n=tf(e[0],c).split(`:`)[0];d.add(n);let r=Ud(e,c);r&&f.add(`${r.rowStart},${r.colStart}`)}}let p=l.length,m=Array(p),h=[],g=r.getRuntime(),_=this._context,v=r.getScope();v.colIndex=0,v.rowIndex=0,v.gridId=n;let y=r.isLegacyIntersect();for(let e=0;e<p;e++){let i=Ud(l[e],c);i.scope=n;let a=i.value,o=i.rowStart,s=i.colStart;v.colIndex=s,v.rowIndex=o;let u=y&&!(f.size>0&&f.has(`${o},${s}`)),p=r.createFormulaBlock(n,_,a,o,s,void 0,u),g=p.resolvedPrecedentsAt(o,s,!0,tL,nL),b=g.length;b===1&&(p=p.wrapImplicit(o,s,d)),i.value=new dI(i,n,p,r,this._unanchored),m[e]=i;let x=i.rowEnd,S=i.colEnd-s,C=x-o,w=[],T=p.getReferences(o,s);for(let e=0;e<b;e++){let r=g[e];if(t.FormulaError.isError(r))continue;let a=EI(T[e],nL[e],tL[e]),o=a.$absColEnd,s=a.$absRowEnd,c={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd+(o?0:S),rowEnd:r.rowEnd+(s?0:C),scope:r.scope??n,value:{formulaEntry:i,formulaBlockWidth:S+1,formulaBlockHeight:C+1,index:e,$absColStart:a.$absColStart,$absColEnd:o,$absRowStart:a.$absRowStart,$absRowEnd:s}};w.push(r),h.push(c)}}if(a.load(m),i.load(h),r.bumpCalcEpochs(!0),o.formulaInserts=this._formulaRecords(m),u){let e=[],s=[],l=new Map,d=this._values,f=u.length;for(let r=0;r<f;r++){let i=Ud(u[r],c),o=i.value??`dynamic`,f=o===`error`,p=i.colStart,m=i.rowStart;rL.colStart=p,rL.rowStart=m,rL.colEnd=p,rL.rowEnd=m,rL.scope=n;let h=a.search(rL);if(h.length!==1)continue;let _=h[0].value,v=_.nodeAt(m,p),y=i.colEnd,b=i.rowEnd,x={colStart:p,rowStart:m,colEnd:y,rowEnd:b};o===`fixed`&&(FP(v).fixedRef=x,_.densify()),v.cachedValue=f?t.FormulaError.BuiltIn.Spill:new iW(g,d,x);let S={colStart:p,rowStart:m,colEnd:y,rowEnd:b,value:new MP(x,0,o)};s.push(S),e.push({colStart:p,rowStart:m,colEnd:y,rowEnd:b,value:o}),TI(l,v,x,fI.Spill)}if(this._spillSpatial.load(s),l.size>0){i.load(Array.from(l.values()).flat()),r.bumpCalcEpochs(!1);let e=new Map(r.getDynamics());for(let[t,n]of l)e.set(t,n);r.setDynamics(e)}e.length>0&&(o.spillInserts=e)}let b=!1,x=e.volatile,S=x?x.length:0;if(S>0){let e=r.getVolatiles(),t=t=>{e.add(t)},n=Array(S);for(let e=0;e<S;e++){let r=ef(x[e],c);n[e]={...r};let i=a.search(r),o=i.length;for(let e=0;e<o;e++){let n=i[e];NI(n,r,t)}}this._markDirtyRegionsNow(n),b=!0}let C=this._contentfulSpatial,w=!C.isEmpty(),T=null,E={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:n};for(let e=0;e<p;e++){let t=m[e];if(!t)continue;let n=(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1),r=0;if(w){E.rowStart=t.rowStart,E.colStart=t.colStart,E.rowEnd=t.rowEnd,E.colEnd=t.colEnd;let e=C.search(E);for(let n=0;n<e.length;n++){let i=e[n];r+=(Math.min(i.rowEnd,t.rowEnd)-Math.max(i.rowStart,t.rowStart)+1)*(Math.min(i.colEnd,t.colEnd)-Math.max(i.colStart,t.colStart)+1)}}r<n&&(t.value.uncalculated=!0),(r<n||t.value?.getError())&&(T??=[]).push({rowStart:t.rowStart,colStart:t.colStart,rowEnd:t.rowEnd,colEnd:t.colEnd})}if(T&&(this._markDirtyRegionsNow(T),b=!0),s&&p>0){let e=Array(p);for(let t=0;t<p;t++){let n=m[t];e[t]={rowStart:n.rowStart,colStart:n.colStart,rowEnd:n.rowEnd,colEnd:n.colEnd}}this._markDirtyRegionsNow(e),b=!0}b&&(r.isLoading()?r.requestCalculateGrid(n):this.calculate())}}catch(e){throw e}finally{this._isProcessingJSON=!1}return o}_toJSONNow(e){let r=this._container.getFormulas().getSpatialAt(this._gridId)?.all(),i=r?r.length:0;i>0&&(r=Or(r,n.RangeAxis.Column,2,fL),r.sort(n.CoordUtils.rowFirstRangeComparator)),i=r?r.length:0;let a=this._hiddenRows,o=this._hiddenColumns,s=this._filtered;if(i===0&&!a&&!o&&!s)return null;let c={};a&&(c.hiddenRows=a),o&&(c.hiddenColumns=o),s&&(c.filtered=!0);let l=this._spillSpatial.all(),u=l.length;if(u>1&&l.sort(n.CoordUtils.rowFirstRangeComparator),i>0){let e=Array(i);for(let t=0;t<i;t++){let n=r[t];e[t]=n.value.toJSON(!1,n)}c.formulas=e}if(u>0){let e=this.getEntireCoords(),t=Array(u);for(let n=0;n<u;n++){let r=l[n];t[n]=[fd(r,e),r.value.getKind()]}c.formulaArray=t}let d=this._container.getVolatiles(),f=this._gridId,p=null;if(d.size>0){let e=d.values(),n=e.next(),r=this._values.getAxis()===t.IRange.Axis.Column,i=ei(!0);for(;!n.done;){let t=n.value;if(n=e.next(),t.gridId!==f||t.ext!==null&&t.ext.shownGroup!==0)continue;let a=t.colIndex,o=t.rowIndex,s=r?a:o,c=r?o:a;i.append(s,c)}p=i.done(!0)}let m=this._circularSpatial;if(!m.isEmpty()){let e=m.all(),t=p?p.slice():[];for(let n=0;n<e.length;n++){let r=e[n];t.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd})}p=Or(t,n.RangeAxis.Column,2)}let h=p?p.length:0;if(h>0){let e=Array(h);for(let t=0;t<h;t++){let n=p[t];e[t]=fd(n,this.getEntireCoords())}c.volatile=e}return c}},ZI=new WeakMap,QI=(e,t)=>{let n=e?.length??0;if(n!==(t?.length??0))return!1;for(let r=0;r<n;r++)if(e[r].min!==t[r].min||e[r].max!==t[r].max)return!1;return!0},$I=8,eL={rowStart:0,colStart:0,rowEnd:0,colEnd:0},tL=[],nL=[],rL={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},iL={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},aL={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},oL=Object.freeze({search:(e,t,r,i)=>i??n.CommonUtils.EmptyArray,getBoundingRange:()=>null,isEmpty:()=>!0}),sL={colStart:0,rowStart:0,colEnd:0,rowEnd:0},cL=[null],lL=Object.freeze({full:!0}),uL=[];function dL(e,t){return e.value===t.value}function fL(e,t){let n=e[0].value?.formula,r=e[1].value?.formula;if(n&&r&&n.isEquals(r))return t}function pL(e,t,n){let r=t.gridId;if(!r||!e.getNamedNodeInfo(r))return;let i=[r,...e.getNamedDependentNames(r)];for(let t=0;t<i.length;t++){let r=e.getNamedDependents(i[t]);for(let e=0;e<r.length;e++)n.push({...r[e]})}}function mL(e,t,n,r){(n&&n.length!==0||r&&r.length!==0)&&(gL(t,null,r),hL(e,null,r),hL(e,n,null),gL(t,n,null))}function hL(e,t,n){(t&&t.length!==0||n&&n.length!==0)&&(n&&e.removeAll(n,dL),t&&e.load(t))}function gL(e,n,r){let i=r?r.length:0;for(let n=0;n<i;n++){let i=r[n],a=i.value,o=a.registeredPrecedents;if(o){for(let t=0;t<o.length;t++)e.remove(o[t],dL);a.registeredPrecedents=null}let s=a.ref,c=s.rowStart,l=s.colStart,u=a.formula.resolvedPrecedentsAt(c,l);if(!u)continue;let d=u.length;for(let n=0;n<d;n++){let r=u[n];if(r===null||t.FormulaError.isError(r))continue;aL.rowStart=r.rowStart,aL.colStart=r.colStart,aL.rowEnd=r.rowEnd,aL.colEnd=r.colEnd,aL.scope=r.scope??i.scope,uL.length=0;let a=e.search(aL,!1,!1,uL),o=a.length;for(let t=0;t<o;t++){let n=a[t],r=n.value.formulaEntry;r&&r.value===i.value&&e.remove(n,dL)}}}let a=n?n.length:0;if(a===0)return;let o=[];for(let e=0;e<a;e++){let t=n[e],r=[],i=o.length;OI(t,o,r),o.length>i&&(t.value.registeredPrecedents=o.slice(i))}e.load(o)}uL.fill(null,0,10);var _L=class e{constructor(e,t,n,r,i,a,o=vU,s){this._runtime=e,this._skipOrigin=s,this._grid=t,this._range=n,this._localCoords=r??[t.getCoords()],this._iteratorOptions=i,this._segmentCache=a??_U(t),this._ZoneSizeMinor=o}getGrid(){return this._grid}clone(t,n){return new e(this._runtime,t??this._grid,this._range?.clone()??null,n,this._iteratorOptions,_U(t??this._grid,this._segmentCache),this._ZoneSizeMinor,this._skipOrigin)}clear(){this._sortedNumbers=void 0,this._aggregates=void 0,this._typedCounts=void 0,this._raw=void 0,this._lastNumber=void 0,this._frequencies=void 0,this._ranked=void 0}_getLastNumber(){let e=this._lastNumber;return e===void 0&&(e=function(e,n,r,i,a,o){if(n.getCount()===0)return;let s=n.getAxis()===t.IRange.Axis.Column,c=i.length,l=uU(a,s,o),u=l?.major??null,d=l?.minor??null,f=xU(e,a),p=f.coerce,m=f.defaultCoerce,h=a?{...wU,...a,overflowRun:!0}:wU,g=h.bounds,_,v=-1,y=-1;for(let e=0;e<c;e++){let a=i[e];if(!a)continue;let o=s?a.colStart:a.rowStart,c=s?a.rowStart:a.colStart,l=s?a.colEnd:a.rowEnd,f=s?a.rowEnd:a.colEnd;g.colStart=s?o:c,g.rowStart=s?c:o,g.colEnd=s?l:f,g.rowEnd=s?f:l;let b=n.getRuns(h),x=b.next();for(;!x.done;){let[e,n,i]=x.value;if(x=b.next(),u&&dU(u,e))continue;let a=Math.max(0,c-n),o=Math.min(i.length-1,f-n);if(!(a>o))for(let c=o;c>=a;c--){let a=n+c;if(d){let e=fU(d,a,!0)-n;if(e!==c){e<c&&(c=e+1);continue}}let o=s?a:e,l=s?e:a;if(o<v||o===v&&l<=y){if(s)break;continue}let u=i.at(c),f=IH(u,!0);if(!(f!==t.ScalarType.Number&&(!p||(u=p(u,f,m,r),IH(u,!0)!==t.ScalarType.Number)))&&(v=o,y=l,_=u,s))break}}}return _}(this._runtime,this._grid,this._range,this._localCoords,this._iteratorOptions,this._skipOrigin)??null,this._lastNumber=e),e??void 0}toLocalCoords(t,n){return new e(this._runtime,this._grid,this._range,Array.isArray(t)?t:[t],n??this._iteratorOptions,this._segmentCache,this._ZoneSizeMinor,this._skipOrigin)}getCoords(){let e=this._localCoords,t=null;for(let n=0;n<e.length;n++){let r=e[n];r&&(t=t?{rowStart:Math.min(t.rowStart,r.rowStart),colStart:Math.min(t.colStart,r.colStart),rowEnd:Math.max(t.rowEnd,r.rowEnd),colEnd:Math.max(t.colEnd,r.colEnd)}:{rowStart:r.rowStart,colStart:r.colStart,rowEnd:r.rowEnd,colEnd:r.colEnd})}return t}getSize(){let e=this._localCoords,t=e.length,n=0;for(let r=0;r<t;r++){let t=e[r];n+=mU(this._iteratorOptions,t,this._skipOrigin)}return n}_walk(){let e=this._raw;return e===void 0&&(e=bU(this._runtime,this._grid,this._range,this._localCoords,this._iteratorOptions?{...this._iteratorOptions,onError:`ignore`}:vL,this._segmentCache,this._ZoneSizeMinor,this._skipOrigin),this._raw=e),e}getCount(){return this._walk()?.count??0}getAggregates(e){if(e)return SU(bU(this._runtime,this._grid,this._range,this._localCoords,this._iteratorOptions?{...this._iteratorOptions,...e}:e,this._segmentCache,this._ZoneSizeMinor,this._skipOrigin));let n=this._aggregates;if(!n){let e=this._iteratorOptions?.onError??`ignore`,r=this._raw,i;r!==void 0&&(e===`ignore`||r===null||r.typed[t.ScalarType.Error]===0&&(this._iteratorOptions?.coerce==null||r.count===r.typed[t.ScalarType.Number]))?i=r:(i=bU(this._runtime,this._grid,this._range,this._localCoords,this._iteratorOptions,this._segmentCache,this._ZoneSizeMinor,this._skipOrigin),this._raw=i),n=SU(i),this._aggregates=n}return n}getSnappedSum(e){let t=this.getAggregates(),n=e??t.sum??0;return zU(n,RU(t))?BU(n,this._getLastNumber()):n}getSortedNumbers(){let e=this._sortedNumbers;return e||(e=JU.fromGrid(this._grid,this._localCoords,this._iteratorOptions,this._skipOrigin),this._sortedNumbers=e),e}getRanked(e){if(e)return WU(this._grid,this._localCoords,this._iteratorOptions,e,this._defaultCompare(),this._skipOrigin)[Symbol.iterator]();let t=this._ranked;return t||(t=WU(this._grid,this._localCoords,this._iteratorOptions,e,this._defaultCompare(),this._skipOrigin),this._ranked=t),t[Symbol.iterator]()}getFrequencies(e){if(e)return this._buildFrequencies(e);let t=this._frequencies;return t||(t=this._buildFrequencies(),this._frequencies=t),t}_buildFrequencies(e){let n=e?.includeBlanks?this.getTypedCounts([t.ScalarType.Null])[t.ScalarType.Null]:0,r=e?.filterFn?void 0:this.getCount()+n;return Cv.fromGrid(this._grid,this._localCoords,this._iteratorOptions,e,this._defaultCompare(),n,r,this._skipOrigin)}_defaultCompare(){let e=this._runtime.getLocaleProfile();return(t,n)=>sa.compare(t,n,e)}getTypedCounts(e){let n=this._typedCounts;if(!n){let e=this._walk()?.typed,r={[t.ScalarType.Number]:e?.[t.ScalarType.Number]??0,[t.ScalarType.String]:e?.[t.ScalarType.String]??0,[t.ScalarType.Boolean]:e?.[t.ScalarType.Boolean]??0,[t.ScalarType.Error]:e?.[t.ScalarType.Error]??0,[t.ScalarType.RichData]:e?.[t.ScalarType.RichData]??0,[t.ScalarType.Null]:0},i=this._localCoords,a=i.length,o=0;for(let e=0;e<a;e++){let t=i[e];t&&(o+=mU(this._iteratorOptions,t,this._skipOrigin))}r[t.ScalarType.Null]=Math.max(0,o-r[t.ScalarType.Number]-r[t.ScalarType.String]-r[t.ScalarType.Boolean]-r[t.ScalarType.Error]-r[t.ScalarType.RichData]),n=Object.freeze(r),this._typedCounts=n}if(e===void 0)return n;let r={},i=e.length;for(let t=0;t<i;t++)r[e[t]]=n[e[t]]??0;return r}get isIRangeStats(){return!0}},vL={onError:`ignore`},yL=class{constructor(e){this._errorEpoch=0,this._errorReconciled=null,this._deadSavepoints=null,this._emitter=null,this._closed=!1,this._backend=e.backend,this._calculation=e.calculation??null,this._host=e,this._valuesAxis=e.valuesAxis??t.IRange.Axis.Column,this._runtime=e.runtime,this._transactions=e.transactions??new g({transient:!0});let n=new yr({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),r=new ni({axis:this._valuesAxis}),i=new yr({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}}),a=new yr({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0}});this._rangeStats=new _L(this._runtime,r,null),this._stateId=this._transactions.create({formulaSpatial:n,cellValuesGrid:r,contentfulSpatial:i,spillSpatial:new yr,volatile:null,pendingSpatial:new yr,calcErrorsSpatial:new yr,circularSpatial:new yr,errorSpatial:a,deleted:!1,hiddenRows:null,hiddenColumns:null,filtered:!1})}_loadContent(e,n){let r=this._valuesAxis===t.IRange.Axis.Column,i=n.formulas;i.clear(),e.formulas&&i.load(this._entriesFromJSON(e.formulas));let a=n.values;a.clear();let o=n.contentful;o.clear();let s=n.errorValues;s.clear();let c=e.data;if(c&&c.length>0){a.setValues(c),o.load(PP(c,r));let e=_I(c,r);e.length>0&&s.load(Or(e,t.IRange.Axis.Column,2**53-1))}let l=n.spills;if(l.clear(),e.formulaArray){let t=this._spillsFromJSON(e.formulaArray);t.length>0&&l.load(t)}n.volatile=e.volatile&&e.volatile.length>0?e.volatile:null,n.pending.clear(),n.calcErrors.clear(),n.circulars.clear()}_getBackend(){return this._backend}getStateId(){return this._stateId}_getState(e){return e?e.getState(this._stateId):this._transactions.getState(this._stateId)}_getStateAt(e){let t=this._transactions;return e===t.getPendingTransaction()?.getId()?this._getState():t.getStateAt(e,this._stateId)}getFormulaAt(e,t){let n=this._getState().formulaSpatial.search({colStart:t,rowStart:e,colEnd:t,rowEnd:e});return n.length>0?n[0].value??null:null}getFormulas(e){return this._getState(e).formulaSpatial}getValues(e){return this._getState(e).cellValuesGrid}getContentful(e){return this._getState(e).contentfulSpatial}getSpills(e){return this._getState(e).spillSpatial}getPending(e){return this._getState(e).pendingSpatial}getCalcErrors(e){return this._getState(e).calcErrorsSpatial}getCirculars(e){return this._getState(e).circularSpatial}getVolatileRegions(){return this._getState().volatile}getRangeStats(){let e=this._getState().cellValuesGrid;return this._rangeStats.getGrid()!==e&&(this._rangeStats=this._rangeStats.clone(e)),this._rangeStats}getErrorValues(){let e=this._getState().cellValuesGrid,n=this._errorReconciled;if(n&&n.values===e&&n.epoch===this._errorEpoch)return n.spatial;let r=new yr,i=function(e){let n=[],r=e.getAxis()===t.IRange.Axis.Column,i=e.getRuns(),a=i.next();for(;!a.done;){let[e,t,o]=a.value;a=i.next(),gI(n,e,t,o,r)}return n}(e);return i.length>0&&r.load(Or(i,t.IRange.Axis.Column,2**53-1)),this._errorReconciled={values:e,epoch:this._errorEpoch,spatial:r},r}_beginWrite(e,t=!0){let n=this,r=this._transactions,i=this._getState(),a=e?.cloneKey??r.getCurrentTransaction()?.getSavepointId(),o={},s=null;return{current:i,noteArray(e){(s??=[]).push(e)},get formulas(){return o.formulaSpatial??=i.formulaSpatial.clone(a)},set formulas(e){o.formulaSpatial=e},get values(){return o.cellValuesGrid??=i.cellValuesGrid.clone(a)},set values(e){o.cellValuesGrid=e},get contentful(){return o.contentfulSpatial??=i.contentfulSpatial.clone(a)},set contentful(e){o.contentfulSpatial=e},get spills(){return o.spillSpatial??=i.spillSpatial.clone(a)},set spills(e){o.spillSpatial=e},get pending(){return o.pendingSpatial??=i.pendingSpatial.clone(a)},set pending(e){o.pendingSpatial=e},get calcErrors(){return o.calcErrorsSpatial??=i.calcErrorsSpatial.clone(a)},set calcErrors(e){o.calcErrorsSpatial=e},get circulars(){return o.circularSpatial??=i.circularSpatial.clone(a)},set circulars(e){o.circularSpatial=e},get errorValues(){return o.errorSpatial??=i.errorSpatial.clone(a)},set errorValues(e){o.errorSpatial=e},get volatile(){return o.volatile===void 0?i.volatile:o.volatile},set volatile(e){o.volatile=e},commit(){if(Object.keys(o).length===0)return;let e=r.getCurrentTransaction()?.getSavepointId(),i=r.beginCommit(e===void 0?void 0:{onRollback:()=>{(n._deadSavepoints??=new Set).add(e)}});try{let e=o.cellValuesGrid;if(e&&(n._rangeStats=n._rangeStats.clone(e)),i.updateState(n._stateId,o),t){let e={inputsId:String(++bL),arrays:s};s=null,n._notify(`onInputsWritten`,e)}i.commit()}catch(e){throw i.rollback(),e}}}}_write(e,t,n=!0){let r=this._beginWrite(t,n);e(r),r.commit()}_amend(e){let t=this._transactions.beginCommit();try{t.updateState(this._stateId,e),t.amend()}catch(e){throw t.rollback(),e}}setInputs(e,n,r){let i=n?n.length:0,a=e?.tuples;return(i>0||a&&a.length>0)&&this._write(e=>{let o=e.formulas;if(a){let e=this._valuesAxis===t.IRange.Axis.Column,n={majorStart:0,minorStart:0,majorEnd:0,minorEnd:0};for(let t=0;t<a.length;t++){let r=a[t];n.majorStart=n.majorEnd=r[0];let i=r[1];for(let t=0;t<i.length;t++){let r=i[t];n.minorStart=r[0],n.minorEnd=r[0]+r[1].length-1;let a=zr(n,e);o.has(a)&&xL(o,a)}}}for(let e=0;e<i;e++){let t=n[e],r={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd},i=t.value;i==null?o.has(r)&&xL(o,r):o.insertNonOverlapping({...r,value:new tM(i,r,null)},{noMerge:!0})}let s=r?.arrayFixed,c=s?s.rowStart:-1,l=s?s.colStart:-1;for(let t=0;t<i;t++){let r=n[t];r.value!==null&&r.value!==void 0&&(c===r.rowStart&&l===r.colStart||SL(o,e.spills,r))}this._writeInputValues(e,a,n,s)},r),this._backend.setInputs(e,n,r).then(this._adopter())}_writeInputValues(e,n,r,i){let a=this._valuesAxis===t.IRange.Axis.Column,o=e.current,s=n&&n.length>0?PP(n,a):null,c=s?s.length:0;if(!o.spillSpatial.isEmpty()){let t=o.spillSpatial;for(let n=0;n<c;n++){let r=s[n],i=t.search(r);for(let t=0;t<i.length;t++){let n=i[t];mI(n.rowStart,n.colStart,r)&&e.values.delete(n)}}let n=e.spills,i=e=>{let t=n.search(e);for(let r=0;r<t.length;r++){let i=t[r];mI(i.rowStart,i.colStart,e)&&n.remove(i)}};for(let e=0;e<c;e++)i(s[e]);if(r)for(let e=0;e<r.length;e++)i(r[e])}if(i){let t={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd};e.spills.insertNonOverlapping({...t,value:new MP(t,0,`fixed`)})}if(!s)return;e.values.setValues(n);let l=e.contentful;for(let e=0;e<c;e++)l.insertNonOverlapping(s[e]);if(!o.circularSpatial.isEmpty()){let t=e.circulars;for(let e=0;e<c;e++){let n=s[e];t.insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:null})}}let u=_I(n,a);if(!o.errorSpatial.isEmpty()||u.length>0){let t=e.errorValues;for(let e=0;e<c;e++){let n=s[e];t.insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:null})}for(let e=0;e<u.length;e++)t.insertNonOverlapping(u[e])}}_removeInputValues(e,t){let n=e.current,r={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd};if(e.values.delete(r),e.contentful.insertNonOverlapping({...r,value:null}),!n.spillSpatial.isEmpty()){let t=e.spills,n=t.search(r);for(let e=0;e<n.length;e++){let i=n[e];mI(i.rowStart,i.colStart,r)&&t.remove(i)}}n.circularSpatial.isEmpty()||e.circulars.insertNonOverlapping({...r,value:null}),n.errorSpatial.isEmpty()||e.errorValues.insertNonOverlapping({...r,value:null})}remove(e,t){let n=t?.clearArrays??!1;this._write(t=>{let r=null;if(n&&!t.current.spillSpatial.isEmpty()){let n=(e,n)=>{e&&t.noteArray(e),n&&t.noteArray(n)};r=FI(e,t.spills,t.values,t.contentful,n),wI(-1,[e],[],t.contentful,t.spills,t.values,void 0,void 0,n)}t.current.formulaSpatial.has(e)&&xL(t.formulas,e),this._removeInputValues(t,e),r?.()},t);let r=t;if(t?.clearArrays!==void 0){let{clearArrays:e,...n}=t;r=n}return this._backend.remove(e,r).then(this._adopter())}_shiftInputValues(e,n,r){let i=r===t.IRange.Direction.Left||r===t.IRange.Direction.Right,a=r===t.IRange.Direction.Right||r===t.IRange.Direction.Down,o=e.current,s=a?this._insertValidator():void 0,c=o.cellValuesGrid.getCoords();if(c){let t=(a?1:-1)*(i?n.colEnd-n.colStart+1:n.rowEnd-n.rowStart+1),o=e.values,l=e.spills,u=e.contentful,d=FI(n,l,o,u,(t,n)=>{t&&e.noteArray(t),n&&e.noteArray(n)},!i);if(a){let e={...n,colEnd:i?Math.max(n.colEnd,c.colEnd)+(n.colEnd-n.colStart+1):n.colStart,rowEnd:i?n.rowStart:Math.max(n.rowEnd,c.rowEnd)+(n.rowEnd-n.rowStart+1)},r=u.search(e);for(let e=0;e<r.length;e++){let a=r[e],o={...n};i?o.colEnd=Math.max(o.colEnd,a.colEnd)+t:o.rowEnd=Math.max(o.rowEnd,a.rowEnd)+t,s(o)}}o.shift(n,r),e.spills=l.shift({range:n,direction:r,cloneIfUpdate:!1,coordValidator:s}),e.contentful=u.shift({range:n,direction:r,cloneIfUpdate:!1,coordValidator:s}),d?.(a,i?0:t,i?t:0)}o.errorSpatial.isEmpty()||(e.errorValues=e.errorValues.shift({range:n,direction:r,cloneIfUpdate:!1,coordValidator:s}))}_insertValidator(){let e=this.getEntireCoords();return(t,r)=>{if(!n.CoordUtils.isRangeWithinRange(t,e))throw new n.OutOfBoundsError(r??(0,n.t)(`error.sheet.insertOob`))}}shift(e){return this._write(t=>{this._shiftInputValues(t,e.range,e.direction),t.formulas.shift({range:e.range,direction:e.direction})},e),this._backend.shift(e).then(this._adopter())}autoFill(e,t,n){let r=typeof e==`string`?Ad(e):e,i=typeof t==`string`?Ad(t):t;return this._write(e=>{let t=e.formulas,n=t.createCopiedEntries(r,i);wL(t,i,n.inserts)},n),this._backend.autoFill(e,t,n).then(this._adopter())}getSnapshot(e){let t=this,n=this._backend.getSnapshot(e),r=this._getState().formulaSpatial.clone(),i=e?.range,a={...typeof i==`string`?Ad(i):i};a.scope=this.getId();let o=e?.isCut??!1;return{...n,copyTo(e,i){let s=e.grid??t._host.getGrid?.(e.gridId)??null;if(!s)return n.copyTo(e,i);let c=typeof e.range==`string`?Ad(e.range):e.range,l=i?.isCut??o,u=s._copyFormulaEntries(r,a,c,{transpose:i?.transpose??!1,cutFrom:l?a:void 0},i),d=e=>{let t=e._calculation?.getStatus();return t===X.Status.Running||t===X.Status.Starting};return s._calculation===t._calculation&&d(t)&&d(s)?n.copyTo(e,i).then(s._adopter()):u.length===0?Promise.resolve({cycleId:0}):s._backend.setInputs(null,u,{commitId:i?.commitId}).then(s._adopter())},getCoords:()=>a}}_copyFormulaEntries(e,t,n,r,i){let a=e.createCopiedEntries(t,n,r),o=[];return this._write(e=>{let t=wL(e.formulas,n,a.inserts);o=Array(t.length);for(let e=0;e<t.length;e++){let n=t[e];o[e]={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:n.value.a1}}},i),o}seed(e,t){this._write(t=>this._loadContent(e,t),void 0,!1);let n=CL(e.hiddenRows),r=CL(e.hiddenColumns);return this._holdOwnerState({hiddenRows:n,hiddenColumns:r,filtered:e.filtered??!1}),(n||r)&&(e={...e,hiddenRows:n??void 0,hiddenColumns:r??void 0}),this._backend.seed(e,t)}revert(e){return this._backend.revert(e).then(this._adopter())}delete(e){if(this._hasState()){let e=this._transactions.beginCommit();try{e.updateState(this._stateId,{deleted:!0}),e.commit()}catch(t){throw e.rollback(),t}}this._backend.delete(e)}_isLive(){if(this._closed)return!1;let e=this._transactions.getState(this._stateId);return e!==void 0&&!e.deleted}setReferenceAt(e,t,n,r){return this._backend.setReferenceAt(e,t,n,r).then(n=>this._adoptAt(e,t,n))}setReferenceModeAt(e,t,n,r,i){return this._backend.setReferenceModeAt(e,t,n,r,i).then(n=>this._adoptAt(e,t,n))}calculate(e){return this._backend.calculate(e)}markDirtyRegions(e){this._backend.markDirtyRegions(e)}_resendFormula(e,t){return this._backend.setInputs(null,[{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:t}]).then(this._adopter())}_isOwned(){return!0===this._host.isOwned}_requestPass(){this._backend.requestPass()}getGraphNeighborsAt(e,t,n){return this._backend.getGraphNeighborsAt(e,t,n)}_getNameGraph(e,t){return this._backend.getNameGraph(e,t)}evaluateAt(e,t,n){return this._backend.evaluateAt(e,t,n)}_isClosed(){return this._closed}_hasState(){return this._transactions.getState(this._stateId)!==void 0}_evaluateScalarAt(e,t,n){return this._backend.evaluateScalarAt(e,t,n)}_setBody(e){return this._backend.setBody(e).then(this._adopter())}isVolatileAt(e,t){return this._backend.isVolatileAt(e,t)}addListeners(e,t){return this._emitter??=new x(this),this._emitter.addListeners(e,t)}_notify(e,t){this._emitter?.notify(e,{params:t})}getEntireCoords(){return this._backend.getEntireCoords()}resize(e){this._backend.resize(e)}setHidden(e,r,i){let a=CL(r);this._holdOwnerState(e===t.IRange.Axis.Column?{hiddenColumns:a}:{hiddenRows:a}),this._backend.setHidden(e,a??n.CommonUtils.EmptyArray,i)}setFiltered(e,t){this._holdOwnerState({filtered:e}),this._backend.setFiltered(e,t)}_holdOwnerState(e){let t=this._transactions.getState(this._stateId);if(!t||!(e.hiddenRows!==void 0&&e.hiddenRows!==t.hiddenRows||e.hiddenColumns!==void 0&&e.hiddenColumns!==t.hiddenColumns||e.filtered!==void 0&&e.filtered!==t.filtered))return;let n=this._transactions.beginCommit();try{n.updateState(this._stateId,e),n.commit()}catch(e){throw n.rollback(),e}}getId(){return this._backend.getId()}async toJSON(e){let t=this._calculation?.getStatus();return t!==X.Status.Off&&t!==X.Status.Error&&t!==X.Status.Stopping&&this._calculation?this._backend.toJSON(e):this._content(e)}_seedContent(){return this._host.isOwned?this._content({includeData:!0})??{}:null}_content(e){let t=this._getState(),r={};if(e?.includeData){let e=function(e){let t=[],n=null,r=e.getRuns(),i=r.next();for(;!i.done;){let[e,a,o]=i.value;i=r.next(),n&&n[0]===e||(n=[e,[]],t.push(n)),n[1].push([a,o])}return t}(t.cellValuesGrid);e.length>0&&(r.data=e)}t.hiddenRows&&(r.hiddenRows=t.hiddenRows),t.hiddenColumns&&(r.hiddenColumns=t.hiddenColumns),t.filtered&&(r.filtered=!0);let i=t.formulaSpatial,a=i.all(),o=a.length;if(o>0){a.sort(n.CoordUtils.rowFirstRangeComparator);let e=this.getEntireCoords(),s=t.spillSpatial.all(),c=null;if(s.length>0){c=new Map;for(let t=0;t<s.length;t++){let n=s[t];c.set(`${n.rowStart},${n.colStart}`,[fd(n,e),n.value.getKind()])}}let l=Array(o),u=null;for(let e=0;e<o;e++){let t=a[e],n=t.value,r=c?.get(`${t.rowStart},${t.colStart}`);r&&(u??=[]).push(r);let i=n.isCompiled()?n.getTextAt(t.rowStart,t.colStart,!1):n.a1;l[e]=[fd(t),i]}r.formulas=l,u&&(r.formulaArray=u);let d=t.volatile;if(d){let t=[];for(let n=0;n<d.length;n++){let r=ef(d[n],e);r&&i.search(r).length>0&&t.push(d[n])}t.length>0&&(r.volatile=t)}}return o!==0||r.data||r.hiddenRows||r.hiddenColumns||r.filtered?r:null}_spillsFromJSON(e){let t=this.getEntireCoords(),n=[];for(let r=0;r<e.length;r++){let i=Ud(e[r],t);if(!i)continue;let a={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd};n.push({...a,value:new MP(a,0,i.value??`dynamic`)})}return n}_entriesFromJSON(e){let t=this.getEntireCoords(),n=[];for(let r=0;r<e.length;r++){let i=Ud(e[r],t);if(!i||typeof i.value!=`string`)continue;let a={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd};n.push({...a,value:new tM(i.value,a,null)})}return n}_onCalculated(e){if(this._closed)return;let t=this._vendSnapshots(e.commitId);t&&(this._errorEpoch++,this._adopt(e,t),this._applyValueVend(e,t),this._notify(`onComplete`,e))}_adopter(){let e=this._transactions.getCurrentTransaction()?.getSavepointId();return t=>(this._closed||e!==void 0&&this._deadSavepoints?.has(e)||this._adopt(t),t)}_adoptAt(e,t,r){if(!r||this._closed)return r;let i={colStart:t,rowStart:e,colEnd:t,rowEnd:e},a=this._getState().formulaSpatial,o=a.search(i),s=null,c=!1;for(let e=0;e<o.length;e++){let t=o[e];if(!n.CoordUtils.isEqualRanges(t,i))continue;let l=t.value,u=TL(l,r);u!==l&&(c=!0,s??=a.clone(this._transactions.getCurrentTransaction()?.getSavepointId()),s.insertNonOverlapping({...t,value:u},{noMerge:!0}))}return s&&this._amend({formulaSpatial:s}),this._notify(`onFormulasChanged`,c),r}_vendSnapshots(e){let t=this._transactions,n=this._getState(),r=t.getPendingTransaction(),i=r?{id:r.getId(),state:n,open:!0}:null;if(e===void 0||i&&e===i.id)return[i??{id:t.getCurrentCommit(!1).getId(),state:n,open:!1}];let a=t.getCurrentCommit(!1).getId();if(t.getStateAt(e,this._stateId)===void 0||t.getStateAt(a,this._stateId)===void 0)return null;let o=[],s=!1;for(let n=4,r=0;!s;n*=8){let i=t.getLog(a,n);for(let n=r;n<i.length;n++){let r=i[n].getId(),a=t.getStateAt(r,this._stateId);if(a&&o.push({id:r,state:a,open:!1}),r===e){s=!0;break}}if(i.length<n)break;r=i.length}return s&&o.length!==0?(o.reverse(),i&&o.push(i),o):null}_vendParentState(e){let t=this._transactions;if(e.open)return t.getStateAt(t.getCurrentCommit(!1).getId(),this._stateId)??null;let n=t.getLog(e.id,2);return n.length<2?null:t.getStateAt(n[1].getId(),this._stateId)??null}_writeVend(e,t){let n=this._transactions;n.amend(e.id,()=>{let e=n.beginCommit();try{e.updateState(this._stateId,t),e.commit()}catch(t){throw e.rollback(),t}})}_adopt(e,t){let r=e.formulaInserts,i=e.formulaRemoves;if(!e.isFull&&!r&&!i)return;let a=t??this._vendSnapshots(e.commitId);if(!a)return;let o=a[0].state.formulaSpatial;if(e.isFull){let e=o.all();for(let t=0;t<e.length;t++)e[t].value.setBlock(null)}let s=e=>`${e.rowStart},${e.colStart},${e.rowEnd},${e.colEnd}`,c=r?r.length:0,l=null;if(c>0&&i){l=new Map;for(let e=0;e<c;e++)l.set(s(r[e]),r[e])}let u=!1,d=new Map,f=(e,t)=>{let n=d.get(e);return n||(n=TL(e,t),n!==e&&(u=!0,d.set(e,n)),n)},p=this._transactions.getPendingTransaction(),m=null,h=null,g=!1;for(let e=0;e<a.length;e++){let t=a[e],u=t.state.formulaSpatial,d=e===a.length-1;if(e>0&&u===m){h&&(this._writeVend(t,{formulaSpatial:h}),d&&(g=!0));continue}let _=e===0,v=e=>_||DL(o,u,e),y=e=>_||EL(o,e),b=[],x=!1,S=new Set;if(i)for(let e=0;e<i.length;e++){let t=i[e];if(!v(t))continue;let r=u.search(t),a=[],o=!1;for(let e=0;e<r.length;e++){let i=r[e],c=i.value,u=l?.get(s(i));if(!u||!n.CoordUtils.isRangeWithinRange(i,t)){o=!0;continue}let d=c;S.has(u)||(d=f(c,u.value),S.add(u)),d!==c&&(o=!0),a.push({coords:{colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd},entry:d})}o&&(x=!0,b.push({region:t,kept:a}))}let C=[],w=[];for(let e=0;e<c;e++){let t=r[e];if(S.has(t))continue;let i=t.value,a=u.search(t),o=null;for(let e=0;e<a.length;e++)if(n.CoordUtils.isEqualRanges(a[e],t)){o=a[e];break}if(o){if(y(o)){let e=o.value,n=f(e,i);n!==e&&(x=!0,w.push({...t,value:n}))}continue}if(!v(t))continue;let s={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd},c=new tM(``,s,null);c.setBlock(i),C.push({...s,value:c}),x=!0}let T=null;if(x){let e=t.open?p?.getSavepointId():void 0;T=u.clone(e);for(let e=0;e<b.length;e++){let t=b[e];T.insertNonOverlapping({...t.region,value:null},{noMerge:!0});for(let e=0;e<t.kept.length;e++)T.insert({...t.kept[e].coords,value:t.kept[e].entry})}for(let e=0;e<w.length;e++)T.insertNonOverlapping(w[e],{noMerge:!0});for(let e=0;e<C.length;e++)T.insertNonOverlapping(C[e],{noMerge:!0});this._writeVend(t,{formulaSpatial:T}),d&&(g=!0)}m=u,h=T}(g||u)&&this._notify(`onFormulasChanged`,u)}_applyValueVend(e,r){let i=e=>(e.open?this._getState():this._getStateAt(e.id))?.formulaSpatial,a=i(r[0]);if(!a)return;let o=e=>{let t=null;for(let n=0;n<e.length;n++){let r=i(e[n]);r&&r!==a&&(t??=[]).push(r)}return t},s=(e,t)=>{if(!t)return!0;for(let n=0;n<t.length;n++)if(!DL(a,t[n],e))return!1;return!0},c=(e,t)=>{let r=[],i=t=>{let i=n.CoordUtils.intersectRanges(t,e);i&&r.push(i)};for(let n=0;n<t.length;n++){let r=t[n],o=r.search(e);for(let e=0;e<o.length;e++)EL(a,o[e])||i(o[e]);let s=a.search(e);for(let e=0;e<s.length;e++)EL(r,s[e])||i(s[e])}return r},l=this._vendParentState(r[0]),u=e=>e.open?this._transactions.getCurrentTransaction()?.getSavepointId():void 0,d=(e,t,n)=>{let i=new Map;for(let t=0;t<r.length;t++){let n=e(r[t].state),a=i.get(n);a?a.push(r[t]):i.set(n,[r[t]])}let a=[];return i.forEach((r,i)=>{let s=i;if(l&&e(l)===i){s=n(i,r[0]);for(let e=0;e<r.length;e++)this._writeVend(r[e],{[t]:s})}a.push([s,o(r)])}),a},f=this._valuesAxis,p=f===t.IRange.Axis.Column,m=(e,t,n)=>({colStart:p?e:t,rowStart:p?t:e,colEnd:p?e:t+n-1,rowEnd:p?t+n-1:e}),h=(e,t)=>{if(!t)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r][0],a=e[r][1],o=[];for(let e=0;e<a.length;e++){let n=a[e][0],r=a[e][1],c=r.length;if(s(m(i,n,c),t)){o.push(a[e]);continue}let l=-1,u=[];for(let e=0;e<c;e++)s(m(i,n+e,1),t)?(l<0&&(l=e),u.push(r.at(e))):l>=0&&(o.push([n+l,u]),u=[],l=-1);l>=0&&o.push([n+l,u])}o.length>0&&n.push([i,o])}return n},g=(e,t)=>t?e.filter(e=>s(e,t)):e,_=(e,t)=>{if(!t)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(s(i,t)){n.push(i);continue}let a=Mh([i],c(i,t));for(let e=0;e<a.length;e++)n.push({...a[e],value:i.value})}return n},v=(e,t,n)=>{if(!t)return void e.clear();let r=e.all(),i=[];for(let e=0;e<r.length;e++){let a=r[e];if(s(a,t))continue;if(!n){i.push(a);continue}let o=c(a,t);for(let e=0;e<o.length;e++)i.push({...o[e],value:a.value})}e.clear();for(let t=0;t<i.length;t++)e.insertNonOverlapping(i[t])},y=!0===e.isFull,b=e.valueInserts,x=e.valueRemoves;if(b||x){let e=d(e=>e.cellValuesGrid,`cellValuesGrid`,e=>e.clone());for(let t=0;t<e.length;t++){let[n,r]=e[t];if(x){let e=g(x,r);for(let t=0;t<e.length;t++)n.delete(e[t])}b&&n.setValues(h(b.tuples,r))}let t=d(e=>e.contentfulSpatial,`contentfulSpatial`,(e,t)=>e.clone(u(t)));for(let e=0;e<t.length;e++){let[n,r]=t[e];if(x){let e=g(x,r);for(let t=0;t<e.length;t++)n.insertNonOverlapping({...e[t],value:null})}if(b){let e=h(b.tuples,r);for(let t=0;t<e.length;t++){let r=e[t][0],i=e[t][1];for(let e=0;e<i.length;e++){let t=m(r,i[e][0],i[e][1].length);n.insertNonOverlapping({...t,value:new NP(t,f)})}}}}this._rangeStats=this._rangeStats.clone(this._getState().cellValuesGrid),this._rangeStats.clear()}let S=e.spillInserts,C=e.spillRemoves;if(y||S||C){let e=d(e=>e.spillSpatial,`spillSpatial`,(e,t)=>e.clone(u(t)));for(let t=0;t<e.length;t++){let[r,i]=e[t];if(y&&v(r,i,!1),C){let e=g(C,i);for(let t=0;t<e.length;t++)r.remove(e[t])}if(S){let e=g(S,i),t=Array(e.length);for(let r=0;r<e.length;r++){let i=n.CoordUtils.sanitizeRange(e[r]);t[r]={...i,value:new MP(i,0,e[r].value)}}t.length>0&&r.load(t)}}}let w=e.errorInserts,T=e.errorRemoves;if(y||w||T){let e=d(e=>e.calcErrorsSpatial,`calcErrorsSpatial`,(e,t)=>e.clone(u(t)));for(let t=0;t<e.length;t++){let[n,r]=e[t];if(y&&v(n,r,!0),T){let e=_(T,r);for(let t=0;t<e.length;t++)n.remove(e[t])}if(w){let e=_(w,r);e.length>0&&n.load(e)}}}let E=e.pendingUpdates;if(y||E){let e=d(e=>e.pendingSpatial,`pendingSpatial`,(e,t)=>e.clone(u(t)));for(let t=0;t<e.length;t++){let[n,r]=e[t];if(y&&v(n,r,!0),E){let e=_(E,r);for(let t=0;t<e.length;t++){let r=e[t];n.insertNonOverlapping(!1===r.value?{...r,value:null}:r)}}}}let D=e.circularUpdates;if(y||D){let e=d(e=>e.circularSpatial,`circularSpatial`,(e,t)=>e.clone(u(t)));for(let t=0;t<e.length;t++){let[n,r]=e[t];if(y&&v(n,r,!1),D){let e=g(D,r);for(let t=0;t<e.length;t++)n.insertNonOverlapping(e[t])}}}}close(){this._closed||(this._closed=!0,this._backend.close(),this._notify(`onClose`,void 0),this._emitter?.close(),this._emitter=null,this._transactions.remove(this._stateId))}get[Symbol.toStringTag](){return`[CalcGrid]`}},bL=0,xL=(e,t)=>{e.insertNonOverlapping({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,value:null},{noMerge:!0})},SL=(e,t,n)=>{let r=e.search(n);if(r.length!==1)return;let i=r[0];if(i.colStart!==n.colStart||i.rowStart!==n.rowStart||i.colEnd!==n.colEnd||i.rowEnd!==n.rowEnd)return;let a=e=>{let n=t.search({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowStart});for(let t=0;t<n.length;t++){let r=n[t];if(r.value.isFixed()&&mI(r.rowStart,r.colStart,e))return!0}return!1};Mr(t=>e.search(t),i,(e,t,n,r)=>{if(a(e)||a(t))return;let i=e.value.getMerged(t.value,n,r);return i&&(i.block=null),i},(t,n)=>{e.removeAll(t,HI),e.insertNonOverlapping(n,{noMerge:!0})})},CL=e=>{if(!e||e.length===0)return null;let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]={min:e[n].min,max:e[n].max};return t},wL=(e,n,r)=>{if(xL(e,n),r.length===0)return r;let i=r.length>1?Or(r,t.IRange.Axis.Column,2**53-1,jr):r;return e.load(i),i},TL=(e,t)=>{let n=e.imageBlock(t);if(n===e.a1)return e.setBlock(t),e;let r=new tM(n,e.ref,t);return r.relativeForm()===e.relativeForm()?(e.setBlock(t),e):r},EL=(e,t)=>{let r=e.search(t);for(let e=0;e<r.length;e++)if(r[e].value===t.value&&n.CoordUtils.isEqualRanges(r[e],t))return!0;return!1},DL=(e,t,n)=>{let r=t.search(n);if(r.length!==e.search(n).length)return!1;for(let t=0;t<r.length;t++)if(!EL(e,r[t]))return!1;return!0},OL=class{constructor(e){this._body=null,this._blank=null,this._bodyRequest=null,this._bodyPending=!1,this._onDispose=e.onDispose,this._onCalculated=e.onCalculated,this._id=e.id,this._grid=e.grid,this._transactions=e.transactions??null,this._container=e.container,this._context=e.context}getId(){return this._id}setBody(e,t){return this._sendBody({options:e,onAnswered:t})}_sendBody(e){this._bodyRequest=e,this._bodyPending=!0,this._body=null;let t=this._amendCurrent(()=>this._grid._setBody(e.options));return t.then(t=>{this._bodyRequest===e&&this._bodyPending&&!this._grid._isClosed()&&(this._refine(t),this._getEntry()?.value.isCompiled()&&(this._bodyPending=!1,e.onAnswered?.()))},()=>{}),t}_restart(){let e=this._bodyRequest;if(e&&this._bodyPending)return this._sendBody(e);let t=this._body;if(!t)return null;let n=this._grid._resendFormula(t.coords,t.text);return n.then(e=>{this._body===t&&this._refine(e)},()=>{}),n}getBody(){return this._body}_onComplete(e){this._refine(e),e.blankRegion!==void 0&&(this._blank=e.blankRegion),this._onCalculated?.(e)}_refine(e){let t=e.formulaInserts;if(!t||t.length===0)return;let n=t[0],r=n.value;r&&(this._body={coords:this._coordsOf(n),text:r.getTextAt(n.rowStart,n.colStart)})}_resync(){this._bodyPending=!1;let e=this._getEntry();this._body=e?{coords:this._coordsOf(e),text:e.value.getTextAt(e.rowStart,e.colStart)}:null}_rewrite(e,t){return this._write(e,t)}_write(e,t){this._bodyRequest=null,this._bodyPending=!1;let n=this._body={coords:this._coordsOf(e),text:t},r=this._amendCurrent(()=>this._grid.setInputs(null,[{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:t}]));return r.then(e=>{this._body===n&&this._refine(e)},()=>{}),r}setPlaceholder(e){let t=this.getCoords()??kL;return this._write(t,e)}moveBody(e){let t=this._getEntry();if(!t)return null;let n=t.value.getTextAt(t.rowStart,t.colStart);return this._amendCurrent(()=>this._grid.remove(this._grid.getEntireCoords())),this._write(e,n)}requestPass(){this._grid._requestPass()}clear(){return this._body=null,this._amendCurrent(()=>this._grid.remove(this._grid.getEntireCoords()))}getCoords(){let e=this._getEntry();return e?this._coordsOf(e):null}_coordsOf(e){return{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}}getBlock(){return this._bodyPending?null:this._getEntry()?.value.block??null}_getCalcGrid(){return this._grid}getView(){return this._getEntry()?.value??null}_evaluateScalarAt(e,t,n){return this._grid._evaluateScalarAt(e,t,n)}getValueGrid(){return this._grid.getValues()}getBlankRegion(){return this._blank}getBlankValueWithin(e){let t=this._blank;if(!t)return null;let n=t.extent;return e.rowStart<n.rowStart||e.rowEnd>n.rowEnd||e.colStart<n.colStart||e.colEnd>n.colEnd?null:t.value??null}getValues(e){let t=this._getEntry(),n=e??(t?this._coordsOf(t):null);return n?new iW(this._container.getRuntime(),this._grid.getValues(),n,null,!1,!1,this.getBlankValueWithin(n)):null}dispose(){this._body=null,this._onDispose?.(),this._amendCurrent(()=>{this._grid._hasState()&&this._grid.remove(this._grid.getEntireCoords()),this._grid.delete()})}_amendCurrent(e){let t=this._transactions;if(!t||t.getCurrentTransaction())return e();let n=t.beginCommit();try{let t=e();return n.amend(),t}catch(e){throw n.rollback(),e}}_getEntry(){if(this._grid._isClosed()||!this._grid._hasState())return null;let e=this._grid.getFormulas().search(this._grid.getEntireCoords());if(e.length===0)return null;let t=e[0];return t.value?t:null}},kL=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),AL=()=>[],jL=(e,...t)=>{if(e.isEmpty())return;let r,i=t.length;for(let n=0;n<i;n++){let i=t[n],a=i.length;for(let t=0;t<a;t++){let n=e.search(i[t]),a=n.length;for(let e=0;e<a;e++){let t=n[e],i=t.value;if(!i.isFixed())continue;r||=[];let a=!1;for(let e=0;e<r.length&&!a;e++)a=r[e].value===i;a||r.push(t)}}}if(!r)return;let a=r.length;for(let e=0;e<a;e++){let a=r[e],o=a.colEnd-a.colStart+1,s=o*(a.rowEnd-a.rowStart+1),c=new Set;for(let e=0;e<i&&c.size<s;e++){let r=t[e],i=r.length;for(let e=0;e<i&&c.size<s;e++){let t=n.CoordUtils.intersectRanges(a,r[e]);if(t)for(let e=t.rowStart;e<=t.rowEnd;e++)for(let n=t.colStart;n<=t.colEnd;n++)c.add((e-a.rowStart)*o+(n-a.colStart))}}if(c.size<s)throw new n.ExpectedError((0,n.t)(`error.sheet.changePartOfArray`))}},ML={rowStart:0,colStart:0,rowEnd:0,colEnd:0},NL=[{colIndex:-1,rowIndex:-1},null,null,null,null];function PL(e,t,r,i){let a=i?.description??(0,n.messageKey)(`op.setComments`),o=DA(t),s=e.beginCommit({description:a});try{let n=e.getState();if(!n)return;let c=n.comments,l=[],u=t.length;for(let n=0;n<u;n++){let i=t[n],o=r===void 0?i.value:r;if(o===void 0)continue;let s=ij(o);if(s===null){if(!c.has(i))continue;c=c.deleteRanges([i]),l.push(i);continue}let u={rowStart:i.rowStart,rowEnd:i.rowStart,colStart:i.colStart,colEnd:i.colStart},d=c.search(u)[0]?.value??null,f=s.id?s:null;f?(d&&(c=c.deleteRanges([u])),c=e.loadComments(c,[{r:u,v:f}])):d?d.update(s,{description:a}):c=e.loadComments(c,[{r:u,v:e.newCommentJSON(s)}]),l.push(u)}if(l.length===0)return void s.commit();c!==n.comments&&e.updateState({comments:c}),e.invalidateUsedCoords(),e.notifyCommentsChange(),e.recordChange(s,`comments`,l),e.commitWithDirectives(s,o,i)}catch(e){throw s.rollback(),e}}var FL=e=>ae(e)??e;function IL(e,t,r,i){let a=i?.description??(0,n.messageKey)(`op.setHyperlink`);e.protectionCheck(()=>[`insertHyperlinks`,`formatCells`],t,a);let o=DA(t),s=e.beginCommit({description:a});e.getProtection().isLocked()&&e.recordSkipProtectionCheck(s);try{let a=e.getState();if(!a)return;let c=a.hyperlinkSpatial,l=c,u=e.styles,d=e=>{let t={...e.getAuthoredProperties()};if(t.named){let e=u.getNamedStyles().getByName(t.named)?.getRanged().getPropertiesAt(0,0,null);t=n.CommonUtils.mergeContentful(e,t)}return delete t.font,t.named=q.BuiltInName.Hyperlink,t},f=[],p=t.length;for(let n=0;n<p;n++){let i=t[n],o=null,s=i.value,u=s===void 0?r:s,p;if(u!==null)if(u.isIHyperlink)p={...u._p},o=u.getTextToDisplay();else if(typeof u==`string`)p={address:FL(u)};else if(u.address||u.textToDisplay){let e=u,t={...e};delete t.textToDisplay,t.address?(t.address=FL(t.address),p=t):p=null,o=e.textToDisplay??null}else p=null;else p=null;if(c===l&&(l=c.clone()),p!==null||c.size()>0){if(o&&r){let t=e.isDataColumn;aR(e,Jr(o,{majorStart:t?i.colStart:i.rowStart,majorEnd:t?i.colEnd:i.rowEnd,minorStart:t?i.rowStart:i.colStart,minorEnd:t?i.rowEnd:i.colEnd},t),void 0,null,{isHyperlink:!0,isBroadcast:!0})}p===null?e.getRangedEntries(a.hyperlinkSpatial,[i],{onEntry:(e,t)=>(l.insertNonOverlapping({...t,value:p}),t.value)}):(l.insertNonOverlapping({...i,value:p}),f.push({...i,value:d}))}}e.invalidateUsedCoords(),e.updateState({hyperlinkSpatial:l}),f.length>0&&LL(e,f,void 0,void 0,!1,!0),e.recordChange(s,`hyperlinks`,t),e.commitWithDirectives(s,o,i)}catch(e){throw s.rollback(),e}}function LL(e,r,i,a,o=!1,s=!1){let l=a?.description??(0,n.messageKey)(`op.updateStyle`);s||e.protectionCheck(()=>[`formatCells`],r,l);let u=!s&&typeof i==`function`;for(let e=0;!s&&!u&&e<r.length;e++)u=typeof r[e].value==`function`;let d=e.beginCommit({description:l,savepoint:u});e.getProtection().isLocked()&&e.recordSkipProtectionCheck(d);let f=DA(r);try{let s=e.getState();if(!s)return;let l=d.getSavepointId(),u=e.getEntireCoords(),p=e.getEntireCoords,m=s.borderSpatial.clone(l),h=s.fillSpatial.clone(l),g=s.contentSpatial.clone(l),_=s.continuousFillSpatial,v=s.dateFormatSpatial,y=e.styles,b=EH(y),x=(e,t)=>{if(o&&e.value&&e.value.getProperties()?.numberFormat)return e;let r=n.CoordUtils.sanitizeRange(e),i=e.value??new tg(y,p,r),a=t.value,s=a?a.getUpdateProperties()??a.getProperties():null,c=i.cloneWithUpdate(s);return c.isEmpty()&&(c=null),{...t,value:c}},S=e=>{let r=!_.isEmpty(),i=!v.isEmpty(),a=g.search(e),o=[],l=[];for(let t=0;t<a.length;t++){let r=a[t],i=r.value?r.value._p:null;if(!i)continue;let s=n.CoordUtils.intersectRanges(r,e),u=i.alignment?.horizontal;u!==c.HorizontalAlignment.CenterContinuous&&u!==c.HorizontalAlignment.Fill||o.push({...s,value:b(new tg(y,p,s),{alignment:{horizontal:u}})});let d=i.numberFormat;typeof d==`number`&&(d=cu(d)),d&&(Fl(d)||Il(d))&&l.push({...s,value:d})}(r||o.length)&&(_===s.continuousFillSpatial&&(_=_.clone()),_.insertNonOverlapping({...e,value:null}),o.length>0&&_.load(Or(o,t.IRange.Axis.Column,2**53-1,(e,t)=>e[0].value?._p?.alignment?.horizontal===e[1].value?._p?.alignment?.horizontal?t:void 0))),(i||l.length)&&(v===s.dateFormatSpatial&&(v=v.clone()),v.insertNonOverlapping({...e,value:null}),l.length>0&&v.load(Or(l,t.IRange.Axis.Column,2**53-1,(e,t)=>e[0].value===e[1].value?t:void 0)))},C=(e,t,n)=>{let r=t?t.getUpdateProperties()??t.getProperties():null,i;if(n||r?.alignment===null?i=null:r?.alignment&&r.alignment.horizontal!==void 0&&(i=r.alignment.horizontal??null),i!==void 0){let t=i===c.HorizontalAlignment.CenterContinuous||i===c.HorizontalAlignment.Fill;if(t||!_.isEmpty()){_===s.continuousFillSpatial&&(_=_.clone());let n=t?b(new tg(y,p,e),{alignment:{horizontal:i}}):null;_.insertNonOverlapping({...e,value:n})}}let a=n?null:r?.numberFormat;if(a!==void 0){typeof a==`number`&&(a=cu(a));let t=!!a&&(Fl(a)||Il(a));!t&&v.isEmpty()||(v===s.dateFormatSpatial&&(v=v.clone()),v.insertNonOverlapping({...e,value:t?a:null}))}},w=!1,T=r.length;for(let t=0;t<T;t++){let a=r[t],s=a.value,c=s===void 0?i:s;if(typeof c==`function`){w=!0;let t={colStart:Math.max(a.colStart-1,u.colStart),rowStart:Math.max(a.rowStart-1,u.rowStart),colEnd:Math.min(a.colEnd+1,u.colEnd),rowEnd:Math.min(a.rowEnd+1,u.rowEnd)},r=e.composeDirectStyleView(t,{border:m,fill:h,content:g}),i=(e,t)=>{let r=e.value??new tg(y,p,n.CoordUtils.sanitizeRange(e)),i=b(r,c);return i&&i.isEmpty()&&(i=null),{...t,value:i}},o=b(new tg(y,p,a),c,!0);o?._p?.borders&&DH(o,a,r,b,u),r.insertNonOverlapping({...a,value:o},{onIntersect:i}),OH(r,m,h,g,t),S(t);continue}let l=b(new tg(y,p,a),c,!0),d=null;if(l===null){let e={...a,value:null};m.insertNonOverlapping(e,{onIntersect:x}),h.insertNonOverlapping(e,{onIntersect:x}),g.insertNonOverlapping(e,{onIntersect:x})}else{let e=l.splitByFeature();d=e.content,e.border&&(e.border?._p?.borders&&DH(e.border,a,m,b,u),m.insertNonOverlapping({...a,value:e.border},{onIntersect:x})),e.fill&&h.insertNonOverlapping({...a,value:e.fill},{onIntersect:x}),e.content&&g.insertNonOverlapping({...a,value:e.content},{onIntersect:x})}(l===null||d)&&(w=!0),o?S(a):(l===null||d)&&C(a,d,l===null)}e.invalidateUsedCoords(),e.updateState({borderSpatial:m,fillSpatial:h,contentSpatial:g,continuousFillSpatial:_,dateFormatSpatial:v}),e.notify(`onStyleChange`),o?d.commit():(e.recordChange(d,`style`,r),e.commitWithDirectives(d,f,w||!a?.autoFit?a:{...a,autoFit:!1}))}catch(e){throw d.rollback(),e}}function RL(e,t,n,r,i){let a=$L(i),o=t;for(let t=0;t<a.length;t++)if(o=zL(e,o,n,r,a[t]),o===null)return null;return o}function zL(e,t,n,r,i){if(i===null||t?.continuous)return null;let a=e.styles,o=e.getEntireCoords,s=EH(a),l={colStart:r,rowStart:n,colEnd:r,rowEnd:n},u=t?.borderStyle,d=t?.fillStyle,f=t?.contentStyle,p=d,m=f;if(typeof i==`function`){let e=s(tg.compose(u,d,f)??new tg(a,o,l),i),t=e&&!e.isEmpty()?e.splitByFeature():null,n=e=>JSON.stringify(e?.getProperties()?.borders??null);if(n(t?.border)!==n(u))return null;p=t?.fill,m=t?.content}else{let e=s(new tg(a,o,l),i,!0);if(!e)return null;let t=e.splitByFeature();if(t.border)return null;let n=(e,t)=>(e??new tg(a,o,l)).cloneWithUpdate(t.getUpdateProperties()??t.getProperties());t.fill&&(p=n(d,t.fill)),t.content&&(m=n(f,t.content))}let h={...t};p&&!p.isEmpty()?h.fillStyle=p:delete h.fillStyle,m&&!m.isEmpty()?h.contentStyle=m:delete h.contentStyle;let g=h.contentStyle?.getProperties(),_=g?.alignment?.horizontal;if(_===c.HorizontalAlignment.CenterContinuous||_===c.HorizontalAlignment.Fill)return null;let v=g?.numberFormat;return typeof v==`number`&&(v=cu(v)),v&&(Fl(v)||Il(v))?h.dateFormat=v:delete h.dateFormat,h}function BL(e,t,n,r,i){let a={colStart:r,rowStart:n,colEnd:r,rowEnd:n},o=EH(e.styles),s=$L(i),c=t.search(a)[0]?.value??null;for(let t=0;t<s.length;t++)c=o(c??new tg(e.styles,e.getEntireCoords,a),s[t]);let l=c?.getProperties()?.numberFormat;return typeof l==`number`&&(l=cu(l)),!!l&&(Fl(l)||Il(l))}function VL(e,r,i=null){if(e.protectionCheck(AL,r),r.length===1&&n.CoordUtils.isSingleCell(r[0]))return;let a=t.IRange.AxisSelection.Both;i?.axes?a=i.axes:i===t.IRange.AxisSelection.Row?a=t.IRange.AxisSelection.Row:i===t.IRange.AxisSelection.Column&&(a=t.IRange.AxisSelection.Column);let o=i?.discardMultipleValues??!1,s=DA(r),c=e.getSelection().getCoords(),l=null,u=e.beginCommit({description:i?.description??(0,n.messageKey)(`op.merge`)}),d=r[0];try{let f=e.getMerges(r);if(mA(r)||f.length>0){let t=n.CoordUtils.unionRangesArrays(f),i=n.CoordUtils.unionRangesArrays(r);if(!(!t&&!i||t&&i&&n.CoordUtils.isRangeWithinRange(t,i)))throw console.warn((0,n.t)(`error.sheet.mergeOverlapping`),r),new n.ExpectedError((0,n.t)(`error.sheet.mergeOverlapping`));HL(e,f)}let p=e.createSparseBuilder({axis:t.IRange.Axis.Column}),m=[],h=[],g=[];try{let i=e.getEntireCoords(),u=e.calcGrid.getContentful(),f=null;for(let e=0;e<r.length;e++)f=n.CoordUtils.unionRanges(f,r[e]);let _=e.composeDirectStyleView(f??void 0),v=!1,y=t=>{let r={rowIndex:t.rowStart,colIndex:t.colStart},i=null;if(v){let e=u.search(t),a=e.length,s=[];for(let r=0;r<a;r++){let i=n.CoordUtils.intersectRanges(e[r],t);if(i){for(let e=i.rowStart;e<=i.rowEnd;e++)for(let t=i.colStart;t<=i.colEnd;t++)s.push({rowIndex:e,colIndex:t});if(s.length>1&&!o)throw new n.TypedError((0,n.t)(`error.sheet.mergeMultipleValues`),`discardMultipleValues`)}}if(s.length>0){let e=s[0];for(let t=1;t<s.length;t++){let n=s[t];(n.rowIndex<e.rowIndex||n.rowIndex===e.rowIndex&&n.colIndex<e.colIndex)&&(e=n)}e.rowIndex===r.rowIndex&&e.colIndex===r.colIndex||(i=e);for(let t=0;t<s.length;t++){let n=s[t];n===e||n.rowIndex===r.rowIndex&&n.colIndex===r.colIndex||g.push({rowIndex:n.rowIndex,colIndex:n.colIndex,update:null})}}}i||=r;let a=null,s=null,c=null,l=null,f=null,p=null,y=null;ML.colStart=t.colStart,ML.rowStart=t.rowStart,ML.colEnd=t.colStart,ML.rowEnd=t.rowStart;let b=_.search(ML);if(b.length>0){y=b[0].value?.getPropertiesAt(t.rowStart,t.colEnd,null);let e=y?.borders;a=e?.left??null,s=e?.top??null,f=e?.right??null,p=e?.bottom??null}if(ML.colStart=t.colEnd,ML.colEnd=t.colEnd,b=_.search(ML),b.length>0){let e=b[0].value?.getPropertiesAt(t.rowStart,t.colEnd,null)?.borders;e&&e.right&&(c=e.right)}if(ML.colStart=t.colStart,ML.colEnd=t.colStart,ML.rowStart=t.rowEnd,ML.rowEnd=t.rowEnd,b=_.search(ML),b.length>0){let e=b[0].value?.getPropertiesAt(t.rowEnd,t.colStart,null)?.borders;e&&e.bottom&&(l=e.bottom)}if(!c||!l){ML.colStart=t.colEnd,ML.colEnd=t.colEnd,ML.rowStart=t.rowEnd,ML.rowEnd=t.rowEnd,b=_.search(ML);let e=b?.[0];if(e){let n=e.value?.getPropertiesAt(t.rowEnd,t.colEnd,null)?.borders;n&&(c||=n.right??null,l||=n.bottom??null)}}let x=!n.CoordUtils.isEqualCells(i,r);if(x){ML.colStart=i.colIndex,ML.colEnd=i.colIndex,ML.rowStart=i.rowIndex,ML.rowEnd=i.rowIndex;let e=_.search(ML);e.length>0&&(y=e[0].value?.getPropertiesAt(i.rowIndex,i.colIndex,null)??y)}if(m.push({...t,value:null}),m.push({...t,value:{...y,borders:{top:s,left:a,right:c??f,bottom:l??p,horizontal:null,vertical:null}}}),x){let t=e.getRange(i).getCell();g.push({rowIndex:r.rowIndex,colIndex:r.colIndex,update:t}),g.push({rowIndex:i.rowIndex,colIndex:i.colIndex,update:null})}h.push(t),d=n.CoordUtils.unionRanges(d,t)},b=[...r].sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Column)),x=b.length;for(let r=0;r<x;r++){let o=b[r];if(!n.CoordUtils.isSingleCell(o)){if(l||!c||!n.CoordUtils.isCellWithinRange(c.cell,o)||c.cell.rowIndex===o.rowStart&&c.cell.colIndex===o.colStart||(l={...s,cell:{rowIndex:o.rowStart,colIndex:o.colStart}}),v=u.search(o).length>0,e.validateOrRemoveOverlaps(o,`merge`),o.colStart<i.colStart||o.rowStart<i.rowStart||o.colEnd>i.colEnd||o.rowEnd>i.rowEnd)throw new n.ExpectedError((0,n.t)(`error.sheet.mergeOob`));if(a===t.IRange.AxisSelection.Column){let e=o.rowEnd===i.rowEnd?Math.max(1,i.rowEnd):o.rowEnd;for(let t=o.rowStart;t<=e;t++)y({...o,rowStart:t,rowEnd:t})}else if(a===t.IRange.AxisSelection.Row){let e=o.colEnd===i.colEnd?Math.max(1,i.colEnd):o.colEnd;for(let t=o.colStart;t<=e;t++)y({...o,colStart:t,colEnd:t})}else y(o)}}g.sort((e,t)=>e.colIndex-t.colIndex||e.rowIndex-t.rowIndex);let S=g.length;for(let e=0;e<S;e++){let t=g[e];p.pushAt(t.rowIndex,t.colIndex,t.update)}p.apply(),e.indexMerges(h),LL(e,m),e.updateState({})}catch(e){throw e.type?new n.TypedError(e.message??`Unable to merge`,e.type):new n.ExpectedError(e.message??`Unable to merge`)}l&&(s=l),s&&e.recordSelection(u,s,i),e.recordChange(u,`merges`,r),u.commit()}catch(e){throw u.rollback(),e}}function HL(e,t,r){if(e.protectionCheck(AL,t),mA(t))throw new n.ExpectedError((0,n.t)(`error.sheet.unmergeOverlapping`));if(!e.getState())return;let i=n.CoordUtils.unionRangesArrays(t),a=DA(t),o=e.beginCommit({description:r?.description??(0,n.messageKey)(`op.unmerge`)}),s=e.stateFor(o).mergeSpatial,c=[];try{let l=t.length;for(let e=0;e<l;e++){let r=t[e],a=s.search(r),o=a.length;for(let e=0;e<o;e++){let t=a[e];if(!n.CoordUtils.isSingleCell(r)&&!n.CoordUtils.isRangeWithinRange(t,i))throw new n.ExpectedError((0,n.t)(`error.sheet.unmergePartial`));c.push(t)}}if(c.length===0)return void o.rollback();e.indexMerges(null,c),e.recordChange(o,`merges`,t),e.commitWithDirectives(o,a,r)}catch(e){throw o.rollback(),e}}function UL(e){let t=e.entry;if(t===null){let n=e.rowIndex,r=e.colIndex;t=e.entry=new tM(e.a1,{colStart:r,rowStart:n,colEnd:r,rowEnd:n},null).imageAtAnchor()}return t}function WL(e,t,n){return UL(e).getTextAt(t,n)}var GL={rowIndex:0,colIndex:0},KL=e=>e.r1c1??=Hd(e.a1,e.rowIndex,e.colIndex),qL=(e,t)=>e===null||t===null?e===t?t:void 0:KL(e)===KL(t)?e:void 0,JL=(e,t)=>e===null||t===null?e===t?t:void 0:e,YL=e=>(t,n)=>{let r=t[0].value,i=t[1].value;if(r!==void 0&&i!==void 0)return e(r,i)===void 0?void 0:n},XL=YL(qL),ZL=YL(JL),QL=class{constructor(e){this.updates=e}};function $L(e){return e instanceof QL?e.updates:[e]}var eR=(e,t)=>new QL([...$L(e),...$L(t)]);function tR(e,n,r,i,a=e.isDataColumn,o=!1){let s=a?t.IRange.Axis.Column:t.IRange.Axis.Row,c=e.getProtection().isLocked(),l=e.getProtection().isFormatCellsAllowed(),u=e.strings,d={[W.Type.BorderStyle]:!1,[W.Type.FillStyle]:!1,[W.Type.ContentStyle]:!1,[W.Type.Table]:!1},f=!1,p=!1;c&&e.hasRangedEntries(`protectedRanges`,n)&&(d[W.Type.Unlock]=!1,f=!0,p=!0),e.hasRangedEntries(`mergeSpatial`,n)&&(d[W.Type.Merge]=!1,f=!0);let m=e.rangeStateIterator({bounds:n,axis:s,searchTypes:d,byCell:!0}),h=ei(a),g=ei(a,(e,t)=>{if(e===t)return t},eR),_=ei(a,(e,t)=>{if(e===t)return t}),v=ei(a,(e,t)=>{if(e===t)return t}),y=i?.isBroadcast??!1,b=ei(a,y?JL:qL),x=null,S=null;!1!==r?.textParser&&(S={ignoreQuotePrefix:!1,parse:null,...r&&!0!==r.textParser?r.textParser:{}},x=new yH(u,null,e.cellOptions));let C=c&&zh(e.styles,null);return{ctx:e,options:r,internalOptions:i,isColumn:a,isDataChange:i?.isCell??!1,isInternalHyperlink:i?.isHyperlink??!1,isBroadcast:y,isLocked:c,allowFormatCells:l,hasUnlockRanges:p,runtime:e.runtime,isHeld:o,isRefused:!1,isLocalStyle:null,hasLateRefusals:!1,iterRanges:m,requiresRangeCheck:f,seekCoords:{rowIndex:0,colIndex:0},cellMajor:-1,cellMinor:-1,cellIntersection:null,optionsFromString:S,contextState:x,resolvedStringCache:new Map,lastDirectStyle:void 0,isTextNumFmt:!1,defaultStyleUnlocked:C,isStyleUnlocked:C,usedStyleUnlock:!1,lastUnlock:void 0,isUnlockExempt:!1,isPasswordGated:!1,deletes:h,styleUpdates:g,hyperlinkUpdates:_,commentUpdates:v,formulaUpdates:b,mergeUpdates:[]}}function nR(e,r,i,a){let o=function(e,t,n){let r=e.iterRanges;if(r===null)return null;let i=e.cellMajor,a=e.cellMinor;if(t<i||t===i&&n<a)return null;if(t===i&&n===a)return e.cellIntersection;let o=e.isColumn,s=e.seekCoords;s.rowIndex=o?n:t,s.colIndex=o?t:n;let c=r.next(s);if(c.done)return e.cellIntersection=null,e.iterRanges=null,e.requiresRangeCheck=!1,null;let l=c.value.cell,u=e.cellMajor=o?l.colIndex:l.rowIndex,d=e.cellMinor=o?l.rowIndex:l.colIndex,f=e.cellIntersection=c.value.intersection;return t===u&&n===d?f:null}(e,i,a);if(o?.merge){let t=o.merge.getCoords(),n=e.isColumn?t.colStart:t.rowStart,r=e.isColumn?t.rowStart:t.colStart;if(n!==i||r!==a)return}let s=o?.contentStyle;if(e.lastDirectStyle!==s&&(e.lastDirectStyle=s,e.isTextNumFmt=!1,e.isStyleUnlocked=e.defaultStyleUnlocked,s)){let t=s.getPropertiesAt(0,0,null),n=t?.numberFormat;n&&(e.isTextNumFmt=!!(c=n)&&(c===49||c===`@`||typeof c!=`number`&&(Hl().getFormatInfo(c)?.isText??!1))),e.isLocked&&(e.isStyleUnlocked=zh(e.ctx.styles,t))}var c;if(e.isDataChange&&r&&r.isICell){let t=r;if(t.isTopLeft()){let n=t.getSpans();e.hasLateRefusals=!0,e.mergeUpdates.push({colStart:e.isColumn?i:a,rowStart:e.isColumn?a:i,colEnd:(e.isColumn?i:a)+n.width-1,rowEnd:(e.isColumn?a:i)+n.height-1})}}GL.rowIndex=e.isColumn?a:i,GL.colIndex=e.isColumn?i:a;let l=kM(e.runtime,r,e.isTextNumFmt?null:e.optionsFromString,e.resolvedStringCache,!1,GL);if(l===void 0)return;let u=l.value;if(typeof u==`string`&&u.length>t.Scalar.MAX_TEXT_LENGTH&&(u=u.slice(0,t.Scalar.MAX_TEXT_LENGTH)),l.stringToParse){NL[0].colIndex=e.isColumn?i:a,NL[0].rowIndex=e.isColumn?a:i,NL[1]=u,NL[2]=o,e.contextState.setState(NL);let t=e.optionsFromString?.parse(l.stringToParse,e.contextState.context),n=kM(e.runtime,t,e.optionsFromString,e.resolvedStringCache,!0);if(e.contextState.clear(),n===null)return n;n!==void 0&&(l={...n})}if(e.isLocked){let t=o?.unlock;if(t!==e.lastUnlock&&(e.lastUnlock=t,e.isUnlockExempt=!1,e.isPasswordGated=!1,t))if(Array.isArray(t)){let n=t.length;for(let r=0;r<n;r++){if(t[r].isUnlocked()){e.isUnlockExempt=!0;break}e.isPasswordGated=!0}}else t.isUnlocked()?e.isUnlockExempt=!0:e.isPasswordGated=!0;if(!e.isUnlockExempt&&e.isStyleUnlocked)e.usedStyleUnlock=!0;else if(!e.isUnlockExempt){let t=e.isPasswordGated?(0,n.t)(`error.sheet.protectedRangeLocked`):(0,n.t)(`error.sheet.protectedSheet`);if(r===null||l.value!==void 0||!e.allowFormatCells&&l.style!==void 0)throw new n.ProtectedError(t)}}if(e.isHeld&&(l.hyperlink!==void 0||l.comments!==void 0))return void(e.isRefused=!0);let d=e.isLocalStyle;if(d&&l.style&&!d(e.isColumn?a:i,e.isColumn?i:a,l.style))return void(e.isRefused=!0);if(!e.isInternalHyperlink){let t=l.style,r=t!==void 0&&(t!==null||e.isDataChange),o=l.hyperlink,s=o!==void 0&&(o!==null||e.isDataChange);e.isLocked&&(r&&e.ctx.protectionCheck(()=>[`formatCells`],null,(0,n.messageKey)(`op.updateStyle`)),s&&e.ctx.protectionCheck(()=>[`insertHyperlinks`,`formatCells`],null,(0,n.messageKey)(`op.setHyperlink`)));let c=l.impliedStyle;c!==void 0&&e.styleUpdates.append(i,a,c),r&&(typeof t==`function`&&(e.hasLateRefusals=!0),e.styleUpdates.append(i,a,t)),s&&(e.hasLateRefusals=!0,e.hyperlinkUpdates.append(i,a,o));let u=l.comments;u!==void 0&&(e.hasLateRefusals=!0,e.commentUpdates.append(i,a,u))}let f=l.formula;return f===void 0||f===null&&!e.isDataChange||e.formulaUpdates.append(i,a,f===null?null:{a1:f,rowIndex:e.isColumn?a:i,colIndex:e.isColumn?i:a,r1c1:null,entry:null}),u}function rR(e,t,n,r){let i=null;if(e.requiresRangeCheck||e.isLocked||typeof t!=`number`?(e.requiresRangeCheck||e.isLocked||t!==null||e.isDataChange)&&(i=nR(e,t,n,r)):i=t,typeof i==`number`){let e=$H(i);i=typeof e==`number`?eU(e):e}return i===null&&e.deletes.append(n,r),i}function iR(e,r,i,a,o){let s=e.ctx,c=s.beginCommit({description:e.options?.description??(0,n.messageKey)(`op.updateCells`),savepoint:e.hasLateRefusals});(e.hasUnlockRanges||e.isLocked&&e.allowFormatCells)&&s.recordSkipProtectionCheck(c);try{(function(e,r,i,a,o,s){let{ctx:c,options:l,internalOptions:u,isBroadcast:d,usedStyleUnlock:f,deletes:p,styleUpdates:m,hyperlinkUpdates:h,commentUpdates:g,formulaUpdates:_,mergeUpdates:v}=e,y=c.calcGrid,b=r.getSavepointId(),x={commitId:r.getId(),cloneKey:b},S=p.done(),C=S.length,w=PP(i,c.isDataColumn),T=_.done();T.length>1&&(T=Or(T,e.isColumn?t.IRange.Axis.Column:t.IRange.Axis.Row,1,d?ZL:XL)),jL(y.getSpills(),S,w,T);let E=u?.arrayFixed;if(E){let e=T.length===1?T[0]:null;if(!e||!e.value||!n.CoordUtils.isSingleCell(e)||e.colStart!==E.colStart||e.rowStart!==E.rowStart)throw new n.ExpectedError((0,n.t)(`error.sheet.arrayFixedFormula`))}for(let e=0;e<C;e++)y.remove(S[e],x);let D;i.length>0&&(D={tuples:i,bounds:a});let O=T.length,k=Array(O);for(let e=0;e<O;e++){let t=T[e],n=t.value?UL(t.value).a1:null;k[e]={...t,value:n}}(D||k.length>0)&&y.setInputs(D,k,E?{...x,arrayFixed:E}:x);let A=function(e){let t=null;for(let n=0;n<e.length;n++){let r=e[n];if(!(r.value instanceof QL)){t?.push(r);continue}t??=e.slice(0,n);let i=r.value.updates;for(let e=0;e<i.length;e++)t.push({...r,value:i[e]})}return t??e}(m.done());A.length>0&&LL(c,A,void 0,void 0,!1,!0),v.length>0&&VL(c,v);let j=h.done();j.length>0&&IL(c,j);let M=g.done();M.length>0&&PL(c,M),l?.autoFormat&&c.recordAutoFormat(r);let N={ranges:[s?.selection??o]};c.recordChange(r,`data`,s?.changes??[o]);let P=[];for(let e=0;e<O;e++){let t=T[e];t.value&&P.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd})}c.recordFormulasEntered(r,P),f&&c.recordSkipProtectionCheck(r),c.commitWithDirectives(r,N,l)})(e,c,r,i,a,o)}catch(e){throw c.rollback(),e}}function aR(e,t,r,i=void 0,a=null){if(!t)return;let o=t.tuples,s=t.bounds,c=e.isDataColumn,l=s.majorStart,u=s.majorEnd,d=s.minorStart,f=s.minorEnd,p={colStart:c?l:d,rowStart:c?d:l,colEnd:c?u:f,rowEnd:c?f:u};(i??=((t,r)=>{e.validateCoords(t,r??(0,n.t)(`error.sheet.oobRange`))}))(p);let m=tR(e,p,r,a),h=[],g=e.lists.createList,_=[],v=-1,y=-1,b=o.length;for(let e=0;e<b;e++){let t=o[e],r=t[0];if(v>=r)throw new z.OutOfOrderError(`Duplicate or out of order major indices: {${r}}.`);if(v=r,y=-(2**53-1),r<l||r>u)throw new n.OutOfBoundsError(`Provided major bounds is invalid`);let i=t[1],a=[],s=i.length;for(let e=0;e<s;e++){let t=i[e],o=t[1],s=o.length,c=t[0],l=c;if(y>l)throw new z.OutOfOrderError(`Duplicate or out of order minor indices: {${l}}.`);if(l<d||l+s>f+1)throw new n.OutOfBoundsError(`Provided minor bounds is invalid`);let u=0,p=0,h=typeof o.at==`function`;for(let e=0;e<s;e++){let t=rR(m,h?o.at(e):o[e],r,l);t==null?(u>0&&(a.push([c,g(_,u,p)]),u=0,p=0),c=l+1):(_[u++]=t,p|=z.hintOf(t)|(t===_[0]?0:z.Hint.NotUniform)),l++}y=l,u>0&&a.push([c,g(_,u,p)])}a.length>0&&h.push([r,a])}iR(m,h,s,p)}function oR(e,t){let n=e.search(t),r=n.length;if(r===0)return e;let i=new Set;for(let e=0;e<r;e++){let t=n[e].value;t!==void 0&&i.add(t)}for(let n of i){let r=e.getCoords(n);r&&(e=e.setCoords(n,Mh(r,[t])))}return e}function sR(e,t,r=null,i,a=!1,o=null){let s=null,c=(0,n.messageKey)(`op.clear`),l=!1,u=!1,d=!1,f=!1,p=!1,m=!1,h=!1;if(r===wk.Content.Formulas)c=(0,n.messageKey)(`op.clearFormulas`),m=!0;else if(r===wk.Content.Values)c=(0,n.messageKey)(`op.clearValues`),m=!0;else if(r===wk.Content.Formats)c=(0,n.messageKey)(`op.clearFormats`),l=!0,s=[`formatCells`];else if(r===wk.Content.Comments)c=(0,n.messageKey)(`op.clearComments`),d=!0;else if(r===wk.Content.Notes)c=(0,n.messageKey)(`op.clearNotes`),f=!0;else if(r===wk.Content.Hyperlinks)c=(0,n.messageKey)(`op.clearHyperlinks`),u=!0,s=[`formatCells`];else if(r===wk.Content.DataValidations)c=(0,n.messageKey)(`op.clearDataValidations`),h=!0,s=[];else if(r===wk.Content.Tables)c=(0,n.messageKey)(`op.clearTables`),p=!0;else{if(r!==null)throw new n.ExpectedError((0,n.t)(`error.sheet.clearUnsupported`,{type:r}));s=[],c=(0,n.messageKey)(`op.clearAll`),m=!0,l=!0,u=!0,d=!0,h=!0}s!==null&&e.protectionCheck(()=>s,t,i?.description??c),m&&jL(e.calcGrid.getSpills(),n.CoordUtils.sanitizeRangeArray(t));let g=DA(t),_=e.beginCommit({description:i?.description??c});s!==null&&e.getProtection().isLocked()&&e.recordSkipProtectionCheck(_);let v=e.getState(),y=e.calcGrid,b={commitId:_.getId(),cloneKey:_.getSavepointId()},x=v.conditionalFormats,S=v.dataValidations;try{let s=n.CoordUtils.sanitizeRangeArray(t);if(u&&!v.hyperlinkSpatial.isEmpty()&&IL(e,s,null),d&&!v.comments.isEmpty()&&PL(e,s,null),f&&!v.comments.isEmpty()){let t=function(e,t){let r=[],i=t.length;for(let a=0;a<i;a++){let i=t[a],o=e.search(i),s=o.length;for(let e=0;e<s;e++){let t=o[e];t.value?.isNote()&&r.push({...n.CoordUtils.sanitizeRange(t),value:null})}}return r}(v.comments,s);t.length>0&&PL(e,t,null)}if(l&&(LL(e,s,null),a||HL(e,s)),h&&!(l||m||p)&&!S.isEmpty()){let e=t.length;for(let n=0;n<e;n++)S=oR(S,t[n])}if(l||m||p){let i=t.length;for(let s=0;s<i;s++){let i=t[s];if(!l||a||x.isEmpty()||(x=oR(x,i)),!h||a||S.isEmpty()||(S=oR(S,i)),!a){let t=e.getTables().getItems({address:i}),a=t.length;for(let e=0;e<a;e++){let a=t[e],s=a.getRange().getCoords();n.CoordUtils.isRangeWithinRange(s,i)&&(o&&n.CoordUtils.isRangeWithinRange(s,o)||(p||r===null?a._remove(`error`):l&&a.updateStyleOptions({name:null})))}let s=e.getAutoTable();if(s){if(!n.CoordUtils.isRangeWithinRange(s.getRange().getCoords(),i))continue;s.delete()}}}}if(m){let e=t.length;for(let n=0;n<e;n++)y.remove(t[n],{...b,clearArrays:!0})}e.updateState({conditionalFormats:x,dataValidations:S}),e.recordChange(_,`data`,t),e.commitWithDirectives(_,g,i)}catch(e){throw _.rollback(),e}}var cR=new Set([`description`,`axis`,`skipBoundsCheck`]),lR=class e{constructor(e){this._transaction=null,this._count=0,this._isCell=!1,this._scan=null,this._isBeginning=!1,this._isOriented=!1,this._isTransposed=!1,this._builder=null,this._changes=null,this._firstWrites=[],this._firstValue=void 0,this._lastMajor=0,this._lastMinor=0,this._isValueAtLast=!1,this._hasValues=!1,this._majorMin=0,this._majorMax=0,this._minorMin=0,this._minorMax=0,this._generation=0,this._ctx=e}isHolding(){return this._count>0}hold(e,t,n,r){let i=this._ctx;if(!e||n||i.isClosed())return!1;let a=i.transactions.getCurrentTransaction();if(!a)return!1;let o=e.bounds,s=o.majorStart,c=o.minorStart;if(s!==o.majorEnd||c!==o.minorEnd)return!1;let l=!1;if(r){for(let e in r)if(r[e]){if(e===`isCell`)l=!0;else if(e!==`isBroadcast`)return!1}}if(t){for(let e in t)if(t[e]!==void 0&&!cR.has(e))return!1}let u=e.tuples[0]?.[1][0]?.[1];if(!u)return!1;let d=typeof u.at==`function`?u.at(0):u[0];if(typeof d==`object`&&d&&d.isICell)return!1;let f=i.isDataColumn,p=f?c:s,m=f?s:c,h=i.getEntireCoords();if(!h||p<h.rowStart||p>h.rowEnd||m<h.colStart||m>h.colEnd)return!1;let g=i.getSpills(a);return!(!g.isEmpty()&&g.search({rowStart:p,colStart:m,rowEnd:p,colEnd:m}).length>0)&&(this._holdIn(a),this._count>0&&!this._continues(s,c,l)&&this.flush(),this._push(s,c,d,l,h))}holdStyle(e,t,n,r,i){let a=this._ctx;if(typeof n!=`object`||!n||a.isClosed())return!1;let o=a.transactions.getCurrentTransaction();if(!o)return!1;if(r){for(let e in r)if(r[e]!==void 0&&!cR.has(e))return!1}if(a.getMutations().getProtection().isLocked())return!1;let s=a.getEntireCoords();if(!s||e<s.rowStart||e>s.rowEnd||t<s.colStart||t>s.colEnd||!i())return!1;let c=a.isDataColumn,l=c?t:e,u=c?e:t;return this._holdIn(o),this._count>0&&!this._continues(l,u,null)&&this.flush(),this._pushStyle(l,u,n,s),!0}_holdIn(e){this._transaction!==e&&(this.flush(),this._transaction=this._ctx.transactions.beginCommit({savepoint:!1,flush:()=>{this._isBeginning||this.flush()},writes:this._ctx.writes,onRollback:()=>this.discard()}))}getTransaction(){return this._transaction}read(t,n){if(this._count===0)return e.NotHeld;let r=this._scan.isColumn;return this._valueAt(r?n:t,r?t:n)}_valueAt(t,n){if(!this._isOriented){let r=this._firstValue;return t===this._lastMajor&&n===this._lastMinor&&r!==void 0?r:e.NotHeld}if(this._changes.find(t,n)===void 0)return e.NotHeld;let r=this._builder.getAt(t,n);return r===void 0?this._scan.deletes.find(t,n)===void 0?e.NotHeld:null:r}readCell(t,n){if(this._count===0)return e.NotHeld;let r=this._scan,i=r.isColumn,a=i?n:t,o=i?t:n,s=this._valueAt(a,o),c=r.styleUpdates.find(a,o)?.value;if(s===e.NotHeld)return c===void 0?e.NotHeld:{value:null,isValueHeld:!1,formula:null,style:c};if(s===null&&this._isCell)return;let l=r.formulaUpdates.find(a,o)?.value;return{value:s,isValueHeld:!0,formula:l?WL(l,t,n):null,style:c}}readStyleUpdate(e,t){let n=this._scan.isColumn;return this._scan.styleUpdates.find(n?t:e,n?e:t)?.value}isHeldGeneration(e){return this._count>0&&this._generation===e}getGeneration(){return this._generation}flush(){if(this._count===0)return;let e=this._ctx.isDataColumn,t=this._scan,n=this._lastMajor,r=this._lastMinor,i=this._hasValues,a=i?{majorStart:this._majorMin,majorEnd:this._majorMax,minorStart:this._minorMin,minorEnd:this._minorMax}:{majorStart:n,majorEnd:n,minorStart:r,minorEnd:r},o=this._toRange(a.majorStart,a.minorStart,a.majorEnd,a.minorEnd),s,c;if(this._isOriented){s=this._builder.build()?.tuples??[];let e=this._changes.done(!0);c=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t];c[t]={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd}}}else{let e=this._firstValue;s=e==null?[]:[[n,[[r,t.ctx.lists.createList([e])]]]],c=i?[o]:[]}this._clear();let l=e?n:r,u=e?r:n;iR(t,s,a,o,{changes:c,selection:{colStart:l,rowStart:u,colEnd:l,rowEnd:u}})}discard(){this._clear()}_toRange(e,t,n,r){return this._ctx.isDataColumn?{colStart:e,rowStart:t,colEnd:n,rowEnd:r}:{colStart:t,rowStart:e,colEnd:r,rowEnd:n}}_continues(e,t,n){if(n!==null&&n!==this._isCell)return!1;let r=this._lastMajor,i=this._lastMinor;return e===r&&t===i?n===null||!this._isValueAtLast:this._isOriented?this._isTransposed?t>i||t===i&&e>r:e>r||e===r&&t>i:e>r||t>i}_begin(e,t,n){this._isBeginning=!0;try{let r=tR(this._ctx.getMutations(),e,void 0,t?{isCell:!0}:null,n,!0);return r.isLocalStyle=(e,t,n)=>this._ctx.isLocalStyle(this._transaction,e,t,n),r}finally{this._isBeginning=!1}}_scanCell(e,t,n,r){return e.isRefused=!1,rR(e,t,n,r)}_beginRun(e,t,n){let r=this._begin(this._toRange(e,t,e,t),n,this._ctx.isDataColumn);return this._scan=r,this._isCell=n,this._isOriented=!1,r}_orientTo(e,t,n){this._orient(e!==this._lastMajor&&(t===this._lastMinor||e<=this._lastMajor),n)}_push(e,t,n,r,i){let a;if(this._count===0||!this._isOriented&&e===this._lastMajor&&t===this._lastMinor){let i=this._count===0?this._beginRun(e,t,r):this._scan;if(a=this._scanCell(i,n,e,t),i.isRefused)return!1;this._firstWrites.push(n),this._firstValue=a}else{this._isOriented||this._orientTo(e,t,i);let r=this._scan,o=this._isTransposed,s=o?t:e,c=o?e:t;if(a=this._scanCell(r,n,s,c),r.isRefused)return!1;a!=null&&this._builder.pushAt(s,c,a),this._changes.append(s,c)}return this._hasValues?(e<this._majorMin&&(this._majorMin=e),e>this._majorMax&&(this._majorMax=e),t<this._minorMin&&(this._minorMin=t),t>this._minorMax&&(this._minorMax=t)):(this._hasValues=!0,this._majorMin=this._majorMax=e,this._minorMin=this._minorMax=t),this._lastMajor=e,this._lastMinor=t,this._isValueAtLast=!0,this._count++,!0}_pushStyle(e,t,n,r){if(this._count===0||!this._isOriented&&e===this._lastMajor&&t===this._lastMinor)(this._count===0?this._beginRun(e,t,!1):this._scan).styleUpdates.append(e,t,n),this._firstWrites.push(new uR(n));else{this._isOriented||this._orientTo(e,t,r);let i=this._isTransposed;this._scan.styleUpdates.append(i?t:e,i?e:t,n)}e===this._lastMajor&&t===this._lastMinor&&this._count!==0||(this._isValueAtLast=!1),this._lastMajor=e,this._lastMinor=t,this._count++}_orient(e,t){let n=this._ctx.isDataColumn,r=this._begin(t,this._isCell,e?!n:n),i=e?this._lastMinor:this._lastMajor,a=e?this._lastMajor:this._lastMinor,o=r.ctx.lists.createList,s=e?new z.TransposedBuilder(o):new z.Builder(o),c=ei(r.isColumn),l=this._firstWrites;for(let e=0;e<l.length;e++){let t=l[e];if(t instanceof uR){r.styleUpdates.append(i,a,t.update);continue}let n=this._scanCell(r,t,i,a);n!=null&&s.pushAt(i,a,n),c.append(i,a)}this._scan=r,this._builder=s,this._changes=c,this._isTransposed=e,this._isOriented=!0,this._firstWrites=[],this._firstValue=void 0}_clear(){this._generation++,this._count=0,this._scan=null,this._builder=null,this._changes=null,this._isOriented=!1,this._firstWrites=[],this._firstValue=void 0,this._isValueAtLast=!1,this._hasValues=!1}},uR=class{constructor(e){this.update=e}};(lR||={}).NotHeld=Symbol(`NotHeld`);var dR=(e,t,n)=>{if(!e||e.length===0)return null;let r=[],i=[],a=t,o=!1,s=e.length;for(let t=0;t<s;t++){let s=e[t];if(!(s.max<a)){if(s.min>n)break;o=!0,s.min>a&&(r.push(a),i.push(s.min-1)),a=Math.max(a,s.max+1)}}return o?(a<=n&&(r.push(a),i.push(n)),{start:Int32Array.from(r),end:Int32Array.from(i),count:r.length}):null},fR=(e,t)=>{let n=e.end,r=0,i=e.count;for(;r<i;){let e=r+i>>>1;n[e]<t?r=e+1:i=e}return r};function pR(e,t,r,i,a,o,s){let c=e.state,l=e.calcGrid,u=dR(o,t.rowStart,t.rowEnd),d=dR(s,t.colStart,t.colEnd);if(u&&u.count===0||d&&d.count===0)return null;let f=((e=64)=>({count:0,rowS:new Int32Array(e),rowE:new Int32Array(e),colS:new Int32Array(e),colE:new Int32Array(e),type:new Uint16Array(e),value:[],keys:[]}))(),p=f.keys,m=new Map,h=t.rowStart,g=t.rowEnd,_=t.colStart,v=t.colEnd,y=(e,t,n,r,i,a)=>{let o=f.count;o>=f.rowS.length&&((e,t)=>{if(e.rowS.length>=t)return;let n=Math.max(t,2*e.rowS.length);e.rowS=Yt(e.rowS,n),e.rowE=Yt(e.rowE,n),e.colS=Yt(e.colS,n),e.colE=Yt(e.colE,n);let r=new Uint16Array(n);r.set(e.type),e.type=r})(f,o+1),f.rowS[o]=e,f.rowE[o]=t,f.colS[o]=n,f.colE[o]=r,f.type[o]=i,f.value[o]=a,f.count=o+1},b=(e,t,n)=>{let r=e.rowStart>h?e.rowStart:h,i=e.rowEnd<g?e.rowEnd:g,a=e.colStart>_?e.colStart:_,o=e.colEnd<v?e.colEnd:v;if(r>i||a>o)return;if(!u&&!d)return void y(r,i,a,o,t,n);if(u){let e=u.count;for(let s=fR(u,r);s<e;s++){let e=u.start[s];if(e>i)break;let c=e>r?e:r,l=u.end[s],f=l<i?l:i;if(!d){y(c,f,a,o,t,n);continue}let p=d.count;for(let e=fR(d,a);e<p;e++){let r=d.start[e];if(r>o)break;let i=d.end[e];y(c,f,r>a?r:a,i<o?i:o,t,n)}}return}let s=d.count;for(let e=fR(d,a);e<s;e++){let s=d.start[e];if(s>o)break;let c=d.end[e];y(r,i,s>a?s:a,c<o?c:o,t,n)}},x=e=>{let t=m.get(e);return t===void 0&&(t=p.length,p.push(e),m.set(e,t)),t};if(i&&i.length>0){let t=e.getEntireCoords(),n=i.length;for(let e=0;e<n;e++){let n=i[e],r=n?n.length:0;if(r===0)continue;let a=x(``+e);for(let e=0;e<r;e++){let r=Ud(n[e],t);b(r,a,r.value)}}}if(!r)return f.count>0?f:null;let S=(e,i)=>{let o=r[e];if(o===void 0||!i)return;let s=i.search(t,!1),c=s.length;if(c===0)return;let l=x(e);for(let e=0;e<c;e++){let r=s[e];if(o&&!n.CoordUtils.isRangeWithinRange(t,r)||a&&!n.CoordUtils.isRangeWithinRange(r,a))continue;let i=r.value;b(r,l,i?.model??i??!0)}};if(r[W.Type.Merge]!==void 0&&c.mergeSpatial){let e=c.mergeSpatial.search(t),n=e.length;if(n>0){let t=x(W.Type.Merge);for(let r=0;r<n;r++){let n=e[r];b(n,t,n.value)}}}return S(W.Type.Unlock,c.protectedRanges),S(W.Type.Continuous,c.continuousFillSpatial),S(W.Type.DateFormat,c.dateFormatSpatial),S(W.Type.Hyperlink,c.hyperlinkSpatial),S(W.Type.Comments,c.comments),S(W.Type.BorderStyle,c.borderSpatial),S(W.Type.FillStyle,c.fillSpatial),S(W.Type.ContentStyle,c.contentSpatial),S(W.Type.Contentful,l.getContentful()),S(W.Type.Formula,{search:t=>Vh(l.getFormulas(),c.contentSpatial,t,e.cellOptions.getProtection(),e.cellOptions.styles)}),S(W.Type.Pending,l.getPending()),S(W.Type.CalcError,l.getCalcErrors()),S(W.Type.Circular,l.getCirculars()),r[W.Type.Error]!==void 0&&S(W.Type.Error,e.calcGrid.getErrorValues()),S(W.Type.Spills,l.getSpills()),S(W.Type.Table,c.tables),S(W.Type.AutoTable,c.autoTables),S(W.Type.DataValidations,c.dataValidations),S(W.Type.Conditionals,c.conditionalFormats),f.count>0?f:null}var mR=class extends Qt{_materialize(e){let t=this._rOff,n=this._pool,r=this._store,i=r.keys,a=r.type,o=r.value,s=t[e+1],c={};for(let r=t[e];r<s;r++){let e=n[r],t=i[a[e]],s=o[e],l=c[t];if(l)if(Array.isArray(l))if(Array.isArray(s)){let e=s.length;for(let t=0;t<e;t++)l.push(s[t])}else l.push(s);else c[t]=[l,s];else c[t]=s}return c}},hR={rowStart:0,colStart:0,rowEnd:0,colEnd:0},gR={visibility:`visible`,includeEmpty:!0};function _R(e,r){if(!e.state||!r||!r.searchTypes)return Bt;let i=r.bounds??e.getUsedCoords()??e.getEntireCoords(),a=null;!0===r.searchTypes?a=uf:n.CommonUtils.isObject(r.searchTypes)&&(a=r.searchTypes);let o=r.ignoreHidden,s=!0===o||o===t.IRange.Axis.Row?uH(e.rowHeaders):null,c=!0===o||o===t.IRange.Axis.Column?uH(e.columnHeaders):null,l=pR(e,i,a,r.injectReferences,r.fullyContained?i:void 0,s,c);if(!l)return Bt;let u=(r.axis??t.IRange.Axis.Column)!==t.IRange.Axis.Row,d=r.reverse??!1,f=r.byCell??!1,p=r.includeMergeOverflow??!1,m=i.colStart,h=i.rowStart,g=new mR(l,i,u,d);return{next:e=>{let t;if(t=f?e?g.seekCell(e.rowIndex,e.colIndex):g.nextCell():g.nextRegion(),!t)return zt;let n=g.intersection,r;if(p){let e=n?.merge;if(e){let t=e.getCoords(),n=t.colStart,i=t.rowStart;n<m&&h<i&&(r={colIndex:n,rowIndex:i})}}r||={colIndex:g.colStart,rowIndex:g.rowStart};let i={colIndex:g.colEnd,rowIndex:g.rowEnd};return{done:!1,value:{start:d?i:r,end:d?r:i,cell:f?{colIndex:g.cellCol,rowIndex:g.cellRow}:null,intersection:n}}}}}function vR(e,r,i){if(!e.state||!r)return null;let a=e.getEntireCoords();i&&(a={colStart:Math.max(a.colStart-i,a.colStart),rowStart:a.rowStart,colEnd:Math.min(a.colEnd+i,a.colEnd),rowEnd:a.rowEnd});let o={rowStart:r.rowStart,colStart:a.colStart,rowEnd:r.rowEnd,colEnd:a.colEnd},s={bounds:o,searchTypes:pf,axis:t.IRange.Axis.Row,ignoreHidden:!0,byCell:!1},c=r.colStart,l=r.colEnd,u,d,f=-1,p=(e,t)=>{let n=e.next();for(;!n.done;){let r=n.value,i=r.intersection,a=i.contentful;if(a){let e=r.start.rowIndex;if(!d||e!==f){let n=r.end.rowIndex,o=a.getCoords(),s=t?o.colEnd:o.colStart,c=null;t&&(c=i.continuous),u||=[];for(let t=e;t<=n;t++)u.push({rowIndex:t,colIndex:s,continuous:c,intersection:i,scalar:null,leftIndex:0,rightIndex:0,overflow:null,style:null})}f=e,d=r}n=e.next()}};c>a.colStart&&(o.colStart=a.colStart,o.colEnd=r.colStart-1,p(_R(e,s),!0)),f=-1,d=void 0,l<a.colEnd&&(o.colStart=r.colEnd+1,o.colEnd=a.colEnd,p(_R(e,s),!1));let m=e.calcGrid.getValues();if(!u)return null;u.sort(n.CoordUtils.columnFirstCellComparator);let h=u.length,g=e.cellOptions,_,v;for(let e=0;e<h;e++){let n=u[e],r=n.rowIndex,i=n.colIndex,a=m.getValueAt(r,i);n.scalar=a;let o=n.continuous;if(o||typeof a==`string`&&!n.intersection?.merge){hR.colStart=i,hR.rowStart=r,hR.colEnd=i,hR.rowEnd=r;let e=VM(void 0,hR,n.intersection,g,!0);n.style=e;let s=zM(r,i,t.ScalarType.String,e,a,null,null,o?.getCoords(),g);if(s){let e=s.leftIndex,t=s.rightIndex;n.leftIndex=e,n.rightIndex=t,(t>0&&i<c||e>0&&i>l)&&(n.overflow=s)}}n.overflow?(_||=[],_.push(n)):(v||=[],v.push(n))}return{overflows:_,stops:v}}var yR,bR=RegExp(`([0-9]+)$`),xR=86400,SR=e=>{for(let t=e.length-1;t>=0;t--)if(e[t]!==null&&e[t]!==void 0)return{value:e[t],index:t};return null},CR=(e,t)=>Math.abs(e-t)<=1e-9*Math.max(1,Math.abs(e),Math.abs(t)),wR=(e,t,n)=>t===void 0?e:r=>{let i=e(r);return i===null||((e,t,n)=>n?e>t:e<t)(i,t,n)?null:i},TR=e=>Math.round((e-Math.floor(e))*xR),ER=(e,t,n)=>{let r=e+t/xR;return n&&r<0?r-Math.floor(r):r},DR=(e,t,n=!1)=>{let r=t(e[0],e[1]);if(r===0&&!n)return null;for(let n=2;n<e.length;n++)if(t(e[n-1],e[n])!==r)return null;return r},OR=(e,t)=>{for(let n=0;n<e.length;n++)if(!tl(e[n],t))return!1;return!0},kR=(e,t)=>{if(e.length<2)return null;let n=DR(e,(e,t)=>TR(t)-TR(e),!0),r=OR(e,t),i=!0,a=el(e[0],t);for(let n=1;n<e.length;n++)if(el(e[n],t)!==a){i=!1;break}if(n!==null&&(r||i)){let n=DR(e,(e,n)=>$c(n,t)-$c(e,t));if(n!==null)return n%12==0?{unit:Hc.Year,monthEnd:r}:{unit:Hc.Month,monthEnd:r}}if(DR(e,(e,t)=>Math.round((t-e)*xR))===null){let n=!0;for(let r=0;r<e.length;r++)if(al(e[r],t)){n=!1;break}return n&&DR(e,(e,n)=>ol(n,t)-ol(e,t))!==null?{unit:Hc.Weekday,monthEnd:!1}:null}return{unit:Hc.Day,monthEnd:!1}},AR={[Hc.Day]:`days`,[Hc.Weekday]:`weekdays`,[Hc.Month]:`months`,[Hc.Year]:`years`};function jR(e,t,n,r,i){let a=n=>{let i=t+n-1,a=t+n;for(let t=0;t<e.length;t++){let n=e[t],o=r?n.rowStart:n.colStart,s=r?n.rowEnd:n.colEnd;if(o<=i&&s>=a)return!0}return!1},o=[0];for(let e=1;e<n;e++)a(e)||o.push(e);return o.push(n),i?o:o.map(e=>n-e).sort((e,t)=>e-t)}(function(e){e.Date=class{constructor(e){this.type=t.InteropScalarType.Date,this.supportsStep=!0,this.supportsStop=!0,this._options=e;let n=e?.unit?AR[e.unit]:null;this.id=e?.monthEnd?`date.monthEnd`:n?`date.${n}`:`date`}matches(e,t=0){let n=0;for(let r=t;r<e.length;r++){let i=e[r];if(i!==null){if(typeof i!=`number`)break;n=r-t+1}}return n}createFillAt(e,t){let n=!0===(t={...this._options,...t}).date1904,r=this._options?.unit,i=[];for(let t=0;t<e.length;t++)e[t]!==null&&i.push(e[t]);let a=i.length;if(a===0)return null;let o=i[0],s=!0;for(let e=0;e<a;e++)if(i[e]>=1){s=!1;break}let c=!0===t.monthEnd,l=t.stopValue,u=t.stepValue,d=(e,t,r,i)=>{if(r===Hc.Month||r===Hc.Year){let a=r===Hc.Year?12*i:i;return wR(r=>nl(e,a*(r-t),c,n),l,a>=0)}if(r===Hc.Weekday)return wR(r=>sl(e,i*(r-t),n),l,i>=0);let a=(r===Hc.Day||e>=1?xR:3600)*i;return wR(n=>ER(e,a*(n-t),s),l,a>=0)};if(u!==void 0&&r!==void 0){let t=SR(e);return t?d(t.value,t.index,r,u):null}if(a===1){let n=u??(t.reverse?-1:1);return d(o,SR(e).index,r,n)}let f=(e,t=!1)=>DR(i,e,t),p=f((e,t)=>TR(t)-TR(e),!0),m=r?null:kR(i,n),h=r===Hc.Month||r===Hc.Year;if(h||m?.unit===Hc.Month||m?.unit===Hc.Year){let t=f((e,t)=>$c(t,n)-$c(e,n));if(t!==null&&p!==null){let r=OR(i,n)||c;if(u!==void 0){let t=SR(e);return d(t.value,t.index,Hc.Month,u)}return wR(e=>ER(nl(o,t*e,r,n),p*e,!1),l,t>=0)}if(h)return null}if(r===Hc.Weekday||m?.unit===Hc.Weekday){let e=f((e,t)=>ol(t,n)-ol(e,n));return e===null?null:wR(t=>sl(o,e*t,n),l,e>=0)}if(!r||r===Hc.Day){let t=f((e,t)=>Math.round((t-e)*xR));if(t!==null){if(u!==void 0){let t=SR(e);return d(t.value,t.index,Hc.Day,u)}return wR(e=>ER(o,t*e,s),l,t>=0)}}return null}};let n=e=>{let t=0;for(let n=0;n<e.length;n++)typeof e[n]!=`number`||isNaN(e[n])||t++;return t};e.Linear=class{constructor(e){this.id=`linear`,this.type=t.InteropScalarType.Number,this.supportsStep=!0,this.supportsStop=!0,this.supportsTrend=!0,this._options=e}matches(e,t=0){let n=0;for(let r=t;r<e.length;r++){let i=e[r];if(i!==null){if(typeof i!=`number`)break;n=r-t+1}}return n}createFillAt(e,t){let r=(t={...this._options,...t}).stopValue;if(!0===t.trend){if(n(e)<2)return null;let t=$j(e);return e=>t.m*(e+1)+t.b}let i=t.stepValue;if(i!==void 0){let t=SR(e);if(!t)return null;let n=t.value,a=t.index;return wR(e=>n+i*(e-a),r,i>=0)}let a=$j(e),o=a.b,s=a.m;return e.length===1?(t.reverse&&(s=-s),t.multiFill?wR(e=>e*s+o,r,s>=0):null):wR(e=>s*(e+1)+o,r,s>=0)}};let r=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r!=null&&t.push(r)}return t},i=e=>{if(e.length<2||e[0]===0)return null;let t=e[1]/e[0];for(let n=2;n<e.length;n++)if(e[n-1]===0||!CR(e[n]/e[n-1],t))return null;return t};e.Growth=class{constructor(e){this.id=`growth`,this.type=t.InteropScalarType.Number,this.supportsStep=!0,this.supportsStop=!0,this.supportsTrend=!0,this._options=e}matches(e,t=0,n){let a=0;for(let n=t;n<e.length;n++){let r=e[n];if(r!==null){if(typeof r!=`number`)break;a=n-t+1}}if(a===0)return 0;if(n?.stepValue!==void 0||!0===n?.trend)return a;let o=r(e.slice(t,t+a));return o.length>=2&&i(o)===null?0:a}createFillAt(e,t){if(!0===(t={...this._options,...t}).trend){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r!=`number`||isNaN(r))t.push(null);else{if(r<=0)return null;t.push(Math.log(r))}}if(n(t)<2)return null;let r=$j(t);return e=>Math.exp(r.m*(e+1)+r.b)}let a=SR(e);if(!a)return null;let o,s=t.stepValue;if(s!==void 0)o=s;else{let t=r(e);if(t.length<2)return null;let n=i(t);if(n===null)return null;o=n}let c=a.value,l=a.index;return wR(e=>c*o**+(e-l),t.stopValue,c*o>=c)}};let a={sensitivity:`accent`};e.Ordinal=class{constructor(){this.id=`ordinal`,this.type=t.InteropScalarType.String}_template(e){let t=e.match(bR);if(!t)return null;let n=t[1],r=e.lastIndexOf(n);return r===-1?null:e.substring(0,r)}matches(e,t=0){let n=null,r=0;for(let i=t;i<e.length;i++){let o=e[i];if(o===null)continue;if(typeof o!=`string`)break;let s=this._template(o);if(s===null)break;if(n===null)n=s;else if(s.localeCompare(n,void 0,a)!==0)break;r=i-t+1}return r}createFillAt(e,t){let n=[],r=e[0],i=null,a=null,o=0;if(r){let e=r.match(bR);if(e){i=e[1],i.startsWith(`0`)&&(o=i.length);let t=r.lastIndexOf(i);a=r.substring(0,t)}}let s=e.length;for(let t=0;t<s;t++){let r=e[t],i=null;if(r){let e=r.substring(a.length,r.length);e.startsWith(`0`)&&(o=Math.max(o,e.length));let t=parseFloat(e);isNaN(t)||(i=t)}n.push(i)}let c=$j(n),l=c.b,u=c.m;return u!==0&&Number.isInteger(u)?n=>{if(e[n%s]===null)return null;let r=(s===1?t.reverse?-n:n:u*(n+1))+l,i=``+Math.abs(r),c=`0`.repeat(Math.max(0,o-i.length))+i;return a+c}:null}},e.Copy=class{constructor(){this.id=`copy`}matches(e,t=0){let n=0;for(let r=t;r<e.length;r++)e[r]!==null&&(n=r-t+1);return n}createFillAt(e,t){let n=e.length;return t=>e[t%n]??null}};let o=Object.freeze([`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`]),s=Object.freeze([`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`]),c=Object.freeze([`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`]),l=Object.freeze([`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`]);e.List=class{constructor(e){this.id=`list`,this.type=t.InteropScalarType.String,this._lists=[],this._map=new Map;let n=[];if(e?.customLists){let t=e.customLists;for(let e=t.length-1;e>=0;e--)n.push(t[e])}n.push(l),n.push(c),n.push(s),n.push(o);let r=this._map,i=[],a=n.length;for(let e=0;e<a;e++){let t=n[e],a=[];i.push(a);let o=t.length;for(let n=0;n<o;n++){let i=E(t[n],!0),o=i.toLowerCase().trim(),s=r.get(o);s||(s=[],r.set(o,s));let c={value:i,asKey:o,major:e,minor:n};s.push(c),a.push(c)}}this._lists=Object.freeze(i)}matches(e,t=0){let n=null,r=0;for(let i=t;i<e.length;i++){let a=e[i];if(a===null)continue;if(typeof a!=`string`)break;let o=this._map.get(a.toLowerCase().trim());if(!o)break;if(n===null)n=o.map(e=>e.major);else{let e=[];for(let t=0;t<n.length;t++)for(let r=0;r<o.length;r++)if(o[r].major===n[t]){e.push(n[t]);break}if(e.length===0)break;n=e}r=i-t+1}return r}createFillAt(e,t){let n=[],r=e[0];n.push(r.toLowerCase().trim());let i=this._map.get(n[0]),a=new Map,o=new Set,s=i.length;for(let e=0;e<s;e++){let t=i[e];a.set(t.major,t)}if(e.length>1){let t=e.length;for(let r=1;r<t;r++){let t=e[r].toLowerCase().trim(),i=this._map.get(t);if(!i)return null;n.push(t);let s=i.length;for(let e=0;e<s;e++){let t=i[e].major;a.has(t)&&o.add(t)}}if(o.size===0)return null}let c=null,l=this._lists;for(let t=0;!c&&t<l.length;t++)(e.length===1||o.has(t))&&(c=a.get(t));if(!c)return null;let u=!1,d=!1,f=Eg(r);f===1?u=!0:(f===-1||Eg(r[0])===-1)&&(d=!0);let p=l[c.major],m=p.length,h=e=>{let t=this._map.get(e);if(!t)return-1;for(let e=0;e<t.length;e++)if(t[e].major===c.major)return t[e].minor;return-1},g=c.minor,_=1;if(n.length>1){let e=h(n[1]);if(e===-1)return null;_=e-g;let t=_>0?_-m:_+m;Math.abs(t)<Math.abs(_)&&(_=t);let r=n.length;for(let e=2;e<r;e++){let t=((g+e*_)%m+m)%m;if(h(n[e])!==t)return null}}e.length===1&&t?.reverse&&(_=-_);let v=e.length;return t=>{if(e[t%v]===null)return null;let n=(t*_+g)%m;n<0&&(n=m+n);let r=p[n].value??null;return u?r.toUpperCase():d?r.toLowerCase():r}}},e.Composite=class{constructor(e,n=`composite`){this._byType=new Map,e=Array.isArray(e)?[...e]:[e],this._fillers=e,this.id=n;let r=Object.values(t.InteropScalarType);for(let t=0;t<r.length;t++){let n=r[t];this._byType.set(n,e.filter(e=>e.type===void 0||e.type===n))}}matches(e,t=0,n){let r=0;for(let n=t;n<e.length;n++)e[n]!==null&&(r=n-t+1);if(r===0)return 0;let i=n?.types,a=t+r;for(let o=t;o<a;o++){if(e[o]===null)continue;let t=i?i[o]:IH(e[o],!0),a=this._byType.get(t),s=a?a.length:0;for(let t=0;t<s;t++)if(a[t].matches(e,o,n)>0)return r}return 0}createFillAt(e,n){this._fillers,n={multiFill:e.length>1,...n,trend:!1};let r=e.length,i=0,a=!1;for(let t=0;!a&&t<=r;t++)e[t]===null?i++:a=!0;let o=0;a=!1;for(let t=r-1;!a&&t>=i;t--)e[t]===null?o++:a=!0;let s=[],c=null,l=null,u=[],d=i,f=0,p=e=>{if(c&&c.max+1===d){let t=c.value;t.fillAt.push(e),c.max=d,t.length++,t.valuesLength++}else c={min:d,max:d,value:{fillAt:[e],start:d,length:1,valuesLength:r,blankInterval:0}};s.push(c)},m=n.types,h=t=>m?m[t]:IH(e[t],!0),g=r-o;for(d=i;d<g;){let r=e[d];if(r===null){d++;continue}let i=h(d),a=d+1;for(;a<g;){let e=h(a);if(e!==i&&e!==t.InteropScalarType.Null)break;a++}l=null;let o=0,c=this._byType.get(i),m=c?c.length:0;for(let t=0;!l&&t<m;t++){let n=Math.min(c[t].matches(e,d),a-d);n>0&&(l=c[t],o=n)}for(;o>0&&e[d+o-1]===null;)o--;if(!l){p(r),d++;continue}let _=0;f=0;for(let t=1;t<o;t++)e[d+t]===null?_++:(_>0&&(t-_===1?f=_:_!==f&&(f=0)),_=0);u=[e[d]];let v=1+f,y=o;for(let t=v;t<y;t+=v)u.push(e[d+t]);if(u.length>0){let e=u.length,t=e+(e-1)*f,r=l.createFillAt?.(u,n)??u;s.push({min:d,max:d+t-1,value:{fillAt:r,start:d,length:t,valuesLength:e,blankInterval:f}})}d+=o}let _=At(s);return e=>{let t=e>=0,n=Math.abs(e),i=jt(n%r,_);if(!i)return null;let a=Math.floor(n/r),o=i.length,s=i.start,c=(a+ +!!t)*s+(a+ +!t)*(r-(s+o)),l=e+(t?-c:c),u=i.blankInterval;if(u!==0){let e=l%o;if(e%(1+u)!==0)return null;l=Math.floor(e/(1+u))+i.valuesLength*a}let d=i.fillAt;return typeof d==`function`?d(l):d[l%d.length]}}};let u=e.Types={Series:new yR.Composite([new yR.Date,new yR.Linear,new yR.Ordinal,new yR.List],`series`),Linear:new yR.Linear,Growth:new yR.Growth,DateDays:new yR.Date({unit:Hc.Day}),DateWeekdays:new yR.Date({unit:Hc.Weekday}),DateMonths:new yR.Date({unit:Hc.Month}),DateYears:new yR.Date({unit:Hc.Year}),DateMonthEnd:new yR.Date({unit:Hc.Month,monthEnd:!0}),Copy:new yR.Copy},d=e.Presets={Copy:{id:`copy`,filler:u.Copy},Series:{id:`series`,filler:u.Series},Linear:{id:`linear`,filler:u.Linear},Growth:{id:`growth`,filler:u.Growth},DateYears:{id:`date.years`,filler:u.DateYears},DateMonthEnd:{id:`date.monthEnd`,filler:u.DateMonthEnd},DateMonths:{id:`date.months`,filler:u.DateMonths},DateWeekdays:{id:`date.weekdays`,filler:u.DateWeekdays},DateDays:{id:`date.days`,filler:u.DateDays},LinearTrend:{id:`linear.trend`,filler:u.Linear,options:{trend:!0},minValues:2},GrowthTrend:{id:`growth.trend`,filler:u.Growth,options:{trend:!0},minValues:2}};e.canApply=(e,n,r)=>{let i=e.filler.type,a=0,o=r.length;for(let e=0;e<o;e++){let n=r[e];if(n!==t.InteropScalarType.Null&&(a++,i!==void 0&&n!==i))return!1}return!(a<(e.minValues??1))&&e.filler.matches(n,0,{...e.options,types:r})>0};let f=new Map(Object.values(d).map(e=>[e.id,e]));e.getPreset=e=>f.get(e),e.detectPreset=(e,n,r)=>{let i=[],a=!1,o=!1;for(let r=0;r<n.length;r++){let s=n[r];s!==t.InteropScalarType.Null&&(o=!0,s===t.InteropScalarType.Date?i.push(e[r]):s===t.InteropScalarType.Number&&(a=!0))}return i.length>0?(s=kR(i,!0===r?.date1904))?s.unit===Hc.Year?d.DateYears:s.unit===Hc.Month?s.monthEnd?d.DateMonthEnd:d.DateMonths:s.unit===Hc.Weekday?d.DateWeekdays:d.DateDays:d.DateDays:a?d.Linear:o?d.Series:d.Copy;var s},e.toFillOptions=(e,t)=>{let n=!0===(t?.trend??e.options?.trend)&&!0===e.filler.supportsTrend;return{filler:e.filler,fillerOptions:{...t,...e.options,trend:n,stepValue:n?void 0:t?.stepValue,stopValue:n?void 0:t?.stopValue}}},e.fillTo=(e,t,n,r)=>{let i=[],a=t.length,o=e.createFillAt(t,r);for(let e=a;e<n;e++)i.push(o(e));return i}})(yR||={});var MR=e=>e?t.IRange.Axis.Row:t.IRange.Axis.Column;function NR(e,r,i,a){let o,s,c;if(a){let e=bH(r,a);if(i!==void 0&&i!==e.direction)throw new n.ExpectedError(n.CommonMessages.MESSAGE_ERROR_INVALID_ARG(i));if(e.amount<=0)return null;o=e.direction,s={...r},c={...a}}else{o=i??(r.rowStart===r.rowEnd&&r.colStart!==r.colEnd?t.IRange.Direction.Right:t.IRange.Direction.Down);let n=o===t.IRange.Direction.Down||o===t.IRange.Direction.Up,a=n?r.rowStart:r.colStart,l=(n?r.rowEnd:r.colEnd)-a+1;if(l<2)return null;let u=function(e,t,n){let r=[];for(let t of e.getRegions(gv.Feature.Contentful))r.push(t.getRange().getCoords());let i=e=>t?e.rowStart:e.colStart;r.sort((e,t)=>i(e)-i(t));let a=n-1;for(let e=0;e<r.length;e++){let n=r[e];if(i(n)>a+1)break;let o=t?n.rowEnd:n.colEnd;o>a&&(a=o)}return a-n+1}(e.getRange(r),n,a),d=u<=0||u>=l?1:u;s=n?{...r,rowEnd:a+d-1}:{...r,colEnd:a+d-1},c={...r}}let l=o===t.IRange.Direction.Down||o===t.IRange.Direction.Up,u=l?s.rowStart:s.colStart,d=(l?s.rowEnd:s.colEnd)-u+1,f=l?c.rowEnd-c.rowStart+1:c.colEnd-c.colStart+1,p=l?s.colStart:s.rowStart,m=new Map,h,g=-1;for(let n of e.getRange(s).entries({axis:MR(l),features:[gv.Feature.DateFormat],reuseContext:!0})){let e=n.context.getCoords(),r=(l?e.colIndex:e.rowIndex)-p,i=r===g?h:m.get(r);if(!i){if(m.size>=64)continue;i={values:Array(d).fill(null),types:Array(d).fill(t.InteropScalarType.Null)},m.set(r,i)}g=r,h=i;let a=(l?e.rowIndex:e.colIndex)-u;i.values[a]=n.value??null,i.types[a]=n.context.getInteropType()}let _=e.getWorkbook()?.getRuntime().isDate1904()??!1,v=Object.values(yR.Presets),y=new Set;for(let e of m.values()){if(y.size>=v.length)break;for(let t=0;t<v.length;t++){let n=v[t];y.has(n.id)||yR.canApply(n,e.values,e.types)&&y.add(n.id)}}let b=[];for(let e=0;e<v.length;e++)y.has(v[e].id)&&b.push(v[e].id);let x=m.values().next().value,S=[x?yR.detectPreset(x.values,x.types,{date1904:_}).id:yR.Presets.Copy.id,yR.Presets.DateDays.id,yR.Presets.Linear.id,yR.Presets.Series.id],C=b[0]??yR.Presets.Copy.id;for(let e=0;e<S.length;e++)if(y.has(S[e])){C=S[e];break}return{direction:o,template:s,destination:c,templateSize:d,size:f,offered:b,presetId:C}}function PR(e,t){return e._withProjectedMerge(t)}function FR(e,t){return{coords:t,getCellAt:(t,n)=>e.getCell({rowIndex:t,colIndex:n})}}function IR(e){let{ctx:t,template:r,destination:i,mergesTemplate:a,filler:o,withValues:s,withFormats:c,isVertical:l,isForward:u,templateStart:d,templateEnd:f,templateSize:p,fillerOptions:m,scanFills:h,safeCreateFillAt:g}=e,_=t.getState(),v=t.getAutoFillPreviewCache(),y;return v&&v.state===_&&v.isForward===u&&v.filler===o&&v.fillerOptions===m&&n.CoordUtils.isEqualRanges(v.template,r)?y=v.seriesByLine:(y=new Map,t.setAutoFillPreviewCache({state:_,template:r,isForward:u,filler:o,fillerOptions:m,seriesByLine:y})),{coords:i,getCellAt:(e,i)=>{let m={rowIndex:e,colIndex:i};if(n.CoordUtils.isCellWithinRange(m,r))return t.getCell(m);let _=null;if(c&&a.length>0){let t=l?e:i,n=l?i:e,r=d+((t-d)%p+p)%p;for(let e=0;e<a.length;e++){let i=a[e],o=l?i.rowStart:i.colStart,s=l?i.rowEnd:i.colEnd,c=l?i.colStart:i.rowStart,u=l?i.colEnd:i.rowEnd;if(o<=r&&r<=s&&c<=n&&n<=u){let e=t-(r-o);_=l?{rowStart:e,rowEnd:e+(s-o),colStart:c,colEnd:u}:{rowStart:c,rowEnd:u,colStart:e,colEnd:e+(s-o)};break}}}if(_&&(e!==_.rowStart||i!==_.colStart))return PR(t.createCell(null,m),_);let v=l?m.rowIndex:m.colIndex,b=u?v-d:d-v+p-1,x={...m},S=b%p;x[l?`rowIndex`:`colIndex`]=u?S+d:f-S;let C=t.getCell(x),w,T=null;if(s){let e=(e=>{if(y.has(e))return y.get(e);let t={...r};l?t.colStart=t.colEnd=e:t.rowStart=t.rowEnd=e;let n=h(t),i=n.length>0?n[n.length-1]:null,a=i?g(o,i.values,i.types):null;return y.set(e,a),a})(l?m.colIndex:m.rowIndex);e&&C.getFormula()===null&&(T=e(b))}return w=c?s?t.createCell(null,m).createCell({value:T,style:C.getStyle()}):t.createCell({value:t.getCell(m).getValue(),style:C.getStyle()},m):t.getCell(m).createCell({value:T}),_?PR(w,_):w}}}function LR(e){let t=e?.type;if(t!==void 0&&t!==wk.Content.Formats&&t!==wk.Content.Values)throw new n.ExpectedError(n.CommonMessages.MESSAGE_ERROR_INVALID_ARG(t));return{withValues:t!==wk.Content.Formats,withFormats:t!==wk.Content.Values}}function RR(e,r,i,a){let{withValues:o,withFormats:s}=LR(a),{direction:c,amount:l}=bH(r,i),u=!0===a?.preview;if(l===0)return!!u&&FR(e,i);if(l<0)return u?FR(e,i):zR(e,r,i,c,a);let d=c===t.IRange.Direction.Up||c===t.IRange.Direction.Down,f=e.getSelection().getCoords(),p=[],m=a?.filler??yR.Types.Series,h={...a?.fillerOptions},g=null,_=null;try{let y={...r},b={...r},x=[r],S=e.getMerges(x);if(S.length>0&&!n.CoordUtils.isRangeWithinRange(n.CoordUtils.unionRangesArrays(S),r))throw new n.ExpectedError((0,n.t)(`error.sheet.autofillOverlapMerge`));if(c===t.IRange.Direction.Left)y.colStart=b.colStart=r.colStart-l,y.colEnd=r.colStart-1;else if(c===t.IRange.Direction.Right)y.colEnd=b.colEnd=r.colEnd+l,y.colStart=r.colEnd+1;else if(c===t.IRange.Direction.Up)y.rowStart=b.rowStart=r.rowStart-l,y.rowEnd=r.rowStart-1;else{if(c!==t.IRange.Direction.Down)throw new n.ExpectedError(n.CommonMessages.MESSAGE_ERROR_INVALID_ARG(c));y.rowEnd=b.rowEnd=r.rowEnd+l,y.rowStart=r.rowEnd+1}if(S.length>0){let e=c===t.IRange.Direction.Down||c===t.IRange.Direction.Right,i=d?r.rowStart:r.colStart,a=(d?r.rowEnd:r.colEnd)-i+1,o=jR(S,i,a,d,e),s=l%a;if(!o.some(e=>e%a===s)){let e=a;for(let t=0;t<o.length;t++){let n=o[t];n>0&&n<e&&(e=n)}throw new n.ExpectedError((v=e,(0,n.t)(`error.sheet.autofillMultiple`,{modulus:v})))}}let C=d?`rowIndex`:`colIndex`,w=d?`colIndex`:`rowIndex`,T=d?r.rowEnd+1-r.rowStart:r.colEnd+1-r.colStart,E=d?r.rowStart:r.colStart,D=d?r.rowEnd:r.colEnd,O=d?i.rowStart:i.colStart,k=d?i.rowEnd:i.colEnd,A=d?c===t.IRange.Direction.Down:c===t.IRange.Direction.Right;A||(h.reverse=!0);let j=A?D+1:O,M=A?k:E-1,N=M-j+1;p.push(n.CoordUtils.unionRanges(y,r));let P=e.runtime.isDate1904(),F=!e.getState().dateFormatSpatial.isEmpty(),I=F?Hl():null,L=new Map,R=e=>{let t=L.get(e);return t===void 0&&(t=I.isDateFormat(e)||I.isTimeFormat(e),L.set(e,t)),t},ee=n=>{let r=[],i=null,a=e.cellStateIterator({bounds:n,reverse:!A,axis:d?t.IRange.Axis.Column:t.IRange.Axis.Row,searchTypes:!!F&&{[W.Type.DateFormat]:!1},ignoreEmptyIntersections:!0}),o=a.next();for(;!o.done;){let e=o.value,n=e[0];i?.oppositeIndex!==n[w]&&(i={oppositeIndex:n[w],lastIndex:A?E-1:D+1,values:[],types:[]},r.push(i));let s=n[C];if(A)for(let e=i.lastIndex+1;e<s;e++)i.values.push(null),i.types.push(t.InteropScalarType.Null);else for(let e=i.lastIndex-1;e>s;e--)i.values.push(null),i.types.push(t.InteropScalarType.Null);i.lastIndex=s;let c=e[1]??null,l=e[2]?.dateFormat,u=l!==void 0&&typeof c==`number`&&R(l);i.values.push(c),i.types.push(u?t.InteropScalarType.Date:IH(c)),o=a.next()}let s=r.length;for(let e=0;e<s;e++){let n=r[e],i=n.values;for(let e=i.length;e<T;e++)i.push(null),n.types.push(t.InteropScalarType.Null)}return r},te=(e,t,n)=>{let r={...h,types:n,date1904:P};if(e.matches(t,0,r)>0){let n=e.createFillAt(t,r);if(n)return n}return yR.Types.Copy.createFillAt(t)};if(u)return IR({ctx:e,template:r,destination:i,mergesTemplate:S,filler:m,withValues:o,withFormats:s,isVertical:d,isForward:A,templateStart:E,templateEnd:D,templateSize:T,fillerOptions:a?.fillerOptions,scanFills:ee,safeCreateFillAt:te});g=e.beginCommit({description:(0,n.messageKey)(`op.autoFill`),operation:{name:`autoFill`,params:[r,i,a]}});let ne=o?ee(r):[],re=e.createSparseBuilder({axis:d?t.IRange.Axis.Column:t.IRange.Axis.Row}),ie=ne.length;ne.sort((e,t)=>e.oppositeIndex-t.oppositeIndex);for(let e=0;e<ie;e++){let t=e,n=te(m,ne[t].values,ne[t].types),r=ne[t].oppositeIndex,i=A?T:T+N-1;for(let e=0;e<N;e++){let t=n(i+(A?e:-e));Xc(t,!0)&&(t=fl(t,P));let a=j+e;d?re.pushAt(a,r,t):re.pushAt(r,a,t)}}sR(e,[y],a?.type??null),o&&re.apply();let ae=s?e.getMerges([b]):[],oe=n.CoordUtils.unionRangesArrays(ae);if(ae.length>0&&!n.CoordUtils.isRangeWithinRange(oe,b))throw new n.ExpectedError((0,n.t)(`error.sheet.autofillOverlapMerge`));if(ae.length>0){let n=[],i=ae.length;if(d){let e=r.rowEnd-r.rowStart+1,a=c===t.IRange.Direction.Up?-e:e;for(let e=0;e<i;e++){let t=ae[e],r=t.rowEnd-t.rowStart+1;for(let e=1;;e++){let i=t.rowStart+e*a,o=i+r-1;if(i<y.rowStart||o>y.rowEnd)break;n.push({colStart:t.colStart,rowStart:i,colEnd:t.colEnd,rowEnd:o})}}}else{let e=r.colEnd-r.colStart+1,a=c===t.IRange.Direction.Left?-e:e;for(let e=0;e<i;e++){let t=ae[e],r=t.colEnd-t.colStart+1;for(let e=1;;e++){let i=t.colStart+e*a,o=i+r-1;if(i<y.colStart||o>y.colEnd)break;n.push({colStart:i,rowStart:t.rowStart,colEnd:o,rowEnd:t.rowEnd})}}}VL(e,n)}let se=e.getState(),ce={},le={};le.borderSpatial=se.borderSpatial,le.fillSpatial=se.fillSpatial,le.contentSpatial=se.contentSpatial,le.continuousFillSpatial=se.continuousFillSpatial,le.dateFormatSpatial=se.dateFormatSpatial;let ue=r,de=y;if(!A){let e=(d?b.rowEnd+1-b.rowStart:b.colEnd+1-b.colStart)%T,t=d?`rowStart`:`colStart`,n=d?`rowEnd`:`colEnd`;e!==0&&(de={...y,[n]:Math.min(y[n],y[t]+e)},ue={...r,[t]:r[n]-e+1},y[t]=y[t]+e)}let fe=s?Object.keys(le):[],pe=fe.length;for(let e=0;e<pe;e++){let t=fe[e],n=le[t].createCopiedEntries(ue,de),r=se[t].clone(),i=n.removes,a=i.length;for(let e=0;e<a;e++)r.remove(i[e]);r.load(n.inserts),ce[t]=r}if(A&&o){let t=e.getTables().getItems({address:{rowIndex:r.rowEnd,colIndex:r.colEnd}});if(t.length===1){let e=t[0],n=e.getRange().getCoords();(y.rowEnd>n.rowEnd||y.colEnd>n.colEnd)&&e.resize({colStart:n.colStart,rowStart:n.rowStart,colEnd:Math.max(n.colEnd,y.colEnd),rowEnd:Math.max(n.rowEnd,y.rowEnd)})}}if(s){let e=d?{colStart:r.colStart,colEnd:r.colEnd,rowStart:j,rowEnd:M}:{rowStart:r.rowStart,rowEnd:r.rowEnd,colStart:j,colEnd:M};BR(se.conditionalFormats,r,e,T,d),BR(se.dataValidations,r,e,T,d)}o&&e.calcGrid.autoFill(r,y,{commitId:g.getId(),cloneKey:g.getSavepointId()}),e.updateState(ce),_={...f,ranges:p},e.commitWithDirectives(g,_,a,{undo:DA([r])})}catch(e){throw g?.rollback(),e}var v;return!0}function zR(e,r,i,a,o){let s={...r};if(a===t.IRange.Direction.Down)s.rowStart=i.rowEnd+1;else if(a===t.IRange.Direction.Up)s.rowEnd=i.rowStart-1;else if(a===t.IRange.Direction.Right)s.colStart=i.colEnd+1;else{if(a!==t.IRange.Direction.Left)throw new n.ExpectedError(n.CommonMessages.MESSAGE_ERROR_INVALID_ARG(a));s.colEnd=i.colStart-1}let c=e.getMerges([s]);if(c.length>0&&!n.CoordUtils.isRangeWithinRange(n.CoordUtils.unionRangesArrays(c),s))throw new n.ExpectedError((0,n.t)(`error.sheet.autofillOverlapMerge`));let l=e.getSelection().getCoords(),u={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd},d=e.beginCommit({description:`Auto Fill`,operation:{name:`autoFill`,params:[r,i,o]}});try{LR(o),sR(e,[s],o?.type??null);let t={...l,cell:{rowIndex:Math.min(Math.max(l.cell.rowIndex,u.rowStart),u.rowEnd),colIndex:Math.min(Math.max(l.cell.colIndex,u.colStart),u.colEnd)},ranges:[u]};e.commitWithDirectives(d,t,o,{undo:DA([r])})}catch(e){throw d?.rollback(),e}return!0}function BR(e,t,r,i,a){if(e.isEmpty())return;let o=e.search(t),s=o.length;if(s===0)return;let c=new Set;for(let e=0;e<s;e++){let t=o[e].value;t!==void 0&&c.add(t)}let l=a?r.rowStart:r.colStart,u=a?r.rowEnd:r.colEnd;for(let o of c){let s=e.getCoords(o);if(!s)continue;let c=[];for(let e=0;e<s.length;e++){let o=n.CoordUtils.intersectRanges(s[e],t);if(!o)continue;let d=a?o.rowStart:o.colStart,f=a?o.rowEnd:o.colEnd,p=Math.ceil((l-f)/i),m=Math.floor((u-d)/i);if(m<p)continue;let h=(e,t)=>{let i=a?{...o,rowStart:e,rowEnd:t}:{...o,colStart:e,colEnd:t},s=n.CoordUtils.intersectRanges(i,r);s&&c.push(s)};if(f-d+1===i)h(d+p*i,f+m*i);else for(let e=p;e<=m;e++)e!==0&&h(d+e*i,f+e*i)}c.length!==0&&o._extendRanges(c)}}function VR(e,t,r,i=null){let a=null;return i===null&&e.readonly&&(i=(0,n.messageKey)(`error.sheet.readonlyRange`)),(r||i)&&(a={getOptions:r,readOnly:i}),new EV(function(e,t){if(!e)return e;let n=!1;for(let r=0;r<e.length;r++){let i=e[r]?.scope;if(i&&YV(i,t)){n=!0;break}}return n?e.map(e=>typeof e==`string`||!0===e?.isICellRange?e:JV(e,t)):e}(t,e.internal.getSheet()),e.internal,a)}function HR(e,t,r=(0,n.t)(`error.sheet.oobRange`),i=!1){if(!i&&!n.CoordUtils.isRangeWithinRange(t,e.getEntireCoords()))throw new n.OutOfBoundsError(r);let a=t.colStart,o=t.rowStart,s=t.colEnd,c=t.rowEnd;if(c<o||s<a)throw new n.ExpectedError((0,n.t)(`error.address.invalidRangeInverted`));if(!(Number.isInteger(a)&&Number.isFinite(a)&&Number.isInteger(o)&&Number.isFinite(o)&&Number.isInteger(s)&&Number.isFinite(s)&&Number.isInteger(c)&&Number.isFinite(c)))throw new n.ExpectedError((0,n.t)(`error.address.invalidRangeCoords`))}function UR(e){return e?new n.ExpectedError((0,n.t)(`error.address.noAddress`)):new n.ExpectedError(o_(e))}function WR(e,t=null,r=null,i=null){if(t&&e.isClosed)return;if(!e.isInitializing&&e.readonly)throw new n.ExpectedError(((e=(0,n.messageKey)(`op.update`))=>(0,n.t)(`error.sheet.readonlySheet`,{description:(0,n.t)(e)}))(i));r&&!Array.isArray(r)&&(r=[r]);let a=t(r),o=e.getProtection();if(!o?.isLocked())return;if(a.length===0)throw new n.ProtectedError((0,n.t)(`error.sheet.protectedSheet`));let s=a.length;for(let e=0;e<s;e++){let t=a[e];if(!0!==o[`is${t.charAt(0).toUpperCase()}${t.slice(1)}Allowed`]?.())throw new n.ProtectedError(Oj())}}function GR(e,t,r=null,i=!0,a=!1,o=!1){if(r&&e.isClosed||t==null)return n.CommonUtils.EmptyArray;let s=Td(t,e.getEntireCoords(),a?yd:bd,t=>{if(i&&typeof t==`string`){let r=(e.getNames()?.getByName(t))?.getRanges?.();if(r)return r.getCoords();let i=e.resolveRange(t);if(i&&i.getSheet()===e.internal.getSheet())return console.warn((0,n.t)(`error.sheet.addressInvalidScope`)),[i.getCoords()];throw new n.ExpectedError(`Invalid sheet reference '${t}'.`)}}),c=s.length;for(let t=0;t<c;t++){let r=s[t];if(r){if(a){let t=r.scope;if(t&&t!==e.getName())throw new n.ExpectedError((0,n.t)(`error.sheet.addressInvalidScope`))}HR(e,r,void 0,o)}}if(!r)return s;if(s.length===0)throw UR(t);return WR(e,r,s),s}function KR(e,t,r=null,i=!0){if(!t)throw new n.ExpectedError((0,n.t)(`error.address.noAddress`));let a=GR(e,t,r?e=>r(e):void 0,i);if(a.length===0)throw new n.ExpectedError(o_(t));return a[0]}var qR=class e{constructor(e){if(this._magicCell=null,this._adjusting=null,this._firstActiveCoords=null,this._cache={range:null,ranges:null},this._sheet=e.sheet,!this._sheet)throw Error(`Sheet is required`);this._coords=e.coords??n.CoordUtils.EmptySelection,this._emitter=new x(this),this._adjusting=null,this._shapePolicy=e.shapePolicy??`mixed`,this._navigationPolicy=e.navigationPolicy??`clear`}navigate(e,r=!1,i=!1,a=0){let o=this._coords;if(!o.cell)return this;let s=o.cell,c=o.cell;if(r&&o.ranges.length>0){let n=o.ranges[o.rangeIndex],r=o.cell;switch(e){case t.IRange.Direction.Up:c={rowIndex:r.rowIndex===n.rowStart?n.rowEnd:n.rowStart,colIndex:n.colEnd},s={rowIndex:r.rowIndex===n.rowStart?n.rowStart:n.rowEnd,colIndex:n.colStart};break;case t.IRange.Direction.Down:c={rowIndex:r.rowIndex===n.rowEnd?n.rowStart:n.rowEnd,colIndex:n.colEnd},s={rowIndex:r.rowIndex===n.rowEnd?n.rowEnd:n.rowStart,colIndex:n.colStart};break;case t.IRange.Direction.Left:c={rowIndex:n.rowEnd,colIndex:r.colIndex===n.colStart?n.colEnd:n.colStart},s={rowIndex:n.rowStart,colIndex:r.colIndex===n.colStart?n.colStart:n.colEnd};break;case t.IRange.Direction.Right:c={rowIndex:n.rowEnd,colIndex:r.colIndex===n.colEnd?n.colStart:n.colEnd},s={rowIndex:n.rowStart,colIndex:r.colIndex===n.colEnd?n.colEnd:n.colStart}}}let l=this._getRangeFromCell(c),{rowStart:u,colStart:d}=l,f=this._magicCell;if(f)switch(e){case t.IRange.Direction.Up:case t.IRange.Direction.Down:f.colIndex>=l.colStart&&f.colIndex<=l.colEnd&&(d=f.colIndex);break;case t.IRange.Direction.Left:case t.IRange.Direction.Right:f.rowIndex>=l.rowStart&&f.rowIndex<=l.rowEnd&&(u=f.rowIndex)}if(!a){let r=this._getEntireRange(),a=r.rowStart??0,o=r.rowEnd??2**53-1,s=r.colStart??0,f=r.colEnd??2**53-1;switch(e){case t.IRange.Direction.Up:u=n.SelectionTraversalUtils.traverseHiddenHeaders(this._hiddenRowsAt.bind(this),Math.max(l.rowStart-1,a),e,Math.max(a,this._hiddenRowsAt(a,!1)));break;case t.IRange.Direction.Down:u=n.SelectionTraversalUtils.traverseHiddenHeaders(this._hiddenRowsAt.bind(this),Math.min(l.rowEnd+1,o),e,Math.min(o,o-this._hiddenRowsAt(o,!0)));break;case t.IRange.Direction.Left:d=n.SelectionTraversalUtils.traverseHiddenHeaders(this._hiddenColumnsAt.bind(this),Math.max(l.colStart-1,s),e,Math.max(s,this._hiddenColumnsAt(s,!1)));break;case t.IRange.Direction.Right:d=n.SelectionTraversalUtils.traverseHiddenHeaders(this._hiddenColumnsAt.bind(this),Math.min(l.colEnd+1,f),e,Math.min(f,f-this._hiddenColumnsAt(f,!0)))}if(i)switch(e){case t.IRange.Direction.Up:case t.IRange.Direction.Down:u=this._contentfulCellFinder({...c,colIndex:this._coords.cell.colIndex},e);break;case t.IRange.Direction.Left:case t.IRange.Direction.Right:d=this._contentfulCellFinder({...c,rowIndex:this._coords.cell.rowIndex},e)}u=Math.min(Math.max(u,a),o),d=Math.min(Math.max(d,s),f)}let p=null;a&&(p={});let m={rowIndex:u,colIndex:d},h=this._getRangeFromCell(m),g={rowIndex:h.rowStart,colIndex:h.colStart};r||(this._magicCell=m);let _=this._firstActiveCoords,v=n.CoordUtils.isEqualCells(_,g)&&n.CoordUtils.isEqualCells(_,s);if(r&&!v?this.modify(g,s):this.clearAndModify(g),p)this._scrollCellCoordsIntoView(p);else{if(r&&_){let n=this._getEntireRange();if(e===t.IRange.Direction.Right&&_.colIndex===n.colEnd||e===t.IRange.Direction.Left&&_.colIndex===n.colStart||e===t.IRange.Direction.Up&&_.rowIndex===n.rowEnd||e===t.IRange.Direction.Down&&_.rowIndex===n.rowStart)return this}e===t.IRange.Direction.Left||e===t.IRange.Direction.Right?this._scrollCellCoordsIntoView({colStart:m.colIndex}):e!==t.IRange.Direction.Up&&e!==t.IRange.Direction.Down||this._scrollCellCoordsIntoView({rowStart:m.rowIndex})}return this}getCoords(){return this._coords}hasTopOrLeft(){let e=this._coords;if(e.cell.rowIndex===0||e.cell.colIndex===0)return!0;let t=e.ranges,n=t.length;for(let e=0;e<n;e++){let n=t[e];if(n.rowStart===0||n.colStart===0)return!0}return!1}getSheet(){return this._sheet}getCell(){let e=this._coords;return this._sheet.getCell(e.cell)}getRange(e){let t=this._coords,n=this._cache;if(!e&&n.range)return n.range;let r=EA(t),i=this._sheet.getRange(this._localCoords(r[0]));return e||(n.range=i),i}getRanges(e){let t=this._coords,n=this._cache;if(!e&&n.ranges)return n.ranges;let r=EA(t),i=this._sheet.getRanges(r,e);return e||(this._cache.ranges=i),i}updateCoords(e){let t=this._coords;if(n.CoordUtils.isEqualSelectionCoords(t,e))return this;let r=this._resolveEntireHeaderSelection(TA(e,this._coords,this._getEntireRange()));if(n.CoordUtils.isEqualSelectionCoords(t,r))return this;this._coords=r;let i=this._cache;return i.range=null,i.ranges=null,this._emitter.notify(`onChange`),this}isEntire(){let e=this._coords;if(e.ranges.length===0)return!1;let t=this._getEntireRange(),r=e.ranges,i=r.length;for(let e=0;e<i;e++){let i=r[e];if(!n.CoordUtils.isRangeWithinRange(t,i))return!1}return!0}getSelectedRuns(e){return wA(e,this._coords,this._getEntireRange())}isEquals(e){let t=this._coords,r=e.getCoords();return n.CoordUtils.isEqualSelectionCoords(t,r)}traverse(e=t.IRange.Axis.Row,r=!1,i){let a=t.IRange.Direction.Right;a=e===t.IRange.Axis.Row?r?t.IRange.Direction.Left:t.IRange.Direction.Right:r?t.IRange.Direction.Up:t.IRange.Direction.Down;let o=this._coords;if(o.ranges.length===0){let t=KV(this._sheet).getTraverseRegion(o.cell,e,r)??i;if(t&&!n.CoordUtils.isSingleCell(t)){let e={ranges:[t],cell:o.cell,rangeIndex:0},r=n.SelectionTraversalUtils.findNextCellWithinSelection(e,a,this._getRangeFromCell.bind(this),this._hiddenRowsAt.bind(this),this._hiddenColumnsAt.bind(this));return this.clearAndModify(r.cell),this._scrollCellCoordsIntoView({rowStart:r.cell.rowIndex,colStart:r.cell.colIndex}),this}return this.navigate(a)}let s=this._getRangeFromCell(o.cell);if(n.CoordUtils.isEqualRangesArrays([s],o.ranges))return this.navigate(a);let c=n.SelectionTraversalUtils.findNextCellWithinSelection(o,a,this._getRangeFromCell.bind(this),this._hiddenRowsAt.bind(this),this._hiddenColumnsAt.bind(this));return this.updateCoords(c)}traverseCorners(){let e=this._coords;if(e.ranges.length===0)return this;let r=e.ranges[e.rangeIndex],i=this._hiddenRowsAt.bind(this),a=this._hiddenColumnsAt.bind(this),o=n.SelectionTraversalUtils.traverseHiddenHeaders(i,r.rowStart,t.IRange.Direction.Down,r.rowEnd),s=n.SelectionTraversalUtils.traverseHiddenHeaders(i,r.rowEnd,t.IRange.Direction.Up,r.rowStart),c=n.SelectionTraversalUtils.traverseHiddenHeaders(a,r.colStart,t.IRange.Direction.Right,r.colEnd),l=n.SelectionTraversalUtils.traverseHiddenHeaders(a,r.colEnd,t.IRange.Direction.Left,r.colStart),{rowIndex:u,colIndex:d}=e.cell,f;return f=u===o&&d===c?{rowIndex:o,colIndex:l}:u===o&&d===l?{rowIndex:s,colIndex:c}:u===s&&d===c?{rowIndex:s,colIndex:l}:{rowIndex:o,colIndex:c},this.updateCoords({ranges:e.ranges,rangeIndex:e.rangeIndex,cell:f}),this._scrollCellCoordsIntoView({rowStart:f.rowIndex,colStart:f.colIndex}),this}clearHidden(){let e=this.getRanges().getVisible();if(!e)return this;let t=e.getCoords();if(t.length===0)return this;let r=this._coords.cell,i=this._hiddenRowsAt(r.rowIndex)>0||this._hiddenColumnsAt(r.colIndex)>0?{rowIndex:t[0].rowStart,colIndex:t[0].colStart}:r,a=0;for(let e=0;e<t.length;e++)if(n.CoordUtils.isCellWithinRange(i,t[e])){a=e;break}return this.updateCoords({ranges:t,rangeIndex:a,cell:i})}_resolveEntireHeaderSelection(e){let t=e.rangeIndex,n=t>=0?e.ranges[t]:null;if(!n)return e;let r=this._getEntireRange(),i=WV([n],r,!0),a=GV([n],r,!0);if(i===a)return e;let o=e.cell;if(i&&o.rowIndex!==n.rowStart||a&&o.colIndex!==n.colStart)return e;let s=this._sheet.getView();if(!s)return e;let c=(i?this._entireColumnsToTableBody(n):null)??n,l=s.getTopLeftCell(),u=i?Math.max(c.rowStart,Math.min(l.rowIndex,c.rowEnd)):o.rowIndex,d=a?Math.max(c.colStart,Math.min(l.colIndex,c.colEnd)):o.colIndex;return c===n&&u===o.rowIndex&&d===o.colIndex?e:Object.freeze({cell:Object.freeze({...o,rowIndex:u,colIndex:d}),ranges:c===n?e.ranges:e.ranges.map((e,n)=>n===t?c:e),rangeIndex:t})}_entireColumnsToTableBody(e){let t=this._sheet.getColumnHeaders(),n=t.at(e.colStart)?.getColumn();if(!n)return null;let r=n.getTable();for(let n=e.colStart+1;n<=e.colEnd;n++)if(t.at(n)?.getColumn()?.getTable()!==r)return null;let i=r.getDataRange().getCoords();return!i||i.rowStart>i.rowEnd?null:Object.freeze({...e,rowStart:i.rowStart,rowEnd:i.rowEnd})}_isEntireRange(e){e||=EA(this._coords)[0];let t=this._sheet.getEntireRange().getCoords();return GV([e],t,!0)&&WV([e],t,!0)}async selectRegion(e){let r=e?.entireRegion??!1,i=e?.contentOnly??!1,a=e?.axis,o=this._sheet;if(a!==void 0){let e=this._coords,r=o.getCell(e.cell).getTable(),i=(r?r.getDataRange():o.getEntireRange()).getCoords(),s=e.ranges.length&&e.rangeIndex>=0?e.ranges[e.rangeIndex]:n.CoordUtils.cellToRange(e.cell),c=a===t.IRange.Axis.Column||a===t.IRange.AxisSelection.Both,l=a===t.IRange.Axis.Row||a===t.IRange.AxisSelection.Both,u={rowStart:c?i.rowStart:s.rowStart,rowEnd:c?i.rowEnd:s.rowEnd,colStart:l?i.colStart:s.colStart,colEnd:l?i.colEnd:s.colEnd},d=e.rangeIndex;return this._setSelectionRanges(e=>e.length?e.map((e,t)=>t===d?{...e,...u}:e):[u]),o.getRange(u)}let s=null;if(r)s=o.getEntireRange();else{let e=this._coords;if(this._isEntireRange()){let t=o.getRange(e.cell);s=t.getSurrounding(),s.isEntireRange()&&(s=t)}else s=this.getRange().getSurrounding({contentOnly:i})}return s&&await s.select(),s}clear(){this._setSelectionRanges(n.CoordUtils.EmptyRanges)}modify(e,t,n){if(this._shapePolicy===`cell`)return;let r=this._coords,i=this._rangesFromCellOptional(r,e,t??r.cell);if(!i)return;let a=r.rangeIndex;this._setSelectionRanges(e=>e.length?e.map((e,t)=>a===t?{...e,...i}:e):[i]),n&&i&&this._setSelectionCell({colIndex:i.colStart,rowIndex:i.rowStart})}append(e,t=e,r){if(this._shapePolicy!==`ranges`&&this._shapePolicy!==`mixed`||!e||this._isCellOutOfBounds(e)||this._isCellOutOfBounds(t))return;let i=this._coords,a=this._cellToRangeActual(e,t);if(!a)return;let o=i.ranges.length>0?[...i.ranges]:[this._cellToRangeActual(i.cell,i.cell)];o.push(a);let s={ranges:o,cell:{rowIndex:a.rowStart,colIndex:a.colStart,...r},rangeIndex:o.length-1};n.CoordUtils.isEqualSelectionCoords(s,i)||this.updateCoords(s)}clearAndModify(e,t,n){let r=this._coords;e={...r.cell,...e},t??=e;let i=this._rangesFromCellOptional(r,e,t);if(!i)return;let a={rowIndex:i.rowStart,colIndex:i.colStart},o={...a,...n};this._navigationPolicy===`modify`?this.modify(a,a):(this._firstActiveCoords=o,this.clear()),this._setSelectionCell(o)}setAdjusting(e){this._adjusting=e,this._emitter.notify(`onAdjustingChange`)}getAdjusting(){let t=this._adjusting;if(!t)return null;let n=new e({sheet:this._sheet,coords:t,shapePolicy:this._shapePolicy,navigationPolicy:this._navigationPolicy});return n._adjusting=t,n}createSelection(t){return new e({sheet:this._sheet,coords:t?.coords,shapePolicy:t?.shapePolicy??this._shapePolicy,navigationPolicy:t?.navigationPolicy??this._navigationPolicy})}addListeners(e,t){return this._emitter.addListeners(e,t)}_setSelectionRanges(e){let t=this._coords,r=typeof e==`function`?e(t.ranges):e??n.CoordUtils.EmptyRanges;if(n.CoordUtils.isEqualRangesArrays(r,t.ranges))return;let i=Math.max(r.length?0:-1,Math.min(t.rangeIndex,r.length-1)),a=t.cell;i===-1||n.CoordUtils.isCellWithinRange(a,r[i])||(a={rowIndex:r[i].rowStart,colIndex:r[i].colStart}),this._shapePolicy===`mixed`&&r.length===1&&n.CoordUtils.isSingleCell(r[0])&&n.CoordUtils.isCellWithinRange(a,r[0])&&(r=[],i=-1);let o={cell:a,ranges:r,rangeIndex:i};n.CoordUtils.isEqualSelectionCoords(o,t)||this.updateCoords(o)}_setSelectionCell(e){let t=this._coords,r=e??n.CoordUtils.EmptyCell,i=this._getRangeFromCell(r),a=this._shapePolicy===`range`||this._shapePolicy===`ranges`;if(t.ranges.length===0&&(a||!n.CoordUtils.isSingleCell(i)))return this.updateCoords({ranges:[i],rangeIndex:0,cell:r});if(n.CoordUtils.isEqualCells(r,t.cell))return this;let o=t.ranges,s=t.rangeIndex;this._shapePolicy===`mixed`&&t.ranges.length===1&&(n.CoordUtils.isSingleCell(t.ranges[0])&&n.CoordUtils.isCellWithinRange(r,t.ranges[0])||!n.CoordUtils.isCellWithinRange(r,t.ranges[0]))&&(o=[],s=-1);let c={ranges:o,rangeIndex:s,cell:r};return n.CoordUtils.isEqualSelectionCoords(c,t)?this:this.updateCoords(c)}_isCellOutOfBounds(e){let t=this._getEntireRange();return e.rowIndex<t.rowStart||e.colIndex<t.colStart||e.colIndex>t.colEnd||e.rowIndex>t.rowEnd}_cellToRangeActual(e,t){let r={rowStart:Math.min(e.rowIndex,t.rowIndex),colStart:Math.min(e.colIndex,t.colIndex),rowEnd:Math.max(e.rowIndex,t.rowIndex),colEnd:Math.max(e.colIndex,t.colIndex)};if(this._canSelectionSpanMergedCells(r))return r;let i=this._getRangeFromCell(e),a=this._getRangeFromCell(t),o={rowStart:Math.min(i.rowStart,a.rowStart),colStart:Math.min(i.colStart,a.colStart),rowEnd:Math.max(i.rowEnd,a.rowEnd),colEnd:Math.max(i.colEnd,a.colEnd)},s=this._getMergedRanges(o);return n.CoordUtils.extendRangeToUnionRanges(o,s)}_rangesFromCellOptional(e,t,n){let r=e.ranges.length>0?e.ranges[e.rangeIndex]:{rowStart:e.cell.rowIndex,colStart:e.cell.colIndex,rowEnd:e.cell.rowIndex,colEnd:e.cell.colIndex},i={rowStart:Math.min(t.rowIndex??r.rowStart,n.rowIndex??r.rowStart),colStart:Math.min(t.colIndex??r.colStart,n.colIndex??r.colStart),rowEnd:Math.max(t.rowIndex??r.rowEnd,n.rowIndex??r.rowEnd),colEnd:Math.max(t.colIndex??r.colEnd,n.colIndex??r.colEnd)},a={rowIndex:i.rowStart,colIndex:i.colStart},o={rowIndex:i.rowEnd,colIndex:i.colEnd};if(!this._isCellOutOfBounds(a)&&!this._isCellOutOfBounds(o))return this._cellToRangeActual(a,o)}_getEntireRange(){return this._sheet.getEntireRange().getCoords()}_hiddenRowsAt(e,t){return this._sheet.getRowHeaders().hiddenHeadersAt(e,t)}_hiddenColumnsAt(e,t){return this._sheet.getColumnHeaders().hiddenHeadersAt(e,t)}_localCoords(e){if(!e||e.scope===void 0)return e;let{scope:t,...n}=e;return n}_getRangeFromCell(e){let t=n.CoordUtils.cellToRange(e);if(this._sheet.isDeleted())return t;let r=this._sheet.getRange(this._localCoords(t),{ignoreHidden:!0}).getMerges();return r.length===0?t:r[0]}_canSelectionSpanMergedCells(e){let t=this._sheet.getRange(this._localCoords(e));return t.isEntireColumns()||t.isEntireRows()}_getMergedRanges(e){return this._sheet.getRange(this._localCoords(e),{ignoreHidden:!0}).getMerges()}_isContentfulCell(){return!1}_contentfulCellFinder(e,r){let i=this._sheet.getRange(this._localCoords(n.CoordUtils.cellToRange(e))).getExtended(r,e).getCoords();switch(r){case t.IRange.Direction.Up:return i.rowStart;case t.IRange.Direction.Down:return i.rowEnd;case t.IRange.Direction.Left:return i.colStart;case t.IRange.Direction.Right:return i.colEnd}}_scrollCellCoordsIntoView(e,t){return this._sheet.scrollTo(e,t?{scroll:t}:void 0)}get[Symbol.toStringTag](){return`[RangeShape]`}toString(){let e=``;return e+=`selection:[${this._sheet.getRange(this._localCoords(this._coords.cell)).toString()}`,this._coords.ranges&&this._coords.ranges.length>0&&(e+=`, ${this._sheet.getRanges(this._coords.ranges.map(e=>this._localCoords(e))).toString()}`),this._coords.rangeIndex!==void 0&&this._coords.rangeIndex!==-1&&(e+=`, ${this._coords.rangeIndex}`),e+=`]`,e}get isIRangeSelection(){return!0}},JR=Object.freeze({coords:n.CoordUtils.EmptyCell,topLeft:n.TypesUtils.EmptyTopLeft}),YR=(Object.freeze({cell:n.CoordUtils.EmptyCell,ranges:n.CommonUtils.EmptyArray,rangeIndex:0}),Object.freeze({selection:null,topLeft:n.TypesUtils.EmptyTopLeft,freezePanes:JR,showRowHeaders:!0,showColumnHeaders:!0,showRowGridlines:!0,showColumnGridlines:!0,rowHeaderStyle:Sj.HeaderTextStyle.One,columnHeaderStyle:Sj.HeaderTextStyle.A1,tableNames:Sj.ColumnHeaderTableNames.Sticky,showFormulas:!1,showLockedShading:!1,showInvalid:!1,showZeros:!0,rightToLeft:!1,zoomScale:100,gridLineColor:null}));function XR(e,t=!0,n=15,r=10,i=400){let a=Math.max(e-r,0)+(t?1:-1);return Math.min(i,Math[t?`ceil`:`floor`](a/n)*n+r)}var ZR=class{constructor(e){let t=e?.sheet;if(!t)throw Error(`SheetView requires a sheet.`);this._id=n.CommonUtils.uuidV4();let r=new x(this);this._emitter=r,this._sheet=t;let i=new qR({sheet:t});this._rangeSelection=i,this.clear(!1),e?.json&&this._fromJSON(e.json);let a=this,o={onChange(e){a._emitter.notify(`onSelectionChange`)}};this._rangeSelectionRemoveListener=i.addListeners(o,{transactional:!1})}getId(){return this._id}addListeners(e,t){return this._emitter.addListeners(e,t)}setTopLeft(e){if(!e)return this;let t=this._state,n=t.topLeft,r=n.left,i=n.top,a=e.left??r,o=e.top??i;return a===r&&o===i||(t.topLeft=Object.freeze({left:a,top:o}),this._emitter.notify(`onTopLeftChange`)),this}getTopLeft(){return this._state.topLeft}getTopLeftCell(){let e=this._state.topLeft,t=this._state.freezePanes,n=t?.coords,r=t?.topLeft,i=(n?.rowIndex??0)>0,a=(n?.colIndex??0)>0;return{rowIndex:this._sheet.getRowHeaders().getIndex(i?r?.top??0:e.top),colIndex:this._sheet.getColumnHeaders().getIndex(a?r?.left??0:e.left)}}getFreezePanes(){return this._state.freezePanes}setFreezePanes(e){return this._state.freezePanes=this._mergeFreezePanes(e),this._emitter.notify(`onFreezePaneChange`),this}_mergeFreezePanes(e){return e?{...this._state.freezePanes,coords:{colIndex:e?.coords?.colIndex??this._state.freezePanes.coords.colIndex,rowIndex:e?.coords?.rowIndex??this._state.freezePanes.coords.rowIndex},topLeft:{left:e?.topLeft?.left??this._state.topLeft.left,top:e?.topLeft?.top??this._state.topLeft.top}}:JR}isShowRowHeaders(){return this._state.showRowHeaders}setShowRowHeaders(e){return this._update(e,`showRowHeaders`,`onHeaderChange`),this}isShowColumnHeaders(){return this._state.showColumnHeaders}setShowColumnHeaders(e){return this._update(e,`showColumnHeaders`,`onHeaderChange`),this}isShowRowGridlines(){return this._state.showRowGridlines}setShowRowGridlines(e){return this._state.showRowGridlines=e,this._notifyAll(),this}isShowColumnGridlines(){return this._state.showColumnGridlines}setShowColumnGridlines(e){return this._state.showColumnGridlines=e,this._notifyAll(),this}getRowHeaderStyle(){return this._state.rowHeaderStyle}setRowHeaderStyle(e){return this._update(e,`rowHeaderStyle`,`onHeaderChange`),this}setColumnHeaderStyle(e){return this._update(e,`columnHeaderStyle`,`onHeaderChange`),this}getColumnHeaderStyle(){return this._state.columnHeaderStyle}setColumnHeaderTableNames(e){return this._update(e,`tableNames`,`onHeaderChange`),this}getColumnHeaderTableNames(){return this._state.tableNames}getZoomScale(){return this._state.zoomScale}setZoomScale(e){e<1&&console.warn(`Zoom scale is expressed as a whole number percentage (e.g., 100 for 100%).`);let t=Math.min(400,Math.max(10,e));return this._state.zoomScale===t?this:this._updateZoom(t)}zoomIn(){return this._updateZoom(XR(this.getZoomScale(),!0))}zoomOut(){return this._updateZoom(XR(this.getZoomScale(),!1))}_updateZoom(e){return e===this.getZoomScale()||(this.update({zoomScale:e}),this._emitter.notify(`onZoomScaleChange`)),this}getNextZoomScale(e,t){return XR(this.getZoomScale(),e,t)}isShowFormulas(){return this._state.showFormulas}setShowFormulas(e){return this._state.showFormulas=e,this._notifyAll(),this}isShowLockedShading(){return this._state.showLockedShading}setShowLockedShading(e){return this._state.showLockedShading=e,this._notifyAll(),this}isShowInvalid(){return this._state.showInvalid}setShowInvalid(e){return this._state.showInvalid=e,this._notifyAll(),this}isRightToLeft(){return this._state.rightToLeft}setRightToLeft(e){return this._state.rightToLeft=e,this._notifyAll(),this}isShowZeros(){return this._state.showZeros}setShowZeros(e){return this._state.showZeros=e,this._notifyAll(),this}getGridLineColor(){return this._state.gridLineColor}setGridLineColor(e){return this._state.gridLineColor=e,this._notifyAll(),this}getRangeSelection(){return this._rangeSelection}getMovableSelection(){return this._movableSelection}setMovableSelection(e){let t=this._movableSelection;return this._movableSelection=Object.freeze(e??[]),n.CommonUtils.isEqualArrays(t,this._movableSelection)||this._emitter.notify(`onMovableSelectionChange`),this}selectMovables(e,t=!1){let r=new Set(this._sheet.getMovables().getItems()),i=null,a=!1;if(t){i=[...this._movableSelection];for(let t=e.length-1;t>=0;t--){let n=e[t],o=i.indexOf(n);if(o!==t){if(a=!0,!r.has(n))throw Error(`Movable ${n.getContent().getName?.()} not found in sheet.`);o!==-1&&i.splice(o,1),i.unshift(n)}}}else a=!n.CommonUtils.isEqualArrays(e,this._movableSelection),i=[...e];return a?(this._movableSelection=i,this._emitter.notify(`onSelectionChange`),this._emitter.notify(`onMovableSelectionChange`),this):this}unselectMovables(e){let t=this._movableSelection,n=[];for(let r=0;r<t.length;r++){let i=t[r];e.indexOf(i)===-1&&n.push(i)}return t.length!==n.length&&(this._movableSelection=n,this._emitter.notify(`onSelectionChange`),this._emitter.notify(`onMovableSelectionChange`)),this}_update(e,t,n){let r=this._state,i=r[t];return r[t]=e,i!==e&&this._emitter.notify(n),i}_notifyAll(){let e=this._emitter;e.notify(`onSelectionChange`),e.notify(`onTopLeftChange`),e.notify(`onZoomScaleChange`),e.notify(`onFreezePaneChange`),e.notify(`onAnyChange`),e.notify(`onHeaderChange`)}toJSON(){let e={},t=Object.keys(this._state),n=t.length;for(let r=0;r<n;r++){let n=t[r],i=this._state[n];i!=null&&i!==YR[n]&&(e[n]=i)}delete e.movableSelection,delete e.gridLineColor,this._state.gridLineColor instanceof zf&&(e.gridLineColor=this._state.gridLineColor.toString()),delete e.topLeft,!this._state.topLeft||this._state.topLeft.left===0&&this._state.topLeft.top===0||(e.topLeft={left:this._state.topLeft.left??0,top:this._state.topLeft.top??0}),delete e.selection;let r=this._rangeSelection.getCoords();if(r){let t={};!r.cell||r.cell.colIndex===0&&r.cell.rowIndex===0||(t.cell=cd(r.cell)),r.ranges&&r.ranges.length>0&&(t.ranges=xd(r.ranges),r.rangeIndex!==void 0&&r.rangeIndex!==-1&&r.rangeIndex!==0&&(t.rangeIndex=r.rangeIndex)),Object.keys(t).length>0&&(e.selection=t)}return delete e.freezePanes,!this._state.freezePanes||this._state.freezePanes.coords.colIndex===0&&this._state.freezePanes.coords.rowIndex===0||(e.freezePanes={...this._state.freezePanes}),Object.keys(e).length===0?null:e}_fromJSON(e){let t=JSON.parse(JSON.stringify(e||{}));t?.zoomScale&&(t.zoomScale=n.CommonUtils.roundAccurately(parseFloat(e.zoomScale),2));let r=e=>{let t=this._sheet.getRange(e).getBounds();return{x:1*t.x,y:1*t.y,width:1*t.width,height:1*t.height}};if(typeof t?.gridLineColor==`string`&&(this._sheet?.getStyles()?t.gridLineColor=this._sheet.getStyles().parseColor(e.gridLineColor):console.warn(`Style was created with no styles so gridLineColor can't be parsed.`)),t.topLeft)if(typeof t.topLeft==`string`){let e=r(Ed(t.topLeft));t.topLeft={left:e.x,top:e.y}}else t.topLeft=Object.freeze({left:t.topLeft?.left??t?.x??0,top:t.topLeft?.top??t?.y??0});if(t.selection){let e=Ed(t.selection.cell??`A1`);if(t.selection.cell=e,t.selection.ranges){let r=Math.max(0,Math.min(t.selection.rangeIndex??t.selection.ranges?.length-1,t.selection.ranges?.length-1));t.selection.rangeIndex=r;let i=!1;for(let a=0;a<t.selection.ranges.length;a++){let o=Ad(t.selection.ranges[a]);t.selection.ranges[a]=o,a===r&&e&&!n.CoordUtils.isCellWithinRange(e,o)&&(i=!0)}if(i)for(let r=0;i&&r<t.selection.ranges.length;r++)n.CoordUtils.isCellWithinRange(e,t.selection.ranges[r])&&(i=!1,t.selection.rangeIndex=r);i&&(t.selection.ranges.push(n.CoordUtils.cellToRange(e)),t.selection.rangeIndex=t.selection.ranges.length-1)}else delete t.selection.rangeIndex}if(t.freezePanes){let e=t.freezePanes;if(typeof e.coords==`string`&&(e.coords=Ed(e.coords)),typeof e.topLeft==`string`){let n=Ed(e.topLeft),i=r({colIndex:n.colIndex,rowIndex:n.rowIndex}),a=r({colIndex:e?.coords?.colIndex??0,rowIndex:e?.coords?.rowIndex??0});e.topLeft={left:0,top:0},t.topLeft||={top:0,left:0},n.colIndex>0&&(e.topLeft.left=t.topLeft?.left??0,t.topLeft.left=i.x-a.x+e.topLeft.left),n.rowIndex>0&&(e.topLeft.top=t.topLeft?.top??0,t.topLeft.top=i.y-a.y+e.topLeft.top)}t.freezePanes={coords:{colIndex:e?.coords?.colIndex??0,rowIndex:e?.coords?.rowIndex??0},topLeft:{left:e?.topLeft?.left??0,top:e?.topLeft?.top??0}}}this.update(t)}clear(e=!0){return this._state={...YR},this._movableSelection=n.CommonUtils.EmptyArray,this._rangeSelection.clear(),e&&this._notifyAll(),this}update(e){let t={...YR,...this._state,...e};return t.selection&&(this._rangeSelection.updateCoords(t.selection),delete t.selection),t.freezePanes=this._mergeFreezePanes(t.freezePanes),t.zoomScale=Math.min(400,Math.max(10,t.zoomScale)),this._state=t,this._notifyAll(),this}get[Symbol.toStringTag](){return`[SheetView]`}toString(){let e=this.toJSON();return e?JSON.stringify(e):`DefaultSheetView`}get isISheetView(){return!0}},QR=class e{constructor(e,t,n){this.isIExternalBook=!0,this._json=e,this._id=t,this._collection=n}getId(){return this._id}getDisplayName(e){return $S(this,e)}getSources(){return this._json.sources??n.CommonUtils.EmptyArray}getSheetNames(){return this._json.sheetNames}getDefinedNames(){return this._json.definedNames??[]}getSheetData(e){return this._json.sheetDataSet?.find(t=>t.sheetIndex===e)??null}getDependents(){return this._collection._getDependents(this._id)}delete(e){this._collection._remove(this._id,e)}breakLink(e){this._collection._breakLink(this._id,e)}refresh(){return this._collection._refresh(this._id)}toJSON(){return this._json}_withSnapshot(t){return new e({...this._json,sheetNames:[...t.sheetNames],definedNames:t.definedNames?[...t.definedNames]:void 0,sheetDataSet:t.sheetDataSet?[...t.sheetDataSet]:void 0},this._id,this._collection)}_withRefreshError(){let t=this._json.sheetDataSet;return!t||t.length===0||t.every(e=>e.refreshError)?this:new e({...this._json,sheetDataSet:t.map(e=>e.refreshError?e:{...e,refreshError:!0})},this._id,this._collection)}_withSheetName(t){return new e({...this._json,sheetNames:[...this._json.sheetNames,t]},this._id,this._collection)}},$R=class extends S{constructor(e){super(e?.transactions),this.isIExternalBookCollection=!0,this._getDependentsById=e?.getDependents??null,this._getSheetRange=e?.getSheetRange??null,this._resolver=e?.resolver??null;let t=this;this._transactions=e?.transactions??new g({transient:!0}),this._stateId=this._transactions.create(),this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onAfterStateChange(e){t._notifyCollectionChange()}});let r=e?.json??[],i=r.map(()=>n.CommonUtils.uuidV4()),a=r.map((e,t)=>e?new QR(e,i[t],this):null),o=this._beginCommit((0,n.messageKey)(`op.initialize`));try{o.updateState(this._stateId,()=>({items:a,ids:i})),o.amend()}catch(e){throw o.rollback(),e}}_getIdByIndex(e){return this._getState().ids[e-1]??null}_getIndexById(e){let t=this._getState().ids.indexOf(e);return t===-1?-1:t+1}getById(e){let t=this._getState(),n=t.ids.indexOf(e);return n===-1?null:t.items[n]??null}_getItems(){let e=[],t=this._getState().items,n=t.length;for(let r=0;r<n;r++){let n=t[r];n&&e.push(n)}return e}_getByIndex(e){return this._getState().items[e-1]??null}add(e,t){this._assertWritable();let r=typeof e.sources==`string`?[tC(e.sources)]:[...e.sources];if(r.length===0)throw Error(`sources is required`);let i={sources:r,sheetNames:e.sheetNames?[...e.sheetNames]:[]},a=n.CommonUtils.uuidV4(),o=new QR(i,a,this);return this._updateState(e=>({items:[...e.items,o],ids:[...e.ids,a]}),{description:(0,n.t)(`op.addExternalBook`,{name:QS(o)}),...t}),o}_remove(e,t){this._assertWritable();let r=this._getState(),i=r.ids.indexOf(e);if(i===-1)return!1;let a=r.items[i],o=a?(0,n.t)(`op.removeExternalBook`,{name:QS(a)}):(0,n.messageKey)(`op.removeExternalBook`);return this._updateState(t=>{let n=t.ids.indexOf(e);if(n===-1)return t;let r=[...t.items],i=[...t.ids];return r.splice(n,1),i.splice(n,1),{items:r,ids:i}},{description:o,...t}),!0}_breakLink(e,t){this._assertWritable();let r=this.getById(e);if(!r)return!1;let i=(0,n.t)(`op.breakExternalLink`,{name:QS(r)});return this._transactions.doBatch(()=>(this._breakDependents(r),this._remove(e)),{description:i,...t})}breakAll(e){this._assertWritable();let t=this.getItems();return t.length===0?0:this._transactions.doBatch(()=>{let e=0;for(let n=0;n<t.length;n++)this._breakDependents(t[n]),this._remove(t[n].getId())&&e++;return e},{description:(0,n.messageKey)(`op.breakExternalLinks`),...e})}async refreshAll(){let e=this.getItems(),t=[];for(let n=0;n<e.length;n++)t.push(await this._refresh(e[n].getId()));return t}async _refresh(e){let t=this.getById(e),r=this._resolver;if(!t||!r)return{bookId:e,status:`unavailable`};let i;try{i=await r.resolve(t)}catch(t){return this.getById(e)&&this._markRefreshError(e),{bookId:e,status:`failed`,error:t?.message??String(t)}}return i&&this.getById(e)?(this._assertWritable(),this._updateState(t=>{let n=t.ids.indexOf(e),r=t.items[n];if(!r)return t;let a=[...t.items];return a[n]=r._withSnapshot(i),{...t,items:a}},{description:(0,n.t)(`op.refreshExternalLink`,{name:QS(t)})}),{bookId:e,status:`refreshed`}):{bookId:e,status:`unavailable`}}_markRefreshError(e){this._assertWritable(),this._updateState(t=>{let n=t.ids.indexOf(e),r=t.items[n];if(!r)return t;let i=r._withRefreshError();if(i===r)return t;let a=[...t.items];return a[n]=i,{...t,items:a}},{description:(0,n.t)(`op.refreshExternalLink`,{name:QS(this.getById(e))})})}_breakDependents(e){let t=e.getDependents();for(let e=0;e<t.length;e++){let n=t[e],r=this._getSheetRange?.(n)??null;r&&r.setValues(r.getValues())}}_getDependents(e){return this._getDependentsById?.(e)??n.CommonUtils.EmptyArray}_addSheetName(e,t){this._assertWritable();let r=this._getState(),i=r.ids.indexOf(e),a=r.items[i];if(!a)return-1;let o=a.getSheetNames(),s=t.toLowerCase();for(let e=0;e<o.length;e++)if(o[e].toLowerCase()===s)return e;return this._updateState(n=>{let r=n.ids.indexOf(e),i=n.items[r];if(!i)return n;let a=[...n.items];return a[r]=i._withSheetName(t),{...n,items:a}},{description:(0,n.t)(`op.addExternalBook`,{name:QS(a)})}),o.length}toJSON(){let e=this._getState().items;return e.length===0?null:e.map(e=>e?.toJSON()??null)}addListeners(e,t){return super.addListeners(e,t)}close(){this.isClosed()||(this._close(),this._transactionsRemoveListener?.())}_assertWritable(){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`))}_getState(){return this._transactions.getState(this._stateId)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_updateState(e,t){let n=this._beginCommit(t);try{n.updateState(this._stateId,e),n.commit()}catch(e){throw n.rollback(),e}}},ez=class{constructor(e){this._namesByKey=new Map,this._namesById=new Map,this._hostsById=new Map,this._loadedData=new Map,this._options=e}sync(e=!1){let{books:n,getGrid:r,unregisterGrid:i}=this._options,a=this._options.holdsGrids?.()??!0,o=new Set,s=new Set,c=new Set,l=n.getItems();for(let t=0;t<l.length;t++){let n=l[t],u=n.getId(),d=n.getSheetNames();for(let e=0;e<d.length;e++){let t=uC(u,e);o.add(t),a&&(r(t)?this._loadedData.get(t)!==(n.getSheetData(e)?.data??null)&&(i(t),this._registerSheet(n,e,t),c.add(u)):(this._registerSheet(n,e,t),c.add(u)))}let f=n.getDefinedNames();for(let t=0;t<f.length;t++){let r=f[t];if(!r.name)continue;let i=r.sheetIndex,a=uC(u,i!==void 0&&i>=0&&i<d.length?i:-1),o=nz(a,r.name);s.add(o);let l=this._namesByKey.get(o);if(l){if(l.refersTo!==(r.refersTo??``)){l.refersTo=r.refersTo??``;let e=this._hostsById.get(l.getId());e&&this._queueBody(l.getId(),e,n,a,l.refersTo,!1),c.add(u)}}else this._registerName(n,a,r,e),c.add(u)}}for(let e of this._registeredSheetGrids())o.has(e)||(i(e),this._loadedData.delete(e),c.add(cC(e).bookId));for(let[e,n]of this._namesByKey){if(s.has(e))continue;this._namesByKey.delete(e),this._namesById.delete(n.getId());let r=this._hostsById.get(n.getId());this._hostsById.delete(n.getId()),r?.setPlaceholder(t.FormulaError.BuiltIn.Name.toString()),c.add(cC(n.getScope()).bookId)}return c}getNameByScope(e,t){return this._namesByKey.get(nz(t,e))??null}getNameById(e){return this._namesById.get(e)??null}_registeredSheetGrids(){let e=[];for(let t of this._options.gridIds()){let n=cC(t);n&&n.sheetIndex>=0&&e.push(t)}return e}_registerSheet(e,t,n){let r=this._options.createGrid(n),i=e.getSheetData(t)?.data??null;this._loadedData.set(n,i);let a=function(e){if(!e||e.length===0)return null;let t=[];for(let n=0;n<e.length;n++){let[r,i]=e[n];for(let e=0;e<i.length;e++){let[n,a]=i[e],o=a.length;for(let e=0;e<o;e++){let i=tz(a.at(e));i!=null&&t.push({col:n+e,row:r,value:i})}}}if(t.length===0)return null;t.sort((e,t)=>e.col-t.col||e.row-t.row);let n=new z.Builder;for(let e=0;e<t.length;e++)n.pushAt(t[e].col,t[e].row,t[e].value);return n.build()?.tuples??null}(i);a&&r._seedNow({data:a})}_registerName(e,t,n,r){let{bindNameId:i,createHost:a}=this._options,o=i(n.name,t),s={getId:()=>o,getName:()=>n.name,getScope:()=>t,refersTo:n.refersTo??``};this._namesByKey.set(nz(t,n.name),s),this._namesById.set(o,s);let c=a(o);this._hostsById.set(o,c),this._queueBody(o,c,e,t,s.refersTo,r)}_queueBody(e,n,r,i,a,o){let{queue:s,recompileNamed:c}=this._options,l=a.trim();l.startsWith(`=`)&&(l=l.substring(1)),l||=t.FormulaError.BuiltIn.Ref.toString();let u=cC(i),d=u.sheetIndex>=0?u.sheetIndex:r.getSheetNames().length>0?0:-1,f=uC(u.bookId,d);s(async()=>{this._hostsById.get(e)===n&&n.setBody({coords:rz,expression:l,authoredAt:iz,scopeGridId:f})&&(o||c(e))})}};function tz(e){if(e==null)return null;if(typeof e!=`object`)return e;let n=e;switch(n.t){case`e`:return t.FormulaError.getBuiltInByCode(n.v)??t.FormulaError.BuiltIn.Value;case`b`:return n.v!==0;default:return n.v}}var nz=(e,t)=>e+`::`+t.toLowerCase(),rz=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),iz=Object.freeze({rowIndex:0,colIndex:0}),az=32768,oz=(e,t)=>e*az+t,sz=class{constructor(e,n,r){this._pending=new Map,this._errors=0,this._uncovered=!1,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1,this._demand=new Map,this._demandErrors=0,this._demandRowStart=2**53-1,this._demandRowEnd=-1,this._demandColStart=2**53-1,this._demandColEnd=-1,this._anyRowStart=2**53-1,this._anyRowEnd=-1,this._anyColStart=2**53-1,this._anyColEnd=-1,this._inner=e,this._committed=n,this._flush=r,this._isColumn=e.getAxis()===t.IRange.Axis.Column}get isPendingOverlay(){return!0}getInner(){return this._inner}get size(){return this._pending.size}get demandSize(){return this._demand.size}push(e,n,r){let i=oz(e,n),a=this._pending,o=a.get(i);o===void 0?this._inner.getValueAt(e,n)===void 0&&(this._uncovered=!0):t.FormulaError.isError(o)&&this._errors--,t.FormulaError.isError(r)&&this._errors++,a.set(i,r??null),e<this._rowStart&&(this._rowStart=e),e>this._rowEnd&&(this._rowEnd=e),n<this._colStart&&(this._colStart=n),n>this._colEnd&&(this._colEnd=n),this._growAny(e,n)}pushDemand(e,n,r){r??=null;let i=oz(e,n),a=this._demand,o=a.get(i);o!==void 0&&t.FormulaError.isError(o)&&this._demandErrors--,t.FormulaError.isError(r)&&this._demandErrors++,a.set(i,r),this._inner.getValueAt(e,n)===void 0&&this._inner.setValueAt(e,n,r),e<this._demandRowStart&&(this._demandRowStart=e),e>this._demandRowEnd&&(this._demandRowEnd=e),n<this._demandColStart&&(this._demandColStart=n),n>this._demandColEnd&&(this._demandColEnd=n),this._growAny(e,n)}takeDemand(e,n){let r=this._demand;if(r.size===0)return;let i=oz(e,n),a=r.get(i);a!==void 0&&(t.FormulaError.isError(a)&&this._demandErrors--,r.delete(i),r.size===0&&this._resetDemand())}commitDemand(){this._demand.size!==0&&(this._writeDemandIn(null),this._demand.clear(),this._resetDemand())}reset(){this._pending.size!==0&&(this._pending.clear(),this._errors=0,this._uncovered=!1,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1,this._resetAny())}_resetDemand(){this._demandErrors=0,this._demandRowStart=2**53-1,this._demandRowEnd=-1,this._demandColStart=2**53-1,this._demandColEnd=-1,this._resetAny()}_growAny(e,t){e<this._anyRowStart&&(this._anyRowStart=e),e>this._anyRowEnd&&(this._anyRowEnd=e),t<this._anyColStart&&(this._anyColStart=t),t>this._anyColEnd&&(this._anyColEnd=t)}_resetAny(){this._anyRowStart=Math.min(this._rowStart,this._demandRowStart),this._anyRowEnd=Math.max(this._rowEnd,this._demandRowEnd),this._anyColStart=Math.min(this._colStart,this._demandColStart),this._anyColEnd=Math.max(this._colEnd,this._demandColEnd)}intersects(e,t,n,r){return e<=this._anyRowEnd&&n>=this._anyRowStart&&t<=this._anyColEnd&&r>=this._anyColStart}_pendingIntersects(e,t,n,r){return e<=this._rowEnd&&n>=this._rowStart&&t<=this._colEnd&&r>=this._colStart}hasErrorIn(e){if(this._committed.hasErrorIn(e))return!0;let t=e.rowStart,n=e.colStart,r=e.rowEnd,i=e.colEnd;return!!(this._errors>0&&this._pendingIntersects(t,n,r,i)&&cz(this._pending,t,n,r,i))||this._demandErrors>0&&t<=this._demandRowEnd&&r>=this._demandRowStart&&n<=this._demandColEnd&&i>=this._demandColStart&&cz(this._demand,t,n,r,i)}_boundsIntersect(e){return!e||this._pendingIntersects(e.rowStart??-(2**53-1),e.colStart??-(2**53-1),e.rowEnd??2**53-1,e.colEnd??2**53-1)}_writeDemandIn(e){if(this._demand.size===0)return;let t=e?.rowStart??-(2**53-1),n=e?.colStart??-(2**53-1),r=e?.rowEnd??2**53-1,i=e?.colEnd??2**53-1;if(t>this._demandRowEnd||r<this._demandRowStart||n>this._demandColEnd||i<this._demandColStart)return;let a=this._inner;for(let[e,o]of this._demand){let s=Math.floor(e/az),c=e-s*az;s>=t&&s<=r&&c>=n&&c<=i&&a.setValueAt(s,c,o)}}_layered(e){if(this._pending.size>0){let t=this._pending.get(e);if(t!==void 0)return t}return this._demand.size>0?this._demand.get(e):void 0}_coverFor(e){this._uncovered&&this._boundsIntersect(e)&&this._flush()}_flushIfPendingIn(e){this._pending.size>0&&this._boundsIntersect(e)&&this._flush(),this._writeDemandIn(e)}_inBounds(e,t){return e>=this._anyRowStart&&e<=this._anyRowEnd&&t>=this._anyColStart&&t<=this._anyColEnd}_isEmpty(){return this._pending.size===0&&this._demand.size===0}_substituteRun(e,t,n){let r=this._isColumn,i=r?this._anyColStart:this._anyRowStart,a=r?this._anyColEnd:this._anyRowEnd;if(e<i||e>a)return n;let o=r?this._anyRowStart:this._anyColStart,s=r?this._anyRowEnd:this._anyColEnd,c=n.length,l=t+c-1;if(l<o||t>s)return n;let u=Math.max(t,o),d=Math.min(l,s),f=null;for(let i=u;i<=d;i++){let a=this._layered(r?oz(i,e):oz(e,i));if(a!==void 0){if(f===null){f=Array(c);for(let e=0;e<c;e++)f[e]=n.at(e)}f[i-t]=a}}return f??n}getValueAt(e,t){if(this._inBounds(e,t)){let n=this._layered(oz(e,t));if(n!==void 0)return n}return this._inner.getValueAt(e,t)}getRuns(e){this._coverFor(e?.bounds);let t=this._inner.getRuns(e);if(this._isEmpty())return t;let n={[Symbol.iterator]:()=>n,next:()=>{let e=t.next();if(e.done)return e;let n=e.value,r=this._substituteRun(n[0],n[1],n[2]);return r===n[2]?e:{done:!1,value:[n[0],n[1],r]}}};return n}entries(e){this._coverFor(e?.bounds);let t=this._inner.entries(e);if(this._isEmpty())return t;let n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);if(n.done)return n;let r=n.value,i=r[0];if(this._inBounds(i.rowIndex,i.colIndex)){let e=this._layered(oz(i.rowIndex,i.colIndex));e!==void 0&&(r[1]=e)}return n}};return n}values(e){if(this._coverFor(e?.bounds),this._isEmpty())return this._inner.values(e);let t=this.entries(e),n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);return n.done?{done:!0,value:void 0}:{done:!1,value:n.value[1]}}};return n}keys(e){return this._coverFor(e?.bounds),this._inner.keys(e)}getValues(e){return this._flushIfPendingIn(e),this._inner.getValues(e)}copyTo(e,t,n){this._flushIfPendingIn(n),this._inner.copyTo(e,t,n)}getAxis(){return this._inner.getAxis()}getCount(){return this._coverFor(null),this._inner.getCount()}getCoords(){return this._coverFor(null),this._inner.getCoords()}getMaxCoords(){return this._inner.getMaxCoords?.()??null}clone(e){return this._flush(),this._writeDemandIn(null),this._inner.clone(e)}cloneEmpty(e){return this._inner.cloneEmpty(e)}setValues(e){return this._commitAll(),this._inner.setValues(e),this}setValueAt(e,t,n){this._commitAll(),this._inner.setValueAt(e,t,n)}delete(e){return this._commitAll(),this._inner.delete?.(e)??!1}clear(){this._commitAll(),this._inner.clear?.()}shift(e,t){return this._commitAll(),this._inner.shift?.(e,t)??!1}_commitAll(){this._flush(),this.commitDemand()}get[Symbol.toStringTag](){return`[PendingOverlayGrid]`}};function cz(e,n,r,i,a){for(let[o,s]of e){if(!t.FormulaError.isError(s))continue;let e=Math.floor(o/az),c=o-e*az;if(e>=n&&e<=i&&c>=r&&c<=a)return!0}return!1}var lz=class extends VT{constructor(e,t){super(),this.nodes=e,this.count=t}},uz=class extends VT{constructor(e){super(),this.node=e}},dz=class extends VT{constructor(e){super(),this.node=e}};function fz(e,n=0,r=0){let i=(e=e._materializeEmpty())._values,a=e._coords,o=i.getRuns({bounds:a}),s=i.getAxis()!==t.IRange.Axis.Row,c=s?a.colStart:a.rowStart,l=s?a.rowStart:a.colStart,u=new z.Builder(null,n,r),d=o.next();for(;!d.done;){let e=d.value;u.pushMultipleAt(e[0]-c,e[1]-l,e[2]),d=o.next()}return u.build()}function pz(e,n,r){let i=n.rowEnd-n.rowStart+1,a=n.colEnd-n.colStart+1,o=function(e,n,r){let i=e?.isIRange?e:null,a=i?i.getRowCount():1,o=i?i.getColumnCount():1,s=Array(n);for(let c=0;c<n;c++){let n=Array(r),l=a===1?0:c<a?c:-1;for(let a=0;a<r;a++){let r=o===1?0:a<o?a:-1;n[a]=l<0||r<0?t.FormulaError.BuiltIn.NA:i?i.getValueAt(l,r):e}s[c]=n}return s}(e,i,a),s=r?a:i,c=r?i:a,l=r?n.colStart:n.rowStart,u=r?n.rowStart:n.colStart,d=new z.Builder(null),f=!0;for(let e=0;e<s;e++){let t=null,n=0;for(let i=0;i<c;i++){let a=r?o[i][e]:o[e][i];a==null?t&&=(d.pushMultipleAt(l+e,u+n,t),null):(t||(t=[],n=i,f=!1),t.push(a))}t&&d.pushMultipleAt(l+e,u+n,t)}return f?null:d.build()}function mz(e,t,n,r,i=null){let a=e.value,o=a.formulaBlockWidth,s=a.formulaBlockHeight,c=a.formulaEntry.value,l=n-e.colStart,u=t-e.rowStart,d=e.rowEnd-e.rowStart-(s-1),f=e.colEnd-e.colStart-(o-1),p=a.$absRowEnd?0:Math.max(0,u-d),m=a.$absRowStart?s-1:Math.min(s-1,u),h=a.$absColEnd?0:Math.max(0,l-f),g=a.$absColStart?o-1:Math.min(o-1,l),_=c.ref;i===null?c.forEachNodeIn(_.rowStart+p,_.rowStart+m,_.colStart+h,_.colStart+g,r):i(c,_.rowStart+p,_.rowStart+m,_.colStart+h,_.colStart+g,r)}function hz(e,t,n,r,i,a,o=null){let s=e.value,c=s.formulaBlockWidth,l=s.formulaBlockHeight,u=Math.max(t,e.rowStart),d=Math.min(r,e.rowEnd);if(u>d)return;let f=Math.max(n,e.colStart),p=Math.min(i,e.colEnd);if(f>p)return;let m=e.rowEnd-e.rowStart-(l-1),h=e.colEnd-e.colStart-(c-1),g=s.$absRowEnd?0:Math.max(0,u-e.rowStart-m),_=s.$absRowStart?l-1:Math.min(l-1,d-e.rowStart),v=s.$absColEnd?0:Math.max(0,f-e.colStart-h),y=s.$absColStart?c-1:Math.min(c-1,p-e.colStart);if(g>_||v>y)return;let b=1,x=0,S=1,C=0;if(t>=e.rowStart&&t<=e.rowEnd&&n>=e.colStart&&n<=e.colEnd){let r=t-e.rowStart,i=n-e.colStart;b=s.$absRowEnd?0:Math.max(0,r-m),x=s.$absRowStart?l-1:Math.min(l-1,r),S=s.$absColEnd?0:Math.max(0,i-h),C=s.$absColStart?c-1:Math.min(c-1,i)}let w=s.formulaEntry.value,T=w.ref,E=e=>{let t=e.rowIndex-T.rowStart,n=e.colIndex-T.colStart;t>=b&&t<=x&&n>=S&&n<=C||a(e)};o===null?w.forEachNodeIn(T.rowStart+g,T.rowStart+_,T.colStart+v,T.colStart+y,E):o(w,T.rowStart+g,T.rowStart+_,T.colStart+v,T.colStart+y,E)}var gz=class{constructor(e,t){this.members=new Set,this.downstream=new Set,this._memberEntry=null,this._downstreamEntry=null,this._iteration=null,this._host=e,this._cycleId=t}getCycleId(){return this._cycleId}isEmpty(){return this.members.size===0&&this.downstream.size===0}getEntry(e){return e?(this._memberEntry||={cycle:this,kind:`member`},this._memberEntry):(this._downstreamEntry||={cycle:this,kind:`downstream`},this._downstreamEntry)}setIteration(e){this._iteration=e}getRepresentative(){let e=this._liveMembers();return e.length>0?this._toCoords(e[0]):null}getMembers(){return this._liveMembers().map(e=>this._toCoords(e))}getMemberCount(){return this._countLive(this.members)}getDownstreamCount(){return this._countLive(this.downstream)}isMember(e){return this._memberAt(e)!==null}getPath(e){let t=this._memberAt(e);if(!t)return[];let n=this.members,r=[t],i=t.ext.cycleNext;for(;i&&i!==t&&r.length<n.size&&n.has(i)&&this._host.isLiveNode(i);)r.push(i),i=i.ext.cycleNext;return r.map(e=>this._toCoords(e))}_memberAt(e){for(let t of this.members)if(t.rowIndex===e.rowIndex&&t.colIndex===e.colIndex&&this._host.isLiveNode(t)&&(e.scope===void 0||e.scope===this._scopeOf(t)))return t;return null}isIterative(){return this._iteration!==null}isConverged(){return this._iteration?.converged??!1}getIterationCount(){return this._iteration?.iterationCount??0}getLastChange(){return this._iteration?.lastChange??0}getPreviousChange(){return this._iteration?.previousChange??NaN}_liveMembers(){let e=[];for(let t of this.members)this._host.isLiveNode(t)&&e.push(t);return e.sort(_z),e}_countLive(e){let t=0;for(let n of e)this._host.isLiveNode(n)&&t++;return t}_scopeOf(e){return(e.gridId?this._host.resolveScope(e.gridId):void 0)??null}_toCoords(e){return{rowIndex:e.rowIndex,colIndex:e.colIndex,scope:this._scopeOf(e)}}};function _z(e,t){return e.gridId===t.gridId?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.gridId===null?-1:t.gridId===null?1:e.gridId.localeCompare(t.gridId)}var vz=class{constructor(e,t,r){this._pendingCalcs=new Map,this._circularNodesLength=0,this._demandBatch=[],this._taintGroup=0,this._iterate=null,this._demandActive=!1,this._iterHitsLength=0,this._iterMembersLength=0,this._iterDownstreamLength=0,this._openGroups=new Map,this._groupAlias=new Map,this._sweeping=!1,this._iterSorted=!1,this._sweepIndex=-1,this._deferredLength=0,this._passActive=!1,this._passCycleId=0,this._passMarkId=0,this._flush=null,this._overlays=null,this._fallbackDirty=null,this._cycles=new Map,this._cycleGroupNext=0,this._cycleEpoch=0,this._demandStats={evaluations:0,retries:0},this._planStats={formulaCacheHits:0,formulaCacheMisses:0,passes:0,fastEligible:0,fastHits:0,closureEligible:0,closureHits:0,stampedPlans:0,closureAssertFailures:0,planAssertFailures:0,dependentsAssertFailures:0,dependentsCacheHits:0,dependentsCacheMisses:0,evaluated:0,discoveryMs:0,inDegreeMs:0,kahnMs:0,evaluateMs:0},this.planCacheMode=`on`,this._planIdNext=0,this._lastPlanId=0,this._lastStampedLength=0,this._lastStampedOrderedLength=0,this._planMemos=[{seeds:[],seedsLength:0,plan:[],planLength:0,epoch:-1,used:0,cycleFree:!1,cycleEpoch:-1,demandStart:0},{seeds:[],seedsLength:0,plan:[],planLength:0,epoch:-1,used:0,cycleFree:!1,cycleEpoch:-1,demandStart:0}],this._planMemoClock=0,this._pendingPromises=new Set,this._gridUpdates=null,this._addDynamicPrecedent=null,this.scheduleRecalculation=(e,t)=>{t&&(this._pendingCalcs.set(t,e),this._flushPendingCalcs())},this.doCollectVolatileCalcs=(e,t,n,r,i)=>{let a=r.values,o=r.length;if(!n||n.size===0)return o;let s=o,c=new Map,l=n=>{n.markId=t,n.cycleId=e,a[s++]=n;let r=n.ext;r!==null&&r.pendingPromise&&(r.pendingPromise.cancelled=!0)};return n.forEach(n=>{if(n.markId===t&&n.cycleId===e||!(e=>{let t=e.block;if(!t)return!1;let n=c.get(t);if(n!==void 0)return n;Nz.colStart=Nz.colEnd=e.colIndex,Nz.rowStart=Nz.rowEnd=e.rowIndex,Nz.scope=e.gridId;let r=i.search(Nz),a=!1;for(let e=0;!a&&e<r.length;e++)a=r[e].value===t;return c.set(t,a),a})(n))return;let r=n.block;if(r.isBlankAware(e)){let i=r.getTouched(e,t),a=r.representative;if(a===null||a.markId===t&&a.cycleId===e||l(a),n===a||!function(e,t,n){for(let r=0;r<e.length;r++){let i=e[r];if(t>=i.rowStart&&t<=i.rowEnd&&n>=i.colStart&&n<=i.colEnd)return!0}return!1}(i.touched,n.rowIndex,n.colIndex))return}l(n)}),r.length=s,s},this.doCollectDirtyCalcs=(e,t,n,r,i,a,o)=>{let s=r.values,c=r.length,l=n=>{if(n.cycleId===e&&n.markId===t)return;s[c++]=n,n.markId=t,n.cycleId=e;let r=n.ext;r!==null&&r.pendingPromise&&(r.pendingPromise.cancelled=!0)},u=(n,r,i,a,o)=>{let s=n.ref;if(n.isBlankAware(e)){let c=n.getTouched(e,t),u=c.touched,d=u.length;for(let e=0;e<d;e++){let t=u[e],c=Math.max(r,t.rowStart-s.rowStart),d=Math.min(i,t.rowEnd-s.rowStart);if(c>d)continue;let f=Math.max(a,t.colStart-s.colStart),p=Math.min(o,t.colEnd-s.colStart);f>p||n.mintNodesIn(s.rowStart+c,s.rowStart+d,s.colStart+f,s.colStart+p,l)}let f=n.representative;f!==null&&bz(c.blank,s,r,i,a,o)&&l(f);return}n.mintNodesIn(s.rowStart+r,s.rowStart+i,s.colStart+a,s.colStart+o,l)},d=e=>{let t=e.ref;u(e,0,t.rowEnd-t.rowStart,0,t.colEnd-t.colStart)},f=n.length;for(let e=0;e<f;e++){let t=n[e];$z.length=0;let r=$z;a.search(t,!1,!1,r);let s=r.length;i.search(t,!1,!1,r);let c=r.length;if(c===0)continue;let l=t.colStart,f=t.rowStart,p=t.colEnd-l,m=t.rowEnd-f;for(let e=0;e<s;e++){let t=r[e],n=t.value;if(n.index<0){o.push(t),d(n.formulaEntry.value);continue}let i=n.formulaEntry.value,a=i.ref,s=a.colEnd-a.colStart,c=a.rowEnd-a.rowStart,h=t.colEnd-t.colStart-s,g=t.rowEnd-t.rowStart-c,_=0,v=c,y=0,b=s,x=f-t.rowStart,S=l-t.colStart;n.$absRowEnd||(_=Math.min(Math.max(x-g,0),c)),n.$absRowStart||(v=Math.min(x+m,c)),n.$absColEnd||(y=Math.min(Math.max(S-h,0),s)),n.$absColStart||(b=Math.min(p+S,s)),u(i,_,v,y,b)}for(let e=s;e<c;e++){let t=r[e],n=t.value,i=n.ref,a=i.colEnd-i.colStart,o=i.rowEnd-i.rowStart,s=f-t.rowStart,c=l-t.colStart;u(n,Math.min(Math.max(s,0),o),Math.min(s+m,o),Math.min(Math.max(c,0),a),Math.min(p+c,a))}}return r.length=c,c},this._container=e,this._context=t,this._requestCalculate=r,this._cycleHost={isLiveNode:e=>this.isLiveNode(e),resolveScope:t=>e.resolveScope(t)},this._passHook=(e,t,n,r,i,a)=>this._onPassRead(e,t,n,r,i,!0===a),this._taintDownstream=e=>{if((e.state&QP)!==lF)return;e.state=e.state&~ZP|YP|sF|dF;let t=FP(e);t.cycleGroup=this._taintGroup,t.demandValue=Gz(e),this._addCircular(e)},this._flushPendingCalcs=n.TimerUtils.debounce(()=>{let e=this._container.getVolatiles();this._pendingCalcs.forEach((t,n)=>{n.cycleId>t||e.add(n)}),this._pendingCalcs.clear(),this._requestCalculate()},100)}execute(e,t,n){let{isFullCalc:r,calcCoords:i,gridId:a,scopeGridId:o}=t,{gridsAll:s,formulaSpatial:c,dirtySpatial:l,oldVolatiles:u}=n,d=this._container,f=e=>d.getIncrementalUpdates(e),p=d.getPrecedents(),m=p,h=d.getDynamics(),g=h,_=new Map;this._gridUpdates=_,this._resetCircular(),this._iterate=t.iterate??null,this._context._setDynamicReadHook(this._passHook),this._passActive=!0;let v=[],y=new Set,b=()=>{if(v.length!==0){m===p&&(m=m.clone()),m.removeAll(v,dL);for(let e=0;e<v.length;e++)y.add(v[e].value.formulaEntry.value);v.length=0}},x=1,S=wB;if(S.length=0,r||(this.doCollectVolatileCalcs(e,x,u,S,c),u.clear()),i)s.get(i.scope??a)&&this.doCollectDirtyCalcs(e,x,[i],S,c,m,v);else{let t=o&&s.has(o)?o:null,n=t?[t]:r?s.keys():l.getScopeKeys(),i=[],a=!1;for(let e of n){let n=s.get(e);if(n)if(f(e),r){let t={...n.getEntireCoords()};t.scope=e,i.push(t)}else a||(a=!0,l.all3D(i),t&&(i=i.filter(t=>t.scope===e)))}this.doCollectDirtyCalcs(e,x,i,S,c,m,v)}if(_.size===0&&S.length===0)return this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,null;if(S.length===0)return this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,{precedentSpatial:m,dynamicByBlock:g,lastUpdates:new Map(_)};let C=new Map;this._addDynamicPrecedent=(e,t,n)=>{e?.block&&(d.getScope().perCellRead=!0,TI(C,e,t,n))};let w=new Map,T=(e,t)=>{(function(e,t,n,r){if(t===0)return;let i,a,o,s=xz,c=[],l=new Set,u=()=>{let e=i.build();e&&e.tuples&&(o.values.setValues(e.tuples),hI(o.errorSpatial,e.tuples,r));let t=a.done(!0);for(let e=0;e<t.length;e++){let n=t[e];o.notifyValues.insertNonOverlapping(n)}let n=o.pendingConflating;if(n){let e=n.done(!0);o.notifyPending.load(e),o.pendingConflating=null}let s=o.circularConflating;if(s){let e=s.done(!0);o.notifyCircular.load(e),o.circularConflating=null}let l=o.formatsConflating;if(l){let e=l.done(!0);o.notifyFormats.load(e),o.formatsConflating=null}c.length>0&&(o.notifyFormats.load(c),c=[])};e.length=t,e.sort(r?Cz:Tz);for(let d=0;d<t;d++){let t=e[d],f=t.colIndex,p=t.rowIndex,m=t.gridId;m||console.log(`nodeGridId is null`,t),m!==s&&(s!==xz&&u(),i=new z.Builder(yz),a=ei(r),s=m,o=n(m));let h=r?f:p,g=r?p:f,_=t.cachedValue;_?.isIRange||(i.pushAt(h,g,_),a.append(h,g));let v=t.block,y=t.numFmt;t.numFmt=null;let b=v.getFormatReferences();if(b.length>0){if(!l.has(v)){l.add(v);let e=v.ref;c.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:{references:b,fallback:y}})}}else y!==null&&(o.formatsConflating||=ei(r),o.formatsConflating.append(h,g,y))}u()})(e,t,f,!0);for(let n=0;n<t;n++){let t=e[n];t.state=t.state&~ZP|sF}for(let[e,t]of _)w.set(e,t);_.clear()},E=r,D=TB;D.length=0;let O=0,k=!1;do{++x,b(),this.doMarkAndPlan(e,x,S,D);let t=this.doEvaluate(e,f,this.scheduleRecalculation,T,E,D);k=t!==void 0,k&&(E=!1,++x,S.length=0,this.doCollectDirtyCalcs(e,x,t.all(),S,c,m,v),O>200&&(++x,b(),this.doMarkAndPlan(e,x,S,D,!0),this.doEvaluate(e,f,this.scheduleRecalculation,T,!1,D),this._hasCycle()||console.error(`Too many iterations, possible cycle or leak`),k=!1)),O++}while(k);if(C.size>0)if(function(e,t,n){for(let t of n)if(!e.has(t))return!1;for(let[n,r]of e){let e=t.get(n);if(!e||e.length!==r.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],i=n.value.index,a=!1;for(let t=0;t<e.length;t++){let r=e[t];if(r.value.index===i){a=r.scope===n.scope&&r.colStart===n.colStart&&r.rowStart===n.rowStart&&r.colEnd===n.colEnd&&r.rowEnd===n.rowEnd;break}}if(!a)return!1}}return!0}(C,h,y))m=p,g=h,C.clear();else{m===p&&(m=m.clone()),g===h&&(g=new Map(g));for(let e of C.keys()){let t=g.get(e);t&&m.removeAll(t,dL)}m.load(Array.from(C.values()).flat());for(let[e,t]of C)g.set(e,t);C.clear()}return this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,{precedentSpatial:m,dynamicByBlock:g,lastUpdates:w}}_onPassRead(e,t,n,r,i,a=!1){if(!this._passActive)return!1;let o=this._passCycleId,s=this._passMarkId;Lz.rowStart=t,Lz.colStart=n,Lz.rowEnd=r,Lz.colEnd=i,Lz.scope=e;let c=this._container.getFormulas().search(Lz),l=c.length,u=this._iterate!==null,d=this._container.getScope().node,f=d!==null&&(d.state&nF)!==0,p=0,m=null,h=!1,g=!1,_=e=>{if(e.cycleId!==o||e.markId!==s)return void(u||(e.state&$P)===0||(a?g=!0:this._demandActive?this._markDownstream(e):m=e));let t=e.state&ZP;if(t!==cF||h||(this._flush?.(),h=!0,t=e.state&ZP),t!==oF)t===aF||t===cF?nB[p++]=e:(e.state&QP)!==lF&&(a?g=!0:u&&this._demandActive?this._onMemberRead(e):u||this._demandActive?this._markDownstream(e):m=e);else if(a)g=!0;else{if(f||(e.state&=~nF),!u||!this._demandActive)throw new uz(e);(e.state&XP)===0&&(e.state|=XP,oB[this._iterHitsLength++]=e)}};for(let e=0;e<l;e++){let a=c[e],l=a.value,u=Math.max(a.rowStart,t),d=Math.min(a.rowEnd,r),f=Math.max(a.colStart,n),p=Math.min(a.colEnd,i),m=l.representative;if(m!==null&&m.cycleId===o&&m.markId===s&&l.isBlankAware(o)){let e=l.getTouchedCached(),t=e.touched;for(let e=0;e<t.length;e++){let n=t[e],r=Math.max(u,n.rowStart),i=Math.min(d,n.rowEnd);if(r>i)continue;let a=Math.max(f,n.colStart),o=Math.min(p,n.colEnd);a>o||l.forEachNodeIn(r,i,a,o,_)}bz(e.blank,a,u-a.rowStart,d-a.rowStart,f-a.colStart,p-a.colStart)&&_(m);continue}l.forEachNodeIn(u,d,f,p,_)}if(p>0)throw new lz(nB,p);if(m)throw new dz(m);return g}_markDownstream(e){let t=this._container.getScope().node;t&&(t.state&QP)===lF&&(t.state=t.state&~QP|dF,FP(t).cycleGroup=this._resolveGroup(Wz(e)),this._addCircular(t),this._iterate&&(lB[this._iterDownstreamLength++]=t))}_onMemberRead(e){let t=e.state;if((t&QP)===uF){if(this._openGroups.has(this._resolveGroup(e.ext.cycleGroup)))return void((t&XP)===0&&(e.state|=XP,oB[this._iterHitsLength++]=e))}else if(this._sweeping&&(t&tF)===0&&e.ext.demandValue!==void 0){let t=this._container.getScope().node;if(t&&((t.state&QP)===uF||(t.state&tF)!==0))return void this._sweepAlong(e,t)}this._markDownstream(e)}_sweepAlong(e,t){let n=e.ext,r=t.ext,i=this._resolveGroup(r.cycleGroup);(t.state&QP)===uF&&this._resolveGroup(n.cycleGroup)===i?(e.state=e.state&~QP|uF,n.cycleGroup=i,r.cycleNext===null&&(r.cycleNext=e)):e.state|=tF,this._addIterMember(e,n.demandValue)}_addIterMember(e,t){let n=this._iterMembersLength++;if(this._iterSorted){for(;n>0&&wz(sB[n-1],e)>0;)sB[n]=sB[n-1],cB[n]=cB[n-1],n--;n<=this._sweepIndex&&this._sweepIndex++}sB[n]=e,cB[n]=t}_sortIterMembers(){this._iterSorted=!0;let e=this._iterMembersLength;if(e<2)return;let t=Array(e);for(let n=0;n<e;n++)t[n]=n;t.sort((e,t)=>wz(sB[e],sB[t]));let n=Array(e),r=Array(e);for(let i=0;i<e;i++)n[i]=sB[t[i]],r[i]=cB[t[i]];for(let t=0;t<e;t++)sB[t]=n[t],cB[t]=r[t]}_resolveGroup(e){let t=this._groupAlias;if(t.size===0)return e;let n=t.get(e);for(;n!==void 0;)e=n,n=t.get(e);return e}_settleGroups(){if(this._groupAlias.size===0)return;let e=this._circularNodesLength;for(let t=0;t<e;t++){let e=rB[t];if((e.state&QP)===lF)continue;let n=e.ext;n.cycleGroup=this._resolveGroup(n.cycleGroup)}this._groupAlias.clear()}_collectUnevaluated(e,t,n){let r=this._passCycleId,i=this._passMarkId,a=this._container.getFormulas().search(e),o=a.length;for(let s=0;s<o;s++)a[s].value.forEachNodeIn(e.rowStart,e.rowEnd,e.colStart,e.colEnd,e=>{e.cycleId===r&&e.markId===i&&(e.state&ZP)===aF&&(t[n++]=e)});return n}doDemandEvaluate(e,t,n,r){if(n.length===0)return;let i=this._container.getScope();this._demandActive=!0,this._iterMembersLength=0,this._iterDownstreamLength=0,this._iterSorted=!1;try{this._demandRun(t,n,n.length),this._settleGroups(),this._iterate&&this._iterMembersLength>0&&this._demandSweep(t)}finally{this._demandActive=!1,this._sweeping=!1,this._sweepIndex=-1,this._openGroups.clear(),this._settleGroups(),this._iterHitsLength>0&&this._drainIterHits(),i.node=null,i.colIndex=2**53-1,i.rowIndex=2**53-1}}_pushDemand(e,t){let n=t?.isIRange?t.getValueAt(0,0)??0:t;this._overlayFor(e.gridId).pushDemand(e.rowIndex,e.colIndex,n)}_overlayFor(e){let t=this._overlays,n=t.get(e);if(n===void 0){let r=this._flush,i=this._container;n=new sz(i.getIncrementalUpdates(e).values,i.getGrid(e),()=>r?.()),t.set(e,n)}return n}_fitCell(e,t){return e.arrayFirstCell&&typeof t==`object`&&t&&!0===t.isIRange?t.getValueAt(0,0)??0:t}_finalizeRepresentative(e,n,r,i){let a=e.block,o=this._passCycleId,s=this._passMarkId;if(a.blankCycleId===o&&a.blankMarkId===s)return;let c=this._container.getScope().perCellRead;if(i||c||n&&(n.then||n.isIRange))return void this._fallbackBlank(a,c);let l=a.blankShared,u=a.blankValue;a.blankValue=n,a.blankCycleId=o,a.blankMarkId=s;let d=a.getTouchedCached().blank,f=e.gridId,p=r.values,m=r.errorSpatial,h=this._container.getGrid(f);if(h!==null&&h.getShadowOf()!==null){let e=zz;for(let t=0;t<d.length;t++){let n=d[t];p.delete(n),vI(m,n),e.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:f,value:null}),r.notifyBlank(n)}r.contentfulSpatial.insertAllNonOverlapping(e),e.length=0;return}let g=p.getAxis()===t.IRange.Axis.Column,_=g?t.IRange.Axis.Column:t.IRange.Axis.Row,v=zz,y=Bz;for(let e=0;e<d.length;e++){let t=d[e],r=g?t.colStart:t.rowStart,i=g?t.colEnd:t.rowEnd,a=g?t.rowStart:t.colStart,o=g?t.rowEnd-t.rowStart+1:t.colEnd-t.colStart+1,s=new ln([n],o),c=Array(i-r+1);for(let e=r;e<=i;e++)c[e-r]=[e,[[a,s]]];p.setValues(c),vI(m,t),hI(m,c,g);let l={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:f};v.push({...l,value:new NP(l,_)}),y.push(l)}r.contentfulSpatial.insertAllNonOverlapping(v),r.notifyValues.insertAllNonOverlapping(y),v.length=0,y.length=0,a.setBlankShared(d),this._dirtyBlankReaders(f,d,u===n?l:null)}_dirtyBlankReaders(e,t,n){if(n!==null&&QF(t,n))return;let r=this._container.getPrecedents(),i=Hz,a=Uz;a.scope=e;for(let e=0;e<t.length;e++)n===null?i.push(t[e]):$F(t[e],n,i);for(let t=0;t<i.length;t++){let n=i[t];a.colStart=n.colStart,a.rowStart=n.rowStart,a.colEnd=n.colEnd,a.rowEnd=n.rowEnd,r.search(a).length!==0&&(this._fallbackDirty??=new yr).insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:e})}i.length=0}_fallbackBlank(e,t){t?(e.blankRefused=!0,e.densify()):e.blankFallbackCycleId=this._passCycleId,e.setBlankShared(null);let n=e.getTouchedCached();if(n===null)return;let r=n.blank;if(r.length===0)return;let i=this._fallbackDirty??=new yr,a=e.gridId,o=Vz;for(let e=0;e<r.length;e++){let t=r[e];o.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:a})}i.insertAllNonOverlapping(o),o.length=0}_valueOnGrid(e){return this._overlayFor(e.gridId).getValueAt(e.rowIndex,e.colIndex)??(e.block.uncalculated?``:null)}_unstartPrefetched(e){e.state&=~(ZP|QP|YP),aB[this._deferredLength++]=e}_unwindSpeculative(e,t){for(;t>0;){let n=e[t-1];if((n.state&(ZP|nF))!==(oF|nF))break;this._unstartPrefetched(n),t--}return t}_demandRun(e,n,r){let i=this._container,a=this._context,o=i.getScope(),s=this._demandStats,c=eB,l=0,u=tB;this._deferredLength=0;for(let i=0;;i++){let d;if(i<r)d=n[i];else{if(!(this._deferredLength>0))break;d=aB[--this._deferredLength]}if((d.state&ZP)===aF)for(d.state&=~nF,c[l++]=d;l>0;){let n=c[l-1],r=n.state&ZP;if(r===sF){l--;continue}let i;r===aF&&(n.state=n.state&~(ZP|rF)|oF|YP,this._addCircular(n));let d=null,f=!1,p=n.ext;if((n.state&qP)!==0||p!==null&&p.pendingPromise&&(n.state&JP)!==0)i=n.cachedValue??null;else{UP(n,LP(n)),o.node=n,o.gridId=n.gridId,o.rowIndex=n.rowIndex,o.colIndex=n.colIndex,o.drawIndex=0,s.evaluations++,f=n.block.representative===n&&n.block.isBlankAware(this._passCycleId),f&&(o.perCellRead=!1),a._setReadHook(this._passHook);try{let e=n.block.formula;i=e.evaluateAt(n.rowIndex,n.colIndex),i&&i.then||(i=this._fitCell(n.block,e.finalizeValueForCell(i)))}catch(e){if(!(e instanceof lz||e instanceof uz||e instanceof dz))throw e;d=e}finally{a._setReadHook(null)}let e=this._iterHitsLength;if(e>0&&(n.state&nF)!==0){this._drainIterHits(),this._unstartPrefetched(n),l=this._unwindSpeculative(c,l-1);continue}if(e>0){for(let t=0;t<e;t++){let e=oB[t];if(e.state&=~XP,(e.state&ZP)===oF){this._markCycleSlice(c,l,e,null);continue}let n=this._openGroups.get(this._resolveGroup(e.ext.cycleGroup));n===void 0?this._markDownstream(e):this._markCycleSlice(c,l,c[n],e)}this._iterHitsLength=0}}if(d instanceof lz){if((n.state&nF)!==0){this._unstartPrefetched(n),l=this._unwindSpeculative(c,l-1);continue}s.retries++;let e=0,r=IP(n),i=r.length;for(let a=0;a<i;a++){let i=r[a];if(t.FormulaError.isError(i))continue;let o=i;o.scope?e=this._collectUnevaluated(o,u,e):(Lz.rowStart=o.rowStart,Lz.colStart=o.colStart,Lz.rowEnd=o.rowEnd,Lz.colEnd=o.colEnd,Lz.scope=n.gridId,e=this._collectUnevaluated(Lz,u,e))}for(let t=0;t<e;t++){let e=u[t];(e.state&(ZP|rF))===aF&&(e.state|=nF|rF,c[l++]=e)}let a=d.nodes,o=d.count;for(let e=0;e<o;e++){let t=a[e];(t.state&ZP)===aF&&(t.state=t.state&~nF|rF,c[l++]=t)}continue}if(d instanceof uz){if((n.state&nF)!==0){this._unstartPrefetched(n),l=this._unwindSpeculative(c,l-1);continue}let e=this._markCycleSlice(c,l,d.node,null);for(let t=e;t<l;t++){let e=c[t];if((e.state&ZP)!==oF)continue;if((e.state&nF)!==0){this._unstartPrefetched(e);continue}e.state=e.state&~(ZP|nF)|sF;let n=Gz(e);FP(e).demandValue=n,this._pushDemand(e,n);let r=e.block;r.representative===e&&r.isBlankAware(this._passCycleId)&&this._fallbackBlank(r,!1)}l=e;continue}if(d instanceof dz){n.state=n.state&~(ZP|QP|nF)|sF|dF;let e=Gz(n),t=FP(n);t.cycleGroup=Wz(d.node),t.demandValue=e,this._pushDemand(n,e),f&&this._fallbackBlank(n.block,!1),l--;continue}if(this._iterate||(n.state&QP)!==dF)FP(n).demandValue=i,i&&i.then||this._pushDemand(n,i),f&&this._finalizeRepresentative(n,i,e(n.gridId),!1);else{let e=Gz(n);FP(n).demandValue=e,this._pushDemand(n,e),f&&this._fallbackBlank(n.block,!1)}if(n.state=n.state&~(ZP|nF)|sF,l--,this._openGroups.size>0&&(n.state&QP)===uF){let e=this._resolveGroup(n.ext.cycleGroup);this._openGroups.get(e)===l&&this._openGroups.delete(e)}}}}_markCycleSlice(e,t,n,r){let i=t-1;for(;i>=0&&e[i]!==n;)i--;i<0&&(i=t-1);let a=0;for(let n=i;n<t&&a===0;n++){let t=e[n];(t.state&nF)===0&&(t.state&(ZP|QP))===(oF|uF)&&(a=this._resolveGroup(t.ext.cycleGroup))}a===0&&(a=++this._cycleGroupNext);let o=this._iterate!==null,s=i;if(o){let e=this._openGroups.get(a);e!==void 0&&e<s&&(s=e)}let c=null,l=null;for(let n=i;n<t;n++){let t=e[n],r=t.state;if((r&ZP)!==oF||(r&nF)!==0)continue;o&&(r&QP)!==uF&&this._addIterMember(t,this._valueOnGrid(t)),t.state=r&~QP|uF;let i=FP(t);if(o&&(r&QP)===uF){let e=this._resolveGroup(i.cycleGroup);if(e!==a){let t=this._openGroups.get(e);t!==void 0&&(t<s&&(s=t),this._openGroups.delete(e)),this._groupAlias.set(e,a)}}i.cycleGroup=a,l?FP(l).cycleNext=t:c=t,l=t}return l&&(FP(l).cycleNext=r??c),o&&this._openGroups.set(a,s),i}_demandSweep(e){let t=this._iterate,n=sB,r=t.maxIteration,i=t.maxChange;this._sortIterMembers();for(let e=0;e<this._iterMembersLength;e++){let t=n[e],r=t.ext;if(r.demandValue&&r.demandValue.then)continue;let i=cB[e];r.demandValue=i,this._pushDemand(t,i)}let a=0,o=!1,s=0,c=!1;for(this._sweeping=!0,this._sweepIndex=0;this._sweepIndex<this._iterMembersLength;){let t=n[this._sweepIndex],r=t.ext;if(r.demandValue===null){let n=this._demandEvaluateOne(e,t);r.demandValue=n,n&&n.then?c=!0:this._pushDemand(t,n)}this._sweepIndex++}this._sweepIndex=-1;let l=new Map,u=new Map,d=new Map;for(;a<r&&!c;){let t=0;l.clear();let r=this._iterMembersLength;for(this._sweepIndex=0;this._sweepIndex<this._iterMembersLength;){let r=n[this._sweepIndex],i=r.ext,a=i.demandValue,o=this._demandEvaluateOne(e,r);if(i.demandValue=o,o&&o.then){c=!0;break}this._pushDemand(r,o);let s=CB(a,o);if(s>t&&(t=s),(r.state&QP)===uF){let e=i.cycleGroup,t=l.get(e);(t===void 0||s>t)&&l.set(e,s)}this._sweepIndex++}this._sweepIndex=-1;let f=this._iterMembersLength!==r;a++,s=t;let p=d;if(d=u,u=l,l=p,!c&&!f&&t<i){o=!0;break}}this._sweeping=!1;let f=lB,p=this._iterDownstreamLength;for(let e=0;e<p;e++){let t=f[e];(t.state&ZP)===sF&&(t.state&QP)===dF&&(t.state=t.state&~ZP|aF)}this._demandRun(e,f,p),this._settleGroups();let m=new Map,h=this._container.getVolatiles(),g=this._iterMembersLength;for(let e=0;e<g;e++){let t=n[e];if((t.state&QP)!==uF)continue;let r=t.ext.cycleGroup,i=m.get(r);i===void 0&&(i={converged:o,iterationCount:a,lastChange:u.get(r)??s,previousChange:d.get(r)??NaN},m.set(r,i),this._cycleOf(r).setIteration(i)),h?.add(t)}}_drainIterHits(){let e=this._iterHitsLength;for(let t=0;t<e;t++)oB[t].state&=~XP;this._iterHitsLength=0}_demandEvaluateOne(e,t){let n=this._context,r=this._container.getScope(),i=t.block.formula,a=LP(t);for(;;){UP(t,a),r.node=t,r.gridId=t.gridId,r.rowIndex=t.rowIndex,r.colIndex=t.colIndex,r.drawIndex=0,this._demandStats.evaluations++;let o,s=null;n._setReadHook(this._passHook);try{o=i.evaluateAt(t.rowIndex,t.colIndex),o&&o.then||(o=this._fitCell(t.block,i.finalizeValueForCell(o)))}catch(e){if(!(e instanceof lz))throw e;s=e}finally{n._setReadHook(null)}if(this._iterHitsLength>0&&this._drainIterHits(),!s)return o;this._demandStats.retries++;let c=s.nodes,l=s.count;for(let e=0;e<l;e++)iB[e]=c[e];this._demandRun(e,iB,l)}}getCycleCells(){let e=[];for(let t of this._cycles.values())for(let n of[t.members,t.downstream])for(let t of n)t.gridId&&this.isLiveNode(t)&&e.push({rowStart:t.rowIndex,rowEnd:t.rowIndex,colStart:t.colIndex,colEnd:t.colIndex,scope:t.gridId});return e}_hasCycle(){let e=rB,t=this._circularNodesLength;for(let n=0;n<t;n++)if((e[n].state&QP)===uF)return!0;return!1}_addCircular(e){(e.state&eF)===0&&(e.state|=eF,rB[this._circularNodesLength++]=e)}_resetCircular(){let e=this._circularNodesLength;for(let t=0;t<e;t++)rB[t].state&=~eF;this._circularNodesLength=0}_trackCircular(e,t,n,r,i){let a=FP(e),o=e.state&QP,s=o===lF?0:a.cycleGroup;if(a.shownGroup===s&&(e.state&$P)===o<<2)return;if(this._cycleEpoch++,a.shownGroup!==0){let t=this._cycles.get(a.shownGroup);t&&(t.members.delete(e),t.downstream.delete(e),t.isEmpty()&&this._cycles.delete(a.shownGroup))}let c=!1;if(s!==0){let t=this._cycleOf(s),n=o===uF;(n?t.members:t.downstream).add(e),c=t.getEntry(n)}a.shownGroup=s,e.state=e.state&~$P|o<<2,t.circularConflating||=ei(i),t.circularConflating.append(n,r,c)}_cycleOf(e){let t=this._cycles.get(e);return t||(t=new gz(this._cycleHost,e),this._cycles.set(e,t)),t}isLiveNode(e){let t=e.gridId;if(!t)return!1;let n=e.rowIndex,r=e.colIndex,i=this._container.getFormulas().search({colStart:r,colEnd:r,rowStart:n,rowEnd:n,scope:t});for(let t=0;t<i.length;t++)if(i[t].value.nodeAtOrNull(n,r)===e)return!0;return!1}getCircularNodes(){return rB.slice(0,this._circularNodesLength)}getDemandStats(){return{...this._demandStats,...this._planStats}}resetStats(){let e=this._demandStats;for(let t in e)e[t]=0;let t=this._planStats;for(let e in t)t[e]=0}doMarkAndPlan(e,n,r,i,a=!1){let o=r.values,s=r.length,c=i.values,l=0;this._passCycleId=e,this._passMarkId=n;let u=this._container,d=u.getPrecedents(),f=u.getFormulas(),p=this.planCacheMode,{staticEpoch:m,precedentEpoch:h}=u.getCalcEpochs(),g=this._lastPlanId,_=this._planStats;_.passes++;let v=Ez(),y=p!==`off`&&!a&&g!==0,b=y?this._matchPlanMemo(s,e,n-1,h):null;if(b!==null&&_.closureEligible++,zP=0,b!==null&&p===`on`){let t=b.plan,r=b.planLength,a=b.demandStart;for(let i=0;i<r;i++){let r=t[i];r.markId=n,r.cycleId=e,r.inDegree=0,r.state&=~iF,r.ext!==null&&(r.ext.cycleGroup=0),VP(r,LP(r)),c[i]=r}return i.length=r,a<r&&this._flagDemandAppendix(c,a,r),_.closureHits++,_.discoveryMs+=Ez()-v,a===r}let x=0,S=0,C=0,w=0,T=0,E=0,D=0,O=0;for(let t=0;t<s;t++){let r=o[t];if(r.cycleId===e&&r.markId===n)continue;r.markId=n,r.cycleId=e,r.inDegree=0,r.state&=~iF;let i=r.ext;i!==null&&(i.cycleGroup=0),(r.planEpoch!==m||r.planId!==g||i!==null&&i.shownGroup!==0)&&(y=!1),VP(r,LP(r)),Yz[x++]=r,Zz[O++]=r}let k=t=>{if(t.cycleId===e&&t.markId===n)return;t.markId=n,t.cycleId=e,t.inDegree=0,t.state&=~iF;let r=t.ext;r!==null&&(r.cycleGroup=0),(t.planEpoch!==m||t.planId!==g||r!==null&&r.shownGroup!==0)&&(y=!1),VP(t,LP(t)),Yz[x++]=t,Zz[O++]=t},A=(t,r,i,a,o,s)=>{let c=t.ref;r<=c.rowStart&&i>=c.rowEnd&&a<=c.colStart&&o>=c.colEnd&&t.isBlankAware(e)?t.forEachTouchedNode(e,n,s):t.mintNodesIn(r,i,a,o,s)};for(;D<O;){let e=Zz[D++],t=e.colIndex,n=e.rowIndex,r=e.gridId,i,a=p!==`off`&&e.dependentsEpoch===h;a&&p===`on`?(_.dependentsCacheHits++,i=e.dependents):(Pz.colStart=t,Pz.rowStart=n,Pz.colEnd=t,Pz.rowEnd=n,Pz.scope=r,i=d.search(Pz),a?(_.dependentsCacheHits++,jz(e.dependents,i)||(_.dependentsAssertFailures++,console.error(`CalcExecutor: stale dependents cache at`,r,n,t))):(_.dependentsCacheMisses++,p!==`off`&&(e.dependentsEpoch=h))),e.dependents=i;let o=e.ext;if(o!==null&&(o.spillDependents=dB,o.spillRowEnd=-1,o.spillColEnd=-1),mB(e)){let i=fB,a=pB;Fz.colStart=t,Fz.rowStart=n,Fz.colEnd=a,Fz.rowEnd=i,Fz.scope=r;let o=d.search(Fz),s=o.length;if(s>0){let r=FP(e);r.spillDependents=o,r.spillRowEnd=i,r.spillColEnd=a,Xz[S++]=e;for(let e=0;e<s;e++)hz(o[e],n,t,i,a,k,A)}}let s=i.length;if(s!==0)for(let e=0;e<s;e++)mz(i[e],n,t,k,A)}let j=Ez();if(_.discoveryMs+=j-v,y&&_.fastEligible++,b!==null){let t=b.plan,r=b.planLength===x;for(let i=0;r&&i<x;i++){let a=t[i];r=a.cycleId===e&&a.markId===n}r||(_.closureAssertFailures++,console.error(`CalcExecutor: whole-closure reuse would have planned a different affected set`))}if(y&&p===`on`){(function(e,t,n,r){if(8*t<r){let r=kz;for(let n=0;n<t;n++)r[n]=e[n];r.length=t,r.sort(Dz);for(let e=0;e<t;e++)n[e]=r[e];return}if(Oz.length<r){let e=[];for(let t=0;t<r;t++)e.push(null);Oz=e}let i=Oz,a=r,o=-1;for(let n=0;n<t;n++){let t=e[n],r=t.orderIndex;i[r]=t,r<a&&(a=r),r>o&&(o=r)}let s=0;for(let e=a;e<=o;e++){let t=i[e];t!==null&&(i[e]=null,n[s++]=t)}})(Yz,x,c,this._lastStampedLength),i.length=x;let e=x,t=this._lastStampedOrderedLength;for(;e>0&&c[e-1].orderIndex>=t;)e--;return e<x&&this._flagDemandAppendix(c,e,x),this._rememberPlan(o,s,c,x,h,e),_.fastHits++,_.kahnMs+=Ez()-j,e===x}let M=null,N=null,P=t=>{t.cycleId===e&&t.markId===n?(gB++,y&&t.orderIndex>=hB.orderIndex&&(_.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would invert a static edge at`,hB.gridId,hB.rowIndex,hB.colIndex),y=!1)):this._iterate||(t.state&$P)===0||(this._taintGroup=t.ext.shownGroup,this._taintDownstream(hB))};for(let e=0;e<x;e++){let n=Yz[e],r=IP(n),i=r.length,a=0;for(let e=0;e<i;e++){let i=r[e];if(t.FormulaError.isError(i))continue;let o=i.colStart,s=i.rowStart,c=i.colEnd,l=i.rowEnd,u=i.scope??n.gridId,d;if(M!==null&&N===u&&o>=M.colStart&&c<=M.colEnd&&s>=M.rowStart&&l<=M.rowEnd)uB[0]=M,d=uB,T++;else if(Iz.colStart=o,Iz.rowStart=s,Iz.colEnd=c,Iz.rowEnd=l,Iz.scope=u,d=f.search(Iz),E++,d.length===1){let e=d[0];e.colEnd>e.colStart||e.rowEnd>e.rowStart?(M=e,N=u):M=null}else M=null;let p=d.length;for(let e=0;e<p;e++){let t=d[e],r=t.colStart,i=t.rowStart,u=t.colEnd,f=t.rowEnd,p=Math.max(r,o),m=Math.max(i,s),h=Math.min(u,c),g=Math.min(f,l);hB=n,gB=a,t.value.forEachNodeIn(m,g,p,h,P),a=gB}}n.inDegree=a,S===0&&n.inDegree===0&&(Qz[w++]=n)}if(S>0){let t=Xz[0],r=r=>{r.cycleId===e&&r.markId===n&&(r.inDegree++,y&&t.orderIndex>=r.orderIndex&&(_.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would invert a spill body edge at`,r.gridId,r.rowIndex,r.colIndex),y=!1))};for(let e=0;e<S;e++){let n=Xz[e];t=n;let i=n.ext,a=i.spillDependents,o=a.length;for(let e=0;e<o;e++)hz(a[e],n.rowIndex,n.colIndex,i.spillRowEnd,i.spillColEnd,r)}for(let e=0;e<x;e++){let t=Yz[e];t.inDegree===0&&(Qz[w++]=t)}}_.formulaCacheHits+=T,_.formulaCacheMisses+=E;let F=Ez();_.inDegreeMs+=F-j;let I=t=>{t.cycleId===e&&t.markId===n&&(t.inDegree--,t.inDegree===0&&(Qz[w++]=t))};for(;C<w;){let e=Qz[C++];c[l++]=e;let t=e.colIndex,n=e.rowIndex,r=e.ext;if(r!==null){let e=r.spillDependents,i=e.length;for(let a=0;a<i;a++)hz(e[a],n,t,r.spillRowEnd,r.spillColEnd,I)}let i;i=e.dependents;let a=i.length;if(a!==0)for(let e=0;e<a;e++)mz(i[e],n,t,I)}if(_.kahnMs+=Ez()-F,a||l<x){if(y){let e=this._lastStampedOrderedLength;for(let t=0;t<x;t++){let n=Yz[t];if(n.inDegree>0&&n.orderIndex<e){_.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would have missed an unorderable subset`);break}}}let e=this._demandBatch;e.length=0,a&&(l=0);for(let t=0;t<x;t++){let n=Yz[t];(a||n.inDegree>0)&&(n.state|=YP,FP(n).demandValue=void 0,e.push(n))}e.sort(Tz);let t=e.length,n=l;for(let n=0;n<t;n++){let t=e[n];c[l++]=t,this._addCircular(t)}if(i.length=l,a)this._planMemos[0].epoch=-1,this._planMemos[1].epoch=-1;else if(p!==`off`){if(!y){let e=++this._planIdNext;this._lastPlanId=e;for(let t=0;t<l;t++){let n=c[t];n.orderIndex=t,n.planId=e,n.planEpoch=m}this._lastStampedLength=l,this._lastStampedOrderedLength=n,_.stampedPlans++}this._rememberPlan(o,s,c,l,h,n)}return!1}if(i.length=l,p!==`off`&&!y){let e=++this._planIdNext;this._lastPlanId=e;for(let t=0;t<l;t++){let n=c[t];n.orderIndex=t,n.planId=e,n.planEpoch=m}this._lastStampedLength=l,this._lastStampedOrderedLength=l,_.stampedPlans++}return p!==`off`&&this._rememberPlan(o,s,c,l,h),!0}_flagDemandAppendix(e,t,n){let r=this._demandBatch;r.length=0;for(let i=t;i<n;i++){let t=e[i];t.state|=YP,FP(t).demandValue=void 0,r.push(t),this._addCircular(t)}}_invalidatePlans(){this._lastPlanId=0,this._planMemos[0].epoch=-1,this._planMemos[1].epoch=-1}_matchPlanMemo(e,t,n,r){let i=this._planMemos,a=this._cycleEpoch;for(let o=0;o<2;o++){let s=i[o];if(s.epoch===r&&s.seedsLength===e&&s.cycleFree&&s.cycleEpoch===a&&Az(s.seeds,s.seedsLength,e,t,n))return s.used=++this._planMemoClock,s}return null}_rememberPlan(e,t,n,r,i,a=r){let o=this._planMemos,s=o[0],c=o[1],l=s.epoch===i?c.epoch===i&&s.used<=c.used?s:c:s;l.used=++this._planMemoClock;let u=l.seeds;for(let n=0;n<t;n++)u[n]=e[n];u.length=t,l.seedsLength=t;let d=l.plan,f=!0;for(let e=0;e<r;e++){let t=n[e];d[e]=t;let r=t.ext;r!==null&&r.shownGroup!==0&&(f=!1)}d.length=r,l.planLength=r,l.epoch=i,l.cycleFree=f,l.cycleEpoch=this._cycleEpoch,l.demandStart=a}doEvaluate(e,r,i,a,o,s){let c=Ez(),l=this._container,u=this._context,d=l.getScope(),f=u.getRuntime(),p=s.values,m=s.length;yB=this._passCycleId,bB=this._passMarkId;let h=Jz,g,_,v,y,b,x,S,C,w,T,E,D,O,k=0,A=new Map;this._overlays=A;let j=e=>this._overlayFor(e),M=e=>{E=l.getGrid(e),T=E.getEntireCoords.bind(E),_=r(e),v=_.gridId,O=j(e),y=_.values,D=_.errorSpatial,b=_.contentfulSpatial,x=_.spillSpatial,S=_.notifyValues,C=_.notifySpillsInsert,w=_.notifySpillsRemove,_.notifyFormats,_.notifyPending,d.gridId=v},N=t.IRange.Axis.Column,P=N===t.IRange.Axis.Column,F=()=>{if(k>0){a(h,k),k=0;for(let e of A.values())e.reset();v!==void 0&&(_=r(v))}};this._flush=F;let I=0;for(;I<m;)try{for(;I<m;I++){let a=p[I],s=a.colIndex,c=a.rowIndex;if((a.state&GP)!==0&&e===a.cycleId){a.state&=~GP;continue}let u=a.gridId;u!==v&&M(u);let m=a.block,A=m.representative===a&&m.isBlankAware(e),L,R,ee=a.cachedValue;ee?.isIRange&&(L=ee);let te,ne=!1;t.FormulaError.isError(ee,t.FormulaError.Code.Spill)&&(R=ee,ne=!0),o&&(ee=void 0),!te&&ee&&t.FormulaError.isError(ee)&&(te=ee);let re=(a.state&qP)!==0,ie=(a.state&YP)!==0;ie&&(a.state&ZP)!==sF&&(F(),this.doDemandEvaluate(e,r,this._demandBatch,F),d.gridId=u);let ae=ie?null:IP(a),oe=a.inputsAt;if(ae&&oe>=0){let e=BP(),n=ae.length;for(let r=0;r<n;r++){let n=ae[r];if(t.FormulaError.isError(n)){e[oe+r]=n;continue}let i=n.colStart,a=n.rowStart,o=n.colEnd,s=n.rowEnd;if(s!==a||i!==o){let t=n.scope,c=y,u=T,d=O,p=E;t&&t!==v&&(p=l.getGrid(t),p&&(c=p.getValues(),d=j(t),u=p.getEntireCoords.bind(p)));let m=p;d.intersects(a,i,s,o)&&(c=d,m=d);let h=new OW(f,c,{...n},null,u,l.resolveScope);h._setErrorIndex(m),e[oe+r]=h}}}let se=P?s:c,ce=P?c:s;d.node=a,d.colIndex=s,d.rowIndex=c,d.drawIndex=0;let le=m.formula,ue,de=null,fe=(a.state&KP)!==0,pe=fe,me=a.ext;if(ie&&!this._iterate&&(a.state&QP)!==lF)me!==null&&(me.demandValue=void 0),ue=Gz(a),pe=!1,me!==null&&me.pendingPromise&&(me.pendingPromise.cancelled=!0,me.pendingPromise=null,a.state&=~JP);else if((re||me!==null&&me.pendingPromise)&&(pe=!0,ue=a.cachedValue??null,me!==null&&me.pendingPromise&&((a.state&JP)===0?(me.pendingPromise.cancelled=!0,ue=void 0):(me.pendingPromise=null,a.state&=~JP,pe=!1))),ue===void 0){if(d.colIndex=s,d.rowIndex=c,d.drawIndex=0,ie){let e=me===null?void 0:me.demandValue;me!==null&&(me.demandValue=void 0),ue=e===void 0?0:e,de=ue&&ue.then?ue:null}else a.state=a.state&~ZP|oF,A&&(d.perCellRead=!1),this._planStats.evaluated++,ue=le.evaluateAt(c,s),de=ue&&ue.then?ue:null,de||(ue=le.finalizeValueForCell(ue));pe=!!de}else me!==null&&(me.demandValue=void 0);if((a.state&ZP)!==sF&&(a.state=a.state&~ZP|cF),pe!==fe&&(pe?a.state|=KP:a.state&=~KP,_.pendingConflating||=ei(P),_.pendingConflating.append(se,ce,pe)),de&&(ue=a.cachedValue??null,!de.__originator)){de.__originator=e;let n=a;this._pendingPromises.add(n),FP(n).pendingPromise=de,n.state&=~JP,de.then(t=>{if(this._pendingPromises.delete(n),de.cancelled)return;FP(n).pendingPromise=de,n.state|=JP;let r=le.finalizeValueForCell(t);r===null&&(r=0),n.cachedValue=r,i(e,n)},r=>{this._pendingPromises.delete(n),FP(n).pendingPromise=null,n.state&=~JP,n.cachedValue=t.FormulaError.BuiltIn.Calc,this.scheduleRecalculation(e,n)})}let he;ie&&O.takeDemand(c,s);let ge=a.ext,_e=ge===null?null:ge.fixedRef;if(L||R||_e){Kz.colStart=s,Kz.rowStart=c,Kz.colEnd=s,Kz.rowEnd=c;let e=x.search(Kz);for(let t=0;!he&&t<e.length;t++){let n=e[t];n.colStart===s&&n.rowStart===c&&(he=n)}if(he&&(x.remove(he,dL),!he||!he.value.getError())){let e={...he,value:null};b.insertNonOverlapping(e),y.delete(e),vI(D,e)}}ue=this._fitCell(m,ue);let ve=1,ye=1,be=ue,xe=be?.isIRange,Se,Ce=t.FormulaError.isError(ue,t.FormulaError.Code.Spill);if(_e){ve=_e.colEnd-_e.colStart+1,ye=_e.rowEnd-_e.rowStart+1;let t={colStart:_e.colStart,rowStart:_e.rowStart,colEnd:_e.colEnd,rowEnd:_e.rowEnd,scope:u},n=pz(ue,t,P)?.tuples;y.delete(t),n&&y.setValues(n),vI(D,t),hI(D,n,P),Se={...t,value:new MP(t,e,`fixed`)},x.insert(Se),l.addDynamicPrecedent(a,t,fI.Spill),b.insertNonOverlapping({...t,value:new NP(t,N)})}else if(xe&&be.size>1){ve=be.getColumnCount(),ye=be.getRowCount();let r={colStart:s,rowStart:c,colEnd:s+ve-1,rowEnd:c+ye-1,scope:u},i=T(),o=!n.CoordUtils.isRangeWithinRange(r,i);if(o&&(r.colEnd=Math.min(r.colEnd,i.colEnd),r.rowEnd=Math.min(r.rowEnd,i.rowEnd)),Ce=o,!Ce){let e=b.search(r);if(Ce=e.length>1,!Ce&&e.length===1){let t=e[0],i=n.CoordUtils.intersectRanges(r,t,Mz);!i||i.rowEnd===i.rowStart&&i.colStart===i.colEnd&&i.colStart===s&&i.rowStart===c||(Ce=!0)}}let d,f;if(Ce)ue=t.FormulaError.BuiltIn.Spill,ve=1,ye=1,d=[[se,[[ce,[ue]]]]],y.setValues(d),hI(D,d,P),f={colStart:s,rowStart:c,colEnd:s,rowEnd:c};else{let e=fz(be,se,ce);e&&(d=e.tuples),d&&y.setValues(d),vI(D,r),hI(D,d,P),f=r}let p=Ce?{colStart:s,rowStart:c,colEnd:s,rowEnd:c,scope:u}:r;Se={...p,value:new MP(p,e,Ce?`error`:`dynamic`)},x.insert(Se),l.addDynamicPrecedent(a,r,fI.Spill),b.insertNonOverlapping({...f,value:new NP(f,N)})}!A||m.blankCycleId===e&&m.blankMarkId===this._passMarkId||this._finalizeRepresentative(a,ue,_,de!==null||pe||ie||!0===xe||Ce||_e!==null);let we=!1;if((he||Se||Ce||R)&&(we=n.CoordUtils.isEqualRanges(he,Se),he&&w.push(he),Se&&C.push(Se)),Se||he){let e=1,t=1;he&&(e=he.colEnd-he.colStart+1,t=he.rowEnd-he.rowStart+1);let n={colStart:s,rowStart:c,colEnd:s+Math.max(ve,e)-1,rowEnd:c+Math.max(ye,t)-1,scope:u};S.insertNonOverlapping(n),we&&Ce===ne||(this._invalidatePlans(),l.getPrecedents().search(n).length>0&&(a.state|=GP,g||=new yr,g.insertNonOverlapping(n)))}ue&&t.FormulaError.isError(ue),le.getError()&&le.getError(),a.cachedValue=ue,h[k++]=a,xe||_e||O.push(c,s,ue),k>=Sz&&F(),((a.state&QP)!==lF||a.ext!==null&&a.ext.shownGroup!==0)&&this._trackCircular(a,_,se,ce,P);let Te=a.dependents,Ee=Te.length;if(Ee>0){let e=(a.state&KP)!==0,t=!this._iterate&&(a.state&QP)!==lF;t&&(this._taintGroup=a.ext.cycleGroup);for(let n=0;n<Ee;n++){let r=Te[n];t&&mz(r,c,s,this._taintDownstream);let i=r.value.index;i<0||(e?mz(r,c,s,SB):(_B=i,vB=ue,mz(r,c,s,xB)))}}}}catch(t){let n=p[I];if(t instanceof lz||t instanceof uz&&this._iterate){let i=Rz;if(i.length=0,t instanceof lz)for(let e=0;e<t.count;e++)i.push(t.nodes[e]);i.push(n),F(),n.state&=~ZP,this.doDemandEvaluate(e,r,i,F)}else{if(!(t instanceof uz||t instanceof dz))throw t;{let e=t instanceof uz;n.state=n.state&~(ZP|QP)|YP|sF|(e?uF:dF);let r=FP(n);r.demandValue=Gz(n),r.cycleGroup=e?++this._cycleGroupNext:Wz(t.node),e&&(r.cycleNext=n),this._addCircular(n)}}d.gridId=n.gridId}d.node=null,d.colIndex=2**53-1,d.rowIndex=2**53-1,F();for(let e of A.values())e.commitDemand();this._flush=null,this._overlays=null;let L=this._fallbackDirty;return L!==null&&(this._fallbackDirty=null,g?g.insertAllNonOverlapping(L.all()):g=L),(()=>{let e=RP,t=zP;for(let n=0;n<t;n++)e[n]=void 0;zP=0})(),this._planStats.evaluateMs+=Ez()-c,g}},yz=(e,t)=>new Rt.ArrayList(e.slice(0,t));function bz(e,t,n,r,i,a){let o=t.rowStart+n,s=t.rowStart+r,c=t.colStart+i,l=t.colStart+a;for(let t=0;t<e.length;t++){let n=e[t];if(n.rowStart<=s&&n.rowEnd>=o&&n.colStart<=l&&n.colEnd>=c)return!0}return!1}var xz=Symbol(`unsetGridId`),Sz=1024;function Cz(e,t){return e.scope===t.scope?e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex:e.scope===null?-1:t.scope===null?1:e.scope.localeCompare(t.scope)}function wz(e,t){return e.gridId===t.gridId?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.gridId===null?-1:t.gridId===null?1:e.gridId<t.gridId?-1:1}function Tz(e,t){return e.scope===t.scope?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.scope===null?-1:t.scope===null?1:e.scope.localeCompare(t.scope)}var Ez=()=>globalThis.performance?.now()??Date.now(),Dz=(e,t)=>e.orderIndex-t.orderIndex,Oz=[],kz=[];function Az(e,t,n,r,i){if(t!==n)return!1;for(let n=0;n<t;n++){let t=e[n];if(t.cycleId!==r||t.markId!==i)return!1}return!0}function jz(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;let n=!0;for(let r=0;r<e.length&&n;r++)n=e[r].value===t[r].value;if(n)return!0;let r=new Set;for(let t=0;t<e.length;t++)r.add(e[t].value);for(let e=0;e<t.length;e++)if(!r.has(t[e].value))return!1;return!0}var Mz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Nz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Pz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Fz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Iz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Lz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Rz=[null],zz=[],Bz=[],Vz=[],Hz=[],Uz={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Wz=e=>{let t=e.ext;return t===null?0:(e.state&QP)===lF?t.shownGroup:t.cycleGroup},Gz=e=>e.cachedValue??0,Kz={rowStart:0,colStart:0,rowEnd:0,colEnd:0},qz=1e4,Jz=rU(qz),Yz=rU(qz),Xz=rU(qz),Zz=rU(qz),Qz=rU(qz),$z=rU(qz),eB=rU(qz),tB=rU(qz),nB=rU(qz),rB=rU(qz),iB=rU(qz),aB=rU(qz),oB=rU(qz),sB=rU(qz),cB=rU(qz),lB=rU(qz),uB=[null],dB=[],fB=-1,pB=-1;function mB(e){let t=e.ext,n=t===null?null:t.fixedRef;if(n!==null)return fB=n.rowEnd,pB=n.colEnd,n.rowEnd>e.rowIndex||n.colEnd>e.colIndex;let r=e.cachedValue;return!!r?.isIRange&&(fB=e.rowIndex+r.getRowCount()-1,pB=e.colIndex+r.getColumnCount()-1,fB>e.rowIndex||pB>e.colIndex)}var hB=null,gB=0,_B=-1,vB=void 0,yB=0,bB=0,xB=e=>{e.cycleId===yB&&e.markId===bB&&((e,t,n)=>{let r=e.inputsAt;r<0||(RP[r+t]=n)})(e,_B,vB)},SB=e=>{e.state|=qP};function CB(e,t){let n=e??0,r=t??0;if(typeof n==`number`&&typeof r==`number`){let e=Math.abs(r-n);return e==e?e:1/0}return n===r?0:1/0}var wB={values:rU(qz),length:0},TB={values:rU(qz),length:0},EB=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),DB=class extends S{constructor(e){super(e?.transactions),this._pendingJSON=null,this._wiringDirty=!1,this._wiringBatchDepth=0,this._namesEmitter=null,this._hydrating=!1,this._container=e?.container??null,this._bindSheet=e?.bindSheet??null,this._context=e?.context??null,this._ready=e?.ready??null,this._getActiveCell=e?.getActiveCell??(()=>null),this._createHost=e?.createHost??null,this._getRange=e?.getRange,this._getRanges=e?.getRanges,this._createGraphRanges=e?.createGraphRanges,this._resolveSheetScope=e?.resolveSheetScope??null,this._isReadOnly=e?.isReadOnly??null,this._getOrBindProxyFakeId=e?.getOrBindProxyFakeId??null,this._queuePendingAction=e?.queuePendingAction??null,this._isEngineReady=e?.isEngineReady??null;let t=this;this._transactions=e?.transactions??new g({transient:!0}),this._stateId=this._transactions.create(),this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onAfterStateChange(e){t._notifyCollectionChange()}}),this._initState()}hydrate(e){if(this._pendingJSON=null,!e)return;let t=e.length;this._hydrating=!0;try{for(let r=0;r<t;r++){let t=e[r];try{this.add({name:t.name,expression:t.ref,scope:t.scope??null,comment:t.comment,hidden:t.hidden})}catch(e){n.Notifier.warn(`Unable to load named item '${t?.name}'.`,{meta:e?.message})}}}finally{this._hydrating=!1}}setPendingJSON(e){this._pendingJSON=e??null}toJSON(){let e=this._getState();if(!e||e.itemsById.size===0){let e=this._pendingJSON;return e&&e.length>0?e.map(e=>({...e})):null}let t=Array.from(e.itemsById.values());t.sort((e,t)=>{let n=AB(e.getScope()).localeCompare(AB(t.getScope()));return n===0?AB(e.getName()).localeCompare(AB(t.getName())):n});let n=[],r=t.length;for(let e=0;e<r;e++){let r=t[e].toJSON();r&&n.push(r)}return n.length>0?n:null}add(e){if(this.isClosed())throw Error((0,n.t)(`error.model.modelClosed`));if(!this._hydrating&&this._isReadOnly?.())throw Error((0,n.t)(`error.named.nameReadonly`));if(!e?.name)throw Error(`name is required`);if(!e?.expression)throw Error(`expression is required`);let t=null;if(e.cell&&this._getRange){let r=this._getRange(e.cell)?.getCoords()??null;r&&n.CoordUtils.isSingleCell(r)&&(t={colIndex:r.colStart,rowIndex:r.rowStart})}t||=this._getActiveCell?.()??n.CoordUtils.EmptyCell;let r=t.scope??this._getActiveCell?.()?.scope??null,i=this._resolveScopeInput(e.scope??null),a=this._findSameIdentity(e.name,i);if(a){if(!e.replaceExisting)throw Error((0,n.t)(`error.named.nameExists`,{name:e.name}));a.delete()}let o=this._getOrBindProxyFakeId?.(e.name,this._resolveScopeName(i))??null,s=o&&this._createHost?this._createHost(o):null,c=this._container&&this._context&&this._ready?{container:this._container,context:this._context,ready:this._ready,host:s,getScopeGridId:()=>r||(i?this._bindSheetScope(i):this._getActiveCell?.()?.scope??null),queuePendingAction:this._queuePendingAction??void 0,isEngineReady:this._isEngineReady??void 0,markWired:()=>this._markWired(),getRanges:this._getRanges,getRange:this._getRange,createGraphRanges:this._createGraphRanges,resolveSheetScope:this._resolveSheetScope??void 0,getNamedById:e=>this.getById(e)}:null,l=new kB(t,{...e,scope:i},()=>this._remove(l.getId()),c,o,e=>{let t=this._findSameIdentity(e,l.getScopeId());if(t&&t!==l)throw Error((0,n.t)(`error.named.nameExists`,{name:e}))},this._transactions,this._isReadOnly,this._resolveSheetScope??void 0,()=>this._markContentsChanged(),()=>this._notifyNamesWritten(l,!1));return this._updateState(e=>({...e,itemsById:new Map(e.itemsById).set(l.getId(),l)}),(0,n.t)(`op.addNamedFormulaNamed`,{name:e.name})),this._notifyNamesWritten(l,!1),c&&l._wireNow(),l}_markWired(){this._markContentsChanged()}_markContentsChanged(){this.isClosed()||(this._wiringDirty=!0,this._wiringBatchDepth===0&&this._flushWired())}_beginWiringBatch(){this._wiringBatchDepth++}_endWiringBatch(){this._wiringBatchDepth>0&&this._wiringBatchDepth--,this._wiringBatchDepth===0&&this._flushWired()}_flushWired(){this._wiringDirty&&!this.isClosed()&&(this._wiringDirty=!1,this._notifyCollectionChange())}_getItems(e){let t=this._getState();if(!t)return n.CommonUtils.EmptyArray;let r=Array.from(t.itemsById.values());if(!e)return r;let i=e.name?.toUpperCase(),a=`scope`in e;return r.filter(t=>(!i||t.getName().toUpperCase()===i)&&(!a||t.getScope()===e.scope))}getByName(e,t){if(!e)return null;let n=this._getState();if(!n)return null;let r=e.toUpperCase(),i=t?t.toUpperCase():null,a=null,o=null;for(let e of n.itemsById.values()){if(e.getName().toUpperCase()!==r)continue;let t=e.getScope();if(t!==null){if(i!==null&&t.toUpperCase()===i)return e;o||=e}else a||=e}return i===null?a??o:a}getCount(){return this._getState()?.itemsById.size??0}addListeners(e,t){return super.addListeners(e,t)}getById(e){return e?this._getState()?.itemsById.get(e)??null:null}_findSameIdentity(e,t){let n=this._getState();if(!n)return null;let r=e.toUpperCase();for(let e of n.itemsById.values())if(e.getScopeId()===t&&e.getName().toUpperCase()===r)return e;return null}_bindSheetScope(e){let t=this._bindSheet;return t?t(e):this._container?.getSymbols().bind($.Sheet,e)??null}_resolveScopeInput(e){if(!e)return null;try{return this._bindSheetScope(e)??e}catch{return e}}_resolveScopeName(e){return e?this._resolveSheetScope?.(e)??e:null}_remove(e){let t=this.getById(e);this._updateState(t=>{let n=new Map(t.itemsById);return n.delete(e),{...t,itemsById:n}},(0,n.messageKey)(`op.removeNamedFormula`)),t&&this._notifyNamesWritten(t,!0)}_addNamesWrittenListener(e){return this._namesEmitter??=new x(this),this._namesEmitter.addListeners(e)}_notifyNamesWritten(e,t){this._namesEmitter&&this._namesEmitter.notify(`onNamesWritten`,{params:OB(e,t)})}_namesAsWritten(){let e=this._getState();if(!e)return n.CommonUtils.EmptyArray;let t=[];for(let n of e.itemsById.values())t.push(OB(n,!1));return t}close(){this.isClosed()||(this._close(),this._transactionsRemoveListener?.())}_getState(){return this.isClosed()?null:this._transactions.getState(this._stateId)}_beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}_updateState(e,t=(0,n.messageKey)(`op.update`),r){let i=this._beginCommit(t);try{i.updateState(this._stateId,e),i.commit(r)}catch(e){throw i.rollback(),e}}_initState(){let e=this._beginCommit((0,n.messageKey)(`op.initialize`));try{e.updateState(this._stateId,()=>({itemsById:new Map})),e.amend()}catch(t){throw e.rollback(),t}}get isINamedFormulasCollection(){return!0}},OB=(e,t)=>({id:e.getId(),name:e.getName(),scopeId:e.getScopeId(),removed:t}),kB=class extends rM{_getNamedState(){return this._transactions.getState(this._stateId)}get _block(){return this._host?.getBlock()}constructor(e,t,r,i,a,o,s,c,l,u,d){let f=a??n.CommonUtils.uuidV4();super(e,null,{getRanges:e=>i?.getRanges?.(e)??null,getRange:e=>i?.getRange?.(e)??null,getCalcGrid:()=>i?.host?._getCalcGrid()??null,resolveSheetScope:e=>i?.resolveSheetScope?.(e)??null,getOwnScope:()=>{let e=i?.getScopeGridId();return e?i?.resolveSheetScope?.(e)??null:null}}),this._closed=!1,this._seenBlock=null,this._seenDeleted=!1,this._seenExpression=null,this._id=f,this._transactions=s??new g({transient:!0}),this._stateId=this._transactions.create({name:t.name,scope:t.scope??null,comment:t.comment??null,hidden:t.hidden??!1,isDeleted:!1,expression:jB(t.expression)}),this._deleteFromCollection=r,this._checkRename=o??null,this._wire=i,this._host=i?.host??null,this._isReadOnly=c??null,this._resolveSheetScope=l??null,this._notifyCollection=u??null,this._notifyNameWritten=d??null;let p=this;this._emitter=new x(this,this._transactions),this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onAfterStateChange(e,t,n,r){n||r||p._recordSeen(p._block??null,e)},onRestoreOrRevert(){p._emitter.notify(`onInvalidated`),p._notifyCollection?.();let e=p._block??null,t=p._getNamedState(),n=e!==p._seenBlock||t.isDeleted!==p._seenDeleted||t.expression!==p._seenExpression;p._recordSeen(e,t),n&&p._wire&&e&&(p._wire.container.invalidateNamed(p._id),p._emitter.notify(`onRangesChange`),p._wire.markWired?.())}})}_wireNow(){this._wire&&!this._closed&&this._doWireCore()}_recordSeen(e,t){this._seenBlock=e,this._seenDeleted=t.isDeleted,this._seenExpression=t.expression}getId(){return this._id}getName(){return this._getNamedState().name}getScope(){let e=this._getNamedState().scope;return e?this._resolveSheetScope?.(e)??e:null}getScopeId(){return this._getNamedState().scope}getType(){return`formula`}getValue(){return this.getExpression()}setName(e,t){let r=this._getNamedState();return e&&e!==r.name?(this._checkRename?.(e),this._updateNamedState({name:e},(0,n.t)(`op.updateNamed`,{name:e}),t),this._notifyNameWritten?.(),this):this}setExpression(e,t){if(!e)throw Error(`expression is required`);let r=jB(e);return r===this._getNamedState().expression||(this._updateNamedState({expression:r},(0,n.t)(`op.updateNamed`,{name:this.getName()}),t),this._wire&&this._doWireCore()),this}getComment(){return this._getNamedState().comment}setComment(e,t){return this._updateNamedState({comment:e},(0,n.messageKey)(`op.setComment`),t)}isHidden(){return this._getNamedState().hidden}setHidden(e=!1,t){return this._updateNamedState({hidden:e},(0,n.messageKey)(`op.setHidden`),t)}_updateNamedState(e,t,r){if(this._closed)throw Error((0,n.t)(`error.model.modelClosed`));if(this.isReadOnly())throw Error((0,n.t)(`error.named.nameReadonly`));let i=this._transactions.beginCommit({description:t,...r});try{i.updateState(this._stateId,e),this._emitter.notify(`onAnyChange`),i.commit()}catch(e){throw i.rollback(),e}return this._notifyCollection?.(),this}async select(e){return await this.getRanges()?.select(e),this}toJSON(){let e=this._getNamedState(),t={name:e.name,ref:this.getExpression()},n=this.getScope();return n&&(t.scope=n),e.comment&&(t.comment=e.comment),e.hidden&&(t.hidden=!0),t}isReadOnly(){return this._isReadOnly?.()??!1}isDeleted(){return this._getNamedState()?.isDeleted??!1}addListeners(e,t){return this._emitter.addListeners(e,t)}getVersionId(){return this._transactions.getVersionId(this._stateId)}beginCommit(e){return this._transactions.beginCommit(typeof e==`string`?{description:e}:e)}doBatch(e,t){return this._transactions.doBatch(e,typeof t==`string`?{description:t}:t)}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify(`onClose`),this._closed=!0,this._transactionsRemoveListener?.())}get isIModel(){return!0}get isINamed(){return!0}getRanges(){return this._block?.isReferenceOnly()?this.getReferences():null}getDirectDependents(){return this._graphRanges(`dependents`,!0)}getDependents(){return this._graphRanges(`dependents`,!1)}_asNodeInfo(){let e=this._coords,t=e?.scope,n=(t?this._wire?.resolveSheetScope?.(t):null)??this.getScope()??null;return{id:this._id,name:this.getName(),sheetName:n,rowIndex:e?.rowIndex??0,colIndex:e?.colIndex??0}}getDirectPrecedents(){return this._graphRanges(`precedents`,!0)}getPrecedents(){return this._graphRanges(`precedents`,!1)}async _graphRanges(e,t){let n=this._wire,r=n?.host?._getCalcGrid();if(!n||!r)return null;let{cells:i,names:a}=await r._getNameGraph(e,t),o=n.resolveSheetScope,s=[];for(let e=0;e<i.length;e++){let t=i[e],n=t.scope?o?.(t.scope):null;n&&s.push({...t,scope:n})}if(s.length===0&&a.length===0)return null;let c=s.length>0?kr(s):[];return a.length===0?n.getRanges?.(c)??null:n.createGraphRanges?.(c,a)??(c.length>0?n.getRanges?.(c)??null:null)}delete(e){if(this._getNamedState()?.isDeleted)return;if(this.isReadOnly())throw Error((0,n.t)(`error.named.nameReadonly`));let t=this._wire?.container,r=this._transactions.beginCommit({description:(0,n.t)(`op.deleteNamedItem`,{name:this.getName()}),...e});try{this._host&&t&&this._host?.setPlaceholder(`#NAME?`),r.updateState(this._stateId,{isDeleted:!0}),this._deleteFromCollection(),this._emitter.notify(`onDelete`),r.commit()}catch(e){throw r.rollback(),e}t?.recompileNamed(this._id)}async evaluate(e){this._wire&&!this._block&&await this._wire.ready();let t=this._wire,n=this._block;if(!t||!n)throw Error(`Named formula '${this.getName()}' cannot be evaluated: calculation engine not available.`);let r=typeof e==`number`?e:e?.evalIndex;return this._host._evaluateScalarAt(0,0,r)}getCalculationStatus(){return this._block?X.ResultStatus.Ready:X.ResultStatus.Stale}getExpression(e){let t=this._block;if(!t)return this._host?.getBody()?.text??this._getNamedState().expression;let n=e?.cell?.rowIndex??0,r=e?.cell?.colIndex??0,i=e?.r1c1??!1,a=e?.evalIndex;return t.getTextAt(n,r,i,a,e?.target)}_getBodyNode(){return this._wire?.container.getGrid(this._id)?.getFormulaBlockAt(0,0)?.getNode()??null}getTokens(e){return this._block?super.getTokens(e):n.CommonUtils.EmptyArray}isReferenceOnly(){return this._block?.isReferenceOnly()??!1}_referencesAt(){return this._block?.getReferencesAt(0,0)??null}async setReferenceAt(e,t,n){throw Error(`setReferenceAt is not supported on a named formula.`)}async setReferenceModeAt(e,t,n,r){throw Error(`setReferenceModeAt is not supported on a named formula.`)}async _doWireCore(){let{getScopeGridId:e}=this._wire,t=e();if(!t)return;let n=this._coords?.rowIndex??0,r=this._coords?.colIndex??0,i=this._host?.setBody({coords:EB,expression:this._getNamedState().expression,authoredAt:{rowIndex:n,colIndex:r},scopeGridId:t,recompile:!0,priority:!0},()=>this._bodyAnswered());i&&await i.then(()=>{},()=>{})}_bodyAnswered(){!this._closed&&this._wire&&(this._recordSeen(this._block??null,this._getNamedState()),this._emitter.notify(`onRangesChange`),this._wire.markWired?.())}toString(){return`${this.getName()} => ${this._block?this._block.getTextAt(0,0,!1):this._getNamedState().expression}`}get[Symbol.toStringTag](){return`[NamedFormula]`}};function AB(e){return e?e.toUpperCase():``}function jB(e){return e.startsWith(`=`)?e.substring(1):e}var MB=class extends iE{isLambda(){return!0}},NB=new WeakMap,PB=e=>{let n;try{n=e._getBodyNode?.()??null}catch{return null}if(n?.type!==`function`||String(n.value).toUpperCase()!==`LAMBDA`)return null;let r=n.inputs??[],i=[];for(let e=0;e<r.length-1;e++){let t=r[e]?.value;if(r[e]?.type!==`named`||!t?.name)return null;i.push(t.optional?{name:t.name,optional:!0}:{name:t.name})}let a=e.getName(),o=e.getComment()||e.getValue()||void 0,s=JSON.stringify([a,o,i]),c=NB.get(e);if(c?.key===s)return c.fn;let l=new MB({name:a,parameters:i},()=>t.FormulaError.BuiltIn.Calc,()=>null,{summary:o,category:`Lambda`});return NB.set(e,{key:s,fn:l}),l};function FB(e,t){let n=t.indexOf(`:`);return e.getColumnById(n>=0?t.substring(n+1):t)}function IB(e,t){let{columnFromId:n,columnToId:r}=e;return!!n&&!FB(t,n)||!!r&&!FB(t,r)}function LB(e,n,r){let i,a;switch(e.spec){case 1:{let e=r.getRange().getCoords();i=e.rowStart,a=e.rowEnd;break}case 2:{if(!r.isShowHeaders())return t.FormulaError.BuiltIn.Ref;let e=r.getHeaderRowRange().getCoords();i=e.rowStart,a=e.rowEnd;break}case 3:{if(!r.isShowTotals())return t.FormulaError.BuiltIn.Ref;let e=r.getTotalRowRange().getCoords();i=e.rowStart,a=e.rowEnd;break}case 4:{let e=r.isShowHeaders()?r.getHeaderRowRange().getCoords():r.getDataRange().getCoords(),t=r.getDataRange().getCoords();i=e.rowStart,a=t.rowEnd;break}case 5:{let e=r.getDataRange().getCoords(),t=r.isShowTotals()?r.getTotalRowRange().getCoords():e;i=e.rowStart,a=t.rowEnd;break}default:{let e=r.getDataRange().getCoords();i=e.rowStart,a=e.rowEnd}}let o=r.getRange().getCoords(),s=o.colStart,c=o.colEnd,l=e.columnFromId,u=e.columnToId;if(l){let e=FB(r,l);if(!e)return t.FormulaError.BuiltIn.Ref;if(s=o.colStart+e.getIndex(),c=s,u&&u!==l){let e=FB(r,u);if(!e)return t.FormulaError.BuiltIn.Ref;c=o.colStart+e.getIndex()}}if(e.isThisRow){if(n<i||n>a)return t.FormulaError.BuiltIn.Value;i=n,a=n}return{colStart:s,colEnd:c,rowStart:i,rowEnd:a,scope:r.getSheet().getId(),$colStart:!0,$rowStart:!0,$colEnd:!0,$rowEnd:!0}}var RB=class extends cO{constructor(e){super({...e??{},transactions:new g({maxCommits:WB})}),this._status=X.Status.Off,this._statusTransition=null,this._externalBindings=null,this._pendingNames=null,this._compilerEditingStorage=null,this._cycleId=0,this._staticEpoch=1,this._precedentEpoch=1,this._epochSeenFormulas=null,this._epochSeenPrecedents=null,this._epochSeenDynamics=null,this._volatiles=new Set,this._formulaHosts=new Map,this._calculatedCommitId=null,this._calculatedEngineId=null,this._modelStore=null,this._fronts=new Map,this._gridSpecs=new Map,this._engineUp=!1,this._modelStoreRemoveListener=null,this._mirrorRemoveListener=null,this._modelMirrorId=null,this._engineIds=new Map,this._landingOf=new Map,this._mirroredId=null,this._lastRevert=null,this._outstanding=null,this._pendingActions=null,this._pendingPriority=null,this._draining=!1,this._drainDepth=0,this._drainScheduled=!1,this._calcOwed=!1,this._calcOwedBy=null,this._channel=null,this._bootPending=null,this._passesInFlight=0,this._calculationState=X.CalculationState.Done,this._calculationStatePosted=!1,this._calculationStateWaiters=null,this._bootFull=!1,this._bootExplicit=!1,this._compilerWaiters=null,this._wroteWhileOff=!1,this._calcMode=X.CalculationMode.Automatic,this._iterate=!1,this._maxIteration=100,this._maxIterateChange=.001,this._calcJSON=null,this._removeNamedItemsListeners=null,this._namedDependents=null,this._namedDependentsOf=null,this._resolvers=null,this._tableSymbols=null,this._nameSymbols=null,this._tablesDerived=null,this._namesDerived=null,this._sheetsDerived=null,this._rollbackHooked=null,this._modelStore=e?.transactions??null,this._initialize(e)}_initialize(e){this._runtime=e?.runtime??new vt(`Calculation Runtime`,{getNow:()=>this._getTransactions().getCurrentCommit().getTimestamp()}),this._getActiveCell=e?.getActiveCell??(()=>null),this._getRange=e?.getRange??(()=>null),this._getRanges=e?.getRanges??(()=>null);let r=e,i=r?.namedCollection??null,a=e=>e?.getType()===`table`?e:null,o=e=>{if(!e)return null;let t=this._replicaTables()?.idByName.get(e.toLowerCase());return a(t===void 0?i?.getByName(e,!0):i?.getById(t))},s=e=>this._replicaTables()?.of.get(e.getId())?.[0]??e.getName(),c=(e,t)=>{let n=this._replicaTables()?.of.get(e.getId())?.[1];if(!n)return null;for(let e=0;e<n.length;e++)if(t(n[e]))return n[e];return null},l=new TC(o,e=>a(i?.getById(e)),s);this._tableSymbols=l;let u=new Map,d={bind:(e,t)=>{let n=t?.at;if(e||!n)return l.bind(e,t);let r=(e=>{if(!e.scope||!i)return null;let t=e.scope,n=t.toLowerCase(),r=i.getItems({type:`table`});for(let i=0;i<r.length;i++){let a=r[i].getValue(),o=a?.getSheet();if(!o||o.getId()!==t&&o.getName()?.toLowerCase()!==n)continue;let s=a.getRange().getCoords();if(e.rowIndex>=s.rowStart&&e.rowIndex<=s.rowEnd&&e.colIndex>=s.colStart&&e.colIndex<=s.colEnd)return r[i]}return null})(n);return r?l.bind(s(r)):null},resolve:(e,t)=>l.resolve(e,t)},f=new EC((e,t)=>{try{e=e.toLowerCase();let n=(t?l.getRealById(t):null)??o(t);if(!n)return null;let r=this._replicaTables()?.of.has(n.getId())?c(n,t=>t[1].toLowerCase()===e)?.[0]:n.getValue().getColumnByName(e)?.getId();return r==null?null:`_`+(l.bind(s(n))??``)+`:`+r}catch{return null}},e=>{if(!e.startsWith(`_`))return null;let t=(e=e.substring(1)).split(`:`),n=t[0],r=t[1],i=l.getRealById(n);if(!i)return null;let a=i.getValue().getColumnById(r);return a?{stableId:e,toString:()=>c(i,e=>e[0]===r)?.[1]??a.getName()??`(untitled)`}:null}),p=r?.getSheetById,m=new $R({json:r?.externalBooks,resolver:r?.externalBookResolver,transactions:r?.transactions,getDependents:e=>j._getSymbolDependents(e),getSheetRange:e=>{let t=e.scope?p?.(e.scope):null;if(!t?.getRange)return null;let{rowStart:n,colStart:r,rowEnd:i,colEnd:a}=e;return t.getRange({rowStart:n,colStart:r,rowEnd:i,colEnd:a})}});this._externalBooks=m;let h=()=>m,g={addBook:e=>m.add(function(e){return{sources:[tC(e.dir+e.book)],sheetNames:e.sheetName===null?[]:[e.sheetName]}}(e)).getId(),addSheet:(e,t)=>m._addSheetName(e,t)},_=()=>{let e=new Set,t=m.toJSON()?.length??0;for(let n=1;n<=t;n++)e.add(m._getIdByIndex(n));return e},v=_();m.addListeners({onCollectionChange:()=>{if(j.isClosed())return;let e=_(),t=new Set;for(let n of e)v.has(n)||t.add(n);for(let n of v)e.has(n)||t.add(n);v=e,j._whenSafe(async()=>{if(!j.isClosed()){for(let e of j._externalBindings?.sync()??n.CommonUtils.EmptyArray)t.add(e);j._markDirtyReferencing(t)}})}},{transactional:!1}),r?.addSheetsListener?.(()=>{j.isClosed()||j._sendSheets()},{transactional:!1});let y={bind:(e,t,n)=>fC(h(),e,t?g:null,n),resolve:(e,t)=>function(e,t,n){let r=e?cC(t):null;if(!r)return null;let i=e._getIndexById(r.bookId);if(i===-1)return hC(t);let a=e.getById(r.bookId),o=a?.getSheetNames(),s=null;if(r.sheetIndex>=0){let e=o?.[r.sheetIndex],n=o?.[r.sheetEnd];if(e===void 0||n===void 0)return hC(t);s=r.sheetEnd===r.sheetIndex?e:e+`:`+n}return{stableId:t,toString:()=>n&&a?a.getDisplayName(s):`[`+i+`]`+(s??``),getName:()=>s,getEntireCoords:()=>null}}(h(),e,t)},b=new gC(e=>j._sheetIdByName(e),e=>{let n=j._getState();if(n.sheets.has(e)){let t=n.sheets.get(e)??null,r=n.gridsAll.get(e);return{stableId:e,toString:()=>t??e,getName:()=>t,getEntireCoords:()=>r?.getEntireCoords()??null}}if(sC(e))return null;let r=j._getState().gridsAll.get(e);return r?{stableId:e,toString:()=>t.FormulaError.BuiltIn.Ref.toString(),getEntireCoords:()=>r.getEntireCoords()}:null},y,e=>j._sheetIds().indexOf(e)),S=new YS;S.registerProvider($.Sheet,b),S.registerProvider($.Table,d),S.registerProvider($.TableColumn,f);let C=()=>r?.getSheetIds?.()??n.CommonUtils.EmptyArray,w=new gC(e=>{let t=C(),n=e.toLowerCase();for(let e=0;e<t.length;e++)if(p?.(t[e])?.getName()?.toLowerCase()===n)return t[e];return null},e=>{let n=p?.(e);if(n)return{stableId:e,toString:()=>n.getName()??e,getName:()=>n.getName()??null,getEntireCoords:()=>n.getEntireCoords()??null};if(sC(e))return null;let r=j._fronts.get(e);return r?{stableId:e,toString:()=>t.FormulaError.BuiltIn.Ref.toString(),getEntireCoords:()=>r.getEntireCoords()}:null},y,e=>C().indexOf(e)),T=new Map([[$.Sheet,w],[$.Table,{bind:(e,t)=>d.bind(e,t),resolve:(e,t)=>{let n=l.resolve(e,t);return n?{stableId:n.stableId,toString:()=>l.getRealById(e)?.getName()??n.toString()}:null}}],[$.TableColumn,{bind:(e,t)=>f.bind(e,t),resolve:(e,t)=>{let n=f.resolve(e,t);if(!n)return null;let r=(e.startsWith(`_`)?e.substring(1):e).split(`:`),i=l.getRealById(r[0])?.getValue().getColumnById(r[1])??null;return{stableId:n.stableId,toString:()=>i?.getName()??n.toString()}}}]]);this._modelSymbolRegistry=new XS(S,T);let E=null;this._resolvers={getStructureReferenceCoords:(e,n,r,i)=>{if(!e)return t.FormulaError.BuiltIn.Ref;let a=e.tableId;if(!a)return t.FormulaError.BuiltIn.Ref;let o=l.getRealById(a);if(!o)return t.FormulaError.BuiltIn.Ref;let s=o.getValue();return!s||s.isDeleted()?t.FormulaError.BuiltIn.Ref:LB(e,n,s)},getNamedFormulaBlock:e=>N.getGrid(e)?.getFormulaBlockAt(0,0)??null},this._emitter=new x(this),this._updateState({gridsAll:new Map,gridMaps:new Map,sheets:new Map,tables:new Map,names:new Map});let D=this._modelStore;if(D){let e=this,t=D.amend(D.getCurrentCommit(!1).getId(),()=>D.create({mirror:!0}));this._modelMirrorId=t,this._mirrorRemoveListener=D.addStateListener(t,{onRestoreOrRevert(t,n){if(e._followRestore(n.getId()),e._channel){let t=e._modelHistory();e._markHeld(n=>n.commitId!==void 0&&e._engineIds.has(n.commitId)&&!t.has(n.commitId))}}}),this._modelStoreRemoveListener=D.addListener({onCommitClose(t,n,r,i){if(n){let n=t.getId();e._markHeld(e=>e.dead||e.commitId===n),e._revertTo(D.getCurrentCommit(!1).getId()),e._dropLanding(`${n}:0`);return}r||i?e._foldPhantom(t.getId()):e._mirror(t.getId())}})}let O=e?.json;this._calcJSON=O?{...O}:null,this._calcMode=O?.calcMode??X.CalculationMode.Automatic,this._iterate=O?.iterate??e?.enableIterativeCalculations??!1,this._maxIteration=O?.maxIteration??O?.maxIterations??e?.maxIteration??100,this._maxIterateChange=O?.maxIterateChange??e?.maxIterateChange??.001;let k=new di({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),A=new di({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}});this._updateState({formulaSpatial:k,precedentSpatial:A,dynamicByBlock:new Map,dirtySpatial:new di}),D&&this._mirror(D.getCurrentCommit(!1).getId());let j=this,M={rowIndex:0,colIndex:0,gridId:null,node:null,depth:0,activeNames:new Set,implicitIntersect:!1,firstCell:!1,perCellRead:!1,drawIndex:0},N={getRuntime:()=>j._runtime,getScope:()=>M,createFormulaBlock(e,t,n,r,i,a,o){if(!j._compiler)throw Error(`The calculation engine has not started; nothing can compile yet.`);let s=a?j._getEditingCompiler(a):j._compiler,c=cC(e)?.bookId??null,l=c?null:cC(j._externalBindings?.getNameById(e)?.getScope()??``)?.bookId??null;return new fM(s.compile(t.getRuntime(),r,i,n,N.getSymbols(),e=>t.getFunction(e),c??l?uC(c??l,-1):j._sheetName(e),o,c?{book:c}:void 0),t,M,e,()=>this.getGrid(e)?.getEntireCoords()??null,j._resolvers)},getSymbols:()=>S,resolveScope:e=>S.resolve($.Sheet,e)?.toString(),getSheetIndex:e=>{let t=j._options;if(e===void 0)return t.getSheetIndex?.()??-1;let n=j._sheetIdByName(e);return n===null?t.getSheetIndex?.(e)??-1:j._sheetIds().indexOf(n)},getSheetCount:()=>j._getState().sheets.size,getSheetIds:()=>j._sheetIds(),getSheetSpanIds:e=>{let t=vC(e);if(t){let e=j._sheetIds(),n=e.indexOf(t[0]),r=e.indexOf(t[1]);return n===-1||r===-1?null:e.slice(Math.min(n,r),Math.max(n,r)+1)}let n=cC(e);if(!n||n.sheetEnd===n.sheetIndex)return null;let r=[];for(let e=n.sheetIndex;e<=n.sheetEnd;e++)r.push(uC(n.bookId,e));return r},getFormulas:()=>j._getState().formulaSpatial,setFormulas(e){j._amendState({formulaSpatial:e},qB)},getPrecedents:()=>j._getState().precedentSpatial,setPrecedents(e){j._amendState({precedentSpatial:e},qB)},getDynamics:()=>j._getState().dynamicByBlock,setDynamics(e){j._amendState({dynamicByBlock:e},qB)},addDynamicPrecedent(e,t,n){j._calcExecutor._addDynamicPrecedent?.(e,t,n)},getVolatiles:()=>j._volatiles,isLegacyIntersect:()=>!0===j._calcJSON?.legacyIntersect,getGridValues(e){let t=j._calcExecutor._overlays?.get(e);if(t)return t;let n=j._calcExecutor._gridUpdates?.get(e);if(n)return n.values;let r=j._getState().gridsAll.get(e);return r?r.getValues():(console.warn(`invalid gridId for updates`,e),null)},getIncrementalUpdates(e){let t=j._calcExecutor._gridUpdates;if(!t)return null;let n=t.get(e);if(!n){let r=N.getGrid(e);if(!r)return console.warn(`invalid gridId for updates`,e),null;n=r.beginUpdates(),t.set(e,n)}return n},registerGrid:e=>{j._registerGrid(e)},unregisterGrid:e=>{j._unregisterGrid(e)},getGrid:e=>j.isClosed()?null:j._getState().gridsAll.get(e)??null,markDirty:e=>{let n=j._getState(),r=n.dirtySpatial.clone(),i=n.precedentSpatial,a=n.formulaSpatial,o=!1,s=Or(e,t.IRange.Axis.Column,2);for(let e=0;e<s.length;e++){let t=s[e];(i?.has(t)||a?.has(t))&&(o=!0,r.insertNonOverlapping(t))}return o&&(j._amendState({dirtySpatial:r},qB),j._noteCalculationState()),o},getDirtyGrid:e=>j._getState().dirtySpatial.getSpatialAt(e),calculateGrid:(e,t)=>j._calculate(t,e),requestCalculateGrid:e=>{j._owePass(e)},getCycleId:()=>j._cycleId,getCalculatedCommitId:()=>j._calculatedCommitId,landRequest:(e,t)=>j._landUnder(e,t),sendRequest:(e,t,n)=>j._sendRequest(e,t,n),getImager:e=>j._imagerFor(e),setGridMaps:(e,t)=>{let n=new Map(j._getState().gridMaps);n.set(e,t),j._amendState({gridMaps:n},qB)},recordTouched:(e,t)=>{let n=j._getTransactions().getPendingTransaction();n&&t.length!==0&&n.setIntent(GB,n=>{let r={...n??{}};return r[e]=[...r[e]??[],...t],r})},revertTo:(e,t)=>j._revertTo(e)?.get(t)??null,getCalcEpochs:()=>{let e=j._getState();return e.formulaSpatial!==j._epochSeenFormulas&&(j._epochSeenFormulas=e.formulaSpatial,j._staticEpoch++,j._precedentEpoch++),e.precedentSpatial!==j._epochSeenPrecedents&&(j._epochSeenPrecedents=e.precedentSpatial,j._precedentEpoch++),e.dynamicByBlock!==j._epochSeenDynamics&&(j._epochSeenDynamics=e.dynamicByBlock,j._precedentEpoch++),{staticEpoch:j._staticEpoch,precedentEpoch:j._precedentEpoch}},bumpCalcEpochs:e=>{e&&j._staticEpoch++,j._precedentEpoch++},getNow:()=>j._runtime.getNow(),whenSafe:e=>{j._whenSafe(e)},isLoading:()=>j._draining||j._status===X.Status.Starting,recompileNamed(e){j._whenSafe(async()=>{j._recompileReferencing(new Set([e]))})},invalidateNamed(e){j._whenSafe(async()=>{j._markDirtyReferencing(new Set([e]))})},getNamedNodeInfo(e,t){let n=j._namedFormulas.getById(e);return n?t&&j._getNamedDependents(e).length===0?null:n._asNodeInfo():null},getNamedDependents:e=>j._getNamedDependents(e),getNamedDependentNames:e=>j._getNamedDependentNames(e)};this._container=N,this._removeNamedItemsListeners=i?.addListeners({onCollectionChange:()=>{if(j.isClosed())return;let e=l.reconcile(),t=i.getItems(),n=this._getState().itemRemoveListeners;n?.forEach(e=>e()),n=[];for(let e of t)if(e.getType()===`table`){let t=e.getValue(),r=()=>{if(t.isDeleted())return``;let e=t.getRange().getCoords();return`${t.getSheet()?.getId()}!${e.rowStart},${e.colStart}:${e.rowEnd},${e.colEnd}|${t.isShowHeaders()}|${t.isShowTotals()}`},i=t.getId();u.has(i)||u.set(i,r());let a=()=>{if(j.isClosed())return;let t=r();if(t===u.get(i)||(u.set(i,t),!t))return;let n=l.bind(s(e),{existing:!0});n&&j._whenSafe(async()=>{j.isClosed()||j._recompileReferencing(new Set([n]))})};n.push(t.addListeners({onAnchorCoordsChange:a,onInvalidated:a},{transactional:!1}))}this._amendState({itemRemoveListeners:n},qB),e.length>0&&j._whenSafe(async()=>{j.isClosed()||j._markDirtyReferencing(new Set(e))})}},{transactional:!1})??null;let P=new xF(N,t.IRange.Axis.Column,this._options?.functions);this._context=P;let F=new DB({container:N,context:P,ready:()=>this.ready(),getActiveCell:()=>this._getActiveCell(),getRange:e=>this._getRange(e),getRanges:e=>this._getRanges(e),createGraphRanges:this._options?.createGraphRanges,resolveSheetScope:e=>p?.(e)?.getName()??this._sheetName(e),bindSheet:e=>this._modelSymbolRegistry.bind($.Sheet,e),createHost:e=>this._createFormulaHost({id:e,entireCoords:FH(),unanchored:!0}),getOrBindProxyFakeId:(e,t)=>E?.bind(e,{scope:t,own:!0})??null,queuePendingAction:e=>this._whenSafe(e,!0),isEngineReady:()=>this._status===X.Status.Running&&!this._draining,transactions:r?.transactions,isReadOnly:()=>this.isReadOnly()||(this._options?.isNamesReadOnly?.()??!1)});this._namedFormulas=F,E=new TC((e,t)=>{if(sC(t))return j._externalBindings?.getNameByScope(e,t)??null;let n=j._replicaNameId(e,t);return n===void 0?F.getByName(e,t):F.getById(n)},e=>F.getById(e)??j._externalBindings?.getNameById(e)??null,e=>j._replicaNames()?.of.get(e.getId())?.[0]??e.getName()),this._nameSymbols=E,S.registerProvider($.NamedFormula,E);let I=E;T.set($.NamedFormula,{bind:(e,t)=>I.bind(e,t),resolve:(e,t)=>{let n=I.resolve(e,t);return n?{stableId:n.stableId,toString:()=>I.getRealById(e)?.getName()??n.toString()}:null}}),F._addNamesWrittenListener({onNamesWritten:(e,t)=>{j._nameWritten(t)}}),this._pendingNames=r?.names??null,F.setPendingJSON(this._pendingNames),F.addListeners({onCollectionChange:()=>{if(j.isClosed())return;let e=E.reconcile();j._markDirtyReferencing(new Set(e))}}),this._calcExecutor=new vz(N,P,()=>this.calculate()),this._externalBindings=new ez({books:m,createGrid:e=>this._createBackendGrid({uuid:e}),unregisterGrid:e=>{let t=N.getGrid(e);t?t._detach():this._unregisterGrid(e)},getGrid:e=>N.getGrid(e),gridIds:()=>this._getState().gridsAll.keys(),createHost:e=>this._createFormulaHost({id:e,entireCoords:FH(),unanchored:!0}),holdsGrids:()=>this._engineUp,bindNameId:(e,t)=>E.bind(e,{scope:t,own:!0}),queue:e=>this._whenSafe(e,!0),recompileNamed:e=>N.recompileNamed(e)}),this._externalBindings.sync(!0)}_markDirtyReferencing(e){if(e.size===0)return!1;let t=this._namedTargets(e),n=this._getState().formulaSpatial.all3D(),r=[];for(let e=0;e<n.length;e++){let i=n[e].value;if(i.gridId==null)continue;let a=i.getReferencedSymbolIds();for(let e=0;e<a.length;e++)if(t.has(a[e])){r.push({...i.ref,scope:i.gridId});break}}return r.length!==0&&(this._container.markDirty(r),!0)}_recompileReferencing(e){if(e.size===0)return;let t=this._namedTargets(e),n=[];for(let t of e){let e=this._tableSymbols?.getRealById(t)?.getValue();e&&!e.isDeleted()&&n.push([t,e])}let r=this._getState().formulaSpatial.all3D();for(let e=0;e<r.length;e++){let i=r[e].value,a=i.getReferencedSymbolIds(),o=!1;for(let e=0;e<a.length&&!o;e++)o=t.has(a[e]);if(!o)continue;let s=i.ref,c=i.formula,l=i.gridId,u=l!=null&&!this._namedFormulas.getById(l)&&!sC(l)&&!this._externalBindings?.getNameById(l);if(c&&u)for(let e=0;e<n.length;e++){let[t,r]=n[e];a.includes(t)&&(c=c.replaceTableReferences(t,e=>IB(e,r)?wS():null))}let d=c&&c!==i.formula?c.getTextAt(s.rowStart,s.colStart):i.getTextAt(s.rowStart,s.colStart);this._writeBlockText(i,d)}}_releaseTableReferences(e,t){let n=this._tableSymbols?.bind(e.getName(),{existing:!0});if(!n)return;let r=t===`address`?function(e){let t=e=>({getCoords:()=>e}),n=e.getRange().getCoords(),r=t(e.getDataRange().getCoords()),i=e.isShowHeaders(),a=e.isShowTotals(),o=i?t(e.getHeaderRowRange().getCoords()):r,s=a?t(e.getTotalRowRange().getCoords()):r,c=new Map,l=n.colEnd-n.colStart+1;for(let t=0;t<l;t++){let n=e.getColumnAt(t);n&&c.set(String(n.getId()),n.getIndex())}let u=e.getSheet().getId();return{getRange:()=>t(n),getDataRange:()=>r,getHeaderRowRange:()=>o,getTotalRowRange:()=>s,isShowHeaders:()=>i,isShowTotals:()=>a,getColumnById:e=>{let t=c.get(e);return t===void 0?null:{getIndex:()=>t}},getSheet:()=>({getId:()=>u})}}(e):null;this._whenSafe(async()=>{this.isClosed()||this._rewriteTableReferences(n,r)})}_refitTableRows(e,t,r,i,a,o,s){let c=()=>{if(this.isClosed())return;let o=this._container.getSymbols().bind($.Sheet,e);if(!o)return;let s=this._getState().precedentSpatial.search({colStart:t.colStart,rowStart:r.rowStart,colEnd:t.colEnd,rowEnd:r.rowEnd,scope:o}),c=null;for(let e=0;e<s.length;e++){let t=s[e].value;if(t.index<0)continue;let n=t.formulaEntry.value,r=n.gridId;if(r==null||sC(r)||this._externalBindings?.getNameById(r))continue;let i=(c??=new Map).get(n);i?i.includes(t.index)||i.push(t.index):c.set(n,[t.index])}if(!c)return;let l=(e,t,n,r,i)=>{if(t)return e===n?[r,i]:null;let a=n-e;return a>=r&&a<=i?[a,a]:null},u=(e,t,n,r,i,a)=>{if(t)return(r?e>=n:e<=n)?[i,a]:null;let o=r?Math.max(i,n-e):i,s=r?a:Math.min(a,n-e);return o<=s?[o,s]:null},d=(e,t)=>{if(!e||!t)return null;let n=Math.max(e[0],t[0]),r=Math.min(e[1],t[1]);return n<=r?[n,r]:null};for(let[e,s]of c){let c=e.ref,f=(c.rowStart!==c.rowEnd||c.colStart!==c.colEnd)&&(e.getAnchorNode().ext?.fixedRef??null)!==null,p=[];for(let n=0;n<s.length;n++){let m=s[n],h=e.getReferenceAt(c.rowStart,c.colStart,m);if(!h||h.colStart===void 0||h.scope&&h.scope!==o)continue;let g=e=>({...h,rowStart:h.rowStart+(e?a.rowStart-r.rowStart:0),rowEnd:h.rowEnd+(a.rowEnd-r.rowEnd)}),_=c.rowStart,v=f?c.rowStart:c.rowEnd,y=c.colStart,b=f?c.colStart:c.colEnd,x=d(u(h.colStart,h.$colStart,t.colStart,!0,y,b),u(h.colEnd,h.$colEnd,t.colEnd,!1,y,b));if(!x)continue;let S=l(h.rowEnd,h.$rowEnd,r.rowEnd,_,v);if(S)for(let e of i===null?[r.rowStart]:[r.rowStart,i]){let t=d(S,l(h.rowStart,h.$rowStart,e,_,v));t&&p.push({coords:f?c:{rowStart:t[0],rowEnd:t[1],colStart:x[0],colEnd:x[1]},index:m,refitted:g(e===r.rowStart)})}}if(p.length===0)continue;let m=new Set,h=new Set;for(let e=0;e<p.length;e++){let t=p[e].coords;m.add(t.rowStart).add(t.rowEnd+1),h.add(t.colStart).add(t.colEnd+1)}let g=Array.from(m).sort((e,t)=>e-t),_=Array.from(h).sort((e,t)=>e-t);for(let t=0;t<g.length-1;t++)for(let r=0;r<_.length-1;r++){let i={rowStart:g[t],rowEnd:g[t+1]-1,colStart:_[r],colEnd:_[r+1]-1},a=e;for(let e=0;e<p.length;e++)n.CoordUtils.isRangeWithinRange(i,p[e].coords)&&(a=a.setReferenceAt(p[e].index,p[e].refitted)??a);a!==e&&this._writeBlockText(e,a.getTextAt(i.rowStart,i.colStart),i)}}};o||this._status!==X.Status.Running||c(),this._whenSafe(async()=>{s()&&c()})}_rewriteTableReferences(e,n){let r=e=>n?function(e,n){let r=LB({...e,isThisRow:!1},0,n);if(t.FormulaError.isError(r))return wS();let i=r,a=e.isThisRow,o=aS({colIndex:i.colStart,rowIndex:a?0:i.rowStart,$colIndex:!0,$rowIndex:!a});return o.value.scope=i.scope??null,i.colStart!==i.colEnd||!a&&i.rowStart!==i.rowEnd?hS(`:`,o,aS({colIndex:i.colEnd,rowIndex:a?0:i.rowEnd,$colIndex:!0,$rowIndex:!a}),!0):o}(e,n):wS(),i=this._getState().formulaSpatial.all3D();for(let t=0;t<i.length;t++){let n=i[t].value,a=n.gridId;if(a==null||!n.getReferencedSymbolIds().includes(e)||this._namedFormulas.getById(a)||sC(a)||this._externalBindings?.getNameById(a))continue;let o=n.formula,s=o?.replaceTableReferences(e,r);if(!s||s===o)continue;let c=n.ref;this._writeBlockText(n,s.getTextAt(c.rowStart,c.colStart))}}_writeBlockText(e,t,r=e.ref){let i=this._container.getGrid(e.gridId);if(!i)return;let a=r,o=this._formulaHosts.get(e.gridId);if(o)return void o._rewrite(a,t);i._setInputsNow(null,[{...a,value:t}]);let s=this._getState().formulaSpatial.search({...a,scope:e.gridId});for(let t=0;t<s.length;t++){let r=s[t].value;r!==e&&n.CoordUtils.isEqualRanges(r.ref,a)&&eI(e,r)}}_replaceSheetSpans(e,t,n){let r=this._container;this._landUnder(this._modelLanding()??void 0,()=>{for(let i=0;i<t.length;i++){let a=r.getGrid(t[i]);if(a)return void a._replaceSheetSpans(e,t,n)}})}_getNamedDependents(e){return this._getSymbolDependents(e)}_getSymbolDependents(e){return this._getSymbolIndex().get(e)??n.CommonUtils.EmptyArray}_getSymbolIndex(){let e=this._getState().formulaSpatial;if(this._namedDependentsOf!==e||!this._namedDependents){let t=new Map,n=e.all3D();for(let e=0;e<n.length;e++){let r=n[e].value;if(r.gridId==null||sC(r.gridId)||this._externalBindings?.getNameById(r.gridId))continue;let i=r.getReferencedSymbolIds();if(i.length===0)continue;let a=r.ref,o={rowStart:a.rowStart,colStart:a.colStart,rowEnd:a.rowEnd,colEnd:a.colEnd,scope:r.gridId};for(let e=0;e<i.length;e++){let n=t.get(i[e]);n?n.push(o):t.set(i[e],[o])}}this._namedDependents=t,this._namedDependentsOf=e}return this._namedDependents}_getNamedDependentNames(e){let t=new Set,n=[e];for(let e=0;e<n.length;e++){let r=this._getNamedDependents(n[e]);for(let e=0;e<r.length;e++){let i=r[e].scope;i&&!t.has(i)&&this._namedFormulas.getById(i)&&(t.add(i),n.push(i))}}return t}_namedTargets(e){let t=new Set(e);for(let n of e)for(let e of this._getNamedDependentNames(n))t.add(e);return t}_stats(){return this._calcExecutor.getDemandStats()}_resetStats(){this._calcExecutor.resetStats()}_planCacheMode(e){return e&&(this._calcExecutor.planCacheMode=e),this._calcExecutor.planCacheMode}start(){return this._statusTransition||(this._statusTransition=(async()=>{if(this._status===X.Status.Off||this._status===X.Status.Error)try{this._status=X.Status.Starting,this._emitter.notify(`onStatusChange`),this._emitter.notify(`onStarting`);let e=this._liveSheets();this._amendState({sheets:new Map(e),tables:e.length>0?this._liveTables():new Map,names:this._liveNames()},qB),this._openEngineGrids(!0);let t=this._container,n=this._context,[r,i]=await Promise.all([n._initialize(),Promise.resolve().then(()=>require("./CrcmEew-dr51xpf9.cjs"))]);if(this._closed)return void(this._status=X.Status.Off);let a=r.functions;this._functions=a;let o=this._namedFormulas;a._setNamedSource({getByName:(e,t)=>{let n=o.getByName(e,t??null);return n?PB(n):null},getItems:()=>{let e=new Map,t=o.getItems();for(let n of[!0,!1])for(let r of t){if(r.getScope()===null!==n)continue;let t=r.getName().toUpperCase();if(e.has(t))continue;let i=PB(r);i&&e.set(t,i)}return Array.from(e.values())}}),t.getSymbols().registerProvider($.Function,new kC(()=>a)),this._compilerModule=i,this._compiler=new i.FormulaCompiler,this.hydrateNames(),await this._boot()}catch(e){throw this._status=X.Status.Error,this._abandonStart(),this._dropEngine(),this._emitter.notify(`onError`,e),this._emitter.notify(`onStatusChange`),e}finally{this._statusTransition=null,this._noteCalculationState()}})(),this._statusTransition.catch(()=>{})),this._statusTransition}_whenSafe(e,t=!1){if(t){let t=this._pendingPriority;t||(this._pendingPriority=t=[]),t.push(e)}else{let t=this._pendingActions;t||(this._pendingActions=t=[]),t.push(e)}this._scheduleDrain()}_sendRequest(e,t,n){t!==void 0&&this._hookRollback(t);let r=t=>GI(t,this._imagerFor(e)),i;if(UI.getMode()===`off`)i=this._sendRequestNow(e,t,n).then(r);else{let a=UI.request(n,n.type);i=this._sendRequestNow(e,t,a).then(e=>r(UI.results(e,`response`)))}let a=this._outstanding??=new Set;a.add(i),this._noteCalculationState();let o=()=>{a.delete(i),this._noteCalculationState()};return i.then(o,o),i}_sendRequestNow(e,t,n){let r=this._status;if(n.type===`requestPass`)return this._owePass(e),Promise.resolve({cycleId:this._cycleId});if(n.type===`revert`&&r!==X.Status.Running)return Promise.resolve({cycleId:this._cycleId,commitId:KI(n)});if(n.type===`close`&&r!==X.Status.Running&&r!==X.Status.Starting)return this._container.getGrid(e)?._detach(),Promise.resolve({cycleId:this._cycleId});if(r===X.Status.Running){if(n.type===`sheets`)return this._applySheets(n.sheets),Promise.resolve({cycleId:this._cycleId,commitId:KI(n)});if(n.type===`tables`)return this._applyTables(n.changes),Promise.resolve({cycleId:this._cycleId,commitId:KI(n)});if(n.type===`names`)return this._applyNames(n.changes),Promise.resolve({cycleId:this._cycleId,commitId:KI(n)});if(n.type===`rollback`)return this._savepointRolledBack(n.savepointId),Promise.resolve({cycleId:this._cycleId});if(n.type===`create`)return this._createEngineGrid(n.spec),Promise.resolve({cycleId:this._cycleId});let r=this._container.getGrid(e);if(!r)return Promise.resolve({cycleId:this._cycleId,commitId:KI(n)});try{return Promise.resolve(r._apply(n,t))}catch(e){return Promise.reject(e)}}if(r===X.Status.Starting){if(n.type===`rollback`){let e=n.savepointId;this._markHeld(t=>t.dead||t.landingId===e)}return new Promise((r,i)=>{(this._channel??=[]).push({gridId:e,request:n,landingId:t,commitId:KI(n),dead:!1,resolve:r,reject:i})})}return zB.has(n.type)||(this._wroteWhileOff=!0),Promise.resolve({cycleId:this._cycleId,commitId:KI(n)})}_markHeld(e){let t=this._channel;if(t)for(let n=0;n<t.length;n++)t[n].dead=e(t[n])}_abandonStart(){let e=this._channel;if(this._channel=null,e)for(let t=0;t<e.length;t++)e[t].resolve({cycleId:this._cycleId,commitId:e[t].commitId});this._releaseCompilerWaiters()}_releaseCompilerWaiters(){let e=this._compilerWaiters;if(this._compilerWaiters=null,e)for(let t=0;t<e.length;t++)e[t]()}_whenCanCompile(){return this._status===X.Status.Running?Promise.resolve():this._status===X.Status.Starting?new Promise(e=>{(this._compilerWaiters??=[]).push(e)}):this.start()}async _boot(){this._drainDepth++,this._draining=!0;try{if(this._engineUp=!0,this._externalBindings?.sync(!0),this._pendingPriority?.length&&await this._drainPending(!0),this._closed)return;let e=this._getTransactions(),t=this._wroteWhileOff;for(this._wroteWhileOff=!1;this._channel;){let n=this._channel,r=e=>e.type===`create`?0:e.type===`setBody`&&!0===e.body.priority?1:2,i=[];for(let e=0;e<3;e++)for(let t=0;t<n.length;t++)r(n[t].request)===e&&i.push(n[t]);this._channel=null;for(let n=0;n<i.length;n++){let r=i[n],a=r.request;if(a.type===`sheets`){r.dead||this._applySheets(a.sheets),r.resolve({cycleId:this._cycleId,commitId:r.commitId});continue}if(a.type===`tables`){r.dead||this._applyTables(a.changes),r.resolve({cycleId:this._cycleId,commitId:r.commitId});continue}if(a.type===`names`){r.dead||this._applyNames(a.changes),r.resolve({cycleId:this._cycleId,commitId:r.commitId});continue}if(a.type===`rollback`){r.dead||this._savepointRolledBack(a.savepointId),r.resolve({cycleId:this._cycleId});continue}if(a.type===`create`){this._createEngineGrid(a.spec),r.resolve({cycleId:this._cycleId});continue}if(a.type===`requestPass`){r.resolve({cycleId:this._cycleId});continue}let o=r.dead?null:this._container.getGrid(r.gridId);if(o){a.type===`seed`&&a.options?.full&&!t&&(a={...a,options:{...a.options,full:!1}});try{r.resolve(o._apply(a,e.getCurrentCommit(!1).getId(),!0))}catch(e){r.reject(e)}}else r.resolve({cycleId:this._cycleId,commitId:r.commitId})}}this._forgetEarlierLandings(),this._status=X.Status.Running,this._emitter.notify(`onStatusChange`),this._emitter.notify(`onReady`),this._releaseCompilerWaiters(),(this._pendingPriority?.length||this._pendingActions?.length)&&await this._drainPending()}finally{this._drainDepth--,this._draining=this._drainDepth>0}this._closed||await this._scheduleBoot()}_scheduleBoot(){return this._bootPending??=new Promise(e=>{setTimeout(()=>{this._runBoot().catch(e=>{this.isClosed()||this._emitter.notify(`onError`,e)}).finally(e)},0)})}async _runBoot(){this._bootPending=null;let e=this._bootFull,t=this._bootExplicit;if(this._bootFull=!1,this._bootExplicit=!1,!this.isClosed()&&this._status===X.Status.Running)return e||t?(this._calcOwed=!1,this._calcOwedBy=null,void await this._calculate(e?JB:void 0)):void await this._drainStandalone()}_scheduleDrain(){this._drainScheduled||this._draining||this._status===X.Status.Running&&(this._bootPending||(this._drainScheduled=!0,this._noteCalculationState(),queueMicrotask(()=>{this._drainScheduled=!1,this._noteCalculationState(),this.isClosed()||this._status!==X.Status.Running||(this._pendingActions?.length||this._pendingPriority?.length||this._calcOwed)&&this._drainStandalone().catch(e=>{this.isClosed()||this._emitter.notify(`onError`,e)})})))}async _drainStandalone(){await this._drainPending();let e=this._calcOwedBy;this._calcOwed=!1,this._calcOwedBy=null,this.isClosed()||this._status!==X.Status.Running||this._getState().dirtySpatial.isEmpty()||(e||this._calcMode!==X.CalculationMode.Manual?await this._calculate(void 0,e??void 0):this._emitter.notify(`onStale`))}_owePass(e){this._calcOwed=!0,this._calcOwedBy??=e,this._scheduleDrain(),this._noteCalculationState()}async _drainPending(e=!1){this._drainDepth++,this._draining=!0;let t=this._namedFormulas;t?._beginWiringBatch();try{for(;this._pendingPriority?.length||!e&&this._pendingActions?.length;){let e=this._pendingPriority;if(e?.length){this._pendingPriority=null;for(let t of e)await t();continue}let t=this._pendingActions;this._pendingActions=null;for(let e of t)await e()}this._pendingPriority=null,e||(this._pendingActions=null)}finally{this._drainDepth--,this._draining=this._drainDepth>0,t?._endWiringBatch(),this._noteCalculationState()}this._drainDepth===0&&this._calcOwed&&this._scheduleDrain()}async calculate(e){let t;return!0===e?t=JB:e&&(t=e),this._calculate(t)}async _calculate(e,t){return this._calculateNow(e,t)}async _calculateNow(e,t){this._passesInFlight++,this._noteCalculationState();try{return await this._runCalculation(e,t)}finally{this._passesInFlight--,this._noteCalculationState()}}async _runCalculation(e,t){let n=this.getStatus();if(n===X.Status.Off||n===X.Status.Starting||this._bootPending)return!t&&e?.full?this._bootFull=!0:t?this._owePass(t):this._bootExplicit=!0,n===X.Status.Off?await this.start():n===X.Status.Starting?await this._statusTransition:await this._bootPending,this.getStatus();if(n!==X.Status.Running)return n;if(t&&this._draining)return this._calcOwed=!0,this._calcOwedBy??=t,n;if(this._pendingActions?.length&&await this._drainPending(),this.isClosed())return this._status;this._flushModel();let r=this._getState();if(t&&this._calcMode===X.CalculationMode.Manual)return r.dirtySpatial.isEmpty()||this._emitter.notify(`onStale`),n;let i,a=e?.full??r.isFullCalcRequired,o=e?.range;if(o){let e=this._options;e.getRange?i=e.getRange(o)?.getCoords():o?.rowStart===void 0?a=!0:i=o}let s=this._getTransactions().getCurrentCommit().getId();if(t&&!a&&!i&&s===this._calculatedEngineId&&r.dirtySpatial.isEmpty())return this.getStatus();this._calculatedEngineId=s;let c=this._modelStore?.getPendingTransaction()??null;this._calculatedCommitId=c?c.getId():this._mirroredId??s;let l=this._volatiles;this._volatiles=new Set;let u=++this._cycleId,d=this._calcExecutor.execute(u,{isFullCalc:a,calcCoords:i,gridId:t,scopeGridId:e?.scope,iterate:this._iterate?{maxIteration:this._maxIteration,maxChange:this._maxIterateChange}:null},{gridsAll:r.gridsAll,formulaSpatial:r.formulaSpatial,dirtySpatial:r.dirtySpatial,oldVolatiles:l});if(!d)return Promise.resolve(this.getStatus());let f=!a&&!i&&e?.scope&&r.gridsAll.has(e.scope)?e.scope:null,p=new di;f&&r.dirtySpatial.getSpatialAt(f)&&(p=r.dirtySpatial.clone(),p.getSpatialAt(f).clear()),this._amendState({precedentSpatial:d.precedentSpatial,dynamicByBlock:d.dynamicByBlock,dirtySpatial:p,isFullCalcRequired:!1},qB);for(let t of d.lastUpdates.values())t.done(u,e);return this.getStatus()}_processRestoreOrRevert(e,t){super._processRestoreOrRevert(e,t),e.gridMaps.forEach((t,n)=>{e.gridsAll.get(n)?._adoptMaps(t)}),this._formulaHosts.forEach(e=>{e._resync()})}_toStoredText(e,t){this._checkReady(),e.startsWith(`=`)&&(e=e.substring(1));let n=this._container,r=n.getSymbols().bind($.Sheet,t.scope);if(!r)throw Error(`'${t.scope}' not found.`);return n.createFormulaBlock(r,this._context,e,t.rowIndex,t.colIndex).getTextAt(t.rowIndex,t.colIndex)}_createFormulaHost(e){let t=this._container,n=e.id,r=this._fronts.get(n)??null;r&&!r._isLive()&&(r=null),r||(r=this._createCalcGrid({uuid:n,shadowOf:e.shadowOf,unanchored:e.unanchored,arrayFirstCell:e.arrayFirstCell,entireCoords:e.entireCoords,sizeOf:e.sizeOf,isOwned:!1}),r.addListeners({onComplete:(e,t)=>{this._formulaHosts.get(n)?._onComplete(t)}}));let i=new OL({id:n,grid:r,container:t,context:this._context,transactions:this._modelStore,onCalculated:e.onCalculated,onDispose:()=>{this._formulaHosts.get(n)===i&&this._formulaHosts.delete(n)}});return this._formulaHosts.set(n,i),i}async _evaluateOver(e){let{sheetGridId:t,coords:r,expression:i,authoredAt:a}=e,o=this._container;if(!this._fronts.has(t))throw Error(`'${t}' not found.`);let s=this._createFormulaHost({id:`once-${t}-${n.CommonUtils.uuidV4()}`,shadowOf:t,arrayFirstCell:e.arrayFirstCell,sizeOf:t});try{if(await s.setBody({coords:r,expression:i,authoredAt:a,scopeGridId:t}),this.isClosed())throw Error(`Calculation not started.`);await this._calculate({scope:s.getId()});let e=s.getValueGrid().clone();return new iW(o.getRuntime(),e,r,null,!1,!1,s.getBlankValueWithin(r))}finally{s.dispose()}}_createCalcGrid(e){let{isOwned:t,valuesAxis:r,getGrid:i,getEntireCoords:a,...o}=e,s=e.uuid||`gen`+n.CommonUtils.uuidV4(),c=e.sizeOf,l=e.entireCoords??null,u=new yL({backend:new qI({id:s,send:(e,t,n)=>this._sendRequest(e,t,n),calculation:this,getEntireCoords:a??(c===void 0?()=>l??MH:()=>this._fronts.get(c)?.getEntireCoords()??MH)}),calculation:this,runtime:this.getRuntime(),transactions:this._modelStore??void 0,valuesAxis:r,isOwned:t,getGrid:e=>this._fronts.get(e)??null});return this._fronts.set(s,u),this._gridSpecs.set(s,{id:s,shadowOf:o.shadowOf,unanchored:o.unanchored,arrayFirstCell:o.arrayFirstCell,sizeOf:c}),u.addListeners({onClose:()=>{this._fronts.get(s)===u&&(this._fronts.delete(s),this._gridSpecs.delete(s))}}),this._sendRequest(s,void 0,{type:`create`,spec:{...this._specOf(u),name:o.name}}),u}_specOf(e){let t=e.getId(),n={...this._gridSpecs.get(t),id:t};if(n.sizeOf===void 0){let t=e.getEntireCoords();n.entireCoords={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}return n}_createEngineGrid(e){let t=e.id,n=this._container,r=e.sizeOf,i=e.entireCoords,a=r===void 0?i?()=>i:void 0:()=>n.getGrid(r)?.getEntireCoords()??MH;return this._createBackendGrid({uuid:t,name:e.name,shadowOf:e.shadowOf,unanchored:e.unanchored,arrayFirstCell:e.arrayFirstCell,getEntireCoords:a,onCalculated:e=>{this._fronts.get(t)?._onCalculated(e)}})}_openEngineGrids(e){let t=[],n=[];this._fronts.forEach(e=>{e._isLive()&&(e._isOwned()?n:t).push(e)});let r=[...t,...n];for(let e=0;e<r.length;e++)this._sendRequest(r[e].getId(),void 0,{type:`create`,spec:this._specOf(r[e])});this._formulaHosts.forEach(e=>{e._restart()});for(let t=0;t<n.length;t++){let r=n[t]._seedContent();r&&n[t]._getBackend().seed(r,{full:e}).catch(e=>this._reportError(e))}}_dropEngine(){this._engineUp=!1,this._volatiles.clear(),this._amendState({gridsAll:new Map,gridMaps:new Map,formulaSpatial:new di({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),precedentSpatial:new di({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}}),dynamicByBlock:new Map,dirtySpatial:new di},qB)}_forgetEarlierLandings(e=this._mirroredId){if(this._engineIds.clear(),this._landingOf.clear(),this._lastRevert=null,e===null)return;let t=this._getTransactions().getCurrentCommit(!1).getId();this._engineIds.set(e,t),this._landingOf.set(t,e)}_followRestore(e){let t=this._status;if(t===X.Status.Off||t===X.Status.Error)return this._mirroredId=e,void(this._lastRevert=null);let n=this._engineIds.get(e);t!==X.Status.Running||n!==void 0&&this._holdsEngineCommit(n)?this._revertTo(e):(this._mirroredId=e,this._lastRevert=null,this._whenSafe(async()=>{this.isClosed()||this._status!==X.Status.Running||this._rebuildEngine()},!0))}_rebuildEngine(){this._dropEngine(),this._engineUp=!0;let e=this._liveSheets();this._amendState({sheets:new Map(e),tables:e.length>0?this._liveTables():new Map,names:this._liveNames()},qB),this._externalBindings?.sync(!0),this._openEngineGrids(!1),this._forgetEarlierLandings()}_reportError(e){this.isClosed()||this._emitter.notify(`onError`,e)}_createBackendGrid(e){let t=this._options,n=new XI({...t,...e,context:this._context,container:this._container,calculation:this}),r=this._getState(),i=new Map(r.gridsAll);i.set(n.getId(),n);let a=e?.name;if(a===void 0)this._amendState({gridsAll:i},qB);else{let e=new Map(r.sheets);e.set(n.getId(),a),this._amendState({gridsAll:i,sheets:e},qB)}return n}_registerGrid(e){let t=e.getId();this._unregisterGrid(t);let n=new Map(this._getState().gridsAll);n.set(t,e),this._amendState({gridsAll:n},qB)}_unregisterGrid(e){let t=new Map(this._getState().gridsAll);t.get(e),t.delete(e),this._amendState({gridsAll:t},qB)}_liveSheets(){let e=this._options,t=e.getSheetIds?.()??n.CommonUtils.EmptyArray,r=[];for(let n=0;n<t.length;n++){let i=e.getSheetById?.(t[n]);i&&r.push([t[n],i.getName()??null])}return r}_sendSheets(){let e=this._modelStore,t=e?e.getPendingTransaction()?.getId()??e.getCurrentCommit(!1).getId():void 0;this._sendRequest(``,void 0,{type:`sheets`,sheets:this._liveSheets(),options:{commitId:t}})}_applySheets(e){let t=this._getState().sheets,n=new Map;for(let t=0;t<e.length;t++)n.set(e[t][0],e[t][1]);let r=!1,i=0,a=Array.from(n.keys());for(let[e,o]of t){if(n.has(e)&&(n.get(e)!==o||a[i]!==e)){r=!0;break}i++}this._amendState({sheets:n},qB),r&&this.calculate(!0)}_liveTables(){let e=(this._options?.namedCollection)?.getItems({type:`table`})??n.CommonUtils.EmptyArray,t=new Map;for(let n=0;n<e.length;n++){let r=e[n],i=r.getValue();i&&!i.isDeleted()&&t.set(r.getId(),BB(i))}return t}_liveNames(){let e=new Map,t=this._namedFormulas?._namesAsWritten()??n.CommonUtils.EmptyArray;for(let n=0;n<t.length;n++)e.set(t[n].id,[t[n].name,t[n].scopeId]);return e}_tableChanged(e,t){let n=e.getNamed?.()?.getId();if(!n)return;let r=t||e.isDeleted()?null:BB(e);this._sendSymbolChange(`tables`,n,r,VB)}_nameWritten(e){let t=e.removed?null:[e.name,e.scopeId];this._sendSymbolChange(`names`,e.id,t,HB)}_sendSymbolChange(e,t,n,r){if(this.isClosed())return;let i=this._status;if(i!==X.Status.Running&&i!==X.Status.Starting||i===X.Status.Running&&r(this._getState()[e].get(t),n))return;let a=this._modelStore,o=a?a.getPendingTransaction()?.getId()??a.getCurrentCommit(!1).getId():void 0,s=[[t,n]];this._sendRequest(``,void 0,{type:e,changes:s,options:{commitId:o}})}_applyTables(e){let t=new Map(this._getState().tables);for(let n=0;n<e.length;n++){let[r,i]=e[n];i?t.set(r,i):t.delete(r)}this._amendState({tables:t},qB),this._markDirtyReconciled(this._tableSymbols)}_applyNames(e){let t=new Map(this._getState().names);for(let n=0;n<e.length;n++){let[r,i]=e[n];i?t.set(r,i):t.delete(r)}this._amendState({names:t},qB),this._markDirtyReconciled(this._nameSymbols)}_markDirtyReconciled(e){let t=e?.reconcile()??n.CommonUtils.EmptyArray;t.length!==0&&this._whenSafe(async()=>{this.isClosed()||this._markDirtyReferencing(new Set(t))})}_replicaTables(){if(this._status===X.Status.Off||this._status===X.Status.Error)return null;let e=this._getState()?.tables;if(!e)return null;let t=this._tablesDerived;if(!t||t.of!==e){let n=new Map;for(let[t,r]of e)n.set(r[0].toLowerCase(),t);t=this._tablesDerived={of:e,idByName:n}}return t}_replicaNames(){if(this._status===X.Status.Off||this._status===X.Status.Error)return null;let e=this._getState()?.names;if(!e)return null;let t=this._namesDerived;if(!t||t.of!==e){let n=new Map;for(let[t,r]of e){let e=r[0].toLowerCase(),i=n.get(e);i?i.push(t):n.set(e,[t])}t=this._namesDerived={of:e,idsByName:n}}return t}_replicaNameId(e,t){let n=this._replicaNames(),r=n?.idsByName.get(e.toLowerCase());if(!r)return;let i,a,o=null;t&&(o=this._getState().sheets.has(t)?t:this._sheetsCache().idByName.get(t.toLowerCase())??t);for(let e=0;e<r.length;e++){let t=n.of.get(r[e])[1];if(t!==null){if(o!==null&&t===o)return r[e];a??=r[e]}else i??=r[e]}return t?i:i??a}_modelSymbols(){return this._modelSymbolRegistry}_imagerFor(e){return this._container,{symbols:this._modelSymbolRegistry,gridId:e,getEntireCoords:()=>this._fronts.get(e)?.getEntireCoords()??MH,getDisplayLocale:()=>Wx(Bx(this._runtime.getLocaleProfile().decimal)),resolveTableReference:(n,r)=>this._resolvers?.getStructureReferenceCoords?.(n,r,0,e)??t.FormulaError.BuiltIn.Ref}}_sheetsCache(){let e=this._getState().sheets,t=this._sheetsDerived;if(!t||t.of!==e){let n=[],r=new Map;for(let[t,i]of e)n.push(t),i!==null&&r.set(i.toLowerCase(),t);t=this._sheetsDerived={of:e,ids:n,idByName:r}}return t}_sheetIds(){return this._sheetsCache().ids}_sheetIdByName(e){return this._sheetsCache().idByName.get(e.toLowerCase())??null}_sheetName(e){return this._getState().sheets.get(e)??null}async stop(){this._status===X.Status.Running&&(this._status=X.Status.Stopping,this._emitter.notify(`onStatusChange`),this._emitter.notify(`onStopping`),this._status=X.Status.Off,this._dropEngine(),this._emitter.notify(`onStatusChange`),this._emitter.notify(`onStop`),this._noteCalculationState())}close(){if(!this.isClosed()){this.stop(),this._modelStoreRemoveListener?.(),this._modelStoreRemoveListener=null,this._mirrorRemoveListener?.(),this._mirrorRemoveListener=null,this._externalBooks?.close();for(let e of Array.from(this._fronts.values()))e.close();super.close()}}_flushModel(){this._modelStore&&this._modelMirrorId&&this._modelStore.getState(this._modelMirrorId)}_landUnder(e,t){if(e??=this._modelLanding()??void 0,e===void 0)return t();let n=this._getTransactions(),r=n.getCurrentCommit(!1).getId();if(this._engineIds.has(e)||e===r||n.getPendingTransaction()!==null)return n.amend(r,t);let i=n.beginCommit(),a;try{a=t(),i.commit()}catch(e){throw i.rollback(),e}let o=n.getCurrentCommit(!1).getId();return this._engineIds.set(e,o),o!==r&&this._landingOf.set(o,e),a}_holdsEngineCommit(e){return this._getTransactions().getStateAt(e,this._id)!==void 0}_mirror(e){if(this.isClosed())return;let t=this._getTransactions();if(t.getPendingTransaction()===null){let n=t.beginCommit();n.updateState(this._id,{...this._getState(),mirrorOf:e}),n.commit()}let n=t.getCurrentCommit(!1).getId();this._engineIds.set(e,n),this._landingOf.get(n)===void 0&&this._landingOf.set(n,e),this._mirroredId=e,this._engineIds.size>2*WB&&this._sweepLandings()}_dropLanding(e){let t=this._engineIds.get(e);t!==void 0&&(this._engineIds.delete(e),this._landingOf.get(t)===e&&this._landingOf.delete(t))}_sweepLandings(){let e=this._getTransactions(),t=new Set,n=e.getLog(e.getTipCommit().getId(),2**53-1);for(let e=0;e<n.length;e++)t.add(n[e].getId());this._engineIds.forEach((e,n)=>{t.has(e)||this._engineIds.delete(n)}),this._landingOf.forEach((e,n)=>{t.has(n)||this._landingOf.delete(n)})}_modelHistory(){let e=new Set,t=this._modelStore;if(!t)return e;let n=t.getLog(t.getCurrentCommit(!1).getId(),2**53-1);for(let t=0;t<n.length;t++)e.add(n[t].getId());return e}_foldPhantom(e){let t=this._getTransactions(),n=`${e}:`,r=(e,t)=>{let n={...e,...t},r=e?.[GB],i=t?.[GB];if(r&&i){let e={...r};for(let t of Object.keys(i))e[t]=[...e[t]??[],...i[t]];n[GB]=e}return n};for(;;){let e=t.getTipCommit().getId(),i=this._landingOf.get(e);if(i===void 0||!i.startsWith(n)||!t._squashTip(r))break;this._landingOf.delete(e),this._engineIds.delete(i)}this._engineIds.delete(`${e}:0`),this._lastRevert=null}_modelLanding(){let e=this._modelStore;if(!e||this._getTransactions().getPendingTransaction()!==null)return null;let t=e.getCurrentTransaction();if(!t)return null;let n=t.getSavepointId(),r=t.getId();return n===r?`${r}:0`:n}_updateState(e,t,n){return this._amendState(e,t,n)}_amendState(e,t,n){let r=this._modelLanding();return r===null?super._amendState(e,t,n):this._landUnder(r,()=>super._amendState(e,t,n))}_revertTo(e){let t=this._getTransactions(),n=this._engineIds.get(e);if(n===void 0)return null;if(!this._holdsEngineCommit(n))return this._dropLanding(e),null;let r=t.getCurrentCommit(!1).getId(),i=this._lastRevert;if(i&&i.commitId===e&&r===n)return i.regions;if(r===n)return this._mirroredId=e,null;let a=(e,n)=>{let r=t.getLog(e,2**53-1),i=[];for(let e=0;e<r.length;e++){if(r[e].getId()===n)return i;i.push(r[e])}return null},o=a(r,n)??a(n,r),s=new Map;if(o)for(let e=0;e<o.length;e++){let t=o[e].getIntents()?.[GB];if(t)for(let e of Object.keys(t))s.set(e,[...s.get(e)??[],...t[e]])}t.restore(n),this._mirroredId=e,this._lastRevert={commitId:e,regions:s};let c=[];return s.forEach((e,t)=>{for(let n=0;n<e.length;n++)c.push({...e[n],scope:t})}),c.length>0&&this._container.markDirty(c),s}_hookRollback(e){let t=this._modelStore;if(!t||e.endsWith(`:0`))return;let n=t.getCurrentTransaction();if(!n||n.getDepth()===0||n.getSavepointId()!==e)return;let r=this._rollbackHooked??=new Set;r.has(e)||(r.add(e),t.beginCommit({savepoint:!1,onCommit:()=>{r.delete(e)},onRollback:()=>{r.delete(e),this.isClosed()||this._sendRequest(``,void 0,{type:`rollback`,savepointId:e})}}).commit())}_savepointRolledBack(e){let t=this._getTransactions(),n=this._engineIds.get(e);if(n===void 0||(this._engineIds.delete(e),this._landingOf.get(n)!==e))return;if(t.getCurrentCommit(!1).getId()!==n)return void console.warn(`a rolled-back savepoint is not the engine's latest commit`,e);let r=t.getCurrentCommit(!1).getIntents()?.[GB];if(t.revert(n),this._landingOf.delete(n),this._lastRevert=null,!r)return;let i=[];for(let e of Object.keys(r)){let t=r[e];for(let n=0;n<t.length;n++)i.push({...t[n],scope:e})}i.length>0&&this._container.markDirty(i)}getStatus(){return this._status}_whenRequestsSettled(){let e=this._outstanding;return e&&e.size!==0?Promise.allSettled(Array.from(e)).then(()=>this._whenRequestsSettled()):Promise.resolve()}getCalculationMode(){return this._calcMode}setCalculationMode(e){if(!KB.has(e))throw Error(`Invalid calculation mode: '${e}'.`);if(e===this._calcMode)return this;let t=this._calcMode===X.CalculationMode.Manual;return this._calcMode=e,this._emitter.notify(`onOptionsChange`),this._noteCalculationState(),t&&this.isCalculationRequired()&&this.calculate(),this}isCalculationRequired(){return!this._getState().dirtySpatial.isEmpty()}getIterativeCalculation(){return{enabled:this._iterate,maxIteration:this._maxIteration,maxChange:this._maxIterateChange}}setIterativeCalculation(e){let t=typeof e==`boolean`?{enabled:e}:e??{},n=t.enabled??this._iterate,r=Math.max(1,Math.floor(t.maxIteration??this._maxIteration))||1,i=Math.max(0,t.maxChange??this._maxIterateChange)||0;if(n===this._iterate&&r===this._maxIteration&&i===this._maxIterateChange)return this;if(this._iterate=n,this._maxIteration=r,this._maxIterateChange=i,this._emitter.notify(`onOptionsChange`),this._status===X.Status.Running){let e=this._calcExecutor.getCycleCells();e.length>0&&this._container.markDirty(e),this.calculate()}return this}toJSON(){let e={...this._calcJSON??{}};return this._calcMode===X.CalculationMode.Automatic?delete e.calcMode:e.calcMode=this._calcMode,this._iterate?e.iterate=!0:delete e.iterate,this._maxIteration===100?delete e.maxIteration:e.maxIteration=this._maxIteration,delete e.maxIterations,this._maxIterateChange===.001?delete e.maxIterateChange:e.maxIterateChange=this._maxIterateChange,e}async ready(e){if(this._status===X.Status.Error)return this._status;let t=typeof e==`boolean`?e:e?.full??!1;for(;await this._readyPass(t),t=!1,await this._whenRequestsSettled(),!this.isClosed()&&this._status===X.Status.Running&&this._isWorking();)await new Promise(e=>{(this._calculationStateWaiters??=[]).push(e)});return UB}async _readyPass(e){if(this._status===X.Status.Off?await this.start():this._status===X.Status.Starting?await this._statusTransition:this._bootPending&&await this._bootPending,this._pendingActions?.length&&await this._drainPending(),this._calcMode===X.CalculationMode.Manual)return;this._flushModel();let t=this._getState(),n=t.gridsAll,r=e?n.keys():t.dirtySpatial.getScopeKeys(),i=[];for(let e of r){let t=n.get(e);t&&i.push(t._calculateNow())}await Promise.all(i)}getCalculationState(){let e=this._status;return e===X.Status.Starting?X.CalculationState.Calculating:e!==X.Status.Running||this.isClosed()?X.CalculationState.Done:this._isWorking()?X.CalculationState.Calculating:this._getState().dirtySpatial.isEmpty()?X.CalculationState.Done:this._calcMode===X.CalculationMode.Manual?X.CalculationState.Pending:X.CalculationState.Calculating}_isWorking(){return(this._outstanding?.size??0)>0||this._drainScheduled||this._draining||!!this._pendingActions?.length||!!this._pendingPriority?.length||this._calcOwed||this._passesInFlight>0||this._bootPending!==null}_noteCalculationState(){this._calculationStatePosted||(this._calculationStatePosted=!0,queueMicrotask(()=>{this._calculationStatePosted=!1;let e=this._calculationStateWaiters;if(this._calculationStateWaiters=null,!this.isClosed()){let e=this.getCalculationState();e!==this._calculationState&&(this._calculationState=e,this._emitter.notify(`onCalculationStateChange`))}e?.forEach(e=>e())}))}_getEditingCompiler(e=`display`){let t=this._compilerModule;if(!t)throw Error(`Calculation not started.`);if(e===`storage`)return this._compilerEditingStorage??=new t.FormulaCompiler({profile:`editing`}),this._compilerEditingStorage;let n=Bx(this._runtime.getLocaleProfile().decimal),r=Wx(n),i=r.specifiers,a=i?`${i.all},${i.data},${i.headers},${i.totals},${i.thisRow}`:``,o=`${n.separatorDecimal}|${n.separatorFunction}|${n.separatorRow}|${r.booleanTrue}|${r.booleanFalse}|${r.errorLiterals.join(`,`)}|${r.errorRefs.join(`,`)}|${a}`;if(!this._compilerEditing||this._compilerEditingSig!==o){let e={locale:r};this._compilerEditing=new t.FormulaCompiler({profile:`editing`,lexerOptions:e}),this._compilerEditingSig=o}return this._compilerEditing}createFormula(e,t,n){return this._createFormula(e,t,n?.target??`storage`)}_createFormula(e,t,r){this._checkReady(),e.startsWith?.(`=`)&&(e=e.substring(1));let i=this._container,a=this._context,o=null,s=0,c=0,l=this._getActiveCell()?.scope??null,u=null;if(t)o=t.scope,s=t.colIndex??0,c=t.rowIndex??0,o&&(l=i.getSymbols().bind($.Sheet,o));else{u=l,l=`temporary`;let e=i.getGrid(l);e||(e=this._createBackendGrid({context:a,container:i,calculation:this,uuid:l}),this._registerGrid(e))}let d=this._getState().gridsAll.get(l);if(!d)throw Error(`'${o}' not found.`);let f=i.getScope(),p;f.colIndex=s,f.rowIndex=c,f.gridId=l,p=u?i.createFormulaBlock(u,a,e,c,s,r):i.createFormulaBlock(l,a,e,c,s,r);let m=new dI(n.CoordUtils.EmptyRange,l,p,i,!0);return new iM({colIndex:s,rowIndex:c},p,{...this._options,getRange:this._getRange,getRanges:this._getRanges,getCalcGrid:()=>d,resolveSheetScope:e=>this._sheetName(e),getOwnScope:()=>this._sheetName(l),inputTarget:r,autoCorrect:e=>{let n=this._getEditingCompiler(r).autoCorrect(e);if(n===null)return null;let i=this._createFormula(n,t,r);return i.isValid()?i:null},createAt:(e,n)=>this._createFormula(e,{scope:t?.scope,rowIndex:n.rowIndex,colIndex:n.colIndex},r)},async(t,n)=>{await this.ready();let r=m.getAnchorNode();f.colIndex=s,f.rowIndex=c,f.gridId=l,r.gridId=l,r.colIndex=s,r.rowIndex=c,f.node=r;let i=typeof n==`number`?void 0:n,o=typeof n==`number`?n:n?.evalIndex,d=i?.block;if(d){let t=await this._evaluateOver({sheetGridId:u??l,coords:d,expression:e,authoredAt:{rowIndex:c,colIndex:s},arrayFirstCell:!0===i?.arrayFirstCell});return t.getRowCount()!==1||t.getColumnCount()!==1||i?.alwaysReturnRange?t:t.getValueAt(0,0)??0}let p=t.evaluateAt(c,s,o),h=t.finalizeValue(p);return h===null&&(h=0),!i?.alwaysReturnRange||h?.isIRange||Array.isArray(h)?h:a.createRange(1,1,h)})}async evaluate(e,t){let n,r,i;if(await this.ready(),typeof t==`number`)n=t;else if(t){let{target:e,...a}=t;i=e,n=a,r=Object.keys(a).length>0?a:void 0}return this.createFormula(e,r,{target:i}).evaluate(n)}getFunctions(){return this._checkReady(),this._functions}getExternalBooks(){return this._externalBooks}getNamedFormulas(){return this._namedFormulas}hydrateNames(){let e=this._pendingNames;e&&(this._pendingNames=null,this._namedFormulas.hydrate(e))}getRuntime(){return this._runtime}_checkReady(){if(this._status!==X.Status.Running)throw Error(this._statusMessage())}_statusMessage(){switch(this._status){case X.Status.Off:return`Calculation is off`;case X.Status.Error:return`Calculation failed to start`;case X.Status.Starting:return`Calculation is starting`;case X.Status.Stopping:return`Calculation is stopping`;case X.Status.Running:return`Calculation is running`;default:return`Unknown calculation status`}}get[Symbol.toStringTag](){return`[Calculation]`}toString(){return`Calculation`}get isICalculation(){return!0}},zB=new Set([`seed`,`snapshot`,`rollback`,`calculate`,`markDirty`,`revert`,`close`,`create`,`resize`,`graph`,`isVolatile`]),BB=e=>{let t=e.getColumns(),n=Array(t.length);for(let e=0;e<t.length;e++)n[e]=[String(t[e].getId()),t[e].getName()??``];return[e.getName(),n]},VB=(e,t)=>{if(!e||!t)return!e&&!t;if(e[0]!==t[0]||e[1].length!==t[1].length)return!1;for(let n=0;n<e[1].length;n++)if(e[1][n][0]!==t[1][n][0]||e[1][n][1]!==t[1][n][1])return!1;return!0},HB=(e,t)=>e&&t?e[0]===t[0]&&e[1]===t[1]:!e&&!t,UB=Promise.resolve(X.Status.Running),WB=4e3,GB=`calc.touched`,KB=new Set(Object.values(X.CalculationMode)),qB=Object.freeze({description:(0,n.messageKey)(`op.updateCalculations`)}),JB=Object.freeze({full:!0}),YB=e=>{if(typeof e==`string`)return`'${e}'`;try{return JSON.stringify(e)}catch{return String(e)}},XB=(e,t)=>{if(!e)return null;let n={colStart:Math.max(e.colStart,t.colStart),rowStart:Math.max(e.rowStart,t.rowStart),colEnd:Math.min(e.colEnd,t.colEnd),rowEnd:Math.min(e.rowEnd,t.rowEnd)};return n.rowStart>n.rowEnd||n.colStart>n.colEnd?null:n},ZB=(e,t)=>{if(!e?.xml)return null;let n={xml:e.xml},r=e.images;if(r){let e=[];for(let n=0;n<r.length;n++){let i=t(r[n].resId);i&&e.push({id:r[n].id,resource:i})}e.length>0&&(n.images=e)}return n},QB=(e,t)=>{if(!e)return null;let n={xml:e.xml},r=e.images;return r&&r.length>0&&(n.images=r.map(e=>({id:e.id,resId:t(e.resource)??0}))),n},$B=class e{_getInternal(){return this._internal}_getReadCtx(){if(!this._readCtx){let e=this;this._readCtx={get state(){return e._getState()},get rowHeaders(){return e._rowHeaders},get columnHeaders(){return e._colHeaders},get cellOptions(){return e._cellOptions},get strings(){return e._strings},get lists(){return e._lists},getEntireCoords:this._getEntireCoords.bind(this),getUsedCoords:this._getUsedCoords.bind(this),get calcGrid(){return e._calcGrid}}}return this._readCtx}_getMutationCtx(){return this._mutationCtx||=this._buildMutationCtx(),this._mutationCtx}_buildMutationCtx(){let e=this;return{get rowHeaders(){return e._rowHeaders},get columnHeaders(){return e._colHeaders},get rowHeadersShiftCallback(){return e._rowHeadersShiftCallback},get columnHeadersShiftCallback(){return e._colHeadersShiftCallback},getEntireCoords:this._getEntireCoords.bind(this),getView:this.getView.bind(this),beginCommit:this._beginCommit.bind(this),updateState:this._updateState.bind(this),getState:this._getState.bind(this),stateFor:e=>e.getState(this._stateId),get calcGrid(){return e._calcGrid},invalidateUsedCoords:()=>{e._lastUsedCoordsRead.coords=null},validateCoords:this._validateCoords.bind(this),protectionCheck:this._protectionCheck.bind(this),getDefaultShiftAxis:this._getDefaultShiftAxis.bind(this),processLayoutChange:this._processLayoutChange.bind(this),takeShiftedMovableModels:()=>{let t=e._shiftedMovableModels;return e._shiftedMovableModels=null,t},takeShiftedNoteModels:()=>{let t=e._shiftedNoteModels;return e._shiftedNoteModels=null,t},markColumnHeaderTableNames:this._markColumnHeaderTableNames.bind(this),commitWithDirectives:this._commitWithDirectives.bind(this),get styles(){return e._styles},getRangedEntries:this._getRangedEntries.bind(this),createSparseBuilder:this._createSparseBuilder.bind(this),composeDirectStyleView:this._composeDirectStyleView.bind(this),autoFit:this._autoFit.bind(this),recordAutoFormat:this._recordAutoFormat.bind(this),recordSkipProtectionCheck:this._recordSkipProtectionCheck.bind(this),recordFreezePanes:this._recordFreezePanes.bind(this),recordSelection:this._recordSelection.bind(this),notify:this._notify.bind(this),getRange:this.getRange.bind(this),getSelection:this.getSelection.bind(this),getMerges:this._getMerges.bind(this),indexMerges:this._indexMerges.bind(this),validateOrRemoveOverlaps:this._validateOrRemoveOverlaps.bind(this),autoSelect:this._autoSelect.bind(this),get isDataColumn(){return e._isDataColumn},get strings(){return e._strings},get lists(){return e._lists},get cellOptions(){return e._cellOptions},get runtime(){return e._runtime},getProtection:this.getProtection.bind(this),hasRangedEntries:this._hasRangedEntries.bind(this),rangeStateIterator:this._rangeStateIterator.bind(this),recordChange:this._recordChange.bind(this),loadComments:(t,n)=>e._createComments(t,`comments`,n,e=>new yj(e)),newCommentJSON:this._newCommentJSON.bind(this),notifyCommentsChange:this._notifyCommentsChange.bind(this),recordFormulasEntered:this._recordFormulasEntered.bind(this),getTables:this.getTables.bind(this),getAutoTable:this.getAutoTable.bind(this),cellIterator:this._cellIterator.bind(this),cellStateIterator:this._cellStateIterator.bind(this),rangeToCoords:this._rangeToCoords.bind(this),getCell:this.getCell.bind(this),createCell:this.createCell.bind(this),getAutoFillPreviewCache:()=>e._autoFillPreviewCache,setAutoFillPreviewCache:t=>{e._autoFillPreviewCache=t}}}_getCoordCtx(){return this._coordCtx||=this._buildCoordCtx(),this._coordCtx}_buildCoordCtx(){let e=this;return{get internal(){return e._internal},get readonly(){return e._options.readonly??!1},get isClosed(){return e._closed},get isInitializing(){return e._initializing},get lastCellDecoded(){return e._lastCellDecoded},getEntireCoords:this._getEntireCoords.bind(this),getNamedFormulas:()=>e._calculation?.getNamedFormulas(),getNames:this.getNames.bind(this),getProtection:this.getProtection.bind(this),getName:this.getName.bind(this),resolveRange:t=>e._options.resolveRange?.(t)}}constructor(e){this._selectionAtCommitStart=null,this._initializing=!0,this._starting=null,this._legacyDrawing=null,this._legacyDrawingHF=null,this._pivotTables=[],this._pivotTableCollection=new fA(()=>this._pivotTables.slice()),this._announcedDeletes=new WeakSet,this._namesScoped=null,this._listenerNodes=new Map,this._lastCellDecoded={address:null,coords:null},this._lastCellSelected={coords:null,cell:null},this._lastCellRead={coords:null,cell:null},this._lastValueRead={range:null,isDateOrTime:null},this._lastGetRangeRead={},this._lastUsedCoordsRead={coords:null,range:null},this._lastRangeRead={address:null,range:null,ranges:null},this._isDataColumn=!0,this._codeName=null,this._outlineSettings=fV,this._conditionalFormatCalculation=!0,this._isDate1904=!1,this._colHeaders=null,this._colHeadersShiftCallback=null,this._colHeadersListener=null,this._colHeadersRemoveListener=null,this._colHeadersHiddenRemoveListener=null,this._rowHeaders=null,this._rowHeadersShiftCallback=null,this._rowHeadersListener=null,this._rowHeadersRemoveListener=null,this._rowHeadersHiddenRemoveListener=null,this._isAdjustHeaders=!1,this._shiftedMovableModels=null,this._shiftedNoteModels=null,this._closed=!1,this._cellBuffer=null,this._internal={getSheet:()=>this,getState:this._getState.bind(this),getCalcGrid:()=>this._calcGrid,isDataColumn:()=>this._isDataColumn,createRange:this._createRange.bind(this),isContentful:this._isContentful.bind(this),cellToCoords:this._cellToCoords.bind(this),rangeToCoords:this._rangeToCoords.bind(this),rangesToCoords:this._rangesToCoords.bind(this),validateCoords:this._validateCoords.bind(this),getScalar:this._getScalar.bind(this),getCellAt:this._getCellAt.bind(this),cellIterator:this._cellIterator.bind(this),getVisible:this._getVisible.bind(this),getUsedCoords:this._getUsedCoords.bind(this),updateTuples:this._updateTuples.bind(this),merge:this._merge.bind(this),unmerge:this._unmerge.bind(this),getMerges:this._getMerges.bind(this),insertFrom:this._insertFrom.bind(this),canInsertFrom:this._canInsertFrom.bind(this),insertCells:this._insertCells.bind(this),deleteCells:this._deleteCells.bind(this),getStyle:this._getStyle.bind(this),updateStyles:this._updateStyles.bind(this),getSnapshot:this._getSnapshot.bind(this),getRangeStats:this._getRangeStats.bind(this),getDefaultShiftAxis:this._getDefaultShiftAxis.bind(this),getDefaultSortCriteria:this._getDefaultSortCriteria.bind(this),getDefaultAutoFillCriteria:this._getDefaultAutoFillCriteria.bind(this),find:this._find.bind(this),copyFrom:this._copyFrom.bind(this),contentCounts:this._contentCounts.bind(this),featureCounts:this._featureCounts.bind(this),featureRegions:this._featureRegions.bind(this),dependencyRanges:this._dependencyRanges.bind(this),clear:this._clear.bind(this),calculate:this._calculate.bind(this),autoSelect:this._autoSelect.bind(this),beginCommit:this._beginCommit.bind(this),recordSelection:this._recordSelection.bind(this),commitWithDirectives:this._commitWithDirectives.bind(this),autoFit:this._autoFit.bind(this),getBestFit:this._getBestFit.bind(this),invalidateRendering:this._invalidateRendering.bind(this),addListenerNode:this._addListenerNode.bind(this),addWatch:this._addWatch.bind(this),surroundingRegion:this._surroundingRegion.bind(this),getTraverseRegion:this._getTraverseRegion.bind(this),sort:this._sort.bind(this),filter:this._filter.bind(this),evalFilter:this._evalFilter.bind(this),applyFilterRuns:this._applyFilterRuns.bind(this),filteredTables:this._filteredTables.bind(this),setHyperlinks:this._setHyperlinks.bind(this),setComments:this._setComments.bind(this),getBoundsAtCoords:this._getBoundsAtCoords.bind(this),extendRange:this._extendRange.bind(this),createTupleBuilder:e=>this._createTupleBuilder(e),createSparseBuilder:this._createSparseBuilder.bind(this),autoFill:this._autoFill.bind(this),autoFillRange:this._autoFillRange.bind(this)},this._readCtx=null,this._ownsCalcGrid=!0,this._mutationCtx=null,this._autoFillPreviewCache=null,this._coordCtx=null;let t=Object.freeze({...e}),r=e?.container?.getName?.();this._id=(r?r+`-`:``)+n.CommonUtils.uuidV4(),Y_._validate(!0),this._transactions=t.transactions??new g,this._ownTransactions=!t.transactions,this._stateId=this._transactions.create();let i=this,a=this._beginCommit({description:(0,n.messageKey)(`op.newSheet`)});try{this._strings=t.strings??new rv,this._ownStrings=!t.strings,this._lists=new Mj(this._strings);let e=t.styles??new ag;this._styles=e,this._ownStyles=!t.styles,this._namedTableSource=new bv({getSheets:()=>[i]}),this._names=t.names??new xk({addressToRanges:e=>i.getRanges(e),getCurrentScope:()=>i.getName(),isReadOnly:()=>i._options.readonly??!1,transactions:i._transactions,getSources:()=>i._calculation?[i._calculation.getNamedFormulas(),i._namedTableSource]:n.CommonUtils.EmptyArray}),this._ownNames=!t.names,this._namesRemoveListener=this._names.addListeners({onCollectionChange:e=>{i._calculateFull()}},{transactional:!1}),this._runtime=t.runtime??new vt(`Sheet Runtime`,{isDate1904:()=>this._isDate1904,getNow:()=>this._transactions.getCurrentCommit().getTimestamp()}),this._calculation=t.calculation,this._ownCalculation=!t.calculation;let r=e=>{let t=i.getName();return typeof t==`string`&&t.toUpperCase()===e.toUpperCase()};this._calculation||=new RB({runtime:i._runtime,functions:t.functions,getActiveCell:()=>{let e=i.getSelectedRange()?.getCoords();return e?{rowIndex:e.rowStart,colIndex:e.colStart,scope:i.getId()}:null},getRange:i.getRange.bind(i),getRanges:i.getRanges.bind(i),getSheetIndex:e=>e===void 0||r(e)?0:-1,getSheetCount:()=>1,getSheetById:e=>this.getId()===e?this:null,namedCollection:i.getNames(),strings:i._strings,transactions:i._transactions}),this._workbook=t.workbook??null,this._normalStyleRanged=e.getNamedStyles().getByName(q.BuiltInName.Normal).getRanged(),this._resources=t.resources??new nv,this._ownResources=!t.resources;let o=t.calcOnLoad??`auto`,s=!1,c=(async()=>{try{if(this._ownCalculation&&o!==`none`&&(o===`full`?await this._calculation.calculate({full:!0}):await this._calculation.start(),this._closed))return}finally{s=!0,this._starting=null}})();s||(this._starting=c),this._starting?.catch(()=>{}),t.container?.setNameChangeCallback&&t.container.setNameChangeCallback(()=>{i._notify(`onNameChange`);let e=this._beginCommit({description:(0,n.messageKey)(`op.setName`)});e.updateState(i._stateId,{}),i._recordChange(e,`sheets`,[i._getEntireCoords()]),e.amend()}),t.container?.setVisibilityCallback&&t.container.setVisibilityCallback(()=>{i._notify(`onVisibilityChange`)}),t.container?.setIndexCallback&&t.container.setIndexCallback(()=>{i._notify(`onIndexChange`)}),this._modules=new zO({transactions:this._transactions,isReadOnly:()=>this._isModulesReadOnly()}),this._placedIndex={spatial:`movableSpatial`,byModel:`movableMapModel`,zIndexBase:()=>0,create:e=>new pk(e)},this._noteIndex={spatial:`noteSpatial`,byModel:`noteMapModel`,zIndexBase:()=>i._getState()?.movableSpatial.size()??0,create:e=>new Dj(e)},this._noteBoxes={add:(e,t,n)=>i._addNoteBox(e,t,n),isDefault:(e,t)=>{let n=t.getBounds();if(!n)return!1;let r=e.getRange().getCoords();return a=n,o=hj({rowIndex:r.rowStart,colIndex:r.colStart},i._noteLayout()),Math.abs(a.x-o.x)<=1&&Math.abs(a.y-o.y)<=1&&Math.abs(a.x+a.width-(o.x+o.width))<=1&&Math.abs(a.y+a.height-(o.y+o.height))<=1;var a,o}},this._movables=new gk(this._addMovable.bind(this),this._searchMovables.bind(this),()=>{let e=i._getState();return e?(e.movableMapModel?.size??0)+(e.noteMapModel?.size??0):0},this._updateSelectedMovables.bind(this),(e,t)=>this._emitterMovables.addListeners(e,t),this._addMovablePicture.bind(this)),this._emitterMovables=new x(this._movables,this._transactions),this._charts=new vk(this._movables),this._tables=new CA(this._addTable.bind(this),this._getTables.bind(this),e=>{let t=i._getState();return t?t.tables.getByName(e):null},this._forwardCollectionListeners(`onTablesChange`,()=>this._tables)),this._dataValidations=new ej(this._addDataValidation.bind(this),(e,t,r)=>{let a=e?this._rangeToCoords(e):this._getEntireCoords(),o=i._getState();return o?i._getRangedEntries(o.dataValidations,[a],{ignoreHidden:t,fullyContained:r},!0):n.CommonUtils.EmptyArray},e=>{let t=[{r:e?.getRanges().getCoords()??this.getSelectedRanges().getCoords(),v:e?.toJSON()??{}}],n=i._getState().dataValidations.clone(),r;return i._createDataValidations(n,`dataValidations`,t,e=>(r=new XA({...e,transactions:null,setContainerCallbacks:null,setContainerCoords:null,setContainerName:null,setContainerIndex:null,isProtected:null,invalidate:null}),r)),r},this._forwardCollectionListeners(`onDataValidationsChange`,()=>this._dataValidations)),this._conditionals=new YA(this._addConditionalFormat.bind(this),(e,t,r)=>{let a=e?this._rangeToCoords(e):this._getEntireCoords(),o=i._getState();return o?i._getRangedEntries(o.conditionalFormats,[a],{ignoreHidden:t,fullyContained:r},!0):n.CommonUtils.EmptyArray},e=>{let t=[{r:e?.getRanges().getCoords()??this.getSelectedRanges().getCoords(),v:e?.toJSON()??{condition:{operator:Y.BuiltInOperatorNames.Between,param:null}}}],n=i._getState().conditionalFormats.clone(),r;return i._createConditionalFormats(n,`conditionalFormats`,t,e=>(r=new IA({...e,transactions:null,setContainerCallbacks:null,setContainerCoords:null,setContainerName:null,setContainerIndex:null,isProtected:null,invalidate:null}),r)),r},this._forwardCollectionListeners(`onConditionalFormatsChange`,()=>this._conditionals)),this._protectedRanges=new rj(this._addProtectedRange.bind(this),(e,t,r)=>{let a=e?this._rangeToCoords(e):this._getEntireCoords(),o=i._getState();return o?i._getRangedEntries(o.protectedRanges,[a],{ignoreHidden:t,fullyContained:r},!0):n.CommonUtils.EmptyArray},e=>{let t=i._getState();return t?t.protectedRanges.getByName(e):null},e=>{let t=[{r:e?.getRanges().getCoords()??this.getSelectedRanges().getCoords(),v:e?.toJSON()??{name:i._nextProtectedRangeName()}}],n=i._getState().protectedRanges.clone(),r;return i._createProtectedRanges(n,`protectedRanges`,t,e=>(r=new tj({...e,transactions:null,setContainerCallbacks:null,setContainerCoords:null,setContainerName:null,setContainerIndex:null,isProtected:null,invalidate:null}),r)),r},this._forwardCollectionListeners(`onProtectedRangesChange`,()=>this._protectedRanges)),this._comments=new Ej(this._addComment.bind(this),(e,t,r)=>{let a=e?this._rangeToCoords(e):this._getEntireCoords(),o=i._getState();return o?i._getRangedEntries(o.comments,[a],{ignoreHidden:t,fullyContained:r},!0):n.CommonUtils.EmptyArray},this._forwardCollectionListeners(`onCommentsChange`,()=>this._comments)),this._options=t,this._emitter=new x(this,this._transactions),this._view=new ZR({sheet:this}),this._initListenerState(),t?.container?.beforeFromJSON?.(this),this._fromJSON(t?.json,t.disableLoadAutoFit),this._recordInitial(a),this._ownTransactions?a.amend():a.commit()}catch(e){throw a.rollback(),e}this._initializing=!1}_createRange(e,t,r=null){return function(e,t,r,i=null){if(typeof t==`string`){let a=t,o=e.getNamedFormulas()?.getById?.(a),s=o?.getName()??a,c=(o?.isReferenceOnly?.()?o.getReferences()?.at(0)?.getCoords():null)??e.getEntireCoords();i===null&&e.readonly&&(i=(0,n.messageKey)(`error.sheet.readonlyRange`));let l=null;return(r||i)&&(l={getOptions:r,readOnly:i}),new Yj(a,s,c,e.internal,l,o?()=>o.getRanges():null)}if(!t)return XV(e.internal.getSheet(),e.getEntireCoords());if(HR(e,t),e.isClosed)return XV(null,e.getEntireCoords(),t);i===null&&e.readonly&&(i=(0,n.messageKey)(`error.sheet.readonlyRange`));let a=null;(r||i)&&(a={getOptions:r,readOnly:i});let o=JV(t,e.internal.getSheet()),s=qV(e.internal,o.scope);return s?new Kj(function(e){if(!e)return null;let t={colStart:e.colIndex??e.colStart??0,rowStart:e.rowIndex??e.rowStart??0,colEnd:e.colIndex??e.colEnd??0,rowEnd:e.rowIndex??e.rowEnd??0};return e.scope&&(t.scope=e.scope),(e.$colStart||e.$colIndex)&&(t.$colStart=!0),(e.$colEnd||e.$colIndex)&&(t.$colEnd=!0),(e.$rowStart||e.$rowIndex)&&(t.$rowStart=!0),(e.$rowEnd||e.$rowIndex)&&(t.$rowEnd=!0),t}(o),s,a):XV(e.internal.getSheet(),e.getEntireCoords(),t)}(this._getCoordCtx(),e,t,r)}_createRanges(e,t,n=null){return VR(this._getCoordCtx(),e,t,n)}getRange(e,t){if(e===void 0)return this.getSelectedRange(t);let r=e?.scope;r!==void 0&&r!==this.getName()&&console.warn(`Sheet.getRange(${YB(e)}) called with a scope (${r}) that does not match this sheet (${this.getName()}).`,e);let i=!t&&e&&(e.rowStart!==void 0||typeof e==`string`&&tV.test(e));if(i){if(typeof e==`string`){if(this._lastRangeRead.address===e)return this._lastRangeRead.range}else if(e.rowStart!==void 0&&gH(e,this._lastRangeRead.address))return this._lastRangeRead.range}try{let r=this._rangesToCoords(e);if(r.length>1)throw new n.ExpectedError((0,n.t)(`error.address.singleRangeOnlyAlt`));let a=r[0]?.scope;a!==void 0&&a!==this.getName()&&console.warn(`Sheet.getRange(${YB(e)}) called with a scope (${a}) that does not match this sheet (${this.getName()}).`,e);let o=this._createRange(r[0],t);return i&&(this._lastRangeRead.address=typeof e==`string`?e:{...e},this._lastRangeRead.range=o),o}catch(t){throw t instanceof n.OutOfBoundsError?new n.OutOfBoundsError(t.message):new n.ExpectedError(t.message??o_(e))}}getCell(e){if(e===void 0)return this.getSelectedCell();let t=this.getRange(e);if(t.size>1)throw new n.ExpectedError((0,n.t)(`error.address.singleCellOnly`));return t.getCell()}getRanges(e,t){if(!e)throw new n.ExpectedError((0,n.t)(`error.address.noAddress`));let r=this._rangesToCoords(e);if(r.length===0)throw this._createRangeError(e);return this._createRanges(r,t)}getEntireRange(e){if(!e){let e=this._entireRangeCache;return e||(e=this._createRange(this._getEntireCoords()),this._entireRangeCache=e),e}return this.getRange(this._getEntireCoords(),e)}_getEntireCoords(){let e=this._entireCoordsCache;if(!e){let t=this._getState();if(!t)return null;e=t.entireCoords,this._entireCoordsCache=e}return e}getEntireCoords(){return this._getEntireCoords()}getUsedRange(e){let t=this._getUsedCoords(e),n=t?this.getRange(t,e):null;return e||(this._lastUsedCoordsRead.coords=t,this._lastUsedCoordsRead.range=n),n}getStats(e){let t=this._getUsedCoords();return this._getRangeStats(t?[t]:[],e)}getRegions(e,t){let n=Vj(e??t?.features);return new Wj(this._getEntireCoords(),this._getInternal(),n,t)}_cellToCoords(e){return function(e,t){let r=e.lastCellDecoded;if(r.address===t)return r.coords;let i=KR(e,t);if(!i||!n.CoordUtils.isSingleCell(i))throw new n.ExpectedError((0,n.t)(`error.address.singleCellOnly`));let a={colIndex:i.colStart,rowIndex:i.rowStart};return r.address=t,r.coords=a,a}(this._getCoordCtx(),e)}_validateCoords(e,t=(0,n.t)(`error.sheet.oobRange`),r=!1){HR(this._getCoordCtx(),e,t,r)}_createRangeError(e){return UR(e)}_protectionCheck(e=null,t=null,n=null){WR(this._getCoordCtx(),e,t,n)}_rangesToCoords(e,t=null,n=!0,r=!1,i=!1){return GR(this._getCoordCtx(),e,t,n,r,i)}_rangeToCoords(e,t=null,n=!0){return KR(this._getCoordCtx(),e,t,n)}_collectRanges(e,t=[],r=!0,i=this._getState(),a,o){(function(e,t,r=[],i=!0,a,o=e.state,s,c){let l=!0===i||typeof i==`object`&&!!i&&Object.keys(i).length>0,u=a&&a.length>0;if(!l&&!u)return;let d=(e,a,o=!1)=>{if(!o&&!0!==i&&i[e]===void 0||!a)return;let c=a.search(t,!1),l=c.length;if(l===0)return;let u=i[e];for(let i=0;i<l;i++){let a=c[i];if(u&&!n.CoordUtils.isRangeWithinRange(t,a)||s&&!n.CoordUtils.isRangeWithinRange(a,s))continue;let o=n.CoordUtils.intersectRanges(t,a),l=a.value,d=a.value?.model??l??!0;r.push({...o,value:{[e]:d}})}};if(u){let i=a?a.length:0,o=e.getEntireCoords(),s=n.CoordUtils.isEqualRanges(t,o);for(let e=0;e<i;e++){let t=a[e],n=t?t.length:0;if(n>0){let i=``+e;if(s)for(let e=0;e<n;e++){let n=Ud(t[e],o);n.value={[i]:n.value},r.push(n)}else{let e=[...t];for(let t=0;t<n;t++)e[t]=Ud(e[t],o);let r=new yr;r.load(e),d(i,r,!0)}}}}if(!l)return;if(f=W.Type.Merge,(typeof i==`boolean`&&!0===i||i[f]!==void 0)&&o.mergeSpatial){let e=o.mergeSpatial.search(t),i=e.length;for(let a=0;a<i;a++){let i=e[a],o=n.CoordUtils.intersectRanges(t,i);r.push({...o,value:{merge:i.value}})}}var f;d(W.Type.Unlock,o.protectedRanges),d(W.Type.Continuous,o.continuousFillSpatial),d(W.Type.DateFormat,o.dateFormatSpatial),d(W.Type.Hyperlink,o.hyperlinkSpatial),d(W.Type.Comments,o.comments),d(W.Type.BorderStyle,o.borderSpatial),d(W.Type.FillStyle,o.fillSpatial),d(W.Type.ContentStyle,o.contentSpatial);let p=e.calcGrid;d(W.Type.Contentful,p.getContentful(c)),d(W.Type.Formula,{search:t=>Vh(p.getFormulas(c),o.contentSpatial,t,e.cellOptions.getProtection(),e.cellOptions.styles)}),d(W.Type.Pending,p.getPending(c)),d(W.Type.CalcError,p.getCalcErrors(c)),d(W.Type.Circular,p.getCirculars(c)),!0!==i&&i[W.Type.Error]!==void 0&&d(W.Type.Error,e.calcGrid.getErrorValues()),d(W.Type.Spills,p.getSpills(c)),d(W.Type.Table,o.tables),d(W.Type.AutoTable,o.autoTables),d(W.Type.DataValidations,o.dataValidations),d(W.Type.Conditionals,o.conditionalFormats)})(this._getReadCtx(),e,t,r,a,i,void 0,o)}_cellIterator(e){let t=this._cellOptions,n=this._strings,r=this._cellStateIterator(e),i=e?.reuseContext?new yH(n,e,t):null;return{next(a){let o=r.next(a);if(o.done)return zt;let s=o.value,c=i??new yH(n,e,t),l=c.context;return{done:!1,value:{value:c.setState(s),context:l}}},[Symbol.iterator](){return this}}}_rangeStateIterator(e){return _R(this._getReadCtx(),e)}_overflowAndStops(e,t){return vR(this._getReadCtx(),e,t)}_cellStateIterator(e){return function(e,r){let i=e.state;if(!i)return Bt;let a=r?.bounds,o=a??e.getEntireCoords(),s=r?.axis??t.IRange.Axis.Row,c=r?.reverse??!1,l=r?.includeEmpty,u={bounds:o,axis:s,reverse:c},d;l&&(d={bounds:o,axis:s,reverse:c});let f=r?.ignoreHidden;if(!0===f||f===t.IRange.Axis.Row){let t=uH(e.rowHeaders);u.processRowSkip=Lt(t),l&&(d.processRowSkip=Lt(t))}if(!0===f||f===t.IRange.Axis.Column){let t=uH(e.columnHeaders);u.processColumnSkip=Lt(t),l&&(d.processRowSkip=Lt(t))}let p=l||!r?.ignoreEmptyIntersections,m=r?.includeMergeOverflow??!1,h=r?.injectReferences,g=r.searchTypes;!0===g?g=df:g||!h&&!m||(g=n.CommonUtils.EmptyObject);let _=g?_R(e,{bounds:o,axis:s,reverse:c,searchTypes:g,includeMergeOverflow:m,ignoreHidden:f,injectReferences:h,byCell:!0}):Bt,v,y;if(m&&a){let t=vR(e,a);t&&(v=t.overflows,v?.sort(n.CoordUtils.createCellComparator(s,c)),y=t.stops,y?.sort(n.CoordUtils.createCellComparator(s,c)))}let b=v?v.length:0,x=y?y.length:0,S=0,C=0,w=i?e.calcGrid.getValues():null,T=w?w.entries(u):Bt,E=T.next(),D=null,O=null,k=null;E.done||(D=E.value[0],O=E.value[1]);let A=v?.[S++],j=_.next(),M=null,N=s!==t.IRange.Axis.Row,P,F=n.CoordUtils.createCellComparator(s,c),I;if(!j.done){let e=j.value;M=e.intersection,I=e.start}P=e=>{let t=null,n=null,r=null,i=!1,a=!1,o=null,s=null,c=!1;if(A&&(D?F(A,D)<0&&(c=!0):I?F(A,I)<0&&(c=!0):S<=b&&(c=!0)),c)t={colIndex:A.colIndex,rowIndex:A.rowIndex},n=A.scalar,r=A.intersection,A=v[S++];else if(D&&I){let e=F(D,I);e<0?(t=D,n=O,i=!0):e>0?(t=I,r=M,a=!0):(t=D,n=O,r=M,i=!0,a=!0)}else if(D)t=D,n=O,i=!0;else{if(!I||!p)return zt;t=I,r=M,a=!0}if(i&&(E=T.next(),E.done?D=null:(D=E.value[0],O=E.value[1])),a){let e=p?void 0:D;if(j=_.next(e),j.done)I=null,M=null;else{let e=j.value;M=e.intersection,I=e.cell}}let l=!1,u=t.rowIndex,d=t.colIndex;N||(l=u===k?.rowIndex);let f=!1;if(N||(f=u===D?.rowIndex),l)o=k;else if(m){let e=!1;for(;!e&&C<x;){let t=y[C],n=t.rowIndex;n<u?C++:(e=!0,n===u&&t.colIndex<d&&(C++,o={colIndex:t.colIndex,rowIndex:t.rowIndex}))}}if(f)s=D;else if(m){let e=!1;for(;!e&&C<x;){let t=y[C],n=t.rowIndex;n<u?C++:(e=!0,n===u&&t.colIndex>d&&(C++,s={colIndex:t.colIndex,rowIndex:t.rowIndex}))}}return(i||c)&&(k=t),{done:!1,value:[t,n,r,o,s]}};let L={next:P,return:e=>null,throw:e=>null};return l&&(L=new Wr(L,u)),L}(this._getReadCtx(),e)}_indexMerges(e,t=null){if(!(e&&e.length!==0||t&&t.length!==0))return;let n=this._getState();if(!n)return;let r=this._beginCommit({description:`indexMerges`}),i=n.mergeSpatial.clone();if(t){let e=t.length;for(let n=0;n<e;n++)i.remove(t[n])}if(e){let t=e=>this._calcGrid.getValues().getValueAt(e.rowStart,e.colStart),n=[],r=e.length;for(let i=0;i<r;i++){let r=e[i];n.push({...r,value:new eM(r,t)})}i.load(n)}this._updateState({mergeSpatial:i}),r.commit()}_composeDirectStyleView(e,t){let n=this._getState(),r=t??{border:n.borderSpatial,fill:n.fillSpatial,content:n.contentSpatial},i=new jP({entireCoords:this._getEntireCoords()}),a=(e,t)=>({...t,value:tg.mergeOverlay(e.value,t.value)}),o=t=>{let n=e?t.search(e):t.all(),r=n.length;for(let e=0;e<r;e++){let t=n[e];t.value&&i.insertNonOverlapping({...t,value:t.value},{onIntersect:a})}};return o(r.content),o(r.fill),o(r.border),i}_updateStyles(e,t,n,r=!1){!r&&e.length===1&&this._holdStyle(e[0],t,n)||LL(this._getMutationCtx(),e,t,n,r)}_holdStyle(e,t,n){if(e.rowStart!==e.rowEnd||e.colStart!==e.colEnd)return!1;let r=e.value===void 0?t:e.value;if(r===void 0)return!1;let i=e.rowStart,a=e.colStart,o=this._getCellBuffer();return o.holdStyle(i,a,r,n,()=>{let e=o.isHolding()?o.getTransaction().getState(this._stateId):this._getState();return this._isLocalStyle(e,i,a,r)})}_isLocalStyle(e,t,n,r){return typeof r!=`function`&&function(e,t,n,r,i){if(i===null||typeof i==`function`)return!1;let a={colStart:r,rowStart:n,colEnd:r,rowEnd:n},o=EH(e.styles)(new tg(e.styles,e.getEntireCoords,a),i,!0);if(!o)return!1;let s=o.splitByFeature();if(s.border)return!1;let l=s.content?(s.content.getUpdateProperties()??s.content.getProperties())?.alignment:void 0;if(l!==void 0){let e=l?.horizontal;if(e===c.HorizontalAlignment.CenterContinuous||e===c.HorizontalAlignment.Fill||t.search(a).length>0)return!1}return!0}(this._getMutationCtx(),e.continuousFillSpatial,t,n,r)}_createSparseBuilder(e,r=null,i){let a=e?.axis??t.IRange.Axis.Row,o=e?.allowUnorderedWrites??!1,s=a===t.IRange.Axis.Column,c=s!==this._isDataColumn,l=this,u,d,f,p=this._createTupleBuilder(c),m=null;if(r){let e=r.getCoords(),t=e.colStart,i=e.rowStart,a=e.colEnd,o=e.rowEnd;m=(e,r)=>{if(e<i||e>o||r<t||r>a)throw new n.OutOfBoundsError}}s?(d=(e,t,n)=>(m?.(e,t),p.pushAt(t,e,n),u),f=(e,t,n)=>(m?.(e,t+(n?.length??0)),p.pushMultipleAt(t,e,n),u)):(d=(e,t,n)=>(m?.(e,t),p.pushAt(e,t,n),u),f=(e,t,n)=>(m?.(e+(n?.length??0),t),p.pushMultipleAt(e,t,n),u));let h=e=>{let t=p.build();return t&&l._updateTuples(t,e,null,i),r},g=!1===o?null:n.CoordUtils.createCellComparator(e?.axis),_=n.CommonUtils.isObject(o)?o:void 0,v=null;return u=Object.freeze({push:(e,t)=>{let n=l._cellToCoords(e);return g&&(v&&g(n,v)<=0&&(h(_),p=l._createTupleBuilder(c)),v=n),d(s?n.colIndex:n.rowIndex,s?n.rowIndex:n.colIndex,t)},pushAt:d,pushMultipleAt:f,apply:h}),u}_updateTuples(e,t,n=void 0,r=null){this._getCellBuffer().hold(e,t,n,r)||aR(this._getMutationCtx(),e,t,n,r)}_getCellBuffer(){let e=this._cellBuffer;if(!e){let t=this;e=new lR({isDataColumn:this._isDataColumn,transactions:this._transactions,writes:[this._stateId,this._calcGrid.getStateId(),this._calculation._modelMirrorId??this._calculation.getId()],isClosed:()=>t._closed,getEntireCoords:()=>t._getEntireCoords(),getSpills:e=>t._calcGrid.getSpills(e),isLocalStyle:(e,n,r,i)=>t._isLocalStyle(e.getState(t._stateId),n,r,i),getMutations:()=>t._getMutationCtx()}),this._cellBuffer=e}return e}_sort(e,t){return Zj(this,e,t)}_filter(e,t,r){return async function(e,t,r,i){let a=await mO(e,t,r),o=i?.description??(0,n.messageKey)(`op.filter`),s=e._beginCommit({description:o,...i});try{hO(e,a,{description:o}),s.commit()}catch(e){throw s.rollback(),e}return t}(this,e,t,r)}_evalFilter(e,t){return mO(this,e,t)}_applyFilterRuns(e,t){hO(this,e,t)}_autoFill(e,t,n){return RR(this._getMutationCtx(),e,t,n)}_autoFillRange(e,n){return function(e,n,r){let{direction:i,amount:a}=bH(n,r);if(a<=0)return{...r};let o=e.getMerges([n]);if(o.length===0)return{...r};let s=i===t.IRange.Direction.Up||i===t.IRange.Direction.Down,c=i===t.IRange.Direction.Down||i===t.IRange.Direction.Right,l=s?n.rowStart:n.colStart,u=(s?n.rowEnd:n.colEnd)-l+1,d=jR(o,l,u,s,c),f=e.getEntireCoords(),p=c?s?f.rowEnd-n.rowEnd:f.colEnd-n.colEnd:s?n.rowStart-f.rowStart:n.colStart-f.colStart,m=function(e,t,n){let r=e-e%t,i=e%t;for(let e=0;e<n.length;e++)if(n[e]>=i)return r+n[e];return r+t}(a,u,d);return m>p&&(m=function(e,t,n){if(e<0)return 0;let r=e-e%t,i=e%t;for(let e=n.length-1;e>=0;e--)if(n[e]<=i)return r+n[e];return r}(p,u,d)),m<=0?{...n}:s?c?{...n,rowEnd:n.rowEnd+m}:{...n,rowStart:n.rowStart-m}:c?{...n,colEnd:n.colEnd+m}:{...n,colStart:n.colStart-m}}(this._getMutationCtx(),e,n)}_autoFillShrink(e,t,n,r){return zR(this._getMutationCtx(),e,t,n,r)}_setHyperlinks(e,t,n){IL(this._getMutationCtx(),e,t,n)}_requestFor(e){return e?{commitId:e.getId(),cloneKey:e.getSavepointId()}:{commitId:this._transactions.getCurrentCommit().getId()}}_resolveInheritedFormats(t,r,i){let a=this._transactions,o=e=>a.getStateAt(t,e._stateId)??e._getState(),s=t=>{if(!t||t===this.getId()||t===this.getName())return this;let n=this._workbook?.getSheets().getItems({visibility:Eu.Visibility.VeryHidden});if(!n)return null;for(let r=0;r<n.length;r++){let i=n[r];if((i.getId()===t||i.getName()===t)&&i instanceof e)return i}return null},c=new yr,l=r.length;for(let e=0;e<l;e++){let t=r[e].coords,a=[];for(let e=0;e<i.length;e++){let r=n.CoordUtils.intersectRanges(t,i[e]);r&&a.push(r)}if(a.length===0)continue;let l=t.rowStart,u=t.colStart,d=r[e].references;for(let e=d.length-1;e>=0;e--){let r=d[e],i=s(r.scope);if(!i)continue;let f=!0===r.$rowStart,p=!0===r.$colStart,m=Bd(r,l,u),h=m.rowStart,g=m.colStart,_=n.CoordUtils.intersectRanges({rowStart:f?h:h+(t.rowStart-l),colStart:p?g:g+(t.colStart-u),rowEnd:f?h:h+(t.rowEnd-l),colEnd:p?g:g+(t.colEnd-u)},i._getEntireCoords());if(!_)continue;let v=o(i);if(!v)continue;let y=v.contentSpatial.search(_),b=y.length;for(let e=0;e<b;e++){let r=y[e],i=r.value?.getProperties()?.numberFormat;if(CV(i))continue;let o=n.CoordUtils.intersectRanges(r,_),s={rowStart:f?t.rowStart:o.rowStart-h+l,rowEnd:f?t.rowEnd:o.rowEnd-h+l,colStart:p?t.colStart:o.colStart-g+u,colEnd:p?t.colEnd:o.colEnd-g+u};for(let e=0;e<a.length;e++){let t=n.CoordUtils.intersectRanges(s,a[e]);t&&c.insertNonOverlapping({...t,value:{numberFormat:i}})}}}}return c.all()}_realizeCalcedValues(e){if(!e||!this._getState())return;let t=e.spillInserts,n=e.spillRemoves,r=this._calculation._calculatedCommitId??this._transactions.getCurrentCommit(!1).getId();this._amendBookkeeping(r,t=>{this._promoteCalcResults(t,e)}),!e.bounds&&!e.isFull||this._initializing||(this._invalidateCaches(),this._notifyUsedRangeChange(),this._notifyListenerNodes(this._getState(),[e.bounds??this._getEntireCoords()],{isDataChange:!0,getTransactionId:uV,timeStamp:Date.now(),isUndo:!1,trigger:`calc`},!1),(t||n)&&this._notify(`onSpillsChange`),this._notify(`onDataChange`))}_promoteCalcResults(e,t){let r=this.getId(),i=e.getIntents();if(i[`sheet.calcResolved`]?.includes(r))return;let a=i[PN]?.[r];if(!a||a.length===0)return;let o=t.bounds;if(!o)return;let s=[];for(let e=0;e<a.length;e++){let t=n.CoordUtils.intersectRanges(a[e],o);t&&s.push(t)}if(s.length===0)return;let c=this._beginCommit();try{let a=t.formatInserts,o=i[BN];if(a&&o?.includes(r)){let t=[],r=[];for(let e=0;e<a.length;e++){let i=a[e],o=i.value,c;if(typeof o==`string`?c=o:(r.push({coords:i,references:o.references}),c=o.fallback),c!==null)for(let e=0;e<s.length;e++){let r=n.CoordUtils.intersectRanges(i,s[e]);r&&t.push({...r,value:{numberFormat:c}})}}if(r.length>0){let t=this._resolveInheritedFormats(e.getId(),r,s);t.length>0&&this._updateStyles(t,void 0,void 0,!0)}t.length>0&&this._updateStyles(t,void 0,void 0,!0)}let l=i[LN]?.find(e=>e.sheetId===r);l&&this._autoFit(s,l.options??sV),c.setIntent(`sheet.calcResolved`,e=>[...e??[],r]),c.updateState(this._stateId,{}),c.commit()}catch(e){throw c.rollback(),e}}calculate(e){return this._calculation.calculate({full:e,scope:this._calcGrid.getId()})}_calculate(e,t){let n=this._calcGrid;n.markDirtyRegions(e),this._calculation.calculate({...t,scope:n.getId()})}_calculateFull(){this._ownCalculation&&!this._initializing&&this._calculation.getStatus()!==X.Status.Off&&this._calculation.calculate(!0)}_setComments(e,t,n){PL(this._getMutationCtx(),e,t,n)}_clear(e,t=null,n,r=!1,i=null){sR(this._getMutationCtx(),e,t,n,r,i)}_merge(e,t=null){VL(this._getMutationCtx(),e,t)}_unmerge(e,t){HL(this._getMutationCtx(),e,t)}_getMerges(e,t=!1){if(e.length===0)return n.CommonUtils.EmptyArray;let r=this._getState();return r?this._getRangedEntries(r.mergeSpatial,e,{ignoreHidden:t,fullyContained:!1,onEntry:e=>e.getCoords()}):n.CommonUtils.EmptyArray}_clone(){let t={...this._options,calcGrid:this._calcGrid,container:{getName:()=>`Snapshot of ${this.getName()}`,getIndex:()=>1}};this._ownStyles&&(t.styles=this._styles),this._ownStrings&&(t.strings=this._strings),this._ownResources&&(t.resources=this._resources),this._ownNames&&(t.names=this._names),this._ownCalculation&&(t.calculation=this._calculation),t.transactions=new g({transient:!0});let n=new e(t),r=this._transactions.getState(this._stateId);n._updateState(r);let i=new ZR({sheet:this,json:this.getView().toJSON()});return i.selectMovables(this.getView().getMovableSelection()),n.setView(i),n}_getSnapshot(e,t,r){if(e.length===0)return n.CommonUtils.EmptyArray;let i=this._getState();if(!r){let e=this._transactions.getCurrentCommit().getId();e&&(r=()=>e)}if(!i)return null;t=Object.freeze({...t});let a=this._clone();a.isMarked=!0;let o=this,s=o.getView(),c=(0,n.messageKey)(`op.range`),l=[];if(e.length>1)throw new n.ExpectedError((0,n.t)(`error.sheet.copyMultipleRanges`));let u=SH(e,a._getState().mergeSpatial,a.getEntireCoords()),d=function(e,t,r,i){let a=[],o=null,s=null,c=r&&r.length>0;if(c){let e=r.length;for(let t=0;t<e;t++){let e=r[t].getSnapshot?.(i);e&&(a.push(e),o=qN(e.getCoords(),o))}}else if(t){let r=t.length;for(let c=0;c<r;c++){let r=t[c],l=e.getMovables().getItems({ignoreHidden:!1,fullyContained:!0,address:r}),u=l.length;for(let t=0;t<u;t++){let c=l[t].getSnapshot?.(i);c&&(a.push(c),o=qN(e.getRange(r).getBounds(),o),s=n.CoordUtils.unionRanges(s,r))}}}if(a.length===0)return null;let l=()=>i.description??(a?.length===1?a[0]?.getName():(0,n.t)(`copy.drawings`));return{copyTo:async(e,t)=>{let r={...i,...t},s=e.getSheet(),c=s.getView(),u=c.getMovableSelection(),d=e.getCoords(),f=r?.isCut??!1,p=c.getMovableSelection();c.selectMovables([]);let m=s.beginCommit(r.description??(f?(0,n.t)(`op.cutNamed`,{name:l()}):(0,n.t)(`op.copyNamed`,{name:l()})));try{let e=0,t=0;if(p.length>0&&a.length>0){let n=2**53-1,r=2**53-1;for(let e=0;e<u.length;e++){let t=u[e].getBounds();n=Math.min(t.x,n),r=Math.min(t.y,r)}let i=2**53-1,o=2**53-1,c=a.length;for(let e=0;e<c;e++){let t=a[e].getCoords();i=Math.min(t.x,i),o=Math.min(t.y,o)}e=n-i,t=r-o;let l=a[0].getCoords(),d={...l,x:l.x+e,y:l.y+t},f=pA(s.getMovables(),d);e+=f.x,t+=f.y}else if(o){let n=s.getRange(d).getBounds();e=n.x-o.x,t=n.y-o.y}let n=[],i=a.length;for(let o=0;o<i;o++){let i=a[o],c=i.getCoords(),l={...c,x:c.x+e,y:c.y+t};n.push(i.copyTo({movables:s.getMovables(),bounds:l},{autoSelect:{addToSelection:!0},...r}))}await Promise.all(n),m?.updateState(s._getStateId(),{}),s._recordMovableSelection(`before`,p,m),m.commit()}catch(e){throw m.rollback(),e}return null},getName:l,getCoords:()=>s,getMarkOptions:()=>i,toText:()=>c?a[0].toText?.()??null:null,toHtml:()=>c?a[0].toHtml?.()??null:null,toImage:()=>c?a[0].toImage?.()??null:null,getSource:()=>e,isISnapshot:!0}}(a,u,s.getMovableSelection(),t);if(d){if(s.getMovableSelection().length>0)return d;l.push(d)}let f={singleMerge:null};l.push({copyTo(r,i){let s={...t,...i},c=r.getSheet(),l=r.getCoords(),d=l,p=c.getRange(d),m=!1,h=p.getMerges();if(h.length===1&&n.CoordUtils.isEqualRanges(h[0],l))if(n.CoordUtils.isSingleCell(e[0]))m=!0;else{let e=_A(b);a._getMerges([n.CoordUtils.cellToRange(e)]).length===1&&(m=!0)}let g=s.type;return m&&(f.singleMerge=l,g??=wk.Content.Values),s.isCut&&c===o?o._clear([d],g??null,void 0,!1,u[0]):p.clear(g),d}});let p=a._getEntireCoords(),m=u.length,h=a._getState();if(!h)return n.CommonUtils.EmptyArray;for(let e=0;e<m;e++){let n=u[e];l.push(vP(o.getColumnHeaders().getRange(n),n,Object.freeze({...t,includeHeaders:n.rowStart<=p.rowStart&&n.rowEnd>=p.rowEnd})))}for(let e=0;e<m;e++){let n=u[e];l.push(vP(o.getRowHeaders().getRange(n),n,Object.freeze({...t,includeHeaders:n.colStart<=p.colStart&&n.colEnd>=p.colEnd})))}let g=yP(o,a,u,c,t,(e,t)=>a._copyRange(o,a,u,e,t,f));l.push(g);let _=a._calcGrid.getSnapshot({range:u[0],isCut:t?.isCut});l.push({async copyTo(e,n){if(n?.type&&n?.type!==wk.Content.Formulas)return null;let r=e.getSheet(),i=e.getCoords();if(a.getProtection().isLocked())return null;let s={...t,...n},c=r,l=c._calcGrid,d=c._requestFor(c._transactions.getCurrentTransaction());_.copyTo({gridId:l.getId(),grid:l,range:i},{isCut:s.isCut,fitDestination:n?.fitDestination,transpose:s.transpose,commitId:d.commitId,cloneKey:d.cloneKey});let f=i;return s.isCut&&(r!==o||s.transpose||o._moveReferences(u[0],i)),f}});let v={ignoreHidden:!1,fullyContained:!0,onEntry:e=>e.model};for(let e=0;e<m;e++){let n=u[e],r=a._getRangedEntries(h.tables,[n],v),i=r.length;for(let e=0;e<i;e++){let i=r[e],o=i.getRange().getCoords(),s=o.colStart-n.colStart,c=o.rowStart-n.rowStart,u=i.getSnapshot(t);l.push({async copyTo(e,t){let n=e.getSheet(),r=e.getCoords();if(a.getProtection().isLocked())return null;let i={colStart:r.colStart+s,rowStart:r.rowStart+c,colEnd:r.colEnd+s,rowEnd:r.rowEnd+c};return u.copyTo({tables:n.getTables(),range:i},t)}})}}let y={ignoreHidden:!1,fullyContained:!1};for(let e=0;e<m;e++){let r=u[e],i=a._getRangedEntries(h.conditionalFormats,[r],y,!0),s=i.length;for(let e=0;e<s;e++){let s=i[e],c=s.getRanges().getCoords(),u=[];for(let e=0;e<c.length;e++){let t=n.CoordUtils.intersectRanges(c[e],r);t&&u.push(t)}if(u.length===0)continue;let d=s.getSnapshot(t),f=e;l.push({async copyTo(e,n){let i={...t,...n};if(i.type&&i.type!==wk.Content.Formats||a.getProtection().isLocked())return null;let s=e.getSheet(),c=_P(u,r,e.getCoords(),!!i.transpose);return c.length===0?null:d.copyTo({conditionals:s.getConditionalFormats(),range:c[0],ranges:c,extend:s===o,index:f},n)}})}let c=a._getRangedEntries(h.dataValidations,[r],y,!0),d=c.length;for(let e=0;e<d;e++){let i=c[e],s=i.getRanges().getCoords(),u=[];for(let e=0;e<s.length;e++){let t=n.CoordUtils.intersectRanges(s[e],r);t&&u.push(t)}if(u.length===0)continue;let d=i.getSnapshot(t),f=e;l.push({async copyTo(e,n){let i={...t,...n};if(i.type||a.getProtection().isLocked())return null;let s=e.getSheet(),c=_P(u,r,e.getCoords(),!!i.transpose);return c.length===0?null:d.copyTo({validations:s.getDataValidations(),range:c[0],ranges:c,extend:s===o,index:f},n)}})}}let b=u[0];return function(e,t,r,i,a,o,s=null){return{async copyTo(t,i){let s=null,c={...a,...i},l=r.beginCommit(c.description??o);try{let r=e.length;for(let i=0;i<r;i++){let r=await e[i].copyTo(t,c);r&&(s=n.CoordUtils.unionRanges(s,r))}l.commit()}catch(e){throw l.rollback(),e}return s},getMarkOptions:()=>a,getName:()=>(0,n.t)(o),getSource:()=>t,getCoords:()=>i,toText(){let t=s?.toText?.()??null,n=e.length;for(let r=0;!t&&r<n;r++)t=e?.[r].toText?.();return t??null},toHtml(){let t=s?.toHtml?.()??null,n=e.length;for(let r=0;!t&&r<n;r++)t=e?.[r].toHtml?.();return t??null},toImage(){let t=s?.toImage?.()??null,n=e.length;for(let r=0;!t&&r<n;r++)t=e?.[r].toImage?.();return t??null},isISnapshot:!0}}(l,o,a,b,t,c,g)}async _copyRange(e,r,i,a,o,s){if(i.length>1)throw new n.ExpectedError((0,n.t)(`error.sheet.insertCopyMultipleRanges`));if(!i||i.length===0)throw new n.ExpectedError((0,n.t)(`error.sheet.copyNoSource`));let c=a.getSheet(),l=a.getCoords(),u={...i[0]},d=(o={...o}).isCut,f=!o.type||o.type===wk.Content.Formats,p=!o.type||o.type===wk.Content.Values,m=!o.type||o.type===wk.Content.Formats||o.type===wk.Content.Hyperlinks,h=c.getEntireRange(),g=h.getCoords(),_=[],v=[],y=[],b=[],x=[],S=(o.fitDestination??!1)&&!n.CoordUtils.isSingleCell(l),C=l;if(S&&(u={...u,colEnd:u.colStart+Math.min(C.colEnd-C.colStart,u.colEnd-u.colStart),rowEnd:u.rowStart+Math.min(C.rowEnd-C.rowStart,u.rowEnd-u.rowStart)}),!n.CoordUtils.isRangeWithinRange(C,g))throw console.warn(C,g),new n.ExpectedError((0,n.t)(`error.sheet.pasteOob`));let w=o.undoRange?DA([o.undoRange.getCoords()]):null,T=c.getTransactions().beginCommit({description:o.description??(0,n.messageKey)(`op.paste`)});try{if(!this._getState())return n.CommonUtils.EmptyArray;let i=new Set,a=o.transpose,g=!((a||o.adjustCells)&&f)&&i.size===1;if(g){let e=i.values().next();g=n.CoordUtils.isRangeWithinRange(u,e.value.getCoords())&&!gH(u,e.value.getCoords())}g&&=c.getTables().getItems({address:C}).length===0,a&&(g=!0),s.singleMerge&&(f=!1,m=!1);let S=l.colStart-u.colStart,E=l.rowStart-u.rowStart,D=o.adjustCells,O={...ff};if(delete O[W.Type.BorderStyle],delete O[W.Type.FillStyle],delete O[W.Type.ContentStyle],!f){let e=this.getProtection().isLocked();O={},e&&(O[W.Type.Unlock]=!1)}let k=t.IRange.Axis.Column,A;if(p){A=h.createSparseBuilder({axis:o.transpose?t.IRange.Axis.Row:t.IRange.Axis.Column});let e={axis:k,searchTypes:O,bounds:u},r=new yH(this._strings,e,this._cellOptions),i=(e,t,n)=>{let i=e[0],s=r.setState(e),c=r.context,d=c.getCell(),h=d.isTopLeft(),v=E,y=S;if(a){let e=i.colIndex-u.colStart,r=i.rowIndex-u.rowStart;v=e+n+l.rowStart,y=r+t+l.colStart}else v=E+i.rowIndex+t,y=S+i.colIndex+n;let b=!1,x={value:void 0,style:void 0,hyperlink:void 0};if(p&&(x.value=s,b=!0),f){let t=e[2];t&&(t.borderStyle||t.fillStyle||t.contentStyle||t.table)&&(x.style=d.getStyle(!g),b=!0)}m&&(x.hyperlink=d.getHyperlink(),b=!0);let C=x;if(D&&h){let e=D(s,c,{rowIndex:v,colIndex:y},o);e!==void 0&&(C=e,b=!0)}if(b&&(A.pushAt(v,y,C),f)){let e=d.getSpans();(e.width>1||e.height>1)&&h&&_.push({colStart:y,rowStart:v,colEnd:y+(o.transpose?e.height:e.width)-1,rowEnd:v+(o.transpose?e.width:e.height)-1})}},c=this._cellStateIterator(e),d={next(){let e=c.next();if(e.done)return zt;let t=e.value[0],n;return e.value&&(n=[t,e.value]),{done:e.done,value:n}}};if(!s.singleMerge&&!n.CoordUtils.isEqualRanges(C,u)){let e=C.colEnd-C.colStart+1,t=C.rowEnd-C.rowStart+1;d=new Gr({delegate:d,bounds:u,axis:k,dims:{major:o.transpose?t:e,minor:o.transpose?e:t}})}let v=d.next();for(;!v.done;){let e=v.value,t=e[1],n=e[0],r=t[0];i(t,n.rowIndex-r.rowIndex,n.colIndex-r.colIndex),v=d.next()}}let j=r._getState(),M={},N={transpose:a??!1};f&&(M.borderSpatial=j.borderSpatial,M.fillSpatial=j.fillSpatial,M.contentSpatial=j.contentSpatial,M.continuousFillSpatial=j.continuousFillSpatial,M.mergeSpatial=j.mergeSpatial),d&&(e._clear([u],void 0,void 0,!1,u),b.push(u));let P=c,F=P._getState(),I=Object.keys(M),L=I.length;for(let e=0;e<L;e++){let t=I[e],n=M[t].createCopiedEntries(u,C,N),r=F[t].clone(),i=n.removes,a=i.length;for(let e=0;e<a;e++)r.remove(i[e]);r.load(n.inserts),F[t]=r}P._updateState(F),b.push(C),x.push(C),v&&v.length>0&&P._colHeaders.updateHeaderPairs(v),y&&y.length>0&&P._rowHeaders.updateHeaderPairs(y),A?.apply(),_.length>0&&c.getRanges(_).merge(),P._recordSelection(T,DA(x),o,w),P._recordChange(T,`data`,b),T.commit()}catch(e){throw console.warn(e),T.rollback(),Error((E=e.message,(0,n.t)(`error.sheet.paste`,{message:E})),{cause:e})}var E;return n.CoordUtils.unionRangesArrays(x)}_snapShotFromSource(e,t){if(e.isISnapshot)return e;let r=e,i=null;if(r?.isICellRanges)throw new n.ExpectedError((0,n.t)(`error.sheet.copyMultipleRanges`));if(r?.isICellRange)i=r;else{let e=this.getWorkbook();i=typeof r==`string`&&r.includes(`!`)&&e?e.getRange(r):this.getRange(r)}if(i.isICellRange){let e=i;if(e.isInvalid())throw new n.ExpectedError((0,n.t)(`error.sheet.copyInvalidSource`));return e.getSnapshot(t)}throw new n.ExpectedError((0,n.t)(`error.sheet.copyInvalidSource`))}async _copyFrom(e,t,r){if(!t)throw new n.ExpectedError((0,n.t)(`error.sheet.copyMissingArgs`));let i=this._snapShotFromSource(t,r),a=(0,n.messageKey)(`op.paste`),o=this._beginCommit({description:r?.description??a}),s=null;try{let t=bA(e,i.getCoords(),r?.fitDestination,r?.transpose),c=this.getRange(t);s=await i.copyTo(c,r);let l=i.getName?.(),u=[s];r?.isCut&&u.push(i.getCoords()),this._recordChange(o,`data`,u),this._commitWithDirectives(o,DA([s??t]),r,{commit:{description:l?r?.description??(0,n.t)(`op.pasteNamed`,{name:l}):a}})}catch(e){throw o.rollback(),e}return s}addAutoTable(e,t){e||=this.getSelectedRange().getCoords();let r=this._rangeToCoords(e);if(r=this._surroundingRegion(r,{contentOnly:!0}),n.CoordUtils.isSingleCell(r)&&!this._isContentful([r]))throw new n.ExpectedError((0,n.t)(`error.sheet.tableEmpty`));r=this._rangeToCoords(r,()=>[`sort`,`autoTable`]);let i=this._getEntireCoords();if(r.rowStart===r.rowEnd){if(r.rowEnd===i.rowEnd)throw new n.ExpectedError((0,n.t)(`error.sheet.table1By1`));r.rowEnd+=1}let a={...r},o=(0,n.messageKey)(`op.insertAutoTable`),s=this._beginCommit({description:t?.description??o}),c;try{let e={...t?.properties,style:null};this._validateOrRemoveOverlaps(r,`table`,null,t?.replaceExisting??!1);let n=this,i=this._getState(),o=i.autoTables;o=this._createTables(o,`autoTables`,[{r,v:e}],e=>{let t=new RO(e);return c=t,t},e=>e.addListeners({onDelete:()=>{let t=i.autoTables;t=t.deleteModel(e),n._updateState({autoTables:t}),n._notify(`onAutoTableChange`)}},{once:!0})),this._updateState({autoTables:o}),this._tellFiltered(),this._notify(`onAutoTableChange`),this._notifyTablesChange();let l=DA([r]);this._recordSelection(s,l,t),this._recordChange(s,`anchored`,[a,r]),s.commit()}catch(e){throw s.rollback(),e}return c}getAutoTable(){let e=this._getState();if(!e)return null;let t=e.autoTables.all();return t.length===0?null:t[0]}_filteredTables(){let e=[],t=this.getAutoTable();t&&t.getActiveFilters().length>0&&e.push(t);let n=this._tables.getItems();for(let t=0;t<n.length;t++)n[t].getActiveFilters().length>0&&e.push(n[t]);return e}_tellFiltered(){if(this._closed||!this._ownsCalcGrid)return;let e=this._transactions.getCurrentTransaction(),t=this._calcGrid;e&&t&&t.setFiltered(this._filteredTables().length>0,this._requestFor(e))}_getDefaultShiftAxis(e){return function(e,n){if(n){if(e.colStart<=n.colStart&&e.colEnd>=n.colEnd)return t.IRange.Axis.Row;if(e.rowStart<=n.rowStart&&e.rowEnd>=n.rowEnd)return t.IRange.Axis.Column}return e?function(e){return e.rowEnd-e.rowStart>e.colEnd-e.colStart?t.IRange.Axis.Column:t.IRange.Axis.Row}(e):t.IRange.Axis.Row}(e,this._getEntireCoords())}_getTables(e,t=!1,r=!1){let i=e?this._rangeToCoords(e):this._getEntireCoords(),a=this._getState();return a?this._getRangedEntries(a.tables,[i],{ignoreHidden:t,fullyContained:r,onEntry:e=>e.model}):n.CommonUtils.EmptyArray}_getDefaultAutoFillCriteria(e,t,n){return NR(this,e,t,n)}_getDefaultSortCriteria(e,r=t.IRange.Axis.Row,i){let a=(i?this._cellToCoords(i):null)??_A(e),o=n.CoordUtils.cellToRange(a),s=this._getTables(o)[0]??null,c=!1;if(!s){let e=this.getAutoTable();e&&e.getRange().getIntersect(o)&&(s=e,c=!0)}let l=function(e,r,i,a=t.IRange.Axis.Row){let o=e.getRange(r,{ignoreHidden:a}),s=o.forEach((e,t)=>({break:t.getCoords()}),{features:[],axis:a});if(!s)return;let c=a===t.IRange.Axis.Row,l=new Map,u,d=new Map,f=null,p=c?s.rowIndex:s.colIndex;o.forEach((e,n)=>{let r=n.getCoords(),i=c?r.colIndex:r.rowIndex;if((c?r.rowIndex:r.colIndex)===p)l.set(i,e),u=n.getType();else{let e=n.getType();u!==t.ScalarType.Null&&e!==t.ScalarType.Null&&u!==e&&(f=!0)}if(f)return af},{axis:a===t.IRange.Axis.Row?t.IRange.Axis.Column:t.IRange.Axis.Row,features:[],includeEmpty:!0,address:{colStart:s.colIndex,rowStart:s.rowIndex,colEnd:c?r.colEnd:s.colIndex+1,rowEnd:c?s.rowIndex+1:r.rowEnd}});let m={colStart:s.colIndex,rowStart:s.rowIndex,colEnd:r.colEnd,rowEnd:r.rowEnd};if(m.colStart>m.colEnd||m.rowStart>m.rowEnd||n.CoordUtils.isSingleCell(m))return null;if(f){let e=c?m.colStart:m.rowStart;l.forEach((t,n)=>{n<e||d.set(n-e,t+``)})}let h={colIndex:Math.min(Math.max(i?.colIndex??0,m.colStart),m.colEnd),rowIndex:Math.min(Math.max(i?.rowIndex??0,m.rowStart),m.rowEnd)},g=a!==t.IRange.Axis.Row,_={...oa.DefaultRangeOptions,hasHeader:f,axis:a,sorts:[{index:g?h.rowIndex-m.rowStart:h.colIndex-m.colStart}]},v=m;return f&&(v={colStart:g?m.colStart+1:m.colStart,rowStart:g?m.rowStart:m.rowStart+1,colEnd:m.colEnd,rowEnd:m.rowEnd}),{coords:m,options:_,headers:d,sortCoords:v}}(this,e,a,r);if(!l)return l;if(s){let e=s.getActiveSorts(),n=[];for(let t=0;t<e.length;t++)n.push({index:e[t].getIndex(),criteria:e[t].getCriteria()});let i=s.getRange().getCoords(),o=s.getSortAt(a.colIndex-i.colStart),u=o.getCriteria();n.length===0&&n.push({index:o.getIndex(),criteria:u}),l.options.sorts=n,u!==null&&(l.options.reverse=u.reverse,l.options.collatorOptions=u.collatorOptions);let d=c?s.getDataRange().getCoords():null,f=d?d.rowStart>i.rowStart:s.isShowHeaders();if(!c){let e=new Map;if(f){let t=s.getColumns();for(let n=0;n<t.length;n++)e.set(n,t[n].getName())}l.headers=e}l.options.hasHeader=f;let p=r!==t.IRange.Axis.Row;l.sortCoords=f?{...l.coords,colStart:p?Math.min(l.coords.colStart+1,l.coords.colEnd):l.coords.colStart,rowStart:p?l.coords.rowStart:Math.min(l.coords.rowStart+1,l.coords.rowEnd)}:l.coords}return l}_getInsertFromRefusal(e,r,i,a,o){if(a&&o){let t=n.CoordUtils.classifyInsertCut(r,e,i);if(t===n.CoordUtils.InsertCutShift.Inside)return(0,n.t)(`error.sheet.insertCutInside`);if(t===n.CoordUtils.InsertCutShift.Tear)return(0,n.t)(`error.sheet.insertCutOverlap`)}let s=this._getState();if(!s)return null;let c=i===t.IRange.Axis.Row,l=this._getEntireCoords(),u=c?{colStart:e.colStart,colEnd:e.colEnd,rowStart:e.rowStart,rowEnd:l.rowEnd}:{rowStart:e.rowStart,rowEnd:e.rowEnd,colStart:e.colStart,colEnd:l.colEnd},d=c?t.IRange.AxisSelection.Row:t.IRange.AxisSelection.Column,f=s.mergeSpatial.search(u);for(let t=0;t<f.length;t++){let r=f[t];if(Nr(e,r,d)||(c?e.rowStart>r.rowStart&&e.rowStart<=r.rowEnd:e.colStart>r.colStart&&e.colStart<=r.colEnd))return(0,n.t)(`error.sheet.insertMergeThrough`)}let p=this._getTables(u);for(let t=0;t<p.length;t++)if(Nr(e,p[t].getRange().getCoords(),d))return(0,n.t)(`error.table.tableSplit`);return null}_canInsertFrom(e,t,n){if(!t||!e?.length)return!1;let r=null,i=this,a=t;if(a.isISnapshot)r=a.getCoords?.()??null,i=a.getSource?.()??null;else{let e=t,n=e?.isICellRange?e:null;if(!n){let t=this.getWorkbook();n=typeof e==`string`&&e.includes(`!`)&&t?t.getRange(e):this.getRange(e)}if(!n||n.isInvalid())return!1;r=n.getCoords(),i=n.getSheet()}if(!r)return!1;let o=bA(e[0],r,n?.fitDestination),s=n?.axis??this._getDefaultShiftAxis(o);return this._getInsertFromRefusal(o,r,s,n?.isCut??!1,i===this)===null}async _insertFrom(e,r,i){if(!r)throw new n.NullNotAllowedError;let a=this._snapShotFromSource(r),o=a.getCoords(),s=bA(e[0],o,i?.fitDestination),c=DA([s]),l=c,u=i?.axis??this._getDefaultShiftAxis(s),d=u===t.IRange.Axis.Row,f={...o},p=i?.isCut??!1,m=this===a.getSource(),h=this._getInsertFromRefusal(s,f,u,p,m);if(h)throw new n.ExpectedError(h);let g=p&&m&&n.CoordUtils.classifyInsertCut(f,s,u)===n.CoordUtils.InsertCutShift.Close,_=this._beginCommit({description:i?.description??(0,n.messageKey)(`op.insertCopiedCells`),operation:{name:`insertFrom`}});try{if(this._insertCells([s],u),await this._copyFrom(s,a,{...i,isCut:(i?.isCut??!1)&&!g}),i?.isCut){if(c=DA([o]),s={...s},g){if(d){let e=f.rowEnd-f.rowStart+1;s.rowStart<=f.rowStart?(f.rowStart+=e,f.rowEnd+=e):(s.rowStart-=e,s.rowEnd-=e)}else{let e=f.colEnd-f.colStart+1;s.colStart<=f.colStart?(f.colStart+=e,f.colEnd+=e):(s.colStart-=e,s.colEnd-=e)}a.getSource().getRanges([f]).delete(u)}l=DA([s])}this._recordChange(_,`address`,e),this._commitWithDirectives(_,l,i,{undo:c})}catch(e){throw _.rollback(),e}return s}_insertCells(e,t,n){this._shiftCells(e,t,!0,n)}_deleteCells(e,t){this._shiftCells(e,t,!1)}_shiftCells(e,r,i,a){(function(e,r,i,a,o){let s;a&&(o??=((t,r)=>{e.validateCoords(t,r??(0,n.t)(`error.sheet.insertOob`))})),i===t.IRange.Axis.Column||i===t.IRange.Axis.Row?(s=i,i={}):i&&(s=i.axis);let c=i?.description??(a?(0,n.messageKey)(`op.insertCells`):(0,n.messageKey)(`op.deleteCells`)),l=(s??e.getDefaultShiftAxis(r[0]))===t.IRange.Axis.Column;if(e.protectionCheck(()=>[l?a?`insertColumns`:`deleteColumns`:a?`insertRows`:`deleteRows`],r,c),mA(r))throw new n.ExpectedError(a?(0,n.t)(`error.sheet.insertOverlapping`):(0,n.t)(`error.sheet.deleteOverlapping`));let u=e.calcGrid.getSpills();for(let e=0;e<r.length;e++)PI(u,r[e],l,a);let d=e.getEntireCoords(),f=d.colEnd,p=d.rowEnd,m=DA(r),h=e.beginCommit({description:c,operation:{name:a?`insertCells`:`deleteCells`}});e.getProtection().isLocked()&&e.recordSkipProtectionCheck(h);let g=e.stateFor(h),_=l?a?t.IRange.Direction.Right:t.IRange.Direction.Left:a?t.IRange.Direction.Down:t.IRange.Direction.Up;try{let n=g.mergeSpatial,s=g.borderSpatial,c=g.fillSpatial,u=g.contentSpatial,v=g.continuousFillSpatial,y=g.dateFormatSpatial,b=g.hyperlinkSpatial,x=g.movableSpatial,S=e.calcGrid,C=e.getView().getFreezePanes().coords,w=C.rowIndex>0||C.colIndex>0,T={...C},E=Cn(r.slice(),t.IRange.Direction.Left),D=E.length;for(let t=0;t<D;t++){let r=E[t];f=Math.min(f,r.colStart),p=Math.min(p,r.rowStart);let i=(a?1:-1)*(l?r.colEnd-r.colStart+1:r.rowEnd-r.rowStart+1);S.shift({range:r,direction:_,commitId:h.getId(),cloneKey:h.getSavepointId()});let m=r.colStart<=d.colStart&&r.colEnd>=d.colEnd,C=r.rowStart<=d.rowStart&&r.rowEnd>=d.rowEnd;w&&(m||C)&&(T=wH(T,r,l,i,d));let D=(e,t,n,r)=>{let i=null;n>1&&(i=e.at(n-1));let a=r-n+1;t?.(n,a),i&&e.updateHeaderPairs([{address:{min:n,max:r},update:i}])};m&&(a?D(e.rowHeaders,e.rowHeadersShiftCallback,r.rowStart,r.rowEnd):e.rowHeadersShiftCallback(r.rowStart,-1*(r.rowEnd-r.rowStart+1))),C&&(a?D(e.columnHeaders,e.columnHeadersShiftCallback,r.colStart,r.colEnd):e.columnHeadersShiftCallback(r.colStart,-1*(r.colEnd-r.colStart+1))),n=n.shift({range:r,direction:_,cloneIfUpdate:n===g.mergeSpatial}),s=s.shift({range:r,direction:_,cloneIfUpdate:s===g.borderSpatial}),c=c.shift({range:r,direction:_,cloneIfUpdate:c===g.fillSpatial}),u=u.shift({range:r,direction:_,cloneIfUpdate:u===g.contentSpatial}),v=v.shift({range:r,direction:_,cloneIfUpdate:v===g.continuousFillSpatial,coordValidator:o}),y=y.shift({range:r,direction:_,cloneIfUpdate:y===g.dateFormatSpatial,coordValidator:o}),b=b.shift({range:r,direction:_,cloneIfUpdate:b===g.hyperlinkSpatial,coordValidator:o}),x=x.shift({range:r,direction:_,cloneIfUpdate:x===g.movableSpatial,coordValidator:o})}let O=g.tables.shift({ranges:E,direction:_,coordValidator:o}),k=g.autoTables.shift({ranges:E,direction:_,coordValidator:o}),A=g.dataValidations.shift({ranges:E,direction:_,coordValidator:o}),j=g.conditionalFormats.shift({ranges:E,direction:_,coordValidator:o}),M=g.protectedRanges.shift({ranges:E,direction:_,coordValidator:o}),N=g.comments.shift({ranges:E,direction:_,coordValidator:o}),P=e.getState().noteSpatial;for(let t=0;t<D;t++)P=P.shift({range:E[t],direction:_,cloneIfUpdate:P===e.getState().noteSpatial,coordValidator:o});let F=g.listeners.shift({ranges:E,direction:_}),I=T.rowIndex!==C.rowIndex||T.colIndex!==C.colIndex;I&&e.getView().setFreezePanes({coords:T}),e.updateState({mergeSpatial:n,borderSpatial:s,fillSpatial:c,contentSpatial:u,continuousFillSpatial:v,dateFormatSpatial:y,hyperlinkSpatial:b,movableSpatial:x,movableMapModel:e.takeShiftedMovableModels()??e.getState().movableMapModel,noteSpatial:P,noteMapModel:e.takeShiftedNoteModels()??e.getState().noteMapModel,tables:O,autoTables:k,dataValidations:A,conditionalFormats:j,protectedRanges:M,comments:N,listeners:F}),e.processLayoutChange(),e.markColumnHeaderTableNames(),e.recordChange(h,`address`,E),I&&e.recordFreezePanes(h,C,T),e.commitWithDirectives(h,m,i,{axis:l?t.IRange.Axis.Column:t.IRange.Axis.Row})}catch(t){throw e.takeShiftedMovableModels(),h.rollback(),t instanceof n.OutOfBoundsError?new n.ExpectedError(t.message||(0,n.t)(`error.sheet.insertOob`)):t}})(this._getMutationCtx(),e,r,i,a)}_processLayoutChange(){let e=this._getState();if(!e)return;this._cellOptions?.renderCellCache?.clear();let t=[...e.movableSpatial.all(),...e.noteSpatial.all()],n=t.length;for(let e=0;e<n;e++)t[e].value.callbacks?.processLayout?.();this._notify(`onLayoutChange`)}_autoFit(e,r){(function(e,r,i){let a=e;if(a._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let o;i={expandOnly:!1,skipCustomSize:!1,minContent:!1,...i};let s=GV(r,a._getEntireCoords(),!0),c=WV(r,a._getEntireCoords(),!0);o=!s&&c?(0,n.messageKey)(`op.autofitColumns`):!c&&s?(0,n.messageKey)(`op.autofitRows`):c&&s?(0,n.messageKey)(`op.autofitAll`):(0,n.messageKey)(`op.autofit`);let l=i.axes!==t.IRange.AxisSelection.Row;a._colHeaders.isProtected()&&(l=!1);let u=i.axes!==t.IRange.AxisSelection.Column;if(a._rowHeaders.isProtected()&&(u=!1),!u&&!l)return;let d=l&&(!1===i.expandOnly||i.expandOnly===t.IRange.Axis.Row),f=u&&(!1===i.expandOnly||i.expandOnly===t.IRange.Axis.Column),p=i.minContent??!1;u&&a._protectionCheck(()=>[`formatRows`],r,o),l&&a._protectionCheck(()=>[`formatColumns`],r,o);let m=DA(r),h=a._beginCommit({description:i.description??o}),g=a._isAdjustHeaders;a._isAdjustHeaders=!0;try{let e=B.getDeviceScale(),o=a._defaultRowHeight()*e,s=a._defaultColWidth(),c={host:a,cellOptions:a._cellOptions,normalStyle:a._styles.getNormal(),isRow:u,isColumn:l,isRowAxis:i.axes===t.IRange.AxisSelection.Row,minContent:p,isFormulaView:_N(a,i),mapCache:new Map},_={isShrinkToFitRow:f,isShrinkToFitColumn:d,updateHeaderOptions:{skipCustomSize:i.skipCustomSize},clampHeight:(e,t=1)=>{if(e===0||t>1)return;let n=Math.max(e??0,o);return f?()=>n:e=>Math.max(e??0,n)},clampWidth:(e,t=1)=>{if(!(e===0||t>1))return d?()=>e:t=>Math.max(t??0,e??s)}},v=kr(r,1);v.sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Column));let y=v.length;for(let e=0;e<y;e++){let t=v[e],{segments:n,rowFloors:r,colFloors:i}=gN(c,t,lN(a,_,t));if(l&&xN(a,_,t,n,i),u){let e=l?vN(n,(e,t)=>sN(a,e,t)):null;e&&mN(c,e,t),SN(a,_,t,n,r)}}a._isAdjustHeaders=g,a._processLayoutChange(),a._recordChange(h,`layout`,r),a._commitWithDirectives(h,i?.autoSelect?m:null,i)}catch(e){throw a._isAdjustHeaders=g,h.rollback(),e}})(this,e,r)}_getBestFit(e,r){return function(e,r,i){let a=e;if(a._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let o=i?.axes!==t.IRange.AxisSelection.Row,s=i?.axes!==t.IRange.AxisSelection.Column,c=a._colHeaders,l=a._rowHeaders,u=a._defaultRowHeight()*B.getDeviceScale(),d={host:a,cellOptions:a._cellOptions,normalStyle:a._styles.getNormal(),isRow:s,isColumn:o,isRowAxis:i?.axes===t.IRange.AxisSelection.Row,minContent:i?.minContent??!1,isFormulaView:_N(a,i),mapCache:new Map},{segments:f,rowFloors:p,colFloors:m}=gN(d,r,r),h,g,_=null;if(o){let e=new Map;wN(m,e),yN(f,r,(t,n,r)=>{r>1||CN(e,t,n??0)}),_=e,h=DN(c,r.colStart,r.colEnd,EN(c,e,c.getDefaultSize()))}else h=c.getSpanSize(r.colStart,r.colEnd+1);if(s){if(_){let e=_,t=c.getDefaultSize(),n=vN(f,(n,r)=>{let i=0;for(let a=n;a<n+r;a++){let n=e.get(a);i+=n===void 0?aN(c,a):TN(c,n>0?n:t)}return i});n&&mN(d,n,r)}let e=new Map;wN(p,e),bN(f,r,(t,n,r,i)=>{if(i>1)return;let a=r??0;for(let r=t;r<=n;r++)CN(e,r,a)});for(let[t,n]of e)n<u&&e.set(t,u);let t=EN(l,e,l.getDefaultSize());g=DN(l,r.rowStart,r.rowEnd,t)}else g=l.getSpanSize(r.rowStart,r.rowEnd+1);return{width:h,height:g}}(this,e,r)}_createRangeEvent(e,t,n){let r=this,i=()=>{let n=r._getState();return this._closed||n.deleted?XV(null):e?Array.isArray(e)?r._createRanges(e):r._createRange(e):XV(this,this._getEntireCoords(),null,t.invalidError)},a=t.trigger;return{getSource:i,getFrom:()=>{let e=t.from;if(e)return e;let a=n;return a||=i().getCoords(),Array.isArray(a)?r._createRanges(a):r._createRanges([a])},getTo:()=>t.to??null,trigger:a,isUndo:t.isUndo??!1,isDataChange:t.isDataChange??!1,getTransactionId:t.getTransactionId,toString:()=>`SheetRangeEvent: ('${a}', ${i().toString()})`,timeStamp:t.timeStamp??Date.now()}}_addListenerNode(e,t,n){return this._registerListenerNode(e,t,n).remove}_registerListenerNode(e,t,r,i=bV){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));if(!t)throw Error((0,n.t)(`error.sheet.listenerNull`));let a=r?{...nV,...r}:nV,o=this,s=gV++%(2**53-1),c=null;this._amendCurrent(()=>{let t=this._getState().listeners.load([{r:[...e],v:void 0}],{createModel:e=>(c=i({nodeId:s,listenerOptions:a,resolveRanges:e=>e?o.getRanges(e):ZV(o),getContainerCoords:()=>o._getState()?.listeners?.getCoords(c)??null}),e.setContainerCallbacks?.({processDelete:()=>{c?.delete()}}),c),addListeners:()=>yV});this._updateState({listeners:t})});let l={node:c,handler:a.weakly?null:t,handlerW:a.weakly?new WeakRef(t):null,options:a,lastCoords:this._getState()?.listeners?.getCoords(c)??null};this._listenerNodes.set(s,l);let u=!1;return{node:c,remove:()=>{u||(u=!0,o._listenerNodes.delete(s),o._removeListenerNode(l.node))}}}_addWatch(e,t,r,i,a){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let o=this,s=null,c=!1,l=null,u=()=>{if(c||o._closed)return;let n=i??{rowIndex:e.rowStart,colIndex:e.colStart},l=typeof t==`string`?t:t.getExpression(),u=l.startsWith(`=`)?l.substring(1):l;s=o._registerWatch(e,u,n,r,!0===a?.arrayFirstCell)};return this._calculation.getStatus()===X.Status.Running?u():l=o._calculation.addListeners({onReady:()=>{l?.(),l=null,u()}},{transactional:!1}),()=>{c||(c=!0,l?.(),s?.())}}_registerWatch(e,t,n,r,i){let a=this,o=this.getId();this._ensureWatchAtCurrent(`added`);let s=this._calculation,c=`watch-${o}-${gV++%(2**53-1)}`,l=-1,u=()=>{let e=a._listenerNodes.get(l);return!e?.watch||a._closed?null:{anchor:e.node,handlers:e.watch}},{host:d,removeNode:f}=this._amendCurrent(()=>{let a=s._createFormulaHost({id:c,shadowOf:o,arrayFirstCell:i,sizeOf:o,onCalculated:e=>{let t=u();t&&t.anchor.deliver(e,t.handlers)}}),{node:d,remove:f}=this._registerListenerNode([e],()=>{u()?.anchor.reconcile()},{transactional:!0,ignoreDataChanges:!0},e=>new jN({...e,host:a}));return l=d.getNodeId(),this._listenerNodes.get(l).watch=r,a.setBody({coords:e,expression:t,authoredAt:n,scopeGridId:o}),{host:a,removeNode:f}});return d.requestPass(),r.onRegistered?.(d),()=>{a._closed||a._ensureWatchAtCurrent(`removed`),f(),a._closed||a._amendCurrent(()=>{d.dispose()})}}_ensureWatchAtCurrent(e){if(this._transactions.isAmendingOtherCommit())throw Error(`A watch can not be ${e} while amending a commit other than the current one.`)}_holdFormulas(e){let t=this,n=this._calculation,r=null,i=gV++%(2**53-1);return n._whenSafe?.(async()=>{if(t._closed)return;let a=e();if(a.length===0)return;let o=t.getId(),s=t._amendCurrent(()=>a.map((e,t)=>{try{let r=n._createFormulaHost({id:`held-${o}-${i}-${t}`,unanchored:!0,arrayFirstCell:!0,sizeOf:o}),a=e.startsWith(`=`)?e.substring(1):e;return{host:r,written:r.setBody({coords:_V,expression:a,authoredAt:vV,scopeGridId:o})}}catch{return null}}));if(await Promise.all(s.map(e=>e?.written.catch(()=>null))),t._closed)return;let c=[];r=s.map(e=>{if(!e)return null;let t=e.host.getBlock()?.getTextAt(0,0);return t?{host:e.host,wired:t}:(c.push(e.host),null)}),c.length>0&&t._amendCurrent(()=>{for(let e=0;e<c.length;e++)c[e].dispose()})}),{getText(e){let n=r?.[e];if(!n||t._closed)return null;let i=n.host.getBlock()?.getTextAt(0,0)??null;return i===n.wired?null:i},release(){if(!r||t._closed)return;let e=r;t._amendCurrent(()=>{for(let t=0;t<e.length;t++)e[t]?.host.dispose()})}}}_moveReferences(e,t){if(this._closed||e.colStart===t.colStart&&e.rowStart===t.rowStart)return;let n=this._getState();if(!n)return;let r=n.listeners.copyTo({colIndex:t.colStart,rowIndex:t.rowStart},e,!0);r!==n.listeners&&this._updateState({listeners:r})}_removeListenerNode(e){let t=this._getState();t&&!this._closed&&t.listeners.getCoords(e)!==null&&this._amendCurrent(()=>{this._updateState({listeners:t.listeners.deleteModel(e)})})}_notifyListenerNodes(e,t,r,i){let a=e?.listeners;if(!a||a.isEmpty()||this._listenerNodes.size===0||!t)return;let o=this._getEntireCoords(),s=new Map,c=t.length;for(let e=0;e<c;e++){let r=n.CoordUtils.intersectRanges(o,t[e]);if(!r)continue;let c=a.search(r),l=c.length;for(let e=0;e<l;e++){let t=c[e].value.getNodeId(),n=this._listenerNodes.get(t);if(!n||(n.options.transactional??!1)!==i)continue;let a=s.get(t);a?a[a.length-1]!==r&&a.push(r):s.set(t,[r])}}s.forEach((e,t)=>{let n=this._listenerNodes.get(t);n&&this._deliverToNode(n,`data`,r,e)})}_notifyListenerNodeMoves(e,t,r){if(this._listenerNodes.size===0)return;let i=e?.listeners;this._listenerNodes.forEach(e=>{if((e.options.transactional??!1)!==t)return;let a=i?i.getCoords(e.node):null;if(!a&&e.node.getContainerCoords()||function(e,t){if(!e||!t)return e===t||!e?.length&&!t?.length;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!n.CoordUtils.isEqualRanges(e[r],t[r]))return!1;return!0}(e.lastCoords,a)||(e.lastCoords=a?[...a]:null,a&&e.node.undelete(),!r))return;let o=a||e.node.isDeleted()?`address`:`restore`;o===`restore`&&t||this._deliverToNode(e,o,r)})}_deliverToNode(e,n,r,i){let a=e.options;if(n===`data`&&a.ignoreDataChanges||n===`address`&&a.ignoreAddressChanges)return;let o=e.handler??e.handlerW?.deref();if(!o)return;let s=e.node.getContainerCoords();n===`data`&&s&&(e.lastCoords=[...s]);let c=s&&s.length===1?s[0]:s,l=this._createRangeEvent(c,{...r,trigger:n,invalidError:e.node.isDeleted()?Qu:t.FormulaError.Label.NA},i);a.once&&(this._listenerNodes.delete(e.node.getNodeId()),this._removeListenerNode(e.node));try{o(l)}catch(e){console.warn(e)}}_notifyUsedRangeChange(){this._lastCellRead.coords=null,this._lastUsedCoordsRead.coords=null,this._notify(`onUsedRangeChange`)}_notify(e){return this._emitter.notify(e)}_notifyConditionalFormatsChange(){this._notify(`onConditionalFormatsChange`),this._notify(`onStyleChange`)}_notifyTablesChange(){this._notify(`onTablesChange`),this._notify(`onStyleChange`)}_notifyDataValidationsChange(){this._notify(`onDataValidationsChange`),this._notify(`onStyleChange`)}_notifyProtectedRangesChange(){this._notify(`onProtectedRangesChange`),this._notify(`onProtectionChange`)}_notifyCommentsChange(){this._notify(`onCommentsChange`),this._notify(`onStyleChange`)}_forwardCollectionListeners(e,t){return(n,r)=>{let i=n.onCollectionChange,a=n.onInvalidated;return this._emitter.addListeners({[e]:i?()=>{i(t())}:void 0,onInvalidated:a?()=>{a(t())}:void 0},r)}}addListeners(e,t){return this._emitter.addListeners(e,t)}_getUsedCoords(e){let t=this._getState();if(!t)return null;let r=this._calcGrid.getValues().getCoords(),i=e?.features;if(i!==void 0){let e=typeof i==`string`?[i]:i;for(let i=0;i<e.length;i++)r=n.CoordUtils.unionRanges(cf(t,this._calcGrid,e[i]),r);return XB(r,this._getEntireCoords())}return r=n.CoordUtils.unionRanges(t.borderSpatial.getContentfulCoords(),r),r=n.CoordUtils.unionRanges(t.fillSpatial.getContentfulCoords(),r),r=n.CoordUtils.unionRanges(t.contentSpatial.getContentfulCoords(),r),r=n.CoordUtils.unionRanges(t.mergeSpatial.getContentfulCoords(),r),r=n.CoordUtils.unionRanges(t.tables.getBoundingRange(),r),r=n.CoordUtils.unionRanges(this._calcGrid.getFormulas().getBoundingRange(),r),r=n.CoordUtils.unionRanges(this._calcGrid.getSpills().getBoundingRange(),r),r=n.CoordUtils.unionRanges(this._calcGrid.getPending().getBoundingRange(),r),r=XB(r,this._getEntireCoords()),r?(this._lastUsedCoordsRead&&this._lastUsedCoordsRead.coords&&gH(this._lastUsedCoordsRead.coords,r)||(this._lastUsedCoordsRead.coords=r,this._lastUsedCoordsRead.range=null),this._lastUsedCoordsRead.coords):(this._lastUsedCoordsRead.coords=null,null)}_getRangeStats(e,r){if(e.length===0)return this._calcGrid.getRangeStats().toLocalCoords([],r);let i=TH(e),a=r?.ignoreHidden;if(a){let e=i[0];for(let t=1;t<i.length;t++)e=n.CoordUtils.unionRanges(e,i[t]);let o=!0===a||a===t.IRange.Axis.Row?fH(this._rowHeaders,e.rowStart,e.rowEnd):null,s=!0===a||a===t.IRange.Axis.Column?fH(this._colHeaders,e.colStart,e.colEnd):null;(o||s)&&(r={...r},o&&(r.processRowSkip=pH(r.processRowSkip,o)),s&&(r.processColumnSkip=pH(r.processColumnSkip,s)))}return this._calcGrid.getRangeStats().toLocalCoords(i,r)}_isContentful(e,t){return!!this._contentCounts(e,void 0,t)}_contentCounts(e,t,n=!1){if(!t){let e=Object.keys(wk.Content),n=e.length;t=[];for(let r=0;r<n;r++){let n=e[r],i=wk.Content[n];i!==wk.Content.Formats&&i!==wk.Content.Tables&&t.push(i)}}let r={},i=t.length,a,o,s=!1;for(let e=0;e<i;e++){let n=t[e];n===wk.Content.Values?r[W.Type.Contentful]=!1:n===wk.Content.Formulas?r[W.Type.Formula]=!1:n===wk.Content.Formats?(r[W.Type.BorderStyle]=!1,r[W.Type.FillStyle]=!1,r[W.Type.ContentStyle]=!1):n===wk.Content.Tables&&(r[W.Type.Table]=!1,s=!0)}let c=()=>{a=new Set,o={};for(let e=0;e<i;e++){let n=t[e];o[n]=0}},l=e.length;for(let t=0;t<l;t++){let i=e[t],l=this._rangeStateIterator({searchTypes:r,ignoreHidden:n,bounds:i}),u=l.next();for(;!u.done;){o||c();let e=u.value,t=(e.end.colIndex-e.start.colIndex+1)*(e.end.rowIndex-e.start.rowIndex+1),n=e.intersection;if(n){n.contentful&&(o[wk.Content.Values]=(o[wk.Content.Values]??0)+t),n.formula&&(o[wk.Content.Formulas]=(o[wk.Content.Formulas]??0)+t);let e=n.table;e&&(s&&!a.has(e)&&(o[wk.Content.Tables]=(o[wk.Content.Tables]??0)+1,a.add(e)),n.contentful||(o[wk.Content.Values]=(o[wk.Content.Values]??0)+t))}u=l.next()}}return o}_featureCounts(e,t,n=!1){let r=gv.Feature,i=Object.values(r),a=t===void 0?i:Vj(t),o={};for(let e=0;e<i.length;e++)o[i[e]]=0;e.length>1&&(e=TH(e));let s=new Map;for(let e=0;e<a.length;e++){let t=a[e],n=of[t];if(n===null)continue;let r=s.get(n);r?r.push(t):s.set(n,[t])}let c=e.length;for(let[t,i]of s){let a=t===W.Type.ContentStyle,s={[t]:!1};t===W.Type.Unlock&&(s[W.Type.ContentStyle]=!1);for(let t=0;t<c;t++){let c=this._rangeStateIterator({searchTypes:s,ignoreHidden:n,bounds:e[t]}),l=c.next();for(;!l.done;){let e=l.value,t=e.intersection;if(t){let n=(e.end.colIndex-e.start.colIndex+1)*(e.end.rowIndex-e.start.rowIndex+1);if(a){let a=t.contentStyle?.getPropertiesAt(e.start.rowIndex,e.start.colIndex,null);if(a)for(let e=0;e<i.length;e++){let t=i[e];(t===r.NumberFormat&&a.numberFormat!==void 0||t===r.Alignment&&a.alignment!==void 0||t===r.Font&&a.font!==void 0||t===r.Protection&&a.protection!==void 0)&&(o[t]+=n)}}else for(let e=0;e<i.length;e++){let r=i[e];oV(t,r,this._styles)&&(o[r]+=n)}}l=c.next()}}}return new iV(o)}async _dependencyRanges(e,t,n){let r=this._calcGrid;if(!r)return null;let i=e.scope&&e.scope===this.getName()?{...e,scope:void 0}:e,{cells:a,names:o}=await r.getGraphNeighborsAt(i,t,n);if(this._closed)return null;let s=this._toRangeScopes(a),c=this._namedGraphRanges(o);return s.length!==0||c?this._createRanges(c?[...c,...s]:s):null}_namedGraphRanges(e){if(e.length===0)return null;let t=this._calculation?.getNamedFormulas()??null,n=this._internal,r=Array(e.length);for(let i=0;i<e.length;i++){let a=e[i];r[i]=new Xj(a,t,(a.sheetName?qV(n,a.sheetName):null)??n,null)}return r}_toRangeScopes(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(!i.scope){n.push(i);continue}let a=this._resolveSheetScope(i.scope);a?n.push({...i,scope:a}):t?.add(i.scope)}return n}_resolveSheetScope(e){if(this.getId()===e)return this.getName();let t=this._workbook?.getSheets().getItems();if(t){for(let n of t)if(n.getId()===e)return n.getName()}return null}_featureRegions(e,r,i){let a=gv.Feature,o=i?.containment===`fullyContained`,s={},c=[],l=[];for(let e=0;e<r.length;e++){let t=r[e];switch(t){case a.NumberFormat:case a.Alignment:case a.Font:case a.Protection:c.push(t),s[W.Type.ContentStyle]=!1;break;case a.Unlock:s[W.Type.Unlock]=!1,s[W.Type.ContentStyle]=!1,l.push(t);break;default:{let e=of[t];if(e===null)return[];s[e]=!1,l.push(t)}}}let u=l.includes(a.Contentful),d=l.includes(a.Unlock),f=l.includes(a.Fill),p=[];for(let e=0;e<l.length;e++)l[e]!==a.Contentful&&l[e]!==a.Fill&&p.push(of[l[e]]);let m=[];for(let e=0;e<c.length;e++)switch(c[e]){case a.NumberFormat:m.push(`numberFormat`);break;case a.Alignment:m.push(`alignment`);break;case a.Font:m.push(`font`);break;case a.Protection:m.push(`protection`)}m.length>0&&m.push(`named`);let h=new Map,g=(e,t)=>{if(!e)return``;let r=h.get(e);if(r===void 0){let i=e.getPropertiesAt(0,0,null);if(i)if(t){let e=Array(t.length);for(let n=0;n<t.length;n++)e[n]=i[t[n]]??null;r=n.BufferUtils.JSONStableStringify(e)}else r=n.BufferUtils.JSONStableStringify(i);else r=``;h.set(e,r)}return r},_=e=>{let t=[];u&&t.push(!!e.contentful),d&&t.push(zh(this._styles,e.contentStyle?.getPropertiesAt(0,0,null))),f&&t.push(g(e.fillStyle,null));for(let n=0;n<p.length;n++)t.push(e[p[n]]);return m.length>0&&t.push(g(e.contentStyle,m)),t},v=new Map,y=Symbol(`rects`),b=e=>{let t=v;for(let n=0;n<e.length;n++){let r=t.get(e[n]);r||(r=new Map,t.set(e[n],r)),t=r}let n=t.get(y);return n||(n=[],t.set(y,n)),n},x=this._rangeStateIterator({searchTypes:s,ignoreHidden:i?.ignoreHidden??!1,bounds:e,fullyContained:o}),S=x.next();for(;!S.done;){let t=S.value,n=t.intersection;if(n){let r=!1;for(let e=0;!r&&e<l.length;e++)r=oV(n,l[e],this._styles);if(!r&&c.length>0){let e=n.contentStyle?.getPropertiesAt(t.start.rowIndex,t.start.colIndex,null);if(e)for(let t=0;!r&&t<c.length;t++){let n=c[t];r=n===a.NumberFormat&&e.numberFormat!==void 0||n===a.Alignment&&e.alignment!==void 0||n===a.Font&&e.font!==void 0||n===a.Protection&&e.protection!==void 0}}r&&b(_(n)).push({rowStart:Math.max(t.start.rowIndex,e.rowStart),colStart:Math.max(t.start.colIndex,e.colStart),rowEnd:Math.min(t.end.rowIndex,e.rowEnd),colEnd:Math.min(t.end.colIndex,e.colEnd)})}S=x.next()}let C=[],w=e=>{for(let[n,r]of e)n===y?C.push(...Or(r,t.IRange.Axis.Column,2**53-1)):w(r)};w(v);let T=i?.axis===t.IRange.Axis.Column,E=!0===i?.reverse;return C.sort((e,t)=>{let n=T?e.colStart-t.colStart||e.rowStart-t.rowStart:e.rowStart-t.rowStart||e.colStart-t.colStart;return E?-n:n}),C}find(e){return e?((e=typeof e==`string`?{text:e}:{...e}).from||(e.from=this.getSelection().getCoords().cell),this.getEntireRange().find(e)):Bt}setEntireSize(e,r){e||=dV;let i=this._getEntireCoords(),a=i.colEnd-i.colStart+1,o=i.rowEnd-i.rowStart+1,s=e?.width??a,c=e?.height??o;if(s===a&&c===o)return this;let l=this._beginCommit({description:r?.description??(0,n.messageKey)(`op.setEntireSize`),operation:{name:`setEntireSize`}});try{s<a&&this._deleteCells([{colStart:s,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd}],t.IRange.Axis.Column),c<o&&this._deleteCells([{colStart:i.colStart,rowStart:c,colEnd:i.colEnd,rowEnd:i.rowEnd}],t.IRange.Axis.Row);let e=Object.freeze({colStart:0,rowStart:0,colEnd:s-1,rowEnd:c-1}),u=this._getState(),d=u.borderSpatial.clone();d.setEntireCoords(e);let f=u.fillSpatial.clone();f.setEntireCoords(e);let p=u.contentSpatial.clone();p.setEntireCoords(e),this._updateState({entireCoords:e,borderSpatial:d,fillSpatial:f,contentSpatial:p}),this._entireCoordsCache=null,this._entireRangeCache=null,this._calcGrid.resize(this._requestFor(l)),this._emitter.notify(`onViewChange`,{source:this.getView()}),this._colHeaders._invalidateExtent(),this._rowHeaders._invalidateExtent(),s>a&&this._insertCells([{colStart:i.colEnd+1,rowStart:e.rowStart,colEnd:s-a+i.colEnd,rowEnd:e.rowEnd}],t.IRange.Axis.Column),c>o&&this._insertCells([{colStart:e.colStart,rowStart:i.rowEnd+1,colEnd:e.colEnd,rowEnd:c-o+i.rowEnd}],t.IRange.Axis.Row);let m=this.getSelection().getCoords(),h=TA(m,n.CoordUtils.EmptySelection,e);this._notify(`onLayoutChange`),this._recordSelection(l,h,r,m),l.commit(r)}catch(e){throw l.rollback(),e}return this}_find(e,r){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));typeof r==`string`&&(r={text:r});let i=r?.text;if(!i)return Bt;let a=[...e],o=r?.axis??t.IRange.Axis.Row,s=r?.reverse,c=!r?.disableWrap,l=r?.from?this._cellToCoords(r?.from):null,u=null;if(l){let e=-1;for(let t=0;e===-1&&t<a.length;t++)n.CoordUtils.isCellWithinRange(l,a[t])&&(e=t);u=n.CoordUtils.cellToRange(l);let t=hA(a[e],u,o);t.push(u);let r=n.CoordUtils.createRangeComparator(o,s);t.sort(r);let i=-1,d=t.length;for(let e=0;e<d;e++)r(t[e],u)<=0&&(i=e);a.splice(e,1,...t);let f=e+i,p=[];for(let e=0;e<=f;e++)p.push(a.shift());if(c){let e=p.length;for(let t=0;t<e;t++)a.push(p[t])}}if(a.length===0)return Bt;let d=r?.fields?.includes(wk.Content.Formulas)??!1,f=r?.fields?.includes(wk.Content.Values)??!0,p=r?.matchEntireCell??!1,m=r?.matchCase??!1,h=r?.useRegex??!1,g=function(e,t,n){let r=t?``:`i`;return n?new RegExp(e,r):new RegExp((e=>{let t=e.replace(/[|\\{}()[\]^$+.]/g,`\\$&`);return t=t.replace(/~\?/g,`\\?`),t=t.replace(/~\*/g,`\\*`),t=t.replace(/~~/g,`~`),t})(e),r)}(i,m,h),_=i.length,v=(e,t)=>{let n=e=>{if(!e)return!1;let t=!!e.match(g);return t&&p&&e.length!==_&&(t=!1),t},r=t.getCell(),i=!1;return!i&&d?i=n(r.getFormulaText({target:`display`})??r.getText(SV)):f&&(i=n(r.getNumberFormat().displayText)),i};if(r?.matchCustom){let e=r.matchCustom,t={matchCase:m,matchEntireCell:p,useRegex:h,fields:r?.fields??[wk.Content.Formulas]},n,i,a=v,o=()=>a(n,i);v=(r,a)=>(n=r,i=a,e(r,o,t,a))}let y=-1,b=null,x=zt,S=!1,C=()=>{if(x.done){if(y++,y>=a.length)return S=!0,!1;b=this._cellIterator({reverse:s,axis:o,searchTypes:!1,bounds:a[y]})}if(x=b.next(),!x.done){let e=x.value;return v(e.value,e.context)}return!1};return{next:()=>{let e=null;for(;!S&&!e;)C()&&(e=x.value.context.getCell());return e?{value:e,done:!1}:zt}}}getRuntime(){return this._runtime}_getTraverseRegion(e,t,n){let r=this._getState().tables.search({rowStart:e.rowIndex,colStart:e.colIndex,rowEnd:e.rowIndex,colEnd:e.colIndex});return r.length===0?null:r[0].value._getTraverseRegion(e,t,n)}_surroundingRegion(e,t){let r=this._getState(),i=t?.contentOnly??!1,a=this._getEntireCoords();if(!i){let t=r.tables.search(e);if(t.length>0){let r=t[0].value,i=r.getDataRange().getCoords(),o=r.getRange().getCoords();return n.CoordUtils.isEqualRanges(i,e)?o:n.CoordUtils.isEqualRanges(o,e)?a:i}}let o=i?e:a;return function(e,t,r=2e4){if(!t||t.length===0)return null;let i=null,a=!1;for(let r=0;r<t.length;r++){let o=t[r];o&&(i=n.CoordUtils.unionRanges(i,o.getBoundingRange()),a||=o.search(e).length>0)}if(!i)return null;let o={...n.CoordUtils.EmptyRange},s=e,c=a?{...e}:null;if(!c){let r=(e=>{let r=[],i=t.length;for(let n=0;n<i;n++){let i=t[n];if(!i)continue;let a=i.search(e),o=a.length;r=o>0?Array(o):void 0;for(let e=0;e<o;e++){let t=a[e];r[e]=t}}return r||n.CommonUtils.EmptyArray})({colStart:e.colEnd,rowStart:e.rowEnd,colEnd:e.colEnd+1,rowEnd:e.rowEnd+1}),i=r.length;if(i>0){c={...e};for(let e=0;e<i;e++){let t=r[e];c.colEnd=Math.max(c.colEnd,t.colStart),c.rowEnd=Math.max(c.rowEnd,t.rowStart)}}}let l={...n.CoordUtils.EmptyRange},u=()=>{let e=t.length;for(let r=0;r<e;r++){let e=t[r];if(!e)continue;let i=e.search(o),a=i.length;for(let e=0;e<a;e++){let t=i[e];c=n.CoordUtils.unionRanges(c,t,l)}}return c};o.colStart=e.colStart,o.rowStart=e.rowStart,o.colEnd=e.colEnd,o.rowEnd=e.rowEnd,u();let d={...c},f={...n.CoordUtils.EmptyRange},p=0;do{if(o.colStart=f.colStart=d.colStart,o.rowStart=f.rowStart=d.rowStart,o.colEnd=f.colEnd=d.colEnd,o.rowEnd=f.rowEnd=d.rowEnd,d.colStart>i.colStart&&(o.colStart=d.colStart-1,o.colEnd=d.colStart-1,o.rowStart=d.rowStart-1,o.rowEnd=d.rowEnd+1,u()),d.rowStart>i.rowStart&&(o.rowStart=d.rowStart-1,o.rowEnd=d.rowStart-1,o.colStart=d.colStart-1,o.colEnd=d.colEnd+1,u()),d.colEnd<i.colEnd&&(o.colStart=d.colEnd+1,o.colEnd=d.colEnd+1,o.rowStart=d.rowStart-1,o.rowEnd=d.rowEnd+1,u()),d.rowEnd<i.rowEnd&&(o.rowStart=d.rowEnd+1,o.rowEnd=d.rowEnd+1,o.colStart=d.colStart-1,o.colEnd=d.colEnd+1,u()),!c)return null;if(d.colStart=c.colStart,d.rowStart=c.rowStart,d.colEnd=c.colEnd,d.rowEnd=c.rowEnd,n.CoordUtils.isEqualRanges(d,f))return n.CoordUtils.isEqualRanges(s,d)?null:d;if(n.CoordUtils.isEqualRanges(d,s))return null;if(n.CoordUtils.isEqualRanges(d,f))return d;p++}while(p<r);return null}(e,[this._calcGrid.getContentful(),r.mergeSpatial,this._calcGrid.getFormulas(),this._calcGrid.getSpills(),this._calcGrid.getPending()])||o}_extendRange(e,r){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let i={...this._getEntireCoords()},a=this.getRowHeaders(),o=this.getColumnHeaders(),s=(this._cacheTableColumnHeaders?.table)?.getRange().getCoords(),c=!1;if(s){let n={...s};n.rowStart+=a.hiddenHeadersAt(n.rowStart,!1),n.rowEnd-=a.hiddenHeadersAt(n.rowEnd,!0),n.colStart+=o.hiddenHeadersAt(n.colStart,!1),n.colEnd-=o.hiddenHeadersAt(n.colEnd,!0),(e===t.IRange.Direction.Up&&r.rowIndex>n.rowStart||e===t.IRange.Direction.Down&&r.rowIndex<n.rowEnd||e===t.IRange.Direction.Left&&r.colIndex>n.colStart||e===t.IRange.Direction.Right&&r.colIndex<n.colEnd)&&(c=!0),c&&(i=n)}i.rowStart+=a.hiddenHeadersAt(i.rowStart,!1),i.rowEnd-=a.hiddenHeadersAt(i.rowEnd,!0),i.colStart+=o.hiddenHeadersAt(i.colStart,!1),i.colEnd-=o.hiddenHeadersAt(i.colEnd,!0);let l=this,u=[],d={ignoreHidden:!0,onFound:(e,t)=>{u.push(n.CoordUtils.intersectRanges(e,t))},onEntry:(e,t)=>t},f={ignoreHidden:!0,onEntry:(e,t)=>e.tvTl()===void 0?null:t},p=this._getState();if(!p)return n.CommonUtils.EmptyArray;let m,h=l._getRangedEntries(p.mergeSpatial,[n.CoordUtils.cellToRange(r)],f);h.length>0&&(m=h[0]);let g=[e=>l._getRangedEntries(l._getState().mergeSpatial,e,f),e=>(u=[],l._getRangedEntries(l._calcGrid.getContentful(),e,d),u)];return c||g.push(e=>(u=[],l._getRangedEntries(l._getState().tables,e,d),u)),function(e,r,i,a,o){let s,c,l,u={...r},d=n.CoordUtils.cellToRange(u),f=a(d).length>0;if(f){let r=1,o=e===t.IRange.Direction.Up||e===t.IRange.Direction.Down;i&&(r+=o?i.rowEnd-i.rowStart:i.colEnd-i.colStart),e!==t.IRange.Direction.Left&&e!==t.IRange.Direction.Up||(r=-r),o?u.rowIndex+=r:u.colIndex+=r,d=n.CoordUtils.cellToRange(u),f=a(d).length>0}switch(e){case t.IRange.Direction.Up:d.rowStart=Math.min(o.rowStart,d.rowStart),c=a(d).sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Row,!0)),s=r.rowIndex,l=f?c.length===1&&s===c[0].rowStart?o.rowStart:c[0].rowStart:c.length===0?o.rowStart:c[0].rowEnd;break;case t.IRange.Direction.Down:d.rowEnd=Math.max(o.rowEnd,d.rowEnd),c=a(d).sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Row,!1)),s=r.rowIndex,l=f?c.length===1&&s===c[0].rowEnd?o.rowEnd:c[0].rowEnd:c.length===0?o.rowEnd:c[0].rowStart;break;case t.IRange.Direction.Left:d.colStart=Math.min(o.colStart,d.colStart),c=a(d).sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Column,!0)),s=r.colIndex,l=f?c.length===1&&s===c[0].colStart?o.colStart:c[0].colStart:c.length===0?o.colStart:c[0].colEnd;break;case t.IRange.Direction.Right:d.colEnd=Math.max(o.colEnd,d.colEnd),c=a(d).sort(n.CoordUtils.createRangeComparator(t.IRange.Axis.Column,!1)),s=r.colIndex,l=f?c.length===1&&s===c[0].colEnd?o.colEnd:c[0].colEnd:c.length===0?o.colEnd:c[0].colStart}let p=c?c.length:0;if(f&&p>1){let n=!1;for(let r=1;!n&&r<p;r++){let i=c[r];switch(e){case t.IRange.Direction.Up:i.rowEnd<l-1?n=!0:l=Math.min(l,i.rowStart);break;case t.IRange.Direction.Down:i.rowStart>l+1?n=!0:l=Math.max(l,i.rowEnd);break;case t.IRange.Direction.Left:i.colEnd<l-1?n=!0:l=Math.min(l,i.colStart);break;case t.IRange.Direction.Right:i.colStart>l+1?n=!0:l=Math.max(l,i.colEnd)}}}let m=n.CoordUtils.cellToRange(r);switch(e){case t.IRange.Direction.Up:m.rowStart=l;break;case t.IRange.Direction.Down:m.rowEnd=l;break;case t.IRange.Direction.Left:m.colStart=l;break;case t.IRange.Direction.Right:m.colEnd=l}return m}(e,r,m,e=>{let t=[],n=[e],r=g.length;for(let e=0;e<r;e++){let r=(0,g[e])(n),i=r.length;for(let e=0;e<i;e++){let n=r[e];t.push(n)}}return t},i)}_defaultFontDims(){if(this._defaultFontBoundsCache)return this._defaultFontBoundsCache;let e=this._styles.getNormal(),t=0,n=0;for(let r=0;r<=9;r++){let i=e.measureText(r.toString());t=Math.ceil(Math.max(i.width,t)),n=Math.max(i.lineHeight,n)}return this._defaultFontBoundsCache={width:t,height:n},this._defaultFontBoundsCache}getColumnWidthAsFontUnit(e){let t=Math.round(this._defaultFontDims().width),n=e/(this.getView().isShowFormulas()?2:1);if(!t||!e)return 0;let r=5;return n<r+t&&(r=n*(r/(r+t))),(n-r)/t}_createTupleBuilder(e=!1){return e?new z.TransposedBuilder:new z.Builder}_defaultColWidth(){if(this._defaultColWidthCache)return this._defaultColWidthCache;let e=this._defaultFontDims()?.width||7,t=8*Math.round((8*e+5)/8)/Math.round(this._defaultFontDims().width);return this._defaultColWidthCache=t}_defaultRowHeight(){if(this._defaultRowHeightCache)return this._defaultRowHeightCache;let e=this._defaultFontDims();if(!e||e.width===0)return this._defaultRowHeightCache=20/B.getDeviceScale(),this._defaultRowHeightCache;let t=e.height;return this._defaultRowHeightCache=Math.round(t/B.getDeviceScale()*4)/4,this._defaultRowHeightCache}getProtection(){return this._protection??null}async _scrollIntoView(e,r){if(!r)return!0;!0===r&&(r=n.CommonUtils.EmptyObject);let i=r.axis,a=e;i===t.IRange.Axis.Column?a={colStart:e.colStart,rowStart:void 0,colEnd:e.colEnd,rowEnd:void 0}:i===t.IRange.Axis.Row&&(a={colStart:void 0,rowStart:e.rowStart,colEnd:void 0,rowEnd:e.rowEnd});let o={coords:a},s=await this._emitter.notify(`onRequestScrollIntoView`,{params:o,async:!0});if(!s)return!1;let c=s.length;for(let e=0;e<c;e++)if(!1===s[e])return!1;return!0}async _selectSheet(e,t){return!1!==await this._options.container?.requestSelect?.()&&this._scrollIntoView(e,t)}async scrollTo(e,t){let n={...t,coords:e},r=await this._emitter.notify(`onRequestScrollIntoView`,{params:n,async:!0});if(!r)return!1;let i=r.length;for(let e=0;e<i;e++)if(!1===r[e])return!1;return!0}_resolveSelectOptions(e,t){return e?(!0===e&&(e={autoFocus:!0,scrollIntoView:!0}),!0===e.scrollIntoView&&(e={...e,scrollIntoView:{}}),t&&(e={...e,scrollIntoView:{axis:t,...e?.scrollIntoView}}),e):null}_commitWithDirectives(e,t,r,i){if(t&&(this._recordSelection(e,t,r,i?.undo,i?.axis),r?.autoFit)){let i=t.ranges?.length?t.ranges:t.cell?[n.CoordUtils.cellToRange(t.cell)]:null;i&&this._recordAutoFit(e,i,r.autoFit)}e.commit(i?.commit)}_recordSelection(e,t,n,r,i){let a=n?.autoSelect,o=n?.autoSelectRestore===void 0?a:n.autoSelectRestore,s={sheetId:this.getId(),viewId:this.getView().getId(),selection:t,options:!!a&&(this._resolveSelectOptions(a,i)??!0),restoreOptions:!!o&&(this._resolveSelectOptions(o,i)??!0),nested:UN(e)};r&&(s.undo=r),e.setIntent(FN,e=>e?[...e,s]:[s])}_restoredSelection(e,t){return WN(e,this.getId(),this.getView().getId(),t?`undo`:`redo`)}_recordChange(e,t,n){if(!n||n.length===0)return;let r=this.getId(),i=e.getId();e.setIntent(`sheet.events`,e=>{let a={...e},o={...a[r]};return o[t]=HN(o[t],n,i),a[r]=o,a})}_recordFormulasEntered(e,t){if(!t||t.length===0)return;let n=this.getId(),r=e.getId();e.setIntent(PN,e=>{let i={...e};return i[n]=HN(i[n],t,r),i})}_sheetEvents(e){return e?.[`sheet.events`]?.[this.getId()]??null}_changedRanges(e,t){let n=this._sheetEvents(e);if(!n)return null;let r=t??Object.keys(n),i=null,a=r.length;for(let e=0;e<a;e++){let t=n[r[e]];t&&t.length!==0&&(i?i.push(...t):i=[...t])}return i}_recordAutoFit(e,t,n){if(!n||t.length===0)return;let r=!0===n?void 0:n,i=this.getId();e.setIntent(LN,e=>{let n=e?[...e]:[],a=n.find(e=>e.sheetId===i&&e.options===r);return a?n[n.indexOf(a)]={...a,ranges:[...a.ranges,...t]}:n.push({sheetId:i,ranges:[...t],options:r}),n})}_recordAutoFormat(e){let t=this.getId();e.setIntent(BN,e=>e?.includes(t)?e:[...e??[],t])}_recordSkipProtectionCheck(e){let t=this.getId();e.setIntent(`sheet.skipProtectionCheck`,e=>e?.includes(t)?e:[...e??[],t])}_recordInitial(e){let t=this.getId();e.setIntent(`sheet.initial`,e=>e?.includes(t)?e:[...e??[],t]),this._recordSkipProtectionCheck(e)}_recordFreezePanes(e,t,n){let r=this.getId();e.setIntent(RN,e=>({...e,[r]:{before:e?.[r]?.before??t,after:n}}))}_recordMovableSelection(e,t,n){let r=n??this._transactions.getPendingTransaction();if(!r)return;let i=this.getId(),a=this.getView().getId(),o=t.map(e=>e.getId());r.setIntent(zN,t=>{let n=t?.[i];return{...t,[i]:e===`before`?{viewId:a,before:n?.before??o,after:n?.after}:{viewId:a,before:n?.before,after:o}}})}_restoredMovableSelection(e,t){let n=e?.[zN]?.[this.getId()];if(!n||n.viewId!==this.getView().getId())return null;let r=t?n.before??n.after:n.after??n.before;if(!r)return null;let i=new Map,a=this.getMovables().getItems();for(let e=0;e<a.length;e++)i.set(a[e].getId(),a[e]);let o=[];for(let e=0;e<r.length;e++){let t=i.get(r[e]);t&&o.push(t)}return o}_amendCurrent(e){return this._amendBookkeeping(this._transactions.getCurrentCommit(!1).getId(),e)}_amendBookkeeping(e,t){let n=this._transactions.getPendingTransaction()===null;return this._transactions.amend(e,e=>(n&&this._recordSkipProtectionCheck(this._transactions.getPendingTransaction()),t(e)))}_resolveAutoFit(e){let t=e.getIntents()[LN];if(!t)return;let n=this.getId(),r=t.length;for(let e=0;e<r;e++){let r=t[e];r.sheetId===n&&this._autoFit(r.ranges,r.options??sV)}}_onRootTransactionClose(e){let t=this._selectionAtCommitStart;this._selectionAtCommitStart=null;let r=WN(e.getIntents(),this.getId(),this.getView().getId(),`forward`);r&&t&&n.CoordUtils.isEqualSelectionCoords(t,this.getSelection().getCoords())&&this._autoSelect(r.options,r.selection)}_normalizeSelection(e){let t=this._view?.getRangeSelection();if(!t)return;let r=t.getCoords(),i=this._getEntireCoords(),a=!n.CoordUtils.isCellWithinRange(r.cell,i),o=r.ranges??n.CommonUtils.EmptyArray;for(let e=0;!a&&e<o.length;e++)a=!!o[e]&&!n.CoordUtils.isRangeWithinRange(o[e],i);if(a&&(r=TA(r,n.CoordUtils.EmptySelection,i)),e){let e=r.cell,t=this._getMerges([n.CoordUtils.cellToRange(e)])[0];!t||t.rowStart===e.rowIndex&&t.colStart===e.colIndex||(r={...r,cell:{rowIndex:t.rowStart,colIndex:t.colStart}})}t.updateCoords(r)}async _autoSelect(e,t,r){if(!e)return n.CommonUtils.EmptyArray;let i=this._resolveSelectOptions(e,r),a=i?.autoFocus,o=i?.scrollIntoView,s=i?.anchor,c=this.getSelection().getCoords(),l=EA(t??null),u=this._getEntireCoords(),d=SH(l,this._getState().mergeSpatial,u),f=-1,p=null;if(!s){let e=c?.cell,t=d.length;for(let r=0;f===-1&&r<t;r++){let t=d[r];n.CoordUtils.isCellWithinRange(e,t)&&(f=r,p=e)}}let m=DA(d,p,f);this.getSelection().updateCoords(m);let h=n.CoordUtils.cellToRange(m.cell);if(i?.preserveSelectedSheet)return await this._scrollIntoView(h,o),d;{let e=await this._selectSheet(h,o);if(!1!==o&&!1===e)return d}if(!1!==a){let e=await this._notify(`onRequestFocus`);if(!e)return d;let t=e.length;for(let n=0;n<t;n++)if(!1===e[n])return d}return d}getSelection(){return this.getView().getRangeSelection()}getSelectedCell(){return this.getSelection().getCell()}getSelectedRange(e){return this.getSelection().getRange(e)}getSelectedRanges(e){return this.getSelection().getRanges(e)}getView(){return this._view}setView(e){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));if(!e)throw new n.ExpectedError((0,n.t)(`error.sheet.emptyView`));this._viewRemoveListener?.(),this._view=e;let t=this._viewListener;return this._viewRemoveListener=e.addListeners(t,{transactional:!1}),t.onTopLeftChange?.(e),t.onFreezePaneChange?.(e),t.onHeaderChange?.(e),t.onZoomScaleChange?.(e),t.onSelectionChange?.(e),t.onMovableSelectionChange?.(e),t.onAnyChange?.(e),this._emitter.notify(`onViewChange`,{source:e}),this}getTabColor(){return this._tabColor}setTabColor(e){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));return this._tabColor=typeof e==`string`?this._styles.parseColor(e):e??null,this._notify(`onTabColorChange`),this}getCodeName(){return this._codeName}getOutlineSettings(){return this._outlineSettings}isConditionalFormatCalculationEnabled(){return this._conditionalFormatCalculation}_isModulesReadOnly(){return this.getWorkbook()?._isStructureProtected?.()??!1}getModules(){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));return this._modules}getRowHeaders(){return this._rowHeaders}getColumnHeaders(){return this._colHeaders}_openCalcGrid(e){let n=this,r=this._calculation,i=r._createCalcGrid({getEntireCoords:()=>n._getEntireCoords(),name:n.getName()??null,isOwned:!0,valuesAxis:n._isDataColumn?t.IRange.Axis.Column:t.IRange.Axis.Row,uuid:n.getId()});return i.addListeners({onComplete(e,t){n._realizeCalcedValues(t)},onFormulasChanged(e,t){n._closed||(n._invalidateCaches(),t&&!n._initializing&&n._notify(`onDataChange`))},onInputsWritten(e,t){if(n._closed)return;n._updateState({inputsCommitId:t.inputsId});let r=n._transactions.getCurrentTransaction();t.arrays&&r&&n._recordChange(r,`spills`,t.arrays)}}),e&&i.seed(e).catch(e=>r._reportError(e)),i}async toJSON(e){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));await Promise.resolve(this._starting);let r=this.getCalculation();r.getStatus()!==X.Status.Off&&await r.ready(),await this._emitter.notify(`onBeforeSave`,{async:!0});let i={},a=this._getState();if(!a)return i;let o=this._getEntireCoords(),s=null;{let n=e?.ignoreData??!1,r=e?.ignoreFormulas,a;n&&r||(s=await this._calcGrid.toJSON());try{if(!n){a=this._strings.beginPersist();let e=[],n=this._cellStateIterator({searchTypes:!1,axis:t.IRange.Axis.Column}),r=n.next(),o=-(2**53-1),s=-(2**53-1),c=null,l=null,u=null,d=null;for(;!r.done;){let i=r.value[0],f=i.colIndex,p=i.rowIndex;f!==o&&(d&&e.push(d),c=[],u=[],d=[f,u],o=f,s=p-2),p>s+1&&(c=[],l=[p,c],u.push(l));let m=r.value[1],h=IH(m),g;if(h===t.ScalarType.Number)g=m;else if(h===t.ScalarType.Boolean)g=m;else if(h===t.ScalarType.String)g=``+a.add(m);else if(h===t.ScalarType.Error)g={t:`e`,v:m.getCode()};else if(h===t.ScalarType.RichData){let e=m,t=e.getType(),n=e?.toJSON?.();t&&n&&(g={t:`r`,v:0})}else console.warn(`error`,g);c.push(g),s=p,r=n.next()}d&&e.push(d),e.length>0&&(i.data=e)}a&&this._ownStrings&&(i.strings=await a.toJSONAsync())}finally{a?.endPersist()}let c=o.colEnd+1,l=o.rowEnd+1;if(c!==dV.width||l!==dV.height){let e={};c!==dV.width&&(e.width=c),l!==dV.height&&(e.height=l),i.entireSize=e}let u=this._colHeaders.toJSON();u&&(u.headers&&u.headers.length>0&&(i.cols=u.headers),u.defaultSize!==void 0&&u.defaultSize!==-1&&(i.defaultColSize=u.defaultSize));let d=this._rowHeaders.toJSON();d&&(d.headers&&d.headers.length>0&&(i.rows=d.headers),d.defaultSize!==void 0&&d.defaultSize!==-1&&(i.defaultRowSize=d.defaultSize));let f=this.getProtection().toJSON();f&&(i.protection=f);let p=this._view.toJSON();p&&(i.view=p),this._tabColor&&(i.tabColor=this._tabColor.toString()),this._codeName&&(i.codeName=this._codeName);let m={};for(let e of Object.keys(fV))this._outlineSettings[e]!==fV[e]&&(m[e]=this._outlineSettings[e]);Object.keys(m).length>0&&(i.outline=m),this._conditionalFormatCalculation||(i.conditionalFormatCalculation=!1);let h=this._modules?.toJSON();h&&Object.keys(h).length>0&&(i.modules=h)}if(!e?.ignoreStyles){let r=Cn(a.mergeSpatial.all());r.length>0&&(i.merges=xd(r));let s=Cn(this._composeDirectStyleView().all());if(s.length>0){let r=this._styles.beginPersist(),a=e?.splitDirectBorders,c=e?.includeHeaderStyles;try{let e=s.length,l=[];for(let t=0;t<e;t++){let e=s[t],i=e.value.toJSON();if(!i)continue;let c=!0;if(a&&i.borders&&!n.CoordUtils.isSingleCell(e)){let t=Wh(e,i,o),n=t.length;for(let e=0;e<n;e++){let n=t[e],i=r.getElementID(n[1]);l.push([n[0],i])}c=!1}if(c){let t=r.getElementID(i);l.push([e,t])}}if(c&&l){let e=function(e,r,i){if(!e.cells||e.cells.length===0)return e;let a=e.cells.map(([e,t])=>({...e,value:t}));a.sort((e,t)=>e.value-t.value);let o=Qh(a,r,null,e.cols,!0),s=Array(a[a.length-1].value+1).fill(0),c=Math.floor((r.colEnd-r.colStart+1)/2),l,u=o.length;for(let e=0;l===void 0&&e<u;e++){let t=o[e],n=t.value.s,r=s[n]+(t.max-t.min+1);r>c&&(l=n),s[n]=r}let d=Qh(a,r,l,e.rows,!1);if(e.cols===o&&e.rows===d)return e;let f=[],p=Nt(o,r,!0),m=Nt(d,r,!1),h=a,g=p.length;for(let e=0;e<g;e++){let t=p[e];h.push(t),h.push({...t,value:0})}let _=m.length;for(let e=0;e<_;e++){let t=m[e];h.push(t),h.push({...t,value:0})}let v=new Vt.IteratorInstance(h,{axis:t.IRange.Axis.Column}),y=r.rowEnd,b=r.colEnd,x=(e,t)=>{e.rowStart>=y||e.colStart>=b||f.push([e,t])},S=new Map,C=e=>{let t=S.get(e);if(t===void 0){let n=i.getElementJSON(e);t=n?.borders?n:null,S.set(e,t)}return t},w=(e,t,r)=>{let a=C(t);if(!a||n.CoordUtils.isEqualRanges(e,r))return t;let o=Uh(a.borders,e,r,!0);o&&=Uh(o,e,r,!1);let s={...a};return o?s.borders=o:delete s.borders,i.getElementID(s)??t},T=(e,t,n,r,i)=>t===r&&(!C(r)||w(e,t,i)===w(n,r,i)),E=new Map,D=(e,t)=>{if(t.rowStart>=y||t.colStart>=b)return;let n=E.get(e);n?n.push(t):E.set(e,[t])},O=[],k=[],A=v.next();for(;!A.done;){let e=A.value;A=v.next();let t=e.overlaps,n=e.range,r=t.length;if(r===1){t[0].value&&D(t[0],n);continue}let i,a,o,s,c,l;for(let e=0;e<r;e++){let n=t[e],r=n.value;typeof r==`number`?r===0&&i!==void 0||(i=r,a=n):n.rowStart===0&&n.rowEnd===y?(c=r.s,l=n):n.colStart===0&&n.colEnd===b&&(o=r.s,s=n)}o===void 0?c===void 0?(i!==0||r!==2&&r!==4)&&D(a,n):T(l,c,a,i,n)?k.push({...n,value:c,header:l}):i===0?O.push({...n,value:0}):D(a,n):T(s,o,a,i,n)||D(a,n)}for(let[e,n]of E){let r=Or(n,t.IRange.Axis.Column,2**53-1);for(let t=0;t<r.length;t++){let n={rowStart:r[t].rowStart,colStart:r[t].colStart,rowEnd:r[t].rowEnd,colEnd:r[t].colEnd};f.push([n,w(e,e.value,n)])}}let j=d;if(O.length>0){let e=Jh(O,k,r),t=e.length;for(let n=0;n<t;n++){let t=e[n];j=Tt(wt(j??[],{min:t.min,max:t.max,value:0},Zh))}let n=O.length;for(let t=0;t<n;t++)Yh(O[t],e,null,e=>x(e,0));let i=k.length;for(let t=0;t<i;t++){let n=k[t];Yh(n,e,e=>x(e,w(n.header,n.value,e)),null)}}return f.sort((e,t)=>{let n=e[0],r=t[0];return n.rowStart===r.rowStart?n.colStart-r.colStart:n.rowStart-r.rowStart}),{cols:o,rows:j,cells:f}}({cells:l,cols:i.cols?Qd(i.cols,!0):[],rows:i.rows?Qd(i.rows,!1):[]},o,r);l=e.cells,e.cols.length>0?i.cols=Zd(e.cols,!0):delete i.cols,e.rows.length>0?i.rows=Zd(e.rows,!1):delete i.rows}let u=l.length;for(let e=0;e<u;e++){let t=l[e];l[e]=[xA.rangeToString(t[0],o),t[1]]}if(l.length>0&&(i.directStyles=l),this._ownStyles){let e=r.toJSON();e&&Object.keys(e).length>0&&(i.styles=e)}}catch(e){console.warn(e)}finally{r.endPersist()}}let c=Cn(a.hyperlinkSpatial.all()),l=c.length;if(l>0){let e=Array(l);for(let t=0;t<l;t++){let n=c[t],r=n.value;e[t]={r:xA.rangeToString(n,o),v:r}}i.hyperlinks=e}}let c=a.comments.toJSON();c&&c.length>0&&(i.comments=c);let l=a.tables.toJSON();l&&l.length>0&&(i.tables=l);let u=a.autoTables.toJSON();u&&u.length>0&&(i.autoTable=u[0]);let d=a.dataValidations.toJSON();d&&d.length>0&&(i.validations=d);let f=a.conditionalFormats.toJSON();f&&f.length>0&&(i.conditionals=f);let p=a.protectedRanges.toJSON();p&&p.length>0&&(i.protectedRanges=p);let m=null;try{let t=this._searchMovableIndex(a.movableSpatial),n=t.length,r=e?.resources??`embed`,o;if(r===`ignore`?o=()=>0:(m=this._resources.beginPersist(),o=m.toResourceId.bind(m)),n>0){let e=[];for(let r=0;r<n;r++)try{let n=t[r].toJSON?.(o);n&&e.push(n)}catch(e){console.warn(`Unable to persist movable`,e)}e.length>0&&(i.movables=e)}let s=this.getPicture();s&&(i.picture=s.toJSON(o));let c=QB(this._legacyDrawing,o);c&&(i.legacyDrawing=c);let l=QB(this._legacyDrawingHF,o);l&&(i.legacyDrawingHF=l);let u=this._pivotTables;if(u.length>0){let e=[];for(let t=0;t<u.length;t++){let n=u[t].toJSON(o);n&&e.push(n)}e.length>0&&(i.pivotTables=e)}if(r!==`ignore`&&this._ownResources){let e=await m.toJSONAsync(typeof r==`function`?r:void 0);e.length>0&&(i.resources=e)}}catch(e){console.warn(e)}finally{m?.endPersist()}if(s){let e=s.formulas;e&&(i.formulas=e);let t=s.formulaArray;t&&(i.formulaArray=t);let n=s.volatile;n&&(i.volatile=n)}return this._emitter.notify(`onSave`,{params:i}),i}getStyles(){return this._styles}getResources(){return this._resources}getTransactions(){return this._transactions}getStrings(){return this._strings}_searchMovables(e){let t=this._getState();if(t===null)return n.CommonUtils.EmptyArray;let r=this._searchMovableIndex(t.movableSpatial,e),i=this._searchMovableIndex(t.noteSpatial,e);return i.length===0?r:r.length===0?i:[...r,...i]}_addNoteBox(e,t,r){let i=e.getRange().getCoords(),a={rowIndex:i.rowStart,colIndex:i.colStart},o=this._noteLayout(),s={anchor:t?vj(t,a,this._getEntireCoords()):_j(hj(a,o),o),content:{type:`note`,json:null}};r&&(s.hidden=!0);let c=this._getState(),l=this._createMovableEntry(s,c.noteSpatial.size(),void 0,this._noteIndex,e),u=l.value.model;if(this._initializing)return c.noteSpatial.insert(l),c.noteMapModel.set(u,l),u;let d=this._beginCommit({description:(0,n.messageKey)(`op.addComment`)});try{let e=c.noteSpatial.clone();e.insert(l);let t=new Map(c.noteMapModel);t.set(u,l),this._updateState({noteSpatial:e,noteMapModel:t}),d.commit()}catch(e){throw d.rollback(),e}return this._emitterMovables.notify(`onCollectionChange`),this._notify(`onMovablesChange`),u}_noteLayout(){return{getBoundsAtCoords:this._getBoundsAtCoords.bind(this),getCoordsAtBounds:this._getCoordsAtBounds.bind(this),getMaxBounds:()=>this._getBoundsAtCoords(this._getEntireCoords())}}_searchMovableIndex(e,t){let r=t?.ignoreHidden??!1,i=t?.bounds,a=t?.fullyContained,o=this;if(this._getState()===null)return n.CommonUtils.EmptyArray;let s=t?.address?this._rangeToCoords(t?.address):this._getEntireCoords();return this._getRangedEntries(e,[s],{ignoreHidden:r,fullyContained:a,onEntry:e=>{let n=t?.type;if(n){if(Array.isArray(n)){if(!n.includes(e.model.getContent().getType()))return null}else if(n&&e.model.getContent().getType()!==n)return null}let a=null;if(r&&(e.model.isHidden()||(a=o._getBoundsAtCoords(e.model.getRange().getCoords()),a.width===0||a.height===0)))return null;if(i){a||=o._getBoundsAtCoords(e.model.getRange().getCoords());let t=a,n=i;if(t.y>n.y+n.height||t.y+t.height<n.y||t.x>n.x+n.width||t.x+t.width<n.x)return null}return e.model}}).sort((e,t)=>e.getZIndex()-t.getZIndex())}_updateSelectedMovables(e,t){let r=this.getView().getMovableSelection();if(!r||r.length===0)return;let i=this._beginCommit({description:t??(0,n.messageKey)(`op.updateMovables`)});try{let t=r.length;for(let n=0;n<t;n++)e(r[n]);this._recordMovableSelection(`after`,r,i),i.commit()}catch(e){throw i.rollback(),e}}async _addMovable(e){if(!this.getProtection().isObjectsAllowed())throw new n.ProtectedError((0,n.t)(`error.sheet.insertItemProtected`));if(!e)throw new n.ExpectedError(`No movable options provided`);if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));if(e.type===`note`)throw new n.ExpectedError(kj(e.type));if(e.autoPlace===`viewport`&&e.bounds?.width!=null&&e.bounds?.height!=null){let t=(await this._emitter.notify(`onRequestViewport`,{async:!0}))?.find(Boolean)??null;if(t){let n=Math.min(e.bounds.width,t.width-8),r=Math.min(e.bounds.height,t.height-8);e={...e,bounds:{x:t.x+(t.width-n)/2,y:t.y+(t.height-r)/2,width:n,height:r}}}}let t={};if(e?.type){t.content={type:e.type,json:e?.json},e.name&&(t.content.name=e.name);let n=e.altText;n&&(t.content.description=n)}e?.anchorType&&(t.anchorType=e?.anchorType),e.bounds&&(t.anchor=null);let r=this._getState().movableSpatial,i=this._beginCommit({description:e?.description??(0,n.messageKey)(`op.insertDrawing`)}),a=this._createMovableEntry(t,r.size(),e.fromResourceId),o=r.clone();o.insert(a);let s=this._getState().movableMapModel,c=new Map(s),l=a.value.model;if(c.set(l,a),this._updateState({movableSpatial:o,movableMapModel:c}),e.bounds&&a.value.model.setBounds(e.bounds,e),!1!==e?.autoSelect){this._recordMovableSelection(`before`,this.getView().getMovableSelection(),i);let t=e?.autoSelect??!1;!0===t&&(t={autoFocus:!0,scrollIntoView:!0,addToSelection:!1}),t&&this.getView().selectMovables([a.value.model],t.addToSelection),this._recordMovableSelection(`after`,this.getView().getMovableSelection(),i)}return i.commit(),this._emitterMovables.notify(`onCollectionChange`),this._notify(`onMovablesChange`),a.value.model}async _addMovablePicture(e,t={type:`picture`}){if(!e)throw new n.ExpectedError((0,n.t)(`error.sheet.noImageProvided`));if(!this.getProtection().isObjectsAllowed())throw new n.ProtectedError((0,n.t)(`error.sheet.insertItemProtected`));let r=this._resources.add(e),i=await r.toBuffer(),a=await r.getType(),o=this._getBoundsAtCoords(this.getSelection().getRange().getCoords()),{naturalSize:s,asUrl:c}=await n.ImageUtils.loadImageDetails(i,a?.mime);URL.revokeObjectURL(c);let l={...o,...s,...t?.bounds};if(n.CommonUtils.isNullOrUndefined(t?.bounds?.x)||n.CommonUtils.isNullOrUndefined(t?.bounds?.y)){let e=pA(this.getMovables(),l,n.CommonUtils.isNullOrUndefined(t?.bounds?.x),n.CommonUtils.isNullOrUndefined(t?.bounds?.y));l.x+=e.x,l.y+=e.y}t?.bounds&&!1!==t?.json?.lockAspect&&(n.CommonUtils.isNullOrUndefined(t?.bounds.width)&&n.CommonUtils.isDefined(t?.bounds.height)&&(l.width=l.height*s.width/s.height),n.CommonUtils.isNullOrUndefined(t?.bounds.height)&&n.CommonUtils.isDefined(t?.bounds.width)&&(l.height=l.width*s.height/s.width));let u={...t?.json,resId:0};return await this._addMovable({anchorType:ev.Type.OneCell,description:(0,n.messageKey)(`op.insertImage`),...t,bounds:l,type:`picture`,json:u,fromResourceId:e=>e===0?r:(console.warn(`received an unexpected resourceId`,e),null)})}setPicture(e,t){let r=this,i;return e&&(i=new Ck({resource:this._resources.add(e),deleteFromContainer:e=>{r._getState().picture&&(r._updateState({picture:null},{description:(0,n.messageKey)(`op.deletePicture`),...e}),r._notify(`onStyleChange`))},transactions:this._transactions})),r._updateState({picture:i},{description:i?(0,n.messageKey)(`op.setPicture`):(0,n.messageKey)(`op.removePicture`),...t}),r._notify(`onStyleChange`),this}getPicture(){return this._getState().picture??null}getPivotTables(){return this._pivotTableCollection}getTables(){return this._tables}getDataValidations(){return this._dataValidations}getConditionalFormats(){return this._conditionals}getProtectedRanges(){return this._protectedRanges}getComments(){return this._comments}getConditionals(){return this._conditionals}getMovables(){return this._movables}getCharts(){return this._charts}_validateOrRemoveOverlaps(e,t,r=null,i=!1,a=!1){let o=this;t!==`merge`&&gA(this._getMerges([e]),e,(e,r)=>{if(r||!i)throw new n.ExpectedError(Aj(t));o._unmerge([e])});let s=[],c=this.getTables().getItems({address:e}),l=c.length;for(let e=0;e<l;e++){let t=c[e];r!==t&&s.push(t.getRange().getCoords())}gA(s,e,(e,r,a)=>{if(r||!i)throw new n.ExpectedError(Aj(t));c[a]._remove()});let u=this._getState().autoTables.search(e);if(u.length>0){let r=i||a;gA(u,e,(e,i,a)=>{if(i||!r)throw new n.ExpectedError(Aj(t));u[a].value.delete()})}}_getAutoTableCarryOver(e){let t=this.getAutoTable();if(!t||!n.CoordUtils.isEqualRanges(t.getRange().getCoords(),e))return null;let r=[],i=t.getActiveFilters();for(let e=0;e<i.length;e++){let t=i[e].getCondition();t&&r.push({index:i[e].getIndex(),...t.toJSON()})}let a=[],o=t.getActiveSorts();for(let e=0;e<o.length;e++)a.push({index:o[e].getIndex(),criteria:o[e].getCriteria()});return r.length===0&&a.length===0?null:{conditions:r,sorts:a}}_addTable(e,r){let i=this._rangeToCoords(e,()=>[`objects`]),a=this._getEntireCoords(),o;typeof r==`boolean`?o=r:r&&(o=r.hasHeader);let s=typeof r!=`object`||r?.properties?.headerRowCount!==0;s?o===void 0&&(o=this._getDefaultSortCriteria(i)?.options?.hasHeader??!1):o=!0;let c=i.rowEnd<a.rowEnd;if(s&&i.rowStart===i.rowEnd&&(o||!c)){if(!c)throw new n.ExpectedError((0,n.t)(`error.sheet.table1By1`));i.rowEnd+=1}let l={...i},u=this._beginCommit({description:(0,n.messageKey)(`op.insertTable`)}),d;try{o||!c&&this._isContentful([{...i,rowStart:i.rowEnd}])||(this._insertCells([{...i,rowEnd:i.rowStart}],t.IRange.Axis.Row),c&&(i={...i,rowEnd:i.rowEnd+1}));let e=this._getAutoTableCarryOver(i);this._validateOrRemoveOverlaps(i,`table`,null,!1,!0);let n=r,a=n?.properties?.style??{};typeof a==`string`&&(a={name:a});let s={...n?.properties,style:a};s.style=a,a.name===void 0&&(a.name=this._styles.getTableStyles().getDefault().getName());let f=this._getState().tables;f=this._createTables(f,`tables`,[{r:i,v:s}],e=>{let t=new yO({...e,syncSheet:!0,hasTotals:!0===n?.hasTotals});return d=t,t}),this._updateState({tables:f}),d._showTotalsFromProps(),d._detectCalculatedColumns(),this._tellFiltered(),this._notifyTablesChange(),n?.disabledAutofit||this._autoFit(d.getRanges().getCoords(),{expandOnly:!0,formulaView:!1}),e&&(e.sorts.length>0&&d.sort({sorts:e.sorts}),e.conditions.length>0&&d._carryFilters(e.conditions));let p=DA([i]);this._recordSelection(u,p,typeof r==`object`?r:null),this._recordChange(u,`anchored`,[l,i]),u.commit()}catch(e){throw u.rollback(),e}return d}_addAnchored(e,t,r){let{index:i=0,replaceExisting:a=!1,description:o=r.description,autoSelect:s,author:c,readOnly:l,expectedCommitId:u,...d}=t??{},f,p;e||=this.getSelectedRanges(),r.isItem(e)?(f={...e.toJSON()},p=e.getRanges().getCoords()):(f=d,p=e);let m=this._rangesToCoords(p,()=>r.allowance),h=DA(m),g=[...m],_=this._beginCommit({description:o}),v;this.getProtection().isLocked()&&this._recordSkipProtectionCheck(_);try{let e=this._getState()[r.key],t=a?e.getByIndex(i):null;t&&_H(e.getCoords(t)??void 0,n.CoordUtils.sanitizeRangeArray(m)??void 0)&&(r.isSameItem?.(t,f)??1)?(r.replace(t,f,{description:o}),v=t):(e=r.load(e,{r:m,v:r.prepareInsert?.(f)??f},e=>{v=e}),i<e.size()-1&&(e=e.setIndex(v,i)),this._updateState({[r.key]:e}),r.autoFit&&this._autoFit(v.getRanges().getCoords(),{expandOnly:!0,formulaView:!1})),r.notify(),h&&this._recordSelection(_,h,{autoSelect:s}),this._recordChange(_,`anchored`,g),_.commit()}catch(e){throw _.rollback(),e}return v}_addDataValidation(e,t){return this._addAnchored(e,t,{key:`dataValidations`,isItem:e=>!!e?.isIDataValidation,description:(0,n.messageKey)(`op.insertDataValidation`),allowance:[],load:(e,t,n)=>this._createDataValidations(e,`dataValidations`,[t],e=>{let t=new XA(e);return n(t),t}),replace:(e,t,n)=>{e.update(t,n)},notify:()=>this._notifyDataValidationsChange(),autoFit:!0})}_addConditionalFormat(e,t){return this._addAnchored(e,t,{key:`conditionalFormats`,isItem:e=>!!e?.isIConditionalFormat,description:(0,n.messageKey)(`op.insertConditionalFormat`),allowance:[`formatCells`],load:(e,t,n)=>this._createConditionalFormats(e,`conditionalFormats`,[t],e=>{let t=new IA(e);return n(t),t}),isSameItem:(e,t)=>t.scale!==void 0&&e.getScale()?.type===t.scale.type,replace:(e,t,n)=>{e.update(IA.replaceModifiers(t),n)},notify:()=>this._notifyConditionalFormatsChange(),autoFit:!0})}_nextProtectedRangeName(){let e=this._getState()?.protectedRanges;if(!e)return`Range1`;for(let t=1;;t++){let n=`Range${t}`;if(!e.getByName(n))return n}}_addProtectedRange(e,t){return this._addAnchored(e,t,{key:`protectedRanges`,isItem:e=>!!e?.isIProtectedRange,description:(0,n.messageKey)(`op.insertProtectedRange`),allowance:[],load:(e,t,n)=>this._createProtectedRanges(e,`protectedRanges`,[t],e=>{let t=new tj(e);return n(t),t}),prepareInsert:e=>!e.name||this._getState().protectedRanges.getByName(e.name)?{...e,name:this._nextProtectedRangeName()}:e,replace:(e,t,n)=>{let r=t.name?this._getState().protectedRanges.getByName(t.name):null,i=!t.name||r&&r!==e?void 0:t.name;e.update({...t,name:i},n)},notify:()=>this._notifyProtectedRangesChange()})}_addComment(e,t,r){let{replaceExisting:i=!1,description:a=(0,n.messageKey)(`op.addComment`),autoSelect:o,...s}=r??{},c=this._rangeToCoords(e,()=>[`objects`]);if(c.rowStart!==c.rowEnd||c.colStart!==c.colEnd)throw new n.ExpectedError((0,n.t)(`error.comment.singleCell`));let l=this._beginCommit({description:a}),u;try{let e=this._getState().comments.search(c)[0]?.value??null;if(e){if(!i)throw new n.ExpectedError((0,n.t)(`error.comment.cellHasComment`));e.delete()}let r=this._createComments(this._getState().comments,`comments`,[{r:c,v:this._newCommentJSON({...s,content:t})}],e=>{let t=new yj(e);return u=t,t});this._updateState({comments:r}),this._notifyCommentsChange(),this._recordSelection(l,DA([c]),{autoSelect:o}),this._recordChange(l,`comments`,[c]),l.commit()}catch(e){throw l.rollback(),e}return u}createCell(e,t=null,n){return e?.createCell?e:(t?this.getRange(t).getCell():this._emptyCell).createCell(e,n)}_getBoundsAtCoords(e){let t=this._rowHeaders,n=this._colHeaders,r=n.getOffset(e.colStart),i=t.getOffset(e.rowStart);return{x:r,y:i,width:n.getOffset(e.colEnd+1)-r,height:t.getOffset(e.rowEnd+1)-i}}_getCoordsAtBounds(e){let t=this._rowHeaders,n=this._colHeaders,r=e.x,i=e.y;return{colStart:n.getIndex(r),rowStart:t.getIndex(i),colEnd:n.getIndex(r+e.width),rowEnd:t.getIndex(i+e.height)}}getRangeAtBounds(e,t){if(!e)throw new n.NullNotAllowedError;let r=this._getCoordsAtBounds(e);return this.getRange(r,t)}getRangeAt(e,t,n,r,i){return this.getRange({rowStart:e,colStart:t,rowEnd:n??e,colEnd:r??t},i)}_getVisible(e,r){return function(e,r,i){if(r.length===0)return r;let a=new yr;a.load(r);let o=i?.axes??t.IRange.AxisSelection.Both,s=(e,t)=>{let n=a.search(e),r=n.length;for(let i=0;i<r;i++){let r=n[i],o=hA(r,e,t);a.remove(r),a.load(o)}},c=e.getEntireCoords();if(o===t.IRange.AxisSelection.Both||o===t.IRange.AxisSelection.Row){let n=e.rowHeaders,i=r.length;for(let e=0;e<i;e++){let i=r[e];n.getRange({min:i.rowStart,max:i.rowEnd}).forEachSpan((e,n)=>{if(e!==0)return;let r=n.getCoords();s({colStart:c.colStart,rowStart:r.min,colEnd:c.colEnd,rowEnd:r.max},t.IRange.Axis.Row)})}}if(o===t.IRange.AxisSelection.Both||o===t.IRange.AxisSelection.Column){let n=e.columnHeaders,i=r.length;for(let e=0;e<i;e++){let i=r[e];n.getRange({min:i.colStart,max:i.colEnd}).forEachSpan((e,n)=>{if(e!==0)return;let r=n.getCoords();s({colStart:r.min,rowStart:c.rowStart,colEnd:r.max,rowEnd:c.rowEnd},t.IRange.Axis.Column)})}}return a.all().sort(n.CoordUtils.rowFirstRangeComparator)}(this._getReadCtx(),e,r)}_hasRangedEntries(e,t){return function(e,t,r){let i=e.state;if(!i)return!1;let a=i[t];if(!a)throw new n.ExpectedError(`Invalid range key ${t}`);return!a.isEmpty()&&a.has(r)}(this._getReadCtx(),e,t)}_getRangedEntries(e,r,i,a=!1){return function(e,r,i,a){if(i.length===0||!r||r.isEmpty())return n.CommonUtils.EmptyArray;let o=a?.spatialSort??!1,s=a?.ignoreHidden??!1,c=a?.fullyContained??!1,l=a?.onEntry??null,u=a?.onFound??null,d=a?.sort,f;d&&(f=n.CoordUtils.createRangeComparator(d.axis,d.reverse));let p=new Set,m=(e,t)=>{let n=e.length,r=u&&f?[...e].sort(f):e;for(let e=0;e<n;e++){let n=r[e];u&&u(n,t),p.add(n)}},h=i.length;for(let n=0;n<h;n++){let a=i[n];if(s){if(!0===s){let t={min:a.colStart,max:a.colEnd},n={min:a.rowStart,max:a.rowEnd};e.rowHeaders.getRange(n).forEachSpan((n,i)=>{let a=i.getCoords(),s=a.min,l=a.max;e.columnHeaders.getRange(t).forEachSpan((e,t)=>{let n=t.getCoords(),i=n.min,a=n.max,u={colStart:i,rowStart:s,colEnd:a,rowEnd:l},d=r.search(u,c,o);d.length>0&&m(d,u)},gR)},gR)}else if(s===t.IRange.Axis.Column){let t={min:a.colStart,max:a.colEnd};e.columnHeaders.getRange(t).forEachSpan((e,t)=>{let n=t.getCoords(),i=n.min,s=n.max,l={colStart:i,rowStart:a.rowStart,colEnd:s,rowEnd:a.rowEnd},u=r.search(l,c,o);u.length>0&&m(u,l)},gR)}else if(s===t.IRange.Axis.Row){let t={min:a.rowStart,max:a.rowEnd};e.rowHeaders.getRange(t).forEachSpan((e,t)=>{let n=t.getCoords(),i=n.min,s=n.max,l={colStart:a.colStart,rowStart:i,colEnd:a.colEnd,rowEnd:s},u=r.search(l,c,o);u.length>0&&m(u,l)},gR)}}else{let e=a,t=r.search(e,c,o);t.length>0&&m(t,e)}}if(p.size===0)return n.CommonUtils.EmptyArray;let g=Array.from(p.values());f&&g.sort(f);let _=[],v=new Set,y=g.length;for(let e=0;e<y;e++){let t;l&&(t=l(g[e].value,g[e])),t===void 0&&(t=g[e].value),t===null||v.has(t)||(v.add(t),_.push(t))}return _||=n.CommonUtils.EmptyArray,_}(this._getReadCtx(),e,r,a?{...i,spatialSort:!0}:i)}_processAnchorShift(e){let t=e.after,r=n.CoordUtils.sanitizeRange(e.after),i=n.CoordUtils.sanitizeRange(e.before);e.after&&this._validateCoords(r,(0,n.t)(`error.sheet.insertItemOob`));let a=e.before.value.callbacks?.processShift?.({...e,after:r,before:i});return a&&(gH(a,r)||(t||=e.before,t={...t,...a})),t}delete(){if(this._closed)return;try{this._notify(`onBeforeDelete`)}catch(e){throw e instanceof Error?e:new n.ExpectedError(e.message??(0,n.t)(`error.sheet.modelDelete`))}let e=this._beginCommit({description:(0,n.t)(`op.deleteSheet`,{name:this.getName()})});this._getState(),this._updateState({deleted:!0}),this._calcGrid.delete(this._requestFor(e)),this._listenerNodes.forEach(e=>{e.watch&&e.node.host.dispose()}),this._deleteCells([this._getEntireCoords()]),this._notify(`onDelete`),e.commit()}doBatch(e,t){let r=this;return t=typeof t==`string`?{description:t}:{description:(0,n.messageKey)(`op.updateSheet`),...t},this._transactions.doBatch(e,t,(e,n)=>{if(e.getDepth()===0&&t?.autoSelect){let t=r.getId();e.setIntent(IN,e=>({...e,[t]:!0}))}})}isDeleted(){let e=this._getState();return!e||e?.deleted}isClosed(){return this._closed}close(){if(this._closed)return;this._cellBuffer?.discard(),this._protectionRemoveListener?.(),this._protection=new a_(void 0,this._options.readonly);let e=this._getState();e.tables.close(),e.autoTables.close(),this._searchMovables().forEach(e=>{e.close()}),this._notify(`onClose`),this._ownResources,this._languageRemoveListener?.(),this._languageRemoveListener=void 0,this._regionalRemoveListener?.(),this._regionalRemoveListener=void 0,this._namesRemoveListener?.(),this._ownNames&&this._names.close(),this._ownCalculation&&this._calculation.close(),this._ownStyles,this._modules.close(),this._colHeaders.close(),this._rowHeaders.close(),this._emitter.close(),this._transactionsRemoveListener?.(),this._transactionsCloseRemoveListener?.(),this._ownsCalcGrid&&this._calcGrid?.close(),this._closed=!0}beginCommit(e){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));return this._beginCommit(typeof e==`string`?{description:e}:e)}_getState(){return this._closed?null:this._transactions.getState(this._stateId)}_getStateId(){return this._stateId}_beginCommit(e){let t=typeof e==`string`?{description:e}:{...e};return this._transactions.beginCommit(t)}_updateState(e,t){if(!e)return;this._lastGetRangeRead=null;let n=this._transactions.beginCommit(t),r;try{r=n.updateState(this._stateId,e),n.commit()}catch(e){throw n.rollback(),e}return r}_getScalar(e,t,r=!1){let i,a=null,o=null,s=this._cellBuffer;if(s!==null&&s.isHolding()){let n=s.read(e,t);if(n===lR.NotHeld){o=s.getTransaction(),a=o.getState(this._stateId);let n=r?s.readStyleUpdate(e,t):void 0;if(n!==void 0){let r=this._calcGrid.getValues(o).getValueAt(e,t);return typeof r==`number`?BL(this._getMutationCtx(),a.contentSpatial,e,t,n)?dl(r,this._isDate1904):r:r??null}}else if(n!==void 0){if(!r||typeof n!=`number`)return n;o=s.getTransaction(),a=o.getState(this._stateId);let c=s.readStyleUpdate(e,t);if(c!==void 0)return BL(this._getMutationCtx(),a.contentSpatial,e,t,c)?dl(n,this._isDate1904):n;i=n}}if(a===null&&(a=this._getState()),i===void 0&&(i=this._calcGrid.getValues(o).getValueAt(e,t)),i===void 0)return null;let c=i;if(r&&typeof c==`number`){let r=!1;rV.colStart=t,rV.rowStart=e,rV.colEnd=t,rV.rowEnd=e;let i=this._lastValueRead,o=this._lastValueRead.range;if(o&&n.CoordUtils.isRangeWithinRange(rV,o))r=i.isDateOrTime;else{let e=a.dateFormatSpatial.search(rV);r=e.length>0,r&&(i.range=e[0],i.isDateOrTime=!0)}r&&(c=dl(c,this._isDate1904))}return c}_markColumnHeaderTableNames(){let e=this._getState();if(!e)return;let t=this.getView().getColumnHeaderTableNames(),r=this._cacheTableColumnHeaders,i=r.showInHeader,a=e.tables;if(t===Sj.ColumnHeaderTableNames.None||a.isEmpty())return void(r.table&&(r.table=null,r.showInHeader=!1,r.tableMin=-1,r.tableMax=-1,r.lastTop=-1,r.lastColIndex=-1,r.lastRowIndex=-1,i&&this._notify(`onViewChange`)));let o=this.getSelection().getCoords().cell,s=o.colIndex,c=o.rowIndex,l=s!==r.lastColIndex||c!==r.lastRowIndex,u=r.table,d;if(l?(r.lastColIndex=s,r.lastRowIndex=c,u&&n.CoordUtils.isCellWithinRange(o,u.getRange().getCoords())?d=u:(cV.colStart=s,cV.rowStart=c,cV.colEnd=s,cV.rowEnd=c,d=a.search(cV)[0]?.value??null)):d=u,!d)return r.showInHeader=!1,r.table=null,r.tableMin=-1,r.tableMax=-1,void(i&&this._notify(`onViewChange`));r.table=d;let f=d.getRange().getCoords();if(!f)return;let p;if(r.tableMin=f.colStart,r.tableMax=f.colEnd,t===Sj.ColumnHeaderTableNames.Sticky){let e=r.lastTop,t=this.getView(),i=t.getFreezePanes(),a=((i.coords?.rowIndex??0)>0?i.topLeft:t.getTopLeft())?.top??e;if(e===a&&u===d)return;r.lastTop=a;let o={colIndex:f.colStart,rowIndex:this.getRowHeaders().getIndex(a)-1};p=n.CoordUtils.isCellWithinRange(o,f)}else t===Sj.ColumnHeaderTableNames.Hidden&&(p=d.isITable&&!d.isHeaderVisible());r.showInHeader=p,p!==i&&this._notify(`onViewChange`)}_getCellAt(e,t){let n=this._cellBuffer;if(n!==null&&n.isHolding()){let r=n.readCell(e,t);if(r!==void 0){let i=n.getTransaction(),a=this._getCellAtState(i.getState(this._stateId),i,e,t,r===lR.NotHeld?null:r);if(a!==null)return a}}let r=this._getState();return r?this._getCellAtState(r,null,e,t,null):this._emptyCell}_getCellAtState(e,r,i,a,o){let s={rowIndex:i,colIndex:a},c;if(o?.isValueHeld)c=o.value;else{let e=this._calcGrid.getValues(r).getValueAt(i,a);c=e===void 0?null:e}let l=[];this._collectRanges(n.CoordUtils.cellToRange(s),l,!0,e,void 0,r);let u=mH(l);if(o){if(o.isValueHeld&&u&&(u.formula||u.spills||u.pending||u.calcError||u.circular))return null;let e=o.formula;if(e!==null){let t=this._cellBuffer.getGeneration(),n=this;u={...u,formula:new nM(e,{colStart:a,rowStart:i,colEnd:a,rowEnd:i},()=>{if(!n._cellBuffer?.isHeldGeneration(t))return n._calcGrid?.getFormulaAt(i,a)??null})}}if(o.style!==void 0&&(u=RL(this._getMutationCtx(),u,i,a,o.style),u===null))return null}if(u&&Object.keys(u).length===0&&(u=null),c===null&&!u)return new JM(this._cellOptions,s);let d=c===null?t.ScalarType.Null:IH(c);return new JM(this._cellOptions,s,d,c,u)}_queryStyle(e,t,r){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));lV.length=0;let i=lV,a,o=null,s=null,c=this._cellBuffer;if(c!==null&&c.isHolding()&&(!r||n.CoordUtils.isSingleCell(r))){let t=c.readCell(e.rowStart,e.colStart);if(t!==void 0){let e=c.getTransaction();a=e.getState(this._stateId),o=e,t!==lR.NotHeld&&(s=t)}}this._collectRanges(e,i,!0,a??this._getState(),void 0,o);let l=mH(i);if(s?.style!==void 0){let t=RL(this._getMutationCtx(),l,e.rowStart,e.colStart,s.style);t===null?(i.length=0,this._collectRanges(e,i),l=mH(i)):l=t}return VM(null,e,l,t,!0,r)}_getStyle(e,t,n){let r;if(t)r={colStart:t.cell.colIndex,rowStart:t.cell.rowIndex,colEnd:t.cell.colIndex,rowEnd:t.cell.rowIndex};else{let t=e[0];r={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart,rowEnd:t.rowStart}}let i=e.length===1?e[0]:void 0,a=this,o=this._cellOptions;return o={...o,styleUpdater:(t,s)=>(n?n(t,s):a._updateStyles(e,t,s),a._queryStyle(r,o,i))},a._queryStyle(r,o,i)}_initHeadersState(e,n){let r=this;this._cacheTableColumnHeaders={table:null,showInHeader:!1,tableMin:-1,tableMax:-1,lastTop:0,lastColIndex:-1,lastRowIndex:-1},this._defaultFontBoundsCache=null,this._defaultColWidthCache=0,this._defaultRowHeightCache=0,this._colHeadersRemoveListener?.(),this._colHeadersHiddenRemoveListener?.(),this._colHeaders=new kP({sheet:r,json:e,axis:t.IRange.Axis.Column,transactions:this._transactions,isProtected:()=>!r._initializing&&!r.getProtection().isFormatColumnsAllowed(),getColumnAt:e=>{let t=r._cacheTableColumnHeaders;if(!t.showInHeader||e>t.tableMax||e<t.tableMin)return null;let n=e-t.tableMin;return t.table.getColumnAt(n)},getTextAt:e=>{let t=r._cacheTableColumnHeaders;if(t.showInHeader&&e<=t.tableMax&&e>=t.tableMin){let n=t.table.getColumns()[e-t.tableMin];if(n&&n.getName()!==void 0)return n.getName()}let n=this.getView().getColumnHeaderStyle();return n===Sj.HeaderTextStyle.A1?mV(e):n===Sj.HeaderTextStyle.Zero?pV(e):n===Sj.HeaderTextStyle.One?hV(e):void 0},defaultSize:()=>this._defaultColWidth(),scaleFactor:()=>{let e=this.getView().isShowFormulas()?2:1;return Math.round(this._defaultFontDims().width)*e},maxSize:()=>255,getEntireSheetCoords:()=>r._getEntireCoords(),setContainerShiftedCallback:e=>{this._colHeadersShiftCallback=e},hiddenChanged:()=>r._tellHidden(t.IRange.Axis.Column)}),this._colHeadersRemoveListener=this._colHeaders.addListeners(this._colHeadersListener,{transactional:!0}),this._colHeadersHiddenRemoveListener=this._colHeaders.addListeners({onHiddenChange:()=>{r._notify(`onColumnsHiddenChange`)}},{transactional:!1}),this._rowHeadersRemoveListener?.(),this._rowHeadersHiddenRemoveListener?.();let i=B.getDeviceScale();this._rowHeaders=new kP({sheet:r,json:n,axis:t.IRange.Axis.Row,transactions:this._transactions,isProtected:()=>!r._initializing&&!r.getProtection().isFormatRowsAllowed(),getTextAt:e=>{let t=this.getView().getRowHeaderStyle();return t===Sj.HeaderTextStyle.One?hV(e):t===Sj.HeaderTextStyle.Zero?pV(e):t===Sj.HeaderTextStyle.A1?mV(e):void 0},defaultSize:()=>this._defaultRowHeight(),scaleFactor:()=>i,minSize:()=>0,maxSize:()=>409,getEntireSheetCoords:()=>r._getEntireCoords(),setContainerShiftedCallback:e=>{this._rowHeadersShiftCallback=e},hiddenChanged:()=>r._tellHidden(t.IRange.Axis.Row)}),this._rowHeadersRemoveListener=this._rowHeaders.addListeners(this._rowHeadersListener,{transactional:!0}),this._rowHeadersHiddenRemoveListener=this._rowHeaders.addListeners({onHiddenChange:()=>{r._notify(`onRowsHiddenChange`)}},{transactional:!1})}_tellHidden(e){if(this._closed||!this._ownsCalcGrid)return;let n=this._transactions.getCurrentTransaction(),r=this._calcGrid;if(!n||!r)return;let i=e===t.IRange.Axis.Column?this._colHeaders:this._rowHeaders;r.setHidden(e,uH(i),this._requestFor(n))}_invalidateCaches(){this._lastCellDecoded.address=null,this._lastCellSelected.coords=null,this._lastCellRead.coords=null,this._lastValueRead.range=null;let e=this._cellOptions?.renderCellCache;e&&e.size>0&&e.clear(),this._lastGetRangeRead={},this._lastUsedCoordsRead.coords=null,this._lastRangeRead.address=null,this._entireCoordsCache=null,this._entireRangeCache=null}_initListenerState(){let e=this,t=()=>{e._invalidateCaches()};this._transactionsRemoveListener=this._transactions.addStateListener(this._stateId,{onBeforeCommitStart(t,r,i,a,o){if(!e._initializing&&!(o?.[`sheet.skipProtectionCheck`])?.includes(e.getId())&&e.getProtection().isLocked())throw new n.ProtectedError((0,n.t)(`error.sheet.protectedSheet`))},async onBeforeCommitEnd(t,n,r,i,a){e._resolveAutoFit(n);let o=()=>n.getId();e._notifyListenerNodeMoves(t,!0,{isDataChange:!1,getTransactionId:o,timeStamp:n.getTimestamp(),trigger:`address`}),e._notifyListenerNodes(t,e._changedRanges(a),{isDataChange:!0,getTransactionId:o,timeStamp:n.getTimestamp(),trigger:`data`},!0)},async onRestoreOrRevert(n,r,i,a,o){t(),e._calculateFull();let s=e._restoredSelection(o,i);s&&e._autoSelect(s.options||!0,s.selection);let c=o?.[RN]?.[e.getId()];c&&e.getView().setFreezePanes({coords:i?c.before:c.after});let l=e._restoredMovableSelection(o,i);l&&e.getView().selectMovables(l),e._notify(`onViewChange`),e._notify(`onInvalidated`),e._emitterMovables.notify(`onInvalidated`),e._notifyUsedRangeChange()},async onAfterStateChange(n,r,i,a,o){let s=()=>r.getId();t();let c=e._sheetEvents(o);if(e._normalizeSelection(!!c?.merges),c?.merges&&e._notify(`onMergesChange`),c?.spills&&e._notify(`onSpillsChange`),e._notifyListenerNodeMoves(n,!1,{isDataChange:!1,isUndo:i,isRestoreOrRevert:i,getTransactionId:uV,timeStamp:Date.now(),trigger:`address`}),e._notifyListenerNodeMoves(n,!0,null),(o?.[`sheet.initial`])?.includes(e.getId()))return;let l=e._changedRanges(o);l&&((i||a)&&(e._calculation.getStatus()!==X.Status.Off&&e._calcGrid.revert({commitId:r.getId()}),e._calcGrid.markDirtyRegions(l)),e._calculation.getStatus()!==X.Status.Off&&e._calcGrid.calculate()),l&&(e._notifyUsedRangeChange(),e._notifyListenerNodes(n,l,{isDataChange:!0,getTransactionId:s,timeStamp:r.getTimestamp(),isUndo:i,trigger:`data`},!1),e._notify(`onDataChange`))},onClose(){let t=e._getState();t&&(t.movableSpatial.clear(),t.noteSpatial.clear())}}),this._transactionsCloseRemoveListener=this._transactions.addListener({onCommitStart(){e._selectionAtCommitStart=e._view?.getRangeSelection().getCoords()??null},onCommitClose(t){e._onRootTransactionClose(t)}}),this._colHeadersListener={onSizesChange:t=>{e._isAdjustHeaders||e._processLayoutChange()}},this._rowHeadersListener={onSizesChange:t=>{e._isAdjustHeaders||e._processLayoutChange()}};let r=new Set,i={onTopLeftChange(t){e._markColumnHeaderTableNames(),e._notify(`onTopLeftChange`)},onZoomScaleChange(t){e._notify(`onZoomScaleChange`)},onFreezePaneChange(t){e._notify(`onFreezePaneChange`)},onHeaderChange(t){e._markColumnHeaderTableNames(),e._notify(`onNameChange`)},onSelectionChange(t){e._markColumnHeaderTableNames(),e._notify(`onSelectionChange`)},onMovableSelectionChange(t){let n=t.getMovableSelection(),i=new Map,a=new Set,o=e._getState().movableMapModel,s=n.length;for(let e=0;e<s;e++){let t=n[e];r.has(t)?r.delete(t):i.set(t,e),a.add(t)}let c=e._getState().noteMapModel,l=e=>o.get(e)??c.get(e);r.forEach(e=>{l(e)?.value?.callbacks.processSelection(!1,!1)}),i.forEach((e,t)=>{l(t)?.value?.callbacks.processSelection(!0,e===0)}),r=a,e._notify(`onMovableSelectionChange`)},onAnyChange(){e._defaultColWidthCache=0,e._defaultRowHeightCache=0,e._defaultFontBoundsCache=null,e._notify(`onLayoutChange`),e._notify(`onViewChange`)}};this._viewListener=i,this._protectionListener={onLockChange(){if(e._closed)return;let t=e._protection;if(t.isLocked()||t.isPaused())return;let n=e._protectedRanges.getItems();for(let e=0;e<n.length;e++)n[e].relock()},onChange(){if(e._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let t=e=>{e.value?.callbacks.processProtection?.()};e._getState().movableMapModel.forEach(t),e._getState().noteMapModel.forEach(t),e._getState().tables.processCallbacks((e,t)=>{t.processProtection?.()}),e._invalidateCaches(),e._notify(`onProtectionChange`)}},this._stylesListener={onAnyChange(){e._invalidateRendering()}}}_invalidateRendering(){this._defaultColWidthCache=0,this._defaultRowHeightCache=0,this._defaultFontBoundsCache=null,this._notify(`onLayoutChange`),this._notify(`onStyleChange`),this._notify(`onViewChange`);let e=this._getEntireCoords();this._autoFit([e],{axes:t.IRange.AxisSelection.Both,skipCustomSize:!0,expandOnly:!0,formulaView:!1})}_initViewState(e,t){this._lastGetRangeRead=null,this._lastCellDecoded.address=null,this._lastCellSelected.coords=null,this._lastCellRead.coords=null,this._cellOptions?.renderCellCache?.clear(),this._entireCoordsCache=e,this._entireRangeCache=null;let r=this;this._protectionRemoveListener?.(),this._protection=new a_(void 0,this._options.readonly),this._protectionRemoveListener=this._protection.addListeners(this._protectionListener),this._stylesRemoveListener?.(),this._stylesRemoveListener=this._styles.addListeners(this._stylesListener),this._languageRemoveListener?.(),this._languageRemoveListener=n.DefaultLanguagePackService.addChangeListener(()=>{r._closed||r._invalidateRendering()}),this._regionalRemoveListener?.(),this._regionalRemoveListener=this._workbook?.addListeners({onRegionalChange:()=>{r._closed||r._invalidateRendering()}},{transactional:!1}),this._viewRemoveListener?.();let i=new ZR({sheet:this,json:t});this._view=i,this._viewRemoveListener=i.addListeners(this._viewListener,{transactional:!1});let a=this._getEntireCoords.bind(this),o={getRanges:(e,t)=>{if(!e)return ZV(this);let n=this._rangesToCoords(e);return r._createRanges(n,t)},getEntireRange:r.getEntireRange.bind(r)};this._updateState({borderSpatial:new jP({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0},entireCoords:e}),fillSpatial:new jP({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0},entireCoords:e}),contentSpatial:new jP({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0},entireCoords:e}),continuousFillSpatial:new yr({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0}}),dateFormatSpatial:new yr({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0}}),mergeSpatial:new jP({updateEntryOptions:{getShifted(e,t,n){let i=$h(n,r._getEntireCoords());return i?{...i,value:new eM(i,e.value._tvTl)}:null},getSplit(e,t){throw new n.ExpectedError((0,n.t)(`error.sheet.insertMergeThrough`))}},entireCoords:e}),movableMapModel:new Map,movableSpatial:new yr({updateEntryOptions:{getShifted(e,t,n){let i=e.value.callbacks.processShift?.(n),a=null,o=r._shiftedMovableModels??=new Map(r._getState().movableMapModel),s=e.value.model;return i?(a={...i,value:{...e.value}},o.set(s,a)):o.delete(s),a}}}),noteMapModel:new Map,noteSpatial:new yr({updateEntryOptions:{getShifted(e,t,n){let i=r._shiftedNoteModels??=new Map(r._getState().noteMapModel),a=e.value.model,o=a.isDeleted()?null:e.value.callbacks.processShift?.(n),s=null;return o?(s={...o,value:{...e.value}},i.set(a,s)):i.delete(a),s}}}),picture:null,hyperlinkSpatial:new yr({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}}),autoTables:new lv(o),tables:new lv(o),conditionalFormats:new lv(o),dataValidations:new lv(o),protectedRanges:new lv(o),comments:new lv(o),listeners:new lv({...o,isSplittable:!1,shiftEntry:(e,t)=>AN.shiftReference(t,a())}),entireCoords:{colStart:0,rowStart:0,colEnd:dV.width-1,rowEnd:dV.height-1},inputsCommitId:null,deleted:!1})}_initCellState(){let e=this,r={colStart:0,rowStart:0,colEnd:0,rowEnd:0},i=[r],a={ignoreHidden:!0,sort:{axis:t.IRange.Axis.Column,reverse:!1}};this._cellOptions={runtime:this._runtime,renderCellCache:new v_({max:eV}),doBatchCalcGrid:async(t,n)=>{this._getState();let r=this._beginCommit(n);try{let n=await t(this._calcGrid);n&&e._recordChange(r,`data`,[n]),r.commit()}catch(e){throw r.rollback(),e}this._calculation.getStatus()!==X.Status.Off&&await this._calculation.calculate({scope:this._calcGrid.getId()})},sheet:this,normalStyleRanged:this._normalStyleRanged,colHeaders:this._colHeaders,styles:this._styles,getRange:this.getRange.bind(this),getRanges:this.getRanges.bind(this),getProtection:this.getProtection.bind(this),getCalcGrid:()=>this._calcGrid,getCalculationStatus:()=>this._calculation.getStatus(),dependencyRanges:this._dependencyRanges.bind(this),resolveSheetScope:e=>this._resolveSheetScope(e),autoCorrect:(e,t)=>this.getCalculation().createFormula(e,{...t,scope:this.getName()}).autoCorrect(),createAt:(e,t)=>this.getCalculation().createFormula(e,{...t,scope:this.getName()}),nextContentful:(t,o,s=!1)=>{if(r.colStart=s?o:t.colIndex+1,r.rowStart=t.rowIndex,r.colEnd=s?t.colIndex-1:o,r.rowEnd=t.rowIndex,a.sort.reverse=s,!e._getState())return n.CommonUtils.EmptyArray;let c=e._getRangedEntries(e._calcGrid.getContentful(),i,a);if(!c||c.length===0)return o;let l=c[0],u=s?l.getState().colStart:l.getState().colEnd;return s?Math.min(u+1,t.colIndex):Math.max(u-1,t.colIndex)},styleUpdater:(t,n,r)=>{let i=[r];return e._updateStyles(i,t,n),e._getStyle(i)},opener:async(e,t,n,r)=>{if(e.startsWith(`#`)){e=e.substring(1);let n=this._rangesToCoords(e),r=n[0]?.scope;if(r&&r!==this.getName()){let n=this.getWorkbook()?.getSheets().getByName(r)??null;return!!n&&(await n.getRanges(e).select(t??!0),!0)}return await this._autoSelect(t??!0,DA(n)),!0}{let t=this._options.opener;return t?t(e,n??`_blank`,r):n===`_self`&&ov(e)&&(e=>{if(typeof document>`u`||!document.body)return!1;let t=document.createElement(`iframe`);return t.style.display=`none`,t.setAttribute(`aria-hidden`,`true`),t.src=e,document.body.appendChild(t),setTimeout(()=>t.remove(),5e3),!0})(e)||window.open(e,n??`_blank`,r),!0}}},this._emptyCell=new YM(this._cellOptions)}_createTables(e,t,r,i,a){let o=this,s=()=>{let e=o._cacheTableColumnHeaders;e.lastRowIndex=-1,e.lastColIndex=-1,o._markColumnHeaderTableNames()};a||=e=>e.addListeners({onAnchorCoordsChange(){s(),o._notifyTablesChange()},onSortChange(){o._notifyTablesChange()},onFilterChange(){o._notifyTablesChange()},onHiddenButtonsChange(){o._notifyTablesChange()},onStyleChange(){o._cellOptions?.renderCellCache?.clear(),o._notify(`onStyleChange`)},onDelete(t){o._announcedDeletes.delete(e)||(o._cellOptions?.renderCellCache?.clear(),s(),o._notifyTablesChange())}},{transactional:!1});let c={createModel:e=>i({transactions:o._transactions,sheet:o,names:o._names,isProtected:()=>!o._initializing&&!o.getProtection().isObjectsAllowed(),processTableUpdate(){o._notifyUsedRangeChange()},filteredChanged(){o._tellFiltered()},releaseReferences(e,t){o._calculation._releaseTableReferences(e,t)},symbolsChanged(e){o._calculation._tableChanged(e,!1)},refitBodyRows(e,t,n,r,i,a){o._calculation._refitTableRows(o.getId(),e,t,n,r,i,a)},...e}),addListeners:a,setContainerCoords(e,r,i){let a=i?.description??(0,n.messageKey)(`op.resizeTable`);o._protectionCheck(()=>[`objects`],r,a);let s=r[0];o._validateOrRemoveOverlaps(s,`table`,e);let c=o._beginCommit({description:a}),l=o._getState()?.[t];l=l.setCoords(e,[s]),o._updateState({[t]:l}),o._recordSelection(c,DA(e.getRanges().getCoords()),i),c.commit()},setContainerName(e,r,i){let a=i?.description??(0,n.messageKey)(`op.setTableName`);o._protectionCheck(()=>[`objects`],void 0,a);let s=o._beginCommit({description:a});try{let a=o._getState()?.[t],c=a.getByName(r);if(c&&c!==e)throw new n.ExpectedError((e=>(0,n.t)(`error.sheet.uniqueName`,{name:e}))(r));a=a.setName(e,r),o._updateState({[t]:a},i),o._calculation._tableChanged(e,!1),o._notifyTablesChange(),s.commit()}catch(e){throw s.rollback(),e}},deleteFromContainer(e,r){let i=r?.description??(0,n.t)(`op.deleteTableNamed`,{name:e.getName?.()});o._protectionCheck(()=>[`objects`],void 0,i);let a=o._beginCommit({description:i}),c=o._getState()?.[t];c=c.deleteModel(e),o._updateState({[t]:c}),o._calculation._tableChanged(e,!0),o._tellFiltered(),o._announcedDeletes.add(e),o._notifyTablesChange(),o._notify(`onLayoutChange`),s(),o._recordSelection(a,DA(e.getRanges().getCoords()),r),a.commit()}};return e.load(r,c)}_createDataValidations(e,t,r,i,a){let o=this;a||=e=>e.addListeners({onAnchorCoordsChange(){o._notifyDataValidationsChange()},onAnyChange(){o._notifyDataValidationsChange()},onDelete(t){o._announcedDeletes.delete(e)||o._notifyDataValidationsChange()}},{transactional:!1});let s={createModel:e=>i({transactions:o._transactions,isProtected(){if(o._initializing)return!1;let e=o.getProtection();return e.isLocked()||e.isReadOnly()},getGridValues:()=>o._calcGrid.getValues(),getRuntime:()=>o.getRuntime(),getCalculation:()=>o._calculation??null,...e}),addListeners:a,invalidate(e){o._notifyUsedRangeChange(),o._notifyDataValidationsChange()},setContainerCoords(e,r,i){let a=i?.description??(0,n.messageKey)(`op.updateDataValidations`);o._protectionCheck(()=>[],r,a);let s=o._beginCommit({description:a}),c=o._getState()?.[t];c=c.setCoords(e,r),o._updateState({[t]:c}),o._notifyDataValidationsChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},getContainerIndex:e=>(o._getState()?.[t]).getIndex(e)??-1,setContainerIndex(e,r,i){let a=i?.description??(0,n.messageKey)(`op.reorderDataValidations`);o._protectionCheck(()=>[],e.getRanges().getCoords(),a);let s=o._beginCommit({description:a}),c=o._getState()?.[t];c=c.setIndex(e,r),o._updateState({[t]:c}),o._notifyDataValidationsChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},deleteFromContainer(e,r){let i=r?.description??(0,n.t)(`op.deleteDataValidationNamed`,{name:e.getName?.()});o._protectionCheck(()=>[],void 0,i);let a=o._beginCommit({description:i}),s=o._getState()?.[t];s=s.deleteModel(e),o._updateState({[t]:s}),o._announcedDeletes.add(e),o._notifyDataValidationsChange(),o._recordSelection(a,DA(e.getRanges().getCoords()),r),a.commit()}};return e.load(r,s)}_createConditionalFormats(e,t,r,i,a){let o=this;a||=e=>e.addListeners({onAnchorCoordsChange(){o._notifyConditionalFormatsChange()},onDelete(t){o._announcedDeletes.delete(e)||o._notifyConditionalFormatsChange()}},{transactional:!1});let s={createModel:e=>i({transactions:o._transactions,sheet:o,isProtected:()=>!o._initializing&&!o.getProtection().isFormatCellsAllowed(),getGridValues:()=>o._calcGrid.getValues(),getRuntime:()=>o.getRuntime(),getCalculation:()=>o._calculation??null,...e}),addListeners:a,invalidate(e){o._invalidateCaches(),o._notifyUsedRangeChange(),o._notifyConditionalFormatsChange()},setContainerCoords(e,r,i){let a=i?.description??(0,n.messageKey)(`op.updateConditionalFormat`);o._protectionCheck(()=>[`formatCells`],e.getRanges().getCoords(),a),o._protectionCheck(()=>[`formatCells`],r,a);let s=o._beginCommit({description:a});o.getProtection().isLocked()&&o._recordSkipProtectionCheck(s);let c=o._getState()?.[t];c=c.setCoords(e,r),o._updateState({[t]:c}),o._notifyConditionalFormatsChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},getContainerIndex:e=>(o._getState()?.[t]).getIndex(e)??-1,setContainerIndex(e,r,i){let a=i?.description??(0,n.messageKey)(`op.reorderConditionalFormat`);o._protectionCheck(()=>[`formatCells`],e.getRanges().getCoords(),a);let s=o._beginCommit({description:a});o.getProtection().isLocked()&&o._recordSkipProtectionCheck(s);let c=o._getState()?.[t];c=c.setIndex(e,r),o._updateState({[t]:c}),o._notifyConditionalFormatsChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},deleteFromContainer(e,r){let i=r?.description??(0,n.t)(`op.deleteConditionalFormatNamed`,{name:e.getName?.()});o._protectionCheck(()=>[`formatCells`],void 0,i);let a=o._beginCommit({description:i});o.getProtection().isLocked()&&o._recordSkipProtectionCheck(a);let s=o._getState()?.[t];s=s.deleteModel(e),o._updateState({[t]:s}),o._announcedDeletes.add(e),o._notifyConditionalFormatsChange(),o._recordSelection(a,DA(e.getRanges().getCoords()),r),a.commit()}};return e.load(r,s)}_createProtectedRanges(e,t,r,i,a){let o=this;a||=e=>e.addListeners({onAnchorCoordsChange(){o._notifyProtectedRangesChange()},onConfigChange(){o._notifyProtectedRangesChange()},onDelete(t){o._announcedDeletes.delete(e)||o._notifyProtectedRangesChange()}},{transactional:!1});let s={createModel:e=>i({transactions:o._transactions,isProtected(){if(o._initializing)return!1;let e=o.getProtection();return e.isLocked()||e.isReadOnly()},...e}),addListeners:a,invalidate(e){o._notifyProtectedRangesChange()},setContainerCoords(e,r,i){let a=i?.description??(0,n.messageKey)(`op.updateProtectedRanges`);o._protectionCheck(()=>[],r,a);let s=o._beginCommit({description:a}),c=o._getState()?.[t];c=c.setCoords(e,r),o._updateState({[t]:c}),o._notifyProtectedRangesChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},setContainerName(e,r,i){let a=i?.description??(0,n.messageKey)(`op.setProtectedRangeName`);o._protectionCheck(()=>[],void 0,a);let s=o._beginCommit({description:a});try{let a=o._getState()?.[t],c=a.getByName(r);if(c&&c!==e)throw new n.ExpectedError((0,n.t)(`error.protectedRange.uniqueName`,{name:r}));a=a.setName(e,r),o._updateState({[t]:a},i),o._notifyProtectedRangesChange(),s.commit()}catch(e){throw s.rollback(),e}},getContainerIndex:e=>(o._getState()?.[t]).getIndex(e)??-1,setContainerIndex(e,r,i){let a=i?.description??(0,n.messageKey)(`op.reorderProtectedRange`);o._protectionCheck(()=>[],e.getRanges().getCoords(),a);let s=o._beginCommit({description:a}),c=o._getState()?.[t];c=c.setIndex(e,r),o._updateState({[t]:c}),o._notifyProtectedRangesChange(),o._recordSelection(s,DA(e.getRanges().getCoords()),i),s.commit()},deleteFromContainer(e,r){let i=r?.description??(0,n.t)(`op.deleteProtectedRangeNamed`,{name:e.getName?.()});o._protectionCheck(()=>[],void 0,i);let a=o._beginCommit({description:i}),s=o._getState()?.[t];s=s.deleteModel(e),o._updateState({[t]:s}),o._announcedDeletes.add(e),o._notifyProtectedRangesChange(),o._recordSelection(a,DA(e.getRanges().getCoords()),r),a.commit()}};return e.load(r,s)}_createComments(e,t,r,i,a){let o=this;a||=e=>e.addListeners({onAnchorCoordsChange(){o._notifyCommentsChange()},onContentChange(){o._notifyCommentsChange()},onResolvedChange(){o._notifyCommentsChange()},onRepliesChange(){o._notifyCommentsChange()},onDelete(t){o._announcedDeletes.delete(e)||o._notifyCommentsChange()}},{transactional:!1});let s={createModel:e=>i({transactions:o._transactions,isProtected:()=>!o._initializing&&!o.getProtection().isObjectsAllowed(),getPeople:()=>o.getWorkbook()?.getPeople()??null,boxes:o._noteBoxes,...e}),addListeners:a,invalidate(e){o._notifyCommentsChange()},setContainerCoords(e,r,i){let a=i?.description??(0,n.messageKey)(`op.updateComment`);o._protectionCheck(()=>[`objects`],e.getRanges().getCoords(),a),o._protectionCheck(()=>[`objects`],r,a);let s=o._beginCommit({description:a}),c=o._getState()?.[t];c=c.setCoords(e,r),o._updateState({[t]:c}),o._notifyCommentsChange(),s.commit()},getContainerIndex:e=>(o._getState()?.[t]).getIndex(e)??-1,deleteFromContainer(e,r){let i=r?.description??(0,n.messageKey)(`op.deleteComment`);o._protectionCheck(()=>[`objects`],void 0,i);let a=o._beginCommit({description:i}),s=o._getState()?.[t];s=s.deleteModel(e),o._updateState({[t]:s}),o._announcedDeletes.add(e),o._notifyCommentsChange(),a.commit()}};return e.load(r,s)}_newCommentJSON(e){let t=this.getWorkbook()?.getPeople()??null,r=!!e.asNote,i={id:n.CommonUtils.uuidV4().toUpperCase(),content:oj(e.content)},a=pj(e.person,t);return a&&(i.personId=a),r?i.asNote=!0:(i.dt=new Date().toISOString(),e.resolved&&(i.done=!0)),i}_createMovableEntry(e,t,r,i=this._placedIndex,a){let o=null;if(e?.anchor)o={colStart:e.anchor.tl?.c??0,rowStart:e.anchor.tl?.r??0,colEnd:e.anchor.br?.c??0,rowEnd:e.anchor.br?.r??0},e.anchor.br?.x||--o.colEnd,e.anchor.br?.y||--o.rowEnd;else{let e=this.getSelection().getRange().getCoords();o={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}}let s={model:null,callbacks:{processShift:null,processAfterShift:null,processLayout:null,processDelete:null,processZIndex:null,processSelection:null,processProtection:null},zIndex:t},c={...o,value:s},l=()=>s.model?d._getState()?.[i.byModel]?.get(s.model):c,u=(e,t,r=!0)=>{if(p)return;let a=l();if(!a)return;let o=t??(0,n.messageKey)(`op.updateDrawing`);d._protectionCheck(()=>[`objects`],void 0,o);let s=d._beginCommit({description:o}),u=(d._getState()?.[i.spatial]).clone(),f=d._getState()?.[i.byModel],m=new Map(f);!1!==e(a,u,m)&&(d._updateState({[i.spatial]:u,[i.byModel]:m}),r&&(d._emitterMovables.notify(`onCollectionChange`,{transactional:!0}),d._notify(`onMovablesChange`)),c.value.model.isSelected()&&d._recordMovableSelection(`after`,d.getView().getMovableSelection(),s),s.commit())},d=this,f=e.content.type,p=!0,m=(e,t,n,r)=>{let i=n.all().sort((e,t)=>e.value.zIndex-t.value.zIndex),a=t.value.zIndex;if((e=Math.max(0,Math.min(i.length-1,e)))===a)return!1;let o=[],s=[],c=[],l=a<e,u=t=>{let n=i[t];o.push(n);let u={...n,value:{...n.value,zIndex:l?t-1:t+1}};n.value.zIndex===a&&(u.value.zIndex=e),s.push(u),r.set(u.value.model,u),c.push(u)};if(l)for(let t=a;t<=e;t++)u(t);else for(let t=a;t>=e;t--)u(t);let d=o.length;for(let e=0;e<d;e++)n.remove(o[e],xV);n.load(s);let f=c.length;for(let e=0;e<f;e++)c[e].value.callbacks.processZIndex?.()},h=()=>d._resources.beginPersist(),g=f===`picture`,_={content:null,fromResourceId:r,defaultLockAspectRatio:g,beginPersistResource:h,getMaxBounds:()=>d._getBoundsAtCoords(d._getEntireCoords()),getRanges:e=>d.getRanges(e),invalidate:()=>{d._initializing||d._closed||(d._emitterMovables.notify(`onCollectionChange`),d._notify(`onMovablesChange`))},runtime:this._runtime,transactions:this._transactions,getBoundsAtCoords:d._getBoundsAtCoords.bind(d),getCoordsAtBounds:d._getCoordsAtBounds.bind(d),scrollIntoView:async e=>{let t=l()?.value?.model;return!!t&&d._selectSheet(t.getRange().getCoords(),e)},select:async e=>{let t=l()?.value?.model;if(!t)return!1;try{d.getView().selectMovables([t],e?.addToSelection)}catch(e){return console.warn(e),!1}let n=await d._selectSheet(t.getRange().getCoords(),e?.scrollIntoView);return!e?.scrollIntoView||!1!==n},unselect:()=>{let e=l()?.value?.model;return!!e&&(d.getView().unselectMovables([e]),!0)},isSelected(){let e=l()?.value?.model;return!!e&&d.getView().getMovableSelection().includes(e)},moveToBackOnContainer:()=>{u((e,t,n)=>m(0,e,t,n),(0,n.messageKey)(`op.moveToBack`))},moveBackwardOnContainer:()=>{u((e,t,n)=>m(e.value.zIndex-1,e,t,n),(0,n.messageKey)(`op.moveBackwards`))},moveForwardOnContainer(){u((e,t,n)=>m(e.value.zIndex+1,e,t,n),(0,n.messageKey)(`op.moveForward`))},moveToFrontOnContainer(){u((e,t,n)=>m(t.size()-1,e,t,n),(0,n.messageKey)(`op.moveToFront`))},getZIndex:()=>i.zIndexBase()+(l()?.value?.zIndex??0),getContainerIndex:()=>l()?.value?.zIndex??0,setContainerIndex(e,t){u((t,n,r)=>m(e,t,n,r),t?.description??(0,n.messageKey)(`op.setIndex`))},setContainerCoords(e,t){if(!e)return;let r=d._rangesToCoords(e,()=>[`objects`]),i=r[0];return c.colStart=i.colStart,c.rowStart=i.rowStart,c.colEnd=i.colEnd,c.rowEnd=i.rowEnd,u((e,t,n)=>{let r={...e,...i};t.remove(e,xV),t.insert(r),n.set(r.value.model,r)},(0,n.messageKey)(`op.updateDrawing`),!1),r},deleteFromContainer(e){let t=l();t?.value&&d.getView().unselectMovables([t.value.model]);let r=[];u((e,t,n)=>{n.delete(e.value.model),t.remove(e,xV),e.value.callbacks.processDelete?.(),r.push(e);let i=e.value.zIndex,a=t.all().sort((e,t)=>e.value.zIndex-t.value.zIndex),o=[],s=[],c=a.length;for(let e=i+1;e<c;e++){let t=a[e];o.push(t);let r={...t,value:{...t.value,zIndex:e-1}};s.push(r),n.set(r.value.model,r)}let l=o.length;for(let e=0;e<l;e++)t.remove(o[e],xV);t.load(s)},e?.description??(0,n.messageKey)(`op.deleteDrawing`),!0);let i=r.length;for(let e=0;e<i;e++)r[e].value.callbacks.processZIndex?.()},setContainerCallbacks(e){let t=l()?.value??s;t&&(t.callbacks={...t.callbacks,...e},t.removeListener?.())},isProtected:()=>!d._initializing&&!d.getProtection().isObjectsAllowed(),coords:o,getEntireRange:d.getEntireRange.bind(d),json:e},v=e.content.json,y=e,b={type:f,transactions:this._transactions,beginPersistResource:h,fromResourceId:r,defaultLockAspectRatio:g,json:v,name:e.content.name??y.name??null,description:e.content.description??y.description??null,isReadOnly:_.isProtected,deleteFromContainer:()=>{s.model._deleteFromContent()},getMovable:()=>s.model,getRange:e=>(this.getWorkbook()??this).getRange(e),holdFormulas:e=>this._holdFormulas(e)},x=a??null;return x||(f===`picture`?x=new Ck(b):f===`chart`?x=new Qk(b):f===`shape`||f===`sp`||f===`cxnSp`||f===`grpSp`?x=new iA(b):f===`relIds`?x=new sA({...b,type:`smartArt`}):f===`slicer`?x=new oA(b):f===`control`?x=new cA(b):(f===`graphicFrame`||console.warn(kj(f)),x=new sA(b))),s.model=i.create({..._,content:x}),p=!1,c}_fromJSON(e,r=!1){this._initializing=!0,this._emitter.notify(`onBeforeLoad`,{params:e});let i=this._beginCommit({description:(0,n.messageKey)(`op.loadSheet`)});this._recordInitial(i);let a=e||{},o=this._strings.beginPersist(),s=this._resources.beginPersist(),l=this._styles.beginPersist();try{this._ownStrings&&o.fromJSON(a.strings),this._ownResources&&s.fromJSON(a.resources),this._ownStyles&&l.fromJSON(a.styles);let e={colStart:0,rowStart:0,colEnd:dV.width-1,rowEnd:dV.height-1},u=a.entireSize;u&&(e=Object.freeze({colStart:0,rowStart:0,colEnd:(u.width??dV.width)-1,rowEnd:(u.height??dV.height)-1}));let d=CH(a.cols,t.IRange.Axis.Column,e),f=CH(a.rows,t.IRange.Axis.Row,e);this._initHeadersState({headers:a.cols,defaultSize:a.defaultColSize},{headers:a.rows,defaultSize:a.defaultRowSize}),this._initViewState(e,a.view),this._colHeaders.invalidate(),this._rowHeaders.invalidate(),this._initCellState(),a.tabColor&&(this._tabColor=this._styles.parseColor(a.tabColor)),this._codeName=a.codeName??null,this._outlineSettings=a.outline?Object.freeze({...fV,...a.outline}):fV,this._conditionalFormatCalculation=a.conditionalFormatCalculation??!0;let p=a.modules;if(p||this._modules.getCount()>0){let e=this,t={};for(let n of Object.keys(p??{}))t[n]=uk(n,p[n],()=>e);this._modules.close(),this._modules=new zO({transactions:this._transactions,initial:t,isReadOnly:()=>this._isModulesReadOnly()})}let m=this._getState(),h=a.data,g=h?.length??0,_=this._lists,v=[];if(g>0)for(let e=0;e<g;e++){let t=h[e];typeof t==`string`&&(t=JSON.parse(t));let n=t[1],r=n.length;for(let e=0;e<r;e++){let t=n[e];t[1]=_.fromJSONRun(t[1])}v.push(t)}let y=m.borderSpatial,b=m.fillSpatial,x=m.contentSpatial,S=m.continuousFillSpatial,C=m.dateFormatSpatial,w=this._options.styles,T=a.directStyles,E,D;if(T){let n=T.length;E=Array(n);for(let r=0;r<n;r++){let n=Ud(T[r],e);n.value={axes:t.IRange.AxisSelection.Both,index:n.value},E[r]=n}}if(d||f){let e=[...E||n.CommonUtils.EmptyArray,...d||n.CommonUtils.EmptyArray,...f||n.CommonUtils.EmptyArray];E=[];try{let n=new Vt.IteratorInstance(e,{axis:t.IRange.Axis.Column}),r=n.next();for(;!r.done;){let e=r.value,i=e.overlaps,a=i.length,o;if(a===1){if(o=i[0].value,o.index===0){r=n.next();continue}}else{let e,n,r;for(let o=0;!e&&o<a;o++){let a=i[o].value,s=a.axes;s===t.IRange.AxisSelection.Both?e=a:s===t.IRange.AxisSelection.Row?r=a:s===t.IRange.AxisSelection.Column&&(n=a)}o=e??r??n}let s=e.range;E.push({...s,value:o}),r=n.next()}}catch(e){console.log(e)}}if(E){let e=this._getEntireCoords.bind(this),r=[],i=[],a=[],o=t=>{let o=t.value,s=l.getElementJSON(o.index),u=n.CoordUtils.sanitizeRange(t),d=new tg(w,e,u,s,void 0,o.axes),f=d._p?.alignment?.horizontal;f===c.HorizontalAlignment.CenterContinuous&&r.push(u),f===c.HorizontalAlignment.Fill&&i.push(u);let p=d._p?.numberFormat;return typeof p==`number`&&(p=cu(p)),p&&(Fl(p)||Il(p))&&a.push({...u,value:p}),{...u,value:d}},s=E.length;D=Array(s);for(let e=0;e<s;e++)D[e]=o(E[e]);let u=[],d=[],f=[];for(let e=0;e<s;e++){let t=D[e];if(!t.value)continue;let n=t.value.splitByFeature();n.border&&u.push({...t,value:n.border}),n.fill&&d.push({...t,value:n.fill}),n.content&&f.push({...t,value:n.content})}let p=(e,n)=>{n.length!==0&&e.load(n.length>1?Or(n,t.IRange.Axis.Column,2**53-1,jr):n)};p(y,u),p(b,d),p(x,f);let m=(n,r)=>{let i=(n=Or(n,t.IRange.Axis.Column,2**53-1)).length,a=Array(i);for(let t=0;t<i;t++){let i=n[t];a[t]={...i,value:new tg(w,e,i,{alignment:{horizontal:r}})}}S.load(a)};m(r,c.HorizontalAlignment.CenterContinuous),m(i,c.HorizontalAlignment.Fill),a=Or(a,t.IRange.Axis.Column,2**53-1),C.load(a)}m=this._updateState({borderSpatial:y,fillSpatial:b,contentSpatial:x,continuousFillSpatial:S,dateFormatSpatial:C,entireCoords:e});let O=a.merges;if(O){let t=[],n=O.length;for(let r=0;r<n;r++){let n=ef(O[r],e);t.push(n)}this._indexMerges(t)}let k=m.hyperlinkSpatial,A=a.hyperlinks;if(A){let t=A,n=t.length,r=Array(n);for(let i=0;i<n;i++){let n=Ud(t[i],e),a=n.value;n.value=typeof a==`string`?{address:a}:{...a},r[i]=n}k.load(r)}let j=m.comments,M=a.comments;M&&(j=this._createComments(j,`comments`,function(e){let t=[],r=new Map,i=null;for(let a=0;a<e.length;a++){let o=e[a];if(!o)continue;let s=Array.isArray(o),c=s?o[0]:o.r,l=s?o[1]:o.v;if(l==null)continue;let u=typeof l==`string`?{id:n.CommonUtils.uuidV4().toUpperCase(),content:l}:{...l},d=u.parentId;d?(delete u.parentId,(i??=[]).push({parentId:d,json:u})):(u.id||=n.CommonUtils.uuidV4().toUpperCase(),r.set(u.id,u),t.push({r:c,v:u}))}if(i)for(let e=0;e<i.length;e++){let{parentId:t,json:n}=i[e],a=r.get(t);if(!a)continue;let{done:o,asNote:s,replies:c,box:l,...u}=n;a.replies=[...a.replies??[],u]}return t}(M),e=>new yj(e)));let N=m.tables,P=a.tables;P&&(N=this._createTables(N,`tables`,P,e=>new yO(e)));let F=m.autoTables,I=a.autoTable;I&&(F=this._createTables(F,`autoTables`,[I],e=>new RO(e)));let L=m.dataValidations,R=a.validations;R&&(L=this._createDataValidations(L,`dataValidations`,R,e=>new XA(e)));let ee=m.conditionalFormats,te=a.conditionals;te&&(ee=this._createConditionalFormats(ee,`conditionalFormats`,te,e=>new IA(e)));let ne=m.protectedRanges,re=a.protectedRanges;re&&(ne=this._createProtectedRanges(ne,`protectedRanges`,re,e=>new tj(e)));let ie=m.movableMapModel,ae=m.movableSpatial,oe=a.movables;if(oe){let e=[],t=oe.length;for(let n=0;n<t;n++){let t=oe[n];try{let r=this._createMovableEntry(t,n,s.fromResourceId.bind(s));ie.set(r.value.model,r),e.push(r)}catch(e){console.warn(`Unable to load movable`,n,t,e)}}ae.load(e)}let se=null,ce=a.picture;if(ce){let e=this;se=new Ck({json:ce,fromResourceId:s.fromResourceId.bind(s),deleteFromContainer:t=>{e._getState().picture&&(e._updateState({picture:null},{description:(0,n.messageKey)(`op.deletePicture`),...t}),e._notify(`onStyleChange`))},transactions:this._transactions})}let le=s.fromResourceId.bind(s);this._legacyDrawing=ZB(a.legacyDrawing,le),this._legacyDrawingHF=ZB(a.legacyDrawingHF,le);let ue=[],de=a.pivotTables;if(de)for(let e=0;e<de.length;e++){let t=de[e];t&&typeof t.cacheId==`number`&&ue.push(new dA({json:t,sheet:this,fromResourceId:le}))}this._pivotTables=ue,m=this._updateState({hyperlinkSpatial:k,movableSpatial:ae,movableMapModel:ie,autoTables:F,tables:N,conditionalFormats:ee,dataValidations:L,protectedRanges:ne,comments:j,picture:se});let fe={};a.formulas&&(fe.formulas=a.formulas),v.length>0&&(fe.data=v),a.formulaArray&&(fe.formulaArray=a.formulaArray),a.volatile&&a.volatile.length>0&&(fe.volatile=a.volatile);let pe=uH(this._rowHeaders);pe.length>0&&(fe.hiddenRows=pe);let me=uH(this._colHeaders);me.length>0&&(fe.hiddenColumns=me),this._filteredTables().length>0&&(fe.filtered=!0);let he=this._options.calcGrid;if(he?(this._calcGrid=he,this._ownsCalcGrid=!1):this._calcGrid=this._openCalcGrid(fe),!r){let e=this._getUsedCoords();e&&this._autoFit([e],{axes:t.IRange.AxisSelection.Row,skipCustomSize:!0,expandOnly:!0,formulaView:!1})}i.commit(),a.protection&&this._protection.fromJSON(a.protection),this._notify(`onLoad`)}finally{l.endPersist(),s.endPersist(),o.endPersist()}this._initializing=!1}getId(){return this._id}getVersionId(){return this._transactions.getVersionId(this._stateId)}getName(){return this._closed?Qu:this._options.container?.getName?.()??null}setName(e,t){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let r=this._options.container?.setName;if(!r)throw new n.ExpectedError(`Unable to set name for sheet.`);return r(e,t),this}getVisibility(){return this._closed?Eu.Visibility.VeryHidden:this._options.container?.getVisibility?.()??Eu.Visibility.Hidden}setVisibility(e=!0,t){if(this._closed)throw Error((0,n.t)(`error.sheet.modelClosed`));let r=this._options.container?.setVisibility;if(!r)throw new n.ExpectedError(`Unable to set visibility for sheet.`);let i;return i=!0===e?Eu.Visibility.Visible:!1===e?Eu.Visibility.Hidden:e,r(i,t),this}async select(e){return await this._options.container?.requestSelect?.(e),this}async duplicate(){return await this._options.container?.duplicate?.(),this}getIndex(){return this._options.container?.getIndex?.()??-1}setIndex(e,t){return this._options.container?.setIndex?.(e,t),this}getNames(){let e=this._names;return e&&(this._namesScoped||=e._scopedTo(this),this._namesScoped)}getCalculation(){let e=this._calculation;if(!e)return e;if(!this._calculationScoped){let t=this,n=new Map,r=e=>({...e??{},scope:e?.scope??t.getName()});this._calculationScoped=new Proxy(e,{get:(e,t)=>{if(t===`createFormula`)return(t,n,i)=>e.createFormula(t,r(n),i);if(t===`evaluate`)return(t,n)=>e.evaluate(t,r(n));let i=Reflect.get(e,t,e);if(typeof i!=`function`)return i;let a=n.get(t);return a||(a=i.bind(e),n.set(t,a)),a}})}return this._calculationScoped}createFormula(e,t,n){return this.getCalculation().createFormula(e,t,n)}evaluate(e,t){return t=typeof t==`number`?{evalIndex:t,scope:this.getName()}:{...t,scope:this.getName()},this.getCalculation().evaluate(e,t)}whenCalculationReady(){let e=this._starting;return e?e.then(()=>this.getCalculation().ready()):this.getCalculation().ready()}getWorkbook(){return this._workbook}get[Symbol.toStringTag](){return`[Sheet]`}toString(){return`[${this.getName()??`(untitled)`}]`}get isISheet(){return!0}},eV=8192,tV=/^\$?[A-Za-z]{1,3}\$?\d{1,7}(:\$?[A-Za-z]{1,3}\$?\d{1,7})?$/,nV={ignoreDataChanges:!1},rV={colStart:-1,rowStart:-1,colEnd:-1,rowEnd:-1},iV=class{constructor(e){Object.assign(this,e),Object.freeze(this)}get isICellRangeCounts(){return!0}};function aV(e){return new iV(e)}function oV(e,t,n){let r=gv.Feature;switch(t){case r.Contentful:return!!e.contentful;case r.DateFormat:return!!e.dateFormat;case r.Formula:return!!e.formula;case r.Spills:return!!e.spills;case r.CalcError:return e.calcError!==void 0;case r.Circular:return!!e.circular;case r.Error:return!!e.error;case r.Fill:return!!e.fillStyle;case r.Borders:return!!e.borderStyle;case r.Merge:return!!e.merge;case r.Table:return!!e.table;case r.AutoTable:return!!e.autoTable;case r.Hyperlink:return!!e.hyperlink;case r.Comments:return!!e.comments;case r.Unlock:return!!e.unlock||zh(n,e.contentStyle?.getPropertiesAt(0,0,null));case r.Conditionals:return!!e.conditionals;case r.DataValidations:return!!e.dataValidations;default:return!1}}var sV={skipCustomSize:!0,expandOnly:t.IRange.Axis.Column,minContent:!0},cV={rowStart:0,colStart:0,rowEnd:0,colEnd:0},lV=[],uV=()=>null,dV={width:2**14,height:2**20},fV=Object.freeze({summaryBelow:!0,summaryRight:!0,showOutlineSymbols:!0,applyStyles:!1}),pV=e=>`${e}`,mV=e=>id(e),hV=e=>`${e+1}`,gV=0,_V=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),vV=Object.freeze({rowIndex:0,colIndex:0}),yV=()=>{},bV=e=>new AN(e),xV=(e,t)=>!(!n.CoordUtils.isEqualRanges(e,t)||e.value.model!==t.value.model),SV={useFormattingCategory:!0},CV=e=>e==null||e===0||typeof e==`string`&&e.toLowerCase()===`general`,wV,TV=e=>typeof e==`object`&&!!e&&!0===e.isICellRange,EV=class e{constructor(e,t,n){this._coords=Object.freeze(e),this._internal=t,this._readOnly=n?.readOnly??null,this._options=n??void 0,this._cacheRanges=[]}_getStickyOptions(){return this._options?.getOptions}_createRanges(t,n){let r=this._options;return n&&(r={...this._options,getOptions:xH(this._options?.getOptions,n)}),new e(t,this._internal,r)}_createRange(e,t){if(typeof e==`string`)return this._internal.createRange(e,xH(this._getStickyOptions(),t));let n=this._options;t&&(n={...this._options,getOptions:xH(this._options?.getOptions,t)});let r=qV(this._internal,e?.scope);return r?new Kj(e,r,n):XV(this._internal.getSheet(),this._internal.getSheet().getEntireCoords(),e)}_validateWrite(){let e=this._readOnly;if(e)throw Error((0,n.t)(e))}_byScope(){let e=this.getCoords(),t=this._internal,n=!1;for(let r=0;r<e.length;r++){let i=e[r]?.scope;if(i&&qV(t,i)!==t){n=!0;break}}if(!n)return null;let r=[],i=new Map;for(let n=0;n<e.length;n++){let a=e[n];if(!a)continue;let o=qV(t,a.scope);if(!o)continue;let s=o.getSheet().getName(),c=i.get(s);c||(c={internal:o,coords:[]},i.set(s,c),r.push(c)),c.coords.push(a.scope?{...a,scope:void 0}:a)}return r}_writeByScope(e,t){let n=this._byScope();n?this.doBatch(()=>{for(let t=0;t<n.length;t++)e(n[t].internal,n[t].coords)},t):e(this._internal,this.getCoords())}_readCoordsByScope(e){let t=this._byScope();if(!t)return e(this._internal,this.getCoords());let n=this._internal,r=[];for(let i=0;i<t.length;i++){let a=t[i],o=a.internal===n?void 0:a.internal.getSheet().getName(),s=e(a.internal,a.coords);for(let e=0;e<s.length;e++)r.push(o?{...s[e],scope:o}:s[e])}return r}getCoords(){let e=this._coords;for(let t=0;t<e.length;t++){let n=e[t];if(typeof n==`string`||TV(n))return this._resolveCoords()}return e}_resolveCoords(){let e=this._coords,t=this._cacheRanges,n=Array(e.length);for(let r=0;r<e.length;r++){let i=e[r];if(typeof i==`string`)n[r]=(t[r]??(t[r]=this._createRange(i))).getCoords();else if(TV(i)){t[r]||(t[r]=i);let e=i.getCoords(),a=i.getSheet()?.getName();n[r]=a&&a!==this._internal.getSheet().getName()&&!e.scope?{...e,scope:a}:e}else n[r]=i}return n}[Symbol.iterator](){let e=this.entries({features:Gj});return{next(){let t=e.next();return t.done?zt:{done:!1,value:t.value.value}},[Symbol.iterator](){return this}}}entries(e){let t=this.getCoords(),n=e?.reverse??!1,r=n?t.length-1:0,i=this,a=i.at(r),o=a.entries(e),s=o.next();return{next(){let c=s;do{if(s.done){if(r=n?r-1:r+1,r>=t.length||r<0)return s=zt,c;a=i.at(r),o=a.entries(e)}s=o.next()}while(s.done);return c},[Symbol.iterator](){return this}}}async select(e){let t=await this._internal.autoSelect(e??!0,DA(this.getCoords()));return this._createRanges(t)}calculate(){let e=this._byScope();if(!e)return this._internal.calculate(this.getCoords()),this;for(let t=0;t<e.length;t++)e[t].internal.calculate(e[t].coords);return this}addListener(e,t){return this._listenByScope((n,r)=>n.addListenerNode(r,e,t))}addWatch(e,t,n){return this._addWatch(e,(r,i,a)=>r._addWatch(e,{onValues:e=>{t(e,i,r)}},a,n))}_addWatch(e,t){let r=this.getCount();if(r===0)return()=>{};let i=n.CoordUtils.unionRangesArrays(this.getCoords()),a={rowIndex:i.rowStart,colIndex:i.colStart},o=[];for(let e=0;e<r;e++)o.push(t(this.at(e),e,a));return()=>{for(let e=0;e<o.length;e++)o[e]()}}_listenByScope(e){let t=this._byScope();if(!t)return e(this._internal,this.getCoords());let n=Array(t.length);for(let r=0;r<t.length;r++)n[r]=e(t[r].internal,t[r].coords);return()=>{for(let e=0;e<n.length;e++)n[e]?.()}}find(e){let t=this._byScope();if(!t)return this._internal.find(this.getCoords(),e);let n=0,r=t[0].internal.find(t[0].coords,e);return{next(){for(;;){let i=r.next();if(!i.done)return i;if(++n>=t.length)return zt;r=t[n].internal.find(t[n].coords,e)}}}}getFlattened(e){let t=this.getCoords();if(t.length===1)return this._createRanges(t,e);let n=TH(t);return this._createRanges(n,e)}getPrecedents(e=!1){return this._trace(!1,e)}getDependents(e=!1){return this._trace(!0,e)}async _trace(e,t){let n=this.getCoords(),r=[];for(let i=0;i<n.length;i++){if(!n[i])continue;let a=this.at(i);r.push(e?t?a.getDependents():a.getDirectDependents():t?a.getPrecedents():a.getDirectPrecedents())}let i=await Promise.all(r),a=[];for(let e=0;e<i.length;e++){let t=i[e];t&&t.getCount()>0&&a.push(...this._rehome(t))}return a.length===0?null:this._createRanges(a.length>1?TH(a):a)}_rehome(e){let t=this._internal.getSheet().getName(),n=e.getSheet()?.getName(),r=e.getCoords(),i=Array(r.length);for(let e=0;e<r.length;e++){let a=r[e],o=a.scope??n;i[e]=o===t?a.scope?{...a,scope:void 0}:a:{...a,scope:o}}return i}getVisible(e){let t=this._readCoordsByScope((t,n)=>t.getVisible(n,e));return t&&t.length!==0?this._createRanges(t,e):null}getFixed(e){let t=this.getCoords(),n=t.length,r=Array(n);for(let i=0;i<n;i++)r[i]=vH(t[i],e);return this._createRanges(r)}autoFit(e){return this._validateWrite(),this._writeByScope((t,n)=>t.autoFit(n,e),e),this}clear(e,t){return this._validateWrite(),this._writeByScope((n,r)=>n.clear(r,e,t),t),this}setValue(e,t){this._validateWrite();let r=this.getCoords();return r.length===1?(this._createRange(r[0]).setValue(e,t),this):(this.doBatch(()=>{for(let n=0;n<r.length;n++)this._createRange(r[n]).setValue(e,t)},{description:(0,n.messageKey)(`op.setValue`),...t}),this)}getStyle(){let e=this._byScope();if(!e)return this._internal.getStyle(this.getCoords());let t=e[0];return t.internal.getStyle(t.coords,void 0,(t,n)=>{this.doBatch(()=>{for(let r=0;r<e.length;r++)e[r].internal.updateStyles(e[r].coords,t,n)})})}merge(e){return this._validateWrite(),this._writeByScope((t,n)=>t.merge(n,e),typeof e==`object`?e:void 0),this}unmerge(e){return this._validateWrite(),this._writeByScope((t,n)=>t.unmerge(n,e),e),this}getMerges(){let e=this._getStickyOptions()?.ignoreHidden??!1;return this._readCoordsByScope((t,n)=>t.getMerges(n,e))}insert(e){if(this._validateWrite(),typeof e==`object`&&e?.span){if(this.getCount()!==1)throw new n.ExpectedError((0,n.t)(`error.address.singleRangeOnly`));return this.at(0).insert(e),this}return this._writeByScope((t,n)=>t.insertCells(n,e),typeof e==`object`?e:void 0),this}delete(e){if(this._validateWrite(),typeof e==`object`&&e?.span){if(this.getCount()!==1)throw new n.ExpectedError((0,n.t)(`error.address.singleRangeOnly`));return this.at(0).delete(e),this}return this._writeByScope((t,n)=>t.deleteCells(n,e),typeof e==`object`?e:void 0),this}async insertFrom(e,t){this._validateWrite();let n=await this._internal.insertFrom(this.getCoords(),e,t);return n?this._createRanges([n]):null}async copyFrom(e,t){let n=await this._internal.copyFrom(this.getCoords()[0],e,t);return n?this._createRanges([n]):null}isInvalidAny(){let e=this.getCoords(),t=e?e.length:0;if(t===0)return!0;for(let n=0;n<t;n++)if(e[n]===null)return!0;return!1}getSnapshot(e){return this._internal.getSnapshot(this.getCoords(),e)}getEntireRows(e,n){return this._createRanges(UV(this.getCoords(),this._internal.getSheet().getEntireCoords(),t.IRange.Axis.Column,e),n)}getEntireColumns(e,n){return this._createRanges(UV(this.getCoords(),this._internal.getSheet().getEntireCoords(),t.IRange.Axis.Row,e),n)}getRowHeaders(e){let t=this.getCoords();return this._internal.getSheet().getRowHeaders().getRanges(t,e)}getColumnHeaders(e){let t=this.getCoords();return this._internal.getSheet().getColumnHeaders().getRanges(t,e)}getDefaultShiftAxis(){return this._internal.getDefaultShiftAxis(this.getCoords()[0])}getCount(){return this.getCoords()?.length??0}get size(){let e=this.getCoords();if(!e)return 0;let t=0;for(let n of e)t+=(n.rowEnd-n.rowStart+1)*(n.colEnd-n.colStart+1);return t}get length(){return this.getCount()}getStats(e){return this._internal.getRangeStats(this.getCoords(),e)}getCounts(e){let t=this._getStickyOptions(),n=e??t?.features,r=t?.ignoreHidden??!1,i=this._byScope();if(!i)return this._internal.featureCounts(this.getCoords(),n,r);let a={};for(let e=0;e<i.length;e++){let t=i[e].internal.featureCounts(i[e].coords,n,r);for(let e of Object.keys(t))a[e]=(a[e]??0)+t[e]}return aV(a)}isContentful(e){let t=this._getStickyOptions(),n=e??t?.features;if(n===void 0){let e=this._byScope();if(!e)return this._internal.isContentful(this.getCoords(),t?.ignoreHidden??!1);for(let n=0;n<e.length;n++)if(e[n].internal.isContentful(e[n].coords,t?.ignoreHidden??!1))return!0;return!1}let r=this.getCounts(n),i=typeof n==`string`?[n]:n;for(let e=0;e<i.length;e++)if(r[i[e]]>0)return!0;return!1}getRowCount(){return this._internal.getSheet().getRowHeaders().getRanges(this.getCoords()).getHeaderCount()}getColumnCount(){return this._internal.getSheet().getColumnHeaders().getRanges(this.getCoords()).getHeaderCount()}isEntireRowsAny(){return this._internal.getSheet().getRowHeaders().getRanges(this.getCoords()).isEntireHeadersAny()}isEntireColumnsAny(){return this._internal.getSheet().getColumnHeaders().getRanges(this.getCoords()).isEntireHeadersAny()}isEntireRows(){return this._internal.getSheet().getRowHeaders().getRanges(this.getCoords()).isEntireHeaders()}isEntireColumns(){return this._internal.getSheet().getColumnHeaders().getRanges(this.getCoords()).isEntireHeaders()}isOverlapping(){let e=this._byScope();if(!e)return mA(this.getCoords());for(let t=0;t<e.length;t++)if(mA(e[t].coords))return!0;return!1}isSingleCell(){let e=this.getCoords();return e.length===1&&n.CoordUtils.isSingleCell(e[0])}isEqual(e,t){let n=this._internal.rangesToCoords(e,void 0,void 0,void 0,!0);return _H(this.getCoords(),n)}at(e){let t=this.getCoords();if(e<0||e>t.length-1)throw new n.OutOfBoundsError;let r=this._cacheRanges,i=r[e];return i||(i=this._createRange(t[e]),r[e]=i),i}isReadOnly(){return this._readOnly!==null}isInvalid(){return!1}getAddress(e){return Sd(this.getCoords(),this._internal.getSheet().getEntireCoords(),void 0,ld)}getSheet(){return this._internal.getSheet()}doBatch(e,t){return this._internal.getSheet().doBatch(t=>e(t),typeof t==`string`?t:{description:(0,n.messageKey)(`op.rangesUpdate`),...t})}get[Symbol.toStringTag](){return`[SheetRanges]`}toString(){return this.getAddress()}get isICellRanges(){return!0}};function DV(){return!1}function OV(){return!0}function kV(){return null}function AV(){return Bt}function jV(){return 0}var MV=new vt(`InvalidRuntime`,null),NV={runtime:MV,sheet:null,styles:null,normalStyleRanged:null,nextContentful:(e,t,n)=>0,getProtection:()=>zV,getRange:e=>VV,getRanges:e=>new HV(null),opener:(e,t,n,r)=>Promise.resolve(!1)},PV=class extends JM{constructor(e=null){super(NV,null),this._invalidSheet=e}getSheet(){return this._invalidSheet}createCell(){return this}getType(){return t.ScalarType.Error}getWarnings(){return[Qu]}getStyle(e=!1){return wV||=new ag().getNormal()}toString(){return`${this._coords?cd(this._coords):Qu} => ${this._v??`{blank}`}`}},FV=new PV,IV=new WeakMap,LV,RV=()=>VV,zV=new a_(void 0,!0),BV=new ni,VV={forEach:function(){},[Symbol.iterator]:AV,entries:AV,values:AV,select:J,find:J,calculate:J,getCell:()=>FV,getFormula:kV,getFormulas:()=>[[``]],getNumberFormat:J,getNumberFormats:J,createFormula:J,getValue:kV,getInteropValue:kV,setValue:J,setFormula:J,setFormulas:J,setNumberFormat:J,setNumberFormats:J,setValues:J,updateCells:J,getCells:()=>[[FV]],getStyle:J,getValues:()=>[[null]],getValuesRange:()=>new iW(MV,BV,null,null),setComputedValues:J,getInteropValues:()=>[[null]],getBounds:kV,getBestFit:kV,getIntersect:RV,getUnion:RV,getDifferences:J,getResizeBy:RV,getResizeTo:RV,getOffsetBy:RV,getOffsetTo:RV,getFixed:RV,getRangeAt:RV,getRowAt:RV,getRowAfter:RV,getRowBefore:RV,getRowBy:RV,getColumnAt:RV,getColumnAfter:RV,getColumnBefore:RV,getColumnBy:RV,getTopLeft:RV,getBottomRight:RV,getUsedRange:RV,getEntireRows:RV,getEntireColumns:RV,getSurrounding:J,getExtended:J,isEntireRows:DV,isEntireColumns:DV,isEntireRange:DV,isSingleCell:OV,isEqual:DV,size:0,sort:J,sortAt:J,filter:J,textToColumns:J,removeDuplicates:J,clear:J,setHyperlink:J,setComments:J,merge:J,unmerge:J,getMerges:J,getUnlocked:J,getConditionalFormats:J,getDataValidations:J,getComments:J,getTables:J,getMovables:J,insert:J,insertFrom:J,canInsertFrom:DV,delete:J,addAutoTable:J,addTable:J,getDefaultShiftAxis:J,getDefaultSortCriteria:J,getDefaultAutoFillCriteria:J,autoFill:J,autoFit:J,getSnapshot:J,copyFrom:J,doBatch:J,createSparseBuilder:J,getRowHeaders:J,getColumnHeaders:J,getCounts:J,getRegions:J,getDirectPrecedents:J,getDirectDependents:J,getPrecedents:J,getDependents:J,getStats:()=>(LV||=new _L(MV,BV,null,[BV.getMaxCoords()]),LV),isContentful:DV,addListener:J,addWatch:J,getColumnStart:jV,getRowStart:jV,getColumnEnd:jV,getRowEnd:jV,getRowCount:jV,getColumnCount:jV,getVisible:J,getCoords:kV,isEmpty:OV,toString:()=>Qu,getAddress:()=>Qu,isInvalid:OV,getSheet:kV,isReadOnly:OV,isICellRange:!0},HV=class extends EV{constructor(e,t){super(null,e,t)}getMerges(){return J()}getStyle(){return J()}find(){return Bt}[Symbol.iterator](){return Bt}entries(){return Bt}calculate(){return J()}clear(){return J()}merge(){return J()}unmerge(){return J()}insert(){return J()}delete(){return J()}insertFrom(){return J()}canInsertFrom(){return!1}getSnapshot(){return J()}copyFrom(){return J()}getEntireRows(){return J()}getEntireColumns(){return J()}getRowHeaders(){return J()}getColumnHeaders(){return J()}getDefaultShiftAxis(){return J()}getFlattened(){return J()}getVisible(){return J()}getAddress(){return J()}getStats(){return LV}getCounts(){return J()}getRegions(){return J()}getDirectPrecedents(){return J()}getDirectDependents(){return J()}getPrecedents(){return J()}getDependents(){return J()}isContentful(){return J()}getRowCount(){return 0}getColumnCount(){return 0}isReadOnly(){return!0}isOverlapping(){return!1}isEntireRows(){return!1}isEntireRowsAny(){return!1}isEntireColumns(){return!1}isEntireColumnsAny(){return!1}isInvalidAny(){return!1}isSingleCell(){return!0}isEqual(){return!1}getFixed(){return J()}at(){return J()}doBatch(){return J()}getCoords(){return null}isInvalid(){return!0}toString(){return Qu}select(){return J()}addListener(){return J()}};function UV(e,n,r,i=!1){let a=r===t.IRange.Axis.Row,o=e.length,s=Array(o);for(let t=0;t<o;t++){let r=e[t];if(a){let e=r.colEnd-r.colStart+1;s[t]={...r,colStart:i?r.colEnd+1:r.colStart,rowStart:n.rowStart,colEnd:i?r.colEnd+e:r.colEnd,rowEnd:n.rowEnd}}else{let e=r.rowEnd-r.rowStart+1;s[t]={...r,colStart:n.colStart,rowStart:i?r.rowEnd+1:r.rowStart,colEnd:n.colEnd,rowEnd:i?r.rowEnd+e:r.rowEnd}}}return s}function WV(e,t,n){let r=t,i=e.length,a=r.rowStart,o=r.rowEnd;for(let t=0;t<i;t++){let r=e[t];if((r.rowStart<=a&&r.rowEnd>=o)!==n)return!n}return n}function GV(e,t,n){let r=t,i=e.length,a=r.colStart,o=r.colEnd;for(let t=0;t<i;t++){let r=e[t];if((r.colStart<=a&&r.colEnd>=o)!==n)return!n}return n}function KV(e){return e._getInternal()}function qV(e,t){if(!t)return e;let n=e.getSheet();if(t===n.getName())return e;let r=n.getWorkbook();if(!r)return null;let i=r.getSheets().getItems({name:t,visibility:Eu.Visibility.VeryHidden})?.[0];return i?KV(i):null}function JV(e,t){if(!e?.scope||!YV(e.scope,t))return e;let n={...e};return delete n.scope,n}function YV(e,t){return e===t.getName()||e===t.getId()}function XV(e,t=null,n=null,r=Qu){if(!e&&!n)return VV;let i=function(e){if(!e)return FV;let t=IV.get(e);return t||(t=new PV(e),IV.set(e,t)),t}(e);return Object.freeze({...VV,getSheet:()=>e,getCell:()=>i,getCells:()=>[[i]],bounds:()=>n,getAddress:()=>r,toString:()=>n?fd(n,t):r})}function ZV(e){return new HV(e)}var QV=/(\d)\*\*([-+]?\d)/g,$V=[` `,`\xA0`,` `,` `],eH=RegExp(`([0-9])[`+$V.join(``)+`](?=[0-9])`,`g`),tH=/[^\s#0.,%E+\-_();[\]]/,nH=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function rH(e){let t=0,n=e.length;for(;t<n&&e.charCodeAt(t)===32;)t++;for(;n>t&&e.charCodeAt(n-1)===32;)n--;return e.slice(t,n)}var iH=`€`,aH=32767;function oH(e,t){let n=rH(e);if(n===``)return null;let r=!1;if(n.includes(`(`)||n.includes(`)`)){if(!n.startsWith(`(`)||!n.endsWith(`)`)||(n=rH(n.slice(1,-1)),n.includes(`(`)||n.includes(`)`)))return null;r=!0}let i=e=>{let r=t.currencyPosition===`after`===e?[iH]:[t.currencySymbol,iH];for(let t of r)if(t&&(e?n.startsWith(t):n.endsWith(t)))return n=rH(e?n.slice(t.length):n.slice(0,n.length-t.length)),!0;return!1},a=!1,o=()=>{(i(!0)||i(!1))&&(a=!0)};o(),(n.startsWith(`+`)||n.startsWith(`-`))&&(r=r!==n.startsWith(`-`),n=rH(n.slice(1)),o());let s=!1;return n.startsWith(`%`)?(n=rH(n.slice(1)),s=!0):n.endsWith(`%`)&&(n=rH(n.slice(0,-1)),s=!0),a&&s?null:{core:n,negative:r,percent:s}}var sH=/^(\d+) (\d{1,5})\/(\d{1,5})$/;function cH(e,n,r,i){let a=function(e,t){let n=e.replace(QV,`$1E$2`);return $V.includes(t.group)&&(n=n.replace(eH,`$1${t.group}`)),n}(rH(n),r);if(function(e,t,n){let r=oH(e,t);if(!r)return!1;let i=sH.exec(r.core);if(!i)return!1;let a=Number(i[2]),o=Number(i[3]);if(o===0||a>aH||o>aH)return!1;let s=Number(i[1])+a/o;r.percent&&(s/=100),r.negative&&(s=-s),n.value=s;let c=r.percent?`0.00%`:o>=10?`# ??/??`:`# ?/?`,l=r.percent?`%`:`/`;return n.style=e=>{if(!e.getNumberFormat().includes(l))return{numberFormat:c}},!0}(a,r,i))return!0;if(!function(e,t){let n=oH(e,t);if(!n)return!1;let r=n.core,i=nH(t.decimal),a=nH(t.group),o=t.group?`\\d+|\\d{1,3}(?:${a}\\d{3})+`:`\\d+`;return RegExp(`^(?:(?:${o})(?:${i}\\d*)?|${i}\\d+)(?:[eE][+-]?\\d+)?$`).test(r)}(a,r))return!1;let o=function(e,t={}){let n=vo(t.locale||``)||bo,r=n.decimal,i=[...Jo[r]||[Ko,qo]];i.includes(n.group)||n.group===Uo||n.group===r||i.push(n.group);let a=``,o=``,s=1,c=``,l=!1,u=!1,d=!1,f=!1,p=!1,m=null,h=!1,g=0,_=[Uo,Wo,Go,`+`,`%`,`(`,`-`].concat(co);for(;_.includes(e[g]);){let t=e[g];if(t===`-`){if(l||u)return null;l=!0,s=-1}else if(lo.test(t)){if(p)return null;p=!0,m=t}else if(t===`(`){if(u||l)return null;u=!0,s=-1}else if(t===`%`){if(f)return null;f=!0}g++}let v,y=!1;if(e[g]===r||Yo(e[g]))for(;g<e.length;){let t=e[g];if(!v&&i.includes(t))v=t;else if(!(v&&v===t))if(t===r){if(y)break;a+=`.`,y=!0}else{if(!Yo(t))break;a+=t}g++}if(e[g]===`e`||e[g]===`E`){o+=e[g],g++,e[g]!==`+`&&e[g]!==`-`||(o+=e[g],g++);let t=g;for(;Yo(e[g]);)o+=e[g],g++;if(t===g)return null}let b=[Uo,Wo,Go,`%`,`$`,`)`].concat(co);for(;b.includes(e[g]);){let t=e[g];if(lo.test(t)){if(p)return null;p=!0,m=t,h=!0}else if(t===`)`){if(d||!u)return null;d=!0}else if(t===`%`){if(f)return null;f=!0}g++}if(g!==e.length)return null;let x=parseFloat(a+o);if(!isFinite(x))return null;if(o){if(f||p)return null;c=`0.00E+00`}else if(f){if(p)return null;c=a.includes(`.`)?`0.00%`:`0%`,x*=.01}else if(p){let e=a.includes(`.`)?`#,##0.00`:`#,##0`;c=h?e+m:m+e}else v&&(c=a.includes(`.`)?`#,##0.00`:`#,##0`);let S={v:x*s};return c&&(S.z=c),S}(t.Scalar.truncateNumberText(a),{locale:r.tag});if(!o||typeof o.v!=`number`)return!1;i.value=o.v;let s=o.z;if(!s)return!0;if(s.includes(`%`))return i.style=e=>{if(!e.getNumberFormat().includes(`%`))return{numberFormat:s}},!0;let c=s.match(tH)?.[0];if(c){let e=s.includes(`.`)?`${c}#,##0.00`:`${c}#,##0`;return i.style=t=>{if(!t.getNumberFormat().includes(c))return{numberFormat:`${e}_);[Red](${e})`}},!0}return i.style={numberFormat:s},!0}function lH(e,t,r,i){if(t===void 0)throw Error(`A value is required to create a cell from a text.`);let a=i??{value:null};if((t=n.CommonUtils.castToString(t))===``)return a;let o=Ti(t);if(o!==void 0)return a.value=o,a;if(t.startsWith(`'`)&&!r?.ignoreQuotePrefix)return a.style={quotePrefix:!0},a.value=t.substring(1,t.length),a;if(a.value=t,cH(0,t,e.getLocaleProfile(),a)||function(e,t,n){if(t.startsWith(` `))return!1;let r=null,i=null;try{i=El(e,t,!0,!0);let n=t;if(i){let e=i.leadingText.trim(),t=i.trailingText.trim();if(e.length>0&&t.length>0)return!1;n=e.length>0?e:t}n.trim().length>0&&(r=Dl(e,n,null,!1,!0)),!r&&i&&(i.leadingText.trim().length>0||i.trailingText.trim().length>0)&&(i=null)}catch{}if(!r&&!i)return!1;n.style=t=>{let n=t.getNumberFormat(),a=Fl(n);if(r&&a)return;let o=Il(n);if(!i||!o){if(r&&i&&!a&&!o?n=`m/d/yyyy h:mm`:r&&!a?n=r.numberFormat:i&&!o&&(n=i.numberFormat),i&&i.parsed.serial>1&&(n=`General`),r&&!a&&!i){let t=wu.Parser.formatValue(e,r.numberFormat,r.asSerialDate),i=e.getLocale();t===new Intl.DateTimeFormat(i).format(r.asJSDate)?n=`Short Date`:t===new Intl.DateTimeFormat(i,{dateStyle:`full`}).format(r.asJSDate)?n=`Long Date`:t===new Intl.DateTimeFormat(i,{timeStyle:`medium`}).format(r.asJSDate)&&(n=`Long Time`)}return{numberFormat:n}}};let a=0;return r&&(a+=r.asSerialDate),i&&(a+=i.parsed.serial),n.value=a,!0}(e,t,a))return a;let s=Ei(t);if(s)return a.value=s,a;a.value=t;let l=ae(t);return l!==null&&(a.hyperlink=l),t.includes(`
|
|
93
|
-
`)&&(a.style={...a?.style,alignment:{overflow:c.Overflow.Wrap}}),a}function uH(e){let t=e._indexedHidden;if(t)return t;let n=[];return e.getUsedRange().forEachSpan((e,t)=>{let r=t.getCoords();e===0&&n.push(r)},{includeStyles:!1}),Tt(Et(n))}var dH=new WeakMap;function fH(e,t,n){let r=uH(e),i=0,a=r.length;for(;i<a;){let e=i+a>>>1;r[e].max<t?i=e+1:a=e}if(i===r.length||r[i].min>n)return null;let o=dH.get(r);return o||(o=Lt(r),dH.set(r,o)),o}function pH(e,t){return e?(n,r)=>{for(;;){let i=t(e(n,r),r);if(i===n)return i;n=i}}:t}function mH(e){if(!e)return null;let t=null,n=e.length;for(let r=0;r<n;r++){let n=e[r].value;if(!n)continue;t||={};let i=Object.keys(n),a=i.length;for(let e=0;e<a;e++){let r=i[e],a=t[r];if(a)if(Array.isArray(a)){let e=n[r];if(Array.isArray(e)){let t=e.length;for(let n=0;n<t;n++)a.push(e[n])}else a.push(e)}else t[r]=[a,n[r]];else t[r]=n[r]}}return t}function hH(e,n,r,i=!1,a=!1){let o,s=r?.includeMergeOverflow??!1;if(i)o=!0;else if(a||s){let e={};a&&(e[W.Type.DateFormat]=!1,e[W.Type.Table]=!1),s&&(e[W.Type.Merge]=!1),o=e}let c=r?.axis??t.IRange.Axis.Row,l=r?.maxSize??1e4,u=e({includeEmpty:!0,axis:c,reverse:r?.reverse,ignoreHidden:r?.ignoreHidden,includeMergeOverflow:s,searchTypes:o,bounds:n,reuseContext:!0}),d=c!==t.IRange.Axis.Row,f=[],p,m=-1,h=null,g=0;for(p=u.next();!p.done;){if(g>l)throw Error(jj(l));let e=p.value,t=e.context.getCoords(),n=d?t.colIndex:t.rowIndex;n!==m&&(h=[],f.push(h),m=n);let r=e.value;if(i)r=e.context.getCell();else if(a&&r!==null){let t=e.context.getInteropValue();t&&(r=t)}h.push(r),p=u.next(),g++}return f}function gH(e,t){return e===t||!(!e||!t)&&e.rowStart===t.rowStart&&e.rowEnd===t.rowEnd&&e.colStart===t.colStart&&e.colEnd===t.colEnd&&e.$rowStart===t.$rowStart&&e.$rowEnd===t.$rowEnd&&e.$colStart===t.$colStart&&e.$colEnd===t.$colEnd&&e.scope===t.scope}function _H(e,t){if(e===t)return!0;if(!e||!t)return!1;let n=e.length;if(n!==t.length)return!1;for(let r=0;r<n;r++)if(!gH(e[r],t[r]))return!1;return!0}function vH(e,t){if(!e)return;let n={...e};return t?typeof t==`boolean`?(n.$colStart=t,n.$rowStart=t,n.$colEnd=t,n.$rowEnd=t,n):(typeof t.colStart==`boolean`&&(n.$colStart=t.colStart),typeof t.rowStart==`boolean`&&(n.$rowStart=t.rowStart),typeof t.colEnd==`boolean`&&(n.$colEnd=t.colEnd),typeof t.rowEnd==`boolean`&&(n.$rowEnd=t.rowEnd),n):n}var yH=class{constructor(e,r,i){this._c=null;let a=this;this.setState=e=>{let n=e[0],i=e[1],a=e[2];if(r&&r.includeMergeOverflow&&a&&a.merge){let e=r.bounds,t=a.merge.getCoords(),o=!1,s=t.colStart,c=t.rowStart,l=e.colStart,u=e.rowStart,d=n.colIndex,f=n.rowIndex;!o&&s<l&&c>=u&&d===l&&f===c&&(o=!0),!o&&c<u&&s>=l&&f===u&&d===s&&(o=!0),!o&&c<u&&s<l&&f===u&&d===l&&(o=!0),o&&(i=a.merge.tvTl())}a&&Object.keys(a).length===0&&(a=null);let o=i;return i===void 0?(this._t=t.ScalarType.Null,this._v=null,o=null):(this._t=IH(o),this._v=o),this._r=a,this._p=e[3],this._n=e[4],this._c=n,o},this.clear=()=>{a._c=null},this.context={getCoords(){let e=a._c;if(!e)throw Error((0,n.t)(`error.sheet.iteratorClosed`));return e},getCell(){let e=a._c;if(!e)throw Error((0,n.t)(`error.sheet.iteratorClosed`));let t=a._r,o=!0!==r?.searchTypes||t?.merge||r?.injectReferences?null:i.renderCellCache,s;if(o){s=32768*e.rowIndex+e.colIndex;let t=o.get(s);if(t)return t}let c=a._t,l=a._v,u=new JM(i,o?{rowIndex:e.rowIndex,colIndex:e.colIndex}:e,c,l,t,a._p,a._n);return o&&o.set(s,u),u},getType:()=>a._t,getInteropType(){let e=a._t;return e===t.ScalarType.Number&&a._r?.dateFormat?t.InteropScalarType.Date:e},getInteropValue(){let e=a._t,n=a._v;return e===t.ScalarType.Number&&a._r?.dateFormat?KH(i.runtime,n,a._t,t.InteropScalarType.Date,!1):n},getAddress(e,t=!1){if(!a.context)throw Error((0,n.t)(`error.sheet.iteratorClosed`));let r=a._c;return e&&(r={...a._c,...e}),i.getRange(r).getAddress(t)},getInjectedReference(e){let t=a._r;if(!t)return;let n=t[e];return n===void 0?void 0:n}}}};function bH(e,r){let i=t.IRange.Direction.Down,a=0,o={...e};if(r.colStart<e.colStart?(i=t.IRange.Direction.Left,a=e.colStart-r.colStart,o.colStart=r.colStart):r.colEnd>e.colEnd?(i=t.IRange.Direction.Right,a=r.colEnd-e.colEnd,o.colEnd=r.colEnd):r.rowStart<e.rowStart?(i=t.IRange.Direction.Up,a=e.rowStart-r.rowStart,o.rowStart=r.rowStart):r.rowEnd>e.rowEnd||r.rowEnd<e.rowEnd?(i=t.IRange.Direction.Down,a=r.rowEnd-e.rowEnd,o.rowEnd=r.rowEnd):r.colEnd<e.colEnd?(i=t.IRange.Direction.Right,a=r.colEnd-e.colEnd,o.colEnd=r.colEnd):r.rowStart>e.rowStart?(i=t.IRange.Direction.Up,a=e.rowStart-r.rowStart,o.rowStart=r.rowStart):r.colStart>e.colStart&&(i=t.IRange.Direction.Left,a=e.colStart-r.colStart,o.colStart=r.colStart),!wr(o,r))throw new n.ExpectedError(((e,t)=>(0,n.t)(`error.sheet.autofillInvalidDestination`,{template:e,destination:t}))(fd(e),fd(r)));return{direction:i,amount:a}}function xH(e,t){if(e||t)return e&&t?{...e,...t}:e||t}function SH(e,t,r){if(!e||e.length===0||!t)return n.CommonUtils.EmptyArray;let i=[...e],a=i.length,o=r.colStart,s=r.rowStart,c=r.colEnd,l=r.rowEnd;for(let e=0;e<a;e++){let n={...i[e]},r=n,a=t.search(n),u=n.rowStart<=s&&n.rowEnd>=l,d=n.colStart<=o&&n.colStart>=c,f=a.length;for(let e=0;e<f;e++){let t=a[e];u||(r.colStart=Math.min(r.colStart,t.colStart),r.colEnd=Math.max(r.colEnd,t.colEnd)),d||(r.rowStart=Math.min(r.rowStart,t.rowStart),r.rowEnd=Math.max(r.rowEnd,t.rowEnd))}i[e]=r}return i}function CH(e,n,r){if(!e||e.length===0)return null;let i=e.length,a,o=-1,s=[],c=n===t.IRange.Axis.Column,l=c?r.rowStart:r.colStart,u=c?r.rowEnd:r.colEnd,d=c?t.IRange.AxisSelection.Column:t.IRange.AxisSelection.Row;for(let t=0;t<i;t++){let n=Xd(e[t],c),r=n?.value.s;if(!n||r===void 0){o=-1;continue}let i=n.min,f=n.max;r!==o||a.colEnd+1!==i?(a={colStart:c?i:l,rowStart:c?l:i,colEnd:c?f:u,rowEnd:c?u:f,value:{axes:d,index:r}},o=r,s.push(a)):a.colEnd=f}return s.length===0?null:s}function wH(e,t,r,i,a){let o=e,s=r?t.colStart:t.rowStart,c=r?a.colEnd:a.rowEnd,l=r?e.colIndex:e.rowIndex;if(i>0&&l>s||i<0&&s<=l){o={...e};let t=Math.max(l+i,s);if(o[r?`colIndex`:`rowIndex`]=t,l>c)throw new n.ExpectedError((0,n.t)(`error.sheet.insertOobFreeze`))}return o}function TH(e,n=t.IRange.AxisSelection.Both){let r=n===t.IRange.AxisSelection.Both,i=r?2**53-1:1,a=kr(e,i,n===t.IRange.AxisSelection.Row?t.IRange.Axis.Column:t.IRange.Axis.Row);if(r){let n=kr(e,i,t.IRange.Axis.Column);n.length<a.length&&(a=n)}return a}function EH(e){return(t,n,r=!1)=>{let i=null,a=Mg(n,()=>i||(i=Yg(void 0,e,t,t.getCoords()),i)),o=t.cloneWithUpdate(a,r);return o.isEmpty()&&!o.getUpdateProperties()?null:o}}function DH(e,t,n,r,i){let a=e._p?.borders;if(!a)return;let o,s,c={onIntersect:(e,t)=>{if(!e)return e;let n=e.value?._p?.borders;if(!n)return e;let i;return o===V.Edge.Left?n.left&&e.colStart===s&&(i={borders:{left:null}}):o===V.Edge.Top?n.top&&e.rowStart===s&&(i={borders:{top:null}}):o===V.Edge.Right?n.right&&e.colEnd===s&&(i={borders:{right:null}}):o===V.Edge.Bottom&&n.bottom&&e.rowEnd===s&&(i={borders:{bottom:null}}),i?{...t,value:r(e.value,i)}:e}};a.right&&t.colEnd<i.colEnd&&(o=V.Edge.Left,s=t.colEnd+1,n.insertNonOverlapping({colStart:s,rowStart:t.rowStart,colEnd:s,rowEnd:t.rowEnd,value:void 0},c)),a.bottom&&t.rowEnd<i.rowEnd&&(o=V.Edge.Top,s=t.rowEnd+1,n.insertNonOverlapping({colStart:t.colStart,rowStart:s,colEnd:t.colEnd,rowEnd:s,value:void 0},c)),a.left&&t.colStart>i.colStart&&(o=V.Edge.Right,s=t.colStart-1,n.insertNonOverlapping({colStart:s,rowStart:t.rowStart,colEnd:s,rowEnd:t.rowEnd,value:void 0},c)),a.top&&t.rowStart>i.rowStart&&(o=V.Edge.Bottom,s=t.rowStart-1,n.insertNonOverlapping({colStart:t.colStart,rowStart:s,colEnd:t.colEnd,rowEnd:s,value:void 0},c))}function OH(e,t,n,r,i){let a=(e,t)=>({...t,value:null}),o={...i,value:null};t.insertNonOverlapping(o,{onIntersect:a}),n.insertNonOverlapping(o,{onIntersect:a}),r.insertNonOverlapping(o,{onIntersect:a});let s=e.search(i);for(let e=0;e<s.length;e++){let i=s[e],a=i.value;if(!a)continue;let o=a.splitByFeature();o.border&&t.insertNonOverlapping({...i,value:o.border}),o.fill&&n.insertNonOverlapping({...i,value:o.fill}),o.content&&r.insertNonOverlapping({...i,value:o.content})}}function kH(e,t){let n=!1;for(let r of e)if(t&&r===t)n=!n;else if(!n){if(r===`,`)return`,`;if(r===` `)return` `}}function AH(e,t,n,r){let i=[],a=``,o=!1,s=t.length;for(let r=0;r<e.length;r++){let c=e[r];n&&c===n?o=!o:o||e.slice(r,r+s)!==t?a+=c:(i.push(a),a=``,r+=s-1)}i.push(a);let c=r?i.map(e=>e.length>0?e:null):i.filter(e=>e.length>0);return c.length>0?c:[null]}function jH(e,t,n){let r=typeof t;if(r===`number`)return``+e+``+t.toString();if(r===`string`){let r=t,i=n.get(r);return i===void 0&&(i=r.toLowerCase(),n.set(r,i)),``+e+``+i}return r===`boolean`?``+e+``+(t?`1`:`0`):t==null?``+e+`\0`:``+e+``+t.getCode()}var MH=Object.freeze({colStart:0,rowStart:0,colEnd:2**14-1,rowEnd:2**20-1});function NH(){return MH}var PH=Object.freeze({colStart:0,rowStart:0,colEnd:2**31-2,rowEnd:2**31-2});function FH(){return PH}var IH=(e,r=!1)=>typeof e==`number`?isNaN(e)||e===1/0||e===-1/0?t.ScalarType.Error:t.ScalarType.Number:typeof e==`string`?t.ScalarType.String:typeof e==`boolean`?t.ScalarType.Boolean:e?.isFormulaError?t.ScalarType.Error:e===null?t.ScalarType.Null:n.CommonUtils.isObject(e)&&e.hasOwnProperty(`getType`)&&typeof e.getType()==`string`?t.ScalarType.RichData:r&&Xc(e,!0)?t.InteropScalarType.Date:e===void 0?(console.warn(`undefined`),t.ScalarType.Null):null,LH=new Map([[t.ScalarType.Null,`any`],[t.ScalarType.Number,`number`],[t.ScalarType.String,`string`],[t.ScalarType.Boolean,`boolean`],[t.ScalarType.Error,`FormulaError`],[t.ScalarType.RichData,`richData`],[t.InteropScalarType.Date,`Date`],[`*`,`Scalar`]]),RH=new Map([[`p`,`IReferenceRange`],[`r`,`IRange`],[`m`,`[][]`],[`*`,`any`]]);function zH(e){let t=e.scalar,n=e.range,r=t?LH.get(t)??`InvalidScalar`:``,i=n?RH.get(n)??`InvalidRange`:``,a;return a=t&&n?n===`m`?`${r}${i}`:`${i}<${r}>`:r||i,a+=`[]`.repeat(e.arrayDepth??0),a}var BH={axis:t.IRange.Axis.Row},VH=22250738585072014e-324,HH=/^ *[^\S ]|[^\S ] *$/;function UH(e,t){if(e===0)return`0`;if(!Number.isFinite(e))return e.toString();let n=e<0,[r,i]=Math.abs(e).toExponential(14).split(`e`),a=r.replace(`.`,``),o=a.length;for(;o>1&&a.charCodeAt(o-1)===48;)o--;a=a.slice(0,o);let s=parseInt(i,10),c=t.getLocaleProfile().decimal,l=null;if(s>=0){let e=s+1;a.length>e?l=a.slice(0,e)+c+a.slice(e):e<=20&&(l=a.padEnd(e,`0`))}else{let e=-s-1;2+e+a.length<=20&&(l=`0`+c+`0`.repeat(e)+a)}if(l===null){let e=a.length>1?a[0]+c+a.slice(1):a,t=Math.abs(s);l=e+(s<0?`E-`:`E+`)+(t<10?`0`+t:String(t))}return n?`-`+l:l}function WH(e,n){let r=n.trim();if(r===``)return t.FormulaError.BuiltIn.Value;let i=Number(t.Scalar.truncateNumberText(r));return Number.isFinite(i)?dl(i,e.isDate1904())??t.FormulaError.BuiltIn.Value:t.FormulaError.BuiltIn.Value}function GH(e,n,r){if(!r)switch(n){case t.InteropScalarType.Number:return null;case t.InteropScalarType.String:r=aU;break;case t.InteropScalarType.Boolean:r=oU;break;case t.InteropScalarType.Date:r=sU;break;case t.InteropScalarType.Null:r=cU;break;case t.InteropScalarType.Error:case t.InteropScalarType.RichData:default:return null}let i=!1,a=!1,o=!1,s=!1,c=r.length;for(let e=0;e<c;e++)switch(r[e]){case t.ScalarType.Number:i=!0;break;case t.ScalarType.String:a=!0;break;case t.ScalarType.Boolean:o=!0;break;case t.ScalarType.RichData:break;case t.ScalarType.Null:s=!0}return n===t.ScalarType.Number?(n,r)=>{if(r===t.ScalarType.Error)return n;switch(r){case t.ScalarType.Null:return s?0:null;case t.ScalarType.String:if(!a)return null;let r=n;if(r.length>255||HH.test(r))return t.FormulaError.BuiltIn.Value;let i=Number(t.Scalar.truncateNumberText(r));if(i===0&&r.trim()===``)return t.FormulaError.BuiltIn.Value;if(isNaN(i)){let t=lH(e,r);t&&(i=t.value)}return!Number.isFinite(i)||Math.abs(i)>999999999999999e293?t.FormulaError.BuiltIn.Value:i;case t.ScalarType.Boolean:return o?+!!n:null}return null}:n===t.ScalarType.String?(n,r)=>{if(r===t.ScalarType.Error)return n;switch(r){case t.ScalarType.Number:return i?UH(n,e):null;case t.ScalarType.Boolean:return o?Ci(n):null;case t.ScalarType.Null:return s?``:null}return null}:n===t.InteropScalarType.Boolean?(e,n)=>{if(n===t.ScalarType.Error)return e;switch(n){case t.ScalarType.Number:return i?eU(e)!==0:null;case t.ScalarType.String:if(!a)return null;let n=e;return n===`TRUE`||n!==`FALSE`&&(n=n.toUpperCase(),n===`TRUE`||n!==`FALSE`&&null);case t.ScalarType.Null:return!s&&null}return null}:n===t.InteropScalarType.Date?(n,r)=>{if(r===t.ScalarType.Error)return n;switch(r){case t.ScalarType.Number:return i?dl(n,e.isDate1904())??t.FormulaError.BuiltIn.Value:null;case t.ScalarType.String:if(!a)return null;let r=Ll(e,n);return r===null?WH(e,n):dl(r,e.isDate1904());case t.ScalarType.Null:return s?dl(0,e.isDate1904()):null}return null}:n===t.ScalarType.Null?(e,n)=>{if(n===t.ScalarType.Error)return e;switch(n){case t.ScalarType.Number:return i?0:null;case t.ScalarType.String:return a?``:null;case t.ScalarType.Boolean:return!o&&null}return null}:n===t.InteropScalarType.RichData?(e,t)=>null:null}function KH(e,n,r,i=t.ScalarType.Number,a=!1){if(r===i||!i)return r===t.ScalarType.Number&&(n=tU(n,null,`number`)),n;if(VC(n)&&i!==`l`&&i!==`*`||(0,t.isLazyValue)(n))return t.FormulaError.BuiltIn.Value;if(i===t.ScalarType.Number){switch(r){case t.ScalarType.Null:return 0;case t.ScalarType.String:if(n.length>255)return t.FormulaError.BuiltIn.Value;let r=0;try{let t=lH(e,n);r=t&&typeof t.value==`number`?t.value:NaN}catch{}return!Number.isFinite(r)||Math.abs(r)>999999999999999e293?t.FormulaError.BuiltIn.Value:r;case t.ScalarType.Boolean:return a?+!!n:t.FormulaError.BuiltIn.Value;case t.InteropScalarType.Date:return fl(n,e.isDate1904())??t.FormulaError.BuiltIn.Value;case t.ScalarType.Error:return n}return n.toString()}if(i===t.ScalarType.String){switch(r){case t.ScalarType.Null:return``;case t.ScalarType.Number:return UH(n,e);case t.ScalarType.Boolean:return Ci(n);case t.ScalarType.Error:return n}return n}if(i===t.InteropScalarType.Boolean){switch(r){case t.ScalarType.Null:return!1;case t.ScalarType.Number:return eU(n)!==0;case t.ScalarType.String:let e=n.toUpperCase();return e===`TRUE`||e!==`FALSE`&&t.FormulaError.BuiltIn.Value;case t.ScalarType.Error:return n}return t.FormulaError.BuiltIn.Value}if(i===t.InteropScalarType.Date){switch(r){case t.ScalarType.Null:return dl(0,e.isDate1904());case t.ScalarType.Number:return dl(n,e.isDate1904())??t.FormulaError.BuiltIn.Value;case t.ScalarType.String:let r=Ll(e,n);return r===null?WH(e,n):dl(r,e.isDate1904());case t.ScalarType.Error:return n}return t.FormulaError.BuiltIn.Value}return i===t.InteropScalarType.RichData?null:t.FormulaError.BuiltIn.Value}var qH=(e,n,r=null)=>{let i=Array.isArray(n),a=e.next();for(;!a.done;){let o=a.value;if(r===`reject`&&t.FormulaError.isError(o)||o instanceof t.FormulaError.Value)return o;i?n.push(o):n.values[n.length++]=o,a=e.next()}};function JH(e){if(!Array.isArray(e))return!1;let t=e[0];return!(!t||typeof t!=`object`)&&(!!t.isIRange||t.colStart!==void 0)}function YH(e,n,r,i=!1,a,o,s=null,c=!1){let l=r;if(l===null)return;if(l.colStart!==void 0){let t=e.getReference?.(l);o&&!c&&(t=t.toType(o)),l=t}if(l.isIRange&&c&&o){let r=e.getRuntime(),i=Array.isArray(n);if(!0===l.isIReferenceRange&&l.size===1&&l.getValueAt(0,0)==null)return;for(let e of l.values({includeEmpty:!0,onError:`value`,...BH})){if(t.FormulaError.isError(e)){if(s===`reject`)return e;i?n.push(e):n.values[n.length++]=e;continue}let a=KH(r,e??null,IH(e??null,!0),o,!1);if(t.FormulaError.isError(a))return a;i?n.push(a):n.values[n.length++]=a}return}if(l.isIRange){let e=l,r=s===`reject`?`throw`:`value`;try{return qH(e.values({type:o,onError:r,...BH}),n,s)}catch(e){if(t.FormulaError.isError(e))return e;throw e}}let u=Array.isArray(n);if(Array.isArray(l)){let r=l.length;for(let d=0;d<r;d++){let r=l[d];if(r!==null||c)if(Array.isArray(r)){let t=YH(e,n,r,i,a,o,s,c);if(t)return t}else{if(s===`reject`&&t.FormulaError.isError(r))return r;if(o&&(r=KH(e.getRuntime(),r,IH(r,!0),o,!c&&i),r instanceof t.FormulaError.Value)){if(i&&o===t.ScalarType.Boolean)continue;return r}u?n.push(r):n.values[n.length++]=l}}return}return s===`reject`&&t.FormulaError.isError(l)||o&&(l=KH(e.getRuntime(),l,IH(l,!0),o,i),l instanceof t.FormulaError.Value)?l:void(u?n.push(l):n.values[n.length++]=l)}function XH(e,n,r,i,a,o=null){if(r===`p`){let e=n;if(!e||!e.isIReferenceRange){if(t.FormulaError.isError(n))return n;let e=n;if(e?.isIRange&&e.size===1){let n=e.getValueAt(0,0);if(t.FormulaError.isError(n))return n}return t.FormulaError.BuiltIn.Value}return i&&(e=o===`accept`?e.toType({type:i,onError:`value`}):e.toType(i)),e}let s;try{n?.isIReferenceRange?(s=n,i&&(s=o===`accept`?s.toType({type:i,onError:`value`}):s.toType(i))):o===`accept`?(s=t.FormulaError.isError(n)?e.getRange(n,void 0,!1):e.getRange(n,void 0,a),i&&(s=s.toType({type:i,onError:`value`}))):(s=e.getRange(n,i??void 0,a),i&&s===n&&(s=s.toType({type:i,onError:`throw`})))}catch(e){if(HT(e))throw e;return e}return r===`r`?s:s.getValues()}function ZH(e,n,r,i,a,o,s,c,l=null,u=!1){let d=r;if(d&&d.colStart!==void 0)if(a)d=e.getReference?.(d);else{let t=d.colStart,n=d.rowStart,r=d.colEnd;d=d.rowEnd!==n||t!==r?e.getReference?.(d):e.getValueAt(n,t,d.scope)}if(i&&typeof r==`string`&&o===t.ScalarType.Boolean)if(r===`TRUE`||r===`FALSE`)d=r===`TRUE`;else{let e=r.toUpperCase();e!==`TRUE`&&e!==`FALSE`||(d=e===`TRUE`)}d?.isIRange&&d._isDirectScalarBox?.()&&(d=d.getValueAt(0,0));let f=d?function(e){let t=e,n=0;for(;Array.isArray(t);)n++,t=t[0];return t&&(t.isIRange||t.colStart!==void 0)&&(n+=2),n}(d):0;if(f===0&&t.FormulaError.isError(d)){if(l===`reject`)return d;if(l===`accept`){if(a)return void(Array.isArray(n)?n.push(d):n.values[n.length++]=d);o=null}}if(!u||!c||f!==0||d!==null){if(f===0&&o){let n=IH(d,!0);if(n!==o){let r=!i&&c;if(d=KH(e.getRuntime(),d,n,o,!u&&!r),i&&c&&o===t.ScalarType.Boolean&&t.FormulaError.isError(d))return}if(!s&&t.FormulaError.isError(d))return d}if(c){if(f===3){let t=d;for(let r=0;r<t.length;r++){let d=ZH(e,n,t[r],i,a,o,s,c,l,u);if(d)return d}return}if(!a)return YH(e,n,d,i,a,o,l,u);if(d=XH(e,d,a,o,i,l),t.FormulaError.isError(d))return d}else{if(JH(d))return t.FormulaError.BuiltIn.Value;if(a){if(d=XH(e,d,a,o,i,l),t.FormulaError.isError(d))return d}else if(f>0){if(d=function(e,n=!1){let r=e;for(;Array.isArray(r);){if(r.length>1)return n?t.FormulaError.BuiltIn.Value:r;r=r[0]}if(r?.isIRange){if(n&&r.size!==1)return t.FormulaError.BuiltIn.Value;r=r.getValueAt(0,0)}return r}(d,!0),l===`reject`&&t.FormulaError.isError(d))return d;if(o&&!t.FormulaError.isError(d)){let n=IH(d,!0);if(n!==o&&(d=KH(e.getRuntime(),d,n,o,i)),!s&&t.FormulaError.isError(d))return d}}}if(!s&&t.FormulaError.isError(d))return d;Array.isArray(n)?n.push(d):n.values[n.length++]=d}}function QH(e,n,r,i,a,o,s){let c=r;if(i&&a===t.ScalarType.Boolean&&typeof r==`string`)if(r===`TRUE`||r===`FALSE`)c=r===`TRUE`;else{let e=r.toUpperCase();e!==`TRUE`&&e!==`FALSE`||(c=e===`TRUE`)}if(t.FormulaError.isError(c)){if(s===`reject`)return c;s===`accept`&&(a=null)}if(a){let t=IH(c,!0);t!==a&&(c=KH(e.getRuntime(),c,t,a,!0))}if(!o&&t.FormulaError.isError(c))return c;n.values[n.length++]=c}function $H(e){return e!=e||e===1/0||e===-1/0?t.FormulaError.BuiltIn.Num:e}function eU(e){return e>-22250738585072014e-324&&e<VH?0:e}function tU(e,n,r=typeof e){if(r===`number`)return $H(e);if(r===`string`)return e.length>t.Scalar.MAX_TEXT_LENGTH?t.FormulaError.BuiltIn.Value:e;if(e==null)return null;if(!n)return e;if(Array.isArray(e)){if(JH(e))return e;try{e=n.getRange(e)}catch{return t.FormulaError.BuiltIn.Value}}return e}function nU(e,n,r){let i;i=Array.isArray(e)?Array.isArray(e[0])?e:[e]:[[e]],n||=new ni({axis:t.IRange.Axis.Column});let a=n.getAxis()===t.IRange.Axis.Column,o=r?.colStart??0,s=r?.rowStart??0,c=Yr(i,a,Rr(o,s,void 0,void 0,a),!0);if(!c){let e=0;for(let t=0;t<i.length;t++)e=Math.max(e,i[t]?.length??0);return{values:n,coords:{rowStart:s,colStart:o,rowEnd:s+i.length-1,colEnd:o+e-1},isLiteral:!r}}let l=zr(c.bounds,a);return n.setValues(c.tuples),{values:n,coords:l,isLiteral:!r}}function rU(e,t=null){if(e<48){let n=[];for(let r=0;r<e;r++)n.push(t);return n}return Array(e).fill(t)}function iU(e){if(e<48){let t=[];for(let n=0;n<e;n++)t.push(void 0);return t}return Array(e).fill(void 0)}var aU=Object.freeze([t.ScalarType.Number,t.ScalarType.Boolean,t.ScalarType.Null]),oU=Object.freeze([t.ScalarType.Number,t.ScalarType.Null]),sU=Object.freeze([t.ScalarType.Number,t.ScalarType.String,t.ScalarType.Null]),cU=Object.freeze([t.ScalarType.Number,t.ScalarType.String,t.ScalarType.Boolean]),lU=Object.freeze([t.ScalarType.Number,t.ScalarType.String,t.ScalarType.Boolean,t.ScalarType.Null,t.ScalarType.RichData]);function uU(e,t,n){let r=e?.processRowSkip,i=e?.processColumnSkip;if(!r&&!i)return null;let a=r?{skip:r,origin:n?.rowIndex??0}:null,o=i?{skip:i,origin:n?.colIndex??0}:null;return t?{major:o,minor:a}:{major:a,minor:o}}var dU=(e,t)=>{let n=t-e.origin;return e.skip(n)!==n},fU=(e,t,n)=>e.skip(t-e.origin,n)+e.origin,pU=(e,t,n)=>{if(!e)return n-t+1;let r=0;for(let i=t;i<=n;i++){let t=fU(e,i);t===i?r++:t>i&&(i=t-1)}return r};function mU(e,t,n){let r=uU(e,!0,n);return r?pU(r.minor,t.rowStart,t.rowEnd)*pU(r.major,t.colStart,t.colEnd):(t.colEnd-t.colStart+1)*(t.rowEnd-t.rowStart+1)}var hU=(e,t)=>{let n=e.bySkip.get(t.skip);n||(n=new Map,e.bySkip.set(t.skip,n));let r=n.get(t.origin);return r||(r=new WeakMap,n.set(t.origin,r)),r},gU=new WeakMap,_U=(e,t)=>{let n=gU.get(e);return n||(n=t??{coerce:void 0,byRun:new WeakMap,bySkip:new WeakMap},gU.set(e,n)),n},vU=2**13,yU=Object.freeze({count:0,numericalCount:0,sum:null,min:null,max:null,average:null,var:null,varP:null,stdDev:null,stdDevP:null});function bU(e,n,r,i,a,o,s,c){if(n.getCount()===0)return null;let l=null,u=n.getAxis()===t.IRange.Axis.Column,d=i.length,f=uU(a,u,c),p=f?.major??null,m=f?.minor??null,h=a?{...CU,...a}:CU,g=h.bounds,_=a?.coerce;o.coerce!==_&&(o.byRun=new WeakMap,o.bySkip=new WeakMap,o.coerce=_);let v=m?hU(o,m):o.byRun,y=xU(e,a),b=y.coerce,x=y.defaultCoerce,S=a?.onError??`ignore`,C=!1,w=null;if(S!==`ignore`)if(S===`throw`)C=!0;else{if(S===`value`)throw Error(`onError "value" is not supported in RangeStats`);typeof S==`function`&&(w=S)}for(let e=0;e<d;e++){let a=i[e];if(!a)continue;let o=u?a.colStart:a.rowStart,c=u?a.rowStart:a.colStart,d=u?a.colEnd:a.rowEnd,f=u?a.rowEnd:a.colEnd;g.colStart=u?o:c,g.rowStart=u?c:o,g.colEnd=u?d:f,g.rowEnd=u?f:d;let _=n.getRuns(h),y,S,T=0,E=0,D=0,O=0,k=0,A=0,j=0,M=0,N=0,P=0,F=!1,I=_.next();for(I.done||l||(l=TU());!I.done;){let[e,n,i]=I.value;if(I=_.next(),!(p&&dU(p,e)||(T=i.length,E=Math.max(0,c-n),D=Math.min(T-1,f-n),E>D))){S=v.get(i),S||(O=Math.ceil(T/s),S=Array(O),v.set(i,S)),k=Math.floor(E/s),A=Math.floor(D/s);for(let e=k;e<=A;e++){if(j=e*s,M=Math.min((e+1)*s-1,T-1),N=Math.max(E,j),P=Math.min(D,M),N>P)continue;F=N===j&&P===M;let a=S[e];if(F){if(a){if((C||w)&&(a.typed[t.ScalarType.Error]>0||b!==null&&a.count!==a.typed[t.ScalarType.Number]))for(let e=j;e<=M;e++){if(m){let t=fU(m,n+e)-n;if(t!==e){t>e&&(e=t-1);continue}}y=i.at(e);let a=IH(y,!0);if(a!==t.ScalarType.Number&&(b&&(y=b(y,a,x,r)),t.FormulaError.isError(y))){if(C)throw y;w(y)}}}else{let o=TU();Ht.forEachLeaf(i,(e,i,a,s)=>{let c=i+s-a;if(b===null&&m===null){let t=e.getViews?.();if(t)return void FU(o,e,t,i,c,C,w)}let l;for(let s=i;s<=c;s++){if(m){let e=fU(m,n+a+(s-i))-n-a+i;if(e!==s){e>s&&(s=e-1);continue}}o.count++,l=e.at(s);let c=IH(l,!0);if(VC(l)&&(l=t.FormulaError.BuiltIn.Value,c=t.ScalarType.Error),o.typed[EU(c)]++,c!==t.ScalarType.Number){let e=!0;if(b&&(l=b(l,c,x,r),c=IH(l,!0),e=c!==t.ScalarType.Number),t.FormulaError.isError(l)){if(C)throw l;w&&w(l)}if(e)continue}DU(o,l)}},j,M),a=o,S[e]=a}IU(l,a)}else for(let e=N;e<=P;e++){if(m){let t=fU(m,n+e)-n;if(t!==e){t>e&&(e=t-1);continue}}l.count++,y=i.at(e);let a=IH(y,!0);if(l.typed[EU(a)]++,a!==t.ScalarType.Number){let e=!0;if(b&&(y=b(y,a,null,r),a=IH(y,!0),e=a!==t.ScalarType.Number),t.FormulaError.isError(y)){if(C)throw y;w&&w(y)}if(e)continue}DU(l,y)}}}}}return l}function xU(e,n){let r=n?.coerce;if(r){if(typeof r==`function`)return{coerce:r,defaultCoerce:GH(e,t.ScalarType.Number,lU)};if(Array.isArray(r))return{coerce:GH(e,t.ScalarType.Number,r),defaultCoerce:null}}return{coerce:null,defaultCoerce:null}}function SU(e){if(!e||e.count===0)return yU;let t=e.numericalCount;if(!t||e.min===void 0)return Object.freeze({...yU,count:e.count});let n=e.sum/t,r=Math.max(0,e.sumSq/t-n*n),i=t>1?r*(t/(t-1)):null,a={count:e.count,numericalCount:t,sum:e.sum,min:e.min,max:e.max,average:n,varP:r,stdDevP:Math.sqrt(r),var:i,stdDev:i===null?null:Math.sqrt(i)};return a.populationVariance=r,Object.freeze(a)}var CU={bounds:{colStart:0,rowStart:0,colEnd:0,rowEnd:0},overflowRun:!0},wU={bounds:{colStart:0,rowStart:0,colEnd:0,rowEnd:0},overflowRun:!0},TU=()=>({count:0,min:void 0,max:void 0,numericalCount:0,sum:0,sumSq:0,typed:{[t.ScalarType.Number]:0,[t.ScalarType.String]:0,[t.ScalarType.Boolean]:0,[t.ScalarType.Error]:0,[t.ScalarType.RichData]:0,[t.ScalarType.Null]:0}}),EU=e=>{switch(e){case t.ScalarType.Number:case t.ScalarType.String:case t.ScalarType.Boolean:case t.ScalarType.Error:case t.ScalarType.RichData:case t.ScalarType.Null:return e;case t.InteropScalarType.Date:return t.ScalarType.Number;default:return t.ScalarType.Null}},DU=(e,t)=>{e.sum+=t,e.numericalCount++,e.sumSq+=t*t,e.min===void 0?(e.min=t,e.max=t):(t<e.min&&(e.min=t),t>e.max&&(e.max=t))},OU=_i.Type.Blank,kU=_i.Type.False,AU=_i.Type.True,jU=_i.Type.Int32,MU=_i.Type.Float64,NU=_i.Type.String,PU=_i.Type.Error,FU=(e,n,r,i,a,o,s)=>{let c=r.types,l=e.typed;if(c===null&&(r.defaultType===jU||r.defaultType===MU)){let n=r.ints,o=r.doubles,s=r.intShift,c=r.intOffset,u=r.defaultType===jU,d=e.sum,f=e.sumSq,p=e.min,m=e.max,h=0,g=0;for(let e=i;e<=a;e++){let t=u?n[(e<<s)+c]:o[e];t-t===0?(d+=t,f+=t*t,h++,p===void 0?(p=t,m=t):(t<p&&(p=t),t>m&&(m=t))):g++}e.count+=a-i+1,e.sum=d,e.sumSq=f,e.min=p,e.max=m,e.numericalCount+=h,l[t.ScalarType.Number]+=h,l[t.ScalarType.Error]+=g;return}let u=r.defaultType,d=r.ints,f=r.doubles,p=r.intShift,m=r.intOffset;for(let r=i;r<=a;r++)switch(e.count++,c===null?u:c[r]){case jU:l[t.ScalarType.Number]++,DU(e,d[(r<<p)+m]);break;case MU:{let n=f[r];n-n===0?(l[t.ScalarType.Number]++,DU(e,n)):l[t.ScalarType.Error]++;break}case OU:l[t.ScalarType.Null]++;break;case kU:case AU:l[t.ScalarType.Boolean]++;break;case NU:l[t.ScalarType.String]++;break;case PU:if(l[t.ScalarType.Error]++,o)throw n.at(r);s&&s(n.at(r))}},IU=(e,n)=>{e.sum+=n.sum,e.numericalCount+=n.numericalCount,e.count+=n.count,e.sumSq+=n.sumSq;let r=e.typed,i=n.typed;r[t.ScalarType.Number]+=i[t.ScalarType.Number],r[t.ScalarType.String]+=i[t.ScalarType.String],r[t.ScalarType.Boolean]+=i[t.ScalarType.Boolean],r[t.ScalarType.Error]+=i[t.ScalarType.Error],r[t.ScalarType.RichData]+=i[t.ScalarType.RichData],r[t.ScalarType.Null]+=i[t.ScalarType.Null],n.min!==void 0&&(e.min===void 0?(e.min=n.min,e.max=n.max):(n.min<e.min&&(e.min=n.min),n.max>e.max&&(e.max=n.max)))},LU=0x4000000000000,RU=e=>{let t=e.min;return t==null?0:Math.max(Math.abs(t),Math.abs(e.max))},zU=(e,t)=>e!==0&&e!==1/0&&e!==-1/0&&Math.abs(e)*LU<=t+Math.abs(e),BU=(e,t)=>t===void 0?e:Math.abs(e)*LU<=Math.abs(e-t)?0:e,VU=class{constructor(e,t,n){this._kept=[],this._limit=e,this._distinct=t,this._rank=n}offer(e){let t=this._kept,n=this._rank;if(this._distinct){let r=t.length;for(let i=0;i<r;i++)if(n(t[i],e)===0)return}let r=t.length;r<this._limit?t.splice(HU(t,e,n),0,e):n(e,t[r-1])<0&&(t.pop(),t.splice(HU(t,e,n),0,e))}values(){return this._kept}};function HU(e,t,n){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;n(e[a],t)<=0?r=a+1:i=a}return r}function UU(e,t){let n=e?.compareFn??t;return e?.reverse?n:(e,t)=>n(t,e)}function WU(e,n,r,i,a,o){let s=i?.limit??10;if(!(s>0)||e.getCount()===0)return KU;let c=i?.includeBlanks??!1,l=i?.filterFn,u=UU(i,a),d=new VU(s,i?.distinct??!1,u),f=e.getAxis()===t.IRange.Axis.Column,p=n.length,m=uU(r,f,o),h=m?.major??null,g=m?.minor??null,_=r?{...qU,...r}:qU,v=_.bounds,y=0,b=0;for(let t=0;t<p;t++){let i=n[t];if(!i)continue;c&&(y+=mU(r,i,o));let a=f?i.colStart:i.rowStart,s=f?i.rowStart:i.colStart,u=f?i.colEnd:i.rowEnd,p=f?i.rowEnd:i.colEnd;v.colStart=f?a:s,v.rowStart=f?s:a,v.colEnd=f?u:p,v.rowEnd=f?p:u;let m=e.getRuns(_),x=m.next();for(;!x.done;){let[e,t,n]=x.value;if(x=m.next(),h&&dU(h,e))continue;let r=n.length,i=Math.max(0,s-t),a=Math.min(r-1,p-t);if(!(i>a))for(let e=i;e<=a;e++){if(g){let n=fU(g,t+e)-t;if(n!==e){n>e&&(e=n-1);continue}}b++;let r=n.at(e);l&&!l(r)||d.offer(r)}}}if(c){let e=y-b,t=Math.min(e,s);for(let e=0;e<t;e++)d.offer(null)}return d.values()}function GU(e,t,n){let r=t?.limit??10;if(!(r>0))return KU;let i=UU(t,n),a=new VU(r,t?.distinct??!1,i),o=e.length;for(let n=0;n<o;n++){let r=e[n].getRanked(t),i=r.next();for(;!i.done;)a.offer(i.value),i=r.next()}return a.values()}var KU=Object.freeze([]),qU={bounds:{colStart:0,rowStart:0,colEnd:0,rowEnd:0},overflowRun:!0},JU=class e{constructor(e){this._sorted=e}static fromGrid(t,n,r,i){return new e(e._collectNumbers(t,n,r,i))}getLarge(e){return this._inRank(e)?this._sorted[Math.trunc(this._sorted.length-e)]:null}getSmall(e){return this._inRank(e)?this._sorted[Math.trunc(e-1)]:null}_inRank(e){return e>=1&&e<=this._sorted.length}getPercentile(e,t=!1){let n=this._sorted,r=n.length;if(r===0)return null;if(t){if(e<=0||e>=1)return null;let t=e*(r+1)-1;return t<0||t>r-1?null:YU(n,t)}return e<0||e>1?null:YU(n,e*(r-1))}getRankOf(e,t=!0,n=!1){let r=this._sorted,i=r.length;if(i===0)return null;let a=XU(r,e);if(a>=i||r[a]!==e)return null;let o=ZU(r,e)-1;return n?((t?i-o:a+1)+(t?i-a:o+1))/2:t?i-o:a+1}getPercentRankOf(e,n=!1,r){let i=this._sorted,a=i.length;if(a===0)return null;let o=XU(i,e),s;if(o<a&&i[o]===e){if(a===1)return 1;s=n?(o+1)/(a+1):o/(a-1)}else{if(o===0||o>=a)return null;let t=i[o-1],r=(e-t)/(i[o]-t);s=n?(o+r)/(a+1):(o-1+r)/(a-1)}if(r===void 0)return s;if(!(r>=1))return t.FormulaError.BuiltIn.Num;let c=10**Math.trunc(r);return Number.isFinite(c)?Math.floor(s*c)/c:t.FormulaError.BuiltIn.Div0}getValues(){return this._sorted}findFloor(e){let t=this._sorted;if(t.length===0)return null;let n=ZU(t,e)-1;return n<0?null:t[n]}findCeiling(e){let t=this._sorted;if(t.length===0)return null;let n=XU(t,e);return n>=t.length?null:t[n]}static _collectNumbers(e,n,r,i){if(e.getCount()===0)return QU;let a=[],o=e.getAxis()===t.IRange.Axis.Column,s=n.length,c=uU(r,o,i),l=c?.major??null,u=c?.minor??null,d=r?{...$U,...r}:$U,f=d.bounds;for(let t=0;t<s;t++){let r=n[t];if(!r)continue;let i=o?r.colStart:r.rowStart,s=o?r.rowStart:r.colStart,c=o?r.colEnd:r.rowEnd,p=o?r.rowEnd:r.colEnd;f.colStart=o?i:s,f.rowStart=o?s:i,f.colEnd=o?c:p,f.rowEnd=o?p:c;let m=e.getRuns(d),h=m.next();for(;!h.done;){let[e,t,n]=h.value;if(h=m.next(),l&&dU(l,e))continue;let r=n.length,i=Math.max(0,s-t),o=Math.min(r-1,p-t);if(!(i>o))for(let e=i;e<=o;e++){if(u){let n=fU(u,t+e)-t;if(n!==e){n>e&&(e=n-1);continue}}let r=n.at(e);typeof r==`number`&&a.push(r)}}}return a.sort((e,t)=>e-t),Object.freeze(a)}};function YU(e,t){let n=Math.floor(t),r=t-n;return r===0?e[n]:e[n]+r*(e[n+1]-e[n])}function XU(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i]<t?n=i+1:r=i}return n}function ZU(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i]<=t?n=i+1:r=i}return n}var QU=Object.freeze([]),$U={bounds:{colStart:0,rowStart:0,colEnd:0,rowEnd:0},overflowRun:!0},eW=new WeakMap;function tW(e){switch(typeof e){case`number`:case`boolean`:return e;case`string`:return ia(e);default:return}}var nW=(e,t,n,r,i)=>{if(e.length<16){if(i){for(let i=r;i>=n;i--)if(tW(e.at(i))===t)return i}else for(let i=n;i<=r;i++)if(tW(e.at(i))===t)return i;return-1}let a=(e=>{let t=eW.get(e);if(t!==void 0)return t;t=new Map;let n=e.length;for(let r=0;r<n;r++){let n=tW(e.at(r));if(n===void 0)continue;let i=t.get(n);i===void 0?t.set(n,r):typeof i==`number`?t.set(n,[i,r]):i.push(r)}return eW.set(e,t),t})(e).get(t);if(a===void 0)return-1;if(typeof a==`number`)return a>=n&&a<=r?a:-1;let o=0,s=a.length-1;if(i){for(;o<s;){let e=o+s+1>>1;a[e]<=r?o=e:s=e-1}return a[o]<=r&&a[o]>=n?a[o]:-1}for(;o<s;){let e=o+s>>1;a[e]>=n?s=e:o=e+1}return a[o]>=n&&a[o]<=r?a[o]:-1},rW={bounds:void 0,overflowRun:!0},iW=class e{constructor(e,t,n,r=null,i=!1,a=!1,o=null){this._isLiteral=!1,this._isDirectScalar=!1,this._localRangeStats=null,this._localRangeStatsOptions=void 0,this._absentValue=null,this._runtime=e,r&&(r={...fW,...r}).axis===`fastest`&&(r.axis=t.getAxis()),this._values=t,this._coords=n,this._optionsIterator=r??fW,this._isLiteral=i,this._isDirectScalar=a,this._absentValue=o??null}argsort(e=this,n=1,r=t.IRange.Axis.Row){let i=r===t.IRange.Axis.Column,a=Array.isArray(e)?e:[e],o=Array.isArray(n)?n:[n];return function(e,t,n,r){let i=Array.from({length:e},(e,t)=>t),a=t.length;if(a===1){let e=t[0],a=n[0]??1;return i.sort((t,n)=>TW(e[t],e[n],a,r)),i}return i.sort((e,i)=>{for(let o=0;o<a;o++){let a=n[o]??1,s=t[o],c=TW(s[e],s[i],a,r);if(c!==0)return c}return 0}),i}(i?this.getColumnCount():this.getRowCount(),a.map(e=>function(e,t,n){let r=n?e.getColumnCount():e.getRowCount(),i=Array(r).fill(null),a=e.entries(),o=a.next();for(;!o.done;){let{value:e,coords:r}=o.value;(n?r.rowIndex:r.colIndex)===t&&(i[n?r.colIndex:r.rowIndex]=e),o=a.next()}return i}(e,0,i)),o,this._runtime.getLocaleProfile())}uniqueIndices(e=t.IRange.Axis.Row,n=!1){let r=e===t.IRange.Axis.Column,i=r?this.getColumnCount():this.getRowCount(),a=Array(i).fill(``),o=new Map,s=this.entries({axis:e,includeEmpty:!1}),c=s.next();for(;!c.done;){let{value:e,coords:t}=c.value,n=r?t.colIndex:t.rowIndex,i=r?t.rowIndex:t.colIndex;a[n]+=DW(i,e,o),c=s.next()}return function(e,t){let n=new Map;for(let t of e)n.set(t,(n.get(t)??0)+1);let r=new Set,i=[];for(let a=0;a<e.length;a++){let o=e[a];r.has(o)||(r.add(o),t&&n.get(o)!==1||i.push(a))}return i}(a,n)}broadcast(e,r,i){if(e===void 0)return this._self();i=i?{...this._optionsIterator,...i}:this._optionsIterator;let a=i?.type,o=i?.otherType??a,s=a?this._coerceValue(null,a,i,t.ScalarType.Null):null,c=o?this._coerceValue(null,o,i,t.ScalarType.Null):null,l=this._values,u=l.getAxis()===t.IRange.Axis.Column,d=this._coords??n.CoordUtils.EmptyRange,f=e?.isIRange?e:null,p=f?f._coords??n.CoordUtils.EmptyRange:n.CoordUtils.EmptyRange,m=d.colEnd-d.colStart+1,h=d.rowEnd-d.rowStart+1,g=p.colEnd-p.colStart+1,_=p.rowEnd-p.rowStart+1,v=Math.min(m,g),y=Math.min(h,_),b=Math.max(m,g),x=Math.max(h,_),S=i?.misalignValue??null,C=S!==null&&(b>v||x>y);if(m!==g){if(m===1)v=g;else if(g===1)v=m;else if(S===null)throw Error(`Incompatible shapes for broadcast: cols ${m} and ${g} must be equal or one must be 1`)}if(h!==_){if(h===1)y=_;else if(_===1)y=h;else if(S===null)throw Error(`Incompatible shapes for broadcast: rows ${h} and ${_} must be equal or one must be 1`)}let w=d.colStart,T=d.rowStart,E=u?v:y,D=u?y:v,O=r.length===2,k=(e,t,n,r,i)=>{let a=n.colEnd-n.colStart+1,o=n.rowEnd-n.rowStart+1;if(!t._coords||a===1&&o===1)return null;let s={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colStart+Math.min(a,v)-1,rowEnd:n.rowStart+Math.min(o,y)-1},c=a===1?v:Math.min(a,v),l=o===1?y:Math.min(o,y);return new gW(e,t._values,s,u,u?c:l,u?l:c,r,r(void 0)??i,i,i,t._skipsOnGrid(t._optionsIterator))},A=this._memberReader(i,!1),j=k(0,this,d,A,s),M=s;j===null&&(M=(this._coords?A(l.getValueAt(d.rowStart,d.colStart)):A(void 0))??s);let N=null,P=c;if(f!==null){let e=f._memberReader({...i,type:o??null},!1);N=k(1,f,p,e,c),N===null&&(P=(f._coords?e(f._values.getValueAt(p.rowStart,p.colStart)):e(void 0))??c)}else P=(o?this._coerceValue(e,o,i):e)??c;let F=[];j&&F.push(j),N&&F.push(N);let I=u?w:T,L=u?T:w,R=new z.Builder(void 0,0,0,!0),ee=(e,t)=>({colIndex:u?e:t,rowIndex:u?t:e}),te=O?`region`:j===null||N===null||this._absentValue!==null||f._absentValue!==null?`each`:`skip`,ne,re,ie,ae=(e,t)=>{re=j===null?M:j.covers?j.valueAt(t):j.empty,ie=N===null?P:N.covers?N.valueAt(t):N.empty};_W(F,E,D,(e,t,i)=>{if(te!==`skip`)if(re=j===null?M:j.empty,ie=N===null?P:N.empty,te!==`each`)R.pushAbsentAt(I+e,L+t,i-t),ne===void 0&&(ne=r(re,ie,n.CoordUtils.EmptyCell,this)??null,R.setAbsentValue(ne));else for(let n=t;n<i;n++)R.pushAt(I+e,L+n,r(re,ie,ee(e,n),this))},(e,t,i,a)=>{if(a&&O){ae(0,t);let a=r(re,ie,n.CoordUtils.EmptyCell,this);R.pushMultipleAt(I+e,L+t,new ln([a],i-t+1));return}for(let n=t;n<=i;n++)ae(0,n),R.pushAt(I+e,L+n,r(re,ie,ee(e,n),this))});let oe=R.build(),se=oe.absentValue??null,ce;if(C){let e=l.clone();if(this._applyRegion(e,oe,!1),b>v){let t=Jr(S,Rr(w+v,T,w+b-1,T+x-1,u),u);e.setValues(t.tuples)}if(x>y){let t=Jr(S,Rr(w,T+y,w+b-1,T+x-1,u),u);e.setValues(t.tuples)}ce=this._newRange(e,{colStart:w,rowStart:T,colEnd:w+b-1,rowEnd:T+x-1},this._optionsIterator,!1,!1,se)}else{let e=l.cloneEmpty();this._applyRegion(e,oe,!0),ce=this._newRange(e,{colStart:w,rowStart:T,colEnd:w+v-1,rowEnd:T+y-1},this._optionsIterator,!1,!1,se)}return ce._untyped()}choose(e,r,i){let a=i?.misalignValue??t.FormulaError.BuiltIn.NA;if(this.isEmpty())return this.replace([[a]]);let o=e.map(e=>e.isIRange?e:this.fill(e)),s=o.length,c=this.getColumnCount(),l=this.getRowCount();if(c===1&&l===1){let e=r(this.getValueAt(0,0),n.CoordUtils.EmptyCell,this);return t.FormulaError.isError(e)?this.replace([[e]]):typeof e!=`number`||e<0||e>=s?this.replace([[a]]):o[e]}let u=c,d=l,f=u===1||d===1;for(let e=0;e<s;e++){let t=o[e],n=t.getColumnCount(),r=t.getRowCount();f=f||n===1||r===1,u=Math.max(u,n),d=Math.max(d,r)}let p=this;return f&&u>1&&d>1&&(c===1||l===1)&&(p=p.tile(l===1?d:1,c===1?u:1)),p=p.map((e,n)=>{let i=n.colIndex,c=n.rowIndex,l=r(e,n,this);if(t.FormulaError.isError(l))return l;if(typeof l!=`number`||l<0||l>=s)return a;let u=o[l];f&&(u.getColumnCount()===1&&(i=0),u.getRowCount()===1&&(c=0));let d=u.getValueAt(c,i);return d===void 0?a:d}),p=p.resize(d,u,a),p}clear(){let e=this._coords,t=this._values;return!e||t.getCount()===0&&this._absentValue===null?this._self():(t=t.cloneEmpty(),this._newRange(t,this._coords,this._optionsIterator))}clone(e,t=!1,n=!1){return this._newRange(this._values,this._coords,e?{...this._optionsIterator,...e}:this._optionsIterator,t,n,this._absentValue)}compute(e){return e(this)}concat(e,n=t.IRange.Axis.Row,r=t.FormulaError.BuiltIn.NA){let i=n===t.IRange.Axis.Column,a=this.getColumnCount(),o=this.getRowCount(),s=e.getColumnCount(),c=e.getRowCount(),l=i?a+s:Math.max(a,s),u=i?Math.max(o,c):o+c;if(r!==null){let t=i?o<u?this.resize(u,a,r):this:a<l?this.resize(o,l,r):this,d=i?c<u?e.resize(u,s,r):e:s<l?e.resize(c,l,r):e;return t.concat(d,n,null)}let d=this.resize(u,l,null).sparseBuilder(t.IRange.Axis.Column),f=i?0:o,p=i?a:0,m=e.entries({axis:t.IRange.Axis.Column,includeEmpty:!1}),h=m.next();for(;!h.done;){let{value:e,coords:t}=h.value;d.pushAt(t.rowIndex+f,t.colIndex+p,e),h=m.next()}return d.build()}empty(){let e=this._coords,t=this._values;return!e||t.getCount()===0&&this._absentValue===null?this._self():(t=t.cloneEmpty(),this._newRange(t,null,this._optionsIterator))}entries(e){let t=this._coords;if(!t)return Bt;let n=e?.bounds;if(e={...this._optionsIterator,...e,bounds:t},n){let r=(n.colStart??0)-t.colStart,i=(n.rowStart??0)-t.rowStart,a=Math.max(r+t.colStart,t.colStart),o=Math.max(i+t.rowStart,t.rowStart),s=Math.min((n.colEnd??2**53-1)-r,t.colEnd-t.colStart)+1,c=Math.min((n.rowEnd??2**53-1)-i,t.rowEnd-t.rowStart)+1;e.bounds={colStart:a,rowStart:o,colEnd:a+s-1,rowEnd:o+c-1}}let r=this._entries(e),i={[Symbol.iterator]:()=>i,next(){for(;;){let e=r.next();if(e.done)return zt;let n=e.value,i=n[0];return{done:!1,value:{coords:{colIndex:i.colIndex-t.colStart,rowIndex:i.rowIndex-t.rowStart},value:n[1]??null}}}}};return i}errors(e){let n=this.entries({axis:e?.axis??t.IRange.Axis.Row,bounds:e?.bounds,reverse:e?.reverse,type:null}),r={[Symbol.iterator]:()=>r,next(){let e=n.next();for(;!e.done;){let r=e.value.value;if(t.FormulaError.isError(r))return e;if(VC(r))return{done:!1,value:{coords:e.value.coords,value:t.FormulaError.BuiltIn.Value}};e=n.next()}return zt}};return r}every(e,t){if(!e)return!0;let n=this.entries(t),r=n.next();for(;!r.done;){let t=r.value;if(!e(t.value,t.coords,this))return!1;r=n.next()}return!0}fill(e,t){let n=this._coords;if(!n)return this._self();if(t){if(this._absentValue!==null)return this._materializeEmpty().fill(e,t);if(n=this._absoluteCoords(t),!n)return this._self()}let r=this._values.clone();return vW(r,n,e),this._newRange(r,n,this._optionsIterator)}fillEmpty(e,t){let n=this._coords;return n?this._absentValue!==null||e===null?this:t?(n=this._absoluteCoords(t),n?this._fillAbsent(e,n):this._self()):n.rowStart===n.rowEnd&&n.colStart===n.colEnd&&this._values.getValueAt(n.rowStart,n.colStart)!=null?this:this._newRange(this._values,n,this._optionsIterator,this._isLiteral,!1,e):this._self()}_fillAbsent(e,n){let r=this._values,i=r.getAxis(),a=i,o=a===t.IRange.Axis.Column,s=o?n.colStart:n.rowStart,c=o?n.rowStart:n.colStart,l=o?n.colEnd:n.rowEnd,u=o?n.rowEnd:n.colEnd,d=r.getRuns({bounds:n,overflowRun:!0}),f=d.next(),p=s,m=c,h=a===i?new z.Builder:new z.TransposedBuilder;for(;!f.done;){let t=f.value,n=t[0];for(;p<n;){let t=new ln([e],u+1-m);h.pushMultipleAt(p,m,t),p++,m=c}let r=t[1],i=Math.max(r,c),a=t[2],o=Math.min(r+a.length-1,u);if(m<i){let t=new ln([e],r-m);h.pushMultipleAt(p,m,t)}m=o+1,o>=u?(p=n+1,m=c):p=n,f=d.next()}for(;p<=l;){let t=new ln([e],u+1-m);h.pushMultipleAt(p,m,t),p++,m=c}return this._cloneFromBuilder(h,null,!1,null)}_materializeEmpty(){let e=this._absentValue,t=this._coords;return e!==null&&t?this._fillAbsent(e,t):this}filter(e,n){let r=this._coords,i=this._values;if(!r||i.getCount()===0&&this._absentValue===null)return this._self();let a=n?.axis===`fastest`?i.getAxis():n?.axis??this._optionsIterator.axis,o=this.empty()._createBuilder(a),s=a===t.IRange.Axis.Column,c=-1,l=-1,u=!1,d=0,f=this.entries(n),p=f.next();for(;!p.done;){let n=p.value,r=n.coords,i=s?r.colIndex:r.rowIndex,a=s?r.rowIndex:r.colIndex,m=n.value;d++;let h=e(m,r,this);h?(i!==c&&(c=i,l++),t.FormulaError.isError(h)&&(m=h),o.pushAt(l,a,m)):u=!0,p=f.next()}return u||d!==this.size?this.empty()._cloneFromBuilder(o):this._self()}firstError(){let e=this.errors().next();return e.done?null:e.value.value}flatten(e){if(e&&(e.processRowSkip||e.processColumnSkip)){let{processRowSkip:t,processColumnSkip:n,...r}=e;return this.clone({processRowSkip:t,processColumnSkip:n}).flatten(r)}let n=(e?.axis===t.IRange.Axis.Column?this.transpose():this).reshape(this.getRowCount()*this.getColumnCount(),1);return e&&(e.type!==void 0||e.coerce||e.onError||e.errorOnInvalidCoercion)?n.toType(e):n}getValuesFlat(e){let t=[],n=this.values(e),r=n.next();for(;!r.done;)t.push(r.value),r=n.next();return t}indexOf(e,n){let r=this._coords;if(!r)return-1;let i=!0===n?.reverse,a=this._values,o=a.getAxis()===t.IRange.Axis.Column;return(o?r.colStart!==r.colEnd:r.rowStart!==r.rowEnd)||this._absentValue!==null||this._optionsIterator.type||this._hasSkips()||!0===a.observesReads||tW(e)===void 0?this._indexOfScan(e,i):function(e,t,n,r,i){let a=tW(r);if(a===void 0)return-1;let o=n?t.rowStart:t.colStart,s=n?t.rowEnd:t.colEnd;rW.bounds=t;let c=e.getRuns(rW);if(!i){let e=c.next();for(;!e.done;){let t=e.value[1],n=e.value[2],r=Math.max(o-t,0),i=Math.min(s-t,n.length-1);if(r<=i){let e=nW(n,a,r,i,!1);if(e!==-1)return t+e-o}e=c.next()}return-1}let l=[],u=[],d=c.next();for(;!d.done;)l.push(d.value[1]),u.push(d.value[2]),d=c.next();for(let e=u.length-1;e>=0;e--){let t=l[e],n=u[e],r=Math.max(o-t,0),i=Math.min(s-t,n.length-1);if(r>i)continue;let c=nW(n,a,r,i,!0);if(c!==-1)return t+c-o}return-1}(a,r,o,e,i)}_indexOfScan(e,n){let r=this._coords,i=r.colEnd-r.colStart+1,a=this._runtime.getLocaleProfile(),o=this.entries({axis:t.IRange.Axis.Row,includeEmpty:!1,reverse:n}),s=o.next();for(;!s.done;){let t=s.value,n=t.value;if(n!=null&&EW(n,e,a))return t.coords.rowIndex*i+t.coords.colIndex;s=o.next()}return-1}forEach(e,t){if(!e)return;let n=this.entries(t),r=n.next();for(;!r.done;){let t=r.value,i=e(t.value,t.coords,this);if(i)return i.break;r=n.next()}}getColumnCount(){let e=this._coords;return e?e.colEnd-e.colStart+1:0}getRowCount(){let e=this._coords;return e?e.rowEnd-e.rowStart+1:0}getShape(){let e=this._coords;return{rows:e.rowEnd-e.rowStart+1,columns:e.colEnd-e.colStart+1}}getStats(e){let t=this._optionsIterator;if(t!==void 0&&t.type!==void 0&&e?.onError===void 0&&(t.onError===void 0||t.onError===`throw`)&&this.hasError())throw this.firstError();return this._getStats(e)}_getStats(e){let t=this._localRangeStats;if(!t||e!==this._localRangeStatsOptions){let n=this._coords,r=this._optionsIterator,i=e;(r.processRowSkip||r.processColumnSkip)&&(i={processRowSkip:r.processRowSkip,processColumnSkip:r.processColumnSkip,...e});let a=n&&i&&(i.processRowSkip||i.processColumnSkip)?{rowIndex:n.rowStart,colIndex:n.colStart}:void 0;t=new _L(this._runtime,this._materializeEmpty()._values,this,[n],i,void 0,void 0,a),this._localRangeStats=t,this._localRangeStatsOptions=e}return t}hasError(){if(this.size===1){let e=this._coords,n=oW(this._optionsIterator,0,0)?void 0:this._values.getValueAt(e.rowStart,e.colStart),r=n===void 0?this._absentValue:n;return t.FormulaError.isError(r)||VC(r)}return this.size<=xW?!this.errors({axis:`fastest`}).next().done:(this._getStats().getTypedCounts(SW)[t.ScalarType.Error]??0)>0}getType(){return this._optionsIterator?.type??void 0}getValueAt(e,t,n){let r=this._coords;if(!r||e<0||t<0||e>=r.rowEnd-r.rowStart+1||t>=this.getColumnCount())return;let i=this._values;n=n?{...this._optionsIterator,...n}:this._optionsIterator;let a=oW(n,e,t)?void 0:i.getValueAt(e+r.rowStart,t+r.colStart),o=a===void 0?this._absentValue:a,s=n?.type;return s&&(o=this._coerceValue(o,s,n)),o}getValues(e){if(!this._coords)return[[]];let n={...e,includeEmpty:!0,reverse:!1,onError:`value`,bounds:{colStart:0,rowStart:0,colEnd:this.getColumnCount()-1,rowEnd:this.getRowCount()-1}},r=!1;n.axis=e?.axis??t.IRange.Axis.Row,e&&(e.maxRows&&(n.bounds.rowEnd=0+e.maxRows-1),e.maxCols&&(n.bounds.colEnd=0+e.maxCols-1),e.trailingEmpties&&(r=e.trailingEmpties),n.axis=e?.axis??t.IRange.Axis.Row);let i=[];if(!r){n.includeEmpty=!1,n.reverse=!0,n.axis=t.IRange.Axis.Row;let r=this.entries(n).next();if(r.done)return dW;n.axis=t.IRange.Axis.Column;let i=this.entries(n).next();n.bounds.rowEnd=r.value.coords.rowIndex,n.bounds.colEnd=i.value.coords.colIndex,n.includeEmpty=!0,n.reverse=!1,n.axis=e?.axis??t.IRange.Axis.Row}let a=this.entries(n),o=n.axis!==t.IRange.Axis.Row,s=e?.onValue,c,l=-1,u=[];for(c=a.next();!c.done;){let e=c.value,t=e.coords,n=o?t.colIndex:t.rowIndex;n!==l&&(u=[],i.push(u),l=n);let r=e.value;if(s){let e=s(r,t.rowIndex,t.colIndex,this);e!==void 0&&(r=e)}u.push(r),c=a.next()}return i}map(e,n){let r=this._coords,i=this._values;if(!r)return this._self()._untyped();if(n&&(n.processRowSkip||n.processColumnSkip)){let{processRowSkip:t,processColumnSkip:r,...i}=n;return this.clone({processRowSkip:t,processColumnSkip:r}).map(e,i)}let a=n?.blankRegions===`once`;if((a||e.length<=1)&&!n?.includeEmpty&&(a||this._absentValue===null)&&this.size>1)return this._mapRuns(e,n,a);let o=n?.axis===`fastest`?i.getAxis():n?.axis??this._optionsIterator.axis,s=this.entries(n),c,l=s.next();l.done||(c=this._createBuilder(o));let u=o===t.IRange.Axis.Column,d=u?r.colStart:r.rowStart,f=u?r.rowStart:r.colStart,p;for(;!l.done;){let t=l.value,n=t.coords,r=u?n.colIndex:n.rowIndex,i=u?n.rowIndex:n.colIndex,a=t.value;l=s.next();let o=e(a,n,this);o===void 0?o=a:o===null?(p||=ei(u),p.append(r+d,i+f)):c.pushAt(r,i,o)}let m=(n?.includeEmpty??!1)||this._absentValue!==null;return this._cloneFromBuilder(c,p,!1,m?null:this._absentValue)._untyped()}_mapRuns(e,n,r){let i=this._coords,a=this._values,o=a.getAxis()===t.IRange.Axis.Column,s=this._memberReader(n?{...this._optionsIterator,...n}:this._optionsIterator,!1),c=i.colEnd-i.colStart+1,l=i.rowEnd-i.rowStart+1,u=o?c:l,d=o?l:c,f=o?i.colStart:i.rowStart,p=o?i.rowStart:i.colStart,m=new gW(0,a,i,o,u,d,s,null,null,null,this._skipsOnGrid(n?{...this._optionsIterator,...n}:this._optionsIterator)),h=new z.Builder(void 0,0,0,!0),g,_=(e,t)=>({colIndex:o?e:t,rowIndex:o?t:e});_W([m],u,d,(t,n,i)=>{if(!r)return;h.pushAbsentAt(f+t,p+n,i-n);let a=s(void 0);if(a!==void 0&&g===void 0){let t=e(a,hW,this);g=t===void 0?this._absentValue:t,h.setAbsentValue(g)}},(t,n,r,i)=>{let a=m.seg;if(i){let i=a.value;if(i===void 0)return;let o=e(i,hW,this);if(o===void 0)return;h.pushMultipleAt(f+t,p+n,new ln([o],r-n+1));return}let o=a.list,c=a.base;for(let i=n;i<=r;i++){let n=s(o.at(i+c));if(n===void 0)continue;let r=e(n,_(t,i),this);r!==void 0&&h.pushAt(f+t,p+i,r)}}),g===void 0&&h.setAbsentValue(this._absentValue);let v=h.build(),y=v.absentValue??null;return v.tuples.length===0&&v.clears.length===0?(y===this._absentValue?this._self():this._newRange(a,i,this._optionsIterator,this._isLiteral,!1,y))._untyped():this._cloneFromRegion(v,null,!1,y)._untyped()}mask(e,n,r){let i=r?.misalignValue??t.FormulaError.BuiltIn.NA,a=r?.emptyValue??null,o=r?.isTrue,s=GH(this._runtime,t.ScalarType.Boolean),c=e?.isIRange?e:this._newRange(this._values,null),l=n?.isIRange?n:this._newRange(this._values,null);if(c.size===1){let e=c.getValueAt(0,0),n=IH(e),i=n===t.ScalarType.Boolean?e:s(e,n);return t.FormulaError.isError(i)?this.empty().replace([[i]]):(!0===i?l:this).fillEmpty(r?.emptyValue??null)}let u=c.getColumnCount(),d=c.getRowCount(),f=l.getColumnCount(),p=this.getColumnCount(),m=Math.max(f,p,u),h=l.getRowCount(),g=this.getRowCount(),_=Math.max(h,g,d);c=c.repeat(d===1?_:1,u===1?m:1);let v=c.getColumnCount(),y=c.getRowCount(),b=this;b=b.repeat(g===1?y:1,p===1?v:1),b=b.fillEmpty(a);let x=h===1,S=f===1,C=b.sparseBuilder(bW),w=Math.max(g===1?y:g,x?y:h),T=Math.max(p===1?v:p,S?v:f);c=c.resize(w,T,i),c.forEach((e,n)=>{let r;if(o)r=o(e,n);else if(!0===e)r=!0;else if(!1===e)r=!1;else{let n=IH(e);r=n===t.ScalarType.Boolean?e:s(e,n)}let c=n.rowIndex,u=n.colIndex,d=null;!1!==r&&(!0===r?d=!S&&u>=f||!x&&c>=h?i:l.getValueAt(x?0:c,S?0:u)??a:t.FormulaError.isError(r)&&(d=r),C.pushAt(c,u,d))},CW);let E=C.build();return E=E.resize(_,m,i),E}alignValues(e,r){let i=r?{...this._optionsIterator,...r}:this._optionsIterator,a=this._values.getAxis(),o=i.axis,s=o&&o!==`fastest`?o:a,c=s===t.IRange.Axis.Column,l=e=>{let t=e.iterator.next();if(t.done)return void(e.done=!0);let n=t.value;e.value=n[1]??null,e.rowRel=n[0].rowIndex-e.rowBase,e.colRel=n[0].colIndex-e.colBase},u=[],d=(e,t,r)=>{let i=t._coords??n.CoordUtils.EmptyRange,a={slot:e,iterator:t._entries({...r,axis:s,bounds:i,reuseResult:!1}),done:!1,value:null,rowRel:0,colRel:0,rowBase:i.rowStart,colBase:i.colStart};l(a),u.push(a)};d(0,this,i);let f=[],p=e.length;for(let t=0;t<p;t++){let n=e[t];if(n===null){f.push(t+1);continue}d(t+1,n,n._optionsIterator)}let m=p+1,h=u.length,g=f.length,_=c?this.getRowCount():this.getColumnCount();return{[Symbol.iterator](){return this},next:()=>{let e=0,t=0,n=!1;for(let r=0;r<h;r++){let i=u[r];i.done||(n?(c?i.colRel-t||i.rowRel-e:i.rowRel-e||i.colRel-t)<0&&(e=i.rowRel,t=i.colRel):(e=i.rowRel,t=i.colRel,n=!0))}if(!n)return zt;let r=Array(m).fill(null);for(let n=0;n<h;n++){let i=u[n];i.done||i.rowRel!==e||i.colRel!==t||(r[i.slot]=i.value,l(i))}if(g>0){let n=c?t*_+e+1:e*_+t+1;for(let e=0;e<g;e++)r[f[e]]=n}return{done:!1,value:[r,{rowIndex:e,colIndex:t}]}}}}alignReduce(e,t,n,r){if(!t)return n;let i=Array.isArray(e)?e:[e],a=this.alignValues(i,r),o=n,s=a.next(),c=r?.emptyFold;if(!c){for(;!s.done;){let[e,n]=s.value;o=t(o,e,n,this),s=a.next()}return o}let l=this.getRowCount(),u=this.getColumnCount(),d=0;for(;!s.done;){let[e,n]=s.value;n.rowIndex<l&&n.colIndex<u&&d++,o=t(o,e,n,this),s=a.next()}let f=l*u-d;return f>0?c(o,f):o}reduce(e,t,n){if(!e)return t;let r=this.entries(n),i=r.next(),a=t;for(;!i.done;){let t=i.value;a=e(a,t.value,t.coords,this),i=r.next()}return a}repeat(e,t){if(e===1&&t===1)return this._self();if(e<=0||t<=0)throw Error(`Invalid tile dimensions: ${e} x ${t}`);let n=this._coords;if(!n)return this._self();let r=this._values.cloneEmpty(),i=n.colStart,a=n.rowStart,o={colStart:0,rowStart:0,colEnd:0,rowEnd:0};this.forEach((n,s)=>{o.colStart=i+s.colIndex*t,o.rowStart=a+s.rowIndex*e,o.colEnd=o.colStart+t-1,o.rowEnd=o.rowStart+e-1,vW(r,o,n)});let s=this.getColumnCount(),c=this.getRowCount();return n={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colStart+t*s-1,rowEnd:n.rowStart+e*c-1},this._newRange(r,n,this._optionsFresh())}reshape(e,t){let n=this.getRowCount(),r=this.getColumnCount();if(e===n&&t===r)return this._self();if(e<=0||t<=0||!Number.isFinite(e)||!Number.isFinite(t))throw Error(`Invalid reshape dimensions: ${e} x ${t}`);if(e*t<n*r)throw Error(`Cannot reshape ${n} x ${r} into ${e} x ${t}; the target holds fewer positions.`);let i=this._coords;if(!i)return this._self();let a=this._values.cloneEmpty(),o=i.rowStart,s=i.colStart;return this.forEach((e,n)=>{let i=n.rowIndex*r+n.colIndex;a.setValueAt(o+Math.trunc(i/t),s+i%t,e)}),this._newRange(a,{colStart:s,rowStart:o,colEnd:s+t-1,rowEnd:o+e-1},this._optionsFresh())}replace(e,t){let r;if(e?.isIRange)r=e;else{let t=nU(e,new ni({axis:this._values.getAxis()}),this._coords);r=this._newRange(t.values,t.coords,this._optionsFresh(),t.isLiteral)}if(this.size===0)return r._self();if(r.size===0)return this._self();let i=r._absentValue!==null;r=r._materializeEmpty();let a=Math.max(this.getColumnCount(),r.getColumnCount()+(t?.colIndex??0)),o=Math.max(this.getRowCount(),r.getRowCount()+(t?.rowIndex??0));if(this._absentValue!==null&&(!i||a>this.getColumnCount()||o>this.getRowCount()))return this._materializeEmpty().replace(r,t);let s=this._values.clone(),c=r._values,l=r._coords??n.CoordUtils.EmptyRange,u=this._coords??n.CoordUtils.EmptyRange,d=u.colStart,f=u.rowStart,p=d+(t?.colIndex??0),m=f+(t?.rowIndex??0);c.copyTo(s,{colIndex:p,rowIndex:m},l);let h={colStart:d,rowStart:f,colEnd:d+a-1,rowEnd:f+o-1};return this._newRange(s,h,this._optionsIterator,!1,!1,this._absentValue)}resize(e,t,n=null){if(t<0||e<0)throw Error(`Invalid resize dimensions: ${t} x ${e}`);let r=this._coords,i=r?r.colStart:0,a=r?r.rowStart:0,o=r?r.colEnd:0,s=r?r.rowEnd:0;if(t===(r?o-i+1:0)&&e===(r?s-a+1:0))return this._self();let c=this._absentValue;if(c!==null&&n!==c)return this._materializeEmpty().resize(e,t,n);let l=i+t-1,u=a+e-1,d=this._values;d=d.clone(),(!r||l>o||u>s)&&yW(d,r,l,u,c===null?n:null);let f={colStart:i,rowStart:a,colEnd:l,rowEnd:u};return this._newRange(d,f,this._optionsIterator,!1,!1,c)}select(e,t,n,r,i){Array.isArray(e)||(e=[e]);let a=e.length,o=-1;return n!==void 0&&(t=[...t,n],o=t.length-1),this.choose(t,(t,n)=>{let i=n.colIndex,s=n.rowIndex;for(let o=0;o<a;o++){let a=e[o];if(a.isIRange){let e=a,t=e.getColumnCount(),n=e.getRowCount();i+1>t&&t===1&&(i=0),s+1>n&&n===1&&(s=0),a=e.getValueAt(s,i)}if(r){if(wW.colIndex=i,wW.rowIndex=s,r(t,n,a,wW,this))return o}else if(t===a)return o}return o},i)}slice(e){if(!e)return this._self();let t=this._absoluteCoords(e);return t?this._newRange(this._values,t,this._optionsIterator,!1,!1,this._absentValue):this.empty()}some(e,t){if(!e)return!1;let n=this.entries(t),r=n.next();for(;!r.done;){let t=r.value;if(e(t.value,t.coords,this))return!0;r=n.next()}return!1}sort(e=1,n=t.IRange.Axis.Row){let r=this.argsort(this,e,n);return this.take(r,n)}sparseBuilder(e){let r=this._values,i=this._axisFromOptions(e),a=r.getAxis(),o=i!==t.IRange.Axis.Row,s=i===a?new z.Builder:new z.TransposedBuilder,c=this,l=this._coords??n.CoordUtils.EmptyRange,u=l.colStart,d=l.rowStart,f=o?u:d,p=o?d:u,m={pushAt(e,t,n){if(n===null)return m;let r=o?t:e,i=o?e:t;return s.pushAt(r+f,i+p,n),m},pushMultipleAt(e,t,n){let r;r=Array.isArray(n)?n:n.isIRange?n.getValuesFlat():[n];let i=o?t:e,a=o?e:t;return s.pushMultipleAt(i+f,a+p,r),m},build:()=>c._cloneFromBuilder(s)};return m}_takeSparse(e,n){let r=this.getRowCount(),i=this.getColumnCount(),a=n===t.IRange.Axis.Column,o=e.length,s=this.empty().resize(a?r:o,a?o:i,null).sparseBuilder(a?t.IRange.Axis.Column:t.IRange.Axis.Row);if(a)for(let t=0;t<o;t++){let n=e[t];for(let e=0;e<r;e++){let r=this.getValueAt(e,n);r!=null&&s.pushAt(e,t,r)}}else for(let t=0;t<o;t++){let n=e[t];for(let e=0;e<i;e++){let r=this.getValueAt(n,e);r!=null&&s.pushAt(t,e,r)}}return s.build()}_takeDense(e,n){let r=this.getRowCount(),i=this.getColumnCount(),a=n===t.IRange.Axis.Column,o=Array.from({length:i},()=>Array(r).fill(null)),s=this.entries(bW),c=s.next();for(;!c.done;){let{value:e,coords:t}=c.value;o[t.colIndex][t.rowIndex]=e,c=s.next()}let l=e.length,u=this.empty().resize(a?r:l,a?l:i,null).sparseBuilder(a?t.IRange.Axis.Column:t.IRange.Axis.Row);if(a)for(let t=0;t<l;t++){let n=o[e[t]];if(n)for(let e=0;e<r;e++){let r=n[e];r!=null&&u.pushAt(e,t,r)}}else for(let t=0;t<l;t++){let n=e[t];for(let e=0;e<i;e++){let r=o[e][n];r!=null&&u.pushAt(t,e,r)}}return u.build()}take(e,n=t.IRange.Axis.Row){let r=this.getRowCount(),i=this.getColumnCount();return e.length*i<i*r*.7?this._takeSparse(e,n):this._takeDense(e,n)}tile(e,t){if(e===1&&t===1)return this._self();if(e<=0||t<=0)throw Error(`Invalid tile dimensions: ${e} x ${t}`);let n=this._coords;if(!n)return this._self();if(this._absentValue!==null)return this._materializeEmpty().tile(e,t);let r=this._values,i=r.cloneEmpty(),a=this.getColumnCount(),o=this.getRowCount(),s=n.colStart,c=n.rowStart,l=0,u=0,d={rowIndex:0,colIndex:0};for(let f=0;f<e;f++){l=f*o;for(let e=0;e<t;e++)u=e*a,d.colIndex=s+u,d.rowIndex=c+l,r.copyTo(i,d,n)}return n={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colStart+t*a-1,rowEnd:n.rowStart+e*o-1},this._newRange(i,n,this._optionsFresh())}toScalar(){if(this.size!==1)throw Error(`Cannot convert to scalar, range size is ${this.size} not 1`);return this.getValueAt(0,0)}toType(e){let t=typeof e==`string`?{type:e}:e,n=this._optionsIterator;return n=n?{...n,...t}:t,this._newRange(this._values,this._coords,n,!1,!1,this._absentValue)}transpose(){if(this.size<=1)return this._self();let e=this._values,n=this._coords,r=e.getAxis(),i=this._entries({axis:r===t.IRange.Axis.Column?t.IRange.Axis.Row:t.IRange.Axis.Column,bounds:n,reuseResult:!0}),a=r===t.IRange.Axis.Column,o=new z.Builder,s=n.colStart,c=n.rowStart,l=i.next();for(;!l.done;){let e=l.value,t=e[0],n=t.colIndex-s,r=t.rowIndex-c,u=e[1];o.pushAt(a?r:n,a?n:r,u),l=i.next()}let u=this.empty()._cloneFromBuilder(o),d=n.colEnd-n.colStart+1,f=n.rowEnd-n.rowStart+1;return u.getRowCount()!==d||u.getColumnCount()!==f?u.resize(d,f):u}values(e){let t=this.entries(e);return{[Symbol.iterator](){return this},next(){let e=t.next();return e.done?zt:{done:!1,value:e.value.value}}}}zip(e,r,i){let a=i?{...this._optionsIterator,...i}:this._optionsIterator,o=a.type??null,s=o?this._coerceValue(null,o,a,t.ScalarType.Null):null,c=i?.misalignValue??t.FormulaError.BuiltIn.NA,l=i?.tile??!0,u=i?.blankRegions===`once`,d=this._values,f=d.getAxis()===t.IRange.Axis.Column,p=e.length+1,m=Array(p),h=Array(p),g=1,_=1;for(let t=0;t<p;t++){let n=t===0?this:e[t-1];if(h[t]=null,typeof n==`object`&&n&&!0===n.isIRange){let e=n;if(e.size>1){h[t]=e;let n=e.getRowCount(),r=e.getColumnCount();n>g&&(g=n),r>_&&(_=r);continue}let r=e.size===1?e.getValueAt(0,0):null;m[t]=(o?this._coerceValue(r,o,a):r)??s;continue}let r=n===void 0?null:n;m[t]=(o?this._coerceValue(r,o,a):r)??s}let v=f?_:g,y=f?g:_,b=[],x=[],S=[];for(let e=0;e<p;e++){let t=h[e];if(t===null)continue;let n=t._coords,r=t.getRowCount(),i=t.getColumnCount(),u=r===1&&l?g:r,d=i===1&&l?_:i,p=t._memberReader({...e===0?a:t._optionsIterator,type:o},!1),m=new gW(e,t._values,n,f,f?d:u,f?u:d,p,p(void 0)??s,c,s,t._skipsOnGrid(t._optionsIterator));b.push(m),m.majorExtent<v&&x.indexOf(m.majorExtent)<0&&x.push(m.majorExtent),m.minorExtent<y&&S.indexOf(m.minorExtent)<0&&S.push(m.minorExtent)}let C=b.length;x.sort((e,t)=>e-t),S.sort((e,t)=>e-t);let w=S.length+1,T=(e,t)=>{let n=0;for(;n<e.length&&e[n]<=t;)n++;return n},E=(e,t)=>{for(let n=0;n<C;n++){let r=b[n];m[r.slot]=r.covers?r.valueAt(t):e>=r.majorExtent||t>=r.minorExtent?r.pad:r.empty}},D=(e,t)=>{for(let n=0;n<C;n++){let r=b[n];m[r.slot]=e>=r.majorExtent||t>=r.minorExtent?r.pad:r.empty}},O=(e,t)=>({rowIndex:f?t:e,colIndex:f?e:t}),k=this._coords??n.CoordUtils.EmptyRange,A=f?k.colStart:k.rowStart,j=f?k.rowStart:k.colStart,M=new z.Builder(void 0,0,0,!0),N=u?Array((x.length+1)*w):null,P;_W(b,v,y,(e,t,n)=>{if(!u){for(let i=t;i<n;i++)D(e,i),M.pushAt(A+e,j+i,r(m,O(e,i),this));return}let i=T(x,e),a=t;for(;a<n;){let t=T(S,a),o=t<S.length?S[t]:y,s=Math.min(o,n),c=i*w+t;if(c===0)M.pushAbsentAt(A+e,j+a,s-a),P===void 0&&(D(e,a),P=r(m,hW,this)??null,M.setAbsentValue(P));else{let t=N[c];t===void 0&&(D(e,a),t=r(m,hW,this)??null,N[c]=t),M.pushMultipleAt(A+e,j+a,new ln([t],s-a))}a=s}},(e,t,n,i)=>{if(i&&u){E(e,t);let i=r(m,hW,this);M.pushMultipleAt(A+e,j+t,new ln([i],n-t+1));return}for(let i=t;i<=n;i++)E(e,i),M.pushAt(A+e,j+i,r(m,O(e,i),this))});let F=M.build(),I=d.cloneEmpty();return this._applyRegion(I,F,!0),this._newRange(I,{colStart:k.colStart,rowStart:k.rowStart,colEnd:k.colStart+_-1,rowEnd:k.rowStart+g-1},this._optionsIterator,!1,!1,F.absentValue??null)._untyped()}_isLiteralArray(){return this._isLiteral}_isDirectScalarBox(){return this._isDirectScalar}isEmpty(){return this.size===0}get size(){let e=this._coords;return e?(e.colEnd-e.colStart+1)*(e.rowEnd-e.rowStart+1):0}[Symbol.iterator](){let e=this.entries();return{next(){let t=e.next();return t.done?zt:{done:!1,value:t.value.value}},[Symbol.iterator](){return this}}}toString(){let e=this._coords;return e?`${e.rowEnd-e.rowStart+1}x${e.colEnd-e.colStart+1}:${this._toStringValues()}`:`0x0:{}`}get[Symbol.toStringTag](){return`[Range]`}_validateCoords(e){}_axisFromOptions(e){let t=this._optionsIterator;if(!e)return t.axis;let n;return n=typeof e==`object`&&`axis`in e?e.axis:e,n?n===`fastest`?this._values.getAxis():n:t.axis}_toStringValues(e=39){let n=`{`,r=this.entries({includeEmpty:!0,axis:t.IRange.Axis.Row,onError:`value`}),i=r.next(),a=0,o=i.value?.coords.rowIndex??0;for(;!i.done&&n.length<e;){let e=i.value;e.coords.rowIndex>o?(n+=`;`,o=e.coords.rowIndex):a>0&&(n+=`,`),a++;let t=e.value;t===null?t=``:typeof t==`string`?t=`"${t}"`:typeof t==`boolean`&&(t=t?`TRUE`:`FALSE`),n+=t,i=r.next()}return i.done?n+=`}`:n+=`...`,n}_entries(e){let t=this._coords;if(!t)return Bt;let n=this._values,r=this._optionsIterator,i=e?.axis===`fastest`?n.getAxis():e?.axis??r.axis,a=e?{...r,...e,axis:i}:r,o=n.entries(this._skipsOnGrid(a)),s=e?.type,c=this._absentValue;if(e?.includeEmpty||c!==null){if(a.bounds||(a={...a,bounds:t}),a.processRowSkip||a.processColumnSkip){let{processRowSkip:e,processColumnSkip:t,...n}=a;a=n}o=new Wr(o,a),s||c===null||(o=mW(o,c))}if(s){let t=o,n=this._memberReader(e,e?.includeEmpty??!1);o={[Symbol.iterator]:()=>o,next(){for(;;){let e=t.next();if(e.done)return zt;let r=e.value,i=r[1],a=n(i);if(a!==void 0)return a===i?e:{done:!1,value:[r[0],a]}}}}}return o}_memberReader(e,n){let r=this._absentValue,i=e?.type;if(!i)return e=>e===void 0?r:e;let a=null;n&&(a=this._coerceValue(null,i,{...e,onError:`value`},t.ScalarType.Null));let o=e.errorOnInvalidCoercion??!1,s=e.onError??`throw`,c=s===`ignore`,l=!1,u=!1,d=null;c||(s===`throw`?l=!0:s===`value`?u=!0:typeof s==`function`&&(d=s));let f=this._runtime,p=this,m=GH(f,i),h=e.coerce,g;h&&(typeof h==`function`?(m=h,g=GH(f,i,lU)):Array.isArray(h)&&(m=GH(f,i,h)));let _=this._isDirectScalar,v=e=>{if(e===null&&c)return a;let r=IH(e,!0);if(_&&!m&&r!==i&&(e=KH(f,e,r,i,!0),r=IH(e,!0)),r===i)return e;let s=null;if(r===t.ScalarType.Error?s=e:m&&(s=m(e,r,g,p),o&&s===null&&e!==null&&(s=t.FormulaError.BuiltIn.Value)),t.FormulaError.isError(s))if(c)s=null;else{if(l)throw s;u||d&&d(e)}return s===null?n?null:void 0:s};if(r===null)return e=>e===void 0?a:v(e);if(d)return e=>v(e===void 0?r:e);let y,b,x=0;return e=>{if(e!==void 0)return v(e);if(x===0)try{y=v(r),x=1}catch(e){b=e,x=2}if(x===2)throw b;return y}}_absoluteCoords(e,t){let r=this._coords??n.CoordUtils.EmptyRange,i=r.colStart,a=r.rowStart;uW.colStart=(e.colStart??0)+i,uW.rowStart=(e.rowStart??0)+a,uW.colEnd=(e.colEnd??r.colEnd-i)+i,uW.rowEnd=(e.rowEnd??r.rowEnd-a)+a;let o=n.CoordUtils.intersectRanges(r,uW,t);return o&&this._validateCoords(o),o}_self(){return this._isLiteral?this.clone():this}_untyped(){let e=this._optionsIterator;if(!e?.type)return this;let{type:t,coerce:n,...r}=e;return this._newRange(this._values,this._coords,r,this._isLiteral,!1,this._absentValue)}_optionsFresh(){let e=this._optionsIterator;if(!e.processRowSkip&&!e.processColumnSkip)return e;let{processRowSkip:t,processColumnSkip:n,...r}=e;return r}_optionsAt(e){let t=this._optionsIterator,n=t.processRowSkip,r=t.processColumnSkip;if(!n&&!r)return t;let i=this._coords;if(!e||!i)return this._optionsFresh();let a=e.rowStart-i.rowStart,o=e.colStart-i.colStart,s=i.rowEnd-i.rowStart+1,c=i.colEnd-i.colStart+1,l=e.rowEnd-e.rowStart+1+a>s,u=e.colEnd-e.colStart+1+o>c;return a!==0||o!==0||l||u?{...t,processRowSkip:n?cW(n,a,s):void 0,processColumnSkip:r?cW(r,o,c):void 0}:t}_hasSkips(){let e=this._optionsIterator;return e.processRowSkip!==void 0||e.processColumnSkip!==void 0}_skipsOnGrid(e){let t=e.processRowSkip,n=e.processColumnSkip;if(!t&&!n)return e;let r=this._coords;return r?{...e,processRowSkip:t?sW(t,r.rowStart):void 0,processColumnSkip:n?sW(n,r.colStart):void 0}:e}_createBuilder(e){let r=this._coords??n.CoordUtils.EmptyRange,i=this._values.getAxis(),a=e??i,o=a!==t.IRange.Axis.Row,s=o?r.colStart:r.rowStart,c=o?r.rowStart:r.colStart;return a===i?new z.Builder(null,s,c):new z.TransposedBuilder(null,s,c)}_applyRegion(e,t,n){if(!t)return;let r=t.clears;!n&&r&&pW(e,r),t.tuples.length>0&&e.setValues(t.tuples)}_cloneFromBuilder(e,t=null,n=!1,r=this._absentValue){return this._cloneFromRegion(e?e.build():null,t,n,r)}_cloneFromRegion(e,n=null,r=!1,i=this._absentValue){let a=e&&e.tuples.length>0?e:null,o=e?.clears;if(!(a||n||o&&o.length>0))return this._self();let s=this._values;s=r?s.cloneEmpty():s.clone();let c=s.getAxis()===t.IRange.Axis.Column;if(n){let e=n.done();for(let t of e)s.delete(t)}o&&!r&&pW(s,o);let l=this._coords;if(a){let e=zr(a.bounds,c),t=l,n=t?t.colStart:0,r=t?t.rowStart:0,i=t?t.colEnd:0,o=t?t.rowEnd:0,u=e.colEnd,d=e.rowEnd;(u>i||d>o)&&yW(s,t,u,d),s.setValues(a.tuples),l={colStart:n,rowStart:r,colEnd:Math.max(u,i),rowEnd:Math.max(d,o)}}return this._newRange(s,l,this._optionsIterator,this._isLiteral,!1,i)}_coerceValue(e,n,r,i){if(!n)return e;let a=this._runtime,o=GH(a,n),s=r?.coerce,c;s&&(typeof s==`function`?(o=s,c=GH(a,n,lU)):Array.isArray(s)&&(o=GH(a,n,s))),i??=IH(e,!0),this._isDirectScalar&&i!==n&&(e=KH(this._runtime,e,i,n,!0),i=IH(e,!0));let l=null;if(i===n)l=e;else if(o?l=o(e,i,c,this):i===t.ScalarType.Error&&(l=e),t.FormulaError.isError(l)){let e=r?.onError??`throw`;if(e===`throw`)throw l;e===`value`||(e===`ignore`?l=null:typeof e==`function`&&e(l))}return l}_mergeIterators(e,r,i){let a=this._coords??n.CoordUtils.EmptyRange,o=e._coords??n.CoordUtils.EmptyRange,s=this._values.getAxis(),c=i?.axis===`fastest`?s:i?.axis??s,l=c!==t.IRange.Axis.Row,u=this._entries(i),d=this._entries(i),f=a.colStart,p=a.rowStart,m=f-o.colStart,h=p-o.rowStart,g=c===s?new z.Builder:new z.TransposedBuilder,_=new Kr({...i,axis:c,bounds:a,comparator:(l?vA:yA)(a,o)},u,d),v=_.next();for(;!v.done;){let e=v.value,t=e[1],n=e[3],i=e[0],a=e[2],o=i?i.colIndex:a.colIndex+m,s=i?i.rowIndex:a.rowIndex+h,c=r(t,n,{colIndex:o-f,rowIndex:s-p},this),u=l?o:s,d=l?s:o;g.pushAt(u,d,c),v=_.next()}return g}_newRange(t,n,r=null,i=!1,a=!1,o=null){return r===this._optionsIterator&&n!==this._coords&&(r=this._optionsAt(n)),new e(this._runtime,t,n,r,i,a,o)}get isIRange(){return!0}},aW=class extends iW{constructor(e,t,n,r){super(e,t,n),this._visibleCoords=r}_getStats(e){return super._getStats(e).toLocalCoords(this._visibleCoords,e)}},oW=(e,t,n)=>{let r=e?.processRowSkip;if(r&&r(t)!==t)return!0;let i=e?.processColumnSkip;return i!==void 0&&i(n)!==n},sW=(e,t)=>t===0?e:(n,r)=>e(n-t,r)+t,cW=(e,t,n)=>(r,i)=>{let a=r+t;return a<0||a>=n?r:e(a,i)-t},lW={colStart:-(2**53-1),rowStart:-(2**53-1),colEnd:2**53-1,rowEnd:2**53-1},uW={colStart:-(2**53-1),rowStart:-(2**53-1),colEnd:2**53-1,rowEnd:2**53-1},dW=Object.freeze([Object.freeze([null])]),fW=Object.freeze({axis:t.IRange.Axis.Row}),pW=(e,n)=>{let r=e.getAxis()===t.IRange.Axis.Column;for(let t=0;t<n.length;t++){let i=n[t],a=i[0],o=i[1],s=o+i[2]-1;e.delete(r?{colStart:a,colEnd:a,rowStart:o,rowEnd:s}:{colStart:o,colEnd:s,rowStart:a,rowEnd:a})}},mW=(e,t)=>{let n={[Symbol.iterator]:()=>n,next(){let n=e.next();return n.done||n.value[1]!==void 0?n:{done:!1,value:[n.value[0],t]}}};return n},hW=Object.freeze({rowIndex:-1,colIndex:-1}),gW=class{constructor(e,n,r,i,a,o,s,c,l,u,d){this.seg=null,this.covers=!1,this._replay=null,this._replayMajor=0,this._replayAt=0,this._queue=[],this._queueAt=0,this.slot=e,this.majorExtent=a,this.minorExtent=o,this.read=s,this.empty=c,this.pad=l,this.dropped=u,this._isColumn=i,this._majorBase=i?r.colStart:r.rowStart,this._minorBase=i?r.rowStart:r.colStart,this._minorStart=this._minorBase,this._minorEnd=i?r.rowEnd:r.colEnd;let f=1+(i?r.colEnd-r.colStart:r.rowEnd-r.rowStart),p=this._minorEnd-this._minorStart+1;this._minorTile=p===1&&o>1;let m=n.getAxis()===t.IRange.Axis.Column===i,h=d?.processRowSkip,g=d?.processColumnSkip,_=m&&!h&&!g;if(this._runs=_?n.getRuns({bounds:r,overflowRun:!0}):null,this._cells=_?null:n.entries({axis:i?t.IRange.Axis.Column:t.IRange.Axis.Row,bounds:r,reuseResult:!1,processRowSkip:h,processColumnSkip:g}),f===1&&a>1){let e=[];for(;this._fill();){let t=this._queue;for(let n=this._queueAt;n<t.length;n++)e.push(t[n]);this._queueAt=t.length}this._replay=e,this._replayMajor=-1,this._replayAt=e.length}this.next()}valueAt(e){let t=this.seg,n=t.uniform?t.value:this.read(t.list.at(e+t.base));return n===void 0?this.dropped:n}next(){let e=this._replay;if(e!==null){if(this._replayAt>=e.length&&(this._replayMajor++,this._replayAt=0,this._replayMajor>=this.majorExtent||e.length===0))return void(this.seg=null);let t=e[this._replayAt++];t.major=this._replayMajor,t.from=t.start,this.seg=t;return}this._queueAt>=this._queue.length&&!this._fill()?this.seg=null:this.seg=this._queue[this._queueAt++]}_fill(){for(this._queue.length=0,this._queueAt=0;this._queue.length===0;){let e=this._runs;if(e!==null){let t=e.next();if(t.done)return!1;let n=t.value;this._pushRun(n[0]-this._majorBase,n[1],n[2])}else{let e=this._cells.next();if(e.done)return!1;let t=e.value,n=t[0],r=(this._isColumn?n.colIndex:n.rowIndex)-this._majorBase,i=this._isColumn?n.rowIndex:n.colIndex;if(i<this._minorStart||i>this._minorEnd)continue;this._push(r,i-this._minorBase,i-this._minorBase,!0,this.read(t[1]),null,0)}}return!0}_pushRun(e,t,n){let r=Math.max(t,this._minorStart),i=Math.min(t+n.length-1,this._minorEnd);if(r>i)return;let a=this._minorBase;if(this._minorTile)return void this._push(e,0,this.minorExtent-1,!0,this.read(n.at(r-t)),null,0);let o=t-a,s=n.getUniformRuns?.()??null;if(s===null)return void this._push(e,r-a,i-a,!1,void 0,n,-o);let c=r;for(let r=0;r<s.length;r++){let l=s[r],u=Math.max(t+l[0],c),d=Math.min(t+l[1],i);u>d||(c<u&&this._push(e,c-a,u-1-a,!1,void 0,n,-o),this._push(e,u-a,d-a,!0,this.read(l[2]),null,0),c=d+1)}c<=i&&this._push(e,c-a,i-a,!1,void 0,n,-o)}_push(e,t,n,r,i,a,o){this._queue.push({major:e,from:t,to:n,start:t,uniform:r,value:i,list:a,base:o})}},_W=(e,t,n,r,i)=>{let a=e.length,o=0,s=0,c=(e,t)=>{for(;o<e;)s<n&&r(o,s,n),o++,s=0;s<t&&(r(o,s,t),s=t)};for(;;){let t=0,r=0,l=!1;for(let n=0;n<a;n++){let i=e[n].seg;i!==null&&(!l||i.major<t||i.major===t&&i.from<r)&&(t=i.major,r=i.from,l=!0)}if(!l)break;(t>o||r>s)&&c(t,r);let u=n-1,d=!0;for(let n=0;n<a;n++){let i=e[n],a=i.seg;if(a!==null&&a.major===t){if(a.from===r){i.covers=!0,a.to<u&&(u=a.to),a.uniform||(d=!1);continue}a.from-1<u&&(u=a.from-1)}i.covers=!1;let o=i.minorExtent;o>r&&o-1<u&&(u=o-1)}i(t,r,u,d);for(let t=0;t<a;t++){let n=e[t];if(!n.covers)continue;let r=n.seg;r.to<=u?n.next():r.from=u+1}s=u+1,s>=n?(o=t+1,s=0):o=t}c(t,0)},vW=(e,n,r)=>{if(r===null)return void e.delete(n);let i=e.getAxis()===t.IRange.Axis.Column,a=Jr(r,Rr(n.colStart,n.rowStart,n.colEnd,n.rowEnd,i),i);e.setValues(a.tuples)},yW=(e,t,n,r,i=null)=>{if(!t)return lW.colStart=0,lW.rowStart=0,lW.colEnd=n,lW.rowEnd=r,void vW(e,lW,i);let a=t.colEnd,o=Math.max(n,a),s=t.rowEnd,c=Math.max(r,s);o>a&&(lW.colStart=a+1,lW.rowStart=t.rowStart,lW.colEnd=o,lW.rowEnd=c,vW(e,lW,i),o=a),c>s&&(lW.colStart=t.colStart,lW.rowStart=s+1,lW.colEnd=o,lW.rowEnd=c,vW(e,lW,i))},bW=Object.freeze({axis:`fastest`}),xW=64,SW=Object.freeze([t.ScalarType.Error]),CW=Object.freeze({axis:`fastest`,onError:`value`}),wW={colIndex:-(2**53-1),rowIndex:-(2**53-1)};function TW(e,t,n,r){let i=e==null,a=t==null;return i||a?i&&a?0:i?1:-1:sa.compare(e,t,r,r.collator)*n}function EW(e,t,n){return typeof e==`number`&&typeof t==`number`?e===t:sa.compare(e,t,n)===0}function DW(e,t,n){if(typeof t!=`string`)return e+wv(t);let r=n.get(t);return r===void 0&&(r=wv(t),n.set(t,r)),e+r}var OW=class e extends iW{constructor(e,t,n,r,i,a){if(super(e,t,n,r??null),this._errorIndex=null,this._onCoordsRead=null,this._getEntireCoords=i??NH,this._resolveScope=a,this._coords=kW(n,this._getEntireCoords()),!n)throw Error(`ReferenceRange requires a coords`);this._validateCoords(n)}getCoords(){this._onCoordsRead?.();let e=this._coords;if(e.scope){let n=this._resolveScope(e.scope);if(n==null)throw new t.FormulaError.Ref;e={...e,scope:n}}return e}get isIReferenceRange(){return!0}_setErrorIndex(e){this._errorIndex=e}_setCoordsReadHook(e){this._onCoordsRead=e}hasError(){let e=this._errorIndex;if(e===null||this.size<=1)return super.hasError();let t=e.hasErrorIn(this._coords);return t&&this._hasSkips()?super.hasError():t}slice(t){if(!t)return this._self();let n=this._absoluteCoords(t);if(!n)return this.empty();let r=this._coords.scope;r!==void 0&&n.scope===void 0&&(n={...n,scope:r});let i=new e(this._runtime,this._values,n,this._optionsAt(n),this._getEntireCoords,this._resolveScope);return i._errorIndex=this._errorIndex,i._onCoordsRead=this._onCoordsRead,i}clone(t,n=!1,r=!1){if(n||r)return super.clone(t,n,r);let i=new e(this._runtime,this._values,this._coords,t?{...this._optionsIterator,...t}:this._optionsIterator,this._getEntireCoords,this._resolveScope);return i._errorIndex=this._errorIndex,i._onCoordsRead=this._onCoordsRead,i}_toValueRange(){return new iW(this._runtime,this._values,this._coords,this._optionsIterator)}toType(t){let n=typeof t==`string`?{type:t}:t,r=new e(this._runtime,this._values,this._coords,n,this._getEntireCoords,this._resolveScope);return r._errorIndex=this._errorIndex,r._onCoordsRead=this._onCoordsRead,r}_validateCoords(e){let t=this._getEntireCoords?.();if(t&&(e.rowStart<t.rowStart&&e.rowStart!==-(2**53-1)||e.rowEnd>t.rowEnd&&e.rowEnd!==2**53-1||e.colStart<t.colStart&&e.colStart!==-(2**53-1)||e.colEnd>t.colEnd&&e.colEnd!==2**53-1))throw new n.OutOfBoundsError}get[Symbol.toStringTag](){return`[ReferenceRange]`}toString(){let e=this._coords,n=this._getEntireCoords();return e.scope&&(e={...e},e.scope=this._resolveScope(e.scope)??t.FormulaError.Label.Ref),`${gd(e,n)}=>${super.toString()}`}},kW=(e,t)=>{let n=e.rowStart,r=e.rowEnd,i=e.colStart,a=e.colEnd,o=!1;return i===-(2**53-1)&&(i=t.colStart,o=!0),n===-(2**53-1)&&(n=t.rowStart,o=!0),r===2**53-1&&(r=t.rowEnd,o=!0),a===2**53-1&&(a=t.colEnd,o=!0),o?{rowStart:n,rowEnd:r,colStart:i,colEnd:a,scope:e.scope}:e};Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return pT}}),Object.defineProperty(exports,"$t",{enumerable:!0,get:function(){return Qu}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return qO}}),Object.defineProperty(exports,"An",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"At",{enumerable:!0,get:function(){return r_}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return gT}}),Object.defineProperty(exports,"Bt",{enumerable:!0,get:function(){return zp}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return xA}}),Object.defineProperty(exports,"Cn",{enumerable:!0,get:function(){return ut}}),Object.defineProperty(exports,"Ct",{enumerable:!0,get:function(){return bv}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return xk}}),Object.defineProperty(exports,"Dn",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"Dt",{enumerable:!0,get:function(){return Q_}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return fk}}),Object.defineProperty(exports,"En",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"Et",{enumerable:!0,get:function(){return nv}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return zD}}),Object.defineProperty(exports,"Fn",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"Ft",{enumerable:!0,get:function(){return Pp}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return rT}}),Object.defineProperty(exports,"Gt",{enumerable:!0,get:function(){return cp}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return iT}}),Object.defineProperty(exports,"Ht",{enumerable:!0,get:function(){return fp}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return zE}}),Object.defineProperty(exports,"In",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"It",{enumerable:!0,get:function(){return oh}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return TT}}),Object.defineProperty(exports,"Jt",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return eT}}),Object.defineProperty(exports,"Kt",{enumerable:!0,get:function(){return up}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return RE}}),Object.defineProperty(exports,"Lt",{enumerable:!0,get:function(){return Op}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return KO}}),Object.defineProperty(exports,"Mn",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"Mt",{enumerable:!0,get:function(){return Dp}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return zO}}),Object.defineProperty(exports,"Nn",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"Nt",{enumerable:!0,get:function(){return ih}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return lk}}),Object.defineProperty(exports,"On",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"Ot",{enumerable:!0,get:function(){return Y_}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return yO}}),Object.defineProperty(exports,"Pn",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"Pt",{enumerable:!0,get:function(){return Np}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return xT}}),Object.defineProperty(exports,"Qt",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return IE}}),Object.defineProperty(exports,"Rt",{enumerable:!0,get:function(){return Sm}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return OA}}),Object.defineProperty(exports,"Sn",{enumerable:!0,get:function(){return pt}}),Object.defineProperty(exports,"St",{enumerable:!0,get:function(){return gv}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return fA}}),Object.defineProperty(exports,"Tn",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"Tt",{enumerable:!0,get:function(){return rv}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return ST}}),Object.defineProperty(exports,"Ut",{enumerable:!0,get:function(){return Hf}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return Vw}}),Object.defineProperty(exports,"Vt",{enumerable:!0,get:function(){return mp}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return oT}}),Object.defineProperty(exports,"Wt",{enumerable:!0,get:function(){return Bf}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return Hw}}),Object.defineProperty(exports,"Xt",{enumerable:!0,get:function(){return zf}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return aT}}),Object.defineProperty(exports,"Yt",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return CT}}),Object.defineProperty(exports,"Zt",{enumerable:!0,get:function(){return If}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Xj}}),Object.defineProperty(exports,"_n",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"_t",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return KV}}),Object.defineProperty(exports,"an",{enumerable:!0,get:function(){return Eu}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return rC}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Ej}}),Object.defineProperty(exports,"bn",{enumerable:!0,get:function(){return ht}}),Object.defineProperty(exports,"bt",{enumerable:!0,get:function(){return wv}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return HV}}),Object.defineProperty(exports,"cn",{enumerable:!0,get:function(){return oa}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return aV}}),Object.defineProperty(exports,"dn",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return JS}}),Object.defineProperty(exports,"en",{enumerable:!0,get:function(){return Sd}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return hw}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return RB}}),Object.defineProperty(exports,"fn",{enumerable:!0,get:function(){return xi}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return SS}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return GN}}),Object.defineProperty(exports,"gn",{enumerable:!0,get:function(){return Ei}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return Gx}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return cP}}),Object.defineProperty(exports,"hn",{enumerable:!0,get:function(){return Ti}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return bS}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return XV}}),Object.defineProperty(exports,"in",{enumerable:!0,get:function(){return bd}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return nC}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return GO}}),Object.defineProperty(exports,"jn",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"jt",{enumerable:!0,get:function(){return ag}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return ek}}),Object.defineProperty(exports,"kn",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"kt",{enumerable:!0,get:function(){return o_}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return EV}}),Object.defineProperty(exports,"ln",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return WS}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return dP}}),Object.defineProperty(exports,"mn",{enumerable:!0,get:function(){return wi}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return yS}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return GU}}),Object.defineProperty(exports,"nn",{enumerable:!0,get:function(){return Td}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return $S}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return xH}}),Object.defineProperty(exports,"on",{enumerable:!0,get:function(){return wu}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return ZS}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return yR}}),Object.defineProperty(exports,"pn",{enumerable:!0,get:function(){return Ci}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return CS}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return $w}}),Object.defineProperty(exports,"qt",{enumerable:!0,get:function(){return jf}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return SU}}),Object.defineProperty(exports,"rn",{enumerable:!0,get:function(){return ld}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return QS}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return VV}}),Object.defineProperty(exports,"sn",{enumerable:!0,get:function(){return Vc}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return tC}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return JU}}),Object.defineProperty(exports,"tn",{enumerable:!0,get:function(){return gd}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return eC}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return $B}}),Object.defineProperty(exports,"un",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return GS}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Kj}}),Object.defineProperty(exports,"vn",{enumerable:!0,get:function(){return zt}}),Object.defineProperty(exports,"vt",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return wk}}),Object.defineProperty(exports,"wn",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"wt",{enumerable:!0,get:function(){return ev}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return JA}}),Object.defineProperty(exports,"xn",{enumerable:!0,get:function(){return _t}}),Object.defineProperty(exports,"xt",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Sj}}),Object.defineProperty(exports,"yn",{enumerable:!0,get:function(){return vt}}),Object.defineProperty(exports,"yt",{enumerable:!0,get:function(){return Cv}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return mT}}),Object.defineProperty(exports,"zt",{enumerable:!0,get:function(){return Dm}});
|