@univerjs/core 0.1.8 → 0.1.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/lib/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  `):"",this.name="UnsubscriptionError",this.errors=e}});function He(t,s){if(t){var e=t.indexOf(s);0<=e&&t.splice(e,1)}}var ks=function(){function t(s){this.initialTeardown=s,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var s,e,n,r,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=Me(o),l=a.next();!l.done;l=a.next()){var u=l.value;u.remove(this)}}catch(g){s={error:g}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(s)throw s.error}}else o.remove(this);var c=this.initialTeardown;if(ct(c))try{c()}catch(g){i=g instanceof Jt?g.errors:[g]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var _=Me(h),f=_.next();!f.done;f=_.next()){var E=f.value;try{Fe(E)}catch(g){i=i!=null?i:[],g instanceof Jt?i=xe(xe([],Pe(i)),Pe(g.errors)):i.push(g)}}}catch(g){n={error:g}}finally{try{f&&!f.done&&(r=_.return)&&r.call(_)}finally{if(n)throw n.error}}}if(i)throw new Jt(i)}},t.prototype.add=function(s){var e;if(s&&s!==this)if(this.closed)Fe(s);else{if(s instanceof t){if(s.closed||s._hasParent(this))return;s._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(s)}},t.prototype._hasParent=function(s){var e=this._parentage;return e===s||Array.isArray(e)&&e.includes(s)},t.prototype._addParent=function(s){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(s),e):e?[e,s]:s},t.prototype._removeParent=function(s){var e=this._parentage;e===s?this._parentage=null:Array.isArray(e)&&He(e,s)},t.prototype.remove=function(s){var e=this._finalizers;e&&He(e,s),s instanceof t&&s._removeParent(this)},t.EMPTY=function(){var s=new t;return s.closed=!0,s}(),t}();ks.EMPTY;function Qr(t){return t instanceof ks||t&&"closed"in t&&ct(t.remove)&&ct(t.add)&&ct(t.unsubscribe)}function Fe(t){ct(t)?t():t.unsubscribe()}class Gs{constructor(s=!1){d(this,"skipNextObservers");d(this,"lastReturnValue");d(this,"isStopPropagation",!1);this.initialize(s)}initialize(s=!1){return this.skipNextObservers=s,this}stopPropagation(){this.isStopPropagation=!0}}function $s(t){return t instanceof kt}class kt{constructor(s,e){d(this,"_willBeUnregistered",!1);d(this,"unregisterOnNextCall",!1);this.callback=s,this.observable=e}dispose(){this.observable.remove(this)}}class Gt{constructor(s){d(this,"_observers",new Array);d(this,"_eventState");d(this,"_onObserverAdded");this._eventState=new Gs,s&&(this._onObserverAdded=s)}get observers(){return this._observers}add(s,e=!1,n=!1){if(!s)return null;const r=new kt(s,this);return r.unregisterOnNextCall=n,e?this._observers.unshift(r):this._observers.push(r),this._onObserverAdded&&this._onObserverAdded(r),r}addOnce(s){return this.add(s,void 0,!0)}remove(s){return s&&this._observers.indexOf(s)!==-1?(this._deferUnregister(s),!0):!1}removeCallback(s){for(let e=0;e<this._observers.length;e++){const n=this._observers[e];if(!n._willBeUnregistered&&n.callback===s)return this._deferUnregister(n),!0}return!1}makeObserverTopPriority(s){this._remove(s),this._observers.unshift(s)}makeObserverBottomPriority(s){this._remove(s),this._observers.push(s)}notifyObservers(s){if(!this._observers.length)return null;const e=this._eventState;e.skipNextObservers=!1,e.lastReturnValue=s,e.isStopPropagation=!1;let n=!1;for(let r=0;r<this._observers.length;r++){const i=this._observers[r];if(!i._willBeUnregistered&&(e.lastReturnValue=i.callback(s,e),i.unregisterOnNextCall&&this._deferUnregister(i),e.isStopPropagation&&(n=!0),e.skipNextObservers))return{lastReturnValue:e.lastReturnValue,stopPropagation:n}}return{lastReturnValue:e.lastReturnValue,stopPropagation:n}}notifyObserversWithPromise(s){let e=Promise.resolve(s);if(!this._observers.length)return e;const n=this._eventState;n.skipNextObservers=!1;for(let r=0;r<this._observers.length;r++){const i=this._observers[r];n.skipNextObservers||i._willBeUnregistered||(e=e.then(()=>i.callback(s,n)),i.unregisterOnNextCall&&this._deferUnregister(i))}return e.then(()=>s)}notifyObserver(s,e){if(s._willBeUnregistered)return;const n=this._eventState;return n.skipNextObservers=!1,s.callback(e,n),s.unregisterOnNextCall&&this._deferUnregister(s),{lastReturnValue:n.lastReturnValue,stopPropagation:n.isStopPropagation}}hasObservers(){return this._observers.length>0}clear(){this._observers=new Array,this._onObserverAdded=null}clone(){const s=new Gt;return s._observers=this._observers.slice(0),s}_deferUnregister(s){s.unregisterOnNextCall=!1,s._willBeUnregistered=!0,setTimeout(()=>{this._remove(s)},0)}_remove(s){if(!s)return!1;const e=this._observers.indexOf(s);return e!==-1?(this._observers.splice(e,1),!0):!1}}function v(t){let s=!1;return t?Qr(t)?{dispose:()=>t.unsubscribe()}:$s(t)?{dispose:()=>{s||(s=!0,t.dispose())}}:typeof t=="function"?{dispose:()=>{s||(s=!0,t())}}:t:v(()=>{})}function ti(t){return v(()=>{t.unsubscribe()})}class Ee{constructor(){d(this,"_disposables",new Set)}add(s){const e=v(s);return this._disposables.add(e),{dispose:()=>{e.dispose(),this._disposables.delete(e)}}}dispose(){this._disposables.forEach(s=>{s.dispose()}),this._disposables.clear()}}class p{constructor(){d(this,"_disposed",!1);d(this,"_collection",new Ee)}disposeWithMe(s){return this._collection.add(s)}ensureNotDisposed(){if(this._disposed)throw new Error("[Disposable]: object is disposed!")}dispose(){this._disposed||(this._disposed=!0,this._collection.dispose())}}class ei extends p{constructor(){super(...arguments);d(this,"dispose$",new L.Subject)}dispose(){super.dispose(),this.dispose$.next(),this.dispose$.complete()}}class at{static hasLength(s,e){return s.length===e}static getValueType(s){return Object.prototype.toString.apply(s)}static isObject(s){return this.getValueType(s)==="[object Object]"}static isIterable(s){return s[Symbol.iterator]!=null}static isNumber(s){return this.getValueType(s)==="[object Number]"}}function $t(t,s){const e=t.indexOf(s);return e>-1?(t.splice(e,1),!0):!1}function si(t){const s=new Set,e=[];for(const n of t)s.has(n)||(s.add(n),e.push(n));return e}function ni(t,s){for(let e=t.length-1;e>-1;e--){const n=t[e];if(s(n,e))return n}return null}function ri(t,s){if(t.length===0)return t;const e=s%t.length;return t.slice(e).concat(t.slice(0,e))}function ii(t,s){const e=new Map;return t.forEach(n=>{const r=s(n);let i=e.get(r);e.has(r)||(i=[],e.set(r,i)),i.push(n)}),e}const S=Symbol("newer"),D=Symbol("older");class Vs{constructor(s){d(this,"entry");this.entry=s}[Symbol.iterator](){return this}next(){const s=this.entry;return s?(this.entry=s[S],{done:!1,value:s.key}):{done:!0,value:void 0}}}class js{constructor(s){d(this,"entry");this.entry=s}[Symbol.iterator](){return this}next(){const s=this.entry;return s?(this.entry=s[S],{done:!1,value:s.value}):{done:!0,value:void 0}}}class Ks{constructor(s){d(this,"entry");this.entry=s}[Symbol.iterator](){return this}next(){const s=this.entry;return s?(this.entry=s[S],{done:!1,value:[s.key,s.value]}):{done:!0,value:void 0}}}var La,Ta;class ee{constructor(s,e){d(this,"key");d(this,"value");d(this,La);d(this,Ta);this.key=s,this.value=e,this[S]=void 0,this[D]=void 0}toJSON(){return{key:this.key,value:this.value}}}La=S,Ta=D;class Ys{constructor(...s){d(this,"_keymap");d(this,"size",0);d(this,"limit");d(this,"oldest");d(this,"newest");d(this,"_onShiftListeners",[]);if(at.hasLength(s,1)){if(at.isNumber(s[0])){const e=s[0];this._initialize(e,void 0);return}if(at.isIterable(s[0])){const e=s[0];this._initialize(0,e);return}return}if(at.hasLength(s,2)){const e=s[0],n=s[1];this._initialize(e,n)}}onShift(s){if(this._onShiftListeners.indexOf(s)===-1)return this._onShiftListeners.push(s),v(()=>$t(this._onShiftListeners,s));throw new Error("[LRUMap]: the listener has been registered!")}_initialize(s,e){this.oldest=void 0,this.newest=void 0,this.size=0,this.limit=s,this._keymap=new Map,e&&(this.assign(e),s<1&&(this.limit=this.size))}_markEntryAsUsed(s){s!==this.newest&&(s[S]&&(s===this.oldest&&(this.oldest=s[S]),s[S][D]=s[D]),s[D]&&(s[D][S]=s[S]),s[S]=void 0,s[D]=this.newest,this.newest&&(this.newest[S]=s),this.newest=s)}assign(s){let e,n=this.limit||Number.MAX_VALUE;this._keymap.clear();const r=s[Symbol.iterator]();for(let i=r.next();!i.done;i=r.next()){const o=new ee(i.value[0],i.value[1]);if(this._keymap.set(o.key,o),e?(e[S]=o,o[D]=e):this.oldest=o,e=o,n--===0)throw new Error("overflow")}this.newest=e,this.size=this._keymap.size}set(s,e){let n=this._keymap.get(s);return n?(n.value=e,this._markEntryAsUsed(n),this):(this._keymap.set(s,n=new ee(s,e)),this.newest?(this.newest[S]=n,n[D]=this.newest):this.oldest=n,this.newest=n,++this.size,this.size>this.limit&&this.shift(),this)}shift(){const s=this.oldest;if(s)return this.oldest&&this.oldest[S]?(this.oldest=this.oldest[S],this.oldest[D]=void 0):(this.oldest=void 0,this.newest=void 0),s[S]=s[D]=void 0,this._keymap.delete(s.key),--this.size,this._onShiftListeners.forEach(e=>e(s)),[s.key,s.value]}get(s){const e=this._keymap.get(s);if(e)return this._markEntryAsUsed(e),e.value}has(s){return this._keymap.has(s)}find(s){const e=this._keymap.get(s);return e?e.value:void 0}delete(s){const e=this._keymap.get(s);if(e)return this._keymap.delete(e.key),e[S]&&e[D]?(e[D][S]=e[S],e[S][D]=e[D]):e[S]?(e[S][D]=void 0,this.oldest=e[S]):e[D]?(e[D][S]=void 0,this.newest=e[D]):this.oldest=this.newest=void 0,this.size--,e.value}clear(){this.oldest=void 0,this.newest=void 0,this.size=0,this._keymap.clear()}keys(){return new Vs(this.oldest)}values(){return new js(this.oldest)}entries(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Ks(this.oldest)}forEach(s,e){typeof e!="object"&&(e=this);let n=this.oldest;for(;n;)s.call(e,n.value,n.key,this),n=n[S]}toJSON(){const s=new Array(this.size);let e=0,n=this.oldest;for(;n;)s[e++]={key:n.key,value:n.value},n=n[S];return s}toString(){let s="",e=this.oldest;for(;e;)s+=`${String(e.key)}:${e.value}`,e=e[S],e&&(s+=" < ");return s}}function y(t){let s=0;const e=Object.keys(t);for(const n of e){const r=Number(n);s=Math.max(s,r)}return s+1}function se(t,s,e){const n=y(e),r=e;for(let i=n-1;i>=t;i--)r[i+1]=r[i];r[t]=s}function ne(t,s,e){const n=Object.keys(e).reduce((r,i)=>Math.max(r,Number.parseInt(i)),0)+1;for(let r=t;r<n;r++)r<t+s?delete e[r]:e[r]!==void 0&&(e[r-s]=e[r],delete e[r])}function oi(t,s){const e=t,n=Object.keys(e),r=n.length,i=s,o=Object.keys(i),a=o.length,l={};let u=0;for(let c=0;c<r;c++,u++){const h=n[c];l[u]=e[h]}for(let c=0;c<a;c++,u++){const h=o[c];l[u]=i[h]}return l}function ai(t,s,e){const n=e;if(y(e)>0){const i={};let o=0;for(let a=t;a<=s;a++)n[a]&&(i[o]=n[a],o++);return i}return{}}function re(t,s,e,n){const r=t>e;if(!r&&t+s>e)throw new Error("Invalid move operation");r?li(t,s,e,n):ui(t,s,e,n)}function li(t,s,e,n){const r=n,i=[];for(let o=t;o<t+s;o++)i.push(r[o]);for(let o=t-1;o>=e;o--){const a=r[o];r[o+s]=a,a===void 0&&delete r[o+s]}i.forEach((o,a)=>{r[e+a]=o,o===void 0&&delete r[e+a]})}function ui(t,s,e,n){const r=n,i=[];for(let o=t;o<t+s;o++)i.push(r[o]);for(let o=t+s;o<e;o++){const a=r[o];r[o-s]=a,a===void 0&&delete r[o-s]}i.forEach((o,a)=>{r[e+a-s]=o,o===void 0&&delete r[e+a-s]})}class G{constructor(s={}){d(this,"_matrix");this._setOriginValue(s)}static MakeObjectMatrixSize(s){return new G({[s-1]:{}})}getMatrix(){return this._matrix}forEach(s){const e=this._matrix,n=Object.keys(e);for(const r of n){const i=Number(r),o=e[i];if(s(i,o)===!1)return this}return this}forRow(s){const e=this._matrix,n=Object.keys(e);for(const r of n){const i=Number(r),o=e[i];if(s(i,Object.keys(o).map(l=>Number(l)))===!1)return this}return this}forValue(s){const e=this._matrix,n=Object.keys(e);for(const r of n){const i=Number(r),o=e[i];if(!o)continue;const a=Object.keys(o);for(const l of a){const u=Number(l),c=o[Number(l)];if(s(i,u,c)===!1)return this}}return this}swapRow(s,e){const n=this._matrix[s],r=this._matrix[e];this._matrix[s]=r,this._matrix[e]=n}getRow(s){return this._matrix[s]}getRowOrCreate(s){let e=this.getRow(s);return e==null&&(e={},this._matrix[s]=e),e}reset(){this._setOriginValue({})}hasValue(){const s=this._matrix,e=Object.keys(s);if(e.length===0)return!1;for(const n of e){const r=Number(n),i=s[r];if(Object.keys(i).length>0)return!0}return!1}getValue(s,e){var n,r;return(r=(n=this._matrix)==null?void 0:n[s])==null?void 0:r[e]}setValue(s,e,n){const r=this.getRowOrCreate(s);r[e]=n}deleteValue(s,e){var n,r;(r=(n=this._matrix)==null?void 0:n[s])==null||delete r[e]}realDeleteValue(s,e){var n,r,i;if((r=(n=this._matrix)==null?void 0:n[s])==null||delete r[e],this.getRow(s)){const o=this.getRow(s);if(o==null)return;Object.keys(o).length===0&&((i=this._matrix)==null||delete i[s])}}setRow(s,e){this._matrix[s]=e}moveRows(s,e,n){re(s,e,n,this._matrix)}moveColumns(s,e,n){this.forEach((r,i)=>{re(s,e,n,i)})}insertRows(s,e){for(let n=s;n<s+e;n++)se(n,{},this._matrix)}insertColumns(s,e){for(let n=s;n<s+e;n++)this.forEach((r,i)=>{se(n,void 0,i)})}removeRows(s,e){ne(s,e,this._matrix)}removeColumns(s,e){this.forEach((n,r)=>{ne(s,e,r)})}getFragment(s,e,n,r){const i=new G;let o=0;for(let a=s;a<=e;a++){const l={};let u=0;for(let c=n;c<=r;c++){const h=this.getValue(a,c);l[u]=h,u++}i.setRow(o,l),o++}return i}getSlice(s,e,n,r){const i=new G;for(let o=s;o<=e;o++)for(let a=n;a<=r;a++){const l=this.getValue(o,a);l&&i.setValue(o,a,R.deepClone(l))}return i}getSizeOf(){return Object.keys(this._matrix).length}getLength(){return y(this._matrix)}getRange(){const n=this.getLength()-1;let r=0;const i=this.getLength();for(let o=0;o<i;o++){const a=this.getRow(o);if(a){const l=y(a)-1;r=l>r?l:r}}return{startRow:0,startColumn:0,endRow:n,endColumn:r}}toNativeArray(){const s=new Array;return this.forValue((e,n,r)=>{s.push(r)}),s}toArray(){const s=[];return this.forRow((e,n)=>{s[e]==null&&(s[e]=[]),n.forEach(r=>{s[e][r]=this.getValue(e,r)})}),s}toFullArray(){const s=this.getRange(),{endColumn:e,endRow:n}=s,r=[];for(let i=0;i<=n;i++){const o=Array(e+1).fill(void 0);r.push(o)}return this.forValue((i,o,a)=>{r[i][o]=a}),r}toJSON(){return this._matrix}clone(){const s=JSON.stringify(this._matrix);return JSON.parse(s)}getData(){const s=JSON.stringify(this._matrix);return JSON.parse(s)}getArrayData(){let s=0,e=0,n=!1,r=!1;const i=new G;return this.forEach((o,a)=>{n||(n=!0,s=o),Object.keys(a).forEach(l=>{const u=Number(l);r?u<e&&(e=u):(r=!0,e=u);const c=this.getValue(o,u);i.setValue(o-s,u-e,c)})}),i.getData()}getDataRange(){let s=0,e=0,n=0,r=-1,i=!1,o=!1;return this.forEach((a,l)=>{if(i||(i=!0,s=a),l==null)return;const u=y(l)-1;u>n&&(n=u),Object.keys(l).forEach(c=>{const h=Number(c);o?h<e&&(e=h):(o=!0,e=h)}),a>r&&(r=a)}),{startRow:s,startColumn:e,endRow:r,endColumn:n}}getDiscreteRanges(){const s=[];return this.forEach((e,n)=>{Object.keys(n).forEach(r=>{const i=Number(r);let o=!1;for(const a of s)if(e>=a.startRow&&e<=a.endRow+1&&i>=a.startColumn&&i<=a.endColumn+1){a.endRow=Math.max(e,a.endRow),a.endColumn=Math.max(i,a.endColumn),o=!0;break}o||s.push({startRow:e,endRow:e,startColumn:i,endColumn:i})})}),s}merge(s){this.forValue((e,n)=>{const r=s.getValue(e,n);r!=null&&this.setValue(e,n,r)})}_setOriginValue(s={}){this._matrix=s}}var ge=(t=>(t.INIT="init",t.FETCHING="fetching",t.DONE="done",t))(ge||{});class zs{constructor(){d(this,"status","init")}}const ci=t=>t.some(s=>s.status==="init")?"init":t.some(s=>s.status==="fetching")?"fetching":"done",z=class z{static clone(s){return s.rangeType!==void 0?{startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn,rangeType:s.rangeType}:{startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn}}static equals(s,e){return s==null||e==null?!1:s.endRow===e.endRow&&s.endColumn===e.endColumn&&s.startRow===e.startRow&&s.startColumn===e.startColumn&&(s.rangeType===e.rangeType||s.rangeType===void 0&&e.rangeType===x.NORMAL||e.rangeType===void 0&&s.rangeType===x.NORMAL)}static intersects(s,e){const n=s.startRow,r=s.endRow,i=s.startColumn,o=s.endColumn,a=e.startRow,l=e.endRow,u=e.startColumn,c=e.endColumn,h=Math.abs(i+o-u-c),_=Math.abs(i-o)+Math.abs(u-c),f=Math.abs(n+r-a-l),E=Math.abs(n-r)+Math.abs(a-l);return h<=_&&f<=E}static getIntersects(s,e){const n=s.startRow,r=s.endRow,i=s.startColumn,o=s.endColumn,a=e.startRow,l=e.endRow,u=e.startColumn,c=e.endColumn;let h,_,f,E;if(a<=r)a>=n?_=a:_=n;else return null;if(l>=n)l>=r?E=r:E=l;else return null;if(u<=o)u>i?h=u:h=i;else return null;if(c>=i)c>=o?f=o:f=c;else return null;return{startRow:_,endRow:E,startColumn:h,endColumn:f,rangeType:x.NORMAL}}static contains(s,e){return s.startRow<=e.startRow&&s.endRow>=e.endRow&&s.startColumn<=e.startColumn&&s.endColumn>=e.endColumn}static realContain(s,e){return z.contains(s,e)&&(s.startRow<e.startRow||s.endRow>e.endRow||s.startColumn<e.startColumn||s.endColumn>e.endColumn)}static union(...s){return s.reduce((e,n)=>({startRow:Math.min(e.startRow,n.startRow),startColumn:Math.min(e.startColumn,n.startColumn),endRow:Math.max(e.endRow,n.endRow),endColumn:Math.max(e.endColumn,n.endColumn),rangeType:x.NORMAL}),s[0])}static subtract(s,e){if(e.startRow>s.endRow||e.endRow<s.startRow||e.startColumn>s.endColumn||e.endColumn<s.startColumn)return[s];const n=[];e.startRow>=s.startRow&&n.push({startRow:s.startRow,startColumn:s.startColumn,endRow:e.startRow-1,endColumn:s.endColumn}),e.endRow<=s.endRow&&n.push({startRow:e.endRow+1,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn});const r=Math.max(s.startRow,e.startRow),i=Math.min(s.endRow,e.endRow);return e.startColumn>=s.startColumn&&n.push({startRow:r,startColumn:s.startColumn,endRow:i,endColumn:e.startColumn-1}),e.endColumn<=s.endColumn&&n.push({startRow:r,startColumn:e.endColumn+1,endRow:i,endColumn:s.endColumn}),n.filter(a=>a.startRow<=a.endRow&&a.startColumn<=a.endColumn)}};d(z,"getRelativeRange",(s,e)=>({startRow:s.startRow-e.startRow,endRow:s.endRow-s.startRow,startColumn:s.startColumn-e.startColumn,endColumn:s.endColumn-s.startColumn})),d(z,"getPositionRange",(s,e,n)=>({...n||{},startRow:n&&[w.ROW,w.ALL].includes(n.startAbsoluteRefType||0)?n.startRow:s.startRow+e.startRow,endRow:n&&[w.ROW,w.ALL].includes(n.endAbsoluteRefType||0)?n.endRow:s.endRow+s.startRow+e.startRow,startColumn:n&&[w.COLUMN,w.ALL].includes(n.startAbsoluteRefType||0)?n.startColumn:s.startColumn+e.startColumn,endColumn:n&&[w.COLUMN,w.ALL].includes(n.endAbsoluteRefType||0)?n.endColumn:s.endColumn+s.startColumn+e.startColumn})),d(z,"moveHorizontal",(s,e=0,n=0)=>({...s,startColumn:s.startColumn+e,endColumn:s.endColumn+e+n})),d(z,"moveVertical",(s,e=0,n=0)=>({...s,startRow:s.startRow+e,endRow:s.endRow+e+n})),d(z,"moveOffset",(s,e,n)=>({...s,startRow:s.startRow+n,endRow:s.endRow+n,startColumn:s.startColumn+e,endColumn:s.endColumn+e}));let X=z;class hi{constructor(s,e){d(this,"_values",[]);d(this,"_keys",[]);d(this,"_keyMaps",new Map);this._values=s,this._keys=e,s.forEach(n=>{this._initKeyMap(n)})}_initKeyMap(s){this._keys.forEach(e=>{const n=s[e],r=this._keyMaps.get(e)||new Map;r.set(n,s),this._keyMaps.set(e,r)})}getValue(s,e){const n=e||this._keys;for(let r=0;r<n.length;r++){const i=this._keyMaps.get(n[r]);if(i!=null&&i.has(s))return i.get(s)}return null}hasValue(s){for(let e=0;e<this._keys.length;e++){const n=this._keyMaps.get(this._keys[e]);if(n!=null&&n.has(s))return!0}return!1}addValue(s){this._values.push(s),this._initKeyMap(s)}setValue(s,e,n){const r=this.getValue(s);r&&Object.keys(r).includes(e)&&(r[e]=n)}deleteValue(s){const e=this.getValue(s);if(e){this._keys.forEach(r=>{const i=this._keyMaps.get(r),o=e[r];i==null||i.delete(o)});const n=this._values.findIndex(r=>r===e);this._values.splice(n,1)}}getValues(){return this._values}getKeyMap(s){var e;return[...((e=this._keyMaps.get(s))==null?void 0:e.keys())||[]]}clear(){this._values=[],this._keys=[],this._keyMaps.clear()}}function ie(t,s,e,n){return{forEach(r){for(let i=t;i<=s;i++)for(let o=e;o<=n;o++)r(i,o)}}}function di(t){if(t==null||t.length===0)return Number.NaN;const s=t.toLowerCase().split(""),e=s.length,n=o=>o.charCodeAt(0)-96;let r=0,i=0;for(let o=0;o<e;o++)i=n(s[o]),r+=i*26**(e-o-1);return r===0?Number.NaN:r-1}const xt=65,ys=90,_i=97;function fi(t){const s=ys-xt+1;let e="";for(;t>=0;)e=String.fromCharCode(t%s+xt)+e,t=Math.floor(t/s)-1;return e}function Xs(t,s){let e="";for(;s>0;)e+=t,s--;return e}function Ei(t,s=!1){const e=ys-xt+1;let n=_i;s&&(n=xt);const r=String.fromCharCode(t%e+n),i=Math.floor(t/e)+1;return Xs(r,i)}function gi(t,s){return t.zIndex>s.zIndex?1:t.zIndex===s.zIndex?0:-1}function Ri(t,s){return t.zIndex>s.zIndex?-1:t.zIndex===s.zIndex?0:1}function ot(t="index",s=1){return(e,n)=>e[t]>n[t]?s:e[t]===n[t]?0:-s}function mi(t,s){let e;return function(...n){const r=this,i=function(){e=null,t.apply(r,n)};clearTimeout(e),e=setTimeout(i,s)}}function Lt(t,s,e){const{dataStream:n,textRuns:r=[]}=t;let i=s;const o=[];for(const a of r){const{st:l,ed:u}=a;R.hasIntersectionBetweenTwoRanges(s,e,l,u)&&(l>i?(o.push(n.slice(i,l)),o.push(oe(n,{...a,ed:Math.min(u,e)}))):o.push(oe(n,{...a,st:i,ed:Math.min(u,e)}))),i=Math.max(s,Math.min(u,e))}return i!==e&&o.push(n.slice(i,e)),o.join("")}function Ci(t,s=!0){var e;if(s&&((e=t.paragraphs)!=null&&e.length)){const{dataStream:n,paragraphs:r=[]}=t;let i="",o=-1;for(const a of r){const{startIndex:l,paragraphStyle:u={}}=a,{spaceAbove:c,spaceBelow:h,lineSpacing:_}=u,f=[];c!=null&&(typeof c=="number"?f.push(`margin-top: ${c}px`):f.push(`margin-top: ${c.v}px`)),h!=null&&(typeof h=="number"?f.push(`margin-bottom: ${h}px`):f.push(`margin-bottom: ${h.v}px`)),_!=null&&f.push(`line-height: ${_}`),l>o+1?i+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${Lt(t,o+1,l)}</p>`:i+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,o=l}return o!==n.length&&(i+=Lt(t,o,n.length)),i}else return Lt(t,0,t.dataStream.length)}function oe(t,s){const{st:e,ed:n,ts:r={}}=s,{ff:i,fs:o,it:a,bl:l,ul:u,st:c,ol:h,bg:_,cl:f,va:E}=r;let g=t.slice(e,n);const m=[];return a===C.TRUE&&(g=`<i>${g}</i>`),E===it.SUPERSCRIPT?g=`<sup>${g}</sup>`:E===it.SUBSCRIPT&&(g=`<sub>${g}</sub>`),(u==null?void 0:u.s)===C.TRUE&&(g=`<u>${g}</u>`),(c==null?void 0:c.s)===C.TRUE&&(g=`<s>${g}</s>`),l===C.TRUE&&(g=`<strong>${g}</strong>`),i&&m.push(`font-family: ${i}`),f&&m.push(`color: ${f.rgb}`),o&&m.push(`font-size: ${o}pt`),h&&m.push("text-decoration: overline"),_&&m.push(`background: ${_.rgb}`),m.length?`<span style="${m.join("; ")};">${g}</span>`:g}const lt={sheetId:"",range:{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1}},Oi={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1},Ii={startRow:0,startColumn:0,endRow:0,endColumn:0},Ai={row:0,column:0},Tt={ff:"Arial",fs:11,it:C.FALSE,bl:C.FALSE,ul:{s:C.FALSE},st:{s:C.FALSE},ol:{s:C.FALSE},tr:{a:0,v:C.FALSE},td:_t.UNSPECIFIED,cl:{rgb:"#000"},bg:{rgb:"#fff"},ht:Z.UNSPECIFIED,vt:rt.UNSPECIFIED,tb:ft.UNSPECIFIED,pd:{t:0,r:0,b:0,l:0}},qs={id:"default_slide",title:"defaultSlide",pageSize:{width:300,height:300}};var Js=(t=>(t.ARRAY_CONVERTOR="ARRAY_CONVERTOR",t.MATRIX_CONVERTOR="MATRIX_CONVERTOR",t))(Js||{});function At(t,s){const{textRuns:e=[]}=s;let n=0;for(const i of e){const{ts:o={},st:a,ed:l}=i;if(o[t]==null)return C.FALSE;switch(t){case"bl":case"it":{if(o[t]===C.FALSE)return C.FALSE;break}case"ul":case"st":{if(o[t].s===C.FALSE)return C.FALSE;break}default:throw new Error(`unknown style key: ${t} in IStyleBase`)}n+=l-a}return s.dataStream.indexOf(`\r
4
4
  `)===n?C.TRUE:C.FALSE}class et{constructor(s,e,n){d(this,"_range");d(this,"_worksheet");this._deps=n,this._range=e,this._worksheet=s}static foreach(s,e){const{startRow:n,startColumn:r,endRow:i,endColumn:o}=s;for(let a=n;a<=i;a++)for(let l=r;l<=o;l++)e(a,l)}getRangeData(){return this._range}getValue(){return this.getValues()[0][0]}getValues(){const{startRow:s,endRow:e,startColumn:n,endColumn:r}=this._range,i=[];for(let o=s;o<=e;o++){const a=[];for(let l=n;l<=r;l++)a.push(this.getMatrix().getValue(o,l)||null);i.push(a)}return i}getMatrix(){const{startRow:s,endRow:e,startColumn:n,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new G;for(let a=s;a<=e;a++)for(let l=n;l<=r;l++)o.setValue(a,l,i.getValue(a,l)||null);return o}getMatrixObject(){const{startRow:s,endRow:e,startColumn:n,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new G;for(let a=s;a<=e;a++)for(let l=n;l<=r;l++)o.setValue(a-s,l-n,i.getValue(a,l)||{});return o}getA1Notation(){const{startRow:s,endRow:e,startColumn:n,endColumn:r}=this._range;let i,o;return n<r?(i=R.numToWord(n+1)+(s+1),o=R.numToWord(r+1)+(e+1)):(i=R.numToWord(r+1)+(e+1),o=R.numToWord(n+1)+(s+1)),i===o?`${i}`:`${i}:${o}`}getBackground(){return this.getBackgrounds()[0][0]}getBackgrounds(){const s=this._deps.getStyles();return this.getValues().map(e=>e.map(n=>{var i;const r=s.getStyleByCell(n);return((i=r==null?void 0:r.bg)==null?void 0:i.rgb)||Tt.bg.rgb}))}getCell(s,e){const{startRow:n,endRow:r,startColumn:i,endColumn:o}=this._range,a={startRow:n+s,endRow:n+s,startColumn:i+e,endColumn:i+e};return new et(this._worksheet,a,this._deps)}getColumn(){return this._range.startColumn}getObjectValue(s={}){return this.getObjectValues(s)[0][0]}getObjectValues(s={}){var a;const{startRow:e,endRow:n,startColumn:r,endColumn:i}=this._range,o=this._worksheet.getCellMatrix().getFragment(e,n,r,i).getData();if(s.isIncludeStyle){const l=this._deps.getStyles();for(let u=0;u<=n-e;u++)for(let c=0;c<=i-r;c++){if(o==null||((a=o==null?void 0:o[u])==null?void 0:a[c])==null)continue;const h=o[u][c].s;h&&(o[u][c].s=l.get(h))}}return o}getFontColor(){return this.getFontColors()[0][0]}getFontColors(){const s=this._deps.getStyles();return this.getValues().map(e=>e.map(n=>{var i;const r=s.getStyleByCell(n);return((i=r==null?void 0:r.cl)==null?void 0:i.rgb)||Tt.cl.rgb}))}getFontFamilies(){return this._getStyles("ff")}getFontFamily(){return this.getFontFamilies()[0][0]}getUnderlines(){return this._getStyles("ul")}getUnderline(){var e,n;const{p:s}=(e=this.getValue())!=null?e:{};return s&&Array.isArray((n=s.body)==null?void 0:n.textRuns)&&s.body.textRuns.length>0?At("ul",s.body)===C.TRUE?{s:C.TRUE}:{s:C.FALSE}:this.getUnderlines()[0][0]}getOverlines(){return this._getStyles("ol")}getOverline(){return this.getOverlines()[0][0]}getStrikeThrough(){var e,n;const{p:s}=(e=this.getValue())!=null?e:{};return s&&Array.isArray((n=s.body)==null?void 0:n.textRuns)&&s.body.textRuns.length>0?At("st",s.body)===C.TRUE?{s:C.TRUE}:{s:C.FALSE}:this.getStrikeThroughs()[0][0]}getStrikeThroughs(){return this._getStyles("st")}getFontSize(){var e,n;const{p:s}=(e=this.getValue())!=null?e:{};return s&&Array.isArray((n=s.body)==null?void 0:n.textRuns)&&s.body.textRuns.length>0?s.body.textRuns.some(r=>{var i;return((i=r==null?void 0:r.ts)==null?void 0:i.fs)!=null})?Math.max(...s.body.textRuns.map(r=>{var i;return((i=r==null?void 0:r.ts)==null?void 0:i.fs)||0})):this.getFontSizes()[0][0]:this.getFontSizes()[0][0]}getFontSizes(){return this._getStyles("fs")}getBorder(){return this.getBorders()[0][0]}getBorders(){return this._getStyles("bd")}getFontStyle(){var e,n;const{p:s}=(e=this.getValue())!=null?e:{};return s&&Array.isArray((n=s.body)==null?void 0:n.textRuns)&&s.body.textRuns.length>0?At("it",s.body)===C.TRUE?Dt.ITALIC:Dt.NORMAL:this._getFontStyles()[0][0]}_getFontStyles(){return this._getStyles("it")}getFontWeight(){var e,n;const{p:s}=(e=this.getValue())!=null?e:{};return s&&Array.isArray((n=s.body)==null?void 0:n.textRuns)&&s.body.textRuns.length>0?At("bl",s.body)===C.TRUE?pt.BOLD:pt.NORMAL:this._getFontWeights()[0][0]}_getFontWeights(){return this._getStyles("bl")}getGridId(){return this._worksheet.getSheetId()}getHeight(){const{_range:s,_worksheet:e}=this,{startRow:n,endRow:r}=s;let i=0;for(let o=0;o<=r-n;o++){const a=e.getRowHeight(o);i+=a}return i}getHorizontalAlignment(){return this.getHorizontalAlignments()[0][0]}getHorizontalAlignments(){return this._getStyles("ht")}getLastColumn(){return this._range.endColumn}getLastRow(){return this._range.endRow}getNumColumns(){const{startColumn:s,endColumn:e}=this._range;return e-s+1}getNumRows(){const{startRow:s,endRow:e}=this._range;return e-s+1}getRichTextValue(){return this.getRichTextValues()[0][0]}getRichTextValues(){return this.getValues().map(s=>s.map(e=>(e==null?void 0:e.p)||""))}getRowIndex(){return this._range.startRow}getSheet(){return this._worksheet}getTextDirection(){return this.getTextDirections()[0][0]}getTextDirections(){return this._getStyles("td")}getTextRotation(){return this.getTextRotations()[0][0]}getTextRotations(){return this._getStyles("tr")}getTextStyle(){return this.getTextStyles()[0][0]}getTextStyles(){const s=this._deps.getStyles();return this.getValues().map(e=>e.map(n=>s.getStyleByCell(n)))}getVerticalAlignment(){return this.getVerticalAlignments()[0][0]}getVerticalAlignments(){return this._getStyles("vt")}getWidth(){const{_range:s,_worksheet:e}=this,{startColumn:n,endColumn:r}=s;let i=0;for(let o=0;o<=r-n;o++)i+=e.getColumnWidth(o);return i}getWrap(){return this.getWraps()[0][0]}getWraps(){return this._getStyles("tb")}getWrapStrategies(){return this._getStyles("tb")}getWrapStrategy(){return this.getWrapStrategies()[0][0]}forEach(s){et.foreach(this._range,s)}_getStyles(s){const e=this._deps.getStyles();return this.getValues().map(n=>n.map(r=>{const i=e&&e.getStyleByCell(r);return i&&i[s]||Tt[s]}))}}function Ni(t,s){if(t.length===0||t[0].length===0)return null;const e=new Array(t[0].length).fill(0);let n=0,r=null;for(let i=0;i<t.length;i++){for(let a=0;a<t[0].length;a++)e[a]=s(t[i][a])?e[a]+1:0;const o=Si(e);o.area>n&&(n=o.area,r={startColumn:o.start,startRow:i-o.height+1,endColumn:o.end,endRow:i})}return r}function Si(t){const s=[];let e=0,n={area:0,height:0,start:0,end:0},r=0;for(;r<t.length;)if(s.length===0||t[r]>=t[s[s.length-1]])s.push(r++);else{const i=t[s.pop()],o=s.length===0?r:r-s[s.length-1]-1;i*o>e&&(e=i*o,n={area:e,height:i,start:s.length===0?0:s[s.length-1]+1,end:r-1})}for(;s.length>0;){const i=t[s.pop()],o=s.length===0?r:r-s[s.length-1]-1;i*o>e&&(e=i*o,n={area:e,height:i,start:s.length===0?0:s[s.length-1]+1,end:r-1})}return n}function Li(t,s){et.foreach(s,(e,n)=>{t[e][n]=void 0})}function Ti(t,s){const e=t.toFullArray(),n=[];for(;;){const r=Ni(e,s);if(!r)break;n.push(r),Li(e,r)}return n}function bi(t,s,e,n=!1){let r={...t};const i=r.startAbsoluteRefType||w.NONE,o=r.endAbsoluteRefType||w.NONE;return!n&&i===w.ALL&&o===w.ALL?r:n||i===w.NONE&&o===w.NONE?X.moveOffset(r,s,e):(i===w.NONE?r={...r,startRow:r.startRow+e,startColumn:r.startColumn+s}:i===w.COLUMN?r={...r,startRow:r.startRow+e}:i===w.ROW&&(r={...r,startColumn:r.startColumn+s}),o===w.NONE?r={...r,endRow:r.endRow+e,endColumn:r.endColumn+s}:o===w.COLUMN?r={...r,endRow:r.endRow+e}:o===w.ROW&&(r={...r,endColumn:r.endColumn+s}),r)}var B=(t=>(t[t.UNDEFINED=0]="UNDEFINED",t[t.OK=1]="OK",t[t.INTERNAL_ERROR=2]="INTERNAL_ERROR",t[t.PERMISSION_DENIED=3]="PERMISSION_DENIED",t[t.NOT_FOUND=4]="NOT_FOUND",t[t.UNAUTHENTICATED=5]="UNAUTHENTICATED",t[t.ALREADY_EXISTS=6]="ALREADY_EXISTS",t[t.INVALID_ARGUMENT=7]="INVALID_ARGUMENT",t[t.TOO_MANY_REQUESTS=8]="TOO_MANY_REQUESTS",t[t.CHANGESET_REVISION_CONFILICT=5001]="CHANGESET_REVISION_CONFILICT",t[t.SNAPSHOT_INVALID_SNAPSHOT=6001]="SNAPSHOT_INVALID_SNAPSHOT",t[t.APPLY_REJECT=7001]="APPLY_REJECT",t[t.APPLY_NON_SEQUENTIAL_REVISION=7002]="APPLY_NON_SEQUENTIAL_REVISION",t[t.APPLY_REVISION_CONFILICT=7003]="APPLY_REVISION_CONFILICT",t[t.CONNECTOR_DATA_TOO_LARGE=8001]="CONNECTOR_DATA_TOO_LARGE",t[t.LICENSE_MAX_UNITS_EXCEEDED=9001]="LICENSE_MAX_UNITS_EXCEEDED",t[t.LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED=9002]="LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED",t[t.LICENSE_IMPORT_SIZE_EXCEEDED=9003]="LICENSE_IMPORT_SIZE_EXCEEDED",t[t.LICENSE_EXPORT_SIZE_EXCEEDED=9004]="LICENSE_EXPORT_SIZE_EXCEEDED",t[t.LICENSE_DISTRO_REJECTED=9005]="LICENSE_DISTRO_REJECTED",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(B||{});function Zs(t){return!!(t&&t.code&&t.code!==B.OK&&t.code!=="OK")}var O=(t=>(t[t.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",t[t.UNIVER_DOC=1]="UNIVER_DOC",t[t.UNIVER_SHEET=2]="UNIVER_SHEET",t[t.UNIVER_SLIDE=3]="UNIVER_SLIDE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(O||{});class Vt extends p{}class Re{constructor(){d(this,"_data",[])}static create(){return new Re}add(s){this._data.indexOf(s)>-1||this._data.push(s)}delete(s){const e=this._data.indexOf(s);this._data.splice(e,1)}getData(){return this._data}}class me{constructor(){d(this,"_data",new Map)}static create(){return new me}add(s,e){this._data.has(s)||this._data.set(s,e)}delete(s){this._data.delete(s)}getData(){return this._data}}class Qs{constructor(){d(this,"cursor",0)}reset(){return this.cursor=0,this}moveCursor(s){this.cursor+=s}moveCursorTo(s){this.cursor=s}}var tn=(t=>(t[t.PARAGRAPH=0]="PARAGRAPH",t[t.SECTION_BREAK=1]="SECTION_BREAK",t[t.TABLE=2]="TABLE",t[t.TABLE_ROW=3]="TABLE_ROW",t[t.TABLE_CELL=4]="TABLE_CELL",t))(tn||{}),Ce=(t=>(t.PARAGRAPH="\r",t.SECTION_BREAK=`
5
5
  `,t.TABLE_START="",t.TABLE_ROW_START="\x1B",t.TABLE_CELL_START="",t.TABLE_CELL_END="",t.TABLE_ROW_END="",t.TABLE_END="",t.CUSTOM_RANGE_START="",t.CUSTOM_RANGE_END="",t.COLUMN_BREAK="\v",t.PAGE_BREAK="\f",t.DOCS_END="\0",t.TAB=" ",t.CUSTOM_BLOCK="\b",t.LETTER="",t.SPACE=" ",t))(Ce||{});function Oe(t){const s=[];for(const e of t){const{st:n,ed:r,ts:i}=e;if(e.sId===void 0&&delete e.sId,n===r||R.isEmptyObject(i)&&e.sId==null)continue;if(s.length===0){s.push(e);continue}const o=s.pop();Hs(e,o)&&R.hasIntersectionBetweenTwoRanges(o.st,o.ed,e.st,e.ed)?s.push({...e,st:o.st,ed:r}):s.push(o,e)}return s}function en(t,s,e,n){var u;const{textRuns:r}=t;if(r==null)return;const i=[],o=r.length;let a=!1;const l=(u=s.textRuns)!=null?u:[];if(l.length)for(let c=0,h=l.length;c<h;c++){const _=l[c];_.st+=n,_.ed+=n}for(let c=0;c<o;c++){const h=r[c],{st:_,ed:f}=h;if(f<n)i.push(h);else if(n>=_&&n<=f)if(a)h.st+=e,h.ed+=e,i.push(h);else{a=!0,h.ed+=e;const E=[];if(l.length){const g={...h,st:_,ed:l[0].st};E.push(g),E.push(...l);const m=l[l.length-1],N={...h,st:m.ed,ed:f+e};E.push(N)}else E.push(h);i.push(...E)}else h.st+=e,h.ed+=e,a||(a=!0,i.push(...l)),i.push(h)}a||(a=!0,i.push(...l)),t.textRuns=Oe(i)}function Ie(t,s,e,n){const{paragraphs:r}=t;if(r==null)return;const{paragraphs:i,dataStream:o}=s,a=[];let l=-1;for(let c=0,h=r.length;c<h;c++){const _=r[c],{startIndex:f}=_;f>=n&&(_.startIndex+=e),l===-1&&f>=n&&(l=c),a.push(_.startIndex)}let u=-1;if(i){for(let c=0,h=i.length;c<h;c++){const _=i[c];_.startIndex+=n;const f=_.startIndex;u=a.indexOf(f)}if(o===Ce.PARAGRAPH&&i.length===1){const c=r[l],h=i[0],_=c.paragraphStyle,f=c.bullet;c.paragraphStyle=h.paragraphStyle,c.bullet=h.bullet,h.paragraphStyle=_,h.bullet=f}u!==-1&&r.splice(u,1),r.push(...i),r.sort(ot("startIndex"))}}function wi(t,s,e,n){const{sectionBreaks:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:u}=l;u>=n&&(l.startIndex+=e)}const i=s.sectionBreaks;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=n}r.push(...i),r.sort(ot("startIndex"))}}function sn(t,s,e,n){const{customBlocks:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:u}=l;u>=n&&(l.startIndex+=e)}const i=s.customBlocks;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=n}r.push(...i),r.sort(ot("startIndex"))}}function Ae(t,s,e,n){const{tables:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:u,endIndex:c}=l;u>n?(l.startIndex+=e,l.endIndex+=e):c>=n-1&&(l.endIndex+=e)}const i=s.tables;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=n,l.endIndex+=n}r.push(...i),r.sort(ot("startIndex"))}}function vi(t,s,e,n){const{customRanges:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:u,endIndex:c}=l;u>n?(l.startIndex+=e,l.endIndex+=e):c>=n-1&&(l.endIndex+=e)}const i=s.customRanges;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=n,l.endIndex+=n}r.push(...i),r.sort(ot("startIndex"))}}function nn(t,s,e){const{textRuns:n}=t,r=e,i=e+s,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{st:h,ed:_}=c;if(r<=h&&i>=_){o.push({...c,st:h-r,ed:_-r});continue}else h<=r&&_>=i?(o.push({...c,st:r-r,ed:i-r}),c.ed-=s):r>=h&&r<_?(o.push({...c,st:r-r,ed:_-r}),c.ed=r):i>h&&i<=_?(o.push({...c,st:h-r,ed:i-r}),c.st=i-s,c.ed-=s):h>=i&&(c.st-=s,c.ed-=s);a.push(c)}t.textRuns=a}return o}function rn(t,s,e){const{paragraphs:n}=t,r=e,i=e+s,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{startIndex:h}=c;if(h>=r&&h<i){o.push({...c,startIndex:h-e});continue}else h>=i&&(c.startIndex-=s);a.push(c)}t.paragraphs=a}return o}function on(t,s,e){const{sectionBreaks:n}=t,r=e,i=e+s-1,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{startIndex:h}=c;if(h>=r&&h<=i){o.push({...c,startIndex:h-e});continue}else h>i&&(c.startIndex-=s);a.push(c)}t.sectionBreaks=a}return o}function an(t,s,e){const{customBlocks:n}=t,r=e,i=e+s-1,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{startIndex:h}=c;if(h>=r&&h<=i){o.push({...c,startIndex:h-e});continue}else h>i&&(c.startIndex-=s);a.push(c)}t.customBlocks=a}return o}function ln(t,s,e){const{tables:n}=t,r=e,i=e+s-1,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{startIndex:h,endIndex:_}=c;if(r<=h&&i>=_){o.push({...c,startIndex:h-e,endIndex:_-e});continue}else if(h<=r&&_>=i){const f=fe(h,_,r,i);c.startIndex=f[0],c.endIndex=f[1]}else i<h&&(c.startIndex-=s,c.endIndex-=s);a.push(c)}t.tables=a}return o}function un(t,s,e){const{customRanges:n}=t,r=e,i=e+s-1,o=[];if(n){const a=[];for(let l=0,u=n.length;l<u;l++){const c=n[l],{startIndex:h,endIndex:_}=c;if(r<=h&&i>=_){o.push({...c,startIndex:h-e,endIndex:_-e});continue}else if(h<=r&&_>=i){const f=fe(h,_,r,i);c.startIndex=f[0],c.endIndex=f[1]}else i<h&&(c.startIndex-=s,c.endIndex-=s);a.push(c)}t.customRanges=a}return o}function Ui(t,s,e){const{dataStream:n}=t,r=e,i=e+s,o=nn(t,s,e),a=rn(t,s,e),l=on(t,s,e),u=an(t,s,e),c=ln(t,s,e),h=un(t,s,e);let _="";return n&&(t.dataStream=Bs(n,r,i),_=n.slice(r,i)),{dataStream:_,textRuns:o,paragraphs:a,sectionBreaks:l,customBlocks:u,tables:c,customRanges:h}}function Di(t,s,e,n){t.dataStream=Ws(t.dataStream,n,s.dataStream),en(t,s,e,n),Ie(t,s,e,n),wi(t,s,e,n),sn(t,s,e,n),Ae(t,s,e,n),vi(t,s,e,n)}var Ht=(t=>(t.BULLET_LIST="BULLET_LIST",t.ORDER_LIST="ORDER_LIST",t))(Ht||{});const pi={BULLET_LIST:{listType:"BULLET_LIST",nestingLevel:[{bulletAlignment:K.START,glyphFormat:" %0",textStyle:{fs:12},startNumber:0,glyphSymbol:"●",hanging:21,indentStart:21},{bulletAlignment:K.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"■",hanging:21,indentStart:42},{bulletAlignment:K.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"◆",hanging:21,indentStart:63}]},ORDER_LIST:{listType:"ORDER_LIST",nestingLevel:[{bulletAlignment:K.START,glyphFormat:" %1.",textStyle:{fs:12},startNumber:0,glyphType:ut.DECIMAL,hanging:21,indentStart:21},{bulletAlignment:K.START,glyphFormat:" %1.%2)",textStyle:{fs:12},startNumber:0,glyphType:ut.DECIMAL,hanging:21,indentStart:42},{bulletAlignment:K.START,glyphFormat:" %1.%2.%3.",textStyle:{fs:12},startNumber:0,glyphType:ut.DECIMAL,hanging:21,indentStart:63}]}};function Mi(t,s,e,n,r){const i=Pi(t,s,e,n,r),o=xi(t,s,e,n,r),a=Hi(t,s,e,n,r),l=Fi(t,s,e,n,r),u=Wi(t,s,e,n,r),c=Bi(t,s,e,n,r);return{dataStream:"",textRuns:i,paragraphs:o,sectionBreaks:a,customBlocks:l,tables:u,customRanges:c}}function Pi(t,s,e,n,r){const{textRuns:i}=t,{textRuns:o}=s;if(i==null||o==null)return;const a=nn(t,e,n);if(r!==P.REPLACE){const l=cn(o,a,r);s.textRuns=l}return en(t,s,e,n),a}function cn(t,s,e){if(s.length===0)return t;t=R.deepClone(t),s=R.deepClone(s);const n=[],r=t.length,i=s.length;let o=0,a=0,l=null;function u(){return l?(n.push(l),l=null,!0):!1}for(;o<r&&a<i;){const{st:f,ed:E,ts:g}=t[o],{st:m,ed:N,ts:U,sId:M}=s[a];let V;e===P.COVER?V={...U,...g}:V={...g,...U},E<m?(u()||n.push(t[o]),o++):N<f?(u()||n.push(s[a]),a++):(n.push({st:Math.min(f,m),ed:Math.max(f,m),ts:f<m?{...g}:{...U},sId:f<m?void 0:M}),n.push({st:Math.max(f,m),ed:Math.min(E,N),ts:V,sId:M}),E<N?(o++,s[a].st=E):(a++,t[o].st=N),l={st:Math.min(E,N),ed:Math.max(E,N),ts:E<N?{...U}:{...g},sId:E<N?M:void 0})}u();const c=n[n.length-1],h=t[r-1],_=s[i-1];return c.ed!==Math.max(h.ed,_.ed)&&(h.ed>_.ed?n.push(h):n.push(_)),Oe(n)}function xi(t,s,e,n,r){const{paragraphs:i}=t,{paragraphs:o}=s;if(i==null||o==null)return;const a=rn(t,e,n);if(r!==P.REPLACE){const l=[];for(const u of o){const{startIndex:c,paragraphStyle:h,bullet:_}=u;let f=[];for(const E of a){const{startIndex:g,paragraphStyle:m,bullet:N}=E;let U,M;if(r===P.COVER?(U={...m,...h},M={listId:"",listType:Ht.BULLET_LIST,nestingLevel:0,textStyle:{},...N,..._}):(U={...h,...m},M={listId:"",listType:Ht.BULLET_LIST,nestingLevel:0,textStyle:{},..._,...N}),c===g){f.push({startIndex:c,paragraphStyle:U,bullet:M});break}}l.push(...f),f=[]}s.paragraphs=l}return Ie(t,s,e,n),a}function Hi(t,s,e,n,r){const{sectionBreaks:i}=t,{sectionBreaks:o}=s;if(i==null||o==null)return;const a=on(t,e,n);if(r!==P.REPLACE){const l=[];for(const u of o){const{startIndex:c}=u;let h=[];for(const _ of a){const{startIndex:f}=_;if(c===f){r===P.COVER?h.push({..._,...u}):h.push({...u,..._});break}}l.push(...h),h=[]}s.sectionBreaks=l}return Ie(t,s,e,n),a}function Fi(t,s,e,n,r){const{customBlocks:i}=t,{customBlocks:o}=s;if(i==null||o==null)return;const a=an(t,e,n);if(r!==P.REPLACE){const l=[];for(const u of o){const{startIndex:c}=u;let h=[];for(const _ of a){const{startIndex:f}=_;if(c===f){r===P.COVER?h.push({..._,...u}):h.push({...u,..._});break}}l.push(...h),h=[]}s.customBlocks=l}return sn(t,s,e,n),a}function Wi(t,s,e,n,r){const{tables:i}=t,{tables:o}=s;if(i==null||o==null)return;const a=ln(t,e,n);if(r!==P.REPLACE){const l=[];for(const u of o){const{startIndex:c,endIndex:h}=u;let _=[];for(const f of a){const{startIndex:E,endIndex:g}=f;if(E>=c&&g<=h){r===P.COVER?_.push({...f,...u}):_.push({...u,...f});break}}l.push(..._),_=[]}s.tables=l}return Ae(t,s,e,n),a}function Bi(t,s,e,n,r){const{customRanges:i}=t,{tables:o}=s;if(i==null||o==null)return;const a=un(t,e,n);if(r!==P.REPLACE){const l=[];for(const u of o){const{startIndex:c,endIndex:h}=u;let _=[];for(const f of a){const{startIndex:E,endIndex:g}=f;if(E>=c&&g<=h){r===P.COVER?_.push({...f,...u}):_.push({...u,...f});break}}l.push(..._),_=[]}s.customRanges=l}return Ae(t,s,e,n),a}var I=(t=>(t.RETAIN="r",t.INSERT="i",t.DELETE="d",t))(I||{});function Ne(t,s,e){const{dataStream:n,textRuns:r=[],paragraphs:i=[]}=t,o={dataStream:n.slice(s,e)},a=[];for(const u of r){const c=R.deepClone(u),{st:h,ed:_}=c;R.hasIntersectionBetweenTwoRanges(h,_,s,e)&&(s>=h&&s<=_?a.push({...c,st:s,ed:Math.min(e,_)}):e>=h&&e<=_?a.push({...c,st:Math.max(s,h),ed:e}):a.push(c))}a.length&&(o.textRuns=a.map(u=>{const{st:c,ed:h}=u;return{...u,st:c-s,ed:h-s}}));const l=[];for(const u of i){const{startIndex:c}=u;c>=s&&c<=e&&l.push(R.deepClone(u))}return l.length&&(o.paragraphs=l.map(u=>({...u,startIndex:u.startIndex-s}))),o}function ae(t,s,e=P.COVER){if(s.dataStream!=="")throw new Error("Cannot compose other body with non-empty dataStream");const n={dataStream:t.dataStream},{textRuns:r=[],paragraphs:i=[]}=t,{textRuns:o=[],paragraphs:a=[]}=s,l=cn(o,r,e);l.length&&(n.textRuns=l);const u=[];let c=0,h=0;for(;c<i.length&&h<a.length;){const _=i[c],f=a[h],{startIndex:E}=_,{startIndex:g}=f;E===g?(u.push(R.deepMerge(_,f)),c++,h++):E<g?(u.push(R.deepClone(_)),c++):(u.push(R.deepClone(f)),h++)}return c<i.length&&u.push(...i.slice(c)),h<a.length&&u.push(...a.slice(h)),u.length&&(n.paragraphs=u),n}function ki(t){const{body:s}=t;if(s==null)return!0;const{textRuns:e=[],paragraphs:n=[]}=s;return e.length===0&&n.length===0}function Gi(t=R.generateRandomId(6),s=nt.EN_US,e=""){return{id:t,locale:s,title:e,body:{dataStream:`\r
6
- `,textRuns:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:5,lineSpacing:1,spaceBelow:0}}],sectionBreaks:[{startIndex:1}]},documentStyle:{pageSize:{width:793.3333333333334,height:1122.6666666666667},marginTop:50,marginBottom:50,marginRight:40,marginLeft:40,renderConfig:{vertexAngle:0,centerAngle:0}},settings:{}}}const Se={id:"default_doc",documentStyle:{}};class $i extends Vt{constructor(e){super();d(this,"type",O.UNIVER_DOC);d(this,"snapshot");this.snapshot={...Se,...e}}getUnitId(){throw new Error("Method not implemented.")}get drawings(){return this.snapshot.drawings}get documentStyle(){return this.snapshot.documentStyle}get lists(){return this.snapshot.lists}get body(){return this.snapshot.body}get zoomRatio(){var e;return((e=this.snapshot.settings)==null?void 0:e.zoomRatio)||1}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getParentRenderUnitId(){return this.snapshot.parentRenderUnitId}getSnapshot(){return this.snapshot}updateDocumentId(e){this.snapshot.id=e}updateDocumentRenderConfig(e){const{documentStyle:n}=this.snapshot;n.renderConfig==null?n.renderConfig=e:n.renderConfig={...n.renderConfig,...e}}updateDocumentStyle(e){this.snapshot.documentStyle==null?this.snapshot.documentStyle=e:this.snapshot.documentStyle={...this.snapshot.documentStyle,...e}}updateDocumentDataMargin(e){const{t:n,l:r,b:i,r:o}=e,{documentStyle:a}=this.snapshot;n!=null&&(a.marginTop=n),r!=null&&(a.marginLeft=r),i!=null&&(a.marginBottom=i),o!=null&&(a.marginRight=o)}updateDocumentDataPageSize(e,n){const{documentStyle:r}=this.snapshot;if(!r.pageSize){e=e!=null?e:Number.POSITIVE_INFINITY,n=n!=null?n:Number.POSITIVE_INFINITY,r.pageSize={width:e,height:n};return}e!==void 0&&(r.pageSize.width=e),n!==void 0&&(r.pageSize.height=n)}updateDrawing(e,n){const{drawings:r}=this,{width:i,height:o,left:a,top:l}=n,u=r==null?void 0:r[e];if(!u)return;const c=u.objectTransform;c.size.width=i,c.size.height=o,c.positionH.posOffset=a,c.positionV.posOffset=l}setZoomRatio(e=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:e}:this.snapshot.settings.zoomRatio=1}}class st extends $i{constructor(e){var r;super(R.isEmptyObject(e)?Gi():e);d(this,"_unitId");d(this,"headerModelMap",new Map);d(this,"footerModelMap",new Map);const n=6;this._unitId=(r=this.snapshot.id)!=null?r:R.generateRandomId(n),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(e=>{e.dispose()}),this.footerModelMap.forEach(e=>{e.dispose()})}getRev(){var e;return(e=this.snapshot.rev)!=null?e:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(e){if(e.id&&e.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Se,...e},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(e){if(e!=null){if(this.headerModelMap.has(e))return this.headerModelMap.get(e);if(this.footerModelMap.has(e))return this.footerModelMap.get(e)}return this}getUnitId(){return this._unitId}apply(e){const n=[],r=new Qs;return r.reset(),e.forEach(i=>{if(i=R.deepClone(i),i.t===I.RETAIN){const{coverType:o,body:a,len:l,segmentId:u}=i;if(a!=null){const c=this._updateApply(a,l,r.cursor,o,u);n.push({...i,t:I.RETAIN,coverType:P.REPLACE,body:c})}else n.push({...i,t:I.RETAIN});r.moveCursor(l)}else if(i.t===I.INSERT){const{body:o,len:a,segmentId:l,line:u}=i;this._insertApply(o,a,r.cursor,l),r.moveCursor(a),n.push({t:I.DELETE,len:a,line:u,segmentId:l})}else if(i.t===I.DELETE){const{len:o,segmentId:a}=i,l=this._deleteApply(o,r.cursor,a);n.push({...i,t:I.INSERT,body:l})}else throw new Error(`Unknown action type for action: ${i}.`)}),n}sliceBody(e,n){const r=this.getBody();if(r!=null)return Ne(r,e,n)}_updateApply(e,n,r,i=P.COVER,o){if(e==null)throw new Error("updateBody is none");const a=this.snapshot,l=St(a,o);if(l==null)throw new Error("no body has changed");return Mi(l,e,n,r,i)}_deleteApply(e,n,r){const i=this.snapshot,o=St(i,r);if(o==null)throw new Error("no body has changed");return e<=0?{dataStream:""}:Ui(o,e,n)}_insertApply(e,n,r,i){const o=this.snapshot,a=St(o,i);if(n!==0){if(a==null)throw new Error("no body has changed");Di(a,e,n,r)}}_initializeHeaderFooterModel(){const{headers:e,footers:n}=this.getSnapshot();if(e)for(const r in e){const i=e[r];this.headerModelMap.set(r,new st(i))}if(n)for(const r in n){const i=n[r];this.footerModelMap.set(r,new st(i))}}updateDocumentId(e){super.updateDocumentId(e),this._unitId=e}}async function hn(t){for(const[s,e]of t.entries())try{if(!await e())return{index:s,result:!1}}catch(n){return{index:s,result:!1,error:n}}return{result:!0,index:-1}}function dn(t){for(const[s,e]of t.entries())try{if(!e())return{index:s,result:!1}}catch(n){return{index:s,result:!1,error:n}}return{result:!0,index:-1}}const gt=A.createIdentifier("univer.context-service");class _n extends p{constructor(){super(...arguments);d(this,"_contextChanged$",new L.Subject);d(this,"contextChanged$",this._contextChanged$.asObservable());d(this,"_contextMap",new Map)}dispose(){super.dispose(),this._contextChanged$.complete()}getContextValue(e){var n;return(n=this._contextMap.get(e))!=null?n:!1}setContextValue(e,n){this._contextMap.set(e,n),this._contextChanged$.next({[e]:n})}subscribeContextValue$(e){return new L.Observable(n=>{const r=this._contextChanged$.pipe(L.filter(i=>typeof i[e]<"u")).subscribe(i=>n.next(i[e]));return this._contextMap.has(e)&&n.next(this._contextMap.get(e)),()=>r.unsubscribe()})}}var fn=(t=>(t[t.SILENT=0]="SILENT",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.VERBOSE=4]="VERBOSE",t))(fn||{});const J=A.createIdentifier("univer.log");class En extends p{constructor(){super(...arguments);d(this,"_logLevel",3)}debug(...e){this._logLevel>=4&&this._log(console.debug,...e)}log(...e){this._logLevel>=3&&this._log(console.log,...e)}warn(...e){this._logLevel>=2&&this._log(console.warn,...e)}error(...e){this._logLevel>=1&&this._log(console.error,...e)}setLogLevel(e){this._logLevel=e}_log(e,...n){const r=n[0];/^\[(.*?)\]/g.test(r)?e(`\x1B[97;104m${r}\x1B[0m`,...n.slice(1)):e(...n)}}var Vi=Object.defineProperty,ji=Object.getOwnPropertyDescriptor,Ki=(t,s,e,n)=>{for(var r=n>1?void 0:n?ji(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Vi(s,e,r),r},We=(t,s)=>(e,n)=>s(e,n,t),jt=(t=>(t[t.COMMAND=0]="COMMAND",t[t.OPERATION=1]="OPERATION",t[t.MUTATION=2]="MUTATION",t))(jt||{});const Rt=A.createIdentifier("anywhere.command-service");class Yi{constructor(){d(this,"_commands",new Map)}registerCommand(s){if(this._commands.has(s.id))throw new Error(`[CommandRegistry]: command "${s.id}" has been registered before.`);return this._commands.set(s.id,s),v(()=>{var e;this._commands.delete(s.id),(e=s.onDispose)==null||e.call(s)})}hasCommand(s){return this._commands.has(s)}getCommand(s){return this._commands.has(s)?[this._commands.get(s)]:null}}const gn={id:"nil",type:0,handler:()=>!0};exports.CommandService=class{constructor(s,e){d(this,"_commandRegistry");d(this,"_beforeCommandExecutionListeners",[]);d(this,"_commandExecutedListeners",[]);d(this,"_multiCommandDisposables",new Map);d(this,"_commandExecutingLevel",0);d(this,"_commandExecutionStack",[]);this._injector=s,this._logService=e,this._commandRegistry=new Yi,this._registerCommand(gn)}hasCommand(s){return this._commandRegistry.hasCommand(s)}registerCommand(s){return this._registerCommand(s)}registerMultipleCommand(s){return this._registerMultiCommand(s)}beforeCommandExecuted(s){if(this._beforeCommandExecutionListeners.indexOf(s)===-1)return this._beforeCommandExecutionListeners.push(s),v(()=>{const e=this._beforeCommandExecutionListeners.indexOf(s);this._beforeCommandExecutionListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}onCommandExecuted(s){if(this._commandExecutedListeners.indexOf(s)===-1)return this._commandExecutedListeners.push(s),v(()=>{const e=this._commandExecutedListeners.indexOf(s);this._commandExecutedListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}async executeCommand(s,e,n){const r=this._commandRegistry.getCommand(s);if(r){const[i]=r,o={id:i.id,type:i.type,params:e},a=this._pushCommandExecutionStack(o);this._beforeCommandExecutionListeners.forEach(u=>u(o,n));const l=await this._execute(i,e,n);return this._commandExecutedListeners.forEach(u=>u(o,n)),a.dispose(),l}throw new Error(`[CommandService]: command "${s}" is not registered.`)}syncExecuteCommand(s,e,n){var i;const r=this._commandRegistry.getCommand(s);if(r){const[o]=r,a={id:o.id,type:o.type,params:e};if(o.type===2){const c=ni(this._commandExecutionStack,h=>h.type===0);c&&(a.params=(i=a.params)!=null?i:{},a.params.trigger=c.id)}const l=this._pushCommandExecutionStack(a);this._beforeCommandExecutionListeners.forEach(c=>c(a,n));const u=this._syncExecute(o,e,n);return this._commandExecutedListeners.forEach(c=>c(a,n)),l.dispose(),u}throw new Error(`[CommandService]: command "${s}" is not registered.`)}_pushCommandExecutionStack(s){return this._commandExecutionStack.push(s),v(()=>$t(this._commandExecutionStack,s))}_registerCommand(s){return this._commandRegistry.registerCommand(s)}_registerMultiCommand(s){const e=this._commandRegistry.getCommand(s.id);let n;if(e){if(e[0].multi!==!0)throw new Error("Command has registered as a single command.");n=e[0]}else{const i=new Ee;n=new zi(s.id),i.add(this._commandRegistry.registerCommand(n)),i.add(v(()=>{this._multiCommandDisposables.delete(s.id)})),this._multiCommandDisposables.set(s.id,i)}const r=n.registerImplementation(s);return v(()=>{var i;r.dispose(),n.hasImplementations()||(i=this._multiCommandDisposables.get(s.id))==null||i.dispose()})}async _execute(s,e,n){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(this._commandExecutingLevel,0))}executing command "${s.id}"`),this._commandExecutingLevel++;let r;try{r=await this._injector.invoke(s.handler,e,n),this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}_syncExecute(s,e,n){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(0,this._commandExecutingLevel))}executing command "${s.id}".`),this._commandExecutingLevel++;let r;try{if(r=this._injector.invoke(s.handler,e,n),r instanceof Promise)throw new TypeError("[CommandService]: Command handler should not return a promise.");this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}};exports.CommandService=Ki([We(0,A.Inject(A.Injector)),We(1,J)],exports.CommandService);class zi{constructor(s){d(this,"name");d(this,"multi",!0);d(this,"type",0);d(this,"priority",0);d(this,"_implementations",[]);d(this,"handler",async(s,e)=>{if(!this._implementations.length)return!1;const n=s.get(J),r=s.get(gt),i=s.get(A.Injector);for(const o of this._implementations){const a=o.command.preconditions;if((!a||a&&a(r))&&(n.debug("[MultiCommand]",`executing implementation "${o.command.name}".`),await i.invoke(o.command.handler,e)))return!0}return!1});this.id=s,this.name=s}registerImplementation(s){const e={command:s};return this._implementations.push(e),this._implementations.sort((n,r)=>r.command.priority-n.command.priority),v(()=>{var r;const n=this._implementations.indexOf(e);this._implementations.splice(n,1),(r=s.onDispose)==null||r.call(s)})}hasImplementations(){return this._implementations.length>0}}function Le(t,s,e){const n=t.map(r=>()=>s.syncExecuteCommand(r.id,r.params,e));return dn(n)}function yi(t,s,e){const n=t.map(r=>()=>s.executeCommand(r.id,r.params,e));return hn(n)}const Rn=A.createIdentifier("univer.config-service");class mn{constructor(){d(this,"_config",new Map)}getConfig(s){return this._config.get(s)}setConfig(s,e){this._config.set(s,e)}deleteConfig(s){this._config.delete(s)}}class Cn extends p{constructor(){super(...arguments);d(this,"_error$",new L.Subject);d(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(e){this._error$.next({errorKey:e})}}const Xi="__default_document_sub_component_id20231101__";class On{constructor(){d(this,"_managerInfo",new Map);d(this,"_remove$",new L.Subject);d(this,"remove$",this._remove$.asObservable());d(this,"_andOrUpdate$",new L.Subject);d(this,"andOrUpdate$",this._andOrUpdate$.asObservable());d(this,"_pluginUpdate$",new L.Subject);d(this,"pluginUpdate$",this._pluginUpdate$.asObservable())}getFloatObject(s){return this._getFloatingObject(s)}getFloatObjects(s){return this._getFloatingObjects(s)}dispose(){this._remove$.complete(),this._andOrUpdate$.complete(),this._pluginUpdate$.complete(),this._managerInfo.clear()}clear(s){const e=this._clearByParam(s);this._remove$.next(e)}addOrUpdate(s){const e=this._addByParam(s);this._andOrUpdate$.next(e)}BatchAddOrUpdate(s){const e=[];s.forEach(n=>{e.push(...this._addByParam(n))}),this._andOrUpdate$.next(e)}remove(s){const e=this._removeByParam(s);this._remove$.next(e)}pluginUpdateRefresh(s){this._pluginUpdate$.next(s)}_getFloatingObjects(s){var r;if(s==null)return;const{unitId:e,subUnitId:n}=s;return(r=this._managerInfo.get(e))==null?void 0:r.get(n)}_getFloatingObject(s){var i,o;if(s==null)return;const{unitId:e,subUnitId:n,floatingObjectId:r}=s;return(o=(i=this._managerInfo.get(e))==null?void 0:i.get(n))==null?void 0:o.get(r)}_addByParam(s){const{unitId:e,subUnitId:n,floatingObject:r,floatingObjectId:i}=s;this._managerInfo.has(e)||this._managerInfo.set(e,new Map);const o=this._managerInfo.get(e);return o.has(n)||o.set(n,new Map),o.get(n).set(i,r),[{unitId:e,subUnitId:n,floatingObjectId:i,floatingObject:r}]}_clearByParam(s){const e=this._getFloatingObjects(s),{unitId:n,subUnitId:r}=s,i=[];return e==null||e.forEach((o,a)=>{i.push({unitId:n,subUnitId:r,floatingObjectId:a,floatingObject:o})}),e==null||e.clear(),i}_removeByParam(s){const e=this._getFloatingObjects(s),n=e==null?void 0:e.get(s.floatingObjectId);return n==null?[]:(e==null||e.delete(s.floatingObjectId),[{...s,floatingObject:n}])}}const In=A.createIdentifier("univer.floating-object.service");class An{constructor(s={}){d(this,"_styles");d(this,"_cacheMap",new Ys(1e5));this._styles=s,this._generateCacheMap()}each(s){return Object.entries(this._styles).forEach(s),this}search(s,e){if(this._cacheMap.has(e))return this._cacheMap.get(e);const n=this._getExistingStyleId(s);return n||"-1"}get(s){return typeof s!="string"?s:(s=String(s),this._styles[s])}add(s,e){const n=R.generateRandomId(6);return this._styles[n]=s,this._cacheMap.set(e,n),n}setValue(s){if(s==null)return;const e=JSON.stringify(s),n=this.search(s,e);return n!=="-1"?n:this.add(s,e)}toJSON(){return this._styles}getStyleByCell(s){let e;s&&R.isObject(s.s)?e=s.s:e=(s==null?void 0:s.s)&&this.get(s.s);const n=s==null?void 0:s.interceptorStyle;return n?{...e,...n}:e}_generateCacheMap(){const{_styles:s,_cacheMap:e}=this;for(const n in s){const r=JSON.stringify(s[n]);e.set(r,n)}}_getExistingStyleId(s){const{_styles:e}=this;for(const n in e)if(R.diffValue(e[n],s))return n;return null}}class qi{constructor(s,e){d(this,"_columnData",{});this._config=s,this._columnData=e}getColumnData(){return this._columnData}getColVisible(s){const{_columnData:e}=this,n=e[s];return n?n.hd!==C.TRUE:!0}getHiddenCols(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getColVisible(o);r&&a?(r=!1,n.push({rangeType:x.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!a&&(r=!0,i=o)}return r&&n.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:x.COLUMN}),n}getVisibleCols(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getColVisible(o);r&&!a?(r=!1,n.push({rangeType:x.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&a&&(r=!0,i=o)}return r&&n.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:x.COLUMN}),n}getColumnDatas(s,e){const n={};let r=0;for(let i=s;i<s+e;i++){const o=this.getColumnOrCreate(i);n[r]=o,r++}return n}getSize(){return y(this._columnData)}getColumnWidth(s){const{_columnData:e}=this,n=this._config;let r=0;return r=(e[s]||{hd:C.FALSE,w:n.defaultColumnWidth}).w||n.defaultColumnWidth,r}getColumn(s){const e=this._columnData[s];if(e)return e}getColumnOrCreate(s){const{_columnData:e}=this,n=this._config,r=e[s];if(r)return r;const i={w:n.defaultColumnWidth,hd:C.FALSE};return this._columnData[s]=i,i}}class Ji{constructor(s,e,n){d(this,"_rowData");this._config=s,this._viewModel=e,this._rowData=n}getRowData(){return this._rowData}getRowDatas(s,e){const n={};let r=0;for(let i=s;i<s+e;i++){const o=this.getRowOrCreate(i);n[r]=o,r++}return n}getRowHeight(s,e=1){const{_rowData:n}=this,r=this._config;let i=0;for(let o=0;o<e;o++){const a=n[o+s]||{hd:C.FALSE,h:r.defaultRowHeight},{ia:l,ah:u,h:c=r.defaultRowHeight}=a;i+=(l==null||l===C.TRUE)&&typeof u=="number"?u:c}return i}getRow(s){return this._rowData[s]}getRowOrCreate(s){const{_rowData:e}=this,n=e[s];if(n)return n;const r=this._config,i={hd:C.FALSE,h:r.defaultRowHeight};return e[s]=i,i}getHiddenRows(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getRowRawVisible(o);r&&a?(r=!1,n.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:x.ROW})):!r&&!a&&(r=!0,i=o)}return r&&n.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:x.ROW}),n}getVisibleRows(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getRowRawVisible(o);r&&!a?(r=!1,n.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:x.ROW})):!r&&a&&(r=!0,i=o)}return r&&n.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:x.ROW}),n}getRowRawVisible(s){const e=this.getRow(s);return e?e.hd!==C.TRUE:!0}getSize(){return y(this._rowData)}}const Zi="DEFAULT_WORKSHEET_ROW_COUNT",Nn=1e3,Qi="DEFAULT_WORKSHEET_COLUMN_COUNT",Sn=20,to="DEFAULT_WORKSHEET_ROW_HEIGHT",Ln=19,eo="DEFAULT_WORKSHEET_COLUMN_WIDTH",Tn=73,so="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",bn=46,no="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",wn=20;function vn(t){const s={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:C.FALSE,rowCount:Nn,columnCount:Sn,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Tn,defaultRowHeight:Ln,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:C.TRUE,rowHeader:{width:bn,hidden:C.FALSE},columnHeader:{height:wn,hidden:C.FALSE},selections:["A1"],rightToLeft:C.FALSE};return Object.keys(s).forEach(e=>{const n=e;typeof t[n]>"u"&&(t[n]=s[n])}),t}class Un extends p{constructor(e){super();d(this,"_cellContentInterceptor",null);d(this,"_rowFilteredInterceptor",null);this.getRawCell=e}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(e,n){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(e,n):this.getRawCell(e,n)}getRowFiltered(e){var n,r;return(r=(n=this._rowFilteredInterceptor)==null?void 0:n.getRowFiltered(e))!=null?r:!1}registerCellContentInterceptor(e){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=e,v(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(e){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=e,v(()=>this._rowFilteredInterceptor=null)}}class Et{constructor(s,e,n){d(this,"_sheetId");d(this,"_snapshot");d(this,"_cellData");d(this,"_rowManager");d(this,"_columnManager");d(this,"_viewModel");var a;this.unitId=s,this._styles=n,this._snapshot=vn(e);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(a=this._snapshot.id)!=null?a:R.generateRandomId(6),this._cellData=new G(o),this._viewModel=new Un((l,u)=>this.getCellRaw(l,u)),this._rowManager=new Ji(this._snapshot,this._viewModel,i),this._columnManager=new qi(this._snapshot,r)}__interceptViewModel(s){s(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const s=this.getCellMatrix(),e=this.getMergeData();let n=-1,r=-1,i=-1,o=-1,a=!1,l=!1;return s.forEach((u,c)=>{Object.keys(c).forEach(h=>{const _=+h,f=s.getValue(u,_),E=f!=null&&f.s?this._styles.get(f.s):null,g=(E==null?void 0:E.bd)&&(E.bd.b||E.bd.l||E.bd.r||E.bd.t||E.bd.bc_tr||E.bd.bl_tr||E.bd.ml_tr||E.bd.tl_bc||E.bd.tl_br||E.bd.tl_mr);(f&&(f.v||f.p)||E!=null&&E.bg||g)&&(a?n=Math.min(n,u):(n=u,a=!0),r=Math.max(r,u),l?i=Math.min(i,_):(l=!0,i=_),o=Math.max(o,_))})}),e.forEach(u=>{a?n=Math.min(n,u.startRow):(n=u.startRow,a=!0),r=Math.max(r,u.endRow),l?i=Math.min(i,u.startColumn):(i=u.startColumn,a=!0),o=Math.max(o,u.endColumn)}),!a||!l?null:{startColumn:i,startRow:n,endColumn:o,endRow:r}}getRowManager(){return this._rowManager}getUnitId(){return this.unitId}getSheetId(){return this._sheetId}getColumnManager(){return this._columnManager}getName(){return this._snapshot.name}clone(){const{_snapshot:s}=this,e=R.deepClone(s);return new Et(this.unitId,e,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(s,e){const n=this._snapshot.mergeData;for(let r=0;r<n.length;r++){const i=n[r];if(X.intersects({startRow:s,startColumn:e,endRow:s,endColumn:e},i))return i}return null}getCell(s,e){return s<0||e<0?null:this._viewModel.getCell(s,e)}getCellRaw(s,e){return this.getCellMatrix().getValue(s,e)}getRowFiltered(s){return this._viewModel.getRowFiltered(s)}getMatrixWithMergedCells(s,e,n,r,i=!1){const o=this.getCellMatrix(),a=this._snapshot.mergeData.filter(u=>X.intersects({startRow:s,startColumn:e,endRow:n,endColumn:r},u)),l=new G;return ie(s,n,e,r).forEach((u,c)=>{const h=i?this.getCellRaw(u,c):this.getCell(u,c);h&&l.setValue(u,c,h)}),a.forEach(u=>{const{startColumn:c,startRow:h,endColumn:_,endRow:f}=u;ie(h,f,c,_).forEach((E,g)=>{E===h&&g===c&&l.setValue(E,g,{...o.getValue(E,g),rowSpan:f-h+1,colSpan:_-c+1}),(E!==h||g!==c)&&l.realDeleteValue(E,g)})}),l}getRange(s,e,n,r){return typeof s=="object"?new et(this,s,{getStyles:()=>this._styles}):new et(this,{startRow:s,startColumn:e,endColumn:r||e,endRow:n||s},{getStyles:()=>this._styles})}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:s}=this,{columnCount:e}=s;return e}getMaxRows(){const{_snapshot:s}=this,{rowCount:e}=s;return e}getRowCount(){return this._snapshot.rowCount}setRowCount(s){this._snapshot.rowCount=s}getColumnCount(){return this._snapshot.columnCount}setColumnCount(s){this._snapshot.columnCount=s}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:s}=this,{showGridlines:e}=s;return e===0}getTabColor(){const{_snapshot:s}=this,{tabColor:e}=s;return e}getColumnWidth(s){return this.getColumnManager().getColumnWidth(s)}getRowHeight(s){return this._viewModel.getRowFiltered(s)?0:this.getRowManager().getRowHeight(s)}getRowVisible(s){return this._viewModel.getRowFiltered(s)?!1:this.getRowRawVisible(s)}getRowRawVisible(s){return this.getRowManager().getRowRawVisible(s)}getHiddenRows(s,e){const n=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(s,e);return r.forEach(i=>i.endColumn=n),r}getColVisible(s){return this._columnManager.getColVisible(s)}getHiddenCols(s,e){const n=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(s,e);return r.forEach(i=>i.endRow=n),r}getVisibleRows(){const s=this.getRowCount();return this._rowManager.getVisibleRows(0,s-1)}getVisibleCols(){const s=this.getColumnCount();return this._columnManager.getVisibleCols(0,s-1)}isRightToLeft(){const{_snapshot:s}=this,{rightToLeft:e}=s;return e}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(s){return s&&(s.v!==void 0||s.f!==void 0||s.p!==void 0)}iterateByRow(s,e=!0){const{startRow:n,startColumn:r,endRow:i,endColumn:o}=s,a=this;return{[Symbol.iterator]:()=>{let l=n,u=r;return{next(){for(;;){if(u>o&&(l+=1,u=r),l>i)return{done:!0,value:void 0};const c=a.getCell(l,u),h=!c,_=a.getMergedCell(l,u);if(_){if(l!==_.startRow||u!==_.startColumn){u=_.endColumn+1;continue}if(h&&e){u=_.endColumn+1;continue}const E={row:l,col:u,value:c};return E.colSpan=_.endColumn-_.startColumn+1,E.rowSpan=_.endRow-_.startRow+1,u=_.endColumn+1,{done:!1,value:E}}if(h&&e)u+=1;else{const f={row:l,col:u,value:c};return u+=1,{done:!1,value:f}}}}}}}}iterateByColumn(s,e=!0,n=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:a}=s,l=this;return{[Symbol.iterator]:()=>{let u=r,c=i;return{next(){for(;;){if(u>o&&(c+=1,u=r),c>a)return{done:!0,value:void 0};const h=l.getMergedCell(u,c);if(h){const E=u!==h.startRow,g=E||c!==h.startColumn;if(n&&g||!n&&E){u=h.endRow+1;continue}const m=l.getCell(h.startRow,h.startColumn);if(!m&&e){u=h.endRow+1;continue}const U={row:u,col:h.startColumn,value:m};return U.colSpan=h.endColumn-h.startColumn+1,U.rowSpan=h.endRow-h.startRow+1,u=h.endRow+1,{done:!1,value:U}}const _=l.getCell(u,c);if(!_&&e)u+=1;else{const E={row:u,col:c,value:_};return u+=1,{done:!1,value:E}}}}}}}}}function ro(t){var n,r;if(!t)return"";const s=(r=(n=t.p)==null?void 0:n.body)==null?void 0:r.dataStream;if(s)return s;const e=t.v;return typeof e=="string"?t.t===Q.BOOLEAN?e.toUpperCase():e:typeof e=="number"?t.t===Q.BOOLEAN?e?"TRUE":"FALSE":e.toString():typeof e=="boolean"?e?"TRUE":"FALSE":""}const io="0.1.8";function oo(t="",s=nt.ZH_CN,e=""){return{id:t,sheetOrder:[],name:e,appVersion:io,locale:s,styles:{},sheets:{},resources:[]}}var ao=Object.defineProperty,lo=Object.getOwnPropertyDescriptor,uo=(t,s,e,n)=>{for(var r=n>1?void 0:n?lo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&ao(s,e,r),r},co=(t,s)=>(e,n)=>s(e,n,t);function ho(t,s){return`${t.getUnitId()}|${s.getSheetId()}`}exports.Workbook=class extends Vt{constructor(e={},n){super();d(this,"type",O.UNIVER_SHEET);d(this,"_sheetCreated$",new L.Subject);d(this,"sheetCreated$",this._sheetCreated$.asObservable());d(this,"_sheetDisposed$",new L.Subject);d(this,"sheetDisposed$",this._sheetDisposed$.asObservable());d(this,"_activeSheet$",new L.BehaviorSubject(null));d(this,"activeSheet$",this._activeSheet$.asObservable());d(this,"_worksheets");d(this,"_styles");d(this,"_snapshot");d(this,"_unitId");d(this,"_count");this._logService=n;const r=oo();R.isEmptyObject(e)?this._snapshot=r:this._snapshot=R.commonExtend(r,e);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=R.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new An(i),this._count=1,this._worksheets=new Map,this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._snapshot.name}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete()}save(){return R.deepClone(this._snapshot)}static isIRangeType(e){return typeof e=="string"||"startRow"in e||"row"in e}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}getUnitId(){return this._unitId}getRev(){var e;return(e=this._snapshot.rev)!=null?e:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(e,n,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[e])return!1;i[e]=r,o.splice(n,0,e);const a=new Et(this._unitId,r,this._styles);return this._worksheets.set(e,a),this._sheetCreated$.next(a),!0}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(e){const{sheetOrder:n}=this._snapshot;return n.findIndex(r=>r===e)}getRawActiveSheet(){return this._activeSheet}getActiveSheet(){const e=this.getRawActiveSheet();if(e)return e;const n=this._snapshot.sheetOrder;for(let i=0,o=n.length;i<o;i++){const a=this._worksheets.get(n[i]);if(a&&a.isSheetHidden()!==C.TRUE)return this.setActiveSheet(a),a}const r=this._worksheets.get(n[0]);return this.setActiveSheet(r),r}setActiveSheet(e){this._activeSheet$.next(e)}removeSheet(e){var r;return this._worksheets.get(e)?(((r=this._activeSheet)==null?void 0:r.getSheetId())===e&&this.setActiveSheet(null),this._worksheets.delete(e),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(e),1),delete this._snapshot.sheets[e],!0):!1}getActiveSheetIndex(){const{sheetOrder:e}=this._snapshot;return e.findIndex(n=>this._worksheets.get(n)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:e}=this._snapshot;return e.map(n=>this._worksheets.get(n))}getSheetsName(){const{sheetOrder:e}=this._snapshot,n=[];return e.forEach(r=>{const i=this._worksheets.get(r);i&&n.push(i.getName())}),n}getSheetIndex(e){const{sheetOrder:n}=this._snapshot;return n.findIndex(r=>e.getSheetId()===r)}getSheetBySheetName(e){const{sheetOrder:n}=this._snapshot,r=n.find(i=>this._worksheets.get(i).getName()===e);return this._worksheets.get(r)}getSheetBySheetId(e){return this._worksheets.get(e)}getSheetByIndex(e){const{sheetOrder:n}=this._snapshot;return this._worksheets.get(n[e])}getHiddenWorksheets(){return this.getSheets().filter(e=>e.getConfig().hidden===C.TRUE).map(e=>e.getConfig().id)}transformRangeType(e){if(typeof e=="string")return this._getCellRange(e);if(typeof e!="string"&&"row"in e){const n=e;return{sheetId:"",range:{startRow:n.row[0],startColumn:n.column[0],endRow:n.row[1],endColumn:n.column[1]}}}return typeof e!="string"&&"startRow"in e?{sheetId:"",range:e}:lt}load(e){this._snapshot=e}checkSheetName(e){return this.getSheetsName().includes(e)}uniqueSheetName(e="Sheet1"){let n=e;for(;this.checkSheetName(n);)n=e+this._count,this._count++;return n}generateNewSheetName(e){let n=e+this._count;for(;this.checkSheetName(n);)n=e+this._count,this._count++;return n}_getCellRange(e){var c,h,_,f,E;let n="",r="";if(e.indexOf("!")>-1){const g=e.split("!");n=g[0],r=g[1],n=n.replace(/\\'/g,"'").replace(/''/g,"'"),n.substring(0,1)==="'"&&n.substring(n.length-1,1)==="'"&&(n=n.substring(1,n.length-1))}else r=e;if(r.indexOf(":")===-1){const g=Number.parseInt(r.replace(/[^0-9]/g,""),10)-1,m=R.ABCatNum(r.replace(/[^A-Za-z]/g,""));return!Number.isNaN(g)&&!Number.isNaN(m)?{sheetId:n,range:{startRow:g,endRow:g,startColumn:m,endColumn:m}}:lt}r=r.split(":");const i=[0,0],o=[0,0],a=((c=this.getSheetBySheetName(n))==null?void 0:c.getMaxRows())||((h=this.getActiveSheet())==null?void 0:h.getMaxRows()),l=((_=this.getSheetBySheetName(n))==null?void 0:_.getMaxColumns())||((f=this.getActiveSheet())==null?void 0:f.getMaxColumns());return i[0]=Number.parseInt(r[0].replace(/[^0-9]/g,""),10)-1,i[1]=Number.parseInt(r[1].replace(/[^0-9]/g,""),10)-1,Number.isNaN(i[0])&&(i[0]=0),Number.isNaN(i[1])&&(i[1]=a),i[0]>i[1]||(o[0]=R.ABCatNum(r[0].replace(/[^A-Za-z]/g,"")),o[1]=R.ABCatNum(r[1].replace(/[^A-Za-z]/g,"")),Number.isNaN(o[0])&&(o[0]=0),Number.isNaN(o[1])&&(o[1]=l),o[0]>o[1])?lt:{sheetId:((E=this.getSheetBySheetName(n))==null?void 0:E.getSheetId())||"",range:{startRow:i[0],endRow:i[1],startColumn:o[0],endColumn:o[1]}}}_passWorksheetSnapshots(){const{_snapshot:e,_worksheets:n}=this,{sheets:r,sheetOrder:i}=e;if(R.isEmptyObject(r)){const o=R.generateRandomId();r[o]={id:o}}for(const o in r){const a=r[o],{name:l}=a;a.name=this.uniqueSheetName(l),a.name!==l&&this._logService.debug("[Workbook]",`The worksheet name ${l} is duplicated, we changed it to ${a.name}. Please fix the problem in your snapshot.`);const u=new Et(this._unitId,a,this._styles);n.set(o,u),i.includes(o)||i.push(o)}}};exports.Workbook=uo([co(1,J)],exports.Workbook);class Te extends Vt{constructor(e){var n;super();d(this,"type",O.UNIVER_SLIDE);d(this,"_snapshot");d(this,"_unitId");this._snapshot={...qs,...e},this._unitId=(n=this._snapshot.id)!=null?n:R.generateRandomId(6)}getContainer(){return this._snapshot.container}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var e;return(e=this._snapshot.body)==null?void 0:e.pages}getPageOrder(){var e;return(e=this._snapshot.body)==null?void 0:e.pageOrder}getPage(e){const n=this.getPages();return n==null?void 0:n[e]}getElementsByPage(e){var n;return(n=this.getPage(e))==null?void 0:n.pageElements}getElement(e,n){var r;return(r=this.getElementsByPage(e))==null?void 0:r[n]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:de.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const ht="FOCUSING_SHEET",bt="FOCUSING_DOC",wt="FOCUSING_SLIDE",_o="FOCUSING_EDITOR_BUT_HIDDEN",Dn="EDITOR_ACTIVATED",fo="FOCUSING_EDITOR_INPUT_FORMULA",pn="FOCUSING_FORMULA_EDITOR",Eo="FOCUSING_UNIVER_EDITOR",go="FOCUSING_EDITOR_INPUT_FORMULA",Ro="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE";var mo=Object.defineProperty,Co=Object.getOwnPropertyDescriptor,Oo=(t,s,e,n)=>{for(var r=n>1?void 0:n?Co(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&mo(s,e,r),r},Be=(t,s)=>(e,n)=>s(e,n,t);const q=A.createIdentifier("univer.current");exports.UniverInstanceService=class extends p{constructor(e,n){super();d(this,"_unitsByType",new Map);d(this,"_createHandler");d(this,"_ctorByType",new Map);d(this,"_currentUnits$",new L.BehaviorSubject({}));d(this,"currentUnits$",this._currentUnits$.asObservable());d(this,"_unitAdded$",new L.Subject);d(this,"unitAdded$",this._unitAdded$.asObservable());d(this,"_unitDisposed$",new L.Subject);d(this,"unitDisposed$",this._unitDisposed$.asObservable());d(this,"_focused$",new L.BehaviorSubject(null));d(this,"focused$",this._focused$.asObservable());this._injector=e,this._contextService=n}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(e){this._createHandler=e}createUnit(e,n){return this._createHandler(e,n,this._ctorByType.get(e))}registerCtorForType(e,n){return this._ctorByType.set(e,n),{dispose:()=>{this._ctorByType.delete(e)}}}getCurrentTypeOfUnit$(e){return this.currentUnits$.pipe(L.map(n=>{var r;return(r=n[e])!=null?r:null}),L.distinctUntilChanged())}getCurrentUnitForType(e){return this._currentUnits$.getValue()[e]}setCurrentUnitForType(e){const n=this._getUnitById(e);if(!n)throw new Error(`[UniverInstanceService]: no document with unitId ${e}!`);this._currentUnits$.next({...this._currentUnits$.getValue(),[n[1]]:n[0]})}getTypeOfUnitAdded$(e){return this._unitAdded$.pipe(L.filter(n=>n.type===e))}__addUnit(e){const n=e.type;this._unitsByType.has(n)||this._unitsByType.set(n,[]),this._unitsByType.get(n).push(e),this._unitAdded$.next(e),this._currentUnits$.next({...this._currentUnits$.getValue(),[n]:e})}getTypeOfUnitDisposed$(e){return this.unitDisposed$.pipe(L.filter(n=>n.type===e))}getUnit(e,n){var i;const r=(i=this._getUnitById(e))==null?void 0:i[0];return n&&(r==null?void 0:r.type)!==n?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(O.UNIVER_DOC)}getUniverDocInstance(e){return this.getUnit(e,O.UNIVER_DOC)}getUniverSheetInstance(e){return this.getUnit(e,O.UNIVER_SHEET)}getAllUnitsForType(e){var n;return(n=this._unitsByType.get(e))!=null?n:[]}changeDoc(e,n){const r=this.getAllUnitsForType(O.UNIVER_DOC),i=r.find(o=>o.getUnitId()===e);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(n)}get focused(){var n;const e=this._focused$.getValue();return e?(n=this._getUnitById(e))==null?void 0:n[0]:null}focusUnit(e){this._focused$.next(e),this.focused instanceof exports.Workbook?(this._contextService.setContextValue(bt,!1),this._contextService.setContextValue(ht,!0),this._contextService.setContextValue(wt,!1)):this.focused instanceof st?(this._contextService.setContextValue(bt,!0),this._contextService.setContextValue(ht,!1),this._contextService.setContextValue(wt,!1)):this.focused instanceof Te&&(this._contextService.setContextValue(bt,!1),this._contextService.setContextValue(ht,!1),this._contextService.setContextValue(wt,!0))}getFocusedUnit(){return this.focused}getUnitType(e){const n=this._getUnitById(e);if(!n)throw new Error(`[UniverInstanceService]: No document with unitId ${e}`);return n[1]}disposeUnit(e){const n=this._getUnitById(e);if(!n)return!1;const[r,i]=n,o=this._unitsByType.get(i),a=o.indexOf(r);return o.splice(a,1),this._unitDisposed$.next(r),this._currentUnits$.next({...this._currentUnits$.getValue(),[i]:null}),this._focused$.next(null),!0}_getUnitById(e){for(const[n,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===e);if(i)return[i,n]}}};exports.UniverInstanceService=Oo([Be(0,A.Inject(A.Injector)),Be(1,gt)],exports.UniverInstanceService);var b=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(b||{});const Io={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},vt=new Map;function be(t,s){return function(r){we(t,s)}}function we(t,s){vt.has(t)||vt.set(t,[]),vt.get(t).push(s)}var Ao=Object.defineProperty,No=Object.getOwnPropertyDescriptor,Mn=(t,s,e,n)=>{for(var r=n>1?void 0:n?No(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Ao(s,e,r),r},le=(t,s)=>(e,n)=>s(e,n,t);exports.LifecycleService=class extends p{constructor(e){super();d(this,"_lifecycle$",new L.BehaviorSubject(b.Starting));d(this,"lifecycle$",this._lifecycle$.asObservable());d(this,"_lock",!1);this._logService=e,this._reportProgress(b.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(e){if(e<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(e!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(e),this._lifecycle$.next(e),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new L.Observable(e=>(this.stage===b.Starting||(this.stage===b.Ready?e.next(b.Starting):this.stage===b.Rendered?(e.next(b.Starting),e.next(b.Ready)):(e.next(b.Starting),e.next(b.Ready),e.next(b.Rendered))),this._lifecycle$.subscribe(e)))}_reportProgress(e){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${Io[e]}".`)}};exports.LifecycleService=Mn([le(0,J)],exports.LifecycleService);exports.LifecycleInitializerService=class extends p{constructor(e,n){super();d(this,"_seenTokens",new Set);this._lifecycleService=e,this._injector=n}initModulesOnStage(e){var n;(n=vt.get(e))==null||n.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}};exports.LifecycleInitializerService=Mn([le(0,A.Inject(exports.LifecycleService)),le(1,A.Inject(A.Injector))],exports.LifecycleInitializerService);class dt extends p{constructor(){super();d(this,"_currentLocale",nt.ZH_CN);d(this,"_locales",null);d(this,"localeChanged$",new L.Subject);d(this,"t",(e,...n)=>{if(!this._locales)throw new Error("Locale not initialized");const r=e.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return n.forEach((a,l)=>{o=o.replace(`{${l}}`,a)}),o}else return e});this.disposeWithMe(v(()=>this.localeChanged$.complete()))}load(e){var n;this._locales=R.deepMerge((n=this._locales)!=null?n:{},e)}setLocale(e){this._currentLocale=e,this.localeChanged$.next()}getLocales(){var e;return(e=this._locales)==null?void 0:e[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(e,n){const r=n.shift();if(r&&e&&r in e){const i=e[r];return n.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,n):i}return null}}const Kt=A.createIdentifier("resource-manager-service");var So=Object.defineProperty,Lo=Object.getOwnPropertyDescriptor,To=(t,s,e,n)=>{for(var r=n>1?void 0:n?Lo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&So(s,e,r),r},ke=(t,s)=>(e,n)=>s(e,n,t);const ve=A.createIdentifier("univer.permission-service");exports.PermissionService=class extends p{constructor(e,n){super();d(this,"_permissionPointMap",new Map);d(this,"deletePermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e);if(r){const i=r.get(n);i&&(i.complete(),this._permissionPointMap.delete(n))}});d(this,"addPermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e)||new Map;return r.has(n.id)?!1:(r.set(n.id,new L.BehaviorSubject(n)),this._permissionPointMap.set(e,r),!0)});d(this,"updatePermissionPoint",(e,n,r)=>{const i=this._permissionPointMap.get(e);if(!i)return;const o=i.get(n);if(o){const a=o.getValue();a.value=r,a.status=ge.DONE,o.next(a)}});d(this,"getPermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e);if(!r)return;const i=r.get(n);if(i)return i.getValue()});this._resourceManagerService=e,this._univerInstanceService=n}_toJson(e){const n=this._permissionPointMap.get(e);let r=[];return n&&(r=[...n.keys()].reduce((i,o)=>{const a=n.get(o);return a&&i.push(a.getValue()),i},[])),JSON.stringify(r)}_parseJson(e){return JSON.parse(e)}composePermission$(e,n){const r=this._permissionPointMap.get(e),i=n.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.asObservable()});return L.combineLatest(i).pipe(rr.map(o=>(o.every(a=>this._permissionPointMap.get(a.id)),o)))}composePermission(e,n){const r=this._permissionPointMap.get(e);return n.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.getValue()})}};exports.PermissionService=To([be(b.Starting,exports.PermissionService),ke(0,A.Inject(Kt)),ke(1,A.Inject(q))],exports.PermissionService);const Pn="univer.editable";class Ut extends zs{constructor(e){super();d(this,"id",Pn);d(this,"value",!0);d(this,"unitID");this.unitID=e}}var bo=Object.defineProperty,wo=Object.getOwnPropertyDescriptor,vo=(t,s,e,n)=>{for(var r=n>1?void 0:n?wo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&bo(s,e,r),r},Ge=(t,s)=>(e,n)=>s(e,n,t);exports.UniverPermissionService=class extends p{constructor(s,e){super(),this._permissionService=s,this._univerInstanceService=e,this._init()}_init(){this._univerInstanceService.getTypeOfUnitAdded$(O.UNIVER_SHEET).subscribe(s=>{const e=new Ut(s.getUnitId());this._permissionService.addPermissionPoint(s.getUnitId(),e)})}getEditable(s=(e=>(e=this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET))==null?void 0:e.getUnitId())()){if(!s)return;const n=new Ut(s),r=this._permissionService.getPermissionPoint(s,n.id);return r==null?void 0:r.value}setEditable(s,e){const n=new Ut(s);this._permissionService.updatePermissionPoint(s,n.id,e)}};exports.UniverPermissionService=vo([be(b.Starting,exports.UniverPermissionService),Ge(0,A.Inject(ve)),Ge(1,A.Inject(q))],exports.UniverPermissionService);class xn extends p{constructor(){super(...arguments);d(this,"_resourceMap",new Map);d(this,"_register$",new L.Subject);d(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(e){return this.getAllResourceHooks().map(i=>{const o=i.toJson(e);return{name:i.pluginName,data:o}})}registerPluginResource(e){const n=e.pluginName;if(this._resourceMap.has(n))throw new Error(`the pluginName is registered {${n}}`);return this._resourceMap.set(n,e),this._register$.next(e),v(()=>this._resourceMap.delete(n))}disposePluginResource(e){this._resourceMap.delete(e)}loadResources(e,n){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=n==null?void 0:n.find(a=>a.name===r.pluginName))==null?void 0:o.data;if(i)try{const a=r.parseJson(i);r.onLoad(e,a)}catch{console.error("LoadResources Error!")}})}unloadResources(e){this.getAllResourceHooks().forEach(n=>{n.onUnLoad(e)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}var Uo=Object.defineProperty,Do=Object.getOwnPropertyDescriptor,po=(t,s,e,n)=>{for(var r=n>1?void 0:n?Do(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Uo(s,e,r),r},$e=(t,s)=>(e,n)=>s(e,n,t);let ue=class extends p{constructor(s,e){super();d(this,"saveWorkbook",s=>{const e=s.getUnitId(),n=this._resourceManagerService.getResources(e)||[],r=s.getSnapshot();return r.resources=n,r});this._resourceManagerService=s,this._univerInstanceService=e,this._init()}_init(){const s=n=>{n.businesses.forEach(r=>{switch(r){case O.UNRECOGNIZED:case O.UNIVER_UNKNOWN:case O.UNIVER_SLIDE:case O.UNIVER_DOC:break;case O.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(O.UNIVER_SHEET).forEach(i=>{const a=(i.getSnapshot().resources||[]).find(l=>l.name===n.pluginName);if(a)try{const l=n.parseJson(a.data);n.onLoad(i.getUnitId(),l)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${n.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(n=>{s(n)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(n=>{s(n)})),this.disposeWithMe(v(this._univerInstanceService.getTypeOfUnitAdded$(O.UNIVER_SHEET).subscribe(n=>{this._resourceManagerService.loadResources(n.getUnitId(),n.getSnapshot().resources)}))),this.disposeWithMe(v(this._univerInstanceService.getTypeOfUnitDisposed$(O.UNIVER_SHEET).subscribe(n=>{this._resourceManagerService.unloadResources(n.getUnitId())})))}};ue=po([$e(0,A.Inject(Kt)),$e(1,A.Inject(q))],ue);const Ue=A.createIdentifier("resource-loader-service");we(b.Ready,Ue);class De extends p{constructor(){super();d(this,"_currentTheme");d(this,"_currentTheme$",new L.BehaviorSubject({}));d(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(v(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(e){this._currentTheme=e,this._currentTheme$.next(e)}}const Hn="__defaultDocumentNormalEditorSpecialUnitId_20231006__",Fn="__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__",Mo=`\r
6
+ `,textRuns:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:5,lineSpacing:1,spaceBelow:0}}],sectionBreaks:[{startIndex:1}]},documentStyle:{pageSize:{width:793.3333333333334,height:1122.6666666666667},marginTop:50,marginBottom:50,marginRight:40,marginLeft:40,renderConfig:{vertexAngle:0,centerAngle:0}},settings:{}}}const Se={id:"default_doc",documentStyle:{}};class $i extends Vt{constructor(e){super();d(this,"type",O.UNIVER_DOC);d(this,"snapshot");this.snapshot={...Se,...e}}getUnitId(){throw new Error("Method not implemented.")}get drawings(){return this.snapshot.drawings}get documentStyle(){return this.snapshot.documentStyle}get lists(){return this.snapshot.lists}get body(){return this.snapshot.body}get zoomRatio(){var e;return((e=this.snapshot.settings)==null?void 0:e.zoomRatio)||1}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getParentRenderUnitId(){return this.snapshot.parentRenderUnitId}getSnapshot(){return this.snapshot}updateDocumentId(e){this.snapshot.id=e}updateDocumentRenderConfig(e){const{documentStyle:n}=this.snapshot;n.renderConfig==null?n.renderConfig=e:n.renderConfig={...n.renderConfig,...e}}updateDocumentStyle(e){this.snapshot.documentStyle==null?this.snapshot.documentStyle=e:this.snapshot.documentStyle={...this.snapshot.documentStyle,...e}}updateDocumentDataMargin(e){const{t:n,l:r,b:i,r:o}=e,{documentStyle:a}=this.snapshot;n!=null&&(a.marginTop=n),r!=null&&(a.marginLeft=r),i!=null&&(a.marginBottom=i),o!=null&&(a.marginRight=o)}updateDocumentDataPageSize(e,n){const{documentStyle:r}=this.snapshot;if(!r.pageSize){e=e!=null?e:Number.POSITIVE_INFINITY,n=n!=null?n:Number.POSITIVE_INFINITY,r.pageSize={width:e,height:n};return}e!==void 0&&(r.pageSize.width=e),n!==void 0&&(r.pageSize.height=n)}updateDrawing(e,n){const{drawings:r}=this,{width:i,height:o,left:a,top:l}=n,u=r==null?void 0:r[e];if(!u)return;const c=u.objectTransform;c.size.width=i,c.size.height=o,c.positionH.posOffset=a,c.positionV.posOffset=l}setZoomRatio(e=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:e}:this.snapshot.settings.zoomRatio=1}}class st extends $i{constructor(e){var r;super(R.isEmptyObject(e)?Gi():e);d(this,"_unitId");d(this,"headerModelMap",new Map);d(this,"footerModelMap",new Map);const n=6;this._unitId=(r=this.snapshot.id)!=null?r:R.generateRandomId(n),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(e=>{e.dispose()}),this.footerModelMap.forEach(e=>{e.dispose()})}getRev(){var e;return(e=this.snapshot.rev)!=null?e:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(e){if(e.id&&e.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Se,...e},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(e){if(e!=null){if(this.headerModelMap.has(e))return this.headerModelMap.get(e);if(this.footerModelMap.has(e))return this.footerModelMap.get(e)}return this}getUnitId(){return this._unitId}apply(e){const n=[],r=new Qs;return r.reset(),e.forEach(i=>{if(i=R.deepClone(i),i.t===I.RETAIN){const{coverType:o,body:a,len:l,segmentId:u}=i;if(a!=null){const c=this._updateApply(a,l,r.cursor,o,u);n.push({...i,t:I.RETAIN,coverType:P.REPLACE,body:c})}else n.push({...i,t:I.RETAIN});r.moveCursor(l)}else if(i.t===I.INSERT){const{body:o,len:a,segmentId:l,line:u}=i;this._insertApply(o,a,r.cursor,l),r.moveCursor(a),n.push({t:I.DELETE,len:a,line:u,segmentId:l})}else if(i.t===I.DELETE){const{len:o,segmentId:a}=i,l=this._deleteApply(o,r.cursor,a);n.push({...i,t:I.INSERT,body:l})}else throw new Error(`Unknown action type for action: ${i}.`)}),n}sliceBody(e,n){const r=this.getBody();if(r!=null)return Ne(r,e,n)}_updateApply(e,n,r,i=P.COVER,o){if(e==null)throw new Error("updateBody is none");const a=this.snapshot,l=St(a,o);if(l==null)throw new Error("no body has changed");return Mi(l,e,n,r,i)}_deleteApply(e,n,r){const i=this.snapshot,o=St(i,r);if(o==null)throw new Error("no body has changed");return e<=0?{dataStream:""}:Ui(o,e,n)}_insertApply(e,n,r,i){const o=this.snapshot,a=St(o,i);if(n!==0){if(a==null)throw new Error("no body has changed");Di(a,e,n,r)}}_initializeHeaderFooterModel(){const{headers:e,footers:n}=this.getSnapshot();if(e)for(const r in e){const i=e[r];this.headerModelMap.set(r,new st(i))}if(n)for(const r in n){const i=n[r];this.footerModelMap.set(r,new st(i))}}updateDocumentId(e){super.updateDocumentId(e),this._unitId=e}}async function hn(t){for(const[s,e]of t.entries())try{if(!await e())return{index:s,result:!1}}catch(n){return{index:s,result:!1,error:n}}return{result:!0,index:-1}}function dn(t){for(const[s,e]of t.entries())try{if(!e())return{index:s,result:!1}}catch(n){return{index:s,result:!1,error:n}}return{result:!0,index:-1}}const gt=A.createIdentifier("univer.context-service");class _n extends p{constructor(){super(...arguments);d(this,"_contextChanged$",new L.Subject);d(this,"contextChanged$",this._contextChanged$.asObservable());d(this,"_contextMap",new Map)}dispose(){super.dispose(),this._contextChanged$.complete()}getContextValue(e){var n;return(n=this._contextMap.get(e))!=null?n:!1}setContextValue(e,n){this._contextMap.set(e,n),this._contextChanged$.next({[e]:n})}subscribeContextValue$(e){return new L.Observable(n=>{const r=this._contextChanged$.pipe(L.filter(i=>typeof i[e]<"u")).subscribe(i=>n.next(i[e]));return this._contextMap.has(e)&&n.next(this._contextMap.get(e)),()=>r.unsubscribe()})}}var fn=(t=>(t[t.SILENT=0]="SILENT",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.VERBOSE=4]="VERBOSE",t))(fn||{});const J=A.createIdentifier("univer.log");class En extends p{constructor(){super(...arguments);d(this,"_logLevel",3)}debug(...e){this._logLevel>=4&&this._log(console.debug,...e)}log(...e){this._logLevel>=3&&this._log(console.log,...e)}warn(...e){this._logLevel>=2&&this._log(console.warn,...e)}error(...e){this._logLevel>=1&&this._log(console.error,...e)}setLogLevel(e){this._logLevel=e}_log(e,...n){const r=n[0];/^\[(.*?)\]/g.test(r)?e(`\x1B[97;104m${r}\x1B[0m`,...n.slice(1)):e(...n)}}var Vi=Object.defineProperty,ji=Object.getOwnPropertyDescriptor,Ki=(t,s,e,n)=>{for(var r=n>1?void 0:n?ji(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Vi(s,e,r),r},We=(t,s)=>(e,n)=>s(e,n,t),jt=(t=>(t[t.COMMAND=0]="COMMAND",t[t.OPERATION=1]="OPERATION",t[t.MUTATION=2]="MUTATION",t))(jt||{});const Rt=A.createIdentifier("anywhere.command-service");class Yi{constructor(){d(this,"_commands",new Map)}registerCommand(s){if(this._commands.has(s.id))throw new Error(`[CommandRegistry]: command "${s.id}" has been registered before.`);return this._commands.set(s.id,s),v(()=>{var e;this._commands.delete(s.id),(e=s.onDispose)==null||e.call(s)})}hasCommand(s){return this._commands.has(s)}getCommand(s){return this._commands.has(s)?[this._commands.get(s)]:null}}const gn={id:"nil",type:0,handler:()=>!0};exports.CommandService=class{constructor(s,e){d(this,"_commandRegistry");d(this,"_beforeCommandExecutionListeners",[]);d(this,"_commandExecutedListeners",[]);d(this,"_multiCommandDisposables",new Map);d(this,"_commandExecutingLevel",0);d(this,"_commandExecutionStack",[]);this._injector=s,this._logService=e,this._commandRegistry=new Yi,this._registerCommand(gn)}hasCommand(s){return this._commandRegistry.hasCommand(s)}registerCommand(s){return this._registerCommand(s)}registerMultipleCommand(s){return this._registerMultiCommand(s)}beforeCommandExecuted(s){if(this._beforeCommandExecutionListeners.indexOf(s)===-1)return this._beforeCommandExecutionListeners.push(s),v(()=>{const e=this._beforeCommandExecutionListeners.indexOf(s);this._beforeCommandExecutionListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}onCommandExecuted(s){if(this._commandExecutedListeners.indexOf(s)===-1)return this._commandExecutedListeners.push(s),v(()=>{const e=this._commandExecutedListeners.indexOf(s);this._commandExecutedListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}async executeCommand(s,e,n){const r=this._commandRegistry.getCommand(s);if(r){const[i]=r,o={id:i.id,type:i.type,params:e},a=this._pushCommandExecutionStack(o);this._beforeCommandExecutionListeners.forEach(u=>u(o,n));const l=await this._execute(i,e,n);return this._commandExecutedListeners.forEach(u=>u(o,n)),a.dispose(),l}throw new Error(`[CommandService]: command "${s}" is not registered.`)}syncExecuteCommand(s,e,n){var i;const r=this._commandRegistry.getCommand(s);if(r){const[o]=r,a={id:o.id,type:o.type,params:e};if(o.type===2){const c=ni(this._commandExecutionStack,h=>h.type===0);c&&(a.params=(i=a.params)!=null?i:{},a.params.trigger=c.id)}const l=this._pushCommandExecutionStack(a);this._beforeCommandExecutionListeners.forEach(c=>c(a,n));const u=this._syncExecute(o,e,n);return this._commandExecutedListeners.forEach(c=>c(a,n)),l.dispose(),u}throw new Error(`[CommandService]: command "${s}" is not registered.`)}_pushCommandExecutionStack(s){return this._commandExecutionStack.push(s),v(()=>$t(this._commandExecutionStack,s))}_registerCommand(s){return this._commandRegistry.registerCommand(s)}_registerMultiCommand(s){const e=this._commandRegistry.getCommand(s.id);let n;if(e){if(e[0].multi!==!0)throw new Error("Command has registered as a single command.");n=e[0]}else{const i=new Ee;n=new zi(s.id),i.add(this._commandRegistry.registerCommand(n)),i.add(v(()=>{this._multiCommandDisposables.delete(s.id)})),this._multiCommandDisposables.set(s.id,i)}const r=n.registerImplementation(s);return v(()=>{var i;r.dispose(),n.hasImplementations()||(i=this._multiCommandDisposables.get(s.id))==null||i.dispose()})}async _execute(s,e,n){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(this._commandExecutingLevel,0))}executing command "${s.id}"`),this._commandExecutingLevel++;let r;try{r=await this._injector.invoke(s.handler,e,n),this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}_syncExecute(s,e,n){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(0,this._commandExecutingLevel))}executing command "${s.id}".`),this._commandExecutingLevel++;let r;try{if(r=this._injector.invoke(s.handler,e,n),r instanceof Promise)throw new TypeError("[CommandService]: Command handler should not return a promise.");this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}};exports.CommandService=Ki([We(0,A.Inject(A.Injector)),We(1,J)],exports.CommandService);class zi{constructor(s){d(this,"name");d(this,"multi",!0);d(this,"type",0);d(this,"priority",0);d(this,"_implementations",[]);d(this,"handler",async(s,e)=>{if(!this._implementations.length)return!1;const n=s.get(J),r=s.get(gt),i=s.get(A.Injector);for(const o of this._implementations){const a=o.command.preconditions;if((!a||a&&a(r))&&(n.debug("[MultiCommand]",`executing implementation "${o.command.name}".`),await i.invoke(o.command.handler,e)))return!0}return!1});this.id=s,this.name=s}registerImplementation(s){const e={command:s};return this._implementations.push(e),this._implementations.sort((n,r)=>r.command.priority-n.command.priority),v(()=>{var r;const n=this._implementations.indexOf(e);this._implementations.splice(n,1),(r=s.onDispose)==null||r.call(s)})}hasImplementations(){return this._implementations.length>0}}function Le(t,s,e){const n=t.map(r=>()=>s.syncExecuteCommand(r.id,r.params,e));return dn(n)}function yi(t,s,e){const n=t.map(r=>()=>s.executeCommand(r.id,r.params,e));return hn(n)}const Rn=A.createIdentifier("univer.config-service");class mn{constructor(){d(this,"_config",new Map)}getConfig(s){return this._config.get(s)}setConfig(s,e){this._config.set(s,e)}deleteConfig(s){this._config.delete(s)}}class Cn extends p{constructor(){super(...arguments);d(this,"_error$",new L.Subject);d(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(e){this._error$.next({errorKey:e})}}const Xi="__default_document_sub_component_id20231101__";class On{constructor(){d(this,"_managerInfo",new Map);d(this,"_remove$",new L.Subject);d(this,"remove$",this._remove$.asObservable());d(this,"_andOrUpdate$",new L.Subject);d(this,"andOrUpdate$",this._andOrUpdate$.asObservable());d(this,"_pluginUpdate$",new L.Subject);d(this,"pluginUpdate$",this._pluginUpdate$.asObservable())}getFloatObject(s){return this._getFloatingObject(s)}getFloatObjects(s){return this._getFloatingObjects(s)}dispose(){this._remove$.complete(),this._andOrUpdate$.complete(),this._pluginUpdate$.complete(),this._managerInfo.clear()}clear(s){const e=this._clearByParam(s);this._remove$.next(e)}addOrUpdate(s){const e=this._addByParam(s);this._andOrUpdate$.next(e)}BatchAddOrUpdate(s){const e=[];s.forEach(n=>{e.push(...this._addByParam(n))}),this._andOrUpdate$.next(e)}remove(s){const e=this._removeByParam(s);this._remove$.next(e)}pluginUpdateRefresh(s){this._pluginUpdate$.next(s)}_getFloatingObjects(s){var r;if(s==null)return;const{unitId:e,subUnitId:n}=s;return(r=this._managerInfo.get(e))==null?void 0:r.get(n)}_getFloatingObject(s){var i,o;if(s==null)return;const{unitId:e,subUnitId:n,floatingObjectId:r}=s;return(o=(i=this._managerInfo.get(e))==null?void 0:i.get(n))==null?void 0:o.get(r)}_addByParam(s){const{unitId:e,subUnitId:n,floatingObject:r,floatingObjectId:i}=s;this._managerInfo.has(e)||this._managerInfo.set(e,new Map);const o=this._managerInfo.get(e);return o.has(n)||o.set(n,new Map),o.get(n).set(i,r),[{unitId:e,subUnitId:n,floatingObjectId:i,floatingObject:r}]}_clearByParam(s){const e=this._getFloatingObjects(s),{unitId:n,subUnitId:r}=s,i=[];return e==null||e.forEach((o,a)=>{i.push({unitId:n,subUnitId:r,floatingObjectId:a,floatingObject:o})}),e==null||e.clear(),i}_removeByParam(s){const e=this._getFloatingObjects(s),n=e==null?void 0:e.get(s.floatingObjectId);return n==null?[]:(e==null||e.delete(s.floatingObjectId),[{...s,floatingObject:n}])}}const In=A.createIdentifier("univer.floating-object.service");class An{constructor(s={}){d(this,"_styles");d(this,"_cacheMap",new Ys(1e5));this._styles=s,this._generateCacheMap()}each(s){return Object.entries(this._styles).forEach(s),this}search(s,e){if(this._cacheMap.has(e))return this._cacheMap.get(e);const n=this._getExistingStyleId(s);return n||"-1"}get(s){return typeof s!="string"?s:(s=String(s),this._styles[s])}add(s,e){const n=R.generateRandomId(6);return this._styles[n]=s,this._cacheMap.set(e,n),n}setValue(s){if(s==null)return;const e=JSON.stringify(s),n=this.search(s,e);return n!=="-1"?n:this.add(s,e)}toJSON(){return this._styles}getStyleByCell(s){let e;s&&R.isObject(s.s)?e=s.s:e=(s==null?void 0:s.s)&&this.get(s.s);const n=s==null?void 0:s.interceptorStyle;return n?{...e,...n}:e}_generateCacheMap(){const{_styles:s,_cacheMap:e}=this;for(const n in s){const r=JSON.stringify(s[n]);e.set(r,n)}}_getExistingStyleId(s){const{_styles:e}=this;for(const n in e)if(R.diffValue(e[n],s))return n;return null}}class qi{constructor(s,e){d(this,"_columnData",{});this._config=s,this._columnData=e}getColumnData(){return this._columnData}getColVisible(s){const{_columnData:e}=this,n=e[s];return n?n.hd!==C.TRUE:!0}getHiddenCols(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getColVisible(o);r&&a?(r=!1,n.push({rangeType:x.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!a&&(r=!0,i=o)}return r&&n.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:x.COLUMN}),n}getVisibleCols(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getColVisible(o);r&&!a?(r=!1,n.push({rangeType:x.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&a&&(r=!0,i=o)}return r&&n.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:x.COLUMN}),n}getColumnDatas(s,e){const n={};let r=0;for(let i=s;i<s+e;i++){const o=this.getColumnOrCreate(i);n[r]=o,r++}return n}getSize(){return y(this._columnData)}getColumnWidth(s){const{_columnData:e}=this,n=this._config;let r=0;return r=(e[s]||{hd:C.FALSE,w:n.defaultColumnWidth}).w||n.defaultColumnWidth,r}getColumn(s){const e=this._columnData[s];if(e)return e}getColumnOrCreate(s){const{_columnData:e}=this,n=this._config,r=e[s];if(r)return r;const i={w:n.defaultColumnWidth,hd:C.FALSE};return this._columnData[s]=i,i}}class Ji{constructor(s,e,n){d(this,"_rowData");this._config=s,this._viewModel=e,this._rowData=n}getRowData(){return this._rowData}getRowDatas(s,e){const n={};let r=0;for(let i=s;i<s+e;i++){const o=this.getRowOrCreate(i);n[r]=o,r++}return n}getRowHeight(s,e=1){const{_rowData:n}=this,r=this._config;let i=0;for(let o=0;o<e;o++){const a=n[o+s]||{hd:C.FALSE,h:r.defaultRowHeight},{ia:l,ah:u,h:c=r.defaultRowHeight}=a;i+=(l==null||l===C.TRUE)&&typeof u=="number"?u:c}return i}getRow(s){return this._rowData[s]}getRowOrCreate(s){const{_rowData:e}=this,n=e[s];if(n)return n;const r=this._config,i={hd:C.FALSE,h:r.defaultRowHeight};return e[s]=i,i}getHiddenRows(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getRowRawVisible(o);r&&a?(r=!1,n.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:x.ROW})):!r&&!a&&(r=!0,i=o)}return r&&n.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:x.ROW}),n}getVisibleRows(s=0,e=this.getSize()-1){const n=[];let r=!1,i=-1;for(let o=s;o<=e;o++){const a=this.getRowRawVisible(o);r&&!a?(r=!1,n.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:x.ROW})):!r&&a&&(r=!0,i=o)}return r&&n.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:x.ROW}),n}getRowRawVisible(s){const e=this.getRow(s);return e?e.hd!==C.TRUE:!0}getSize(){return y(this._rowData)}}const Zi="DEFAULT_WORKSHEET_ROW_COUNT",Nn=1e3,Qi="DEFAULT_WORKSHEET_COLUMN_COUNT",Sn=20,to="DEFAULT_WORKSHEET_ROW_HEIGHT",Ln=19,eo="DEFAULT_WORKSHEET_COLUMN_WIDTH",Tn=73,so="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",bn=46,no="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",wn=20;function vn(t){const s={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:C.FALSE,rowCount:Nn,columnCount:Sn,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Tn,defaultRowHeight:Ln,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:C.TRUE,rowHeader:{width:bn,hidden:C.FALSE},columnHeader:{height:wn,hidden:C.FALSE},selections:["A1"],rightToLeft:C.FALSE};return Object.keys(s).forEach(e=>{const n=e;typeof t[n]>"u"&&(t[n]=s[n])}),t}class Un extends p{constructor(e){super();d(this,"_cellContentInterceptor",null);d(this,"_rowFilteredInterceptor",null);this.getRawCell=e}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(e,n){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(e,n):this.getRawCell(e,n)}getRowFiltered(e){var n,r;return(r=(n=this._rowFilteredInterceptor)==null?void 0:n.getRowFiltered(e))!=null?r:!1}registerCellContentInterceptor(e){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=e,v(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(e){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=e,v(()=>this._rowFilteredInterceptor=null)}}class Et{constructor(s,e,n){d(this,"_sheetId");d(this,"_snapshot");d(this,"_cellData");d(this,"_rowManager");d(this,"_columnManager");d(this,"_viewModel");var a;this.unitId=s,this._styles=n,this._snapshot=vn(e);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(a=this._snapshot.id)!=null?a:R.generateRandomId(6),this._cellData=new G(o),this._viewModel=new Un((l,u)=>this.getCellRaw(l,u)),this._rowManager=new Ji(this._snapshot,this._viewModel,i),this._columnManager=new qi(this._snapshot,r)}__interceptViewModel(s){s(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const s=this.getCellMatrix(),e=this.getMergeData();let n=-1,r=-1,i=-1,o=-1,a=!1,l=!1;return s.forEach((u,c)=>{Object.keys(c).forEach(h=>{const _=+h,f=s.getValue(u,_),E=f!=null&&f.s?this._styles.get(f.s):null,g=(E==null?void 0:E.bd)&&(E.bd.b||E.bd.l||E.bd.r||E.bd.t||E.bd.bc_tr||E.bd.bl_tr||E.bd.ml_tr||E.bd.tl_bc||E.bd.tl_br||E.bd.tl_mr);(f&&(f.v||f.p)||E!=null&&E.bg||g)&&(a?n=Math.min(n,u):(n=u,a=!0),r=Math.max(r,u),l?i=Math.min(i,_):(l=!0,i=_),o=Math.max(o,_))})}),e.forEach(u=>{a?n=Math.min(n,u.startRow):(n=u.startRow,a=!0),r=Math.max(r,u.endRow),l?i=Math.min(i,u.startColumn):(i=u.startColumn,a=!0),o=Math.max(o,u.endColumn)}),!a||!l?null:{startColumn:i,startRow:n,endColumn:o,endRow:r}}getRowManager(){return this._rowManager}getUnitId(){return this.unitId}getSheetId(){return this._sheetId}getColumnManager(){return this._columnManager}getName(){return this._snapshot.name}clone(){const{_snapshot:s}=this,e=R.deepClone(s);return new Et(this.unitId,e,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(s,e){const n=this._snapshot.mergeData;for(let r=0;r<n.length;r++){const i=n[r];if(X.intersects({startRow:s,startColumn:e,endRow:s,endColumn:e},i))return i}return null}getCell(s,e){return s<0||e<0?null:this._viewModel.getCell(s,e)}getCellRaw(s,e){return this.getCellMatrix().getValue(s,e)}getRowFiltered(s){return this._viewModel.getRowFiltered(s)}getMatrixWithMergedCells(s,e,n,r,i=!1){const o=this.getCellMatrix(),a=this._snapshot.mergeData.filter(u=>X.intersects({startRow:s,startColumn:e,endRow:n,endColumn:r},u)),l=new G;return ie(s,n,e,r).forEach((u,c)=>{const h=i?this.getCellRaw(u,c):this.getCell(u,c);h&&l.setValue(u,c,h)}),a.forEach(u=>{const{startColumn:c,startRow:h,endColumn:_,endRow:f}=u;ie(h,f,c,_).forEach((E,g)=>{E===h&&g===c&&l.setValue(E,g,{...o.getValue(E,g),rowSpan:f-h+1,colSpan:_-c+1}),(E!==h||g!==c)&&l.realDeleteValue(E,g)})}),l}getRange(s,e,n,r){return typeof s=="object"?new et(this,s,{getStyles:()=>this._styles}):new et(this,{startRow:s,startColumn:e,endColumn:r||e,endRow:n||s},{getStyles:()=>this._styles})}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:s}=this,{columnCount:e}=s;return e}getMaxRows(){const{_snapshot:s}=this,{rowCount:e}=s;return e}getRowCount(){return this._snapshot.rowCount}setRowCount(s){this._snapshot.rowCount=s}getColumnCount(){return this._snapshot.columnCount}setColumnCount(s){this._snapshot.columnCount=s}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:s}=this,{showGridlines:e}=s;return e===0}getTabColor(){const{_snapshot:s}=this,{tabColor:e}=s;return e}getColumnWidth(s){return this.getColumnManager().getColumnWidth(s)}getRowHeight(s){return this._viewModel.getRowFiltered(s)?0:this.getRowManager().getRowHeight(s)}getRowVisible(s){return this._viewModel.getRowFiltered(s)?!1:this.getRowRawVisible(s)}getRowRawVisible(s){return this.getRowManager().getRowRawVisible(s)}getHiddenRows(s,e){const n=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(s,e);return r.forEach(i=>i.endColumn=n),r}getColVisible(s){return this._columnManager.getColVisible(s)}getHiddenCols(s,e){const n=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(s,e);return r.forEach(i=>i.endRow=n),r}getVisibleRows(){const s=this.getRowCount();return this._rowManager.getVisibleRows(0,s-1)}getVisibleCols(){const s=this.getColumnCount();return this._columnManager.getVisibleCols(0,s-1)}isRightToLeft(){const{_snapshot:s}=this,{rightToLeft:e}=s;return e}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(s){return s&&(s.v!==void 0||s.f!==void 0||s.p!==void 0)}iterateByRow(s,e=!0){const{startRow:n,startColumn:r,endRow:i,endColumn:o}=s,a=this;return{[Symbol.iterator]:()=>{let l=n,u=r;return{next(){for(;;){if(u>o&&(l+=1,u=r),l>i)return{done:!0,value:void 0};const c=a.getCell(l,u),h=!c,_=a.getMergedCell(l,u);if(_){if(l!==_.startRow||u!==_.startColumn){u=_.endColumn+1;continue}if(h&&e){u=_.endColumn+1;continue}const E={row:l,col:u,value:c};return E.colSpan=_.endColumn-_.startColumn+1,E.rowSpan=_.endRow-_.startRow+1,u=_.endColumn+1,{done:!1,value:E}}if(h&&e)u+=1;else{const f={row:l,col:u,value:c};return u+=1,{done:!1,value:f}}}}}}}}iterateByColumn(s,e=!0,n=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:a}=s,l=this;return{[Symbol.iterator]:()=>{let u=r,c=i;return{next(){for(;;){if(u>o&&(c+=1,u=r),c>a)return{done:!0,value:void 0};const h=l.getMergedCell(u,c);if(h){const E=u!==h.startRow,g=E||c!==h.startColumn;if(n&&g||!n&&E){u=h.endRow+1;continue}const m=l.getCell(h.startRow,h.startColumn);if(!m&&e){u=h.endRow+1;continue}const U={row:u,col:h.startColumn,value:m};return U.colSpan=h.endColumn-h.startColumn+1,U.rowSpan=h.endRow-h.startRow+1,u=h.endRow+1,{done:!1,value:U}}const _=l.getCell(u,c);if(!_&&e)u+=1;else{const E={row:u,col:c,value:_};return u+=1,{done:!1,value:E}}}}}}}}}function ro(t){var n,r;if(!t)return"";const s=(r=(n=t.p)==null?void 0:n.body)==null?void 0:r.dataStream;if(s)return s;const e=t.v;return typeof e=="string"?t.t===Q.BOOLEAN?e.toUpperCase():e:typeof e=="number"?t.t===Q.BOOLEAN?e?"TRUE":"FALSE":e.toString():typeof e=="boolean"?e?"TRUE":"FALSE":""}const io="0.1.9";function oo(t="",s=nt.ZH_CN,e=""){return{id:t,sheetOrder:[],name:e,appVersion:io,locale:s,styles:{},sheets:{},resources:[]}}var ao=Object.defineProperty,lo=Object.getOwnPropertyDescriptor,uo=(t,s,e,n)=>{for(var r=n>1?void 0:n?lo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&ao(s,e,r),r},co=(t,s)=>(e,n)=>s(e,n,t);function ho(t,s){return`${t.getUnitId()}|${s.getSheetId()}`}exports.Workbook=class extends Vt{constructor(e={},n){super();d(this,"type",O.UNIVER_SHEET);d(this,"_sheetCreated$",new L.Subject);d(this,"sheetCreated$",this._sheetCreated$.asObservable());d(this,"_sheetDisposed$",new L.Subject);d(this,"sheetDisposed$",this._sheetDisposed$.asObservable());d(this,"_activeSheet$",new L.BehaviorSubject(null));d(this,"activeSheet$",this._activeSheet$.asObservable());d(this,"_worksheets");d(this,"_styles");d(this,"_snapshot");d(this,"_unitId");d(this,"_count");this._logService=n;const r=oo();R.isEmptyObject(e)?this._snapshot=r:this._snapshot=R.commonExtend(r,e);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=R.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new An(i),this._count=1,this._worksheets=new Map,this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._snapshot.name}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete()}save(){return R.deepClone(this._snapshot)}static isIRangeType(e){return typeof e=="string"||"startRow"in e||"row"in e}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}getUnitId(){return this._unitId}getRev(){var e;return(e=this._snapshot.rev)!=null?e:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(e,n,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[e])return!1;i[e]=r,o.splice(n,0,e);const a=new Et(this._unitId,r,this._styles);return this._worksheets.set(e,a),this._sheetCreated$.next(a),!0}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(e){const{sheetOrder:n}=this._snapshot;return n.findIndex(r=>r===e)}getRawActiveSheet(){return this._activeSheet}getActiveSheet(){const e=this.getRawActiveSheet();if(e)return e;const n=this._snapshot.sheetOrder;for(let i=0,o=n.length;i<o;i++){const a=this._worksheets.get(n[i]);if(a&&a.isSheetHidden()!==C.TRUE)return this.setActiveSheet(a),a}const r=this._worksheets.get(n[0]);return this.setActiveSheet(r),r}setActiveSheet(e){this._activeSheet$.next(e)}removeSheet(e){var r;return this._worksheets.get(e)?(((r=this._activeSheet)==null?void 0:r.getSheetId())===e&&this.setActiveSheet(null),this._worksheets.delete(e),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(e),1),delete this._snapshot.sheets[e],!0):!1}getActiveSheetIndex(){const{sheetOrder:e}=this._snapshot;return e.findIndex(n=>this._worksheets.get(n)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:e}=this._snapshot;return e.map(n=>this._worksheets.get(n))}getSheetsName(){const{sheetOrder:e}=this._snapshot,n=[];return e.forEach(r=>{const i=this._worksheets.get(r);i&&n.push(i.getName())}),n}getSheetIndex(e){const{sheetOrder:n}=this._snapshot;return n.findIndex(r=>e.getSheetId()===r)}getSheetBySheetName(e){const{sheetOrder:n}=this._snapshot,r=n.find(i=>this._worksheets.get(i).getName()===e);return this._worksheets.get(r)}getSheetBySheetId(e){return this._worksheets.get(e)}getSheetByIndex(e){const{sheetOrder:n}=this._snapshot;return this._worksheets.get(n[e])}getHiddenWorksheets(){return this.getSheets().filter(e=>e.getConfig().hidden===C.TRUE).map(e=>e.getConfig().id)}transformRangeType(e){if(typeof e=="string")return this._getCellRange(e);if(typeof e!="string"&&"row"in e){const n=e;return{sheetId:"",range:{startRow:n.row[0],startColumn:n.column[0],endRow:n.row[1],endColumn:n.column[1]}}}return typeof e!="string"&&"startRow"in e?{sheetId:"",range:e}:lt}load(e){this._snapshot=e}checkSheetName(e){return this.getSheetsName().includes(e)}uniqueSheetName(e="Sheet1"){let n=e;for(;this.checkSheetName(n);)n=e+this._count,this._count++;return n}generateNewSheetName(e){let n=e+this._count;for(;this.checkSheetName(n);)n=e+this._count,this._count++;return n}_getCellRange(e){var c,h,_,f,E;let n="",r="";if(e.indexOf("!")>-1){const g=e.split("!");n=g[0],r=g[1],n=n.replace(/\\'/g,"'").replace(/''/g,"'"),n.substring(0,1)==="'"&&n.substring(n.length-1,1)==="'"&&(n=n.substring(1,n.length-1))}else r=e;if(r.indexOf(":")===-1){const g=Number.parseInt(r.replace(/[^0-9]/g,""),10)-1,m=R.ABCatNum(r.replace(/[^A-Za-z]/g,""));return!Number.isNaN(g)&&!Number.isNaN(m)?{sheetId:n,range:{startRow:g,endRow:g,startColumn:m,endColumn:m}}:lt}r=r.split(":");const i=[0,0],o=[0,0],a=((c=this.getSheetBySheetName(n))==null?void 0:c.getMaxRows())||((h=this.getActiveSheet())==null?void 0:h.getMaxRows()),l=((_=this.getSheetBySheetName(n))==null?void 0:_.getMaxColumns())||((f=this.getActiveSheet())==null?void 0:f.getMaxColumns());return i[0]=Number.parseInt(r[0].replace(/[^0-9]/g,""),10)-1,i[1]=Number.parseInt(r[1].replace(/[^0-9]/g,""),10)-1,Number.isNaN(i[0])&&(i[0]=0),Number.isNaN(i[1])&&(i[1]=a),i[0]>i[1]||(o[0]=R.ABCatNum(r[0].replace(/[^A-Za-z]/g,"")),o[1]=R.ABCatNum(r[1].replace(/[^A-Za-z]/g,"")),Number.isNaN(o[0])&&(o[0]=0),Number.isNaN(o[1])&&(o[1]=l),o[0]>o[1])?lt:{sheetId:((E=this.getSheetBySheetName(n))==null?void 0:E.getSheetId())||"",range:{startRow:i[0],endRow:i[1],startColumn:o[0],endColumn:o[1]}}}_passWorksheetSnapshots(){const{_snapshot:e,_worksheets:n}=this,{sheets:r,sheetOrder:i}=e;if(R.isEmptyObject(r)){const o=R.generateRandomId();r[o]={id:o}}for(const o in r){const a=r[o],{name:l}=a;a.name=this.uniqueSheetName(l),a.name!==l&&this._logService.debug("[Workbook]",`The worksheet name ${l} is duplicated, we changed it to ${a.name}. Please fix the problem in your snapshot.`);const u=new Et(this._unitId,a,this._styles);n.set(o,u),i.includes(o)||i.push(o)}}};exports.Workbook=uo([co(1,J)],exports.Workbook);class Te extends Vt{constructor(e){var n;super();d(this,"type",O.UNIVER_SLIDE);d(this,"_snapshot");d(this,"_unitId");this._snapshot={...qs,...e},this._unitId=(n=this._snapshot.id)!=null?n:R.generateRandomId(6)}getContainer(){return this._snapshot.container}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var e;return(e=this._snapshot.body)==null?void 0:e.pages}getPageOrder(){var e;return(e=this._snapshot.body)==null?void 0:e.pageOrder}getPage(e){const n=this.getPages();return n==null?void 0:n[e]}getElementsByPage(e){var n;return(n=this.getPage(e))==null?void 0:n.pageElements}getElement(e,n){var r;return(r=this.getElementsByPage(e))==null?void 0:r[n]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:de.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const ht="FOCUSING_SHEET",bt="FOCUSING_DOC",wt="FOCUSING_SLIDE",_o="FOCUSING_EDITOR_BUT_HIDDEN",Dn="EDITOR_ACTIVATED",fo="FOCUSING_EDITOR_INPUT_FORMULA",pn="FOCUSING_FORMULA_EDITOR",Eo="FOCUSING_UNIVER_EDITOR",go="FOCUSING_EDITOR_INPUT_FORMULA",Ro="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE";var mo=Object.defineProperty,Co=Object.getOwnPropertyDescriptor,Oo=(t,s,e,n)=>{for(var r=n>1?void 0:n?Co(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&mo(s,e,r),r},Be=(t,s)=>(e,n)=>s(e,n,t);const q=A.createIdentifier("univer.current");exports.UniverInstanceService=class extends p{constructor(e,n){super();d(this,"_unitsByType",new Map);d(this,"_createHandler");d(this,"_ctorByType",new Map);d(this,"_currentUnits$",new L.BehaviorSubject({}));d(this,"currentUnits$",this._currentUnits$.asObservable());d(this,"_unitAdded$",new L.Subject);d(this,"unitAdded$",this._unitAdded$.asObservable());d(this,"_unitDisposed$",new L.Subject);d(this,"unitDisposed$",this._unitDisposed$.asObservable());d(this,"_focused$",new L.BehaviorSubject(null));d(this,"focused$",this._focused$.asObservable());this._injector=e,this._contextService=n}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(e){this._createHandler=e}createUnit(e,n){return this._createHandler(e,n,this._ctorByType.get(e))}registerCtorForType(e,n){return this._ctorByType.set(e,n),{dispose:()=>{this._ctorByType.delete(e)}}}getCurrentTypeOfUnit$(e){return this.currentUnits$.pipe(L.map(n=>{var r;return(r=n[e])!=null?r:null}),L.distinctUntilChanged())}getCurrentUnitForType(e){return this._currentUnits$.getValue()[e]}setCurrentUnitForType(e){const n=this._getUnitById(e);if(!n)throw new Error(`[UniverInstanceService]: no document with unitId ${e}!`);this._currentUnits$.next({...this._currentUnits$.getValue(),[n[1]]:n[0]})}getTypeOfUnitAdded$(e){return this._unitAdded$.pipe(L.filter(n=>n.type===e))}__addUnit(e){const n=e.type;this._unitsByType.has(n)||this._unitsByType.set(n,[]),this._unitsByType.get(n).push(e),this._unitAdded$.next(e),this._currentUnits$.next({...this._currentUnits$.getValue(),[n]:e})}getTypeOfUnitDisposed$(e){return this.unitDisposed$.pipe(L.filter(n=>n.type===e))}getUnit(e,n){var i;const r=(i=this._getUnitById(e))==null?void 0:i[0];return n&&(r==null?void 0:r.type)!==n?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(O.UNIVER_DOC)}getUniverDocInstance(e){return this.getUnit(e,O.UNIVER_DOC)}getUniverSheetInstance(e){return this.getUnit(e,O.UNIVER_SHEET)}getAllUnitsForType(e){var n;return(n=this._unitsByType.get(e))!=null?n:[]}changeDoc(e,n){const r=this.getAllUnitsForType(O.UNIVER_DOC),i=r.find(o=>o.getUnitId()===e);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(n)}get focused(){var n;const e=this._focused$.getValue();return e?(n=this._getUnitById(e))==null?void 0:n[0]:null}focusUnit(e){this._focused$.next(e),this.focused instanceof exports.Workbook?(this._contextService.setContextValue(bt,!1),this._contextService.setContextValue(ht,!0),this._contextService.setContextValue(wt,!1)):this.focused instanceof st?(this._contextService.setContextValue(bt,!0),this._contextService.setContextValue(ht,!1),this._contextService.setContextValue(wt,!1)):this.focused instanceof Te&&(this._contextService.setContextValue(bt,!1),this._contextService.setContextValue(ht,!1),this._contextService.setContextValue(wt,!0))}getFocusedUnit(){return this.focused}getUnitType(e){const n=this._getUnitById(e);if(!n)throw new Error(`[UniverInstanceService]: No document with unitId ${e}`);return n[1]}disposeUnit(e){const n=this._getUnitById(e);if(!n)return!1;const[r,i]=n,o=this._unitsByType.get(i),a=o.indexOf(r);return o.splice(a,1),this._unitDisposed$.next(r),this._currentUnits$.next({...this._currentUnits$.getValue(),[i]:null}),this._focused$.next(null),!0}_getUnitById(e){for(const[n,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===e);if(i)return[i,n]}}};exports.UniverInstanceService=Oo([Be(0,A.Inject(A.Injector)),Be(1,gt)],exports.UniverInstanceService);var b=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(b||{});const Io={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},vt=new Map;function be(t,s){return function(r){we(t,s)}}function we(t,s){vt.has(t)||vt.set(t,[]),vt.get(t).push(s)}var Ao=Object.defineProperty,No=Object.getOwnPropertyDescriptor,Mn=(t,s,e,n)=>{for(var r=n>1?void 0:n?No(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Ao(s,e,r),r},le=(t,s)=>(e,n)=>s(e,n,t);exports.LifecycleService=class extends p{constructor(e){super();d(this,"_lifecycle$",new L.BehaviorSubject(b.Starting));d(this,"lifecycle$",this._lifecycle$.asObservable());d(this,"_lock",!1);this._logService=e,this._reportProgress(b.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(e){if(e<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(e!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(e),this._lifecycle$.next(e),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new L.Observable(e=>(this.stage===b.Starting||(this.stage===b.Ready?e.next(b.Starting):this.stage===b.Rendered?(e.next(b.Starting),e.next(b.Ready)):(e.next(b.Starting),e.next(b.Ready),e.next(b.Rendered))),this._lifecycle$.subscribe(e)))}_reportProgress(e){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${Io[e]}".`)}};exports.LifecycleService=Mn([le(0,J)],exports.LifecycleService);exports.LifecycleInitializerService=class extends p{constructor(e,n){super();d(this,"_seenTokens",new Set);this._lifecycleService=e,this._injector=n}initModulesOnStage(e){var n;(n=vt.get(e))==null||n.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}};exports.LifecycleInitializerService=Mn([le(0,A.Inject(exports.LifecycleService)),le(1,A.Inject(A.Injector))],exports.LifecycleInitializerService);class dt extends p{constructor(){super();d(this,"_currentLocale",nt.ZH_CN);d(this,"_locales",null);d(this,"localeChanged$",new L.Subject);d(this,"t",(e,...n)=>{if(!this._locales)throw new Error("Locale not initialized");const r=e.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return n.forEach((a,l)=>{o=o.replace(`{${l}}`,a)}),o}else return e});this.disposeWithMe(v(()=>this.localeChanged$.complete()))}load(e){var n;this._locales=R.deepMerge((n=this._locales)!=null?n:{},e)}setLocale(e){this._currentLocale=e,this.localeChanged$.next()}getLocales(){var e;return(e=this._locales)==null?void 0:e[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(e,n){const r=n.shift();if(r&&e&&r in e){const i=e[r];return n.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,n):i}return null}}const Kt=A.createIdentifier("resource-manager-service");var So=Object.defineProperty,Lo=Object.getOwnPropertyDescriptor,To=(t,s,e,n)=>{for(var r=n>1?void 0:n?Lo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&So(s,e,r),r},ke=(t,s)=>(e,n)=>s(e,n,t);const ve=A.createIdentifier("univer.permission-service");exports.PermissionService=class extends p{constructor(e,n){super();d(this,"_permissionPointMap",new Map);d(this,"deletePermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e);if(r){const i=r.get(n);i&&(i.complete(),this._permissionPointMap.delete(n))}});d(this,"addPermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e)||new Map;return r.has(n.id)?!1:(r.set(n.id,new L.BehaviorSubject(n)),this._permissionPointMap.set(e,r),!0)});d(this,"updatePermissionPoint",(e,n,r)=>{const i=this._permissionPointMap.get(e);if(!i)return;const o=i.get(n);if(o){const a=o.getValue();a.value=r,a.status=ge.DONE,o.next(a)}});d(this,"getPermissionPoint",(e,n)=>{const r=this._permissionPointMap.get(e);if(!r)return;const i=r.get(n);if(i)return i.getValue()});this._resourceManagerService=e,this._univerInstanceService=n}_toJson(e){const n=this._permissionPointMap.get(e);let r=[];return n&&(r=[...n.keys()].reduce((i,o)=>{const a=n.get(o);return a&&i.push(a.getValue()),i},[])),JSON.stringify(r)}_parseJson(e){return JSON.parse(e)}composePermission$(e,n){const r=this._permissionPointMap.get(e),i=n.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.asObservable()});return L.combineLatest(i).pipe(rr.map(o=>(o.every(a=>this._permissionPointMap.get(a.id)),o)))}composePermission(e,n){const r=this._permissionPointMap.get(e);return n.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.getValue()})}};exports.PermissionService=To([be(b.Starting,exports.PermissionService),ke(0,A.Inject(Kt)),ke(1,A.Inject(q))],exports.PermissionService);const Pn="univer.editable";class Ut extends zs{constructor(e){super();d(this,"id",Pn);d(this,"value",!0);d(this,"unitID");this.unitID=e}}var bo=Object.defineProperty,wo=Object.getOwnPropertyDescriptor,vo=(t,s,e,n)=>{for(var r=n>1?void 0:n?wo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&bo(s,e,r),r},Ge=(t,s)=>(e,n)=>s(e,n,t);exports.UniverPermissionService=class extends p{constructor(s,e){super(),this._permissionService=s,this._univerInstanceService=e,this._init()}_init(){this._univerInstanceService.getTypeOfUnitAdded$(O.UNIVER_SHEET).subscribe(s=>{const e=new Ut(s.getUnitId());this._permissionService.addPermissionPoint(s.getUnitId(),e)})}getEditable(s=(e=>(e=this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET))==null?void 0:e.getUnitId())()){if(!s)return;const n=new Ut(s),r=this._permissionService.getPermissionPoint(s,n.id);return r==null?void 0:r.value}setEditable(s,e){const n=new Ut(s);this._permissionService.updatePermissionPoint(s,n.id,e)}};exports.UniverPermissionService=vo([be(b.Starting,exports.UniverPermissionService),Ge(0,A.Inject(ve)),Ge(1,A.Inject(q))],exports.UniverPermissionService);class xn extends p{constructor(){super(...arguments);d(this,"_resourceMap",new Map);d(this,"_register$",new L.Subject);d(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(e){return this.getAllResourceHooks().map(i=>{const o=i.toJson(e);return{name:i.pluginName,data:o}})}registerPluginResource(e){const n=e.pluginName;if(this._resourceMap.has(n))throw new Error(`the pluginName is registered {${n}}`);return this._resourceMap.set(n,e),this._register$.next(e),v(()=>this._resourceMap.delete(n))}disposePluginResource(e){this._resourceMap.delete(e)}loadResources(e,n){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=n==null?void 0:n.find(a=>a.name===r.pluginName))==null?void 0:o.data;if(i)try{const a=r.parseJson(i);r.onLoad(e,a)}catch{console.error("LoadResources Error!")}})}unloadResources(e){this.getAllResourceHooks().forEach(n=>{n.onUnLoad(e)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}var Uo=Object.defineProperty,Do=Object.getOwnPropertyDescriptor,po=(t,s,e,n)=>{for(var r=n>1?void 0:n?Do(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Uo(s,e,r),r},$e=(t,s)=>(e,n)=>s(e,n,t);let ue=class extends p{constructor(s,e){super();d(this,"saveWorkbook",s=>{const e=s.getUnitId(),n=this._resourceManagerService.getResources(e)||[],r=s.getSnapshot();return r.resources=n,r});this._resourceManagerService=s,this._univerInstanceService=e,this._init()}_init(){const s=n=>{n.businesses.forEach(r=>{switch(r){case O.UNRECOGNIZED:case O.UNIVER_UNKNOWN:case O.UNIVER_SLIDE:case O.UNIVER_DOC:break;case O.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(O.UNIVER_SHEET).forEach(i=>{const a=(i.getSnapshot().resources||[]).find(l=>l.name===n.pluginName);if(a)try{const l=n.parseJson(a.data);n.onLoad(i.getUnitId(),l)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${n.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(n=>{s(n)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(n=>{s(n)})),this.disposeWithMe(v(this._univerInstanceService.getTypeOfUnitAdded$(O.UNIVER_SHEET).subscribe(n=>{this._resourceManagerService.loadResources(n.getUnitId(),n.getSnapshot().resources)}))),this.disposeWithMe(v(this._univerInstanceService.getTypeOfUnitDisposed$(O.UNIVER_SHEET).subscribe(n=>{this._resourceManagerService.unloadResources(n.getUnitId())})))}};ue=po([$e(0,A.Inject(Kt)),$e(1,A.Inject(q))],ue);const Ue=A.createIdentifier("resource-loader-service");we(b.Ready,Ue);class De extends p{constructor(){super();d(this,"_currentTheme");d(this,"_currentTheme$",new L.BehaviorSubject({}));d(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(v(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(e){this._currentTheme=e,this._currentTheme$.next(e)}}const Hn="__defaultDocumentNormalEditorSpecialUnitId_20231006__",Fn="__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__",Mo=`\r
7
7
  `;function Po(t){return`__internalEditorId__${t}`}function xo(t){return t.startsWith("__")}var Ho=Object.defineProperty,Fo=Object.getOwnPropertyDescriptor,Wo=(t,s,e,n)=>{for(var r=n>1?void 0:n?Fo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Ho(s,e,r),r},Zt=(t,s)=>(e,n)=>s(e,n,t);const Yt=A.createIdentifier("univer.undo-redo.service"),Bo=20;class Wn{dispose(){}async dispatchToHandlers(){return!1}}const Bn="univer.command.redo",kn="univer.command.undo",Gn=new class extends Wn{constructor(){super(...arguments);d(this,"type",jt.COMMAND);d(this,"id",kn)}async handler(s){const e=s.get(Yt),n=e.pitchTopUndoElement();if(!n)return!1;const r=s.get(Rt);return Le(n.undoMutations,r)?(e.popUndoToRedo(),!0):!1}},$n=new class extends Wn{constructor(){super(...arguments);d(this,"type",jt.COMMAND);d(this,"id",Bn)}async handler(s){const e=s.get(Yt),n=e.pitchTopRedoElement();if(!n)return!1;const r=s.get(Rt);return Le(n.redoMutations,r)?(e.popRedoToUndo(),!0):!1}};exports.LocalUndoRedoService=class extends p{constructor(e,n,r){super();d(this,"undoRedoStatus$");d(this,"_undoRedoStatus$",new L.BehaviorSubject({undos:0,redos:0}));d(this,"_undoStacks",new Map);d(this,"_redoStacks",new Map);d(this,"_batchingStatus",new Map);this._univerInstanceService=e,this._commandService=n,this._contextService=r,this.undoRedoStatus$=this._undoRedoStatus$.asObservable(),this.disposeWithMe(this._commandService.registerCommand(Gn)),this.disposeWithMe(this._commandService.registerCommand($n)),this.disposeWithMe(v(()=>this._undoRedoStatus$.complete())),this.disposeWithMe(v(this._univerInstanceService.focused$.subscribe(()=>this._updateStatus())))}pushUndoRedo(e){const{unitID:n}=e,r=this._getRedoStack(n,!0),i=this._getUndoStack(n,!0);if(r.length=0,this._batchingStatus.has(e.unitID)){const a=this._batchingStatus.get(e.unitID),l=this._pitchUndoElement(e.unitID);a===0||!l?(o(e),this._batchingStatus.set(e.unitID,1)):this._tryBatchingElements(l,e)}else o(e);function o(a){i.push(a),i.length>Bo&&i.splice(0,1)}this._updateStatus()}clearUndoRedo(e){const n=this._getRedoStack(e);n&&(n.length=0);const r=this._getUndoStack(e);r&&(r.length=0),this._updateStatus()}pitchTopUndoElement(){const e=this._getFocusedUnitId();return this._pitchUndoElement(e)}pitchTopRedoElement(){const e=this._getFocusedUnitId();return this._pitchRedoElement(e)}_pitchUndoElement(e){const n=this._getUndoStack(e);return n!=null&&n.length?n[n.length-1]:null}_pitchRedoElement(e){const n=this._getRedoStack(e);return n!=null&&n.length?n[n.length-1]:null}popUndoToRedo(){const n=this._getUndoStackForFocused().pop();n&&(this._getRedoStackForFocused().push(n),this._updateStatus())}popRedoToUndo(){const n=this._getRedoStackForFocused().pop();n&&(this._getUndoStackForFocused().push(n),this._updateStatus())}__tempBatchingUndoRedo(e){if(this._batchingStatus.has(e))throw new Error("[LocalUndoRedoService]: cannot batching undo redo twice at the same time!");return this._batchingStatus.set(e,0),v(()=>this._batchingStatus.delete(e))}_updateStatus(){var i,o;const e=this._getFocusedUnitId(),n=e&&((i=this._undoStacks.get(e))==null?void 0:i.length)||0,r=e&&((o=this._redoStacks.get(e))==null?void 0:o.length)||0;this._undoRedoStatus$.next({undos:n,redos:r})}_getUndoStack(e,n=!1){let r=this._undoStacks.get(e);return!r&&n&&(r=[],this._undoStacks.set(e,r)),r||null}_getRedoStack(e,n=!1){let r=this._redoStacks.get(e);return!r&&n&&(r=[],this._redoStacks.set(e,r)),r||null}_getUndoStackForFocused(){const e=this._getFocusedUnitId();if(!e)throw new Error("No focused univer instance!");return this._getUndoStack(e,!0)}_getRedoStackForFocused(){const e=this._getFocusedUnitId();if(!e)throw new Error("No focused univer instance!");return this._getRedoStack(e,!0)}_tryBatchingElements(e,n){e.redoMutations.push(...n.redoMutations),e.undoMutations.push(...n.undoMutations)}_getFocusedUnitId(){var o,a,l,u;let e="";const n=this._contextService.getContextValue(ht),r=this._contextService.getContextValue(pn),i=this._contextService.getContextValue(Dn);return n?r?e=Fn:i?e=Hn:e=(a=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId())!=null?a:"":e=(u=(l=this._univerInstanceService.getFocusedUnit())==null?void 0:l.getUnitId())!=null?u:"",e}};exports.LocalUndoRedoService=Wo([Zt(0,q),Zt(1,Rt),Zt(2,gt)],exports.LocalUndoRedoService);class ce extends p{onStarting(s){}onReady(){}onRendered(){}onSteady(){}getUniverInstanceType(){return this.constructor.type}getPluginName(){return this.constructor.pluginName}}d(ce,"pluginName"),d(ce,"type",O.UNIVER_UNKNOWN);class ko{constructor(){d(this,"_plugins",[])}addPlugin(s){this._plugins.push(s)}removePlugins(){const s=this._plugins.slice();return this._plugins.length=0,s}forEachPlugin(s){this._plugins.forEach(s)}}class Go{constructor(){d(this,"_pluginsRegistered",[])}registerPlugin(s,e){this._pluginsRegistered.push({plugin:s,options:e})}getRegisterPlugins(){return this._pluginsRegistered.slice()}removePlugins(){this._pluginsRegistered=[]}}var $o=Object.defineProperty,Vo=Object.getOwnPropertyDescriptor,jo=(t,s,e,n)=>{for(var r=n>1?void 0:n?Vo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&$o(s,e,r),r},Nt=(t,s)=>(e,n)=>s(e,n,t);exports.PluginHolder=class extends p{constructor(e,n,r,i){super();d(this,"_started",!1);d(this,"_pluginRegistered",new Set);d(this,"_pluginStore",new ko);d(this,"_pluginRegistry",new Go);this._logService=e,this._injector=n,this._lifecycleService=r,this._lifecycleInitializerService=i}get started(){return this._started}dispose(){super.dispose(),this._pluginStore.forEachPlugin(e=>e.dispose()),this._pluginStore.removePlugins(),this._pluginRegistry.removePlugins(),this._pluginRegistered.clear()}registerPlugin(e,n){const{pluginName:r}=e;if(this._pluginRegistered.has(r)){this._logService.warn("[PluginService]",`plugin ${r} has already been registered. This registration will be ignored.`);return}this._pluginRegistered.add(r),this._pluginRegistry.registerPlugin(e,n)}start(){this._started||(this._started=!0,this.flush())}flush(){if(!this._started)return;const e=this._pluginRegistry.getRegisterPlugins().map(({plugin:r,options:i})=>this._initPlugin(r,i));this._pluginRegistry.removePlugins();const n=this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().subscribe(r=>{this._pluginsRunLifecycle(e,r),r===b.Steady&&n.dispose()}))}_pluginsRunLifecycle(e,n){e.forEach(r=>{switch(n){case b.Starting:r.onStarting(this._injector);break;case b.Ready:r.onReady();break;case b.Rendered:r.onRendered();break;case b.Steady:r.onSteady();break}}),this._lifecycleInitializerService.initModulesOnStage(n)}_initPlugin(e,n){return this._injector.createInstance(e,n)}};exports.PluginHolder=jo([Nt(0,J),Nt(1,A.Inject(A.Injector)),Nt(2,A.Inject(exports.LifecycleService)),Nt(3,A.Inject(exports.LifecycleInitializerService))],exports.PluginHolder);var Ko=Object.defineProperty,Yo=Object.getOwnPropertyDescriptor,zo=(t,s,e,n)=>{for(var r=n>1?void 0:n?Yo(s,e):s,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(n?o(s,e,r):o(r))||r);return n&&r&&Ko(s,e,r),r},yo=(t,s)=>(e,n)=>s(e,n,t);const Xo=4;exports.PluginService=class{constructor(s){d(this,"_pluginHolderForUniver");d(this,"_pluginHoldersForTypes",new Map);d(this,"_flushTimer");this._injector=s,this._pluginHolderForUniver=this._injector.createInstance(exports.PluginHolder),this._pluginHolderForUniver.start()}dispose(){this._clearFlushTimer();for(const s of this._pluginHoldersForTypes.values())s.dispose();this._pluginHolderForUniver.dispose()}registerPlugin(s,e){this._assertPluginValid(s),this._scheduleInitPlugin();const{type:n}=s;n===O.UNIVER_UNKNOWN?(this._pluginHolderForUniver.registerPlugin(s,e),this._pluginHolderForUniver.flush()):this._ensurePluginHolderForType(n).registerPlugin(s,e)}startPluginForType(s){this._ensurePluginHolderForType(s).start()}_ensurePluginHolderForType(s){if(!this._pluginHoldersForTypes.has(s)){const e=this._injector.createInstance(exports.PluginHolder);return this._pluginHoldersForTypes.set(s,e),e}return this._pluginHoldersForTypes.get(s)}_assertPluginValid(s){const{type:e,pluginName:n}=s;if(e===O.UNRECOGNIZED)throw new Error(`[PluginService]: invalid plugin type for ${s}. Please assign a "type" to your plugin.`);if(n==="")throw new Error(`[PluginService]: no plugin name for ${s}. Please assign a "pluginName" to your plugin.`)}_scheduleInitPlugin(){this._flushTimer===void 0&&(this._flushTimer=setTimeout(()=>{this._pluginHolderForUniver.started||this._pluginHolderForUniver.start(),this._flushPlugins(),this._clearFlushTimer()},Xo))}_clearFlushTimer(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=void 0)}_flushPlugins(){this._pluginHolderForUniver.flush();for(const[s,e]of this._pluginHoldersForTypes)e.started&&e.flush()}};exports.PluginService=zo([yo(0,A.Inject(A.Injector))],exports.PluginService);function Vn(t,s){if(!s)return t;const e=[];for(const n of t){if(n.length===1){e.push(n);continue}const r=s.find(([i])=>i===n[0]);if(r){if(r[1]===null)continue;e.push([n[0],r[1]])}else e.push(n)}return e}class qo{constructor(s={},e){d(this,"_startedTypes",new Set);d(this,"_injector");const n=this._injector=Jo(e,s==null?void 0:s.override),{theme:r,locale:i,locales:o,logLevel:a}=s;r&&this._injector.get(De).setTheme(r),o&&this._injector.get(dt).load(o),i&&this._injector.get(dt).setLocale(i),a&&this._injector.get(J).setLogLevel(a),this._init(n),this._pluginService}get _univerInstanceService(){return this._injector.get(q)}get _pluginService(){return this._injector.get(exports.PluginService)}__getInjector(){return this._injector}dispose(){this._injector.dispose()}setLocale(s){this._injector.get(dt).setLocale(s)}createUnit(s,e){return this._univerInstanceService.createUnit(s,e)}createUniverSheet(s){return this._univerInstanceService.createUnit(O.UNIVER_SHEET,s)}createUniverDoc(s){return this._univerInstanceService.createUnit(O.UNIVER_DOC,s)}createUniverSlide(s){return this._univerInstanceService.createUnit(O.UNIVER_SLIDE,s)}_init(s){this._univerInstanceService.registerCtorForType(O.UNIVER_SHEET,exports.Workbook),this._univerInstanceService.registerCtorForType(O.UNIVER_DOC,st),this._univerInstanceService.registerCtorForType(O.UNIVER_SLIDE,Te);const e=s.get(q);e.__setCreateHandler((n,r,i)=>{if(!this._startedTypes.has(n)){this._pluginService.startPluginForType(n),this._startedTypes.add(n);const a=s.createInstance(i,r);return e.__addUnit(a),this._tryProgressToReady(),a}const o=s.createInstance(i,r);return e.__addUnit(o),o})}_tryProgressToReady(){this._injector.get(exports.LifecycleService).stage<b.Ready&&(this._injector.get(exports.LifecycleService).stage=b.Ready)}registerPlugin(s,e){this._pluginService.registerPlugin(s,e)}}function Jo(t,s){const e=Vn([[Cn],[dt],[De],[exports.LifecycleService],[exports.LifecycleInitializerService],[exports.UniverPermissionService],[exports.PluginService],[q,{useClass:exports.UniverInstanceService}],[ve,{useClass:exports.PermissionService}],[J,{useClass:En,lazy:!0}],[Rt,{useClass:exports.CommandService,lazy:!0}],[Yt,{useClass:exports.LocalUndoRedoService,lazy:!0}],[Rn,{useClass:mn}],[gt,{useClass:_n}],[In,{useClass:On,lazy:!0}],[Kt,{useClass:xn,lazy:!0}],[Ue,{useClass:ue,lazy:!0}]],s);return t?t.createChild(e):new A.Injector(e)}const Zo=(t,s)=>s.length===t.length&&!t.some(e=>s.some(n=>!X.equals(n,e))),Qo=(t,s)=>s.length===t.length&&t.every((e,n)=>{const r=s[n];return r.unitId===e.unitId&&r.sheetId===e.sheetId&&X.equals(e.range,r.range)});function ta(t,s){if(Object.is(t,s))return!0;if(typeof t!="object"||!t||typeof s!="object"||!s)return!1;const e=Object.keys(t),n=Object.keys(s);if(e.length!==n.length)return!1;const r=Object.prototype.hasOwnProperty.bind(s);for(let i=0;i<e.length;i++){const o=e[i];if(!r(o))return!1;const a=t[o],l=s[o];if(a!==l)return!1}return!0}function jn(t){return/^-?\d+(\.\d+)?$/.test(t)}function ea(t){return jn(t)?Number(t)<=Number.MAX_SAFE_INTEGER:!1}function sa(t){return["true","false"].includes(t.toLowerCase())}function na(t,s){return s.forEach(e=>t.add(e)),t}function ra(t,s=16){let e=0,n=null;return function(...i){const o=Date.now();o-e<s?(n&&clearTimeout(n),n=setTimeout(()=>{e=o,t.apply(this,i)},s)):(e=o,t.apply(this,i))}}function ia(t){const s=new MessageChannel;let e=!1;return s.port1.onmessage=()=>{e||t()},s.port2.postMessage(null),()=>{e=!0}}var Kn=(t=>(t[t.TEXT=0]="TEXT",t[t.ARROW=1]="ARROW",t[t.CUSTOM=2]="CUSTOM",t))(Kn||{});class he{constructor(s){d(this,"_index",0);d(this,"_offset",0);this._actions=s}hasNext(){return this.peekLength()<Number.POSITIVE_INFINITY}next(s){s||(s=Number.POSITIVE_INFINITY);const e=this._actions[this._index];if(e){const n=this._offset,r=e.len;return s>=r-n?(s=r-n,this._index+=1,this._offset=0):this._offset+=s,e.t===I.DELETE||e.t===I.RETAIN&&e.body==null?R.deepClone({...e,len:s}):R.deepClone({...e,len:s,body:Ne(e.body,n,n+s)})}else return{t:I.RETAIN,len:Number.POSITIVE_INFINITY}}peek(){return this._actions[this._index]}peekLength(){return this._actions[this._index]?this._actions[this._index].len-this._offset:Number.POSITIVE_INFINITY}peekType(){const s=this._actions[this._index];return s?s.t:I.RETAIN}rest(){if(this.hasNext()){if(this._offset===0)return this._actions.slice(this._index);{const s=this._offset,e=this._index,n=this.next(),r=this._actions.slice(this._index);return this._offset=s,this._index=e,[n].concat(r)}}else return[]}}function Ve(t){return Object.keys(t).length===1}class zt{constructor(){d(this,"_actions",[])}static compose(s,e){const n=new he(s),r=new he(e),i=new zt;for(;n.hasNext()||r.hasNext();)if(r.peekType()===I.INSERT)i.push(r.next());else if(n.peekType()===I.DELETE)i.push(n.next());else{const o=Math.min(n.peekLength(),r.peekLength()),a=n.next(o),l=r.next(o);a.t===I.INSERT&&l.t===I.RETAIN?l.body==null?i.push(a):i.push({...a,body:ae(a.body,l.body,l.coverType)}):a.t===I.RETAIN&&l.t===I.RETAIN?a.body==null&&l.body==null?i.push(a.len!==Number.POSITIVE_INFINITY?a:l):a.body&&l.body?i.push({...a,body:ae(a.body,l.body,l.coverType)}):i.push(a.body?a:l):a.t===I.RETAIN&&l.t===I.DELETE?i.push(l):a.t===I.INSERT&&(l.t,I.DELETE)}return i.trimEndUselessRetainAction(),i.serialize()}insert(s,e,n=""){const r={t:I.INSERT,body:e,len:s,line:0,segmentId:n};return this.push(r),this}retain(s,e="",n,r){const i={t:I.RETAIN,len:s,segmentId:e};return n!=null&&(i.body=n),r!=null&&(i.coverType=r),this.push(i),this}delete(s,e=""){const n={t:I.DELETE,len:s,line:0,segmentId:e};return this.push(n),this}serialize(){return this._actions}push(...s){if(s.length>1){for(const i of s)this.push(i);return this}let e=this._actions.length,n=this._actions[e-1];const r=R.deepClone(s[0]);if(r.t===I.RETAIN&&r.len===0&&r.body==null)return this;if(typeof n=="object"){if(n.t===I.DELETE&&r.t===I.DELETE)return n.len+=r.len,this;if(n.t===I.DELETE&&r.t===I.INSERT&&(e-=1,n=this._actions[e-1],n==null))return this._actions.unshift(r),this;if(n.t===I.RETAIN&&r.t===I.RETAIN&&n.body==null&&r.body==null)return n.len+=r.len,this;if(n.t===I.INSERT&&Ve(n.body)&&r.t===I.INSERT&&Ve(r.body))return n.len+=r.len,n.body.dataStream+=r.body.dataStream,this}return e===this._actions.length?this._actions.push(r):this._actions.splice(e,0,r),this}trimEndUselessRetainAction(){let s=this._actions[this._actions.length-1];for(;s&&s.t===I.RETAIN&&ki(s);)this._actions.pop(),s=this._actions[this._actions.length-1];return this}}function oa(t,s,e){if(s==="")return t;const n={id:"mock-id",body:t,documentStyle:{}},r=new st(n),i=s.length;let o;for(;(o=r.getBody().dataStream.indexOf(s))>=0;){const l=new zt;if(o>0&&l.retain(o),e.length>0){const c=r.sliceBody(o,o+i),h={dataStream:e};Array.isArray(c==null?void 0:c.textRuns)&&c.textRuns.length&&(h.textRuns=[{...c.textRuns[0],st:0,ed:e.length}]),l.insert(e.length,h)}l.delete(i);const u=l.serialize();r.apply(u)}const a=r.getBody();return r.dispose(),a}class aa extends Gt{add(s){if(!s)return null;const e=new kt(s,this);return this._observers=[e],this._onObserverAdded&&this._onObserverAdded(e),e}makeObserverTopPriority(){}makeObserverBottomPriority(){}}const la=A.createIdentifier("ILocalStorageService");function ua(t){return new L.Observable(s=>{const e=t((...n)=>s.next(n));return()=>e==null?void 0:e.dispose()})}function ca(t){return`sheet_interceptor_${t}`}const Yn=t=>function(s,e){let n=-1;function r(i,o){if(i<=n)throw new Error("[SheetInterceptorService]: next() called multiple times!");return n=i,i===t.length?o:t[i].handler(o,e,r.bind(null,i+1))}return r(0,s)};class ha{constructor(s){d(this,"_interceptorsByName",new Map);d(this,"_interceptorPoints");this._interceptorPoints=s}fetchThroughInterceptors(s){const e=s,n=this._interceptorsByName.get(e);return Yn(n||[])}intercept(s,e){const n=s;this._interceptorsByName.has(n)||this._interceptorsByName.set(n,[]);const r=this._interceptorsByName.get(n);return r.push(e),this._interceptorsByName.set(n,r.sort((i,o)=>{var a,l;return((a=o.priority)!=null?a:0)-((l=i.priority)!=null?l:0)})),()=>$t(this._interceptorsByName.get(n),e)}getInterceptPoints(){return this._interceptorPoints}}const da=A.createIdentifier("univer.snapshot-server-service");class _a{constructor(){d(this,"_sheetBlockCache",new Map)}getUnitOnRev(s,e){return Promise.resolve({snapshot:{unitID:"",type:O.UNIVER_SHEET,rev:0,workbook:void 0,doc:void 0},changesets:[],error:{code:B.OK,message:""}})}getSheetBlock(s,e){const n=this._sheetBlockCache.get(e.blockID);return Promise.resolve({block:n,error:{code:B.OK,message:""}})}fetchMissingChangesets(s,e){return Promise.resolve({changesets:[],error:{code:B.OK,message:""}})}getResourcesRequest(s,e){return Promise.resolve({resources:{},error:{code:B.OK,message:""}})}saveSnapshot(s,e){return Promise.resolve({error:{code:B.OK,message:""}})}saveSheetBlock(s,e){const{block:n}=e;return n?(this._sheetBlockCache.set(n.id,n),Promise.resolve({error:{code:B.OK,message:""},blockID:n.id})):Promise.resolve({error:{code:B.UNDEFINED,message:"block is required"},blockID:""})}saveChangeset(s,e){return Promise.resolve({error:{code:B.OK,message:""},concurrent:[]})}}function fa(t){return btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(s,e)=>String.fromCharCode(Number.parseInt(e,16))))}function pe(t){return decodeURIComponent(Array.prototype.map.call(atob(t),s=>`%${`00${s.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}const mt=new TextEncoder,yt=new TextDecoder;function zn(t){const s=R.deepClone(t);return delete s.id,delete s.name,delete s.rowCount,delete s.columnCount,delete s.cellData,mt.encode(JSON.stringify(s))}function yn(t){const s=R.deepClone(t);return delete s.id,delete s.rev,delete s.name,delete s.sheetOrder,delete s.sheets,mt.encode(JSON.stringify(s))}function Ea(t){const s=R.deepClone(t);return delete s.id,delete s.rev,delete s.title,delete s.resources,mt.encode(JSON.stringify(s))}function je(t){return JSON.parse(yt.decode(t))}function ga(t){return JSON.parse(typeof t=="string"?pe(t):yt.decode(t))}function Ra(t){return JSON.parse(typeof t=="string"?pe(t):yt.decode(t))}const Qt=256;function Xn(t,s){const e=new G(t),n=e.getLength(),r=[];let i=0;for(;i<n;){const o=Math.min(i+Qt,n-1),a=e.getSlice(i,Math.min(i+Qt,n-1),0,s),l=ma(a);r.push({id:R.generateRandomId(19,"0123456789"),startRow:i,endRow:o,data:l}),i+=Qt}return r}function ma(t){const s=t.getData();return mt.encode(JSON.stringify(s))}async function Ca(t,s,e,n,r){const i={},o={};if(!await Promise.all(Object.entries(s.sheets).map(async([h,_])=>{const f={id:_.id,type:Ft.GRID,name:_.name,rowCount:_.rowCount,columnCount:_.columnCount,originalMeta:zn(_)};if(o[h]=f,_.cellData){const E=Xn(_.cellData,_.rowCount),g=await Promise.all(E.map(m=>r.saveSheetBlock(t,{unitID:e,type:O.UNIVER_SHEET,block:m})));if(g.some(m=>{var N;return((N=m.error)==null?void 0:N.code)!==B.OK}))return!1;i[h]={sheetID:h,blocks:g.map(m=>m.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const l=yn(s),u={unitID:s.id,rev:n,creator:"",name:s.name,sheetOrder:s.sheetOrder,sheets:o,blockMeta:i,resources:s.resources||[],originalMeta:l};return{snapshotRes:{unitID:e,rev:u.rev,type:O.UNIVER_SHEET,workbook:u,doc:void 0}}}async function Oa(t,s,e,n,r){var _,f;const i={},o={};if(!await Promise.all(Object.entries(s.sheets).map(async([E,g])=>{const m={id:g.id,type:Ft.GRID,name:g.name,rowCount:g.rowCount,columnCount:g.columnCount,originalMeta:zn(g)};if(o[E]=m,g.cellData){const N=Xn(g.cellData,g.rowCount),U=await Promise.all(N.map(M=>r.saveSheetBlock(t,{unitID:e,type:O.UNIVER_SHEET,block:M})));if(U.some(M=>{var V;return((V=M.error)==null?void 0:V.code)!==B.OK}))return!1;i[E]={sheetID:E,blocks:U.map(M=>M.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const l=yn(s),u={unitID:s.id,rev:n,creator:"",name:s.name,sheetOrder:s.sheetOrder,sheets:o,blockMeta:i,resources:s.resources||[],originalMeta:l},c={unitID:e,rev:u.rev,type:O.UNIVER_SHEET,workbook:u,doc:void 0},h=await r.saveSnapshot(t,{unitID:e,type:O.UNIVER_SHEET,snapshot:c});if(Zs(h.error))throw new Error(`transformWorkbookDataToSnapshot(): Failed to save snapshot.
8
8
  ErrorCode: ${(_=h.error)==null?void 0:_.code}:${(f=h.error)==null?void 0:f.message}`);return{snapshot:c}}function Ia(t,s,e){const n=t.workbook;if(!n)throw new Error("");const r={};Object.entries(n.sheets).forEach(([l,u])=>{const c=je(u.originalMeta);r[l]={id:u.id,name:u.name,rowCount:u.rowCount,columnCount:u.columnCount,...c}});const i=new Map;s.forEach(l=>{i.set(l.id,l)}),n.blockMeta&&Object.entries(n.blockMeta).forEach(([l,u])=>{var _;const c=r[l];c.cellData={};const h=[];(_=u.blocks)==null||_.forEach(f=>{const E=i.get(f);if(E)h.push(E);else throw new Error("")}),h.forEach(f=>{const E=ga(f.data);Object.entries(E).forEach(([g,m])=>{const N=c.cellData[+g]={};Object.entries(m).forEach(([U,M])=>{N[+U]=M})})})});const o=je(n.originalMeta);return{id:t.unitID,rev:n.rev,name:n.name,sheetOrder:n.sheetOrder,appVersion:"",locale:nt.EN_US,sheets:r,styles:{},resources:n.resources||[],...o}}function Aa(t){const s=t.doc;if(s==null)throw new Error("transformSnapshotToDocumentData(): snapshot.doc is undefined.");const{unitID:e,rev:n,name:r,originalMeta:i}=s,{body:o,documentStyle:a={},settings:l={}}=Ra(i);return{id:e,rev:n,locale:nt.EN_US,title:r,body:o,documentStyle:a,settings:l}}async function Na(t,s,e,n,r){var l,u,c;const i={unitID:s.id,rev:n,creator:"",name:(l=s.title)!=null?l:"",resources:s.resources||[],originalMeta:Ea(s)},o={unitID:e,rev:i.rev,type:O.UNIVER_DOC,workbook:void 0,doc:i},a=await r.saveSnapshot(t,{unitID:e,type:O.UNIVER_DOC,snapshot:o});if(Zs(a.error))throw new Error(`transformDocumentDataToSnapshot(): Failed to save snapshot.
9
9
  ErrorCode: ${(u=a.error)==null?void 0:u.code}:${(c=a.error)==null?void 0:c.message}`);return{snapshot:o}}async function Sa(t,s){const e=t.workbook;if(!e)throw new Error("Workbook metadata is not available");const n=[],r=[];return Object.entries(e.blockMeta).forEach(([i,o])=>{const a=o.blocks.map(async l=>{const u={unitID:e.unitID,type:O.UNIVER_SHEET,blockID:l},{block:c}=await s.getSheetBlock({},u);if(c)n.push(c);else throw new Error("Block not found")});r.push(...a)}),await Promise.all(r),n}var qn=(t=>(t[t.INFO=0]="INFO",t[t.STOP=1]="STOP",t[t.WARNING=2]="WARNING",t))(qn||{}),Jn=(t=>(t[t.DISABLED=0]="DISABLED",t[t.FULL_ALPHA=1]="FULL_ALPHA",t[t.FULL_HANGUL=2]="FULL_HANGUL",t[t.FULL_KATAKANA=3]="FULL_KATAKANA",t[t.HALF_ALPHA=4]="HALF_ALPHA",t[t.HALF_HANGUL=5]="HALF_HANGUL",t[t.HALF_KATAKANA=6]="HALF_KATAKANA",t[t.HIRAGANA=7]="HIRAGANA",t[t.NO_CONTROL=8]="NO_CONTROL",t[t.OFF=9]="OFF",t[t.ON=10]="ON",t))(Jn||{}),Zn=(t=>(t.BETWEEN="between",t.EQUAL="equal",t.GREATER_THAN="greaterThan",t.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",t.LESS_THAN="lessThan",t.LESS_THAN_OR_EQUAL="lessThanOrEqual",t.NOT_BETWEEN="notBetween",t.NOT_EQUAL="notEqual",t))(Zn||{}),Qn=(t=>(t.CUSTOM="custom",t.LIST="list",t.LIST_MULTIPLE="listMultiple",t.NONE="none",t.TEXT_LENGTH="textLength",t.DATE="date",t.TIME="time",t.WHOLE="whole",t.DECIMAL="decimal",t.CHECKBOX="checkbox",t))(Qn||{}),tr=(t=>(t.VALID="valid",t.INVALID="invalid",t.VALIDATING="validating",t))(tr||{});ir();exports.ABCToNumber=di;exports.AbsoluteRefType=w;exports.ActionIterator=he;exports.AlignTypeH=Us;exports.AlignTypeV=Ds;exports.AutoFillSeries=ze;exports.BaselineOffset=it;exports.BlockType=ds;exports.BooleanNumber=C;exports.BorderStyleTypes=T;exports.BorderType=ye;exports.BulletAlignment=K;exports.COLORS=te;exports.CellValueType=Q;exports.ClientSnapshotServerService=_a;exports.Color=tt;exports.ColorBuilder=Bt;exports.ColorKit=k;exports.ColorType=W;exports.ColumnSeparatorType=Es;exports.CommandType=jt;exports.CommonHideTypes=Xe;exports.ConfigService=mn;exports.ContentAlignment=Ls;exports.ContextService=_n;exports.CopyPasteType=qe;exports.CustomRangeType=hs;exports.DEFAULT_CELL=Ai;exports.DEFAULT_DOC=Se;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=Xi;exports.DEFAULT_EMPTY_DOCUMENT_VALUE=Mo;exports.DEFAULT_RANGE=Oi;exports.DEFAULT_RANGE_ARRAY=lt;exports.DEFAULT_SELECTION=Ii;exports.DEFAULT_SLIDE=qs;exports.DEFAULT_STYLES=Tt;exports.DEFAULT_WORKSHEET_COLUMN_COUNT=Sn;exports.DEFAULT_WORKSHEET_COLUMN_COUNT_KEY=Qi;exports.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT=wn;exports.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY=no;exports.DEFAULT_WORKSHEET_COLUMN_WIDTH=Tn;exports.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY=eo;exports.DEFAULT_WORKSHEET_ROW_COUNT=Nn;exports.DEFAULT_WORKSHEET_ROW_COUNT_KEY=Zi;exports.DEFAULT_WORKSHEET_ROW_HEIGHT=Ln;exports.DEFAULT_WORKSHEET_ROW_HEIGHT_KEY=to;exports.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH=bn;exports.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY=so;exports.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY=Fn;exports.DOCS_NORMAL_EDITOR_UNIT_ID_KEY=Hn;exports.DashStyleType=As;exports.DataStreamTreeNodeType=tn;exports.DataStreamTreeTokenType=Ce;exports.DataValidationErrorStyle=qn;exports.DataValidationImeMode=Jn;exports.DataValidationOperator=Zn;exports.DataValidationRenderMode=Kn;exports.DataValidationStatus=tr;exports.DataValidationType=Qn;exports.DesktopLogService=En;exports.DeveloperMetadataVisibility=Je;exports.Dimension=Ze;exports.Direction=Qe;exports.Disposable=p;exports.DisposableCollection=Ee;exports.DocStyleType=us;exports.DocumentDataModel=st;exports.EDITOR_ACTIVATED=Dn;exports.EXTENSION_NAMES=Js;exports.Entry=ee;exports.EntryIterator=Ks;exports.ErrorService=Cn;exports.EventState=Gs;exports.FOCUSING_DOC=bt;exports.FOCUSING_EDITOR_BUT_HIDDEN=_o;exports.FOCUSING_EDITOR_INPUT_FORMULA=fo;exports.FOCUSING_EDITOR_STANDALONE=go;exports.FOCUSING_FORMULA_EDITOR=pn;exports.FOCUSING_SHEET=ht;exports.FOCUSING_SLIDE=wt;exports.FOCUSING_UNIVER_EDITOR=Eo;exports.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE=Ro;exports.FloatingObjectManagerService=On;exports.FollowNumberWithType=cs;exports.FontItalic=Dt;exports.FontStyleType=Ts;exports.FontWeight=pt;exports.FormatType=ts;exports.GlyphType=ut;exports.GridType=_s;exports.HLSColor=as;exports.HorizontalAlign=Z;exports.ICommandService=Rt;exports.IConfigService=Rn;exports.IContextService=gt;exports.IFloatingObjectManagerService=In;exports.ILocalStorageService=la;exports.ILogService=J;exports.IPermissionService=ve;exports.IResourceLoaderService=Ue;exports.IResourceManagerService=Kt;exports.ISnapshotServerService=da;exports.IUndoRedoService=Yt;exports.IUniverInstanceService=q;exports.InterceptorManager=ha;exports.InterpolationPointType=es;exports.KeyIterator=Vs;exports.LRUHelper=at;exports.LRUMap=Ys;exports.LifecycleStages=b;exports.LocaleService=dt;exports.LocaleType=nt;exports.LogLevel=fn;exports.MemoryCursor=Qs;exports.NamedStyleType=Os;exports.NilCommand=gn;exports.NumberUnitType=vs;exports.ObjectMatrix=G;exports.ObjectRelativeFromH=bs;exports.ObjectRelativeFromV=ws;exports.Observable=Gt;exports.ObservableHooks=aa;exports.Observer=kt;exports.OnLifecycle=be;exports.PRESET_LIST_TYPE=pi;exports.PageElementType=Ps;exports.PageOrientType=Ms;exports.PageType=de;exports.ParagraphElementType=Rs;exports.PermissionPoint=zs;exports.PermissionStatus=ge;exports.Plugin=ce;exports.PositionedObjectLayoutType=Cs;exports.PresetListType=Ht;exports.ProtectionType=ss;exports.RANGE_TYPE=x;exports.RGBA_PAREN=hr;exports.RGB_PAREN=cr;exports.Range=et;exports.Rectangle=X;exports.RedoCommand=$n;exports.RedoCommandId=Bn;exports.RefAlias=hi;exports.Registry=Re;exports.RegistryAsMap=me;exports.RelativeDate=ns;exports.RelativeSlideLink=xs;exports.ResourceManagerService=xn;exports.RgbColor=Mt;exports.RxDisposable=ei;exports.SectionType=fs;exports.ShapeType=rs;exports.SheetTypes=Ft;exports.SheetViewModel=Un;exports.SlideDataModel=Te;exports.SpacingRule=Is;exports.Styles=An;exports.THEME_COLORS=os;exports.TabStopAlignment=Ns;exports.TextDecoration=is;exports.TextDirection=_t;exports.TextDirectionType=gs;exports.TextX=zt;exports.TextXActionType=I;exports.ThemeColor=Pt;exports.ThemeColorType=H;exports.ThemeColors=Wt;exports.ThemeService=De;exports.Tools=R;exports.UndoCommand=Gn;exports.UndoCommandId=kn;exports.UnitModel=Vt;exports.Univer=qo;exports.UniverEditablePermission=Ut;exports.UniverEditablePermissionPoint=Pn;exports.UniverInstanceType=O;exports.UpdateDocsAttributeType=P;exports.ValueIterator=js;exports.VerticalAlign=rt;exports.WidthType=Ss;exports.Worksheet=Et;exports.WrapStrategy=ft;exports.WrapTextType=ms;exports.b64DecodeUnicode=pe;exports.b64EncodeUnicode=fa;exports.binarySearchArray=Ke;exports.cellToRange=Yr;exports.characterSpacingControlType=ps;exports.checkForSubstrings=zr;exports.checkParagraphHasBullet=yr;exports.checkParagraphHasIndent=Xr;exports.checkParagraphHasIndentByStyle=Fs;exports.codeToBlob=lr;exports.composeBody=ae;exports.composeInterceptors=Yn;exports.concatMatrixArray=oi;exports.convertBodyToHtml=Ci;exports.covertTextRunToHtml=oe;exports.createInterceptorKey=ca;exports.createInternalEditorID=Po;exports.createRowColIter=ie;exports.debounce=mi;exports.dedupe=si;exports.deepCompare=_e;exports.deleteContent=Bs;exports.extractPureTextFromCell=ro;exports.fromCallback=ua;exports.fromObservable=ti;exports.generateTemporarySnap=Ca;exports.getArrayLength=y;exports.getBodySlice=Ne;exports.getBodySliceHtml=Lt;exports.getBorderStyleType=jr;exports.getCellValueType=Tr;exports.getColorStyle=$;exports.getDocsUpdateBody=St;exports.getReverseDirection=ur;exports.getSheetBlocksFromSnapshot=Sa;exports.getTypeFromPermissionItemList=ci;exports.getWorksheetUID=ho;exports.groupBy=ii;exports.handleJsonToDom=$r;exports.handleStyleToString=Vr;exports.hashAlgorithm=Jr;exports.horizontalLineSegmentsSubtraction=fe;exports.insertMatrixArray=se;exports.insertTextToContent=Ws;exports.isBlackColor=Nr;exports.isBooleanString=sa;exports.isCellV=wr;exports.isEmptyCell=Br;exports.isFormulaId=Gr;exports.isFormulaString=kr;exports.isICellData=Lr;exports.isInternalEditorID=xo;exports.isNullCell=br;exports.isNumeric=jn;exports.isObserver=$s;exports.isRangesEqual=Zo;exports.isRealNum=qr;exports.isSafeNumeric=ea;exports.isSameStyleTextRun=Hs;exports.isUnitRangesEqual=Qo;exports.isValidRange=Kr;exports.isWhiteColor=Sr;exports.makeCellRangeToRangeData=Wr;exports.makeCellToSelection=Fr;exports.mergeOverrideWithDependencies=Vn;exports.mergeSets=na;exports.mergeWorksheetSnapshotWithDefault=vn;exports.moveMatrixArray=re;exports.moveRangeByOffset=bi;exports.normalizeTextRuns=Oe;exports.numberToABC=fi;exports.numberToListABC=Ei;exports.orderSearchArray=Ye;exports.queryObjectMatrix=Ti;exports.remove=$t;exports.repeatStringNumTimes=Xs;exports.replaceInDocumentBody=oa;exports.requestImmediateMacroTask=ia;exports.rotate=ri;exports.runOnLifecycle=we;exports.searchArray=ar;exports.selectionToArray=vr;exports.sequence=dn;exports.sequenceAsync=hn;exports.sequenceExecute=Le;exports.sequenceExecuteAsync=yi;exports.shallowEqual=ta;exports.sliceMatrixArray=ai;exports.sortRules=gi;exports.sortRulesByDesc=Ri;exports.sortRulesFactory=ot;exports.spliceArray=ne;exports.textDecoder=yt;exports.textEncoder=mt;exports.throttle=ra;exports.toDisposable=v;exports.transformDocumentDataToSnapshot=Na;exports.transformSnapshotToDocumentData=Aa;exports.transformSnapshotToWorkbookData=Ia;exports.transformWorkbookDataToSnapshot=Oa;
package/lib/es/index.js CHANGED
@@ -5730,7 +5730,7 @@ function gu(t) {
5730
5730
  const s = t.v;
5731
5731
  return typeof s == "string" ? t.t === nt.BOOLEAN ? s.toUpperCase() : s : typeof s == "number" ? t.t === nt.BOOLEAN ? s ? "TRUE" : "FALSE" : s.toString() : typeof s == "boolean" ? s ? "TRUE" : "FALSE" : "";
5732
5732
  }
5733
- const ti = "0.1.8";
5733
+ const ti = "0.1.9";
5734
5734
  function ei(t = "", e = ut.ZH_CN, s = "") {
5735
5735
  return {
5736
5736
  id: t,
package/lib/umd/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  `):"",this.name="UnsubscriptionError",this.errors=e}});function Pn(t,n){if(t){var e=t.indexOf(n);0<=e&&t.splice(e,1)}}var Hn=function(){function t(n){this.initialTeardown=n,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var n,e,s,r,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=Un(o),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(R){n={error:R}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(n)throw n.error}}else o.remove(this);var h=this.initialTeardown;if(ht(h))try{h()}catch(R){i=R instanceof ne?R.errors:[R]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var f=Un(d),E=f.next();!E.done;E=f.next()){var g=E.value;try{Fn(g)}catch(R){i=i!=null?i:[],R instanceof ne?i=Mn(Mn([],Dn(i)),Dn(R.errors)):i.push(R)}}}catch(R){s={error:R}}finally{try{E&&!E.done&&(r=f.return)&&r.call(f)}finally{if(s)throw s.error}}}if(i)throw new ne(i)}},t.prototype.add=function(n){var e;if(n&&n!==this)if(this.closed)Fn(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(n)}},t.prototype._hasParent=function(n){var e=this._parentage;return e===n||Array.isArray(e)&&e.includes(n)},t.prototype._addParent=function(n){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(n),e):e?[e,n]:n},t.prototype._removeParent=function(n){var e=this._parentage;e===n?this._parentage=null:Array.isArray(e)&&Pn(e,n)},t.prototype.remove=function(n){var e=this._finalizers;e&&Pn(e,n),n instanceof t&&n._removeParent(this)},t.EMPTY=function(){var n=new t;return n.closed=!0,n}(),t}();Hn.EMPTY;function Jr(t){return t instanceof Hn||t&&"closed"in t&&ht(t.remove)&&ht(t.add)&&ht(t.unsubscribe)}function Fn(t){ht(t)?t():t.unsubscribe()}class pn{constructor(n=!1){_(this,"skipNextObservers");_(this,"lastReturnValue");_(this,"isStopPropagation",!1);this.initialize(n)}initialize(n=!1){return this.skipNextObservers=n,this}stopPropagation(){this.isStopPropagation=!0}}function Wn(t){return t instanceof Dt}class Dt{constructor(n,e){_(this,"_willBeUnregistered",!1);_(this,"unregisterOnNextCall",!1);this.callback=n,this.observable=e}dispose(){this.observable.remove(this)}}class Mt{constructor(n){_(this,"_observers",new Array);_(this,"_eventState");_(this,"_onObserverAdded");this._eventState=new pn,n&&(this._onObserverAdded=n)}get observers(){return this._observers}add(n,e=!1,s=!1){if(!n)return null;const r=new Dt(n,this);return r.unregisterOnNextCall=s,e?this._observers.unshift(r):this._observers.push(r),this._onObserverAdded&&this._onObserverAdded(r),r}addOnce(n){return this.add(n,void 0,!0)}remove(n){return n&&this._observers.indexOf(n)!==-1?(this._deferUnregister(n),!0):!1}removeCallback(n){for(let e=0;e<this._observers.length;e++){const s=this._observers[e];if(!s._willBeUnregistered&&s.callback===n)return this._deferUnregister(s),!0}return!1}makeObserverTopPriority(n){this._remove(n),this._observers.unshift(n)}makeObserverBottomPriority(n){this._remove(n),this._observers.push(n)}notifyObservers(n){if(!this._observers.length)return null;const e=this._eventState;e.skipNextObservers=!1,e.lastReturnValue=n,e.isStopPropagation=!1;let s=!1;for(let r=0;r<this._observers.length;r++){const i=this._observers[r];if(!i._willBeUnregistered&&(e.lastReturnValue=i.callback(n,e),i.unregisterOnNextCall&&this._deferUnregister(i),e.isStopPropagation&&(s=!0),e.skipNextObservers))return{lastReturnValue:e.lastReturnValue,stopPropagation:s}}return{lastReturnValue:e.lastReturnValue,stopPropagation:s}}notifyObserversWithPromise(n){let e=Promise.resolve(n);if(!this._observers.length)return e;const s=this._eventState;s.skipNextObservers=!1;for(let r=0;r<this._observers.length;r++){const i=this._observers[r];s.skipNextObservers||i._willBeUnregistered||(e=e.then(()=>i.callback(n,s)),i.unregisterOnNextCall&&this._deferUnregister(i))}return e.then(()=>n)}notifyObserver(n,e){if(n._willBeUnregistered)return;const s=this._eventState;return s.skipNextObservers=!1,n.callback(e,s),n.unregisterOnNextCall&&this._deferUnregister(n),{lastReturnValue:s.lastReturnValue,stopPropagation:s.isStopPropagation}}hasObservers(){return this._observers.length>0}clear(){this._observers=new Array,this._onObserverAdded=null}clone(){const n=new Mt;return n._observers=this._observers.slice(0),n}_deferUnregister(n){n.unregisterOnNextCall=!1,n._willBeUnregistered=!0,setTimeout(()=>{this._remove(n)},0)}_remove(n){if(!n)return!1;const e=this._observers.indexOf(n);return e!==-1?(this._observers.splice(e,1),!0):!1}}function U(t){let n=!1;return t?Jr(t)?{dispose:()=>t.unsubscribe()}:Wn(t)?{dispose:()=>{n||(n=!0,t.dispose())}}:typeof t=="function"?{dispose:()=>{n||(n=!0,t())}}:t:U(()=>{})}function Zr(t){return U(()=>{t.unsubscribe()})}class se{constructor(){_(this,"_disposables",new Set)}add(n){const e=U(n);return this._disposables.add(e),{dispose:()=>{e.dispose(),this._disposables.delete(e)}}}dispose(){this._disposables.forEach(n=>{n.dispose()}),this._disposables.clear()}}class D{constructor(){_(this,"_disposed",!1);_(this,"_collection",new se)}disposeWithMe(n){return this._collection.add(n)}ensureNotDisposed(){if(this._disposed)throw new Error("[Disposable]: object is disposed!")}dispose(){this._disposed||(this._disposed=!0,this._collection.dispose())}}class Qr extends D{constructor(){super(...arguments);_(this,"dispose$",new I.Subject)}dispose(){super.dispose(),this.dispose$.next(),this.dispose$.complete()}}class dt{static hasLength(n,e){return n.length===e}static getValueType(n){return Object.prototype.toString.apply(n)}static isObject(n){return this.getValueType(n)==="[object Object]"}static isIterable(n){return n[Symbol.iterator]!=null}static isNumber(n){return this.getValueType(n)==="[object Number]"}}function Pt(t,n){const e=t.indexOf(n);return e>-1?(t.splice(e,1),!0):!1}function ti(t){const n=new Set,e=[];for(const s of t)n.has(s)||(n.add(s),e.push(s));return e}function ei(t,n){for(let e=t.length-1;e>-1;e--){const s=t[e];if(n(s,e))return s}return null}function ni(t,n){if(t.length===0)return t;const e=n%t.length;return t.slice(e).concat(t.slice(0,e))}function si(t,n){const e=new Map;return t.forEach(s=>{const r=n(s);let i=e.get(r);e.has(r)||(i=[],e.set(r,i)),i.push(s)}),e}const T=Symbol("newer"),M=Symbol("older");class Bn{constructor(n){_(this,"entry");this.entry=n}[Symbol.iterator](){return this}next(){const n=this.entry;return n?(this.entry=n[T],{done:!1,value:n.key}):{done:!0,value:void 0}}}class kn{constructor(n){_(this,"entry");this.entry=n}[Symbol.iterator](){return this}next(){const n=this.entry;return n?(this.entry=n[T],{done:!1,value:n.value}):{done:!0,value:void 0}}}class Gn{constructor(n){_(this,"entry");this.entry=n}[Symbol.iterator](){return this}next(){const n=this.entry;return n?(this.entry=n[T],{done:!1,value:[n.key,n.value]}):{done:!0,value:void 0}}}class re{constructor(n,e){_(this,"key");_(this,"value");_(this,Na);_(this,Sa);this.key=n,this.value=e,this[T]=void 0,this[M]=void 0}toJSON(){return{key:this.key,value:this.value}}}Na=T,Sa=M;class $n{constructor(...n){_(this,"_keymap");_(this,"size",0);_(this,"limit");_(this,"oldest");_(this,"newest");_(this,"_onShiftListeners",[]);if(dt.hasLength(n,1)){if(dt.isNumber(n[0])){const e=n[0];this._initialize(e,void 0);return}if(dt.isIterable(n[0])){const e=n[0];this._initialize(0,e);return}return}if(dt.hasLength(n,2)){const e=n[0],s=n[1];this._initialize(e,s)}}onShift(n){if(this._onShiftListeners.indexOf(n)===-1)return this._onShiftListeners.push(n),U(()=>Pt(this._onShiftListeners,n));throw new Error("[LRUMap]: the listener has been registered!")}_initialize(n,e){this.oldest=void 0,this.newest=void 0,this.size=0,this.limit=n,this._keymap=new Map,e&&(this.assign(e),n<1&&(this.limit=this.size))}_markEntryAsUsed(n){n!==this.newest&&(n[T]&&(n===this.oldest&&(this.oldest=n[T]),n[T][M]=n[M]),n[M]&&(n[M][T]=n[T]),n[T]=void 0,n[M]=this.newest,this.newest&&(this.newest[T]=n),this.newest=n)}assign(n){let e,s=this.limit||Number.MAX_VALUE;this._keymap.clear();const r=n[Symbol.iterator]();for(let i=r.next();!i.done;i=r.next()){const o=new re(i.value[0],i.value[1]);if(this._keymap.set(o.key,o),e?(e[T]=o,o[M]=e):this.oldest=o,e=o,s--===0)throw new Error("overflow")}this.newest=e,this.size=this._keymap.size}set(n,e){let s=this._keymap.get(n);return s?(s.value=e,this._markEntryAsUsed(s),this):(this._keymap.set(n,s=new re(n,e)),this.newest?(this.newest[T]=s,s[M]=this.newest):this.oldest=s,this.newest=s,++this.size,this.size>this.limit&&this.shift(),this)}shift(){const n=this.oldest;if(n)return this.oldest&&this.oldest[T]?(this.oldest=this.oldest[T],this.oldest[M]=void 0):(this.oldest=void 0,this.newest=void 0),n[T]=n[M]=void 0,this._keymap.delete(n.key),--this.size,this._onShiftListeners.forEach(e=>e(n)),[n.key,n.value]}get(n){const e=this._keymap.get(n);if(e)return this._markEntryAsUsed(e),e.value}has(n){return this._keymap.has(n)}find(n){const e=this._keymap.get(n);return e?e.value:void 0}delete(n){const e=this._keymap.get(n);if(e)return this._keymap.delete(e.key),e[T]&&e[M]?(e[M][T]=e[T],e[T][M]=e[M]):e[T]?(e[T][M]=void 0,this.oldest=e[T]):e[M]?(e[M][T]=void 0,this.newest=e[M]):this.oldest=this.newest=void 0,this.size--,e.value}clear(){this.oldest=void 0,this.newest=void 0,this.size=0,this._keymap.clear()}keys(){return new Bn(this.oldest)}values(){return new kn(this.oldest)}entries(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Gn(this.oldest)}forEach(n,e){typeof e!="object"&&(e=this);let s=this.oldest;for(;s;)n.call(e,s.value,s.key,this),s=s[T]}toJSON(){const n=new Array(this.size);let e=0,s=this.oldest;for(;s;)n[e++]={key:s.key,value:s.value},s=s[T];return n}toString(){let n="",e=this.oldest;for(;e;)n+=`${String(e.key)}:${e.value}`,e=e[T],e&&(n+=" < ");return n}}function Y(t){let n=0;const e=Object.keys(t);for(const s of e){const r=Number(s);n=Math.max(n,r)}return n+1}function ie(t,n,e){const s=Y(e),r=e;for(let i=s-1;i>=t;i--)r[i+1]=r[i];r[t]=n}function oe(t,n,e){const s=Object.keys(e).reduce((r,i)=>Math.max(r,Number.parseInt(i)),0)+1;for(let r=t;r<s;r++)r<t+n?delete e[r]:e[r]!==void 0&&(e[r-n]=e[r],delete e[r])}function ri(t,n){const e=t,s=Object.keys(e),r=s.length,i=n,o=Object.keys(i),a=o.length,l={};let c=0;for(let h=0;h<r;h++,c++){const d=s[h];l[c]=e[d]}for(let h=0;h<a;h++,c++){const d=o[h];l[c]=i[d]}return l}function ii(t,n,e){const s=e;if(Y(e)>0){const i={};let o=0;for(let a=t;a<=n;a++)s[a]&&(i[o]=s[a],o++);return i}return{}}function ae(t,n,e,s){const r=t>e;if(!r&&t+n>e)throw new Error("Invalid move operation");r?oi(t,n,e,s):ai(t,n,e,s)}function oi(t,n,e,s){const r=s,i=[];for(let o=t;o<t+n;o++)i.push(r[o]);for(let o=t-1;o>=e;o--){const a=r[o];r[o+n]=a,a===void 0&&delete r[o+n]}i.forEach((o,a)=>{r[e+a]=o,o===void 0&&delete r[e+a]})}function ai(t,n,e,s){const r=s,i=[];for(let o=t;o<t+n;o++)i.push(r[o]);for(let o=t+n;o<e;o++){const a=r[o];r[o-n]=a,a===void 0&&delete r[o-n]}i.forEach((o,a)=>{r[e+a-n]=o,o===void 0&&delete r[e+a-n]})}class V{constructor(n={}){_(this,"_matrix");this._setOriginValue(n)}static MakeObjectMatrixSize(n){return new V({[n-1]:{}})}getMatrix(){return this._matrix}forEach(n){const e=this._matrix,s=Object.keys(e);for(const r of s){const i=Number(r),o=e[i];if(n(i,o)===!1)return this}return this}forRow(n){const e=this._matrix,s=Object.keys(e);for(const r of s){const i=Number(r),o=e[i];if(n(i,Object.keys(o).map(l=>Number(l)))===!1)return this}return this}forValue(n){const e=this._matrix,s=Object.keys(e);for(const r of s){const i=Number(r),o=e[i];if(!o)continue;const a=Object.keys(o);for(const l of a){const c=Number(l),h=o[Number(l)];if(n(i,c,h)===!1)return this}}return this}swapRow(n,e){const s=this._matrix[n],r=this._matrix[e];this._matrix[n]=r,this._matrix[e]=s}getRow(n){return this._matrix[n]}getRowOrCreate(n){let e=this.getRow(n);return e==null&&(e={},this._matrix[n]=e),e}reset(){this._setOriginValue({})}hasValue(){const n=this._matrix,e=Object.keys(n);if(e.length===0)return!1;for(const s of e){const r=Number(s),i=n[r];if(Object.keys(i).length>0)return!0}return!1}getValue(n,e){var s,r;return(r=(s=this._matrix)==null?void 0:s[n])==null?void 0:r[e]}setValue(n,e,s){const r=this.getRowOrCreate(n);r[e]=s}deleteValue(n,e){var s,r;(r=(s=this._matrix)==null?void 0:s[n])==null||delete r[e]}realDeleteValue(n,e){var s,r,i;if((r=(s=this._matrix)==null?void 0:s[n])==null||delete r[e],this.getRow(n)){const o=this.getRow(n);if(o==null)return;Object.keys(o).length===0&&((i=this._matrix)==null||delete i[n])}}setRow(n,e){this._matrix[n]=e}moveRows(n,e,s){ae(n,e,s,this._matrix)}moveColumns(n,e,s){this.forEach((r,i)=>{ae(n,e,s,i)})}insertRows(n,e){for(let s=n;s<n+e;s++)ie(s,{},this._matrix)}insertColumns(n,e){for(let s=n;s<n+e;s++)this.forEach((r,i)=>{ie(s,void 0,i)})}removeRows(n,e){oe(n,e,this._matrix)}removeColumns(n,e){this.forEach((s,r)=>{oe(n,e,r)})}getFragment(n,e,s,r){const i=new V;let o=0;for(let a=n;a<=e;a++){const l={};let c=0;for(let h=s;h<=r;h++){const d=this.getValue(a,h);l[c]=d,c++}i.setRow(o,l),o++}return i}getSlice(n,e,s,r){const i=new V;for(let o=n;o<=e;o++)for(let a=s;a<=r;a++){const l=this.getValue(o,a);l&&i.setValue(o,a,m.deepClone(l))}return i}getSizeOf(){return Object.keys(this._matrix).length}getLength(){return Y(this._matrix)}getRange(){const s=this.getLength()-1;let r=0;const i=this.getLength();for(let o=0;o<i;o++){const a=this.getRow(o);if(a){const l=Y(a)-1;r=l>r?l:r}}return{startRow:0,startColumn:0,endRow:s,endColumn:r}}toNativeArray(){const n=new Array;return this.forValue((e,s,r)=>{n.push(r)}),n}toArray(){const n=[];return this.forRow((e,s)=>{n[e]==null&&(n[e]=[]),s.forEach(r=>{n[e][r]=this.getValue(e,r)})}),n}toFullArray(){const n=this.getRange(),{endColumn:e,endRow:s}=n,r=[];for(let i=0;i<=s;i++){const o=Array(e+1).fill(void 0);r.push(o)}return this.forValue((i,o,a)=>{r[i][o]=a}),r}toJSON(){return this._matrix}clone(){const n=JSON.stringify(this._matrix);return JSON.parse(n)}getData(){const n=JSON.stringify(this._matrix);return JSON.parse(n)}getArrayData(){let n=0,e=0,s=!1,r=!1;const i=new V;return this.forEach((o,a)=>{s||(s=!0,n=o),Object.keys(a).forEach(l=>{const c=Number(l);r?c<e&&(e=c):(r=!0,e=c);const h=this.getValue(o,c);i.setValue(o-n,c-e,h)})}),i.getData()}getDataRange(){let n=0,e=0,s=0,r=-1,i=!1,o=!1;return this.forEach((a,l)=>{if(i||(i=!0,n=a),l==null)return;const c=Y(l)-1;c>s&&(s=c),Object.keys(l).forEach(h=>{const d=Number(h);o?d<e&&(e=d):(o=!0,e=d)}),a>r&&(r=a)}),{startRow:n,startColumn:e,endRow:r,endColumn:s}}getDiscreteRanges(){const n=[];return this.forEach((e,s)=>{Object.keys(s).forEach(r=>{const i=Number(r);let o=!1;for(const a of n)if(e>=a.startRow&&e<=a.endRow+1&&i>=a.startColumn&&i<=a.endColumn+1){a.endRow=Math.max(e,a.endRow),a.endColumn=Math.max(i,a.endColumn),o=!0;break}o||n.push({startRow:e,endRow:e,startColumn:i,endColumn:i})})}),n}merge(n){this.forValue((e,s)=>{const r=n.getValue(e,s);r!=null&&this.setValue(e,s,r)})}_setOriginValue(n={}){this._matrix=n}}var le=(t=>(t.INIT="init",t.FETCHING="fetching",t.DONE="done",t))(le||{});class Vn{constructor(){_(this,"status","init")}}const li=t=>t.some(n=>n.status==="init")?"init":t.some(n=>n.status==="fetching")?"fetching":"done",J=class J{static clone(n){return n.rangeType!==void 0?{startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:n.rangeType}:{startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn}}static equals(n,e){return n==null||e==null?!1:n.endRow===e.endRow&&n.endColumn===e.endColumn&&n.startRow===e.startRow&&n.startColumn===e.startColumn&&(n.rangeType===e.rangeType||n.rangeType===void 0&&e.rangeType===p.NORMAL||e.rangeType===void 0&&n.rangeType===p.NORMAL)}static intersects(n,e){const s=n.startRow,r=n.endRow,i=n.startColumn,o=n.endColumn,a=e.startRow,l=e.endRow,c=e.startColumn,h=e.endColumn,d=Math.abs(i+o-c-h),f=Math.abs(i-o)+Math.abs(c-h),E=Math.abs(s+r-a-l),g=Math.abs(s-r)+Math.abs(a-l);return d<=f&&E<=g}static getIntersects(n,e){const s=n.startRow,r=n.endRow,i=n.startColumn,o=n.endColumn,a=e.startRow,l=e.endRow,c=e.startColumn,h=e.endColumn;let d,f,E,g;if(a<=r)a>=s?f=a:f=s;else return null;if(l>=s)l>=r?g=r:g=l;else return null;if(c<=o)c>i?d=c:d=i;else return null;if(h>=i)h>=o?E=o:E=h;else return null;return{startRow:f,endRow:g,startColumn:d,endColumn:E,rangeType:p.NORMAL}}static contains(n,e){return n.startRow<=e.startRow&&n.endRow>=e.endRow&&n.startColumn<=e.startColumn&&n.endColumn>=e.endColumn}static realContain(n,e){return J.contains(n,e)&&(n.startRow<e.startRow||n.endRow>e.endRow||n.startColumn<e.startColumn||n.endColumn>e.endColumn)}static union(...n){return n.reduce((e,s)=>({startRow:Math.min(e.startRow,s.startRow),startColumn:Math.min(e.startColumn,s.startColumn),endRow:Math.max(e.endRow,s.endRow),endColumn:Math.max(e.endColumn,s.endColumn),rangeType:p.NORMAL}),n[0])}static subtract(n,e){if(e.startRow>n.endRow||e.endRow<n.startRow||e.startColumn>n.endColumn||e.endColumn<n.startColumn)return[n];const s=[];e.startRow>=n.startRow&&s.push({startRow:n.startRow,startColumn:n.startColumn,endRow:e.startRow-1,endColumn:n.endColumn}),e.endRow<=n.endRow&&s.push({startRow:e.endRow+1,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn});const r=Math.max(n.startRow,e.startRow),i=Math.min(n.endRow,e.endRow);return e.startColumn>=n.startColumn&&s.push({startRow:r,startColumn:n.startColumn,endRow:i,endColumn:e.startColumn-1}),e.endColumn<=n.endColumn&&s.push({startRow:r,startColumn:e.endColumn+1,endRow:i,endColumn:n.endColumn}),s.filter(a=>a.startRow<=a.endRow&&a.startColumn<=a.endColumn)}};_(J,"getRelativeRange",(n,e)=>({startRow:n.startRow-e.startRow,endRow:n.endRow-n.startRow,startColumn:n.startColumn-e.startColumn,endColumn:n.endColumn-n.startColumn})),_(J,"getPositionRange",(n,e,s)=>({...s||{},startRow:s&&[v.ROW,v.ALL].includes(s.startAbsoluteRefType||0)?s.startRow:n.startRow+e.startRow,endRow:s&&[v.ROW,v.ALL].includes(s.endAbsoluteRefType||0)?s.endRow:n.endRow+n.startRow+e.startRow,startColumn:s&&[v.COLUMN,v.ALL].includes(s.startAbsoluteRefType||0)?s.startColumn:n.startColumn+e.startColumn,endColumn:s&&[v.COLUMN,v.ALL].includes(s.endAbsoluteRefType||0)?s.endColumn:n.endColumn+n.startColumn+e.startColumn})),_(J,"moveHorizontal",(n,e=0,s=0)=>({...n,startColumn:n.startColumn+e,endColumn:n.endColumn+e+s})),_(J,"moveVertical",(n,e=0,s=0)=>({...n,startRow:n.startRow+e,endRow:n.endRow+e+s})),_(J,"moveOffset",(n,e,s)=>({...n,startRow:n.startRow+s,endRow:n.endRow+s,startColumn:n.startColumn+e,endColumn:n.endColumn+e}));let z=J;class ui{constructor(n,e){_(this,"_values",[]);_(this,"_keys",[]);_(this,"_keyMaps",new Map);this._values=n,this._keys=e,n.forEach(s=>{this._initKeyMap(s)})}_initKeyMap(n){this._keys.forEach(e=>{const s=n[e],r=this._keyMaps.get(e)||new Map;r.set(s,n),this._keyMaps.set(e,r)})}getValue(n,e){const s=e||this._keys;for(let r=0;r<s.length;r++){const i=this._keyMaps.get(s[r]);if(i!=null&&i.has(n))return i.get(n)}return null}hasValue(n){for(let e=0;e<this._keys.length;e++){const s=this._keyMaps.get(this._keys[e]);if(s!=null&&s.has(n))return!0}return!1}addValue(n){this._values.push(n),this._initKeyMap(n)}setValue(n,e,s){const r=this.getValue(n);r&&Object.keys(r).includes(e)&&(r[e]=s)}deleteValue(n){const e=this.getValue(n);if(e){this._keys.forEach(r=>{const i=this._keyMaps.get(r),o=e[r];i==null||i.delete(o)});const s=this._values.findIndex(r=>r===e);this._values.splice(s,1)}}getValues(){return this._values}getKeyMap(n){var e;return[...((e=this._keyMaps.get(n))==null?void 0:e.keys())||[]]}clear(){this._values=[],this._keys=[],this._keyMaps.clear()}}function ue(t,n,e,s){return{forEach(r){for(let i=t;i<=n;i++)for(let o=e;o<=s;o++)r(i,o)}}}function ci(t){if(t==null||t.length===0)return Number.NaN;const n=t.toLowerCase().split(""),e=n.length,s=o=>o.charCodeAt(0)-96;let r=0,i=0;for(let o=0;o<e;o++)i=s(n[o]),r+=i*26**(e-o-1);return r===0?Number.NaN:r-1}const Ht=65,xn=90,hi=97;function di(t){const n=xn-Ht+1;let e="";for(;t>=0;)e=String.fromCharCode(t%n+Ht)+e,t=Math.floor(t/n)-1;return e}function jn(t,n){let e="";for(;n>0;)e+=t,n--;return e}function _i(t,n=!1){const e=xn-Ht+1;let s=hi;n&&(s=Ht);const r=String.fromCharCode(t%e+s),i=Math.floor(t/e)+1;return jn(r,i)}function fi(t,n){return t.zIndex>n.zIndex?1:t.zIndex===n.zIndex?0:-1}function Ei(t,n){return t.zIndex>n.zIndex?-1:t.zIndex===n.zIndex?0:1}function at(t="index",n=1){return(e,s)=>e[t]>s[t]?n:e[t]===s[t]?0:-n}function gi(t,n){let e;return function(...s){const r=this,i=function(){e=null,t.apply(r,s)};clearTimeout(e),e=setTimeout(i,n)}}function Ft(t,n,e){const{dataStream:s,textRuns:r=[]}=t;let i=n;const o=[];for(const a of r){const{st:l,ed:c}=a;m.hasIntersectionBetweenTwoRanges(n,e,l,c)&&(l>i?(o.push(s.slice(i,l)),o.push(ce(s,{...a,ed:Math.min(c,e)}))):o.push(ce(s,{...a,st:i,ed:Math.min(c,e)}))),i=Math.max(n,Math.min(c,e))}return i!==e&&o.push(s.slice(i,e)),o.join("")}function Ri(t,n=!0){var e;if(n&&((e=t.paragraphs)!=null&&e.length)){const{dataStream:s,paragraphs:r=[]}=t;let i="",o=-1;for(const a of r){const{startIndex:l,paragraphStyle:c={}}=a,{spaceAbove:h,spaceBelow:d,lineSpacing:f}=c,E=[];h!=null&&(typeof h=="number"?E.push(`margin-top: ${h}px`):E.push(`margin-top: ${h.v}px`)),d!=null&&(typeof d=="number"?E.push(`margin-bottom: ${d}px`):E.push(`margin-bottom: ${d.v}px`)),f!=null&&E.push(`line-height: ${f}`),l>o+1?i+=`<p class="UniverNormal" ${E.length?`style="${E.join("; ")};"`:""}>${Ft(t,o+1,l)}</p>`:i+=`<p class="UniverNormal" ${E.length?`style="${E.join("; ")};"`:""}></p>`,o=l}return o!==s.length&&(i+=Ft(t,o,s.length)),i}else return Ft(t,0,t.dataStream.length)}function ce(t,n){const{st:e,ed:s,ts:r={}}=n,{ff:i,fs:o,it:a,bl:l,ul:c,st:h,ol:d,bg:f,cl:E,va:g}=r;let R=t.slice(e,s);const C=[];return a===O.TRUE&&(R=`<i>${R}</i>`),g===ot.SUPERSCRIPT?R=`<sup>${R}</sup>`:g===ot.SUBSCRIPT&&(R=`<sub>${R}</sub>`),(c==null?void 0:c.s)===O.TRUE&&(R=`<u>${R}</u>`),(h==null?void 0:h.s)===O.TRUE&&(R=`<s>${R}</s>`),l===O.TRUE&&(R=`<strong>${R}</strong>`),i&&C.push(`font-family: ${i}`),E&&C.push(`color: ${E.rgb}`),o&&C.push(`font-size: ${o}pt`),d&&C.push("text-decoration: overline"),f&&C.push(`background: ${f.rgb}`),C.length?`<span style="${C.join("; ")};">${R}</span>`:R}const _t={sheetId:"",range:{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1}},mi={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1},Ci={startRow:0,startColumn:0,endRow:0,endColumn:0},Oi={row:0,column:0},pt={ff:"Arial",fs:11,it:O.FALSE,bl:O.FALSE,ul:{s:O.FALSE},st:{s:O.FALSE},ol:{s:O.FALSE},tr:{a:0,v:O.FALSE},td:lt.UNSPECIFIED,cl:{rgb:"#000"},bg:{rgb:"#fff"},ht:tt.UNSPECIFIED,vt:it.UNSPECIFIED,tb:ut.UNSPECIFIED,pd:{t:0,r:0,b:0,l:0}},Kn={id:"default_slide",title:"defaultSlide",pageSize:{width:300,height:300}};var Yn=(t=>(t.ARRAY_CONVERTOR="ARRAY_CONVERTOR",t.MATRIX_CONVERTOR="MATRIX_CONVERTOR",t))(Yn||{});function Wt(t,n){const{textRuns:e=[]}=n;let s=0;for(const i of e){const{ts:o={},st:a,ed:l}=i;if(o[t]==null)return O.FALSE;switch(t){case"bl":case"it":{if(o[t]===O.FALSE)return O.FALSE;break}case"ul":case"st":{if(o[t].s===O.FALSE)return O.FALSE;break}default:throw new Error(`unknown style key: ${t} in IStyleBase`)}s+=l-a}return n.dataStream.indexOf(`\r
4
4
  `)===s?O.TRUE:O.FALSE}class st{constructor(n,e,s){_(this,"_range");_(this,"_worksheet");this._deps=s,this._range=e,this._worksheet=n}static foreach(n,e){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=n;for(let a=s;a<=i;a++)for(let l=r;l<=o;l++)e(a,l)}getRangeData(){return this._range}getValue(){return this.getValues()[0][0]}getValues(){const{startRow:n,endRow:e,startColumn:s,endColumn:r}=this._range,i=[];for(let o=n;o<=e;o++){const a=[];for(let l=s;l<=r;l++)a.push(this.getMatrix().getValue(o,l)||null);i.push(a)}return i}getMatrix(){const{startRow:n,endRow:e,startColumn:s,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new V;for(let a=n;a<=e;a++)for(let l=s;l<=r;l++)o.setValue(a,l,i.getValue(a,l)||null);return o}getMatrixObject(){const{startRow:n,endRow:e,startColumn:s,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new V;for(let a=n;a<=e;a++)for(let l=s;l<=r;l++)o.setValue(a-n,l-s,i.getValue(a,l)||{});return o}getA1Notation(){const{startRow:n,endRow:e,startColumn:s,endColumn:r}=this._range;let i,o;return s<r?(i=m.numToWord(s+1)+(n+1),o=m.numToWord(r+1)+(e+1)):(i=m.numToWord(r+1)+(e+1),o=m.numToWord(s+1)+(n+1)),i===o?`${i}`:`${i}:${o}`}getBackground(){return this.getBackgrounds()[0][0]}getBackgrounds(){const n=this._deps.getStyles();return this.getValues().map(e=>e.map(s=>{var i;const r=n.getStyleByCell(s);return((i=r==null?void 0:r.bg)==null?void 0:i.rgb)||pt.bg.rgb}))}getCell(n,e){const{startRow:s,endRow:r,startColumn:i,endColumn:o}=this._range,a={startRow:s+n,endRow:s+n,startColumn:i+e,endColumn:i+e};return new st(this._worksheet,a,this._deps)}getColumn(){return this._range.startColumn}getObjectValue(n={}){return this.getObjectValues(n)[0][0]}getObjectValues(n={}){var a;const{startRow:e,endRow:s,startColumn:r,endColumn:i}=this._range,o=this._worksheet.getCellMatrix().getFragment(e,s,r,i).getData();if(n.isIncludeStyle){const l=this._deps.getStyles();for(let c=0;c<=s-e;c++)for(let h=0;h<=i-r;h++){if(o==null||((a=o==null?void 0:o[c])==null?void 0:a[h])==null)continue;const d=o[c][h].s;d&&(o[c][h].s=l.get(d))}}return o}getFontColor(){return this.getFontColors()[0][0]}getFontColors(){const n=this._deps.getStyles();return this.getValues().map(e=>e.map(s=>{var i;const r=n.getStyleByCell(s);return((i=r==null?void 0:r.cl)==null?void 0:i.rgb)||pt.cl.rgb}))}getFontFamilies(){return this._getStyles("ff")}getFontFamily(){return this.getFontFamilies()[0][0]}getUnderlines(){return this._getStyles("ul")}getUnderline(){var e,s;const{p:n}=(e=this.getValue())!=null?e:{};return n&&Array.isArray((s=n.body)==null?void 0:s.textRuns)&&n.body.textRuns.length>0?Wt("ul",n.body)===O.TRUE?{s:O.TRUE}:{s:O.FALSE}:this.getUnderlines()[0][0]}getOverlines(){return this._getStyles("ol")}getOverline(){return this.getOverlines()[0][0]}getStrikeThrough(){var e,s;const{p:n}=(e=this.getValue())!=null?e:{};return n&&Array.isArray((s=n.body)==null?void 0:s.textRuns)&&n.body.textRuns.length>0?Wt("st",n.body)===O.TRUE?{s:O.TRUE}:{s:O.FALSE}:this.getStrikeThroughs()[0][0]}getStrikeThroughs(){return this._getStyles("st")}getFontSize(){var e,s;const{p:n}=(e=this.getValue())!=null?e:{};return n&&Array.isArray((s=n.body)==null?void 0:s.textRuns)&&n.body.textRuns.length>0?n.body.textRuns.some(r=>{var i;return((i=r==null?void 0:r.ts)==null?void 0:i.fs)!=null})?Math.max(...n.body.textRuns.map(r=>{var i;return((i=r==null?void 0:r.ts)==null?void 0:i.fs)||0})):this.getFontSizes()[0][0]:this.getFontSizes()[0][0]}getFontSizes(){return this._getStyles("fs")}getBorder(){return this.getBorders()[0][0]}getBorders(){return this._getStyles("bd")}getFontStyle(){var e,s;const{p:n}=(e=this.getValue())!=null?e:{};return n&&Array.isArray((s=n.body)==null?void 0:s.textRuns)&&n.body.textRuns.length>0?Wt("it",n.body)===O.TRUE?At.ITALIC:At.NORMAL:this._getFontStyles()[0][0]}_getFontStyles(){return this._getStyles("it")}getFontWeight(){var e,s;const{p:n}=(e=this.getValue())!=null?e:{};return n&&Array.isArray((s=n.body)==null?void 0:s.textRuns)&&n.body.textRuns.length>0?Wt("bl",n.body)===O.TRUE?Nt.BOLD:Nt.NORMAL:this._getFontWeights()[0][0]}_getFontWeights(){return this._getStyles("bl")}getGridId(){return this._worksheet.getSheetId()}getHeight(){const{_range:n,_worksheet:e}=this,{startRow:s,endRow:r}=n;let i=0;for(let o=0;o<=r-s;o++){const a=e.getRowHeight(o);i+=a}return i}getHorizontalAlignment(){return this.getHorizontalAlignments()[0][0]}getHorizontalAlignments(){return this._getStyles("ht")}getLastColumn(){return this._range.endColumn}getLastRow(){return this._range.endRow}getNumColumns(){const{startColumn:n,endColumn:e}=this._range;return e-n+1}getNumRows(){const{startRow:n,endRow:e}=this._range;return e-n+1}getRichTextValue(){return this.getRichTextValues()[0][0]}getRichTextValues(){return this.getValues().map(n=>n.map(e=>(e==null?void 0:e.p)||""))}getRowIndex(){return this._range.startRow}getSheet(){return this._worksheet}getTextDirection(){return this.getTextDirections()[0][0]}getTextDirections(){return this._getStyles("td")}getTextRotation(){return this.getTextRotations()[0][0]}getTextRotations(){return this._getStyles("tr")}getTextStyle(){return this.getTextStyles()[0][0]}getTextStyles(){const n=this._deps.getStyles();return this.getValues().map(e=>e.map(s=>n.getStyleByCell(s)))}getVerticalAlignment(){return this.getVerticalAlignments()[0][0]}getVerticalAlignments(){return this._getStyles("vt")}getWidth(){const{_range:n,_worksheet:e}=this,{startColumn:s,endColumn:r}=n;let i=0;for(let o=0;o<=r-s;o++)i+=e.getColumnWidth(o);return i}getWrap(){return this.getWraps()[0][0]}getWraps(){return this._getStyles("tb")}getWrapStrategies(){return this._getStyles("tb")}getWrapStrategy(){return this.getWrapStrategies()[0][0]}forEach(n){st.foreach(this._range,n)}_getStyles(n){const e=this._deps.getStyles();return this.getValues().map(s=>s.map(r=>{const i=e&&e.getStyleByCell(r);return i&&i[n]||pt[n]}))}}function Ii(t,n){if(t.length===0||t[0].length===0)return null;const e=new Array(t[0].length).fill(0);let s=0,r=null;for(let i=0;i<t.length;i++){for(let a=0;a<t[0].length;a++)e[a]=n(t[i][a])?e[a]+1:0;const o=Ai(e);o.area>s&&(s=o.area,r={startColumn:o.start,startRow:i-o.height+1,endColumn:o.end,endRow:i})}return r}function Ai(t){const n=[];let e=0,s={area:0,height:0,start:0,end:0},r=0;for(;r<t.length;)if(n.length===0||t[r]>=t[n[n.length-1]])n.push(r++);else{const i=t[n.pop()],o=n.length===0?r:r-n[n.length-1]-1;i*o>e&&(e=i*o,s={area:e,height:i,start:n.length===0?0:n[n.length-1]+1,end:r-1})}for(;n.length>0;){const i=t[n.pop()],o=n.length===0?r:r-n[n.length-1]-1;i*o>e&&(e=i*o,s={area:e,height:i,start:n.length===0?0:n[n.length-1]+1,end:r-1})}return s}function Ni(t,n){st.foreach(n,(e,s)=>{t[e][s]=void 0})}function Si(t,n){const e=t.toFullArray(),s=[];for(;;){const r=Ii(e,n);if(!r)break;s.push(r),Ni(e,r)}return s}function Li(t,n,e,s=!1){let r={...t};const i=r.startAbsoluteRefType||v.NONE,o=r.endAbsoluteRefType||v.NONE;return!s&&i===v.ALL&&o===v.ALL?r:s||i===v.NONE&&o===v.NONE?z.moveOffset(r,n,e):(i===v.NONE?r={...r,startRow:r.startRow+e,startColumn:r.startColumn+n}:i===v.COLUMN?r={...r,startRow:r.startRow+e}:i===v.ROW&&(r={...r,startColumn:r.startColumn+n}),o===v.NONE?r={...r,endRow:r.endRow+e,endColumn:r.endColumn+n}:o===v.COLUMN?r={...r,endRow:r.endRow+e}:o===v.ROW&&(r={...r,endColumn:r.endColumn+n}),r)}var k=(t=>(t[t.UNDEFINED=0]="UNDEFINED",t[t.OK=1]="OK",t[t.INTERNAL_ERROR=2]="INTERNAL_ERROR",t[t.PERMISSION_DENIED=3]="PERMISSION_DENIED",t[t.NOT_FOUND=4]="NOT_FOUND",t[t.UNAUTHENTICATED=5]="UNAUTHENTICATED",t[t.ALREADY_EXISTS=6]="ALREADY_EXISTS",t[t.INVALID_ARGUMENT=7]="INVALID_ARGUMENT",t[t.TOO_MANY_REQUESTS=8]="TOO_MANY_REQUESTS",t[t.CHANGESET_REVISION_CONFILICT=5001]="CHANGESET_REVISION_CONFILICT",t[t.SNAPSHOT_INVALID_SNAPSHOT=6001]="SNAPSHOT_INVALID_SNAPSHOT",t[t.APPLY_REJECT=7001]="APPLY_REJECT",t[t.APPLY_NON_SEQUENTIAL_REVISION=7002]="APPLY_NON_SEQUENTIAL_REVISION",t[t.APPLY_REVISION_CONFILICT=7003]="APPLY_REVISION_CONFILICT",t[t.CONNECTOR_DATA_TOO_LARGE=8001]="CONNECTOR_DATA_TOO_LARGE",t[t.LICENSE_MAX_UNITS_EXCEEDED=9001]="LICENSE_MAX_UNITS_EXCEEDED",t[t.LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED=9002]="LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED",t[t.LICENSE_IMPORT_SIZE_EXCEEDED=9003]="LICENSE_IMPORT_SIZE_EXCEEDED",t[t.LICENSE_EXPORT_SIZE_EXCEEDED=9004]="LICENSE_EXPORT_SIZE_EXCEEDED",t[t.LICENSE_DISTRO_REJECTED=9005]="LICENSE_DISTRO_REJECTED",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(k||{});function zn(t){return!!(t&&t.code&&t.code!==k.OK&&t.code!=="OK")}var N=(t=>(t[t.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",t[t.UNIVER_DOC=1]="UNIVER_DOC",t[t.UNIVER_SHEET=2]="UNIVER_SHEET",t[t.UNIVER_SLIDE=3]="UNIVER_SLIDE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(N||{});class Bt extends D{}class he{constructor(){_(this,"_data",[])}static create(){return new he}add(n){this._data.indexOf(n)>-1||this._data.push(n)}delete(n){const e=this._data.indexOf(n);this._data.splice(e,1)}getData(){return this._data}}class de{constructor(){_(this,"_data",new Map)}static create(){return new de}add(n,e){this._data.has(n)||this._data.set(n,e)}delete(n){this._data.delete(n)}getData(){return this._data}}class yn{constructor(){_(this,"cursor",0)}reset(){return this.cursor=0,this}moveCursor(n){this.cursor+=n}moveCursorTo(n){this.cursor=n}}var Xn=(t=>(t[t.PARAGRAPH=0]="PARAGRAPH",t[t.SECTION_BREAK=1]="SECTION_BREAK",t[t.TABLE=2]="TABLE",t[t.TABLE_ROW=3]="TABLE_ROW",t[t.TABLE_CELL=4]="TABLE_CELL",t))(Xn||{}),_e=(t=>(t.PARAGRAPH="\r",t.SECTION_BREAK=`
5
5
  `,t.TABLE_START="",t.TABLE_ROW_START="\x1B",t.TABLE_CELL_START="",t.TABLE_CELL_END="",t.TABLE_ROW_END="",t.TABLE_END="",t.CUSTOM_RANGE_START="",t.CUSTOM_RANGE_END="",t.COLUMN_BREAK="\v",t.PAGE_BREAK="\f",t.DOCS_END="\0",t.TAB=" ",t.CUSTOM_BLOCK="\b",t.LETTER="",t.SPACE=" ",t))(_e||{});function fe(t){const n=[];for(const e of t){const{st:s,ed:r,ts:i}=e;if(e.sId===void 0&&delete e.sId,s===r||m.isEmptyObject(i)&&e.sId==null)continue;if(n.length===0){n.push(e);continue}const o=n.pop();Tn(e,o)&&m.hasIntersectionBetweenTwoRanges(o.st,o.ed,e.st,e.ed)?n.push({...e,st:o.st,ed:r}):n.push(o,e)}return n}function qn(t,n,e,s){var c;const{textRuns:r}=t;if(r==null)return;const i=[],o=r.length;let a=!1;const l=(c=n.textRuns)!=null?c:[];if(l.length)for(let h=0,d=l.length;h<d;h++){const f=l[h];f.st+=s,f.ed+=s}for(let h=0;h<o;h++){const d=r[h],{st:f,ed:E}=d;if(E<s)i.push(d);else if(s>=f&&s<=E)if(a)d.st+=e,d.ed+=e,i.push(d);else{a=!0,d.ed+=e;const g=[];if(l.length){const R={...d,st:f,ed:l[0].st};g.push(R),g.push(...l);const C=l[l.length-1],L={...d,st:C.ed,ed:E+e};g.push(L)}else g.push(d);i.push(...g)}else d.st+=e,d.ed+=e,a||(a=!0,i.push(...l)),i.push(d)}a||(a=!0,i.push(...l)),t.textRuns=fe(i)}function Ee(t,n,e,s){const{paragraphs:r}=t;if(r==null)return;const{paragraphs:i,dataStream:o}=n,a=[];let l=-1;for(let h=0,d=r.length;h<d;h++){const f=r[h],{startIndex:E}=f;E>=s&&(f.startIndex+=e),l===-1&&E>=s&&(l=h),a.push(f.startIndex)}let c=-1;if(i){for(let h=0,d=i.length;h<d;h++){const f=i[h];f.startIndex+=s;const E=f.startIndex;c=a.indexOf(E)}if(o===_e.PARAGRAPH&&i.length===1){const h=r[l],d=i[0],f=h.paragraphStyle,E=h.bullet;h.paragraphStyle=d.paragraphStyle,h.bullet=d.bullet,d.paragraphStyle=f,d.bullet=E}c!==-1&&r.splice(c,1),r.push(...i),r.sort(at("startIndex"))}}function Ti(t,n,e,s){const{sectionBreaks:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:c}=l;c>=s&&(l.startIndex+=e)}const i=n.sectionBreaks;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=s}r.push(...i),r.sort(at("startIndex"))}}function Jn(t,n,e,s){const{customBlocks:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:c}=l;c>=s&&(l.startIndex+=e)}const i=n.customBlocks;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=s}r.push(...i),r.sort(at("startIndex"))}}function ge(t,n,e,s){const{tables:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:c,endIndex:h}=l;c>s?(l.startIndex+=e,l.endIndex+=e):h>=s-1&&(l.endIndex+=e)}const i=n.tables;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=s,l.endIndex+=s}r.push(...i),r.sort(at("startIndex"))}}function wi(t,n,e,s){const{customRanges:r}=t;if(r==null)return;for(let o=0,a=r.length;o<a;o++){const l=r[o],{startIndex:c,endIndex:h}=l;c>s?(l.startIndex+=e,l.endIndex+=e):h>=s-1&&(l.endIndex+=e)}const i=n.customRanges;if(i){for(let o=0,a=i.length;o<a;o++){const l=i[o];l.startIndex+=s,l.endIndex+=s}r.push(...i),r.sort(at("startIndex"))}}function Zn(t,n,e){const{textRuns:s}=t,r=e,i=e+n,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{st:d,ed:f}=h;if(r<=d&&i>=f){o.push({...h,st:d-r,ed:f-r});continue}else d<=r&&f>=i?(o.push({...h,st:r-r,ed:i-r}),h.ed-=n):r>=d&&r<f?(o.push({...h,st:r-r,ed:f-r}),h.ed=r):i>d&&i<=f?(o.push({...h,st:d-r,ed:i-r}),h.st=i-n,h.ed-=n):d>=i&&(h.st-=n,h.ed-=n);a.push(h)}t.textRuns=a}return o}function Qn(t,n,e){const{paragraphs:s}=t,r=e,i=e+n,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{startIndex:d}=h;if(d>=r&&d<i){o.push({...h,startIndex:d-e});continue}else d>=i&&(h.startIndex-=n);a.push(h)}t.paragraphs=a}return o}function ts(t,n,e){const{sectionBreaks:s}=t,r=e,i=e+n-1,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{startIndex:d}=h;if(d>=r&&d<=i){o.push({...h,startIndex:d-e});continue}else d>i&&(h.startIndex-=n);a.push(h)}t.sectionBreaks=a}return o}function es(t,n,e){const{customBlocks:s}=t,r=e,i=e+n-1,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{startIndex:d}=h;if(d>=r&&d<=i){o.push({...h,startIndex:d-e});continue}else d>i&&(h.startIndex-=n);a.push(h)}t.customBlocks=a}return o}function ns(t,n,e){const{tables:s}=t,r=e,i=e+n-1,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{startIndex:d,endIndex:f}=h;if(r<=d&&i>=f){o.push({...h,startIndex:d-e,endIndex:f-e});continue}else if(d<=r&&f>=i){const E=ee(d,f,r,i);h.startIndex=E[0],h.endIndex=E[1]}else i<d&&(h.startIndex-=n,h.endIndex-=n);a.push(h)}t.tables=a}return o}function ss(t,n,e){const{customRanges:s}=t,r=e,i=e+n-1,o=[];if(s){const a=[];for(let l=0,c=s.length;l<c;l++){const h=s[l],{startIndex:d,endIndex:f}=h;if(r<=d&&i>=f){o.push({...h,startIndex:d-e,endIndex:f-e});continue}else if(d<=r&&f>=i){const E=ee(d,f,r,i);h.startIndex=E[0],h.endIndex=E[1]}else i<d&&(h.startIndex-=n,h.endIndex-=n);a.push(h)}t.customRanges=a}return o}function bi(t,n,e){const{dataStream:s}=t,r=e,i=e+n,o=Zn(t,n,e),a=Qn(t,n,e),l=ts(t,n,e),c=es(t,n,e),h=ns(t,n,e),d=ss(t,n,e);let f="";return s&&(t.dataStream=vn(s,r,i),f=s.slice(r,i)),{dataStream:f,textRuns:o,paragraphs:a,sectionBreaks:l,customBlocks:c,tables:h,customRanges:d}}function vi(t,n,e,s){t.dataStream=bn(t.dataStream,s,n.dataStream),qn(t,n,e,s),Ee(t,n,e,s),Ti(t,n,e,s),Jn(t,n,e,s),ge(t,n,e,s),wi(t,n,e,s)}var kt=(t=>(t.BULLET_LIST="BULLET_LIST",t.ORDER_LIST="ORDER_LIST",t))(kt||{});const Ui={BULLET_LIST:{listType:"BULLET_LIST",nestingLevel:[{bulletAlignment:j.START,glyphFormat:" %0",textStyle:{fs:12},startNumber:0,glyphSymbol:"●",hanging:21,indentStart:21},{bulletAlignment:j.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"■",hanging:21,indentStart:42},{bulletAlignment:j.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"◆",hanging:21,indentStart:63}]},ORDER_LIST:{listType:"ORDER_LIST",nestingLevel:[{bulletAlignment:j.START,glyphFormat:" %1.",textStyle:{fs:12},startNumber:0,glyphType:ct.DECIMAL,hanging:21,indentStart:21},{bulletAlignment:j.START,glyphFormat:" %1.%2)",textStyle:{fs:12},startNumber:0,glyphType:ct.DECIMAL,hanging:21,indentStart:42},{bulletAlignment:j.START,glyphFormat:" %1.%2.%3.",textStyle:{fs:12},startNumber:0,glyphType:ct.DECIMAL,hanging:21,indentStart:63}]}};function Di(t,n,e,s,r){const i=Mi(t,n,e,s,r),o=Pi(t,n,e,s,r),a=Hi(t,n,e,s,r),l=Fi(t,n,e,s,r),c=pi(t,n,e,s,r),h=Wi(t,n,e,s,r);return{dataStream:"",textRuns:i,paragraphs:o,sectionBreaks:a,customBlocks:l,tables:c,customRanges:h}}function Mi(t,n,e,s,r){const{textRuns:i}=t,{textRuns:o}=n;if(i==null||o==null)return;const a=Zn(t,e,s);if(r!==H.REPLACE){const l=rs(o,a,r);n.textRuns=l}return qn(t,n,e,s),a}function rs(t,n,e){if(n.length===0)return t;t=m.deepClone(t),n=m.deepClone(n);const s=[],r=t.length,i=n.length;let o=0,a=0,l=null;function c(){return l?(s.push(l),l=null,!0):!1}for(;o<r&&a<i;){const{st:E,ed:g,ts:R}=t[o],{st:C,ed:L,ts:P,sId:F}=n[a];let Z;e===H.COVER?Z={...P,...R}:Z={...R,...P},g<C?(c()||s.push(t[o]),o++):L<E?(c()||s.push(n[a]),a++):(s.push({st:Math.min(E,C),ed:Math.max(E,C),ts:E<C?{...R}:{...P},sId:E<C?void 0:F}),s.push({st:Math.max(E,C),ed:Math.min(g,L),ts:Z,sId:F}),g<L?(o++,n[a].st=g):(a++,t[o].st=L),l={st:Math.min(g,L),ed:Math.max(g,L),ts:g<L?{...P}:{...R},sId:g<L?F:void 0})}c();const h=s[s.length-1],d=t[r-1],f=n[i-1];return h.ed!==Math.max(d.ed,f.ed)&&(d.ed>f.ed?s.push(d):s.push(f)),fe(s)}function Pi(t,n,e,s,r){const{paragraphs:i}=t,{paragraphs:o}=n;if(i==null||o==null)return;const a=Qn(t,e,s);if(r!==H.REPLACE){const l=[];for(const c of o){const{startIndex:h,paragraphStyle:d,bullet:f}=c;let E=[];for(const g of a){const{startIndex:R,paragraphStyle:C,bullet:L}=g;let P,F;if(r===H.COVER?(P={...C,...d},F={listId:"",listType:kt.BULLET_LIST,nestingLevel:0,textStyle:{},...L,...f}):(P={...d,...C},F={listId:"",listType:kt.BULLET_LIST,nestingLevel:0,textStyle:{},...f,...L}),h===R){E.push({startIndex:h,paragraphStyle:P,bullet:F});break}}l.push(...E),E=[]}n.paragraphs=l}return Ee(t,n,e,s),a}function Hi(t,n,e,s,r){const{sectionBreaks:i}=t,{sectionBreaks:o}=n;if(i==null||o==null)return;const a=ts(t,e,s);if(r!==H.REPLACE){const l=[];for(const c of o){const{startIndex:h}=c;let d=[];for(const f of a){const{startIndex:E}=f;if(h===E){r===H.COVER?d.push({...f,...c}):d.push({...c,...f});break}}l.push(...d),d=[]}n.sectionBreaks=l}return Ee(t,n,e,s),a}function Fi(t,n,e,s,r){const{customBlocks:i}=t,{customBlocks:o}=n;if(i==null||o==null)return;const a=es(t,e,s);if(r!==H.REPLACE){const l=[];for(const c of o){const{startIndex:h}=c;let d=[];for(const f of a){const{startIndex:E}=f;if(h===E){r===H.COVER?d.push({...f,...c}):d.push({...c,...f});break}}l.push(...d),d=[]}n.customBlocks=l}return Jn(t,n,e,s),a}function pi(t,n,e,s,r){const{tables:i}=t,{tables:o}=n;if(i==null||o==null)return;const a=ns(t,e,s);if(r!==H.REPLACE){const l=[];for(const c of o){const{startIndex:h,endIndex:d}=c;let f=[];for(const E of a){const{startIndex:g,endIndex:R}=E;if(g>=h&&R<=d){r===H.COVER?f.push({...E,...c}):f.push({...c,...E});break}}l.push(...f),f=[]}n.tables=l}return ge(t,n,e,s),a}function Wi(t,n,e,s,r){const{customRanges:i}=t,{tables:o}=n;if(i==null||o==null)return;const a=ss(t,e,s);if(r!==H.REPLACE){const l=[];for(const c of o){const{startIndex:h,endIndex:d}=c;let f=[];for(const E of a){const{startIndex:g,endIndex:R}=E;if(g>=h&&R<=d){r===H.COVER?f.push({...E,...c}):f.push({...c,...E});break}}l.push(...f),f=[]}n.customRanges=l}return ge(t,n,e,s),a}var S=(t=>(t.RETAIN="r",t.INSERT="i",t.DELETE="d",t))(S||{});function Re(t,n,e){const{dataStream:s,textRuns:r=[],paragraphs:i=[]}=t,o={dataStream:s.slice(n,e)},a=[];for(const c of r){const h=m.deepClone(c),{st:d,ed:f}=h;m.hasIntersectionBetweenTwoRanges(d,f,n,e)&&(n>=d&&n<=f?a.push({...h,st:n,ed:Math.min(e,f)}):e>=d&&e<=f?a.push({...h,st:Math.max(n,d),ed:e}):a.push(h))}a.length&&(o.textRuns=a.map(c=>{const{st:h,ed:d}=c;return{...c,st:h-n,ed:d-n}}));const l=[];for(const c of i){const{startIndex:h}=c;h>=n&&h<=e&&l.push(m.deepClone(c))}return l.length&&(o.paragraphs=l.map(c=>({...c,startIndex:c.startIndex-n}))),o}function me(t,n,e=H.COVER){if(n.dataStream!=="")throw new Error("Cannot compose other body with non-empty dataStream");const s={dataStream:t.dataStream},{textRuns:r=[],paragraphs:i=[]}=t,{textRuns:o=[],paragraphs:a=[]}=n,l=rs(o,r,e);l.length&&(s.textRuns=l);const c=[];let h=0,d=0;for(;h<i.length&&d<a.length;){const f=i[h],E=a[d],{startIndex:g}=f,{startIndex:R}=E;g===R?(c.push(m.deepMerge(f,E)),h++,d++):g<R?(c.push(m.deepClone(f)),h++):(c.push(m.deepClone(E)),d++)}return h<i.length&&c.push(...i.slice(h)),d<a.length&&c.push(...a.slice(d)),c.length&&(s.paragraphs=c),s}function Bi(t){const{body:n}=t;if(n==null)return!0;const{textRuns:e=[],paragraphs:s=[]}=n;return e.length===0&&s.length===0}function ki(t=m.generateRandomId(6),n=Q.EN_US,e=""){return{id:t,locale:n,title:e,body:{dataStream:`\r
6
- `,textRuns:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:5,lineSpacing:1,spaceBelow:0}}],sectionBreaks:[{startIndex:1}]},documentStyle:{pageSize:{width:793.3333333333334,height:1122.6666666666667},marginTop:50,marginBottom:50,marginRight:40,marginLeft:40,renderConfig:{vertexAngle:0,centerAngle:0}},settings:{}}}const Ce={id:"default_doc",documentStyle:{}};class Gi extends Bt{constructor(e){super();_(this,"type",N.UNIVER_DOC);_(this,"snapshot");this.snapshot={...Ce,...e}}getUnitId(){throw new Error("Method not implemented.")}get drawings(){return this.snapshot.drawings}get documentStyle(){return this.snapshot.documentStyle}get lists(){return this.snapshot.lists}get body(){return this.snapshot.body}get zoomRatio(){var e;return((e=this.snapshot.settings)==null?void 0:e.zoomRatio)||1}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getParentRenderUnitId(){return this.snapshot.parentRenderUnitId}getSnapshot(){return this.snapshot}updateDocumentId(e){this.snapshot.id=e}updateDocumentRenderConfig(e){const{documentStyle:s}=this.snapshot;s.renderConfig==null?s.renderConfig=e:s.renderConfig={...s.renderConfig,...e}}updateDocumentStyle(e){this.snapshot.documentStyle==null?this.snapshot.documentStyle=e:this.snapshot.documentStyle={...this.snapshot.documentStyle,...e}}updateDocumentDataMargin(e){const{t:s,l:r,b:i,r:o}=e,{documentStyle:a}=this.snapshot;s!=null&&(a.marginTop=s),r!=null&&(a.marginLeft=r),i!=null&&(a.marginBottom=i),o!=null&&(a.marginRight=o)}updateDocumentDataPageSize(e,s){const{documentStyle:r}=this.snapshot;if(!r.pageSize){e=e!=null?e:Number.POSITIVE_INFINITY,s=s!=null?s:Number.POSITIVE_INFINITY,r.pageSize={width:e,height:s};return}e!==void 0&&(r.pageSize.width=e),s!==void 0&&(r.pageSize.height=s)}updateDrawing(e,s){const{drawings:r}=this,{width:i,height:o,left:a,top:l}=s,c=r==null?void 0:r[e];if(!c)return;const h=c.objectTransform;h.size.width=i,h.size.height=o,h.positionH.posOffset=a,h.positionV.posOffset=l}setZoomRatio(e=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:e}:this.snapshot.settings.zoomRatio=1}}class rt extends Gi{constructor(e){var r;super(m.isEmptyObject(e)?ki():e);_(this,"_unitId");_(this,"headerModelMap",new Map);_(this,"footerModelMap",new Map);const s=6;this._unitId=(r=this.snapshot.id)!=null?r:m.generateRandomId(s),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(e=>{e.dispose()}),this.footerModelMap.forEach(e=>{e.dispose()})}getRev(){var e;return(e=this.snapshot.rev)!=null?e:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(e){if(e.id&&e.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Ce,...e},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(e){if(e!=null){if(this.headerModelMap.has(e))return this.headerModelMap.get(e);if(this.footerModelMap.has(e))return this.footerModelMap.get(e)}return this}getUnitId(){return this._unitId}apply(e){const s=[],r=new yn;return r.reset(),e.forEach(i=>{if(i=m.deepClone(i),i.t===S.RETAIN){const{coverType:o,body:a,len:l,segmentId:c}=i;if(a!=null){const h=this._updateApply(a,l,r.cursor,o,c);s.push({...i,t:S.RETAIN,coverType:H.REPLACE,body:h})}else s.push({...i,t:S.RETAIN});r.moveCursor(l)}else if(i.t===S.INSERT){const{body:o,len:a,segmentId:l,line:c}=i;this._insertApply(o,a,r.cursor,l),r.moveCursor(a),s.push({t:S.DELETE,len:a,line:c,segmentId:l})}else if(i.t===S.DELETE){const{len:o,segmentId:a}=i,l=this._deleteApply(o,r.cursor,a);s.push({...i,t:S.INSERT,body:l})}else throw new Error(`Unknown action type for action: ${i}.`)}),s}sliceBody(e,s){const r=this.getBody();if(r!=null)return Re(r,e,s)}_updateApply(e,s,r,i=H.COVER,o){if(e==null)throw new Error("updateBody is none");const a=this.snapshot,l=Ut(a,o);if(l==null)throw new Error("no body has changed");return Di(l,e,s,r,i)}_deleteApply(e,s,r){const i=this.snapshot,o=Ut(i,r);if(o==null)throw new Error("no body has changed");return e<=0?{dataStream:""}:bi(o,e,s)}_insertApply(e,s,r,i){const o=this.snapshot,a=Ut(o,i);if(s!==0){if(a==null)throw new Error("no body has changed");vi(a,e,s,r)}}_initializeHeaderFooterModel(){const{headers:e,footers:s}=this.getSnapshot();if(e)for(const r in e){const i=e[r];this.headerModelMap.set(r,new rt(i))}if(s)for(const r in s){const i=s[r];this.footerModelMap.set(r,new rt(i))}}updateDocumentId(e){super.updateDocumentId(e),this._unitId=e}}async function is(t){for(const[n,e]of t.entries())try{if(!await e())return{index:n,result:!1}}catch(s){return{index:n,result:!1,error:s}}return{result:!0,index:-1}}function os(t){for(const[n,e]of t.entries())try{if(!e())return{index:n,result:!1}}catch(s){return{index:n,result:!1,error:s}}return{result:!0,index:-1}}const ft=A.createIdentifier("univer.context-service");class as extends D{constructor(){super(...arguments);_(this,"_contextChanged$",new I.Subject);_(this,"contextChanged$",this._contextChanged$.asObservable());_(this,"_contextMap",new Map)}dispose(){super.dispose(),this._contextChanged$.complete()}getContextValue(e){var s;return(s=this._contextMap.get(e))!=null?s:!1}setContextValue(e,s){this._contextMap.set(e,s),this._contextChanged$.next({[e]:s})}subscribeContextValue$(e){return new I.Observable(s=>{const r=this._contextChanged$.pipe(I.filter(i=>typeof i[e]<"u")).subscribe(i=>s.next(i[e]));return this._contextMap.has(e)&&s.next(this._contextMap.get(e)),()=>r.unsubscribe()})}}var ls=(t=>(t[t.SILENT=0]="SILENT",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.VERBOSE=4]="VERBOSE",t))(ls||{});const y=A.createIdentifier("univer.log");class us extends D{constructor(){super(...arguments);_(this,"_logLevel",3)}debug(...e){this._logLevel>=4&&this._log(console.debug,...e)}log(...e){this._logLevel>=3&&this._log(console.log,...e)}warn(...e){this._logLevel>=2&&this._log(console.warn,...e)}error(...e){this._logLevel>=1&&this._log(console.error,...e)}setLogLevel(e){this._logLevel=e}_log(e,...s){const r=s[0];/^\[(.*?)\]/g.test(r)?e(`\x1B[97;104m${r}\x1B[0m`,...s.slice(1)):e(...s)}}var $i=Object.defineProperty,Vi=Object.getOwnPropertyDescriptor,xi=(t,n,e,s)=>{for(var r=s>1?void 0:s?Vi(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&$i(n,e,r),r},cs=(t,n)=>(e,s)=>n(e,s,t),Gt=(t=>(t[t.COMMAND=0]="COMMAND",t[t.OPERATION=1]="OPERATION",t[t.MUTATION=2]="MUTATION",t))(Gt||{});const Et=A.createIdentifier("anywhere.command-service");class ji{constructor(){_(this,"_commands",new Map)}registerCommand(n){if(this._commands.has(n.id))throw new Error(`[CommandRegistry]: command "${n.id}" has been registered before.`);return this._commands.set(n.id,n),U(()=>{var e;this._commands.delete(n.id),(e=n.onDispose)==null||e.call(n)})}hasCommand(n){return this._commands.has(n)}getCommand(n){return this._commands.has(n)?[this._commands.get(n)]:null}}const hs={id:"nil",type:0,handler:()=>!0};u.CommandService=class{constructor(n,e){_(this,"_commandRegistry");_(this,"_beforeCommandExecutionListeners",[]);_(this,"_commandExecutedListeners",[]);_(this,"_multiCommandDisposables",new Map);_(this,"_commandExecutingLevel",0);_(this,"_commandExecutionStack",[]);this._injector=n,this._logService=e,this._commandRegistry=new ji,this._registerCommand(hs)}hasCommand(n){return this._commandRegistry.hasCommand(n)}registerCommand(n){return this._registerCommand(n)}registerMultipleCommand(n){return this._registerMultiCommand(n)}beforeCommandExecuted(n){if(this._beforeCommandExecutionListeners.indexOf(n)===-1)return this._beforeCommandExecutionListeners.push(n),U(()=>{const e=this._beforeCommandExecutionListeners.indexOf(n);this._beforeCommandExecutionListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}onCommandExecuted(n){if(this._commandExecutedListeners.indexOf(n)===-1)return this._commandExecutedListeners.push(n),U(()=>{const e=this._commandExecutedListeners.indexOf(n);this._commandExecutedListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}async executeCommand(n,e,s){const r=this._commandRegistry.getCommand(n);if(r){const[i]=r,o={id:i.id,type:i.type,params:e},a=this._pushCommandExecutionStack(o);this._beforeCommandExecutionListeners.forEach(c=>c(o,s));const l=await this._execute(i,e,s);return this._commandExecutedListeners.forEach(c=>c(o,s)),a.dispose(),l}throw new Error(`[CommandService]: command "${n}" is not registered.`)}syncExecuteCommand(n,e,s){var i;const r=this._commandRegistry.getCommand(n);if(r){const[o]=r,a={id:o.id,type:o.type,params:e};if(o.type===2){const h=ei(this._commandExecutionStack,d=>d.type===0);h&&(a.params=(i=a.params)!=null?i:{},a.params.trigger=h.id)}const l=this._pushCommandExecutionStack(a);this._beforeCommandExecutionListeners.forEach(h=>h(a,s));const c=this._syncExecute(o,e,s);return this._commandExecutedListeners.forEach(h=>h(a,s)),l.dispose(),c}throw new Error(`[CommandService]: command "${n}" is not registered.`)}_pushCommandExecutionStack(n){return this._commandExecutionStack.push(n),U(()=>Pt(this._commandExecutionStack,n))}_registerCommand(n){return this._commandRegistry.registerCommand(n)}_registerMultiCommand(n){const e=this._commandRegistry.getCommand(n.id);let s;if(e){if(e[0].multi!==!0)throw new Error("Command has registered as a single command.");s=e[0]}else{const i=new se;s=new Ki(n.id),i.add(this._commandRegistry.registerCommand(s)),i.add(U(()=>{this._multiCommandDisposables.delete(n.id)})),this._multiCommandDisposables.set(n.id,i)}const r=s.registerImplementation(n);return U(()=>{var i;r.dispose(),s.hasImplementations()||(i=this._multiCommandDisposables.get(n.id))==null||i.dispose()})}async _execute(n,e,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(this._commandExecutingLevel,0))}executing command "${n.id}"`),this._commandExecutingLevel++;let r;try{r=await this._injector.invoke(n.handler,e,s),this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}_syncExecute(n,e,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(0,this._commandExecutingLevel))}executing command "${n.id}".`),this._commandExecutingLevel++;let r;try{if(r=this._injector.invoke(n.handler,e,s),r instanceof Promise)throw new TypeError("[CommandService]: Command handler should not return a promise.");this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}},u.CommandService=xi([cs(0,A.Inject(A.Injector)),cs(1,y)],u.CommandService);class Ki{constructor(n){_(this,"name");_(this,"multi",!0);_(this,"type",0);_(this,"priority",0);_(this,"_implementations",[]);_(this,"handler",async(n,e)=>{if(!this._implementations.length)return!1;const s=n.get(y),r=n.get(ft),i=n.get(A.Injector);for(const o of this._implementations){const a=o.command.preconditions;if((!a||a&&a(r))&&(s.debug("[MultiCommand]",`executing implementation "${o.command.name}".`),await i.invoke(o.command.handler,e)))return!0}return!1});this.id=n,this.name=n}registerImplementation(n){const e={command:n};return this._implementations.push(e),this._implementations.sort((s,r)=>r.command.priority-s.command.priority),U(()=>{var r;const s=this._implementations.indexOf(e);this._implementations.splice(s,1),(r=n.onDispose)==null||r.call(n)})}hasImplementations(){return this._implementations.length>0}}function Oe(t,n,e){const s=t.map(r=>()=>n.syncExecuteCommand(r.id,r.params,e));return os(s)}function Yi(t,n,e){const s=t.map(r=>()=>n.executeCommand(r.id,r.params,e));return is(s)}const ds=A.createIdentifier("univer.config-service");class _s{constructor(){_(this,"_config",new Map)}getConfig(n){return this._config.get(n)}setConfig(n,e){this._config.set(n,e)}deleteConfig(n){this._config.delete(n)}}class fs extends D{constructor(){super(...arguments);_(this,"_error$",new I.Subject);_(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(e){this._error$.next({errorKey:e})}}const zi="__default_document_sub_component_id20231101__";class Es{constructor(){_(this,"_managerInfo",new Map);_(this,"_remove$",new I.Subject);_(this,"remove$",this._remove$.asObservable());_(this,"_andOrUpdate$",new I.Subject);_(this,"andOrUpdate$",this._andOrUpdate$.asObservable());_(this,"_pluginUpdate$",new I.Subject);_(this,"pluginUpdate$",this._pluginUpdate$.asObservable())}getFloatObject(n){return this._getFloatingObject(n)}getFloatObjects(n){return this._getFloatingObjects(n)}dispose(){this._remove$.complete(),this._andOrUpdate$.complete(),this._pluginUpdate$.complete(),this._managerInfo.clear()}clear(n){const e=this._clearByParam(n);this._remove$.next(e)}addOrUpdate(n){const e=this._addByParam(n);this._andOrUpdate$.next(e)}BatchAddOrUpdate(n){const e=[];n.forEach(s=>{e.push(...this._addByParam(s))}),this._andOrUpdate$.next(e)}remove(n){const e=this._removeByParam(n);this._remove$.next(e)}pluginUpdateRefresh(n){this._pluginUpdate$.next(n)}_getFloatingObjects(n){var r;if(n==null)return;const{unitId:e,subUnitId:s}=n;return(r=this._managerInfo.get(e))==null?void 0:r.get(s)}_getFloatingObject(n){var i,o;if(n==null)return;const{unitId:e,subUnitId:s,floatingObjectId:r}=n;return(o=(i=this._managerInfo.get(e))==null?void 0:i.get(s))==null?void 0:o.get(r)}_addByParam(n){const{unitId:e,subUnitId:s,floatingObject:r,floatingObjectId:i}=n;this._managerInfo.has(e)||this._managerInfo.set(e,new Map);const o=this._managerInfo.get(e);return o.has(s)||o.set(s,new Map),o.get(s).set(i,r),[{unitId:e,subUnitId:s,floatingObjectId:i,floatingObject:r}]}_clearByParam(n){const e=this._getFloatingObjects(n),{unitId:s,subUnitId:r}=n,i=[];return e==null||e.forEach((o,a)=>{i.push({unitId:s,subUnitId:r,floatingObjectId:a,floatingObject:o})}),e==null||e.clear(),i}_removeByParam(n){const e=this._getFloatingObjects(n),s=e==null?void 0:e.get(n.floatingObjectId);return s==null?[]:(e==null||e.delete(n.floatingObjectId),[{...n,floatingObject:s}])}}const gs=A.createIdentifier("univer.floating-object.service");class Rs{constructor(n={}){_(this,"_styles");_(this,"_cacheMap",new $n(1e5));this._styles=n,this._generateCacheMap()}each(n){return Object.entries(this._styles).forEach(n),this}search(n,e){if(this._cacheMap.has(e))return this._cacheMap.get(e);const s=this._getExistingStyleId(n);return s||"-1"}get(n){return typeof n!="string"?n:(n=String(n),this._styles[n])}add(n,e){const s=m.generateRandomId(6);return this._styles[s]=n,this._cacheMap.set(e,s),s}setValue(n){if(n==null)return;const e=JSON.stringify(n),s=this.search(n,e);return s!=="-1"?s:this.add(n,e)}toJSON(){return this._styles}getStyleByCell(n){let e;n&&m.isObject(n.s)?e=n.s:e=(n==null?void 0:n.s)&&this.get(n.s);const s=n==null?void 0:n.interceptorStyle;return s?{...e,...s}:e}_generateCacheMap(){const{_styles:n,_cacheMap:e}=this;for(const s in n){const r=JSON.stringify(n[s]);e.set(r,s)}}_getExistingStyleId(n){const{_styles:e}=this;for(const s in e)if(m.diffValue(e[s],n))return s;return null}}class yi{constructor(n,e){_(this,"_columnData",{});this._config=n,this._columnData=e}getColumnData(){return this._columnData}getColVisible(n){const{_columnData:e}=this,s=e[n];return s?s.hd!==O.TRUE:!0}getHiddenCols(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getColVisible(o);r&&a?(r=!1,s.push({rangeType:p.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!a&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:p.COLUMN}),s}getVisibleCols(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getColVisible(o);r&&!a?(r=!1,s.push({rangeType:p.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&a&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:p.COLUMN}),s}getColumnDatas(n,e){const s={};let r=0;for(let i=n;i<n+e;i++){const o=this.getColumnOrCreate(i);s[r]=o,r++}return s}getSize(){return Y(this._columnData)}getColumnWidth(n){const{_columnData:e}=this,s=this._config;let r=0;return r=(e[n]||{hd:O.FALSE,w:s.defaultColumnWidth}).w||s.defaultColumnWidth,r}getColumn(n){const e=this._columnData[n];if(e)return e}getColumnOrCreate(n){const{_columnData:e}=this,s=this._config,r=e[n];if(r)return r;const i={w:s.defaultColumnWidth,hd:O.FALSE};return this._columnData[n]=i,i}}class Xi{constructor(n,e,s){_(this,"_rowData");this._config=n,this._viewModel=e,this._rowData=s}getRowData(){return this._rowData}getRowDatas(n,e){const s={};let r=0;for(let i=n;i<n+e;i++){const o=this.getRowOrCreate(i);s[r]=o,r++}return s}getRowHeight(n,e=1){const{_rowData:s}=this,r=this._config;let i=0;for(let o=0;o<e;o++){const a=s[o+n]||{hd:O.FALSE,h:r.defaultRowHeight},{ia:l,ah:c,h=r.defaultRowHeight}=a;i+=(l==null||l===O.TRUE)&&typeof c=="number"?c:h}return i}getRow(n){return this._rowData[n]}getRowOrCreate(n){const{_rowData:e}=this,s=e[n];if(s)return s;const r=this._config,i={hd:O.FALSE,h:r.defaultRowHeight};return e[n]=i,i}getHiddenRows(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getRowRawVisible(o);r&&a?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:p.ROW})):!r&&!a&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:p.ROW}),s}getVisibleRows(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getRowRawVisible(o);r&&!a?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:p.ROW})):!r&&a&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:p.ROW}),s}getRowRawVisible(n){const e=this.getRow(n);return e?e.hd!==O.TRUE:!0}getSize(){return Y(this._rowData)}}const qi="DEFAULT_WORKSHEET_ROW_COUNT",ms=1e3,Ji="DEFAULT_WORKSHEET_COLUMN_COUNT",Cs=20,Zi="DEFAULT_WORKSHEET_ROW_HEIGHT",Os=19,Qi="DEFAULT_WORKSHEET_COLUMN_WIDTH",Is=73,to="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",As=46,eo="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",Ns=20;function Ss(t){const n={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:O.FALSE,rowCount:ms,columnCount:Cs,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Is,defaultRowHeight:Os,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:O.TRUE,rowHeader:{width:As,hidden:O.FALSE},columnHeader:{height:Ns,hidden:O.FALSE},selections:["A1"],rightToLeft:O.FALSE};return Object.keys(n).forEach(e=>{const s=e;typeof t[s]>"u"&&(t[s]=n[s])}),t}class Ls extends D{constructor(e){super();_(this,"_cellContentInterceptor",null);_(this,"_rowFilteredInterceptor",null);this.getRawCell=e}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(e,s){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(e,s):this.getRawCell(e,s)}getRowFiltered(e){var s,r;return(r=(s=this._rowFilteredInterceptor)==null?void 0:s.getRowFiltered(e))!=null?r:!1}registerCellContentInterceptor(e){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=e,U(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(e){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=e,U(()=>this._rowFilteredInterceptor=null)}}class gt{constructor(n,e,s){_(this,"_sheetId");_(this,"_snapshot");_(this,"_cellData");_(this,"_rowManager");_(this,"_columnManager");_(this,"_viewModel");var a;this.unitId=n,this._styles=s,this._snapshot=Ss(e);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(a=this._snapshot.id)!=null?a:m.generateRandomId(6),this._cellData=new V(o),this._viewModel=new Ls((l,c)=>this.getCellRaw(l,c)),this._rowManager=new Xi(this._snapshot,this._viewModel,i),this._columnManager=new yi(this._snapshot,r)}__interceptViewModel(n){n(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const n=this.getCellMatrix(),e=this.getMergeData();let s=-1,r=-1,i=-1,o=-1,a=!1,l=!1;return n.forEach((c,h)=>{Object.keys(h).forEach(d=>{const f=+d,E=n.getValue(c,f),g=E!=null&&E.s?this._styles.get(E.s):null,R=(g==null?void 0:g.bd)&&(g.bd.b||g.bd.l||g.bd.r||g.bd.t||g.bd.bc_tr||g.bd.bl_tr||g.bd.ml_tr||g.bd.tl_bc||g.bd.tl_br||g.bd.tl_mr);(E&&(E.v||E.p)||g!=null&&g.bg||R)&&(a?s=Math.min(s,c):(s=c,a=!0),r=Math.max(r,c),l?i=Math.min(i,f):(l=!0,i=f),o=Math.max(o,f))})}),e.forEach(c=>{a?s=Math.min(s,c.startRow):(s=c.startRow,a=!0),r=Math.max(r,c.endRow),l?i=Math.min(i,c.startColumn):(i=c.startColumn,a=!0),o=Math.max(o,c.endColumn)}),!a||!l?null:{startColumn:i,startRow:s,endColumn:o,endRow:r}}getRowManager(){return this._rowManager}getUnitId(){return this.unitId}getSheetId(){return this._sheetId}getColumnManager(){return this._columnManager}getName(){return this._snapshot.name}clone(){const{_snapshot:n}=this,e=m.deepClone(n);return new gt(this.unitId,e,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(n,e){const s=this._snapshot.mergeData;for(let r=0;r<s.length;r++){const i=s[r];if(z.intersects({startRow:n,startColumn:e,endRow:n,endColumn:e},i))return i}return null}getCell(n,e){return n<0||e<0?null:this._viewModel.getCell(n,e)}getCellRaw(n,e){return this.getCellMatrix().getValue(n,e)}getRowFiltered(n){return this._viewModel.getRowFiltered(n)}getMatrixWithMergedCells(n,e,s,r,i=!1){const o=this.getCellMatrix(),a=this._snapshot.mergeData.filter(c=>z.intersects({startRow:n,startColumn:e,endRow:s,endColumn:r},c)),l=new V;return ue(n,s,e,r).forEach((c,h)=>{const d=i?this.getCellRaw(c,h):this.getCell(c,h);d&&l.setValue(c,h,d)}),a.forEach(c=>{const{startColumn:h,startRow:d,endColumn:f,endRow:E}=c;ue(d,E,h,f).forEach((g,R)=>{g===d&&R===h&&l.setValue(g,R,{...o.getValue(g,R),rowSpan:E-d+1,colSpan:f-h+1}),(g!==d||R!==h)&&l.realDeleteValue(g,R)})}),l}getRange(n,e,s,r){return typeof n=="object"?new st(this,n,{getStyles:()=>this._styles}):new st(this,{startRow:n,startColumn:e,endColumn:r||e,endRow:s||n},{getStyles:()=>this._styles})}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:n}=this,{columnCount:e}=n;return e}getMaxRows(){const{_snapshot:n}=this,{rowCount:e}=n;return e}getRowCount(){return this._snapshot.rowCount}setRowCount(n){this._snapshot.rowCount=n}getColumnCount(){return this._snapshot.columnCount}setColumnCount(n){this._snapshot.columnCount=n}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:n}=this,{showGridlines:e}=n;return e===0}getTabColor(){const{_snapshot:n}=this,{tabColor:e}=n;return e}getColumnWidth(n){return this.getColumnManager().getColumnWidth(n)}getRowHeight(n){return this._viewModel.getRowFiltered(n)?0:this.getRowManager().getRowHeight(n)}getRowVisible(n){return this._viewModel.getRowFiltered(n)?!1:this.getRowRawVisible(n)}getRowRawVisible(n){return this.getRowManager().getRowRawVisible(n)}getHiddenRows(n,e){const s=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(n,e);return r.forEach(i=>i.endColumn=s),r}getColVisible(n){return this._columnManager.getColVisible(n)}getHiddenCols(n,e){const s=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(n,e);return r.forEach(i=>i.endRow=s),r}getVisibleRows(){const n=this.getRowCount();return this._rowManager.getVisibleRows(0,n-1)}getVisibleCols(){const n=this.getColumnCount();return this._columnManager.getVisibleCols(0,n-1)}isRightToLeft(){const{_snapshot:n}=this,{rightToLeft:e}=n;return e}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(n){return n&&(n.v!==void 0||n.f!==void 0||n.p!==void 0)}iterateByRow(n,e=!0){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=n,a=this;return{[Symbol.iterator]:()=>{let l=s,c=r;return{next(){for(;;){if(c>o&&(l+=1,c=r),l>i)return{done:!0,value:void 0};const h=a.getCell(l,c),d=!h,f=a.getMergedCell(l,c);if(f){if(l!==f.startRow||c!==f.startColumn){c=f.endColumn+1;continue}if(d&&e){c=f.endColumn+1;continue}const g={row:l,col:c,value:h};return g.colSpan=f.endColumn-f.startColumn+1,g.rowSpan=f.endRow-f.startRow+1,c=f.endColumn+1,{done:!1,value:g}}if(d&&e)c+=1;else{const E={row:l,col:c,value:h};return c+=1,{done:!1,value:E}}}}}}}}iterateByColumn(n,e=!0,s=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:a}=n,l=this;return{[Symbol.iterator]:()=>{let c=r,h=i;return{next(){for(;;){if(c>o&&(h+=1,c=r),h>a)return{done:!0,value:void 0};const d=l.getMergedCell(c,h);if(d){const g=c!==d.startRow,R=g||h!==d.startColumn;if(s&&R||!s&&g){c=d.endRow+1;continue}const C=l.getCell(d.startRow,d.startColumn);if(!C&&e){c=d.endRow+1;continue}const P={row:c,col:d.startColumn,value:C};return P.colSpan=d.endColumn-d.startColumn+1,P.rowSpan=d.endRow-d.startRow+1,c=d.endRow+1,{done:!1,value:P}}const f=l.getCell(c,h);if(!f&&e)c+=1;else{const g={row:c,col:h,value:f};return c+=1,{done:!1,value:g}}}}}}}}}function no(t){var s,r;if(!t)return"";const n=(r=(s=t.p)==null?void 0:s.body)==null?void 0:r.dataStream;if(n)return n;const e=t.v;return typeof e=="string"?t.t===et.BOOLEAN?e.toUpperCase():e:typeof e=="number"?t.t===et.BOOLEAN?e?"TRUE":"FALSE":e.toString():typeof e=="boolean"?e?"TRUE":"FALSE":""}const so="0.1.8";function ro(t="",n=Q.ZH_CN,e=""){return{id:t,sheetOrder:[],name:e,appVersion:so,locale:n,styles:{},sheets:{},resources:[]}}var io=Object.defineProperty,oo=Object.getOwnPropertyDescriptor,ao=(t,n,e,s)=>{for(var r=s>1?void 0:s?oo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&io(n,e,r),r},lo=(t,n)=>(e,s)=>n(e,s,t);function uo(t,n){return`${t.getUnitId()}|${n.getSheetId()}`}u.Workbook=class extends Bt{constructor(e={},s){super();_(this,"type",N.UNIVER_SHEET);_(this,"_sheetCreated$",new I.Subject);_(this,"sheetCreated$",this._sheetCreated$.asObservable());_(this,"_sheetDisposed$",new I.Subject);_(this,"sheetDisposed$",this._sheetDisposed$.asObservable());_(this,"_activeSheet$",new I.BehaviorSubject(null));_(this,"activeSheet$",this._activeSheet$.asObservable());_(this,"_worksheets");_(this,"_styles");_(this,"_snapshot");_(this,"_unitId");_(this,"_count");this._logService=s;const r=ro();m.isEmptyObject(e)?this._snapshot=r:this._snapshot=m.commonExtend(r,e);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=m.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new Rs(i),this._count=1,this._worksheets=new Map,this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._snapshot.name}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete()}save(){return m.deepClone(this._snapshot)}static isIRangeType(e){return typeof e=="string"||"startRow"in e||"row"in e}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}getUnitId(){return this._unitId}getRev(){var e;return(e=this._snapshot.rev)!=null?e:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(e,s,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[e])return!1;i[e]=r,o.splice(s,0,e);const a=new gt(this._unitId,r,this._styles);return this._worksheets.set(e,a),this._sheetCreated$.next(a),!0}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(e){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>r===e)}getRawActiveSheet(){return this._activeSheet}getActiveSheet(){const e=this.getRawActiveSheet();if(e)return e;const s=this._snapshot.sheetOrder;for(let i=0,o=s.length;i<o;i++){const a=this._worksheets.get(s[i]);if(a&&a.isSheetHidden()!==O.TRUE)return this.setActiveSheet(a),a}const r=this._worksheets.get(s[0]);return this.setActiveSheet(r),r}setActiveSheet(e){this._activeSheet$.next(e)}removeSheet(e){var r;return this._worksheets.get(e)?(((r=this._activeSheet)==null?void 0:r.getSheetId())===e&&this.setActiveSheet(null),this._worksheets.delete(e),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(e),1),delete this._snapshot.sheets[e],!0):!1}getActiveSheetIndex(){const{sheetOrder:e}=this._snapshot;return e.findIndex(s=>this._worksheets.get(s)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:e}=this._snapshot;return e.map(s=>this._worksheets.get(s))}getSheetsName(){const{sheetOrder:e}=this._snapshot,s=[];return e.forEach(r=>{const i=this._worksheets.get(r);i&&s.push(i.getName())}),s}getSheetIndex(e){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>e.getSheetId()===r)}getSheetBySheetName(e){const{sheetOrder:s}=this._snapshot,r=s.find(i=>this._worksheets.get(i).getName()===e);return this._worksheets.get(r)}getSheetBySheetId(e){return this._worksheets.get(e)}getSheetByIndex(e){const{sheetOrder:s}=this._snapshot;return this._worksheets.get(s[e])}getHiddenWorksheets(){return this.getSheets().filter(e=>e.getConfig().hidden===O.TRUE).map(e=>e.getConfig().id)}transformRangeType(e){if(typeof e=="string")return this._getCellRange(e);if(typeof e!="string"&&"row"in e){const s=e;return{sheetId:"",range:{startRow:s.row[0],startColumn:s.column[0],endRow:s.row[1],endColumn:s.column[1]}}}return typeof e!="string"&&"startRow"in e?{sheetId:"",range:e}:_t}load(e){this._snapshot=e}checkSheetName(e){return this.getSheetsName().includes(e)}uniqueSheetName(e="Sheet1"){let s=e;for(;this.checkSheetName(s);)s=e+this._count,this._count++;return s}generateNewSheetName(e){let s=e+this._count;for(;this.checkSheetName(s);)s=e+this._count,this._count++;return s}_getCellRange(e){var h,d,f,E,g;let s="",r="";if(e.indexOf("!")>-1){const R=e.split("!");s=R[0],r=R[1],s=s.replace(/\\'/g,"'").replace(/''/g,"'"),s.substring(0,1)==="'"&&s.substring(s.length-1,1)==="'"&&(s=s.substring(1,s.length-1))}else r=e;if(r.indexOf(":")===-1){const R=Number.parseInt(r.replace(/[^0-9]/g,""),10)-1,C=m.ABCatNum(r.replace(/[^A-Za-z]/g,""));return!Number.isNaN(R)&&!Number.isNaN(C)?{sheetId:s,range:{startRow:R,endRow:R,startColumn:C,endColumn:C}}:_t}r=r.split(":");const i=[0,0],o=[0,0],a=((h=this.getSheetBySheetName(s))==null?void 0:h.getMaxRows())||((d=this.getActiveSheet())==null?void 0:d.getMaxRows()),l=((f=this.getSheetBySheetName(s))==null?void 0:f.getMaxColumns())||((E=this.getActiveSheet())==null?void 0:E.getMaxColumns());return i[0]=Number.parseInt(r[0].replace(/[^0-9]/g,""),10)-1,i[1]=Number.parseInt(r[1].replace(/[^0-9]/g,""),10)-1,Number.isNaN(i[0])&&(i[0]=0),Number.isNaN(i[1])&&(i[1]=a),i[0]>i[1]||(o[0]=m.ABCatNum(r[0].replace(/[^A-Za-z]/g,"")),o[1]=m.ABCatNum(r[1].replace(/[^A-Za-z]/g,"")),Number.isNaN(o[0])&&(o[0]=0),Number.isNaN(o[1])&&(o[1]=l),o[0]>o[1])?_t:{sheetId:((g=this.getSheetBySheetName(s))==null?void 0:g.getSheetId())||"",range:{startRow:i[0],endRow:i[1],startColumn:o[0],endColumn:o[1]}}}_passWorksheetSnapshots(){const{_snapshot:e,_worksheets:s}=this,{sheets:r,sheetOrder:i}=e;if(m.isEmptyObject(r)){const o=m.generateRandomId();r[o]={id:o}}for(const o in r){const a=r[o],{name:l}=a;a.name=this.uniqueSheetName(l),a.name!==l&&this._logService.debug("[Workbook]",`The worksheet name ${l} is duplicated, we changed it to ${a.name}. Please fix the problem in your snapshot.`);const c=new gt(this._unitId,a,this._styles);s.set(o,c),i.includes(o)||i.push(o)}}},u.Workbook=ao([lo(1,y)],u.Workbook);class Ie extends Bt{constructor(e){var s;super();_(this,"type",N.UNIVER_SLIDE);_(this,"_snapshot");_(this,"_unitId");this._snapshot={...Kn,...e},this._unitId=(s=this._snapshot.id)!=null?s:m.generateRandomId(6)}getContainer(){return this._snapshot.container}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var e;return(e=this._snapshot.body)==null?void 0:e.pages}getPageOrder(){var e;return(e=this._snapshot.body)==null?void 0:e.pageOrder}getPage(e){const s=this.getPages();return s==null?void 0:s[e]}getElementsByPage(e){var s;return(s=this.getPage(e))==null?void 0:s.pageElements}getElement(e,s){var r;return(r=this.getElementsByPage(e))==null?void 0:r[s]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:Qt.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const Rt="FOCUSING_SHEET",$t="FOCUSING_DOC",Vt="FOCUSING_SLIDE",co="FOCUSING_EDITOR_BUT_HIDDEN",Ts="EDITOR_ACTIVATED",ho="FOCUSING_EDITOR_INPUT_FORMULA",ws="FOCUSING_FORMULA_EDITOR",_o="FOCUSING_UNIVER_EDITOR",fo="FOCUSING_EDITOR_INPUT_FORMULA",Eo="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE";var go=Object.defineProperty,Ro=Object.getOwnPropertyDescriptor,mo=(t,n,e,s)=>{for(var r=s>1?void 0:s?Ro(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&go(n,e,r),r},bs=(t,n)=>(e,s)=>n(e,s,t);const X=A.createIdentifier("univer.current");u.UniverInstanceService=class extends D{constructor(e,s){super();_(this,"_unitsByType",new Map);_(this,"_createHandler");_(this,"_ctorByType",new Map);_(this,"_currentUnits$",new I.BehaviorSubject({}));_(this,"currentUnits$",this._currentUnits$.asObservable());_(this,"_unitAdded$",new I.Subject);_(this,"unitAdded$",this._unitAdded$.asObservable());_(this,"_unitDisposed$",new I.Subject);_(this,"unitDisposed$",this._unitDisposed$.asObservable());_(this,"_focused$",new I.BehaviorSubject(null));_(this,"focused$",this._focused$.asObservable());this._injector=e,this._contextService=s}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(e){this._createHandler=e}createUnit(e,s){return this._createHandler(e,s,this._ctorByType.get(e))}registerCtorForType(e,s){return this._ctorByType.set(e,s),{dispose:()=>{this._ctorByType.delete(e)}}}getCurrentTypeOfUnit$(e){return this.currentUnits$.pipe(I.map(s=>{var r;return(r=s[e])!=null?r:null}),I.distinctUntilChanged())}getCurrentUnitForType(e){return this._currentUnits$.getValue()[e]}setCurrentUnitForType(e){const s=this._getUnitById(e);if(!s)throw new Error(`[UniverInstanceService]: no document with unitId ${e}!`);this._currentUnits$.next({...this._currentUnits$.getValue(),[s[1]]:s[0]})}getTypeOfUnitAdded$(e){return this._unitAdded$.pipe(I.filter(s=>s.type===e))}__addUnit(e){const s=e.type;this._unitsByType.has(s)||this._unitsByType.set(s,[]),this._unitsByType.get(s).push(e),this._unitAdded$.next(e),this._currentUnits$.next({...this._currentUnits$.getValue(),[s]:e})}getTypeOfUnitDisposed$(e){return this.unitDisposed$.pipe(I.filter(s=>s.type===e))}getUnit(e,s){var i;const r=(i=this._getUnitById(e))==null?void 0:i[0];return s&&(r==null?void 0:r.type)!==s?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(N.UNIVER_DOC)}getUniverDocInstance(e){return this.getUnit(e,N.UNIVER_DOC)}getUniverSheetInstance(e){return this.getUnit(e,N.UNIVER_SHEET)}getAllUnitsForType(e){var s;return(s=this._unitsByType.get(e))!=null?s:[]}changeDoc(e,s){const r=this.getAllUnitsForType(N.UNIVER_DOC),i=r.find(o=>o.getUnitId()===e);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(s)}get focused(){var s;const e=this._focused$.getValue();return e?(s=this._getUnitById(e))==null?void 0:s[0]:null}focusUnit(e){this._focused$.next(e),this.focused instanceof u.Workbook?(this._contextService.setContextValue($t,!1),this._contextService.setContextValue(Rt,!0),this._contextService.setContextValue(Vt,!1)):this.focused instanceof rt?(this._contextService.setContextValue($t,!0),this._contextService.setContextValue(Rt,!1),this._contextService.setContextValue(Vt,!1)):this.focused instanceof Ie&&(this._contextService.setContextValue($t,!1),this._contextService.setContextValue(Rt,!1),this._contextService.setContextValue(Vt,!0))}getFocusedUnit(){return this.focused}getUnitType(e){const s=this._getUnitById(e);if(!s)throw new Error(`[UniverInstanceService]: No document with unitId ${e}`);return s[1]}disposeUnit(e){const s=this._getUnitById(e);if(!s)return!1;const[r,i]=s,o=this._unitsByType.get(i),a=o.indexOf(r);return o.splice(a,1),this._unitDisposed$.next(r),this._currentUnits$.next({...this._currentUnits$.getValue(),[i]:null}),this._focused$.next(null),!0}_getUnitById(e){for(const[s,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===e);if(i)return[i,s]}}},u.UniverInstanceService=mo([bs(0,A.Inject(A.Injector)),bs(1,ft)],u.UniverInstanceService);var b=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(b||{});const Co={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},xt=new Map;function Ae(t,n){return function(r){Ne(t,n)}}function Ne(t,n){xt.has(t)||xt.set(t,[]),xt.get(t).push(n)}var Oo=Object.defineProperty,Io=Object.getOwnPropertyDescriptor,vs=(t,n,e,s)=>{for(var r=s>1?void 0:s?Io(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Oo(n,e,r),r},Se=(t,n)=>(e,s)=>n(e,s,t);u.LifecycleService=class extends D{constructor(e){super();_(this,"_lifecycle$",new I.BehaviorSubject(b.Starting));_(this,"lifecycle$",this._lifecycle$.asObservable());_(this,"_lock",!1);this._logService=e,this._reportProgress(b.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(e){if(e<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(e!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(e),this._lifecycle$.next(e),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new I.Observable(e=>(this.stage===b.Starting||(this.stage===b.Ready?e.next(b.Starting):this.stage===b.Rendered?(e.next(b.Starting),e.next(b.Ready)):(e.next(b.Starting),e.next(b.Ready),e.next(b.Rendered))),this._lifecycle$.subscribe(e)))}_reportProgress(e){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${Co[e]}".`)}},u.LifecycleService=vs([Se(0,y)],u.LifecycleService),u.LifecycleInitializerService=class extends D{constructor(e,s){super();_(this,"_seenTokens",new Set);this._lifecycleService=e,this._injector=s}initModulesOnStage(e){var s;(s=xt.get(e))==null||s.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}},u.LifecycleInitializerService=vs([Se(0,A.Inject(u.LifecycleService)),Se(1,A.Inject(A.Injector))],u.LifecycleInitializerService);class mt extends D{constructor(){super();_(this,"_currentLocale",Q.ZH_CN);_(this,"_locales",null);_(this,"localeChanged$",new I.Subject);_(this,"t",(e,...s)=>{if(!this._locales)throw new Error("Locale not initialized");const r=e.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return s.forEach((a,l)=>{o=o.replace(`{${l}}`,a)}),o}else return e});this.disposeWithMe(U(()=>this.localeChanged$.complete()))}load(e){var s;this._locales=m.deepMerge((s=this._locales)!=null?s:{},e)}setLocale(e){this._currentLocale=e,this.localeChanged$.next()}getLocales(){var e;return(e=this._locales)==null?void 0:e[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(e,s){const r=s.shift();if(r&&e&&r in e){const i=e[r];return s.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,s):i}return null}}const jt=A.createIdentifier("resource-manager-service");var Ao=Object.defineProperty,No=Object.getOwnPropertyDescriptor,So=(t,n,e,s)=>{for(var r=s>1?void 0:s?No(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Ao(n,e,r),r},Us=(t,n)=>(e,s)=>n(e,s,t);const Le=A.createIdentifier("univer.permission-service");u.PermissionService=class extends D{constructor(e,s){super();_(this,"_permissionPointMap",new Map);_(this,"deletePermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e);if(r){const i=r.get(s);i&&(i.complete(),this._permissionPointMap.delete(s))}});_(this,"addPermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e)||new Map;return r.has(s.id)?!1:(r.set(s.id,new I.BehaviorSubject(s)),this._permissionPointMap.set(e,r),!0)});_(this,"updatePermissionPoint",(e,s,r)=>{const i=this._permissionPointMap.get(e);if(!i)return;const o=i.get(s);if(o){const a=o.getValue();a.value=r,a.status=le.DONE,o.next(a)}});_(this,"getPermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e);if(!r)return;const i=r.get(s);if(i)return i.getValue()});this._resourceManagerService=e,this._univerInstanceService=s}_toJson(e){const s=this._permissionPointMap.get(e);let r=[];return s&&(r=[...s.keys()].reduce((i,o)=>{const a=s.get(o);return a&&i.push(a.getValue()),i},[])),JSON.stringify(r)}_parseJson(e){return JSON.parse(e)}composePermission$(e,s){const r=this._permissionPointMap.get(e),i=s.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.asObservable()});return I.combineLatest(i).pipe(nr.map(o=>(o.every(a=>this._permissionPointMap.get(a.id)),o)))}composePermission(e,s){const r=this._permissionPointMap.get(e);return s.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.getValue()})}},u.PermissionService=So([Ae(b.Starting,u.PermissionService),Us(0,A.Inject(jt)),Us(1,A.Inject(X))],u.PermissionService);const Ds="univer.editable";class Kt extends Vn{constructor(e){super();_(this,"id",Ds);_(this,"value",!0);_(this,"unitID");this.unitID=e}}var Lo=Object.defineProperty,To=Object.getOwnPropertyDescriptor,wo=(t,n,e,s)=>{for(var r=s>1?void 0:s?To(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Lo(n,e,r),r},Ms=(t,n)=>(e,s)=>n(e,s,t);u.UniverPermissionService=class extends D{constructor(n,e){super(),this._permissionService=n,this._univerInstanceService=e,this._init()}_init(){this._univerInstanceService.getTypeOfUnitAdded$(N.UNIVER_SHEET).subscribe(n=>{const e=new Kt(n.getUnitId());this._permissionService.addPermissionPoint(n.getUnitId(),e)})}getEditable(n=(e=>(e=this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET))==null?void 0:e.getUnitId())()){if(!n)return;const s=new Kt(n),r=this._permissionService.getPermissionPoint(n,s.id);return r==null?void 0:r.value}setEditable(n,e){const s=new Kt(n);this._permissionService.updatePermissionPoint(n,s.id,e)}},u.UniverPermissionService=wo([Ae(b.Starting,u.UniverPermissionService),Ms(0,A.Inject(Le)),Ms(1,A.Inject(X))],u.UniverPermissionService);class Ps extends D{constructor(){super(...arguments);_(this,"_resourceMap",new Map);_(this,"_register$",new I.Subject);_(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(e){return this.getAllResourceHooks().map(i=>{const o=i.toJson(e);return{name:i.pluginName,data:o}})}registerPluginResource(e){const s=e.pluginName;if(this._resourceMap.has(s))throw new Error(`the pluginName is registered {${s}}`);return this._resourceMap.set(s,e),this._register$.next(e),U(()=>this._resourceMap.delete(s))}disposePluginResource(e){this._resourceMap.delete(e)}loadResources(e,s){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=s==null?void 0:s.find(a=>a.name===r.pluginName))==null?void 0:o.data;if(i)try{const a=r.parseJson(i);r.onLoad(e,a)}catch{console.error("LoadResources Error!")}})}unloadResources(e){this.getAllResourceHooks().forEach(s=>{s.onUnLoad(e)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}var bo=Object.defineProperty,vo=Object.getOwnPropertyDescriptor,Uo=(t,n,e,s)=>{for(var r=s>1?void 0:s?vo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&bo(n,e,r),r},Hs=(t,n)=>(e,s)=>n(e,s,t);let Te=class extends D{constructor(n,e){super();_(this,"saveWorkbook",n=>{const e=n.getUnitId(),s=this._resourceManagerService.getResources(e)||[],r=n.getSnapshot();return r.resources=s,r});this._resourceManagerService=n,this._univerInstanceService=e,this._init()}_init(){const n=s=>{s.businesses.forEach(r=>{switch(r){case N.UNRECOGNIZED:case N.UNIVER_UNKNOWN:case N.UNIVER_SLIDE:case N.UNIVER_DOC:break;case N.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(N.UNIVER_SHEET).forEach(i=>{const a=(i.getSnapshot().resources||[]).find(l=>l.name===s.pluginName);if(a)try{const l=s.parseJson(a.data);s.onLoad(i.getUnitId(),l)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(s=>{n(s)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(s=>{n(s)})),this.disposeWithMe(U(this._univerInstanceService.getTypeOfUnitAdded$(N.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.loadResources(s.getUnitId(),s.getSnapshot().resources)}))),this.disposeWithMe(U(this._univerInstanceService.getTypeOfUnitDisposed$(N.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.unloadResources(s.getUnitId())})))}};Te=Uo([Hs(0,A.Inject(jt)),Hs(1,A.Inject(X))],Te);const we=A.createIdentifier("resource-loader-service");Ne(b.Ready,we);class be extends D{constructor(){super();_(this,"_currentTheme");_(this,"_currentTheme$",new I.BehaviorSubject({}));_(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(U(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(e){this._currentTheme=e,this._currentTheme$.next(e)}}const Fs="__defaultDocumentNormalEditorSpecialUnitId_20231006__",ps="__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__",Do=`\r
6
+ `,textRuns:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:5,lineSpacing:1,spaceBelow:0}}],sectionBreaks:[{startIndex:1}]},documentStyle:{pageSize:{width:793.3333333333334,height:1122.6666666666667},marginTop:50,marginBottom:50,marginRight:40,marginLeft:40,renderConfig:{vertexAngle:0,centerAngle:0}},settings:{}}}const Ce={id:"default_doc",documentStyle:{}};class Gi extends Bt{constructor(e){super();_(this,"type",N.UNIVER_DOC);_(this,"snapshot");this.snapshot={...Ce,...e}}getUnitId(){throw new Error("Method not implemented.")}get drawings(){return this.snapshot.drawings}get documentStyle(){return this.snapshot.documentStyle}get lists(){return this.snapshot.lists}get body(){return this.snapshot.body}get zoomRatio(){var e;return((e=this.snapshot.settings)==null?void 0:e.zoomRatio)||1}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getParentRenderUnitId(){return this.snapshot.parentRenderUnitId}getSnapshot(){return this.snapshot}updateDocumentId(e){this.snapshot.id=e}updateDocumentRenderConfig(e){const{documentStyle:s}=this.snapshot;s.renderConfig==null?s.renderConfig=e:s.renderConfig={...s.renderConfig,...e}}updateDocumentStyle(e){this.snapshot.documentStyle==null?this.snapshot.documentStyle=e:this.snapshot.documentStyle={...this.snapshot.documentStyle,...e}}updateDocumentDataMargin(e){const{t:s,l:r,b:i,r:o}=e,{documentStyle:a}=this.snapshot;s!=null&&(a.marginTop=s),r!=null&&(a.marginLeft=r),i!=null&&(a.marginBottom=i),o!=null&&(a.marginRight=o)}updateDocumentDataPageSize(e,s){const{documentStyle:r}=this.snapshot;if(!r.pageSize){e=e!=null?e:Number.POSITIVE_INFINITY,s=s!=null?s:Number.POSITIVE_INFINITY,r.pageSize={width:e,height:s};return}e!==void 0&&(r.pageSize.width=e),s!==void 0&&(r.pageSize.height=s)}updateDrawing(e,s){const{drawings:r}=this,{width:i,height:o,left:a,top:l}=s,c=r==null?void 0:r[e];if(!c)return;const h=c.objectTransform;h.size.width=i,h.size.height=o,h.positionH.posOffset=a,h.positionV.posOffset=l}setZoomRatio(e=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:e}:this.snapshot.settings.zoomRatio=1}}class rt extends Gi{constructor(e){var r;super(m.isEmptyObject(e)?ki():e);_(this,"_unitId");_(this,"headerModelMap",new Map);_(this,"footerModelMap",new Map);const s=6;this._unitId=(r=this.snapshot.id)!=null?r:m.generateRandomId(s),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(e=>{e.dispose()}),this.footerModelMap.forEach(e=>{e.dispose()})}getRev(){var e;return(e=this.snapshot.rev)!=null?e:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(e){if(e.id&&e.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Ce,...e},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(e){if(e!=null){if(this.headerModelMap.has(e))return this.headerModelMap.get(e);if(this.footerModelMap.has(e))return this.footerModelMap.get(e)}return this}getUnitId(){return this._unitId}apply(e){const s=[],r=new yn;return r.reset(),e.forEach(i=>{if(i=m.deepClone(i),i.t===S.RETAIN){const{coverType:o,body:a,len:l,segmentId:c}=i;if(a!=null){const h=this._updateApply(a,l,r.cursor,o,c);s.push({...i,t:S.RETAIN,coverType:H.REPLACE,body:h})}else s.push({...i,t:S.RETAIN});r.moveCursor(l)}else if(i.t===S.INSERT){const{body:o,len:a,segmentId:l,line:c}=i;this._insertApply(o,a,r.cursor,l),r.moveCursor(a),s.push({t:S.DELETE,len:a,line:c,segmentId:l})}else if(i.t===S.DELETE){const{len:o,segmentId:a}=i,l=this._deleteApply(o,r.cursor,a);s.push({...i,t:S.INSERT,body:l})}else throw new Error(`Unknown action type for action: ${i}.`)}),s}sliceBody(e,s){const r=this.getBody();if(r!=null)return Re(r,e,s)}_updateApply(e,s,r,i=H.COVER,o){if(e==null)throw new Error("updateBody is none");const a=this.snapshot,l=Ut(a,o);if(l==null)throw new Error("no body has changed");return Di(l,e,s,r,i)}_deleteApply(e,s,r){const i=this.snapshot,o=Ut(i,r);if(o==null)throw new Error("no body has changed");return e<=0?{dataStream:""}:bi(o,e,s)}_insertApply(e,s,r,i){const o=this.snapshot,a=Ut(o,i);if(s!==0){if(a==null)throw new Error("no body has changed");vi(a,e,s,r)}}_initializeHeaderFooterModel(){const{headers:e,footers:s}=this.getSnapshot();if(e)for(const r in e){const i=e[r];this.headerModelMap.set(r,new rt(i))}if(s)for(const r in s){const i=s[r];this.footerModelMap.set(r,new rt(i))}}updateDocumentId(e){super.updateDocumentId(e),this._unitId=e}}async function is(t){for(const[n,e]of t.entries())try{if(!await e())return{index:n,result:!1}}catch(s){return{index:n,result:!1,error:s}}return{result:!0,index:-1}}function os(t){for(const[n,e]of t.entries())try{if(!e())return{index:n,result:!1}}catch(s){return{index:n,result:!1,error:s}}return{result:!0,index:-1}}const ft=A.createIdentifier("univer.context-service");class as extends D{constructor(){super(...arguments);_(this,"_contextChanged$",new I.Subject);_(this,"contextChanged$",this._contextChanged$.asObservable());_(this,"_contextMap",new Map)}dispose(){super.dispose(),this._contextChanged$.complete()}getContextValue(e){var s;return(s=this._contextMap.get(e))!=null?s:!1}setContextValue(e,s){this._contextMap.set(e,s),this._contextChanged$.next({[e]:s})}subscribeContextValue$(e){return new I.Observable(s=>{const r=this._contextChanged$.pipe(I.filter(i=>typeof i[e]<"u")).subscribe(i=>s.next(i[e]));return this._contextMap.has(e)&&s.next(this._contextMap.get(e)),()=>r.unsubscribe()})}}var ls=(t=>(t[t.SILENT=0]="SILENT",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.VERBOSE=4]="VERBOSE",t))(ls||{});const y=A.createIdentifier("univer.log");class us extends D{constructor(){super(...arguments);_(this,"_logLevel",3)}debug(...e){this._logLevel>=4&&this._log(console.debug,...e)}log(...e){this._logLevel>=3&&this._log(console.log,...e)}warn(...e){this._logLevel>=2&&this._log(console.warn,...e)}error(...e){this._logLevel>=1&&this._log(console.error,...e)}setLogLevel(e){this._logLevel=e}_log(e,...s){const r=s[0];/^\[(.*?)\]/g.test(r)?e(`\x1B[97;104m${r}\x1B[0m`,...s.slice(1)):e(...s)}}var $i=Object.defineProperty,Vi=Object.getOwnPropertyDescriptor,xi=(t,n,e,s)=>{for(var r=s>1?void 0:s?Vi(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&$i(n,e,r),r},cs=(t,n)=>(e,s)=>n(e,s,t),Gt=(t=>(t[t.COMMAND=0]="COMMAND",t[t.OPERATION=1]="OPERATION",t[t.MUTATION=2]="MUTATION",t))(Gt||{});const Et=A.createIdentifier("anywhere.command-service");class ji{constructor(){_(this,"_commands",new Map)}registerCommand(n){if(this._commands.has(n.id))throw new Error(`[CommandRegistry]: command "${n.id}" has been registered before.`);return this._commands.set(n.id,n),U(()=>{var e;this._commands.delete(n.id),(e=n.onDispose)==null||e.call(n)})}hasCommand(n){return this._commands.has(n)}getCommand(n){return this._commands.has(n)?[this._commands.get(n)]:null}}const hs={id:"nil",type:0,handler:()=>!0};u.CommandService=class{constructor(n,e){_(this,"_commandRegistry");_(this,"_beforeCommandExecutionListeners",[]);_(this,"_commandExecutedListeners",[]);_(this,"_multiCommandDisposables",new Map);_(this,"_commandExecutingLevel",0);_(this,"_commandExecutionStack",[]);this._injector=n,this._logService=e,this._commandRegistry=new ji,this._registerCommand(hs)}hasCommand(n){return this._commandRegistry.hasCommand(n)}registerCommand(n){return this._registerCommand(n)}registerMultipleCommand(n){return this._registerMultiCommand(n)}beforeCommandExecuted(n){if(this._beforeCommandExecutionListeners.indexOf(n)===-1)return this._beforeCommandExecutionListeners.push(n),U(()=>{const e=this._beforeCommandExecutionListeners.indexOf(n);this._beforeCommandExecutionListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}onCommandExecuted(n){if(this._commandExecutedListeners.indexOf(n)===-1)return this._commandExecutedListeners.push(n),U(()=>{const e=this._commandExecutedListeners.indexOf(n);this._commandExecutedListeners.splice(e,1)});throw new Error("[CommandService]: could not add a listener twice.")}async executeCommand(n,e,s){const r=this._commandRegistry.getCommand(n);if(r){const[i]=r,o={id:i.id,type:i.type,params:e},a=this._pushCommandExecutionStack(o);this._beforeCommandExecutionListeners.forEach(c=>c(o,s));const l=await this._execute(i,e,s);return this._commandExecutedListeners.forEach(c=>c(o,s)),a.dispose(),l}throw new Error(`[CommandService]: command "${n}" is not registered.`)}syncExecuteCommand(n,e,s){var i;const r=this._commandRegistry.getCommand(n);if(r){const[o]=r,a={id:o.id,type:o.type,params:e};if(o.type===2){const h=ei(this._commandExecutionStack,d=>d.type===0);h&&(a.params=(i=a.params)!=null?i:{},a.params.trigger=h.id)}const l=this._pushCommandExecutionStack(a);this._beforeCommandExecutionListeners.forEach(h=>h(a,s));const c=this._syncExecute(o,e,s);return this._commandExecutedListeners.forEach(h=>h(a,s)),l.dispose(),c}throw new Error(`[CommandService]: command "${n}" is not registered.`)}_pushCommandExecutionStack(n){return this._commandExecutionStack.push(n),U(()=>Pt(this._commandExecutionStack,n))}_registerCommand(n){return this._commandRegistry.registerCommand(n)}_registerMultiCommand(n){const e=this._commandRegistry.getCommand(n.id);let s;if(e){if(e[0].multi!==!0)throw new Error("Command has registered as a single command.");s=e[0]}else{const i=new se;s=new Ki(n.id),i.add(this._commandRegistry.registerCommand(s)),i.add(U(()=>{this._multiCommandDisposables.delete(n.id)})),this._multiCommandDisposables.set(n.id,i)}const r=s.registerImplementation(n);return U(()=>{var i;r.dispose(),s.hasImplementations()||(i=this._multiCommandDisposables.get(n.id))==null||i.dispose()})}async _execute(n,e,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(this._commandExecutingLevel,0))}executing command "${n.id}"`),this._commandExecutingLevel++;let r;try{r=await this._injector.invoke(n.handler,e,s),this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}_syncExecute(n,e,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(0,this._commandExecutingLevel))}executing command "${n.id}".`),this._commandExecutingLevel++;let r;try{if(r=this._injector.invoke(n.handler,e,s),r instanceof Promise)throw new TypeError("[CommandService]: Command handler should not return a promise.");this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}},u.CommandService=xi([cs(0,A.Inject(A.Injector)),cs(1,y)],u.CommandService);class Ki{constructor(n){_(this,"name");_(this,"multi",!0);_(this,"type",0);_(this,"priority",0);_(this,"_implementations",[]);_(this,"handler",async(n,e)=>{if(!this._implementations.length)return!1;const s=n.get(y),r=n.get(ft),i=n.get(A.Injector);for(const o of this._implementations){const a=o.command.preconditions;if((!a||a&&a(r))&&(s.debug("[MultiCommand]",`executing implementation "${o.command.name}".`),await i.invoke(o.command.handler,e)))return!0}return!1});this.id=n,this.name=n}registerImplementation(n){const e={command:n};return this._implementations.push(e),this._implementations.sort((s,r)=>r.command.priority-s.command.priority),U(()=>{var r;const s=this._implementations.indexOf(e);this._implementations.splice(s,1),(r=n.onDispose)==null||r.call(n)})}hasImplementations(){return this._implementations.length>0}}function Oe(t,n,e){const s=t.map(r=>()=>n.syncExecuteCommand(r.id,r.params,e));return os(s)}function Yi(t,n,e){const s=t.map(r=>()=>n.executeCommand(r.id,r.params,e));return is(s)}const ds=A.createIdentifier("univer.config-service");class _s{constructor(){_(this,"_config",new Map)}getConfig(n){return this._config.get(n)}setConfig(n,e){this._config.set(n,e)}deleteConfig(n){this._config.delete(n)}}class fs extends D{constructor(){super(...arguments);_(this,"_error$",new I.Subject);_(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(e){this._error$.next({errorKey:e})}}const zi="__default_document_sub_component_id20231101__";class Es{constructor(){_(this,"_managerInfo",new Map);_(this,"_remove$",new I.Subject);_(this,"remove$",this._remove$.asObservable());_(this,"_andOrUpdate$",new I.Subject);_(this,"andOrUpdate$",this._andOrUpdate$.asObservable());_(this,"_pluginUpdate$",new I.Subject);_(this,"pluginUpdate$",this._pluginUpdate$.asObservable())}getFloatObject(n){return this._getFloatingObject(n)}getFloatObjects(n){return this._getFloatingObjects(n)}dispose(){this._remove$.complete(),this._andOrUpdate$.complete(),this._pluginUpdate$.complete(),this._managerInfo.clear()}clear(n){const e=this._clearByParam(n);this._remove$.next(e)}addOrUpdate(n){const e=this._addByParam(n);this._andOrUpdate$.next(e)}BatchAddOrUpdate(n){const e=[];n.forEach(s=>{e.push(...this._addByParam(s))}),this._andOrUpdate$.next(e)}remove(n){const e=this._removeByParam(n);this._remove$.next(e)}pluginUpdateRefresh(n){this._pluginUpdate$.next(n)}_getFloatingObjects(n){var r;if(n==null)return;const{unitId:e,subUnitId:s}=n;return(r=this._managerInfo.get(e))==null?void 0:r.get(s)}_getFloatingObject(n){var i,o;if(n==null)return;const{unitId:e,subUnitId:s,floatingObjectId:r}=n;return(o=(i=this._managerInfo.get(e))==null?void 0:i.get(s))==null?void 0:o.get(r)}_addByParam(n){const{unitId:e,subUnitId:s,floatingObject:r,floatingObjectId:i}=n;this._managerInfo.has(e)||this._managerInfo.set(e,new Map);const o=this._managerInfo.get(e);return o.has(s)||o.set(s,new Map),o.get(s).set(i,r),[{unitId:e,subUnitId:s,floatingObjectId:i,floatingObject:r}]}_clearByParam(n){const e=this._getFloatingObjects(n),{unitId:s,subUnitId:r}=n,i=[];return e==null||e.forEach((o,a)=>{i.push({unitId:s,subUnitId:r,floatingObjectId:a,floatingObject:o})}),e==null||e.clear(),i}_removeByParam(n){const e=this._getFloatingObjects(n),s=e==null?void 0:e.get(n.floatingObjectId);return s==null?[]:(e==null||e.delete(n.floatingObjectId),[{...n,floatingObject:s}])}}const gs=A.createIdentifier("univer.floating-object.service");class Rs{constructor(n={}){_(this,"_styles");_(this,"_cacheMap",new $n(1e5));this._styles=n,this._generateCacheMap()}each(n){return Object.entries(this._styles).forEach(n),this}search(n,e){if(this._cacheMap.has(e))return this._cacheMap.get(e);const s=this._getExistingStyleId(n);return s||"-1"}get(n){return typeof n!="string"?n:(n=String(n),this._styles[n])}add(n,e){const s=m.generateRandomId(6);return this._styles[s]=n,this._cacheMap.set(e,s),s}setValue(n){if(n==null)return;const e=JSON.stringify(n),s=this.search(n,e);return s!=="-1"?s:this.add(n,e)}toJSON(){return this._styles}getStyleByCell(n){let e;n&&m.isObject(n.s)?e=n.s:e=(n==null?void 0:n.s)&&this.get(n.s);const s=n==null?void 0:n.interceptorStyle;return s?{...e,...s}:e}_generateCacheMap(){const{_styles:n,_cacheMap:e}=this;for(const s in n){const r=JSON.stringify(n[s]);e.set(r,s)}}_getExistingStyleId(n){const{_styles:e}=this;for(const s in e)if(m.diffValue(e[s],n))return s;return null}}class yi{constructor(n,e){_(this,"_columnData",{});this._config=n,this._columnData=e}getColumnData(){return this._columnData}getColVisible(n){const{_columnData:e}=this,s=e[n];return s?s.hd!==O.TRUE:!0}getHiddenCols(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getColVisible(o);r&&a?(r=!1,s.push({rangeType:p.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!a&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:p.COLUMN}),s}getVisibleCols(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getColVisible(o);r&&!a?(r=!1,s.push({rangeType:p.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&a&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:e,rangeType:p.COLUMN}),s}getColumnDatas(n,e){const s={};let r=0;for(let i=n;i<n+e;i++){const o=this.getColumnOrCreate(i);s[r]=o,r++}return s}getSize(){return Y(this._columnData)}getColumnWidth(n){const{_columnData:e}=this,s=this._config;let r=0;return r=(e[n]||{hd:O.FALSE,w:s.defaultColumnWidth}).w||s.defaultColumnWidth,r}getColumn(n){const e=this._columnData[n];if(e)return e}getColumnOrCreate(n){const{_columnData:e}=this,s=this._config,r=e[n];if(r)return r;const i={w:s.defaultColumnWidth,hd:O.FALSE};return this._columnData[n]=i,i}}class Xi{constructor(n,e,s){_(this,"_rowData");this._config=n,this._viewModel=e,this._rowData=s}getRowData(){return this._rowData}getRowDatas(n,e){const s={};let r=0;for(let i=n;i<n+e;i++){const o=this.getRowOrCreate(i);s[r]=o,r++}return s}getRowHeight(n,e=1){const{_rowData:s}=this,r=this._config;let i=0;for(let o=0;o<e;o++){const a=s[o+n]||{hd:O.FALSE,h:r.defaultRowHeight},{ia:l,ah:c,h=r.defaultRowHeight}=a;i+=(l==null||l===O.TRUE)&&typeof c=="number"?c:h}return i}getRow(n){return this._rowData[n]}getRowOrCreate(n){const{_rowData:e}=this,s=e[n];if(s)return s;const r=this._config,i={hd:O.FALSE,h:r.defaultRowHeight};return e[n]=i,i}getHiddenRows(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getRowRawVisible(o);r&&a?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:p.ROW})):!r&&!a&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:p.ROW}),s}getVisibleRows(n=0,e=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=n;o<=e;o++){const a=this.getRowRawVisible(o);r&&!a?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:p.ROW})):!r&&a&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:e,startColumn:0,endColumn:0,rangeType:p.ROW}),s}getRowRawVisible(n){const e=this.getRow(n);return e?e.hd!==O.TRUE:!0}getSize(){return Y(this._rowData)}}const qi="DEFAULT_WORKSHEET_ROW_COUNT",ms=1e3,Ji="DEFAULT_WORKSHEET_COLUMN_COUNT",Cs=20,Zi="DEFAULT_WORKSHEET_ROW_HEIGHT",Os=19,Qi="DEFAULT_WORKSHEET_COLUMN_WIDTH",Is=73,to="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",As=46,eo="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",Ns=20;function Ss(t){const n={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:O.FALSE,rowCount:ms,columnCount:Cs,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Is,defaultRowHeight:Os,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:O.TRUE,rowHeader:{width:As,hidden:O.FALSE},columnHeader:{height:Ns,hidden:O.FALSE},selections:["A1"],rightToLeft:O.FALSE};return Object.keys(n).forEach(e=>{const s=e;typeof t[s]>"u"&&(t[s]=n[s])}),t}class Ls extends D{constructor(e){super();_(this,"_cellContentInterceptor",null);_(this,"_rowFilteredInterceptor",null);this.getRawCell=e}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(e,s){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(e,s):this.getRawCell(e,s)}getRowFiltered(e){var s,r;return(r=(s=this._rowFilteredInterceptor)==null?void 0:s.getRowFiltered(e))!=null?r:!1}registerCellContentInterceptor(e){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=e,U(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(e){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=e,U(()=>this._rowFilteredInterceptor=null)}}class gt{constructor(n,e,s){_(this,"_sheetId");_(this,"_snapshot");_(this,"_cellData");_(this,"_rowManager");_(this,"_columnManager");_(this,"_viewModel");var a;this.unitId=n,this._styles=s,this._snapshot=Ss(e);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(a=this._snapshot.id)!=null?a:m.generateRandomId(6),this._cellData=new V(o),this._viewModel=new Ls((l,c)=>this.getCellRaw(l,c)),this._rowManager=new Xi(this._snapshot,this._viewModel,i),this._columnManager=new yi(this._snapshot,r)}__interceptViewModel(n){n(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const n=this.getCellMatrix(),e=this.getMergeData();let s=-1,r=-1,i=-1,o=-1,a=!1,l=!1;return n.forEach((c,h)=>{Object.keys(h).forEach(d=>{const f=+d,E=n.getValue(c,f),g=E!=null&&E.s?this._styles.get(E.s):null,R=(g==null?void 0:g.bd)&&(g.bd.b||g.bd.l||g.bd.r||g.bd.t||g.bd.bc_tr||g.bd.bl_tr||g.bd.ml_tr||g.bd.tl_bc||g.bd.tl_br||g.bd.tl_mr);(E&&(E.v||E.p)||g!=null&&g.bg||R)&&(a?s=Math.min(s,c):(s=c,a=!0),r=Math.max(r,c),l?i=Math.min(i,f):(l=!0,i=f),o=Math.max(o,f))})}),e.forEach(c=>{a?s=Math.min(s,c.startRow):(s=c.startRow,a=!0),r=Math.max(r,c.endRow),l?i=Math.min(i,c.startColumn):(i=c.startColumn,a=!0),o=Math.max(o,c.endColumn)}),!a||!l?null:{startColumn:i,startRow:s,endColumn:o,endRow:r}}getRowManager(){return this._rowManager}getUnitId(){return this.unitId}getSheetId(){return this._sheetId}getColumnManager(){return this._columnManager}getName(){return this._snapshot.name}clone(){const{_snapshot:n}=this,e=m.deepClone(n);return new gt(this.unitId,e,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(n,e){const s=this._snapshot.mergeData;for(let r=0;r<s.length;r++){const i=s[r];if(z.intersects({startRow:n,startColumn:e,endRow:n,endColumn:e},i))return i}return null}getCell(n,e){return n<0||e<0?null:this._viewModel.getCell(n,e)}getCellRaw(n,e){return this.getCellMatrix().getValue(n,e)}getRowFiltered(n){return this._viewModel.getRowFiltered(n)}getMatrixWithMergedCells(n,e,s,r,i=!1){const o=this.getCellMatrix(),a=this._snapshot.mergeData.filter(c=>z.intersects({startRow:n,startColumn:e,endRow:s,endColumn:r},c)),l=new V;return ue(n,s,e,r).forEach((c,h)=>{const d=i?this.getCellRaw(c,h):this.getCell(c,h);d&&l.setValue(c,h,d)}),a.forEach(c=>{const{startColumn:h,startRow:d,endColumn:f,endRow:E}=c;ue(d,E,h,f).forEach((g,R)=>{g===d&&R===h&&l.setValue(g,R,{...o.getValue(g,R),rowSpan:E-d+1,colSpan:f-h+1}),(g!==d||R!==h)&&l.realDeleteValue(g,R)})}),l}getRange(n,e,s,r){return typeof n=="object"?new st(this,n,{getStyles:()=>this._styles}):new st(this,{startRow:n,startColumn:e,endColumn:r||e,endRow:s||n},{getStyles:()=>this._styles})}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:n}=this,{columnCount:e}=n;return e}getMaxRows(){const{_snapshot:n}=this,{rowCount:e}=n;return e}getRowCount(){return this._snapshot.rowCount}setRowCount(n){this._snapshot.rowCount=n}getColumnCount(){return this._snapshot.columnCount}setColumnCount(n){this._snapshot.columnCount=n}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:n}=this,{showGridlines:e}=n;return e===0}getTabColor(){const{_snapshot:n}=this,{tabColor:e}=n;return e}getColumnWidth(n){return this.getColumnManager().getColumnWidth(n)}getRowHeight(n){return this._viewModel.getRowFiltered(n)?0:this.getRowManager().getRowHeight(n)}getRowVisible(n){return this._viewModel.getRowFiltered(n)?!1:this.getRowRawVisible(n)}getRowRawVisible(n){return this.getRowManager().getRowRawVisible(n)}getHiddenRows(n,e){const s=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(n,e);return r.forEach(i=>i.endColumn=s),r}getColVisible(n){return this._columnManager.getColVisible(n)}getHiddenCols(n,e){const s=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(n,e);return r.forEach(i=>i.endRow=s),r}getVisibleRows(){const n=this.getRowCount();return this._rowManager.getVisibleRows(0,n-1)}getVisibleCols(){const n=this.getColumnCount();return this._columnManager.getVisibleCols(0,n-1)}isRightToLeft(){const{_snapshot:n}=this,{rightToLeft:e}=n;return e}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(n){return n&&(n.v!==void 0||n.f!==void 0||n.p!==void 0)}iterateByRow(n,e=!0){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=n,a=this;return{[Symbol.iterator]:()=>{let l=s,c=r;return{next(){for(;;){if(c>o&&(l+=1,c=r),l>i)return{done:!0,value:void 0};const h=a.getCell(l,c),d=!h,f=a.getMergedCell(l,c);if(f){if(l!==f.startRow||c!==f.startColumn){c=f.endColumn+1;continue}if(d&&e){c=f.endColumn+1;continue}const g={row:l,col:c,value:h};return g.colSpan=f.endColumn-f.startColumn+1,g.rowSpan=f.endRow-f.startRow+1,c=f.endColumn+1,{done:!1,value:g}}if(d&&e)c+=1;else{const E={row:l,col:c,value:h};return c+=1,{done:!1,value:E}}}}}}}}iterateByColumn(n,e=!0,s=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:a}=n,l=this;return{[Symbol.iterator]:()=>{let c=r,h=i;return{next(){for(;;){if(c>o&&(h+=1,c=r),h>a)return{done:!0,value:void 0};const d=l.getMergedCell(c,h);if(d){const g=c!==d.startRow,R=g||h!==d.startColumn;if(s&&R||!s&&g){c=d.endRow+1;continue}const C=l.getCell(d.startRow,d.startColumn);if(!C&&e){c=d.endRow+1;continue}const P={row:c,col:d.startColumn,value:C};return P.colSpan=d.endColumn-d.startColumn+1,P.rowSpan=d.endRow-d.startRow+1,c=d.endRow+1,{done:!1,value:P}}const f=l.getCell(c,h);if(!f&&e)c+=1;else{const g={row:c,col:h,value:f};return c+=1,{done:!1,value:g}}}}}}}}}function no(t){var s,r;if(!t)return"";const n=(r=(s=t.p)==null?void 0:s.body)==null?void 0:r.dataStream;if(n)return n;const e=t.v;return typeof e=="string"?t.t===et.BOOLEAN?e.toUpperCase():e:typeof e=="number"?t.t===et.BOOLEAN?e?"TRUE":"FALSE":e.toString():typeof e=="boolean"?e?"TRUE":"FALSE":""}const so="0.1.9";function ro(t="",n=Q.ZH_CN,e=""){return{id:t,sheetOrder:[],name:e,appVersion:so,locale:n,styles:{},sheets:{},resources:[]}}var io=Object.defineProperty,oo=Object.getOwnPropertyDescriptor,ao=(t,n,e,s)=>{for(var r=s>1?void 0:s?oo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&io(n,e,r),r},lo=(t,n)=>(e,s)=>n(e,s,t);function uo(t,n){return`${t.getUnitId()}|${n.getSheetId()}`}u.Workbook=class extends Bt{constructor(e={},s){super();_(this,"type",N.UNIVER_SHEET);_(this,"_sheetCreated$",new I.Subject);_(this,"sheetCreated$",this._sheetCreated$.asObservable());_(this,"_sheetDisposed$",new I.Subject);_(this,"sheetDisposed$",this._sheetDisposed$.asObservable());_(this,"_activeSheet$",new I.BehaviorSubject(null));_(this,"activeSheet$",this._activeSheet$.asObservable());_(this,"_worksheets");_(this,"_styles");_(this,"_snapshot");_(this,"_unitId");_(this,"_count");this._logService=s;const r=ro();m.isEmptyObject(e)?this._snapshot=r:this._snapshot=m.commonExtend(r,e);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=m.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new Rs(i),this._count=1,this._worksheets=new Map,this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._snapshot.name}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete()}save(){return m.deepClone(this._snapshot)}static isIRangeType(e){return typeof e=="string"||"startRow"in e||"row"in e}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}getUnitId(){return this._unitId}getRev(){var e;return(e=this._snapshot.rev)!=null?e:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(e,s,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[e])return!1;i[e]=r,o.splice(s,0,e);const a=new gt(this._unitId,r,this._styles);return this._worksheets.set(e,a),this._sheetCreated$.next(a),!0}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(e){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>r===e)}getRawActiveSheet(){return this._activeSheet}getActiveSheet(){const e=this.getRawActiveSheet();if(e)return e;const s=this._snapshot.sheetOrder;for(let i=0,o=s.length;i<o;i++){const a=this._worksheets.get(s[i]);if(a&&a.isSheetHidden()!==O.TRUE)return this.setActiveSheet(a),a}const r=this._worksheets.get(s[0]);return this.setActiveSheet(r),r}setActiveSheet(e){this._activeSheet$.next(e)}removeSheet(e){var r;return this._worksheets.get(e)?(((r=this._activeSheet)==null?void 0:r.getSheetId())===e&&this.setActiveSheet(null),this._worksheets.delete(e),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(e),1),delete this._snapshot.sheets[e],!0):!1}getActiveSheetIndex(){const{sheetOrder:e}=this._snapshot;return e.findIndex(s=>this._worksheets.get(s)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:e}=this._snapshot;return e.map(s=>this._worksheets.get(s))}getSheetsName(){const{sheetOrder:e}=this._snapshot,s=[];return e.forEach(r=>{const i=this._worksheets.get(r);i&&s.push(i.getName())}),s}getSheetIndex(e){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>e.getSheetId()===r)}getSheetBySheetName(e){const{sheetOrder:s}=this._snapshot,r=s.find(i=>this._worksheets.get(i).getName()===e);return this._worksheets.get(r)}getSheetBySheetId(e){return this._worksheets.get(e)}getSheetByIndex(e){const{sheetOrder:s}=this._snapshot;return this._worksheets.get(s[e])}getHiddenWorksheets(){return this.getSheets().filter(e=>e.getConfig().hidden===O.TRUE).map(e=>e.getConfig().id)}transformRangeType(e){if(typeof e=="string")return this._getCellRange(e);if(typeof e!="string"&&"row"in e){const s=e;return{sheetId:"",range:{startRow:s.row[0],startColumn:s.column[0],endRow:s.row[1],endColumn:s.column[1]}}}return typeof e!="string"&&"startRow"in e?{sheetId:"",range:e}:_t}load(e){this._snapshot=e}checkSheetName(e){return this.getSheetsName().includes(e)}uniqueSheetName(e="Sheet1"){let s=e;for(;this.checkSheetName(s);)s=e+this._count,this._count++;return s}generateNewSheetName(e){let s=e+this._count;for(;this.checkSheetName(s);)s=e+this._count,this._count++;return s}_getCellRange(e){var h,d,f,E,g;let s="",r="";if(e.indexOf("!")>-1){const R=e.split("!");s=R[0],r=R[1],s=s.replace(/\\'/g,"'").replace(/''/g,"'"),s.substring(0,1)==="'"&&s.substring(s.length-1,1)==="'"&&(s=s.substring(1,s.length-1))}else r=e;if(r.indexOf(":")===-1){const R=Number.parseInt(r.replace(/[^0-9]/g,""),10)-1,C=m.ABCatNum(r.replace(/[^A-Za-z]/g,""));return!Number.isNaN(R)&&!Number.isNaN(C)?{sheetId:s,range:{startRow:R,endRow:R,startColumn:C,endColumn:C}}:_t}r=r.split(":");const i=[0,0],o=[0,0],a=((h=this.getSheetBySheetName(s))==null?void 0:h.getMaxRows())||((d=this.getActiveSheet())==null?void 0:d.getMaxRows()),l=((f=this.getSheetBySheetName(s))==null?void 0:f.getMaxColumns())||((E=this.getActiveSheet())==null?void 0:E.getMaxColumns());return i[0]=Number.parseInt(r[0].replace(/[^0-9]/g,""),10)-1,i[1]=Number.parseInt(r[1].replace(/[^0-9]/g,""),10)-1,Number.isNaN(i[0])&&(i[0]=0),Number.isNaN(i[1])&&(i[1]=a),i[0]>i[1]||(o[0]=m.ABCatNum(r[0].replace(/[^A-Za-z]/g,"")),o[1]=m.ABCatNum(r[1].replace(/[^A-Za-z]/g,"")),Number.isNaN(o[0])&&(o[0]=0),Number.isNaN(o[1])&&(o[1]=l),o[0]>o[1])?_t:{sheetId:((g=this.getSheetBySheetName(s))==null?void 0:g.getSheetId())||"",range:{startRow:i[0],endRow:i[1],startColumn:o[0],endColumn:o[1]}}}_passWorksheetSnapshots(){const{_snapshot:e,_worksheets:s}=this,{sheets:r,sheetOrder:i}=e;if(m.isEmptyObject(r)){const o=m.generateRandomId();r[o]={id:o}}for(const o in r){const a=r[o],{name:l}=a;a.name=this.uniqueSheetName(l),a.name!==l&&this._logService.debug("[Workbook]",`The worksheet name ${l} is duplicated, we changed it to ${a.name}. Please fix the problem in your snapshot.`);const c=new gt(this._unitId,a,this._styles);s.set(o,c),i.includes(o)||i.push(o)}}},u.Workbook=ao([lo(1,y)],u.Workbook);class Ie extends Bt{constructor(e){var s;super();_(this,"type",N.UNIVER_SLIDE);_(this,"_snapshot");_(this,"_unitId");this._snapshot={...Kn,...e},this._unitId=(s=this._snapshot.id)!=null?s:m.generateRandomId(6)}getContainer(){return this._snapshot.container}getParentRenderUnitId(){return this._snapshot.parentRenderUnitId}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var e;return(e=this._snapshot.body)==null?void 0:e.pages}getPageOrder(){var e;return(e=this._snapshot.body)==null?void 0:e.pageOrder}getPage(e){const s=this.getPages();return s==null?void 0:s[e]}getElementsByPage(e){var s;return(s=this.getPage(e))==null?void 0:s.pageElements}getElement(e,s){var r;return(r=this.getElementsByPage(e))==null?void 0:r[s]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:Qt.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const Rt="FOCUSING_SHEET",$t="FOCUSING_DOC",Vt="FOCUSING_SLIDE",co="FOCUSING_EDITOR_BUT_HIDDEN",Ts="EDITOR_ACTIVATED",ho="FOCUSING_EDITOR_INPUT_FORMULA",ws="FOCUSING_FORMULA_EDITOR",_o="FOCUSING_UNIVER_EDITOR",fo="FOCUSING_EDITOR_INPUT_FORMULA",Eo="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE";var go=Object.defineProperty,Ro=Object.getOwnPropertyDescriptor,mo=(t,n,e,s)=>{for(var r=s>1?void 0:s?Ro(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&go(n,e,r),r},bs=(t,n)=>(e,s)=>n(e,s,t);const X=A.createIdentifier("univer.current");u.UniverInstanceService=class extends D{constructor(e,s){super();_(this,"_unitsByType",new Map);_(this,"_createHandler");_(this,"_ctorByType",new Map);_(this,"_currentUnits$",new I.BehaviorSubject({}));_(this,"currentUnits$",this._currentUnits$.asObservable());_(this,"_unitAdded$",new I.Subject);_(this,"unitAdded$",this._unitAdded$.asObservable());_(this,"_unitDisposed$",new I.Subject);_(this,"unitDisposed$",this._unitDisposed$.asObservable());_(this,"_focused$",new I.BehaviorSubject(null));_(this,"focused$",this._focused$.asObservable());this._injector=e,this._contextService=s}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(e){this._createHandler=e}createUnit(e,s){return this._createHandler(e,s,this._ctorByType.get(e))}registerCtorForType(e,s){return this._ctorByType.set(e,s),{dispose:()=>{this._ctorByType.delete(e)}}}getCurrentTypeOfUnit$(e){return this.currentUnits$.pipe(I.map(s=>{var r;return(r=s[e])!=null?r:null}),I.distinctUntilChanged())}getCurrentUnitForType(e){return this._currentUnits$.getValue()[e]}setCurrentUnitForType(e){const s=this._getUnitById(e);if(!s)throw new Error(`[UniverInstanceService]: no document with unitId ${e}!`);this._currentUnits$.next({...this._currentUnits$.getValue(),[s[1]]:s[0]})}getTypeOfUnitAdded$(e){return this._unitAdded$.pipe(I.filter(s=>s.type===e))}__addUnit(e){const s=e.type;this._unitsByType.has(s)||this._unitsByType.set(s,[]),this._unitsByType.get(s).push(e),this._unitAdded$.next(e),this._currentUnits$.next({...this._currentUnits$.getValue(),[s]:e})}getTypeOfUnitDisposed$(e){return this.unitDisposed$.pipe(I.filter(s=>s.type===e))}getUnit(e,s){var i;const r=(i=this._getUnitById(e))==null?void 0:i[0];return s&&(r==null?void 0:r.type)!==s?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(N.UNIVER_DOC)}getUniverDocInstance(e){return this.getUnit(e,N.UNIVER_DOC)}getUniverSheetInstance(e){return this.getUnit(e,N.UNIVER_SHEET)}getAllUnitsForType(e){var s;return(s=this._unitsByType.get(e))!=null?s:[]}changeDoc(e,s){const r=this.getAllUnitsForType(N.UNIVER_DOC),i=r.find(o=>o.getUnitId()===e);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(s)}get focused(){var s;const e=this._focused$.getValue();return e?(s=this._getUnitById(e))==null?void 0:s[0]:null}focusUnit(e){this._focused$.next(e),this.focused instanceof u.Workbook?(this._contextService.setContextValue($t,!1),this._contextService.setContextValue(Rt,!0),this._contextService.setContextValue(Vt,!1)):this.focused instanceof rt?(this._contextService.setContextValue($t,!0),this._contextService.setContextValue(Rt,!1),this._contextService.setContextValue(Vt,!1)):this.focused instanceof Ie&&(this._contextService.setContextValue($t,!1),this._contextService.setContextValue(Rt,!1),this._contextService.setContextValue(Vt,!0))}getFocusedUnit(){return this.focused}getUnitType(e){const s=this._getUnitById(e);if(!s)throw new Error(`[UniverInstanceService]: No document with unitId ${e}`);return s[1]}disposeUnit(e){const s=this._getUnitById(e);if(!s)return!1;const[r,i]=s,o=this._unitsByType.get(i),a=o.indexOf(r);return o.splice(a,1),this._unitDisposed$.next(r),this._currentUnits$.next({...this._currentUnits$.getValue(),[i]:null}),this._focused$.next(null),!0}_getUnitById(e){for(const[s,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===e);if(i)return[i,s]}}},u.UniverInstanceService=mo([bs(0,A.Inject(A.Injector)),bs(1,ft)],u.UniverInstanceService);var b=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(b||{});const Co={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},xt=new Map;function Ae(t,n){return function(r){Ne(t,n)}}function Ne(t,n){xt.has(t)||xt.set(t,[]),xt.get(t).push(n)}var Oo=Object.defineProperty,Io=Object.getOwnPropertyDescriptor,vs=(t,n,e,s)=>{for(var r=s>1?void 0:s?Io(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Oo(n,e,r),r},Se=(t,n)=>(e,s)=>n(e,s,t);u.LifecycleService=class extends D{constructor(e){super();_(this,"_lifecycle$",new I.BehaviorSubject(b.Starting));_(this,"lifecycle$",this._lifecycle$.asObservable());_(this,"_lock",!1);this._logService=e,this._reportProgress(b.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(e){if(e<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(e!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(e),this._lifecycle$.next(e),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new I.Observable(e=>(this.stage===b.Starting||(this.stage===b.Ready?e.next(b.Starting):this.stage===b.Rendered?(e.next(b.Starting),e.next(b.Ready)):(e.next(b.Starting),e.next(b.Ready),e.next(b.Rendered))),this._lifecycle$.subscribe(e)))}_reportProgress(e){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${Co[e]}".`)}},u.LifecycleService=vs([Se(0,y)],u.LifecycleService),u.LifecycleInitializerService=class extends D{constructor(e,s){super();_(this,"_seenTokens",new Set);this._lifecycleService=e,this._injector=s}initModulesOnStage(e){var s;(s=xt.get(e))==null||s.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}},u.LifecycleInitializerService=vs([Se(0,A.Inject(u.LifecycleService)),Se(1,A.Inject(A.Injector))],u.LifecycleInitializerService);class mt extends D{constructor(){super();_(this,"_currentLocale",Q.ZH_CN);_(this,"_locales",null);_(this,"localeChanged$",new I.Subject);_(this,"t",(e,...s)=>{if(!this._locales)throw new Error("Locale not initialized");const r=e.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return s.forEach((a,l)=>{o=o.replace(`{${l}}`,a)}),o}else return e});this.disposeWithMe(U(()=>this.localeChanged$.complete()))}load(e){var s;this._locales=m.deepMerge((s=this._locales)!=null?s:{},e)}setLocale(e){this._currentLocale=e,this.localeChanged$.next()}getLocales(){var e;return(e=this._locales)==null?void 0:e[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(e,s){const r=s.shift();if(r&&e&&r in e){const i=e[r];return s.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,s):i}return null}}const jt=A.createIdentifier("resource-manager-service");var Ao=Object.defineProperty,No=Object.getOwnPropertyDescriptor,So=(t,n,e,s)=>{for(var r=s>1?void 0:s?No(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Ao(n,e,r),r},Us=(t,n)=>(e,s)=>n(e,s,t);const Le=A.createIdentifier("univer.permission-service");u.PermissionService=class extends D{constructor(e,s){super();_(this,"_permissionPointMap",new Map);_(this,"deletePermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e);if(r){const i=r.get(s);i&&(i.complete(),this._permissionPointMap.delete(s))}});_(this,"addPermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e)||new Map;return r.has(s.id)?!1:(r.set(s.id,new I.BehaviorSubject(s)),this._permissionPointMap.set(e,r),!0)});_(this,"updatePermissionPoint",(e,s,r)=>{const i=this._permissionPointMap.get(e);if(!i)return;const o=i.get(s);if(o){const a=o.getValue();a.value=r,a.status=le.DONE,o.next(a)}});_(this,"getPermissionPoint",(e,s)=>{const r=this._permissionPointMap.get(e);if(!r)return;const i=r.get(s);if(i)return i.getValue()});this._resourceManagerService=e,this._univerInstanceService=s}_toJson(e){const s=this._permissionPointMap.get(e);let r=[];return s&&(r=[...s.keys()].reduce((i,o)=>{const a=s.get(o);return a&&i.push(a.getValue()),i},[])),JSON.stringify(r)}_parseJson(e){return JSON.parse(e)}composePermission$(e,s){const r=this._permissionPointMap.get(e),i=s.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.asObservable()});return I.combineLatest(i).pipe(nr.map(o=>(o.every(a=>this._permissionPointMap.get(a.id)),o)))}composePermission(e,s){const r=this._permissionPointMap.get(e);return s.map(o=>{const a=r==null?void 0:r.get(o);if(!a)throw new Error(`${o} permissionPoint is not exist`);return a.getValue()})}},u.PermissionService=So([Ae(b.Starting,u.PermissionService),Us(0,A.Inject(jt)),Us(1,A.Inject(X))],u.PermissionService);const Ds="univer.editable";class Kt extends Vn{constructor(e){super();_(this,"id",Ds);_(this,"value",!0);_(this,"unitID");this.unitID=e}}var Lo=Object.defineProperty,To=Object.getOwnPropertyDescriptor,wo=(t,n,e,s)=>{for(var r=s>1?void 0:s?To(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Lo(n,e,r),r},Ms=(t,n)=>(e,s)=>n(e,s,t);u.UniverPermissionService=class extends D{constructor(n,e){super(),this._permissionService=n,this._univerInstanceService=e,this._init()}_init(){this._univerInstanceService.getTypeOfUnitAdded$(N.UNIVER_SHEET).subscribe(n=>{const e=new Kt(n.getUnitId());this._permissionService.addPermissionPoint(n.getUnitId(),e)})}getEditable(n=(e=>(e=this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET))==null?void 0:e.getUnitId())()){if(!n)return;const s=new Kt(n),r=this._permissionService.getPermissionPoint(n,s.id);return r==null?void 0:r.value}setEditable(n,e){const s=new Kt(n);this._permissionService.updatePermissionPoint(n,s.id,e)}},u.UniverPermissionService=wo([Ae(b.Starting,u.UniverPermissionService),Ms(0,A.Inject(Le)),Ms(1,A.Inject(X))],u.UniverPermissionService);class Ps extends D{constructor(){super(...arguments);_(this,"_resourceMap",new Map);_(this,"_register$",new I.Subject);_(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(e){return this.getAllResourceHooks().map(i=>{const o=i.toJson(e);return{name:i.pluginName,data:o}})}registerPluginResource(e){const s=e.pluginName;if(this._resourceMap.has(s))throw new Error(`the pluginName is registered {${s}}`);return this._resourceMap.set(s,e),this._register$.next(e),U(()=>this._resourceMap.delete(s))}disposePluginResource(e){this._resourceMap.delete(e)}loadResources(e,s){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=s==null?void 0:s.find(a=>a.name===r.pluginName))==null?void 0:o.data;if(i)try{const a=r.parseJson(i);r.onLoad(e,a)}catch{console.error("LoadResources Error!")}})}unloadResources(e){this.getAllResourceHooks().forEach(s=>{s.onUnLoad(e)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}var bo=Object.defineProperty,vo=Object.getOwnPropertyDescriptor,Uo=(t,n,e,s)=>{for(var r=s>1?void 0:s?vo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&bo(n,e,r),r},Hs=(t,n)=>(e,s)=>n(e,s,t);let Te=class extends D{constructor(n,e){super();_(this,"saveWorkbook",n=>{const e=n.getUnitId(),s=this._resourceManagerService.getResources(e)||[],r=n.getSnapshot();return r.resources=s,r});this._resourceManagerService=n,this._univerInstanceService=e,this._init()}_init(){const n=s=>{s.businesses.forEach(r=>{switch(r){case N.UNRECOGNIZED:case N.UNIVER_UNKNOWN:case N.UNIVER_SLIDE:case N.UNIVER_DOC:break;case N.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(N.UNIVER_SHEET).forEach(i=>{const a=(i.getSnapshot().resources||[]).find(l=>l.name===s.pluginName);if(a)try{const l=s.parseJson(a.data);s.onLoad(i.getUnitId(),l)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(s=>{n(s)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(s=>{n(s)})),this.disposeWithMe(U(this._univerInstanceService.getTypeOfUnitAdded$(N.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.loadResources(s.getUnitId(),s.getSnapshot().resources)}))),this.disposeWithMe(U(this._univerInstanceService.getTypeOfUnitDisposed$(N.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.unloadResources(s.getUnitId())})))}};Te=Uo([Hs(0,A.Inject(jt)),Hs(1,A.Inject(X))],Te);const we=A.createIdentifier("resource-loader-service");Ne(b.Ready,we);class be extends D{constructor(){super();_(this,"_currentTheme");_(this,"_currentTheme$",new I.BehaviorSubject({}));_(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(U(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(e){this._currentTheme=e,this._currentTheme$.next(e)}}const Fs="__defaultDocumentNormalEditorSpecialUnitId_20231006__",ps="__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__",Do=`\r
7
7
  `;function Mo(t){return`__internalEditorId__${t}`}function Po(t){return t.startsWith("__")}var Ho=Object.defineProperty,Fo=Object.getOwnPropertyDescriptor,po=(t,n,e,s)=>{for(var r=s>1?void 0:s?Fo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Ho(n,e,r),r},ve=(t,n)=>(e,s)=>n(e,s,t);const Yt=A.createIdentifier("univer.undo-redo.service"),Wo=20;class Ws{dispose(){}async dispatchToHandlers(){return!1}}const Bs="univer.command.redo",ks="univer.command.undo",Gs=new class extends Ws{constructor(){super(...arguments);_(this,"type",Gt.COMMAND);_(this,"id",ks)}async handler(n){const e=n.get(Yt),s=e.pitchTopUndoElement();if(!s)return!1;const r=n.get(Et);return Oe(s.undoMutations,r)?(e.popUndoToRedo(),!0):!1}},$s=new class extends Ws{constructor(){super(...arguments);_(this,"type",Gt.COMMAND);_(this,"id",Bs)}async handler(n){const e=n.get(Yt),s=e.pitchTopRedoElement();if(!s)return!1;const r=n.get(Et);return Oe(s.redoMutations,r)?(e.popRedoToUndo(),!0):!1}};u.LocalUndoRedoService=class extends D{constructor(e,s,r){super();_(this,"undoRedoStatus$");_(this,"_undoRedoStatus$",new I.BehaviorSubject({undos:0,redos:0}));_(this,"_undoStacks",new Map);_(this,"_redoStacks",new Map);_(this,"_batchingStatus",new Map);this._univerInstanceService=e,this._commandService=s,this._contextService=r,this.undoRedoStatus$=this._undoRedoStatus$.asObservable(),this.disposeWithMe(this._commandService.registerCommand(Gs)),this.disposeWithMe(this._commandService.registerCommand($s)),this.disposeWithMe(U(()=>this._undoRedoStatus$.complete())),this.disposeWithMe(U(this._univerInstanceService.focused$.subscribe(()=>this._updateStatus())))}pushUndoRedo(e){const{unitID:s}=e,r=this._getRedoStack(s,!0),i=this._getUndoStack(s,!0);if(r.length=0,this._batchingStatus.has(e.unitID)){const a=this._batchingStatus.get(e.unitID),l=this._pitchUndoElement(e.unitID);a===0||!l?(o(e),this._batchingStatus.set(e.unitID,1)):this._tryBatchingElements(l,e)}else o(e);function o(a){i.push(a),i.length>Wo&&i.splice(0,1)}this._updateStatus()}clearUndoRedo(e){const s=this._getRedoStack(e);s&&(s.length=0);const r=this._getUndoStack(e);r&&(r.length=0),this._updateStatus()}pitchTopUndoElement(){const e=this._getFocusedUnitId();return this._pitchUndoElement(e)}pitchTopRedoElement(){const e=this._getFocusedUnitId();return this._pitchRedoElement(e)}_pitchUndoElement(e){const s=this._getUndoStack(e);return s!=null&&s.length?s[s.length-1]:null}_pitchRedoElement(e){const s=this._getRedoStack(e);return s!=null&&s.length?s[s.length-1]:null}popUndoToRedo(){const s=this._getUndoStackForFocused().pop();s&&(this._getRedoStackForFocused().push(s),this._updateStatus())}popRedoToUndo(){const s=this._getRedoStackForFocused().pop();s&&(this._getUndoStackForFocused().push(s),this._updateStatus())}__tempBatchingUndoRedo(e){if(this._batchingStatus.has(e))throw new Error("[LocalUndoRedoService]: cannot batching undo redo twice at the same time!");return this._batchingStatus.set(e,0),U(()=>this._batchingStatus.delete(e))}_updateStatus(){var i,o;const e=this._getFocusedUnitId(),s=e&&((i=this._undoStacks.get(e))==null?void 0:i.length)||0,r=e&&((o=this._redoStacks.get(e))==null?void 0:o.length)||0;this._undoRedoStatus$.next({undos:s,redos:r})}_getUndoStack(e,s=!1){let r=this._undoStacks.get(e);return!r&&s&&(r=[],this._undoStacks.set(e,r)),r||null}_getRedoStack(e,s=!1){let r=this._redoStacks.get(e);return!r&&s&&(r=[],this._redoStacks.set(e,r)),r||null}_getUndoStackForFocused(){const e=this._getFocusedUnitId();if(!e)throw new Error("No focused univer instance!");return this._getUndoStack(e,!0)}_getRedoStackForFocused(){const e=this._getFocusedUnitId();if(!e)throw new Error("No focused univer instance!");return this._getRedoStack(e,!0)}_tryBatchingElements(e,s){e.redoMutations.push(...s.redoMutations),e.undoMutations.push(...s.undoMutations)}_getFocusedUnitId(){var o,a,l,c;let e="";const s=this._contextService.getContextValue(Rt),r=this._contextService.getContextValue(ws),i=this._contextService.getContextValue(Ts);return s?r?e=ps:i?e=Fs:e=(a=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId())!=null?a:"":e=(c=(l=this._univerInstanceService.getFocusedUnit())==null?void 0:l.getUnitId())!=null?c:"",e}},u.LocalUndoRedoService=po([ve(0,X),ve(1,Et),ve(2,ft)],u.LocalUndoRedoService);class Ue extends D{onStarting(n){}onReady(){}onRendered(){}onSteady(){}getUniverInstanceType(){return this.constructor.type}getPluginName(){return this.constructor.pluginName}}_(Ue,"pluginName"),_(Ue,"type",N.UNIVER_UNKNOWN);class Bo{constructor(){_(this,"_plugins",[])}addPlugin(n){this._plugins.push(n)}removePlugins(){const n=this._plugins.slice();return this._plugins.length=0,n}forEachPlugin(n){this._plugins.forEach(n)}}class ko{constructor(){_(this,"_pluginsRegistered",[])}registerPlugin(n,e){this._pluginsRegistered.push({plugin:n,options:e})}getRegisterPlugins(){return this._pluginsRegistered.slice()}removePlugins(){this._pluginsRegistered=[]}}var Go=Object.defineProperty,$o=Object.getOwnPropertyDescriptor,Vo=(t,n,e,s)=>{for(var r=s>1?void 0:s?$o(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&Go(n,e,r),r},zt=(t,n)=>(e,s)=>n(e,s,t);u.PluginHolder=class extends D{constructor(e,s,r,i){super();_(this,"_started",!1);_(this,"_pluginRegistered",new Set);_(this,"_pluginStore",new Bo);_(this,"_pluginRegistry",new ko);this._logService=e,this._injector=s,this._lifecycleService=r,this._lifecycleInitializerService=i}get started(){return this._started}dispose(){super.dispose(),this._pluginStore.forEachPlugin(e=>e.dispose()),this._pluginStore.removePlugins(),this._pluginRegistry.removePlugins(),this._pluginRegistered.clear()}registerPlugin(e,s){const{pluginName:r}=e;if(this._pluginRegistered.has(r)){this._logService.warn("[PluginService]",`plugin ${r} has already been registered. This registration will be ignored.`);return}this._pluginRegistered.add(r),this._pluginRegistry.registerPlugin(e,s)}start(){this._started||(this._started=!0,this.flush())}flush(){if(!this._started)return;const e=this._pluginRegistry.getRegisterPlugins().map(({plugin:r,options:i})=>this._initPlugin(r,i));this._pluginRegistry.removePlugins();const s=this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().subscribe(r=>{this._pluginsRunLifecycle(e,r),r===b.Steady&&s.dispose()}))}_pluginsRunLifecycle(e,s){e.forEach(r=>{switch(s){case b.Starting:r.onStarting(this._injector);break;case b.Ready:r.onReady();break;case b.Rendered:r.onRendered();break;case b.Steady:r.onSteady();break}}),this._lifecycleInitializerService.initModulesOnStage(s)}_initPlugin(e,s){return this._injector.createInstance(e,s)}},u.PluginHolder=Vo([zt(0,y),zt(1,A.Inject(A.Injector)),zt(2,A.Inject(u.LifecycleService)),zt(3,A.Inject(u.LifecycleInitializerService))],u.PluginHolder);var xo=Object.defineProperty,jo=Object.getOwnPropertyDescriptor,Ko=(t,n,e,s)=>{for(var r=s>1?void 0:s?jo(n,e):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(n,e,r):o(r))||r);return s&&r&&xo(n,e,r),r},Yo=(t,n)=>(e,s)=>n(e,s,t);const zo=4;u.PluginService=class{constructor(n){_(this,"_pluginHolderForUniver");_(this,"_pluginHoldersForTypes",new Map);_(this,"_flushTimer");this._injector=n,this._pluginHolderForUniver=this._injector.createInstance(u.PluginHolder),this._pluginHolderForUniver.start()}dispose(){this._clearFlushTimer();for(const n of this._pluginHoldersForTypes.values())n.dispose();this._pluginHolderForUniver.dispose()}registerPlugin(n,e){this._assertPluginValid(n),this._scheduleInitPlugin();const{type:s}=n;s===N.UNIVER_UNKNOWN?(this._pluginHolderForUniver.registerPlugin(n,e),this._pluginHolderForUniver.flush()):this._ensurePluginHolderForType(s).registerPlugin(n,e)}startPluginForType(n){this._ensurePluginHolderForType(n).start()}_ensurePluginHolderForType(n){if(!this._pluginHoldersForTypes.has(n)){const e=this._injector.createInstance(u.PluginHolder);return this._pluginHoldersForTypes.set(n,e),e}return this._pluginHoldersForTypes.get(n)}_assertPluginValid(n){const{type:e,pluginName:s}=n;if(e===N.UNRECOGNIZED)throw new Error(`[PluginService]: invalid plugin type for ${n}. Please assign a "type" to your plugin.`);if(s==="")throw new Error(`[PluginService]: no plugin name for ${n}. Please assign a "pluginName" to your plugin.`)}_scheduleInitPlugin(){this._flushTimer===void 0&&(this._flushTimer=setTimeout(()=>{this._pluginHolderForUniver.started||this._pluginHolderForUniver.start(),this._flushPlugins(),this._clearFlushTimer()},zo))}_clearFlushTimer(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=void 0)}_flushPlugins(){this._pluginHolderForUniver.flush();for(const[n,e]of this._pluginHoldersForTypes)e.started&&e.flush()}},u.PluginService=Ko([Yo(0,A.Inject(A.Injector))],u.PluginService);function Vs(t,n){if(!n)return t;const e=[];for(const s of t){if(s.length===1){e.push(s);continue}const r=n.find(([i])=>i===s[0]);if(r){if(r[1]===null)continue;e.push([s[0],r[1]])}else e.push(s)}return e}class yo{constructor(n={},e){_(this,"_startedTypes",new Set);_(this,"_injector");const s=this._injector=Xo(e,n==null?void 0:n.override),{theme:r,locale:i,locales:o,logLevel:a}=n;r&&this._injector.get(be).setTheme(r),o&&this._injector.get(mt).load(o),i&&this._injector.get(mt).setLocale(i),a&&this._injector.get(y).setLogLevel(a),this._init(s),this._pluginService}get _univerInstanceService(){return this._injector.get(X)}get _pluginService(){return this._injector.get(u.PluginService)}__getInjector(){return this._injector}dispose(){this._injector.dispose()}setLocale(n){this._injector.get(mt).setLocale(n)}createUnit(n,e){return this._univerInstanceService.createUnit(n,e)}createUniverSheet(n){return this._univerInstanceService.createUnit(N.UNIVER_SHEET,n)}createUniverDoc(n){return this._univerInstanceService.createUnit(N.UNIVER_DOC,n)}createUniverSlide(n){return this._univerInstanceService.createUnit(N.UNIVER_SLIDE,n)}_init(n){this._univerInstanceService.registerCtorForType(N.UNIVER_SHEET,u.Workbook),this._univerInstanceService.registerCtorForType(N.UNIVER_DOC,rt),this._univerInstanceService.registerCtorForType(N.UNIVER_SLIDE,Ie);const e=n.get(X);e.__setCreateHandler((s,r,i)=>{if(!this._startedTypes.has(s)){this._pluginService.startPluginForType(s),this._startedTypes.add(s);const a=n.createInstance(i,r);return e.__addUnit(a),this._tryProgressToReady(),a}const o=n.createInstance(i,r);return e.__addUnit(o),o})}_tryProgressToReady(){this._injector.get(u.LifecycleService).stage<b.Ready&&(this._injector.get(u.LifecycleService).stage=b.Ready)}registerPlugin(n,e){this._pluginService.registerPlugin(n,e)}}function Xo(t,n){const e=Vs([[fs],[mt],[be],[u.LifecycleService],[u.LifecycleInitializerService],[u.UniverPermissionService],[u.PluginService],[X,{useClass:u.UniverInstanceService}],[Le,{useClass:u.PermissionService}],[y,{useClass:us,lazy:!0}],[Et,{useClass:u.CommandService,lazy:!0}],[Yt,{useClass:u.LocalUndoRedoService,lazy:!0}],[ds,{useClass:_s}],[ft,{useClass:as}],[gs,{useClass:Es,lazy:!0}],[jt,{useClass:Ps,lazy:!0}],[we,{useClass:Te,lazy:!0}]],n);return t?t.createChild(e):new A.Injector(e)}const qo=(t,n)=>n.length===t.length&&!t.some(e=>n.some(s=>!z.equals(s,e))),Jo=(t,n)=>n.length===t.length&&t.every((e,s)=>{const r=n[s];return r.unitId===e.unitId&&r.sheetId===e.sheetId&&z.equals(e.range,r.range)});function Zo(t,n){if(Object.is(t,n))return!0;if(typeof t!="object"||!t||typeof n!="object"||!n)return!1;const e=Object.keys(t),s=Object.keys(n);if(e.length!==s.length)return!1;const r=Object.prototype.hasOwnProperty.bind(n);for(let i=0;i<e.length;i++){const o=e[i];if(!r(o))return!1;const a=t[o],l=n[o];if(a!==l)return!1}return!0}function xs(t){return/^-?\d+(\.\d+)?$/.test(t)}function Qo(t){return xs(t)?Number(t)<=Number.MAX_SAFE_INTEGER:!1}function ta(t){return["true","false"].includes(t.toLowerCase())}function ea(t,n){return n.forEach(e=>t.add(e)),t}function na(t,n=16){let e=0,s=null;return function(...i){const o=Date.now();o-e<n?(s&&clearTimeout(s),s=setTimeout(()=>{e=o,t.apply(this,i)},n)):(e=o,t.apply(this,i))}}function sa(t){const n=new MessageChannel;let e=!1;return n.port1.onmessage=()=>{e||t()},n.port2.postMessage(null),()=>{e=!0}}var js=(t=>(t[t.TEXT=0]="TEXT",t[t.ARROW=1]="ARROW",t[t.CUSTOM=2]="CUSTOM",t))(js||{});class De{constructor(n){_(this,"_index",0);_(this,"_offset",0);this._actions=n}hasNext(){return this.peekLength()<Number.POSITIVE_INFINITY}next(n){n||(n=Number.POSITIVE_INFINITY);const e=this._actions[this._index];if(e){const s=this._offset,r=e.len;return n>=r-s?(n=r-s,this._index+=1,this._offset=0):this._offset+=n,e.t===S.DELETE||e.t===S.RETAIN&&e.body==null?m.deepClone({...e,len:n}):m.deepClone({...e,len:n,body:Re(e.body,s,s+n)})}else return{t:S.RETAIN,len:Number.POSITIVE_INFINITY}}peek(){return this._actions[this._index]}peekLength(){return this._actions[this._index]?this._actions[this._index].len-this._offset:Number.POSITIVE_INFINITY}peekType(){const n=this._actions[this._index];return n?n.t:S.RETAIN}rest(){if(this.hasNext()){if(this._offset===0)return this._actions.slice(this._index);{const n=this._offset,e=this._index,s=this.next(),r=this._actions.slice(this._index);return this._offset=n,this._index=e,[s].concat(r)}}else return[]}}function Ks(t){return Object.keys(t).length===1}class yt{constructor(){_(this,"_actions",[])}static compose(n,e){const s=new De(n),r=new De(e),i=new yt;for(;s.hasNext()||r.hasNext();)if(r.peekType()===S.INSERT)i.push(r.next());else if(s.peekType()===S.DELETE)i.push(s.next());else{const o=Math.min(s.peekLength(),r.peekLength()),a=s.next(o),l=r.next(o);a.t===S.INSERT&&l.t===S.RETAIN?l.body==null?i.push(a):i.push({...a,body:me(a.body,l.body,l.coverType)}):a.t===S.RETAIN&&l.t===S.RETAIN?a.body==null&&l.body==null?i.push(a.len!==Number.POSITIVE_INFINITY?a:l):a.body&&l.body?i.push({...a,body:me(a.body,l.body,l.coverType)}):i.push(a.body?a:l):a.t===S.RETAIN&&l.t===S.DELETE?i.push(l):a.t===S.INSERT&&(l.t,S.DELETE)}return i.trimEndUselessRetainAction(),i.serialize()}insert(n,e,s=""){const r={t:S.INSERT,body:e,len:n,line:0,segmentId:s};return this.push(r),this}retain(n,e="",s,r){const i={t:S.RETAIN,len:n,segmentId:e};return s!=null&&(i.body=s),r!=null&&(i.coverType=r),this.push(i),this}delete(n,e=""){const s={t:S.DELETE,len:n,line:0,segmentId:e};return this.push(s),this}serialize(){return this._actions}push(...n){if(n.length>1){for(const i of n)this.push(i);return this}let e=this._actions.length,s=this._actions[e-1];const r=m.deepClone(n[0]);if(r.t===S.RETAIN&&r.len===0&&r.body==null)return this;if(typeof s=="object"){if(s.t===S.DELETE&&r.t===S.DELETE)return s.len+=r.len,this;if(s.t===S.DELETE&&r.t===S.INSERT&&(e-=1,s=this._actions[e-1],s==null))return this._actions.unshift(r),this;if(s.t===S.RETAIN&&r.t===S.RETAIN&&s.body==null&&r.body==null)return s.len+=r.len,this;if(s.t===S.INSERT&&Ks(s.body)&&r.t===S.INSERT&&Ks(r.body))return s.len+=r.len,s.body.dataStream+=r.body.dataStream,this}return e===this._actions.length?this._actions.push(r):this._actions.splice(e,0,r),this}trimEndUselessRetainAction(){let n=this._actions[this._actions.length-1];for(;n&&n.t===S.RETAIN&&Bi(n);)this._actions.pop(),n=this._actions[this._actions.length-1];return this}}function ra(t,n,e){if(n==="")return t;const s={id:"mock-id",body:t,documentStyle:{}},r=new rt(s),i=n.length;let o;for(;(o=r.getBody().dataStream.indexOf(n))>=0;){const l=new yt;if(o>0&&l.retain(o),e.length>0){const h=r.sliceBody(o,o+i),d={dataStream:e};Array.isArray(h==null?void 0:h.textRuns)&&h.textRuns.length&&(d.textRuns=[{...h.textRuns[0],st:0,ed:e.length}]),l.insert(e.length,d)}l.delete(i);const c=l.serialize();r.apply(c)}const a=r.getBody();return r.dispose(),a}class ia extends Mt{add(n){if(!n)return null;const e=new Dt(n,this);return this._observers=[e],this._onObserverAdded&&this._onObserverAdded(e),e}makeObserverTopPriority(){}makeObserverBottomPriority(){}}const oa=A.createIdentifier("ILocalStorageService");function aa(t){return new I.Observable(n=>{const e=t((...s)=>n.next(s));return()=>e==null?void 0:e.dispose()})}function la(t){return`sheet_interceptor_${t}`}const Ys=t=>function(n,e){let s=-1;function r(i,o){if(i<=s)throw new Error("[SheetInterceptorService]: next() called multiple times!");return s=i,i===t.length?o:t[i].handler(o,e,r.bind(null,i+1))}return r(0,n)};class ua{constructor(n){_(this,"_interceptorsByName",new Map);_(this,"_interceptorPoints");this._interceptorPoints=n}fetchThroughInterceptors(n){const e=n,s=this._interceptorsByName.get(e);return Ys(s||[])}intercept(n,e){const s=n;this._interceptorsByName.has(s)||this._interceptorsByName.set(s,[]);const r=this._interceptorsByName.get(s);return r.push(e),this._interceptorsByName.set(s,r.sort((i,o)=>{var a,l;return((a=o.priority)!=null?a:0)-((l=i.priority)!=null?l:0)})),()=>Pt(this._interceptorsByName.get(s),e)}getInterceptPoints(){return this._interceptorPoints}}const ca=A.createIdentifier("univer.snapshot-server-service");class ha{constructor(){_(this,"_sheetBlockCache",new Map)}getUnitOnRev(n,e){return Promise.resolve({snapshot:{unitID:"",type:N.UNIVER_SHEET,rev:0,workbook:void 0,doc:void 0},changesets:[],error:{code:k.OK,message:""}})}getSheetBlock(n,e){const s=this._sheetBlockCache.get(e.blockID);return Promise.resolve({block:s,error:{code:k.OK,message:""}})}fetchMissingChangesets(n,e){return Promise.resolve({changesets:[],error:{code:k.OK,message:""}})}getResourcesRequest(n,e){return Promise.resolve({resources:{},error:{code:k.OK,message:""}})}saveSnapshot(n,e){return Promise.resolve({error:{code:k.OK,message:""}})}saveSheetBlock(n,e){const{block:s}=e;return s?(this._sheetBlockCache.set(s.id,s),Promise.resolve({error:{code:k.OK,message:""},blockID:s.id})):Promise.resolve({error:{code:k.UNDEFINED,message:"block is required"},blockID:""})}saveChangeset(n,e){return Promise.resolve({error:{code:k.OK,message:""},concurrent:[]})}}function da(t){return btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(n,e)=>String.fromCharCode(Number.parseInt(e,16))))}function Me(t){return decodeURIComponent(Array.prototype.map.call(atob(t),n=>`%${`00${n.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}const Ct=new TextEncoder,Xt=new TextDecoder;function zs(t){const n=m.deepClone(t);return delete n.id,delete n.name,delete n.rowCount,delete n.columnCount,delete n.cellData,Ct.encode(JSON.stringify(n))}function ys(t){const n=m.deepClone(t);return delete n.id,delete n.rev,delete n.name,delete n.sheetOrder,delete n.sheets,Ct.encode(JSON.stringify(n))}function _a(t){const n=m.deepClone(t);return delete n.id,delete n.rev,delete n.title,delete n.resources,Ct.encode(JSON.stringify(n))}function Xs(t){return JSON.parse(Xt.decode(t))}function fa(t){return JSON.parse(typeof t=="string"?Me(t):Xt.decode(t))}function Ea(t){return JSON.parse(typeof t=="string"?Me(t):Xt.decode(t))}const Pe=256;function qs(t,n){const e=new V(t),s=e.getLength(),r=[];let i=0;for(;i<s;){const o=Math.min(i+Pe,s-1),a=e.getSlice(i,Math.min(i+Pe,s-1),0,n),l=ga(a);r.push({id:m.generateRandomId(19,"0123456789"),startRow:i,endRow:o,data:l}),i+=Pe}return r}function ga(t){const n=t.getData();return Ct.encode(JSON.stringify(n))}async function Ra(t,n,e,s,r){const i={},o={};if(!await Promise.all(Object.entries(n.sheets).map(async([d,f])=>{const E={id:f.id,type:It.GRID,name:f.name,rowCount:f.rowCount,columnCount:f.columnCount,originalMeta:zs(f)};if(o[d]=E,f.cellData){const g=qs(f.cellData,f.rowCount),R=await Promise.all(g.map(C=>r.saveSheetBlock(t,{unitID:e,type:N.UNIVER_SHEET,block:C})));if(R.some(C=>{var L;return((L=C.error)==null?void 0:L.code)!==k.OK}))return!1;i[d]={sheetID:d,blocks:R.map(C=>C.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const l=ys(n),c={unitID:n.id,rev:s,creator:"",name:n.name,sheetOrder:n.sheetOrder,sheets:o,blockMeta:i,resources:n.resources||[],originalMeta:l};return{snapshotRes:{unitID:e,rev:c.rev,type:N.UNIVER_SHEET,workbook:c,doc:void 0}}}async function ma(t,n,e,s,r){var f,E;const i={},o={};if(!await Promise.all(Object.entries(n.sheets).map(async([g,R])=>{const C={id:R.id,type:It.GRID,name:R.name,rowCount:R.rowCount,columnCount:R.columnCount,originalMeta:zs(R)};if(o[g]=C,R.cellData){const L=qs(R.cellData,R.rowCount),P=await Promise.all(L.map(F=>r.saveSheetBlock(t,{unitID:e,type:N.UNIVER_SHEET,block:F})));if(P.some(F=>{var Z;return((Z=F.error)==null?void 0:Z.code)!==k.OK}))return!1;i[g]={sheetID:g,blocks:P.map(F=>F.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const l=ys(n),c={unitID:n.id,rev:s,creator:"",name:n.name,sheetOrder:n.sheetOrder,sheets:o,blockMeta:i,resources:n.resources||[],originalMeta:l},h={unitID:e,rev:c.rev,type:N.UNIVER_SHEET,workbook:c,doc:void 0},d=await r.saveSnapshot(t,{unitID:e,type:N.UNIVER_SHEET,snapshot:h});if(zn(d.error))throw new Error(`transformWorkbookDataToSnapshot(): Failed to save snapshot.
8
8
  ErrorCode: ${(f=d.error)==null?void 0:f.code}:${(E=d.error)==null?void 0:E.message}`);return{snapshot:h}}function Ca(t,n,e){const s=t.workbook;if(!s)throw new Error("");const r={};Object.entries(s.sheets).forEach(([l,c])=>{const h=Xs(c.originalMeta);r[l]={id:c.id,name:c.name,rowCount:c.rowCount,columnCount:c.columnCount,...h}});const i=new Map;n.forEach(l=>{i.set(l.id,l)}),s.blockMeta&&Object.entries(s.blockMeta).forEach(([l,c])=>{var f;const h=r[l];h.cellData={};const d=[];(f=c.blocks)==null||f.forEach(E=>{const g=i.get(E);if(g)d.push(g);else throw new Error("")}),d.forEach(E=>{const g=fa(E.data);Object.entries(g).forEach(([R,C])=>{const L=h.cellData[+R]={};Object.entries(C).forEach(([P,F])=>{L[+P]=F})})})});const o=Xs(s.originalMeta);return{id:t.unitID,rev:s.rev,name:s.name,sheetOrder:s.sheetOrder,appVersion:"",locale:Q.EN_US,sheets:r,styles:{},resources:s.resources||[],...o}}function Oa(t){const n=t.doc;if(n==null)throw new Error("transformSnapshotToDocumentData(): snapshot.doc is undefined.");const{unitID:e,rev:s,name:r,originalMeta:i}=n,{body:o,documentStyle:a={},settings:l={}}=Ea(i);return{id:e,rev:s,locale:Q.EN_US,title:r,body:o,documentStyle:a,settings:l}}async function Ia(t,n,e,s,r){var l,c,h;const i={unitID:n.id,rev:s,creator:"",name:(l=n.title)!=null?l:"",resources:n.resources||[],originalMeta:_a(n)},o={unitID:e,rev:i.rev,type:N.UNIVER_DOC,workbook:void 0,doc:i},a=await r.saveSnapshot(t,{unitID:e,type:N.UNIVER_DOC,snapshot:o});if(zn(a.error))throw new Error(`transformDocumentDataToSnapshot(): Failed to save snapshot.
9
9
  ErrorCode: ${(c=a.error)==null?void 0:c.code}:${(h=a.error)==null?void 0:h.message}`);return{snapshot:o}}async function Aa(t,n){const e=t.workbook;if(!e)throw new Error("Workbook metadata is not available");const s=[],r=[];return Object.entries(e.blockMeta).forEach(([i,o])=>{const a=o.blocks.map(async l=>{const c={unitID:e.unitID,type:N.UNIVER_SHEET,blockID:l},{block:h}=await n.getSheetBlock({},c);if(h)s.push(h);else throw new Error("Block not found")});r.push(...a)}),await Promise.all(r),s}var Js=(t=>(t[t.INFO=0]="INFO",t[t.STOP=1]="STOP",t[t.WARNING=2]="WARNING",t))(Js||{}),Zs=(t=>(t[t.DISABLED=0]="DISABLED",t[t.FULL_ALPHA=1]="FULL_ALPHA",t[t.FULL_HANGUL=2]="FULL_HANGUL",t[t.FULL_KATAKANA=3]="FULL_KATAKANA",t[t.HALF_ALPHA=4]="HALF_ALPHA",t[t.HALF_HANGUL=5]="HALF_HANGUL",t[t.HALF_KATAKANA=6]="HALF_KATAKANA",t[t.HIRAGANA=7]="HIRAGANA",t[t.NO_CONTROL=8]="NO_CONTROL",t[t.OFF=9]="OFF",t[t.ON=10]="ON",t))(Zs||{}),Qs=(t=>(t.BETWEEN="between",t.EQUAL="equal",t.GREATER_THAN="greaterThan",t.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",t.LESS_THAN="lessThan",t.LESS_THAN_OR_EQUAL="lessThanOrEqual",t.NOT_BETWEEN="notBetween",t.NOT_EQUAL="notEqual",t))(Qs||{}),tr=(t=>(t.CUSTOM="custom",t.LIST="list",t.LIST_MULTIPLE="listMultiple",t.NONE="none",t.TEXT_LENGTH="textLength",t.DATE="date",t.TIME="time",t.WHOLE="whole",t.DECIMAL="decimal",t.CHECKBOX="checkbox",t))(tr||{}),er=(t=>(t.VALID="valid",t.INVALID="invalid",t.VALIDATING="validating",t))(er||{});sr(),u.ABCToNumber=ci,u.AbsoluteRefType=v,u.ActionIterator=De,u.AlignTypeH=On,u.AlignTypeV=In,u.AutoFillSeries=pe,u.BaselineOffset=ot,u.BlockType=en,u.BooleanNumber=O,u.BorderStyleTypes=w,u.BorderType=We,u.BulletAlignment=j,u.COLORS=qt,u.CellValueType=et,u.ClientSnapshotServerService=ha,u.Color=nt,u.ColorBuilder=Lt,u.ColorKit=$,u.ColorType=B,u.ColumnSeparatorType=rn,u.CommandType=Gt,u.CommonHideTypes=Be,u.ConfigService=_s,u.ContentAlignment=En,u.ContextService=as,u.CopyPasteType=ke,u.CustomRangeType=tn,u.DEFAULT_CELL=Oi,u.DEFAULT_DOC=Ce,u.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=zi,u.DEFAULT_EMPTY_DOCUMENT_VALUE=Do,u.DEFAULT_RANGE=mi,u.DEFAULT_RANGE_ARRAY=_t,u.DEFAULT_SELECTION=Ci,u.DEFAULT_SLIDE=Kn,u.DEFAULT_STYLES=pt,u.DEFAULT_WORKSHEET_COLUMN_COUNT=Cs,u.DEFAULT_WORKSHEET_COLUMN_COUNT_KEY=Ji,u.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT=Ns,u.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY=eo,u.DEFAULT_WORKSHEET_COLUMN_WIDTH=Is,u.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY=Qi,u.DEFAULT_WORKSHEET_ROW_COUNT=ms,u.DEFAULT_WORKSHEET_ROW_COUNT_KEY=qi,u.DEFAULT_WORKSHEET_ROW_HEIGHT=Os,u.DEFAULT_WORKSHEET_ROW_HEIGHT_KEY=Zi,u.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH=As,u.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY=to,u.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY=ps,u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY=Fs,u.DashStyleType=dn,u.DataStreamTreeNodeType=Xn,u.DataStreamTreeTokenType=_e,u.DataValidationErrorStyle=Js,u.DataValidationImeMode=Zs,u.DataValidationOperator=Qs,u.DataValidationRenderMode=js,u.DataValidationStatus=er,u.DataValidationType=tr,u.DesktopLogService=us,u.DeveloperMetadataVisibility=Ge,u.Dimension=$e,u.Direction=Ve,u.Disposable=D,u.DisposableCollection=se,u.DocStyleType=Ze,u.DocumentDataModel=rt,u.EDITOR_ACTIVATED=Ts,u.EXTENSION_NAMES=Yn,u.Entry=re,u.EntryIterator=Gn,u.ErrorService=fs,u.EventState=pn,u.FOCUSING_DOC=$t,u.FOCUSING_EDITOR_BUT_HIDDEN=co,u.FOCUSING_EDITOR_INPUT_FORMULA=ho,u.FOCUSING_EDITOR_STANDALONE=fo,u.FOCUSING_FORMULA_EDITOR=ws,u.FOCUSING_SHEET=Rt,u.FOCUSING_SLIDE=Vt,u.FOCUSING_UNIVER_EDITOR=_o,u.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE=Eo,u.FloatingObjectManagerService=Es,u.FollowNumberWithType=Qe,u.FontItalic=At,u.FontStyleType=gn,u.FontWeight=Nt,u.FormatType=xe,u.GlyphType=ct,u.GridType=nn,u.HLSColor=qe,u.HorizontalAlign=tt,u.ICommandService=Et,u.IConfigService=ds,u.IContextService=ft,u.IFloatingObjectManagerService=gs,u.ILocalStorageService=oa,u.ILogService=y,u.IPermissionService=Le,u.IResourceLoaderService=we,u.IResourceManagerService=jt,u.ISnapshotServerService=ca,u.IUndoRedoService=Yt,u.IUniverInstanceService=X,u.InterceptorManager=ua,u.InterpolationPointType=je,u.KeyIterator=Bn,u.LRUHelper=dt,u.LRUMap=$n,u.LifecycleStages=b,u.LocaleService=mt,u.LocaleType=Q,u.LogLevel=ls,u.MemoryCursor=yn,u.NamedStyleType=cn,u.NilCommand=hs,u.NumberUnitType=Cn,u.ObjectMatrix=V,u.ObjectRelativeFromH=Rn,u.ObjectRelativeFromV=mn,u.Observable=Mt,u.ObservableHooks=ia,u.Observer=Dt,u.OnLifecycle=Ae,u.PRESET_LIST_TYPE=Ui,u.PageElementType=Sn,u.PageOrientType=Nn,u.PageType=Qt,u.ParagraphElementType=an,u.PermissionPoint=Vn,u.PermissionStatus=le,u.Plugin=Ue,u.PositionedObjectLayoutType=un,u.PresetListType=kt,u.ProtectionType=Ke,u.RANGE_TYPE=p,u.RGBA_PAREN=ur,u.RGB_PAREN=lr,u.Range=st,u.Rectangle=z,u.RedoCommand=$s,u.RedoCommandId=Bs,u.RefAlias=ui,u.Registry=he,u.RegistryAsMap=de,u.RelativeDate=Ye,u.RelativeSlideLink=Ln,u.ResourceManagerService=Ps,u.RgbColor=Tt,u.RxDisposable=Qr,u.SectionType=sn,u.ShapeType=ze,u.SheetTypes=It,u.SheetViewModel=Ls,u.SlideDataModel=Ie,u.SpacingRule=hn,u.Styles=Rs,u.THEME_COLORS=Xe,u.TabStopAlignment=_n,u.TextDecoration=ye,u.TextDirection=lt,u.TextDirectionType=on,u.TextX=yt,u.TextXActionType=S,u.ThemeColor=wt,u.ThemeColorType=W,u.ThemeColors=St,u.ThemeService=be,u.Tools=m,u.UndoCommand=Gs,u.UndoCommandId=ks,u.UnitModel=Bt,u.Univer=yo,u.UniverEditablePermission=Kt,u.UniverEditablePermissionPoint=Ds,u.UniverInstanceType=N,u.UpdateDocsAttributeType=H,u.ValueIterator=kn,u.VerticalAlign=it,u.WidthType=fn,u.Worksheet=gt,u.WrapStrategy=ut,u.WrapTextType=ln,u.b64DecodeUnicode=Me,u.b64EncodeUnicode=da,u.binarySearchArray=He,u.cellToRange=jr,u.characterSpacingControlType=An,u.checkForSubstrings=Kr,u.checkParagraphHasBullet=Yr,u.checkParagraphHasIndent=zr,u.checkParagraphHasIndentByStyle=wn,u.codeToBlob=or,u.composeBody=me,u.composeInterceptors=Ys,u.concatMatrixArray=ri,u.convertBodyToHtml=Ri,u.covertTextRunToHtml=ce,u.createInterceptorKey=la,u.createInternalEditorID=Mo,u.createRowColIter=ue,u.debounce=gi,u.dedupe=ti,u.deepCompare=te,u.deleteContent=vn,u.extractPureTextFromCell=no,u.fromCallback=aa,u.fromObservable=Zr,u.generateTemporarySnap=Ra,u.getArrayLength=Y,u.getBodySlice=Re,u.getBodySliceHtml=Ft,u.getBorderStyleType=Vr,u.getCellValueType=Sr,u.getColorStyle=x,u.getDocsUpdateBody=Ut,u.getReverseDirection=ar,u.getSheetBlocksFromSnapshot=Aa,u.getTypeFromPermissionItemList=li,u.getWorksheetUID=uo,u.groupBy=si,u.handleJsonToDom=Gr,u.handleStyleToString=$r,u.hashAlgorithm=Xr,u.horizontalLineSegmentsSubtraction=ee,u.insertMatrixArray=ie,u.insertTextToContent=bn,u.isBlackColor=Ir,u.isBooleanString=ta,u.isCellV=Tr,u.isEmptyCell=Wr,u.isFormulaId=kr,u.isFormulaString=Br,u.isICellData=Nr,u.isInternalEditorID=Po,u.isNullCell=Lr,u.isNumeric=xs,u.isObserver=Wn,u.isRangesEqual=qo,u.isRealNum=yr,u.isSafeNumeric=Qo,u.isSameStyleTextRun=Tn,u.isUnitRangesEqual=Jo,u.isValidRange=xr,u.isWhiteColor=Ar,u.makeCellRangeToRangeData=pr,u.makeCellToSelection=Fr,u.mergeOverrideWithDependencies=Vs,u.mergeSets=ea,u.mergeWorksheetSnapshotWithDefault=Ss,u.moveMatrixArray=ae,u.moveRangeByOffset=Li,u.normalizeTextRuns=fe,u.numberToABC=di,u.numberToListABC=_i,u.orderSearchArray=Fe,u.queryObjectMatrix=Si,u.remove=Pt,u.repeatStringNumTimes=jn,u.replaceInDocumentBody=ra,u.requestImmediateMacroTask=sa,u.rotate=ni,u.runOnLifecycle=Ne,u.searchArray=ir,u.selectionToArray=wr,u.sequence=os,u.sequenceAsync=is,u.sequenceExecute=Oe,u.sequenceExecuteAsync=Yi,u.shallowEqual=Zo,u.sliceMatrixArray=ii,u.sortRules=fi,u.sortRulesByDesc=Ei,u.sortRulesFactory=at,u.spliceArray=oe,u.textDecoder=Xt,u.textEncoder=Ct,u.throttle=na,u.toDisposable=U,u.transformDocumentDataToSnapshot=Ia,u.transformSnapshotToDocumentData=Oa,u.transformSnapshotToWorkbookData=Ca,u.transformWorkbookDataToSnapshot=ma,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/core",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "private": false,
5
5
  "description": "Core library for Univer.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -66,7 +66,7 @@
66
66
  "typescript": "^5.4.5",
67
67
  "vite": "^5.2.10",
68
68
  "vitest": "^1.5.0",
69
- "@univerjs/shared": "0.1.8"
69
+ "@univerjs/shared": "0.1.9"
70
70
  },
71
71
  "scripts": {
72
72
  "test": "vitest run",