@univerjs/sheets-ui 0.1.0-beta.4 → 0.1.0-beta.5

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/umd/index.js CHANGED
@@ -1,12 +1,12 @@
1
- (function(A,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@wendellhu/redi"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings"),require("@univerjs/docs"),require("rxjs/operators"),require("@univerjs/engine-formula"),require("clsx"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/ui","@wendellhu/redi","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings","@univerjs/docs","rxjs/operators","@univerjs/engine-formula","clsx","@univerjs/engine-numfmt"],a):(A=typeof globalThis<"u"?globalThis:A||self,a(A.UniverSheetsUi={},A.UniverCore,A.UniverSheets,A.UniverUi,A["@wendellhu/redi"],A.rxjs,A.UniverEngineRender,A.React,A.UniverDesign,A["@wendellhu/redi/react-bindings"],A.UniverDocs,A.rxjs.operators,A.UniverEngineFormula,A.clsx,A.UniverEngineNumfmt))})(this,function(A,a,g,I,N,P,b,L,Se,K,q,to,ne,Dt,ss){"use strict";var um=Object.defineProperty;var hm=(A,a,g)=>a in A?um(A,a,{enumerable:!0,configurable:!0,writable:!0,value:g}):A[a]=g;var C=(A,a,g)=>(hm(A,typeof a!="symbol"?a+"":a,g),g);var Ki;const no={InsertRow:!0,InsertColumn:!0,AddRowTop:!1,AddRowBottom:!1,AddColumnLeft:!1,AddColumnRight:!1,DeleteRow:!0,DeleteColumn:!0,HideRow:!1,ShowRow:!1,RowHeight:!1,HideColumn:!1,ShowColumn:!1,ColumnWidth:!1,DeleteCell:!0,ClearContent:!0,Matrix:!1},io={undo:!0,redo:!0,paintFormat:!0,currencyFormat:!0,percentageFormat:!0,numberDecrease:!0,numberIncrease:!0,moreFormats:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,border:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0,mergeCell:!0},oo={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0,formulaBar:!0,rightMenu:!0,countBar:!0,sheetBar:!0},as={layout:{sheetContainerConfig:oo,rightMenuConfig:no,toolbarConfig:io}},ro="SheetUI";function sn(i,e){if(i==null)return;const n=e.getRenderById(i);if(n==null)return;const{mainComponent:t,scene:o,engine:r}=n;return{document:t,scene:o,engine:r}}const ii={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},an=["零","一","二","三","四","五","六","七","八","九"],so=["","万","亿","万亿","亿亿"],ls=["","十","百","千"],ao={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Ve(i){if(!i)return 0;let e=0,n=0,t=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const l=ii[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(n+=t);else{const c=ao[r[s]],d=c.value;o=c.secUnit,o?(n=(n+t)*d,e+=n,n=0):n+=t*d,t=0}}return e+n}function cs(i){let e="",n="",t=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,n=an[r]+n):(o=!1,e=an[r],e+=ls[t],n=e+n),t++,i=Math.floor(i/10)}return n}function ds(i){let e=0,n="",t="",o=!1;if(i===0)return an[0];for(;i>0;){const r=i%1e4;o&&(t=an[0]+t),n=cs(r),n+=r!==0?so[e]:so[0],t=n+t,o=r<1e3&&r>0,i=Math.floor(i/1e4),e++}return t}function us(i){if(!i)return!1;let e=!0;if(i)if(i.length===1)i==="日"||i in ii?e=!0:e=!1;else{const n=i.split("");for(let t=0;t<n.length;t++)if(!(n[t]in ii||n[t]in ao)){e=!1;break}}return e}function ln(i){if(!i)return{isExtendNumber:!1};const e=/0|([1-9]+[0-9]*)/g,n=e.test(i);if(n){const t=i.match(e);if(t&&t.length>0){const o=t[t.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),l=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:n}}function hs(i){let e;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?e=!0:e=!1,e}function ms(i){let e;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?e=!0:e=!1,e}function Ss(i,e){let n=0;for(let t=0;t<i.length&&i[t]<e;t++)n++;return n}function Nt(i){let e=!0;const n=i[1]-i[0];for(let t=1;t<i.length;t++)if(i[t]-i[t-1]!==n){e=!1;break}return e}function _s(i,e,n){const t=[],o=Math.floor(e/i),r=e%i;let s=0;if(o>0){for(let l=0;l<o;l++)for(let c=0;c<n.length;c++)t[n[c]+l*i]=s,s++;for(let l=0;l<n.length&&n[l]<r;l++)t[n[l]+i*o]=s,s++}else for(let l=0;l<n.length&&n[l]<r;l++)t[n[l]]=s,s++;return t}function et(i,e){const n=[];for(let t=1;t<=e;t++){const o=(t-1)%i.length,r=a.Tools.deepClone(i[o]);n.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return n}function gs(i,e){var t;const n=[];for(let o=1;o<=e;o++){const r=(o-1)%i.length,s={s:(t=i[r])==null?void 0:t.s};n.push(s)}return n}function fs(i){let e=!0;const n=i[1]/i[0];for(let t=1;t<i.length;t++)if(i[t]/i[t-1]!==n){e=!1;break}return e}function ps(i){const e=[];for(let n=1;n<=i;n++)e.push(n);return e}function lo(i,e,n){var r,s,l,c;const t=[],o=[];for(let d=0;d<i.length;d++)o.push(Number((r=i[d])==null?void 0:r.v));if(i.length>2&&fs(o))for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]),m=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((l=i[1])==null?void 0:l.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(h.v=m,t.push(h))}else{const d=ps(i.length);for(let u=1;u<=e;u++){const h=(u-1)%i.length,m=a.Tools.deepClone(i[h]),S=n===a.Direction.DOWN||n===a.Direction.RIGHT,_=vs(i.length+u,o,d,S);m&&(m.v=_,t.push(m))}}return t}function vs(i,e,n,t=!0){function o(h){let m=0;for(let S=0;S<h.length;S++)m+=h[S];return m/h.length}const r=o(n),s=o(e);let l=0,c=0;for(let h=0;h<n.length;h++)l+=(n[h]-r)*(e[h]-s),c+=(n[h]-r)*(n[h]-r);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function co(i,e,n){var r;const t=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=e;s++){const l=(s-1)%i.length,c=a.Tools.deepClone(i[l]),d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(o),h=u==null?void 0:u[u.length-1],m=Math.abs(Number(h)+n*s);if(!d||!h)continue;const S=d.lastIndexOf(h),_=d.substr(0,S)+m.toString()+d.substr(S+h.length);c&&(c.v=_,t.push(c))}return t}function dt(i,e,n,t=0){var l,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=o.length)return[];const r=o[t],s=[];for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);let m=0;if(((l=i[i.length-1])==null?void 0:l.v)===r[0])m=7+n*d;else{const _=`${(c=i[i.length-1])==null?void 0:c.v}`;if(_){const f=_.substr(_.length-1,1);m=Ve(f)+n*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const S=m%7;h&&(h.v=r[S],s.push(h))}return s}function uo(i,e,n){var o;const t=[];for(let r=1;r<=e;r++){const s=(r-1)%i.length,l=a.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=Ve(c)+n*r;let u;d<=0?u="零":u=ds(d),l&&(l.v=u,t.push(l))}return t}const Pt={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function Cs(i){let e=!1;return Object.keys(Pt).forEach(n=>{Pt[n].includes(i)&&(e=!0)}),e}function oi(i){let e="";const n=[];return Object.keys(Pt).forEach(t=>{Pt[t].includes(i)&&(e=t,n.push(...Pt[t]))}),{name:e,series:n}}function ho(i,e,n,t){var s;const o=t.length,r=[];for(let l=1;l<=e;l++){const c=(l-1)%i.length,d=a.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+n*l;h<0&&(h+=Math.abs(n)*o);const m=h%o;d&&(d.v=t[m],r.push(d))}return r}function Is(i,e){const n=[];let t;if(e.startRow<i.startRow)t=a.Direction.UP;else if(e.endRow>i.endRow)t=a.Direction.DOWN;else if(e.startColumn<i.startColumn)t=a.Direction.LEFT;else if(e.endColumn>i.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const o=i.endRow-i.startRow+1,r=e.endRow-e.startRow+1,s=Math.floor(r/o),l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-l,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=e.endColumn-e.startColumn+1,s=Math.floor(r/o),l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-l,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return n}function mo(i){const e=new a.ObjectMatrix;return i.forEach(n=>{const{startRow:t,startColumn:o,endRow:r,endColumn:s}=n;for(let l=t;l<=r;l++)for(let c=o;c<=s;c++)e.setValue(l,c,{v:null,p:null,f:null,si:null})}),e.getData()}const So={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,e)=>!0},cn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(i,e)=>{const n=i.get(a.IUniverInstanceService),t=i.get(a.ICommandService),o=i.get(a.IUndoRedoService),r=n.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=e,h={subUnitId:c,unitId:s,cellValue:mo([d])},m=g.SetRangeValuesUndoMutationFactory(i,h);return t.executeCommand(g.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),t.syncExecuteCommand(g.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:g.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:g.SetRangeValuesMutation.id,params:h}],undo(){return t.syncExecuteCommand(g.SetRangeValuesMutation.id,m)},redo(){return t.syncExecuteCommand(g.SetRangeValuesMutation.id,h)}}),!0):!1}};function ie(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)}function ri(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function Ms(i){return i.getContextValue(a.EDITOR_ACTIVATED)}function _o(i){return i.getContextValue(a.FOCUSING_FORMULA_EDITOR)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Rs(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function dn(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)}var fe=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(fe||{}),V=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_MAIN_LEFT_TOP="viewMainLeftTop",i.VIEW_MAIN_TOP="viewMainTop",i.VIEW_MAIN_LEFT="viewMainLeft",i.VIEW_ROW_TOP="viewRowTop",i.VIEW_ROW_BOTTOM="viewRowBottom",i.VIEW_COLUMN_LEFT="viewColumnLeft",i.VIEW_COLUMN_RIGHT="viewColumnRight",i.VIEW_LEFT_TOP="viewLeftTop",i))(V||{});const go=0,Ze=2,bs=3,si=[10,400],fo=1001;var ws=Object.defineProperty,Ts=Object.getOwnPropertyDescriptor,Es=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ts(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ws(e,n,o),o},po=(i,e)=>(n,t)=>e(n,t,i);A.SheetSkeletonManagerService=class{constructor(e,n){C(this,"_currentSkeleton",{unitId:"",sheetId:""});C(this,"_sheetSkeletonParam",[]);C(this,"_currentSkeleton$",new P.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=e,this._localeService=n}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(e){const n=this._getCurrentBySearch(e);if(n!=null)this._reCalculate(n);else{const{unitId:o,sheetId:r}=e,s=this._currentUniverService.getUniverSheetInstance(e.unitId),l=s==null?void 0:s.getSheetBySheetId(e.sheetId);if(l==null||s==null)return;const c=this._buildSkeleton(l,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=e;const t=this.getCurrent();return this._currentSkeletonBefore$.next(t),this._currentSkeleton$.next(t),this.getCurrent()}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeleton,e)}makeDirty(e,n=!0){const t=this._getCurrentBySearch(e);t!=null&&(t.dirty=n)}_getCurrentBySearch(e){const n=this._sheetSkeletonParam.find(t=>t.unitId===e.unitId&&t.sheetId===e.sheetId);return n!=null&&(n.commandId=e.commandId),n}_buildSkeleton(e,n){const t=e.getConfig();return b.SpreadsheetSkeleton.create(e,t,e.getCellMatrix(),n.getStyles(),this._localeService)}},A.SheetSkeletonManagerService=Es([po(0,a.IUniverInstanceService),po(1,N.Inject(a.LocaleService))],A.SheetSkeletonManagerService);class ys{constructor(){C(this,"_startColumn",-1);C(this,"_startRow",-1);C(this,"_endColumn",-1);C(this,"_endRow",-1);C(this,"_startX",0);C(this,"_startY",0);C(this,"_endX",0);C(this,"_endY",0);C(this,"_currentCell");C(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._currentCell}get rangeType(){return this._rangeType}isEqual(e){const{startColumn:n,startRow:t,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return n===s&&t===l&&o===c&&r===d}isInclude(e){const{startColumn:n,startRow:t,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return!(c<n||s>o||l>r||d<t)}highlightToSelection(){return a.makeCellToSelection(this._currentCell)}getRange(){return{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this.rangeType}}getCell(){return this._currentCell}getRangeType(){return this._rangeType}getValue(){return{rangeWithCoord:{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this._rangeType},primaryWithCoord:this._currentCell}}setValue(e,n){const{startColumn:t,startRow:o,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=e;this._startColumn=t,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(n)}setCurrentCell(e){e&&(this._currentCell=e)}clearCurrentCell(){this._currentCell=null}}const vo=.3;class un{constructor(e,n,t=!0,o){C(this,"_leftControl");C(this,"_rightControl");C(this,"_topControl");C(this,"_bottomControl");C(this,"_backgroundControlTop");C(this,"_backgroundControlBottom");C(this,"_backgroundControlMiddleLeft");C(this,"_backgroundControlMiddleRight");C(this,"_fillControl");C(this,"_selectionShape");C(this,"_rowHeaderBackground");C(this,"_rowHeaderBorder");C(this,"_rowHeaderGroup");C(this,"_rowHeaderHighlight");C(this,"_columnHeaderBackground");C(this,"_columnHeaderBorder");C(this,"_columnHeaderGroup");C(this,"_columnHeaderHighlight");C(this,"_topLeftWidget");C(this,"_topCenterWidget");C(this,"_topRightWidget");C(this,"_middleLeftWidget");C(this,"_middleRightWidget");C(this,"_bottomLeftWidget");C(this,"_bottomCenterWidget");C(this,"_bottomRightWidget");C(this,"_dashRect");C(this,"_selectionModel");C(this,"_selectionStyle");C(this,"_rowHeaderWidth",0);C(this,"_columnHeaderHeight",0);C(this,"_widgetRects",[]);C(this,"_dispose$",new P.BehaviorSubject(this));C(this,"dispose$",this._dispose$.asObservable());C(this,"selectionMoving$",new P.Subject);C(this,"selectionMoved$",new P.Subject);C(this,"selectionScaling$",new P.Subject);C(this,"selectionScaled$",new P.Subject);C(this,"selectionFilling$",new P.Subject);C(this,"_selectionFilled$",new P.Subject);C(this,"selectionFilled$",this._selectionFilled$.asObservable());C(this,"_defaultStyle");C(this,"_currentStyle");C(this,"_isHelperSelection",!0);this._scene=e,this._zIndex=n,this._isHeaderHighlight=t,this._themeService=o,this._initialize()}get zIndex(){return this._zIndex}get leftControl(){return this._leftControl}get rightControl(){return this._rightControl}get topControl(){return this._topControl}get bottomControl(){return this._bottomControl}get fillControl(){return this._fillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShape}get model(){return this._selectionModel}get topLeftWidget(){return this._topLeftWidget}get topCenterWidget(){return this._topCenterWidget}get topRightWidget(){return this._topRightWidget}get middleLeftWidget(){return this._middleLeftWidget}get middleRightWidget(){return this._middleRightWidget}get bottomLeftWidget(){return this._bottomLeftWidget}get bottomCenterWidget(){return this._bottomCenterWidget}get bottomRightWidget(){return this._bottomRightWidget}get selectionStyle(){return this._selectionStyle}get dashRect(){return this._dashRect}get isHelperSelection(){return this._isHelperSelection}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}enableHeaderHighlight(){this._isHelperSelection=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}refreshSelectionFilled(e){this._selectionFilled$.next(e)}updateStyle(e){this._updateControl(e,this._rowHeaderWidth,this._columnHeaderHeight)}update(e,n=0,t=0,o,r){this._selectionModel.setValue(e,r),o==null&&(o=this._selectionStyle),this._updateControl(o,n,t)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,n,t,o,r,s,l,c,d,u,h,m,S,_,f,v,M,R,T,w,E,y,x,O,D;(e=this._leftControl)==null||e.dispose(),(n=this._rightControl)==null||n.dispose(),(t=this._topControl)==null||t.dispose(),(o=this._bottomControl)==null||o.dispose(),(r=this._backgroundControlTop)==null||r.dispose(),(s=this._backgroundControlMiddleLeft)==null||s.dispose(),(l=this._backgroundControlMiddleRight)==null||l.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),(d=this._fillControl)==null||d.dispose(),(u=this._selectionShape)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(m=this._rowHeaderBorder)==null||m.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(_=this._rowHeaderBackground)==null||_.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(M=this._columnHeaderGroup)==null||M.dispose(),(R=this._topLeftWidget)==null||R.dispose(),(T=this._topCenterWidget)==null||T.dispose(),(w=this._topRightWidget)==null||w.dispose(),(E=this._middleLeftWidget)==null||E.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(x=this._bottomLeftWidget)==null||x.dispose(),(O=this._bottomCenterWidget)==null||O.dispose(),(D=this._bottomRightWidget)==null||D.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let n;if(e.isMerged){const t=e.mergeInfo;n={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:t.endColumn,startX:t.startX,endX:t.endX,startY:t.startY,endY:t.endY}}else{const{actualRow:t,actualColumn:o,startX:r,endX:s,startY:l,endY:c}=e;n={startRow:t,endRow:t,startColumn:o,endColumn:o,startX:r,endX:s,startY:l,endY:c}}return n}}getValue(){return{...this._selectionModel.getValue(),style:this._selectionStyle}}getRange(){return this._selectionModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}updateStyleId(e){this._selectionStyle!=null&&(this._selectionStyle.id=e)}_updateControl(e,n,t){const{startX:o,startY:r,endX:s,endY:l}=this._selectionModel,c=this._defaultStyle;e==null&&(e=c),this._currentStyle=e;const{stroke:d=c.stroke,widgets:u=c.widgets,hasAutoFill:h=c.hasAutoFill,AutofillStroke:m=c.AutofillStroke,strokeDash:S}=e;let{strokeWidth:_=c.strokeWidth,AutofillSize:f=c.AutofillSize,AutofillStrokeWidth:v=c.AutofillStrokeWidth}=e;const M=this._getScale(),R=(_+g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/M;_/=M,f/=M,v/=M<1?1:M;const T=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/M,w=b.FIX_ONE_PIXEL_BLUR_OFFSET/M;this.leftControl.transformByState({height:l-r,left:-R+w,width:_,strokeWidth:T,top:-T/2+w}),this.leftControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:l-r,left:s-o-R+w,width:_,strokeWidth:T,top:-T/2+w}),this.rightControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:s-o+_,top:-R+w,left:-R+w,height:_,strokeWidth:T}),this.topControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:s-o+_,top:l-r-R+w,height:_,left:-R+w,strokeWidth:T}),this.bottomControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),S==null?this.dashRect.hide():(this.dashRect.transformByState({height:l-r-_/2,width:s-o-_/2,strokeWidth:_,left:_/2-1/M,top:_/2-1/M}),this.dashRect.setProps({strokeDashArray:[0,S]}),this.dashRect.show()),h===!0&&!this._hasWidgets(u)?(this.fillControl.setProps({fill:d,stroke:m,strokeScaleEnabled:!1}),this.fillControl.transformByState({width:f-v,height:f-v,left:s-o-f/2+v/2,top:l-r-f/2+v/2,strokeWidth:v}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,n,t),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(o,r),this._selectionStyle=e,this._rowHeaderWidth=n||0,this._columnHeaderHeight=t||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=g.getNormalSelectionStyle(this._themeService),this._selectionModel=new ys;const e=this._zIndex;this._leftControl=new b.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightControl=new b.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topControl=new b.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomControl=new b.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new b.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new b.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._fillControl=new b.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._dashRect=new b.Rect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const n=[this._fillControl,this._leftControl,this._rightControl,this._topControl,this._bottomControl,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashRect];this._widgetRects=this._initialWidget(),this._selectionShape=new b.Group("__SpreadsheetSelectionShape__"+e,...n,...this._widgetRects),this._selectionShape.hide(),this._selectionShape.evented=!1,this._selectionShape.zIndex=e;const t=this.getScene();t.addObject(this._selectionShape,bs),t.onTransformChangeObservable.add(o=>{o.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._updateControl(this._currentStyle,this._rowHeaderWidth,this._columnHeaderHeight)}),this._initialTitle()}_initialTitle(){const e=this._zIndex;this._rowHeaderBackground=new b.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new b.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new b.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new b.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new b.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new b.Group("__SpreadSheetSelectionColumnHeaderGroup__"+e,this._columnHeaderBackground,this._columnHeaderBorder),this._columnHeaderGroup.hide(),this._columnHeaderGroup.evented=!1,this._columnHeaderGroup.zIndex=e,this.getScene().addObjects([this._rowHeaderGroup,this._columnHeaderGroup],b.DEFAULT_SELECTION_LAYER_INDEX)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new b.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new b.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new b.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new b.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new b.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new b.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new b.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new b.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}_updateBackgroundTitle(e,n,t){const{startX:o,startY:r,endX:s,endY:l,rangeType:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d);const u=this._getScale(),{stroke:h,hasRowHeader:m,rowHeaderFill:S=d.rowHeaderFill,rowHeaderStroke:_=d.rowHeaderStroke,hasColumnHeader:f,columnHeaderFill:v=d.columnHeaderFill,columnHeaderStroke:M=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:R=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:T=d.columnHeaderStrokeWidth}=e;if(R/=u,T/=u,f===!0){let w=v;this._isHeaderHighlight&&c===a.RANGE_TYPE.COLUMN&&(w=new a.ColorKit(h).setAlpha(vo).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(s-o,t),this._columnHeaderBorder.setProps({fill:M}),this._columnHeaderBorder.transformByState({width:s-o,height:T,top:t-T+1/u}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(o,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),m===!0){let w=S;this._isHeaderHighlight&&c===a.RANGE_TYPE.ROW&&(w=new a.ColorKit(h).setAlpha(vo).toString()),this._rowHeaderBackground.setProps({fill:w}),this._rowHeaderBackground.resize(n,l-r),this._rowHeaderBorder.setProps({fill:_}),this._rowHeaderBorder.transformByState({width:R,height:l-r,left:n-R+1/u}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:n,startY:t,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const l=this._getScale(),{fill:c=s.fill}=e;let{strokeWidth:d=s.strokeWidth}=e;d/=l;const u=this._selectionModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-n,r-t),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:m,endX:S,endY:_}=u,f=d/2,v={left:-f,top:-f,width:o-n+f*2,height:m-t+f};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const M={left:-f,top:m-t,width:h-n+f,height:_-m};M.width<0&&(M.width=0,M.height=0),this._backgroundControlMiddleLeft.transformByState(M);const R={left:S-n-f,top:m-t,width:o-S+f*2,height:_-m};R.width<0&&(R.width=0,R.height=0),this._backgroundControlMiddleRight.transformByState(R);const T={left:-f,top:_-t,width:o-n+f*2,height:r-_+f};T.height<0&&(T.width=0,T.height=0),this._backgroundControlBottom.transformByState(T),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:n,startY:t,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const{stroke:l=s.stroke,widgets:c=s.widgets,widgetStroke:d=s.widgetStroke}=e,u=this._getScale();let{widgetSize:h=s.widgetSize,widgetStrokeWidth:m=s.widgetStrokeWidth}=e;h/=u,m/=u;const S={left:-h/2+m/2,center:(o-n)/2-h/2+m/2,right:o-n-h/2+m/2,top:-h/2,middle:(r-t)/2-h/2,bottom:r-t-h/2+m/2},_=h-m;this._widgetRects.forEach(f=>{f.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:_,width:_,left:S.left,top:S.top,strokeWidth:m}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:_,width:_,left:S.center,top:S.top,strokeWidth:m}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:_,width:_,left:S.right,top:S.top,strokeWidth:m}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:_,width:_,left:S.left,top:S.middle,strokeWidth:m}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:_,width:_,left:S.right,top:S.middle,strokeWidth:m}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:_,width:_,left:S.left,top:S.bottom,strokeWidth:m}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:_,width:_,left:S.center,top:S.bottom,strokeWidth:m}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:_,width:_,left:S.right,top:S.bottom,strokeWidth:m}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const n=Object.keys(e);if(n.length===0)return!1;for(const t of n)if(e[t]===!0)return!0;return!0}_getScale(){const{scaleX:e,scaleY:n}=this._scene.getAncestorScale();return Math.max(e,n)}}const Co="__SpreadsheetHelperSelectionTempRect",Os=35;class Io{constructor(e,n,t,o,r){C(this,"_startOffsetX",0);C(this,"_startOffsetY",0);C(this,"_relativeSelectionPositionRow",0);C(this,"_relativeSelectionPositionColumn",0);C(this,"_relativeSelectionRowLength",0);C(this,"_relativeSelectionColumnLength",0);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_helperSelection");C(this,"_scrollTimer");C(this,"_activeViewport");C(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});C(this,"_isInMergeState",!1);C(this,"_fillControlColors",[]);this._control=e,this._skeleton=n,this._scene=t,this._themeService=o,this._injector=r,this._initialControl(),this._initialWidget(),this._initialFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var e,n;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(n=this._helperSelection)==null||n.dispose()}_getFreeze(){var n;return(n=this._injector.get(A.SheetSkeletonManagerService).getCurrent())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(e,n){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(n.viewPortKey){case V.VIEW_MAIN:return e.endRow>=t.startRow&&e.endColumn>=t.startColumn;case V.VIEW_MAIN_TOP:case V.VIEW_COLUMN_RIGHT:return e.endColumn>=t.startColumn&&e.startRow<t.startRow;case V.VIEW_MAIN_LEFT:case V.VIEW_ROW_BOTTOM:return e.endRow>=t.startRow&&e.startColumn<t.startColumn;case V.VIEW_MAIN_LEFT_TOP:case V.VIEW_COLUMN_LEFT:case V.VIEW_ROW_TOP:case V.VIEW_LEFT_TOP:return e.startRow<t.startRow&&e.startColumn<t.startColumn}}_clearObserverEvent(){this._scene.onPointerMoveObserver.remove(this._moveObserver),this._scene.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_initialControl(){const{leftControl:e,rightControl:n,topControl:t,bottomControl:o}=this._control;[e,n,t,o].forEach(r=>{r.onPointerEnterObserver.add(()=>{r.setCursor(b.CURSOR_TYPE.MOVE)}),r.onPointerLeaveObserver.add(()=>{r.resetCursor()}),r.onPointerDownObserver.add(this._controlEvent.bind(this))})}_controlMoving(e,n){var y;const t=this._scene,o=t.getScrollXYByRelativeCoords(b.Vector2.FromArray([e,n])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,n,r,s,o),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let S=m+this._relativeSelectionRowLength;S>u&&(S=u,S-m<this._relativeSelectionRowLength&&(m=S-this._relativeSelectionRowLength));let _=d+this._relativeSelectionPositionColumn;_<0&&(_=0);let f=_+this._relativeSelectionColumnLength;f>h&&(f=h,f-_<this._relativeSelectionColumnLength&&(_=f-this._relativeSelectionColumnLength));const v=this._skeleton.getNoMergeCellPositionByIndex(m,_),M=this._skeleton.getNoMergeCellPositionByIndex(S,f),R=(v==null?void 0:v.startY)||0,T=(M==null?void 0:M.endY)||0,w=(v==null?void 0:v.startX)||0,E=(M==null?void 0:M.endX)||0;(y=this._helperSelection)==null||y.transformByState({left:w,top:R,width:E-w,height:T-R}),this._targetSelection={startY:R,endY:T,startX:w,endX:E,startRow:m,endRow:S,startColumn:_,endColumn:f},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(e){const{offsetX:n,offsetY:t}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([n,t])),{x:s,y:l}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:m,column:S}=h,{startRow:_,startColumn:f,endRow:v,endColumn:M}=this._control.model;let R=0,T=0;m<_?R-=1:m>v&&(R+=1),S<f?T-=1:S>M&&(T+=1),this._relativeSelectionPositionRow=_-m+R,this._relativeSelectionPositionColumn=f-S+T,this._relativeSelectionRowLength=v-_,this._relativeSelectionColumnLength=M-f;const w=this._control.selectionStyle,E=this._getScale();this.isHelperSelection&&(this._helperSelection=new b.Rect(Co,{stroke:w.stroke,strokeWidth:w.strokeWidth/E}),o.addObject(this._helperSelection));const y=o.getViewport(V.VIEW_MAIN),x=b.ScrollTimer.create(o);x.startScroll(s,l,y),this._scrollTimer=x,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(O=>{const{offsetX:D,offsetY:B}=O,{x:H,y:F}=o.getRelativeCoord(b.Vector2.FromArray([D,B]));this._controlMoving(H,F),o.setCursor(b.CURSOR_TYPE.MOVE),x.scrolling(H,F,()=>{this._controlMoving(H,F)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var D,B;(D=this._helperSelection)==null||D.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableEvent(),(B=this._scrollTimer)==null||B.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:e,topCenterWidget:n,topRightWidget:t,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[b.CURSOR_TYPE.NORTH_WEST_RESIZE,b.CURSOR_TYPE.NORTH_RESIZE,b.CURSOR_TYPE.NORTH_EAST_RESIZE,b.CURSOR_TYPE.WEST_RESIZE,b.CURSOR_TYPE.EAST_RESIZE,b.CURSOR_TYPE.SOUTH_WEST_RESIZE,b.CURSOR_TYPE.SOUTH_RESIZE,b.CURSOR_TYPE.SOUTH_EAST_RESIZE];[e,n,t,o,r,s,l,c].forEach((u,h)=>{u.onPointerEnterObserver.add(()=>{u.setCursor(d[h])}),u.onPointerLeaveObserver.add(()=>{u.resetCursor()}),u.onPointerDownObserver.add(m=>{this._widgetEvent(m,d[h])})})}_widgetMoving(e,n,t){const o=this._scene,r=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(e,n,s,l,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let S=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=d,v=u;t===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(S=d,_=u,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.NORTH_RESIZE?(S=d,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===b.CURSOR_TYPE.NORTH_EAST_RESIZE?(S=d,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=u):t===b.CURSOR_TYPE.WEST_RESIZE?(S=this._relativeSelectionPositionRow,_=u,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.EAST_RESIZE?f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===b.CURSOR_TYPE.SOUTH_WEST_RESIZE?(S=this._relativeSelectionPositionRow,_=u,f=d,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.SOUTH_RESIZE&&(S=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=d,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:M,startColumn:R,endRow:T,endColumn:w}=this._swapPositions(S,_,f,v),E=this._skeleton.getNoMergeCellPositionByIndex(M,R),y=this._skeleton.getNoMergeCellPositionByIndex(T,w),x=(E==null?void 0:E.startY)||0,O=(y==null?void 0:y.endY)||0,D=(E==null?void 0:E.startX)||0,B=(y==null?void 0:y.endX)||0;this._targetSelection={startY:x,endY:O,startX:D,endX:B,startRow:S,endRow:f,startColumn:_,endColumn:v},this._control.update(this._targetSelection,h,m,this._control.selectionStyle),this._control.clearHighlight(),this._control.selectionScaling$.next(this._targetSelection)}_widgetEvent(e,n){const{offsetX:t,offsetY:o}=e,r=this._scene,s=r.getRelativeCoord(b.Vector2.FromArray([t,o])),{x:l,y:c}=s;this._startOffsetX=t,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:m}=this._control.model;this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=u,this._relativeSelectionRowLength=h-d,this._relativeSelectionColumnLength=m-u,n===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):n===b.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:n===b.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:n===b.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:n===b.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const S=b.ScrollTimer.create(r);S.startScroll(l,c),this._scrollTimer=S,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(_=>{const{offsetX:f,offsetY:v}=_,{x:M,y:R}=r.getRelativeCoord(b.Vector2.FromArray([f,v]));this._widgetMoving(M,R,n),r.setCursor(n),S.scrolling(M,R,()=>{this._widgetMoving(M,R,n)})}),this._upObserver=r.onPointerUpObserver.add(()=>{var f;const _=this._scene;_.resetCursor(),this._clearObserverEvent(),_.enableEvent(),(f=this._scrollTimer)==null||f.dispose(),this._control.selectionScaled$.next(this._targetSelection)})}_initialFill(){const{fillControl:e}=this._control;e.onPointerEnterObserver.add(()=>{e.setCursor(b.CURSOR_TYPE.CROSSHAIR)}),e.onPointerLeaveObserver.add(()=>{e.resetCursor()}),e.onPointerDownObserver.add(this._fillEvent.bind(this))}_fillMoving(e,n){var B,H,F;const t=this._scene,o=t.getScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,n,r,s,o),{row:c,column:d}=l,u=t.getRelativeCoord(b.Vector2.FromArray([e,n])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,M=!1,R=!0;if((d<_||d>v)&&c>=S&&c<=f){const W=this._fillRuler(d,_,v,this._relativeSelectionColumnLength,m);_=W.startRowOrColumn,v=W.endRowOrColumn,M=W.isLighten,R=!1}else if((c<S||c>f)&&d>=_&&d<=v){const W=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,f=W.endRowOrColumn,M=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const W=this._fillRuler(d,_,v,this._relativeSelectionColumnLength,m);_=W.startRowOrColumn,v=W.endRowOrColumn,M=W.isLighten,R=!1}else{const W=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,f=W.endRowOrColumn,M=W.isLighten}const T=this._skeleton.getNoMergeCellPositionByIndex(S,_),w=this._skeleton.getNoMergeCellPositionByIndex(f,v),E=(T==null?void 0:T.startY)||0,y=(w==null?void 0:w.endY)||0,x=(T==null?void 0:T.startX)||0,O=(w==null?void 0:w.endX)||0;M?this._controlHandler((W,z)=>{const Y=new a.ColorKit(this._fillControlColors[z]).lighten(Os).toRgbString();W.setProps({fill:Y})}):this._controlHandler((W,z)=>{W.setProps({fill:this._fillControlColors[z]})});const D=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===f&&R===!0||_===v&&R===!1?(B=this._helperSelection)==null||B.hide():((H=this._helperSelection)==null||H.transformByState({left:x-D/2,top:E-D/2,width:O-x,height:y-E}),(F=this._helperSelection)==null||F.show()),this._targetSelection={startY:E,endY:y,startX:x,endX:O,startRow:S,endRow:f,startColumn:_,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(e){const{offsetX:n,offsetY:t}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([n,t])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const m=this._control.selectionStyle;let S=m==null?void 0:m.stroke,_=m==null?void 0:m.strokeWidth;const f=g.getNormalSelectionStyle(this._themeService);S==null&&(S=f.stroke),_==null&&(_=f.strokeWidth);const v=this._getScale();_/=v;const M=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,R=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new b.Rect(Co,{stroke:R,strokeWidth:_+M/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(b.Vector2.FromArray([n,t]));const T=o.getViewport(V.VIEW_MAIN),w=b.ScrollTimer.create(o,this._activeViewport.viewPortKey===V.VIEW_MAIN?b.ScrollTimerType.ALL:b.ScrollTimerType.NONE);w.startScroll(s,l,T),this._scrollTimer=w,o.disableEvent(),this._controlHandler(E=>{this._fillControlColors.push(E.fill)}),this._moveObserver=o.onPointerMoveObserver.add(E=>{var F;const{offsetX:y,offsetY:x}=E,O=o.getActiveViewportByCoord(b.Vector2.FromArray([y,x])),{x:D,y:B}=o.getRelativeCoord(b.Vector2.FromArray([y,x]));this._fillMoving(D,B),o.setCursor(b.CURSOR_TYPE.CROSSHAIR);const H=this._targetSelection;if(T&&O&&((F=this._activeViewport)==null?void 0:F.viewPortKey)!==(O==null?void 0:O.viewPortKey)){let W;H.startRow!==c?(w.scrollTimerType=b.ScrollTimerType.Y,W={...H,endRow:H.startRow}):H.endRow!==u?(w.scrollTimerType=b.ScrollTimerType.Y,W={...H,startRow:H.endRow}):H.startColumn!==d?(w.scrollTimerType=b.ScrollTimerType.X,W={...H,endColumn:H.startColumn}):(w.scrollTimerType=b.ScrollTimerType.X,W={...H,startColumn:H.endColumn}),this._isSelectionInViewport(W,O)&&(T.scrollTo({x:w.scrollTimerType===b.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===b.ScrollTimerType.Y?0:void 0}),this._activeViewport=O)}w.scrolling(D,B,()=>{this._fillMoving(D,B)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var y,x;(y=this._helperSelection)==null||y.dispose();const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableEvent(),(x=this._scrollTimer)==null||x.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((O,D)=>{O.setProps({fill:this._fillControlColors[D]})}),this._fillControlColors=[]})}_hasMergeInRange(e,n,t,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:l,startColumn:c,endRow:d,endColumn:u}=s,h={left:n,top:e,right:o,bottom:t},m={left:c,top:l,right:u,bottom:d};if(b.isRectIntersect(h,m))return!0}return!1}_swapPositions(e,n,t,o){const r=Math.min(e,t),s=Math.min(n,o),l=Math.max(e,t),c=Math.max(n,o);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(e){const{leftControl:n,rightControl:t,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[n,t,o,r,s,l,c,d,u];for(let m=0,S=h.length;m<S;m++){const _=h[m];e(_,m)}}_fillRuler(e,n,t,o,r){let s=!1;if(e<n)if(this._isInMergeState&&e<n){const l=n-e,c=o+1,d=Math.ceil(l/c);let u=n-d*c;u<0&&(u=n-(d-1)*c),n=u}else n=e;else if(e>=n&&e<=t)s=!0,t=e;else if(this._isInMergeState&&e>t){const l=e-t,c=o+1,d=Math.ceil(l/c);let u=t+d*c;u>r&&(u=t+(d-1)*c),t=u}else t=e;return{rowOrColumn:e,startRowOrColumn:n,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:e,scaleY:n}=this._scene.getAncestorScale();return Math.max(e,n)}}var xs=Object.defineProperty,As=Object.getOwnPropertyDescriptor,Ds=(i,e,n,t)=>{for(var o=t>1?void 0:t?As(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&xs(e,n,o),o},hn=(i,e)=>(n,t)=>e(n,t,i);A.SelectionRenderService=class{constructor(e,n,t,o){C(this,"hasSelection",!1);C(this,"_downObserver");C(this,"_moveObserver");C(this,"_upObserver");C(this,"_controlFillConfig$",new P.BehaviorSubject(null));C(this,"controlFillConfig$",this._controlFillConfig$.asObservable());C(this,"_selectionControls",[]);C(this,"_startSelectionRange",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});C(this,"_startOffsetX",0);C(this,"_startOffsetY",0);C(this,"_scrollTimer");C(this,"_cancelDownObserver");C(this,"_cancelUpObserver");C(this,"_skeleton");C(this,"_scene");C(this,"_isHeaderHighlight",!0);C(this,"_isDetectMergedCell",!0);C(this,"_selectionStyle");C(this,"_isSelectionEnabled",!0);C(this,"_isShowPreviousEnable",0);C(this,"_isRemainLastEnable",!0);C(this,"_isSkipRemainLastEnable",!1);C(this,"_selectionMoveEnd$",new P.BehaviorSubject([]));C(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());C(this,"_selectionMoving$",new P.Subject);C(this,"selectionMoving$",this._selectionMoving$.asObservable());C(this,"_selectionMoveStart$",new P.Subject);C(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());C(this,"_activeViewport");this._themeService=e,this._shortcutService=n,this._sheetSkeletonManagerService=t,this._injector=o,this._selectionStyle=g.getNormalSelectionStyle(this._themeService)}enableHeaderHighlight(){this._isHeaderHighlight=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}enableDetectMergedCell(){this._isDetectMergedCell=!0}disableDetectMergedCell(){this._isDetectMergedCell=!1}setStyle(e){this._selectionStyle=e}resetStyle(){this.setStyle(g.getNormalSelectionStyle(this._themeService))}enableSelection(){this._isSelectionEnabled=!0}disableSelection(){this._isSelectionEnabled=!1}enableShowPrevious(){this._isShowPreviousEnable=!0}disableShowPrevious(){this._isShowPreviousEnable=!1}enableRemainLast(){this._isRemainLastEnable=!0}disableRemainLast(){this._isRemainLastEnable=!1}enableSkipRemainLast(){this._isSkipRemainLastEnable=!0}disableSkipRemainLast(){this._isSkipRemainLastEnable=!1}getViewPort(){return this._activeViewport}addControlToCurrentByRangeData(e){const n=this.getCurrentControls();if(!n)return;const{rangeWithCoord:t,primaryWithCoord:o}=e,r=this._skeleton;let s=e.style;s==null&&(s=g.getNormalSelectionStyle(this._themeService));const l=this._scene;if(l==null||r==null)return;const c=new un(l,n.length,this._isHeaderHighlight,this._themeService);new Io(c,r,l,this._themeService,this._injector);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(t,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),n.push(c)}updateControlForCurrentByRangeData(e){const n=this.getCurrentControls();if(!n)return;const t=this._skeleton;if(t==null)return;const{rowHeaderWidth:o,columnHeaderHeight:r}=t;for(let s=0,l=e.length;s<l;s++){const{rangeWithCoord:c,primaryWithCoord:d,style:u}=e[s];n[s].update(c,o,r,u,d)}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}changeRuntime(e,n,t){this._skeleton=e,this._scene=n,this._activeViewport=t||n.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(n=>n.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const e=this.getCurrentControls();if(e.length>0){for(const n of e)n.dispose();e.length=0}}_getFreeze(){var n;return(n=this._sheetSkeletonManagerService.getCurrent())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,n){if(!this._scene||e===void 0||n===void 0)return null;const t=this._getFreeze();if(!t||t.startRow<=0&&t.startColumn<=0)return this._scene.getViewport(V.VIEW_MAIN);if(e>t.startRow&&n>t.startColumn)return this._scene.getViewport(V.VIEW_MAIN);if(e<=t.startRow&&n<=t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT_TOP);if(e<=t.startRow&&n>t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_TOP);if(e>t.startRow&&n<=t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT)}getActiveSelections(){const e=this.getCurrentControls();if(e&&e.length>0)return e==null?void 0:e.map(t=>{const o=t.model,r=o.currentCell;let s=null;return r&&(s={actualRow:r.actualRow,actualColumn:r.actualColumn,isMerged:r.isMerged,isMergedMainCell:r.isMergedMainCell,startRow:r.mergeInfo.startRow,startColumn:r.mergeInfo.startColumn,endRow:r.mergeInfo.endRow,endColumn:r.mergeInfo.endColumn}),{range:{startRow:o.startRow,startColumn:o.startColumn,endRow:o.endRow,endColumn:o.endColumn},primary:s}})}getActiveRange(){const e=this.getCurrentControls(),n=e&&e[e.length-1].model;return n&&{startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn}}getActiveSelection(){const e=this.getCurrentControls();return e&&e[e.length-1]}endSelection(){this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}reset(){this._clearSelectionControls(),this._moveObserver=null,this._upObserver=null,this._downObserver=null}resetAndEndSelection(){this.endSelection(),this.reset()}eventTrigger(e,n=0,t=a.RANGE_TYPE.NORMAL,o,r=b.ScrollTimerType.ALL){var Q,se;if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:l,offsetY:c}=e,d=this._scene;if(d==null||s==null)return;o!=null&&(this._activeViewport=o);const u=d.getViewport(V.VIEW_MAIN),h=d.getRelativeCoord(b.Vector2.FromArray([l,c]));let{x:m,y:S}=h;this._startOffsetX=m,this._startOffsetY=S;const _=d.getScrollXYByRelativeCoords(h),{scaleX:f,scaleY:v}=d.getAncestorScale();t===a.RANGE_TYPE.ROW?m=0:t===a.RANGE_TYPE.COLUMN&&(S=0);const M=this._getSelectedRangeWithMerge(m,S,f,v,_);if(!M)return!1;const{rangeWithCoord:R,primaryWithCoord:T}=M,{startRow:w,startColumn:E,endColumn:y,endRow:x,startY:O,endY:D,startX:B,endX:H}=R,{rowHeaderWidth:F,columnHeaderHeight:W}=s,z={startColumn:E,startRow:w,endColumn:y,endRow:x,startY:O,endY:D,startX:B,endX:H,rangeType:t};this._startSelectionRange=z;let Y=this.getActiveSelection();const te=this.getCurrentControls();if(!te)return!1;for(const X of te){if(e.button===2&&X.model.isInclude(z)){Y=X;return}if(X.model.isEqual(z)){Y=X;break}e.shiftKey||X.clearHighlight()}if(te.length>0&&!e.ctrlKey&&!e.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const X of te)X.dispose();te.length=0}const j=Y&&Y.model.currentCell;if(Y&&e.shiftKey&&j){const{actualRow:X,actualColumn:G,mergeInfo:J}=j,ce=Math.min(X,z.startRow,J.startRow),ae=Math.max(X,z.endRow,J.endRow),ge=Math.min(G,z.startColumn,J.startColumn),Xe=Math.max(G,z.endColumn,J.endColumn),Ce=s.getMergeBounding(ce,ge,ae,Xe),me=s.getNoMergeCellPositionByIndex(Ce.startRow,Ce.startColumn),le=s.getNoMergeCellPositionByIndex(Ce.endRow,Ce.endColumn),Ye={startColumn:Ce.startColumn,startRow:Ce.startRow,endColumn:Ce.endColumn,endRow:Ce.endRow,startY:me.startY,endY:le.endY,startX:me.startX,endX:le.endX,rangeType:t},Ie=s.getCellByIndex(X,G);this._startSelectionRange={startColumn:Ie.mergeInfo.startColumn,startRow:Ie.mergeInfo.startRow,endColumn:Ie.mergeInfo.endColumn,endRow:Ie.mergeInfo.endRow,startY:Ie.mergeInfo.startY||0,endY:Ie.mergeInfo.endY||0,startX:Ie.mergeInfo.startX||0,endX:Ie.mergeInfo.endX||0,rangeType:t},Y.update(Ye,F,W,this._selectionStyle,j)}else this._isRemainLastEnable&&Y&&!e.ctrlKey&&!e.shiftKey&&!this._isSkipRemainLastEnable?Y.update(z,F,W,this._selectionStyle,T):(Y=new un(d,te.length+n,this._isHeaderHighlight,this._themeService),new Io(Y,s,d,this._themeService,this._injector),Y.update(z,F,W,this._selectionStyle,T),te.push(Y));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const ee=d.getActiveViewportByCoord(b.Vector2.FromArray([m,S])),re=b.ScrollTimer.create(this._scene,r);re.startScroll((Q=u==null?void 0:u.left)!=null?Q:0,(se=u==null?void 0:u.top)!=null?se:0,u),this._scrollTimer=re,this._addCancelObserver(),(t===a.RANGE_TYPE.ROW||t===a.RANGE_TYPE.COLUMN)&&this._moving(m,S,Y,t);let Z=0,U=0,k=m,$=S;this._moveObserver=d.onPointerMoveObserver.add(X=>{var Ie,en,tn,nn,on,ts,ns,is,os,rs;const{offsetX:G,offsetY:J}=X,{x:ce,y:ae}=d.getRelativeCoord(b.Vector2.FromArray([G,J]));this._moving(ce,ae,Y,t);let ge=ce,Xe=ae;const Ce=this.getActiveSelection(),me=(Ie=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Ie.skeleton.getWorksheetConfig().freeze,le=Ce==null?void 0:Ce.model,Ye=(en=d.getActiveViewportByCoord(b.Vector2.FromArray([G,J])))!=null?en:this._getViewportByCell(le==null?void 0:le.endRow,le==null?void 0:le.endColumn);if(ee&&Ye&&u){const Ji=k<u.left&&ce>u.left||k>u.left&&ce<u.left,Qi=$<u.top&&ae>u.top||$>u.top&&ae<u.top;Ji&&(Z+=1),Qi&&(U+=1);const ke=ee.viewPortKey,rn=Ye.viewPortKey;if(ke===V.VIEW_ROW_TOP)J<u.top&&((tn=le==null?void 0:le.endRow)!=null?tn:0)<((nn=me==null?void 0:me.startRow)!=null?nn:0)?Xe=u.top:Qi&&U%2===1&&u.scrollTo({y:0});else if(ke===V.VIEW_COLUMN_LEFT)G<u.left&&((on=le==null?void 0:le.endColumn)!=null?on:0)<((ts=me==null?void 0:me.startColumn)!=null?ts:0)?ge=u.left:Ji&&Z%2===1&&u.scrollTo({x:0});else if(ke===rn){let $e=!1,ct=!1;ke===V.VIEW_MAIN_LEFT_TOP?($e=!0,ct=!0):ke===V.VIEW_MAIN_TOP?ct=!0:ke===V.VIEW_MAIN_LEFT&&($e=!0),((ns=le==null?void 0:le.endRow)!=null?ns:0)>((is=me==null?void 0:me.startRow)!=null?is:0)&&(ct=!1),((os=le==null?void 0:le.endColumn)!=null?os:0)>((rs=me==null?void 0:me.startColumn)!=null?rs:0)&&($e=!1),$e&&(ge=u.left),ct&&(Xe=u.top)}else{const $e={x:ee.scrollX,y:ee.scrollY},ct={x:Ye.scrollX,y:Ye.scrollY},qi=$e.x!==ct.x&&Ji&&Z%2===1,eo=$e.y!==ct.y&&Qi&&U%2===1;(qi||eo)&&(u.scrollTo({x:qi?$e.x:void 0,y:eo?$e.y:void 0}),qi||(ge=u.left),eo||(Xe=u.top)),(ke===V.VIEW_MAIN_LEFT_TOP&&rn===V.VIEW_MAIN_LEFT||rn===V.VIEW_MAIN_LEFT_TOP&&ke===V.VIEW_MAIN_LEFT)&&(ge=u.left),(ke===V.VIEW_MAIN_LEFT_TOP&&rn===V.VIEW_MAIN_TOP||rn===V.VIEW_MAIN_LEFT_TOP&&ke===V.VIEW_MAIN_TOP)&&(Xe=u.top)}k=ce,$=ae}re.scrolling(ge,Xe,()=>{this._moving(ce,ae,Y,t)})}),this._upObserver=d.onPointerUpObserver.add(X=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(e){const{range:n,primary:t,style:o}=e;let r=this.convertRangeDataToSelection(n);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:a.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(t),style:o}}convertRangeDataToSelection(e){const{startRow:n,startColumn:t,endRow:o,endColumn:r,rangeType:s}=e,l=this._scene,c=this._skeleton;if(l==null||c==null)return;l.getAncestorScale();const d=c.getNoMergeCellPositionByIndex(n,t),u=c.getNoMergeCellPositionByIndex(o,r);return{startRow:n,startColumn:t,endRow:o,endColumn:r,rangeType:s,startY:(d==null?void 0:d.startY)||0,endY:(u==null?void 0:u.endY)||0,startX:(d==null?void 0:d.startX)||0,endX:(u==null?void 0:u.endX)||0}}convertCellRangeToInfo(e){if(e==null)return;const n=this._scene,t=this._skeleton;if(n==null||t==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startRow:c,startColumn:d,endRow:u,endColumn:h}=e,m=t.getNoMergeCellPositionByIndex(o,r),S=t.getNoMergeCellPositionByIndex(c,d),_=t.getNoMergeCellPositionByIndex(u,h);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startX:m.startX,startY:m.startY,endX:m.endX,endY:m.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(S==null?void 0:S.startY)||0,endY:(_==null?void 0:_.endY)||0,startX:(S==null?void 0:S.startX)||0,endX:(_==null?void 0:_.endX)||0}}}_moving(e,n,t,o){var se;const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:l,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,{startRow:h,endRow:m,startColumn:S,endColumn:_}=(t==null?void 0:t.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1},f=s.getViewport(V.VIEW_MAIN),v=(se=this._getViewportByCell(m,_))!=null?se:f,M=s.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),v),{scaleX:R,scaleY:T}=s.getAncestorScale(),{rowHeaderWidth:w,columnHeaderHeight:E}=r;o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(n=Number.POSITIVE_INFINITY);const y=this._getSelectedRangeWithMerge(e,n,R,T,M);if(!y)return!1;const{rangeWithCoord:x,primaryWithCoord:O}=y,{startRow:D,startColumn:B,endColumn:H,endRow:F}=x,W=Math.min(D,l),z=Math.min(B,c),Y=Math.max(F,d),te=Math.max(H,u);let j={startRow:W,startColumn:z,endRow:Y,endColumn:te};if(this._isDetectMergedCell&&(j=r.getSelectionBounding(W,z,Y,te)),!j)return!1;const{startRow:ee,startColumn:re,endRow:Z,endColumn:U}=j,k=r.getNoMergeCellPositionByIndex(ee,re),$=r.getNoMergeCellPositionByIndex(Z,U),Q={startColumn:re,startRow:ee,endColumn:U,endRow:Z,startY:(k==null?void 0:k.startY)||0,endY:($==null?void 0:$.endY)||0,startX:(k==null?void 0:k.startX)||0,endX:($==null?void 0:$.endX)||0};(S!==re||h!==ee||_!==U||m!==Z)&&t!=null&&(t.update(Q,w,E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var t,o;const e=this._scene;if(e==null)return;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),e.enableEvent(),(t=this._scrollTimer)==null||t.dispose();const n=(o=e.getEngine())==null?void 0:o.activeScene;n==null||n.onPointerDownObserver.remove(this._cancelDownObserver),n==null||n.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var t;const e=this._scene;if(e==null)return;const n=(t=e.getEngine())==null?void 0:t.activeScene;n==null||n===e||(n.onPointerDownObserver.remove(this._cancelDownObserver),n.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=n.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=n.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(e,n,t,o,r){var M;if(this._isDetectMergedCell){const R=(M=this._skeleton)==null?void 0:M.calculateCellIndexByPosition(e,n,t,o,r),T=a.makeCellToSelection(R);return T==null?void 0:{primaryWithCoord:R,rangeWithCoord:T}}const s=this._skeleton;if(s==null)return;const l=s.getCellPositionByOffset(e,n,t,o,r),{row:c,column:d}=l,u=s.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:m,endX:S,endY:_}=u,f={startY:m,endY:_,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:m,endY:_,startX:h,endX:S,mergeInfo:f},rangeWithCoord:f}}},A.SelectionRenderService=Ds([hn(0,N.Inject(a.ThemeService)),hn(1,I.IShortcutService),hn(2,N.Inject(A.SheetSkeletonManagerService)),hn(3,N.Inject(N.Injector))],A.SelectionRenderService);const _e=N.createIdentifier("deprecated.univer.sheet.selection-render-service");var Ns=Object.defineProperty,Ps=Object.getOwnPropertyDescriptor,Hs=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ps(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ns(e,n,o),o},tt=(i,e)=>(n,t)=>e(n,t,i);const Ls=1e4,Ht=N.createIdentifier("univer.mark-selection-service");A.MarkSelectionService=class extends a.Disposable{constructor(n,t,o,r,s,l,c){super();C(this,"_shapeMap",new Map);this._currentService=n,this._renderManagerService=t,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=l,this._selectionManagerService=c}addShape(n,t=[],o=Ls){const r=this._currentService.getCurrentUniverSheetInstance(),s=r.getActiveSheet().getSheetId(),l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:n,subUnitId:s,unitId:r.getUnitId(),zIndex:o,control:null,exits:t}),this.refreshShapes(),l}refreshShapes(){const n=this._currentService.getCurrentUniverSheetInstance().getUnitId(),t=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var R;const{unitId:r,subUnitId:s,selection:l,control:c,zIndex:d}=o;if(c&&c.dispose(),r!==n||s!==t)return;const{style:u}=l,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:S}=this._selectionRenderService.convertSelectionRangeToData(l),_=(R=this._sheetSkeletonManagerService.getCurrent())==null?void 0:R.skeleton;if(!h||!_)return;const{rowHeaderWidth:f,columnHeaderHeight:v}=_,M=new un(h,d,!1,this._themeService);M.update(m,f,v,u,S),o.control=M})}getShapeMap(){return this._shapeMap}removeShape(n){const t=this._shapeMap.get(n);if(!t)return;const{control:o}=t;o&&o.dispose(),this._shapeMap.delete(n)}removeAllShapes(){for(const n of this._shapeMap.values()){const{control:t}=n;t&&t.dispose()}this._shapeMap.clear()}},A.MarkSelectionService=Hs([tt(0,a.IUniverInstanceService),tt(1,b.IRenderManagerService),tt(2,_e),tt(3,a.ICommandService),tt(4,N.Inject(A.SheetSkeletonManagerService)),tt(5,N.Inject(a.ThemeService)),tt(6,N.Inject(g.SelectionManagerService))],A.MarkSelectionService);const Us=10,ks=6;function Vs(){return a.Tools.generateRandomId(ks)}function Bs(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Fs{constructor(){C(this,"_cache",new a.LRUMap(Us))}set(e,n){this._cache.set(e,n)}get(e){return this._cache.get(e)}del(e){this._cache.delete(e)}clear(){this._cache.clear()}}const mn=new Fs;var nt=(i=>(i.COPY="COPY",i.CUT="CUT",i))(nt||{});function Ws(i,e,n,t,o){const r=[],s=[];if(t.copyType===nt.CUT){const{undos:l,redos:c}=js(i,e,o);r.push(...c),s.push(...l)}else{const{undos:l,redos:c}=bo(e,n,o);r.push(...c),s.push(...l);const{undos:d,redos:u}=Mo(e,n,o);r.push(...u),s.push(...d);const{undos:h,redos:m}=Ro(e,n,o);r.push(...m),s.push(...h);const{undos:S,redos:_}=ai(e,n,o);r.push(..._),s.push(...S)}return{undos:s,redos:r}}function js(i,e,n){let t=[],o=[];const{range:r,subUnitId:s,unitId:l}=i,{range:c,subUnitId:d}=e;if(r&&c){const u=n.get(a.IUniverInstanceService),h=n.get(g.SheetInterceptorService),m=u.getUniverSheetInstance(l),S=m==null?void 0:m.getSheetBySheetId(s),_=m==null?void 0:m.getSheetBySheetId(d);if(S&&_){const f=new a.ObjectMatrix,v=new a.ObjectMatrix,M=(j,ee)=>({startRow:j,endRow:j,startColumn:ee,endColumn:ee}),R=S.getCellMatrix(),T=_.getCellMatrix();a.Range.foreach(r,(j,ee)=>{f.setValue(j,ee,R.getValue(j,ee)),v.setValue(j,ee,null)});const w=new a.ObjectMatrix;a.Range.foreach(c,(j,ee)=>{w.setValue(j,ee,T.getValue(j,ee))});const E=new a.ObjectMatrix;a.Range.foreach(r,(j,ee)=>{const re=M(j,ee),Z=a.Rectangle.getRelativeRange(re,r),U=a.Rectangle.getPositionRange(Z,c);E.setValue(U.startRow,U.startColumn,R.getValue(j,ee))});const y={from:{value:v.getMatrix(),subUnitId:s},to:{value:E.getMatrix(),subUnitId:d},unitId:l},x={from:{value:f.getMatrix(),subUnitId:s},to:{value:w.getMatrix(),subUnitId:d},unitId:l},O=h.onCommandExecute({id:g.MoveRangeCommand.id,params:{toRange:c,fromRange:r}}),D=S.getMergeData(),B=_.getMergeData(),H=D.filter(j=>a.Rectangle.intersects(j,r)),F=B.filter(j=>a.Rectangle.intersects(j,c)),W=H.map(j=>a.Rectangle.getRelativeRange(j,r)).map(j=>a.Rectangle.getPositionRange(j,c)),z=g.getAddMergeMutationRangeByType(W).filter(j=>!B.some(ee=>a.Rectangle.equals(j,ee))),Y=[{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}},{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:F}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:z}}],te=[{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:z}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:F}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}}];t=[{id:g.MoveRangeMutation.id,params:y},...O.redos,...Y,{id:g.SetSelectionsOperation.id,params:{unitId:l,sheetId:d,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:c}]}}],o=[{id:g.SetSelectionsOperation.id,params:{unitId:l,sheetId:s,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:r}]}},...O.undos,...te,{id:g.MoveRangeMutation.id,params:x}]}}return{undos:o,redos:t}}function Mo(i,e,n){const{unitId:t,subUnitId:o,range:r}=i,s=[],l=[],{startColumn:c,startRow:d}=r,u=new a.ObjectMatrix;e.forValue((S,_,f)=>{u.setValue(S+d,_+c,{v:f.v})});const h={unitId:t,subUnitId:o,cellValue:u.getData()};s.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);return l.push({id:g.SetRangeValuesMutation.id,params:m}),{undos:l,redos:s}}function Ro(i,e,n){const t=[],o=[],{unitId:r,subUnitId:s,range:l}=i,{startColumn:c,startRow:d}=l,u=new a.ObjectMatrix;e.forValue((S,_,f)=>{var M;const v={s:f.s};(M=f.p)!=null&&M.body&&(v.p=f.p),u.setValue(S+d,_+c,v)});const h={unitId:r,subUnitId:s,cellValue:u.getData()};t.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);return o.push({id:g.SetRangeValuesMutation.id,params:m}),{undos:o,redos:t}}function bo(i,e,n){const t=[],o=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=i,{startColumn:d,startRow:u}=c;if(e.forValue((h,m,S)=>{S.s&&r.setValue(h+u,m+d,{s:null})}),r.getLength()>0){const h={subUnitId:l,unitId:s,cellValue:r.getData()};t.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);o.push({id:g.SetRangeValuesMutation.id,params:m})}return{undos:o,redos:t}}function ai(i,e,n){const t=[],o=[],{unitId:r,subUnitId:s,range:l}=i,{startColumn:c,startRow:d,endColumn:u,endRow:h}=l;let m=!1;const S=[];if(e.forValue((v,M,R)=>{if(R.rowSpan){const T=R.colSpan||1,w={startRow:d+v,endRow:d+v+R.rowSpan-1,startColumn:c+M,endColumn:c+M+T-1};S.push(w),m=!0}else if(R.colSpan){const T=R.rowSpan||1,w={startRow:d+v,endRow:d+v+T-1,startColumn:c+M,endColumn:c+M+R.colSpan-1};S.push(w),m=!0}}),m){const M=n.get(a.IUniverInstanceService).getUniverSheetInstance(r),R=M==null?void 0:M.getSheetBySheetId(s);if(M&&R){const w=R.getMergeData().filter(x=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},x)),E={unitId:r,subUnitId:s,ranges:w};t.push({id:g.RemoveWorksheetMergeMutation.id,params:E});const y=g.RemoveMergeUndoMutationFactory(n,E);o.push({id:g.AddWorksheetMergeMutation.id,params:y})}}const _={unitId:r,subUnitId:s,ranges:S};t.push({id:g.AddWorksheetMergeMutation.id,params:_});const f=g.AddMergeUndoMutationFactory(n,_);return o.push({id:g.RemoveWorksheetMergeMutation.id,params:f}),{undos:o,redos:t}}function wo(i){let e=i.replace(/(\r\n|\n)/g,"\r");e.endsWith(`\r
1
+ (function(A,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@wendellhu/redi"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings"),require("@univerjs/docs"),require("rxjs/operators"),require("@univerjs/engine-formula"),require("clsx"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/ui","@wendellhu/redi","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings","@univerjs/docs","rxjs/operators","@univerjs/engine-formula","clsx","@univerjs/engine-numfmt"],a):(A=typeof globalThis<"u"?globalThis:A||self,a(A.UniverSheetsUi={},A.UniverCore,A.UniverSheets,A.UniverUi,A["@wendellhu/redi"],A.rxjs,A.UniverEngineRender,A.React,A.UniverDesign,A["@wendellhu/redi/react-bindings"],A.UniverDocs,A.rxjs.operators,A.UniverEngineFormula,A.clsx,A.UniverEngineNumfmt))})(this,function(A,a,g,I,D,P,b,H,_e,K,ee,qi,te,Nt,rs){"use strict";var dm=Object.defineProperty;var um=(A,a,g)=>a in A?dm(A,a,{enumerable:!0,configurable:!0,writable:!0,value:g}):A[a]=g;var C=(A,a,g)=>(um(A,typeof a!="symbol"?a+"":a,g),g);var Zi;const eo={InsertRow:!0,InsertColumn:!0,AddRowTop:!1,AddRowBottom:!1,AddColumnLeft:!1,AddColumnRight:!1,DeleteRow:!0,DeleteColumn:!0,HideRow:!1,ShowRow:!1,RowHeight:!1,HideColumn:!1,ShowColumn:!1,ColumnWidth:!1,DeleteCell:!0,ClearContent:!0,Matrix:!1},to={undo:!0,redo:!0,paintFormat:!0,currencyFormat:!0,percentageFormat:!0,numberDecrease:!0,numberIncrease:!0,moreFormats:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,border:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0,mergeCell:!0},no={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0,formulaBar:!0,rightMenu:!0,countBar:!0,sheetBar:!0},ss={layout:{sheetContainerConfig:no,rightMenuConfig:eo,toolbarConfig:to}},io="SheetUI";function sn(i,e){if(i==null)return;const n=e.getRenderById(i);if(n==null)return;const{mainComponent:t,scene:o,engine:r}=n;return{document:t,scene:o,engine:r}}const ni={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},an=["零","一","二","三","四","五","六","七","八","九"],oo=["","万","亿","万亿","亿亿"],as=["","十","百","千"],ro={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Ve(i){if(!i)return 0;let e=0,n=0,t=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const l=ni[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(n+=t);else{const c=ro[r[s]],d=c.value;o=c.secUnit,o?(n=(n+t)*d,e+=n,n=0):n+=t*d,t=0}}return e+n}function ls(i){let e="",n="",t=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,n=an[r]+n):(o=!1,e=an[r],e+=as[t],n=e+n),t++,i=Math.floor(i/10)}return n}function cs(i){let e=0,n="",t="",o=!1;if(i===0)return an[0];for(;i>0;){const r=i%1e4;o&&(t=an[0]+t),n=ls(r),n+=r!==0?oo[e]:oo[0],t=n+t,o=r<1e3&&r>0,i=Math.floor(i/1e4),e++}return t}function ds(i){if(!i)return!1;let e=!0;if(i)if(i.length===1)i==="日"||i in ni?e=!0:e=!1;else{const n=i.split("");for(let t=0;t<n.length;t++)if(!(n[t]in ni||n[t]in ro)){e=!1;break}}return e}function ln(i){if(!i)return{isExtendNumber:!1};const e=/0|([1-9]+[0-9]*)/g,n=e.test(i);if(n){const t=i.match(e);if(t&&t.length>0){const o=t[t.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),l=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:n}}function us(i){let e;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?e=!0:e=!1,e}function hs(i){let e;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?e=!0:e=!1,e}function ms(i,e){let n=0;for(let t=0;t<i.length&&i[t]<e;t++)n++;return n}function Dt(i){let e=!0;const n=i[1]-i[0];for(let t=1;t<i.length;t++)if(i[t]-i[t-1]!==n){e=!1;break}return e}function _s(i,e,n){const t=[],o=Math.floor(e/i),r=e%i;let s=0;if(o>0){for(let l=0;l<o;l++)for(let c=0;c<n.length;c++)t[n[c]+l*i]=s,s++;for(let l=0;l<n.length&&n[l]<r;l++)t[n[l]+i*o]=s,s++}else for(let l=0;l<n.length&&n[l]<r;l++)t[n[l]]=s,s++;return t}function et(i,e){const n=[];for(let t=1;t<=e;t++){const o=(t-1)%i.length,r=a.Tools.deepClone(i[o]);n.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return n}function Ss(i,e){var t;const n=[];for(let o=1;o<=e;o++){const r=(o-1)%i.length,s={s:(t=i[r])==null?void 0:t.s};n.push(s)}return n}function gs(i){let e=!0;const n=i[1]/i[0];for(let t=1;t<i.length;t++)if(i[t]/i[t-1]!==n){e=!1;break}return e}function fs(i){const e=[];for(let n=1;n<=i;n++)e.push(n);return e}function so(i,e,n){var r,s,l,c;const t=[],o=[];for(let d=0;d<i.length;d++)o.push(Number((r=i[d])==null?void 0:r.v));if(i.length>2&&gs(o))for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]),m=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((l=i[1])==null?void 0:l.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(h.v=m,t.push(h))}else{const d=fs(i.length);for(let u=1;u<=e;u++){const h=(u-1)%i.length,m=a.Tools.deepClone(i[h]),_=n===a.Direction.DOWN||n===a.Direction.RIGHT,S=ps(i.length+u,o,d,_);m&&(m.v=S,t.push(m))}}return t}function ps(i,e,n,t=!0){function o(h){let m=0;for(let _=0;_<h.length;_++)m+=h[_];return m/h.length}const r=o(n),s=o(e);let l=0,c=0;for(let h=0;h<n.length;h++)l+=(n[h]-r)*(e[h]-s),c+=(n[h]-r)*(n[h]-r);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function ao(i,e,n){var r;const t=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=e;s++){const l=(s-1)%i.length,c=a.Tools.deepClone(i[l]),d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(o),h=u==null?void 0:u[u.length-1],m=Math.abs(Number(h)+n*s);if(!d||!h)continue;const _=d.lastIndexOf(h),S=d.substr(0,_)+m.toString()+d.substr(_+h.length);c&&(c.v=S,t.push(c))}return t}function dt(i,e,n,t=0){var l,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=o.length)return[];const r=o[t],s=[];for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);let m=0;if(((l=i[i.length-1])==null?void 0:l.v)===r[0])m=7+n*d;else{const S=`${(c=i[i.length-1])==null?void 0:c.v}`;if(S){const f=S.substr(S.length-1,1);m=Ve(f)+n*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const _=m%7;h&&(h.v=r[_],s.push(h))}return s}function lo(i,e,n){var o;const t=[];for(let r=1;r<=e;r++){const s=(r-1)%i.length,l=a.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=Ve(c)+n*r;let u;d<=0?u="零":u=cs(d),l&&(l.v=u,t.push(l))}return t}const Pt={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function vs(i){let e=!1;return Object.keys(Pt).forEach(n=>{Pt[n].includes(i)&&(e=!0)}),e}function ii(i){let e="";const n=[];return Object.keys(Pt).forEach(t=>{Pt[t].includes(i)&&(e=t,n.push(...Pt[t]))}),{name:e,series:n}}function co(i,e,n,t){var s;const o=t.length,r=[];for(let l=1;l<=e;l++){const c=(l-1)%i.length,d=a.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+n*l;h<0&&(h+=Math.abs(n)*o);const m=h%o;d&&(d.v=t[m],r.push(d))}return r}function Cs(i,e){const n=[];let t;if(e.startRow<i.startRow)t=a.Direction.UP;else if(e.endRow>i.endRow)t=a.Direction.DOWN;else if(e.startColumn<i.startColumn)t=a.Direction.LEFT;else if(e.endColumn>i.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const o=i.endRow-i.startRow+1,r=e.endRow-e.startRow+1,s=Math.floor(r/o),l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-l,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=e.endColumn-e.startColumn+1,s=Math.floor(r/o),l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)n.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});l>0&&n.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-l,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return n}function uo(i){const e=new a.ObjectMatrix;return i.forEach(n=>{const{startRow:t,startColumn:o,endRow:r,endColumn:s}=n;for(let l=t;l<=r;l++)for(let c=o;c<=s;c++)e.setValue(l,c,{v:null,p:null,f:null,si:null})}),e.getData()}const ho={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,e)=>!0},cn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(i,e)=>{const n=i.get(a.IUniverInstanceService),t=i.get(a.ICommandService),o=i.get(a.IUndoRedoService),r=n.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=e,h={subUnitId:c,unitId:s,cellValue:uo([d])},m=g.SetRangeValuesUndoMutationFactory(i,h);return t.executeCommand(g.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),t.syncExecuteCommand(g.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:g.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:g.SetRangeValuesMutation.id,params:h}],undo(){return t.syncExecuteCommand(g.SetRangeValuesMutation.id,m)},redo(){return t.syncExecuteCommand(g.SetRangeValuesMutation.id,h)}}),!0):!1}};function oi(i){return i.getContextValue(a.FOCUSING_SHEET)}function ne(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)}function mo(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function Is(i){return i.getContextValue(a.EDITOR_ACTIVATED)}function _o(i){return i.getContextValue(a.FOCUSING_FORMULA_EDITOR)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Ms(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function dn(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)}var fe=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(fe||{}),V=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_MAIN_LEFT_TOP="viewMainLeftTop",i.VIEW_MAIN_TOP="viewMainTop",i.VIEW_MAIN_LEFT="viewMainLeft",i.VIEW_ROW_TOP="viewRowTop",i.VIEW_ROW_BOTTOM="viewRowBottom",i.VIEW_COLUMN_LEFT="viewColumnLeft",i.VIEW_COLUMN_RIGHT="viewColumnRight",i.VIEW_LEFT_TOP="viewLeftTop",i))(V||{});const So=0,Ze=2,Rs=3,ri=[10,400],go=1001;var bs=Object.defineProperty,ws=Object.getOwnPropertyDescriptor,Ts=(i,e,n,t)=>{for(var o=t>1?void 0:t?ws(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&bs(e,n,o),o},fo=(i,e)=>(n,t)=>e(n,t,i);A.SheetSkeletonManagerService=class{constructor(e,n){C(this,"_currentSkeleton",{unitId:"",sheetId:""});C(this,"_sheetSkeletonParam",[]);C(this,"_currentSkeleton$",new P.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=e,this._localeService=n}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(e){const n=this._getCurrentBySearch(e);if(n!=null)this._reCalculate(n);else{const{unitId:o,sheetId:r}=e,s=this._currentUniverService.getUniverSheetInstance(e.unitId),l=s==null?void 0:s.getSheetBySheetId(e.sheetId);if(l==null||s==null)return;const c=this._buildSkeleton(l,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=e;const t=this.getCurrent();return this._currentSkeletonBefore$.next(t),this._currentSkeleton$.next(t),this.getCurrent()}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeleton,e)}makeDirty(e,n=!0){const t=this._getCurrentBySearch(e);t!=null&&(t.dirty=n)}getOrCreateSkeleton(e){const n=this._getCurrentBySearch(e);if(n)return n.skeleton;const t=this._currentUniverService.getUniverSheetInstance(e.unitId),o=t==null?void 0:t.getSheetBySheetId(e.sheetId);if(!o||!t)return;const r=this._buildSkeleton(o,t);return this._sheetSkeletonParam.push({unitId:e.unitId,sheetId:e.sheetId,skeleton:r,dirty:!1}),r}_getCurrentBySearch(e){const n=this._sheetSkeletonParam.find(t=>t.unitId===e.unitId&&t.sheetId===e.sheetId);return n!=null&&(n.commandId=e.commandId),n}_buildSkeleton(e,n){const t=e.getConfig();return b.SpreadsheetSkeleton.create(e,t,e.getCellMatrix(),n.getStyles(),this._localeService)}},A.SheetSkeletonManagerService=Ts([fo(0,a.IUniverInstanceService),fo(1,D.Inject(a.LocaleService))],A.SheetSkeletonManagerService);class Es{constructor(){C(this,"_startColumn",-1);C(this,"_startRow",-1);C(this,"_endColumn",-1);C(this,"_endRow",-1);C(this,"_startX",0);C(this,"_startY",0);C(this,"_endX",0);C(this,"_endY",0);C(this,"_currentCell");C(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._currentCell}get rangeType(){return this._rangeType}isEqual(e){const{startColumn:n,startRow:t,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return n===s&&t===l&&o===c&&r===d}isInclude(e){const{startColumn:n,startRow:t,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return!(c<n||s>o||l>r||d<t)}highlightToSelection(){return a.makeCellToSelection(this._currentCell)}getRange(){return{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this.rangeType}}getCell(){return this._currentCell}getRangeType(){return this._rangeType}getValue(){return{rangeWithCoord:{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this._rangeType},primaryWithCoord:this._currentCell}}setValue(e,n){const{startColumn:t,startRow:o,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=e;this._startColumn=t,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(n)}setCurrentCell(e){e&&(this._currentCell=e)}clearCurrentCell(){this._currentCell=null}}const po=.3;class un{constructor(e,n,t=!0,o){C(this,"_leftControl");C(this,"_rightControl");C(this,"_topControl");C(this,"_bottomControl");C(this,"_backgroundControlTop");C(this,"_backgroundControlBottom");C(this,"_backgroundControlMiddleLeft");C(this,"_backgroundControlMiddleRight");C(this,"_fillControl");C(this,"_selectionShape");C(this,"_rowHeaderBackground");C(this,"_rowHeaderBorder");C(this,"_rowHeaderGroup");C(this,"_rowHeaderHighlight");C(this,"_columnHeaderBackground");C(this,"_columnHeaderBorder");C(this,"_columnHeaderGroup");C(this,"_columnHeaderHighlight");C(this,"_topLeftWidget");C(this,"_topCenterWidget");C(this,"_topRightWidget");C(this,"_middleLeftWidget");C(this,"_middleRightWidget");C(this,"_bottomLeftWidget");C(this,"_bottomCenterWidget");C(this,"_bottomRightWidget");C(this,"_dashRect");C(this,"_selectionModel");C(this,"_selectionStyle");C(this,"_rowHeaderWidth",0);C(this,"_columnHeaderHeight",0);C(this,"_widgetRects",[]);C(this,"_dispose$",new P.BehaviorSubject(this));C(this,"dispose$",this._dispose$.asObservable());C(this,"selectionMoving$",new P.Subject);C(this,"selectionMoved$",new P.Subject);C(this,"selectionScaling$",new P.Subject);C(this,"selectionScaled$",new P.Subject);C(this,"selectionFilling$",new P.Subject);C(this,"_selectionFilled$",new P.Subject);C(this,"selectionFilled$",this._selectionFilled$.asObservable());C(this,"_defaultStyle");C(this,"_currentStyle");C(this,"_isHelperSelection",!0);C(this,"_antLineOffset",0);C(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=n,this._isHeaderHighlight=t,this._themeService=o,this._initialize()}get zIndex(){return this._zIndex}get leftControl(){return this._leftControl}get rightControl(){return this._rightControl}get topControl(){return this._topControl}get bottomControl(){return this._bottomControl}get fillControl(){return this._fillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShape}get model(){return this._selectionModel}get topLeftWidget(){return this._topLeftWidget}get topCenterWidget(){return this._topCenterWidget}get topRightWidget(){return this._topRightWidget}get middleLeftWidget(){return this._middleLeftWidget}get middleRightWidget(){return this._middleRightWidget}get bottomLeftWidget(){return this._bottomLeftWidget}get bottomCenterWidget(){return this._bottomCenterWidget}get bottomRightWidget(){return this._bottomRightWidget}get selectionStyle(){return this._selectionStyle}get dashRect(){return this._dashRect}get isHelperSelection(){return this._isHelperSelection}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}enableHeaderHighlight(){this._isHelperSelection=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}refreshSelectionFilled(e){this._selectionFilled$.next(e)}updateStyle(e){this._updateControl(e,this._rowHeaderWidth,this._columnHeaderHeight)}update(e,n=0,t=0,o,r){this._selectionModel.setValue(e,r),o==null&&(o=this._selectionStyle),this._updateControl(o,n,t)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,n,t,o,r,s,l,c,d,u,h,m,_,S,f,v,M,R,T,E,w,y,O,x,N;(e=this._leftControl)==null||e.dispose(),(n=this._rightControl)==null||n.dispose(),(t=this._topControl)==null||t.dispose(),(o=this._bottomControl)==null||o.dispose(),(r=this._backgroundControlTop)==null||r.dispose(),(s=this._backgroundControlMiddleLeft)==null||s.dispose(),(l=this._backgroundControlMiddleRight)==null||l.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),(d=this._fillControl)==null||d.dispose(),(u=this._selectionShape)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(m=this._rowHeaderBorder)==null||m.dispose(),(_=this._rowHeaderGroup)==null||_.dispose(),(S=this._rowHeaderBackground)==null||S.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(M=this._columnHeaderGroup)==null||M.dispose(),(R=this._topLeftWidget)==null||R.dispose(),(T=this._topCenterWidget)==null||T.dispose(),(E=this._topRightWidget)==null||E.dispose(),(w=this._middleLeftWidget)==null||w.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(O=this._bottomLeftWidget)==null||O.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(N=this._bottomRightWidget)==null||N.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let n;if(e.isMerged){const t=e.mergeInfo;n={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:t.endColumn,startX:t.startX,endX:t.endX,startY:t.startY,endY:t.endY}}else{const{actualRow:t,actualColumn:o,startX:r,endX:s,startY:l,endY:c}=e;n={startRow:t,endRow:t,startColumn:o,endColumn:o,startX:r,endX:s,startY:l,endY:c}}return n}}getValue(){return{...this._selectionModel.getValue(),style:this._selectionStyle}}getRange(){return this._selectionModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}updateStyleId(e){this._selectionStyle!=null&&(this._selectionStyle.id=e)}_updateControl(e,n,t){const{startX:o,startY:r,endX:s,endY:l}=this._selectionModel,c=this._defaultStyle;e==null&&(e=c),this._currentStyle=e;const{stroke:d=c.stroke,widgets:u=c.widgets,hasAutoFill:h=c.hasAutoFill,AutofillStroke:m=c.AutofillStroke,strokeDash:_,isAnimationDash:S}=e;let{strokeWidth:f=c.strokeWidth,AutofillSize:v=c.AutofillSize,AutofillStrokeWidth:M=c.AutofillStrokeWidth}=e;const R=this._getScale(),T=(f+g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/R;f/=R,v/=R,M/=R<1?1:R;const E=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/R,w=b.FIX_ONE_PIXEL_BLUR_OFFSET/R;if(this.leftControl.transformByState({height:l-r,left:-T+w,width:f,strokeWidth:E,top:-E/2+w}),this.leftControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:l-r,left:s-o-T+w,width:f,strokeWidth:E,top:-E/2+w}),this.rightControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:s-o+f,top:-T+w,left:-T+w,height:f,strokeWidth:E}),this.topControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:s-o+f,top:l-r-T+w,height:f,left:-T+w,strokeWidth:E}),this.bottomControl.setProps({fill:d,stroke:g.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),_==null)this.dashRect.hide(),this._stopAntLineAnimation();else{const y=e.strokeWidth*2/R;this.dashRect.transformByState({height:l-r,width:s-o,strokeWidth:y,left:-y/2+w,top:-y/2+w}),this.dashRect.setProps({strokeDashArray:[0,_/R]}),this._stopAntLineAnimation(),S!==!1&&this._startAntLineAnimation(),this.dashRect.show()}h===!0&&!this._hasWidgets(u)?(this.fillControl.setProps({fill:d,stroke:m,strokeScaleEnabled:!1}),this.fillControl.transformByState({width:v-M,height:v-M,left:s-o-v/2+M/2,top:l-r-v/2+M/2,strokeWidth:M}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,n,t),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(o,r),this._selectionStyle=e,this._rowHeaderWidth=n||0,this._columnHeaderHeight=t||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=g.getNormalSelectionStyle(this._themeService),this._selectionModel=new Es;const e=this._zIndex;this._leftControl=new b.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightControl=new b.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topControl=new b.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomControl=new b.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new b.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new b.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._fillControl=new b.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._dashRect=new b.Rect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const n=[this._fillControl,this._leftControl,this._rightControl,this._topControl,this._bottomControl,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashRect];this._widgetRects=this._initialWidget(),this._selectionShape=new b.Group("__SpreadsheetSelectionShape__"+e,...n,...this._widgetRects),this._selectionShape.hide(),this._selectionShape.evented=!1,this._selectionShape.zIndex=e;const t=this.getScene();t.addObject(this._selectionShape,Rs),t.onTransformChangeObservable.add(o=>{o.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._updateControl(this._currentStyle,this._rowHeaderWidth,this._columnHeaderHeight)}),this._initialTitle()}_initialTitle(){const e=this._zIndex;this._rowHeaderBackground=new b.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new b.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new b.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new b.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new b.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new b.Group("__SpreadSheetSelectionColumnHeaderGroup__"+e,this._columnHeaderBackground,this._columnHeaderBorder),this._columnHeaderGroup.hide(),this._columnHeaderGroup.evented=!1,this._columnHeaderGroup.zIndex=e,this.getScene().addObjects([this._rowHeaderGroup,this._columnHeaderGroup],b.DEFAULT_SELECTION_LAYER_INDEX)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new b.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new b.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new b.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new b.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new b.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new b.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new b.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new b.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}_updateBackgroundTitle(e,n,t){const{startX:o,startY:r,endX:s,endY:l,rangeType:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d);const u=this._getScale(),{stroke:h,hasRowHeader:m,rowHeaderFill:_=d.rowHeaderFill,rowHeaderStroke:S=d.rowHeaderStroke,hasColumnHeader:f,columnHeaderFill:v=d.columnHeaderFill,columnHeaderStroke:M=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:R=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:T=d.columnHeaderStrokeWidth}=e;if(R/=u,T/=u,f===!0){let E=v;this._isHeaderHighlight&&c===a.RANGE_TYPE.COLUMN&&(E=new a.ColorKit(h).setAlpha(po).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(s-o,t),this._columnHeaderBorder.setProps({fill:M}),this._columnHeaderBorder.transformByState({width:s-o,height:T,top:t-T+1/u}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(o,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),m===!0){let E=_;this._isHeaderHighlight&&c===a.RANGE_TYPE.ROW&&(E=new a.ColorKit(h).setAlpha(po).toString()),this._rowHeaderBackground.setProps({fill:E}),this._rowHeaderBackground.resize(n,l-r),this._rowHeaderBorder.setProps({fill:S}),this._rowHeaderBorder.transformByState({width:R,height:l-r,left:n-R+1/u}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:n,startY:t,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const l=this._getScale(),{fill:c=s.fill}=e;let{strokeWidth:d=s.strokeWidth}=e;d/=l;const u=this._selectionModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-n,r-t),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:m,endX:_,endY:S}=u,f=d/2,v={left:-f,top:-f,width:o-n+f*2,height:m-t+f};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const M={left:-f,top:m-t,width:h-n+f,height:S-m};M.width<0&&(M.width=0,M.height=0),this._backgroundControlMiddleLeft.transformByState(M);const R={left:_-n-f,top:m-t,width:o-_+f*2,height:S-m};R.width<0&&(R.width=0,R.height=0),this._backgroundControlMiddleRight.transformByState(R);const T={left:-f,top:S-t,width:o-n+f*2,height:r-S+f};T.height<0&&(T.width=0,T.height=0),this._backgroundControlBottom.transformByState(T),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:n,startY:t,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const{stroke:l=s.stroke,widgets:c=s.widgets,widgetStroke:d=s.widgetStroke}=e,u=this._getScale();let{widgetSize:h=s.widgetSize,widgetStrokeWidth:m=s.widgetStrokeWidth}=e;h/=u,m/=u;const _={left:-h/2+m/2,center:(o-n)/2-h/2+m/2,right:o-n-h/2+m/2,top:-h/2,middle:(r-t)/2-h/2,bottom:r-t-h/2+m/2},S=h-m;this._widgetRects.forEach(f=>{f.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:S,width:S,left:_.left,top:_.top,strokeWidth:m}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:S,width:S,left:_.center,top:_.top,strokeWidth:m}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:S,width:S,left:_.right,top:_.top,strokeWidth:m}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:S,width:S,left:_.left,top:_.middle,strokeWidth:m}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:S,width:S,left:_.right,top:_.middle,strokeWidth:m}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:S,width:S,left:_.left,top:_.bottom,strokeWidth:m}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:S,width:S,left:_.center,top:_.bottom,strokeWidth:m}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:S,width:S,left:_.right,top:_.bottom,strokeWidth:m}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const n=Object.keys(e);if(n.length===0)return!1;for(const t of n)if(e[t]===!0)return!0;return!0}_getScale(){const{scaleX:e,scaleY:n}=this._scene.getAncestorScale();return Math.max(e,n)}_stopAntLineAnimation(){this._antLineOffset=0,b.cancelRequestFrame(this._antRequestNewFrame)}_startAntLineAnimation(){const e=this._getScale();this._antLineOffset+=.6/e,this._antLineOffset>16/e&&(this._antLineOffset=0),this.dashRect.setProps({strokeDashOffset:-this._antLineOffset}),this._antRequestNewFrame=b.requestNewFrame(()=>{this._startAntLineAnimation()})}}const vo="__SpreadsheetHelperSelectionTempRect",ys=35;class Co{constructor(e,n,t,o,r){C(this,"_startOffsetX",0);C(this,"_startOffsetY",0);C(this,"_relativeSelectionPositionRow",0);C(this,"_relativeSelectionPositionColumn",0);C(this,"_relativeSelectionRowLength",0);C(this,"_relativeSelectionColumnLength",0);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_helperSelection");C(this,"_scrollTimer");C(this,"_activeViewport");C(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});C(this,"_isInMergeState",!1);C(this,"_fillControlColors",[]);this._control=e,this._skeleton=n,this._scene=t,this._themeService=o,this._injector=r,this._initialControl(),this._initialWidget(),this._initialFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var e,n;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(n=this._helperSelection)==null||n.dispose()}_getFreeze(){var n;return(n=this._injector.get(A.SheetSkeletonManagerService).getCurrent())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(e,n){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(n.viewPortKey){case V.VIEW_MAIN:return e.endRow>=t.startRow&&e.endColumn>=t.startColumn;case V.VIEW_MAIN_TOP:case V.VIEW_COLUMN_RIGHT:return e.endColumn>=t.startColumn&&e.startRow<t.startRow;case V.VIEW_MAIN_LEFT:case V.VIEW_ROW_BOTTOM:return e.endRow>=t.startRow&&e.startColumn<t.startColumn;case V.VIEW_MAIN_LEFT_TOP:case V.VIEW_COLUMN_LEFT:case V.VIEW_ROW_TOP:case V.VIEW_LEFT_TOP:return e.startRow<t.startRow&&e.startColumn<t.startColumn}}_clearObserverEvent(){this._scene.onPointerMoveObserver.remove(this._moveObserver),this._scene.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_initialControl(){const{leftControl:e,rightControl:n,topControl:t,bottomControl:o}=this._control;[e,n,t,o].forEach(r=>{r.onPointerEnterObserver.add(()=>{r.setCursor(b.CURSOR_TYPE.MOVE)}),r.onPointerLeaveObserver.add(()=>{r.resetCursor()}),r.onPointerDownObserver.add(this._controlEvent.bind(this))})}_controlMoving(e,n){var y;const t=this._scene,o=t.getScrollXYByRelativeCoords(b.Vector2.FromArray([e,n])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,n,r,s,o),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let _=m+this._relativeSelectionRowLength;_>u&&(_=u,_-m<this._relativeSelectionRowLength&&(m=_-this._relativeSelectionRowLength));let S=d+this._relativeSelectionPositionColumn;S<0&&(S=0);let f=S+this._relativeSelectionColumnLength;f>h&&(f=h,f-S<this._relativeSelectionColumnLength&&(S=f-this._relativeSelectionColumnLength));const v=this._skeleton.getNoMergeCellPositionByIndex(m,S),M=this._skeleton.getNoMergeCellPositionByIndex(_,f),R=(v==null?void 0:v.startY)||0,T=(M==null?void 0:M.endY)||0,E=(v==null?void 0:v.startX)||0,w=(M==null?void 0:M.endX)||0;(y=this._helperSelection)==null||y.transformByState({left:E,top:R,width:w-E,height:T-R}),this._targetSelection={startY:R,endY:T,startX:E,endX:w,startRow:m,endRow:_,startColumn:S,endColumn:f},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(e){const{offsetX:n,offsetY:t}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([n,t])),{x:s,y:l}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:m,column:_}=h,{startRow:S,startColumn:f,endRow:v,endColumn:M}=this._control.model;let R=0,T=0;m<S?R-=1:m>v&&(R+=1),_<f?T-=1:_>M&&(T+=1),this._relativeSelectionPositionRow=S-m+R,this._relativeSelectionPositionColumn=f-_+T,this._relativeSelectionRowLength=v-S,this._relativeSelectionColumnLength=M-f;const E=this._control.selectionStyle,w=this._getScale();this.isHelperSelection&&(this._helperSelection=new b.Rect(vo,{stroke:E.stroke,strokeWidth:E.strokeWidth/w}),o.addObject(this._helperSelection));const y=o.getViewport(V.VIEW_MAIN),O=b.ScrollTimer.create(o);O.startScroll(s,l,y),this._scrollTimer=O,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(x=>{const{offsetX:N,offsetY:F}=x,{x:L,y:W}=o.getRelativeCoord(b.Vector2.FromArray([N,F]));this._controlMoving(L,W),o.setCursor(b.CURSOR_TYPE.MOVE),O.scrolling(L,W,()=>{this._controlMoving(L,W)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var N,F;(N=this._helperSelection)==null||N.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableEvent(),(F=this._scrollTimer)==null||F.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:e,topCenterWidget:n,topRightWidget:t,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[b.CURSOR_TYPE.NORTH_WEST_RESIZE,b.CURSOR_TYPE.NORTH_RESIZE,b.CURSOR_TYPE.NORTH_EAST_RESIZE,b.CURSOR_TYPE.WEST_RESIZE,b.CURSOR_TYPE.EAST_RESIZE,b.CURSOR_TYPE.SOUTH_WEST_RESIZE,b.CURSOR_TYPE.SOUTH_RESIZE,b.CURSOR_TYPE.SOUTH_EAST_RESIZE];[e,n,t,o,r,s,l,c].forEach((u,h)=>{u.onPointerEnterObserver.add(()=>{u.setCursor(d[h])}),u.onPointerLeaveObserver.add(()=>{u.resetCursor()}),u.onPointerDownObserver.add(m=>{this._widgetEvent(m,d[h])})})}_widgetMoving(e,n,t){const o=this._scene,r=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(e,n,s,l,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let _=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,v=u;t===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(_=d,S=u,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.NORTH_RESIZE?(_=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===b.CURSOR_TYPE.NORTH_EAST_RESIZE?(_=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=u):t===b.CURSOR_TYPE.WEST_RESIZE?(_=this._relativeSelectionPositionRow,S=u,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.EAST_RESIZE?f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===b.CURSOR_TYPE.SOUTH_WEST_RESIZE?(_=this._relativeSelectionPositionRow,S=u,f=d,v=this._relativeSelectionPositionColumn):t===b.CURSOR_TYPE.SOUTH_RESIZE&&(_=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:M,startColumn:R,endRow:T,endColumn:E}=this._swapPositions(_,S,f,v),w=this._skeleton.getNoMergeCellPositionByIndex(M,R),y=this._skeleton.getNoMergeCellPositionByIndex(T,E),O=(w==null?void 0:w.startY)||0,x=(y==null?void 0:y.endY)||0,N=(w==null?void 0:w.startX)||0,F=(y==null?void 0:y.endX)||0;this._targetSelection={startY:O,endY:x,startX:N,endX:F,startRow:_,endRow:f,startColumn:S,endColumn:v},this._control.update(this._targetSelection,h,m,this._control.selectionStyle),this._control.clearHighlight(),this._control.selectionScaling$.next(this._targetSelection)}_widgetEvent(e,n){const{offsetX:t,offsetY:o}=e,r=this._scene,s=r.getRelativeCoord(b.Vector2.FromArray([t,o])),{x:l,y:c}=s;this._startOffsetX=t,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:m}=this._control.model;this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=u,this._relativeSelectionRowLength=h-d,this._relativeSelectionColumnLength=m-u,n===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):n===b.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:n===b.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:n===b.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:n===b.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const _=b.ScrollTimer.create(r);_.startScroll(l,c),this._scrollTimer=_,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(S=>{const{offsetX:f,offsetY:v}=S,{x:M,y:R}=r.getRelativeCoord(b.Vector2.FromArray([f,v]));this._widgetMoving(M,R,n),r.setCursor(n),_.scrolling(M,R,()=>{this._widgetMoving(M,R,n)})}),this._upObserver=r.onPointerUpObserver.add(()=>{var f;const S=this._scene;S.resetCursor(),this._clearObserverEvent(),S.enableEvent(),(f=this._scrollTimer)==null||f.dispose(),this._control.selectionScaled$.next(this._targetSelection)})}_initialFill(){const{fillControl:e}=this._control;e.onPointerEnterObserver.add(()=>{e.setCursor(b.CURSOR_TYPE.CROSSHAIR)}),e.onPointerLeaveObserver.add(()=>{e.resetCursor()}),e.onPointerDownObserver.add(this._fillEvent.bind(this))}_fillMoving(e,n){var F,L,W;const t=this._scene,o=t.getScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,n,r,s,o),{row:c,column:d}=l,u=t.getRelativeCoord(b.Vector2.FromArray([e,n])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let _=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,M=!1,R=!0;if((d<S||d>v)&&c>=_&&c<=f){const B=this._fillRuler(d,S,v,this._relativeSelectionColumnLength,m);S=B.startRowOrColumn,v=B.endRowOrColumn,M=B.isLighten,R=!1}else if((c<_||c>f)&&d>=S&&d<=v){const B=this._fillRuler(c,_,f,this._relativeSelectionRowLength,h);_=B.startRowOrColumn,f=B.endRowOrColumn,M=B.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const B=this._fillRuler(d,S,v,this._relativeSelectionColumnLength,m);S=B.startRowOrColumn,v=B.endRowOrColumn,M=B.isLighten,R=!1}else{const B=this._fillRuler(c,_,f,this._relativeSelectionRowLength,h);_=B.startRowOrColumn,f=B.endRowOrColumn,M=B.isLighten}const T=this._skeleton.getNoMergeCellPositionByIndex(_,S),E=this._skeleton.getNoMergeCellPositionByIndex(f,v),w=(T==null?void 0:T.startY)||0,y=(E==null?void 0:E.endY)||0,O=(T==null?void 0:T.startX)||0,x=(E==null?void 0:E.endX)||0;M?this._controlHandler((B,z)=>{const Y=new a.ColorKit(this._fillControlColors[z]).lighten(ys).toRgbString();B.setProps({fill:Y})}):this._controlHandler((B,z)=>{B.setProps({fill:this._fillControlColors[z]})});const N=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();_===f&&R===!0||S===v&&R===!1?(F=this._helperSelection)==null||F.hide():((L=this._helperSelection)==null||L.transformByState({left:O-N/2,top:w-N/2,width:x-O,height:y-w}),(W=this._helperSelection)==null||W.show()),this._targetSelection={startY:w,endY:y,startX:O,endX:x,startRow:_,endRow:f,startColumn:S,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(e){const{offsetX:n,offsetY:t}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([n,t])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const m=this._control.selectionStyle;let _=m==null?void 0:m.stroke,S=m==null?void 0:m.strokeWidth;const f=g.getNormalSelectionStyle(this._themeService);_==null&&(_=f.stroke),S==null&&(S=f.strokeWidth);const v=this._getScale();S/=v;const M=g.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,R=new a.ColorKit(_).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new b.Rect(vo,{stroke:R,strokeWidth:S+M/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(b.Vector2.FromArray([n,t]));const T=o.getViewport(V.VIEW_MAIN),E=b.ScrollTimer.create(o,this._activeViewport.viewPortKey===V.VIEW_MAIN?b.ScrollTimerType.ALL:b.ScrollTimerType.NONE);E.startScroll(s,l,T),this._scrollTimer=E,o.disableEvent(),this._controlHandler(w=>{this._fillControlColors.push(w.fill)}),this._moveObserver=o.onPointerMoveObserver.add(w=>{var W;const{offsetX:y,offsetY:O}=w,x=o.getActiveViewportByCoord(b.Vector2.FromArray([y,O])),{x:N,y:F}=o.getRelativeCoord(b.Vector2.FromArray([y,O]));this._fillMoving(N,F),o.setCursor(b.CURSOR_TYPE.CROSSHAIR);const L=this._targetSelection;if(T&&x&&((W=this._activeViewport)==null?void 0:W.viewPortKey)!==(x==null?void 0:x.viewPortKey)){let B;L.startRow!==c?(E.scrollTimerType=b.ScrollTimerType.Y,B={...L,endRow:L.startRow}):L.endRow!==u?(E.scrollTimerType=b.ScrollTimerType.Y,B={...L,startRow:L.endRow}):L.startColumn!==d?(E.scrollTimerType=b.ScrollTimerType.X,B={...L,endColumn:L.startColumn}):(E.scrollTimerType=b.ScrollTimerType.X,B={...L,startColumn:L.endColumn}),this._isSelectionInViewport(B,x)&&(T.scrollTo({x:E.scrollTimerType===b.ScrollTimerType.X?0:void 0,y:E.scrollTimerType===b.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}E.scrolling(N,F,()=>{this._fillMoving(N,F)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var y,O;(y=this._helperSelection)==null||y.dispose();const w=this._scene;w.resetCursor(),this._clearObserverEvent(),w.enableEvent(),(O=this._scrollTimer)==null||O.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,N)=>{x.setProps({fill:this._fillControlColors[N]})}),this._fillControlColors=[]})}_hasMergeInRange(e,n,t,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:l,startColumn:c,endRow:d,endColumn:u}=s,h={left:n,top:e,right:o,bottom:t},m={left:c,top:l,right:u,bottom:d};if(b.isRectIntersect(h,m))return!0}return!1}_swapPositions(e,n,t,o){const r=Math.min(e,t),s=Math.min(n,o),l=Math.max(e,t),c=Math.max(n,o);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(e){const{leftControl:n,rightControl:t,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[n,t,o,r,s,l,c,d,u];for(let m=0,_=h.length;m<_;m++){const S=h[m];e(S,m)}}_fillRuler(e,n,t,o,r){let s=!1;if(e<n)if(this._isInMergeState&&e<n){const l=n-e,c=o+1,d=Math.ceil(l/c);let u=n-d*c;u<0&&(u=n-(d-1)*c),n=u}else n=e;else if(e>=n&&e<=t)s=!0,t=e;else if(this._isInMergeState&&e>t){const l=e-t,c=o+1,d=Math.ceil(l/c);let u=t+d*c;u>r&&(u=t+(d-1)*c),t=u}else t=e;return{rowOrColumn:e,startRowOrColumn:n,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:e,scaleY:n}=this._scene.getAncestorScale();return Math.max(e,n)}}var Os=Object.defineProperty,xs=Object.getOwnPropertyDescriptor,As=(i,e,n,t)=>{for(var o=t>1?void 0:t?xs(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Os(e,n,o),o},hn=(i,e)=>(n,t)=>e(n,t,i);A.SelectionRenderService=class{constructor(e,n,t,o){C(this,"hasSelection",!1);C(this,"_downObserver");C(this,"_moveObserver");C(this,"_upObserver");C(this,"_controlFillConfig$",new P.BehaviorSubject(null));C(this,"controlFillConfig$",this._controlFillConfig$.asObservable());C(this,"_selectionControls",[]);C(this,"_startSelectionRange",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});C(this,"_startOffsetX",0);C(this,"_startOffsetY",0);C(this,"_scrollTimer");C(this,"_cancelDownObserver");C(this,"_cancelUpObserver");C(this,"_skeleton");C(this,"_scene");C(this,"_isHeaderHighlight",!0);C(this,"_isDetectMergedCell",!0);C(this,"_selectionStyle");C(this,"_isSelectionEnabled",!0);C(this,"_isShowPreviousEnable",0);C(this,"_isRemainLastEnable",!0);C(this,"_isSkipRemainLastEnable",!1);C(this,"_selectionMoveEnd$",new P.BehaviorSubject([]));C(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());C(this,"_selectionMoving$",new P.Subject);C(this,"selectionMoving$",this._selectionMoving$.asObservable());C(this,"_selectionMoveStart$",new P.Subject);C(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());C(this,"_activeViewport");this._themeService=e,this._shortcutService=n,this._sheetSkeletonManagerService=t,this._injector=o,this._selectionStyle=g.getNormalSelectionStyle(this._themeService)}enableHeaderHighlight(){this._isHeaderHighlight=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}enableDetectMergedCell(){this._isDetectMergedCell=!0}disableDetectMergedCell(){this._isDetectMergedCell=!1}setStyle(e){this._selectionStyle=e}resetStyle(){this.setStyle(g.getNormalSelectionStyle(this._themeService))}enableSelection(){this._isSelectionEnabled=!0}disableSelection(){this._isSelectionEnabled=!1}enableShowPrevious(){this._isShowPreviousEnable=!0}disableShowPrevious(){this._isShowPreviousEnable=!1}enableRemainLast(){this._isRemainLastEnable=!0}disableRemainLast(){this._isRemainLastEnable=!1}enableSkipRemainLast(){this._isSkipRemainLastEnable=!0}disableSkipRemainLast(){this._isSkipRemainLastEnable=!1}getViewPort(){return this._activeViewport}addControlToCurrentByRangeData(e){const n=this.getCurrentControls();if(!n)return;const{rangeWithCoord:t,primaryWithCoord:o}=e,r=this._skeleton;let s=e.style;s==null&&(s=g.getNormalSelectionStyle(this._themeService));const l=this._scene;if(l==null||r==null)return;const c=new un(l,n.length,this._isHeaderHighlight,this._themeService);new Co(c,r,l,this._themeService,this._injector);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(t,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),n.push(c)}updateControlForCurrentByRangeData(e){const n=this.getCurrentControls();if(!n)return;const t=this._skeleton;if(t==null)return;const{rowHeaderWidth:o,columnHeaderHeight:r}=t;for(let s=0,l=e.length;s<l;s++){const{rangeWithCoord:c,primaryWithCoord:d,style:u}=e[s];n[s].update(c,o,r,u,d)}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}changeRuntime(e,n,t){this._skeleton=e,this._scene=n,this._activeViewport=t||n.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(n=>n.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const e=this.getCurrentControls();if(e.length>0){for(const n of e)n.dispose();e.length=0}}_getFreeze(){var n;return(n=this._sheetSkeletonManagerService.getCurrent())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,n){if(!this._scene||e===void 0||n===void 0)return null;const t=this._getFreeze();if(!t||t.startRow<=0&&t.startColumn<=0)return this._scene.getViewport(V.VIEW_MAIN);if(e>t.startRow&&n>t.startColumn)return this._scene.getViewport(V.VIEW_MAIN);if(e<=t.startRow&&n<=t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT_TOP);if(e<=t.startRow&&n>t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_TOP);if(e>t.startRow&&n<=t.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT)}getActiveSelections(){const e=this.getCurrentControls();if(e&&e.length>0)return e==null?void 0:e.map(t=>{const o=t.model,r=o.currentCell;let s=null;return r&&(s={actualRow:r.actualRow,actualColumn:r.actualColumn,isMerged:r.isMerged,isMergedMainCell:r.isMergedMainCell,startRow:r.mergeInfo.startRow,startColumn:r.mergeInfo.startColumn,endRow:r.mergeInfo.endRow,endColumn:r.mergeInfo.endColumn}),{range:{startRow:o.startRow,startColumn:o.startColumn,endRow:o.endRow,endColumn:o.endColumn},primary:s}})}getActiveRange(){const e=this.getCurrentControls(),n=e&&e[e.length-1].model;return n&&{startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn}}getActiveSelection(){const e=this.getCurrentControls();return e&&e[e.length-1]}endSelection(){this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}reset(){this._clearSelectionControls(),this._moveObserver=null,this._upObserver=null,this._downObserver=null}resetAndEndSelection(){this.endSelection(),this.reset()}eventTrigger(e,n=0,t=a.RANGE_TYPE.NORMAL,o,r=b.ScrollTimerType.ALL){var ie,oe;if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:l,offsetY:c}=e,d=this._scene;if(d==null||s==null)return;o!=null&&(this._activeViewport=o);const u=d.getViewport(V.VIEW_MAIN),h=d.getRelativeCoord(b.Vector2.FromArray([l,c]));let{x:m,y:_}=h;this._startOffsetX=m,this._startOffsetY=_;const S=d.getScrollXYByRelativeCoords(h),{scaleX:f,scaleY:v}=d.getAncestorScale();t===a.RANGE_TYPE.ROW?m=0:t===a.RANGE_TYPE.COLUMN&&(_=0);const M=this._getSelectedRangeWithMerge(m,_,f,v,S);if(!M)return!1;const{rangeWithCoord:R,primaryWithCoord:T}=M,{startRow:E,startColumn:w,endColumn:y,endRow:O,startY:x,endY:N,startX:F,endX:L}=R,{rowHeaderWidth:W,columnHeaderHeight:B}=s,z={startColumn:w,startRow:E,endColumn:y,endRow:O,startY:x,endY:N,startX:F,endX:L,rangeType:t};this._startSelectionRange=z;let Y=this.getActiveSelection();const J=this.getCurrentControls();if(!J)return!1;for(const X of J){if(e.button===2&&X.model.isInclude(z)){Y=X;return}if(X.model.isEqual(z)){Y=X;break}e.shiftKey||X.clearHighlight()}if(J.length>0&&!e.ctrlKey&&!e.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const X of J)X.dispose();J.length=0}const j=Y&&Y.model.currentCell;if(Y&&e.shiftKey&&j){const{actualRow:X,actualColumn:G,mergeInfo:Q}=j,ce=Math.min(X,z.startRow,Q.startRow),ae=Math.max(X,z.endRow,Q.endRow),ge=Math.min(G,z.startColumn,Q.startColumn),Ye=Math.max(G,z.endColumn,Q.endColumn),Ce=s.getMergeBounding(ce,ge,ae,Ye),me=s.getNoMergeCellPositionByIndex(Ce.startRow,Ce.startColumn),le=s.getNoMergeCellPositionByIndex(Ce.endRow,Ce.endColumn),Xe={startColumn:Ce.startColumn,startRow:Ce.startRow,endColumn:Ce.endColumn,endRow:Ce.endRow,startY:me.startY,endY:le.endY,startX:me.startX,endX:le.endX,rangeType:t},Ie=s.getCellByIndex(X,G);this._startSelectionRange={startColumn:Ie.mergeInfo.startColumn,startRow:Ie.mergeInfo.startRow,endColumn:Ie.mergeInfo.endColumn,endRow:Ie.mergeInfo.endRow,startY:Ie.mergeInfo.startY||0,endY:Ie.mergeInfo.endY||0,startX:Ie.mergeInfo.startX||0,endX:Ie.mergeInfo.endX||0,rangeType:t},Y.update(Xe,W,B,this._selectionStyle,j)}else this._isRemainLastEnable&&Y&&!e.ctrlKey&&!e.shiftKey&&!this._isSkipRemainLastEnable?Y.update(z,W,B,this._selectionStyle,T):(Y=new un(d,J.length+n,this._isHeaderHighlight,this._themeService),new Co(Y,s,d,this._themeService,this._injector),Y.update(z,W,B,this._selectionStyle,T),J.push(Y));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const q=d.getActiveViewportByCoord(b.Vector2.FromArray([m,_])),se=b.ScrollTimer.create(this._scene,r);se.startScroll((ie=u==null?void 0:u.left)!=null?ie:0,(oe=u==null?void 0:u.top)!=null?oe:0,u),this._scrollTimer=se,this._addCancelObserver(),(t===a.RANGE_TYPE.ROW||t===a.RANGE_TYPE.COLUMN)&&this._moving(m,_,Y,t);let $=0,k=0,U=m,Z=_;this._moveObserver=d.onPointerMoveObserver.add(X=>{var Ie,en,tn,nn,on,es,ts,ns,is,os;const{offsetX:G,offsetY:Q}=X,{x:ce,y:ae}=d.getRelativeCoord(b.Vector2.FromArray([G,Q]));this._moving(ce,ae,Y,t);let ge=ce,Ye=ae;const Ce=this.getActiveSelection(),me=(Ie=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Ie.skeleton.getWorksheetConfig().freeze,le=Ce==null?void 0:Ce.model,Xe=(en=d.getActiveViewportByCoord(b.Vector2.FromArray([G,Q])))!=null?en:this._getViewportByCell(le==null?void 0:le.endRow,le==null?void 0:le.endColumn);if(q&&Xe&&u){const Gi=U<u.left&&ce>u.left||U>u.left&&ce<u.left,Ki=Z<u.top&&ae>u.top||Z>u.top&&ae<u.top;Gi&&($+=1),Ki&&(k+=1);const ke=q.viewPortKey,rn=Xe.viewPortKey;if(ke===V.VIEW_ROW_TOP)Q<u.top&&((tn=le==null?void 0:le.endRow)!=null?tn:0)<((nn=me==null?void 0:me.startRow)!=null?nn:0)?Ye=u.top:Ki&&k%2===1&&u.scrollTo({y:0});else if(ke===V.VIEW_COLUMN_LEFT)G<u.left&&((on=le==null?void 0:le.endColumn)!=null?on:0)<((es=me==null?void 0:me.startColumn)!=null?es:0)?ge=u.left:Gi&&$%2===1&&u.scrollTo({x:0});else if(ke===rn){let $e=!1,ct=!1;ke===V.VIEW_MAIN_LEFT_TOP?($e=!0,ct=!0):ke===V.VIEW_MAIN_TOP?ct=!0:ke===V.VIEW_MAIN_LEFT&&($e=!0),((ts=le==null?void 0:le.endRow)!=null?ts:0)>((ns=me==null?void 0:me.startRow)!=null?ns:0)&&(ct=!1),((is=le==null?void 0:le.endColumn)!=null?is:0)>((os=me==null?void 0:me.startColumn)!=null?os:0)&&($e=!1),$e&&(ge=u.left),ct&&(Ye=u.top)}else{const $e={x:q.scrollX,y:q.scrollY},ct={x:Xe.scrollX,y:Xe.scrollY},Ji=$e.x!==ct.x&&Gi&&$%2===1,Qi=$e.y!==ct.y&&Ki&&k%2===1;(Ji||Qi)&&(u.scrollTo({x:Ji?$e.x:void 0,y:Qi?$e.y:void 0}),Ji||(ge=u.left),Qi||(Ye=u.top)),(ke===V.VIEW_MAIN_LEFT_TOP&&rn===V.VIEW_MAIN_LEFT||rn===V.VIEW_MAIN_LEFT_TOP&&ke===V.VIEW_MAIN_LEFT)&&(ge=u.left),(ke===V.VIEW_MAIN_LEFT_TOP&&rn===V.VIEW_MAIN_TOP||rn===V.VIEW_MAIN_LEFT_TOP&&ke===V.VIEW_MAIN_TOP)&&(Ye=u.top)}U=ce,Z=ae}se.scrolling(ge,Ye,()=>{this._moving(ce,ae,Y,t)})}),this._upObserver=d.onPointerUpObserver.add(X=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(e){const{range:n,primary:t,style:o}=e;let r=this.convertRangeDataToSelection(n);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:a.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(t),style:o}}convertRangeDataToSelection(e){const{startRow:n,startColumn:t,endRow:o,endColumn:r,rangeType:s}=e,l=this._scene,c=this._skeleton;if(l==null||c==null)return;l.getAncestorScale();const d=c.getNoMergeCellPositionByIndex(n,t),u=c.getNoMergeCellPositionByIndex(o,r);return{startRow:n,startColumn:t,endRow:o,endColumn:r,rangeType:s,startY:(d==null?void 0:d.startY)||0,endY:(u==null?void 0:u.endY)||0,startX:(d==null?void 0:d.startX)||0,endX:(u==null?void 0:u.endX)||0}}convertCellRangeToInfo(e){if(e==null)return;const n=this._scene,t=this._skeleton;if(n==null||t==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startRow:c,startColumn:d,endRow:u,endColumn:h}=e,m=t.getNoMergeCellPositionByIndex(o,r),_=t.getNoMergeCellPositionByIndex(c,d),S=t.getNoMergeCellPositionByIndex(u,h);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startX:m.startX,startY:m.startY,endX:m.endX,endY:m.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(_==null?void 0:_.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(_==null?void 0:_.startX)||0,endX:(S==null?void 0:S.endX)||0}}}_moving(e,n,t,o){var oe;const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:l,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,{startRow:h,endRow:m,startColumn:_,endColumn:S}=(t==null?void 0:t.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1},f=s.getViewport(V.VIEW_MAIN),v=(oe=this._getViewportByCell(m,S))!=null?oe:f,M=s.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),v),{scaleX:R,scaleY:T}=s.getAncestorScale(),{rowHeaderWidth:E,columnHeaderHeight:w}=r;o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(n=Number.POSITIVE_INFINITY);const y=this._getSelectedRangeWithMerge(e,n,R,T,M);if(!y)return!1;const{rangeWithCoord:O,primaryWithCoord:x}=y,{startRow:N,startColumn:F,endColumn:L,endRow:W}=O,B=Math.min(N,l),z=Math.min(F,c),Y=Math.max(W,d),J=Math.max(L,u);let j={startRow:B,startColumn:z,endRow:Y,endColumn:J};if(this._isDetectMergedCell&&(j=r.getSelectionBounding(B,z,Y,J)),!j)return!1;const{startRow:q,startColumn:se,endRow:$,endColumn:k}=j,U=r.getNoMergeCellPositionByIndex(q,se),Z=r.getNoMergeCellPositionByIndex($,k),ie={startColumn:se,startRow:q,endColumn:k,endRow:$,startY:(U==null?void 0:U.startY)||0,endY:(Z==null?void 0:Z.endY)||0,startX:(U==null?void 0:U.startX)||0,endX:(Z==null?void 0:Z.endX)||0};(_!==se||h!==q||S!==k||m!==$)&&t!=null&&(t.update(ie,E,w),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var t,o;const e=this._scene;if(e==null)return;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),e.enableEvent(),(t=this._scrollTimer)==null||t.dispose();const n=(o=e.getEngine())==null?void 0:o.activeScene;n==null||n.onPointerDownObserver.remove(this._cancelDownObserver),n==null||n.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var t;const e=this._scene;if(e==null)return;const n=(t=e.getEngine())==null?void 0:t.activeScene;n==null||n===e||(n.onPointerDownObserver.remove(this._cancelDownObserver),n.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=n.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=n.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(e,n,t,o,r){var M;if(this._isDetectMergedCell){const R=(M=this._skeleton)==null?void 0:M.calculateCellIndexByPosition(e,n,t,o,r),T=a.makeCellToSelection(R);return T==null?void 0:{primaryWithCoord:R,rangeWithCoord:T}}const s=this._skeleton;if(s==null)return;const l=s.getCellPositionByOffset(e,n,t,o,r),{row:c,column:d}=l,u=s.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:m,endX:_,endY:S}=u,f={startY:m,endY:S,startX:h,endX:_,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:m,endY:S,startX:h,endX:_,mergeInfo:f},rangeWithCoord:f}}},A.SelectionRenderService=As([hn(0,D.Inject(a.ThemeService)),hn(1,I.IShortcutService),hn(2,D.Inject(A.SheetSkeletonManagerService)),hn(3,D.Inject(D.Injector))],A.SelectionRenderService);const Se=D.createIdentifier("deprecated.univer.sheet.selection-render-service");var Ns=Object.defineProperty,Ds=Object.getOwnPropertyDescriptor,Ps=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ds(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ns(e,n,o),o},tt=(i,e)=>(n,t)=>e(n,t,i);const Hs=1e4,Ht=D.createIdentifier("univer.mark-selection-service");A.MarkSelectionService=class extends a.Disposable{constructor(n,t,o,r,s,l,c){super();C(this,"_shapeMap",new Map);this._currentService=n,this._renderManagerService=t,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=l,this._selectionManagerService=c}addShape(n,t=[],o=Hs){const r=this._currentService.getCurrentUniverSheetInstance(),s=r.getActiveSheet().getSheetId(),l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:n,subUnitId:s,unitId:r.getUnitId(),zIndex:o,control:null,exits:t}),this.refreshShapes(),l}refreshShapes(){const n=this._currentService.getCurrentUniverSheetInstance().getUnitId(),t=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var R;const{unitId:r,subUnitId:s,selection:l,control:c,zIndex:d}=o;if(c&&c.dispose(),r!==n||s!==t)return;const{style:u}=l,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:_}=this._selectionRenderService.convertSelectionRangeToData(l),S=(R=this._sheetSkeletonManagerService.getCurrent())==null?void 0:R.skeleton;if(!h||!S)return;const{rowHeaderWidth:f,columnHeaderHeight:v}=S,M=new un(h,d,!1,this._themeService);M.update(m,f,v,u,_),o.control=M})}getShapeMap(){return this._shapeMap}removeShape(n){const t=this._shapeMap.get(n);if(!t)return;const{control:o}=t;o&&o.dispose(),this._shapeMap.delete(n)}removeAllShapes(){for(const n of this._shapeMap.values()){const{control:t}=n;t&&t.dispose()}this._shapeMap.clear()}},A.MarkSelectionService=Ps([tt(0,a.IUniverInstanceService),tt(1,b.IRenderManagerService),tt(2,Se),tt(3,a.ICommandService),tt(4,D.Inject(A.SheetSkeletonManagerService)),tt(5,D.Inject(a.ThemeService)),tt(6,D.Inject(g.SelectionManagerService))],A.MarkSelectionService);const Ls=10,Us=6;function ks(){return a.Tools.generateRandomId(Us)}function Vs(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Bs{constructor(){C(this,"_cache",new a.LRUMap(Ls))}set(e,n){this._cache.set(e,n)}get(e){return this._cache.get(e)}del(e){this._cache.delete(e)}clear(){this._cache.clear()}}var nt=(i=>(i.COPY="COPY",i.CUT="CUT",i))(nt||{});function Fs(i,e,n,t,o){const r=[],s=[];if(t.copyType===nt.CUT){const{undos:l,redos:c}=Ws(i,e,o);r.push(...c),s.push(...l)}else{const{undos:l,redos:c}=Ro(e,n,o);r.push(...c),s.push(...l);const{undos:d,redos:u}=Io(e,n,o);r.push(...u),s.push(...d);const{undos:h,redos:m}=Mo(e,n,o);r.push(...m),s.push(...h);const{undos:_,redos:S}=si(e,n,o);r.push(...S),s.push(..._)}return{undos:s,redos:r}}function Ws(i,e,n){let t=[],o=[];const{range:r,subUnitId:s,unitId:l}=i,{range:c,subUnitId:d}=e;if(r&&c){const u=n.get(a.IUniverInstanceService),h=n.get(g.SheetInterceptorService),m=u.getUniverSheetInstance(l),_=m==null?void 0:m.getSheetBySheetId(s),S=m==null?void 0:m.getSheetBySheetId(d);if(_&&S){const f=new a.ObjectMatrix,v=new a.ObjectMatrix,M=(j,q)=>({startRow:j,endRow:j,startColumn:q,endColumn:q}),R=_.getCellMatrix(),T=S.getCellMatrix();a.Range.foreach(r,(j,q)=>{f.setValue(j,q,a.Tools.deepClone(R.getValue(j,q))),v.setValue(j,q,null)});const E=new a.ObjectMatrix;a.Range.foreach(c,(j,q)=>{E.setValue(j,q,a.Tools.deepClone(T.getValue(j,q)))});const w=new a.ObjectMatrix;a.Range.foreach(r,(j,q)=>{const se=M(j,q),$=a.Rectangle.getRelativeRange(se,r),k=a.Rectangle.getPositionRange($,c);w.setValue(k.startRow,k.startColumn,R.getValue(j,q))});const y={from:{value:v.getMatrix(),subUnitId:s},to:{value:w.getMatrix(),subUnitId:d},unitId:l},O={from:{value:f.getMatrix(),subUnitId:s},to:{value:E.getMatrix(),subUnitId:d},unitId:l},x=h.onCommandExecute({id:g.MoveRangeCommand.id,params:{toRange:c,fromRange:r}}),N=_.getMergeData(),F=S.getMergeData(),L=N.filter(j=>a.Rectangle.intersects(j,r)),W=F.filter(j=>a.Rectangle.intersects(j,c)),B=L.map(j=>a.Rectangle.getRelativeRange(j,r)).map(j=>a.Rectangle.getPositionRange(j,c)),z=g.getAddMergeMutationRangeByType(B).filter(j=>!F.some(q=>a.Rectangle.equals(j,q))),Y=[{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}},{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:W}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:z}}],J=[{id:g.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:z}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:W}},{id:g.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}}];t=[{id:g.MoveRangeMutation.id,params:y},...x.redos,...Y,{id:g.SetSelectionsOperation.id,params:{unitId:l,subUnitId:d,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:c}]}}],o=[{id:g.SetSelectionsOperation.id,params:{unitId:l,sheetId:s,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:r}]}},...x.undos,...J,{id:g.MoveRangeMutation.id,params:O}]}}return{undos:o,redos:t}}function Io(i,e,n){const{unitId:t,subUnitId:o,range:r}=i,s=[],l=[],{startColumn:c,startRow:d}=r,u=new a.ObjectMatrix;e.forValue((_,S,f)=>{u.setValue(_+d,S+c,{v:f.v})});const h={unitId:t,subUnitId:o,cellValue:u.getData()};s.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);return l.push({id:g.SetRangeValuesMutation.id,params:m}),{undos:l,redos:s}}function Mo(i,e,n){const t=[],o=[],{unitId:r,subUnitId:s,range:l}=i,{startColumn:c,startRow:d}=l,u=new a.ObjectMatrix;e.forValue((_,S,f)=>{var M;const v={s:f.s};(M=f.p)!=null&&M.body&&(v.p=f.p),u.setValue(_+d,S+c,v)});const h={unitId:r,subUnitId:s,cellValue:u.getData()};t.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);return o.push({id:g.SetRangeValuesMutation.id,params:m}),{undos:o,redos:t}}function Ro(i,e,n){const t=[],o=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=i,{startColumn:d,startRow:u}=c;if(e.forValue((h,m,_)=>{_.s&&r.setValue(h+u,m+d,{s:null})}),r.getLength()>0){const h={subUnitId:l,unitId:s,cellValue:r.getData()};t.push({id:g.SetRangeValuesMutation.id,params:h});const m=g.SetRangeValuesUndoMutationFactory(n,h);o.push({id:g.SetRangeValuesMutation.id,params:m})}return{undos:o,redos:t}}function si(i,e,n){const t=[],o=[],{unitId:r,subUnitId:s,range:l}=i,{startColumn:c,startRow:d,endColumn:u,endRow:h}=l;let m=!1;const _=[];if(e.forValue((v,M,R)=>{if(R.rowSpan){const T=R.colSpan||1,E={startRow:d+v,endRow:d+v+R.rowSpan-1,startColumn:c+M,endColumn:c+M+T-1};_.push(E),m=!0}else if(R.colSpan){const T=R.rowSpan||1,E={startRow:d+v,endRow:d+v+T-1,startColumn:c+M,endColumn:c+M+R.colSpan-1};_.push(E),m=!0}}),m){const M=n.get(a.IUniverInstanceService).getUniverSheetInstance(r),R=M==null?void 0:M.getSheetBySheetId(s);if(M&&R){const E=R.getMergeData().filter(O=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},O)),w={unitId:r,subUnitId:s,ranges:E};t.push({id:g.RemoveWorksheetMergeMutation.id,params:w});const y=g.RemoveMergeUndoMutationFactory(n,w);o.push({id:g.AddWorksheetMergeMutation.id,params:y})}}const S={unitId:r,subUnitId:s,ranges:_};t.push({id:g.AddWorksheetMergeMutation.id,params:S});const f=g.AddMergeUndoMutationFactory(n,S);return o.push({id:g.RemoveWorksheetMergeMutation.id,params:f}),{undos:o,redos:t}}function bo(i){let e=i.replace(/(\r\n|\n)/g,"\r");e.endsWith(`\r
2
2
  `)||(e+=`\r
3
3
  `);const n=[];for(let t=0;t<e.length;t++)e[t]==="\r"&&n.push({startIndex:t});return{dataStream:e,paragraphs:n,sectionBreaks:[{startIndex:e.indexOf(`
4
- `)}]}}function zs(i){const e=new DOMParser,n=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(n,"text/html").querySelector("#univer-root")}function Xs(i){const e=i.style,n={};for(let t=0;t<e.length;t++){const o=e[t],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=parseInt(r);n.spaceAbove=/pt/.test(r)?li(s):s;break}case"margin-bottom":{const s=parseInt(r);n.spaceBelow=/pt/.test(r)?li(s):s;break}}}return Object.getOwnPropertyNames(n).length?n:null}function li(i){return i/.75}function To(i,e){const n=[];for(let t=0,o=i.length;t<o;t++)i[t]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:t});if(e)for(const t of n)e.bullet&&(t.bullet=a.Tools.deepClone(e.bullet)),e.paragraphStyle&&(t.paragraphStyle=a.Tools.deepClone(e.paragraphStyle));return n}function ci(i){const e=i.style,n={},t=i.tagName.toLowerCase();switch(t){case"b":case"em":case"strong":{n.bl=a.BooleanNumber.TRUE;break}case"s":{n.st={s:a.BooleanNumber.TRUE};break}case"u":{n.ul={s:a.BooleanNumber.TRUE};break}case"i":{n.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{n.va=t==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{n.ff=s;break}case"font-size":{const l=parseInt(s);Number.isNaN(l)||(n.fs=/pt$/.test(s)?li(l):l);break}case"font-style":{s==="italic"&&(n.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(n.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?n.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?n.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(n.st={s:a.BooleanNumber.TRUE});break}case"color":{const l=new a.ColorKit(s);l.isValid&&(n.cl={rgb:l.toRgbString()});break}case"background-color":{const l=new a.ColorKit(s);l.isValid&&(n.bg={rgb:l.toRgbString()});break}}}return n}function Eo(i,e){const n=i.tagName.toLowerCase();return typeof e=="string"?n===e:Array.isArray(e)?e.some(t=>t===n):e(i)}const ni=class ni{constructor(e){C(this,"styleCache",new Map);C(this,"styleRules",[]);C(this,"afterProcessRules",[]);C(this,"getCurrentSkeleton");this.getCurrentSkeleton=e.getCurrentSkeleton}static use(e){if(this.pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this.pluginList.push(e)}convert(e){const n=ni.pluginList.find(m=>m.checkPasteType(e));n&&(this.styleRules=[...n.stylesRules],this.afterProcessRules=[...n.afterProcessRules]);const t=new a.ObjectMatrix,o=zs(e),r={dataStream:"",textRuns:[]},s=[],l=e.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),c=[];this.process(null,o==null?void 0:o.childNodes,r,c);const{paragraphs:d,dataStream:u,textRuns:h}=r;if(d){const m=d.map(S=>S.startIndex+1);m.unshift(0);for(let S=0;S<m.length;S++){let _;S===m.length-1?_=`${u.substring(m[S])}\r
5
- `:_=`${u.substring(m[S],m[S+1]-1)}\r
6
- `;const f=[];h==null||h.forEach(M=>{M.st>=m[S]&&M.ed<=m[S+1]&&f.push({st:M.st-m[S],ed:M.ed-m[S],ts:M.ts})});const v=this._generateDocumentDataModelSnapshot({body:{dataStream:_,textRuns:f,paragraphs:To(_)}});t.setValue(t.getLength(),0,{v:_,p:v}),s.push({}),l&&c.forEach(M=>{const R=t.getDataRange().endRow+1;if(M.index===S){const T=l.shift(),{cellMatrix:w,colProperties:E,rowProperties:y}=this._parseTable(T);w&&w.forValue((x,O,D)=>{t.setValue(R+x,O,D)}),s.push(...y)}})}}else{if(u){const m=`${u}\r
7
- `,S={dataStream:m,textRuns:h,paragraphs:To(m)},_=this._generateDocumentDataModelSnapshot({body:S});t.setValue(0,0,{v:u,p:_}),s.push({})}l&&l.forEach(m=>{const S=t.getDataRange().endRow+1,{cellMatrix:_}=this._parseTable(m);_&&_.forValue((f,v,M)=>{const{rowSpan:R=1,colSpan:T=1}=M;for(let w=0;w<R;w++)for(let E=0;E<T;E++)t.setValue(S+f+w,v+E,{v:""});t.setValue(S+f,v,M)}),s.push(...s)})}return{rowProperties:[],colProperties:[],cellMatrix:t}}_parseTable(e){const n=new a.ObjectMatrix;Zs(e);const{rowProperties:t,rowCount:o,cellMatrix:r}=Ys(e);return r&&r.forValue((s,l,c)=>{var u;const d=I.handleStringToStyle(void 0,(u=c.properties)==null?void 0:u.style);if(/\r|\n/.test(c.content)){const h=wo(c.content),m=this._generateDocumentDataModelSnapshot({body:h});n.setValue(s,l,{v:c.content,p:m,s:d,rowSpan:c.rowSpan,colSpan:c.colSpan})}else n.setValue(s,l,{v:c.content,s:d,rowSpan:c.rowSpan,colSpan:c.colSpan})}),{rowProperties:[],colProperties:[],cellMatrix:n}}_generateDocumentDataModelSnapshot(e){var l;const n=this.getCurrentSkeleton();if(n==null)return null;const{skeleton:t}=n,o=(l=t.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...o==null?void 0:o.getSnapshot(),...e};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(e,n,t,o){var r,s;for(const l of n)if(l.nodeName.toLowerCase()==="table")o.push({index:((r=t==null?void 0:t.paragraphs)==null?void 0:r.length)||0});else if(l.nodeType===Node.TEXT_NODE){const c=(s=l.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let d;e&&this.styleCache.has(e)&&(d=this.styleCache.get(e));const u={dataStream:"",textRuns:[]};t.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(t.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:d}),u.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:d}))}else if(l.nodeType===Node.ELEMENT_NODE){const c=e?this.styleCache.get(e):{},d=this.styleRules.find(({filter:S})=>Eo(l,S)),u=d?d.getStyle(l):ci(l);this.styleCache.set(l,{...c,...u});const{childNodes:h}=l;this.process(l,h,t,o);const m=this.afterProcessRules.find(({filter:S})=>Eo(l,S));m&&m.handler(t,l)}}};C(ni,"pluginList",[]);let Lt=ni;function Ys(i){const e=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,n=i.matchAll(e);if(!n)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const t=Array.from(n),o=t.map(l=>di(l[1])),{colCount:r,cellMatrix:s}=$s(t.map(l=>l[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function $s(i){const e=new a.ObjectMatrix,n=new Map,t=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((l,c)=>{const d=c===0,u=l.matchAll(t);r=0,Array.from(u).forEach(h=>{const m=di(h[1]),S=Gs(h[2].replace("<br>","\r").replace(/<\/?[^>]*>/g,"")),_=m.rowspan?+m.rowspan:1,f=m.colspan?+m.colspan:1;if(!d){for(let M=r;M<o;M++)if(!(n.get(M)>=s)){r=M;break}}const v={content:S,properties:m};f>1&&(v.colSpan=+f),_>1&&(v.rowSpan=+_),d&&(o+=f);for(let M=r;M<r+f;M++)n.set(M,s+_-1);e.setValue(s,r,v),r+=f}),s+=1}),{colCount:o,cellMatrix:e}}function di(i){if(!i)return{};const e=/([\w-]+)="([^"]*)"/gi,n=i.matchAll(e),t={};return Array.from(n).forEach(o=>{const[r,s,l]=o;t[s]=l}),t}function Zs(i){const e=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,n=i.match(e);if(!n||!n[2])return null;const t=/<col([\s\S]*?)>/g,o=n[2].matchAll(t);return o?Array.from(o).map(r=>di(r[1])):null}function Gs(i){const e={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return i.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,n=>e[n])}const Ks={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=ci(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},Js={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=ci(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const n={startIndex:i.dataStream.length},t=Xs(e);t&&(n.paragraphStyle=t),i.paragraphs.push(n),i.dataStream+="\r"}}]};function Qs(i,e,n,t){const o=n.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=ui(o),s=hi(r),l=e.map(c=>qs(i,c,n,t)).filter(c=>!!c).join("");return`<tr${s}>${l}</tr>`}function qs(i,e,n,t){const o=t.getValue(i,e),r=n.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,i,e,o==null?void 0:o.rowSpan,o==null?void 0:o.colSpan)}).filter(d=>!!d),s=ui(r),l=hi(s),c=n.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,e))||""},"");return`<td${l}>${c}</td>`}function ea(i,e){return`<colgroup>${i.map(t=>{const o=e.map(l=>{var c;return(c=l.onCopyColumn)==null?void 0:c.call(l,t)}).filter(l=>!!l),r=ui(o);return`<col ${hi(r)}>`}).join("")}</colgroup>`}function ui(i){return i.reduce((e,n)=>(Object.keys(n).forEach(o=>{e[o]?e[o]+=`;${n[o]}`:e[o]=n[o]}),e),{})}function hi(i){return Object.keys(i).reduce((e,n)=>(e+=` ${n}="${i[n]}"`,e),"")}function ta(i,e){const n=[];for(let t=i;t<=e;t++)n.push(t);return n}class na{convert(e,n,t){const{startColumn:o,endColumn:r}=n,s=ea(ta(o,r),t),l=[],{startRow:c,endRow:d,startColumn:u,endColumn:h}=e.getDataRange();for(let S=c;S<=d;S++){const _=Array.from({length:h-u+1},(f,v)=>u+v);l.push(Qs(S,_,t,e))}return`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
8
- <tbody>${l.join("")}</tbody></table>`}}var ia=Object.defineProperty,oa=Object.getOwnPropertyDescriptor,ra=(i,e,n,t)=>{for(var o=t>1?void 0:t?oa(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ia(e,n,o),o},Ge=(i,e)=>(n,t)=>e(n,t,i);const pe={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border"};Lt.use(Js),Lt.use(Ks);const ut=N.createIdentifier("sheet.clipboard-service");A.SheetClipboardService=class extends a.Disposable{constructor(n,t,o,r,s,l,c,d){super();C(this,"_clipboardHooks",[]);C(this,"_clipboardHooks$",new P.BehaviorSubject([]));C(this,"clipboardHooks$",this._clipboardHooks$.asObservable());C(this,"_htmlToUSM");C(this,"_usmToHtml");C(this,"_copyMarkId",null);this._logService=n,this._currentUniverService=t,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=l,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Lt({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new na}async copy(n=nt.COPY){const t=this._selectionManagerService.getLast();if(!t)return!1;const o=this._clipboardHooks;o.reduce((M,R)=>{var w;const T=(w=R.getFilteredOutRows)==null?void 0:w.call(R);return T==null||T.forEach(E=>M.add(E)),M},new Set);const{startColumn:r,startRow:s,endColumn:l,endRow:c}=t.range,d=this._currentUniverService.getCurrentUniverSheetInstance(),u=d.getActiveSheet(),h=u.getMatrixWithMergedCells(s,r,c,l),m=new a.ObjectMatrix;for(let M=s;M<=c;M++)for(let R=r;R<=l;R++){const T=h.getValue(M,R);T?m.setValue(M-s,R-r,{...yo(),...a.Tools.deepClone(T)}):m.setValue(M-s,R-r,yo())}o.forEach(M=>{var R;return(R=M.onBeforeCopy)==null?void 0:R.call(M,d.getUnitId(),u.getSheetId(),t.range)});let S=this._usmToHtml.convert(h,t.range,o);const _=sa(m),f=Vs();S=S.replace(/(<[a-z]+)/,(M,R)=>`${R} data-copy-id="${f}"`),mn.set(f,{unitId:d.getUnitId(),subUnitId:u.getSheetId(),range:t.range,matrix:m,copyType:n}),await this._clipboardInterfaceService.write(_,S),this._markSelectionService.removeAllShapes();const v=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...t,style:v}),o.forEach(M=>{var R;return(R=M.onAfterCopy)==null?void 0:R.call(M)}),!0}async cut(){return this.copy(nt.CUT)}async paste(n,t=pe.DEFAULT_PASTE){const o=n.types,r=o.indexOf(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await n.getType(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"",s=o.indexOf(I.HTML_CLIPBOARD_MIME_TYPE)!==-1?await n.getType(I.HTML_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"";return s?this._pasteHTML(s,t):r?this._pastePlainText(r,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(n,t){return n?this._pasteHTML(n,pe.DEFAULT_PASTE):t?this._pastePlainText(t,pe.DEFAULT_PASTE):Promise.resolve(!1)}addClipboardHook(n){if(this._clipboardHooks.findIndex(o=>o.id===n.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",n.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(n.priority||0)<r});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,n),this._notifyClipboardHook(),a.toDisposable(()=>{const o=this._clipboardHooks.indexOf(n);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(n,t){const o=this._getPastingTarget();if(!o.selection)return!1;const r=o.selection.range,{unitId:s,subUnitId:l}=o,c=this._clipboardHooks,d=[];if(c.some(_=>{var f;return d.push(_)&&((f=_.onBeforePaste)==null?void 0:f.call(_,{unitId:s,subUnitId:l,range:r}))===!1}))return d.forEach(_=>{var f;return(f=_.onAfterPaste)==null?void 0:f.call(_,!1)}),!1;const h=[],m=[];d.forEach(_=>{var v;const f=(v=_.onPastePlainText)==null?void 0:v.call(_,{unitId:s,subUnitId:l,range:r},n,{pasteType:t});f&&(h.push(...f.redos),m.push(...f.undos))});const S=h.every(_=>this._commandService.executeCommand(_.id,_.params));return S&&this._undoRedoService.pushUndoRedo({unitID:this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),undoMutations:m,redoMutations:h}),S}async _pasteHTML(n,t){const o=Bs(n);return o&&mn.get(o)?this._pasteInternal(o,t):this._pasteExternal(n,t)}async _pasteExternal(n,t){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(n),{startColumn:h,endColumn:m,startRow:S,endRow:_}=u.getDataRange(),f=_-S+1,v=m-h+1;if(!u||m<h||_<S)return!1;const M=this._transformPastedData(f,v,u,r.range);return M?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:l,pastedRange:M},t):!1}async _pasteInternal(n,t){var O,D;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o,c=a.Tools.deepClone(mn.get(n)),{range:d,matrix:u,unitId:h,subUnitId:m}=c||{};if(!r||!u||!c||!d||!h||!m||!r||!u||!c)return!1;const S=(O=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:O.getStyles();u.forValue((B,H,F)=>{if(typeof F.s=="string"){const W=a.Tools.deepClone(F);W.s=S==null?void 0:S.getStyleByCell(F),u.setValue(B,H,W)}});const{startColumn:_,endColumn:f,startRow:v,endRow:M}=d,R=this._transformPastedData(M-v+1,f-_+1,u,r.range);if(!R)return!1;const T=(D=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:D.getSheetBySheetId(m);if(!T)return!1;const w=T.getColumnManager(),E=T.getConfig().defaultColumnWidth,y=[];for(let B=_;B<=f;B++){const H=w.getColumnOrCreate(B);y.push({width:`${H.w||E}`})}const x=this._pasteUSM({cellMatrix:u,colProperties:y},{unitId:s,subUnitId:l,pastedRange:R},t,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:n});return c.copyType===nt.CUT&&(mn.set(n,{...c,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),x}_pasteUSM(n,t,o,r){const{rowProperties:s,colProperties:l,cellMatrix:c}=n,{unitId:d,subUnitId:u,pastedRange:h}=t,{startColumn:m,endColumn:S}=h,_=S-m+1,f=this._clipboardHooks,v=[];if(f.some(D=>{var B;return v.push(D)&&((B=D.onBeforePaste)==null?void 0:B.call(D,{unitId:d,subUnitId:u,range:h}))===!1}))return v.forEach(D=>{var B;return(B=D.onAfterPaste)==null?void 0:B.call(D,!1)}),!1;if(!c)return!1;const R=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,T={copyType:(r==null?void 0:r.copyType)||nt.COPY,copyId:r==null?void 0:r.copyId,pasteType:o},w=[],E=[];v.filter(D=>!D.specialPasteInfo&&D.id!==pe.DEFAULT_PASTE||o===D.id).forEach(D=>{var F,W,z;if(s){const Y=(F=D.onPasteRows)==null?void 0:F.call(D,{range:h,unitId:d,subUnitId:u},s,{pasteType:o});Y&&(w.push(...Y.redos),E.push(...Y.undos))}const B=(W=D.onPasteColumns)==null?void 0:W.call(D,{range:h,unitId:d,subUnitId:u},l||new Array(_).map(()=>({})),{pasteType:o});B&&(w.push(...B.redos),E.push(...B.undos));const H=(z=D.onPasteCells)==null?void 0:z.call(D,R,{range:h,unitId:d,subUnitId:u},c,T);H&&(w.push(...H.redos),E.push(...H.undos))});const x=this._getSetSelectionOperation(d,u,h,c);x&&w.push(x),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:E,redoMutationsInfo:w});const O=w.every(D=>this._commandService.executeCommand(D.id,D.params));return O&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:E,redoMutations:w}),O}_getSetSelectionOperation(n,t,o,r){var f;const s=(f=this._currentUniverService.getUniverSheetInstance(n))==null?void 0:f.getSheetBySheetId(t);if(!s)return null;const{startRow:l,startColumn:c}=o,d={startRow:l,endRow:l,startColumn:c,endColumn:c},u=g.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,S=(h==null?void 0:h.colSpan)||1;if(m>1||S>1){const v={startRow:l,endRow:l+m-1,startColumn:c,endColumn:c+S-1};u.startRow=v.startRow,u.endRow=v.endRow,u.startColumn=v.startColumn,u.endColumn=v.endColumn,u.isMerged=!0,u.isMergedMainCell=!0}const _={unitId:n,subUnitId:t,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:g.SetSelectionsOperation.id,params:_}}_getPastingTarget(){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:n.getUnitId(),subUnitId:t.getSheetId(),selection:o}}_transformPastedData(n,t,o,r){const{startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=c-s+1,h=d-l+1,f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(E=>a.Rectangle.intersects({startRow:s,startColumn:l,endRow:c,endColumn:d},E)),v=f[0];let M=0,R=0,T=0,w=0;if(v&&(M=v.startRow,R=v.startColumn,T=v.endRow,w=v.endColumn),u%n===0&&h%t===0)if(f.length>0&&(u!==n||h!==t))if(M===s&&R===l&&T===c&&w===d)if(ua(o))for(let y=0;y<u;y++)for(let x=0;x<h;x++){const O=o.getValue(y%n,x%t);O&&o.setValue(y,x,O)}else o.forValue((y,x,O)=>{O.s=null,delete O.colSpan,delete O.rowSpan});else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const x=o.getValue(E%n,y%t);x&&o.setValue(E,y,x)}else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const x=o.getValue(E%n,y%t);x&&o.setValue(E,y,x)}else if(f.length>0)if(this._topLeftCellsMatch(n,t,r))r.endRow=s+n-1,r.endColumn=l+t-1;else{if(c>v.endRow||d>v.endColumn)return null;o.forValue((y,x,O)=>{O.s=null,delete O.colSpan,delete O.rowSpan})}else r.endRow=s+n-1,r.endColumn=l+t-1;return r}_topLeftCellsMatch(n,t,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:l,startColumn:c,endRow:d,endColumn:u}=o,h=ca(l+n-1,c,c+n-1,s),m=da(c+t-1,l,l+n-1,s);return!h&&!m}},A.SheetClipboardService=ra([Ge(0,a.ILogService),Ge(1,a.IUniverInstanceService),Ge(2,N.Inject(g.SelectionManagerService)),Ge(3,I.IClipboardInterfaceService),Ge(4,a.IUndoRedoService),Ge(5,a.ICommandService),Ge(6,Ht),Ge(7,N.Inject(A.SheetSkeletonManagerService))],A.SheetClipboardService);function sa(i){let e="";return i.forRow((n,t)=>{const o=[];t.forEach(r=>{const s=i.getValue(n,r);if(s){const l=aa(s);o.push(l)}}),e+=o.join(" "),n!==i.getLength()-1&&(e+=`
9
- `)}),e}function aa(i){const e=i.v;return la((e==null?void 0:e.toString())||"")}const la=i=>i.replace(/&/g,"&amp;").replace(/\uFEFF/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function ca(i,e,n,t){return t.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&e<=o.startColumn&&o.startColumn<=n)}function da(i,e,n,t){return t.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&e<=o.startRow&&o.startRow<=n)}function ua(i){let e=0;return i.forValue((n,t,o)=>{if(o&&e++,e>1)return!1}),e>1}function yo(){return{p:null,v:null,s:null,f:null,si:null,t:null}}function Oo(i){return ie(i)&&!i.getContextValue(a.EDITOR_ACTIVATED)}const mi=998,xo={id:I.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:mi,preconditions:Oo,handler:async i=>i.get(ut).copy()},ha={id:I.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:mi,preconditions:ri,handler:async i=>i.get(ut).cut()},ht={id:I.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:mi,preconditions:Oo,handler:async(i,e)=>{const n=i.get(a.ILogService);if(n.debug("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){n.debug("[SheetPasteCommand]","failed to execute paste command on the activeElement, trying to use clipboard API.");const r=await i.get(I.IClipboardInterfaceService).read(),s=i.get(ut);return r.length!==0?s.paste(r[0],e==null?void 0:e.value):!1}return!1}},Ao={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_VALUE})},Do={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_FORMAT})},No={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_COL_WIDTH})},Po={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_BESIDES_BORDER})};var ma=Object.defineProperty,Sa=Object.getOwnPropertyDescriptor,_a=(i,e,n,t)=>{for(var o=t>1?void 0:t?Sa(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ma(e,n,o),o},Ho=(i,e)=>(n,t)=>e(n,t,i);let Ut=class{constructor(i,e){C(this,"_current",null);C(this,"_shortcutParam",[]);this._currentUniverService=i,this._localeService=e}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const e=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(e!=null){const n=this._shortcutParam.indexOf(e);this._shortcutParam.splice(n,1)}return this._shortcutParam.push(i),e}remove(i){if(i==null)return;const e=this._getCurrentBySearch(i);if(e==null)return;const n=this._shortcutParam.indexOf(e);return this._shortcutParam.splice(n,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(n=>n.unitId===i.unitId&&n.sheetId===i.sheetId&&n.keycode===i.keycode)}};Ut=_a([Ho(0,a.IUniverInstanceService),Ho(1,N.Inject(a.LocaleService))],Ut);function Ke(i,e,n,t,o=!0,r=1,s=!0){let l={...i};t==null&&(t={startRow:0,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1});let c;switch(e){case a.Direction.UP:for(c=i.startRow-r;c>-1&&!n.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,o&&(l=Ke(l,a.Direction.LEFT,n,t,!1)));break;case a.Direction.DOWN:for(c=i.endRow+r;c<n.getRowCount()&&!n.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,o&&(l=Ke(l,a.Direction.RIGHT,n,t,!1)));break;case a.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!n.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,o&&(l=Ke(l,a.Direction.UP,n,t,!1)));break;case a.Direction.RIGHT:for(c=i.endColumn+r;c<n.getColumnCount()&&!n.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,o&&(l=Ke(l,a.Direction.DOWN,n,t,!1)));break}return l}function Si(i,e,n){const t={...i},{startRow:o,startColumn:r,endRow:s,endColumn:l}=kt(i,e,n);let c=Vt(n,o,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===e){let h=t.startRow-1;for(;h>-1&&!n.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:S}=Vt(n,h,t.startColumn,h,t.endColumn);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let _=h;S.forValue(f=>{_=Math.min(f,_)}),t.startRow=_}else t.startRow=h;if(t.endRow=t.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.DOWN===e){let h=t.endRow+1;for(;h<n.getRowCount()&&!n.getRowVisible(h);)h+=1;if(h===n.getRowCount()){u=!1;break}const{hasValue:m,matrix:S}=Vt(n,h,t.startColumn,h,t.endColumn);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let _=h;S.forValue((f,v,M)=>{_=Math.max(f+(M.rowSpan||1)-1,_)}),t.endRow=_}else t.endRow=h;if(t.startRow=t.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.LEFT===e){let h=t.startColumn-1;for(;h>-1&&!n.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:S}=Vt(n,t.startRow,h,t.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let _=h;S.forValue((f,v)=>{_=Math.min(v,_)}),t.startColumn=_}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.RIGHT===e){let h=t.endColumn+1;for(;h<n.getColumnCount()&&!n.getColVisible(h);)h+=1;if(h===n.getColumnCount()){u=!1;break}const{hasValue:m,matrix:S}=Vt(n,t.startRow,h,t.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let _=h;S.forValue((f,v,M)=>{_=Math.max(v+(M.colSpan||1)-1,_)}),t.endColumn=_}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return g.alignToMergedCellsBorders(t,n,!0)}function Lo(i,e,n){return Ke(i,e,n,void 0,!1,1,!1)}function ga(i,e,n){const t=Si(i,e,n);return g.alignToMergedCellsBorders(a.Rectangle.union(t,i),n,!0)}function fa(i,e,n){const t=Lo(i,e,n),o={startRow:Math.min(i.startRow,t.startRow),startColumn:Math.min(i.startColumn,t.startColumn),endRow:Math.max(i.endRow,t.endRow),endColumn:Math.max(i.endColumn,t.endColumn)};return g.alignToMergedCellsBorders(a.Rectangle.union(i,o),n)}function pa(i,e,n,t){const o=a.getReverseDirection(n),r=Si(kt(i,o,t),n,t);return n===a.Direction.UP&&r.startRow<=i.startRow?g.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):n===a.Direction.DOWN&&r.endRow>=i.endRow?g.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):n===a.Direction.LEFT&&r.startColumn<=i.startColumn?g.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},t,!0):n===a.Direction.RIGHT&&r.endColumn>=i.endColumn?g.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(e),r)}function va(i,e,n){const t=a.getReverseDirection(e),o=kt(i,t,n),r=kt(i,e,n),s=Lo(o,e,n);return g.alignToMergedCellsBorders(a.Rectangle.union(r,s),n,!1)}function Ca(i,e,n){const{left:t,right:o,up:r,down:s}=e,l=n.getMaxRows(),c=n.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;n.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((S,_,f)=>{f.v&&(u.startRow=Math.min(S,u.startRow),u.startColumn=Math.min(_,u.startColumn),u.endColumn=Math.max(_,u.endColumn),d=!0)})}if(s&&u.endRow!==l-1){const h=u.endRow+1;n.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((S,_,f)=>{f.v&&(u.endRow=Math.max(S+(f.rowSpan!==void 0?f.rowSpan-1:0),u.endRow),u.startColumn=Math.min(_,u.startColumn),u.endColumn=Math.max(_,u.endColumn),d=!0)})}if(t&&u.startColumn!==0){const h=u.startColumn-1;n.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((S,_,f)=>{f.v&&(u.startColumn=Math.min(_,u.startColumn),u.startRow=Math.min(S,u.startRow),u.endRow=Math.max(S,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;n.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((S,_,f)=>{f.v&&(u.endColumn=Math.max(_+(f.colSpan!==void 0?f.colSpan-1:0),u.endColumn),u.startRow=Math.min(S,u.startRow),u.endRow=Math.max(S,u.endRow),d=!0)})}}return u}function Uo(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function kt(i,e,n){let t;switch(e){case a.Direction.UP:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return g.alignToMergedCellsBorders(t,n,!1)}function Vt(i,e,n,t,o){let r=!1;const s=i.getMatrixWithMergedCells(e,n,t,o).forValue((l,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function _i(i,e,n){const t=a.Rectangle.clone(i);if(e==null)return t;switch(n){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=e.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=e.actualRow;break}return t}function Ia(i,e,n){const{primary:t,range:o}=i,r=a.Rectangle.clone(o);switch(e){case a.Direction.UP:case a.Direction.DOWN:r.startRow=t.startRow,r.endRow=t.endRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=t.startColumn,r.endColumn=t.endColumn;break}const s=kt(r,e,n);switch(e){case a.Direction.DOWN:return o.startRow<s.startRow;case a.Direction.UP:return o.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<o.endColumn;case a.Direction.RIGHT:return s.startColumn>o.startColumn}}function ko(i,e){let n=i[0].startRow,t=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:l}=r;n=Math.min(n,s),t=Math.max(t,l)});const o=new Array(t-n+1).fill(!1);return e.forEach(r=>{const{startRow:s,endRow:l}=r;for(let c=Math.max(s,n);c<=Math.min(l,t);c++)o[c-n]=!0}),i.every(r=>{const{startRow:s,endRow:l}=r;for(let c=s;c<=l;c++)if(!o[c-n])return!1;return!0})}function Vo(i,e){let n=i[0].startColumn,t=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:l}=r;n=Math.min(n,s),t=Math.max(t,l)});const o=new Array(t-n+1).fill(!1);return e.forEach(r=>{const{startColumn:s,endColumn:l}=r;for(let c=Math.max(s,n);c<=Math.min(l,t);c++)o[c-n]=!0}),i.every(r=>{const{startColumn:s,endColumn:l}=r;for(let c=s;c<=l;c++)if(!o[c-n])return!1;return!0})}var Ae=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(Ae||{});const Re={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=e,{range:l,primary:c}=o,d=_i(l,c,r),u=s===1?Si(d,r,t):Ke(d,r,t),h=g.getCellAtRowCol(u.startRow,u.startColumn,t);return a.Rectangle.equals(h,d)?!1:(i.get(Ut).remove({unitId:n.getUnitId(),sheetId:t.getSheetId(),keycode:I.KeyCode.TAB}),i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:a.Rectangle.clone(h),primary:{startRow:h.startRow,startColumn:h.startColumn,endRow:h.endRow,endColumn:h.endColumn,actualRow:u.startRow,actualColumn:u.startColumn,isMerged:h.isMerged,isMergedMainCell:h.startRow===u.startRow&&h.startColumn===u.startColumn}}]}))}},it={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast(),r=n.getUnitId(),s=t.getSheetId();if(!o)return!1;const{direction:l,keycode:c}=e,{range:d,primary:u}=o;let h=_i(d,u,l);const m=i.get(Ut),S=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});let _;const{startRow:f,endRow:v,startColumn:M,endColumn:R}=d;if(a.Rectangle.equals(d,u)){if(c===I.KeyCode.TAB)S==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:I.KeyCode.TAB,selection:o});else{const E=S==null?void 0:S.selection;if(E!=null){const{range:y,primary:x}=E;h=_i(y,x,l)}m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB})}const T=Ke(h,l,t),w=g.getCellAtRowCol(T.startRow,T.startColumn,t);if(a.Rectangle.equals(w,h))return!1;_={range:a.Rectangle.clone(w),primary:{startRow:w.startRow,startColumn:w.startColumn,endRow:w.endRow,endColumn:w.endColumn,actualRow:T.startRow,actualColumn:T.startColumn,isMerged:w.isMerged,isMergedMainCell:w.startRow===T.startRow&&w.startColumn===T.startColumn}}}else{m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});const T=a.Tools.deepClone(u),w=Ke({startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn},l,t,{startRow:f,endRow:v,startColumn:M,endColumn:R}),E=g.getCellAtRowCol(w.startRow,w.startColumn,t);_={range:a.Rectangle.clone(d),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:w.startRow,actualColumn:w.startColumn,isMerged:E.isMerged,isMergedMainCell:E.startRow===w.startRow&&E.startColumn===w.startColumn}}}return i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:r,subUnitId:s,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[_]})}},De={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:l,direction:c}=e,u=Ia(o,c,t)?l===1?pa(r,{...a.Rectangle.clone(s),rangeType:a.RANGE_TYPE.NORMAL},c,t):va(r,c,t):l===1?ga(r,c,t):fa(r,c,t);return a.Rectangle.equals(u,r)?!1:i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let Ne=[],gi="";const Bo={id:"sheet.command.select-all",type:a.CommandType.COMMAND,onDispose(){Ne=[],gi=""},handler:async(i,e={expandToGapFirst:!0,loop:!1})=>{const n=i.get(g.SelectionManagerService).getLast(),t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=t.getActiveSheet();if(!n||!o)return!1;const r=`${t.getUnitId()}|${o.getSheetId()}`;r!==gi&&(Ne=[],gi=r);const s=o.getMaxRows(),l=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=e,{range:u,primary:h}=n,m=u.endColumn===l-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;Ne.some(_=>a.Rectangle.equals(_,u))||(Ne=[],Ne.push(u));let S;if(m)if(d){if(Ne.findIndex(f=>a.Rectangle.equals(f,u))!==Ne.length-1)return!1;S=Ne[0]}else return!1;else c?(S=Ca(u,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(S,u)&&(S=Uo(o))):S=Uo(o);return Ne.some(_=>a.Rectangle.equals(_,S))||Ne.push(S),i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:o.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:S,primary:h}]})}};var Ma=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,ba=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ra(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ma(e,n,o),o},Sn=(i,e)=>(n,t)=>e(n,t,i);const wa=a.createInterceptorKey("BEFORE_CELL_EDIT"),Ta=a.createInterceptorKey("AFTER_CELL_EDIT");A.EditorBridgeService=class extends a.Disposable{constructor(n,t,o,r){super();C(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);C(this,"_isForceKeepVisible",!1);C(this,"_editorIsDirty",!1);C(this,"_visible",{visible:!1,eventType:b.DeviceInputEventType.Dblclick});C(this,"_currentEditCell",null);C(this,"_currentEditCellState",null);C(this,"_currentEditCellState$",new P.BehaviorSubject(null));C(this,"currentEditCellState$",this._currentEditCellState$.asObservable());C(this,"_visible$",new P.BehaviorSubject(this._visible));C(this,"visible$",this._visible$.asObservable());C(this,"_afterVisible$",new P.BehaviorSubject(this._visible));C(this,"afterVisible$",this._afterVisible$.asObservable());C(this,"interceptor",new a.InterceptorManager({BEFORE_CELL_EDIT:wa,AFTER_CELL_EDIT:Ta}));this._sheetSkeletonManagerService=n,this._selectionRenderService=t,this._themeService=o,this._currentUniverService=r,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:s=>s}))),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:s=>s})))}refreshEditCellState(){const n=this.getLatestEditCellState();this._currentEditCellState=n,this._currentEditCellState$.next(n)}setEditCell(n){this._currentEditCell=n;const t=this.getLatestEditCellState();this._currentEditCellState=t,this._currentEditCellState$.next(t)}getEditCellState(){return this._currentEditCellState}getLatestEditCellState(){var W,z;const n=this._currentEditCell;if(n==null)return;const t=this._sheetSkeletonManagerService.getCurrent();if(t==null)return;const{skeleton:o}=t,{primary:r,unitId:s,sheetId:l,scene:c,engine:d}=n,{startRow:u,startColumn:h}=r,m=this._selectionRenderService.convertCellRangeToInfo(r);if(m==null)return;const S=a.makeCellToSelection(m);if(S==null)return;const _=b.getCanvasOffsetByEngine(d);let{startX:f,startY:v,endX:M,endY:R}=S;const{scaleX:T,scaleY:w}=c.getAncestorScale(),{scaleX:E,scaleY:y}=c.getPrecisionScale(),x=c.getScrollXY(this._selectionRenderService.getViewPort());f=b.fixLineWidthByScale(o.convertTransformToOffsetX(f,T,x),E),v=b.fixLineWidthByScale(o.convertTransformToOffsetY(v,w,x),y),M=b.fixLineWidthByScale(o.convertTransformToOffsetX(M,T,x),E),R=b.fixLineWidthByScale(o.convertTransformToOffsetY(R,w,x),y);const O=this._currentUniverService.getCurrentUniverSheetInstance(),D=O.getActiveSheet(),B={workbook:O,worksheet:D,unitId:O.getUnitId(),subUnitId:D.getSheetId(),row:u,col:h},H=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(D.getCell(u,h),B);let F=H&&o.getCellDocumentModelWithFormula(H);if((!F||F.documentModel==null)&&(F=o.getBlankCellDocumentModel(H)),(W=F.documentModel)==null||W.setZoomRatio(Math.max(T,w)),(H==null?void 0:H.isInArrayFormulaRange)===!0){const Y=(z=F.documentModel)==null?void 0:z.getBody();Y&&(Y.textRuns=[{st:0,ed:Y.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:f,startY:v,endX:M,endY:R},scaleX:T,scaleY:w,canvasOffset:_,row:u,column:h,unitId:s,sheetId:l,documentLayoutObject:F,editorUnitId:this._editorUnitId,isInArrayFormulaRange:H==null?void 0:H.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(n){this._visible=n,n.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._isForceKeepVisible=!0}disableForceKeepVisible(){this._isForceKeepVisible=!1}isForceKeepVisible(){return this._isForceKeepVisible}changeEditorDirty(n){this._editorIsDirty=n}getEditorDirty(){return this._editorIsDirty}},A.EditorBridgeService=ba([Sn(0,N.Inject(A.SheetSkeletonManagerService)),Sn(1,_e),Sn(2,N.Inject(a.ThemeService)),Sn(3,a.IUniverInstanceService)],A.EditorBridgeService);const be=N.createIdentifier("univer.sheet-editor-bridge.service"),Pe={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(i,e)=>{const n=i.get(be);return e==null?!1:(n.changeVisible(e),!0)}},Bt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0};class Je{constructor(){C(this,"_scrollInfo",new Map);C(this,"_currentScroll",null);C(this,"_scrollInfo$",new P.BehaviorSubject(null));C(this,"scrollInfo$",this._scrollInfo$.asObservable())}dispose(){this._scrollInfo$.complete()}setCurrentScroll(e){this._currentScroll=e,this._refresh(e)}getScrollByParam(e){return this._getCurrentScroll(e)}getCurrentScroll(){return this._getCurrentScroll(this._currentScroll)}addOrReplace(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e})}addOrReplaceNoRefresh(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e},!1)}addOrReplaceByParam(e){this._addByParam(e)}clear(){this._currentScroll!=null&&this._clearByParam(this._currentScroll)}_addByParam(e,n=!0){const{unitId:t,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:l,offsetY:c}=e;this._scrollInfo.has(t)||this._scrollInfo.set(t,new Map),this._scrollInfo.get(t).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:l,offsetY:c}),n===!0&&this._refresh({unitId:t,sheetId:o})}_clearByParam(e){this._addByParam({...e,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._refresh(e)}_getCurrentScroll(e){var o;if(e==null)return;const{unitId:n,sheetId:t}=e;return(o=this._scrollInfo.get(n))==null?void 0:o.get(t)}_refresh(e){this._scrollInfo$.next(this._getCurrentScroll(e))}}const mt={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(i,e)=>{if(e==null)return!1;const n=i.get(Je),r=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.sheetId),{xSplit:s,ySplit:l}=r.getConfig().freeze;return n.addOrReplaceByParam({...e,sheetViewStartRow:e.sheetViewStartRow-l,sheetViewStartColumn:e.sheetViewStartColumn-s}),!0}},_n={id:"sheet.operation.set-editor-resize",type:a.CommandType.OPERATION,handler:(i,e)=>!0},Be={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,e)=>{const n=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId),t=n==null?void 0:n.getSheetBySheetId(e.subUnitId);return t==null?!1:(t.getConfig().zoomRatio=e.zoomRatio,!0)}};var Fo={exports:{}},gn={};/**
4
+ `)}]}}function ai(i){const e=i.style,n={},t=i.tagName.toLowerCase();switch(t){case"b":case"em":case"strong":{n.bl=a.BooleanNumber.TRUE;break}case"s":{n.st={s:a.BooleanNumber.TRUE};break}case"u":{n.ul={s:a.BooleanNumber.TRUE};break}case"i":{n.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{n.va=t==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{n.ff=s;break}case"font-size":{const l=Number.parseInt(s);Number.isNaN(l)||s.endsWith("pt")&&(n.fs=l);break}case"font-style":{s==="italic"&&(n.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(n.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?n.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?n.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(n.st={s:a.BooleanNumber.TRUE});break}case"color":{const l=new a.ColorKit(s);l.isValid&&(n.cl={rgb:l.toRgbString()});break}case"background-color":{const l=new a.ColorKit(s);l.isValid&&(n.bg={rgb:l.toRgbString()});break}}}return n}function js(i){const e=new DOMParser,n=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(n,"text/html").querySelector("#univer-root")}function zs(i){const e=i.style,n={};for(let t=0;t<e.length;t++){const o=e[t],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=Number.parseInt(r);n.spaceAbove=/pt/.test(r)?wo(s):s;break}case"margin-bottom":{const s=Number.parseInt(r);n.spaceBelow=/pt/.test(r)?wo(s):s;break}}}return Object.getOwnPropertyNames(n).length?n:null}function wo(i){return i/.75}function To(i,e){const n=[];for(let t=0,o=i.length;t<o;t++)i[t]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:t});if(e)for(const t of n)e.bullet&&(t.bullet=a.Tools.deepClone(e.bullet)),e.paragraphStyle&&(t.paragraphStyle=a.Tools.deepClone(e.paragraphStyle));return n}function Eo(i,e){const n=i.tagName.toLowerCase();return typeof e=="string"?n===e:Array.isArray(e)?e.some(t=>t===n):e(i)}const ti=class ti{constructor(e){C(this,"styleCache",new Map);C(this,"styleRules",[]);C(this,"afterProcessRules",[]);C(this,"getCurrentSkeleton");this.getCurrentSkeleton=e.getCurrentSkeleton}static use(e){if(this.pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this.pluginList.push(e)}convert(e){const n=ti.pluginList.find(_=>_.checkPasteType(e));n&&(this.styleRules=[...n.stylesRules],this.afterProcessRules=[...n.afterProcessRules]);const t=new a.ObjectMatrix,o=js(e),r={dataStream:"",textRuns:[]},s=[],l=[],c=e.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,o==null?void 0:o.childNodes,r,d);const{paragraphs:u,dataStream:h,textRuns:m}=r;if(u){const _=u.map(S=>S.startIndex+1);_.unshift(0);for(let S=0;S<_.length;S++){let f;S===_.length-1?f=`${h.substring(_[S])}\r
5
+ `:f=`${h.substring(_[S],_[S+1]-1)}\r
6
+ `;const v=[];m==null||m.forEach(R=>{R.st>=_[S]&&R.ed<=_[S+1]&&v.push({st:R.st-_[S],ed:R.ed-_[S],ts:R.ts})});const M=this._generateDocumentDataModelSnapshot({body:{dataStream:f,textRuns:v,paragraphs:To(f)}});t.setValue(t.getLength(),0,{v:f,p:M}),s.push({}),c&&d.forEach(R=>{const T=t.getDataRange().endRow+1;if(R.index===S){const E=c.shift(),{cellMatrix:w,colProperties:y,rowProperties:O}=this._parseTable(E);w&&w.forValue((x,N,F)=>{t.setValue(T+x,N,F)}),y&&l.push(...y),s.push(...O)}})}}else{if(h){const _=`${h}\r
7
+ `,S={dataStream:_,textRuns:m,paragraphs:To(_)},f=this._generateDocumentDataModelSnapshot({body:S});t.setValue(0,0,{v:h,p:f}),s.push({})}c&&c.forEach(_=>{const S=t.getDataRange().endRow+1,{cellMatrix:f,rowProperties:v,colProperties:M}=this._parseTable(_);f&&f.forValue((R,T,E)=>{const{rowSpan:w=1,colSpan:y=1}=E;for(let O=0;O<w;O++)for(let x=0;x<y;x++)t.setValue(S+R+O,T+x,{v:""});t.setValue(S+R,T,E)}),M&&l.push(...M),s.push(...v)})}return{rowProperties:s,colProperties:l,cellMatrix:t}}_parseTable(e){const n=new a.ObjectMatrix,t=$s(e),{rowProperties:o,rowCount:r,cellMatrix:s}=Ys(e);return s&&s.forValue((l,c,d)=>{var h;const u=I.handleStringToStyle(void 0,(h=d.properties)==null?void 0:h.style);if(/\r|\n/.test(d.content)){const m=bo(d.content),_=this._generateDocumentDataModelSnapshot({body:m});n.setValue(l,c,{v:d.content,p:_,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}else n.setValue(l,c,{v:d.content,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}),{rowProperties:o,colProperties:t,cellMatrix:n}}_generateDocumentDataModelSnapshot(e){var l;const n=this.getCurrentSkeleton();if(n==null)return null;const{skeleton:t}=n,o=(l=t.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...o==null?void 0:o.getSnapshot(),...e};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(e,n,t,o){var r,s;for(const l of n)if(l.nodeName.toLowerCase()==="table")o.push({index:((r=t==null?void 0:t.paragraphs)==null?void 0:r.length)||0});else if(l.nodeType===Node.TEXT_NODE){const c=(s=l.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let d;e&&this.styleCache.has(e)&&(d=this.styleCache.get(e));const u={dataStream:"",textRuns:[]};t.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(t.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:d}),u.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:d}))}else if(l.nodeType===Node.ELEMENT_NODE){const c=e?this.styleCache.get(e):{},d=this.styleRules.find(({filter:_})=>Eo(l,_)),u=d?d.getStyle(l):ai(l);this.styleCache.set(l,{...c,...u});const{childNodes:h}=l;this.process(l,h,t,o);const m=this.afterProcessRules.find(({filter:_})=>Eo(l,_));m&&m.handler(t,l)}}};C(ti,"pluginList",[]);let Lt=ti;function Ys(i){const e=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,n=i.matchAll(e);if(!n)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const t=Array.from(n),o=t.map(l=>li(l[1])),{colCount:r,cellMatrix:s}=Xs(t.map(l=>l[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function Xs(i){const e=new a.ObjectMatrix,n=new Map,t=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((l,c)=>{const d=c===0,u=l.matchAll(t);r=0,Array.from(u).forEach(h=>{const m=li(h[1]),_=Zs(h[2].replace("<br>","\r").replace(/<\/?[^>]*>/g,"")),S=m.rowspan?+m.rowspan:1,f=m.colspan?+m.colspan:1;if(!d){for(let M=r;M<o;M++)if(!(n.get(M)>=s)){r=M;break}}const v={content:_,properties:m};f>1&&(v.colSpan=+f),S>1&&(v.rowSpan=+S),d&&(o+=f);for(let M=r;M<r+f;M++)n.set(M,s+S-1);e.setValue(s,r,v),r+=f}),s+=1}),{colCount:o,cellMatrix:e}}function li(i){if(!i)return{};const e=/([\w-]+)="([^"]*)"/gi,n=i.matchAll(e),t={};return Array.from(n).forEach(o=>{const[r,s,l]=o;t[s]=l}),t}function $s(i){const e=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,n=i.match(e);if(!n||!n[2])return null;const t=/<col([\s\S]*?)>/g,o=n[2].matchAll(t);return o?Array.from(o).map(r=>li(r[1])):null}function Zs(i){const e={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return i.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,n=>e[n])}const Gs={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=ai(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},Ks={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=ai(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const n={startIndex:i.dataStream.length},t=zs(e);t&&(n.paragraphStyle=t),i.paragraphs.push(n),i.dataStream+="\r"}}]};function Js(i,e,n,t){const o=n.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=ci(o),s=di(r),l=e.map(c=>Qs(i,c,n,t)).filter(c=>!!c).join("");return`<tr${s}>${l}</tr>`}function Qs(i,e,n,t){const o=t.getValue(i,e),r=n.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,i,e,o==null?void 0:o.rowSpan,o==null?void 0:o.colSpan)}).filter(d=>!!d),s=ci(r),l=di(s),c=n.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,e))||""},"");return`<td${l}>${c}</td>`}function qs(i,e){return`<colgroup>${i.map(t=>{const o=e.map(l=>{var c;return(c=l.onCopyColumn)==null?void 0:c.call(l,t)}).filter(l=>!!l),r=ci(o);return`<col ${di(r)}>`}).join("")}</colgroup>`}function ci(i){return i.reduce((e,n)=>(Object.keys(n).forEach(o=>{e[o]?e[o]+=`;${n[o]}`:e[o]=n[o]}),e),{})}function di(i){return Object.keys(i).reduce((e,n)=>(e+=` ${n}="${i[n]}"`,e),"")}function ea(i,e){const n=[];for(let t=i;t<=e;t++)n.push(t);return n}class ta{convert(e,n,t){const{startColumn:o,endColumn:r}=n,s=qs(ea(o,r),t),l=[],{startRow:c,endRow:d,startColumn:u,endColumn:h}=e.getDataRange();for(let _=c;_<=d;_++){const S=Array.from({length:h-u+1},(f,v)=>u+v);l.push(Js(_,S,t,e))}return`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
8
+ <tbody>${l.join("")}</tbody></table>`}}var na=Object.defineProperty,ia=Object.getOwnPropertyDescriptor,oa=(i,e,n,t)=>{for(var o=t>1?void 0:t?ia(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&na(e,n,o),o},Ge=(i,e)=>(n,t)=>e(n,t,i);const pe={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border"};Lt.use(Ks),Lt.use(Gs);const ut=D.createIdentifier("sheet.clipboard-service");A.SheetClipboardService=class extends a.Disposable{constructor(n,t,o,r,s,l,c,d){super();C(this,"_clipboardHooks",[]);C(this,"_clipboardHooks$",new P.BehaviorSubject([]));C(this,"clipboardHooks$",this._clipboardHooks$.asObservable());C(this,"_htmlToUSM");C(this,"_usmToHtml");C(this,"_copyContentCache");C(this,"_copyMarkId",null);this._logService=n,this._currentUniverService=t,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=l,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Lt({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new ta,this._copyContentCache=new Bs}copyContentCache(){return this._copyContentCache}async copy(n=nt.COPY){const t=this._selectionManagerService.getLast();if(!t)return!1;const o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=this._clipboardHooks;s.forEach(_=>{var S;return(S=_.onBeforeCopy)==null?void 0:S.call(_,o.getUnitId(),r.getSheetId(),t.range)});const l=this._generateCopyContent(o.getUnitId(),r.getSheetId(),t.range,s);if(!l)return!1;const{html:c,plain:d,matrixFragment:u,copyId:h}=l;this._copyContentCache.set(h,{unitId:o.getUnitId(),subUnitId:r.getSheetId(),range:t.range,matrix:u,copyType:n}),await this._clipboardInterfaceService.write(d,c),this._markSelectionService.removeAllShapes();const m=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...t,style:m}),s.forEach(_=>{var S;return(S=_.onAfterCopy)==null?void 0:S.call(_)}),!0}async cut(){return this.copy(nt.CUT)}async paste(n,t=pe.DEFAULT_PASTE){const o=n.types,r=o.indexOf(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await n.getType(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"",s=o.indexOf(I.HTML_CLIPBOARD_MIME_TYPE)!==-1?await n.getType(I.HTML_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"";return s?this._pasteHTML(s,t):r?this._pastePlainText(r,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(n,t){return n?this._pasteHTML(n,pe.DEFAULT_PASTE):t?this._pastePlainText(t,pe.DEFAULT_PASTE):Promise.resolve(!1)}addClipboardHook(n){if(this._clipboardHooks.findIndex(o=>o.id===n.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",n.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(n.priority||0)<r});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,n),this._notifyClipboardHook(),a.toDisposable(()=>{const o=this._clipboardHooks.indexOf(n);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(n,t,o,r){const s=this._currentUniverService.getUniverSheetInstance(n),l=s==null?void 0:s.getSheetBySheetId(t);if(!s||!l)return null;r.reduce((M,R)=>{var E;const T=(E=R.getFilteredOutRows)==null?void 0:E.call(R);return T==null||T.forEach(w=>M.add(w)),M},new Set);const{startColumn:c,startRow:d,endColumn:u,endRow:h}=o,m=l.getMatrixWithMergedCells(d,c,h,u),_=new a.ObjectMatrix;for(let M=d;M<=h;M++)for(let R=c;R<=u;R++){const T=m.getValue(M,R);T?_.setValue(M-d,R-c,{...yo(),...a.Tools.deepClone(T)}):_.setValue(M-d,R-c,yo())}let S=this._usmToHtml.convert(m,o,r);const f=ra(_),v=ks();return S=S.replace(/(<[a-z]+)/,(M,R)=>`${R} data-copy-id="${v}"`),{copyId:v,plain:f,html:S,matrixFragment:_}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(n,t){const o=this._getPastingTarget();if(!o.selection)return!1;const r=o.selection.range,{unitId:s,subUnitId:l}=o,c=this._clipboardHooks,d=[];if(c.some(S=>{var f;return d.push(S)&&((f=S.onBeforePaste)==null?void 0:f.call(S,{unitId:s,subUnitId:l,range:r}))===!1}))return d.forEach(S=>{var f;return(f=S.onAfterPaste)==null?void 0:f.call(S,!1)}),!1;const h=[],m=[];d.forEach(S=>{var v;const f=(v=S.onPastePlainText)==null?void 0:v.call(S,{unitId:s,subUnitId:l,range:r},n,{pasteType:t});f&&(h.push(...f.redos),m.push(...f.undos))});const _=h.every(S=>this._commandService.executeCommand(S.id,S.params));return _&&this._undoRedoService.pushUndoRedo({unitID:this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),undoMutations:m,redoMutations:h}),_}async _pasteHTML(n,t){const o=Vs(n);return o&&this._copyContentCache.get(o)?this._pasteInternal(o,t):this._pasteExternal(n,t)}async _pasteExternal(n,t){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(n),{startColumn:h,endColumn:m,startRow:_,endRow:S}=u.getDataRange(),f=S-_+1,v=m-h+1;if(!u||m<h||S<_)return!1;const M=this._transformPastedData(f,v,u,r.range);return M?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:l,pastedRange:M},t):!1}async _pasteInternal(n,t){var L,W;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o,c=a.Tools.deepClone(this._copyContentCache.get(n)),{range:d,matrix:u,unitId:h,subUnitId:m}=c||{};if(!r||!u||!c||!d||!h||!m||!r||!u||!c)return!1;const _=(L=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:L.getStyles();u.forValue((B,z,Y)=>{if(typeof Y.s=="string"){const J=a.Tools.deepClone(Y);J.s=_==null?void 0:_.getStyleByCell(Y),u.setValue(B,z,J)}});const{startColumn:S,endColumn:f,startRow:v,endRow:M}=d,R=this._transformPastedData(M-v+1,f-S+1,u,r.range);if(!R)return!1;const T=(W=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:W.getSheetBySheetId(m);if(!T)return!1;const E=T.getColumnManager(),w=T.getRowManager(),y=T.getConfig().defaultColumnWidth,O=T.getConfig().defaultRowHeight,x=[],N=[];for(let B=S;B<=f;B++){const z=E.getColumnOrCreate(B);x.push({width:`${z.w||y}`})}for(let B=v;B<=M;B++){const z=w.getRowOrCreate(B);N.push({height:`${z.h||O}`})}const F=this._pasteUSM({cellMatrix:u,colProperties:x,rowProperties:N},{unitId:s,subUnitId:l,pastedRange:R},t,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:n});return c.copyType===nt.CUT&&(this._copyContentCache.set(n,{...c,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),F}_pasteUSM(n,t,o,r){const{rowProperties:s,colProperties:l,cellMatrix:c}=n,{unitId:d,subUnitId:u,pastedRange:h}=t,{startColumn:m,endColumn:_}=h,S=_-m+1,f=this._clipboardHooks,v=[];if(f.some(N=>{var F;return v.push(N)&&((F=N.onBeforePaste)==null?void 0:F.call(N,{unitId:d,subUnitId:u,range:h}))===!1}))return v.forEach(N=>{var F;return(F=N.onAfterPaste)==null?void 0:F.call(N,!1)}),!1;if(!c)return!1;const R=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,T={copyType:(r==null?void 0:r.copyType)||nt.COPY,copyId:r==null?void 0:r.copyId,pasteType:o},E=[],w=[];v.filter(N=>!N.specialPasteInfo&&N.id!==pe.DEFAULT_PASTE||o===N.id).forEach(N=>{var W,B,z;if(s){const Y=(W=N.onPasteRows)==null?void 0:W.call(N,{range:h,unitId:d,subUnitId:u},s,{pasteType:o});Y&&(E.push(...Y.redos),w.push(...Y.undos))}const F=(B=N.onPasteColumns)==null?void 0:B.call(N,{range:h,unitId:d,subUnitId:u},l||new Array(S).map(()=>({})),{pasteType:o});F&&(E.push(...F.redos),w.push(...F.undos));const L=(z=N.onPasteCells)==null?void 0:z.call(N,R,{range:h,unitId:d,subUnitId:u},c,T);L&&(E.push(...L.redos),w.push(...L.undos))});const O=this._getSetSelectionOperation(d,u,h,c);O&&E.push(O),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:w,redoMutationsInfo:E});const x=E.every(N=>this._commandService.executeCommand(N.id,N.params));return x&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:w,redoMutations:E}),x}_getSetSelectionOperation(n,t,o,r){var f;const s=(f=this._currentUniverService.getUniverSheetInstance(n))==null?void 0:f.getSheetBySheetId(t);if(!s)return null;const{startRow:l,startColumn:c}=o,d={startRow:l,endRow:l,startColumn:c,endColumn:c},u=g.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,_=(h==null?void 0:h.colSpan)||1;if(m>1||_>1){const v={startRow:l,endRow:l+m-1,startColumn:c,endColumn:c+_-1};u.startRow=v.startRow,u.endRow=v.endRow,u.startColumn=v.startColumn,u.endColumn=v.endColumn,u.isMerged=!0,u.isMergedMainCell=!0}const S={unitId:n,subUnitId:t,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:g.SetSelectionsOperation.id,params:S}}_getPastingTarget(){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:n.getUnitId(),subUnitId:t.getSheetId(),selection:o}}_transformPastedData(n,t,o,r){const{startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=c-s+1,h=d-l+1,f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(w=>a.Rectangle.intersects({startRow:s,startColumn:l,endRow:c,endColumn:d},w)),v=f[0];let M=0,R=0,T=0,E=0;if(v&&(M=v.startRow,R=v.startColumn,T=v.endRow,E=v.endColumn),u%n===0&&h%t===0)if(f.length>0&&(u!==n||h!==t))if(M===s&&R===l&&T===c&&E===d)if(da(o))for(let y=0;y<u;y++)for(let O=0;O<h;O++){const x=o.getValue(y%n,O%t);x&&o.setValue(y,O,x)}else o.forValue((y,O,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan});else for(let w=0;w<u;w++)for(let y=0;y<h;y++){const O=o.getValue(w%n,y%t);O&&o.setValue(w,y,O)}else for(let w=0;w<u;w++)for(let y=0;y<h;y++){const O=o.getValue(w%n,y%t);O&&o.setValue(w,y,O)}else if(f.length>0)if(this._topLeftCellsMatch(n,t,r))r.endRow=s+n-1,r.endColumn=l+t-1;else{if(c>v.endRow||d>v.endColumn)return null;o.forValue((y,O,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan})}else r.endRow=s+n-1,r.endColumn=l+t-1;return r}_topLeftCellsMatch(n,t,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:l,startColumn:c,endRow:d,endColumn:u}=o,h=la(l+n-1,c,c+n-1,s),m=ca(c+t-1,l,l+n-1,s);return!h&&!m}},A.SheetClipboardService=oa([Ge(0,a.ILogService),Ge(1,a.IUniverInstanceService),Ge(2,D.Inject(g.SelectionManagerService)),Ge(3,I.IClipboardInterfaceService),Ge(4,a.IUndoRedoService),Ge(5,a.ICommandService),Ge(6,Ht),Ge(7,D.Inject(A.SheetSkeletonManagerService))],A.SheetClipboardService);function ra(i){let e="";return i.forRow((n,t)=>{const o=[];t.forEach(r=>{const s=i.getValue(n,r);if(s){const l=sa(s);o.push(l)}}),e+=o.join(" "),n!==i.getLength()-1&&(e+=`
9
+ `)}),e}function sa(i){const e=i.v;return aa((e==null?void 0:e.toString())||"")}const aa=i=>i.replace(/&/g,"&amp;").replace(/\uFEFF/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function la(i,e,n,t){return t.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&e<=o.startColumn&&o.startColumn<=n)}function ca(i,e,n,t){return t.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&e<=o.startRow&&o.startRow<=n)}function da(i){let e=0;return i.forValue((n,t,o)=>{if(o&&e++,e>1)return!1}),e>1}function yo(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const ui=998,Oo={id:I.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ui,preconditions:oi,handler:async i=>i.get(ut).copy()},ua={id:I.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ui,preconditions:oi,handler:async i=>i.get(ut).cut()},ht={id:I.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:ui,preconditions:oi,handler:async(i,e)=>{const n=i.get(a.ILogService);if(n.debug("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){n.debug("[SheetPasteCommand]","failed to execute paste command on the activeElement, trying to use clipboard API.");const r=await i.get(I.IClipboardInterfaceService).read(),s=i.get(ut);return r.length!==0?s.paste(r[0],e==null?void 0:e.value):!1}return!1}},xo={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_VALUE})},Ao={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_FORMAT})},No={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_COL_WIDTH})},Do={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(ht.id,{value:pe.SPECIAL_PASTE_BESIDES_BORDER})};var ha=Object.defineProperty,ma=Object.getOwnPropertyDescriptor,_a=(i,e,n,t)=>{for(var o=t>1?void 0:t?ma(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ha(e,n,o),o},Po=(i,e)=>(n,t)=>e(n,t,i);let Ut=class{constructor(i,e){C(this,"_current",null);C(this,"_shortcutParam",[]);this._currentUniverService=i,this._localeService=e}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const e=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(e!=null){const n=this._shortcutParam.indexOf(e);this._shortcutParam.splice(n,1)}return this._shortcutParam.push(i),e}remove(i){if(i==null)return;const e=this._getCurrentBySearch(i);if(e==null)return;const n=this._shortcutParam.indexOf(e);return this._shortcutParam.splice(n,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(n=>n.unitId===i.unitId&&n.sheetId===i.sheetId&&n.keycode===i.keycode)}};Ut=_a([Po(0,a.IUniverInstanceService),Po(1,D.Inject(a.LocaleService))],Ut);function Ke(i,e,n,t,o=!0,r=1,s=!0){let l={...i};t==null&&(t={startRow:0,endRow:n.getRowCount()-1,startColumn:0,endColumn:n.getColumnCount()-1});let c;switch(e){case a.Direction.UP:for(c=i.startRow-r;c>-1&&!n.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,o&&(l=Ke(l,a.Direction.LEFT,n,t,!1)));break;case a.Direction.DOWN:for(c=i.endRow+r;c<n.getRowCount()&&!n.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,o&&(l=Ke(l,a.Direction.RIGHT,n,t,!1)));break;case a.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!n.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,o&&(l=Ke(l,a.Direction.UP,n,t,!1)));break;case a.Direction.RIGHT:for(c=i.endColumn+r;c<n.getColumnCount()&&!n.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,o&&(l=Ke(l,a.Direction.DOWN,n,t,!1)));break}return l}function hi(i,e,n){const t={...i},{startRow:o,startColumn:r,endRow:s,endColumn:l}=kt(i,e,n);let c=Vt(n,o,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===e){let h=t.startRow-1;for(;h>-1&&!n.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:_}=Vt(n,h,t.startColumn,h,t.endColumn);if(c&&!m&&!d){u=!1;break}else{if(_.getLength()!==0){let S=h;_.forValue(f=>{S=Math.min(f,S)}),t.startRow=S}else t.startRow=h;if(t.endRow=t.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.DOWN===e){let h=t.endRow+1;for(;h<n.getRowCount()&&!n.getRowVisible(h);)h+=1;if(h===n.getRowCount()){u=!1;break}const{hasValue:m,matrix:_}=Vt(n,h,t.startColumn,h,t.endColumn);if(c&&!m&&!d){u=!1;break}else{if(_.getLength()!==0){let S=h;_.forValue((f,v,M)=>{S=Math.max(f+(M.rowSpan||1)-1,S)}),t.endRow=S}else t.endRow=h;if(t.startRow=t.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.LEFT===e){let h=t.startColumn-1;for(;h>-1&&!n.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:_}=Vt(n,t.startRow,h,t.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(_.getLength()!==0){let S=h;_.forValue((f,v)=>{S=Math.min(v,S)}),t.startColumn=S}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.RIGHT===e){let h=t.endColumn+1;for(;h<n.getColumnCount()&&!n.getColVisible(h);)h+=1;if(h===n.getColumnCount()){u=!1;break}const{hasValue:m,matrix:_}=Vt(n,t.startRow,h,t.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(_.getLength()!==0){let S=h;_.forValue((f,v,M)=>{S=Math.max(v+(M.colSpan||1)-1,S)}),t.endColumn=S}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return g.alignToMergedCellsBorders(t,n,!0)}function Ho(i,e,n){return Ke(i,e,n,void 0,!1,1,!1)}function Sa(i,e,n){const t=hi(i,e,n);return g.alignToMergedCellsBorders(a.Rectangle.union(t,i),n,!0)}function ga(i,e,n){const t=Ho(i,e,n),o={startRow:Math.min(i.startRow,t.startRow),startColumn:Math.min(i.startColumn,t.startColumn),endRow:Math.max(i.endRow,t.endRow),endColumn:Math.max(i.endColumn,t.endColumn)};return g.alignToMergedCellsBorders(a.Rectangle.union(i,o),n)}function fa(i,e,n,t){const o=a.getReverseDirection(n),r=hi(kt(i,o,t),n,t);return n===a.Direction.UP&&r.startRow<=i.startRow?g.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):n===a.Direction.DOWN&&r.endRow>=i.endRow?g.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):n===a.Direction.LEFT&&r.startColumn<=i.startColumn?g.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},t,!0):n===a.Direction.RIGHT&&r.endColumn>=i.endColumn?g.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(e),r)}function pa(i,e,n){const t=a.getReverseDirection(e),o=kt(i,t,n),r=kt(i,e,n),s=Ho(o,e,n);return g.alignToMergedCellsBorders(a.Rectangle.union(r,s),n,!1)}function va(i,e,n){const{left:t,right:o,up:r,down:s}=e,l=n.getMaxRows(),c=n.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;n.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((_,S,f)=>{f.v&&(u.startRow=Math.min(_,u.startRow),u.startColumn=Math.min(S,u.startColumn),u.endColumn=Math.max(S,u.endColumn),d=!0)})}if(s&&u.endRow!==l-1){const h=u.endRow+1;n.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((_,S,f)=>{f.v&&(u.endRow=Math.max(_+(f.rowSpan!==void 0?f.rowSpan-1:0),u.endRow),u.startColumn=Math.min(S,u.startColumn),u.endColumn=Math.max(S,u.endColumn),d=!0)})}if(t&&u.startColumn!==0){const h=u.startColumn-1;n.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((_,S,f)=>{f.v&&(u.startColumn=Math.min(S,u.startColumn),u.startRow=Math.min(_,u.startRow),u.endRow=Math.max(_,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;n.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((_,S,f)=>{f.v&&(u.endColumn=Math.max(S+(f.colSpan!==void 0?f.colSpan-1:0),u.endColumn),u.startRow=Math.min(_,u.startRow),u.endRow=Math.max(_,u.endRow),d=!0)})}}return u}function Lo(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function kt(i,e,n){let t;switch(e){case a.Direction.UP:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return g.alignToMergedCellsBorders(t,n,!1)}function Vt(i,e,n,t,o){let r=!1;const s=i.getMatrixWithMergedCells(e,n,t,o).forValue((l,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function mi(i,e,n){const t=a.Rectangle.clone(i);if(e==null)return t;switch(n){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=e.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=e.actualRow;break}return t}function Ca(i,e,n){const{primary:t,range:o}=i,r=a.Rectangle.clone(o);switch(e){case a.Direction.UP:case a.Direction.DOWN:r.startRow=t.startRow,r.endRow=t.endRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=t.startColumn,r.endColumn=t.endColumn;break}const s=kt(r,e,n);switch(e){case a.Direction.DOWN:return o.startRow<s.startRow;case a.Direction.UP:return o.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<o.endColumn;case a.Direction.RIGHT:return s.startColumn>o.startColumn}}function Uo(i,e){let n=i[0].startRow,t=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:l}=r;n=Math.min(n,s),t=Math.max(t,l)});const o=new Array(t-n+1).fill(!1);return e.forEach(r=>{const{startRow:s,endRow:l}=r;for(let c=Math.max(s,n);c<=Math.min(l,t);c++)o[c-n]=!0}),i.every(r=>{const{startRow:s,endRow:l}=r;for(let c=s;c<=l;c++)if(!o[c-n])return!1;return!0})}function ko(i,e){let n=i[0].startColumn,t=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:l}=r;n=Math.min(n,s),t=Math.max(t,l)});const o=new Array(t-n+1).fill(!1);return e.forEach(r=>{const{startColumn:s,endColumn:l}=r;for(let c=Math.max(s,n);c<=Math.min(l,t);c++)o[c-n]=!0}),i.every(r=>{const{startColumn:s,endColumn:l}=r;for(let c=s;c<=l;c++)if(!o[c-n])return!1;return!0})}var Ae=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(Ae||{});const Re={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=e,{range:l,primary:c}=o,d=mi(l,c,r),u=s===1?hi(d,r,t):Ke(d,r,t),h=g.getCellAtRowCol(u.startRow,u.startColumn,t);return a.Rectangle.equals(h,d)?!1:(i.get(Ut).remove({unitId:n.getUnitId(),sheetId:t.getSheetId(),keycode:I.KeyCode.TAB}),i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:a.Rectangle.clone(h),primary:{startRow:h.startRow,startColumn:h.startColumn,endRow:h.endRow,endColumn:h.endColumn,actualRow:u.startRow,actualColumn:u.startColumn,isMerged:h.isMerged,isMergedMainCell:h.startRow===u.startRow&&h.startColumn===u.startColumn}}]}))}},it={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast(),r=n.getUnitId(),s=t.getSheetId();if(!o)return!1;const{direction:l,keycode:c}=e,{range:d,primary:u}=o;let h=mi(d,u,l);const m=i.get(Ut),_=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});let S;const{startRow:f,endRow:v,startColumn:M,endColumn:R}=d;if(a.Rectangle.equals(d,u)){if(c===I.KeyCode.TAB)_==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:I.KeyCode.TAB,selection:o});else{const w=_==null?void 0:_.selection;if(w!=null){const{range:y,primary:O}=w;h=mi(y,O,l)}m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB})}const T=Ke(h,l,t),E=g.getCellAtRowCol(T.startRow,T.startColumn,t);if(a.Rectangle.equals(E,h))return!1;S={range:a.Rectangle.clone(E),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:T.startRow,actualColumn:T.startColumn,isMerged:E.isMerged,isMergedMainCell:E.startRow===T.startRow&&E.startColumn===T.startColumn}}}else{m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});const T=a.Tools.deepClone(u),E=Ke({startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn},l,t,{startRow:f,endRow:v,startColumn:M,endColumn:R}),w=g.getCellAtRowCol(E.startRow,E.startColumn,t);S={range:a.Rectangle.clone(d),primary:{startRow:w.startRow,startColumn:w.startColumn,endRow:w.endRow,endColumn:w.endColumn,actualRow:E.startRow,actualColumn:E.startColumn,isMerged:w.isMerged,isMergedMainCell:w.startRow===E.startRow&&w.startColumn===E.startColumn}}}return i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:r,subUnitId:s,pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[S]})}},Ne={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=i.get(g.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:l,direction:c}=e,u=Ca(o,c,t)?l===1?fa(r,{...a.Rectangle.clone(s),rangeType:a.RANGE_TYPE.NORMAL},c,t):pa(r,c,t):l===1?Sa(r,c,t):ga(r,c,t);return a.Rectangle.equals(u,r)?!1:i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let De=[],_i="";const Vo={id:"sheet.command.select-all",type:a.CommandType.COMMAND,onDispose(){De=[],_i=""},handler:async(i,e={expandToGapFirst:!0,loop:!1})=>{const n=i.get(g.SelectionManagerService).getLast(),t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=t.getActiveSheet();if(!n||!o)return!1;const r=`${t.getUnitId()}|${o.getSheetId()}`;r!==_i&&(De=[],_i=r);const s=o.getMaxRows(),l=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=e,{range:u,primary:h}=n,m=u.endColumn===l-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;De.some(S=>a.Rectangle.equals(S,u))||(De=[],De.push(u));let _;if(m)if(d){if(De.findIndex(f=>a.Rectangle.equals(f,u))!==De.length-1)return!1;_=De[0]}else return!1;else c?(_=va(u,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(_,u)&&(_=Lo(o))):_=Lo(o);return De.some(S=>a.Rectangle.equals(S,_))||De.push(_),i.get(a.ICommandService).executeCommand(g.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:o.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:_,primary:h}]})}};var Ia=Object.defineProperty,Ma=Object.getOwnPropertyDescriptor,Ra=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ma(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ia(e,n,o),o},mn=(i,e)=>(n,t)=>e(n,t,i);const ba=a.createInterceptorKey("BEFORE_CELL_EDIT"),wa=a.createInterceptorKey("AFTER_CELL_EDIT");A.EditorBridgeService=class extends a.Disposable{constructor(n,t,o,r){super();C(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);C(this,"_isForceKeepVisible",!1);C(this,"_editorIsDirty",!1);C(this,"_visible",{visible:!1,eventType:b.DeviceInputEventType.Dblclick});C(this,"_currentEditCell",null);C(this,"_currentEditCellState",null);C(this,"_currentEditCellState$",new P.BehaviorSubject(null));C(this,"currentEditCellState$",this._currentEditCellState$.asObservable());C(this,"_visible$",new P.BehaviorSubject(this._visible));C(this,"visible$",this._visible$.asObservable());C(this,"_afterVisible$",new P.BehaviorSubject(this._visible));C(this,"afterVisible$",this._afterVisible$.asObservable());C(this,"interceptor",new a.InterceptorManager({BEFORE_CELL_EDIT:ba,AFTER_CELL_EDIT:wa}));this._sheetSkeletonManagerService=n,this._selectionRenderService=t,this._themeService=o,this._currentUniverService=r,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:s=>s}))),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:s=>s})))}refreshEditCellState(){const n=this.getLatestEditCellState();this._currentEditCellState=n,this._currentEditCellState$.next(n)}setEditCell(n){this._currentEditCell=n;const t=this.getLatestEditCellState();this._currentEditCellState=t,this._currentEditCellState$.next(t)}getEditCellState(){return this._currentEditCellState}getLatestEditCellState(){var B,z;const n=this._currentEditCell;if(n==null)return;const t=this._sheetSkeletonManagerService.getCurrent();if(t==null)return;const{skeleton:o}=t,{primary:r,unitId:s,sheetId:l,scene:c,engine:d}=n,{startRow:u,startColumn:h}=r,m=this._selectionRenderService.convertCellRangeToInfo(r);if(m==null)return;const _=a.makeCellToSelection(m);if(_==null)return;const S=b.getCanvasOffsetByEngine(d);let{startX:f,startY:v,endX:M,endY:R}=_;const{scaleX:T,scaleY:E}=c.getAncestorScale(),{scaleX:w,scaleY:y}=c.getPrecisionScale(),O=c.getScrollXY(this._selectionRenderService.getViewPort());f=b.fixLineWidthByScale(o.convertTransformToOffsetX(f,T,O),w),v=b.fixLineWidthByScale(o.convertTransformToOffsetY(v,E,O),y),M=b.fixLineWidthByScale(o.convertTransformToOffsetX(M,T,O),w),R=b.fixLineWidthByScale(o.convertTransformToOffsetY(R,E,O),y);const x=this._currentUniverService.getCurrentUniverSheetInstance(),N=x.getActiveSheet(),F={workbook:x,worksheet:N,unitId:x.getUnitId(),subUnitId:N.getSheetId(),row:u,col:h},L=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(N.getCell(u,h),F);let W=L&&o.getCellDocumentModelWithFormula(L);if(!W||W.documentModel==null){const Y=o.getBlankCellDocumentModel(L);if(W!=null){const{verticalAlign:J,horizontalAlign:j,wrapStrategy:q,textRotation:se,fill:$}=W,{centerAngle:k,vertexAngle:U}=b.convertTextRotation(se);Y.documentModel.documentStyle.renderConfig={verticalAlign:J,horizontalAlign:j,wrapStrategy:q,background:{rgb:$},centerAngle:k,vertexAngle:U}}W=Y}if((B=W.documentModel)==null||B.setZoomRatio(Math.max(T,E)),(L==null?void 0:L.isInArrayFormulaRange)===!0){const Y=(z=W.documentModel)==null?void 0:z.getBody();Y&&(Y.textRuns=[{st:0,ed:Y.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:f,startY:v,endX:M,endY:R},scaleX:T,scaleY:E,canvasOffset:S,row:u,column:h,unitId:s,sheetId:l,documentLayoutObject:W,editorUnitId:this._editorUnitId,isInArrayFormulaRange:L==null?void 0:L.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(n){this._visible=n,n.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._isForceKeepVisible=!0}disableForceKeepVisible(){this._isForceKeepVisible=!1}isForceKeepVisible(){return this._isForceKeepVisible}changeEditorDirty(n){this._editorIsDirty=n}getEditorDirty(){return this._editorIsDirty}},A.EditorBridgeService=Ra([mn(0,D.Inject(A.SheetSkeletonManagerService)),mn(1,Se),mn(2,D.Inject(a.ThemeService)),mn(3,a.IUniverInstanceService)],A.EditorBridgeService);const be=D.createIdentifier("univer.sheet-editor-bridge.service"),Pe={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(i,e)=>{const n=i.get(be);return e==null?!1:(n.changeVisible(e),!0)}},Bt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0};class Je{constructor(){C(this,"_scrollInfo",new Map);C(this,"_currentScroll",null);C(this,"_scrollInfo$",new P.BehaviorSubject(null));C(this,"scrollInfo$",this._scrollInfo$.asObservable())}dispose(){this._scrollInfo$.complete()}setCurrentScroll(e){this._currentScroll=e,this._refresh(e)}getScrollByParam(e){return this._getCurrentScroll(e)}getCurrentScroll(){return this._getCurrentScroll(this._currentScroll)}addOrReplace(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e})}addOrReplaceNoRefresh(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e},!1)}addOrReplaceByParam(e){this._addByParam(e)}clear(){this._currentScroll!=null&&this._clearByParam(this._currentScroll)}_addByParam(e,n=!0){const{unitId:t,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:l,offsetY:c}=e;this._scrollInfo.has(t)||this._scrollInfo.set(t,new Map),this._scrollInfo.get(t).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:l,offsetY:c}),n===!0&&this._refresh({unitId:t,sheetId:o})}_clearByParam(e){this._addByParam({...e,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._refresh(e)}_getCurrentScroll(e){var o;if(e==null)return;const{unitId:n,sheetId:t}=e;return(o=this._scrollInfo.get(n))==null?void 0:o.get(t)}_refresh(e){this._scrollInfo$.next(this._getCurrentScroll(e))}}const mt={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(i,e)=>{if(e==null)return!1;const n=i.get(Je),r=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.sheetId),{xSplit:s,ySplit:l}=r.getConfig().freeze;return n.addOrReplaceByParam({...e,sheetViewStartRow:e.sheetViewStartRow-l,sheetViewStartColumn:e.sheetViewStartColumn-s}),!0}},_n={id:"sheet.operation.set-editor-resize",type:a.CommandType.OPERATION,handler:(i,e)=>!0},Be={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,e)=>{const n=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId),t=n==null?void 0:n.getSheetBySheetId(e.subUnitId);return t==null?!1:(t.getConfig().zoomRatio=e.zoomRatio,!0)}};var Bo={exports:{}},Sn={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.production.min.js
12
12
  *
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Ea=L,ya=Symbol.for("react.element"),Oa=Symbol.for("react.fragment"),xa=Object.prototype.hasOwnProperty,Aa=Ea.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Da={key:!0,ref:!0,__self:!0,__source:!0};function Wo(i,e,n){var t,o={},r=null,s=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(t in e)xa.call(e,t)&&!Da.hasOwnProperty(t)&&(o[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)o[t]===void 0&&(o[t]=e[t]);return{$$typeof:ya,type:i,key:r,ref:s,props:o,_owner:Aa.current}}gn.Fragment=Oa,gn.jsx=Wo,gn.jsxs=Wo,Fo.exports=gn;var p=Fo.exports,we=function(){return we=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},we.apply(this,arguments)},Na=function(i,e){var n={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(n[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,t=Object.getOwnPropertySymbols(i);o<t.length;o++)e.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(i,t[o])&&(n[t[o]]=i[t[o]]);return n},Me=L.forwardRef(function(i,e){var n=i.icon,t=i.id,o=i.className,r=i.extend,s=Na(i,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(o||"").trim(),c=L.useRef("_".concat(La()));return jo(n,"".concat(t),{defIds:n.defIds,idSuffix:c.current},we({ref:e,className:l},s),r)});function jo(i,e,n,t,o){return L.createElement(i.tag,we(we({key:e},Pa(i,n,o)),t),(Ha(i,n).children||[]).map(function(r,s){return jo(r,"".concat(e,"-").concat(i.tag,"-").concat(s),n,void 0,o)}))}function Pa(i,e,n){var t=we({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var o=e.defIds;return!o||o.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var s=r[0],l=r[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function Ha(i,e){var n,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?we(we({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&t&&t.indexOf(o.attrs.id)>-1?we(we({},o),{attrs:we(we({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):i}function La(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";var Ua={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365zM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377zM2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365zM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647zM9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635zM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635z",fillRule:"evenodd",clipRule:"evenodd"}}]},zo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"autofill",ref:e,icon:Ua}))});zo.displayName="Autofill";const ka=zo;var Va={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.44 3.57291C14.698 3.83093 14.698 4.24927 14.44 4.50729L6.44342 12.5037C6.28721 12.6599 6.03395 12.6599 5.87774 12.5037L1.55992 8.18578C1.3019 7.92776 1.3019 7.50942 1.55993 7.2514C1.81795 6.99338 2.23629 6.99338 2.49431 7.25141L6.01916 10.7763C6.09727 10.8544 6.2239 10.8544 6.30201 10.7763L13.5056 3.57291C13.7636 3.31489 14.1819 3.31489 14.44 3.57291Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Xo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"check-mark-single",ref:e,icon:Va}))});Xo.displayName="CheckMarkSingle";const fn=Xo;var Ba={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.57061 3.65132C4.31677 3.39748 3.90521 3.39748 3.65137 3.65132C3.39753 3.90516 3.39753 4.31672 3.65137 4.57056L7.08079 7.99998L3.65123 11.4295C3.39739 11.6834 3.39739 12.0949 3.65123 12.3488C3.90507 12.6026 4.31662 12.6026 4.57047 12.3488L8.00003 8.91921L11.4295 12.3487C11.6834 12.6026 12.0949 12.6026 12.3488 12.3487C12.6026 12.0949 12.6026 11.6833 12.3488 11.4295L8.91927 7.99998L12.3486 4.57061C12.6025 4.31677 12.6025 3.90521 12.3486 3.65137C12.0948 3.39753 11.6832 3.39753 11.4294 3.65137L8.00003 7.08074L4.57061 3.65132Z"}}]},Yo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"close-single",ref:e,icon:Ba}))});Yo.displayName="CloseSingle";const Fa=Yo;var Wa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1213",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_1213)"},children:[{tag:"path",attrs:{d:"M1.22297.954345C1.3529.929358 1.51542.914795 1.7147.914795H6.85715C7.0561.914795 7.21986.929297 7.35152.959681 7.48737.991031 7.5967 1.04983 7.67995 1.13863 7.76349 1.22774 7.81571 1.34646 7.84615 1.48343L7.84671 1.48597C7.87164 1.62058 7.88612 1.79252 7.88612 2.00111V7.16269C7.88612 7.36211 7.87154 7.52439 7.84667 7.6587 7.82039 7.79533 7.76169 7.91004 7.67831 7.9934 7.59462 8.0771 7.48565 8.13006 7.35692 8.16096 7.22966 8.1915 7.06561 8.20599 6.87627 8.20599H1.7147C1.52177 8.20599 1.36349 8.19641 1.23252 8.17122 1.09967 8.14567.98914 8.09813.90398 8.0134.818184 7.93285.765734 7.8172.735395 7.68573.705177 7.55478.68573 7.38178.68573 7.16269V1.9581C.68573 1.7541.700286 1.58699.725186 1.45253.751461 1.31589.810166 1.20119.893537 1.11782.978617 1.03274 1.08895.98522 1.22033.954901L1.22297.954345zM2.02733 2.07424C1.95064 2.07854 1.91191 2.09755 1.89153 2.11849 1.86949 2.1517 1.85476 2.19738 1.85473 2.25901L1.86389 3.92571H3.72054V2.07424H2.02733zM4.8991 2.07901V3.92571H6.70756V2.20184C6.70756 2.15684 6.7041 2.12531 6.69899 2.10487 6.69675 2.09591 6.69467 2.09093 6.69349 2.08853 6.68344 2.08345 6.66389 2.07901 6.61819 2.07901H4.8991zM1.86466 5.08037L1.87384 6.90902C1.87384 6.95115 1.87723 6.98219 1.8825 7.00371 1.8864 7.01961 1.89067 7.02788 1.8933 7.03179 1.8933 7.03179 1.89686 7.03365 1.8996 7.03479 1.90589 7.03741 1.91476 7.04025 1.92666 7.04282 1.95062 7.04799 1.98341 7.05133 2.02535 7.05133H3.72532V5.08037H1.86466zM4.8991 5.08037V7.05133H6.55606C6.63148 7.05133 6.67174 7.04228 6.68909 7.03374 6.69039 7.03177 6.69349 7.02643 6.69691 7.01502 6.70311 6.99436 6.70756 6.96264 6.70756 6.91894V5.08037H4.8991zM8.65114 7.83368C8.78108 7.80869 8.94359 7.79413 9.14288 7.79413H14.2853C14.4843 7.79413 14.648 7.80863 14.7797 7.83902 14.9155 7.87037 15.0249 7.92916 15.1081 8.01797 15.1917 8.10707 15.2439 8.2258 15.2743 8.36277L15.2749 8.36531C15.2998 8.49991 15.3143 8.67185 15.3143 8.88045V14.042C15.3143 14.2414 15.2997 14.4037 15.2748 14.538 15.2486 14.6747 15.1899 14.7894 15.1065 14.8727 15.0228 14.9564 14.9138 15.0094 14.7851 15.0403 14.6578 15.0708 14.4938 15.0853 14.3044 15.0853H9.14288C8.94995 15.0853 8.79166 15.0757 8.6607 15.0506 8.52785 15.025 8.41732 14.9775 8.33216 14.8927 8.24636 14.8122 8.19391 14.6965 8.16358 14.5651 8.13336 14.4341 8.11391 14.2611 8.11391 14.042V8.83744C8.11391 8.63343 8.12847 8.46633 8.15337 8.33186 8.17964 8.19523 8.23835 8.08053 8.32172 7.99716 8.4068 7.91208 8.51713 7.86456 8.64851 7.83424L8.65114 7.83368zM9.45551 8.95357C9.37882 8.95788 9.34009 8.97689 9.3197 8.99782 9.29767 9.03103 9.28294 9.07672 9.28291 9.13834L9.29206 10.805H11.1487V8.95357H9.45551zM12.3273 8.95835V10.805H14.1357V9.08118C14.1357 9.03618 14.1323 9.00465 14.1272 8.98421 14.1249 8.97524 14.1228 8.97026 14.1217 8.96786 14.1116 8.96278 14.0921 8.95835 14.0464 8.95835H12.3273zM9.29283 11.9597L9.30202 13.7884C9.30202 13.8305 9.30541 13.8615 9.31068 13.883 9.31457 13.8989 9.31885 13.9072 9.32148 13.9111L9.32448 13.9127 9.32778 13.9141C9.33407 13.9167 9.34293 13.9196 9.35484 13.9222 9.3788 13.9273 9.41159 13.9307 9.45353 13.9307H11.1535V11.9597H9.29283zM12.3273 11.9597V13.9307H13.9842C14.0597 13.9307 14.0999 13.9216 14.1173 13.9131 14.1186 13.9111 14.1217 13.9058 14.1251 13.8944 14.1313 13.8737 14.1357 13.842 14.1357 13.7983V11.9597H12.3273z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.46247 2.15033C9.46247 1.74649 9.78985 1.41911 10.1937 1.41911H12.3873C13.5988 1.41911 14.581 2.40124 14.581 3.61276V5.80641C14.581 6.21025 14.2536 6.53762 13.8498 6.53762 13.4459 6.53762 13.1185 6.21025 13.1185 5.80641V3.61276C13.1185 3.20893 12.7912 2.88154 12.3873 2.88154H10.1937C9.78985 2.88154 9.46247 2.55417 9.46247 2.15033zM2.88154 10.1937C2.88154 9.78986 2.55416 9.46248 2.15032 9.46248 1.74648 9.46248 1.4191 9.78986 1.4191 10.1937V12.3873C1.4191 13.5988 2.40123 14.581 3.61275 14.581H5.8064C6.21024 14.581 6.53761 14.2536 6.53761 13.8498 6.53761 13.4459 6.21024 13.1186 5.8064 13.1186H3.61275C3.20892 13.1186 2.88154 12.7912 2.88154 12.3873V10.1937z"}}]}]},$o=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"convert-single",ref:e,icon:Wa}))});$o.displayName="ConvertSingle";const ja=$o;var za={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_371_77",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_371_77)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]}]},Zo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"dropdown-single",ref:e,icon:za}))});Zo.displayName="DropdownSingle";const Go=Zo;var Xa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.6905 4.78738C2.01709 4.61737 2.41966 4.7443 2.58967 5.07089C2.75217 5.38305 3.00913 5.69251 3.36183 5.98156C4.36103 6.80048 6.03866 7.37872 7.99833 7.37872C9.958 7.37872 11.6356 6.80049 12.6348 5.98157C12.9875 5.69251 13.2445 5.38304 13.407 5.0709C13.577 4.7443 13.9796 4.61737 14.3062 4.78737C14.6327 4.95738 14.7597 5.35995 14.5897 5.68654C14.329 6.18726 13.9448 6.63187 13.48 7.01281C13.4365 7.04842 13.3923 7.08356 13.3473 7.11821L14.8065 8.57746C15.0669 8.83781 15.0669 9.25992 14.8065 9.52027C14.5462 9.78062 14.124 9.78062 13.8637 9.52027L12.1741 7.83063C11.6495 8.08125 11.0697 8.28368 10.451 8.43104L10.9916 10.4486C11.0869 10.8042 10.8759 11.1698 10.5202 11.2651C10.1646 11.3604 9.79902 11.1493 9.70373 10.7937L9.13044 8.6541C8.7607 8.69234 8.38239 8.71205 7.99833 8.71205C7.61155 8.71205 7.2306 8.69206 6.85837 8.65329L6.28486 10.7937C6.18957 11.1494 5.82401 11.3604 5.46837 11.2651C5.11272 11.1698 4.90167 10.8043 4.99696 10.4486L5.53804 8.42923C4.92309 8.28224 4.34666 8.0808 3.82483 7.8317L2.13636 9.52018C1.87602 9.78053 1.45391 9.78053 1.19355 9.52018C0.933204 9.25983 0.933203 8.83772 1.19355 8.57737L2.65127 7.11965C2.60559 7.08453 2.56072 7.04892 2.51667 7.01281C2.05184 6.63186 1.66764 6.18725 1.40699 5.68655C1.23698 5.35996 1.36391 4.95739 1.6905 4.78738Z"}}]},Ko=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"eyelash-single",ref:e,icon:Xa}))});Ko.displayName="EyelashSingle";const Ya=Ko;var $a={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_367_60",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_367_60)"},children:[{tag:"path",attrs:{d:"M5.48334 4.89587C5.35517 4.89587 5.26008 4.777 5.28822 4.65196L5.37367 4.27223C5.47369 3.84311 5.65731 3.4768 5.93107 3.18085 6.23007 2.85761 6.67323 2.71538 7.21663 2.71538 7.41772 2.71538 7.63284 2.73908 7.86113 2.78378 7.88014 2.7875 7.89899 2.79139 7.91771 2.79543 8.12915 2.84113 8.35624 2.74611 8.43956 2.54647L8.66692 2.00173C8.75382 1.79351 8.65103 1.55537 8.43507 1.49007 8.40283 1.48032 8.36953 1.47045 8.33516 1.46047 8.0467 1.37763 7.70317 1.3335 7.29999 1.3335 6.2394 1.3335 5.44639 1.60069 4.89385 2.10573 4.32912 2.62202 3.92814 3.3605 3.70338 4.33753L2.25629 10.5523C2.18051 10.8899 2.08525 11.253 1.96769 11.6425 1.849 12.0347 1.70655 12.4208 1.54146 12.7986 1.37502 13.1773 1.18738 13.5375.978805 13.8784.912697 13.9865.8444 14.0896.773916 14.1876.684332 14.3122.753952 14.4944.905805 14.5167 1.5556 14.6123 2.23715 14.4376 2.60122 13.8909 2.74587 13.6737 2.88704 13.426 3.02434 13.1464 3.3856 12.411 3.72447 11.3716 4.03792 10.0188L4.88825 6.37667C4.90938 6.28616 4.99007 6.22214 5.08301 6.22214H7.04403C7.22895 6.22214 7.38976 6.09538 7.43296 5.91557L7.55939 5.3893C7.61982 5.13775 7.42917 4.89587 7.17046 4.89587H5.48334zM13.7403 5.0817L11.9317 7.33096 10.8281 5.13886C10.7615 4.99145 10.6146 4.89673 10.4529 4.89673H9.73214C9.4277 4.89673 9.22847 5.21561 9.36195 5.48923L10.8281 8.41635 8.21708 11.5106C7.98512 11.7771 8.17444 12.1929 8.5278 12.1929H9.10532C9.22597 12.1929 9.37975 12.1436 9.45801 12.0518L11.53 9.62616 12.5369 11.9223C12.5978 12.0844 12.7522 12.1929 12.9254 12.1929H13.7193C14.0023 12.1929 14.161 11.9788 14.0619 11.7137L12.592 8.64761C12.592 8.64761 14.8202 5.81675 15.0205 5.54025 15.2159 5.27062 15.0215 4.89673 14.6886 4.89673H14.0854C13.9467 4.89673 13.8525 4.9502 13.7403 5.0817z"}}]}]},Jo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"fx-single",ref:e,icon:$a}))});Jo.displayName="FxSingle";const Za=Jo;var Ga={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_249",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_249)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.74717 2.0944C8.74717 1.68671 8.41279 1.3562 8.00032 1.3562C7.58785 1.3562 7.25347 1.68671 7.25347 2.0944V7.26186H2.02541C1.61294 7.26186 1.27856 7.59237 1.27856 8.00007C1.27856 8.40777 1.61294 8.73827 2.02541 8.73827H7.25347V13.9057C7.25347 14.3134 7.58785 14.6439 8.00032 14.6439C8.41279 14.6439 8.74717 14.3134 8.74717 13.9057V8.73827H13.975C14.3874 8.73827 14.7218 8.40777 14.7218 8.00007C14.7218 7.59237 14.3874 7.26186 13.975 7.26186H8.74717V2.0944Z"}}]}]},Qo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"increase-single",ref:e,icon:Ga}))});Qo.displayName="IncreaseSingle";const Ka=Qo;var Ja={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_556",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_556)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M0.629584 3.99986C1.13729 3.4922 1.9604 3.49224 2.46806 3.99995L7.57569 9.10806C7.81 9.3424 8.18992 9.3424 8.42424 9.10808L13.5323 3.99998C14.04 3.4923 14.8631 3.4923 15.3708 3.99998C15.8785 4.50766 15.8785 5.33078 15.3708 5.83846L9.41415 11.7951C8.63307 12.5762 7.36669 12.5762 6.58565 11.7951L0.629497 5.83834C0.121839 5.33063 0.121879 4.50752 0.629584 3.99986Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},qo=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"more-down-single",ref:e,icon:Ja}))});qo.displayName="MoreDownSingle";const fi=qo;var Qa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.45493 2.80093C5.74783 2.49409 6.2227 2.49409 6.5156 2.80093L11.0156 7.51523C11.3085 7.82207 11.3085 8.31956 11.0156 8.6264L6.44488 13.27C6.15199 13.5768 5.67711 13.5768 5.38422 13.27C5.09133 12.9631 5.09133 12.4656 5.38422 12.1588L9.28804 8.20898C9.36409 8.13203 9.36517 8.00855 9.29047 7.93029L5.45493 3.9121C5.16204 3.60526 5.16204 3.10777 5.45493 2.80093Z",fillRule:"evenodd",clipRule:"evenodd"}}]},er=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"more-single",ref:e,icon:Qa}))});er.displayName="MoreSingle";const tr=er;var qa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1204",style:{"mask-type":"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1204)"},children:[{tag:"rect",attrs:{width:12.62,height:2.79,x:1.69,y:12.25,fill:"colorChannel1",rx:1.4}},{tag:"path",attrs:{fill:"currentColor",d:"M7.74646 2.1642C7.34284 1.65121 6.85947 1.28205 6.38447 1.09593C5.86863 0.893787 5.15166 0.852126 4.70047 1.42917C4.29842 1.94344 4.33082 2.70249 4.57691 3.50395C4.68808 3.8661 4.86846 4.22254 5.12522 4.56617C5.13695 4.58185 5.14927 4.5968 5.16211 4.61102C5.17152 4.6214 5.18122 4.63139 5.19115 4.64096C5.20459 4.65393 5.21855 4.66618 5.23296 4.6777L3.5064 6.40422C3.26756 6.64306 3.26756 7.03033 3.5064 7.26919L7.23756 11.0004C7.47648 11.2392 7.86375 11.2392 8.1026 11.0004L12.8329 6.27001C13.0717 6.03117 13.0717 5.6439 12.8329 5.40505L9.10172 1.67387C8.86288 1.43503 8.47561 1.43503 8.23676 1.67387L7.74646 2.1642ZM7.46162 4.50638C7.47252 4.57574 7.48163 4.64652 7.4888 4.71868C7.52232 5.05481 7.82194 5.30013 8.15807 5.26661C8.4942 5.23311 8.73954 4.93345 8.70601 4.59732C8.65786 4.11463 8.54251 3.6666 8.37892 3.26169L8.66928 2.97135L11.5354 5.83753L10.6106 6.76237H4.87824L7.40802 4.2326C7.42885 4.32128 7.44684 4.41255 7.46162 4.50638ZM6.87284 3.03784C6.57441 2.62008 6.22261 2.34634 5.93815 2.23487C5.80233 2.18165 5.71528 2.17827 5.67638 2.18335C5.6725 2.18387 5.66929 2.18443 5.6666 2.18497L5.6619 2.18607C5.64166 2.21954 5.53594 2.45979 5.74626 3.1449C5.81241 3.36036 5.92262 3.58602 6.09307 3.81761L6.87284 3.03784Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.1932 11.5463C12.6454 11.5463 13.012 11.1797 13.012 10.7275C13.012 10.4475 12.6981 9.92821 12.459 9.5733C12.3299 9.38173 12.0564 9.38174 11.9274 9.57331C11.6883 9.92822 11.3744 10.4475 11.3744 10.7275C11.3744 11.1797 11.741 11.5463 12.1932 11.5463Z"}}]}]},nr=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"paint-bucket",ref:e,icon:qa}))});nr.displayName="PaintBucket";const el=nr;var tl={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.49152 1.3335C1.79021 1.3335 1.22168 1.90202 1.22168 2.60334V13.397C1.22168 14.0983 1.79021 14.6668 2.49152 14.6668H9.42803C9.98031 14.6668 10.428 14.2191 10.428 13.6668V13.397V10.9234C10.428 10.7577 10.5623 10.6234 10.728 10.6234H13.2852H13.555C14.1073 10.6234 14.555 10.1757 14.555 9.62343V2.60334C14.555 1.90202 13.9865 1.3335 13.2852 1.3335H2.49152ZM8.85819 13.397C9.02387 13.397 9.15819 13.2627 9.15819 13.097V10.9234C9.15819 10.7577 9.02387 10.6234 8.85819 10.6234H6.60104C6.43536 10.6234 6.30104 10.7577 6.30104 10.9234V13.097C6.30104 13.2627 6.43536 13.397 6.60104 13.397H8.85819ZM13.2852 9.05359C13.2852 9.21927 13.1509 9.35359 12.9852 9.35359H10.728C10.5623 9.35359 10.428 9.21927 10.428 9.05359V6.96718C10.428 6.80149 10.5623 6.66718 10.728 6.66718H12.9852C13.1509 6.66718 13.2852 6.80149 13.2852 6.96718V9.05359ZM8.85819 9.35359C9.02387 9.35359 9.15819 9.21927 9.15819 9.05359V6.96718C9.15819 6.80149 9.02387 6.66718 8.85819 6.66718H6.60104C6.43536 6.66718 6.30104 6.80149 6.30104 6.96718V9.05359C6.30104 9.21927 6.43536 9.35359 6.60104 9.35359H8.85819ZM13.2852 5.09734C13.2852 5.26302 13.1509 5.39734 12.9852 5.39734H10.728C10.5623 5.39734 10.428 5.26302 10.428 5.09734V2.90334C10.428 2.73765 10.5623 2.60334 10.728 2.60334H12.9852C13.1509 2.60334 13.2852 2.73765 13.2852 2.90334V5.09734ZM8.85819 5.39734C9.02387 5.39734 9.15819 5.26302 9.15819 5.09734V2.90334C9.15819 2.73765 9.02387 2.60334 8.85819 2.60334H6.60104C6.43536 2.60334 6.30104 2.73765 6.30104 2.90334V5.09734C6.30104 5.26302 6.43536 5.39734 6.60104 5.39734H8.85819ZM5.0312 2.90334C5.0312 2.73765 4.89689 2.60334 4.7312 2.60334H2.79152C2.62584 2.60334 2.49152 2.73765 2.49152 2.90334V5.09734C2.49152 5.26302 2.62584 5.39734 2.79152 5.39734H4.7312C4.89689 5.39734 5.0312 5.26302 5.0312 5.09734V2.90334ZM5.0312 6.96718C5.0312 6.80149 4.89689 6.66718 4.7312 6.66718H2.79152C2.62584 6.66718 2.49152 6.80149 2.49152 6.96718V9.05359C2.49152 9.21927 2.62584 9.35359 2.79152 9.35359H4.7312C4.89689 9.35359 5.0312 9.21927 5.0312 9.05359V6.96718ZM5.0312 10.9234C5.0312 10.7577 4.89689 10.6234 4.7312 10.6234H2.79152C2.62584 10.6234 2.49152 10.7577 2.49152 10.9234V13.097C2.49152 13.2627 2.62584 13.397 2.79152 13.397H4.7312C4.89689 13.397 5.0312 13.2627 5.0312 13.097V10.9234Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.0703 11.9137C12.0445 11.75 12.2176 11.6277 12.3633 11.7068L14.6735 12.9609C14.8412 13.052 14.7972 13.3003 14.6155 13.3333C14.6046 13.3352 14.5937 13.3371 14.5831 13.34L13.58 13.6178L12.8438 14.5421C12.7486 14.7038 12.5031 14.6572 12.4739 14.4718L12.0703 11.9137Z"}}]},ir=L.forwardRef(function(i,e){return L.createElement(Me,Object.assign({},i,{id:"select-range-single",ref:e,icon:tl}))});ir.displayName="SelectRangeSingle";const nl=ir,ot={rangeSelector:"univer-range-selector",rangeSelectorEditor:"univer-range-selector-editor",rangeSelectorIcon:"univer-range-selector-icon",rangeSelectorActive:"univer-range-selector-active"};function il(i){const{onChange:e,onActive:n}=i,[t,o]=L.useState(!1),r=L.useRef(null),s=K.useDependency(a.LocaleService),l=K.useDependency(g.SelectionManagerService);L.useEffect(()=>{var m;if(t){n(t);const S=l.selectionMoveEnd$.subscribe(_=>{const f=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],v=Math.floor(Math.random()*f.length),M=f[v];r.current&&(r.current.innerHTML=M)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),S.unsubscribe()}}e(((m=r.current)==null?void 0:m.innerHTML)||"")},[t]);function c(m){var v,M,R;if(((v=m.target)==null?void 0:v.closest('[data-range-selector="true"]'))||m.target===r.current)return;const _=(M=m.target)==null?void 0:M.closest(`.${ot.rangeSelector}`);(_==null?void 0:_.querySelector(`.${ot.rangeSelectorEditor}`))!==r.current&&(o(!1),(R=r.current)==null||R.blur())}function d(m){m.stopPropagation(),m.key==="Enter"&&(m.preventDefault(),m.currentTarget.blur(),o(!1))}function u(){o(!0)}function h(){var m;if(!t){(m=r.current)==null||m.focus();return}o(!t)}return p.jsxs("div",{className:t?`${ot.rangeSelector} ${ot.rangeSelectorActive}`:ot.rangeSelector,children:[p.jsx("div",{ref:r,className:ot.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(Se.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:ot.rangeSelectorIcon,onClick:h,children:p.jsx(nl,{})})})]})}var St=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(St||{}),ue=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(ue||{}),oe=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(oe||{});const ol={type:ue.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER,isContinue:(i,e)=>i.type===ue.NUMBER,applyFunctions:{[oe.SERIES]:(i,e,n)=>{const{data:t}=i;return n===a.Direction.LEFT||n===a.Direction.UP?(t.reverse(),lo(t,e,n).reverse()):lo(t,e,n)}}},or={type:ue.OTHER,priority:0,match:()=>!0,isContinue:(i,e)=>i.type===ue.OTHER},rl={type:ue.EXTEND_NUMBER,priority:900,match:i=>ln(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,e)=>{var n;if(i.type===ue.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:o}=ln(`${(n=i.cellData)==null?void 0:n.v}`||""),{beforeTxt:r,afterTxt:s}=ln(`${e==null?void 0:e.v}`||"");if(t===r&&o===s)return!0}return!1},applyFunctions:{[oe.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.UP||n===a.Direction.LEFT;let r;if(t.length===1)return r=o?-1:1,Te(co(t,e,r),o);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(ln(d).matchTxt))}return o&&(t.reverse(),s.reverse()),Nt(s)?(r=s[1]-s[0],Te(co(t,e,r),o)):et(t,e)}}},sl={type:ue.CHN_NUMBER,priority:830,match:i=>!!us(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_NUMBER,applyFunctions:{[oe.SERIES]:(i,e,n)=>{var c,d,u;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||Ve(h)<7)?Te(dt(t,e,m),o):Te(uo(t,e,m),o)}let r=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const m=`${(u=t[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&Ve(m)>0&&Ve(m)<7?s.push(Ve(m)+l*7):s.push(Ve(m))}if(o&&(t.reverse(),s.reverse()),Nt(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const m=s[1]-s[0];return Te(dt(t,e,m),o)}const h=s[1]-s[0];return Te(uo(t,e,h),o)}return et(t,e)}}},al={type:ue.CHN_WEEK2,priority:820,match:i=>!!hs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK2,applyFunctions:{[oe.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){let c;return o?c=-1:c=1,Te(dt(t,e,c,1),o)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Ve(u)+s*7)}if(o&&(t.reverse(),r.reverse()),Nt(r)){const c=r[1]-r[0];return Te(dt(t,e,c,1),o)}return et(t,e)}}},ll={type:ue.CHN_WEEK3,priority:810,match:i=>ms(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK3,applyFunctions:{[oe.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){let c;return o?c=-1:c=1,Te(dt(t,e,c,2),o)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Ve(u)+s*7)}}if(o&&(t.reverse(),r.reverse()),Nt(r)){const c=r[1]-r[0];return Te(dt(t,e,c,2),o)}return et(t,e)}}},cl={type:ue.LOOP_SERIES,priority:800,match:i=>Cs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>{var n;return i.type===ue.LOOP_SERIES?oi(`${(n=i.cellData)==null?void 0:n.v}`||"").name===oi(`${e==null?void 0:e.v}`||"").name:!1},applyFunctions:{[oe.SERIES]:(i,e,n)=>{var c,d;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP,{series:r}=oi(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return o?u=-1:u=1,Te(ho(t,e,u,r),o)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(l++,s.push(l*r.length)):s.push(r.indexOf(h)+l*7))}if(o&&(t.reverse(),s.reverse()),Nt(s)){const u=s[1]-s[0];return Te(ho(t,e,u,r),o)}return et(t,e)}}};function Te(i,e){return e?i.reverse():i}var dl=Object.defineProperty,ul=Object.getOwnPropertyDescriptor,hl=(i,e,n,t)=>{for(var o=t>1?void 0:t?ul(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&dl(e,n,o),o},pi=(i,e)=>(n,t)=>e(n,t,i);A.AutoFillService=class extends a.Disposable{constructor(n,t,o){super();C(this,"_rules",[]);C(this,"_hooks",[]);C(this,"_applyType$",new P.BehaviorSubject(oe.SERIES));C(this,"_isFillingStyle",!0);C(this,"_autoFillLocation$",new P.BehaviorSubject(null));C(this,"autoFillLocation$",this._autoFillLocation$.asObservable());C(this,"_showMenu$",new P.BehaviorSubject(!1));C(this,"showMenu$",this._showMenu$.asObservable());C(this,"_direction",a.Direction.DOWN);C(this,"applyType$",this._applyType$.asObservable());C(this,"_menu$",new P.BehaviorSubject([{label:"autoFill.copy",value:oe.COPY,disable:!1},{label:"autoFill.series",value:oe.SERIES,disable:!1},{label:"autoFill.formatOnly",value:oe.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:oe.NO_FORMAT,disable:!1}]));C(this,"menu$",this._menu$.asObservable());this._sheetInterceptorService=n,this._univerInstanceService=t,this._selectionManagerService=o,this._init()}_init(){this._rules=[ol,rl,sl,al,ll,cl,or].sort((n,t)=>t.priority-n.priority),this._isFillingStyle=!0}getOneByPriority(n){return n.length<=0?[]:[n.reduce((o,r)=>(r.priority||0)>(o.priority||0)?r:o,n[0])]}addHook(n){if(this._hooks.find(t=>t.id===n.id))throw new Error(`Add hook failed, hook id '${n.id}' already exist!`);return n.priority===void 0&&(n.priority=0),n.type===void 0&&(n.type=St.Append),this._hooks.push(n),a.toDisposable(()=>{const t=this._hooks.findIndex(o=>o===n);t>-1&&this._hooks.splice(t,1)})}registerRule(n){if(this._rules.find(o=>o.type===n.type))throw new Error(`Registry rule failed, type '${n.type}' already exist!`);const t=this._rules.findIndex(o=>o.priority<n.priority);this._rules.splice(t===-1?this._rules.length:t,0,n)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:n,target:t,unitId:o,subUnitId:r}=this.autoFillLocation||{};if(!n||!t||!o||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:n,target:t,unitId:o,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===St.Only);if(l.length>0)return this.getOneByPriority(l);const c=this.getOneByPriority(s.filter(u=>u.type===St.Default)),d=s.filter(u=>u.type===St.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(n){this._applyType$.next(n)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(n){this._direction=n}isFillingStyle(){return this._isFillingStyle}setFillingStyle(n){this._isFillingStyle=n}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(n){this._autoFillLocation$.next(n)}setDisableApplyType(n,t){this._menu$.next(this._menu$.getValue().map(o=>o.value===n?{...o,disable:t}:o))}setShowMenu(n){this._showMenu$.next(n)}},A.AutoFillService=hl([a.OnLifecycle(a.LifecycleStages.Rendered,A.AutoFillService),pi(0,N.Inject(g.SheetInterceptorService)),pi(1,N.Inject(a.IUniverInstanceService)),pi(2,N.Inject(g.SelectionManagerService))],A.AutoFillService);const Ft=N.createIdentifier("univer.auto-fill-service");var ml=Object.defineProperty,Sl=Object.getOwnPropertyDescriptor,_l=(i,e,n,t)=>{for(var o=t>1?void 0:t?Sl(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ml(e,n,o),o},Fe=(i,e)=>(n,t)=>e(n,t,i);A.AutoFillController=class extends a.Disposable{constructor(n,t,o,r,s,l,c,d,u){super();C(this,"_beforeApplyData",[]);C(this,"_copyData",[]);C(this,"_defaultHook");this._univerInstanceService=n,this._selectionRenderService=t,this._commandService=o,this._undoRedoService=r,this._autoFillService=s,this._editorBridgeService=l,this._sheetInterceptorService=c,this._selectionManagerService=d,this._injector=u,this._defaultHook={id:"default",type:St.Default,priority:0,onBeforeFillData:(h,m)=>{this._presetAndCacheData(h,m)},onFillData:(h,m,S)=>this._fillData(h,m,S)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[So,cn].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initDefaultHook(){this._autoFillService.addHook(this._defaultHook)}_onSelectionControlFillChanged(){const n=new a.DisposableCollection;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==g.SetSelectionsOperation.id)return;const o=this._selectionManagerService.getCurrent();if((o==null?void 0:o.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return;n.dispose(),this._selectionRenderService.getCurrentControls().forEach(s=>{n.add(a.toDisposable(s.selectionFilled$.subscribe(l=>{if(l==null||l.startColumn===-1||l.startRow===-1||l.endColumn===-1||l.endRow===-1)return;const c={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow},d={startColumn:l.startColumn,endColumn:l.endColumn,startRow:l.startRow,endRow:l.endRow};this._triggerAutoFill(c,d)}))),n.add(a.toDisposable(s.fillControl.onDblclickObserver.add(()=>{const l={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow};this._handleDbClickFill(l)}))),n.add(a.toDisposable(s.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})})))})}))}_onApplyTypeChanged(){this.disposeWithMe(a.toDisposable(this._autoFillService.applyType$.subscribe(()=>{this._handleFillData()})))}_triggerAutoFill(n,t){var d;if(n.startColumn===t.startColumn&&n.startRow===t.startRow&&n.endColumn===t.endColumn&&n.endRow===t.endRow)return;if(t.endColumn<n.endColumn&&t.endColumn>n.startColumn){this._commandService.executeCommand(cn.id,{clearRange:{startRow:t.startRow,endRow:t.endRow,startColumn:t.endColumn+1,endColumn:n.endColumn},selectionRange:t});return}if(t.endRow<n.endRow&&t.endRow>n.startRow){this._commandService.executeCommand(cn.id,{clearRange:{startRow:t.endRow+1,endRow:n.endRow,startColumn:t.startColumn,endColumn:t.endColumn},selectionRange:t});return}const o={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:t.endColumn};let r=null;if(t.startRow<n.startRow)r=a.Direction.UP,o.endRow=n.startRow-1;else if(t.endRow>n.endRow)r=a.Direction.DOWN,o.startRow=n.endRow+1;else if(t.startColumn<n.startColumn)r=a.Direction.LEFT,o.endColumn=n.startColumn-1;else if(t.endColumn>n.endColumn)r=a.Direction.RIGHT,o.startColumn=n.endColumn+1;else return;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),l=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._autoFillService.direction=r,this._autoFillService.autoFillLocation={source:n,target:o,unitId:s,subUnitId:l},this._autoFillService.getActiveHooks().forEach(u=>{var h;(h=u==null?void 0:u.onBeforeFillData)==null||h.call(u,{source:n,target:o,unitId:s,subUnitId:l},r)}),(d=this._autoFillService.menu.find(u=>u.value===oe.SERIES))!=null&&d.disable?this._autoFillService.applyType=oe.COPY:this._autoFillService.applyType=oe.SERIES}_handleDbClickFill(n){const t=this._detectFillRange(n);t.endRow<=n.endRow||this._triggerAutoFill(n,t)}_detectFillRange(n){var m,S,_,f,v,M;const{startRow:t,endRow:o,startColumn:r,endColumn:s}=n,l=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!l)return n;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=o;if(r>0&&((S=c.getValue(t,r-1))==null?void 0:S.v)!=null){let R=t;for(;((_=c.getValue(R,r-1))==null?void 0:_.v)!=null&&R<d;)R+=1;h=R-1}else if(s<u&&((f=c.getValue(o,s+1))==null?void 0:f.v)!=null){let R=t;for(;((v=c.getValue(R,s+1))==null?void 0:v.v)!=null&&R<d;)R+=1;h=R-1}for(let R=o+1;R<=h;R++)for(let T=r;T<=s;T++)if(((M=c.getValue(R,T))==null?void 0:M.v)!=null){h=R-1;break}return{startColumn:r,endColumn:s,startRow:t,endRow:h}}_handleFillData(){const{source:n,target:t,unitId:o=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:r=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=this._autoFillService.autoFillLocation||{},s=this._autoFillService.direction;if(!n||!t)return;const l=a.Rectangle.union(n,t),c=this._autoFillService.applyType,d=this._autoFillService.getActiveHooks();this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,{selections:[{primary:{...l,actualRow:l.startRow,actualColumn:l.startColumn,endColumn:l.startColumn,endRow:l.startRow},range:{...l,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:r});const u=[],h=[];d.forEach(S=>{var v;const{undos:_,redos:f}=((v=S.onFillData)==null?void 0:v.call(S,{source:n,target:t,unitId:o,subUnitId:r},s,c))||{};_&&u.push(..._),f&&h.push(...f)}),h.every(S=>this._commandService.syncExecuteCommand(S.id,S.params))&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:u,redoMutations:h}),d.forEach(S=>{var _;(_=S.onAfterFillData)==null||_.call(S,{source:n,target:t,unitId:o,subUnitId:r},s,c)}),this._autoFillService.setShowMenu(!0)}_getApplyData(n,t,o,r,s,l=!0){const c=[],d=Math.floor(o/t),u=o%t,h=this._autoFillService.getRules();if(!l&&s===oe.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(S=>{m[S.type]=[]}),h.forEach(S=>{const{type:_,applyFunctions:f={}}=S,v=n[_];v&&v.forEach(M=>{const R=Ss(M.index,u),T=M.index.length*d+R,w=this._applyFunctions(M,T,r,s,f,n),E=_s(t,o,M.index);m[_].push({data:w,index:E})})});for(let S=0;S<o;S++)h.forEach(_=>{const{type:f}=_,v=m[f];for(let M=0;M<v.length;M++)S in v[M].index&&c.push(v[M].data[v[M].index[S]])});return c}_applyFunctions(n,t,o,r,s,l){const{data:c}=n,d=o===a.Direction.UP||o===a.Direction.LEFT;if(r===oe.COPY){const u=s==null?void 0:s[oe.COPY];return u?u(n,t,o,l):(d&&c.reverse(),et(c,t))}if(r===oe.SERIES){const u=s==null?void 0:s[oe.SERIES];return u?u(n,t,o,l):(d&&c.reverse(),s!=null&&s[oe.COPY]?s[oe.COPY](n,t,o,l):et(c,t))}if(r===oe.ONLY_FORMAT){const u=s==null?void 0:s[oe.ONLY_FORMAT];return u?u(n,t,o,l):gs(c,t)}}_getCopyData(n,t){const{startRow:o,startColumn:r,endRow:s,endColumn:l}=n,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=t===a.Direction.DOWN||t===a.Direction.UP;let m,S,_,f;h?(m=r,S=l,_=o,f=s):(m=o,S=s,_=r,f=l);for(let v=m;v<=S;v++){const M=this._getEmptyCopyDataPiece(),R={type:void 0,cellData:void 0};for(let T=_;T<=f;T++){let w;h?w=c.getValue(T,v):w=c.getValue(v,T);const{type:E,isContinue:y}=d.find(x=>x.match(w))||or;if(y(R,w)){const x=M[E],O=x[x.length-1];O.data.push(w),O.index.push(T-_)}else{const x=M[E];x?x.push({data:[w],index:[T-_]}):M[E]=[{data:[w],index:[T-_]}]}R.type=E,R.cellData=w}u.push(M)}return u}_getEmptyCopyDataPiece(){const n={};return this._autoFillService.getRules().forEach(t=>{n[t.type]=[]}),n}_getMergeApplyData(n,t,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),l=[];for(let c=n.startRow;c<=n.endRow;c++)for(let d=n.startColumn;d<=n.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:S,endColumn:_}=b.getCellInfoInMergeData(c,d,s);if(u){if(o===a.Direction.DOWN){let f=h+r,v=S+r;for(;v<=t.endRow;)l.push({startRow:f,startColumn:m,endRow:v,endColumn:_}),f+=r,v+=r}else if(o===a.Direction.UP){let f=h-r,v=S-r;for(;f>=t.startRow;)l.push({startRow:f,startColumn:m,endRow:v,endColumn:_}),f-=r,v-=r}else if(o===a.Direction.RIGHT){let f=m+r,v=_+r;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:f,endRow:S,endColumn:v}),f+=r,v+=r}else if(o===a.Direction.LEFT){let f=m-r,v=_-r;for(;f>=t.startColumn;)l.push({startRow:h,startColumn:f,endRow:S,endColumn:v}),f-=r,v-=r}}}return l}_presetAndCacheData(n,t){const{source:o,target:r}=n,s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),l=[];for(let c=r.startRow;c<=r.endRow;c++){const d=[];for(let u=r.startColumn;u<=r.endColumn;u++)d.push(a.Tools.deepClone(s.getValue(c,u)));l.push(d)}this._beforeApplyData=l,this._copyData=this._getCopyData(o,t),this._hasSeries(this._copyData)?this._autoFillService.setDisableApplyType(oe.SERIES,!1):this._autoFillService.setDisableApplyType(oe.SERIES,!0)}_fillData(n,t,o){var Q,se;const r=[],s=[];let l=!0;o===oe.NO_FORMAT&&(l=!1,o=oe.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=n;if(!c||!d||t==null)return{undos:r,redos:s};const{startRow:m,startColumn:S,endRow:_,endColumn:f}=c,{startRow:v,startColumn:M,endRow:R,endColumn:T}=d,w=this._copyData;let E;t===a.Direction.DOWN||t===a.Direction.UP?E=_-m+1:E=f-S+1;const y=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const X=R-v+1,G=[];for(let J=M;J<=T;J++){const ce=w[J-M],ae=this._getApplyData(ce,E,X,t,o,l);G.push(ae)}for(let J=0;J<G[0].length;J++){const ce=[];for(let ae=0;ae<G.length;ae++)ce.push({s:null,...G[ae][J]});y.push(ce)}}else{const X=T-M+1;for(let G=v;G<=R;G++){const J=w[G-v],ce=this._getApplyData(J,E,X,t,o,l),ae=[];for(let ge=0;ge<ce.length;ge++)ae.push({s:null,...ce[ge]});y.push(ae)}}let x=[];const O=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();l?(x=this._getMergeApplyData(c,d,t,E),y.forEach(X=>{X.forEach(G=>{G&&O&&O&&(G.s=O.getStyleByCell(G))})})):y.forEach((X,G)=>{X.forEach((J,ce)=>{J&&O&&(J.s=O.getStyleByCell(this._beforeApplyData[G][ce])||null)})}),o===oe.ONLY_FORMAT&&y.forEach((X,G)=>{X.forEach((J,ce)=>{if(J){const ae=this._beforeApplyData[G][ce]||{};J.f=ae.f,J.si=ae.si,J.t=ae.t,J.v=ae.v}})});const D={get:this._injector.get.bind(this._injector)},B=[],H=(se=(Q=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:Q.getSheetBySheetId(h))==null?void 0:se.getMergeData();H&&H.forEach(X=>{a.Rectangle.intersects(X,d)&&B.push(X)});const F={unitId:u,subUnitId:h,ranges:B},W=g.RemoveMergeUndoMutationFactory(D,F);s.push({id:g.RemoveWorksheetMergeMutation.id,params:F}),r.push({id:g.AddWorksheetMergeMutation.id,params:W});const z={subUnitId:h,unitId:u,cellValue:mo([d])},Y=g.SetRangeValuesUndoMutationFactory(D,z),te=this._sheetInterceptorService.onCommandExecute({id:g.ClearSelectionContentCommand.id});s.push({id:g.SetRangeValuesMutation.id,params:z},...te.redos),r.push(...te.undos,{id:g.SetRangeValuesMutation.id,params:Y});const j=new a.ObjectMatrix,{startRow:ee,startColumn:re,endRow:Z,endColumn:U}=d;for(let X=0;X<=Z-ee;X++)for(let G=0;G<=U-re;G++)y[X][G]&&j.setValue(X+ee,G+re,y[X][G]);const k={subUnitId:h,unitId:u,cellValue:j.getMatrix()},$=g.SetRangeValuesUndoMutationFactory(D,k);if(r.push({id:g.SetRangeValuesMutation.id,params:$}),s.push({id:g.SetRangeValuesMutation.id,params:k}),x!=null&&x.length){const X=g.getAddMergeMutationRangeByType(x),G={unitId:u,subUnitId:h,ranges:X},J=g.AddMergeUndoMutationFactory(D,G);r.push({id:g.RemoveWorksheetMergeMutation.id,params:J}),s.push({id:g.AddWorksheetMergeMutation.id,params:G})}return{undos:r,redos:s}}_hasSeries(n){return n.some(t=>Object.keys(t).some(r=>{var s;return!!((s=t[r])!=null&&s.length&&![ue.OTHER,ue.FORMULA].includes(r))}))}},A.AutoFillController=_l([a.OnLifecycle(a.LifecycleStages.Steady,A.AutoFillController),Fe(0,a.IUniverInstanceService),Fe(1,_e),Fe(2,a.ICommandService),Fe(3,a.IUndoRedoService),Fe(4,Ft),Fe(5,be),Fe(6,N.Inject(g.SheetInterceptorService)),Fe(7,N.Inject(g.SelectionManagerService)),Fe(8,N.Inject(N.Injector))],A.AutoFillController);const rr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async i=>{var c;const n=(c=i.get(g.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(n!=null&&n.length))return!1;const t=i.get(a.ICommandService),l=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(ko(l,n)){const d=i.get(I.IConfirmService),u=i.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(g.SetRowHiddenCommand.id),!0}},sr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async i=>{var c;const n=(c=i.get(g.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(n!=null&&n.length))return!1;const t=i.get(a.ICommandService),l=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(Vo(l,n)){const d=i.get(I.IConfirmService),u=i.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(g.SetColHiddenCommand.id),!0}},vi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatBoldCommand.id):e.executeCommand(g.SetBoldCommand.id)}},Ci={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatItalicCommand.id):e.executeCommand(g.SetItalicCommand.id)}},Ii={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatUnderlineCommand.id):e.executeCommand(g.SetUnderlineCommand.id)}},Mi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatStrikethroughCommand.id):e.executeCommand(g.SetStrikeThroughCommand.id)}},gl={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatSubscriptCommand.id):!1}},fl={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(q.SetInlineFormatSuperscriptCommand.id):!1}},ar={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(q.SetInlineFormatFontSizeCommand.id,e):n.executeCommand(g.SetFontSizeCommand.id,e)}},lr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(q.SetInlineFormatFontFamilyCommand.id,e):n.executeCommand(g.SetFontFamilyCommand.id,e)}},pn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(q.SetInlineFormatTextColorCommand.id,e):n.executeCommand(g.SetTextColorCommand.id,e)}};function cr(i,e){return e.some(n=>pl(i,n))}function pl(i,e){const{startRow:n,startColumn:t,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(n,t,r,o);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==n||d!==t)&&i.cellHasValue(u))return l=!0,!1}),l}function dr(i,e,n,t){const o=[],r=[],s=n.getSheetId();return t.forEach(l=>{const c=vl(n,l),d={unitId:e,subUnitId:s,cellValue:c.getData()},u=g.SetRangeValuesUndoMutationFactory(i,d);o.push({id:g.SetRangeValuesMutation.id,params:u}),r.push({id:g.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function vl(i,e){const{startRow:n,startColumn:t,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(n,t,r,o),l=new a.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==n||d!==t)&&l.setValue(c,d,null)}),l}var Cl=Object.defineProperty,Il=Object.getOwnPropertyDescriptor,Ml=(i,e,n,t)=>{for(var o=t>1?void 0:t?Il(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Cl(e,n,o),o},Ri=(i,e)=>(n,t)=>e(n,t,i),ye=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(ye||{});const _t=N.createIdentifier("univer.format-painter-service");let bi=class extends a.Disposable{constructor(e,n,t){super();C(this,"status$");C(this,"_selectionFormat");C(this,"_markId",null);C(this,"_status$");this._selectionManagerService=e,this._univerInstanceService=n,this._markSelectionService=t,this._status$=new P.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}setStatus(e){e!==0&&this._getSelectionRangeFormat(),this._updateRangeMark(e),this._status$.next(e)}getStatus(){return this._status$.getValue()}_updateRangeMark(e){if(this._markSelectionService.removeAllShapes(),this._markId=null,e!==0){const n=this._selectionManagerService.getLast();if(n){const t=this._selectionManagerService.createCopyPasteSelection();e===2?this._markId=this._markSelectionService.addShape({...n,style:t}):this._markId=this._markSelectionService.addShape({...n,style:t},[g.SetRangeValuesMutation.id])}}}_getSelectionRangeFormat(){const e=this._selectionManagerService.getLast(),n=e==null?void 0:e.range;if(!n)return;const{startRow:t,endRow:o,startColumn:r,endColumn:s}=n,l=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(l==null?void 0:l.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=l.getStyles(),m=new a.ObjectMatrix;for(let S=t;S<=o;S++)for(let _=r;_<=s;_++){const f=d.getValue(S,_);m.setValue(S,_,h.getStyleByCell(f)||{});const{isMergedMainCell:v,...M}=b.getCellInfoInMergeData(S,_,u);v&&this._selectionFormat.merges.push({startRow:M.startRow,startColumn:M.startColumn,endRow:M.endRow,endColumn:M.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};bi=Ml([Ri(0,N.Inject(g.SelectionManagerService)),Ri(1,a.IUniverInstanceService),Ri(2,Ht)],bi);const wi={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(i,e)=>e?(i.get(_t).setStatus(e.status),!0):!1},ur={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const n=i.get(_t).getStatus();let t;return n!==ye.OFF?t=ye.OFF:t=ye.INFINITE,i.get(a.ICommandService).executeCommand(wi.id,{status:t})}},Ti={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const n=i.get(_t).getStatus();let t;return n!==ye.OFF?t=ye.OFF:t=ye.ONCE,i.get(a.ICommandService).executeCommand(wi.id,{status:t})}},hr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,e)=>{const n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(g.SelectionManagerService),s=i.get(g.SheetInterceptorService),{styleValues:l,styleRange:c,mergeRanges:d,unitId:u=o.getCurrentUniverSheetInstance().getUnitId(),subUnitId:h=o.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=e,m=c?[c]:r.getSelectionRanges();if(!m||!m.length)return!1;const S=new a.ObjectMatrix;let _;if(a.Tools.isArray(l))for(let z=0;z<m.length;z++){const{startRow:Y,startColumn:te,endRow:j,endColumn:ee}=m[z];for(let re=0;re<=j-Y;re++)for(let Z=0;Z<=ee-te;Z++)S.setValue(re+Y,Z+te,l[re][Z])}else if(a.isICellData(l))for(let z=0;z<m.length;z++){const{startRow:Y,startColumn:te}=m[z];S.setValue(Y,te,l)}else _=l;const f={subUnitId:h,unitId:u,cellValue:_!=null?_:S.getMatrix()},v=g.SetRangeValuesUndoMutationFactory(i,f);if(!s.fetchThroughInterceptors(g.INTERCEPTOR_POINT.PERMISSION)(null,{id:g.SetRangeValuesCommand.id,params:f}))return!1;const M=n.syncExecuteCommand(g.SetRangeValuesMutation.id,f),{undos:R,redos:T}=s.onCommandExecute({id:g.SetRangeValuesCommand.id,params:{...f,range:m}}),w=g.getAddMergeMutationRangeByType(d),E=o.getUniverSheetInstance(u).getSheetBySheetId(h),y=[],x=[],O=cr(E,w),D={unitId:u,subUnitId:h,ranges:w},B={unitId:u,subUnitId:h,ranges:w};y.push({id:g.RemoveWorksheetMergeMutation.id,params:D}),y.push({id:g.AddWorksheetMergeMutation.id,params:B});const H=g.RemoveMergeUndoMutationFactory(i,D),F=g.AddMergeUndoMutationFactory(i,B);if(x.push({id:g.RemoveWorksheetMergeMutation.id,params:F}),x.push({id:g.AddWorksheetMergeMutation.id,params:H}),O){const z=dr(i,u,E,w);y.unshift(...z.redos),x.push(...z.undos)}const W=await a.sequenceExecute([...T,...y],n);return M&&W.result?(t.pushUndoRedo({unitID:u,undoMutations:[{id:g.SetRangeValuesMutation.id,params:v},...R,...x],redoMutations:[{id:g.SetRangeValuesMutation.id,params:f},...T,...y]}),!0):!1}},vn={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,e)=>{const{type:n}=e||{},t=i.get(a.IUniverInstanceService),o=i.get(a.IUndoRedoService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),l=i.get(a.ICommandService),d=i.get(g.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(Je),{sheetViewStartRow:S=0,sheetViewStartColumn:_=0}=m.getCurrentScroll()||{};let f,v,M,R;const{startRow:T,startColumn:w,rangeType:E}=h;if(E===a.RANGE_TYPE.ROW||n===1)f=T,M=T-S,v=-1,R=0;else if(E===a.RANGE_TYPE.COLUMN||n===2)f=-1,M=0,v=w,R=w-_;else if(E===a.RANGE_TYPE.NORMAL)f=T,M=T-S,v=w,R=w-_;else return!1;const y={unitId:r,subUnitId:s,startRow:f,startColumn:v,xSplit:v>0?Math.max(1,R):R,ySplit:f>0?Math.max(1,M):M},x=g.SetFrozenMutationFactory(i,y);return l.syncExecuteCommand(g.SetFrozenMutation.id,y)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:g.SetFrozenMutation.id,params:x}],redoMutations:[{id:g.SetFrozenMutation.id,params:y}]}),!0}},mr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(vn.id,{type:1}),!0)},Sr={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(vn.id,{type:2}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(a.IUndoRedoService),o=n.getCurrentUniverSheetInstance().getUnitId(),r=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},l=g.SetFrozenMutationFactory(i,s);return e.syncExecuteCommand(g.SetFrozenMutation.id,s)&&t.pushUndoRedo({unitID:o,undoMutations:[{id:g.SetFrozenMutation.id,params:l}],redoMutations:[{id:g.SetFrozenMutation.id,params:s}]}),!0}},gt="UI_PLUGIN_SHEETS",Cn=`${gt}_COLOR_PICKER_COMPONENT`,gr=`${gt}_FONT_FAMILY_COMPONENT`,fr=`${gt}_FONT_FAMILY_ITEM_COMPONENT`,pr=`${gt}_FONT_SIZE_COMPONENT`,Ei=`${gt}_MENU_ITEM_INPUT_COMPONENT`,yi={sheetsUiContextMenuInput:"univer-sheets-ui-context-menu-input",sheetsUiContextMenuInputContainer:"univer-sheets-ui-context-menu-input-container",sheetsUiContextMenuInputNumber:"univer-sheets-ui-context-menu-input-number"},Rl=i=>{const{prefix:e,suffix:n,value:t,onChange:o,min:r=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=i,l=K.useDependency(a.LocaleService),[c,d]=L.useState(),u=m=>{var S;d(m==null?void 0:m.toString()),o((S=m==null?void 0:m.toString())!=null?S:"")};L.useEffect(()=>{d(t)},[t]);function h(m){m.key==="Backspace"&&m.stopPropagation()}return p.jsxs("div",{className:yi.sheetsUiContextMenuInput,children:[l.t(e),p.jsx("span",{className:yi.sheetsUiContextMenuInputContainer,onClick:m=>m.stopPropagation(),children:p.jsx(Se.InputNumber,{className:yi.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:h,onChange:u,min:r,max:s})}),l.t(n)]})};var de=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(de||{});function bl(i){const e=i.get(_t);return{id:Ti.id,subId:ur.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",positions:[I.MenuPosition.TOOLBAR_START],activated$:new P.Observable(n=>{let t=!1;const o=e.status$.subscribe(r=>{t=r!==ye.OFF,n.next(t)});return n.next(t),()=>{o.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function wl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(a.IContextService),o=i.get(g.SelectionManagerService);return{id:vi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=o.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let S=a.FontWeight.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getFontWeight()}r.next(S===a.FontWeight.BOLD)}if((c===q.SetTextSelectionsOperation.id||c===q.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.bl;r.next(m===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function Tl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:Ci.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let S=a.FontItalic.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getFontStyle()}r.next(S===a.FontItalic.ITALIC)}if((c===q.SetTextSelectionsOperation.id||c===q.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.it;r.next(m===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function El(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:Ii.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let S;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getUnderline()}r.next(!!(S&&S.s))}if((c===q.SetTextSelectionsOperation.id||c===q.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.ul;r.next((m==null?void 0:m.s)===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function yl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:Mi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let S;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getStrikeThrough()}r.next(!!(S&&S.s))}if((c===q.SetTextSelectionsOperation.id||c===q.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.st;r.next((m==null?void 0:m.s)===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function Ol(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:lr.id,tooltip:"toolbar.font",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,label:gr,positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_FAMILY_LIST.map(o=>({label:{name:fr,hoverable:!0},value:o.value})),disabled$:g.getCurrentSheetDisabled$(i),value$:new P.Observable(o=>{const r=I.FONT_FAMILY_LIST[0].value,s=e.onCommandExecuted(l=>{var m;const c=l.id;if(c!==g.SetRangeValuesMutation.id&&c!==g.SetSelectionsOperation.id)return;const d=(m=t.getLast())==null?void 0:m.primary,u=n.getCurrentUniverSheetInstance().getActiveSheet();let h;if(d!=null){const S=u.getRange(d.startRow,d.startColumn);h=S==null?void 0:S.getFontFamily()}o.next(h!=null?h:r)});return o.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function xl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService),r=g.getCurrentSheetDisabled$(i);return{id:ar.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:pr,props:{min:1,max:400,disabled$:r}},positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_SIZE_LIST,disabled$:r,value$:new P.Observable(s=>{const c=e.onCommandExecuted(d=>{var h,m;const u=d.id;if(u===g.SetRangeValuesMutation.id||u===g.SetSelectionsOperation.id){const S=(h=t.getLast())==null?void 0:h.primary,_=n.getCurrentUniverSheetInstance().getActiveSheet();let f;if(S!=null){const v=_.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontSize()}s.next(f!=null?f:14)}if((u===q.SetTextSelectionsOperation.id||u===q.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const S=jt(i);if(S==null)return;const _=(m=S.ts)==null?void 0:m.fs;s.next(_!=null?_:14)}});return s.next(14),c.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function Al(i){return{id:g.ResetTextColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:pn.id,disabled$:g.getCurrentSheetDisabled$(i)}}function Dl(i){const e=i.get(a.ICommandService),n=i.get(a.ThemeService);return{id:pn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:Cn,hoverable:!1}}],value$:new P.Observable(t=>{const o=n.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===pn.id){const l=s.params.value;t.next(l!=null?l:o)}});return t.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function Nl(i){return{id:g.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:g.SetBackgroundColorCommand.id,disabled$:g.getCurrentSheetDisabled$(i)}}function Pl(i){const e=i.get(a.ICommandService),n=i.get(a.ThemeService);return{id:g.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Cn,hoverable:!1}}],value$:new P.Observable(t=>{const o=n.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===g.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:o)}});return t.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const vr=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function Hl(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);return{id:g.SetHorizontalTextAlignCommand.id,icon:vr[0].icon,positions:[I.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:vr,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetHorizontalTextAlignCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}t.next(d!=null?d:a.HorizontalAlign.LEFT)});return t.next(a.HorizontalAlign.LEFT),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const Cr=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function Ll(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);return{id:g.SetVerticalTextAlignCommand.id,icon:Cr[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:Cr,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetVerticalTextAlignCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getVerticalAlignment()}t.next(d!=null?d:a.VerticalAlign.TOP)});return t.next(a.VerticalAlign.TOP),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const Ir=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function Ul(i){const e=i.get(g.SelectionManagerService),n=i.get(a.IUniverInstanceService);return{id:g.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:Ir[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:Ir,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetTextWrapCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=e.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getWrapStrategy()}t.next(d!=null?d:a.WrapStrategy.OVERFLOW)});return t.next(a.WrapStrategy.OVERFLOW),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const Mr=[{label:"textRotate.none",icon:"NoRotationSingle",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesSingle",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesSingle",value:45},{label:"textRotate.vertical",icon:"VerticalTextSingle",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesSingle",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesSingle",value:90}];function kl(i){const e=i.get(g.SelectionManagerService),n=i.get(a.IUniverInstanceService);return{id:g.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Mr[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:Mr,positions:[I.MenuPosition.TOOLBAR_START],value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u,h;const s=r.id;if(s!==g.SetTextRotationCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=e.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const m=c.getRange(l.startRow,l.startColumn);d=m==null?void 0:m.getTextRotation()}(d==null?void 0:d.v)===a.BooleanNumber.TRUE?t.next("v"):t.next((h=d&&d.a)!=null?h:0)});return t.next(0),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function ft(i){return new P.Observable(e=>e.next(!i.get(I.IClipboardInterfaceService).supportClipboard))}function Vl(){return{id:I.CopyCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Bl(i){return{id:I.PasteCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:ft(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const pt="sheet.menu.paste-special";function Fl(i){return{id:pt,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",disabled$:ft(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Wl(i){return{id:Ao.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[pt],disabled$:ft(i)}}function jl(i){return{id:Do.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[pt],disabled$:ft(i)}}function zl(i){return{id:No.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[pt],disabled$:ft(i)}}function Xl(i){return{id:Po.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[pt],disabled$:ft(i)}}function Yl(){return{id:g.SetWorksheetRowIsAutoHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Wt="sheet.menu.sheet-frozen";function $l(){return{id:Wt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[I.MenuPosition.CONTEXT_MENU]}}const Oi="sheet.header-menu.sheet-frozen";function Zl(){return{id:Oi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function Gl(){return{id:vn.id,type:I.MenuItemType.BUTTON,positions:[Wt,Oi],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function Kl(){return{id:mr.id,type:I.MenuItemType.BUTTON,positions:[Wt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function Jl(){return{id:Sr.id,type:I.MenuItemType.BUTTON,positions:[Wt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function Ql(){return{id:_r.id,type:I.MenuItemType.BUTTON,positions:[Wt,Oi],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function ql(){return{id:rr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function ec(){return{id:sr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function tc(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);function t(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=n.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.ROW);return!!(s!=null&&s.some(c=>{for(let d=c.startRow;d<=c.endRow;d++)if(!r.getRowVisible(d))return!0;return!1}))}const o=i.get(a.ICommandService);return{id:g.SetSelectedRowsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new P.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===g.SetSelectionsOperation.id||l.id===g.SetRowHiddenMutation.id||l.id===g.SetRowVisibleMutation.id)&&r.next(!t())});return r.next(!t()),()=>s.dispose()})}}function nc(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);function t(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=n.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.COLUMN);return!s||s.length===0?!1:!!s.some(c=>{for(let d=c.startColumn;d<=c.endColumn;d++)if(!r.getColVisible(d))return!0;return!1})}const o=i.get(a.ICommandService);return{id:g.SetSelectedColsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new P.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===g.SetSelectionsOperation.id||l.id===g.SetColHiddenMutation.id||l.id===g.SetColVisibleMutation.id)&&r.next(!t())});return r.next(!t()),()=>s.dispose()})}}function ic(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:g.SetRowHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:Ei,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:new P.Observable(o=>{function r(){var u;const l=(u=t.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;l!=null&&(d=c.getRowHeight(l.startRow)),o.next(d!=null?d:0)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function oc(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:g.SetColWidthCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:Ei,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:new P.Observable(o=>{function r(){var u;const l=(u=t.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d=0;l!=null&&(d=c.getColumnWidth(l.startColumn)),o.next(d)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function jt(i){var c;const e=i.get(a.IUniverInstanceService),n=i.get(q.TextSelectionManagerService),t=e.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=n.getActiveRange();if(t==null||o==null)return;const r=(c=t.getBody())==null?void 0:c.textRuns;if(r==null)return;const{startOffset:s}=o;return r.find(({st:d,ed:u})=>s>=d&&s<u)}function ve(i,e){const t=i.getCurrentUniverSheetInstance().getUnitId(),o=e.getRenderById(t);if(o==null)return;const{components:r,mainComponent:s,scene:l,engine:c}=o,d=s,u=r.get(fe.ROW),h=r.get(fe.COLUMN),m=r.get(fe.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:l,engine:c}}function xi(i,e,n,t){const{startX:o,startY:r,endX:s,endY:l}=t.getCellByIndex(i,e);return{startX:o,startY:r,endX:s,endY:l}}function vt(i,e,n,t,o){const r=n.getRelativeCoord(b.Vector2.FromArray([i,e])),{x:s,y:l}=r,c=n.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=n.getAncestorScale(),h=t.getCellPositionByOffset(s,l,d,u,c),{row:m,column:S}=h,_=t.getNoMergeCellPositionByIndex(m,S),{startX:f,startY:v,endX:M,endY:R}=_;return{startX:f,startY:v,endX:M,endY:R,row:m,column:S}}function In(i,e,n,t){const o=n.getRelativeCoord(b.Vector2.FromArray([i,e])),r=n.getViewport(V.VIEW_MAIN),s=n.getScrollXYByRelativeCoords(o,r),{scaleX:l,scaleY:c}=n.getAncestorScale(),{x:d,y:u}=s,h=i/l+d,m=e/c+u;return{x:h,y:m}}const rc={spreadsheetLabel:"Spreadsheet",spreadsheetRightLabel:"more Sheets",toolbar:{undo:"Undo",redo:"Redo",formatPainter:"Paint format",currencyFormat:"Format as currency",percentageFormat:"Format as percent",numberDecrease:"Decrease decimal places",numberIncrease:"Increase decimal places",moreFormats:"More formats",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",customColor:"CUSTOM",alternatingColors:"Alternating colors",confirmColor:"OK",cancelColor:"Cancel",collapse:"Collapse",fillColor:{main:"Fill color",right:"Choose color"},border:{main:"Border",right:"Border style"},mergeCell:{main:"Merge cells",right:"Choose merge type"},horizontalAlignMode:{main:"Horizontal align",right:"Alignment"},verticalAlignMode:{main:"Vertical align",right:"Alignment"},textWrapMode:{main:"Text wrap",right:"Text wrap mode"},textRotateMode:{main:"Text rotate",right:"Text rotate mode"},freezeTopRow:"Freeze top row",sortAndFilter:"Sort and filter",findAndReplace:"Find and replace",sum:"SUM",autoSum:"Auto SUM",moreFunction:"More functions",conditionalFormat:"Conditional format",comment:"Comment",pivotTable:"Pivot Table",chart:"Chart",screenshot:"Screenshot",splitColumn:"Split text",insertImage:"Insert image",insertLink:"Insert link",dataValidation:"Data validation",protection:"Protect the sheet",clearText:"Clear color",noColorSelectedText:"No color is selected",toolMore:"More",toolLess:"Less",toolClose:"Close",toolMoreTip:"More features",moreOptions:"More options",cellFormat:"Cell format config",print:"Print",borderMethod:{top:"Upper frame line",bottom:"Lower frame line",left:"Left frame line",right:"Right frame line"},more:"More"},defaultFmt:{Automatic:{text:"Automatic",value:"General",example:""},Number:{text:"Number",value:"##0.00",example:"1000.12"},Percent:{text:"Percent",value:"#0.00%",example:"12.21%"},PlainText:{text:"Plain text",value:"@",example:""},Scientific:{text:"Scientific",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"Accounting",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"Ten Thousand",value:"w",example:"1亿2000万2500"},Currency:{text:"Currency",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"Date",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"Time",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"Time 24H",value:"hh:mm",example:"15:00"},DateTime:{text:"Date time",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"Date time 24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"Custom Formats",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"More currency formats",moreDateTime:"More date and time formats",moreNumber:"More number formats",titleCurrency:"Currency formats",decimalPlaces:"Decimal places",titleDateTime:"Date and time formats",titleNumber:"Number formats"},print:{normalBtn:"Normal",layoutBtn:"Page Layout",pageBtn:"Page break preview",menuItemPrint:"Print (Ctrl+P)",menuItemAreas:"Print areas",menuItemRows:"Print title rows",menuItemColumns:"Print title columns"},align:{left:"left",center:"center",right:"right",top:"top",middle:"middle",bottom:"bottom"},dateFmtList:[{name:"1930-08-05",value:"yyyy-MM-dd"},{name:"1930/8/5",value:"yyyy/MM/dd"},{name:"08-05",value:"MM-dd"},{name:"8-5",value:"M-d"},{name:"13:30:30",value:"h:mm:ss"},{name:"13:30",value:"h:mm"},{name:"PM 01:30",value:"AM/PM hh:mm"},{name:"PM 1:30",value:"AM/PM h:mm"},{name:"PM 1:30:30",value:"AM/PM h:mm:ss"},{name:"08-05 PM 01:30",value:"MM-dd AM/PM hh:mm"}],numFmtList:[{name:"1235",value:"0"},{name:"1234.56",value:"0.00"},{name:"1,235",value:"#,##0"},{name:"1,234.56",value:"#,##0.00"},{name:"1,235",value:"#,##0_);(#,##0)"},{name:"1,235",value:"#,##0_);[Red](#,##0)"},{name:"1,234.56",value:"#,##0.00_);(#,##0.00)"},{name:"1,234.56",value:"#,##0.00_);[Red](#,##0.00)"},{name:"$1,235",value:"$#,##0_);($#,##0)"},{name:"$1,235",value:"$#,##0_);[Red]($#,##0)"},{name:"$1,234.56",value:"$#,##0.00_);($#,##0.00)"},{name:"$1,234.56",value:"$#,##0.00_);[Red]($#,##0.00)"},{name:"1234.56",value:"@"},{name:"123456%",value:"0%"},{name:"123456.00%",value:"0.00%"},{name:"1.23E+03",value:"0.00E+00"},{name:"1.2E+3",value:"##0.0E+0"},{name:"1234 5/9",value:"# ?/?"},{name:"1234 14/25",value:"# ??/??"},{name:"$ 1,235",value:'_($* #,##0_);_(...($* "-"_);_(@_)'},{name:"1,235",value:'_(* #,##0_);_(*..._(* "-"_);_(@_)'},{name:"$ 1,234.56",value:'_($* #,##0.00_);_(...($* "-"_);_(@_)'},{name:"1,234.56",value:'_(* #,##0.00_);...* "-"??_);_(@_)'}],button:{confirm:"OK",cancel:"Cancel",close:"Close",update:"Update",delete:"Delete",insert:"Insert",prevPage:"Previous",nextPage:"Next",total:"total:"},punctuation:{tab:"Tab",semicolon:"semicolond",comma:"comma",space:"space"},colorPicker:{collapse:"Collapse",customColor:"CUSTOM",change:"Change",confirmColor:"OK",cancelColor:"Cancel"},borderLine:{borderTop:"borderTop",borderBottom:"borderBottom",borderLeft:"borderLeft",borderRight:"borderRight",borderNone:"borderNone",borderAll:"borderAll",borderOutside:"borderOutside",borderInside:"borderInside",borderHorizontal:"borderHorizontal",borderVertical:"borderVertical",borderColor:"borderColor",borderSize:"borderSize",borderType:"borderType"},merge:{all:"Merge all",vertical:"Vertical merge",horizontal:"Horizontal merge",cancel:"Cancel merge",overlappingError:"Cannot merge overlapping areas",partiallyError:"Cannot perform this operation on partially merged cells",confirm:{title:"Continue merging would only keep the upper-left cell value, discard other values. Are you sure to continue?",cancel:"Cancel merging",confirm:"Continue merging",waring:"Waring",dismantleMergeCellWaring:"This will cause some merged cells to be split. Do you want to continue?"}},textWrap:{overflow:"Overflow",wrap:"Wrap",clip:"Clip"},textRotate:{none:"None",angleUp:"Tilt Up",angleDown:"Tilt Down",vertical:"Stack Vertically",rotationUp:"Rotate Up",rotationDown:"Rotate Down"},sheetConfig:{delete:"Delete",copy:"Copy",rename:"Rename",changeColor:"Change color",hide:"Hide",unhide:"Unhide",moveLeft:"Move left",moveRight:"Move right",resetColor:"Reset color",cancelText:"Cancel",chooseText:"Confirm color",tipNameRepeat:"The name of the tab page cannot be repeated! Please revise",noMoreSheet:"The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.",confirmDelete:"Are you sure to delete",redoDelete:"Can be undo by Ctrl+Z",noHide:"Can't hide, at least keep one sheet tag",chartEditNoOpt:"This operation is not allowed in chart editing mode!",sheetNameErrorTitle:"There was a problem",sheetNameSpecCharError:`The name cannot contain:[ ] : ? * / ' "`,sheetNameCannotIsEmptyError:"The sheet name cannot be empty.",sheetNameAlreadyExistsError:"The sheet name already exists. Please enter another name.",deleteSheet:"Delete worksheet",deleteSheetContent:"Confirm to delete this worksheet. It will not be retrieved after deletion. Are you sure you want to delete it?"},rightClick:{copy:"Copy",copyAs:"Copy as",cut:"Cut",paste:"Paste",pasteSpecial:"Paste Special",pasteValue:"Paste Value",pasteFormat:"Paste Format",pasteColWidth:"Paste Column Width",pasteBesidesBorder:"Paste Besides Border Styles",insert:"Insert",insertRow:"Insert Row",insertRowBefore:"Insert Row Before",insertColumn:"Insert Column",insertColumnBefore:"Insert Column Before",delete:"Delete",deleteCell:"Delete Cell",insertCell:"Insert Cell",deleteSelected:"Delete Selected ",hide:"Hide",hideSelected:"Hide Selected ",showHide:"Show Hidden",toTopAdd:"Towards Top Add",toBottomAdd:"Towards Bottom Add",toLeftAdd:"Towards Left Add",toRightAdd:"Towards Right Add",deleteSelectedRow:"Delete Selected row",deleteSelectedColumn:"Delete Selected column",hideSelectedRow:"Hide Selected Row",showHideRow:"Show Selected Row",rowHeight:"Row Height",hideSelectedColumn:"Hide Selected Column",showHideColumn:"Show Hide Column",columnWidth:"Column Width",to:"Towards",left:"Left",right:"Right",top:"Top",bottom:"Bottom",moveLeft:"Move Left",moveUp:"Move up",moveRight:"Move Right",moveDown:"Move Down",add:"Add",row:"Row",column:"Column",width:"Width",height:"Height",number:"Number",confirm:"Confirm",orderAZ:"A-Z order",orderZA:"Z-A order",clearSelection:"Clear",clearContent:"Clear Contents",clearFormat:"Clear Formats",clearAll:"Clear All",matrix:"Matrix operation",sortSelection:"Sort",filterSelection:"Filter",chartGeneration:"Create Chart",firstLineTitle:"First Line Title",untitled:"Untitled",array1:"One-dimensional array",array2:"Two-dimensional array",array3:"Multidimensional Arrays",diagonal:"Diagonal",antiDiagonal:"Anti-diagonal",diagonalOffset:"Diagonal offset",offset:"Offset",boolean:"Boolean",flip:"Flip",upAndDown:"Up and down",leftAndRight:"Left and right",clockwise:"Clockwise",counterclockwise:"Counterclockwise",transpose:"Transpose",matrixCalculation:"Matrix Calculation",plus:"Plus",minus:"Minus",multiply:"Multiply",divided:"Divided",power:"Power",root:"Root",log:"Log",delete0:"Delete 0 values at both ends",removeDuplicate:"Remove duplicate values",byRow:"By row",byCol:"By column",generateNewMatrix:"Generate new matrix",fitContent:"Fit for data",freeze:"Freeze",freezeCol:"Freeze to this column",freezeRow:"Freeze to this row",cancelFreeze:"Cancel freeze",zenEditor:"Full Screen Editor",deleteAllRowsAlert:"You can't delete all the rows on the sheet",deleteAllColumnsAlert:"You can't delete all the columns on the sheet",hideAllRowsAlert:"You can't hide all the rows on the sheet",hideAllColumnsAlert:"You can't hide all the columns on the sheet"},info:{tooltip:"Tooltip",notChangeMerge:"You cannot make partial changes to the merged cells",detailUpdate:"New opened",detailSave:"Local cache restored",row:"",column:"",loading:"Loading...",copy:"Copy",return:"Exit",rename:"Rename",tips:"Rename",noName:"Untitled spreadsheet",wait:"waiting for update",add:"Add",addLast:"more rows at bottom",backTop:"Back to the top",pageInfo:"Total ${total},${totalPage} page,current ${currentPage}",nextPage:"Next",tipInputNumber:"Please enter the number",tipInputNumberLimit:"The increase range is limited to 1-100",tipRowHeightLimit:"Row height must be between 0 ~ 545",tipColumnWidthLimit:"The column width must be between 0 ~ 2038",pageInfoFull:"Total ${total},${totalPage} page,All data displayed",problem:"There was a problem"},clipboard:{paste:{exceedMaxCells:"The number of cells pasted exceeds the maximum number of cells"}},statusbar:{sum:"Sum",average:"Average",min:"Min",max:"Max",count:"Numerical Count",countA:"Count",clickToCopy:"Click to Copy",copied:"Copied"},autoFill:{copy:"Copy Cell",series:"Fill Series",formatOnly:"Format Only",noFormat:"No Format"},rangeSelector:{placeholder:"Select range or input value",tooltip:"Select range"},shortcut:{sheet:{"zoom-in":"Zoom in","zoom-out":"Zoom out","reset-zoom":"Reset zoom level","select-below-cell":"Select the cell below","select-up-cell":"Select the cell above","select-left-cell":"Select the left cell","select-right-cell":"Select the right cell","select-next-cell":"Select the next cell","select-previous-cell":"Select the previous cell","select-up-value-cell":"Select the cell above that has value","select-below-value-cell":"Select the cell below that has value","select-left-value-cell":"Select the cell left that has value","select-right-value-cell":"Select the cell right that has value","expand-selection-down":"Expand selection down","expand-selection-up":"Expand selection up","expand-selection-left":"Expand selection left","expand-selection-right":"Expand selection right","expand-selection-to-left-gap":"Expand selection to the left gap","expand-selection-to-below-gap":"Expand selection to the below gap","expand-selection-to-right-gap":"Expand selection to the right gap","expand-selection-to-up-gap":"Expand selection to the up gap","select-all":"Select all","toggle-editing":"Toggle editing","delete-and-start-editing":"Clear and start editing","abort-editing":"Abort editing","break-line":"Break line","set-bold":"Toggle bold","set-italic":"Toggle italic","set-underline":"Toggle underline","set-strike-through":"Toggle strike through"}},"sheet-view":"Sheet View","sheet-edit":"Sheet Edit"},Rr={spreadsheetLabel:"插件",spreadsheetRightLabel:"更多 Sheets",toolbar:{undo:"撤销",redo:"重做",formatPainter:"格式刷",currencyFormat:"货币格式",percentageFormat:"百分比格式",numberDecrease:"减少小数位数",numberIncrease:"增加小数位数",moreFormats:"更多格式",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",customColor:"自定义",alternatingColors:"交替颜色",confirmColor:"确定颜色",cancelColor:"取消",collapse:"收起",fillColor:{main:"单元格颜色",right:"颜色选择"},border:{main:"边框",right:"边框类型"},mergeCell:{main:"合并单元格",right:"选择合并类型"},horizontalAlignMode:{main:"水平对齐",right:"对齐方式"},verticalAlignMode:{main:"垂直对齐",right:"对齐方式"},textWrapMode:{main:"文本换行",right:"换行方式"},textRotateMode:{main:"文本旋转",right:"旋转方式"},freezeTopRow:"冻结首行",sortAndFilter:"排序和筛选",findAndReplace:"查找替换",sum:"求和",autoSum:"自动求和",moreFunction:"更多函数",conditionalalFormat:"条件格式",comment:"批注",pivotTable:"数据透视表",chart:"图表",screenshot:"截图",splitColumn:"分列",insertImage:"插入图片",insertLink:"插入链接",dataValidation:"数据验证",protection:"保护工作表内容",clearText:"清除颜色选择",noColorSelectedText:"没有颜色被选择",toolMore:"更多",toolLess:"少于",toolClose:"收起",toolMoreTip:"更多功能",moreOptions:"更多选项",cellFormat:"设置单元格格式",print:"打印",borderMethod:{top:"上框线",bottom:"下框线",left:"左框线",right:"右框线"},more:"更多"},defaultFmt:{Automatic:{text:"自动",value:"General",example:""},Number:{text:"数字",value:"##0.00",example:"1000.12"},Percent:{text:"百分比",value:"#0.00%",example:"12.21%"},PlainText:{text:"纯文本",value:"@",example:""},Scientific:{text:"科学计数",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"会计",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"万元",value:"w",example:"1亿2000万2500"},Currency:{text:"货币",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"日期",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"时间",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"时间24H",value:"hh:mm",example:"15:00"},DateTime:{text:"日期时间",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"日期时间24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"自定义格式",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"更多货币格式",moreDateTime:"更多日期与时间格式",moreNumber:"更多数字格式",titleCurrency:"货币格式",decimalPlaces:"小数位数",titleDateTime:"日期与时间格式",titleNumber:"数字格式"},print:{normalBtn:"常规视图",layoutBtn:"页面布局",pageBtn:"分页预览",menuItemPrint:"打印(Ctrl+P)",menuItemAreas:"打印区域",menuItemRows:"打印标题行",menuItemColumns:"打印标题列"},align:{left:"左对齐",center:"中间对齐",right:"右对齐",top:"顶部对齐",middle:"居中对齐",bottom:"底部对齐"},button:{confirm:"确定",cancel:"取消",close:"关闭",update:"Update",delete:"Delete",insert:"新建",prevPage:"上一页",nextPage:"下一页",total:"总共:"},punctuation:{tab:"Tab 键",semicolon:"分号",comma:"逗号",space:"空格"},colorPicker:{collapse:"收起",customColor:"自定义",change:"切换",confirmColor:"确定",cancelColor:"取消"},borderLine:{borderTop:"上框线",borderBottom:"下框线",borderLeft:"左框线",borderRight:"右框线",borderNone:"无",borderAll:"所有",borderOutside:"外侧",borderInside:"内侧",borderHorizontal:"内侧横线",borderVertical:"内侧竖线",borderColor:"边框颜色",borderSize:"边框粗细",borderType:"边框线类型"},merge:{all:"全部合并",vertical:"垂直合并",horizontal:"水平合并",cancel:"取消合并",overlappingError:"不能合并重叠区域",partiallyError:"无法对部分合并单元格执行此操作",confirm:{title:"合并单元格仅保存左上角单元格的值,是否继续?",cancel:"取消合并",confirm:"继续合并",waring:"警告",dismantleMergeCellWaring:"此操作会导致一些合并单元格被拆散,是否继续?"}},textWrap:{overflow:"溢出",wrap:"自动换行",clip:"截断"},textRotate:{none:"无旋转",angleUp:"向上倾斜",angleDown:"向下倾斜",vertical:"竖排文字",rotationUp:"向上90°",rotationDown:"向下90°"},sheetConfig:{delete:"删除",copy:"复制",rename:"重命名",changeColor:"更改颜色",hide:"隐藏",unhide:"取消隐藏",moveLeft:"向左移",moveRight:"向右移",resetColor:"重置颜色",cancelText:"取消",chooseText:"确定颜色",tipNameRepeat:"标签页的名称不能重复!请重新修改",noMoreSheet:"工作薄内至少含有一张可视工作表。若需删除选定的工作表,请先插入一张新工作表或显示一张隐藏的工作表。",confirmDelete:"是否删除",redoDelete:"可以通过Ctrl+Z撤销删除",noHide:"不能隐藏, 至少保留一个sheet标签",chartEditNoOpt:"图表编辑模式下不允许该操作!",sheetNameErrorTitle:"错误",sheetNameSpecCharError:`名称不能超过31个字符,首尾不能是' 且名称不能包含:\r
18
- [ ] : \\ ? * /`,sheetNameCannotIsEmptyError:"名称不能为空。",sheetNameAlreadyExistsError:"工作表已存在,请输入其它名称。",deleteSheet:"删除工作表",deleteSheetContent:"确认删除此工作表,删除后将不可找回,确定要删除吗?"},rightClick:{copy:"复制",copyAs:"复制为",cut:"剪切",paste:"粘贴",pasteSpecial:"选择性粘贴",pasteValue:"仅粘贴值",pasteFormat:"仅粘贴格式",pasteColWidth:"仅粘贴列宽",pasteBesidesBorder:"仅粘贴边框以外内容",insert:"插入",delete:"删除",insertRow:"插入行",insertRowBefore:"在上方插入行",insertColumn:"插入列",insertColumnBefore:"在左侧插入列",deleteCell:"删除单元格",insertCell:"插入单元格",deleteSelected:"删除选中",hide:"隐藏",hideSelected:"隐藏选中",showHide:"显示隐藏",toTopAdd:"向上增加",toBottomAdd:"向下增加",toLeftAdd:"向左增加",toRightAdd:"向右增加",deleteSelectedRow:"删除选中行",deleteSelectedColumn:"删除选中列",hideSelectedRow:"隐藏选中行",showHideRow:"显示隐藏行",rowHeight:"行高",hideSelectedColumn:"隐藏选中列",showHideColumn:"显示隐藏列",columnWidth:"列宽",to:"向",left:"左",right:"右",top:"上",bottom:"下",moveLeft:"左移",moveUp:"上移",moveRight:"右移",moveDown:"下移",add:"增加",row:"行",column:"列",width:"宽",height:"高",number:"数字",confirm:"确认",orderAZ:"A-Z顺序排列",orderZA:"Z-A降序排列",clearSelection:"清除",clearContent:"清除内容",clearFormat:"清除格式",clearAll:"清除全部",matrix:"矩阵操作选区",sortSelection:"排序选区",filterSelection:"筛选选区",chartGeneration:"图表生成",firstLineTitle:"首行为标题",untitled:"无标题",array1:"一维数组",array2:"二维数组",array3:"多维数组",diagonal:"对角线",antiDiagonal:"反对角线",diagonalOffset:"对角偏移",offset:"偏移量",boolean:"布尔值",flip:"翻转",upAndDown:"上下",leftAndRight:"左右",clockwise:"顺时针",counterclockwise:"逆时针",transpose:"转置",matrixCalculation:"矩阵计算",plus:"加",minus:"减",multiply:"乘",divided:"除",power:"次方",root:"次方根",log:"log",delete0:"删除两端0值",removeDuplicate:"删除重复值",byRow:"按行",byCol:"按列",generateNewMatrix:"生成新矩阵",fitContent:"适合数据",freeze:"冻结",freezeCol:"冻结列",freezeRow:"冻结行",cancelFreeze:"取消冻结",zenEditor:"禅模式编辑",deleteAllRowsAlert:"您无法删除工作表上的所有行",deleteAllColumnsAlert:"您无法删除工作表上的所有列",hideAllRowsAlert:"您无法隐藏工作表上的所有行",hideAllColumnsAlert:"您无法隐藏工作表上的所有列"},info:{tooltip:"提示",notChangeMerge:"不能对合并单元格做部分更改",detailUpdate:"新打开",detailSave:"已恢复本地缓存",row:"行",column:"列",loading:"渲染中···",copy:"副本",return:"返回",rename:"重命名",tips:"重命名",noName:"无标题的电子表格",wait:"待更新",add:"添加",addLast:"在底部添加",backTop:"回到顶部",pageInfo:"共${total}条,${totalPage}页,当前已显示${currentPage}页",nextPage:"下一页",tipInputNumber:"请输入数字",tipInputNumberLimit:"增加范围限制在1-100",tipRowHeightLimit:"行高必须在0 ~ 545之间",tipColumnWidthLimit:"列宽必须在0 ~ 2038之间",pageInfoFull:"共${total}条,${totalPage}页,已显示全部数据",problem:"出现了一个问题"},clipboard:{paste:{exceedMaxCells:"粘贴区域超出最大单元格数"}},statusbar:{sum:"求和",average:"平均值",min:"最小值",max:"最大值",count:"数值计数",countA:"计数",clickToCopy:"点击复制数值",copied:"已复制"},autoFill:{copy:"复制单元格",series:"填充序列",formatOnly:"仅填充格式",noFormat:"不带格式填充"},rangeSelector:{placeholder:"选择范围或输入值",tooltip:"选择范围"},shortcut:{sheet:{"zoom-in":"放大","zoom-out":"缩小","reset-zoom":"恢复缩放","select-below-cell":"选择下方单元格","select-up-cell":"选择上方单元格","select-left-cell":"选择左侧单元格","select-right-cell":"选择右侧单元格","select-next-cell":"选择后一个单元格","select-previous-cell":"选择前一个单元格","select-up-value-cell":"选择上方有值的单元格","select-below-value-cell":"选择下方有值的单元格","select-left-value-cell":"选择左侧有值的单元格","select-right-value-cell":"选择右侧有值的单元格","expand-selection-down":"向下扩展选区","expand-selection-up":"向上扩展选区","expand-selection-left":"向左扩展选区","expand-selection-right":"向右扩展选区","expand-selection-to-left-gap":"向左扩展选区到下一个边界","expand-selection-to-below-gap":"向下扩展选区到下一个边界","expand-selection-to-right-gap":"向右扩展选区到下一个边界","expand-selection-to-up-gap":"向上扩展选区到下一个边界","select-all":"全选","toggle-editing":"开始 / 结束编辑","delete-and-start-editing":"清空并开始编辑","abort-editing":"放弃编辑","break-line":"换行","set-bold":"切换粗体","set-italic":"切换斜体","set-underline":"切换下划线","set-strike-through":"切换删除线"}},"sheet-view":"浏览表格","sheet-edit":"编辑表格"},sc=(i,e,n=!1)=>{const t=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=t(e)%t(i),s=o(e)%o(i),l={startRow:0,endRow:t(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(t(e)/t(i)),d=Math.floor(o(e)/o(i)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let m=1;m<=d;m++){const S=t(i)*(h-1),_=o(i)*(m-1),f={startRow:S+e.startRow,endRow:S+e.startRow,startColumn:_+e.startColumn,endColumn:_+e.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else if(!r&&s&&!n)for(let h=1;h<=c;h++){const m=t(i)*(h-1),S=0,_={startRow:m+e.startRow,endRow:m+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:l,startRange:_})}else if(r&&!s&&!n)for(let h=1;h<=d;h++){const S=o(i)*(h-1),_={startRow:0+e.startRow,endRow:0+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:l,startRange:_})}else{const h={startRow:e.startRow,endRow:e.startRow,startColumn:e.startColumn,endColumn:e.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};class br{constructor(){C(this,"_state",null);C(this,"_rect",null);C(this,"_focus",!1);C(this,"_state$",new P.BehaviorSubject(null));C(this,"state$",this._state$.asObservable());C(this,"_rect$",new P.BehaviorSubject(null));C(this,"rect$",this._rect$.asObservable());C(this,"_focus$",new P.BehaviorSubject(this._focus));C(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(e){this._state=e,this._refresh(e)}getRect(){return this._rect}setRect(e){this._rect=e,this._rect$.next(e)}getState(){return this._state}setFocus(e=!1){this._focus=e,this._focus$.next(e)}_refresh(e){this._state$.next(e)}}const zt=N.createIdentifier("univer.sheet-cell-editor-manager.service");class ac{constructor(){C(this,"_position",null);C(this,"_position$",new P.BehaviorSubject(null));C(this,"position$",this._position$.asObservable());C(this,"_focus",!1);C(this,"_focus$",new P.BehaviorSubject(this._focus));C(this,"focus$",this._focus$.asObservable());C(this,"_fxBtnClick$",new P.BehaviorSubject(!1));C(this,"fxBtnClick$",this._fxBtnClick$.asObservable());C(this,"_foldBtnStatus$",new P.BehaviorSubject(!1));C(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(e){this._position=e,this._refresh(e)}getPosition(){return this._position}setFocus(e=!1){this._focus=e,this._focus$.next(e)}handleFxBtnClick(e){this._fxBtnClick$.next(e)}handleFoldBtnClick(e){this._foldBtnStatus$.next(e)}_refresh(e){this._position$.next(e)}}const Mn=N.createIdentifier("univer.sheet-formula-editor-manager.service");var lc=Object.defineProperty,cc=Object.getOwnPropertyDescriptor,dc=(i,e,n,t)=>{for(var o=t>1?void 0:t?cc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&lc(e,n,o),o},wr=(i,e)=>(n,t)=>e(n,t,i);let Rn=class extends a.Disposable{constructor(e,n){super();C(this,"_previousSheetIndex",-1);this._commandService=e,this._univerInstanceService=n,this.disposeWithMe(this._commandService.beforeCommandExecuted((t,o)=>{if(t.id===g.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(t)})),this.disposeWithMe(this._commandService.onCommandExecuted((t,o)=>{if(t.id===g.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===g.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(!(o!=null&&o.fromCollab)){if(t.id===g.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(t);if(t.id===g.SetWorksheetHideMutation.id&&!t.params.hidden)return this._adjustActiveSheetOnShowSheet(t)}}))}_adjustActiveSheetOnHideSheet(e){const{unitId:n,subUnitId:t}=e.params,o=this._univerInstanceService.getUniverSheetInstance(n);if(!o||(o==null?void 0:o.getRawActiveSheet())!==t)return;const s=o.getActiveSheetIndex(),l=Tr(o,s);this._switchToNextSheet(n,l)}_beforeAdjustActiveSheetOnRemoveSheet(e){const{unitId:n,subUnitId:t}=e.params,o=this._univerInstanceService.getUniverSheetInstance(n);if(!o)return;const r=o.getSheetBySheetId(t);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(e){if(this._previousSheetIndex===-1)return;const{unitId:n}=e.params,t=this._univerInstanceService.getUniverSheetInstance(n);if(!t||t.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,l=Tr(t,s);this._switchToNextSheet(n,l)}_adjustActiveSheetOnInsertSheet(e){const{unitId:n,sheet:t}=e.params;this._switchToNextSheet(n,t.id)}_adjustActiveSheetOnShowSheet(e){const{unitId:n,subUnitId:t}=e.params;this._switchToNextSheet(n,t)}_switchToNextSheet(e,n){this._commandService.executeCommand(g.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:n})}};Rn=dc([a.OnLifecycle(a.LifecycleStages.Ready,Rn),wr(0,a.ICommandService),wr(1,a.IUniverInstanceService)],Rn);function Tr(i,e){const n=i.getSheetSize();for(let t=e;t>-1;t--){const o=i.getSheetByIndex(t);if(!o.getConfig().hidden)return o.getSheetId()}for(let t=e;t<n;t++){const o=i.getSheetByIndex(t);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var uc=Object.defineProperty,hc=Object.getOwnPropertyDescriptor,mc=(i,e,n,t)=>{for(var o=t>1?void 0:t?hc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&uc(e,n,o),o},Xt=(i,e)=>(n,t)=>e(n,t,i);let bn=class{constructor(i,e,n,t,o){this._injector=i,this._sheetInterceptorService=e,this._selectionManagerService=n,this._univerInstanceService=t,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e,_sheetSkeletonManagerService:n,_injector:t}=this,{skeleton:o}=n.getCurrent(),r=o.calculateAutoHeightInRange(i),s=e.getCurrentUniverSheetInstance(),l=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:l,rowsAutoHeightInfo:r},u=g.SetWorksheetRowAutoHeightMutationFactory(t,d);return{undos:[{id:g.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:g.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;i.interceptCommand({getMutations:n=>n.id!==g.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(n.params.range)}),i.interceptCommand({getMutations:n=>n.id!==g.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(n.params.ranges)}),i.interceptCommand({getMutations:n=>{var r;if(n.id!==g.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=n.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=e.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};bn=mc([a.OnLifecycle(a.LifecycleStages.Ready,bn),Xt(0,N.Inject(N.Injector)),Xt(1,N.Inject(g.SheetInterceptorService)),Xt(2,N.Inject(g.SelectionManagerService)),Xt(3,N.Inject(a.IUniverInstanceService)),Xt(4,N.Inject(A.SheetSkeletonManagerService))],bn);var Sc=Object.defineProperty,_c=Object.getOwnPropertyDescriptor,gc=(i,e,n,t)=>{for(var o=t>1?void 0:t?_c(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Sc(e,n,o),o},Oe=(i,e)=>(n,t)=>e(n,t,i);let wn=class extends a.RxDisposable{constructor(i,e,n,t,o,r,s,l,c,d,u){var h;super(),this._injector=i,this._currentUniverSheet=e,this._commandService=n,this._contextService=t,this._configService=o,this._sheetClipboardService=r,this._clipboardInterfaceService=s,this._messageService=l,this._sheetSkeletonManagerService=c,this._localService=d,this._textSelectionRenderManager=u,this._init(),this._clipboardInterfaceService.supportClipboard||(h=this._textSelectionRenderManager)==null||h.onPaste$.pipe(P.takeUntil(this.dispose$)).subscribe(m=>{var v,M;if(!ie(this._contextService))return;m.event.preventDefault();const S=m.event,_=(v=S.clipboardData)==null?void 0:v.getData("text/html"),f=(M=S.clipboardData)==null?void 0:M.getData("text/plain");this._sheetClipboardService.legacyPaste(_,f)})}_init(){[xo,ha,ht].forEach(e=>this.disposeWithMe(this._commandService.registerMultipleCommand(e))),[Ao,Do,No,Po].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initCopyingHooks())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initPastingHook()));const i=this._initSpecialPasteHooks().map(e=>this._sheetClipboardService.addClipboardHook(e));this.disposeWithMe({dispose:()=>i.forEach(e=>e.dispose())})}_initCopyingHooks(){const i=this;let e=null;return{id:pe.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(n,t){e=i._getWorksheet(n,t)},onCopyCellContent(n,t){const o=e.getCell(n,t);return`${(o==null?void 0:o.v)||""}`},onCopyCellStyle:(n,t,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=e.getRange(n,t).getTextStyle();let d="";return c&&(d=a.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(n){return{width:`${e.getColumnWidth(n)}`}},onCopyRow(n){return{style:`height: ${e.getRowHeight(n)}px;`}},onAfterCopy(){e=null}}}_initPastingHook(){const i=this;let e=null,n=null,t=null;return{id:pe.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste({unitId:o,subUnitId:r,range:s}){t=i._getWorksheet(o,r),e=o,n=r;const l=i._configService.getConfig(g.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return l&&c*d>l?(i._messageService.show({type:Se.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const{range:s}=o,l=[],c=t.getMaxRows(),d=s.endRow-c,u=r.length-d;if(d>0){const S={};r.slice(u).forEach((f,v)=>{const M=f==null?void 0:f.style;if(!M)return;const R=M.split(";");let T=a.DEFAULT_WORKSHEET_ROW_HEIGHT;R.find(w=>{w=w.toLowerCase();const E=I.textTrim(w.substr(0,w.indexOf(":"))),y=I.textTrim(w.substr(w.indexOf(":")+1));return E==="height"?(T=Number.parseFloat(y),!0):!1}),S[v]={h:T,hd:a.BooleanNumber.FALSE}});const _={unitId:e,subUnitId:n,range:{...s,startRow:c},rowInfo:S};l.push({id:g.InsertRowMutation.id,params:_})}const h={};r.slice(0,u).forEach((S,_)=>{const f=S.style;if(!f)return;const v=f.split(";");let M=a.DEFAULT_WORKSHEET_ROW_HEIGHT;v.find(R=>{R=R.toLowerCase();const T=I.textTrim(R.substr(0,R.indexOf(":"))),w=I.textTrim(R.substr(R.indexOf(":")+1));return T==="height"?(M=Number.parseFloat(w),!0):!1}),h[_]=M});const m={unitId:e,subUnitId:n,ranges:[{...s,endRow:Math.min(s.endRow,c)}],rowHeight:h};return l.push({id:g.SetWorksheetRowHeightMutation.id,params:m}),{redos:l,undos:[]}},onPasteColumns(o,r,s){const{range:l}=o,c=[],d=t.getMaxColumns(),u=l.endColumn-d,h=r.length-u;if(u>0){const S={unitId:e,subUnitId:n,range:{...l,startColumn:d},colInfo:r.slice(h).map(_=>({w:_.width?+_.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH,hd:a.BooleanNumber.FALSE}))};c.push({id:g.InsertColMutation.id,params:S})}const m={unitId:e,subUnitId:n,ranges:[{...l,endRow:Math.min(l.endColumn,d)}],colWidth:r.slice(0,h).map(S=>S.width?+S.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return c.push({id:g.SetWorksheetColWidthMutation.id,params:m}),{redos:c,undos:[]}},onPastePlainText(o,r,s){return i._onPastePlainText(o,r,s)},onPasteCells(o,r,s,l){return i._onPasteCells(o,r,s,l)},onAfterPaste(o){t=null}}}_generateDocumentDataModelSnapshot(i){var s;const e=this._sheetSkeletonManagerService.getCurrent();if(e==null)return null;const{skeleton:n}=e,t=(s=n.getBlankCellDocumentModel())==null?void 0:s.documentModel,r={...t==null?void 0:t.getSnapshot(),...i};return t==null||t.reset(r),t==null?void 0:t.getSnapshot()}_onPastePlainText(i,e,n){const{range:t,unitId:o,subUnitId:r}=i;let s;if(/\r|\n/.test(e)){const c=wo(e),d=this._generateDocumentDataModelSnapshot({body:c});s={[t.startRow]:{[t.startColumn]:{p:d}}}}else s={[t.startRow]:{[t.startColumn]:{v:e}}};const l={unitId:o,subUnitId:r,cellValue:s};return{redos:[{id:g.SetRangeValuesMutation.id,params:l}],undos:[{id:g.SetRangeValuesMutation.id,params:g.SetRangeValuesUndoMutationFactory(this._injector,l)}]}}_onPasteCells(i,e,n,t){const o={get:this._injector.get.bind(this._injector)};return Ws(i,e,n,t,o)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},e=this,n={id:pe.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,l,c,d)=>{const u=e._currentUniverSheet.getCurrentUniverSheetInstance();return u.getUnitId(),u.getActiveSheet().getSheetId(),Mo(l,c,i)}},t={id:pe.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,l,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance();u.getUnitId(),u.getActiveSheet().getSheetId();const h=[],m=[],{undos:S,redos:_}=bo(l,c,i);h.push(..._),m.push(...S);const{undos:f,redos:v}=ai(l,c,i);h.push(...v),m.push(...f);const{undos:M,redos:R}=Ro(l,c,i);return h.push(...R),m.push(...M),{undos:m,redos:h}}},o={id:pe.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,l,c){const d=e._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],S=e._getWorksheet(u,h),{range:_}=s,f=S.getMaxColumns(),v=_.endColumn-f,M=l.length-v,R={unitId:u,subUnitId:h,ranges:[{..._,endRow:Math.min(_.endColumn,f)}],colWidth:l.slice(0,M).map(T=>T.width?+T.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return m.push({id:g.SetWorksheetColWidthMutation.id,params:R}),m.push({id:g.SetWorksheetColWidthMutation.id,params:R}),{redos:m,undos:[]}}},r={id:pe.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,l,c,d){e._currentUniverSheet.getCurrentUniverSheetInstance();const u=[],h=[],{range:m,unitId:S,subUnitId:_}=l,{startColumn:f,startRow:v,endColumn:M,endRow:R}=m,T=new a.ObjectMatrix;c.forValue((O,D,B)=>{const H=B.s;typeof H=="object"&&T.setValue(O+v,D+f,{s:{...H,bd:void 0},v:B.v})});const w={unitId:S,subUnitId:_,cellValue:T.getData()};u.push({id:g.SetRangeValuesMutation.id,params:w});const E=g.SetRangeValuesUndoMutationFactory(i,w);h.push({id:g.SetRangeValuesMutation.id,params:E});const{undos:y,redos:x}=ai(l,c,i);return h.push(...y),u.push(...x),{redos:u,undos:h}}};return[n,t,o,r]}_getWorksheet(i,e){var t;const n=(t=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:t.getSheetBySheetId(e);if(!n)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${e}.`);return n}};wn=gc([a.OnLifecycle(a.LifecycleStages.Steady,wn),Oe(0,N.Inject(N.Injector)),Oe(1,a.IUniverInstanceService),Oe(2,a.ICommandService),Oe(3,a.IContextService),Oe(4,a.IConfigService),Oe(5,ut),Oe(6,I.IClipboardInterfaceService),Oe(7,I.IMessageService),Oe(8,N.Inject(A.SheetSkeletonManagerService)),Oe(9,N.Inject(a.LocaleService)),Oe(10,N.Optional(b.ITextSelectionRenderManager))],wn);var fc=Object.defineProperty,pc=Object.getOwnPropertyDescriptor,vc=(i,e,n,t)=>{for(var o=t>1?void 0:t?pc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&fc(e,n,o),o},Yt=(i,e)=>(n,t)=>e(n,t,i);let Tn=class extends a.Disposable{constructor(i,e,n,t,o){super(),this._currentUniverService=i,this._contextMenuService=e,this._renderManagerService=n,this._selectionManagerService=t,this._selectionRenderService=o,this._currentUniverService.currentSheet$.subscribe(r=>{if(r==null)throw new Error("workbook is null");this._addListeners()})}_addListeners(){const i=ve(this._currentUniverService,this._renderManagerService);if(!i)return;const e=i.spreadsheet.onPointerDownObserver,n=e.add(l=>{if(l.button===2){const c=this._selectionManagerService.getSelections(),d=c==null?void 0:c[0];if(!d)return;const u=d.range.rangeType,h=this._selectionRenderService.convertSelectionRangeToData(d).rangeWithCoord,m=()=>{if(!h)return!1;const _=l.offsetX,f=l.offsetY;switch(u){case a.RANGE_TYPE.ROW:return h.startY<=f&&h.endY>=f;case a.RANGE_TYPE.COLUMN:return h.startX<=_&&h.endX>=_;default:return h.startX<=_&&h.endX>=_&&h.startY<=f&&h.endY>=f}},S=_=>{this._contextMenuService.triggerContextMenu(l,_)};m()?u===a.RANGE_TYPE.COLUMN?S(de.COL_HEADER_CONTEXT_MENU):u===a.RANGE_TYPE.ROW?S(de.ROW_HEADER_CONTEXT_MENU):S(I.MenuPosition.CONTEXT_MENU):S(I.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(a.toDisposable(()=>e.remove(n)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,de.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,de.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(s)))}};Tn=vc([a.OnLifecycle(a.LifecycleStages.Rendered,Tn),Yt(0,a.IUniverInstanceService),Yt(1,I.IContextMenuService),Yt(2,b.IRenderManagerService),Yt(3,N.Inject(g.SelectionManagerService)),Yt(4,_e)],Tn);var Cc=Object.defineProperty,Ic=Object.getOwnPropertyDescriptor,Mc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ic(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Cc(e,n,o),o},Ai=(i,e)=>(n,t)=>e(n,t,i);let En=class extends a.RxDisposable{constructor(i,e,n){super(),this._currentUniverService=i,this._renderManagerService=e,this._undoRedoService=n,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(e=>{const n=e.getConfig();i[e.getSheetId()]={cellData:new a.ObjectMatrix(n.cellData),rowCount:n.rowCount,columnCount:n.columnCount}})}_commandExecutedListener(){}_getDocObject(){return q.getDocObject(this._currentUniverService,this._renderManagerService)}};En=Mc([a.OnLifecycle(a.LifecycleStages.Steady,En),Ai(0,a.IUniverInstanceService),Ai(1,b.IRenderManagerService),Ai(2,N.Inject(a.IUndoRedoService))],En);const Er=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],Rc=[I.KeyCode.ENTER,I.KeyCode.TAB,...Er];function bc(){const i=[];for(const e of Er)i.push({id:Bt.id,binding:e,preconditions:n=>dn(n),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!1}}),i.push({id:Bt.id,binding:e|I.MetaKeys.SHIFT,preconditions:n=>dn(n),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!0}});return i}const wc={id:Pe.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>dn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},Tc={id:Pe.id,binding:I.KeyCode.TAB,preconditions:i=>dn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},Ec={id:Pe.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>ri(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},yc={id:q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>ri(i),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},Oc={id:q.DeleteLeftCommand.id,preconditions:i=>Ms(i)||_o(i),binding:I.KeyCode.BACKSPACE},xc={id:Pe.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ie(i)&&!_o(i),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};var Ac=Object.defineProperty,Dc=Object.getOwnPropertyDescriptor,Nc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Dc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ac(e,n,o),o},He=(i,e)=>(n,t)=>e(n,t,i);function Pc(i){const{textRuns:e=[],paragraphs:n=[]}=i;return e.some(t=>t.ts&&!a.Tools.isEmptyObject(t.ts))||n.some(t=>t.bullet)||n.length>=2}let yn=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_onInputSubscription");C(this,"_cursorChangeObservers");C(this,"_editorVisiblePrevious",!1);C(this,"_isCursorChange",0);this._currentUniverService=e,this._renderManagerService=n,this._commandService=t,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._undoRedoService=c,this._sheetInterceptorService=d,this._selectionManagerService=u,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe();const e=this._getEditorObject();if(e==null)return;const{document:n}=e;n.onPointerDownObserver.remove(this._cursorChangeObservers)}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this._onInputSubscription=this._editorBridgeService.visible$.subscribe(e=>{const{visible:n,keycode:t,eventType:o}=e;if(n===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=n,n===!0){this._isCursorChange=o===b.DeviceInputEventType.PointerDown?2:1;return}this._isCursorChange=0;const r=this._selectionManagerService.getSelections(),s=this._selectionManagerService.getCurrent();if(s==null)return;const{unitId:l,sheetId:c,pluginName:d}=s;if(this._exitInput(e),t===I.KeyCode.ESC){this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,{unitId:l,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getEditCellState();if(u==null)return;const{unitId:h,sheetId:m,row:S,column:_,documentLayoutObject:f}=u;if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(t);return}const M=this._currentUniverService.getUniverSheetInstance(h),R=M==null?void 0:M.getSheetBySheetId(m);if(R==null)return;const T=Hc(R.getCellRaw(S,_)||{},f,this._lexerTreeBuilder);if(T==null){this._moveCursor(t);return}const w={subUnitId:m,unitId:h,workbook:M,worksheet:R,row:S,col:_},E=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(T,w);this._commandService.executeCommand(g.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:S,startColumn:_,endRow:S,endColumn:_},value:E}),this._moveCursor(t),l===h&&m!==c&&this._editorBridgeService.isForceKeepVisible()&&this._commandService.executeCommand(g.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h}),this._selectionManagerService.refreshSelection()})}_exitInput(e){this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const n=this._editorBridgeService.getCurrentEditorId();n!=null&&(this._undoRedoService.clearUndoRedo(n),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Rc.includes(e))return;let n=a.Direction.LEFT;switch(e){case I.KeyCode.ENTER:n=a.Direction.DOWN;break;case I.KeyCode.TAB:n=a.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:n=a.Direction.DOWN;break;case I.KeyCode.ARROW_UP:n=a.Direction.UP;break;case I.KeyCode.ARROW_LEFT:n=a.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:n=a.Direction.RIGHT;break}e===I.KeyCode.ENTER||e===I.KeyCode.TAB?this._commandService.executeCommand(it.id,{keycode:e,direction:n}):this._commandService.executeCommand(Re.id,{direction:n})}_cursorStateListener(){const e=this._getEditorObject();if(e==null)return;const{document:n}=e;this._cursorChangeObservers=n.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})}_commandExecutedListener(){const e=[Bt.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){const t=n.params,{keycode:o,isShift:r}=t;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(t)}}))}_moveInEditor(e,n){let t=a.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?t=a.Direction.DOWN:e===I.KeyCode.ARROW_UP?t=a.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(t=a.Direction.RIGHT),n?this._commandService.executeCommand(q.MoveSelectionOperation.id,{direction:t}):this._commandService.executeCommand(q.MoveCursorOperation.id,{direction:t})}_getEditorObject(){return sn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};yn=Nc([a.OnLifecycle(a.LifecycleStages.Steady,yn),He(0,a.IUniverInstanceService),He(1,b.IRenderManagerService),He(2,a.ICommandService),He(3,be),He(4,a.IContextService),He(5,zt),He(6,N.Inject(ne.LexerTreeBuilder)),He(7,a.IUndoRedoService),He(8,N.Inject(g.SheetInterceptorService)),He(9,N.Inject(g.SelectionManagerService))],yn);function Hc(i,e,n){i=a.Tools.deepClone(i);const{documentModel:t}=e;if(t==null)return null;const o=t.getSnapshot(),{body:r}=o;if(r==null)return null;const s=r.dataStream;let c=s.substring(s.length-2,s.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?s.substring(0,s.length-2):s;if(a.isFormulaString(c)){if(i.f===c)return null;const d=n.checkIfAddBracket(c);for(let u=0;u<d;u++)c+=ne.matchToken.CLOSE_BRACKET;i.f=c,i.v=null,i.p=null}else if(Pc(r))r.dataStream===`\r
19
- `?(i.v="",i.f=null,i.si=null,i.p=null):(i.p=o,i.v=null,i.f=null,i.si=null);else{if((c===i.v||c===""&&i.v==null)&&i.p==null)return null;i.v=c,i.f=null,i.si=null,i.p=null}return i}var Lc=Object.defineProperty,Uc=Object.getOwnPropertyDescriptor,kc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Uc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Lc(e,n,o),o},Le=(i,e)=>(n,t)=>e(n,t,i);let On=class extends a.RxDisposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_loadedMap",new Set);this._univerInstanceService=e,this._renderManagerService=n,this._editorBridgeService=t,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=l,this._formulaEditorManagerService=c,this._undoRedoService=d,this._textSelectionManagerService=u,this._initialize()}_initialize(){this._syncFormulaEditorContent(),this._commandExecutedListener(),this._syncEditorSize(),this._listenFxBtnClick(),this._listenFoldBtnClick(),this._renderManagerService.currentRender$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._loadedMap.has(e)||(this._initialMain(e),this._loadedMap.add(e)))}),this._textSelectionManagerService.textSelection$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{unitId:n}=e;n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(P.takeUntil(this.dispose$)).subscribe(()=>{var n;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(a.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0);const t=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown});const r=(n=t==null?void 0:t.getBody())==null?void 0:n.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const l=[{startOffset:s.length,endOffset:s.length}],c={unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(q.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(l)}})}_listenFoldBtnClick(){this._formulaEditorManagerService.foldBtnStatus$.pipe(P.takeUntil(this.dispose$)).subscribe(()=>{this._textSelectionManagerService.refreshSelection()})}_initialMain(e){const n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:t}=n;t!=null&&this.disposeWithMe(a.toDisposable(t.onPointerDownObserver.add(()=>{this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown})})))}_syncEditorSize(){this._formulaEditorManagerService.position$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const n=sn(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),t=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(n==null||t==null)return;const{width:o,height:r}=e,{engine:s}=n;t.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.currentEditCellState$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(e)}),this._editorBridgeService.visible$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null||e.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const n=this._editorBridgeService.getLatestEditCellState();n!=null&&this._editorSyncHandler(n)})}_editorSyncHandler(e){var s;const n=(s=e.documentLayoutObject.documentModel)==null?void 0:s.getBody();let t=n==null?void 0:n.dataStream,o=n==null?void 0:n.paragraphs,r=[];t==null||o==null||(e.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===b.DeviceInputEventType.Dblclick?(t=`\r
20
- `,o=[{startIndex:0}]):e.isInArrayFormulaRange===!0&&(r=(n==null?void 0:n.textRuns)||[]),this._syncContentAndRender(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,t,o,r),this._autoScroll())}_commandExecutedListener(){const e=[q.RichTextEditingMutation.id,_n.id],n=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s;if(e.includes(o.id)){const l=o.params,{unitId:c}=l;if(n.includes(c)){const d=this._univerInstanceService.getUniverDocInstance(c),u=(r=d==null?void 0:d.getBody())==null?void 0:r.dataStream,h=(s=d==null?void 0:d.getBody())==null?void 0:s.paragraphs,m=c===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(u==null||h==null)return;this._syncContentAndRender(m,u,h),this._autoScroll()}}}));const t=[g.SetRangeValuesMutation.id,g.MoveRangeMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s,l,c,d;if(t.includes(o.id)){const u=this._editorBridgeService.getLatestEditCellState();if(u==null)return;let h=!1;const{row:m,column:S}=u;if(o.id===g.SetRangeValuesMutation.id&&o.params?(s=(r=o.params.cellValue)==null?void 0:r[m])!=null&&s[S]&&(h=!0):o.id===g.MoveRangeMutation.id&&o.params&&(c=(l=o.params.to.value)==null?void 0:l[m])!=null&&c[S]&&(h=!0),h){const _=(d=u.documentLayoutObject.documentModel)==null?void 0:d.getBody();if(_==null)return;const{dataStream:f,paragraphs:v=[]}=_;this._syncContentAndRender(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,f,v),this._autoScroll()}}}))}_syncContentAndRender(e,n,t,o=[]){var h;const r=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(e),l=this._univerInstanceService.getUniverDocInstance(e),c=this._docViewModelManagerService.getViewModel(e);if(l==null||c==null||s==null)return;l.getBody().dataStream=n,l.getBody().paragraphs=this._clearParagraph(t),e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(l.getBody().textRuns=[]),o.length>0&&(l.getBody().textRuns=o),c.reset(l);const{skeleton:d}=s,u=this._renderManagerService.getRenderById(e);u!=null&&(d.calculate(),r.includes(e)&&((h=u.mainComponent)==null||h.makeDirty()))}_clearParagraph(e){const n=a.Tools.deepClone(e);for(const t of n)t.paragraphStyle&&(t.paragraphStyle.horizontalAlign=a.HorizontalAlign.UNSPECIFIED);return n}_autoScroll(){var _,f;const e=(_=this._docSkeletonManagerService.getSkeletonByUnitId(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:_.skeleton,n=this._formulaEditorManagerService.getPosition(),t=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||n==null||t==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:l,mainComponent:c}=t;let{actualHeight:d}=e.getActualSize();d+=r+s;const{width:u,height:h}=n,m=l.getViewport(q.VIEWPORT_KEY.VIEW_MAIN);let S=m==null?void 0:m.getScrollBar();l.transformByState({width:u,height:d}),c==null||c.resize(u,d),d>h?S==null?m&&new b.ScrollBar(m,{enableHorizontal:!1,barSize:8}):m==null||m.resetSizeAndScrollBar():(S=null,m==null||m.scrollTo({x:0,y:0}),(f=m==null?void 0:m.getScrollBar())==null||f.dispose())}};On=kc([a.OnLifecycle(a.LifecycleStages.Steady,On),Le(0,a.IUniverInstanceService),Le(1,b.IRenderManagerService),Le(2,be),Le(3,N.Inject(q.DocSkeletonManagerService)),Le(4,N.Inject(q.DocViewModelManagerService)),Le(5,a.ICommandService),Le(6,a.IContextService),Le(7,Mn),Le(8,a.IUndoRedoService),Le(9,N.Inject(q.TextSelectionManagerService))],On);var Vc=Object.defineProperty,Bc=Object.getOwnPropertyDescriptor,Fc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Bc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Vc(e,n,o),o},Wc=(i,e)=>(n,t)=>e(n,t,i);let xn=class extends a.Disposable{constructor(i){super(),this._currentUniverService=i,setTimeout(()=>{this._initialize()},0)}_initialize(){this._currentUniverService.createDoc({id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}});const i={id:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{pageSize:{width:1/0,height:1/0},marginTop:5,marginBottom:5,marginRight:0,marginLeft:0,paragraphLineGapDefault:0,renderConfig:{horizontalAlign:a.HorizontalAlign.UNSPECIFIED,verticalAlign:a.VerticalAlign.UNSPECIFIED,centerAngle:0,vertexAngle:0,wrapStrategy:a.WrapStrategy.WRAP}}};this._currentUniverService.createDoc(i)}};xn=Fc([a.OnLifecycle(a.LifecycleStages.Rendered,xn),Wc(0,a.IUniverInstanceService)],xn);const yr={sheetFooterBarHeight:"36",sheetContainer:"univer-sheet-container"};var jc=Object.defineProperty,zc=Object.getOwnPropertyDescriptor,Xc=(i,e,n,t)=>{for(var o=t>1?void 0:t?zc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&jc(e,n,o),o},xe=(i,e)=>(n,t)=>e(n,t,i);const Or=-1e3,xr=5,Yc=2;let An=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u,h){super();C(this,"_onInputSubscription");C(this,"_onInputActivateSubscription");C(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=e,this._docViewModelManagerService=n,this._contextService=t,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=l,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._initialize(),this._commandExecutedListener()}dispose(){var e,n;(e=this._onInputSubscription)==null||e.unsubscribe(),(n=this._onInputActivateSubscription)==null||n.unsubscribe()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const e=this._getEditorObject();e!=null&&this.disposeWithMe(a.toDisposable(e.document.onPointerDownObserver.add(()=>{var n;if(this._editorBridgeService.isVisible()){const t=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(t==null||o==null)return;const r=(n=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:n.skeleton;if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u}=t;this._fitTextSize(s,c,r,l,d,u)}})))}_initialCursorSync(){this._cellEditorManagerService.focus$.subscribe(()=>{this._textSelectionRenderManager.sync()})}_initialEditFocusListener(){this._onInputSubscription=this._editorBridgeService.currentEditCellState$.subscribe(e=>{if(e==null||this._editorBridgeService.isForceKeepVisible())return;const{position:n,documentLayoutObject:t,scaleX:o,editorUnitId:r}=e;if(this._getEditorObject()==null)return;const{startX:l,endX:c}=n,{textRotation:d,wrapStrategy:u,documentModel:h}=t,{a:m}=d;h.updateDocumentId(r),u===a.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-l)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(Or,Or)})}_fitTextSize(e,n,t,o,r=1,s=1){const{startX:l,startY:c,endX:d,endY:u}=e,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:S}=this._predictingSize(e,n,t,o,r,s),{verticalAlign:_,paddingData:f,fill:v}=o;let M=d-l,R=u-c;if(M<m&&(M=m),R<S)R=S,h.updateDocumentDataMargin(f);else{let T=f.t||0;_===a.VerticalAlign.MIDDLE?T=(R-S)/2:_===a.VerticalAlign.BOTTOM&&(T=R-S),T/=s,T=T<(f.t||0)?f.t||0:T,h.updateDocumentDataMargin({t:T})}t.calculate(),this._editAreaProcessing(M,R,e,n,v,r,s)}_predictingSize(e,n,t,o,r=1,s=1){const{startX:l,endX:c}=e,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,S=document.body.clientWidth;if(u===a.WrapStrategy.WRAP&&m===0){const{actualWidth:v,actualHeight:M}=t.getActualSize();return{actualWidth:v*r,actualHeight:M*s}}h==null||h.updateDocumentDataPageSize((S-l-n.left)/r),t.calculate();const _=t.getActualSize();let f=c-l;return f<_.actualWidth*r+xr*r&&(f=_.actualWidth*r+xr*r),h==null||h.updateDocumentDataPageSize(f/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED}),{actualWidth:f,actualHeight:_.actualHeight*s}}_editAreaProcessing(e,n,t,o,r,s=1,l=1){var E;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=t;const{document:h,scene:m,engine:S}=c,_=m.getViewport(q.VIEWPORT_KEY.VIEW_MAIN),f=document.body.clientHeight-u-parseFloat(yr.sheetFooterBarHeight)-o.top-Yc*2,v=document.body.clientWidth-d-o.left;let M=n,R=_==null?void 0:_.getScrollBar();M>f?(M=f,R==null?_&&new b.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetSizeAndScrollBar()):(R=null,(E=_==null?void 0:_.getScrollBar())==null||E.dispose()),e+=(R==null?void 0:R.barSize)||0,e>v&&(e=v),d-=b.FIX_ONE_PIXEL_BLUR_OFFSET,u-=b.FIX_ONE_PIXEL_BLUR_OFFSET,this._addBackground(m,e/s,n/l,r);const{scaleX:T,scaleY:w}=m.getPrecisionScale();m.transformByState({width:e/s,height:n/l,scaleX:s,scaleY:l}),h.resize(e/s,n/l),requestIdleCallback(()=>{S.resizeBySize(b.fixLineWidthByScale(e,T),b.fixLineWidthByScale(M,w))}),this._cellEditorManagerService.setState({startX:d,startY:u,endX:e+d,endY:M+u,show:!0})}_addBackground(e,n,t,o){const r="_backgroundRectHelperColor_",s=e.getObject(r);s==null&&o==null||(s==null?e.addObjects([new b.Rect(r,{width:n,height:t,fill:o,evented:!1})],q.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:n,height:t})))}_initialStartEdit(){this._onInputActivateSubscription=this._editorBridgeService.visible$.subscribe(e=>{var w,E,y;const{visible:n,eventType:t,keycode:o}=e;if(n===this._editorVisiblePrevious||(this._editorVisiblePrevious=n,n===!1))return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:S=!1}=r,_=this._getEditorObject();if(_==null)return;const{document:f,scene:v}=_;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const{documentModel:M}=l,R=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(R==null||M==null)return;const{skeleton:T}=R;if(this._fitTextSize(s,c,T,l,d,u),t===b.DeviceInputEventType.Keyboard||t===b.DeviceInputEventType.Dblclick&&S){const x=a.Tools.deepClone(M.snapshot),O=(w=this._docViewModelManagerService.getCurrent())==null?void 0:w.docViewModel;this._resetBodyStyle(x.body),M.reset(x),O.reset(M),f.makeDirty(),(o===I.KeyCode.BACKSPACE||t===b.DeviceInputEventType.Dblclick)&&(T.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(t===b.DeviceInputEventType.Dblclick){const x=M.getBody().dataStream.length-2||0;(E=v.getViewport(q.VIEWPORT_KEY.VIEW_MAIN))==null||E.scrollTo({y:1/0}),this._textSelectionManagerService.replaceTextRanges([{startOffset:x,endOffset:x}])}(y=this._renderManagerService.getRenderById(m))==null||y.scene.resetCursor()})}_resetBodyStyle(e){e.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,e.textRuns!=null&&(e.textRuns.length===1?(e.textRuns[0].st=0,e.textRuns[0].ed=1):e.textRuns=void 0),e.paragraphs!=null&&(e.paragraphs.length===1?e.paragraphs[0].startIndex=0:e.paragraphs=[{startIndex:0}]),e.sectionBreaks!=null&&(e.sectionBreaks=void 0),e.tables!=null&&(e.tables=void 0),e.customRanges!=null&&(e.customRanges=void 0),e.customBlocks!=null&&(e.customBlocks=void 0)}_initialKeyboardListener(){this._textSelectionRenderManager.onInputBefore$.subscribe(e=>{const n=this._contextService.getContextValue(a.FOCUSING_FORMULA_EDITOR);this._contextService.getContextValue(a.FOCUSING_SHEET)&&!n&&this._showEditorByKeyboard(e)})}_showEditorByKeyboard(e){if(e==null)return;const n=e.event;this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:n.which})}_commandExecutedListener(){const e=[q.RichTextEditingMutation.id,_n.id],n=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var o;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,l=this._editorBridgeService.getCurrentEditorId();if(l==null)return;this._editorBridgeService.changeEditorDirty(!0);const c=(o=this._docSkeletonManagerService.getSkeletonByUnitId(l))==null?void 0:o.skeleton;if(c==null||!n.includes(s))return;const d=this._editorBridgeService.getEditCellState();if(d==null)return;const{position:u,documentLayoutObject:h,canvasOffset:m,scaleX:S,scaleY:_}=d;this._fitTextSize(u,m,c,h,S,_)}}))}_getEditorObject(){return sn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};An=Xc([a.OnLifecycle(a.LifecycleStages.Steady,An),xe(0,N.Inject(q.DocSkeletonManagerService)),xe(1,N.Inject(q.DocViewModelManagerService)),xe(2,a.IContextService),xe(3,a.IUniverInstanceService),xe(4,b.IRenderManagerService),xe(5,be),xe(6,zt),xe(7,b.ITextSelectionRenderManager),xe(8,N.Inject(q.TextSelectionManagerService)),xe(9,a.ICommandService),xe(10,N.Inject(a.LocaleService))],An);const Dn={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{delta:n,reset:t}=e,o=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();let c=t?100:Math.round((r.getConfig().zoomRatio+n)*100);c=Math.max(si[0],c),c=Math.min(si[1],c);const d=c/100;return i.get(a.ICommandService).executeCommand(Be.id,{unitId:s,subUnitId:l,zoomRatio:d})}},Nn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{unitId:n,subUnitId:t,zoomRatio:o}=e;return i.get(a.ICommandService).executeCommand(Be.id,{unitId:n,subUnitId:t,zoomRatio:o})}},Ar={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(i,e)=>(i.get(be).setEditCell(e),!0)};var $c=Object.defineProperty,Zc=Object.getOwnPropertyDescriptor,Gc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Zc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&$c(e,n,o),o},Ct=(i,e)=>(n,t)=>e(n,t,i);let Pn=class extends a.RxDisposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._editorBridgeService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener()}_initSelectionChangeListener(){P.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(P.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null||i==null||i.length===0||i[i.length-1]==null)return;const{primary:t}=i[i.length-1];if(t==null)return;const o=this._getSheetObject();if(o==null)return;const{unitId:r,sheetId:s}=n,{scene:l,engine:c}=o;this._commandService.executeCommand(Ar.id,{scene:l,engine:c,primary:t,unitId:r,sheetId:s})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:e,spreadsheetColumnHeader:n,spreadsheetLeftTopPlaceholder:t,spreadsheetRowHeader:o}=i;e.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Dblclick})}),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),o.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this))}_keepVisibleHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&(this._selectionManagerService.makeDirty(!1),this._commandService.executeCommand(Pe.id,{visible:!1,eventType:b.DeviceInputEventType.PointerDown}),setTimeout(()=>{this._selectionManagerService.makeDirty(!0)},0))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_commandExecutedListener(){const i=g.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{n!=null&&n.fromCollab||(e.id===g.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(e.id)&&this._hideEditor())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===Nn.id&&this._editorBridgeService.refreshEditCellState()}))}};Pn=Gc([a.OnLifecycle(a.LifecycleStages.Rendered,Pn),Ct(0,N.Inject(A.SheetSkeletonManagerService)),Ct(1,a.IUniverInstanceService),Ct(2,a.ICommandService),Ct(3,b.IRenderManagerService),Ct(4,be),Ct(5,N.Inject(g.SelectionManagerService))],Pn);var Kc=Object.defineProperty,Jc=Object.getOwnPropertyDescriptor,Qc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Jc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Kc(e,n,o),o},$t=(i,e)=>(n,t)=>e(n,t,i);let Hn=class extends a.Disposable{constructor(i,e,n,t,o){super(),this._commandService=i,this._formatPainterService=e,this._currentUniverService=n,this._renderManagerService=t,this._selectionRenderService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:e}=this._getSheetObject()||{};e&&(i!==ye.OFF?e.setDefaultCursor(b.CURSOR_TYPE.CELL):e.setDefaultCursor(b.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(a.toDisposable(this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{if(this._formatPainterService.getStatus()!==ye.OFF){const{rangeWithCoord:e}=i[i.length-1];this._applyFormatPainter({startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}),this._formatPainterService.getStatus()===ye.ONCE&&this._commandService.executeCommand(Ti.id)}})))}async _applyFormatPainter(i){const{styles:e,merges:n}=this._formatPainterService.getSelectionFormat(),t=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!e)return;const{startRow:r,startColumn:s,endRow:l,endColumn:c}=e.getDataRange(),d=l-r+1,u=c-s+1,h=Array.from({length:i.endRow-i.startRow+1},()=>Array.from({length:i.endColumn-i.startColumn+1},()=>({}))),m=[];h.forEach((_,f)=>{_.forEach((v,M)=>{const R=f%d+r,T=M%u+s,w=e.getValue(R,T);w&&(h[f][M].s=w)})}),n.forEach(_=>{const f={startRow:_.startRow-r,startColumn:_.startColumn-s,endRow:_.endRow-r,endColumn:_.endColumn-s},v=Math.max(1,Math.floor((i.endRow-i.startRow+1)/d)),M=Math.max(1,Math.floor((i.endColumn-i.startColumn+1)/u));for(let R=0;R<v;R++)for(let T=0;T<M;T++)m.push({startRow:f.startRow+R*d+i.startRow,startColumn:f.startColumn+T*u+i.startColumn,endRow:f.endRow+R*d+i.startRow,endColumn:f.endColumn+T*u+i.startColumn})});const S={subUnitId:o,unitId:t,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(hr.id,S)}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Hn=Qc([a.OnLifecycle(a.LifecycleStages.Rendered,Hn),$t(0,a.ICommandService),$t(1,_t),$t(2,a.IUniverInstanceService),$t(3,b.IRenderManagerService),$t(4,_e)],Hn);const Ln={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(i,e={offsetX:0,offsetY:0})=>{const n=i.get(a.ICommandService),t=i.get(Je),r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:l,ySplit:c}=s.getConfig().freeze,d=t.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=e||{},{sheetViewStartRow:m=0,sheetViewStartColumn:S=0,offsetX:_=0,offsetY:f=0}=d||{};return n.executeCommand(mt.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:S+l,offsetX:_+u,offsetY:f+h})}},It={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=t.getActiveSheet(),s=i.get(Je).getCurrentScroll();if(!o)return!1;const l=i.get(a.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=e,{sheetViewStartColumn:m,sheetViewStartRow:S,offsetX:_,offsetY:f}=s||{},{xSplit:v,ySplit:M}=o.getConfig().freeze;return l.executeCommand(mt.id,{unitId:t.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c!=null?c:(S!=null?S:0)+M,sheetViewStartColumn:d!=null?d:(m!=null?m:0)+v,offsetX:u!=null?u:_,offsetY:h!=null?h:f})}};a.CommandType.COMMAND;var qc=Object.defineProperty,ed=Object.getOwnPropertyDescriptor,td=(i,e,n,t)=>{for(var o=t>1?void 0:t?ed(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&qc(e,n,o),o},Ue=(i,e)=>(n,t)=>e(n,t,i);const nd="__SpreadsheetFreezeRowMainName__",id="__SpreadsheetFreezeRowHeaderName__",od="__SpreadsheetFreezeColumnMainName__",rd="__SpreadsheetFreezeColumnHeaderName__",Di=4,sd=.01;let Un=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_rowFreezeHeaderRect");C(this,"_rowFreezeMainRect");C(this,"_columnFreezeHeaderRect");C(this,"_columnFreezeMainRect");C(this,"_freezeDownObservers",[]);C(this,"_freezeMoveObservers",[]);C(this,"_freezeLeaveObservers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_changeToRow",-1);C(this,"_changeToColumn",-1);C(this,"_changeToOffsetX",0);C(this,"_changeToOffsetY",0);C(this,"_activeViewport",null);C(this,"_freezeNormalHeaderColor","");C(this,"_freezeNormalMainColor","");C(this,"_freezeActiveColor","");C(this,"_freezeHoverColor","");C(this,"_lastFreeze");this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=l,this._themeService=c,this._sheetInterceptorService=d,this._injector=u,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,n){var x;const t=n!=null?n:this._getFreeze();if(t==null)return;const o=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(o==null)return;const{startRow:r,startColumn:s}=t,l=this._getPositionByIndex(r,s);if(l==null)return;const c=this._getSheetObject();if(c==null)return;const d=c.engine,u=(d==null?void 0:d.width)||0,h=(d==null?void 0:d.height)||0,m=c.scene,{startX:S,startY:_}=l,{rowTotalHeight:f,columnTotalWidth:v,rowHeaderWidthAndMarginLeft:M,columnHeaderHeightAndMarginTop:R}=o,T=u>v+M?u:v+R,w=h>f+R?h:f+R;this._changeToRow=r,this._changeToColumn=s,this._changeToOffsetX=S,this._changeToOffsetY=_;const E=Math.max(m.scaleX,m.scaleY),y=Di/(E<1?1:E);if(e===0){const O=y;this._rowFreezeHeaderRect=new b.Rect(id,{fill:this._freezeNormalHeaderColor,width:M,height:y,left:0,top:_-O,zIndex:3});let D=this._freezeNormalHeaderColor;(r===-1||r===0)&&(D=this._freezeNormalMainColor),this._rowFreezeMainRect=new b.Rect(nd,{fill:D,width:T*2,height:y,left:M,top:_-O,zIndex:3}),m.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],Ze)}else{const O=y;this._columnFreezeHeaderRect=new b.Rect(rd,{fill:this._freezeNormalHeaderColor,width:y,height:R,left:S-O,top:0,zIndex:3});let D=this._freezeNormalHeaderColor;(s===-1||s===0)&&(D=this._freezeNormalMainColor),this._columnFreezeMainRect=new b.Rect(od,{fill:D,width:y,height:w*2,left:S-O,top:R,zIndex:3}),m.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],Ze)}this._eventBinding(e)}_eventBinding(e=0){let n=this._rowFreezeHeaderRect,t=this._rowFreezeMainRect;e===1&&(n=this._columnFreezeHeaderRect,t=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{n==null||n.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(t==null?void 0:t.onPointerEnterObserver.add(()=>{n==null||n.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{n==null||n.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(t==null?void 0:t.onPointerLeaveObserver.add(()=>{n==null||n.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,n,t,e)})),this._freezeDownObservers.push(t==null?void 0:t.onPointerDownObserver.add(s=>{this._freezeDown(s,n,t,e)}))}_getCurrentLastVisibleRow(){var h,m,S,_;const e=this._getSheetObject();if(e==null)return;const n=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(n==null)return;const t=e.scene,o=Math.max(t.scaleX,t.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(e.engine.height-n.columnHeaderHeight)/o,l=(m=r==null?void 0:r.sheetViewStartRow)!=null?m:0,c=l===0?-((S=r==null?void 0:r.offsetY)!=null?S:0):n.rowHeightAccumulation[l-1]-((_=r==null?void 0:r.offsetY)!=null?_:0);let d=0,u=!1;for(let f=l,v=n.rowHeightAccumulation.length;f<v;f++)if(n.rowHeightAccumulation[f]-c>s){d=f,u=!0;break}return u||(d=n.rowHeightAccumulation.length-1),d}_getActiveViewport(e){var t;const n=(t=this._getSheetObject())==null?void 0:t.scene.getViewports();return n&&n.find(o=>o.isHit(new b.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,n,t,o=0){var h;const r=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(r==null)return;const s=this._getSheetObject();if(s==null)return;const{scene:l}=s;l.setCursor(b.CURSOR_TYPE.GRABBING),l.disableEvent();const c=this._getCurrentLastVisibleRow(),d=c===void 0?Number.POSITIVE_INFINITY:r.rowHeightAccumulation[c];this._activeViewport=null;const u=this._getFreeze();u&&(this._changeToColumn=u.startColumn,this._changeToRow=u.startRow),this._moveObserver=l.onPointerMoveObserver.add(m=>{var T,w,E,y;const S=this._getActiveViewport(m),{startX:_,startY:f,row:v,column:M}=vt(m.offsetX,m.offsetY,l,r,S||void 0);l.setCursor(b.CURSOR_TYPE.GRABBING);const R=Di/Math.max(l.scaleX,l.scaleY);o===0?((T=n.transformByState({top:Math.min(f,d)-R/2}))==null||T.setProps({fill:this._freezeActiveColor}),(w=t.transformByState({top:Math.min(f,d)-R/2}))==null||w.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=c===void 0?v:Math.min(v,c),this._changeToOffsetY=Math.min(f,d),this._activeViewport=S):((E=n.transformByState({left:_-R/2}))==null||E.setProps({fill:this._freezeActiveColor}),(y=t.transformByState({left:_-R/2}))==null||y.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=M,this._changeToOffsetX=_,this._activeViewport=S)}),this._upObserver=l.onPointerUpObserver.add(()=>{var O,D;l.resetCursor(),l.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:S}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(n.setProps({fill:this._freezeNormalHeaderColor}),t.setProps({fill:this._freezeNormalMainColor})):(n==null||n.setProps({fill:this._freezeNormalHeaderColor}),t==null||t.setProps({fill:this._freezeNormalHeaderColor}));const _=Di/Math.max(l.scaleX,l.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(n.transformByState({top:S-_}),t.transformByState({top:S-_})):(this._changeToColumn===0||this._changeToColumn===-1)&&(n.transformByState({left:m-_}),t.transformByState({left:m-_}));const f=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:v,sheetViewStartColumn:M}=f;if(M==null||v==null)return;const R=this._currentUniverService.getCurrentUniverSheetInstance(),T=R.getActiveSheet(),w=(O=T.getConfig())==null?void 0:O.freeze;let E=(w==null?void 0:w.xSplit)||0,y=(w==null?void 0:w.ySplit)||0;const x=(D=this._activeViewport)==null?void 0:D.viewPortKey;o===0&&(!x||x===V.VIEW_LEFT_TOP||x===V.VIEW_MAIN_LEFT_TOP||x===V.VIEW_MAIN_TOP||x===V.VIEW_ROW_TOP?y=this._changeToRow-(w.startRow-w.ySplit):y=this._changeToRow-v,y=y<0?0:y),o===1&&(!x||x===V.VIEW_LEFT_TOP||x===V.VIEW_MAIN_LEFT_TOP||x===V.VIEW_MAIN_LEFT||x===V.VIEW_COLUMN_LEFT?E=this._changeToColumn-(w.startColumn-w.xSplit):E=this._changeToColumn-M,E=E<0?0:E),this._commandService.executeCommand(g.SetFrozenCommand.id,{startRow:y===0?-1:this._changeToRow,startColumn:E===0?-1:this._changeToColumn,ySplit:y,xSplit:E,unitId:R.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e,t=n.getViewport(V.VIEW_COLUMN_LEFT),o=n.getViewport(V.VIEW_COLUMN_RIGHT),r=n.getViewport(V.VIEW_ROW_TOP),s=n.getViewport(V.VIEW_ROW_BOTTOM),l=n.getViewport(V.VIEW_LEFT_TOP),c=n.getViewport(V.VIEW_MAIN),d=n.getViewport(V.VIEW_MAIN_LEFT_TOP),u=n.getViewport(V.VIEW_MAIN_LEFT),h=n.getViewport(V.VIEW_MAIN_TOP);if(!(t==null||o==null||r==null||s==null||l==null||c==null||d==null||u==null||h==null))return{viewMain:c,viewMainLeftTop:d,viewMainLeft:u,viewMainTop:h,viewColumnLeft:t,viewColumnRight:o,viewRowTop:r,viewRowBottom:s,viewLeftTop:l}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewMain:n,viewRowBottom:t,viewColumnRight:o,viewMainLeft:r,viewMainTop:s}=e;this.disposeWithMe(n.onScrollAfterObserver.add(l=>{const{scrollX:c,scrollY:d,actualScrollX:u,actualScrollY:h}=l;t.isActive&&t.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),o.isActive&&o.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0),r.isActive&&r.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),s.isActive&&s.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0)}))}_updateViewport(e=-1,n=-1,t=0,o=0,r=3){var x;const s=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(s==null)return;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=s,d=this._getViewports();if(!d)return;const{viewMain:u,viewMainLeftTop:h,viewMainLeft:m,viewMainTop:S,viewColumnLeft:_,viewColumnRight:f,viewRowTop:v,viewRowBottom:M,viewLeftTop:R}=d;f.resize({left:l,top:0,height:c,right:0}),M.resize({left:0,top:c,bottom:0,width:l}),R.resize({left:0,top:0,width:l,height:c});let T=!0,w=!0;h.enable(),(e===-1||e===0)&&(T=!1),(n===-1||n===0)&&(w=!1);const E=s.getNoMergeCellPositionByIndexWithNoHeader(e-t,n-o),y=s.getNoMergeCellPositionByIndexWithNoHeader(e,n);if(h.disable(),S.disable(),m.disable(),v.disable(),_.disable(),h.resetPadding(),S.resetPadding(),m.resetPadding(),v.resetPadding(),_.resetPadding(),T===!1&&w===!1)u.resize({left:l,top:c,bottom:0,right:0}),u.resetPadding();else if(T===!0&&w===!1){const O=y.startY-E.startY;u.resize({left:l,top:c+O,bottom:0,right:0}),u.setPadding({startY:E.startY,endY:y.startY,startX:0,endX:0}),r&2&&this._commandService.executeCommand(It.id,{sheetViewStartRow:0,offsetY:0}),S.resize({left:l,top:c,height:O,right:0}),S.updateScroll({actualScrollY:E.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),v.resize({left:0,top:c,width:l,height:O}),v.updateScroll({actualScrollY:E.startY}).makeDirty(!0),M.resize({left:0,top:c+O,bottom:0,width:l}),S.enable(),v.enable()}else if(T===!1&&w===!0){const O=y.startX-E.startX;u.resize({left:l+O,top:c,bottom:0,right:0}),u.setPadding({startX:E.startX,endX:y.startX,startY:0,endY:0}),r&1&&this._commandService.executeCommand(It.id,{sheetViewStartColumn:0,offsetX:0}),m.resize({left:l,top:c,width:O,bottom:0,right:0}),m.updateScroll({actualScrollX:E.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),_.resize({left:l,top:0,width:O,height:c}),_.updateScroll({actualScrollX:E.startX}).makeDirty(!0),f.resize({left:l+O,top:0,height:c,right:0}),m.enable(),_.enable()}else{const O=y.startX-E.startX,D=y.startY-E.startY;u.resize({left:l+O,top:c+D,bottom:0,right:0}),u.setPadding({startY:E.startY,endY:y.startY,startX:E.startX,endX:y.startX}),r&&this._commandService.executeCommand(It.id,{...r&1?{sheetViewStartColumn:0,offsetX:0}:null,...r&2?{sheetViewStartRow:0,offsetY:0}:null}),m.resize({left:l,top:c+D,width:O,bottom:0}),m.updateScroll({actualScrollX:E.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),S.resize({left:l+O,top:c,height:D,right:0}),S.updateScroll({actualScrollY:E.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),h.resize({left:l,top:c,width:O,height:D}),h.updateScroll({actualScrollX:E.startX,actualScrollY:E.startY}).makeDirty(!0),v.resize({left:0,top:c,width:l,height:D}),v.updateScroll({actualScrollY:E.startY}).makeDirty(!0),M.resize({left:0,top:c+D,bottom:0,width:l}),_.resize({left:l,top:0,width:O,height:c}),_.updateScroll({actualScrollX:E.startX}).makeDirty(!0),f.resize({left:l+O,top:0,height:c,right:0}),h.enable(),S.enable(),m.enable(),v.enable(),_.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[g.SetWorksheetActiveOperation.id,g.InsertRangeMoveDownCommand.id,g.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:l=0}=t;this._refreshFreeze(o,r,s,l,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()})))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(sd).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const n={redos:[],undos:[]},t=this._getFreeze();if(!t)return n;const o=r=>{const s=this._currentUniverService.getCurrentUniverSheetInstance(),l=s.getUnitId(),d=s.getActiveSheet().getSheetId();this._refreshFreeze(r.startRow,r.startColumn,r.ySplit,r.xSplit,0);const u={...r,unitId:l,subUnitId:d,resetScroll:!1},h=g.SetFrozenMutationFactory(this._injector,u);return{undos:[{id:g.SetFrozenMutation.id,params:h}],redos:[{id:g.SetFrozenMutation.id,params:u}]}};if(e.id===g.MoveColsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startColumn:s},toRange:{startColumn:l}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===a.RANGE_TYPE.COLUMN&&v.range.startColumn<=s&&s<=v.range.endColumn);if(!(c!=null&&c.length))return n;const d=c[0].range,u={...d,startColumn:l,endColumn:l+d.endColumn-d.startColumn};if(!t||t.startColumn<=0||d.startColumn>=t.startColumn&&u.startColumn>=t.startColumn||d.startColumn===u.startColumn||d.endColumn<t.startColumn&&u.startColumn<t.startColumn)return n;const h=d.endColumn-d.startColumn+1,m=Math.max(Math.min(t.startColumn,d.endColumn+1)-d.startColumn,0);let S,_;u.startColumn>=t.startColumn?(S=Math.max(t.startColumn-m,1),_=Math.max(t.xSplit-m,1)):(S=t.startColumn+h-m,_=t.xSplit+h-m);const f={...t,startColumn:S,xSplit:_};return o(f)}if(e.id===g.MoveRowsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startRow:s},toRange:{startRow:l}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===a.RANGE_TYPE.ROW&&v.range.startRow<=s&&s<=v.range.endRow);if(!(c!=null&&c.length))return n;const d=c[0].range,u={...d,startRow:l,endRow:l+d.endRow-d.startRow};if(!t||t.startRow<=0||d.startRow>=t.startRow&&u.startRow>=t.startRow||d.startRow===u.startRow||d.endRow<t.startRow&&u.startRow<t.startRow)return n;const h=d.endRow-d.startRow+1,m=Math.max(Math.min(t.startRow,d.endRow+1)-d.startRow,0);let S,_;u.startRow>=t.startRow?(S=Math.max(t.startRow-m,1),_=Math.max(t.ySplit-m,1)):(S=t.startRow+h-m,_=t.ySplit+h-m);const f={...t,startRow:S,ySplit:_};return o(f)}if(e.id===g.RemoveColCommand.id||e.id===g.RemoveRowCommand.id){const r=e.params,s=r.range;if(s.rangeType===a.RANGE_TYPE.COLUMN&&s.startColumn<t.startColumn){const l=Math.min(t.startColumn,s.endColumn+1)-s.startColumn,c={...t,startColumn:Math.max(1,t.startColumn-l),xSplit:Math.max(1,t.xSplit-l)};return o(c)}if(r.range.rangeType===a.RANGE_TYPE.ROW&&s.startRow<t.startRow){const l=Math.min(t.startRow,s.endRow+1)-s.startRow,c={...t,startRow:Math.max(1,t.startRow-l),ySplit:Math.max(1,t.ySplit-l)};return o(c)}}return n}}))}_commandExecutedListener(){const e=[g.SetFrozenMutation.id,Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){const t=this._lastFreeze,o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=n.params,{unitId:l,subUnitId:c}=s;if(!(l===o.getUnitId()&&c===r.getSheetId()))return;const d=r.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:m=-1,ySplit:S=0,xSplit:_=0}=d;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==m||t.xSplit!==_)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,m,S,_,u)}else if(n.id===g.SetWorksheetRowHeightMutation.id){const t=this._getFreeze();n.params&&t&&n.params.ranges.some(o=>o.startRow<t.startRow)&&this._refreshCurrent()}else if(n.id===g.SetWorksheetColWidthMutation.id){const t=this._getFreeze();n.params&&t&&n.params.ranges.some(o=>o.startColumn<t.startColumn)&&this._refreshCurrent()}else if(n.id===g.SetWorksheetRowAutoHeightMutation.id){const t=n.params,o=this._getFreeze();if(o&&o.startRow>-1&&t.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}else if(n.id===g.SetColHiddenMutation.id||n.id===g.SetColVisibleMutation.id){const t=n.params,o=this._getFreeze(),r=t.ranges;o&&o.startColumn>-1&&r.some(s=>s.startColumn<o.startColumn)&&this._refreshCurrent()}else if(n.id===g.SetRowHiddenMutation.id||n.id===g.SetRowVisibleMutation.id){const t=n.params,o=this._getFreeze(),r=t.ranges;o&&o.startRow>-1&&r.some(s=>s.startRow<o.startRow)&&this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onTransformChangeObservable.add(t=>{t.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onPointerMoveObserver.remove(this._moveObserver),n.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var t,o,r,s;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(o=this._rowFreezeMainRect)==null||o.dispose(),(r=this._columnFreezeHeaderRect)==null||r.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(l=>{n.onPointerDownObserver.remove(l),n.onPointerMoveObserver.remove(l),n.onPointerLeaveObserver.remove(l)}),n.onPointerEnterObserver.remove(this._moveObserver),n.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(e,n){var c;if(this._getSheetObject()==null)return;const o=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton,r=o==null?void 0:o.getNoMergeCellPositionByIndex(e,n);if(o==null)return;if(r!=null&&(!isNaN(r.endX)||!isNaN(r.endY)))return r;const{rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:l}=o;return{startX:s,endX:s,startY:l,endY:l}}_getFreeze(){var n;const e=(n=this._sheetSkeletonManagerService.getCurrent())==null?void 0:n.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_refreshFreeze(e,n,t,o,r){var l;const s={startRow:e,startColumn:n,ySplit:t,xSplit:o};this._clearFreeze(),this._createFreeze(0,s),this._createFreeze(1,s),this._updateViewport(e,n,t,o,r),(l=this._getSheetObject())==null||l.spreadsheet.makeForceDirty()}};Un=td([a.OnLifecycle(a.LifecycleStages.Rendered,Un),Ue(0,N.Inject(A.SheetSkeletonManagerService)),Ue(1,a.IUniverInstanceService),Ue(2,a.ICommandService),Ue(3,b.IRenderManagerService),Ue(4,_e),Ue(5,N.Inject(g.SelectionManagerService)),Ue(6,N.Inject(Je)),Ue(7,N.Inject(a.ThemeService)),Ue(8,N.Inject(g.SheetInterceptorService)),Ue(9,N.Inject(N.Injector))],Un);var Ni=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(Ni||{});const ad="rgba(0, 0, 0, 0.15)",We="rgb(0, 0, 0)",kn="rgb(255, 255, 255, 1)";class ld extends b.Shape{constructor(n,t){super(n,t);C(this,"_size",12);C(this,"_iconRatio",.4);C(this,"_mode",0);this.setShapeProps(t)}setShapeProps(n){n!=null&&n.size&&(this._size=n.size),n!=null&&n.mode&&(this._mode=n.mode),this.transformByState({width:this._size,height:this._size})}_draw(n){this._mode===1&&b.Rect.drawWith(n,{width:this._size,height:this._size,radius:this._size,fill:ad});const t=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=t*Math.sin(o),s=t*Math.cos(o);b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:-r+this._size/2,y:-s+this._size/2},{x:r+this._size/2,y:-s+this._size/2},{x:this._size/2,y:t+this._size/2}]],fill:We})}}var cd=Object.defineProperty,dd=Object.getOwnPropertyDescriptor,ud=(i,e,n,t)=>{for(var o=t>1?void 0:t?dd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&cd(e,n,o),o},Mt=(i,e)=>(n,t)=>e(n,t,i);const hd="__SpreadsheetHeaderMenuSHAPEControllerShape__",md="__SpreadsheetHeaderMenuMAINControllerShape__",Sd="rgba(0, 0, 0, 0.1)";let Vn=class extends a.Disposable{constructor(e,n,t,o,r,s){super();C(this,"_hoverRect");C(this,"_hoverMenu");C(this,"_currentColumn",1/0);C(this,"_observers",[]);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._renderManagerService=t,this._contextMenuService=o,this._commandService=r,this._selectionManagerService=s,this._initialize()}dispose(){var o,r;(o=this._hoverRect)==null||o.dispose(),(r=this._hoverMenu)==null||r.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t}=e;this._observers.forEach(s=>{n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s),t.onPointerEnterObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s)})}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;this._hoverRect=new b.Rect(hd,{fill:Sd,evented:!1}),this._hoverMenu=new ld(md,{zIndex:100,visible:!1}),n.addObjects([this._hoverRect,this._hoverMenu],Ze),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(e=0){const n=this._getSheetObject();if(n==null)return;const{spreadsheetColumnHeader:t,spreadsheetRowHeader:o}=n,r=e===0?o:t;this._observers.push(r==null?void 0:r.onPointerEnterObserver.add(()=>{var s;(s=this._hoverRect)==null||s.show()})),this._observers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var v,M,R;const l=(v=this._sheetSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(l==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=l,{startX:h,startY:m,endX:S,endY:_,column:f}=vt(s.offsetX,s.offsetY,c.scene,l);if(e===0)(M=this._hoverRect)==null||M.transformByState({width:d,height:_-m,left:0,top:m});else{if(this._currentColumn=f,(R=this._hoverRect)==null||R.transformByState({width:S-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(S-h<u*2){this._hoverMenu.hide();return}const T=u*.8;this._hoverMenu.transformByState({left:S-u,top:u/2-T/2}),this._hoverMenu.setShapeProps({size:T}),this._hoverMenu.show()}})),this._observers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._hoverRect)==null||s.hide(),(l=this._hoverMenu)==null||l.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ni.HIGHLIGHT,visible:!0}),e.scene.setCursor(b.CURSOR_TYPE.POINTER))}),this._hoverMenu.onPointerLeaveObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ni.NORMAL,visible:!1}),e.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(e=>{if(!this._getSheetObject())return;const t=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();if(!!!(o!=null&&o.filter(s=>s.rangeType===a.RANGE_TYPE.COLUMN).find(s=>{const{startColumn:l,endColumn:c}=s;return t>=l&&t<=c}))){const s=this._getSelectionOnColumn(t);this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,s)}e.stopPropagation(),e.preventDefault(),this._contextMenuService.triggerContextMenu(e,de.COL_HEADER_CONTEXT_MENU)}))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_getSelectionOnColumn(e){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet();return{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:{startRow:0,startColumn:e,endRow:t.getRowCount()-1,endColumn:e,rangeType:a.RANGE_TYPE.COLUMN},primary:{startRow:0,startColumn:e,endRow:0,endColumn:e,actualRow:0,actualColumn:e,isMerged:!1,isMergedMainCell:!1},style:null}]}}};Vn=ud([a.OnLifecycle(a.LifecycleStages.Rendered,Vn),Mt(0,N.Inject(A.SheetSkeletonManagerService)),Mt(1,a.IUniverInstanceService),Mt(2,b.IRenderManagerService),Mt(3,I.IContextMenuService),Mt(4,a.ICommandService),Mt(5,N.Inject(g.SelectionManagerService))],Vn);var _d=Object.defineProperty,gd=Object.getOwnPropertyDescriptor,fd=(i,e,n,t)=>{for(var o=t>1?void 0:t?gd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&_d(e,n,o),o},Rt=(i,e)=>(n,t)=>e(n,t,i);const pd="__SpreadsheetHeaderMoveControllerBackground__",vd="__SpreadsheetHeaderMoveControllerShapeLine__",Cd="rgba(0, 0, 0, 0.1)",Id="rgb(119, 119, 119)",Md=4;let Bn=class extends a.Disposable{constructor(e,n,t,o,r,s){super();C(this,"_startOffsetX",-1/0);C(this,"_startOffsetY",-1/0);C(this,"_moveHelperBackgroundShape");C(this,"_moveHelperLineShape");C(this,"_sheetObject");C(this,"_rowOrColumnDownObservers",[]);C(this,"_rowOrColumnMoveObservers",[]);C(this,"_rowOrColumnLeaveObservers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_scrollTimer");C(this,"_changeFromColumn",-1);C(this,"_changeFromRow",-1);C(this,"_changeToColumn",-1);C(this,"_changeToRow",-1);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._renderManagerService=t,this._commandService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._initialize()}dispose(){var r,s;(r=this._moveHelperBackgroundShape)==null||r.dispose(),(s=this._moveHelperLineShape)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t,scene:o}=e;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(l=>{n.onPointerDownObserver.remove(l),t.onPointerDownObserver.remove(l)}),o.onPointerMoveObserver.remove(this._moveObserver),o.onPointerUpObserver.remove(this._upObserver),this._scrollTimer.dispose()}_initialize(){const e=this._getSheetObject();e!=null&&(this._sheetObject=e,this._initialRowOrColumn(0),this._initialRowOrColumn(1))}_initialRowOrColumn(e=0){const{spreadsheetColumnHeader:n,spreadsheetRowHeader:t,scene:o}=this._sheetObject,r=e===0?t:n;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const l=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(l==null)return;const{row:c,column:d}=vt(s.offsetX,s.offsetY,o,l);if(this._checkInHeaderRange(e===0?c:d,e)===!1){o.resetCursor(),this._selectionRenderService.enableSelection();return}o.setCursor(b.CURSOR_TYPE.GRAB),this._selectionRenderService.disableSelection()})),this._rowOrColumnLeaveObservers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._moveHelperBackgroundShape)==null||s.hide(),(l=this._moveHelperLineShape)==null||l.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var E;const l=(E=this._sheetSkeletonManagerService.getCurrent())==null?void 0:E.skeleton;if(l==null)return;const{offsetX:c,offsetY:d}=s,u=o.getRelativeCoord(b.Vector2.FromArray([c,d])),{x:h,y:m}=u;this._startOffsetX=h,this._startOffsetY=m;const{row:S,column:_}=vt(s.offsetX,s.offsetY,o,l);let f;e===0?(this._changeFromRow=S,f=b.ScrollTimerType.Y):(this._changeFromColumn=_,f=b.ScrollTimerType.X);const v=this._checkInHeaderRange(e===0?S:_,e);if(v===!1)return;const M=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(b.CURSOR_TYPE.GRABBING),o.disableEvent();let R=!1,T;const w=()=>{if(R)return;T=b.ScrollTimer.create(o,f);const y=o.getViewport(V.VIEW_MAIN);T.startScroll(h,m,y),this._scrollTimer=T,R=!0};this._moveObserver=o.onPointerMoveObserver.add(y=>{w();const{offsetX:x,offsetY:O}=y,{x:D,y:B}=o.getRelativeCoord(b.Vector2.FromArray([x,O]));o.setCursor(b.CURSOR_TYPE.GRABBING),this._rowColumnMoving(D,B,v,M,e),T.scrolling(D,B,()=>{this._rowColumnMoving(D,B,v,M,e)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var x,O,D;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableEvent(),this._clearObserverEvent(),(x=this._scrollTimer)==null||x.dispose();const y=this._selectionManagerService.getSelections();if(e===0){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const H=(O=((y==null?void 0:y.filter(F=>F.range.rangeType===a.RANGE_TYPE.ROW&&F.range.startRow<=this._changeFromRow&&this._changeFromRow<=F.range.endRow))||[])[0])==null?void 0:O.range;H&&this._commandService.executeCommand(g.MoveRowsCommand.id,{fromRange:H,toRange:{...H,startRow:this._changeToRow,endRow:this._changeToRow+H.endRow-H.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const H=(D=((y==null?void 0:y.filter(F=>F.range.rangeType===a.RANGE_TYPE.COLUMN&&F.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=F.range.endColumn))||[])[0])==null?void 0:D.range;H&&this._commandService.executeCommand(g.MoveColsCommand.id,{fromRange:H,toRange:{...H,startColumn:this._changeToColumn,endColumn:this._changeToColumn+H.endColumn-H.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})}))}_rowColumnMoving(e,n,t,o,r){var ee,re,Z,U,k,$,Q;const{scene:s}=this._sheetObject,l=(ee=this._sheetSkeletonManagerService.getCurrent())==null?void 0:ee.skeleton;if(l==null)return;const{rowHeaderWidth:c,columnHeaderHeight:d,rowTotalHeight:u,columnTotalWidth:h}=l,m=s.getScrollXY(s.getViewport(V.VIEW_MAIN)),{scaleX:S,scaleY:_}=s.getAncestorScale(),f=l.getCellPositionByOffset(e,n,S,_,m),{row:v,column:M}=f,R=l.getNoMergeCellPositionByIndex(v,M),{startX:T,startY:w,endX:E,endY:y}=R,x=this._selectionRenderService.convertRangeDataToSelection(t.range);if(x==null)return;const O=Math.max(S,S),{startX:D,endX:B,startY:H,endY:F,startRow:W,startColumn:z,endRow:Y,endColumn:te}=x;r===0?(re=this._moveHelperBackgroundShape)==null||re.transformByState({height:F-H,width:h+c,left:0,top:H+(n-this._startOffsetY)/O+m.y-o.y}):(Z=this._moveHelperBackgroundShape)==null||Z.transformByState({height:u+d,width:B-D,left:D+(e-this._startOffsetX)/O+m.x-o.x,top:0}),(U=this._moveHelperBackgroundShape)==null||U.show();const j=Md/O;if(r===0){let se=0;if(v<=W)se=w-j/2,this._changeToRow=v;else if(v>Y)se=y-j/2,this._changeToRow=v+1;else return;(k=this._moveHelperLineShape)==null||k.transformByState({height:j,width:h,left:c,top:se})}else{let se=0;if(M<=z)se=T-j/2,this._changeToColumn=M;else if(M>te)se=E-j/2,this._changeToColumn=M+1;else return;($=this._moveHelperLineShape)==null||$.transformByState({height:u,width:j,left:se,top:d})}(Q=this._moveHelperLineShape)==null||Q.show()}_checkInHeaderRange(e,n=0){var l;const t=this._selectionManagerService.getSelections();if(((l=this._selectionManagerService.getCurrent())==null?void 0:l.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return!1;const r=t==null?void 0:t.find(c=>{const d=c.range,{startRow:u,endRow:h,startColumn:m,endColumn:S,rangeType:_}=d;return n===1?e>=m&&e<=S&&a.RANGE_TYPE.COLUMN===_:e>=u&&e<=h&&a.RANGE_TYPE.ROW===_}),s=r==null?void 0:r.range;return r==null||s==null||s.rangeType===a.RANGE_TYPE.ALL||s.rangeType===a.RANGE_TYPE.NORMAL||s.rangeType===a.RANGE_TYPE.ROW&&n!==0||s.rangeType===a.RANGE_TYPE.COLUMN&&n!==1?!1:r}_clearObserverEvent(){const{scene:e}=this._sheetObject;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_newBackgroundAndLine(){const{scene:e}=this._sheetObject;this._moveHelperBackgroundShape=new b.Rect(pd,{fill:Cd,evented:!1,zIndex:100}),this._moveHelperLineShape=new b.Rect(vd,{fill:Id,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],Ze)}_disposeBackgroundAndLine(){var e,n;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(n=this._moveHelperLineShape)==null||n.dispose()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Bn=fd([a.OnLifecycle(a.LifecycleStages.Rendered,Bn),Rt(0,N.Inject(A.SheetSkeletonManagerService)),Rt(1,a.IUniverInstanceService),Rt(2,b.IRenderManagerService),Rt(3,a.ICommandService),Rt(4,_e),Rt(5,N.Inject(g.SelectionManagerService))],Bn);var Pi=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(Pi||{});const Rd="rgba(120, 120, 120, 0.01)",Hi="rgb(68, 71, 70)",Zt=12,Li=4;class Dr extends b.Shape{constructor(n,t){super(n,t);C(this,"_size",Zt);C(this,"_color",Hi);C(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(n){let{width:t,height:o}=this,r=0,s=0;const l=this.getScene(),{scaleX:c,scaleY:d}=l.getAncestorScale(),u=Math.max(c,d),h=Zt/u,m=Li/u;this.mode===0?(t=m,r=h-m):(o=m,s=h-m),b.Rect.drawWith(n,{width:this.width,height:this.height,left:0,top:0,fill:Rd}),b.Rect.drawWith(n,{width:t,height:o,fill:Hi,radius:m}),n.save(),n.transform(1,0,0,1,r,s),b.Rect.drawWith(n,{width:t,height:o,fill:Hi,radius:m}),n.restore()}setShapeProps(n){return n!=null&&n.size&&(this._size=n.size),n!=null&&n.mode&&(this._mode=n.mode),n!=null&&n.color&&(this._color=n.color),this.mode===0?this.transformByState({width:Zt,height:this.size}):this.transformByState({width:this.size,height:Zt}),this}}var bd=Object.defineProperty,wd=Object.getOwnPropertyDescriptor,Td=(i,e,n,t)=>{for(var o=t>1?void 0:t?wd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&bd(e,n,o),o},Gt=(i,e)=>(n,t)=>e(n,t,i);const Ed="__SpreadsheetHeaderResizeControllerShapeRow__",yd="__SpreadsheetHeaderResizeControllerShapeColumn__",Nr="__SpreadsheetHeaderResizeControllerShapeHelper__",Pr="rgb(199, 199, 199)",Od=2;let Fn=class extends a.Disposable{constructor(e,n,t,o,r){super();C(this,"_currentRow",0);C(this,"_currentColumn",0);C(this,"_rowResizeRect");C(this,"_columnResizeRect");C(this,"_observers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_resizeHelperShape");C(this,"_startOffsetX",1/0);C(this,"_startOffsetY",1/0);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._editorBridgeService=r,this._initialize()}dispose(){var o,r;(o=this._rowResizeRect)==null||o.dispose(),this._rowResizeRect=null,(r=this._columnResizeRect)==null||r.dispose(),this._columnResizeRect=null;const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t}=e;this._observers.forEach(s=>{n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;this._rowResizeRect=new Dr(Ed,{visible:!1,mode:Pi.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Dr(yd,{visible:!1,mode:Pi.VERTICAL,zIndex:100}),n.addObjects([this._rowResizeRect,this._columnResizeRect],Ze),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const n=this._getSheetObject();if(n==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:o,scene:r}=n,s=e===0?t:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((l,c)=>{var x;const d=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(d==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:u,columnHeaderHeight:h}=d,{startX:m,startY:S,endX:_,endY:f,row:v,column:M}=vt(l.offsetX,l.offsetY,r,d),R=In(l.offsetX,l.offsetY,r),{scaleX:T,scaleY:w}=r.getAncestorScale(),E=Math.max(T,w),y=Zt/E;if(e===0){let O=S-y/2;if(R.y<=S+y/2&&R.y>=S)this._currentRow=v-1;else if(R.y>=f-y/2&&R.y<=f)this._currentRow=v,O=f-y/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const D=u/3;this._rowResizeRect.transformByState({left:u/2-D/2,top:O}),this._rowResizeRect.setShapeProps({size:D}),this._rowResizeRect.show()}else{let O=m-y/2;if(R.x<=m+y/2&&R.x>=m)this._currentColumn=M-1;else if(R.x>=_-y/2&&R.x<=_)this._currentColumn=M,O=_-y/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const D=h*.7;this._columnResizeRect.transformByState({left:O,top:h/2-D/2}),this._columnResizeRect.setShapeProps({size:D}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((l,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(e=0){const n=this._getSheetObject();if(n==null)return;const{scene:t}=n,o=e===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=t.getEngine(),s=(r==null?void 0:r.width)||0,l=(r==null?void 0:r.height)||0;this.disposeWithMe(a.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),t.setCursor(e===0?b.CURSOR_TYPE.ROW_RESIZE:b.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(a.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),t.resetCursor())}))),this.disposeWithMe(a.toDisposable(o.onPointerDownObserver.add((c,d)=>{var re,Z,U,k,$,Q,se;const u=(re=this._sheetSkeletonManagerService.getCurrent())==null?void 0:re.skeleton;if(u==null)return;const h=this._getSheetObject();if(h==null)return;const{scene:m}=h,S=m.getViewport(V.VIEW_MAIN),_=(((U=(Z=S==null?void 0:S.getScrollBar())==null?void 0:Z.horizonBarRect)==null?void 0:U.height)||0)+10,f=((($=(k=S==null?void 0:S.getScrollBar())==null?void 0:k.verticalBarRect)==null?void 0:$.width)||0)+10,v=In(c.offsetX,c.offsetY,m),{scaleX:M,scaleY:R}=m.getAncestorScale();this._startOffsetX=v.x,this._startOffsetY=v.y;const T=u.getOffsetByPositionX(this._currentColumn),w=u.getOffsetByPositionY(this._currentRow),E=u.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let y=!1,x=0,O=0;const{columnTotalWidth:D,rowHeaderWidth:B,rowTotalHeight:H,columnHeaderHeight:F}=u,W=s>D+B?s:D+B,z=l>H+F?l:H+F,Y=Math.max(M,R),te=Li/Y;e===0?this._resizeHelperShape=new b.Rect(Nr,{width:W,height:te,fill:Pr,left:0,top:w-te/2}):this._resizeHelperShape=new b.Rect(Nr,{width:te,height:z,fill:Pr,left:T-te/2,top:0});const j=((Q=this._columnResizeRect)==null?void 0:Q.left)||0,ee=((se=this._rowResizeRect)==null?void 0:se.top)||0;m.addObject(this._resizeHelperShape,Ze),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(X=>{var Ye,Ie,en,tn,nn,on;const G=m.getRelativeCoord(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),J=m.getScrollXYByRelativeCoords(G,S),ce=In(X.offsetX,X.offsetY,m),{x:ae,y:ge}=ce,{scaleX:Xe,scaleY:Ce}=m.getAncestorScale(),me=Math.max(Xe,Ce),le=Li/me;x=ae-this._startOffsetX-le/2,O=ge-this._startOffsetY-le/2,Math.abs(e===0?O:x)>=Od&&(y=!0),e===0?(O>l-_+J.y-E.startY&&(O=l-_+J.y-E.startY),O<-(E.endY-E.startY)+2&&(O=-(E.endY-E.startY)+2),y&&((Ye=this._resizeHelperShape)==null||Ye.transformByState({top:w+O}),(Ie=this._rowResizeRect)==null||Ie.transformByState({top:ee+O+le/2}),(en=this._rowResizeRect)==null||en.show(),m.setCursor(b.CURSOR_TYPE.ROW_RESIZE))):(x>s-f+J.x-E.startX&&(x=s-f+J.x-E.startX),x<-(E.endX-E.startX)+2&&(x=-(E.endX-E.startX)+2),y&&((tn=this._resizeHelperShape)==null||tn.transformByState({left:T+x}),(nn=this._columnResizeRect)==null||nn.transformByState({left:j+x+le/2}),(on=this._columnResizeRect)==null||on.show(),m.setCursor(b.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(X=>{var ce,ae,ge;const G=ve(this._currentUniverService,this._renderManagerService);if(G==null)return;this._clearObserverEvent(),(ce=this._resizeHelperShape)==null||ce.dispose(),this._resizeHelperShape=null;const{scene:J}=G;J.enableEvent(),y&&(J.resetCursor(),(ae=this._rowResizeRect)==null||ae.hide(),(ge=this._columnResizeRect)==null||ge.hide(),e===0?this._commandService.executeCommand(g.DeltaRowHeightCommand.id,{deltaY:O,anchorRow:this._currentRow}):this._commandService.executeCommand(g.DeltaColumnWidthCommand.id,{deltaX:x,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(a.toDisposable(o.onDblclickObserver.add(()=>{var c;if(e===0){const d=this._getSheetObject();if(d==null)return;const{scene:u}=d;u.resetCursor(),this._commandService.executeCommand(g.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onPointerMoveObserver.remove(this._moveObserver),n.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Fn=Td([a.OnLifecycle(a.LifecycleStages.Rendered,Fn),Gt(0,N.Inject(A.SheetSkeletonManagerService)),Gt(1,a.IUniverInstanceService),Gt(2,a.ICommandService),Gt(3,b.IRenderManagerService),Gt(4,be)],Fn);var Ui=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(Ui||{});const Kt=12,xd=.4;class Hr extends b.Shape{constructor(n,t,o){super(n,t);C(this,"_size",Kt);C(this,"_iconRatio",xd);C(this,"_hovered",!0);C(this,"_hasPrevious",!0);C(this,"_hasNext",!0);C(this,"_unhideType");t&&this.setShapeProps(t),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(n){n.type!==void 0&&(this._unhideType=n.type),n.hovered!==void 0&&(this._hovered=n.hovered),n.hasPrevious!==void 0&&(this._hasPrevious=n.hasPrevious),n.hasNext!==void 0&&(this._hasNext=n.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(n){this._unhideType===0?this._drawOnRow(n):this._drawOnCol(n)}_drawOnRow(n){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(n,{width:this._size,height:this._size,stroke:We,fill:kn}):b.Rect.drawWith(n,{width:this._size,height:2*this._size,stroke:We,fill:kn}));const t=this._size*.5*this._iconRatio,o=Math.PI/3,r=t*Math.cos(o),s=t*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:this._size/2,y:this._size/2-s},{x:this._size/2-s,y:this._size/2+r},{x:this._size/2+s,y:this._size/2+r}]],fill:We}),this._hasNext){const l=this._hasPrevious?3:1;b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:this._size/2,y:this._size*l/2+s},{x:this._size/2-s,y:this._size*l/2-r},{x:this._size/2+s,y:this._size*l/2-r}]],fill:We})}}_drawOnCol(n){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(n,{width:this._size,height:this._size,stroke:We,fill:kn}):b.Rect.drawWith(n,{width:2*this._size,height:this._size,stroke:We,fill:kn}));const t=this._size*.5*this._iconRatio,o=Math.PI/3,r=t*Math.cos(o),s=t*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:-r+this._size/2,y:this._size/2},{x:this._size/2+s,y:this._size/2-s},{x:this._size/2+s,y:this._size/2+s}]],fill:We}),this._hasNext){const l=this._hasPrevious?3:1;b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:r+this._size*l/2,y:this._size/2},{x:-s+this._size*l/2,y:this._size/2-s},{x:-s+this._size*l/2,y:this._size/2+s}]],fill:We})}}}var Ad=Object.defineProperty,Dd=Object.getOwnPropertyDescriptor,Nd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Dd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ad(e,n,o),o},Wn=(i,e)=>(n,t)=>e(n,t,i);const Lr="__SpreadsheetHeaderUnhideSHAPEControllerShape__",Pd=[g.SetRowHiddenMutation.id,g.SetRowVisibleMutation.id,g.SetColHiddenMutation.id,g.SetColVisibleMutation.id];let jn=class extends a.RxDisposable{constructor(e,n,t,o){super();C(this,"_shapes",new Map);this._sheetSkeletonManagerService=e,this._cmdSrv=n,this._univerInstanceService=t,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const n=this._univerInstanceService.getCurrentUniverSheetInstance(),t=n.getActiveSheet();t&&this._initForWorksheet(n,t),this._sheetSkeletonManagerService.currentSkeleton$.pipe(P.takeUntil(this.dispose$),P.startWith(void 0),P.pairwise()).subscribe(([o,r])=>{if(r){const s=this._univerInstanceService.getUniverSheetInstance(r.unitId),l=s.getSheetBySheetId(r.sheetId);this._updateWorksheet(s,l,o==null?void 0:o.sheetId)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!Pd.includes(o.id)||!o.params||!o.params.unitId||!o.params.subUnitId)return;const r=this._univerInstanceService.getUniverSheetInstance(o.params.unitId),s=r==null?void 0:r.getSheetBySheetId(o.params.subUnitId);s&&this._updateWorksheet(r,s,s.getSheetId())}))}_initForWorksheet(e,n){var m;const t=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!t)return;const o=n.getHiddenRows(),r=n.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:l}=s,c=n.getRowCount(),d=o.map(S=>{const{startRow:_,endRow:f}=S,v=xi(_,0,l,t),M=_!==0,R=f!==c-1;return new Hr(Lr,{type:Ui.ROW,hovered:!1,hasPrevious:M,hasNext:R,top:v.startY-(M?Kt:0),left:v.startX-Kt},()=>this._cmdSrv.executeCommand(g.SetSpecificRowsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),ranges:[S]}))}),u=n.getColumnCount(),h=r.map(S=>{const{startColumn:_,endColumn:f}=S,v=xi(0,_,l,t),M=_!==0,R=f!==u-1;return new Hr(Lr,{type:Ui.COLUMN,hovered:!1,hasPrevious:M,hasNext:R,left:v.startX-(M?Kt:0),top:20-Kt},()=>this._cmdSrv.executeCommand(g.SetSpecificColsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),ranges:[S]}))});l.addObjects(h,fo),l.addObjects(d,fo),this._shapes.set(a.getWorksheetUID(e,n),{cols:h,rows:d})}_updateWorksheet(e,n,t){if(t){const o=this._shapes.get(`${e.getUnitId()}|${t}`);o==null||o.cols.forEach(r=>r.dispose()),o==null||o.rows.forEach(r=>r.dispose())}this._initForWorksheet(e,n)}_getSheetObject(){return ve(this._univerInstanceService,this._rendererManagerService)}};jn=Nd([a.OnLifecycle(a.LifecycleStages.Rendered,jn),Wn(0,N.Inject(A.SheetSkeletonManagerService)),Wn(1,a.ICommandService),Wn(2,a.IUniverInstanceService),Wn(3,b.IRenderManagerService)],jn);var Hd=Object.defineProperty,Ld=Object.getOwnPropertyDescriptor,Ud=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ld(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Hd(e,n,o),o},ki=(i,e)=>(n,t)=>e(n,t,i);let zn=class extends a.Disposable{constructor(i,e,n){super(),this._markSelectionService=i,this._commandService=e,this._sheetSkeletonManagerService=n,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[Pe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)?this._markSelectionService.removeAllShapes():this._markSelectionService.getShapeMap().forEach((t,o)=>{t.exits.includes(e.id)&&this._markSelectionService.removeShape(o)})}))}_addRefreshListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};zn=Ud([a.OnLifecycle(a.LifecycleStages.Steady,zn),ki(0,N.Inject(Ht)),ki(1,a.ICommandService),ki(2,N.Inject(A.SheetSkeletonManagerService))],zn);var kd=Object.defineProperty,Vd=Object.getOwnPropertyDescriptor,Bd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Vd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&kd(e,n,o),o},Vi=(i,e)=>(n,t)=>e(n,t,i);let Xn=class extends a.Disposable{constructor(e,n,t){super();C(this,"_initialize",()=>{const e=new a.DisposableCollection;this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{e.dispose();const n=this._selectionManagerService.getCurrent();if((n==null?void 0:n.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{e.add(a.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),l={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn,rangeType:s.rangeType},c={startRow:r.startRow,startColumn:r.startColumn,endRow:r.endRow,endColumn:r.endColumn,rangeType:s.rangeType};if(l.startRow===c.startRow&&l.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:l,toRange:c};this._commandService.executeCommand(g.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=e,this._selectionManagerService=n,this._commandService=t,this._initialize()}};Xn=Bd([a.OnLifecycle(a.LifecycleStages.Steady,Xn),Vi(0,N.Inject(_e)),Vi(1,N.Inject(g.SelectionManagerService)),Vi(2,N.Inject(a.ICommandService))],Xn);var Fd=Object.defineProperty,Wd=Object.getOwnPropertyDescriptor,jd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Wd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Fd(e,n,o),o},bt=(i,e)=>(n,t)=>e(n,t,i);let wt=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}scrollToVisible(i=!0){var F,W,z,Y;let e,n;const t=this._selectionManagerService.getLast();if(t==null)return;const{startRow:o,startColumn:r,actualRow:s,actualColumn:l}=t.primary,c=i?s:o,d=i?l:r,{rowHeightAccumulation:u,columnWidthAccumulation:h}=(W=(F=this._sheetSkeletonManagerService.getCurrent())==null?void 0:F.skeleton)!=null?W:{};if(u==null||h==null)return;const m=(z=this._getSheetObject())==null?void 0:z.scene;if(m==null)return;const S=m.getViewport(V.VIEW_MAIN);if(S==null||this._getSheetObject()==null)return;const f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:v,startRow:M,ySplit:R,xSplit:T}=f.getFreeze(),w=S.getBounding(),E=(Y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Y.skeleton;if(E==null)return;const{startRow:y,startColumn:x,endRow:O,endColumn:D}=E.getRowColumnSegment(w);if(c>=M&&d>=v-T&&(c<=y&&(e=c),c>=O)){const te=u[c]-S.height;for(let j=y;j<=c;j++)if(u[j]>=te){e=j+1;break}}if(d>=v&&c>=M-R&&(d<=x&&(n=d),d>=D)){const te=h[d]-S.width;for(let j=x;j<=d;j++)if(h[j]>=te){n=j+1;break}}if(e===void 0&&n===void 0)return;const{offsetX:B,offsetY:H}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(It.id,{sheetViewStartRow:e,sheetViewStartColumn:n,offsetX:n===void 0?B:0,offsetY:e===void 0?H:0})}dispose(){super.dispose()}_initialize(){this._scrollEventBinding(),this._scrollSubscribeBinding(),this._skeletonListener()}_getFreeze(){var e;const i=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_scrollEventBinding(){var n;const i=(n=this._getSheetObject())==null?void 0:n.scene;if(i==null)return;const e=i.getViewport(V.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollAfterObserver.add(t=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=t,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,l);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollByBarObserver.add(t=>{var S;const o=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton;if(o==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=t,c=this._getFreeze(),{row:d,column:u,rowOffset:h,columnOffset:m}=o.getDecomposedOffset(s,l);this._commandService.executeCommand(It.id,{sheetViewStartRow:d+((c==null?void 0:c.ySplit)||0),sheetViewStartColumn:u+((c==null?void 0:c.xSplit)||0),offsetX:m,offsetY:h})})))}_scrollSubscribeBinding(){this.disposeWithMe(a.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var _;const e=(_=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_.skeleton,n=this._getSheetObject();if(e==null||n==null)return;const t=n.scene;n.scene.getAncestorScale();const o=t.getViewport(V.VIEW_MAIN);if(o==null)return;if(i==null){o.scrollTo({x:0,y:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:l,offsetY:c}=i,{startX:d,startY:u}=e.getCellByIndexWithNoHeader(r,s),h=d+l,m=u+c,S=o.getBarScroll(h,m);o.scrollTo(S)})))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:n}=i;this._renderManagerService.getRenderById(e)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:e,sheetId:n}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:e,unitId:n}=i,t=(c=this._renderManagerService.getRenderById(n))==null?void 0:c.scene;if(e==null||t==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:l}=e;t==null||t.transformByState({width:s+r,height:l+o})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};wt=jd([a.OnLifecycle(a.LifecycleStages.Rendered,wt),bt(0,N.Inject(A.SheetSkeletonManagerService)),bt(1,a.IUniverInstanceService),bt(2,a.ICommandService),bt(3,b.IRenderManagerService),bt(4,N.Inject(g.SelectionManagerService)),bt(5,N.Inject(Je))],wt);var zd=Object.defineProperty,Xd=Object.getOwnPropertyDescriptor,Yd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Xd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&zd(e,n,o),o},Ur=(i,e)=>(n,t)=>e(n,t,i);const $d=[Re.id,it.id];let Yn=class extends a.Disposable{constructor(i,e){super(),this._commandService=i,this._scrollController=e,this.disposeWithMe(this._commandService.onCommandExecuted(n=>{$d.includes(n.id)&&this._scrollController.scrollToVisible()}))}};Yn=Yd([a.OnLifecycle(a.LifecycleStages.Rendered,Yn),Ur(0,a.ICommandService),Ur(1,N.Inject(wt))],Yn);var Zd=Object.defineProperty,Gd=Object.getOwnPropertyDescriptor,Kd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Gd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Zd(e,n,o),o},Qe=(i,e)=>(n,t)=>e(n,t,i);let $n=class extends a.Disposable{constructor(i,e,n,t,o,r,s,l){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._scrollController=l,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),e=i.getActiveSheet(),n=this._getSheetObject();if(n==null)return;this._initViewMainListener(n),this._initRowHeader(n),this._initColumnHeader(n),this._initLeftTop(n),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const t=i.getUnitId(),o=e.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,unitId:t,sheetId:o})}_getActiveViewport(i){const e=this._getSheetObject();return e==null?void 0:e.scene.getActiveViewportByCoord(b.Vector2.FromArray([i.offsetX,i.offsetY]))}_initViewMainListener(i){const{spreadsheet:e}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,t)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,e.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(n)),n.button!==2&&t.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(()=>{this._selectionRenderService.resetStyle();const i=this._selectionManagerService.getSelections(),e=this._selectionManagerService.getCurrent();i==null||(e==null?void 0:e.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){const e=i.map(n=>{const t=this._selectionRenderService.convertSelectionRangeToData(n);return t.style=g.getNormalSelectionStyle(this._themeService),t});this._selectionRenderService.updateControlForCurrentByRangeData(e)}_initRowHeader(i){const{spreadsheetRowHeader:e,spreadsheet:n}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,((n==null?void 0:n.zIndex)||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(t),b.ScrollTimerType.Y),t.button!==2&&o.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:e,spreadsheet:n}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,((n==null?void 0:n.zIndex)||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(t),b.ScrollTimerType.X),t.button!==2&&o.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:e}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,t)=>{var l;const o=(l=this._sheetSkeletonManagerService.getCurrent())==null?void 0:l.skeleton;if(o==null)return;this._selectionRenderService.reset();const r=this._getAllRange(o),s=this._selectionRenderService.convertSelectionRangeToData(r);this._selectionRenderService.addControlToCurrentByRangeData(s),this._selectionRenderService.refreshSelectionMoveStart(),n.button!==2&&t.stopPropagation()})))}_initSelectionChangeListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const e of i){if(e==null)continue;const n=this._selectionRenderService.convertSelectionRangeToData(e);this._selectionRenderService.addControlToCurrentByRangeData(n)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVE_END)})}_move(i,e){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getUnitId(),o=n.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(g.SetSelectionsOperation.id,{unitId:t,subUnitId:o,type:e,pluginName:(r==null?void 0:r.pluginName)||g.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>g.convertSelectionDataToRange(s))})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===n.getUnitId()&&s===t.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:n,skeleton:t}=i,o=this._renderManagerService.getRenderById(e);if(o==null)return;const{scene:r}=o,s=r.getViewport(V.VIEW_MAIN);this._selectionRenderService.changeRuntime(t,r,s);const l=this._selectionManagerService.getCurrent(),c=(l==null?void 0:l.pluginName)||g.NORMAL_SELECTION_PLUGIN_NAME;if((l==null?void 0:l.unitId)===e&&l.sheetId===n){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:e,sheetId:n});c===g.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(t)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const e=i.mergeData;return g.transformCellDataToSelectionData(0,0,e)||{range:{startRow:0,startColumn:0,endRow:0,endColumn:0},primary:{actualRow:0,actualColumn:0,startRow:0,startColumn:0,endRow:0,endColumn:0,isMerged:!1,isMergedMainCell:!1},style:null}}};$n=Kd([a.OnLifecycle(a.LifecycleStages.Rendered,$n),Qe(0,N.Inject(A.SheetSkeletonManagerService)),Qe(1,a.IUniverInstanceService),Qe(2,a.ICommandService),Qe(3,b.IRenderManagerService),Qe(4,_e),Qe(5,N.Inject(g.SelectionManagerService)),Qe(6,N.Inject(a.ThemeService)),Qe(7,N.Inject(wt))],$n);var Jd=Object.defineProperty,Qd=Object.getOwnPropertyDescriptor,qd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Qd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Jd(e,n,o),o},Tt=(i,e)=>(n,t)=>e(n,t,i);let Zn=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=n,this._commandService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:n,sheetId:t}=i,o=this._currentUniverService.getUniverSheetInstance(n),r=o==null?void 0:o.getSheetBySheetId(t);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:l,components:c,scene:d}=s,u=l,h=c.get(fe.ROW),m=c.get(fe.COLUMN),S=c.get(fe.LEFT_TOP),{rowHeaderWidth:_,columnHeaderHeight:f}=e;u==null||u.updateSkeleton(e),h==null||h.updateSkeleton(e),m==null||m.updateSkeleton(e),S==null||S.transformByState({width:_,height:f})})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((i,e)=>{var o,r;const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getUnitId();if(g.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const s=n.getActiveSheet(),l=s.getSheetId(),c=i.params,{unitId:d,subUnitId:u}=c;if(!(d===n.getUnitId()&&u===s.getSheetId()))return;i.id!==g.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:d,sheetId:l,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:d,sheetId:l,commandId:i.id})}else g.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===a.CommandType.MUTATION&&((r=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.mainComponent)==null||r.makeDirty())}))}};Zn=qd([a.OnLifecycle(a.LifecycleStages.Ready,Zn),Tt(0,N.Inject(A.SheetSkeletonManagerService)),Tt(1,a.IUniverInstanceService),Tt(2,b.IRenderManagerService),Tt(3,a.ICommandService),Tt(4,_e),Tt(5,N.Inject(g.SelectionManagerService))],Zn);const je={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,e)=>{const n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(I.IConfirmService),s=i.get(a.LocaleService),l=e.unitId,c=e.subUnitId,d=e.selections,u=g.getAddMergeMutationRangeByType(d,e.value),h=o.getUniverSheetInstance(l).getSheetBySheetId(c),m=[],S=[],_=cr(h,u);if(_&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const f={unitId:l,subUnitId:c,ranges:u},v={unitId:l,subUnitId:c,ranges:u};m.push({id:g.RemoveWorksheetMergeMutation.id,params:f}),m.push({id:g.AddWorksheetMergeMutation.id,params:v});const M=g.RemoveMergeUndoMutationFactory(i,f),R=g.AddMergeUndoMutationFactory(i,v);if(S.push({id:g.RemoveWorksheetMergeMutation.id,params:R}),S.push({id:g.AddWorksheetMergeMutation.id,params:M}),_){const w=dr(i,l,h,u);m.unshift(...w.redos),S.push(...w.undos)}return a.sequenceExecute(m,n).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:m}),!0):!1}},kr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{selections:t,unitId:l,subUnitId:c})}},Vr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:a.Dimension.COLUMNS,selections:t,unitId:l,subUnitId:c})}},Br={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:a.Dimension.ROWS,selections:t,unitId:l,subUnitId:c})}},Bi={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const _=a.Rectangle.getIntersects(S,d);return _?u(S)>u(_):!1})||await e.confirm({id:Bi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.DeleteRangeMoveLeftCommand.id):!0}},Fi={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const _=a.Rectangle.getIntersects(S,d);return _?u(S)>u(_):!1})||await e.confirm({id:Fi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.DeleteRangeMoveUpCommand.id):!0}},Wi={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const _=a.Rectangle.getIntersects(S,d);return _?u(S)>u(_):!1})||await e.confirm({id:Wi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.InsertRangeMoveDownCommand.id):!0}},ji={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const _=a.Rectangle.getIntersects(S,d);return _?u(S)>u(_):!1})||await e.confirm({id:ji.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.InsertRangeMoveRightCommand.id):!0}},Fr={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(i,e)=>{const n=i.get(Ft);return n.applyType=e.type,!0}},Wr={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{var d;const n=i.get(g.SelectionManagerService);let t=e==null?void 0:e.range;if(t||(t=(d=n.getLast())==null?void 0:d.range),!t)return!1;const o=i.get(a.ICommandService),c=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(ko(c,[t])){const u=i.get(I.IConfirmService),h=i.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(g.RemoveRowCommand.id,{range:t}),!0}},jr={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{var d;const n=i.get(g.SelectionManagerService);let t=e==null?void 0:e.range;if(t||(t=(d=n.getLast())==null?void 0:d.range),!t)return!1;const o=i.get(a.ICommandService),c=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(Vo(c,[t])){const u=i.get(I.IConfirmService),h=i.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(g.RemoveColCommand.id,{range:t}),!0}},zr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{const{subUnitId:n}=e,t=i.get(I.IConfirmService),o=i.get(a.ICommandService),r=i.get(a.LocaleService);return await t.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:r.t("sheetConfig.deleteSheet")},children:{title:r.t("sheetConfig.deleteSheetContent")},cancelText:r.t("button.cancel"),confirmText:r.t("button.confirm")})?(await o.executeCommand(g.RemoveSheetCommand.id,{subUnitId:n}),!0):!1}},Et=N.createIdentifier("univer.sheetbar-service");class eu extends a.Disposable{constructor(){super();C(this,"renameId$");C(this,"removeId$");C(this,"scroll$");C(this,"scrollX$");C(this,"addSheet$");C(this,"_renameId$");C(this,"_removeId$");C(this,"_scroll$");C(this,"_scrollX$");C(this,"_addSheet$");C(this,"_currentHandler",null);this._renameId$=new P.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new P.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new P.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new P.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new P.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(n){this._renameId$.next(n)}setRemoveId(n){this._removeId$.next(n)}setScroll(n){this._scroll$.next(n)}setScrollX(n){this._scrollX$.next(n)}setAddSheet(n){this._addSheet$.next(n)}triggerSheetBarMenu(){var n;(n=this._currentHandler)==null||n.handleSheetBarMenu()}registerSheetBarMenuHandler(n){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=n,a.toDisposable(()=>{this._currentHandler=null})}}const Xr={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async i=>(i.get(Et).triggerSheetBarMenu(),!0)},Yr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(i,e)=>{const n=i.get(Et);return e&&n.setRenameId(e.subUnitId),!0}},tu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),p.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),p.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),p.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),p.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),p.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),p.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),p.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),p.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),p.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),p.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),p.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),p.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),p.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),p.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),p.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),p.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),p.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),nu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),p.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),p.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),p.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),p.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),p.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),p.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),p.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),p.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),p.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),p.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),p.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),iu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),p.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),p.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),p.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),p.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),p.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),p.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),p.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),p.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),p.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),p.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),p.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),p.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),p.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),p.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),p.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),p.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),p.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),p.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),p.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),ou=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),p.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),p.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),p.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),p.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),p.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),p.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),p.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),p.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),p.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),p.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),p.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),p.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),p.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),p.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),p.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),p.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),p.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),p.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),p.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),p.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),p.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),p.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),p.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),p.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),p.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),p.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),p.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),p.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),p.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),p.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),p.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),p.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),p.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),p.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),p.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),p.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),p.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),p.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),p.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),p.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),p.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),p.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),ru=()=>p.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),su=()=>p.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),p.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),p.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),p.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),p.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),p.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),au=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),p.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),p.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),p.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),lu=()=>p.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),p.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),p.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),p.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),p.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),p.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),p.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),p.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),p.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),p.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),p.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),p.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),p.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),p.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),p.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),p.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),p.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),p.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),p.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),p.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),cu=()=>p.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),$r=()=>p.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Zr(i){const{type:e=a.BorderStyleTypes.THIN}=i;switch(e){case a.BorderStyleTypes.DASH_DOT:return p.jsx(tu,{});case a.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(nu,{});case a.BorderStyleTypes.DASHED:return p.jsx(iu,{});case a.BorderStyleTypes.HAIR:return p.jsx(ou,{});case a.BorderStyleTypes.MEDIUM:return p.jsx(ru,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(su,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(au,{});case a.BorderStyleTypes.MEDIUM_DASHED:return p.jsx(lu,{});case a.BorderStyleTypes.THICK:return p.jsx(cu,{});case a.BorderStyleTypes.THIN:return p.jsx($r,{});default:return p.jsx($r,{})}}const ze={uiPluginSheetsBorderPanel:"univer-ui-plugin-sheets-border-panel",uiPluginSheetsBorderPanelPosition:"univer-ui-plugin-sheets-border-panel-position",uiPluginSheetsBorderPanelPositionItem:"univer-ui-plugin-sheets-border-panel-position-item",uiPluginSheetsBorderPanelStyles:"univer-ui-plugin-sheets-border-panel-styles",uiPluginSheetsBorderPanelBoard:"univer-ui-plugin-sheets-border-panel-board",uiPluginSheetsBorderPanelButton:"univer-ui-plugin-sheets-border-panel-button",uiPluginSheetsBorderPanelMoreIcon:"univer-ui-plugin-sheets-border-panel-more-icon"},Gr=`${gt}_BORDER_PANEL_COMPONENT`,Kr=[{label:"borderLine.borderTop",icon:"UpBorder",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorder",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorder",value:"left"},{label:"borderLine.borderRight",icon:"RightBorder",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderSingle",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderSingle",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorder",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorder",value:"inside"},{label:"borderLine.borderHorizontal",icon:"InnerBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"InnerBorder",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashSingle",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalSingle",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalSingle",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashSingle",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalSingle",value:"mltr_bctr"}],du=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function uu(i){var l;const e=K.useDependency(I.ComponentManager),{onChange:n,value:t}=i;function o(c,d){n==null||n({...t,[d]:c})}function r(c){const d=e.get(c);return d&&p.jsx(d,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function s(c){c.stopPropagation()}return p.jsxs("section",{className:ze.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:ze.uiPluginSheetsBorderPanelPosition,children:Kr.map(c=>p.jsx("div",{className:ze.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(c.value,"type"),children:r(c.icon)},c.value))}),p.jsxs("div",{className:ze.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(Se.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:ze.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(Se.ColorPicker,{onChange:c=>o(c,"color")})}),children:p.jsxs("a",{className:ze.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(el,{extend:{colorChannel1:(l=t.color)!=null?l:"rgb(var(--primary-color))"}}),p.jsx("span",{className:ze.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(fi,{})})]})})}),p.jsx("div",{children:p.jsx(Se.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(Se.Menu,{children:du.map(c=>p.jsx(Se.MenuItem,{eventKey:c.value.toString(),onClick:()=>o(c.value,"style"),children:p.jsx(Zr,{type:c.value})},c.value))})}),children:p.jsxs("a",{className:ze.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(Zr,{type:a.BorderStyleTypes.THIN}),p.jsx("span",{className:ze.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(fi,{})})]})})})]})]})}const hu={countBar:"univer-count-bar"},mu=[50,80,100,130,150,170,200,400],Su=100;function _u(){const i=K.useDependency(a.ICommandService),e=K.useDependency(a.IUniverInstanceService),n=K.useDependency(a.IContextService),t=c(),[o,r]=L.useState(t),l=!Se.useObservable(()=>P.combineLatest(n.subscribeContextValue$(a.FOCUSING_UNIVER_EDITOR),n.subscribeContextValue$(a.EDITOR_ACTIVATED)).pipe(P.map(([u,h])=>u&&!h),P.debounceTime(Su)),!1,!0,[a.FOCUSING_UNIVER_EDITOR]);L.useEffect(()=>i.onCommandExecuted(h=>{if(h.id===Be.id||h.id===g.SetWorksheetActivateCommand.id){const m=c();r(m)}}).dispose,[i]);function c(){const u=e.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()*100||100;return Math.round(u)}function d(u){r(u);const h=e.getCurrentUniverSheetInstance(),m=h==null?void 0:h.getActiveSheet();if(m==null)return;const S=u/100;i.executeCommand(Nn.id,{unitId:h.getUnitId(),subUnitId:m.getSheetId(),zoomRatio:S})}return p.jsx(Se.Slider,{disabled:l,min:si[0],value:o,shortcuts:mu,onChange:d})}function gu(i){return p.jsx("section",{className:hu.countBar,children:p.jsx(_u,{})})}const Jr={editorContainer:"univer-editor-container",editorInput:"univer-editor-input"},Gn=-1e3,Qr={width:0,height:0,top:Gn,left:Gn},fu=()=>{const[i,e]=L.useState({...Qr}),n=L.useRef(null),t=K.useDependency(b.IRenderManagerService),o=K.useDependency(zt);return L.useEffect(()=>{const r=n.current;if(!r)return;const s=t.currentRender$.pipe(to.switchMap(()=>{var c;const l=(c=t.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:c.engine;return l==null||l.setContainer(r),o.state$})).subscribe(l=>{if(l==null)return;const{startX:c=Gn,startY:d=Gn,endX:u=0,endY:h=0,show:m=!1}=l;if(!m)e({...Qr});else{e({width:u-c,height:h-d,left:c,top:d});const S=n.current;if(!S)return;const{left:_,top:f,width:v,height:M}=S.getBoundingClientRect();o.setRect({left:_,top:f,width:v,height:M})}});return()=>{s.unsubscribe()}},[]),L.useEffect(()=>{o.setFocus(!0)},[i]),p.jsx("div",{className:Jr.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx("div",{className:Jr.editorInput,ref:n})})},he={formulaBox:"univer-formula-box",nameRanges:"univer-name-ranges",nameRangesInput:"univer-name-ranges-input",formulaBar:"univer-formula-bar",formulaIcon:"univer-formula-icon",formulaIconWrapper:"univer-formula-icon-wrapper",iconContainer:"univer-icon-container",iconContainerSuccess:"univer-icon-container-success",formulaActive:"univer-formula-active",iconContainerError:"univer-icon-container-error",formulaInput:"univer-formula-input",formulaContent:"univer-formula-content",arrowContainer:"univer-arrow-container"};function pu(){const[i,e]=L.useState(he.formulaGrey),[n,t]=L.useState(0),o=L.useRef(null),r=K.useDependency(b.IRenderManagerService),s=K.useDependency(Mn),l=K.useDependency(be);L.useEffect(()=>{const m=o.current;if(!m)return;const S=r.currentRender$.subscribe(f=>{var M;if(f!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const v=(M=r.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:M.engine;v==null||v.setContainer(m)}),_=new ResizeObserver(()=>{const f=m.getBoundingClientRect();s.setPosition(f)});return _.observe(m),l.visible$.subscribe(f=>{e(f.visible?he.formulaActive:he.formulaGrey)}),()=>{_.unobserve(m),S.unsubscribe()}},[]);function c(){t(n===0?1:0),setTimeout(()=>{s.handleFoldBtnClick(n===1)},150)}function d(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC})}function u(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})}function h(){s.handleFxBtnClick(!0)}return p.jsxs("div",{className:he.formulaBox,style:{height:n===0?"28px":"82px"},children:[p.jsx("div",{className:he.nameRanges,children:p.jsx("div",{className:he.nameRangesInput})}),p.jsxs("div",{className:he.formulaBar,children:[p.jsx("div",{className:he.formulaIcon,children:p.jsxs("div",{className:he.formulaIconWrapper,children:[p.jsx("span",{className:Dt(he.iconContainer,he.iconContainerError,i),onClick:d,children:p.jsx(Fa,{})}),p.jsx("span",{className:Dt(he.iconContainer,he.iconContainerSuccess,i),onClick:u,children:p.jsx(fn,{})}),p.jsx("span",{className:he.iconContainer,onClick:h,children:p.jsx(Za,{})})]})}),p.jsxs("div",{className:he.formulaInput,children:[p.jsx("div",{onContextMenu:m=>m.preventDefault(),className:he.formulaContent,ref:o}),p.jsx("div",{className:he.arrowContainer,onClick:c,children:n===0?p.jsx(Go,{}):p.jsx(Go,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const rt={operateContainer:"univer-operate-container",autoFillPopupMenu:"univer-auto-fill-popup-menu",autoFillPopupMenuItem:"univer-auto-fill-popup-menu-item",autoFillPopupMenuItemIcon:"univer-auto-fill-popup-menu-item-icon",autoFillPopupMenuItemTitle:"univer-auto-fill-popup-menu-item-title",autoFillPopupMenuItemHide:"univer-auto-fill-popup-menu-item-hide",btnContainer:"univer-btn-container",btnContainerExpand:"univer-btn-container-expand"},vu=()=>{const[,i]=L.useState({});return L.useCallback(()=>i(e=>!e),[])},Cu=()=>{var re;const i=K.useDependency(a.ICommandService),e=K.useDependency(A.SheetSkeletonManagerService),n=K.useDependency(a.IUniverInstanceService),t=K.useDependency(b.IRenderManagerService),o=K.useDependency(_e),r=K.useDependency(Ft),s=K.useDependency(a.LocaleService),[l,c]=L.useState([]),[d,u]=L.useState(!1),[h,m]=L.useState({row:-1,col:-1}),[S,_]=L.useState(oe.SERIES),[f,v]=L.useState(!1),M=()=>{v(!0)},R=()=>{v(!1)},T=vu(),w=ve(n,t);if(w==null)return null;const{scene:E}=w;if(L.useEffect(()=>{const Z=[Pe.id,cn.id,Be.id,g.SetWorksheetActiveOperation.id,g.MoveRangeMutation.id];return i.onCommandExecuted(k=>{k.id===mt.id&&T(),Z.includes(k.id)&&m({row:-1,col:-1})}).dispose},[T,i]),L.useEffect(()=>a.toDisposable(r.menu$.subscribe(U=>{c(U.map(k=>({...k,index:U.indexOf(k)})))})).dispose,[r]),L.useEffect(()=>a.toDisposable(r.showMenu$.subscribe(U=>{const{source:k,target:$}=r.autoFillLocation||{source:null,target:null};if(U&&k&&$){const Q=a.Rectangle.union(k,$);m({row:Q.endRow,col:Q.endColumn})}})).dispose,[r]),L.useEffect(()=>a.toDisposable(r.applyType$.subscribe(U=>{_(U)})).dispose,[r]),L.useEffect(()=>{function Z(){u(!1)}return document.addEventListener("wheel",Z),()=>{document.removeEventListener("wheel",Z)}},[d]),h.col<0||h.row<0)return null;const y=(re=e.getCurrent())==null?void 0:re.skeleton,x=o.getViewPort(),O=E==null?void 0:E.scaleX,D=E==null?void 0:E.scaleY,B=E==null?void 0:E.getScrollXY(x);if(!O||!E||!O||!D||!B)return null;const H=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endX)||0,F=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endY)||0,W=y==null?void 0:y.convertTransformToOffsetX(H,O,B),z=y==null?void 0:y.convertTransformToOffsetY(F,D,B);if(W==null||z==null)return null;const Y=Z=>{u(Z)},te=Z=>{i.executeCommand(Fr.id,{type:Z.value})},j=d||f,ee=l.filter(Z=>!Z.disable);return p.jsx("div",{onMouseEnter:M,onMouseLeave:R,style:{left:`${W+2}px`,top:`${z+2}px`,position:"absolute"},children:p.jsx(Se.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:rt.autoFillPopupMenu,children:ee.map(Z=>p.jsxs("li",{onClick:()=>te(Z),className:rt.autoFillPopupMenuItem,children:[p.jsx("span",{className:rt.autoFillPopupMenuItemIcon,children:Z.value===S&&p.jsx(fn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:rt.autoFillPopupMenuItemTitle,children:s.t(Z.label)})]},Z.index))}),visible:d,onVisibleChange:Y,children:p.jsxs("div",{className:Dt(rt.btnContainer,{[rt.btnContainerExpand]:d}),children:[p.jsx(ka,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),j&&p.jsx(fi,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},Iu=()=>p.jsx("div",{className:rt.operateContainer,children:p.jsx(Cu,{})}),Kn={sheetBar:"univer-sheet-bar",sheetBarOptions:"univer-sheet-bar-options",sheetBarOptionsDivider:"univer-sheet-bar-options-divider"},Mu={sheetBarBtn:"univer-sheet-bar-btn"};function Jn(i){const{children:e,className:n,style:t,disabled:o=!1,onClick:r,...s}=i,l=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:Mu.sheetBarBtn,style:t,disabled:o,onClick:l,...s,children:e})}const qe={sheetBarMenu:"univer-sheet-bar-menu",sheetBarMenuItem:"univer-sheet-bar-menu-item",sheetBarMenuItemIcon:"univer-sheet-bar-menu-item-icon",sheetBarMenuItemHide:"univer-sheet-bar-menu-item-hide",sheetBarMenuItemSelect:"univer-sheet-bar-menu-item-select",sheetBarMenuItemLabel:"univer-sheet-bar-menu-item-label"};function Ru(i){const{style:e}=i,[n,t]=L.useState([]),[o,r]=L.useState(!1),s=K.useDependency(a.IUniverInstanceService),l=K.useDependency(a.ICommandService),c=K.useDependency(Et),d=s.getCurrentUniverSheetInstance(),u=f=>{const{sheetId:v}=f;v&&(f.hidden?l.executeCommand(g.SetWorksheetShowCommand.id,{value:v}):f.selected||l.executeCommand(g.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:v}),r(!1))};L.useEffect(()=>{m();const f=new a.DisposableCollection;return f.add(h()),f.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:S})),()=>{f.dispose()}},[]);const h=()=>l.onCommandExecuted(f=>{switch(f.id){case g.SetWorksheetHideMutation.id:case g.RemoveSheetMutation.id:case g.SetWorksheetNameMutation.id:case g.InsertSheetMutation.id:case g.SetWorksheetOrderMutation.id:case g.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const v=d.getSheets().map((M,R)=>({label:M.getName(),index:`${R}`,sheetId:M.getSheetId(),hidden:M.isSheetHidden()===a.BooleanNumber.TRUE,selected:M.getStatus()===a.BooleanNumber.TRUE}));t(v)};function S(){r(!0)}const _=f=>{r(f)};return p.jsx(Se.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:qe.sheetBarMenu,style:{...e},children:n.map(f=>p.jsxs("li",{onClick:()=>u(f),className:f.selected?`${qe.sheetBarMenuItem} ${qe.sheetBarMenuItemSelect}`:f.hidden?`${qe.sheetBarMenuItem} ${qe.sheetBarMenuItemHide}`:qe.sheetBarMenuItem,children:[p.jsx("span",{className:qe.sheetBarMenuItemIcon,children:f.selected?p.jsx(fn,{}):f.hidden?p.jsx(Ya,{}):p.jsx(fn,{})}),p.jsx("span",{className:qe.sheetBarMenuItemLabel,children:f.label})]},f.index))}),visible:o,onVisibleChange:_,children:p.jsx(Jn,{children:p.jsx(ja,{})})})}const Ee={slideTabBarContainer:"univer-slide-tab-bar-container",slideTabBar:"univer-slide-tab-bar",slideTabItem:"univer-slide-tab-item",slideTabActive:"univer-slide-tab-active",slideTabSpan:"univer-slide-tab-span",slideTabSpanEdit:"univer-slide-tab-span-edit",slideTabItemDropdown:"univer-slide-tab-item-dropdown"};function bu(i){const{sheetId:e,label:n,color:t,selected:o}=i,[r,s]=L.useState(o),l=K.useDependency(a.ThemeService);L.useEffect(()=>{s(o)},[o]);const c=d=>{const u=l.getCurrentTheme(),h=u.textColor,m=u.colorWhite;return new a.ColorKit(d).isDark()?m:h};return p.jsx("div",{"data-id":e,className:r?`${Ee.slideTabActive} ${Ee.slideTabItem}`:Ee.slideTabItem,style:{backgroundColor:!r&&t?t:"",color:!r&&t?c(t):"",boxShadow:r&&t?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${t}`:""},children:p.jsx("span",{className:Ee.slideTabSpan,children:n})},e)}const wu={easeOutStrong(i,e,n,t){return-n*((i=i/t-1)*i*i*i-1)+e},backOut(i,e,n,t,o){return typeof o>"u"&&(o=.7),n*((i=i/t-1)*i*((o+1)*i+o)+1)+e}},Tu={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class Eu{constructor(e){C(this,"_config");C(this,"_status",0);C(this,"_start",0);C(this,"_handle",0);C(this,"_delayHandle",null);this._config={...Tu,...e},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...e){let n=0;return new Promise(t=>{for(let o=0;o<e.length;o++){const r=e[o],s=r._config,l=s.success;s.loop||(s.success=d=>{n++,l&&l.call(r,d),n===e.length&&t()})}})}request(){this._config.delay===0?(this._status=0,this._start=Date.now(),this._fakeHandle()):(this._delayHandle&&clearTimeout(this._delayHandle),this._delayHandle=setTimeout(()=>{this._status=0,this._start=Date.now(),this._fakeHandle()},this._config.delay))}cancel(){this._status=1,this._delayHandle&&clearTimeout(this._delayHandle),cancelAnimationFrame(this._handle)}_fakeHandle(){let e=Date.now()-this._start;e=e>=this._config.duration?this._config.duration:e;const t=wu[this._config.type](e,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(t),this._status===1){this._config.cancel(t),this._config.complete(t);return}if(e===this._config.duration){this._config.success(t),this._config.complete(t);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class st{constructor(e,n){C(this,"_slideTabItem");C(this,"_animate");C(this,"_midline",0);C(this,"_translateX");C(this,"_scrollbar");C(this,"_slideTabBar");C(this,"_editMode");C(this,"_placeholder");this._slideTabItem=e,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=n,this._placeholder=null,this._scrollbar=n.getScrollbar(),this.update()}static midline(e){return e.getBoundingRect().x+e.getBoundingRect().width/2}static leftLine(e){return e.getBoundingRect().x}static rightLine(e){return e.getBoundingRect().x+e.getBoundingRect().width}static make(e,n){const t=[];return e.forEach(o=>t.push(new st(o,n))),t}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var e;(e=this.getEditor())==null||e.focus()}selectAll(){const e=this.getEditor();e&&yt.keepSelectAll(e)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(e){return this._translateX=e,this._slideTabItem.style.transform=`translateX(${e}px)`,this.getTranslateXDirection()}setEditor(e){let n=!0;if(this._editMode===!1){const t=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("blur",o),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",r),t.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(t==null?void 0:t.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}e&&e(d)}};let r=d=>{t&&(d.stopPropagation(),d.key==="Enter"&&t.blur())};const s=d=>{n=!1},l=d=>{n=!0},c=d=>{if(!t)return;const u=50;setTimeout(()=>{if(n){const h=t.innerText;h.length>u&&(t.innerText=h.substring(0,u),yt.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("blur",o),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",r),t.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,yt.keepSelectAll(t))}}nameCheck(){const e=this._slideTabItem.querySelector("span");if(!e)return!1;const n=e.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(n)}animate(){return{translateX:e=>{this._translateX!==e&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Eu({begin:this._translateX,end:e,receive:n=>{this._slideTabItem.style.transform=`translateX(${n}px)`}}),this._translateX=e,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(e){this._slideTabItem.after(e._slideTabItem||e)}update(){this._midline=st.midline(this)}disableFixed(){if(this._placeholder){const e=this._slideTabBar.primeval();this._slideTabItem.style.removeProperty("position"),this._slideTabItem.style.removeProperty("left"),this._slideTabItem.style.removeProperty("top"),this._slideTabItem.style.removeProperty("width"),this._slideTabItem.style.removeProperty("height"),this._slideTabItem.style.removeProperty("background"),this._slideTabItem.style.removeProperty("padding"),this._slideTabItem.style.removeProperty("box-sizing"),this._slideTabItem.style.removeProperty("font-size"),this._slideTabItem.style.removeProperty("font-family"),this._slideTabItem.style.removeProperty("font-weight"),this._slideTabItem.style.removeProperty("color"),this._slideTabItem.style.removeProperty("border-radius"),this._placeholder.after(this._slideTabItem),e.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const e=document.createElement("div"),n=this.getBoundingRect(),t=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=e,this._placeholder.style.width=`${n.width}px`,this._placeholder.style.height=`${n.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=t.margin,this._slideTabItem.style.background=t.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=t.boxSizing,this._slideTabItem.style.fontSize=t.fontSize,this._slideTabItem.style.fontFamily=t.fontFamily,this._slideTabItem.style.fontWeight=t.fontWeight,this._slideTabItem.style.color=t.color,this._slideTabItem.style.borderRadius=t.borderRadius,this._slideTabItem.style.left=`${n.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${n.y}px`,this._slideTabItem.style.width=`${n.width}px`,this._slideTabItem.style.height=`${n.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(e),document.body.appendChild(this._slideTabItem)}addEventListener(e,n,t){this._slideTabItem.addEventListener(e,n,t)}removeEventListener(e,n,t){this._slideTabItem.removeEventListener(e,n,t)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const e=this._slideTabItem.getBoundingClientRect();return e.x+=this._scrollbar.getScrollX(),e}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const e=st.midline(this);return e>this._midline?1:e<this._midline?-1:0}equals(e){return e&&e._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class yu{constructor(e){C(this,"_slideTabBar");C(this,"_scrollX");const n=e.primeval();this._scrollX=n.scrollLeft,this._slideTabBar=e}scrollX(e){const n=this._slideTabBar.primeval();n.scrollLeft=e,this._scrollX=n.scrollLeft}scrollRight(){const e=this._slideTabBar.primeval();e.scrollLeft=e.scrollWidth,this._scrollX=e.scrollLeft}getScrollX(){return this._scrollX}}const At=class At{constructor(e){C(this,"_activeTabItemIndex",0);C(this,"_slideTabBar");C(this,"_slideTabItems",[]);C(this,"_config");C(this,"_downActionX",0);C(this,"_moveActionX",0);C(this,"_compareIndex",0);C(this,"_activeTabItem",null);C(this,"_moveAction");C(this,"_upAction");C(this,"_downAction");C(this,"_wheelAction");C(this,"_scrollIncremental",0);C(this,"_compareDirection",0);C(this,"_autoScrollTime",null);C(this,"_slideScrollbar");C(this,"_longPressTimer",null);C(this,"_leftBoundingLine",0);C(this,"_rightBoundingLine",0);C(this,"_leftMoveX",0);C(this,"_rightMoveX",0);var s;if(e.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const n=e.slideTabBarContainer.querySelector(`.${(s=e.slideTabBarClassName)!=null?s:"slide-tab-bar"}`);if(n==null)throw new Error("not found slide-tab-bar");this._slideTabBar=n,this._slideScrollbar=new yu(this),this._config=e,this._initConfig();let t=0,o=0,r=0;this._downAction=l=>{var y,x,O,D,B,H;if((y=this._activeTabItem)!=null&&y.isEditMode())return;const c=(O=(x=l.target)==null?void 0:x.closest(`.${e.slideTabBarItemClassName}`))==null?void 0:O.getAttribute("data-id"),d=this._slideTabItems.findIndex(F=>F.getId()===c);if(c==null||d===-1)return;if(this._activeTabItemIndex!==d){(D=this._activeTabItem)==null||D.removeEventListener("pointermove",this._moveAction),(B=this._activeTabItem)==null||B.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(l,c);return}if(this._compareIndex=d,this._downActionX=l.pageX,this._moveActionX=0,this._scrollIncremental=0,this._activeTabItem=this._slideTabItems[d],!this._activeTabItem){console.error("Not found active slide-tab-item in sheet bar");return}const u=this._activeTabItem.getSlideTabItem();u==null||u.setPointerCapture(l.pointerId),(H=this._activeTabItem)==null||H.addEventListener("pointerup",this._upAction);const{x:h,width:m}=this._activeTabItem.getBoundingRect(),{x:S,width:_}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(h-f),this._rightBoundingLine=h-f+m-this._downActionX,this._leftMoveX=h-S-f,this._rightMoveX=S+_-(h+m)+f,l.button===2||this._hasEditItem())return;const{pageX:v,pageY:M}=l,R=Date.now(),T=R-r<=At.DoubleClickDelay,w=Math.abs(v-t)<10,E=Math.abs(M-o)<10;T&&w&&E&&this._activeTabItem.setEditor(),t=v,o=M,r=R,this._longPressTimer=setTimeout(()=>{var F,W;(F=this._activeTabItem)==null||F.enableFixed(),this._startAutoScroll(),u&&(u.setPointerCapture(l.pointerId),u.style.cursor="move",(W=this._activeTabItem)==null||W.addEventListener("pointermove",this._moveAction))},At.LongPressDelay)},this._upAction=l=>{var d,u,h;if(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem)return;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const c=(d=this._activeTabItem)==null?void 0:d.getSlideTabItem();c&&(c.style.cursor="",c.releasePointerCapture(l.pointerId),(u=this._activeTabItem)==null||u.removeEventListener("pointermove",this._moveAction),(h=this._activeTabItem)==null||h.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&(this.removeListener(),this._config.onSlideEnd(l,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=l=>{this._activeTabItem&&(this._moveActionX=l.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(l),this._scrollRight(l))},this._wheelAction=l=>{this.setScroll(l.deltaY)},this.addListener()}static checkedSkipSlide(e){let n=e.target;for(;n!=null&&n!==document.body;){if(n.getAttribute("data-slide-skip"))return!0;n=n.parentElement}return!1}static keepLastIndex(e){setTimeout(()=>{const n=window.getSelection();n&&(n.selectAllChildren(e),n.collapseToEnd())})}static keepSelectAll(e){setTimeout(()=>{const n=window.getSelection();if(!n)return;const t=document.createRange();t.selectNodeContents(e),n.removeAllRanges(),n.addRange(t)})}update(e){this._config.currentIndex=e,this._initConfig(),this.removeListener(),this.addListener()}primeval(){return this._slideTabBar}updateItems(){for(let e=0;e<this._slideTabItems.length;e++)this._slideTabItems[e].animate().cancel(),this._slideTabItems[e].translateX(0),this._slideTabItems[e].update()}getScrollbar(){return this._slideScrollbar}getConfig(){return this._config}getBoundingRect(){return this._slideTabBar.getBoundingClientRect()}getSlideTabItems(){return this._slideTabItems}getActiveItem(){return this._activeTabItem}isLeftEnd(){return this._slideTabBar.scrollLeft===0}isRightEnd(){const e=this._slideTabBar.parentElement;return e?this._slideTabBar.scrollWidth-e.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.removeEventListener("pointerdown",this._downAction)})}setScroll(e){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),e>0){const n=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}else if(e<0){const n=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(e){if(e>0){const n=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}else if(e<0){const n=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(e){let n=0;const t=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(n=e?c-r.left-t:c+d-s+t,!0):!1}),n}calculateRightScrollX(e){let n=0;const t=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(n=e?c+d-r.left-r.width+t:c-s-t,!0):!1}),n}destroy(){this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null,this.removeListener()}_hasEditItem(){for(let e=0;e<this._slideTabItems.length;e++)if(this._slideTabItems[e].isEditMode())return!0;return!1}_autoScrollFrame(){if(this._activeTabItem)switch(this._compareDirection=this._activeTabItem.translateX(this._moveActionX),this._compareDirection){case 1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareRight();break}case 0:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareIndex=this._activeTabItemIndex;break}case-1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareLeft();break}}this._autoScrollTime=requestAnimationFrame(()=>{this._autoScrollFrame()})}_startAutoScroll(){this._autoScrollTime==null&&this._autoScrollFrame()}_closeAutoScroll(){this._autoScrollTime&&cancelAnimationFrame(this._autoScrollTime),this._autoScrollTime=null}_scrollLeft(e){const n=this.getBoundingRect(),t=e.pageX-n.x;t<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(t-this._leftBoundingLine)*.1,50))}_scrollRight(e){const n=this.getBoundingRect(),t=e.pageX-n.x;t>n.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(t-(n.width-this._rightBoundingLine))*.1,50))}_sortedItems(){if(this._activeTabItem!=null&&this._activeTabItemIndex!=null&&this._compareIndex!=null&&(this._slideTabItems.splice(this._activeTabItemIndex,1),this._slideTabItems.splice(this._compareIndex,0,this._activeTabItem),this._config.slideTabBarItemAutoSort))for(let e=0;e<this._slideTabItems.length;e++){const n=this._slideTabItems[e],t=this._slideTabItems[e+1];t&&n.after(t)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),n=this._slideTabItems.length,t=[];for(let r=0;r<e&&!(r>=e);r++)t.push(this._slideTabItems[r]);for(let r=e+1;r<n;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=t.length-1;r>=0;r--){const s=t[r];st.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=r,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),n=this._slideTabItems.length,t=[];for(let r=e+1;r<n;r++)t.push(this._slideTabItems[r]);for(let r=0;r<e;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=0;r<t.length;r++){const s=t[r];st.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=e+r+1,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){var n;const e=this._slideTabBar.querySelectorAll(`.${(n=this._config.slideTabBarItemClassName)!=null?n:"slide-tab-item"}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=st.make(e,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};C(At,"LongPressDelay",500),C(At,"DoubleClickDelay",300);let yt=At;function Ou(){const[i,e]=L.useState([]),[n,t]=L.useState(""),[o,r]=L.useState(""),[s,l]=L.useState(!1),[c,d]=L.useState([0,0]),u=L.useRef({slideTabBar:null}),h=L.useRef(null),m=K.useDependency(a.IUniverInstanceService),S=K.useDependency(a.ICommandService),_=K.useDependency(Et),f=K.useDependency(a.LocaleService),v=K.useDependency(I.IConfirmService),M=K.useDependency(_e),R=K.useDependency(be),T=K.useInjector(),w=m.getCurrentUniverSheetInstance();L.useEffect(()=>{F();const U=E(),k=H(),$=[W(),z(),Y(),te()];return()=>{k.dispose(),U.destroy(),$.forEach(Q=>Q.unsubscribe())}},[]),L.useEffect(()=>{i.length>0&&B()},[i]);const E=()=>{const U=new yt({slideTabBarClassName:Ee.slideTabBar,slideTabBarItemActiveClassName:Ee.slideTabActive,slideTabBarItemClassName:Ee.slideTabItem,slideTabBarSpanEditClassName:Ee.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(k,$)=>{S.executeCommand(g.SetWorksheetNameCommand.id,{subUnitId:k,name:$})},onSlideEnd:(k,$)=>{S.executeCommand(g.SetWorksheetOrderCommand.id,{order:$})},onChangeTab:(k,$)=>{S.executeCommand(g.SetWorksheetActivateCommand.id,{subUnitId:$,unitId:w.getUnitId()}).then(()=>{k.button===2&&Z(!0)}),setTimeout(()=>{T.get(b.ITextSelectionRenderManager).focus()},0)},onScroll:k=>{_.setScroll(k)},onNameCheckAlert:k=>y(k)||x(k)});return u.current.slideTabBar=U,re(U),U},y=U=>{if(U.trim()===""){const k="sheetNameEmptyAlert";return v.open({id:k,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){O(),v.close(k)},onConfirm(){O(),v.close(k)}}),!0}return!1},x=U=>{const k=m.getCurrentUniverSheetInstance();if(k.getActiveSheet().getName()===U)return!1;const se=k.checkSheetName(U);if(se){const X="sheetNameRepeatAlert";v.open({id:X,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){v.close(X),O()},onConfirm(){v.close(X),O()}})}return se},O=()=>{M.endSelection(),setTimeout(()=>{var k;const U=(k=u.current.slideTabBar)==null?void 0:k.getActiveItem();U&&(U.focus(),U.selectAll())},0)},D=()=>{var U,k;(k=(U=u.current.slideTabBar)==null?void 0:U.getActiveItem())==null||k.setEditor()},B=()=>{var k;const U=i.findIndex($=>$.selected);(k=u.current.slideTabBar)==null||k.update(U)},H=()=>S.onCommandExecuted(U=>{switch(U.id){case g.SetTabColorMutation.id:case g.SetWorksheetHideMutation.id:case g.RemoveSheetMutation.id:case g.SetWorksheetNameMutation.id:case g.InsertSheetMutation.id:case g.SetWorksheetOrderMutation.id:case g.SetWorksheetActiveOperation.id:F();break}}),F=()=>{const U=w.getActiveSheet().getSheetId();t(U);const $=w.getSheets().filter(Q=>!Q.isSheetHidden()).map((Q,se)=>{var X;return{sheetId:Q.getSheetId(),label:Q.getName(),index:se,selected:Q.getStatus()===a.BooleanNumber.TRUE,color:(X=Q.getTabColor())!=null?X:void 0}});e($)},W=()=>_.scroll$.subscribe(U=>{j(U)}),z=()=>_.scrollX$.subscribe(U=>{var k;(k=u.current.slideTabBar)==null||k.flipPage(U)}),Y=()=>_.renameId$.subscribe(()=>{D()}),te=()=>_.addSheet$.subscribe(()=>{var U;(U=u.current.slideTabBar)==null||U.getScrollbar().scrollRight()}),j=U=>{const{leftEnd:k,rightEnd:$}=U;let Q="";k&&$?Q="":k&&!$?Q="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!k&&$?Q="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!k&&!$&&(Q="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(Q)},ee=U=>{_.setScroll({leftEnd:U.isLeftEnd(),rightEnd:U.isRightEnd()})},re=U=>{var Q;const k=(Q=h.current)==null?void 0:Q.querySelector(`.${Ee.slideTabBar}`);if(!k)return;new ResizeObserver(()=>{ee(U)}).observe(k)},Z=U=>{var k,$,Q,se,X;if(!R.isForceKeepVisible()){if(U){const{left:G}=($=(k=h.current)==null?void 0:k.getBoundingClientRect())!=null?$:{},{left:J}=(X=(se=(Q=u.current.slideTabBar)==null?void 0:Q.getActiveItem())==null?void 0:se.getSlideTabItem().getBoundingClientRect())!=null?X:{};G!==void 0&&J!==void 0&&d([J-G,0])}l(U)}};return p.jsx(Se.Dropdown,{className:Ee.slideTabItemDropdown,visible:s,align:{offset:c},trigger:["contextMenu"],overlay:p.jsx(I.Menu,{menuType:de.SHEET_BAR,onOptionSelect:U=>{const{label:k,value:$}=U;S.executeCommand(k,{value:$,subUnitId:n}),l(!1)}}),onVisibleChange:Z,children:p.jsx("div",{className:Ee.slideTabBarContainer,ref:h,children:p.jsx("div",{className:Ee.slideTabBar,style:{boxShadow:o},children:i.map(U=>L.createElement(bu,{...U,key:U.sheetId,selected:n===U.sheetId}))})})})}const qr=100,xu=()=>{const[i,e]=L.useState(!0),[n,t]=L.useState(!0),o=K.useDependency(a.ICommandService),r=K.useDependency(Et);L.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;e(h),t(m)},l=()=>{o.executeCommand(g.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-qr)},d=()=>{r.setScrollX(qr)};return p.jsxs("div",{className:Kn.sheetBar,children:[p.jsxs("div",{className:Kn.sheetBarOptions,children:[p.jsx(Jn,{onClick:l,children:p.jsx(Ka,{})}),p.jsx(Ru,{})]}),p.jsx(Ou,{}),(!i||!n)&&p.jsxs("div",{className:`${Kn.sheetBarOptions} ${Kn.sheetBarOptionsDivider}`,children:[p.jsx(Jn,{disabled:i,onClick:c,children:p.jsx(tr,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(Jn,{disabled:n,onClick:d,children:p.jsx(tr,{})})]})]})};class Au{constructor(){C(this,"_functions",[{func:ne.FUNCTION_NAMES_STATISTICAL.MAX,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ne.FUNCTION_NAMES_STATISTICAL.MIN,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ne.FUNCTION_NAMES_MATH.SUM,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ne.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:e=>{var n,t;return((t=(n=e.values.find(o=>o.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1}},{func:ne.FUNCTION_NAMES_STATISTICAL.COUNT,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ne.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===ne.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}}]);C(this,"_state$",new P.BehaviorSubject(null));C(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(e){var t;const n={values:[],pattern:null};e==null||e.values.forEach(o=>{const r=this._functions.find(s=>s.func===o.func);r&&(r.filter===void 0||r.filter(e))&&n.values.push(o)}),n.pattern=(t=e==null?void 0:e.pattern)!=null?t:null,this._state$.next(n)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(e){this._functions.push(...e)}}const zi=N.createIdentifier("univer.sheet-status-bar.service"),Ot={statusBar:"univer-status-bar",singleMode:"univer-single-mode",statusBarDiv:"univer-status-bar-div",statisticList:"univer-statistic-list",statisticListColumn:"univer-statistic-list-column",statisticItem:"univer-statistic-item",statisticPicker:"univer-statistic-picker",statisticPickerItem:"univer-statistic-picker-item",statisticMore:"univer-statistic-more"},Du=[ne.FUNCTION_NAMES_MATH.SUM,ne.FUNCTION_NAMES_STATISTICAL.AVERAGE,ne.FUNCTION_NAMES_STATISTICAL.MIN,ne.FUNCTION_NAMES_STATISTICAL.MAX],Xi={[ne.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[ne.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[ne.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[ne.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[ne.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[ne.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[ne.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},Yi=i=>{const e=K.useDependency(a.LocaleService),n=K.useDependency(I.IMessageService),t=K.useDependency(I.IClipboardInterfaceService),o=Nu(i),r=async()=>{await t.writeText(i.value.toString()),n.show({type:Se.MessageType.Success,content:e.t("statusbar.copied")})};return p.jsx(Se.Tooltip,{title:e.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:Ot.statisticItem,onClick:r,children:p.jsx("span",{children:`${e.t((Xi==null?void 0:Xi[i.name])||i.name)}: ${o}`})},i.name)})};function Nu(i){const{pattern:e,value:n}=i;return typeof n!="number"?"Invalid input":n>=1e8?n.toExponential(2):e&&Du.includes(i.name)?ss.format(e,n):n.toLocaleString()}const es=800,Pu=3,Hu=()=>{const[i,e]=L.useState(window.innerWidth<es),[n,t]=L.useState(!0),o=K.useDependency(zi),r=o.getFunctions().map((m,S)=>({name:m.func,value:0,show:!0,disable:!1,pattern:null})),[s,l]=L.useState(r),c=s.find(m=>m.show&&!m.disable),d=i&&c?[c]:s.filter(m=>m.show&&!m.disable);L.useEffect(()=>{const m=o.state$.subscribe(S=>{const _=S==null?void 0:S.values;if(!_||_.length===0)t(!1);else{t(!0);const f=s.map(v=>{var R;const M=_.find(T=>T.func===v.name);return M?(v.value=M.value,v.disable=!1):v.disable=!0,v.pattern=(R=S==null?void 0:S.pattern)!=null?R:null,v});l(f)}});return()=>{m.unsubscribe()}},[o]);const u=Lu(()=>{const m=window.innerWidth<es;i!==m&&e(m)},100);L.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>Pu){const m=[];d.forEach((S,_)=>{_%2===0&&m.push(d.slice(_,_+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((S,_)=>p.jsxs("div",{className:Ot.statisticListColumn,children:[(S==null?void 0:S[0])&&p.jsx(Yi,{...S==null?void 0:S[0]},S==null?void 0:S[0].name),(S==null?void 0:S[1])&&p.jsx(Yi,{...S==null?void 0:S[1]},S==null?void 0:S[1].name)]},`stat-col-${_}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(Yi,{...m},m.name))});return n&&p.jsxs("div",{className:Dt(Ot.statusBar,{[Ot.singleMode]:i}),children:[p.jsx("div",{className:Dt(Ot.statisticList),children:h}),p.jsx("div",{className:Ot.statusBarDiv})]})};function Lu(i,e){let n;return function(...t){const o=this,r=function(){n=null,i.apply(o,t)};clearTimeout(n),n=setTimeout(r,e)}}function Uu(){return p.jsxs("section",{className:yr.sheetContainer,"data-range-selector":!0,children:[p.jsx(xu,{}),p.jsx(Hu,{}),p.jsx(gu,{})]})}function ku(){return p.jsx(p.Fragment,{children:p.jsx(pu,{})})}function Vu(){return p.jsxs(p.Fragment,{children:[p.jsx(fu,{}),p.jsx(Iu,{})]})}function Bu(i){const e=i.get(g.BorderStyleManagerService),n=g.getCurrentSheetDisabled$(i);return{id:g.SetBorderBasicCommand.id,icon:new P.Observable(t=>{const o="AllBorderSingle",r=i.get(g.BorderStyleManagerService),s=i.get(a.ICommandService).onCommandExecuted(l=>{var m;if(l.id!==g.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=Kr.find(S=>S.value===d),h=(m=u==null?void 0:u.icon)!=null?m:o;t.next(h)});return t.next(o),s.dispose}),group:I.MenuGroup.TOOLBAR_FORMAT,tooltip:"toolbar.border.main",positions:[I.MenuPosition.TOOLBAR_START],type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Gr,hoverable:!1},value$:e.borderInfo$}],value$:e.borderInfo$,hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:n}}const Qn="sheet.menu.clear-selection";function Fu(){return{id:Qn,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[I.MenuPosition.CONTEXT_MENU,de.COL_HEADER_CONTEXT_MENU,de.ROW_HEADER_CONTEXT_MENU]}}function Wu(){return{id:g.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[Qn]}}function ju(){return{id:g.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[Qn]}}function zu(){return{id:g.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[Qn]}}const Jt="sheet.menu.delete";function Xu(){return{id:Jt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[I.MenuPosition.CONTEXT_MENU]}}function Yu(){return{id:jr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[Jt,de.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function $u(){return{id:Wr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteRow",positions:[Jt,de.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function Zu(){return{id:Bi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[Jt]}}function Gu(){return{id:Fi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[Jt]}}const $i="sheet.menu.col-insert";function Ku(){return{id:$i,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.COL_HEADER_CONTEXT_MENU]}}const Zi="sheet.menu.row-insert";function Ju(){return{id:Zi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.ROW_HEADER_CONTEXT_MENU]}}const Qt="sheet.menu.cell-insert";function Qu(){return{id:Qt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[I.MenuPosition.CONTEXT_MENU]}}function qu(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[Zi,Qt],hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function eh(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertRowAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[Zi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function th(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,positions:[$i,Qt],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function nh(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertColAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[$i],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function ih(){return{id:ji.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[Qt]}}function oh(){return{id:Wi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[Qt]}}function rh(i){const e=g.getCurrentSheetDisabled$(i);return{id:je.id,icon:"MergeAllSingle",tooltip:"toolbar.mergeCell.main",positions:[I.MenuPosition.TOOLBAR_START],group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:e}}function sh(i){return{id:kr.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[je.id]}}function ah(i){return{id:Vr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[je.id]}}function lh(i){return{id:Br.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[je.id]}}function ch(i){return{id:g.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[je.id]}}function dh(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:zr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.delete",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values()).filter(d=>d.getConfig().hidden===a.BooleanNumber.FALSE);t.next(c.length===1)}});return t.next(!1),o.dispose})}}function uh(){return{id:g.CopySheetCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.copy"}}function hh(){return{id:Yr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.rename"}}function mh(){return{id:g.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[de.SHEET_BAR],type:I.MenuItemType.SELECTOR,selections:[{label:{name:Cn,hoverable:!1}}]}}function Sh(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:g.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.hide",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values()).filter(d=>d.getConfig().hidden===a.BooleanNumber.FALSE);t.next(c.length===1)}});return t.next(!1),o.dispose})}}function _h(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:Xr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.unhide",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values());t.next(c.length===1)}});return t.next(!1),o.dispose})}}const gh={id:g.SetRowHiddenCommand.id,preconditions:i=>ie(i),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},fh={id:g.SetColHiddenCommand.id,preconditions:i=>ie(i),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},ph={id:Re.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.DOWN}},vh={id:Re.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.UP}},Ch={id:Re.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.LEFT}},Ih={id:Re.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.RIGHT}},Mh={id:it.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},Rh={id:it.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},bh={id:it.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},wh={id:it.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ie,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},Th={id:Re.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.DOWN,jumpOver:Ae.moveGap}},Eh={id:Re.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.UP,jumpOver:Ae.moveGap}},yh={id:Re.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.LEFT,jumpOver:Ae.moveGap}},Oh={id:Re.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Ae.moveGap}},xh={id:De.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ie,staticParameters:{direction:a.Direction.DOWN}},Ah={id:De.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ie,staticParameters:{direction:a.Direction.UP}},Dh={id:De.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ie,staticParameters:{direction:a.Direction.LEFT}},Nh={id:De.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ie,staticParameters:{direction:a.Direction.RIGHT}},Ph={id:De.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.DOWN,jumpOver:Ae.moveGap}},Hh={id:De.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.UP,jumpOver:Ae.moveGap}},Lh={id:De.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.LEFT,jumpOver:Ae.moveGap}},Uh={id:De.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Ae.moveGap}},kh={id:Bo.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:ie,staticParameters:{expandToGapFirst:!0,loop:!0}},Vh={id:vi.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>ie(i),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},Bh={id:Ci.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>ie(i),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Fh={id:Ii.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>ie(i),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Wh={id:Mi.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:i=>ie(i),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},jh={id:g.ClearSelectionContentCommand.id,preconditions:i=>ie(i),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},zh={id:Dn.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ie,priority:1,staticParameters:{delta:.2}},Xh={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},Yh={id:Dn.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ie,priority:1,staticParameters:{delta:-.2}},$h={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Zh={id:Dn.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:ie,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Gh={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var Kh=Object.defineProperty,Jh=Object.getOwnPropertyDescriptor,Qh=(i,e,n,t)=>{for(var o=t>1?void 0:t?Jh(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Kh(e,n,o),o},xt=(i,e)=>(n,t)=>e(n,t,i);let qn=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._injector=i,this._componentManager=e,this._commandService=n,this._shortcutService=t,this._menuService=o,this._uiController=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ei,Rl)),this.disposeWithMe(i.register(Gr,uu)),this.disposeWithMe(i.register(Cn,Se.ColorPicker)),this.disposeWithMe(i.register(gr,I.FontFamily)),this.disposeWithMe(i.register(fr,I.FontFamilyItem)),this.disposeWithMe(i.register(pr,I.FontSize))}_initCommands(){[kr,je,Br,Vr,Dn,De,Re,it,Yr,zr,Wr,jr,rr,sr,It,Bo,Ar,_n,g.SetBoldCommand,Bt,Pe,vi,Ci,Ii,Mi,gl,fl,ar,lr,pn,g.SetItalicCommand,g.SetStrikeThroughCommand,g.SetFontFamilyCommand,g.SetFontSizeCommand,wi,ur,Ti,hr,mt,Ln,vn,mr,Sr,_r,g.SetUnderlineCommand,Nn,Be,Xr,Fr,Wi,Fi,ji,Bi].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[Vl,Bl,Fl,Wl,jl,zl,Xl,Wu,ju,zu,Fu,Ku,Ju,Qu,qu,eh,th,nh,$u,ql,tc,ec,nc,Yu,ic,Yl,oc,Xu,Zu,Gu,ih,oh,Gl,Kl,Jl,Ql,$l,Zl,bl,wl,Tl,El,yl,Ol,xl,Al,Dl,Nl,Pl,Bu,rh,sh,ah,lh,ch,Hl,Ll,Ul,kl,dh,uh,hh,mh,Sh,_h].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[ph,vh,Ch,Ih,Mh,Rh,bh,wh,Th,Eh,yh,Oh,xh,Ah,Dh,Nh,Ph,Hh,Lh,Uh,kh,zh,Yh,Zh,Gh,Xh,$h,Vh,Bh,Fh,Wh,jh,...bc(),wc,Tc,yc,Oc,xc,Ec,gh,fh].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>K.connectInjector(ku,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>K.connectInjector(Uu,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>K.connectInjector(Vu,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts()}};qn=Qh([a.OnLifecycle(a.LifecycleStages.Ready,qn),xt(0,N.Inject(N.Injector)),xt(1,N.Inject(I.ComponentManager)),xt(2,a.ICommandService),xt(3,I.IShortcutService),xt(4,I.IMenuService),xt(5,I.IUIController)],qn);var qh=Object.defineProperty,em=Object.getOwnPropertyDescriptor,tm=(i,e,n,t)=>{for(var o=t>1?void 0:t?em(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&qh(e,n,o),o},at=(i,e)=>(n,t)=>e(n,t,i);let ei=class extends a.Disposable{constructor(e,n,t,o,r,s,l){super();C(this,"_calculateTimeout",-1);this._univerInstanceService=e,this._selectionManagerService=n,this._functionService=t,this._statusBarService=o,this._commandService=r,this._formulaDataModel=s,this._numfmtService=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(e=>{var n;((n=this._selectionManagerService.getCurrent())==null?void 0:n.pluginName)===g.NORMAL_SELECTION_PLUGIN_NAME&&e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{const t=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),t)},100))}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(e=>{var n;if(((n=this._selectionManagerService.getCurrent())==null?void 0:n.pluginName)===g.NORMAL_SELECTION_PLUGIN_NAME&&e){const t=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),t)}}))),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===g.SetRangeValuesMutation.id){const n=this._selectionManagerService.getSelections();n&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(n.map(t=>t.range))},100))}}))}_calculateSelection(e,n){var c;const t=this._univerInstanceService.getCurrentUniverSheetInstance(),o=t.getUnitId(),r=t.getActiveSheet().getSheetId(),s={},l=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(d=>{const u=d.getConfig();s[d.getSheetId()]={cellData:new a.ObjectMatrix(u.cellData),rowCount:u.rowCount,columnCount:u.columnCount}}),e!=null&&e.length){const d=e.map(f=>new ne.RangeReferenceObject(f,r,o));d.forEach(f=>{f.setUnitData({[o]:s}),l&&f.setArrayFormulaCellData(ne.convertUnitDataToRuntime(l))});const h=this._statusBarService.getFunctions().map(f=>{const v=this._functionService.getExecutor(f.func);if(!v)return;const M=d.map(T=>T.toArrayValueObject(!1));if((v==null?void 0:v.calculate(...M)).getValue)return{func:f.func,value:(v==null?void 0:v.calculate(...M)).getValue()}});if(h.every(f=>f===void 0))return;let m=null;if(n){const{actualRow:f,actualColumn:v}=n;m=(c=this._numfmtService.getValue(o,r,f,v))==null?void 0:c.pattern}const _={values:h.filter(f=>f!==void 0),pattern:m};this._statusBarService.setState(_)}else this._statusBarService.setState(null)}_isSingleCell(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}};ei=tm([a.OnLifecycle(a.LifecycleStages.Ready,ei),at(0,a.IUniverInstanceService),at(1,N.Inject(g.SelectionManagerService)),at(2,ne.IFunctionService),at(3,zi),at(4,a.ICommandService),at(5,N.Inject(ne.FormulaDataModel)),at(6,N.Inject(g.INumfmtService))],ei);var nm=Object.defineProperty,im=Object.getOwnPropertyDescriptor,om=(i,e,n,t)=>{for(var o=t>1?void 0:t?im(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&nm(e,n,o),o},lt=(i,e)=>(n,t)=>e(n,t,i);let ti=class extends a.Disposable{constructor(i,e,n,t,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._scrollManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._zoomEventBinding()}_zoomEventBinding(){var e;const i=(e=this._getSheetObject())==null?void 0:e.scene;i!=null&&(i.getViewport(V.VIEW_MAIN),this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add((n,t)=>{if(!n.ctrlKey)return;const o=Math.abs(n.deltaX);let r=o<40?.2:o<80?.4:.2;r*=n.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),l=s.getActiveSheet(),c=l.getZoomRatio();let d=+Number.parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Nn.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:l.getSheetId()}),n.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const t=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(t)})))}_commandExecutedListener(){const i=[Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===n.getUnitId()&&s===t.getSheetId()))return;const l=t.getConfig().zoomRatio||1;this._updateViewZoom(l)}}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};ti=om([a.OnLifecycle(a.LifecycleStages.Rendered,ti),lt(0,N.Inject(A.SheetSkeletonManagerService)),lt(1,a.IUniverInstanceService),lt(2,a.ICommandService),lt(3,b.IRenderManagerService),lt(4,_e),lt(5,N.Inject(g.SelectionManagerService)),lt(6,N.Inject(Je))],ti);var rm=Object.defineProperty,sm=Object.getOwnPropertyDescriptor,am=(i,e,n,t)=>{for(var o=t>1?void 0:t?sm(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&rm(e,n,o),o},qt=(i,e)=>(n,t)=>e(n,t,i);A.SheetCanvasView=class extends a.RxDisposable{constructor(n,t,o,r,s){super();C(this,"_scene");C(this,"_currentWorkbook");C(this,"_loadedMap",new Set);C(this,"_isLoadedEditor",!1);C(this,"_fps$",new P.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._currentUniverService.currentSheet$.subscribe(l=>{if(l==null)return;const c=l.getUnitId();this._loadedMap.has(c)||(this._currentWorkbook=l,this._addNewRender(),this._loadedMap.add(c))})}dispose(){this._fps$.complete()}_addNewRender(){const n=this._currentWorkbook,t=n.getUnitId(),o=n.getContainer(),r=n.getParentRenderUnitId();if(o!=null&&r!=null)throw new Error("container or parentRenderUnitId can only exist one");const s=o==null&&r!=null;s?this._renderManagerService.createRenderWithParent(t,r):this._renderManagerService.createRender(t);const l=this._renderManagerService.getRenderById(t);if(l==null)return;const{scene:c,engine:d}=l;c.openTransformer(),this._scene=c,c.addLayer(new b.Layer(c,[],0),new b.Layer(c,[],2)),l!=null&&this._addComponent(l),n.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(t)}_addComponent(n){const t=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();this._addViewport(r);const c=new b.Spreadsheet(fe.MAIN),d=new b.SpreadsheetRowHeader(fe.ROW),u=new b.SpreadsheetColumnHeader(fe.COLUMN),h=new b.Rect(fe.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});n.mainComponent=c,n.components.set(fe.MAIN,c),n.components.set(fe.ROW,d),n.components.set(fe.COLUMN,u),n.components.set(fe.LEFT_TOP,h),t.addObjects([c],go),t.addObjects([d,u,h],Ze),t.enableLayerCache(go,Ze),this._sheetSkeletonManagerService.setCurrent({sheetId:l,unitId:s})}_addViewport(n){const t=this._scene;if(t==null)return;const{rowHeader:o,columnHeader:r}=n.getConfig(),s=new b.Viewport(V.VIEW_MAIN,t,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0});return new b.Viewport(V.VIEW_ROW_TOP,t,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_ROW_BOTTOM,t,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_LEFT,t,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_RIGHT,t,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_LEFT_TOP,t,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_MAIN_LEFT_TOP,t,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_LEFT,t,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_TOP,t,{isWheelPreventDefaultX:!0,active:!1}),t.onMouseWheelObserver.add((l,c)=>{if(l.ctrlKey)return;let d=0,u=0;const h=s.limitedScroll();if(l.inputIndex===b.PointerInput.MouseWheelX){const S=Math.abs(l.deltaX);l.deltaX>0?d=S:d=-S,this._commandService.executeCommand(Ln.id,{offsetX:d}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?l.preventDefault():h!=null&&h.isLimitedX||l.preventDefault()}if(l.inputIndex===b.PointerInput.MouseWheelY){let S=Math.abs(l.deltaY);l.shiftKey?(S*=3,l.deltaY>0?d=S:d=-S,this._commandService.executeCommand(Ln.id,{offsetX:d}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?l.preventDefault():h!=null&&h.isLimitedX||l.preventDefault()):(l.deltaY>0?u=S:u=-S,this._commandService.executeCommand(Ln.id,{offsetY:u}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedY||c.stopPropagation():s.isWheelPreventDefaultY?l.preventDefault():h!=null&&h.isLimitedY||l.preventDefault())}l.inputIndex,b.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}),new b.ScrollBar(s),t.attachControl(),s}},A.SheetCanvasView=am([a.OnLifecycle(a.LifecycleStages.Ready,A.SheetCanvasView),qt(0,a.IUniverInstanceService),qt(1,a.ICommandService),qt(2,b.IRenderManagerService),qt(3,_e),qt(4,N.Inject(A.SheetSkeletonManagerService))],A.SheetCanvasView);var lm=Object.defineProperty,cm=Object.getOwnPropertyDescriptor,dm=(i,e,n,t)=>{for(var o=t>1?void 0:t?cm(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&lm(e,n,o),o},Gi=(i,e)=>(n,t)=>e(n,t,i);A.UniverSheetsUIPlugin=(Ki=class extends a.Plugin{constructor(e,n,t,o){super(ro),this._injector=n,this._localeService=t,this._currentUniverService=o,this._localeService.load({zhCN:Rr})}onStarting(e){[[A.SheetCanvasView],[Ut],[be,{useClass:A.EditorBridgeService}],[ut,{useClass:A.SheetClipboardService}],[Et,{useClass:eu}],[_t,{useClass:bi}],[zt,{useClass:br}],[Mn,{useClass:ac}],[Ft,{useClass:A.AutoFillService}],[Je],[A.SheetSkeletonManagerService],[_e,{useClass:A.SelectionRenderService}],[zi,{useClass:Au}],[Ht,{useClass:A.MarkSelectionService}],[Rn],[bn],[Pn],[yn],[On],[Hn],[Un],[Vn],[Bn],[Fn],[jn],[xn],[Xn],[wt],[$n],[wn],[Tn],[Yn],[Zn],[qn],[An],[ti],[A.AutoFillController],[ei],[En],[zn]].forEach(n=>e.add(n))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const e=this._currentUniverService;e.currentSheet$.pipe(to.filter(n=>!!n)).subscribe(n=>{e.focusUniverInstance(n.getUnitId())})}},C(Ki,"type",a.PluginType.Sheet),Ki),A.UniverSheetsUIPlugin=dm([Gi(1,N.Inject(N.Injector)),Gi(2,N.Inject(a.LocaleService)),Gi(3,a.IUniverInstanceService)],A.UniverSheetsUIPlugin),A.APPLY_TYPE=oe,A.AutoFillCommand=So,A.COPY_TYPE=nt,A.CellEditorManagerService=br,A.DATA_TYPE=ue,A.DefaultRightMenuConfig=no,A.DefaultSheetContainerConfig=oo,A.DefaultSheetUIConfig=as,A.DefaultToolbarConfig=io,A.ExpandSelectionCommand=De,A.IAutoFillService=Ft,A.ICellEditorManagerService=zt,A.IEditorBridgeService=be,A.IFormulaEditorManagerService=Mn,A.IMarkSelectionService=Ht,A.ISelectionRenderService=_e,A.ISheetClipboardService=ut,A.JumpOver=Ae,A.MoveSelectionCommand=Re,A.PASTE_SPECIAL_MENU_ID=pt,A.PREDEFINED_HOOK_NAME=pe,A.RangeSelector=il,A.SHEET_UI_PLUGIN_NAME=ro,A.SelectionShape=un,A.SetCellEditVisibleArrowOperation=Bt,A.SetEditorResizeOperation=_n,A.SetScrollOperation=mt,A.SetZoomRatioOperation=Be,A.SheetCopyCommand=xo,A.SheetPasteCommand=ht,A.VIEWPORT_KEY=V,A.enUS=rc,A.getAutoFillRepeatRange=Is,A.getCoordByCell=xi,A.getCoordByOffset=vt,A.getEditorObject=sn,A.getRepeatRange=sc,A.getSheetObject=ve,A.getTransformCoord=In,A.whenFormulaEditorActivated=Rs,A.zhCN=Rr,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
17
+ */var Ta=H,Ea=Symbol.for("react.element"),ya=Symbol.for("react.fragment"),Oa=Object.prototype.hasOwnProperty,xa=Ta.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Aa={key:!0,ref:!0,__self:!0,__source:!0};function Fo(i,e,n){var t,o={},r=null,s=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(t in e)Oa.call(e,t)&&!Aa.hasOwnProperty(t)&&(o[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)o[t]===void 0&&(o[t]=e[t]);return{$$typeof:Ea,type:i,key:r,ref:s,props:o,_owner:xa.current}}Sn.Fragment=ya,Sn.jsx=Fo,Sn.jsxs=Fo,Bo.exports=Sn;var p=Bo.exports,we=function(){return we=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},we.apply(this,arguments)},Na=function(i,e){var n={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(n[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,t=Object.getOwnPropertySymbols(i);o<t.length;o++)e.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(i,t[o])&&(n[t[o]]=i[t[o]]);return n},Me=H.forwardRef(function(i,e){var n=i.icon,t=i.id,o=i.className,r=i.extend,s=Na(i,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(o||"").trim(),c=H.useRef("_".concat(Ha()));return Wo(n,"".concat(t),{defIds:n.defIds,idSuffix:c.current},we({ref:e,className:l},s),r)});function Wo(i,e,n,t,o){return H.createElement(i.tag,we(we({key:e},Da(i,n,o)),t),(Pa(i,n).children||[]).map(function(r,s){return Wo(r,"".concat(e,"-").concat(i.tag,"-").concat(s),n,void 0,o)}))}function Da(i,e,n){var t=we({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var o=e.defIds;return!o||o.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var s=r[0],l=r[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function Pa(i,e){var n,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?we(we({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&t&&t.indexOf(o.attrs.id)>-1?we(we({},o),{attrs:we(we({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):i}function Ha(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";var La={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365zM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377zM2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365zM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647zM9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635zM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635z",fillRule:"evenodd",clipRule:"evenodd"}}]},jo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"autofill",ref:e,icon:La}))});jo.displayName="Autofill";const Ua=jo;var ka={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.44 3.57291C14.698 3.83093 14.698 4.24927 14.44 4.50729L6.44342 12.5037C6.28721 12.6599 6.03395 12.6599 5.87774 12.5037L1.55992 8.18578C1.3019 7.92776 1.3019 7.50942 1.55993 7.2514C1.81795 6.99338 2.23629 6.99338 2.49431 7.25141L6.01916 10.7763C6.09727 10.8544 6.2239 10.8544 6.30201 10.7763L13.5056 3.57291C13.7636 3.31489 14.1819 3.31489 14.44 3.57291Z",fillRule:"evenodd",clipRule:"evenodd"}}]},zo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"check-mark-single",ref:e,icon:ka}))});zo.displayName="CheckMarkSingle";const gn=zo;var Va={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.57061 3.65132C4.31677 3.39748 3.90521 3.39748 3.65137 3.65132C3.39753 3.90516 3.39753 4.31672 3.65137 4.57056L7.08079 7.99998L3.65123 11.4295C3.39739 11.6834 3.39739 12.0949 3.65123 12.3488C3.90507 12.6026 4.31662 12.6026 4.57047 12.3488L8.00003 8.91921L11.4295 12.3487C11.6834 12.6026 12.0949 12.6026 12.3488 12.3487C12.6026 12.0949 12.6026 11.6833 12.3488 11.4295L8.91927 7.99998L12.3486 4.57061C12.6025 4.31677 12.6025 3.90521 12.3486 3.65137C12.0948 3.39753 11.6832 3.39753 11.4294 3.65137L8.00003 7.08074L4.57061 3.65132Z"}}]},Yo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"close-single",ref:e,icon:Va}))});Yo.displayName="CloseSingle";const Ba=Yo;var Fa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1213",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_1213)"},children:[{tag:"path",attrs:{d:"M1.22297.954345C1.3529.929358 1.51542.914795 1.7147.914795H6.85715C7.0561.914795 7.21986.929297 7.35152.959681 7.48737.991031 7.5967 1.04983 7.67995 1.13863 7.76349 1.22774 7.81571 1.34646 7.84615 1.48343L7.84671 1.48597C7.87164 1.62058 7.88612 1.79252 7.88612 2.00111V7.16269C7.88612 7.36211 7.87154 7.52439 7.84667 7.6587 7.82039 7.79533 7.76169 7.91004 7.67831 7.9934 7.59462 8.0771 7.48565 8.13006 7.35692 8.16096 7.22966 8.1915 7.06561 8.20599 6.87627 8.20599H1.7147C1.52177 8.20599 1.36349 8.19641 1.23252 8.17122 1.09967 8.14567.98914 8.09813.90398 8.0134.818184 7.93285.765734 7.8172.735395 7.68573.705177 7.55478.68573 7.38178.68573 7.16269V1.9581C.68573 1.7541.700286 1.58699.725186 1.45253.751461 1.31589.810166 1.20119.893537 1.11782.978617 1.03274 1.08895.98522 1.22033.954901L1.22297.954345zM2.02733 2.07424C1.95064 2.07854 1.91191 2.09755 1.89153 2.11849 1.86949 2.1517 1.85476 2.19738 1.85473 2.25901L1.86389 3.92571H3.72054V2.07424H2.02733zM4.8991 2.07901V3.92571H6.70756V2.20184C6.70756 2.15684 6.7041 2.12531 6.69899 2.10487 6.69675 2.09591 6.69467 2.09093 6.69349 2.08853 6.68344 2.08345 6.66389 2.07901 6.61819 2.07901H4.8991zM1.86466 5.08037L1.87384 6.90902C1.87384 6.95115 1.87723 6.98219 1.8825 7.00371 1.8864 7.01961 1.89067 7.02788 1.8933 7.03179 1.8933 7.03179 1.89686 7.03365 1.8996 7.03479 1.90589 7.03741 1.91476 7.04025 1.92666 7.04282 1.95062 7.04799 1.98341 7.05133 2.02535 7.05133H3.72532V5.08037H1.86466zM4.8991 5.08037V7.05133H6.55606C6.63148 7.05133 6.67174 7.04228 6.68909 7.03374 6.69039 7.03177 6.69349 7.02643 6.69691 7.01502 6.70311 6.99436 6.70756 6.96264 6.70756 6.91894V5.08037H4.8991zM8.65114 7.83368C8.78108 7.80869 8.94359 7.79413 9.14288 7.79413H14.2853C14.4843 7.79413 14.648 7.80863 14.7797 7.83902 14.9155 7.87037 15.0249 7.92916 15.1081 8.01797 15.1917 8.10707 15.2439 8.2258 15.2743 8.36277L15.2749 8.36531C15.2998 8.49991 15.3143 8.67185 15.3143 8.88045V14.042C15.3143 14.2414 15.2997 14.4037 15.2748 14.538 15.2486 14.6747 15.1899 14.7894 15.1065 14.8727 15.0228 14.9564 14.9138 15.0094 14.7851 15.0403 14.6578 15.0708 14.4938 15.0853 14.3044 15.0853H9.14288C8.94995 15.0853 8.79166 15.0757 8.6607 15.0506 8.52785 15.025 8.41732 14.9775 8.33216 14.8927 8.24636 14.8122 8.19391 14.6965 8.16358 14.5651 8.13336 14.4341 8.11391 14.2611 8.11391 14.042V8.83744C8.11391 8.63343 8.12847 8.46633 8.15337 8.33186 8.17964 8.19523 8.23835 8.08053 8.32172 7.99716 8.4068 7.91208 8.51713 7.86456 8.64851 7.83424L8.65114 7.83368zM9.45551 8.95357C9.37882 8.95788 9.34009 8.97689 9.3197 8.99782 9.29767 9.03103 9.28294 9.07672 9.28291 9.13834L9.29206 10.805H11.1487V8.95357H9.45551zM12.3273 8.95835V10.805H14.1357V9.08118C14.1357 9.03618 14.1323 9.00465 14.1272 8.98421 14.1249 8.97524 14.1228 8.97026 14.1217 8.96786 14.1116 8.96278 14.0921 8.95835 14.0464 8.95835H12.3273zM9.29283 11.9597L9.30202 13.7884C9.30202 13.8305 9.30541 13.8615 9.31068 13.883 9.31457 13.8989 9.31885 13.9072 9.32148 13.9111L9.32448 13.9127 9.32778 13.9141C9.33407 13.9167 9.34293 13.9196 9.35484 13.9222 9.3788 13.9273 9.41159 13.9307 9.45353 13.9307H11.1535V11.9597H9.29283zM12.3273 11.9597V13.9307H13.9842C14.0597 13.9307 14.0999 13.9216 14.1173 13.9131 14.1186 13.9111 14.1217 13.9058 14.1251 13.8944 14.1313 13.8737 14.1357 13.842 14.1357 13.7983V11.9597H12.3273z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.46247 2.15033C9.46247 1.74649 9.78985 1.41911 10.1937 1.41911H12.3873C13.5988 1.41911 14.581 2.40124 14.581 3.61276V5.80641C14.581 6.21025 14.2536 6.53762 13.8498 6.53762 13.4459 6.53762 13.1185 6.21025 13.1185 5.80641V3.61276C13.1185 3.20893 12.7912 2.88154 12.3873 2.88154H10.1937C9.78985 2.88154 9.46247 2.55417 9.46247 2.15033zM2.88154 10.1937C2.88154 9.78986 2.55416 9.46248 2.15032 9.46248 1.74648 9.46248 1.4191 9.78986 1.4191 10.1937V12.3873C1.4191 13.5988 2.40123 14.581 3.61275 14.581H5.8064C6.21024 14.581 6.53761 14.2536 6.53761 13.8498 6.53761 13.4459 6.21024 13.1186 5.8064 13.1186H3.61275C3.20892 13.1186 2.88154 12.7912 2.88154 12.3873V10.1937z"}}]}]},Xo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"convert-single",ref:e,icon:Fa}))});Xo.displayName="ConvertSingle";const Wa=Xo;var ja={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_371_77",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_371_77)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]}]},$o=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"dropdown-single",ref:e,icon:ja}))});$o.displayName="DropdownSingle";const Zo=$o;var za={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.6905 4.78738C2.01709 4.61737 2.41966 4.7443 2.58967 5.07089C2.75217 5.38305 3.00913 5.69251 3.36183 5.98156C4.36103 6.80048 6.03866 7.37872 7.99833 7.37872C9.958 7.37872 11.6356 6.80049 12.6348 5.98157C12.9875 5.69251 13.2445 5.38304 13.407 5.0709C13.577 4.7443 13.9796 4.61737 14.3062 4.78737C14.6327 4.95738 14.7597 5.35995 14.5897 5.68654C14.329 6.18726 13.9448 6.63187 13.48 7.01281C13.4365 7.04842 13.3923 7.08356 13.3473 7.11821L14.8065 8.57746C15.0669 8.83781 15.0669 9.25992 14.8065 9.52027C14.5462 9.78062 14.124 9.78062 13.8637 9.52027L12.1741 7.83063C11.6495 8.08125 11.0697 8.28368 10.451 8.43104L10.9916 10.4486C11.0869 10.8042 10.8759 11.1698 10.5202 11.2651C10.1646 11.3604 9.79902 11.1493 9.70373 10.7937L9.13044 8.6541C8.7607 8.69234 8.38239 8.71205 7.99833 8.71205C7.61155 8.71205 7.2306 8.69206 6.85837 8.65329L6.28486 10.7937C6.18957 11.1494 5.82401 11.3604 5.46837 11.2651C5.11272 11.1698 4.90167 10.8043 4.99696 10.4486L5.53804 8.42923C4.92309 8.28224 4.34666 8.0808 3.82483 7.8317L2.13636 9.52018C1.87602 9.78053 1.45391 9.78053 1.19355 9.52018C0.933204 9.25983 0.933203 8.83772 1.19355 8.57737L2.65127 7.11965C2.60559 7.08453 2.56072 7.04892 2.51667 7.01281C2.05184 6.63186 1.66764 6.18725 1.40699 5.68655C1.23698 5.35996 1.36391 4.95739 1.6905 4.78738Z"}}]},Go=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"eyelash-single",ref:e,icon:za}))});Go.displayName="EyelashSingle";const Ya=Go;var Xa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_367_60",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_367_60)"},children:[{tag:"path",attrs:{d:"M5.48334 4.89587C5.35517 4.89587 5.26008 4.777 5.28822 4.65196L5.37367 4.27223C5.47369 3.84311 5.65731 3.4768 5.93107 3.18085 6.23007 2.85761 6.67323 2.71538 7.21663 2.71538 7.41772 2.71538 7.63284 2.73908 7.86113 2.78378 7.88014 2.7875 7.89899 2.79139 7.91771 2.79543 8.12915 2.84113 8.35624 2.74611 8.43956 2.54647L8.66692 2.00173C8.75382 1.79351 8.65103 1.55537 8.43507 1.49007 8.40283 1.48032 8.36953 1.47045 8.33516 1.46047 8.0467 1.37763 7.70317 1.3335 7.29999 1.3335 6.2394 1.3335 5.44639 1.60069 4.89385 2.10573 4.32912 2.62202 3.92814 3.3605 3.70338 4.33753L2.25629 10.5523C2.18051 10.8899 2.08525 11.253 1.96769 11.6425 1.849 12.0347 1.70655 12.4208 1.54146 12.7986 1.37502 13.1773 1.18738 13.5375.978805 13.8784.912697 13.9865.8444 14.0896.773916 14.1876.684332 14.3122.753952 14.4944.905805 14.5167 1.5556 14.6123 2.23715 14.4376 2.60122 13.8909 2.74587 13.6737 2.88704 13.426 3.02434 13.1464 3.3856 12.411 3.72447 11.3716 4.03792 10.0188L4.88825 6.37667C4.90938 6.28616 4.99007 6.22214 5.08301 6.22214H7.04403C7.22895 6.22214 7.38976 6.09538 7.43296 5.91557L7.55939 5.3893C7.61982 5.13775 7.42917 4.89587 7.17046 4.89587H5.48334zM13.7403 5.0817L11.9317 7.33096 10.8281 5.13886C10.7615 4.99145 10.6146 4.89673 10.4529 4.89673H9.73214C9.4277 4.89673 9.22847 5.21561 9.36195 5.48923L10.8281 8.41635 8.21708 11.5106C7.98512 11.7771 8.17444 12.1929 8.5278 12.1929H9.10532C9.22597 12.1929 9.37975 12.1436 9.45801 12.0518L11.53 9.62616 12.5369 11.9223C12.5978 12.0844 12.7522 12.1929 12.9254 12.1929H13.7193C14.0023 12.1929 14.161 11.9788 14.0619 11.7137L12.592 8.64761C12.592 8.64761 14.8202 5.81675 15.0205 5.54025 15.2159 5.27062 15.0215 4.89673 14.6886 4.89673H14.0854C13.9467 4.89673 13.8525 4.9502 13.7403 5.0817z"}}]}]},Ko=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"fx-single",ref:e,icon:Xa}))});Ko.displayName="FxSingle";const $a=Ko;var Za={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_249",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_249)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.74717 2.0944C8.74717 1.68671 8.41279 1.3562 8.00032 1.3562C7.58785 1.3562 7.25347 1.68671 7.25347 2.0944V7.26186H2.02541C1.61294 7.26186 1.27856 7.59237 1.27856 8.00007C1.27856 8.40777 1.61294 8.73827 2.02541 8.73827H7.25347V13.9057C7.25347 14.3134 7.58785 14.6439 8.00032 14.6439C8.41279 14.6439 8.74717 14.3134 8.74717 13.9057V8.73827H13.975C14.3874 8.73827 14.7218 8.40777 14.7218 8.00007C14.7218 7.59237 14.3874 7.26186 13.975 7.26186H8.74717V2.0944Z"}}]}]},Jo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"increase-single",ref:e,icon:Za}))});Jo.displayName="IncreaseSingle";const Ga=Jo;var Ka={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_556",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_556)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M0.629584 3.99986C1.13729 3.4922 1.9604 3.49224 2.46806 3.99995L7.57569 9.10806C7.81 9.3424 8.18992 9.3424 8.42424 9.10808L13.5323 3.99998C14.04 3.4923 14.8631 3.4923 15.3708 3.99998C15.8785 4.50766 15.8785 5.33078 15.3708 5.83846L9.41415 11.7951C8.63307 12.5762 7.36669 12.5762 6.58565 11.7951L0.629497 5.83834C0.121839 5.33063 0.121879 4.50752 0.629584 3.99986Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Qo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"more-down-single",ref:e,icon:Ka}))});Qo.displayName="MoreDownSingle";const Si=Qo;var Ja={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.45493 2.80093C5.74783 2.49409 6.2227 2.49409 6.5156 2.80093L11.0156 7.51523C11.3085 7.82207 11.3085 8.31956 11.0156 8.6264L6.44488 13.27C6.15199 13.5768 5.67711 13.5768 5.38422 13.27C5.09133 12.9631 5.09133 12.4656 5.38422 12.1588L9.28804 8.20898C9.36409 8.13203 9.36517 8.00855 9.29047 7.93029L5.45493 3.9121C5.16204 3.60526 5.16204 3.10777 5.45493 2.80093Z",fillRule:"evenodd",clipRule:"evenodd"}}]},qo=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"more-single",ref:e,icon:Ja}))});qo.displayName="MoreSingle";const er=qo;var Qa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1204",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1204)"},children:[{tag:"rect",attrs:{width:12.62,height:2.79,x:1.69,y:12.25,fill:"colorChannel1",rx:1.4}},{tag:"path",attrs:{fill:"currentColor",d:"M7.74646 2.1642C7.34284 1.65121 6.85947 1.28205 6.38447 1.09593C5.86863 0.893787 5.15166 0.852126 4.70047 1.42917C4.29842 1.94344 4.33082 2.70249 4.57691 3.50395C4.68808 3.8661 4.86846 4.22254 5.12522 4.56617C5.13695 4.58185 5.14927 4.5968 5.16211 4.61102C5.17152 4.6214 5.18122 4.63139 5.19115 4.64096C5.20459 4.65393 5.21855 4.66618 5.23296 4.6777L3.5064 6.40422C3.26756 6.64306 3.26756 7.03033 3.5064 7.26919L7.23756 11.0004C7.47648 11.2392 7.86375 11.2392 8.1026 11.0004L12.8329 6.27001C13.0717 6.03117 13.0717 5.6439 12.8329 5.40505L9.10172 1.67387C8.86288 1.43503 8.47561 1.43503 8.23676 1.67387L7.74646 2.1642ZM7.46162 4.50638C7.47252 4.57574 7.48163 4.64652 7.4888 4.71868C7.52232 5.05481 7.82194 5.30013 8.15807 5.26661C8.4942 5.23311 8.73954 4.93345 8.70601 4.59732C8.65786 4.11463 8.54251 3.6666 8.37892 3.26169L8.66928 2.97135L11.5354 5.83753L10.6106 6.76237H4.87824L7.40802 4.2326C7.42885 4.32128 7.44684 4.41255 7.46162 4.50638ZM6.87284 3.03784C6.57441 2.62008 6.22261 2.34634 5.93815 2.23487C5.80233 2.18165 5.71528 2.17827 5.67638 2.18335C5.6725 2.18387 5.66929 2.18443 5.6666 2.18497L5.6619 2.18607C5.64166 2.21954 5.53594 2.45979 5.74626 3.1449C5.81241 3.36036 5.92262 3.58602 6.09307 3.81761L6.87284 3.03784Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.1932 11.5463C12.6454 11.5463 13.012 11.1797 13.012 10.7275C13.012 10.4475 12.6981 9.92821 12.459 9.5733C12.3299 9.38173 12.0564 9.38174 11.9274 9.57331C11.6883 9.92822 11.3744 10.4475 11.3744 10.7275C11.3744 11.1797 11.741 11.5463 12.1932 11.5463Z"}}]}]},tr=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"paint-bucket",ref:e,icon:Qa}))});tr.displayName="PaintBucket";const qa=tr;var el={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.49152 1.3335C1.79021 1.3335 1.22168 1.90202 1.22168 2.60334V13.397C1.22168 14.0983 1.79021 14.6668 2.49152 14.6668H9.42803C9.98031 14.6668 10.428 14.2191 10.428 13.6668V13.397V10.9234C10.428 10.7577 10.5623 10.6234 10.728 10.6234H13.2852H13.555C14.1073 10.6234 14.555 10.1757 14.555 9.62343V2.60334C14.555 1.90202 13.9865 1.3335 13.2852 1.3335H2.49152ZM8.85819 13.397C9.02387 13.397 9.15819 13.2627 9.15819 13.097V10.9234C9.15819 10.7577 9.02387 10.6234 8.85819 10.6234H6.60104C6.43536 10.6234 6.30104 10.7577 6.30104 10.9234V13.097C6.30104 13.2627 6.43536 13.397 6.60104 13.397H8.85819ZM13.2852 9.05359C13.2852 9.21927 13.1509 9.35359 12.9852 9.35359H10.728C10.5623 9.35359 10.428 9.21927 10.428 9.05359V6.96718C10.428 6.80149 10.5623 6.66718 10.728 6.66718H12.9852C13.1509 6.66718 13.2852 6.80149 13.2852 6.96718V9.05359ZM8.85819 9.35359C9.02387 9.35359 9.15819 9.21927 9.15819 9.05359V6.96718C9.15819 6.80149 9.02387 6.66718 8.85819 6.66718H6.60104C6.43536 6.66718 6.30104 6.80149 6.30104 6.96718V9.05359C6.30104 9.21927 6.43536 9.35359 6.60104 9.35359H8.85819ZM13.2852 5.09734C13.2852 5.26302 13.1509 5.39734 12.9852 5.39734H10.728C10.5623 5.39734 10.428 5.26302 10.428 5.09734V2.90334C10.428 2.73765 10.5623 2.60334 10.728 2.60334H12.9852C13.1509 2.60334 13.2852 2.73765 13.2852 2.90334V5.09734ZM8.85819 5.39734C9.02387 5.39734 9.15819 5.26302 9.15819 5.09734V2.90334C9.15819 2.73765 9.02387 2.60334 8.85819 2.60334H6.60104C6.43536 2.60334 6.30104 2.73765 6.30104 2.90334V5.09734C6.30104 5.26302 6.43536 5.39734 6.60104 5.39734H8.85819ZM5.0312 2.90334C5.0312 2.73765 4.89689 2.60334 4.7312 2.60334H2.79152C2.62584 2.60334 2.49152 2.73765 2.49152 2.90334V5.09734C2.49152 5.26302 2.62584 5.39734 2.79152 5.39734H4.7312C4.89689 5.39734 5.0312 5.26302 5.0312 5.09734V2.90334ZM5.0312 6.96718C5.0312 6.80149 4.89689 6.66718 4.7312 6.66718H2.79152C2.62584 6.66718 2.49152 6.80149 2.49152 6.96718V9.05359C2.49152 9.21927 2.62584 9.35359 2.79152 9.35359H4.7312C4.89689 9.35359 5.0312 9.21927 5.0312 9.05359V6.96718ZM5.0312 10.9234C5.0312 10.7577 4.89689 10.6234 4.7312 10.6234H2.79152C2.62584 10.6234 2.49152 10.7577 2.49152 10.9234V13.097C2.49152 13.2627 2.62584 13.397 2.79152 13.397H4.7312C4.89689 13.397 5.0312 13.2627 5.0312 13.097V10.9234Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.0703 11.9137C12.0445 11.75 12.2176 11.6277 12.3633 11.7068L14.6735 12.9609C14.8412 13.052 14.7972 13.3003 14.6155 13.3333C14.6046 13.3352 14.5937 13.3371 14.5831 13.34L13.58 13.6178L12.8438 14.5421C12.7486 14.7038 12.5031 14.6572 12.4739 14.4718L12.0703 11.9137Z"}}]},nr=H.forwardRef(function(i,e){return H.createElement(Me,Object.assign({},i,{id:"select-range-single",ref:e,icon:el}))});nr.displayName="SelectRangeSingle";const tl=nr,ot={rangeSelector:"univer-range-selector",rangeSelectorEditor:"univer-range-selector-editor",rangeSelectorIcon:"univer-range-selector-icon",rangeSelectorActive:"univer-range-selector-active"};function nl(i){const{onChange:e,onActive:n}=i,[t,o]=H.useState(!1),r=H.useRef(null),s=K.useDependency(a.LocaleService),l=K.useDependency(g.SelectionManagerService);H.useEffect(()=>{var m;if(t){n(t);const _=l.selectionMoveEnd$.subscribe(S=>{const f=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],v=Math.floor(Math.random()*f.length),M=f[v];r.current&&(r.current.innerHTML=M)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),_.unsubscribe()}}e(((m=r.current)==null?void 0:m.innerHTML)||"")},[t]);function c(m){var v,M,R;if(((v=m.target)==null?void 0:v.closest('[data-range-selector="true"]'))||m.target===r.current)return;const S=(M=m.target)==null?void 0:M.closest(`.${ot.rangeSelector}`);(S==null?void 0:S.querySelector(`.${ot.rangeSelectorEditor}`))!==r.current&&(o(!1),(R=r.current)==null||R.blur())}function d(m){m.stopPropagation(),m.key==="Enter"&&(m.preventDefault(),m.currentTarget.blur(),o(!1))}function u(){o(!0)}function h(){var m;if(!t){(m=r.current)==null||m.focus();return}o(!t)}return p.jsxs("div",{className:t?`${ot.rangeSelector} ${ot.rangeSelectorActive}`:ot.rangeSelector,children:[p.jsx("div",{ref:r,className:ot.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(_e.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:ot.rangeSelectorIcon,onClick:h,children:p.jsx(tl,{})})})]})}var _t=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(_t||{}),ue=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(ue||{}),re=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(re||{});const il={type:ue.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER,isContinue:(i,e)=>i.type===ue.NUMBER,applyFunctions:{[re.SERIES]:(i,e,n)=>{const{data:t}=i;return n===a.Direction.LEFT||n===a.Direction.UP?(t.reverse(),so(t,e,n).reverse()):so(t,e,n)}}},ir={type:ue.OTHER,priority:0,match:()=>!0,isContinue:(i,e)=>i.type===ue.OTHER},ol={type:ue.EXTEND_NUMBER,priority:900,match:i=>ln(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,e)=>{var n;if(i.type===ue.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:o}=ln(`${(n=i.cellData)==null?void 0:n.v}`||""),{beforeTxt:r,afterTxt:s}=ln(`${e==null?void 0:e.v}`||"");if(t===r&&o===s)return!0}return!1},applyFunctions:{[re.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.UP||n===a.Direction.LEFT;let r;if(t.length===1)return r=o?-1:1,Te(ao(t,e,r),o);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(ln(d).matchTxt))}return o&&(t.reverse(),s.reverse()),Dt(s)?(r=s[1]-s[0],Te(ao(t,e,r),o)):et(t,e)}}},rl={type:ue.CHN_NUMBER,priority:830,match:i=>!!ds(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_NUMBER,applyFunctions:{[re.SERIES]:(i,e,n)=>{var c,d,u;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||Ve(h)<7)?Te(dt(t,e,m),o):Te(lo(t,e,m),o)}let r=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const m=`${(u=t[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&Ve(m)>0&&Ve(m)<7?s.push(Ve(m)+l*7):s.push(Ve(m))}if(o&&(t.reverse(),s.reverse()),Dt(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const m=s[1]-s[0];return Te(dt(t,e,m),o)}const h=s[1]-s[0];return Te(lo(t,e,h),o)}return et(t,e)}}},sl={type:ue.CHN_WEEK2,priority:820,match:i=>!!us(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK2,applyFunctions:{[re.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){let c;return o?c=-1:c=1,Te(dt(t,e,c,1),o)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Ve(u)+s*7)}if(o&&(t.reverse(),r.reverse()),Dt(r)){const c=r[1]-r[0];return Te(dt(t,e,c,1),o)}return et(t,e)}}},al={type:ue.CHN_WEEK3,priority:810,match:i=>hs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK3,applyFunctions:{[re.SERIES]:(i,e,n)=>{var l;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP;if(t.length===1){let c;return o?c=-1:c=1,Te(dt(t,e,c,2),o)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Ve(u)+s*7)}}if(o&&(t.reverse(),r.reverse()),Dt(r)){const c=r[1]-r[0];return Te(dt(t,e,c,2),o)}return et(t,e)}}},ll={type:ue.LOOP_SERIES,priority:800,match:i=>vs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>{var n;return i.type===ue.LOOP_SERIES?ii(`${(n=i.cellData)==null?void 0:n.v}`||"").name===ii(`${e==null?void 0:e.v}`||"").name:!1},applyFunctions:{[re.SERIES]:(i,e,n)=>{var c,d;const{data:t}=i,o=n===a.Direction.LEFT||n===a.Direction.UP,{series:r}=ii(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return o?u=-1:u=1,Te(co(t,e,u,r),o)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(l++,s.push(l*r.length)):s.push(r.indexOf(h)+l*7))}if(o&&(t.reverse(),s.reverse()),Dt(s)){const u=s[1]-s[0];return Te(co(t,e,u,r),o)}return et(t,e)}}};function Te(i,e){return e?i.reverse():i}var cl=Object.defineProperty,dl=Object.getOwnPropertyDescriptor,ul=(i,e,n,t)=>{for(var o=t>1?void 0:t?dl(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&cl(e,n,o),o},gi=(i,e)=>(n,t)=>e(n,t,i);A.AutoFillService=class extends a.Disposable{constructor(n,t,o){super();C(this,"_rules",[]);C(this,"_hooks",[]);C(this,"_applyType$",new P.BehaviorSubject(re.SERIES));C(this,"_isFillingStyle",!0);C(this,"_autoFillLocation$",new P.BehaviorSubject(null));C(this,"autoFillLocation$",this._autoFillLocation$.asObservable());C(this,"_showMenu$",new P.BehaviorSubject(!1));C(this,"showMenu$",this._showMenu$.asObservable());C(this,"_direction",a.Direction.DOWN);C(this,"applyType$",this._applyType$.asObservable());C(this,"_menu$",new P.BehaviorSubject([{label:"autoFill.copy",value:re.COPY,disable:!1},{label:"autoFill.series",value:re.SERIES,disable:!1},{label:"autoFill.formatOnly",value:re.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:re.NO_FORMAT,disable:!1}]));C(this,"menu$",this._menu$.asObservable());this._sheetInterceptorService=n,this._univerInstanceService=t,this._selectionManagerService=o,this._init()}_init(){this._rules=[il,ol,rl,sl,al,ll,ir].sort((n,t)=>t.priority-n.priority),this._isFillingStyle=!0}getOneByPriority(n){return n.length<=0?[]:[n.reduce((o,r)=>(r.priority||0)>(o.priority||0)?r:o,n[0])]}addHook(n){if(this._hooks.find(t=>t.id===n.id))throw new Error(`Add hook failed, hook id '${n.id}' already exist!`);return n.priority===void 0&&(n.priority=0),n.type===void 0&&(n.type=_t.Append),this._hooks.push(n),a.toDisposable(()=>{const t=this._hooks.findIndex(o=>o===n);t>-1&&this._hooks.splice(t,1)})}registerRule(n){if(this._rules.find(o=>o.type===n.type))throw new Error(`Registry rule failed, type '${n.type}' already exist!`);const t=this._rules.findIndex(o=>o.priority<n.priority);this._rules.splice(t===-1?this._rules.length:t,0,n)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:n,target:t,unitId:o,subUnitId:r}=this.autoFillLocation||{};if(!n||!t||!o||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:n,target:t,unitId:o,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===_t.Only);if(l.length>0)return this.getOneByPriority(l);const c=this.getOneByPriority(s.filter(u=>u.type===_t.Default)),d=s.filter(u=>u.type===_t.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(n){this._applyType$.next(n)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(n){this._direction=n}isFillingStyle(){return this._isFillingStyle}setFillingStyle(n){this._isFillingStyle=n}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(n){this._autoFillLocation$.next(n)}setDisableApplyType(n,t){this._menu$.next(this._menu$.getValue().map(o=>o.value===n?{...o,disable:t}:o))}setShowMenu(n){this._showMenu$.next(n)}},A.AutoFillService=ul([a.OnLifecycle(a.LifecycleStages.Rendered,A.AutoFillService),gi(0,D.Inject(g.SheetInterceptorService)),gi(1,D.Inject(a.IUniverInstanceService)),gi(2,D.Inject(g.SelectionManagerService))],A.AutoFillService);const Ft=D.createIdentifier("univer.auto-fill-service");var hl=Object.defineProperty,ml=Object.getOwnPropertyDescriptor,_l=(i,e,n,t)=>{for(var o=t>1?void 0:t?ml(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&hl(e,n,o),o},Fe=(i,e)=>(n,t)=>e(n,t,i);A.AutoFillController=class extends a.Disposable{constructor(n,t,o,r,s,l,c,d,u){super();C(this,"_beforeApplyData",[]);C(this,"_copyData",[]);C(this,"_defaultHook");this._univerInstanceService=n,this._selectionRenderService=t,this._commandService=o,this._undoRedoService=r,this._autoFillService=s,this._editorBridgeService=l,this._sheetInterceptorService=c,this._selectionManagerService=d,this._injector=u,this._defaultHook={id:"default",type:_t.Default,priority:0,onBeforeFillData:(h,m)=>{this._presetAndCacheData(h,m)},onFillData:(h,m,_)=>this._fillData(h,m,_)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[ho,cn].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initDefaultHook(){this._autoFillService.addHook(this._defaultHook)}_onSelectionControlFillChanged(){const n=new a.DisposableCollection;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==g.SetSelectionsOperation.id)return;const o=this._selectionManagerService.getCurrent();if((o==null?void 0:o.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return;n.dispose(),this._selectionRenderService.getCurrentControls().forEach(s=>{n.add(a.toDisposable(s.selectionFilled$.subscribe(l=>{if(l==null||l.startColumn===-1||l.startRow===-1||l.endColumn===-1||l.endRow===-1)return;const c={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow},d={startColumn:l.startColumn,endColumn:l.endColumn,startRow:l.startRow,endRow:l.endRow};this._triggerAutoFill(c,d)}))),n.add(a.toDisposable(s.fillControl.onDblclickObserver.add(()=>{const l={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow};this._handleDbClickFill(l)}))),n.add(a.toDisposable(s.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})})))})}))}_onApplyTypeChanged(){this.disposeWithMe(a.toDisposable(this._autoFillService.applyType$.subscribe(()=>{this._handleFillData()})))}_triggerAutoFill(n,t){var d;if(n.startColumn===t.startColumn&&n.startRow===t.startRow&&n.endColumn===t.endColumn&&n.endRow===t.endRow)return;if(t.endColumn<n.endColumn&&t.endColumn>n.startColumn){this._commandService.executeCommand(cn.id,{clearRange:{startRow:t.startRow,endRow:t.endRow,startColumn:t.endColumn+1,endColumn:n.endColumn},selectionRange:t});return}if(t.endRow<n.endRow&&t.endRow>n.startRow){this._commandService.executeCommand(cn.id,{clearRange:{startRow:t.endRow+1,endRow:n.endRow,startColumn:t.startColumn,endColumn:t.endColumn},selectionRange:t});return}const o={startRow:t.startRow,endRow:t.endRow,startColumn:t.startColumn,endColumn:t.endColumn};let r=null;if(t.startRow<n.startRow)r=a.Direction.UP,o.endRow=n.startRow-1;else if(t.endRow>n.endRow)r=a.Direction.DOWN,o.startRow=n.endRow+1;else if(t.startColumn<n.startColumn)r=a.Direction.LEFT,o.endColumn=n.startColumn-1;else if(t.endColumn>n.endColumn)r=a.Direction.RIGHT,o.startColumn=n.endColumn+1;else return;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),l=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._autoFillService.direction=r,this._autoFillService.autoFillLocation={source:n,target:o,unitId:s,subUnitId:l},this._autoFillService.getActiveHooks().forEach(u=>{var h;(h=u==null?void 0:u.onBeforeFillData)==null||h.call(u,{source:n,target:o,unitId:s,subUnitId:l},r)}),(d=this._autoFillService.menu.find(u=>u.value===re.SERIES))!=null&&d.disable?this._autoFillService.applyType=re.COPY:this._autoFillService.applyType=re.SERIES}_handleDbClickFill(n){const t=this._detectFillRange(n);t.endRow<=n.endRow||this._triggerAutoFill(n,t)}_detectFillRange(n){var m,_,S,f,v,M;const{startRow:t,endRow:o,startColumn:r,endColumn:s}=n,l=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!l)return n;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=o;if(r>0&&((_=c.getValue(t,r-1))==null?void 0:_.v)!=null){let R=t;for(;((S=c.getValue(R,r-1))==null?void 0:S.v)!=null&&R<d;)R+=1;h=R-1}else if(s<u&&((f=c.getValue(o,s+1))==null?void 0:f.v)!=null){let R=t;for(;((v=c.getValue(R,s+1))==null?void 0:v.v)!=null&&R<d;)R+=1;h=R-1}for(let R=o+1;R<=h;R++)for(let T=r;T<=s;T++)if(((M=c.getValue(R,T))==null?void 0:M.v)!=null){h=R-1;break}return{startColumn:r,endColumn:s,startRow:t,endRow:h}}_handleFillData(){const{source:n,target:t,unitId:o=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:r=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=this._autoFillService.autoFillLocation||{},s=this._autoFillService.direction;if(!n||!t)return;const l=a.Rectangle.union(n,t),c=this._autoFillService.applyType,d=this._autoFillService.getActiveHooks();this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,{selections:[{primary:{...l,actualRow:l.startRow,actualColumn:l.startColumn,endColumn:l.startColumn,endRow:l.startRow},range:{...l,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:r});const u=[],h=[];d.forEach(_=>{var v;const{undos:S,redos:f}=((v=_.onFillData)==null?void 0:v.call(_,{source:n,target:t,unitId:o,subUnitId:r},s,c))||{};S&&u.push(...S),f&&h.push(...f)}),h.every(_=>this._commandService.syncExecuteCommand(_.id,_.params))&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:u,redoMutations:h}),d.forEach(_=>{var S;(S=_.onAfterFillData)==null||S.call(_,{source:n,target:t,unitId:o,subUnitId:r},s,c)}),this._autoFillService.setShowMenu(!0)}_getApplyData(n,t,o,r,s,l=!0){const c=[],d=Math.floor(o/t),u=o%t,h=this._autoFillService.getRules();if(!l&&s===re.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(_=>{m[_.type]=[]}),h.forEach(_=>{const{type:S,applyFunctions:f={}}=_,v=n[S];v&&v.forEach(M=>{const R=ms(M.index,u),T=M.index.length*d+R,E=this._applyFunctions(M,T,r,s,f,n),w=_s(t,o,M.index);m[S].push({data:E,index:w})})});for(let _=0;_<o;_++)h.forEach(S=>{const{type:f}=S,v=m[f];for(let M=0;M<v.length;M++)_ in v[M].index&&c.push(v[M].data[v[M].index[_]])});return c}_applyFunctions(n,t,o,r,s,l){const{data:c}=n,d=o===a.Direction.UP||o===a.Direction.LEFT;if(r===re.COPY){const u=s==null?void 0:s[re.COPY];return u?u(n,t,o,l):(d&&c.reverse(),et(c,t))}if(r===re.SERIES){const u=s==null?void 0:s[re.SERIES];return u?u(n,t,o,l):(d&&c.reverse(),s!=null&&s[re.COPY]?s[re.COPY](n,t,o,l):et(c,t))}if(r===re.ONLY_FORMAT){const u=s==null?void 0:s[re.ONLY_FORMAT];return u?u(n,t,o,l):Ss(c,t)}}_getCopyData(n,t){const{startRow:o,startColumn:r,endRow:s,endColumn:l}=n,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=t===a.Direction.DOWN||t===a.Direction.UP;let m,_,S,f;h?(m=r,_=l,S=o,f=s):(m=o,_=s,S=r,f=l);for(let v=m;v<=_;v++){const M=this._getEmptyCopyDataPiece(),R={type:void 0,cellData:void 0};for(let T=S;T<=f;T++){let E;h?E=c.getValue(T,v):E=c.getValue(v,T);const{type:w,isContinue:y}=d.find(O=>O.match(E))||ir;if(y(R,E)){const O=M[w],x=O[O.length-1];x.data.push(E),x.index.push(T-S)}else{const O=M[w];O?O.push({data:[E],index:[T-S]}):M[w]=[{data:[E],index:[T-S]}]}R.type=w,R.cellData=E}u.push(M)}return u}_getEmptyCopyDataPiece(){const n={};return this._autoFillService.getRules().forEach(t=>{n[t.type]=[]}),n}_getMergeApplyData(n,t,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),l=[];for(let c=n.startRow;c<=n.endRow;c++)for(let d=n.startColumn;d<=n.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:_,endColumn:S}=b.getCellInfoInMergeData(c,d,s);if(u){if(o===a.Direction.DOWN){let f=h+r,v=_+r;for(;v<=t.endRow;)l.push({startRow:f,startColumn:m,endRow:v,endColumn:S}),f+=r,v+=r}else if(o===a.Direction.UP){let f=h-r,v=_-r;for(;f>=t.startRow;)l.push({startRow:f,startColumn:m,endRow:v,endColumn:S}),f-=r,v-=r}else if(o===a.Direction.RIGHT){let f=m+r,v=S+r;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:f,endRow:_,endColumn:v}),f+=r,v+=r}else if(o===a.Direction.LEFT){let f=m-r,v=S-r;for(;f>=t.startColumn;)l.push({startRow:h,startColumn:f,endRow:_,endColumn:v}),f-=r,v-=r}}}return l}_presetAndCacheData(n,t){const{source:o,target:r}=n,s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),l=[];for(let c=r.startRow;c<=r.endRow;c++){const d=[];for(let u=r.startColumn;u<=r.endColumn;u++)d.push(a.Tools.deepClone(s.getValue(c,u)));l.push(d)}this._beforeApplyData=l,this._copyData=this._getCopyData(o,t),this._hasSeries(this._copyData)?this._autoFillService.setDisableApplyType(re.SERIES,!1):this._autoFillService.setDisableApplyType(re.SERIES,!0)}_fillData(n,t,o){var ie,oe;const r=[],s=[];let l=!0;o===re.NO_FORMAT&&(l=!1,o=re.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=n;if(!c||!d||t==null)return{undos:r,redos:s};const{startRow:m,startColumn:_,endRow:S,endColumn:f}=c,{startRow:v,startColumn:M,endRow:R,endColumn:T}=d,E=this._copyData;let w;t===a.Direction.DOWN||t===a.Direction.UP?w=S-m+1:w=f-_+1;const y=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const X=R-v+1,G=[];for(let Q=M;Q<=T;Q++){const ce=E[Q-M],ae=this._getApplyData(ce,w,X,t,o,l);G.push(ae)}for(let Q=0;Q<G[0].length;Q++){const ce=[];for(let ae=0;ae<G.length;ae++)ce.push({s:null,...G[ae][Q]});y.push(ce)}}else{const X=T-M+1;for(let G=v;G<=R;G++){const Q=E[G-v],ce=this._getApplyData(Q,w,X,t,o,l),ae=[];for(let ge=0;ge<ce.length;ge++)ae.push({s:null,...ce[ge]});y.push(ae)}}let O=[];const x=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();l?(O=this._getMergeApplyData(c,d,t,w),y.forEach(X=>{X.forEach(G=>{G&&x&&x&&(G.s=x.getStyleByCell(G))})})):y.forEach((X,G)=>{X.forEach((Q,ce)=>{Q&&x&&(Q.s=x.getStyleByCell(this._beforeApplyData[G][ce])||null)})}),o===re.ONLY_FORMAT&&y.forEach((X,G)=>{X.forEach((Q,ce)=>{if(Q){const ae=this._beforeApplyData[G][ce]||{};Q.f=ae.f,Q.si=ae.si,Q.t=ae.t,Q.v=ae.v}})});const N={get:this._injector.get.bind(this._injector)},F=[],L=(oe=(ie=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:ie.getSheetBySheetId(h))==null?void 0:oe.getMergeData();L&&L.forEach(X=>{a.Rectangle.intersects(X,d)&&F.push(X)});const W={unitId:u,subUnitId:h,ranges:F},B=g.RemoveMergeUndoMutationFactory(N,W);s.push({id:g.RemoveWorksheetMergeMutation.id,params:W}),r.push({id:g.AddWorksheetMergeMutation.id,params:B});const z={subUnitId:h,unitId:u,cellValue:uo([d])},Y=g.SetRangeValuesUndoMutationFactory(N,z),J=this._sheetInterceptorService.onCommandExecute({id:g.ClearSelectionContentCommand.id});s.push({id:g.SetRangeValuesMutation.id,params:z},...J.redos),r.push(...J.undos,{id:g.SetRangeValuesMutation.id,params:Y});const j=new a.ObjectMatrix,{startRow:q,startColumn:se,endRow:$,endColumn:k}=d;for(let X=0;X<=$-q;X++)for(let G=0;G<=k-se;G++)y[X][G]&&j.setValue(X+q,G+se,y[X][G]);const U={subUnitId:h,unitId:u,cellValue:j.getMatrix()},Z=g.SetRangeValuesUndoMutationFactory(N,U);if(r.push({id:g.SetRangeValuesMutation.id,params:Z}),s.push({id:g.SetRangeValuesMutation.id,params:U}),O!=null&&O.length){const X=g.getAddMergeMutationRangeByType(O),G={unitId:u,subUnitId:h,ranges:X},Q=g.AddMergeUndoMutationFactory(N,G);r.push({id:g.RemoveWorksheetMergeMutation.id,params:Q}),s.push({id:g.AddWorksheetMergeMutation.id,params:G})}return{undos:r,redos:s}}_hasSeries(n){return n.some(t=>Object.keys(t).some(r=>{var s;return!!((s=t[r])!=null&&s.length&&![ue.OTHER,ue.FORMULA].includes(r))}))}},A.AutoFillController=_l([a.OnLifecycle(a.LifecycleStages.Steady,A.AutoFillController),Fe(0,a.IUniverInstanceService),Fe(1,Se),Fe(2,a.ICommandService),Fe(3,a.IUndoRedoService),Fe(4,Ft),Fe(5,be),Fe(6,D.Inject(g.SheetInterceptorService)),Fe(7,D.Inject(g.SelectionManagerService)),Fe(8,D.Inject(D.Injector))],A.AutoFillController);const or={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async i=>{var c;const n=(c=i.get(g.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(n!=null&&n.length))return!1;const t=i.get(a.ICommandService),l=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(Uo(l,n)){const d=i.get(I.IConfirmService),u=i.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(g.SetRowHiddenCommand.id),!0}},rr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async i=>{var c;const n=(c=i.get(g.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(n!=null&&n.length))return!1;const t=i.get(a.ICommandService),l=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(ko(l,n)){const d=i.get(I.IConfirmService),u=i.get(a.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(g.SetColHiddenCommand.id),!0}},fi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatBoldCommand.id):e.executeCommand(g.SetBoldCommand.id)}},pi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatItalicCommand.id):e.executeCommand(g.SetItalicCommand.id)}},vi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatUnderlineCommand.id):e.executeCommand(g.SetUnderlineCommand.id)}},Ci={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatStrikethroughCommand.id):e.executeCommand(g.SetStrikeThroughCommand.id)}},Sl={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatSubscriptCommand.id):!1}},gl={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(ee.SetInlineFormatSuperscriptCommand.id):!1}},sr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(ee.SetInlineFormatFontSizeCommand.id,e):n.executeCommand(g.SetFontSizeCommand.id,e)}},ar={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(ee.SetInlineFormatFontFamilyCommand.id,e):n.executeCommand(g.SetFontFamilyCommand.id,e)}},fn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,e)=>{const n=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?n.executeCommand(ee.SetInlineFormatTextColorCommand.id,e):n.executeCommand(g.SetTextColorCommand.id,e)}};function lr(i,e){return e.some(n=>fl(i,n))}function fl(i,e){const{startRow:n,startColumn:t,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(n,t,r,o);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==n||d!==t)&&i.cellHasValue(u))return l=!0,!1}),l}function cr(i,e,n,t){const o=[],r=[],s=n.getSheetId();return t.forEach(l=>{const c=pl(n,l),d={unitId:e,subUnitId:s,cellValue:c.getData()},u=g.SetRangeValuesUndoMutationFactory(i,d);o.push({id:g.SetRangeValuesMutation.id,params:u}),r.push({id:g.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function pl(i,e){const{startRow:n,startColumn:t,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(n,t,r,o),l=new a.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==n||d!==t)&&l.setValue(c,d,null)}),l}var vl=Object.defineProperty,Cl=Object.getOwnPropertyDescriptor,Il=(i,e,n,t)=>{for(var o=t>1?void 0:t?Cl(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&vl(e,n,o),o},Ii=(i,e)=>(n,t)=>e(n,t,i),ye=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(ye||{});const St=D.createIdentifier("univer.format-painter-service");let Mi=class extends a.Disposable{constructor(e,n,t){super();C(this,"status$");C(this,"_selectionFormat");C(this,"_markId",null);C(this,"_status$");this._selectionManagerService=e,this._univerInstanceService=n,this._markSelectionService=t,this._status$=new P.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}setStatus(e){e!==0&&this._getSelectionRangeFormat(),this._updateRangeMark(e),this._status$.next(e)}getStatus(){return this._status$.getValue()}_updateRangeMark(e){if(this._markSelectionService.removeAllShapes(),this._markId=null,e!==0){const n=this._selectionManagerService.getLast();if(n){const t=this._selectionManagerService.createCopyPasteSelection();e===2?this._markId=this._markSelectionService.addShape({...n,style:t}):this._markId=this._markSelectionService.addShape({...n,style:t},[g.SetRangeValuesMutation.id])}}}_getSelectionRangeFormat(){const e=this._selectionManagerService.getLast(),n=e==null?void 0:e.range;if(!n)return;const{startRow:t,endRow:o,startColumn:r,endColumn:s}=n,l=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(l==null?void 0:l.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=l.getStyles(),m=new a.ObjectMatrix;for(let _=t;_<=o;_++)for(let S=r;S<=s;S++){const f=d.getValue(_,S);m.setValue(_,S,h.getStyleByCell(f)||{});const{isMergedMainCell:v,...M}=b.getCellInfoInMergeData(_,S,u);v&&this._selectionFormat.merges.push({startRow:M.startRow,startColumn:M.startColumn,endRow:M.endRow,endColumn:M.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};Mi=Il([Ii(0,D.Inject(g.SelectionManagerService)),Ii(1,a.IUniverInstanceService),Ii(2,Ht)],Mi);const Ri={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(i,e)=>e?(i.get(St).setStatus(e.status),!0):!1},dr={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const n=i.get(St).getStatus();let t;return n!==ye.OFF?t=ye.OFF:t=ye.INFINITE,i.get(a.ICommandService).executeCommand(Ri.id,{status:t})}},bi={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const n=i.get(St).getStatus();let t;return n!==ye.OFF?t=ye.OFF:t=ye.ONCE,i.get(a.ICommandService).executeCommand(Ri.id,{status:t})}},ur={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,e)=>{const n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(g.SelectionManagerService),s=i.get(g.SheetInterceptorService),{styleValues:l,styleRange:c,mergeRanges:d,unitId:u=o.getCurrentUniverSheetInstance().getUnitId(),subUnitId:h=o.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=e,m=c?[c]:r.getSelectionRanges();if(!m||!m.length)return!1;const _=new a.ObjectMatrix;let S;if(a.Tools.isArray(l))for(let z=0;z<m.length;z++){const{startRow:Y,startColumn:J,endRow:j,endColumn:q}=m[z];for(let se=0;se<=j-Y;se++)for(let $=0;$<=q-J;$++)_.setValue(se+Y,$+J,l[se][$])}else if(a.isICellData(l))for(let z=0;z<m.length;z++){const{startRow:Y,startColumn:J}=m[z];_.setValue(Y,J,l)}else S=l;const f={subUnitId:h,unitId:u,cellValue:S!=null?S:_.getMatrix()},v=g.SetRangeValuesUndoMutationFactory(i,f);if(!s.fetchThroughInterceptors(g.INTERCEPTOR_POINT.PERMISSION)(null,{id:g.SetRangeValuesCommand.id,params:f}))return!1;const M=n.syncExecuteCommand(g.SetRangeValuesMutation.id,f),{undos:R,redos:T}=s.onCommandExecute({id:g.SetRangeValuesCommand.id,params:{...f,range:m}}),E=g.getAddMergeMutationRangeByType(d),w=o.getUniverSheetInstance(u).getSheetBySheetId(h),y=[],O=[],x=lr(w,E),N={unitId:u,subUnitId:h,ranges:E},F={unitId:u,subUnitId:h,ranges:E};y.push({id:g.RemoveWorksheetMergeMutation.id,params:N}),y.push({id:g.AddWorksheetMergeMutation.id,params:F});const L=g.RemoveMergeUndoMutationFactory(i,N),W=g.AddMergeUndoMutationFactory(i,F);if(O.push({id:g.RemoveWorksheetMergeMutation.id,params:W}),O.push({id:g.AddWorksheetMergeMutation.id,params:L}),x){const z=cr(i,u,w,E);y.unshift(...z.redos),O.push(...z.undos)}const B=await a.sequenceExecute([...T,...y],n);return M&&B.result?(t.pushUndoRedo({unitID:u,undoMutations:[{id:g.SetRangeValuesMutation.id,params:v},...R,...O],redoMutations:[{id:g.SetRangeValuesMutation.id,params:f},...T,...y]}),!0):!1}},pn={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,e)=>{const{type:n}=e||{},t=i.get(a.IUniverInstanceService),o=i.get(a.IUndoRedoService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),l=i.get(a.ICommandService),d=i.get(g.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(Je),{sheetViewStartRow:_=0,sheetViewStartColumn:S=0}=m.getCurrentScroll()||{};let f,v,M,R;const{startRow:T,startColumn:E,rangeType:w}=h;if(w===a.RANGE_TYPE.ROW||n===1)f=T,M=T-_,v=-1,R=0;else if(w===a.RANGE_TYPE.COLUMN||n===2)f=-1,M=0,v=E,R=E-S;else if(w===a.RANGE_TYPE.NORMAL)f=T,M=T-_,v=E,R=E-S;else return!1;const y={unitId:r,subUnitId:s,startRow:f,startColumn:v,xSplit:v>0?Math.max(1,R):R,ySplit:f>0?Math.max(1,M):M},O=g.SetFrozenMutationFactory(i,y);return l.syncExecuteCommand(g.SetFrozenMutation.id,y)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:g.SetFrozenMutation.id,params:O}],redoMutations:[{id:g.SetFrozenMutation.id,params:y}]}),!0}},hr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(pn.id,{type:1}),!0)},mr={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(pn.id,{type:2}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(a.IUndoRedoService),o=n.getCurrentUniverSheetInstance().getUnitId(),r=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},l=g.SetFrozenMutationFactory(i,s);return e.syncExecuteCommand(g.SetFrozenMutation.id,s)&&t.pushUndoRedo({unitID:o,undoMutations:[{id:g.SetFrozenMutation.id,params:l}],redoMutations:[{id:g.SetFrozenMutation.id,params:s}]}),!0}},gt="UI_PLUGIN_SHEETS",vn=`${gt}_COLOR_PICKER_COMPONENT`,Sr=`${gt}_FONT_FAMILY_COMPONENT`,gr=`${gt}_FONT_FAMILY_ITEM_COMPONENT`,fr=`${gt}_FONT_SIZE_COMPONENT`,wi=`${gt}_MENU_ITEM_INPUT_COMPONENT`,Ti={sheetsUiContextMenuInput:"univer-sheets-ui-context-menu-input",sheetsUiContextMenuInputContainer:"univer-sheets-ui-context-menu-input-container",sheetsUiContextMenuInputNumber:"univer-sheets-ui-context-menu-input-number"},Ml=i=>{const{prefix:e,suffix:n,value:t,onChange:o,min:r=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=i,l=K.useDependency(a.LocaleService),[c,d]=H.useState(),u=m=>{var _;d(m==null?void 0:m.toString()),o((_=m==null?void 0:m.toString())!=null?_:"")};H.useEffect(()=>{d(t)},[t]);function h(m){m.key==="Backspace"&&m.stopPropagation()}return p.jsxs("div",{className:Ti.sheetsUiContextMenuInput,children:[l.t(e),p.jsx("span",{className:Ti.sheetsUiContextMenuInputContainer,onClick:m=>m.stopPropagation(),children:p.jsx(_e.InputNumber,{className:Ti.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:h,onChange:u,min:r,max:s})}),l.t(n)]})};var de=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(de||{});function Rl(i){const e=i.get(St);return{id:bi.id,subId:dr.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",positions:[I.MenuPosition.TOOLBAR_START],activated$:new P.Observable(n=>{let t=!1;const o=e.status$.subscribe(r=>{t=r!==ye.OFF,n.next(t)});return n.next(t),()=>{o.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function bl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(a.IContextService),o=i.get(g.SelectionManagerService);return{id:fi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=o.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let _=a.FontWeight.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);_=S==null?void 0:S.getFontWeight()}r.next(_===a.FontWeight.BOLD)}if((c===ee.SetTextSelectionsOperation.id||c===ee.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.bl;r.next(m===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function wl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:pi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let _=a.FontItalic.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);_=S==null?void 0:S.getFontStyle()}r.next(_===a.FontItalic.ITALIC)}if((c===ee.SetTextSelectionsOperation.id||c===ee.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.it;r.next(m===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function Tl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:vi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let _;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);_=S==null?void 0:S.getUnderline()}r.next(!!(_&&_.s))}if((c===ee.SetTextSelectionsOperation.id||c===ee.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.ul;r.next((m==null?void 0:m.s)===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function El(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService);return{id:Ci.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[I.MenuPosition.TOOLBAR_START],disabled$:g.getCurrentSheetDisabled$(i),activated$:new P.Observable(r=>{const s=e.onCommandExecuted(l=>{var d,u;const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id){const h=(d=t.getLast())==null?void 0:d.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let _;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);_=S==null?void 0:S.getStrikeThrough()}r.next(!!(_&&_.s))}if((c===ee.SetTextSelectionsOperation.id||c===ee.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const h=jt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.st;r.next((m==null?void 0:m.s)===a.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function yl(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:ar.id,tooltip:"toolbar.font",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,label:Sr,positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_FAMILY_LIST.map(o=>({label:{name:gr,hoverable:!0},value:o.value})),disabled$:g.getCurrentSheetDisabled$(i),value$:new P.Observable(o=>{const r=I.FONT_FAMILY_LIST[0].value,s=e.onCommandExecuted(l=>{var m;const c=l.id;if(c!==g.SetRangeValuesMutation.id&&c!==g.SetSelectionsOperation.id)return;const d=(m=t.getLast())==null?void 0:m.primary,u=n.getCurrentUniverSheetInstance().getActiveSheet();let h;if(d!=null){const _=u.getRange(d.startRow,d.startColumn);h=_==null?void 0:_.getFontFamily()}o.next(h!=null?h:r)});return o.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function Ol(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService),o=i.get(a.IContextService),r=g.getCurrentSheetDisabled$(i);return{id:sr.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:fr,props:{min:1,max:400,disabled$:r}},positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_SIZE_LIST,disabled$:r,value$:new P.Observable(s=>{const c=e.onCommandExecuted(d=>{var h,m;const u=d.id;if(u===g.SetRangeValuesMutation.id||u===g.SetSelectionsOperation.id){const _=(h=t.getLast())==null?void 0:h.primary,S=n.getCurrentUniverSheetInstance().getActiveSheet();let f;if(_!=null){const v=S.getRange(_.startRow,_.startColumn);f=v==null?void 0:v.getFontSize()}s.next(f!=null?f:14)}if((u===ee.SetTextSelectionsOperation.id||u===ee.SetInlineFormatCommand.id)&&o.getContextValue(a.EDITOR_ACTIVATED)&&o.getContextValue(a.FOCUSING_SHEET)){const _=jt(i);if(_==null)return;const S=(m=_.ts)==null?void 0:m.fs;s.next(S!=null?S:14)}});return s.next(14),c.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function xl(i){return{id:g.ResetTextColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:fn.id,disabled$:g.getCurrentSheetDisabled$(i)}}function Al(i){const e=i.get(a.ICommandService),n=i.get(a.ThemeService);return{id:fn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:vn,hoverable:!1}}],value$:new P.Observable(t=>{const o=n.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===fn.id){const l=s.params.value;t.next(l!=null?l:o)}});return t.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function Nl(i){return{id:g.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:g.SetBackgroundColorCommand.id,disabled$:g.getCurrentSheetDisabled$(i)}}function Dl(i){const e=i.get(a.ICommandService),n=i.get(a.ThemeService);return{id:g.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:vn,hoverable:!1}}],value$:new P.Observable(t=>{const o=n.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===g.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:o)}});return t.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const pr=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function Pl(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);return{id:g.SetHorizontalTextAlignCommand.id,icon:pr[0].icon,positions:[I.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:pr,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetHorizontalTextAlignCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}t.next(d!=null?d:a.HorizontalAlign.LEFT)});return t.next(a.HorizontalAlign.LEFT),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const vr=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function Hl(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);return{id:g.SetVerticalTextAlignCommand.id,icon:vr[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:vr,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetVerticalTextAlignCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getVerticalAlignment()}t.next(d!=null?d:a.VerticalAlign.TOP)});return t.next(a.VerticalAlign.TOP),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const Cr=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function Ll(i){const e=i.get(g.SelectionManagerService),n=i.get(a.IUniverInstanceService);return{id:g.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:Cr[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:Cr,value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==g.SetTextWrapCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=e.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getWrapStrategy()}t.next(d!=null?d:a.WrapStrategy.OVERFLOW)});return t.next(a.WrapStrategy.OVERFLOW),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}const Ir=[{label:"textRotate.none",icon:"NoRotationSingle",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesSingle",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesSingle",value:45},{label:"textRotate.vertical",icon:"VerticalTextSingle",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesSingle",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesSingle",value:90}];function Ul(i){const e=i.get(g.SelectionManagerService),n=i.get(a.IUniverInstanceService);return{id:g.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Ir[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:Ir,positions:[I.MenuPosition.TOOLBAR_START],value$:new P.Observable(t=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u,h;const s=r.id;if(s!==g.SetTextRotationCommand.id&&s!==g.SetSelectionsOperation.id)return;const l=(u=e.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const m=c.getRange(l.startRow,l.startColumn);d=m==null?void 0:m.getTextRotation()}(d==null?void 0:d.v)===a.BooleanNumber.TRUE?t.next("v"):t.next((h=d&&d.a)!=null?h:0)});return t.next(0),o.dispose}),hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:g.getCurrentSheetDisabled$(i)}}function ft(i){return new P.Observable(e=>e.next(!i.get(I.IClipboardInterfaceService).supportClipboard))}function kl(){return{id:I.CopyCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Vl(i){return{id:I.PasteCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:ft(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const pt="sheet.menu.paste-special";function Bl(i){return{id:pt,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",disabled$:ft(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Fl(i){return{id:xo.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[pt],disabled$:ft(i)}}function Wl(i){return{id:Ao.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[pt],disabled$:ft(i)}}function jl(i){return{id:No.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[pt],disabled$:ft(i)}}function zl(i){return{id:Do.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[pt],disabled$:ft(i)}}function Yl(){return{id:g.SetWorksheetRowIsAutoHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Wt="sheet.menu.sheet-frozen";function Xl(){return{id:Wt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[I.MenuPosition.CONTEXT_MENU]}}const Ei="sheet.header-menu.sheet-frozen";function $l(){return{id:Ei,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function Zl(){return{id:pn.id,type:I.MenuItemType.BUTTON,positions:[Wt,Ei],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function Gl(){return{id:hr.id,type:I.MenuItemType.BUTTON,positions:[Wt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function Kl(){return{id:mr.id,type:I.MenuItemType.BUTTON,positions:[Wt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function Jl(){return{id:_r.id,type:I.MenuItemType.BUTTON,positions:[Wt,Ei],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function Ql(){return{id:or.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function ql(){return{id:rr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function ec(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);function t(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=n.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.ROW);return!!(s!=null&&s.some(c=>{for(let d=c.startRow;d<=c.endRow;d++)if(!r.getRowVisible(d))return!0;return!1}))}const o=i.get(a.ICommandService);return{id:g.SetSelectedRowsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new P.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===g.SetSelectionsOperation.id||l.id===g.SetRowHiddenMutation.id||l.id===g.SetRowVisibleMutation.id)&&r.next(!t())});return r.next(!t()),()=>s.dispose()})}}function tc(i){const e=i.get(a.IUniverInstanceService),n=i.get(g.SelectionManagerService);function t(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=n.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.COLUMN);return!s||s.length===0?!1:!!s.some(c=>{for(let d=c.startColumn;d<=c.endColumn;d++)if(!r.getColVisible(d))return!0;return!1})}const o=i.get(a.ICommandService);return{id:g.SetSelectedColsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new P.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===g.SetSelectionsOperation.id||l.id===g.SetColHiddenMutation.id||l.id===g.SetColVisibleMutation.id)&&r.next(!t())});return r.next(!t()),()=>s.dispose()})}}function nc(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:g.SetRowHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:wi,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:new P.Observable(o=>{function r(){var u;const l=(u=t.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d;l!=null&&(d=c.getRowHeight(l.startRow)),o.next(d!=null?d:0)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function ic(i){const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),t=i.get(g.SelectionManagerService);return{id:g.SetColWidthCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:wi,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:new P.Observable(o=>{function r(){var u;const l=(u=t.getLast())==null?void 0:u.primary,c=n.getCurrentUniverSheetInstance().getActiveSheet();let d=0;l!=null&&(d=c.getColumnWidth(l.startColumn)),o.next(d)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===g.SetRangeValuesMutation.id||c===g.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function jt(i){var c;const e=i.get(a.IUniverInstanceService),n=i.get(ee.TextSelectionManagerService),t=e.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=n.getActiveRange();if(t==null||o==null)return;const r=(c=t.getBody())==null?void 0:c.textRuns;if(r==null)return;const{startOffset:s}=o;return r.find(({st:d,ed:u})=>s>=d&&s<u)}function ve(i,e){const t=i.getCurrentUniverSheetInstance().getUnitId(),o=e.getRenderById(t);if(o==null)return;const{components:r,mainComponent:s,scene:l,engine:c}=o,d=s,u=r.get(fe.ROW),h=r.get(fe.COLUMN),m=r.get(fe.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:l,engine:c}}function yi(i,e,n,t){const{startX:o,startY:r,endX:s,endY:l}=t.getCellByIndex(i,e);return{startX:o,startY:r,endX:s,endY:l}}function vt(i,e,n,t,o){const r=n.getRelativeCoord(b.Vector2.FromArray([i,e])),{x:s,y:l}=r,c=n.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=n.getAncestorScale(),h=t.getCellPositionByOffset(s,l,d,u,c),{row:m,column:_}=h,S=t.getNoMergeCellPositionByIndex(m,_),{startX:f,startY:v,endX:M,endY:R}=S;return{startX:f,startY:v,endX:M,endY:R,row:m,column:_}}function Cn(i,e,n,t){const o=n.getRelativeCoord(b.Vector2.FromArray([i,e])),r=n.getViewport(V.VIEW_MAIN),s=n.getScrollXYByRelativeCoords(o,r),{scaleX:l,scaleY:c}=n.getAncestorScale(),{x:d,y:u}=s,h=i/l+d,m=e/c+u;return{x:h,y:m}}const oc={spreadsheetLabel:"Spreadsheet",spreadsheetRightLabel:"more Sheets",toolbar:{undo:"Undo",redo:"Redo",formatPainter:"Paint format",currencyFormat:"Format as currency",percentageFormat:"Format as percent",numberDecrease:"Decrease decimal places",numberIncrease:"Increase decimal places",moreFormats:"More formats",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",customColor:"CUSTOM",alternatingColors:"Alternating colors",confirmColor:"OK",cancelColor:"Cancel",collapse:"Collapse",fillColor:{main:"Fill color",right:"Choose color"},border:{main:"Border",right:"Border style"},mergeCell:{main:"Merge cells",right:"Choose merge type"},horizontalAlignMode:{main:"Horizontal align",right:"Alignment"},verticalAlignMode:{main:"Vertical align",right:"Alignment"},textWrapMode:{main:"Text wrap",right:"Text wrap mode"},textRotateMode:{main:"Text rotate",right:"Text rotate mode"},freezeTopRow:"Freeze top row",sortAndFilter:"Sort and filter",findAndReplace:"Find and replace",sum:"SUM",autoSum:"Auto SUM",moreFunction:"More functions",conditionalFormat:"Conditional format",comment:"Comment",pivotTable:"Pivot Table",chart:"Chart",screenshot:"Screenshot",splitColumn:"Split text",insertImage:"Insert image",insertLink:"Insert link",dataValidation:"Data validation",protection:"Protect the sheet",clearText:"Clear color",noColorSelectedText:"No color is selected",toolMore:"More",toolLess:"Less",toolClose:"Close",toolMoreTip:"More features",moreOptions:"More options",cellFormat:"Cell format config",print:"Print",borderMethod:{top:"Upper frame line",bottom:"Lower frame line",left:"Left frame line",right:"Right frame line"},more:"More"},defaultFmt:{Automatic:{text:"Automatic",value:"General",example:""},Number:{text:"Number",value:"##0.00",example:"1000.12"},Percent:{text:"Percent",value:"#0.00%",example:"12.21%"},PlainText:{text:"Plain text",value:"@",example:""},Scientific:{text:"Scientific",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"Accounting",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"Ten Thousand",value:"w",example:"1亿2000万2500"},Currency:{text:"Currency",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"Date",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"Time",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"Time 24H",value:"hh:mm",example:"15:00"},DateTime:{text:"Date time",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"Date time 24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"Custom Formats",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"More currency formats",moreDateTime:"More date and time formats",moreNumber:"More number formats",titleCurrency:"Currency formats",decimalPlaces:"Decimal places",titleDateTime:"Date and time formats",titleNumber:"Number formats"},print:{normalBtn:"Normal",layoutBtn:"Page Layout",pageBtn:"Page break preview",menuItemPrint:"Print (Ctrl+P)",menuItemAreas:"Print areas",menuItemRows:"Print title rows",menuItemColumns:"Print title columns"},align:{left:"left",center:"center",right:"right",top:"top",middle:"middle",bottom:"bottom"},dateFmtList:[{name:"1930-08-05",value:"yyyy-MM-dd"},{name:"1930/8/5",value:"yyyy/MM/dd"},{name:"08-05",value:"MM-dd"},{name:"8-5",value:"M-d"},{name:"13:30:30",value:"h:mm:ss"},{name:"13:30",value:"h:mm"},{name:"PM 01:30",value:"AM/PM hh:mm"},{name:"PM 1:30",value:"AM/PM h:mm"},{name:"PM 1:30:30",value:"AM/PM h:mm:ss"},{name:"08-05 PM 01:30",value:"MM-dd AM/PM hh:mm"}],numFmtList:[{name:"1235",value:"0"},{name:"1234.56",value:"0.00"},{name:"1,235",value:"#,##0"},{name:"1,234.56",value:"#,##0.00"},{name:"1,235",value:"#,##0_);(#,##0)"},{name:"1,235",value:"#,##0_);[Red](#,##0)"},{name:"1,234.56",value:"#,##0.00_);(#,##0.00)"},{name:"1,234.56",value:"#,##0.00_);[Red](#,##0.00)"},{name:"$1,235",value:"$#,##0_);($#,##0)"},{name:"$1,235",value:"$#,##0_);[Red]($#,##0)"},{name:"$1,234.56",value:"$#,##0.00_);($#,##0.00)"},{name:"$1,234.56",value:"$#,##0.00_);[Red]($#,##0.00)"},{name:"1234.56",value:"@"},{name:"123456%",value:"0%"},{name:"123456.00%",value:"0.00%"},{name:"1.23E+03",value:"0.00E+00"},{name:"1.2E+3",value:"##0.0E+0"},{name:"1234 5/9",value:"# ?/?"},{name:"1234 14/25",value:"# ??/??"},{name:"$ 1,235",value:'_($* #,##0_);_(...($* "-"_);_(@_)'},{name:"1,235",value:'_(* #,##0_);_(*..._(* "-"_);_(@_)'},{name:"$ 1,234.56",value:'_($* #,##0.00_);_(...($* "-"_);_(@_)'},{name:"1,234.56",value:'_(* #,##0.00_);...* "-"??_);_(@_)'}],button:{confirm:"OK",cancel:"Cancel",close:"Close",update:"Update",delete:"Delete",insert:"Insert",prevPage:"Previous",nextPage:"Next",total:"total:"},punctuation:{tab:"Tab",semicolon:"semicolond",comma:"comma",space:"space"},colorPicker:{collapse:"Collapse",customColor:"CUSTOM",change:"Change",confirmColor:"OK",cancelColor:"Cancel"},borderLine:{borderTop:"borderTop",borderBottom:"borderBottom",borderLeft:"borderLeft",borderRight:"borderRight",borderNone:"borderNone",borderAll:"borderAll",borderOutside:"borderOutside",borderInside:"borderInside",borderHorizontal:"borderHorizontal",borderVertical:"borderVertical",borderColor:"borderColor",borderSize:"borderSize",borderType:"borderType"},merge:{all:"Merge all",vertical:"Vertical merge",horizontal:"Horizontal merge",cancel:"Cancel merge",overlappingError:"Cannot merge overlapping areas",partiallyError:"Cannot perform this operation on partially merged cells",confirm:{title:"Continue merging would only keep the upper-left cell value, discard other values. Are you sure to continue?",cancel:"Cancel merging",confirm:"Continue merging",waring:"Waring",dismantleMergeCellWaring:"This will cause some merged cells to be split. Do you want to continue?"}},textWrap:{overflow:"Overflow",wrap:"Wrap",clip:"Clip"},textRotate:{none:"None",angleUp:"Tilt Up",angleDown:"Tilt Down",vertical:"Stack Vertically",rotationUp:"Rotate Up",rotationDown:"Rotate Down"},sheetConfig:{delete:"Delete",copy:"Copy",rename:"Rename",changeColor:"Change color",hide:"Hide",unhide:"Unhide",moveLeft:"Move left",moveRight:"Move right",resetColor:"Reset color",cancelText:"Cancel",chooseText:"Confirm color",tipNameRepeat:"The name of the tab page cannot be repeated! Please revise",noMoreSheet:"The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.",confirmDelete:"Are you sure to delete",redoDelete:"Can be undo by Ctrl+Z",noHide:"Can't hide, at least keep one sheet tag",chartEditNoOpt:"This operation is not allowed in chart editing mode!",sheetNameErrorTitle:"There was a problem",sheetNameSpecCharError:`The name cannot contain:[ ] : ? * / ' "`,sheetNameCannotIsEmptyError:"The sheet name cannot be empty.",sheetNameAlreadyExistsError:"The sheet name already exists. Please enter another name.",deleteSheet:"Delete worksheet",deleteSheetContent:"Confirm to delete this worksheet. It will not be retrieved after deletion. Are you sure you want to delete it?"},rightClick:{copy:"Copy",copyAs:"Copy as",cut:"Cut",paste:"Paste",pasteSpecial:"Paste Special",pasteValue:"Paste Value",pasteFormat:"Paste Format",pasteColWidth:"Paste Column Width",pasteBesidesBorder:"Paste Besides Border Styles",insert:"Insert",insertRow:"Insert Row",insertRowBefore:"Insert Row Before",insertColumn:"Insert Column",insertColumnBefore:"Insert Column Before",delete:"Delete",deleteCell:"Delete Cell",insertCell:"Insert Cell",deleteSelected:"Delete Selected ",hide:"Hide",hideSelected:"Hide Selected ",showHide:"Show Hidden",toTopAdd:"Towards Top Add",toBottomAdd:"Towards Bottom Add",toLeftAdd:"Towards Left Add",toRightAdd:"Towards Right Add",deleteSelectedRow:"Delete Selected row",deleteSelectedColumn:"Delete Selected column",hideSelectedRow:"Hide Selected Row",showHideRow:"Show Selected Row",rowHeight:"Row Height",hideSelectedColumn:"Hide Selected Column",showHideColumn:"Show Hide Column",columnWidth:"Column Width",to:"Towards",left:"Left",right:"Right",top:"Top",bottom:"Bottom",moveLeft:"Move Left",moveUp:"Move up",moveRight:"Move Right",moveDown:"Move Down",add:"Add",row:"Row",column:"Column",width:"Width",height:"Height",number:"Number",confirm:"Confirm",orderAZ:"A-Z order",orderZA:"Z-A order",clearSelection:"Clear",clearContent:"Clear Contents",clearFormat:"Clear Formats",clearAll:"Clear All",matrix:"Matrix operation",sortSelection:"Sort",filterSelection:"Filter",chartGeneration:"Create Chart",firstLineTitle:"First Line Title",untitled:"Untitled",array1:"One-dimensional array",array2:"Two-dimensional array",array3:"Multidimensional Arrays",diagonal:"Diagonal",antiDiagonal:"Anti-diagonal",diagonalOffset:"Diagonal offset",offset:"Offset",boolean:"Boolean",flip:"Flip",upAndDown:"Up and down",leftAndRight:"Left and right",clockwise:"Clockwise",counterclockwise:"Counterclockwise",transpose:"Transpose",matrixCalculation:"Matrix Calculation",plus:"Plus",minus:"Minus",multiply:"Multiply",divided:"Divided",power:"Power",root:"Root",log:"Log",delete0:"Delete 0 values at both ends",removeDuplicate:"Remove duplicate values",byRow:"By row",byCol:"By column",generateNewMatrix:"Generate new matrix",fitContent:"Fit for data",freeze:"Freeze",freezeCol:"Freeze to this column",freezeRow:"Freeze to this row",cancelFreeze:"Cancel freeze",zenEditor:"Full Screen Editor",deleteAllRowsAlert:"You can't delete all the rows on the sheet",deleteAllColumnsAlert:"You can't delete all the columns on the sheet",hideAllRowsAlert:"You can't hide all the rows on the sheet",hideAllColumnsAlert:"You can't hide all the columns on the sheet"},info:{tooltip:"Tooltip",notChangeMerge:"You cannot make partial changes to the merged cells",detailUpdate:"New opened",detailSave:"Local cache restored",row:"",column:"",loading:"Loading...",copy:"Copy",return:"Exit",rename:"Rename",tips:"Rename",noName:"Untitled spreadsheet",wait:"waiting for update",add:"Add",addLast:"more rows at bottom",backTop:"Back to the top",pageInfo:"Total ${total},${totalPage} page,current ${currentPage}",nextPage:"Next",tipInputNumber:"Please enter the number",tipInputNumberLimit:"The increase range is limited to 1-100",tipRowHeightLimit:"Row height must be between 0 ~ 545",tipColumnWidthLimit:"The column width must be between 0 ~ 2038",pageInfoFull:"Total ${total},${totalPage} page,All data displayed",problem:"There was a problem"},clipboard:{paste:{exceedMaxCells:"The number of cells pasted exceeds the maximum number of cells"}},statusbar:{sum:"Sum",average:"Average",min:"Min",max:"Max",count:"Numerical Count",countA:"Count",clickToCopy:"Click to Copy",copied:"Copied"},autoFill:{copy:"Copy Cell",series:"Fill Series",formatOnly:"Format Only",noFormat:"No Format"},rangeSelector:{placeholder:"Select range or input value",tooltip:"Select range"},shortcut:{sheet:{"zoom-in":"Zoom in","zoom-out":"Zoom out","reset-zoom":"Reset zoom level","select-below-cell":"Select the cell below","select-up-cell":"Select the cell above","select-left-cell":"Select the left cell","select-right-cell":"Select the right cell","select-next-cell":"Select the next cell","select-previous-cell":"Select the previous cell","select-up-value-cell":"Select the cell above that has value","select-below-value-cell":"Select the cell below that has value","select-left-value-cell":"Select the cell left that has value","select-right-value-cell":"Select the cell right that has value","expand-selection-down":"Expand selection down","expand-selection-up":"Expand selection up","expand-selection-left":"Expand selection left","expand-selection-right":"Expand selection right","expand-selection-to-left-gap":"Expand selection to the left gap","expand-selection-to-below-gap":"Expand selection to the below gap","expand-selection-to-right-gap":"Expand selection to the right gap","expand-selection-to-up-gap":"Expand selection to the up gap","select-all":"Select all","toggle-editing":"Toggle editing","delete-and-start-editing":"Clear and start editing","abort-editing":"Abort editing","break-line":"Break line","set-bold":"Toggle bold","set-italic":"Toggle italic","set-underline":"Toggle underline","set-strike-through":"Toggle strike through"}},"sheet-view":"Sheet View","sheet-edit":"Sheet Edit"},Mr={spreadsheetLabel:"插件",spreadsheetRightLabel:"更多 Sheets",toolbar:{undo:"撤销",redo:"重做",formatPainter:"格式刷",currencyFormat:"货币格式",percentageFormat:"百分比格式",numberDecrease:"减少小数位数",numberIncrease:"增加小数位数",moreFormats:"更多格式",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",customColor:"自定义",alternatingColors:"交替颜色",confirmColor:"确定颜色",cancelColor:"取消",collapse:"收起",fillColor:{main:"单元格颜色",right:"颜色选择"},border:{main:"边框",right:"边框类型"},mergeCell:{main:"合并单元格",right:"选择合并类型"},horizontalAlignMode:{main:"水平对齐",right:"对齐方式"},verticalAlignMode:{main:"垂直对齐",right:"对齐方式"},textWrapMode:{main:"文本换行",right:"换行方式"},textRotateMode:{main:"文本旋转",right:"旋转方式"},freezeTopRow:"冻结首行",sortAndFilter:"排序和筛选",findAndReplace:"查找替换",sum:"求和",autoSum:"自动求和",moreFunction:"更多函数",conditionalalFormat:"条件格式",comment:"批注",pivotTable:"数据透视表",chart:"图表",screenshot:"截图",splitColumn:"分列",insertImage:"插入图片",insertLink:"插入链接",dataValidation:"数据验证",protection:"保护工作表内容",clearText:"清除颜色选择",noColorSelectedText:"没有颜色被选择",toolMore:"更多",toolLess:"少于",toolClose:"收起",toolMoreTip:"更多功能",moreOptions:"更多选项",cellFormat:"设置单元格格式",print:"打印",borderMethod:{top:"上框线",bottom:"下框线",left:"左框线",right:"右框线"},more:"更多"},defaultFmt:{Automatic:{text:"自动",value:"General",example:""},Number:{text:"数字",value:"##0.00",example:"1000.12"},Percent:{text:"百分比",value:"#0.00%",example:"12.21%"},PlainText:{text:"纯文本",value:"@",example:""},Scientific:{text:"科学计数",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"会计",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"万元",value:"w",example:"1亿2000万2500"},Currency:{text:"货币",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"日期",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"时间",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"时间24H",value:"hh:mm",example:"15:00"},DateTime:{text:"日期时间",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"日期时间24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"自定义格式",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"更多货币格式",moreDateTime:"更多日期与时间格式",moreNumber:"更多数字格式",titleCurrency:"货币格式",decimalPlaces:"小数位数",titleDateTime:"日期与时间格式",titleNumber:"数字格式"},print:{normalBtn:"常规视图",layoutBtn:"页面布局",pageBtn:"分页预览",menuItemPrint:"打印(Ctrl+P)",menuItemAreas:"打印区域",menuItemRows:"打印标题行",menuItemColumns:"打印标题列"},align:{left:"左对齐",center:"中间对齐",right:"右对齐",top:"顶部对齐",middle:"居中对齐",bottom:"底部对齐"},button:{confirm:"确定",cancel:"取消",close:"关闭",update:"Update",delete:"Delete",insert:"新建",prevPage:"上一页",nextPage:"下一页",total:"总共:"},punctuation:{tab:"Tab 键",semicolon:"分号",comma:"逗号",space:"空格"},colorPicker:{collapse:"收起",customColor:"自定义",change:"切换",confirmColor:"确定",cancelColor:"取消"},borderLine:{borderTop:"上框线",borderBottom:"下框线",borderLeft:"左框线",borderRight:"右框线",borderNone:"无",borderAll:"所有",borderOutside:"外侧",borderInside:"内侧",borderHorizontal:"内侧横线",borderVertical:"内侧竖线",borderColor:"边框颜色",borderSize:"边框粗细",borderType:"边框线类型"},merge:{all:"全部合并",vertical:"垂直合并",horizontal:"水平合并",cancel:"取消合并",overlappingError:"不能合并重叠区域",partiallyError:"无法对部分合并单元格执行此操作",confirm:{title:"合并单元格仅保存左上角单元格的值,是否继续?",cancel:"取消合并",confirm:"继续合并",waring:"警告",dismantleMergeCellWaring:"此操作会导致一些合并单元格被拆散,是否继续?"}},textWrap:{overflow:"溢出",wrap:"自动换行",clip:"截断"},textRotate:{none:"无旋转",angleUp:"向上倾斜",angleDown:"向下倾斜",vertical:"竖排文字",rotationUp:"向上90°",rotationDown:"向下90°"},sheetConfig:{delete:"删除",copy:"复制",rename:"重命名",changeColor:"更改颜色",hide:"隐藏",unhide:"取消隐藏",moveLeft:"向左移",moveRight:"向右移",resetColor:"重置颜色",cancelText:"取消",chooseText:"确定颜色",tipNameRepeat:"标签页的名称不能重复!请重新修改",noMoreSheet:"工作薄内至少含有一张可视工作表。若需删除选定的工作表,请先插入一张新工作表或显示一张隐藏的工作表。",confirmDelete:"是否删除",redoDelete:"可以通过Ctrl+Z撤销删除",noHide:"不能隐藏, 至少保留一个sheet标签",chartEditNoOpt:"图表编辑模式下不允许该操作!",sheetNameErrorTitle:"错误",sheetNameSpecCharError:`名称不能超过31个字符,首尾不能是' 且名称不能包含:\r
18
+ [ ] : \\ ? * /`,sheetNameCannotIsEmptyError:"名称不能为空。",sheetNameAlreadyExistsError:"工作表已存在,请输入其它名称。",deleteSheet:"删除工作表",deleteSheetContent:"确认删除此工作表,删除后将不可找回,确定要删除吗?"},rightClick:{copy:"复制",copyAs:"复制为",cut:"剪切",paste:"粘贴",pasteSpecial:"选择性粘贴",pasteValue:"仅粘贴值",pasteFormat:"仅粘贴格式",pasteColWidth:"仅粘贴列宽",pasteBesidesBorder:"仅粘贴边框以外内容",insert:"插入",delete:"删除",insertRow:"插入行",insertRowBefore:"在上方插入行",insertColumn:"插入列",insertColumnBefore:"在左侧插入列",deleteCell:"删除单元格",insertCell:"插入单元格",deleteSelected:"删除选中",hide:"隐藏",hideSelected:"隐藏选中",showHide:"显示隐藏",toTopAdd:"向上增加",toBottomAdd:"向下增加",toLeftAdd:"向左增加",toRightAdd:"向右增加",deleteSelectedRow:"删除选中行",deleteSelectedColumn:"删除选中列",hideSelectedRow:"隐藏选中行",showHideRow:"显示隐藏行",rowHeight:"行高",hideSelectedColumn:"隐藏选中列",showHideColumn:"显示隐藏列",columnWidth:"列宽",to:"向",left:"左",right:"右",top:"上",bottom:"下",moveLeft:"左移",moveUp:"上移",moveRight:"右移",moveDown:"下移",add:"增加",row:"行",column:"列",width:"宽",height:"高",number:"数字",confirm:"确认",orderAZ:"A-Z顺序排列",orderZA:"Z-A降序排列",clearSelection:"清除",clearContent:"清除内容",clearFormat:"清除格式",clearAll:"清除全部",matrix:"矩阵操作选区",sortSelection:"排序选区",filterSelection:"筛选选区",chartGeneration:"图表生成",firstLineTitle:"首行为标题",untitled:"无标题",array1:"一维数组",array2:"二维数组",array3:"多维数组",diagonal:"对角线",antiDiagonal:"反对角线",diagonalOffset:"对角偏移",offset:"偏移量",boolean:"布尔值",flip:"翻转",upAndDown:"上下",leftAndRight:"左右",clockwise:"顺时针",counterclockwise:"逆时针",transpose:"转置",matrixCalculation:"矩阵计算",plus:"加",minus:"减",multiply:"乘",divided:"除",power:"次方",root:"次方根",log:"log",delete0:"删除两端0值",removeDuplicate:"删除重复值",byRow:"按行",byCol:"按列",generateNewMatrix:"生成新矩阵",fitContent:"适合数据",freeze:"冻结",freezeCol:"冻结列",freezeRow:"冻结行",cancelFreeze:"取消冻结",zenEditor:"禅模式编辑",deleteAllRowsAlert:"您无法删除工作表上的所有行",deleteAllColumnsAlert:"您无法删除工作表上的所有列",hideAllRowsAlert:"您无法隐藏工作表上的所有行",hideAllColumnsAlert:"您无法隐藏工作表上的所有列"},info:{tooltip:"提示",notChangeMerge:"不能对合并单元格做部分更改",detailUpdate:"新打开",detailSave:"已恢复本地缓存",row:"行",column:"列",loading:"渲染中···",copy:"副本",return:"返回",rename:"重命名",tips:"重命名",noName:"无标题的电子表格",wait:"待更新",add:"添加",addLast:"在底部添加",backTop:"回到顶部",pageInfo:"共${total}条,${totalPage}页,当前已显示${currentPage}页",nextPage:"下一页",tipInputNumber:"请输入数字",tipInputNumberLimit:"增加范围限制在1-100",tipRowHeightLimit:"行高必须在0 ~ 545之间",tipColumnWidthLimit:"列宽必须在0 ~ 2038之间",pageInfoFull:"共${total}条,${totalPage}页,已显示全部数据",problem:"出现了一个问题"},clipboard:{paste:{exceedMaxCells:"粘贴区域超出最大单元格数"}},statusbar:{sum:"求和",average:"平均值",min:"最小值",max:"最大值",count:"数值计数",countA:"计数",clickToCopy:"点击复制数值",copied:"已复制"},autoFill:{copy:"复制单元格",series:"填充序列",formatOnly:"仅填充格式",noFormat:"不带格式填充"},rangeSelector:{placeholder:"选择范围或输入值",tooltip:"选择范围"},shortcut:{sheet:{"zoom-in":"放大","zoom-out":"缩小","reset-zoom":"恢复缩放","select-below-cell":"选择下方单元格","select-up-cell":"选择上方单元格","select-left-cell":"选择左侧单元格","select-right-cell":"选择右侧单元格","select-next-cell":"选择后一个单元格","select-previous-cell":"选择前一个单元格","select-up-value-cell":"选择上方有值的单元格","select-below-value-cell":"选择下方有值的单元格","select-left-value-cell":"选择左侧有值的单元格","select-right-value-cell":"选择右侧有值的单元格","expand-selection-down":"向下扩展选区","expand-selection-up":"向上扩展选区","expand-selection-left":"向左扩展选区","expand-selection-right":"向右扩展选区","expand-selection-to-left-gap":"向左扩展选区到下一个边界","expand-selection-to-below-gap":"向下扩展选区到下一个边界","expand-selection-to-right-gap":"向右扩展选区到下一个边界","expand-selection-to-up-gap":"向上扩展选区到下一个边界","select-all":"全选","toggle-editing":"开始 / 结束编辑","delete-and-start-editing":"清空并开始编辑","abort-editing":"放弃编辑","break-line":"换行","set-bold":"切换粗体","set-italic":"切换斜体","set-underline":"切换下划线","set-strike-through":"切换删除线"}},"sheet-view":"浏览表格","sheet-edit":"编辑表格"},rc=(i,e,n=!1)=>{const t=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=t(e)%t(i),s=o(e)%o(i),l={startRow:0,endRow:t(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(t(e)/t(i)),d=Math.floor(o(e)/o(i)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let m=1;m<=d;m++){const _=t(i)*(h-1),S=o(i)*(m-1),f={startRow:_+e.startRow,endRow:_+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else if(!r&&s&&!n)for(let h=1;h<=c;h++){const m=t(i)*(h-1),_=0,S={startRow:m+e.startRow,endRow:m+e.startRow,startColumn:_+e.startColumn,endColumn:_+e.startColumn};u.push({repeatRelativeRange:l,startRange:S})}else if(r&&!s&&!n)for(let h=1;h<=d;h++){const _=o(i)*(h-1),S={startRow:0+e.startRow,endRow:0+e.startRow,startColumn:_+e.startColumn,endColumn:_+e.startColumn};u.push({repeatRelativeRange:l,startRange:S})}else{const h={startRow:e.startRow,endRow:e.startRow,startColumn:e.startColumn,endColumn:e.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};class Rr{constructor(){C(this,"_state",null);C(this,"_rect",null);C(this,"_focus",!1);C(this,"_state$",new P.BehaviorSubject(null));C(this,"state$",this._state$.asObservable());C(this,"_rect$",new P.BehaviorSubject(null));C(this,"rect$",this._rect$.asObservable());C(this,"_focus$",new P.BehaviorSubject(this._focus));C(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(e){this._state=e,this._refresh(e)}getRect(){return this._rect}setRect(e){this._rect=e,this._rect$.next(e)}getState(){return this._state}setFocus(e=!1){this._focus=e,this._focus$.next(e)}_refresh(e){this._state$.next(e)}}const zt=D.createIdentifier("univer.sheet-cell-editor-manager.service");class sc{constructor(){C(this,"_position",null);C(this,"_position$",new P.BehaviorSubject(null));C(this,"position$",this._position$.asObservable());C(this,"_focus",!1);C(this,"_focus$",new P.BehaviorSubject(this._focus));C(this,"focus$",this._focus$.asObservable());C(this,"_fxBtnClick$",new P.BehaviorSubject(!1));C(this,"fxBtnClick$",this._fxBtnClick$.asObservable());C(this,"_foldBtnStatus$",new P.BehaviorSubject(!1));C(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(e){this._position=e,this._refresh(e)}getPosition(){return this._position}setFocus(e=!1){this._focus=e,this._focus$.next(e)}handleFxBtnClick(e){this._fxBtnClick$.next(e)}handleFoldBtnClick(e){this._foldBtnStatus$.next(e)}_refresh(e){this._position$.next(e)}}const In=D.createIdentifier("univer.sheet-formula-editor-manager.service");var ac=Object.defineProperty,lc=Object.getOwnPropertyDescriptor,cc=(i,e,n,t)=>{for(var o=t>1?void 0:t?lc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ac(e,n,o),o},br=(i,e)=>(n,t)=>e(n,t,i);let Mn=class extends a.Disposable{constructor(e,n){super();C(this,"_previousSheetIndex",-1);this._commandService=e,this._univerInstanceService=n,this.disposeWithMe(this._commandService.beforeCommandExecuted((t,o)=>{if(t.id===g.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(t)})),this.disposeWithMe(this._commandService.onCommandExecuted((t,o)=>{if(t.id===g.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===g.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(!(o!=null&&o.fromCollab)){if(t.id===g.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(t);if(t.id===g.SetWorksheetHideMutation.id&&!t.params.hidden)return this._adjustActiveSheetOnShowSheet(t)}}))}_adjustActiveSheetOnHideSheet(e){const{unitId:n,subUnitId:t}=e.params,o=this._univerInstanceService.getUniverSheetInstance(n);if(!o||o.getActiveSheet().getSheetId()!==t)return;const s=o.getActiveSheetIndex(),l=wr(o,s);this._switchToNextSheet(n,l)}_beforeAdjustActiveSheetOnRemoveSheet(e){const{unitId:n,subUnitId:t}=e.params,o=this._univerInstanceService.getUniverSheetInstance(n);if(!o)return;const r=o.getSheetBySheetId(t);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(e){if(this._previousSheetIndex===-1)return;const{unitId:n}=e.params,t=this._univerInstanceService.getUniverSheetInstance(n);if(!t||t.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,l=wr(t,s);this._switchToNextSheet(n,l)}_adjustActiveSheetOnInsertSheet(e){const{unitId:n,sheet:t}=e.params;this._switchToNextSheet(n,t.id)}_adjustActiveSheetOnShowSheet(e){const{unitId:n,subUnitId:t}=e.params;this._switchToNextSheet(n,t)}_switchToNextSheet(e,n){this._commandService.executeCommand(g.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:n})}};Mn=cc([a.OnLifecycle(a.LifecycleStages.Ready,Mn),br(0,a.ICommandService),br(1,a.IUniverInstanceService)],Mn);function wr(i,e){const n=i.getSheetSize();for(let t=e;t>-1;t--){const o=i.getSheetByIndex(t);if(!o.getConfig().hidden)return o.getSheetId()}for(let t=e;t<n;t++){const o=i.getSheetByIndex(t);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var dc=Object.defineProperty,uc=Object.getOwnPropertyDescriptor,hc=(i,e,n,t)=>{for(var o=t>1?void 0:t?uc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&dc(e,n,o),o},Yt=(i,e)=>(n,t)=>e(n,t,i);let Rn=class{constructor(i,e,n,t,o){this._injector=i,this._sheetInterceptorService=e,this._selectionManagerService=n,this._univerInstanceService=t,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e,_sheetSkeletonManagerService:n,_injector:t}=this,{skeleton:o}=n.getCurrent(),r=o.calculateAutoHeightInRange(i),s=e.getCurrentUniverSheetInstance(),l=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:l,rowsAutoHeightInfo:r},u=g.SetWorksheetRowAutoHeightMutationFactory(t,d);return{undos:[{id:g.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:g.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;i.interceptCommand({getMutations:n=>n.id!==g.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(n.params.range)}),i.interceptCommand({getMutations:n=>n.id!==g.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(n.params.ranges)}),i.interceptCommand({getMutations:n=>{var r;if(n.id!==g.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=n.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=e.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};Rn=hc([a.OnLifecycle(a.LifecycleStages.Ready,Rn),Yt(0,D.Inject(D.Injector)),Yt(1,D.Inject(g.SheetInterceptorService)),Yt(2,D.Inject(g.SelectionManagerService)),Yt(3,D.Inject(a.IUniverInstanceService)),Yt(4,D.Inject(A.SheetSkeletonManagerService))],Rn);var mc=Object.defineProperty,_c=Object.getOwnPropertyDescriptor,Sc=(i,e,n,t)=>{for(var o=t>1?void 0:t?_c(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&mc(e,n,o),o},Oe=(i,e)=>(n,t)=>e(n,t,i);let bn=class extends a.RxDisposable{constructor(i,e,n,t,o,r,s,l,c,d,u){var h;super(),this._injector=i,this._currentUniverSheet=e,this._commandService=n,this._contextService=t,this._configService=o,this._sheetClipboardService=r,this._clipboardInterfaceService=s,this._messageService=l,this._sheetSkeletonManagerService=c,this._localService=d,this._textSelectionRenderManager=u,this._init(),this._clipboardInterfaceService.supportClipboard||(h=this._textSelectionRenderManager)==null||h.onPaste$.pipe(P.takeUntil(this.dispose$)).subscribe(m=>{var v,M;if(!ne(this._contextService))return;m.event.preventDefault();const _=m.event,S=(v=_.clipboardData)==null?void 0:v.getData("text/html"),f=(M=_.clipboardData)==null?void 0:M.getData("text/plain");this._sheetClipboardService.legacyPaste(S,f)})}_init(){[Oo,ua,ht].forEach(e=>this.disposeWithMe(this._commandService.registerMultipleCommand(e))),[xo,Ao,No,Do].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initCopyingHooks())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initPastingHook()));const i=this._initSpecialPasteHooks().map(e=>this._sheetClipboardService.addClipboardHook(e));this.disposeWithMe({dispose:()=>i.forEach(e=>e.dispose())})}_initCopyingHooks(){const i=this;let e=null;return{id:pe.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(n,t){e=i._getWorksheet(n,t)},onCopyCellContent(n,t){const o=e.getCell(n,t);return`${(o==null?void 0:o.v)||""}`},onCopyCellStyle:(n,t,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=e.getRange(n,t).getTextStyle();let d="";return c&&(d=a.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(n){return{width:`${e.getColumnWidth(n)}`}},onCopyRow(n){return{style:`height: ${e.getRowHeight(n)}px;`}},onAfterCopy(){e=null}}}_initPastingHook(){const i=this;let e=null,n=null,t=null;return{id:pe.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste({unitId:o,subUnitId:r,range:s}){t=i._getWorksheet(o,r),e=o,n=r;const l=i._configService.getConfig(g.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return l&&c*d>l?(i._messageService.show({type:_e.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const{range:s}=o,l=[],c=t.getMaxRows(),d=s.endRow-c,u=r.length-d;if(d>0){const _={};r.slice(u).forEach((f,v)=>{const{style:M,height:R}=f||{};if(M){const T=M.split(";");let E=a.DEFAULT_WORKSHEET_ROW_HEIGHT;T.find(w=>{w=w.toLowerCase();const y=I.textTrim(w.substr(0,w.indexOf(":"))),O=I.textTrim(w.substr(w.indexOf(":")+1));return y==="height"?(E=Number.parseFloat(O),!0):!1}),_[v]={h:E,hd:a.BooleanNumber.FALSE}}else R&&(_[v]={h:Number.parseFloat(R),hd:a.BooleanNumber.FALSE})});const S={unitId:e,subUnitId:n,range:{...s,startRow:c},rowInfo:_};l.push({id:g.InsertRowMutation.id,params:S})}const h={};r.slice(0,u).forEach((_,S)=>{const{style:f,height:v}=_;if(f){const M=f.split(";");let R=a.DEFAULT_WORKSHEET_ROW_HEIGHT;M.find(T=>{T=T.toLowerCase();const E=I.textTrim(T.substr(0,T.indexOf(":"))),w=I.textTrim(T.substr(T.indexOf(":")+1));return E==="height"?(R=Number.parseFloat(w),!0):!1}),h[S+s.startRow]=R}else v&&(h[S+s.startRow]=Number.parseFloat(v))});const m={unitId:e,subUnitId:n,ranges:[{...s,endRow:Math.min(s.endRow,c)}],rowHeight:h};return l.push({id:g.SetWorksheetRowHeightMutation.id,params:m}),{redos:l,undos:[]}},onPasteColumns(o,r,s){var S;const{range:l}=o,c=[],d=t.getMaxColumns(),u=l.endColumn-d,h=r.length-u,m=(S=i._configService.getConfig(a.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?S:a.DEFAULT_WORKSHEET_COLUMN_WIDTH;if(u>0){const f={unitId:e,subUnitId:n,range:{...l,startColumn:d},colInfo:r.slice(h).map(v=>({w:v.width?+v.width:m,hd:a.BooleanNumber.FALSE}))};c.push({id:g.InsertColMutation.id,params:f})}const _={unitId:e,subUnitId:n,ranges:[{...l,endRow:Math.min(l.endColumn,d)}],colWidth:r.slice(0,h).map(f=>f.width?+f.width:m)};return c.push({id:g.SetWorksheetColWidthMutation.id,params:_}),{redos:c,undos:[]}},onPastePlainText(o,r,s){return i._onPastePlainText(o,r,s)},onPasteCells(o,r,s,l){return i._onPasteCells(o,r,s,l)},onAfterPaste(o){t=null}}}_generateDocumentDataModelSnapshot(i){var s;const e=this._sheetSkeletonManagerService.getCurrent();if(e==null)return null;const{skeleton:n}=e,t=(s=n.getBlankCellDocumentModel())==null?void 0:s.documentModel,r={...t==null?void 0:t.getSnapshot(),...i};return t==null||t.reset(r),t==null?void 0:t.getSnapshot()}_onPastePlainText(i,e,n){const{range:t,unitId:o,subUnitId:r}=i;let s;if(/\r|\n/.test(e)){const c=bo(e),d=this._generateDocumentDataModelSnapshot({body:c});s={[t.startRow]:{[t.startColumn]:{p:d}}}}else s={[t.startRow]:{[t.startColumn]:{v:e}}};const l={unitId:o,subUnitId:r,cellValue:s};return{redos:[{id:g.SetRangeValuesMutation.id,params:l}],undos:[{id:g.SetRangeValuesMutation.id,params:g.SetRangeValuesUndoMutationFactory(this._injector,l)}]}}_onPasteCells(i,e,n,t){const o={get:this._injector.get.bind(this._injector)};return Fs(i,e,n,t,o)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},e=this,n={id:pe.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,l,c,d)=>{const u=e._currentUniverSheet.getCurrentUniverSheetInstance();return u.getUnitId(),u.getActiveSheet().getSheetId(),Io(l,c,i)}},t={id:pe.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,l,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance();u.getUnitId(),u.getActiveSheet().getSheetId();const h=[],m=[],{undos:_,redos:S}=Ro(l,c,i);h.push(...S),m.push(..._);const{undos:f,redos:v}=si(l,c,i);h.push(...v),m.push(...f);const{undos:M,redos:R}=Mo(l,c,i);return h.push(...R),m.push(...M),{undos:m,redos:h}}},o={id:pe.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,l,c){var E;const d=e._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],_=e._getWorksheet(u,h),{range:S}=s,f=_.getMaxColumns(),v=S.endColumn-f,M=l.length-v,R=(E=e._configService.getConfig(a.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?E:a.DEFAULT_WORKSHEET_COLUMN_WIDTH,T={unitId:u,subUnitId:h,ranges:[{...S,endRow:Math.min(S.endColumn,f)}],colWidth:l.slice(0,M).map(w=>w.width?+w.width:R)};return m.push({id:g.SetWorksheetColWidthMutation.id,params:T}),m.push({id:g.SetWorksheetColWidthMutation.id,params:T}),{redos:m,undos:[]}}},r={id:pe.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,l,c,d){e._currentUniverSheet.getCurrentUniverSheetInstance();const u=[],h=[],{range:m,unitId:_,subUnitId:S}=l,{startColumn:f,startRow:v,endColumn:M,endRow:R}=m,T=new a.ObjectMatrix;c.forValue((x,N,F)=>{const L=F.s;typeof L=="object"&&T.setValue(x+v,N+f,{s:{...L,bd:void 0},v:F.v})});const E={unitId:_,subUnitId:S,cellValue:T.getData()};u.push({id:g.SetRangeValuesMutation.id,params:E});const w=g.SetRangeValuesUndoMutationFactory(i,E);h.push({id:g.SetRangeValuesMutation.id,params:w});const{undos:y,redos:O}=si(l,c,i);return h.push(...y),u.push(...O),{redos:u,undos:h}}};return[n,t,o,r]}_getWorksheet(i,e){var t;const n=(t=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:t.getSheetBySheetId(e);if(!n)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${e}.`);return n}};bn=Sc([a.OnLifecycle(a.LifecycleStages.Steady,bn),Oe(0,D.Inject(D.Injector)),Oe(1,a.IUniverInstanceService),Oe(2,a.ICommandService),Oe(3,a.IContextService),Oe(4,a.IConfigService),Oe(5,ut),Oe(6,I.IClipboardInterfaceService),Oe(7,I.IMessageService),Oe(8,D.Inject(A.SheetSkeletonManagerService)),Oe(9,D.Inject(a.LocaleService)),Oe(10,D.Optional(b.ITextSelectionRenderManager))],bn);var gc=Object.defineProperty,fc=Object.getOwnPropertyDescriptor,pc=(i,e,n,t)=>{for(var o=t>1?void 0:t?fc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&gc(e,n,o),o},Xt=(i,e)=>(n,t)=>e(n,t,i);let wn=class extends a.Disposable{constructor(i,e,n,t,o){super(),this._currentUniverService=i,this._contextMenuService=e,this._renderManagerService=n,this._selectionManagerService=t,this._selectionRenderService=o,this._currentUniverService.currentSheet$.subscribe(r=>{if(r==null)throw new Error("workbook is null");this._addListeners()})}_addListeners(){const i=ve(this._currentUniverService,this._renderManagerService);if(!i)return;const e=i.spreadsheet.onPointerDownObserver,n=e.add(l=>{if(l.button===2){const c=this._selectionManagerService.getSelections(),d=c==null?void 0:c[0];if(!d)return;const u=d.range.rangeType,h=this._selectionRenderService.convertSelectionRangeToData(d).rangeWithCoord,m=()=>{if(!h)return!1;const S=l.offsetX,f=l.offsetY;switch(u){case a.RANGE_TYPE.ROW:return h.startY<=f&&h.endY>=f;case a.RANGE_TYPE.COLUMN:return h.startX<=S&&h.endX>=S;default:return h.startX<=S&&h.endX>=S&&h.startY<=f&&h.endY>=f}},_=S=>{this._contextMenuService.triggerContextMenu(l,S)};m()?u===a.RANGE_TYPE.COLUMN?_(de.COL_HEADER_CONTEXT_MENU):u===a.RANGE_TYPE.ROW?_(de.ROW_HEADER_CONTEXT_MENU):_(I.MenuPosition.CONTEXT_MENU):_(I.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(a.toDisposable(()=>e.remove(n)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,de.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,de.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(s)))}};wn=pc([a.OnLifecycle(a.LifecycleStages.Rendered,wn),Xt(0,a.IUniverInstanceService),Xt(1,I.IContextMenuService),Xt(2,b.IRenderManagerService),Xt(3,D.Inject(g.SelectionManagerService)),Xt(4,Se)],wn);var vc=Object.defineProperty,Cc=Object.getOwnPropertyDescriptor,Ic=(i,e,n,t)=>{for(var o=t>1?void 0:t?Cc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&vc(e,n,o),o},Oi=(i,e)=>(n,t)=>e(n,t,i);let Tn=class extends a.RxDisposable{constructor(i,e,n){super(),this._currentUniverService=i,this._renderManagerService=e,this._undoRedoService=n,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(e=>{const n=e.getConfig();i[e.getSheetId()]={cellData:new a.ObjectMatrix(n.cellData),rowCount:n.rowCount,columnCount:n.columnCount}})}_commandExecutedListener(){}_getDocObject(){return ee.getDocObject(this._currentUniverService,this._renderManagerService)}};Tn=Ic([a.OnLifecycle(a.LifecycleStages.Steady,Tn),Oi(0,a.IUniverInstanceService),Oi(1,b.IRenderManagerService),Oi(2,D.Inject(a.IUndoRedoService))],Tn);const Tr=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],Mc=[I.KeyCode.ENTER,I.KeyCode.TAB,...Tr];function Rc(){const i=[];for(const e of Tr)i.push({id:Bt.id,binding:e,preconditions:n=>dn(n),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!1}}),i.push({id:Bt.id,binding:e|I.MetaKeys.SHIFT,preconditions:n=>dn(n),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!0}});return i}const bc={id:Pe.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>dn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},wc={id:Pe.id,binding:I.KeyCode.TAB,preconditions:i=>dn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},Tc={id:Pe.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>mo(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},Ec={id:ee.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>mo(i),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},yc={id:ee.DeleteLeftCommand.id,preconditions:i=>Is(i)||_o(i),binding:I.KeyCode.BACKSPACE},Oc={id:Pe.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ne(i)&&!_o(i),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};var xc=Object.defineProperty,Ac=Object.getOwnPropertyDescriptor,Nc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ac(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&xc(e,n,o),o},He=(i,e)=>(n,t)=>e(n,t,i);function Dc(i){const{textRuns:e=[],paragraphs:n=[]}=i;return e.some(t=>t.ts&&!a.Tools.isEmptyObject(t.ts))||n.some(t=>t.bullet)||n.length>=2}let En=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_onInputSubscription");C(this,"_cursorChangeObservers");C(this,"_editorVisiblePrevious",!1);C(this,"_isCursorChange",0);this._currentUniverService=e,this._renderManagerService=n,this._commandService=t,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._undoRedoService=c,this._sheetInterceptorService=d,this._selectionManagerService=u,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe();const e=this._getEditorObject();if(e==null)return;const{document:n}=e;n.onPointerDownObserver.remove(this._cursorChangeObservers)}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this._onInputSubscription=this._editorBridgeService.visible$.subscribe(e=>{const{visible:n,keycode:t,eventType:o}=e;if(n===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=n,n===!0){this._isCursorChange=o===b.DeviceInputEventType.PointerDown?2:1;return}this._isCursorChange=0;const r=this._selectionManagerService.getSelections(),s=this._selectionManagerService.getCurrent();if(s==null)return;const{unitId:l,sheetId:c,pluginName:d}=s;if(this._exitInput(e),t===I.KeyCode.ESC){this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,{unitId:l,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getEditCellState();if(u==null)return;const{unitId:h,sheetId:m,row:_,column:S,documentLayoutObject:f}=u;if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(t);return}const M=this._currentUniverService.getUniverSheetInstance(h),R=M==null?void 0:M.getSheetBySheetId(m);if(R==null)return;const T=Pc(R.getCellRaw(_,S)||{},f,this._lexerTreeBuilder);if(T==null){this._moveCursor(t);return}const E={subUnitId:m,unitId:h,workbook:M,worksheet:R,row:_,col:S},w=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(T,E);this._commandService.executeCommand(g.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:_,startColumn:S,endRow:_,endColumn:S},value:w}),this._moveCursor(t),l===h&&m!==c&&this._editorBridgeService.isForceKeepVisible()&&this._commandService.executeCommand(g.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h}),this._selectionManagerService.refreshSelection()})}_exitInput(e){this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const n=this._editorBridgeService.getCurrentEditorId();n!=null&&(this._undoRedoService.clearUndoRedo(n),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Mc.includes(e))return;let n=a.Direction.LEFT;switch(e){case I.KeyCode.ENTER:n=a.Direction.DOWN;break;case I.KeyCode.TAB:n=a.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:n=a.Direction.DOWN;break;case I.KeyCode.ARROW_UP:n=a.Direction.UP;break;case I.KeyCode.ARROW_LEFT:n=a.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:n=a.Direction.RIGHT;break}e===I.KeyCode.ENTER||e===I.KeyCode.TAB?this._commandService.executeCommand(it.id,{keycode:e,direction:n}):this._commandService.executeCommand(Re.id,{direction:n})}_cursorStateListener(){const e=this._getEditorObject();if(e==null)return;const{document:n}=e;this._cursorChangeObservers=n.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})}_commandExecutedListener(){const e=[Bt.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){const t=n.params,{keycode:o,isShift:r}=t;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(t)}}))}_moveInEditor(e,n){let t=a.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?t=a.Direction.DOWN:e===I.KeyCode.ARROW_UP?t=a.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(t=a.Direction.RIGHT),n?this._commandService.executeCommand(ee.MoveSelectionOperation.id,{direction:t}):this._commandService.executeCommand(ee.MoveCursorOperation.id,{direction:t})}_getEditorObject(){return sn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};En=Nc([a.OnLifecycle(a.LifecycleStages.Steady,En),He(0,a.IUniverInstanceService),He(1,b.IRenderManagerService),He(2,a.ICommandService),He(3,be),He(4,a.IContextService),He(5,zt),He(6,D.Inject(te.LexerTreeBuilder)),He(7,a.IUndoRedoService),He(8,D.Inject(g.SheetInterceptorService)),He(9,D.Inject(g.SelectionManagerService))],En);function Pc(i,e,n){i=a.Tools.deepClone(i);const{documentModel:t}=e;if(t==null)return null;const o=t.getSnapshot(),{body:r}=o;if(r==null)return null;const s=r.dataStream;let c=s.substring(s.length-2,s.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?s.substring(0,s.length-2):s;if(a.isFormulaString(c)){if(i.f===c)return null;const d=n.checkIfAddBracket(c);for(let u=0;u<d;u++)c+=te.matchToken.CLOSE_BRACKET;i.f=c,i.v=null,i.p=null}else if(Dc(r))r.dataStream===`\r
19
+ `?(i.v="",i.f=null,i.si=null,i.p=null):(i.p=o,i.v=null,i.f=null,i.si=null);else{if((c===i.v||c===""&&i.v==null)&&i.p==null)return null;i.v=c,i.f=null,i.si=null,i.p=null}return i}var Hc=Object.defineProperty,Lc=Object.getOwnPropertyDescriptor,Uc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Lc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Hc(e,n,o),o},Le=(i,e)=>(n,t)=>e(n,t,i);let yn=class extends a.RxDisposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_loadedMap",new Set);this._univerInstanceService=e,this._renderManagerService=n,this._editorBridgeService=t,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=l,this._formulaEditorManagerService=c,this._undoRedoService=d,this._textSelectionManagerService=u,this._initialize()}_initialize(){this._syncFormulaEditorContent(),this._commandExecutedListener(),this._syncEditorSize(),this._listenFxBtnClick(),this._listenFoldBtnClick(),this._renderManagerService.currentRender$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._loadedMap.has(e)||(this._initialMain(e),this._loadedMap.add(e)))}),this._textSelectionManagerService.textSelection$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{unitId:n}=e;n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(P.takeUntil(this.dispose$)).subscribe(()=>{var n;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(a.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0);const t=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown});const r=(n=t==null?void 0:t.getBody())==null?void 0:n.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const l=[{startOffset:s.length,endOffset:s.length}],c={unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(ee.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(l)}})}_listenFoldBtnClick(){this._formulaEditorManagerService.foldBtnStatus$.pipe(P.takeUntil(this.dispose$)).subscribe(()=>{this._textSelectionManagerService.refreshSelection()})}_initialMain(e){const n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:t}=n;t!=null&&this.disposeWithMe(a.toDisposable(t.onPointerDownObserver.add(()=>{this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown})})))}_syncEditorSize(){this._formulaEditorManagerService.position$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const n=sn(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),t=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(n==null||t==null)return;const{width:o,height:r}=e,{engine:s}=n;t.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.currentEditCellState$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(e)}),this._editorBridgeService.visible$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null||e.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const n=this._editorBridgeService.getLatestEditCellState();n!=null&&this._editorSyncHandler(n)})}_editorSyncHandler(e){var s;const n=(s=e.documentLayoutObject.documentModel)==null?void 0:s.getBody();let t=n==null?void 0:n.dataStream,o=n==null?void 0:n.paragraphs,r=[];t==null||o==null||(e.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===b.DeviceInputEventType.Dblclick?(t=`\r
20
+ `,o=[{startIndex:0}]):e.isInArrayFormulaRange===!0&&(r=(n==null?void 0:n.textRuns)||[]),this._syncContentAndRender(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,t,o,r),this._autoScroll())}_commandExecutedListener(){const e=[ee.RichTextEditingMutation.id,_n.id],n=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s;if(e.includes(o.id)){const l=o.params,{unitId:c}=l;if(n.includes(c)){const d=this._univerInstanceService.getUniverDocInstance(c),u=(r=d==null?void 0:d.getBody())==null?void 0:r.dataStream,h=(s=d==null?void 0:d.getBody())==null?void 0:s.paragraphs,m=c===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(u==null||h==null)return;this._syncContentAndRender(m,u,h),this._autoScroll()}}}));const t=[g.SetRangeValuesMutation.id,g.MoveRangeMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s,l,c,d;if(t.includes(o.id)){const u=this._editorBridgeService.getLatestEditCellState();if(u==null)return;let h=!1;const{row:m,column:_}=u;if(o.id===g.SetRangeValuesMutation.id&&o.params?(s=(r=o.params.cellValue)==null?void 0:r[m])!=null&&s[_]&&(h=!0):o.id===g.MoveRangeMutation.id&&o.params&&(c=(l=o.params.to.value)==null?void 0:l[m])!=null&&c[_]&&(h=!0),h){const S=(d=u.documentLayoutObject.documentModel)==null?void 0:d.getBody();if(S==null)return;const{dataStream:f,paragraphs:v=[]}=S;this._syncContentAndRender(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,f,v),this._autoScroll()}}}))}_syncContentAndRender(e,n,t,o=[]){var h;const r=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(e),l=this._univerInstanceService.getUniverDocInstance(e),c=this._docViewModelManagerService.getViewModel(e);if(l==null||c==null||s==null)return;l.getBody().dataStream=n,l.getBody().paragraphs=this._clearParagraph(t),e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(l.getBody().textRuns=[]),o.length>0&&(l.getBody().textRuns=o),c.reset(l);const{skeleton:d}=s,u=this._renderManagerService.getRenderById(e);u!=null&&(d.calculate(),r.includes(e)&&((h=u.mainComponent)==null||h.makeDirty()))}_clearParagraph(e){const n=a.Tools.deepClone(e);for(const t of n)t.paragraphStyle&&(t.paragraphStyle.horizontalAlign=a.HorizontalAlign.UNSPECIFIED);return n}_autoScroll(){var S,f;const e=(S=this._docSkeletonManagerService.getSkeletonByUnitId(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:S.skeleton,n=this._formulaEditorManagerService.getPosition(),t=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||n==null||t==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:l,mainComponent:c}=t;let{actualHeight:d}=e.getActualSize();d+=r+s;const{width:u,height:h}=n,m=l.getViewport(ee.VIEWPORT_KEY.VIEW_MAIN);let _=m==null?void 0:m.getScrollBar();l.transformByState({width:u,height:d}),c==null||c.resize(u,d),d>h?_==null?m&&new b.ScrollBar(m,{enableHorizontal:!1,barSize:8}):m==null||m.resetSizeAndScrollBar():(_=null,m==null||m.scrollTo({x:0,y:0}),(f=m==null?void 0:m.getScrollBar())==null||f.dispose())}};yn=Uc([a.OnLifecycle(a.LifecycleStages.Steady,yn),Le(0,a.IUniverInstanceService),Le(1,b.IRenderManagerService),Le(2,be),Le(3,D.Inject(ee.DocSkeletonManagerService)),Le(4,D.Inject(ee.DocViewModelManagerService)),Le(5,a.ICommandService),Le(6,a.IContextService),Le(7,In),Le(8,a.IUndoRedoService),Le(9,D.Inject(ee.TextSelectionManagerService))],yn);var kc=Object.defineProperty,Vc=Object.getOwnPropertyDescriptor,Bc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Vc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&kc(e,n,o),o},Fc=(i,e)=>(n,t)=>e(n,t,i);let On=class extends a.Disposable{constructor(i){super(),this._currentUniverService=i,setTimeout(()=>{this._initialize()},0)}_initialize(){this._currentUniverService.createDoc({id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}});const i={id:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{pageSize:{width:Number.POSITIVE_INFINITY,height:Number.POSITIVE_INFINITY},marginTop:5,marginBottom:5,marginRight:0,marginLeft:0,paragraphLineGapDefault:0,renderConfig:{horizontalAlign:a.HorizontalAlign.UNSPECIFIED,verticalAlign:a.VerticalAlign.UNSPECIFIED,centerAngle:0,vertexAngle:0,wrapStrategy:a.WrapStrategy.WRAP}}};this._currentUniverService.createDoc(i)}};On=Bc([a.OnLifecycle(a.LifecycleStages.Rendered,On),Fc(0,a.IUniverInstanceService)],On);const Er={sheetFooterBarHeight:"36",sheetContainer:"univer-sheet-container"};var Wc=Object.defineProperty,jc=Object.getOwnPropertyDescriptor,zc=(i,e,n,t)=>{for(var o=t>1?void 0:t?jc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Wc(e,n,o),o},xe=(i,e)=>(n,t)=>e(n,t,i);const yr=-1e3,Or=5,Yc=2;let xn=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u,h){super();C(this,"_onInputSubscription");C(this,"_onInputActivateSubscription");C(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=e,this._docViewModelManagerService=n,this._contextService=t,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=l,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._initialize(),this._commandExecutedListener()}dispose(){var e,n;(e=this._onInputSubscription)==null||e.unsubscribe(),(n=this._onInputActivateSubscription)==null||n.unsubscribe()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const e=this._getEditorObject();e!=null&&this.disposeWithMe(a.toDisposable(e.document.onPointerDownObserver.add(()=>{var n;if(this._editorBridgeService.isVisible()){const t=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(t==null||o==null)return;const r=(n=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:n.skeleton;if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u}=t;this._fitTextSize(s,c,r,l,d,u)}})))}_initialCursorSync(){this._cellEditorManagerService.focus$.subscribe(()=>{this._textSelectionRenderManager.sync()})}_initialEditFocusListener(){this._onInputSubscription=this._editorBridgeService.currentEditCellState$.subscribe(e=>{if(e==null||this._editorBridgeService.isForceKeepVisible())return;const{position:n,documentLayoutObject:t,scaleX:o,editorUnitId:r}=e;if(this._getEditorObject()==null)return;const{startX:l,endX:c}=n,{textRotation:d,wrapStrategy:u,documentModel:h}=t,{a:m}=d;h.updateDocumentId(r),u===a.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-l)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(yr,yr)})}_fitTextSize(e,n,t,o,r=1,s=1){const{startX:l,startY:c,endX:d,endY:u}=e,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:_}=this._predictingSize(e,n,t,o,r,s),{verticalAlign:S,paddingData:f,fill:v}=o;let M=d-l,R=u-c;if(M<m&&(M=m),R<_)R=_,h.updateDocumentDataMargin(f);else{let T=R-_||0;S===a.VerticalAlign.MIDDLE?T=(R-_)/2:S===a.VerticalAlign.TOP&&(T=f.t||0),T/=s,T=T<(f.t||0)?f.t||0:T,h.updateDocumentDataMargin({t:T})}t.calculate(),this._editAreaProcessing(M,R,e,n,v,r,s)}_predictingSize(e,n,t,o,r=1,s=1){const{startX:l,endX:c}=e,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,_=document.body.clientWidth;if(u===a.WrapStrategy.WRAP&&m===0){const{actualWidth:v,actualHeight:M}=t.getActualSize();return{actualWidth:v*r,actualHeight:M*s}}h==null||h.updateDocumentDataPageSize((_-l-n.left)/r),t.calculate();const S=t.getActualSize();let f=c-l;return f<S.actualWidth*r+Or*r&&(f=S.actualWidth*r+Or*r),h==null||h.updateDocumentDataPageSize(f/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED}),{actualWidth:f,actualHeight:S.actualHeight*s}}_editAreaProcessing(e,n,t,o,r,s=1,l=1){var w;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=t;const{document:h,scene:m,engine:_}=c,S=m.getViewport(ee.VIEWPORT_KEY.VIEW_MAIN),f=document.body.clientHeight-u-Number.parseFloat(Er.sheetFooterBarHeight)-o.top-Yc*2,v=document.body.clientWidth-d-o.left;let M=n,R=S==null?void 0:S.getScrollBar();M>f?(M=f,R==null?S&&new b.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetSizeAndScrollBar()):(R=null,(w=S==null?void 0:S.getScrollBar())==null||w.dispose()),e+=(R==null?void 0:R.barSize)||0,e>v&&(e=v),d-=b.FIX_ONE_PIXEL_BLUR_OFFSET,u-=b.FIX_ONE_PIXEL_BLUR_OFFSET,this._addBackground(m,e/s,n/l,r);const{scaleX:T,scaleY:E}=m.getPrecisionScale();m.transformByState({width:e/s,height:n/l,scaleX:s,scaleY:l}),h.resize(e/s,n/l),requestIdleCallback(()=>{_.resizeBySize(b.fixLineWidthByScale(e,T),b.fixLineWidthByScale(M,E))}),this._cellEditorManagerService.setState({startX:d,startY:u,endX:e+d,endY:M+u,show:!0})}_addBackground(e,n,t,o){const r="_backgroundRectHelperColor_",s=e.getObject(r);s==null&&o==null||(s==null?e.addObjects([new b.Rect(r,{width:n,height:t,fill:o,evented:!1})],ee.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:n,height:t})))}_initialStartEdit(){this._onInputActivateSubscription=this._editorBridgeService.visible$.subscribe(e=>{var E,w,y;const{visible:n,eventType:t,keycode:o}=e;if(n===this._editorVisiblePrevious||(this._editorVisiblePrevious=n,n===!1))return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:_=!1}=r,S=this._getEditorObject();if(S==null)return;const{document:f,scene:v}=S;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const{documentModel:M}=l,R=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(R==null||M==null)return;const{skeleton:T}=R;if(this._fitTextSize(s,c,T,l,d,u),t===b.DeviceInputEventType.Keyboard||t===b.DeviceInputEventType.Dblclick&&_){const O=a.Tools.deepClone(M.snapshot),x=(E=this._docViewModelManagerService.getCurrent())==null?void 0:E.docViewModel;this._resetBodyStyle(O.body),M.reset(O),x.reset(M),f.makeDirty(),(o===I.KeyCode.BACKSPACE||t===b.DeviceInputEventType.Dblclick)&&(T.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(t===b.DeviceInputEventType.Dblclick){const O=M.getBody().dataStream.length-2||0;(w=v.getViewport(ee.VIEWPORT_KEY.VIEW_MAIN))==null||w.scrollTo({y:Number.POSITIVE_INFINITY}),this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O}])}(y=this._renderManagerService.getRenderById(m))==null||y.scene.resetCursor()})}_resetBodyStyle(e){e.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,e.textRuns!=null&&(e.textRuns.length===1?(e.textRuns[0].st=0,e.textRuns[0].ed=1):e.textRuns=void 0),e.paragraphs!=null&&(e.paragraphs.length===1?e.paragraphs[0].startIndex=0:e.paragraphs=[{startIndex:0}]),e.sectionBreaks!=null&&(e.sectionBreaks=void 0),e.tables!=null&&(e.tables=void 0),e.customRanges!=null&&(e.customRanges=void 0),e.customBlocks!=null&&(e.customBlocks=void 0)}_initialKeyboardListener(){this._textSelectionRenderManager.onInputBefore$.subscribe(e=>{const n=this._contextService.getContextValue(a.FOCUSING_FORMULA_EDITOR);this._contextService.getContextValue(a.FOCUSING_SHEET)&&!n&&this._showEditorByKeyboard(e)})}_showEditorByKeyboard(e){if(e==null)return;const n=e.event;this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:n.which})}_commandExecutedListener(){const e=[ee.RichTextEditingMutation.id,_n.id],n=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var o;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,l=this._editorBridgeService.getCurrentEditorId();if(l==null)return;this._editorBridgeService.changeEditorDirty(!0);const c=(o=this._docSkeletonManagerService.getSkeletonByUnitId(l))==null?void 0:o.skeleton;if(c==null||!n.includes(s))return;const d=this._editorBridgeService.getEditCellState();if(d==null)return;const{position:u,documentLayoutObject:h,canvasOffset:m,scaleX:_,scaleY:S}=d;this._fitTextSize(u,m,c,h,_,S)}}))}_getEditorObject(){return sn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};xn=zc([a.OnLifecycle(a.LifecycleStages.Steady,xn),xe(0,D.Inject(ee.DocSkeletonManagerService)),xe(1,D.Inject(ee.DocViewModelManagerService)),xe(2,a.IContextService),xe(3,a.IUniverInstanceService),xe(4,b.IRenderManagerService),xe(5,be),xe(6,zt),xe(7,b.ITextSelectionRenderManager),xe(8,D.Inject(ee.TextSelectionManagerService)),xe(9,a.ICommandService),xe(10,D.Inject(a.LocaleService))],xn);const An={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{delta:n,reset:t}=e,o=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();let c=t?100:Math.round((r.getConfig().zoomRatio+n)*100);c=Math.max(ri[0],c),c=Math.min(ri[1],c);const d=c/100;return i.get(a.ICommandService).executeCommand(Be.id,{unitId:s,subUnitId:l,zoomRatio:d})}},Nn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{unitId:n,subUnitId:t,zoomRatio:o}=e;return i.get(a.ICommandService).executeCommand(Be.id,{unitId:n,subUnitId:t,zoomRatio:o})}},xr={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(i,e)=>(i.get(be).setEditCell(e),!0)};var Xc=Object.defineProperty,$c=Object.getOwnPropertyDescriptor,Zc=(i,e,n,t)=>{for(var o=t>1?void 0:t?$c(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Xc(e,n,o),o},Ct=(i,e)=>(n,t)=>e(n,t,i);let Dn=class extends a.RxDisposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._editorBridgeService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener()}_initSelectionChangeListener(){P.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(P.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null||i==null||i.length===0||i[i.length-1]==null)return;const{primary:t}=i[i.length-1];if(t==null)return;const o=this._getSheetObject();if(o==null)return;const{unitId:r,sheetId:s}=n,{scene:l,engine:c}=o;this._commandService.executeCommand(xr.id,{scene:l,engine:c,primary:t,unitId:r,sheetId:s})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:e,spreadsheetColumnHeader:n,spreadsheetLeftTopPlaceholder:t,spreadsheetRowHeader:o}=i;e.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Dblclick})}),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),o.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this))}_keepVisibleHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&(this._selectionManagerService.makeDirty(!1),this._commandService.executeCommand(Pe.id,{visible:!1,eventType:b.DeviceInputEventType.PointerDown}),setTimeout(()=>{this._selectionManagerService.makeDirty(!0)},0))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_commandExecutedListener(){const i=g.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{n!=null&&n.fromCollab||(e.id===g.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(e.id)&&this._hideEditor())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===Nn.id&&this._editorBridgeService.refreshEditCellState()}))}};Dn=Zc([a.OnLifecycle(a.LifecycleStages.Rendered,Dn),Ct(0,D.Inject(A.SheetSkeletonManagerService)),Ct(1,a.IUniverInstanceService),Ct(2,a.ICommandService),Ct(3,b.IRenderManagerService),Ct(4,be),Ct(5,D.Inject(g.SelectionManagerService))],Dn);var Gc=Object.defineProperty,Kc=Object.getOwnPropertyDescriptor,Jc=(i,e,n,t)=>{for(var o=t>1?void 0:t?Kc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Gc(e,n,o),o},$t=(i,e)=>(n,t)=>e(n,t,i);let Pn=class extends a.Disposable{constructor(i,e,n,t,o){super(),this._commandService=i,this._formatPainterService=e,this._currentUniverService=n,this._renderManagerService=t,this._selectionRenderService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:e}=this._getSheetObject()||{};e&&(i!==ye.OFF?e.setDefaultCursor(b.CURSOR_TYPE.CELL):e.setDefaultCursor(b.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(a.toDisposable(this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{if(this._formatPainterService.getStatus()!==ye.OFF){const{rangeWithCoord:e}=i[i.length-1];this._applyFormatPainter({startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}),this._formatPainterService.getStatus()===ye.ONCE&&this._commandService.executeCommand(bi.id)}})))}async _applyFormatPainter(i){const{styles:e,merges:n}=this._formatPainterService.getSelectionFormat(),t=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!e)return;const{startRow:r,startColumn:s,endRow:l,endColumn:c}=e.getDataRange(),d=l-r+1,u=c-s+1,h=Array.from({length:i.endRow-i.startRow+1},()=>Array.from({length:i.endColumn-i.startColumn+1},()=>({}))),m=[];h.forEach((S,f)=>{S.forEach((v,M)=>{const R=f%d+r,T=M%u+s,E=e.getValue(R,T);E&&(h[f][M].s=E)})}),n.forEach(S=>{const f={startRow:S.startRow-r,startColumn:S.startColumn-s,endRow:S.endRow-r,endColumn:S.endColumn-s},v=Math.max(1,Math.floor((i.endRow-i.startRow+1)/d)),M=Math.max(1,Math.floor((i.endColumn-i.startColumn+1)/u));for(let R=0;R<v;R++)for(let T=0;T<M;T++)m.push({startRow:f.startRow+R*d+i.startRow,startColumn:f.startColumn+T*u+i.startColumn,endRow:f.endRow+R*d+i.startRow,endColumn:f.endColumn+T*u+i.startColumn})});const _={subUnitId:o,unitId:t,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(ur.id,_)}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Pn=Jc([a.OnLifecycle(a.LifecycleStages.Rendered,Pn),$t(0,a.ICommandService),$t(1,St),$t(2,a.IUniverInstanceService),$t(3,b.IRenderManagerService),$t(4,Se)],Pn);const Hn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(i,e={offsetX:0,offsetY:0})=>{const n=i.get(a.ICommandService),t=i.get(Je),r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:l,ySplit:c}=s.getConfig().freeze,d=t.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=e||{},{sheetViewStartRow:m=0,sheetViewStartColumn:_=0,offsetX:S=0,offsetY:f=0}=d||{};return n.executeCommand(mt.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:_+l,offsetX:S+u,offsetY:f+h})}},It={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=t.getActiveSheet(),s=i.get(Je).getCurrentScroll();if(!o)return!1;const l=i.get(a.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=e,{sheetViewStartColumn:m,sheetViewStartRow:_,offsetX:S,offsetY:f}=s||{},{xSplit:v,ySplit:M}=o.getConfig().freeze;return l.executeCommand(mt.id,{unitId:t.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c!=null?c:(_!=null?_:0)+M,sheetViewStartColumn:d!=null?d:(m!=null?m:0)+v,offsetX:u!=null?u:S,offsetY:h!=null?h:f})}};a.CommandType.COMMAND;var Qc=Object.defineProperty,qc=Object.getOwnPropertyDescriptor,ed=(i,e,n,t)=>{for(var o=t>1?void 0:t?qc(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Qc(e,n,o),o},Ue=(i,e)=>(n,t)=>e(n,t,i);const td="__SpreadsheetFreezeRowMainName__",nd="__SpreadsheetFreezeRowHeaderName__",id="__SpreadsheetFreezeColumnMainName__",od="__SpreadsheetFreezeColumnHeaderName__",xi=4,rd=.01;let Ln=class extends a.Disposable{constructor(e,n,t,o,r,s,l,c,d,u){super();C(this,"_rowFreezeHeaderRect");C(this,"_rowFreezeMainRect");C(this,"_columnFreezeHeaderRect");C(this,"_columnFreezeMainRect");C(this,"_freezeDownObservers",[]);C(this,"_freezeMoveObservers",[]);C(this,"_freezeLeaveObservers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_changeToRow",-1);C(this,"_changeToColumn",-1);C(this,"_changeToOffsetX",0);C(this,"_changeToOffsetY",0);C(this,"_activeViewport",null);C(this,"_freezeNormalHeaderColor","");C(this,"_freezeNormalMainColor","");C(this,"_freezeActiveColor","");C(this,"_freezeHoverColor","");C(this,"_lastFreeze");this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=l,this._themeService=c,this._sheetInterceptorService=d,this._injector=u,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,n){var O;const t=n!=null?n:this._getFreeze();if(t==null)return;const o=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(o==null)return;const{startRow:r,startColumn:s}=t,l=this._getPositionByIndex(r,s);if(l==null)return;const c=this._getSheetObject();if(c==null)return;const d=c.engine,u=(d==null?void 0:d.width)||0,h=(d==null?void 0:d.height)||0,m=c.scene,{startX:_,startY:S}=l,{rowTotalHeight:f,columnTotalWidth:v,rowHeaderWidthAndMarginLeft:M,columnHeaderHeightAndMarginTop:R}=o,T=u>v+M?u:v+R,E=h>f+R?h:f+R;this._changeToRow=r,this._changeToColumn=s,this._changeToOffsetX=_,this._changeToOffsetY=S;const w=Math.max(m.scaleX,m.scaleY),y=xi/(w<1?1:w);if(e===0){const x=y;this._rowFreezeHeaderRect=new b.Rect(nd,{fill:this._freezeNormalHeaderColor,width:M,height:y,left:0,top:S-x,zIndex:3});let N=this._freezeNormalHeaderColor;(r===-1||r===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new b.Rect(td,{fill:N,width:T*2,height:y,left:M,top:S-x,zIndex:3}),m.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],Ze)}else{const x=y;this._columnFreezeHeaderRect=new b.Rect(od,{fill:this._freezeNormalHeaderColor,width:y,height:R,left:_-x,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new b.Rect(id,{fill:N,width:y,height:E*2,left:_-x,top:R,zIndex:3}),m.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],Ze)}this._eventBinding(e)}_eventBinding(e=0){let n=this._rowFreezeHeaderRect,t=this._rowFreezeMainRect;e===1&&(n=this._columnFreezeHeaderRect,t=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{n==null||n.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(t==null?void 0:t.onPointerEnterObserver.add(()=>{n==null||n.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{n==null||n.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(t==null?void 0:t.onPointerLeaveObserver.add(()=>{n==null||n.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,n,t,e)})),this._freezeDownObservers.push(t==null?void 0:t.onPointerDownObserver.add(s=>{this._freezeDown(s,n,t,e)}))}_getCurrentLastVisibleRow(){var h,m,_,S;const e=this._getSheetObject();if(e==null)return;const n=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(n==null)return;const t=e.scene,o=Math.max(t.scaleX,t.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(e.engine.height-n.columnHeaderHeight)/o,l=(m=r==null?void 0:r.sheetViewStartRow)!=null?m:0,c=l===0?-((_=r==null?void 0:r.offsetY)!=null?_:0):n.rowHeightAccumulation[l-1]-((S=r==null?void 0:r.offsetY)!=null?S:0);let d=0,u=!1;for(let f=l,v=n.rowHeightAccumulation.length;f<v;f++)if(n.rowHeightAccumulation[f]-c>s){d=f,u=!0;break}return u||(d=n.rowHeightAccumulation.length-1),d}_getActiveViewport(e){var t;const n=(t=this._getSheetObject())==null?void 0:t.scene.getViewports();return n&&n.find(o=>o.isHit(new b.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,n,t,o=0){var h;const r=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(r==null)return;const s=this._getSheetObject();if(s==null)return;const{scene:l}=s;l.setCursor(b.CURSOR_TYPE.GRABBING),l.disableEvent();const c=this._getCurrentLastVisibleRow(),d=c===void 0?Number.POSITIVE_INFINITY:r.rowHeightAccumulation[c];this._activeViewport=null;const u=this._getFreeze();u&&(this._changeToColumn=u.startColumn,this._changeToRow=u.startRow),this._moveObserver=l.onPointerMoveObserver.add(m=>{var T,E,w,y;const _=this._getActiveViewport(m),{startX:S,startY:f,row:v,column:M}=vt(m.offsetX,m.offsetY,l,r,_||void 0);l.setCursor(b.CURSOR_TYPE.GRABBING);const R=xi/Math.max(l.scaleX,l.scaleY);o===0?((T=n.transformByState({top:Math.min(f,d)-R/2}))==null||T.setProps({fill:this._freezeActiveColor}),(E=t.transformByState({top:Math.min(f,d)-R/2}))==null||E.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=c===void 0?v:Math.min(v,c),this._changeToOffsetY=Math.min(f,d),this._activeViewport=_):((w=n.transformByState({left:S-R/2}))==null||w.setProps({fill:this._freezeActiveColor}),(y=t.transformByState({left:S-R/2}))==null||y.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=M,this._changeToOffsetX=S,this._activeViewport=_)}),this._upObserver=l.onPointerUpObserver.add(()=>{var x,N;l.resetCursor(),l.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:_}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(n.setProps({fill:this._freezeNormalHeaderColor}),t.setProps({fill:this._freezeNormalMainColor})):(n==null||n.setProps({fill:this._freezeNormalHeaderColor}),t==null||t.setProps({fill:this._freezeNormalHeaderColor}));const S=xi/Math.max(l.scaleX,l.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(n.transformByState({top:_-S}),t.transformByState({top:_-S})):(this._changeToColumn===0||this._changeToColumn===-1)&&(n.transformByState({left:m-S}),t.transformByState({left:m-S}));const f=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:v,sheetViewStartColumn:M}=f;if(M==null||v==null)return;const R=this._currentUniverService.getCurrentUniverSheetInstance(),T=R.getActiveSheet(),E=(x=T.getConfig())==null?void 0:x.freeze;let w=(E==null?void 0:E.xSplit)||0,y=(E==null?void 0:E.ySplit)||0;const O=(N=this._activeViewport)==null?void 0:N.viewPortKey;o===0&&(!O||O===V.VIEW_LEFT_TOP||O===V.VIEW_MAIN_LEFT_TOP||O===V.VIEW_MAIN_TOP||O===V.VIEW_ROW_TOP?y=this._changeToRow-(E.startRow-E.ySplit):y=this._changeToRow-v,y=y<0?0:y),o===1&&(!O||O===V.VIEW_LEFT_TOP||O===V.VIEW_MAIN_LEFT_TOP||O===V.VIEW_MAIN_LEFT||O===V.VIEW_COLUMN_LEFT?w=this._changeToColumn-(E.startColumn-E.xSplit):w=this._changeToColumn-M,w=w<0?0:w),this._commandService.executeCommand(g.SetFrozenCommand.id,{startRow:y===0?-1:this._changeToRow,startColumn:w===0?-1:this._changeToColumn,ySplit:y,xSplit:w,unitId:R.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e,t=n.getViewport(V.VIEW_COLUMN_LEFT),o=n.getViewport(V.VIEW_COLUMN_RIGHT),r=n.getViewport(V.VIEW_ROW_TOP),s=n.getViewport(V.VIEW_ROW_BOTTOM),l=n.getViewport(V.VIEW_LEFT_TOP),c=n.getViewport(V.VIEW_MAIN),d=n.getViewport(V.VIEW_MAIN_LEFT_TOP),u=n.getViewport(V.VIEW_MAIN_LEFT),h=n.getViewport(V.VIEW_MAIN_TOP);if(!(t==null||o==null||r==null||s==null||l==null||c==null||d==null||u==null||h==null))return{viewMain:c,viewMainLeftTop:d,viewMainLeft:u,viewMainTop:h,viewColumnLeft:t,viewColumnRight:o,viewRowTop:r,viewRowBottom:s,viewLeftTop:l}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewMain:n,viewRowBottom:t,viewColumnRight:o,viewMainLeft:r,viewMainTop:s}=e;this.disposeWithMe(n.onScrollAfterObserver.add(l=>{const{scrollX:c,scrollY:d,actualScrollX:u,actualScrollY:h}=l;t.isActive&&t.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),o.isActive&&o.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0),r.isActive&&r.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),s.isActive&&s.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0)}))}_updateViewport(e=-1,n=-1,t=0,o=0,r=3){var O;const s=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(s==null)return;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=s,d=this._getViewports();if(!d)return;const{viewMain:u,viewMainLeftTop:h,viewMainLeft:m,viewMainTop:_,viewColumnLeft:S,viewColumnRight:f,viewRowTop:v,viewRowBottom:M,viewLeftTop:R}=d;f.resize({left:l,top:0,height:c,right:0}),M.resize({left:0,top:c,bottom:0,width:l}),R.resize({left:0,top:0,width:l,height:c});let T=!0,E=!0;h.enable(),(e===-1||e===0)&&(T=!1),(n===-1||n===0)&&(E=!1);const w=s.getNoMergeCellPositionByIndexWithNoHeader(e-t,n-o),y=s.getNoMergeCellPositionByIndexWithNoHeader(e,n);if(h.disable(),_.disable(),m.disable(),v.disable(),S.disable(),h.resetPadding(),_.resetPadding(),m.resetPadding(),v.resetPadding(),S.resetPadding(),T===!1&&E===!1)u.resize({left:l,top:c,bottom:0,right:0}),u.resetPadding();else if(T===!0&&E===!1){const x=y.startY-w.startY;u.resize({left:l,top:c+x,bottom:0,right:0}),u.setPadding({startY:w.startY,endY:y.startY,startX:0,endX:0}),r&2&&this._commandService.executeCommand(It.id,{sheetViewStartRow:0,offsetY:0}),_.resize({left:l,top:c,height:x,right:0}),_.updateScroll({actualScrollY:w.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),v.resize({left:0,top:c,width:l,height:x}),v.updateScroll({actualScrollY:w.startY}).makeDirty(!0),M.resize({left:0,top:c+x,bottom:0,width:l}),_.enable(),v.enable()}else if(T===!1&&E===!0){const x=y.startX-w.startX;u.resize({left:l+x,top:c,bottom:0,right:0}),u.setPadding({startX:w.startX,endX:y.startX,startY:0,endY:0}),r&1&&this._commandService.executeCommand(It.id,{sheetViewStartColumn:0,offsetX:0}),m.resize({left:l,top:c,width:x,bottom:0,right:0}),m.updateScroll({actualScrollX:w.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),S.resize({left:l,top:0,width:x,height:c}),S.updateScroll({actualScrollX:w.startX}).makeDirty(!0),f.resize({left:l+x,top:0,height:c,right:0}),m.enable(),S.enable()}else{const x=y.startX-w.startX,N=y.startY-w.startY;u.resize({left:l+x,top:c+N,bottom:0,right:0}),u.setPadding({startY:w.startY,endY:y.startY,startX:w.startX,endX:y.startX}),r&&this._commandService.executeCommand(It.id,{...r&1?{sheetViewStartColumn:0,offsetX:0}:null,...r&2?{sheetViewStartRow:0,offsetY:0}:null}),m.resize({left:l,top:c+N,width:x,bottom:0}),m.updateScroll({actualScrollX:w.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),_.resize({left:l+x,top:c,height:N,right:0}),_.updateScroll({actualScrollY:w.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),h.resize({left:l,top:c,width:x,height:N}),h.updateScroll({actualScrollX:w.startX,actualScrollY:w.startY}).makeDirty(!0),v.resize({left:0,top:c,width:l,height:N}),v.updateScroll({actualScrollY:w.startY}).makeDirty(!0),M.resize({left:0,top:c+N,bottom:0,width:l}),S.resize({left:l,top:0,width:x,height:c}),S.updateScroll({actualScrollX:w.startX}).makeDirty(!0),f.resize({left:l+x,top:0,height:c,right:0}),h.enable(),_.enable(),m.enable(),v.enable(),S.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[g.SetWorksheetActiveOperation.id,g.InsertRangeMoveDownCommand.id,g.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:l=0}=t;this._refreshFreeze(o,r,s,l,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()})))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(rd).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const n={redos:[],undos:[]},t=this._getFreeze();if(!t)return n;const o=r=>{const s=this._currentUniverService.getCurrentUniverSheetInstance(),l=s.getUnitId(),d=s.getActiveSheet().getSheetId();this._refreshFreeze(r.startRow,r.startColumn,r.ySplit,r.xSplit,0);const u={...r,unitId:l,subUnitId:d,resetScroll:!1},h=g.SetFrozenMutationFactory(this._injector,u);return{undos:[{id:g.SetFrozenMutation.id,params:h}],redos:[{id:g.SetFrozenMutation.id,params:u}]}};if(e.id===g.MoveColsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startColumn:s},toRange:{startColumn:l}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===a.RANGE_TYPE.COLUMN&&v.range.startColumn<=s&&s<=v.range.endColumn);if(!(c!=null&&c.length))return n;const d=c[0].range,u={...d,startColumn:l,endColumn:l+d.endColumn-d.startColumn};if(!t||t.startColumn<=0||d.startColumn>=t.startColumn&&u.startColumn>=t.startColumn||d.startColumn===u.startColumn||d.endColumn<t.startColumn&&u.startColumn<t.startColumn)return n;const h=d.endColumn-d.startColumn+1,m=Math.max(Math.min(t.startColumn,d.endColumn+1)-d.startColumn,0);let _,S;u.startColumn>=t.startColumn?(_=Math.max(t.startColumn-m,1),S=Math.max(t.xSplit-m,1)):(_=t.startColumn+h-m,S=t.xSplit+h-m);const f={...t,startColumn:_,xSplit:S};return o(f)}if(e.id===g.MoveRowsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startRow:s},toRange:{startRow:l}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===a.RANGE_TYPE.ROW&&v.range.startRow<=s&&s<=v.range.endRow);if(!(c!=null&&c.length))return n;const d=c[0].range,u={...d,startRow:l,endRow:l+d.endRow-d.startRow};if(!t||t.startRow<=0||d.startRow>=t.startRow&&u.startRow>=t.startRow||d.startRow===u.startRow||d.endRow<t.startRow&&u.startRow<t.startRow)return n;const h=d.endRow-d.startRow+1,m=Math.max(Math.min(t.startRow,d.endRow+1)-d.startRow,0);let _,S;u.startRow>=t.startRow?(_=Math.max(t.startRow-m,1),S=Math.max(t.ySplit-m,1)):(_=t.startRow+h-m,S=t.ySplit+h-m);const f={...t,startRow:_,ySplit:S};return o(f)}if(e.id===g.RemoveColCommand.id||e.id===g.RemoveRowCommand.id){const r=e.params,s=r.range;if(s.rangeType===a.RANGE_TYPE.COLUMN&&s.startColumn<t.startColumn){const l=Math.min(t.startColumn,s.endColumn+1)-s.startColumn,c={...t,startColumn:Math.max(1,t.startColumn-l),xSplit:Math.max(1,t.xSplit-l)};return o(c)}if(r.range.rangeType===a.RANGE_TYPE.ROW&&s.startRow<t.startRow){const l=Math.min(t.startRow,s.endRow+1)-s.startRow,c={...t,startRow:Math.max(1,t.startRow-l),ySplit:Math.max(1,t.ySplit-l)};return o(c)}}return n}}))}_commandExecutedListener(){const e=[g.SetFrozenMutation.id,Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){const t=this._lastFreeze,o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=n.params,{unitId:l,subUnitId:c}=s;if(!(l===o.getUnitId()&&c===r.getSheetId()))return;const d=r.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:m=-1,ySplit:_=0,xSplit:S=0}=d;(!t||t.startRow!==h||t.ySplit!==_)&&(u|=2),(!t||t.startColumn!==m||t.xSplit!==S)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,m,_,S,u)}else if(n.id===g.SetWorksheetRowHeightMutation.id){const t=this._getFreeze();n.params&&t&&n.params.ranges.some(o=>o.startRow<t.startRow)&&this._refreshCurrent()}else if(n.id===g.SetWorksheetColWidthMutation.id){const t=this._getFreeze();n.params&&t&&n.params.ranges.some(o=>o.startColumn<t.startColumn)&&this._refreshCurrent()}else if(n.id===g.SetWorksheetRowAutoHeightMutation.id){const t=n.params,o=this._getFreeze();if(o&&o.startRow>-1&&t.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}else if(n.id===g.SetColHiddenMutation.id||n.id===g.SetColVisibleMutation.id){const t=n.params,o=this._getFreeze(),r=t.ranges;o&&o.startColumn>-1&&r.some(s=>s.startColumn<o.startColumn)&&this._refreshCurrent()}else if(n.id===g.SetRowHiddenMutation.id||n.id===g.SetRowVisibleMutation.id){const t=n.params,o=this._getFreeze(),r=t.ranges;o&&o.startRow>-1&&r.some(s=>s.startRow<o.startRow)&&this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onTransformChangeObservable.add(t=>{t.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onPointerMoveObserver.remove(this._moveObserver),n.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var t,o,r,s;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(o=this._rowFreezeMainRect)==null||o.dispose(),(r=this._columnFreezeHeaderRect)==null||r.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(l=>{n.onPointerDownObserver.remove(l),n.onPointerMoveObserver.remove(l),n.onPointerLeaveObserver.remove(l)}),n.onPointerEnterObserver.remove(this._moveObserver),n.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(e,n){var c;if(this._getSheetObject()==null)return;const o=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton,r=o==null?void 0:o.getNoMergeCellPositionByIndex(e,n);if(o==null)return;if(r!=null&&(!isNaN(r.endX)||!isNaN(r.endY)))return r;const{rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:l}=o;return{startX:s,endX:s,startY:l,endY:l}}_getFreeze(){var n;const e=(n=this._sheetSkeletonManagerService.getCurrent())==null?void 0:n.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_refreshFreeze(e,n,t,o,r){var l;const s={startRow:e,startColumn:n,ySplit:t,xSplit:o};this._clearFreeze(),this._createFreeze(0,s),this._createFreeze(1,s),this._updateViewport(e,n,t,o,r),(l=this._getSheetObject())==null||l.spreadsheet.makeForceDirty()}};Ln=ed([a.OnLifecycle(a.LifecycleStages.Rendered,Ln),Ue(0,D.Inject(A.SheetSkeletonManagerService)),Ue(1,a.IUniverInstanceService),Ue(2,a.ICommandService),Ue(3,b.IRenderManagerService),Ue(4,Se),Ue(5,D.Inject(g.SelectionManagerService)),Ue(6,D.Inject(Je)),Ue(7,D.Inject(a.ThemeService)),Ue(8,D.Inject(g.SheetInterceptorService)),Ue(9,D.Inject(D.Injector))],Ln);var Ai=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(Ai||{});const sd="rgba(0, 0, 0, 0.15)",We="rgb(0, 0, 0)",Un="rgb(255, 255, 255, 1)";class ad extends b.Shape{constructor(n,t){super(n,t);C(this,"_size",12);C(this,"_iconRatio",.4);C(this,"_mode",0);this.setShapeProps(t)}setShapeProps(n){n!=null&&n.size&&(this._size=n.size),n!=null&&n.mode&&(this._mode=n.mode),this.transformByState({width:this._size,height:this._size})}_draw(n){this._mode===1&&b.Rect.drawWith(n,{width:this._size,height:this._size,radius:this._size,fill:sd});const t=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=t*Math.sin(o),s=t*Math.cos(o);b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:-r+this._size/2,y:-s+this._size/2},{x:r+this._size/2,y:-s+this._size/2},{x:this._size/2,y:t+this._size/2}]],fill:We})}}var ld=Object.defineProperty,cd=Object.getOwnPropertyDescriptor,dd=(i,e,n,t)=>{for(var o=t>1?void 0:t?cd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&ld(e,n,o),o},Mt=(i,e)=>(n,t)=>e(n,t,i);const ud="__SpreadsheetHeaderMenuSHAPEControllerShape__",hd="__SpreadsheetHeaderMenuMAINControllerShape__",md="rgba(0, 0, 0, 0.1)";let kn=class extends a.Disposable{constructor(e,n,t,o,r,s){super();C(this,"_hoverRect");C(this,"_hoverMenu");C(this,"_currentColumn",Number.POSITIVE_INFINITY);C(this,"_observers",[]);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._renderManagerService=t,this._contextMenuService=o,this._commandService=r,this._selectionManagerService=s,this._initialize()}dispose(){var o,r;(o=this._hoverRect)==null||o.dispose(),(r=this._hoverMenu)==null||r.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t}=e;this._observers.forEach(s=>{n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s),t.onPointerEnterObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s)})}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;this._hoverRect=new b.Rect(ud,{fill:md,evented:!1}),this._hoverMenu=new ad(hd,{zIndex:100,visible:!1}),n.addObjects([this._hoverRect,this._hoverMenu],Ze),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(e=0){const n=this._getSheetObject();if(n==null)return;const{spreadsheetColumnHeader:t,spreadsheetRowHeader:o}=n,r=e===0?o:t;this._observers.push(r==null?void 0:r.onPointerEnterObserver.add(()=>{var s;(s=this._hoverRect)==null||s.show()})),this._observers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var v,M,R;const l=(v=this._sheetSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(l==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=l,{startX:h,startY:m,endX:_,endY:S,column:f}=vt(s.offsetX,s.offsetY,c.scene,l);if(e===0)(M=this._hoverRect)==null||M.transformByState({width:d,height:S-m,left:0,top:m});else{if(this._currentColumn=f,(R=this._hoverRect)==null||R.transformByState({width:_-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(_-h<u*2){this._hoverMenu.hide();return}const T=u*.8;this._hoverMenu.transformByState({left:_-u,top:u/2-T/2}),this._hoverMenu.setShapeProps({size:T}),this._hoverMenu.show()}})),this._observers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._hoverRect)==null||s.hide(),(l=this._hoverMenu)==null||l.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ai.HIGHLIGHT,visible:!0}),e.scene.setCursor(b.CURSOR_TYPE.POINTER))}),this._hoverMenu.onPointerLeaveObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ai.NORMAL,visible:!1}),e.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(e=>{if(!this._getSheetObject())return;const t=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();if(!!!(o!=null&&o.filter(s=>s.rangeType===a.RANGE_TYPE.COLUMN).find(s=>{const{startColumn:l,endColumn:c}=s;return t>=l&&t<=c}))){const s=this._getSelectionOnColumn(t);this._commandService.syncExecuteCommand(g.SetSelectionsOperation.id,s)}e.stopPropagation(),e.preventDefault(),this._contextMenuService.triggerContextMenu(e,de.COL_HEADER_CONTEXT_MENU)}))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_getSelectionOnColumn(e){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet();return{unitId:n.getUnitId(),subUnitId:t.getSheetId(),pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:{startRow:0,startColumn:e,endRow:t.getRowCount()-1,endColumn:e,rangeType:a.RANGE_TYPE.COLUMN},primary:{startRow:0,startColumn:e,endRow:0,endColumn:e,actualRow:0,actualColumn:e,isMerged:!1,isMergedMainCell:!1},style:null}]}}};kn=dd([a.OnLifecycle(a.LifecycleStages.Rendered,kn),Mt(0,D.Inject(A.SheetSkeletonManagerService)),Mt(1,a.IUniverInstanceService),Mt(2,b.IRenderManagerService),Mt(3,I.IContextMenuService),Mt(4,a.ICommandService),Mt(5,D.Inject(g.SelectionManagerService))],kn);var _d=Object.defineProperty,Sd=Object.getOwnPropertyDescriptor,gd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Sd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&_d(e,n,o),o},Rt=(i,e)=>(n,t)=>e(n,t,i);const fd="__SpreadsheetHeaderMoveControllerBackground__",pd="__SpreadsheetHeaderMoveControllerShapeLine__",vd="rgba(0, 0, 0, 0.1)",Cd="rgb(119, 119, 119)",Id=4;let Vn=class extends a.Disposable{constructor(e,n,t,o,r,s){super();C(this,"_startOffsetX",Number.NEGATIVE_INFINITY);C(this,"_startOffsetY",Number.NEGATIVE_INFINITY);C(this,"_moveHelperBackgroundShape");C(this,"_moveHelperLineShape");C(this,"_sheetObject");C(this,"_rowOrColumnDownObservers",[]);C(this,"_rowOrColumnMoveObservers",[]);C(this,"_rowOrColumnLeaveObservers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_scrollTimer");C(this,"_changeFromColumn",-1);C(this,"_changeFromRow",-1);C(this,"_changeToColumn",-1);C(this,"_changeToRow",-1);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._renderManagerService=t,this._commandService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._initialize()}dispose(){var r,s;(r=this._moveHelperBackgroundShape)==null||r.dispose(),(s=this._moveHelperLineShape)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t,scene:o}=e;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(l=>{n.onPointerDownObserver.remove(l),t.onPointerDownObserver.remove(l)}),o.onPointerMoveObserver.remove(this._moveObserver),o.onPointerUpObserver.remove(this._upObserver),this._scrollTimer.dispose()}_initialize(){const e=this._getSheetObject();e!=null&&(this._sheetObject=e,this._initialRowOrColumn(0),this._initialRowOrColumn(1))}_initialRowOrColumn(e=0){const{spreadsheetColumnHeader:n,spreadsheetRowHeader:t,scene:o}=this._sheetObject,r=e===0?t:n;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const l=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(l==null)return;const{row:c,column:d}=vt(s.offsetX,s.offsetY,o,l);if(this._checkInHeaderRange(e===0?c:d,e)===!1){o.resetCursor(),this._selectionRenderService.enableSelection();return}o.setCursor(b.CURSOR_TYPE.GRAB),this._selectionRenderService.disableSelection()})),this._rowOrColumnLeaveObservers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._moveHelperBackgroundShape)==null||s.hide(),(l=this._moveHelperLineShape)==null||l.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var w;const l=(w=this._sheetSkeletonManagerService.getCurrent())==null?void 0:w.skeleton;if(l==null)return;const{offsetX:c,offsetY:d}=s,u=o.getRelativeCoord(b.Vector2.FromArray([c,d])),{x:h,y:m}=u;this._startOffsetX=h,this._startOffsetY=m;const{row:_,column:S}=vt(s.offsetX,s.offsetY,o,l);let f;e===0?(this._changeFromRow=_,f=b.ScrollTimerType.Y):(this._changeFromColumn=S,f=b.ScrollTimerType.X);const v=this._checkInHeaderRange(e===0?_:S,e);if(v===!1)return;const M=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(b.CURSOR_TYPE.GRABBING),o.disableEvent();let R=!1,T;const E=()=>{if(R)return;T=b.ScrollTimer.create(o,f);const y=o.getViewport(V.VIEW_MAIN);T.startScroll(h,m,y),this._scrollTimer=T,R=!0};this._moveObserver=o.onPointerMoveObserver.add(y=>{E();const{offsetX:O,offsetY:x}=y,{x:N,y:F}=o.getRelativeCoord(b.Vector2.FromArray([O,x]));o.setCursor(b.CURSOR_TYPE.GRABBING),this._rowColumnMoving(N,F,v,M,e),T.scrolling(N,F,()=>{this._rowColumnMoving(N,F,v,M,e)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var O,x,N;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableEvent(),this._clearObserverEvent(),(O=this._scrollTimer)==null||O.dispose();const y=this._selectionManagerService.getSelections();if(e===0){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const L=(x=((y==null?void 0:y.filter(W=>W.range.rangeType===a.RANGE_TYPE.ROW&&W.range.startRow<=this._changeFromRow&&this._changeFromRow<=W.range.endRow))||[])[0])==null?void 0:x.range;L&&this._commandService.executeCommand(g.MoveRowsCommand.id,{fromRange:L,toRange:{...L,startRow:this._changeToRow,endRow:this._changeToRow+L.endRow-L.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const L=(N=((y==null?void 0:y.filter(W=>W.range.rangeType===a.RANGE_TYPE.COLUMN&&W.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=W.range.endColumn))||[])[0])==null?void 0:N.range;L&&this._commandService.executeCommand(g.MoveColsCommand.id,{fromRange:L,toRange:{...L,startColumn:this._changeToColumn,endColumn:this._changeToColumn+L.endColumn-L.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})}))}_rowColumnMoving(e,n,t,o,r){var q,se,$,k,U,Z,ie;const{scene:s}=this._sheetObject,l=(q=this._sheetSkeletonManagerService.getCurrent())==null?void 0:q.skeleton;if(l==null)return;const{rowHeaderWidth:c,columnHeaderHeight:d,rowTotalHeight:u,columnTotalWidth:h}=l,m=s.getScrollXY(s.getViewport(V.VIEW_MAIN)),{scaleX:_,scaleY:S}=s.getAncestorScale(),f=l.getCellPositionByOffset(e,n,_,S,m),{row:v,column:M}=f,R=l.getNoMergeCellPositionByIndex(v,M),{startX:T,startY:E,endX:w,endY:y}=R,O=this._selectionRenderService.convertRangeDataToSelection(t.range);if(O==null)return;const x=Math.max(_,_),{startX:N,endX:F,startY:L,endY:W,startRow:B,startColumn:z,endRow:Y,endColumn:J}=O;r===0?(se=this._moveHelperBackgroundShape)==null||se.transformByState({height:W-L,width:h+c,left:0,top:L+(n-this._startOffsetY)/x+m.y-o.y}):($=this._moveHelperBackgroundShape)==null||$.transformByState({height:u+d,width:F-N,left:N+(e-this._startOffsetX)/x+m.x-o.x,top:0}),(k=this._moveHelperBackgroundShape)==null||k.show();const j=Id/x;if(r===0){let oe=0;if(v<=B)oe=E-j/2,this._changeToRow=v;else if(v>Y)oe=y-j/2,this._changeToRow=v+1;else return;(U=this._moveHelperLineShape)==null||U.transformByState({height:j,width:h,left:c,top:oe})}else{let oe=0;if(M<=z)oe=T-j/2,this._changeToColumn=M;else if(M>J)oe=w-j/2,this._changeToColumn=M+1;else return;(Z=this._moveHelperLineShape)==null||Z.transformByState({height:u,width:j,left:oe,top:d})}(ie=this._moveHelperLineShape)==null||ie.show()}_checkInHeaderRange(e,n=0){var l;const t=this._selectionManagerService.getSelections();if(((l=this._selectionManagerService.getCurrent())==null?void 0:l.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return!1;const r=t==null?void 0:t.find(c=>{const d=c.range,{startRow:u,endRow:h,startColumn:m,endColumn:_,rangeType:S}=d;return n===1?e>=m&&e<=_&&a.RANGE_TYPE.COLUMN===S:e>=u&&e<=h&&a.RANGE_TYPE.ROW===S}),s=r==null?void 0:r.range;return r==null||s==null||s.rangeType===a.RANGE_TYPE.ALL||s.rangeType===a.RANGE_TYPE.NORMAL||s.rangeType===a.RANGE_TYPE.ROW&&n!==0||s.rangeType===a.RANGE_TYPE.COLUMN&&n!==1?!1:r}_clearObserverEvent(){const{scene:e}=this._sheetObject;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_newBackgroundAndLine(){const{scene:e}=this._sheetObject;this._moveHelperBackgroundShape=new b.Rect(fd,{fill:vd,evented:!1,zIndex:100}),this._moveHelperLineShape=new b.Rect(pd,{fill:Cd,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],Ze)}_disposeBackgroundAndLine(){var e,n;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(n=this._moveHelperLineShape)==null||n.dispose()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Vn=gd([a.OnLifecycle(a.LifecycleStages.Rendered,Vn),Rt(0,D.Inject(A.SheetSkeletonManagerService)),Rt(1,a.IUniverInstanceService),Rt(2,b.IRenderManagerService),Rt(3,a.ICommandService),Rt(4,Se),Rt(5,D.Inject(g.SelectionManagerService))],Vn);var Ni=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(Ni||{});const Md="rgba(120, 120, 120, 0.01)",Di="rgb(68, 71, 70)",Zt=12,Pi=4;class Ar extends b.Shape{constructor(n,t){super(n,t);C(this,"_size",Zt);C(this,"_color",Di);C(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(n){let{width:t,height:o}=this,r=0,s=0;const l=this.getScene(),{scaleX:c,scaleY:d}=l.getAncestorScale(),u=Math.max(c,d),h=Zt/u,m=Pi/u;this.mode===0?(t=m,r=h-m):(o=m,s=h-m),b.Rect.drawWith(n,{width:this.width,height:this.height,left:0,top:0,fill:Md}),b.Rect.drawWith(n,{width:t,height:o,fill:Di,radius:m}),n.save(),n.transform(1,0,0,1,r,s),b.Rect.drawWith(n,{width:t,height:o,fill:Di,radius:m}),n.restore()}setShapeProps(n){return n!=null&&n.size&&(this._size=n.size),n!=null&&n.mode&&(this._mode=n.mode),n!=null&&n.color&&(this._color=n.color),this.mode===0?this.transformByState({width:Zt,height:this.size}):this.transformByState({width:this.size,height:Zt}),this}}var Rd=Object.defineProperty,bd=Object.getOwnPropertyDescriptor,wd=(i,e,n,t)=>{for(var o=t>1?void 0:t?bd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Rd(e,n,o),o},Gt=(i,e)=>(n,t)=>e(n,t,i);const Td="__SpreadsheetHeaderResizeControllerShapeRow__",Ed="__SpreadsheetHeaderResizeControllerShapeColumn__",Nr="__SpreadsheetHeaderResizeControllerShapeHelper__",Dr="rgb(199, 199, 199)",yd=2;let Bn=class extends a.Disposable{constructor(e,n,t,o,r){super();C(this,"_currentRow",0);C(this,"_currentColumn",0);C(this,"_rowResizeRect");C(this,"_columnResizeRect");C(this,"_observers",[]);C(this,"_moveObserver");C(this,"_upObserver");C(this,"_resizeHelperShape");C(this,"_startOffsetX",Number.POSITIVE_INFINITY);C(this,"_startOffsetY",Number.POSITIVE_INFINITY);this._sheetSkeletonManagerService=e,this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._editorBridgeService=r,this._initialize()}dispose(){var o,r;(o=this._rowResizeRect)==null||o.dispose(),this._rowResizeRect=null,(r=this._columnResizeRect)==null||r.dispose(),this._columnResizeRect=null;const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:t}=e;this._observers.forEach(s=>{n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;this._rowResizeRect=new Ar(Td,{visible:!1,mode:Ni.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Ar(Ed,{visible:!1,mode:Ni.VERTICAL,zIndex:100}),n.addObjects([this._rowResizeRect,this._columnResizeRect],Ze),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const n=this._getSheetObject();if(n==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:o,scene:r}=n,s=e===0?t:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((l,c)=>{var O;const d=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(d==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:u,columnHeaderHeight:h}=d,{startX:m,startY:_,endX:S,endY:f,row:v,column:M}=vt(l.offsetX,l.offsetY,r,d),R=Cn(l.offsetX,l.offsetY,r),{scaleX:T,scaleY:E}=r.getAncestorScale(),w=Math.max(T,E),y=Zt/w;if(e===0){let x=_-y/2;if(R.y<=_+y/2&&R.y>=_)this._currentRow=v-1;else if(R.y>=f-y/2&&R.y<=f)this._currentRow=v,x=f-y/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const N=u/3;this._rowResizeRect.transformByState({left:u/2-N/2,top:x}),this._rowResizeRect.setShapeProps({size:N}),this._rowResizeRect.show()}else{let x=m-y/2;if(R.x<=m+y/2&&R.x>=m)this._currentColumn=M-1;else if(R.x>=S-y/2&&R.x<=S)this._currentColumn=M,x=S-y/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const N=h*.7;this._columnResizeRect.transformByState({left:x,top:h/2-N/2}),this._columnResizeRect.setShapeProps({size:N}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((l,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(e=0){const n=this._getSheetObject();if(n==null)return;const{scene:t}=n,o=e===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=t.getEngine(),s=(r==null?void 0:r.width)||0,l=(r==null?void 0:r.height)||0;this.disposeWithMe(a.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),t.setCursor(e===0?b.CURSOR_TYPE.ROW_RESIZE:b.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(a.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),t.resetCursor())}))),this.disposeWithMe(a.toDisposable(o.onPointerDownObserver.add((c,d)=>{var se,$,k,U,Z,ie,oe;const u=(se=this._sheetSkeletonManagerService.getCurrent())==null?void 0:se.skeleton;if(u==null)return;const h=this._getSheetObject();if(h==null)return;const{scene:m}=h,_=m.getViewport(V.VIEW_MAIN),S=(((k=($=_==null?void 0:_.getScrollBar())==null?void 0:$.horizonBarRect)==null?void 0:k.height)||0)+10,f=(((Z=(U=_==null?void 0:_.getScrollBar())==null?void 0:U.verticalBarRect)==null?void 0:Z.width)||0)+10,v=Cn(c.offsetX,c.offsetY,m),{scaleX:M,scaleY:R}=m.getAncestorScale();this._startOffsetX=v.x,this._startOffsetY=v.y;const T=u.getOffsetByPositionX(this._currentColumn),E=u.getOffsetByPositionY(this._currentRow),w=u.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let y=!1,O=0,x=0;const{columnTotalWidth:N,rowHeaderWidth:F,rowTotalHeight:L,columnHeaderHeight:W}=u,B=s>N+F?s:N+F,z=l>L+W?l:L+W,Y=Math.max(M,R),J=Pi/Y;e===0?this._resizeHelperShape=new b.Rect(Nr,{width:B,height:J,fill:Dr,left:0,top:E-J/2}):this._resizeHelperShape=new b.Rect(Nr,{width:J,height:z,fill:Dr,left:T-J/2,top:0});const j=((ie=this._columnResizeRect)==null?void 0:ie.left)||0,q=((oe=this._rowResizeRect)==null?void 0:oe.top)||0;m.addObject(this._resizeHelperShape,Ze),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(X=>{var Xe,Ie,en,tn,nn,on;const G=m.getRelativeCoord(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Q=m.getScrollXYByRelativeCoords(G,_),ce=Cn(X.offsetX,X.offsetY,m),{x:ae,y:ge}=ce,{scaleX:Ye,scaleY:Ce}=m.getAncestorScale(),me=Math.max(Ye,Ce),le=Pi/me;O=ae-this._startOffsetX-le/2,x=ge-this._startOffsetY-le/2,Math.abs(e===0?x:O)>=yd&&(y=!0),e===0?(x>l-S+Q.y-w.startY&&(x=l-S+Q.y-w.startY),x<-(w.endY-w.startY)+2&&(x=-(w.endY-w.startY)+2),y&&((Xe=this._resizeHelperShape)==null||Xe.transformByState({top:E+x}),(Ie=this._rowResizeRect)==null||Ie.transformByState({top:q+x+le/2}),(en=this._rowResizeRect)==null||en.show(),m.setCursor(b.CURSOR_TYPE.ROW_RESIZE))):(O>s-f+Q.x-w.startX&&(O=s-f+Q.x-w.startX),O<-(w.endX-w.startX)+2&&(O=-(w.endX-w.startX)+2),y&&((tn=this._resizeHelperShape)==null||tn.transformByState({left:T+O}),(nn=this._columnResizeRect)==null||nn.transformByState({left:j+O+le/2}),(on=this._columnResizeRect)==null||on.show(),m.setCursor(b.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(X=>{var ce,ae,ge;const G=ve(this._currentUniverService,this._renderManagerService);if(G==null)return;this._clearObserverEvent(),(ce=this._resizeHelperShape)==null||ce.dispose(),this._resizeHelperShape=null;const{scene:Q}=G;Q.enableEvent(),y&&(Q.resetCursor(),(ae=this._rowResizeRect)==null||ae.hide(),(ge=this._columnResizeRect)==null||ge.hide(),e===0?this._commandService.executeCommand(g.DeltaRowHeightCommand.id,{deltaY:x,anchorRow:this._currentRow}):this._commandService.executeCommand(g.DeltaColumnWidthCommand.id,{deltaX:O,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(a.toDisposable(o.onDblclickObserver.add(()=>{var c;if(e===0){const d=this._getSheetObject();if(d==null)return;const{scene:u}=d;u.resetCursor(),this._commandService.executeCommand(g.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e;n.onPointerMoveObserver.remove(this._moveObserver),n.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Bn=wd([a.OnLifecycle(a.LifecycleStages.Rendered,Bn),Gt(0,D.Inject(A.SheetSkeletonManagerService)),Gt(1,a.IUniverInstanceService),Gt(2,a.ICommandService),Gt(3,b.IRenderManagerService),Gt(4,be)],Bn);var Hi=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(Hi||{});const Kt=12,Od=.4;class Pr extends b.Shape{constructor(n,t,o){super(n,t);C(this,"_size",Kt);C(this,"_iconRatio",Od);C(this,"_hovered",!0);C(this,"_hasPrevious",!0);C(this,"_hasNext",!0);C(this,"_unhideType");t&&this.setShapeProps(t),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(n){n.type!==void 0&&(this._unhideType=n.type),n.hovered!==void 0&&(this._hovered=n.hovered),n.hasPrevious!==void 0&&(this._hasPrevious=n.hasPrevious),n.hasNext!==void 0&&(this._hasNext=n.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(n){this._unhideType===0?this._drawOnRow(n):this._drawOnCol(n)}_drawOnRow(n){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(n,{width:this._size,height:this._size,stroke:We,fill:Un}):b.Rect.drawWith(n,{width:this._size,height:2*this._size,stroke:We,fill:Un}));const t=this._size*.5*this._iconRatio,o=Math.PI/3,r=t*Math.cos(o),s=t*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:this._size/2,y:this._size/2-s},{x:this._size/2-s,y:this._size/2+r},{x:this._size/2+s,y:this._size/2+r}]],fill:We}),this._hasNext){const l=this._hasPrevious?3:1;b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:this._size/2,y:this._size*l/2+s},{x:this._size/2-s,y:this._size*l/2-r},{x:this._size/2+s,y:this._size*l/2-r}]],fill:We})}}_drawOnCol(n){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(n,{width:this._size,height:this._size,stroke:We,fill:Un}):b.Rect.drawWith(n,{width:2*this._size,height:this._size,stroke:We,fill:Un}));const t=this._size*.5*this._iconRatio,o=Math.PI/3,r=t*Math.cos(o),s=t*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:-r+this._size/2,y:this._size/2},{x:this._size/2+s,y:this._size/2-s},{x:this._size/2+s,y:this._size/2+s}]],fill:We}),this._hasNext){const l=this._hasPrevious?3:1;b.RegularPolygon.drawWith(n,{pointsGroup:[[{x:r+this._size*l/2,y:this._size/2},{x:-s+this._size*l/2,y:this._size/2-s},{x:-s+this._size*l/2,y:this._size/2+s}]],fill:We})}}}var xd=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,Nd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Ad(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&xd(e,n,o),o},Fn=(i,e)=>(n,t)=>e(n,t,i);const Hr="__SpreadsheetHeaderUnhideSHAPEControllerShape__",Dd=[g.SetRowHiddenMutation.id,g.SetRowVisibleMutation.id,g.SetColHiddenMutation.id,g.SetColVisibleMutation.id];let Wn=class extends a.RxDisposable{constructor(e,n,t,o){super();C(this,"_shapes",new Map);this._sheetSkeletonManagerService=e,this._cmdSrv=n,this._univerInstanceService=t,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const n=this._univerInstanceService.getCurrentUniverSheetInstance(),t=n.getActiveSheet();t&&this._initForWorksheet(n,t),this._sheetSkeletonManagerService.currentSkeleton$.pipe(P.takeUntil(this.dispose$),P.startWith(void 0),P.pairwise()).subscribe(([o,r])=>{if(r){const s=this._univerInstanceService.getUniverSheetInstance(r.unitId),l=s.getSheetBySheetId(r.sheetId);this._updateWorksheet(s,l,o==null?void 0:o.sheetId)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!Dd.includes(o.id)||!o.params||!o.params.unitId||!o.params.subUnitId)return;const r=this._univerInstanceService.getUniverSheetInstance(o.params.unitId),s=r==null?void 0:r.getSheetBySheetId(o.params.subUnitId);s&&this._updateWorksheet(r,s,s.getSheetId())}))}_initForWorksheet(e,n){var m;const t=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!t)return;const o=n.getHiddenRows(),r=n.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:l}=s,c=n.getRowCount(),d=o.map(_=>{const{startRow:S,endRow:f}=_,v=yi(S,0,l,t),M=S!==0,R=f!==c-1;return new Pr(Hr,{type:Hi.ROW,hovered:!1,hasPrevious:M,hasNext:R,top:v.startY-(M?Kt:0),left:v.startX-Kt},()=>this._cmdSrv.executeCommand(g.SetSpecificRowsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),ranges:[_]}))}),u=n.getColumnCount(),h=r.map(_=>{const{startColumn:S,endColumn:f}=_,v=yi(0,S,l,t),M=S!==0,R=f!==u-1;return new Pr(Hr,{type:Hi.COLUMN,hovered:!1,hasPrevious:M,hasNext:R,left:v.startX-(M?Kt:0),top:20-Kt},()=>this._cmdSrv.executeCommand(g.SetSpecificColsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),ranges:[_]}))});l.addObjects(h,go),l.addObjects(d,go),this._shapes.set(a.getWorksheetUID(e,n),{cols:h,rows:d})}_updateWorksheet(e,n,t){if(t){const o=this._shapes.get(`${e.getUnitId()}|${t}`);o==null||o.cols.forEach(r=>r.dispose()),o==null||o.rows.forEach(r=>r.dispose())}this._initForWorksheet(e,n)}_getSheetObject(){return ve(this._univerInstanceService,this._rendererManagerService)}};Wn=Nd([a.OnLifecycle(a.LifecycleStages.Rendered,Wn),Fn(0,D.Inject(A.SheetSkeletonManagerService)),Fn(1,a.ICommandService),Fn(2,a.IUniverInstanceService),Fn(3,b.IRenderManagerService)],Wn);var Pd=Object.defineProperty,Hd=Object.getOwnPropertyDescriptor,Ld=(i,e,n,t)=>{for(var o=t>1?void 0:t?Hd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Pd(e,n,o),o},Li=(i,e)=>(n,t)=>e(n,t,i);let jn=class extends a.Disposable{constructor(i,e,n){super(),this._markSelectionService=i,this._commandService=e,this._sheetSkeletonManagerService=n,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[Pe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)?this._markSelectionService.removeAllShapes():this._markSelectionService.getShapeMap().forEach((t,o)=>{t.exits.includes(e.id)&&this._markSelectionService.removeShape(o)})}))}_addRefreshListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};jn=Ld([a.OnLifecycle(a.LifecycleStages.Steady,jn),Li(0,D.Inject(Ht)),Li(1,a.ICommandService),Li(2,D.Inject(A.SheetSkeletonManagerService))],jn);var Ud=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Vd=(i,e,n,t)=>{for(var o=t>1?void 0:t?kd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Ud(e,n,o),o},Ui=(i,e)=>(n,t)=>e(n,t,i);let zn=class extends a.Disposable{constructor(e,n,t){super();C(this,"_initialize",()=>{const e=new a.DisposableCollection;this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{e.dispose();const n=this._selectionManagerService.getCurrent();if((n==null?void 0:n.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{e.add(a.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),l={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn,rangeType:s.rangeType},c={startRow:r.startRow,startColumn:r.startColumn,endRow:r.endRow,endColumn:r.endColumn,rangeType:s.rangeType};if(l.startRow===c.startRow&&l.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:l,toRange:c};this._commandService.executeCommand(g.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=e,this._selectionManagerService=n,this._commandService=t,this._initialize()}};zn=Vd([a.OnLifecycle(a.LifecycleStages.Steady,zn),Ui(0,D.Inject(Se)),Ui(1,D.Inject(g.SelectionManagerService)),Ui(2,D.Inject(a.ICommandService))],zn);var Bd=Object.defineProperty,Fd=Object.getOwnPropertyDescriptor,Wd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Fd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Bd(e,n,o),o},bt=(i,e)=>(n,t)=>e(n,t,i);let wt=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}scrollToVisible(i=!0){var W,B,z,Y;let e,n;const t=this._selectionManagerService.getLast();if(t==null)return;const{startRow:o,startColumn:r,actualRow:s,actualColumn:l}=t.primary,c=i?s:o,d=i?l:r,{rowHeightAccumulation:u,columnWidthAccumulation:h}=(B=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton)!=null?B:{};if(u==null||h==null)return;const m=(z=this._getSheetObject())==null?void 0:z.scene;if(m==null)return;const _=m.getViewport(V.VIEW_MAIN);if(_==null||this._getSheetObject()==null)return;const f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:v,startRow:M,ySplit:R,xSplit:T}=f.getFreeze(),E=_.getBounding(),w=(Y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Y.skeleton;if(w==null)return;const{startRow:y,startColumn:O,endRow:x,endColumn:N}=w.getRowColumnSegment(E);if(c>=M&&d>=v-T&&(c<=y&&(e=c),c>=x)){const J=u[c]-_.height;for(let j=y;j<=c;j++)if(u[j]>=J){e=j+1;break}}if(d>=v&&c>=M-R&&(d<=O&&(n=d),d>=N)){const J=h[d]-_.width;for(let j=O;j<=d;j++)if(h[j]>=J){n=j+1;break}}if(e===void 0&&n===void 0)return;const{offsetX:F,offsetY:L}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(It.id,{sheetViewStartRow:e,sheetViewStartColumn:n,offsetX:n===void 0?F:0,offsetY:e===void 0?L:0})}dispose(){super.dispose()}_initialize(){this._scrollEventBinding(),this._scrollSubscribeBinding(),this._skeletonListener()}_getFreeze(){var e;const i=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_scrollEventBinding(){var n;const i=(n=this._getSheetObject())==null?void 0:n.scene;if(i==null)return;const e=i.getViewport(V.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollAfterObserver.add(t=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=t,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,l);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollByBarObserver.add(t=>{var _;const o=(_=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_.skeleton;if(o==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=t,c=this._getFreeze(),{row:d,column:u,rowOffset:h,columnOffset:m}=o.getDecomposedOffset(s,l);this._commandService.executeCommand(It.id,{sheetViewStartRow:d+((c==null?void 0:c.ySplit)||0),sheetViewStartColumn:u+((c==null?void 0:c.xSplit)||0),offsetX:m,offsetY:h})})))}_scrollSubscribeBinding(){this.disposeWithMe(a.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var S;const e=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,n=this._getSheetObject();if(e==null||n==null)return;const t=n.scene;n.scene.getAncestorScale();const o=t.getViewport(V.VIEW_MAIN);if(o==null)return;if(i==null){o.scrollTo({x:0,y:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:l,offsetY:c}=i,{startX:d,startY:u}=e.getCellByIndexWithNoHeader(r,s),h=d+l,m=u+c,_=o.getBarScroll(h,m);o.scrollTo(_)})))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:n}=i;this._renderManagerService.getRenderById(e)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:e,sheetId:n}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:e,unitId:n}=i,t=(c=this._renderManagerService.getRenderById(n))==null?void 0:c.scene;if(e==null||t==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:l}=e;t==null||t.transformByState({width:s+r,height:l+o})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};wt=Wd([a.OnLifecycle(a.LifecycleStages.Rendered,wt),bt(0,D.Inject(A.SheetSkeletonManagerService)),bt(1,a.IUniverInstanceService),bt(2,a.ICommandService),bt(3,b.IRenderManagerService),bt(4,D.Inject(g.SelectionManagerService)),bt(5,D.Inject(Je))],wt);var jd=Object.defineProperty,zd=Object.getOwnPropertyDescriptor,Yd=(i,e,n,t)=>{for(var o=t>1?void 0:t?zd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&jd(e,n,o),o},Lr=(i,e)=>(n,t)=>e(n,t,i);const Xd=[Re.id,it.id];let Yn=class extends a.Disposable{constructor(i,e){super(),this._commandService=i,this._scrollController=e,this.disposeWithMe(this._commandService.onCommandExecuted(n=>{Xd.includes(n.id)&&this._scrollController.scrollToVisible()}))}};Yn=Yd([a.OnLifecycle(a.LifecycleStages.Rendered,Yn),Lr(0,a.ICommandService),Lr(1,D.Inject(wt))],Yn);var $d=Object.defineProperty,Zd=Object.getOwnPropertyDescriptor,Gd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Zd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&$d(e,n,o),o},Qe=(i,e)=>(n,t)=>e(n,t,i);let Xn=class extends a.Disposable{constructor(i,e,n,t,o,r,s,l){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._scrollController=l,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),e=i.getActiveSheet(),n=this._getSheetObject();if(n==null)return;this._initViewMainListener(n),this._initRowHeader(n),this._initColumnHeader(n),this._initLeftTop(n),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const t=i.getUnitId(),o=e.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:g.NORMAL_SELECTION_PLUGIN_NAME,unitId:t,sheetId:o})}_getActiveViewport(i){const e=this._getSheetObject();return e==null?void 0:e.scene.getActiveViewportByCoord(b.Vector2.FromArray([i.offsetX,i.offsetY]))}_initViewMainListener(i){const{spreadsheet:e}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,t)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,e.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(n)),n.button!==2&&t.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(()=>{this._selectionRenderService.resetStyle();const i=this._selectionManagerService.getSelections(),e=this._selectionManagerService.getCurrent();i==null||(e==null?void 0:e.pluginName)!==g.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){const e=i.map(n=>{const t=this._selectionRenderService.convertSelectionRangeToData(n);return t.style=g.getNormalSelectionStyle(this._themeService),t});this._selectionRenderService.updateControlForCurrentByRangeData(e)}_initRowHeader(i){const{spreadsheetRowHeader:e,spreadsheet:n}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,((n==null?void 0:n.zIndex)||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(t),b.ScrollTimerType.Y),t.button!==2&&o.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:e,spreadsheet:n}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,((n==null?void 0:n.zIndex)||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(t),b.ScrollTimerType.X),t.button!==2&&o.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:e}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,t)=>{var l;const o=(l=this._sheetSkeletonManagerService.getCurrent())==null?void 0:l.skeleton;if(o==null)return;this._selectionRenderService.reset();const r=this._getAllRange(o),s=this._selectionRenderService.convertSelectionRangeToData(r);this._selectionRenderService.addControlToCurrentByRangeData(s),this._selectionRenderService.refreshSelectionMoveStart(),n.button!==2&&t.stopPropagation()})))}_initSelectionChangeListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const e of i){if(e==null)continue;const n=this._selectionRenderService.convertSelectionRangeToData(e);this._selectionRenderService.addControlToCurrentByRangeData(n)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,g.SelectionMoveType.MOVE_END)})}_move(i,e){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getUnitId(),o=n.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(g.SetSelectionsOperation.id,{unitId:t,subUnitId:o,type:e,pluginName:(r==null?void 0:r.pluginName)||g.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>g.convertSelectionDataToRange(s))})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===n.getUnitId()&&s===t.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:n,skeleton:t}=i,o=this._renderManagerService.getRenderById(e);if(o==null)return;const{scene:r}=o,s=r.getViewport(V.VIEW_MAIN);this._selectionRenderService.changeRuntime(t,r,s);const l=this._selectionManagerService.getCurrent(),c=(l==null?void 0:l.pluginName)||g.NORMAL_SELECTION_PLUGIN_NAME;if((l==null?void 0:l.unitId)===e&&l.sheetId===n){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:e,sheetId:n});c===g.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(t)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const e=i.mergeData;return g.transformCellDataToSelectionData(0,0,e)||{range:{startRow:0,startColumn:0,endRow:0,endColumn:0},primary:{actualRow:0,actualColumn:0,startRow:0,startColumn:0,endRow:0,endColumn:0,isMerged:!1,isMergedMainCell:!1},style:null}}};Xn=Gd([a.OnLifecycle(a.LifecycleStages.Rendered,Xn),Qe(0,D.Inject(A.SheetSkeletonManagerService)),Qe(1,a.IUniverInstanceService),Qe(2,a.ICommandService),Qe(3,b.IRenderManagerService),Qe(4,Se),Qe(5,D.Inject(g.SelectionManagerService)),Qe(6,D.Inject(a.ThemeService)),Qe(7,D.Inject(wt))],Xn);var Kd=Object.defineProperty,Jd=Object.getOwnPropertyDescriptor,Qd=(i,e,n,t)=>{for(var o=t>1?void 0:t?Jd(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Kd(e,n,o),o},Tt=(i,e)=>(n,t)=>e(n,t,i);let $n=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=n,this._commandService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:n,sheetId:t}=i,o=this._currentUniverService.getUniverSheetInstance(n),r=o==null?void 0:o.getSheetBySheetId(t);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:l,components:c,scene:d}=s,u=l,h=c.get(fe.ROW),m=c.get(fe.COLUMN),_=c.get(fe.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=e;u==null||u.updateSkeleton(e),h==null||h.updateSkeleton(e),m==null||m.updateSkeleton(e),_==null||_.transformByState({width:S,height:f})})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((i,e)=>{var o,r;const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getUnitId();if(g.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const s=n.getActiveSheet(),l=s.getSheetId(),c=i.params,{unitId:d,subUnitId:u}=c;if(!(d===n.getUnitId()&&u===s.getSheetId()))return;i.id!==g.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:d,sheetId:l,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:d,sheetId:l,commandId:i.id})}else g.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===a.CommandType.MUTATION&&((r=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.mainComponent)==null||r.makeDirty())}))}};$n=Qd([a.OnLifecycle(a.LifecycleStages.Ready,$n),Tt(0,D.Inject(A.SheetSkeletonManagerService)),Tt(1,a.IUniverInstanceService),Tt(2,b.IRenderManagerService),Tt(3,a.ICommandService),Tt(4,Se),Tt(5,D.Inject(g.SelectionManagerService))],$n);const je={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,e)=>{const n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(I.IConfirmService),s=i.get(a.LocaleService),l=e.unitId,c=e.subUnitId,d=e.selections,u=g.getAddMergeMutationRangeByType(d,e.value),h=o.getUniverSheetInstance(l).getSheetBySheetId(c),m=[],_=[],S=lr(h,u);if(S&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const f={unitId:l,subUnitId:c,ranges:u},v={unitId:l,subUnitId:c,ranges:u};m.push({id:g.RemoveWorksheetMergeMutation.id,params:f}),m.push({id:g.AddWorksheetMergeMutation.id,params:v});const M=g.RemoveMergeUndoMutationFactory(i,f),R=g.AddMergeUndoMutationFactory(i,v);if(_.push({id:g.RemoveWorksheetMergeMutation.id,params:R}),_.push({id:g.AddWorksheetMergeMutation.id,params:M}),S){const E=cr(i,l,h,u);m.unshift(...E.redos),_.push(...E.undos)}return a.sequenceExecute(m,n).result?(t.pushUndoRedo({unitID:l,undoMutations:_,redoMutations:m}),!0):!1}},Ur={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{selections:t,unitId:l,subUnitId:c})}},kr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:a.Dimension.COLUMNS,selections:t,unitId:l,subUnitId:c})}},Vr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(g.SelectionManagerService).getSelectionRanges();if(!(t!=null&&t.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:a.Dimension.ROWS,selections:t,unitId:l,subUnitId:c})}},ki={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=_=>_.endRow-_.startRow;return!c.getMergeData().find(_=>{const S=a.Rectangle.getIntersects(_,d);return S?u(_)>u(S):!1})||await e.confirm({id:ki.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.DeleteRangeMoveLeftCommand.id):!0}},Vi={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=_=>_.endColumn-_.startColumn;return!c.getMergeData().find(_=>{const S=a.Rectangle.getIntersects(_,d);return S?u(_)>u(S):!1})||await e.confirm({id:Vi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.DeleteRangeMoveUpCommand.id):!0}},Bi={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=_=>_.endColumn-_.startColumn;return!c.getMergeData().find(_=>{const S=a.Rectangle.getIntersects(_,d);return S?u(_)>u(S):!1})||await e.confirm({id:Bi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.InsertRangeMoveDownCommand.id):!0}},Fi={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async i=>{const e=i.get(I.IConfirmService),n=i.get(a.ICommandService),t=i.get(a.LocaleService),o=i.get(g.SelectionManagerService),r=i.get(a.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=_=>_.endRow-_.startRow;return!c.getMergeData().find(_=>{const S=a.Rectangle.getIntersects(_,d);return S?u(_)>u(S):!1})||await e.confirm({id:Fi.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?n.executeCommand(g.InsertRangeMoveRightCommand.id):!0}},Br={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(i,e)=>{const n=i.get(Ft);return n.applyType=e.type,!0}},Fr={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{var d;const n=i.get(g.SelectionManagerService);let t=e==null?void 0:e.range;if(t||(t=(d=n.getLast())==null?void 0:d.range),!t)return!1;const o=i.get(a.ICommandService),c=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(Uo(c,[t])){const u=i.get(I.IConfirmService),h=i.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(g.RemoveRowCommand.id,{range:t}),!0}},Wr={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{var d;const n=i.get(g.SelectionManagerService);let t=e==null?void 0:e.range;if(t||(t=(d=n.getLast())==null?void 0:d.range),!t)return!1;const o=i.get(a.ICommandService),c=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(ko(c,[t])){const u=i.get(I.IConfirmService),h=i.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(g.RemoveColCommand.id,{range:t}),!0}},jr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{const{subUnitId:n}=e,t=i.get(I.IConfirmService),o=i.get(a.ICommandService),r=i.get(a.LocaleService);return await t.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:r.t("sheetConfig.deleteSheet")},children:{title:r.t("sheetConfig.deleteSheetContent")},cancelText:r.t("button.cancel"),confirmText:r.t("button.confirm")})?(await o.executeCommand(g.RemoveSheetCommand.id,{subUnitId:n}),!0):!1}},Et=D.createIdentifier("univer.sheetbar-service");class qd extends a.Disposable{constructor(){super();C(this,"renameId$");C(this,"removeId$");C(this,"scroll$");C(this,"scrollX$");C(this,"addSheet$");C(this,"_renameId$");C(this,"_removeId$");C(this,"_scroll$");C(this,"_scrollX$");C(this,"_addSheet$");C(this,"_currentHandler",null);this._renameId$=new P.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new P.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new P.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new P.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new P.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(n){this._renameId$.next(n)}setRemoveId(n){this._removeId$.next(n)}setScroll(n){this._scroll$.next(n)}setScrollX(n){this._scrollX$.next(n)}setAddSheet(n){this._addSheet$.next(n)}triggerSheetBarMenu(){var n;(n=this._currentHandler)==null||n.handleSheetBarMenu()}registerSheetBarMenuHandler(n){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=n,a.toDisposable(()=>{this._currentHandler=null})}}const zr={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async i=>(i.get(Et).triggerSheetBarMenu(),!0)},Yr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(i,e)=>{const n=i.get(Et);return e&&n.setRenameId(e.subUnitId),!0}},eu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),p.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),p.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),p.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),p.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),p.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),p.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),p.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),p.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),p.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),p.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),p.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),p.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),p.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),p.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),p.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),p.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),p.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),tu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),p.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),p.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),p.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),p.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),p.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),p.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),p.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),p.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),p.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),p.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),p.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),nu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),p.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),p.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),p.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),p.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),p.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),p.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),p.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),p.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),p.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),p.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),p.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),p.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),p.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),p.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),p.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),p.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),p.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),p.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),p.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),iu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),p.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),p.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),p.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),p.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),p.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),p.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),p.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),p.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),p.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),p.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),p.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),p.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),p.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),p.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),p.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),p.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),p.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),p.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),p.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),p.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),p.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),p.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),p.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),p.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),p.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),p.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),p.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),p.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),p.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),p.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),p.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),p.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),p.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),p.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),p.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),p.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),p.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),p.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),p.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),p.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),p.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),p.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),ou=()=>p.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),ru=()=>p.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),p.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),p.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),p.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),p.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),p.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),su=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),p.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),p.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),p.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),au=()=>p.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),p.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),p.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),p.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),p.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),p.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),p.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),p.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),p.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),p.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),p.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),p.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),p.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),p.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),p.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),p.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),p.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),p.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),p.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),p.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),lu=()=>p.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),Xr=()=>p.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function $r(i){const{type:e=a.BorderStyleTypes.THIN}=i;switch(e){case a.BorderStyleTypes.DASH_DOT:return p.jsx(eu,{});case a.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(tu,{});case a.BorderStyleTypes.DASHED:return p.jsx(nu,{});case a.BorderStyleTypes.HAIR:return p.jsx(iu,{});case a.BorderStyleTypes.MEDIUM:return p.jsx(ou,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(ru,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(su,{});case a.BorderStyleTypes.MEDIUM_DASHED:return p.jsx(au,{});case a.BorderStyleTypes.THICK:return p.jsx(lu,{});case a.BorderStyleTypes.THIN:return p.jsx(Xr,{});default:return p.jsx(Xr,{})}}const ze={uiPluginSheetsBorderPanel:"univer-ui-plugin-sheets-border-panel",uiPluginSheetsBorderPanelPosition:"univer-ui-plugin-sheets-border-panel-position",uiPluginSheetsBorderPanelPositionItem:"univer-ui-plugin-sheets-border-panel-position-item",uiPluginSheetsBorderPanelStyles:"univer-ui-plugin-sheets-border-panel-styles",uiPluginSheetsBorderPanelBoard:"univer-ui-plugin-sheets-border-panel-board",uiPluginSheetsBorderPanelButton:"univer-ui-plugin-sheets-border-panel-button",uiPluginSheetsBorderPanelMoreIcon:"univer-ui-plugin-sheets-border-panel-more-icon"},Zr=`${gt}_BORDER_PANEL_COMPONENT`,Gr=[{label:"borderLine.borderTop",icon:"UpBorder",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorder",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorder",value:"left"},{label:"borderLine.borderRight",icon:"RightBorder",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderSingle",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderSingle",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorder",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorder",value:"inside"},{label:"borderLine.borderHorizontal",icon:"InnerBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"InnerBorder",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashSingle",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalSingle",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalSingle",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashSingle",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalSingle",value:"mltr_bctr"}],cu=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function du(i){var l;const e=K.useDependency(I.ComponentManager),{onChange:n,value:t}=i;function o(c,d){n==null||n({...t,[d]:c})}function r(c){const d=e.get(c);return d&&p.jsx(d,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function s(c){c.stopPropagation()}return p.jsxs("section",{className:ze.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:ze.uiPluginSheetsBorderPanelPosition,children:Gr.map(c=>p.jsx("div",{className:ze.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(c.value,"type"),children:r(c.icon)},c.value))}),p.jsxs("div",{className:ze.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(_e.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:ze.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(_e.ColorPicker,{onChange:c=>o(c,"color")})}),children:p.jsxs("a",{className:ze.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(qa,{extend:{colorChannel1:(l=t.color)!=null?l:"rgb(var(--primary-color))"}}),p.jsx("span",{className:ze.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Si,{})})]})})}),p.jsx("div",{children:p.jsx(_e.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(_e.Menu,{children:cu.map(c=>p.jsx(_e.MenuItem,{eventKey:c.value.toString(),onClick:()=>o(c.value,"style"),children:p.jsx($r,{type:c.value})},c.value))})}),children:p.jsxs("a",{className:ze.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx($r,{type:a.BorderStyleTypes.THIN}),p.jsx("span",{className:ze.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Si,{})})]})})})]})]})}const uu={countBar:"univer-count-bar"},hu=[50,80,100,130,150,170,200,400],mu=100;function _u(){const i=K.useDependency(a.ICommandService),e=K.useDependency(a.IUniverInstanceService),n=K.useDependency(a.IContextService),t=c(),[o,r]=H.useState(t),l=!_e.useObservable(()=>P.combineLatest(n.subscribeContextValue$(a.FOCUSING_UNIVER_EDITOR),n.subscribeContextValue$(a.EDITOR_ACTIVATED)).pipe(P.map(([u,h])=>u&&!h),P.debounceTime(mu)),!1,!0,[a.FOCUSING_UNIVER_EDITOR]);H.useEffect(()=>i.onCommandExecuted(h=>{if(h.id===Be.id||h.id===g.SetWorksheetActivateCommand.id){const m=c();r(m)}}).dispose,[i]);function c(){const u=e.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()*100||100;return Math.round(u)}function d(u){r(u);const h=e.getCurrentUniverSheetInstance(),m=h==null?void 0:h.getActiveSheet();if(m==null)return;const _=u/100;i.executeCommand(Nn.id,{unitId:h.getUnitId(),subUnitId:m.getSheetId(),zoomRatio:_})}return p.jsx(_e.Slider,{disabled:l,min:ri[0],value:o,shortcuts:hu,onChange:d})}function Su(i){return p.jsx("section",{className:uu.countBar,children:p.jsx(_u,{})})}const Kr={editorContainer:"univer-editor-container",editorInput:"univer-editor-input"},Zn=-1e3,Jr={width:0,height:0,top:Zn,left:Zn},gu=()=>{const[i,e]=H.useState({...Jr}),n=H.useRef(null),t=K.useDependency(b.IRenderManagerService),o=K.useDependency(zt);return H.useEffect(()=>{const r=n.current;if(!r)return;const s=t.currentRender$.pipe(qi.switchMap(()=>{var c;const l=(c=t.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:c.engine;return l==null||l.setContainer(r),o.state$})).subscribe(l=>{if(l==null)return;const{startX:c=Zn,startY:d=Zn,endX:u=0,endY:h=0,show:m=!1}=l;if(!m)e({...Jr});else{e({width:u-c,height:h-d,left:c,top:d});const _=n.current;if(!_)return;const{left:S,top:f,width:v,height:M}=_.getBoundingClientRect();o.setRect({left:S,top:f,width:v,height:M})}});return()=>{s.unsubscribe()}},[]),H.useEffect(()=>{o.setFocus(!0)},[i]),p.jsx("div",{className:Kr.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx("div",{className:Kr.editorInput,ref:n})})},he={formulaBox:"univer-formula-box",nameRanges:"univer-name-ranges",nameRangesInput:"univer-name-ranges-input",formulaBar:"univer-formula-bar",formulaIcon:"univer-formula-icon",formulaIconWrapper:"univer-formula-icon-wrapper",iconContainer:"univer-icon-container",iconContainerSuccess:"univer-icon-container-success",formulaActive:"univer-formula-active",iconContainerError:"univer-icon-container-error",formulaInput:"univer-formula-input",formulaContent:"univer-formula-content",arrowContainer:"univer-arrow-container"};function fu(){const[i,e]=H.useState(he.formulaGrey),[n,t]=H.useState(0),o=H.useRef(null),r=K.useDependency(b.IRenderManagerService),s=K.useDependency(In),l=K.useDependency(be);H.useEffect(()=>{const m=o.current;if(!m)return;const _=r.currentRender$.subscribe(f=>{var M;if(f!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const v=(M=r.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:M.engine;v==null||v.setContainer(m)}),S=new ResizeObserver(()=>{const f=m.getBoundingClientRect();s.setPosition(f)});return S.observe(m),l.visible$.subscribe(f=>{e(f.visible?he.formulaActive:he.formulaGrey)}),()=>{S.unobserve(m),_.unsubscribe()}},[]);function c(){t(n===0?1:0),setTimeout(()=>{s.handleFoldBtnClick(n===1)},150)}function d(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC})}function u(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})}function h(){s.handleFxBtnClick(!0)}return p.jsxs("div",{className:he.formulaBox,style:{height:n===0?"28px":"82px"},children:[p.jsx("div",{className:he.nameRanges,children:p.jsx("div",{className:he.nameRangesInput})}),p.jsxs("div",{className:he.formulaBar,children:[p.jsx("div",{className:he.formulaIcon,children:p.jsxs("div",{className:he.formulaIconWrapper,children:[p.jsx("span",{className:Nt(he.iconContainer,he.iconContainerError,i),onClick:d,children:p.jsx(Ba,{})}),p.jsx("span",{className:Nt(he.iconContainer,he.iconContainerSuccess,i),onClick:u,children:p.jsx(gn,{})}),p.jsx("span",{className:he.iconContainer,onClick:h,children:p.jsx($a,{})})]})}),p.jsxs("div",{className:he.formulaInput,children:[p.jsx("div",{onContextMenu:m=>m.preventDefault(),className:he.formulaContent,ref:o}),p.jsx("div",{className:he.arrowContainer,onClick:c,children:n===0?p.jsx(Zo,{}):p.jsx(Zo,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const rt={operateContainer:"univer-operate-container",autoFillPopupMenu:"univer-auto-fill-popup-menu",autoFillPopupMenuItem:"univer-auto-fill-popup-menu-item",autoFillPopupMenuItemIcon:"univer-auto-fill-popup-menu-item-icon",autoFillPopupMenuItemTitle:"univer-auto-fill-popup-menu-item-title",autoFillPopupMenuItemHide:"univer-auto-fill-popup-menu-item-hide",btnContainer:"univer-btn-container",btnContainerExpand:"univer-btn-container-expand"},pu=()=>{const[,i]=H.useState({});return H.useCallback(()=>i(e=>!e),[])},vu=()=>{var se;const i=K.useDependency(a.ICommandService),e=K.useDependency(A.SheetSkeletonManagerService),n=K.useDependency(a.IUniverInstanceService),t=K.useDependency(b.IRenderManagerService),o=K.useDependency(Se),r=K.useDependency(Ft),s=K.useDependency(a.LocaleService),[l,c]=H.useState([]),[d,u]=H.useState(!1),[h,m]=H.useState({row:-1,col:-1}),[_,S]=H.useState(re.SERIES),[f,v]=H.useState(!1),M=()=>{v(!0)},R=()=>{v(!1)},T=pu(),E=ve(n,t);if(E==null)return null;const{scene:w}=E;if(H.useEffect(()=>{const $=[Pe.id,cn.id,Be.id,g.SetWorksheetActiveOperation.id,g.MoveRangeMutation.id];return i.onCommandExecuted(U=>{U.id===mt.id&&T(),$.includes(U.id)&&m({row:-1,col:-1})}).dispose},[T,i]),H.useEffect(()=>a.toDisposable(r.menu$.subscribe(k=>{c(k.map(U=>({...U,index:k.indexOf(U)})))})).dispose,[r]),H.useEffect(()=>a.toDisposable(r.showMenu$.subscribe(k=>{const{source:U,target:Z}=r.autoFillLocation||{source:null,target:null};if(k&&U&&Z){const ie=a.Rectangle.union(U,Z);m({row:ie.endRow,col:ie.endColumn})}})).dispose,[r]),H.useEffect(()=>a.toDisposable(r.applyType$.subscribe(k=>{S(k)})).dispose,[r]),H.useEffect(()=>{function $(){u(!1)}return document.addEventListener("wheel",$),()=>{document.removeEventListener("wheel",$)}},[d]),h.col<0||h.row<0)return null;const y=(se=e.getCurrent())==null?void 0:se.skeleton,O=o.getViewPort(),x=w==null?void 0:w.scaleX,N=w==null?void 0:w.scaleY,F=w==null?void 0:w.getScrollXY(O);if(!x||!w||!x||!N||!F)return null;const L=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endX)||0,W=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endY)||0,B=y==null?void 0:y.convertTransformToOffsetX(L,x,F),z=y==null?void 0:y.convertTransformToOffsetY(W,N,F);if(B==null||z==null)return null;const Y=$=>{u($)},J=$=>{i.executeCommand(Br.id,{type:$.value})},j=d||f,q=l.filter($=>!$.disable);return p.jsx("div",{onMouseEnter:M,onMouseLeave:R,style:{left:`${B+2}px`,top:`${z+2}px`,position:"absolute"},children:p.jsx(_e.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:rt.autoFillPopupMenu,children:q.map($=>p.jsxs("li",{onClick:()=>J($),className:rt.autoFillPopupMenuItem,children:[p.jsx("span",{className:rt.autoFillPopupMenuItemIcon,children:$.value===_&&p.jsx(gn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:rt.autoFillPopupMenuItemTitle,children:s.t($.label)})]},$.index))}),visible:d,onVisibleChange:Y,children:p.jsxs("div",{className:Nt(rt.btnContainer,{[rt.btnContainerExpand]:d}),children:[p.jsx(Ua,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),j&&p.jsx(Si,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},Cu=()=>p.jsx("div",{className:rt.operateContainer,children:p.jsx(vu,{})}),Gn={sheetBar:"univer-sheet-bar",sheetBarOptions:"univer-sheet-bar-options",sheetBarOptionsDivider:"univer-sheet-bar-options-divider"},Iu={sheetBarBtn:"univer-sheet-bar-btn"};function Kn(i){const{children:e,className:n,style:t,disabled:o=!1,onClick:r,...s}=i,l=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:Iu.sheetBarBtn,style:t,disabled:o,onClick:l,...s,children:e})}const qe={sheetBarMenu:"univer-sheet-bar-menu",sheetBarMenuItem:"univer-sheet-bar-menu-item",sheetBarMenuItemIcon:"univer-sheet-bar-menu-item-icon",sheetBarMenuItemHide:"univer-sheet-bar-menu-item-hide",sheetBarMenuItemSelect:"univer-sheet-bar-menu-item-select",sheetBarMenuItemLabel:"univer-sheet-bar-menu-item-label"};function Mu(i){const{style:e}=i,[n,t]=H.useState([]),[o,r]=H.useState(!1),s=K.useDependency(a.IUniverInstanceService),l=K.useDependency(a.ICommandService),c=K.useDependency(Et),d=s.getCurrentUniverSheetInstance(),u=f=>{const{sheetId:v}=f;v&&(f.hidden?l.executeCommand(g.SetWorksheetShowCommand.id,{value:v}):f.selected||l.executeCommand(g.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:v}),r(!1))};H.useEffect(()=>{m();const f=new a.DisposableCollection;return f.add(h()),f.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:_})),()=>{f.dispose()}},[]);const h=()=>l.onCommandExecuted(f=>{switch(f.id){case g.SetWorksheetHideMutation.id:case g.RemoveSheetMutation.id:case g.SetWorksheetNameMutation.id:case g.InsertSheetMutation.id:case g.SetWorksheetOrderMutation.id:case g.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const f=d.getSheets(),v=d.getActiveSheet(),M=f.map((R,T)=>({label:R.getName(),index:`${T}`,sheetId:R.getSheetId(),hidden:R.isSheetHidden()===a.BooleanNumber.TRUE,selected:v===R}));t(M)};function _(){r(!0)}const S=f=>{r(f)};return p.jsx(_e.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:qe.sheetBarMenu,style:{...e},children:n.map(f=>p.jsxs("li",{onClick:()=>u(f),className:f.selected?`${qe.sheetBarMenuItem} ${qe.sheetBarMenuItemSelect}`:f.hidden?`${qe.sheetBarMenuItem} ${qe.sheetBarMenuItemHide}`:qe.sheetBarMenuItem,children:[p.jsx("span",{className:qe.sheetBarMenuItemIcon,children:f.selected?p.jsx(gn,{}):f.hidden?p.jsx(Ya,{}):p.jsx(gn,{})}),p.jsx("span",{className:qe.sheetBarMenuItemLabel,children:f.label})]},f.index))}),visible:o,onVisibleChange:S,children:p.jsx(Kn,{children:p.jsx(Wa,{})})})}const Ee={slideTabBarContainer:"univer-slide-tab-bar-container",slideTabBar:"univer-slide-tab-bar",slideTabItem:"univer-slide-tab-item",slideTabActive:"univer-slide-tab-active",slideTabSpan:"univer-slide-tab-span",slideTabSpanEdit:"univer-slide-tab-span-edit",slideTabItemDropdown:"univer-slide-tab-item-dropdown"};function Ru(i){const{sheetId:e,label:n,color:t,selected:o}=i,[r,s]=H.useState(o),l=K.useDependency(a.ThemeService);H.useEffect(()=>{s(o)},[o]);const c=d=>{const u=l.getCurrentTheme(),h=u.textColor,m=u.colorWhite;return new a.ColorKit(d).isDark()?m:h};return p.jsx("div",{"data-id":e,className:r?`${Ee.slideTabActive} ${Ee.slideTabItem}`:Ee.slideTabItem,style:{backgroundColor:!r&&t?t:"",color:!r&&t?c(t):"",boxShadow:r&&t?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${t}`:""},children:p.jsx("span",{className:Ee.slideTabSpan,children:n})},e)}const bu={easeOutStrong(i,e,n,t){return-n*((i=i/t-1)*i*i*i-1)+e},backOut(i,e,n,t,o){return typeof o>"u"&&(o=.7),n*((i=i/t-1)*i*((o+1)*i+o)+1)+e}},wu={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class Tu{constructor(e){C(this,"_config");C(this,"_status",0);C(this,"_start",0);C(this,"_handle",0);C(this,"_delayHandle",null);this._config={...wu,...e},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...e){let n=0;return new Promise(t=>{for(let o=0;o<e.length;o++){const r=e[o],s=r._config,l=s.success;s.loop||(s.success=d=>{n++,l&&l.call(r,d),n===e.length&&t()})}})}request(){this._config.delay===0?(this._status=0,this._start=Date.now(),this._fakeHandle()):(this._delayHandle&&clearTimeout(this._delayHandle),this._delayHandle=setTimeout(()=>{this._status=0,this._start=Date.now(),this._fakeHandle()},this._config.delay))}cancel(){this._status=1,this._delayHandle&&clearTimeout(this._delayHandle),cancelAnimationFrame(this._handle)}_fakeHandle(){let e=Date.now()-this._start;e=e>=this._config.duration?this._config.duration:e;const t=bu[this._config.type](e,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(t),this._status===1){this._config.cancel(t),this._config.complete(t);return}if(e===this._config.duration){this._config.success(t),this._config.complete(t);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class st{constructor(e,n){C(this,"_slideTabItem");C(this,"_animate");C(this,"_midline",0);C(this,"_translateX");C(this,"_scrollbar");C(this,"_slideTabBar");C(this,"_editMode");C(this,"_placeholder");this._slideTabItem=e,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=n,this._placeholder=null,this._scrollbar=n.getScrollbar(),this.update()}static midline(e){return e.getBoundingRect().x+e.getBoundingRect().width/2}static leftLine(e){return e.getBoundingRect().x}static rightLine(e){return e.getBoundingRect().x+e.getBoundingRect().width}static make(e,n){const t=[];return e.forEach(o=>t.push(new st(o,n))),t}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var e;(e=this.getEditor())==null||e.focus()}selectAll(){const e=this.getEditor();e&&yt.keepSelectAll(e)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(e){return this._translateX=e,this._slideTabItem.style.transform=`translateX(${e}px)`,this.getTranslateXDirection()}setEditor(e){let n=!0;if(this._editMode===!1){const t=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("blur",o),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",r),t.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(t==null?void 0:t.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}e&&e(d)}};let r=d=>{t&&(d.stopPropagation(),d.key==="Enter"&&t.blur())};const s=d=>{n=!1},l=d=>{n=!0},c=d=>{if(!t)return;const u=50;setTimeout(()=>{if(n){const h=t.innerText;h.length>u&&(t.innerText=h.substring(0,u),yt.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("blur",o),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",r),t.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,yt.keepSelectAll(t))}}nameCheck(){const e=this._slideTabItem.querySelector("span");if(!e)return!1;const n=e.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(n)}animate(){return{translateX:e=>{this._translateX!==e&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Tu({begin:this._translateX,end:e,receive:n=>{this._slideTabItem.style.transform=`translateX(${n}px)`}}),this._translateX=e,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(e){this._slideTabItem.after(e._slideTabItem||e)}update(){this._midline=st.midline(this)}disableFixed(){if(this._placeholder){const e=this._slideTabBar.primeval();this._slideTabItem.style.removeProperty("position"),this._slideTabItem.style.removeProperty("left"),this._slideTabItem.style.removeProperty("top"),this._slideTabItem.style.removeProperty("width"),this._slideTabItem.style.removeProperty("height"),this._slideTabItem.style.removeProperty("background"),this._slideTabItem.style.removeProperty("padding"),this._slideTabItem.style.removeProperty("box-sizing"),this._slideTabItem.style.removeProperty("font-size"),this._slideTabItem.style.removeProperty("font-family"),this._slideTabItem.style.removeProperty("font-weight"),this._slideTabItem.style.removeProperty("color"),this._slideTabItem.style.removeProperty("border-radius"),this._placeholder.after(this._slideTabItem),e.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const e=document.createElement("div"),n=this.getBoundingRect(),t=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=e,this._placeholder.style.width=`${n.width}px`,this._placeholder.style.height=`${n.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=t.margin,this._slideTabItem.style.background=t.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=t.boxSizing,this._slideTabItem.style.fontSize=t.fontSize,this._slideTabItem.style.fontFamily=t.fontFamily,this._slideTabItem.style.fontWeight=t.fontWeight,this._slideTabItem.style.color=t.color,this._slideTabItem.style.borderRadius=t.borderRadius,this._slideTabItem.style.left=`${n.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${n.y}px`,this._slideTabItem.style.width=`${n.width}px`,this._slideTabItem.style.height=`${n.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(e),document.body.appendChild(this._slideTabItem)}addEventListener(e,n,t){this._slideTabItem.addEventListener(e,n,t)}removeEventListener(e,n,t){this._slideTabItem.removeEventListener(e,n,t)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const e=this._slideTabItem.getBoundingClientRect();return e.x+=this._scrollbar.getScrollX(),e}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const e=st.midline(this);return e>this._midline?1:e<this._midline?-1:0}equals(e){return e&&e._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class Eu{constructor(e){C(this,"_slideTabBar");C(this,"_scrollX");const n=e.primeval();this._scrollX=n.scrollLeft,this._slideTabBar=e}scrollX(e){const n=this._slideTabBar.primeval();n.scrollLeft=e,this._scrollX=n.scrollLeft}scrollRight(){const e=this._slideTabBar.primeval();e.scrollLeft=e.scrollWidth,this._scrollX=e.scrollLeft}getScrollX(){return this._scrollX}}const At=class At{constructor(e){C(this,"_activeTabItemIndex",0);C(this,"_slideTabBar");C(this,"_slideTabItems",[]);C(this,"_config");C(this,"_downActionX",0);C(this,"_moveActionX",0);C(this,"_compareIndex",0);C(this,"_activeTabItem",null);C(this,"_moveAction");C(this,"_upAction");C(this,"_downAction");C(this,"_wheelAction");C(this,"_scrollIncremental",0);C(this,"_compareDirection",0);C(this,"_autoScrollTime",null);C(this,"_slideScrollbar");C(this,"_longPressTimer",null);C(this,"_leftBoundingLine",0);C(this,"_rightBoundingLine",0);C(this,"_leftMoveX",0);C(this,"_rightMoveX",0);var s;if(e.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const n=e.slideTabBarContainer.querySelector(`.${(s=e.slideTabBarClassName)!=null?s:"slide-tab-bar"}`);if(n==null)throw new Error("not found slide-tab-bar");this._slideTabBar=n,this._slideScrollbar=new Eu(this),this._config=e,this._initConfig();let t=0,o=0,r=0;this._downAction=l=>{var y,O,x,N,F,L;if((y=this._activeTabItem)!=null&&y.isEditMode())return;const c=(x=(O=l.target)==null?void 0:O.closest(`.${e.slideTabBarItemClassName}`))==null?void 0:x.getAttribute("data-id"),d=this._slideTabItems.findIndex(W=>W.getId()===c);if(c==null||d===-1)return;if(this._activeTabItemIndex!==d){(N=this._activeTabItem)==null||N.removeEventListener("pointermove",this._moveAction),(F=this._activeTabItem)==null||F.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(l,c);return}if(this._compareIndex=d,this._downActionX=l.pageX,this._moveActionX=0,this._scrollIncremental=0,this._activeTabItem=this._slideTabItems[d],!this._activeTabItem){console.error("Not found active slide-tab-item in sheet bar");return}const u=this._activeTabItem.getSlideTabItem();u==null||u.setPointerCapture(l.pointerId),(L=this._activeTabItem)==null||L.addEventListener("pointerup",this._upAction);const{x:h,width:m}=this._activeTabItem.getBoundingRect(),{x:_,width:S}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(h-f),this._rightBoundingLine=h-f+m-this._downActionX,this._leftMoveX=h-_-f,this._rightMoveX=_+S-(h+m)+f,l.button===2||this._hasEditItem())return;const{pageX:v,pageY:M}=l,R=Date.now(),T=R-r<=At.DoubleClickDelay,E=Math.abs(v-t)<10,w=Math.abs(M-o)<10;T&&E&&w&&this._activeTabItem.setEditor(),t=v,o=M,r=R,this._longPressTimer=setTimeout(()=>{var W,B;(W=this._activeTabItem)==null||W.enableFixed(),this._startAutoScroll(),u&&(u.setPointerCapture(l.pointerId),u.style.cursor="move",(B=this._activeTabItem)==null||B.addEventListener("pointermove",this._moveAction))},At.LongPressDelay)},this._upAction=l=>{var d,u,h;if(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem)return;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const c=(d=this._activeTabItem)==null?void 0:d.getSlideTabItem();c&&(c.style.cursor="",c.releasePointerCapture(l.pointerId),(u=this._activeTabItem)==null||u.removeEventListener("pointermove",this._moveAction),(h=this._activeTabItem)==null||h.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&(this.removeListener(),this._config.onSlideEnd(l,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=l=>{this._activeTabItem&&(this._moveActionX=l.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(l),this._scrollRight(l))},this._wheelAction=l=>{this.setScroll(l.deltaY)},this.addListener()}static checkedSkipSlide(e){let n=e.target;for(;n!=null&&n!==document.body;){if(n.getAttribute("data-slide-skip"))return!0;n=n.parentElement}return!1}static keepLastIndex(e){setTimeout(()=>{const n=window.getSelection();n&&(n.selectAllChildren(e),n.collapseToEnd())})}static keepSelectAll(e){setTimeout(()=>{const n=window.getSelection();if(!n)return;const t=document.createRange();t.selectNodeContents(e),n.removeAllRanges(),n.addRange(t)})}update(e){this._config.currentIndex=e,this._initConfig(),this.removeListener(),this.addListener()}primeval(){return this._slideTabBar}updateItems(){for(let e=0;e<this._slideTabItems.length;e++)this._slideTabItems[e].animate().cancel(),this._slideTabItems[e].translateX(0),this._slideTabItems[e].update()}getScrollbar(){return this._slideScrollbar}getConfig(){return this._config}getBoundingRect(){return this._slideTabBar.getBoundingClientRect()}getSlideTabItems(){return this._slideTabItems}getActiveItem(){return this._activeTabItem}isLeftEnd(){return this._slideTabBar.scrollLeft===0}isRightEnd(){const e=this._slideTabBar.parentElement;return e?this._slideTabBar.scrollWidth-e.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.removeEventListener("pointerdown",this._downAction)})}setScroll(e){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),e>0){const n=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}else if(e<0){const n=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(e){if(e>0){const n=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}else if(e<0){const n=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+n)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(e){let n=0;const t=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(n=e?c-r.left-t:c+d-s+t,!0):!1}),n}calculateRightScrollX(e){let n=0;const t=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(n=e?c+d-r.left-r.width+t:c-s-t,!0):!1}),n}destroy(){this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null,this.removeListener()}_hasEditItem(){for(let e=0;e<this._slideTabItems.length;e++)if(this._slideTabItems[e].isEditMode())return!0;return!1}_autoScrollFrame(){if(this._activeTabItem)switch(this._compareDirection=this._activeTabItem.translateX(this._moveActionX),this._compareDirection){case 1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareRight();break}case 0:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareIndex=this._activeTabItemIndex;break}case-1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareLeft();break}}this._autoScrollTime=requestAnimationFrame(()=>{this._autoScrollFrame()})}_startAutoScroll(){this._autoScrollTime==null&&this._autoScrollFrame()}_closeAutoScroll(){this._autoScrollTime&&cancelAnimationFrame(this._autoScrollTime),this._autoScrollTime=null}_scrollLeft(e){const n=this.getBoundingRect(),t=e.pageX-n.x;t<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(t-this._leftBoundingLine)*.1,50))}_scrollRight(e){const n=this.getBoundingRect(),t=e.pageX-n.x;t>n.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(t-(n.width-this._rightBoundingLine))*.1,50))}_sortedItems(){if(this._activeTabItem!=null&&this._activeTabItemIndex!=null&&this._compareIndex!=null&&(this._slideTabItems.splice(this._activeTabItemIndex,1),this._slideTabItems.splice(this._compareIndex,0,this._activeTabItem),this._config.slideTabBarItemAutoSort))for(let e=0;e<this._slideTabItems.length;e++){const n=this._slideTabItems[e],t=this._slideTabItems[e+1];t&&n.after(t)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),n=this._slideTabItems.length,t=[];for(let r=0;r<e&&!(r>=e);r++)t.push(this._slideTabItems[r]);for(let r=e+1;r<n;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=t.length-1;r>=0;r--){const s=t[r];st.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=r,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),n=this._slideTabItems.length,t=[];for(let r=e+1;r<n;r++)t.push(this._slideTabItems[r]);for(let r=0;r<e;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=0;r<t.length;r++){const s=t[r];st.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=e+r+1,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){var n;const e=this._slideTabBar.querySelectorAll(`.${(n=this._config.slideTabBarItemClassName)!=null?n:"slide-tab-item"}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=st.make(e,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};C(At,"LongPressDelay",500),C(At,"DoubleClickDelay",300);let yt=At;function yu(){const[i,e]=H.useState([]),[n,t]=H.useState(""),[o,r]=H.useState(""),[s,l]=H.useState(!1),[c,d]=H.useState([0,0]),u=H.useRef({slideTabBar:null}),h=H.useRef(null),m=K.useDependency(a.IUniverInstanceService),_=K.useDependency(a.ICommandService),S=K.useDependency(Et),f=K.useDependency(a.LocaleService),v=K.useDependency(I.IConfirmService),M=K.useDependency(Se),R=K.useDependency(be),T=K.useInjector(),E=m.getCurrentUniverSheetInstance();H.useEffect(()=>{W();const k=w(),U=L(),Z=[B(),z(),Y(),J()];return()=>{U.dispose(),k.destroy(),Z.forEach(ie=>ie.unsubscribe())}},[]),H.useEffect(()=>{i.length>0&&F()},[i]);const w=()=>{const k=new yt({slideTabBarClassName:Ee.slideTabBar,slideTabBarItemActiveClassName:Ee.slideTabActive,slideTabBarItemClassName:Ee.slideTabItem,slideTabBarSpanEditClassName:Ee.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(U,Z)=>{_.executeCommand(g.SetWorksheetNameCommand.id,{subUnitId:U,name:Z})},onSlideEnd:(U,Z)=>{_.executeCommand(g.SetWorksheetOrderCommand.id,{order:Z})},onChangeTab:(U,Z)=>{_.executeCommand(g.SetWorksheetActivateCommand.id,{subUnitId:Z,unitId:E.getUnitId()}).then(()=>{U.button===2&&$(!0)}),setTimeout(()=>{T.get(b.ITextSelectionRenderManager).focus()},0)},onScroll:U=>{S.setScroll(U)},onNameCheckAlert:U=>y(U)||O(U)});return u.current.slideTabBar=k,se(k),k},y=k=>{if(k.trim()===""){const U="sheetNameEmptyAlert";return v.open({id:U,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){x(),v.close(U)},onConfirm(){x(),v.close(U)}}),!0}return!1},O=k=>{const U=m.getCurrentUniverSheetInstance();if(U.getActiveSheet().getName()===k)return!1;const oe=U.checkSheetName(k);if(oe){const X="sheetNameRepeatAlert";v.open({id:X,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){v.close(X),x()},onConfirm(){v.close(X),x()}})}return oe},x=()=>{M.endSelection(),setTimeout(()=>{var U;const k=(U=u.current.slideTabBar)==null?void 0:U.getActiveItem();k&&(k.focus(),k.selectAll())},0)},N=()=>{var k,U;(U=(k=u.current.slideTabBar)==null?void 0:k.getActiveItem())==null||U.setEditor()},F=()=>{var U;const k=i.findIndex(Z=>Z.selected);(U=u.current.slideTabBar)==null||U.update(k)},L=()=>_.onCommandExecuted(k=>{switch(k.id){case g.SetTabColorMutation.id:case g.SetWorksheetHideMutation.id:case g.RemoveSheetMutation.id:case g.SetWorksheetNameMutation.id:case g.InsertSheetMutation.id:case g.SetWorksheetOrderMutation.id:case g.SetWorksheetActiveOperation.id:W();break}}),W=()=>{const k=E.getActiveSheet().getSheetId();t(k);const U=E.getSheets(),Z=E.getActiveSheet(),ie=U.filter(oe=>!oe.isSheetHidden()).map((oe,X)=>{var G;return{sheetId:oe.getSheetId(),label:oe.getName(),index:X,selected:Z===oe,color:(G=oe.getTabColor())!=null?G:void 0}});e(ie)},B=()=>S.scroll$.subscribe(k=>{j(k)}),z=()=>S.scrollX$.subscribe(k=>{var U;(U=u.current.slideTabBar)==null||U.flipPage(k)}),Y=()=>S.renameId$.subscribe(()=>{N()}),J=()=>S.addSheet$.subscribe(()=>{var k;(k=u.current.slideTabBar)==null||k.getScrollbar().scrollRight()}),j=k=>{const{leftEnd:U,rightEnd:Z}=k;let ie="";U&&Z?ie="":U&&!Z?ie="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&Z?ie="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&!Z&&(ie="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(ie)},q=k=>{S.setScroll({leftEnd:k.isLeftEnd(),rightEnd:k.isRightEnd()})},se=k=>{var ie;const U=(ie=h.current)==null?void 0:ie.querySelector(`.${Ee.slideTabBar}`);if(!U)return;new ResizeObserver(()=>{q(k)}).observe(U)},$=k=>{var U,Z,ie,oe,X;if(!R.isForceKeepVisible()){if(k){const{left:G}=(Z=(U=h.current)==null?void 0:U.getBoundingClientRect())!=null?Z:{},{left:Q}=(X=(oe=(ie=u.current.slideTabBar)==null?void 0:ie.getActiveItem())==null?void 0:oe.getSlideTabItem().getBoundingClientRect())!=null?X:{};G!==void 0&&Q!==void 0&&d([Q-G,0])}l(k)}};return p.jsx(_e.Dropdown,{className:Ee.slideTabItemDropdown,visible:s,align:{offset:c},trigger:["contextMenu"],overlay:p.jsx(I.Menu,{menuType:de.SHEET_BAR,onOptionSelect:k=>{const{label:U,value:Z}=k;_.executeCommand(U,{value:Z,subUnitId:n}),l(!1)}}),onVisibleChange:$,children:p.jsx("div",{className:Ee.slideTabBarContainer,ref:h,children:p.jsx("div",{className:Ee.slideTabBar,style:{boxShadow:o},children:i.map(k=>H.createElement(Ru,{...k,key:k.sheetId,selected:n===k.sheetId}))})})})}const Qr=100,Ou=()=>{const[i,e]=H.useState(!0),[n,t]=H.useState(!0),o=K.useDependency(a.ICommandService),r=K.useDependency(Et);H.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;e(h),t(m)},l=()=>{o.executeCommand(g.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-Qr)},d=()=>{r.setScrollX(Qr)};return p.jsxs("div",{className:Gn.sheetBar,children:[p.jsxs("div",{className:Gn.sheetBarOptions,children:[p.jsx(Kn,{onClick:l,children:p.jsx(Ga,{})}),p.jsx(Mu,{})]}),p.jsx(yu,{}),(!i||!n)&&p.jsxs("div",{className:`${Gn.sheetBarOptions} ${Gn.sheetBarOptionsDivider}`,children:[p.jsx(Kn,{disabled:i,onClick:c,children:p.jsx(er,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(Kn,{disabled:n,onClick:d,children:p.jsx(er,{})})]})]})};class xu{constructor(){C(this,"_functions",[{func:te.FUNCTION_NAMES_STATISTICAL.MAX,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.MIN,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:te.FUNCTION_NAMES_MATH.SUM,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:e=>{var n,t;return((t=(n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1}},{func:te.FUNCTION_NAMES_STATISTICAL.COUNT,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:e=>{var n,t,o,r;return((t=(n=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:n.value)!=null?t:0)>1&&((r=(o=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}}]);C(this,"_state$",new P.BehaviorSubject(null));C(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(e){var t;const n={values:[],pattern:null};e==null||e.values.forEach(o=>{const r=this._functions.find(s=>s.func===o.func);r&&(r.filter===void 0||r.filter(e))&&n.values.push(o)}),n.pattern=(t=e==null?void 0:e.pattern)!=null?t:null,this._state$.next(n)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(e){this._functions.push(...e)}}const Wi=D.createIdentifier("univer.sheet-status-bar.service"),Ot={statusBar:"univer-status-bar",singleMode:"univer-single-mode",statusBarDiv:"univer-status-bar-div",statisticList:"univer-statistic-list",statisticListColumn:"univer-statistic-list-column",statisticItem:"univer-statistic-item",statisticPicker:"univer-statistic-picker",statisticPickerItem:"univer-statistic-picker-item",statisticMore:"univer-statistic-more"},Au=[te.FUNCTION_NAMES_MATH.SUM,te.FUNCTION_NAMES_STATISTICAL.AVERAGE,te.FUNCTION_NAMES_STATISTICAL.MIN,te.FUNCTION_NAMES_STATISTICAL.MAX],ji={[te.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[te.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[te.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[te.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[te.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[te.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[te.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},zi=i=>{const e=K.useDependency(a.LocaleService),n=K.useDependency(I.IMessageService),t=K.useDependency(I.IClipboardInterfaceService),o=Nu(i),r=async()=>{await t.writeText(i.value.toString()),n.show({type:_e.MessageType.Success,content:e.t("statusbar.copied")})};return p.jsx(_e.Tooltip,{title:e.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:Ot.statisticItem,onClick:r,children:p.jsx("span",{children:`${e.t((ji==null?void 0:ji[i.name])||i.name)}: ${o}`})},i.name)})};function Nu(i){const{pattern:e,value:n}=i;return typeof n!="number"?"Invalid input":n>=1e8?n.toExponential(2):e&&Au.includes(i.name)?rs.format(e,n):n.toLocaleString()}const qr=800,Du=3,Pu=()=>{const[i,e]=H.useState(window.innerWidth<qr),[n,t]=H.useState(!0),o=K.useDependency(Wi),r=o.getFunctions().map((m,_)=>({name:m.func,value:0,show:!0,disable:!1,pattern:null})),[s,l]=H.useState(r),c=s.find(m=>m.show&&!m.disable),d=i&&c?[c]:s.filter(m=>m.show&&!m.disable);H.useEffect(()=>{const m=o.state$.subscribe(_=>{const S=_==null?void 0:_.values;if(!S||S.length===0)t(!1);else{t(!0);const f=s.map(v=>{var R;const M=S.find(T=>T.func===v.name);return M?(v.value=M.value,v.disable=!1):v.disable=!0,v.pattern=(R=_==null?void 0:_.pattern)!=null?R:null,v});l(f)}});return()=>{m.unsubscribe()}},[o]);const u=Hu(()=>{const m=window.innerWidth<qr;i!==m&&e(m)},100);H.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>Du){const m=[];d.forEach((_,S)=>{S%2===0&&m.push(d.slice(S,S+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((_,S)=>p.jsxs("div",{className:Ot.statisticListColumn,children:[(_==null?void 0:_[0])&&p.jsx(zi,{..._==null?void 0:_[0]},_==null?void 0:_[0].name),(_==null?void 0:_[1])&&p.jsx(zi,{..._==null?void 0:_[1]},_==null?void 0:_[1].name)]},`stat-col-${S}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(zi,{...m},m.name))});return n&&p.jsxs("div",{className:Nt(Ot.statusBar,{[Ot.singleMode]:i}),children:[p.jsx("div",{className:Nt(Ot.statisticList),children:h}),p.jsx("div",{className:Ot.statusBarDiv})]})};function Hu(i,e){let n;return function(...t){const o=this,r=function(){n=null,i.apply(o,t)};clearTimeout(n),n=setTimeout(r,e)}}function Lu(){return p.jsxs("section",{className:Er.sheetContainer,"data-range-selector":!0,children:[p.jsx(Ou,{}),p.jsx(Pu,{}),p.jsx(Su,{})]})}function Uu(){return p.jsx(p.Fragment,{children:p.jsx(fu,{})})}function ku(){return p.jsxs(p.Fragment,{children:[p.jsx(gu,{}),p.jsx(Cu,{})]})}function Vu(i){const e=i.get(g.BorderStyleManagerService),n=g.getCurrentSheetDisabled$(i);return{id:g.SetBorderBasicCommand.id,icon:new P.Observable(t=>{const o="AllBorderSingle",r=i.get(g.BorderStyleManagerService),s=i.get(a.ICommandService).onCommandExecuted(l=>{var m;if(l.id!==g.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=Gr.find(_=>_.value===d),h=(m=u==null?void 0:u.icon)!=null?m:o;t.next(h)});return t.next(o),s.dispose}),group:I.MenuGroup.TOOLBAR_FORMAT,tooltip:"toolbar.border.main",positions:[I.MenuPosition.TOOLBAR_START],type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Zr,hoverable:!1},value$:e.borderInfo$}],value$:e.borderInfo$,hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:n}}const Jn="sheet.menu.clear-selection";function Bu(){return{id:Jn,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[I.MenuPosition.CONTEXT_MENU,de.COL_HEADER_CONTEXT_MENU,de.ROW_HEADER_CONTEXT_MENU]}}function Fu(){return{id:g.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[Jn]}}function Wu(){return{id:g.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[Jn]}}function ju(){return{id:g.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[Jn]}}const Jt="sheet.menu.delete";function zu(){return{id:Jt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[I.MenuPosition.CONTEXT_MENU]}}function Yu(){return{id:Wr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[Jt,de.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function Xu(){return{id:Fr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteRow",positions:[Jt,de.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function $u(){return{id:ki.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[Jt]}}function Zu(){return{id:Vi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[Jt]}}const Yi="sheet.menu.col-insert";function Gu(){return{id:Yi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.COL_HEADER_CONTEXT_MENU]}}const Xi="sheet.menu.row-insert";function Ku(){return{id:Xi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.ROW_HEADER_CONTEXT_MENU]}}const Qt="sheet.menu.cell-insert";function Ju(){return{id:Qt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[I.MenuPosition.CONTEXT_MENU]}}function Qu(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[Xi,Qt],hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function qu(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertRowAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[Xi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function eh(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,positions:[Yi,Qt],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function th(i){const e=i.get(g.SelectionManagerService);return{id:g.InsertColAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[Yi],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new P.Observable(n=>{const t=e.getSelections();n.next((t==null?void 0:t.length)!==1)})}}function nh(){return{id:Fi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[Qt]}}function ih(){return{id:Bi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[Qt]}}function oh(i){const e=g.getCurrentSheetDisabled$(i);return{id:je.id,icon:"MergeAllSingle",tooltip:"toolbar.mergeCell.main",positions:[I.MenuPosition.TOOLBAR_START],group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET),disabled$:e}}function rh(i){return{id:Ur.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[je.id]}}function sh(i){return{id:kr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[je.id]}}function ah(i){return{id:Vr.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[je.id]}}function lh(i){return{id:g.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[je.id]}}function ch(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:jr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.delete",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values()).filter(d=>d.getConfig().hidden===a.BooleanNumber.FALSE);t.next(c.length===1)}});return t.next(!1),o.dispose})}}function dh(){return{id:g.CopySheetCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.copy"}}function uh(){return{id:Yr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.rename"}}function hh(){return{id:g.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[de.SHEET_BAR],type:I.MenuItemType.SELECTOR,selections:[{label:{name:vn,hoverable:!1}}]}}function mh(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:g.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.hide",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values()).filter(d=>d.getConfig().hidden===a.BooleanNumber.FALSE);t.next(c.length===1)}});return t.next(!1),o.dispose})}}function _h(i){const e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService);return{id:zr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.unhide",disabled$:new P.Observable(t=>{const o=n.onCommandExecuted(r=>{const s=r.id;if(s===g.RemoveSheetMutation.id||s===g.InsertSheetMutation.id||s===g.SetWorksheetHideMutation.id){const l=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(l.values());t.next(c.length===1)}});return t.next(!1),o.dispose})}}const Sh={id:g.SetRowHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},gh={id:g.SetColHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},fh={id:Re.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.DOWN}},ph={id:Re.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.UP}},vh={id:Re.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.LEFT}},Ch={id:Re.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.RIGHT}},Ih={id:it.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},Mh={id:it.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},Rh={id:it.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},bh={id:it.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},wh={id:Re.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.DOWN,jumpOver:Ae.moveGap}},Th={id:Re.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.UP,jumpOver:Ae.moveGap}},Eh={id:Re.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.LEFT,jumpOver:Ae.moveGap}},yh={id:Re.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Ae.moveGap}},Oh={id:Ne.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:a.Direction.DOWN}},xh={id:Ne.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:a.Direction.UP}},Ah={id:Ne.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:a.Direction.LEFT}},Nh={id:Ne.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:a.Direction.RIGHT}},Dh={id:Ne.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.DOWN,jumpOver:Ae.moveGap}},Ph={id:Ne.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.UP,jumpOver:Ae.moveGap}},Hh={id:Ne.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.LEFT,jumpOver:Ae.moveGap}},Lh={id:Ne.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Ae.moveGap}},Uh={id:Vo.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{expandToGapFirst:!0,loop:!0}},kh={id:fi.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},Vh={id:pi.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Bh={id:vi.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Fh={id:Ci.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},Wh={id:g.ClearSelectionContentCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},jh={id:An.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ne,priority:1,staticParameters:{delta:.2}},zh={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},Yh={id:An.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ne,priority:1,staticParameters:{delta:-.2}},Xh={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},$h={id:An.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:ne,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Zh={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var Gh=Object.defineProperty,Kh=Object.getOwnPropertyDescriptor,Jh=(i,e,n,t)=>{for(var o=t>1?void 0:t?Kh(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Gh(e,n,o),o},xt=(i,e)=>(n,t)=>e(n,t,i);let Qn=class extends a.Disposable{constructor(i,e,n,t,o,r){super(),this._injector=i,this._componentManager=e,this._commandService=n,this._shortcutService=t,this._menuService=o,this._uiController=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(wi,Ml)),this.disposeWithMe(i.register(Zr,du)),this.disposeWithMe(i.register(vn,_e.ColorPicker)),this.disposeWithMe(i.register(Sr,I.FontFamily)),this.disposeWithMe(i.register(gr,I.FontFamilyItem)),this.disposeWithMe(i.register(fr,I.FontSize))}_initCommands(){[Ur,je,Vr,kr,An,Ne,Re,it,Yr,jr,Fr,Wr,or,rr,It,Vo,xr,_n,g.SetBoldCommand,Bt,Pe,fi,pi,vi,Ci,Sl,gl,sr,ar,fn,g.SetItalicCommand,g.SetStrikeThroughCommand,g.SetFontFamilyCommand,g.SetFontSizeCommand,Ri,dr,bi,ur,mt,Hn,pn,hr,mr,_r,g.SetUnderlineCommand,Nn,Be,zr,Br,Bi,Vi,Fi,ki].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[kl,Vl,Bl,Fl,Wl,jl,zl,Fu,Wu,ju,Bu,Gu,Ku,Ju,Qu,qu,eh,th,Xu,Ql,ec,ql,tc,Yu,nc,Yl,ic,zu,$u,Zu,nh,ih,Zl,Gl,Kl,Jl,Xl,$l,Rl,bl,wl,Tl,El,yl,Ol,xl,Al,Nl,Dl,Vu,oh,rh,sh,ah,lh,Pl,Hl,Ll,Ul,ch,dh,uh,hh,mh,_h].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[fh,ph,vh,Ch,Ih,Mh,Rh,bh,wh,Th,Eh,yh,Oh,xh,Ah,Nh,Dh,Ph,Hh,Lh,Uh,jh,Yh,$h,Zh,zh,Xh,kh,Vh,Bh,Fh,Wh,...Rc(),bc,wc,Ec,yc,Oc,Tc,Sh,gh].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>K.connectInjector(Uu,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>K.connectInjector(Lu,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>K.connectInjector(ku,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts()}};Qn=Jh([a.OnLifecycle(a.LifecycleStages.Ready,Qn),xt(0,D.Inject(D.Injector)),xt(1,D.Inject(I.ComponentManager)),xt(2,a.ICommandService),xt(3,I.IShortcutService),xt(4,I.IMenuService),xt(5,I.IUIController)],Qn);var Qh=Object.defineProperty,qh=Object.getOwnPropertyDescriptor,em=(i,e,n,t)=>{for(var o=t>1?void 0:t?qh(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&Qh(e,n,o),o},at=(i,e)=>(n,t)=>e(n,t,i);let qn=class extends a.Disposable{constructor(e,n,t,o,r,s,l){super();C(this,"_calculateTimeout",-1);this._univerInstanceService=e,this._selectionManagerService=n,this._functionService=t,this._statusBarService=o,this._commandService=r,this._formulaDataModel=s,this._numfmtService=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(e=>{var n;((n=this._selectionManagerService.getCurrent())==null?void 0:n.pluginName)===g.NORMAL_SELECTION_PLUGIN_NAME&&e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{const t=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),t)},100))}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.pipe(P.debounceTime(100)).subscribe(e=>{var n;if(((n=this._selectionManagerService.getCurrent())==null?void 0:n.pluginName)===g.NORMAL_SELECTION_PLUGIN_NAME&&e){const t=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),t)}}))),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===g.SetRangeValuesMutation.id){const n=this._selectionManagerService.getSelections();n&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(n.map(t=>t.range))},100))}}))}_calculateSelection(e,n){var c;const t=this._univerInstanceService.getCurrentUniverSheetInstance(),o=t.getUnitId(),r=t.getActiveSheet().getSheetId(),s={},l=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(d=>{const u=d.getConfig();s[d.getSheetId()]={cellData:new a.ObjectMatrix(u.cellData),rowCount:u.rowCount,columnCount:u.columnCount}}),e!=null&&e.length){const d=e.map(f=>new te.RangeReferenceObject(f,r,o));d.forEach(f=>{f.setUnitData({[o]:s}),l&&f.setArrayFormulaCellData(te.convertUnitDataToRuntime(l))});const h=this._statusBarService.getFunctions().map(f=>{const v=this._functionService.getExecutor(f.func);if(!v)return;const M=d.map(E=>E.toArrayValueObject(!1)),R=v==null?void 0:v.calculate(...M),T=R==null?void 0:R.getValue();if(T)return{func:f.func,value:T}});if(h.every(f=>f===void 0))return;let m=null;if(n){const{actualRow:f,actualColumn:v}=n;m=(c=this._numfmtService.getValue(o,r,f,v))==null?void 0:c.pattern}const S={values:h.filter(f=>f!==void 0),pattern:m};this._statusBarService.setState(S)}else this._statusBarService.setState(null)}_isSingleCell(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}};qn=em([a.OnLifecycle(a.LifecycleStages.Ready,qn),at(0,a.IUniverInstanceService),at(1,D.Inject(g.SelectionManagerService)),at(2,te.IFunctionService),at(3,Wi),at(4,a.ICommandService),at(5,D.Inject(te.FormulaDataModel)),at(6,D.Inject(g.INumfmtService))],qn);var tm=Object.defineProperty,nm=Object.getOwnPropertyDescriptor,im=(i,e,n,t)=>{for(var o=t>1?void 0:t?nm(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&tm(e,n,o),o},lt=(i,e)=>(n,t)=>e(n,t,i);let ei=class extends a.Disposable{constructor(i,e,n,t,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=n,this._renderManagerService=t,this._selectionRenderService=o,this._selectionManagerService=r,this._scrollManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._zoomEventBinding()}_zoomEventBinding(){var e;const i=(e=this._getSheetObject())==null?void 0:e.scene;i!=null&&(i.getViewport(V.VIEW_MAIN),this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add((n,t)=>{if(!n.ctrlKey)return;const o=Math.abs(n.deltaX);let r=o<40?.2:o<80?.4:.2;r*=n.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),l=s.getActiveSheet(),c=l.getZoomRatio();let d=+Number.parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Nn.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:l.getSheetId()}),n.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const t=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(t)})))}_commandExecutedListener(){const i=[Be.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const n=this._currentUniverService.getCurrentUniverSheetInstance(),t=n.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===n.getUnitId()&&s===t.getSheetId()))return;const l=t.getConfig().zoomRatio||1;this._updateViewZoom(l)}}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};ei=im([a.OnLifecycle(a.LifecycleStages.Rendered,ei),lt(0,D.Inject(A.SheetSkeletonManagerService)),lt(1,a.IUniverInstanceService),lt(2,a.ICommandService),lt(3,b.IRenderManagerService),lt(4,Se),lt(5,D.Inject(g.SelectionManagerService)),lt(6,D.Inject(Je))],ei);var om=Object.defineProperty,rm=Object.getOwnPropertyDescriptor,sm=(i,e,n,t)=>{for(var o=t>1?void 0:t?rm(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&om(e,n,o),o},qt=(i,e)=>(n,t)=>e(n,t,i);A.SheetCanvasView=class extends a.RxDisposable{constructor(n,t,o,r,s){super();C(this,"_scene");C(this,"_currentWorkbook");C(this,"_loadedMap",new Set);C(this,"_isLoadedEditor",!1);C(this,"_fps$",new P.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._currentUniverService=n,this._commandService=t,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._currentUniverService.currentSheet$.subscribe(l=>{if(l==null)return;const c=l.getUnitId();this._loadedMap.has(c)||(this._currentWorkbook=l,this._addNewRender(),this._loadedMap.add(c))})}dispose(){this._fps$.complete()}_addNewRender(){const n=this._currentWorkbook,t=n.getUnitId(),o=n.getContainer(),r=n.getParentRenderUnitId();if(o!=null&&r!=null)throw new Error("container or parentRenderUnitId can only exist one");const s=o==null&&r!=null;s?this._renderManagerService.createRenderWithParent(t,r):this._renderManagerService.createRender(t);const l=this._renderManagerService.getRenderById(t);if(l==null)return;const{scene:c,engine:d}=l;c.openTransformer(),this._scene=c,c.addLayer(new b.Layer(c,[],0),new b.Layer(c,[],2)),l!=null&&this._addComponent(l),n.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(t)}_addComponent(n){const t=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();this._addViewport(r);const c=new b.Spreadsheet(fe.MAIN),d=new b.SpreadsheetRowHeader(fe.ROW),u=new b.SpreadsheetColumnHeader(fe.COLUMN),h=new b.Rect(fe.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});n.mainComponent=c,n.components.set(fe.MAIN,c),n.components.set(fe.ROW,d),n.components.set(fe.COLUMN,u),n.components.set(fe.LEFT_TOP,h),t.addObjects([c],So),t.addObjects([d,u,h],Ze),t.enableLayerCache(So,Ze),this._sheetSkeletonManagerService.setCurrent({sheetId:l,unitId:s})}_addViewport(n){const t=this._scene;if(t==null)return;const{rowHeader:o,columnHeader:r}=n.getConfig(),s=new b.Viewport(V.VIEW_MAIN,t,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0});return new b.Viewport(V.VIEW_ROW_TOP,t,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_ROW_BOTTOM,t,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_LEFT,t,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_RIGHT,t,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_LEFT_TOP,t,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_MAIN_LEFT_TOP,t,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_LEFT,t,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_TOP,t,{isWheelPreventDefaultX:!0,active:!1}),t.onMouseWheelObserver.add((l,c)=>{if(l.ctrlKey)return;let d=0,u=0;const h=s.limitedScroll();if(l.inputIndex===b.PointerInput.MouseWheelX){const _=Math.abs(l.deltaX);l.deltaX>0?d=_:d=-_,this._commandService.executeCommand(Hn.id,{offsetX:d}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?l.preventDefault():h!=null&&h.isLimitedX||l.preventDefault()}if(l.inputIndex===b.PointerInput.MouseWheelY){let _=Math.abs(l.deltaY);l.shiftKey?(_*=3,l.deltaY>0?d=_:d=-_,this._commandService.executeCommand(Hn.id,{offsetX:d}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?l.preventDefault():h!=null&&h.isLimitedX||l.preventDefault()):(l.deltaY>0?u=_:u=-_,this._commandService.executeCommand(Hn.id,{offsetY:u}),t.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedY||c.stopPropagation():s.isWheelPreventDefaultY?l.preventDefault():h!=null&&h.isLimitedY||l.preventDefault())}l.inputIndex,b.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}),new b.ScrollBar(s),t.attachControl(),s}},A.SheetCanvasView=sm([a.OnLifecycle(a.LifecycleStages.Ready,A.SheetCanvasView),qt(0,a.IUniverInstanceService),qt(1,a.ICommandService),qt(2,b.IRenderManagerService),qt(3,Se),qt(4,D.Inject(A.SheetSkeletonManagerService))],A.SheetCanvasView);var am=Object.defineProperty,lm=Object.getOwnPropertyDescriptor,cm=(i,e,n,t)=>{for(var o=t>1?void 0:t?lm(e,n):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(t?s(e,n,o):s(o))||o);return t&&o&&am(e,n,o),o},$i=(i,e)=>(n,t)=>e(n,t,i);A.UniverSheetsUIPlugin=(Zi=class extends a.Plugin{constructor(e,n,t,o){super(io),this._injector=n,this._localeService=t,this._currentUniverService=o,this._localeService.load({zhCN:Mr})}onStarting(e){[[A.SheetCanvasView],[Ut],[be,{useClass:A.EditorBridgeService}],[ut,{useClass:A.SheetClipboardService}],[Et,{useClass:qd}],[St,{useClass:Mi}],[zt,{useClass:Rr}],[In,{useClass:sc}],[Ft,{useClass:A.AutoFillService}],[Je],[A.SheetSkeletonManagerService],[Se,{useClass:A.SelectionRenderService}],[Wi,{useClass:xu}],[Ht,{useClass:A.MarkSelectionService}],[Mn],[Rn],[Dn],[En],[yn],[Pn],[Ln],[kn],[Vn],[Bn],[Wn],[On],[zn],[wt],[Xn],[bn],[wn],[Yn],[$n],[Qn],[xn],[ei],[A.AutoFillController],[qn],[Tn],[jn]].forEach(n=>e.add(n))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const e=this._currentUniverService;e.currentSheet$.pipe(qi.filter(n=>!!n)).subscribe(n=>{e.focusUniverInstance(n.getUnitId())})}},C(Zi,"type",a.PluginType.Sheet),Zi),A.UniverSheetsUIPlugin=cm([$i(1,D.Inject(D.Injector)),$i(2,D.Inject(a.LocaleService)),$i(3,a.IUniverInstanceService)],A.UniverSheetsUIPlugin),A.APPLY_TYPE=re,A.AutoFillCommand=ho,A.COPY_TYPE=nt,A.CellEditorManagerService=Rr,A.DATA_TYPE=ue,A.DefaultRightMenuConfig=eo,A.DefaultSheetContainerConfig=no,A.DefaultSheetUIConfig=ss,A.DefaultToolbarConfig=to,A.ExpandSelectionCommand=Ne,A.IAutoFillService=Ft,A.ICellEditorManagerService=zt,A.IEditorBridgeService=be,A.IFormulaEditorManagerService=In,A.IMarkSelectionService=Ht,A.ISelectionRenderService=Se,A.ISheetClipboardService=ut,A.JumpOver=Ae,A.MoveSelectionCommand=Re,A.PASTE_SPECIAL_MENU_ID=pt,A.PREDEFINED_HOOK_NAME=pe,A.RangeSelector=nl,A.SHEET_UI_PLUGIN_NAME=io,A.SelectionShape=un,A.SetCellEditVisibleArrowOperation=Bt,A.SetEditorResizeOperation=_n,A.SetScrollOperation=mt,A.SetZoomRatioOperation=Be,A.SheetCopyCommand=Oo,A.SheetPasteCommand=ht,A.VIEWPORT_KEY=V,A.enUS=oc,A.getAutoFillRepeatRange=Cs,A.getCoordByCell=yi,A.getCoordByOffset=vt,A.getEditorObject=sn,A.getRepeatRange=rc,A.getSheetObject=ve,A.getTransformCoord=Cn,A.whenFormulaEditorActivated=Ms,A.whenSheetEditorFocused=ne,A.zhCN=Mr,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});