@univerjs/sheets 0.10.13 → 0.10.14
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 +2 -2
- package/lib/es/index.js +224 -224
- package/lib/index.js +224 -224
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
package/lib/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(g,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/engine-formula"),require("rxjs/operators"),require("@univerjs/rpc")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/engine-formula","rxjs/operators","@univerjs/rpc"],i):(g=typeof globalThis<"u"?globalThis:g||self,i(g.UniverSheets={},g.UniverCore,g.rxjs,g.UniverEngineFormula,g.rxjs.operators,g.UniverRpc))})(this,(function(g,i,D,J,kt,$i){"use strict";var Wd=Object.defineProperty;var Vd=(g,i,D)=>i in g?Wd(g,i,{enumerable:!0,configurable:!0,writable:!0,value:D}):g[i]=D;var f=(g,i,D)=>Vd(g,typeof i!="symbol"?i+"":i,D);function Li(s,e,t){var r,a,l;if(e.t)return e.t;if(e.v===null)return null;const n=s.getStyleByCell(e),o=s.getStyleByCell(t);if(t.t===i.CellValueType.FORCE_STRING){if(!i.isTextFormat((r=o==null?void 0:o.n)==null?void 0:r.pattern)&&e.v!==void 0){if(i.isRealNum(e.v))return i.CellValueType.NUMBER;if(i.isBooleanString(`${e.v}`))return i.CellValueType.BOOLEAN}return i.CellValueType.FORCE_STRING}return Hi(n)?i.isTextFormat((a=n==null?void 0:n.n)==null?void 0:a.pattern)?i.CellValueType.STRING:eo(e,t):i.isTextFormat((l=o==null?void 0:o.n)==null?void 0:l.pattern)?i.CellValueType.STRING:eo(e,t)}function eo(s,e){return s.v!==void 0?Vn(s.v,s.t):Vn(e.v,e.t)}function Hi(s){var e;return!!((e=s==null?void 0:s.n)!=null&&e.pattern)}function Vn(s,e){return s===null?null:typeof s=="string"?i.isRealNum(s)?(+s==0||+s==1)&&e===i.CellValueType.BOOLEAN?i.CellValueType.BOOLEAN:e!==i.CellValueType.STRING&&e!==i.CellValueType.FORCE_STRING&&i.willLoseNumericPrecision(s)?i.CellValueType.FORCE_STRING:i.CellValueType.NUMBER:i.isBooleanString(s)?i.CellValueType.BOOLEAN:i.CellValueType.STRING:typeof s=="number"?(s===0||s===1)&&e===i.CellValueType.BOOLEAN?i.CellValueType.BOOLEAN:i.CellValueType.NUMBER:typeof s=="boolean"?i.CellValueType.BOOLEAN:i.CellValueType.FORCE_STRING}const ge=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:i.Tools.deepClone(e.ranges)}},j={id:"sheet.mutation.add-worksheet-merge",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const a=o.getConfig().mergeData,l=e.ranges;for(let u=0;u<l.length;u++)a.push(l[u]);return o.getSpanModel().rebuild(a),!0}},Bi=i.createInterceptorKey("CELL_CONTENT"),Fi=i.createInterceptorKey("ROW_FILTERED"),Ae={CELL_CONTENT:Bi,ROW_FILTERED:Fi};var to=(s=>(s[s.DATA_VALIDATION=9]="DATA_VALIDATION",s[s.NUMFMT=10]="NUMFMT",s[s.CELL_IMAGE=11]="CELL_IMAGE",s))(to||{});const no="sheet.interceptor.range-theme-id",so="sheet.interceptor.ignore-range-theme";var ji=Object.getOwnPropertyDescriptor,Gi=(s,e,t,n)=>{for(var o=n>1?void 0:n?ji(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},zi=(s,e)=>(t,n)=>e(t,n,s);const $n=i.createInterceptorKey("BEFORE_CELL_EDIT"),Zt=i.createInterceptorKey("AFTER_CELL_EDIT"),Qt=i.createInterceptorKey("VALIDATE_CELL");g.SheetInterceptorService=class extends i.Disposable{constructor(t){super();f(this,"_interceptorsByName",new Map);f(this,"_commandInterceptors",[]);f(this,"_rangeInterceptors",[]);f(this,"_autoHeightInterceptors",[]);f(this,"_beforeCommandInterceptor",[]);f(this,"_afterCommandInterceptors",[]);f(this,"_workbookDisposables",new Map);f(this,"_worksheetDisposables",new Map);f(this,"_interceptorsDirty",!1);f(this,"_composedInterceptorByKey",new Map);f(this,"writeCellInterceptor",new i.InterceptorManager({BEFORE_CELL_EDIT:$n,AFTER_CELL_EDIT:Zt,VALIDATE_CELL:Qt}));this._univerInstanceService=t,this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._interceptWorkbook(n)})),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>this._disposeWorkbookInterceptor(n))),this.intercept(Ae.CELL_CONTENT,{priority:-1,effect:i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value,handler:n=>n}),this.disposeWithMe(this.writeCellInterceptor.intercept(Zt,{priority:-1,handler:n=>n})),this.disposeWithMe(this.writeCellInterceptor.intercept($n,{priority:-1,handler:n=>n})),this.disposeWithMe(this.writeCellInterceptor.intercept(Qt,{priority:-1,handler:n=>n}))}dispose(){super.dispose(),this._workbookDisposables.forEach(t=>t.dispose()),this._workbookDisposables.clear(),this._worksheetDisposables.clear(),this._interceptorsByName.clear()}interceptCommand(t){if(this._commandInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._commandInterceptors.push(t),this._commandInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._commandInterceptors,t)))}onCommandExecute(t){const n=this._commandInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}interceptAfterCommand(t){if(this._afterCommandInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._afterCommandInterceptors.push(t),this._afterCommandInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._afterCommandInterceptors,t)))}afterCommandExecute(t){const n=this._afterCommandInterceptors.map(o=>o.getMutations(t));return{undos:n.map(o=>o.undos).flat(),redos:n.map(o=>o.redos).flat()}}interceptAutoHeight(t){if(this._autoHeightInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._autoHeightInterceptors.push(t),this._autoHeightInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._autoHeightInterceptors,t)))}generateMutationsOfAutoHeight(t){const n=this._autoHeightInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}interceptBeforeCommand(t){if(this._beforeCommandInterceptor.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._beforeCommandInterceptor.push(t),this._beforeCommandInterceptor.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._beforeCommandInterceptor,t)))}async beforeCommandExecute(t){return(await Promise.all(this._beforeCommandInterceptor.map(o=>o.performCheck(t)))).every(o=>o)}interceptRanges(t){if(this._rangeInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._rangeInterceptors.push(t),this._rangeInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._rangeInterceptors,t)))}generateMutationsByRanges(t){const n=this._rangeInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}onWriteCell(t,n,o,r,a){const l={subUnitId:n.getSheetId(),unitId:t.getUnitId(),workbook:t,worksheet:n,row:o,col:r,origin:i.Tools.deepClone(a)};return this.writeCellInterceptor.fetchThroughInterceptors(Zt)(a,l)}onValidateCell(t,n,o,r){const a={subUnitId:n.getSheetId(),unitId:t.getUnitId(),workbook:t,worksheet:n,row:o,col:r};return this.writeCellInterceptor.fetchThroughInterceptors(Qt)(Promise.resolve(!0),a)}intercept(t,n){const o=t;this._interceptorsByName.has(o)||this._interceptorsByName.set(o,[]);const r=this._interceptorsByName.get(o);r.push(n);const a=r.sort((l,u)=>{var d,c;return((d=u.priority)!=null?d:0)-((c=l.priority)!=null?c:0)});if(this._interceptorsDirty=!0,o===Ae.CELL_CONTENT){const l=i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value;this._interceptorsByName.set(`${o}-${l}`,a);const u=i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value;return this._interceptorsByName.set(`${o}-${i.InterceptorEffectEnum.Style}`,a.filter(d=>((d.effect||u)&i.InterceptorEffectEnum.Style)>0)),this._interceptorsByName.set(`${o}-${i.InterceptorEffectEnum.Value}`,a.filter(d=>((d.effect||u)&i.InterceptorEffectEnum.Value)>0)),this.disposeWithMe(i.toDisposable(()=>{i.remove(this._interceptorsByName.get(o),n),i.remove(this._interceptorsByName.get(`${o}-${l}`),n),i.remove(this._interceptorsByName.get(`${o}-${i.InterceptorEffectEnum.Style}`),n),i.remove(this._interceptorsByName.get(`${o}-${i.InterceptorEffectEnum.Value}`),n)}))}else return this._interceptorsByName.set(o,a),this.disposeWithMe(i.toDisposable(()=>i.remove(this._interceptorsByName.get(o),n)))}fetchThroughInterceptors(t,n,o,r){const a=n===void 0?t:`${t}-${n}`,l=o!=null?o:a;let u=this._composedInterceptorByKey.get(l);if(!u||this._interceptorsDirty){let d=this._interceptorsByName.get(a);d&&r&&(d=d.filter(r)),u=i.composeInterceptors(d||[]),this._composedInterceptorByKey.set(l,u)}return u}_interceptWorkbook(t){const n=new i.DisposableCollection,o=t.getUnitId(),r=this,a=l=>{const u=l.getSheetId();l.__interceptViewModel(d=>{const c=new i.DisposableCollection;r._worksheetDisposables.set(oo(o,l),c),c.add(d.registerCellContentInterceptor({getCell(m,h,R,C,S){const v=l.getCellRaw(m,h);return r.fetchThroughInterceptors(Ae.CELL_CONTENT,R,C,S)(v,{unitId:o,subUnitId:u,row:m,col:h,worksheet:l,workbook:t,rawData:v})}})),c.add(d.registerRowFilteredInterceptor({getRowFiltered(m){return!!r.fetchThroughInterceptors(Ae.ROW_FILTERED)(!1,{unitId:o,subUnitId:u,row:m,workbook:t,worksheet:l})}}))})};t.getSheets().forEach(l=>a(l)),n.add(t.sheetCreated$.subscribe(l=>a(l))),n.add(i.toDisposable(()=>t.getSheets().forEach(l=>this._disposeSheetInterceptor(o,l)))),n.add(t.sheetDisposed$.subscribe(l=>this._disposeSheetInterceptor(o,l))),this._workbookDisposables.set(o,n)}_disposeWorkbookInterceptor(t){const n=t.getUnitId(),o=this._workbookDisposables.get(n);o&&(o.dispose(),this._workbookDisposables.delete(n))}_disposeSheetInterceptor(t,n){const o=oo(t,n),r=this._worksheetDisposables.get(o);r&&(r.dispose(),this._worksheetDisposables.delete(o))}},g.SheetInterceptorService=Gi([zi(0,i.IUniverInstanceService)],g.SheetInterceptorService);function oo(s,e){return`${s}|${e.getSheetId()}`}const Z=s=>{const e={};return s.bg&&(e.bg={...s.bg}),s.ol&&(e.ol={...s.ol}),s.bd&&(e.bd={...s.bd}),s.cl&&(e.cl={...s.cl}),s.ht&&(e.ht=s.ht),s.vt&&(e.vt=s.vt),s.bl!==void 0&&(e.bl=s.bl),e};function qi(s){const e={};if(s.length===1)return s[0];for(const t of s)t.bg&&(e.bg=t.bg),t.ol&&(e.ol=t.ol),t.bd&&(e.bd={...e.bd,...t.bd}),t.cl&&(e.cl=t.cl),t.ht&&(e.ht=t.ht),t.vt&&(e.vt=t.vt),t.bl!==void 0&&(e.bl=t.bl);return e}const x={wholeStyle:1,headerRowStyle:2,headerColumnStyle:4,firstRowStyle:8,secondRowStyle:16,lastRowStyle:32,firstColumnStyle:128,secondColumnStyle:256,lastColumnStyle:512};class We{constructor(e,t){f(this,"_name");f(this,"wholeStyle",null);f(this,"headerRowStyle",null);f(this,"headerColumnStyle",null);f(this,"firstRowStyle",null);f(this,"secondRowStyle",null);f(this,"lastRowStyle",null);f(this,"firstColumnStyle",null);f(this,"secondColumnStyle",null);f(this,"lastColumnStyle",null);f(this,"_mergeCacheMap",new Map);t&&this.fromJson({...t,name:e}),this._name=e}getName(){return this._name}getWholeStyle(){return this.wholeStyle}setWholeStyle(e){this.wholeStyle=e,this._resetStyleCache()}getFirstRowStyle(){return this.firstRowStyle}setFirstRowStyle(e){this.firstRowStyle=e,this._resetStyleCache()}getSecondRowStyle(){return this.secondRowStyle}setSecondRowStyle(e){this.secondRowStyle=e,this._resetStyleCache()}getLastRowStyle(){return this.lastRowStyle}setLastRowStyle(e){this.lastRowStyle=e,this._resetStyleCache()}getFirstColumnStyle(){return this.firstColumnStyle}setFirstColumnStyle(e){this.firstColumnStyle=e,this._resetStyleCache()}getSecondColumnStyle(){return this.secondColumnStyle}setSecondColumnStyle(e){this.secondColumnStyle=e,this._resetStyleCache()}getLastColumnStyle(){return this.lastColumnStyle}setLastColumnStyle(e){this.lastColumnStyle=e,this._resetStyleCache()}getHeaderRowStyle(){return this.headerRowStyle}setHeaderRowStyle(e){this.headerRowStyle=e,this._resetStyleCache()}getHeaderColumnStyle(){return this.headerColumnStyle}setHeaderColumnStyle(e){this.headerColumnStyle=e,this._resetStyleCache()}getStyle(e,t,n,o,r){let a=0;return n&&(a=a|x.lastRowStyle),o&&(a=a|x.lastColumnStyle),e>=0&&t>=0&&(a=a|x.wholeStyle),e%2===1&&(a=a|(r?x.secondRowStyle:x.firstRowStyle)),e%2===0&&(a=a|(r?x.firstRowStyle:x.secondRowStyle)),e===0&&(a=a|x.headerRowStyle),t===0&&(a=a|x.headerColumnStyle),t%2===1&&(a=a|x.firstColumnStyle),t%2===0&&(a=a|x.secondColumnStyle),a===0?null:this._getMergeStyle(a)}_getMergeStyle(e){let t=this._mergeCacheMap.get(e);return t||(t=this._mergeStyle(e),this._mergeCacheMap.set(e,t)),t}_mergeStyle(e){const t=[];return this.wholeStyle&&e&x.wholeStyle&&t.push(this.wholeStyle),this.firstColumnStyle&&e&x.firstColumnStyle&&t.push(this.firstColumnStyle),this.secondColumnStyle&&e&x.secondColumnStyle&&t.push(this.secondColumnStyle),this.firstRowStyle&&e&x.firstRowStyle&&t.push(this.firstRowStyle),this.secondRowStyle&&e&x.secondRowStyle&&t.push(this.secondRowStyle),this.headerColumnStyle&&e&x.headerColumnStyle&&t.push(this.headerColumnStyle),this.lastColumnStyle&&e&x.lastColumnStyle&&t.push(this.lastColumnStyle),this.headerRowStyle&&e&x.headerRowStyle&&t.push(this.headerRowStyle),this.lastRowStyle&&e&x.lastRowStyle&&t.push(this.lastRowStyle),qi(t)}_resetStyleCache(){this._mergeCacheMap.clear()}toJson(){const e={name:this._name};return this.wholeStyle&&(e.wholeStyle=Z(this.wholeStyle)),this.headerRowStyle&&(e.headerRowStyle=Z(this.headerRowStyle)),this.headerColumnStyle&&(e.headerColumnStyle=Z(this.headerColumnStyle)),this.firstRowStyle&&(e.firstRowStyle=Z(this.firstRowStyle)),this.secondRowStyle&&(e.secondRowStyle=Z(this.secondRowStyle)),this.lastRowStyle&&(e.lastRowStyle=Z(this.lastRowStyle)),this.firstColumnStyle&&(e.firstColumnStyle=Z(this.firstColumnStyle)),this.secondColumnStyle&&(e.secondColumnStyle=Z(this.secondColumnStyle)),this.lastColumnStyle&&(e.lastColumnStyle=Z(this.lastColumnStyle)),e}fromJson(e){this._name=e.name,e.wholeStyle&&(this.wholeStyle=Z(e.wholeStyle)),e.headerRowStyle&&(this.headerRowStyle=Z(e.headerRowStyle)),e.headerColumnStyle&&(this.headerColumnStyle=Z(e.headerColumnStyle)),e.firstRowStyle&&(this.firstRowStyle=Z(e.firstRowStyle)),e.secondRowStyle&&(this.secondRowStyle=Z(e.secondRowStyle)),e.lastRowStyle&&(this.lastRowStyle=Z(e.lastRowStyle)),e.firstColumnStyle&&(this.firstColumnStyle=Z(e.firstColumnStyle)),e.secondColumnStyle&&(this.secondColumnStyle=Z(e.secondColumnStyle)),e.lastColumnStyle&&(this.lastColumnStyle=Z(e.lastColumnStyle))}dispose(){this._mergeCacheMap.clear()}}const Yi=(s,e,t)=>new We(`light-${s}`,{headerRowStyle:{bg:{rgb:e}},firstColumnStyle:{bg:{rgb:"rgb(255, 255, 255)"}},secondColumnStyle:{bg:{rgb:t}},lastRowStyle:{bg:{rgb:e}}}),Ki=(s,e,t)=>new We(`middle-${s}`,{headerRowStyle:{bg:{rgb:e}},headerColumnStyle:{bg:{rgb:t}},secondRowStyle:{bg:{rgb:t}},lastRowStyle:{bg:{rgb:e}},lastColumnStyle:{bg:{rgb:t}}}),Ji=(s,e,t,n)=>new We(`dark-${s}`,{headerRowStyle:{bg:{rgb:e},cl:{rgb:"rgb(255, 255, 255)"},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE},firstRowStyle:{bg:{rgb:t}},secondRowStyle:{bg:{rgb:n}},lastRowStyle:{bg:{rgb:e}}}),xi=[{baseName:"blue",header:"rgb(164, 202, 254)",color:"rgb(225, 239, 254)"},{baseName:"grey",header:"rgb(205, 208, 216)",color:"rgb(238, 239, 241)"},{baseName:"red",header:"rgb(248, 180, 180)",color:"rgb(253, 232, 232)"},{baseName:"orange",header:"rgb(253, 186, 140)",color:"rgb(254, 236, 220)"},{baseName:"yellow",header:"rgb(250, 200, 21)",color:"rgb(255, 244, 185)"},{baseName:"green",header:"rgb(132, 225, 188)",color:"rgb(222, 247, 236)"},{baseName:"azure",header:"rgb(126, 220, 226)",color:"rgb(213, 245, 246)"},{baseName:"indigo",header:"rgb(186, 198, 248)",color:"rgb(233, 237, 255)"},{baseName:"purple",header:"rgb(202, 191, 253)",color:"rgb(237, 235, 254)"},{baseName:"magenta",header:"rgb(248, 180, 217)",color:"rgb(252, 232, 243)"}],Xi=[{baseName:"blue",rowHeader:"rgb(63, 131, 248)",colHeader:"rgb(195, 221, 253)"},{baseName:"grey",rowHeader:"rgb(95, 101, 116)",colHeader:"rgb(227, 229, 234)"},{baseName:"red",rowHeader:"rgb(240, 82, 82)",colHeader:"rgb(251, 213, 213)"},{baseName:"orange",rowHeader:"rgb(255, 90, 31)",colHeader:"rgb(252, 217, 189)"},{baseName:"yellow",rowHeader:"rgb(212, 157, 15)",colHeader:"rgb(252, 220, 106)"},{baseName:"green",rowHeader:"rgb(13, 164, 113)",colHeader:"rgb(188, 240, 218)"},{baseName:"azure",rowHeader:"rgb(6, 148, 162)",colHeader:"rgb(175, 236, 239)"},{baseName:"indigo",rowHeader:"rgb(70, 106, 247)",colHeader:"rgb(210, 218, 250)"},{baseName:"purple",rowHeader:"rgb(144, 97, 249)",colHeader:"rgb(220, 215, 254)"},{baseName:"magenta",rowHeader:"rgb(231, 70, 148)",colHeader:"rgb(250, 209, 232)"}],Zi=[{baseName:"blue",rowHeader:"rgb(30, 66, 159)",firstRow:"rgb(195, 221, 253)",secondRow:"rgb(118, 169, 250)"},{baseName:"grey",rowHeader:"rgb(44, 48, 64)",firstRow:"rgb(227, 229, 234)",secondRow:"rgb(151, 157, 172)"},{baseName:"red",rowHeader:"rgb(155, 28, 28)",firstRow:"rgb(251, 213, 213)",secondRow:"rgb(249, 128, 128)"},{baseName:"orange",rowHeader:"rgb(180, 52, 3)",firstRow:"rgb(252, 217, 189)",secondRow:"rgb(255, 138, 76)"},{baseName:"yellow",rowHeader:"rgb(154, 109, 21)",firstRow:"rgb(252, 220, 106)",secondRow:"rgb(212, 157, 15)"},{baseName:"green",rowHeader:"rgb(4, 108, 78)",firstRow:"rgb(188, 240, 218)",secondRow:"rgb(49, 196, 141)"},{baseName:"azure",rowHeader:"rgb(3, 102, 114)",firstRow:"rgb(175, 236, 239)",secondRow:"rgb(22, 189, 202)"},{baseName:"indigo",rowHeader:"rgb(16, 51, 191)",firstRow:"rgb(210, 218, 250)",secondRow:"rgb(98, 128, 249)"},{baseName:"purple",rowHeader:"rgb(74, 29, 150)",firstRow:"rgb(220, 215, 254)",secondRow:"rgb(172, 148, 250)"},{baseName:"magenta",rowHeader:"rgb(153, 21, 75)",firstRow:"rgb(250, 209, 232)",secondRow:"rgb(241, 126, 184)"}],Qi=xi.map(({baseName:s,header:e,color:t})=>Yi(s,e,t)),ea=Xi.map(({baseName:s,rowHeader:e,colHeader:t})=>Ki(s,e,t)),ta=Zi.map(({baseName:s,rowHeader:e,firstRow:t,secondRow:n})=>Ji(s,e,t,n)),na=[...Qi,...ea,...ta],ro={headerRowStyle:{bg:{rgb:"rgb(68,114,196)"},cl:{rgb:"rgb(255,255,255)"},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE},firstRowStyle:{bg:{rgb:"rgb(217,225,242)"}}},sa=new We("default",ro),oa=new We("default-last-row",{...ro,lastRowStyle:{bd:{t:{s:i.BorderStyleTypes.THIN,cl:{rgb:"rgb(68,114,196)"}}},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE}});class ra{constructor(){f(this,"_toggleRanges",[])}refresh(e,t){const{startRow:n,endRow:o}=e,r=[];let a=0,l=!1,u=-1;for(let d=n;d<=o;d++){if(!t(d)){a++,a%2===1?l=!0:(l=!1,u!==-1&&(r.push([u,d-1]),u=-1));continue}a%2===1?l?u===-1&&(u=d):(l=!0,u=d):l&&(r.push([u,d-2]),l=!1,u=-1),d===o&&l&&r.push([u,d])}this._toggleRanges=r}getToggleRanges(){return this._toggleRanges.concat()}getIsToggled(e){let t=0,n=this._toggleRanges.length-1;for(;t<=n;){const o=Math.floor((t+n)/2),[r,a]=this._toggleRanges[o];if(e<r)n=o-1;else if(e>a)t=o+1;else return!0}return!1}}var ia=Object.getOwnPropertyDescriptor,aa=(s,e,t,n)=>{for(var o=n>1?void 0:n?ia(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ln=(s,e)=>(t,n)=>e(t,n,s);const la="SHEET_RANGE_THEME_MODEL_PLUGIN";g.SheetRangeThemeModel=class extends i.Disposable{constructor(t,n,o){super();f(this,"_rangeThemeStyleMap",new Map);f(this,"_rangeThemeStyleRuleMap",new Map);f(this,"_rTreeCollection",new Map);f(this,"_defaultRangeThemeMap",new Map);f(this,"_zebraCrossingCacheMap",new Map);f(this,"_rowVisibleFuncSet",new Map);f(this,"_rangeThemeMapChanged$",new D.Subject);f(this,"rangeThemeMapChange$",this._rangeThemeMapChanged$.asObservable());this._sheetInterceptorService=t,this._resourceManagerService=n,this._univerInstanceService=o,this._registerIntercept(),this._initSnapshot(),this._initDefaultTheme()}_initDefaultTheme(){this.registerDefaultRangeTheme(sa),this.registerDefaultRangeTheme(oa);for(const t of na)this.registerDefaultRangeTheme(t)}_ensureRangeThemeStyleMap(t){return this._rangeThemeStyleMap.has(t)||this._rangeThemeStyleMap.set(t,new Map),this._rangeThemeStyleMap.get(t)}_ensureRangeThemeStyleRuleMap(t){return this._rangeThemeStyleRuleMap.has(t)||this._rangeThemeStyleRuleMap.set(t,new Map),this._rangeThemeStyleRuleMap.get(t)}_ensureRTreeCollection(t){return this._rTreeCollection.has(t)||this._rTreeCollection.set(t,new i.RTree),this._rTreeCollection.get(t)}getDefaultRangeThemeStyle(t){return this._defaultRangeThemeMap.get(t)}getCustomRangeThemeStyle(t,n){return this._ensureRangeThemeStyleMap(t).get(n)}_getSheetRowVisibleFuncSet(t,n){this._rowVisibleFuncSet.has(t)||this._rowVisibleFuncSet.set(t,new Map);const o=this._rowVisibleFuncSet.get(t);return o.has(n)||o.set(n,new Set),o.get(n)}_getSheetRowVisibleHasInit(t,n){var o;return!!(this._rowVisibleFuncSet.has(t)&&((o=this._rowVisibleFuncSet.get(t))!=null&&o.has(n)))}refreshSheetRowVisibleFuncSet(t,n){const o=this._getSheetRowVisibleFuncSet(t,n);o.clear();const r=this._univerInstanceService.getUnit(t);if(r){const a=r.getSheetBySheetId(n);if(a){const l=a.getRowCount(),u=a.getRowManager();for(let d=1;d<=l;d++)a.getRowVisible(d)?u.getRowHeight(d)===0&&o.add(d):o.add(d)}}}_ensureZebraCrossingCache(t,n,o){this._zebraCrossingCacheMap.has(t)||this._zebraCrossingCacheMap.set(t,new Map);const r=this._zebraCrossingCacheMap.get(t);r.has(n)||r.set(n,new Map);const a=r.get(n);return a.has(o)||a.set(o,new ra),a.get(o)}registerRangeThemeRule(t,n){const{unitId:o,subUnitId:r,range:a}=n,l=i.generateRandomId(),u=this._ensureRangeThemeStyleRuleMap(o),d=this._ensureRTreeCollection(o);u.set(l,{rangeInfo:n,themeName:t}),d.insert({unitId:o,sheetId:r,range:a,id:l}),this._getSheetRowVisibleHasInit(o,r)||this.refreshSheetRowVisibleFuncSet(o,r);const c=this._ensureZebraCrossingCache(o,r,l),m=this._getSheetRowVisibleFuncSet(o,r);c.refresh(a,h=>!m.has(h))}getRegisteredRangeThemeStyle(t){const{unitId:n,subUnitId:o,range:r}=t,a=this._ensureRTreeCollection(n),l=Array.from(a.bulkSearch([{unitId:n,sheetId:o,range:r}]));if(l[0]){const d=this._ensureRangeThemeStyleRuleMap(n).get(l[0]);if(d)return d.themeName}}refreshZebraCrossingCacheBySheet(t,n){this._zebraCrossingCacheMap.has(t)||this._zebraCrossingCacheMap.set(t,new Map);const o=this._zebraCrossingCacheMap.get(t);o.has(n)||o.set(n,new Map);const r=o.get(n);r&&r.forEach((a,l)=>{const d=this._ensureRangeThemeStyleRuleMap(t).get(l);d?a.refresh(d.rangeInfo.range,c=>!this._getSheetRowVisibleFuncSet(t,n).has(c)):r.delete(l)})}removeRangeThemeRule(t,n){const{unitId:o,subUnitId:r,range:a}=n,l=this._ensureRTreeCollection(o),u=Array.from(l.bulkSearch([{unitId:o,sheetId:r,range:a}])),d=this._ensureRangeThemeStyleRuleMap(o);for(let c=0;c<u.length;c++){const m=d.get(u[c]);if(m&&m.themeName===t){d.delete(u[c]),l.remove({unitId:o,sheetId:r,range:a,id:u[c]});const h=this._zebraCrossingCacheMap.get(o);if(h){const R=h.get(r);R&&R.delete(u[c])}break}}}registerDefaultRangeTheme(t){this._defaultRangeThemeMap.set(t.getName(),t),this._rangeThemeMapChanged$.next({type:"add",styleName:t.getName()})}unRegisterDefaultRangeTheme(t){this._defaultRangeThemeMap.delete(t),this._rangeThemeMapChanged$.next({type:"remove",styleName:t})}getRegisteredRangeThemes(){return Array.from(this._defaultRangeThemeMap.keys())}registerRangeThemeStyle(t,n){this._ensureRangeThemeStyleMap(t).set(n.getName(),n),this._rangeThemeMapChanged$.next({type:"add",styleName:n.getName()})}unregisterRangeThemeStyle(t,n){this._ensureRangeThemeStyleMap(t).delete(n),this._rangeThemeMapChanged$.next({type:"remove",styleName:n})}getALLRegisteredTheme(t){return Array.from(this._ensureRangeThemeStyleMap(t).keys())}getRangeThemeStyle(t,n){return this._defaultRangeThemeMap.has(n)?this._defaultRangeThemeMap.get(n):this._ensureRangeThemeStyleMap(t).get(n)}getCellStyle(t,n,o,r){const a={startRow:o,startColumn:r,endRow:o,endColumn:r},l=this._ensureRTreeCollection(t),u=Array.from(l.bulkSearch([{unitId:t,sheetId:n,range:a}]));if(u[0]){const c=this._ensureRangeThemeStyleRuleMap(t).get(u[0]);if(c){const{rangeInfo:m,themeName:h}=c,R=o-m.range.startRow,C=r-m.range.startColumn,S=this.getRangeThemeStyle(t,h),I=this._ensureZebraCrossingCache(t,n,u[0]).getIsToggled(o);if(S)return S.getStyle(R,C,o===m.range.endRow,r===m.range.endColumn,I)}}}_registerIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{id:no,effect:i.InterceptorEffectEnum.Style,handler:(t,n,o)=>{const{row:r,col:a,unitId:l,subUnitId:u}=n,d=this.getCellStyle(l,u,r,a);if(d){const c=!t||t===n.rawData?{...n.rawData}:t;return c.themeStyle=d,o(c)}return o(t)}}))}toJson(t){const n=this._ensureRangeThemeStyleRuleMap(t),o=this._ensureRangeThemeStyleMap(t);if(o.size===0&&n.size===0)return"{}";const r={};n.forEach((l,u)=>{r[u]=l});const a={};return o.forEach((l,u)=>{a[u]=l.toJson()}),JSON.stringify({rangeThemeStyleRuleMap:r,rangeThemeStyleMapJson:a})}fromJSON(t,n){const{rangeThemeStyleRuleMap:o,rangeThemeStyleMapJson:r}=n;o&&Object.keys(o).forEach(a=>{const l=o[a],{themeName:u,rangeInfo:d}=l;u.startsWith("table")||(this.registerRangeThemeRule(u,d),this._ensureRTreeCollection(d.unitId).insert({unitId:a,sheetId:d.subUnitId,range:d.range,id:a}))}),r&&Object.keys(r).forEach(a=>{const l=r[a],u=new We(l.name);u.fromJson(l),this._ensureRangeThemeStyleMap(t).set(u.getName(),u)})}deleteUnitId(t){this._rangeThemeStyleMap.delete(t),this._rangeThemeStyleRuleMap.delete(t),this._rTreeCollection.delete(t)}_initSnapshot(){this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:t=>this.toJson(t),parseJson:t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}},businesses:[i.UniverInstanceType.UNIVER_SHEET],pluginName:la,onLoad:(t,n)=>{this.fromJSON(t,n)},onUnLoad:t=>{this.deleteUnitId(t)}}))}dispose(){super.dispose(),this._rangeThemeStyleMap.clear(),this._rangeThemeStyleRuleMap.clear(),this._defaultRangeThemeMap.clear(),this._rTreeCollection.clear(),this._zebraCrossingCacheMap.clear(),this._rowVisibleFuncSet.clear()}},g.SheetRangeThemeModel=aa([Ln(0,i.Inject(g.SheetInterceptorService)),Ln(1,i.Inject(i.IResourceManagerService)),Ln(2,i.Inject(i.IUniverInstanceService))],g.SheetRangeThemeModel);function Hn(s,e){const{unitId:t}=e,n=t?s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):s.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET);return n?{workbook:n,unitId:n.getUnitId()}:null}function P(s,e={}){const{unitId:t,subUnitId:n}=e,o=t?s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):s.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=n?o.getSheetBySheetId(n):o.getActiveSheet(!0);return r?{worksheet:r,workbook:o,unitId:o.getUnitId(),subUnitId:r.getSheetId()}:null}function Ie(s,e){const{unitId:t,subUnitId:n}=e,o=s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=o.getSheetBySheetId(n);return r?{worksheet:r,workbook:o}:null}const rt={id:"sheet.mutation.set-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,themeName:r}=e,a=s.get(i.IUniverInstanceService),l=P(a),u=s.get(g.SheetRangeThemeModel);return l?(u.registerRangeThemeRule(r,{range:o,unitId:t,subUnitId:n}),!0):!1}},io=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),range:e.range,themeName:e.themeName}},it={id:"sheet.mutation.remove-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,themeName:r}=e,a=s.get(i.IUniverInstanceService),l=P(a),u=s.get(g.SheetRangeThemeModel);return l?(u.removeRangeThemeRule(r,{range:o,unitId:t,subUnitId:n}),!0):!1}},ao=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),range:e.range,themeName:e.themeName}},en=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}},re={id:"sheet.mutation.insert-row",type:i.CommandType.MUTATION,handler:(s,e)=>{var C;const{unitId:t,subUnitId:n,range:o,rowInfo:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(l==null)throw new Error("universheet is null error!");const u=l.getSheetBySheetId(n);if(u==null)throw new Error("worksheet is null error!");const d=u.getRowManager().getRowData(),c={h:u.getConfig().defaultRowHeight,hd:0},m=o.startRow,h=o.endRow-o.startRow+1;for(let S=m;S<m+h;S++)r?i.insertMatrixArray(S,(C=r[S-o.startRow])!=null?C:c,d):i.insertMatrixArray(S,c,d);return u.setRowCount(u.getRowCount()+h),u.getCellMatrix().insertRows(o.startRow,h),!0}},Ot=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}},ie={id:"sheet.mutation.insert-col",type:i.CommandType.MUTATION,handler:(s,e)=>{var C;const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=o.getColumnManager(),{range:a,colInfo:l}=e,d=r.getColumnData(),c=a.startColumn,m=a.endColumn-a.startColumn+1,h=o.getConfig().defaultColumnWidth;for(let S=c;S<c+m;S++){const v={w:h,hd:0};l?i.insertMatrixArray(S,(C=l[S-a.startColumn])!=null?C:v,d):i.insertMatrixArray(S,v,d)}return o.setColumnCount(o.getColumnCount()+a.endColumn-a.startColumn+1),o.getCellMatrix().insertColumns(a.startColumn,m),!0}},Le={id:"sheet.mutation.move-range",type:i.CommandType.MUTATION,handler:(s,e)=>{const{from:t,to:n}=e;if(!t||!n)return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getSheetBySheetId(e.from.subUnitId),l=r.getSheetBySheetId(e.to.subUnitId);if(!a||!l)return!1;const u=a.getCellMatrix(),d=l.getCellMatrix();return new i.ObjectMatrix(t.value).forValue((c,m,h)=>{h==null?u.realDeleteValue(c,m):u.setValue(c,m,h)}),new i.ObjectMatrix(n.value).forValue((c,m,h)=>{h==null?d.realDeleteValue(c,m):d.setValue(c,m,h)}),!0}};function lo(s,e){const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,a=o.startRow>r.startRow,l=o.endRow-o.startRow+1;return a?{unitId:t,subUnitId:n,sourceRange:i.Rectangle.clone(r),targetRange:{...o,endRow:o.endRow+l,startRow:o.startRow+l}}:{unitId:t,subUnitId:n,targetRange:i.Rectangle.clone(o),sourceRange:{...r,endRow:r.endRow-l,startRow:r.startRow-l}}}const pe={id:"sheet.mutation.move-rows",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(!l)throw new Error("[MoveRowMutation] univerSheet is null!");const u=l.getSheetBySheetId(n);if(!u)throw new Error("[MoveRowMutation] worksheet is null!");const d=o.startRow,c=o.endRow-o.startRow+1,m=r.startRow,h=u.getRowManager().getRowData();return i.moveMatrixArray(d,c,m,h),u.getCellMatrix().moveRows(d,c,m),!0}};function uo(s,e){const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,a=o.startColumn>r.startColumn,l=o.endColumn-o.startColumn+1;return a?{unitId:t,subUnitId:n,sourceRange:i.Rectangle.clone(r),targetRange:{...o,endColumn:o.endColumn+l,startColumn:o.startColumn+l}}:{unitId:t,subUnitId:n,targetRange:i.Rectangle.clone(o),sourceRange:{...r,startColumn:r.startColumn-l,endColumn:r.endColumn-l}}}const we={id:"sheet.mutation.move-columns",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(!l)throw new Error("[MoveColumnMutation] univerSheet is null!");const u=l.getSheetBySheetId(n);if(!u)throw new Error("[MoveColumnMutation] worksheet is null!");const d=o.startColumn,c=o.endColumn-o.startColumn+1,m=r.startColumn,h=u.getColumnManager().getColumnData();return i.moveMatrixArray(d,c,m,h),u.getCellMatrix().moveColumns(d,c,m),!0}},ua=(s,e)=>{const o=e.getRowManager().getRowData(),r={},a=s.range,l=i.sliceMatrixArray(a.startRow,a.endRow,o),u=i.concatMatrixArray(r,l);return{unitId:s.unitId,subUnitId:s.subUnitId,range:s.range,rowInfo:u}},ae={id:"sheet.mutation.remove-rows",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=e.range,l=o.getRowManager().getRowData();for(let c=r.startRow;c<=r.endRow;c++)o.getRowFiltered(c);const u=r.endRow-r.startRow+1;return i.spliceArray(r.startRow,u,l),o.getCellMatrix().removeRows(r.startRow,u),o.setRowCount(o.getRowCount()-u),!0}},da=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const l=o.getColumnManager().getColumnData(),u={},d=e.range,c=i.sliceMatrixArray(d.startColumn,d.endColumn,l),m=i.concatMatrixArray(u,c);return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,colInfo:m}},ne={id:"sheet.mutation.remove-col",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=e.range,l=o.getColumnManager().getColumnData(),u=r.endColumn-r.startColumn+1;return i.spliceArray(r.startColumn,u,l),o.setColumnCount(o.getColumnCount()-u),o.getCellMatrix().removeColumns(r.startColumn,u),!0}},le=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const a=o.getConfig().mergeData,l=e.ranges,u=[];for(let d=0;d<l.length;d++)for(let c=a.length-1;c>=0;c--){const m=a[c],h=l[d];i.Rectangle.intersects(m,h)&&u.push(a[c])}return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:u}},G={id:"sheet.mutation.remove-worksheet-merge",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const a=o.getConfig().mergeData,l=e.ranges;for(let u=0;u<l.length;u++)for(let d=a.length-1;d>=0;d--){const c=a[d],m=l[u];i.Rectangle.intersects(c,m)&&a.splice(d,1)}return o.getSpanModel().rebuild(a),!0}},co=s=>{const{order:e}=s,t={};return Object.keys(e).forEach(n=>{t[e[Number(n)]]=Number(n)}),{...s,order:t}},Dt={id:"sheet.mutation.reorder-range",type:i.CommandType.MUTATION,handler:(s,e)=>{const{subUnitId:t,unitId:n,range:o,order:r}=e,u=s.get(i.IUniverInstanceService).getUnit(n).getSheetBySheetId(t);if(!u)return!1;const d=new i.ObjectMatrix;i.Range.foreach(o,(m,h)=>{if(r.hasOwnProperty(m)){const R=r[m],C=i.Tools.deepClone(u.getCellRaw(R,h));d.setValue(m,h,C)}});const c=u.getCellMatrix();return d.forValue((m,h,R)=>{c.setValue(m,h,R)}),!0}};function ca(s,e){if(s==null)return s;const t=i.Tools.deepClone(s);if(e==null)return t;const n={};return"h"in e&&(n.h=t.h),"ia"in e&&(n.ia=t.ia),"ah"in e&&(n.ah=t.ah),"hd"in e&&(n.hd=t.hd),"s"in e&&(n.s=t.s),"custom"in e&&(n.custom=t.custom),n}function ma(s,e){if(s==null)return s;const t=i.Tools.deepClone(s);if(e==null)return t;const n={};return"w"in e&&(n.w=t.w),"hd"in e&&(n.hd=t.hd),"s"in e&&(n.s=t.s),"custom"in e&&(n.custom=t.custom),n}const mo=(s,e)=>{const{unitId:t,subUnitId:n,columnData:o}=s,r={},a=e.getColumnManager();for(const l in o){const u=o[l],d=a.getColumn(Number(l));r[l]=ma(d,u)}return{unitId:t,subUnitId:n,columnData:r}},at={id:"sheet.mutation.set-col-data",type:i.CommandType.MUTATION,handler:(s,e)=>{const{columnData:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const{worksheet:r}=o,a=r.getColumnManager();for(const l in t){const u=t[l];if(u==null){a.removeColumn(Number(l));continue}const d=a.getColumnOrCreate(Number(l));Object.assign(d,u)}return!0}},ha=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},lt={id:"sheet.mutation.set-col-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!n)return!1;const o=n.getSheetBySheetId(e.subUnitId).getColumnManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startColumn;l<a.endColumn+1;l++){const u=o.getColumnOrCreate(l);u!=null&&(u.hd=i.BooleanNumber.TRUE)}}return!0}},ga=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},ut={id:"sheet.mutation.set-col-visible",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!n)return!1;const o=n.getSheetBySheetId(e.subUnitId).getColumnManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startColumn;l<a.endColumn+1;l++){const u=o.getColumnOrCreate(l);u!=null&&(u.hd=i.BooleanNumber.FALSE)}}return!0}},dt={id:"sheet.mutation.set-gridlines-color",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=P(s.get(i.IUniverInstanceService),e);if(!t)return!1;const{worksheet:n}=t,o=n.getConfig();return o.gridlinesColor=e.color,!0}};function Ra(s,e,t){var a;const n=s.getStyleByCell(e);n==null&&delete e.s,typeof t.s=="string"&&(t.s=s.get(t.s));const o=tn(n,t.s?t.s:null);o&&(i.Tools.removeNull(o),Object.entries(o).forEach(([l,u])=>{typeof u=="object"&&u!==null&&Object.keys(u).length===0&&delete o[l]})),i.Tools.isEmptyObject(o)?delete e.s:e.s=s.setValue(o);const r=t.v?`${t.v}\r
|
|
1
|
+
(function(g,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/engine-formula"),require("rxjs/operators"),require("@univerjs/rpc")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/engine-formula","rxjs/operators","@univerjs/rpc"],i):(g=typeof globalThis<"u"?globalThis:g||self,i(g.UniverSheets={},g.UniverCore,g.rxjs,g.UniverEngineFormula,g.rxjs.operators,g.UniverRpc))})(this,(function(g,i,O,J,kt,$i){"use strict";var Wd=Object.defineProperty;var Vd=(g,i,O)=>i in g?Wd(g,i,{enumerable:!0,configurable:!0,writable:!0,value:O}):g[i]=O;var f=(g,i,O)=>Vd(g,typeof i!="symbol"?i+"":i,O);function Li(s,e,t){var r,a,l;if(e.t)return e.t;if(e.v===null)return null;const n=s.getStyleByCell(e),o=s.getStyleByCell(t);if(t.t===i.CellValueType.FORCE_STRING){if(!i.isTextFormat((r=o==null?void 0:o.n)==null?void 0:r.pattern)&&e.v!==void 0){if(i.isRealNum(e.v))return i.CellValueType.NUMBER;if(i.isBooleanString(`${e.v}`))return i.CellValueType.BOOLEAN}return i.CellValueType.FORCE_STRING}return Hi(n)?i.isTextFormat((a=n==null?void 0:n.n)==null?void 0:a.pattern)?i.CellValueType.STRING:eo(e,t):i.isTextFormat((l=o==null?void 0:o.n)==null?void 0:l.pattern)?i.CellValueType.STRING:eo(e,t)}function eo(s,e){return s.v!==void 0?Vn(s.v,s.t):Vn(e.v,e.t)}function Hi(s){var e;return!!((e=s==null?void 0:s.n)!=null&&e.pattern)}function Vn(s,e){return s===null?null:typeof s=="string"?i.isRealNum(s)?(+s==0||+s==1)&&e===i.CellValueType.BOOLEAN?i.CellValueType.BOOLEAN:e!==i.CellValueType.STRING&&e!==i.CellValueType.FORCE_STRING&&i.willLoseNumericPrecision(s)?i.CellValueType.FORCE_STRING:i.CellValueType.NUMBER:i.isBooleanString(s)?i.CellValueType.BOOLEAN:i.CellValueType.STRING:typeof s=="number"?(s===0||s===1)&&e===i.CellValueType.BOOLEAN?i.CellValueType.BOOLEAN:i.CellValueType.NUMBER:typeof s=="boolean"?i.CellValueType.BOOLEAN:i.CellValueType.FORCE_STRING}const ge=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:i.Tools.deepClone(e.ranges)}},j={id:"sheet.mutation.add-worksheet-merge",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const a=o.getConfig().mergeData,l=e.ranges;for(let u=0;u<l.length;u++)a.push(l[u]);return o.getSpanModel().rebuild(a),!0}},Bi=i.createInterceptorKey("CELL_CONTENT"),Fi=i.createInterceptorKey("ROW_FILTERED"),Ae={CELL_CONTENT:Bi,ROW_FILTERED:Fi};var to=(s=>(s[s.DATA_VALIDATION=9]="DATA_VALIDATION",s[s.NUMFMT=10]="NUMFMT",s[s.CELL_IMAGE=11]="CELL_IMAGE",s))(to||{});const no="sheet.interceptor.range-theme-id",so="sheet.interceptor.ignore-range-theme";var ji=Object.getOwnPropertyDescriptor,Gi=(s,e,t,n)=>{for(var o=n>1?void 0:n?ji(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},zi=(s,e)=>(t,n)=>e(t,n,s);const $n=i.createInterceptorKey("BEFORE_CELL_EDIT"),Zt=i.createInterceptorKey("AFTER_CELL_EDIT"),Qt=i.createInterceptorKey("VALIDATE_CELL");g.SheetInterceptorService=class extends i.Disposable{constructor(t){super();f(this,"_interceptorsByName",new Map);f(this,"_commandInterceptors",[]);f(this,"_rangeInterceptors",[]);f(this,"_autoHeightInterceptors",[]);f(this,"_beforeCommandInterceptor",[]);f(this,"_afterCommandInterceptors",[]);f(this,"_workbookDisposables",new Map);f(this,"_worksheetDisposables",new Map);f(this,"_interceptorsDirty",!1);f(this,"_composedInterceptorByKey",new Map);f(this,"writeCellInterceptor",new i.InterceptorManager({BEFORE_CELL_EDIT:$n,AFTER_CELL_EDIT:Zt,VALIDATE_CELL:Qt}));this._univerInstanceService=t,this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._interceptWorkbook(n)})),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>this._disposeWorkbookInterceptor(n))),this.intercept(Ae.CELL_CONTENT,{priority:-1,effect:i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value,handler:n=>n}),this.disposeWithMe(this.writeCellInterceptor.intercept(Zt,{priority:-1,handler:n=>n})),this.disposeWithMe(this.writeCellInterceptor.intercept($n,{priority:-1,handler:n=>n})),this.disposeWithMe(this.writeCellInterceptor.intercept(Qt,{priority:-1,handler:n=>n}))}dispose(){super.dispose(),this._workbookDisposables.forEach(t=>t.dispose()),this._workbookDisposables.clear(),this._worksheetDisposables.clear(),this._interceptorsByName.clear()}interceptCommand(t){if(this._commandInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._commandInterceptors.push(t),this._commandInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._commandInterceptors,t)))}onCommandExecute(t){const n=this._commandInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}interceptAfterCommand(t){if(this._afterCommandInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._afterCommandInterceptors.push(t),this._afterCommandInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._afterCommandInterceptors,t)))}afterCommandExecute(t){const n=this._afterCommandInterceptors.map(o=>o.getMutations(t));return{undos:n.map(o=>o.undos).flat(),redos:n.map(o=>o.redos).flat()}}interceptAutoHeight(t){if(this._autoHeightInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._autoHeightInterceptors.push(t),this._autoHeightInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._autoHeightInterceptors,t)))}generateMutationsOfAutoHeight(t){const n=this._autoHeightInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}interceptBeforeCommand(t){if(this._beforeCommandInterceptor.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._beforeCommandInterceptor.push(t),this._beforeCommandInterceptor.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._beforeCommandInterceptor,t)))}async beforeCommandExecute(t){return(await Promise.all(this._beforeCommandInterceptor.map(o=>o.performCheck(t)))).every(o=>o)}interceptRanges(t){if(this._rangeInterceptors.includes(t))throw new Error("[SheetInterceptorService]: Interceptor already exists!");return this._rangeInterceptors.push(t),this._rangeInterceptors.sort((n,o)=>{var r,a;return((r=o.priority)!=null?r:0)-((a=n.priority)!=null?a:0)}),this.disposeWithMe(i.toDisposable(()=>i.remove(this._rangeInterceptors,t)))}generateMutationsByRanges(t){const n=this._rangeInterceptors.map(o=>o.getMutations(t));return{preUndos:n.map(o=>{var r;return(r=o.preUndos)!=null?r:[]}).flat(),undos:n.map(o=>o.undos).flat(),preRedos:n.map(o=>{var r;return(r=o.preRedos)!=null?r:[]}).flat(),redos:n.map(o=>o.redos).flat()}}onWriteCell(t,n,o,r,a){const l={subUnitId:n.getSheetId(),unitId:t.getUnitId(),workbook:t,worksheet:n,row:o,col:r,origin:i.Tools.deepClone(a)};return this.writeCellInterceptor.fetchThroughInterceptors(Zt)(a,l)}onValidateCell(t,n,o,r){const a={subUnitId:n.getSheetId(),unitId:t.getUnitId(),workbook:t,worksheet:n,row:o,col:r};return this.writeCellInterceptor.fetchThroughInterceptors(Qt)(Promise.resolve(!0),a)}intercept(t,n){const o=t;this._interceptorsByName.has(o)||this._interceptorsByName.set(o,[]);const r=this._interceptorsByName.get(o);r.push(n);const a=r.sort((l,u)=>{var d,c;return((d=u.priority)!=null?d:0)-((c=l.priority)!=null?c:0)});if(this._interceptorsDirty=!0,o===Ae.CELL_CONTENT){const l=i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value;this._interceptorsByName.set(`${o}-${l}`,a);const u=i.InterceptorEffectEnum.Style|i.InterceptorEffectEnum.Value;return this._interceptorsByName.set(`${o}-${i.InterceptorEffectEnum.Style}`,a.filter(d=>((d.effect||u)&i.InterceptorEffectEnum.Style)>0)),this._interceptorsByName.set(`${o}-${i.InterceptorEffectEnum.Value}`,a.filter(d=>((d.effect||u)&i.InterceptorEffectEnum.Value)>0)),this.disposeWithMe(i.toDisposable(()=>{i.remove(this._interceptorsByName.get(o),n),i.remove(this._interceptorsByName.get(`${o}-${l}`),n),i.remove(this._interceptorsByName.get(`${o}-${i.InterceptorEffectEnum.Style}`),n),i.remove(this._interceptorsByName.get(`${o}-${i.InterceptorEffectEnum.Value}`),n)}))}else return this._interceptorsByName.set(o,a),this.disposeWithMe(i.toDisposable(()=>i.remove(this._interceptorsByName.get(o),n)))}fetchThroughInterceptors(t,n,o,r){const a=n===void 0?t:`${t}-${n}`,l=o!=null?o:a;let u=this._composedInterceptorByKey.get(l);if(!u||this._interceptorsDirty){let d=this._interceptorsByName.get(a);d&&r&&(d=d.filter(r)),u=i.composeInterceptors(d||[]),this._composedInterceptorByKey.set(l,u)}return u}_interceptWorkbook(t){const n=new i.DisposableCollection,o=t.getUnitId(),r=this,a=l=>{const u=l.getSheetId();l.__interceptViewModel(d=>{const c=new i.DisposableCollection;r._worksheetDisposables.set(oo(o,l),c),c.add(d.registerCellContentInterceptor({getCell(m,h,R,C,S){const v=l.getCellRaw(m,h);return r.fetchThroughInterceptors(Ae.CELL_CONTENT,R,C,S)(v,{unitId:o,subUnitId:u,row:m,col:h,worksheet:l,workbook:t,rawData:v})}})),c.add(d.registerRowFilteredInterceptor({getRowFiltered(m){return!!r.fetchThroughInterceptors(Ae.ROW_FILTERED)(!1,{unitId:o,subUnitId:u,row:m,workbook:t,worksheet:l})}}))})};t.getSheets().forEach(l=>a(l)),n.add(t.sheetCreated$.subscribe(l=>a(l))),n.add(i.toDisposable(()=>t.getSheets().forEach(l=>this._disposeSheetInterceptor(o,l)))),n.add(t.sheetDisposed$.subscribe(l=>this._disposeSheetInterceptor(o,l))),this._workbookDisposables.set(o,n)}_disposeWorkbookInterceptor(t){const n=t.getUnitId(),o=this._workbookDisposables.get(n);o&&(o.dispose(),this._workbookDisposables.delete(n))}_disposeSheetInterceptor(t,n){const o=oo(t,n),r=this._worksheetDisposables.get(o);r&&(r.dispose(),this._worksheetDisposables.delete(o))}},g.SheetInterceptorService=Gi([zi(0,i.IUniverInstanceService)],g.SheetInterceptorService);function oo(s,e){return`${s}|${e.getSheetId()}`}const Z=s=>{const e={};return s.bg&&(e.bg={...s.bg}),s.ol&&(e.ol={...s.ol}),s.bd&&(e.bd={...s.bd}),s.cl&&(e.cl={...s.cl}),s.ht&&(e.ht=s.ht),s.vt&&(e.vt=s.vt),s.bl!==void 0&&(e.bl=s.bl),e};function qi(s){const e={};if(s.length===1)return s[0];for(const t of s)t.bg&&(e.bg=t.bg),t.ol&&(e.ol=t.ol),t.bd&&(e.bd={...e.bd,...t.bd}),t.cl&&(e.cl=t.cl),t.ht&&(e.ht=t.ht),t.vt&&(e.vt=t.vt),t.bl!==void 0&&(e.bl=t.bl);return e}const x={wholeStyle:1,headerRowStyle:2,headerColumnStyle:4,firstRowStyle:8,secondRowStyle:16,lastRowStyle:32,firstColumnStyle:128,secondColumnStyle:256,lastColumnStyle:512};class We{constructor(e,t){f(this,"_name");f(this,"wholeStyle",null);f(this,"headerRowStyle",null);f(this,"headerColumnStyle",null);f(this,"firstRowStyle",null);f(this,"secondRowStyle",null);f(this,"lastRowStyle",null);f(this,"firstColumnStyle",null);f(this,"secondColumnStyle",null);f(this,"lastColumnStyle",null);f(this,"_mergeCacheMap",new Map);t&&this.fromJson({...t,name:e}),this._name=e}getName(){return this._name}getWholeStyle(){return this.wholeStyle}setWholeStyle(e){this.wholeStyle=e,this._resetStyleCache()}getFirstRowStyle(){return this.firstRowStyle}setFirstRowStyle(e){this.firstRowStyle=e,this._resetStyleCache()}getSecondRowStyle(){return this.secondRowStyle}setSecondRowStyle(e){this.secondRowStyle=e,this._resetStyleCache()}getLastRowStyle(){return this.lastRowStyle}setLastRowStyle(e){this.lastRowStyle=e,this._resetStyleCache()}getFirstColumnStyle(){return this.firstColumnStyle}setFirstColumnStyle(e){this.firstColumnStyle=e,this._resetStyleCache()}getSecondColumnStyle(){return this.secondColumnStyle}setSecondColumnStyle(e){this.secondColumnStyle=e,this._resetStyleCache()}getLastColumnStyle(){return this.lastColumnStyle}setLastColumnStyle(e){this.lastColumnStyle=e,this._resetStyleCache()}getHeaderRowStyle(){return this.headerRowStyle}setHeaderRowStyle(e){this.headerRowStyle=e,this._resetStyleCache()}getHeaderColumnStyle(){return this.headerColumnStyle}setHeaderColumnStyle(e){this.headerColumnStyle=e,this._resetStyleCache()}getStyle(e,t,n,o,r){let a=0;return n&&(a=a|x.lastRowStyle),o&&(a=a|x.lastColumnStyle),e>=0&&t>=0&&(a=a|x.wholeStyle),e%2===1&&(a=a|(r?x.secondRowStyle:x.firstRowStyle)),e%2===0&&(a=a|(r?x.firstRowStyle:x.secondRowStyle)),e===0&&(a=a|x.headerRowStyle),t===0&&(a=a|x.headerColumnStyle),t%2===1&&(a=a|x.firstColumnStyle),t%2===0&&(a=a|x.secondColumnStyle),a===0?null:this._getMergeStyle(a)}_getMergeStyle(e){let t=this._mergeCacheMap.get(e);return t||(t=this._mergeStyle(e),this._mergeCacheMap.set(e,t)),t}_mergeStyle(e){const t=[];return this.wholeStyle&&e&x.wholeStyle&&t.push(this.wholeStyle),this.firstColumnStyle&&e&x.firstColumnStyle&&t.push(this.firstColumnStyle),this.secondColumnStyle&&e&x.secondColumnStyle&&t.push(this.secondColumnStyle),this.firstRowStyle&&e&x.firstRowStyle&&t.push(this.firstRowStyle),this.secondRowStyle&&e&x.secondRowStyle&&t.push(this.secondRowStyle),this.headerColumnStyle&&e&x.headerColumnStyle&&t.push(this.headerColumnStyle),this.lastColumnStyle&&e&x.lastColumnStyle&&t.push(this.lastColumnStyle),this.headerRowStyle&&e&x.headerRowStyle&&t.push(this.headerRowStyle),this.lastRowStyle&&e&x.lastRowStyle&&t.push(this.lastRowStyle),qi(t)}_resetStyleCache(){this._mergeCacheMap.clear()}toJson(){const e={name:this._name};return this.wholeStyle&&(e.wholeStyle=Z(this.wholeStyle)),this.headerRowStyle&&(e.headerRowStyle=Z(this.headerRowStyle)),this.headerColumnStyle&&(e.headerColumnStyle=Z(this.headerColumnStyle)),this.firstRowStyle&&(e.firstRowStyle=Z(this.firstRowStyle)),this.secondRowStyle&&(e.secondRowStyle=Z(this.secondRowStyle)),this.lastRowStyle&&(e.lastRowStyle=Z(this.lastRowStyle)),this.firstColumnStyle&&(e.firstColumnStyle=Z(this.firstColumnStyle)),this.secondColumnStyle&&(e.secondColumnStyle=Z(this.secondColumnStyle)),this.lastColumnStyle&&(e.lastColumnStyle=Z(this.lastColumnStyle)),e}fromJson(e){this._name=e.name,e.wholeStyle&&(this.wholeStyle=Z(e.wholeStyle)),e.headerRowStyle&&(this.headerRowStyle=Z(e.headerRowStyle)),e.headerColumnStyle&&(this.headerColumnStyle=Z(e.headerColumnStyle)),e.firstRowStyle&&(this.firstRowStyle=Z(e.firstRowStyle)),e.secondRowStyle&&(this.secondRowStyle=Z(e.secondRowStyle)),e.lastRowStyle&&(this.lastRowStyle=Z(e.lastRowStyle)),e.firstColumnStyle&&(this.firstColumnStyle=Z(e.firstColumnStyle)),e.secondColumnStyle&&(this.secondColumnStyle=Z(e.secondColumnStyle)),e.lastColumnStyle&&(this.lastColumnStyle=Z(e.lastColumnStyle))}dispose(){this._mergeCacheMap.clear()}}const Yi=(s,e,t)=>new We(`light-${s}`,{headerRowStyle:{bg:{rgb:e}},firstColumnStyle:{bg:{rgb:"rgb(255, 255, 255)"}},secondColumnStyle:{bg:{rgb:t}},lastRowStyle:{bg:{rgb:e}}}),Ki=(s,e,t)=>new We(`middle-${s}`,{headerRowStyle:{bg:{rgb:e}},headerColumnStyle:{bg:{rgb:t}},secondRowStyle:{bg:{rgb:t}},lastRowStyle:{bg:{rgb:e}},lastColumnStyle:{bg:{rgb:t}}}),Ji=(s,e,t,n)=>new We(`dark-${s}`,{headerRowStyle:{bg:{rgb:e},cl:{rgb:"rgb(255, 255, 255)"},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE},firstRowStyle:{bg:{rgb:t}},secondRowStyle:{bg:{rgb:n}},lastRowStyle:{bg:{rgb:e}}}),xi=[{baseName:"blue",header:"rgb(164, 202, 254)",color:"rgb(225, 239, 254)"},{baseName:"grey",header:"rgb(205, 208, 216)",color:"rgb(238, 239, 241)"},{baseName:"red",header:"rgb(248, 180, 180)",color:"rgb(253, 232, 232)"},{baseName:"orange",header:"rgb(253, 186, 140)",color:"rgb(254, 236, 220)"},{baseName:"yellow",header:"rgb(250, 200, 21)",color:"rgb(255, 244, 185)"},{baseName:"green",header:"rgb(132, 225, 188)",color:"rgb(222, 247, 236)"},{baseName:"azure",header:"rgb(126, 220, 226)",color:"rgb(213, 245, 246)"},{baseName:"indigo",header:"rgb(186, 198, 248)",color:"rgb(233, 237, 255)"},{baseName:"purple",header:"rgb(202, 191, 253)",color:"rgb(237, 235, 254)"},{baseName:"magenta",header:"rgb(248, 180, 217)",color:"rgb(252, 232, 243)"}],Xi=[{baseName:"blue",rowHeader:"rgb(63, 131, 248)",colHeader:"rgb(195, 221, 253)"},{baseName:"grey",rowHeader:"rgb(95, 101, 116)",colHeader:"rgb(227, 229, 234)"},{baseName:"red",rowHeader:"rgb(240, 82, 82)",colHeader:"rgb(251, 213, 213)"},{baseName:"orange",rowHeader:"rgb(255, 90, 31)",colHeader:"rgb(252, 217, 189)"},{baseName:"yellow",rowHeader:"rgb(212, 157, 15)",colHeader:"rgb(252, 220, 106)"},{baseName:"green",rowHeader:"rgb(13, 164, 113)",colHeader:"rgb(188, 240, 218)"},{baseName:"azure",rowHeader:"rgb(6, 148, 162)",colHeader:"rgb(175, 236, 239)"},{baseName:"indigo",rowHeader:"rgb(70, 106, 247)",colHeader:"rgb(210, 218, 250)"},{baseName:"purple",rowHeader:"rgb(144, 97, 249)",colHeader:"rgb(220, 215, 254)"},{baseName:"magenta",rowHeader:"rgb(231, 70, 148)",colHeader:"rgb(250, 209, 232)"}],Zi=[{baseName:"blue",rowHeader:"rgb(30, 66, 159)",firstRow:"rgb(195, 221, 253)",secondRow:"rgb(118, 169, 250)"},{baseName:"grey",rowHeader:"rgb(44, 48, 64)",firstRow:"rgb(227, 229, 234)",secondRow:"rgb(151, 157, 172)"},{baseName:"red",rowHeader:"rgb(155, 28, 28)",firstRow:"rgb(251, 213, 213)",secondRow:"rgb(249, 128, 128)"},{baseName:"orange",rowHeader:"rgb(180, 52, 3)",firstRow:"rgb(252, 217, 189)",secondRow:"rgb(255, 138, 76)"},{baseName:"yellow",rowHeader:"rgb(154, 109, 21)",firstRow:"rgb(252, 220, 106)",secondRow:"rgb(212, 157, 15)"},{baseName:"green",rowHeader:"rgb(4, 108, 78)",firstRow:"rgb(188, 240, 218)",secondRow:"rgb(49, 196, 141)"},{baseName:"azure",rowHeader:"rgb(3, 102, 114)",firstRow:"rgb(175, 236, 239)",secondRow:"rgb(22, 189, 202)"},{baseName:"indigo",rowHeader:"rgb(16, 51, 191)",firstRow:"rgb(210, 218, 250)",secondRow:"rgb(98, 128, 249)"},{baseName:"purple",rowHeader:"rgb(74, 29, 150)",firstRow:"rgb(220, 215, 254)",secondRow:"rgb(172, 148, 250)"},{baseName:"magenta",rowHeader:"rgb(153, 21, 75)",firstRow:"rgb(250, 209, 232)",secondRow:"rgb(241, 126, 184)"}],Qi=xi.map(({baseName:s,header:e,color:t})=>Yi(s,e,t)),ea=Xi.map(({baseName:s,rowHeader:e,colHeader:t})=>Ki(s,e,t)),ta=Zi.map(({baseName:s,rowHeader:e,firstRow:t,secondRow:n})=>Ji(s,e,t,n)),na=[...Qi,...ea,...ta],ro={headerRowStyle:{bg:{rgb:"rgb(68,114,196)"},cl:{rgb:"rgb(255,255,255)"},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE},firstRowStyle:{bg:{rgb:"rgb(217,225,242)"}}},sa=new We("default",ro),oa=new We("default-last-row",{...ro,lastRowStyle:{bd:{t:{s:i.BorderStyleTypes.THIN,cl:{rgb:"rgb(68,114,196)"}}},ht:i.HorizontalAlign.CENTER,bl:i.BooleanNumber.TRUE}});class ra{constructor(){f(this,"_toggleRanges",[])}refresh(e,t){const{startRow:n,endRow:o}=e,r=[];let a=0,l=!1,u=-1;for(let d=n;d<=o;d++){if(!t(d)){a++,a%2===1?l=!0:(l=!1,u!==-1&&(r.push([u,d-1]),u=-1));continue}a%2===1?l?u===-1&&(u=d):(l=!0,u=d):l&&(r.push([u,d-2]),l=!1,u=-1),d===o&&l&&r.push([u,d])}this._toggleRanges=r}getToggleRanges(){return this._toggleRanges.concat()}getIsToggled(e){let t=0,n=this._toggleRanges.length-1;for(;t<=n;){const o=Math.floor((t+n)/2),[r,a]=this._toggleRanges[o];if(e<r)n=o-1;else if(e>a)t=o+1;else return!0}return!1}}var ia=Object.getOwnPropertyDescriptor,aa=(s,e,t,n)=>{for(var o=n>1?void 0:n?ia(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ln=(s,e)=>(t,n)=>e(t,n,s);const la="SHEET_RANGE_THEME_MODEL_PLUGIN";g.SheetRangeThemeModel=class extends i.Disposable{constructor(t,n,o){super();f(this,"_rangeThemeStyleMap",new Map);f(this,"_rangeThemeStyleRuleMap",new Map);f(this,"_rTreeCollection",new Map);f(this,"_defaultRangeThemeMap",new Map);f(this,"_zebraCrossingCacheMap",new Map);f(this,"_rowVisibleFuncSet",new Map);f(this,"_rangeThemeMapChanged$",new O.Subject);f(this,"rangeThemeMapChange$",this._rangeThemeMapChanged$.asObservable());this._sheetInterceptorService=t,this._resourceManagerService=n,this._univerInstanceService=o,this._registerIntercept(),this._initSnapshot(),this._initDefaultTheme()}_initDefaultTheme(){this.registerDefaultRangeTheme(sa),this.registerDefaultRangeTheme(oa);for(const t of na)this.registerDefaultRangeTheme(t)}_ensureRangeThemeStyleMap(t){return this._rangeThemeStyleMap.has(t)||this._rangeThemeStyleMap.set(t,new Map),this._rangeThemeStyleMap.get(t)}_ensureRangeThemeStyleRuleMap(t){return this._rangeThemeStyleRuleMap.has(t)||this._rangeThemeStyleRuleMap.set(t,new Map),this._rangeThemeStyleRuleMap.get(t)}_ensureRTreeCollection(t){return this._rTreeCollection.has(t)||this._rTreeCollection.set(t,new i.RTree),this._rTreeCollection.get(t)}getDefaultRangeThemeStyle(t){return this._defaultRangeThemeMap.get(t)}getCustomRangeThemeStyle(t,n){return this._ensureRangeThemeStyleMap(t).get(n)}_getSheetRowVisibleFuncSet(t,n){this._rowVisibleFuncSet.has(t)||this._rowVisibleFuncSet.set(t,new Map);const o=this._rowVisibleFuncSet.get(t);return o.has(n)||o.set(n,new Set),o.get(n)}_getSheetRowVisibleHasInit(t,n){var o;return!!(this._rowVisibleFuncSet.has(t)&&((o=this._rowVisibleFuncSet.get(t))!=null&&o.has(n)))}refreshSheetRowVisibleFuncSet(t,n){const o=this._getSheetRowVisibleFuncSet(t,n);o.clear();const r=this._univerInstanceService.getUnit(t);if(r){const a=r.getSheetBySheetId(n);if(a){const l=a.getRowCount(),u=a.getRowManager();for(let d=1;d<=l;d++)a.getRowVisible(d)?u.getRowHeight(d)===0&&o.add(d):o.add(d)}}}_ensureZebraCrossingCache(t,n,o){this._zebraCrossingCacheMap.has(t)||this._zebraCrossingCacheMap.set(t,new Map);const r=this._zebraCrossingCacheMap.get(t);r.has(n)||r.set(n,new Map);const a=r.get(n);return a.has(o)||a.set(o,new ra),a.get(o)}registerRangeThemeRule(t,n){const{unitId:o,subUnitId:r,range:a}=n,l=i.generateRandomId(),u=this._ensureRangeThemeStyleRuleMap(o),d=this._ensureRTreeCollection(o);u.set(l,{rangeInfo:n,themeName:t}),d.insert({unitId:o,sheetId:r,range:a,id:l}),this._getSheetRowVisibleHasInit(o,r)||this.refreshSheetRowVisibleFuncSet(o,r);const c=this._ensureZebraCrossingCache(o,r,l),m=this._getSheetRowVisibleFuncSet(o,r);c.refresh(a,h=>!m.has(h))}getRegisteredRangeThemeStyle(t){const{unitId:n,subUnitId:o,range:r}=t,a=this._ensureRTreeCollection(n),l=Array.from(a.bulkSearch([{unitId:n,sheetId:o,range:r}]));if(l[0]){const d=this._ensureRangeThemeStyleRuleMap(n).get(l[0]);if(d)return d.themeName}}refreshZebraCrossingCacheBySheet(t,n){this._zebraCrossingCacheMap.has(t)||this._zebraCrossingCacheMap.set(t,new Map);const o=this._zebraCrossingCacheMap.get(t);o.has(n)||o.set(n,new Map);const r=o.get(n);r&&r.forEach((a,l)=>{const d=this._ensureRangeThemeStyleRuleMap(t).get(l);d?a.refresh(d.rangeInfo.range,c=>!this._getSheetRowVisibleFuncSet(t,n).has(c)):r.delete(l)})}removeRangeThemeRule(t,n){const{unitId:o,subUnitId:r,range:a}=n,l=this._ensureRTreeCollection(o),u=Array.from(l.bulkSearch([{unitId:o,sheetId:r,range:a}])),d=this._ensureRangeThemeStyleRuleMap(o);for(let c=0;c<u.length;c++){const m=d.get(u[c]);if(m&&m.themeName===t){d.delete(u[c]),l.remove({unitId:o,sheetId:r,range:a,id:u[c]});const h=this._zebraCrossingCacheMap.get(o);if(h){const R=h.get(r);R&&R.delete(u[c])}break}}}registerDefaultRangeTheme(t){this._defaultRangeThemeMap.set(t.getName(),t),this._rangeThemeMapChanged$.next({type:"add",styleName:t.getName()})}unRegisterDefaultRangeTheme(t){this._defaultRangeThemeMap.delete(t),this._rangeThemeMapChanged$.next({type:"remove",styleName:t})}getRegisteredRangeThemes(){return Array.from(this._defaultRangeThemeMap.keys())}registerRangeThemeStyle(t,n){this._ensureRangeThemeStyleMap(t).set(n.getName(),n),this._rangeThemeMapChanged$.next({type:"add",styleName:n.getName()})}unregisterRangeThemeStyle(t,n){this._ensureRangeThemeStyleMap(t).delete(n),this._rangeThemeMapChanged$.next({type:"remove",styleName:n})}getALLRegisteredTheme(t){return Array.from(this._ensureRangeThemeStyleMap(t).keys())}getRangeThemeStyle(t,n){return this._defaultRangeThemeMap.has(n)?this._defaultRangeThemeMap.get(n):this._ensureRangeThemeStyleMap(t).get(n)}getCellStyle(t,n,o,r){const a={startRow:o,startColumn:r,endRow:o,endColumn:r},l=this._ensureRTreeCollection(t),u=Array.from(l.bulkSearch([{unitId:t,sheetId:n,range:a}]));if(u[0]){const c=this._ensureRangeThemeStyleRuleMap(t).get(u[0]);if(c){const{rangeInfo:m,themeName:h}=c,R=o-m.range.startRow,C=r-m.range.startColumn,S=this.getRangeThemeStyle(t,h),I=this._ensureZebraCrossingCache(t,n,u[0]).getIsToggled(o);if(S)return S.getStyle(R,C,o===m.range.endRow,r===m.range.endColumn,I)}}}_registerIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{id:no,effect:i.InterceptorEffectEnum.Style,handler:(t,n,o)=>{const{row:r,col:a,unitId:l,subUnitId:u}=n,d=this.getCellStyle(l,u,r,a);if(d){const c=!t||t===n.rawData?{...n.rawData}:t;return c.themeStyle=d,o(c)}return o(t)}}))}toJson(t){const n=this._ensureRangeThemeStyleRuleMap(t),o=this._ensureRangeThemeStyleMap(t);if(o.size===0&&n.size===0)return"{}";const r={};n.forEach((l,u)=>{r[u]=l});const a={};return o.forEach((l,u)=>{a[u]=l.toJson()}),JSON.stringify({rangeThemeStyleRuleMap:r,rangeThemeStyleMapJson:a})}fromJSON(t,n){const{rangeThemeStyleRuleMap:o,rangeThemeStyleMapJson:r}=n;o&&Object.keys(o).forEach(a=>{const l=o[a],{themeName:u,rangeInfo:d}=l;u.startsWith("table")||(this.registerRangeThemeRule(u,d),this._ensureRTreeCollection(d.unitId).insert({unitId:a,sheetId:d.subUnitId,range:d.range,id:a}))}),r&&Object.keys(r).forEach(a=>{const l=r[a],u=new We(l.name);u.fromJson(l),this._ensureRangeThemeStyleMap(t).set(u.getName(),u)})}deleteUnitId(t){this._rangeThemeStyleMap.delete(t),this._rangeThemeStyleRuleMap.delete(t),this._rTreeCollection.delete(t)}_initSnapshot(){this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:t=>this.toJson(t),parseJson:t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}},businesses:[i.UniverInstanceType.UNIVER_SHEET],pluginName:la,onLoad:(t,n)=>{this.fromJSON(t,n)},onUnLoad:t=>{this.deleteUnitId(t)}}))}dispose(){super.dispose(),this._rangeThemeStyleMap.clear(),this._rangeThemeStyleRuleMap.clear(),this._defaultRangeThemeMap.clear(),this._rTreeCollection.clear(),this._zebraCrossingCacheMap.clear(),this._rowVisibleFuncSet.clear()}},g.SheetRangeThemeModel=aa([Ln(0,i.Inject(g.SheetInterceptorService)),Ln(1,i.Inject(i.IResourceManagerService)),Ln(2,i.Inject(i.IUniverInstanceService))],g.SheetRangeThemeModel);function Hn(s,e){const{unitId:t}=e,n=t?s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):s.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET);return n?{workbook:n,unitId:n.getUnitId()}:null}function P(s,e={}){const{unitId:t,subUnitId:n}=e,o=t?s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):s.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=n?o.getSheetBySheetId(n):o.getActiveSheet(!0);return r?{worksheet:r,workbook:o,unitId:o.getUnitId(),subUnitId:r.getSheetId()}:null}function Ie(s,e){const{unitId:t,subUnitId:n}=e,o=s.getUnit(t,i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=o.getSheetBySheetId(n);return r?{worksheet:r,workbook:o}:null}const rt={id:"sheet.mutation.set-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,themeName:r}=e,a=s.get(i.IUniverInstanceService),l=P(a),u=s.get(g.SheetRangeThemeModel);return l?(u.registerRangeThemeRule(r,{range:o,unitId:t,subUnitId:n}),!0):!1}},io=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),range:e.range,themeName:e.themeName}},it={id:"sheet.mutation.remove-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,themeName:r}=e,a=s.get(i.IUniverInstanceService),l=P(a),u=s.get(g.SheetRangeThemeModel);return l?(u.removeRangeThemeRule(r,{range:o,unitId:t,subUnitId:n}),!0):!1}},ao=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),range:e.range,themeName:e.themeName}},en=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}},re={id:"sheet.mutation.insert-row",type:i.CommandType.MUTATION,handler:(s,e)=>{var C;const{unitId:t,subUnitId:n,range:o,rowInfo:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(l==null)throw new Error("universheet is null error!");const u=l.getSheetBySheetId(n);if(u==null)throw new Error("worksheet is null error!");const d=u.getRowManager().getRowData(),c={h:u.getConfig().defaultRowHeight,hd:0},m=o.startRow,h=o.endRow-o.startRow+1;for(let S=m;S<m+h;S++)r?i.insertMatrixArray(S,(C=r[S-o.startRow])!=null?C:c,d):i.insertMatrixArray(S,c,d);return u.setRowCount(u.getRowCount()+h),u.getCellMatrix().insertRows(o.startRow,h),!0}},Nt=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}},ie={id:"sheet.mutation.insert-col",type:i.CommandType.MUTATION,handler:(s,e)=>{var C;const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=o.getColumnManager(),{range:a,colInfo:l}=e,d=r.getColumnData(),c=a.startColumn,m=a.endColumn-a.startColumn+1,h=o.getConfig().defaultColumnWidth;for(let S=c;S<c+m;S++){const v={w:h,hd:0};l?i.insertMatrixArray(S,(C=l[S-a.startColumn])!=null?C:v,d):i.insertMatrixArray(S,v,d)}return o.setColumnCount(o.getColumnCount()+a.endColumn-a.startColumn+1),o.getCellMatrix().insertColumns(a.startColumn,m),!0}},Le={id:"sheet.mutation.move-range",type:i.CommandType.MUTATION,handler:(s,e)=>{const{from:t,to:n}=e;if(!t||!n)return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getSheetBySheetId(e.from.subUnitId),l=r.getSheetBySheetId(e.to.subUnitId);if(!a||!l)return!1;const u=a.getCellMatrix(),d=l.getCellMatrix();return new i.ObjectMatrix(t.value).forValue((c,m,h)=>{h==null?u.realDeleteValue(c,m):u.setValue(c,m,h)}),new i.ObjectMatrix(n.value).forValue((c,m,h)=>{h==null?d.realDeleteValue(c,m):d.setValue(c,m,h)}),!0}};function lo(s,e){const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,a=o.startRow>r.startRow,l=o.endRow-o.startRow+1;return a?{unitId:t,subUnitId:n,sourceRange:i.Rectangle.clone(r),targetRange:{...o,endRow:o.endRow+l,startRow:o.startRow+l}}:{unitId:t,subUnitId:n,targetRange:i.Rectangle.clone(o),sourceRange:{...r,endRow:r.endRow-l,startRow:r.startRow-l}}}const pe={id:"sheet.mutation.move-rows",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(!l)throw new Error("[MoveRowMutation] univerSheet is null!");const u=l.getSheetBySheetId(n);if(!u)throw new Error("[MoveRowMutation] worksheet is null!");const d=o.startRow,c=o.endRow-o.startRow+1,m=r.startRow,h=u.getRowManager().getRowData();return i.moveMatrixArray(d,c,m,h),u.getCellMatrix().moveRows(d,c,m),!0}};function uo(s,e){const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,a=o.startColumn>r.startColumn,l=o.endColumn-o.startColumn+1;return a?{unitId:t,subUnitId:n,sourceRange:i.Rectangle.clone(r),targetRange:{...o,endColumn:o.endColumn+l,startColumn:o.startColumn+l}}:{unitId:t,subUnitId:n,targetRange:i.Rectangle.clone(o),sourceRange:{...r,startColumn:r.startColumn-l,endColumn:r.endColumn-l}}}const we={id:"sheet.mutation.move-columns",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,sourceRange:o,targetRange:r}=e,l=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(!l)throw new Error("[MoveColumnMutation] univerSheet is null!");const u=l.getSheetBySheetId(n);if(!u)throw new Error("[MoveColumnMutation] worksheet is null!");const d=o.startColumn,c=o.endColumn-o.startColumn+1,m=r.startColumn,h=u.getColumnManager().getColumnData();return i.moveMatrixArray(d,c,m,h),u.getCellMatrix().moveColumns(d,c,m),!0}},ua=(s,e)=>{const o=e.getRowManager().getRowData(),r={},a=s.range,l=i.sliceMatrixArray(a.startRow,a.endRow,o),u=i.concatMatrixArray(r,l);return{unitId:s.unitId,subUnitId:s.subUnitId,range:s.range,rowInfo:u}},ae={id:"sheet.mutation.remove-rows",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=e.range,l=o.getRowManager().getRowData();for(let c=r.startRow;c<=r.endRow;c++)o.getRowFiltered(c);const u=r.endRow-r.startRow+1;return i.spliceArray(r.startRow,u,l),o.getCellMatrix().removeRows(r.startRow,u),o.setRowCount(o.getRowCount()-u),!0}},da=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const l=o.getColumnManager().getColumnData(),u={},d=e.range,c=i.sliceMatrixArray(d.startColumn,d.endColumn,l),m=i.concatMatrixArray(u,c);return{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,colInfo:m}},ne={id:"sheet.mutation.remove-col",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=e.range,l=o.getColumnManager().getColumnData(),u=r.endColumn-r.startColumn+1;return i.spliceArray(r.startColumn,u,l),o.setColumnCount(o.getColumnCount()-u),o.getCellMatrix().removeColumns(r.startColumn,u),!0}},le=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const a=o.getConfig().mergeData,l=e.ranges,u=[];for(let d=0;d<l.length;d++)for(let c=a.length-1;c>=0;c--){const m=a[c],h=l[d];i.Rectangle.intersects(m,h)&&u.push(a[c])}return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:u}},G={id:"sheet.mutation.remove-worksheet-merge",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const a=o.getConfig().mergeData,l=e.ranges;for(let u=0;u<l.length;u++)for(let d=a.length-1;d>=0;d--){const c=a[d],m=l[u];i.Rectangle.intersects(c,m)&&a.splice(d,1)}return o.getSpanModel().rebuild(a),!0}},co=s=>{const{order:e}=s,t={};return Object.keys(e).forEach(n=>{t[e[Number(n)]]=Number(n)}),{...s,order:t}},Ot={id:"sheet.mutation.reorder-range",type:i.CommandType.MUTATION,handler:(s,e)=>{const{subUnitId:t,unitId:n,range:o,order:r}=e,u=s.get(i.IUniverInstanceService).getUnit(n).getSheetBySheetId(t);if(!u)return!1;const d=new i.ObjectMatrix;i.Range.foreach(o,(m,h)=>{if(r.hasOwnProperty(m)){const R=r[m],C=i.Tools.deepClone(u.getCellRaw(R,h));d.setValue(m,h,C)}});const c=u.getCellMatrix();return d.forValue((m,h,R)=>{c.setValue(m,h,R)}),!0}};function ca(s,e){if(s==null)return s;const t=i.Tools.deepClone(s);if(e==null)return t;const n={};return"h"in e&&(n.h=t.h),"ia"in e&&(n.ia=t.ia),"ah"in e&&(n.ah=t.ah),"hd"in e&&(n.hd=t.hd),"s"in e&&(n.s=t.s),"custom"in e&&(n.custom=t.custom),n}function ma(s,e){if(s==null)return s;const t=i.Tools.deepClone(s);if(e==null)return t;const n={};return"w"in e&&(n.w=t.w),"hd"in e&&(n.hd=t.hd),"s"in e&&(n.s=t.s),"custom"in e&&(n.custom=t.custom),n}const mo=(s,e)=>{const{unitId:t,subUnitId:n,columnData:o}=s,r={},a=e.getColumnManager();for(const l in o){const u=o[l],d=a.getColumn(Number(l));r[l]=ma(d,u)}return{unitId:t,subUnitId:n,columnData:r}},at={id:"sheet.mutation.set-col-data",type:i.CommandType.MUTATION,handler:(s,e)=>{const{columnData:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const{worksheet:r}=o,a=r.getColumnManager();for(const l in t){const u=t[l];if(u==null){a.removeColumn(Number(l));continue}const d=a.getColumnOrCreate(Number(l));Object.assign(d,u)}return!0}},ha=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},lt={id:"sheet.mutation.set-col-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!n)return!1;const o=n.getSheetBySheetId(e.subUnitId).getColumnManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startColumn;l<a.endColumn+1;l++){const u=o.getColumnOrCreate(l);u!=null&&(u.hd=i.BooleanNumber.TRUE)}}return!0}},ga=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},ut={id:"sheet.mutation.set-col-visible",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!n)return!1;const o=n.getSheetBySheetId(e.subUnitId).getColumnManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startColumn;l<a.endColumn+1;l++){const u=o.getColumnOrCreate(l);u!=null&&(u.hd=i.BooleanNumber.FALSE)}}return!0}},dt={id:"sheet.mutation.set-gridlines-color",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=P(s.get(i.IUniverInstanceService),e);if(!t)return!1;const{worksheet:n}=t,o=n.getConfig();return o.gridlinesColor=e.color,!0}};function Ra(s,e,t){var a;const n=s.getStyleByCell(e);n==null&&delete e.s,typeof t.s=="string"&&(t.s=s.get(t.s));const o=tn(n,t.s?t.s:null);o&&(i.Tools.removeNull(o),Object.entries(o).forEach(([l,u])=>{typeof u=="object"&&u!==null&&Object.keys(u).length===0&&delete o[l]})),i.Tools.isEmptyObject(o)?delete e.s:e.s=s.setValue(o);const r=t.v?`${t.v}\r
|
|
2
2
|
`:"";!t.p&&e.p&&(r&&r!==((a=e.p.body)==null?void 0:a.dataStream)?delete e.p:fa(e.p,t.s?t.s:null))}function Ca(s,e){if(!e||!Object.keys(e).length)return s;const t=i.Tools.deepClone(s!=null?s:{});for(const n in e)n==="bd"?t[n]=Sa(t[n]||{},e[n]):n in t||(t[n]=null);return t}function Sa(s,e){if(!e||!Object.keys(e).length)return s;for(const t in e)t in s||(s[t]=null);return s}function tn(s,e,t=!1){if(e===null)return e;if(e===void 0)return s;const n=i.Tools.deepClone(s)||{};for(const o in e)t&&["bd","tr","td","ht","vt","tb","pd","bg"].includes(o)||(o in n&&o==="bd"?n[o]=Object.assign(n[o],e[o]):n[o]=e[o]);return"cl"in n&&("ul"in n&&n.ul&&(n.ul.cl=n.cl),"ol"in n&&n.ol&&(n.ol.cl=n.cl),"st"in n&&n.st&&(n.st.cl=n.cl)),n}function ho(s,e){return s.some(t=>t.startIndex===e)?ho(s,e+1):e}function fa(s,e){var a;if(s.body==null)return;Array.isArray(s.body.textRuns)||(s.body.textRuns=[]);let t=0;const n=[],o=((a=s.body)==null?void 0:a.paragraphs)||[];for(const l of s.body.textRuns){const{st:u,ed:d,ts:c={}}=l;if(t<u){const h={st:t,ed:u},R=tn({},e,!0);R&&i.Tools.removeNull(R),i.Tools.isEmptyObject(R)||(h.ts=R),n.push(h)}const m=tn(c,e,!0);m&&i.Tools.removeNull(m),i.Tools.isEmptyObject(m)?delete l.ts:l.ts=m,n.push(l),t=ho(o,d)}const r=s.body.dataStream.endsWith(`\r
|
|
3
|
-
`)?s.body.dataStream.length-2:s.body.dataStream.length;if(t<r){const l={st:t,ed:r},u=tn({},e,!0);u&&i.Tools.removeNull(u),i.Tools.isEmptyObject(u)||(l.ts=u),n.push(l)}s.body.textRuns=i.normalizeTextRuns(n)}function go(s,e){return e.v===void 0||e.v===null?e.v:s===i.CellValueType.NUMBER?Number(e.v):s===i.CellValueType.BOOLEAN?va(e.v)?1:0:s===i.CellValueType.STRING||s===i.CellValueType.FORCE_STRING?`${e.v}`:e.v}function va(s){if(typeof s=="string"){if(s.toUpperCase()==="TRUE")return!0;if(s.toUpperCase()==="FALSE")return!1;if(i.isSafeNumeric(s)){if(Number(s)===0)return!1;if(Number(s)===1)return!0}}if(typeof s=="number"){if(s===0)return!1;if(s===1)return!0}return typeof s=="boolean"?s:null}function Ia(s){return s==null?null:(s.f===void 0&&(s.f=null),s.si===void 0&&(s.si=null),s.p===void 0&&(s.p=null),s.v===void 0&&(s.v=null),s.t===void 0&&(s.t=null),s.s===void 0&&(s.s=null),s.custom===void 0&&(s.custom=null),s)}const ce=(s,e)=>{const{unitId:t,subUnitId:n,cellValue:o}=e,a=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(a==null)throw new Error("workbook is null error!");const l=a.getSheetBySheetId(n);if(l==null)throw new Error("worksheet is null error!");const u=l.getCellMatrix(),d=a.getStyles(),c=new i.ObjectMatrix;return new i.ObjectMatrix(o).forValue((h,R,C)=>{const S=i.Tools.deepClone(u==null?void 0:u.getValue(h,R))||{},v=d.getStyleByCell(S),I=d.getStyleByCell(C);S.s=Ca(v,I),c.setValue(h,R,Ia(S))}),{...e,options:{},cellValue:c.getMatrix()}},F={id:"sheet.mutation.set-range-values",type:i.CommandType.MUTATION,handler:(s,e)=>{const{cellValue:t,subUnitId:n,unitId:o}=e,a=s.get(i.IUniverInstanceService).getUnit(o);if(!a)return!1;const l=a.getSheetBySheetId(n);if(!l)return!1;const u=l.getCellMatrix(),d=a.getStyles();return new i.ObjectMatrix(t).forValue((m,h,R)=>{if(!R)u.realDeleteValue(m,h);else{let C=u.getValue(m,h)||{};C=wa(R,C,d),i.Tools.isEmptyObject(C)?u.realDeleteValue(m,h):u.setValue(m,h,C)}}),!0}},pa=new Set(["f","p","si","custom","ref"]);function wa(s,e,t){const n=Li(t,s,e);return Object.keys(s).forEach(o=>{const r=o;if(pa.has(r)){const a=s[r];Ma(e,r,a)}else r==="v"?s.v!==void 0&&(e.v=go(n,s)):r==="s"&&Ra(t,e,s)}),e.v!==void 0&&(e.t=n,e.v=go(n,e)),e.v===null&&(delete e.t,delete e.v),e}function Ma(s,e,t){t===void 0||(t===null?delete s[e]:s[e]=t)}const Ro=(s,e)=>{const{unitId:t,subUnitId:n,rowData:o}=s,r={},a=e.getRowManager();for(const l in o){const u=o[l],d=a.getRow(Number(l));r[l]=ca(d,u)}return{unitId:t,subUnitId:n,rowData:r}},ct={id:"sheet.mutation.set-row-data",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rowData:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const{worksheet:r}=o,a=r.getRowManager();for(const l in t){const u=t[l];if(u==null){a.removeRow(Number(l));continue}const d=a.getRowOrCreate(Number(l));Object.assign(d,u)}return!0}},ya=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},Ye={id:"sheet.mutation.set-row-visible",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId).getRowManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startRow;l<a.endRow+1;l++){const u=o.getRowOrCreate(l);u!=null&&(u.hd=0)}}return!0}},_a=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},Ke={id:"sheet.mutation.set-row-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId).getRowManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startRow;l<a.endRow+1;l++){const u=o.getRowOrCreate(l);u!=null&&(u.hd=1)}}return!0}},Bn=(s,e)=>{const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getColumnManager();for(let l=0;l<o.length;l++){const u=o[l];for(let d=u.startColumn;d<u.endColumn+1;d++)r[d]=a.getColumnWidth(d)}return{unitId:t,subUnitId:n,ranges:o,colWidth:r}},Ve={id:"sheet.mutation.set-worksheet-col-width",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{worksheet:o}=n,r=o.getColumnManager(),a=e.ranges;for(let l=0;l<a.length;l++){const u=a[l];for(let d=u.startColumn;d<u.endColumn+1;d++)o.getColVisible(d)&&(typeof e.colWidth=="number"?r.setColumnWidth(d,e.colWidth):i.Tools.isDefine(e.colWidth[d])&&r.setColumnWidth(d,e.colWidth[d]))}return!0}},Co=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetColumnCountUndoMutationFactory]: worksheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,columnCount:t.worksheet.getColumnCount()}},mt={id:"sheet.mutation.set-worksheet-column-count",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=Ie(t,e);return n?(n.worksheet.setColumnCount(e.columnCount),!0):!1}},ht={id:"sheet.mutation.set-worksheet-default-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{defaultStyle:t}=e,n=s.get(i.IUniverInstanceService),o=P(n);if(!o)return!1;const{worksheet:r}=o;return r?(r.setDefaultCellStyle(t),!0):!1}},So=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),defaultStyle:n.getDefaultCellStyle()}},fo=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetRowCountUndoMutationFactory]: worksheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,rowCount:t.worksheet.getRowCount()}},gt={id:"sheet.mutation.set-worksheet-row-count",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=Ie(t,e);return n?(n.worksheet.setRowCount(e.rowCount),!0):!1}},vo=(s,e)=>{var l,u;const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getRowManager();for(const{startRow:d,endRow:c}of o)for(let m=d;m<c+1;m++)r[m]=(u=(l=a.getRow(m))==null?void 0:l.h)!=null?u:e.getConfig().defaultRowHeight;return{unitId:t,subUnitId:n,ranges:o,rowHeight:r}},Fn=(s,e)=>{var l;const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getRowManager();for(const{startRow:u,endRow:d}of o)for(let c=u;c<=d;c++)r[c]=(l=a.getRow(c))==null?void 0:l.ia;return{unitId:t,subUnitId:n,ranges:o,autoHeightInfo:r}},ba=(s,e)=>{var l,u;const{unitId:t,subUnitId:n,rowsAutoHeightInfo:o}=s,r=[],a=e.getRowManager();for(const d of o){const{row:c}=d;r.push({row:c,autoHeight:(u=(l=a.getRow(c))==null?void 0:l.ah)!=null?u:e.getConfig().defaultRowHeight})}return{unitId:t,subUnitId:n,rowsAutoHeightInfo:r}},Ee={id:"sheet.mutation.set-worksheet-row-height",type:i.CommandType.MUTATION,handler:(s,e)=>{const{ranges:t,rowHeight:n}=e,o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{worksheet:a}=r,l=a.getRowManager();for(const{startRow:u,endRow:d}of t)for(let c=u;c<=d;c++)typeof n=="number"?l.setRowHeight(c,n):i.Tools.isDefine(n[c])&&l.setRowHeight(c,n[c]);return!0}},Re={id:"sheet.mutation.set-worksheet-row-is-auto-height",type:i.CommandType.MUTATION,handler:(s,e)=>{var l;const{ranges:t,autoHeightInfo:n}=e,o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const a=r.worksheet.getRowManager();for(const{startRow:u,endRow:d}of t)for(let c=u;c<=d;c++){const m=a.getRowOrCreate(c);typeof n=="number"?m.ia=n:m.ia=(l=n[c])!=null?l:void 0}return!0}},jn={id:"sheet.mutation.set-worksheet-row-auto-height",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rowsAutoHeightInfo:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const r=o.worksheet.getRowManager();for(const{row:a,autoHeight:l}of t){const u=r.getRowOrCreate(a);u.ah=l}return!0}},Rt={id:"sheet.mutation.toggle-gridlines",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=P(s.get(i.IUniverInstanceService),e);if(!t)return!1;const{worksheet:n}=t,o=n.getConfig();return o.showGridlines=e.showGridlines,!0}},Ct={id:"sheet.operation.set-worksheet-active",type:i.CommandType.OPERATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getWorksheets();for(const[,o]of n)if(o.getSheetId()===e.subUnitId)return t.setActiveSheet(o),!0;return!1}};var Io=(s=>(s.SET_WORKSHEET_ROW_HEIGHT="sheet.mutation.set-worksheet-row-height",s.SET_WORKSHEET_ROW_IS_AUTO_HEIGHT="sheet.mutation.set-worksheet-row-is-auto-height",s.SET_WORKSHEET_ROW_AUTO_HEIGHT="sheet.mutation.set-worksheet-row-auto-height",s.SET_WORKSHEET_COL_WIDTH="sheet.mutation.set-worksheet-col-width",s.SET_WORKSHEET_ACTIVE="sheet.operation.set-worksheet-active",s.MOVE_ROWS="sheet.mutation.move-rows",s.MOVE_COLUMNS="sheet.mutation.move-columns",s.SET_COL_HIDDEN="sheet.mutation.set-col-hidden",s.SET_COL_VISIBLE="sheet.mutation.set-col-visible",s.SET_ROW_HIDDEN="sheet.mutation.set-row-hidden",s.SET_ROW_VISIBLE="sheet.mutation.set-row-visible",s.INSERT_COL="sheet.mutation.insert-col",s.INSERT_ROW="sheet.mutation.insert-row",s.REMOVE_COL="sheet.mutation.remove-col",s.REMOVE_ROW="sheet.mutation.remove-rows",s.TOGGLE_GRIDLINES="sheet.mutation.toggle-gridlines",s.SET_GRIDLINES_COLOR="sheet.mutation.set-gridlines-color",s))(Io||{}),po=(s=>(s.SET_RANGE_VALUES="sheet.mutation.set-range-values",s.MOVE_RANGE="sheet.mutation.move-range",s.REMOVE_WORKSHEET_MERGE="sheet.mutation.remove-worksheet-merge",s.ADD_WORKSHEET_MERGE="sheet.mutation.add-worksheet-merge",s.REORDER_RANGE="sheet.mutation.reorder-range",s.SET_WORKSHEET_DEFAULT_STYLE="sheet.mutation.set-worksheet-default-style",s.SET_ROW_DATA="sheet.mutation.set-row-data",s.SET_COL_DATA="sheet.mutation.set-col-data",s.SET_WORKSHEET_RANGE_THEME_STYLE="sheet.mutation.set-worksheet-range-theme-style",s.DELETE_WORKSHEET_RANGE_THEME_STYLE="sheet.mutation.delete-worksheet-range-theme-style",s))(po||{});const Ea=[Ee.id,Re.id,jn.id,Ve.id,Ct.id,pe.id,we.id,lt.id,ut.id,Ke.id,Ye.id,ie.id,re.id,ne.id,ae.id,Rt.id,dt.id,gt.id,mt.id],Ta=[F.id,Le.id,G.id,j.id,Dt.id,ht.id,ct.id,at.id,rt.id,it.id];function Ua(s){switch(s.id){case"sheet.mutation.set-range-values":{const e=s.params,t=new i.ObjectMatrix(e.cellValue).getDataRange();return t.endRow===-1?[]:e.cellValue?[{unitId:e.unitId,subUnitId:e.subUnitId,range:t}]:[]}case"sheet.mutation.move-range":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.from.subUnitId,range:new i.ObjectMatrix(e.from.value).getRange()},{unitId:e.unitId,subUnitId:e.to.subUnitId,range:new i.ObjectMatrix(e.to.value).getRange()}]}case"sheet.mutation.remove-worksheet-merge":{const e=s.params;return e.ranges.map(t=>({unitId:e.unitId,subUnitId:e.subUnitId,range:t}))}case"sheet.mutation.add-worksheet-merge":{const e=s.params;return e.ranges.map(t=>({unitId:e.unitId,subUnitId:e.subUnitId,range:t}))}case"sheet.mutation.reorder-range":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}]}case"sheet.mutation.set-worksheet-default-style":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:0,endRow:Number.MAX_SAFE_INTEGER,startColumn:0,endColumn:Number.MAX_SAFE_INTEGER}}]}case"sheet.mutation.set-row-data":{const e=s.params,t=Object.keys(e.rowData).map(Number);return t.length===0?[]:[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:Math.min(...t),endRow:Math.max(...t),startColumn:0,endColumn:Number.MAX_SAFE_INTEGER}}]}case"sheet.mutation.set-col-data":{const e=s.params,t=Object.keys(e.columnData).map(Number);return t.length===0?[]:[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:0,endRow:Number.MAX_SAFE_INTEGER,startColumn:Math.min(...t),endColumn:Math.max(...t)}}]}case"sheet.mutation.set-worksheet-range-theme-style":case"sheet.mutation.delete-worksheet-range-theme-style":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}]}default:return[]}}function Pa(s,e){switch(s.id){case"sheet.mutation.set-worksheet-row-height":case"sheet.mutation.set-worksheet-row-is-auto-height":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.set-worksheet-row-auto-height":{const t=s.params;return t.rowsAutoHeightInfo.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{startRow:n.row,endRow:n.row,startColumn:0,endColumn:e-1,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.set-worksheet-col-width":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.COLUMN}}))}case"sheet.mutation.move-rows":case"sheet.mutation.move-columns":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:t.targetRange},{unitId:t.unitId,subUnitId:t.subUnitId,range:t.sourceRange}]}case"sheet.mutation.set-col-hidden":case"sheet.mutation.set-col-visible":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.COLUMN}}))}case"sheet.mutation.set-row-hidden":case"sheet.mutation.set-row-visible":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.insert-col":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.COLUMN}}]}case"sheet.mutation.insert-row":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.ROW}}]}case"sheet.mutation.remove-col":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.COLUMN}}]}case"sheet.mutation.remove-rows":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.ROW}}]}case"sheet.mutation.toggle-gridlines":case"sheet.mutation.set-gridlines-color":return[];default:return[]}}function wo(s){return s==null?!1:s.v!==void 0&&s.v!==null&&s.v!==""||s.p!==void 0}function nn(s,e){return s&&s.spanAnchor?wo(e.getValue(s.spanAnchor.startRow,s.spanAnchor.startColumn)):wo(s)}function ka(s,e,t,n,o){const r=s.getCellMatrix(),a=s.getSpanModel().getMergedCellRange(e,t,n,o),l=new i.ObjectMatrix;return r.forValue((u,d)=>{const c=r.getValue(u,d);c&&l.setValue(u,d,c)}),a.forEach(u=>{const{startColumn:d,startRow:c,endColumn:m,endRow:h}=u;i.createRowColIter(c,h,d,m).forEach((R,C)=>{R===c&&C===d&&l.setValue(R,C,{...r.getValue(R,C),spanAnchor:{startRow:c,endRow:h,startColumn:d,endColumn:m}}),(R!==c||C!==d)&&(l.realDeleteValue(R,C),l.setValue(R,C,{spanAnchor:{startRow:c,endRow:h,startColumn:d,endColumn:m}}))})}),l}function Oa(s,e,t,n){const{startRow:o,startColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=a;d++){const c=e.getValue(d,r-t);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.startColumn=s.startColumn-t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Da(s,e,t,n){const{startRow:o,endColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=a;d++){const c=e.getValue(d,r+t);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.endColumn=s.endColumn+t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Na(s,e,t,n){const{startRow:o,startColumn:r,endColumn:a}=s;let l=null,u=!1;for(let d=r;d<=a;d++){const c=e.getValue(o-t,d);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.startRow=s.startRow-t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Aa(s,e,t,n){const{startColumn:o,endColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=r;d++){const c=e.getValue(a+t,d);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.endRow=s.endRow+t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Wa(s,e,t){const n=t.getMaxRows(),o=t.getMaxColumns(),r=ka(t,0,0,n-1,o-1),a=t.getSnapshot().mergeData.length>0,{left:l,right:u,up:d,down:c}=e;let m=!0,h={...s};const R=[];for(;m;){if(m=!1,d&&h.startRow!==0){const{hasValue:C,range:S,spanAnchor:v}=Na(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(c&&h.endRow!==n-1){const{hasValue:C,range:S,spanAnchor:v}=Aa(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(l&&h.startColumn!==0){const{hasValue:C,range:S,spanAnchor:v}=Oa(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(u&&h.endColumn!==o-1){const{hasValue:C,range:S,spanAnchor:v}=Da(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}}return R.length>0&&(h=i.Rectangle.union(h,...R)),h}const Mo=s=>{const e=new i.ObjectMatrix;return s.forEach(t=>{i.Range.foreach(t,(n,o)=>{e.setValue(n,o,1)})}),e.forValue((t,n)=>{const o=e.getValue(t-1,n);o&&e.setValue(t,n,o+1)}),e},yo=s=>{const e=s;return e.forValue((t,n)=>{const o=s.getValue(t-1,n);o&&e.setValue(t,n,o+1)}),e},_o=s=>{const e={area:0},t=(n,o)=>e.area<n?(e.area=n,e.range=o,!0):!1;return s.forValue((n,o,r)=>{let a=1,l=r;t(a*l,{startRow:n-l+1,endRow:n,startColumn:o,endColumn:o});const u={startRow:n-l+1,endRow:n,startColumn:0,endColumn:o};for(let d=o-1;d>=0&&s.getValue(n,d);d--){l=Math.min(s.getValue(n,d)||0,l),a++;const c=l*a;u.startColumn=d,u.startRow=n-l+1,t(c,u)}}),e},Va=(s,e)=>{i.Range.foreach(e,(t,n)=>{s.realDeleteValue(t,n)});for(let t=e.startColumn;t<=e.endColumn;t++){const n=e.endRow+1;if(s.getValue(n,t)>0){s.setValue(n,t,1);let r=n+1;for(;s.getValue(r,t)>0;)s.setValue(r,t,s.getValue(r-1,t)+1),r++}}return s},Gn=s=>{const e=[];let t=_o(s);for(;t.area>0;)t.range&&(e.push(t.range),Va(s,t.range)),t=_o(s);return e},zn=s=>{const e=Mo(s);return Gn(e)};class $a{constructor(){f(this,"_matrix",new i.ObjectMatrix)}add(...e){return e.forEach(t=>{i.Range.foreach(t,(n,o)=>{this._matrix.setValue(n,o,1)})}),this}subtract(...e){return e.forEach(t=>{i.Range.foreach(t,(n,o)=>{this._matrix.realDeleteValue(n,o)})}),this}merge(){const e=yo(this._matrix);return Gn(e)}}const La=1.5,Ha="rgba(255, 255, 255, 0.01)";function Ba(s){const{rangeWithCoord:e,primaryWithCoord:t,style:n}=s,o={range:{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,rangeType:e.rangeType,unitId:e.unitId,sheetId:e.sheetId},primary:null,style:n};return t!=null&&(o.primary=bo(t)),o}function bo(s){const{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:o}=s,{startRow:r,startColumn:a,endRow:l,endColumn:u}=s.mergeInfo;return{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:o,startRow:r,startColumn:a,endRow:l,endColumn:u}}var Eo=(s=>(s[s.Tab=1]="Tab",s[s.Comma=2]="Comma",s[s.Semicolon=4]="Semicolon",s[s.Space=8]="Space",s[s.Custom=16]="Custom",s))(Eo||{});class Fa{constructor(){f(this,"_tabCount",0);f(this,"_commaCount",0);f(this,"_semicolonCount",0);f(this,"_spaceCount",0)}add(e){switch(e){case" ":this._tabCount++;break;case",":this._commaCount++;break;case";":this._semicolonCount++;break;case" ":this._spaceCount++;break}}update(e){e&&typeof e=="string"&&(e.includes(" ")&&this._tabCount++,e.includes(",")&&this._commaCount++,e.includes(";")&&this._semicolonCount++,e.trim().includes(" ")&&this._spaceCount++)}getDelimiter(){const e=Math.max(this._tabCount,this._commaCount,this._semicolonCount,this._spaceCount);return e===0||e===this._tabCount?1:e===this._commaCount?2:e===this._semicolonCount?4:e===this._spaceCount?8:1}}function ja(s,e,t){const n=[];t!==void 0&&(s&16)>0&&n.push(t),(s&1)>0&&n.push(" "),(s&2)>0&&n.push(","),(s&4)>0&&n.push(";"),(s&8)>0&&n.push(" ");let o="";for(const a of n)o+=Ga(a);let r="[".concat(o,"]");return e&&(r+="+"),new RegExp(r)}function Ga(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const za=s=>{var t;return((t=s.body)==null?void 0:t.dataStream.replace(/\r\n$/,""))||""};function qa(s){if(s!=null){if(s.p)return za(s.p);if(s.v&&typeof s.v=="string")return s.v;if(s.t&&(s.t===i.CellValueType.FORCE_STRING||s.t===i.CellValueType.STRING))return String(s.v)}}function To(s,e,t,n,o=!1){const r=i.Range.transformRange(e,s),{startColumn:a,startRow:l,endColumn:u,endRow:d}=r;if(a!==u)throw new Error("The range must be in the same column.");if(t&&(t&16)>0&&(n===void 0||n.length!==1))throw new Error("The custom delimiter must a character.");const c=t===void 0,m=c?new Fa:null,h=[];for(let p=l;p<=d;p++){const w=s.getCell(p,a),y=qa(w);h.push(y),m&&m.update(y)}const R=c?m.getDelimiter():t,C=ja(R,o,n);let S=-1,v=0,I=0;const M=[];for(const p of h){if(p!==void 0){const w=String(p).split(C);S<0?S=w.length:S=Math.max(S,w.length),M.push(w),v=I}else M.push(void 0);I++}return{rs:M,maxLength:S===-1?0:S,lastRow:v}}const Ya=(s,e,t="")=>s.reduce((n,o)=>{const r=o&&o[e];return typeof r!="string"?(console.warn(o,`${e} is not string`),n):(r?(n[r]||(n[r]=[]),n[r].push(o)):n[t].push(o),n)},{}),Ka=(s=0)=>{let e=s;return function(){return e++}};function Ja(s){return s==null?!1:s.v!==void 0&&s.v!==null&&s.v!==""||s.p!==void 0}function xa(s,e){for(let t=s.startRow;t<=s.endRow;t++)for(let n=s.startColumn;n<=s.endColumn;n++){const o=e.getCell(t,n);if(Ja(o))return{startRow:t,startColumn:n,endRow:t,endColumn:n}}return null}function qn(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,null)}),e.clone()}function Uo(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,{v:null,p:null,f:null,si:null,custom:null})}),e.clone()}function Xa(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,{s:null})}),e.clone()}function Po(s,e,t,n){const o=e.get(i.IUniverInstanceService),r=t?o.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):o.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),a=n?r==null?void 0:r.getSheetBySheetId(n):r==null?void 0:r.getActiveSheet();if(!a)return null;const{startRow:l,endRow:u,startColumn:d,endColumn:c}=s,m=[],h=[];for(let R=l;R<=u;R++)a.getRowFiltered(R)||m.push(R);for(let R=d;R<=c;R++)h.push(R);return{rows:m,cols:h}}function Nt(s,e,t,n){const o=[],r=[];for(const h of s){const R=Po(h,e,t,n);R&&(o.push(...R.rows),r.push(...R.cols))}const a=Array.from(new Set(o)).sort((h,R)=>h-R),l=Array.from(new Set(r)).sort((h,R)=>h-R),u=[];function d(h){const R=[];let C=h[0];for(let S=1;S<h.length;S++)h[S]!==h[S-1]+1&&(R.push([C,h[S-1]]),C=h[S]);return R.push([C,h[h.length-1]]),R}const c=d(a),m=d(l);for(const[h,R]of c)for(const[C,S]of m)u.push({startRow:h,endRow:R,startColumn:C,endColumn:S});return u}var ko=(s=>(s.OthersCanView="othersCanView",s.NoOneElseCanView="noOneElseCanView",s))(ko||{}),Oo=(s=>(s.DesignedUserCanEdit="designedUserCanEdit",s.OnlyMe="onlyMe",s))(Oo||{});class X{constructor(){f(this,"_model",new Map);f(this,"_ruleChange$",new D.Subject);f(this,"ruleChange$",this._ruleChange$.asObservable());f(this,"_ruleRefresh$",new D.Subject);f(this,"ruleRefresh$",this._ruleRefresh$.asObservable());f(this,"_rangeRuleInitStateChange",new D.BehaviorSubject(!1));f(this,"rangeRuleInitStateChange$",this._rangeRuleInitStateChange.asObservable())}dispose(){this._ruleChange$.complete(),this._ruleRefresh$.complete()}ruleRefresh(e){this._ruleRefresh$.next(e)}getRangeRuleInitState(){return this._rangeRuleInitStateChange.value}changeRuleInitState(e){this._rangeRuleInitStateChange.next(e)}addRule(e,t,n){this._ensureRuleMap(e,t).set(n.id,n),this._ruleChange$.next({unitId:e,subUnitId:t,rule:n,type:"add"})}deleteRule(e,t,n){var r,a,l,u;const o=(a=(r=this._model.get(e))==null?void 0:r.get(t))==null?void 0:a.get(n);o&&((u=(l=this._model.get(e))==null?void 0:l.get(t))==null||u.delete(n),this._ruleChange$.next({unitId:e,subUnitId:t,rule:o,type:"delete"}))}setRule(e,t,n,o){var a,l;const r=this.getRule(e,t,n);r&&((l=(a=this._model.get(e))==null?void 0:a.get(t))==null||l.set(n,o),this._ruleChange$.next({unitId:e,subUnitId:t,oldRule:r,rule:o,type:"set"}))}getRule(e,t,n){var o,r;return(r=(o=this._model.get(e))==null?void 0:o.get(t))==null?void 0:r.get(n)}getSubunitRuleList(e,t){var o;return[...(((o=this._model.get(e))==null?void 0:o.get(t))||new Map).values()]}getSubunitRuleListLength(e,t){var o;const n=(o=this._model.get(e))==null?void 0:o.get(t);return n?n.size:0}_ensureRuleMap(e,t){let n=this._model.get(e);n||(n=new Map,this._model.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n),r=[...o.keys()];e[n]={},r.forEach(a=>{const l=o.get(a);e[n][a]=[...l.values()]})}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n],r=new Map;Object.keys(o).forEach(a=>{const l=o[a].reduce((u,d)=>(u.set(d.id,d),u),new Map);r.set(a,l)}),t.set(n,r)}),this._model=t}deleteUnitModel(e){this._model.delete(e)}createRuleId(e,t){let n=i.generateRandomId(4);const o=this._ensureRuleMap(e,t);for(;o.has(n);)n=i.generateRandomId(4);return n}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)for(const a of r.values())if(a.permissionId===t)return[e,o];return null}}const Za=(s,e)=>{const t=s.get(X),n=e.ruleIds.map(r=>t.getRule(e.unitId,e.subUnitId,r)).filter(r=>!!r);return{id:Ce.id,params:{subUnitId:e.subUnitId,unitId:e.unitId,rules:n}}},Te={id:"sheet.mutation.delete-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,ruleIds:o}=e,r=s.get(X);return o.forEach(a=>{r.deleteRule(t,n,a)}),!0}},Qa=s=>{const e={...s,ruleIds:s.rules.map(t=>t.id)};return{id:Te.id,params:e}},Ce={id:"sheet.mutation.add-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rules:o}=e,r=s.get(X);return o.forEach(a=>{r.addRule(t,n,a)}),!0}},Do={type:i.CommandType.COMMAND,id:"sheet.command.add-range-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(X),{rule:r,permissionId:a}=e,{unitId:l,subUnitId:u,ranges:d,description:c,viewState:m,editState:h}=r,R=[{ranges:d,permissionId:a,id:o.createRuleId(l,u),description:c,unitType:r.unitType,unitId:l,subUnitId:u,viewState:m,editState:h}];if(await t.executeCommand(Ce.id,{unitId:l,subUnitId:u,rules:R})){const S=[{id:Ce.id,params:{unitId:l,subUnitId:u,rules:R}}],v=[{id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:R.map(I=>I.id)}}];n.pushUndoRedo({unitID:l,redoMutations:S,undoMutations:v})}return!0}};var te=(s=>(s[s.MOVE_START=0]="MOVE_START",s[s.MOVING=1]="MOVING",s[s.MOVE_END=2]="MOVE_END",s[s.ONLY_SET=3]="ONLY_SET",s))(te||{});class No extends i.Disposable{constructor(t){super();f(this,"_worksheetSelections",new Map);f(this,"_selectionMoveStart$",new D.Subject);f(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());f(this,"_selectionMoving$",new D.Subject);f(this,"selectionMoving$",this._selectionMoving$.asObservable());f(this,"_selectionMoveEnd$",new D.BehaviorSubject([]));f(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());f(this,"_selectionSet$",new D.BehaviorSubject([]));f(this,"selectionSet$",this._selectionSet$.asObservable());f(this,"selectionChanged$");f(this,"_beforeSelectionMoveEnd$",new D.BehaviorSubject([]));f(this,"beforeSelectionMoveEnd$",this._beforeSelectionMoveEnd$.asObservable());this._workbook=t,this.selectionChanged$=D.merge(this._selectionMoveEnd$,this._selectionSet$)}dispose(){super.dispose(),this._beforeSelectionMoveEnd$.complete(),this._selectionMoveEnd$.complete(),this._selectionMoving$.complete(),this._selectionMoveStart$.complete(),this._selectionSet$.complete(),this._workbook=null}addSelections(t,n){const o=this.getSelectionsOfWorksheet(t);o.push(...n),this._selectionSet$.next(o)}setSelections(t,n=[],o){switch(this.setSelectionsOfWorksheet(t,n),o){case te.MOVE_START:this._selectionMoveStart$.next(n);break;case te.MOVING:this._selectionMoving$.next(n);break;case te.MOVE_END:this._beforeSelectionMoveEnd$.next(n),this._selectionMoveEnd$.next(n);break;case te.ONLY_SET:{this._selectionSet$.next(n);break}default:this._selectionSet$.next(n);break}}getCurrentSelections(){return this._getCurrentSelections()}getSelectionOfWorksheet(t){return this.getSelectionsOfWorksheet(t)}getSelectionsOfWorksheet(t){return this._worksheetSelections.has(t)||this._worksheetSelections.set(t,[]),this._worksheetSelections.get(t)}setSelectionsOfWorksheet(t,n){this._worksheetSelections.set(t,[...n])}deleteSheetSelection(t){this._worksheetSelections.set(t,[])}clear(){this._worksheetSelections.clear(),this._selectionSet$.next([])}_getCurrentSelections(){return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId())}getCurrentLastSelection(){const t=this._getCurrentSelections();return t[t.length-1]}}var el=Object.getOwnPropertyDescriptor,tl=(s,e,t,n)=>{for(var o=n>1?void 0:n?el(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},nl=(s,e)=>(t,n)=>e(t,n,s);g.SheetsSelectionsService=class extends i.RxDisposable{constructor(t){super();f(this,"_cellStylesCache",new Map);f(this,"selectionMoveStart$");f(this,"selectionMoving$");f(this,"selectionMoveEnd$");f(this,"selectionSet$");f(this,"selectionChanged$");f(this,"_workbookSelections",new Map);this._instanceSrv=t,this._init()}get _currentSelectionPos(){const t=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const n=t.getActiveSheet();return{unitId:t.getUnitId(),sheetId:n.getSheetId()}}get currentSelectionParam(){return this._currentSelectionPos}_init(){const t=this._instanceSrv.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).pipe(D.shareReplay(1),D.takeUntil(this.dispose$));this.selectionMoveStart$=t.pipe().pipe(D.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoveStart$:D.of())).pipe(D.takeUntil(this.dispose$)),this.selectionMoving$=t.pipe(D.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoving$:D.of())).pipe(D.takeUntil(this.dispose$)),this.selectionMoveEnd$=t.pipe(D.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoveEnd$:D.of([]))).pipe(D.takeUntil(this.dispose$)),this.selectionSet$=t.pipe(D.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionSet$:D.of([]))).pipe(D.takeUntil(this.dispose$)),this.selectionChanged$=t.pipe(D.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionChanged$:D.of([]))).pipe(D.distinctUntilChanged((n,o)=>n.length!==o.length?!1:n.length===0&&o.length===0?!0:n.every((r,a)=>JSON.stringify(r)===JSON.stringify(o[a]))),D.skip(1)).pipe(D.takeUntil(this.dispose$)),this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(n=>{this._removeWorkbookSelection(n.getUnitId())})),this.disposeWithMe(this.selectionChanged$.pipe(D.takeUntil(this.dispose$)).subscribe(()=>{this._cellStylesCache.clear()}))}dispose(){super.dispose(),this._cellStylesCache.clear(),this._workbookSelections.forEach(t=>t.dispose()),this._workbookSelections.clear(),this.selectionMoveStart$=D.of(null),this.selectionMoving$=D.of(null),this.selectionMoveEnd$=D.of([]),this.selectionSet$=D.of(null),this.selectionChanged$=D.of(null)}clear(){this._workbookSelections.forEach(t=>t.clear())}getCurrentSelections(){return this._getCurrentSelections()}getCurrentLastSelection(){const t=this._getCurrentSelections();return t==null?void 0:t[t.length-1]}addSelections(t,n,o){if(typeof t=="string"){this._ensureWorkbookSelection(t).addSelections(n,o);return}const r=this._currentSelectionPos;if(!r)throw new Error("[SheetsSelectionsService]: cannot find current selection position!");const{unitId:a,sheetId:l}=r;this._ensureWorkbookSelection(a).addSelections(l,t)}setSelections(t,n,o,r){if(typeof t=="string"&&typeof n=="string"){const d=t;this._ensureWorkbookSelection(d).setSelections(n,o||[],r!=null?r:te.ONLY_SET);return}const a=this._currentSelectionPos;if(!a)throw new Error("[SheetsSelectionsService]: cannot find current selection position!");const{unitId:l,sheetId:u}=a;if(typeof t=="object"){const d=t!=null?t:o,c=n!=null?n:te.ONLY_SET;this._ensureWorkbookSelection(l).setSelections(u,d,c)}}clearCurrentSelections(){this._getCurrentSelections().splice(0)}isOverlapping(){const t=this.getCurrentSelections();return t==null?!1:t.some(({range:n},o)=>t.some(({range:r},a)=>o===a?!1:n.startRow<=r.endRow&&n.endRow>=r.startRow&&n.startColumn<=r.endColumn&&n.endColumn>=r.startColumn))}_getCurrentSelections(){const t=this._currentSelectionPos;if(!t)return[];const{unitId:n,sheetId:o}=t;return this._ensureWorkbookSelection(n).getSelectionsOfWorksheet(o)}getWorkbookSelections(t){return this._ensureWorkbookSelection(t)}_ensureWorkbookSelection(t){let n=this._workbookSelections.get(t);if(!n){const o=this._instanceSrv.getUnit(t);if(!o)throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${t}"!`);n=new No(o),this._workbookSelections.set(t,n)}return n}_removeWorkbookSelection(t){this._workbookSelections.delete(t)}getCellStylesProperty(t){var a;const n=(a=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:a.getActiveSheet(),o=this.getCurrentSelections();if(!n||o.length===0)return{isAllValuesSame:!1,value:null};let r=null;for(let l=0;l<o.length;l++){const u=o[l],{startRow:d,endRow:c,startColumn:m,endColumn:h}=u.range;for(let R=d;R<=c;R++)for(let C=m;C<=h;C++){const S=`${R}_${C}`;let v;this._cellStylesCache.has(S)?v=this._cellStylesCache.get(S):(v=n.getComposedCellStyle(R,C),this._cellStylesCache.set(S,v));const I=v[t];if(r!=null&&!i.Tools.diffValue(r,I))return{isAllValuesSame:!1,value:null};r=I}}return{isAllValuesSame:!0,value:r}}},g.SheetsSelectionsService=tl([nl(0,i.IUniverInstanceService)],g.SheetsSelectionsService);const sl="DISABLE_NORMAL_SELECTIONS",ol="SELECTIONS_ENABLED",Ao="REF_SELECTIONS_ENABLED",sn={id:"sheet.command.clear-selection-all",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Nt(m,s,u,c),R=[],C=[],S={subUnitId:c,unitId:u,cellValue:qn(h)},v=ce(s,S);R.push({id:F.id,params:S}),C.push({id:F.id,params:v});const I=a.onCommandExecute({id:sn.id});return R.push(...I.redos),C.unshift(...I.undos),i.sequenceExecute(R,n)?(r.pushUndoRedo({unitID:u,undoMutations:C,redoMutations:R}),!0):!1}},on={id:"sheet.command.clear-selection-format",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Nt(m,s,u,c),R=[],C=[],S={subUnitId:c,unitId:u,cellValue:Xa(h)},v=ce(s,S);R.push({id:F.id,params:S}),C.push({id:F.id,params:v});const I=a.onCommandExecute({id:on.id});return R.push(...I.redos),C.unshift(...I.undos),i.sequenceExecute(R,n)?(r.pushUndoRedo({unitID:u,undoMutations:C,redoMutations:R}),!0):!1}};function At(s,e,t=!0){const n=e.getMatrixWithMergedCells(...i.selectionToArray(s)),o=[];if(n.forValue((a,l,u)=>{if(u.colSpan!==void 0&&u.rowSpan!==void 0){const d={startRow:a,startColumn:l,endRow:a+u.rowSpan-1,endColumn:l+u.colSpan-1};i.Rectangle.contains(s,d)||o.push(d)}}),o.length===0)return s;const r=i.Rectangle.union(s,...o);return t?At(r,e,t):r}function rl(s,e,t){let n=null;return t.getMatrixWithMergedCells(s,e,s,e).forValue((r,a,l)=>(n={actualRow:r,actualColumn:a,startRow:r,startColumn:a,isMerged:l.rowSpan!==void 0||l.colSpan!==void 0,isMergedMainCell:l.rowSpan!==void 0&&l.colSpan!==void 0,endRow:r+(l.rowSpan!==void 0?l.rowSpan-1:0),endColumn:a+(l.colSpan!==void 0?l.colSpan-1:0),rangeType:i.RANGE_TYPE.NORMAL},!1)),n||{actualColumn:e,actualRow:s,startRow:s,startColumn:e,endRow:s,endColumn:e,isMerged:!1,isMergedMainCell:!1,rangeType:i.RANGE_TYPE.NORMAL}}function il(s,e,t){const{startRow:n,startColumn:o,endRow:r,endColumn:a}=s;return Number.isNaN(n)&&(s.startRow=0),Number.isNaN(r)&&(s.endRow=e-1),Number.isNaN(o)&&(s.startColumn=0),Number.isNaN(a)&&(s.endColumn=t-1),s}function se(s,e){const t=Number.isNaN(s.startRow)?0:s.startRow,n=Number.isNaN(s.startColumn)?0:s.startColumn,o=e.getMergedCell(t,n);return o?{...o,actualRow:t,actualColumn:n,rangeType:i.RANGE_TYPE.NORMAL,isMerged:!0,isMergedMainCell:!0}:{startRow:t,startColumn:n,endRow:s.startRow,endColumn:s.startColumn,actualRow:t,actualColumn:n,rangeType:i.RANGE_TYPE.NORMAL,isMerged:!1,isMergedMainCell:!1}}const Ue=(s,e,t)=>({id:q.id,params:{unitId:e.getUnitId(),subUnitId:t.getSheetId(),reveal:!0,selections:[{range:s,primary:se(s,t)}]}});function al(s){if(!s)return!1;const{range:e,primary:t}=s;return i.Rectangle.equals(e,t)}function ll(s){function e(t,n){function o(r){for(let a=r.startRow;a<=r.endRow;a++)if(!s.getRowFiltered(a))for(let l=r.startColumn;l<=r.endColumn;l++)n(a,l,r)}o(t)}return{forOperableEach:e}}const Wo=s=>s.id!==no;function $e(s,e,t,n,o,r,a){const l={};for(let u=e;u<=t;u++)for(let d=n;d<=o;d++){const c=r?s.getCellWithFilteredInterceptors(a,d,so,Wo):s.getCellWithFilteredInterceptors(u,a,so,Wo);!c||!c.s||(l[u]||(l[u]={}),l[u][d]={s:c.s})}return l}var ul=Object.getOwnPropertyDescriptor,dl=(s,e,t,n)=>{for(var o=n>1?void 0:n?ul(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},cl=(s,e)=>(t,n)=>e(t,n,s);const Vo=i.createIdentifier("sheets-formula.ref-selections.service");g.RefSelectionsService=class extends g.SheetsSelectionsService{constructor(e){super(e)}_init(){const e=this._getAliveWorkbooks$().pipe(D.takeUntil(this.dispose$));this.selectionMoveStart$=e.pipe(D.switchMap(t=>D.merge(...t.map(n=>n.selectionMoveStart$)))),this.selectionMoving$=e.pipe(D.switchMap(t=>D.merge(...t.map(n=>n.selectionMoving$)))),this.selectionMoveEnd$=e.pipe(D.switchMap(t=>D.merge(...t.map(n=>n.selectionMoveEnd$)))),this.selectionSet$=e.pipe(D.switchMap(t=>D.merge(...t.map(n=>n.selectionSet$))))}dispose(){super.dispose(),this.selectionMoveStart$=D.of(null),this.selectionMoving$=D.of(null),this.selectionMoveEnd$=D.of(null),this.selectionSet$=D.of(null),delete this._instanceSrv,this._workbookSelections.clear()}_getAliveWorkbooks$(){const e=this._instanceSrv.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET);e.forEach(n=>this._ensureWorkbookSelection(n.getUnitId()));const t=new D.BehaviorSubject(e);return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._ensureWorkbookSelection(n.getUnitId()),t.next([...t.getValue(),n])})),this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._removeWorkbookSelection(n.getUnitId()),t.next(t.getValue().filter(o=>o!==n))})),t.pipe(D.map(n=>n.map(o=>this._ensureWorkbookSelection(o.getUnitId()))))}},g.RefSelectionsService=dl([cl(0,i.IUniverInstanceService)],g.RefSelectionsService);function $o(s,e){const n=s.get(i.IContextService).getContextValue(Ao);return s.get(n&&!e?Vo:g.SheetsSelectionsService)}const q={id:"sheet.operation.set-selections",type:i.CommandType.OPERATION,handler:(s,e)=>{if(!e)return!1;const{selections:t,type:n,unitId:o,subUnitId:r}=e;return $o(s).setSelections(o,r,[...t],n),!0}},Lo={id:"sheet.command.select-range",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnit:n,range:o}=e,r=s.get(i.ICommandService),a=P(s.get(i.IUniverInstanceService),e);if(!a)return!1;const l=[{range:o,primary:se(o,a.worksheet),style:null}];return r.syncExecuteCommand(q.id,{unitId:t,subUnitId:n,selections:l})}},Ho="sheet.command.move-range",Je={type:i.CommandType.COMMAND,id:Ho,handler:async(s,e)=>{var M,p;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(i.ErrorService),a=s.get(i.LocaleService),l=s.get(g.SheetInterceptorService),u=P(o);if(!u||!await l.beforeCommandExecute({id:Je.id,params:e}))return!1;const{worksheet:c,subUnitId:m,unitId:h}=u,R=rn(s,{unitId:h,subUnitId:m,range:e.fromRange},{subUnitId:m,range:e.toRange});if(R===null)return r.emit(a.t("sheets.info.acrossMergedCell")),!1;const C=l.onCommandExecute({id:Je.id,params:e}),S=[...(M=C.preRedos)!=null?M:[],...R.redos,...C.redos,{id:q.id,params:{unitId:h,subUnitId:m,selections:[{range:e.toRange,primary:ml(e.fromRange,e.toRange,c)}],type:te.MOVE_END}}],v=[...(p=C.preUndos)!=null?p:[],...R.undos,...C.undos,{id:q.id,params:{unitId:h,subUnitId:m,selections:[{range:e.fromRange,primary:se(e.fromRange,c)}],type:te.MOVE_END}}];if(i.sequenceExecute(S,t).result){const{undos:w,redos:y}=l.generateMutationsOfAutoHeight({unitId:h,subUnitId:m,ranges:[e.fromRange,e.toRange]}),b=l.afterCommandExecute({id:Je.id,params:e});return i.sequenceExecute([...b.redos,...y],t),n.pushUndoRedo({unitID:h,undoMutations:[...v,...b.undos,...w],redoMutations:[...S,...b.redos,...y]}),!0}return!1}};function rn(s,e,t,n=!1){const o=[],r=[],{range:a,subUnitId:l,unitId:u}=e,{range:d,subUnitId:c}=t,h=s.get(i.IUniverInstanceService).getUniverSheetInstance(u),R=h==null?void 0:h.getSheetBySheetId(c),C=h==null?void 0:h.getSheetBySheetId(l),S=R==null?void 0:R.getCellMatrix(),v=C==null?void 0:C.getCellMatrix();if(R&&C&&S&&v){const I=At(d,R,!1);if(!i.Rectangle.equals(d,I)&&!n)return null;const M=new i.ObjectMatrix,p=new i.ObjectMatrix,w=new i.ObjectMatrix;i.Range.foreach(a,(k,E)=>{const O=v.getValue(k,E);if(M.setValue(k,E,i.Tools.deepClone(O)),O){const W=h==null?void 0:h.getStyles().get(O.s);w.setValue(k,E,i.Tools.deepClone(W))}p.setValue(k,E,null)});const y=new i.ObjectMatrix,b=new i.ObjectMatrix;i.Range.foreach(d,(k,E)=>{y.setValue(k,E,i.Tools.deepClone(S.getValue(k,E)))}),i.Range.foreach(a,(k,E)=>{const O=i.cellToRange(k,E),W=i.Rectangle.getRelativeRange(O,a),V=i.Rectangle.getPositionRange(W,d),$=i.Tools.deepClone(w.getValue(k,E)),L=i.Tools.deepClone(M.getValue(k,E));L&&$&&(L.s=$),b.setValue(V.startRow,V.startColumn,L)});const T={fromRange:e.range,toRange:t.range,from:{value:p.getMatrix(),subUnitId:l},to:{value:b.getMatrix(),subUnitId:c},unitId:u},U={fromRange:t.range,toRange:e.range,from:{value:M.getMatrix(),subUnitId:l},to:{value:y.getMatrix(),subUnitId:c},unitId:u};o.push({id:Le.id,params:T}),r.push({id:Le.id,params:U})}return{redos:o,undos:r}}function ml(s,e,t){const n=s.startRow,o=s.startColumn,r=t.getMergedCell(n,o),a=se(e,t);if(r){const l=r.endRow-r.startRow+1,u=r.endColumn-r.startColumn+1;a.endRow=a.startRow+l-1,a.endColumn=a.startColumn+u-1,a.actualRow=a.startRow,a.actualColumn=a.startColumn,a.isMerged=!1,a.isMergedMainCell=!0}return a}var an=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(an||{}),_=(s=>(s[s.View=0]="View",s[s.Edit=1]="Edit",s[s.ManageCollaborator=2]="ManageCollaborator",s[s.Print=3]="Print",s[s.Duplicate=4]="Duplicate",s[s.Comment=5]="Comment",s[s.Copy=6]="Copy",s[s.Share=7]="Share",s[s.Export=8]="Export",s[s.MoveWorksheet=9]="MoveWorksheet",s[s.DeleteWorksheet=10]="DeleteWorksheet",s[s.HideWorksheet=11]="HideWorksheet",s[s.RenameWorksheet=12]="RenameWorksheet",s[s.CreateWorksheet=13]="CreateWorksheet",s[s.SetWorksheetStyle=14]="SetWorksheetStyle",s[s.EditWorksheetCell=15]="EditWorksheetCell",s[s.InsertHyperlink=16]="InsertHyperlink",s[s.Sort=17]="Sort",s[s.Filter=18]="Filter",s[s.PivotTable=19]="PivotTable",s[s.FloatImg=20]="FloatImg",s[s.History=21]="History",s[s.RwHgtClWdt=22]="RwHgtClWdt",s[s.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",s[s.ViewFilter=24]="ViewFilter",s[s.MoveSheet=25]="MoveSheet",s[s.DeleteSheet=26]="DeleteSheet",s[s.HideSheet=27]="HideSheet",s[s.CopySheet=28]="CopySheet",s[s.RenameSheet=29]="RenameSheet",s[s.CreateSheet=30]="CreateSheet",s[s.SelectProtectedCells=31]="SelectProtectedCells",s[s.SelectUnProtectedCells=32]="SelectUnProtectedCells",s[s.SetCellStyle=33]="SetCellStyle",s[s.SetCellValue=34]="SetCellValue",s[s.SetRowStyle=35]="SetRowStyle",s[s.SetColumnStyle=36]="SetColumnStyle",s[s.InsertRow=37]="InsertRow",s[s.InsertColumn=38]="InsertColumn",s[s.DeleteRow=39]="DeleteRow",s[s.DeleteColumn=40]="DeleteColumn",s[s.EditExtraObject=41]="EditExtraObject",s[s.Delete=42]="Delete",s[s.RecoverHistory=43]="RecoverHistory",s[s.ViewHistory=44]="ViewHistory",s[s.CreatePermissionObject=45]="CreatePermissionObject",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(_||{}),N=(s=>(s[s.Unkonwn=0]="Unkonwn",s[s.Workbook=1]="Workbook",s[s.Worksheet=2]="Worksheet",s[s.SelectRange=3]="SelectRange",s[s.Document=4]="Document",s[s.Slide=5]="Slide",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(N||{});class Se{constructor(e,t,n){f(this,"type",N.SelectRange);f(this,"subType",_.Edit);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${N.SelectRange}.${_.Edit}.${n}`}}class ln{constructor(e,t,n){f(this,"type",N.SelectRange);f(this,"subType",_.View);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${N.SelectRange}.${_.View}.${n}`}}class Yn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Comment);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Comment}_${e}`}}class Kn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Copy);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Copy}_${e}`}}class Bo{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"subType",_.CopySheet);f(this,"status",i.PermissionStatus.INIT);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CopySheet}_${e}`}}class Jn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.CreatePermissionObject);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CreatePermissionObject}_${e}`}}class xn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.CreateSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CreateSheet}_${e}`}}class Fo{constructor(e){f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteColumn);this.unitId=e,this.id=`${this.type}.${_.DeleteColumn}_${e}`}}class jo{constructor(e){f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteRow);this.unitId=e,this.id=`${this.type}.${_.DeleteRow}_${e}`}}class Xn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.DeleteSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.DeleteSheet}_${e}`}}class Zn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Duplicate);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Duplicate}_${e}`}}class me{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Edit);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Edit}_${e}`}}class Qn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Export);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Export}_${e}`}}class un{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.HideSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.HideSheet}_${e}`}}class Go{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.History);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.History}_${e}`}}class zo{constructor(e){f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertColumn);this.unitId=e,this.id=`${this.type}.${_.InsertColumn}_${e}`}}class qo{constructor(e){f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertRow);this.unitId=e,this.id=`${this.type}.${_.InsertRow}_${e}`}}class dn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.ManageCollaborator);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.ManageCollaborator}_${e}`}}class cn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.MoveSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.MoveSheet}_${e}`}}class es{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Print);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Print}_${e}`}}class ts{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.RecoverHistory);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.RecoverHistory}_${e}`}}class mn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.RenameSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.RenameSheet}_${e}`}}class ns{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Share);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Share}_${e}`}}class ss{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.View);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.View}_${e}`}}class os{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",N.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.ViewHistory);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.ViewHistory}_${e}`}}class rs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Copy);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Copy}_${e}_${t}`}}class is{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteColumn);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.DeleteColumn}_${e}_${t}`}}class as{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Delete);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Delete}_${e}_${t}`}}class ls{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteRow);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.DeleteRow}_${e}_${t}`}}class fe{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Edit);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Edit}_${e}_${t}`}}class us{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.EditExtraObject);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.EditExtraObject}_${e}_${t}`}}class ds{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Filter);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Filter}_${e}_${t}`}}class cs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertColumn);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertColumn}_${e}_${t}`}}class ms{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertHyperlink);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertHyperlink}_${e}_${t}`}}class hs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertRow);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertRow}_${e}_${t}`}}class gs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.ManageCollaborator);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.ManageCollaborator}_${e}_${t}`}}class Rs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.PivotTable);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.PivotTable}_${e}_${t}`}}class hl{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SelectProtectedCells);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SelectProtectedCells}_${e}_${t}`}}class gl{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SelectUnProtectedCells);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`}}class Cs{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetCellStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetCellStyle}_${e}_${t}`}}class Wt{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetCellValue);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetCellValue}_${e}_${t}`}}class St{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetColumnStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetColumnStyle}_${e}_${t}`}}class ft{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetRowStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetRowStyle}_${e}_${t}`}}class Ss{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Sort);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Sort}_${e}_${t}`}}class Vt{constructor(e,t){f(this,"value",!0);f(this,"type",N.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.View);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.View}_${e}_${t}`}}const vt={id:"sheet.command.set-range-values",type:i.CommandType.COMMAND,handler:(s,e)=>{var W;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.IPermissionService),u=P(o,e);if(!u)return!1;const{subUnitId:d,unitId:c,workbook:m,worksheet:h}=u,{value:R,range:C,redoUndoId:S}=e,v=C?[C]:(W=r.getCurrentSelections())==null?void 0:W.map(V=>V.range);if(!v||!v.length||!l.getPermissionPoint(new fe(c,d).id))return!1;const I=new i.ObjectMatrix;let M;if(i.Tools.isArray(R))for(let V=0;V<v.length;V++){const{startRow:$,startColumn:L,endRow:Y,endColumn:z}=v[V];for(let K=0;K<=Y-$;K++)for(let oe=0;oe<=z-L;oe++)I.setValue(K+$,oe+L,R[K][oe])}else if(i.isICellData(R))for(let V=0;V<v.length;V++){const{startRow:$,startColumn:L,endRow:Y,endColumn:z}=v[V];for(let K=$;K<=Y;K++)for(let oe=L;oe<=z;oe++)I.setValue(K,oe,R)}else M=R;const p={subUnitId:d,unitId:c,cellValue:M!=null?M:I.getMatrix()},w=ce(s,p),y=i.mapObjectMatrix(p.cellValue,(V,$)=>h.getCellHeight(V,$)||void 0);if(!t.syncExecuteCommand(F.id,p))return!1;const{undos:T,redos:U}=a.onCommandExecute({id:vt.id,params:p}),{undos:k,redos:E}=a.generateMutationsOfAutoHeight({unitId:c,subUnitId:d,ranges:v,cellHeights:new i.ObjectMatrix(y)});if(i.sequenceExecute([...U,...E],t).result){const V=Ue(C!=null?C:I.getRange(),m,h);return n.pushUndoRedo({unitID:c,undoMutations:[{id:F.id,params:w},...T,...k,V],redoMutations:[{id:F.id,params:p},...U,...E,i.Tools.deepClone(V)],id:S}),!0}return!1}};function fs(s,e){const t=[],n=[],{unitId:o,subUnitId:r,range:a,shiftDimension:l,cellValue:u={}}=e,d=s.get(i.IUniverInstanceService),c=s.get(g.SheetInterceptorService),m=d.getUniverSheetInstance(o),h=m==null?void 0:m.getSheetBySheetId(r);if(h){const R=h.getCellMatrix(),C=R.getDataRange();if(a.startColumn<=C.endColumn||a.startRow<=C.endRow){let p,w;if(l===i.Dimension.COLUMNS){const b=Math.min(a.endRow,C.endRow);let T=0;for(let k=a.startRow;k<=b;k++){const E=R.getRow(k),O=E?i.getArrayLength(E)-1:0;T=Math.max(T,O)}p={startRow:a.startRow,startColumn:a.startColumn,endRow:b,endColumn:T};const U=a.endColumn-a.startColumn+1;w={startRow:a.startRow,startColumn:p.startColumn+U,endRow:b,endColumn:p.endColumn+U}}else{const b=Math.min(a.endColumn,C.endColumn),T=C.endRow;p={startRow:a.startRow,startColumn:a.startColumn,endRow:T,endColumn:b};const U=a.endRow-a.startRow+1;w={startRow:p.startRow+U,startColumn:a.startColumn,endRow:p.endRow+U,endColumn:b}}const y=rn(s,{unitId:o,subUnitId:r,range:p},{subUnitId:r,range:w},!0);y&&(t.push(...y.redos),n.push(...y.undos))}if(Object.entries(u).length===0)for(let p=a.startRow;p<=a.endRow;p++){u[p]||(u[p]={});for(let w=a.startColumn;w<=a.endColumn;w++)u[p][w]=null}const S={subUnitId:r,unitId:o,cellValue:u},v=ce(s,S),{undos:I,redos:M}=c.onCommandExecute({id:vt.id,params:{...S,range:a}});t.push({id:F.id,params:S},...M),n.push({id:F.id,params:v},...I)}return{redo:t,undo:n}}function vs(s,e){const t=[],n=[],{unitId:o,subUnitId:r,range:a,shiftDimension:l}=e,u=s.get(i.IUniverInstanceService),d=s.get(g.SheetInterceptorService),c=u.getUniverSheetInstance(o),m=c==null?void 0:c.getSheetBySheetId(r);if(m){const h=m.getCellMatrix(),R=h.getDataRange(),C={subUnitId:r,unitId:o,cellValue:qn([a])},S=ce(s,C),v=d.onCommandExecute({id:vt.id,params:C});if(t.push({id:F.id,params:C},...v.redos),n.push(...v.undos,{id:F.id,params:S}),a.startColumn<=R.endColumn||a.startRow<=R.endRow){let I=null,M=null;if(l===i.Dimension.COLUMNS&&a.endColumn<R.endColumn){const p=Math.min(a.endRow,R.endRow);let w=0;for(let b=a.startRow;b<=p;b++){const T=h.getRow(b),U=T?i.getArrayLength(T)-1:0;w=Math.max(w,U)}I={startRow:a.startRow,startColumn:a.endColumn+1,endRow:p,endColumn:w};const y=a.endColumn-a.startColumn+1;M={startRow:a.startRow,startColumn:I.startColumn-y,endRow:p,endColumn:I.endColumn-y}}if(l===i.Dimension.ROWS&&a.endRow<R.endRow){const p=Math.min(a.endColumn,R.endColumn),w=R.endRow;I={startRow:a.endRow+1,startColumn:a.startColumn,endRow:w,endColumn:p};const y=a.endRow-a.startRow+1;M={startRow:I.startRow-y,startColumn:a.startColumn,endRow:I.endRow-y,endColumn:p}}if(I&&M){const p=rn(s,{unitId:o,subUnitId:r,range:I},{subUnitId:r,range:M},!0);p&&(t.push(...p.redos),n.push(...p.undos))}}}return{redo:t,undo:n}}function Rl(s,e,t,n,o,r){const{startRow:a,endRow:l,startColumn:u,endColumn:d}=e;if(o===i.Dimension.ROWS){const c=l-a+1;for(let m=t;m>=a;m--)for(let h=u;h<=d;h++){const R=s.getValue(m,h);R==null?s.realDeleteValue(m+c,h):s.setValue(m+c,h,R)}for(let m=l;m>=a;m--)for(let h=u;h<=d;h++)r&&r[m]&&r[m][h]?s.setValue(m,h,r[m][h]):s.realDeleteValue(m,h)}else if(o===i.Dimension.COLUMNS){const c=d-u+1;for(let m=a;m<=l;m++)for(let h=n;h>=u;h--){const R=s.getValue(m,h);R==null?s.realDeleteValue(m,h+c):s.setValue(m,h+c,R)}for(let m=a;m<=l;m++)for(let h=d;h>=u;h--)r&&r[m]&&r[m][h]?s.setValue(m,h,r[m][h]):s.realDeleteValue(m,h)}}function Cl(s,e,t,n,o){const{startRow:r,endRow:a,startColumn:l,endColumn:u}=e,d=a-r+1,c=u-l+1;if(o===i.Dimension.ROWS)for(let m=r;m<=t;m++)for(let h=l;h<=u;h++){const R=s.getValue(m+d,h);R==null?s.realDeleteValue(m,h):s.setValue(m,h,R)}else if(o===i.Dimension.COLUMNS)for(let m=r;m<=a;m++)for(let h=l;h<=n;h++){const R=s.getValue(m,h+c);R==null?s.realDeleteValue(m,h):s.setValue(m,h,R)}}const Yo="sheet.command.delete-range-move-left",He={type:i.CommandType.COMMAND,id:Yo,handler:async(s,e)=>{var w,y,b;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=P(o);if(!l)return!1;const{worksheet:u,workbook:d,subUnitId:c,unitId:m}=l;let h=e==null?void 0:e.range;if(h||(h=(w=r.getCurrentLastSelection())==null?void 0:w.range),!h)return!1;const R={range:h,subUnitId:c,unitId:m,shiftDimension:i.Dimension.COLUMNS},C=a.onCommandExecute({id:He.id,params:{range:h}}),{redo:S,undo:v}=vs(s,R),I=[...(y=C.preRedos)!=null?y:[],...S],M=[...C.undos,...v];if(I.push(...C.redos),I.push(Ue(h,d,u)),M.push(...(b=C.preUndos)!=null?b:[]),i.sequenceExecute(I,t).result){const T=a.afterCommandExecute({id:He.id,params:{range:h}});return i.sequenceExecute(T.redos,t),M.push(...T.undos),I.push(...T.redos),n.pushUndoRedo({unitID:m,undoMutations:M.reverse(),redoMutations:I}),!0}return!1}},Ko="sheet.command.delete-range-move-up",Be={type:i.CommandType.COMMAND,id:Ko,handler:async(s,e)=>{var w,y,b;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=P(o);if(!l)return!1;const{unitId:u,subUnitId:d,workbook:c,worksheet:m}=l;let h=e==null?void 0:e.range;if(h||(h=(w=r.getCurrentLastSelection())==null?void 0:w.range),!h)return!1;const R={range:h,subUnitId:d,unitId:u,shiftDimension:i.Dimension.ROWS},C=a.onCommandExecute({id:Be.id,params:{range:h}}),{redo:S,undo:v}=vs(s,R),I=[...(y=C.preRedos)!=null?y:[],...S],M=[...C.undos,...v];if(I.push(...C.redos),I.push(Ue(h,c,m)),M.push(...(b=C.preUndos)!=null?b:[]),i.sequenceExecute(I,t).result){const T=a.afterCommandExecute({id:Be.id,params:{range:h}});return i.sequenceExecute(T.redos,t),M.push(...T.undos),I.push(...T.redos),n.pushUndoRedo({unitID:u,undoMutations:M.reverse(),redoMutations:I}),!0}return!1}},Sl="sheet.command.insert-range-move-down",xe={type:i.CommandType.COMMAND,id:"sheet.command.insert-range-move-down",handler:async(s,e)=>{var W,V,$;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.ErrorService),u=s.get(i.LocaleService);if(r.isOverlapping())return l.emit(u.t("sheets.info.overlappingSelections")),!1;const d=P(o);if(!d)return!1;const{unitId:c,subUnitId:m,worksheet:h,workbook:R}=d;let C=e==null?void 0:e.range;if(C||(C=(W=r.getCurrentLastSelection())==null?void 0:W.range),!C)return!1;const S=[],v=[],I=h.getCellMatrix(),M=I.getDataRange(),w=I.getSlice(M.startRow,M.endRow,C.startColumn,C.endColumn).getDataRange().endRow,y=Math.max(w+(C.endRow-C.startRow+1)-M.endRow,0);if(y>0){const L=C.startRow-1,Y=h.getRowHeight(L),z={unitId:c,subUnitId:m,range:{startRow:M.endRow+1,endRow:M.endRow+y,startColumn:M.startColumn,endColumn:M.endColumn},rowInfo:new Array(y).fill(void 0).map(()=>({h:Y,hd:i.BooleanNumber.FALSE}))};S.push({id:re.id,params:z});const K=en(s,z);v.push({id:ae.id,params:K})}const b={};i.Range.foreach(C,(L,Y)=>{const z=h.getCell(L,Y);z&&(b[L]||(b[L]={}),b[L][Y]={s:z.s})});const T={range:C,subUnitId:m,unitId:c,shiftDimension:i.Dimension.ROWS,cellValue:b},{redo:U,undo:k}=fs(s,T);S.push(...U),v.push(...k);const E=a.onCommandExecute({id:xe.id,params:{range:C}});if(S.push(...E.redos),S.push(Ue(C,R,h)),v.push(...(V=E.preUndos)!=null?V:[]),S.unshift(...($=E.preRedos)!=null?$:[]),v.unshift(...E.undos),i.sequenceExecute(S,t)){const L=a.afterCommandExecute({id:xe.id,params:{range:C}});return i.sequenceExecute(L.redos,t),v.push(...L.undos),S.push(...L.redos),n.pushUndoRedo({unitID:c,undoMutations:v.reverse(),redoMutations:S}),!0}return!1}},Is="sheet.command.insert-range-move-right",It={type:i.CommandType.COMMAND,id:Is,handler:async(s,e)=>{var W,V,$;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.ErrorService),u=s.get(i.LocaleService);if(r.isOverlapping())return l.emit(u.t("sheets.info.overlappingSelections")),!1;const d=P(o);if(!d)return!1;const{workbook:c,worksheet:m,unitId:h,subUnitId:R}=d;let C=e==null?void 0:e.range;if(C||(C=(W=r.getCurrentLastSelection())==null?void 0:W.range),!C)return!1;const S=[],v=[],I=m.getCellMatrix(),M=I.getDataRange(),w=I.getSlice(C.startRow,C.endRow,M.startColumn,M.endColumn).getDataRange().endColumn,y=Math.max(w+(C.endColumn-C.startColumn+1)-M.endColumn,0);if(y>0){const L=C.startColumn-1,Y=m.getColumnWidth(L),z={unitId:h,subUnitId:R,range:{startRow:M.startRow+1,endRow:M.endRow,startColumn:M.endColumn+1,endColumn:M.endColumn+y},colInfo:new Array(y).fill(void 0).map(()=>({w:Y,hd:i.BooleanNumber.FALSE}))};S.push({id:ie.id,params:z});const K=Ot(s,z);v.push({id:ne.id,params:K})}const b={};i.Range.foreach(C,(L,Y)=>{const z=m.getCell(L,Y);!z||!z.s||(b[L]||(b[L]={}),b[L][Y]={s:z.s})});const T={range:C,subUnitId:R,unitId:h,shiftDimension:i.Dimension.COLUMNS,cellValue:b},{redo:U,undo:k}=fs(s,T);S.push(...U),v.push(...k);const E=a.onCommandExecute({id:It.id,params:{range:C}});if(S.push(...E.redos),S.push(Ue(C,c,m)),v.push(...(V=E.preUndos)!=null?V:[]),S.unshift(...($=E.preRedos)!=null?$:[]),v.unshift(...E.undos),i.sequenceExecute(S,t).result){const L=a.afterCommandExecute({id:It.id,params:{range:C}});return i.sequenceExecute(L.redos,t),v.push(...L.undos),S.push(...L.redos),n.pushUndoRedo({unitID:h,undoMutations:v.reverse(),redoMutations:S}),!0}return!1}},Jo="sheet.command.insert-row",Me={type:i.CommandType.COMMAND,id:Jo,handler:async(s,e)=>{const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService),{range:o,direction:r,unitId:a,subUnitId:l,cellValue:u}=e;return await n.beforeCommandExecute({id:Me.id,params:e})?t.syncExecuteCommand(ps.id,{range:o,direction:r,unitId:a,subUnitId:l,cellValue:u}):!1}},ps={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-by-range",handler:(s,e)=>{var U,k,E,O;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=P(o,e);if(!a)return!1;const{workbook:l,worksheet:u}=a,{range:d,direction:c,unitId:m,subUnitId:h,cellValue:R}=e,{startRow:C,endRow:S}=d;d.rangeType=i.RANGE_TYPE.ROW;const v=c===i.Direction.UP?C:C-1,I=u.getRowHeight(v),M={unitId:m,subUnitId:h,range:d,rowInfo:new Array(S-C+1).fill(void 0).map(()=>({h:I,hd:i.BooleanNumber.FALSE}))},p=en(s,M),w=[{id:re.id,params:M}],y=[{id:ae.id,params:p}];R&&Object.keys(R).length>0&&w.push({id:F.id,params:{unitId:m,subUnitId:h,cellValue:R}});const b=r.onCommandExecute({id:Me.id,params:e});if(w.unshift(...(U=b.preRedos)!=null?U:[]),w.push(...(k=b.redos)!=null?k:[]),w.push(Ue(d,l,u)),y.unshift(...(E=b.preUndos)!=null?E:[]),y.push(...(O=b.undos)!=null?O:[]),i.sequenceExecute(w,t).result){const W=r.afterCommandExecute({id:Me.id,params:e});return i.sequenceExecute(W.redos,t),w.push(...W.redos),y.push(...W.undos),n.pushUndoRedo({unitID:e.unitId,undoMutations:y,redoMutations:w}),!0}return!1}},xo={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-before",handler:async(s,e)=>{var v;const n=(v=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:v.map(I=>I.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,subUnitId:u,unitId:d}=a,c=e.value||0,m=o.startRow,h=o.startRow+c-1,R=0,C=l.getColumnCount()-1,S={unitId:d,subUnitId:u,direction:i.Direction.UP,range:{startRow:m,endRow:h,startColumn:R,endColumn:C},cellValue:$e(l,m,h,R,C,!0,m-1)};return s.get(i.ICommandService).executeCommand(Me.id,S)}},Xo={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-after",handler:async s=>{var S;const t=(S=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:S.map(v=>v.range);let n;if((t==null?void 0:t.length)===1)n=t[0];else return!1;const o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=n.endRow-n.startRow+1,c=n.endRow+1,m=n.endRow+d,h=0,R=a.getColumnCount()-1,C={unitId:l,subUnitId:u,direction:i.Direction.DOWN,range:{startRow:c,endRow:m,startColumn:h,endColumn:R,rangeType:i.RANGE_TYPE.ROW},cellValue:$e(a,c,m,h,R,!0,n.endRow)};return s.get(i.ICommandService).executeCommand(Me.id,C)}},Zo={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-rows-above",handler:async(s,e)=>{var I;const n=(I=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:I.map(M=>M.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startRow,h=o.startRow+c-1,R=0,C=l.getColumnCount()-1,S=$e(l,m,h,R,C,!0,m-1),v={unitId:u,subUnitId:d,direction:i.Direction.UP,range:{startRow:m,endRow:h,startColumn:R,endColumn:C,rangeType:i.RANGE_TYPE.ROW},cellValue:S};return s.get(i.ICommandService).executeCommand(Me.id,v)}},Qo={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-rows-after",handler:async(s,e)=>{var v;const n=(v=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:v.map(I=>I.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.endRow+1,h=o.endRow+c,R=0,C=l.getColumnCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.DOWN,range:{startRow:m,endRow:h,startColumn:R,endColumn:C,rangeType:i.RANGE_TYPE.ROW},cellValue:$e(l,m,h,R,C,!0,o.endRow)};return s.get(i.ICommandService).executeCommand(Me.id,S)}},er="sheet.command.insert-col",ye={type:i.CommandType.COMMAND,id:er,handler:async(s,e)=>{const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService),{range:o,direction:r,subUnitId:a,unitId:l,cellValue:u}=e;return await n.beforeCommandExecute({id:ye.id,params:e})?t.syncExecuteCommand(ws.id,{range:o,direction:r,unitId:l,subUnitId:a,cellValue:u}):!1}},ws={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-by-range",handler:(s,e)=>{var T,U,k,E;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),{range:a,direction:l,subUnitId:u,unitId:d,cellValue:c}=e,{startColumn:m,endColumn:h}=e.range;a.rangeType=i.RANGE_TYPE.COLUMN;const R=o.getUniverSheetInstance(e.unitId),C=R.getSheetBySheetId(e.subUnitId),S=l===i.Direction.LEFT?m:m-1,v=C.getColumnWidth(S),I={unitId:d,subUnitId:u,range:a,colInfo:new Array(h-m+1).fill(void 0).map(()=>({w:v,hd:i.BooleanNumber.FALSE}))},M=Ot(s,I),p=[{id:ie.id,params:I}],w=[{id:ne.id,params:M}];c&&p.push({id:F.id,params:{unitId:d,subUnitId:u,cellValue:c}});const y=r.onCommandExecute({id:ye.id,params:e});if(p.unshift(...(T=y.preRedos)!=null?T:[]),p.push(...(U=y.redos)!=null?U:[]),p.push(Ue(a,R,C)),w.unshift(...(k=y.preUndos)!=null?k:[]),w.push(...(E=y.undos)!=null?E:[]),i.sequenceExecute(p,t).result){const O=r.afterCommandExecute({id:ye.id,params:e});return i.sequenceExecute(O.redos,t),p.push(...O.redos),w.push(...O.undos),n.pushUndoRedo({unitID:e.unitId,undoMutations:w.filter(Boolean),redoMutations:p.filter(Boolean)}),!0}return!1}},tr={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-before",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startColumn,h=o.startColumn+c-1,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.LEFT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C,rangeType:i.RANGE_TYPE.COLUMN},cellValue:$e(l,R,C,m,h,!1,m-1)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},nr={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-after",handler:async s=>{const t=s.get(g.SheetsSelectionsService).getCurrentSelections();let n;if((t==null?void 0:t.length)===1)n=t[0].range;else return!1;const o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=n.endColumn-n.startColumn+1,c=n.endColumn+1,m=n.endColumn+d,h=0,R=a.getRowCount()-1,C={unitId:l,subUnitId:u,direction:i.Direction.RIGHT,range:{startColumn:c,endColumn:m,startRow:h,endRow:R},cellValue:$e(a,h,R,c,m,!1,n.endColumn)};return s.get(i.ICommandService).executeCommand(ye.id,C)}},sr={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-cols-before",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startColumn,h=o.startColumn+c-1,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.LEFT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C,rangeType:i.RANGE_TYPE.COLUMN},cellValue:$e(l,R,C,m,h,!1,m-1)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},or={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-cols-right",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.endColumn+1,h=o.endColumn+c,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.RIGHT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C},cellValue:$e(l,R,C,m,h,!1,o.endColumn)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},hn="sheet.command.remove-row",Ms={type:i.CommandType.COMMAND,id:"sheet.command.remove-row-by-range",handler:(s,e)=>{var v,I,M;if(!e)return!1;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{workbook:o,worksheet:r}=n,a=s.get(g.SheetInterceptorService),{range:l,unitId:u,subUnitId:d}=e,c=Nt([l],s,u,d).reverse(),m=[],h=[];c.forEach(p=>{const w=[],y=[],b={unitId:u,subUnitId:d,range:p},T=ua(b,r),U=r.getCellMatrix().getSlice(p.startRow,p.endRow,0,r.getColumnCount()-1),k={unitId:u,subUnitId:d,cellValue:U.getMatrix()};y.push({id:ae.id,params:b}),w.push({id:re.id,params:T}),w.push({id:F.id,params:k}),h.push(...y),m.unshift(...w)});const R=a.onCommandExecute({id:hn,params:{range:l}}),C=s.get(i.ICommandService);if(i.sequenceExecute([...(v=R.preRedos)!=null?v:[],...h,...R.redos,Ue(l,o,r)],C).result){const p=a.afterCommandExecute({id:hn,params:{range:l}});return i.sequenceExecute(p.redos,C),s.get(i.IUndoRedoService).pushUndoRedo({unitID:u,undoMutations:[...(I=R.preUndos)!=null?I:[],...m,...R.undos,...p.undos],redoMutations:[...(M=R.preRedos)!=null?M:[],...h,...R.redos,...p.redos]}),!0}return!1}},$t={type:i.CommandType.COMMAND,id:hn,handler:async(s,e)=>{var h;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.ICommandService);let r=e==null?void 0:e.range;if(r||(r=(h=t.getCurrentLastSelection())==null?void 0:h.range),!r)return!1;const a=s.get(i.IUniverInstanceService),l=P(a);if(!l)return!1;const{worksheet:u,subUnitId:d,unitId:c}=l;return r={...r,startColumn:0,endColumn:Math.max(u.getMaxColumns()-1,0)},await n.beforeCommandExecute({id:$t.id,params:{range:r}})?o.syncExecuteCommand(Ms.id,{range:r,unitId:c,subUnitId:d}):!1}},gn="sheet.command.remove-col",ys={type:i.CommandType.COMMAND,id:"sheet.command.remove-col-by-range",handler:(s,e)=>{var I,M,p;if(!e)return!1;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{workbook:o,worksheet:r}=n,a=s.get(g.SheetInterceptorService),{range:l,unitId:u,subUnitId:d}=e,c={unitId:u,subUnitId:d,range:l},m=da(s,c),h=r.getCellMatrix().getSlice(0,r.getRowCount()-1,l.startColumn,l.endColumn),R={unitId:u,subUnitId:d,cellValue:h.getMatrix()},C=a.onCommandExecute({id:gn,params:{range:l}}),S=s.get(i.ICommandService);if(i.sequenceExecute([...(I=C.preRedos)!=null?I:[],{id:ne.id,params:c},...C.redos,Ue(l,o,r)],S).result){const w=a.afterCommandExecute({id:gn,params:{range:l}});return i.sequenceExecute(w.redos,S),s.get(i.IUndoRedoService).pushUndoRedo({unitID:u,undoMutations:[...(M=C.preUndos)!=null?M:[],{id:ie.id,params:m},{id:F.id,params:R},...C.undos,...w.undos],redoMutations:[...(p=C.preRedos)!=null?p:[],{id:ne.id,params:c},...C.redos,...w.redos]}),!0}return!1}},Lt={type:i.CommandType.COMMAND,id:gn,handler:async(s,e)=>{var h;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.ICommandService);let r=e==null?void 0:e.range;if(r||(r=(h=t.getCurrentLastSelection())==null?void 0:h.range),!r)return!1;const a=s.get(i.IUniverInstanceService),l=P(a);if(!l)return!1;const{worksheet:u,subUnitId:d,unitId:c}=l;return r={...r,startRow:0,endRow:Math.max(u.getMaxRows()-1,0)},await n.beforeCommandExecute({id:Lt.id,params:{range:r}})?o.syncExecuteCommand(ys.id,{range:r,unitId:c,subUnitId:d}):!1}},rr=(s,e)=>{const t=s.get(i.IUniverInstanceService),{subUnitId:n,unitId:o}=e,r=Ie(t,e);if(!r)throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!");const{workbook:a,worksheet:l}=r,u=l.getConfig();return{index:a.getConfig().sheetOrder.findIndex(m=>m===n),sheet:u,unitId:o}},Xe={id:"sheet.mutation.remove-sheet",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),{subUnitId:n,unitId:o}=e,r=t.getUniverSheetInstance(o);return r?r.removeSheet(n):!1}};function fl(s,e){return e.getMergeData().some(t=>t.startRow<s&&s<=t.endRow)}function vl(s,e){return e.getMergeData().some(t=>t.startColumn<s&&s<=t.endColumn)}const ir="sheet.command.move-rows",pt={id:ir,type:i.CommandType.COMMAND,handler:(s,e)=>{var W,V;const t=s.get(g.SheetsSelectionsService),{fromRange:{startRow:n},toRange:{startRow:o},range:r}=e,a=r?[lr(r)]:t.getCurrentSelections(),l=a==null?void 0:a.filter($=>$.range.rangeType===i.RANGE_TYPE.ROW&&$.range.startRow<=n&&n<=$.range.endRow);if((l==null?void 0:l.length)!==1)return!1;const u=s.get(g.SheetInterceptorService),d=s.get(i.IUniverInstanceService),c=P(d,e);if(!c)return!1;const{workbook:m,worksheet:h}=c,R=m.getUnitId(),C=h.getSheetId(),S=s.get(i.ErrorService),v=s.get(i.LocaleService),I=l[0].range,M=l[0].primary,p=At(I,h,!1);if(!i.Rectangle.equals(I,p))return S.emit(v.t("sheets.info.partOfCell")),!1;if(fl(o,h))return S.emit(v.t("sheets.info.acrossMergedCell")),!1;const w={...I,startRow:o,endRow:o+I.endRow-I.startRow},y={unitId:R,subUnitId:C,sourceRange:I,targetRange:w},b=lo(s,y),T=s.get(i.ICommandService),U=u.onCommandExecute({id:pt.id,params:e}),k=[...(W=U.preRedos)!=null?W:[],{id:pe.id,params:y}],E=[...(V=U.preUndos)!=null?V:[],{id:pe.id,params:b}];if(M){const L=o-n<0,Y=I.endRow-I.startRow+1,z=L?w:{...w,startRow:w.startRow-Y,endRow:w.endRow-Y},K={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:z,primary:se(z,h),style:null}]},oe={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:I,primary:M,style:null}]};k.push({id:q.id,params:K}),E.push({id:q.id,params:oe})}if(k.push(...U.redos),E.push(...U.undos),i.sequenceExecute(k,T).result){const $=u.afterCommandExecute({id:pt.id,params:e});return i.sequenceExecute($.redos,T),k.push(...$.redos),E.push(...$.undos),s.get(i.IUndoRedoService).pushUndoRedo({unitID:R,undoMutations:E,redoMutations:k}),!0}return!1}},ar="sheet.command.move-cols",wt={id:ar,type:i.CommandType.COMMAND,handler:(s,e)=>{var W,V;const t=s.get(g.SheetsSelectionsService),{fromRange:{startColumn:n},toRange:{startColumn:o},range:r}=e,a=r?[lr(r)]:t.getCurrentSelections(),l=a==null?void 0:a.filter($=>$.range.rangeType===i.RANGE_TYPE.COLUMN&&$.range.startColumn<=n&&n<=$.range.endColumn);if((l==null?void 0:l.length)!==1)return!1;const u=s.get(g.SheetInterceptorService),d=s.get(i.IUniverInstanceService),c=P(d,e);if(!c)return!1;const{workbook:m,worksheet:h}=c,R=m.getUnitId(),C=h.getSheetId(),S=s.get(i.ErrorService),v=s.get(i.LocaleService),I=l[0].range,M=l[0].primary,p=At(I,h,!1);if(!i.Rectangle.equals(I,p))return S.emit(v.t("sheets.info.partOfCell")),!1;if(vl(o,h))return S.emit(v.t("sheets.info.acrossMergedCell")),!1;const w={...I,startColumn:o,endColumn:o+I.endColumn-I.startColumn},y={unitId:R,subUnitId:C,sourceRange:I,targetRange:w},b=uo(s,y),T=s.get(i.ICommandService),U=u.onCommandExecute({id:wt.id,params:e}),k=[...(W=U.preRedos)!=null?W:[],{id:we.id,params:y}],E=[...(V=U.preUndos)!=null?V:[],{id:we.id,params:b}];if(M){const $=I.endColumn-I.startColumn+1,z=o-n<0?w:{...w,startColumn:w.startColumn-$,endColumn:w.endColumn-$},K={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:z,primary:se(z,h),style:null}]},oe={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:I,primary:M,style:null}]};k.push({id:q.id,params:K}),E.push({id:q.id,params:oe})}if(k.push(...U.redos),E.push(...U.undos),i.sequenceExecute(k,T).result){const $=u.afterCommandExecute({id:wt.id,params:e});return i.sequenceExecute($.redos,T),k.push(...$.redos),E.push(...$.undos),s.get(i.IUndoRedoService).pushUndoRedo({unitID:R,undoMutations:E,redoMutations:k}),!0}return!1}};function lr(s){return{range:s,primary:null,style:null}}var Il=Object.getOwnPropertyDescriptor,pl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Il(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},wl=(s,e)=>(t,n)=>e(t,n,s);g.SheetSkeletonService=class extends i.Disposable{constructor(t){super();f(this,"_sheetSkeletonStore",new Map);this._injector=t,this.disposeWithMe(()=>{this._sheetSkeletonStore=new Map})}getSkeleton(t,n){if(this._sheetSkeletonStore.has(t))return this._sheetSkeletonStore.get(t).get(n)}setSkeleton(t,n,o){this._sheetSkeletonStore.has(t)||this._sheetSkeletonStore.set(t,new Map),this._sheetSkeletonStore.get(t).set(n,o)}deleteSkeleton(t,n){this._sheetSkeletonStore.has(t)&&this._sheetSkeletonStore.get(t).delete(n)}},g.SheetSkeletonService=pl([wl(0,i.Inject(i.Injector))],g.SheetSkeletonService);function _s(s,e){const t=new i.ObjectMatrix;return s.map(n=>i.Range.transformRange(n,e)).forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=e.getCellHeight(o,r);a&&t.setValue(o,r,a)})}),t}const Ml=1e4;function Ht(s,e){if(!e)return{suitableRanges:s,remainingRanges:[]};const t=e.worksheet.getColumnCount(),n=Math.ceil(Ml/t),o=[],r=[],a=e.getOffsetRelativeToRowCol(0,e.scrollY).row,l=s.map(d=>{let c;return a>=d.startRow&&a<=d.endRow?c=0:a<d.startRow?c=d.startRow-a:c=a-d.endRow,{range:d,distance:c,rowCount:d.endRow-d.startRow+1}});l.sort((d,c)=>d.distance!==c.distance?d.distance-c.distance:d.rowCount-c.rowCount);let u=0;for(const d of l)if(u+d.rowCount<=n)o.push(d.range),u+=d.rowCount;else{const c=n-u;if(c>0){const m={...d.range,endRow:d.range.startRow+c-1},h={...d.range,startRow:d.range.startRow+c};o.push(m),r.push(h),u=n}else r.push(d.range)}return{suitableRanges:o,remainingRanges:r}}const ur="sheet.command.reorder-range",Rn={id:ur,type:i.CommandType.COMMAND,handler:(s,e)=>{var p,w;const{subUnitId:t,unitId:n,range:o,order:r}=e,a=s.get(i.ICommandService),l={id:Dt.id,params:{unitId:n,subUnitId:t,order:r,range:o}},u={id:Dt.id,params:co(l.params)},d=s.get(g.SheetInterceptorService),c=d.onCommandExecute({id:Rn.id,params:e}),m=[...(p=c.preRedos)!=null?p:[],l,...c.redos],h=[...(w=c.preUndos)!=null?w:[],u,...c.undos],R=i.sequenceExecute(m,a),{suitableRanges:C,remainingRanges:S}=Ht([o],s.get(g.SheetSkeletonService).getSkeleton(n,t)),{undos:v,redos:I}=d.generateMutationsOfAutoHeight({unitId:n,subUnitId:t,ranges:[o],autoHeightRanges:C,lazyAutoHeightRanges:S}),M=d.afterCommandExecute({id:Rn.id,params:e});return R.result?(i.sequenceExecute([...M.redos,...I],a),s.get(i.IUndoRedoService).pushUndoRedo({unitID:n,undoMutations:[...h,...M.undos,...v],redoMutations:[...m,...M.redos,...I]}),!0):!1}},A={MoveRangeCommandId:Ho,InsertRowCommandId:Jo,InsertColCommandId:er,RemoveColCommandId:gn,RemoveRowCommandId:hn,DeleteRangeMoveLeftCommandId:Yo,DeleteRangeMoveUpCommandId:Ko,InsertRangeMoveDownCommandId:Sl,InsertRangeMoveRightCommandId:Is,MoveColsCommandId:ar,MoveRowsCommandId:ir,ReorderRangeCommandId:ur};var H=(s=>(s[s.Set=0]="Set",s[s.Delete=1]="Delete",s[s.HorizontalMove=2]="HorizontalMove",s[s.VerticalMove=3]="VerticalMove",s[s.Unknown=4]="Unknown",s))(H||{});const Cn=Number.MAX_SAFE_INTEGER,Pe=s=>{const e={...s},t=Number.isNaN(e.startRow)&&Number.isNaN(e.endRow)&&!Number.isNaN(e.startColumn)&&!Number.isNaN(e.endColumn),n=Number.isNaN(e.startColumn)&&Number.isNaN(e.endColumn)&&!Number.isNaN(e.startRow)&&!Number.isNaN(e.endRow);return(e.rangeType===i.RANGE_TYPE.COLUMN||t)&&(e.startRow=0,e.endRow=Cn),(e.rangeType===i.RANGE_TYPE.ROW||n)&&(e.startColumn=0,e.endColumn=Cn),e.rangeType===i.RANGE_TYPE.ALL&&(e.startColumn=0,e.endColumn=Cn,e.startRow=0,e.endRow=Cn),e},he=s=>{let e=s.rangeType;return s.rangeType===i.RANGE_TYPE.COLUMN?e=i.RANGE_TYPE.ROW:s.rangeType===i.RANGE_TYPE.ROW&&(e=i.RANGE_TYPE.COLUMN),{startRow:s.startColumn,endRow:s.endColumn,startColumn:s.startRow,endColumn:s.endRow,rangeType:e}},Bt=(s,e,t)=>{const n={...t},o={...e},r=(S,v)=>{const I=Math.max(S.start,v.start),M=Math.min(S.end,v.end);return M<I?null:{start:I,end:M}},a=S=>S.end-S.start+1,l=(S,v)=>({start:S.start-v.start,end:S.start-v.start+S.end-S.start}),u=(S,v)=>({start:v.start+S.start,end:v.start+S.start+S.end-S.start}),d=e.start>s.start;if(d){const S=Math.min(s.end,e.start)-s.start+1;o.start-=S,o.end-=S}const c=a(s),m=c,h=r(s,n),R=h&&a(h)>=a(n);if(s.end<n.start)n.start-=c,n.end-=c;else if(h){const S=a(h);if(R){const v=l(n,s),I=u(v,o);n.start=I.start,n.end=I.end}else h.start>s.start?d?(n.end-=S+c,n.start-=c):n.end-=S:d?n.end-=S:n.start>s.start&&n.end>s.end?(n.start-=c,n.end-=c+S):n.end-=S}const C=r(o,n);return R||(o.start<=n.start?(n.start+=m,n.end+=m):C&&(d?o.end<=n.start||o.start<=n.start&&o.end>=n.start?(n.start+=m,n.end+=m):o.start>=n.start&&o.start<=n.end&&(n.end+=m):n.start<o.start&&n.end>o.start?n.end+=m:(n.start>=o.end||n.start>=o.start&&n.start<=o.end)&&(n.end+=m,n.start+=m))),{step:n.start-t.start,length:a(n)-a(t)}},bs=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!n||!t)return[];const o=Pe(t),r=Pe(n),a=Pe(e),l=Bt({start:o.startRow,end:o.endRow},{start:r.startRow,end:r.endRow},{start:a.startRow,end:a.endRow});return l===null?[{type:H.Delete}]:[{type:H.VerticalMove,step:l.step||0,length:l.length||0}]},yl=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!t||!n)return[e];const o=t.startRow,r=t.endRow-t.startRow+1,a=n.startRow,l=new i.ObjectMatrix;return i.Range.foreach(e,(d,c)=>{l.setValue(d,c,1)}),l.moveRows(o,r,a),i.queryObjectMatrix(l,d=>d===1)},_l=(s,e)=>{const{range:t,order:n}=s.params||{};if(!t||!n)return[e];const o=new i.ObjectMatrix;i.Range.foreach(e,(l,u)=>{o.setValue(l,u,1)});const r=new i.ObjectMatrix;return i.Range.foreach(t,(l,u)=>{var d;if(Object.prototype.hasOwnProperty.call(n,l)){const c=n[l],m=(d=o.getValue(c,u))!=null?d:0;r.setValue(l,u,m)}}),r.forValue((l,u,d)=>{o.setValue(l,u,d)}),i.queryObjectMatrix(o,l=>l===1)},Es=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!n||!t)return[];const o=Pe(t),r=Pe(n),a=Pe(e),l=Bt({start:o.startColumn,end:o.endColumn},{start:r.startColumn,end:r.endColumn},{start:a.startColumn,end:a.endColumn});return l===null?[{type:H.Delete}]:[{type:H.HorizontalMove,step:l.step||0,length:l.length||0}]},bl=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!t||!n)return[e];const o=t.startColumn,r=t.endColumn-t.startColumn+1,a=n.startColumn,l=new i.ObjectMatrix;return i.Range.foreach(e,(u,d)=>{l.setValue(u,d,1)}),l.moveColumns(o,r,a),i.queryObjectMatrix(l,u=>u===1)},dr=(s,e)=>{var r,a;const t=(r=s.params)==null?void 0:r.toRange,n=(a=s.params)==null?void 0:a.fromRange;if(!t||!n)return[];const o=[];if(i.Rectangle.contains(t,e)&&o.push({type:H.Delete}),i.Rectangle.contains(n,e)){o.push({type:H.Delete});const l=i.Rectangle.getRelativeRange(e,n),u=i.Rectangle.getPositionRange(l,t);return[{type:H.Set,range:u}]}return o},El=(s,e)=>{var m,h;const t=(m=s.params)==null?void 0:m.toRange,n=(h=s.params)==null?void 0:h.fromRange;if(!t||!n)return[e];if(!i.Rectangle.intersects(n,e)&&!i.Rectangle.intersects(t,e))return[e];if(i.Rectangle.contains(n,e)){const R=i.Rectangle.getRelativeRange(e,n);return[i.Rectangle.getPositionRange(R,t)]}const o=new i.ObjectMatrix;i.Range.foreach(e,(R,C)=>{o.setValue(R,C,1)});const r=new i.ObjectMatrix,a=i.Rectangle.getIntersects(n,e);a&&i.Range.foreach(a,(R,C)=>{o.getValue(R,C)&&(o.setValue(R,C,void 0),r.setValue(R,C,1))});const l=t.startColumn-n.startColumn,u=t.startRow-n.startRow,d={startColumn:t.startColumn-l,endColumn:t.endColumn-l,startRow:t.startRow-u,endRow:t.endRow-u};return d&&i.Range.foreach(d,(R,C)=>{var I;const S=R+u,v=C+l;o.setValue(S,v,(I=r.getValue(R,C))!=null?I:0)}),i.queryObjectMatrix(o,R=>R===1)},Ze=(s,e)=>{const t=Pe(s),n=Pe(e),o=a=>a.endColumn-a.startColumn+1,r=a=>a.endRow-a.startRow+1;if(t.startRow<=n.startRow&&t.endRow>=n.endRow){if(n.startColumn<t.startColumn&&n.endColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn<t.startColumn&&n.endColumn>=t.endColumn){const a=i.Rectangle.getIntersects(n,t);if(a)return{step:0,length:-o(a)}}if(n.startColumn>=t.startColumn&&n.endColumn<=t.endColumn&&r(t)>=r(n))return null;if(n.startColumn>=t.startColumn&&n.startColumn<=t.endColumn&&n.endColumn>t.endColumn){const a=i.Rectangle.getIntersects(n,t);if(a){const l=-o(a);return{step:-(o(t)-o(a)),length:l}}}if(n.startColumn>t.endColumn)return{step:-o(t),length:0}}return{step:0,length:0}},Ts=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(t,e);if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.HorizontalMove,step:a,length:l})}return n},cr=(s,e,t)=>{var a;const n=(a=s.params)==null?void 0:a.range;if(!n)return[];const o=[];if(t&&t.length>0){let l=n.startRow;for(let u=n.startRow;u<=n.endRow;u++){if(t.includes(u)){if(u===l){l=u+1;continue}r({...n,startRow:l,endRow:u-1}),l=u+1;continue}u===n.endRow&&r({...n,startRow:l,endRow:n.endRow})}}else r(n);function r(l){const u=Ze(he(l),he(e));if(!u)o.push({type:H.Delete});else{const{step:d,length:c}=u;o.push({type:H.VerticalMove,step:d,length:c})}}return o},Tl=(s,e)=>{const{range:t,order:n}=s.params||{};if(!t||!n)return[];if(i.Rectangle.contains(t,e)&&e.endRow===e.startRow){const o=[],r=e.startRow;for(const a in n)if(n[a]===r){const l=Number(a);return o.push({type:H.VerticalMove,step:l-r,length:0}),o}return[]}return[]},Qe=(s,e)=>{const t=Pe(s),n=Pe(e),o=r=>r.endColumn-r.startColumn+1;return t.startRow<=n.startRow&&t.endRow>=n.endRow?n.startColumn<t.startColumn&&n.endColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn<t.startColumn&&n.endColumn>=t.endColumn?{step:0,length:o(t)}:n.startColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn>=t.startColumn&&n.startColumn<=t.endColumn&&n.endColumn>t.endColumn||n.startColumn>=t.endColumn?{step:o(t),length:0}:{step:0,length:0}:{step:0,length:0}};function Ul(s,e,t){const n=[];if(i.Rectangle.contains(e,t)&&n.push({type:H.Delete}),i.Rectangle.contains(s,t)){n.push({type:H.Delete});const o=i.Rectangle.getRelativeRange(t,s),r=i.Rectangle.getPositionRange(o,e);return[{type:H.Set,range:r}]}return n}const mr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(he(t),he(e)),{step:r,length:a}=o;return n.push({type:H.VerticalMove,step:r,length:a}),n},hr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(t,e),{step:r,length:a}=o;return n.push({type:H.HorizontalMove,step:r,length:a}),n},gr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(he(t),he(e)),{step:r,length:a}=o;return n.push({type:H.VerticalMove,step:r,length:a}),n},Pl=(s,e)=>{var u;const t=(u=s.params)==null?void 0:u.range;if(!t)return[e];const n=t.endRow-t.startRow+1,o={...t,startRow:t.startRow,endRow:Number.POSITIVE_INFINITY},r=i.Rectangle.subtract(e,o),a=i.Rectangle.getIntersects(o,e);if(!a)return[e];const l=new i.ObjectMatrix;return r.forEach(d=>{i.Range.foreach(d,(c,m)=>{l.setValue(c,m,1)})}),a&&i.Range.foreach(a,(d,c)=>{l.setValue(d+n,c,1)}),i.queryObjectMatrix(l,d=>d===1)},Rr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(t,e),{step:r,length:a}=o;return n.push({type:H.HorizontalMove,step:r,length:a}),n},kl=(s,e)=>{var u;const t=(u=s.params)==null?void 0:u.range;if(!t)return[e];const n=t.endColumn-t.startColumn+1,o={...t,startColumn:t.startColumn,endColumn:Number.POSITIVE_INFINITY},r=i.Rectangle.subtract(e,o),a=i.Rectangle.getIntersects(o,e);if(!a)return[e];const l=new i.ObjectMatrix;return r.forEach(d=>{i.Range.foreach(d,(c,m)=>{l.setValue(c,m,1)})}),a&&i.Range.foreach(a,(d,c)=>{l.setValue(d,c+n,1)}),i.queryObjectMatrix(l,d=>d===1)},Cr=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(t,e);if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.HorizontalMove,step:a,length:l})}return n},Ol=(s,e)=>{var d;const t=(d=s.params)==null?void 0:d.range;if(!t)return[e];const n={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:Number.POSITIVE_INFINITY},o=t.endColumn-t.startColumn+1,r=i.Rectangle.getIntersects(t,e),a=i.Rectangle.subtract(e,n),l=i.Rectangle.getIntersects(n,e);if(!r&&!l)return[e];const u=new i.ObjectMatrix;return l&&i.Range.foreach(l,(c,m)=>{u.setValue(c,m-o,1)}),r&&i.Range.foreach(r,(c,m)=>{u.setValue(c,m-o,0)}),a.forEach(c=>{i.Range.foreach(c,(m,h)=>{u.setValue(m,h,1)})}),i.queryObjectMatrix(u,c=>c===1)},Sr=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(he(t),he(e));if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.VerticalMove,step:a,length:l})}return n},Dl=(s,e)=>{var d;const t=(d=s.params)==null?void 0:d.range;if(!t)return[e];const n={...t,startRow:t.startRow,endRow:Number.POSITIVE_INFINITY},o=t.endRow-t.startRow+1,r=i.Rectangle.getIntersects(t,e),a=i.Rectangle.subtract(e,n),l=i.Rectangle.getIntersects(n,e);if(!r&&!l)return[e];const u=new i.ObjectMatrix;return l&&i.Range.foreach(l,(c,m)=>{u.setValue(c-o,m,1)}),r&&i.Range.foreach(r,(c,m)=>{u.setValue(c-o,m,0)}),a.forEach(c=>{i.Range.foreach(c,(m,h)=>{u.setValue(m,h,1)})}),i.queryObjectMatrix(u,c=>c===1)},Nl=(s,e)=>{var o;const t=(o=s.ranges)!=null?o:[s.range],n=new i.ObjectMatrix;return i.Range.foreach(e,(r,a)=>{n.setValue(r,a,1)}),t.forEach(r=>{const a=r.startRow,u=r.endRow-a+1;n.removeRows(a,u)}),i.queryObjectMatrix(n,r=>r===1)},Al=(s,e)=>{const t=s.params,n=t.range.startRow,o=t.range.endRow-t.range.startRow+1;return e.startRow>=n?[{startRow:e.startRow+o,endRow:e.endRow+o,startColumn:e.startColumn,endColumn:e.endColumn}]:e.endRow<n?[e]:[{startRow:e.startRow,endRow:e.endRow+o,startColumn:e.startColumn,endColumn:e.endColumn}]},Wl=(s,e)=>{const t=s.params,n=t.range.startColumn,o=t.range.endColumn-t.range.startColumn+1;return e.startColumn>=n?[{startRow:e.startRow,endRow:e.endRow,startColumn:e.startColumn+o,endColumn:e.endColumn+o}]:e.endColumn<n?[e]:[{startRow:e.startRow,endRow:e.endRow,startColumn:e.startColumn,endColumn:e.endColumn+o}]},et=(s,e)=>{let t={...e};return s.forEach(n=>{switch(n.type){case H.Delete:{t=null;break}case H.HorizontalMove:{if(!t)return;t.startColumn+=n.step,t.endColumn+=n.step+(n.length||0);break}case H.VerticalMove:{if(!t)return;t.startRow+=n.step,t.endRow+=n.step+(n.length||0);break}case H.Set:{t=n.range;break}}}),t&&(t.endColumn<t.startColumn||t.endRow<t.startRow)?null:t},Us=(s,e)=>{let t=[];switch(e.id){case A.DeleteRangeMoveLeftCommandId:{t=Cr(e,s);break}case A.DeleteRangeMoveUpCommandId:{t=Sr(e,s);break}case A.InsertColCommandId:{t=hr(e,s);break}case A.InsertRangeMoveDownCommandId:{t=gr(e,s);break}case A.InsertRangeMoveRightCommandId:{t=Rr(e,s);break}case A.InsertRowCommandId:{t=mr(e,s);break}case A.MoveColsCommandId:{t=Es(e,s);break}case A.MoveRangeCommandId:{t=dr(e,s);break}case A.MoveRowsCommandId:{t=bs(e,s);break}case A.RemoveColCommandId:{t=Ts(e,s);break}case A.RemoveRowCommandId:{t=cr(e,s);break}case A.ReorderRangeCommandId:{t=Tl(e,s);break}}return et(t,s)},Vl=(s,e,t)=>[He.id,Be.id].includes(e.id)||vr(e,t).some(r=>i.Rectangle.intersects(r,s))?Us(s,e):s,Ps=(s,e)=>{let t=[];switch(e.id){case A.DeleteRangeMoveLeftCommandId:return Ol(e,s);case A.DeleteRangeMoveUpCommandId:return Dl(e,s);case A.InsertRangeMoveDownCommandId:return Pl(e,s);case A.InsertRangeMoveRightCommandId:return kl(e,s);case A.InsertColCommandId:return Wl(e,s);case A.InsertRowCommandId:return Al(e,s);case A.MoveColsCommandId:return bl(e,s);case A.MoveRangeCommandId:return El(e,s);case A.MoveRowsCommandId:return yl(e,s);case A.ReorderRangeCommandId:return _l(e,s);case A.RemoveColCommandId:{t=Ts(e,s);break}case A.RemoveRowCommandId:return Nl(e.params,s)}const n=et(t,s);return n?[n]:[]},$l=(s,e,t)=>[He.id,Be.id,xe.id,Is].includes(e.id)||vr(e,t).some(r=>i.Rectangle.intersects(r,s))?Ps(s,e):s;function fr(s,e){const{id:t,params:n}=e;let o={length:0,step:0,type:H.Unknown};switch(t){case Xe.id:o.type=H.Delete;break;case pe.id:o=Bt({start:n.sourceRange.startRow,end:n.sourceRange.endRow},{start:n.targetRange.startRow,end:n.targetRange.endRow},{start:s.startRow,end:s.endRow}),o.type=H.VerticalMove;break;case we.id:o=Bt({start:n.sourceRange.startColumn,end:n.sourceRange.endColumn},{start:n.targetRange.startColumn,end:n.targetRange.endColumn},{start:s.startColumn,end:s.endColumn}),o.type=H.HorizontalMove;break;case ne.id:o=Ze(n.range,s),o?o.type=H.HorizontalMove:o={step:0,length:0,type:H.Delete};break;case ae.id:o=Ze(he(n.range),he(s)),o?o.type=H.VerticalMove:o={step:0,length:0,type:H.Delete};break;case re.id:o=Qe(he(n.range),he(s)),o.type=H.VerticalMove;break;case ie.id:o=Qe(n.range,s),o.type=H.HorizontalMove;break;case Le.id:{const r=n.fromRange||new i.ObjectMatrix(n.from).getRange(),a=n.toRange||new i.ObjectMatrix(n.to).getRange();o=Ul(r,a,s)}break}return o?Array.isArray(o)?et(o,s):et([o],s):s}function vr(s,e){var n,o,r,a,l,u;const{selectionManagerService:t}=e;switch(s.id){case A.MoveColsCommandId:{const d=s.params;return[d.fromRange,{...d.toRange,startColumn:d.toRange.startColumn-.5,endColumn:d.toRange.endColumn-.5}]}case A.MoveRowsCommandId:{const d=s.params;return[d.fromRange,{...d.toRange,startRow:d.toRange.startRow-.5,endRow:d.toRange.startRow-.5}]}case A.MoveRangeCommandId:{const d=s;return[d.params.fromRange,d.params.toRange]}case A.InsertRowCommandId:{const c=s.params.range;return[{...c,startRow:c.startRow-.5,endRow:c.endRow-.5}]}case A.InsertColCommandId:{const c=s.params.range;return[{...c,startColumn:c.startColumn-.5,endColumn:c.endColumn-.5}]}case A.RemoveRowCommandId:return[s.params.range];case A.RemoveColCommandId:return[s.params.range];case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const c=((n=s.params)==null?void 0:n.range)||((r=(o=t.getCurrentSelections())==null?void 0:o.map(m=>m.range))==null?void 0:r[0]);return c?[c]:[]}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const c=((a=s.params)==null?void 0:a.range)||((u=(l=t.getCurrentSelections())==null?void 0:l.map(m=>m.range))==null?void 0:u[0]);return c?[c]:[]}case A.ReorderRangeCommandId:{const d=s,{range:c,order:m}=d.params,h=[];for(let R=c.startRow;R<=c.endRow;R++)R in m&&h.push({startRow:R,endRow:R,startColumn:c.startColumn,endColumn:c.endColumn});return h}}}function Ll(s){switch(s.id){case we.id:{const e=s.params;return[e.sourceRange,{...e.targetRange,startColumn:e.targetRange.startColumn-.5,endColumn:e.targetRange.startColumn-.5}]}case pe.id:{const e=s.params;return[e.sourceRange,{...e.targetRange,startRow:e.targetRange.startRow-.5,endRow:e.targetRange.startRow-.5}]}case Le.id:{const e=s.params;return[new i.ObjectMatrix(e.from.value).getRange(),new i.ObjectMatrix(e.to.value).getRange()]}case ie.id:{const t=s.params.range;return[{...t,startColumn:t.startColumn-.5,endColumn:t.startColumn-.5}]}case re.id:{const t=s.params.range;return[{...t,startRow:t.startRow-.5,endRow:t.startRow-.5}]}case ne.id:return[s.params.range];case ae.id:return[s.params.range]}}function Hl(s,e){var o,r,a,l,u,d;const t=s.get(i.IUniverInstanceService),n=s.get(g.SheetsSelectionsService);switch(e.id){case A.MoveColsCommandId:{const c=e.params,m=P(t,{unitId:c.unitId,subUnitId:c.subUnitId});return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,{...c.toRange,startColumn:c.fromRange.startColumn<c.toRange.startColumn?c.fromRange.endColumn+1:c.toRange.startColumn,endColumn:c.fromRange.startColumn<c.toRange.startColumn?c.toRange.endColumn-1:c.fromRange.startColumn-1}]}}case A.MoveRowsCommandId:{const c=e.params,m=P(t,{unitId:c.unitId,subUnitId:c.subUnitId});return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,{...c.toRange,startRow:c.fromRange.startRow<c.toRange.startRow?c.fromRange.endRow+1:c.toRange.startRow,endRow:c.fromRange.startRow<c.toRange.startRow?c.toRange.endRow-1:c.fromRange.startRow-1}]}}case A.MoveRangeCommandId:{const c=e.params,m=P(t);return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,c.toRange]}}case A.InsertRowCommandId:{const c=e.params,m=c.range;return{unitId:c.unitId,subUnitId:c.subUnitId,ranges:[...m.startRow>0?[{...m,startRow:m.startRow-1,endRow:m.endRow-1}]:[],{...m,startRow:m.startRow,endRow:Number.MAX_SAFE_INTEGER}]}}case A.InsertColCommandId:{const c=e.params,m=c.range;return{unitId:c.unitId,subUnitId:c.subUnitId,ranges:[...m.startColumn>0?[{...m,startColumn:m.startColumn-1,endColumn:m.endColumn-1}]:[],{...m,startColumn:m.startColumn,endColumn:Number.MAX_SAFE_INTEGER}]}}case A.RemoveRowCommandId:{const m=e.params.range,h=P(t);return{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startRow:m.endRow+1,endRow:Number.MAX_SAFE_INTEGER}]}}case A.RemoveColCommandId:{const m=e.params.range,h=P(t);return{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startColumn:m.endColumn+1,endColumn:Number.MAX_SAFE_INTEGER}]}}case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const c=e,m=P(t),h=((o=c.params)==null?void 0:o.range)||((a=(r=n.getCurrentSelections())==null?void 0:r.map(R=>R.range))==null?void 0:a[0]);return h?{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[h,{...h,startRow:h.endRow+1,endRow:Number.MAX_SAFE_INTEGER}]}:{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[]}}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const m=((l=e.params)==null?void 0:l.range)||((d=(u=n.getCurrentSelections())==null?void 0:u.map(R=>R.range))==null?void 0:d[0]),h=P(t);return m?{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startColumn:m.endColumn+1,endColumn:Number.MAX_SAFE_INTEGER}]}:{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[]}}case A.ReorderRangeCommandId:{const c=e,{range:m,order:h}=c.params,R=[];for(let S=m.startRow;S<=m.endRow;S++)S in h&&R.push({startRow:S,endRow:S,startColumn:m.startColumn,endColumn:m.endColumn});const C=P(t);return{unitId:C.unitId,subUnitId:C.subUnitId,ranges:R}}}}var Bl=Object.getOwnPropertyDescriptor,Fl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Bl(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Sn=(s,e)=>(t,n)=>e(t,n,s);const jl=i.createInterceptorKey("MERGE_REDO"),Gl=i.createInterceptorKey("MERGE_UNDO"),Ir=Math.floor(Number.MAX_SAFE_INTEGER/10);class zl extends i.Disposable{constructor(e,t,n,o,r=!1){super(),this._unitId=e,this._subUnitId=t,this._range=n,this._callback=o,this._skipIntersects=r}onMutation(e){var o,r;if(((o=e.params)==null?void 0:o.unitId)!==this._unitId)return;if(e.id===Le.id){const a=e.params;if(a.from.subUnitId!==this._subUnitId||a.to.subUnitId!==this._subUnitId)return}else if(((r=e.params)==null?void 0:r.subUnitId)!==this._subUnitId)return;if(!this._range)return;if(this._skipIntersects){if(e.id===Xe.id)return;const a=Ll(e);if(a!=null&&a.some(l=>i.Rectangle.intersects(l,this._range)))return}const t=fr(this._range,e);if(t&&i.Rectangle.equals(t,this._range))return!1;const n=this._range;this._range=t,this._callback(n,t)}}g.RefRangeService=class extends i.Disposable{constructor(t,n,o,r){super();f(this,"interceptor",new i.InterceptorManager({MERGE_REDO:jl,MERGE_UNDO:Gl}));f(this,"_watchRanges",new Set);f(this,"_refRangeManagerMap",new Map);f(this,"_serializer",ql());f(this,"_onRefRangeChange",()=>{this._sheetInterceptorService.interceptCommand({getMutations:t=>{const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),o=pr(this._univerInstanceService),r=wr(this._univerInstanceService);if(!n||!o||!r)return{redos:[],undos:[],preRedos:[],preUndos:[]};const u=((()=>{switch(t.id){case A.MoveColsCommandId:{const R=t.params,C=Math.min(R.fromRange.startColumn,R.toRange.startColumn);return this._checkRange([{...R.fromRange,startColumn:C,endColumn:n.getColumnCount()-1}],o,r)}case A.MoveRowsCommandId:{const R=t.params,C=Math.min(R.fromRange.startRow,R.toRange.startRow);return this._checkRange([{...R.fromRange,startRow:C,endRow:n.getRowCount()-1}],o,r)}case A.MoveRangeCommandId:{const R=t;return this._checkRange([R.params.fromRange,R.params.toRange],o,r)}case A.InsertRowCommandId:{const S={startRow:t.params.range.startRow,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._checkRange([S],o,r)}case A.InsertColCommandId:{const C=t.params.range.startColumn,S={startRow:0,endRow:n.getRowCount()-1,startColumn:C,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.COLUMN};return this._checkRange([S],o,r)}case A.RemoveRowCommandId:{const S={startRow:t.params.range.startRow,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._checkRange([S],o,r)}case A.RemoveColCommandId:{const C=t.params.range.startColumn,S={startRow:0,endRow:n.getRowCount()-1,startColumn:C,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.COLUMN};return this._checkRange([S],o,r)}case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const C=t.params.range||Mr(this._selectionManagerService)[0],S={startRow:C.startRow,startColumn:C.startColumn,endColumn:C.endColumn,endRow:Ir};return this._checkRange([S],o,r)}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const C=t.params.range||Mr(this._selectionManagerService)[0],S={startRow:C.startRow,startColumn:C.startColumn,endColumn:Ir,endRow:C.endRow};return this._checkRange([S],o,r)}case A.ReorderRangeCommandId:{const R=t,{range:C,order:S}=R.params,v=[];for(let I=C.startRow;I<=C.endRow;I++)I in S&&v.push({startRow:I,endRow:I,startColumn:C.startColumn,endColumn:C.endColumn});return this._checkRange(v,o,r)}}})()||[]).reduce((R,C)=>{const S=C(t);return R.push(S),R},[]).reduce((R,C)=>{var S,v;return R.redos.push(...C.redos),R.undos.push(...C.undos),R.preRedos.push(...(S=C.preRedos)!=null?S:[]),R.preUndos.push(...(v=C.preUndos)!=null?v:[]),R},{redos:[],undos:[],preUndos:[],preRedos:[]}),d=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(u.preRedos,null)||[],c=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(u.redos,null)||[],m=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(u.preUndos,null)||[],h=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(u.undos,null)||[];return{redos:c,undos:h,preRedos:d,preUndos:m}}})});f(this,"_checkRange",(t,n,o)=>{const r=yr(n,o),a=this._refRangeManagerMap.get(r);if(a){const l=new Set;return[...a.keys()].forEach(d=>{const c=a.get(d),m=this._serializer.deserialize(d),h={...m,startRow:+m.startRow,endRow:+m.endRow,startColumn:+m.startColumn,endColumn:+m.endColumn,rangeType:m.rangeType&&+m.rangeType};t.some(R=>i.Rectangle.intersects(R,h))&&c&&c.forEach(R=>{l.add(R)})}),[...l]}return[]});f(this,"registerRefRange",(t,n,o,r)=>{const a=o||pr(this._univerInstanceService),l=r||wr(this._univerInstanceService);if(!a||!l)return i.toDisposable(()=>{});const u=yr(a,l),d=this._serializer.serialize(t);let c=this._refRangeManagerMap.get(u);c||(c=new Map,this._refRangeManagerMap.set(u,c));const m=c.get(d);return m?m.add(n):c.set(d,new Set([n])),i.toDisposable(()=>{const h=c.get(d);h&&(h.delete(n),h.size||(c.delete(d),c.size||this._refRangeManagerMap.delete(u)))})});this._commandService=t,this._sheetInterceptorService=n,this._univerInstanceService=o,this._selectionManagerService=r,this._onRefRangeChange(),this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO,{priority:-1,handler:a=>a}),this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO,{priority:-1,handler:a=>a})}watchRange(t,n,o,r,a){let l;this._watchRanges.size===0&&(l=this._commandService.onCommandExecuted(m=>{if(m.type!==i.CommandType.MUTATION)return!1;for(const h of this._watchRanges)h.onMutation(m)}));const u=new zl(t,n,o,r,a);this._watchRanges.add(u);const d=i.toDisposable(()=>{this._watchRanges.delete(u),this._watchRanges.size===0&&(l==null||l.dispose(),l=null)}),c=this.disposeWithMe(d);return i.toDisposable(()=>{c.dispose(),d.dispose()})}},g.RefRangeService=Fl([Sn(0,i.ICommandService),Sn(1,i.Inject(g.SheetInterceptorService)),Sn(2,i.Inject(i.IUniverInstanceService)),Sn(3,i.Inject(g.SheetsSelectionsService))],g.RefRangeService);function pr(s){return s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getUnitId()}function wr(s){var e;return(e=s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:e.getSheetId()}function Mr(s){var e;return((e=s.getCurrentSelections())==null?void 0:e.map(t=>t.range))||[]}function yr(s,e){return`${s}_${e}`}function ql(){const s=["startRow","startColumn","endRow","endColumn","rangeType"];return{deserialize:t=>{const n=s.reduce((r,a,l)=>(r[String(l)]=a,r),{});return t.split("_").reduce((r,a,l)=>{const u=String(l);return a&&n[u]&&(r[n[u]]=a),r},{})},serialize:t=>s.reduce((n,o,r)=>{const a=t[o];return a!==void 0?`${n}${r>0?"_":""}${a}`:`${n}`},"")}}var Yl=Object.getOwnPropertyDescriptor,Kl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Yl(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Mt=(s,e)=>(t,n)=>e(t,n,s);const Jl=[ie.id,re.id,ne.id,ae.id],xl=[pe.id,we.id];function ks(s,e){let t=s;if(e!==void 0){const n=[];for(let o=0;o<t.length;o++){const{startRow:r,endRow:a,startColumn:l,endColumn:u}=t[o];if(e===i.Dimension.ROWS)for(let d=r;d<=a;d++){const c={startRow:d,endRow:d,startColumn:l,endColumn:u};n.push(c)}else if(e===i.Dimension.COLUMNS)for(let d=l;d<=u;d++){const c={startRow:r,endRow:a,startColumn:d,endColumn:d};n.push(c)}}t=n}return t}const _r=i.createInterceptorKey("mergeCellPermissionCheck");g.MergeCellController=class extends i.Disposable{constructor(t,n,o,r,a,l){super();f(this,"disposableCollection",new i.DisposableCollection);f(this,"interceptor",new i.InterceptorManager({MERGE_CELL_INTERCEPTOR_CHECK:_r}));this._commandService=t,this._refRangeService=n,this._univerInstanceService=o,this._injector=r,this._sheetInterceptorService=a,this._selectionManagerService=l,this._onRefRangeChange(),this._initCommandInterceptor(),this._commandExecutedListener()}_initCommandInterceptor(){const t=this;this._sheetInterceptorService.interceptCommand({getMutations(n){var o;switch(n.id){case sn.id:case on.id:{const r=t._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),a=r.getUnitId(),l=r==null?void 0:r.getActiveSheet();if(!l)return{redos:[],undos:[]};const u=l.getSheetId(),d=l.getConfig().mergeData,c=(o=t._selectionManagerService.getCurrentSelections())==null?void 0:o.map(m=>m.range);if(c&&c.length>0&&c.some(h=>d.some(R=>i.Rectangle.intersects(R,h)))){const h={unitId:a,subUnitId:u,ranges:c},R=le(t._injector,h),C=[{id:G.id,params:h}],S=[{id:j.id,params:R}];return{redos:C,undos:S}}}}return{redos:[],undos:[]}}}),this._sheetInterceptorService.interceptRanges({getMutations:({unitId:n,subUnitId:o,ranges:r})=>{const a=[],l=[],u={redos:a,undos:l};if(!r||!r.length)return u;const d=P(this._univerInstanceService,{unitId:n,subUnitId:o});if(!d)return u;const{worksheet:c}=d,h=c.getMergeData().filter(R=>r.some(C=>i.Rectangle.intersects(R,C)));return h.length?(a.push({id:G.id,params:{unitId:n,subUnitId:o,ranges:h}}),l.push({id:j.id,params:{unitId:n,subUnitId:o,ranges:h}}),{undos:l,redos:a}):u}})}refRangeHandle(t,n,o){switch(t.id){case A.MoveColsCommandId:{const r=t.params;return this._handleMoveColsCommand(r,n,o)}case A.MoveRowsCommandId:{const r=t.params;return this._handleMoveRowsCommand(r,n,o)}case Me.id:{const r=t.params,a=r.unitId||n,l=r.subUnitId||o;return this._handleInsertRowCommand(r,a,l)}case ye.id:{const r=t.params,a=r.unitId||n,l=r.subUnitId||o;return this._handleInsertColCommand(r,a,l)}case Lt.id:{const r=t.params;return this._handleRemoveColCommand(r,n,o)}case $t.id:{const r=t.params;return this._handleRemoveRowCommand(r,n,o)}case Je.id:{const r=t.params;return this._handleMoveRangeCommand(r,n,o)}case It.id:{const r=t.params;return this._handleInsertRangeMoveRightCommand(r,n,o)}case xe.id:{const r=t.params;return this._handleInsertRangeMoveDownCommand(r,n,o)}case Be.id:{const r=t.params;return this._handleDeleteRangeMoveUpCommand(r,n,o)}case He.id:{const r=t.params;return this._handleDeleteRangeMoveLeftCommand(r,n,o)}}return{redos:[],undos:[]}}_onRefRangeChange(){const t=(n,o)=>{const r=this._univerInstanceService.getUniverSheetInstance(n);if(!r)return;const a=r==null?void 0:r.getSheetBySheetId(o);if(!a)return;this.disposableCollection.dispose();const l=a.getMergeData(),u=d=>this.refRangeHandle(d,n,o);l.forEach(d=>{this.disposableCollection.add(this._refRangeService.registerRefRange(d,u,n,o))})};this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===Ct.id){const o=n.params,r=o.subUnitId,a=o.unitId;if(!r||!a)return;t(a,r)}if(n.id===j.id){const o=n.params,r=o.subUnitId,a=o.unitId;if(!r||!a)return;t(o.unitId,o.subUnitId)}})),this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).pipe(D.first(n=>!!n)).subscribe(n=>{const o=n.getActiveSheet();o&&t(n.getUnitId(),o.getSheetId())})}_handleMoveRowsCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=[...a.getMergeData()],u={unitId:n,subUnitId:o,ranges:[]},d={unitId:n,subUnitId:o,ranges:[]},{fromRange:c}=t,{startRow:m,endRow:h}=c;if(l.forEach(S=>{if(m<=S.startRow&&h>=S.endRow){u.ranges.push(S);const v=bs({id:A.MoveRowsCommandId,params:t},S),I=et(v,S);I&&d.ranges.push(I)}}),u.ranges.length===0)return this._handleNull();const R=le(this._injector,u),C=ge(this._injector,d);return{preRedos:[{id:G.id,params:u}],redos:[{id:j.id,params:d}],preUndos:[{id:G.id,params:C}],undos:[{id:j.id,params:R}]}}_handleMoveColsCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=[...a.getMergeData()],u={unitId:n,subUnitId:o,ranges:[]},d={unitId:n,subUnitId:o,ranges:[]},{fromRange:c}=t,{startColumn:m,endColumn:h}=c;if(l.forEach(S=>{if(m<=S.startColumn&&h>=S.endColumn){u.ranges.push(S);const v=Es({id:A.MoveColsCommandId,params:t},S),I=et(v,S);I&&d.ranges.push(I)}}),u.ranges.length===0)return this._handleNull();const R=le(this._injector,u),C=ge(this._injector,d);return{preRedos:[{id:G.id,params:u}],redos:[{id:j.id,params:d}],preUndos:[{id:G.id,params:C}],undos:[{id:j.id,params:R}]}}_handleMoveRangeCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=a.getMergeData(),u=l.filter(C=>i.Rectangle.intersects(C,t.fromRange)),d=l.filter(C=>i.Rectangle.intersects(C,t.toRange)),c=u.map(C=>i.Rectangle.getRelativeRange(C,t.fromRange)).map(C=>i.Rectangle.getPositionRange(C,t.toRange)),m=ks(c).filter(C=>!l.some(S=>i.Rectangle.equals(C,S))),h=[{id:G.id,params:{unitId:n,subUnitId:o,ranges:u}},{id:G.id,params:{unitId:n,subUnitId:o,ranges:d}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:m}}],R=[{id:G.id,params:{unitId:n,subUnitId:o,ranges:m}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:d}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:u}}];return{redos:h,undos:R}}_handleInsertRowCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const{range:l}=t,{startRow:u,endRow:d}=l,c=i.Tools.deepClone(a.getMergeData()).reduce((M,p)=>(u>p.startRow&&u<=p.endRow&&M.push(p),M),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(a.getMergeData()).reduce((M,p)=>{if(u>p.startRow&&u<=p.endRow){const w=d-u+1;p.endRow+=w,this._checkIsMergeCell(p)&&M.push(p)}return M},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h},{id:j.id,params:C}],I=[{id:G.id,params:S},{id:j.id,params:R}];return{redos:v,undos:I}}_handleInsertColCommand(t,n,o){const{range:r}=t,a=_e(this._univerInstanceService,n);if(!a)return this._handleNull();const l=be(a,o);if(!l)return this._handleNull();const{startColumn:u,endColumn:d}=r,c=i.Tools.deepClone(l.getMergeData()).reduce((M,p)=>(u>p.startColumn&&u<=p.endColumn&&M.push(p),M),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(l.getMergeData()).reduce((M,p)=>{if(u>p.startColumn&&u<=p.endColumn){const w=d-u+1;p.endColumn+=w,this._checkIsMergeCell(p)&&M.push(p)}return M},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h},{id:j.id,params:C}],I=[{id:G.id,params:S},{id:j.id,params:R}];return{redos:v,undos:I}}_handleRemoveColCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const{range:l}=t,{startColumn:u,endColumn:d}=l,c=i.Tools.deepClone(a.getMergeData()).reduce((w,y)=>(i.Rectangle.intersects(l,y)&&w.push(y),w),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(a.getMergeData()).reduce((w,y)=>{if(i.Rectangle.intersects(l,y)){if(u<=y.startColumn&&d>=y.endColumn)return w;u>=y.startColumn&&d<=y.endColumn?y.endColumn-=d-u+1:u<y.startColumn?(y.startColumn=u,y.endColumn-=d-u+1):d>y.endColumn&&(y.endColumn=u-1),this._checkIsMergeCell(y)&&w.push(y)}return w},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{preUndos:M,undos:p,preRedos:v,redos:I}}_handleRemoveRowCommand(t,n,o){const{range:r}=t,a=_e(this._univerInstanceService,n);if(!a)return this._handleNull();const l=be(a,o);if(!l)return this._handleNull();const{startRow:u,endRow:d}=r,c=i.Tools.deepClone(l.getMergeData()).reduce((w,y)=>(i.Rectangle.intersects(r,y)&&w.push(y),w),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(l.getMergeData()).reduce((w,y)=>{if(i.Rectangle.intersects(r,y)){if(u<=y.startRow&&d>=y.endRow)return w;u>=y.startRow&&d<=y.endRow?y.endRow-=d-u+1:u<y.startRow?(y.startRow=u,y.endRow-=d-u+1):d>y.endRow&&(y.endRow=u-1),this._checkIsMergeCell(y)&&w.push(y)}return w},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{preUndos:M,undos:p,preRedos:v,redos:I}}_handleInsertRangeMoveRightCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxColumns()-1,d=a.getMergeData(),c=[],m=[];d.forEach(v=>{const{startRow:I,endRow:M,startColumn:p,endColumn:w}=l;if(i.Rectangle.intersects({startRow:I,startColumn:p,endRow:M,endColumn:u},v)&&(c.push(v),i.Rectangle.contains({startRow:I,startColumn:p,endRow:M,endColumn:u},v))){const T=w-p+1;m.push({startRow:v.startRow,startColumn:v.startColumn+T,endRow:v.endRow,endColumn:v.endColumn+T})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C);return{preRedos:[{id:G.id,params:h}],redos:[{id:j.id,params:C}],preUndos:[{id:G.id,params:S}],undos:[{id:j.id,params:R}]}}_handleInsertRangeMoveDownCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxRows()-1,d=a.getMergeData(),c=[],m=[];d.forEach(w=>{const{startRow:y,startColumn:b,endColumn:T,endRow:U}=l;if(i.Rectangle.intersects({startRow:y,startColumn:b,endRow:u,endColumn:T},w)&&(c.push(w),i.Rectangle.contains({startRow:y,startColumn:b,endRow:u,endColumn:T},w))){const O=U-y+1;m.push({startRow:w.startRow+O,startColumn:w.startColumn,endRow:w.endRow+O,endColumn:w.endColumn})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{redos:I,undos:p,preRedos:v,preUndos:M}}_handleDeleteRangeMoveUpCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxRows()-1,d=a.getMergeData(),c=[],m=[];d.forEach(w=>{const{startRow:y,startColumn:b,endColumn:T,endRow:U}=l;if(i.Rectangle.intersects({startRow:y,startColumn:b,endRow:u,endColumn:T},w)&&(c.push(w),i.Rectangle.contains({startRow:y,startColumn:b,endRow:u,endColumn:T},w))){const O=U-y+1,W=i.Rectangle.moveVertical(w,-O);m.push(W)}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{redos:I,undos:p,preRedos:v,preUndos:M}}_handleDeleteRangeMoveLeftCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxColumns()-1,d=a.getMergeData(),c=[],m=[];d.forEach(v=>{const{startRow:I,endRow:M,startColumn:p,endColumn:w}=l;if(i.Rectangle.intersects({startRow:I,startColumn:p,endRow:M,endColumn:u},v)&&(c.push(v),i.Rectangle.contains({startRow:I,startColumn:p,endRow:M,endColumn:u},v))){const T=w-p+1;m.push({startRow:v.startRow,startColumn:v.startColumn-T,endRow:v.endRow,endColumn:v.endColumn-T})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C);return{preRedos:[{id:G.id,params:h}],redos:[{id:j.id,params:C}],undos:[{id:j.id,params:R}],preUndos:[{id:G.id,params:S}]}}_checkIsMergeCell(t){return!(t.startRow===t.endRow&&t.startColumn===t.endColumn)}_handleNull(){return{redos:[],undos:[]}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(xl.includes(t.id)){if(!t.params)return;const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const{sourceRange:r,targetRange:a}=t.params,l=r.startColumn===a.startColumn&&r.endColumn===a.endColumn,u=l?r.endRow-r.startRow+1:r.endColumn-r.startColumn+1,d=l?r.startRow:r.startColumn,c=l?a.startRow:a.startColumn,m=o.getConfig().mergeData,h=[];m.forEach(v=>{let{startRow:I,endRow:M,startColumn:p,endColumn:w,rangeType:y}=v;i.Rectangle.intersects(v,r)||(l?d<I&&c>M?(I-=u,M-=u):d>M&&c<=I&&(I+=u,M+=u):d<p&&c>w?(p-=u,w-=u):d>w&&c<=p&&(p+=u,w+=u)),v.startRow===v.endRow&&v.startColumn===v.endColumn||h.push({startRow:I,endRow:M,startColumn:p,endColumn:w,rangeType:y})}),o.setMergeData(h),this.disposableCollection.dispose();const{unitId:R,subUnitId:C}=t.params,S=v=>this.refRangeHandle(v,R,C);h.forEach(v=>{this.disposableCollection.add(this._refRangeService.registerRefRange(v,S,R,C))})}if(Jl.includes(t.id)){const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const r=o.getConfig().mergeData,a=t.params;if(!a)return;const{range:l}=a,u=t.id.includes("row"),d=t.id.includes("insert"),c=u?l.startRow:l.startColumn,m=u?l.endRow:l.endColumn,h=m-c+1,R=[];r.forEach(I=>{let{startRow:M,endRow:p,startColumn:w,endColumn:y,rangeType:b}=I;d?u?c<=M&&(M+=h,p+=h):c<=w&&(w+=h,y+=h):u?m<M&&(M-=h,p-=h):m<w&&(w-=h,y-=h),I.startRow===I.endRow&&I.startColumn===I.endColumn||R.push({startRow:M,endRow:p,startColumn:w,endColumn:y,rangeType:b})}),o.setMergeData(R),this.disposableCollection.dispose();const{unitId:C,subUnitId:S}=t.params,v=I=>this.refRangeHandle(I,C,S);R.forEach(I=>{this.disposableCollection.add(this._refRangeService.registerRefRange(I,v,C,S))})}}))}},g.MergeCellController=Kl([Mt(0,i.Inject(i.ICommandService)),Mt(1,i.Inject(g.RefRangeService)),Mt(2,i.Inject(i.IUniverInstanceService)),Mt(3,i.Inject(i.Injector)),Mt(4,i.Inject(g.SheetInterceptorService)),Mt(5,i.Inject(g.SheetsSelectionsService))],g.MergeCellController);function _e(s,e){return e?s.getUniverSheetInstance(e):s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET)}function be(s,e){return e?s.getSheetBySheetId(e):s.getActiveSheet()}function Xl(s,e){return e.some(t=>Zl(s,t))}function Zl(s,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,a=s.getMatrixWithMergedCells(t,n,r,o);let l=!1;return a.forValue((u,d,c)=>{if(c&&(u!==t||d!==n)&&s.cellHasValue(c))return l=!0,!1}),l}function Ql(s,e,t,n){const o=[],r=[],a=t.getSheetId();return n.forEach(l=>{const u=eu(t,l),d={unitId:e,subUnitId:a,cellValue:u.getData()},c=ce(s,d);o.push({id:F.id,params:c}),r.push({id:F.id,params:d})}),{undos:o,redos:r}}function eu(s,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,a=s.getMatrixWithMergedCells(t,n,r,o,i.CellModeEnum.Raw),l=new i.ObjectMatrix;return a.forValue((u,d,c)=>{c&&(u!==t||d!==n)&&l.setValue(u,d,null)}),l}const Ft={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=e.unitId,a=e.subUnitId,l=e.selections,u=ks(l,e.value),d=o.getUniverSheetInstance(r).getSheetBySheetId(a),c=[],m=[],h=Xl(d,u),R={unitId:r,subUnitId:a,ranges:u},C={unitId:r,subUnitId:a,ranges:u};c.push({id:G.id,params:R}),c.push({id:j.id,params:C});const S=le(s,R),v=ge(s,C);if(m.push({id:G.id,params:v}),m.push({id:j.id,params:S}),h){const M=Ql(s,r,d,u);c.unshift(...M.redos),m.push(...M.undos)}return i.sequenceExecute(c,t).result?(n.pushUndoRedo({unitID:r,undoMutations:m,redoMutations:c}),!0):!1}},tu={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{selections:n,unitId:l,subUnitId:u})}},nu={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{value:i.Dimension.COLUMNS,selections:n,unitId:l,subUnitId:u})}},su={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{value:i.Dimension.ROWS,selections:n,unitId:l,subUnitId:u})}};function ou(s,e,t,n,o){const r=s.get(i.IUniverInstanceService),a=P(r,{unitId:e,subUnitId:t});if(!a)return;const{worksheet:l}=a;if(l.getMergeData().some(m=>n.some(h=>i.Rectangle.intersects(h,m))))throw new Error("The ranges to be merged overlap with the existing merged cells");s.get(i.ICommandService).executeCommand(Ft.id,{unitId:e,subUnitId:t,selections:n,defaultMerge:o})}class ke{constructor(){f(this,"_model",new Map);f(this,"_ruleChange",new D.Subject);f(this,"_ruleRefresh",new D.Subject);f(this,"_resetOrder",new D.Subject);f(this,"ruleChange$",this._ruleChange.asObservable());f(this,"ruleRefresh$",this._ruleRefresh.asObservable());f(this,"resetOrder$",this._resetOrder.asObservable());f(this,"_worksheetRuleInitStateChange",new D.BehaviorSubject(!1));f(this,"worksheetRuleInitStateChange$",this._worksheetRuleInitStateChange.asObservable())}changeRuleInitState(e){this._worksheetRuleInitStateChange.next(e)}getSheetRuleInitState(){return this._worksheetRuleInitStateChange.value}addRule(e,t){this._ensureSubUnitMap(e).set(t.subUnitId,t),this._ruleChange.next({unitId:e,rule:t,type:"add",subUnitId:t.subUnitId})}deleteRule(e,t){var o,r,a;const n=(r=(o=this._model)==null?void 0:o.get(e))==null?void 0:r.get(t);n&&((a=this._model.get(e))==null||a.delete(t),this._ruleChange.next({unitId:e,rule:n,type:"delete",subUnitId:t}))}setRule(e,t,n){var r,a;const o=this.getRule(e,t);o&&((a=(r=this._model)==null?void 0:r.get(e))==null||a.set(t,n),this._ruleChange.next({unitId:e,oldRule:o,rule:n,type:"set",subUnitId:t}))}getRule(e,t){var n,o;return(o=(n=this._model)==null?void 0:n.get(e))==null?void 0:o.get(t)}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n);o!=null&&o.size&&(e[n]=[],[...o.keys()].forEach(a=>{const l=o.get(a);l&&e[n].push(l)}))}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n];if(o!=null&&o.length){const r=new Map;o.forEach(a=>{r.set(a.subUnitId,a)}),t.set(n,r)}}),this._model=t}deleteUnitModel(e){this._model.delete(e)}_ensureSubUnitMap(e){let t=this._model.get(e);return t||(t=new Map,this._model.set(e,t)),t}ruleRefresh(e){this._ruleRefresh.next(e)}resetOrder(){this._resetOrder.next(Math.random())}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)if(r.permissionId===t)return[e,o]}}const Fe={id:"sheet.mutation.add-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,rule:n}=e;return s.get(ke).addRule(t,n),!0}},tt={id:"sheet.mutation.delete-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n}=e;return s.get(ke).deleteRule(t,n),!0}},br={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,unitId:r}=e,a=o.subUnitId;if(await t.executeCommand(Fe.id,{unitId:r,rule:o,subUnitId:o.subUnitId})){const u=[{id:Fe.id,params:{unitId:r,rule:o,subUnitId:o.subUnitId}}],d=[{id:tt.id,params:{unitId:r,subUnitId:a}}];n.pushUndoRedo({unitID:r,redoMutations:u,undoMutations:d})}return!0}},Er={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-range-theme-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=io(s,e);return t.syncExecuteCommand(rt.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:it.id,params:r}],redoMutations:[{id:rt.id,params:e}]}),!0):!1}},Tr={type:i.CommandType.COMMAND,id:"sheet.command.append-row",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o,subUnitId:r,cellValue:a,insertRowNums:l,insertColumnNums:u,maxRows:d,maxColumns:c}=e,m={unitId:o,subUnitId:r,cellValue:a},h=ce(s,m),R=[{id:F.id,params:m}],C=[{id:F.id,params:h}];if(l){const v={unitId:o,subUnitId:r,range:{startRow:d,endRow:d,startColumn:0,endColumn:c-1}},I=en(s,v);R.unshift({id:re.id,params:v}),C.push({id:ae.id,params:I})}if(u){const v={unitId:o,subUnitId:r,range:{startRow:0,endRow:d-1,startColumn:c,endColumn:c-1+u}},I=Ot(s,v);R.unshift({id:ie.id,params:v}),C.push({id:ne.id,params:I})}return i.sequenceExecute(R,t).result?(n.pushUndoRedo({unitID:o,undoMutations:C,redoMutations:R}),!0):!1}},fn={id:"sheet.command.clear-selection-content",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Nt(m,s,u,c),R={subUnitId:c,unitId:u,cellValue:Uo(h)},C=ce(s,R),S=a.onCommandExecute({id:fn.id}),v=[{id:F.id,params:R},...S.redos],I=[...S.undos,{id:F.id,params:C}];return i.sequenceExecute(v,n).result?(r.pushUndoRedo({unitID:u,undoMutations:I,redoMutations:v}),!0):!1}},Os=(s,e)=>({subUnitId:e.sheet.id,unitId:e.unitId,subUnitName:e.sheet.name}),yt={id:"sheet.mutation.insert-sheet",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),{sheet:n,index:o,unitId:r,styles:a}=e,l=t.getUniverSheetInstance(r);return l?(a&&l.addStyles(a),l.addWorksheet(n.id,o,n)):!1}},Ds={type:i.CommandType.COMMAND,id:"sheet.command.copy-sheet",handler:(s,e)=>{var w,y;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=s.get(i.LocaleService),l=P(o,e);if(!l)return!1;const{workbook:u,worksheet:d,unitId:c,subUnitId:m}=l,h=i.Tools.deepClone(d.getConfig());h.name=ru(u,a,h.name),h.id=i.generateRandomId();const C={index:u.getSheetIndex(d)+1,sheet:h,unitId:c},S=Os(s,C),v=r.onCommandExecute({id:Ds.id,params:{unitId:c,subUnitId:m,targetSubUnitId:h.id}}),I=[...(w=v.preRedos)!=null?w:[],{id:yt.id,params:C},...v.redos],M=[...(y=v.preUndos)!=null?y:[],{id:Xe.id,params:S},...v.undos];return i.sequenceExecute(I,t).result?(n.pushUndoRedo({unitID:c,undoMutations:M,redoMutations:I}),!0):!1}};function ru(s,e,t){let n=`${t} ${e.t("sheets.tabs.sheetCopy","")}`,o=2;for(;s.checkSheetName(n);)n=`${t} ${e.t("sheets.tabs.sheetCopy",`${o}`)}`,o++;return n}const Ur={type:i.CommandType.COMMAND,id:"sheet.command.delete-range-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o,subUnitId:r,rule:a}=e,l={unitId:o,subUnitId:r,ruleIds:[a.id]};return await t.executeCommand(Te.id,l)&&n.pushUndoRedo({unitID:o,redoMutations:[{id:Te.id,params:l}],undoMutations:[{id:Ce.id,params:{unitId:o,subUnitId:r,rules:[a]}}]}),!0}},Pr={type:i.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection",handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,unitId:r,subUnitId:a}=e;t.executeCommand(tt.id,{unitId:r,subUnitId:a});const l=[{id:tt.id,params:{unitId:r,subUnitId:a}}],u=[{id:Fe.id,params:{unitId:r,rule:o,subUnitId:a}}];return n.pushUndoRedo({unitID:r,redoMutations:l,undoMutations:u}),!0}},kr={type:i.CommandType.COMMAND,id:"sheet.command.remove-worksheet-range-theme-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=ao(s,e);return t.syncExecuteCommand(it.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:rt.id,params:r}],redoMutations:[{id:it.id,params:e}]}),!0):!1}},Or={id:"sheet.command.insert-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService);if(!e)return!1;const o={...e};return t.syncExecuteCommand(J.SetDefinedNameMutation.id,o)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:[{id:J.RemoveDefinedNameMutation.id,params:o}],redoMutations:[{id:J.SetDefinedNameMutation.id,params:o}]}),!0):!1}},Dr={id:"sheet.command.insert-sheet",type:i.CommandType.COMMAND,handler:(s,e)=>{var v;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(i.LocaleService),a=Hn(o,{unitId:e==null?void 0:e.unitId});if(!a)return!1;const{unitId:l,workbook:u}=a;let d=u.getSheets().length;const c=e==null?void 0:e.sheet,m=c==null?void 0:c.id,h=i.mergeWorksheetSnapshotWithDefault(c||{});e?(d=(v=e.index)!=null?v:d,h.id=m||i.generateRandomId(),h.name=(c==null?void 0:c.name)||u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)):(h.id=i.generateRandomId(),h.name=u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`));const R={index:d,sheet:h,unitId:l},C=Os(s,R);return t.syncExecuteCommand(yt.id,R)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:Xe.id,params:C}],redoMutations:[{id:yt.id,params:R}]}),!0):!1}},_t={id:"sheet.mutation.register-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,rangeThemeStyleJson:n,themeName:o}=e,r=s.get(i.IUniverInstanceService),a=P(r),l=s.get(g.SheetRangeThemeModel);if(!a)return!1;const u=new We(o,n);return l.registerRangeThemeStyle(t,u),!0}},vn={id:"sheet.mutation.unregister-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,themeName:n}=e,o=s.get(i.IUniverInstanceService),r=P(o),a=s.get(g.SheetRangeThemeModel);return r?(a.unregisterRangeThemeStyle(t,n),!0):!1}},Nr={id:"sheet.command.register-worksheet-range-theme-style",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,rangeThemeStyle:n}=e,o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService);if(!P(o))return!1;const u={unitId:t,themeName:n.getName(),rangeThemeStyleJson:n.toJson()},d={unitId:t,themeName:n.getName()};return r.syncExecuteCommand(_t.id,u)&&a.pushUndoRedo({unitID:t,undoMutations:[{id:vn.id,params:d}],redoMutations:[{id:_t.id,params:u}]}),!0}},Ns={id:"sheet.command.remove-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{var c,m;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService);if(!e)return!1;const r={...e},a=o.onCommandExecute({id:Ns.id,params:e}),l=[...(c=a.preRedos)!=null?c:[],{id:J.RemoveDefinedNameMutation.id,params:r},...a.redos],u=[...(m=a.preUndos)!=null?m:[],{id:J.SetDefinedNameMutation.id,params:r},...a.undos];return i.sequenceExecute(l,t)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:u.filter(Boolean),redoMutations:l.filter(Boolean)}),!0):!1}},In={id:"sheet.command.remove-sheet",type:i.CommandType.COMMAND,handler:(s,e)=>{var I,M;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=P(o,e);if(!a)return!1;const{unitId:l,subUnitId:u,workbook:d,worksheet:c}=a;if(d.getSheets().length<=1)return!1;const m={subUnitId:u,unitId:l,subUnitName:c.getName()},h=rr(s,m),R=r.onCommandExecute({id:In.id,params:{unitId:l,subUnitId:u}}),C=[...(I=R.preRedos)!=null?I:[],{id:Xe.id,params:m},...R.redos],S=[...(M=R.preUndos)!=null?M:[],{id:yt.id,params:h},...R.undos];return i.sequenceExecute(C,t).result?(n.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:C}),!0):!1}},Ar={type:i.CommandType.COMMAND,id:"sheet.command.remove-worksheet-merge",handler:(s,e)=>{var O;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=(e==null?void 0:e.ranges)||((O=t.getCurrentSelections())==null?void 0:O.map(W=>W.range));if(!(a!=null&&a.length))return!1;const l=P(r);if(!l)return!1;const{subUnitId:u,unitId:d,worksheet:c}=l,m={unitId:d,subUnitId:u,ranges:a},R=c.getConfig().mergeData.filter(W=>a.some(V=>i.Rectangle.intersects(V,W)));if(!R.length)return!1;const C=le(s,m),S=t.getCurrentSelections();if(!(S!=null&&S.length))return!1;const v=i.Tools.deepClone(S),I=i.Tools.deepClone(S),M=I[I.length-1],{startRow:p,startColumn:w}=M.range;M.primary={startRow:p,startColumn:w,endRow:p,endColumn:w,actualRow:p,actualColumn:w,isMerged:!1,isMergedMainCell:!1};const y=iu(c,R),b={unitId:d,subUnitId:u,cellValue:y.redoParams.getMatrix()},T={unitId:d,subUnitId:u,cellValue:y.undoParams.getMatrix()},U=[{id:G.id,params:C},{id:F.id,params:b},{id:q.id,params:{selections:I}}],k=[{id:j.id,params:C},{id:F.id,params:T},{id:q.id,params:{selections:v}}];return i.sequenceExecute(U,n)?(o.pushUndoRedo({unitID:d,undoMutations:k,redoMutations:U}),!0):!1}};function iu(s,e){const t=new i.ObjectMatrix,n=new i.ObjectMatrix;return e.forEach(o=>{const{startRow:r,startColumn:a,endColumn:l,endRow:u}=o,d=s.getCellMatrix().getValue(r,a);if(d!=null&&d.s)for(let c=r;c<=u;c++)for(let m=a;m<=l;m++)(c!==r||m!==a)&&(t.setValue(c,m,{s:d.s}),n.setValue(c,m,null))}),{redoParams:t,undoParams:n}}class nt{constructor(){f(this,"_borderInfo",{type:i.BorderType.ALL,color:"#000000",style:i.BorderStyleTypes.THIN,activeBorderType:!1});f(this,"_borderInfo$",new D.BehaviorSubject(this._borderInfo));f(this,"borderInfo$",this._borderInfo$.asObservable())}dispose(){this._borderInfo$.complete()}setType(e){this._borderInfo.type=e,this.setActiveBorderType(!0),this._refresh()}setColor(e){this._borderInfo.color=e,this._refresh()}setStyle(e){this._borderInfo.style=e,this._refresh()}setActiveBorderType(e){this._borderInfo.activeBorderType=e}getBorderInfo(){return this._borderInfo}_refresh(){this._borderInfo$.next(this._borderInfo)}}function pn(s,e){const{startRow:t,startColumn:n,endRow:o,endColumn:r}=s;for(let a=t;a<=o;a++)for(let l=n;l<=r;l++)e(a,l)}const As=(s,e,t,n)=>{const{mr:o,worksheet:r}=s;e.startRow<0||e.startColumn<0||pn(e,(a,l)=>{var c,m;const u=r.getMergedCell(a,l);let d=t;if(u&&(t.bc_tr||t.ml_tr||t.bl_tr||t.tl_mr||t.tl_bc||t.tl_br)){if(n){const h=i.Tools.deepClone((c=o.getValue(u.startRow,u.startColumn))==null?void 0:c.s);d=h!=null&&h.bd?Object.assign(h.bd,t):t}o.setValue(u.startRow,u.startColumn,{s:{bd:d}})}else{if(n){const h=i.Tools.deepClone((m=o.getValue(a,l))==null?void 0:m.s);d=h!=null&&h.bd?Object.assign(h.bd,t):t}o.setValue(a,l,{s:{bd:d}})}})},au=s=>{const e={startRow:s.startRow-1,startColumn:s.startColumn,endRow:s.startRow-1,endColumn:s.endColumn},t={startRow:s.startRow,startColumn:s.startColumn-1,endRow:s.endRow,endColumn:s.startColumn-1},n={startRow:s.endRow+1,startColumn:s.startColumn,endRow:s.endRow+1,endColumn:s.endColumn},o={startRow:s.startRow,startColumn:s.endColumn+1,endRow:s.endRow,endColumn:s.endColumn+1},r={startRow:s.startRow,startColumn:s.startColumn,endRow:s.startRow,endColumn:s.endColumn},a={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.startColumn},l={startRow:s.endRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn},u={startRow:s.startRow,startColumn:s.endColumn,endRow:s.endRow,endColumn:s.endColumn};return{topRangeOut:e,leftRangeOut:t,bottomRangeOut:n,rightRangeOut:o,topRange:r,leftRange:a,bottomRange:l,rightRange:u}};function lu(s,e,t){const{style:n,color:o,type:r}=s.getBorderInfo(),a=r===i.BorderType.TOP||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,l=r===i.BorderType.LEFT||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,u=r===i.BorderType.BOTTOM||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,d=r===i.BorderType.RIGHT||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,c=r===i.BorderType.VERTICAL||r===i.BorderType.ALL||r===i.BorderType.INSIDE,m=r===i.BorderType.HORIZONTAL||r===i.BorderType.ALL||r===i.BorderType.INSIDE,h=r.indexOf("tlbr")>-1,R=r.indexOf("tlbc")>-1,C=r.indexOf("tlmr")>-1,S=r.indexOf("bltr")>-1,v=r.indexOf("mltr")>-1,I=r.indexOf("bctr")>-1,M=t[0],{topRangeOut:p,leftRangeOut:w,bottomRangeOut:y,rightRangeOut:b,topRange:T,leftRange:U,bottomRange:k,rightRange:E}=au(M),O=new i.ObjectMatrix,{worksheet:W,unitId:V,subUnitId:$}=e;return{worksheet:W,unitId:V,subUnitId:$,style:n,color:o,type:r,top:a,left:l,right:d,bottom:u,vertical:c,horizontal:m,tl_br:h,tl_bc:R,tl_mr:C,bl_tr:S,ml_tr:v,bc_tr:I,topRangeOut:p,leftRangeOut:w,bottomRangeOut:y,rightRangeOut:b,topRange:T,leftRange:U,bottomRange:k,rightRange:E,range:M,mr:O,borderStyle:{s:n,cl:{rgb:o}}}}const uu=s=>{const{range:e,mr:t,borderStyle:n,vertical:o,horizontal:r,worksheet:a}=s;o&&pn(e,(l,u)=>{var c,m,h;const d=a.getMergedCell(l,u);if(d){const R=(c=t.getValue(d.startRow,d.startColumn))==null?void 0:c.s;d.startColumn!==e.startColumn&&t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{l:i.Tools.deepClone(n)}):{l:i.Tools.deepClone(n)}}})}else{if(u!==e.endColumn){const R=(m=t.getValue(l,u))==null?void 0:m.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{r:i.Tools.deepClone(n)}):{r:i.Tools.deepClone(n)}}})}if(u!==e.startColumn){const R=(h=t.getValue(l,u))==null?void 0:h.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{l:i.Tools.deepClone(n)}):{l:i.Tools.deepClone(n)}}})}}}),r&&pn(e,(l,u)=>{var c,m,h;const d=a.getMergedCell(l,u);if(d){const R=(c=t.getValue(d.startRow,d.startColumn))==null?void 0:c.s;d.startRow!==e.startRow&&t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{t:i.Tools.deepClone(n)}):{t:i.Tools.deepClone(n)}}})}else{if(l!==e.endRow){const R=(m=t.getValue(l,u))==null?void 0:m.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{b:i.Tools.deepClone(n)}):{b:i.Tools.deepClone(n)}}})}if(l!==e.startRow){const R=(h=t.getValue(l,u))==null?void 0:h.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{t:i.Tools.deepClone(n)}):{t:i.Tools.deepClone(n)}}})}}})};function du(s){const{borderStyle:e,tl_br:t,tl_bc:n,tl_mr:o,bl_tr:r,ml_tr:a,bc_tr:l}=s,u=(d,c,m)=>{As(s,d,c,m)};t&&u(s.range,{tl_br:i.Tools.deepClone(e)},!0),n&&u(s.range,{tl_bc:i.Tools.deepClone(e)},!0),o&&u(s.range,{tl_mr:i.Tools.deepClone(e)},!0),r&&u(s.range,{bl_tr:i.Tools.deepClone(e)},!0),a&&u(s.range,{ml_tr:i.Tools.deepClone(e)},!0),l&&u(s.range,{bc_tr:i.Tools.deepClone(e)},!0)}const cu=s=>{const{top:e,left:t,right:n,bottom:o,borderStyle:r,bottomRange:a,topRange:l,leftRange:u,rightRange:d,bottomRangeOut:c,topRangeOut:m,leftRangeOut:h,rightRangeOut:R}=s,C=(S,v,I)=>{As(s,S,v,I)};e&&(C(m,{b:null}),C(l,{t:i.Tools.deepClone(r)},!0)),o&&(C(c,{t:null}),C(a,{b:i.Tools.deepClone(r)},!0)),t&&(C(h,{r:null}),C(u,{l:i.Tools.deepClone(r)},!0)),n&&(C(R,{l:null}),C(d,{r:i.Tools.deepClone(r)},!0))},mu=s=>{const{range:e,worksheet:t,mr:n,top:o,bottom:r,left:a,right:l,vertical:u,horizontal:d,tl_br:c,tl_bc:m,tl_mr:h,bl_tr:R,ml_tr:C,bc_tr:S,topRange:v,bottomRange:I,leftRange:M,rightRange:p,topRangeOut:w,bottomRangeOut:y,leftRangeOut:b,rightRangeOut:T}=s,U=(k,E,O)=>{As(s,k,E,O)};!o&&!r&&!a&&!l&&!u&&!d&&!c&&!m&&!h&&!R&&!C&&!S&&(pn(e,(k,E)=>{var W,V,$,L,Y,z,K,oe;const O=t.getMergedCell(k,E);if(O){if(O.endColumn!==e.endColumn){const B=(W=n.getValue(O.startRow,O.startColumn))==null?void 0:W.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{r:null}):{r:null}}})}if(O.startColumn!==e.startColumn){const B=(V=n.getValue(O.startRow,O.startColumn))==null?void 0:V.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{l:null}):{l:null}}})}if(O.endRow!==e.endRow){const B=($=n.getValue(O.startRow,O.startColumn))==null?void 0:$.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{b:null}):{b:null}}})}if(O.startRow!==e.startRow){const B=(L=n.getValue(O.startRow,O.startColumn))==null?void 0:L.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{t:null}):{t:null}}})}}else{if(E!==e.endColumn){const B=(Y=n.getValue(k,E))==null?void 0:Y.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{r:null}):{r:null}}})}if(E!==e.startColumn){const B=(z=n.getValue(k,E))==null?void 0:z.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{l:null}):{l:null}}})}if(k!==e.endRow){const B=(K=n.getValue(k,E))==null?void 0:K.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{b:null}):{b:null}}})}if(k!==e.startRow){const B=(oe=n.getValue(k,E))==null?void 0:oe.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{t:null}):{t:null}}})}}}),U(w,{b:null}),U(v,{t:null},!0),U(y,{t:null}),U(I,{b:null},!0),U(b,{r:null}),U(M,{l:null},!0),U(T,{l:null}),U(p,{r:null},!0),U(e,{tl_br:null},!0),U(e,{tl_bc:null},!0),U(e,{tl_mr:null},!0),U(e,{bl_tr:null},!0),U(e,{ml_tr:null},!0),U(e,{bc_tr:null},!0))},bt={id:"sheet.command.set-border",type:i.CommandType.COMMAND,handler:(s,e)=>{var I;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(nt),l=P(o,e);if(!l)return!1;const u=(e==null?void 0:e.ranges)||((I=r.getCurrentSelections())==null?void 0:I.map(M=>M.range));if(!(u!=null&&u.length))return!1;const{activeBorderType:d}=a.getBorderInfo();if(!d)return!1;const c=lu(a,l,u);uu(c),cu(c),du(c),mu(c);const{unitId:m,subUnitId:h,mr:R}=c,C={unitId:m,subUnitId:h,cellValue:R.getData()},S=ce(s,C);return t.syncExecuteCommand(F.id,C)?(n.pushUndoRedo({unitID:m,undoMutations:[{id:F.id,params:S}],redoMutations:[{id:F.id,params:C}]}),!0):!1}},Wr={id:"sheet.command.set-border-position",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e.value)return!1;const t=s.get(i.ICommandService);return s.get(nt).setType(e.value),t.syncExecuteCommand(bt.id)}},Vr={id:"sheet.command.set-border-style",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService);return s.get(nt).setStyle(e.value),t.syncExecuteCommand(bt.id)}},$r={id:"sheet.command.set-border-color",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService);return s.get(nt).setColor(e.value),t.syncExecuteCommand(bt.id)}},Lr={id:"sheet.command.set-border-basic",type:i.CommandType.COMMAND,handler:(s,e)=>{const{unitId:t,subUnitId:n,value:o,ranges:r}=e,{type:a,color:l,style:u}=o,d=s.get(i.ICommandService),c=s.get(nt);return c.setType(a),l&&c.setColor(l),c.setStyle(u),d.syncExecuteCommand(bt.id,{unitId:t,subUnitId:n,ranges:r})}},Hr={type:i.CommandType.COMMAND,id:"sheet.command.set-col-data",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{columnData:a}=e,{unitId:l,subUnitId:u,worksheet:d}=r,c={subUnitId:u,unitId:l,columnData:a},m=mo(c,d);return t.syncExecuteCommand(at.id,c)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:at.id,params:m}],redoMutations:[{id:at.id,params:c}]}),!0):!1}},Et={type:i.CommandType.COMMAND,id:"sheet.command.set-col-visible-on-cols",handler:(s,e)=>{var I,M;const{unitId:t,subUnitId:n,ranges:o}=e,r=s.get(g.SheetInterceptorService),a=s.get(i.ICommandService),l=s.get(i.IUniverInstanceService),u=P(l,{unitId:t,subUnitId:n});if(!u)return!1;const{worksheet:d}=u,c={unitId:t,subUnitId:n,ranges:o},m={unitId:t,subUnitId:n,reveal:!0,selections:o.map(p=>({range:p,primary:se(p,d),style:null}))},h=ga(s,c),R={unitId:t,subUnitId:n,selections:Br(o).map(p=>({range:p,primary:se(p,d),style:null}))},C=i.sequenceExecute([{id:ut.id,params:c},{id:q.id,params:m}],a),S=r.onCommandExecute({id:Et.id,params:e}),v=i.sequenceExecute([...S.redos],a);if(C.result&&v.result){const p=r.afterCommandExecute({id:Et.id,params:e});return i.sequenceExecute(p.redos,a),s.get(i.IUndoRedoService).pushUndoRedo({unitID:t,undoMutations:[{id:lt.id,params:h},{id:q.id,params:R},...(I=S.undos)!=null?I:[],...p.undos],redoMutations:[...(M=S.preRedos)!=null?M:[],{id:ut.id,params:c},{id:q.id,params:m},...S.redos,...p.redos]}),!0}return!0}},Ws={type:i.CommandType.COMMAND,id:"sheet.command.set-selected-cols-visible",handler:s=>{var d;const e=s.get(g.SheetsSelectionsService),t=s.get(i.ICommandService),n=(d=e.getCurrentSelections())==null?void 0:d.map(c=>c.range).filter(c=>c.rangeType===i.RANGE_TYPE.COLUMN);if(!(n!=null&&n.length))return!1;const o=P(s.get(i.IUniverInstanceService));if(!o)return!1;const{worksheet:r,unitId:a,subUnitId:l}=o,u=n.map(c=>r.getHiddenCols(c.startColumn,c.endColumn)).flat();return t.executeCommand(Et.id,{unitId:a,subUnitId:l,ranges:u})}},wn={type:i.CommandType.COMMAND,id:"sheet.command.set-col-hidden",handler:(s,e)=>{var M,p,w,y;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService);let a=(M=e==null?void 0:e.ranges)!=null&&M.length?e.ranges:(p=t.getCurrentSelections())==null?void 0:p.map(b=>b.range).filter(b=>b.rangeType===i.RANGE_TYPE.COLUMN);if(!(a!=null&&a.length))return!1;const l=P(o,e);if(!l)return!1;const{worksheet:u,unitId:d,subUnitId:c}=l;a=hu(l.worksheet,a);const m={unitId:d,subUnitId:c,ranges:a},h={unitId:d,subUnitId:c,selections:Br(a).map(b=>({range:b,primary:se(b,u),style:null}))},R=ha(s,m),C={unitId:d,subUnitId:c,reveal:!0,selections:a.map(b=>({range:b,primary:se(b,u),style:null}))},S=i.sequenceExecute([{id:lt.id,params:m},{id:q.id,params:h}],r),v=n.onCommandExecute({id:wn.id,params:m}),I=i.sequenceExecute([...v.redos],r);if(S.result&&I.result){const b=n.afterCommandExecute({id:wn.id,params:m});return i.sequenceExecute(b.redos,r),s.get(i.IUndoRedoService).pushUndoRedo({unitID:d,undoMutations:[{id:ut.id,params:R},{id:q.id,params:C},...(w=v.undos)!=null?w:[],...b.undos],redoMutations:[...(y=v.preRedos)!=null?y:[],{id:lt.id,params:m},{id:q.id,params:h},...v.redos,...b.redos]}),!0}return!1}};function hu(s,e){const t=s.getRowCount()-1,n=s.getHiddenCols(),o=[];return e.forEach(r=>{const a=n.filter(l=>l.startColumn>=r.startColumn&&l.endColumn<=r.endColumn);if(a.length){let l=r.startColumn;a.forEach(u=>{u.startColumn>l&&(o.push({startColumn:l,endColumn:u.startColumn-1,startRow:0,endRow:t}),l=u.endColumn+1)}),l<=r.endColumn&&o.push({startColumn:l,endColumn:r.endColumn,startRow:0,endRow:t})}else o.push(r)}),o}function Br(s){return gu(s).map(t=>{const n=t.startColumn===0?t.endColumn+1:t.startColumn-1;return{...t,startColumn:n,endColumn:n}})}function gu(s){const e=[];let t;return s.sort((n,o)=>n.startColumn-o.startColumn).forEach(n=>{if(!t){t=n;return}t.endColumn===n.startColumn-1?t.endColumn=n.endColumn:(e.push(t),t=n)}),e.push(t),e}const Vs={id:"sheet.command.set-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{var m,h;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService);if(!e)return!1;const r={...e},a=J.SetDefinedNameMutationFactory(s,e),l=o.onCommandExecute({id:Vs.id,params:e}),u=[...(m=l.preRedos)!=null?m:[],{id:J.RemoveDefinedNameMutation.id,params:a},{id:J.SetDefinedNameMutation.id,params:r},...l.redos],d=[...(h=l.preUndos)!=null?h:[],{id:J.RemoveDefinedNameMutation.id,params:r},{id:J.SetDefinedNameMutation.id,params:a},...l.undos];return i.sequenceExecute(u,t)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:d.filter(Boolean),redoMutations:u.filter(Boolean)}),!0):!1}},$s=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const a=o.getConfig().freeze;return{unitId:e.unitId,subUnitId:e.subUnitId,...a}},Oe={id:"sheet.mutation.set-frozen",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=o.getConfig(),{startRow:a,startColumn:l,ySplit:u,xSplit:d}=e;return r.freeze={startRow:a,startColumn:l,ySplit:u,xSplit:d},!0}},Fr={type:i.CommandType.COMMAND,id:"sheet.command.set-frozen",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,{unitId:e.unitId,subUnitId:e.subUnitId});if(!r)return!1;const{unitId:a,subUnitId:l,worksheet:u}=r,{startColumn:d,startRow:c,xSplit:m,ySplit:h}=e;if(c>=u.getRowCount()||d>=u.getColumnCount()||m>=u.getColumnCount()||h>=u.getRowCount())return!1;const R={unitId:a,subUnitId:l,...e},C=$s(s,R);return t.syncExecuteCommand(Oe.id,R)?(n.pushUndoRedo({unitID:a,undoMutations:[{id:Oe.id,params:C}],redoMutations:[{id:Oe.id,params:R}]}),!0):!1}},jr={type:i.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUniverInstanceService),o=s.get(i.IUndoRedoService),r=P(n,{unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId});if(!r)return!1;const{unitId:a,subUnitId:l}=r,u={unitId:a,subUnitId:l,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},d=$s(s,u);return t.syncExecuteCommand(Oe.id,u)&&o.pushUndoRedo({unitID:a,undoMutations:[{id:Oe.id,params:d}],redoMutations:[{id:Oe.id,params:u}]}),!0}},Gr={type:i.CommandType.COMMAND,id:"sheet.command.set-gridlines-color",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a}=r,l=a.getConfig().gridlinesColor;if(l===(e==null?void 0:e.color))return!1;const{unitId:u,subUnitId:d}=r,c={color:e==null?void 0:e.color,unitId:u,subUnitId:d},m={color:l,unitId:u,subUnitId:d};return t.syncExecuteCommand(dt.id,c)?(n.pushUndoRedo({unitID:u,undoMutations:[{id:dt.id,params:m}],redoMutations:[{id:dt.id,params:c}]}),!0):!1}},Q={id:"sheet.mutation.set-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rule:o,ruleId:r}=e;return s.get(X).setRule(t,n,r,o),!0}},Ru=(s,e)=>{const{unitId:t,subUnitId:n,ruleId:o}=e,a=s.get(X).getRule(t,n,o);return a?{id:Q.id,params:{...e,rule:a}}:null},st={id:"sheet.mutation.set-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rule:o}=e;return s.get(ke).setRule(t,n,o),!0}},zr={type:i.CommandType.COMMAND,id:"sheet.command.set-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(X),{rule:r,oldRule:a}=e,{unitId:l,subUnitId:u}=r,d=[],c=[];return(a==null?void 0:a.unitType)===r.unitType?r.unitType===N.Worksheet?(d.push({id:st.id,params:{unitId:l,subUnitId:u,rule:r}}),c.push({id:st.id,params:{unitId:l,subUnitId:u,rule:a}})):(d.push({id:Q.id,params:{unitId:l,subUnitId:u,rule:r,ruleId:r.id}}),c.push({id:Q.id,params:{unitId:l,subUnitId:u,ruleId:a.id,rule:a}})):(a&&(a.unitType===N.Worksheet?(d.push({id:tt.id,params:{unitId:l,subUnitId:u}}),c.push({id:Fe.id,params:{unitId:l,rule:a,subUnitId:a.subUnitId}})):a.unitType===N.SelectRange&&(d.push({id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:[a.id]}}),c.push({id:Ce.id,params:{unitId:l,subUnitId:u,rules:[a]}}))),r.unitType===N.Worksheet?(d.push({id:Fe.id,params:{unitId:l,rule:r,subUnitId:r.subUnitId}}),c.unshift({id:tt.id,params:{unitId:l,subUnitId:u}})):r.unitType===N.SelectRange&&(r.id=o.createRuleId(l,u),d.push({id:Ce.id,params:{unitId:l,subUnitId:u,rules:[r]}}),c.unshift({id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:[r.id]}}))),i.sequenceExecute(d,t)&&n.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:d}),!0}},qr={type:i.CommandType.COMMAND,id:"sheet.command.set-row-data",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{rowData:a}=e,{unitId:l,subUnitId:u,worksheet:d}=r,c={subUnitId:u,unitId:l,rowData:a},m=Ro(c,d);return t.syncExecuteCommand(ct.id,c)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:ct.id,params:m}],redoMutations:[{id:ct.id,params:c}]}),!0):!1}},Tt={type:i.CommandType.COMMAND,id:"sheet.command.set-specific-rows-visible",handler:(s,e)=>{var I,M,p;const{unitId:t,subUnitId:n,ranges:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(g.SheetInterceptorService),u=P(s.get(i.IUniverInstanceService),{unitId:t,subUnitId:n});if(!u)return!1;const{worksheet:d}=u,c={unitId:t,subUnitId:n,ranges:o},m={unitId:t,subUnitId:n,reveal:!0,selections:o.map(w=>({range:w,primary:se(w,d),style:null}))},h=ya(s,c),R={unitId:t,subUnitId:n,selections:Yr(o).map(w=>({range:w,primary:se(w,d),style:null}))},C=i.sequenceExecute([{id:Ye.id,params:c},{id:q.id,params:m}],r),S=l.onCommandExecute({id:Tt.id,params:e}),v=i.sequenceExecute([...S.redos],r);if(C.result&&v.result){const w=l.afterCommandExecute({id:Tt.id,params:e});return i.sequenceExecute(w.redos,r),a.pushUndoRedo({unitID:t,undoMutations:[...(I=S.preUndos)!=null?I:[],{id:Ke.id,params:h},{id:q.id,params:R},...(M=S.undos)!=null?M:[],...w.undos],redoMutations:[...(p=S.preRedos)!=null?p:[],{id:Ye.id,params:c},{id:q.id,params:m},...S.redos,...w.redos]}),!0}return!0}},Ls={type:i.CommandType.COMMAND,id:"sheet.command.set-selected-rows-visible",handler:async s=>{var c;const e=s.get(g.SheetsSelectionsService),t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=(c=e.getCurrentSelections())==null?void 0:c.map(m=>m.range).filter(m=>m.rangeType===i.RANGE_TYPE.ROW);if(!(o!=null&&o.length))return!1;const r=P(t);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=o.map(m=>a.getHiddenRows(m.startRow,m.endRow)).flat();return n.executeCommand(Tt.id,{unitId:l,subUnitId:u,ranges:d})}},Mn={type:i.CommandType.COMMAND,id:"sheet.command.set-rows-hidden",handler:(s,e)=>{var M,p,w,y,b,T;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=s.get(g.SheetInterceptorService);let l=(M=e==null?void 0:e.ranges)!=null&&M.length?e.ranges:(p=t.getCurrentSelections())==null?void 0:p.map(U=>U.range).filter(U=>U.rangeType===i.RANGE_TYPE.ROW);if(!(l!=null&&l.length))return!1;const u=P(r,e);if(!u)return!1;l=Cu(u.worksheet,l);const{unitId:d,subUnitId:c,worksheet:m}=u,h={unitId:d,subUnitId:c,ranges:l},R={unitId:d,subUnitId:c,selections:Yr(l).map(U=>({range:U,primary:se(U,m),style:null}))},C=_a(s,h),S={unitId:d,subUnitId:c,reveal:!0,selections:l.map(U=>({range:U,primary:se(U,m),style:null}))},v=a.onCommandExecute({id:Mn.id,params:h});if(i.sequenceExecute([...(w=v.preRedos)!=null?w:[],{id:Ke.id,params:h},{id:q.id,params:R},...v.redos],n).result){const U=a.afterCommandExecute({id:Mn.id,params:h});return i.sequenceExecute(U.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(y=v.preUndos)!=null?y:[],{id:Ye.id,params:C},{id:q.id,params:S},...(b=v.undos)!=null?b:[],...U.undos],redoMutations:[...(T=v.preRedos)!=null?T:[],{id:Ke.id,params:h},{id:q.id,params:R},...v.redos,...U.redos]}),!0}return!0}};function Cu(s,e){const t=s.getMaxColumns()-1,n=s.getHiddenRows(),o=[];return e.forEach(r=>{const a=n.filter(l=>l.startRow>=r.startRow&&l.endRow<=r.endRow);if(a.length){let l=r.startRow;a.forEach(u=>{u.startRow>l&&(o.push({startRow:l,endRow:u.startRow-1,startColumn:0,endColumn:t}),l=u.endRow+1)}),l<=r.endRow&&o.push({startRow:l,endRow:r.endRow,startColumn:0,endColumn:t})}else o.push(r)}),o}function Yr(s){return Su(s).map(t=>{const n=t.startRow===0?t.endRow+1:t.startRow-1;return{...t,startRow:n,endRow:n}})}function Su(s){const e=[];let t;return s.sort((n,o)=>n.startRow-o.startRow).forEach(n=>{if(!t){t=n;return}n.startRow===t.endRow+1?t.endRow=n.endRow:(e.push(t),t=n)}),e.push(t),e}const fu=["ff","fs","tr","tb"],ee={type:i.CommandType.COMMAND,id:"sheet.command.set-style",handler:(s,e)=>{var k;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{unitId:o,subUnitId:r,worksheet:a}=n,{range:l,style:u}=e,d=s.get(i.ICommandService),c=s.get(i.IUndoRedoService),m=s.get(g.SheetsSelectionsService),h=l?[l]:(k=m.getCurrentSelections())==null?void 0:k.map(E=>E.range);if(!(h!=null&&h.length))return!1;const R=new i.ObjectMatrix,C=ll(a);if(i.Tools.isArray(u.value))for(let E=0;E<h.length;E++)C.forOperableEach(h[E],(O,W,V)=>{R.setValue(O,W,{s:{[u.type]:u.value[O-V.startRow][W-V.startColumn]}})});else for(let E=0;E<h.length;E++){const O={s:{[u.type]:u.value}};C.forOperableEach(h[E],(W,V)=>R.setValue(W,V,O))}const S={subUnitId:r,unitId:o,cellValue:R.getMatrix()},v=s.get(g.SheetSkeletonService).getSkeleton(o,r),I=ce(s,S),M=d.syncExecuteCommand(F.id,S),p=s.get(g.SheetInterceptorService);let w=[],y=[];if(fu.includes(e==null?void 0:e.style.type)){const{suitableRanges:E,remainingRanges:O}=Ht(h,v),W=_s(E,a),{undos:V,redos:$}=p.generateMutationsOfAutoHeight({unitId:o,subUnitId:r,ranges:E,autoHeightRanges:E,lazyAutoHeightRanges:O,cellHeights:W});w=V,y=$}const{undos:b,redos:T}=p.onCommandExecute({id:ee.id,params:e}),U=i.sequenceExecute([...T,...y],d);return M&&U.result?(c.pushUndoRedo({unitID:S.unitId,undoMutations:[{id:F.id,params:I},...b,...w],redoMutations:[{id:F.id,params:S},...T,...y]}),!0):!1}},vu={type:i.CommandType.COMMAND,id:"sheet.command.set-bold",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t,{actualRow:o,actualColumn:r}=e.primary,l={style:{type:"bl",value:n.getRange(o,r).getFontWeight()===i.FontWeight.BOLD?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,l)}},Iu={type:i.CommandType.COMMAND,id:"sheet.command.set-italic",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;if(e.primary){const{startRow:a,startColumn:l}=e.primary;o=n.getRange(a,l).getFontStyle()===i.FontItalic.ITALIC}const r={style:{type:"it",value:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},pu={type:i.CommandType.COMMAND,id:"sheet.command.set-underline",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.startRow,e.primary.startColumn).getUnderline().s);const r={style:{type:"ul",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},wu={type:i.CommandType.COMMAND,id:"sheet.command.set-stroke",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.actualRow,e.primary.actualColumn).getStrikeThrough().s);const r={style:{type:"st",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},Mu={type:i.CommandType.COMMAND,id:"sheet.command.set-overline",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.startRow,e.primary.startColumn).getOverline().s);const r={style:{type:"ol",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},yu={type:i.CommandType.COMMAND,id:"sheet.command.set-font-family",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"ff",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},_u={type:i.CommandType.COMMAND,id:"sheet.command.set-font-size",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"fs",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},Kr={type:i.CommandType.COMMAND,id:"sheet.command.set-text-color",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"cl",value:{rgb:e.value}}};return t.syncExecuteCommand(ee.id,n)}},Jr={type:i.CommandType.COMMAND,id:"sheet.command.reset-text-color",handler:s=>{const e=s.get(i.ICommandService),t={style:{type:"cl",value:{rgb:null}}};return e.syncExecuteCommand(ee.id,t)}},xr={type:i.CommandType.COMMAND,id:"sheet.command.set-background-color",handler:(s,e)=>{if(!e||!e.value)return!1;const t=s.get(i.ICommandService),n={style:{type:"bg",value:{rgb:e.value}}};return t.syncExecuteCommand(ee.id,n)}},Xr={type:i.CommandType.COMMAND,id:"sheet.command.reset-background-color",handler:s=>{const e=s.get(i.ICommandService),t={style:{type:"bg",value:{rgb:null}}};return e.syncExecuteCommand(ee.id,t)}},Zr={type:i.CommandType.COMMAND,id:"sheet.command.set-vertical-text-align",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"vt",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},Qr={type:i.CommandType.COMMAND,id:"sheet.command.set-horizontal-text-align",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"ht",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},ei={type:i.CommandType.COMMAND,id:"sheet.command.set-text-wrap",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"tb",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},ti={type:i.CommandType.COMMAND,id:"sheet.command.set-text-rotation",handler:(s,e)=>{if(!e)return!1;const t=typeof e.value=="number"?{a:e.value}:{a:0,v:i.BooleanNumber.TRUE},n=s.get(i.ICommandService),o={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"tr",value:t}};return n.syncExecuteCommand(ee.id,o)}},bu=(s,e)=>{const r=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor;return{...i.Tools.deepClone(e),color:r}},jt={id:"sheet.mutation.set-tab-color",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().tabColor=e.color,!0):!1}},ni={type:i.CommandType.COMMAND,id:"sheet.command.set-tab-color",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService));if(!o)return!1;const{unitId:r,subUnitId:a}=o,l={color:e.value,unitId:r,subUnitId:a},u=bu(s,l);return t.syncExecuteCommand(jt.id,l)?(n.pushUndoRedo({unitID:r,undoMutations:[{id:jt.id,params:u}],redoMutations:[{id:jt.id,params:l}]}),!0):!1}},Hs={id:"sheet.mutation.set-workbook-name",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUnit(e.unitId,i.UniverInstanceType.UNIVER_SHEET);return t?(t.setName(e.name),!0):!1}},Bs={type:i.CommandType.COMMAND,id:"sheet.command.set-workbook-name",handler:(s,e)=>{var u;const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService);if(!Hn(s.get(i.IUniverInstanceService),e))return!1;const r=n.onCommandExecute({id:Bs.id,params:e}),a={name:e.name,unitId:e.unitId},l=[...(u=r.preRedos)!=null?u:[],{id:Hs.id,params:a},...r.redos];return i.sequenceExecute(l,t).result}},Eu=4,Fs={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-activate",handler:(s,e,t)=>{const n=s.get(i.ICommandService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{unitId:r,subUnitId:a}=o;return new Promise(l=>{setTimeout(()=>{const u=n.syncExecuteCommand(Ct.id,{unitId:r,subUnitId:a},t);l(u)},Eu)})}},Gt={type:i.CommandType.COMMAND,id:"sheet.command.delta-column-width",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();if(!(n!=null&&n.length))return!1;const o=s.get(i.ICommandService),r=s.get(i.IUndoRedoService),a=P(s.get(i.IUniverInstanceService));if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,{anchorCol:c,deltaX:m}=e,R=l.getColumnWidth(c)+m,C=n.length===1&&n[0].range.rangeType===i.RANGE_TYPE.ALL,S=n.filter(L=>L.range.rangeType===i.RANGE_TYPE.COLUMN),v=C?i.RANGE_TYPE.ALL:S.some(({range:L})=>{const{startColumn:Y,endColumn:z}=L;return Y<=c&&c<=z})?i.RANGE_TYPE.COLUMN:i.RANGE_TYPE.NORMAL;let I;if(v===i.RANGE_TYPE.ALL){const L=l.getRowCount(),Y=new Array(l.getColumnCount()).fill(void 0).map((z,K)=>({startRow:0,endRow:L-1,startColumn:K,endColumn:K}));I={subUnitId:d,unitId:u,colWidth:R,ranges:Y}}else v===i.RANGE_TYPE.COLUMN?I={subUnitId:d,unitId:u,ranges:S.map(L=>i.Rectangle.clone(L.range)),colWidth:R}:I={subUnitId:d,unitId:u,colWidth:R,ranges:[{startRow:0,endRow:l.getMaxRows()-1,startColumn:c,endColumn:c}]};const M=s.get(g.SheetSkeletonService).getSkeleton(u,d),{suitableRanges:p,remainingRanges:w}=Ht(I.ranges,M);_s(p,l);const y=s.get(g.SheetInterceptorService),{undos:b,redos:T}=y.onCommandExecute({id:Gt.id,params:I}),U=Bn(I,l),k=o.syncExecuteCommand(Ve.id,I),{undos:E,redos:O}=y.generateMutationsOfAutoHeight({unitId:u,subUnitId:d,ranges:p,autoHeightRanges:p,lazyAutoHeightRanges:w}),{undos:W,redos:V}=s.get(g.SheetInterceptorService).afterCommandExecute({id:Gt.id,params:I}),$=i.sequenceExecute([...T,...V,...O],o);return k&&$.result&&r.pushUndoRedo({unitID:u,undoMutations:[{id:Ve.id,params:U},...b,...W,...E],redoMutations:[{id:Ve.id,params:I},...T,...V,...O]}),!0}},zt={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-col-width",handler:(s,e)=>{var y,b,T,U;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(g.SheetInterceptorService),a=(y=e==null?void 0:e.ranges)!=null&&y.length?e.ranges:(b=t.getCurrentSelections())==null?void 0:b.map(k=>k.range);if(!(a!=null&&a.length))return!1;const l=P(s.get(i.IUniverInstanceService),e);if(!l)return!1;const{subUnitId:u,unitId:d,worksheet:c}=l,m=s.get(g.SheetSkeletonService).getSkeleton(d,u),h={subUnitId:u,unitId:d,ranges:a,colWidth:e.value},{suitableRanges:R,remainingRanges:C}=Ht(h.ranges,m);_s(R,c);const S=Bn(h,c),v=n.syncExecuteCommand(Ve.id,h),{undos:I,redos:M}=r.generateMutationsOfAutoHeight({unitId:d,subUnitId:u,ranges:R,autoHeightRanges:R,lazyAutoHeightRanges:C}),p=r.onCommandExecute({id:zt.id,params:h}),w=i.sequenceExecute([...p.redos,...M],n);if(v&&w.result){const k=r.afterCommandExecute({id:zt.id,params:h});return i.sequenceExecute(k.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(T=p.preUndos)!=null?T:[],{id:Ve.id,params:S},...p.undos,...k.undos,...I],redoMutations:[...(U=p.preRedos)!=null?U:[],{id:Ve.id,params:h},...p.redos,...k.redos,...M]}),!0}return!1}};i.CommandType.COMMAND;const si={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-column-count",handler:(s,e)=>{const{unitId:t,subUnitId:n,columnCount:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(i.IUniverInstanceService);if(!P(l,e))return!1;const d={unitId:t,subUnitId:n,columnCount:o},c=Co(s,d);return r.syncExecuteCommand(mt.id,d)?(a.pushUndoRedo({unitID:t,undoMutations:[{id:mt.id,params:c}],redoMutations:[{id:mt.id,params:d}]}),!0):!1}},oi={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-default-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=So(s,e);return t.syncExecuteCommand(ht.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:ht.id,params:r}],redoMutations:[{id:ht.id,params:e}]}),!0):!1}},ri=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{hidden:n.isSheetHidden(),unitId:e.unitId,subUnitId:n.getSheetId()}},je={id:"sheet.mutation.set-worksheet-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(t==null)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().hidden=e.hidden,!0):!1}},ii={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-hidden",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.ErrorService),r=s.get(i.LocaleService),a=P(s.get(i.IUniverInstanceService),e);if(!a)return!1;const{workbook:l,worksheet:u,unitId:d,subUnitId:c}=a;if(u.getConfig().hidden===i.BooleanNumber.TRUE)return!1;const h={unitId:d,subUnitId:c,hidden:i.BooleanNumber.TRUE},R=ri(s,h);return l.getSheets().filter(I=>I.getConfig().hidden===i.BooleanNumber.FALSE).length===1?(o.emit(r.t("sheets.info.hideSheet")),!1):t.syncExecuteCommand(je.id,h)?(n.pushUndoRedo({unitID:d,undoMutations:[{id:je.id,params:R}],redoMutations:[{id:je.id,params:h}]}),!0):!1}},Tu=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,name:n.getName(),subUnitId:n.getSheetId()}},qt={id:"sheet.mutation.set-worksheet-name",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(t==null)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().name=e.name,!0):!1}},yn={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-name",handler:(s,e)=>{var C,S;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService),r=P(s.get(i.IUniverInstanceService),e);if(!r)return!1;const{unitId:a,subUnitId:l}=r,u={subUnitId:l,name:e.name,unitId:a},d=Tu(s,u),c=o.onCommandExecute({id:yn.id,params:e}),m=[...(C=c.preRedos)!=null?C:[],{id:qt.id,params:u},...c.redos],h=[...(S=c.preUndos)!=null?S:[],{id:qt.id,params:d},...c.undos];return i.sequenceExecute(m,t).result?(n.pushUndoRedo({unitID:a,undoMutations:h,redoMutations:m}),!0):!1}},Uu=(s,e)=>({...i.Tools.deepClone(e),toOrder:e.fromOrder,fromOrder:e.toOrder}),Yt={id:"sheet.mutation.set-worksheet-order",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getConfig();return n.sheetOrder.splice(e.fromOrder,1),n.sheetOrder.splice(e.toOrder,0,e.subUnitId),!0}},js={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-order",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{workbook:r,unitId:a,subUnitId:l}=o,d={fromOrder:r.getConfig().sheetOrder.indexOf(l),toOrder:e.order,unitId:a,subUnitId:l},c=Uu(s,d);return t.syncExecuteCommand(Yt.id,d)?(n.pushUndoRedo({unitID:a,undoMutations:[{id:Yt.id,params:c}],redoMutations:[{id:Yt.id,params:d}]}),!0):!1}};class Ut{constructor(){f(this,"_model",new Map);f(this,"_pointChange",new D.Subject);f(this,"pointChange$",this._pointChange.asObservable())}addRule(e){this._ensureSubUnitMap(e.unitId).set(e.subUnitId,e),this._pointChange.next(e)}deleteRule(e,t){var o,r,a;const n=(o=this._model.get(e))==null?void 0:o.get(t);n&&((a=(r=this._model)==null?void 0:r.get(e))==null||a.delete(t),this._pointChange.next(n))}getRule(e,t){var n,o;return(o=(n=this._model)==null?void 0:n.get(e))==null?void 0:o.get(t)}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n);o!=null&&o.size&&(e[n]=[],[...o.keys()].forEach(a=>{const l=o.get(a);l&&e[n].push(l)}))}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n];if(o!=null&&o.length){const r=new Map;o.forEach(a=>{r.set(a.subUnitId,a)}),t.set(n,r)}}),this._model=t}deleteUnitModel(e){this._model.delete(e)}_ensureSubUnitMap(e){let t=this._model.get(e);return t||(t=new Map,this._model.set(e,t)),t}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)if(r.permissionId===t)return[e,o]}}class Gs{constructor(e,t,n){f(this,"type",N.SelectRange);f(this,"subType",_.Delete);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${N.SelectRange}.${_.Delete}.${n}`}}class zs{constructor(e,t,n){f(this,"type",N.SelectRange);f(this,"subType",_.ManageCollaborator);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${N.SelectRange}.${_.ManageCollaborator}.${n}`}}const ue=()=>[ln,Se,zs,Gs],Ge=[_.Edit,_.View,_.ManageCollaborator,_.Delete],Pu=(s="unitId",e="subUnitId",t="permissionId")=>ue().reduce((n,o)=>{const r=new o(s,e,t);return n[r.subType]=r.value,n},{}),Pt=()=>[me,es,Yn,ss,Kn,Qn,dn,xn,Xn,mn,un,Zn,ns,cn,Bo,os,ts,Jn,qo,zo,jo,Fo],ai=[_.Edit,_.Print,_.Comment,_.View,_.Copy,_.Export,_.ManageCollaborator,_.CreateSheet,_.DeleteSheet,_.RenameSheet,_.HideSheet,_.Duplicate,_.Share,_.MoveSheet,_.CopySheet,_.RecoverHistory,_.ViewHistory,_.CreatePermissionObject,_.InsertRow,_.InsertColumn,_.DeleteRow,_.DeleteColumn],de=()=>[fe,Vt,gs,as],ve=()=>[rs,is,ls,us,ds,cs,hs,ms,Rs,Cs,Wt,St,ft,Ss],_n=[_.Copy,_.DeleteColumn,_.DeleteRow,_.EditExtraObject,_.Filter,_.InsertColumn,_.InsertRow,_.InsertHyperlink,_.PivotTable,_.SetCellStyle,_.SetCellValue,_.SetColumnStyle,_.SetRowStyle,_.Sort];var ku=Object.getOwnPropertyDescriptor,Ou=(s,e,t,n)=>{for(var o=n>1?void 0:n?ku(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},ze=(s,e)=>(t,n)=>e(t,n,s);const Du="SHEET_WORKSHEET_PROTECTION_PLUGIN",Nu="SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN";g.WorksheetPermissionService=class extends i.RxDisposable{constructor(e,t,n,o,r,a,l,u){super(),this._permissionService=e,this._univerInstanceService=t,this._injector=n,this._worksheetProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=r,this._resourceManagerService=a,this._rangeProtectionRuleModel=l,this._logService=u,this._init(),this._initRuleChange(),this._initRuleSnapshot(),this._initPointSnapshot()}_init(){const e=t=>{const n=t.getUnitId(),o=r=>{const a=r.getSheetId();[...de(),...ve()].forEach(l=>{const u=new l(n,a);this._permissionService.addPermissionPoint(u)}),this._logService.debug("[WorksheetPermissionService]","Initialization completed",n,a)};t.getSheets().forEach(r=>{o(r)}),t.sheetCreated$.subscribe(r=>{o(r)}),t.sheetDisposed$.subscribe(r=>{const a=r.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(n,a).forEach(u=>{[...ue()].forEach(d=>{const c=new d(n,a,u.permissionId);this._permissionService.deletePermissionPoint(c.id)})}),[...de(),...ve()].forEach(u=>{const d=new u(n,a);this._permissionService.deletePermissionPoint(d.id)})})};this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(t=>{e(t)}),this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).pipe(kt.takeUntil(this.dispose$)).subscribe(e),this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).pipe(kt.takeUntil(this.dispose$)).subscribe(t=>{t.getSheets().forEach(n=>{const o=t.getUnitId(),r=n.getSheetId();de().forEach(a=>{const l=new a(o,r);this._permissionService.deletePermissionPoint(l.id)})})})}_initRuleChange(){this.disposeWithMe(this._worksheetProtectionRuleModel.ruleChange$.subscribe(e=>{switch(e.type){case"add":break;case"delete":{de().forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,!0)});break}case"set":{de().forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,e.rule)});break}}}))}_initRuleSnapshot(){const e=()=>{const n=this._worksheetProtectionRuleModel.toObject();return JSON.stringify(n)},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Du,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{this._worksheetProtectionRuleModel.fromObject(o),Object.keys(o).forEach(r=>{de().forEach(a=>{const l=new a(n,r);l.value=!1,this._permissionService.addPermissionPoint(l)})}),this._worksheetProtectionRuleModel.changeRuleInitState(!0)},onUnLoad:n=>{const o=this._univerInstanceService.getUnit(n);o&&(o.getSheets().forEach(r=>{const a=r.getSheetId();[...de(),...ve()].forEach(l=>{const u=new l(n,a);this._permissionService.deletePermissionPoint(u.id)})}),Pt().forEach(r=>{const a=new r(n);this._permissionService.deletePermissionPoint(a.id)})),this._worksheetProtectionRuleModel.deleteUnitModel(n)}}))}_initPointSnapshot(){const e=()=>{const n=this._worksheetProtectionPointRuleModel.toObject();return JSON.stringify(n)},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Nu,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{this._worksheetProtectionPointRuleModel.fromObject(o),Object.keys(o).forEach(r=>{ve().forEach(a=>{const l=new a(n,r);this._permissionService.addPermissionPoint(l)})})},onUnLoad:n=>{this._worksheetProtectionPointRuleModel.deleteUnitModel(n)}}))}},g.WorksheetPermissionService=Ou([ze(0,i.Inject(i.IPermissionService)),ze(1,i.Inject(i.IUniverInstanceService)),ze(2,i.Inject(i.Injector)),ze(3,i.Inject(ke)),ze(4,i.Inject(Ut)),ze(5,i.Inject(i.IResourceManagerService)),ze(6,i.Inject(X)),ze(7,i.Inject(i.ILogService))],g.WorksheetPermissionService);const bn={id:"sheet.mutation.set-worksheet-permission-points",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rule:t}=e;return s.get(Ut).addRule(t),!0}},li={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-permission-points",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),{rule:n}=e;return t.executeCommand(bn.id,{rule:n,unitId:n.unitId,subUnitId:n.subUnitId}),!0}},ui={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,permissionId:r,oldRule:a}=e,{unitId:l,subUnitId:u}=o,d={...o,permissionId:r};if(await t.executeCommand(st.id,{unitId:l,subUnitId:u,newRule:d})){const m=[{id:st.id,params:{unitId:l,subUnitId:u,newRule:d}}],h=[{id:st.id,params:{unitId:l,subUnitId:u,rule:a}}];n.pushUndoRedo({unitID:l,redoMutations:m,undoMutations:h})}return!0}},Au=(s,e)=>{const r=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft;return{...i.Tools.deepClone(e),rightToLeft:r}},En={id:"sheet.mutation.set-worksheet-right-to-left",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getSheetBySheetId(e.subUnitId);if(!n)return!1;const o=n.getConfig();return o.rightToLeft=e.rightToLeft,!0}},Wu={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-right-to-left",handler:async(s,e)=>{var m;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{unitId:r,subUnitId:a}=o;let l=i.BooleanNumber.FALSE;e&&(l=(m=e.rightToLeft)!=null?m:i.BooleanNumber.FALSE);const u={rightToLeft:l,unitId:r,subUnitId:a},d=Au(s,u);return t.syncExecuteCommand(En.id,u)?(n.pushUndoRedo({unitID:r,undoMutations:[{id:En.id,params:d}],redoMutations:[{id:En.id,params:u}]}),!0):!1}},di={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-row-count",handler:(s,e)=>{const{unitId:t,subUnitId:n,rowCount:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(i.IUniverInstanceService);if(!P(l,e))return!1;const d={unitId:t,subUnitId:n,rowCount:o},c=fo(s,d);return r.syncExecuteCommand(gt.id,d)?(a.pushUndoRedo({unitID:t,undoMutations:[{id:gt.id,params:c}],redoMutations:[{id:gt.id,params:d}]}),!0):!1}},Kt={type:i.CommandType.COMMAND,id:"sheet.command.delta-row-height",handler:async(s,e)=>{var k,E;const n=s.get(g.SheetsSelectionsService).getCurrentSelections(),o=s.get(g.SheetInterceptorService);if(!(n!=null&&n.length))return!1;const r=P(s.get(i.IUniverInstanceService));if(!r)return!1;const{worksheet:a,subUnitId:l,unitId:u}=r,{anchorRow:d,deltaY:c}=e,h=a.getRowHeight(d)+c,R=n.length===1&&n[0].range.rangeType===i.RANGE_TYPE.ALL,C=n.filter(O=>O.range.rangeType===i.RANGE_TYPE.ROW),S=R?i.RANGE_TYPE.ALL:C.some(({range:O})=>{const{startRow:W,endRow:V}=O;return W<=d&&d<=V})?i.RANGE_TYPE.ROW:i.RANGE_TYPE.NORMAL;let v;if(S===i.RANGE_TYPE.ALL){const O=a.getColumnCount(),W=new Array(a.getRowCount()).fill(void 0).map((V,$)=>({startRow:$,endRow:$,startColumn:0,endColumn:O-1}));v={subUnitId:l,unitId:u,rowHeight:h,ranges:W}}else S===i.RANGE_TYPE.ROW?v={subUnitId:l,unitId:u,ranges:C.map(O=>i.Rectangle.clone(O.range)),rowHeight:h}:v={subUnitId:l,unitId:u,rowHeight:h,ranges:[{startRow:d,endRow:d,startColumn:0,endColumn:a.getMaxColumns()-1}]};const I=vo(v,a),M={unitId:u,subUnitId:l,ranges:v.ranges,autoHeightInfo:i.BooleanNumber.FALSE},p=Fn(M,a),w=s.get(i.ICommandService),y=s.get(i.IUndoRedoService),b=o.onCommandExecute({id:Kt.id,params:v}),T=i.sequenceExecute([{id:Ee.id,params:v},{id:Re.id,params:M}],w),U=i.sequenceExecute([...b.redos],w);if(T.result&&U.result){const O=o.afterCommandExecute({id:Kt.id,params:v});return i.sequenceExecute(O.redos,w),y.pushUndoRedo({unitID:u,undoMutations:[...(k=b.preUndos)!=null?k:[],{id:Ee.id,params:I},{id:Re.id,params:p},...b.undos,...O.undos],redoMutations:[...(E=b.preRedos)!=null?E:[],{id:Ee.id,params:v},{id:Re.id,params:M},...b.redos,...O.redos]}),!0}return!1}},Jt={type:i.CommandType.COMMAND,id:"sheet.command.set-row-height",handler:(s,e)=>{var p,w,y,b;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=s.get(g.SheetInterceptorService),l=(p=e==null?void 0:e.ranges)!=null&&p.length?e.ranges:(w=t.getCurrentSelections())==null?void 0:w.map(T=>T.range);if(!(l!=null&&l.length))return!1;const u=P(r,e);if(!u)return!1;const{unitId:d,subUnitId:c,worksheet:m}=u,h={subUnitId:c,unitId:d,ranges:l,rowHeight:e.value},R=vo(h,m),C={unitId:d,subUnitId:c,ranges:h.ranges,autoHeightInfo:i.BooleanNumber.FALSE},S=Fn(C,m),v=i.sequenceExecute([{id:Ee.id,params:h},{id:Re.id,params:C}],n),I=a.onCommandExecute({id:Jt.id,params:h}),M=i.sequenceExecute([...I.redos],n);if(v.result&&M.result){const T=a.afterCommandExecute({id:Jt.id,params:h});return i.sequenceExecute(T.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(y=I.preRedos)!=null?y:[],{id:Ee.id,params:R},{id:Re.id,params:S},...I.undos,...T.undos],redoMutations:[...(b=I.preRedos)!=null?b:[],{id:Ee.id,params:h},{id:Re.id,params:C},...I.redos,...T.redos]}),!0}return!1}},Tn={type:i.CommandType.COMMAND,id:"sheet.command.set-row-is-auto-height",handler:(s,e)=>{var T,U;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUniverInstanceService),a=P(r,e);if(!a)return!1;const{unitId:l,subUnitId:u,worksheet:d}=a,c=(T=e==null?void 0:e.ranges)!=null&&T.length?e.ranges:(U=o.getCurrentSelections())==null?void 0:U.map(k=>k.range);if(!(c!=null&&c.length))return!1;const m={unitId:l,subUnitId:u,ranges:c,autoHeightInfo:i.BooleanNumber.TRUE},h=Fn(m,d),R=t.syncExecuteCommand(Re.id,m),C=s.get(g.SheetSkeletonService).getSkeleton(l,u),{suitableRanges:S,remainingRanges:v}=Ht(m.ranges,C),I=s.get(g.SheetInterceptorService),{undos:M,redos:p}=I.generateMutationsOfAutoHeight({unitId:l,subUnitId:u,ranges:S,autoHeightRanges:S,lazyAutoHeightRanges:v}),{undos:w,redos:y}=I.onCommandExecute({id:Tn.id,params:m}),b=i.sequenceExecute([...y,...p],t);return R&&b.result?(n.pushUndoRedo({unitID:l,undoMutations:[{id:Re.id,params:h},...w,...M],redoMutations:[{id:Re.id,params:m},...y,...p]}),!0):!1}},qs={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-show",handler:(s,e)=>{const{unitId:t,subUnitId:n}=e,o=s.get(i.ICommandService),r=s.get(i.IUndoRedoService),a=s.get(i.IUniverInstanceService);if(!P(s.get(i.IUniverInstanceService)))return!1;const u=a.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!u)return!1;const d=u.getSheetBySheetId(n);if(!d||d.getConfig().hidden===i.BooleanNumber.FALSE)return!1;const m={unitId:t,subUnitId:n,hidden:i.BooleanNumber.FALSE},h=ri(s,m),R=o.syncExecuteCommand(je.id,m),C={unitId:t,subUnitId:n},S=o.syncExecuteCommand(Ct.id,C);return R&&S?(r.pushUndoRedo({unitID:t,undoMutations:[{id:je.id,params:h}],redoMutations:[{id:je.id,params:m}]}),!0):!1}},ci={type:i.CommandType.COMMAND,id:"sheet.command.split-text-to-columns",handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,delimiter:r,customDelimiter:a,treatMultipleDelimitersAsOne:l}=e,u=s.get(i.ICommandService),d=s.get(i.IUniverInstanceService),c=s.get(i.IUndoRedoService);if(!P(s.get(i.IUniverInstanceService)))return!1;const h=d.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!h)return!1;const R=h.getSheetBySheetId(n);if(!R)return!1;const{lastRow:C,rs:S,maxLength:v}=To(R,o,r,a,l),I=R.getColumnCount(),{startColumn:M}=i.Range.transformRange(o,R);if(o.startColumn!==o.endColumn)return!1;const p=[],w=[],y=M+v+1-I;if(y>0){const O={unitId:t,subUnitId:n,range:{startRow:0,endRow:R.getRowCount()-1,startColumn:I-1,endColumn:I-1+y}};p.push({id:ie.id,params:O});const W=Ot(s,O);w.push({id:ne.id,params:W})}const b={startRow:o.startRow,endRow:C,startColumn:M,endColumn:M+v},T=new i.ObjectMatrix;for(let O=b.startRow;O<=b.endRow;O++)for(let W=b.startColumn;W<=b.endColumn;W++){const V=S[O-b.startRow];W===0&&(V==null?void 0:V.length)===1?T.setValue(O,W,R.getCell(O,W)):T.setValue(O,W,{v:(V==null?void 0:V[W-b.startColumn])||null,p:null,f:null,si:null,custom:null})}const U={unitId:t,subUnitId:n,cellValue:T.clone()},k=ce(s,U);return p.push({id:F.id,params:U}),w.unshift({id:F.id,params:k}),i.sequenceExecute(p,u).result?(c.pushUndoRedo({unitID:t,undoMutations:w,redoMutations:p}),!0):!1}},mi={id:"sheet.command.toggle-cell-checkbox",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,row:o,col:r,paragraphIndex:a}=e,u=s.get(i.IUniverInstanceService).getUnit(t,i.UniverInstanceType.UNIVER_SHEET),d=u==null?void 0:u.getSheetBySheetId(n),c=s.get(i.IUndoRedoService),m=s.get(i.ICommandService);if(!d)return!1;const h=d.getCell(o,r);if(!(h!=null&&h.p))return!1;const R=i.Tools.deepClone(h.p),C=new i.DocumentDataModel(R),S=i.BuildTextUtils.paragraph.bullet.toggleChecklist({document:C,paragraphIndex:a});if(!S)return!1;i.TextX.apply(C.getBody(),S.serialize());const v={unitId:t,subUnitId:n,cellValue:{[o]:{[r]:{p:R,t:i.CellValueType.STRING}}}},I={id:F.id,params:v},M=ce(s,v),p={id:F.id,params:M},w=[I],y=[p];return c.pushUndoRedo({redoMutations:w,undoMutations:y,unitID:t}),m.syncExecuteCommand(I.id,I.params)}},hi={type:i.CommandType.COMMAND,id:"sheet.command.toggle-gridlines",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a}=r,l=a.getConfig().showGridlines;if(l===(e==null?void 0:e.showGridlines))return!1;const{unitId:u,subUnitId:d}=r,c={showGridlines:l===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE,unitId:u,subUnitId:d},m={showGridlines:l,unitId:u,subUnitId:d};return t.syncExecuteCommand(Rt.id,c)?(n.pushUndoRedo({unitID:u,undoMutations:[{id:Rt.id,params:m}],redoMutations:[{id:Rt.id,params:c}]}),!0):!1}},gi={id:"sheet.command.unregister-worksheet-range-theme-style",type:i.CommandType.COMMAND,handler:(s,e)=>{var h;if(!e)return!1;const{unitId:t,themeName:n}=e,o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(g.SheetRangeThemeModel);if(!P(o))return!1;const d={unitId:t,themeName:n},c={unitId:t,themeName:n,rangeThemeStyleJson:(h=l.getRangeThemeStyle(t,n))==null?void 0:h.toJson()};return r.syncExecuteCommand(_t.id,e)&&a.pushUndoRedo({unitID:t,undoMutations:[{id:_t.id,params:c}],redoMutations:[{id:vn.id,params:d}]}),!0}},Ri={id:"sheet.mutation.add-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{styleJSON:t,unitId:n}=e,o=s.get(g.SheetRangeThemeModel),r=new We(t.name);return r.fromJson(t),o.registerRangeThemeStyle(n,r),!0}},Ci={id:"sheet.mutation.empty",type:i.CommandType.MUTATION,handler:()=>!0},Si={id:"sheet.operation.mark-dirty-row-auto-height",type:i.CommandType.OPERATION,handler:()=>!0},fi={id:"sheet.operation.cancel-mark-dirty-row-auto-height",type:i.CommandType.OPERATION,handler:()=>!0},ot=i.createIdentifier("INumfmtService"),Vu=(s,e)=>{const t=s.get(ot),{values:n,unitId:o,subUnitId:r}=e,a=[],l=[];Object.keys(n).forEach(d=>{n[d].ranges.forEach(m=>{i.Range.foreach(m,(h,R)=>{const C=t.getValue(o,r,h,R);C?a.push({pattern:C.pattern,row:h,col:R}):l.push({startColumn:R,endColumn:R,startRow:h,endRow:h})})})});const u=[];if(a.length){const d=Pn(o,r,a);Object.keys(d.values).forEach(c=>{const m=d.values[c];m.ranges=zn(m.ranges)}),u.push({id:Un.id,params:Pn(o,r,a)})}return l.length&&u.push({id:Ys.id,params:{unitId:o,subUnitId:r,ranges:l}}),u},Un={id:"sheet.mutation.set.numfmt",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{values:t,refMap:n}=e,o=s.get(ot),r=e.unitId,a=e.subUnitId,l=Object.keys(t).reduce((u,d)=>{const c=n[d],m=t[d].ranges;return c&&u.push({...c,ranges:m}),u},[]);return o.setValues(r,a,l),!0}},Ys={id:"sheet.mutation.remove.numfmt",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,ranges:o}=e;return s.get(ot).deleteValues(t,n,o),!0}},$u=(s,e)=>{const t=s.get(ot),{ranges:n,unitId:o,subUnitId:r}=e,a=[];if(n.forEach(u=>{i.Range.foreach(u,(d,c)=>{const m=t.getValue(o,r,d,c);m&&a.push({pattern:m.pattern,row:d,col:c})})}),!a.length)return[];const l=Pn(o,r,a);return Object.keys(l.values).forEach(u=>{const d=l.values[u];d.ranges=zn(d.ranges)}),[{id:Un.id,params:l}]},Pn=(s,e,t)=>{const n=Ya(t,"pattern"),o={},r={},a=Ka();return Object.keys(n).forEach(l=>{const u=n[l],d=a();o[d]={pattern:l},u.forEach(c=>{r[d]||(r[d]={ranges:[]}),r[d].ranges.push(i.cellToRange(c.row,c.col))})}),{unitId:s,subUnitId:e,refMap:o,values:r}},vi={id:"sheet.mutation.remove-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{styleName:t,unitId:n}=e;return s.get(g.SheetRangeThemeModel).unregisterRangeThemeStyle(n,t),!0}},Ii={id:"sheet.mutation.set-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{unitId:t,styleName:n,style:o}=e,a=s.get(g.SheetRangeThemeModel).getRangeThemeStyle(t,n);return a&&(o.headerRowStyle&&a.setHeaderRowStyle(o.headerRowStyle),o.firstRowStyle&&a.setFirstRowStyle(o.firstRowStyle),o.secondRowStyle&&a.setSecondRowStyle(o.secondRowStyle),o.lastRowStyle&&a.setLastRowStyle(o.lastRowStyle)),!0}},pi={id:"sheet.operation.scroll-to-cell",type:i.CommandType.OPERATION,handler:()=>!0},Lu=(s,e,t)=>{const o=s.get(g.SheetsSelectionsService).getCurrentSelections(),{value:r,selections:a,unitId:l,subUnitId:u}=e;if(o){const c=o[(o==null?void 0:o.length)-1].primary;if(c){const{actualColumn:m,actualRow:h}=c;let{startRow:R,startColumn:C,endRow:S,endColumn:v}=a[a.length-1];if(r===i.Dimension.COLUMNS){const w=t.find(y=>y.startColumn===m&&y.endColumn===m&&h===y.startRow);w&&(v=w.endColumn,R=w.startRow,S=w.endRow)}else if(r===i.Dimension.ROWS){const w=t.find(y=>y.startRow===h&&y.endRow===h&&m===y.startColumn);w&&(S=w.endRow,C=w.startColumn,v=w.endColumn)}const I={startRow:R,startColumn:C,endRow:S,endColumn:v,actualRow:h,actualColumn:m,isMerged:!0,isMergedMainCell:R===h&&C===m},M=o.map((w,y,b)=>({range:w.range,style:null,primary:y===b.length-1?I:null})),p={unitId:l,subUnitId:u,type:te.ONLY_SET,selections:M};return{id:q.id,params:p}}return null}return null},Hu=(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections(),{unitId:o,subUnitId:r}=e;if(n&&n[(n==null?void 0:n.length)-1].primary){const u={unitId:o,subUnitId:r,type:te.ONLY_SET,selections:[...n]};return{id:q.id,params:u}}return null},wi="maxCellsPerSheet",Bu=3e6;var Fu=Object.getOwnPropertyDescriptor,ju=(s,e,t,n)=>{for(var o=n>1?void 0:n?Fu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Mi=(s,e)=>(t,n)=>e(t,n,s);const Gu="SHEET_DEFINED_NAME_PLUGIN",zu="AllDefaultWorkbook";g.DefinedNameDataController=class extends i.Disposable{constructor(e,t){super(),this._definedNamesService=e,this._resourceManagerService=t,this._initialize()}_initialize(){this._initSnapshot()}_initSnapshot(){const e=n=>{const o=this._definedNamesService.getDefinedNameMap(n);return o?JSON.stringify(o):""},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:Gu,businesses:[i.UniverInstanceType.UNIVER_SHEET],toJson:n=>e(n),parseJson:n=>t(n),onUnLoad:n=>{this._definedNamesService.removeUnitDefinedName(n)},onLoad:(n,o)=>{this._definedNamesService.registerDefinedNames(n,o)}}))}},g.DefinedNameDataController=ju([Mi(0,J.IDefinedNamesService),Mi(1,i.IResourceManagerService)],g.DefinedNameDataController);const yi="sheets.config",_i={};var qu=Object.getOwnPropertyDescriptor,Yu=(s,e,t,n)=>{for(var o=n>1?void 0:n?qu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ks=(s,e)=>(t,n)=>e(t,n,s);const Ku=[Oe.id],Ju=[re.id,ie.id,ae.id,ne.id,pe.id,we.id];g.SheetsFreezeSyncController=class extends i.Disposable{constructor(t,n,o){var a,l;super();f(this,"_d",new i.DisposableCollection);f(this,"_enabled",!0);this._univerInstanceService=t,this._commandService=n,this._configService=o;const r=(l=(a=this._configService.getConfig(yi))==null?void 0:a.freezeSync)!=null?l:!0;this.setEnabled(r)}getEnabled(){return this._enabled}setEnabled(t){t?this._d.dispose():this._initOnlyLocalListener(),this._enabled=t}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((t,n)=>{Ku.includes(t.id)&&(n||(n={}),n.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((t,n)=>{if(Ju.includes(t.id)&&(n!=null&&n.fromCollab)){const{id:o,params:r}=t;o===re.id?this._handleInsertRowMutation(r,n):o===ie.id?this._handleInsertColMutation(r,n):o===ae.id?this._handleRemoveRowMutation(r,n):o===ne.id?this._handleRemoveColMutation(r,n):o===pe.id?this._handleMoveRowsMutation(r,n):o===we.id&&this._handleMoveColsMutation(r,n)}}))}_handleInsertRowMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startRow<l.startRow){const u=o.endRow-o.startRow+1,d={...l,startRow:Math.max(1,l.startRow+u),ySplit:Math.max(1,l.ySplit+u)};this._sequenceExecute(r,a,d,n)}}_handleInsertColMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startColumn<l.startColumn){const u=o.endColumn-o.startColumn+1,d={...l,startColumn:Math.max(1,l.startColumn+u),xSplit:Math.max(1,l.xSplit+u)};this._sequenceExecute(r,a,d,n)}}_handleRemoveRowMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startRow<l.startRow){const u=Math.min(l.startRow,o.endRow+1)-o.startRow,d={...l,startRow:Math.max(1,l.startRow-u),ySplit:Math.max(1,l.ySplit-u)};this._sequenceExecute(r,a,d,n)}}_handleRemoveColMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startColumn<l.startColumn){const u=Math.min(l.startColumn,o.endColumn+1)-o.startColumn,d={...l,startColumn:Math.max(1,l.startColumn-u),xSplit:Math.max(1,l.xSplit-u)};this._sequenceExecute(r,a,d,n)}}_handleMoveRowsMutation(t,n){const{sourceRange:o,targetRange:r,unitId:a,subUnitId:l}=t,u=this._getFreeze(a,l);if(!u||u.startRow<=0||o.startRow>=u.startRow&&r.startRow>=u.startRow||o.endRow<u.startRow&&r.endRow<u.startRow)return;const d=o.endRow-o.startRow+1,c=Math.max(Math.min(u.startRow,o.endRow+1)-o.startRow,0),m={...u};r.startRow>=u.startRow?(m.startRow=Math.max(1,u.startRow-c),m.ySplit=Math.max(1,u.ySplit-c)):(m.startRow=u.startRow+d-c,m.ySplit=u.ySplit+d-c),this._sequenceExecute(a,l,m,n)}_handleMoveColsMutation(t,n){const{sourceRange:o,targetRange:r,unitId:a,subUnitId:l}=t,u=this._getFreeze(a,l);if(!u||u.startColumn<=0||o.startColumn>=u.startColumn&&r.startColumn>=u.startColumn||o.endColumn<u.startColumn&&r.endColumn<u.startColumn)return;const d=o.endColumn-o.startColumn+1,c=Math.max(Math.min(u.startColumn,o.endColumn+1)-o.startColumn,0),m={...u};r.startColumn>=u.startColumn?(m.startColumn=Math.max(1,u.startColumn-c),m.xSplit=Math.max(1,u.xSplit-c)):(m.startColumn=u.startColumn+d-c,m.xSplit=u.xSplit+d-c),this._sequenceExecute(a,l,m,n)}_getFreeze(t,n){const o=this._univerInstanceService.getUnit(t,i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=o.getSheetBySheetId(n);return r?r.getFreeze():null}_sequenceExecute(t,n,o,r){i.sequenceExecute([{id:Oe.id,params:{...o,unitId:t,subUnitId:n,resetScroll:!1}}],this._commandService,r)}},g.SheetsFreezeSyncController=Yu([Ks(0,i.Inject(i.IUniverInstanceService)),Ks(1,i.ICommandService),Ks(2,i.IConfigService)],g.SheetsFreezeSyncController);var xu=Object.getOwnPropertyDescriptor,Xu=(s,e,t,n)=>{for(var o=n>1?void 0:n?xu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},De=(s,e)=>(t,n)=>e(t,n,s);g.SheetPermissionCheckController=class extends i.Disposable{constructor(t,n,o,r,a,l,u,d,c,m){super();f(this,"disposableCollection",new i.DisposableCollection);f(this,"_triggerPermissionUIEvent$",new D.Subject);f(this,"triggerPermissionUIEvent$",this._triggerPermissionUIEvent$.asObservable());this._commandService=t,this._univerInstanceService=n,this._permissionService=o,this._selectionManagerService=r,this._rangeProtectionRuleModel=a,this._worksheetProtectionRuleModel=l,this._localeService=u,this._lexerTreeBuilder=d,this._contextService=c,this._definedNamesService=m,this._initialize()}blockExecuteWithoutPermission(t){throw this._triggerPermissionUIEvent$.next(t),new i.CustomCommandExecutionError("have no permission")}_getPermissionCheck(t,n){let o=!0,r="";switch(t){case vt.id:i.isICellData(n.value)&&n.value.f?(o=this._permissionCheckWithFormula(n),r=this._localeService.t("permission.dialog.formulaErr")):o=this._permissionCheckBySetRangeValue({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[Wt,fe]},n);break;case fn.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[Wt,fe]}),r=this._localeService.t("permission.dialog.editErr");break;case Gt.id:case zt.id:o=this.permissionCheckWithoutRange({worksheetTypes:[St]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Kt.id:case Jt.id:case Tn.id:o=this.permissionCheckWithoutRange({worksheetTypes:[ft]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case wt.id:case pt.id:o=this._permissionCheckByMoveCommand(n),r=this._localeService.t("permission.dialog.moveRowColErr");break;case Je.id:o=this._permissionCheckByMoveRangeCommand(n),r=this._localeService.t("permission.dialog.moveRangeErr");break;case js.id:o=this._permissionCheckByWorksheetCommand([me,cn]),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder();break;case yn.id:o=this._permissionCheckByWorksheetCommand([me,mn]),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder();break;case qs.id:{const{unitId:a,subUnitId:l}=n;o=this._permissionCheckByWorksheetCommand([me,un],a,l),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder()}break;case Et.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,St]},n.ranges),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Tt.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,ft]},n.ranges),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Ws.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,St]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Ls.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,ft]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case It.id:o=this._permissionCheckWithInsertRangeMove("right"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case xe.id:o=this._permissionCheckWithInsertRangeMove("bottom"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case He.id:o=this._permissionCheckWithInsertRangeMove("left"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case Be.id:o=this._permissionCheckWithInsertRangeMove("top"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break}o||this.blockExecuteWithoutPermission(r)}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{this._getPermissionCheck(t.id,t==null?void 0:t.params)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(t.id===qt.id){const o=t.params,{unitId:r=(n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getUnitId(),subUnitId:a}=o;if(!r||!a)return;const l=this._worksheetProtectionRuleModel.getRule(r,a),u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a);l&&this._worksheetProtectionRuleModel.ruleRefresh(l.permissionId),u.length&&this._rangeProtectionRuleModel.ruleRefresh(a)}}))}_permissionCheckWithInsertRangeMove(t){var c;const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=i.Tools.deepClone((c=this._selectionManagerService.getCurrentLastSelection())==null?void 0:c.range);return!(!l||(t==="top"||t==="bottom"?l.endRow=o.getRowCount()-1:(t==="left"||t==="right")&&(l.endColumn=o.getColumnCount()-1),this._rangeProtectionRuleModel.getSubunitRuleList(r,a).map(m=>m.ranges).flat().some(m=>i.Rectangle.getIntersects(l,m))))}_permissionCheckByWorksheetCommand(t,n,o){var c,m;const r=P(this._univerInstanceService,{unitId:n,subUnitId:o});if(!r)return!1;const{unitId:a,subUnitId:l}=r,u=this._worksheetProtectionRuleModel.getRule(a,l),d=this._rangeProtectionRuleModel.getSubunitRuleList(a,l).length>0;return u||d?(m=(c=this._permissionService.getPermissionPoint(new dn(a).id))==null?void 0:c.value)!=null?m:!1:this._permissionService.composePermission(t.map(h=>new h(a).id)).every(h=>h.value)}permissionCheckWithoutRange(t){var R,C,S,v;const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=this._selectionManagerService.getCurrentLastSelection();if(!l)return!0;const u=(C=(R=l==null?void 0:l.primary)==null?void 0:R.actualRow)!=null?C:0,d=(v=(S=l==null?void 0:l.primary)==null?void 0:S.actualColumn)!=null?v:0,{workbookTypes:c,worksheetTypes:m,rangeTypes:h}=t;return!(c&&c.some(M=>{var y,b;const p=new M(r);return((b=(y=this._permissionService.getPermissionPoint(p.id))==null?void 0:y.value)!=null?b:!1)===!1})===!0||m&&m.some(M=>{var y,b;const p=new M(r,a);return((b=(y=this._permissionService.getPermissionPoint(p.id))==null?void 0:y.value)!=null?b:!1)===!1})===!0||h&&h.some(M=>{var T,U,k,E,O;const p=(U=(T=o.getCell(u,d))==null?void 0:T.selectionProtection)==null?void 0:U[0];if(!(p!=null&&p.ruleId))return!1;const w=(k=this._rangeProtectionRuleModel.getRule(r,a,p.ruleId))==null?void 0:k.permissionId;if(!w)return!1;const y=new M(r,a,w);return((O=(E=this._permissionService.getPermissionPoint(y.id))==null?void 0:E.value)!=null?O:!1)===!1})===!0)}permissionCheckWithRanges(t,n,o,r){var C;const a=P(this._univerInstanceService);if(!a)return!1;const{workbook:l,worksheet:u}=a;o||(o=l.getUnitId()),r||(r=u.getSheetId());const d=n!=null?n:(C=this._selectionManagerService.getCurrentSelections())==null?void 0:C.map(S=>S.range);if(!d)return!1;const{workbookTypes:c,worksheetTypes:m,rangeTypes:h}=t,R=[];return c&&R.push(...c.map(S=>new S(o).id)),m&&R.push(...m.map(S=>new S(o,r).id)),h&&this._rangeProtectionRuleModel.getSubunitRuleList(o,r).forEach(S=>{d.some(I=>S.ranges.some(M=>i.Rectangle.intersects(M,I)))&&R.push(...h.map(I=>new I(o,r,S.permissionId).id))}),R.length?this._permissionService.composePermission(R).every(S=>S.value):!0}_permissionCheckByMoveCommand(t){const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=t.toRange;l.endRow===o.getRowCount()-1?l.endColumn=l.startColumn:l.endRow=l.startRow;const u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a).reduce((d,c)=>[...d,...c.ranges],[]).filter(d=>i.Rectangle.intersects(d,l));return u.length>0?!1:(u.forEach(d=>{var c,m;for(let h=d.startRow;h<=d.endRow;h++)for(let R=d.startColumn;R<=d.endColumn;R++){const C=(m=(c=o.getCell(h,R))==null?void 0:c.selectionProtection)==null?void 0:m[0];if((C==null?void 0:C[_.Edit])===!1)return!1}}),!0)}_permissionCheckByMoveRangeCommand(t){const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=t.toRange,u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a).reduce((d,c)=>[...d,...c.ranges],[]).filter(d=>i.Rectangle.intersects(d,l));return u.length>0?!1:(u.forEach(d=>{var c,m;for(let h=d.startRow;h<=d.endRow;h++)for(let R=d.startColumn;R<=d.endColumn;R++){const C=(m=(c=o.getCell(h,R))==null?void 0:c.selectionProtection)==null?void 0:m[0];if((C==null?void 0:C[_.Edit])===!1)return!1}}),!0)}_permissionCheckBySetRangeValue(t,n){let o=[];n.range?o=[n.range]:o=[new i.ObjectMatrix(n.value).getDataRange()];const{unitId:r,subUnitId:a}=n;return this.permissionCheckWithRanges(t,o,r,a)}_permissionCheckWithFormula(t){var a,l,u,d,c;const n=t.value,o=t.range,r=n.f;if(r){const m=r.substring(1),h=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),R=(a=t.unitId)!=null?a:h.getUnitId(),C=this._definedNamesService.getValueByName(R,m);if(C){let S=C.formulaOrRefString;S.startsWith(J.operatorToken.EQUALS)&&(S=S.slice(1));const v=S.split(",");for(let I=0;I<v.length;I++){const M=v[I],p=J.deserializeRangeWithSheet(M);if(p.sheetName){const w=h.getSheetBySheetName(p.sheetName);if(!w)return!0;const{startRow:y,endRow:b,startColumn:T,endColumn:U}=p.range;for(let k=y;k<=b;k++)for(let E=T;E<=U;E++){const O=(u=(l=w.getCell(k,E))==null?void 0:l.selectionProtection)==null?void 0:u[0];if((O==null?void 0:O[_.View])===!1)return!1}}}return!0}else{const S=this._lexerTreeBuilder.sequenceNodesBuilder(r);if(!S)return!0;for(let v=0;v<S.length;v++){const I=S[v];if(typeof I=="string"||I.nodeType!==J.sequenceNodeType.REFERENCE)continue;const{token:M}=I,p=J.deserializeRangeWithSheetWithCache(M),w=p.unitId?this._univerInstanceService.getUnit(p.unitId):this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!w)return!0;let y=p.sheetName?w.getSheetBySheetName(p.sheetName):w.getActiveSheet();const b=w.getUnitId();if(p.sheetName){if(y=w.getSheetBySheetName(p.sheetName),!y)return!0;const O=y==null?void 0:y.getSheetId();if(!this._permissionService.getPermissionPoint(new Vt(b,O).id))return!1}if(!y)return!0;const{startRow:T,endRow:U,startColumn:k,endColumn:E}=p.range;for(let O=T;O<=U;O++)for(let W=k;W<=E;W++){const V=(c=(d=y.getCell(O,W))==null?void 0:d.selectionProtection)==null?void 0:c[0];if((V==null?void 0:V[_.View])===!1)return!1}}return!0}}if(o){const m=P(this._univerInstanceService);if(!m)return!1;const h=t.unitId||m.unitId,R=t.subUnitId||m.subUnitId,S=this._rangeProtectionRuleModel.getSubunitRuleList(h,R).filter(I=>I.ranges.some(M=>i.Rectangle.intersects(M,o))).map(I=>new Se(h,R,I.permissionId).id);if(!this._permissionService.composePermission(S).every(I=>I.value))return!1}return!0}},g.SheetPermissionCheckController=Xu([De(0,i.ICommandService),De(1,i.IUniverInstanceService),De(2,i.IPermissionService),De(3,i.Inject(g.SheetsSelectionsService)),De(4,i.Inject(X)),De(5,i.Inject(ke)),De(6,i.Inject(i.LocaleService)),De(7,i.Inject(J.LexerTreeBuilder)),De(8,i.IContextService),De(9,J.IDefinedNamesService)],g.SheetPermissionCheckController);var Zu=Object.getOwnPropertyDescriptor,Qu=(s,e,t,n)=>{for(var o=n>1?void 0:n?Zu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},xt=(s,e)=>(t,n)=>e(t,n,s);g.WorkbookPermissionService=class extends i.Disposable{constructor(t,n,o,r,a){super();f(this,"_unitPermissionInitStateChange",new D.BehaviorSubject(!1));f(this,"unitPermissionInitStateChange$",this._unitPermissionInitStateChange.asObservable());this._permissionService=t,this._univerInstanceService=n,this._rangeProtectionRuleModel=o,this._worksheetProtectionRuleModel=r,this._worksheetProtectionPointModel=a,this._init()}_init(){const t=n=>{const o=n.getUnitId();Pt().forEach(r=>{const a=new r(o);this._permissionService.addPermissionPoint(a)})};this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{t(n)}),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{t(n)})),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{const o=n.getUnitId();n.getSheets().forEach(r=>{const a=r.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(o,a).forEach(u=>{[...ue()].forEach(d=>{const c=new d(o,a,u.permissionId);this._permissionService.deletePermissionPoint(c.id)})}),[...de(),...ve()].forEach(u=>{const d=new u(o,a);this._permissionService.deletePermissionPoint(d.id)})}),Pt().forEach(r=>{const a=new r(o);this._permissionService.deletePermissionPoint(a.id)}),this._rangeProtectionRuleModel.deleteUnitModel(o),this._worksheetProtectionPointModel.deleteUnitModel(o),this._worksheetProtectionRuleModel.deleteUnitModel(o)}))}changeUnitInitState(t){this._unitPermissionInitStateChange.next(t)}},g.WorkbookPermissionService=Qu([xt(0,i.Inject(i.IPermissionService)),xt(1,i.Inject(i.IUniverInstanceService)),xt(2,i.Inject(X)),xt(3,i.Inject(ke)),xt(4,i.Inject(Ut))],g.WorkbookPermissionService);var ed=Object.getOwnPropertyDescriptor,td=(s,e,t,n)=>{for(var o=n>1?void 0:n?ed(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ne=(s,e)=>(t,n)=>e(t,n,s);g.SheetPermissionInitController=class extends i.Disposable{constructor(e,t,n,o,r,a,l,u,d,c){super(),this._univerInstanceService=e,this._permissionService=t,this._authzIoService=n,this._rangeProtectionRuleModel=o,this._worksheetProtectionRuleModel=r,this._userManagerService=a,this._worksheetProtectionPointRuleModel=l,this._workbookPermissionService=u,this._undoRedoService=d,this._commandService=c}initPermission(){this._initRangePermissionFromSnapshot(),this._initRangePermissionChange(),this._initWorksheetPermissionFromSnapshot(),this._initWorksheetPermissionChange(),this._initWorksheetPermissionPointsChange(),this._initWorkbookPermissionFromSnapshot(),this._initUserChange(),this._refreshPermissionByCollaCreate()}refreshRangeProtectPermission(){this._initRangePermissionFromSnapshot()}async _initRangePermissionFromSnapshot(){const e=async t=>{const n=[],o=t.getUnitId(),r=t.getSheets(),a=new Map;if(r.forEach(l=>{const u=l.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(o,u).forEach(d=>{a.set(d.permissionId,d),n.push({objectID:d.permissionId,unitID:o,objectType:N.SelectRange,actions:Ge})})}),!n.length){this._rangeProtectionRuleModel.changeRuleInitState(!0);return}this._authzIoService.batchAllowed(n).then(l=>{l.forEach(u=>{const d=a.get(u.objectID);d&&ue().forEach(c=>{const m=new c(o,d.subUnitId,u.objectID),h=m.subType,R=u.actions.find(C=>C.action===h);(R==null?void 0:R.allowed)!==void 0&&this._permissionService.updatePermissionPoint(m.id,R.allowed)})}),this._rangeProtectionRuleModel.changeRuleInitState(!0)})};await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(t=>e(t))),this._rangeProtectionRuleModel.changeRuleInitState(!0)}_initRangePermissionChange(){this.disposeWithMe(this._rangeProtectionRuleModel.ruleChange$.subscribe(e=>{e.type!=="delete"?this._authzIoService.allowed({objectID:e.rule.permissionId,unitID:e.unitId,objectType:N.SelectRange,actions:Ge}).then(t=>{ue().forEach(n=>{if(e.type==="set"){const{rule:u,oldRule:d}=e;if(u.permissionId===(d==null?void 0:d.permissionId))return}const o=e.rule,r=new n(o.unitId,o.subUnitId,o.permissionId),a=r.subType,l=t.find(u=>u.action===a);l&&this._permissionService.updatePermissionPoint(r.id,l.allowed)}),this._rangeProtectionRuleModel.ruleRefresh(e.rule.permissionId)}):this._rangeProtectionRuleModel.getSubunitRuleList(e.unitId,e.subUnitId).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e.unitId,e.subUnitId),[...ve()].forEach(n=>{const o=new n(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(o.id,o.value)}))}))}async initWorkbookPermissionChange(e){var n;const t=e||((n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getUnitId());if(t)return this._authzIoService.allowed({objectID:t,objectType:N.Workbook,unitID:t,actions:ai}).then(o=>{Pt().forEach(r=>{const a=new r(t),l=a.subType,u=o.find(d=>d.action===l);u&&this._permissionService.updatePermissionPoint(a.id,u.allowed)})})}async _initWorkbookPermissionFromSnapshot(){await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(e=>this.initWorkbookPermissionChange(e.getUnitId()))),this._workbookPermissionService.changeUnitInitState(!0)}_initWorksheetPermissionChange(){this.disposeWithMe(this._worksheetProtectionRuleModel.ruleChange$.subscribe(e=>{e.type!=="delete"?this._authzIoService.allowed({objectID:e.rule.permissionId,unitID:e.unitId,objectType:N.Worksheet,actions:Ge}).then(t=>{de().forEach(n=>{const o=new n(e.unitId,e.subUnitId),r=o.subType,a=t.find(l=>l.action===r);a&&this._permissionService.updatePermissionPoint(o.id,a.allowed)}),this._worksheetProtectionRuleModel.ruleRefresh(e.rule.permissionId)}):([...de(),...ve()].forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e.unitId,e.subUnitId))}))}_initWorksheetPermissionPointsChange(){this.disposeWithMe(this._worksheetProtectionPointRuleModel.pointChange$.subscribe(e=>{this._authzIoService.allowed({objectID:e.permissionId,unitID:e.unitId,objectType:N.Worksheet,actions:_n}).then(t=>{ve().forEach(n=>{const o=new n(e.unitId,e.subUnitId),r=o.subType,a=t.find(l=>l.action===r);a&&this._permissionService.updatePermissionPoint(o.id,a.allowed)})})}))}async _initWorksheetPermissionFromSnapshot(){const e=async t=>{const n=[],o=t.getUnitId(),r=t.getSheets(),a=new Map;if(r.forEach(l=>{const u=l.getSheetId(),d=this._worksheetProtectionRuleModel.getRule(o,u);d&&(a.set(d.permissionId,d),n.push({objectID:d.permissionId,unitID:o,objectType:N.Worksheet,actions:Ge}));const c=this._worksheetProtectionPointRuleModel.getRule(o,u);c&&(a.set(c.permissionId,c),n.push({objectID:c.permissionId,unitID:o,objectType:N.Worksheet,actions:_n}))}),!n.length){this._worksheetProtectionRuleModel.changeRuleInitState(!0);return}this._authzIoService.batchAllowed(n).then(l=>{l.forEach(u=>{const d=a.get(u.objectID);d&&[...de(),...ve()].forEach(c=>{const m=new c(o,d.subUnitId),h=m.subType,R=u.actions.find(C=>C.action===h);(R==null?void 0:R.allowed)!==void 0&&this._permissionService.updatePermissionPoint(m.id,R.allowed)})}),this._worksheetProtectionRuleModel.changeRuleInitState(!0)})};await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(t=>e(t))),this._worksheetProtectionRuleModel.changeRuleInitState(!0)}_initUserChange(){this.disposeWithMe(this._userManagerService.currentUser$.pipe(D.skip(1)).subscribe(()=>{const e=this._permissionService.getAllPermissionPoint();this._permissionService.clearPermissionMap(),this._worksheetProtectionRuleModel.changeRuleInitState(!1),this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const o=n.getUnitId();Pt().forEach(r=>{let a=new r(o);e.has(a.id)&&(a=e.get(a.id)),this._permissionService.addPermissionPoint(a)}),n.getSheets().forEach(r=>{const a=r.getSheetId();[...de(),...ve()].forEach(u=>{let d=new u(o,a);e.has(d.id)&&(d=e.get(d.id)),this._permissionService.addPermissionPoint(d)}),this._rangeProtectionRuleModel.getSubunitRuleList(o,a).forEach(u=>{ue().forEach(d=>{let c=new d(o,a,u.permissionId);e.has(c.id)&&(c=e.get(c.id)),this._permissionService.addPermissionPoint(c)})})}),this._initWorkbookPermissionFromSnapshot(),this._initWorksheetPermissionFromSnapshot(),this._initRangePermissionFromSnapshot()})}))}refreshPermission(e,t){const n=this._worksheetProtectionRuleModel.getTargetByPermissionId(e,t);let o=!1;if(n){const[l,u]=n;this._authzIoService.allowed({objectID:t,unitID:e,objectType:N.Worksheet,actions:Ge}).then(d=>{let c="";de().forEach(m=>{var S;const h=new m(e,u),R=h.subType,C=d.find(v=>v.action===R);C&&(((S=this._permissionService.getPermissionPoint(h.id))==null?void 0:S.value)!==C.allowed&&(o=!0),this._permissionService.updatePermissionPoint(h.id,C.allowed),c+=`${C.action}_${C.allowed}`)}),this._worksheetProtectionRuleModel.ruleRefresh(`${t}_${c}`),o&&this._undoRedoService.clearUndoRedo(e)})}const r=this._worksheetProtectionPointRuleModel.getTargetByPermissionId(e,t);if(r){const[l,u]=r;this._authzIoService.allowed({objectID:t,unitID:e,objectType:N.Worksheet,actions:_n}).then(d=>{ve().forEach(c=>{var C;const m=new c(e,u),h=m.subType,R=d.find(S=>S.action===h);R&&(((C=this._permissionService.getPermissionPoint(m.id))==null?void 0:C.value)!==R.allowed&&(o=!0),this._permissionService.updatePermissionPoint(m.id,R.allowed))}),o&&this._undoRedoService.clearUndoRedo(e)})}const a=this._rangeProtectionRuleModel.getTargetByPermissionId(e,t);if(a){const[l,u]=a;this._authzIoService.allowed({objectID:t,unitID:e,objectType:N.SelectRange,actions:Ge}).then(d=>{let c="";ue().forEach(m=>{var S;const h=new m(e,u,t),R=h.subType,C=d.find(v=>v.action===R);C&&(((S=this._permissionService.getPermissionPoint(h.id))==null?void 0:S.value)!==C.allowed&&(o=!0),this._permissionService.updatePermissionPoint(h.id,C.allowed),c+=`${C.action}_${C.allowed}`)}),this._rangeProtectionRuleModel.ruleRefresh(`${t}_${c}`),o&&this._undoRedoService.clearUndoRedo(e)})}}_refreshPermissionByCollaCreate(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(t!=null&&t.fromCollab&&(e.id===Ce.id||e.id===Fe.id||e.id===bn.id)){const n=e.params;this._undoRedoService.clearUndoRedo(n.unitId)}}))}},g.SheetPermissionInitController=td([Ne(0,i.IUniverInstanceService),Ne(1,i.IPermissionService),Ne(2,i.IAuthzIoService),Ne(3,i.Inject(X)),Ne(4,i.Inject(ke)),Ne(5,i.Inject(i.UserManagerService)),Ne(6,i.Inject(Ut)),Ne(7,i.Inject(g.WorkbookPermissionService)),Ne(8,i.Inject(i.IUndoRedoService)),Ne(9,i.Inject(i.ICommandService))],g.SheetPermissionInitController);var nd=Object.getOwnPropertyDescriptor,sd=(s,e,t,n)=>{for(var o=n>1?void 0:n?nd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Js=(s,e)=>(t,n)=>e(t,n,s);g.ZebraCrossingCacheController=class extends i.Disposable{constructor(t,n,o){super();f(this,"_zebraCacheUpdateSubject",new D.Subject);this._commandService=t,this._sheetRangeThemeModel=n,this._univerInstanceService=o,this._init()}_init(){this._initializeCommandListener(),this._initTriggerCacheUpdateListener()}updateZebraCrossingCache(t,n){this._zebraCacheUpdateSubject.next({unitId:t,subUnitId:n})}_initializeCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{const{id:n}=t;let o,r;switch(n){case re.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ye.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ke.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case ae.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ee.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break}o&&r&&(this._sheetRangeThemeModel.refreshSheetRowVisibleFuncSet(o,r),this._sheetRangeThemeModel.refreshZebraCrossingCacheBySheet(o,r))}))}_initTriggerCacheUpdateListener(){this.disposeWithMe(this._zebraCacheUpdateSubject.subscribe(({unitId:t,subUnitId:n})=>{this._sheetRangeThemeModel.refreshSheetRowVisibleFuncSet(t,n),this._sheetRangeThemeModel.refreshZebraCrossingCacheBySheet(t,n)}))}},g.ZebraCrossingCacheController=sd([Js(0,i.Inject(i.ICommandService)),Js(1,i.Inject(g.SheetRangeThemeModel)),Js(2,i.Inject(i.IUniverInstanceService))],g.ZebraCrossingCacheController);var od=Object.getOwnPropertyDescriptor,rd=(s,e,t,n)=>{for(var o=n>1?void 0:n?od(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},bi=(s,e)=>(t,n)=>e(t,n,s);g.RangeProtectionRenderModel=class{constructor(e,t){f(this,"_cache",new i.LRUMap(1e4));this._selectionProtectionRuleModel=e,this._permissionService=t,this._init()}_init(){this._permissionService.permissionPointUpdate$.pipe(kt.filter(e=>e.type===N.SelectRange),kt.filter(e=>ue().some(t=>e instanceof t)),kt.map(e=>e)).subscribe(e=>{const t=this._selectionProtectionRuleModel.getSubunitRuleList(e.unitId,e.subUnitId);for(const n of t)n.permissionId===e.permissionId&&n.ranges.forEach(o=>{i.Range.foreach(o,(r,a)=>{const l=this._createKey(e.unitId,e.subUnitId,r,a);this._cache.delete(l)})})}),this._selectionProtectionRuleModel.ruleChange$.subscribe(e=>{var t;e.rule.ranges.forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=this._createKey(e.unitId,e.subUnitId,o,r);this._cache.delete(a)})}),e.type==="set"&&((t=e.oldRule)==null||t.ranges.forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=this._createKey(e.unitId,e.subUnitId,o,r);this._cache.delete(a)})}))})}_createKey(e,t,n,o){return`${e}_${t}_${n}_${o}`}getCellInfo(e,t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(e,t),a=[];if(!r||!r.length)return a;const l=this._createKey(e,t,n,o),u=this._cache.get(l);if(u)return u;const d=[];for(const c of r)if(c.ranges.some(m=>m.startRow<=n&&m.endRow>=n&&m.startColumn<=o&&m.endColumn>=o)){const m=ue().reduce((h,R)=>{var v;const C=new R(e,t,c.permissionId),S=this._permissionService.getPermissionPoint(C.id);return h[C.subType]=(v=S==null?void 0:S.value)!=null?v:C.value,h},{});d.push({...m,ruleId:c.id,ranges:c.ranges})}return this._cache.set(l,d),d}clear(){this._cache.clear()}},g.RangeProtectionRenderModel=rd([bi(0,i.Inject(X)),bi(1,i.Inject(i.IPermissionService))],g.RangeProtectionRenderModel);var id=Object.getOwnPropertyDescriptor,ad=(s,e,t,n)=>{for(var o=n>1?void 0:n?id(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},xs=(s,e)=>(t,n)=>e(t,n,s);g.RangeProtectionCache=class extends i.Disposable{constructor(t,n,o){super();f(this,"_cellRuleCache",new Map);f(this,"_permissionIdCache",new Map);f(this,"_cellInfoCache",new Map);f(this,"_rowInfoCache",new Map);f(this,"_colInfoCache",new Map);this._ruleModel=t,this._permissionService=n,this._univerInstanceService=o,this._initUpdateCellRuleCache(),this._initUpdateCellInfoCache(),this._initUpdateRowColInfoCache(),this._initCache()}_initCache(){this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(t=>{t.getSheets().forEach(n=>{const o=t.getUnitId(),r=n.getSheetId();this.reBuildCache(o,r)})})}_initUpdateCellInfoCache(){this._permissionService.permissionPointUpdate$.pipe(D.filter(t=>t.type===N.SelectRange),D.map(t=>t)).subscribe(t=>{const{subUnitId:n,unitId:o,permissionId:r}=t,a=this._permissionIdCache.get(r);if(!a)return;const l=this._ruleModel.getRule(o,n,a);if(!l)return;const u=this._ensureCellInfoMap(o,n);l.ranges.forEach(d=>{const{startRow:c,endRow:m,startColumn:h,endColumn:R}=d;for(let C=c;C<=m;C++)for(let S=h;S<=R;S++)u.delete(`${C}-${S}`)})}),this._ruleModel.ruleChange$.subscribe(t=>{var a;const{unitId:n,subUnitId:o}=t,r=this._ensureCellInfoMap(n,o);t.rule.ranges.forEach(l=>{i.Range.foreach(l,(u,d)=>{r.delete(`${u}-${d}`)})}),t.type==="set"&&((a=t.oldRule)==null||a.ranges.forEach(l=>{i.Range.foreach(l,(u,d)=>{this._cellInfoCache.delete(`${u}-${d}`)})}))})}_initUpdateCellRuleCache(){this._ruleModel.ruleChange$.subscribe(t=>{const{type:n}=t;n==="add"?this._addCellRuleCache(t):n==="delete"?this._deleteCellRuleCache(t):(this._deleteCellRuleCache({...t,rule:t.oldRule}),this._addCellRuleCache(t))})}_ensureRuleMap(t,n){let o=this._cellRuleCache.get(t);o||(o=new Map,this._cellRuleCache.set(t,o));let r=o.get(n);return r||(r=new Map,o.set(n,r)),r}_ensureCellInfoMap(t,n){let o=this._cellInfoCache.get(t);o||(o=new Map,this._cellInfoCache.set(t,o));let r=o.get(n);return r||(r=new Map,o.set(n,r)),r}_ensureRowColInfoMap(t,n,o){let r=o==="row"?this._rowInfoCache.get(t):this._colInfoCache.get(t);r||(r=new Map,o==="row"?this._rowInfoCache.set(t,r):this._colInfoCache.set(t,r));let a=r.get(n);return a||(a=new Map,r.set(n,a)),a}_addCellRuleCache(t){const{subUnitId:n,unitId:o,rule:r}=t,a=this._ensureRuleMap(o,n);r.ranges.forEach(l=>{const{startRow:u,endRow:d,startColumn:c,endColumn:m}=l;for(let h=u;h<=d;h++)for(let R=c;R<=m;R++)a.set(`${h}-${R}`,r.id)}),this._permissionIdCache.set(r.permissionId,r.id)}_deleteCellRuleCache(t){const{subUnitId:n,unitId:o,rule:r}=t,a=this._ensureRuleMap(o,n),l=this._ensureCellInfoMap(o,n);r.ranges.forEach(u=>{const{startRow:d,endRow:c,startColumn:m,endColumn:h}=u;for(let R=d;R<=c;R++)for(let C=m;C<=h;C++)a.delete(`${R}-${C}`),l.delete(`${R}-${C}`)}),this._permissionIdCache.delete(r.permissionId)}_getSelectionActions(t,n,o){var c,m,h,R,C,S,v,I,M,p,w,y;const r=(h=(m=this._permissionService.getPermissionPoint((c=new Se(t,n,o.permissionId))==null?void 0:c.id))==null?void 0:m.value)!=null?h:!0,a=(S=(C=this._permissionService.getPermissionPoint((R=new ln(t,n,o.permissionId))==null?void 0:R.id))==null?void 0:C.value)!=null?S:!0,l=(M=(I=this._permissionService.getPermissionPoint((v=new zs(t,n,o.permissionId))==null?void 0:v.id))==null?void 0:I.value)!=null?M:!1,u=(y=(w=this._permissionService.getPermissionPoint((p=new Gs(t,n,o.permissionId))==null?void 0:p.id))==null?void 0:w.value)!=null?y:!1;return{[_.Edit]:r,[_.View]:a,[_.ManageCollaborator]:l,[_.Delete]:u}}reBuildCache(t,n){const o=this._ensureRuleMap(t,n),r=this._ensureCellInfoMap(t,n);o.clear(),r.clear();const a=this._ensureRowColInfoMap(t,n,"row"),l=this._ensureRowColInfoMap(t,n,"col");a.clear(),l.clear(),this._ruleModel.getSubunitRuleList(t,n).forEach(u=>{const d=this._getSelectionActions(t,n,u),c={...d,ruleId:u.id,ranges:u.ranges};u.ranges.forEach(m=>{const{startRow:h,endRow:R,startColumn:C,endColumn:S}=m;for(let v=h;v<=R;v++){const I=a.get(`${v}`);I?I.set(u.id,d):a.set(`${v}`,new Map([[u.id,d]]));for(let M=C;M<=S;M++){o.set(`${v}-${M}`,u.id),r.set(`${v}-${M}`,c);const p=l.get(`${M}`);p?p.set(u.id,d):l.set(`${M}`,new Map([[u.id,d]]))}}}),this._permissionIdCache.set(u.permissionId,u.id)})}getRowPermissionInfo(t,n,o,r){var u;const a=(u=this._rowInfoCache.get(t))==null?void 0:u.get(n);if(!a)return!0;const l=a.get(`${o}`);return l?r.every(d=>{for(const c of l.values())if(c[d]===!1)return!1;return!0}):!0}getColPermissionInfo(t,n,o,r){var u;const a=(u=this._colInfoCache.get(t))==null?void 0:u.get(n);if(!a)return!0;const l=a.get(`${o}`);return l?r.every(d=>{for(const c of l.values())if(c[d]===!1)return!1;return!0}):!0}_initUpdateRowColInfoCache(){this._permissionService.permissionPointUpdate$.pipe(D.filter(t=>t.type===N.SelectRange),D.map(t=>t)).subscribe({next:t=>{const{subUnitId:n,unitId:o,permissionId:r}=t,a=this._permissionIdCache.get(r);if(!a)return;const l=this._ruleModel.getRule(o,n,a);if(!l)return;const u=this._ensureRowColInfoMap(o,n,"row"),d=this._ensureRowColInfoMap(o,n,"col"),c=this._getSelectionActions(o,n,l);l.ranges.forEach(m=>{const{startRow:h,endRow:R,startColumn:C,endColumn:S}=m;for(let v=h;v<=R;v++){const I=u.get(`${v}`);I?I.set(a,c):u.set(`${v}`,new Map([[a,c]]));for(let M=C;M<=S;M++){const p=d.get(`${M}`);p?p.set(a,c):d.set(`${M}`,new Map([[a,c]]))}}})}}),this._ruleModel.ruleChange$.subscribe(t=>{if(t.type==="delete"){const{unitId:n,subUnitId:o,rule:r}=t,a=this._ensureRowColInfoMap(n,o,"row"),l=this._ensureRowColInfoMap(n,o,"col");r.ranges.forEach(u=>{const{startRow:d,endRow:c,startColumn:m,endColumn:h}=u;for(let R=d;R<=c;R++){const C=a.get(`${R}`);C==null||C.delete(r.id);for(let S=m;S<=h;S++){const v=l.get(`${S}`);v==null||v.delete(r.id)}}})}})}getCellInfo(t,n,o,r){var c,m;const a=this._ensureCellInfoMap(t,n),l=a.get(`${o}-${r}`);if(l)return l;const u=(m=(c=this._cellRuleCache.get(t))==null?void 0:c.get(n))==null?void 0:m.get(`${o}-${r}`);if(!u)return;const d=this._ruleModel.getRule(t,n,u);if(d){const R={...this._getSelectionActions(t,n,d),ruleId:u,ranges:d.ranges};return a.set(`${o}-${r}`,R),R}}deleteUnit(t){this._cellRuleCache.delete(t),this._cellInfoCache.delete(t),this._rowInfoCache.delete(t),this._colInfoCache.delete(t);const n=this._univerInstanceService.getUnit(t);n==null||n.getSheets().forEach(o=>{const r=o.getSheetId();this._ruleModel.getSubunitRuleList(t,r).forEach(a=>{this._permissionIdCache.delete(a.permissionId)})})}},g.RangeProtectionCache=ad([xs(0,i.Inject(X)),xs(1,i.Inject(i.IPermissionService)),xs(2,i.Inject(i.IUniverInstanceService))],g.RangeProtectionCache);const Ei="ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY";var ld=Object.getOwnPropertyDescriptor,ud=(s,e,t,n)=>{for(var o=n>1?void 0:n?ld(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Xs=(s,e)=>(t,n)=>e(t,n,s);let kn=class extends i.Disposable{constructor(s,e,t){var o;super(),this._commandService=s,this._configService=e,this._dataSyncPrimaryController=t,[F,ie,re,yt,Le,pe,we,ne,ae,Xe,G,Ys,j,Hs,qt,Un,Dt,Ci,Ke,Ye,Si,fi].forEach(r=>{var a;this._commandService.registerCommand(r),(a=this._dataSyncPrimaryController)==null||a.registerSyncingMutations(r)}),((o=this._configService.getConfig(Ei))!=null?o:!1)||[Tr,sn,fn,on,Ds,He,Be,Gt,Kt,nr,tr,sr,or,ws,ye,xe,It,Xo,xo,Qo,Zo,ps,Me,Dr,wt,Je,pt,Ms,Lt,ys,$t,In,Rn,Ar,Xr,Jr,xr,Lr,$r,bt,Wr,Vr,wn,lt,ut,zt,Hr,at,Fr,Oe,jr,Qr,vt,Jt,Mn,qr,ct,Ws,Ls,Et,Tt,ee,ni,jt,Kr,ti,ei,Zr,Bs,Fs,Ct,ii,je,yn,js,Yt,jn,Ee,Tn,Re,Ve,di,gt,si,mt,Lo,q,pi,Or,Ns,Vs,qs,hi,Rt,Gr,dt,li,Fe,st,tt,bn,Do,zr,Ur,br,Pr,ui,Ce,Te,Q,mi,ht,oi,ci,it,rt,vn,_t,gi,Nr,Er,kr,Ri,Ii,vi].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._configService.setConfig(wi,Bu)}};kn=ud([Xs(0,i.ICommandService),Xs(1,i.IConfigService),Xs(2,i.Optional($i.DataSyncPrimaryController))],kn);var dd=Object.getOwnPropertyDescriptor,cd=(s,e,t,n)=>{for(var o=n>1?void 0:n?dd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ti=(s,e)=>(t,n)=>e(t,n,s);let On=class extends i.Disposable{constructor(s,e){super(),this._univerInstanceService=s,this._commandService=e,this._initialize()}_initialize(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id!==J.SetFormulaCalculationResultMutation.id)return;const e=s.params,{unitData:t}=e,n=Object.keys(t),o=[];for(let a=0;a<n.length;a++){const l=n[a],u=t[l];if(u==null)continue;const d=Object.keys(u);for(let c=0;c<d.length;c++){const m=d[c],h=u[m];if(h==null)continue;const R=this._getMergedCellData(l,m,h),C={subUnitId:m,unitId:l,cellValue:R};o.push({id:F.id,params:C})}}return o.every(a=>this._commandService.executeCommand(a.id,a.params,{onlyLocal:!0,fromFormula:!0}))}))}_getMergedCellData(s,e,t){const n=this._univerInstanceService.getUniverSheetInstance(s),o=n==null?void 0:n.getStyles(),r=n==null?void 0:n.getSheetBySheetId(e),a=r==null?void 0:r.getCellMatrix(),l=new i.ObjectMatrix(t);return l.forValue((u,d,c)=>{const m=a==null?void 0:a.getValue(u,d),h=J.handleNumfmtInCell(m,c,o);l.setValue(u,d,h)}),l.getMatrix()}};On=cd([Ti(0,i.Inject(i.IUniverInstanceService)),Ti(1,i.ICommandService)],On);var md=Object.getOwnPropertyDescriptor,hd=(s,e,t,n)=>{for(var o=n>1?void 0:n?md(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},gd=(s,e)=>(t,n)=>e(t,n,s);let Dn=class extends i.Disposable{constructor(s){super(),this._sheetInterceptorService=s,this._initialize()}_initialize(){this._initInterceptorCellContent()}_initInterceptorCellContent(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:11,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{var o;if(!s)return t(s);const n=e.workbook.getStyles().getStyleByCell(s);return i.isDefaultFormat((o=n==null?void 0:n.n)==null?void 0:o.pattern)&&(s==null?void 0:s.t)===i.CellValueType.NUMBER&&s.v!==void 0&&s.v!==null&&i.isRealNum(s.v)&&((!s||s===e.rawData)&&(s={...e.rawData}),s.v=J.stripErrorMargin(Number(s.v))),t(s)}}))}};Dn=hd([gd(0,i.Inject(g.SheetInterceptorService))],Dn);var Rd=Object.getOwnPropertyDescriptor,Cd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Rd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Nn=(s,e)=>(t,n)=>e(t,n,s);let An=class extends i.Disposable{constructor(s,e,t,n){super(),this._permissionService=s,this._worksheetProtectionRuleModel=e,this._sheetInterceptorService=t,this._rangeProtectionCache=n,this._initViewModelByRangeInterceptor(),this._initViewModelBySheetInterceptor()}_initViewModelByRangeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:999,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{const{unitId:n,subUnitId:o,row:r,col:a}=e,l=this._rangeProtectionCache.getCellInfo(n,o,r,a);if(l){const u=l[_.View]===!1,d=!s||s===e.rawData?{...e.rawData}:s;return d.selectionProtection=[l],u?(delete d.s,delete d.v,delete d.p,d):t(d)}return t(s)}}))}_initViewModelBySheetInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:999,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{var a,l,u,d,c;const{unitId:n,subUnitId:o}=e,r=this._worksheetProtectionRuleModel.getRule(n,o);if(r!=null&&r.permissionId){const m=[{[_.View]:(l=(a=this._permissionService.getPermissionPoint(new Vt(n,o).id))==null?void 0:a.value)!=null?l:!1,[_.Edit]:(d=(u=this._permissionService.getPermissionPoint(new fe(n,o).id))==null?void 0:u.value)!=null?d:!1}],h=!((c=m[0])!=null&&c[_.View]),R=!s||s===e.rawData?{...s}:s;return R.hasWorksheetRule=!0,R.selectionProtection=m,h?(delete R.s,delete R.v,delete R.p,R):t(R)}return t(s)}}))}};An=Cd([Nn(0,i.IPermissionService),Nn(1,i.Inject(ke)),Nn(2,i.Inject(g.SheetInterceptorService)),Nn(3,i.Inject(g.RangeProtectionCache))],An);const Zs=i.createIdentifier("univer.exclusive-range-service");class Ui extends i.Disposable{constructor(){super(...arguments);f(this,"_exclusiveRanges",new Map);f(this,"_exclusiveRangesChange$",new D.Subject);f(this,"exclusiveRangesChange$",this._exclusiveRangesChange$.asObservable())}_ensureUnitMap(t){return this._exclusiveRanges.has(t)||this._exclusiveRanges.set(t,new Map),this._exclusiveRanges.get(t)}_ensureSubunitMap(t,n){const o=this._ensureUnitMap(t);return o.has(n)||o.set(n,new Map),o.get(n)}_ensureFeature(t,n,o){const r=this._ensureSubunitMap(t,n);return r.has(o)||r.set(o,[]),r.get(o)}addExclusiveRange(t,n,o,r){const a=this._ensureFeature(t,n,o);a.push(...r),this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:a.map(l=>l.range)})}getExclusiveRanges(t,n,o){var r,a;return(a=(r=this._exclusiveRanges.get(t))==null?void 0:r.get(n))==null?void 0:a.get(o)}clearExclusiveRanges(t,n,o){const r=this.getExclusiveRanges(t,n,o);this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:(r==null?void 0:r.map(a=>a.range))||[]}),this._ensureFeature(t,n,o),this._exclusiveRanges.get(t).get(n).set(o,[])}clearExclusiveRangesByGroupId(t,n,o,r){const a=this.getExclusiveRanges(t,n,o);this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:(a==null?void 0:a.map(u=>u.range))||[]});const l=this.getExclusiveRanges(t,n,o);if(l){const u=l.filter(d=>d.groupId!==r);this._exclusiveRanges.get(t).get(n).set(o,u)}}getInterestGroupId(t){const n=[];return t.forEach(o=>{var d;const r=o.range,{unitId:a,sheetId:l}=r;if(!a||!l)return;const u=(d=this._exclusiveRanges.get(a))==null?void 0:d.get(l);if(u)for(const c of u.keys()){const m=u.get(c);if(m){for(const h of m)if(i.Rectangle.intersects(r,h.range)){n.push(c);break}}}}),n}}var Sd=Object.getOwnPropertyDescriptor,fd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Sd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Qs=(s,e)=>(t,n)=>e(t,n,s);g.NumfmtService=class extends i.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._logService=n}getValue(e,t,n,o){const r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)return;const a=r==null?void 0:r.getSheetBySheetId(t);if(!a)return;const l=r.getStyles(),u=a.getCellRaw(n,o);if(u!=null&&u.s){const d=l.get(u.s);if(d!=null&&d.n)return d.n}return null}deleteValues(e,t,n){const o=this._univerInstanceService.getUniverSheetInstance(e);if(!o)return;const r=o==null?void 0:o.getSheetBySheetId(t);if(!r)return;const a=o.getStyles();n.forEach(l=>{i.Range.foreach(l,(u,d)=>{const c=r.getCellRaw(u,d);if(!c)return;const m=c==null?void 0:c.s,R={...m&&a.get(m)||{}};delete R.n;const C=a.setValue(R);c.s=C})})}setValues(e,t,n){const o=this._univerInstanceService.getUniverSheetInstance(e);if(!o)return;const r=o==null?void 0:o.getSheetBySheetId(t);if(!r)return;const a=o.getStyles(),l=r.getCellMatrix();n.forEach(u=>{u.ranges.forEach(d=>{i.Range.foreach(d,(c,m)=>{const h=r.getCellRaw(c,m);if(h){const C={...a.getStyleByCell(h)||{},n:{pattern:u.pattern}},S=a.setValue(C);h.s=S}else{const R={n:{pattern:u.pattern}},C=a.setValue(R);C&&l.setValue(c,m,{s:C})}})})})}},g.NumfmtService=fd([Qs(0,i.IResourceManagerService),Qs(1,i.IUniverInstanceService),Qs(2,i.ILogService)],g.NumfmtService);var vd=Object.getOwnPropertyDescriptor,Id=(s,e,t,n)=>{for(var o=n>1?void 0:n?vd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},qe=(s,e)=>(t,n)=>e(t,n,s);const Pi=[ie.id,re.id,ne.id,ae.id],ki=[pe.id,we.id];g.RangeProtectionRefRangeService=class extends i.Disposable{constructor(t,n,o,r,a,l,u,d){super();f(this,"disposableCollection",new i.DisposableCollection);this._selectionProtectionRuleModel=t,this._univerInstanceService=n,this._commandService=o,this._refRangeService=r,this._selectionProtectionRenderModel=a,this._rangeProtectionCache=l,this._sheetInterceptorService=u,this._rangeProtectionRuleModel=d,this._onRefRangeChange(),this._correctPermissionRange(),this._initReBuildCache(),this._initRemoveSheet()}_onRefRangeChange(){const t=(o,r)=>{const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!a||!(a==null?void 0:a.getSheetBySheetId(r)))return;this.disposableCollection.dispose();const u=c=>this.refRangeHandle(c,o,r);this._selectionProtectionRuleModel.getSubunitRuleList(o,r).reduce((c,m)=>[...c,...m.ranges],[]).forEach(c=>{this.disposableCollection.add(this._refRangeService.registerRefRange(c,u,o,r))})};this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===Fs.id){const r=o.params,a=r.subUnitId,l=r.unitId;if(!a||!l)return;t(l,a)}if(o.id===Q.id||o.id===Ce.id){const r=o.params,a=r.subUnitId,l=r.unitId;if(!a||!l)return;t(l,a)}}));const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(n){const o=n.getActiveSheet();if(!o)return;t(n.getUnitId(),o.getSheetId())}}refRangeHandle(t,n,o){switch(t.id){case pt.id:return this._getRefRangeMutationsByMoveRows(t.params,n,o);case wt.id:return this._getRefRangeMutationsByMoveCols(t.params,n,o);case Me.id:return this._getRefRangeMutationsByInsertRows(t.params,n,o);case ye.id:return this._getRefRangeMutationsByInsertCols(t.params,n,o);case Lt.id:return this._getRefRangeMutationsByDeleteCols(t.params,n,o);case $t.id:return this._getRefRangeMutationsByDeleteRows(t.params,n,o)}return{redos:[],undos:[]}}_getRefRangeMutationsByDeleteCols(t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(l=>l.ranges.some(u=>i.Rectangle.intersects(u,t.range))),a=t.range;if(r.length){const l=[],u=[];return r.forEach(d=>{const c=i.Tools.deepClone(d),m=c.ranges.reduce((h,R)=>{if(i.Rectangle.intersects(R,a)){const C=i.Tools.deepClone(R),{startColumn:S,endColumn:v}=a;if(S<=C.startColumn&&v>=C.endColumn)return h;S>=C.startColumn&&v<=C.endColumn?C.endColumn-=v-S+1:S<C.startColumn?(C.startColumn=S,C.endColumn-=v-S+1):v>C.endColumn&&(C.endColumn=S-1),this._checkIsRightRange(C)&&h.push(C)}return h},[]);c.ranges=m,c.ranges.length?(l.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:d.id}}),u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:d,ruleId:d.id}})):(l.push({id:Te.id,params:{unitId:n,subUnitId:o,ruleIds:[d.id]}}),u.push({id:Ce.id,params:{unitId:n,subUnitId:o,name:"",rules:[d]}}))}),{redos:l,undos:u}}return{undos:[],redos:[]}}_getRefRangeMutationsByDeleteRows(t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(l=>l.ranges.some(u=>i.Rectangle.intersects(u,t.range))),a=t.range;if(r.length){const l=[],u=[];return r.forEach(d=>{const c=i.Tools.deepClone(d),m=c.ranges.reduce((h,R)=>{if(i.Rectangle.intersects(R,a)){const C=i.Tools.deepClone(R),{startRow:S,endRow:v}=a;if(S<=C.startRow&&v>=C.endRow)return h;S>=C.startRow&&v<=C.endRow?C.endRow-=v-S+1:S<C.startRow?(C.startRow=S,C.endRow-=v-S+1):v>C.endRow&&(C.endRow=S-1),this._checkIsRightRange(C)&&h.push(C)}return h},[]);c.ranges=m,l.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:d.id}}),u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:d,ruleId:d.id}})}),{redos:l,undos:u}}return{undos:[],redos:[]}}_getRefRangeMutationsByInsertCols(t,n,o){const r=t.range.startColumn,a=t.range.endColumn-t.range.startColumn+1,l=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(u=>u.ranges.some(d=>r>d.startColumn&&r<=d.endColumn));if(l.length){const u=[],d=[];return l.forEach(c=>{const m=i.Tools.deepClone(c);let h=!1;m.ranges.forEach(R=>{r>R.startColumn&&r<=R.endColumn&&(R.endColumn+=a,h=!0)}),h&&(u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:c.id}}),d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:c.id}}))}),{redos:u,undos:d}}return{undos:[],redos:[]}}_getRefRangeMutationsByInsertRows(t,n,o){const r=t.range.startRow,a=t.range.endRow-t.range.startRow+1,l=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(u=>u.ranges.some(d=>r>d.startRow&&r<=d.endRow));if(l.length){const u=[],d=[];return l.forEach(c=>{const m=i.Tools.deepClone(c);let h=!1;m.ranges.forEach(R=>{r>R.startRow&&r<=R.endRow&&(R.endRow+=a,h=!0)}),h&&(u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:c.id}}),d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:c.id}}))}),{redos:u,undos:d}}return{undos:[],redos:[]}}_getRefRangeMutationsByMoveRows(t,n,o){const r=t.toRange,a=r.startRow,l=r.endRow-r.startRow+1,u=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(d=>d.ranges.some(c=>a>c.startRow&&a<=c.endRow));if(u.length){const d=[],c=[];return u.forEach(m=>{const h=i.Tools.deepClone(m),C=t.fromRange.startRow;let S=!1;h.ranges.forEach(v=>{a>v.startRow&&a<=v.endRow&&(C<v.startRow&&(v.startRow=v.startRow-l,v.endRow=v.endRow-l),v.endRow+=l,S=!0)}),S&&(d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:h,ruleId:m.id}}),c.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:m.id}}))}),{redos:d,undos:c}}return{undos:[],redos:[]}}_getRefRangeMutationsByMoveCols(t,n,o){const r=t.toRange,a=r.startColumn,l=r.endColumn-r.startColumn+1,u=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(d=>d.ranges.some(c=>a>c.startColumn&&a<=c.endColumn));if(u.length){const d=[],c=[];return u.forEach(m=>{const h=i.Tools.deepClone(m),C=t.fromRange.startColumn;let S=!1;h.ranges.forEach(v=>{a>v.startColumn&&a<=v.endColumn&&(C<v.startColumn&&(v.startColumn=v.startColumn-l,v.endColumn=v.endColumn-l),v.endColumn+=l,S=!0)}),S&&(d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:h,ruleId:m.id}}),c.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:m.id}}))}),{redos:d,undos:c}}return{undos:[],redos:[]}}_correctPermissionRange(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(ki.includes(t.id)){if(!t.params)return;const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const{sourceRange:r,targetRange:a}=t.params,l=r.startColumn===a.startColumn&&r.endColumn===a.endColumn,u=l?r.endRow-r.startRow+1:r.endColumn-r.startColumn+1,d=l?r.startRow:r.startColumn,c=l?a.startRow:a.startColumn;this._selectionProtectionRuleModel.getSubunitRuleList(n.getUnitId(),o.getSheetId()).forEach(v=>{v.ranges.forEach(M=>{let{startRow:p,endRow:w,startColumn:y,endColumn:b}=M;i.Rectangle.intersects(M,r)||(l?d<p&&c>w?(p-=u,w-=u):d>w&&c<=p&&(p+=u,w+=u):d<y&&c>b?(y-=u,b-=u):d>b&&c<=y&&(y+=u,b+=u)),this._checkIsRightRange({startRow:p,endRow:w,startColumn:y,endColumn:b})&&(M.startColumn=y,M.endColumn=b,M.startRow=p,M.endRow=w)})}),this.disposableCollection.dispose();const{unitId:h,subUnitId:R}=t.params,C=v=>this.refRangeHandle(v,h,R);this._selectionProtectionRuleModel.getSubunitRuleList(h,R).reduce((v,I)=>[...v,...I.ranges],[]).forEach(v=>{this.disposableCollection.add(this._refRangeService.registerRefRange(v,C,h,R))}),this._selectionProtectionRenderModel.clear()}if(Pi.includes(t.id)){const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const r=t.params;if(!r)return;const{range:a}=r,l=t.id.includes("row"),u=t.id.includes("insert"),d=l?a.startRow:a.startColumn,c=l?a.endRow:a.endColumn,m=c-d+1;this._selectionProtectionRuleModel.getSubunitRuleList(n.getUnitId(),o.getSheetId()).forEach(I=>{I.ranges.forEach(p=>{let{startRow:w,endRow:y,startColumn:b,endColumn:T}=p;u?l?d<=w&&(w+=m,y+=m):d<=b&&(b+=m,T+=m):l?c<w&&(w-=m,y-=m):c<b&&(b-=m,T-=m),this._checkIsRightRange({startRow:w,endRow:y,startColumn:b,endColumn:T})&&(p.startColumn=b,p.endColumn=T,p.startRow=w,p.endRow=y)})}),this.disposableCollection.dispose();const{unitId:R,subUnitId:C}=t.params,S=I=>this.refRangeHandle(I,R,C);this._selectionProtectionRuleModel.getSubunitRuleList(R,C).reduce((I,M)=>[...I,...M.ranges],[]).forEach(I=>{this.disposableCollection.add(this._refRangeService.registerRefRange(I,S,R,C))}),this._selectionProtectionRenderModel.clear()}}))}_checkIsRightRange(t){return t.startRow<=t.endRow&&t.startColumn<=t.endColumn}_initReBuildCache(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(Pi.includes(t.id)||ki.includes(t.id)){const{unitId:n,subUnitId:o}=t.params;this._rangeProtectionCache.reBuildCache(n,o)}}))}_initRemoveSheet(){this._sheetInterceptorService.interceptCommand({getMutations:t=>{const n=[],o=[],r=[],a=[];if(t.id===In.id){const l=t.params,u=[],d=[];this._rangeProtectionRuleModel.getSubunitRuleList(l.unitId,l.subUnitId).forEach(c=>{u.push(c.id),d.push(c)}),u.length&&d.length&&(r.push({id:Te.id,params:{unitId:l.unitId,subUnitId:l.subUnitId,ruleIds:u}}),n.push({id:Ce.id,params:{unitId:l.unitId,subUnitId:l.subUnitId,name:"",rules:d}}))}return{redos:o,undos:n,preRedos:r,preUndos:a}}})}},g.RangeProtectionRefRangeService=Id([qe(0,i.Inject(X)),qe(1,i.Inject(i.IUniverInstanceService)),qe(2,i.ICommandService),qe(3,i.Inject(g.RefRangeService)),qe(4,i.Inject(g.RangeProtectionRenderModel)),qe(5,i.Inject(g.RangeProtectionCache)),qe(6,i.Inject(g.SheetInterceptorService)),qe(7,i.Inject(X))],g.RangeProtectionRefRangeService);var pd=Object.getOwnPropertyDescriptor,wd=(s,e,t,n)=>{for(var o=n>1?void 0:n?pd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Xt=(s,e)=>(t,n)=>e(t,n,s);const Md="SHEET_RANGE_PROTECTION_PLUGIN";g.RangeProtectionService=class extends i.Disposable{constructor(e,t,n,o,r){super(),this._selectionProtectionRuleModel=e,this._permissionService=t,this._resourceManagerService=n,this._selectionProtectionCache=o,this._univerInstanceService=r,this._initSnapshot(),this._initRuleChange()}_initRuleChange(){this.disposeWithMe(this._selectionProtectionRuleModel.ruleChange$.subscribe(e=>{switch(e.type){case"add":{ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.addPermissionPoint(n)});break}case"delete":{ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.deletePermissionPoint(n.id)});break}case"set":{e.oldRule.permissionId!==e.rule.permissionId&&ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.oldRule.permissionId);this._permissionService.deletePermissionPoint(n.id);const o=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.addPermissionPoint(o)});break}}}))}_initSnapshot(){const e=n=>{const r=this._selectionProtectionRuleModel.toObject()[n];return r?JSON.stringify(r):""},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Md,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{const r=this._selectionProtectionRuleModel.toObject();r[n]=o,this._selectionProtectionRuleModel.fromObject(r);const a=[];Object.keys(o).forEach(l=>{const u=o[l];this._selectionProtectionRuleModel.getSubunitRuleList(n,l).forEach(d=>{a.push({objectID:d.permissionId,unitID:n,objectType:N.SelectRange,actions:Ge})}),u.forEach(d=>{ue().forEach(c=>{const m=new c(n,l,d.permissionId);m.value=!1,this._permissionService.addPermissionPoint(m)})}),this._selectionProtectionCache.reBuildCache(n,l)})},onUnLoad:n=>{this._selectionProtectionCache.deleteUnit(n)}}))}},g.RangeProtectionService=wd([Xt(0,i.Inject(X)),Xt(1,i.Inject(i.IPermissionService)),Xt(2,i.Inject(i.IResourceManagerService)),Xt(3,i.Inject(g.RangeProtectionCache)),Xt(4,i.Inject(i.IUniverInstanceService))],g.RangeProtectionService);var yd=Object.getOwnPropertyDescriptor,_d=(s,e,t,n)=>{for(var o=n>1?void 0:n?yd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},bd=(s,e)=>(t,n)=>e(t,n,s);g.SheetRangeThemeService=class extends i.Disposable{constructor(e){super(),this._sheetRangeThemeModel=e}registerRangeTheme(e,t){this._sheetRangeThemeModel.registerRangeThemeStyle(e,t)}removeRangeThemeRule(e,t){this._sheetRangeThemeModel.removeRangeThemeRule(e,t)}getALLRegisterThemes(e){return this._sheetRangeThemeModel.getALLRegisteredTheme(e)}registerRangeThemeStyle(e,t){this._sheetRangeThemeModel.registerRangeThemeRule(e,t)}getAppliedRangeThemeStyle(e){return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(e)}getRegisteredRangeThemes(){return this._sheetRangeThemeModel.getRegisteredRangeThemes()}},g.SheetRangeThemeService=_d([bd(0,i.Inject(g.SheetRangeThemeModel))],g.SheetRangeThemeService);var Ed=Object.defineProperty,Td=Object.getOwnPropertyDescriptor,Ud=(s,e,t)=>e in s?Ed(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Pd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Td(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Oi=(s,e)=>(t,n)=>e(t,n,s),Di=(s,e,t)=>Ud(s,typeof e!="symbol"?e+"":e,t);const kd="SHEET_PLUGIN";g.UniverSheetsPlugin=class extends i.Plugin{constructor(e=_i,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...o}=i.merge({},_i,this._config);this._configService.setConfig(yi,o),this._initConfig(),this._initDependencies()}_initConfig(){var e,t,n;(e=this._config)!=null&&e.onlyRegisterFormulaRelatedMutations&&this._configService.setConfig(Ei,!0),(t=this._config)!=null&&t.isRowStylePrecedeColumnStyle&&this._configService.setConfig(i.IS_ROW_STYLE_PRECEDE_COLUMN_STYLE,!0),(n=this._config)!=null&&n.autoHeightForMergedCells&&this._configService.setConfig(i.AUTO_HEIGHT_FOR_MERGED_CELLS,!0)}_initDependencies(){var t;const e=[[nt],[g.SheetsSelectionsService],[g.RefRangeService],[g.WorkbookPermissionService],[ot,{useClass:g.NumfmtService}],[g.SheetInterceptorService],[g.SheetRangeThemeService],[g.SheetSkeletonService],[kn],[g.MergeCellController],[Dn],[g.DefinedNameDataController],[g.ZebraCrossingCacheController],[g.SheetsFreezeSyncController],[g.WorksheetPermissionService],[ke],[Ut],[An],[g.SheetPermissionInitController],[g.SheetPermissionCheckController],[g.SheetRangeThemeModel],[g.RangeProtectionRenderModel],[X],[g.RangeProtectionCache],[g.RangeProtectionRefRangeService],[g.RangeProtectionService],[Zs,{useClass:Ui,deps:[g.SheetsSelectionsService]}]];(t=this._config)!=null&&t.notExecuteFormula||e.push([On]),i.registerDependencies(this._injector,i.mergeOverrideWithDependencies(e,this._config.override)),i.touchDependencies(this._injector,[[g.SheetInterceptorService],[g.RangeProtectionService],[Zs],[g.SheetPermissionInitController],[g.SheetsFreezeSyncController]])}onStarting(){i.touchDependencies(this._injector,[[kn],[g.MergeCellController],[g.WorkbookPermissionService],[g.WorksheetPermissionService],[An],[g.SheetSkeletonService]])}onRendered(){i.touchDependencies(this._injector,[[ot]])}onReady(){i.touchDependencies(this._injector,[[On],[g.DefinedNameDataController],[g.ZebraCrossingCacheController],[g.SheetRangeThemeModel],[Dn],[g.RangeProtectionRenderModel],[g.RangeProtectionRefRangeService],[g.RefRangeService],[g.SheetPermissionCheckController]])}},Di(g.UniverSheetsPlugin,"pluginName",kd),Di(g.UniverSheetsPlugin,"type",i.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsPlugin=Pd([i.DependentOn(J.UniverFormulaEnginePlugin),Oi(1,i.Inject(i.Injector)),Oi(2,i.IConfigService)],g.UniverSheetsPlugin);const Od={WorkbookCommentPermission:Yn,WorkbookCopyPermission:Kn,WorkbookCreateProtectPermission:Jn,WorkbookCreateSheetPermission:xn,WorkbookDeleteSheetPermission:Xn,WorkbookDuplicatePermission:Zn,WorkbookEditablePermission:me,WorkbookExportPermission:Qn,WorkbookHideSheetPermission:un,WorkbookHistoryPermission:Go,WorkbookManageCollaboratorPermission:dn,WorkbookMoveSheetPermission:cn,WorkbookPrintPermission:es,WorkbookRecoverHistoryPermission:ts,WorkbookRenameSheetPermission:mn,WorkbookSharePermission:ns,WorkbookViewHistoryPermission:os,WorkbookViewPermission:ss,WorksheetCopyPermission:rs,WorksheetDeleteColumnPermission:is,WorksheetDeleteProtectionPermission:as,WorksheetDeleteRowPermission:ls,WorksheetEditExtraObjectPermission:us,WorksheetEditPermission:fe,WorksheetFilterPermission:ds,WorksheetInsertColumnPermission:cs,WorksheetInsertHyperlinkPermission:ms,WorksheetInsertRowPermission:hs,WorksheetManageCollaboratorPermission:gs,WorksheetPivotTablePermission:Rs,WorksheetSetCellStylePermission:Cs,WorksheetSetCellValuePermission:Wt,WorksheetSetColumnStylePermission:St,WorksheetSetRowStylePermission:ft,WorksheetSortPermission:Ss,WorksheetViewPermission:Vt,RangeProtectionPermissionEditPoint:Se,RangeProtectionPermissionViewPoint:ln},Dd=(s,e,t,n)=>{const o=s.get(i.IPermissionService),r=s.get(X),a=o.getPermissionPoint(new me(e).id);if(!(a!=null&&a.value))return!1;const l=o.getPermissionPoint(new fe(e,t).id);if(!(l!=null&&l.value))return!1;const d=r.getSubunitRuleList(e,t).filter(c=>c.ranges.some(m=>n.some(h=>i.Rectangle.intersects(m,h))));return d.length?d.every(c=>{const m=c.permissionId,h=o.getPermissionPoint(new Se(e,t,m).id);return!!(h!=null&&h.value)}):!0},Ni=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startRow:l,endRow:u}=a;let d=t.startRow-n,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;for(;!e.getRowVisible(d)||!m;)d--,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;if(d>=l)return{...t,startRow:d,endRow:d};if(r){const h={...t,startRow:u,endRow:u};return Wi(s,e,h,n,o,!1)}},Ai=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startRow:l,endRow:u}=a;let d=t.endRow+n,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;for(;!e.getRowVisible(d)||!m;)d++,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;if(d<=u)return{...t,startRow:d,endRow:d};if(r){const h={...t,startRow:l,endRow:l};return Vi(s,e,h,n,o,!1)}},Wi=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startColumn:l,endColumn:u}=a;let d=t.startColumn-n,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;for(;!e.getColVisible(d)||!m;)d--,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;if(d>=l)return{...t,startColumn:d,endColumn:d};if(r){const h={...t,startColumn:u,endColumn:u};return Ni(s,e,h,n,o,!1)}},Vi=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startColumn:l,endColumn:u}=a;let d=t.endColumn+n,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;for(;!e.getColVisible(d)||!m;)d++,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;if(d<=u)return{...t,endColumn:d,startColumn:d};if(r){const h={...t,startColumn:l,endColumn:l};return Ai(s,e,h,n,o,!1)}};function Wn(s,e,t){let n=null;return t.getMatrixWithMergedCells(s,e,s,e).forValue((r,a,l)=>(n={actualRow:r,actualColumn:a,startRow:r,startColumn:a,isMerged:l.rowSpan!==void 0||l.colSpan!==void 0,isMergedMainCell:l.rowSpan!==void 0&&l.colSpan!==void 0,endRow:r+(l.rowSpan!==void 0?l.rowSpan-1:0),endColumn:a+(l.colSpan!==void 0?l.colSpan-1:0),rangeType:i.RANGE_TYPE.NORMAL},!1)),n||{actualColumn:e,actualRow:s,startRow:s,startColumn:e,endRow:s,endColumn:e,isMerged:!1,isMergedMainCell:!1,rangeType:i.RANGE_TYPE.NORMAL}}const Nd=(s,e,t,n,o=1)=>{switch(n){case i.Direction.UP:return Ni(s,e,t,o);case i.Direction.DOWN:return Ai(s,e,t,o);case i.Direction.LEFT:return Wi(s,e,t,o);case i.Direction.RIGHT:return Vi(s,e,t,o)}},Ad=(s,e,t)=>{let n,o=-1,r;for(let I=0;I<s.length;I++)if(s[I].primary){n=s[I],o=I,r=n.primary;break}if(o===-1)return null;const a=e===i.Direction.LEFT||e===i.Direction.UP,l=a?o-1>=0?o-1:s.length-1:o+1<s.length?o+1:0,u=s[l];if(!n||!r)return null;const d={...r},{startRow:c,startColumn:m,endRow:h,endColumn:R}=n.range,C=a?d.startRow===c&&d.startColumn===m:d.endRow===h&&d.endColumn===R,S=C&&a;if(!i.Rectangle.equals(n.range,d)){const I=C?u.range:Nd(n.range,t,d,e);if(!I)return null;const M=S?Wn(I.endRow,I.endColumn,t):Wn(I.startRow,I.startColumn,t);return{startRow:M.startRow,startColumn:M.startColumn,endRow:M.endRow,endColumn:M.endColumn}}const v=S?Wn(u.range.endRow,u.range.endColumn,t):Wn(u.range.startRow,u.range.startColumn,t);return{startRow:v.startRow,startColumn:v.startColumn,endRow:v.endRow,endColumn:v.endColumn}};g.AFTER_CELL_EDIT=Zt,g.AddMergeRedoSelectionsOperationFactory=Lu,g.AddMergeUndoMutationFactory=ge,g.AddMergeUndoSelectionsOperationFactory=Hu,g.AddRangeProtectionCommand=Do,g.AddRangeProtectionMutation=Ce,g.AddRangeThemeMutation=Ri,g.AddWorksheetMergeAllCommand=tu,g.AddWorksheetMergeCommand=Ft,g.AddWorksheetMergeHorizontalCommand=su,g.AddWorksheetMergeMutation=j,g.AddWorksheetMergeVerticalCommand=nu,g.AddWorksheetProtectionCommand=br,g.AddWorksheetProtectionMutation=Fe,g.AppendRowCommand=Tr,g.BEFORE_CELL_EDIT=$n,g.BorderStyleManagerService=nt,g.COMMAND_LISTENER_SKELETON_CHANGE=Ea,g.COMMAND_LISTENER_VALUE_CHANGE=Ta,g.CancelFrozenCommand=jr,g.CancelMarkDirtyRowAutoHeightMutation=fi,g.ClearSelectionAllCommand=sn,g.ClearSelectionContentCommand=fn,g.ClearSelectionFormatCommand=on,g.CopySheetCommand=Ds,g.DISABLE_NORMAL_SELECTIONS=sl,g.DeleteRangeMoveLeftCommand=He,g.DeleteRangeMoveUpCommand=Be,g.DeleteRangeProtectionCommand=Ur,g.DeleteRangeProtectionMutation=Te,g.DeleteWorksheetProtectionCommand=Pr,g.DeleteWorksheetProtectionMutation=tt,g.DeleteWorksheetRangeThemeStyleCommand=kr,g.DeleteWorksheetRangeThemeStyleMutation=it,g.DeleteWorksheetRangeThemeStyleMutationFactory=ao,g.DeltaColumnWidthCommand=Gt,g.DeltaRowHeightCommand=Kt,g.EditStateEnum=Oo,g.EffectRefRangId=A,g.EmptyMutation=Ci,g.ExclusiveRangeService=Ui,g.FactoryAddRangeProtectionMutation=Qa,g.FactoryDeleteRangeProtectionMutation=Za,g.FactorySetRangeProtectionMutation=Ru,g.IExclusiveRangeService=Zs,g.INTERCEPTOR_POINT=Ae,g.INumfmtService=ot,g.IRefSelectionsService=Vo,g.InsertColAfterCommand=nr,g.InsertColBeforeCommand=tr,g.InsertColByRangeCommand=ws,g.InsertColCommand=ye,g.InsertColMutation=ie,g.InsertColMutationUndoFactory=Ot,g.InsertDefinedNameCommand=Or,g.InsertMultiColsLeftCommand=sr,g.InsertMultiColsRightCommand=or,g.InsertMultiRowsAboveCommand=Zo,g.InsertMultiRowsAfterCommand=Qo,g.InsertRangeMoveDownCommand=xe,g.InsertRangeMoveRightCommand=It,g.InsertRowAfterCommand=Xo,g.InsertRowBeforeCommand=xo,g.InsertRowByRangeCommand=ps,g.InsertRowCommand=Me,g.InsertRowMutation=re,g.InsertRowMutationUndoFactory=en,g.InsertSheetCommand=Dr,g.InsertSheetMutation=yt,g.InsertSheetUndoMutationFactory=Os,g.InterceptCellContentPriority=to,g.MAX_CELL_PER_SHEET_KEY=wi,g.MERGE_CELL_INTERCEPTOR_CHECK=_r,g.MarkDirtyRowAutoHeightMutation=Si,g.MoveColsCommand=wt,g.MoveColsMutation=we,g.MoveColsMutationUndoFactory=uo,g.MoveRangeCommand=Je,g.MoveRangeMutation=Le,g.MoveRowsCommand=pt,g.MoveRowsMutation=pe,g.MoveRowsMutationUndoFactory=lo,g.OperatorType=H,g.PermissionPointsDefinitions=Od,g.REF_SELECTIONS_ENABLED=Ao,g.RangeMergeUtil=$a,g.RangeProtectionPermissionDeleteProtectionPoint=Gs,g.RangeProtectionPermissionEditPoint=Se,g.RangeProtectionPermissionManageCollaPoint=zs,g.RangeProtectionPermissionViewPoint=ln,g.RangeProtectionRuleModel=X,g.RangeThemeStyle=We,g.RegisterWorksheetRangeThemeStyleCommand=Nr,g.RegisterWorksheetRangeThemeStyleMutation=_t,g.RemoveColByRangeCommand=ys,g.RemoveColCommand=Lt,g.RemoveColMutation=ne,g.RemoveDefinedNameCommand=Ns,g.RemoveMergeUndoMutationFactory=le,g.RemoveNumfmtMutation=Ys,g.RemoveRangeThemeMutation=vi,g.RemoveRowByRangeCommand=Ms,g.RemoveRowCommand=$t,g.RemoveRowMutation=ae,g.RemoveSheetCommand=In,g.RemoveSheetMutation=Xe,g.RemoveSheetUndoMutationFactory=rr,g.RemoveWorksheetMergeCommand=Ar,g.RemoveWorksheetMergeMutation=G,g.ReorderRangeCommand=Rn,g.ReorderRangeMutation=Dt,g.ReorderRangeUndoMutationFactory=co,g.ResetBackgroundColorCommand=Xr,g.ResetTextColorCommand=Jr,g.SCOPE_WORKBOOK_VALUE_DEFINED_NAME=zu,g.SELECTIONS_ENABLED=ol,g.SELECTION_CONTROL_BORDER_BUFFER_COLOR=Ha,g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH=La,g.ScrollToCellOperation=pi,g.SelectRangeCommand=Lo,g.SelectionMoveType=te,g.SetBackgroundColorCommand=xr,g.SetBoldCommand=vu,g.SetBorderBasicCommand=Lr,g.SetBorderColorCommand=$r,g.SetBorderCommand=bt,g.SetBorderPositionCommand=Wr,g.SetBorderStyleCommand=Vr,g.SetColDataCommand=Hr,g.SetColDataMutation=at,g.SetColDataMutationFactory=mo,g.SetColHiddenCommand=wn,g.SetColHiddenMutation=lt,g.SetColVisibleMutation=ut,g.SetColWidthCommand=zt,g.SetDefinedNameCommand=Vs,g.SetFontFamilyCommand=yu,g.SetFontSizeCommand=_u,g.SetFrozenCommand=Fr,g.SetFrozenMutation=Oe,g.SetFrozenMutationFactory=$s,g.SetGridlinesColorCommand=Gr,g.SetGridlinesColorMutation=dt,g.SetHorizontalTextAlignCommand=Qr,g.SetItalicCommand=Iu,g.SetNumfmtMutation=Un,g.SetOverlineCommand=Mu,g.SetProtectionCommand=zr,g.SetRangeProtectionMutation=Q,g.SetRangeThemeMutation=Ii,g.SetRangeValuesCommand=vt,g.SetRangeValuesMutation=F,g.SetRangeValuesUndoMutationFactory=ce,g.SetRowDataCommand=qr,g.SetRowDataMutation=ct,g.SetRowDataMutationFactory=Ro,g.SetRowHeightCommand=Jt,g.SetRowHiddenCommand=Mn,g.SetRowHiddenMutation=Ke,g.SetRowVisibleMutation=Ye,g.SetSelectedColsVisibleCommand=Ws,g.SetSelectedRowsVisibleCommand=Ls,g.SetSelectionsOperation=q,g.SetSpecificColsVisibleCommand=Et,g.SetSpecificRowsVisibleCommand=Tt,g.SetStrikeThroughCommand=wu,g.SetStyleCommand=ee,g.SetTabColorCommand=ni,g.SetTabColorMutation=jt,g.SetTextColorCommand=Kr,g.SetTextRotationCommand=ti,g.SetTextWrapCommand=ei,g.SetUnderlineCommand=pu,g.SetVerticalTextAlignCommand=Zr,g.SetWorkbookNameCommand=Bs,g.SetWorkbookNameMutation=Hs,g.SetWorksheetActivateCommand=Fs,g.SetWorksheetActiveOperation=Ct,g.SetWorksheetColWidthMutation=Ve,g.SetWorksheetColWidthMutationFactory=Bn,g.SetWorksheetColumnCountCommand=si,g.SetWorksheetColumnCountMutation=mt,g.SetWorksheetColumnCountUndoMutationFactory=Co,g.SetWorksheetDefaultStyleCommand=oi,g.SetWorksheetDefaultStyleMutation=ht,g.SetWorksheetDefaultStyleMutationFactory=So,g.SetWorksheetHideCommand=ii,g.SetWorksheetHideMutation=je,g.SetWorksheetNameCommand=yn,g.SetWorksheetNameMutation=qt,g.SetWorksheetOrderCommand=js,g.SetWorksheetOrderMutation=Yt,g.SetWorksheetPermissionPointsCommand=li,g.SetWorksheetPermissionPointsMutation=bn,g.SetWorksheetProtectionCommand=ui,g.SetWorksheetProtectionMutation=st,g.SetWorksheetRangeThemeStyleCommand=Er,g.SetWorksheetRangeThemeStyleMutation=rt,g.SetWorksheetRangeThemeStyleMutationFactory=io,g.SetWorksheetRightToLeftCommand=Wu,g.SetWorksheetRightToLeftMutation=En,g.SetWorksheetRowAutoHeightMutation=jn,g.SetWorksheetRowAutoHeightMutationFactory=ba,g.SetWorksheetRowCountCommand=di,g.SetWorksheetRowCountMutation=gt,g.SetWorksheetRowCountUndoMutationFactory=fo,g.SetWorksheetRowHeightMutation=Ee,g.SetWorksheetRowIsAutoHeightCommand=Tn,g.SetWorksheetRowIsAutoHeightMutation=Re,g.SetWorksheetShowCommand=qs,g.SheetSkeletonChangeType=Io,g.SheetValueChangeType=po,g.SplitDelimiterEnum=Eo,g.SplitTextToColumnsCommand=ci,g.ToggleCellCheckboxCommand=mi,g.ToggleGridlinesCommand=hi,g.ToggleGridlinesMutation=Rt,g.UnitAction=_,g.UnitObject=N,g.UnregisterWorksheetRangeThemeStyleCommand=gi,g.UnregisterWorksheetRangeThemeStyleMutation=vn,g.VALIDATE_CELL=Qt,g.ViewStateEnum=ko,g.WorkbookCommentPermission=Yn,g.WorkbookCopyPermission=Kn,g.WorkbookCopySheetPermission=Bo,g.WorkbookCreateProtectPermission=Jn,g.WorkbookCreateSheetPermission=xn,g.WorkbookDeleteColumnPermission=Fo,g.WorkbookDeleteRowPermission=jo,g.WorkbookDeleteSheetPermission=Xn,g.WorkbookDuplicatePermission=Zn,g.WorkbookEditablePermission=me,g.WorkbookExportPermission=Qn,g.WorkbookHideSheetPermission=un,g.WorkbookHistoryPermission=Go,g.WorkbookInsertColumnPermission=zo,g.WorkbookInsertRowPermission=qo,g.WorkbookManageCollaboratorPermission=dn,g.WorkbookMoveSheetPermission=cn,g.WorkbookPrintPermission=es,g.WorkbookRecoverHistoryPermission=ts,g.WorkbookRenameSheetPermission=mn,g.WorkbookSelectionModel=No,g.WorkbookSharePermission=ns,g.WorkbookViewHistoryPermission=os,g.WorkbookViewPermission=ss,g.WorksheetCopyPermission=rs,g.WorksheetDeleteColumnPermission=is,g.WorksheetDeleteProtectionPermission=as,g.WorksheetDeleteRowPermission=ls,g.WorksheetEditExtraObjectPermission=us,g.WorksheetEditPermission=fe,g.WorksheetFilterPermission=ds,g.WorksheetInsertColumnPermission=cs,g.WorksheetInsertHyperlinkPermission=ms,g.WorksheetInsertRowPermission=hs,g.WorksheetManageCollaboratorPermission=gs,g.WorksheetPivotTablePermission=Rs,g.WorksheetProtectionPointModel=Ut,g.WorksheetProtectionRuleModel=ke,g.WorksheetSelectProtectedCellsPermission=hl,g.WorksheetSelectUnProtectedCellsPermission=gl,g.WorksheetSetCellStylePermission=Cs,g.WorksheetSetCellValuePermission=Wt,g.WorksheetSetColumnStylePermission=St,g.WorksheetSetRowStylePermission=ft,g.WorksheetSortPermission=Ss,g.WorksheetViewPermission=Vt,g.addMergeCellsUtil=ou,g.adjustRangeOnMutation=fr,g.alignToMergedCellsBorders=At,g.baseProtectionActions=Ge,g.checkCellValueType=Vn,g.checkRangesEditablePermission=Dd,g.convertPrimaryWithCoordToPrimary=bo,g.convertSelectionDataToRange=Ba,g.copyRangeStyles=$e,g.createTopMatrixFromMatrix=yo,g.createTopMatrixFromRanges=Mo,g.defaultWorkbookPermissionPoints=ai,g.defaultWorksheetPermissionPoint=_n,g.expandToContinuousRange=Wa,g.factoryRemoveNumfmtUndoMutation=$u,g.factorySetNumfmtUndoMutation=Vu,g.findAllRectangle=Gn,g.findFirstNonEmptyCell=xa,g.followSelectionOperation=Ue,g.generateNullCell=qn,g.generateNullCellValue=Uo,g.getAddMergeMutationRangeByType=ks,g.getAllRangePermissionPoint=ue,g.getAllWorkbookPermissionPoint=Pt,g.getAllWorksheetPermissionPoint=de,g.getAllWorksheetPermissionPointByPointPanel=ve,g.getCellAtRowCol=rl,g.getDefaultRangePermission=Pu,g.getInsertRangeMutations=fs,g.getMoveRangeUndoRedoMutations=rn,g.getNextPrimaryCell=Ad,g.getPrimaryForRange=se,g.getRemoveRangeMutations=vs,g.getSelectionsService=$o,g.getSeparateEffectedRangesOnCommand=Hl,g.getSheetCommandTarget=P,g.getSheetCommandTargetWorkbook=Hn,g.getSheetMutationTarget=Ie,g.getSkeletonChangedEffectedRange=Pa,g.getValueChangedEffectedRange=Ua,g.getVisibleRanges=Nt,g.handleBaseInsertRange=Qe,g.handleBaseMoveRowsCols=Bt,g.handleBaseRemoveRange=Ze,g.handleCommonDefaultRangeChangeWithEffectRefCommands=Ps,g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests=$l,g.handleDefaultRangeChangeWithEffectRefCommands=Us,g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests=Vl,g.handleDeleteRangeMoveLeft=Cr,g.handleDeleteRangeMoveUp=Sr,g.handleDeleteRangeMutation=Cl,g.handleIRemoveCol=Ts,g.handleIRemoveRow=cr,g.handleInsertCol=hr,g.handleInsertRangeMoveDown=gr,g.handleInsertRangeMoveRight=Rr,g.handleInsertRangeMutation=Rl,g.handleInsertRow=mr,g.handleMoveCols=Es,g.handleMoveRange=dr,g.handleMoveRows=bs,g.isSingleCellSelection=al,g.rangeMerge=zn,g.rangeToDiscreteRange=Po,g.rotateRange=he,g.runRefRangeMutations=et,g.setEndForRange=il,g.splitRangeText=To,g.transformCellsToRange=Pn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
3
|
+
`)?s.body.dataStream.length-2:s.body.dataStream.length;if(t<r){const l={st:t,ed:r},u=tn({},e,!0);u&&i.Tools.removeNull(u),i.Tools.isEmptyObject(u)||(l.ts=u),n.push(l)}s.body.textRuns=i.normalizeTextRuns(n)}function go(s,e){return e.v===void 0||e.v===null?e.v:s===i.CellValueType.NUMBER?Number(e.v):s===i.CellValueType.BOOLEAN?va(e.v)?1:0:s===i.CellValueType.STRING||s===i.CellValueType.FORCE_STRING?`${e.v}`:e.v}function va(s){if(typeof s=="string"){if(s.toUpperCase()==="TRUE")return!0;if(s.toUpperCase()==="FALSE")return!1;if(i.isSafeNumeric(s)){if(Number(s)===0)return!1;if(Number(s)===1)return!0}}if(typeof s=="number"){if(s===0)return!1;if(s===1)return!0}return typeof s=="boolean"?s:null}function Ia(s){return s==null?null:(s.f===void 0&&(s.f=null),s.si===void 0&&(s.si=null),s.p===void 0&&(s.p=null),s.v===void 0&&(s.v=null),s.t===void 0&&(s.t=null),s.s===void 0&&(s.s=null),s.custom===void 0&&(s.custom=null),s)}const ce=(s,e)=>{const{unitId:t,subUnitId:n,cellValue:o}=e,a=s.get(i.IUniverInstanceService).getUniverSheetInstance(t);if(a==null)throw new Error("workbook is null error!");const l=a.getSheetBySheetId(n);if(l==null)throw new Error("worksheet is null error!");const u=l.getCellMatrix(),d=a.getStyles(),c=new i.ObjectMatrix;return new i.ObjectMatrix(o).forValue((h,R,C)=>{const S=i.Tools.deepClone(u==null?void 0:u.getValue(h,R))||{},v=d.getStyleByCell(S),I=d.getStyleByCell(C);S.s=Ca(v,I),c.setValue(h,R,Ia(S))}),{...e,options:{},cellValue:c.getMatrix()}},F={id:"sheet.mutation.set-range-values",type:i.CommandType.MUTATION,handler:(s,e)=>{const{cellValue:t,subUnitId:n,unitId:o}=e,a=s.get(i.IUniverInstanceService).getUnit(o);if(!a)return!1;const l=a.getSheetBySheetId(n);if(!l)return!1;const u=l.getCellMatrix(),d=a.getStyles();return new i.ObjectMatrix(t).forValue((m,h,R)=>{if(!R)u.realDeleteValue(m,h);else{let C=u.getValue(m,h)||{};C=wa(R,C,d),i.Tools.isEmptyObject(C)?u.realDeleteValue(m,h):u.setValue(m,h,C)}}),!0}},pa=new Set(["f","p","si","custom","ref"]);function wa(s,e,t){const n=Li(t,s,e);return Object.keys(s).forEach(o=>{const r=o;if(pa.has(r)){const a=s[r];Ma(e,r,a)}else r==="v"?s.v!==void 0&&(e.v=go(n,s)):r==="s"&&Ra(t,e,s)}),e.v!==void 0&&(e.t=n,e.v=go(n,e)),e.v===null&&(delete e.t,delete e.v),e}function Ma(s,e,t){t===void 0||(t===null?delete s[e]:s[e]=t)}const Ro=(s,e)=>{const{unitId:t,subUnitId:n,rowData:o}=s,r={},a=e.getRowManager();for(const l in o){const u=o[l],d=a.getRow(Number(l));r[l]=ca(d,u)}return{unitId:t,subUnitId:n,rowData:r}},ct={id:"sheet.mutation.set-row-data",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rowData:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const{worksheet:r}=o,a=r.getRowManager();for(const l in t){const u=t[l];if(u==null){a.removeRow(Number(l));continue}const d=a.getRowOrCreate(Number(l));Object.assign(d,u)}return!0}},ya=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},Ye={id:"sheet.mutation.set-row-visible",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId).getRowManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startRow;l<a.endRow+1;l++){const u=o.getRowOrCreate(l);u!=null&&(u.hd=0)}}return!0}},_a=(s,e)=>{if(s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId)==null)throw new Error("universheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,ranges:e.ranges}},Ke={id:"sheet.mutation.set-row-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId).getRowManager();for(let r=0;r<e.ranges.length;r++){const a=e.ranges[r];for(let l=a.startRow;l<a.endRow+1;l++){const u=o.getRowOrCreate(l);u!=null&&(u.hd=1)}}return!0}},Bn=(s,e)=>{const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getColumnManager();for(let l=0;l<o.length;l++){const u=o[l];for(let d=u.startColumn;d<u.endColumn+1;d++)r[d]=a.getColumnWidth(d)}return{unitId:t,subUnitId:n,ranges:o,colWidth:r}},Ve={id:"sheet.mutation.set-worksheet-col-width",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{worksheet:o}=n,r=o.getColumnManager(),a=e.ranges;for(let l=0;l<a.length;l++){const u=a[l];for(let d=u.startColumn;d<u.endColumn+1;d++)o.getColVisible(d)&&(typeof e.colWidth=="number"?r.setColumnWidth(d,e.colWidth):i.Tools.isDefine(e.colWidth[d])&&r.setColumnWidth(d,e.colWidth[d]))}return!0}},Co=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetColumnCountUndoMutationFactory]: worksheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,columnCount:t.worksheet.getColumnCount()}},mt={id:"sheet.mutation.set-worksheet-column-count",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=Ie(t,e);return n?(n.worksheet.setColumnCount(e.columnCount),!0):!1}},ht={id:"sheet.mutation.set-worksheet-default-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{defaultStyle:t}=e,n=s.get(i.IUniverInstanceService),o=P(n);if(!o)return!1;const{worksheet:r}=o;return r?(r.setDefaultCellStyle(t),!0):!1}},So=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,subUnitId:n.getSheetId(),defaultStyle:n.getDefaultCellStyle()}},fo=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetRowCountUndoMutationFactory]: worksheet is null error!");return{unitId:e.unitId,subUnitId:e.subUnitId,rowCount:t.worksheet.getRowCount()}},gt={id:"sheet.mutation.set-worksheet-row-count",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),n=Ie(t,e);return n?(n.worksheet.setRowCount(e.rowCount),!0):!1}},vo=(s,e)=>{var l,u;const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getRowManager();for(const{startRow:d,endRow:c}of o)for(let m=d;m<c+1;m++)r[m]=(u=(l=a.getRow(m))==null?void 0:l.h)!=null?u:e.getConfig().defaultRowHeight;return{unitId:t,subUnitId:n,ranges:o,rowHeight:r}},Fn=(s,e)=>{var l;const{unitId:t,subUnitId:n,ranges:o}=s,r={},a=e.getRowManager();for(const{startRow:u,endRow:d}of o)for(let c=u;c<=d;c++)r[c]=(l=a.getRow(c))==null?void 0:l.ia;return{unitId:t,subUnitId:n,ranges:o,autoHeightInfo:r}},ba=(s,e)=>{var l,u;const{unitId:t,subUnitId:n,rowsAutoHeightInfo:o}=s,r=[],a=e.getRowManager();for(const d of o){const{row:c}=d;r.push({row:c,autoHeight:(u=(l=a.getRow(c))==null?void 0:l.ah)!=null?u:e.getConfig().defaultRowHeight})}return{unitId:t,subUnitId:n,rowsAutoHeightInfo:r}},Ee={id:"sheet.mutation.set-worksheet-row-height",type:i.CommandType.MUTATION,handler:(s,e)=>{const{ranges:t,rowHeight:n}=e,o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{worksheet:a}=r,l=a.getRowManager();for(const{startRow:u,endRow:d}of t)for(let c=u;c<=d;c++)typeof n=="number"?l.setRowHeight(c,n):i.Tools.isDefine(n[c])&&l.setRowHeight(c,n[c]);return!0}},Re={id:"sheet.mutation.set-worksheet-row-is-auto-height",type:i.CommandType.MUTATION,handler:(s,e)=>{var l;const{ranges:t,autoHeightInfo:n}=e,o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const a=r.worksheet.getRowManager();for(const{startRow:u,endRow:d}of t)for(let c=u;c<=d;c++){const m=a.getRowOrCreate(c);typeof n=="number"?m.ia=n:m.ia=(l=n[c])!=null?l:void 0}return!0}},jn={id:"sheet.mutation.set-worksheet-row-auto-height",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rowsAutoHeightInfo:t}=e,n=s.get(i.IUniverInstanceService),o=P(n,e);if(!o)return!1;const r=o.worksheet.getRowManager();for(const{row:a,autoHeight:l}of t){const u=r.getRowOrCreate(a);u.ah=l}return!0}},Rt={id:"sheet.mutation.toggle-gridlines",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=P(s.get(i.IUniverInstanceService),e);if(!t)return!1;const{worksheet:n}=t,o=n.getConfig();return o.showGridlines=e.showGridlines,!0}},Ct={id:"sheet.operation.set-worksheet-active",type:i.CommandType.OPERATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getWorksheets();for(const[,o]of n)if(o.getSheetId()===e.subUnitId)return t.setActiveSheet(o),!0;return!1}};var Io=(s=>(s.SET_WORKSHEET_ROW_HEIGHT="sheet.mutation.set-worksheet-row-height",s.SET_WORKSHEET_ROW_IS_AUTO_HEIGHT="sheet.mutation.set-worksheet-row-is-auto-height",s.SET_WORKSHEET_ROW_AUTO_HEIGHT="sheet.mutation.set-worksheet-row-auto-height",s.SET_WORKSHEET_COL_WIDTH="sheet.mutation.set-worksheet-col-width",s.SET_WORKSHEET_ACTIVE="sheet.operation.set-worksheet-active",s.MOVE_ROWS="sheet.mutation.move-rows",s.MOVE_COLUMNS="sheet.mutation.move-columns",s.SET_COL_HIDDEN="sheet.mutation.set-col-hidden",s.SET_COL_VISIBLE="sheet.mutation.set-col-visible",s.SET_ROW_HIDDEN="sheet.mutation.set-row-hidden",s.SET_ROW_VISIBLE="sheet.mutation.set-row-visible",s.INSERT_COL="sheet.mutation.insert-col",s.INSERT_ROW="sheet.mutation.insert-row",s.REMOVE_COL="sheet.mutation.remove-col",s.REMOVE_ROW="sheet.mutation.remove-rows",s.TOGGLE_GRIDLINES="sheet.mutation.toggle-gridlines",s.SET_GRIDLINES_COLOR="sheet.mutation.set-gridlines-color",s))(Io||{}),po=(s=>(s.SET_RANGE_VALUES="sheet.mutation.set-range-values",s.MOVE_RANGE="sheet.mutation.move-range",s.REMOVE_WORKSHEET_MERGE="sheet.mutation.remove-worksheet-merge",s.ADD_WORKSHEET_MERGE="sheet.mutation.add-worksheet-merge",s.REORDER_RANGE="sheet.mutation.reorder-range",s.SET_WORKSHEET_DEFAULT_STYLE="sheet.mutation.set-worksheet-default-style",s.SET_ROW_DATA="sheet.mutation.set-row-data",s.SET_COL_DATA="sheet.mutation.set-col-data",s.SET_WORKSHEET_RANGE_THEME_STYLE="sheet.mutation.set-worksheet-range-theme-style",s.DELETE_WORKSHEET_RANGE_THEME_STYLE="sheet.mutation.delete-worksheet-range-theme-style",s))(po||{});const Ea=[Ee.id,Re.id,jn.id,Ve.id,Ct.id,pe.id,we.id,lt.id,ut.id,Ke.id,Ye.id,ie.id,re.id,ne.id,ae.id,Rt.id,dt.id,gt.id,mt.id],Ta=[F.id,Le.id,G.id,j.id,Ot.id,ht.id,ct.id,at.id,rt.id,it.id];function Ua(s){switch(s.id){case"sheet.mutation.set-range-values":{const e=s.params,t=new i.ObjectMatrix(e.cellValue).getDataRange();return t.endRow===-1?[]:e.cellValue?[{unitId:e.unitId,subUnitId:e.subUnitId,range:t}]:[]}case"sheet.mutation.move-range":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.from.subUnitId,range:new i.ObjectMatrix(e.from.value).getRange()},{unitId:e.unitId,subUnitId:e.to.subUnitId,range:new i.ObjectMatrix(e.to.value).getRange()}]}case"sheet.mutation.remove-worksheet-merge":{const e=s.params;return e.ranges.map(t=>({unitId:e.unitId,subUnitId:e.subUnitId,range:t}))}case"sheet.mutation.add-worksheet-merge":{const e=s.params;return e.ranges.map(t=>({unitId:e.unitId,subUnitId:e.subUnitId,range:t}))}case"sheet.mutation.reorder-range":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}]}case"sheet.mutation.set-worksheet-default-style":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:0,endRow:Number.MAX_SAFE_INTEGER,startColumn:0,endColumn:Number.MAX_SAFE_INTEGER}}]}case"sheet.mutation.set-row-data":{const e=s.params,t=Object.keys(e.rowData).map(Number);return t.length===0?[]:[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:Math.min(...t),endRow:Math.max(...t),startColumn:0,endColumn:Number.MAX_SAFE_INTEGER}}]}case"sheet.mutation.set-col-data":{const e=s.params,t=Object.keys(e.columnData).map(Number);return t.length===0?[]:[{unitId:e.unitId,subUnitId:e.subUnitId,range:{startRow:0,endRow:Number.MAX_SAFE_INTEGER,startColumn:Math.min(...t),endColumn:Math.max(...t)}}]}case"sheet.mutation.set-worksheet-range-theme-style":case"sheet.mutation.delete-worksheet-range-theme-style":{const e=s.params;return[{unitId:e.unitId,subUnitId:e.subUnitId,range:e.range}]}default:return[]}}function Pa(s,e){switch(s.id){case"sheet.mutation.set-worksheet-row-height":case"sheet.mutation.set-worksheet-row-is-auto-height":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.set-worksheet-row-auto-height":{const t=s.params;return t.rowsAutoHeightInfo.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{startRow:n.row,endRow:n.row,startColumn:0,endColumn:e-1,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.set-worksheet-col-width":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.COLUMN}}))}case"sheet.mutation.move-rows":case"sheet.mutation.move-columns":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:t.targetRange},{unitId:t.unitId,subUnitId:t.subUnitId,range:t.sourceRange}]}case"sheet.mutation.set-col-hidden":case"sheet.mutation.set-col-visible":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.COLUMN}}))}case"sheet.mutation.set-row-hidden":case"sheet.mutation.set-row-visible":{const t=s.params;return t.ranges.map(n=>({unitId:t.unitId,subUnitId:t.subUnitId,range:{...n,rangeType:i.RANGE_TYPE.ROW}}))}case"sheet.mutation.insert-col":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.COLUMN}}]}case"sheet.mutation.insert-row":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.ROW}}]}case"sheet.mutation.remove-col":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.COLUMN}}]}case"sheet.mutation.remove-rows":{const t=s.params;return[{unitId:t.unitId,subUnitId:t.subUnitId,range:{...t.range,rangeType:i.RANGE_TYPE.ROW}}]}case"sheet.mutation.toggle-gridlines":case"sheet.mutation.set-gridlines-color":return[];default:return[]}}function wo(s){return s==null?!1:s.v!==void 0&&s.v!==null&&s.v!==""||s.p!==void 0}function nn(s,e){return s&&s.spanAnchor?wo(e.getValue(s.spanAnchor.startRow,s.spanAnchor.startColumn)):wo(s)}function ka(s,e,t,n,o){const r=s.getCellMatrix(),a=s.getSpanModel().getMergedCellRange(e,t,n,o),l=new i.ObjectMatrix;return r.forValue((u,d)=>{const c=r.getValue(u,d);c&&l.setValue(u,d,c)}),a.forEach(u=>{const{startColumn:d,startRow:c,endColumn:m,endRow:h}=u;i.createRowColIter(c,h,d,m).forEach((R,C)=>{R===c&&C===d&&l.setValue(R,C,{...r.getValue(R,C),spanAnchor:{startRow:c,endRow:h,startColumn:d,endColumn:m}}),(R!==c||C!==d)&&(l.realDeleteValue(R,C),l.setValue(R,C,{spanAnchor:{startRow:c,endRow:h,startColumn:d,endColumn:m}}))})}),l}function Na(s,e,t,n){const{startRow:o,startColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=a;d++){const c=e.getValue(d,r-t);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.startColumn=s.startColumn-t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Oa(s,e,t,n){const{startRow:o,endColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=a;d++){const c=e.getValue(d,r+t);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.endColumn=s.endColumn+t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Da(s,e,t,n){const{startRow:o,startColumn:r,endColumn:a}=s;let l=null,u=!1;for(let d=r;d<=a;d++){const c=e.getValue(o-t,d);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.startRow=s.startRow-t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Aa(s,e,t,n){const{startColumn:o,endColumn:r,endRow:a}=s;let l=null,u=!1;for(let d=o;d<=r;d++){const c=e.getValue(a+t,d);if(u=u||nn(c,e),!n&&u)break;c&&c.spanAnchor&&(l?l={startRow:Math.min(c.spanAnchor.startRow,l.startRow),startColumn:Math.min(c.spanAnchor.startColumn,l.startColumn),endRow:Math.max(c.spanAnchor.endRow,l.endRow),endColumn:Math.max(c.spanAnchor.endColumn,l.endColumn)}:l={startRow:c.spanAnchor.startRow,startColumn:c.spanAnchor.startColumn,endRow:c.spanAnchor.endRow,endColumn:c.spanAnchor.endColumn})}return u?(s.endRow=s.endRow+t,{spanAnchor:l,hasValue:!0,range:s}):{spanAnchor:null,hasValue:!1,range:s}}function Wa(s,e,t){const n=t.getMaxRows(),o=t.getMaxColumns(),r=ka(t,0,0,n-1,o-1),a=t.getSnapshot().mergeData.length>0,{left:l,right:u,up:d,down:c}=e;let m=!0,h={...s};const R=[];for(;m;){if(m=!1,d&&h.startRow!==0){const{hasValue:C,range:S,spanAnchor:v}=Da(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(c&&h.endRow!==n-1){const{hasValue:C,range:S,spanAnchor:v}=Aa(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(l&&h.startColumn!==0){const{hasValue:C,range:S,spanAnchor:v}=Na(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}if(u&&h.endColumn!==o-1){const{hasValue:C,range:S,spanAnchor:v}=Oa(h,r,1,a);if(v&&R.push(v),C){h=S,m=!0;continue}}}return R.length>0&&(h=i.Rectangle.union(h,...R)),h}const Mo=s=>{const e=new i.ObjectMatrix;return s.forEach(t=>{i.Range.foreach(t,(n,o)=>{e.setValue(n,o,1)})}),e.forValue((t,n)=>{const o=e.getValue(t-1,n);o&&e.setValue(t,n,o+1)}),e},yo=s=>{const e=s;return e.forValue((t,n)=>{const o=s.getValue(t-1,n);o&&e.setValue(t,n,o+1)}),e},_o=s=>{const e={area:0},t=(n,o)=>e.area<n?(e.area=n,e.range=o,!0):!1;return s.forValue((n,o,r)=>{let a=1,l=r;t(a*l,{startRow:n-l+1,endRow:n,startColumn:o,endColumn:o});const u={startRow:n-l+1,endRow:n,startColumn:0,endColumn:o};for(let d=o-1;d>=0&&s.getValue(n,d);d--){l=Math.min(s.getValue(n,d)||0,l),a++;const c=l*a;u.startColumn=d,u.startRow=n-l+1,t(c,u)}}),e},Va=(s,e)=>{i.Range.foreach(e,(t,n)=>{s.realDeleteValue(t,n)});for(let t=e.startColumn;t<=e.endColumn;t++){const n=e.endRow+1;if(s.getValue(n,t)>0){s.setValue(n,t,1);let r=n+1;for(;s.getValue(r,t)>0;)s.setValue(r,t,s.getValue(r-1,t)+1),r++}}return s},Gn=s=>{const e=[];let t=_o(s);for(;t.area>0;)t.range&&(e.push(t.range),Va(s,t.range)),t=_o(s);return e},zn=s=>{const e=Mo(s);return Gn(e)};class $a{constructor(){f(this,"_matrix",new i.ObjectMatrix)}add(...e){return e.forEach(t=>{i.Range.foreach(t,(n,o)=>{this._matrix.setValue(n,o,1)})}),this}subtract(...e){return e.forEach(t=>{i.Range.foreach(t,(n,o)=>{this._matrix.realDeleteValue(n,o)})}),this}merge(){const e=yo(this._matrix);return Gn(e)}}const La=1.5,Ha="rgba(255, 255, 255, 0.01)";function Ba(s){const{rangeWithCoord:e,primaryWithCoord:t,style:n}=s,o={range:{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,rangeType:e.rangeType,unitId:e.unitId,sheetId:e.sheetId},primary:null,style:n};return t!=null&&(o.primary=bo(t)),o}function bo(s){const{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:o}=s,{startRow:r,startColumn:a,endRow:l,endColumn:u}=s.mergeInfo;return{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:o,startRow:r,startColumn:a,endRow:l,endColumn:u}}var Eo=(s=>(s[s.Tab=1]="Tab",s[s.Comma=2]="Comma",s[s.Semicolon=4]="Semicolon",s[s.Space=8]="Space",s[s.Custom=16]="Custom",s))(Eo||{});class Fa{constructor(){f(this,"_tabCount",0);f(this,"_commaCount",0);f(this,"_semicolonCount",0);f(this,"_spaceCount",0)}add(e){switch(e){case" ":this._tabCount++;break;case",":this._commaCount++;break;case";":this._semicolonCount++;break;case" ":this._spaceCount++;break}}update(e){e&&typeof e=="string"&&(e.includes(" ")&&this._tabCount++,e.includes(",")&&this._commaCount++,e.includes(";")&&this._semicolonCount++,e.trim().includes(" ")&&this._spaceCount++)}getDelimiter(){const e=Math.max(this._tabCount,this._commaCount,this._semicolonCount,this._spaceCount);return e===0||e===this._tabCount?1:e===this._commaCount?2:e===this._semicolonCount?4:e===this._spaceCount?8:1}}function ja(s,e,t){const n=[];t!==void 0&&(s&16)>0&&n.push(t),(s&1)>0&&n.push(" "),(s&2)>0&&n.push(","),(s&4)>0&&n.push(";"),(s&8)>0&&n.push(" ");let o="";for(const a of n)o+=Ga(a);let r="[".concat(o,"]");return e&&(r+="+"),new RegExp(r)}function Ga(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const za=s=>{var t;return((t=s.body)==null?void 0:t.dataStream.replace(/\r\n$/,""))||""};function qa(s){if(s!=null){if(s.p)return za(s.p);if(s.v&&typeof s.v=="string")return s.v;if(s.t&&(s.t===i.CellValueType.FORCE_STRING||s.t===i.CellValueType.STRING))return String(s.v)}}function To(s,e,t,n,o=!1){const r=i.Range.transformRange(e,s),{startColumn:a,startRow:l,endColumn:u,endRow:d}=r;if(a!==u)throw new Error("The range must be in the same column.");if(t&&(t&16)>0&&(n===void 0||n.length!==1))throw new Error("The custom delimiter must a character.");const c=t===void 0,m=c?new Fa:null,h=[];for(let p=l;p<=d;p++){const w=s.getCell(p,a),y=qa(w);h.push(y),m&&m.update(y)}const R=c?m.getDelimiter():t,C=ja(R,o,n);let S=-1,v=0,I=0;const M=[];for(const p of h){if(p!==void 0){const w=String(p).split(C);S<0?S=w.length:S=Math.max(S,w.length),M.push(w),v=I}else M.push(void 0);I++}return{rs:M,maxLength:S===-1?0:S,lastRow:v}}const Ya=(s,e,t="")=>s.reduce((n,o)=>{const r=o&&o[e];return typeof r!="string"?(console.warn(o,`${e} is not string`),n):(r?(n[r]||(n[r]=[]),n[r].push(o)):n[t].push(o),n)},{}),Ka=(s=0)=>{let e=s;return function(){return e++}};function Ja(s){return s==null?!1:s.v!==void 0&&s.v!==null&&s.v!==""||s.p!==void 0}function xa(s,e){for(let t=s.startRow;t<=s.endRow;t++)for(let n=s.startColumn;n<=s.endColumn;n++){const o=e.getCell(t,n);if(Ja(o))return{startRow:t,startColumn:n,endRow:t,endColumn:n}}return null}function qn(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,null)}),e.clone()}function Uo(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,{v:null,p:null,f:null,si:null,custom:null})}),e.clone()}function Xa(s){const e=new i.ObjectMatrix;return s.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:a}=t;for(let l=n;l<=r;l++)for(let u=o;u<=a;u++)e.setValue(l,u,{s:null})}),e.clone()}function Po(s,e,t,n){const o=e.get(i.IUniverInstanceService),r=t?o.getUnit(t,i.UniverInstanceType.UNIVER_SHEET):o.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),a=n?r==null?void 0:r.getSheetBySheetId(n):r==null?void 0:r.getActiveSheet();if(!a)return null;const{startRow:l,endRow:u,startColumn:d,endColumn:c}=s,m=[],h=[];for(let R=l;R<=u;R++)a.getRowFiltered(R)||m.push(R);for(let R=d;R<=c;R++)h.push(R);return{rows:m,cols:h}}function Dt(s,e,t,n){const o=[],r=[];for(const h of s){const R=Po(h,e,t,n);R&&(o.push(...R.rows),r.push(...R.cols))}const a=Array.from(new Set(o)).sort((h,R)=>h-R),l=Array.from(new Set(r)).sort((h,R)=>h-R),u=[];function d(h){const R=[];let C=h[0];for(let S=1;S<h.length;S++)h[S]!==h[S-1]+1&&(R.push([C,h[S-1]]),C=h[S]);return R.push([C,h[h.length-1]]),R}const c=d(a),m=d(l);for(const[h,R]of c)for(const[C,S]of m)u.push({startRow:h,endRow:R,startColumn:C,endColumn:S});return u}var ko=(s=>(s.OthersCanView="othersCanView",s.NoOneElseCanView="noOneElseCanView",s))(ko||{}),No=(s=>(s.DesignedUserCanEdit="designedUserCanEdit",s.OnlyMe="onlyMe",s))(No||{});class X{constructor(){f(this,"_model",new Map);f(this,"_ruleChange$",new O.Subject);f(this,"ruleChange$",this._ruleChange$.asObservable());f(this,"_ruleRefresh$",new O.Subject);f(this,"ruleRefresh$",this._ruleRefresh$.asObservable());f(this,"_rangeRuleInitStateChange",new O.BehaviorSubject(!1));f(this,"rangeRuleInitStateChange$",this._rangeRuleInitStateChange.asObservable())}dispose(){this._ruleChange$.complete(),this._ruleRefresh$.complete()}ruleRefresh(e){this._ruleRefresh$.next(e)}getRangeRuleInitState(){return this._rangeRuleInitStateChange.value}changeRuleInitState(e){this._rangeRuleInitStateChange.next(e)}addRule(e,t,n){this._ensureRuleMap(e,t).set(n.id,n),this._ruleChange$.next({unitId:e,subUnitId:t,rule:n,type:"add"})}deleteRule(e,t,n){var r,a,l,u;const o=(a=(r=this._model.get(e))==null?void 0:r.get(t))==null?void 0:a.get(n);o&&((u=(l=this._model.get(e))==null?void 0:l.get(t))==null||u.delete(n),this._ruleChange$.next({unitId:e,subUnitId:t,rule:o,type:"delete"}))}setRule(e,t,n,o){var a,l;const r=this.getRule(e,t,n);r&&((l=(a=this._model.get(e))==null?void 0:a.get(t))==null||l.set(n,o),this._ruleChange$.next({unitId:e,subUnitId:t,oldRule:r,rule:o,type:"set"}))}getRule(e,t,n){var o,r;return(r=(o=this._model.get(e))==null?void 0:o.get(t))==null?void 0:r.get(n)}getSubunitRuleList(e,t){var o;return[...(((o=this._model.get(e))==null?void 0:o.get(t))||new Map).values()]}getSubunitRuleListLength(e,t){var o;const n=(o=this._model.get(e))==null?void 0:o.get(t);return n?n.size:0}_ensureRuleMap(e,t){let n=this._model.get(e);n||(n=new Map,this._model.set(e,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n),r=[...o.keys()];e[n]={},r.forEach(a=>{const l=o.get(a);e[n][a]=[...l.values()]})}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n],r=new Map;Object.keys(o).forEach(a=>{const l=o[a].reduce((u,d)=>(u.set(d.id,d),u),new Map);r.set(a,l)}),t.set(n,r)}),this._model=t}deleteUnitModel(e){this._model.delete(e)}createRuleId(e,t){let n=i.generateRandomId(4);const o=this._ensureRuleMap(e,t);for(;o.has(n);)n=i.generateRandomId(4);return n}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)for(const a of r.values())if(a.permissionId===t)return[e,o];return null}}const Za=(s,e)=>{const t=s.get(X),n=e.ruleIds.map(r=>t.getRule(e.unitId,e.subUnitId,r)).filter(r=>!!r);return{id:Ce.id,params:{subUnitId:e.subUnitId,unitId:e.unitId,rules:n}}},Te={id:"sheet.mutation.delete-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,ruleIds:o}=e,r=s.get(X);return o.forEach(a=>{r.deleteRule(t,n,a)}),!0}},Qa=s=>{const e={...s,ruleIds:s.rules.map(t=>t.id)};return{id:Te.id,params:e}},Ce={id:"sheet.mutation.add-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rules:o}=e,r=s.get(X);return o.forEach(a=>{r.addRule(t,n,a)}),!0}},Oo={type:i.CommandType.COMMAND,id:"sheet.command.add-range-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(X),{rule:r,permissionId:a}=e,{unitId:l,subUnitId:u,ranges:d,description:c,viewState:m,editState:h}=r,R=[{ranges:d,permissionId:a,id:o.createRuleId(l,u),description:c,unitType:r.unitType,unitId:l,subUnitId:u,viewState:m,editState:h}];if(await t.executeCommand(Ce.id,{unitId:l,subUnitId:u,rules:R})){const S=[{id:Ce.id,params:{unitId:l,subUnitId:u,rules:R}}],v=[{id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:R.map(I=>I.id)}}];n.pushUndoRedo({unitID:l,redoMutations:S,undoMutations:v})}return!0}};var te=(s=>(s[s.MOVE_START=0]="MOVE_START",s[s.MOVING=1]="MOVING",s[s.MOVE_END=2]="MOVE_END",s[s.ONLY_SET=3]="ONLY_SET",s))(te||{});class Do extends i.Disposable{constructor(t){super();f(this,"_worksheetSelections",new Map);f(this,"_selectionMoveStart$",new O.Subject);f(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());f(this,"_selectionMoving$",new O.Subject);f(this,"selectionMoving$",this._selectionMoving$.asObservable());f(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));f(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());f(this,"_selectionSet$",new O.BehaviorSubject([]));f(this,"selectionSet$",this._selectionSet$.asObservable());f(this,"selectionChanged$");f(this,"_beforeSelectionMoveEnd$",new O.BehaviorSubject([]));f(this,"beforeSelectionMoveEnd$",this._beforeSelectionMoveEnd$.asObservable());this._workbook=t,this.selectionChanged$=O.merge(this._selectionMoveEnd$,this._selectionSet$)}dispose(){super.dispose(),this._beforeSelectionMoveEnd$.complete(),this._selectionMoveEnd$.complete(),this._selectionMoving$.complete(),this._selectionMoveStart$.complete(),this._selectionSet$.complete(),this._workbook=null}addSelections(t,n){const o=this.getSelectionsOfWorksheet(t);o.push(...n),this._selectionSet$.next(o)}setSelections(t,n=[],o){switch(this.setSelectionsOfWorksheet(t,n),o){case te.MOVE_START:this._selectionMoveStart$.next(n);break;case te.MOVING:this._selectionMoving$.next(n);break;case te.MOVE_END:this._beforeSelectionMoveEnd$.next(n),this._selectionMoveEnd$.next(n);break;case te.ONLY_SET:{this._selectionSet$.next(n);break}default:this._selectionSet$.next(n);break}}getCurrentSelections(){return this._getCurrentSelections()}getSelectionOfWorksheet(t){return this.getSelectionsOfWorksheet(t)}getSelectionsOfWorksheet(t){return this._worksheetSelections.has(t)||this._worksheetSelections.set(t,[]),this._worksheetSelections.get(t)}setSelectionsOfWorksheet(t,n){this._worksheetSelections.set(t,[...n])}deleteSheetSelection(t){this._worksheetSelections.set(t,[])}clear(){this._worksheetSelections.clear(),this._selectionSet$.next([])}_getCurrentSelections(){return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId())}getCurrentLastSelection(){const t=this._getCurrentSelections();return t[t.length-1]}}var el=Object.getOwnPropertyDescriptor,tl=(s,e,t,n)=>{for(var o=n>1?void 0:n?el(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},nl=(s,e)=>(t,n)=>e(t,n,s);g.SheetsSelectionsService=class extends i.RxDisposable{constructor(t){super();f(this,"_cellStylesCache",new Map);f(this,"selectionMoveStart$");f(this,"selectionMoving$");f(this,"selectionMoveEnd$");f(this,"selectionSet$");f(this,"selectionChanged$");f(this,"_workbookSelections",new Map);this._instanceSrv=t,this._init()}get _currentSelectionPos(){const t=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const n=t.getActiveSheet();return{unitId:t.getUnitId(),sheetId:n.getSheetId()}}get currentSelectionParam(){return this._currentSelectionPos}_init(){const t=this._instanceSrv.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).pipe(O.shareReplay(1),O.takeUntil(this.dispose$));this.selectionMoveStart$=t.pipe().pipe(O.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoveStart$:O.of())).pipe(O.takeUntil(this.dispose$)),this.selectionMoving$=t.pipe(O.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoving$:O.of())).pipe(O.takeUntil(this.dispose$)),this.selectionMoveEnd$=t.pipe(O.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionMoveEnd$:O.of([]))).pipe(O.takeUntil(this.dispose$)),this.selectionSet$=t.pipe(O.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionSet$:O.of([]))).pipe(O.takeUntil(this.dispose$)),this.selectionChanged$=t.pipe(O.switchMap(n=>n?this._ensureWorkbookSelection(n.getUnitId()).selectionChanged$:O.of([]))).pipe(O.distinctUntilChanged((n,o)=>n.length!==o.length?!1:n.length===0&&o.length===0?!0:n.every((r,a)=>JSON.stringify(r)===JSON.stringify(o[a]))),O.skip(1)).pipe(O.takeUntil(this.dispose$)),this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(n=>{this._removeWorkbookSelection(n.getUnitId())})),this.disposeWithMe(this.selectionChanged$.pipe(O.takeUntil(this.dispose$)).subscribe(()=>{this._cellStylesCache.clear()}))}dispose(){super.dispose(),this._cellStylesCache.clear(),this._workbookSelections.forEach(t=>t.dispose()),this._workbookSelections.clear(),this.selectionMoveStart$=O.of(null),this.selectionMoving$=O.of(null),this.selectionMoveEnd$=O.of([]),this.selectionSet$=O.of(null),this.selectionChanged$=O.of(null)}clear(){this._workbookSelections.forEach(t=>t.clear())}getCurrentSelections(){return this._getCurrentSelections()}getCurrentLastSelection(){const t=this._getCurrentSelections();return t==null?void 0:t[t.length-1]}addSelections(t,n,o){if(typeof t=="string"){this._ensureWorkbookSelection(t).addSelections(n,o);return}const r=this._currentSelectionPos;if(!r)throw new Error("[SheetsSelectionsService]: cannot find current selection position!");const{unitId:a,sheetId:l}=r;this._ensureWorkbookSelection(a).addSelections(l,t)}setSelections(t,n,o,r){if(typeof t=="string"&&typeof n=="string"){const d=t;this._ensureWorkbookSelection(d).setSelections(n,o||[],r!=null?r:te.ONLY_SET);return}const a=this._currentSelectionPos;if(!a)throw new Error("[SheetsSelectionsService]: cannot find current selection position!");const{unitId:l,sheetId:u}=a;if(typeof t=="object"){const d=t!=null?t:o,c=n!=null?n:te.ONLY_SET;this._ensureWorkbookSelection(l).setSelections(u,d,c)}}clearCurrentSelections(){this._getCurrentSelections().splice(0)}isOverlapping(){const t=this.getCurrentSelections();return t==null?!1:t.some(({range:n},o)=>t.some(({range:r},a)=>o===a?!1:n.startRow<=r.endRow&&n.endRow>=r.startRow&&n.startColumn<=r.endColumn&&n.endColumn>=r.startColumn))}_getCurrentSelections(){const t=this._currentSelectionPos;if(!t)return[];const{unitId:n,sheetId:o}=t;return this._ensureWorkbookSelection(n).getSelectionsOfWorksheet(o)}getWorkbookSelections(t){return this._ensureWorkbookSelection(t)}_ensureWorkbookSelection(t){let n=this._workbookSelections.get(t);if(!n){const o=this._instanceSrv.getUnit(t);if(!o)throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${t}"!`);n=new Do(o),this._workbookSelections.set(t,n)}return n}_removeWorkbookSelection(t){this._workbookSelections.delete(t)}getCellStylesProperty(t){var a;const n=(a=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:a.getActiveSheet(),o=this.getCurrentSelections();if(!n||o.length===0)return{isAllValuesSame:!1,value:null};let r=null;for(let l=0;l<o.length;l++){const u=o[l],{startRow:d,endRow:c,startColumn:m,endColumn:h}=u.range;for(let R=d;R<=c;R++)for(let C=m;C<=h;C++){const S=`${R}_${C}`;let v;this._cellStylesCache.has(S)?v=this._cellStylesCache.get(S):(v=n.getComposedCellStyle(R,C),this._cellStylesCache.set(S,v));const I=v[t];if(r!=null&&!i.Tools.diffValue(r,I))return{isAllValuesSame:!1,value:null};r=I}}return{isAllValuesSame:!0,value:r}}},g.SheetsSelectionsService=tl([nl(0,i.IUniverInstanceService)],g.SheetsSelectionsService);const sl="DISABLE_NORMAL_SELECTIONS",ol="SELECTIONS_ENABLED",Ao="REF_SELECTIONS_ENABLED",sn={id:"sheet.command.clear-selection-all",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Dt(m,s,u,c),R=[],C=[],S={subUnitId:c,unitId:u,cellValue:qn(h)},v=ce(s,S);R.push({id:F.id,params:S}),C.push({id:F.id,params:v});const I=a.onCommandExecute({id:sn.id});return R.push(...I.redos),C.unshift(...I.undos),i.sequenceExecute(R,n)?(r.pushUndoRedo({unitID:u,undoMutations:C,redoMutations:R}),!0):!1}},on={id:"sheet.command.clear-selection-format",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Dt(m,s,u,c),R=[],C=[],S={subUnitId:c,unitId:u,cellValue:Xa(h)},v=ce(s,S);R.push({id:F.id,params:S}),C.push({id:F.id,params:v});const I=a.onCommandExecute({id:on.id});return R.push(...I.redos),C.unshift(...I.undos),i.sequenceExecute(R,n)?(r.pushUndoRedo({unitID:u,undoMutations:C,redoMutations:R}),!0):!1}};function At(s,e,t=!0){const n=e.getMatrixWithMergedCells(...i.selectionToArray(s)),o=[];if(n.forValue((a,l,u)=>{if(u.colSpan!==void 0&&u.rowSpan!==void 0){const d={startRow:a,startColumn:l,endRow:a+u.rowSpan-1,endColumn:l+u.colSpan-1};i.Rectangle.contains(s,d)||o.push(d)}}),o.length===0)return s;const r=i.Rectangle.union(s,...o);return t?At(r,e,t):r}function rl(s,e,t){let n=null;return t.getMatrixWithMergedCells(s,e,s,e).forValue((r,a,l)=>(n={actualRow:r,actualColumn:a,startRow:r,startColumn:a,isMerged:l.rowSpan!==void 0||l.colSpan!==void 0,isMergedMainCell:l.rowSpan!==void 0&&l.colSpan!==void 0,endRow:r+(l.rowSpan!==void 0?l.rowSpan-1:0),endColumn:a+(l.colSpan!==void 0?l.colSpan-1:0),rangeType:i.RANGE_TYPE.NORMAL},!1)),n||{actualColumn:e,actualRow:s,startRow:s,startColumn:e,endRow:s,endColumn:e,isMerged:!1,isMergedMainCell:!1,rangeType:i.RANGE_TYPE.NORMAL}}function il(s,e,t){const{startRow:n,startColumn:o,endRow:r,endColumn:a}=s;return Number.isNaN(n)&&(s.startRow=0),Number.isNaN(r)&&(s.endRow=e-1),Number.isNaN(o)&&(s.startColumn=0),Number.isNaN(a)&&(s.endColumn=t-1),s}function se(s,e){const t=Number.isNaN(s.startRow)?0:s.startRow,n=Number.isNaN(s.startColumn)?0:s.startColumn,o=e.getMergedCell(t,n);return o?{...o,actualRow:t,actualColumn:n,rangeType:i.RANGE_TYPE.NORMAL,isMerged:!0,isMergedMainCell:!0}:{startRow:t,startColumn:n,endRow:s.startRow,endColumn:s.startColumn,actualRow:t,actualColumn:n,rangeType:i.RANGE_TYPE.NORMAL,isMerged:!1,isMergedMainCell:!1}}const Ue=(s,e,t)=>({id:q.id,params:{unitId:e.getUnitId(),subUnitId:t.getSheetId(),reveal:!0,selections:[{range:s,primary:se(s,t)}]}});function al(s){if(!s)return!1;const{range:e,primary:t}=s;return i.Rectangle.equals(e,t)}function ll(s){function e(t,n){function o(r){for(let a=r.startRow;a<=r.endRow;a++)if(!s.getRowFiltered(a))for(let l=r.startColumn;l<=r.endColumn;l++)n(a,l,r)}o(t)}return{forOperableEach:e}}const Wo=s=>s.id!==no;function $e(s,e,t,n,o,r,a){const l={};for(let u=e;u<=t;u++)for(let d=n;d<=o;d++){const c=r?s.getCellWithFilteredInterceptors(a,d,so,Wo):s.getCellWithFilteredInterceptors(u,a,so,Wo);!c||!c.s||(l[u]||(l[u]={}),l[u][d]={s:c.s})}return l}var ul=Object.getOwnPropertyDescriptor,dl=(s,e,t,n)=>{for(var o=n>1?void 0:n?ul(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},cl=(s,e)=>(t,n)=>e(t,n,s);const Vo=i.createIdentifier("sheets-formula.ref-selections.service");g.RefSelectionsService=class extends g.SheetsSelectionsService{constructor(e){super(e)}_init(){const e=this._getAliveWorkbooks$().pipe(O.takeUntil(this.dispose$));this.selectionMoveStart$=e.pipe(O.switchMap(t=>O.merge(...t.map(n=>n.selectionMoveStart$)))),this.selectionMoving$=e.pipe(O.switchMap(t=>O.merge(...t.map(n=>n.selectionMoving$)))),this.selectionMoveEnd$=e.pipe(O.switchMap(t=>O.merge(...t.map(n=>n.selectionMoveEnd$)))),this.selectionSet$=e.pipe(O.switchMap(t=>O.merge(...t.map(n=>n.selectionSet$))))}dispose(){super.dispose(),this.selectionMoveStart$=O.of(null),this.selectionMoving$=O.of(null),this.selectionMoveEnd$=O.of(null),this.selectionSet$=O.of(null),delete this._instanceSrv,this._workbookSelections.clear()}_getAliveWorkbooks$(){const e=this._instanceSrv.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET);e.forEach(n=>this._ensureWorkbookSelection(n.getUnitId()));const t=new O.BehaviorSubject(e);return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._ensureWorkbookSelection(n.getUnitId()),t.next([...t.getValue(),n])})),this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{this._removeWorkbookSelection(n.getUnitId()),t.next(t.getValue().filter(o=>o!==n))})),t.pipe(O.map(n=>n.map(o=>this._ensureWorkbookSelection(o.getUnitId()))))}},g.RefSelectionsService=dl([cl(0,i.IUniverInstanceService)],g.RefSelectionsService);function $o(s,e){const n=s.get(i.IContextService).getContextValue(Ao);return s.get(n&&!e?Vo:g.SheetsSelectionsService)}const q={id:"sheet.operation.set-selections",type:i.CommandType.OPERATION,handler:(s,e)=>{if(!e)return!1;const{selections:t,type:n,unitId:o,subUnitId:r}=e;return $o(s).setSelections(o,r,[...t],n),!0}},Lo={id:"sheet.command.select-range",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnit:n,range:o}=e,r=s.get(i.ICommandService),a=P(s.get(i.IUniverInstanceService),e);if(!a)return!1;const l=[{range:o,primary:se(o,a.worksheet),style:null}];return r.syncExecuteCommand(q.id,{unitId:t,subUnitId:n,selections:l})}},Ho="sheet.command.move-range",Je={type:i.CommandType.COMMAND,id:Ho,handler:async(s,e)=>{var M,p;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(i.ErrorService),a=s.get(i.LocaleService),l=s.get(g.SheetInterceptorService),u=P(o);if(!u||!await l.beforeCommandExecute({id:Je.id,params:e}))return!1;const{worksheet:c,subUnitId:m,unitId:h}=u,R=rn(s,{unitId:h,subUnitId:m,range:e.fromRange},{subUnitId:m,range:e.toRange});if(R===null)return r.emit(a.t("sheets.info.acrossMergedCell")),!1;const C=l.onCommandExecute({id:Je.id,params:e}),S=[...(M=C.preRedos)!=null?M:[],...R.redos,...C.redos,{id:q.id,params:{unitId:h,subUnitId:m,selections:[{range:e.toRange,primary:ml(e.fromRange,e.toRange,c)}],type:te.MOVE_END}}],v=[...(p=C.preUndos)!=null?p:[],...R.undos,...C.undos,{id:q.id,params:{unitId:h,subUnitId:m,selections:[{range:e.fromRange,primary:se(e.fromRange,c)}],type:te.MOVE_END}}];if(i.sequenceExecute(S,t).result){const{undos:w,redos:y}=l.generateMutationsOfAutoHeight({unitId:h,subUnitId:m,ranges:[e.fromRange,e.toRange]}),b=l.afterCommandExecute({id:Je.id,params:e});return i.sequenceExecute([...b.redos,...y],t),n.pushUndoRedo({unitID:h,undoMutations:[...v,...b.undos,...w],redoMutations:[...S,...b.redos,...y]}),!0}return!1}};function rn(s,e,t,n=!1){const o=[],r=[],{range:a,subUnitId:l,unitId:u}=e,{range:d,subUnitId:c}=t,h=s.get(i.IUniverInstanceService).getUniverSheetInstance(u),R=h==null?void 0:h.getSheetBySheetId(c),C=h==null?void 0:h.getSheetBySheetId(l),S=R==null?void 0:R.getCellMatrix(),v=C==null?void 0:C.getCellMatrix();if(R&&C&&S&&v){const I=At(d,R,!1);if(!i.Rectangle.equals(d,I)&&!n)return null;const M=new i.ObjectMatrix,p=new i.ObjectMatrix,w=new i.ObjectMatrix;i.Range.foreach(a,(k,E)=>{const N=v.getValue(k,E);if(M.setValue(k,E,i.Tools.deepClone(N)),N){const W=h==null?void 0:h.getStyles().get(N.s);w.setValue(k,E,i.Tools.deepClone(W))}p.setValue(k,E,null)});const y=new i.ObjectMatrix,b=new i.ObjectMatrix;i.Range.foreach(d,(k,E)=>{y.setValue(k,E,i.Tools.deepClone(S.getValue(k,E)))}),i.Range.foreach(a,(k,E)=>{const N=i.cellToRange(k,E),W=i.Rectangle.getRelativeRange(N,a),V=i.Rectangle.getPositionRange(W,d),$=i.Tools.deepClone(w.getValue(k,E)),L=i.Tools.deepClone(M.getValue(k,E));L&&$&&(L.s=$),b.setValue(V.startRow,V.startColumn,L)});const T={fromRange:e.range,toRange:t.range,from:{value:p.getMatrix(),subUnitId:l},to:{value:b.getMatrix(),subUnitId:c},unitId:u},U={fromRange:t.range,toRange:e.range,from:{value:M.getMatrix(),subUnitId:l},to:{value:y.getMatrix(),subUnitId:c},unitId:u};o.push({id:Le.id,params:T}),r.push({id:Le.id,params:U})}return{redos:o,undos:r}}function ml(s,e,t){const n=s.startRow,o=s.startColumn,r=t.getMergedCell(n,o),a=se(e,t);if(r){const l=r.endRow-r.startRow+1,u=r.endColumn-r.startColumn+1;a.endRow=a.startRow+l-1,a.endColumn=a.startColumn+u-1,a.actualRow=a.startRow,a.actualColumn=a.startColumn,a.isMerged=!1,a.isMergedMainCell=!0}return a}var an=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(an||{}),_=(s=>(s[s.View=0]="View",s[s.Edit=1]="Edit",s[s.ManageCollaborator=2]="ManageCollaborator",s[s.Print=3]="Print",s[s.Duplicate=4]="Duplicate",s[s.Comment=5]="Comment",s[s.Copy=6]="Copy",s[s.Share=7]="Share",s[s.Export=8]="Export",s[s.MoveWorksheet=9]="MoveWorksheet",s[s.DeleteWorksheet=10]="DeleteWorksheet",s[s.HideWorksheet=11]="HideWorksheet",s[s.RenameWorksheet=12]="RenameWorksheet",s[s.CreateWorksheet=13]="CreateWorksheet",s[s.SetWorksheetStyle=14]="SetWorksheetStyle",s[s.EditWorksheetCell=15]="EditWorksheetCell",s[s.InsertHyperlink=16]="InsertHyperlink",s[s.Sort=17]="Sort",s[s.Filter=18]="Filter",s[s.PivotTable=19]="PivotTable",s[s.FloatImg=20]="FloatImg",s[s.History=21]="History",s[s.RwHgtClWdt=22]="RwHgtClWdt",s[s.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",s[s.ViewFilter=24]="ViewFilter",s[s.MoveSheet=25]="MoveSheet",s[s.DeleteSheet=26]="DeleteSheet",s[s.HideSheet=27]="HideSheet",s[s.CopySheet=28]="CopySheet",s[s.RenameSheet=29]="RenameSheet",s[s.CreateSheet=30]="CreateSheet",s[s.SelectProtectedCells=31]="SelectProtectedCells",s[s.SelectUnProtectedCells=32]="SelectUnProtectedCells",s[s.SetCellStyle=33]="SetCellStyle",s[s.SetCellValue=34]="SetCellValue",s[s.SetRowStyle=35]="SetRowStyle",s[s.SetColumnStyle=36]="SetColumnStyle",s[s.InsertRow=37]="InsertRow",s[s.InsertColumn=38]="InsertColumn",s[s.DeleteRow=39]="DeleteRow",s[s.DeleteColumn=40]="DeleteColumn",s[s.EditExtraObject=41]="EditExtraObject",s[s.Delete=42]="Delete",s[s.RecoverHistory=43]="RecoverHistory",s[s.ViewHistory=44]="ViewHistory",s[s.CreatePermissionObject=45]="CreatePermissionObject",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(_||{}),D=(s=>(s[s.Unkonwn=0]="Unkonwn",s[s.Workbook=1]="Workbook",s[s.Worksheet=2]="Worksheet",s[s.SelectRange=3]="SelectRange",s[s.Document=4]="Document",s[s.Slide=5]="Slide",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(D||{});class Se{constructor(e,t,n){f(this,"type",D.SelectRange);f(this,"subType",_.Edit);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${D.SelectRange}.${_.Edit}.${n}`}}class ln{constructor(e,t,n){f(this,"type",D.SelectRange);f(this,"subType",_.View);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${D.SelectRange}.${_.View}.${n}`}}class Yn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Comment);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Comment}_${e}`}}class Kn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Copy);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Copy}_${e}`}}class Bo{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"subType",_.CopySheet);f(this,"status",i.PermissionStatus.INIT);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CopySheet}_${e}`}}class Jn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.CreatePermissionObject);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CreatePermissionObject}_${e}`}}class xn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.CreateSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.CreateSheet}_${e}`}}class Fo{constructor(e){f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteColumn);this.unitId=e,this.id=`${this.type}.${_.DeleteColumn}_${e}`}}class jo{constructor(e){f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteRow);this.unitId=e,this.id=`${this.type}.${_.DeleteRow}_${e}`}}class Xn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.DeleteSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.DeleteSheet}_${e}`}}class Zn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Duplicate);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Duplicate}_${e}`}}class me{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Edit);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Edit}_${e}`}}class Qn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Export);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Export}_${e}`}}class un{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.HideSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.HideSheet}_${e}`}}class Go{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.History);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.History}_${e}`}}class zo{constructor(e){f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertColumn);this.unitId=e,this.id=`${this.type}.${_.InsertColumn}_${e}`}}class qo{constructor(e){f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertRow);this.unitId=e,this.id=`${this.type}.${_.InsertRow}_${e}`}}class dn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.ManageCollaborator);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.ManageCollaborator}_${e}`}}class cn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.MoveSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.MoveSheet}_${e}`}}class es{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Print);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Print}_${e}`}}class ts{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.RecoverHistory);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.RecoverHistory}_${e}`}}class mn{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.RenameSheet);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.RenameSheet}_${e}`}}class ns{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.Share);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.Share}_${e}`}}class ss{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.View);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.View}_${e}`}}class os{constructor(e){f(this,"id");f(this,"value",!0);f(this,"type",D.Workbook);f(this,"status",i.PermissionStatus.INIT);f(this,"subType",_.ViewHistory);this.unitId=e,this.unitId=e,this.id=`${this.type}.${_.ViewHistory}_${e}`}}class rs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Copy);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Copy}_${e}_${t}`}}class is{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteColumn);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.DeleteColumn}_${e}_${t}`}}class as{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Delete);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Delete}_${e}_${t}`}}class ls{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.DeleteRow);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.DeleteRow}_${e}_${t}`}}class fe{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Edit);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Edit}_${e}_${t}`}}class us{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.EditExtraObject);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.EditExtraObject}_${e}_${t}`}}class ds{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Filter);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Filter}_${e}_${t}`}}class cs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertColumn);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertColumn}_${e}_${t}`}}class ms{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertHyperlink);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertHyperlink}_${e}_${t}`}}class hs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.InsertRow);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.InsertRow}_${e}_${t}`}}class gs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.ManageCollaborator);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.ManageCollaborator}_${e}_${t}`}}class Rs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.PivotTable);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.PivotTable}_${e}_${t}`}}class hl{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SelectProtectedCells);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SelectProtectedCells}_${e}_${t}`}}class gl{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SelectUnProtectedCells);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`}}class Cs{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetCellStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetCellStyle}_${e}_${t}`}}class Wt{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetCellValue);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetCellValue}_${e}_${t}`}}class St{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetColumnStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetColumnStyle}_${e}_${t}`}}class ft{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.SetRowStyle);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.SetRowStyle}_${e}_${t}`}}class Ss{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.Sort);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.Sort}_${e}_${t}`}}class Vt{constructor(e,t){f(this,"value",!0);f(this,"type",D.Worksheet);f(this,"status",i.PermissionStatus.INIT);f(this,"id");f(this,"subType",_.View);this.unitId=e,this.subUnitId=t,this.id=`${this.type}.${_.View}_${e}_${t}`}}const vt={id:"sheet.command.set-range-values",type:i.CommandType.COMMAND,handler:(s,e)=>{var W;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.IPermissionService),u=P(o,e);if(!u)return!1;const{subUnitId:d,unitId:c,workbook:m,worksheet:h}=u,{value:R,range:C,redoUndoId:S}=e,v=C?[C]:(W=r.getCurrentSelections())==null?void 0:W.map(V=>V.range);if(!v||!v.length||!l.getPermissionPoint(new fe(c,d).id))return!1;const I=new i.ObjectMatrix;let M;if(i.Tools.isArray(R))for(let V=0;V<v.length;V++){const{startRow:$,startColumn:L,endRow:Y,endColumn:z}=v[V];for(let K=0;K<=Y-$;K++)for(let oe=0;oe<=z-L;oe++)I.setValue(K+$,oe+L,R[K][oe])}else if(i.isICellData(R))for(let V=0;V<v.length;V++){const{startRow:$,startColumn:L,endRow:Y,endColumn:z}=v[V];for(let K=$;K<=Y;K++)for(let oe=L;oe<=z;oe++)I.setValue(K,oe,R)}else M=R;const p={subUnitId:d,unitId:c,cellValue:M!=null?M:I.getMatrix()},w=ce(s,p),y=i.mapObjectMatrix(p.cellValue,(V,$)=>h.getCellHeight(V,$)||void 0);if(!t.syncExecuteCommand(F.id,p))return!1;const{undos:T,redos:U}=a.onCommandExecute({id:vt.id,params:p}),{undos:k,redos:E}=a.generateMutationsOfAutoHeight({unitId:c,subUnitId:d,ranges:v,cellHeights:new i.ObjectMatrix(y)});if(i.sequenceExecute([...U,...E],t).result){const V=Ue(C!=null?C:I.getRange(),m,h);return n.pushUndoRedo({unitID:c,undoMutations:[{id:F.id,params:w},...T,...k,V],redoMutations:[{id:F.id,params:p},...U,...E,i.Tools.deepClone(V)],id:S}),!0}return!1}};function fs(s,e){const t=[],n=[],{unitId:o,subUnitId:r,range:a,shiftDimension:l,cellValue:u={}}=e,d=s.get(i.IUniverInstanceService),c=s.get(g.SheetInterceptorService),m=d.getUniverSheetInstance(o),h=m==null?void 0:m.getSheetBySheetId(r);if(h){const R=h.getCellMatrix(),C=R.getDataRange();if(a.startColumn<=C.endColumn||a.startRow<=C.endRow){let p,w;if(l===i.Dimension.COLUMNS){const b=Math.min(a.endRow,C.endRow);let T=0;for(let k=a.startRow;k<=b;k++){const E=R.getRow(k),N=E?i.getArrayLength(E)-1:0;T=Math.max(T,N)}p={startRow:a.startRow,startColumn:a.startColumn,endRow:b,endColumn:T};const U=a.endColumn-a.startColumn+1;w={startRow:a.startRow,startColumn:p.startColumn+U,endRow:b,endColumn:p.endColumn+U}}else{const b=Math.min(a.endColumn,C.endColumn),T=C.endRow;p={startRow:a.startRow,startColumn:a.startColumn,endRow:T,endColumn:b};const U=a.endRow-a.startRow+1;w={startRow:p.startRow+U,startColumn:a.startColumn,endRow:p.endRow+U,endColumn:b}}const y=rn(s,{unitId:o,subUnitId:r,range:p},{subUnitId:r,range:w},!0);y&&(t.push(...y.redos),n.push(...y.undos))}if(Object.entries(u).length===0)for(let p=a.startRow;p<=a.endRow;p++){u[p]||(u[p]={});for(let w=a.startColumn;w<=a.endColumn;w++)u[p][w]=null}const S={subUnitId:r,unitId:o,cellValue:u},v=ce(s,S),{undos:I,redos:M}=c.onCommandExecute({id:vt.id,params:{...S,range:a}});t.push({id:F.id,params:S},...M),n.push({id:F.id,params:v},...I)}return{redo:t,undo:n}}function vs(s,e){const t=[],n=[],{unitId:o,subUnitId:r,range:a,shiftDimension:l}=e,u=s.get(i.IUniverInstanceService),d=s.get(g.SheetInterceptorService),c=u.getUniverSheetInstance(o),m=c==null?void 0:c.getSheetBySheetId(r);if(m){const h=m.getCellMatrix(),R=h.getDataRange(),C={subUnitId:r,unitId:o,cellValue:qn([a])},S=ce(s,C),v=d.onCommandExecute({id:vt.id,params:C});if(t.push({id:F.id,params:C},...v.redos),n.push(...v.undos,{id:F.id,params:S}),a.startColumn<=R.endColumn||a.startRow<=R.endRow){let I=null,M=null;if(l===i.Dimension.COLUMNS&&a.endColumn<R.endColumn){const p=Math.min(a.endRow,R.endRow);let w=0;for(let b=a.startRow;b<=p;b++){const T=h.getRow(b),U=T?i.getArrayLength(T)-1:0;w=Math.max(w,U)}I={startRow:a.startRow,startColumn:a.endColumn+1,endRow:p,endColumn:w};const y=a.endColumn-a.startColumn+1;M={startRow:a.startRow,startColumn:I.startColumn-y,endRow:p,endColumn:I.endColumn-y}}if(l===i.Dimension.ROWS&&a.endRow<R.endRow){const p=Math.min(a.endColumn,R.endColumn),w=R.endRow;I={startRow:a.endRow+1,startColumn:a.startColumn,endRow:w,endColumn:p};const y=a.endRow-a.startRow+1;M={startRow:I.startRow-y,startColumn:a.startColumn,endRow:I.endRow-y,endColumn:p}}if(I&&M){const p=rn(s,{unitId:o,subUnitId:r,range:I},{subUnitId:r,range:M},!0);p&&(t.push(...p.redos),n.push(...p.undos))}}}return{redo:t,undo:n}}function Rl(s,e,t,n,o,r){const{startRow:a,endRow:l,startColumn:u,endColumn:d}=e;if(o===i.Dimension.ROWS){const c=l-a+1;for(let m=t;m>=a;m--)for(let h=u;h<=d;h++){const R=s.getValue(m,h);R==null?s.realDeleteValue(m+c,h):s.setValue(m+c,h,R)}for(let m=l;m>=a;m--)for(let h=u;h<=d;h++)r&&r[m]&&r[m][h]?s.setValue(m,h,r[m][h]):s.realDeleteValue(m,h)}else if(o===i.Dimension.COLUMNS){const c=d-u+1;for(let m=a;m<=l;m++)for(let h=n;h>=u;h--){const R=s.getValue(m,h);R==null?s.realDeleteValue(m,h+c):s.setValue(m,h+c,R)}for(let m=a;m<=l;m++)for(let h=d;h>=u;h--)r&&r[m]&&r[m][h]?s.setValue(m,h,r[m][h]):s.realDeleteValue(m,h)}}function Cl(s,e,t,n,o){const{startRow:r,endRow:a,startColumn:l,endColumn:u}=e,d=a-r+1,c=u-l+1;if(o===i.Dimension.ROWS)for(let m=r;m<=t;m++)for(let h=l;h<=u;h++){const R=s.getValue(m+d,h);R==null?s.realDeleteValue(m,h):s.setValue(m,h,R)}else if(o===i.Dimension.COLUMNS)for(let m=r;m<=a;m++)for(let h=l;h<=n;h++){const R=s.getValue(m,h+c);R==null?s.realDeleteValue(m,h):s.setValue(m,h,R)}}const Yo="sheet.command.delete-range-move-left",He={type:i.CommandType.COMMAND,id:Yo,handler:async(s,e)=>{var w,y,b;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=P(o);if(!l)return!1;const{worksheet:u,workbook:d,subUnitId:c,unitId:m}=l;let h=e==null?void 0:e.range;if(h||(h=(w=r.getCurrentLastSelection())==null?void 0:w.range),!h)return!1;const R={range:h,subUnitId:c,unitId:m,shiftDimension:i.Dimension.COLUMNS},C=a.onCommandExecute({id:He.id,params:{range:h}}),{redo:S,undo:v}=vs(s,R),I=[...(y=C.preRedos)!=null?y:[],...S],M=[...C.undos,...v];if(I.push(...C.redos),I.push(Ue(h,d,u)),M.push(...(b=C.preUndos)!=null?b:[]),i.sequenceExecute(I,t).result){const T=a.afterCommandExecute({id:He.id,params:{range:h}});return i.sequenceExecute(T.redos,t),M.push(...T.undos),I.push(...T.redos),n.pushUndoRedo({unitID:m,undoMutations:M.reverse(),redoMutations:I}),!0}return!1}},Ko="sheet.command.delete-range-move-up",Be={type:i.CommandType.COMMAND,id:Ko,handler:async(s,e)=>{var w,y,b;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=P(o);if(!l)return!1;const{unitId:u,subUnitId:d,workbook:c,worksheet:m}=l;let h=e==null?void 0:e.range;if(h||(h=(w=r.getCurrentLastSelection())==null?void 0:w.range),!h)return!1;const R={range:h,subUnitId:d,unitId:u,shiftDimension:i.Dimension.ROWS},C=a.onCommandExecute({id:Be.id,params:{range:h}}),{redo:S,undo:v}=vs(s,R),I=[...(y=C.preRedos)!=null?y:[],...S],M=[...C.undos,...v];if(I.push(...C.redos),I.push(Ue(h,c,m)),M.push(...(b=C.preUndos)!=null?b:[]),i.sequenceExecute(I,t).result){const T=a.afterCommandExecute({id:Be.id,params:{range:h}});return i.sequenceExecute(T.redos,t),M.push(...T.undos),I.push(...T.redos),n.pushUndoRedo({unitID:u,undoMutations:M.reverse(),redoMutations:I}),!0}return!1}},Sl="sheet.command.insert-range-move-down",xe={type:i.CommandType.COMMAND,id:"sheet.command.insert-range-move-down",handler:async(s,e)=>{var W,V,$;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.ErrorService),u=s.get(i.LocaleService);if(r.isOverlapping())return l.emit(u.t("sheets.info.overlappingSelections")),!1;const d=P(o);if(!d)return!1;const{unitId:c,subUnitId:m,worksheet:h,workbook:R}=d;let C=e==null?void 0:e.range;if(C||(C=(W=r.getCurrentLastSelection())==null?void 0:W.range),!C)return!1;const S=[],v=[],I=h.getCellMatrix(),M=I.getDataRange(),w=I.getSlice(M.startRow,M.endRow,C.startColumn,C.endColumn).getDataRange().endRow,y=Math.max(w+(C.endRow-C.startRow+1)-M.endRow,0);if(y>0){const L=C.startRow-1,Y=h.getRowHeight(L),z={unitId:c,subUnitId:m,range:{startRow:M.endRow+1,endRow:M.endRow+y,startColumn:M.startColumn,endColumn:M.endColumn},rowInfo:new Array(y).fill(void 0).map(()=>({h:Y,hd:i.BooleanNumber.FALSE}))};S.push({id:re.id,params:z});const K=en(s,z);v.push({id:ae.id,params:K})}const b={};i.Range.foreach(C,(L,Y)=>{const z=h.getCell(L,Y);z&&(b[L]||(b[L]={}),b[L][Y]={s:z.s})});const T={range:C,subUnitId:m,unitId:c,shiftDimension:i.Dimension.ROWS,cellValue:b},{redo:U,undo:k}=fs(s,T);S.push(...U),v.push(...k);const E=a.onCommandExecute({id:xe.id,params:{range:C}});if(S.push(...E.redos),S.push(Ue(C,R,h)),v.push(...(V=E.preUndos)!=null?V:[]),S.unshift(...($=E.preRedos)!=null?$:[]),v.unshift(...E.undos),i.sequenceExecute(S,t)){const L=a.afterCommandExecute({id:xe.id,params:{range:C}});return i.sequenceExecute(L.redos,t),v.push(...L.undos),S.push(...L.redos),n.pushUndoRedo({unitID:c,undoMutations:v.reverse(),redoMutations:S}),!0}return!1}},Is="sheet.command.insert-range-move-right",It={type:i.CommandType.COMMAND,id:Is,handler:async(s,e)=>{var W,V,$;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(g.SheetInterceptorService),l=s.get(i.ErrorService),u=s.get(i.LocaleService);if(r.isOverlapping())return l.emit(u.t("sheets.info.overlappingSelections")),!1;const d=P(o);if(!d)return!1;const{workbook:c,worksheet:m,unitId:h,subUnitId:R}=d;let C=e==null?void 0:e.range;if(C||(C=(W=r.getCurrentLastSelection())==null?void 0:W.range),!C)return!1;const S=[],v=[],I=m.getCellMatrix(),M=I.getDataRange(),w=I.getSlice(C.startRow,C.endRow,M.startColumn,M.endColumn).getDataRange().endColumn,y=Math.max(w+(C.endColumn-C.startColumn+1)-M.endColumn,0);if(y>0){const L=C.startColumn-1,Y=m.getColumnWidth(L),z={unitId:h,subUnitId:R,range:{startRow:M.startRow+1,endRow:M.endRow,startColumn:M.endColumn+1,endColumn:M.endColumn+y},colInfo:new Array(y).fill(void 0).map(()=>({w:Y,hd:i.BooleanNumber.FALSE}))};S.push({id:ie.id,params:z});const K=Nt(s,z);v.push({id:ne.id,params:K})}const b={};i.Range.foreach(C,(L,Y)=>{const z=m.getCell(L,Y);!z||!z.s||(b[L]||(b[L]={}),b[L][Y]={s:z.s})});const T={range:C,subUnitId:R,unitId:h,shiftDimension:i.Dimension.COLUMNS,cellValue:b},{redo:U,undo:k}=fs(s,T);S.push(...U),v.push(...k);const E=a.onCommandExecute({id:It.id,params:{range:C}});if(S.push(...E.redos),S.push(Ue(C,c,m)),v.push(...(V=E.preUndos)!=null?V:[]),S.unshift(...($=E.preRedos)!=null?$:[]),v.unshift(...E.undos),i.sequenceExecute(S,t).result){const L=a.afterCommandExecute({id:It.id,params:{range:C}});return i.sequenceExecute(L.redos,t),v.push(...L.undos),S.push(...L.redos),n.pushUndoRedo({unitID:h,undoMutations:v.reverse(),redoMutations:S}),!0}return!1}},Jo="sheet.command.insert-row",Me={type:i.CommandType.COMMAND,id:Jo,handler:async(s,e)=>{const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService),{range:o,direction:r,unitId:a,subUnitId:l,cellValue:u}=e;return await n.beforeCommandExecute({id:Me.id,params:e})?t.syncExecuteCommand(ps.id,{range:o,direction:r,unitId:a,subUnitId:l,cellValue:u}):!1}},ps={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-by-range",handler:(s,e)=>{var U,k,E,N;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=P(o,e);if(!a)return!1;const{workbook:l,worksheet:u}=a,{range:d,direction:c,unitId:m,subUnitId:h,cellValue:R}=e,{startRow:C,endRow:S}=d;d.rangeType=i.RANGE_TYPE.ROW;const v=c===i.Direction.UP?C:C-1,I=u.getRowHeight(v),M={unitId:m,subUnitId:h,range:d,rowInfo:new Array(S-C+1).fill(void 0).map(()=>({h:I,hd:i.BooleanNumber.FALSE}))},p=en(s,M),w=[{id:re.id,params:M}],y=[{id:ae.id,params:p}];R&&Object.keys(R).length>0&&w.push({id:F.id,params:{unitId:m,subUnitId:h,cellValue:R}});const b=r.onCommandExecute({id:Me.id,params:e});if(w.unshift(...(U=b.preRedos)!=null?U:[]),w.push(...(k=b.redos)!=null?k:[]),w.push(Ue(d,l,u)),y.unshift(...(E=b.preUndos)!=null?E:[]),y.push(...(N=b.undos)!=null?N:[]),i.sequenceExecute(w,t).result){const W=r.afterCommandExecute({id:Me.id,params:e});return i.sequenceExecute(W.redos,t),w.push(...W.redos),y.push(...W.undos),n.pushUndoRedo({unitID:e.unitId,undoMutations:y,redoMutations:w}),!0}return!1}},xo={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-before",handler:async(s,e)=>{var v;const n=(v=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:v.map(I=>I.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,subUnitId:u,unitId:d}=a,c=e.value||0,m=o.startRow,h=o.startRow+c-1,R=0,C=l.getColumnCount()-1,S={unitId:d,subUnitId:u,direction:i.Direction.UP,range:{startRow:m,endRow:h,startColumn:R,endColumn:C},cellValue:$e(l,m,h,R,C,!0,m-1)};return s.get(i.ICommandService).executeCommand(Me.id,S)}},Xo={type:i.CommandType.COMMAND,id:"sheet.command.insert-row-after",handler:async s=>{var S;const t=(S=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:S.map(v=>v.range);let n;if((t==null?void 0:t.length)===1)n=t[0];else return!1;const o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=n.endRow-n.startRow+1,c=n.endRow+1,m=n.endRow+d,h=0,R=a.getColumnCount()-1,C={unitId:l,subUnitId:u,direction:i.Direction.DOWN,range:{startRow:c,endRow:m,startColumn:h,endColumn:R,rangeType:i.RANGE_TYPE.ROW},cellValue:$e(a,c,m,h,R,!0,n.endRow)};return s.get(i.ICommandService).executeCommand(Me.id,C)}},Zo={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-rows-above",handler:async(s,e)=>{var I;const n=(I=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:I.map(M=>M.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startRow,h=o.startRow+c-1,R=0,C=l.getColumnCount()-1,S=$e(l,m,h,R,C,!0,m-1),v={unitId:u,subUnitId:d,direction:i.Direction.UP,range:{startRow:m,endRow:h,startColumn:R,endColumn:C,rangeType:i.RANGE_TYPE.ROW},cellValue:S};return s.get(i.ICommandService).executeCommand(Me.id,v)}},Qo={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-rows-after",handler:async(s,e)=>{var v;const n=(v=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:v.map(I=>I.range);let o;if((n==null?void 0:n.length)===1)o=n[0];else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.endRow+1,h=o.endRow+c,R=0,C=l.getColumnCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.DOWN,range:{startRow:m,endRow:h,startColumn:R,endColumn:C,rangeType:i.RANGE_TYPE.ROW},cellValue:$e(l,m,h,R,C,!0,o.endRow)};return s.get(i.ICommandService).executeCommand(Me.id,S)}},er="sheet.command.insert-col",ye={type:i.CommandType.COMMAND,id:er,handler:async(s,e)=>{const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService),{range:o,direction:r,subUnitId:a,unitId:l,cellValue:u}=e;return await n.beforeCommandExecute({id:ye.id,params:e})?t.syncExecuteCommand(ws.id,{range:o,direction:r,unitId:l,subUnitId:a,cellValue:u}):!1}},ws={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-by-range",handler:(s,e)=>{var T,U,k,E;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),{range:a,direction:l,subUnitId:u,unitId:d,cellValue:c}=e,{startColumn:m,endColumn:h}=e.range;a.rangeType=i.RANGE_TYPE.COLUMN;const R=o.getUniverSheetInstance(e.unitId),C=R.getSheetBySheetId(e.subUnitId),S=l===i.Direction.LEFT?m:m-1,v=C.getColumnWidth(S),I={unitId:d,subUnitId:u,range:a,colInfo:new Array(h-m+1).fill(void 0).map(()=>({w:v,hd:i.BooleanNumber.FALSE}))},M=Nt(s,I),p=[{id:ie.id,params:I}],w=[{id:ne.id,params:M}];c&&p.push({id:F.id,params:{unitId:d,subUnitId:u,cellValue:c}});const y=r.onCommandExecute({id:ye.id,params:e});if(p.unshift(...(T=y.preRedos)!=null?T:[]),p.push(...(U=y.redos)!=null?U:[]),p.push(Ue(a,R,C)),w.unshift(...(k=y.preUndos)!=null?k:[]),w.push(...(E=y.undos)!=null?E:[]),i.sequenceExecute(p,t).result){const N=r.afterCommandExecute({id:ye.id,params:e});return i.sequenceExecute(N.redos,t),p.push(...N.redos),w.push(...N.undos),n.pushUndoRedo({unitID:e.unitId,undoMutations:w.filter(Boolean),redoMutations:p.filter(Boolean)}),!0}return!1}},tr={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-before",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startColumn,h=o.startColumn+c-1,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.LEFT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C,rangeType:i.RANGE_TYPE.COLUMN},cellValue:$e(l,R,C,m,h,!1,m-1)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},nr={type:i.CommandType.COMMAND,id:"sheet.command.insert-col-after",handler:async s=>{const t=s.get(g.SheetsSelectionsService).getCurrentSelections();let n;if((t==null?void 0:t.length)===1)n=t[0].range;else return!1;const o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=n.endColumn-n.startColumn+1,c=n.endColumn+1,m=n.endColumn+d,h=0,R=a.getRowCount()-1,C={unitId:l,subUnitId:u,direction:i.Direction.RIGHT,range:{startColumn:c,endColumn:m,startRow:h,endRow:R},cellValue:$e(a,h,R,c,m,!1,n.endColumn)};return s.get(i.ICommandService).executeCommand(ye.id,C)}},sr={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-cols-before",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.startColumn,h=o.startColumn+c-1,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.LEFT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C,rangeType:i.RANGE_TYPE.COLUMN},cellValue:$e(l,R,C,m,h,!1,m-1)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},or={type:i.CommandType.COMMAND,id:"sheet.command.insert-multi-cols-right",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();let o;if((n==null?void 0:n.length)===1)o=n[0].range;else return!1;const r=s.get(i.IUniverInstanceService),a=P(r);if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,c=e.value||0,m=o.endColumn+1,h=o.endColumn+c,R=0,C=l.getRowCount()-1,S={unitId:u,subUnitId:d,direction:i.Direction.RIGHT,range:{startColumn:m,endColumn:h,startRow:R,endRow:C},cellValue:$e(l,R,C,m,h,!1,o.endColumn)};return s.get(i.ICommandService).executeCommand(ye.id,S)}},hn="sheet.command.remove-row",Ms={type:i.CommandType.COMMAND,id:"sheet.command.remove-row-by-range",handler:(s,e)=>{var v,I,M;if(!e)return!1;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{workbook:o,worksheet:r}=n,a=s.get(g.SheetInterceptorService),{range:l,unitId:u,subUnitId:d}=e,c=Dt([l],s,u,d).reverse(),m=[],h=[];c.forEach(p=>{const w=[],y=[],b={unitId:u,subUnitId:d,range:p},T=ua(b,r),U=r.getCellMatrix().getSlice(p.startRow,p.endRow,0,r.getColumnCount()-1),k={unitId:u,subUnitId:d,cellValue:U.getMatrix()};y.push({id:ae.id,params:b}),w.push({id:re.id,params:T}),w.push({id:F.id,params:k}),h.push(...y),m.unshift(...w)});const R=a.onCommandExecute({id:hn,params:{range:l}}),C=s.get(i.ICommandService);if(i.sequenceExecute([...(v=R.preRedos)!=null?v:[],...h,...R.redos,Ue(l,o,r)],C).result){const p=a.afterCommandExecute({id:hn,params:{range:l}});return i.sequenceExecute(p.redos,C),s.get(i.IUndoRedoService).pushUndoRedo({unitID:u,undoMutations:[...(I=R.preUndos)!=null?I:[],...m,...R.undos,...p.undos],redoMutations:[...(M=R.preRedos)!=null?M:[],...h,...R.redos,...p.redos]}),!0}return!1}},$t={type:i.CommandType.COMMAND,id:hn,handler:async(s,e)=>{var h;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.ICommandService);let r=e==null?void 0:e.range;if(r||(r=(h=t.getCurrentLastSelection())==null?void 0:h.range),!r)return!1;const a=s.get(i.IUniverInstanceService),l=P(a);if(!l)return!1;const{worksheet:u,subUnitId:d,unitId:c}=l;return r={...r,startColumn:0,endColumn:Math.max(u.getMaxColumns()-1,0)},await n.beforeCommandExecute({id:$t.id,params:{range:r}})?o.syncExecuteCommand(Ms.id,{range:r,unitId:c,subUnitId:d}):!1}},gn="sheet.command.remove-col",ys={type:i.CommandType.COMMAND,id:"sheet.command.remove-col-by-range",handler:(s,e)=>{var I,M,p;if(!e)return!1;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{workbook:o,worksheet:r}=n,a=s.get(g.SheetInterceptorService),{range:l,unitId:u,subUnitId:d}=e,c={unitId:u,subUnitId:d,range:l},m=da(s,c),h=r.getCellMatrix().getSlice(0,r.getRowCount()-1,l.startColumn,l.endColumn),R={unitId:u,subUnitId:d,cellValue:h.getMatrix()},C=a.onCommandExecute({id:gn,params:{range:l}}),S=s.get(i.ICommandService);if(i.sequenceExecute([...(I=C.preRedos)!=null?I:[],{id:ne.id,params:c},...C.redos,Ue(l,o,r)],S).result){const w=a.afterCommandExecute({id:gn,params:{range:l}});return i.sequenceExecute(w.redos,S),s.get(i.IUndoRedoService).pushUndoRedo({unitID:u,undoMutations:[...(M=C.preUndos)!=null?M:[],{id:ie.id,params:m},{id:F.id,params:R},...C.undos,...w.undos],redoMutations:[...(p=C.preRedos)!=null?p:[],{id:ne.id,params:c},...C.redos,...w.redos]}),!0}return!1}},Lt={type:i.CommandType.COMMAND,id:gn,handler:async(s,e)=>{var h;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.ICommandService);let r=e==null?void 0:e.range;if(r||(r=(h=t.getCurrentLastSelection())==null?void 0:h.range),!r)return!1;const a=s.get(i.IUniverInstanceService),l=P(a);if(!l)return!1;const{worksheet:u,subUnitId:d,unitId:c}=l;return r={...r,startRow:0,endRow:Math.max(u.getMaxRows()-1,0)},await n.beforeCommandExecute({id:Lt.id,params:{range:r}})?o.syncExecuteCommand(ys.id,{range:r,unitId:c,subUnitId:d}):!1}},rr=(s,e)=>{const t=s.get(i.IUniverInstanceService),{subUnitId:n,unitId:o}=e,r=Ie(t,e);if(!r)throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!");const{workbook:a,worksheet:l}=r,u=l.getConfig();return{index:a.getConfig().sheetOrder.findIndex(m=>m===n),sheet:u,unitId:o}},Xe={id:"sheet.mutation.remove-sheet",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),{subUnitId:n,unitId:o}=e,r=t.getUniverSheetInstance(o);return r?r.removeSheet(n):!1}};function fl(s,e){return e.getMergeData().some(t=>t.startRow<s&&s<=t.endRow)}function vl(s,e){return e.getMergeData().some(t=>t.startColumn<s&&s<=t.endColumn)}const ir="sheet.command.move-rows",pt={id:ir,type:i.CommandType.COMMAND,handler:(s,e)=>{var W,V;const t=s.get(g.SheetsSelectionsService),{fromRange:{startRow:n},toRange:{startRow:o},range:r}=e,a=r?[lr(r)]:t.getCurrentSelections(),l=a==null?void 0:a.filter($=>$.range.rangeType===i.RANGE_TYPE.ROW&&$.range.startRow<=n&&n<=$.range.endRow);if((l==null?void 0:l.length)!==1)return!1;const u=s.get(g.SheetInterceptorService),d=s.get(i.IUniverInstanceService),c=P(d,e);if(!c)return!1;const{workbook:m,worksheet:h}=c,R=m.getUnitId(),C=h.getSheetId(),S=s.get(i.ErrorService),v=s.get(i.LocaleService),I=l[0].range,M=l[0].primary,p=At(I,h,!1);if(!i.Rectangle.equals(I,p))return S.emit(v.t("sheets.info.partOfCell")),!1;if(fl(o,h))return S.emit(v.t("sheets.info.acrossMergedCell")),!1;const w={...I,startRow:o,endRow:o+I.endRow-I.startRow},y={unitId:R,subUnitId:C,sourceRange:I,targetRange:w},b=lo(s,y),T=s.get(i.ICommandService),U=u.onCommandExecute({id:pt.id,params:e}),k=[...(W=U.preRedos)!=null?W:[],{id:pe.id,params:y}],E=[...(V=U.preUndos)!=null?V:[],{id:pe.id,params:b}];if(M){const L=o-n<0,Y=I.endRow-I.startRow+1,z=L?w:{...w,startRow:w.startRow-Y,endRow:w.endRow-Y},K={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:z,primary:se(z,h),style:null}]},oe={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:I,primary:M,style:null}]};k.push({id:q.id,params:K}),E.push({id:q.id,params:oe})}if(k.push(...U.redos),E.push(...U.undos),i.sequenceExecute(k,T).result){const $=u.afterCommandExecute({id:pt.id,params:e});return i.sequenceExecute($.redos,T),k.push(...$.redos),E.push(...$.undos),s.get(i.IUndoRedoService).pushUndoRedo({unitID:R,undoMutations:E,redoMutations:k}),!0}return!1}},ar="sheet.command.move-cols",wt={id:ar,type:i.CommandType.COMMAND,handler:(s,e)=>{var W,V;const t=s.get(g.SheetsSelectionsService),{fromRange:{startColumn:n},toRange:{startColumn:o},range:r}=e,a=r?[lr(r)]:t.getCurrentSelections(),l=a==null?void 0:a.filter($=>$.range.rangeType===i.RANGE_TYPE.COLUMN&&$.range.startColumn<=n&&n<=$.range.endColumn);if((l==null?void 0:l.length)!==1)return!1;const u=s.get(g.SheetInterceptorService),d=s.get(i.IUniverInstanceService),c=P(d,e);if(!c)return!1;const{workbook:m,worksheet:h}=c,R=m.getUnitId(),C=h.getSheetId(),S=s.get(i.ErrorService),v=s.get(i.LocaleService),I=l[0].range,M=l[0].primary,p=At(I,h,!1);if(!i.Rectangle.equals(I,p))return S.emit(v.t("sheets.info.partOfCell")),!1;if(vl(o,h))return S.emit(v.t("sheets.info.acrossMergedCell")),!1;const w={...I,startColumn:o,endColumn:o+I.endColumn-I.startColumn},y={unitId:R,subUnitId:C,sourceRange:I,targetRange:w},b=uo(s,y),T=s.get(i.ICommandService),U=u.onCommandExecute({id:wt.id,params:e}),k=[...(W=U.preRedos)!=null?W:[],{id:we.id,params:y}],E=[...(V=U.preUndos)!=null?V:[],{id:we.id,params:b}];if(M){const $=I.endColumn-I.startColumn+1,z=o-n<0?w:{...w,startColumn:w.startColumn-$,endColumn:w.endColumn-$},K={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:z,primary:se(z,h),style:null}]},oe={unitId:R,subUnitId:C,type:te.MOVE_END,selections:[{range:I,primary:M,style:null}]};k.push({id:q.id,params:K}),E.push({id:q.id,params:oe})}if(k.push(...U.redos),E.push(...U.undos),i.sequenceExecute(k,T).result){const $=u.afterCommandExecute({id:wt.id,params:e});return i.sequenceExecute($.redos,T),k.push(...$.redos),E.push(...$.undos),s.get(i.IUndoRedoService).pushUndoRedo({unitID:R,undoMutations:E,redoMutations:k}),!0}return!1}};function lr(s){return{range:s,primary:null,style:null}}var Il=Object.getOwnPropertyDescriptor,pl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Il(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},wl=(s,e)=>(t,n)=>e(t,n,s);g.SheetSkeletonService=class extends i.Disposable{constructor(t){super();f(this,"_sheetSkeletonStore",new Map);this._injector=t,this.disposeWithMe(()=>{this._sheetSkeletonStore=new Map})}getSkeleton(t,n){if(this._sheetSkeletonStore.has(t))return this._sheetSkeletonStore.get(t).get(n)}setSkeleton(t,n,o){this._sheetSkeletonStore.has(t)||this._sheetSkeletonStore.set(t,new Map),this._sheetSkeletonStore.get(t).set(n,o)}deleteSkeleton(t,n){this._sheetSkeletonStore.has(t)&&this._sheetSkeletonStore.get(t).delete(n)}},g.SheetSkeletonService=pl([wl(0,i.Inject(i.Injector))],g.SheetSkeletonService);function _s(s,e){const t=new i.ObjectMatrix;return s.map(n=>i.Range.transformRange(n,e)).forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=e.getCellHeight(o,r);a&&t.setValue(o,r,a)})}),t}const Ml=1e4;function Ht(s,e){if(!e)return{suitableRanges:s,remainingRanges:[]};const t=e.worksheet.getColumnCount(),n=Math.ceil(Ml/t),o=[],r=[],a=e.getOffsetRelativeToRowCol(0,e.scrollY).row,l=s.map(d=>{let c;return a>=d.startRow&&a<=d.endRow?c=0:a<d.startRow?c=d.startRow-a:c=a-d.endRow,{range:d,distance:c,rowCount:d.endRow-d.startRow+1}});l.sort((d,c)=>d.distance!==c.distance?d.distance-c.distance:d.rowCount-c.rowCount);let u=0;for(const d of l)if(u+d.rowCount<=n)o.push(d.range),u+=d.rowCount;else{const c=n-u;if(c>0){const m={...d.range,endRow:d.range.startRow+c-1},h={...d.range,startRow:d.range.startRow+c};o.push(m),r.push(h),u=n}else r.push(d.range)}return{suitableRanges:o,remainingRanges:r}}const ur="sheet.command.reorder-range",Rn={id:ur,type:i.CommandType.COMMAND,handler:(s,e)=>{var p,w;const{subUnitId:t,unitId:n,range:o,order:r}=e,a=s.get(i.ICommandService),l={id:Ot.id,params:{unitId:n,subUnitId:t,order:r,range:o}},u={id:Ot.id,params:co(l.params)},d=s.get(g.SheetInterceptorService),c=d.onCommandExecute({id:Rn.id,params:e}),m=[...(p=c.preRedos)!=null?p:[],l,...c.redos],h=[...(w=c.preUndos)!=null?w:[],u,...c.undos],R=i.sequenceExecute(m,a),{suitableRanges:C,remainingRanges:S}=Ht([o],s.get(g.SheetSkeletonService).getSkeleton(n,t)),{undos:v,redos:I}=d.generateMutationsOfAutoHeight({unitId:n,subUnitId:t,ranges:[o],autoHeightRanges:C,lazyAutoHeightRanges:S}),M=d.afterCommandExecute({id:Rn.id,params:e});return R.result?(i.sequenceExecute([...M.redos,...I],a),s.get(i.IUndoRedoService).pushUndoRedo({unitID:n,undoMutations:[...h,...M.undos,...v],redoMutations:[...m,...M.redos,...I]}),!0):!1}},A={MoveRangeCommandId:Ho,InsertRowCommandId:Jo,InsertColCommandId:er,RemoveColCommandId:gn,RemoveRowCommandId:hn,DeleteRangeMoveLeftCommandId:Yo,DeleteRangeMoveUpCommandId:Ko,InsertRangeMoveDownCommandId:Sl,InsertRangeMoveRightCommandId:Is,MoveColsCommandId:ar,MoveRowsCommandId:ir,ReorderRangeCommandId:ur};var H=(s=>(s[s.Set=0]="Set",s[s.Delete=1]="Delete",s[s.HorizontalMove=2]="HorizontalMove",s[s.VerticalMove=3]="VerticalMove",s[s.Unknown=4]="Unknown",s))(H||{});const Cn=Number.MAX_SAFE_INTEGER,Pe=s=>{const e={...s},t=Number.isNaN(e.startRow)&&Number.isNaN(e.endRow)&&!Number.isNaN(e.startColumn)&&!Number.isNaN(e.endColumn),n=Number.isNaN(e.startColumn)&&Number.isNaN(e.endColumn)&&!Number.isNaN(e.startRow)&&!Number.isNaN(e.endRow);return(e.rangeType===i.RANGE_TYPE.COLUMN||t)&&(e.startRow=0,e.endRow=Cn),(e.rangeType===i.RANGE_TYPE.ROW||n)&&(e.startColumn=0,e.endColumn=Cn),e.rangeType===i.RANGE_TYPE.ALL&&(e.startColumn=0,e.endColumn=Cn,e.startRow=0,e.endRow=Cn),e},he=s=>{let e=s.rangeType;return s.rangeType===i.RANGE_TYPE.COLUMN?e=i.RANGE_TYPE.ROW:s.rangeType===i.RANGE_TYPE.ROW&&(e=i.RANGE_TYPE.COLUMN),{startRow:s.startColumn,endRow:s.endColumn,startColumn:s.startRow,endColumn:s.endRow,rangeType:e}},Bt=(s,e,t)=>{const n={...t},o={...e},r=(S,v)=>{const I=Math.max(S.start,v.start),M=Math.min(S.end,v.end);return M<I?null:{start:I,end:M}},a=S=>S.end-S.start+1,l=(S,v)=>({start:S.start-v.start,end:S.start-v.start+S.end-S.start}),u=(S,v)=>({start:v.start+S.start,end:v.start+S.start+S.end-S.start}),d=e.start>s.start;if(d){const S=Math.min(s.end,e.start)-s.start+1;o.start-=S,o.end-=S}const c=a(s),m=c,h=r(s,n),R=h&&a(h)>=a(n);if(s.end<n.start)n.start-=c,n.end-=c;else if(h){const S=a(h);if(R){const v=l(n,s),I=u(v,o);n.start=I.start,n.end=I.end}else h.start>s.start?d?(n.end-=S+c,n.start-=c):n.end-=S:d?n.end-=S:n.start>s.start&&n.end>s.end?(n.start-=c,n.end-=c+S):n.end-=S}const C=r(o,n);return R||(o.start<=n.start?(n.start+=m,n.end+=m):C&&(d?o.end<=n.start||o.start<=n.start&&o.end>=n.start?(n.start+=m,n.end+=m):o.start>=n.start&&o.start<=n.end&&(n.end+=m):n.start<o.start&&n.end>o.start?n.end+=m:(n.start>=o.end||n.start>=o.start&&n.start<=o.end)&&(n.end+=m,n.start+=m))),{step:n.start-t.start,length:a(n)-a(t)}},bs=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!n||!t)return[];const o=Pe(t),r=Pe(n),a=Pe(e),l=Bt({start:o.startRow,end:o.endRow},{start:r.startRow,end:r.endRow},{start:a.startRow,end:a.endRow});return l===null?[{type:H.Delete}]:[{type:H.VerticalMove,step:l.step||0,length:l.length||0}]},yl=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!t||!n)return[e];const o=t.startRow,r=t.endRow-t.startRow+1,a=n.startRow,l=new i.ObjectMatrix;return i.Range.foreach(e,(d,c)=>{l.setValue(d,c,1)}),l.moveRows(o,r,a),i.queryObjectMatrix(l,d=>d===1)},_l=(s,e)=>{const{range:t,order:n}=s.params||{};if(!t||!n)return[e];const o=new i.ObjectMatrix;i.Range.foreach(e,(l,u)=>{o.setValue(l,u,1)});const r=new i.ObjectMatrix;return i.Range.foreach(t,(l,u)=>{var d;if(Object.prototype.hasOwnProperty.call(n,l)){const c=n[l],m=(d=o.getValue(c,u))!=null?d:0;r.setValue(l,u,m)}}),r.forValue((l,u,d)=>{o.setValue(l,u,d)}),i.queryObjectMatrix(o,l=>l===1)},Es=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!n||!t)return[];const o=Pe(t),r=Pe(n),a=Pe(e),l=Bt({start:o.startColumn,end:o.endColumn},{start:r.startColumn,end:r.endColumn},{start:a.startColumn,end:a.endColumn});return l===null?[{type:H.Delete}]:[{type:H.HorizontalMove,step:l.step||0,length:l.length||0}]},bl=(s,e)=>{const{fromRange:t,toRange:n}=s.params||{};if(!t||!n)return[e];const o=t.startColumn,r=t.endColumn-t.startColumn+1,a=n.startColumn,l=new i.ObjectMatrix;return i.Range.foreach(e,(u,d)=>{l.setValue(u,d,1)}),l.moveColumns(o,r,a),i.queryObjectMatrix(l,u=>u===1)},dr=(s,e)=>{var r,a;const t=(r=s.params)==null?void 0:r.toRange,n=(a=s.params)==null?void 0:a.fromRange;if(!t||!n)return[];const o=[];if(i.Rectangle.contains(t,e)&&o.push({type:H.Delete}),i.Rectangle.contains(n,e)){o.push({type:H.Delete});const l=i.Rectangle.getRelativeRange(e,n),u=i.Rectangle.getPositionRange(l,t);return[{type:H.Set,range:u}]}return o},El=(s,e)=>{var m,h;const t=(m=s.params)==null?void 0:m.toRange,n=(h=s.params)==null?void 0:h.fromRange;if(!t||!n)return[e];if(!i.Rectangle.intersects(n,e)&&!i.Rectangle.intersects(t,e))return[e];if(i.Rectangle.contains(n,e)){const R=i.Rectangle.getRelativeRange(e,n);return[i.Rectangle.getPositionRange(R,t)]}const o=new i.ObjectMatrix;i.Range.foreach(e,(R,C)=>{o.setValue(R,C,1)});const r=new i.ObjectMatrix,a=i.Rectangle.getIntersects(n,e);a&&i.Range.foreach(a,(R,C)=>{o.getValue(R,C)&&(o.setValue(R,C,void 0),r.setValue(R,C,1))});const l=t.startColumn-n.startColumn,u=t.startRow-n.startRow,d={startColumn:t.startColumn-l,endColumn:t.endColumn-l,startRow:t.startRow-u,endRow:t.endRow-u};return d&&i.Range.foreach(d,(R,C)=>{var I;const S=R+u,v=C+l;o.setValue(S,v,(I=r.getValue(R,C))!=null?I:0)}),i.queryObjectMatrix(o,R=>R===1)},Ze=(s,e)=>{const t=Pe(s),n=Pe(e),o=a=>a.endColumn-a.startColumn+1,r=a=>a.endRow-a.startRow+1;if(t.startRow<=n.startRow&&t.endRow>=n.endRow){if(n.startColumn<t.startColumn&&n.endColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn<t.startColumn&&n.endColumn>=t.endColumn){const a=i.Rectangle.getIntersects(n,t);if(a)return{step:0,length:-o(a)}}if(n.startColumn>=t.startColumn&&n.endColumn<=t.endColumn&&r(t)>=r(n))return null;if(n.startColumn>=t.startColumn&&n.startColumn<=t.endColumn&&n.endColumn>t.endColumn){const a=i.Rectangle.getIntersects(n,t);if(a){const l=-o(a);return{step:-(o(t)-o(a)),length:l}}}if(n.startColumn>t.endColumn)return{step:-o(t),length:0}}return{step:0,length:0}},Ts=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(t,e);if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.HorizontalMove,step:a,length:l})}return n},cr=(s,e,t)=>{var a;const n=(a=s.params)==null?void 0:a.range;if(!n)return[];const o=[];if(t&&t.length>0){let l=n.startRow;for(let u=n.startRow;u<=n.endRow;u++){if(t.includes(u)){if(u===l){l=u+1;continue}r({...n,startRow:l,endRow:u-1}),l=u+1;continue}u===n.endRow&&r({...n,startRow:l,endRow:n.endRow})}}else r(n);function r(l){const u=Ze(he(l),he(e));if(!u)o.push({type:H.Delete});else{const{step:d,length:c}=u;o.push({type:H.VerticalMove,step:d,length:c})}}return o},Tl=(s,e)=>{const{range:t,order:n}=s.params||{};if(!t||!n)return[];if(i.Rectangle.contains(t,e)&&e.endRow===e.startRow){const o=[],r=e.startRow;for(const a in n)if(n[a]===r){const l=Number(a);return o.push({type:H.VerticalMove,step:l-r,length:0}),o}return[]}return[]},Qe=(s,e)=>{const t=Pe(s),n=Pe(e),o=r=>r.endColumn-r.startColumn+1;return t.startRow<=n.startRow&&t.endRow>=n.endRow?n.startColumn<t.startColumn&&n.endColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn<t.startColumn&&n.endColumn>=t.endColumn?{step:0,length:o(t)}:n.startColumn>=t.startColumn&&n.endColumn<=t.endColumn||n.startColumn>=t.startColumn&&n.startColumn<=t.endColumn&&n.endColumn>t.endColumn||n.startColumn>=t.endColumn?{step:o(t),length:0}:{step:0,length:0}:{step:0,length:0}};function Ul(s,e,t){const n=[];if(i.Rectangle.contains(e,t)&&n.push({type:H.Delete}),i.Rectangle.contains(s,t)){n.push({type:H.Delete});const o=i.Rectangle.getRelativeRange(t,s),r=i.Rectangle.getPositionRange(o,e);return[{type:H.Set,range:r}]}return n}const mr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(he(t),he(e)),{step:r,length:a}=o;return n.push({type:H.VerticalMove,step:r,length:a}),n},hr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(t,e),{step:r,length:a}=o;return n.push({type:H.HorizontalMove,step:r,length:a}),n},gr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(he(t),he(e)),{step:r,length:a}=o;return n.push({type:H.VerticalMove,step:r,length:a}),n},Pl=(s,e)=>{var u;const t=(u=s.params)==null?void 0:u.range;if(!t)return[e];const n=t.endRow-t.startRow+1,o={...t,startRow:t.startRow,endRow:Number.POSITIVE_INFINITY},r=i.Rectangle.subtract(e,o),a=i.Rectangle.getIntersects(o,e);if(!a)return[e];const l=new i.ObjectMatrix;return r.forEach(d=>{i.Range.foreach(d,(c,m)=>{l.setValue(c,m,1)})}),a&&i.Range.foreach(a,(d,c)=>{l.setValue(d+n,c,1)}),i.queryObjectMatrix(l,d=>d===1)},Rr=(s,e)=>{var l;const t=(l=s.params)==null?void 0:l.range;if(!t)return[];const n=[],o=Qe(t,e),{step:r,length:a}=o;return n.push({type:H.HorizontalMove,step:r,length:a}),n},kl=(s,e)=>{var u;const t=(u=s.params)==null?void 0:u.range;if(!t)return[e];const n=t.endColumn-t.startColumn+1,o={...t,startColumn:t.startColumn,endColumn:Number.POSITIVE_INFINITY},r=i.Rectangle.subtract(e,o),a=i.Rectangle.getIntersects(o,e);if(!a)return[e];const l=new i.ObjectMatrix;return r.forEach(d=>{i.Range.foreach(d,(c,m)=>{l.setValue(c,m,1)})}),a&&i.Range.foreach(a,(d,c)=>{l.setValue(d,c+n,1)}),i.queryObjectMatrix(l,d=>d===1)},Cr=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(t,e);if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.HorizontalMove,step:a,length:l})}return n},Nl=(s,e)=>{var d;const t=(d=s.params)==null?void 0:d.range;if(!t)return[e];const n={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:Number.POSITIVE_INFINITY},o=t.endColumn-t.startColumn+1,r=i.Rectangle.getIntersects(t,e),a=i.Rectangle.subtract(e,n),l=i.Rectangle.getIntersects(n,e);if(!r&&!l)return[e];const u=new i.ObjectMatrix;return l&&i.Range.foreach(l,(c,m)=>{u.setValue(c,m-o,1)}),r&&i.Range.foreach(r,(c,m)=>{u.setValue(c,m-o,0)}),a.forEach(c=>{i.Range.foreach(c,(m,h)=>{u.setValue(m,h,1)})}),i.queryObjectMatrix(u,c=>c===1)},Sr=(s,e)=>{var r;const t=(r=s.params)==null?void 0:r.range;if(!t)return[];const n=[],o=Ze(he(t),he(e));if(!o)n.push({type:H.Delete});else{const{step:a,length:l}=o;n.push({type:H.VerticalMove,step:a,length:l})}return n},Ol=(s,e)=>{var d;const t=(d=s.params)==null?void 0:d.range;if(!t)return[e];const n={...t,startRow:t.startRow,endRow:Number.POSITIVE_INFINITY},o=t.endRow-t.startRow+1,r=i.Rectangle.getIntersects(t,e),a=i.Rectangle.subtract(e,n),l=i.Rectangle.getIntersects(n,e);if(!r&&!l)return[e];const u=new i.ObjectMatrix;return l&&i.Range.foreach(l,(c,m)=>{u.setValue(c-o,m,1)}),r&&i.Range.foreach(r,(c,m)=>{u.setValue(c-o,m,0)}),a.forEach(c=>{i.Range.foreach(c,(m,h)=>{u.setValue(m,h,1)})}),i.queryObjectMatrix(u,c=>c===1)},Dl=(s,e)=>{var o;const t=(o=s.ranges)!=null?o:[s.range],n=new i.ObjectMatrix;return i.Range.foreach(e,(r,a)=>{n.setValue(r,a,1)}),t.forEach(r=>{const a=r.startRow,u=r.endRow-a+1;n.removeRows(a,u)}),i.queryObjectMatrix(n,r=>r===1)},Al=(s,e)=>{const t=s.params,n=t.range.startRow,o=t.range.endRow-t.range.startRow+1;return e.startRow>=n?[{startRow:e.startRow+o,endRow:e.endRow+o,startColumn:e.startColumn,endColumn:e.endColumn}]:e.endRow<n?[e]:[{startRow:e.startRow,endRow:e.endRow+o,startColumn:e.startColumn,endColumn:e.endColumn}]},Wl=(s,e)=>{const t=s.params,n=t.range.startColumn,o=t.range.endColumn-t.range.startColumn+1;return e.startColumn>=n?[{startRow:e.startRow,endRow:e.endRow,startColumn:e.startColumn+o,endColumn:e.endColumn+o}]:e.endColumn<n?[e]:[{startRow:e.startRow,endRow:e.endRow,startColumn:e.startColumn,endColumn:e.endColumn+o}]},et=(s,e)=>{let t={...e};return s.forEach(n=>{switch(n.type){case H.Delete:{t=null;break}case H.HorizontalMove:{if(!t)return;t.startColumn+=n.step,t.endColumn+=n.step+(n.length||0);break}case H.VerticalMove:{if(!t)return;t.startRow+=n.step,t.endRow+=n.step+(n.length||0);break}case H.Set:{t=n.range;break}}}),t&&(t.endColumn<t.startColumn||t.endRow<t.startRow)?null:t},Us=(s,e)=>{let t=[];switch(e.id){case A.DeleteRangeMoveLeftCommandId:{t=Cr(e,s);break}case A.DeleteRangeMoveUpCommandId:{t=Sr(e,s);break}case A.InsertColCommandId:{t=hr(e,s);break}case A.InsertRangeMoveDownCommandId:{t=gr(e,s);break}case A.InsertRangeMoveRightCommandId:{t=Rr(e,s);break}case A.InsertRowCommandId:{t=mr(e,s);break}case A.MoveColsCommandId:{t=Es(e,s);break}case A.MoveRangeCommandId:{t=dr(e,s);break}case A.MoveRowsCommandId:{t=bs(e,s);break}case A.RemoveColCommandId:{t=Ts(e,s);break}case A.RemoveRowCommandId:{t=cr(e,s);break}case A.ReorderRangeCommandId:{t=Tl(e,s);break}}return et(t,s)},Vl=(s,e,t)=>[He.id,Be.id].includes(e.id)||vr(e,t).some(r=>i.Rectangle.intersects(r,s))?Us(s,e):s,Ps=(s,e)=>{let t=[];switch(e.id){case A.DeleteRangeMoveLeftCommandId:return Nl(e,s);case A.DeleteRangeMoveUpCommandId:return Ol(e,s);case A.InsertRangeMoveDownCommandId:return Pl(e,s);case A.InsertRangeMoveRightCommandId:return kl(e,s);case A.InsertColCommandId:return Wl(e,s);case A.InsertRowCommandId:return Al(e,s);case A.MoveColsCommandId:return bl(e,s);case A.MoveRangeCommandId:return El(e,s);case A.MoveRowsCommandId:return yl(e,s);case A.ReorderRangeCommandId:return _l(e,s);case A.RemoveColCommandId:{t=Ts(e,s);break}case A.RemoveRowCommandId:return Dl(e.params,s)}const n=et(t,s);return n?[n]:[]},$l=(s,e,t)=>[He.id,Be.id,xe.id,Is].includes(e.id)||vr(e,t).some(r=>i.Rectangle.intersects(r,s))?Ps(s,e):s;function fr(s,e){const{id:t,params:n}=e;let o={length:0,step:0,type:H.Unknown};switch(t){case Xe.id:o.type=H.Delete;break;case pe.id:o=Bt({start:n.sourceRange.startRow,end:n.sourceRange.endRow},{start:n.targetRange.startRow,end:n.targetRange.endRow},{start:s.startRow,end:s.endRow}),o.type=H.VerticalMove;break;case we.id:o=Bt({start:n.sourceRange.startColumn,end:n.sourceRange.endColumn},{start:n.targetRange.startColumn,end:n.targetRange.endColumn},{start:s.startColumn,end:s.endColumn}),o.type=H.HorizontalMove;break;case ne.id:o=Ze(n.range,s),o?o.type=H.HorizontalMove:o={step:0,length:0,type:H.Delete};break;case ae.id:o=Ze(he(n.range),he(s)),o?o.type=H.VerticalMove:o={step:0,length:0,type:H.Delete};break;case re.id:o=Qe(he(n.range),he(s)),o.type=H.VerticalMove;break;case ie.id:o=Qe(n.range,s),o.type=H.HorizontalMove;break;case Le.id:{const r=n.fromRange||new i.ObjectMatrix(n.from).getRange(),a=n.toRange||new i.ObjectMatrix(n.to).getRange();o=Ul(r,a,s)}break}return o?Array.isArray(o)?et(o,s):et([o],s):s}function vr(s,e){var n,o,r,a,l,u;const{selectionManagerService:t}=e;switch(s.id){case A.MoveColsCommandId:{const d=s.params;return[d.fromRange,{...d.toRange,startColumn:d.toRange.startColumn-.5,endColumn:d.toRange.endColumn-.5}]}case A.MoveRowsCommandId:{const d=s.params;return[d.fromRange,{...d.toRange,startRow:d.toRange.startRow-.5,endRow:d.toRange.startRow-.5}]}case A.MoveRangeCommandId:{const d=s;return[d.params.fromRange,d.params.toRange]}case A.InsertRowCommandId:{const c=s.params.range;return[{...c,startRow:c.startRow-.5,endRow:c.endRow-.5}]}case A.InsertColCommandId:{const c=s.params.range;return[{...c,startColumn:c.startColumn-.5,endColumn:c.endColumn-.5}]}case A.RemoveRowCommandId:return[s.params.range];case A.RemoveColCommandId:return[s.params.range];case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const c=((n=s.params)==null?void 0:n.range)||((r=(o=t.getCurrentSelections())==null?void 0:o.map(m=>m.range))==null?void 0:r[0]);return c?[c]:[]}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const c=((a=s.params)==null?void 0:a.range)||((u=(l=t.getCurrentSelections())==null?void 0:l.map(m=>m.range))==null?void 0:u[0]);return c?[c]:[]}case A.ReorderRangeCommandId:{const d=s,{range:c,order:m}=d.params,h=[];for(let R=c.startRow;R<=c.endRow;R++)R in m&&h.push({startRow:R,endRow:R,startColumn:c.startColumn,endColumn:c.endColumn});return h}}}function Ll(s){switch(s.id){case we.id:{const e=s.params;return[e.sourceRange,{...e.targetRange,startColumn:e.targetRange.startColumn-.5,endColumn:e.targetRange.startColumn-.5}]}case pe.id:{const e=s.params;return[e.sourceRange,{...e.targetRange,startRow:e.targetRange.startRow-.5,endRow:e.targetRange.startRow-.5}]}case Le.id:{const e=s.params;return[new i.ObjectMatrix(e.from.value).getRange(),new i.ObjectMatrix(e.to.value).getRange()]}case ie.id:{const t=s.params.range;return[{...t,startColumn:t.startColumn-.5,endColumn:t.startColumn-.5}]}case re.id:{const t=s.params.range;return[{...t,startRow:t.startRow-.5,endRow:t.startRow-.5}]}case ne.id:return[s.params.range];case ae.id:return[s.params.range]}}function Hl(s,e){var o,r,a,l,u,d;const t=s.get(i.IUniverInstanceService),n=s.get(g.SheetsSelectionsService);switch(e.id){case A.MoveColsCommandId:{const c=e.params,m=P(t,{unitId:c.unitId,subUnitId:c.subUnitId});return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,{...c.toRange,startColumn:c.fromRange.startColumn<c.toRange.startColumn?c.fromRange.endColumn+1:c.toRange.startColumn,endColumn:c.fromRange.startColumn<c.toRange.startColumn?c.toRange.endColumn-1:c.fromRange.startColumn-1}]}}case A.MoveRowsCommandId:{const c=e.params,m=P(t,{unitId:c.unitId,subUnitId:c.subUnitId});return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,{...c.toRange,startRow:c.fromRange.startRow<c.toRange.startRow?c.fromRange.endRow+1:c.toRange.startRow,endRow:c.fromRange.startRow<c.toRange.startRow?c.toRange.endRow-1:c.fromRange.startRow-1}]}}case A.MoveRangeCommandId:{const c=e.params,m=P(t);return{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[c.fromRange,c.toRange]}}case A.InsertRowCommandId:{const c=e.params,m=c.range;return{unitId:c.unitId,subUnitId:c.subUnitId,ranges:[...m.startRow>0?[{...m,startRow:m.startRow-1,endRow:m.endRow-1}]:[],{...m,startRow:m.startRow,endRow:Number.MAX_SAFE_INTEGER}]}}case A.InsertColCommandId:{const c=e.params,m=c.range;return{unitId:c.unitId,subUnitId:c.subUnitId,ranges:[...m.startColumn>0?[{...m,startColumn:m.startColumn-1,endColumn:m.endColumn-1}]:[],{...m,startColumn:m.startColumn,endColumn:Number.MAX_SAFE_INTEGER}]}}case A.RemoveRowCommandId:{const m=e.params.range,h=P(t);return{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startRow:m.endRow+1,endRow:Number.MAX_SAFE_INTEGER}]}}case A.RemoveColCommandId:{const m=e.params.range,h=P(t);return{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startColumn:m.endColumn+1,endColumn:Number.MAX_SAFE_INTEGER}]}}case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const c=e,m=P(t),h=((o=c.params)==null?void 0:o.range)||((a=(r=n.getCurrentSelections())==null?void 0:r.map(R=>R.range))==null?void 0:a[0]);return h?{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[h,{...h,startRow:h.endRow+1,endRow:Number.MAX_SAFE_INTEGER}]}:{unitId:m.unitId,subUnitId:m.subUnitId,ranges:[]}}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const m=((l=e.params)==null?void 0:l.range)||((d=(u=n.getCurrentSelections())==null?void 0:u.map(R=>R.range))==null?void 0:d[0]),h=P(t);return m?{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[m,{...m,startColumn:m.endColumn+1,endColumn:Number.MAX_SAFE_INTEGER}]}:{unitId:h.unitId,subUnitId:h.subUnitId,ranges:[]}}case A.ReorderRangeCommandId:{const c=e,{range:m,order:h}=c.params,R=[];for(let S=m.startRow;S<=m.endRow;S++)S in h&&R.push({startRow:S,endRow:S,startColumn:m.startColumn,endColumn:m.endColumn});const C=P(t);return{unitId:C.unitId,subUnitId:C.subUnitId,ranges:R}}}}var Bl=Object.getOwnPropertyDescriptor,Fl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Bl(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Sn=(s,e)=>(t,n)=>e(t,n,s);const jl=i.createInterceptorKey("MERGE_REDO"),Gl=i.createInterceptorKey("MERGE_UNDO"),Ir=Math.floor(Number.MAX_SAFE_INTEGER/10);class zl extends i.Disposable{constructor(e,t,n,o,r=!1){super(),this._unitId=e,this._subUnitId=t,this._range=n,this._callback=o,this._skipIntersects=r}onMutation(e){var o,r;if(((o=e.params)==null?void 0:o.unitId)!==this._unitId)return;if(e.id===Le.id){const a=e.params;if(a.from.subUnitId!==this._subUnitId||a.to.subUnitId!==this._subUnitId)return}else if(((r=e.params)==null?void 0:r.subUnitId)!==this._subUnitId)return;if(!this._range)return;if(this._skipIntersects){if(e.id===Xe.id)return;const a=Ll(e);if(a!=null&&a.some(l=>i.Rectangle.intersects(l,this._range)))return}const t=fr(this._range,e);if(t&&i.Rectangle.equals(t,this._range))return!1;const n=this._range;this._range=t,this._callback(n,t)}}g.RefRangeService=class extends i.Disposable{constructor(t,n,o,r){super();f(this,"interceptor",new i.InterceptorManager({MERGE_REDO:jl,MERGE_UNDO:Gl}));f(this,"_watchRanges",new Set);f(this,"_refRangeManagerMap",new Map);f(this,"_serializer",ql());f(this,"_onRefRangeChange",()=>{this._sheetInterceptorService.interceptCommand({getMutations:t=>{const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),o=pr(this._univerInstanceService),r=wr(this._univerInstanceService);if(!n||!o||!r)return{redos:[],undos:[],preRedos:[],preUndos:[]};const u=((()=>{switch(t.id){case A.MoveColsCommandId:{const R=t.params,C=Math.min(R.fromRange.startColumn,R.toRange.startColumn);return this._checkRange([{...R.fromRange,startColumn:C,endColumn:n.getColumnCount()-1}],o,r)}case A.MoveRowsCommandId:{const R=t.params,C=Math.min(R.fromRange.startRow,R.toRange.startRow);return this._checkRange([{...R.fromRange,startRow:C,endRow:n.getRowCount()-1}],o,r)}case A.MoveRangeCommandId:{const R=t;return this._checkRange([R.params.fromRange,R.params.toRange],o,r)}case A.InsertRowCommandId:{const S={startRow:t.params.range.startRow,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._checkRange([S],o,r)}case A.InsertColCommandId:{const C=t.params.range.startColumn,S={startRow:0,endRow:n.getRowCount()-1,startColumn:C,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.COLUMN};return this._checkRange([S],o,r)}case A.RemoveRowCommandId:{const S={startRow:t.params.range.startRow,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._checkRange([S],o,r)}case A.RemoveColCommandId:{const C=t.params.range.startColumn,S={startRow:0,endRow:n.getRowCount()-1,startColumn:C,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.COLUMN};return this._checkRange([S],o,r)}case A.DeleteRangeMoveUpCommandId:case A.InsertRangeMoveDownCommandId:{const C=t.params.range||Mr(this._selectionManagerService)[0],S={startRow:C.startRow,startColumn:C.startColumn,endColumn:C.endColumn,endRow:Ir};return this._checkRange([S],o,r)}case A.DeleteRangeMoveLeftCommandId:case A.InsertRangeMoveRightCommandId:{const C=t.params.range||Mr(this._selectionManagerService)[0],S={startRow:C.startRow,startColumn:C.startColumn,endColumn:Ir,endRow:C.endRow};return this._checkRange([S],o,r)}case A.ReorderRangeCommandId:{const R=t,{range:C,order:S}=R.params,v=[];for(let I=C.startRow;I<=C.endRow;I++)I in S&&v.push({startRow:I,endRow:I,startColumn:C.startColumn,endColumn:C.endColumn});return this._checkRange(v,o,r)}}})()||[]).reduce((R,C)=>{const S=C(t);return R.push(S),R},[]).reduce((R,C)=>{var S,v;return R.redos.push(...C.redos),R.undos.push(...C.undos),R.preRedos.push(...(S=C.preRedos)!=null?S:[]),R.preUndos.push(...(v=C.preUndos)!=null?v:[]),R},{redos:[],undos:[],preUndos:[],preRedos:[]}),d=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(u.preRedos,null)||[],c=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(u.redos,null)||[],m=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(u.preUndos,null)||[],h=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(u.undos,null)||[];return{redos:c,undos:h,preRedos:d,preUndos:m}}})});f(this,"_checkRange",(t,n,o)=>{const r=yr(n,o),a=this._refRangeManagerMap.get(r);if(a){const l=new Set;return[...a.keys()].forEach(d=>{const c=a.get(d),m=this._serializer.deserialize(d),h={...m,startRow:+m.startRow,endRow:+m.endRow,startColumn:+m.startColumn,endColumn:+m.endColumn,rangeType:m.rangeType&&+m.rangeType};t.some(R=>i.Rectangle.intersects(R,h))&&c&&c.forEach(R=>{l.add(R)})}),[...l]}return[]});f(this,"registerRefRange",(t,n,o,r)=>{const a=o||pr(this._univerInstanceService),l=r||wr(this._univerInstanceService);if(!a||!l)return i.toDisposable(()=>{});const u=yr(a,l),d=this._serializer.serialize(t);let c=this._refRangeManagerMap.get(u);c||(c=new Map,this._refRangeManagerMap.set(u,c));const m=c.get(d);return m?m.add(n):c.set(d,new Set([n])),i.toDisposable(()=>{const h=c.get(d);h&&(h.delete(n),h.size||(c.delete(d),c.size||this._refRangeManagerMap.delete(u)))})});this._commandService=t,this._sheetInterceptorService=n,this._univerInstanceService=o,this._selectionManagerService=r,this._onRefRangeChange(),this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO,{priority:-1,handler:a=>a}),this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO,{priority:-1,handler:a=>a})}watchRange(t,n,o,r,a){let l;this._watchRanges.size===0&&(l=this._commandService.onCommandExecuted(m=>{if(m.type!==i.CommandType.MUTATION)return!1;for(const h of this._watchRanges)h.onMutation(m)}));const u=new zl(t,n,o,r,a);this._watchRanges.add(u);const d=i.toDisposable(()=>{this._watchRanges.delete(u),this._watchRanges.size===0&&(l==null||l.dispose(),l=null)}),c=this.disposeWithMe(d);return i.toDisposable(()=>{c.dispose(),d.dispose()})}},g.RefRangeService=Fl([Sn(0,i.ICommandService),Sn(1,i.Inject(g.SheetInterceptorService)),Sn(2,i.Inject(i.IUniverInstanceService)),Sn(3,i.Inject(g.SheetsSelectionsService))],g.RefRangeService);function pr(s){return s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getUnitId()}function wr(s){var e;return(e=s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:e.getSheetId()}function Mr(s){var e;return((e=s.getCurrentSelections())==null?void 0:e.map(t=>t.range))||[]}function yr(s,e){return`${s}_${e}`}function ql(){const s=["startRow","startColumn","endRow","endColumn","rangeType"];return{deserialize:t=>{const n=s.reduce((r,a,l)=>(r[String(l)]=a,r),{});return t.split("_").reduce((r,a,l)=>{const u=String(l);return a&&n[u]&&(r[n[u]]=a),r},{})},serialize:t=>s.reduce((n,o,r)=>{const a=t[o];return a!==void 0?`${n}${r>0?"_":""}${a}`:`${n}`},"")}}var Yl=Object.getOwnPropertyDescriptor,Kl=(s,e,t,n)=>{for(var o=n>1?void 0:n?Yl(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Mt=(s,e)=>(t,n)=>e(t,n,s);const Jl=[ie.id,re.id,ne.id,ae.id],xl=[pe.id,we.id];function ks(s,e){let t=s;if(e!==void 0){const n=[];for(let o=0;o<t.length;o++){const{startRow:r,endRow:a,startColumn:l,endColumn:u}=t[o];if(e===i.Dimension.ROWS)for(let d=r;d<=a;d++){const c={startRow:d,endRow:d,startColumn:l,endColumn:u};n.push(c)}else if(e===i.Dimension.COLUMNS)for(let d=l;d<=u;d++){const c={startRow:r,endRow:a,startColumn:d,endColumn:d};n.push(c)}}t=n}return t}const _r=i.createInterceptorKey("mergeCellPermissionCheck");g.MergeCellController=class extends i.Disposable{constructor(t,n,o,r,a,l){super();f(this,"disposableCollection",new i.DisposableCollection);f(this,"interceptor",new i.InterceptorManager({MERGE_CELL_INTERCEPTOR_CHECK:_r}));this._commandService=t,this._refRangeService=n,this._univerInstanceService=o,this._injector=r,this._sheetInterceptorService=a,this._selectionManagerService=l,this._onRefRangeChange(),this._initCommandInterceptor(),this._commandExecutedListener()}_initCommandInterceptor(){const t=this;this._sheetInterceptorService.interceptCommand({getMutations(n){var o;switch(n.id){case sn.id:case on.id:{const r=t._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),a=r.getUnitId(),l=r==null?void 0:r.getActiveSheet();if(!l)return{redos:[],undos:[]};const u=l.getSheetId(),d=l.getConfig().mergeData,c=(o=t._selectionManagerService.getCurrentSelections())==null?void 0:o.map(m=>m.range);if(c&&c.length>0&&c.some(h=>d.some(R=>i.Rectangle.intersects(R,h)))){const h={unitId:a,subUnitId:u,ranges:c},R=le(t._injector,h),C=[{id:G.id,params:h}],S=[{id:j.id,params:R}];return{redos:C,undos:S}}}}return{redos:[],undos:[]}}}),this._sheetInterceptorService.interceptRanges({getMutations:({unitId:n,subUnitId:o,ranges:r})=>{const a=[],l=[],u={redos:a,undos:l};if(!r||!r.length)return u;const d=P(this._univerInstanceService,{unitId:n,subUnitId:o});if(!d)return u;const{worksheet:c}=d,h=c.getMergeData().filter(R=>r.some(C=>i.Rectangle.intersects(R,C)));return h.length?(a.push({id:G.id,params:{unitId:n,subUnitId:o,ranges:h}}),l.push({id:j.id,params:{unitId:n,subUnitId:o,ranges:h}}),{undos:l,redos:a}):u}})}refRangeHandle(t,n,o){switch(t.id){case A.MoveColsCommandId:{const r=t.params;return this._handleMoveColsCommand(r,n,o)}case A.MoveRowsCommandId:{const r=t.params;return this._handleMoveRowsCommand(r,n,o)}case Me.id:{const r=t.params,a=r.unitId||n,l=r.subUnitId||o;return this._handleInsertRowCommand(r,a,l)}case ye.id:{const r=t.params,a=r.unitId||n,l=r.subUnitId||o;return this._handleInsertColCommand(r,a,l)}case Lt.id:{const r=t.params;return this._handleRemoveColCommand(r,n,o)}case $t.id:{const r=t.params;return this._handleRemoveRowCommand(r,n,o)}case Je.id:{const r=t.params;return this._handleMoveRangeCommand(r,n,o)}case It.id:{const r=t.params;return this._handleInsertRangeMoveRightCommand(r,n,o)}case xe.id:{const r=t.params;return this._handleInsertRangeMoveDownCommand(r,n,o)}case Be.id:{const r=t.params;return this._handleDeleteRangeMoveUpCommand(r,n,o)}case He.id:{const r=t.params;return this._handleDeleteRangeMoveLeftCommand(r,n,o)}}return{redos:[],undos:[]}}_onRefRangeChange(){const t=(n,o)=>{const r=this._univerInstanceService.getUniverSheetInstance(n);if(!r)return;const a=r==null?void 0:r.getSheetBySheetId(o);if(!a)return;this.disposableCollection.dispose();const l=a.getMergeData(),u=d=>this.refRangeHandle(d,n,o);l.forEach(d=>{this.disposableCollection.add(this._refRangeService.registerRefRange(d,u,n,o))})};this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===Ct.id){const o=n.params,r=o.subUnitId,a=o.unitId;if(!r||!a)return;t(a,r)}if(n.id===j.id){const o=n.params,r=o.subUnitId,a=o.unitId;if(!r||!a)return;t(o.unitId,o.subUnitId)}})),this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).pipe(O.first(n=>!!n)).subscribe(n=>{const o=n.getActiveSheet();o&&t(n.getUnitId(),o.getSheetId())})}_handleMoveRowsCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=[...a.getMergeData()],u={unitId:n,subUnitId:o,ranges:[]},d={unitId:n,subUnitId:o,ranges:[]},{fromRange:c}=t,{startRow:m,endRow:h}=c;if(l.forEach(S=>{if(m<=S.startRow&&h>=S.endRow){u.ranges.push(S);const v=bs({id:A.MoveRowsCommandId,params:t},S),I=et(v,S);I&&d.ranges.push(I)}}),u.ranges.length===0)return this._handleNull();const R=le(this._injector,u),C=ge(this._injector,d);return{preRedos:[{id:G.id,params:u}],redos:[{id:j.id,params:d}],preUndos:[{id:G.id,params:C}],undos:[{id:j.id,params:R}]}}_handleMoveColsCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=[...a.getMergeData()],u={unitId:n,subUnitId:o,ranges:[]},d={unitId:n,subUnitId:o,ranges:[]},{fromRange:c}=t,{startColumn:m,endColumn:h}=c;if(l.forEach(S=>{if(m<=S.startColumn&&h>=S.endColumn){u.ranges.push(S);const v=Es({id:A.MoveColsCommandId,params:t},S),I=et(v,S);I&&d.ranges.push(I)}}),u.ranges.length===0)return this._handleNull();const R=le(this._injector,u),C=ge(this._injector,d);return{preRedos:[{id:G.id,params:u}],redos:[{id:j.id,params:d}],preUndos:[{id:G.id,params:C}],undos:[{id:j.id,params:R}]}}_handleMoveRangeCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=a.getMergeData(),u=l.filter(C=>i.Rectangle.intersects(C,t.fromRange)),d=l.filter(C=>i.Rectangle.intersects(C,t.toRange)),c=u.map(C=>i.Rectangle.getRelativeRange(C,t.fromRange)).map(C=>i.Rectangle.getPositionRange(C,t.toRange)),m=ks(c).filter(C=>!l.some(S=>i.Rectangle.equals(C,S))),h=[{id:G.id,params:{unitId:n,subUnitId:o,ranges:u}},{id:G.id,params:{unitId:n,subUnitId:o,ranges:d}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:m}}],R=[{id:G.id,params:{unitId:n,subUnitId:o,ranges:m}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:d}},{id:j.id,params:{unitId:n,subUnitId:o,ranges:u}}];return{redos:h,undos:R}}_handleInsertRowCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const{range:l}=t,{startRow:u,endRow:d}=l,c=i.Tools.deepClone(a.getMergeData()).reduce((M,p)=>(u>p.startRow&&u<=p.endRow&&M.push(p),M),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(a.getMergeData()).reduce((M,p)=>{if(u>p.startRow&&u<=p.endRow){const w=d-u+1;p.endRow+=w,this._checkIsMergeCell(p)&&M.push(p)}return M},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h},{id:j.id,params:C}],I=[{id:G.id,params:S},{id:j.id,params:R}];return{redos:v,undos:I}}_handleInsertColCommand(t,n,o){const{range:r}=t,a=_e(this._univerInstanceService,n);if(!a)return this._handleNull();const l=be(a,o);if(!l)return this._handleNull();const{startColumn:u,endColumn:d}=r,c=i.Tools.deepClone(l.getMergeData()).reduce((M,p)=>(u>p.startColumn&&u<=p.endColumn&&M.push(p),M),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(l.getMergeData()).reduce((M,p)=>{if(u>p.startColumn&&u<=p.endColumn){const w=d-u+1;p.endColumn+=w,this._checkIsMergeCell(p)&&M.push(p)}return M},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h},{id:j.id,params:C}],I=[{id:G.id,params:S},{id:j.id,params:R}];return{redos:v,undos:I}}_handleRemoveColCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const{range:l}=t,{startColumn:u,endColumn:d}=l,c=i.Tools.deepClone(a.getMergeData()).reduce((w,y)=>(i.Rectangle.intersects(l,y)&&w.push(y),w),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(a.getMergeData()).reduce((w,y)=>{if(i.Rectangle.intersects(l,y)){if(u<=y.startColumn&&d>=y.endColumn)return w;u>=y.startColumn&&d<=y.endColumn?y.endColumn-=d-u+1:u<y.startColumn?(y.startColumn=u,y.endColumn-=d-u+1):d>y.endColumn&&(y.endColumn=u-1),this._checkIsMergeCell(y)&&w.push(y)}return w},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{preUndos:M,undos:p,preRedos:v,redos:I}}_handleRemoveRowCommand(t,n,o){const{range:r}=t,a=_e(this._univerInstanceService,n);if(!a)return this._handleNull();const l=be(a,o);if(!l)return this._handleNull();const{startRow:u,endRow:d}=r,c=i.Tools.deepClone(l.getMergeData()).reduce((w,y)=>(i.Rectangle.intersects(r,y)&&w.push(y),w),[]);if(c.length===0)return this._handleNull();const m=i.Tools.deepClone(l.getMergeData()).reduce((w,y)=>{if(i.Rectangle.intersects(r,y)){if(u<=y.startRow&&d>=y.endRow)return w;u>=y.startRow&&d<=y.endRow?y.endRow-=d-u+1:u<y.startRow?(y.startRow=u,y.endRow-=d-u+1):d>y.endRow&&(y.endRow=u-1),this._checkIsMergeCell(y)&&w.push(y)}return w},[]),h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{preUndos:M,undos:p,preRedos:v,redos:I}}_handleInsertRangeMoveRightCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxColumns()-1,d=a.getMergeData(),c=[],m=[];d.forEach(v=>{const{startRow:I,endRow:M,startColumn:p,endColumn:w}=l;if(i.Rectangle.intersects({startRow:I,startColumn:p,endRow:M,endColumn:u},v)&&(c.push(v),i.Rectangle.contains({startRow:I,startColumn:p,endRow:M,endColumn:u},v))){const T=w-p+1;m.push({startRow:v.startRow,startColumn:v.startColumn+T,endRow:v.endRow,endColumn:v.endColumn+T})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C);return{preRedos:[{id:G.id,params:h}],redos:[{id:j.id,params:C}],preUndos:[{id:G.id,params:S}],undos:[{id:j.id,params:R}]}}_handleInsertRangeMoveDownCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxRows()-1,d=a.getMergeData(),c=[],m=[];d.forEach(w=>{const{startRow:y,startColumn:b,endColumn:T,endRow:U}=l;if(i.Rectangle.intersects({startRow:y,startColumn:b,endRow:u,endColumn:T},w)&&(c.push(w),i.Rectangle.contains({startRow:y,startColumn:b,endRow:u,endColumn:T},w))){const N=U-y+1;m.push({startRow:w.startRow+N,startColumn:w.startColumn,endRow:w.endRow+N,endColumn:w.endColumn})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{redos:I,undos:p,preRedos:v,preUndos:M}}_handleDeleteRangeMoveUpCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxRows()-1,d=a.getMergeData(),c=[],m=[];d.forEach(w=>{const{startRow:y,startColumn:b,endColumn:T,endRow:U}=l;if(i.Rectangle.intersects({startRow:y,startColumn:b,endRow:u,endColumn:T},w)&&(c.push(w),i.Rectangle.contains({startRow:y,startColumn:b,endRow:u,endColumn:T},w))){const N=U-y+1,W=i.Rectangle.moveVertical(w,-N);m.push(W)}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C),v=[{id:G.id,params:h}],I=[{id:j.id,params:C}],M=[{id:G.id,params:S}],p=[{id:j.id,params:R}];return{redos:I,undos:p,preRedos:v,preUndos:M}}_handleDeleteRangeMoveLeftCommand(t,n,o){const r=_e(this._univerInstanceService,n);if(!r)return this._handleNull();const a=be(r,o);if(!a)return this._handleNull();const l=t.range,u=a.getMaxColumns()-1,d=a.getMergeData(),c=[],m=[];d.forEach(v=>{const{startRow:I,endRow:M,startColumn:p,endColumn:w}=l;if(i.Rectangle.intersects({startRow:I,startColumn:p,endRow:M,endColumn:u},v)&&(c.push(v),i.Rectangle.contains({startRow:I,startColumn:p,endRow:M,endColumn:u},v))){const T=w-p+1;m.push({startRow:v.startRow,startColumn:v.startColumn-T,endRow:v.endRow,endColumn:v.endColumn-T})}});const h={unitId:n,subUnitId:o,ranges:c},R=le(this._injector,h),C={unitId:n,subUnitId:o,ranges:m},S=ge(this._injector,C);return{preRedos:[{id:G.id,params:h}],redos:[{id:j.id,params:C}],undos:[{id:j.id,params:R}],preUndos:[{id:G.id,params:S}]}}_checkIsMergeCell(t){return!(t.startRow===t.endRow&&t.startColumn===t.endColumn)}_handleNull(){return{redos:[],undos:[]}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(xl.includes(t.id)){if(!t.params)return;const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const{sourceRange:r,targetRange:a}=t.params,l=r.startColumn===a.startColumn&&r.endColumn===a.endColumn,u=l?r.endRow-r.startRow+1:r.endColumn-r.startColumn+1,d=l?r.startRow:r.startColumn,c=l?a.startRow:a.startColumn,m=o.getConfig().mergeData,h=[];m.forEach(v=>{let{startRow:I,endRow:M,startColumn:p,endColumn:w,rangeType:y}=v;i.Rectangle.intersects(v,r)||(l?d<I&&c>M?(I-=u,M-=u):d>M&&c<=I&&(I+=u,M+=u):d<p&&c>w?(p-=u,w-=u):d>w&&c<=p&&(p+=u,w+=u)),v.startRow===v.endRow&&v.startColumn===v.endColumn||h.push({startRow:I,endRow:M,startColumn:p,endColumn:w,rangeType:y})}),o.setMergeData(h),this.disposableCollection.dispose();const{unitId:R,subUnitId:C}=t.params,S=v=>this.refRangeHandle(v,R,C);h.forEach(v=>{this.disposableCollection.add(this._refRangeService.registerRefRange(v,S,R,C))})}if(Jl.includes(t.id)){const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const r=o.getConfig().mergeData,a=t.params;if(!a)return;const{range:l}=a,u=t.id.includes("row"),d=t.id.includes("insert"),c=u?l.startRow:l.startColumn,m=u?l.endRow:l.endColumn,h=m-c+1,R=[];r.forEach(I=>{let{startRow:M,endRow:p,startColumn:w,endColumn:y,rangeType:b}=I;d?u?c<=M&&(M+=h,p+=h):c<=w&&(w+=h,y+=h):u?m<M&&(M-=h,p-=h):m<w&&(w-=h,y-=h),I.startRow===I.endRow&&I.startColumn===I.endColumn||R.push({startRow:M,endRow:p,startColumn:w,endColumn:y,rangeType:b})}),o.setMergeData(R),this.disposableCollection.dispose();const{unitId:C,subUnitId:S}=t.params,v=I=>this.refRangeHandle(I,C,S);R.forEach(I=>{this.disposableCollection.add(this._refRangeService.registerRefRange(I,v,C,S))})}}))}},g.MergeCellController=Kl([Mt(0,i.Inject(i.ICommandService)),Mt(1,i.Inject(g.RefRangeService)),Mt(2,i.Inject(i.IUniverInstanceService)),Mt(3,i.Inject(i.Injector)),Mt(4,i.Inject(g.SheetInterceptorService)),Mt(5,i.Inject(g.SheetsSelectionsService))],g.MergeCellController);function _e(s,e){return e?s.getUniverSheetInstance(e):s.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET)}function be(s,e){return e?s.getSheetBySheetId(e):s.getActiveSheet()}function Xl(s,e){return e.some(t=>Zl(s,t))}function Zl(s,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,a=s.getMatrixWithMergedCells(t,n,r,o);let l=!1;return a.forValue((u,d,c)=>{if(c&&(u!==t||d!==n)&&s.cellHasValue(c))return l=!0,!1}),l}function Ql(s,e,t,n){const o=[],r=[],a=t.getSheetId();return n.forEach(l=>{const u=eu(t,l),d={unitId:e,subUnitId:a,cellValue:u.getData()},c=ce(s,d);o.push({id:F.id,params:c}),r.push({id:F.id,params:d})}),{undos:o,redos:r}}function eu(s,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,a=s.getMatrixWithMergedCells(t,n,r,o,i.CellModeEnum.Raw),l=new i.ObjectMatrix;return a.forValue((u,d,c)=>{c&&(u!==t||d!==n)&&l.setValue(u,d,null)}),l}const Ft={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=e.unitId,a=e.subUnitId,l=e.selections,u=ks(l,e.value),d=o.getUniverSheetInstance(r).getSheetBySheetId(a),c=[],m=[],h=Xl(d,u),R={unitId:r,subUnitId:a,ranges:u},C={unitId:r,subUnitId:a,ranges:u};c.push({id:G.id,params:R}),c.push({id:j.id,params:C});const S=le(s,R),v=ge(s,C);if(m.push({id:G.id,params:v}),m.push({id:j.id,params:S}),h){const M=Ql(s,r,d,u);c.unshift(...M.redos),m.push(...M.undos)}return i.sequenceExecute(c,t).result?(n.pushUndoRedo({unitID:r,undoMutations:m,redoMutations:c}),!0):!1}},tu={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{selections:n,unitId:l,subUnitId:u})}},nu={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{value:i.Dimension.COLUMNS,selections:n,unitId:l,subUnitId:u})}},su={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async s=>{var d;const e=s.get(i.ICommandService),n=(d=s.get(g.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(n!=null&&n.length))return!1;const r=s.get(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!r)return!1;const a=r.getActiveSheet();if(!a)return!1;const l=r.getUnitId(),u=a.getSheetId();return e.executeCommand(Ft.id,{value:i.Dimension.ROWS,selections:n,unitId:l,subUnitId:u})}};function ou(s,e,t,n,o){const r=s.get(i.IUniverInstanceService),a=P(r,{unitId:e,subUnitId:t});if(!a)return;const{worksheet:l}=a;if(l.getMergeData().some(m=>n.some(h=>i.Rectangle.intersects(h,m))))throw new Error("The ranges to be merged overlap with the existing merged cells");s.get(i.ICommandService).executeCommand(Ft.id,{unitId:e,subUnitId:t,selections:n,defaultMerge:o})}class ke{constructor(){f(this,"_model",new Map);f(this,"_ruleChange",new O.Subject);f(this,"_ruleRefresh",new O.Subject);f(this,"_resetOrder",new O.Subject);f(this,"ruleChange$",this._ruleChange.asObservable());f(this,"ruleRefresh$",this._ruleRefresh.asObservable());f(this,"resetOrder$",this._resetOrder.asObservable());f(this,"_worksheetRuleInitStateChange",new O.BehaviorSubject(!1));f(this,"worksheetRuleInitStateChange$",this._worksheetRuleInitStateChange.asObservable())}changeRuleInitState(e){this._worksheetRuleInitStateChange.next(e)}getSheetRuleInitState(){return this._worksheetRuleInitStateChange.value}addRule(e,t){this._ensureSubUnitMap(e).set(t.subUnitId,t),this._ruleChange.next({unitId:e,rule:t,type:"add",subUnitId:t.subUnitId})}deleteRule(e,t){var o,r,a;const n=(r=(o=this._model)==null?void 0:o.get(e))==null?void 0:r.get(t);n&&((a=this._model.get(e))==null||a.delete(t),this._ruleChange.next({unitId:e,rule:n,type:"delete",subUnitId:t}))}setRule(e,t,n){var r,a;const o=this.getRule(e,t);o&&((a=(r=this._model)==null?void 0:r.get(e))==null||a.set(t,n),this._ruleChange.next({unitId:e,oldRule:o,rule:n,type:"set",subUnitId:t}))}getRule(e,t){var n,o;return(o=(n=this._model)==null?void 0:n.get(e))==null?void 0:o.get(t)}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n);o!=null&&o.size&&(e[n]=[],[...o.keys()].forEach(a=>{const l=o.get(a);l&&e[n].push(l)}))}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n];if(o!=null&&o.length){const r=new Map;o.forEach(a=>{r.set(a.subUnitId,a)}),t.set(n,r)}}),this._model=t}deleteUnitModel(e){this._model.delete(e)}_ensureSubUnitMap(e){let t=this._model.get(e);return t||(t=new Map,this._model.set(e,t)),t}ruleRefresh(e){this._ruleRefresh.next(e)}resetOrder(){this._resetOrder.next(Math.random())}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)if(r.permissionId===t)return[e,o]}}const Fe={id:"sheet.mutation.add-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,rule:n}=e;return s.get(ke).addRule(t,n),!0}},tt={id:"sheet.mutation.delete-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n}=e;return s.get(ke).deleteRule(t,n),!0}},br={type:i.CommandType.COMMAND,id:"sheet.command.add-worksheet-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,unitId:r}=e,a=o.subUnitId;if(await t.executeCommand(Fe.id,{unitId:r,rule:o,subUnitId:o.subUnitId})){const u=[{id:Fe.id,params:{unitId:r,rule:o,subUnitId:o.subUnitId}}],d=[{id:tt.id,params:{unitId:r,subUnitId:a}}];n.pushUndoRedo({unitID:r,redoMutations:u,undoMutations:d})}return!0}},Er={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-range-theme-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=io(s,e);return t.syncExecuteCommand(rt.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:it.id,params:r}],redoMutations:[{id:rt.id,params:e}]}),!0):!1}},Tr={type:i.CommandType.COMMAND,id:"sheet.command.append-row",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o,subUnitId:r,cellValue:a,insertRowNums:l,insertColumnNums:u,maxRows:d,maxColumns:c}=e,m={unitId:o,subUnitId:r,cellValue:a},h=ce(s,m),R=[{id:F.id,params:m}],C=[{id:F.id,params:h}];if(l){const v={unitId:o,subUnitId:r,range:{startRow:d,endRow:d,startColumn:0,endColumn:c-1}},I=en(s,v);R.unshift({id:re.id,params:v}),C.push({id:ae.id,params:I})}if(u){const v={unitId:o,subUnitId:r,range:{startRow:0,endRow:d-1,startColumn:c,endColumn:c-1+u}},I=Nt(s,v);R.unshift({id:ie.id,params:v}),C.push({id:ne.id,params:I})}return i.sequenceExecute(R,t).result?(n.pushUndoRedo({unitID:o,undoMutations:C,redoMutations:R}),!0):!1}},fn={id:"sheet.command.clear-selection-content",type:i.CommandType.COMMAND,handler:(s,e)=>{var p;const t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUndoRedoService),a=s.get(g.SheetInterceptorService),l=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!l)return!1;const u=(e==null?void 0:e.unitId)||l.getUnitId(),d=l.getActiveSheet();if(!d)return!1;const c=(e==null?void 0:e.subUnitId)||d.getSheetId(),m=(e==null?void 0:e.ranges)||((p=o.getCurrentSelections())==null?void 0:p.map(w=>w.range));if(!(m!=null&&m.length))return!1;const h=Dt(m,s,u,c),R={subUnitId:c,unitId:u,cellValue:Uo(h)},C=ce(s,R),S=a.onCommandExecute({id:fn.id}),v=[{id:F.id,params:R},...S.redos],I=[...S.undos,{id:F.id,params:C}];return i.sequenceExecute(v,n).result?(r.pushUndoRedo({unitID:u,undoMutations:I,redoMutations:v}),!0):!1}},Ns=(s,e)=>({subUnitId:e.sheet.id,unitId:e.unitId,subUnitName:e.sheet.name}),yt={id:"sheet.mutation.insert-sheet",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService),{sheet:n,index:o,unitId:r,styles:a}=e,l=t.getUniverSheetInstance(r);return l?(a&&l.addStyles(a),l.addWorksheet(n.id,o,n)):!1}},Os={type:i.CommandType.COMMAND,id:"sheet.command.copy-sheet",handler:(s,e)=>{var w,y;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=s.get(i.LocaleService),l=P(o,e);if(!l)return!1;const{workbook:u,worksheet:d,unitId:c,subUnitId:m}=l,h=i.Tools.deepClone(d.getConfig());h.name=ru(u,a,h.name),h.id=i.generateRandomId();const C={index:u.getSheetIndex(d)+1,sheet:h,unitId:c},S=Ns(s,C),v=r.onCommandExecute({id:Os.id,params:{unitId:c,subUnitId:m,targetSubUnitId:h.id}}),I=[...(w=v.preRedos)!=null?w:[],{id:yt.id,params:C},...v.redos],M=[...(y=v.preUndos)!=null?y:[],{id:Xe.id,params:S},...v.undos];return i.sequenceExecute(I,t).result?(n.pushUndoRedo({unitID:c,undoMutations:M,redoMutations:I}),!0):!1}};function ru(s,e,t){let n=`${t} ${e.t("sheets.tabs.sheetCopy","")}`,o=2;for(;s.checkSheetName(n);)n=`${t} ${e.t("sheets.tabs.sheetCopy",`${o}`)}`,o++;return n}const Ur={type:i.CommandType.COMMAND,id:"sheet.command.delete-range-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o,subUnitId:r,rule:a}=e,l={unitId:o,subUnitId:r,ruleIds:[a.id]};return await t.executeCommand(Te.id,l)&&n.pushUndoRedo({unitID:o,redoMutations:[{id:Te.id,params:l}],undoMutations:[{id:Ce.id,params:{unitId:o,subUnitId:r,rules:[a]}}]}),!0}},Pr={type:i.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection",handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,unitId:r,subUnitId:a}=e;t.executeCommand(tt.id,{unitId:r,subUnitId:a});const l=[{id:tt.id,params:{unitId:r,subUnitId:a}}],u=[{id:Fe.id,params:{unitId:r,rule:o,subUnitId:a}}];return n.pushUndoRedo({unitID:r,redoMutations:l,undoMutations:u}),!0}},kr={type:i.CommandType.COMMAND,id:"sheet.command.remove-worksheet-range-theme-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=ao(s,e);return t.syncExecuteCommand(it.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:rt.id,params:r}],redoMutations:[{id:it.id,params:e}]}),!0):!1}},Nr={id:"sheet.command.insert-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService);if(!e)return!1;const o={...e};return t.syncExecuteCommand(J.SetDefinedNameMutation.id,o)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:[{id:J.RemoveDefinedNameMutation.id,params:o}],redoMutations:[{id:J.SetDefinedNameMutation.id,params:o}]}),!0):!1}},Or={id:"sheet.command.insert-sheet",type:i.CommandType.COMMAND,handler:(s,e)=>{var v;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(i.LocaleService),a=Hn(o,{unitId:e==null?void 0:e.unitId});if(!a)return!1;const{unitId:l,workbook:u}=a;let d=u.getSheets().length;const c=e==null?void 0:e.sheet,m=c==null?void 0:c.id,h=i.mergeWorksheetSnapshotWithDefault(c||{});e?(d=(v=e.index)!=null?v:d,h.id=m||i.generateRandomId(),h.name=(c==null?void 0:c.name)||u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)):(h.id=i.generateRandomId(),h.name=u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`));const R={index:d,sheet:h,unitId:l},C=Ns(s,R);return t.syncExecuteCommand(yt.id,R)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:Xe.id,params:C}],redoMutations:[{id:yt.id,params:R}]}),!0):!1}},_t={id:"sheet.mutation.register-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,rangeThemeStyleJson:n,themeName:o}=e,r=s.get(i.IUniverInstanceService),a=P(r),l=s.get(g.SheetRangeThemeModel);if(!a)return!1;const u=new We(o,n);return l.registerRangeThemeStyle(t,u),!0}},vn={id:"sheet.mutation.unregister-worksheet-range-theme-style",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,themeName:n}=e,o=s.get(i.IUniverInstanceService),r=P(o),a=s.get(g.SheetRangeThemeModel);return r?(a.unregisterRangeThemeStyle(t,n),!0):!1}},Dr={id:"sheet.command.register-worksheet-range-theme-style",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,rangeThemeStyle:n}=e,o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService);if(!P(o))return!1;const u={unitId:t,themeName:n.getName(),rangeThemeStyleJson:n.toJson()},d={unitId:t,themeName:n.getName()};return r.syncExecuteCommand(_t.id,u)&&a.pushUndoRedo({unitID:t,undoMutations:[{id:vn.id,params:d}],redoMutations:[{id:_t.id,params:u}]}),!0}},Ds={id:"sheet.command.remove-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{var c,m;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService);if(!e)return!1;const r={...e},a=o.onCommandExecute({id:Ds.id,params:e}),l=[...(c=a.preRedos)!=null?c:[],{id:J.RemoveDefinedNameMutation.id,params:r},...a.redos],u=[...(m=a.preUndos)!=null?m:[],{id:J.SetDefinedNameMutation.id,params:r},...a.undos];return i.sequenceExecute(l,t)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:u.filter(Boolean),redoMutations:l.filter(Boolean)}),!0):!1}},In={id:"sheet.command.remove-sheet",type:i.CommandType.COMMAND,handler:(s,e)=>{var I,M;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetInterceptorService),a=P(o,e);if(!a)return!1;const{unitId:l,subUnitId:u,workbook:d,worksheet:c}=a;if(d.getSheets().length<=1)return!1;const m={subUnitId:u,unitId:l,subUnitName:c.getName()},h=rr(s,m),R=r.onCommandExecute({id:In.id,params:{unitId:l,subUnitId:u}}),C=[...(I=R.preRedos)!=null?I:[],{id:Xe.id,params:m},...R.redos],S=[...(M=R.preUndos)!=null?M:[],{id:yt.id,params:h},...R.undos];return i.sequenceExecute(C,t).result?(n.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:C}),!0):!1}},Ar={type:i.CommandType.COMMAND,id:"sheet.command.remove-worksheet-merge",handler:(s,e)=>{var N;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=(e==null?void 0:e.ranges)||((N=t.getCurrentSelections())==null?void 0:N.map(W=>W.range));if(!(a!=null&&a.length))return!1;const l=P(r);if(!l)return!1;const{subUnitId:u,unitId:d,worksheet:c}=l,m={unitId:d,subUnitId:u,ranges:a},R=c.getConfig().mergeData.filter(W=>a.some(V=>i.Rectangle.intersects(V,W)));if(!R.length)return!1;const C=le(s,m),S=t.getCurrentSelections();if(!(S!=null&&S.length))return!1;const v=i.Tools.deepClone(S),I=i.Tools.deepClone(S),M=I[I.length-1],{startRow:p,startColumn:w}=M.range;M.primary={startRow:p,startColumn:w,endRow:p,endColumn:w,actualRow:p,actualColumn:w,isMerged:!1,isMergedMainCell:!1};const y=iu(c,R),b={unitId:d,subUnitId:u,cellValue:y.redoParams.getMatrix()},T={unitId:d,subUnitId:u,cellValue:y.undoParams.getMatrix()},U=[{id:G.id,params:C},{id:F.id,params:b},{id:q.id,params:{selections:I}}],k=[{id:j.id,params:C},{id:F.id,params:T},{id:q.id,params:{selections:v}}];return i.sequenceExecute(U,n)?(o.pushUndoRedo({unitID:d,undoMutations:k,redoMutations:U}),!0):!1}};function iu(s,e){const t=new i.ObjectMatrix,n=new i.ObjectMatrix;return e.forEach(o=>{const{startRow:r,startColumn:a,endColumn:l,endRow:u}=o,d=s.getCellMatrix().getValue(r,a);if(d!=null&&d.s)for(let c=r;c<=u;c++)for(let m=a;m<=l;m++)(c!==r||m!==a)&&(t.setValue(c,m,{s:d.s}),n.setValue(c,m,null))}),{redoParams:t,undoParams:n}}class nt{constructor(){f(this,"_borderInfo",{type:i.BorderType.ALL,color:"#000000",style:i.BorderStyleTypes.THIN,activeBorderType:!1});f(this,"_borderInfo$",new O.BehaviorSubject(this._borderInfo));f(this,"borderInfo$",this._borderInfo$.asObservable())}dispose(){this._borderInfo$.complete()}setType(e){this._borderInfo.type=e,this.setActiveBorderType(!0),this._refresh()}setColor(e){this._borderInfo.color=e,this._refresh()}setStyle(e){this._borderInfo.style=e,this._refresh()}setActiveBorderType(e){this._borderInfo.activeBorderType=e}getBorderInfo(){return this._borderInfo}_refresh(){this._borderInfo$.next(this._borderInfo)}}function pn(s,e){const{startRow:t,startColumn:n,endRow:o,endColumn:r}=s;for(let a=t;a<=o;a++)for(let l=n;l<=r;l++)e(a,l)}const As=(s,e,t,n)=>{const{mr:o,worksheet:r}=s;e.startRow<0||e.startColumn<0||pn(e,(a,l)=>{var c,m;const u=r.getMergedCell(a,l);let d=t;if(u&&(t.bc_tr||t.ml_tr||t.bl_tr||t.tl_mr||t.tl_bc||t.tl_br)){if(n){const h=i.Tools.deepClone((c=o.getValue(u.startRow,u.startColumn))==null?void 0:c.s);d=h!=null&&h.bd?Object.assign(h.bd,t):t}o.setValue(u.startRow,u.startColumn,{s:{bd:d}})}else{if(n){const h=i.Tools.deepClone((m=o.getValue(a,l))==null?void 0:m.s);d=h!=null&&h.bd?Object.assign(h.bd,t):t}o.setValue(a,l,{s:{bd:d}})}})},au=s=>{const e={startRow:s.startRow-1,startColumn:s.startColumn,endRow:s.startRow-1,endColumn:s.endColumn},t={startRow:s.startRow,startColumn:s.startColumn-1,endRow:s.endRow,endColumn:s.startColumn-1},n={startRow:s.endRow+1,startColumn:s.startColumn,endRow:s.endRow+1,endColumn:s.endColumn},o={startRow:s.startRow,startColumn:s.endColumn+1,endRow:s.endRow,endColumn:s.endColumn+1},r={startRow:s.startRow,startColumn:s.startColumn,endRow:s.startRow,endColumn:s.endColumn},a={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.startColumn},l={startRow:s.endRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn},u={startRow:s.startRow,startColumn:s.endColumn,endRow:s.endRow,endColumn:s.endColumn};return{topRangeOut:e,leftRangeOut:t,bottomRangeOut:n,rightRangeOut:o,topRange:r,leftRange:a,bottomRange:l,rightRange:u}};function lu(s,e,t){const{style:n,color:o,type:r}=s.getBorderInfo(),a=r===i.BorderType.TOP||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,l=r===i.BorderType.LEFT||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,u=r===i.BorderType.BOTTOM||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,d=r===i.BorderType.RIGHT||r===i.BorderType.ALL||r===i.BorderType.OUTSIDE,c=r===i.BorderType.VERTICAL||r===i.BorderType.ALL||r===i.BorderType.INSIDE,m=r===i.BorderType.HORIZONTAL||r===i.BorderType.ALL||r===i.BorderType.INSIDE,h=r.indexOf("tlbr")>-1,R=r.indexOf("tlbc")>-1,C=r.indexOf("tlmr")>-1,S=r.indexOf("bltr")>-1,v=r.indexOf("mltr")>-1,I=r.indexOf("bctr")>-1,M=t[0],{topRangeOut:p,leftRangeOut:w,bottomRangeOut:y,rightRangeOut:b,topRange:T,leftRange:U,bottomRange:k,rightRange:E}=au(M),N=new i.ObjectMatrix,{worksheet:W,unitId:V,subUnitId:$}=e;return{worksheet:W,unitId:V,subUnitId:$,style:n,color:o,type:r,top:a,left:l,right:d,bottom:u,vertical:c,horizontal:m,tl_br:h,tl_bc:R,tl_mr:C,bl_tr:S,ml_tr:v,bc_tr:I,topRangeOut:p,leftRangeOut:w,bottomRangeOut:y,rightRangeOut:b,topRange:T,leftRange:U,bottomRange:k,rightRange:E,range:M,mr:N,borderStyle:{s:n,cl:{rgb:o}}}}const uu=s=>{const{range:e,mr:t,borderStyle:n,vertical:o,horizontal:r,worksheet:a}=s;o&&pn(e,(l,u)=>{var c,m,h;const d=a.getMergedCell(l,u);if(d){const R=(c=t.getValue(d.startRow,d.startColumn))==null?void 0:c.s;d.startColumn!==e.startColumn&&t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{l:i.Tools.deepClone(n)}):{l:i.Tools.deepClone(n)}}})}else{if(u!==e.endColumn){const R=(m=t.getValue(l,u))==null?void 0:m.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{r:i.Tools.deepClone(n)}):{r:i.Tools.deepClone(n)}}})}if(u!==e.startColumn){const R=(h=t.getValue(l,u))==null?void 0:h.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{l:i.Tools.deepClone(n)}):{l:i.Tools.deepClone(n)}}})}}}),r&&pn(e,(l,u)=>{var c,m,h;const d=a.getMergedCell(l,u);if(d){const R=(c=t.getValue(d.startRow,d.startColumn))==null?void 0:c.s;d.startRow!==e.startRow&&t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{t:i.Tools.deepClone(n)}):{t:i.Tools.deepClone(n)}}})}else{if(l!==e.endRow){const R=(m=t.getValue(l,u))==null?void 0:m.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{b:i.Tools.deepClone(n)}):{b:i.Tools.deepClone(n)}}})}if(l!==e.startRow){const R=(h=t.getValue(l,u))==null?void 0:h.s;t.setValue(l,u,{s:{bd:R!=null&&R.bd?Object.assign(R.bd,{t:i.Tools.deepClone(n)}):{t:i.Tools.deepClone(n)}}})}}})};function du(s){const{borderStyle:e,tl_br:t,tl_bc:n,tl_mr:o,bl_tr:r,ml_tr:a,bc_tr:l}=s,u=(d,c,m)=>{As(s,d,c,m)};t&&u(s.range,{tl_br:i.Tools.deepClone(e)},!0),n&&u(s.range,{tl_bc:i.Tools.deepClone(e)},!0),o&&u(s.range,{tl_mr:i.Tools.deepClone(e)},!0),r&&u(s.range,{bl_tr:i.Tools.deepClone(e)},!0),a&&u(s.range,{ml_tr:i.Tools.deepClone(e)},!0),l&&u(s.range,{bc_tr:i.Tools.deepClone(e)},!0)}const cu=s=>{const{top:e,left:t,right:n,bottom:o,borderStyle:r,bottomRange:a,topRange:l,leftRange:u,rightRange:d,bottomRangeOut:c,topRangeOut:m,leftRangeOut:h,rightRangeOut:R}=s,C=(S,v,I)=>{As(s,S,v,I)};e&&(C(m,{b:null}),C(l,{t:i.Tools.deepClone(r)},!0)),o&&(C(c,{t:null}),C(a,{b:i.Tools.deepClone(r)},!0)),t&&(C(h,{r:null}),C(u,{l:i.Tools.deepClone(r)},!0)),n&&(C(R,{l:null}),C(d,{r:i.Tools.deepClone(r)},!0))},mu=s=>{const{range:e,worksheet:t,mr:n,top:o,bottom:r,left:a,right:l,vertical:u,horizontal:d,tl_br:c,tl_bc:m,tl_mr:h,bl_tr:R,ml_tr:C,bc_tr:S,topRange:v,bottomRange:I,leftRange:M,rightRange:p,topRangeOut:w,bottomRangeOut:y,leftRangeOut:b,rightRangeOut:T}=s,U=(k,E,N)=>{As(s,k,E,N)};!o&&!r&&!a&&!l&&!u&&!d&&!c&&!m&&!h&&!R&&!C&&!S&&(pn(e,(k,E)=>{var W,V,$,L,Y,z,K,oe;const N=t.getMergedCell(k,E);if(N){if(N.endColumn!==e.endColumn){const B=(W=n.getValue(N.startRow,N.startColumn))==null?void 0:W.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{r:null}):{r:null}}})}if(N.startColumn!==e.startColumn){const B=(V=n.getValue(N.startRow,N.startColumn))==null?void 0:V.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{l:null}):{l:null}}})}if(N.endRow!==e.endRow){const B=($=n.getValue(N.startRow,N.startColumn))==null?void 0:$.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{b:null}):{b:null}}})}if(N.startRow!==e.startRow){const B=(L=n.getValue(N.startRow,N.startColumn))==null?void 0:L.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{t:null}):{t:null}}})}}else{if(E!==e.endColumn){const B=(Y=n.getValue(k,E))==null?void 0:Y.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{r:null}):{r:null}}})}if(E!==e.startColumn){const B=(z=n.getValue(k,E))==null?void 0:z.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{l:null}):{l:null}}})}if(k!==e.endRow){const B=(K=n.getValue(k,E))==null?void 0:K.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{b:null}):{b:null}}})}if(k!==e.startRow){const B=(oe=n.getValue(k,E))==null?void 0:oe.s;n.setValue(k,E,{s:{bd:B!=null&&B.bd?Object.assign(B.bd,{t:null}):{t:null}}})}}}),U(w,{b:null}),U(v,{t:null},!0),U(y,{t:null}),U(I,{b:null},!0),U(b,{r:null}),U(M,{l:null},!0),U(T,{l:null}),U(p,{r:null},!0),U(e,{tl_br:null},!0),U(e,{tl_bc:null},!0),U(e,{tl_mr:null},!0),U(e,{bl_tr:null},!0),U(e,{ml_tr:null},!0),U(e,{bc_tr:null},!0))},bt={id:"sheet.command.set-border",type:i.CommandType.COMMAND,handler:(s,e)=>{var I;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=s.get(g.SheetsSelectionsService),a=s.get(nt),l=P(o,e);if(!l)return!1;const u=(e==null?void 0:e.ranges)||((I=r.getCurrentSelections())==null?void 0:I.map(M=>M.range));if(!(u!=null&&u.length))return!1;const{activeBorderType:d}=a.getBorderInfo();if(!d)return!1;const c=lu(a,l,u);uu(c),cu(c),du(c),mu(c);const{unitId:m,subUnitId:h,mr:R}=c,C={unitId:m,subUnitId:h,cellValue:R.getData()},S=ce(s,C);return t.syncExecuteCommand(F.id,C)?(n.pushUndoRedo({unitID:m,undoMutations:[{id:F.id,params:S}],redoMutations:[{id:F.id,params:C}]}),!0):!1}},Wr={id:"sheet.command.set-border-position",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e.value)return!1;const t=s.get(i.ICommandService);return s.get(nt).setType(e.value),t.syncExecuteCommand(bt.id)}},Vr={id:"sheet.command.set-border-style",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService);return s.get(nt).setStyle(e.value),t.syncExecuteCommand(bt.id)}},$r={id:"sheet.command.set-border-color",type:i.CommandType.COMMAND,handler:(s,e)=>{const t=s.get(i.ICommandService);return s.get(nt).setColor(e.value),t.syncExecuteCommand(bt.id)}},Lr={id:"sheet.command.set-border-basic",type:i.CommandType.COMMAND,handler:(s,e)=>{const{unitId:t,subUnitId:n,value:o,ranges:r}=e,{type:a,color:l,style:u}=o,d=s.get(i.ICommandService),c=s.get(nt);return c.setType(a),l&&c.setColor(l),c.setStyle(u),d.syncExecuteCommand(bt.id,{unitId:t,subUnitId:n,ranges:r})}},Hr={type:i.CommandType.COMMAND,id:"sheet.command.set-col-data",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{columnData:a}=e,{unitId:l,subUnitId:u,worksheet:d}=r,c={subUnitId:u,unitId:l,columnData:a},m=mo(c,d);return t.syncExecuteCommand(at.id,c)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:at.id,params:m}],redoMutations:[{id:at.id,params:c}]}),!0):!1}},Et={type:i.CommandType.COMMAND,id:"sheet.command.set-col-visible-on-cols",handler:(s,e)=>{var I,M;const{unitId:t,subUnitId:n,ranges:o}=e,r=s.get(g.SheetInterceptorService),a=s.get(i.ICommandService),l=s.get(i.IUniverInstanceService),u=P(l,{unitId:t,subUnitId:n});if(!u)return!1;const{worksheet:d}=u,c={unitId:t,subUnitId:n,ranges:o},m={unitId:t,subUnitId:n,reveal:!0,selections:o.map(p=>({range:p,primary:se(p,d),style:null}))},h=ga(s,c),R={unitId:t,subUnitId:n,selections:Br(o).map(p=>({range:p,primary:se(p,d),style:null}))},C=i.sequenceExecute([{id:ut.id,params:c},{id:q.id,params:m}],a),S=r.onCommandExecute({id:Et.id,params:e}),v=i.sequenceExecute([...S.redos],a);if(C.result&&v.result){const p=r.afterCommandExecute({id:Et.id,params:e});return i.sequenceExecute(p.redos,a),s.get(i.IUndoRedoService).pushUndoRedo({unitID:t,undoMutations:[{id:lt.id,params:h},{id:q.id,params:R},...(I=S.undos)!=null?I:[],...p.undos],redoMutations:[...(M=S.preRedos)!=null?M:[],{id:ut.id,params:c},{id:q.id,params:m},...S.redos,...p.redos]}),!0}return!0}},Ws={type:i.CommandType.COMMAND,id:"sheet.command.set-selected-cols-visible",handler:s=>{var d;const e=s.get(g.SheetsSelectionsService),t=s.get(i.ICommandService),n=(d=e.getCurrentSelections())==null?void 0:d.map(c=>c.range).filter(c=>c.rangeType===i.RANGE_TYPE.COLUMN);if(!(n!=null&&n.length))return!1;const o=P(s.get(i.IUniverInstanceService));if(!o)return!1;const{worksheet:r,unitId:a,subUnitId:l}=o,u=n.map(c=>r.getHiddenCols(c.startColumn,c.endColumn)).flat();return t.executeCommand(Et.id,{unitId:a,subUnitId:l,ranges:u})}},wn={type:i.CommandType.COMMAND,id:"sheet.command.set-col-hidden",handler:(s,e)=>{var M,p,w,y;const t=s.get(g.SheetsSelectionsService),n=s.get(g.SheetInterceptorService),o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService);let a=(M=e==null?void 0:e.ranges)!=null&&M.length?e.ranges:(p=t.getCurrentSelections())==null?void 0:p.map(b=>b.range).filter(b=>b.rangeType===i.RANGE_TYPE.COLUMN);if(!(a!=null&&a.length))return!1;const l=P(o,e);if(!l)return!1;const{worksheet:u,unitId:d,subUnitId:c}=l;a=hu(l.worksheet,a);const m={unitId:d,subUnitId:c,ranges:a},h={unitId:d,subUnitId:c,selections:Br(a).map(b=>({range:b,primary:se(b,u),style:null}))},R=ha(s,m),C={unitId:d,subUnitId:c,reveal:!0,selections:a.map(b=>({range:b,primary:se(b,u),style:null}))},S=i.sequenceExecute([{id:lt.id,params:m},{id:q.id,params:h}],r),v=n.onCommandExecute({id:wn.id,params:m}),I=i.sequenceExecute([...v.redos],r);if(S.result&&I.result){const b=n.afterCommandExecute({id:wn.id,params:m});return i.sequenceExecute(b.redos,r),s.get(i.IUndoRedoService).pushUndoRedo({unitID:d,undoMutations:[{id:ut.id,params:R},{id:q.id,params:C},...(w=v.undos)!=null?w:[],...b.undos],redoMutations:[...(y=v.preRedos)!=null?y:[],{id:lt.id,params:m},{id:q.id,params:h},...v.redos,...b.redos]}),!0}return!1}};function hu(s,e){const t=s.getRowCount()-1,n=s.getHiddenCols(),o=[];return e.forEach(r=>{const a=n.filter(l=>l.startColumn>=r.startColumn&&l.endColumn<=r.endColumn);if(a.length){let l=r.startColumn;a.forEach(u=>{u.startColumn>l&&(o.push({startColumn:l,endColumn:u.startColumn-1,startRow:0,endRow:t}),l=u.endColumn+1)}),l<=r.endColumn&&o.push({startColumn:l,endColumn:r.endColumn,startRow:0,endRow:t})}else o.push(r)}),o}function Br(s){return gu(s).map(t=>{const n=t.startColumn===0?t.endColumn+1:t.startColumn-1;return{...t,startColumn:n,endColumn:n}})}function gu(s){const e=[];let t;return s.sort((n,o)=>n.startColumn-o.startColumn).forEach(n=>{if(!t){t=n;return}t.endColumn===n.startColumn-1?t.endColumn=n.endColumn:(e.push(t),t=n)}),e.push(t),e}const Vs={id:"sheet.command.set-defined-name",type:i.CommandType.COMMAND,handler:(s,e)=>{var m,h;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService);if(!e)return!1;const r={...e},a=J.SetDefinedNameMutationFactory(s,e),l=o.onCommandExecute({id:Vs.id,params:e}),u=[...(m=l.preRedos)!=null?m:[],{id:J.RemoveDefinedNameMutation.id,params:a},{id:J.SetDefinedNameMutation.id,params:r},...l.redos],d=[...(h=l.preUndos)!=null?h:[],{id:J.RemoveDefinedNameMutation.id,params:r},{id:J.SetDefinedNameMutation.id,params:a},...l.undos];return i.sequenceExecute(u,t)?(n.pushUndoRedo({unitID:e.unitId,undoMutations:d.filter(Boolean),redoMutations:u.filter(Boolean)}),!0):!1}},$s=(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(o==null)throw new Error("worksheet is null error!");const a=o.getConfig().freeze;return{unitId:e.unitId,subUnitId:e.subUnitId,...a}},Ne={id:"sheet.mutation.set-frozen",type:i.CommandType.MUTATION,handler:(s,e)=>{const n=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(n==null)throw new Error("universheet is null error!");const o=n.getSheetBySheetId(e.subUnitId);if(!o)return!1;const r=o.getConfig(),{startRow:a,startColumn:l,ySplit:u,xSplit:d}=e;return r.freeze={startRow:a,startColumn:l,ySplit:u,xSplit:d},!0}},Fr={type:i.CommandType.COMMAND,id:"sheet.command.set-frozen",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,{unitId:e.unitId,subUnitId:e.subUnitId});if(!r)return!1;const{unitId:a,subUnitId:l,worksheet:u}=r,{startColumn:d,startRow:c,xSplit:m,ySplit:h}=e;if(c>=u.getRowCount()||d>=u.getColumnCount()||m>=u.getColumnCount()||h>=u.getRowCount())return!1;const R={unitId:a,subUnitId:l,...e},C=$s(s,R);return t.syncExecuteCommand(Ne.id,R)?(n.pushUndoRedo({unitID:a,undoMutations:[{id:Ne.id,params:C}],redoMutations:[{id:Ne.id,params:R}]}),!0):!1}},jr={type:i.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUniverInstanceService),o=s.get(i.IUndoRedoService),r=P(n,{unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId});if(!r)return!1;const{unitId:a,subUnitId:l}=r,u={unitId:a,subUnitId:l,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},d=$s(s,u);return t.syncExecuteCommand(Ne.id,u)&&o.pushUndoRedo({unitID:a,undoMutations:[{id:Ne.id,params:d}],redoMutations:[{id:Ne.id,params:u}]}),!0}},Gr={type:i.CommandType.COMMAND,id:"sheet.command.set-gridlines-color",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a}=r,l=a.getConfig().gridlinesColor;if(l===(e==null?void 0:e.color))return!1;const{unitId:u,subUnitId:d}=r,c={color:e==null?void 0:e.color,unitId:u,subUnitId:d},m={color:l,unitId:u,subUnitId:d};return t.syncExecuteCommand(dt.id,c)?(n.pushUndoRedo({unitID:u,undoMutations:[{id:dt.id,params:m}],redoMutations:[{id:dt.id,params:c}]}),!0):!1}},Q={id:"sheet.mutation.set-range-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rule:o,ruleId:r}=e;return s.get(X).setRule(t,n,r,o),!0}},Ru=(s,e)=>{const{unitId:t,subUnitId:n,ruleId:o}=e,a=s.get(X).getRule(t,n,o);return a?{id:Q.id,params:{...e,rule:a}}:null},st={id:"sheet.mutation.set-worksheet-protection",type:i.CommandType.MUTATION,handler:(s,e)=>{const{unitId:t,subUnitId:n,rule:o}=e;return s.get(ke).setRule(t,n,o),!0}},zr={type:i.CommandType.COMMAND,id:"sheet.command.set-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(X),{rule:r,oldRule:a}=e,{unitId:l,subUnitId:u}=r,d=[],c=[];return(a==null?void 0:a.unitType)===r.unitType?r.unitType===D.Worksheet?(d.push({id:st.id,params:{unitId:l,subUnitId:u,rule:r}}),c.push({id:st.id,params:{unitId:l,subUnitId:u,rule:a}})):(d.push({id:Q.id,params:{unitId:l,subUnitId:u,rule:r,ruleId:r.id}}),c.push({id:Q.id,params:{unitId:l,subUnitId:u,ruleId:a.id,rule:a}})):(a&&(a.unitType===D.Worksheet?(d.push({id:tt.id,params:{unitId:l,subUnitId:u}}),c.push({id:Fe.id,params:{unitId:l,rule:a,subUnitId:a.subUnitId}})):a.unitType===D.SelectRange&&(d.push({id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:[a.id]}}),c.push({id:Ce.id,params:{unitId:l,subUnitId:u,rules:[a]}}))),r.unitType===D.Worksheet?(d.push({id:Fe.id,params:{unitId:l,rule:r,subUnitId:r.subUnitId}}),c.unshift({id:tt.id,params:{unitId:l,subUnitId:u}})):r.unitType===D.SelectRange&&(r.id=o.createRuleId(l,u),d.push({id:Ce.id,params:{unitId:l,subUnitId:u,rules:[r]}}),c.unshift({id:Te.id,params:{unitId:l,subUnitId:u,ruleIds:[r.id]}}))),i.sequenceExecute(d,t)&&n.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:d}),!0}},qr={type:i.CommandType.COMMAND,id:"sheet.command.set-row-data",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o,e);if(!r)return!1;const{rowData:a}=e,{unitId:l,subUnitId:u,worksheet:d}=r,c={subUnitId:u,unitId:l,rowData:a},m=Ro(c,d);return t.syncExecuteCommand(ct.id,c)?(n.pushUndoRedo({unitID:l,undoMutations:[{id:ct.id,params:m}],redoMutations:[{id:ct.id,params:c}]}),!0):!1}},Tt={type:i.CommandType.COMMAND,id:"sheet.command.set-specific-rows-visible",handler:(s,e)=>{var I,M,p;const{unitId:t,subUnitId:n,ranges:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(g.SheetInterceptorService),u=P(s.get(i.IUniverInstanceService),{unitId:t,subUnitId:n});if(!u)return!1;const{worksheet:d}=u,c={unitId:t,subUnitId:n,ranges:o},m={unitId:t,subUnitId:n,reveal:!0,selections:o.map(w=>({range:w,primary:se(w,d),style:null}))},h=ya(s,c),R={unitId:t,subUnitId:n,selections:Yr(o).map(w=>({range:w,primary:se(w,d),style:null}))},C=i.sequenceExecute([{id:Ye.id,params:c},{id:q.id,params:m}],r),S=l.onCommandExecute({id:Tt.id,params:e}),v=i.sequenceExecute([...S.redos],r);if(C.result&&v.result){const w=l.afterCommandExecute({id:Tt.id,params:e});return i.sequenceExecute(w.redos,r),a.pushUndoRedo({unitID:t,undoMutations:[...(I=S.preUndos)!=null?I:[],{id:Ke.id,params:h},{id:q.id,params:R},...(M=S.undos)!=null?M:[],...w.undos],redoMutations:[...(p=S.preRedos)!=null?p:[],{id:Ye.id,params:c},{id:q.id,params:m},...S.redos,...w.redos]}),!0}return!0}},Ls={type:i.CommandType.COMMAND,id:"sheet.command.set-selected-rows-visible",handler:async s=>{var c;const e=s.get(g.SheetsSelectionsService),t=s.get(i.IUniverInstanceService),n=s.get(i.ICommandService),o=(c=e.getCurrentSelections())==null?void 0:c.map(m=>m.range).filter(m=>m.rangeType===i.RANGE_TYPE.ROW);if(!(o!=null&&o.length))return!1;const r=P(t);if(!r)return!1;const{worksheet:a,unitId:l,subUnitId:u}=r,d=o.map(m=>a.getHiddenRows(m.startRow,m.endRow)).flat();return n.executeCommand(Tt.id,{unitId:l,subUnitId:u,ranges:d})}},Mn={type:i.CommandType.COMMAND,id:"sheet.command.set-rows-hidden",handler:(s,e)=>{var M,p,w,y,b,T;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=s.get(g.SheetInterceptorService);let l=(M=e==null?void 0:e.ranges)!=null&&M.length?e.ranges:(p=t.getCurrentSelections())==null?void 0:p.map(U=>U.range).filter(U=>U.rangeType===i.RANGE_TYPE.ROW);if(!(l!=null&&l.length))return!1;const u=P(r,e);if(!u)return!1;l=Cu(u.worksheet,l);const{unitId:d,subUnitId:c,worksheet:m}=u,h={unitId:d,subUnitId:c,ranges:l},R={unitId:d,subUnitId:c,selections:Yr(l).map(U=>({range:U,primary:se(U,m),style:null}))},C=_a(s,h),S={unitId:d,subUnitId:c,reveal:!0,selections:l.map(U=>({range:U,primary:se(U,m),style:null}))},v=a.onCommandExecute({id:Mn.id,params:h});if(i.sequenceExecute([...(w=v.preRedos)!=null?w:[],{id:Ke.id,params:h},{id:q.id,params:R},...v.redos],n).result){const U=a.afterCommandExecute({id:Mn.id,params:h});return i.sequenceExecute(U.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(y=v.preUndos)!=null?y:[],{id:Ye.id,params:C},{id:q.id,params:S},...(b=v.undos)!=null?b:[],...U.undos],redoMutations:[...(T=v.preRedos)!=null?T:[],{id:Ke.id,params:h},{id:q.id,params:R},...v.redos,...U.redos]}),!0}return!0}};function Cu(s,e){const t=s.getMaxColumns()-1,n=s.getHiddenRows(),o=[];return e.forEach(r=>{const a=n.filter(l=>l.startRow>=r.startRow&&l.endRow<=r.endRow);if(a.length){let l=r.startRow;a.forEach(u=>{u.startRow>l&&(o.push({startRow:l,endRow:u.startRow-1,startColumn:0,endColumn:t}),l=u.endRow+1)}),l<=r.endRow&&o.push({startRow:l,endRow:r.endRow,startColumn:0,endColumn:t})}else o.push(r)}),o}function Yr(s){return Su(s).map(t=>{const n=t.startRow===0?t.endRow+1:t.startRow-1;return{...t,startRow:n,endRow:n}})}function Su(s){const e=[];let t;return s.sort((n,o)=>n.startRow-o.startRow).forEach(n=>{if(!t){t=n;return}n.startRow===t.endRow+1?t.endRow=n.endRow:(e.push(t),t=n)}),e.push(t),e}const fu=["ff","fs","tr","tb"],ee={type:i.CommandType.COMMAND,id:"sheet.command.set-style",handler:(s,e)=>{var k;const t=s.get(i.IUniverInstanceService),n=P(t,e);if(!n)return!1;const{unitId:o,subUnitId:r,worksheet:a}=n,{range:l,style:u}=e,d=s.get(i.ICommandService),c=s.get(i.IUndoRedoService),m=s.get(g.SheetsSelectionsService),h=l?[l]:(k=m.getCurrentSelections())==null?void 0:k.map(E=>E.range);if(!(h!=null&&h.length))return!1;const R=new i.ObjectMatrix,C=ll(a);if(i.Tools.isArray(u.value))for(let E=0;E<h.length;E++)C.forOperableEach(h[E],(N,W,V)=>{R.setValue(N,W,{s:{[u.type]:u.value[N-V.startRow][W-V.startColumn]}})});else for(let E=0;E<h.length;E++){const N={s:{[u.type]:u.value}};C.forOperableEach(h[E],(W,V)=>R.setValue(W,V,N))}const S={subUnitId:r,unitId:o,cellValue:R.getMatrix()},v=s.get(g.SheetSkeletonService).getSkeleton(o,r),I=ce(s,S),M=d.syncExecuteCommand(F.id,S),p=s.get(g.SheetInterceptorService);let w=[],y=[];if(fu.includes(e==null?void 0:e.style.type)){const{suitableRanges:E,remainingRanges:N}=Ht(h,v),W=_s(E,a),{undos:V,redos:$}=p.generateMutationsOfAutoHeight({unitId:o,subUnitId:r,ranges:E,autoHeightRanges:E,lazyAutoHeightRanges:N,cellHeights:W});w=V,y=$}const{undos:b,redos:T}=p.onCommandExecute({id:ee.id,params:e}),U=i.sequenceExecute([...T,...y],d);return M&&U.result?(c.pushUndoRedo({unitID:S.unitId,undoMutations:[{id:F.id,params:I},...b,...w],redoMutations:[{id:F.id,params:S},...T,...y]}),!0):!1}},vu={type:i.CommandType.COMMAND,id:"sheet.command.set-bold",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t,{actualRow:o,actualColumn:r}=e.primary,l={style:{type:"bl",value:n.getRange(o,r).getFontWeight()===i.FontWeight.BOLD?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,l)}},Iu={type:i.CommandType.COMMAND,id:"sheet.command.set-italic",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;if(e.primary){const{startRow:a,startColumn:l}=e.primary;o=n.getRange(a,l).getFontStyle()===i.FontItalic.ITALIC}const r={style:{type:"it",value:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},pu={type:i.CommandType.COMMAND,id:"sheet.command.set-underline",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.startRow,e.primary.startColumn).getUnderline().s);const r={style:{type:"ul",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},wu={type:i.CommandType.COMMAND,id:"sheet.command.set-stroke",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.actualRow,e.primary.actualColumn).getStrikeThrough().s);const r={style:{type:"st",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},Mu={type:i.CommandType.COMMAND,id:"sheet.command.set-overline",handler:s=>{const e=s.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!e)return!1;const t=P(s.get(i.IUniverInstanceService));if(!t)return!1;const{worksheet:n}=t;let o=!0;e.primary&&(o=!!n.getRange(e.primary.startRow,e.primary.startColumn).getOverline().s);const r={style:{type:"ol",value:{s:o?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}}};return s.get(i.ICommandService).syncExecuteCommand(ee.id,r)}},yu={type:i.CommandType.COMMAND,id:"sheet.command.set-font-family",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"ff",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},_u={type:i.CommandType.COMMAND,id:"sheet.command.set-font-size",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"fs",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},Kr={type:i.CommandType.COMMAND,id:"sheet.command.set-text-color",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={style:{type:"cl",value:{rgb:e.value}}};return t.syncExecuteCommand(ee.id,n)}},Jr={type:i.CommandType.COMMAND,id:"sheet.command.reset-text-color",handler:s=>{const e=s.get(i.ICommandService),t={style:{type:"cl",value:{rgb:null}}};return e.syncExecuteCommand(ee.id,t)}},xr={type:i.CommandType.COMMAND,id:"sheet.command.set-background-color",handler:(s,e)=>{if(!e||!e.value)return!1;const t=s.get(i.ICommandService),n={style:{type:"bg",value:{rgb:e.value}}};return t.syncExecuteCommand(ee.id,n)}},Xr={type:i.CommandType.COMMAND,id:"sheet.command.reset-background-color",handler:s=>{const e=s.get(i.ICommandService),t={style:{type:"bg",value:{rgb:null}}};return e.syncExecuteCommand(ee.id,t)}},Zr={type:i.CommandType.COMMAND,id:"sheet.command.set-vertical-text-align",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"vt",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},Qr={type:i.CommandType.COMMAND,id:"sheet.command.set-horizontal-text-align",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"ht",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},ei={type:i.CommandType.COMMAND,id:"sheet.command.set-text-wrap",handler:(s,e)=>{if(!e)return!1;const t=s.get(i.ICommandService),n={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"tb",value:e.value}};return t.syncExecuteCommand(ee.id,n)}},ti={type:i.CommandType.COMMAND,id:"sheet.command.set-text-rotation",handler:(s,e)=>{if(!e)return!1;const t=typeof e.value=="number"?{a:e.value}:{a:0,v:i.BooleanNumber.TRUE},n=s.get(i.ICommandService),o={unitId:e.unitId,subUnitId:e.subUnitId,range:e.range,style:{type:"tr",value:t}};return n.syncExecuteCommand(ee.id,o)}},bu=(s,e)=>{const r=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor;return{...i.Tools.deepClone(e),color:r}},jt={id:"sheet.mutation.set-tab-color",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().tabColor=e.color,!0):!1}},ni={type:i.CommandType.COMMAND,id:"sheet.command.set-tab-color",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService));if(!o)return!1;const{unitId:r,subUnitId:a}=o,l={color:e.value,unitId:r,subUnitId:a},u=bu(s,l);return t.syncExecuteCommand(jt.id,l)?(n.pushUndoRedo({unitID:r,undoMutations:[{id:jt.id,params:u}],redoMutations:[{id:jt.id,params:l}]}),!0):!1}},Hs={id:"sheet.mutation.set-workbook-name",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUnit(e.unitId,i.UniverInstanceType.UNIVER_SHEET);return t?(t.setName(e.name),!0):!1}},Bs={type:i.CommandType.COMMAND,id:"sheet.command.set-workbook-name",handler:(s,e)=>{var u;const t=s.get(i.ICommandService),n=s.get(g.SheetInterceptorService);if(!Hn(s.get(i.IUniverInstanceService),e))return!1;const r=n.onCommandExecute({id:Bs.id,params:e}),a={name:e.name,unitId:e.unitId},l=[...(u=r.preRedos)!=null?u:[],{id:Hs.id,params:a},...r.redos];return i.sequenceExecute(l,t).result}},Eu=4,Fs={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-activate",handler:(s,e,t)=>{const n=s.get(i.ICommandService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{unitId:r,subUnitId:a}=o;return new Promise(l=>{setTimeout(()=>{const u=n.syncExecuteCommand(Ct.id,{unitId:r,subUnitId:a},t);l(u)},Eu)})}},Gt={type:i.CommandType.COMMAND,id:"sheet.command.delta-column-width",handler:async(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections();if(!(n!=null&&n.length))return!1;const o=s.get(i.ICommandService),r=s.get(i.IUndoRedoService),a=P(s.get(i.IUniverInstanceService));if(!a)return!1;const{worksheet:l,unitId:u,subUnitId:d}=a,{anchorCol:c,deltaX:m}=e,R=l.getColumnWidth(c)+m,C=n.length===1&&n[0].range.rangeType===i.RANGE_TYPE.ALL,S=n.filter(L=>L.range.rangeType===i.RANGE_TYPE.COLUMN),v=C?i.RANGE_TYPE.ALL:S.some(({range:L})=>{const{startColumn:Y,endColumn:z}=L;return Y<=c&&c<=z})?i.RANGE_TYPE.COLUMN:i.RANGE_TYPE.NORMAL;let I;if(v===i.RANGE_TYPE.ALL){const L=l.getRowCount(),Y=new Array(l.getColumnCount()).fill(void 0).map((z,K)=>({startRow:0,endRow:L-1,startColumn:K,endColumn:K}));I={subUnitId:d,unitId:u,colWidth:R,ranges:Y}}else v===i.RANGE_TYPE.COLUMN?I={subUnitId:d,unitId:u,ranges:S.map(L=>i.Rectangle.clone(L.range)),colWidth:R}:I={subUnitId:d,unitId:u,colWidth:R,ranges:[{startRow:0,endRow:l.getMaxRows()-1,startColumn:c,endColumn:c}]};const M=s.get(g.SheetSkeletonService).getSkeleton(u,d),{suitableRanges:p,remainingRanges:w}=Ht(I.ranges,M);_s(p,l);const y=s.get(g.SheetInterceptorService),{undos:b,redos:T}=y.onCommandExecute({id:Gt.id,params:I}),U=Bn(I,l),k=o.syncExecuteCommand(Ve.id,I),{undos:E,redos:N}=y.generateMutationsOfAutoHeight({unitId:u,subUnitId:d,ranges:p,autoHeightRanges:p,lazyAutoHeightRanges:w}),{undos:W,redos:V}=s.get(g.SheetInterceptorService).afterCommandExecute({id:Gt.id,params:I}),$=i.sequenceExecute([...T,...V,...N],o);return k&&$.result&&r.pushUndoRedo({unitID:u,undoMutations:[{id:Ve.id,params:U},...b,...W,...E],redoMutations:[{id:Ve.id,params:I},...T,...V,...N]}),!0}},zt={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-col-width",handler:(s,e)=>{var y,b,T,U;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(g.SheetInterceptorService),a=(y=e==null?void 0:e.ranges)!=null&&y.length?e.ranges:(b=t.getCurrentSelections())==null?void 0:b.map(k=>k.range);if(!(a!=null&&a.length))return!1;const l=P(s.get(i.IUniverInstanceService),e);if(!l)return!1;const{subUnitId:u,unitId:d,worksheet:c}=l,m=s.get(g.SheetSkeletonService).getSkeleton(d,u),h={subUnitId:u,unitId:d,ranges:a,colWidth:e.value},{suitableRanges:R,remainingRanges:C}=Ht(h.ranges,m);_s(R,c);const S=Bn(h,c),v=n.syncExecuteCommand(Ve.id,h),{undos:I,redos:M}=r.generateMutationsOfAutoHeight({unitId:d,subUnitId:u,ranges:R,autoHeightRanges:R,lazyAutoHeightRanges:C}),p=r.onCommandExecute({id:zt.id,params:h}),w=i.sequenceExecute([...p.redos,...M],n);if(v&&w.result){const k=r.afterCommandExecute({id:zt.id,params:h});return i.sequenceExecute(k.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(T=p.preUndos)!=null?T:[],{id:Ve.id,params:S},...p.undos,...k.undos,...I],redoMutations:[...(U=p.preRedos)!=null?U:[],{id:Ve.id,params:h},...p.redos,...k.redos,...M]}),!0}return!1}};i.CommandType.COMMAND;const si={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-column-count",handler:(s,e)=>{const{unitId:t,subUnitId:n,columnCount:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(i.IUniverInstanceService);if(!P(l,e))return!1;const d={unitId:t,subUnitId:n,columnCount:o},c=Co(s,d);return r.syncExecuteCommand(mt.id,d)?(a.pushUndoRedo({unitID:t,undoMutations:[{id:mt.id,params:c}],redoMutations:[{id:mt.id,params:d}]}),!0):!1}},oi={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-default-style",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{unitId:o}=e,r=So(s,e);return t.syncExecuteCommand(ht.id,e)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:ht.id,params:r}],redoMutations:[{id:ht.id,params:e}]}),!0):!1}},ri=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{hidden:n.isSheetHidden(),unitId:e.unitId,subUnitId:n.getSheetId()}},je={id:"sheet.mutation.set-worksheet-hidden",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(t==null)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().hidden=e.hidden,!0):!1}},ii={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-hidden",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.ErrorService),r=s.get(i.LocaleService),a=P(s.get(i.IUniverInstanceService),e);if(!a)return!1;const{workbook:l,worksheet:u,unitId:d,subUnitId:c}=a;if(u.getConfig().hidden===i.BooleanNumber.TRUE)return!1;const h={unitId:d,subUnitId:c,hidden:i.BooleanNumber.TRUE},R=ri(s,h);return l.getSheets().filter(I=>I.getConfig().hidden===i.BooleanNumber.FALSE).length===1?(o.emit(r.t("sheets.info.hideSheet")),!1):t.syncExecuteCommand(je.id,h)?(n.pushUndoRedo({unitID:d,undoMutations:[{id:je.id,params:R}],redoMutations:[{id:je.id,params:h}]}),!0):!1}},Tu=(s,e)=>{const t=Ie(s.get(i.IUniverInstanceService),e);if(!t)throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!");const{worksheet:n}=t;return{unitId:e.unitId,name:n.getName(),subUnitId:n.getSheetId()}},qt={id:"sheet.mutation.set-worksheet-name",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(t==null)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().name=e.name,!0):!1}},yn={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-name",handler:(s,e)=>{var C,S;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetInterceptorService),r=P(s.get(i.IUniverInstanceService),e);if(!r)return!1;const{unitId:a,subUnitId:l}=r,u={subUnitId:l,name:e.name,unitId:a},d=Tu(s,u),c=o.onCommandExecute({id:yn.id,params:e}),m=[...(C=c.preRedos)!=null?C:[],{id:qt.id,params:u},...c.redos],h=[...(S=c.preUndos)!=null?S:[],{id:qt.id,params:d},...c.undos];return i.sequenceExecute(m,t).result?(n.pushUndoRedo({unitID:a,undoMutations:h,redoMutations:m}),!0):!1}},Uu=(s,e)=>({...i.Tools.deepClone(e),toOrder:e.fromOrder,fromOrder:e.toOrder}),Yt={id:"sheet.mutation.set-worksheet-order",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getConfig();return n.sheetOrder.splice(e.fromOrder,1),n.sheetOrder.splice(e.toOrder,0,e.subUnitId),!0}},js={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-order",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{workbook:r,unitId:a,subUnitId:l}=o,d={fromOrder:r.getConfig().sheetOrder.indexOf(l),toOrder:e.order,unitId:a,subUnitId:l},c=Uu(s,d);return t.syncExecuteCommand(Yt.id,d)?(n.pushUndoRedo({unitID:a,undoMutations:[{id:Yt.id,params:c}],redoMutations:[{id:Yt.id,params:d}]}),!0):!1}};class Ut{constructor(){f(this,"_model",new Map);f(this,"_pointChange",new O.Subject);f(this,"pointChange$",this._pointChange.asObservable())}addRule(e){this._ensureSubUnitMap(e.unitId).set(e.subUnitId,e),this._pointChange.next(e)}deleteRule(e,t){var o,r,a;const n=(o=this._model.get(e))==null?void 0:o.get(t);n&&((a=(r=this._model)==null?void 0:r.get(e))==null||a.delete(t),this._pointChange.next(n))}getRule(e,t){var n,o;return(o=(n=this._model)==null?void 0:n.get(e))==null?void 0:o.get(t)}toObject(){const e={};return[...this._model.keys()].forEach(n=>{const o=this._model.get(n);o!=null&&o.size&&(e[n]=[],[...o.keys()].forEach(a=>{const l=o.get(a);l&&e[n].push(l)}))}),e}fromObject(e){const t=new Map;Object.keys(e).forEach(n=>{const o=e[n];if(o!=null&&o.length){const r=new Map;o.forEach(a=>{r.set(a.subUnitId,a)}),t.set(n,r)}}),this._model=t}deleteUnitModel(e){this._model.delete(e)}_ensureSubUnitMap(e){let t=this._model.get(e);return t||(t=new Map,this._model.set(e,t)),t}getTargetByPermissionId(e,t){const n=this._model.get(e);if(!n)return null;for(const[o,r]of n)if(r.permissionId===t)return[e,o]}}class Gs{constructor(e,t,n){f(this,"type",D.SelectRange);f(this,"subType",_.Delete);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${D.SelectRange}.${_.Delete}.${n}`}}class zs{constructor(e,t,n){f(this,"type",D.SelectRange);f(this,"subType",_.ManageCollaborator);f(this,"status",i.PermissionStatus.INIT);f(this,"value",!0);f(this,"id");f(this,"unitId");f(this,"subUnitId");f(this,"permissionId");this.unitId=e,this.subUnitId=t,this.permissionId=n,this.id=`${D.SelectRange}.${_.ManageCollaborator}.${n}`}}const ue=()=>[ln,Se,zs,Gs],Ge=[_.Edit,_.View,_.ManageCollaborator,_.Delete],Pu=(s="unitId",e="subUnitId",t="permissionId")=>ue().reduce((n,o)=>{const r=new o(s,e,t);return n[r.subType]=r.value,n},{}),Pt=()=>[me,es,Yn,ss,Kn,Qn,dn,xn,Xn,mn,un,Zn,ns,cn,Bo,os,ts,Jn,qo,zo,jo,Fo],ai=[_.Edit,_.Print,_.Comment,_.View,_.Copy,_.Export,_.ManageCollaborator,_.CreateSheet,_.DeleteSheet,_.RenameSheet,_.HideSheet,_.Duplicate,_.Share,_.MoveSheet,_.CopySheet,_.RecoverHistory,_.ViewHistory,_.CreatePermissionObject,_.InsertRow,_.InsertColumn,_.DeleteRow,_.DeleteColumn],de=()=>[fe,Vt,gs,as],ve=()=>[rs,is,ls,us,ds,cs,hs,ms,Rs,Cs,Wt,St,ft,Ss],_n=[_.Copy,_.DeleteColumn,_.DeleteRow,_.EditExtraObject,_.Filter,_.InsertColumn,_.InsertRow,_.InsertHyperlink,_.PivotTable,_.SetCellStyle,_.SetCellValue,_.SetColumnStyle,_.SetRowStyle,_.Sort];var ku=Object.getOwnPropertyDescriptor,Nu=(s,e,t,n)=>{for(var o=n>1?void 0:n?ku(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},ze=(s,e)=>(t,n)=>e(t,n,s);const Ou="SHEET_WORKSHEET_PROTECTION_PLUGIN",Du="SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN";g.WorksheetPermissionService=class extends i.RxDisposable{constructor(e,t,n,o,r,a,l,u){super(),this._permissionService=e,this._univerInstanceService=t,this._injector=n,this._worksheetProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=r,this._resourceManagerService=a,this._rangeProtectionRuleModel=l,this._logService=u,this._init(),this._initRuleChange(),this._initRuleSnapshot(),this._initPointSnapshot()}_init(){const e=t=>{const n=t.getUnitId(),o=r=>{const a=r.getSheetId();[...de(),...ve()].forEach(l=>{const u=new l(n,a);this._permissionService.addPermissionPoint(u)}),this._logService.debug("[WorksheetPermissionService]","Initialization completed",n,a)};t.getSheets().forEach(r=>{o(r)}),t.sheetCreated$.subscribe(r=>{o(r)}),t.sheetDisposed$.subscribe(r=>{const a=r.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(n,a).forEach(u=>{[...ue()].forEach(d=>{const c=new d(n,a,u.permissionId);this._permissionService.deletePermissionPoint(c.id)})}),[...de(),...ve()].forEach(u=>{const d=new u(n,a);this._permissionService.deletePermissionPoint(d.id)})})};this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(t=>{e(t)}),this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).pipe(kt.takeUntil(this.dispose$)).subscribe(e),this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).pipe(kt.takeUntil(this.dispose$)).subscribe(t=>{t.getSheets().forEach(n=>{const o=t.getUnitId(),r=n.getSheetId();de().forEach(a=>{const l=new a(o,r);this._permissionService.deletePermissionPoint(l.id)})})})}_initRuleChange(){this.disposeWithMe(this._worksheetProtectionRuleModel.ruleChange$.subscribe(e=>{switch(e.type){case"add":break;case"delete":{de().forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,!0)});break}case"set":{de().forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,e.rule)});break}}}))}_initRuleSnapshot(){const e=()=>{const n=this._worksheetProtectionRuleModel.toObject();return JSON.stringify(n)},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Ou,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{this._worksheetProtectionRuleModel.fromObject(o),Object.keys(o).forEach(r=>{de().forEach(a=>{const l=new a(n,r);l.value=!1,this._permissionService.addPermissionPoint(l)})}),this._worksheetProtectionRuleModel.changeRuleInitState(!0)},onUnLoad:n=>{const o=this._univerInstanceService.getUnit(n);o&&(o.getSheets().forEach(r=>{const a=r.getSheetId();[...de(),...ve()].forEach(l=>{const u=new l(n,a);this._permissionService.deletePermissionPoint(u.id)})}),Pt().forEach(r=>{const a=new r(n);this._permissionService.deletePermissionPoint(a.id)})),this._worksheetProtectionRuleModel.deleteUnitModel(n)}}))}_initPointSnapshot(){const e=()=>{const n=this._worksheetProtectionPointRuleModel.toObject();return JSON.stringify(n)},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Du,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{this._worksheetProtectionPointRuleModel.fromObject(o),Object.keys(o).forEach(r=>{ve().forEach(a=>{const l=new a(n,r);this._permissionService.addPermissionPoint(l)})})},onUnLoad:n=>{this._worksheetProtectionPointRuleModel.deleteUnitModel(n)}}))}},g.WorksheetPermissionService=Nu([ze(0,i.Inject(i.IPermissionService)),ze(1,i.Inject(i.IUniverInstanceService)),ze(2,i.Inject(i.Injector)),ze(3,i.Inject(ke)),ze(4,i.Inject(Ut)),ze(5,i.Inject(i.IResourceManagerService)),ze(6,i.Inject(X)),ze(7,i.Inject(i.ILogService))],g.WorksheetPermissionService);const bn={id:"sheet.mutation.set-worksheet-permission-points",type:i.CommandType.MUTATION,handler:(s,e)=>{const{rule:t}=e;return s.get(Ut).addRule(t),!0}},li={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-permission-points",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),{rule:n}=e;return t.executeCommand(bn.id,{rule:n,unitId:n.unitId,subUnitId:n.subUnitId}),!0}},ui={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-protection",async handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),{rule:o,permissionId:r,oldRule:a}=e,{unitId:l,subUnitId:u}=o,d={...o,permissionId:r};if(await t.executeCommand(st.id,{unitId:l,subUnitId:u,newRule:d})){const m=[{id:st.id,params:{unitId:l,subUnitId:u,newRule:d}}],h=[{id:st.id,params:{unitId:l,subUnitId:u,rule:a}}];n.pushUndoRedo({unitID:l,redoMutations:m,undoMutations:h})}return!0}},Au=(s,e)=>{const r=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft;return{...i.Tools.deepClone(e),rightToLeft:r}},En={id:"sheet.mutation.set-worksheet-right-to-left",type:i.CommandType.MUTATION,handler:(s,e)=>{const t=s.get(i.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getSheetBySheetId(e.subUnitId);if(!n)return!1;const o=n.getConfig();return o.rightToLeft=e.rightToLeft,!0}},Wu={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-right-to-left",handler:async(s,e)=>{var m;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=P(s.get(i.IUniverInstanceService),e);if(!o)return!1;const{unitId:r,subUnitId:a}=o;let l=i.BooleanNumber.FALSE;e&&(l=(m=e.rightToLeft)!=null?m:i.BooleanNumber.FALSE);const u={rightToLeft:l,unitId:r,subUnitId:a},d=Au(s,u);return t.syncExecuteCommand(En.id,u)?(n.pushUndoRedo({unitID:r,undoMutations:[{id:En.id,params:d}],redoMutations:[{id:En.id,params:u}]}),!0):!1}},di={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-row-count",handler:(s,e)=>{const{unitId:t,subUnitId:n,rowCount:o}=e,r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(i.IUniverInstanceService);if(!P(l,e))return!1;const d={unitId:t,subUnitId:n,rowCount:o},c=fo(s,d);return r.syncExecuteCommand(gt.id,d)?(a.pushUndoRedo({unitID:t,undoMutations:[{id:gt.id,params:c}],redoMutations:[{id:gt.id,params:d}]}),!0):!1}},Kt={type:i.CommandType.COMMAND,id:"sheet.command.delta-row-height",handler:async(s,e)=>{var k,E;const n=s.get(g.SheetsSelectionsService).getCurrentSelections(),o=s.get(g.SheetInterceptorService);if(!(n!=null&&n.length))return!1;const r=P(s.get(i.IUniverInstanceService));if(!r)return!1;const{worksheet:a,subUnitId:l,unitId:u}=r,{anchorRow:d,deltaY:c}=e,h=a.getRowHeight(d)+c,R=n.length===1&&n[0].range.rangeType===i.RANGE_TYPE.ALL,C=n.filter(N=>N.range.rangeType===i.RANGE_TYPE.ROW),S=R?i.RANGE_TYPE.ALL:C.some(({range:N})=>{const{startRow:W,endRow:V}=N;return W<=d&&d<=V})?i.RANGE_TYPE.ROW:i.RANGE_TYPE.NORMAL;let v;if(S===i.RANGE_TYPE.ALL){const N=a.getColumnCount(),W=new Array(a.getRowCount()).fill(void 0).map((V,$)=>({startRow:$,endRow:$,startColumn:0,endColumn:N-1}));v={subUnitId:l,unitId:u,rowHeight:h,ranges:W}}else S===i.RANGE_TYPE.ROW?v={subUnitId:l,unitId:u,ranges:C.map(N=>i.Rectangle.clone(N.range)),rowHeight:h}:v={subUnitId:l,unitId:u,rowHeight:h,ranges:[{startRow:d,endRow:d,startColumn:0,endColumn:a.getMaxColumns()-1}]};const I=vo(v,a),M={unitId:u,subUnitId:l,ranges:v.ranges,autoHeightInfo:i.BooleanNumber.FALSE},p=Fn(M,a),w=s.get(i.ICommandService),y=s.get(i.IUndoRedoService),b=o.onCommandExecute({id:Kt.id,params:v}),T=i.sequenceExecute([{id:Ee.id,params:v},{id:Re.id,params:M}],w),U=i.sequenceExecute([...b.redos],w);if(T.result&&U.result){const N=o.afterCommandExecute({id:Kt.id,params:v});return i.sequenceExecute(N.redos,w),y.pushUndoRedo({unitID:u,undoMutations:[...(k=b.preUndos)!=null?k:[],{id:Ee.id,params:I},{id:Re.id,params:p},...b.undos,...N.undos],redoMutations:[...(E=b.preRedos)!=null?E:[],{id:Ee.id,params:v},{id:Re.id,params:M},...b.redos,...N.redos]}),!0}return!1}},Jt={type:i.CommandType.COMMAND,id:"sheet.command.set-row-height",handler:(s,e)=>{var p,w,y,b;const t=s.get(g.SheetsSelectionsService),n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService),a=s.get(g.SheetInterceptorService),l=(p=e==null?void 0:e.ranges)!=null&&p.length?e.ranges:(w=t.getCurrentSelections())==null?void 0:w.map(T=>T.range);if(!(l!=null&&l.length))return!1;const u=P(r,e);if(!u)return!1;const{unitId:d,subUnitId:c,worksheet:m}=u,h={subUnitId:c,unitId:d,ranges:l,rowHeight:e.value},R=vo(h,m),C={unitId:d,subUnitId:c,ranges:h.ranges,autoHeightInfo:i.BooleanNumber.FALSE},S=Fn(C,m),v=i.sequenceExecute([{id:Ee.id,params:h},{id:Re.id,params:C}],n),I=a.onCommandExecute({id:Jt.id,params:h}),M=i.sequenceExecute([...I.redos],n);if(v.result&&M.result){const T=a.afterCommandExecute({id:Jt.id,params:h});return i.sequenceExecute(T.redos,n),o.pushUndoRedo({unitID:d,undoMutations:[...(y=I.preRedos)!=null?y:[],{id:Ee.id,params:R},{id:Re.id,params:S},...I.undos,...T.undos],redoMutations:[...(b=I.preRedos)!=null?b:[],{id:Ee.id,params:h},{id:Re.id,params:C},...I.redos,...T.redos]}),!0}return!1}},Tn={type:i.CommandType.COMMAND,id:"sheet.command.set-row-is-auto-height",handler:(s,e)=>{var T,U;const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(g.SheetsSelectionsService),r=s.get(i.IUniverInstanceService),a=P(r,e);if(!a)return!1;const{unitId:l,subUnitId:u,worksheet:d}=a,c=(T=e==null?void 0:e.ranges)!=null&&T.length?e.ranges:(U=o.getCurrentSelections())==null?void 0:U.map(k=>k.range);if(!(c!=null&&c.length))return!1;const m={unitId:l,subUnitId:u,ranges:c,autoHeightInfo:i.BooleanNumber.TRUE},h=Fn(m,d),R=t.syncExecuteCommand(Re.id,m),C=s.get(g.SheetSkeletonService).getSkeleton(l,u),{suitableRanges:S,remainingRanges:v}=Ht(m.ranges,C),I=s.get(g.SheetInterceptorService),{undos:M,redos:p}=I.generateMutationsOfAutoHeight({unitId:l,subUnitId:u,ranges:S,autoHeightRanges:S,lazyAutoHeightRanges:v}),{undos:w,redos:y}=I.onCommandExecute({id:Tn.id,params:m}),b=i.sequenceExecute([...y,...p],t);return R&&b.result?(n.pushUndoRedo({unitID:l,undoMutations:[{id:Re.id,params:h},...w,...M],redoMutations:[{id:Re.id,params:m},...y,...p]}),!0):!1}},qs={type:i.CommandType.COMMAND,id:"sheet.command.set-worksheet-show",handler:(s,e)=>{const{unitId:t,subUnitId:n}=e,o=s.get(i.ICommandService),r=s.get(i.IUndoRedoService),a=s.get(i.IUniverInstanceService);if(!P(s.get(i.IUniverInstanceService)))return!1;const u=a.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!u)return!1;const d=u.getSheetBySheetId(n);if(!d||d.getConfig().hidden===i.BooleanNumber.FALSE)return!1;const m={unitId:t,subUnitId:n,hidden:i.BooleanNumber.FALSE},h=ri(s,m),R=o.syncExecuteCommand(je.id,m),C={unitId:t,subUnitId:n},S=o.syncExecuteCommand(Ct.id,C);return R&&S?(r.pushUndoRedo({unitID:t,undoMutations:[{id:je.id,params:h}],redoMutations:[{id:je.id,params:m}]}),!0):!1}},ci={type:i.CommandType.COMMAND,id:"sheet.command.split-text-to-columns",handler:(s,e)=>{const{unitId:t,subUnitId:n,range:o,delimiter:r,customDelimiter:a,treatMultipleDelimitersAsOne:l}=e,u=s.get(i.ICommandService),d=s.get(i.IUniverInstanceService),c=s.get(i.IUndoRedoService);if(!P(s.get(i.IUniverInstanceService)))return!1;const h=d.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!h)return!1;const R=h.getSheetBySheetId(n);if(!R)return!1;const{lastRow:C,rs:S,maxLength:v}=To(R,o,r,a,l),I=R.getColumnCount(),{startColumn:M}=i.Range.transformRange(o,R);if(o.startColumn!==o.endColumn)return!1;const p=[],w=[],y=M+v+1-I;if(y>0){const N={unitId:t,subUnitId:n,range:{startRow:0,endRow:R.getRowCount()-1,startColumn:I-1,endColumn:I-1+y}};p.push({id:ie.id,params:N});const W=Nt(s,N);w.push({id:ne.id,params:W})}const b={startRow:o.startRow,endRow:C,startColumn:M,endColumn:M+v},T=new i.ObjectMatrix;for(let N=b.startRow;N<=b.endRow;N++)for(let W=b.startColumn;W<=b.endColumn;W++){const V=S[N-b.startRow];W===0&&(V==null?void 0:V.length)===1?T.setValue(N,W,R.getCell(N,W)):T.setValue(N,W,{v:(V==null?void 0:V[W-b.startColumn])||null,p:null,f:null,si:null,custom:null})}const U={unitId:t,subUnitId:n,cellValue:T.clone()},k=ce(s,U);return p.push({id:F.id,params:U}),w.unshift({id:F.id,params:k}),i.sequenceExecute(p,u).result?(c.pushUndoRedo({unitID:t,undoMutations:w,redoMutations:p}),!0):!1}},mi={id:"sheet.command.toggle-cell-checkbox",type:i.CommandType.COMMAND,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,row:o,col:r,paragraphIndex:a}=e,u=s.get(i.IUniverInstanceService).getUnit(t,i.UniverInstanceType.UNIVER_SHEET),d=u==null?void 0:u.getSheetBySheetId(n),c=s.get(i.IUndoRedoService),m=s.get(i.ICommandService);if(!d)return!1;const h=d.getCell(o,r);if(!(h!=null&&h.p))return!1;const R=i.Tools.deepClone(h.p),C=new i.DocumentDataModel(R),S=i.BuildTextUtils.paragraph.bullet.toggleChecklist({document:C,paragraphIndex:a});if(!S)return!1;i.TextX.apply(C.getBody(),S.serialize());const v={unitId:t,subUnitId:n,cellValue:{[o]:{[r]:{p:R,t:i.CellValueType.STRING}}}},I={id:F.id,params:v},M=ce(s,v),p={id:F.id,params:M},w=[I],y=[p];return c.pushUndoRedo({redoMutations:w,undoMutations:y,unitID:t}),m.syncExecuteCommand(I.id,I.params)}},hi={type:i.CommandType.COMMAND,id:"sheet.command.toggle-gridlines",handler:(s,e)=>{const t=s.get(i.ICommandService),n=s.get(i.IUndoRedoService),o=s.get(i.IUniverInstanceService),r=P(o);if(!r)return!1;const{worksheet:a}=r,l=a.getConfig().showGridlines;if(l===(e==null?void 0:e.showGridlines))return!1;const{unitId:u,subUnitId:d}=r,c={showGridlines:l===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE,unitId:u,subUnitId:d},m={showGridlines:l,unitId:u,subUnitId:d};return t.syncExecuteCommand(Rt.id,c)?(n.pushUndoRedo({unitID:u,undoMutations:[{id:Rt.id,params:m}],redoMutations:[{id:Rt.id,params:c}]}),!0):!1}},gi={id:"sheet.command.unregister-worksheet-range-theme-style",type:i.CommandType.COMMAND,handler:(s,e)=>{var h;if(!e)return!1;const{unitId:t,themeName:n}=e,o=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),l=s.get(g.SheetRangeThemeModel);if(!P(o))return!1;const d={unitId:t,themeName:n},c={unitId:t,themeName:n,rangeThemeStyleJson:(h=l.getRangeThemeStyle(t,n))==null?void 0:h.toJson()};return r.syncExecuteCommand(_t.id,e)&&a.pushUndoRedo({unitID:t,undoMutations:[{id:_t.id,params:c}],redoMutations:[{id:vn.id,params:d}]}),!0}},Ri={id:"sheet.mutation.add-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{styleJSON:t,unitId:n}=e,o=s.get(g.SheetRangeThemeModel),r=new We(t.name);return r.fromJson(t),o.registerRangeThemeStyle(n,r),!0}},Ci={id:"sheet.mutation.empty",type:i.CommandType.MUTATION,handler:()=>!0},Si={id:"sheet.operation.mark-dirty-row-auto-height",type:i.CommandType.OPERATION,handler:()=>!0},fi={id:"sheet.operation.cancel-mark-dirty-row-auto-height",type:i.CommandType.OPERATION,handler:()=>!0},ot=i.createIdentifier("INumfmtService"),Vu=(s,e)=>{const t=s.get(ot),{values:n,unitId:o,subUnitId:r}=e,a=[],l=[];Object.keys(n).forEach(d=>{n[d].ranges.forEach(m=>{i.Range.foreach(m,(h,R)=>{const C=t.getValue(o,r,h,R);C?a.push({pattern:C.pattern,row:h,col:R}):l.push({startColumn:R,endColumn:R,startRow:h,endRow:h})})})});const u=[];if(a.length){const d=Pn(o,r,a);Object.keys(d.values).forEach(c=>{const m=d.values[c];m.ranges=zn(m.ranges)}),u.push({id:Un.id,params:Pn(o,r,a)})}return l.length&&u.push({id:Ys.id,params:{unitId:o,subUnitId:r,ranges:l}}),u},Un={id:"sheet.mutation.set.numfmt",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{values:t,refMap:n}=e,o=s.get(ot),r=e.unitId,a=e.subUnitId,l=Object.keys(t).reduce((u,d)=>{const c=n[d],m=t[d].ranges;return c&&u.push({...c,ranges:m}),u},[]);return o.setValues(r,a,l),!0}},Ys={id:"sheet.mutation.remove.numfmt",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,ranges:o}=e;return s.get(ot).deleteValues(t,n,o),!0}},$u=(s,e)=>{const t=s.get(ot),{ranges:n,unitId:o,subUnitId:r}=e,a=[];if(n.forEach(u=>{i.Range.foreach(u,(d,c)=>{const m=t.getValue(o,r,d,c);m&&a.push({pattern:m.pattern,row:d,col:c})})}),!a.length)return[];const l=Pn(o,r,a);return Object.keys(l.values).forEach(u=>{const d=l.values[u];d.ranges=zn(d.ranges)}),[{id:Un.id,params:l}]},Pn=(s,e,t)=>{const n=Ya(t,"pattern"),o={},r={},a=Ka();return Object.keys(n).forEach(l=>{const u=n[l],d=a();o[d]={pattern:l},u.forEach(c=>{r[d]||(r[d]={ranges:[]}),r[d].ranges.push(i.cellToRange(c.row,c.col))})}),{unitId:s,subUnitId:e,refMap:o,values:r}},vi={id:"sheet.mutation.remove-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{styleName:t,unitId:n}=e;return s.get(g.SheetRangeThemeModel).unregisterRangeThemeStyle(n,t),!0}},Ii={id:"sheet.mutation.set-range-theme",type:i.CommandType.MUTATION,handler:(s,e)=>{if(!e)return!1;const{unitId:t,styleName:n,style:o}=e,a=s.get(g.SheetRangeThemeModel).getRangeThemeStyle(t,n);return a&&(o.headerRowStyle&&a.setHeaderRowStyle(o.headerRowStyle),o.firstRowStyle&&a.setFirstRowStyle(o.firstRowStyle),o.secondRowStyle&&a.setSecondRowStyle(o.secondRowStyle),o.lastRowStyle&&a.setLastRowStyle(o.lastRowStyle)),!0}},pi={id:"sheet.operation.scroll-to-cell",type:i.CommandType.OPERATION,handler:()=>!0},Lu=(s,e,t)=>{const o=s.get(g.SheetsSelectionsService).getCurrentSelections(),{value:r,selections:a,unitId:l,subUnitId:u}=e;if(o){const c=o[(o==null?void 0:o.length)-1].primary;if(c){const{actualColumn:m,actualRow:h}=c;let{startRow:R,startColumn:C,endRow:S,endColumn:v}=a[a.length-1];if(r===i.Dimension.COLUMNS){const w=t.find(y=>y.startColumn===m&&y.endColumn===m&&h===y.startRow);w&&(v=w.endColumn,R=w.startRow,S=w.endRow)}else if(r===i.Dimension.ROWS){const w=t.find(y=>y.startRow===h&&y.endRow===h&&m===y.startColumn);w&&(S=w.endRow,C=w.startColumn,v=w.endColumn)}const I={startRow:R,startColumn:C,endRow:S,endColumn:v,actualRow:h,actualColumn:m,isMerged:!0,isMergedMainCell:R===h&&C===m},M=o.map((w,y,b)=>({range:w.range,style:null,primary:y===b.length-1?I:null})),p={unitId:l,subUnitId:u,type:te.ONLY_SET,selections:M};return{id:q.id,params:p}}return null}return null},Hu=(s,e)=>{const n=s.get(g.SheetsSelectionsService).getCurrentSelections(),{unitId:o,subUnitId:r}=e;if(n&&n[(n==null?void 0:n.length)-1].primary){const u={unitId:o,subUnitId:r,type:te.ONLY_SET,selections:[...n]};return{id:q.id,params:u}}return null},wi="maxCellsPerSheet",Bu=3e6;var Fu=Object.getOwnPropertyDescriptor,ju=(s,e,t,n)=>{for(var o=n>1?void 0:n?Fu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Mi=(s,e)=>(t,n)=>e(t,n,s);const Gu="SHEET_DEFINED_NAME_PLUGIN",zu="AllDefaultWorkbook";g.DefinedNameDataController=class extends i.Disposable{constructor(e,t){super(),this._definedNamesService=e,this._resourceManagerService=t,this._initialize()}_initialize(){this._initSnapshot()}_initSnapshot(){const e=n=>{const o=this._definedNamesService.getDefinedNameMap(n);return o?JSON.stringify(o):""},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:Gu,businesses:[i.UniverInstanceType.UNIVER_SHEET],toJson:n=>e(n),parseJson:n=>t(n),onUnLoad:n=>{this._definedNamesService.removeUnitDefinedName(n)},onLoad:(n,o)=>{this._definedNamesService.registerDefinedNames(n,o)}}))}},g.DefinedNameDataController=ju([Mi(0,J.IDefinedNamesService),Mi(1,i.IResourceManagerService)],g.DefinedNameDataController);const yi="sheets.config",_i={};var qu=Object.getOwnPropertyDescriptor,Yu=(s,e,t,n)=>{for(var o=n>1?void 0:n?qu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ks=(s,e)=>(t,n)=>e(t,n,s);const Ku=[Ne.id],Ju=[re.id,ie.id,ae.id,ne.id,pe.id,we.id];g.SheetsFreezeSyncController=class extends i.Disposable{constructor(t,n,o){var a,l;super();f(this,"_d",new i.DisposableCollection);f(this,"_enabled",!0);this._univerInstanceService=t,this._commandService=n,this._configService=o;const r=(l=(a=this._configService.getConfig(yi))==null?void 0:a.freezeSync)!=null?l:!0;this.setEnabled(r)}getEnabled(){return this._enabled}setEnabled(t){t?this._d.dispose():this._initOnlyLocalListener(),this._enabled=t}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((t,n)=>{Ku.includes(t.id)&&(n||(n={}),n.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((t,n)=>{if(Ju.includes(t.id)&&(n!=null&&n.fromCollab)){const{id:o,params:r}=t;o===re.id?this._handleInsertRowMutation(r,n):o===ie.id?this._handleInsertColMutation(r,n):o===ae.id?this._handleRemoveRowMutation(r,n):o===ne.id?this._handleRemoveColMutation(r,n):o===pe.id?this._handleMoveRowsMutation(r,n):o===we.id&&this._handleMoveColsMutation(r,n)}}))}_handleInsertRowMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startRow<l.startRow){const u=o.endRow-o.startRow+1,d={...l,startRow:Math.max(1,l.startRow+u),ySplit:Math.max(1,l.ySplit+u)};this._sequenceExecute(r,a,d,n)}}_handleInsertColMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startColumn<l.startColumn){const u=o.endColumn-o.startColumn+1,d={...l,startColumn:Math.max(1,l.startColumn+u),xSplit:Math.max(1,l.xSplit+u)};this._sequenceExecute(r,a,d,n)}}_handleRemoveRowMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startRow<l.startRow){const u=Math.min(l.startRow,o.endRow+1)-o.startRow,d={...l,startRow:Math.max(1,l.startRow-u),ySplit:Math.max(1,l.ySplit-u)};this._sequenceExecute(r,a,d,n)}}_handleRemoveColMutation(t,n){const{range:o,unitId:r,subUnitId:a}=t,l=this._getFreeze(r,a);if(l&&o.startColumn<l.startColumn){const u=Math.min(l.startColumn,o.endColumn+1)-o.startColumn,d={...l,startColumn:Math.max(1,l.startColumn-u),xSplit:Math.max(1,l.xSplit-u)};this._sequenceExecute(r,a,d,n)}}_handleMoveRowsMutation(t,n){const{sourceRange:o,targetRange:r,unitId:a,subUnitId:l}=t,u=this._getFreeze(a,l);if(!u||u.startRow<=0||o.startRow>=u.startRow&&r.startRow>=u.startRow||o.endRow<u.startRow&&r.endRow<u.startRow)return;const d=o.endRow-o.startRow+1,c=Math.max(Math.min(u.startRow,o.endRow+1)-o.startRow,0),m={...u};r.startRow>=u.startRow?(m.startRow=Math.max(1,u.startRow-c),m.ySplit=Math.max(1,u.ySplit-c)):(m.startRow=u.startRow+d-c,m.ySplit=u.ySplit+d-c),this._sequenceExecute(a,l,m,n)}_handleMoveColsMutation(t,n){const{sourceRange:o,targetRange:r,unitId:a,subUnitId:l}=t,u=this._getFreeze(a,l);if(!u||u.startColumn<=0||o.startColumn>=u.startColumn&&r.startColumn>=u.startColumn||o.endColumn<u.startColumn&&r.endColumn<u.startColumn)return;const d=o.endColumn-o.startColumn+1,c=Math.max(Math.min(u.startColumn,o.endColumn+1)-o.startColumn,0),m={...u};r.startColumn>=u.startColumn?(m.startColumn=Math.max(1,u.startColumn-c),m.xSplit=Math.max(1,u.xSplit-c)):(m.startColumn=u.startColumn+d-c,m.xSplit=u.xSplit+d-c),this._sequenceExecute(a,l,m,n)}_getFreeze(t,n){const o=this._univerInstanceService.getUnit(t,i.UniverInstanceType.UNIVER_SHEET);if(!o)return null;const r=o.getSheetBySheetId(n);return r?r.getFreeze():null}_sequenceExecute(t,n,o,r){i.sequenceExecute([{id:Ne.id,params:{...o,unitId:t,subUnitId:n,resetScroll:!1}}],this._commandService,r)}},g.SheetsFreezeSyncController=Yu([Ks(0,i.Inject(i.IUniverInstanceService)),Ks(1,i.ICommandService),Ks(2,i.IConfigService)],g.SheetsFreezeSyncController);var xu=Object.getOwnPropertyDescriptor,Xu=(s,e,t,n)=>{for(var o=n>1?void 0:n?xu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Oe=(s,e)=>(t,n)=>e(t,n,s);g.SheetPermissionCheckController=class extends i.Disposable{constructor(t,n,o,r,a,l,u,d,c,m){super();f(this,"disposableCollection",new i.DisposableCollection);f(this,"_triggerPermissionUIEvent$",new O.Subject);f(this,"triggerPermissionUIEvent$",this._triggerPermissionUIEvent$.asObservable());this._commandService=t,this._univerInstanceService=n,this._permissionService=o,this._selectionManagerService=r,this._rangeProtectionRuleModel=a,this._worksheetProtectionRuleModel=l,this._localeService=u,this._lexerTreeBuilder=d,this._contextService=c,this._definedNamesService=m,this._initialize()}blockExecuteWithoutPermission(t){throw this._triggerPermissionUIEvent$.next(t),new i.CustomCommandExecutionError("have no permission")}_getPermissionCheck(t,n){let o=!0,r="";switch(t){case vt.id:i.isICellData(n.value)&&n.value.f?(o=this._permissionCheckWithFormula(n),r=this._localeService.t("permission.dialog.formulaErr")):o=this._permissionCheckBySetRangeValue({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[Wt,fe]},n);break;case fn.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[Wt,fe]}),r=this._localeService.t("permission.dialog.editErr");break;case Gt.id:case zt.id:o=this.permissionCheckWithoutRange({worksheetTypes:[St]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Kt.id:case Jt.id:case Tn.id:o=this.permissionCheckWithoutRange({worksheetTypes:[ft]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case wt.id:case pt.id:o=this._permissionCheckByMoveCommand(n),r=this._localeService.t("permission.dialog.moveRowColErr");break;case Je.id:o=this._permissionCheckByMoveRangeCommand(n),r=this._localeService.t("permission.dialog.moveRangeErr");break;case js.id:o=this._permissionCheckByWorksheetCommand([me,cn]),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder();break;case yn.id:o=this._permissionCheckByWorksheetCommand([me,mn]),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder();break;case qs.id:{const{unitId:a,subUnitId:l}=n;o=this._permissionCheckByWorksheetCommand([me,un],a,l),r=this._localeService.t("permission.dialog.operatorSheetErr"),o===!1&&this._worksheetProtectionRuleModel.resetOrder()}break;case Et.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,St]},n.ranges),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Tt.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,ft]},n.ranges),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Ws.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,St]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case Ls.id:o=this.permissionCheckWithRanges({workbookTypes:[me],rangeTypes:[Se],worksheetTypes:[fe,ft]}),r=this._localeService.t("permission.dialog.setRowColStyleErr");break;case It.id:o=this._permissionCheckWithInsertRangeMove("right"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case xe.id:o=this._permissionCheckWithInsertRangeMove("bottom"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case He.id:o=this._permissionCheckWithInsertRangeMove("left"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break;case Be.id:o=this._permissionCheckWithInsertRangeMove("top"),r=this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");break}o||this.blockExecuteWithoutPermission(r)}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{this._getPermissionCheck(t.id,t==null?void 0:t.params)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(t.id===qt.id){const o=t.params,{unitId:r=(n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getUnitId(),subUnitId:a}=o;if(!r||!a)return;const l=this._worksheetProtectionRuleModel.getRule(r,a),u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a);l&&this._worksheetProtectionRuleModel.ruleRefresh(l.permissionId),u.length&&this._rangeProtectionRuleModel.ruleRefresh(a)}}))}_permissionCheckWithInsertRangeMove(t){var c;const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=i.Tools.deepClone((c=this._selectionManagerService.getCurrentLastSelection())==null?void 0:c.range);return!(!l||(t==="top"||t==="bottom"?l.endRow=o.getRowCount()-1:(t==="left"||t==="right")&&(l.endColumn=o.getColumnCount()-1),this._rangeProtectionRuleModel.getSubunitRuleList(r,a).map(m=>m.ranges).flat().some(m=>i.Rectangle.getIntersects(l,m))))}_permissionCheckByWorksheetCommand(t,n,o){var c,m;const r=P(this._univerInstanceService,{unitId:n,subUnitId:o});if(!r)return!1;const{unitId:a,subUnitId:l}=r,u=this._worksheetProtectionRuleModel.getRule(a,l),d=this._rangeProtectionRuleModel.getSubunitRuleList(a,l).length>0;return u||d?(m=(c=this._permissionService.getPermissionPoint(new dn(a).id))==null?void 0:c.value)!=null?m:!1:this._permissionService.composePermission(t.map(h=>new h(a).id)).every(h=>h.value)}permissionCheckWithoutRange(t){var R,C,S,v;const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=this._selectionManagerService.getCurrentLastSelection();if(!l)return!0;const u=(C=(R=l==null?void 0:l.primary)==null?void 0:R.actualRow)!=null?C:0,d=(v=(S=l==null?void 0:l.primary)==null?void 0:S.actualColumn)!=null?v:0,{workbookTypes:c,worksheetTypes:m,rangeTypes:h}=t;return!(c&&c.some(M=>{var y,b;const p=new M(r);return((b=(y=this._permissionService.getPermissionPoint(p.id))==null?void 0:y.value)!=null?b:!1)===!1})===!0||m&&m.some(M=>{var y,b;const p=new M(r,a);return((b=(y=this._permissionService.getPermissionPoint(p.id))==null?void 0:y.value)!=null?b:!1)===!1})===!0||h&&h.some(M=>{var T,U,k,E,N;const p=(U=(T=o.getCell(u,d))==null?void 0:T.selectionProtection)==null?void 0:U[0];if(!(p!=null&&p.ruleId))return!1;const w=(k=this._rangeProtectionRuleModel.getRule(r,a,p.ruleId))==null?void 0:k.permissionId;if(!w)return!1;const y=new M(r,a,w);return((N=(E=this._permissionService.getPermissionPoint(y.id))==null?void 0:E.value)!=null?N:!1)===!1})===!0)}permissionCheckWithRanges(t,n,o,r){var C;const a=P(this._univerInstanceService);if(!a)return!1;const{workbook:l,worksheet:u}=a;o||(o=l.getUnitId()),r||(r=u.getSheetId());const d=n!=null?n:(C=this._selectionManagerService.getCurrentSelections())==null?void 0:C.map(S=>S.range);if(!d)return!1;const{workbookTypes:c,worksheetTypes:m,rangeTypes:h}=t,R=[];return c&&R.push(...c.map(S=>new S(o).id)),m&&R.push(...m.map(S=>new S(o,r).id)),h&&this._rangeProtectionRuleModel.getSubunitRuleList(o,r).forEach(S=>{d.some(I=>S.ranges.some(M=>i.Rectangle.intersects(M,I)))&&R.push(...h.map(I=>new I(o,r,S.permissionId).id))}),R.length?this._permissionService.composePermission(R).every(S=>S.value):!0}_permissionCheckByMoveCommand(t){const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=t.toRange;l.endRow===o.getRowCount()-1?l.endColumn=l.startColumn:l.endRow=l.startRow;const u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a).reduce((d,c)=>[...d,...c.ranges],[]).filter(d=>i.Rectangle.intersects(d,l));return u.length>0?!1:(u.forEach(d=>{var c,m;for(let h=d.startRow;h<=d.endRow;h++)for(let R=d.startColumn;R<=d.endColumn;R++){const C=(m=(c=o.getCell(h,R))==null?void 0:c.selectionProtection)==null?void 0:m[0];if((C==null?void 0:C[_.Edit])===!1)return!1}}),!0)}_permissionCheckByMoveRangeCommand(t){const n=P(this._univerInstanceService);if(!n)return!1;const{worksheet:o,unitId:r,subUnitId:a}=n,l=t.toRange,u=this._rangeProtectionRuleModel.getSubunitRuleList(r,a).reduce((d,c)=>[...d,...c.ranges],[]).filter(d=>i.Rectangle.intersects(d,l));return u.length>0?!1:(u.forEach(d=>{var c,m;for(let h=d.startRow;h<=d.endRow;h++)for(let R=d.startColumn;R<=d.endColumn;R++){const C=(m=(c=o.getCell(h,R))==null?void 0:c.selectionProtection)==null?void 0:m[0];if((C==null?void 0:C[_.Edit])===!1)return!1}}),!0)}_permissionCheckBySetRangeValue(t,n){let o=[];n.range?o=[n.range]:o=[new i.ObjectMatrix(n.value).getDataRange()];const{unitId:r,subUnitId:a}=n;return this.permissionCheckWithRanges(t,o,r,a)}_permissionCheckWithFormula(t){var a,l,u,d,c;const n=t.value,o=t.range,r=n.f;if(r){const m=r.substring(1),h=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),R=(a=t.unitId)!=null?a:h.getUnitId(),C=this._definedNamesService.getValueByName(R,m);if(C){let S=C.formulaOrRefString;S.startsWith(J.operatorToken.EQUALS)&&(S=S.slice(1));const v=S.split(",");for(let I=0;I<v.length;I++){const M=v[I],p=J.deserializeRangeWithSheet(M);if(p.sheetName){const w=h.getSheetBySheetName(p.sheetName);if(!w)return!0;const{startRow:y,endRow:b,startColumn:T,endColumn:U}=p.range;for(let k=y;k<=b;k++)for(let E=T;E<=U;E++){const N=(u=(l=w.getCell(k,E))==null?void 0:l.selectionProtection)==null?void 0:u[0];if((N==null?void 0:N[_.View])===!1)return!1}}}return!0}else{const S=this._lexerTreeBuilder.sequenceNodesBuilder(r);if(!S)return!0;for(let v=0;v<S.length;v++){const I=S[v];if(typeof I=="string"||I.nodeType!==J.sequenceNodeType.REFERENCE)continue;const{token:M}=I,p=J.deserializeRangeWithSheetWithCache(M),w=p.unitId?this._univerInstanceService.getUnit(p.unitId):this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!w)return!0;let y=p.sheetName?w.getSheetBySheetName(p.sheetName):w.getActiveSheet();const b=w.getUnitId();if(p.sheetName){if(y=w.getSheetBySheetName(p.sheetName),!y)return!0;const N=y==null?void 0:y.getSheetId();if(!this._permissionService.getPermissionPoint(new Vt(b,N).id))return!1}if(!y)return!0;const{startRow:T,endRow:U,startColumn:k,endColumn:E}=p.range;for(let N=T;N<=U;N++)for(let W=k;W<=E;W++){const V=(c=(d=y.getCell(N,W))==null?void 0:d.selectionProtection)==null?void 0:c[0];if((V==null?void 0:V[_.View])===!1)return!1}}return!0}}if(o){const m=P(this._univerInstanceService);if(!m)return!1;const h=t.unitId||m.unitId,R=t.subUnitId||m.subUnitId,S=this._rangeProtectionRuleModel.getSubunitRuleList(h,R).filter(I=>I.ranges.some(M=>i.Rectangle.intersects(M,o))).map(I=>new Se(h,R,I.permissionId).id);if(!this._permissionService.composePermission(S).every(I=>I.value))return!1}return!0}},g.SheetPermissionCheckController=Xu([Oe(0,i.ICommandService),Oe(1,i.IUniverInstanceService),Oe(2,i.IPermissionService),Oe(3,i.Inject(g.SheetsSelectionsService)),Oe(4,i.Inject(X)),Oe(5,i.Inject(ke)),Oe(6,i.Inject(i.LocaleService)),Oe(7,i.Inject(J.LexerTreeBuilder)),Oe(8,i.IContextService),Oe(9,J.IDefinedNamesService)],g.SheetPermissionCheckController);var Zu=Object.getOwnPropertyDescriptor,Qu=(s,e,t,n)=>{for(var o=n>1?void 0:n?Zu(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},xt=(s,e)=>(t,n)=>e(t,n,s);g.WorkbookPermissionService=class extends i.Disposable{constructor(t,n,o,r,a){super();f(this,"_unitPermissionInitStateChange",new O.BehaviorSubject(!1));f(this,"unitPermissionInitStateChange$",this._unitPermissionInitStateChange.asObservable());this._permissionService=t,this._univerInstanceService=n,this._rangeProtectionRuleModel=o,this._worksheetProtectionRuleModel=r,this._worksheetProtectionPointModel=a,this._init()}_init(){const t=n=>{const o=n.getUnitId();Pt().forEach(r=>{const a=new r(o);this._permissionService.addPermissionPoint(a)})};this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{t(n)}),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{t(n)})),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{const o=n.getUnitId();n.getSheets().forEach(r=>{const a=r.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(o,a).forEach(u=>{[...ue()].forEach(d=>{const c=new d(o,a,u.permissionId);this._permissionService.deletePermissionPoint(c.id)})}),[...de(),...ve()].forEach(u=>{const d=new u(o,a);this._permissionService.deletePermissionPoint(d.id)})}),Pt().forEach(r=>{const a=new r(o);this._permissionService.deletePermissionPoint(a.id)}),this._rangeProtectionRuleModel.deleteUnitModel(o),this._worksheetProtectionPointModel.deleteUnitModel(o),this._worksheetProtectionRuleModel.deleteUnitModel(o)}))}changeUnitInitState(t){this._unitPermissionInitStateChange.next(t)}},g.WorkbookPermissionService=Qu([xt(0,i.Inject(i.IPermissionService)),xt(1,i.Inject(i.IUniverInstanceService)),xt(2,i.Inject(X)),xt(3,i.Inject(ke)),xt(4,i.Inject(Ut))],g.WorkbookPermissionService);var ed=Object.getOwnPropertyDescriptor,td=(s,e,t,n)=>{for(var o=n>1?void 0:n?ed(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},De=(s,e)=>(t,n)=>e(t,n,s);g.SheetPermissionInitController=class extends i.Disposable{constructor(e,t,n,o,r,a,l,u,d,c){super(),this._univerInstanceService=e,this._permissionService=t,this._authzIoService=n,this._rangeProtectionRuleModel=o,this._worksheetProtectionRuleModel=r,this._userManagerService=a,this._worksheetProtectionPointRuleModel=l,this._workbookPermissionService=u,this._undoRedoService=d,this._commandService=c}initPermission(){this._initRangePermissionFromSnapshot(),this._initRangePermissionChange(),this._initWorksheetPermissionFromSnapshot(),this._initWorksheetPermissionChange(),this._initWorksheetPermissionPointsChange(),this._initWorkbookPermissionFromSnapshot(),this._initUserChange(),this._refreshPermissionByCollaCreate()}refreshRangeProtectPermission(){this._initRangePermissionFromSnapshot()}async _initRangePermissionFromSnapshot(){const e=async t=>{const n=[],o=t.getUnitId(),r=t.getSheets(),a=new Map;if(r.forEach(l=>{const u=l.getSheetId();this._rangeProtectionRuleModel.getSubunitRuleList(o,u).forEach(d=>{a.set(d.permissionId,d),n.push({objectID:d.permissionId,unitID:o,objectType:D.SelectRange,actions:Ge})})}),!n.length){this._rangeProtectionRuleModel.changeRuleInitState(!0);return}this._authzIoService.batchAllowed(n).then(l=>{l.forEach(u=>{const d=a.get(u.objectID);d&&ue().forEach(c=>{const m=new c(o,d.subUnitId,u.objectID),h=m.subType,R=u.actions.find(C=>C.action===h);(R==null?void 0:R.allowed)!==void 0&&this._permissionService.updatePermissionPoint(m.id,R.allowed)})}),this._rangeProtectionRuleModel.changeRuleInitState(!0)})};await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(t=>e(t))),this._rangeProtectionRuleModel.changeRuleInitState(!0)}_initRangePermissionChange(){this.disposeWithMe(this._rangeProtectionRuleModel.ruleChange$.subscribe(e=>{e.type!=="delete"?this._authzIoService.allowed({objectID:e.rule.permissionId,unitID:e.unitId,objectType:D.SelectRange,actions:Ge}).then(t=>{ue().forEach(n=>{if(e.type==="set"){const{rule:u,oldRule:d}=e;if(u.permissionId===(d==null?void 0:d.permissionId))return}const o=e.rule,r=new n(o.unitId,o.subUnitId,o.permissionId),a=r.subType,l=t.find(u=>u.action===a);l&&this._permissionService.updatePermissionPoint(r.id,l.allowed)}),this._rangeProtectionRuleModel.ruleRefresh(e.rule.permissionId)}):this._rangeProtectionRuleModel.getSubunitRuleList(e.unitId,e.subUnitId).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e.unitId,e.subUnitId),[...ve()].forEach(n=>{const o=new n(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(o.id,o.value)}))}))}async initWorkbookPermissionChange(e){var n;const t=e||((n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getUnitId());if(t)return this._authzIoService.allowed({objectID:t,objectType:D.Workbook,unitID:t,actions:ai}).then(o=>{Pt().forEach(r=>{const a=new r(t),l=a.subType,u=o.find(d=>d.action===l);u&&this._permissionService.updatePermissionPoint(a.id,u.allowed)})})}async _initWorkbookPermissionFromSnapshot(){await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(e=>this.initWorkbookPermissionChange(e.getUnitId()))),this._workbookPermissionService.changeUnitInitState(!0)}_initWorksheetPermissionChange(){this.disposeWithMe(this._worksheetProtectionRuleModel.ruleChange$.subscribe(e=>{e.type!=="delete"?this._authzIoService.allowed({objectID:e.rule.permissionId,unitID:e.unitId,objectType:D.Worksheet,actions:Ge}).then(t=>{de().forEach(n=>{const o=new n(e.unitId,e.subUnitId),r=o.subType,a=t.find(l=>l.action===r);a&&this._permissionService.updatePermissionPoint(o.id,a.allowed)}),this._worksheetProtectionRuleModel.ruleRefresh(e.rule.permissionId)}):([...de(),...ve()].forEach(t=>{const n=new t(e.unitId,e.subUnitId);this._permissionService.updatePermissionPoint(n.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e.unitId,e.subUnitId))}))}_initWorksheetPermissionPointsChange(){this.disposeWithMe(this._worksheetProtectionPointRuleModel.pointChange$.subscribe(e=>{this._authzIoService.allowed({objectID:e.permissionId,unitID:e.unitId,objectType:D.Worksheet,actions:_n}).then(t=>{ve().forEach(n=>{const o=new n(e.unitId,e.subUnitId),r=o.subType,a=t.find(l=>l.action===r);a&&this._permissionService.updatePermissionPoint(o.id,a.allowed)})})}))}async _initWorksheetPermissionFromSnapshot(){const e=async t=>{const n=[],o=t.getUnitId(),r=t.getSheets(),a=new Map;if(r.forEach(l=>{const u=l.getSheetId(),d=this._worksheetProtectionRuleModel.getRule(o,u);d&&(a.set(d.permissionId,d),n.push({objectID:d.permissionId,unitID:o,objectType:D.Worksheet,actions:Ge}));const c=this._worksheetProtectionPointRuleModel.getRule(o,u);c&&(a.set(c.permissionId,c),n.push({objectID:c.permissionId,unitID:o,objectType:D.Worksheet,actions:_n}))}),!n.length){this._worksheetProtectionRuleModel.changeRuleInitState(!0);return}this._authzIoService.batchAllowed(n).then(l=>{l.forEach(u=>{const d=a.get(u.objectID);d&&[...de(),...ve()].forEach(c=>{const m=new c(o,d.subUnitId),h=m.subType,R=u.actions.find(C=>C.action===h);(R==null?void 0:R.allowed)!==void 0&&this._permissionService.updatePermissionPoint(m.id,R.allowed)})}),this._worksheetProtectionRuleModel.changeRuleInitState(!0)})};await Promise.all(this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).map(t=>e(t))),this._worksheetProtectionRuleModel.changeRuleInitState(!0)}_initUserChange(){this.disposeWithMe(this._userManagerService.currentUser$.pipe(O.skip(1)).subscribe(()=>{const e=this._permissionService.getAllPermissionPoint();this._permissionService.clearPermissionMap(),this._worksheetProtectionRuleModel.changeRuleInitState(!1),this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const o=n.getUnitId();Pt().forEach(r=>{let a=new r(o);e.has(a.id)&&(a=e.get(a.id)),this._permissionService.addPermissionPoint(a)}),n.getSheets().forEach(r=>{const a=r.getSheetId();[...de(),...ve()].forEach(u=>{let d=new u(o,a);e.has(d.id)&&(d=e.get(d.id)),this._permissionService.addPermissionPoint(d)}),this._rangeProtectionRuleModel.getSubunitRuleList(o,a).forEach(u=>{ue().forEach(d=>{let c=new d(o,a,u.permissionId);e.has(c.id)&&(c=e.get(c.id)),this._permissionService.addPermissionPoint(c)})})}),this._initWorkbookPermissionFromSnapshot(),this._initWorksheetPermissionFromSnapshot(),this._initRangePermissionFromSnapshot()})}))}refreshPermission(e,t){const n=this._worksheetProtectionRuleModel.getTargetByPermissionId(e,t);let o=!1;if(n){const[l,u]=n;this._authzIoService.allowed({objectID:t,unitID:e,objectType:D.Worksheet,actions:Ge}).then(d=>{let c="";de().forEach(m=>{var S;const h=new m(e,u),R=h.subType,C=d.find(v=>v.action===R);C&&(((S=this._permissionService.getPermissionPoint(h.id))==null?void 0:S.value)!==C.allowed&&(o=!0),this._permissionService.updatePermissionPoint(h.id,C.allowed),c+=`${C.action}_${C.allowed}`)}),this._worksheetProtectionRuleModel.ruleRefresh(`${t}_${c}`),o&&this._undoRedoService.clearUndoRedo(e)})}const r=this._worksheetProtectionPointRuleModel.getTargetByPermissionId(e,t);if(r){const[l,u]=r;this._authzIoService.allowed({objectID:t,unitID:e,objectType:D.Worksheet,actions:_n}).then(d=>{ve().forEach(c=>{var C;const m=new c(e,u),h=m.subType,R=d.find(S=>S.action===h);R&&(((C=this._permissionService.getPermissionPoint(m.id))==null?void 0:C.value)!==R.allowed&&(o=!0),this._permissionService.updatePermissionPoint(m.id,R.allowed))}),o&&this._undoRedoService.clearUndoRedo(e)})}const a=this._rangeProtectionRuleModel.getTargetByPermissionId(e,t);if(a){const[l,u]=a;this._authzIoService.allowed({objectID:t,unitID:e,objectType:D.SelectRange,actions:Ge}).then(d=>{let c="";ue().forEach(m=>{var S;const h=new m(e,u,t),R=h.subType,C=d.find(v=>v.action===R);C&&(((S=this._permissionService.getPermissionPoint(h.id))==null?void 0:S.value)!==C.allowed&&(o=!0),this._permissionService.updatePermissionPoint(h.id,C.allowed),c+=`${C.action}_${C.allowed}`)}),this._rangeProtectionRuleModel.ruleRefresh(`${t}_${c}`),o&&this._undoRedoService.clearUndoRedo(e)})}}_refreshPermissionByCollaCreate(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(t!=null&&t.fromCollab&&(e.id===Ce.id||e.id===Fe.id||e.id===bn.id)){const n=e.params;this._undoRedoService.clearUndoRedo(n.unitId)}}))}},g.SheetPermissionInitController=td([De(0,i.IUniverInstanceService),De(1,i.IPermissionService),De(2,i.IAuthzIoService),De(3,i.Inject(X)),De(4,i.Inject(ke)),De(5,i.Inject(i.UserManagerService)),De(6,i.Inject(Ut)),De(7,i.Inject(g.WorkbookPermissionService)),De(8,i.Inject(i.IUndoRedoService)),De(9,i.Inject(i.ICommandService))],g.SheetPermissionInitController);var nd=Object.getOwnPropertyDescriptor,sd=(s,e,t,n)=>{for(var o=n>1?void 0:n?nd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Js=(s,e)=>(t,n)=>e(t,n,s);g.ZebraCrossingCacheController=class extends i.Disposable{constructor(t,n,o){super();f(this,"_zebraCacheUpdateSubject",new O.Subject);this._commandService=t,this._sheetRangeThemeModel=n,this._univerInstanceService=o,this._init()}_init(){this._initializeCommandListener(),this._initTriggerCacheUpdateListener()}updateZebraCrossingCache(t,n){this._zebraCacheUpdateSubject.next({unitId:t,subUnitId:n})}_initializeCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{const{id:n}=t;let o,r;switch(n){case re.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ye.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ke.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case ae.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break;case Ee.id:{const a=t.params;o=a.unitId,r=a.subUnitId}break}o&&r&&(this._sheetRangeThemeModel.refreshSheetRowVisibleFuncSet(o,r),this._sheetRangeThemeModel.refreshZebraCrossingCacheBySheet(o,r))}))}_initTriggerCacheUpdateListener(){this.disposeWithMe(this._zebraCacheUpdateSubject.subscribe(({unitId:t,subUnitId:n})=>{this._sheetRangeThemeModel.refreshSheetRowVisibleFuncSet(t,n),this._sheetRangeThemeModel.refreshZebraCrossingCacheBySheet(t,n)}))}},g.ZebraCrossingCacheController=sd([Js(0,i.Inject(i.ICommandService)),Js(1,i.Inject(g.SheetRangeThemeModel)),Js(2,i.Inject(i.IUniverInstanceService))],g.ZebraCrossingCacheController);var od=Object.getOwnPropertyDescriptor,rd=(s,e,t,n)=>{for(var o=n>1?void 0:n?od(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},bi=(s,e)=>(t,n)=>e(t,n,s);g.RangeProtectionRenderModel=class{constructor(e,t){f(this,"_cache",new i.LRUMap(1e4));this._selectionProtectionRuleModel=e,this._permissionService=t,this._init()}_init(){this._permissionService.permissionPointUpdate$.pipe(kt.filter(e=>e.type===D.SelectRange),kt.filter(e=>ue().some(t=>e instanceof t)),kt.map(e=>e)).subscribe(e=>{const t=this._selectionProtectionRuleModel.getSubunitRuleList(e.unitId,e.subUnitId);for(const n of t)n.permissionId===e.permissionId&&n.ranges.forEach(o=>{i.Range.foreach(o,(r,a)=>{const l=this._createKey(e.unitId,e.subUnitId,r,a);this._cache.delete(l)})})}),this._selectionProtectionRuleModel.ruleChange$.subscribe(e=>{var t;e.rule.ranges.forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=this._createKey(e.unitId,e.subUnitId,o,r);this._cache.delete(a)})}),e.type==="set"&&((t=e.oldRule)==null||t.ranges.forEach(n=>{i.Range.foreach(n,(o,r)=>{const a=this._createKey(e.unitId,e.subUnitId,o,r);this._cache.delete(a)})}))})}_createKey(e,t,n,o){return`${e}_${t}_${n}_${o}`}getCellInfo(e,t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(e,t),a=[];if(!r||!r.length)return a;const l=this._createKey(e,t,n,o),u=this._cache.get(l);if(u)return u;const d=[];for(const c of r)if(c.ranges.some(m=>m.startRow<=n&&m.endRow>=n&&m.startColumn<=o&&m.endColumn>=o)){const m=ue().reduce((h,R)=>{var v;const C=new R(e,t,c.permissionId),S=this._permissionService.getPermissionPoint(C.id);return h[C.subType]=(v=S==null?void 0:S.value)!=null?v:C.value,h},{});d.push({...m,ruleId:c.id,ranges:c.ranges})}return this._cache.set(l,d),d}clear(){this._cache.clear()}},g.RangeProtectionRenderModel=rd([bi(0,i.Inject(X)),bi(1,i.Inject(i.IPermissionService))],g.RangeProtectionRenderModel);var id=Object.getOwnPropertyDescriptor,ad=(s,e,t,n)=>{for(var o=n>1?void 0:n?id(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},xs=(s,e)=>(t,n)=>e(t,n,s);g.RangeProtectionCache=class extends i.Disposable{constructor(t,n,o){super();f(this,"_cellRuleCache",new Map);f(this,"_permissionIdCache",new Map);f(this,"_cellInfoCache",new Map);f(this,"_rowInfoCache",new Map);f(this,"_colInfoCache",new Map);this._ruleModel=t,this._permissionService=n,this._univerInstanceService=o,this._initUpdateCellRuleCache(),this._initUpdateCellInfoCache(),this._initUpdateRowColInfoCache(),this._initCache()}_initCache(){this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(t=>{t.getSheets().forEach(n=>{const o=t.getUnitId(),r=n.getSheetId();this.reBuildCache(o,r)})})}_initUpdateCellInfoCache(){this._permissionService.permissionPointUpdate$.pipe(O.filter(t=>t.type===D.SelectRange),O.map(t=>t)).subscribe(t=>{const{subUnitId:n,unitId:o,permissionId:r}=t,a=this._permissionIdCache.get(r);if(!a)return;const l=this._ruleModel.getRule(o,n,a);if(!l)return;const u=this._ensureCellInfoMap(o,n);l.ranges.forEach(d=>{const{startRow:c,endRow:m,startColumn:h,endColumn:R}=d;for(let C=c;C<=m;C++)for(let S=h;S<=R;S++)u.delete(`${C}-${S}`)})}),this._ruleModel.ruleChange$.subscribe(t=>{var a;const{unitId:n,subUnitId:o}=t,r=this._ensureCellInfoMap(n,o);t.rule.ranges.forEach(l=>{i.Range.foreach(l,(u,d)=>{r.delete(`${u}-${d}`)})}),t.type==="set"&&((a=t.oldRule)==null||a.ranges.forEach(l=>{i.Range.foreach(l,(u,d)=>{this._cellInfoCache.delete(`${u}-${d}`)})}))})}_initUpdateCellRuleCache(){this._ruleModel.ruleChange$.subscribe(t=>{const{type:n}=t;n==="add"?this._addCellRuleCache(t):n==="delete"?this._deleteCellRuleCache(t):(this._deleteCellRuleCache({...t,rule:t.oldRule}),this._addCellRuleCache(t))})}_ensureRuleMap(t,n){let o=this._cellRuleCache.get(t);o||(o=new Map,this._cellRuleCache.set(t,o));let r=o.get(n);return r||(r=new Map,o.set(n,r)),r}_ensureCellInfoMap(t,n){let o=this._cellInfoCache.get(t);o||(o=new Map,this._cellInfoCache.set(t,o));let r=o.get(n);return r||(r=new Map,o.set(n,r)),r}_ensureRowColInfoMap(t,n,o){let r=o==="row"?this._rowInfoCache.get(t):this._colInfoCache.get(t);r||(r=new Map,o==="row"?this._rowInfoCache.set(t,r):this._colInfoCache.set(t,r));let a=r.get(n);return a||(a=new Map,r.set(n,a)),a}_addCellRuleCache(t){const{subUnitId:n,unitId:o,rule:r}=t,a=this._ensureRuleMap(o,n);r.ranges.forEach(l=>{const{startRow:u,endRow:d,startColumn:c,endColumn:m}=l;for(let h=u;h<=d;h++)for(let R=c;R<=m;R++)a.set(`${h}-${R}`,r.id)}),this._permissionIdCache.set(r.permissionId,r.id)}_deleteCellRuleCache(t){const{subUnitId:n,unitId:o,rule:r}=t,a=this._ensureRuleMap(o,n),l=this._ensureCellInfoMap(o,n);r.ranges.forEach(u=>{const{startRow:d,endRow:c,startColumn:m,endColumn:h}=u;for(let R=d;R<=c;R++)for(let C=m;C<=h;C++)a.delete(`${R}-${C}`),l.delete(`${R}-${C}`)}),this._permissionIdCache.delete(r.permissionId)}_getSelectionActions(t,n,o){var c,m,h,R,C,S,v,I,M,p,w,y;const r=(h=(m=this._permissionService.getPermissionPoint((c=new Se(t,n,o.permissionId))==null?void 0:c.id))==null?void 0:m.value)!=null?h:!0,a=(S=(C=this._permissionService.getPermissionPoint((R=new ln(t,n,o.permissionId))==null?void 0:R.id))==null?void 0:C.value)!=null?S:!0,l=(M=(I=this._permissionService.getPermissionPoint((v=new zs(t,n,o.permissionId))==null?void 0:v.id))==null?void 0:I.value)!=null?M:!1,u=(y=(w=this._permissionService.getPermissionPoint((p=new Gs(t,n,o.permissionId))==null?void 0:p.id))==null?void 0:w.value)!=null?y:!1;return{[_.Edit]:r,[_.View]:a,[_.ManageCollaborator]:l,[_.Delete]:u}}reBuildCache(t,n){const o=this._ensureRuleMap(t,n),r=this._ensureCellInfoMap(t,n);o.clear(),r.clear();const a=this._ensureRowColInfoMap(t,n,"row"),l=this._ensureRowColInfoMap(t,n,"col");a.clear(),l.clear(),this._ruleModel.getSubunitRuleList(t,n).forEach(u=>{const d=this._getSelectionActions(t,n,u),c={...d,ruleId:u.id,ranges:u.ranges};u.ranges.forEach(m=>{const{startRow:h,endRow:R,startColumn:C,endColumn:S}=m;for(let v=h;v<=R;v++){const I=a.get(`${v}`);I?I.set(u.id,d):a.set(`${v}`,new Map([[u.id,d]]));for(let M=C;M<=S;M++){o.set(`${v}-${M}`,u.id),r.set(`${v}-${M}`,c);const p=l.get(`${M}`);p?p.set(u.id,d):l.set(`${M}`,new Map([[u.id,d]]))}}}),this._permissionIdCache.set(u.permissionId,u.id)})}getRowPermissionInfo(t,n,o,r){var u;const a=(u=this._rowInfoCache.get(t))==null?void 0:u.get(n);if(!a)return!0;const l=a.get(`${o}`);return l?r.every(d=>{for(const c of l.values())if(c[d]===!1)return!1;return!0}):!0}getColPermissionInfo(t,n,o,r){var u;const a=(u=this._colInfoCache.get(t))==null?void 0:u.get(n);if(!a)return!0;const l=a.get(`${o}`);return l?r.every(d=>{for(const c of l.values())if(c[d]===!1)return!1;return!0}):!0}_initUpdateRowColInfoCache(){this._permissionService.permissionPointUpdate$.pipe(O.filter(t=>t.type===D.SelectRange),O.map(t=>t)).subscribe({next:t=>{const{subUnitId:n,unitId:o,permissionId:r}=t,a=this._permissionIdCache.get(r);if(!a)return;const l=this._ruleModel.getRule(o,n,a);if(!l)return;const u=this._ensureRowColInfoMap(o,n,"row"),d=this._ensureRowColInfoMap(o,n,"col"),c=this._getSelectionActions(o,n,l);l.ranges.forEach(m=>{const{startRow:h,endRow:R,startColumn:C,endColumn:S}=m;for(let v=h;v<=R;v++){const I=u.get(`${v}`);I?I.set(a,c):u.set(`${v}`,new Map([[a,c]]));for(let M=C;M<=S;M++){const p=d.get(`${M}`);p?p.set(a,c):d.set(`${M}`,new Map([[a,c]]))}}})}}),this._ruleModel.ruleChange$.subscribe(t=>{if(t.type==="delete"){const{unitId:n,subUnitId:o,rule:r}=t,a=this._ensureRowColInfoMap(n,o,"row"),l=this._ensureRowColInfoMap(n,o,"col");r.ranges.forEach(u=>{const{startRow:d,endRow:c,startColumn:m,endColumn:h}=u;for(let R=d;R<=c;R++){const C=a.get(`${R}`);C==null||C.delete(r.id);for(let S=m;S<=h;S++){const v=l.get(`${S}`);v==null||v.delete(r.id)}}})}})}getCellInfo(t,n,o,r){var c,m;const a=this._ensureCellInfoMap(t,n),l=a.get(`${o}-${r}`);if(l)return l;const u=(m=(c=this._cellRuleCache.get(t))==null?void 0:c.get(n))==null?void 0:m.get(`${o}-${r}`);if(!u)return;const d=this._ruleModel.getRule(t,n,u);if(d){const R={...this._getSelectionActions(t,n,d),ruleId:u,ranges:d.ranges};return a.set(`${o}-${r}`,R),R}}deleteUnit(t){this._cellRuleCache.delete(t),this._cellInfoCache.delete(t),this._rowInfoCache.delete(t),this._colInfoCache.delete(t);const n=this._univerInstanceService.getUnit(t);n==null||n.getSheets().forEach(o=>{const r=o.getSheetId();this._ruleModel.getSubunitRuleList(t,r).forEach(a=>{this._permissionIdCache.delete(a.permissionId)})})}},g.RangeProtectionCache=ad([xs(0,i.Inject(X)),xs(1,i.Inject(i.IPermissionService)),xs(2,i.Inject(i.IUniverInstanceService))],g.RangeProtectionCache);const Ei="ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY";var ld=Object.getOwnPropertyDescriptor,ud=(s,e,t,n)=>{for(var o=n>1?void 0:n?ld(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Xs=(s,e)=>(t,n)=>e(t,n,s);let kn=class extends i.Disposable{constructor(s,e,t){var o;super(),this._commandService=s,this._configService=e,this._dataSyncPrimaryController=t,[F,ie,re,yt,Le,pe,we,ne,ae,Xe,G,Ys,j,Hs,qt,Un,Ot,Ci,Ke,Ye,Si,fi].forEach(r=>{var a;this._commandService.registerCommand(r),(a=this._dataSyncPrimaryController)==null||a.registerSyncingMutations(r)}),((o=this._configService.getConfig(Ei))!=null?o:!1)||[Tr,sn,fn,on,Os,He,Be,Gt,Kt,nr,tr,sr,or,ws,ye,xe,It,Xo,xo,Qo,Zo,ps,Me,Or,wt,Je,pt,Ms,Lt,ys,$t,In,Rn,Ar,Xr,Jr,xr,Lr,$r,bt,Wr,Vr,wn,lt,ut,zt,Hr,at,Fr,Ne,jr,Qr,vt,Jt,Mn,qr,ct,Ws,Ls,Et,Tt,ee,ni,jt,Kr,ti,ei,Zr,Bs,Fs,Ct,ii,je,yn,js,Yt,jn,Ee,Tn,Re,Ve,di,gt,si,mt,Lo,q,pi,Nr,Ds,Vs,qs,hi,Rt,Gr,dt,li,Fe,st,tt,bn,Oo,zr,Ur,br,Pr,ui,Ce,Te,Q,mi,ht,oi,ci,it,rt,vn,_t,gi,Dr,Er,kr,Ri,Ii,vi].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._configService.setConfig(wi,Bu)}};kn=ud([Xs(0,i.ICommandService),Xs(1,i.IConfigService),Xs(2,i.Optional($i.DataSyncPrimaryController))],kn);var dd=Object.getOwnPropertyDescriptor,cd=(s,e,t,n)=>{for(var o=n>1?void 0:n?dd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ti=(s,e)=>(t,n)=>e(t,n,s);let Nn=class extends i.Disposable{constructor(s,e){super(),this._univerInstanceService=s,this._commandService=e,this._initialize()}_initialize(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id!==J.SetFormulaCalculationResultMutation.id)return;const e=s.params,{unitData:t}=e,n=Object.keys(t),o=[];for(let a=0;a<n.length;a++){const l=n[a],u=t[l];if(u==null)continue;const d=Object.keys(u);for(let c=0;c<d.length;c++){const m=d[c],h=u[m];if(h==null)continue;const R=this._getMergedCellData(l,m,h),C={subUnitId:m,unitId:l,cellValue:R};o.push({id:F.id,params:C})}}return o.every(a=>this._commandService.executeCommand(a.id,a.params,{onlyLocal:!0,fromFormula:!0}))}))}_getMergedCellData(s,e,t){const n=this._univerInstanceService.getUniverSheetInstance(s),o=n==null?void 0:n.getStyles(),r=n==null?void 0:n.getSheetBySheetId(e),a=r==null?void 0:r.getCellMatrix(),l=new i.ObjectMatrix(t);return l.forValue((u,d,c)=>{const m=a==null?void 0:a.getValue(u,d),h=J.handleNumfmtInCell(m,c,o);l.setValue(u,d,h)}),l.getMatrix()}};Nn=cd([Ti(0,i.Inject(i.IUniverInstanceService)),Ti(1,i.ICommandService)],Nn);var md=Object.getOwnPropertyDescriptor,hd=(s,e,t,n)=>{for(var o=n>1?void 0:n?md(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},gd=(s,e)=>(t,n)=>e(t,n,s);let On=class extends i.Disposable{constructor(s){super(),this._sheetInterceptorService=s,this._initialize()}_initialize(){this._initInterceptorCellContent()}_initInterceptorCellContent(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:11,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{var o;if(!s)return t(s);const n=e.workbook.getStyles().getStyleByCell(s);return i.isDefaultFormat((o=n==null?void 0:n.n)==null?void 0:o.pattern)&&(s==null?void 0:s.t)===i.CellValueType.NUMBER&&s.v!==void 0&&s.v!==null&&i.isRealNum(s.v)&&((!s||s===e.rawData)&&(s={...e.rawData}),s.v=J.stripErrorMargin(Number(s.v))),t(s)}}))}};On=hd([gd(0,i.Inject(g.SheetInterceptorService))],On);var Rd=Object.getOwnPropertyDescriptor,Cd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Rd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Dn=(s,e)=>(t,n)=>e(t,n,s);let An=class extends i.Disposable{constructor(s,e,t,n){super(),this._permissionService=s,this._worksheetProtectionRuleModel=e,this._sheetInterceptorService=t,this._rangeProtectionCache=n,this._initViewModelByRangeInterceptor(),this._initViewModelBySheetInterceptor()}_initViewModelByRangeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:999,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{const{unitId:n,subUnitId:o,row:r,col:a}=e,l=this._rangeProtectionCache.getCellInfo(n,o,r,a);if(l){const u=l[_.View]===!1,d=!s||s===e.rawData?{...e.rawData}:s;return d.selectionProtection=[l],u?(delete d.s,delete d.v,delete d.p,d):t(d)}return t(s)}}))}_initViewModelBySheetInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(Ae.CELL_CONTENT,{priority:999,effect:i.InterceptorEffectEnum.Value|i.InterceptorEffectEnum.Style,handler:(s,e,t)=>{var a,l,u,d,c;const{unitId:n,subUnitId:o}=e,r=this._worksheetProtectionRuleModel.getRule(n,o);if(r!=null&&r.permissionId){const m=[{[_.View]:(l=(a=this._permissionService.getPermissionPoint(new Vt(n,o).id))==null?void 0:a.value)!=null?l:!1,[_.Edit]:(d=(u=this._permissionService.getPermissionPoint(new fe(n,o).id))==null?void 0:u.value)!=null?d:!1}],h=!((c=m[0])!=null&&c[_.View]),R=!s||s===e.rawData?{...s}:s;return R.hasWorksheetRule=!0,R.selectionProtection=m,h?(delete R.s,delete R.v,delete R.p,R):t(R)}return t(s)}}))}};An=Cd([Dn(0,i.IPermissionService),Dn(1,i.Inject(ke)),Dn(2,i.Inject(g.SheetInterceptorService)),Dn(3,i.Inject(g.RangeProtectionCache))],An);const Zs=i.createIdentifier("univer.exclusive-range-service");class Ui extends i.Disposable{constructor(){super(...arguments);f(this,"_exclusiveRanges",new Map);f(this,"_exclusiveRangesChange$",new O.Subject);f(this,"exclusiveRangesChange$",this._exclusiveRangesChange$.asObservable())}_ensureUnitMap(t){return this._exclusiveRanges.has(t)||this._exclusiveRanges.set(t,new Map),this._exclusiveRanges.get(t)}_ensureSubunitMap(t,n){const o=this._ensureUnitMap(t);return o.has(n)||o.set(n,new Map),o.get(n)}_ensureFeature(t,n,o){const r=this._ensureSubunitMap(t,n);return r.has(o)||r.set(o,[]),r.get(o)}addExclusiveRange(t,n,o,r){const a=this._ensureFeature(t,n,o);a.push(...r),this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:a.map(l=>l.range)})}getExclusiveRanges(t,n,o){var r,a;return(a=(r=this._exclusiveRanges.get(t))==null?void 0:r.get(n))==null?void 0:a.get(o)}clearExclusiveRanges(t,n,o){const r=this.getExclusiveRanges(t,n,o);this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:(r==null?void 0:r.map(a=>a.range))||[]}),this._ensureFeature(t,n,o),this._exclusiveRanges.get(t).get(n).set(o,[])}clearExclusiveRangesByGroupId(t,n,o,r){const a=this.getExclusiveRanges(t,n,o);this._exclusiveRangesChange$.next({unitId:t,subUnitId:n,ranges:(a==null?void 0:a.map(u=>u.range))||[]});const l=this.getExclusiveRanges(t,n,o);if(l){const u=l.filter(d=>d.groupId!==r);this._exclusiveRanges.get(t).get(n).set(o,u)}}getInterestGroupId(t){const n=[];return t.forEach(o=>{var d;const r=o.range,{unitId:a,sheetId:l}=r;if(!a||!l)return;const u=(d=this._exclusiveRanges.get(a))==null?void 0:d.get(l);if(u)for(const c of u.keys()){const m=u.get(c);if(m){for(const h of m)if(i.Rectangle.intersects(r,h.range)){n.push(c);break}}}}),n}}var Sd=Object.getOwnPropertyDescriptor,fd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Sd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Qs=(s,e)=>(t,n)=>e(t,n,s);g.NumfmtService=class extends i.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._logService=n}getValue(e,t,n,o){const r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)return;const a=r==null?void 0:r.getSheetBySheetId(t);if(!a)return;const l=r.getStyles(),u=a.getCellRaw(n,o);if(u!=null&&u.s){const d=l.get(u.s);if(d!=null&&d.n)return d.n}return null}deleteValues(e,t,n){const o=this._univerInstanceService.getUniverSheetInstance(e);if(!o)return;const r=o==null?void 0:o.getSheetBySheetId(t);if(!r)return;const a=o.getStyles();n.forEach(l=>{i.Range.foreach(l,(u,d)=>{const c=r.getCellRaw(u,d);if(!c)return;const m=c==null?void 0:c.s,R={...m&&a.get(m)||{}};delete R.n;const C=a.setValue(R);c.s=C})})}setValues(e,t,n){const o=this._univerInstanceService.getUniverSheetInstance(e);if(!o)return;const r=o==null?void 0:o.getSheetBySheetId(t);if(!r)return;const a=o.getStyles(),l=r.getCellMatrix();n.forEach(u=>{u.ranges.forEach(d=>{i.Range.foreach(d,(c,m)=>{const h=r.getCellRaw(c,m);if(h){const C={...a.getStyleByCell(h)||{},n:{pattern:u.pattern}},S=a.setValue(C);h.s=S}else{const R={n:{pattern:u.pattern}},C=a.setValue(R);C&&l.setValue(c,m,{s:C})}})})})}},g.NumfmtService=fd([Qs(0,i.IResourceManagerService),Qs(1,i.IUniverInstanceService),Qs(2,i.ILogService)],g.NumfmtService);var vd=Object.getOwnPropertyDescriptor,Id=(s,e,t,n)=>{for(var o=n>1?void 0:n?vd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},qe=(s,e)=>(t,n)=>e(t,n,s);const Pi=[ie.id,re.id,ne.id,ae.id],ki=[pe.id,we.id];g.RangeProtectionRefRangeService=class extends i.Disposable{constructor(t,n,o,r,a,l,u,d){super();f(this,"disposableCollection",new i.DisposableCollection);this._selectionProtectionRuleModel=t,this._univerInstanceService=n,this._commandService=o,this._refRangeService=r,this._selectionProtectionRenderModel=a,this._rangeProtectionCache=l,this._sheetInterceptorService=u,this._rangeProtectionRuleModel=d,this._onRefRangeChange(),this._correctPermissionRange(),this._initReBuildCache(),this._initRemoveSheet()}_onRefRangeChange(){const t=(o,r)=>{const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!a||!(a==null?void 0:a.getSheetBySheetId(r)))return;this.disposableCollection.dispose();const u=c=>this.refRangeHandle(c,o,r);this._selectionProtectionRuleModel.getSubunitRuleList(o,r).reduce((c,m)=>[...c,...m.ranges],[]).forEach(c=>{this.disposableCollection.add(this._refRangeService.registerRefRange(c,u,o,r))})};this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===Fs.id){const r=o.params,a=r.subUnitId,l=r.unitId;if(!a||!l)return;t(l,a)}if(o.id===Q.id||o.id===Ce.id){const r=o.params,a=r.subUnitId,l=r.unitId;if(!a||!l)return;t(l,a)}}));const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(n){const o=n.getActiveSheet();if(!o)return;t(n.getUnitId(),o.getSheetId())}}refRangeHandle(t,n,o){switch(t.id){case pt.id:return this._getRefRangeMutationsByMoveRows(t.params,n,o);case wt.id:return this._getRefRangeMutationsByMoveCols(t.params,n,o);case Me.id:return this._getRefRangeMutationsByInsertRows(t.params,n,o);case ye.id:return this._getRefRangeMutationsByInsertCols(t.params,n,o);case Lt.id:return this._getRefRangeMutationsByDeleteCols(t.params,n,o);case $t.id:return this._getRefRangeMutationsByDeleteRows(t.params,n,o)}return{redos:[],undos:[]}}_getRefRangeMutationsByDeleteCols(t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(l=>l.ranges.some(u=>i.Rectangle.intersects(u,t.range))),a=t.range;if(r.length){const l=[],u=[];return r.forEach(d=>{const c=i.Tools.deepClone(d),m=c.ranges.reduce((h,R)=>{if(i.Rectangle.intersects(R,a)){const C=i.Tools.deepClone(R),{startColumn:S,endColumn:v}=a;if(S<=C.startColumn&&v>=C.endColumn)return h;S>=C.startColumn&&v<=C.endColumn?C.endColumn-=v-S+1:S<C.startColumn?(C.startColumn=S,C.endColumn-=v-S+1):v>C.endColumn&&(C.endColumn=S-1),this._checkIsRightRange(C)&&h.push(C)}return h},[]);c.ranges=m,c.ranges.length?(l.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:d.id}}),u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:d,ruleId:d.id}})):(l.push({id:Te.id,params:{unitId:n,subUnitId:o,ruleIds:[d.id]}}),u.push({id:Ce.id,params:{unitId:n,subUnitId:o,name:"",rules:[d]}}))}),{redos:l,undos:u}}return{undos:[],redos:[]}}_getRefRangeMutationsByDeleteRows(t,n,o){const r=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(l=>l.ranges.some(u=>i.Rectangle.intersects(u,t.range))),a=t.range;if(r.length){const l=[],u=[];return r.forEach(d=>{const c=i.Tools.deepClone(d),m=c.ranges.reduce((h,R)=>{if(i.Rectangle.intersects(R,a)){const C=i.Tools.deepClone(R),{startRow:S,endRow:v}=a;if(S<=C.startRow&&v>=C.endRow)return h;S>=C.startRow&&v<=C.endRow?C.endRow-=v-S+1:S<C.startRow?(C.startRow=S,C.endRow-=v-S+1):v>C.endRow&&(C.endRow=S-1),this._checkIsRightRange(C)&&h.push(C)}return h},[]);c.ranges=m,l.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:d.id}}),u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:d,ruleId:d.id}})}),{redos:l,undos:u}}return{undos:[],redos:[]}}_getRefRangeMutationsByInsertCols(t,n,o){const r=t.range.startColumn,a=t.range.endColumn-t.range.startColumn+1,l=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(u=>u.ranges.some(d=>r>d.startColumn&&r<=d.endColumn));if(l.length){const u=[],d=[];return l.forEach(c=>{const m=i.Tools.deepClone(c);let h=!1;m.ranges.forEach(R=>{r>R.startColumn&&r<=R.endColumn&&(R.endColumn+=a,h=!0)}),h&&(u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:c.id}}),d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:c.id}}))}),{redos:u,undos:d}}return{undos:[],redos:[]}}_getRefRangeMutationsByInsertRows(t,n,o){const r=t.range.startRow,a=t.range.endRow-t.range.startRow+1,l=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(u=>u.ranges.some(d=>r>d.startRow&&r<=d.endRow));if(l.length){const u=[],d=[];return l.forEach(c=>{const m=i.Tools.deepClone(c);let h=!1;m.ranges.forEach(R=>{r>R.startRow&&r<=R.endRow&&(R.endRow+=a,h=!0)}),h&&(u.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:c.id}}),d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:c,ruleId:c.id}}))}),{redos:u,undos:d}}return{undos:[],redos:[]}}_getRefRangeMutationsByMoveRows(t,n,o){const r=t.toRange,a=r.startRow,l=r.endRow-r.startRow+1,u=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(d=>d.ranges.some(c=>a>c.startRow&&a<=c.endRow));if(u.length){const d=[],c=[];return u.forEach(m=>{const h=i.Tools.deepClone(m),C=t.fromRange.startRow;let S=!1;h.ranges.forEach(v=>{a>v.startRow&&a<=v.endRow&&(C<v.startRow&&(v.startRow=v.startRow-l,v.endRow=v.endRow-l),v.endRow+=l,S=!0)}),S&&(d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:h,ruleId:m.id}}),c.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:m.id}}))}),{redos:d,undos:c}}return{undos:[],redos:[]}}_getRefRangeMutationsByMoveCols(t,n,o){const r=t.toRange,a=r.startColumn,l=r.endColumn-r.startColumn+1,u=this._selectionProtectionRuleModel.getSubunitRuleList(n,o).filter(d=>d.ranges.some(c=>a>c.startColumn&&a<=c.endColumn));if(u.length){const d=[],c=[];return u.forEach(m=>{const h=i.Tools.deepClone(m),C=t.fromRange.startColumn;let S=!1;h.ranges.forEach(v=>{a>v.startColumn&&a<=v.endColumn&&(C<v.startColumn&&(v.startColumn=v.startColumn-l,v.endColumn=v.endColumn-l),v.endColumn+=l,S=!0)}),S&&(d.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:h,ruleId:m.id}}),c.push({id:Q.id,params:{unitId:n,subUnitId:o,rule:m,ruleId:m.id}}))}),{redos:d,undos:c}}return{undos:[],redos:[]}}_correctPermissionRange(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(ki.includes(t.id)){if(!t.params)return;const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const{sourceRange:r,targetRange:a}=t.params,l=r.startColumn===a.startColumn&&r.endColumn===a.endColumn,u=l?r.endRow-r.startRow+1:r.endColumn-r.startColumn+1,d=l?r.startRow:r.startColumn,c=l?a.startRow:a.startColumn;this._selectionProtectionRuleModel.getSubunitRuleList(n.getUnitId(),o.getSheetId()).forEach(v=>{v.ranges.forEach(M=>{let{startRow:p,endRow:w,startColumn:y,endColumn:b}=M;i.Rectangle.intersects(M,r)||(l?d<p&&c>w?(p-=u,w-=u):d>w&&c<=p&&(p+=u,w+=u):d<y&&c>b?(y-=u,b-=u):d>b&&c<=y&&(y+=u,b+=u)),this._checkIsRightRange({startRow:p,endRow:w,startColumn:y,endColumn:b})&&(M.startColumn=y,M.endColumn=b,M.startRow=p,M.endRow=w)})}),this.disposableCollection.dispose();const{unitId:h,subUnitId:R}=t.params,C=v=>this.refRangeHandle(v,h,R);this._selectionProtectionRuleModel.getSubunitRuleList(h,R).reduce((v,I)=>[...v,...I.ranges],[]).forEach(v=>{this.disposableCollection.add(this._refRangeService.registerRefRange(v,C,h,R))}),this._selectionProtectionRenderModel.clear()}if(Pi.includes(t.id)){const n=this._univerInstanceService.getUniverSheetInstance(t.params.unitId);if(!n)return;const o=n.getSheetBySheetId(t.params.subUnitId);if(!o)return;const r=t.params;if(!r)return;const{range:a}=r,l=t.id.includes("row"),u=t.id.includes("insert"),d=l?a.startRow:a.startColumn,c=l?a.endRow:a.endColumn,m=c-d+1;this._selectionProtectionRuleModel.getSubunitRuleList(n.getUnitId(),o.getSheetId()).forEach(I=>{I.ranges.forEach(p=>{let{startRow:w,endRow:y,startColumn:b,endColumn:T}=p;u?l?d<=w&&(w+=m,y+=m):d<=b&&(b+=m,T+=m):l?c<w&&(w-=m,y-=m):c<b&&(b-=m,T-=m),this._checkIsRightRange({startRow:w,endRow:y,startColumn:b,endColumn:T})&&(p.startColumn=b,p.endColumn=T,p.startRow=w,p.endRow=y)})}),this.disposableCollection.dispose();const{unitId:R,subUnitId:C}=t.params,S=I=>this.refRangeHandle(I,R,C);this._selectionProtectionRuleModel.getSubunitRuleList(R,C).reduce((I,M)=>[...I,...M.ranges],[]).forEach(I=>{this.disposableCollection.add(this._refRangeService.registerRefRange(I,S,R,C))}),this._selectionProtectionRenderModel.clear()}}))}_checkIsRightRange(t){return t.startRow<=t.endRow&&t.startColumn<=t.endColumn}_initReBuildCache(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(Pi.includes(t.id)||ki.includes(t.id)){const{unitId:n,subUnitId:o}=t.params;this._rangeProtectionCache.reBuildCache(n,o)}}))}_initRemoveSheet(){this._sheetInterceptorService.interceptCommand({getMutations:t=>{const n=[],o=[],r=[],a=[];if(t.id===In.id){const l=t.params,u=[],d=[];this._rangeProtectionRuleModel.getSubunitRuleList(l.unitId,l.subUnitId).forEach(c=>{u.push(c.id),d.push(c)}),u.length&&d.length&&(r.push({id:Te.id,params:{unitId:l.unitId,subUnitId:l.subUnitId,ruleIds:u}}),n.push({id:Ce.id,params:{unitId:l.unitId,subUnitId:l.subUnitId,name:"",rules:d}}))}return{redos:o,undos:n,preRedos:r,preUndos:a}}})}},g.RangeProtectionRefRangeService=Id([qe(0,i.Inject(X)),qe(1,i.Inject(i.IUniverInstanceService)),qe(2,i.ICommandService),qe(3,i.Inject(g.RefRangeService)),qe(4,i.Inject(g.RangeProtectionRenderModel)),qe(5,i.Inject(g.RangeProtectionCache)),qe(6,i.Inject(g.SheetInterceptorService)),qe(7,i.Inject(X))],g.RangeProtectionRefRangeService);var pd=Object.getOwnPropertyDescriptor,wd=(s,e,t,n)=>{for(var o=n>1?void 0:n?pd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Xt=(s,e)=>(t,n)=>e(t,n,s);const Md="SHEET_RANGE_PROTECTION_PLUGIN";g.RangeProtectionService=class extends i.Disposable{constructor(e,t,n,o,r){super(),this._selectionProtectionRuleModel=e,this._permissionService=t,this._resourceManagerService=n,this._selectionProtectionCache=o,this._univerInstanceService=r,this._initSnapshot(),this._initRuleChange()}_initRuleChange(){this.disposeWithMe(this._selectionProtectionRuleModel.ruleChange$.subscribe(e=>{switch(e.type){case"add":{ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.addPermissionPoint(n)});break}case"delete":{ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.deletePermissionPoint(n.id)});break}case"set":{e.oldRule.permissionId!==e.rule.permissionId&&ue().forEach(t=>{const n=new t(e.unitId,e.subUnitId,e.oldRule.permissionId);this._permissionService.deletePermissionPoint(n.id);const o=new t(e.unitId,e.subUnitId,e.rule.permissionId);this._permissionService.addPermissionPoint(o)});break}}}))}_initSnapshot(){const e=n=>{const r=this._selectionProtectionRuleModel.toObject()[n];return r?JSON.stringify(r):""},t=n=>{if(!n)return{};try{return JSON.parse(n)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e,parseJson:t,pluginName:Md,businesses:[an.UNIVER_SHEET],onLoad:(n,o)=>{const r=this._selectionProtectionRuleModel.toObject();r[n]=o,this._selectionProtectionRuleModel.fromObject(r);const a=[];Object.keys(o).forEach(l=>{const u=o[l];this._selectionProtectionRuleModel.getSubunitRuleList(n,l).forEach(d=>{a.push({objectID:d.permissionId,unitID:n,objectType:D.SelectRange,actions:Ge})}),u.forEach(d=>{ue().forEach(c=>{const m=new c(n,l,d.permissionId);m.value=!1,this._permissionService.addPermissionPoint(m)})}),this._selectionProtectionCache.reBuildCache(n,l)})},onUnLoad:n=>{this._selectionProtectionCache.deleteUnit(n)}}))}},g.RangeProtectionService=wd([Xt(0,i.Inject(X)),Xt(1,i.Inject(i.IPermissionService)),Xt(2,i.Inject(i.IResourceManagerService)),Xt(3,i.Inject(g.RangeProtectionCache)),Xt(4,i.Inject(i.IUniverInstanceService))],g.RangeProtectionService);var yd=Object.getOwnPropertyDescriptor,_d=(s,e,t,n)=>{for(var o=n>1?void 0:n?yd(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},bd=(s,e)=>(t,n)=>e(t,n,s);g.SheetRangeThemeService=class extends i.Disposable{constructor(e){super(),this._sheetRangeThemeModel=e}registerRangeTheme(e,t){this._sheetRangeThemeModel.registerRangeThemeStyle(e,t)}removeRangeThemeRule(e,t){this._sheetRangeThemeModel.removeRangeThemeRule(e,t)}getALLRegisterThemes(e){return this._sheetRangeThemeModel.getALLRegisteredTheme(e)}registerRangeThemeStyle(e,t){this._sheetRangeThemeModel.registerRangeThemeRule(e,t)}getAppliedRangeThemeStyle(e){return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(e)}getRegisteredRangeThemes(){return this._sheetRangeThemeModel.getRegisteredRangeThemes()}},g.SheetRangeThemeService=_d([bd(0,i.Inject(g.SheetRangeThemeModel))],g.SheetRangeThemeService);var Ed=Object.defineProperty,Td=Object.getOwnPropertyDescriptor,Ud=(s,e,t)=>e in s?Ed(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Pd=(s,e,t,n)=>{for(var o=n>1?void 0:n?Td(e,t):e,r=s.length-1,a;r>=0;r--)(a=s[r])&&(o=a(o)||o);return o},Ni=(s,e)=>(t,n)=>e(t,n,s),Oi=(s,e,t)=>Ud(s,typeof e!="symbol"?e+"":e,t);const kd="SHEET_PLUGIN";g.UniverSheetsPlugin=class extends i.Plugin{constructor(e=_i,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...o}=i.merge({},_i,this._config);this._configService.setConfig(yi,o),this._initConfig(),this._initDependencies()}_initConfig(){var e,t,n;(e=this._config)!=null&&e.onlyRegisterFormulaRelatedMutations&&this._configService.setConfig(Ei,!0),(t=this._config)!=null&&t.isRowStylePrecedeColumnStyle&&this._configService.setConfig(i.IS_ROW_STYLE_PRECEDE_COLUMN_STYLE,!0),(n=this._config)!=null&&n.autoHeightForMergedCells&&this._configService.setConfig(i.AUTO_HEIGHT_FOR_MERGED_CELLS,!0)}_initDependencies(){var t;const e=[[nt],[g.SheetsSelectionsService],[g.RefRangeService],[g.WorkbookPermissionService],[ot,{useClass:g.NumfmtService}],[g.SheetInterceptorService],[g.SheetRangeThemeService],[g.SheetSkeletonService],[kn],[g.MergeCellController],[On],[g.DefinedNameDataController],[g.ZebraCrossingCacheController],[g.SheetsFreezeSyncController],[g.WorksheetPermissionService],[ke],[Ut],[An],[g.SheetPermissionInitController],[g.SheetPermissionCheckController],[g.SheetRangeThemeModel],[g.RangeProtectionRenderModel],[X],[g.RangeProtectionCache],[g.RangeProtectionRefRangeService],[g.RangeProtectionService],[Zs,{useClass:Ui,deps:[g.SheetsSelectionsService]}]];(t=this._config)!=null&&t.notExecuteFormula||e.push([Nn]),i.registerDependencies(this._injector,i.mergeOverrideWithDependencies(e,this._config.override)),i.touchDependencies(this._injector,[[g.SheetInterceptorService],[g.RangeProtectionService],[Zs],[g.SheetPermissionInitController],[g.SheetsFreezeSyncController]])}onStarting(){i.touchDependencies(this._injector,[[kn],[g.MergeCellController],[g.WorkbookPermissionService],[g.WorksheetPermissionService],[An],[g.SheetSkeletonService]])}onRendered(){i.touchDependencies(this._injector,[[ot]])}onReady(){i.touchDependencies(this._injector,[[Nn],[g.DefinedNameDataController],[g.ZebraCrossingCacheController],[g.SheetRangeThemeModel],[On],[g.RangeProtectionRenderModel],[g.RangeProtectionRefRangeService],[g.RefRangeService],[g.SheetPermissionCheckController]])}},Oi(g.UniverSheetsPlugin,"pluginName",kd),Oi(g.UniverSheetsPlugin,"type",i.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsPlugin=Pd([i.DependentOn(J.UniverFormulaEnginePlugin),Ni(1,i.Inject(i.Injector)),Ni(2,i.IConfigService)],g.UniverSheetsPlugin);const Nd={WorkbookCommentPermission:Yn,WorkbookCopyPermission:Kn,WorkbookCreateProtectPermission:Jn,WorkbookCreateSheetPermission:xn,WorkbookDeleteSheetPermission:Xn,WorkbookDuplicatePermission:Zn,WorkbookEditablePermission:me,WorkbookExportPermission:Qn,WorkbookHideSheetPermission:un,WorkbookHistoryPermission:Go,WorkbookManageCollaboratorPermission:dn,WorkbookMoveSheetPermission:cn,WorkbookPrintPermission:es,WorkbookRecoverHistoryPermission:ts,WorkbookRenameSheetPermission:mn,WorkbookSharePermission:ns,WorkbookViewHistoryPermission:os,WorkbookViewPermission:ss,WorksheetCopyPermission:rs,WorksheetDeleteColumnPermission:is,WorksheetDeleteProtectionPermission:as,WorksheetDeleteRowPermission:ls,WorksheetEditExtraObjectPermission:us,WorksheetEditPermission:fe,WorksheetFilterPermission:ds,WorksheetInsertColumnPermission:cs,WorksheetInsertHyperlinkPermission:ms,WorksheetInsertRowPermission:hs,WorksheetManageCollaboratorPermission:gs,WorksheetPivotTablePermission:Rs,WorksheetSetCellStylePermission:Cs,WorksheetSetCellValuePermission:Wt,WorksheetSetColumnStylePermission:St,WorksheetSetRowStylePermission:ft,WorksheetSortPermission:Ss,WorksheetViewPermission:Vt,RangeProtectionPermissionEditPoint:Se,RangeProtectionPermissionViewPoint:ln},Od=(s,e,t,n)=>{const o=s.get(i.IPermissionService),r=s.get(X),a=o.getPermissionPoint(new me(e).id);if(!(a!=null&&a.value))return!1;const l=o.getPermissionPoint(new fe(e,t).id);if(!(l!=null&&l.value))return!1;const d=r.getSubunitRuleList(e,t).filter(c=>c.ranges.some(m=>n.some(h=>i.Rectangle.intersects(m,h))));return d.length?d.every(c=>{const m=c.permissionId,h=o.getPermissionPoint(new Se(e,t,m).id);return!!(h!=null&&h.value)}):!0},Di=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startRow:l,endRow:u}=a;let d=t.startRow-n,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;for(;!e.getRowVisible(d)||!m;)d--,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;if(d>=l)return{...t,startRow:d,endRow:d};if(r){const h={...t,startRow:u,endRow:u};return Wi(s,e,h,n,o,!1)}},Ai=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startRow:l,endRow:u}=a;let d=t.endRow+n,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;for(;!e.getRowVisible(d)||!m;)d++,c=e.getMergedCell(d,t.startColumn),m=!c||c.startRow===d&&c.startColumn===t.startColumn;if(d<=u)return{...t,startRow:d,endRow:d};if(r){const h={...t,startRow:l,endRow:l};return Vi(s,e,h,n,o,!1)}},Wi=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startColumn:l,endColumn:u}=a;let d=t.startColumn-n,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;for(;!e.getColVisible(d)||!m;)d--,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;if(d>=l)return{...t,startColumn:d,endColumn:d};if(r){const h={...t,startColumn:u,endColumn:u};return Di(s,e,h,n,o,!1)}},Vi=(s,e,t,n=1,o=!0,r=!0)=>{const a=i.Range.transformRange(s,e),{startColumn:l,endColumn:u}=a;let d=t.endColumn+n,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;for(;!e.getColVisible(d)||!m;)d++,c=e.getMergedCell(t.startRow,d),m=!c||c.startRow===t.startRow&&c.startColumn===d;if(d<=u)return{...t,endColumn:d,startColumn:d};if(r){const h={...t,startColumn:l,endColumn:l};return Ai(s,e,h,n,o,!1)}};function Wn(s,e,t){let n=null;return t.getMatrixWithMergedCells(s,e,s,e).forValue((r,a,l)=>(n={actualRow:r,actualColumn:a,startRow:r,startColumn:a,isMerged:l.rowSpan!==void 0||l.colSpan!==void 0,isMergedMainCell:l.rowSpan!==void 0&&l.colSpan!==void 0,endRow:r+(l.rowSpan!==void 0?l.rowSpan-1:0),endColumn:a+(l.colSpan!==void 0?l.colSpan-1:0),rangeType:i.RANGE_TYPE.NORMAL},!1)),n||{actualColumn:e,actualRow:s,startRow:s,startColumn:e,endRow:s,endColumn:e,isMerged:!1,isMergedMainCell:!1,rangeType:i.RANGE_TYPE.NORMAL}}const Dd=(s,e,t,n,o=1)=>{switch(n){case i.Direction.UP:return Di(s,e,t,o);case i.Direction.DOWN:return Ai(s,e,t,o);case i.Direction.LEFT:return Wi(s,e,t,o);case i.Direction.RIGHT:return Vi(s,e,t,o)}},Ad=(s,e,t)=>{let n,o=-1,r;for(let I=0;I<s.length;I++)if(s[I].primary){n=s[I],o=I,r=n.primary;break}if(o===-1)return null;const a=e===i.Direction.LEFT||e===i.Direction.UP,l=a?o-1>=0?o-1:s.length-1:o+1<s.length?o+1:0,u=s[l];if(!n||!r)return null;const d={...r},{startRow:c,startColumn:m,endRow:h,endColumn:R}=n.range,C=a?d.startRow===c&&d.startColumn===m:d.endRow===h&&d.endColumn===R,S=C&&a;if(!i.Rectangle.equals(n.range,d)){const I=C?u.range:Dd(n.range,t,d,e);if(!I)return null;const M=S?Wn(I.endRow,I.endColumn,t):Wn(I.startRow,I.startColumn,t);return{startRow:M.startRow,startColumn:M.startColumn,endRow:M.endRow,endColumn:M.endColumn}}const v=S?Wn(u.range.endRow,u.range.endColumn,t):Wn(u.range.startRow,u.range.startColumn,t);return{startRow:v.startRow,startColumn:v.startColumn,endRow:v.endRow,endColumn:v.endColumn}};g.AFTER_CELL_EDIT=Zt,g.AddMergeRedoSelectionsOperationFactory=Lu,g.AddMergeUndoMutationFactory=ge,g.AddMergeUndoSelectionsOperationFactory=Hu,g.AddRangeProtectionCommand=Oo,g.AddRangeProtectionMutation=Ce,g.AddRangeThemeMutation=Ri,g.AddWorksheetMergeAllCommand=tu,g.AddWorksheetMergeCommand=Ft,g.AddWorksheetMergeHorizontalCommand=su,g.AddWorksheetMergeMutation=j,g.AddWorksheetMergeVerticalCommand=nu,g.AddWorksheetProtectionCommand=br,g.AddWorksheetProtectionMutation=Fe,g.AppendRowCommand=Tr,g.BEFORE_CELL_EDIT=$n,g.BorderStyleManagerService=nt,g.COMMAND_LISTENER_SKELETON_CHANGE=Ea,g.COMMAND_LISTENER_VALUE_CHANGE=Ta,g.CancelFrozenCommand=jr,g.CancelMarkDirtyRowAutoHeightMutation=fi,g.ClearSelectionAllCommand=sn,g.ClearSelectionContentCommand=fn,g.ClearSelectionFormatCommand=on,g.CopySheetCommand=Os,g.DISABLE_NORMAL_SELECTIONS=sl,g.DeleteRangeMoveLeftCommand=He,g.DeleteRangeMoveUpCommand=Be,g.DeleteRangeProtectionCommand=Ur,g.DeleteRangeProtectionMutation=Te,g.DeleteWorksheetProtectionCommand=Pr,g.DeleteWorksheetProtectionMutation=tt,g.DeleteWorksheetRangeThemeStyleCommand=kr,g.DeleteWorksheetRangeThemeStyleMutation=it,g.DeleteWorksheetRangeThemeStyleMutationFactory=ao,g.DeltaColumnWidthCommand=Gt,g.DeltaRowHeightCommand=Kt,g.EditStateEnum=No,g.EffectRefRangId=A,g.EmptyMutation=Ci,g.ExclusiveRangeService=Ui,g.FactoryAddRangeProtectionMutation=Qa,g.FactoryDeleteRangeProtectionMutation=Za,g.FactorySetRangeProtectionMutation=Ru,g.IExclusiveRangeService=Zs,g.INTERCEPTOR_POINT=Ae,g.INumfmtService=ot,g.IRefSelectionsService=Vo,g.InsertColAfterCommand=nr,g.InsertColBeforeCommand=tr,g.InsertColByRangeCommand=ws,g.InsertColCommand=ye,g.InsertColMutation=ie,g.InsertColMutationUndoFactory=Nt,g.InsertDefinedNameCommand=Nr,g.InsertMultiColsLeftCommand=sr,g.InsertMultiColsRightCommand=or,g.InsertMultiRowsAboveCommand=Zo,g.InsertMultiRowsAfterCommand=Qo,g.InsertRangeMoveDownCommand=xe,g.InsertRangeMoveRightCommand=It,g.InsertRowAfterCommand=Xo,g.InsertRowBeforeCommand=xo,g.InsertRowByRangeCommand=ps,g.InsertRowCommand=Me,g.InsertRowMutation=re,g.InsertRowMutationUndoFactory=en,g.InsertSheetCommand=Or,g.InsertSheetMutation=yt,g.InsertSheetUndoMutationFactory=Ns,g.InterceptCellContentPriority=to,g.MAX_CELL_PER_SHEET_KEY=wi,g.MERGE_CELL_INTERCEPTOR_CHECK=_r,g.MarkDirtyRowAutoHeightMutation=Si,g.MoveColsCommand=wt,g.MoveColsMutation=we,g.MoveColsMutationUndoFactory=uo,g.MoveRangeCommand=Je,g.MoveRangeMutation=Le,g.MoveRowsCommand=pt,g.MoveRowsMutation=pe,g.MoveRowsMutationUndoFactory=lo,g.OperatorType=H,g.PermissionPointsDefinitions=Nd,g.REF_SELECTIONS_ENABLED=Ao,g.RangeMergeUtil=$a,g.RangeProtectionPermissionDeleteProtectionPoint=Gs,g.RangeProtectionPermissionEditPoint=Se,g.RangeProtectionPermissionManageCollaPoint=zs,g.RangeProtectionPermissionViewPoint=ln,g.RangeProtectionRuleModel=X,g.RangeThemeStyle=We,g.RegisterWorksheetRangeThemeStyleCommand=Dr,g.RegisterWorksheetRangeThemeStyleMutation=_t,g.RemoveColByRangeCommand=ys,g.RemoveColCommand=Lt,g.RemoveColMutation=ne,g.RemoveDefinedNameCommand=Ds,g.RemoveMergeUndoMutationFactory=le,g.RemoveNumfmtMutation=Ys,g.RemoveRangeThemeMutation=vi,g.RemoveRowByRangeCommand=Ms,g.RemoveRowCommand=$t,g.RemoveRowMutation=ae,g.RemoveSheetCommand=In,g.RemoveSheetMutation=Xe,g.RemoveSheetUndoMutationFactory=rr,g.RemoveWorksheetMergeCommand=Ar,g.RemoveWorksheetMergeMutation=G,g.ReorderRangeCommand=Rn,g.ReorderRangeMutation=Ot,g.ReorderRangeUndoMutationFactory=co,g.ResetBackgroundColorCommand=Xr,g.ResetTextColorCommand=Jr,g.SCOPE_WORKBOOK_VALUE_DEFINED_NAME=zu,g.SELECTIONS_ENABLED=ol,g.SELECTION_CONTROL_BORDER_BUFFER_COLOR=Ha,g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH=La,g.ScrollToCellOperation=pi,g.SelectRangeCommand=Lo,g.SelectionMoveType=te,g.SetBackgroundColorCommand=xr,g.SetBoldCommand=vu,g.SetBorderBasicCommand=Lr,g.SetBorderColorCommand=$r,g.SetBorderCommand=bt,g.SetBorderPositionCommand=Wr,g.SetBorderStyleCommand=Vr,g.SetColDataCommand=Hr,g.SetColDataMutation=at,g.SetColDataMutationFactory=mo,g.SetColHiddenCommand=wn,g.SetColHiddenMutation=lt,g.SetColVisibleMutation=ut,g.SetColWidthCommand=zt,g.SetDefinedNameCommand=Vs,g.SetFontFamilyCommand=yu,g.SetFontSizeCommand=_u,g.SetFrozenCommand=Fr,g.SetFrozenMutation=Ne,g.SetFrozenMutationFactory=$s,g.SetGridlinesColorCommand=Gr,g.SetGridlinesColorMutation=dt,g.SetHorizontalTextAlignCommand=Qr,g.SetItalicCommand=Iu,g.SetNumfmtMutation=Un,g.SetOverlineCommand=Mu,g.SetProtectionCommand=zr,g.SetRangeProtectionMutation=Q,g.SetRangeThemeMutation=Ii,g.SetRangeValuesCommand=vt,g.SetRangeValuesMutation=F,g.SetRangeValuesUndoMutationFactory=ce,g.SetRowDataCommand=qr,g.SetRowDataMutation=ct,g.SetRowDataMutationFactory=Ro,g.SetRowHeightCommand=Jt,g.SetRowHiddenCommand=Mn,g.SetRowHiddenMutation=Ke,g.SetRowVisibleMutation=Ye,g.SetSelectedColsVisibleCommand=Ws,g.SetSelectedRowsVisibleCommand=Ls,g.SetSelectionsOperation=q,g.SetSpecificColsVisibleCommand=Et,g.SetSpecificRowsVisibleCommand=Tt,g.SetStrikeThroughCommand=wu,g.SetStyleCommand=ee,g.SetTabColorCommand=ni,g.SetTabColorMutation=jt,g.SetTextColorCommand=Kr,g.SetTextRotationCommand=ti,g.SetTextWrapCommand=ei,g.SetUnderlineCommand=pu,g.SetVerticalTextAlignCommand=Zr,g.SetWorkbookNameCommand=Bs,g.SetWorkbookNameMutation=Hs,g.SetWorksheetActivateCommand=Fs,g.SetWorksheetActiveOperation=Ct,g.SetWorksheetColWidthMutation=Ve,g.SetWorksheetColWidthMutationFactory=Bn,g.SetWorksheetColumnCountCommand=si,g.SetWorksheetColumnCountMutation=mt,g.SetWorksheetColumnCountUndoMutationFactory=Co,g.SetWorksheetDefaultStyleCommand=oi,g.SetWorksheetDefaultStyleMutation=ht,g.SetWorksheetDefaultStyleMutationFactory=So,g.SetWorksheetHideCommand=ii,g.SetWorksheetHideMutation=je,g.SetWorksheetNameCommand=yn,g.SetWorksheetNameMutation=qt,g.SetWorksheetOrderCommand=js,g.SetWorksheetOrderMutation=Yt,g.SetWorksheetPermissionPointsCommand=li,g.SetWorksheetPermissionPointsMutation=bn,g.SetWorksheetProtectionCommand=ui,g.SetWorksheetProtectionMutation=st,g.SetWorksheetRangeThemeStyleCommand=Er,g.SetWorksheetRangeThemeStyleMutation=rt,g.SetWorksheetRangeThemeStyleMutationFactory=io,g.SetWorksheetRightToLeftCommand=Wu,g.SetWorksheetRightToLeftMutation=En,g.SetWorksheetRowAutoHeightMutation=jn,g.SetWorksheetRowAutoHeightMutationFactory=ba,g.SetWorksheetRowCountCommand=di,g.SetWorksheetRowCountMutation=gt,g.SetWorksheetRowCountUndoMutationFactory=fo,g.SetWorksheetRowHeightMutation=Ee,g.SetWorksheetRowIsAutoHeightCommand=Tn,g.SetWorksheetRowIsAutoHeightMutation=Re,g.SetWorksheetShowCommand=qs,g.SheetSkeletonChangeType=Io,g.SheetValueChangeType=po,g.SplitDelimiterEnum=Eo,g.SplitTextToColumnsCommand=ci,g.ToggleCellCheckboxCommand=mi,g.ToggleGridlinesCommand=hi,g.ToggleGridlinesMutation=Rt,g.UnitAction=_,g.UnitObject=D,g.UnregisterWorksheetRangeThemeStyleCommand=gi,g.UnregisterWorksheetRangeThemeStyleMutation=vn,g.VALIDATE_CELL=Qt,g.ViewStateEnum=ko,g.WorkbookCommentPermission=Yn,g.WorkbookCopyPermission=Kn,g.WorkbookCopySheetPermission=Bo,g.WorkbookCreateProtectPermission=Jn,g.WorkbookCreateSheetPermission=xn,g.WorkbookDeleteColumnPermission=Fo,g.WorkbookDeleteRowPermission=jo,g.WorkbookDeleteSheetPermission=Xn,g.WorkbookDuplicatePermission=Zn,g.WorkbookEditablePermission=me,g.WorkbookExportPermission=Qn,g.WorkbookHideSheetPermission=un,g.WorkbookHistoryPermission=Go,g.WorkbookInsertColumnPermission=zo,g.WorkbookInsertRowPermission=qo,g.WorkbookManageCollaboratorPermission=dn,g.WorkbookMoveSheetPermission=cn,g.WorkbookPrintPermission=es,g.WorkbookRecoverHistoryPermission=ts,g.WorkbookRenameSheetPermission=mn,g.WorkbookSelectionModel=Do,g.WorkbookSharePermission=ns,g.WorkbookViewHistoryPermission=os,g.WorkbookViewPermission=ss,g.WorksheetCopyPermission=rs,g.WorksheetDeleteColumnPermission=is,g.WorksheetDeleteProtectionPermission=as,g.WorksheetDeleteRowPermission=ls,g.WorksheetEditExtraObjectPermission=us,g.WorksheetEditPermission=fe,g.WorksheetFilterPermission=ds,g.WorksheetInsertColumnPermission=cs,g.WorksheetInsertHyperlinkPermission=ms,g.WorksheetInsertRowPermission=hs,g.WorksheetManageCollaboratorPermission=gs,g.WorksheetPivotTablePermission=Rs,g.WorksheetProtectionPointModel=Ut,g.WorksheetProtectionRuleModel=ke,g.WorksheetSelectProtectedCellsPermission=hl,g.WorksheetSelectUnProtectedCellsPermission=gl,g.WorksheetSetCellStylePermission=Cs,g.WorksheetSetCellValuePermission=Wt,g.WorksheetSetColumnStylePermission=St,g.WorksheetSetRowStylePermission=ft,g.WorksheetSortPermission=Ss,g.WorksheetViewPermission=Vt,g.addMergeCellsUtil=ou,g.adjustRangeOnMutation=fr,g.alignToMergedCellsBorders=At,g.baseProtectionActions=Ge,g.checkCellValueType=Vn,g.checkRangesEditablePermission=Od,g.convertPrimaryWithCoordToPrimary=bo,g.convertSelectionDataToRange=Ba,g.copyRangeStyles=$e,g.createTopMatrixFromMatrix=yo,g.createTopMatrixFromRanges=Mo,g.defaultWorkbookPermissionPoints=ai,g.defaultWorksheetPermissionPoint=_n,g.expandToContinuousRange=Wa,g.factoryRemoveNumfmtUndoMutation=$u,g.factorySetNumfmtUndoMutation=Vu,g.findAllRectangle=Gn,g.findFirstNonEmptyCell=xa,g.followSelectionOperation=Ue,g.generateNullCell=qn,g.generateNullCellValue=Uo,g.getAddMergeMutationRangeByType=ks,g.getAllRangePermissionPoint=ue,g.getAllWorkbookPermissionPoint=Pt,g.getAllWorksheetPermissionPoint=de,g.getAllWorksheetPermissionPointByPointPanel=ve,g.getCellAtRowCol=rl,g.getDefaultRangePermission=Pu,g.getInsertRangeMutations=fs,g.getMoveRangeUndoRedoMutations=rn,g.getNextPrimaryCell=Ad,g.getPrimaryForRange=se,g.getRemoveRangeMutations=vs,g.getSelectionsService=$o,g.getSeparateEffectedRangesOnCommand=Hl,g.getSheetCommandTarget=P,g.getSheetCommandTargetWorkbook=Hn,g.getSheetMutationTarget=Ie,g.getSkeletonChangedEffectedRange=Pa,g.getValueChangedEffectedRange=Ua,g.getVisibleRanges=Dt,g.handleBaseInsertRange=Qe,g.handleBaseMoveRowsCols=Bt,g.handleBaseRemoveRange=Ze,g.handleCommonDefaultRangeChangeWithEffectRefCommands=Ps,g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests=$l,g.handleDefaultRangeChangeWithEffectRefCommands=Us,g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests=Vl,g.handleDeleteRangeMoveLeft=Cr,g.handleDeleteRangeMoveUp=Sr,g.handleDeleteRangeMutation=Cl,g.handleIRemoveCol=Ts,g.handleIRemoveRow=cr,g.handleInsertCol=hr,g.handleInsertRangeMoveDown=gr,g.handleInsertRangeMoveRight=Rr,g.handleInsertRangeMutation=Rl,g.handleInsertRow=mr,g.handleMoveCols=Es,g.handleMoveRange=dr,g.handleMoveRows=bs,g.isSingleCellSelection=al,g.rangeMerge=zn,g.rangeToDiscreteRange=Po,g.rotateRange=he,g.runRefRangeMutations=et,g.setEndForRange=il,g.splitRangeText=To,g.transformCellsToRange=Pn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|