@univerjs/core 0.2.1 → 0.2.2

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
@@ -2,8 +2,8 @@
2
2
  `+n.map(function(s,r){return r+1+") "+s.toString()}).join(`
3
3
  `):"",this.name="UnsubscriptionError",this.errors=n}});function xs(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var Qr=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,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 l=Ls(o),a=l.next();!a.done;a=l.next()){var c=a.value;c.remove(this)}}catch(E){e={error:E}}finally{try{a&&!a.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}else o.remove(this);var h=this.initialTeardown;if(Ve(h))try{h()}catch(E){i=E instanceof Wn?E.errors:[E]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var d=Ls(u),f=d.next();!f.done;f=d.next()){var m=f.value;try{Ps(m)}catch(E){i=i!=null?i:[],E instanceof Wn?i=ys(ys([],Ds(i)),Ds(E.errors)):i.push(E)}}}catch(E){s={error:E}}finally{try{f&&!f.done&&(r=d.return)&&r.call(d)}finally{if(s)throw s.error}}}if(i)throw new Wn(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)Ps(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&xs(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&xs(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();Qr.EMPTY;function Ml(t){return t instanceof Qr||t&&"closed"in t&&Ve(t.remove)&&Ve(t.add)&&Ve(t.unsubscribe)}function Ps(t){Ve(t)?t():t.unsubscribe()}function bt(t){let e=!1;return t?Ml(t)?{dispose:()=>t.unsubscribe()}:typeof t=="function"?{dispose:()=>{e||(e=!0,t())}}:t:bt(()=>{})}function Ul(t){return bt(()=>{t.unsubscribe()})}class cs{constructor(){g(this,"_disposables",new Set)}add(e){const n=bt(e);return this._disposables.add(n),{dispose:()=>{n.dispose(),this._disposables.delete(n)}}}dispose(){this._disposables.forEach(e=>{e.dispose()}),this._disposables.clear()}}class yt{constructor(){g(this,"_disposed",!1);g(this,"_collection",new cs)}disposeWithMe(e){return this._collection.add(e)}ensureNotDisposed(){if(this._disposed)throw new Error("[Disposable]: object is disposed!")}dispose(){this._disposed||(this._disposed=!0,this._collection.dispose())}}class Ll extends yt{constructor(){super(...arguments);g(this,"dispose$",new rt.Subject)}dispose(){super.dispose(),this.dispose$.next(),this.dispose$.complete()}}class Be{static hasLength(e,n){return e.length===n}static getValueType(e){return Object.prototype.toString.apply(e)}static isObject(e){return this.getValueType(e)==="[object Object]"}static isIterable(e){return e[Symbol.iterator]!=null}static isNumber(e){return this.getValueType(e)==="[object Number]"}}function Tn(t,e){const n=t.indexOf(e);return n>-1?(t.splice(n,1),!0):!1}function Dl(t){const e=new Set,n=[];for(const s of t)e.has(s)||(e.add(s),n.push(s));return n}function yl(t,e){for(let n=t.length-1;n>-1;n--){const s=t[n];if(e(s,n))return s}return null}function xl(t,e){if(t.length===0)return t;const n=e%t.length;return t.slice(n).concat(t.slice(0,n))}function Pl(t,e){const n=new Map;return t.forEach(s=>{const r=e(s);let i=n.get(r);n.has(r)||(i=[],n.set(r,i)),i.push(s)}),n}function kl(t){return Array.isArray(t)?t:[t]}const ct=Symbol("newer"),Lt=Symbol("older");class ti{constructor(e){g(this,"entry");this.entry=e}[Symbol.iterator](){return this}next(){const e=this.entry;return e?(this.entry=e[ct],{done:!1,value:e.key}):{done:!0,value:void 0}}}class ei{constructor(e){g(this,"entry");this.entry=e}[Symbol.iterator](){return this}next(){const e=this.entry;return e?(this.entry=e[ct],{done:!1,value:e.value}):{done:!0,value:void 0}}}class ni{constructor(e){g(this,"entry");this.entry=e}[Symbol.iterator](){return this}next(){const e=this.entry;return e?(this.entry=e[ct],{done:!1,value:[e.key,e.value]}):{done:!0,value:void 0}}}var Ys,zs;zs=ct,Ys=Lt;class zn{constructor(e,n){g(this,"key");g(this,"value");g(this,zs);g(this,Ys);this.key=e,this.value=n,this[ct]=void 0,this[Lt]=void 0}toJSON(){return{key:this.key,value:this.value}}}class si{constructor(...e){g(this,"_keymap");g(this,"size",0);g(this,"limit");g(this,"oldest");g(this,"newest");g(this,"_onShiftListeners",[]);if(Be.hasLength(e,1)){if(Be.isNumber(e[0])){const n=e[0];this._initialize(n,void 0);return}if(Be.isIterable(e[0])){const n=e[0];this._initialize(0,n);return}return}if(Be.hasLength(e,2)){const n=e[0],s=e[1];this._initialize(n,s)}}onShift(e){if(this._onShiftListeners.indexOf(e)===-1)return this._onShiftListeners.push(e),bt(()=>Tn(this._onShiftListeners,e));throw new Error("[LRUMap]: the listener has been registered!")}_initialize(e,n){this.oldest=void 0,this.newest=void 0,this.size=0,this.limit=e,this._keymap=new Map,n&&(this.assign(n),e<1&&(this.limit=this.size))}_markEntryAsUsed(e){e!==this.newest&&(e[ct]&&(e===this.oldest&&(this.oldest=e[ct]),e[ct][Lt]=e[Lt]),e[Lt]&&(e[Lt][ct]=e[ct]),e[ct]=void 0,e[Lt]=this.newest,this.newest&&(this.newest[ct]=e),this.newest=e)}assign(e){let n,s=this.limit||Number.MAX_VALUE;this._keymap.clear();const r=e[Symbol.iterator]();for(let i=r.next();!i.done;i=r.next()){const o=new zn(i.value[0],i.value[1]);if(this._keymap.set(o.key,o),n?(n[ct]=o,o[Lt]=n):this.oldest=o,n=o,s--===0)throw new Error("overflow")}this.newest=n,this.size=this._keymap.size}set(e,n){let s=this._keymap.get(e);return s?(s.value=n,this._markEntryAsUsed(s),this):(this._keymap.set(e,s=new zn(e,n)),this.newest?(this.newest[ct]=s,s[Lt]=this.newest):this.oldest=s,this.newest=s,++this.size,this.size>this.limit&&this.shift(),this)}shift(){const e=this.oldest;if(e)return this.oldest&&this.oldest[ct]?(this.oldest=this.oldest[ct],this.oldest[Lt]=void 0):(this.oldest=void 0,this.newest=void 0),e[ct]=e[Lt]=void 0,this._keymap.delete(e.key),--this.size,this._onShiftListeners.forEach(n=>n(e)),[e.key,e.value]}get(e){const n=this._keymap.get(e);if(n)return this._markEntryAsUsed(n),n.value}has(e){return this._keymap.has(e)}find(e){const n=this._keymap.get(e);return n?n.value:void 0}delete(e){const n=this._keymap.get(e);if(n)return this._keymap.delete(n.key),n[ct]&&n[Lt]?(n[Lt][ct]=n[ct],n[ct][Lt]=n[Lt]):n[ct]?(n[ct][Lt]=void 0,this.oldest=n[ct]):n[Lt]?(n[Lt][ct]=void 0,this.newest=n[Lt]):this.oldest=this.newest=void 0,this.size--,n.value}clear(){this.oldest=void 0,this.newest=void 0,this.size=0,this._keymap.clear()}keys(){return new ti(this.oldest)}values(){return new ei(this.oldest)}entries(){return this[Symbol.iterator]()}[Symbol.iterator](){return new ni(this.oldest)}forEach(e,n){typeof n!="object"&&(n=this);let s=this.oldest;for(;s;)e.call(n,s.value,s.key,this),s=s[ct]}toJSON(){const e=new Array(this.size);let n=0,s=this.oldest;for(;s;)e[n++]={key:s.key,value:s.value},s=s[ct];return e}toString(){let e="",n=this.oldest;for(;n;)e+=`${String(n.key)}:${n.value}`,n=n[ct],n&&(e+=" < ");return e}}function _e(t){let e=0;const n=Object.keys(t);for(const s of n){const r=Number(s);e=Math.max(e,r)}return e+1}function Xn(t,e,n){const s=_e(n),r=n;for(let i=s-1;i>=t;i--)r[i+1]=r[i];r[t]=e}function qn(t,e,n){const s=Object.keys(n).reduce((r,i)=>Math.max(r,Number.parseInt(i)),0)+1;for(let r=t;r<s;r++)r<t+e?delete n[r]:n[r]!==void 0&&(n[r-e]=n[r],delete n[r])}function Hl(t,e){const n=t,s=Object.keys(n),r=s.length,i=e,o=Object.keys(i),l=o.length,a={};let c=0;for(let h=0;h<r;h++,c++){const u=s[h];a[c]=n[u]}for(let h=0;h<l;h++,c++){const u=o[h];a[c]=i[u]}return a}function Fl(t,e,n){const s=n;if(_e(n)>0){const i={};let o=0;for(let l=t;l<=e;l++)s[l]&&(i[o]=s[l],o++);return i}return{}}function Jn(t,e,n,s){const r=t>n;if(!r&&t+e>n)throw new Error("Invalid move operation");r?$l(t,e,n,s):Wl(t,e,n,s)}function $l(t,e,n,s){const r=s,i=[];for(let o=t;o<t+e;o++)i.push(r[o]);for(let o=t-1;o>=n;o--){const l=r[o];r[o+e]=l,l===void 0&&delete r[o+e]}i.forEach((o,l)=>{r[n+l]=o,o===void 0&&delete r[n+l]})}function Wl(t,e,n,s){const r=s,i=[];for(let o=t;o<t+e;o++)i.push(r[o]);for(let o=t+e;o<n;o++){const l=r[o];r[o-e]=l,l===void 0&&delete r[o-e]}i.forEach((o,l)=>{r[n+l-e]=o,o===void 0&&delete r[n+l-e]})}class ee{constructor(e={}){g(this,"_matrix");this._setOriginValue(e)}static MakeObjectMatrixSize(e){return new ee({[e-1]:{}})}getMatrix(){return this._matrix}forEach(e){const n=this._matrix,s=Object.keys(n);for(const r of s){const i=Number(r),o=n[i];if(e(i,o)===!1)return this}return this}forRow(e){const n=this._matrix,s=Object.keys(n);for(const r of s){const i=Number(r),o=n[i];if(e(i,Object.keys(o).map(a=>Number(a)))===!1)return this}return this}forValue(e){const n=this._matrix,s=Object.keys(n);for(const r of s){const i=Number(r),o=n[i];if(!o)continue;const l=Object.keys(o);for(const a of l){const c=Number(a),h=o[Number(a)];if(e(i,c,h)===!1)return this}}return this}swapRow(e,n){const s=this._matrix[e],r=this._matrix[n];this._matrix[e]=r,this._matrix[n]=s}getRow(e){return this._matrix[e]}getRowOrCreate(e){let n=this.getRow(e);return n==null&&(n={},this._matrix[e]=n),n}reset(){this._setOriginValue({})}hasValue(){const e=this._matrix,n=Object.keys(e);if(n.length===0)return!1;for(const s of n){const r=Number(s),i=e[r];if(Object.keys(i).length>0)return!0}return!1}getValue(e,n){var s,r;return(r=(s=this._matrix)==null?void 0:s[e])==null?void 0:r[n]}setValue(e,n,s){const r=this.getRowOrCreate(e);r[n]=s}deleteValue(e,n){var s,r;(r=(s=this._matrix)==null?void 0:s[e])==null||delete r[n]}realDeleteValue(e,n){var s,r,i;if((r=(s=this._matrix)==null?void 0:s[e])==null||delete r[n],this.getRow(e)){const o=this.getRow(e);if(o==null)return;Object.keys(o).length===0&&((i=this._matrix)==null||delete i[e])}}setRow(e,n){this._matrix[e]=n}moveRows(e,n,s){Jn(e,n,s,this._matrix)}moveColumns(e,n,s){this.forEach((r,i)=>{Jn(e,n,s,i)})}insertRows(e,n){for(let s=e;s<e+n;s++)Xn(s,{},this._matrix)}insertColumns(e,n){for(let s=e;s<e+n;s++)this.forEach((r,i)=>{i&&Xn(s,void 0,i)})}removeRows(e,n){qn(e,n,this._matrix)}removeColumns(e,n){this.forEach((s,r)=>{r&&qn(e,n,r)})}getFragment(e,n,s,r){const i=new ee;let o=0;for(let l=e;l<=n;l++){const a={};let c=0;for(let h=s;h<=r;h++){const u=this.getValue(l,h);a[c]=u,c++}i.setRow(o,a),o++}return i}getSlice(e,n,s,r){const i=new ee;for(let o=e;o<=n;o++)for(let l=s;l<=r;l++){const a=this.getValue(o,l);a&&i.setValue(o,l,D.deepClone(a))}return i}getSizeOf(){return Object.keys(this._matrix).length}getLength(){return _e(this._matrix)}getRange(){const s=this.getLength()-1;let r=0;const i=this.getLength();for(let o=0;o<i;o++){const l=this.getRow(o);if(l){const a=_e(l)-1;r=a>r?a:r}}return{startRow:0,startColumn:0,endRow:s,endColumn:r}}toNativeArray(){const e=new Array;return this.forValue((n,s,r)=>{e.push(r)}),e}toArray(){const e=[];return this.forRow((n,s)=>{e[n]==null&&(e[n]=[]),s.forEach(r=>{e[n][r]=this.getValue(n,r)})}),e}toFullArray(){const e=this.getRange(),{endColumn:n,endRow:s}=e,r=[];for(let i=0;i<=s;i++){const o=Array(n+1).fill(void 0);r.push(o)}return this.forValue((i,o,l)=>{r[i][o]=l}),r}toJSON(){return this._matrix}clone(){const e=JSON.stringify(this._matrix);return JSON.parse(e)}getData(){const e=JSON.stringify(this._matrix);return JSON.parse(e)}getArrayData(){let e=0,n=0,s=!1,r=!1;const i=new ee;return this.forEach((o,l)=>{s||(s=!0,e=o),Object.keys(l).forEach(a=>{const c=Number(a);r?c<n&&(n=c):(r=!0,n=c);const h=this.getValue(o,c);i.setValue(o-e,c-n,h)})}),i.getData()}getDataRange(){let e=0,n=0,s=0,r=-1,i=!1,o=!1;return this.forEach((l,a)=>{if(i||(i=!0,e=l),a==null)return;const c=_e(a)-1;c>s&&(s=c),Object.keys(a).forEach(h=>{const u=Number(h);o?u<n&&(n=u):(o=!0,n=u)}),l>r&&(r=l)}),{startRow:e,startColumn:n,endRow:r,endColumn:s}}getDiscreteRanges(){const e=[];return this.forEach((n,s)=>{Object.keys(s).forEach(r=>{const i=Number(r);let o=!1;for(const l of e)if(n>=l.startRow&&n<=l.endRow+1&&i>=l.startColumn&&i<=l.endColumn+1){l.endRow=Math.max(n,l.endRow),l.endColumn=Math.max(i,l.endColumn),o=!0;break}o||e.push({startRow:n,endRow:n,startColumn:i,endColumn:i})})}),e}merge(e){this.forValue((n,s)=>{const r=e.getValue(n,s);r!=null&&this.setValue(n,s,r)})}_setOriginValue(e={}){this._matrix=e}}const ue=class ue{static clone(e){return e.rangeType!==void 0?{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,rangeType:e.rangeType}:{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}}static equals(e,n){return e==null||n==null?!1:e.endRow===n.endRow&&e.endColumn===n.endColumn&&e.startRow===n.startRow&&e.startColumn===n.startColumn&&(e.rangeType===n.rangeType||e.rangeType===void 0&&n.rangeType===it.NORMAL||n.rangeType===void 0&&e.rangeType===it.NORMAL)}static intersects(e,n){if(e.rangeType===it.ROW&&n.rangeType===it.COLUMN||e.rangeType===it.COLUMN&&n.rangeType===it.ROW)return!0;if(e.rangeType===it.ROW&&n.rangeType===it.ROW)return e.startRow<=n.endRow&&e.endRow>=n.startRow;if(e.rangeType===it.COLUMN&&n.rangeType===it.COLUMN)return e.startColumn<=n.endColumn&&e.endColumn>=n.startColumn;const s=Math.floor(Number.MAX_SAFE_INTEGER/10),r=Number.isNaN(e.startRow)?0:e.startRow,i=Number.isNaN(e.endRow)?s:e.endRow,o=Number.isNaN(e.startColumn)?0:e.startColumn,l=Number.isNaN(e.endColumn)?s:e.endColumn,a=Number.isNaN(n.startRow)?0:n.startRow,c=Number.isNaN(n.endRow)?s:n.endRow,h=Number.isNaN(n.startColumn)?0:n.startColumn,u=Number.isNaN(n.endColumn)?s:n.endColumn,d=Math.abs(o+l-h-u),f=Math.abs(o-l)+Math.abs(h-u),m=Math.abs(r+i-a-c),E=Math.abs(r-i)+Math.abs(a-c);return d<=f&&m<=E}static getIntersects(e,n){const s=e.startRow,r=e.endRow,i=e.startColumn,o=e.endColumn,l=n.startRow,a=n.endRow,c=n.startColumn,h=n.endColumn;let u,d,f,m;if(l<=r)l>=s?d=l:d=s;else return null;if(a>=s)a>=r?m=r:m=a;else return null;if(c<=o)c>i?u=c:u=i;else return null;if(h>=i)h>=o?f=o:f=h;else return null;return{startRow:d,endRow:m,startColumn:u,endColumn:f,rangeType:it.NORMAL}}static contains(e,n){return e.startRow<=n.startRow&&e.endRow>=n.endRow&&e.startColumn<=n.startColumn&&e.endColumn>=n.endColumn}static realContain(e,n){return ue.contains(e,n)&&(e.startRow<n.startRow||e.endRow>n.endRow||e.startColumn<n.startColumn||e.endColumn>n.endColumn)}static union(...e){return e.reduce((n,s)=>({startRow:Math.min(n.startRow,s.startRow),startColumn:Math.min(n.startColumn,s.startColumn),endRow:Math.max(n.endRow,s.endRow),endColumn:Math.max(n.endColumn,s.endColumn),rangeType:it.NORMAL}),e[0])}static realUnion(...e){const n=e.some(i=>i.rangeType===it.COLUMN),s=e.some(i=>i.rangeType===it.ROW),r=ue.union(...e);return{startColumn:s?Number.NaN:r.startColumn,endColumn:s?Number.NaN:r.endColumn,startRow:n?Number.NaN:r.startRow,endRow:n?Number.NaN:r.endRow,rangeType:s?it.ROW:n?it.COLUMN:it.NORMAL}}static subtract(e,n){if(n.startRow>e.endRow||n.endRow<e.startRow||n.startColumn>e.endColumn||n.endColumn<e.startColumn)return[e];const s=[];n.startRow>=e.startRow&&s.push({startRow:e.startRow,startColumn:e.startColumn,endRow:n.startRow-1,endColumn:e.endColumn}),n.endRow<=e.endRow&&s.push({startRow:n.endRow+1,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn});const r=Math.max(e.startRow,n.startRow),i=Math.min(e.endRow,n.endRow);return n.startColumn>=e.startColumn&&s.push({startRow:r,startColumn:e.startColumn,endRow:i,endColumn:n.startColumn-1}),n.endColumn<=e.endColumn&&s.push({startRow:r,startColumn:n.endColumn+1,endRow:i,endColumn:e.endColumn}),s.filter(l=>l.startRow<=l.endRow&&l.startColumn<=l.endColumn)}static hasIntersectionBetweenTwoRect(e,n){return!(e.left>n.right||e.right<n.left||e.top>n.bottom||e.bottom<n.top)}static getIntersectionBetweenTwoRect(e,n){const s=Math.max(e.left,n.left),r=Math.min(e.right,n.right),i=Math.max(e.top,n.top),o=Math.min(e.bottom,n.bottom);return r<=s||o<=i?null:{left:s,right:r,top:i,bottom:o,width:r-s,height:o-i}}};g(ue,"getRelativeRange",(e,n)=>({startRow:e.startRow-n.startRow,endRow:e.endRow-e.startRow,startColumn:e.startColumn-n.startColumn,endColumn:e.endColumn-e.startColumn})),g(ue,"getPositionRange",(e,n,s)=>({...s||{},startRow:s&&[At.ROW,At.ALL].includes(s.startAbsoluteRefType||0)?s.startRow:e.startRow+n.startRow,endRow:s&&[At.ROW,At.ALL].includes(s.endAbsoluteRefType||0)?s.endRow:e.endRow+e.startRow+n.startRow,startColumn:s&&[At.COLUMN,At.ALL].includes(s.startAbsoluteRefType||0)?s.startColumn:e.startColumn+n.startColumn,endColumn:s&&[At.COLUMN,At.ALL].includes(s.endAbsoluteRefType||0)?s.endColumn:e.endColumn+e.startColumn+n.startColumn})),g(ue,"moveHorizontal",(e,n=0,s=0)=>({...e,startColumn:e.startColumn+n,endColumn:e.endColumn+n+s})),g(ue,"moveVertical",(e,n=0,s=0)=>({...e,startRow:e.startRow+n,endRow:e.endRow+n+s})),g(ue,"moveOffset",(e,n,s)=>({...e,startRow:e.startRow+s,endRow:e.endRow+s,startColumn:e.startColumn+n,endColumn:e.endColumn+n}));let me=ue;class Bl{constructor(e,n){g(this,"_values",[]);g(this,"_keys",[]);g(this,"_keyMaps",new Map);this._values=e,this._keys=n,e.forEach(s=>{this._initKeyMap(s)})}_initKeyMap(e){this._keys.forEach(n=>{const s=e[n],r=this._keyMaps.get(n)||new Map;r.set(s,e),this._keyMaps.set(n,r)})}getValue(e,n){const s=n||this._keys;for(let r=0;r<s.length;r++){const i=this._keyMaps.get(s[r]);if(i!=null&&i.has(e))return i.get(e)}return null}hasValue(e){for(let n=0;n<this._keys.length;n++){const s=this._keyMaps.get(this._keys[n]);if(s!=null&&s.has(e))return!0}return!1}addValue(e){this._values.push(e),this._initKeyMap(e)}setValue(e,n,s){const r=this.getValue(e);r&&Object.keys(r).includes(n)&&(r[n]=s)}deleteValue(e){const n=this.getValue(e);if(n){this._keys.forEach(r=>{const i=this._keyMaps.get(r),o=n[r];i==null||i.delete(o)});const s=this._values.findIndex(r=>r===n);this._values.splice(s,1)}}getValues(){return this._values}getKeyMap(e){var n;return[...((n=this._keyMaps.get(e))==null?void 0:n.keys())||[]]}clear(){this._values=[],this._keys=[],this._keyMaps.clear()}}function Zn(t,e,n,s){return{forEach(r){for(let i=t;i<=e;i++)for(let o=n;o<=s;o++)r(i,o)}}}function Gl(t){if(t==null||t.length===0)return Number.NaN;const e=t.toLowerCase().split(""),n=e.length,s=o=>o.charCodeAt(0)-96;let r=0,i=0;for(let o=0;o<n;o++)i=s(e[o]),r+=i*26**(n-o-1);return r===0?Number.NaN:r-1}const In=65,ri=90,jl=97;function Vl(t){const e=ri-In+1;let n="";for(;t>=0;)n=String.fromCharCode(t%e+In)+n,t=Math.floor(t/e)-1;return n}function ii(t,e){let n="";for(;e>0;)n+=t,e--;return n}function Kl(t,e=!1){const n=ri-In+1;let s=jl;e&&(s=In);const r=String.fromCharCode(t%n+s),i=Math.floor(t/n)+1;return ii(r,i)}function Yl(t,e){return t.zIndex>e.zIndex?1:t.zIndex===e.zIndex?0:-1}function zl(t,e){return t.zIndex>e.zIndex?-1:t.zIndex===e.zIndex?0:1}function Me(t="index",e=1){return(n,s)=>n[t]>s[t]?e:n[t]===s[t]?0:-e}function Xl(t,e){let n;function s(...r){const i=this,o=function(){n=null,t.apply(i,r)};clearTimeout(n),n=setTimeout(o,e)}return Object.defineProperty(s,"cancel",{value:()=>{clearTimeout(n)},enumerable:!1,writable:!1}),s}function hn(t,e,n){const{dataStream:s,textRuns:r=[]}=t;let i=e;const o=[];for(const l of r){const{st:a,ed:c}=l;D.hasIntersectionBetweenTwoRanges(e,n,a,c)&&(a>i?(o.push(s.slice(i,a)),o.push(Qn(s,{...l,ed:Math.min(c,n)}))):o.push(Qn(s,{...l,st:i,ed:Math.min(c,n)}))),i=Math.max(e,Math.min(c,n))}return i!==n&&o.push(s.slice(i,n)),o.join("")}function ql(t,e=!0){var n;if(e&&((n=t.paragraphs)!=null&&n.length)){const{dataStream:s,paragraphs:r=[]}=t;let i="",o=-1;for(const l of r){const{startIndex:a,paragraphStyle:c={}}=l,{spaceAbove:h,spaceBelow:u,lineSpacing:d}=c,f=[];h!=null&&(typeof h=="number"?f.push(`margin-top: ${h}px`):f.push(`margin-top: ${h.v}px`)),u!=null&&(typeof u=="number"?f.push(`margin-bottom: ${u}px`):f.push(`margin-bottom: ${u.v}px`)),d!=null&&f.push(`line-height: ${d}`),a>o+1?i+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${hn(t,o+1,a)}</p>`:i+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,o=a}return o!==s.length&&(i+=hn(t,o,s.length)),i}else return hn(t,0,t.dataStream.length)}function Qn(t,e){const{st:n,ed:s,ts:r={}}=e,{ff:i,fs:o,it:l,bl:a,ul:c,st:h,ol:u,bg:d,cl:f,va:m}=r;let E=t.slice(n,s);const P=[];return l===K.TRUE&&(E=`<i>${E}</i>`),m===ke.SUPERSCRIPT?E=`<sup>${E}</sup>`:m===ke.SUBSCRIPT&&(E=`<sub>${E}</sub>`),(c==null?void 0:c.s)===K.TRUE&&(E=`<u>${E}</u>`),(h==null?void 0:h.s)===K.TRUE&&(E=`<s>${E}</s>`),a===K.TRUE&&(E=`<strong>${E}</strong>`),i&&P.push(`font-family: ${i}`),f&&P.push(`color: ${f.rgb}`),o&&P.push(`font-size: ${o}pt`),u&&P.push("text-decoration: overline"),d&&P.push(`background: ${d.rgb}`),P.length?`<span style="${P.join("; ")};">${E}</span>`:E}const Jl={sheetId:"",range:{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1}},Zl={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1},Ql={startRow:0,startColumn:0,endRow:0,endColumn:0},ta={row:0,column:0},dn={ff:"Arial",fs:11,it:K.FALSE,bl:K.FALSE,ul:{s:K.FALSE},st:{s:K.FALSE},ol:{s:K.FALSE},tr:{a:0,v:K.FALSE},td:qe.UNSPECIFIED,cl:{rgb:"#000"},bg:{rgb:"#fff"},ht:Ne.UNSPECIFIED,vt:xe.UNSPECIFIED,tb:Pe.UNSPECIFIED,pd:{t:0,r:0,b:0,l:0}},oi={id:"default_slide",title:"defaultSlide",pageSize:{width:300,height:300}};var li=(t=>(t.ARRAY_CONVERTOR="ARRAY_CONVERTOR",t.MATRIX_CONVERTOR="MATRIX_CONVERTOR",t))(li||{});function an(t,e){const{textRuns:n=[]}=e;let s=0;for(const i of n){const{ts:o={},st:l,ed:a}=i;if(o[t]==null)return K.FALSE;switch(t){case"bl":case"it":{if(o[t]===K.FALSE)return K.FALSE;break}case"ul":case"st":{if(o[t].s===K.FALSE)return K.FALSE;break}default:throw new Error(`unknown style key: ${t} in IStyleBase`)}s+=a-l}return e.dataStream.indexOf(`\r
4
4
  `)===s?K.TRUE:K.FALSE}const ze=class ze{constructor(e,n,s){g(this,"_range");g(this,"_worksheet");this._deps=s,this._range=n,this._worksheet=e}static foreach(e,n){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=e;for(let l=s;l<=i;l++)for(let a=r;a<=o;a++)n(l,a)}getRangeData(){return this._range}getValue(){return this.getValues()[0][0]}getValues(){const{startRow:e,endRow:n,startColumn:s,endColumn:r}=this._range,i=[];for(let o=e;o<=n;o++){const l=[];for(let a=s;a<=r;a++)l.push(this.getMatrix().getValue(o,a)||null);i.push(l)}return i}getMatrix(){const{startRow:e,endRow:n,startColumn:s,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new ee;for(let l=e;l<=n;l++)for(let a=s;a<=r;a++)o.setValue(l,a,i.getValue(l,a)||null);return o}getMatrixObject(){const{startRow:e,endRow:n,startColumn:s,endColumn:r}=this._range,i=this._worksheet.getCellMatrix(),o=new ee;for(let l=e;l<=n;l++)for(let a=s;a<=r;a++)o.setValue(l-e,a-s,i.getValue(l,a)||{});return o}getA1Notation(){const{startRow:e,endRow:n,startColumn:s,endColumn:r}=this._range;let i,o;return s<r?(i=D.numToWord(s+1)+(e+1),o=D.numToWord(r+1)+(n+1)):(i=D.numToWord(r+1)+(n+1),o=D.numToWord(s+1)+(e+1)),i===o?`${i}`:`${i}:${o}`}getBackground(){return this.getBackgrounds()[0][0]}getBackgrounds(){const e=this._deps.getStyles();return this.getValues().map(n=>n.map(s=>{var i;const r=e.getStyleByCell(s);return((i=r==null?void 0:r.bg)==null?void 0:i.rgb)||dn.bg.rgb}))}getCell(e,n){const{startRow:s,endRow:r,startColumn:i,endColumn:o}=this._range,l={startRow:s+e,endRow:s+e,startColumn:i+n,endColumn:i+n};return new ze(this._worksheet,l,this._deps)}getColumn(){return this._range.startColumn}getObjectValue(e={}){return this.getObjectValues(e)[0][0]}getObjectValues(e={}){var l;const{startRow:n,endRow:s,startColumn:r,endColumn:i}=this._range,o=this._worksheet.getCellMatrix().getFragment(n,s,r,i).getData();if(e.isIncludeStyle){const a=this._deps.getStyles();for(let c=0;c<=s-n;c++)for(let h=0;h<=i-r;h++){if(o==null||((l=o==null?void 0:o[c])==null?void 0:l[h])==null)continue;const u=o[c][h].s;u&&(o[c][h].s=a.get(u))}}return o}getFontColor(){return this.getFontColors()[0][0]}getFontColors(){const e=this._deps.getStyles();return this.getValues().map(n=>n.map(s=>{var i;const r=e.getStyleByCell(s);return((i=r==null?void 0:r.cl)==null?void 0:i.rgb)||dn.cl.rgb}))}getFontFamilies(){return this._getStyles("ff")}getFontFamily(){return this.getFontFamilies()[0][0]}getUnderlines(){return this._getStyles("ul")}getUnderline(){var n,s;const{p:e}=(n=this.getValue())!=null?n:{};return e&&Array.isArray((s=e.body)==null?void 0:s.textRuns)&&e.body.textRuns.length>0?an("ul",e.body)===K.TRUE?{s:K.TRUE}:{s:K.FALSE}:this.getUnderlines()[0][0]}getOverlines(){return this._getStyles("ol")}getOverline(){return this.getOverlines()[0][0]}getStrikeThrough(){var n,s;const{p:e}=(n=this.getValue())!=null?n:{};return e&&Array.isArray((s=e.body)==null?void 0:s.textRuns)&&e.body.textRuns.length>0?an("st",e.body)===K.TRUE?{s:K.TRUE}:{s:K.FALSE}:this.getStrikeThroughs()[0][0]}getStrikeThroughs(){return this._getStyles("st")}getFontSize(){var n,s;const e=((n=this.getValue())==null?void 0:n.p)||{};return e&&Array.isArray((s=e.body)==null?void 0:s.textRuns)&&e.body.textRuns.length>0?e.body.textRuns.some(r=>{var i;return((i=r==null?void 0:r.ts)==null?void 0:i.fs)!=null})?Math.max(...e.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 n,s;const{p:e}=(n=this.getValue())!=null?n:{};return e&&Array.isArray((s=e.body)==null?void 0:s.textRuns)&&e.body.textRuns.length>0?an("it",e.body)===K.TRUE?En.ITALIC:En.NORMAL:this._getFontStyles()[0][0]}_getFontStyles(){return this._getStyles("it")}getFontWeight(){var n,s;const{p:e}=(n=this.getValue())!=null?n:{};return e&&Array.isArray((s=e.body)==null?void 0:s.textRuns)&&e.body.textRuns.length>0?an("bl",e.body)===K.TRUE?pn.BOLD:pn.NORMAL:this._getFontWeights()[0][0]}_getFontWeights(){return this._getStyles("bl")}getGridId(){return this._worksheet.getSheetId()}getHeight(){const{_range:e,_worksheet:n}=this,{startRow:s,endRow:r}=e;let i=0;for(let o=0;o<=r-s;o++){const l=n.getRowHeight(o);i+=l}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:e,endColumn:n}=this._range;return n-e+1}getNumRows(){const{startRow:e,endRow:n}=this._range;return n-e+1}getRichTextValue(){return this.getRichTextValues()[0][0]}getRichTextValues(){return this.getValues().map(e=>e.map(n=>(n==null?void 0:n.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 e=this._deps.getStyles();return this.getValues().map(n=>n.map(s=>e.getStyleByCell(s)))}getVerticalAlignment(){return this.getVerticalAlignments()[0][0]}getVerticalAlignments(){return this._getStyles("vt")}getWidth(){const{_range:e,_worksheet:n}=this,{startColumn:s,endColumn:r}=e;let i=0;for(let o=0;o<=r-s;o++)i+=n.getColumnWidth(o);return i}getWrap(){return this.getWrapStrategy()===Pe.WRAP?K.TRUE:K.FALSE}getWrapStrategies(){return this._getStyles("tb")}getWrapStrategy(){return this.getWrapStrategies()[0][0]}forEach(e){ze.foreach(this._range,e)}_getStyles(e){const n=this._deps.getStyles();return this.getValues().map(s=>s.map(r=>{const i=n&&n.getStyleByCell(r);return i&&i[e]||dn[e]}))}};g(ze,"transformRange",(e,n)=>e.rangeType===it.ALL?{startColumn:0,startRow:0,endColumn:n.getMaxColumns()-1,endRow:n.getMaxRows()-1}:e.rangeType===it.COLUMN?{startRow:0,endRow:n.getMaxRows()-1,startColumn:e.startColumn,endColumn:e.endColumn}:e.rangeType===it.ROW?{startColumn:0,endColumn:n.getMaxColumns()-1,startRow:e.startRow,endRow:e.endRow}:e);let He=ze;function ea(t,e){if(t.length===0||t[0].length===0)return null;const n=new Array(t[0].length).fill(0);let s=0,r=null;for(let i=0;i<t.length;i++){for(let l=0;l<t[0].length;l++)n[l]=e(t[i][l])?n[l]+1:0;const o=na(n);o.area>s&&(s=o.area,r={startColumn:o.start,startRow:i-o.height+1,endColumn:o.end,endRow:i})}return r}function na(t){const e=[];let n=0,s={area:0,height:0,start:0,end:0},r=0;for(;r<t.length;)if(e.length===0||t[r]>=t[e[e.length-1]])e.push(r++);else{const i=t[e.pop()],o=e.length===0?r:r-e[e.length-1]-1;i*o>n&&(n=i*o,s={area:n,height:i,start:e.length===0?0:e[e.length-1]+1,end:r-1})}for(;e.length>0;){const i=t[e.pop()],o=e.length===0?r:r-e[e.length-1]-1;i*o>n&&(n=i*o,s={area:n,height:i,start:e.length===0?0:e[e.length-1]+1,end:r-1})}return s}function sa(t,e){He.foreach(e,(n,s)=>{t[n][s]=void 0})}function ra(t,e){const n=t.toFullArray(),s=[];for(;;){const r=ea(n,e);if(!r)break;s.push(r),sa(n,r)}return s}function ia(t,e,n,s=!1){let r={...t};const i=r.startAbsoluteRefType||At.NONE,o=r.endAbsoluteRefType||At.NONE;return!s&&i===At.ALL&&o===At.ALL?r:s||i===At.NONE&&o===At.NONE?me.moveOffset(r,e,n):(i===At.NONE?r={...r,startRow:r.startRow+n,startColumn:r.startColumn+e}:i===At.COLUMN?r={...r,startRow:r.startRow+n}:i===At.ROW&&(r={...r,startColumn:r.startColumn+e}),o===At.NONE?r={...r,endRow:r.endRow+n,endColumn:r.endColumn+e}:o===At.COLUMN?r={...r,endRow:r.endRow+n}:o===At.ROW&&(r={...r,endColumn:r.endColumn+e}),r)}async function ai(t){for(const[e,n]of t.entries())try{if(!await n())return{index:e,result:!1}}catch(s){return{index:e,result:!1,error:s}}return{result:!0,index:-1}}function ui(t){for(const[e,n]of t.entries())try{if(!n())return{index:e,result:!1}}catch(s){return{index:e,result:!1,error:s}}return{result:!0,index:-1}}const Qe=ut.createIdentifier("univer.context-service");class ci extends yt{constructor(){super(...arguments);g(this,"_contextChanged$",new rt.Subject);g(this,"contextChanged$",this._contextChanged$.asObservable());g(this,"_contextMap",new Map)}dispose(){super.dispose(),this._contextChanged$.complete()}getContextValue(n){var s;return(s=this._contextMap.get(n))!=null?s:!1}setContextValue(n,s){this._contextMap.set(n,s),this._contextChanged$.next({[n]:s})}subscribeContextValue$(n){return new rt.Observable(s=>{const r=this._contextChanged$.pipe(rt.filter(i=>typeof i[n]<"u")).subscribe(i=>s.next(i[n]));return this._contextMap.has(n)&&s.next(this._contextMap.get(n)),()=>r.unsubscribe()})}}var hi=(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))(hi||{});const pe=ut.createIdentifier("univer.log");class di extends yt{constructor(){super(...arguments);g(this,"_logLevel",3)}debug(...n){this._logLevel>=4&&this._log(console.debug,...n)}log(...n){this._logLevel>=3&&this._log(console.log,...n)}warn(...n){this._logLevel>=2&&this._log(console.warn,...n)}error(...n){this._logLevel>=1&&this._log(console.error,...n)}setLogLevel(n){this._logLevel=n}_log(n,...s){const r=s[0];/^\[(.*?)\]/g.test(r)?n(`\x1B[97;104m${r}\x1B[0m`,...s.slice(1)):n(...s)}}var oa=Object.defineProperty,la=Object.getOwnPropertyDescriptor,aa=(t,e,n,s)=>{for(var r=s>1?void 0:s?la(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&oa(e,n,r),r},ks=(t,e)=>(n,s)=>e(n,s,t),tn=(t=>(t[t.COMMAND=0]="COMMAND",t[t.OPERATION=1]="OPERATION",t[t.MUTATION=2]="MUTATION",t))(tn||{});const en=ut.createIdentifier("anywhere.command-service");class ua{constructor(){g(this,"_commands",new Map);g(this,"_commandTypes",new Map)}registerCommand(e){if(this._commands.has(e.id))throw new Error(`[CommandRegistry]: command "${e.id}" has been registered before.`);return this._commands.set(e.id,e),this._commandTypes.set(e.id,e.type),bt(()=>{var n;this._commands.delete(e.id),this._commandTypes.delete(e.id),(n=e.onDispose)==null||n.call(e)})}hasCommand(e){return this._commands.has(e)}getCommand(e){return this._commands.has(e)?[this._commands.get(e)]:null}getCommandType(e){return this._commandTypes.get(e)}}const fi={id:"nil",type:0,handler:()=>!0};exports.CommandService=class{constructor(e,n){g(this,"_commandRegistry");g(this,"_beforeCommandExecutionListeners",[]);g(this,"_commandExecutedListeners",[]);g(this,"_multiCommandDisposables",new Map);g(this,"_commandExecutingLevel",0);g(this,"_commandExecutionStack",[]);this._injector=e,this._logService=n,this._commandRegistry=new ua,this._registerCommand(fi)}hasCommand(e){return this._commandRegistry.hasCommand(e)}registerCommand(e){return this._registerCommand(e)}registerMultipleCommand(e){return this._registerMultiCommand(e)}beforeCommandExecuted(e){if(this._beforeCommandExecutionListeners.indexOf(e)===-1)return this._beforeCommandExecutionListeners.push(e),bt(()=>{const n=this._beforeCommandExecutionListeners.indexOf(e);this._beforeCommandExecutionListeners.splice(n,1)});throw new Error("[CommandService]: could not add a listener twice.")}onCommandExecuted(e){if(this._commandExecutedListeners.indexOf(e)===-1)return this._commandExecutedListeners.push(e),bt(()=>{const n=this._commandExecutedListeners.indexOf(e);this._commandExecutedListeners.splice(n,1)});throw new Error("[CommandService]: could not add a listener twice.")}async executeCommand(e,n,s){try{const r=this._commandRegistry.getCommand(e);if(r){const[i]=r,o={id:i.id,type:i.type,params:n},l=this._pushCommandExecutionStack(o);this._beforeCommandExecutionListeners.forEach(c=>c(o,s));const a=await this._execute(i,n,s);return this._commandExecutedListeners.forEach(c=>c(o,s)),l.dispose(),a}throw new Error(`[CommandService]: command "${e}" is not registered.`)}catch(r){throw this._logService.error(r),r}}syncExecuteCommand(e,n,s){var i;const r=this._commandRegistry.getCommand(e);if(r){const[o]=r,l={id:o.id,type:o.type,params:n};if(o.type===2){const h=yl(this._commandExecutionStack,u=>u.type===0);h&&(l.params=(i=l.params)!=null?i:{},l.params.trigger=h.id)}const a=this._pushCommandExecutionStack(l);this._beforeCommandExecutionListeners.forEach(h=>h(l,s));const c=this._syncExecute(o,n,s);return this._commandExecutedListeners.forEach(h=>h(l,s)),a.dispose(),c}throw new Error(`[CommandService]: command "${e}" is not registered.`)}_pushCommandExecutionStack(e){return this._commandExecutionStack.push(e),bt(()=>Tn(this._commandExecutionStack,e))}_registerCommand(e){return this._commandRegistry.registerCommand(e)}_registerMultiCommand(e){const n=this._commandRegistry.getCommand(e.id);let s;if(n){if(n[0].multi!==!0)throw new Error("Command has registered as a single command.");s=n[0]}else{const i=new cs;s=new ca(e.id),i.add(this._commandRegistry.registerCommand(s)),i.add(bt(()=>{this._multiCommandDisposables.delete(e.id)})),this._multiCommandDisposables.set(e.id,i)}const r=s.registerImplementation(e);return bt(()=>{var i;r.dispose(),s.hasImplementations()||(i=this._multiCommandDisposables.get(e.id))==null||i.dispose()})}async _execute(e,n,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(this._commandExecutingLevel,0))}executing command "${e.id}"`),this._commandExecutingLevel++;let r;try{r=await this._injector.invoke(e.handler,n,s),this._commandExecutingLevel--}catch(i){throw r=!1,this._commandExecutingLevel=0,i}return r}_syncExecute(e,n,s){this._logService.debug("[CommandService]",`${"|-".repeat(Math.max(0,this._commandExecutingLevel))}executing command "${e.id}".`),this._commandExecutingLevel++;let r;try{if(r=this._injector.invoke(e.handler,n,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}};exports.CommandService=aa([ks(0,ut.Inject(ut.Injector)),ks(1,pe)],exports.CommandService);class ca{constructor(e){g(this,"name");g(this,"multi",!0);g(this,"type",0);g(this,"priority",0);g(this,"_implementations",[]);g(this,"handler",async(e,n)=>{if(!this._implementations.length)return!1;const s=e.get(pe),r=e.get(Qe),i=e.get(ut.Injector);for(const o of this._implementations){const l=o.command.preconditions;if((!l||l&&l(r))&&(s.debug("[MultiCommand]",`executing implementation "${o.command.name}".`),await i.invoke(o.command.handler,n)))return!0}return!1});this.id=e,this.name=e}registerImplementation(e){const n={command:e};return this._implementations.push(n),this._implementations.sort((s,r)=>r.command.priority-s.command.priority),bt(()=>{var r;const s=this._implementations.indexOf(n);this._implementations.splice(s,1),(r=e.onDispose)==null||r.call(e)})}hasImplementations(){return this._implementations.length>0}}function hs(t,e,n){const s=t.map(r=>()=>e.syncExecuteCommand(r.id,r.params,n));return ui(s)}function ha(t,e,n){const s=t.map(r=>()=>e.executeCommand(r.id,r.params,n));return ai(s)}function gi(t){return new rt.Observable(e=>{const n=t((...s)=>e.next(s));return()=>n==null?void 0:n.dispose()})}const da=t=>new Promise(e=>{rt.merge(gi(t.onCommandExecuted.bind(t)).pipe(cn.filter(([n])=>n.type===tn.MUTATION)),rt.timer(300)).pipe(cn.debounceTime(16),cn.first()).subscribe(()=>{e()})});var Xt=(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.COMPLETION_FINISHED=9]="COMPLETION_FINISHED",t[t.CHANGESET_REVISION_CONFILICT=5001]="CHANGESET_REVISION_CONFILICT",t[t.SNAPSHOT_INVALID_SNAPSHOT=6001]="SNAPSHOT_INVALID_SNAPSHOT",t[t.SNAPSHOT_HAS_BEEN_REMOVED=6002]="SNAPSHOT_HAS_BEEN_REMOVED",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.APPLY_PERMISSION_DENIED=7004]="APPLY_PERMISSION_DENIED",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.YUUMI_UNABLE_LOAD_URL=10001]="YUUMI_UNABLE_LOAD_URL",t[t.YUUMI_URL_COL_OUT_OF_RANGE=10002]="YUUMI_URL_COL_OUT_OF_RANGE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(Xt||{});function _i(t){return!!(t&&t.code&&t.code!==Xt.OK&&t.code!=="OK")}var Z=(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))(Z||{}),Ft=(t=>(t[t.Reader=0]="Reader",t[t.Editor=1]="Editor",t[t.Owner=2]="Owner",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(Ft||{}),fn=(t=>(t[t.Unkonwn=0]="Unkonwn",t[t.Workbook=1]="Workbook",t[t.Worksheet=2]="Worksheet",t[t.SelectRange=3]="SelectRange",t[t.Document=4]="Document",t[t.Slide=5]="Slide",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(fn||{});class Mn extends yt{}class ds{constructor(){g(this,"_data",[])}static create(){return new ds}add(e){this._data.indexOf(e)>-1||this._data.push(e)}delete(e){const n=this._data.indexOf(e);this._data.splice(n,1)}getData(){return this._data}}class fs{constructor(){g(this,"_data",new Map)}static create(){return new fs}add(e,n){this._data.has(e)||this._data.set(e,n)}delete(e){this._data.delete(e)}getData(){return this._data}}var mi=(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[t.CUSTOM_BLOCK=5]="CUSTOM_BLOCK",t))(mi||{}),ce=(t=>(t.PARAGRAPH="\r",t.SECTION_BREAK=`
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||{}),On=(t=>(t.BULLET_LIST="BULLET_LIST",t.ORDER_LIST="ORDER_LIST",t))(On||{});const fa={BULLET_LIST:{listType:"BULLET_LIST",nestingLevel:[{bulletAlignment:fe.START,glyphFormat:" %0",textStyle:{fs:12},startNumber:0,glyphSymbol:"●",hanging:21,indentStart:21},{bulletAlignment:fe.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"■",hanging:21,indentStart:42},{bulletAlignment:fe.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"◆",hanging:21,indentStart:63}]},ORDER_LIST:{listType:"ORDER_LIST",nestingLevel:[{bulletAlignment:fe.START,glyphFormat:" %1.",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:21},{bulletAlignment:fe.START,glyphFormat:" %1.%2)",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:42},{bulletAlignment:fe.START,glyphFormat:" %1.%2.%3.",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:63}]}};function gs(t){const e=[];for(const n of t){const{ed:s,ts:r}=n;if(n.sId===void 0&&delete n.sId,D.isEmptyObject(r)&&n.sId==null)continue;if(e.length===0){e.push(n);continue}const i=e.pop();Xr(n,i)&&D.hasIntersectionBetweenTwoRanges(i.st,i.ed,n.st,n.ed)?e.push({...n,st:i.st,ed:s}):e.push(i,n)}return e}function Ei(t,e,n,s){var c;const{textRuns:r}=t;if(r==null)return;const i=[],o=r.length;let l=!1;const a=(c=e.textRuns)!=null?c:[];if(a.length)for(const h of a)h.st+=s,h.ed+=s;for(let h=0;h<o;h++){const u=r[h],d=r[h+1],{st:f,ed:m}=u;if(m<s)i.push(u);else if(s>=f&&s<=m){if(d&&d.st===d.ed&&s===d.st){i.push(u);continue}if(l)u.st+=n,u.ed+=n,i.push(u);else{l=!0,u.ed+=n;const E=[];if(a.length){const P={...u,st:f,ed:a[0].st};P.ed>P.st&&E.push(P),E.push(...a);const x=a[a.length-1],Q={...u,st:x.ed,ed:m+n};Q.ed>Q.st&&E.push(Q)}else E.push(u);i.push(...E)}}else u.st+=n,u.ed+=n,l||(l=!0,i.push(...a)),i.push(u)}l||(l=!0,i.push(...a)),t.textRuns=gs(i)}function _s(t,e,n,s){const{paragraphs:r}=t;if(r==null)return;const{paragraphs:i,dataStream:o}=e,l=[];let a=-1;for(let h=0,u=r.length;h<u;h++){const d=r[h],{startIndex:f}=d;f>=s&&(d.startIndex+=n),a===-1&&f>=s&&(a=h),l.push(d.startIndex)}let c=-1;if(i){for(let h=0,u=i.length;h<u;h++){const d=i[h];d.startIndex+=s;const f=d.startIndex;c=l.indexOf(f)}if(o===ce.PARAGRAPH&&i.length===1){const h=r[a],u=i[0],d=h.paragraphStyle,f=h.bullet;h.paragraphStyle=u.paragraphStyle,h.bullet=u.bullet,u.paragraphStyle=d,u.bullet=f}c!==-1&&r.splice(c,1),r.push(...i),r.sort(Me("startIndex"))}}function ga(t,e,n,s){const{sectionBreaks:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c}=a;c>=s&&(a.startIndex+=n)}const i=e.sectionBreaks;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function pi(t,e,n,s){const{customBlocks:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c}=a;c>=s&&(a.startIndex+=n)}const i=e.customBlocks;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function Ri(t,e,n,s){const{tables:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c,endIndex:h}=a;c>s?(a.startIndex+=n,a.endIndex+=n):h>=s-1&&(a.endIndex+=n)}const i=e.tables;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s,a.endIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function Ci(t,e,n,s){t.customRanges||(t.customRanges=[]);const{customRanges:r}=t,i={};for(let l=0,a=r.length;l<a;l++){const c=r[l];i[c.rangeId]=c;const{startIndex:h,endIndex:u}=c;h>=s?(c.startIndex+=n,c.endIndex+=n):u>s-1&&(c.endIndex+=n)}const o=[];if(e.customRanges){for(let l=0,a=e.customRanges.length;l<a;l++){const c=e.customRanges[l],h=i[c.rangeId];if(c.startIndex+=s,c.endIndex+=s,h){if(h.startIndex<=c.startIndex&&h.endIndex>=c.endIndex)continue;if(t.dataStream[h.startIndex]===ce.CUSTOM_RANGE_START&&t.dataStream[h.endIndex]===ce.CUSTOM_RANGE_END){o.push(c);continue}if(t.dataStream[h.startIndex]===ce.CUSTOM_RANGE_START){h.endIndex=c.endIndex;continue}if(t.dataStream[h.endIndex]===ce.CUSTOM_RANGE_END){h.startIndex=c.startIndex;continue}}o.push(c)}r.push(...o),r.sort(Me("startIndex"))}}function _a(t){t.sort((s,r)=>s.startIndex-r.startIndex);const e=[];let n=t[0];for(let s=1;s<t.length;s++)n.endIndex+1>=t[s].startIndex?n.endIndex=Math.max(n.endIndex,t[s].endIndex):(e.push(n),n=t[s]);return e.push(n),e}function ma(t){const e={};for(let n=0,s=t.length;n<s;n++){const r=t[n],i=e[r.id];e[r.id]=[...i!=null?i:[],r]}return Object.keys(e).forEach(n=>{const s=e[n],r=_a(s);e[n]=r}),Object.values(e).flat()}function Ii(t,e,n,s){t.customDecorations||(t.customDecorations=[]);const{customDecorations:r}=t;if(n>0)for(let i=0,o=r.length;i<o;i++){const l=r[i],{startIndex:a,endIndex:c}=l;a>=s?(l.startIndex+=n,l.endIndex+=n):c>s-1&&(l.endIndex+=n)}if(e.customDecorations){const i=[];for(let o=0,l=e.customDecorations.length;o<l;o++){const a=e.customDecorations[o];i.push(a),a.startIndex+=s,a.endIndex+=s}r.push(...i),t.customDecorations=ma(r),t.customDecorations.sort(Me("startIndex"))}}function Oi(t,e,n){var l;const{textRuns:s}=t,r=n,i=n+e,o=[];if(r===i&&(s!=null&&s.find(a=>a.st===n&&a.ed===n))){const a=s.find(c=>c.st===n&&c.ed===n);return o.push({...a,st:a.st-n,ed:a.ed-n}),t.textRuns=(l=t.textRuns)==null?void 0:l.filter(c=>c!==a),o}if(s){const a=[];for(let c=0,h=s.length;c<h;c++){const u=s[c],{st:d,ed:f}=u;if(r<=d&&i>=f){o.push({...u,st:d-r,ed:f-r});continue}else d<=r&&f>=i?(o.push({...u,st:r-r,ed:i-r}),u.ed-=e):r>=d&&r<f?(o.push({...u,st:r-r,ed:f-r}),u.ed=r):i>d&&i<=f?(o.push({...u,st:d-r,ed:i-r}),u.st=i-e,u.ed-=e):d>=i&&(u.st-=e,u.ed-=e);a.push(u)}t.textRuns=a}return o.length===0&&o.push({st:0,ed:e,ts:{}}),o}function Si(t,e,n){const{paragraphs:s}=t,r=n,i=n+e,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<i){o.push({...h,startIndex:u-n});continue}else u>=i&&(h.startIndex-=e);l.push(h)}t.paragraphs=l}return o}function Ni(t,e,n){const{sectionBreaks:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<=i){o.push({...h,startIndex:u-n});continue}else u>i&&(h.startIndex-=e);l.push(h)}t.sectionBreaks=l}return o}function Ai(t,e,n){const{customBlocks:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<=i){o.push({...h,startIndex:u-n});continue}else u>i&&(h.startIndex-=e);l.push(h)}t.customBlocks=l}return o}function bi(t,e,n){const{tables:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u,endIndex:d}=h;if(r<=u&&i>=d){o.push({...h,startIndex:u-n,endIndex:d-n});continue}else if(u<=r&&d>=i){const f=wn(u,d,r,i);h.startIndex=f[0],h.endIndex=f[1]}else i<u&&(h.startIndex-=e,h.endIndex-=e);l.push(h)}t.tables=l}return o}function vi(t,e,n){const{customRanges:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u,endIndex:d}=h;if(r<=u&&i>=u){o.push({...h,startIndex:u-n,endIndex:d-n});continue}else if(u<=r&&d>=i){const f=wn(u,d,r,i);h.startIndex=f[0],h.endIndex=f[1]}else i<u&&(h.startIndex-=e,h.endIndex-=e);l.push(h)}t.customRanges=l}return o}function wi(t,e,n,s=!0){const{customDecorations:r}=t,i=n,o=n+e-1,l=[];if(r){const a=[];for(let c=0,h=r.length;c<h;c++){const u=r[c],{startIndex:d,endIndex:f}=u;if(d>=i&&f<=o){l.push(u);continue}else if(Math.max(i,d)<=Math.min(o,f)){const m=wn(d,f,i,o);u.startIndex=m[0],u.endIndex=m[1]}else o<d&&s&&(u.startIndex-=e,u.endIndex-=e);a.push(u)}t.customDecorations=a}return l}function Ea(t,e,n,s,r){const i=pa(t,e,n,s,r),o=Ra(t,e,n,s,r),l=Ca(t,e,n,s,r),a=Ia(t,e,n,s,r),c=Oa(t,e,n,s,r),h=Sa(t,e,n,s,r),u=Na(t,e,n,s,r);return{dataStream:"",textRuns:i,paragraphs:o,sectionBreaks:l,customBlocks:a,tables:c,customRanges:h,customDecorations:u}}function pa(t,e,n,s,r){const{textRuns:i}=t,{textRuns:o}=e;if(i==null||o==null)return;const l=Oi(t,n,s);if(r!==Pt.REPLACE){const a=Ti(o,l,r);e.textRuns=a}return Ei(t,e,n,s),l}function Ti(t,e,n){if(e.length===0)return t;t=D.deepClone(t),e=D.deepClone(e);const s=[],r=t.length,i=e.length;let o=0,l=0,a=null;function c(){return a?(s.push(a),a=null,!0):!1}for(;o<r&&l<i;){const{st:f,ed:m,ts:E}=t[o],{st:P,ed:x,ts:Q,sId:_t}=e[l];let ht;if(n===Pt.COVER?ht={...Q,...E}:ht={...E,...Q},m<P)c()||s.push(t[o]),o++;else if(x<f)c()||s.push(e[l]),l++;else{const p={st:Math.min(f,P),ed:Math.max(f,P),ts:f<P?{...E}:{...Q},sId:f<P?void 0:_t};p.ed>p.st&&s.push(p),s.push({st:Math.max(f,P),ed:Math.min(m,x),ts:ht,sId:_t}),m<x?(o++,e[l].st=m,e[l].st===e[l].ed&&l++):(l++,t[o].st=x,t[o].st===t[o].ed&&o++);const O={st:Math.min(m,x),ed:Math.max(m,x),ts:m<x?{...Q}:{...E},sId:m<x?_t:void 0};a=O.ed>O.st?O:null}}c();const h=s[s.length-1],u=t[r-1],d=e[i-1];return h.ed!==Math.max(u.ed,d.ed)&&(u.ed>d.ed?s.push(u):s.push(d)),gs(s)}function Ra(t,e,n,s,r){const{paragraphs:i}=t,{paragraphs:o}=e;if(i==null||o==null)return;const l=Si(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h,paragraphStyle:u,bullet:d}=c;let f=[];for(const m of l){const{startIndex:E,paragraphStyle:P,bullet:x}=m;let Q,_t;if(r===Pt.COVER?(Q={...P,...u},_t={listId:"",listType:On.BULLET_LIST,nestingLevel:0,textStyle:{},...x,...d}):(Q={...u,...P},_t={listId:"",listType:On.BULLET_LIST,nestingLevel:0,textStyle:{},...d,...x}),h===E){f.push({startIndex:h,paragraphStyle:Q,bullet:_t});break}}a.push(...f),f=[]}e.paragraphs=a}return _s(t,e,n,s),l}function Ca(t,e,n,s,r){const{sectionBreaks:i}=t,{sectionBreaks:o}=e;if(i==null||o==null)return;const l=Ni(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h}=c;let u=[];for(const d of l){const{startIndex:f}=d;if(h===f){r===Pt.COVER?u.push({...d,...c}):u.push({...c,...d});break}}a.push(...u),u=[]}e.sectionBreaks=a}return _s(t,e,n,s),l}function Ia(t,e,n,s,r){const{customBlocks:i}=t,{customBlocks:o}=e;if(i==null||o==null)return;const l=Ai(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h}=c;let u=[];for(const d of l){const{startIndex:f}=d;if(h===f){r===Pt.COVER?u.push({...d,...c}):u.push({...c,...d});break}}a.push(...u),u=[]}e.customBlocks=a}return pi(t,e,n,s),l}function Oa(t,e,n,s,r){const{tables:i}=t,{tables:o}=e;if(i==null||o==null)return;const l=bi(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h,endIndex:u}=c;let d=[];for(const f of l){const{startIndex:m,endIndex:E}=f;if(m>=h&&E<=u){r===Pt.COVER?d.push({...f,...c}):d.push({...c,...f});break}}a.push(...d),d=[]}e.tables=a}return Ri(t,e,n,s),l}function Sa(t,e,n,s,r){t.customRanges||(t.customRanges=[]);const{customRanges:i}=t,{customRanges:o}=e;if(i==null||o==null)return;let l=[];return r===Pt.REPLACE&&(l=vi(t,n,s)),Ci(t,e,0,s),l}function Na(t,e,n,s,r){t.customDecorations||(t.customDecorations=[]);let i=[];return r===Pt.REPLACE&&(i=wi(t,n,s,!1)),Ii(t,e,0,s),i}function Je(t,e,n,s=!1){const{dataStream:r,textRuns:i=[],paragraphs:o=[]}=t,l={dataStream:r.slice(e,n)},a=[];for(const u of i){const d=D.deepClone(u),{st:f,ed:m}=d;D.hasIntersectionBetweenTwoRanges(f,m,e,n)&&(e>=f&&e<=m?a.push({...d,st:e,ed:Math.min(n,m)}):n>=f&&n<=m?a.push({...d,st:Math.max(e,f),ed:n}):a.push(d))}a.length?l.textRuns=a.map(u=>{const{st:d,ed:f}=u;return{...u,st:d-e,ed:f-e}}):s&&(l.textRuns=[{st:0,ed:n-e,ts:{}}]);const c=[];for(const u of o){const{startIndex:d}=u;d>=e&&d<=n&&c.push(D.deepClone(u))}c.length&&(l.paragraphs=c.map(u=>({...u,startIndex:u.startIndex-e}))),l.customDecorations=Ui(t,e,n);const{customRanges:h}=Mi(t,e,n);return l.customRanges=h,l}function Aa(t){const{dataStream:e,textRuns:n,paragraphs:s,customRanges:r,customDecorations:i}=t;let o=0,l=0;r==null||r.forEach(c=>{c.startIndex<0&&(o=Math.max(o,-c.startIndex)),c.endIndex>e.length-1&&(l=Math.max(l,c.endIndex-e.length+1))});const a=`${ce.CUSTOM_RANGE_START.repeat(o)}${e}${ce.CUSTOM_RANGE_END.repeat(l)}`;return n&&(n[0]&&(n[0].st=n[0].st-o),n[n.length-1]&&(n[n.length-1].ed=n[n.length-1].ed+l)),n==null||n.forEach(c=>{c.st+=o,c.ed+=o}),s==null||s.forEach(c=>{c.startIndex+=o}),r==null||r.forEach(c=>{c.startIndex+=o,c.endIndex+=o}),i==null||i.forEach(c=>{c.startIndex+=o,c.endIndex+=l}),{...t,dataStream:a,textRuns:n,paragraphs:s,customRanges:r,customDecorations:i}}function Mi(t,e,n){const{customRanges:s=[]}=t;let r=0,i=0;const o=s.filter(l=>Math.max(l.startIndex,e)<=Math.min(l.endIndex,n-1)).map(l=>({...l,startIndex:l.startIndex,endIndex:l.endIndex}));if(o.length){o.forEach(l=>{l.startIndex<e&&(r+=1),l.endIndex>n-1&&(i+=1)});for(let l=0;l<r;l++){const a=o[l];a.startIndex=e-r+l}if(i){const l=[...o].sort((a,c)=>c.endIndex-a.endIndex);for(let a=0;a<i;a++){const c=l[a];c.endIndex=n+i-a-1}}}return{customRanges:o.map(l=>({...l,startIndex:l.startIndex-e,endIndex:l.endIndex-e})),leftOffset:r,rightOffset:i}}function Ui(t,e,n){const{customDecorations:s=[]}=t,r=[];return s.forEach(i=>{if(Math.max(i.startIndex,e)<=Math.min(i.endIndex,n-1)){const o=D.deepClone(i);r.push({...o,startIndex:Math.max(o.startIndex-e,0),endIndex:Math.min(o.endIndex,n)-e})}}),r}function ts(t,e,n=Pt.COVER){if(e.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:l=[]}=e,a=Ti(o,r,n);a.length&&(s.textRuns=a);const c=[];let h=0,u=0;for(;h<i.length&&u<l.length;){const d=i[h],f=l[u],{startIndex:m}=d,{startIndex:E}=f;m===E?(c.push(D.deepMerge(d,f)),h++,u++):m<E?(c.push(D.deepClone(d)),h++):(c.push(D.deepClone(f)),u++)}return h<i.length&&c.push(...i.slice(h)),u<l.length&&c.push(...l.slice(u)),c.length&&(s.paragraphs=c),s}function ba(t){const{body:e}=t;if(e==null)return!0;const{textRuns:n=[],paragraphs:s=[]}=e;return n.length===0&&s.length===0}function va(t=D.generateRandomId(6),e=Te.EN_US,n=""){return{id:t,locale:e,title:n,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:{}}}var Wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wa(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var $t={},Li={},ms={};Object.defineProperty(ms,"__esModule",{value:!0});function Ta(t,e){if(Array.isArray(e))return!1;for(let n in t)if(!Es(t[n],e[n]))return!1;for(let n in e)if(t[n]===void 0)return!1;return!0}function Ma(t,e){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Es(t[n],e[n]))return!1;return!0}function Es(t,e){return t===e?!0:t===null||e===null||typeof t!="object"||typeof e!="object"?!1:Array.isArray(t)?Ma(t,e):Ta(t,e)}ms.default=Es;var ps={};Object.defineProperty(ps,"__esModule",{value:!0});function es(t){if(t===null)return null;if(Array.isArray(t))return t.map(es);if(typeof t=="object"){const e={};for(let n in t)e[n]=es(t[n]);return e}else return t}ps.default=es;var Rs={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildOf=t.advancer=t.readCursor=t.writeCursor=t.WriteCursor=t.ReadCursor=t.isValidPathItem=void 0;function e(h,u){if(!h)throw new Error(u)}const n=h=>h!=null&&typeof h=="object"&&!Array.isArray(h),s=(h,u)=>typeof h==typeof u?h>u:typeof h=="string"&&typeof u=="number";function r(h,u){for(let d in h){const f=d;u.write(f,h[f])}}t.isValidPathItem=h=>typeof h=="number"||typeof h=="string"&&h!=="__proto__";class i{constructor(u=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=u}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const u=[];let d=this.container,f=this.parents.length-1,m=this.idx;for(;m>=0;)u.unshift(d[m]),m===0?(m=this.indexes[f*2],d=this.parents[f--]):m-=n(d[m-1])?2:1;return u}}class o extends i{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let u;return this.container&&this.container.length>this.idx+1&&n(u=this.container[this.idx+1])?u:null}descendFirst(){let u=this.idx+1;if(!this.container||u>=this.container.length||n(this.container[u])&&u+1>=this.container.length)return!1;n(this.container[u])&&u++;const d=this.container[u];return Array.isArray(d)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(u),this.idx=0,this.container=d):this.idx=u,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const u=this.indexes[this.indexes.length-1]+1,d=this.parents[this.parents.length-1];return u>=d.length?!1:(e(!isNaN(u)),this.indexes[this.indexes.length-1]=u,this.container=d[u],!0)}_init(u,d,f,m){this.container=u,this.idx=d,this.parents=f.slice(),this.indexes=m.slice()}clone(){const u=new o;return u._init(this.container,this.idx,this.parents,this.indexes),u}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(u,d){const f=this.getComponent();f&&d(f,u);for(const m of this)u&&u.descend(m),this.traverse(u,d),u&&u.ascend()}eachPick(u,d){this.traverse(u,(f,m)=>{f.p!=null&&d(f.p,m)})}eachDrop(u,d){this.traverse(u,(f,m)=>{f.d!=null&&d(f.d,m)})}}t.ReadCursor=o;class l extends i{constructor(u=null){super(u),this.pendingDescent=[],this._op=u}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let u=0;u<this.pendingDescent.length;u++){const d=this.pendingDescent[u];let f=this.idx+1;if(f<this.container.length&&n(this.container[f])&&f++,e(f===this.container.length||!n(this.container[f])),f===this.container.length)this.container.push(d),this.idx=f;else if(this.container[f]===d)this.idx=f;else{if(!Array.isArray(this.container[f])){const m=this.container.splice(f,this.container.length-f);this.container.push(m),this.lcIdx>-1&&(this.lcIdx=f)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(s(d,this.container[this.lcIdx][0])),f=this.lcIdx+1,this.lcIdx=-1);f<this.container.length&&s(d,this.container[f][0]);)f++;if(this.indexes.push(f),this.idx=0,f<this.container.length&&this.container[f][0]===d)this.container=this.container[f];else{const m=[d];this.container.splice(f,0,m),this.container=m}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const u=this.idx+1;if(u<this.container.length&&n(this.container[u]))return this.container[u];{const d={};return this.container.splice(u,0,d),d}}write(u,d){const f=this.getComponent();e(f[u]==null||f[u]===d,"Internal consistency error: Overwritten component. File a bug"),f[u]=d}get(){return this._op}descend(u){if(!t.isValidPathItem(u))throw Error("Invalid JSON key");this.pendingDescent.push(u)}descendPath(u){return this.pendingDescent.push(...u),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(u,d=r){if(u===null)return;if(e(Array.isArray(u)),u===this._op)throw Error("Cannot merge into my own tree");const f=this.lcIdx,m=this.parents.length;let E=0;for(let P=0;P<u.length;P++){const x=u[P];typeof x=="string"||typeof x=="number"?(E++,this.descend(x)):Array.isArray(x)?this.mergeTree(x,d):typeof x=="object"&&d(x,this)}for(;E--;)this.ascend();this.lcIdx=this.parents.length===m?f:-1}at(u,d){this.descendPath(u),d(this);for(let f=0;f<u.length;f++)this.ascend();return this}writeAtPath(u,d,f){return this.at(u,()=>this.write(d,f)),this.reset(),this}writeMove(u,d,f=0){return this.writeAtPath(u,"p",f).writeAtPath(d,"d",f)}getPath(){const u=super.getPath();return u.push(...this.pendingDescent),u}}t.WriteCursor=l,t.writeCursor=()=>new l,t.readCursor=h=>new o(h);function a(h,u,d){let f,m;m=f=h?h.descendFirst():!1;function E(P){let x;for(;m;){const Q=x=h.getKey();if(P!=null){let _t=!1;if(u&&typeof Q=="number"&&(x=u(Q,h.getComponent()),x<0&&(x=~x,_t=!0)),s(x,P))return null;if(x===P&&!_t)return h}d&&typeof x=="number"&&d(x,h.getComponent()),m=h.nextSibling()}return null}return E.end=()=>{f&&h.ascend()},E}t.advancer=a;function c(h,u,d){let f,m,E,P;for(f=m=h&&h.descendFirst(),E=P=u&&u.descendFirst();f||E;){let x=f?h.getKey():null,Q=E?u.getKey():null;x!==null&&Q!==null&&(s(Q,x)?Q=null:x!==Q&&(x=null)),d(x==null?Q:x,x!=null?h:null,Q!=null?u:null),x!=null&&f&&(f=h.nextSibling()),Q!=null&&E&&(E=u.nextSibling())}m&&h.ascend(),P&&u.ascend()}t.eachChildOf=c})(Rs);var Cs={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(t.ConflictType||(t.ConflictType={}))})(Cs);var Bn={},Se={},Hs;function Is(){return Hs||(Hs=1,Object.defineProperty(Se,"__esModule",{value:!0}),Se.uniToStrPos=Se.strPosToUni=void 0,Se.strPosToUni=(t,e=t.length)=>{let n=0,s=0;for(;s<e;s++){const r=t.charCodeAt(s);r>=55296&&r<=57343&&(n++,s++)}if(s!==e)throw Error("Invalid offset - splits unicode bytes");return s-n},Se.uniToStrPos=(t,e)=>{let n=0;for(;e>0;e--){const s=t.charCodeAt(n);n+=s>=55296&&s<=57343?2:1}return n}),Se}var Gn={},Fs;function ns(){return Fs||(Fs=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.uniSlice=t.dlen=t.eachOp=void 0;const e=Is(),n=p=>{if(!Array.isArray(p))throw Error("Op must be an array of components");let O=null;for(let v=0;v<p.length;v++){const z=p[v];switch(typeof z){case"object":if(typeof z.d!="number"&&typeof z.d!="string")throw Error("Delete must be number or string");if(t.dlen(z.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(z.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(z>0))throw Error("Skip components must be >0");if(typeof O=="number")throw Error("Adjacent skip components should be combined");break}O=z}if(typeof O=="number")throw Error("Op has a trailing skip")};function s(p,O){let v=0,z=0;for(let et=0;et<p.length;et++){const X=p[et];switch(O(X,v,z),typeof X){case"object":v+=t.dlen(X.d);break;case"string":z+=e.strPosToUni(X);break;case"number":v+=X,z+=X;break}}}t.eachOp=s;function r(p,O){const v=[],z=l(v);return s(p,(et,X,Gt)=>{z(O(et,X,Gt))}),u(v)}const i=p=>p,o=p=>r(p,i);t.dlen=p=>typeof p=="number"?p:e.strPosToUni(p);const l=p=>O=>{if(!(!O||O.d===0||O.d===""))if(p.length===0)p.push(O);else if(typeof O==typeof p[p.length-1])if(typeof O=="object"){const v=p[p.length-1];v.d=typeof v.d=="string"&&typeof O.d=="string"?v.d+O.d:t.dlen(v.d)+t.dlen(O.d)}else p[p.length-1]+=O;else p.push(O)},a=p=>typeof p=="number"?p:typeof p=="string"?e.strPosToUni(p):typeof p.d=="number"?p.d:e.strPosToUni(p.d);t.uniSlice=(p,O,v)=>{const z=e.uniToStrPos(p,O),et=v==null?1/0:e.uniToStrPos(p,v);return p.slice(z,et)};const c=(p,O,v)=>typeof p=="number"?v==null?p-O:Math.min(p,v)-O:t.uniSlice(p,O,v),h=p=>{let O=0,v=0;return{take:(X,Gt)=>{if(O===p.length)return X===-1?null:X;const St=p[O];let ft;if(typeof St=="number")return X===-1||St-v<=X?(ft=St-v,++O,v=0,ft):(v+=X,X);if(typeof St=="string"){if(X===-1||Gt==="i"||e.strPosToUni(St.slice(v))<=X)return ft=St.slice(v),++O,v=0,ft;{const Ct=v+e.uniToStrPos(St.slice(v),X);return ft=St.slice(v,Ct),v=Ct,ft}}else{if(X===-1||Gt==="d"||t.dlen(St.d)-v<=X)return ft={d:c(St.d,v)},++O,v=0,ft;{let Ct=c(St.d,v,v+X);return v+=X,{d:Ct}}}},peek:()=>p[O]}},u=p=>(p.length>0&&typeof p[p.length-1]=="number"&&p.pop(),p);function d(p,O,v){if(v!=="left"&&v!=="right")throw Error("side ("+v+") must be 'left' or 'right'");n(p),n(O);const z=[],et=l(z),{take:X,peek:Gt}=h(p);for(let ft=0;ft<O.length;ft++){const Ct=O[ft];let Tt,jt;switch(typeof Ct){case"number":for(Tt=Ct;Tt>0;)jt=X(Tt,"i"),et(jt),typeof jt!="string"&&(Tt-=a(jt));break;case"string":v==="left"&&typeof Gt()=="string"&&et(X(-1)),et(e.strPosToUni(Ct));break;case"object":for(Tt=t.dlen(Ct.d);Tt>0;)switch(jt=X(Tt,"i"),typeof jt){case"number":Tt-=jt;break;case"string":et(jt);break;case"object":Tt-=t.dlen(jt.d)}break}}let St;for(;St=X(-1);)et(St);return u(z)}function f(p,O){n(p),n(O);const v=[],z=l(v),{take:et}=h(p);for(let Gt=0;Gt<O.length;Gt++){const St=O[Gt];let ft,Ct;switch(typeof St){case"number":for(ft=St;ft>0;)Ct=et(ft,"d"),z(Ct),typeof Ct!="object"&&(ft-=a(Ct));break;case"string":z(St);break;case"object":ft=t.dlen(St.d);let Tt=0;for(;Tt<ft;)switch(Ct=et(ft-Tt,"d"),typeof Ct){case"number":z({d:c(St.d,Tt,Tt+Ct)}),Tt+=Ct;break;case"string":Tt+=e.strPosToUni(Ct);break;case"object":z(Ct)}break}}let X;for(;X=et(-1);)z(X);return u(v)}const m=(p,O)=>{let v=0;for(let z=0;z<O.length&&p>v;z++){const et=O[z];switch(typeof et){case"number":{v+=et;break}case"string":const X=e.strPosToUni(et);v+=X,p+=X;break;case"object":p-=Math.min(t.dlen(et.d),p-v);break}}return p},E=(p,O)=>typeof p=="number"?m(p,O):p.map(v=>m(v,O));function P(p,O,v){return r(p,(z,et)=>typeof z=="object"&&typeof z.d=="number"?{d:v.slice(O,et,et+z.d)}:z)}function x(p){return r(p,O=>{switch(typeof O){case"object":if(typeof O.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return O.d;case"string":return{d:O};case"number":return O}})}function Q(p){return r(p,O=>typeof O=="object"&&typeof O.d=="string"?{d:e.strPosToUni(O.d)}:O)}function _t(p){let O=!0;return s(p,v=>{typeof v=="object"&&typeof v.d=="number"&&(O=!1)}),O}function ht(p){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:u,normalize:o,checkOp:n,create(O=""){if(typeof O!="string")throw Error("Initial data must be a string");return p.create(O)},apply(O,v){n(v);const z=p.builder(O);for(let et=0;et<v.length;et++){const X=v[et];switch(typeof X){case"number":z.skip(X);break;case"string":z.append(X);break;case"object":z.del(t.dlen(X.d));break}}return z.build()},transform:d,compose:f,transformPosition:m,transformSelection:E,isInvertible:_t,makeInvertible(O,v){return P(O,v,p)},stripInvertible:Q,invert:x,invertWithDoc(O,v){return x(P(O,v,p))},isNoop:O=>O.length===0}}t.default=ht}(Gn)),Gn}var un={},$s;function Ua(){if($s)return un;$s=1,Object.defineProperty(un,"__esModule",{value:!0});const t=ns(),e=Is();function n(s,r){return{get:s,getLength(){return s().length},insert(i,o,l){const a=e.strPosToUni(s(),i);return r([a,o],l)},remove(i,o,l){const a=e.strPosToUni(s(),i);return r([a,{d:o}],l)},_onOp(i){t.eachOp(i,(o,l,a)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(a,o);break;case"object":const c=t.dlen(o.d);this.onRemove&&this.onRemove(a,c)}})},onInsert:null,onRemove:null}}return un.default=n,n.provides={text:!0},un}var Ws;function La(){return Ws||(Ws=1,function(t){var e=Wt&&Wt.__createBinding||(Object.create?function(d,f,m,E){E===void 0&&(E=m),Object.defineProperty(d,E,{enumerable:!0,get:function(){return f[m]}})}:function(d,f,m,E){E===void 0&&(E=m),d[E]=f[m]}),n=Wt&&Wt.__setModuleDefault||(Object.create?function(d,f){Object.defineProperty(d,"default",{enumerable:!0,value:f})}:function(d,f){d.default=f}),s=Wt&&Wt.__importStar||function(d){if(d&&d.__esModule)return d;var f={};if(d!=null)for(var m in d)Object.hasOwnProperty.call(d,m)&&e(f,d,m);return n(f,d),f},r=Wt&&Wt.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(t,"__esModule",{value:!0}),t.type=t.remove=t.insert=void 0;const i=Is(),o=s(ns()),l=r(Ua()),a={create(d){return d},toString(d){return d},builder(d){if(typeof d!="string")throw Error("Invalid document snapshot: "+d);const f=[];return{skip(m){let E=i.uniToStrPos(d,m);if(E>d.length)throw Error("The op is too long for this document");f.push(d.slice(0,E)),d=d.slice(E)},append(m){f.push(m)},del(m){d=d.slice(i.uniToStrPos(d,m))},build(){return f.join("")+d}}},slice:o.uniSlice},c=o.default(a),h=Object.assign(Object.assign({},c),{api:l.default});t.type=h,t.insert=(d,f)=>f.length===0?[]:d===0?[f]:[d,f],t.remove=(d,f)=>o.dlen(f)===0?[]:d===0?[{d:f}]:[d,{d:f}];var u=ns();Object.defineProperty(t,"makeType",{enumerable:!0,get:function(){return u.default}})}(Bn)),Bn}(function(t){var e=Wt&&Wt.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(t,"__esModule",{value:!0}),t.editOp=t.replaceOp=t.insertOp=t.moveOp=t.removeOp=t.type=void 0;const n=e(ms),s=e(ps),r=Rs,i=Cs;function o(_,R){if(!_)throw new Error(R)}t.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:r.readCursor,writeCursor:r.writeCursor,create:_=>_,isNoop:_=>_==null,setDebug(_){},registerSubtype:x,checkValidOp:et,normalize:X,apply:Gt,transformPosition:St,compose:ft,tryTransform:kn,transform:Ao,makeInvertible:jt,invert:Ct,invertWithDoc:No,RM_UNEXPECTED_CONTENT:i.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:i.ConflictType.DROP_COLLISION,BLACKHOLE:i.ConflictType.BLACKHOLE,transformNoConflict:(_,R,N)=>Ms(()=>!0,_,R,N),typeAllowingConflictsPred:_=>Object.assign(Object.assign({},t.type),{transform:(R,N,M)=>Ms(_,R,N,M)})};const l=_=>_?_.getComponent():null;function a(_){return _&&typeof _=="object"&&!Array.isArray(_)}const c=_=>Array.isArray(_)?_.slice():_!==null&&typeof _=="object"?Object.assign({},_):_,h=_=>_&&(_.p!=null||_.r!==void 0),u=_=>_&&(_.d!=null||_.i!==void 0);function d(_,R){return o(_!=null),typeof R=="number"?(o(Array.isArray(_),"Invalid key - child is not an array"),(_=_.slice()).splice(R,1)):(o(a(_),"Invalid key - child is not an object"),delete(_=Object.assign({},_))[R]),_}function f(_,R,N){return typeof R=="number"?(o(_!=null,"Container is missing for key"),o(Array.isArray(_),"Cannot use numerical key for object container"),o(_.length>=R,"Cannot insert into out of bounds index"),_.splice(R,0,N)):(o(a(_),"Cannot insert into missing item"),o(_[R]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),_[R]=N),N}t.removeOp=(_,R=!0)=>r.writeCursor().writeAtPath(_,"r",R).get(),t.moveOp=(_,R)=>r.writeCursor().writeMove(_,R).get(),t.insertOp=(_,R)=>r.writeCursor().writeAtPath(_,"i",R).get(),t.replaceOp=(_,R,N)=>r.writeCursor().at(_,M=>{M.write("r",R),M.write("i",N)}).get(),t.editOp=(_,R,N,M=!1)=>r.writeCursor().at(_,A=>O(A,R,N,M)).get();const m=(_,R)=>_!=null&&(typeof R=="number"?Array.isArray(_):typeof _=="object"),E=(_,R)=>m(_,R)?_[R]:void 0,P={};function x(_){let R=_.type?_.type:_;R.name&&(P[R.name]=R),R.uri&&(P[R.uri]=R)}const Q=_=>{const R=P[_];if(R)return R;throw Error("Missing type: "+_)};x(La());const _t=(_,R)=>_+R;x({name:"number",apply:_t,compose:_t,invert:_=>-_,transform:_=>_});const ht=_=>_==null?null:_.et?Q(_.et):_.es?P["text-unicode"]:_.ena!=null?P.number:null,p=_=>_.es?_.es:_.ena!=null?_.ena:_.e,O=(_,R,N,M=!1)=>{const[A,T]=typeof R=="string"?[Q(R),R]:[R,R.name];!M&&A.isNoop&&A.isNoop(N)||(T==="number"?_.write("ena",N):T==="text-unicode"?_.write("es",N):(_.write("et",T),_.write("e",N)))};function v(_){o(typeof _=="number"),o(_>=0),o(_===(0|_))}function z(_){typeof _=="number"?v(_):o(typeof _=="string")}function et(_){if(_===null)return;const R=new Set,N=new Set,M=T=>{let G=!0,W=!1;for(let C in T){const S=T[C];if(G=!1,o(C==="p"||C==="r"||C==="d"||C==="i"||C==="e"||C==="es"||C==="ena"||C==="et","Invalid component item '"+C+"'"),C==="p")v(S),o(!R.has(S)),R.add(S),o(T.r===void 0);else if(C==="d")v(S),o(!N.has(S)),N.add(S),o(T.i===void 0);else if(C==="e"||C==="es"||C==="ena"){o(!W),W=!0;const b=ht(T);o(b,"Missing type in edit"),b.checkValidOp&&b.checkValidOp(p(T))}}o(!G)},A=(T,G,W)=>{if(!Array.isArray(T))throw Error("Op must be null or a list");if(T.length===0)throw Error("Empty descent");G||z(T[0]);let C=1,S=0,b=0;for(let w=0;w<T.length;w++){const B=T[w];if(o(B!=null),Array.isArray(B)){const j=A(B,!1);if(S){const I=typeof b,H=typeof j;I===H?o(b<j,"descent keys are not in order"):o(I==="number"&&H==="string")}b=j,S++,C=3}else typeof B=="object"?(o(C===1,`Prev not scalar - instead ${C}`),M(B),C=2):(o(C!==3),z(B),o(r.isValidPathItem(B),"Invalid path key"),C=1)}return o(S!==1,"Operation makes multiple descents. Remove some []"),o(C===2||C===3),T[0]};A(_,!0),o(R.size===N.size,"Mismatched picks and drops in op");for(let T=0;T<R.size;T++)o(R.has(T)),o(N.has(T))}function X(_){let R=0,N=[];const M=r.writeCursor();return M.mergeTree(_,(A,T)=>{const G=ht(A);if(G){const C=p(A);O(T,G,G.normalize?G.normalize(C):C)}for(const C of["r","p","i","d"])if(A[C]!==void 0){const S=C==="p"||C==="d"?(W=A[C],N[W]==null&&(N[W]=R++),N[W]):A[C];T.write(C,S)}var W}),M.get()}function Gt(_,R){if(et(R),R===null)return _;const N=[];return function M(A,T){let G=A,W=0,C={root:A},S=0,b=C,w="root";function B(){for(;S<W;S++){let j=T[S];typeof j!="object"&&(o(m(b,w)),b=b[w]=c(b[w]),w=j)}}for(;W<T.length;W++){const j=T[W];if(Array.isArray(j)){const I=M(G,j);I!==G&&I!==void 0&&(B(),G=b[w]=I)}else if(typeof j=="object"){j.d!=null?(B(),G=f(b,w,N[j.d])):j.i!==void 0&&(B(),G=f(b,w,j.i));const I=ht(j);if(I)B(),G=b[w]=I.apply(G,p(j));else if(j.e!==void 0)throw Error("Subtype "+j.et+" undefined")}else G=E(G,j)}return C.root}(_=function M(A,T){const G=[];let W=0;for(;W<T.length;W++){const w=T[W];if(Array.isArray(w))break;typeof w!="object"&&(G.push(A),A=E(A,w))}for(let w=T.length-1;w>=W;w--)A=M(A,T[w]);for(--W;W>=0;W--){const w=T[W];if(typeof w!="object"){const B=G.pop();A=A===E(B,w)?B:A===void 0?d(B,w):(S=w,b=A,(C=c(C=B))[S]=b,C)}else h(w)&&(o(A!==void 0,"Cannot pick up or remove undefined"),w.p!=null&&(N[w.p]=A),A=void 0)}var C,S,b;return A}(_,R),R)}function St(_,R){_=_.slice(),et(R);const N=r.readCursor(R);let M,A,T=!1;const G=[];for(let C=0;;C++){const S=_[C],b=N.getComponent();if(b&&(b.r!==void 0?T=!0:b.p!=null&&(T=!1,M=b.p,A=C)),C>=_.length)break;let w=0;const B=r.advancer(N,void 0,(I,H)=>{h(H)&&w++});G.unshift(B);const j=B(S);if(typeof S=="number"&&(_[C]-=w),!j)break}if(G.forEach(C=>C.end()),T)return null;const W=()=>{let C=0;if(M!=null){const S=N.getPath();C=S.length,_=S.concat(_.slice(A))}for(;C<_.length;C++){const S=_[C],b=l(N),w=ht(b);if(w){const I=p(b);w.transformPosition&&(_[C]=w.transformPosition(_[C],I));break}let B=0;const j=r.advancer(N,(I,H)=>u(H)?~(I-B):I-B,(I,H)=>{u(H)&&B++})(S);if(typeof S=="number"&&(_[C]+=B),!j)break}};return M!=null?N.eachDrop(null,C=>{C===M&&W()}):W(),_}function ft(_,R){if(et(_),et(R),_==null)return R;if(R==null)return _;let N=0;const M=r.readCursor(_),A=r.readCursor(R),T=r.writeCursor(),G=[],W=[],C=[],S=[],b=[],w=[],B=new Set;M.traverse(null,I=>{I.p!=null&&(C[I.p]=M.clone())}),A.traverse(null,I=>{I.d!=null&&(S[I.d]=A.clone())});const j=r.writeCursor();return function I(H,gt,at,q,Et,ie,xt,Mt){o(gt||at);const pt=l(gt),Vt=l(at),qt=!!Vt&&Vt.r!==void 0,Re=!!pt&&pt.i!==void 0,Kt=pt?pt.d:null,Bt=Vt?Vt.p:null,oe=(ie||qt)&&Bt==null;if(Bt!=null)q=S[Bt],xt=W[Bt]=new r.WriteCursor;else if(Vt&&Vt.r!==void 0)q=null;else{const L=l(q);L&&L.d!=null&&(q=null)}const ot=l(q);if(Kt!=null)if(H=C[Kt],Mt=G[Kt]=new r.WriteCursor,oe)ie&&!qt&&Mt.write("r",!0);else{const L=b[Kt]=N++;xt.write("d",L)}else if(pt&&pt.i!==void 0)H=null;else{const L=l(H);L&&L.p!=null&&(H=null)}let y;Re?(o(Et===void 0),y=pt.i):y=Et;const V=(Bt==null?!Re||ie||qt:y===void 0)?null:xt.getComponent();if(Bt!=null){if(!(Et!==void 0||Re)){const L=Kt!=null?b[Kt]:N++;w[Bt]=L,Mt.write("p",L)}}else qt&&(Re||Et!==void 0||(Vt.r,Mt.write("r",Vt.r)));const k=oe?null:ht(pt),U=ht(ot);if((k||U)&&(k&&k.name,U&&U.name),k&&U){o(k===U);const L=p(pt),Y=p(ot),wt=k.compose(L,Y);O(xt,k,wt),B.add(ot)}else k?O(xt,k,p(pt)):U&&(O(xt,U,p(ot)),B.add(ot));const F=typeof y=="object"&&y!=null;let nt=!1,st=0,lt=0,vt=0,Nt=0,Rt=0;const Dt=r.advancer(q,(L,Y)=>u(Y)?Nt-L-1:L-Nt,(L,Y)=>{u(Y)&&Nt++}),tt=r.advancer(H,(L,Y)=>h(Y)?st-L-1:L-st,(L,Y)=>{h(Y)&&st++});if(r.eachChildOf(gt,at,(L,Y,wt)=>{let kt,le,Ce=L,Jt=L,$e=L;if(typeof L=="number"){let Ut=L+vt;le=Dt(Ut),Jt=Ut+Nt;let It=L+lt;kt=tt(It),u(l(le))&&(kt=null),Ce=It+st,$e=L+Rt,o(Ce>=0,"p1PickKey is negative"),o(Jt>=0,"p2DropKey is negative");const Zt=u(l(Y)),ae=h(l(wt));(Zt||ae&&!oe)&&Rt--,Zt&&lt--,ae&&vt--}else kt=tt(L),le=Dt(L);Mt.descend(Ce),xt.descend(Jt);const Le=F&&!u(l(Y))?y[$e]:void 0,ne=I(kt,Y,wt,le,Le,oe,xt,Mt);var se,$,mt;F&&!oe?Le!==ne&&(nt||(y=Array.isArray(y)?y.slice():Object.assign({},y),nt=!0),se=y,mt=ne,typeof($=$e)=="number"?(o(Array.isArray(se)),o($<se.length)):(o(!Array.isArray(se)),o(se[$]!==void 0)),mt===void 0?typeof $=="number"?se.splice($,1):delete se[$]:se[$]=mt):o(ne===void 0),xt.ascend(),Mt.ascend()}),tt.end(),Dt.end(),V!=null)V.i=y;else if(!ie&&!qt&&Bt==null)return y}(M,M.clone(),A,A.clone(),void 0,!1,T,j),T.reset(),T.mergeTree(j.get()),T.reset(),T.get(),G.map(I=>I.get()),W.map(I=>I.get()),M.traverse(T,(I,H)=>{const gt=I.p;if(gt!=null){const at=b[gt];at!=null&&H.write("p",at);const q=G[gt];q&&q.get(),q&&H.mergeTree(q.get())}else I.r!==void 0&&H.write("r",I.r)}),T.reset(),T.get(),A.traverse(T,(I,H)=>{const gt=I.d;if(gt!=null){const q=w[gt];q!=null&&H.write("d",q);const Et=W[gt];Et&&H.mergeTree(Et.get())}else I.i!==void 0&&H.write("i",I.i);const at=ht(I);at&&!B.has(I)&&O(H,at,p(I))}),T.get()}function Ct(_){if(_==null)return null;const R=new r.ReadCursor(_),N=new r.WriteCursor;let M;const A=[],T=[];return function G(W,C,S){const b=W.getComponent();let w,B=!1;if(b){b.p!=null&&(C.write("d",b.p),A[b.p]=W.clone()),b.r!==void 0&&C.write("i",b.r),b.d!=null&&(C.write("p",b.d),S=void 0),b.i!==void 0&&(S=w=b.i);const I=ht(b);I&&(S===void 0?(M||(M=new Set),M.add(b)):(p(b),S=I.apply(S,p(b)),B=!0))}let j=0;for(const I of W){C.descend(I);const H=typeof I=="number"?I-j:I,gt=E(S,H);u(W.getComponent())&&j++;const at=G(W,C,gt);if(S!==void 0&&at!==void 0){if(B||(B=!0,S=c(S)),!m(S,H))throw Error("Cannot modify child - invalid operation");S[H]=at}C.ascend()}if(w===void 0)return B?S:void 0;C.write("r",S)}(R,N,void 0),M&&(N.reset(),function G(W,C,S){const b=C.getComponent();if(b){const I=b.d;if(I!=null&&(W=A[I],S=T[I]=r.writeCursor()),M.has(b)){const H=ht(b);if(!H.invert)throw Error(`Cannot invert subtype ${H.name}`);O(S,H,H.invert(p(b)))}}let w=0,B=0;const j=r.advancer(W,(I,H)=>h(H)?w-I-1:I-w,(I,H)=>{h(H)&&w++});for(const I of C)if(typeof I=="number"){const H=I-B,gt=j(H),at=H+w;S.descend(at),G(gt,C,S),u(C.getComponent())&&B++,S.ascend()}else S.descend(I),G(j(I),C,S),S.ascend();j.end()}(R.clone(),R,N),T.length&&(N.reset(),R.traverse(N,(G,W)=>{const C=G.p;if(C!=null){const S=T[C];S&&S.get(),S&&W.mergeTree(S.get())}}))),N.get()}const Tt=(_,R)=>_.some(N=>typeof N=="object"&&(Array.isArray(N)?Tt(N,R):R(N)));function jt(_,R){if(_==null||!Tt(_,C=>{var S;return C.r!==void 0||((S=ht(C))===null||S===void 0?void 0:S.makeInvertible)!=null}))return _;const N=new r.ReadCursor(_),M=new r.WriteCursor;let A=!1;const T=[],G=[],W=(C,S,b)=>{const w=C.getComponent();let B=!1;if(w){w.d!=null&&S.write("d",w.d),w.i!==void 0&&S.write("i",w.i);const I=w.p;if(I!=null&&(T[I]=C.clone(),o(b!==void 0,"Operation picks up at an invalid key"),G[I]=b,S.write("p",w.p)),w.r!==void 0&&b===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const H=ht(w);H&&(H.makeInvertible?A=!0:O(S,H,p(w),!0))}let j=0;for(const I of C){S.descend(I);const H=typeof I=="number"?I-j:I,gt=E(b,H),at=W(C,S,gt);gt!==at&&(B||(B=!0,b=c(b)),at===void 0?(b=d(b,H),typeof I=="number"&&j++):b[H]=at),S.ascend()}return w&&(w.r!==void 0?(S.write("r",s.default(b)),b=void 0):w.p!=null&&(b=void 0)),b};return W(N,M,R),M.get(),A&&(M.reset(),function C(S,b,w,B,j){const I=b.getComponent();if(I){I.i!==void 0?(B=I.i,j=!0):I.d!=null&&(B=G[I.d],S=T[I.d],j=!1,I.d);let q=ht(I);if(q&&q.makeInvertible){const Et=p(I);O(w,q,q.makeInvertible(Et,B),!0)}}let H=0,gt=0;const at=r.advancer(S,(q,Et)=>h(Et)?H-q-1:q-H,(q,Et)=>{h(Et)&&H++});for(const q of b)if(typeof q=="number"){const Et=q-gt,ie=at(Et),xt=Et+H,Mt=E(B,j?Et:xt);w.descend(q),C(ie,b,w,Mt,j),u(b.getComponent())&&gt++,w.ascend()}else{const Et=E(B,q);w.descend(q),C(at(q),b,w,Et,j),w.ascend()}at.end()}(N.clone(),N,M,R,!1)),M.get()}function No(_,R){return Ct(jt(_,R))}const Pn=_=>{if(_==null)return null;const R=_.slice();for(let N=0;N<_.length;N++){const M=R[N];Array.isArray(M)&&(R[N]=Pn(M))}return R};function kn(_,R,N){o(N==="left"||N==="right","Direction must be left or right");const M=N==="left"?0:1;if(R==null)return{ok:!0,result:_};et(_),et(R);let A=null;const T=[],G=[],W=[],C=[],S=[],b=[],w=[],B=[],j=[],I=[],H=[],gt=[],at=[],q=[],Et=[];let ie=0;const xt=r.readCursor(_),Mt=r.readCursor(R),pt=r.writeCursor();if(function ot(y,V=null,k){const U=l(V);U&&(U.r!==void 0?k=V.clone():U.p!=null&&(k=null,b[U.p]=y.clone()));const F=y.getComponent();let nt;F&&(nt=F.p)!=null&&(S[nt]=V?V.clone():null,W[nt]=y.clone(),k&&(I[nt]=!0,j[nt]=k),U&&U.p!=null&&(q[nt]=U.p));const st=r.advancer(V);for(const lt of y)ot(y,st(lt),k);st.end()}(Mt,xt,null),function ot(y,V,k,U,F){const nt=k.getComponent();let st,lt=!1;nt&&((st=nt.d)!=null?(C[st]=k.clone(),U!=null&&(Et[U]==null&&(Et[U]=[]),Et[U].push(st)),y=S[st]||null,V=W[st]||null,I[st]?(F&&(H[st]=!0),F=j[st]||null):!F||M!==1&&q[st]!=null||A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.moveOp(V.getPath(),k.getPath())}),lt=!0):nt.i!==void 0&&(y=V=null,lt=!0,F&&A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.insertOp(k.getPath(),nt.i)})));const vt=l(y);vt&&(vt.r!==void 0?F=y.clone():vt.p!=null&&(vt.p,U=vt.p,F=null));const Nt=ht(nt);Nt&&F&&A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.editOp(k.getPath(),Nt,p(nt),!0)});let Rt=0,Dt=0;const tt=r.advancer(V,(Y,wt)=>h(wt)?Rt-Y-1:Y-Rt,(Y,wt)=>{h(wt)&&Rt++}),L=r.advancer(y);for(const Y of k)if(typeof Y=="number"){const wt=Y-Dt,kt=tt(wt);Dt+=+ot(L(wt+Rt),kt,k,U,F)}else{const wt=tt(Y);ot(L(Y),wt,k,U,F)}return tt.end(),L.end(),lt}(xt,Mt,Mt.clone(),null,null),C.map(ot=>ot&&ot.get()),A)return{ok:!1,conflict:A};H.map(ot=>!!ot);const Vt=[];let qt=null;(function ot(y,V,k,U,F){let nt=!1;const st=l(V);if(h(st)){const tt=st.p;tt!=null?(k=C[tt],U=gt[tt]=r.writeCursor(),nt=!0,F=null):(k=null,F=V.clone())}else u(l(k))&&(k=null);const lt=y.getComponent();if(lt){const tt=lt.p;tt!=null?(F&&(B[tt]=F),Vt[tt]=F||M===1&&nt?null:U.getComponent(),T[tt]=y.clone(),k&&(w[tt]=k.clone())):lt.r!==void 0&&(F||U.write("r",!0),(F||nt)&&(qt==null&&(qt=new Set),qt.add(lt)))}let vt=0,Nt=0;const Rt=r.advancer(V,void 0,(tt,L)=>{h(L)&&vt++}),Dt=r.advancer(k,(tt,L)=>u(L)?~(tt-Nt):tt-Nt,(tt,L)=>{u(L)&&Nt++});if(y)for(const tt of y)if(typeof tt=="string"){const L=Rt(tt),Y=Dt(tt);U.descend(tt),ot(y,L,Y,U,F),U.ascend()}else{const L=Rt(tt),Y=tt-vt,wt=h(l(L))?null:Dt(Y),kt=Y+Nt;o(kt>=0),U.descend(kt),ot(y,L,wt,U,F),U.ascend()}Rt.end(),Dt.end()})(xt,Mt,Mt.clone(),pt,null),pt.reset();let Re=[];if(function ot(y,V,k,U,F,nt){o(V);const st=V.getComponent();let lt=l(U),vt=!1;const Nt=($,mt,Ut)=>$?t.moveOp($.getPath(),mt.getPath()):t.insertOp(mt.getPath(),Ut.i);if(u(st)){const $=st.d;$!=null&&(G[$]=V.clone());const mt=$!=null?Vt[$]:null;let Ut=!1;if(st.i!==void 0||$!=null&&mt){let It;lt&&(lt.i!==void 0||(It=lt.d)!=null&&!I[It])&&(Ut=It!=null?$!=null&&$===q[It]:n.default(lt.i,st.i),Ut||It!=null&&M!==1&&q[It]!=null||A==null&&(A={type:i.ConflictType.DROP_COLLISION,op1:Nt($!=null?T[$]:null,V,st),op2:Nt(It!=null?W[It]:null,U,lt)})),Ut||(nt?A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:Nt($!=null?T[$]:null,V,st),op2:t.removeOp(nt.getPath())}):($!=null?(Re[ie]=$,F.write("d",mt.p=ie++)):F.write("i",s.default(st.i)),vt=!0))}else if($!=null&&!mt){const It=B[$];It&&(nt=It.clone())}$!=null?(y=T[$],k=b[$],U=w[$]):st.i!==void 0&&(y=k=null,Ut||(U=null))}else h(l(y))&&(y=k=U=null);const Rt=l(y),Dt=l(k);if(h(Dt)){const $=Dt.p;Dt.r!==void 0&&(!Rt||Rt.r===void 0)||I[$]?(U=null,nt=k.clone()):$!=null&&(U=C[$],M!==1&&q[$]!=null||((F=at[$])||(F=at[$]=r.writeCursor()),F.reset(),nt=null))}else!u(st)&&u(lt)&&(U=null);lt=U!=null?U.getComponent():null;const tt=ht(st);if(tt){const $=p(st);if(nt)A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.editOp(V.getPath(),tt,$,!0),op2:t.removeOp(nt.getPath())});else{const mt=ht(lt);let Ut;if(mt){if(tt!==mt)throw Error("Transforming incompatible types");const It=p(lt);Ut=tt.transform($,It,N)}else Ut=s.default($);O(F,tt,Ut)}}let L=0,Y=0,wt=0,kt=0,le=0,Ce=0,Jt=y!=null&&y.descendFirst(),$e=Jt;const Le=r.advancer(k,void 0,($,mt)=>{h(mt)&&wt++});let ne=U!=null&&U.descendFirst(),se=ne;for(const $ of V)if(typeof $=="number"){let mt;const Ut=u(V.getComponent()),It=$-Y;{let he;for(;Jt&&typeof(he=y.getKey())=="number";){he+=L;const Qt=y.getComponent(),De=h(Qt);if(he>It||he===It&&(!De||M===0&&Ut))break;if(De){L--;const Ie=Qt.p;q.includes(Ie),Qt.d,l(at[Qt.d]),h(l(at[Qt.d])),(Qt.r===void 0||qt&&qt.has(Qt))&&(Ie==null||!Vt[Ie]||M!==1&&q.includes(Ie))||le--}Jt=y.nextSibling()}mt=Jt&&he===It?y:null}const Zt=It-L;let ae=Le(Zt);const Hn=Zt-wt;let sn=null;{let he,Qt;for(;ne&&typeof(he=U.getKey())=="number";){Qt=he-kt;const De=U.getComponent(),Ie=u(De);if(Qt>Hn)break;if(Qt===Hn){if(!Ie){sn=U;break}{if(M===0&&Ut){sn=U;break}const Oe=ae&&h(ae.getComponent());if(M===0&&Oe)break}}if(Ie){const Oe=De.d;q[Oe],De.i===void 0&&(I[Oe]||q[Oe]!=null&&M!==1)?(I[Oe]||q[Oe]!=null&&M===0)&&(kt++,Ce--):kt++}ne=U.nextSibling()}}const Us=Hn+kt+le+Ce;o(Us>=0,"trying to descend to a negative index"),F.descend(Us),Ut&&(mt=ae=sn=null,Y++),ot(mt,V,ae,sn,F,nt)&&Ce++,F.ascend()}else{let mt;for(;Jt&&(mt=y.getKey(),typeof mt!="string"||!(mt>$||mt===$));)Jt=y.nextSibling();const Ut=Jt&&mt===$?y:null,It=Le($);let Zt;for(;ne&&(Zt=U.getKey(),typeof Zt!="string"||!(Zt>$||Zt===$));)ne=U.nextSibling();const ae=ne&&Zt===$?U:null;F.descend($),ot(Ut,V,It,ae,F,nt),F.ascend()}return Le.end(),$e&&y.ascend(),se&&U.ascend(),vt}(xt,xt.clone(),Mt,Mt.clone(),pt,null),A)return{ok:!1,conflict:A};pt.reset();const Kt=(ot,y,V)=>ot.traverse(y,(k,U)=>{k.d!=null&&V(k.d,ot,U)});(I.length||gt.length)&&(Kt(Mt,pt,(ot,y,V)=>{I[ot]&&!H[ot]&&V.write("r",!0),gt[ot]&&V.mergeTree(gt[ot].get())}),pt.reset());const Bt=[],oe=[];if((at.length||I.length)&&!A){const ot=r.readCursor(Pn(pt.get()));if(Kt(ot,null,(y,V)=>{Bt[y]=V.clone()}),at.forEach(y=>{y&&Kt(r.readCursor(y.get()),null,(V,k)=>{Bt[V]=k.clone()})}),function y(V,k,U,F,nt,st){const lt=l(k);if(lt&&h(lt))if(lt.p!=null){const L=lt.p;Bt[L].getPath(),U=Bt[L],F=oe[L]=r.writeCursor()}else lt.r!==void 0&&(U=null);else u(l(U))&&(U=null);const vt=V.getComponent();if(vt){let L;if((L=vt.d)!=null){const Y=at[L];Y&&(Y.get(),F.mergeTree(Y.get()),U=r.readCursor(Y.get()))}}let Nt=0,Rt=0;const Dt=r.advancer(k,void 0,(L,Y)=>{h(Y)&&Nt--}),tt=r.advancer(U,(L,Y)=>u(Y)?-(L-Rt)-1:L-Rt,(L,Y)=>{u(Y)&&Rt++});for(const L of V)if(typeof L=="number"){const Y=Dt(L),wt=L+Nt,kt=tt(wt),le=wt+Rt;F.descend(le),y(V,Y,kt,F),F.ascend()}else F.descend(L),y(V,Dt(L),tt(L),F),F.ascend();Dt.end(),tt.end()}(Mt,ot,ot.clone(),pt),pt.reset(),A)return{ok:!1,conflict:A};if(pt.get(),oe.length){const y=oe.map(k=>k?k.get():null),V=r.readCursor(Pn(pt.get()));if(Kt(V,pt,(k,U,F)=>{const nt=y[k];nt&&(F.mergeTree(nt),y[k]=null)}),y.find(k=>k)){const k=r.writeCursor(),U=r.writeCursor();let F=0,nt=0;y.forEach(st=>{st!=null&&Kt(r.readCursor(st),null,lt=>{const vt=Re[lt];k.writeMove(T[vt].getPath(),G[vt].getPath(),F++);const Nt=Et[vt];Nt&&Nt.forEach(Rt=>{I[Rt]||M!==1&&q[Rt]!=null||U.writeMove(W[Rt].getPath(),C[Rt].getPath(),nt++)})})}),A={type:i.ConflictType.BLACKHOLE,op1:k.get(),op2:U.get()}}}}return A?{ok:!1,conflict:A}:{ok:!0,result:pt.get()}}const Ts=_=>{const R=new Error("Transform detected write conflict");throw R.conflict=_,R.type=R.name="writeConflict",R};function Ao(_,R,N){const M=kn(_,R,N);if(M.ok)return M.result;Ts(M.conflict)}const Ue=_=>{const R=r.writeCursor();return r.readCursor(_).traverse(R,(N,M)=>{(u(N)||ht(N))&&M.write("r",!0)}),R.get()},bo=(_,R)=>{const{type:N,op1:M,op2:A}=_;switch(N){case i.ConflictType.DROP_COLLISION:return R==="left"?[null,Ue(A)]:[Ue(M),null];case i.ConflictType.RM_UNEXPECTED_CONTENT:let T=!1;return r.readCursor(M).traverse(null,G=>{G.r!==void 0&&(T=!0)}),T?[null,Ue(A)]:[Ue(M),null];case i.ConflictType.BLACKHOLE:return[Ue(M),Ue(A)];default:throw Error("Unrecognised conflict: "+N)}};function Ms(_,R,N,M){let A=null;for(;;){const T=kn(R,N,M);if(T.ok)return ft(A,T.result);{const{conflict:G}=T;_(G)||Ts(G);const[W,C]=bo(G,M);R=ft(X(R),W),N=ft(X(N),C),A=ft(A,C)}}}})(Li);(function(t){var e=Wt&&Wt.__createBinding||(Object.create?function(i,o,l,a){a===void 0&&(a=l),Object.defineProperty(i,a,{enumerable:!0,get:function(){return o[l]}})}:function(i,o,l,a){a===void 0&&(a=l),i[a]=o[l]}),n=Wt&&Wt.__exportStar||function(i,o){for(var l in i)l!=="default"&&!o.hasOwnProperty(l)&&e(o,i,l)};Object.defineProperty(t,"__esModule",{value:!0}),n(Li,t);var s=Rs;Object.defineProperty(t,"ReadCursor",{enumerable:!0,get:function(){return s.ReadCursor}}),Object.defineProperty(t,"WriteCursor",{enumerable:!0,get:function(){return s.WriteCursor}});var r=Cs;Object.defineProperty(t,"ConflictType",{enumerable:!0,get:function(){return r.ConflictType}})})($t);const Da=wa($t),ya=To({__proto__:null,default:Da},[$t]);var J=(t=>(t.RETAIN="r",t.INSERT="i",t.DELETE="d",t))(J||{});class ss{constructor(e){g(this,"_index",0);g(this,"_offset",0);this._actions=e}hasNext(){return this.peekLength()<Number.POSITIVE_INFINITY}next(e){e||(e=Number.POSITIVE_INFINITY);const n=this._actions[this._index];if(n){const s=this._offset,r=n.len;return e>=r-s?(e=r-s,this._index+=1,this._offset=0):this._offset+=e,n.t===J.DELETE||n.t===J.RETAIN&&n.body==null?D.deepClone({...n,len:e}):D.deepClone({...n,len:e,body:Je(n.body,s,s+e)})}else return{t:J.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 e=this._actions[this._index];return e?e.t:J.RETAIN}rest(){if(this.hasNext()){if(this._offset===0)return this._actions.slice(this._index);{const e=this._offset,n=this._index,s=this.next(),r=this._actions.slice(this._index);return this._offset=e,this._index=n,[s].concat(r)}}else return[]}}class Di{constructor(){g(this,"cursor",0)}reset(){return this.cursor=0,this}moveCursor(e){this.cursor+=e}moveCursorTo(e){this.cursor=e}}function yi(t,e,n){const{dataStream:s}=t,r=n,i=n+e,o=Oi(t,e,n),l=Si(t,e,n),a=Ni(t,e,n),c=Ai(t,e,n),h=bi(t,e,n),u=vi(t,e,n),d=wi(t,e,n);let f="";return s&&(t.dataStream=Zr(s,r,i),f=s.slice(r,i)),{dataStream:f,textRuns:o,paragraphs:l,sectionBreaks:a,customBlocks:c,tables:h,customRanges:u,customDecorations:d}}function xi(t,e,n,s){t.dataStream=Jr(t.dataStream,s,e.dataStream),Ei(t,e,n,s),_s(t,e,n,s),ga(t,e,n,s),pi(t,e,n,s),Ri(t,e,n,s),Ci(t,e,n,s),Ii(t,e,n,s)}function xa(t,e,n,s,r=Pt.COVER){return Ea(t,e,n,s,r)}function Pa(t,e,n){return e<=0?{dataStream:""}:yi(t,e,n)}function ka(t,e,n,s){n!==0&&xi(t,e,n,s)}function Ha(t,e){const n=new Di;return n.reset(),e.forEach(s=>{switch(s=D.deepClone(s),s.t){case J.RETAIN:{const{coverType:r,body:i,len:o}=s;i!=null&&xa(t,i,o,n.cursor,r),n.moveCursor(o);break}case J.INSERT:{const{body:r,len:i}=s;ka(t,r,i,n.cursor),n.moveCursor(i);break}case J.DELETE:{const{len:r}=s;Pa(t,r,n.cursor);break}default:throw new Error(`Unknown action type for action: ${s}.`)}}),t}function Bs(t){return Object.keys(t).length===1}const Xe=class Xe{constructor(){g(this,"_actions",[])}static apply(e,n){return Ha(e,n)}static compose(e,n){const s=new ss(e),r=new ss(n),i=new Xe;for(;s.hasNext()||r.hasNext();)if(r.peekType()===J.INSERT)i.push(r.next());else if(s.peekType()===J.DELETE)i.push(s.next());else{const o=Math.min(s.peekLength(),r.peekLength()),l=s.next(o),a=r.next(o);l.t===J.INSERT&&a.t===J.RETAIN?a.body==null?i.push(l):i.push({...l,body:ts(l.body,a.body,a.coverType)}):l.t===J.RETAIN&&a.t===J.RETAIN?l.body==null&&a.body==null?i.push(l.len!==Number.POSITIVE_INFINITY?l:a):l.body&&a.body?i.push({...l,body:ts(l.body,a.body,a.coverType)}):i.push(l.body?l:a):l.t===J.RETAIN&&a.t===J.DELETE?i.push(a):l.t===J.INSERT&&(a.t,J.DELETE)}return i.trimEndUselessRetainAction(),i.serialize()}static transform(e,n,s){throw new Error("transform is not implemented in TextX")}static isNoop(e){return e.length===0}static invert(e){const n=[];for(const s of e)if(s.t===J.INSERT)n.push({t:J.DELETE,len:s.len,line:0,body:s.body,segmentId:s.segmentId});else if(s.t===J.DELETE){if(s.body==null)throw new Error("Can not invert DELETE action without body property, makeInvertible must be called first.");n.push({t:J.INSERT,body:s.body,len:s.len,line:0,segmentId:s.segmentId})}else if(s.body!=null){if(s.oldBody==null)throw new Error("Can not invert RETAIN action without oldBody property, makeInvertible must be called first.");n.push({t:J.RETAIN,body:s.oldBody,oldBody:s.body,len:s.len,coverType:Pt.REPLACE,segmentId:s.segmentId})}else n.push(s);return n}static makeInvertible(e,n){const s=[];let r=0;for(const i of e){if(i.t===J.DELETE&&i.body==null){const o=Je(n,r,r+i.len,!1);i.len=o.dataStream.length,i.body=o}if(i.t===J.RETAIN&&i.body!=null){const o=Je(n,r,r+i.len,!0);i.oldBody={...o,dataStream:""},i.len=o.dataStream.length}s.push(i),i.t!==J.INSERT&&(r+=i.len)}return s}insert(e,n,s=""){const r={t:J.INSERT,body:n,len:e,line:0,segmentId:s};return this.push(r),this}retain(e,n="",s,r){const i={t:J.RETAIN,len:e,segmentId:n};return s!=null&&(i.body=s),r!=null&&(i.coverType=r),this.push(i),this}delete(e,n=""){const s={t:J.DELETE,len:e,line:0,segmentId:n};return this.push(s),this}serialize(){return this._actions}push(...e){if(e.length>1){for(const i of e)this.push(i);return this}let n=this._actions.length,s=this._actions[n-1];const r=D.deepClone(e[0]);if(r.t===J.RETAIN&&r.len===0&&r.body==null)return this;if(typeof s=="object"){if(s.t===J.DELETE&&r.t===J.DELETE)return s.len+=r.len,this;if(s.t===J.DELETE&&r.t===J.INSERT&&(n-=1,s=this._actions[n-1],s==null))return this._actions.unshift(r),this;if(s.t===J.RETAIN&&r.t===J.RETAIN&&s.body==null&&r.body==null)return s.len+=r.len,this;if(s.t===J.INSERT&&Bs(s.body)&&r.t===J.INSERT&&Bs(r.body))return s.len+=r.len,s.body.dataStream+=r.body.dataStream,this}return n===this._actions.length?this._actions.push(r):this._actions.splice(n,0,r),this}trimEndUselessRetainAction(){let e=this._actions[this._actions.length-1];for(;e&&e.t===J.RETAIN&&ba(e);)this._actions.pop(),e=this._actions[this._actions.length-1];return this}};g(Xe,"id","text-x"),g(Xe,"uri","https://github.com/dream-num/univer#text-x");let Ee=Xe;Object.defineProperty(Ee,"name",{value:"text-x"});const ye=class ye{static registerSubtype(e){var n;this._subTypes.has(e.name)&&((n=this._subTypes.get(e.name))==null?void 0:n.id)!==Ee.id||(this._subTypes.set(e.name,e),$t.type.registerSubtype(e))}static apply(e,n){if(!$t.type.isNoop(n))return $t.type.apply(e,n)}static compose(e,n){return $t.type.compose(e,n)}static transform(e,n,s){throw new Error("transform is not implemented in JsonX")}static invertWithDoc(e,n){return $t.type.invertWithDoc(e,n)}static isNoop(e){return $t.type.isNoop(e)}static getInstance(){return this._instance==null&&(this._instance=new ye),this._instance}removeOp(e,n){return $t.removeOp(e,n)}moveOp(e,n){return $t.moveOp(e,n)}insertOp(e,n){return $t.insertOp(e,n)}replaceOp(e,n,s){return $t.replaceOp(e,n,s)}editOp(e,n=["body"]){return $t.editOp(n,Ee.name,e)}};g(ye,"uri","https://github.com/dream-num/univer#json-x"),g(ye,"_subTypes",new Map),g(ye,"_instance",null);let ve=ye;ve.registerSubtype(Ee);const Os={id:"default_doc",documentStyle:{}};class Fa extends Mn{constructor(n){super();g(this,"type",Z.UNIVER_DOC);g(this,"snapshot");this.snapshot={...Os,...n}}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 zoomRatio(){var n;return((n=this.snapshot.settings)==null?void 0:n.zoomRatio)||1}resetDrawing(n,s){this.snapshot.drawings=n,this.snapshot.drawingsOrder=s}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getSnapshot(){return this.snapshot}updateDocumentId(n){this.snapshot.id=n}updateDocumentRenderConfig(n){const{documentStyle:s}=this.snapshot;s.renderConfig==null?s.renderConfig=n:s.renderConfig={...s.renderConfig,...n}}updateDocumentStyle(n){this.snapshot.documentStyle==null?this.snapshot.documentStyle=n:this.snapshot.documentStyle={...this.snapshot.documentStyle,...n}}updateDocumentDataMargin(n){const{t:s,l:r,b:i,r:o}=n,{documentStyle:l}=this.snapshot;s!=null&&(l.marginTop=s),r!=null&&(l.marginLeft=r),i!=null&&(l.marginBottom=i),o!=null&&(l.marginRight=o)}updateDocumentDataPageSize(n,s){const{documentStyle:r}=this.snapshot;if(!r.pageSize){n=n!=null?n:Number.POSITIVE_INFINITY,s=s!=null?s:Number.POSITIVE_INFINITY,r.pageSize={width:n,height:s};return}n!==void 0&&(r.pageSize.width=n),s!==void 0&&(r.pageSize.height=s)}updateDrawing(n,s){const{drawings:r}=this,{width:i,height:o,left:l,top:a}=s,c=r==null?void 0:r[n];if(!c)return;const h=c.docTransform;h.size.width=i,h.size.height=o,h.positionH.posOffset=l,h.positionV.posOffset=a}setZoomRatio(n=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:n}:this.snapshot.settings.zoomRatio=1}}class we extends Fa{constructor(n){var r;super(D.isEmptyObject(n)?va():n);g(this,"_unitId");g(this,"headerModelMap",new Map);g(this,"footerModelMap",new Map);const s=6;this._unitId=(r=this.snapshot.id)!=null?r:D.generateRandomId(s),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(n=>{n.dispose()}),this.footerModelMap.forEach(n=>{n.dispose()})}getDrawings(){return this.snapshot.drawings}getDrawingsOrder(){return this.snapshot.drawingsOrder}getCustomRanges(){var n;return(n=this.snapshot.body)==null?void 0:n.customRanges}getCustomDecorations(){var n;return(n=this.snapshot.body)==null?void 0:n.customDecorations}getRev(){var n;return(n=this.snapshot.rev)!=null?n:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(n){if(n.id&&n.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Os,...n},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(n){if(n!=null){if(this.headerModelMap.has(n))return this.headerModelMap.get(n);if(this.footerModelMap.has(n))return this.footerModelMap.get(n)}return this}getUnitId(){return this._unitId}apply(n){if(!ve.isNoop(n))return this.snapshot=ve.apply(this.snapshot,n),n!=null&&n.some(s=>Array.isArray(s)&&((s==null?void 0:s[0])==="headers"||(s==null?void 0:s[0])==="footers"))&&(this.headerModelMap.clear(),this.footerModelMap.clear(),this._initializeHeaderFooterModel()),this.snapshot}sliceBody(n,s){const r=this.getBody();if(r!=null)return Je(r,n,s)}_initializeHeaderFooterModel(){const{headers:n,footers:s}=this.getSnapshot();if(n)for(const r in n){const i=n[r];this.headerModelMap.set(r,new we(i))}if(s)for(const r in s){const i=s[r];this.footerModelMap.set(r,new we(i))}}updateDocumentId(n){super.updateDocumentId(n),this._unitId=n}}const Pi=ut.createIdentifier("univer.config-service");class ki{constructor(){g(this,"_config",new Map)}getConfig(e){return this._config.get(e)}setConfig(e,n){this._config.set(e,n)}deleteConfig(e){this._config.delete(e)}}class Hi extends yt{constructor(){super(...arguments);g(this,"_error$",new rt.Subject);g(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(n){this._error$.next({errorKey:n})}}class Fi{constructor(e={}){g(this,"_styles");g(this,"_cacheMap",new si(1e5));this._styles=e,this._generateCacheMap()}each(e){return Object.entries(this._styles).forEach(e),this}search(e,n){if(this._cacheMap.has(n))return this._cacheMap.get(n);const s=this._getExistingStyleId(e);return s||"-1"}get(e){return typeof e!="string"?e:(e=String(e),this._styles[e])}add(e,n){const s=D.generateRandomId(6);return this._styles[s]=e,this._cacheMap.set(n,s),s}setValue(e){if(e==null)return;const n=JSON.stringify(e),s=this.search(e,n);return s!=="-1"?s:this.add(e,n)}toJSON(){return this._styles}getStyleByCell(e){let n;e&&D.isObject(e.s)?n=e.s:n=(e==null?void 0:e.s)&&this.get(e.s);const s=e==null?void 0:e.interceptorStyle;return s?{...n,...s}:n}_generateCacheMap(){const{_styles:e,_cacheMap:n}=this;for(const s in e){const r=JSON.stringify(e[s]);n.set(r,s)}}_getExistingStyleId(e){const{_styles:n}=this;for(const s in n)if(D.diffValue(n[s],e))return s;return null}}class $a{constructor(e,n){g(this,"_columnData",{});this._config=e,this._columnData=n}getColumnData(){return this._columnData}getColVisible(e){const{_columnData:n}=this,s=n[e];return s?s.hd!==K.TRUE:!0}getHiddenCols(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getColVisible(o);r&&l?(r=!1,s.push({rangeType:it.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!l&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:n,rangeType:it.COLUMN}),s}getVisibleCols(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getColVisible(o);r&&!l?(r=!1,s.push({rangeType:it.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&l&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:n,rangeType:it.COLUMN}),s}getColumnDatas(e,n){const s={};let r=0;for(let i=e;i<e+n;i++){const o=this.getColumnOrCreate(i);s[r]=o,r++}return s}getSize(){return _e(this._columnData)}getColumnWidth(e){const{_columnData:n}=this,s=this._config;let r=0;return r=(n[e]||{hd:K.FALSE,w:s.defaultColumnWidth}).w||s.defaultColumnWidth,r}getColumn(e){const n=this._columnData[e];if(n)return n}getColumnOrCreate(e){const{_columnData:n}=this,s=this._config,r=n[e];if(r)return r;const i={w:s.defaultColumnWidth,hd:K.FALSE};return this._columnData[e]=i,i}}class Wa{constructor(e,n,s){g(this,"_rowData");this._config=e,this._viewModel=n,this._rowData=s}getRowData(){return this._rowData}getRowDatas(e,n){const s={};let r=0;for(let i=e;i<e+n;i++){const o=this.getRowOrCreate(i);s[r]=o,r++}return s}getRowHeight(e,n=1){const{_rowData:s}=this,r=this._config;let i=0;for(let o=0;o<n;o++){const l=s[o+e]||{hd:K.FALSE,h:r.defaultRowHeight},{ia:a,ah:c,h=r.defaultRowHeight}=l;i+=(a==null||a===K.TRUE)&&typeof c=="number"?c:h}return i}getRow(e){return this._rowData[e]}getRowOrCreate(e){const{_rowData:n}=this,s=n[e];if(s)return s;const r=this._config,i={hd:K.FALSE,h:r.defaultRowHeight};return n[e]=i,i}getHiddenRows(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getRowRawVisible(o);r&&l?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:it.ROW})):!r&&!l&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:n,startColumn:0,endColumn:0,rangeType:it.ROW}),s}getVisibleRows(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getRowRawVisible(o);r&&!l?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:it.ROW})):!r&&l&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:n,startColumn:0,endColumn:0,rangeType:it.ROW}),s}getRowRawVisible(e){const n=this.getRow(e);return n?n.hd!==K.TRUE:!0}getSize(){return _e(this._rowData)}}const Ba="DEFAULT_WORKSHEET_ROW_COUNT",$i=1e3,Ga="DEFAULT_WORKSHEET_COLUMN_COUNT",Wi=20,ja="DEFAULT_WORKSHEET_ROW_HEIGHT",Bi=24,Va="DEFAULT_WORKSHEET_COLUMN_WIDTH",Gi=88,Ka="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",ji=46,Ya="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",Vi=20;function Ki(t){const e={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:K.FALSE,rowCount:$i,columnCount:Wi,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Gi,defaultRowHeight:Bi,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:K.TRUE,rowHeader:{width:ji,hidden:K.FALSE},columnHeader:{height:Vi,hidden:K.FALSE},selections:["A1"],rightToLeft:K.FALSE};return Object.keys(e).forEach(n=>{const s=n;typeof t[s]>"u"&&(t[s]=e[s])}),t}class Yi extends yt{constructor(n){super();g(this,"_cellContentInterceptor",null);g(this,"_rowFilteredInterceptor",null);this.getRawCell=n}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(n,s){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(n,s):this.getRawCell(n,s)}getRowFiltered(n){var s,r;return(r=(s=this._rowFilteredInterceptor)==null?void 0:s.getRowFiltered(n))!=null?r:!1}registerCellContentInterceptor(n){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=n,bt(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(n){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=n,bt(()=>this._rowFilteredInterceptor=null)}}class Ze{constructor(e,n,s){g(this,"_sheetId");g(this,"_snapshot");g(this,"_cellData");g(this,"_rowManager");g(this,"_columnManager");g(this,"_viewModel");var l;this.unitId=e,this._styles=s,this._snapshot=Ki(n);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(l=this._snapshot.id)!=null?l:D.generateRandomId(6),this._cellData=new ee(o),this._viewModel=new Yi((a,c)=>this.getCellRaw(a,c)),this._rowManager=new Wa(this._snapshot,this._viewModel,i),this._columnManager=new $a(this._snapshot,r)}__interceptViewModel(e){e(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const e=this.getCellMatrix(),n=this.getMergeData();let s=-1,r=-1,i=-1,o=-1,l=!1,a=!1;return e.forEach((c,h)=>{Object.keys(h).forEach(u=>{const d=+u,f=e.getValue(c,d),m=f!=null&&f.s?this._styles.get(f.s):null,E=(m==null?void 0:m.bd)&&(m.bd.b||m.bd.l||m.bd.r||m.bd.t||m.bd.bc_tr||m.bd.bl_tr||m.bd.ml_tr||m.bd.tl_bc||m.bd.tl_br||m.bd.tl_mr);(f&&(f.v||f.p)||m!=null&&m.bg||E)&&(l?s=Math.min(s,c):(s=c,l=!0),r=Math.max(r,c),a?i=Math.min(i,d):(a=!0,i=d),o=Math.max(o,d))})}),n.forEach(c=>{l?s=Math.min(s,c.startRow):(s=c.startRow,l=!0),r=Math.max(r,c.endRow),a?i=Math.min(i,c.startColumn):(i=c.startColumn,l=!0),o=Math.max(o,c.endColumn)}),!l||!a?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:e}=this,n=D.deepClone(e);return new Ze(this.unitId,n,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(e,n){const s=this._snapshot.mergeData;for(let r=0;r<s.length;r++){const i=s[r];if(me.intersects({startRow:e,startColumn:n,endRow:e,endColumn:n},i))return i}return null}getCell(e,n){return e<0||n<0?null:this._viewModel.getCell(e,n)}getCellRaw(e,n){return this.getCellMatrix().getValue(e,n)}getRowFiltered(e){return this._viewModel.getRowFiltered(e)}getMatrixWithMergedCells(e,n,s,r,i=!1){const o=this.getCellMatrix(),l=this._snapshot.mergeData.filter(c=>me.intersects({startRow:e,startColumn:n,endRow:s,endColumn:r},c)),a=new ee;return Zn(e,s,n,r).forEach((c,h)=>{const u=i?this.getCellRaw(c,h):this.getCell(c,h);u&&a.setValue(c,h,u)}),l.forEach(c=>{const{startColumn:h,startRow:u,endColumn:d,endRow:f}=c;Zn(u,f,h,d).forEach((m,E)=>{m===u&&E===h&&a.setValue(m,E,{...o.getValue(m,E),rowSpan:f-u+1,colSpan:d-h+1}),(m!==u||E!==h)&&a.realDeleteValue(m,E)})}),a}getRange(e,n,s,r){return typeof e=="object"?new He(this,e,{getStyles:()=>this._styles}):new He(this,{startRow:e,startColumn:n,endColumn:r||n,endRow:s||e},{getStyles:()=>this._styles})}getScrollLeftTopFromSnapshot(){return{scrollLeft:this._snapshot.scrollLeft,scrollTop:this._snapshot.scrollTop}}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:e}=this,{columnCount:n}=e;return n}getMaxRows(){const{_snapshot:e}=this,{rowCount:n}=e;return n}getRowCount(){return this._snapshot.rowCount}setRowCount(e){this._snapshot.rowCount=e}getColumnCount(){return this._snapshot.columnCount}setColumnCount(e){this._snapshot.columnCount=e}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:e}=this,{showGridlines:n}=e;return n===0}getTabColor(){const{_snapshot:e}=this,{tabColor:n}=e;return n}getColumnWidth(e){return this.getColumnManager().getColumnWidth(e)}getRowHeight(e){return this._viewModel.getRowFiltered(e)?0:this.getRowManager().getRowHeight(e)}getRowVisible(e){return this._viewModel.getRowFiltered(e)?!1:this.getRowRawVisible(e)}getRowRawVisible(e){return this.getRowManager().getRowRawVisible(e)}getHiddenRows(e,n){const s=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(e,n);return r.forEach(i=>i.endColumn=s),r}getColVisible(e){return this._columnManager.getColVisible(e)}getHiddenCols(e,n){const s=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(e,n);return r.forEach(i=>i.endRow=s),r}getVisibleRows(){const e=this.getRowCount();return this._rowManager.getVisibleRows(0,e-1)}getVisibleCols(){const e=this.getColumnCount();return this._columnManager.getVisibleCols(0,e-1)}isRightToLeft(){const{_snapshot:e}=this,{rightToLeft:n}=e;return n}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(e){return e&&(e.v!==void 0||e.f!==void 0||e.p!==void 0)}iterateByRow(e,n=!0){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=e,l=this;return{[Symbol.iterator]:()=>{let a=s,c=r;return{next(){for(;;){if(c>o&&(a+=1,c=r),a>i)return{done:!0,value:void 0};const h=l.getCell(a,c),u=!h,d=l.getMergedCell(a,c);if(d){if(a!==d.startRow||c!==d.startColumn){c=d.endColumn+1;continue}if(u&&n){c=d.endColumn+1;continue}const m={row:a,col:c,value:h};return m.colSpan=d.endColumn-d.startColumn+1,m.rowSpan=d.endRow-d.startRow+1,c=d.endColumn+1,{done:!1,value:m}}if(u&&n)c+=1;else{const f={row:a,col:c,value:h};return c+=1,{done:!1,value:f}}}}}}}}iterateByColumn(e,n=!0,s=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:l}=e,a=this;return{[Symbol.iterator]:()=>{let c=r,h=i;return{next(){for(;;){if(c>o&&(h+=1,c=r),h>l)return{done:!0,value:void 0};const u=a.getMergedCell(c,h);if(u){const m=c!==u.startRow,E=m||h!==u.startColumn;if(s&&E||!s&&m){c=u.endRow+1;continue}const P=a.getCell(u.startRow,u.startColumn);if(!P&&n){c=u.endRow+1;continue}const Q={row:c,col:u.startColumn,value:P};return Q.colSpan=u.endColumn-u.startColumn+1,Q.rowSpan=u.endRow-u.startRow+1,c=u.endRow+1,{done:!1,value:Q}}const d=a.getCell(c,h);if(!d&&n)c+=1;else{const m={row:c,col:h,value:d};return c+=1,{done:!1,value:m}}}}}}}}}function za(t){var s,r;if(!t)return"";const e=(r=(s=t.p)==null?void 0:s.body)==null?void 0:r.dataStream;if(e)return e;const n=t.v;return typeof n=="string"?t.t===Ae.BOOLEAN?n.toUpperCase():n.replace(/[\r\n]/g,""):typeof n=="number"?t.t===Ae.BOOLEAN?n?"TRUE":"FALSE":n.toString():typeof n=="boolean"?n?"TRUE":"FALSE":""}const Xa="0.2.1";function qa(t="",e=Te.ZH_CN,n=""){return{id:t,sheetOrder:[],name:n,appVersion:Xa,locale:e,styles:{},sheets:{},resources:[]}}var Ja=Object.defineProperty,Za=Object.getOwnPropertyDescriptor,Qa=(t,e,n,s)=>{for(var r=s>1?void 0:s?Za(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&Ja(e,n,r),r},tu=(t,e)=>(n,s)=>e(n,s,t);function eu(t,e){return`${t.getUnitId()}|${e.getSheetId()}`}exports.Workbook=class extends Mn{constructor(n={},s){super();g(this,"type",Z.UNIVER_SHEET);g(this,"_sheetCreated$",new rt.Subject);g(this,"sheetCreated$",this._sheetCreated$.asObservable());g(this,"_sheetDisposed$",new rt.Subject);g(this,"sheetDisposed$",this._sheetDisposed$.asObservable());g(this,"_activeSheet$",new rt.BehaviorSubject(null));g(this,"activeSheet$",this._activeSheet$.asObservable());g(this,"_worksheets");g(this,"_styles");g(this,"_snapshot");g(this,"_unitId");g(this,"_count");g(this,"_name$");g(this,"name$");this._logService=s;const r=qa();D.isEmptyObject(n)?this._snapshot=r:this._snapshot=D.commonExtend(r,n);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=D.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new Fi(i),this._count=1,this._worksheets=new Map,this._name$=new rt.BehaviorSubject(n.name||""),this.name$=this._name$.asObservable(),this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._name$.getValue()}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete(),this._name$.complete()}save(){return D.deepClone(this._snapshot)}static isIRangeType(n){return typeof n=="string"||"startRow"in n||"row"in n}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}setName(n){this._name$.next(n),this._snapshot.name=n}getUnitId(){return this._unitId}getRev(){var n;return(n=this._snapshot.rev)!=null?n:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(n,s,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[n])return!1;i[n]=r,o.splice(s,0,n);const l=new Ze(this._unitId,r,this._styles);return this._worksheets.set(n,l),this._sheetCreated$.next(l),!0}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(n){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>r===n)}getActiveSheet(){return this._activeSheet}ensureActiveSheet(){const n=this.getActiveSheet();if(n)return n;const s=this._snapshot.sheetOrder;for(let i=0,o=s.length;i<o;i++){const l=this._worksheets.get(s[i]);if(l&&l.isSheetHidden()!==K.TRUE)return this.setActiveSheet(l),l}const r=this._worksheets.get(s[0]);return this.setActiveSheet(r),r}setActiveSheet(n){this._activeSheet$.next(n)}removeSheet(n){var r;const s=this._worksheets.get(n);return s?(((r=this._activeSheet)==null?void 0:r.getSheetId())===n&&this.setActiveSheet(null),this._worksheets.delete(n),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(n),1),delete this._snapshot.sheets[n],this._sheetDisposed$.next(s),!0):!1}getActiveSheetIndex(){const{sheetOrder:n}=this._snapshot;return n.findIndex(s=>this._worksheets.get(s)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:n}=this._snapshot;return n.map(s=>this._worksheets.get(s))}getSheetsName(){const{sheetOrder:n}=this._snapshot,s=[];return n.forEach(r=>{const i=this._worksheets.get(r);i&&s.push(i.getName())}),s}getSheetIndex(n){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>n.getSheetId()===r)}getSheetBySheetName(n){const{sheetOrder:s}=this._snapshot,r=s.find(i=>this._worksheets.get(i).getName()===n);return this._worksheets.get(r)}getSheetBySheetId(n){return this._worksheets.get(n)}getSheetByIndex(n){const{sheetOrder:s}=this._snapshot;return this._worksheets.get(s[n])}getHiddenWorksheets(){return this.getSheets().filter(n=>n.getConfig().hidden===K.TRUE).map(n=>n.getConfig().id)}getUnhiddenWorksheets(){return this.getSheets().filter(n=>n.getConfig().hidden!==K.TRUE).map(n=>n.getConfig().id)}load(n){this._snapshot=n}checkSheetName(n){return this.getSheetsName().includes(n)}uniqueSheetName(n="Sheet1"){let s=n;for(;this.checkSheetName(s);)s=n+this._count,this._count++;return s}generateNewSheetName(n){let s=n+this._count;for(;this.checkSheetName(s);)s=n+this._count,this._count++;return s}_passWorksheetSnapshots(){const{_snapshot:n,_worksheets:s}=this,{sheets:r,sheetOrder:i}=n;if(D.isEmptyObject(r)){const o=D.generateRandomId();r[o]={id:o}}for(const o in r){const l=r[o],{name:a}=l;l.name=this.uniqueSheetName(a),l.name!==a&&this._logService.debug("[Workbook]",`The worksheet name ${a} is duplicated, we changed it to ${l.name}. Please fix the problem in your snapshot.`);const c=new Ze(this._unitId,l,this._styles);s.set(o,c),i.includes(o)||i.push(o)}this.ensureActiveSheet()}};exports.Workbook=Qa([tu(1,pe)],exports.Workbook);class Ss extends Mn{constructor(n){var s;super();g(this,"type",Z.UNIVER_SLIDE);g(this,"_snapshot");g(this,"_unitId");this._snapshot={...oi,...n},this._unitId=(s=this._snapshot.id)!=null?s:D.generateRandomId(6)}getContainer(){return this._snapshot.container}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var n;return(n=this._snapshot.body)==null?void 0:n.pages}getPageOrder(){var n;return(n=this._snapshot.body)==null?void 0:n.pageOrder}getPage(n){const s=this.getPages();return s==null?void 0:s[n]}getElementsByPage(n){var s;return(s=this.getPage(n))==null?void 0:s.pageElements}getElement(n,s){var r;return(r=this.getElementsByPage(n))==null?void 0:r[s]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:as.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const Ke="FOCUSING_SHEET",gn="FOCUSING_DOC",_n="FOCUSING_SLIDE",nu="FOCUSING_EDITOR_BUT_HIDDEN",zi="EDITOR_ACTIVATED",su="FOCUSING_EDITOR_INPUT_FORMULA",Xi="FOCUSING_FORMULA_EDITOR",ru="FOCUSING_UNIVER_EDITOR",iu="FOCUSING_EDITOR_INPUT_FORMULA",ou="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE",lu="FOCUSING_COMMON_DRAWINGS";var au=Object.defineProperty,uu=Object.getOwnPropertyDescriptor,cu=(t,e,n,s)=>{for(var r=s>1?void 0:s?uu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&au(e,n,r),r},Gs=(t,e)=>(n,s)=>e(n,s,t);const Fe=ut.createIdentifier("univer.current");exports.UniverInstanceService=class extends yt{constructor(n,s){super();g(this,"_unitsByType",new Map);g(this,"_createHandler");g(this,"_ctorByType",new Map);g(this,"_currentUnits",new Map);g(this,"_currentUnits$",new rt.BehaviorSubject(this._currentUnits));g(this,"currentUnits$",this._currentUnits$.asObservable());g(this,"_unitAdded$",new rt.Subject);g(this,"unitAdded$",this._unitAdded$.asObservable());g(this,"_unitDisposed$",new rt.Subject);g(this,"unitDisposed$",this._unitDisposed$.asObservable());g(this,"_focused$",new rt.BehaviorSubject(null));g(this,"focused$",this._focused$.asObservable());this._injector=n,this._contextService=s}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(n){this._createHandler=n}createUnit(n,s){return this._createHandler(n,s,this._ctorByType.get(n))}registerCtorForType(n,s){return this._ctorByType.set(n,s),{dispose:()=>{this._ctorByType.delete(n)}}}getCurrentTypeOfUnit$(n){return this.currentUnits$.pipe(rt.map(s=>{var r;return(r=s.get(n))!=null?r:null}),rt.distinctUntilChanged())}getCurrentUnitForType(n){return this._currentUnits.get(n)}setCurrentUnitForType(n){const s=this._getUnitById(n);if(!s)throw new Error(`[UniverInstanceService]: no document with unitId ${n}!`);this._currentUnits.set(s[1],s[0]),this._currentUnits$.next(this._currentUnits)}_removeCurrentUnitForType(n){this._currentUnits.set(n,null),this._currentUnits$.next(this._currentUnits)}getTypeOfUnitAdded$(n){return this._unitAdded$.pipe(rt.filter(s=>s.type===n))}__addUnit(n){const s=n.type;this._unitsByType.has(s)||this._unitsByType.set(s,[]),this._unitsByType.get(s).push(n),this._unitAdded$.next(n),this.setCurrentUnitForType(n.getUnitId())}getTypeOfUnitDisposed$(n){return this.unitDisposed$.pipe(rt.filter(s=>s.type===n))}getUnit(n,s){var i;const r=(i=this._getUnitById(n))==null?void 0:i[0];return s&&(r==null?void 0:r.type)!==s?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(Z.UNIVER_DOC)}getUniverDocInstance(n){return this.getUnit(n,Z.UNIVER_DOC)}getUniverSheetInstance(n){return this.getUnit(n,Z.UNIVER_SHEET)}getAllUnitsForType(n){var s;return(s=this._unitsByType.get(n))!=null?s:[]}changeDoc(n,s){const r=this.getAllUnitsForType(Z.UNIVER_DOC),i=r.find(o=>o.getUnitId()===n);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(s)}get focused(){var s;const n=this._focused$.getValue();return n?(s=this._getUnitById(n))==null?void 0:s[0]:null}focusUnit(n){this._focused$.next(n),this.focused instanceof exports.Workbook?(this._contextService.setContextValue(gn,!1),this._contextService.setContextValue(Ke,!0),this._contextService.setContextValue(_n,!1)):this.focused instanceof we?(this._contextService.setContextValue(gn,!0),this._contextService.setContextValue(Ke,!1),this._contextService.setContextValue(_n,!1)):this.focused instanceof Ss&&(this._contextService.setContextValue(gn,!1),this._contextService.setContextValue(Ke,!1),this._contextService.setContextValue(_n,!0))}getFocusedUnit(){return this.focused}getUnitType(n){const s=this._getUnitById(n);if(!s)throw new Error(`[UniverInstanceService]: No document with unitId ${n}`);return s[1]}disposeUnit(n){const s=this._getUnitById(n);if(!s)return!1;const[r,i]=s,o=this._unitsByType.get(i),l=o.indexOf(r);return o.splice(l,1),this._removeCurrentUnitForType(i),this._focused$.next(null),this._unitDisposed$.next(r),!0}_getUnitById(n){for(const[s,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===n);if(i)return[i,s]}}};exports.UniverInstanceService=cu([Gs(0,ut.Inject(ut.Injector)),Gs(1,Qe)],exports.UniverInstanceService);var Ot=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(Ot||{});const hu={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},mn=new Map;function qi(t,e){return function(r){Un(t,e)}}function Un(t,e){mn.has(t)||mn.set(t,[]),mn.get(t).push(e)}var du=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,Ji=(t,e,n,s)=>{for(var r=s>1?void 0:s?fu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&du(e,n,r),r},rs=(t,e)=>(n,s)=>e(n,s,t);exports.LifecycleService=class extends yt{constructor(n){super();g(this,"_lifecycle$",new rt.BehaviorSubject(Ot.Starting));g(this,"lifecycle$",this._lifecycle$.asObservable());g(this,"_lock",!1);this._logService=n,this._reportProgress(Ot.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(n){if(n<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(n!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(n),this._lifecycle$.next(n),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new rt.Observable(n=>{this.stage===Ot.Starting||(this.stage===Ot.Ready?n.next(Ot.Starting):this.stage===Ot.Rendered?(n.next(Ot.Starting),n.next(Ot.Ready)):(n.next(Ot.Starting),n.next(Ot.Ready),n.next(Ot.Rendered))),this._lifecycle$.subscribe(s=>{n.next(s),s===Ot.Steady&&n.complete()})})}_reportProgress(n){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${hu[n]}".`)}};exports.LifecycleService=Ji([rs(0,pe)],exports.LifecycleService);exports.LifecycleInitializerService=class extends yt{constructor(n,s){super();g(this,"_seenTokens",new Set);this._lifecycleService=n,this._injector=s}initModulesOnStage(n){var s;(s=mn.get(n))==null||s.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}};exports.LifecycleInitializerService=Ji([rs(0,ut.Inject(exports.LifecycleService)),rs(1,ut.Inject(ut.Injector))],exports.LifecycleInitializerService);class Ye extends yt{constructor(){super();g(this,"_currentLocale$",new rt.BehaviorSubject(Te.ZH_CN));g(this,"currentLocale$",this._currentLocale$.asObservable());g(this,"_locales",null);g(this,"localeChanged$",new rt.Subject);g(this,"t",(n,...s)=>{if(!this._locales)throw new Error("[LocaleService]: Locale not initialized");const r=n.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return s.forEach((l,a)=>{o=o.replace(`{${a}}`,l)}),o}else return n});this.disposeWithMe(bt(()=>this.localeChanged$.complete()))}get _currentLocale(){return this._currentLocale$.value}load(n){var s;this._locales=D.deepMerge((s=this._locales)!=null?s:{},n)}setLocale(n){this._currentLocale$.next(n),this.localeChanged$.next()}getLocales(){var n;return(n=this._locales)==null?void 0:n[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(n,s){const r=s.shift();if(r&&n&&r in n){const i=n[r];return s.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,s):i}return null}}var Ns=(t=>(t.INIT="init",t.FETCHING="fetching",t.DONE="done",t))(Ns||{});const As=ut.createIdentifier("univer.permission-service");Un(Ot.Starting,As);class Zi extends yt{constructor(){super(...arguments);g(this,"_permissionPointMap",new Map);g(this,"_permissionPointUpdate$",new rt.Subject);g(this,"permissionPointUpdate$",this._permissionPointUpdate$.asObservable())}deletePermissionPoint(n){const s=this._permissionPointMap.get(n);s&&(s.complete(),this._permissionPointMap.delete(n))}addPermissionPoint(n){const s=n instanceof rt.BehaviorSubject,r=s?n.getValue():n;if(!r.id)return!1;if(this._permissionPointMap.get(r.id))throw new Error(`${r.id} PermissionPoint already exists`);return this._permissionPointMap.set(r.id,s?n:new rt.BehaviorSubject(r)),this._permissionPointUpdate$.next(r),!0}updatePermissionPoint(n,s){const r=this._permissionPointMap.get(n);if(!r)return;const i=r.getValue();i.value=s,i.status=Ns.DONE,r.next({...i}),this._permissionPointUpdate$.next(i)}clearPermissionMap(){this._permissionPointMap.clear()}getPermissionPoint(n){const s=this._permissionPointMap.get(n);if(s)return s.getValue()}getPermissionPoint$(n){const s=this._permissionPointMap.get(n);if(s)return s}composePermission$(n){const s=n.map(r=>{var o;const i=(o=this._permissionPointMap)==null?void 0:o.get(r);if(!i)throw new Error(`[PermissionService]: ${r} permissionPoint does not exist!`);return i.asObservable()});return rt.combineLatest(s).pipe(cn.map(r=>r))}composePermission(n){return n.map(r=>{var o;const i=(o=this._permissionPointMap)==null?void 0:o.get(r);if(!i)throw new Error(`[PermissionService]: ${r} permissionPoint does not exist!`);return i.getValue()})}getAllPermissionPoint(){const n=new Map;return this._permissionPointMap.forEach((s,r)=>{n.set(r,s)}),n}}class Qi extends yt{constructor(){super(...arguments);g(this,"_resourceMap",new Map);g(this,"_register$",new rt.Subject);g(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(n){return this.getAllResourceHooks().map(i=>{const o=i.toJson(n);return{name:i.pluginName,data:o}})}getResourcesByType(n,s){return this.getAllResourceHooks().filter(o=>o.businesses.includes(s)).map(o=>{const l=o.toJson(n);return{name:o.pluginName,data:l}})}registerPluginResource(n){const s=n.pluginName;if(this._resourceMap.has(s))throw new Error(`the pluginName is registered {${s}}`);return this._resourceMap.set(s,n),this._register$.next(n),bt(()=>this._resourceMap.delete(s))}disposePluginResource(n){this._resourceMap.delete(n)}loadResources(n,s){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=s==null?void 0:s.find(l=>l.name===r.pluginName))==null?void 0:o.data;if(i)try{const l=r.parseJson(i);r.onLoad(n,l)}catch{console.error("LoadResources Error!")}})}unloadResources(n){this.getAllResourceHooks().forEach(s=>{s.onUnLoad(n)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}const Ln=ut.createIdentifier("resource-manager-service");var gu=Object.defineProperty,_u=Object.getOwnPropertyDescriptor,mu=(t,e,n,s)=>{for(var r=s>1?void 0:s?_u(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&gu(e,n,r),r},js=(t,e)=>(n,s)=>e(n,s,t);let is=class extends yt{constructor(e,n){super();g(this,"saveWorkbook",e=>{const n=e.getUnitId(),s=this._resourceManagerService.getResources(n)||[],r=e.getSnapshot();return r.resources=s,r});this._resourceManagerService=e,this._univerInstanceService=n,this._init()}_init(){const e=s=>{s.businesses.forEach(r=>{switch(r){case Z.UNRECOGNIZED:case Z.UNIVER_UNKNOWN:case Z.UNIVER_SLIDE:case Z.UNIVER_DOC:{this._univerInstanceService.getAllUnitsForType(Z.UNIVER_DOC).forEach(i=>{const l=(i.getSnapshot().resources||[]).find(a=>a.name===s.pluginName);if(l)try{const a=s.parseJson(l.data);s.onLoad(i.getUnitId(),a)}catch{console.error(`Load Document{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}});break}case Z.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(Z.UNIVER_SHEET).forEach(i=>{const l=(i.getSnapshot().resources||[]).find(a=>a.name===s.pluginName);if(l)try{const a=s.parseJson(l.data);s.onLoad(i.getUnitId(),a)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(s=>{e(s)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(s=>{e(s)})),this.disposeWithMe(bt(this._univerInstanceService.getTypeOfUnitAdded$(Z.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.loadResources(s.getUnitId(),s.getSnapshot().resources)}))),this.disposeWithMe(bt(this._univerInstanceService.getTypeOfUnitDisposed$(Z.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.unloadResources(s.getUnitId())})))}saveDoc(e){const n=e.getUnitId(),s=this._resourceManagerService.getResourcesByType(n,Z.UNIVER_DOC)||[],r=e.getSnapshot();return r.resources=s,r}};is=mu([js(0,ut.Inject(Ln)),js(1,ut.Inject(Fe))],is);const bs=ut.createIdentifier("resource-loader-service");Un(Ot.Ready,bs);class vs extends yt{constructor(){super();g(this,"_currentTheme");g(this,"_currentTheme$",new rt.BehaviorSubject({}));g(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(bt(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(n){this._currentTheme=n,this._currentTheme$.next(n)}}const Dn="__INTERNAL_EDITOR__",to=`${Dn}DOCS_NORMAL`,eo=`${Dn}DOCS_FORMULA_BAR`,Eu=`\r
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||{}),On=(t=>(t.BULLET_LIST="BULLET_LIST",t.ORDER_LIST="ORDER_LIST",t))(On||{});const fa={BULLET_LIST:{listType:"BULLET_LIST",nestingLevel:[{bulletAlignment:fe.START,glyphFormat:" %0",textStyle:{fs:12},startNumber:0,glyphSymbol:"●",hanging:21,indentStart:21},{bulletAlignment:fe.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"■",hanging:21,indentStart:42},{bulletAlignment:fe.START,glyphFormat:" %1",textStyle:{fs:12},startNumber:0,glyphSymbol:"◆",hanging:21,indentStart:63}]},ORDER_LIST:{listType:"ORDER_LIST",nestingLevel:[{bulletAlignment:fe.START,glyphFormat:" %1.",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:21},{bulletAlignment:fe.START,glyphFormat:" %1.%2)",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:42},{bulletAlignment:fe.START,glyphFormat:" %1.%2.%3.",textStyle:{fs:12},startNumber:0,glyphType:je.DECIMAL,hanging:21,indentStart:63}]}};function gs(t){const e=[];for(const n of t){const{ed:s,ts:r}=n;if(n.sId===void 0&&delete n.sId,D.isEmptyObject(r)&&n.sId==null)continue;if(e.length===0){e.push(n);continue}const i=e.pop();Xr(n,i)&&D.hasIntersectionBetweenTwoRanges(i.st,i.ed,n.st,n.ed)?e.push({...n,st:i.st,ed:s}):e.push(i,n)}return e}function Ei(t,e,n,s){var c;const{textRuns:r}=t;if(r==null)return;const i=[],o=r.length;let l=!1;const a=(c=e.textRuns)!=null?c:[];if(a.length)for(const h of a)h.st+=s,h.ed+=s;for(let h=0;h<o;h++){const u=r[h],d=r[h+1],{st:f,ed:m}=u;if(m<s)i.push(u);else if(s>=f&&s<=m){if(d&&d.st===d.ed&&s===d.st){i.push(u);continue}if(l)u.st+=n,u.ed+=n,i.push(u);else{l=!0,u.ed+=n;const E=[];if(a.length){const P={...u,st:f,ed:a[0].st};P.ed>P.st&&E.push(P),E.push(...a);const x=a[a.length-1],Q={...u,st:x.ed,ed:m+n};Q.ed>Q.st&&E.push(Q)}else E.push(u);i.push(...E)}}else u.st+=n,u.ed+=n,l||(l=!0,i.push(...a)),i.push(u)}l||(l=!0,i.push(...a)),t.textRuns=gs(i)}function _s(t,e,n,s){const{paragraphs:r}=t;if(r==null)return;const{paragraphs:i,dataStream:o}=e,l=[];let a=-1;for(let h=0,u=r.length;h<u;h++){const d=r[h],{startIndex:f}=d;f>=s&&(d.startIndex+=n),a===-1&&f>=s&&(a=h),l.push(d.startIndex)}let c=-1;if(i){for(let h=0,u=i.length;h<u;h++){const d=i[h];d.startIndex+=s;const f=d.startIndex;c=l.indexOf(f)}if(o===ce.PARAGRAPH&&i.length===1){const h=r[a],u=i[0],d=h.paragraphStyle,f=h.bullet;h.paragraphStyle=u.paragraphStyle,h.bullet=u.bullet,u.paragraphStyle=d,u.bullet=f}c!==-1&&r.splice(c,1),r.push(...i),r.sort(Me("startIndex"))}}function ga(t,e,n,s){const{sectionBreaks:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c}=a;c>=s&&(a.startIndex+=n)}const i=e.sectionBreaks;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function pi(t,e,n,s){const{customBlocks:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c}=a;c>=s&&(a.startIndex+=n)}const i=e.customBlocks;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function Ri(t,e,n,s){const{tables:r}=t;if(r==null)return;for(let o=0,l=r.length;o<l;o++){const a=r[o],{startIndex:c,endIndex:h}=a;c>s?(a.startIndex+=n,a.endIndex+=n):h>=s-1&&(a.endIndex+=n)}const i=e.tables;if(i){for(let o=0,l=i.length;o<l;o++){const a=i[o];a.startIndex+=s,a.endIndex+=s}r.push(...i),r.sort(Me("startIndex"))}}function Ci(t,e,n,s){t.customRanges||(t.customRanges=[]);const{customRanges:r}=t,i={};for(let l=0,a=r.length;l<a;l++){const c=r[l];i[c.rangeId]=c;const{startIndex:h,endIndex:u}=c;h>=s?(c.startIndex+=n,c.endIndex+=n):u>s-1&&(c.endIndex+=n)}const o=[];if(e.customRanges){for(let l=0,a=e.customRanges.length;l<a;l++){const c=e.customRanges[l],h=i[c.rangeId];if(c.startIndex+=s,c.endIndex+=s,h){if(h.startIndex<=c.startIndex&&h.endIndex>=c.endIndex)continue;if(t.dataStream[h.startIndex]===ce.CUSTOM_RANGE_START&&t.dataStream[h.endIndex]===ce.CUSTOM_RANGE_END){o.push(c);continue}if(t.dataStream[h.startIndex]===ce.CUSTOM_RANGE_START){h.endIndex=c.endIndex;continue}if(t.dataStream[h.endIndex]===ce.CUSTOM_RANGE_END){h.startIndex=c.startIndex;continue}}o.push(c)}r.push(...o),r.sort(Me("startIndex"))}}function _a(t){t.sort((s,r)=>s.startIndex-r.startIndex);const e=[];let n=t[0];for(let s=1;s<t.length;s++)n.endIndex+1>=t[s].startIndex?n.endIndex=Math.max(n.endIndex,t[s].endIndex):(e.push(n),n=t[s]);return e.push(n),e}function ma(t){const e={};for(let n=0,s=t.length;n<s;n++){const r=t[n],i=e[r.id];e[r.id]=[...i!=null?i:[],r]}return Object.keys(e).forEach(n=>{const s=e[n],r=_a(s);e[n]=r}),Object.values(e).flat()}function Ii(t,e,n,s){t.customDecorations||(t.customDecorations=[]);const{customDecorations:r}=t;if(n>0)for(let i=0,o=r.length;i<o;i++){const l=r[i],{startIndex:a,endIndex:c}=l;a>=s?(l.startIndex+=n,l.endIndex+=n):c>s-1&&(l.endIndex+=n)}if(e.customDecorations){const i=[];for(let o=0,l=e.customDecorations.length;o<l;o++){const a=e.customDecorations[o];i.push(a),a.startIndex+=s,a.endIndex+=s}r.push(...i),t.customDecorations=ma(r),t.customDecorations.sort(Me("startIndex"))}}function Oi(t,e,n){var l;const{textRuns:s}=t,r=n,i=n+e,o=[];if(r===i&&(s!=null&&s.find(a=>a.st===n&&a.ed===n))){const a=s.find(c=>c.st===n&&c.ed===n);return o.push({...a,st:a.st-n,ed:a.ed-n}),t.textRuns=(l=t.textRuns)==null?void 0:l.filter(c=>c!==a),o}if(s){const a=[];for(let c=0,h=s.length;c<h;c++){const u=s[c],{st:d,ed:f}=u;if(r<=d&&i>=f){o.push({...u,st:d-r,ed:f-r});continue}else d<=r&&f>=i?(o.push({...u,st:r-r,ed:i-r}),u.ed-=e):r>=d&&r<f?(o.push({...u,st:r-r,ed:f-r}),u.ed=r):i>d&&i<=f?(o.push({...u,st:d-r,ed:i-r}),u.st=i-e,u.ed-=e):d>=i&&(u.st-=e,u.ed-=e);a.push(u)}t.textRuns=a}return o.length===0&&o.push({st:0,ed:e,ts:{}}),o}function Si(t,e,n){const{paragraphs:s}=t,r=n,i=n+e,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<i){o.push({...h,startIndex:u-n});continue}else u>=i&&(h.startIndex-=e);l.push(h)}t.paragraphs=l}return o}function Ni(t,e,n){const{sectionBreaks:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<=i){o.push({...h,startIndex:u-n});continue}else u>i&&(h.startIndex-=e);l.push(h)}t.sectionBreaks=l}return o}function Ai(t,e,n){const{customBlocks:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u}=h;if(u>=r&&u<=i){o.push({...h,startIndex:u-n});continue}else u>i&&(h.startIndex-=e);l.push(h)}t.customBlocks=l}return o}function bi(t,e,n){const{tables:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u,endIndex:d}=h;if(r<=u&&i>=d){o.push({...h,startIndex:u-n,endIndex:d-n});continue}else if(u<=r&&d>=i){const f=wn(u,d,r,i);h.startIndex=f[0],h.endIndex=f[1]}else i<u&&(h.startIndex-=e,h.endIndex-=e);l.push(h)}t.tables=l}return o}function vi(t,e,n){const{customRanges:s}=t,r=n,i=n+e-1,o=[];if(s){const l=[];for(let a=0,c=s.length;a<c;a++){const h=s[a],{startIndex:u,endIndex:d}=h;if(r<=u&&i>=u){o.push({...h,startIndex:u-n,endIndex:d-n});continue}else if(u<=r&&d>=i){const f=wn(u,d,r,i);h.startIndex=f[0],h.endIndex=f[1]}else i<u&&(h.startIndex-=e,h.endIndex-=e);l.push(h)}t.customRanges=l}return o}function wi(t,e,n,s=!0){const{customDecorations:r}=t,i=n,o=n+e-1,l=[];if(r){const a=[];for(let c=0,h=r.length;c<h;c++){const u=r[c],{startIndex:d,endIndex:f}=u;if(d>=i&&f<=o){l.push(u);continue}else if(Math.max(i,d)<=Math.min(o,f)){const m=wn(d,f,i,o);u.startIndex=m[0],u.endIndex=m[1]}else o<d&&s&&(u.startIndex-=e,u.endIndex-=e);a.push(u)}t.customDecorations=a}return l}function Ea(t,e,n,s,r){const i=pa(t,e,n,s,r),o=Ra(t,e,n,s,r),l=Ca(t,e,n,s,r),a=Ia(t,e,n,s,r),c=Oa(t,e,n,s,r),h=Sa(t,e,n,s,r),u=Na(t,e,n,s,r);return{dataStream:"",textRuns:i,paragraphs:o,sectionBreaks:l,customBlocks:a,tables:c,customRanges:h,customDecorations:u}}function pa(t,e,n,s,r){const{textRuns:i}=t,{textRuns:o}=e;if(i==null||o==null)return;const l=Oi(t,n,s);if(r!==Pt.REPLACE){const a=Ti(o,l,r);e.textRuns=a}return Ei(t,e,n,s),l}function Ti(t,e,n){if(e.length===0)return t;t=D.deepClone(t),e=D.deepClone(e);const s=[],r=t.length,i=e.length;let o=0,l=0,a=null;function c(){return a?(s.push(a),a=null,!0):!1}for(;o<r&&l<i;){const{st:f,ed:m,ts:E}=t[o],{st:P,ed:x,ts:Q,sId:_t}=e[l];let ht;if(n===Pt.COVER?ht={...Q,...E}:ht={...E,...Q},m<P)c()||s.push(t[o]),o++;else if(x<f)c()||s.push(e[l]),l++;else{const p={st:Math.min(f,P),ed:Math.max(f,P),ts:f<P?{...E}:{...Q},sId:f<P?void 0:_t};p.ed>p.st&&s.push(p),s.push({st:Math.max(f,P),ed:Math.min(m,x),ts:ht,sId:_t}),m<x?(o++,e[l].st=m,e[l].st===e[l].ed&&l++):(l++,t[o].st=x,t[o].st===t[o].ed&&o++);const O={st:Math.min(m,x),ed:Math.max(m,x),ts:m<x?{...Q}:{...E},sId:m<x?_t:void 0};a=O.ed>O.st?O:null}}c();const h=s[s.length-1],u=t[r-1],d=e[i-1];return h.ed!==Math.max(u.ed,d.ed)&&(u.ed>d.ed?s.push(u):s.push(d)),gs(s)}function Ra(t,e,n,s,r){const{paragraphs:i}=t,{paragraphs:o}=e;if(i==null||o==null)return;const l=Si(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h,paragraphStyle:u,bullet:d}=c;let f=[];for(const m of l){const{startIndex:E,paragraphStyle:P,bullet:x}=m;let Q,_t;if(r===Pt.COVER?(Q={...P,...u},_t={listId:"",listType:On.BULLET_LIST,nestingLevel:0,textStyle:{},...x,...d}):(Q={...u,...P},_t={listId:"",listType:On.BULLET_LIST,nestingLevel:0,textStyle:{},...d,...x}),h===E){f.push({startIndex:h,paragraphStyle:Q,bullet:_t});break}}a.push(...f),f=[]}e.paragraphs=a}return _s(t,e,n,s),l}function Ca(t,e,n,s,r){const{sectionBreaks:i}=t,{sectionBreaks:o}=e;if(i==null||o==null)return;const l=Ni(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h}=c;let u=[];for(const d of l){const{startIndex:f}=d;if(h===f){r===Pt.COVER?u.push({...d,...c}):u.push({...c,...d});break}}a.push(...u),u=[]}e.sectionBreaks=a}return _s(t,e,n,s),l}function Ia(t,e,n,s,r){const{customBlocks:i}=t,{customBlocks:o}=e;if(i==null||o==null)return;const l=Ai(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h}=c;let u=[];for(const d of l){const{startIndex:f}=d;if(h===f){r===Pt.COVER?u.push({...d,...c}):u.push({...c,...d});break}}a.push(...u),u=[]}e.customBlocks=a}return pi(t,e,n,s),l}function Oa(t,e,n,s,r){const{tables:i}=t,{tables:o}=e;if(i==null||o==null)return;const l=bi(t,n,s);if(r!==Pt.REPLACE){const a=[];for(const c of o){const{startIndex:h,endIndex:u}=c;let d=[];for(const f of l){const{startIndex:m,endIndex:E}=f;if(m>=h&&E<=u){r===Pt.COVER?d.push({...f,...c}):d.push({...c,...f});break}}a.push(...d),d=[]}e.tables=a}return Ri(t,e,n,s),l}function Sa(t,e,n,s,r){t.customRanges||(t.customRanges=[]);const{customRanges:i}=t,{customRanges:o}=e;if(i==null||o==null)return;let l=[];return r===Pt.REPLACE&&(l=vi(t,n,s)),Ci(t,e,0,s),l}function Na(t,e,n,s,r){t.customDecorations||(t.customDecorations=[]);let i=[];return r===Pt.REPLACE&&(i=wi(t,n,s,!1)),Ii(t,e,0,s),i}function Je(t,e,n,s=!1){const{dataStream:r,textRuns:i=[],paragraphs:o=[]}=t,l={dataStream:r.slice(e,n)},a=[];for(const u of i){const d=D.deepClone(u),{st:f,ed:m}=d;D.hasIntersectionBetweenTwoRanges(f,m,e,n)&&(e>=f&&e<=m?a.push({...d,st:e,ed:Math.min(n,m)}):n>=f&&n<=m?a.push({...d,st:Math.max(e,f),ed:n}):a.push(d))}a.length?l.textRuns=a.map(u=>{const{st:d,ed:f}=u;return{...u,st:d-e,ed:f-e}}):s&&(l.textRuns=[{st:0,ed:n-e,ts:{}}]);const c=[];for(const u of o){const{startIndex:d}=u;d>=e&&d<=n&&c.push(D.deepClone(u))}c.length&&(l.paragraphs=c.map(u=>({...u,startIndex:u.startIndex-e}))),l.customDecorations=Ui(t,e,n);const{customRanges:h}=Mi(t,e,n);return l.customRanges=h,l}function Aa(t){const{dataStream:e,textRuns:n,paragraphs:s,customRanges:r,customDecorations:i}=t;let o=0,l=0;r==null||r.forEach(c=>{c.startIndex<0&&(o=Math.max(o,-c.startIndex)),c.endIndex>e.length-1&&(l=Math.max(l,c.endIndex-e.length+1))});const a=`${ce.CUSTOM_RANGE_START.repeat(o)}${e}${ce.CUSTOM_RANGE_END.repeat(l)}`;return n&&(n[0]&&(n[0].st=n[0].st-o),n[n.length-1]&&(n[n.length-1].ed=n[n.length-1].ed+l)),n==null||n.forEach(c=>{c.st+=o,c.ed+=o}),s==null||s.forEach(c=>{c.startIndex+=o}),r==null||r.forEach(c=>{c.startIndex+=o,c.endIndex+=o}),i==null||i.forEach(c=>{c.startIndex+=o,c.endIndex+=l}),{...t,dataStream:a,textRuns:n,paragraphs:s,customRanges:r,customDecorations:i}}function Mi(t,e,n){const{customRanges:s=[]}=t;let r=0,i=0;const o=s.filter(l=>Math.max(l.startIndex,e)<=Math.min(l.endIndex,n-1)).map(l=>({...l,startIndex:l.startIndex,endIndex:l.endIndex}));if(o.length){o.forEach(l=>{l.startIndex<e&&(r+=1),l.endIndex>n-1&&(i+=1)});for(let l=0;l<r;l++){const a=o[l];a.startIndex=e-r+l}if(i){const l=[...o].sort((a,c)=>c.endIndex-a.endIndex);for(let a=0;a<i;a++){const c=l[a];c.endIndex=n+i-a-1}}}return{customRanges:o.map(l=>({...l,startIndex:l.startIndex-e,endIndex:l.endIndex-e})),leftOffset:r,rightOffset:i}}function Ui(t,e,n){const{customDecorations:s=[]}=t,r=[];return s.forEach(i=>{if(Math.max(i.startIndex,e)<=Math.min(i.endIndex,n-1)){const o=D.deepClone(i);r.push({...o,startIndex:Math.max(o.startIndex-e,0),endIndex:Math.min(o.endIndex,n)-e})}}),r}function ts(t,e,n=Pt.COVER){if(e.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:l=[]}=e,a=Ti(o,r,n);a.length&&(s.textRuns=a);const c=[];let h=0,u=0;for(;h<i.length&&u<l.length;){const d=i[h],f=l[u],{startIndex:m}=d,{startIndex:E}=f;m===E?(c.push(D.deepMerge(d,f)),h++,u++):m<E?(c.push(D.deepClone(d)),h++):(c.push(D.deepClone(f)),u++)}return h<i.length&&c.push(...i.slice(h)),u<l.length&&c.push(...l.slice(u)),c.length&&(s.paragraphs=c),s}function ba(t){const{body:e}=t;if(e==null)return!0;const{textRuns:n=[],paragraphs:s=[]}=e;return n.length===0&&s.length===0}function va(t=D.generateRandomId(6),e=Te.EN_US,n=""){return{id:t,locale:e,title:n,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:{}}}var Wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wa(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var $t={},Li={},ms={};Object.defineProperty(ms,"__esModule",{value:!0});function Ta(t,e){if(Array.isArray(e))return!1;for(let n in t)if(!Es(t[n],e[n]))return!1;for(let n in e)if(t[n]===void 0)return!1;return!0}function Ma(t,e){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Es(t[n],e[n]))return!1;return!0}function Es(t,e){return t===e?!0:t===null||e===null||typeof t!="object"||typeof e!="object"?!1:Array.isArray(t)?Ma(t,e):Ta(t,e)}ms.default=Es;var ps={};Object.defineProperty(ps,"__esModule",{value:!0});function es(t){if(t===null)return null;if(Array.isArray(t))return t.map(es);if(typeof t=="object"){const e={};for(let n in t)e[n]=es(t[n]);return e}else return t}ps.default=es;var Rs={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildOf=t.advancer=t.readCursor=t.writeCursor=t.WriteCursor=t.ReadCursor=t.isValidPathItem=void 0;function e(h,u){if(!h)throw new Error(u)}const n=h=>h!=null&&typeof h=="object"&&!Array.isArray(h),s=(h,u)=>typeof h==typeof u?h>u:typeof h=="string"&&typeof u=="number";function r(h,u){for(let d in h){const f=d;u.write(f,h[f])}}t.isValidPathItem=h=>typeof h=="number"||typeof h=="string"&&h!=="__proto__";class i{constructor(u=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=u}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const u=[];let d=this.container,f=this.parents.length-1,m=this.idx;for(;m>=0;)u.unshift(d[m]),m===0?(m=this.indexes[f*2],d=this.parents[f--]):m-=n(d[m-1])?2:1;return u}}class o extends i{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let u;return this.container&&this.container.length>this.idx+1&&n(u=this.container[this.idx+1])?u:null}descendFirst(){let u=this.idx+1;if(!this.container||u>=this.container.length||n(this.container[u])&&u+1>=this.container.length)return!1;n(this.container[u])&&u++;const d=this.container[u];return Array.isArray(d)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(u),this.idx=0,this.container=d):this.idx=u,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const u=this.indexes[this.indexes.length-1]+1,d=this.parents[this.parents.length-1];return u>=d.length?!1:(e(!isNaN(u)),this.indexes[this.indexes.length-1]=u,this.container=d[u],!0)}_init(u,d,f,m){this.container=u,this.idx=d,this.parents=f.slice(),this.indexes=m.slice()}clone(){const u=new o;return u._init(this.container,this.idx,this.parents,this.indexes),u}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(u,d){const f=this.getComponent();f&&d(f,u);for(const m of this)u&&u.descend(m),this.traverse(u,d),u&&u.ascend()}eachPick(u,d){this.traverse(u,(f,m)=>{f.p!=null&&d(f.p,m)})}eachDrop(u,d){this.traverse(u,(f,m)=>{f.d!=null&&d(f.d,m)})}}t.ReadCursor=o;class l extends i{constructor(u=null){super(u),this.pendingDescent=[],this._op=u}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let u=0;u<this.pendingDescent.length;u++){const d=this.pendingDescent[u];let f=this.idx+1;if(f<this.container.length&&n(this.container[f])&&f++,e(f===this.container.length||!n(this.container[f])),f===this.container.length)this.container.push(d),this.idx=f;else if(this.container[f]===d)this.idx=f;else{if(!Array.isArray(this.container[f])){const m=this.container.splice(f,this.container.length-f);this.container.push(m),this.lcIdx>-1&&(this.lcIdx=f)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(s(d,this.container[this.lcIdx][0])),f=this.lcIdx+1,this.lcIdx=-1);f<this.container.length&&s(d,this.container[f][0]);)f++;if(this.indexes.push(f),this.idx=0,f<this.container.length&&this.container[f][0]===d)this.container=this.container[f];else{const m=[d];this.container.splice(f,0,m),this.container=m}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const u=this.idx+1;if(u<this.container.length&&n(this.container[u]))return this.container[u];{const d={};return this.container.splice(u,0,d),d}}write(u,d){const f=this.getComponent();e(f[u]==null||f[u]===d,"Internal consistency error: Overwritten component. File a bug"),f[u]=d}get(){return this._op}descend(u){if(!t.isValidPathItem(u))throw Error("Invalid JSON key");this.pendingDescent.push(u)}descendPath(u){return this.pendingDescent.push(...u),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(u,d=r){if(u===null)return;if(e(Array.isArray(u)),u===this._op)throw Error("Cannot merge into my own tree");const f=this.lcIdx,m=this.parents.length;let E=0;for(let P=0;P<u.length;P++){const x=u[P];typeof x=="string"||typeof x=="number"?(E++,this.descend(x)):Array.isArray(x)?this.mergeTree(x,d):typeof x=="object"&&d(x,this)}for(;E--;)this.ascend();this.lcIdx=this.parents.length===m?f:-1}at(u,d){this.descendPath(u),d(this);for(let f=0;f<u.length;f++)this.ascend();return this}writeAtPath(u,d,f){return this.at(u,()=>this.write(d,f)),this.reset(),this}writeMove(u,d,f=0){return this.writeAtPath(u,"p",f).writeAtPath(d,"d",f)}getPath(){const u=super.getPath();return u.push(...this.pendingDescent),u}}t.WriteCursor=l,t.writeCursor=()=>new l,t.readCursor=h=>new o(h);function a(h,u,d){let f,m;m=f=h?h.descendFirst():!1;function E(P){let x;for(;m;){const Q=x=h.getKey();if(P!=null){let _t=!1;if(u&&typeof Q=="number"&&(x=u(Q,h.getComponent()),x<0&&(x=~x,_t=!0)),s(x,P))return null;if(x===P&&!_t)return h}d&&typeof x=="number"&&d(x,h.getComponent()),m=h.nextSibling()}return null}return E.end=()=>{f&&h.ascend()},E}t.advancer=a;function c(h,u,d){let f,m,E,P;for(f=m=h&&h.descendFirst(),E=P=u&&u.descendFirst();f||E;){let x=f?h.getKey():null,Q=E?u.getKey():null;x!==null&&Q!==null&&(s(Q,x)?Q=null:x!==Q&&(x=null)),d(x==null?Q:x,x!=null?h:null,Q!=null?u:null),x!=null&&f&&(f=h.nextSibling()),Q!=null&&E&&(E=u.nextSibling())}m&&h.ascend(),P&&u.ascend()}t.eachChildOf=c})(Rs);var Cs={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(t.ConflictType||(t.ConflictType={}))})(Cs);var Bn={},Se={},Hs;function Is(){return Hs||(Hs=1,Object.defineProperty(Se,"__esModule",{value:!0}),Se.uniToStrPos=Se.strPosToUni=void 0,Se.strPosToUni=(t,e=t.length)=>{let n=0,s=0;for(;s<e;s++){const r=t.charCodeAt(s);r>=55296&&r<=57343&&(n++,s++)}if(s!==e)throw Error("Invalid offset - splits unicode bytes");return s-n},Se.uniToStrPos=(t,e)=>{let n=0;for(;e>0;e--){const s=t.charCodeAt(n);n+=s>=55296&&s<=57343?2:1}return n}),Se}var Gn={},Fs;function ns(){return Fs||(Fs=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.uniSlice=t.dlen=t.eachOp=void 0;const e=Is(),n=p=>{if(!Array.isArray(p))throw Error("Op must be an array of components");let O=null;for(let v=0;v<p.length;v++){const z=p[v];switch(typeof z){case"object":if(typeof z.d!="number"&&typeof z.d!="string")throw Error("Delete must be number or string");if(t.dlen(z.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(z.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(z>0))throw Error("Skip components must be >0");if(typeof O=="number")throw Error("Adjacent skip components should be combined");break}O=z}if(typeof O=="number")throw Error("Op has a trailing skip")};function s(p,O){let v=0,z=0;for(let et=0;et<p.length;et++){const X=p[et];switch(O(X,v,z),typeof X){case"object":v+=t.dlen(X.d);break;case"string":z+=e.strPosToUni(X);break;case"number":v+=X,z+=X;break}}}t.eachOp=s;function r(p,O){const v=[],z=l(v);return s(p,(et,X,Gt)=>{z(O(et,X,Gt))}),u(v)}const i=p=>p,o=p=>r(p,i);t.dlen=p=>typeof p=="number"?p:e.strPosToUni(p);const l=p=>O=>{if(!(!O||O.d===0||O.d===""))if(p.length===0)p.push(O);else if(typeof O==typeof p[p.length-1])if(typeof O=="object"){const v=p[p.length-1];v.d=typeof v.d=="string"&&typeof O.d=="string"?v.d+O.d:t.dlen(v.d)+t.dlen(O.d)}else p[p.length-1]+=O;else p.push(O)},a=p=>typeof p=="number"?p:typeof p=="string"?e.strPosToUni(p):typeof p.d=="number"?p.d:e.strPosToUni(p.d);t.uniSlice=(p,O,v)=>{const z=e.uniToStrPos(p,O),et=v==null?1/0:e.uniToStrPos(p,v);return p.slice(z,et)};const c=(p,O,v)=>typeof p=="number"?v==null?p-O:Math.min(p,v)-O:t.uniSlice(p,O,v),h=p=>{let O=0,v=0;return{take:(X,Gt)=>{if(O===p.length)return X===-1?null:X;const St=p[O];let ft;if(typeof St=="number")return X===-1||St-v<=X?(ft=St-v,++O,v=0,ft):(v+=X,X);if(typeof St=="string"){if(X===-1||Gt==="i"||e.strPosToUni(St.slice(v))<=X)return ft=St.slice(v),++O,v=0,ft;{const Ct=v+e.uniToStrPos(St.slice(v),X);return ft=St.slice(v,Ct),v=Ct,ft}}else{if(X===-1||Gt==="d"||t.dlen(St.d)-v<=X)return ft={d:c(St.d,v)},++O,v=0,ft;{let Ct=c(St.d,v,v+X);return v+=X,{d:Ct}}}},peek:()=>p[O]}},u=p=>(p.length>0&&typeof p[p.length-1]=="number"&&p.pop(),p);function d(p,O,v){if(v!=="left"&&v!=="right")throw Error("side ("+v+") must be 'left' or 'right'");n(p),n(O);const z=[],et=l(z),{take:X,peek:Gt}=h(p);for(let ft=0;ft<O.length;ft++){const Ct=O[ft];let Tt,jt;switch(typeof Ct){case"number":for(Tt=Ct;Tt>0;)jt=X(Tt,"i"),et(jt),typeof jt!="string"&&(Tt-=a(jt));break;case"string":v==="left"&&typeof Gt()=="string"&&et(X(-1)),et(e.strPosToUni(Ct));break;case"object":for(Tt=t.dlen(Ct.d);Tt>0;)switch(jt=X(Tt,"i"),typeof jt){case"number":Tt-=jt;break;case"string":et(jt);break;case"object":Tt-=t.dlen(jt.d)}break}}let St;for(;St=X(-1);)et(St);return u(z)}function f(p,O){n(p),n(O);const v=[],z=l(v),{take:et}=h(p);for(let Gt=0;Gt<O.length;Gt++){const St=O[Gt];let ft,Ct;switch(typeof St){case"number":for(ft=St;ft>0;)Ct=et(ft,"d"),z(Ct),typeof Ct!="object"&&(ft-=a(Ct));break;case"string":z(St);break;case"object":ft=t.dlen(St.d);let Tt=0;for(;Tt<ft;)switch(Ct=et(ft-Tt,"d"),typeof Ct){case"number":z({d:c(St.d,Tt,Tt+Ct)}),Tt+=Ct;break;case"string":Tt+=e.strPosToUni(Ct);break;case"object":z(Ct)}break}}let X;for(;X=et(-1);)z(X);return u(v)}const m=(p,O)=>{let v=0;for(let z=0;z<O.length&&p>v;z++){const et=O[z];switch(typeof et){case"number":{v+=et;break}case"string":const X=e.strPosToUni(et);v+=X,p+=X;break;case"object":p-=Math.min(t.dlen(et.d),p-v);break}}return p},E=(p,O)=>typeof p=="number"?m(p,O):p.map(v=>m(v,O));function P(p,O,v){return r(p,(z,et)=>typeof z=="object"&&typeof z.d=="number"?{d:v.slice(O,et,et+z.d)}:z)}function x(p){return r(p,O=>{switch(typeof O){case"object":if(typeof O.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return O.d;case"string":return{d:O};case"number":return O}})}function Q(p){return r(p,O=>typeof O=="object"&&typeof O.d=="string"?{d:e.strPosToUni(O.d)}:O)}function _t(p){let O=!0;return s(p,v=>{typeof v=="object"&&typeof v.d=="number"&&(O=!1)}),O}function ht(p){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:u,normalize:o,checkOp:n,create(O=""){if(typeof O!="string")throw Error("Initial data must be a string");return p.create(O)},apply(O,v){n(v);const z=p.builder(O);for(let et=0;et<v.length;et++){const X=v[et];switch(typeof X){case"number":z.skip(X);break;case"string":z.append(X);break;case"object":z.del(t.dlen(X.d));break}}return z.build()},transform:d,compose:f,transformPosition:m,transformSelection:E,isInvertible:_t,makeInvertible(O,v){return P(O,v,p)},stripInvertible:Q,invert:x,invertWithDoc(O,v){return x(P(O,v,p))},isNoop:O=>O.length===0}}t.default=ht}(Gn)),Gn}var un={},$s;function Ua(){if($s)return un;$s=1,Object.defineProperty(un,"__esModule",{value:!0});const t=ns(),e=Is();function n(s,r){return{get:s,getLength(){return s().length},insert(i,o,l){const a=e.strPosToUni(s(),i);return r([a,o],l)},remove(i,o,l){const a=e.strPosToUni(s(),i);return r([a,{d:o}],l)},_onOp(i){t.eachOp(i,(o,l,a)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(a,o);break;case"object":const c=t.dlen(o.d);this.onRemove&&this.onRemove(a,c)}})},onInsert:null,onRemove:null}}return un.default=n,n.provides={text:!0},un}var Ws;function La(){return Ws||(Ws=1,function(t){var e=Wt&&Wt.__createBinding||(Object.create?function(d,f,m,E){E===void 0&&(E=m),Object.defineProperty(d,E,{enumerable:!0,get:function(){return f[m]}})}:function(d,f,m,E){E===void 0&&(E=m),d[E]=f[m]}),n=Wt&&Wt.__setModuleDefault||(Object.create?function(d,f){Object.defineProperty(d,"default",{enumerable:!0,value:f})}:function(d,f){d.default=f}),s=Wt&&Wt.__importStar||function(d){if(d&&d.__esModule)return d;var f={};if(d!=null)for(var m in d)Object.hasOwnProperty.call(d,m)&&e(f,d,m);return n(f,d),f},r=Wt&&Wt.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(t,"__esModule",{value:!0}),t.type=t.remove=t.insert=void 0;const i=Is(),o=s(ns()),l=r(Ua()),a={create(d){return d},toString(d){return d},builder(d){if(typeof d!="string")throw Error("Invalid document snapshot: "+d);const f=[];return{skip(m){let E=i.uniToStrPos(d,m);if(E>d.length)throw Error("The op is too long for this document");f.push(d.slice(0,E)),d=d.slice(E)},append(m){f.push(m)},del(m){d=d.slice(i.uniToStrPos(d,m))},build(){return f.join("")+d}}},slice:o.uniSlice},c=o.default(a),h=Object.assign(Object.assign({},c),{api:l.default});t.type=h,t.insert=(d,f)=>f.length===0?[]:d===0?[f]:[d,f],t.remove=(d,f)=>o.dlen(f)===0?[]:d===0?[{d:f}]:[d,{d:f}];var u=ns();Object.defineProperty(t,"makeType",{enumerable:!0,get:function(){return u.default}})}(Bn)),Bn}(function(t){var e=Wt&&Wt.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(t,"__esModule",{value:!0}),t.editOp=t.replaceOp=t.insertOp=t.moveOp=t.removeOp=t.type=void 0;const n=e(ms),s=e(ps),r=Rs,i=Cs;function o(_,R){if(!_)throw new Error(R)}t.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:r.readCursor,writeCursor:r.writeCursor,create:_=>_,isNoop:_=>_==null,setDebug(_){},registerSubtype:x,checkValidOp:et,normalize:X,apply:Gt,transformPosition:St,compose:ft,tryTransform:kn,transform:Ao,makeInvertible:jt,invert:Ct,invertWithDoc:No,RM_UNEXPECTED_CONTENT:i.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:i.ConflictType.DROP_COLLISION,BLACKHOLE:i.ConflictType.BLACKHOLE,transformNoConflict:(_,R,N)=>Ms(()=>!0,_,R,N),typeAllowingConflictsPred:_=>Object.assign(Object.assign({},t.type),{transform:(R,N,M)=>Ms(_,R,N,M)})};const l=_=>_?_.getComponent():null;function a(_){return _&&typeof _=="object"&&!Array.isArray(_)}const c=_=>Array.isArray(_)?_.slice():_!==null&&typeof _=="object"?Object.assign({},_):_,h=_=>_&&(_.p!=null||_.r!==void 0),u=_=>_&&(_.d!=null||_.i!==void 0);function d(_,R){return o(_!=null),typeof R=="number"?(o(Array.isArray(_),"Invalid key - child is not an array"),(_=_.slice()).splice(R,1)):(o(a(_),"Invalid key - child is not an object"),delete(_=Object.assign({},_))[R]),_}function f(_,R,N){return typeof R=="number"?(o(_!=null,"Container is missing for key"),o(Array.isArray(_),"Cannot use numerical key for object container"),o(_.length>=R,"Cannot insert into out of bounds index"),_.splice(R,0,N)):(o(a(_),"Cannot insert into missing item"),o(_[R]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),_[R]=N),N}t.removeOp=(_,R=!0)=>r.writeCursor().writeAtPath(_,"r",R).get(),t.moveOp=(_,R)=>r.writeCursor().writeMove(_,R).get(),t.insertOp=(_,R)=>r.writeCursor().writeAtPath(_,"i",R).get(),t.replaceOp=(_,R,N)=>r.writeCursor().at(_,M=>{M.write("r",R),M.write("i",N)}).get(),t.editOp=(_,R,N,M=!1)=>r.writeCursor().at(_,A=>O(A,R,N,M)).get();const m=(_,R)=>_!=null&&(typeof R=="number"?Array.isArray(_):typeof _=="object"),E=(_,R)=>m(_,R)?_[R]:void 0,P={};function x(_){let R=_.type?_.type:_;R.name&&(P[R.name]=R),R.uri&&(P[R.uri]=R)}const Q=_=>{const R=P[_];if(R)return R;throw Error("Missing type: "+_)};x(La());const _t=(_,R)=>_+R;x({name:"number",apply:_t,compose:_t,invert:_=>-_,transform:_=>_});const ht=_=>_==null?null:_.et?Q(_.et):_.es?P["text-unicode"]:_.ena!=null?P.number:null,p=_=>_.es?_.es:_.ena!=null?_.ena:_.e,O=(_,R,N,M=!1)=>{const[A,T]=typeof R=="string"?[Q(R),R]:[R,R.name];!M&&A.isNoop&&A.isNoop(N)||(T==="number"?_.write("ena",N):T==="text-unicode"?_.write("es",N):(_.write("et",T),_.write("e",N)))};function v(_){o(typeof _=="number"),o(_>=0),o(_===(0|_))}function z(_){typeof _=="number"?v(_):o(typeof _=="string")}function et(_){if(_===null)return;const R=new Set,N=new Set,M=T=>{let G=!0,W=!1;for(let C in T){const S=T[C];if(G=!1,o(C==="p"||C==="r"||C==="d"||C==="i"||C==="e"||C==="es"||C==="ena"||C==="et","Invalid component item '"+C+"'"),C==="p")v(S),o(!R.has(S)),R.add(S),o(T.r===void 0);else if(C==="d")v(S),o(!N.has(S)),N.add(S),o(T.i===void 0);else if(C==="e"||C==="es"||C==="ena"){o(!W),W=!0;const b=ht(T);o(b,"Missing type in edit"),b.checkValidOp&&b.checkValidOp(p(T))}}o(!G)},A=(T,G,W)=>{if(!Array.isArray(T))throw Error("Op must be null or a list");if(T.length===0)throw Error("Empty descent");G||z(T[0]);let C=1,S=0,b=0;for(let w=0;w<T.length;w++){const B=T[w];if(o(B!=null),Array.isArray(B)){const j=A(B,!1);if(S){const I=typeof b,H=typeof j;I===H?o(b<j,"descent keys are not in order"):o(I==="number"&&H==="string")}b=j,S++,C=3}else typeof B=="object"?(o(C===1,`Prev not scalar - instead ${C}`),M(B),C=2):(o(C!==3),z(B),o(r.isValidPathItem(B),"Invalid path key"),C=1)}return o(S!==1,"Operation makes multiple descents. Remove some []"),o(C===2||C===3),T[0]};A(_,!0),o(R.size===N.size,"Mismatched picks and drops in op");for(let T=0;T<R.size;T++)o(R.has(T)),o(N.has(T))}function X(_){let R=0,N=[];const M=r.writeCursor();return M.mergeTree(_,(A,T)=>{const G=ht(A);if(G){const C=p(A);O(T,G,G.normalize?G.normalize(C):C)}for(const C of["r","p","i","d"])if(A[C]!==void 0){const S=C==="p"||C==="d"?(W=A[C],N[W]==null&&(N[W]=R++),N[W]):A[C];T.write(C,S)}var W}),M.get()}function Gt(_,R){if(et(R),R===null)return _;const N=[];return function M(A,T){let G=A,W=0,C={root:A},S=0,b=C,w="root";function B(){for(;S<W;S++){let j=T[S];typeof j!="object"&&(o(m(b,w)),b=b[w]=c(b[w]),w=j)}}for(;W<T.length;W++){const j=T[W];if(Array.isArray(j)){const I=M(G,j);I!==G&&I!==void 0&&(B(),G=b[w]=I)}else if(typeof j=="object"){j.d!=null?(B(),G=f(b,w,N[j.d])):j.i!==void 0&&(B(),G=f(b,w,j.i));const I=ht(j);if(I)B(),G=b[w]=I.apply(G,p(j));else if(j.e!==void 0)throw Error("Subtype "+j.et+" undefined")}else G=E(G,j)}return C.root}(_=function M(A,T){const G=[];let W=0;for(;W<T.length;W++){const w=T[W];if(Array.isArray(w))break;typeof w!="object"&&(G.push(A),A=E(A,w))}for(let w=T.length-1;w>=W;w--)A=M(A,T[w]);for(--W;W>=0;W--){const w=T[W];if(typeof w!="object"){const B=G.pop();A=A===E(B,w)?B:A===void 0?d(B,w):(S=w,b=A,(C=c(C=B))[S]=b,C)}else h(w)&&(o(A!==void 0,"Cannot pick up or remove undefined"),w.p!=null&&(N[w.p]=A),A=void 0)}var C,S,b;return A}(_,R),R)}function St(_,R){_=_.slice(),et(R);const N=r.readCursor(R);let M,A,T=!1;const G=[];for(let C=0;;C++){const S=_[C],b=N.getComponent();if(b&&(b.r!==void 0?T=!0:b.p!=null&&(T=!1,M=b.p,A=C)),C>=_.length)break;let w=0;const B=r.advancer(N,void 0,(I,H)=>{h(H)&&w++});G.unshift(B);const j=B(S);if(typeof S=="number"&&(_[C]-=w),!j)break}if(G.forEach(C=>C.end()),T)return null;const W=()=>{let C=0;if(M!=null){const S=N.getPath();C=S.length,_=S.concat(_.slice(A))}for(;C<_.length;C++){const S=_[C],b=l(N),w=ht(b);if(w){const I=p(b);w.transformPosition&&(_[C]=w.transformPosition(_[C],I));break}let B=0;const j=r.advancer(N,(I,H)=>u(H)?~(I-B):I-B,(I,H)=>{u(H)&&B++})(S);if(typeof S=="number"&&(_[C]+=B),!j)break}};return M!=null?N.eachDrop(null,C=>{C===M&&W()}):W(),_}function ft(_,R){if(et(_),et(R),_==null)return R;if(R==null)return _;let N=0;const M=r.readCursor(_),A=r.readCursor(R),T=r.writeCursor(),G=[],W=[],C=[],S=[],b=[],w=[],B=new Set;M.traverse(null,I=>{I.p!=null&&(C[I.p]=M.clone())}),A.traverse(null,I=>{I.d!=null&&(S[I.d]=A.clone())});const j=r.writeCursor();return function I(H,gt,at,q,Et,ie,xt,Mt){o(gt||at);const pt=l(gt),Vt=l(at),qt=!!Vt&&Vt.r!==void 0,Re=!!pt&&pt.i!==void 0,Kt=pt?pt.d:null,Bt=Vt?Vt.p:null,oe=(ie||qt)&&Bt==null;if(Bt!=null)q=S[Bt],xt=W[Bt]=new r.WriteCursor;else if(Vt&&Vt.r!==void 0)q=null;else{const L=l(q);L&&L.d!=null&&(q=null)}const ot=l(q);if(Kt!=null)if(H=C[Kt],Mt=G[Kt]=new r.WriteCursor,oe)ie&&!qt&&Mt.write("r",!0);else{const L=b[Kt]=N++;xt.write("d",L)}else if(pt&&pt.i!==void 0)H=null;else{const L=l(H);L&&L.p!=null&&(H=null)}let y;Re?(o(Et===void 0),y=pt.i):y=Et;const V=(Bt==null?!Re||ie||qt:y===void 0)?null:xt.getComponent();if(Bt!=null){if(!(Et!==void 0||Re)){const L=Kt!=null?b[Kt]:N++;w[Bt]=L,Mt.write("p",L)}}else qt&&(Re||Et!==void 0||(Vt.r,Mt.write("r",Vt.r)));const k=oe?null:ht(pt),U=ht(ot);if((k||U)&&(k&&k.name,U&&U.name),k&&U){o(k===U);const L=p(pt),Y=p(ot),wt=k.compose(L,Y);O(xt,k,wt),B.add(ot)}else k?O(xt,k,p(pt)):U&&(O(xt,U,p(ot)),B.add(ot));const F=typeof y=="object"&&y!=null;let nt=!1,st=0,lt=0,vt=0,Nt=0,Rt=0;const Dt=r.advancer(q,(L,Y)=>u(Y)?Nt-L-1:L-Nt,(L,Y)=>{u(Y)&&Nt++}),tt=r.advancer(H,(L,Y)=>h(Y)?st-L-1:L-st,(L,Y)=>{h(Y)&&st++});if(r.eachChildOf(gt,at,(L,Y,wt)=>{let kt,le,Ce=L,Jt=L,$e=L;if(typeof L=="number"){let Ut=L+vt;le=Dt(Ut),Jt=Ut+Nt;let It=L+lt;kt=tt(It),u(l(le))&&(kt=null),Ce=It+st,$e=L+Rt,o(Ce>=0,"p1PickKey is negative"),o(Jt>=0,"p2DropKey is negative");const Zt=u(l(Y)),ae=h(l(wt));(Zt||ae&&!oe)&&Rt--,Zt&&lt--,ae&&vt--}else kt=tt(L),le=Dt(L);Mt.descend(Ce),xt.descend(Jt);const Le=F&&!u(l(Y))?y[$e]:void 0,ne=I(kt,Y,wt,le,Le,oe,xt,Mt);var se,$,mt;F&&!oe?Le!==ne&&(nt||(y=Array.isArray(y)?y.slice():Object.assign({},y),nt=!0),se=y,mt=ne,typeof($=$e)=="number"?(o(Array.isArray(se)),o($<se.length)):(o(!Array.isArray(se)),o(se[$]!==void 0)),mt===void 0?typeof $=="number"?se.splice($,1):delete se[$]:se[$]=mt):o(ne===void 0),xt.ascend(),Mt.ascend()}),tt.end(),Dt.end(),V!=null)V.i=y;else if(!ie&&!qt&&Bt==null)return y}(M,M.clone(),A,A.clone(),void 0,!1,T,j),T.reset(),T.mergeTree(j.get()),T.reset(),T.get(),G.map(I=>I.get()),W.map(I=>I.get()),M.traverse(T,(I,H)=>{const gt=I.p;if(gt!=null){const at=b[gt];at!=null&&H.write("p",at);const q=G[gt];q&&q.get(),q&&H.mergeTree(q.get())}else I.r!==void 0&&H.write("r",I.r)}),T.reset(),T.get(),A.traverse(T,(I,H)=>{const gt=I.d;if(gt!=null){const q=w[gt];q!=null&&H.write("d",q);const Et=W[gt];Et&&H.mergeTree(Et.get())}else I.i!==void 0&&H.write("i",I.i);const at=ht(I);at&&!B.has(I)&&O(H,at,p(I))}),T.get()}function Ct(_){if(_==null)return null;const R=new r.ReadCursor(_),N=new r.WriteCursor;let M;const A=[],T=[];return function G(W,C,S){const b=W.getComponent();let w,B=!1;if(b){b.p!=null&&(C.write("d",b.p),A[b.p]=W.clone()),b.r!==void 0&&C.write("i",b.r),b.d!=null&&(C.write("p",b.d),S=void 0),b.i!==void 0&&(S=w=b.i);const I=ht(b);I&&(S===void 0?(M||(M=new Set),M.add(b)):(p(b),S=I.apply(S,p(b)),B=!0))}let j=0;for(const I of W){C.descend(I);const H=typeof I=="number"?I-j:I,gt=E(S,H);u(W.getComponent())&&j++;const at=G(W,C,gt);if(S!==void 0&&at!==void 0){if(B||(B=!0,S=c(S)),!m(S,H))throw Error("Cannot modify child - invalid operation");S[H]=at}C.ascend()}if(w===void 0)return B?S:void 0;C.write("r",S)}(R,N,void 0),M&&(N.reset(),function G(W,C,S){const b=C.getComponent();if(b){const I=b.d;if(I!=null&&(W=A[I],S=T[I]=r.writeCursor()),M.has(b)){const H=ht(b);if(!H.invert)throw Error(`Cannot invert subtype ${H.name}`);O(S,H,H.invert(p(b)))}}let w=0,B=0;const j=r.advancer(W,(I,H)=>h(H)?w-I-1:I-w,(I,H)=>{h(H)&&w++});for(const I of C)if(typeof I=="number"){const H=I-B,gt=j(H),at=H+w;S.descend(at),G(gt,C,S),u(C.getComponent())&&B++,S.ascend()}else S.descend(I),G(j(I),C,S),S.ascend();j.end()}(R.clone(),R,N),T.length&&(N.reset(),R.traverse(N,(G,W)=>{const C=G.p;if(C!=null){const S=T[C];S&&S.get(),S&&W.mergeTree(S.get())}}))),N.get()}const Tt=(_,R)=>_.some(N=>typeof N=="object"&&(Array.isArray(N)?Tt(N,R):R(N)));function jt(_,R){if(_==null||!Tt(_,C=>{var S;return C.r!==void 0||((S=ht(C))===null||S===void 0?void 0:S.makeInvertible)!=null}))return _;const N=new r.ReadCursor(_),M=new r.WriteCursor;let A=!1;const T=[],G=[],W=(C,S,b)=>{const w=C.getComponent();let B=!1;if(w){w.d!=null&&S.write("d",w.d),w.i!==void 0&&S.write("i",w.i);const I=w.p;if(I!=null&&(T[I]=C.clone(),o(b!==void 0,"Operation picks up at an invalid key"),G[I]=b,S.write("p",w.p)),w.r!==void 0&&b===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const H=ht(w);H&&(H.makeInvertible?A=!0:O(S,H,p(w),!0))}let j=0;for(const I of C){S.descend(I);const H=typeof I=="number"?I-j:I,gt=E(b,H),at=W(C,S,gt);gt!==at&&(B||(B=!0,b=c(b)),at===void 0?(b=d(b,H),typeof I=="number"&&j++):b[H]=at),S.ascend()}return w&&(w.r!==void 0?(S.write("r",s.default(b)),b=void 0):w.p!=null&&(b=void 0)),b};return W(N,M,R),M.get(),A&&(M.reset(),function C(S,b,w,B,j){const I=b.getComponent();if(I){I.i!==void 0?(B=I.i,j=!0):I.d!=null&&(B=G[I.d],S=T[I.d],j=!1,I.d);let q=ht(I);if(q&&q.makeInvertible){const Et=p(I);O(w,q,q.makeInvertible(Et,B),!0)}}let H=0,gt=0;const at=r.advancer(S,(q,Et)=>h(Et)?H-q-1:q-H,(q,Et)=>{h(Et)&&H++});for(const q of b)if(typeof q=="number"){const Et=q-gt,ie=at(Et),xt=Et+H,Mt=E(B,j?Et:xt);w.descend(q),C(ie,b,w,Mt,j),u(b.getComponent())&&gt++,w.ascend()}else{const Et=E(B,q);w.descend(q),C(at(q),b,w,Et,j),w.ascend()}at.end()}(N.clone(),N,M,R,!1)),M.get()}function No(_,R){return Ct(jt(_,R))}const Pn=_=>{if(_==null)return null;const R=_.slice();for(let N=0;N<_.length;N++){const M=R[N];Array.isArray(M)&&(R[N]=Pn(M))}return R};function kn(_,R,N){o(N==="left"||N==="right","Direction must be left or right");const M=N==="left"?0:1;if(R==null)return{ok:!0,result:_};et(_),et(R);let A=null;const T=[],G=[],W=[],C=[],S=[],b=[],w=[],B=[],j=[],I=[],H=[],gt=[],at=[],q=[],Et=[];let ie=0;const xt=r.readCursor(_),Mt=r.readCursor(R),pt=r.writeCursor();if(function ot(y,V=null,k){const U=l(V);U&&(U.r!==void 0?k=V.clone():U.p!=null&&(k=null,b[U.p]=y.clone()));const F=y.getComponent();let nt;F&&(nt=F.p)!=null&&(S[nt]=V?V.clone():null,W[nt]=y.clone(),k&&(I[nt]=!0,j[nt]=k),U&&U.p!=null&&(q[nt]=U.p));const st=r.advancer(V);for(const lt of y)ot(y,st(lt),k);st.end()}(Mt,xt,null),function ot(y,V,k,U,F){const nt=k.getComponent();let st,lt=!1;nt&&((st=nt.d)!=null?(C[st]=k.clone(),U!=null&&(Et[U]==null&&(Et[U]=[]),Et[U].push(st)),y=S[st]||null,V=W[st]||null,I[st]?(F&&(H[st]=!0),F=j[st]||null):!F||M!==1&&q[st]!=null||A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.moveOp(V.getPath(),k.getPath())}),lt=!0):nt.i!==void 0&&(y=V=null,lt=!0,F&&A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.insertOp(k.getPath(),nt.i)})));const vt=l(y);vt&&(vt.r!==void 0?F=y.clone():vt.p!=null&&(vt.p,U=vt.p,F=null));const Nt=ht(nt);Nt&&F&&A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(F.getPath()),op2:t.editOp(k.getPath(),Nt,p(nt),!0)});let Rt=0,Dt=0;const tt=r.advancer(V,(Y,wt)=>h(wt)?Rt-Y-1:Y-Rt,(Y,wt)=>{h(wt)&&Rt++}),L=r.advancer(y);for(const Y of k)if(typeof Y=="number"){const wt=Y-Dt,kt=tt(wt);Dt+=+ot(L(wt+Rt),kt,k,U,F)}else{const wt=tt(Y);ot(L(Y),wt,k,U,F)}return tt.end(),L.end(),lt}(xt,Mt,Mt.clone(),null,null),C.map(ot=>ot&&ot.get()),A)return{ok:!1,conflict:A};H.map(ot=>!!ot);const Vt=[];let qt=null;(function ot(y,V,k,U,F){let nt=!1;const st=l(V);if(h(st)){const tt=st.p;tt!=null?(k=C[tt],U=gt[tt]=r.writeCursor(),nt=!0,F=null):(k=null,F=V.clone())}else u(l(k))&&(k=null);const lt=y.getComponent();if(lt){const tt=lt.p;tt!=null?(F&&(B[tt]=F),Vt[tt]=F||M===1&&nt?null:U.getComponent(),T[tt]=y.clone(),k&&(w[tt]=k.clone())):lt.r!==void 0&&(F||U.write("r",!0),(F||nt)&&(qt==null&&(qt=new Set),qt.add(lt)))}let vt=0,Nt=0;const Rt=r.advancer(V,void 0,(tt,L)=>{h(L)&&vt++}),Dt=r.advancer(k,(tt,L)=>u(L)?~(tt-Nt):tt-Nt,(tt,L)=>{u(L)&&Nt++});if(y)for(const tt of y)if(typeof tt=="string"){const L=Rt(tt),Y=Dt(tt);U.descend(tt),ot(y,L,Y,U,F),U.ascend()}else{const L=Rt(tt),Y=tt-vt,wt=h(l(L))?null:Dt(Y),kt=Y+Nt;o(kt>=0),U.descend(kt),ot(y,L,wt,U,F),U.ascend()}Rt.end(),Dt.end()})(xt,Mt,Mt.clone(),pt,null),pt.reset();let Re=[];if(function ot(y,V,k,U,F,nt){o(V);const st=V.getComponent();let lt=l(U),vt=!1;const Nt=($,mt,Ut)=>$?t.moveOp($.getPath(),mt.getPath()):t.insertOp(mt.getPath(),Ut.i);if(u(st)){const $=st.d;$!=null&&(G[$]=V.clone());const mt=$!=null?Vt[$]:null;let Ut=!1;if(st.i!==void 0||$!=null&&mt){let It;lt&&(lt.i!==void 0||(It=lt.d)!=null&&!I[It])&&(Ut=It!=null?$!=null&&$===q[It]:n.default(lt.i,st.i),Ut||It!=null&&M!==1&&q[It]!=null||A==null&&(A={type:i.ConflictType.DROP_COLLISION,op1:Nt($!=null?T[$]:null,V,st),op2:Nt(It!=null?W[It]:null,U,lt)})),Ut||(nt?A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:Nt($!=null?T[$]:null,V,st),op2:t.removeOp(nt.getPath())}):($!=null?(Re[ie]=$,F.write("d",mt.p=ie++)):F.write("i",s.default(st.i)),vt=!0))}else if($!=null&&!mt){const It=B[$];It&&(nt=It.clone())}$!=null?(y=T[$],k=b[$],U=w[$]):st.i!==void 0&&(y=k=null,Ut||(U=null))}else h(l(y))&&(y=k=U=null);const Rt=l(y),Dt=l(k);if(h(Dt)){const $=Dt.p;Dt.r!==void 0&&(!Rt||Rt.r===void 0)||I[$]?(U=null,nt=k.clone()):$!=null&&(U=C[$],M!==1&&q[$]!=null||((F=at[$])||(F=at[$]=r.writeCursor()),F.reset(),nt=null))}else!u(st)&&u(lt)&&(U=null);lt=U!=null?U.getComponent():null;const tt=ht(st);if(tt){const $=p(st);if(nt)A==null&&(A={type:i.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.editOp(V.getPath(),tt,$,!0),op2:t.removeOp(nt.getPath())});else{const mt=ht(lt);let Ut;if(mt){if(tt!==mt)throw Error("Transforming incompatible types");const It=p(lt);Ut=tt.transform($,It,N)}else Ut=s.default($);O(F,tt,Ut)}}let L=0,Y=0,wt=0,kt=0,le=0,Ce=0,Jt=y!=null&&y.descendFirst(),$e=Jt;const Le=r.advancer(k,void 0,($,mt)=>{h(mt)&&wt++});let ne=U!=null&&U.descendFirst(),se=ne;for(const $ of V)if(typeof $=="number"){let mt;const Ut=u(V.getComponent()),It=$-Y;{let he;for(;Jt&&typeof(he=y.getKey())=="number";){he+=L;const Qt=y.getComponent(),De=h(Qt);if(he>It||he===It&&(!De||M===0&&Ut))break;if(De){L--;const Ie=Qt.p;q.includes(Ie),Qt.d,l(at[Qt.d]),h(l(at[Qt.d])),(Qt.r===void 0||qt&&qt.has(Qt))&&(Ie==null||!Vt[Ie]||M!==1&&q.includes(Ie))||le--}Jt=y.nextSibling()}mt=Jt&&he===It?y:null}const Zt=It-L;let ae=Le(Zt);const Hn=Zt-wt;let sn=null;{let he,Qt;for(;ne&&typeof(he=U.getKey())=="number";){Qt=he-kt;const De=U.getComponent(),Ie=u(De);if(Qt>Hn)break;if(Qt===Hn){if(!Ie){sn=U;break}{if(M===0&&Ut){sn=U;break}const Oe=ae&&h(ae.getComponent());if(M===0&&Oe)break}}if(Ie){const Oe=De.d;q[Oe],De.i===void 0&&(I[Oe]||q[Oe]!=null&&M!==1)?(I[Oe]||q[Oe]!=null&&M===0)&&(kt++,Ce--):kt++}ne=U.nextSibling()}}const Us=Hn+kt+le+Ce;o(Us>=0,"trying to descend to a negative index"),F.descend(Us),Ut&&(mt=ae=sn=null,Y++),ot(mt,V,ae,sn,F,nt)&&Ce++,F.ascend()}else{let mt;for(;Jt&&(mt=y.getKey(),typeof mt!="string"||!(mt>$||mt===$));)Jt=y.nextSibling();const Ut=Jt&&mt===$?y:null,It=Le($);let Zt;for(;ne&&(Zt=U.getKey(),typeof Zt!="string"||!(Zt>$||Zt===$));)ne=U.nextSibling();const ae=ne&&Zt===$?U:null;F.descend($),ot(Ut,V,It,ae,F,nt),F.ascend()}return Le.end(),$e&&y.ascend(),se&&U.ascend(),vt}(xt,xt.clone(),Mt,Mt.clone(),pt,null),A)return{ok:!1,conflict:A};pt.reset();const Kt=(ot,y,V)=>ot.traverse(y,(k,U)=>{k.d!=null&&V(k.d,ot,U)});(I.length||gt.length)&&(Kt(Mt,pt,(ot,y,V)=>{I[ot]&&!H[ot]&&V.write("r",!0),gt[ot]&&V.mergeTree(gt[ot].get())}),pt.reset());const Bt=[],oe=[];if((at.length||I.length)&&!A){const ot=r.readCursor(Pn(pt.get()));if(Kt(ot,null,(y,V)=>{Bt[y]=V.clone()}),at.forEach(y=>{y&&Kt(r.readCursor(y.get()),null,(V,k)=>{Bt[V]=k.clone()})}),function y(V,k,U,F,nt,st){const lt=l(k);if(lt&&h(lt))if(lt.p!=null){const L=lt.p;Bt[L].getPath(),U=Bt[L],F=oe[L]=r.writeCursor()}else lt.r!==void 0&&(U=null);else u(l(U))&&(U=null);const vt=V.getComponent();if(vt){let L;if((L=vt.d)!=null){const Y=at[L];Y&&(Y.get(),F.mergeTree(Y.get()),U=r.readCursor(Y.get()))}}let Nt=0,Rt=0;const Dt=r.advancer(k,void 0,(L,Y)=>{h(Y)&&Nt--}),tt=r.advancer(U,(L,Y)=>u(Y)?-(L-Rt)-1:L-Rt,(L,Y)=>{u(Y)&&Rt++});for(const L of V)if(typeof L=="number"){const Y=Dt(L),wt=L+Nt,kt=tt(wt),le=wt+Rt;F.descend(le),y(V,Y,kt,F),F.ascend()}else F.descend(L),y(V,Dt(L),tt(L),F),F.ascend();Dt.end(),tt.end()}(Mt,ot,ot.clone(),pt),pt.reset(),A)return{ok:!1,conflict:A};if(pt.get(),oe.length){const y=oe.map(k=>k?k.get():null),V=r.readCursor(Pn(pt.get()));if(Kt(V,pt,(k,U,F)=>{const nt=y[k];nt&&(F.mergeTree(nt),y[k]=null)}),y.find(k=>k)){const k=r.writeCursor(),U=r.writeCursor();let F=0,nt=0;y.forEach(st=>{st!=null&&Kt(r.readCursor(st),null,lt=>{const vt=Re[lt];k.writeMove(T[vt].getPath(),G[vt].getPath(),F++);const Nt=Et[vt];Nt&&Nt.forEach(Rt=>{I[Rt]||M!==1&&q[Rt]!=null||U.writeMove(W[Rt].getPath(),C[Rt].getPath(),nt++)})})}),A={type:i.ConflictType.BLACKHOLE,op1:k.get(),op2:U.get()}}}}return A?{ok:!1,conflict:A}:{ok:!0,result:pt.get()}}const Ts=_=>{const R=new Error("Transform detected write conflict");throw R.conflict=_,R.type=R.name="writeConflict",R};function Ao(_,R,N){const M=kn(_,R,N);if(M.ok)return M.result;Ts(M.conflict)}const Ue=_=>{const R=r.writeCursor();return r.readCursor(_).traverse(R,(N,M)=>{(u(N)||ht(N))&&M.write("r",!0)}),R.get()},bo=(_,R)=>{const{type:N,op1:M,op2:A}=_;switch(N){case i.ConflictType.DROP_COLLISION:return R==="left"?[null,Ue(A)]:[Ue(M),null];case i.ConflictType.RM_UNEXPECTED_CONTENT:let T=!1;return r.readCursor(M).traverse(null,G=>{G.r!==void 0&&(T=!0)}),T?[null,Ue(A)]:[Ue(M),null];case i.ConflictType.BLACKHOLE:return[Ue(M),Ue(A)];default:throw Error("Unrecognised conflict: "+N)}};function Ms(_,R,N,M){let A=null;for(;;){const T=kn(R,N,M);if(T.ok)return ft(A,T.result);{const{conflict:G}=T;_(G)||Ts(G);const[W,C]=bo(G,M);R=ft(X(R),W),N=ft(X(N),C),A=ft(A,C)}}}})(Li);(function(t){var e=Wt&&Wt.__createBinding||(Object.create?function(i,o,l,a){a===void 0&&(a=l),Object.defineProperty(i,a,{enumerable:!0,get:function(){return o[l]}})}:function(i,o,l,a){a===void 0&&(a=l),i[a]=o[l]}),n=Wt&&Wt.__exportStar||function(i,o){for(var l in i)l!=="default"&&!o.hasOwnProperty(l)&&e(o,i,l)};Object.defineProperty(t,"__esModule",{value:!0}),n(Li,t);var s=Rs;Object.defineProperty(t,"ReadCursor",{enumerable:!0,get:function(){return s.ReadCursor}}),Object.defineProperty(t,"WriteCursor",{enumerable:!0,get:function(){return s.WriteCursor}});var r=Cs;Object.defineProperty(t,"ConflictType",{enumerable:!0,get:function(){return r.ConflictType}})})($t);const Da=wa($t),ya=To({__proto__:null,default:Da},[$t]);var J=(t=>(t.RETAIN="r",t.INSERT="i",t.DELETE="d",t))(J||{});class ss{constructor(e){g(this,"_index",0);g(this,"_offset",0);this._actions=e}hasNext(){return this.peekLength()<Number.POSITIVE_INFINITY}next(e){e||(e=Number.POSITIVE_INFINITY);const n=this._actions[this._index];if(n){const s=this._offset,r=n.len;return e>=r-s?(e=r-s,this._index+=1,this._offset=0):this._offset+=e,n.t===J.DELETE||n.t===J.RETAIN&&n.body==null?D.deepClone({...n,len:e}):D.deepClone({...n,len:e,body:Je(n.body,s,s+e)})}else return{t:J.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 e=this._actions[this._index];return e?e.t:J.RETAIN}rest(){if(this.hasNext()){if(this._offset===0)return this._actions.slice(this._index);{const e=this._offset,n=this._index,s=this.next(),r=this._actions.slice(this._index);return this._offset=e,this._index=n,[s].concat(r)}}else return[]}}class Di{constructor(){g(this,"cursor",0)}reset(){return this.cursor=0,this}moveCursor(e){this.cursor+=e}moveCursorTo(e){this.cursor=e}}function yi(t,e,n){const{dataStream:s}=t,r=n,i=n+e,o=Oi(t,e,n),l=Si(t,e,n),a=Ni(t,e,n),c=Ai(t,e,n),h=bi(t,e,n),u=vi(t,e,n),d=wi(t,e,n);let f="";return s&&(t.dataStream=Zr(s,r,i),f=s.slice(r,i)),{dataStream:f,textRuns:o,paragraphs:l,sectionBreaks:a,customBlocks:c,tables:h,customRanges:u,customDecorations:d}}function xi(t,e,n,s){t.dataStream=Jr(t.dataStream,s,e.dataStream),Ei(t,e,n,s),_s(t,e,n,s),ga(t,e,n,s),pi(t,e,n,s),Ri(t,e,n,s),Ci(t,e,n,s),Ii(t,e,n,s)}function xa(t,e,n,s,r=Pt.COVER){return Ea(t,e,n,s,r)}function Pa(t,e,n){return e<=0?{dataStream:""}:yi(t,e,n)}function ka(t,e,n,s){n!==0&&xi(t,e,n,s)}function Ha(t,e){const n=new Di;return n.reset(),e.forEach(s=>{switch(s=D.deepClone(s),s.t){case J.RETAIN:{const{coverType:r,body:i,len:o}=s;i!=null&&xa(t,i,o,n.cursor,r),n.moveCursor(o);break}case J.INSERT:{const{body:r,len:i}=s;ka(t,r,i,n.cursor),n.moveCursor(i);break}case J.DELETE:{const{len:r}=s;Pa(t,r,n.cursor);break}default:throw new Error(`Unknown action type for action: ${s}.`)}}),t}function Bs(t){return Object.keys(t).length===1}const Xe=class Xe{constructor(){g(this,"_actions",[])}static apply(e,n){return Ha(e,n)}static compose(e,n){const s=new ss(e),r=new ss(n),i=new Xe;for(;s.hasNext()||r.hasNext();)if(r.peekType()===J.INSERT)i.push(r.next());else if(s.peekType()===J.DELETE)i.push(s.next());else{const o=Math.min(s.peekLength(),r.peekLength()),l=s.next(o),a=r.next(o);l.t===J.INSERT&&a.t===J.RETAIN?a.body==null?i.push(l):i.push({...l,body:ts(l.body,a.body,a.coverType)}):l.t===J.RETAIN&&a.t===J.RETAIN?l.body==null&&a.body==null?i.push(l.len!==Number.POSITIVE_INFINITY?l:a):l.body&&a.body?i.push({...l,body:ts(l.body,a.body,a.coverType)}):i.push(l.body?l:a):l.t===J.RETAIN&&a.t===J.DELETE?i.push(a):l.t===J.INSERT&&(a.t,J.DELETE)}return i.trimEndUselessRetainAction(),i.serialize()}static transform(e,n,s){throw new Error("transform is not implemented in TextX")}static isNoop(e){return e.length===0}static invert(e){const n=[];for(const s of e)if(s.t===J.INSERT)n.push({t:J.DELETE,len:s.len,line:0,body:s.body,segmentId:s.segmentId});else if(s.t===J.DELETE){if(s.body==null)throw new Error("Can not invert DELETE action without body property, makeInvertible must be called first.");n.push({t:J.INSERT,body:s.body,len:s.len,line:0,segmentId:s.segmentId})}else if(s.body!=null){if(s.oldBody==null)throw new Error("Can not invert RETAIN action without oldBody property, makeInvertible must be called first.");n.push({t:J.RETAIN,body:s.oldBody,oldBody:s.body,len:s.len,coverType:Pt.REPLACE,segmentId:s.segmentId})}else n.push(s);return n}static makeInvertible(e,n){const s=[];let r=0;for(const i of e){if(i.t===J.DELETE&&i.body==null){const o=Je(n,r,r+i.len,!1);i.len=o.dataStream.length,i.body=o}if(i.t===J.RETAIN&&i.body!=null){const o=Je(n,r,r+i.len,!0);i.oldBody={...o,dataStream:""},i.len=o.dataStream.length}s.push(i),i.t!==J.INSERT&&(r+=i.len)}return s}insert(e,n,s=""){const r={t:J.INSERT,body:n,len:e,line:0,segmentId:s};return this.push(r),this}retain(e,n="",s,r){const i={t:J.RETAIN,len:e,segmentId:n};return s!=null&&(i.body=s),r!=null&&(i.coverType=r),this.push(i),this}delete(e,n=""){const s={t:J.DELETE,len:e,line:0,segmentId:n};return this.push(s),this}serialize(){return this._actions}push(...e){if(e.length>1){for(const i of e)this.push(i);return this}let n=this._actions.length,s=this._actions[n-1];const r=D.deepClone(e[0]);if(r.t===J.RETAIN&&r.len===0&&r.body==null)return this;if(typeof s=="object"){if(s.t===J.DELETE&&r.t===J.DELETE)return s.len+=r.len,this;if(s.t===J.DELETE&&r.t===J.INSERT&&(n-=1,s=this._actions[n-1],s==null))return this._actions.unshift(r),this;if(s.t===J.RETAIN&&r.t===J.RETAIN&&s.body==null&&r.body==null)return s.len+=r.len,this;if(s.t===J.INSERT&&Bs(s.body)&&r.t===J.INSERT&&Bs(r.body))return s.len+=r.len,s.body.dataStream+=r.body.dataStream,this}return n===this._actions.length?this._actions.push(r):this._actions.splice(n,0,r),this}trimEndUselessRetainAction(){let e=this._actions[this._actions.length-1];for(;e&&e.t===J.RETAIN&&ba(e);)this._actions.pop(),e=this._actions[this._actions.length-1];return this}};g(Xe,"id","text-x"),g(Xe,"uri","https://github.com/dream-num/univer#text-x");let Ee=Xe;Object.defineProperty(Ee,"name",{value:"text-x"});const ye=class ye{static registerSubtype(e){var n;this._subTypes.has(e.name)&&((n=this._subTypes.get(e.name))==null?void 0:n.id)!==Ee.id||(this._subTypes.set(e.name,e),$t.type.registerSubtype(e))}static apply(e,n){if(!$t.type.isNoop(n))return $t.type.apply(e,n)}static compose(e,n){return $t.type.compose(e,n)}static transform(e,n,s){throw new Error("transform is not implemented in JsonX")}static invertWithDoc(e,n){return $t.type.invertWithDoc(e,n)}static isNoop(e){return $t.type.isNoop(e)}static getInstance(){return this._instance==null&&(this._instance=new ye),this._instance}removeOp(e,n){return $t.removeOp(e,n)}moveOp(e,n){return $t.moveOp(e,n)}insertOp(e,n){return $t.insertOp(e,n)}replaceOp(e,n,s){return $t.replaceOp(e,n,s)}editOp(e,n=["body"]){return $t.editOp(n,Ee.name,e)}};g(ye,"uri","https://github.com/dream-num/univer#json-x"),g(ye,"_subTypes",new Map),g(ye,"_instance",null);let ve=ye;ve.registerSubtype(Ee);const Os={id:"default_doc",documentStyle:{}};class Fa extends Mn{constructor(n){super();g(this,"type",Z.UNIVER_DOC);g(this,"snapshot");this.snapshot={...Os,...n}}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 zoomRatio(){var n;return((n=this.snapshot.settings)==null?void 0:n.zoomRatio)||1}resetDrawing(n,s){this.snapshot.drawings=n,this.snapshot.drawingsOrder=s}getBody(){return this.snapshot.body}getShouldRenderLoopImmediately(){return this.snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this.snapshot.container}getSnapshot(){return this.snapshot}updateDocumentId(n){this.snapshot.id=n}updateDocumentRenderConfig(n){const{documentStyle:s}=this.snapshot;s.renderConfig==null?s.renderConfig=n:s.renderConfig={...s.renderConfig,...n}}updateDocumentStyle(n){this.snapshot.documentStyle==null?this.snapshot.documentStyle=n:this.snapshot.documentStyle={...this.snapshot.documentStyle,...n}}updateDocumentDataMargin(n){const{t:s,l:r,b:i,r:o}=n,{documentStyle:l}=this.snapshot;s!=null&&(l.marginTop=s),r!=null&&(l.marginLeft=r),i!=null&&(l.marginBottom=i),o!=null&&(l.marginRight=o)}updateDocumentDataPageSize(n,s){const{documentStyle:r}=this.snapshot;if(!r.pageSize){n=n!=null?n:Number.POSITIVE_INFINITY,s=s!=null?s:Number.POSITIVE_INFINITY,r.pageSize={width:n,height:s};return}n!==void 0&&(r.pageSize.width=n),s!==void 0&&(r.pageSize.height=s)}updateDrawing(n,s){const{drawings:r}=this,{width:i,height:o,left:l,top:a}=s,c=r==null?void 0:r[n];if(!c)return;const h=c.docTransform;h.size.width=i,h.size.height=o,h.positionH.posOffset=l,h.positionV.posOffset=a}setZoomRatio(n=1){this.snapshot.settings==null?this.snapshot.settings={zoomRatio:n}:this.snapshot.settings.zoomRatio=1}}class we extends Fa{constructor(n){var r;super(D.isEmptyObject(n)?va():n);g(this,"_unitId");g(this,"headerModelMap",new Map);g(this,"footerModelMap",new Map);const s=6;this._unitId=(r=this.snapshot.id)!=null?r:D.generateRandomId(s),this._initializeHeaderFooterModel()}dispose(){this.headerModelMap.forEach(n=>{n.dispose()}),this.footerModelMap.forEach(n=>{n.dispose()})}getDrawings(){return this.snapshot.drawings}getDrawingsOrder(){return this.snapshot.drawingsOrder}getCustomRanges(){var n;return(n=this.snapshot.body)==null?void 0:n.customRanges}getCustomDecorations(){var n;return(n=this.snapshot.body)==null?void 0:n.customDecorations}getRev(){var n;return(n=this.snapshot.rev)!=null?n:1}incrementRev(){this.snapshot.rev=this.getRev()+1}getSettings(){return this.snapshot.settings}reset(n){if(n.id&&n.id!==this._unitId)throw new Error("Cannot reset a document model with a different unit id!");this.snapshot={...Os,...n},this._initializeHeaderFooterModel()}getSelfOrHeaderFooterModel(n){if(n!=null){if(this.headerModelMap.has(n))return this.headerModelMap.get(n);if(this.footerModelMap.has(n))return this.footerModelMap.get(n)}return this}getUnitId(){return this._unitId}apply(n){if(!ve.isNoop(n))return this.snapshot=ve.apply(this.snapshot,n),n!=null&&n.some(s=>Array.isArray(s)&&((s==null?void 0:s[0])==="headers"||(s==null?void 0:s[0])==="footers"))&&(this.headerModelMap.clear(),this.footerModelMap.clear(),this._initializeHeaderFooterModel()),this.snapshot}sliceBody(n,s){const r=this.getBody();if(r!=null)return Je(r,n,s)}_initializeHeaderFooterModel(){const{headers:n,footers:s}=this.getSnapshot();if(n)for(const r in n){const i=n[r];this.headerModelMap.set(r,new we(i))}if(s)for(const r in s){const i=s[r];this.footerModelMap.set(r,new we(i))}}updateDocumentId(n){super.updateDocumentId(n),this._unitId=n}}const Pi=ut.createIdentifier("univer.config-service");class ki{constructor(){g(this,"_config",new Map)}getConfig(e){return this._config.get(e)}setConfig(e,n){this._config.set(e,n)}deleteConfig(e){this._config.delete(e)}}class Hi extends yt{constructor(){super(...arguments);g(this,"_error$",new rt.Subject);g(this,"error$",this._error$.asObservable())}dispose(){this._error$.complete()}emit(n){this._error$.next({errorKey:n})}}class Fi{constructor(e={}){g(this,"_styles");g(this,"_cacheMap",new si(1e5));this._styles=e,this._generateCacheMap()}each(e){return Object.entries(this._styles).forEach(e),this}search(e,n){if(this._cacheMap.has(n))return this._cacheMap.get(n);const s=this._getExistingStyleId(e);return s||"-1"}get(e){return typeof e!="string"?e:(e=String(e),this._styles[e])}add(e,n){const s=D.generateRandomId(6);return this._styles[s]=e,this._cacheMap.set(n,s),s}setValue(e){if(e==null)return;const n=JSON.stringify(e),s=this.search(e,n);return s!=="-1"?s:this.add(e,n)}toJSON(){return this._styles}getStyleByCell(e){let n;e&&D.isObject(e.s)?n=e.s:n=(e==null?void 0:e.s)&&this.get(e.s);const s=e==null?void 0:e.interceptorStyle;return s?{...n,...s}:n}_generateCacheMap(){const{_styles:e,_cacheMap:n}=this;for(const s in e){const r=JSON.stringify(e[s]);n.set(r,s)}}_getExistingStyleId(e){const{_styles:n}=this;for(const s in n)if(D.diffValue(n[s],e))return s;return null}}class $a{constructor(e,n){g(this,"_columnData",{});this._config=e,this._columnData=n}getColumnData(){return this._columnData}getColVisible(e){const{_columnData:n}=this,s=n[e];return s?s.hd!==K.TRUE:!0}getHiddenCols(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getColVisible(o);r&&l?(r=!1,s.push({rangeType:it.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&!l&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:n,rangeType:it.COLUMN}),s}getVisibleCols(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getColVisible(o);r&&!l?(r=!1,s.push({rangeType:it.COLUMN,startColumn:i,endColumn:o-1,startRow:0,endRow:0})):!r&&l&&(r=!0,i=o)}return r&&s.push({startRow:0,endRow:0,startColumn:i,endColumn:n,rangeType:it.COLUMN}),s}getColumnDatas(e,n){const s={};let r=0;for(let i=e;i<e+n;i++){const o=this.getColumnOrCreate(i);s[r]=o,r++}return s}getSize(){return _e(this._columnData)}getColumnWidth(e){const{_columnData:n}=this,s=this._config;let r=0;return r=(n[e]||{hd:K.FALSE,w:s.defaultColumnWidth}).w||s.defaultColumnWidth,r}getColumn(e){const n=this._columnData[e];if(n)return n}getColumnOrCreate(e){const{_columnData:n}=this,s=this._config,r=n[e];if(r)return r;const i={w:s.defaultColumnWidth,hd:K.FALSE};return this._columnData[e]=i,i}}class Wa{constructor(e,n,s){g(this,"_rowData");this._config=e,this._viewModel=n,this._rowData=s}getRowData(){return this._rowData}getRowDatas(e,n){const s={};let r=0;for(let i=e;i<e+n;i++){const o=this.getRowOrCreate(i);s[r]=o,r++}return s}getRowHeight(e,n=1){const{_rowData:s}=this,r=this._config;let i=0;for(let o=0;o<n;o++){const l=s[o+e]||{hd:K.FALSE,h:r.defaultRowHeight},{ia:a,ah:c,h=r.defaultRowHeight}=l;i+=(a==null||a===K.TRUE)&&typeof c=="number"?c:h}return i}getRow(e){return this._rowData[e]}getRowOrCreate(e){const{_rowData:n}=this,s=n[e];if(s)return s;const r=this._config,i={hd:K.FALSE,h:r.defaultRowHeight};return n[e]=i,i}getHiddenRows(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getRowRawVisible(o);r&&l?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:it.ROW})):!r&&!l&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:n,startColumn:0,endColumn:0,rangeType:it.ROW}),s}getVisibleRows(e=0,n=this.getSize()-1){const s=[];let r=!1,i=-1;for(let o=e;o<=n;o++){const l=this.getRowRawVisible(o);r&&!l?(r=!1,s.push({startRow:i,endRow:o-1,startColumn:0,endColumn:0,rangeType:it.ROW})):!r&&l&&(r=!0,i=o)}return r&&s.push({startRow:i,endRow:n,startColumn:0,endColumn:0,rangeType:it.ROW}),s}getRowRawVisible(e){const n=this.getRow(e);return n?n.hd!==K.TRUE:!0}getSize(){return _e(this._rowData)}}const Ba="DEFAULT_WORKSHEET_ROW_COUNT",$i=1e3,Ga="DEFAULT_WORKSHEET_COLUMN_COUNT",Wi=20,ja="DEFAULT_WORKSHEET_ROW_HEIGHT",Bi=24,Va="DEFAULT_WORKSHEET_COLUMN_WIDTH",Gi=88,Ka="DEFAULT_WORKSHEET_ROW_TITLE_WIDTH",ji=46,Ya="DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT",Vi=20;function Ki(t){const e={name:"Sheet1",id:"sheet-01",tabColor:"",hidden:K.FALSE,rowCount:$i,columnCount:Wi,zoomRatio:1,freeze:{xSplit:0,ySplit:0,startRow:-1,startColumn:-1},scrollTop:0,scrollLeft:0,defaultColumnWidth:Gi,defaultRowHeight:Bi,mergeData:[],cellData:{},rowData:{},columnData:{},showGridlines:K.TRUE,rowHeader:{width:ji,hidden:K.FALSE},columnHeader:{height:Vi,hidden:K.FALSE},selections:["A1"],rightToLeft:K.FALSE};return Object.keys(e).forEach(n=>{const s=n;typeof t[s]>"u"&&(t[s]=e[s])}),t}class Yi extends yt{constructor(n){super();g(this,"_cellContentInterceptor",null);g(this,"_rowFilteredInterceptor",null);this.getRawCell=n}dispose(){super.dispose(),this._cellContentInterceptor=null,this._rowFilteredInterceptor=null}getCell(n,s){return this._cellContentInterceptor?this._cellContentInterceptor.getCell(n,s):this.getRawCell(n,s)}getRowFiltered(n){var s,r;return(r=(s=this._rowFilteredInterceptor)==null?void 0:s.getRowFiltered(n))!=null?r:!1}registerCellContentInterceptor(n){if(this._cellContentInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._cellContentInterceptor=n,bt(()=>this._cellContentInterceptor=null)}registerRowFilteredInterceptor(n){if(this._rowFilteredInterceptor)throw new Error("[SheetViewModel]: Interceptor already registered.");return this._rowFilteredInterceptor=n,bt(()=>this._rowFilteredInterceptor=null)}}class Ze{constructor(e,n,s){g(this,"_sheetId");g(this,"_snapshot");g(this,"_cellData");g(this,"_rowManager");g(this,"_columnManager");g(this,"_viewModel");var l;this.unitId=e,this._styles=s,this._snapshot=Ki(n);const{columnData:r,rowData:i,cellData:o}=this._snapshot;this._sheetId=(l=this._snapshot.id)!=null?l:D.generateRandomId(6),this._cellData=new ee(o),this._viewModel=new Yi((a,c)=>this.getCellRaw(a,c)),this._rowManager=new Wa(this._snapshot,this._viewModel,i),this._columnManager=new $a(this._snapshot,r)}__interceptViewModel(e){e(this._viewModel)}getSnapshot(){return this._snapshot}getCellMatrix(){return this._cellData}getCellMatrixPrintRange(){const e=this.getCellMatrix(),n=this.getMergeData();let s=-1,r=-1,i=-1,o=-1,l=!1,a=!1;return e.forEach((c,h)=>{Object.keys(h).forEach(u=>{const d=+u,f=e.getValue(c,d),m=f!=null&&f.s?this._styles.get(f.s):null,E=(m==null?void 0:m.bd)&&(m.bd.b||m.bd.l||m.bd.r||m.bd.t||m.bd.bc_tr||m.bd.bl_tr||m.bd.ml_tr||m.bd.tl_bc||m.bd.tl_br||m.bd.tl_mr);(f&&(f.v||f.p)||m!=null&&m.bg||E)&&(l?s=Math.min(s,c):(s=c,l=!0),r=Math.max(r,c),a?i=Math.min(i,d):(a=!0,i=d),o=Math.max(o,d))})}),n.forEach(c=>{l?s=Math.min(s,c.startRow):(s=c.startRow,l=!0),r=Math.max(r,c.endRow),a?i=Math.min(i,c.startColumn):(i=c.startColumn,l=!0),o=Math.max(o,c.endColumn)}),!l||!a?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:e}=this,n=D.deepClone(e);return new Ze(this.unitId,n,this._styles)}getMergeData(){return this._snapshot.mergeData}getMergedCell(e,n){const s=this._snapshot.mergeData;for(let r=0;r<s.length;r++){const i=s[r];if(me.intersects({startRow:e,startColumn:n,endRow:e,endColumn:n},i))return i}return null}getCell(e,n){return e<0||n<0?null:this._viewModel.getCell(e,n)}getCellRaw(e,n){return this.getCellMatrix().getValue(e,n)}getRowFiltered(e){return this._viewModel.getRowFiltered(e)}getMatrixWithMergedCells(e,n,s,r,i=!1){const o=this.getCellMatrix(),l=this._snapshot.mergeData.filter(c=>me.intersects({startRow:e,startColumn:n,endRow:s,endColumn:r},c)),a=new ee;return Zn(e,s,n,r).forEach((c,h)=>{const u=i?this.getCellRaw(c,h):this.getCell(c,h);u&&a.setValue(c,h,u)}),l.forEach(c=>{const{startColumn:h,startRow:u,endColumn:d,endRow:f}=c;Zn(u,f,h,d).forEach((m,E)=>{m===u&&E===h&&a.setValue(m,E,{...o.getValue(m,E),rowSpan:f-u+1,colSpan:d-h+1}),(m!==u||E!==h)&&a.realDeleteValue(m,E)})}),a}getRange(e,n,s,r){return typeof e=="object"?new He(this,e,{getStyles:()=>this._styles}):new He(this,{startRow:e,startColumn:n,endColumn:r||n,endRow:s||e},{getStyles:()=>this._styles})}getScrollLeftTopFromSnapshot(){return{scrollLeft:this._snapshot.scrollLeft,scrollTop:this._snapshot.scrollTop}}getZoomRatio(){return this._snapshot.zoomRatio||1}getConfig(){return this._snapshot}getFreeze(){return this._snapshot.freeze}getMaxColumns(){const{_snapshot:e}=this,{columnCount:n}=e;return n}getMaxRows(){const{_snapshot:e}=this,{rowCount:n}=e;return n}getRowCount(){return this._snapshot.rowCount}setRowCount(e){this._snapshot.rowCount=e}getColumnCount(){return this._snapshot.columnCount}setColumnCount(e){this._snapshot.columnCount=e}isSheetHidden(){return this._snapshot.hidden}hasHiddenGridlines(){const{_snapshot:e}=this,{showGridlines:n}=e;return n===0}getTabColor(){const{_snapshot:e}=this,{tabColor:n}=e;return n}getColumnWidth(e){return this.getColumnManager().getColumnWidth(e)}getRowHeight(e){return this._viewModel.getRowFiltered(e)?0:this.getRowManager().getRowHeight(e)}getRowVisible(e){return this._viewModel.getRowFiltered(e)?!1:this.getRowRawVisible(e)}getRowRawVisible(e){return this.getRowManager().getRowRawVisible(e)}getHiddenRows(e,n){const s=this.getMaxColumns()-1,r=this._rowManager.getHiddenRows(e,n);return r.forEach(i=>i.endColumn=s),r}getColVisible(e){return this._columnManager.getColVisible(e)}getHiddenCols(e,n){const s=this.getMaxRows()-1,r=this._columnManager.getHiddenCols(e,n);return r.forEach(i=>i.endRow=s),r}getVisibleRows(){const e=this.getRowCount();return this._rowManager.getVisibleRows(0,e-1)}getVisibleCols(){const e=this.getColumnCount();return this._columnManager.getVisibleCols(0,e-1)}isRightToLeft(){const{_snapshot:e}=this,{rightToLeft:n}=e;return n}getLastRowWithContent(){return this._cellData.getLength()-1}getLastColumnWithContent(){return this._cellData.getRange().endColumn}cellHasValue(e){return e&&(e.v!==void 0||e.f!==void 0||e.p!==void 0)}iterateByRow(e,n=!0){const{startRow:s,startColumn:r,endRow:i,endColumn:o}=e,l=this;return{[Symbol.iterator]:()=>{let a=s,c=r;return{next(){for(;;){if(c>o&&(a+=1,c=r),a>i)return{done:!0,value:void 0};const h=l.getCell(a,c),u=!h,d=l.getMergedCell(a,c);if(d){if(a!==d.startRow||c!==d.startColumn){c=d.endColumn+1;continue}if(u&&n){c=d.endColumn+1;continue}const m={row:a,col:c,value:h};return m.colSpan=d.endColumn-d.startColumn+1,m.rowSpan=d.endRow-d.startRow+1,c=d.endColumn+1,{done:!1,value:m}}if(u&&n)c+=1;else{const f={row:a,col:c,value:h};return c+=1,{done:!1,value:f}}}}}}}}iterateByColumn(e,n=!0,s=!0){const{startRow:r,startColumn:i,endRow:o,endColumn:l}=e,a=this;return{[Symbol.iterator]:()=>{let c=r,h=i;return{next(){for(;;){if(c>o&&(h+=1,c=r),h>l)return{done:!0,value:void 0};const u=a.getMergedCell(c,h);if(u){const m=c!==u.startRow,E=m||h!==u.startColumn;if(s&&E||!s&&m){c=u.endRow+1;continue}const P=a.getCell(u.startRow,u.startColumn);if(!P&&n){c=u.endRow+1;continue}const Q={row:c,col:u.startColumn,value:P};return Q.colSpan=u.endColumn-u.startColumn+1,Q.rowSpan=u.endRow-u.startRow+1,c=u.endRow+1,{done:!1,value:Q}}const d=a.getCell(c,h);if(!d&&n)c+=1;else{const m={row:c,col:h,value:d};return c+=1,{done:!1,value:m}}}}}}}}}function za(t){var s,r;if(!t)return"";const e=(r=(s=t.p)==null?void 0:s.body)==null?void 0:r.dataStream;if(e)return e;const n=t.v;return typeof n=="string"?t.t===Ae.BOOLEAN?n.toUpperCase():n.replace(/[\r\n]/g,""):typeof n=="number"?t.t===Ae.BOOLEAN?n?"TRUE":"FALSE":n.toString():typeof n=="boolean"?n?"TRUE":"FALSE":""}const Xa="0.2.2";function qa(t="",e=Te.ZH_CN,n=""){return{id:t,sheetOrder:[],name:n,appVersion:Xa,locale:e,styles:{},sheets:{},resources:[]}}var Ja=Object.defineProperty,Za=Object.getOwnPropertyDescriptor,Qa=(t,e,n,s)=>{for(var r=s>1?void 0:s?Za(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&Ja(e,n,r),r},tu=(t,e)=>(n,s)=>e(n,s,t);function eu(t,e){return`${t.getUnitId()}|${e.getSheetId()}`}exports.Workbook=class extends Mn{constructor(n={},s){super();g(this,"type",Z.UNIVER_SHEET);g(this,"_sheetCreated$",new rt.Subject);g(this,"sheetCreated$",this._sheetCreated$.asObservable());g(this,"_sheetDisposed$",new rt.Subject);g(this,"sheetDisposed$",this._sheetDisposed$.asObservable());g(this,"_activeSheet$",new rt.BehaviorSubject(null));g(this,"activeSheet$",this._activeSheet$.asObservable());g(this,"_worksheets");g(this,"_styles");g(this,"_snapshot");g(this,"_unitId");g(this,"_count");g(this,"_name$");g(this,"name$");this._logService=s;const r=qa();D.isEmptyObject(n)?this._snapshot=r:this._snapshot=D.commonExtend(r,n);const{styles:i}=this._snapshot;(this._snapshot.id==null||this._snapshot.id.length===0)&&(this._snapshot.id=D.generateRandomId(6)),this._unitId=this._snapshot.id,this._styles=new Fi(i),this._count=1,this._worksheets=new Map,this._name$=new rt.BehaviorSubject(n.name||""),this.name$=this._name$.asObservable(),this._passWorksheetSnapshots()}get _activeSheet(){return this._activeSheet$.getValue()}get name(){return this._name$.getValue()}dispose(){super.dispose(),this._sheetCreated$.complete(),this._sheetDisposed$.complete(),this._activeSheet$.complete(),this._name$.complete()}save(){return D.deepClone(this._snapshot)}static isIRangeType(n){return typeof n=="string"||"startRow"in n||"row"in n}getSnapshot(){return this._snapshot}getName(){return this._snapshot.name}setName(n){this._name$.next(n),this._snapshot.name=n}getUnitId(){return this._unitId}getRev(){var n;return(n=this._snapshot.rev)!=null?n:1}incrementRev(){this._snapshot.rev=this.getRev()+1}getShouldRenderLoopImmediately(){return this._snapshot.shouldStartRenderingImmediately!==!1}getContainer(){return this._snapshot.container}addWorksheet(n,s,r){const{sheets:i,sheetOrder:o}=this._snapshot;if(i[n])return!1;i[n]=r,o.splice(s,0,n);const l=new Ze(this._unitId,r,this._styles);return this._worksheets.set(n,l),this._sheetCreated$.next(l),!0}getSheetOrders(){return this._snapshot.sheetOrder}getWorksheets(){return this._worksheets}getActiveSpreadsheet(){return this}getStyles(){return this._styles}getConfig(){return this._snapshot}getIndexBySheetId(n){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>r===n)}getActiveSheet(){return this._activeSheet}ensureActiveSheet(){const n=this.getActiveSheet();if(n)return n;const s=this._snapshot.sheetOrder;for(let i=0,o=s.length;i<o;i++){const l=this._worksheets.get(s[i]);if(l&&l.isSheetHidden()!==K.TRUE)return this.setActiveSheet(l),l}const r=this._worksheets.get(s[0]);return this.setActiveSheet(r),r}setActiveSheet(n){this._activeSheet$.next(n)}removeSheet(n){var r;const s=this._worksheets.get(n);return s?(((r=this._activeSheet)==null?void 0:r.getSheetId())===n&&this.setActiveSheet(null),this._worksheets.delete(n),this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(n),1),delete this._snapshot.sheets[n],this._sheetDisposed$.next(s),!0):!1}getActiveSheetIndex(){const{sheetOrder:n}=this._snapshot;return n.findIndex(s=>this._worksheets.get(s)===this._activeSheet)}getSheetSize(){return this._snapshot.sheetOrder.length}getSheets(){const{sheetOrder:n}=this._snapshot;return n.map(s=>this._worksheets.get(s))}getSheetsName(){const{sheetOrder:n}=this._snapshot,s=[];return n.forEach(r=>{const i=this._worksheets.get(r);i&&s.push(i.getName())}),s}getSheetIndex(n){const{sheetOrder:s}=this._snapshot;return s.findIndex(r=>n.getSheetId()===r)}getSheetBySheetName(n){const{sheetOrder:s}=this._snapshot,r=s.find(i=>this._worksheets.get(i).getName()===n);return this._worksheets.get(r)}getSheetBySheetId(n){return this._worksheets.get(n)}getSheetByIndex(n){const{sheetOrder:s}=this._snapshot;return this._worksheets.get(s[n])}getHiddenWorksheets(){return this.getSheets().filter(n=>n.getConfig().hidden===K.TRUE).map(n=>n.getConfig().id)}getUnhiddenWorksheets(){return this.getSheets().filter(n=>n.getConfig().hidden!==K.TRUE).map(n=>n.getConfig().id)}load(n){this._snapshot=n}checkSheetName(n){return this.getSheetsName().includes(n)}uniqueSheetName(n="Sheet1"){let s=n;for(;this.checkSheetName(s);)s=n+this._count,this._count++;return s}generateNewSheetName(n){let s=n+this._count;for(;this.checkSheetName(s);)s=n+this._count,this._count++;return s}_passWorksheetSnapshots(){const{_snapshot:n,_worksheets:s}=this,{sheets:r,sheetOrder:i}=n;if(D.isEmptyObject(r)){const o=D.generateRandomId();r[o]={id:o}}for(const o in r){const l=r[o],{name:a}=l;l.name=this.uniqueSheetName(a),l.name!==a&&this._logService.debug("[Workbook]",`The worksheet name ${a} is duplicated, we changed it to ${l.name}. Please fix the problem in your snapshot.`);const c=new Ze(this._unitId,l,this._styles);s.set(o,c),i.includes(o)||i.push(o)}this.ensureActiveSheet()}};exports.Workbook=Qa([tu(1,pe)],exports.Workbook);class Ss extends Mn{constructor(n){var s;super();g(this,"type",Z.UNIVER_SLIDE);g(this,"_snapshot");g(this,"_unitId");this._snapshot={...oi,...n},this._unitId=(s=this._snapshot.id)!=null?s:D.generateRandomId(6)}getContainer(){return this._snapshot.container}getSnapshot(){return this._snapshot}getUnitId(){return this._unitId}getPages(){var n;return(n=this._snapshot.body)==null?void 0:n.pages}getPageOrder(){var n;return(n=this._snapshot.body)==null?void 0:n.pageOrder}getPage(n){const s=this.getPages();return s==null?void 0:s[n]}getElementsByPage(n){var s;return(s=this.getPage(n))==null?void 0:s.pageElements}getElement(n,s){var r;return(r=this.getElementsByPage(n))==null?void 0:r[s]}getPageSize(){return this._snapshot.pageSize}addPage(){return{id:"cover_1",pageType:as.SLIDE,zIndex:1,title:"cover",description:"this is first page, cover",pageBackgroundFill:{rgb:"rgb(255,255,255)"},pageElements:{}}}}const Ke="FOCUSING_SHEET",gn="FOCUSING_DOC",_n="FOCUSING_SLIDE",nu="FOCUSING_EDITOR_BUT_HIDDEN",zi="EDITOR_ACTIVATED",su="FOCUSING_EDITOR_INPUT_FORMULA",Xi="FOCUSING_FORMULA_EDITOR",ru="FOCUSING_UNIVER_EDITOR",iu="FOCUSING_EDITOR_INPUT_FORMULA",ou="FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE",lu="FOCUSING_COMMON_DRAWINGS";var au=Object.defineProperty,uu=Object.getOwnPropertyDescriptor,cu=(t,e,n,s)=>{for(var r=s>1?void 0:s?uu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&au(e,n,r),r},Gs=(t,e)=>(n,s)=>e(n,s,t);const Fe=ut.createIdentifier("univer.current");exports.UniverInstanceService=class extends yt{constructor(n,s){super();g(this,"_unitsByType",new Map);g(this,"_createHandler");g(this,"_ctorByType",new Map);g(this,"_currentUnits",new Map);g(this,"_currentUnits$",new rt.BehaviorSubject(this._currentUnits));g(this,"currentUnits$",this._currentUnits$.asObservable());g(this,"_unitAdded$",new rt.Subject);g(this,"unitAdded$",this._unitAdded$.asObservable());g(this,"_unitDisposed$",new rt.Subject);g(this,"unitDisposed$",this._unitDisposed$.asObservable());g(this,"_focused$",new rt.BehaviorSubject(null));g(this,"focused$",this._focused$.asObservable());this._injector=n,this._contextService=s}dispose(){super.dispose(),this._focused$.complete()}__setCreateHandler(n){this._createHandler=n}createUnit(n,s){return this._createHandler(n,s,this._ctorByType.get(n))}registerCtorForType(n,s){return this._ctorByType.set(n,s),{dispose:()=>{this._ctorByType.delete(n)}}}getCurrentTypeOfUnit$(n){return this.currentUnits$.pipe(rt.map(s=>{var r;return(r=s.get(n))!=null?r:null}),rt.distinctUntilChanged())}getCurrentUnitForType(n){return this._currentUnits.get(n)}setCurrentUnitForType(n){const s=this._getUnitById(n);if(!s)throw new Error(`[UniverInstanceService]: no document with unitId ${n}!`);this._currentUnits.set(s[1],s[0]),this._currentUnits$.next(this._currentUnits)}_removeCurrentUnitForType(n){this._currentUnits.set(n,null),this._currentUnits$.next(this._currentUnits)}getTypeOfUnitAdded$(n){return this._unitAdded$.pipe(rt.filter(s=>s.type===n))}__addUnit(n){const s=n.type;this._unitsByType.has(s)||this._unitsByType.set(s,[]),this._unitsByType.get(s).push(n),this._unitAdded$.next(n),this.setCurrentUnitForType(n.getUnitId())}getTypeOfUnitDisposed$(n){return this.unitDisposed$.pipe(rt.filter(s=>s.type===n))}getUnit(n,s){var i;const r=(i=this._getUnitById(n))==null?void 0:i[0];return s&&(r==null?void 0:r.type)!==s?null:r}getCurrentUniverDocInstance(){return this.getCurrentUnitForType(Z.UNIVER_DOC)}getUniverDocInstance(n){return this.getUnit(n,Z.UNIVER_DOC)}getUniverSheetInstance(n){return this.getUnit(n,Z.UNIVER_SHEET)}getAllUnitsForType(n){var s;return(s=this._unitsByType.get(n))!=null?s:[]}changeDoc(n,s){const r=this.getAllUnitsForType(Z.UNIVER_DOC),i=r.find(o=>o.getUnitId()===n);if(i!=null){const o=r.indexOf(i);r.splice(o,1)}this.__addUnit(s)}get focused(){var s;const n=this._focused$.getValue();return n?(s=this._getUnitById(n))==null?void 0:s[0]:null}focusUnit(n){this._focused$.next(n),this.focused instanceof exports.Workbook?(this._contextService.setContextValue(gn,!1),this._contextService.setContextValue(Ke,!0),this._contextService.setContextValue(_n,!1)):this.focused instanceof we?(this._contextService.setContextValue(gn,!0),this._contextService.setContextValue(Ke,!1),this._contextService.setContextValue(_n,!1)):this.focused instanceof Ss&&(this._contextService.setContextValue(gn,!1),this._contextService.setContextValue(Ke,!1),this._contextService.setContextValue(_n,!0))}getFocusedUnit(){return this.focused}getUnitType(n){const s=this._getUnitById(n);if(!s)throw new Error(`[UniverInstanceService]: No document with unitId ${n}`);return s[1]}disposeUnit(n){const s=this._getUnitById(n);if(!s)return!1;const[r,i]=s,o=this._unitsByType.get(i),l=o.indexOf(r);return o.splice(l,1),this._removeCurrentUnitForType(i),this._focused$.next(null),this._unitDisposed$.next(r),!0}_getUnitById(n){for(const[s,r]of this._unitsByType){const i=r.find(o=>o.getUnitId()===n);if(i)return[i,s]}}};exports.UniverInstanceService=cu([Gs(0,ut.Inject(ut.Injector)),Gs(1,Qe)],exports.UniverInstanceService);var Ot=(t=>(t[t.Starting=0]="Starting",t[t.Ready=1]="Ready",t[t.Rendered=2]="Rendered",t[t.Steady=3]="Steady",t))(Ot||{});const hu={0:"Starting",1:"Ready",2:"Rendered",3:"Steady"},mn=new Map;function qi(t,e){return function(r){Un(t,e)}}function Un(t,e){mn.has(t)||mn.set(t,[]),mn.get(t).push(e)}var du=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,Ji=(t,e,n,s)=>{for(var r=s>1?void 0:s?fu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&du(e,n,r),r},rs=(t,e)=>(n,s)=>e(n,s,t);exports.LifecycleService=class extends yt{constructor(n){super();g(this,"_lifecycle$",new rt.BehaviorSubject(Ot.Starting));g(this,"lifecycle$",this._lifecycle$.asObservable());g(this,"_lock",!1);this._logService=n,this._reportProgress(Ot.Starting)}get stage(){return this._lifecycle$.getValue()}set stage(n){if(n<this.stage)throw new Error("[LifecycleService]: lifecycle stage cannot go backward!");if(n!==this.stage){if(this._lock)throw new Error("[LifecycleService]: cannot set new stage when related logic is all handled!");this._lock=!0,this._reportProgress(n),this._lifecycle$.next(n),this._lock=!1}}dispose(){this._lifecycle$.complete(),super.dispose()}subscribeWithPrevious(){return new rt.Observable(n=>{this.stage===Ot.Starting||(this.stage===Ot.Ready?n.next(Ot.Starting):this.stage===Ot.Rendered?(n.next(Ot.Starting),n.next(Ot.Ready)):(n.next(Ot.Starting),n.next(Ot.Ready),n.next(Ot.Rendered))),this._lifecycle$.subscribe(s=>{n.next(s),s===Ot.Steady&&n.complete()})})}_reportProgress(n){this._logService.debug("[LifecycleService]",`lifecycle progressed to "${hu[n]}".`)}};exports.LifecycleService=Ji([rs(0,pe)],exports.LifecycleService);exports.LifecycleInitializerService=class extends yt{constructor(n,s){super();g(this,"_seenTokens",new Set);this._lifecycleService=n,this._injector=s}initModulesOnStage(n){var s;(s=mn.get(n))==null||s.forEach(r=>{this._injector.has(r)&&!this._seenTokens.has(r)&&(this._injector.get(r),this._seenTokens.add(r))})}};exports.LifecycleInitializerService=Ji([rs(0,ut.Inject(exports.LifecycleService)),rs(1,ut.Inject(ut.Injector))],exports.LifecycleInitializerService);class Ye extends yt{constructor(){super();g(this,"_currentLocale$",new rt.BehaviorSubject(Te.ZH_CN));g(this,"currentLocale$",this._currentLocale$.asObservable());g(this,"_locales",null);g(this,"localeChanged$",new rt.Subject);g(this,"t",(n,...s)=>{if(!this._locales)throw new Error("[LocaleService]: Locale not initialized");const r=n.split("."),i=this.resolveKeyPath(this._locales[this._currentLocale],r);if(typeof i=="string"){let o=i;return s.forEach((l,a)=>{o=o.replace(`{${a}}`,l)}),o}else return n});this.disposeWithMe(bt(()=>this.localeChanged$.complete()))}get _currentLocale(){return this._currentLocale$.value}load(n){var s;this._locales=D.deepMerge((s=this._locales)!=null?s:{},n)}setLocale(n){this._currentLocale$.next(n),this.localeChanged$.next()}getLocales(){var n;return(n=this._locales)==null?void 0:n[this._currentLocale]}getCurrentLocale(){return this._currentLocale}resolveKeyPath(n,s){const r=s.shift();if(r&&n&&r in n){const i=n[r];return s.length>0&&(typeof i=="object"||Array.isArray(i))?this.resolveKeyPath(i,s):i}return null}}var Ns=(t=>(t.INIT="init",t.FETCHING="fetching",t.DONE="done",t))(Ns||{});const As=ut.createIdentifier("univer.permission-service");Un(Ot.Starting,As);class Zi extends yt{constructor(){super(...arguments);g(this,"_permissionPointMap",new Map);g(this,"_permissionPointUpdate$",new rt.Subject);g(this,"permissionPointUpdate$",this._permissionPointUpdate$.asObservable())}deletePermissionPoint(n){const s=this._permissionPointMap.get(n);s&&(s.complete(),this._permissionPointMap.delete(n))}addPermissionPoint(n){const s=n instanceof rt.BehaviorSubject,r=s?n.getValue():n;if(!r.id)return!1;if(this._permissionPointMap.get(r.id))throw new Error(`${r.id} PermissionPoint already exists`);return this._permissionPointMap.set(r.id,s?n:new rt.BehaviorSubject(r)),this._permissionPointUpdate$.next(r),!0}updatePermissionPoint(n,s){const r=this._permissionPointMap.get(n);if(!r)return;const i=r.getValue();i.value=s,i.status=Ns.DONE,r.next({...i}),this._permissionPointUpdate$.next(i)}clearPermissionMap(){this._permissionPointMap.clear()}getPermissionPoint(n){const s=this._permissionPointMap.get(n);if(s)return s.getValue()}getPermissionPoint$(n){const s=this._permissionPointMap.get(n);if(s)return s}composePermission$(n){const s=n.map(r=>{var o;const i=(o=this._permissionPointMap)==null?void 0:o.get(r);if(!i)throw new Error(`[PermissionService]: ${r} permissionPoint does not exist!`);return i.asObservable()});return rt.combineLatest(s).pipe(cn.map(r=>r))}composePermission(n){return n.map(r=>{var o;const i=(o=this._permissionPointMap)==null?void 0:o.get(r);if(!i)throw new Error(`[PermissionService]: ${r} permissionPoint does not exist!`);return i.getValue()})}getAllPermissionPoint(){const n=new Map;return this._permissionPointMap.forEach((s,r)=>{n.set(r,s)}),n}}class Qi extends yt{constructor(){super(...arguments);g(this,"_resourceMap",new Map);g(this,"_register$",new rt.Subject);g(this,"register$",this._register$.asObservable())}getAllResourceHooks(){return[...this._resourceMap.values()]}getResources(n){return this.getAllResourceHooks().map(i=>{const o=i.toJson(n);return{name:i.pluginName,data:o}})}getResourcesByType(n,s){return this.getAllResourceHooks().filter(o=>o.businesses.includes(s)).map(o=>{const l=o.toJson(n);return{name:o.pluginName,data:l}})}registerPluginResource(n){const s=n.pluginName;if(this._resourceMap.has(s))throw new Error(`the pluginName is registered {${s}}`);return this._resourceMap.set(s,n),this._register$.next(n),bt(()=>this._resourceMap.delete(s))}disposePluginResource(n){this._resourceMap.delete(n)}loadResources(n,s){this.getAllResourceHooks().forEach(r=>{var o;const i=(o=s==null?void 0:s.find(l=>l.name===r.pluginName))==null?void 0:o.data;if(i)try{const l=r.parseJson(i);r.onLoad(n,l)}catch{console.error("LoadResources Error!")}})}unloadResources(n){this.getAllResourceHooks().forEach(s=>{s.onUnLoad(n)})}dispose(){this._register$.complete(),this._resourceMap.clear()}}const Ln=ut.createIdentifier("resource-manager-service");var gu=Object.defineProperty,_u=Object.getOwnPropertyDescriptor,mu=(t,e,n,s)=>{for(var r=s>1?void 0:s?_u(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&gu(e,n,r),r},js=(t,e)=>(n,s)=>e(n,s,t);let is=class extends yt{constructor(e,n){super();g(this,"saveWorkbook",e=>{const n=e.getUnitId(),s=this._resourceManagerService.getResources(n)||[],r=e.getSnapshot();return r.resources=s,r});this._resourceManagerService=e,this._univerInstanceService=n,this._init()}_init(){const e=s=>{s.businesses.forEach(r=>{switch(r){case Z.UNRECOGNIZED:case Z.UNIVER_UNKNOWN:case Z.UNIVER_SLIDE:case Z.UNIVER_DOC:{this._univerInstanceService.getAllUnitsForType(Z.UNIVER_DOC).forEach(i=>{const l=(i.getSnapshot().resources||[]).find(a=>a.name===s.pluginName);if(l)try{const a=s.parseJson(l.data);s.onLoad(i.getUnitId(),a)}catch{console.error(`Load Document{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}});break}case Z.UNIVER_SHEET:this._univerInstanceService.getAllUnitsForType(Z.UNIVER_SHEET).forEach(i=>{const l=(i.getSnapshot().resources||[]).find(a=>a.name===s.pluginName);if(l)try{const a=s.parseJson(l.data);s.onLoad(i.getUnitId(),a)}catch{console.error(`Load Workbook{${i.getUnitId()}} Resources{${s.pluginName}} Data Error.`)}})}})};this._resourceManagerService.getAllResourceHooks().forEach(s=>{e(s)}),this.disposeWithMe(this._resourceManagerService.register$.subscribe(s=>{e(s)})),this.disposeWithMe(bt(this._univerInstanceService.getTypeOfUnitAdded$(Z.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.loadResources(s.getUnitId(),s.getSnapshot().resources)}))),this.disposeWithMe(bt(this._univerInstanceService.getTypeOfUnitDisposed$(Z.UNIVER_SHEET).subscribe(s=>{this._resourceManagerService.unloadResources(s.getUnitId())})))}saveDoc(e){const n=e.getUnitId(),s=this._resourceManagerService.getResourcesByType(n,Z.UNIVER_DOC)||[],r=e.getSnapshot();return r.resources=s,r}};is=mu([js(0,ut.Inject(Ln)),js(1,ut.Inject(Fe))],is);const bs=ut.createIdentifier("resource-loader-service");Un(Ot.Ready,bs);class vs extends yt{constructor(){super();g(this,"_currentTheme");g(this,"_currentTheme$",new rt.BehaviorSubject({}));g(this,"currentTheme$",this._currentTheme$.asObservable());this.disposeWithMe(bt(()=>this._currentTheme$.complete()))}getCurrentTheme(){if(!this._currentTheme)throw new Error("[ThemeService]: current theme is not set!");return this._currentTheme}setTheme(n){this._currentTheme=n,this._currentTheme$.next(n)}}const Dn="__INTERNAL_EDITOR__",to=`${Dn}DOCS_NORMAL`,eo=`${Dn}DOCS_FORMULA_BAR`,Eu=`\r
7
7
  `;function pu(t){return`${Dn}${t}`}function Ru(t){return t.startsWith(Dn)}var Cu=Object.defineProperty,Iu=Object.getOwnPropertyDescriptor,Ou=(t,e,n,s)=>{for(var r=s>1?void 0:s?Iu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&Cu(e,n,r),r},jn=(t,e)=>(n,s)=>e(n,s,t);const yn=ut.createIdentifier("univer.undo-redo.service"),Su=20;class no{dispose(){}async dispatchToHandlers(){return!1}}const so="univer.command.redo",ro="univer.command.undo",io=new class extends no{constructor(){super(...arguments);g(this,"type",tn.COMMAND);g(this,"id",ro)}async handler(e){const n=e.get(yn),s=n.pitchTopUndoElement();if(!s)return!1;const r=e.get(en);return hs(s.undoMutations,r)?(n.popUndoToRedo(),!0):!1}},oo=new class extends no{constructor(){super(...arguments);g(this,"type",tn.COMMAND);g(this,"id",so)}async handler(e){const n=e.get(yn),s=n.pitchTopRedoElement();if(!s)return!1;const r=e.get(en);return hs(s.redoMutations,r)?(n.popRedoToUndo(),!0):!1}};exports.LocalUndoRedoService=class extends yt{constructor(n,s,r){super();g(this,"undoRedoStatus$");g(this,"_undoRedoStatus$",new rt.BehaviorSubject({undos:0,redos:0}));g(this,"_undoStacks",new Map);g(this,"_redoStacks",new Map);g(this,"_batchingStatus",new Map);this._univerInstanceService=n,this._commandService=s,this._contextService=r,this.undoRedoStatus$=this._undoRedoStatus$.asObservable(),this.disposeWithMe(this._commandService.registerCommand(io)),this.disposeWithMe(this._commandService.registerCommand(oo)),this.disposeWithMe(bt(()=>this._undoRedoStatus$.complete())),this.disposeWithMe(bt(this._univerInstanceService.focused$.subscribe(()=>this._updateStatus())))}pushUndoRedo(n){const{unitID:s}=n,r=this._getRedoStack(s,!0),i=this._getUndoStack(s,!0);if(r.length=0,this._batchingStatus.has(n.unitID)){const l=this._batchingStatus.get(n.unitID),a=this._pitchUndoElement(n.unitID);l===0||!a?(o(n),this._batchingStatus.set(n.unitID,1)):this._tryBatchingElements(a,n)}else o(n);function o(l){i.push(l),i.length>Su&&i.splice(0,1)}this._updateStatus()}clearUndoRedo(n){const s=this._getRedoStack(n);s&&(s.length=0);const r=this._getUndoStack(n);r&&(r.length=0),this._updateStatus()}pitchTopUndoElement(){const n=this._getFocusedUnitId();return this._pitchUndoElement(n)}pitchTopRedoElement(){const n=this._getFocusedUnitId();return this._pitchRedoElement(n)}_pitchUndoElement(n){const s=this._getUndoStack(n);return s!=null&&s.length?s[s.length-1]:null}_pitchRedoElement(n){const s=this._getRedoStack(n);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(n){if(this._batchingStatus.has(n))throw new Error("[LocalUndoRedoService]: cannot batching undo redo twice at the same time!");return this._batchingStatus.set(n,0),bt(()=>this._batchingStatus.delete(n))}_updateStatus(){var i,o;const n=this._getFocusedUnitId(),s=n&&((i=this._undoStacks.get(n))==null?void 0:i.length)||0,r=n&&((o=this._redoStacks.get(n))==null?void 0:o.length)||0;this._undoRedoStatus$.next({undos:s,redos:r})}_getUndoStack(n,s=!1){let r=this._undoStacks.get(n);return!r&&s&&(r=[],this._undoStacks.set(n,r)),r||null}_getRedoStack(n,s=!1){let r=this._redoStacks.get(n);return!r&&s&&(r=[],this._redoStacks.set(n,r)),r||null}_getUndoStackForFocused(){const n=this._getFocusedUnitId();if(!n)throw new Error("No focused univer instance!");return this._getUndoStack(n,!0)}_getRedoStackForFocused(){const n=this._getFocusedUnitId();if(!n)throw new Error("No focused univer instance!");return this._getRedoStack(n,!0)}_tryBatchingElements(n,s){n.redoMutations.push(...s.redoMutations),n.undoMutations.push(...s.undoMutations)}_getFocusedUnitId(){var o,l,a,c;let n="";const s=this._contextService.getContextValue(Ke),r=this._contextService.getContextValue(Xi),i=this._contextService.getContextValue(zi);return s?r?n=eo:i?n=to:n=(l=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId())!=null?l:"":n=(c=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId())!=null?c:"",n}};exports.LocalUndoRedoService=Ou([jn(0,Fe),jn(1,en),jn(2,Qe)],exports.LocalUndoRedoService);const lo=Symbol("DependentOn");class os extends yt{onStarting(e){}onReady(){}onRendered(){}onSteady(){}getUniverInstanceType(){return this.constructor.type}getPluginName(){return this.constructor.pluginName}}g(os,"pluginName"),g(os,"type",Z.UNIVER_UNKNOWN);class Nu{constructor(){g(this,"_plugins",[])}addPlugin(e){this._plugins.push(e)}removePlugins(){const e=this._plugins.slice();return this._plugins.length=0,e}forEachPlugin(e){this._plugins.forEach(e)}}class Au{constructor(){g(this,"_pluginsRegistered",[])}registerPlugin(e,n){this._pluginsRegistered.push({plugin:e,options:n})}getRegisterPlugins(){return this._pluginsRegistered.slice()}removePlugins(){this._pluginsRegistered=[]}}var bu=Object.defineProperty,vu=Object.getOwnPropertyDescriptor,ao=(t,e,n,s)=>{for(var r=s>1?void 0:s?vu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&bu(e,n,r),r},Ge=(t,e)=>(n,s)=>e(n,s,t);const wu=4;function Tu(...t){return function(e){e[lo]=t}}exports.PluginService=class{constructor(e){g(this,"_pluginHolderForUniver");g(this,"_pluginHoldersForTypes",new Map);g(this,"_seenPlugins",new Set);g(this,"_flushTimer");this._injector=e,this._pluginHolderForUniver=this._injector.createInstance(Sn,this._checkPluginSeen.bind(this),this._immediateInitPlugin.bind(this)),this._pluginHolderForUniver.start()}dispose(){this._clearFlushTimer();for(const e of this._pluginHoldersForTypes.values())e.dispose();this._pluginHolderForUniver.dispose()}registerPlugin(e,n){this._assertPluginValid(e),this._scheduleInitPlugin();const{type:s}=e;s===Z.UNIVER_UNKNOWN?(this._pluginHolderForUniver.register(e,n),this._pluginHolderForUniver.flush()):this._ensurePluginHolderForType(s).register(e,n)}startPluginForType(e){this._ensurePluginHolderForType(e).start()}_ensurePluginHolderForType(e){if(!this._pluginHoldersForTypes.has(e)){const n=this._injector.createInstance(Sn,this._checkPluginSeen.bind(this),this._immediateInitPlugin.bind(this));return this._pluginHoldersForTypes.set(e,n),n}return this._pluginHoldersForTypes.get(e)}_immediateInitPlugin(e){this._seenPlugins.add(e.pluginName),this._ensurePluginHolderForType(e.type).immediateInitPlugin(e)}_checkPluginSeen(e){return this._seenPlugins.has(e.pluginName)}_assertPluginValid(e){const{type:n,pluginName:s}=e;if(n===Z.UNRECOGNIZED)throw new Error(`[PluginService]: invalid plugin type for ${e}. Please assign a "type" to your plugin.`);if(s==="")throw new Error(`[PluginService]: no plugin name for ${e}. Please assign a "pluginName" to your plugin.`);if(this._seenPlugins.has(s))throw new Error(`[PluginService]: duplicated plugin name for "${s}". Maybe a plugin that dependents on "${s} has already registered it. In that case please register "${s}" before the that plugin.`);this._seenPlugins.add(e.pluginName)}_scheduleInitPlugin(){this._flushTimer===void 0&&(this._flushTimer=setTimeout(()=>{this._pluginHolderForUniver.started||this._pluginHolderForUniver.start(),this._flushPlugins(),this._clearFlushTimer()},wu))}_clearFlushTimer(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=void 0)}_flushPlugins(){this._pluginHolderForUniver.flush();for(const[e,n]of this._pluginHoldersForTypes)n.started&&n.flush()}};exports.PluginService=ao([Ge(0,ut.Inject(ut.Injector))],exports.PluginService);let Sn=class extends yt{constructor(e,n,s,r,i,o){super();g(this,"_started",!1);g(this,"_pluginRegistry",new Au);g(this,"_pluginStore",new Nu);this._checkPluginRegistered=e,this._registerPlugin=n,this._logService=s,this._injector=r,this._lifecycleService=i,this._lifecycleInitializerService=o}get started(){return this._started}dispose(){super.dispose(),this._pluginStore.forEachPlugin(e=>e.dispose()),this._pluginStore.removePlugins(),this._pluginRegistry.removePlugins()}register(e,n){this._pluginRegistry.registerPlugin(e,n)}immediateInitPlugin(e){const n=this._initPlugin(e,void 0);this._pluginsRunLifecycle([n])}start(){this._started||(this._started=!0,this.flush())}flush(){if(!this._started)return;const e=this._pluginRegistry.getRegisterPlugins().map(({plugin:n,options:s})=>this._initPlugin(n,s));this._pluginsRunLifecycle(e),this._pluginRegistry.removePlugins()}_initPlugin(e,n){const s=e[lo];if(s){const i=()=>{const o=s.find(l=>!this._checkPluginRegistered(l));return o?(this._logService.warn("[PluginService]",`plugin "${e.pluginName}" depends on "${o.pluginName}" which is not registered. Univer will automatically register it with default configuration.`),this._registerPlugin(o,void 0),!0):!1};for(;i(););}const r=this._injector.createInstance(e,n);return this._pluginStore.addPlugin(r),r}_pluginsRunLifecycle(e){const n=r=>{e.forEach(i=>{switch(r){case Ot.Starting:i.onStarting(this._injector);break;case Ot.Ready:i.onReady();break;case Ot.Rendered:i.onRendered();break;case Ot.Steady:i.onSteady();break}this._lifecycleInitializerService.initModulesOnStage(r)})},s=this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().pipe(rt.finalize(()=>{Promise.resolve().then(()=>s.dispose())})).subscribe(r=>{n(r)}))}};Sn=ao([Ge(2,pe),Ge(3,ut.Inject(ut.Injector)),Ge(4,ut.Inject(exports.LifecycleService)),Ge(5,ut.Inject(exports.LifecycleInitializerService))],Sn);function uo(t,e){if(!e)return t;const n=[];for(const s of t){const r=e.find(([i])=>i===s[0]);if(r){if(r[1]===null)continue;n.push([s[0],r[1]])}else n.push(s)}return n}const ls={[Ft.Editor]:"Editor",[Ft.Owner]:"Owner",[Ft.Reader]:"Reader",[Ft.UNRECOGNIZED]:"UNRECOGNIZED"},Nn=t=>t?{userID:`${ls[t]}_${D.generateRandomId(8)}`,name:ls[t],avatar:""}:{userID:"",name:"",avatar:"",anonymous:!0,canBindAnonymous:!1},Vn=(t,e)=>t.startsWith(ls[e]);var Mu=Object.defineProperty,Uu=Object.getOwnPropertyDescriptor,Lu=(t,e,n,s)=>{for(var r=s>1?void 0:s?Uu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&Mu(e,n,r),r};exports.UserManagerService=class{constructor(){g(this,"_model",new Map);g(this,"_userChange$",new rt.Subject);g(this,"userChange$",this._userChange$.asObservable());g(this,"_currentUser$",new rt.BehaviorSubject(Nn()));g(this,"currentUser$",this._currentUser$.asObservable())}getCurrentUser(){return this._currentUser$.getValue()}setCurrentUser(e){this.addUser(e),this._currentUser$.next(e)}addUser(e){this._model.set(e.userID,e),this._userChange$.next({type:"add",user:e})}getUser(e,n){const s=this._model.get(e);if(s)return s;n&&n()}delete(e){const n=this.getUser(e);this._model.delete(e),n&&this._userChange$.next({type:"delete",user:n})}clear(){this._model.clear(),this._userChange$.next({type:"clear"})}};exports.UserManagerService=Lu([qi(Ot.Starting,exports.UserManagerService)],exports.UserManagerService);var Du=Object.defineProperty,yu=Object.getOwnPropertyDescriptor,xu=(t,e,n,s)=>{for(var r=s>1?void 0:s?yu(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(r=(s?o(e,n,r):o(r))||r);return s&&r&&Du(e,n,r),r},Vs=(t,e)=>(n,s)=>e(n,s,t);exports.AuthzIoLocalService=class{constructor(e,n){g(this,"_permissionMap",new Map([]));this._resourceManagerService=e,this._userManagerService=n,this._initSnapshot(),n.setCurrentUser(Nn(Ft.Owner))}_getRole(e){const n=this._userManagerService.getCurrentUser();return n?Vn(n.userID,e):!1}_initSnapshot(){this._resourceManagerService.registerPluginResource({toJson:e=>{const n=[...this._permissionMap.keys()].reduce((s,r)=>{const i=this._permissionMap.get(r);return s[r]=i,s},{});return JSON.stringify(n)},parseJson:e=>JSON.parse(e),pluginName:"SHEET_AuthzIoMockService_PLUGIN",businesses:[Z.UNIVER_SHEET,Z.UNIVER_DOC,Z.UNIVER_SLIDE],onLoad:(e,n)=>{for(const s in n)this._permissionMap.set(s,n[s])},onUnLoad:()=>{this._permissionMap.clear()}})}async create(e){const n=D.generateRandomId(8);switch(e.objectType){case fn.SelectRange:{const s=e.selectRangeObject;this._permissionMap.set(n,{...s,objectType:e.objectType});break}case fn.Worksheet:{const s=e.worksheetObject;this._permissionMap.set(n,{...s,objectType:e.objectType})}}return n}async allowed(e){var n;if(this._permissionMap.has(e.objectID)){const s=this._permissionMap.get(e.objectID);if(s&&s.objectType===fn.Worksheet)return(n=s==null?void 0:s.strategies)==null?void 0:n.map(r=>({action:r.action,allowed:r.role===Ft.Editor}))}return e.actions.map(s=>({action:s,allowed:this._getRole(Ft.Owner)||this._getRole(Ft.Editor)}))}async batchAllowed(e){const n=this._userManagerService.getCurrentUser(),s=e.map(r=>({unitID:r.unitID,objectID:r.objectID,actions:r.actions.map(i=>({action:i,allowed:!1}))}));return n&&(Vn(n.userID,Ft.Owner)||Vn(n.userID,Ft.Editor))?e.map(r=>({unitID:r.unitID,objectID:r.objectID,actions:r.actions.map(i=>({action:i,allowed:!0}))})):s}async list(e){const n=[];return e.objectIDs.forEach(s=>{const r=this._permissionMap.get(s);if(r){const i={objectID:s,unitID:e.unitID,objectType:r.objectType,name:r.name,shareOn:!1,shareRole:Ft.Owner,shareScope:-1,creator:Nn(Ft.Owner),strategies:[],actions:e.actions.map(o=>({action:o,allowed:this._getRole(Ft.Owner)||this._getRole(Ft.Editor)}))};n.push(i)}}),n}async listCollaborators(){return[]}async listRoles(){return{roles:[],actions:[]}}async deleteCollaborator(){}async update(e){}async updateCollaborator(){}async createCollaborator(){}async putCollaborators(e){}};exports.AuthzIoLocalService=xu([Vs(0,Ln),Vs(1,ut.Inject(exports.UserManagerService))],exports.AuthzIoLocalService);const co=ut.createIdentifier("IAuthzIoIoService");class Pu{constructor(e={},n){g(this,"_startedTypes",new Set);g(this,"_injector");const s=this._injector=ku(n,e==null?void 0:e.override),{theme:r,locale:i,locales:o,logLevel:l}=e;r&&this._injector.get(vs).setTheme(r),o&&this._injector.get(Ye).load(o),i&&this._injector.get(Ye).setLocale(i),l&&this._injector.get(pe).setLogLevel(l),this._init(s)}get _univerInstanceService(){return this._injector.get(Fe)}get _pluginService(){return this._injector.get(exports.PluginService)}__getInjector(){return this._injector}dispose(){this._injector.dispose()}setLocale(e){this._injector.get(Ye).setLocale(e)}createUnit(e,n){return this._univerInstanceService.createUnit(e,n)}createUniverSheet(e){return this._univerInstanceService.createUnit(Z.UNIVER_SHEET,e)}createUniverDoc(e){return this._univerInstanceService.createUnit(Z.UNIVER_DOC,e)}createUniverSlide(e){return this._univerInstanceService.createUnit(Z.UNIVER_SLIDE,e)}_init(e){this._univerInstanceService.registerCtorForType(Z.UNIVER_SHEET,exports.Workbook),this._univerInstanceService.registerCtorForType(Z.UNIVER_DOC,we),this._univerInstanceService.registerCtorForType(Z.UNIVER_SLIDE,Ss);const n=e.get(Fe);n.__setCreateHandler((s,r,i)=>{if(!this._startedTypes.has(s)){this._pluginService.startPluginForType(s),this._startedTypes.add(s);const l=e.createInstance(i,r);return n.__addUnit(l),this._tryProgressToReady(),l}const o=e.createInstance(i,r);return n.__addUnit(o),o})}_tryProgressToReady(){this._injector.get(exports.LifecycleService).stage<Ot.Ready&&(this._injector.get(exports.LifecycleService).stage=Ot.Ready)}registerPlugin(e,n){this._pluginService.registerPlugin(e,n)}}function ku(t,e){const n=uo([[Hi],[Ye],[vs],[exports.LifecycleService],[exports.LifecycleInitializerService],[exports.PluginService],[exports.UserManagerService],[Fe,{useClass:exports.UniverInstanceService}],[As,{useClass:Zi}],[pe,{useClass:di,lazy:!0}],[en,{useClass:exports.CommandService}],[yn,{useClass:exports.LocalUndoRedoService,lazy:!0}],[Pi,{useClass:ki}],[Qe,{useClass:ci}],[Ln,{useClass:Qi,lazy:!0}],[bs,{useClass:is,lazy:!0}],[co,{useClass:exports.AuthzIoLocalService,lazy:!0}]],e);return t?t.createChild(n):new ut.Injector(n)}const Hu=(t,e)=>e.length===t.length&&!t.some(n=>e.some(s=>!me.equals(s,n))),Fu=(t,e)=>e.length===t.length&&t.every((n,s)=>{const r=e[s];return r.unitId===n.unitId&&r.sheetId===n.sheetId&&me.equals(n.range,r.range)});function $u(t,e){if(Object.is(t,e))return!0;if(typeof t!="object"||!t||typeof e!="object"||!e)return!1;const n=Object.keys(t),s=Object.keys(e);if(n.length!==s.length)return!1;const r=Object.prototype.hasOwnProperty.bind(e);for(let i=0;i<n.length;i++){const o=n[i];if(!r(o))return!1;const l=t[o],a=e[o];if(l!==a)return!1}return!0}function ho(t){return/^-?\d+(\.\d+)?$/.test(t)}function Wu(t){return ho(t)?Number(t)<=Number.MAX_SAFE_INTEGER:!1}function Bu(t){return["true","false"].includes(t.toLowerCase())}function Gu(t,e){return e.forEach(n=>t.add(n)),t}function ju(t,e=16){let n=0,s=null;return function(...i){const o=Date.now();o-n<e?(s&&clearTimeout(s),s=setTimeout(()=>{n=o,t.apply(this,i)},e)):(n=o,t.apply(this,i))}}function Vu(t){const e=new MessageChannel;let n=!1;return e.port1.onmessage=()=>{n||t()},e.port2.postMessage(null),()=>{n=!0,e.port1.onmessage=null,e.port1.close(),e.port2.close()}}var fo=(t=>(t[t.TEXT=0]="TEXT",t[t.ARROW=1]="ARROW",t[t.CUSTOM=2]="CUSTOM",t))(fo||{});function Ku(t,e,n){if(e==="")return t;const s={id:"mock-id",body:t,documentStyle:{}},r=new we(s),i=e.length;let o;for(;(o=r.getBody().dataStream.indexOf(e))>=0;){const a=new Ee,c=ve.getInstance();if(o>0&&a.retain(o),n.length>0){const h=r.sliceBody(o,o+i),u={dataStream:n};Array.isArray(h==null?void 0:h.textRuns)&&h.textRuns.length&&(u.textRuns=[{...h.textRuns[0],st:0,ed:n.length}]),a.insert(n.length,u)}a.delete(i),r.apply(c.editOp(a.serialize()))}const l=r.getBody();return r.dispose(),l}class go{constructor(){g(this,"skipNextObservers",!1);g(this,"lastReturnValue");g(this,"isStopPropagation",!1)}stopPropagation(){this.isStopPropagation=!0}}class Yu extends rt.Subject{constructor(){super(...arguments);g(this,"_sortedObservers",[])}subscribe(){throw new Error("[EventSubject]: please use `subscribeEvent` instead of `subscribe` method for `EventSubject`.")}next(){throw new Error("[EventSubject]: please use `emitEvent` instead of `next` method for `EventSubject`.")}unsubscribe(){super.unsubscribe(),this._sortedObservers.length=0}complete(){super.complete(),this._sortedObservers.length=0}subscribeEvent(n){let s;typeof n=="function"?s={next:([i,o])=>n(i,o)}:s=n;const r=super.subscribe(s);return this._sortedObservers.push(s),this._sortedObservers.sort((i,o)=>{var l,a;return((l=i.priority)!=null?l:0)-((a=o.priority)!=null?a:0)}),r.add(()=>this._sortedObservers=this._sortedObservers.filter(i=>i!==s)),r}clearObservers(){this._sortedObservers.forEach(n=>{var s;return(s=n.complete)==null?void 0:s.call(n)}),this._sortedObservers.length=0}emitEvent(n){var s;if(!this.closed){const r=new go;r.lastReturnValue=n;for(const i of this._sortedObservers){const o=(s=i.next)==null?void 0:s.call(i,[n,r]);if(r.lastReturnValue=o,r.skipNextObservers)return{handled:!0,lastReturnValue:r.lastReturnValue,stopPropagation:r.isStopPropagation}}return{handled:this._sortedObservers.length>0,lastReturnValue:r.lastReturnValue,stopPropagation:r.isStopPropagation}}throw new Error("[EventSubject]: cannot emit event on a closed subject.")}}const zu=ut.createIdentifier("ILocalStorageService");function Xu(t){return`sheet_interceptor_${t}`}const _o=t=>function(e,n){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,n,r.bind(null,i+1))}return r(0,e)};class qu{constructor(e){g(this,"_interceptorsByName",new Map);g(this,"_interceptorPoints");this._interceptorPoints=e}fetchThroughInterceptors(e){const n=e,s=this._interceptorsByName.get(n);return _o(s||[])}intercept(e,n){const s=e;this._interceptorsByName.has(s)||this._interceptorsByName.set(s,[]);const r=this._interceptorsByName.get(s);return r.push(n),this._interceptorsByName.set(s,r.sort((i,o)=>{var l,a;return((l=o.priority)!=null?l:0)-((a=i.priority)!=null?a:0)})),()=>Tn(this._interceptorsByName.get(s),n)}getInterceptPoints(){return this._interceptorPoints}}const Ju=ut.createIdentifier("univer.snapshot-server-service");class Zu{constructor(){g(this,"_sheetBlockCache",new Map)}getUnitOnRev(e,n){return Promise.resolve({snapshot:{unitID:"",type:Z.UNIVER_SHEET,rev:0,workbook:void 0,doc:void 0},changesets:[],error:{code:Xt.OK,message:""}})}getSheetBlock(e,n){const s=this._sheetBlockCache.get(n.blockID);return Promise.resolve({block:s,error:{code:Xt.OK,message:""}})}fetchMissingChangesets(e,n){return Promise.resolve({changesets:[],error:{code:Xt.OK,message:""}})}getResourcesRequest(e,n){return Promise.resolve({resources:{},error:{code:Xt.OK,message:""}})}saveSnapshot(e,n){return Promise.resolve({error:{code:Xt.OK,message:""}})}saveSheetBlock(e,n){const{block:s}=n;return s?(this._sheetBlockCache.set(s.id,s),Promise.resolve({error:{code:Xt.OK,message:""},blockID:s.id})):Promise.resolve({error:{code:Xt.UNDEFINED,message:"block is required"},blockID:""})}saveChangeset(e,n){return Promise.resolve({error:{code:Xt.OK,message:""},concurrent:[]})}}function Qu(t){return btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(e,n)=>String.fromCharCode(Number.parseInt(n,16))))}function ws(t){return decodeURIComponent(Array.prototype.map.call(atob(t),e=>`%${`00${e.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}const nn=new TextEncoder,xn=new TextDecoder;function mo(t){const e=D.deepClone(t);return delete e.id,delete e.name,delete e.rowCount,delete e.columnCount,delete e.cellData,nn.encode(JSON.stringify(e))}function Eo(t){const e=D.deepClone(t);return delete e.id,delete e.rev,delete e.name,delete e.sheetOrder,delete e.sheets,nn.encode(JSON.stringify(e))}function tc(t){const e=D.deepClone(t);return delete e.id,delete e.rev,delete e.title,delete e.resources,nn.encode(JSON.stringify(e))}function Ks(t){return JSON.parse(xn.decode(t))}function ec(t){return JSON.parse(typeof t=="string"?ws(t):xn.decode(t))}function nc(t){return JSON.parse(typeof t=="string"?ws(t):xn.decode(t))}const Kn=256*20;function po(t,e){const n=new ee(t),s=n.getLength(),r=[];let i=0;for(;i<s;){const o=Math.min(i+Kn,s-1),l=n.getSlice(i,Math.min(i+Kn,s-1),0,e),a=sc(l);r.push({id:D.generateRandomId(19,"0123456789"),startRow:i,endRow:o,data:a}),i+=Kn}return r}function sc(t){const e=t.getData();return nn.encode(JSON.stringify(e))}async function rc(t,e,n,s,r){const i={},o={};if(!await Promise.all(Object.entries(e.sheets).map(async([u,d])=>{const f={id:d.id,type:An.GRID,name:d.name,rowCount:d.rowCount,columnCount:d.columnCount,originalMeta:mo(d)};if(o[u]=f,d.cellData){const m=po(d.cellData,d.rowCount),E=await Promise.all(m.map(P=>r.saveSheetBlock(t,{unitID:n,type:Z.UNIVER_SHEET,block:P})));if(E.some(P=>{var x;return((x=P.error)==null?void 0:x.code)!==Xt.OK}))return!1;i[u]={sheetID:u,blocks:E.map(P=>P.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const a=Eo(e),c={unitID:e.id,rev:s,creator:"",name:e.name,sheetOrder:e.sheetOrder,sheets:o,blockMeta:i,resources:e.resources||[],originalMeta:a};return{snapshotRes:{unitID:n,rev:c.rev,type:Z.UNIVER_SHEET,workbook:c,doc:void 0}}}async function ic(t,e,n,s,r){var d,f;const i={},o={};if(!await Promise.all(Object.entries(e.sheets).map(async([m,E])=>{const P={id:E.id,type:An.GRID,name:E.name,rowCount:E.rowCount,columnCount:E.columnCount,originalMeta:mo(E)};if(o[m]=P,E.cellData){const x=po(E.cellData,E.rowCount),Q=await Promise.all(x.map(_t=>r.saveSheetBlock(t,{unitID:n,type:Z.UNIVER_SHEET,block:_t})));if(Q.some(_t=>{var ht;return((ht=_t.error)==null?void 0:ht.code)!==Xt.OK}))return!1;i[m]={sheetID:m,blocks:Q.map(_t=>_t.blockID)}}return!0})))throw new Error("[transformWorkbookDataToSnapshot()]: Failed to save sheet blocks.");const a=Eo(e),c={unitID:e.id,rev:s,creator:"",name:e.name,sheetOrder:e.sheetOrder,sheets:o,blockMeta:i,resources:e.resources||[],originalMeta:a},h={unitID:n,rev:c.rev,type:Z.UNIVER_SHEET,workbook:c,doc:void 0},u=await r.saveSnapshot(t,{unitID:n,type:Z.UNIVER_SHEET,snapshot:h});if(_i(u.error))throw new Error(`transformWorkbookDataToSnapshot(): Failed to save snapshot.
8
8
  ErrorCode: ${(d=u.error)==null?void 0:d.code}:${(f=u.error)==null?void 0:f.message}`);return{snapshot:h}}function oc(t,e,n){const s=t.workbook;if(!s)throw new Error("");const r={};Object.entries(s.sheets).forEach(([a,c])=>{const h=Ks(c.originalMeta);r[a]={id:c.id,name:c.name,rowCount:c.rowCount,columnCount:c.columnCount,...h}});const i=new Map;e.forEach(a=>{i.set(a.id,a)}),s.blockMeta&&Object.entries(s.blockMeta).forEach(([a,c])=>{var d;const h=r[a];h.cellData={};const u=[];(d=c.blocks)==null||d.forEach(f=>{const m=i.get(f);if(m)u.push(m);else throw new Error("")}),u.forEach(f=>{const m=ec(f.data);Object.entries(m).forEach(([E,P])=>{const x=h.cellData[+E]={};Object.entries(P).forEach(([Q,_t])=>{x[+Q]=_t})})})});const o=Ks(s.originalMeta);return{id:t.unitID,rev:s.rev,name:s.name,sheetOrder:s.sheetOrder,appVersion:"",locale:Te.EN_US,sheets:r,styles:{},resources:s.resources||[],...o}}function lc(t){const e=t.doc;if(e==null)throw new Error("transformSnapshotToDocumentData(): snapshot.doc is undefined.");const{unitID:n,rev:s,name:r,originalMeta:i}=e,{body:o,documentStyle:l={},settings:a={}}=nc(i);return{id:n,rev:s,locale:Te.EN_US,title:r,body:o,documentStyle:l,settings:a}}async function ac(t,e,n,s,r){var a,c,h;const i={unitID:e.id,rev:s,creator:"",name:(a=e.title)!=null?a:"",resources:e.resources||[],originalMeta:tc(e)},o={unitID:n,rev:i.rev,type:Z.UNIVER_DOC,workbook:void 0,doc:i},l=await r.saveSnapshot(t,{unitID:n,type:Z.UNIVER_DOC,snapshot:o});if(_i(l.error))throw new Error(`transformDocumentDataToSnapshot(): Failed to save snapshot.
9
9
  ErrorCode: ${(c=l.error)==null?void 0:c.code}:${(h=l.error)==null?void 0:h.message}`);return{snapshot:o}}async function uc(t,e){const n=t.workbook;if(!n)throw new Error("Workbook metadata is not available");const s=[],r=[];return Object.entries(n.blockMeta).forEach(([i,o])=>{const l=o.blocks.map(async a=>{const c={unitID:n.unitID,type:Z.UNIVER_SHEET,blockID:a},{block:h}=await e.getSheetBlock({},c);if(h)s.push(h);else throw new Error("Block not found")});r.push(...l)}),await Promise.all(r),s}var Ro=(t=>(t[t.INFO=0]="INFO",t[t.STOP=1]="STOP",t[t.WARNING=2]="WARNING",t))(Ro||{}),Co=(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))(Co||{}),Io=(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))(Io||{}),Oo=(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))(Oo||{}),So=(t=>(t.VALID="valid",t.INVALID="invalid",t.VALIDATING="validating",t))(So||{});const cc=["script","style","meta","comment","link"];function hc(t){return!(t.length===0||t.length>31||t.startsWith("'")||t.endsWith("'")||/[:\\\/\?\*\[\]]/.test(t))}Mo();exports.ABCToNumber=Gl;exports.AbsoluteRefType=At;exports.ActionIterator=ss;exports.AlignTypeH=$r;exports.AlignTypeV=Wr;exports.ArrangeTypeEnum=jr;exports.ArrowsAndMarkersShapes=hr;exports.AutoFillSeries=Zs;exports.BaselineOffset=ke;exports.BasicShapes=cr;exports.BlockType=Ir;exports.BooleanNumber=K;exports.BorderStyleTypes=dt;exports.BorderType=Qs;exports.BulletAlignment=fe;exports.COLORS=Yn;exports.CellValueType=Ae;exports.ClientSnapshotServerService=Zu;exports.Color=be;exports.ColorBuilder=vn;exports.ColorKit=te;exports.ColorType=zt;exports.ColumnSeparatorType=Ar;exports.CommandType=tn;exports.CommonHideTypes=tr;exports.ConfigService=ki;exports.ContentAlignment=xr;exports.ContextService=ci;exports.CopyPasteType=er;exports.CustomDecorationType=Cr;exports.CustomRangeType=Rr;exports.DEFAULT_CELL=ta;exports.DEFAULT_DOC=Os;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=Lo;exports.DEFAULT_EMPTY_DOCUMENT_VALUE=Eu;exports.DEFAULT_RANGE=Zl;exports.DEFAULT_RANGE_ARRAY=Jl;exports.DEFAULT_SELECTION=Ql;exports.DEFAULT_SLIDE=oi;exports.DEFAULT_STYLES=dn;exports.DEFAULT_WORKSHEET_COLUMN_COUNT=Wi;exports.DEFAULT_WORKSHEET_COLUMN_COUNT_KEY=Ga;exports.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT=Vi;exports.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY=Ya;exports.DEFAULT_WORKSHEET_COLUMN_WIDTH=Gi;exports.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY=Va;exports.DEFAULT_WORKSHEET_ROW_COUNT=$i;exports.DEFAULT_WORKSHEET_ROW_COUNT_KEY=Ba;exports.DEFAULT_WORKSHEET_ROW_HEIGHT=Bi;exports.DEFAULT_WORKSHEET_ROW_HEIGHT_KEY=ja;exports.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH=ji;exports.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY=Ka;exports.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY=eo;exports.DOCS_NORMAL_EDITOR_UNIT_ID_KEY=to;exports.DashStyleType=Lr;exports.DataStreamTreeNodeType=mi;exports.DataStreamTreeTokenType=ce;exports.DataValidationErrorStyle=Ro;exports.DataValidationImeMode=Co;exports.DataValidationOperator=Io;exports.DataValidationRenderMode=fo;exports.DataValidationStatus=So;exports.DataValidationType=Oo;exports.DependentOn=Tu;exports.DesktopLogService=di;exports.DeveloperMetadataVisibility=nr;exports.Dimension=sr;exports.Direction=rr;exports.Disposable=yt;exports.DisposableCollection=cs;exports.DocStyleType=Er;exports.DocumentDataModel=we;exports.DocumentFlavor=Or;exports.DrawingTypeEnum=Vr;exports.EDITOR_ACTIVATED=zi;exports.EXTENSION_NAMES=li;exports.Entry=zn;exports.EntryIterator=ni;exports.ErrorService=Hi;exports.EventState=go;exports.EventSubject=Yu;exports.FOCUSING_COMMON_DRAWINGS=lu;exports.FOCUSING_DOC=gn;exports.FOCUSING_EDITOR_BUT_HIDDEN=nu;exports.FOCUSING_EDITOR_INPUT_FORMULA=su;exports.FOCUSING_EDITOR_STANDALONE=iu;exports.FOCUSING_FORMULA_EDITOR=Xi;exports.FOCUSING_SHEET=Ke;exports.FOCUSING_SLIDE=_n;exports.FOCUSING_UNIVER_EDITOR=ru;exports.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE=ou;exports.FollowNumberWithType=pr;exports.FontItalic=En;exports.FontStyleType=Pr;exports.FontWeight=pn;exports.FormatType=ir;exports.GlyphType=je;exports.GridType=Sr;exports.HLSColor=_r;exports.HorizontalAlign=Ne;exports.IAuthzIoService=co;exports.ICommandService=en;exports.IConfigService=Pi;exports.IContextService=Qe;exports.ILocalStorageService=zu;exports.ILogService=pe;exports.IPermissionService=As;exports.IResourceLoaderService=bs;exports.IResourceManagerService=Ln;exports.ISnapshotServerService=Ju;exports.IUndoRedoService=yn;exports.IUniverInstanceService=Fe;exports.InterceptorManager=qu;exports.InterpolationPointType=or;exports.JSON1=ya;exports.JSONX=ve;exports.KeyIterator=ti;exports.LRUHelper=Be;exports.LRUMap=si;exports.LifecycleStages=Ot;exports.LocaleService=Ye;exports.LocaleType=Te;exports.LogLevel=hi;exports.MOVE_BUFFER_VALUE=We;exports.MemoryCursor=Di;exports.NamedStyleType=Mr;exports.NilCommand=fi;exports.NumberUnitType=Fr;exports.ObjectMatrix=ee;exports.ObjectRelativeFromH=kr;exports.ObjectRelativeFromV=Hr;exports.OnLifecycle=qi;exports.OtherShapes=dr;exports.PRESET_LIST_TYPE=fa;exports.PageElementType=Kr;exports.PageOrientType=Gr;exports.PageType=as;exports.ParagraphElementType=vr;exports.PermissionService=Zi;exports.PermissionStatus=Ns;exports.Plugin=os;exports.PositionedObjectLayoutType=Tr;exports.PresetListType=On;exports.ProtectionType=lr;exports.RANGE_TYPE=it;exports.RGBA_PAREN=Ho;exports.RGB_PAREN=ko;exports.ROTATE_BUFFER_VALUE=Xs;exports.Range=He;exports.Rectangle=me;exports.RedoCommand=oo;exports.RedoCommandId=so;exports.RefAlias=Bl;exports.Registry=ds;exports.RegistryAsMap=fs;exports.RelativeDate=ar;exports.RelativeSlideLink=Yr;exports.ResourceManagerService=Qi;exports.RgbColor=Rn;exports.RxDisposable=Ll;exports.SectionType=Nr;exports.SheetTypes=An;exports.SheetViewModel=Yi;exports.SlideDataModel=Ss;exports.SpacingRule=Ur;exports.SpecialShapes=fr;exports.Styles=Fi;exports.THEME_COLORS=gr;exports.TabStopAlignment=Dr;exports.TextDecoration=ur;exports.TextDirection=qe;exports.TextDirectionType=br;exports.TextX=Ee;exports.TextXActionType=J;exports.ThemeColor=Cn;exports.ThemeColorType=Ht;exports.ThemeColors=bn;exports.ThemeService=vs;exports.Tools=D;exports.UndoCommand=io;exports.UndoCommandId=ro;exports.UnitModel=Mn;exports.Univer=Pu;exports.UniverInstanceType=Z;exports.UpdateDocsAttributeType=Pt;exports.ValueIterator=ei;exports.VerticalAlign=xe;exports.WidthType=yr;exports.Worksheet=Ze;exports.WrapStrategy=Pe;exports.WrapTextType=wr;exports.afterInitApply=da;exports.b64DecodeUnicode=ws;exports.b64EncodeUnicode=Qu;exports.binarySearchArray=qs;exports.cellToRange=Sl;exports.characterSpacingControlType=Br;exports.checkForSubstrings=Nl;exports.checkIfMove=Do;exports.checkParagraphHasBullet=Al;exports.checkParagraphHasIndent=bl;exports.checkParagraphHasIndentByStyle=qr;exports.codeToBlob=xo;exports.composeBody=ts;exports.composeInterceptors=_o;exports.concatMatrixArray=Hl;exports.convertBodyToHtml=ql;exports.covertTextRunToHtml=Qn;exports.createDefaultUser=Nn;exports.createInterceptorKey=Xu;exports.createInternalEditorID=pu;exports.createRowColIter=Zn;exports.debounce=Xl;exports.dedupe=Dl;exports.deepCompare=us;exports.deleteContent=Zr;exports.extractPureTextFromCell=za;exports.fromCallback=gi;exports.fromObservable=Ul;exports.generateTemporarySnap=rc;exports.getArrayLength=_e;exports.getBodySlice=Je;exports.getBodySliceHtml=hn;exports.getBorderStyleType=Cl;exports.getCellInfoInMergeData=sl;exports.getCellValueType=Qo;exports.getColorStyle=re;exports.getCustomDecorationSlice=Ui;exports.getCustomRangeSlice=Mi;exports.getDocsUpdateBody=Il;exports.getReverseDirection=Po;exports.getSheetBlocksFromSnapshot=uc;exports.getWorksheetUID=eu;exports.groupBy=Pl;exports.handleStyleToString=Rl;exports.hashAlgorithm=wl;exports.horizontalLineSegmentsSubtraction=wn;exports.insertMatrixArray=Xn;exports.insertTextToContent=Jr;exports.isBlackColor=qo;exports.isBooleanString=Bu;exports.isCellCoverable=ml;exports.isCellV=el;exports.isEmptyCell=zr;exports.isFormulaId=pl;exports.isFormulaString=El;exports.isICellData=Zo;exports.isInternalEditorID=Ru;exports.isNullCell=tl;exports.isNumeric=ho;exports.isRangesEqual=Hu;exports.isRealNum=vl;exports.isSafeNumeric=Wu;exports.isSameStyleTextRun=Xr;exports.isUnitRangesEqual=Fu;exports.isValidRange=Ol;exports.isWhiteColor=Jo;exports.makeArray=kl;exports.makeCellRangeToRangeData=_l;exports.makeCellToSelection=gl;exports.mergeOverrideWithDependencies=uo;exports.mergeSets=Gu;exports.mergeWorksheetSnapshotWithDefault=Ki;exports.moveMatrixArray=Jn;exports.moveRangeByOffset=ia;exports.nameCharacterCheck=hc;exports.normalizeBody=Aa;exports.normalizeTextRuns=gs;exports.numberToABC=Vl;exports.numberToListABC=Kl;exports.orderSearchArray=Js;exports.queryObjectMatrix=ra;exports.remove=Tn;exports.repeatStringNumTimes=ii;exports.replaceInDocumentBody=Ku;exports.requestImmediateMacroTask=Vu;exports.rotate=xl;exports.runOnLifecycle=Un;exports.searchArray=yo;exports.selectionToArray=nl;exports.sequence=ui;exports.sequenceAsync=ai;exports.sequenceExecute=hs;exports.sequenceExecuteAsync=ha;exports.shallowEqual=$u;exports.skipParseTagNames=cc;exports.sliceMatrixArray=Fl;exports.sortRules=Yl;exports.sortRulesByDesc=zl;exports.sortRulesFactory=Me;exports.spliceArray=qn;exports.textDecoder=xn;exports.textEncoder=nn;exports.throttle=ju;exports.toDisposable=bt;exports.transformDocumentDataToSnapshot=ac;exports.transformSnapshotToDocumentData=lc;exports.transformSnapshotToWorkbookData=oc;exports.transformWorkbookDataToSnapshot=ic;exports.updateAttributeByDelete=yi;exports.updateAttributeByInsert=xi;