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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";var os=Object.defineProperty;var rs=(i,e,t)=>e in i?os(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var C=(i,e,t)=>(rs(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),S=require("@univerjs/sheets"),I=require("@univerjs/ui"),N=require("@wendellhu/redi"),D=require("rxjs"),b=require("@univerjs/engine-render"),H=require("react"),ge=require("@univerjs/design"),q=require("@wendellhu/redi/react-bindings"),Q=require("@univerjs/docs"),jo=require("rxjs/operators"),te=require("@univerjs/engine-formula"),zt=require("clsx"),ss=require("@univerjs/engine-numfmt"),$o={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},zo={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},Yo={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:Yo,rightMenuConfig:$o,toolbarConfig:zo}},Xo="SheetUI";function Yn(i,e){if(i==null)return;const t=e.getRenderById(i);if(t==null)return;const{mainComponent:n,scene:o,engine:r}=t;return{document:n,scene:o,engine:r}}const vi={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Vn=["零","一","二","三","四","五","六","七","八","九"],io=["","万","亿","万亿","亿亿"],ls=["","十","百","千"],Zo={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function $e(i){if(!i)return 0;let e=0,t=0,n=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const a=vi[r[s]];if(typeof a<"u")n=a,s===r.length-1&&(t+=n);else{const c=Zo[r[s]],d=c.value;o=c.secUnit,o?(t=(t+n)*d,e+=t,t=0):t+=n*d,n=0}}return e+t}function cs(i){let e="",t="",n=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,t=Vn[r]+t):(o=!1,e=Vn[r],e+=ls[n],t=e+t),n++,i=Math.floor(i/10)}return t}function ds(i){let e=0,t="",n="",o=!1;if(i===0)return Vn[0];for(;i>0;){const r=i%1e4;o&&(n=Vn[0]+n),t=cs(r),t+=r!==0?io[e]:io[0],n=t+n,o=r<1e3&&r>0,i=Math.floor(i/1e4),e++}return n}function us(i){if(!i)return!1;let e=!0;if(i)if(i.length===1)i==="日"||i in vi?e=!0:e=!1;else{const t=i.split("");for(let n=0;n<t.length;n++)if(!(t[n]in vi||t[n]in Zo)){e=!1;break}}return e}function rn(i){if(!i)return{isExtendNumber:!1};const e=/0|([1-9]+[0-9]*)/g,t=e.test(i);if(t){const n=i.match(e);if(n&&n.length>0){const o=n[n.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),a=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:a}}return{isExtendNumber:!1}}return{isExtendNumber:t}}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 gs(i,e){let t=0;for(let n=0;n<i.length&&i[n]<e;n++)t++;return t}function Kt(i){let e=!0;const t=i[1]-i[0];for(let n=1;n<i.length;n++)if(i[n]-i[n-1]!==t){e=!1;break}return e}function _s(i,e,t){const n=[],o=Math.floor(e/i),r=e%i;let s=0;if(o>0){for(let a=0;a<o;a++)for(let c=0;c<t.length;c++)n[t[c]+a*i]=s,s++;for(let a=0;a<t.length&&t[a]<r;a++)n[t[a]+i*o]=s,s++}else for(let a=0;a<t.length&&t[a]<r;a++)n[t[a]]=s,s++;return n}function at(i,e){const t=[];for(let n=1;n<=e;n++){const o=(n-1)%i.length,r=l.Tools.deepClone(i[o]);t.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return t}function Ss(i,e){var n;const t=[];for(let o=1;o<=e;o++){const r=(o-1)%i.length,s={s:(n=i[r])==null?void 0:n.s};t.push(s)}return t}function fs(i){let e=!0;const t=i[1]/i[0];for(let n=1;n<i.length;n++)if(i[n]/i[n-1]!==t){e=!1;break}return e}function ps(i){const e=[];for(let t=1;t<=i;t++)e.push(t);return e}function oo(i,e,t){var r,s,a,c;const n=[],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=l.Tools.deepClone(i[u]),m=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((a=i[1])==null?void 0:a.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(h.v=m,n.push(h))}else{const d=ps(i.length);for(let u=1;u<=e;u++){const h=(u-1)%i.length,m=l.Tools.deepClone(i[h]),g=t===l.Direction.DOWN||t===l.Direction.RIGHT,_=vs(i.length+u,o,d,g);m&&(m.v=_,n.push(m))}}return n}function vs(i,e,t,n=!0){function o(h){let m=0;for(let g=0;g<h.length;g++)m+=h[g];return m/h.length}const r=o(t),s=o(e);let a=0,c=0;for(let h=0;h<t.length;h++)a+=(t[h]-r)*(e[h]-s),c+=(t[h]-r)*(t[h]-r);let d;c===0?d=n?1:-1:d=a/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function ro(i,e,t){var r;const n=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=e;s++){const a=(s-1)%i.length,c=l.Tools.deepClone(i[a]),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)+t*s);if(!d||!h)continue;const g=d.lastIndexOf(h),_=d.substr(0,g)+m.toString()+d.substr(g+h.length);c&&(c.v=_,n.push(c))}return n}function It(i,e,t,n=0){var a,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(n>=o.length)return[];const r=o[n],s=[];for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=l.Tools.deepClone(i[u]);let m=0;if(((a=i[i.length-1])==null?void 0:a.v)===r[0])m=7+t*d;else{const _=`${(c=i[i.length-1])==null?void 0:c.v}`;if(_){const f=_.substr(_.length-1,1);m=$e(f)+t*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const g=m%7;h&&(h.v=r[g],s.push(h))}return s}function so(i,e,t){var o;const n=[];for(let r=1;r<=e;r++){const s=(r-1)%i.length,a=l.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=$e(c)+t*r;let u;d<=0?u="零":u=ds(d),a&&(a.v=u,n.push(a))}return n}const $t={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($t).forEach(t=>{$t[t].includes(i)&&(e=!0)}),e}function ri(i){let e="";const t=[];return Object.keys($t).forEach(n=>{$t[n].includes(i)&&(e=n,t.push(...$t[n]))}),{name:e,series:t}}function ao(i,e,t,n){var s;const o=n.length,r=[];for(let a=1;a<=e;a++){const c=(a-1)%i.length,d=l.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=n.indexOf(u)+t*a;h<0&&(h+=Math.abs(t)*o);const m=h%o;d&&(d.v=n[m],r.push(d))}return r}function Is(i,e){const t=[];let n;if(e.startRow<i.startRow)n=l.Direction.UP;else if(e.endRow>i.endRow)n=l.Direction.DOWN;else if(e.startColumn<i.startColumn)n=l.Direction.LEFT;else if(e.endColumn>i.endColumn)n=l.Direction.RIGHT;else return[];if(n===l.Direction.DOWN||n===l.Direction.UP){const o=i.endRow-i.startRow+1,r=e.endRow-e.startRow+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.DOWN){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:a-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-a,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(n===l.Direction.RIGHT||n===l.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=e.endColumn-e.startColumn+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.RIGHT){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:a-1}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-a,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return t}function Go(i){const e=new l.ObjectMatrix;return i.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:s}=t;for(let a=n;a<=r;a++)for(let c=o;c<=s;c++)e.setValue(a,c,{v:null,p:null,f:null,si:null})}),e.getData()}const Ko={type:l.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,e)=>!0},un={id:"sheet.command.auto-clear-content",type:l.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(l.IUniverInstanceService),n=i.get(l.ICommandService),o=i.get(l.IUndoRedoService),r=t.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=e,h={subUnitId:c,unitId:s,cellValue:Go([d])},m=S.SetRangeValuesUndoMutationFactory(i,h);return n.executeCommand(S.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),n.syncExecuteCommand(S.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:S.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:S.SetRangeValuesMutation.id,params:h}],undo(){return n.syncExecuteCommand(S.SetRangeValuesMutation.id,m)},redo(){return n.syncExecuteCommand(S.SetRangeValuesMutation.id,h)}}),!0):!1}};function xi(i){return i.getContextValue(l.FOCUSING_SHEET)}function ne(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)}function qo(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(l.EDITOR_ACTIVATED)}function Rs(i){return i.getContextValue(l.EDITOR_ACTIVATED)}function Jo(i){return i.getContextValue(l.FOCUSING_FORMULA_EDITOR)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Ms(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.EDITOR_ACTIVATED)&&i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Bn(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)}var Se=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(Se||{}),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 lo=0,qe=2,bs=3,Ci=[10,400],co=1001;var ws=Object.defineProperty,Ts=Object.getOwnPropertyDescriptor,Es=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ts(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ws(e,t,o),o},uo=(i,e)=>(t,n)=>e(t,n,i);exports.SheetSkeletonManagerService=class{constructor(e,t){C(this,"_currentSkeleton",{unitId:"",sheetId:""});C(this,"_sheetSkeletonParam",[]);C(this,"_currentSkeleton$",new D.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new D.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=e,this._localeService=t}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(e){const t=this._getCurrentBySearch(e);if(t!=null)this._reCalculate(t);else{const{unitId:o,sheetId:r}=e,s=this._currentUniverService.getUniverSheetInstance(e.unitId),a=s==null?void 0:s.getSheetBySheetId(e.sheetId);if(a==null||s==null)return;const c=this._buildSkeleton(a,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=e;const n=this.getCurrent();return this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),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,t=!0){const n=this._getCurrentBySearch(e);n!=null&&(n.dirty=t)}getOrCreateSkeleton(e){const t=this._getCurrentBySearch(e);if(t)return t.skeleton;const n=this._currentUniverService.getUniverSheetInstance(e.unitId),o=n==null?void 0:n.getSheetBySheetId(e.sheetId);if(!o||!n)return;const r=this._buildSkeleton(o,n);return this._sheetSkeletonParam.push({unitId:e.unitId,sheetId:e.sheetId,skeleton:r,dirty:!1}),r}_getCurrentBySearch(e){const t=this._sheetSkeletonParam.find(n=>n.unitId===e.unitId&&n.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e,t){const n=e.getConfig();return b.SpreadsheetSkeleton.create(e,n,e.getCellMatrix(),t.getStyles(),this._localeService)}};exports.SheetSkeletonManagerService=Es([uo(0,l.IUniverInstanceService),uo(1,N.Inject(l.LocaleService))],exports.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",l.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:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=e;return t===s&&n===a&&o===c&&r===d}isInclude(e){const{startColumn:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=e;return!(c<t||s>o||a>r||d<n)}highlightToSelection(){return l.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,t){const{startColumn:n,startRow:o,endColumn:r,endRow:s,startX:a,startY:c,endX:d,endY:u,rangeType:h}=e;this._startColumn=n,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=a,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(t)}setCurrentCell(e){e&&(this._currentCell=e)}clearCurrentCell(){this._currentCell=null}}const ho=.3;class Fn{constructor(e,t,n=!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 D.BehaviorSubject(this));C(this,"dispose$",this._dispose$.asObservable());C(this,"selectionMoving$",new D.Subject);C(this,"selectionMoved$",new D.Subject);C(this,"selectionScaling$",new D.Subject);C(this,"selectionScaled$",new D.Subject);C(this,"selectionFilling$",new D.Subject);C(this,"_selectionFilled$",new D.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=t,this._isHeaderHighlight=n,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,t=0,n=0,o,r){this._selectionModel.setValue(e,r),o==null&&(o=this._selectionStyle),this._updateControl(o,t,n)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,t,n,o,r,s,a,c,d,u,h,m,g,_,f,v,R,M,T,E,w,y,O,x,A;(e=this._leftControl)==null||e.dispose(),(t=this._rightControl)==null||t.dispose(),(n=this._topControl)==null||n.dispose(),(o=this._bottomControl)==null||o.dispose(),(r=this._backgroundControlTop)==null||r.dispose(),(s=this._backgroundControlMiddleLeft)==null||s.dispose(),(a=this._backgroundControlMiddleRight)==null||a.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(),(g=this._rowHeaderGroup)==null||g.dispose(),(_=this._rowHeaderBackground)==null||_.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(R=this._columnHeaderGroup)==null||R.dispose(),(M=this._topLeftWidget)==null||M.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(),(A=this._bottomRightWidget)==null||A.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const n=e.mergeInfo;t={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn,startX:n.startX,endX:n.endX,startY:n.startY,endY:n.endY}}else{const{actualRow:n,actualColumn:o,startX:r,endX:s,startY:a,endY:c}=e;t={startRow:n,endRow:n,startColumn:o,endColumn:o,startX:r,endX:s,startY:a,endY:c}}return t}}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,t,n){const{startX:o,startY:r,endX:s,endY:a}=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:g,isAnimationDash:_}=e;let{strokeWidth:f=c.strokeWidth,AutofillSize:v=c.AutofillSize,AutofillStrokeWidth:R=c.AutofillStrokeWidth}=e;const M=this._getScale(),T=(f+S.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/M;f/=M,v/=M,R/=M<1?1:M;const E=S.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/M,w=b.FIX_ONE_PIXEL_BLUR_OFFSET/M;if(this.leftControl.transformByState({height:a-r,left:-T+w,width:f,strokeWidth:E,top:-E/2+w}),this.leftControl.setProps({fill:d,stroke:S.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:a-r,left:s-o-T+w,width:f,strokeWidth:E,top:-E/2+w}),this.rightControl.setProps({fill:d,stroke:S.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:S.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:s-o+f,top:a-r-T+w,height:f,left:-T+w,strokeWidth:E}),this.bottomControl.setProps({fill:d,stroke:S.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),g==null)this.dashRect.hide(),this._stopAntLineAnimation();else{const y=e.strokeWidth*2/M;this.dashRect.transformByState({height:a-r,width:s-o,strokeWidth:y,left:-y/2+w,top:-y/2+w}),this.dashRect.setProps({strokeDashArray:[0,g/M]}),this._stopAntLineAnimation(),_!==!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-R,height:v-R,left:s-o-v/2+R/2,top:a-r-v/2+R/2,strokeWidth:R}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,t,n),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(o,r),this._selectionStyle=e,this._rowHeaderWidth=t||0,this._columnHeaderHeight=n||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=S.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 t=[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,...t,...this._widgetRects),this._selectionShape.hide(),this._selectionShape.evented=!1,this._selectionShape.zIndex=e;const n=this.getScene();n.addObject(this._selectionShape,bs),n.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,t,n){const{startX:o,startY:r,endX:s,endY:a,rangeType:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d);const u=this._getScale(),{stroke:h,hasRowHeader:m,rowHeaderFill:g=d.rowHeaderFill,rowHeaderStroke:_=d.rowHeaderStroke,hasColumnHeader:f,columnHeaderFill:v=d.columnHeaderFill,columnHeaderStroke:R=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:M=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:T=d.columnHeaderStrokeWidth}=e;if(M/=u,T/=u,f===!0){let E=v;this._isHeaderHighlight&&c===l.RANGE_TYPE.COLUMN&&(E=new l.ColorKit(h).setAlpha(ho).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(s-o,n),this._columnHeaderBorder.setProps({fill:R}),this._columnHeaderBorder.transformByState({width:s-o,height:T,top:n-T+1/u}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(o,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),m===!0){let E=g;this._isHeaderHighlight&&c===l.RANGE_TYPE.ROW&&(E=new l.ColorKit(h).setAlpha(ho).toString()),this._rowHeaderBackground.setProps({fill:E}),this._rowHeaderBackground.resize(t,a-r),this._rowHeaderBorder.setProps({fill:_}),this._rowHeaderBorder.transformByState({width:M,height:a-r,left:t-M+1/u}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:n,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const a=this._getScale(),{fill:c=s.fill}=e;let{strokeWidth:d=s.strokeWidth}=e;d/=a;const u=this._selectionModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,r-n),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:g,endY:_}=u,f=d/2,v={left:-f,top:-f,width:o-t+f*2,height:m-n+f};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const R={left:-f,top:m-n,width:h-t+f,height:_-m};R.width<0&&(R.width=0,R.height=0),this._backgroundControlMiddleLeft.transformByState(R);const M={left:g-t-f,top:m-n,width:o-g+f*2,height:_-m};M.width<0&&(M.width=0,M.height=0),this._backgroundControlMiddleRight.transformByState(M);const T={left:-f,top:_-n,width:o-t+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:t,startY:n,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const{stroke:a=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 g={left:-h/2+m/2,center:(o-t)/2-h/2+m/2,right:o-t-h/2+m/2,top:-h/2,middle:(r-n)/2-h/2,bottom:r-n-h/2+m/2},_=h-m;this._widgetRects.forEach(f=>{f.setProps({fill:a,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:_,width:_,left:g.left,top:g.top,strokeWidth:m}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:_,width:_,left:g.center,top:g.top,strokeWidth:m}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:_,width:_,left:g.right,top:g.top,strokeWidth:m}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:_,width:_,left:g.left,top:g.middle,strokeWidth:m}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:_,width:_,left:g.right,top:g.middle,strokeWidth:m}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:_,width:_,left:g.left,top:g.bottom,strokeWidth:m}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:_,width:_,left:g.center,top:g.bottom,strokeWidth:m}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:_,width:_,left:g.right,top:g.bottom,strokeWidth:m}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const n of t)if(e[n]===!0)return!0;return!0}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_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 mo="__SpreadsheetHelperSelectionTempRect",Os=35;class go{constructor(e,t,n,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=t,this._scene=n,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,t;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(t=this._helperSelection)==null||t.dispose()}_getFreeze(){var t;return(t=this._injector.get(exports.SheetSkeletonManagerService).getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(e,t){const n=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(t.viewPortKey){case V.VIEW_MAIN:return e.endRow>=n.startRow&&e.endColumn>=n.startColumn;case V.VIEW_MAIN_TOP:case V.VIEW_COLUMN_RIGHT:return e.endColumn>=n.startColumn&&e.startRow<n.startRow;case V.VIEW_MAIN_LEFT:case V.VIEW_ROW_BOTTOM:return e.endRow>=n.startRow&&e.startColumn<n.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<n.startRow&&e.startColumn<n.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:t,topControl:n,bottomControl:o}=this._control;[e,t,n,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,t){var y;const n=this._scene,o=n.getScrollXYByRelativeCoords(b.Vector2.FromArray([e,t])),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=a,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let g=m+this._relativeSelectionRowLength;g>u&&(g=u,g-m<this._relativeSelectionRowLength&&(m=g-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,_),R=this._skeleton.getNoMergeCellPositionByIndex(g,f),M=(v==null?void 0:v.startY)||0,T=(R==null?void 0:R.endY)||0,E=(v==null?void 0:v.startX)||0,w=(R==null?void 0:R.endX)||0;(y=this._helperSelection)==null||y.transformByState({left:E,top:M,width:w-E,height:T-M}),this._targetSelection={startY:M,endY:T,startX:E,endX:w,startRow:m,endRow:g,startColumn:_,endColumn:f},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([t,n])),{x:s,y:a}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,a,d,u,c);this._startOffsetX=s,this._startOffsetY=a;const{row:m,column:g}=h,{startRow:_,startColumn:f,endRow:v,endColumn:R}=this._control.model;let M=0,T=0;m<_?M-=1:m>v&&(M+=1),g<f?T-=1:g>R&&(T+=1),this._relativeSelectionPositionRow=_-m+M,this._relativeSelectionPositionColumn=f-g+T,this._relativeSelectionRowLength=v-_,this._relativeSelectionColumnLength=R-f;const E=this._control.selectionStyle,w=this._getScale();this.isHelperSelection&&(this._helperSelection=new b.Rect(mo,{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,a,y),this._scrollTimer=O,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(x=>{const{offsetX:A,offsetY:B}=x,{x:P,y:F}=o.getRelativeCoord(b.Vector2.FromArray([A,B]));this._controlMoving(P,F),o.setCursor(b.CURSOR_TYPE.MOVE),O.scrolling(P,F,()=>{this._controlMoving(P,F)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var A,B;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableEvent(),(B=this._scrollTimer)==null||B.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:e,topCenterWidget:t,topRightWidget:n,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:a,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,t,n,o,r,s,a,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,t,n){const o=this._scene,r=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:a}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(e,t,s,a,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let g=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=d,v=u;n===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(g=d,_=u,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.NORTH_RESIZE?(g=d,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):n===b.CURSOR_TYPE.NORTH_EAST_RESIZE?(g=d,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,v=u):n===b.CURSOR_TYPE.WEST_RESIZE?(g=this._relativeSelectionPositionRow,_=u,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.EAST_RESIZE?f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:n===b.CURSOR_TYPE.SOUTH_WEST_RESIZE?(g=this._relativeSelectionPositionRow,_=u,f=d,v=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.SOUTH_RESIZE&&(g=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=d,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:R,startColumn:M,endRow:T,endColumn:E}=this._swapPositions(g,_,f,v),w=this._skeleton.getNoMergeCellPositionByIndex(R,M),y=this._skeleton.getNoMergeCellPositionByIndex(T,E),O=(w==null?void 0:w.startY)||0,x=(y==null?void 0:y.endY)||0,A=(w==null?void 0:w.startX)||0,B=(y==null?void 0:y.endX)||0;this._targetSelection={startY:O,endY:x,startX:A,endX:B,startRow:g,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,t){const{offsetX:n,offsetY:o}=e,r=this._scene,s=r.getRelativeCoord(b.Vector2.FromArray([n,o])),{x:a,y:c}=s;this._startOffsetX=n,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,t===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):t===b.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:t===b.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:t===b.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:t===b.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const g=b.ScrollTimer.create(r);g.startScroll(a,c),this._scrollTimer=g,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(_=>{const{offsetX:f,offsetY:v}=_,{x:R,y:M}=r.getRelativeCoord(b.Vector2.FromArray([f,v]));this._widgetMoving(R,M,t),r.setCursor(t),g.scrolling(R,M,()=>{this._widgetMoving(R,M,t)})}),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,t){var B,P,F;const n=this._scene,o=n.getScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=a,u=n.getRelativeCoord(b.Vector2.FromArray([e,t])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let g=this._relativeSelectionPositionRow,_=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,R=!1,M=!0;if((d<_||d>v)&&c>=g&&c<=f){const k=this._fillRuler(d,_,v,this._relativeSelectionColumnLength,m);_=k.startRowOrColumn,v=k.endRowOrColumn,R=k.isLighten,M=!1}else if((c<g||c>f)&&d>=_&&d<=v){const k=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=k.startRowOrColumn,f=k.endRowOrColumn,R=k.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const k=this._fillRuler(d,_,v,this._relativeSelectionColumnLength,m);_=k.startRowOrColumn,v=k.endRowOrColumn,R=k.isLighten,M=!1}else{const k=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=k.startRowOrColumn,f=k.endRowOrColumn,R=k.isLighten}const T=this._skeleton.getNoMergeCellPositionByIndex(g,_),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;R?this._controlHandler((k,j)=>{const $=new l.ColorKit(this._fillControlColors[j]).lighten(Os).toRgbString();k.setProps({fill:$})}):this._controlHandler((k,j)=>{k.setProps({fill:this._fillControlColors[j]})});const A=S.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();g===f&&M===!0||_===v&&M===!1?(B=this._helperSelection)==null||B.hide():((P=this._helperSelection)==null||P.transformByState({left:O-A/2,top:w-A/2,width:x-O,height:y-w}),(F=this._helperSelection)==null||F.show()),this._targetSelection={startY:w,endY:y,startX:O,endX:x,startRow:g,endRow:f,startColumn:_,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([t,n])),{x:s,y:a}=r;this._startOffsetX=s,this._startOffsetY=a;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 g=m==null?void 0:m.stroke,_=m==null?void 0:m.strokeWidth;const f=S.getNormalSelectionStyle(this._themeService);g==null&&(g=f.stroke),_==null&&(_=f.strokeWidth);const v=this._getScale();_/=v;const R=S.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,M=new l.ColorKit(g).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new b.Rect(mo,{stroke:M,strokeWidth:_+R/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(b.Vector2.FromArray([t,n]));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,a,T),this._scrollTimer=E,o.disableEvent(),this._controlHandler(w=>{this._fillControlColors.push(w.fill)}),this._moveObserver=o.onPointerMoveObserver.add(w=>{var F;const{offsetX:y,offsetY:O}=w,x=o.getActiveViewportByCoord(b.Vector2.FromArray([y,O])),{x:A,y:B}=o.getRelativeCoord(b.Vector2.FromArray([y,O]));this._fillMoving(A,B),o.setCursor(b.CURSOR_TYPE.CROSSHAIR);const P=this._targetSelection;if(T&&x&&((F=this._activeViewport)==null?void 0:F.viewPortKey)!==(x==null?void 0:x.viewPortKey)){let k;P.startRow!==c?(E.scrollTimerType=b.ScrollTimerType.Y,k={...P,endRow:P.startRow}):P.endRow!==u?(E.scrollTimerType=b.ScrollTimerType.Y,k={...P,startRow:P.endRow}):P.startColumn!==d?(E.scrollTimerType=b.ScrollTimerType.X,k={...P,endColumn:P.startColumn}):(E.scrollTimerType=b.ScrollTimerType.X,k={...P,startColumn:P.endColumn}),this._isSelectionInViewport(k,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(A,B,()=>{this._fillMoving(A,B)})}),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,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(e,t,n,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:a,startColumn:c,endRow:d,endColumn:u}=s,h={left:t,top:e,right:o,bottom:n},m={left:c,top:a,right:u,bottom:d};if(b.isRectIntersect(h,m))return!0}return!1}_swapPositions(e,t,n,o){const r=Math.min(e,n),s=Math.min(t,o),a=Math.max(e,n),c=Math.max(t,o);return{startRow:r,startColumn:s,endRow:a,endColumn:c}}_controlHandler(e){const{leftControl:t,rightControl:n,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:a,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[t,n,o,r,s,a,c,d,u];for(let m=0,g=h.length;m<g;m++){const _=h[m];e(_,m)}}_fillRuler(e,t,n,o,r){let s=!1;if(e<t)if(this._isInMergeState&&e<t){const a=t-e,c=o+1,d=Math.ceil(a/c);let u=t-d*c;u<0&&(u=t-(d-1)*c),t=u}else t=e;else if(e>=t&&e<=n)s=!0,n=e;else if(this._isInMergeState&&e>n){const a=e-n,c=o+1,d=Math.ceil(a/c);let u=n+d*c;u>r&&(u=n+(d-1)*c),n=u}else n=e;return{rowOrColumn:e,startRowOrColumn:t,endRowOrColumn:n,isLighten:s}}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}}var xs=Object.defineProperty,As=Object.getOwnPropertyDescriptor,Ns=(i,e,t,n)=>{for(var o=n>1?void 0:n?As(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&xs(e,t,o),o},sn=(i,e)=>(t,n)=>e(t,n,i);exports.SelectionRenderService=class{constructor(e,t,n,o){C(this,"hasSelection",!1);C(this,"_downObserver");C(this,"_moveObserver");C(this,"_upObserver");C(this,"_controlFillConfig$",new D.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 D.BehaviorSubject([]));C(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());C(this,"_selectionMoving$",new D.Subject);C(this,"selectionMoving$",this._selectionMoving$.asObservable());C(this,"_selectionMoveStart$",new D.Subject);C(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());C(this,"_activeViewport");this._themeService=e,this._shortcutService=t,this._sheetSkeletonManagerService=n,this._injector=o,this._selectionStyle=S.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(S.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 t=this.getCurrentControls();if(!t)return;const{rangeWithCoord:n,primaryWithCoord:o}=e,r=this._skeleton;let s=e.style;s==null&&(s=S.getNormalSelectionStyle(this._themeService));const a=this._scene;if(a==null||r==null)return;const c=new Fn(a,t.length,this._isHeaderHighlight,this._themeService);new go(c,r,a,this._themeService,this._injector);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(n,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),t.push(c)}updateControlForCurrentByRangeData(e){const t=this.getCurrentControls();if(!t)return;const n=this._skeleton;if(n==null)return;const{rowHeaderWidth:o,columnHeaderHeight:r}=n;for(let s=0,a=e.length;s<a;s++){const{rangeWithCoord:c,primaryWithCoord:d,style:u}=e[s];t[s].update(c,o,r,u,d)}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}changeRuntime(e,t,n){this._skeleton=e,this._scene=t,this._activeViewport=n||t.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(t=>t.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const e=this.getCurrentControls();if(e.length>0){for(const t of e)t.dispose();e.length=0}}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(!this._scene||e===void 0||t===void 0)return null;const n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0)return this._scene.getViewport(V.VIEW_MAIN);if(e>n.startRow&&t>n.startColumn)return this._scene.getViewport(V.VIEW_MAIN);if(e<=n.startRow&&t<=n.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT_TOP);if(e<=n.startRow&&t>n.startColumn)return this._scene.getViewport(V.VIEW_MAIN_TOP);if(e>n.startRow&&t<=n.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(n=>{const o=n.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(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.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,t=0,n=l.RANGE_TYPE.NORMAL,o,r=b.ScrollTimerType.ALL){var ee,ie;if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:a,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([a,c]));let{x:m,y:g}=h;this._startOffsetX=m,this._startOffsetY=g;const _=d.getScrollXYByRelativeCoords(h),{scaleX:f,scaleY:v}=d.getAncestorScale();n===l.RANGE_TYPE.ROW?m=0:n===l.RANGE_TYPE.COLUMN&&(g=0);const R=this._getSelectedRangeWithMerge(m,g,f,v,_);if(!R)return!1;const{rangeWithCoord:M,primaryWithCoord:T}=R,{startRow:E,startColumn:w,endColumn:y,endRow:O,startY:x,endY:A,startX:B,endX:P}=M,{rowHeaderWidth:F,columnHeaderHeight:k}=s,j={startColumn:w,startRow:E,endColumn:y,endRow:O,startY:x,endY:A,startX:B,endX:P,rangeType:n};this._startSelectionRange=j;let $=this.getActiveSelection();const G=this.getCurrentControls();if(!G)return!1;for(const z of G){if(e.button===2&&z.model.isInclude(j)){$=z;return}if(z.model.isEqual(j)){$=z;break}e.shiftKey||z.clearHighlight()}if(G.length>0&&!e.ctrlKey&&!e.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const z of G)z.dispose();G.length=0}const W=$&&$.model.currentCell;if($&&e.shiftKey&&W){const{actualRow:z,actualColumn:Z,mergeInfo:K}=W,le=Math.min(z,j.startRow,K.startRow),se=Math.max(z,j.endRow,K.endRow),me=Math.min(Z,j.startColumn,K.startColumn),ke=Math.max(Z,j.endColumn,K.endColumn),pe=s.getMergeBounding(le,me,se,ke),ue=s.getNoMergeCellPositionByIndex(pe.startRow,pe.startColumn),ae=s.getNoMergeCellPositionByIndex(pe.endRow,pe.endColumn),Ve={startColumn:pe.startColumn,startRow:pe.startRow,endColumn:pe.endColumn,endRow:pe.endRow,startY:ue.startY,endY:ae.endY,startX:ue.startX,endX:ae.endX,rangeType:n},ve=s.getCellByIndex(z,Z);this._startSelectionRange={startColumn:ve.mergeInfo.startColumn,startRow:ve.mergeInfo.startRow,endColumn:ve.mergeInfo.endColumn,endRow:ve.mergeInfo.endRow,startY:ve.mergeInfo.startY||0,endY:ve.mergeInfo.endY||0,startX:ve.mergeInfo.startX||0,endX:ve.mergeInfo.endX||0,rangeType:n},$.update(Ve,F,k,this._selectionStyle,W)}else this._isRemainLastEnable&&$&&!e.ctrlKey&&!e.shiftKey&&!this._isSkipRemainLastEnable?$.update(j,F,k,this._selectionStyle,T):($=new Fn(d,G.length+t,this._isHeaderHighlight,this._themeService),new go($,s,d,this._themeService,this._injector),$.update(j,F,k,this._selectionStyle,T),G.push($));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const J=d.getActiveViewportByCoord(b.Vector2.FromArray([m,g])),re=b.ScrollTimer.create(this._scene,r);re.startScroll((ee=u==null?void 0:u.left)!=null?ee:0,(ie=u==null?void 0:u.top)!=null?ie:0,u),this._scrollTimer=re,this._addCancelObserver(),(n===l.RANGE_TYPE.ROW||n===l.RANGE_TYPE.COLUMN)&&this._moving(m,g,$,n);let Y=0,U=0,L=m,X=g;this._moveObserver=d.onPointerMoveObserver.add(z=>{var ve,At,Nt,Dt,Pt,Ji,Qi,eo,to,no;const{offsetX:Z,offsetY:K}=z,{x:le,y:se}=d.getRelativeCoord(b.Vector2.FromArray([Z,K]));this._moving(le,se,$,n);let me=le,ke=se;const pe=this.getActiveSelection(),ue=(ve=this._sheetSkeletonManagerService.getCurrent())==null?void 0:ve.skeleton.getWorksheetConfig().freeze,ae=pe==null?void 0:pe.model,Ve=(At=d.getActiveViewportByCoord(b.Vector2.FromArray([Z,K])))!=null?At:this._getViewportByCell(ae==null?void 0:ae.endRow,ae==null?void 0:ae.endColumn);if(J&&Ve&&u){const ti=L<u.left&&le>u.left||L>u.left&&le<u.left,ni=X<u.top&&se>u.top||X>u.top&&se<u.top;ti&&(Y+=1),ni&&(U+=1);const xe=J.viewPortKey,Ht=Ve.viewPortKey;if(xe===V.VIEW_ROW_TOP)K<u.top&&((Nt=ae==null?void 0:ae.endRow)!=null?Nt:0)<((Dt=ue==null?void 0:ue.startRow)!=null?Dt:0)?ke=u.top:ni&&U%2===1&&u.scrollTo({y:0});else if(xe===V.VIEW_COLUMN_LEFT)Z<u.left&&((Pt=ae==null?void 0:ae.endColumn)!=null?Pt:0)<((Ji=ue==null?void 0:ue.startColumn)!=null?Ji:0)?me=u.left:ti&&Y%2===1&&u.scrollTo({x:0});else if(xe===Ht){let Be=!1,Qe=!1;xe===V.VIEW_MAIN_LEFT_TOP?(Be=!0,Qe=!0):xe===V.VIEW_MAIN_TOP?Qe=!0:xe===V.VIEW_MAIN_LEFT&&(Be=!0),((Qi=ae==null?void 0:ae.endRow)!=null?Qi:0)>((eo=ue==null?void 0:ue.startRow)!=null?eo:0)&&(Qe=!1),((to=ae==null?void 0:ae.endColumn)!=null?to:0)>((no=ue==null?void 0:ue.startColumn)!=null?no:0)&&(Be=!1),Be&&(me=u.left),Qe&&(ke=u.top)}else{const Be={x:J.scrollX,y:J.scrollY},Qe={x:Ve.scrollX,y:Ve.scrollY},ii=Be.x!==Qe.x&&ti&&Y%2===1,oi=Be.y!==Qe.y&&ni&&U%2===1;(ii||oi)&&(u.scrollTo({x:ii?Be.x:void 0,y:oi?Be.y:void 0}),ii||(me=u.left),oi||(ke=u.top)),(xe===V.VIEW_MAIN_LEFT_TOP&&Ht===V.VIEW_MAIN_LEFT||Ht===V.VIEW_MAIN_LEFT_TOP&&xe===V.VIEW_MAIN_LEFT)&&(me=u.left),(xe===V.VIEW_MAIN_LEFT_TOP&&Ht===V.VIEW_MAIN_TOP||Ht===V.VIEW_MAIN_LEFT_TOP&&xe===V.VIEW_MAIN_TOP)&&(ke=u.top)}L=le,X=se}re.scrolling(me,ke,()=>{this._moving(le,se,$,n)})}),this._upObserver=d.onPointerUpObserver.add(z=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(e){const{range:t,primary:n,style:o}=e;let r=this.convertRangeDataToSelection(t);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:l.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(n),style:o}}convertRangeDataToSelection(e){const{startRow:t,startColumn:n,endRow:o,endColumn:r,rangeType:s}=e,a=this._scene,c=this._skeleton;if(a==null||c==null)return;a.getAncestorScale();const d=c.getNoMergeCellPositionByIndex(t,n),u=c.getNoMergeCellPositionByIndex(o,r);return{startRow:t,startColumn:n,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 t=this._scene,n=this._skeleton;if(t==null||n==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startRow:c,startColumn:d,endRow:u,endColumn:h}=e,m=n.getNoMergeCellPositionByIndex(o,r),g=n.getNoMergeCellPositionByIndex(c,d),_=n.getNoMergeCellPositionByIndex(u,h);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startX:m.startX,startY:m.startY,endX:m.endX,endY:m.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(g==null?void 0:g.startY)||0,endY:(_==null?void 0:_.endY)||0,startX:(g==null?void 0:g.startX)||0,endX:(_==null?void 0:_.endX)||0}}}_moving(e,t,n,o){var ie;const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:a,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,{startRow:h,endRow:m,startColumn:g,endColumn:_}=(n==null?void 0:n.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1},f=s.getViewport(V.VIEW_MAIN),v=(ie=this._getViewportByCell(m,_))!=null?ie:f,R=s.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),v),{scaleX:M,scaleY:T}=s.getAncestorScale(),{rowHeaderWidth:E,columnHeaderHeight:w}=r;o===l.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===l.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const y=this._getSelectedRangeWithMerge(e,t,M,T,R);if(!y)return!1;const{rangeWithCoord:O,primaryWithCoord:x}=y,{startRow:A,startColumn:B,endColumn:P,endRow:F}=O,k=Math.min(A,a),j=Math.min(B,c),$=Math.max(F,d),G=Math.max(P,u);let W={startRow:k,startColumn:j,endRow:$,endColumn:G};if(this._isDetectMergedCell&&(W=r.getSelectionBounding(k,j,$,G)),!W)return!1;const{startRow:J,startColumn:re,endRow:Y,endColumn:U}=W,L=r.getNoMergeCellPositionByIndex(J,re),X=r.getNoMergeCellPositionByIndex(Y,U),ee={startColumn:re,startRow:J,endColumn:U,endRow:Y,startY:(L==null?void 0:L.startY)||0,endY:(X==null?void 0:X.endY)||0,startX:(L==null?void 0:L.startX)||0,endX:(X==null?void 0:X.endX)||0};(g!==re||h!==J||_!==U||m!==Y)&&n!=null&&(n.update(ee,E,w),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var n,o;const e=this._scene;if(e==null)return;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),e.enableEvent(),(n=this._scrollTimer)==null||n.dispose();const t=(o=e.getEngine())==null?void 0:o.activeScene;t==null||t.onPointerDownObserver.remove(this._cancelDownObserver),t==null||t.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var n;const e=this._scene;if(e==null)return;const t=(n=e.getEngine())==null?void 0:n.activeScene;t==null||t===e||(t.onPointerDownObserver.remove(this._cancelDownObserver),t.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=t.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=t.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(e,t,n,o,r){var R;if(this._isDetectMergedCell){const M=(R=this._skeleton)==null?void 0:R.calculateCellIndexByPosition(e,t,n,o,r),T=l.makeCellToSelection(M);return T==null?void 0:{primaryWithCoord:M,rangeWithCoord:T}}const s=this._skeleton;if(s==null)return;const a=s.getCellPositionByOffset(e,t,n,o,r),{row:c,column:d}=a,u=s.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:m,endX:g,endY:_}=u,f={startY:m,endY:_,startX:h,endX:g,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:m,endY:_,startX:h,endX:g,mergeInfo:f},rangeWithCoord:f}}};exports.SelectionRenderService=Ns([sn(0,N.Inject(l.ThemeService)),sn(1,I.IShortcutService),sn(2,N.Inject(exports.SheetSkeletonManagerService)),sn(3,N.Inject(N.Injector))],exports.SelectionRenderService);const _e=N.createIdentifier("deprecated.univer.sheet.selection-render-service");var Ds=Object.defineProperty,Ps=Object.getOwnPropertyDescriptor,Hs=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ps(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ds(e,t,o),o},et=(i,e)=>(t,n)=>e(t,n,i);const Ls=1e4,qt=N.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends l.Disposable{constructor(t,n,o,r,s,a,c){super();C(this,"_shapeMap",new Map);this._currentService=t,this._renderManagerService=n,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=a,this._selectionManagerService=c}addShape(t,n=[],o=Ls){const r=this._currentService.getCurrentUniverSheetInstance(),s=r.getActiveSheet().getSheetId(),a=l.Tools.generateRandomId();return this._shapeMap.set(a,{selection:t,subUnitId:s,unitId:r.getUnitId(),zIndex:o,control:null,exits:n}),this.refreshShapes(),a}refreshShapes(){const t=this._currentService.getCurrentUniverSheetInstance().getUnitId(),n=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var M;const{unitId:r,subUnitId:s,selection:a,control:c,zIndex:d}=o;if(c&&c.dispose(),r!==t||s!==n)return;const{style:u}=a,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:g}=this._selectionRenderService.convertSelectionRangeToData(a),_=(M=this._sheetSkeletonManagerService.getCurrent())==null?void 0:M.skeleton;if(!h||!_)return;const{rowHeaderWidth:f,columnHeaderHeight:v}=_,R=new Fn(h,d,!1,this._themeService);R.update(m,f,v,u,g),o.control=R})}getShapeMap(){return this._shapeMap}removeShape(t){const n=this._shapeMap.get(t);if(!n)return;const{control:o}=n;o&&o.dispose(),this._shapeMap.delete(t)}removeAllShapes(){for(const t of this._shapeMap.values()){const{control:n}=t;n&&n.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=Hs([et(0,l.IUniverInstanceService),et(1,b.IRenderManagerService),et(2,_e),et(3,l.ICommandService),et(4,N.Inject(exports.SheetSkeletonManagerService)),et(5,N.Inject(l.ThemeService)),et(6,N.Inject(S.SelectionManagerService))],exports.MarkSelectionService);const Us=10,ks=6;function Vs(){return l.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 l.LRUMap(Us))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}del(e){this._cache.delete(e)}clear(){this._cache.clear()}}var rt=(i=>(i.COPY="COPY",i.CUT="CUT",i))(rt||{});function Ws(i,e,t,n,o){const r=[],s=[];if(n.copyType===rt.CUT){const{undos:a,redos:c}=js(i,e,o);r.push(...c),s.push(...a)}else{const{undos:a,redos:c}=tr(e,t,o);r.push(...c),s.push(...a);const{undos:d,redos:u}=Qo(e,t,o);r.push(...u),s.push(...d);const{undos:h,redos:m}=er(e,t,o);r.push(...m),s.push(...h);const{undos:g,redos:_}=Ii(e,t,o);r.push(..._),s.push(...g)}return{undos:s,redos:r}}function js(i,e,t){let n=[],o=[];const{range:r,subUnitId:s,unitId:a}=i,{range:c,subUnitId:d}=e;if(r&&c){const u=t.get(l.IUniverInstanceService),h=t.get(S.SheetInterceptorService),m=u.getUniverSheetInstance(a),g=m==null?void 0:m.getSheetBySheetId(s),_=m==null?void 0:m.getSheetBySheetId(d);if(g&&_){const f=new l.ObjectMatrix,v=new l.ObjectMatrix,R=(W,J)=>({startRow:W,endRow:W,startColumn:J,endColumn:J}),M=g.getCellMatrix(),T=_.getCellMatrix();l.Range.foreach(r,(W,J)=>{f.setValue(W,J,l.Tools.deepClone(M.getValue(W,J))),v.setValue(W,J,null)});const E=new l.ObjectMatrix;l.Range.foreach(c,(W,J)=>{E.setValue(W,J,l.Tools.deepClone(T.getValue(W,J)))});const w=new l.ObjectMatrix;l.Range.foreach(r,(W,J)=>{const re=R(W,J),Y=l.Rectangle.getRelativeRange(re,r),U=l.Rectangle.getPositionRange(Y,c);w.setValue(U.startRow,U.startColumn,M.getValue(W,J))});const y={from:{value:v.getMatrix(),subUnitId:s},to:{value:w.getMatrix(),subUnitId:d},unitId:a},O={from:{value:f.getMatrix(),subUnitId:s},to:{value:E.getMatrix(),subUnitId:d},unitId:a},x=h.onCommandExecute({id:S.MoveRangeCommand.id,params:{toRange:c,fromRange:r}}),A=g.getMergeData(),B=_.getMergeData(),P=A.filter(W=>l.Rectangle.intersects(W,r)),F=B.filter(W=>l.Rectangle.intersects(W,c)),k=P.map(W=>l.Rectangle.getRelativeRange(W,r)).map(W=>l.Rectangle.getPositionRange(W,c)),j=S.getAddMergeMutationRangeByType(k).filter(W=>!B.some(J=>l.Rectangle.equals(W,J))),$=[{id:S.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:P}},{id:S.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:F}},{id:S.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:j}}],G=[{id:S.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:j}},{id:S.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:F}},{id:S.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:P}}];n=[{id:S.MoveRangeMutation.id,params:y},...x.redos,...$,{id:S.SetSelectionsOperation.id,params:{unitId:a,subUnitId:d,pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:c}]}}],o=[{id:S.SetSelectionsOperation.id,params:{unitId:a,sheetId:s,pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:r}]}},...x.undos,...G,{id:S.MoveRangeMutation.id,params:O}]}}return{undos:o,redos:n}}function Qo(i,e,t){const{unitId:n,subUnitId:o,range:r}=i,s=[],a=[],{startColumn:c,startRow:d}=r,u=new l.ObjectMatrix;e.forValue((g,_,f)=>{u.setValue(g+d,_+c,{v:f.v})});const h={unitId:n,subUnitId:o,cellValue:u.getData()};s.push({id:S.SetRangeValuesMutation.id,params:h});const m=S.SetRangeValuesUndoMutationFactory(t,h);return a.push({id:S.SetRangeValuesMutation.id,params:m}),{undos:a,redos:s}}function er(i,e,t){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d}=a,u=new l.ObjectMatrix;e.forValue((g,_,f)=>{var R;const v={s:f.s};(R=f.p)!=null&&R.body&&(v.p=f.p),u.setValue(g+d,_+c,v)});const h={unitId:r,subUnitId:s,cellValue:u.getData()};n.push({id:S.SetRangeValuesMutation.id,params:h});const m=S.SetRangeValuesUndoMutationFactory(t,h);return o.push({id:S.SetRangeValuesMutation.id,params:m}),{undos:o,redos:n}}function tr(i,e,t){const n=[],o=[],r=new l.ObjectMatrix,{unitId:s,subUnitId:a,range:c}=i,{startColumn:d,startRow:u}=c;if(e.forValue((h,m,g)=>{g.s&&r.setValue(h+u,m+d,{s:null})}),r.getLength()>0){const h={subUnitId:a,unitId:s,cellValue:r.getData()};n.push({id:S.SetRangeValuesMutation.id,params:h});const m=S.SetRangeValuesUndoMutationFactory(t,h);o.push({id:S.SetRangeValuesMutation.id,params:m})}return{undos:o,redos:n}}function Ii(i,e,t){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d,endColumn:u,endRow:h}=a;let m=!1;const g=[];if(e.forValue((v,R,M)=>{if(M.rowSpan){const T=M.colSpan||1,E={startRow:d+v,endRow:d+v+M.rowSpan-1,startColumn:c+R,endColumn:c+R+T-1};g.push(E),m=!0}else if(M.colSpan){const T=M.rowSpan||1,E={startRow:d+v,endRow:d+v+T-1,startColumn:c+R,endColumn:c+R+M.colSpan-1};g.push(E),m=!0}}),m){const R=t.get(l.IUniverInstanceService).getUniverSheetInstance(r),M=R==null?void 0:R.getSheetBySheetId(s);if(R&&M){const E=M.getMergeData().filter(O=>l.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},O)),w={unitId:r,subUnitId:s,ranges:E};n.push({id:S.RemoveWorksheetMergeMutation.id,params:w});const y=S.RemoveMergeUndoMutationFactory(t,w);o.push({id:S.AddWorksheetMergeMutation.id,params:y})}}const _={unitId:r,subUnitId:s,ranges:g};n.push({id:S.AddWorksheetMergeMutation.id,params:_});const f=S.AddMergeUndoMutationFactory(t,_);return o.push({id:S.RemoveWorksheetMergeMutation.id,params:f}),{undos:o,redos:n}}function nr(i){let e=i.replace(/(\r\n|\n)/g,"\r");e.endsWith(`\r
2
- `)||(e+=`\r
3
- `);const t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t,sectionBreaks:[{startIndex:e.indexOf(`
4
- `)}]}}function Ai(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=l.BooleanNumber.TRUE;break}case"s":{t.st={s:l.BooleanNumber.TRUE};break}case"u":{t.ul={s:l.BooleanNumber.TRUE};break}case"i":{t.it=l.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?l.BaselineOffset.SUPERSCRIPT:l.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{t.ff=s;break}case"font-size":{const a=Number.parseInt(s);Number.isNaN(a)||s.endsWith("pt")&&(t.fs=a);break}case"font-style":{s==="italic"&&(t.it=l.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=l.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:l.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:l.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:l.BooleanNumber.TRUE});break}case"color":{const a=new l.ColorKit(s);a.isValid&&(t.cl={rgb:a.toRgbString()});break}case"background-color":{const a=new l.ColorKit(s);a.isValid&&(t.bg={rgb:a.toRgbString()});break}}}return t}function $s(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function zs(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const o=e[n],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=Number.parseInt(r);t.spaceAbove=/pt/.test(r)?_o(s):s;break}case"margin-bottom":{const s=Number.parseInt(r);t.spaceBelow=/pt/.test(r)?_o(s):s;break}}}return Object.getOwnPropertyNames(t).length?t:null}function _o(i){return i/.75}function So(i,e){const t=[];for(let n=0,o=i.length;n<o;n++)i[n]===l.DataStreamTreeTokenType.PARAGRAPH&&t.push({startIndex:n});if(e)for(const n of t)e.bullet&&(n.bullet=l.Tools.deepClone(e.bullet)),e.paragraphStyle&&(n.paragraphStyle=l.Tools.deepClone(e.paragraphStyle));return t}function fo(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const zn=class zn{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 t=zn.pluginList.find(g=>g.checkPasteType(e));t&&(this.styleRules=[...t.stylesRules],this.afterProcessRules=[...t.afterProcessRules]);const n=new l.ObjectMatrix,o=$s(e),r={dataStream:"",textRuns:[]},s=[],a=[],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 g=u.map(_=>_.startIndex+1);g.unshift(0);for(let _=0;_<g.length;_++){let f;_===g.length-1?f=`${h.substring(g[_])}\r
5
- `:f=`${h.substring(g[_],g[_+1]-1)}\r
6
- `;const v=[];m==null||m.forEach(M=>{M.st>=g[_]&&M.ed<=g[_+1]&&v.push({st:M.st-g[_],ed:M.ed-g[_],ts:M.ts})});const R=this._generateDocumentDataModelSnapshot({body:{dataStream:f,textRuns:v,paragraphs:So(f)}});n.setValue(n.getLength(),0,{v:f,p:R}),s.push({}),c&&d.forEach(M=>{const T=n.getDataRange().endRow+1;if(M.index===_){const E=c.shift(),{cellMatrix:w,colProperties:y,rowProperties:O}=this._parseTable(E);w&&w.forValue((x,A,B)=>{n.setValue(T+x,A,B)}),y&&a.push(...y),s.push(...O)}})}}else{if(h){const g=`${h}\r
7
- `,_={dataStream:g,textRuns:m,paragraphs:So(g)},f=this._generateDocumentDataModelSnapshot({body:_});n.setValue(0,0,{v:h,p:f}),s.push({})}c&&c.forEach(g=>{const _=n.getDataRange().endRow+1,{cellMatrix:f,rowProperties:v,colProperties:R}=this._parseTable(g);f&&f.forValue((M,T,E)=>{const{rowSpan:w=1,colSpan:y=1}=E;for(let O=0;O<w;O++)for(let x=0;x<y;x++)n.setValue(_+M+O,T+x,{v:""});n.setValue(_+M,T,E)}),R&&a.push(...R),s.push(...v)})}return{rowProperties:s,colProperties:a,cellMatrix:n}}_parseTable(e){const t=new l.ObjectMatrix,n=Zs(e),{rowProperties:o,rowCount:r,cellMatrix:s}=Ys(e);return s&&s.forValue((a,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=nr(d.content),g=this._generateDocumentDataModelSnapshot({body:m});t.setValue(a,c,{v:d.content,p:g,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}else t.setValue(a,c,{v:d.content,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}),{rowProperties:o,colProperties:n,cellMatrix:t}}_generateDocumentDataModelSnapshot(e){var a;const t=this.getCurrentSkeleton();if(t==null)return null;const{skeleton:n}=t,o=(a=n.getBlankCellDocumentModel())==null?void 0:a.documentModel,s={...o==null?void 0:o.getSnapshot(),...e};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(e,t,n,o){var r,s;for(const a of t)if(a.nodeName.toLowerCase()==="table")o.push({index:((r=n==null?void 0:n.paragraphs)==null?void 0:r.length)||0});else if(a.nodeType===Node.TEXT_NODE){const c=(s=a.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:[]};n.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(n.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}),u.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}))}else if(a.nodeType===Node.ELEMENT_NODE){const c=e?this.styleCache.get(e):{},d=this.styleRules.find(({filter:g})=>fo(a,g)),u=d?d.getStyle(a):Ai(a);this.styleCache.set(a,{...c,...u});const{childNodes:h}=a;this.process(a,h,n,o);const m=this.afterProcessRules.find(({filter:g})=>fo(a,g));m&&m.handler(n,a)}}};C(zn,"pluginList",[]);let Yt=zn;function Ys(i){const e=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,t=i.matchAll(e);if(!t)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const n=Array.from(t),o=n.map(a=>Ni(a[1])),{colCount:r,cellMatrix:s}=Xs(n.map(a=>a[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function Xs(i){const e=new l.ObjectMatrix,t=new Map,n=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((a,c)=>{const d=c===0,u=a.matchAll(n);r=0,Array.from(u).forEach(h=>{const m=Ni(h[1]),g=Gs(h[2].replace("<br>","\r").replace(/<\/?[^>]*>/g,"")),_=m.rowspan?+m.rowspan:1,f=m.colspan?+m.colspan:1;if(!d){for(let R=r;R<o;R++)if(!(t.get(R)>=s)){r=R;break}}const v={content:g,properties:m};f>1&&(v.colSpan=+f),_>1&&(v.rowSpan=+_),d&&(o+=f);for(let R=r;R<r+f;R++)t.set(R,s+_-1);e.setValue(s,r,v),r+=f}),s+=1}),{colCount:o,cellMatrix:e}}function Ni(i){if(!i)return{};const e=/([\w-]+)="([^"]*)"/gi,t=i.matchAll(e),n={};return Array.from(t).forEach(o=>{const[r,s,a]=o;n[s]=a}),n}function Zs(i){const e=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,t=i.match(e);if(!t||!t[2])return null;const n=/<col([\s\S]*?)>/g,o=t[2].matchAll(n);return o?Array.from(o).map(r=>Ni(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,t=>e[t])}const Ks={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:l.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"}}]},qs=Ks,Js={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:l.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=zs(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Qs=Js;function ea(i,e,t,n){const o=t.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=Di(o),s=Pi(r),a=e.map(c=>ta(i,c,t,n)).filter(c=>!!c).join("");return`<tr${s}>${a}</tr>`}function ta(i,e,t,n){const o=n.getValue(i,e),r=t.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=Di(r),a=Pi(s),c=t.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,e))||""},"");return`<td${a}>${c}</td>`}function na(i,e){return`<colgroup>${i.map(n=>{const o=e.map(a=>{var c;return(c=a.onCopyColumn)==null?void 0:c.call(a,n)}).filter(a=>!!a),r=Di(o);return`<col ${Pi(r)}>`}).join("")}</colgroup>`}function Di(i){return i.reduce((e,t)=>(Object.keys(t).forEach(o=>{e[o]?e[o]+=`;${t[o]}`:e[o]=t[o]}),e),{})}function Pi(i){return Object.keys(i).reduce((e,t)=>(e+=` ${t}="${i[t]}"`,e),"")}function ia(i,e){const t=[];for(let n=i;n<=e;n++)t.push(n);return t}class oa{convert(e,t,n){const{startColumn:o,endColumn:r}=t,s=na(ia(o,r),n),a=[],{startRow:c,endRow:d,startColumn:u,endColumn:h}=e.getDataRange();for(let g=c;g<=d;g++){const _=Array.from({length:h-u+1},(f,v)=>u+v);a.push(ea(g,_,n,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>${a.join("")}</tbody></table>`}}var ra=Object.defineProperty,sa=Object.getOwnPropertyDescriptor,aa=(i,e,t,n)=>{for(var o=n>1?void 0:n?sa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ra(e,t,o),o},Xe=(i,e)=>(t,n)=>e(t,n,i);const fe={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"};Yt.use(Qs);Yt.use(qs);const Mt=N.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends l.Disposable{constructor(t,n,o,r,s,a,c,d){super();C(this,"_clipboardHooks",[]);C(this,"_clipboardHooks$",new D.BehaviorSubject([]));C(this,"clipboardHooks$",this._clipboardHooks$.asObservable());C(this,"_htmlToUSM");C(this,"_usmToHtml");C(this,"_copyContentCache");C(this,"_copyMarkId",null);this._logService=t,this._currentUniverService=n,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=a,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Yt({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new oa,this._copyContentCache=new Fs}copyContentCache(){return this._copyContentCache}async copy(t=rt.COPY){const n=this._selectionManagerService.getLast();if(!n)return!1;const o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=this._clipboardHooks;s.forEach(g=>{var _;return(_=g.onBeforeCopy)==null?void 0:_.call(g,o.getUnitId(),r.getSheetId(),n.range)});const a=this._generateCopyContent(o.getUnitId(),r.getSheetId(),n.range,s);if(!a)return!1;const{html:c,plain:d,matrixFragment:u,copyId:h}=a;this._copyContentCache.set(h,{unitId:o.getUnitId(),subUnitId:r.getSheetId(),range:n.range,matrix:u,copyType:t}),await this._clipboardInterfaceService.write(d,c),this._markSelectionService.removeAllShapes();const m=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...n,style:m}),s.forEach(g=>{var _;return(_=g.onAfterCopy)==null?void 0:_.call(g)}),!0}async cut(){return this.copy(rt.CUT)}async paste(t,n=fe.DEFAULT_PASTE){const o=t.types,r=o.indexOf(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"",s=o.indexOf(I.HTML_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(I.HTML_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"";return s?this._pasteHTML(s,n):r?this._pastePlainText(r,n):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(t,n){return t?this._pasteHTML(t,fe.DEFAULT_PASTE):n?this._pastePlainText(n,fe.DEFAULT_PASTE):Promise.resolve(!1)}addClipboardHook(t){if(this._clipboardHooks.findIndex(o=>o.id===t.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",t.id),{dispose:()=>{}};const n=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(t.priority||0)<r});return this._clipboardHooks.splice(n!==-1?n:this._clipboardHooks.length,0,t),this._notifyClipboardHook(),l.toDisposable(()=>{const o=this._clipboardHooks.indexOf(t);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(t,n,o,r){const s=this._currentUniverService.getUniverSheetInstance(t),a=s==null?void 0:s.getSheetBySheetId(n);if(!s||!a)return null;r.reduce((R,M)=>{var E;const T=(E=M.getFilteredOutRows)==null?void 0:E.call(M);return T==null||T.forEach(w=>R.add(w)),R},new Set);const{startColumn:c,startRow:d,endColumn:u,endRow:h}=o,m=a.getMatrixWithMergedCells(d,c,h,u),g=new l.ObjectMatrix;for(let R=d;R<=h;R++)for(let M=c;M<=u;M++){const T=m.getValue(R,M);T?g.setValue(R-d,M-c,{...po(),...l.Tools.deepClone(T)}):g.setValue(R-d,M-c,po())}let _=this._usmToHtml.convert(m,o,r);const f=la(g),v=Vs();return _=_.replace(/(<[a-z]+)/,(R,M)=>`${M} data-copy-id="${v}"`),{copyId:v,plain:f,html:_,matrixFragment:g}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(t,n){const o=this._getPastingTarget();if(!o.selection)return!1;const r=o.selection.range,{unitId:s,subUnitId:a}=o,c=this._clipboardHooks,d=[];if(c.some(_=>{var f;return d.push(_)&&((f=_.onBeforePaste)==null?void 0:f.call(_,{unitId:s,subUnitId:a,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:a,range:r},t,{pasteType:n});f&&(h.push(...f.redos),m.push(...f.undos))});const g=h.every(_=>this._commandService.executeCommand(_.id,_.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),undoMutations:m,redoMutations:h}),g}async _pasteHTML(t,n){const o=Bs(t);return o&&this._copyContentCache.get(o)?this._pasteInternal(o,n):this._pasteExternal(t,n)}async _pasteExternal(t,n){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(t),{startColumn:h,endColumn:m,startRow:g,endRow:_}=u.getDataRange(),f=_-g+1,v=m-h+1;if(!u||m<h||_<g)return!1;const R=this._transformPastedData(f,v,u,r.range);return R?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:a,pastedRange:R},n):!1}async _pasteInternal(t,n){var P,F;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o,c=l.Tools.deepClone(this._copyContentCache.get(t)),{range:d,matrix:u,unitId:h,subUnitId:m}=c||{};if(!r||!u||!c||!d||!h||!m||!r||!u||!c)return!1;const g=(P=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:P.getStyles();u.forValue((k,j,$)=>{if(typeof $.s=="string"){const G=l.Tools.deepClone($);G.s=g==null?void 0:g.getStyleByCell($),u.setValue(k,j,G)}});const{startColumn:_,endColumn:f,startRow:v,endRow:R}=d,M=this._transformPastedData(R-v+1,f-_+1,u,r.range);if(!M)return!1;const T=(F=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:F.getSheetBySheetId(m);if(!T)return!1;const E=T.getColumnManager(),w=T.getRowManager(),y=T.getConfig().defaultColumnWidth,O=T.getConfig().defaultRowHeight,x=[],A=[];for(let k=_;k<=f;k++){const j=E.getColumnOrCreate(k);x.push({width:`${j.w||y}`})}for(let k=v;k<=R;k++){const j=w.getRowOrCreate(k);A.push({height:`${j.h||O}`})}const B=this._pasteUSM({cellMatrix:u,colProperties:x,rowProperties:A},{unitId:s,subUnitId:a,pastedRange:M},n,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:t});return c.copyType===rt.CUT&&(this._copyContentCache.set(t,{...c,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),B}_pasteUSM(t,n,o,r){const{rowProperties:s,colProperties:a,cellMatrix:c}=t,{unitId:d,subUnitId:u,pastedRange:h}=n,{startColumn:m,endColumn:g}=h,_=g-m+1,f=this._clipboardHooks,v=[];if(f.some(A=>{var B;return v.push(A)&&((B=A.onBeforePaste)==null?void 0:B.call(A,{unitId:d,subUnitId:u,range:h}))===!1}))return v.forEach(A=>{var B;return(B=A.onAfterPaste)==null?void 0:B.call(A,!1)}),!1;if(!c)return!1;const M=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,T={copyType:(r==null?void 0:r.copyType)||rt.COPY,copyId:r==null?void 0:r.copyId,pasteType:o},E=[],w=[];v.filter(A=>!A.specialPasteInfo&&A.id!==fe.DEFAULT_PASTE||o===A.id).forEach(A=>{var F,k,j;if(s){const $=(F=A.onPasteRows)==null?void 0:F.call(A,{range:h,unitId:d,subUnitId:u},s,{pasteType:o});$&&(E.push(...$.redos),w.push(...$.undos))}const B=(k=A.onPasteColumns)==null?void 0:k.call(A,{range:h,unitId:d,subUnitId:u},a||new Array(_).map(()=>({})),{pasteType:o});B&&(E.push(...B.redos),w.push(...B.undos));const P=(j=A.onPasteCells)==null?void 0:j.call(A,M,{range:h,unitId:d,subUnitId:u},c,T);P&&(E.push(...P.redos),w.push(...P.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(A=>this._commandService.executeCommand(A.id,A.params));return x&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:w,redoMutations:E}),x}_getSetSelectionOperation(t,n,o,r){var f;const s=(f=this._currentUniverService.getUniverSheetInstance(t))==null?void 0:f.getSheetBySheetId(n);if(!s)return null;const{startRow:a,startColumn:c}=o,d={startRow:a,endRow:a,startColumn:c,endColumn:c},u=S.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,g=(h==null?void 0:h.colSpan)||1;if(m>1||g>1){const v={startRow:a,endRow:a+m-1,startColumn:c,endColumn:c+g-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:t,subUnitId:n,pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:S.SetSelectionsOperation.id,params:_}}_getPastingTarget(){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:t.getUnitId(),subUnitId:n.getSheetId(),selection:o}}_transformPastedData(t,n,o,r){const{startRow:s,startColumn:a,endRow:c,endColumn:d}=r,u=c-s+1,h=d-a+1,f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(w=>l.Rectangle.intersects({startRow:s,startColumn:a,endRow:c,endColumn:d},w)),v=f[0];let R=0,M=0,T=0,E=0;if(v&&(R=v.startRow,M=v.startColumn,T=v.endRow,E=v.endColumn),u%t===0&&h%n===0)if(f.length>0&&(u!==t||h!==n))if(R===s&&M===a&&T===c&&E===d)if(ma(o))for(let y=0;y<u;y++)for(let O=0;O<h;O++){const x=o.getValue(y%t,O%n);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%t,y%n);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%t,y%n);O&&o.setValue(w,y,O)}else if(f.length>0)if(this._topLeftCellsMatch(t,n,r))r.endRow=s+t-1,r.endColumn=a+n-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+t-1,r.endColumn=a+n-1;return r}_topLeftCellsMatch(t,n,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:a,startColumn:c,endRow:d,endColumn:u}=o,h=ua(a+t-1,c,c+t-1,s),m=ha(c+n-1,a,a+t-1,s);return!h&&!m}};exports.SheetClipboardService=aa([Xe(0,l.ILogService),Xe(1,l.IUniverInstanceService),Xe(2,N.Inject(S.SelectionManagerService)),Xe(3,I.IClipboardInterfaceService),Xe(4,l.IUndoRedoService),Xe(5,l.ICommandService),Xe(6,qt),Xe(7,N.Inject(exports.SheetSkeletonManagerService))],exports.SheetClipboardService);function la(i){let e="";return i.forRow((t,n)=>{const o=[];n.forEach(r=>{const s=i.getValue(t,r);if(s){const a=ca(s);o.push(a)}}),e+=o.join(" "),t!==i.getLength()-1&&(e+=`
9
- `)}),e}function ca(i){const e=i.v;return da((e==null?void 0:e.toString())||"")}const da=i=>i.replace(/&/g,"&amp;").replace(/\uFEFF/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function ua(i,e,t,n){return n.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&e<=o.startColumn&&o.startColumn<=t)}function ha(i,e,t,n){return n.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&e<=o.startRow&&o.startRow<=t)}function ma(i){let e=0;return i.forValue((t,n,o)=>{if(o&&e++,e>1)return!1}),e>1}function po(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const Hi=998,ir={id:I.CopyCommand.id,name:"sheet.command.copy",type:l.CommandType.COMMAND,multi:!0,priority:Hi,preconditions:xi,handler:async i=>i.get(Mt).copy()},ga={id:I.CutCommand.id,name:"sheet.command.cut",type:l.CommandType.COMMAND,multi:!0,priority:Hi,preconditions:xi,handler:async i=>i.get(Mt).cut()},bt={id:I.PasteCommand.id,type:l.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:Hi,preconditions:xi,handler:async(i,e)=>{const t=i.get(l.ILogService);if(t.debug("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){t.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(Mt);return r.length!==0?s.paste(r[0],e==null?void 0:e.value):!1}return!1}},or={id:"sheet.command.paste-value",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(bt.id,{value:fe.SPECIAL_PASTE_VALUE})},rr={id:"sheet.command.paste-format",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(bt.id,{value:fe.SPECIAL_PASTE_FORMAT})},sr={id:"sheet.command.paste-col-width",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(bt.id,{value:fe.SPECIAL_PASTE_COL_WIDTH})},ar={id:"sheet.command.paste-besides-border",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(bt.id,{value:fe.SPECIAL_PASTE_BESIDES_BORDER})};var _a=Object.defineProperty,Sa=Object.getOwnPropertyDescriptor,fa=(i,e,t,n)=>{for(var o=n>1?void 0:n?Sa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&_a(e,t,o),o},vo=(i,e)=>(t,n)=>e(t,n,i);let Xt=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 t=this._shortcutParam.indexOf(e);this._shortcutParam.splice(t,1)}return this._shortcutParam.push(i),e}remove(i){if(i==null)return;const e=this._getCurrentBySearch(i);if(e==null)return;const t=this._shortcutParam.indexOf(e);return this._shortcutParam.splice(t,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(t=>t.unitId===i.unitId&&t.sheetId===i.sheetId&&t.keycode===i.keycode)}};Xt=fa([vo(0,l.IUniverInstanceService),vo(1,N.Inject(l.LocaleService))],Xt);function Ke(i,e,t,n,o=!0,r=1,s=!0){let a={...i};n==null&&(n={startRow:0,endRow:t.getRowCount()-1,startColumn:0,endColumn:t.getColumnCount()-1});let c;switch(e){case l.Direction.UP:for(c=i.startRow-r;c>-1&&!t.getRowVisible(c);)c-=1;c>=n.startRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.endRow,a.endRow=n.endRow,o&&(a=Ke(a,l.Direction.LEFT,t,n,!1)));break;case l.Direction.DOWN:for(c=i.endRow+r;c<t.getRowCount()&&!t.getRowVisible(c);)c+=1;c<=n.endRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.startRow,a.endRow=n.startRow,o&&(a=Ke(a,l.Direction.RIGHT,t,n,!1)));break;case l.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!t.getColVisible(c);)c-=1;c>=n.startColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.endColumn,a.endColumn=n.endColumn,o&&(a=Ke(a,l.Direction.UP,t,n,!1)));break;case l.Direction.RIGHT:for(c=i.endColumn+r;c<t.getColumnCount()&&!t.getColVisible(c);)c+=1;c<=n.endColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.startColumn,a.endColumn=n.startColumn,o&&(a=Ke(a,l.Direction.DOWN,t,n,!1)));break}return a}function Li(i,e,t){const n={...i},{startRow:o,startColumn:r,endRow:s,endColumn:a}=Zt(i,e,t);let c=Lt(t,o,r,s,a).hasValue,d=!0,u=!0;for(;u;){if(l.Direction.UP===e){let h=n.startRow-1;for(;h>-1&&!t.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=Lt(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let _=h;g.forValue(f=>{_=Math.min(f,_)}),n.startRow=_}else n.startRow=h;if(n.endRow=n.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.DOWN===e){let h=n.endRow+1;for(;h<t.getRowCount()&&!t.getRowVisible(h);)h+=1;if(h===t.getRowCount()){u=!1;break}const{hasValue:m,matrix:g}=Lt(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let _=h;g.forValue((f,v,R)=>{_=Math.max(f+(R.rowSpan||1)-1,_)}),n.endRow=_}else n.endRow=h;if(n.startRow=n.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.LEFT===e){let h=n.startColumn-1;for(;h>-1&&!t.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=Lt(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let _=h;g.forValue((f,v)=>{_=Math.min(v,_)}),n.startColumn=_}else n.startColumn=h;if(n.endColumn=n.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.RIGHT===e){let h=n.endColumn+1;for(;h<t.getColumnCount()&&!t.getColVisible(h);)h+=1;if(h===t.getColumnCount()){u=!1;break}const{hasValue:m,matrix:g}=Lt(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let _=h;g.forValue((f,v,R)=>{_=Math.max(v+(R.colSpan||1)-1,_)}),n.endColumn=_}else n.endColumn=h;if(n.startColumn=n.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return S.alignToMergedCellsBorders(n,t,!0)}function lr(i,e,t){return Ke(i,e,t,void 0,!1,1,!1)}function pa(i,e,t){const n=Li(i,e,t);return S.alignToMergedCellsBorders(l.Rectangle.union(n,i),t,!0)}function va(i,e,t){const n=lr(i,e,t),o={startRow:Math.min(i.startRow,n.startRow),startColumn:Math.min(i.startColumn,n.startColumn),endRow:Math.max(i.endRow,n.endRow),endColumn:Math.max(i.endColumn,n.endColumn)};return S.alignToMergedCellsBorders(l.Rectangle.union(i,o),t)}function Ca(i,e,t,n){const o=l.getReverseDirection(t),r=Li(Zt(i,o,n),t,n);return t===l.Direction.UP&&r.startRow<=i.startRow?S.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===l.Direction.DOWN&&r.endRow>=i.endRow?S.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===l.Direction.LEFT&&r.startColumn<=i.startColumn?S.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):t===l.Direction.RIGHT&&r.endColumn>=i.endColumn?S.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):l.Rectangle.union(l.Rectangle.clone(e),r)}function Ia(i,e,t){const n=l.getReverseDirection(e),o=Zt(i,n,t),r=Zt(i,e,t),s=lr(o,e,t);return S.alignToMergedCellsBorders(l.Rectangle.union(r,s),t,!1)}function Ra(i,e,t){const{left:n,right:o,up:r,down:s}=e,a=t.getMaxRows(),c=t.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,_,f)=>{f.v&&(u.startRow=Math.min(g,u.startRow),u.startColumn=Math.min(_,u.startColumn),u.endColumn=Math.max(_,u.endColumn),d=!0)})}if(s&&u.endRow!==a-1){const h=u.endRow+1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,_,f)=>{f.v&&(u.endRow=Math.max(g+(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(n&&u.startColumn!==0){const h=u.startColumn-1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,_,f)=>{f.v&&(u.startColumn=Math.min(_,u.startColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,_,f)=>{f.v&&(u.endColumn=Math.max(_+(f.colSpan!==void 0?f.colSpan-1:0),u.endColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}}return u}function Co(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL}}function Zt(i,e,t){let n;switch(e){case l.Direction.UP:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.DOWN:n={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.LEFT:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.RIGHT:n={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return S.alignToMergedCellsBorders(n,t,!1)}function Lt(i,e,t,n,o){let r=!1;const s=i.getMatrixWithMergedCells(e,t,n,o).forValue((a,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function Ri(i,e,t){const n=l.Rectangle.clone(i);if(e==null)return n;switch(t){case l.Direction.UP:case l.Direction.DOWN:n.startColumn=n.endColumn=e.actualColumn;break;case l.Direction.LEFT:case l.Direction.RIGHT:n.startRow=n.endRow=e.actualRow;break}return n}function Ma(i,e,t){const{primary:n,range:o}=i,r=l.Rectangle.clone(o);switch(e){case l.Direction.UP:case l.Direction.DOWN:r.startRow=n.startRow,r.endRow=n.endRow;break;case l.Direction.LEFT:case l.Direction.RIGHT:r.startColumn=n.startColumn,r.endColumn=n.endColumn;break}const s=Zt(r,e,t);switch(e){case l.Direction.DOWN:return o.startRow<s.startRow;case l.Direction.UP:return o.endRow>s.endRow;case l.Direction.LEFT:return s.endColumn<o.endColumn;case l.Direction.RIGHT:return s.startColumn>o.startColumn}}function cr(i,e){let t=i[0].startRow,n=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:a}=r;t=Math.min(t,s),n=Math.max(n,a)});const o=new Array(n-t+1).fill(!1);return e.forEach(r=>{const{startRow:s,endRow:a}=r;for(let c=Math.max(s,t);c<=Math.min(a,n);c++)o[c-t]=!0}),i.every(r=>{const{startRow:s,endRow:a}=r;for(let c=s;c<=a;c++)if(!o[c-t])return!1;return!0})}function dr(i,e){let t=i[0].startColumn,n=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:a}=r;t=Math.min(t,s),n=Math.max(n,a)});const o=new Array(n-t+1).fill(!1);return e.forEach(r=>{const{startColumn:s,endColumn:a}=r;for(let c=Math.max(s,t);c<=Math.min(a,n);c++)o[c-t]=!0}),i.every(r=>{const{startColumn:s,endColumn:a}=r;for(let c=s;c<=a;c++)if(!o[c-t])return!1;return!0})}var Le=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(Le||{});const we={id:"sheet.command.move-selection",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(S.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=e,{range:a,primary:c}=o,d=Ri(a,c,r),u=s===1?Li(d,r,n):Ke(d,r,n),h=S.getCellAtRowCol(u.startRow,u.startColumn,n);return l.Rectangle.equals(h,d)?!1:(i.get(Xt).remove({unitId:t.getUnitId(),sheetId:n.getSheetId(),keycode:I.KeyCode.TAB}),i.get(l.ICommandService).executeCommand(S.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:l.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}}]}))}},lt={id:"sheet.command.move-selection-enter-tab",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(S.SelectionManagerService).getLast(),r=t.getUnitId(),s=n.getSheetId();if(!o)return!1;const{direction:a,keycode:c}=e,{range:d,primary:u}=o;let h=Ri(d,u,a);const m=i.get(Xt),g=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});let _;const{startRow:f,endRow:v,startColumn:R,endColumn:M}=d;if(l.Rectangle.equals(d,u)){if(c===I.KeyCode.TAB)g==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:I.KeyCode.TAB,selection:o});else{const w=g==null?void 0:g.selection;if(w!=null){const{range:y,primary:O}=w;h=Ri(y,O,a)}m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB})}const T=Ke(h,a,n),E=S.getCellAtRowCol(T.startRow,T.startColumn,n);if(l.Rectangle.equals(E,h))return!1;_={range:l.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=l.Tools.deepClone(u),E=Ke({startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn},a,n,{startRow:f,endRow:v,startColumn:R,endColumn:M}),w=S.getCellAtRowCol(E.startRow,E.startColumn,n);_={range:l.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(l.ICommandService).executeCommand(S.SetSelectionsOperation.id,{unitId:r,subUnitId:s,pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[_]})}},Ue={id:"sheet.command.expand-selection",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(S.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:a,direction:c}=e,u=Ma(o,c,n)?a===1?Ca(r,{...l.Rectangle.clone(s),rangeType:l.RANGE_TYPE.NORMAL},c,n):Ia(r,c,n):a===1?pa(r,c,n):va(r,c,n);return l.Rectangle.equals(u,r)?!1:i.get(l.ICommandService).executeCommand(S.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let Ae=[],si="";const ur={id:"sheet.command.select-all",type:l.CommandType.COMMAND,onDispose(){Ae=[],si=""},handler:async(i,e={expandToGapFirst:!0,loop:!1})=>{const t=i.get(S.SelectionManagerService).getLast(),n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet();if(!t||!o)return!1;const r=`${n.getUnitId()}|${o.getSheetId()}`;r!==si&&(Ae=[],si=r);const s=o.getMaxRows(),a=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=e,{range:u,primary:h}=t,m=u.endColumn===a-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;Ae.some(_=>l.Rectangle.equals(_,u))||(Ae=[],Ae.push(u));let g;if(m)if(d){if(Ae.findIndex(f=>l.Rectangle.equals(f,u))!==Ae.length-1)return!1;g=Ae[0]}else return!1;else c?(g=Ra(u,{left:!0,right:!0,up:!0,down:!0},o),l.Rectangle.equals(g,u)&&(g=Co(o))):g=Co(o);return Ae.some(_=>l.Rectangle.equals(_,g))||Ae.push(g),i.get(l.ICommandService).executeCommand(S.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:o.getSheetId(),pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:g,primary:h}]})}};var ba=Object.defineProperty,wa=Object.getOwnPropertyDescriptor,Ta=(i,e,t,n)=>{for(var o=n>1?void 0:n?wa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ba(e,t,o),o},an=(i,e)=>(t,n)=>e(t,n,i);const Ea=l.createInterceptorKey("BEFORE_CELL_EDIT"),ya=l.createInterceptorKey("AFTER_CELL_EDIT");exports.EditorBridgeService=class extends l.Disposable{constructor(t,n,o,r){super();C(this,"_editorUnitId",l.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 D.BehaviorSubject(null));C(this,"currentEditCellState$",this._currentEditCellState$.asObservable());C(this,"_visible$",new D.BehaviorSubject(this._visible));C(this,"visible$",this._visible$.asObservable());C(this,"_afterVisible$",new D.BehaviorSubject(this._visible));C(this,"afterVisible$",this._afterVisible$.asObservable());C(this,"interceptor",new l.InterceptorManager({BEFORE_CELL_EDIT:Ea,AFTER_CELL_EDIT:ya}));this._sheetSkeletonManagerService=t,this._selectionRenderService=n,this._themeService=o,this._currentUniverService=r,this.disposeWithMe(l.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:s=>s}))),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:s=>s})))}refreshEditCellState(){const t=this.getLatestEditCellState();this._currentEditCellState=t,this._currentEditCellState$.next(t)}setEditCell(t){this._currentEditCell=t;const n=this.getLatestEditCellState();this._currentEditCellState=n,this._currentEditCellState$.next(n)}getEditCellState(){return this._currentEditCellState}getLatestEditCellState(){var k,j;const t=this._currentEditCell;if(t==null)return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null)return;const{skeleton:o}=n,{primary:r,unitId:s,sheetId:a,scene:c,engine:d}=t,{startRow:u,startColumn:h}=r,m=this._selectionRenderService.convertCellRangeToInfo(r);if(m==null)return;const g=l.makeCellToSelection(m);if(g==null)return;const _=b.getCanvasOffsetByEngine(d);let{startX:f,startY:v,endX:R,endY:M}=g;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),R=b.fixLineWidthByScale(o.convertTransformToOffsetX(R,T,O),w),M=b.fixLineWidthByScale(o.convertTransformToOffsetY(M,E,O),y);const x=this._currentUniverService.getCurrentUniverSheetInstance(),A=x.getActiveSheet(),B={workbook:x,worksheet:A,unitId:x.getUnitId(),subUnitId:A.getSheetId(),row:u,col:h},P=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(A.getCell(u,h),B);let F=P&&o.getCellDocumentModelWithFormula(P);if(!F||F.documentModel==null){const $=o.getBlankCellDocumentModel(P);if(F!=null){const{verticalAlign:G,horizontalAlign:W,wrapStrategy:J,textRotation:re,fill:Y}=F,{centerAngle:U,vertexAngle:L}=b.convertTextRotation(re);$.documentModel.documentStyle.renderConfig={verticalAlign:G,horizontalAlign:W,wrapStrategy:J,background:{rgb:Y},centerAngle:U,vertexAngle:L}}F=$}if((k=F.documentModel)==null||k.setZoomRatio(Math.max(T,E)),(P==null?void 0:P.isInArrayFormulaRange)===!0){const $=(j=F.documentModel)==null?void 0:j.getBody();$&&($.textRuns=[{st:0,ed:$.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:f,startY:v,endX:R,endY:M},scaleX:T,scaleY:E,canvasOffset:_,row:u,column:h,unitId:s,sheetId:a,documentLayoutObject:F,editorUnitId:this._editorUnitId,isInArrayFormulaRange:P==null?void 0:P.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(t){this._visible=t,t.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(t){this._editorIsDirty=t}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=Ta([an(0,N.Inject(exports.SheetSkeletonManagerService)),an(1,_e),an(2,N.Inject(l.ThemeService)),an(3,l.IUniverInstanceService)],exports.EditorBridgeService);const Te=N.createIdentifier("univer.sheet-editor-bridge.service"),He={id:"sheet.operation.set-cell-edit-visible",type:l.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(Te);return e==null?!1:(t.changeVisible(e),!0)}},Gt={id:"sheet.operation.set-cell-edit-visible-arrow",type:l.CommandType.OPERATION,handler:()=>!0};class Je{constructor(){C(this,"_scrollInfo",new Map);C(this,"_currentScroll",null);C(this,"_scrollInfo$",new D.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,t=!0){const{unitId:n,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:a,offsetY:c}=e;this._scrollInfo.has(n)||this._scrollInfo.set(n,new Map),this._scrollInfo.get(n).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:a,offsetY:c}),t===!0&&this._refresh({unitId:n,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:t,sheetId:n}=e;return(o=this._scrollInfo.get(t))==null?void 0:o.get(n)}_refresh(e){this._scrollInfo$.next(this._getCurrentScroll(e))}}const wt={id:"sheet.operation.set-scroll",type:l.CommandType.OPERATION,handler:(i,e)=>{if(e==null)return!1;const t=i.get(Je),r=i.get(l.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.sheetId),{xSplit:s,ySplit:a}=r.getConfig().freeze;return t.addOrReplaceByParam({...e,sheetViewStartRow:e.sheetViewStartRow-a,sheetViewStartColumn:e.sheetViewStartColumn-s}),!0}},Xn={id:"sheet.operation.set-editor-resize",type:l.CommandType.OPERATION,handler:(i,e)=>!0},ze={id:"sheet.operation.set-zoom-ratio",type:l.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(l.IUniverInstanceService).getUniverSheetInstance(e.unitId),n=t==null?void 0:t.getSheetBySheetId(e.subUnitId);return n==null?!1:(n.getConfig().zoomRatio=e.zoomRatio,!0)}};var hr={exports:{}},Zn={};/**
1
+ "use strict";var es=Object.defineProperty;var ts=(i,t,e)=>t in i?es(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var I=(i,t,e)=>(ts(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),_=require("@univerjs/sheets"),v=require("@univerjs/ui"),N=require("@wendellhu/redi"),H=require("rxjs"),b=require("@univerjs/engine-render"),P=require("react"),ge=require("@univerjs/design"),K=require("@wendellhu/redi/react-bindings"),J=require("@univerjs/docs"),ns=require("rxjs/operators"),ee=require("@univerjs/engine-formula"),zt=require("clsx"),is=require("@univerjs/engine-numfmt"),Bo={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},Fo={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},Wo={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},os={layout:{sheetContainerConfig:Wo,rightMenuConfig:Bo,toolbarConfig:Fo}},jo="SheetUI";function zn(i,t){if(i==null)return;const e=t.getRenderById(i);if(e==null)return;const{mainComponent:n,scene:o,engine:r}=e;return{document:n,scene:o,engine:r}}const fi={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},kn=["零","一","二","三","四","五","六","七","八","九"],to=["","万","亿","万亿","亿亿"],rs=["","十","百","千"],$o={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function ze(i){if(!i)return 0;let t=0,e=0,n=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const a=fi[r[s]];if(typeof a<"u")n=a,s===r.length-1&&(e+=n);else{const c=$o[r[s]],d=c.value;o=c.secUnit,o?(e=(e+n)*d,t+=e,e=0):e+=n*d,n=0}}return t+e}function ss(i){let t="",e="",n=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,e=kn[r]+e):(o=!1,t=kn[r],t+=rs[n],e=t+e),n++,i=Math.floor(i/10)}return e}function as(i){let t=0,e="",n="",o=!1;if(i===0)return kn[0];for(;i>0;){const r=i%1e4;o&&(n=kn[0]+n),e=ss(r),e+=r!==0?to[t]:to[0],n=e+n,o=r<1e3&&r>0,i=Math.floor(i/1e4),t++}return n}function ls(i){if(!i)return!1;let t=!0;if(i)if(i.length===1)i==="日"||i in fi?t=!0:t=!1;else{const e=i.split("");for(let n=0;n<e.length;n++)if(!(e[n]in fi||e[n]in $o)){t=!1;break}}return t}function rn(i){if(!i)return{isExtendNumber:!1};const t=/0|([1-9]+[0-9]*)/g,e=t.test(i);if(e){const n=i.match(t);if(n&&n.length>0){const o=n[n.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),a=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:a}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function cs(i){let t;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?t=!0:t=!1,t}function ds(i){let t;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?t=!0:t=!1,t}function us(i,t){let e=0;for(let n=0;n<i.length&&i[n]<t;n++)e++;return e}function Kt(i){let t=!0;const e=i[1]-i[0];for(let n=1;n<i.length;n++)if(i[n]-i[n-1]!==e){t=!1;break}return t}function hs(i,t,e){const n=[],o=Math.floor(t/i),r=t%i;let s=0;if(o>0){for(let a=0;a<o;a++)for(let c=0;c<e.length;c++)n[e[c]+a*i]=s,s++;for(let a=0;a<e.length&&e[a]<r;a++)n[e[a]+i*o]=s,s++}else for(let a=0;a<e.length&&e[a]<r;a++)n[e[a]]=s,s++;return n}function ct(i,t){const e=[];for(let n=1;n<=t;n++){const o=(n-1)%i.length,r=l.Tools.deepClone(i[o]);e.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return e}function ms(i,t){var n;const e=[];for(let o=1;o<=t;o++){const r=(o-1)%i.length,s={s:(n=i[r])==null?void 0:n.s};e.push(s)}return e}function gs(i){let t=!0;const e=i[1]/i[0];for(let n=1;n<i.length;n++)if(i[n]/i[n-1]!==e){t=!1;break}return t}function Ss(i){const t=[];for(let e=1;e<=i;e++)t.push(e);return t}function no(i,t,e){var r,s,a,c;const n=[],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<=t;d++){const u=(d-1)%i.length,h=l.Tools.deepClone(i[u]),m=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((a=i[1])==null?void 0:a.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(h.v=m,n.push(h))}else{const d=Ss(i.length);for(let u=1;u<=t;u++){const h=(u-1)%i.length,m=l.Tools.deepClone(i[h]),g=e===l.Direction.DOWN||e===l.Direction.RIGHT,S=_s(i.length+u,o,d,g);m&&(m.v=S,n.push(m))}}return n}function _s(i,t,e,n=!0){function o(h){let m=0;for(let g=0;g<h.length;g++)m+=h[g];return m/h.length}const r=o(e),s=o(t);let a=0,c=0;for(let h=0;h<e.length;h++)a+=(e[h]-r)*(t[h]-s),c+=(e[h]-r)*(e[h]-r);let d;c===0?d=n?1:-1:d=a/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function io(i,t,e){var r;const n=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=t;s++){const a=(s-1)%i.length,c=l.Tools.deepClone(i[a]),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)+e*s);if(!d||!h)continue;const g=d.lastIndexOf(h),S=d.substr(0,g)+m.toString()+d.substr(g+h.length);c&&(c.v=S,n.push(c))}return n}function vt(i,t,e,n=0){var a,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(n>=o.length)return[];const r=o[n],s=[];for(let d=1;d<=t;d++){const u=(d-1)%i.length,h=l.Tools.deepClone(i[u]);let m=0;if(((a=i[i.length-1])==null?void 0:a.v)===r[0])m=7+e*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=ze(f)+e*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const g=m%7;h&&(h.v=r[g],s.push(h))}return s}function oo(i,t,e){var o;const n=[];for(let r=1;r<=t;r++){const s=(r-1)%i.length,a=l.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=ze(c)+e*r;let u;d<=0?u="零":u=as(d),a&&(a.v=u,n.push(a))}return n}const $t={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 fs(i){let t=!1;return Object.keys($t).forEach(e=>{$t[e].includes(i)&&(t=!0)}),t}function ii(i){let t="";const e=[];return Object.keys($t).forEach(n=>{$t[n].includes(i)&&(t=n,e.push(...$t[n]))}),{name:t,series:e}}function ro(i,t,e,n){var s;const o=n.length,r=[];for(let a=1;a<=t;a++){const c=(a-1)%i.length,d=l.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=n.indexOf(u)+e*a;h<0&&(h+=Math.abs(e)*o);const m=h%o;d&&(d.v=n[m],r.push(d))}return r}function ps(i,t){const e=[];let n;if(t.startRow<i.startRow)n=l.Direction.UP;else if(t.endRow>i.endRow)n=l.Direction.DOWN;else if(t.startColumn<i.startColumn)n=l.Direction.LEFT;else if(t.endColumn>i.endColumn)n=l.Direction.RIGHT;else return[];if(n===l.Direction.DOWN||n===l.Direction.UP){const o=i.endRow-i.startRow+1,r=t.endRow-t.startRow+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&e.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:a-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&e.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-a,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(n===l.Direction.RIGHT||n===l.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=t.endColumn-t.startColumn+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});a>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:a-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});a>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-a,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return e}function zo(i){const t=new l.ObjectMatrix;return i.forEach(e=>{const{startRow:n,startColumn:o,endRow:r,endColumn:s}=e;for(let a=n;a<=r;a++)for(let c=o;c<=s;c++)t.setValue(a,c,{v:null,p:null,f:null,si:null})}),t.getData()}const Yo={type:l.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,t)=>!0},un={id:"sheet.command.auto-clear-content",type:l.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(l.IUniverInstanceService),n=i.get(l.ICommandService),o=i.get(l.IUndoRedoService),r=e.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=t,h={subUnitId:c,unitId:s,cellValue:zo([d])},m=_.SetRangeValuesUndoMutationFactory(i,h);return n.executeCommand(_.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),n.syncExecuteCommand(_.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:_.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:_.SetRangeValuesMutation.id,params:h}],undo(){return n.syncExecuteCommand(_.SetRangeValuesMutation.id,m)},redo(){return n.syncExecuteCommand(_.SetRangeValuesMutation.id,h)}}),!0):!1}};function Oi(i){return i.getContextValue(l.FOCUSING_SHEET)}function te(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)}function Xo(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(l.EDITOR_ACTIVATED)}function Cs(i){return i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(l.EDITOR_ACTIVATED)}function Zo(i){return i.getContextValue(l.FOCUSING_FORMULA_EDITOR)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function vs(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.EDITOR_ACTIVATED)&&i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Vn(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)}var Se=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(Se||{}),B=(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))(B||{});const so=0,Je=2,Is=3,pi=[10,400],ao=1001;var Rs=Object.defineProperty,Ms=Object.getOwnPropertyDescriptor,bs=(i,t,e,n)=>{for(var o=n>1?void 0:n?Ms(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Rs(t,e,o),o},lo=(i,t)=>(e,n)=>t(e,n,i);exports.SheetSkeletonManagerService=class{constructor(t,e){I(this,"_currentSkeleton",{unitId:"",sheetId:""});I(this,"_sheetSkeletonParam",[]);I(this,"_currentSkeleton$",new H.BehaviorSubject(null));I(this,"currentSkeleton$",this._currentSkeleton$.asObservable());I(this,"_currentSkeletonBefore$",new H.BehaviorSubject(null));I(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=t,this._localeService=e}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(t){this._setCurrent(t)}_compareSearch(t,e){return t==null||e==null?!1:t.commandId===e.commandId&&t.sheetId===e.sheetId&&t.unitId===e.unitId}_setCurrent(t){const e=this._getCurrentBySearch(t);if(e!=null)this._reCalculate(e);else{const{unitId:o,sheetId:r}=t,s=this._currentUniverService.getUniverSheetInstance(t.unitId),a=s==null?void 0:s.getSheetBySheetId(t.sheetId);if(a==null||s==null)return;const c=this._buildSkeleton(a,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=t;const n=this.getCurrent();this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n)}reCalculate(){const t=this.getCurrent();t!=null&&this._reCalculate(t)}_reCalculate(t){t.dirty&&(t.skeleton.makeDirty(!0),t.dirty=!1),t.skeleton.calculate()}makeDirtyCurrent(t=!0){this.makeDirty(this._currentSkeleton,t)}makeDirty(t,e=!0){const n=this._getCurrentBySearch(t);n!=null&&(n.dirty=e)}getOrCreateSkeleton(t){const e=this._getCurrentBySearch(t);if(e)return e.skeleton;const n=this._currentUniverService.getUniverSheetInstance(t.unitId),o=n==null?void 0:n.getSheetBySheetId(t.sheetId);if(!o||!n)return;const r=this._buildSkeleton(o,n);return this._sheetSkeletonParam.push({unitId:t.unitId,sheetId:t.sheetId,skeleton:r,dirty:!1}),r}_getCurrentBySearch(t){const e=this._sheetSkeletonParam.find(n=>n.unitId===t.unitId&&n.sheetId===t.sheetId);return e!=null&&(e.commandId=t.commandId),e}_buildSkeleton(t,e){const n=t.getConfig();return b.SpreadsheetSkeleton.create(t,n,t.getCellMatrix(),e.getStyles(),this._localeService)}};exports.SheetSkeletonManagerService=bs([lo(0,l.IUniverInstanceService),lo(1,N.Inject(l.LocaleService))],exports.SheetSkeletonManagerService);class ws{constructor(){I(this,"_startColumn",-1);I(this,"_startRow",-1);I(this,"_endColumn",-1);I(this,"_endRow",-1);I(this,"_startX",0);I(this,"_startY",0);I(this,"_endX",0);I(this,"_endY",0);I(this,"_currentCell");I(this,"_rangeType",l.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(t){const{startColumn:e,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=t;return e===s&&n===a&&o===c&&r===d}isInclude(t){const{startColumn:e,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=t;return!(c<e||s>o||a>r||d<n)}highlightToSelection(){return l.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(t,e){const{startColumn:n,startRow:o,endColumn:r,endRow:s,startX:a,startY:c,endX:d,endY:u,rangeType:h}=t;this._startColumn=n,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=a,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(e)}setCurrentCell(t){t&&(this._currentCell=t)}clearCurrentCell(){this._currentCell=null}}const co=.3;class Bn extends l.Disposable{constructor(e,n,o=!0,r){super();I(this,"_leftControl");I(this,"_rightControl");I(this,"_topControl");I(this,"_bottomControl");I(this,"_backgroundControlTop");I(this,"_backgroundControlBottom");I(this,"_backgroundControlMiddleLeft");I(this,"_backgroundControlMiddleRight");I(this,"_fillControl");I(this,"_selectionShape");I(this,"_rowHeaderBackground");I(this,"_rowHeaderBorder");I(this,"_rowHeaderGroup");I(this,"_rowHeaderHighlight");I(this,"_columnHeaderBackground");I(this,"_columnHeaderBorder");I(this,"_columnHeaderGroup");I(this,"_columnHeaderHighlight");I(this,"_topLeftWidget");I(this,"_topCenterWidget");I(this,"_topRightWidget");I(this,"_middleLeftWidget");I(this,"_middleRightWidget");I(this,"_bottomLeftWidget");I(this,"_bottomCenterWidget");I(this,"_bottomRightWidget");I(this,"_dashRect");I(this,"_selectionModel");I(this,"_selectionStyle");I(this,"_rowHeaderWidth",0);I(this,"_columnHeaderHeight",0);I(this,"_widgetRects",[]);I(this,"_dispose$",new H.BehaviorSubject(this));I(this,"dispose$",this._dispose$.asObservable());I(this,"selectionMoving$",new H.Subject);I(this,"selectionMoved$",new H.Subject);I(this,"selectionScaling$",new H.Subject);I(this,"selectionScaled$",new H.Subject);I(this,"selectionFilling$",new H.Subject);I(this,"_selectionFilled$",new H.Subject);I(this,"selectionFilled$",this._selectionFilled$.asObservable());I(this,"_defaultStyle");I(this,"_currentStyle");I(this,"_isHelperSelection",!0);I(this,"_antLineOffset",0);I(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=n,this._isHeaderHighlight=o,this._themeService=r,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,o=0,r,s){this._selectionModel.setValue(e,s),r==null&&(r=this._selectionStyle),this._updateControl(r,n,o)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,n,o,r,s,a,c,d,u,h,m,g,S,f,C,R,M,w,E,T,O,y,x,A,k;(e=this._leftControl)==null||e.dispose(),(n=this._rightControl)==null||n.dispose(),(o=this._topControl)==null||o.dispose(),(r=this._bottomControl)==null||r.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(a=this._backgroundControlMiddleLeft)==null||a.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),(u=this._fillControl)==null||u.dispose(),(h=this._selectionShape)==null||h.dispose(),(m=this._rowHeaderBackground)==null||m.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(C=this._columnHeaderBackground)==null||C.dispose(),(R=this._columnHeaderBorder)==null||R.dispose(),(M=this._columnHeaderGroup)==null||M.dispose(),(w=this._topLeftWidget)==null||w.dispose(),(E=this._topCenterWidget)==null||E.dispose(),(T=this._topRightWidget)==null||T.dispose(),(O=this._middleLeftWidget)==null||O.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(x=this._bottomLeftWidget)==null||x.dispose(),(A=this._bottomCenterWidget)==null||A.dispose(),(k=this._bottomRightWidget)==null||k.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let n;if(e.isMerged){const o=e.mergeInfo;n={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn,startX:o.startX,endX:o.endX,startY:o.startY,endY:o.endY}}else{const{actualRow:o,actualColumn:r,startX:s,endX:a,startY:c,endY:d}=e;n={startRow:o,endRow:o,startColumn:r,endColumn:r,startX:s,endX:a,startY:c,endY:d}}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,o){const{startX:r,startY:s,endX:a,endY:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d),this._currentStyle=e;const{stroke:u=d.stroke,widgets:h=d.widgets,hasAutoFill:m=d.hasAutoFill,AutofillStroke:g=d.AutofillStroke,strokeDash:S,isAnimationDash:f}=e;let{strokeWidth:C=d.strokeWidth,AutofillSize:R=d.AutofillSize,AutofillStrokeWidth:M=d.AutofillStrokeWidth}=e;const w=this._getScale(),E=(C+_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/w;C/=w,R/=w,M/=w<1?1:w;const T=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/w,O=b.FIX_ONE_PIXEL_BLUR_OFFSET/w;if(this.leftControl.transformByState({height:c-s,left:-E+O,width:C,strokeWidth:T,top:-T/2+O}),this.leftControl.setProps({fill:u,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:c-s,left:a-r-E+O,width:C,strokeWidth:T,top:-T/2+O}),this.rightControl.setProps({fill:u,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:a-r+C,top:-E+O,left:-E+O,height:C,strokeWidth:T}),this.topControl.setProps({fill:u,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:a-r+C,top:c-s-E+O,height:C,left:-E+O,strokeWidth:T}),this.bottomControl.setProps({fill:u,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),S==null)this.dashRect.hide(),this._stopAntLineAnimation();else{const y=e.strokeWidth*2/w;this.dashRect.transformByState({height:c-s,width:a-r,strokeWidth:y,left:-y/2+O,top:-y/2+O}),this.dashRect.setProps({strokeDashArray:[0,S/w]}),this._stopAntLineAnimation(),f!==!1&&this._startAntLineAnimation(),this.dashRect.show()}m===!0&&!this._hasWidgets(h)?(this.fillControl.setProps({fill:u,stroke:g,strokeScaleEnabled:!1}),this.fillControl.transformByState({width:R-M,height:R-M,left:a-r-R/2+M/2,top:c-s-R/2+M/2,strokeWidth:M}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,n,o),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(r,s),this._selectionStyle=e,this._rowHeaderWidth=n||0,this._columnHeaderHeight=o||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=_.getNormalSelectionStyle(this._themeService),this._selectionModel=new ws;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 o=this.getScene();o.addObject(this._selectionShape,Is),this.disposeWithMe(l.toDisposable(o.onTransformChangeObservable.add(r=>{r.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,o){const{startX:r,startY:s,endX:a,endY:c,rangeType:d}=this._selectionModel,u=this._defaultStyle;e==null&&(e=u);const h=this._getScale(),{stroke:m,hasRowHeader:g,rowHeaderFill:S=u.rowHeaderFill,rowHeaderStroke:f=u.rowHeaderStroke,hasColumnHeader:C,columnHeaderFill:R=u.columnHeaderFill,columnHeaderStroke:M=u.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:w=u.rowHeaderStrokeWidth,columnHeaderStrokeWidth:E=u.columnHeaderStrokeWidth}=e;if(w/=h,E/=h,C===!0){let T=R;this._isHeaderHighlight&&d===l.RANGE_TYPE.COLUMN&&(T=new l.ColorKit(m).setAlpha(co).toString()),this._columnHeaderBackground.setProps({fill:T}),this._columnHeaderBackground.resize(a-r,o),this._columnHeaderBorder.setProps({fill:M}),this._columnHeaderBorder.transformByState({width:a-r,height:E,top:o-E+1/h}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(r,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),g===!0){let T=S;this._isHeaderHighlight&&d===l.RANGE_TYPE.ROW&&(T=new l.ColorKit(m).setAlpha(co).toString()),this._rowHeaderBackground.setProps({fill:T}),this._rowHeaderBackground.resize(n,c-s),this._rowHeaderBorder.setProps({fill:f}),this._rowHeaderBorder.transformByState({width:w,height:c-s,left:n-w+1/h}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,s)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:n,startY:o,endX:r,endY:s}=this._selectionModel,a=this._defaultStyle;e==null&&(e=a);const c=this._getScale(),{fill:d=a.fill}=e;let{strokeWidth:u=a.strokeWidth}=e;u/=c;const h=this._selectionModel.highlightToSelection();if(!h){this._backgroundControlTop.resize(r-n,s-o),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:m,startY:g,endX:S,endY:f}=h,C=u/2,R={left:-C,top:-C,width:r-n+C*2,height:g-o+C};R.height<0&&(R.width=0,R.height=0),this._backgroundControlTop.transformByState(R);const M={left:-C,top:g-o,width:m-n+C,height:f-g};M.width<0&&(M.width=0,M.height=0),this._backgroundControlMiddleLeft.transformByState(M);const w={left:S-n-C,top:g-o,width:r-S+C*2,height:f-g};w.width<0&&(w.width=0,w.height=0),this._backgroundControlMiddleRight.transformByState(w);const E={left:-C,top:f-o,width:r-n+C*2,height:s-f+C};E.height<0&&(E.width=0,E.height=0),this._backgroundControlBottom.transformByState(E),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlMiddleLeft.setProps({fill:d}),this._backgroundControlMiddleRight.setProps({fill:d}),this._backgroundControlBottom.setProps({fill:d})}_updateWidgets(e){const{startX:n,startY:o,endX:r,endY:s}=this._selectionModel,a=this._defaultStyle;e==null&&(e=a);const{stroke:c=a.stroke,widgets:d=a.widgets,widgetStroke:u=a.widgetStroke}=e,h=this._getScale();let{widgetSize:m=a.widgetSize,widgetStrokeWidth:g=a.widgetStrokeWidth}=e;m/=h,g/=h;const S={left:-m/2+g/2,center:(r-n)/2-m/2+g/2,right:r-n-m/2+g/2,top:-m/2,middle:(s-o)/2-m/2,bottom:s-o-m/2+g/2},f=m-g;this._widgetRects.forEach(C=>{C.setProps({fill:c,stroke:u})}),d.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),d.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),d.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),d.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),d.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),d.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),d.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),d.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),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 o of n)if(e[o]===!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 uo="__SpreadsheetHelperSelectionTempRect",Ts=35;class ho{constructor(t,e,n,o,r){I(this,"_startOffsetX",0);I(this,"_startOffsetY",0);I(this,"_relativeSelectionPositionRow",0);I(this,"_relativeSelectionPositionColumn",0);I(this,"_relativeSelectionRowLength",0);I(this,"_relativeSelectionColumnLength",0);I(this,"_moveObserver");I(this,"_upObserver");I(this,"_helperSelection");I(this,"_scrollTimer");I(this,"_activeViewport");I(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});I(this,"_isInMergeState",!1);I(this,"_fillControlColors",[]);this._control=t,this._skeleton=e,this._scene=n,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 t,e;(t=this._scrollTimer)==null||t.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var e;return(e=this._injector.get(exports.SheetSkeletonManagerService).getCurrent())==null?void 0:e.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(t,e){const n=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewPortKey){case B.VIEW_MAIN:return t.endRow>=n.startRow&&t.endColumn>=n.startColumn;case B.VIEW_MAIN_TOP:case B.VIEW_COLUMN_RIGHT:return t.endColumn>=n.startColumn&&t.startRow<n.startRow;case B.VIEW_MAIN_LEFT:case B.VIEW_ROW_BOTTOM:return t.endRow>=n.startRow&&t.startColumn<n.startColumn;case B.VIEW_MAIN_LEFT_TOP:case B.VIEW_COLUMN_LEFT:case B.VIEW_ROW_TOP:case B.VIEW_LEFT_TOP:return t.startRow<n.startRow&&t.startColumn<n.startColumn}}_clearObserverEvent(){this._scene.onPointerMoveObserver.remove(this._moveObserver),this._scene.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_initialControl(){const{leftControl:t,rightControl:e,topControl:n,bottomControl:o}=this._control;[t,e,n,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(t,e){var O;const n=this._scene,o=n.getScrollXYByRelativeCoords(b.Vector2.FromArray([t,e])),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(t,e,r,s,o),{row:c,column:d}=a,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let g=m+this._relativeSelectionRowLength;g>u&&(g=u,g-m<this._relativeSelectionRowLength&&(m=g-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 C=this._skeleton.getNoMergeCellPositionByIndex(m,S),R=this._skeleton.getNoMergeCellPositionByIndex(g,f),M=(C==null?void 0:C.startY)||0,w=(R==null?void 0:R.endY)||0,E=(C==null?void 0:C.startX)||0,T=(R==null?void 0:R.endX)||0;(O=this._helperSelection)==null||O.transformByState({left:E,top:M,width:T-E,height:w-M}),this._targetSelection={startY:M,endY:w,startX:E,endX:T,startRow:m,endRow:g,startColumn:S,endColumn:f},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(t){const{offsetX:e,offsetY:n}=t,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([e,n])),{x:s,y:a}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,a,d,u,c);this._startOffsetX=s,this._startOffsetY=a;const{row:m,column:g}=h,{startRow:S,startColumn:f,endRow:C,endColumn:R}=this._control.model;let M=0,w=0;m<S?M-=1:m>C&&(M+=1),g<f?w-=1:g>R&&(w+=1),this._relativeSelectionPositionRow=S-m+M,this._relativeSelectionPositionColumn=f-g+w,this._relativeSelectionRowLength=C-S,this._relativeSelectionColumnLength=R-f;const E=this._control.selectionStyle,T=this._getScale();this.isHelperSelection&&(this._helperSelection=new b.Rect(uo,{stroke:E.stroke,strokeWidth:E.strokeWidth/T}),o.addObject(this._helperSelection));const O=o.getViewport(B.VIEW_MAIN),y=b.ScrollTimer.create(o);y.startScroll(s,a,O),this._scrollTimer=y,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(x=>{const{offsetX:A,offsetY:k}=x,{x:L,y:F}=o.getRelativeCoord(b.Vector2.FromArray([A,k]));this._controlMoving(L,F),o.setCursor(b.CURSOR_TYPE.MOVE),y.scrolling(L,F,()=>{this._controlMoving(L,F)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var A,k;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableEvent(),(k=this._scrollTimer)==null||k.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:t,topCenterWidget:e,topRightWidget:n,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:a,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];[t,e,n,o,r,s,a,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(t,e,n){const o=this._scene,r=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:a}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(t,e,s,a,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,C=u;n===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(g=d,S=u,f=this._relativeSelectionPositionRow,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.NORTH_RESIZE?(g=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):n===b.CURSOR_TYPE.NORTH_EAST_RESIZE?(g=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,C=u):n===b.CURSOR_TYPE.WEST_RESIZE?(g=this._relativeSelectionPositionRow,S=u,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.EAST_RESIZE?f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:n===b.CURSOR_TYPE.SOUTH_WEST_RESIZE?(g=this._relativeSelectionPositionRow,S=u,f=d,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.SOUTH_RESIZE&&(g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:R,startColumn:M,endRow:w,endColumn:E}=this._swapPositions(g,S,f,C),T=this._skeleton.getNoMergeCellPositionByIndex(R,M),O=this._skeleton.getNoMergeCellPositionByIndex(w,E),y=(T==null?void 0:T.startY)||0,x=(O==null?void 0:O.endY)||0,A=(T==null?void 0:T.startX)||0,k=(O==null?void 0:O.endX)||0;this._targetSelection={startY:y,endY:x,startX:A,endX:k,startRow:g,endRow:f,startColumn:S,endColumn:C},this._control.update(this._targetSelection,h,m,this._control.selectionStyle),this._control.clearHighlight(),this._control.selectionScaling$.next(this._targetSelection)}_widgetEvent(t,e){const{offsetX:n,offsetY:o}=t,r=this._scene,s=r.getRelativeCoord(b.Vector2.FromArray([n,o])),{x:a,y:c}=s;this._startOffsetX=n,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,e===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):e===b.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:e===b.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:e===b.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:e===b.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const g=b.ScrollTimer.create(r);g.startScroll(a,c),this._scrollTimer=g,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(S=>{const{offsetX:f,offsetY:C}=S,{x:R,y:M}=r.getRelativeCoord(b.Vector2.FromArray([f,C]));this._widgetMoving(R,M,e),r.setCursor(e),g.scrolling(R,M,()=>{this._widgetMoving(R,M,e)})}),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:t}=this._control;t.onPointerEnterObserver.add(()=>{t.setCursor(b.CURSOR_TYPE.CROSSHAIR)}),t.onPointerLeaveObserver.add(()=>{t.resetCursor()}),t.onPointerDownObserver.add(this._fillEvent.bind(this))}_fillMoving(t,e){var k,L,F;const n=this._scene,o=n.getScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(t,e,r,s,o),{row:c,column:d}=a,u=n.getRelativeCoord(b.Vector2.FromArray([t,e])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,R=!1,M=!0;if((d<S||d>C)&&c>=g&&c<=f){const V=this._fillRuler(d,S,C,this._relativeSelectionColumnLength,m);S=V.startRowOrColumn,C=V.endRowOrColumn,R=V.isLighten,M=!1}else if((c<g||c>f)&&d>=S&&d<=C){const V=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=V.startRowOrColumn,f=V.endRowOrColumn,R=V.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const V=this._fillRuler(d,S,C,this._relativeSelectionColumnLength,m);S=V.startRowOrColumn,C=V.endRowOrColumn,R=V.isLighten,M=!1}else{const V=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=V.startRowOrColumn,f=V.endRowOrColumn,R=V.isLighten}const w=this._skeleton.getNoMergeCellPositionByIndex(g,S),E=this._skeleton.getNoMergeCellPositionByIndex(f,C),T=(w==null?void 0:w.startY)||0,O=(E==null?void 0:E.endY)||0,y=(w==null?void 0:w.startX)||0,x=(E==null?void 0:E.endX)||0;R?this._controlHandler((V,j)=>{const $=new l.ColorKit(this._fillControlColors[j]).lighten(Ts).toRgbString();V.setProps({fill:$})}):this._controlHandler((V,j)=>{V.setProps({fill:this._fillControlColors[j]})});const A=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();g===f&&M===!0||S===C&&M===!1?(k=this._helperSelection)==null||k.hide():((L=this._helperSelection)==null||L.transformByState({left:y-A/2,top:T-A/2,width:x-y,height:O-T}),(F=this._helperSelection)==null||F.show()),this._targetSelection={startY:T,endY:O,startX:y,endX:x,startRow:g,endRow:f,startColumn:S,endColumn:C},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(t){const{offsetX:e,offsetY:n}=t,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([e,n])),{x:s,y:a}=r;this._startOffsetX=s,this._startOffsetY=a;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 g=m==null?void 0:m.stroke,S=m==null?void 0:m.strokeWidth;const f=_.getNormalSelectionStyle(this._themeService);g==null&&(g=f.stroke),S==null&&(S=f.strokeWidth);const C=this._getScale();S/=C;const R=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/C,M=new l.ColorKit(g).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new b.Rect(uo,{stroke:M,strokeWidth:S+R/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(b.Vector2.FromArray([e,n]));const w=o.getViewport(B.VIEW_MAIN),E=b.ScrollTimer.create(o,this._activeViewport.viewPortKey===B.VIEW_MAIN?b.ScrollTimerType.ALL:b.ScrollTimerType.NONE);E.startScroll(s,a,w),this._scrollTimer=E,o.disableEvent(),this._controlHandler(T=>{this._fillControlColors.push(T.fill)}),this._moveObserver=o.onPointerMoveObserver.add(T=>{var F;const{offsetX:O,offsetY:y}=T,x=o.getActiveViewportByCoord(b.Vector2.FromArray([O,y])),{x:A,y:k}=o.getRelativeCoord(b.Vector2.FromArray([O,y]));this._fillMoving(A,k),o.setCursor(b.CURSOR_TYPE.CROSSHAIR);const L=this._targetSelection;if(w&&x&&((F=this._activeViewport)==null?void 0:F.viewPortKey)!==(x==null?void 0:x.viewPortKey)){let V;L.startRow!==c?(E.scrollTimerType=b.ScrollTimerType.Y,V={...L,endRow:L.startRow}):L.endRow!==u?(E.scrollTimerType=b.ScrollTimerType.Y,V={...L,startRow:L.endRow}):L.startColumn!==d?(E.scrollTimerType=b.ScrollTimerType.X,V={...L,endColumn:L.startColumn}):(E.scrollTimerType=b.ScrollTimerType.X,V={...L,startColumn:L.endColumn}),this._isSelectionInViewport(V,x)&&(w.scrollTo({x:E.scrollTimerType===b.ScrollTimerType.X?0:void 0,y:E.scrollTimerType===b.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}E.scrolling(A,k,()=>{this._fillMoving(A,k)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var O,y;(O=this._helperSelection)==null||O.dispose();const T=this._scene;T.resetCursor(),this._clearObserverEvent(),T.enableEvent(),(y=this._scrollTimer)==null||y.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(t,e,n,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:a,startColumn:c,endRow:d,endColumn:u}=s,h={left:e,top:t,right:o,bottom:n},m={left:c,top:a,right:u,bottom:d};if(b.isRectIntersect(h,m))return!0}return!1}_swapPositions(t,e,n,o){const r=Math.min(t,n),s=Math.min(e,o),a=Math.max(t,n),c=Math.max(e,o);return{startRow:r,startColumn:s,endRow:a,endColumn:c}}_controlHandler(t){const{leftControl:e,rightControl:n,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:a,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,n,o,r,s,a,c,d,u];for(let m=0,g=h.length;m<g;m++){const S=h[m];t(S,m)}}_fillRuler(t,e,n,o,r){let s=!1;if(t<e)if(this._isInMergeState&&t<e){const a=e-t,c=o+1,d=Math.ceil(a/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=t;else if(t>=e&&t<=n)s=!0,n=t;else if(this._isInMergeState&&t>n){const a=t-n,c=o+1,d=Math.ceil(a/c);let u=n+d*c;u>r&&(u=n+(d-1)*c),n=u}else n=t;return{rowOrColumn:t,startRowOrColumn:e,endRowOrColumn:n,isLighten:s}}_getScale(){const{scaleX:t,scaleY:e}=this._scene.getAncestorScale();return Math.max(t,e)}}var Es=Object.defineProperty,Os=Object.getOwnPropertyDescriptor,ys=(i,t,e,n)=>{for(var o=n>1?void 0:n?Os(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Es(t,e,o),o},sn=(i,t)=>(e,n)=>t(e,n,i);exports.SelectionRenderService=class{constructor(t,e,n,o){I(this,"hasSelection",!1);I(this,"_downObserver");I(this,"_moveObserver");I(this,"_upObserver");I(this,"_controlFillConfig$",new H.BehaviorSubject(null));I(this,"controlFillConfig$",this._controlFillConfig$.asObservable());I(this,"_selectionControls",[]);I(this,"_startSelectionRange",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});I(this,"_startOffsetX",0);I(this,"_startOffsetY",0);I(this,"_scrollTimer");I(this,"_cancelDownObserver");I(this,"_cancelUpObserver");I(this,"_skeleton");I(this,"_scene");I(this,"_isHeaderHighlight",!0);I(this,"_isDetectMergedCell",!0);I(this,"_selectionStyle");I(this,"_isSelectionEnabled",!0);I(this,"_isShowPreviousEnable",0);I(this,"_isRemainLastEnable",!0);I(this,"_isSkipRemainLastEnable",!1);I(this,"_selectionMoveEnd$",new H.BehaviorSubject([]));I(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());I(this,"_selectionMoving$",new H.Subject);I(this,"selectionMoving$",this._selectionMoving$.asObservable());I(this,"_selectionMoveStart$",new H.Subject);I(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());I(this,"_activeViewport");this._themeService=t,this._shortcutService=e,this._sheetSkeletonManagerService=n,this._injector=o,this._selectionStyle=_.getNormalSelectionStyle(this._themeService)}enableHeaderHighlight(){this._isHeaderHighlight=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}enableDetectMergedCell(){this._isDetectMergedCell=!0}disableDetectMergedCell(){this._isDetectMergedCell=!1}setStyle(t){this._selectionStyle=t}resetStyle(){this.setStyle(_.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(t){const e=this.getCurrentControls();if(!e)return;const{rangeWithCoord:n,primaryWithCoord:o}=t,r=this._skeleton;let s=t.style;s==null&&(s=_.getNormalSelectionStyle(this._themeService));const a=this._scene;if(a==null||r==null)return;const c=new Bn(a,e.length,this._isHeaderHighlight,this._themeService);new ho(c,r,a,this._themeService,this._injector);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(n,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),e.push(c)}updateControlForCurrentByRangeData(t){const e=this.getCurrentControls();if(!e)return;const n=this._skeleton;if(n==null)return;const{rowHeaderWidth:o,columnHeaderHeight:r}=n;for(let s=0,a=t.length;s<a;s++){const{rangeWithCoord:c,primaryWithCoord:d,style:u}=t[s];e[s].update(c,o,r,u,d)}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}changeRuntime(t,e,n){this._skeleton=t,this._scene=e,this._activeViewport=n||e.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(e=>e.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const t=this.getCurrentControls();if(t.length>0){for(const e of t)e.dispose();t.length=0}}_getFreeze(){var e;return(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig().freeze}_getViewportByCell(t,e){if(!this._scene||t===void 0||e===void 0)return null;const n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0)return this._scene.getViewport(B.VIEW_MAIN);if(t>n.startRow&&e>n.startColumn)return this._scene.getViewport(B.VIEW_MAIN);if(t<=n.startRow&&e<=n.startColumn)return this._scene.getViewport(B.VIEW_MAIN_LEFT_TOP);if(t<=n.startRow&&e>n.startColumn)return this._scene.getViewport(B.VIEW_MAIN_TOP);if(t>n.startRow&&e<=n.startColumn)return this._scene.getViewport(B.VIEW_MAIN_LEFT)}getActiveSelections(){const t=this.getCurrentControls();if(t&&t.length>0)return t==null?void 0:t.map(n=>{const o=n.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 t=this.getCurrentControls(),e=t&&t[t.length-1].model;return e&&{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}}getActiveSelection(){const t=this.getCurrentControls();return t&&t[t.length-1]}endSelection(){this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}reset(){var t,e,n;this._clearSelectionControls(),(t=this._moveObserver)==null||t.dispose(),(e=this._upObserver)==null||e.dispose(),(n=this._downObserver)==null||n.dispose(),this._moveObserver=null,this._upObserver=null,this._downObserver=null}resetAndEndSelection(){this.endSelection(),this.reset()}eventTrigger(t,e=0,n=l.RANGE_TYPE.NORMAL,o,r=b.ScrollTimerType.ALL){var oe,re;if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:a,offsetY:c}=t,d=this._scene;if(d==null||s==null)return;o!=null&&(this._activeViewport=o);const u=d.getViewport(B.VIEW_MAIN),h=d.getRelativeCoord(b.Vector2.FromArray([a,c]));let{x:m,y:g}=h;this._startOffsetX=m,this._startOffsetY=g;const S=d.getScrollXYByRelativeCoords(h),{scaleX:f,scaleY:C}=d.getAncestorScale();n===l.RANGE_TYPE.ROW?m=0:n===l.RANGE_TYPE.COLUMN&&(g=0);const R=this._getSelectedRangeWithMerge(m,g,f,C,S);if(!R)return!1;const{rangeWithCoord:M,primaryWithCoord:w}=R,{startRow:E,startColumn:T,endColumn:O,endRow:y,startY:x,endY:A,startX:k,endX:L}=M,{rowHeaderWidth:F,columnHeaderHeight:V}=s,j={startColumn:T,startRow:E,endColumn:O,endRow:y,startY:x,endY:A,startX:k,endX:L,rangeType:n};this._startSelectionRange=j;let $=this.getActiveSelection();const Z=this.getCurrentControls();if(!Z)return!1;for(const Y of Z){if(t.button===2&&Y.model.isInclude(j)){$=Y;return}if(Y.model.isEqual(j)){$=Y;break}t.shiftKey||Y.clearHighlight()}if(Z.length>0&&!t.ctrlKey&&!t.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const Y of Z)Y.dispose();Z.length=0}const W=$&&$.model.currentCell;if($&&t.shiftKey&&W){const{actualRow:Y,actualColumn:X,mergeInfo:Q}=W,le=Math.min(Y,j.startRow,Q.startRow),se=Math.max(Y,j.endRow,Q.endRow),me=Math.min(X,j.startColumn,Q.startColumn),Ve=Math.max(X,j.endColumn,Q.endColumn),pe=s.getMergeBounding(le,me,se,Ve),ue=s.getNoMergeCellPositionByIndex(pe.startRow,pe.startColumn),ae=s.getNoMergeCellPositionByIndex(pe.endRow,pe.endColumn),Be={startColumn:pe.startColumn,startRow:pe.startRow,endColumn:pe.endColumn,endRow:pe.endRow,startY:ue.startY,endY:ae.endY,startX:ue.startX,endX:ae.endX,rangeType:n},Ce=s.getCellByIndex(Y,X);this._startSelectionRange={startColumn:Ce.mergeInfo.startColumn,startRow:Ce.mergeInfo.startRow,endColumn:Ce.mergeInfo.endColumn,endRow:Ce.mergeInfo.endRow,startY:Ce.mergeInfo.startY||0,endY:Ce.mergeInfo.endY||0,startX:Ce.mergeInfo.startX||0,endX:Ce.mergeInfo.endX||0,rangeType:n},$.update(Be,F,V,this._selectionStyle,W)}else this._isRemainLastEnable&&$&&!t.ctrlKey&&!t.shiftKey&&!this._isSkipRemainLastEnable?$.update(j,F,V,this._selectionStyle,w):($=new Bn(d,Z.length+e,this._isHeaderHighlight,this._themeService),new ho($,s,d,this._themeService,this._injector),$.update(j,F,V,this._selectionStyle,w),Z.push($));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const G=d.getActiveViewportByCoord(b.Vector2.FromArray([m,g])),ne=b.ScrollTimer.create(this._scene,r);ne.startScroll((oe=u==null?void 0:u.left)!=null?oe:0,(re=u==null?void 0:u.top)!=null?re:0,u),this._scrollTimer=ne,this._addCancelObserver(),(n===l.RANGE_TYPE.ROW||n===l.RANGE_TYPE.COLUMN)&&this._moving(m,g,$,n);let D=0,U=0,z=m,q=g;this._moveObserver=d.onPointerMoveObserver.add(Y=>{var Ce,xt,At,Nt,Dt,Ki,qi,Ji,Qi,eo;const{offsetX:X,offsetY:Q}=Y,{x:le,y:se}=d.getRelativeCoord(b.Vector2.FromArray([X,Q]));this._moving(le,se,$,n);let me=le,Ve=se;const pe=this.getActiveSelection(),ue=(Ce=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Ce.skeleton.getWorksheetConfig().freeze,ae=pe==null?void 0:pe.model,Be=(xt=d.getActiveViewportByCoord(b.Vector2.FromArray([X,Q])))!=null?xt:this._getViewportByCell(ae==null?void 0:ae.endRow,ae==null?void 0:ae.endColumn);if(G&&Be&&u){const Qn=z<u.left&&le>u.left||z>u.left&&le<u.left,ei=q<u.top&&se>u.top||q>u.top&&se<u.top;Qn&&(D+=1),ei&&(U+=1);const xe=G.viewPortKey,Ht=Be.viewPortKey;if(xe===B.VIEW_ROW_TOP)Q<u.top&&((At=ae==null?void 0:ae.endRow)!=null?At:0)<((Nt=ue==null?void 0:ue.startRow)!=null?Nt:0)?Ve=u.top:ei&&U%2===1&&u.scrollTo({y:0});else if(xe===B.VIEW_COLUMN_LEFT)X<u.left&&((Dt=ae==null?void 0:ae.endColumn)!=null?Dt:0)<((Ki=ue==null?void 0:ue.startColumn)!=null?Ki:0)?me=u.left:Qn&&D%2===1&&u.scrollTo({x:0});else if(xe===Ht){let Fe=!1,et=!1;xe===B.VIEW_MAIN_LEFT_TOP?(Fe=!0,et=!0):xe===B.VIEW_MAIN_TOP?et=!0:xe===B.VIEW_MAIN_LEFT&&(Fe=!0),((qi=ae==null?void 0:ae.endRow)!=null?qi:0)>((Ji=ue==null?void 0:ue.startRow)!=null?Ji:0)&&(et=!1),((Qi=ae==null?void 0:ae.endColumn)!=null?Qi:0)>((eo=ue==null?void 0:ue.startColumn)!=null?eo:0)&&(Fe=!1),Fe&&(me=u.left),et&&(Ve=u.top)}else{const Fe={x:G.scrollX,y:G.scrollY},et={x:Be.scrollX,y:Be.scrollY},ti=Fe.x!==et.x&&Qn&&D%2===1,ni=Fe.y!==et.y&&ei&&U%2===1;(ti||ni)&&(u.scrollTo({x:ti?Fe.x:void 0,y:ni?Fe.y:void 0}),ti||(me=u.left),ni||(Ve=u.top)),(xe===B.VIEW_MAIN_LEFT_TOP&&Ht===B.VIEW_MAIN_LEFT||Ht===B.VIEW_MAIN_LEFT_TOP&&xe===B.VIEW_MAIN_LEFT)&&(me=u.left),(xe===B.VIEW_MAIN_LEFT_TOP&&Ht===B.VIEW_MAIN_TOP||Ht===B.VIEW_MAIN_LEFT_TOP&&xe===B.VIEW_MAIN_TOP)&&(Ve=u.top)}z=le,q=se}ne.scrolling(me,Ve,()=>{this._moving(le,se,$,n)})}),this._upObserver=d.onPointerUpObserver.add(Y=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(t){const{range:e,primary:n,style:o}=t;let r=this.convertRangeDataToSelection(e);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:l.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(n),style:o}}convertRangeDataToSelection(t){const{startRow:e,startColumn:n,endRow:o,endColumn:r,rangeType:s}=t,a=this._scene,c=this._skeleton;if(a==null||c==null)return;a.getAncestorScale();const d=c.getNoMergeCellPositionByIndex(e,n),u=c.getNoMergeCellPositionByIndex(o,r);return{startRow:e,startColumn:n,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(t){if(t==null)return;const e=this._scene,n=this._skeleton;if(e==null||n==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startRow:c,startColumn:d,endRow:u,endColumn:h}=t,m=n.getNoMergeCellPositionByIndex(o,r),g=n.getNoMergeCellPositionByIndex(c,d),S=n.getNoMergeCellPositionByIndex(u,h);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startX:m.startX,startY:m.startY,endX:m.endX,endY:m.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(g==null?void 0:g.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(g==null?void 0:g.startX)||0,endX:(S==null?void 0:S.endX)||0}}}_moving(t,e,n,o){var re;const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:a,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,{startRow:h,endRow:m,startColumn:g,endColumn:S}=(n==null?void 0:n.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1},f=s.getViewport(B.VIEW_MAIN),C=(re=this._getViewportByCell(m,S))!=null?re:f,R=s.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),C),{scaleX:M,scaleY:w}=s.getAncestorScale(),{rowHeaderWidth:E,columnHeaderHeight:T}=r;o===l.RANGE_TYPE.ROW?t=Number.POSITIVE_INFINITY:o===l.RANGE_TYPE.COLUMN&&(e=Number.POSITIVE_INFINITY);const O=this._getSelectedRangeWithMerge(t,e,M,w,R);if(!O)return!1;const{rangeWithCoord:y,primaryWithCoord:x}=O,{startRow:A,startColumn:k,endColumn:L,endRow:F}=y,V=Math.min(A,a),j=Math.min(k,c),$=Math.max(F,d),Z=Math.max(L,u);let W={startRow:V,startColumn:j,endRow:$,endColumn:Z};if(this._isDetectMergedCell&&(W=r.getSelectionBounding(V,j,$,Z)),!W)return!1;const{startRow:G,startColumn:ne,endRow:D,endColumn:U}=W,z=r.getNoMergeCellPositionByIndex(G,ne),q=r.getNoMergeCellPositionByIndex(D,U),oe={startColumn:ne,startRow:G,endColumn:U,endRow:D,startY:(z==null?void 0:z.startY)||0,endY:(q==null?void 0:q.endY)||0,startX:(z==null?void 0:z.startX)||0,endX:(q==null?void 0:q.endX)||0};(g!==ne||h!==G||S!==U||m!==D)&&n!=null&&(n.update(oe,E,T),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var n,o;const t=this._scene;if(t==null)return;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),t.enableEvent(),(n=this._scrollTimer)==null||n.dispose();const e=(o=t.getEngine())==null?void 0:o.activeScene;e==null||e.onPointerDownObserver.remove(this._cancelDownObserver),e==null||e.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var n;const t=this._scene;if(t==null)return;const e=(n=t.getEngine())==null?void 0:n.activeScene;e==null||e===t||(e.onPointerDownObserver.remove(this._cancelDownObserver),e.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=e.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=e.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(t,e,n,o,r){var R;if(this._isDetectMergedCell){const M=(R=this._skeleton)==null?void 0:R.calculateCellIndexByPosition(t,e,n,o,r),w=l.makeCellToSelection(M);return w==null?void 0:{primaryWithCoord:M,rangeWithCoord:w}}const s=this._skeleton;if(s==null)return;const a=s.getCellPositionByOffset(t,e,n,o,r),{row:c,column:d}=a,u=s.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:m,endX:g,endY:S}=u,f={startY:m,endY:S,startX:h,endX:g,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:g,mergeInfo:f},rangeWithCoord:f}}};exports.SelectionRenderService=ys([sn(0,N.Inject(l.ThemeService)),sn(1,v.IShortcutService),sn(2,N.Inject(exports.SheetSkeletonManagerService)),sn(3,N.Inject(N.Injector))],exports.SelectionRenderService);const fe=N.createIdentifier("deprecated.univer.sheet.selection-render-service");var xs=Object.defineProperty,As=Object.getOwnPropertyDescriptor,Ns=(i,t,e,n)=>{for(var o=n>1?void 0:n?As(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&xs(t,e,o),o},tt=(i,t)=>(e,n)=>t(e,n,i);const Ds=1e4,qt=N.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends l.Disposable{constructor(e,n,o,r,s,a,c){super();I(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=n,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=a,this._selectionManagerService=c}addShape(e,n=[],o=Ds){const r=this._currentService.getCurrentUniverSheetInstance(),s=r.getActiveSheet().getSheetId(),a=l.Tools.generateRandomId();return this._shapeMap.set(a,{selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:o,control:null,exits:n}),this.refreshShapes(),a}refreshShapes(){const e=this._currentService.getCurrentUniverSheetInstance().getUnitId(),n=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var M;const{unitId:r,subUnitId:s,selection:a,control:c,zIndex:d}=o;if(c&&c.dispose(),r!==e||s!==n)return;const{style:u}=a,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:g}=this._selectionRenderService.convertSelectionRangeToData(a),S=(M=this._sheetSkeletonManagerService.getCurrent())==null?void 0:M.skeleton;if(!h||!S)return;const{rowHeaderWidth:f,columnHeaderHeight:C}=S,R=new Bn(h,d,!1,this._themeService);R.update(m,f,C,u,g),o.control=R})}getShapeMap(){return this._shapeMap}removeShape(e){const n=this._shapeMap.get(e);if(!n)return;const{control:o}=n;o&&o.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:n}=e;n&&n.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=Ns([tt(0,l.IUniverInstanceService),tt(1,b.IRenderManagerService),tt(2,fe),tt(3,l.ICommandService),tt(4,N.Inject(exports.SheetSkeletonManagerService)),tt(5,N.Inject(l.ThemeService)),tt(6,N.Inject(_.SelectionManagerService))],exports.MarkSelectionService);const Hs=10,Ls=6;function Ps(){return l.Tools.generateRandomId(Ls)}function Us(i){const t=i.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class ks{constructor(){I(this,"_cache",new l.LRUMap(Hs))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}del(t){this._cache.delete(t)}clear(){this._cache.clear()}}var at=(i=>(i.COPY="COPY",i.CUT="CUT",i))(at||{});function Vs(i,t,e,n,o){const r=[],s=[];if(n.copyType===at.CUT){const{undos:a,redos:c}=Bs(i,t,o);r.push(...c),s.push(...a)}else{const{undos:a,redos:c}=qo(t,e,o);r.push(...c),s.push(...a);const{undos:d,redos:u}=Go(t,e,o);r.push(...u),s.push(...d);const{undos:h,redos:m}=Ko(t,e,o);r.push(...m),s.push(...h);const{undos:g,redos:S}=Ci(t,e,o);r.push(...S),s.push(...g)}return{undos:s,redos:r}}function Bs(i,t,e){let n=[],o=[];const{range:r,subUnitId:s,unitId:a}=i,{range:c,subUnitId:d}=t;if(r&&c){const u=e.get(l.IUniverInstanceService),h=e.get(_.SheetInterceptorService),m=u.getUniverSheetInstance(a),g=m==null?void 0:m.getSheetBySheetId(s),S=m==null?void 0:m.getSheetBySheetId(d);if(g&&S){const f=new l.ObjectMatrix,C=new l.ObjectMatrix,R=(W,G)=>({startRow:W,endRow:W,startColumn:G,endColumn:G}),M=g.getCellMatrix(),w=S.getCellMatrix();l.Range.foreach(r,(W,G)=>{f.setValue(W,G,l.Tools.deepClone(M.getValue(W,G))),C.setValue(W,G,null)});const E=new l.ObjectMatrix;l.Range.foreach(c,(W,G)=>{E.setValue(W,G,l.Tools.deepClone(w.getValue(W,G)))});const T=new l.ObjectMatrix;l.Range.foreach(r,(W,G)=>{const ne=R(W,G),D=l.Rectangle.getRelativeRange(ne,r),U=l.Rectangle.getPositionRange(D,c);T.setValue(U.startRow,U.startColumn,M.getValue(W,G))});const O={from:{value:C.getMatrix(),subUnitId:s},to:{value:T.getMatrix(),subUnitId:d},unitId:a},y={from:{value:f.getMatrix(),subUnitId:s},to:{value:E.getMatrix(),subUnitId:d},unitId:a},x=h.onCommandExecute({id:_.MoveRangeCommand.id,params:{toRange:c,fromRange:r}}),A=g.getMergeData(),k=S.getMergeData(),L=A.filter(W=>l.Rectangle.intersects(W,r)),F=k.filter(W=>l.Rectangle.intersects(W,c)),V=L.map(W=>l.Rectangle.getRelativeRange(W,r)).map(W=>l.Rectangle.getPositionRange(W,c)),j=_.getAddMergeMutationRangeByType(V).filter(W=>!k.some(G=>l.Rectangle.equals(W,G))),$=[{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:L}},{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:F}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:j}}],Z=[{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:j}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:F}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:L}}];n=[{id:_.MoveRangeMutation.id,params:O},...x.redos,...$,{id:_.SetSelectionsOperation.id,params:{unitId:a,subUnitId:d,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:c}]}}],o=[{id:_.SetSelectionsOperation.id,params:{unitId:a,sheetId:s,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:r}]}},...x.undos,...Z,{id:_.MoveRangeMutation.id,params:y}]}}return{undos:o,redos:n}}function Go(i,t,e){const{unitId:n,subUnitId:o,range:r}=i,s=[],a=[],{startColumn:c,startRow:d}=r,u=new l.ObjectMatrix;t.forValue((g,S,f)=>{u.setValue(g+d,S+c,{v:f.v})});const h={unitId:n,subUnitId:o,cellValue:u.getData()};s.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(e,h);return a.push({id:_.SetRangeValuesMutation.id,params:m}),{undos:a,redos:s}}function Ko(i,t,e){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d}=a,u=new l.ObjectMatrix;t.forValue((g,S,f)=>{var R;const C={s:f.s};(R=f.p)!=null&&R.body&&(C.p=f.p),u.setValue(g+d,S+c,C)});const h={unitId:r,subUnitId:s,cellValue:u.getData()};n.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(e,h);return o.push({id:_.SetRangeValuesMutation.id,params:m}),{undos:o,redos:n}}function qo(i,t,e){const n=[],o=[],r=new l.ObjectMatrix,{unitId:s,subUnitId:a,range:c}=i,{startColumn:d,startRow:u}=c;if(t.forValue((h,m,g)=>{g.s&&r.setValue(h+u,m+d,{s:null})}),r.getLength()>0){const h={subUnitId:a,unitId:s,cellValue:r.getData()};n.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(e,h);o.push({id:_.SetRangeValuesMutation.id,params:m})}return{undos:o,redos:n}}function Ci(i,t,e){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d,endColumn:u,endRow:h}=a;let m=!1;const g=[];if(t.forValue((C,R,M)=>{if(M.rowSpan){const w=M.colSpan||1,E={startRow:d+C,endRow:d+C+M.rowSpan-1,startColumn:c+R,endColumn:c+R+w-1};g.push(E),m=!0}else if(M.colSpan){const w=M.rowSpan||1,E={startRow:d+C,endRow:d+C+w-1,startColumn:c+R,endColumn:c+R+M.colSpan-1};g.push(E),m=!0}}),m){const R=e.get(l.IUniverInstanceService).getUniverSheetInstance(r),M=R==null?void 0:R.getSheetBySheetId(s);if(R&&M){const E=M.getMergeData().filter(y=>l.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},y)),T={unitId:r,subUnitId:s,ranges:E};n.push({id:_.RemoveWorksheetMergeMutation.id,params:T});const O=_.RemoveMergeUndoMutationFactory(e,T);o.push({id:_.AddWorksheetMergeMutation.id,params:O})}}const S={unitId:r,subUnitId:s,ranges:g};n.push({id:_.AddWorksheetMergeMutation.id,params:S});const f=_.AddMergeUndoMutationFactory(e,S);return o.push({id:_.RemoveWorksheetMergeMutation.id,params:f}),{undos:o,redos:n}}function Jo(i){let t=i.replace(/(\r\n|\n)/g,"\r");t.endsWith(`\r
2
+ `)||(t+=`\r
3
+ `);const e=[];for(let n=0;n<t.length;n++)t[n]==="\r"&&e.push({startIndex:n});return{dataStream:t,paragraphs:e,sectionBreaks:[{startIndex:t.indexOf(`
4
+ `)}]}}function yi(i){const t=i.style,e={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=l.BooleanNumber.TRUE;break}case"s":{e.st={s:l.BooleanNumber.TRUE};break}case"u":{e.ul={s:l.BooleanNumber.TRUE};break}case"i":{e.it=l.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?l.BaselineOffset.SUPERSCRIPT:l.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<t.length;o++){const r=t[o],s=t.getPropertyValue(r);switch(r){case"font-family":{e.ff=s;break}case"font-size":{const a=Number.parseInt(s);Number.isNaN(a)||s.endsWith("pt")&&(e.fs=a);break}case"font-style":{s==="italic"&&(e.it=l.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(e.bl=l.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?e.ul={s:l.BooleanNumber.TRUE}:/overline/.test(s)?e.ol={s:l.BooleanNumber.TRUE}:/line-through/.test(s)&&(e.st={s:l.BooleanNumber.TRUE});break}case"color":{const a=new l.ColorKit(s);a.isValid&&(e.cl={rgb:a.toRgbString()});break}case"background-color":{const a=new l.ColorKit(s);a.isValid&&(e.bg={rgb:a.toRgbString()});break}}}return e}function Fs(i){const t=new DOMParser,e=`<x-univer id="univer-root">${i}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function Ws(i){const t=i.style,e={};for(let n=0;n<t.length;n++){const o=t[n],r=t.getPropertyValue(o);switch(o){case"margin-top":{const s=Number.parseInt(r);e.spaceAbove=/pt/.test(r)?b.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(r);e.spaceBelow=/pt/.test(r)?b.ptToPixel(s):s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function mo(i,t){const e=[];for(let n=0,o=i.length;n<o;n++)i[n]===l.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=l.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=l.Tools.deepClone(t.paragraphStyle));return e}function go(i,t){const e=i.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(i)}const $n=class $n{constructor(t){I(this,"styleCache",new Map);I(this,"styleRules",[]);I(this,"afterProcessRules",[]);I(this,"getCurrentSkeleton");this.getCurrentSkeleton=t.getCurrentSkeleton}static use(t){if(this.pluginList.includes(t))throw new Error(`Univer paste plugin ${t.name} already added`);this.pluginList.push(t)}convert(t){const e=$n.pluginList.find(g=>g.checkPasteType(t));e&&(this.styleRules=[...e.stylesRules],this.afterProcessRules=[...e.afterProcessRules]);const n=new l.ObjectMatrix,o=Fs(t),r={dataStream:"",textRuns:[]},s=[],a=[],c=t.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 g=u.map(S=>S.startIndex+1);g.unshift(0);for(let S=0;S<g.length;S++){let f;S===g.length-1?f=`${h.substring(g[S])}\r
5
+ `:f=`${h.substring(g[S],g[S+1]-1)}\r
6
+ `;const C=[];m==null||m.forEach(M=>{M.st>=g[S]&&M.ed<=g[S+1]&&C.push({st:M.st-g[S],ed:M.ed-g[S],ts:M.ts})});const R=this._generateDocumentDataModelSnapshot({body:{dataStream:f,textRuns:C,paragraphs:mo(f)}});n.setValue(n.getLength(),0,{v:f,p:R}),s.push({}),c&&d.forEach(M=>{const w=n.getDataRange().endRow+1;if(M.index===S){const E=c.shift(),{cellMatrix:T,colProperties:O,rowProperties:y}=this._parseTable(E);T&&T.forValue((x,A,k)=>{n.setValue(w+x,A,k)}),O&&a.push(...O),s.push(...y)}})}}else{if(h){const g=`${h}\r
7
+ `,S={dataStream:g,textRuns:m,paragraphs:mo(g)},f=this._generateDocumentDataModelSnapshot({body:S});n.setValue(0,0,{v:h,p:f}),s.push({})}c&&c.forEach(g=>{const S=n.getDataRange().endRow+1,{cellMatrix:f,rowProperties:C,colProperties:R}=this._parseTable(g);f&&f.forValue((M,w,E)=>{const{rowSpan:T=1,colSpan:O=1}=E;for(let y=0;y<T;y++)for(let x=0;x<O;x++)n.setValue(S+M+y,w+x,{v:""});n.setValue(S+M,w,E)}),R&&a.push(...R),s.push(...C)})}return{rowProperties:s,colProperties:a,cellMatrix:n}}_parseTable(t){const e=new l.ObjectMatrix,n=zs(t),{rowProperties:o,rowCount:r,cellMatrix:s}=js(t);return s&&s.forValue((a,c,d)=>{var h;const u=v.handleStringToStyle(void 0,(h=d.properties)==null?void 0:h.style);if(/\r|\n/.test(d.content)){const m=Jo(d.content),g=this._generateDocumentDataModelSnapshot({body:m});e.setValue(a,c,{v:d.content,p:g,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}else e.setValue(a,c,{v:d.content,s:u,rowSpan:d.rowSpan,colSpan:d.colSpan})}),{rowProperties:o,colProperties:n,cellMatrix:e}}_generateDocumentDataModelSnapshot(t){var a;const e=this.getCurrentSkeleton();if(e==null)return null;const{skeleton:n}=e,o=(a=n.getBlankCellDocumentModel())==null?void 0:a.documentModel,s={...o==null?void 0:o.getSnapshot(),...t};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(t,e,n,o){var r,s;for(const a of e)if(a.nodeName.toLowerCase()==="table")o.push({index:((r=n==null?void 0:n.paragraphs)==null?void 0:r.length)||0});else if(a.nodeType===Node.TEXT_NODE){const c=(s=a.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let d;t&&this.styleCache.has(t)&&(d=this.styleCache.get(t));const u={dataStream:"",textRuns:[]};n.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(n.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}),u.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}))}else if(a.nodeType===Node.ELEMENT_NODE){const c=t?this.styleCache.get(t):{},d=this.styleRules.find(({filter:g})=>go(a,g)),u=d?d.getStyle(a):yi(a);this.styleCache.set(a,{...c,...u});const{childNodes:h}=a;this.process(a,h,n,o);const m=this.afterProcessRules.find(({filter:g})=>go(a,g));m&&m.handler(n,a)}}};I($n,"pluginList",[]);let Yt=$n;function js(i){const t=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,e=i.matchAll(t);if(!e)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const n=Array.from(e),o=n.map(a=>xi(a[1])),{colCount:r,cellMatrix:s}=$s(n.map(a=>a[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function $s(i){const t=new l.ObjectMatrix,e=new Map,n=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((a,c)=>{const d=c===0,u=a.matchAll(n);r=0,Array.from(u).forEach(h=>{const m=xi(h[1]),g=Ys(h[2].replace("<br>","\r").replace(/<\/?[^>]*>/g,"")),S=m.rowspan?+m.rowspan:1,f=m.colspan?+m.colspan:1;if(!d){for(let R=r;R<o;R++)if(!(e.get(R)>=s)){r=R;break}}const C={content:g,properties:m};f>1&&(C.colSpan=+f),S>1&&(C.rowSpan=+S),d&&(o+=f);for(let R=r;R<r+f;R++)e.set(R,s+S-1);t.setValue(s,r,C),r+=f}),s+=1}),{colCount:o,cellMatrix:t}}function xi(i){if(!i)return{};const t=/([\w-]+)="([^"]*)"/gi,e=i.matchAll(t),n={};return Array.from(e).forEach(o=>{const[r,s,a]=o;n[s]=a}),n}function zs(i){const t=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,e=i.match(t);if(!e||!e[2])return null;const n=/<col([\s\S]*?)>/g,o=e[2].matchAll(n);return o?Array.from(o).map(r=>xi(r[1])):null}function Ys(i){const t={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return i.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,e=>t[e])}const Xs={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const t=yi(i);return{st:{s:l.BooleanNumber.TRUE},...t}}}],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"}}]},Zs=Xs,Gs={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const t=yi(i);return{bl:l.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,t){i.paragraphs==null&&(i.paragraphs=[]);const e={startIndex:i.dataStream.length},n=Ws(t);n&&(e.paragraphStyle=n),i.paragraphs.push(e),i.dataStream+="\r"}}]},Ks=Gs;function qs(i,t,e,n){const o=e.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=Ai(o),s=Ni(r),a=t.map(c=>Js(i,c,e,n)).filter(c=>!!c).join("");return`<tr${s}>${a}</tr>`}function Js(i,t,e,n){const o=n.getValue(i,t),r=e.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,i,t,o==null?void 0:o.rowSpan,o==null?void 0:o.colSpan)}).filter(d=>!!d),s=Ai(r),a=Ni(s),c=e.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,t))||""},"");return`<td${a}>${c}</td>`}function Qs(i,t){return`<colgroup>${i.map(n=>{const o=t.map(a=>{var c;return(c=a.onCopyColumn)==null?void 0:c.call(a,n)}).filter(a=>!!a),r=Ai(o);return`<col ${Ni(r)}>`}).join("")}</colgroup>`}function Ai(i){return i.reduce((t,e)=>(Object.keys(e).forEach(o=>{t[o]?t[o]+=`;${e[o]}`:t[o]=e[o]}),t),{})}function Ni(i){return Object.keys(i).reduce((t,e)=>(t+=` ${e}="${i[e]}"`,t),"")}function ea(i,t){const e=[];for(let n=i;n<=t;n++)e.push(n);return e}class ta{convert(t,e,n){const{startColumn:o,endColumn:r}=e,s=Qs(ea(o,r),n),a=[],{startRow:c,endRow:d,startColumn:u,endColumn:h}=t.getDataRange();for(let g=c;g<=d;g++){const S=Array.from({length:h-u+1},(f,C)=>u+C);a.push(qs(g,S,n,t))}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>${a.join("")}</tbody></table>`}}var na=Object.defineProperty,ia=Object.getOwnPropertyDescriptor,oa=(i,t,e,n)=>{for(var o=n>1?void 0:n?ia(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&na(t,e,o),o},Ze=(i,t)=>(e,n)=>t(e,n,i);const _e={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"};Yt.use(Ks);Yt.use(Zs);const Rt=N.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends l.Disposable{constructor(e,n,o,r,s,a,c,d){super();I(this,"_clipboardHooks",[]);I(this,"_clipboardHooks$",new H.BehaviorSubject([]));I(this,"clipboardHooks$",this._clipboardHooks$.asObservable());I(this,"_htmlToUSM");I(this,"_usmToHtml");I(this,"_copyContentCache");I(this,"_copyMarkId",null);this._logService=e,this._currentUniverService=n,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=a,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Yt({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new ta,this._copyContentCache=new ks}copyContentCache(){return this._copyContentCache}async copy(e=at.COPY){const n=this._selectionManagerService.getLast();if(!n)return!1;const o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=this._clipboardHooks;s.forEach(g=>{var S;return(S=g.onBeforeCopy)==null?void 0:S.call(g,o.getUnitId(),r.getSheetId(),n.range)});const a=this._generateCopyContent(o.getUnitId(),r.getSheetId(),n.range,s);if(!a)return!1;const{html:c,plain:d,matrixFragment:u,copyId:h}=a;this._copyContentCache.set(h,{unitId:o.getUnitId(),subUnitId:r.getSheetId(),range:n.range,matrix:u,copyType:e}),await this._clipboardInterfaceService.write(d,c),this._markSelectionService.removeAllShapes();const m=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...n,style:m}),s.forEach(g=>{var S;return(S=g.onAfterCopy)==null?void 0:S.call(g)}),!0}async cut(){return this.copy(at.CUT)}async paste(e,n=_e.DEFAULT_PASTE){const o=e.types,r=o.indexOf(v.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(v.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"",s=o.indexOf(v.HTML_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(v.HTML_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"";return s?this._pasteHTML(s,n):r?this._pastePlainText(r,n):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}legacyPaste(e,n){return e?this._pasteHTML(e,_e.DEFAULT_PASTE):n?this._pastePlainText(n,_e.DEFAULT_PASTE):Promise.resolve(!1)}addClipboardHook(e){if(this._clipboardHooks.findIndex(o=>o.id===e.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",e.id),{dispose:()=>{}};const n=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(e.priority||0)<r});return this._clipboardHooks.splice(n!==-1?n:this._clipboardHooks.length,0,e),this._notifyClipboardHook(),l.toDisposable(()=>{const o=this._clipboardHooks.indexOf(e);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(e,n,o,r){const s=this._currentUniverService.getUniverSheetInstance(e),a=s==null?void 0:s.getSheetBySheetId(n);if(!s||!a)return null;r.reduce((R,M)=>{var E;const w=(E=M.getFilteredOutRows)==null?void 0:E.call(M);return w==null||w.forEach(T=>R.add(T)),R},new Set);const{startColumn:c,startRow:d,endColumn:u,endRow:h}=o,m=a.getMatrixWithMergedCells(d,c,h,u),g=new l.ObjectMatrix;for(let R=d;R<=h;R++)for(let M=c;M<=u;M++){const w=m.getValue(R,M);w?g.setValue(R-d,M-c,{...So(),...l.Tools.deepClone(w)}):g.setValue(R-d,M-c,So())}let S=this._usmToHtml.convert(m,o,r);const f=ra(g),C=Ps();return S=S.replace(/(<[a-z]+)/,(R,M)=>`${M} data-copy-id="${C}"`),{copyId:C,plain:f,html:S,matrixFragment:g}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(e,n){const o=this._getPastingTarget();if(!o.selection)return!1;const r=o.selection.range,{unitId:s,subUnitId:a}=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:a,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 C;const f=(C=S.onPastePlainText)==null?void 0:C.call(S,{unitId:s,subUnitId:a,range:r},e,{pasteType:n});f&&(h.push(...f.redos),m.push(...f.undos))});const g=h.every(S=>this._commandService.executeCommand(S.id,S.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),undoMutations:m,redoMutations:h}),g}async _pasteHTML(e,n){const o=Us(e);return o&&this._copyContentCache.get(o)?this._pasteInternal(o,n):this._pasteExternal(e,n)}async _pasteExternal(e,n){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(e),{startColumn:h,endColumn:m,startRow:g,endRow:S}=u.getDataRange(),f=S-g+1,C=m-h+1;if(!u||m<h||S<g)return!1;const R=this._transformPastedData(f,C,u,r.range);return R?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:a,pastedRange:R},n):!1}async _pasteInternal(e,n){var L,F;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o,c=l.Tools.deepClone(this._copyContentCache.get(e)),{range:d,matrix:u,unitId:h,subUnitId:m}=c||{};if(!r||!u||!c||!d||!h||!m||!r||!u||!c)return!1;const g=(L=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:L.getStyles();u.forValue((V,j,$)=>{if(typeof $.s=="string"){const Z=l.Tools.deepClone($);Z.s=g==null?void 0:g.getStyleByCell($),u.setValue(V,j,Z)}});const{startColumn:S,endColumn:f,startRow:C,endRow:R}=d,M=this._transformPastedData(R-C+1,f-S+1,u,r.range);if(!M)return!1;const w=(F=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:F.getSheetBySheetId(m);if(!w)return!1;const E=w.getColumnManager(),T=w.getRowManager(),O=w.getConfig().defaultColumnWidth,y=w.getConfig().defaultRowHeight,x=[],A=[];for(let V=S;V<=f;V++){const j=E.getColumnOrCreate(V);x.push({width:`${j.w||O}`})}for(let V=C;V<=R;V++){const j=T.getRowOrCreate(V);A.push({height:`${j.h||y}`})}const k=this._pasteUSM({cellMatrix:u,colProperties:x,rowProperties:A},{unitId:s,subUnitId:a,pastedRange:M},n,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:e});return c.copyType===at.CUT&&(this._copyContentCache.set(e,{...c,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),k}_pasteUSM(e,n,o,r){const{rowProperties:s,colProperties:a,cellMatrix:c}=e,{unitId:d,subUnitId:u,pastedRange:h}=n,{startColumn:m,endColumn:g}=h,S=g-m+1,f=this._clipboardHooks,C=[];if(f.some(A=>{var k;return C.push(A)&&((k=A.onBeforePaste)==null?void 0:k.call(A,{unitId:d,subUnitId:u,range:h}))===!1}))return C.forEach(A=>{var k;return(k=A.onAfterPaste)==null?void 0:k.call(A,!1)}),!1;if(!c)return!1;const M=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,w={copyType:(r==null?void 0:r.copyType)||at.COPY,copyId:r==null?void 0:r.copyId,pasteType:o},E=[],T=[];C.filter(A=>!A.specialPasteInfo&&A.id!==_e.DEFAULT_PASTE||o===A.id).forEach(A=>{var F,V,j;if(s){const $=(F=A.onPasteRows)==null?void 0:F.call(A,{range:h,unitId:d,subUnitId:u},s,{pasteType:o});$&&(E.push(...$.redos),T.push(...$.undos))}const k=(V=A.onPasteColumns)==null?void 0:V.call(A,{range:h,unitId:d,subUnitId:u},a||new Array(S).map(()=>({})),{pasteType:o});k&&(E.push(...k.redos),T.push(...k.undos));const L=(j=A.onPasteCells)==null?void 0:j.call(A,M,{range:h,unitId:d,subUnitId:u},c,w);L&&(E.push(...L.redos),T.push(...L.undos))});const y=this._getSetSelectionOperation(d,u,h,c);y&&E.push(y),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:T,redoMutationsInfo:E});const x=E.every(A=>this._commandService.executeCommand(A.id,A.params));return x&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:T,redoMutations:E}),x}_getSetSelectionOperation(e,n,o,r){var f;const s=(f=this._currentUniverService.getUniverSheetInstance(e))==null?void 0:f.getSheetBySheetId(n);if(!s)return null;const{startRow:a,startColumn:c}=o,d={startRow:a,endRow:a,startColumn:c,endColumn:c},u=_.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,g=(h==null?void 0:h.colSpan)||1;if(m>1||g>1){const C={startRow:a,endRow:a+m-1,startColumn:c,endColumn:c+g-1};u.startRow=C.startRow,u.endRow=C.endRow,u.startColumn=C.startColumn,u.endColumn=C.endColumn,u.isMerged=!0,u.isMergedMainCell=!0}const S={unitId:e,subUnitId:n,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:_.SetSelectionsOperation.id,params:S}}_getPastingTarget(){const e=this._currentUniverService.getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:e.getUnitId(),subUnitId:n.getSheetId(),selection:o}}_transformPastedData(e,n,o,r){const{startRow:s,startColumn:a,endRow:c,endColumn:d}=r,u=c-s+1,h=d-a+1,f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(T=>l.Rectangle.intersects({startRow:s,startColumn:a,endRow:c,endColumn:d},T)),C=f[0];let R=0,M=0,w=0,E=0;if(C&&(R=C.startRow,M=C.startColumn,w=C.endRow,E=C.endColumn),u%e===0&&h%n===0)if(f.length>0&&(u!==e||h!==n))if(R===s&&M===a&&w===c&&E===d)if(da(o))for(let O=0;O<u;O++)for(let y=0;y<h;y++){const x=o.getValue(O%e,y%n);x&&o.setValue(O,y,x)}else o.forValue((O,y,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan});else for(let T=0;T<u;T++)for(let O=0;O<h;O++){const y=o.getValue(T%e,O%n);y&&o.setValue(T,O,y)}else for(let T=0;T<u;T++)for(let O=0;O<h;O++){const y=o.getValue(T%e,O%n);y&&o.setValue(T,O,y)}else if(f.length>0)if(this._topLeftCellsMatch(e,n,r))r.endRow=s+e-1,r.endColumn=a+n-1;else{if(c>C.endRow||d>C.endColumn)return null;o.forValue((O,y,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan})}else r.endRow=s+e-1,r.endColumn=a+n-1;return r}_topLeftCellsMatch(e,n,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:a,startColumn:c,endRow:d,endColumn:u}=o,h=la(a+e-1,c,c+e-1,s),m=ca(c+n-1,a,a+e-1,s);return!h&&!m}};exports.SheetClipboardService=oa([Ze(0,l.ILogService),Ze(1,l.IUniverInstanceService),Ze(2,N.Inject(_.SelectionManagerService)),Ze(3,v.IClipboardInterfaceService),Ze(4,l.IUndoRedoService),Ze(5,l.ICommandService),Ze(6,qt),Ze(7,N.Inject(exports.SheetSkeletonManagerService))],exports.SheetClipboardService);function ra(i){let t="";return i.forRow((e,n)=>{const o=[];n.forEach(r=>{const s=i.getValue(e,r);if(s){const a=sa(s);o.push(a)}}),t+=o.join(" "),e!==i.getLength()-1&&(t+=`
9
+ `)}),t}function sa(i){const t=i.v;return aa((t==null?void 0:t.toString())||"")}const aa=i=>i.replace(/&/g,"&amp;").replace(/\uFEFF/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function la(i,t,e,n){return n.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&t<=o.startColumn&&o.startColumn<=e)}function ca(i,t,e,n){return n.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&t<=o.startRow&&o.startRow<=e)}function da(i){let t=0;return i.forValue((e,n,o)=>{if(o&&t++,t>1)return!1}),t>1}function So(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const Di=998,Qo={id:v.CopyCommand.id,name:"sheet.command.copy",type:l.CommandType.COMMAND,multi:!0,priority:Di,preconditions:Oi,handler:async i=>i.get(Rt).copy()},ua={id:v.CutCommand.id,name:"sheet.command.cut",type:l.CommandType.COMMAND,multi:!0,priority:Di,preconditions:Oi,handler:async i=>i.get(Rt).cut()},Mt={id:v.PasteCommand.id,type:l.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:Di,preconditions:Oi,handler:async(i,t)=>{const e=i.get(l.ILogService);if(e.debug("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){e.debug("[SheetPasteCommand]","failed to execute paste command on the activeElement, trying to use clipboard API.");const r=await i.get(v.IClipboardInterfaceService).read(),s=i.get(Rt);return r.length!==0?s.paste(r[0],t==null?void 0:t.value):!1}return!1}},er={id:"sheet.command.paste-value",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(Mt.id,{value:_e.SPECIAL_PASTE_VALUE})},tr={id:"sheet.command.paste-format",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(Mt.id,{value:_e.SPECIAL_PASTE_FORMAT})},nr={id:"sheet.command.paste-col-width",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(Mt.id,{value:_e.SPECIAL_PASTE_COL_WIDTH})},ir={id:"sheet.command.paste-besides-border",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(Mt.id,{value:_e.SPECIAL_PASTE_BESIDES_BORDER})};var ha=Object.defineProperty,ma=Object.getOwnPropertyDescriptor,ga=(i,t,e,n)=>{for(var o=n>1?void 0:n?ma(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&ha(t,e,o),o},_o=(i,t)=>(e,n)=>t(e,n,i);let Xt=class{constructor(i,t){I(this,"_current",null);I(this,"_shortcutParam",[]);this._currentUniverService=i,this._localeService=t}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const t=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(t!=null){const e=this._shortcutParam.indexOf(t);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(i),t}remove(i){if(i==null)return;const t=this._getCurrentBySearch(i);if(t==null)return;const e=this._shortcutParam.indexOf(t);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(e=>e.unitId===i.unitId&&e.sheetId===i.sheetId&&e.keycode===i.keycode)}};Xt=ga([_o(0,l.IUniverInstanceService),_o(1,N.Inject(l.LocaleService))],Xt);function qe(i,t,e,n,o=!0,r=1,s=!0){let a={...i};n==null&&(n={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(t){case l.Direction.UP:for(c=i.startRow-r;c>-1&&!e.getRowVisible(c);)c-=1;c>=n.startRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.endRow,a.endRow=n.endRow,o&&(a=qe(a,l.Direction.LEFT,e,n,!1)));break;case l.Direction.DOWN:for(c=i.endRow+r;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=n.endRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.startRow,a.endRow=n.startRow,o&&(a=qe(a,l.Direction.RIGHT,e,n,!1)));break;case l.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!e.getColVisible(c);)c-=1;c>=n.startColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.endColumn,a.endColumn=n.endColumn,o&&(a=qe(a,l.Direction.UP,e,n,!1)));break;case l.Direction.RIGHT:for(c=i.endColumn+r;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=n.endColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.startColumn,a.endColumn=n.startColumn,o&&(a=qe(a,l.Direction.DOWN,e,n,!1)));break}return a}function Hi(i,t,e){const n={...i},{startRow:o,startColumn:r,endRow:s,endColumn:a}=Zt(i,t,e);let c=Lt(e,o,r,s,a).hasValue,d=!0,u=!0;for(;u;){if(l.Direction.UP===t){let h=n.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=Lt(e,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue(f=>{S=Math.min(f,S)}),n.startRow=S}else n.startRow=h;if(n.endRow=n.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.DOWN===t){let h=n.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:m,matrix:g}=Lt(e,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C,R)=>{S=Math.max(f+(R.rowSpan||1)-1,S)}),n.endRow=S}else n.endRow=h;if(n.startRow=n.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.LEFT===t){let h=n.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=Lt(e,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C)=>{S=Math.min(C,S)}),n.startColumn=S}else n.startColumn=h;if(n.endColumn=n.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.RIGHT===t){let h=n.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:m,matrix:g}=Lt(e,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C,R)=>{S=Math.max(C+(R.colSpan||1)-1,S)}),n.endColumn=S}else n.endColumn=h;if(n.startColumn=n.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return _.alignToMergedCellsBorders(n,e,!0)}function or(i,t,e){return qe(i,t,e,void 0,!1,1,!1)}function Sa(i,t,e){const n=Hi(i,t,e);return _.alignToMergedCellsBorders(l.Rectangle.union(n,i),e,!0)}function _a(i,t,e){const n=or(i,t,e),o={startRow:Math.min(i.startRow,n.startRow),startColumn:Math.min(i.startColumn,n.startColumn),endRow:Math.max(i.endRow,n.endRow),endColumn:Math.max(i.endColumn,n.endColumn)};return _.alignToMergedCellsBorders(l.Rectangle.union(i,o),e)}function fa(i,t,e,n){const o=l.getReverseDirection(e),r=Hi(Zt(i,o,n),e,n);return e===l.Direction.UP&&r.startRow<=i.startRow?_.alignToMergedCellsBorders({...t,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):e===l.Direction.DOWN&&r.endRow>=i.endRow?_.alignToMergedCellsBorders({...t,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):e===l.Direction.LEFT&&r.startColumn<=i.startColumn?_.alignToMergedCellsBorders({...t,startRow:i.startRow,endRow:i.endRow},n,!0):e===l.Direction.RIGHT&&r.endColumn>=i.endColumn?_.alignToMergedCellsBorders({...t,startRow:i.startRow,endRow:i.endRow},n,!0):l.Rectangle.union(l.Rectangle.clone(t),r)}function pa(i,t,e){const n=l.getReverseDirection(t),o=Zt(i,n,e),r=Zt(i,t,e),s=or(o,t,e);return _.alignToMergedCellsBorders(l.Rectangle.union(r,s),e,!1)}function Ca(i,t,e){const{left:n,right:o,up:r,down:s}=t,a=e.getMaxRows(),c=e.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;e.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,S,f)=>{f.v&&(u.startRow=Math.min(g,u.startRow),u.startColumn=Math.min(S,u.startColumn),u.endColumn=Math.max(S,u.endColumn),d=!0)})}if(s&&u.endRow!==a-1){const h=u.endRow+1;e.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,S,f)=>{f.v&&(u.endRow=Math.max(g+(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(n&&u.startColumn!==0){const h=u.startColumn-1;e.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,S,f)=>{f.v&&(u.startColumn=Math.min(S,u.startColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;e.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,S,f)=>{f.v&&(u.endColumn=Math.max(S+(f.colSpan!==void 0?f.colSpan-1:0),u.endColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}}return u}function fo(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL}}function Zt(i,t,e){let n;switch(t){case l.Direction.UP:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.DOWN:n={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.LEFT:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.RIGHT:n={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return _.alignToMergedCellsBorders(n,e,!1)}function Lt(i,t,e,n,o){let r=!1;const s=i.getMatrixWithMergedCells(t,e,n,o).forValue((a,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function vi(i,t,e){const n=l.Rectangle.clone(i);if(t==null)return n;switch(e){case l.Direction.UP:case l.Direction.DOWN:n.startColumn=n.endColumn=t.actualColumn;break;case l.Direction.LEFT:case l.Direction.RIGHT:n.startRow=n.endRow=t.actualRow;break}return n}function va(i,t,e){const{primary:n,range:o}=i,r=l.Rectangle.clone(o);switch(t){case l.Direction.UP:case l.Direction.DOWN:r.startRow=n.startRow,r.endRow=n.endRow;break;case l.Direction.LEFT:case l.Direction.RIGHT:r.startColumn=n.startColumn,r.endColumn=n.endColumn;break}const s=Zt(r,t,e);switch(t){case l.Direction.DOWN:return o.startRow<s.startRow;case l.Direction.UP:return o.endRow>s.endRow;case l.Direction.LEFT:return s.endColumn<o.endColumn;case l.Direction.RIGHT:return s.startColumn>o.startColumn}}function rr(i,t){let e=i[0].startRow,n=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:a}=r;e=Math.min(e,s),n=Math.max(n,a)});const o=new Array(n-e+1).fill(!1);return t.forEach(r=>{const{startRow:s,endRow:a}=r;for(let c=Math.max(s,e);c<=Math.min(a,n);c++)o[c-e]=!0}),i.every(r=>{const{startRow:s,endRow:a}=r;for(let c=s;c<=a;c++)if(!o[c-e])return!1;return!0})}function sr(i,t){let e=i[0].startColumn,n=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:a}=r;e=Math.min(e,s),n=Math.max(n,a)});const o=new Array(n-e+1).fill(!1);return t.forEach(r=>{const{startColumn:s,endColumn:a}=r;for(let c=Math.max(s,e);c<=Math.min(a,n);c++)o[c-e]=!0}),i.every(r=>{const{startColumn:s,endColumn:a}=r;for(let c=s;c<=a;c++)if(!o[c-e])return!1;return!0})}var Ue=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(Ue||{});const Te={id:"sheet.command.move-selection",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const e=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=t,{range:a,primary:c}=o,d=vi(a,c,r),u=s===1?Hi(d,r,n):qe(d,r,n),h=_.getCellAtRowCol(u.startRow,u.startColumn,n);return l.Rectangle.equals(h,d)?!1:(i.get(Xt).remove({unitId:e.getUnitId(),sheetId:n.getSheetId(),keycode:v.KeyCode.TAB}),i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:l.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}}]}))}},dt={id:"sheet.command.move-selection-enter-tab",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const e=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast(),r=e.getUnitId(),s=n.getSheetId();if(!o)return!1;const{direction:a,keycode:c}=t,{range:d,primary:u}=o;let h=vi(d,u,a);const m=i.get(Xt),g=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:v.KeyCode.TAB});let S;const{startRow:f,endRow:C,startColumn:R,endColumn:M}=d;if(l.Rectangle.equals(d,u)){if(c===v.KeyCode.TAB)g==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:v.KeyCode.TAB,selection:o});else{const T=g==null?void 0:g.selection;if(T!=null){const{range:O,primary:y}=T;h=vi(O,y,a)}m.remove({unitId:r,sheetId:s,keycode:v.KeyCode.TAB})}const w=qe(h,a,n),E=_.getCellAtRowCol(w.startRow,w.startColumn,n);if(l.Rectangle.equals(E,h))return!1;S={range:l.Rectangle.clone(E),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}}}else{m.remove({unitId:r,sheetId:s,keycode:v.KeyCode.TAB});const w=l.Tools.deepClone(u),E=qe({startRow:w.startRow,startColumn:w.startColumn,endRow:w.endRow,endColumn:w.endColumn},a,n,{startRow:f,endRow:C,startColumn:R,endColumn:M}),T=_.getCellAtRowCol(E.startRow,E.startColumn,n);S={range:l.Rectangle.clone(d),primary:{startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn,actualRow:E.startRow,actualColumn:E.startColumn,isMerged:T.isMerged,isMergedMainCell:T.startRow===E.startRow&&T.startColumn===E.startColumn}}}return i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:r,subUnitId:s,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[S]})}},ke={id:"sheet.command.expand-selection",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const e=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:a,direction:c}=t,u=va(o,c,n)?a===1?fa(r,{...l.Rectangle.clone(s),rangeType:l.RANGE_TYPE.NORMAL},c,n):pa(r,c,n):a===1?Sa(r,c,n):_a(r,c,n);return l.Rectangle.equals(u,r)?!1:i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:e.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let Ae=[],oi="";const ar={id:"sheet.command.select-all",type:l.CommandType.COMMAND,onDispose(){Ae=[],oi=""},handler:async(i,t={expandToGapFirst:!0,loop:!1})=>{const e=i.get(_.SelectionManagerService).getLast(),n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet();if(!e||!o)return!1;const r=`${n.getUnitId()}|${o.getSheetId()}`;r!==oi&&(Ae=[],oi=r);const s=o.getMaxRows(),a=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=t,{range:u,primary:h}=e,m=u.endColumn===a-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;Ae.some(S=>l.Rectangle.equals(S,u))||(Ae=[],Ae.push(u));let g;if(m)if(d){if(Ae.findIndex(f=>l.Rectangle.equals(f,u))!==Ae.length-1)return!1;g=Ae[0]}else return!1;else c?(g=Ca(u,{left:!0,right:!0,up:!0,down:!0},o),l.Rectangle.equals(g,u)&&(g=fo(o))):g=fo(o);return Ae.some(S=>l.Rectangle.equals(S,g))||Ae.push(g),i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:o.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:g,primary:h}]})}};var Ia=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,Ma=(i,t,e,n)=>{for(var o=n>1?void 0:n?Ra(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Ia(t,e,o),o},Pt=(i,t)=>(e,n)=>t(e,n,i);const ba=l.createInterceptorKey("BEFORE_CELL_EDIT"),wa=l.createInterceptorKey("AFTER_CELL_EDIT");exports.EditorBridgeService=class extends l.Disposable{constructor(e,n,o,r,s){super();I(this,"_editorUnitId",l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);I(this,"_isForceKeepVisible",!1);I(this,"_editorIsDirty",!1);I(this,"_visible",{visible:!1,eventType:b.DeviceInputEventType.Dblclick});I(this,"_currentEditCell",null);I(this,"_currentEditCellState",null);I(this,"_currentEditCellState$",new H.BehaviorSubject(null));I(this,"currentEditCellState$",this._currentEditCellState$.asObservable());I(this,"_visible$",new H.BehaviorSubject(this._visible));I(this,"visible$",this._visible$.asObservable());I(this,"_afterVisible$",new H.BehaviorSubject(this._visible));I(this,"afterVisible$",this._afterVisible$.asObservable());I(this,"interceptor",new l.InterceptorManager({BEFORE_CELL_EDIT:ba,AFTER_CELL_EDIT:wa}));this._sheetSkeletonManagerService=e,this._selectionRenderService=n,this._themeService=o,this._currentUniverService=r,this._editorService=s,this.disposeWithMe(l.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:a=>a}))),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:a=>a})))}refreshEditCellState(){const e=this.getLatestEditCellState();this._currentEditCellState=e,this._currentEditCellState$.next(e)}setEditCell(e){this._currentEditCell=e;const n=this.getLatestEditCellState();this._currentEditCellState=n,this._currentEditCellState$.next(n)}getEditCellState(){return this._currentEditCellState}getLatestEditCellState(){var V,j;const e=this._currentEditCell;if(e==null)return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null)return;const{skeleton:o}=n,{primary:r,unitId:s,sheetId:a,scene:c,engine:d}=e,{startRow:u,startColumn:h}=r,m=this._selectionRenderService.convertCellRangeToInfo(r);if(m==null)return;const g=l.makeCellToSelection(m);if(g==null)return;const S=b.getCanvasOffsetByEngine(d);let{startX:f,startY:C,endX:R,endY:M}=g;const{scaleX:w,scaleY:E}=c.getAncestorScale(),{scaleX:T,scaleY:O}=c.getPrecisionScale(),y=c.getScrollXY(this._selectionRenderService.getViewPort());f=b.fixLineWidthByScale(o.convertTransformToOffsetX(f,w,y),T),C=b.fixLineWidthByScale(o.convertTransformToOffsetY(C,E,y),O),R=b.fixLineWidthByScale(o.convertTransformToOffsetX(R,w,y),T),M=b.fixLineWidthByScale(o.convertTransformToOffsetY(M,E,y),O);const x=this._currentUniverService.getCurrentUniverSheetInstance(),A=x.getActiveSheet(),k={workbook:x,worksheet:A,unitId:x.getUnitId(),subUnitId:A.getSheetId(),row:u,col:h},L=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(A.getCell(u,h),k);let F=L&&o.getCellDocumentModelWithFormula(L);if(!F||F.documentModel==null){const $=o.getBlankCellDocumentModel(L);if(F!=null){const{verticalAlign:Z,horizontalAlign:W,wrapStrategy:G,textRotation:ne,fill:D}=F,{centerAngle:U,vertexAngle:z}=b.convertTextRotation(ne);$.documentModel.documentStyle.renderConfig={verticalAlign:Z,horizontalAlign:W,wrapStrategy:G,background:{rgb:D},centerAngle:U,vertexAngle:z}}F=$}if((V=F.documentModel)==null||V.setZoomRatio(Math.max(w,E)),(L==null?void 0:L.isInArrayFormulaRange)===!0){const $=(j=F.documentModel)==null?void 0:j.getBody();$&&($.textRuns=[{st:0,ed:$.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return this._editorService.setOperationSheetUnitId(s),this._editorService.setOperationSheetSubUnitId(a),{position:{startX:f,startY:C,endX:R,endY:M},scaleX:w,scaleY:E,canvasOffset:S,row:u,column:h,unitId:s,sheetId:a,documentLayoutObject:F,editorUnitId:this._editorUnitId,isInArrayFormulaRange:L==null?void 0:L.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visible=e,e.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(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=Ma([Pt(0,N.Inject(exports.SheetSkeletonManagerService)),Pt(1,fe),Pt(2,N.Inject(l.ThemeService)),Pt(3,l.IUniverInstanceService),Pt(4,v.IEditorService)],exports.EditorBridgeService);const Ee=N.createIdentifier("univer.sheet-editor-bridge.service"),Pe={id:"sheet.operation.set-cell-edit-visible",type:l.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(Ee);return t==null?!1:(e.changeVisible(t),!0)}},Gt={id:"sheet.operation.set-cell-edit-visible-arrow",type:l.CommandType.OPERATION,handler:()=>!0};class Qe{constructor(){I(this,"_scrollInfo",new Map);I(this,"_currentScroll",null);I(this,"_scrollInfo$",new H.BehaviorSubject(null));I(this,"scrollInfo$",this._scrollInfo$.asObservable())}dispose(){this._scrollInfo$.complete()}setCurrentScroll(t){this._currentScroll=t,this._refresh(t)}getScrollByParam(t){return this._getCurrentScroll(t)}getCurrentScroll(){return this._getCurrentScroll(this._currentScroll)}addOrReplace(t){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...t})}addOrReplaceNoRefresh(t){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...t},!1)}addOrReplaceByParam(t){this._addByParam(t)}clear(){this._currentScroll!=null&&this._clearByParam(this._currentScroll)}_addByParam(t,e=!0){const{unitId:n,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:a,offsetY:c}=t;this._scrollInfo.has(n)||this._scrollInfo.set(n,new Map),this._scrollInfo.get(n).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:a,offsetY:c}),e===!0&&this._refresh({unitId:n,sheetId:o})}_clearByParam(t){this._addByParam({...t,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._refresh(t)}_getCurrentScroll(t){var o;if(t==null)return;const{unitId:e,sheetId:n}=t;return(o=this._scrollInfo.get(e))==null?void 0:o.get(n)}_refresh(t){this._scrollInfo$.next(this._getCurrentScroll(t))}}const bt={id:"sheet.operation.set-scroll",type:l.CommandType.OPERATION,handler:(i,t)=>{if(t==null)return!1;const e=i.get(Qe),r=i.get(l.IUniverInstanceService).getUniverSheetInstance(t.unitId).getSheetBySheetId(t.sheetId),{xSplit:s,ySplit:a}=r.getConfig().freeze;return e.addOrReplaceByParam({...t,sheetViewStartRow:t.sheetViewStartRow-a,sheetViewStartColumn:t.sheetViewStartColumn-s}),!0}},Ye={id:"sheet.operation.set-zoom-ratio",type:l.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(l.IUniverInstanceService).getUniverSheetInstance(t.unitId),n=e==null?void 0:e.getSheetBySheetId(t.subUnitId);return n==null?!1:(n.getConfig().zoomRatio=t.zoomRatio,!0)}};var lr={exports:{}},Yn={};/**
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 Oa=H,xa=Symbol.for("react.element"),Aa=Symbol.for("react.fragment"),Na=Object.prototype.hasOwnProperty,Da=Oa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Pa={key:!0,ref:!0,__self:!0,__source:!0};function mr(i,e,t){var n,o={},r=null,s=null;t!==void 0&&(r=""+t),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Na.call(e,n)&&!Pa.hasOwnProperty(n)&&(o[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:xa,type:i,key:r,ref:s,props:o,_owner:Da.current}}Zn.Fragment=Aa;Zn.jsx=mr;Zn.jsxs=mr;hr.exports=Zn;var p=hr.exports,Me=function(){return Me=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},Me.apply(this,arguments)},Ha=function(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(i);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(i,n[o])&&(t[n[o]]=i[n[o]]);return t},Ie=H.forwardRef(function(i,e){var t=i.icon,n=i.id,o=i.className,r=i.extend,s=Ha(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),c=H.useRef("_".concat(ka()));return gr(t,"".concat(n),{defIds:t.defIds,idSuffix:c.current},Me({ref:e,className:a},s),r)});function gr(i,e,t,n,o){return H.createElement(i.tag,Me(Me({key:e},La(i,t,o)),n),(Ua(i,t).children||[]).map(function(r,s){return gr(r,"".concat(e,"-").concat(i.tag,"-").concat(s),t,void 0,o)}))}function La(i,e,t){var n=Me({},i.attrs);t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1);var o=e.defIds;return!o||o.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(r){var s=r[0],a=r[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Ua(i,e){var t,n=e.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?Me(Me({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.indexOf(o.attrs.id)>-1?Me(Me({},o),{attrs:Me(Me({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):i}function ka(){return Math.random().toString(36).substring(2,8)}Ie.displayName="UniverIcon";var Va={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"}}]},_r=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"autofill",ref:e,icon:Va}))});_r.displayName="Autofill";const Ba=_r;var Fa={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"}}]},Sr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"check-mark-single",ref:e,icon:Fa}))});Sr.displayName="CheckMarkSingle";const Wn=Sr;var Wa={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"}}]},fr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"close-single",ref:e,icon:Wa}))});fr.displayName="CloseSingle";const ja=fr;var $a={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"}}]}]},pr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"convert-single",ref:e,icon:$a}))});pr.displayName="ConvertSingle";const za=pr;var Ya={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"}}]}]},vr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"dropdown-single",ref:e,icon:Ya}))});vr.displayName="DropdownSingle";const Io=vr;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"}}]},Cr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"eyelash-single",ref:e,icon:Xa}))});Cr.displayName="EyelashSingle";const Za=Cr;var Ga={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"}}]}]},Ir=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"fx-single",ref:e,icon:Ga}))});Ir.displayName="FxSingle";const Ka=Ir;var qa={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"}}]}]},Rr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"increase-single",ref:e,icon:qa}))});Rr.displayName="IncreaseSingle";const Ja=Rr;var Qa={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"}}]}]},Mr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"more-down-single",ref:e,icon:Qa}))});Mr.displayName="MoreDownSingle";const Mi=Mr;var el={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"}}]},br=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"more-single",ref:e,icon:el}))});br.displayName="MoreSingle";const Ro=br;var tl={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"}}]}]},wr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"paint-bucket",ref:e,icon:tl}))});wr.displayName="PaintBucket";const nl=wr;var il={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"}}]},Tr=H.forwardRef(function(i,e){return H.createElement(Ie,Object.assign({},i,{id:"select-range-single",ref:e,icon:il}))});Tr.displayName="SelectRangeSingle";const ol=Tr,rl="univer-range-selector",sl="univer-range-selector-editor",al="univer-range-selector-icon",ll="univer-range-selector-active",tt={rangeSelector:rl,rangeSelectorEditor:sl,rangeSelectorIcon:al,rangeSelectorActive:ll};function cl(i){const{onChange:e,onActive:t}=i,[n,o]=H.useState(!1),r=H.useRef(null),s=q.useDependency(l.LocaleService),a=q.useDependency(S.SelectionManagerService);H.useEffect(()=>{var m;if(n){t(n);const g=a.selectionMoveEnd$.subscribe(_=>{const f=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],v=Math.floor(Math.random()*f.length),R=f[v];r.current&&(r.current.innerHTML=R)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),g.unsubscribe()}}e(((m=r.current)==null?void 0:m.innerHTML)||"")},[n]);function c(m){var v,R,M;if(((v=m.target)==null?void 0:v.closest('[data-range-selector="true"]'))||m.target===r.current)return;const _=(R=m.target)==null?void 0:R.closest(`.${tt.rangeSelector}`);(_==null?void 0:_.querySelector(`.${tt.rangeSelectorEditor}`))!==r.current&&(o(!1),(M=r.current)==null||M.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(!n){(m=r.current)==null||m.focus();return}o(!n)}return p.jsxs("div",{className:n?`${tt.rangeSelector} ${tt.rangeSelectorActive}`:tt.rangeSelector,children:[p.jsx("div",{ref:r,className:tt.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(ge.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:tt.rangeSelectorIcon,onClick:h,children:p.jsx(ol,{})})})]})}var St=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(St||{}),de=(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))(de||{}),oe=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(oe||{});const dl={type:de.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===l.CellValueType.NUMBER,isContinue:(i,e)=>i.type===de.NUMBER,applyFunctions:{[oe.SERIES]:(i,e,t)=>{const{data:n}=i;return t===l.Direction.LEFT||t===l.Direction.UP?(n.reverse(),oo(n,e,t).reverse()):oo(n,e,t)}}},Er={type:de.OTHER,priority:0,match:()=>!0,isContinue:(i,e)=>i.type===de.OTHER},ul={type:de.EXTEND_NUMBER,priority:900,match:i=>rn(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,e)=>{var t;if(i.type===de.EXTEND_NUMBER){const{beforeTxt:n,afterTxt:o}=rn(`${(t=i.cellData)==null?void 0:t.v}`||""),{beforeTxt:r,afterTxt:s}=rn(`${e==null?void 0:e.v}`||"");if(n===r&&o===s)return!0}return!1},applyFunctions:{[oe.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.UP||t===l.Direction.LEFT;let r;if(n.length===1)return r=o?-1:1,be(ro(n,e,r),o);const s=[];for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;d&&s.push(Number(rn(d).matchTxt))}return o&&(n.reverse(),s.reverse()),Kt(s)?(r=s[1]-s[0],be(ro(n,e,r),o)):at(n,e)}}},hl={type:de.CHN_NUMBER,priority:830,match:i=>!!us(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===de.CHN_NUMBER,applyFunctions:{[oe.SERIES]:(i,e,t)=>{var c,d,u;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){const h=`${(c=n[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||$e(h)<7)?be(It(n,e,m),o):be(so(n,e,m),o)}let r=!1;for(let h=0;h<n.length;h++)if(((d=n[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let a=0;for(let h=0;h<n.length;h++){const m=`${(u=n[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(a++,s.push(a*7)):r&&$e(m)>0&&$e(m)<7?s.push($e(m)+a*7):s.push($e(m))}if(o&&(n.reverse(),s.reverse()),Kt(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 be(It(n,e,m),o)}const h=s[1]-s[0];return be(so(n,e,h),o)}return at(n,e)}}},ml={type:de.CHN_WEEK2,priority:820,match:i=>!!hs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===de.CHN_WEEK2,applyFunctions:{[oe.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,be(It(n,e,c,1),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.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($e(u)+s*7)}if(o&&(n.reverse(),r.reverse()),Kt(r)){const c=r[1]-r[0];return be(It(n,e,c,1),o)}return at(n,e)}}},gl={type:de.CHN_WEEK3,priority:810,match:i=>ms(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===de.CHN_WEEK3,applyFunctions:{[oe.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,be(It(n,e,c,2),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push($e(u)+s*7)}}if(o&&(n.reverse(),r.reverse()),Kt(r)){const c=r[1]-r[0];return be(It(n,e,c,2),o)}return at(n,e)}}},_l={type:de.LOOP_SERIES,priority:800,match:i=>Cs(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>{var t;return i.type===de.LOOP_SERIES?ri(`${(t=i.cellData)==null?void 0:t.v}`||"").name===ri(`${e==null?void 0:e.v}`||"").name:!1},applyFunctions:{[oe.SERIES]:(i,e,t)=>{var c,d;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP,{series:r}=ri(`${(c=n[0])==null?void 0:c.v}`||"");if(n.length===1){let u;return o?u=-1:u=1,be(ao(n,e,u,r),o)}const s=[];let a=0;for(let u=0;u<n.length;u++){const h=`${(d=n[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(a++,s.push(a*r.length)):s.push(r.indexOf(h)+a*7))}if(o&&(n.reverse(),s.reverse()),Kt(s)){const u=s[1]-s[0];return be(ao(n,e,u,r),o)}return at(n,e)}}};function be(i,e){return e?i.reverse():i}var Sl=Object.defineProperty,fl=Object.getOwnPropertyDescriptor,pl=(i,e,t,n)=>{for(var o=n>1?void 0:n?fl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Sl(e,t,o),o},ai=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillService=class extends l.Disposable{constructor(t,n,o){super();C(this,"_rules",[]);C(this,"_hooks",[]);C(this,"_applyType$",new D.BehaviorSubject(oe.SERIES));C(this,"_isFillingStyle",!0);C(this,"_autoFillLocation$",new D.BehaviorSubject(null));C(this,"autoFillLocation$",this._autoFillLocation$.asObservable());C(this,"_showMenu$",new D.BehaviorSubject(!1));C(this,"showMenu$",this._showMenu$.asObservable());C(this,"_direction",l.Direction.DOWN);C(this,"applyType$",this._applyType$.asObservable());C(this,"_menu$",new D.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=t,this._univerInstanceService=n,this._selectionManagerService=o,this._init()}_init(){this._rules=[dl,ul,hl,ml,gl,_l,Er].sort((t,n)=>n.priority-t.priority),this._isFillingStyle=!0}getOneByPriority(t){return t.length<=0?[]:[t.reduce((o,r)=>(r.priority||0)>(o.priority||0)?r:o,t[0])]}addHook(t){if(this._hooks.find(n=>n.id===t.id))throw new Error(`Add hook failed, hook id '${t.id}' already exist!`);return t.priority===void 0&&(t.priority=0),t.type===void 0&&(t.type=St.Append),this._hooks.push(t),l.toDisposable(()=>{const n=this._hooks.findIndex(o=>o===t);n>-1&&this._hooks.splice(n,1)})}registerRule(t){if(this._rules.find(o=>o.type===t.type))throw new Error(`Registry rule failed, type '${t.type}' already exist!`);const n=this._rules.findIndex(o=>o.priority<t.priority);this._rules.splice(n===-1?this._rules.length:n,0,t)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:t,target:n,unitId:o,subUnitId:r}=this.autoFillLocation||{};if(!t||!n||!o||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:t,target:n,unitId:o,subUnitId:r},this._direction,this.applyType))}),a=s.filter(u=>u.type===St.Only);if(a.length>0)return this.getOneByPriority(a);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(t){this._applyType$.next(t)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(t){this._direction=t}isFillingStyle(){return this._isFillingStyle}setFillingStyle(t){this._isFillingStyle=t}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(t){this._autoFillLocation$.next(t)}setDisableApplyType(t,n){this._menu$.next(this._menu$.getValue().map(o=>o.value===t?{...o,disable:n}:o))}setShowMenu(t){this._showMenu$.next(t)}};exports.AutoFillService=pl([l.OnLifecycle(l.LifecycleStages.Rendered,exports.AutoFillService),ai(0,N.Inject(S.SheetInterceptorService)),ai(1,N.Inject(l.IUniverInstanceService)),ai(2,N.Inject(S.SelectionManagerService))],exports.AutoFillService);const Jt=N.createIdentifier("univer.auto-fill-service");var vl=Object.defineProperty,Cl=Object.getOwnPropertyDescriptor,Il=(i,e,t,n)=>{for(var o=n>1?void 0:n?Cl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&vl(e,t,o),o},Fe=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillController=class extends l.Disposable{constructor(t,n,o,r,s,a,c,d,u){super();C(this,"_beforeApplyData",[]);C(this,"_copyData",[]);C(this,"_defaultHook");this._univerInstanceService=t,this._selectionRenderService=n,this._commandService=o,this._undoRedoService=r,this._autoFillService=s,this._editorBridgeService=a,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,g)=>this._fillData(h,m,g)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[Ko,un].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initDefaultHook(){this._autoFillService.addHook(this._defaultHook)}_onSelectionControlFillChanged(){const t=new l.DisposableCollection;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==S.SetSelectionsOperation.id)return;const o=this._selectionManagerService.getCurrent();if((o==null?void 0:o.pluginName)!==S.NORMAL_SELECTION_PLUGIN_NAME)return;t.dispose(),this._selectionRenderService.getCurrentControls().forEach(s=>{t.add(l.toDisposable(s.selectionFilled$.subscribe(a=>{if(a==null||a.startColumn===-1||a.startRow===-1||a.endColumn===-1||a.endRow===-1)return;const c={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow},d={startColumn:a.startColumn,endColumn:a.endColumn,startRow:a.startRow,endRow:a.endRow};this._triggerAutoFill(c,d)}))),t.add(l.toDisposable(s.fillControl.onDblclickObserver.add(()=>{const a={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow};this._handleDbClickFill(a)}))),t.add(l.toDisposable(s.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})})))})}))}_onApplyTypeChanged(){this.disposeWithMe(l.toDisposable(this._autoFillService.applyType$.subscribe(()=>{this._handleFillData()})))}_triggerAutoFill(t,n){var d;if(t.startColumn===n.startColumn&&t.startRow===n.startRow&&t.endColumn===n.endColumn&&t.endRow===n.endRow)return;if(n.endColumn<t.endColumn&&n.endColumn>t.startColumn){this._commandService.executeCommand(un.id,{clearRange:{startRow:n.startRow,endRow:n.endRow,startColumn:n.endColumn+1,endColumn:t.endColumn},selectionRange:n});return}if(n.endRow<t.endRow&&n.endRow>t.startRow){this._commandService.executeCommand(un.id,{clearRange:{startRow:n.endRow+1,endRow:t.endRow,startColumn:n.startColumn,endColumn:n.endColumn},selectionRange:n});return}const o={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn};let r=null;if(n.startRow<t.startRow)r=l.Direction.UP,o.endRow=t.startRow-1;else if(n.endRow>t.endRow)r=l.Direction.DOWN,o.startRow=t.endRow+1;else if(n.startColumn<t.startColumn)r=l.Direction.LEFT,o.endColumn=t.startColumn-1;else if(n.endColumn>t.endColumn)r=l.Direction.RIGHT,o.startColumn=t.endColumn+1;else return;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),a=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._autoFillService.direction=r,this._autoFillService.autoFillLocation={source:t,target:o,unitId:s,subUnitId:a},this._autoFillService.getActiveHooks().forEach(u=>{var h;(h=u==null?void 0:u.onBeforeFillData)==null||h.call(u,{source:t,target:o,unitId:s,subUnitId:a},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(t){const n=this._detectFillRange(t);n.endRow<=t.endRow||this._triggerAutoFill(t,n)}_detectFillRange(t){var m,g,_,f,v,R;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,a=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!a)return t;const c=a.getCellMatrix(),d=a.getMaxRows()-1,u=a.getMaxColumns()-1;let h=o;if(r>0&&((g=c.getValue(n,r-1))==null?void 0:g.v)!=null){let M=n;for(;((_=c.getValue(M,r-1))==null?void 0:_.v)!=null&&M<d;)M+=1;h=M-1}else if(s<u&&((f=c.getValue(o,s+1))==null?void 0:f.v)!=null){let M=n;for(;((v=c.getValue(M,s+1))==null?void 0:v.v)!=null&&M<d;)M+=1;h=M-1}for(let M=o+1;M<=h;M++)for(let T=r;T<=s;T++)if(((R=c.getValue(M,T))==null?void 0:R.v)!=null){h=M-1;break}return{startColumn:r,endColumn:s,startRow:n,endRow:h}}_handleFillData(){const{source:t,target:n,unitId:o=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:r=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=this._autoFillService.autoFillLocation||{},s=this._autoFillService.direction;if(!t||!n)return;const a=l.Rectangle.union(t,n),c=this._autoFillService.applyType,d=this._autoFillService.getActiveHooks();this._commandService.syncExecuteCommand(S.SetSelectionsOperation.id,{selections:[{primary:{...a,actualRow:a.startRow,actualColumn:a.startColumn,endColumn:a.startColumn,endRow:a.startRow},range:{...a,rangeType:l.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:r});const u=[],h=[];d.forEach(g=>{var v;const{undos:_,redos:f}=((v=g.onFillData)==null?void 0:v.call(g,{source:t,target:n,unitId:o,subUnitId:r},s,c))||{};_&&u.push(..._),f&&h.push(...f)}),h.every(g=>this._commandService.syncExecuteCommand(g.id,g.params))&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:u,redoMutations:h}),d.forEach(g=>{var _;(_=g.onAfterFillData)==null||_.call(g,{source:t,target:n,unitId:o,subUnitId:r},s,c)}),this._autoFillService.setShowMenu(!0)}_getApplyData(t,n,o,r,s,a=!0){const c=[],d=Math.floor(o/n),u=o%n,h=this._autoFillService.getRules();if(!a&&s===oe.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(g=>{m[g.type]=[]}),h.forEach(g=>{const{type:_,applyFunctions:f={}}=g,v=t[_];v&&v.forEach(R=>{const M=gs(R.index,u),T=R.index.length*d+M,E=this._applyFunctions(R,T,r,s,f,t),w=_s(n,o,R.index);m[_].push({data:E,index:w})})});for(let g=0;g<o;g++)h.forEach(_=>{const{type:f}=_,v=m[f];for(let R=0;R<v.length;R++)g in v[R].index&&c.push(v[R].data[v[R].index[g]])});return c}_applyFunctions(t,n,o,r,s,a){const{data:c}=t,d=o===l.Direction.UP||o===l.Direction.LEFT;if(r===oe.COPY){const u=s==null?void 0:s[oe.COPY];return u?u(t,n,o,a):(d&&c.reverse(),at(c,n))}if(r===oe.SERIES){const u=s==null?void 0:s[oe.SERIES];return u?u(t,n,o,a):(d&&c.reverse(),s!=null&&s[oe.COPY]?s[oe.COPY](t,n,o,a):at(c,n))}if(r===oe.ONLY_FORMAT){const u=s==null?void 0:s[oe.ONLY_FORMAT];return u?u(t,n,o,a):Ss(c,n)}}_getCopyData(t,n){const{startRow:o,startColumn:r,endRow:s,endColumn:a}=t,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=n===l.Direction.DOWN||n===l.Direction.UP;let m,g,_,f;h?(m=r,g=a,_=o,f=s):(m=o,g=s,_=r,f=a);for(let v=m;v<=g;v++){const R=this._getEmptyCopyDataPiece(),M={type:void 0,cellData:void 0};for(let T=_;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))||Er;if(y(M,E)){const O=R[w],x=O[O.length-1];x.data.push(E),x.index.push(T-_)}else{const O=R[w];O?O.push({data:[E],index:[T-_]}):R[w]=[{data:[E],index:[T-_]}]}M.type=w,M.cellData=E}u.push(R)}return u}_getEmptyCopyDataPiece(){const t={};return this._autoFillService.getRules().forEach(n=>{t[n.type]=[]}),t}_getMergeApplyData(t,n,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),a=[];for(let c=t.startRow;c<=t.endRow;c++)for(let d=t.startColumn;d<=t.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:g,endColumn:_}=b.getCellInfoInMergeData(c,d,s);if(u){if(o===l.Direction.DOWN){let f=h+r,v=g+r;for(;v<=n.endRow;)a.push({startRow:f,startColumn:m,endRow:v,endColumn:_}),f+=r,v+=r}else if(o===l.Direction.UP){let f=h-r,v=g-r;for(;f>=n.startRow;)a.push({startRow:f,startColumn:m,endRow:v,endColumn:_}),f-=r,v-=r}else if(o===l.Direction.RIGHT){let f=m+r,v=_+r;for(;v<=n.endColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:v}),f+=r,v+=r}else if(o===l.Direction.LEFT){let f=m-r,v=_-r;for(;f>=n.startColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:v}),f-=r,v-=r}}}return a}_presetAndCacheData(t,n){const{source:o,target:r}=t,s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),a=[];for(let c=r.startRow;c<=r.endRow;c++){const d=[];for(let u=r.startColumn;u<=r.endColumn;u++)d.push(l.Tools.deepClone(s.getValue(c,u)));a.push(d)}this._beforeApplyData=a,this._copyData=this._getCopyData(o,n),this._hasSeries(this._copyData)?this._autoFillService.setDisableApplyType(oe.SERIES,!1):this._autoFillService.setDisableApplyType(oe.SERIES,!0)}_fillData(t,n,o){var ee,ie;const r=[],s=[];let a=!0;o===oe.NO_FORMAT&&(a=!1,o=oe.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=t;if(!c||!d||n==null)return{undos:r,redos:s};const{startRow:m,startColumn:g,endRow:_,endColumn:f}=c,{startRow:v,startColumn:R,endRow:M,endColumn:T}=d,E=this._copyData;let w;n===l.Direction.DOWN||n===l.Direction.UP?w=_-m+1:w=f-g+1;const y=[];if(n===l.Direction.DOWN||n===l.Direction.UP){const z=M-v+1,Z=[];for(let K=R;K<=T;K++){const le=E[K-R],se=this._getApplyData(le,w,z,n,o,a);Z.push(se)}for(let K=0;K<Z[0].length;K++){const le=[];for(let se=0;se<Z.length;se++)le.push({s:null,...Z[se][K]});y.push(le)}}else{const z=T-R+1;for(let Z=v;Z<=M;Z++){const K=E[Z-v],le=this._getApplyData(K,w,z,n,o,a),se=[];for(let me=0;me<le.length;me++)se.push({s:null,...le[me]});y.push(se)}}let O=[];const x=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();a?(O=this._getMergeApplyData(c,d,n,w),y.forEach(z=>{z.forEach(Z=>{Z&&x&&x&&(Z.s=x.getStyleByCell(Z))})})):y.forEach((z,Z)=>{z.forEach((K,le)=>{K&&x&&(K.s=x.getStyleByCell(this._beforeApplyData[Z][le])||null)})}),o===oe.ONLY_FORMAT&&y.forEach((z,Z)=>{z.forEach((K,le)=>{if(K){const se=this._beforeApplyData[Z][le]||{};K.f=se.f,K.si=se.si,K.t=se.t,K.v=se.v}})});const A={get:this._injector.get.bind(this._injector)},B=[],P=(ie=(ee=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:ee.getSheetBySheetId(h))==null?void 0:ie.getMergeData();P&&P.forEach(z=>{l.Rectangle.intersects(z,d)&&B.push(z)});const F={unitId:u,subUnitId:h,ranges:B},k=S.RemoveMergeUndoMutationFactory(A,F);s.push({id:S.RemoveWorksheetMergeMutation.id,params:F}),r.push({id:S.AddWorksheetMergeMutation.id,params:k});const j={subUnitId:h,unitId:u,cellValue:Go([d])},$=S.SetRangeValuesUndoMutationFactory(A,j),G=this._sheetInterceptorService.onCommandExecute({id:S.ClearSelectionContentCommand.id});s.push({id:S.SetRangeValuesMutation.id,params:j},...G.redos),r.push(...G.undos,{id:S.SetRangeValuesMutation.id,params:$});const W=new l.ObjectMatrix,{startRow:J,startColumn:re,endRow:Y,endColumn:U}=d;for(let z=0;z<=Y-J;z++)for(let Z=0;Z<=U-re;Z++)y[z][Z]&&W.setValue(z+J,Z+re,y[z][Z]);const L={subUnitId:h,unitId:u,cellValue:W.getMatrix()},X=S.SetRangeValuesUndoMutationFactory(A,L);if(r.push({id:S.SetRangeValuesMutation.id,params:X}),s.push({id:S.SetRangeValuesMutation.id,params:L}),O!=null&&O.length){const z=S.getAddMergeMutationRangeByType(O),Z={unitId:u,subUnitId:h,ranges:z},K=S.AddMergeUndoMutationFactory(A,Z);r.push({id:S.RemoveWorksheetMergeMutation.id,params:K}),s.push({id:S.AddWorksheetMergeMutation.id,params:Z})}return{undos:r,redos:s}}_hasSeries(t){return t.some(n=>Object.keys(n).some(r=>{var s;return!!((s=n[r])!=null&&s.length&&![de.OTHER,de.FORMULA].includes(r))}))}};exports.AutoFillController=Il([l.OnLifecycle(l.LifecycleStages.Steady,exports.AutoFillController),Fe(0,l.IUniverInstanceService),Fe(1,_e),Fe(2,l.ICommandService),Fe(3,l.IUndoRedoService),Fe(4,Jt),Fe(5,Te),Fe(6,N.Inject(S.SheetInterceptorService)),Fe(7,N.Inject(S.SelectionManagerService)),Fe(8,N.Inject(N.Injector))],exports.AutoFillController);const yr={id:"sheet.command.hide-row-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const t=(c=i.get(S.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(t!=null&&t.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(cr(a,t)){const d=i.get(I.IConfirmService),u=i.get(l.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 n.executeCommand(S.SetRowHiddenCommand.id),!0}},Or={id:"sheet.command.hide-col-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const t=(c=i.get(S.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(t!=null&&t.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(dr(a,t)){const d=i.get(I.IConfirmService),u=i.get(l.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 n.executeCommand(S.SetColHiddenCommand.id),!0}},Ui={type:l.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatBoldCommand.id):e.executeCommand(S.SetBoldCommand.id)}},ki={type:l.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatItalicCommand.id):e.executeCommand(S.SetItalicCommand.id)}},Vi={type:l.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatUnderlineCommand.id):e.executeCommand(S.SetUnderlineCommand.id)}},Bi={type:l.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatStrikethroughCommand.id):e.executeCommand(S.SetStrikeThroughCommand.id)}},Rl={type:l.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatSubscriptCommand.id):!1}},Ml={type:l.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(Q.SetInlineFormatSuperscriptCommand.id):!1}},xr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(Q.SetInlineFormatFontSizeCommand.id,e):t.executeCommand(S.SetFontSizeCommand.id,e)}},Ar={type:l.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(Q.SetInlineFormatFontFamilyCommand.id,e):t.executeCommand(S.SetFontFamilyCommand.id,e)}},jn={type:l.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(Q.SetInlineFormatTextColorCommand.id,e):t.executeCommand(S.SetTextColorCommand.id,e)}};function Nr(i,e){return e.some(t=>bl(i,t))}function bl(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o);let a=!1;return s.forValue((c,d,u)=>{if(u&&(c!==t||d!==n)&&i.cellHasValue(u))return a=!0,!1}),a}function Dr(i,e,t,n){const o=[],r=[],s=t.getSheetId();return n.forEach(a=>{const c=wl(t,a),d={unitId:e,subUnitId:s,cellValue:c.getData()},u=S.SetRangeValuesUndoMutationFactory(i,d);o.push({id:S.SetRangeValuesMutation.id,params:u}),r.push({id:S.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function wl(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o),a=new l.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==t||d!==n)&&a.setValue(c,d,null)}),a}var Tl=Object.defineProperty,El=Object.getOwnPropertyDescriptor,yl=(i,e,t,n)=>{for(var o=n>1?void 0:n?El(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Tl(e,t,o),o},li=(i,e)=>(t,n)=>e(t,n,i),Oe=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(Oe||{});const Tt=N.createIdentifier("univer.format-painter-service");let bi=class extends l.Disposable{constructor(e,t,n){super();C(this,"status$");C(this,"_selectionFormat");C(this,"_markId",null);C(this,"_status$");this._selectionManagerService=e,this._univerInstanceService=t,this._markSelectionService=n,this._status$=new D.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new l.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 t=this._selectionManagerService.getLast();if(t){const n=this._selectionManagerService.createCopyPasteSelection();e===2?this._markId=this._markSelectionService.addShape({...t,style:n}):this._markId=this._markSelectionService.addShape({...t,style:n},[S.SetRangeValuesMutation.id])}}}_getSelectionRangeFormat(){const e=this._selectionManagerService.getLast(),t=e==null?void 0:e.range;if(!t)return;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,a=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(a==null?void 0:a.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=a.getStyles(),m=new l.ObjectMatrix;for(let g=n;g<=o;g++)for(let _=r;_<=s;_++){const f=d.getValue(g,_);m.setValue(g,_,h.getStyleByCell(f)||{});const{isMergedMainCell:v,...R}=b.getCellInfoInMergeData(g,_,u);v&&this._selectionFormat.merges.push({startRow:R.startRow,startColumn:R.startColumn,endRow:R.endRow,endColumn:R.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};bi=yl([li(0,N.Inject(S.SelectionManagerService)),li(1,l.IUniverInstanceService),li(2,qt)],bi);const Fi={id:"sheet.operation.set-format-painter",type:l.CommandType.OPERATION,handler:(i,e)=>e?(i.get(Tt).setStatus(e.status),!0):!1},Pr={type:l.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const t=i.get(Tt).getStatus();let n;return t!==Oe.OFF?n=Oe.OFF:n=Oe.INFINITE,i.get(l.ICommandService).executeCommand(Fi.id,{status:n})}},Wi={type:l.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const t=i.get(Tt).getStatus();let n;return t!==Oe.OFF?n=Oe.OFF:n=Oe.ONCE,i.get(l.ICommandService).executeCommand(Fi.id,{status:n})}},Hr={type:l.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,e)=>{const t=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(S.SelectionManagerService),s=i.get(S.SheetInterceptorService),{styleValues:a,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 g=new l.ObjectMatrix;let _;if(l.Tools.isArray(a))for(let j=0;j<m.length;j++){const{startRow:$,startColumn:G,endRow:W,endColumn:J}=m[j];for(let re=0;re<=W-$;re++)for(let Y=0;Y<=J-G;Y++)g.setValue(re+$,Y+G,a[re][Y])}else if(l.isICellData(a))for(let j=0;j<m.length;j++){const{startRow:$,startColumn:G}=m[j];g.setValue($,G,a)}else _=a;const f={subUnitId:h,unitId:u,cellValue:_!=null?_:g.getMatrix()},v=S.SetRangeValuesUndoMutationFactory(i,f);if(!s.fetchThroughInterceptors(S.INTERCEPTOR_POINT.PERMISSION)(null,{id:S.SetRangeValuesCommand.id,params:f}))return!1;const R=t.syncExecuteCommand(S.SetRangeValuesMutation.id,f),{undos:M,redos:T}=s.onCommandExecute({id:S.SetRangeValuesCommand.id,params:{...f,range:m}}),E=S.getAddMergeMutationRangeByType(d),w=o.getUniverSheetInstance(u).getSheetBySheetId(h),y=[],O=[],x=Nr(w,E),A={unitId:u,subUnitId:h,ranges:E},B={unitId:u,subUnitId:h,ranges:E};y.push({id:S.RemoveWorksheetMergeMutation.id,params:A}),y.push({id:S.AddWorksheetMergeMutation.id,params:B});const P=S.RemoveMergeUndoMutationFactory(i,A),F=S.AddMergeUndoMutationFactory(i,B);if(O.push({id:S.RemoveWorksheetMergeMutation.id,params:F}),O.push({id:S.AddWorksheetMergeMutation.id,params:P}),x){const j=Dr(i,u,w,E);y.unshift(...j.redos),O.push(...j.undos)}const k=await l.sequenceExecute([...T,...y],t);return R&&k.result?(n.pushUndoRedo({unitID:u,undoMutations:[{id:S.SetRangeValuesMutation.id,params:v},...M,...O],redoMutations:[{id:S.SetRangeValuesMutation.id,params:f},...T,...y]}),!0):!1}},Gn={type:l.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,e)=>{const{type:t}=e||{},n=i.get(l.IUniverInstanceService),o=i.get(l.IUndoRedoService),r=n.getCurrentUniverSheetInstance().getUnitId(),s=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),a=i.get(l.ICommandService),d=i.get(S.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(Je),{sheetViewStartRow:g=0,sheetViewStartColumn:_=0}=m.getCurrentScroll()||{};let f,v,R,M;const{startRow:T,startColumn:E,rangeType:w}=h;if(w===l.RANGE_TYPE.ROW||t===1)f=T,R=T-g,v=-1,M=0;else if(w===l.RANGE_TYPE.COLUMN||t===2)f=-1,R=0,v=E,M=E-_;else if(w===l.RANGE_TYPE.NORMAL)f=T,R=T-g,v=E,M=E-_;else return!1;const y={unitId:r,subUnitId:s,startRow:f,startColumn:v,xSplit:v>0?Math.max(1,M):M,ySplit:f>0?Math.max(1,R):R},O=S.SetFrozenMutationFactory(i,y);return a.syncExecuteCommand(S.SetFrozenMutation.id,y)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:S.SetFrozenMutation.id,params:O}],redoMutations:[{id:S.SetFrozenMutation.id,params:y}]}),!0}},Lr={type:l.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(Gn.id,{type:1}),!0)},Ur={type:l.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(Gn.id,{type:2}),!0)},kr={type:l.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(l.IUndoRedoService),o=t.getCurrentUniverSheetInstance().getUnitId(),r=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},a=S.SetFrozenMutationFactory(i,s);return e.syncExecuteCommand(S.SetFrozenMutation.id,s)&&n.pushUndoRedo({unitID:o,undoMutations:[{id:S.SetFrozenMutation.id,params:a}],redoMutations:[{id:S.SetFrozenMutation.id,params:s}]}),!0}},Et="UI_PLUGIN_SHEETS",Kn=`${Et}_COLOR_PICKER_COMPONENT`,Vr=`${Et}_FONT_FAMILY_COMPONENT`,Br=`${Et}_FONT_FAMILY_ITEM_COMPONENT`,Fr=`${Et}_FONT_SIZE_COMPONENT`,ji=`${Et}_MENU_ITEM_INPUT_COMPONENT`,Ol="univer-sheets-ui-context-menu-input",xl="univer-sheets-ui-context-menu-input-container",Al="univer-sheets-ui-context-menu-input-number",ci={sheetsUiContextMenuInput:Ol,sheetsUiContextMenuInputContainer:xl,sheetsUiContextMenuInputNumber:Al},Nl=i=>{const{prefix:e,suffix:t,value:n,onChange:o,min:r=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=i,a=q.useDependency(l.LocaleService),[c,d]=H.useState(),u=m=>{var g;d(m==null?void 0:m.toString()),o((g=m==null?void 0:m.toString())!=null?g:"")};H.useEffect(()=>{d(n)},[n]);function h(m){m.key==="Backspace"&&m.stopPropagation()}return p.jsxs("div",{className:ci.sheetsUiContextMenuInput,children:[a.t(e),p.jsx("span",{className:ci.sheetsUiContextMenuInputContainer,onClick:m=>m.stopPropagation(),children:p.jsx(ge.InputNumber,{className:ci.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:h,onChange:u,min:r,max:s})}),a.t(t)]})};var ce=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(ce||{});function Dl(i){const e=i.get(Tt);return{id:Wi.id,subId:Pr.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 D.Observable(t=>{let n=!1;const o=e.status$.subscribe(r=>{n=r!==Oe.OFF,t.next(n)});return t.next(n),()=>{o.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}function Pl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(l.IContextService),o=i.get(S.SelectionManagerService);return{id:Ui.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[I.MenuPosition.TOOLBAR_START],disabled$:S.getCurrentSheetDisabled$(i),activated$:new D.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id){const h=(d=o.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontWeight.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);g=_==null?void 0:_.getFontWeight()}r.next(g===l.FontWeight.BOLD)}if((c===Q.SetTextSelectionsOperation.id||c===Q.SetInlineFormatCommand.id)&&n.getContextValue(l.EDITOR_ACTIVATED)&&n.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.bl;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Hl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService),o=i.get(l.IContextService);return{id:ki.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[I.MenuPosition.TOOLBAR_START],disabled$:S.getCurrentSheetDisabled$(i),activated$:new D.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontItalic.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);g=_==null?void 0:_.getFontStyle()}r.next(g===l.FontItalic.ITALIC)}if((c===Q.SetTextSelectionsOperation.id||c===Q.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.it;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Ll(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService),o=i.get(l.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$:S.getCurrentSheetDisabled$(i),activated$:new D.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);g=_==null?void 0:_.getUnderline()}r.next(!!(g&&g.s))}if((c===Q.SetTextSelectionsOperation.id||c===Q.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.ul;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Ul(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService),o=i.get(l.IContextService);return{id:Bi.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$:S.getCurrentSheetDisabled$(i),activated$:new D.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);g=_==null?void 0:_.getStrikeThrough()}r.next(!!(g&&g.s))}if((c===Q.SetTextSelectionsOperation.id||c===Q.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.st;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function kl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService);return{id:Ar.id,tooltip:"toolbar.font",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,label:Vr,positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_FAMILY_LIST.map(o=>({label:{name:Br,hoverable:!0},value:o.value})),disabled$:S.getCurrentSheetDisabled$(i),value$:new D.Observable(o=>{const r=I.FONT_FAMILY_LIST[0].value,s=e.onCommandExecuted(a=>{var m;const c=a.id;if(c!==S.SetRangeValuesMutation.id&&c!==S.SetSelectionsOperation.id)return;const d=(m=n.getLast())==null?void 0:m.primary,u=t.getCurrentUniverSheetInstance().getActiveSheet();let h;if(d!=null){const g=u.getRange(d.startRow,d.startColumn);h=g==null?void 0:g.getFontFamily()}o.next(h!=null?h:r)});return o.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Vl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService),o=i.get(l.IContextService),r=S.getCurrentSheetDisabled$(i);return{id:xr.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 D.Observable(s=>{const c=e.onCommandExecuted(d=>{var h,m;const u=d.id;if(u===S.SetRangeValuesMutation.id||u===S.SetSelectionsOperation.id){const g=(h=n.getLast())==null?void 0:h.primary,_=t.getCurrentUniverSheetInstance().getActiveSheet();let f;if(g!=null){const v=_.getRange(g.startRow,g.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(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const g=en(i);if(g==null)return;const _=(m=g.ts)==null?void 0:m.fs;s.next(_!=null?_:14)}});return s.next(14),c.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Bl(i){return{id:S.ResetTextColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:jn.id,disabled$:S.getCurrentSheetDisabled$(i)}}function Fl(i){const e=i.get(l.ICommandService),t=i.get(l.ThemeService);return{id:jn.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:Kn,hoverable:!1}}],value$:new D.Observable(n=>{const o=t.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===jn.id){const a=s.params.value;n.next(a!=null?a:o)}});return n.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}function Wl(i){return{id:S.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:S.SetBackgroundColorCommand.id,disabled$:S.getCurrentSheetDisabled$(i)}}function jl(i){const e=i.get(l.ICommandService),t=i.get(l.ThemeService);return{id:S.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:Kn,hoverable:!1}}],value$:new D.Observable(n=>{const o=t.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===S.SetBackgroundColorCommand.id){const a=s.params.value;n.next(a!=null?a:o)}});return n.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}const Mo=[{label:"align.left",icon:"LeftJustifyingSingle",value:l.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:l.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:l.HorizontalAlign.RIGHT}];function $l(i){const e=i.get(l.IUniverInstanceService),t=i.get(S.SelectionManagerService);return{id:S.SetHorizontalTextAlignCommand.id,icon:Mo[0].icon,positions:[I.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:Mo,value$:new D.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==S.SetHorizontalTextAlignCommand.id&&s!==S.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}n.next(d!=null?d:l.HorizontalAlign.LEFT)});return n.next(l.HorizontalAlign.LEFT),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}const bo=[{label:"align.top",icon:"AlignTopSingle",value:l.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:l.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:l.VerticalAlign.BOTTOM}];function zl(i){const e=i.get(l.IUniverInstanceService),t=i.get(S.SelectionManagerService);return{id:S.SetVerticalTextAlignCommand.id,icon:bo[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:bo,value$:new D.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==S.SetVerticalTextAlignCommand.id&&s!==S.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getVerticalAlignment()}n.next(d!=null?d:l.VerticalAlign.TOP)});return n.next(l.VerticalAlign.TOP),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}const wo=[{label:"textWrap.overflow",icon:"OverflowSingle",value:l.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:l.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:l.WrapStrategy.CLIP}];function Yl(i){const e=i.get(S.SelectionManagerService),t=i.get(l.IUniverInstanceService);return{id:S.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:wo[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:wo,value$:new D.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==S.SetTextWrapCommand.id&&s!==S.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getWrapStrategy()}n.next(d!=null?d:l.WrapStrategy.OVERFLOW)});return n.next(l.WrapStrategy.OVERFLOW),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}const To=[{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 Xl(i){const e=i.get(S.SelectionManagerService),t=i.get(l.IUniverInstanceService);return{id:S.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:To[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:To,positions:[I.MenuPosition.TOOLBAR_START],value$:new D.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u,h;const s=r.id;if(s!==S.SetTextRotationCommand.id&&s!==S.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const m=c.getRange(a.startRow,a.startColumn);d=m==null?void 0:m.getTextRotation()}(d==null?void 0:d.v)===l.BooleanNumber.TRUE?n.next("v"):n.next((h=d&&d.a)!=null?h:0)});return n.next(0),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:S.getCurrentSheetDisabled$(i)}}function yt(i){return new D.Observable(e=>e.next(!i.get(I.IClipboardInterfaceService).supportClipboard))}function Zl(){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 Gl(i){return{id:I.PasteCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:yt(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const Ot="sheet.menu.paste-special";function Kl(i){return{id:Ot,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",disabled$:yt(i),positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function ql(i){return{id:or.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[Ot],disabled$:yt(i)}}function Jl(i){return{id:rr.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[Ot],disabled$:yt(i)}}function Ql(i){return{id:sr.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[Ot],disabled$:yt(i)}}function ec(i){return{id:ar.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[Ot],disabled$:yt(i)}}function tc(){return{id:S.SetWorksheetRowIsAutoHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Qt="sheet.menu.sheet-frozen";function nc(){return{id:Qt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[I.MenuPosition.CONTEXT_MENU]}}const $i="sheet.header-menu.sheet-frozen";function ic(){return{id:$i,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function oc(){return{id:Gn.id,type:I.MenuItemType.BUTTON,positions:[Qt,$i],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function rc(){return{id:Lr.id,type:I.MenuItemType.BUTTON,positions:[Qt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function sc(){return{id:Ur.id,type:I.MenuItemType.BUTTON,positions:[Qt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function ac(){return{id:kr.id,type:I.MenuItemType.BUTTON,positions:[Qt,$i],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function lc(){return{id:yr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function cc(){return{id:Or.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function dc(i){const e=i.get(l.IUniverInstanceService),t=i.get(S.SelectionManagerService);function n(){var a;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=t.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.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(l.ICommandService);return{id:S.SetSelectedRowsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new D.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===S.SetSelectionsOperation.id||a.id===S.SetRowHiddenMutation.id||a.id===S.SetRowVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function uc(i){const e=i.get(l.IUniverInstanceService),t=i.get(S.SelectionManagerService);function n(){var a;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=t.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.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(l.ICommandService);return{id:S.SetSelectedColsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new D.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===S.SetSelectionsOperation.id||a.id===S.SetColHiddenMutation.id||a.id===S.SetColVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function hc(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService);return{id:S.SetRowHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:ji,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:new D.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;a!=null&&(d=c.getRowHeight(a.startRow)),o.next(d!=null?d:0)}const s=e.onCommandExecuted(a=>{const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function mc(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(S.SelectionManagerService);return{id:S.SetColWidthCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:ji,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:new D.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d=0;a!=null&&(d=c.getColumnWidth(a.startColumn)),o.next(d)}const s=e.onCommandExecuted(a=>{const c=a.id;if(c===S.SetRangeValuesMutation.id||c===S.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function en(i){var c;const e=i.get(l.IUniverInstanceService),t=i.get(Q.TextSelectionManagerService),n=e.getUniverDocInstance(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=t.getActiveRange();if(n==null||o==null)return;const r=(c=n.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 Ce(i,e){const n=i.getCurrentUniverSheetInstance().getUnitId(),o=e.getRenderById(n);if(o==null)return;const{components:r,mainComponent:s,scene:a,engine:c}=o,d=s,u=r.get(Se.ROW),h=r.get(Se.COLUMN),m=r.get(Se.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:a,engine:c}}function wi(i,e,t,n){const{startX:o,startY:r,endX:s,endY:a}=n.getCellByIndex(i,e);return{startX:o,startY:r,endX:s,endY:a}}function Rt(i,e,t,n,o){const r=t.getRelativeCoord(b.Vector2.FromArray([i,e])),{x:s,y:a}=r,c=t.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=t.getAncestorScale(),h=n.getCellPositionByOffset(s,a,d,u,c),{row:m,column:g}=h,_=n.getNoMergeCellPositionByIndex(m,g),{startX:f,startY:v,endX:R,endY:M}=_;return{startX:f,startY:v,endX:R,endY:M,row:m,column:g}}function hn(i,e,t,n){const o=t.getRelativeCoord(b.Vector2.FromArray([i,e])),r=t.getViewport(V.VIEW_MAIN),s=t.getScrollXYByRelativeCoords(o,r),{scaleX:a,scaleY:c}=t.getAncestorScale(),{x:d,y:u}=s,h=i/a+d,m=e/c+u;return{x:h,y:m}}const gc={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"},Wr={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":"编辑表格"},_c=(i,e,t=!1)=>{const n=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=n(e)%n(i),s=o(e)%o(i),a={startRow:0,endRow:n(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(n(e)/n(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 g=n(i)*(h-1),_=o(i)*(m-1),f={startRow:g+e.startRow,endRow:g+e.startRow,startColumn:_+e.startColumn,endColumn:_+e.startColumn};u.push({repeatRelativeRange:a,startRange:f})}else if(!r&&s&&!t)for(let h=1;h<=c;h++){const m=n(i)*(h-1),g=0,_={startRow:m+e.startRow,endRow:m+e.startRow,startColumn:g+e.startColumn,endColumn:g+e.startColumn};u.push({repeatRelativeRange:a,startRange:_})}else if(r&&!s&&!t)for(let h=1;h<=d;h++){const g=o(i)*(h-1),_={startRow:0+e.startRow,endRow:0+e.startRow,startColumn:g+e.startColumn,endColumn:g+e.startColumn};u.push({repeatRelativeRange:a,startRange:_})}else{const h={startRow:e.startRow,endRow:e.startRow,startColumn:e.startColumn,endColumn:e.startColumn};u.push({startRange:h,repeatRelativeRange:a})}return u};class jr{constructor(){C(this,"_state",null);C(this,"_rect",null);C(this,"_focus",!1);C(this,"_state$",new D.BehaviorSubject(null));C(this,"state$",this._state$.asObservable());C(this,"_rect$",new D.BehaviorSubject(null));C(this,"rect$",this._rect$.asObservable());C(this,"_focus$",new D.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 tn=N.createIdentifier("univer.sheet-cell-editor-manager.service");class Sc{constructor(){C(this,"_position",null);C(this,"_position$",new D.BehaviorSubject(null));C(this,"position$",this._position$.asObservable());C(this,"_focus",!1);C(this,"_focus$",new D.BehaviorSubject(this._focus));C(this,"focus$",this._focus$.asObservable());C(this,"_fxBtnClick$",new D.BehaviorSubject(!1));C(this,"fxBtnClick$",this._fxBtnClick$.asObservable());C(this,"_foldBtnStatus$",new D.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 qn=N.createIdentifier("univer.sheet-formula-editor-manager.service");var fc=Object.defineProperty,pc=Object.getOwnPropertyDescriptor,vc=(i,e,t,n)=>{for(var o=n>1?void 0:n?pc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&fc(e,t,o),o},Eo=(i,e)=>(t,n)=>e(t,n,i);let mn=class extends l.Disposable{constructor(e,t){super();C(this,"_previousSheetIndex",-1);this._commandService=e,this._univerInstanceService=t,this.disposeWithMe(this._commandService.beforeCommandExecuted((n,o)=>{if(n.id===S.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(n)})),this.disposeWithMe(this._commandService.onCommandExecuted((n,o)=>{if(n.id===S.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(n);if(n.id===S.SetWorksheetHideMutation.id&&n.params.hidden)return this._adjustActiveSheetOnHideSheet(n);if(!(o!=null&&o.fromCollab)){if(n.id===S.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(n);if(n.id===S.SetWorksheetHideMutation.id&&!n.params.hidden)return this._adjustActiveSheetOnShowSheet(n)}}))}_adjustActiveSheetOnHideSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o||o.getActiveSheet().getSheetId()!==n)return;const s=o.getActiveSheetIndex(),a=yo(o,s);this._switchToNextSheet(t,a)}_beforeAdjustActiveSheetOnRemoveSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o)return;const r=o.getSheetBySheetId(n);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(e){if(this._previousSheetIndex===-1)return;const{unitId:t}=e.params,n=this._univerInstanceService.getUniverSheetInstance(t);if(!n||n.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,a=yo(n,s);this._switchToNextSheet(t,a)}_adjustActiveSheetOnInsertSheet(e){const{unitId:t,sheet:n}=e.params;this._switchToNextSheet(t,n.id)}_adjustActiveSheetOnShowSheet(e){const{unitId:t,subUnitId:n}=e.params;this._switchToNextSheet(t,n)}_switchToNextSheet(e,t){this._commandService.executeCommand(S.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t})}};mn=vc([l.OnLifecycle(l.LifecycleStages.Ready,mn),Eo(0,l.ICommandService),Eo(1,l.IUniverInstanceService)],mn);function yo(i,e){const t=i.getSheetSize();for(let n=e;n>-1;n--){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}for(let n=e;n<t;n++){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var Cc=Object.defineProperty,Ic=Object.getOwnPropertyDescriptor,Rc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ic(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Cc(e,t,o),o},Ut=(i,e)=>(t,n)=>e(t,n,i);let gn=class{constructor(i,e,t,n,o){this._injector=i,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=n,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e,_sheetSkeletonManagerService:t,_injector:n}=this,{skeleton:o}=t.getCurrent(),r=o.calculateAutoHeightInRange(i),s=e.getCurrentUniverSheetInstance(),a=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:a,rowsAutoHeightInfo:r},u=S.SetWorksheetRowAutoHeightMutationFactory(n,d);return{undos:[{id:S.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:S.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;i.interceptCommand({getMutations:t=>t.id!==S.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.range)}),i.interceptCommand({getMutations:t=>t.id!==S.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.ranges)}),i.interceptCommand({getMutations:t=>{var r;if(t.id!==S.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=t.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=e.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};gn=Rc([l.OnLifecycle(l.LifecycleStages.Ready,gn),Ut(0,N.Inject(N.Injector)),Ut(1,N.Inject(S.SheetInterceptorService)),Ut(2,N.Inject(S.SelectionManagerService)),Ut(3,N.Inject(l.IUniverInstanceService)),Ut(4,N.Inject(exports.SheetSkeletonManagerService))],gn);var Mc=Object.defineProperty,bc=Object.getOwnPropertyDescriptor,wc=(i,e,t,n)=>{for(var o=n>1?void 0:n?bc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Mc(e,t,o),o},Ee=(i,e)=>(t,n)=>e(t,n,i);let _n=class extends l.RxDisposable{constructor(i,e,t,n,o,r,s,a,c,d,u){var h;super(),this._injector=i,this._currentUniverSheet=e,this._commandService=t,this._contextService=n,this._configService=o,this._sheetClipboardService=r,this._clipboardInterfaceService=s,this._messageService=a,this._sheetSkeletonManagerService=c,this._localService=d,this._textSelectionRenderManager=u,this._init(),this._clipboardInterfaceService.supportClipboard||(h=this._textSelectionRenderManager)==null||h.onPaste$.pipe(D.takeUntil(this.dispose$)).subscribe(m=>{var v,R;if(!ne(this._contextService))return;m.event.preventDefault();const g=m.event,_=(v=g.clipboardData)==null?void 0:v.getData("text/html"),f=(R=g.clipboardData)==null?void 0:R.getData("text/plain");this._sheetClipboardService.legacyPaste(_,f)})}_init(){[ir,ga,bt].forEach(e=>this.disposeWithMe(this._commandService.registerMultipleCommand(e))),[or,rr,sr,ar].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:fe.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(t,n){e=i._getWorksheet(t,n)},onCopyCellContent(t,n){const o=e.getCell(t,n);return`${(o==null?void 0:o.v)||""}`},onCopyCellStyle:(t,n,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=e.getRange(t,n).getTextStyle();let d="";return c&&(d=l.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(t){return{width:`${e.getColumnWidth(t)}`}},onCopyRow(t){return{style:`height: ${e.getRowHeight(t)}px;`}},onAfterCopy(){e=null}}}_initPastingHook(){const i=this;let e=null,t=null,n=null;return{id:fe.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste({unitId:o,subUnitId:r,range:s}){n=i._getWorksheet(o,r),e=o,t=r;const a=i._configService.getConfig(S.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return a&&c*d>a?(i._messageService.show({type:ge.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const{range:s}=o,a=[],c=n.getMaxRows(),d=s.endRow-c,u=r.length-d;if(d>0){const g={};r.slice(u).forEach((f,v)=>{const{style:R,height:M}=f||{};if(R){const T=R.split(";");let E=l.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}),g[v]={h:E,hd:l.BooleanNumber.FALSE}}else M&&(g[v]={h:Number.parseFloat(M),hd:l.BooleanNumber.FALSE})});const _={unitId:e,subUnitId:t,range:{...s,startRow:c},rowInfo:g};a.push({id:S.InsertRowMutation.id,params:_})}const h={};r.slice(0,u).forEach((g,_)=>{const{style:f,height:v}=g;if(f){const R=f.split(";");let M=l.DEFAULT_WORKSHEET_ROW_HEIGHT;R.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"?(M=Number.parseFloat(w),!0):!1}),h[_+s.startRow]=M}else v&&(h[_+s.startRow]=Number.parseFloat(v))});const m={unitId:e,subUnitId:t,ranges:[{...s,endRow:Math.min(s.endRow,c)}],rowHeight:h};return a.push({id:S.SetWorksheetRowHeightMutation.id,params:m}),{redos:a,undos:[]}},onPasteColumns(o,r,s){var _;const{range:a}=o,c=[],d=n.getMaxColumns(),u=a.endColumn-d,h=r.length-u,m=(_=i._configService.getConfig(l.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?_:l.DEFAULT_WORKSHEET_COLUMN_WIDTH;if(u>0){const f={unitId:e,subUnitId:t,range:{...a,startColumn:d},colInfo:r.slice(h).map(v=>({w:v.width?+v.width:m,hd:l.BooleanNumber.FALSE}))};c.push({id:S.InsertColMutation.id,params:f})}const g={unitId:e,subUnitId:t,ranges:[{...a,endRow:Math.min(a.endColumn,d)}],colWidth:r.slice(0,h).map(f=>f.width?+f.width:m)};return c.push({id:S.SetWorksheetColWidthMutation.id,params:g}),{redos:c,undos:[]}},onPastePlainText(o,r,s){return i._onPastePlainText(o,r,s)},onPasteCells(o,r,s,a){return i._onPasteCells(o,r,s,a)},onAfterPaste(o){n=null}}}_generateDocumentDataModelSnapshot(i){var s;const e=this._sheetSkeletonManagerService.getCurrent();if(e==null)return null;const{skeleton:t}=e,n=(s=t.getBlankCellDocumentModel())==null?void 0:s.documentModel,r={...n==null?void 0:n.getSnapshot(),...i};return n==null||n.reset(r),n==null?void 0:n.getSnapshot()}_onPastePlainText(i,e,t){const{range:n,unitId:o,subUnitId:r}=i;let s;if(/\r|\n/.test(e)){const c=nr(e),d=this._generateDocumentDataModelSnapshot({body:c});s={[n.startRow]:{[n.startColumn]:{p:d}}}}else s={[n.startRow]:{[n.startColumn]:{v:e}}};const a={unitId:o,subUnitId:r,cellValue:s};return{redos:[{id:S.SetRangeValuesMutation.id,params:a}],undos:[{id:S.SetRangeValuesMutation.id,params:S.SetRangeValuesUndoMutationFactory(this._injector,a)}]}}_onPasteCells(i,e,t,n){const o={get:this._injector.get.bind(this._injector)};return Ws(i,e,t,n,o)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},e=this,t={id:fe.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,a,c,d)=>{const u=e._currentUniverSheet.getCurrentUniverSheetInstance();return u.getUnitId(),u.getActiveSheet().getSheetId(),Qo(a,c,i)}},n={id:fe.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,a,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance();u.getUnitId(),u.getActiveSheet().getSheetId();const h=[],m=[],{undos:g,redos:_}=tr(a,c,i);h.push(..._),m.push(...g);const{undos:f,redos:v}=Ii(a,c,i);h.push(...v),m.push(...f);const{undos:R,redos:M}=er(a,c,i);return h.push(...M),m.push(...R),{undos:m,redos:h}}},o={id:fe.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,a,c){var E;const d=e._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],g=e._getWorksheet(u,h),{range:_}=s,f=g.getMaxColumns(),v=_.endColumn-f,R=a.length-v,M=(E=e._configService.getConfig(l.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?E:l.DEFAULT_WORKSHEET_COLUMN_WIDTH,T={unitId:u,subUnitId:h,ranges:[{..._,endRow:Math.min(_.endColumn,f)}],colWidth:a.slice(0,R).map(w=>w.width?+w.width:M)};return m.push({id:S.SetWorksheetColWidthMutation.id,params:T}),m.push({id:S.SetWorksheetColWidthMutation.id,params:T}),{redos:m,undos:[]}}},r={id:fe.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,a,c,d){e._currentUniverSheet.getCurrentUniverSheetInstance();const u=[],h=[],{range:m,unitId:g,subUnitId:_}=a,{startColumn:f,startRow:v,endColumn:R,endRow:M}=m,T=new l.ObjectMatrix;c.forValue((x,A,B)=>{const P=B.s;typeof P=="object"&&T.setValue(x+v,A+f,{s:{...P,bd:void 0},v:B.v})});const E={unitId:g,subUnitId:_,cellValue:T.getData()};u.push({id:S.SetRangeValuesMutation.id,params:E});const w=S.SetRangeValuesUndoMutationFactory(i,E);h.push({id:S.SetRangeValuesMutation.id,params:w});const{undos:y,redos:O}=Ii(a,c,i);return h.push(...y),u.push(...O),{redos:u,undos:h}}};return[t,n,o,r]}_getWorksheet(i,e){var n;const t=(n=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:n.getSheetBySheetId(e);if(!t)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${e}.`);return t}};_n=wc([l.OnLifecycle(l.LifecycleStages.Steady,_n),Ee(0,N.Inject(N.Injector)),Ee(1,l.IUniverInstanceService),Ee(2,l.ICommandService),Ee(3,l.IContextService),Ee(4,l.IConfigService),Ee(5,Mt),Ee(6,I.IClipboardInterfaceService),Ee(7,I.IMessageService),Ee(8,N.Inject(exports.SheetSkeletonManagerService)),Ee(9,N.Inject(l.LocaleService)),Ee(10,N.Optional(b.ITextSelectionRenderManager))],_n);var Tc=Object.defineProperty,Ec=Object.getOwnPropertyDescriptor,yc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ec(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Tc(e,t,o),o},kt=(i,e)=>(t,n)=>e(t,n,i);let Sn=class extends l.Disposable{constructor(i,e,t,n,o){super(),this._currentUniverService=i,this._contextMenuService=e,this._renderManagerService=t,this._selectionManagerService=n,this._selectionRenderService=o,this._currentUniverService.currentSheet$.subscribe(r=>{if(r==null)throw new Error("workbook is null");this._addListeners()})}_addListeners(){const i=Ce(this._currentUniverService,this._renderManagerService);if(!i)return;const e=i.spreadsheet.onPointerDownObserver,t=e.add(a=>{if(a.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 _=a.offsetX,f=a.offsetY;switch(u){case l.RANGE_TYPE.ROW:return h.startY<=f&&h.endY>=f;case l.RANGE_TYPE.COLUMN:return h.startX<=_&&h.endX>=_;default:return h.startX<=_&&h.endX>=_&&h.startY<=f&&h.endY>=f}},g=_=>{this._contextMenuService.triggerContextMenu(a,_)};m()?u===l.RANGE_TYPE.COLUMN?g(ce.COL_HEADER_CONTEXT_MENU):u===l.RANGE_TYPE.ROW?g(ce.ROW_HEADER_CONTEXT_MENU):g(I.MenuPosition.CONTEXT_MENU):g(I.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(l.toDisposable(()=>e.remove(t)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,ce.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>e.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,ce.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>e.remove(s)))}};Sn=yc([l.OnLifecycle(l.LifecycleStages.Rendered,Sn),kt(0,l.IUniverInstanceService),kt(1,I.IContextMenuService),kt(2,b.IRenderManagerService),kt(3,N.Inject(S.SelectionManagerService)),kt(4,_e)],Sn);var Oc=Object.defineProperty,xc=Object.getOwnPropertyDescriptor,Ac=(i,e,t,n)=>{for(var o=n>1?void 0:n?xc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Oc(e,t,o),o},di=(i,e)=>(t,n)=>e(t,n,i);let fn=class extends l.RxDisposable{constructor(i,e,t){super(),this._currentUniverService=i,this._renderManagerService=e,this._undoRedoService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(D.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(e=>{const t=e.getConfig();i[e.getSheetId()]={cellData:new l.ObjectMatrix(t.cellData),rowCount:t.rowCount,columnCount:t.columnCount}})}_commandExecutedListener(){}_getDocObject(){return Q.getDocObject(this._currentUniverService,this._renderManagerService)}};fn=Ac([l.OnLifecycle(l.LifecycleStages.Steady,fn),di(0,l.IUniverInstanceService),di(1,b.IRenderManagerService),di(2,N.Inject(l.IUndoRedoService))],fn);const $r=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],Nc=[I.KeyCode.ENTER,I.KeyCode.TAB,...$r];function Dc(){const i=[];for(const e of $r)i.push({id:Gt.id,binding:e,preconditions:t=>Bn(t),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!1}}),i.push({id:Gt.id,binding:e|I.MetaKeys.SHIFT,preconditions:t=>Bn(t),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!0}});return i}const Pc={id:He.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>Bn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},Hc={id:He.id,binding:I.KeyCode.TAB,preconditions:i=>Bn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},Lc={id:He.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>qo(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},Uc={id:Q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>qo(i),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},kc={id:Q.DeleteLeftCommand.id,preconditions:i=>Rs(i)||Jo(i),binding:I.KeyCode.BACKSPACE},Vc={id:He.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ne(i)&&!Jo(i),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};var Bc=Object.defineProperty,Fc=Object.getOwnPropertyDescriptor,Wc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Fc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Bc(e,t,o),o},Ne=(i,e)=>(t,n)=>e(t,n,i);function jc(i){const{textRuns:e=[],paragraphs:t=[]}=i;return e.some(n=>n.ts&&!l.Tools.isEmptyObject(n.ts))||t.some(n=>n.bullet)||t.length>=2}let pn=class extends l.Disposable{constructor(e,t,n,o,r,s,a,c,d,u){super();C(this,"_onInputSubscription");C(this,"_cursorChangeObservers");C(this,"_editorVisiblePrevious",!1);C(this,"_isCursorChange",0);this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=a,this._undoRedoService=c,this._sheetInterceptorService=d,this._selectionManagerService=u,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe();const e=this._getEditorObject();if(e==null)return;const{document:t}=e;t.onPointerDownObserver.remove(this._cursorChangeObservers)}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this._onInputSubscription=this._editorBridgeService.visible$.subscribe(e=>{const{visible:t,keycode:n,eventType:o}=e;if(t===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=t,t===!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:a,sheetId:c,pluginName:d}=s;if(this._exitInput(e),n===I.KeyCode.ESC){this._commandService.syncExecuteCommand(S.SetSelectionsOperation.id,{unitId:a,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getEditCellState();if(u==null)return;const{unitId:h,sheetId:m,row:g,column:_,documentLayoutObject:f}=u;if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(n);return}const R=this._currentUniverService.getUniverSheetInstance(h),M=R==null?void 0:R.getSheetBySheetId(m);if(M==null)return;const T=$c(M.getCellRaw(g,_)||{},f,this._lexerTreeBuilder);if(T==null){this._moveCursor(n);return}const E={subUnitId:m,unitId:h,workbook:R,worksheet:M,row:g,col:_},w=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(T,E);this._commandService.executeCommand(S.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:g,startColumn:_,endRow:g,endColumn:_},value:w}),this._moveCursor(n),a===h&&m!==c&&this._editorBridgeService.isForceKeepVisible()&&this._commandService.executeCommand(S.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h}),this._selectionManagerService.refreshSelection()})}_exitInput(e){this._contextService.setContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(l.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._editorBridgeService.getCurrentEditorId();t!=null&&(this._undoRedoService.clearUndoRedo(t),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Nc.includes(e))return;let t=l.Direction.LEFT;switch(e){case I.KeyCode.ENTER:t=l.Direction.DOWN;break;case I.KeyCode.TAB:t=l.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:t=l.Direction.DOWN;break;case I.KeyCode.ARROW_UP:t=l.Direction.UP;break;case I.KeyCode.ARROW_LEFT:t=l.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:t=l.Direction.RIGHT;break}e===I.KeyCode.ENTER||e===I.KeyCode.TAB?this._commandService.executeCommand(lt.id,{keycode:e,direction:t}):this._commandService.executeCommand(we.id,{direction:t})}_cursorStateListener(){const e=this._getEditorObject();if(e==null)return;const{document:t}=e;this._cursorChangeObservers=t.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})}_commandExecutedListener(){const e=[Gt.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{keycode:o,isShift:r}=n;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(n)}}))}_moveInEditor(e,t){let n=l.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?n=l.Direction.DOWN:e===I.KeyCode.ARROW_UP?n=l.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(n=l.Direction.RIGHT),t?this._commandService.executeCommand(Q.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(Q.MoveCursorOperation.id,{direction:n})}_getEditorObject(){return Yn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};pn=Wc([l.OnLifecycle(l.LifecycleStages.Steady,pn),Ne(0,l.IUniverInstanceService),Ne(1,b.IRenderManagerService),Ne(2,l.ICommandService),Ne(3,Te),Ne(4,l.IContextService),Ne(5,tn),Ne(6,N.Inject(te.LexerTreeBuilder)),Ne(7,l.IUndoRedoService),Ne(8,N.Inject(S.SheetInterceptorService)),Ne(9,N.Inject(S.SelectionManagerService))],pn);function $c(i,e,t){i=l.Tools.deepClone(i);const{documentModel:n}=e;if(n==null)return null;const o=n.getSnapshot(),{body:r}=o;if(r==null)return null;const s=r.dataStream;let c=s.substring(s.length-2,s.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?s.substring(0,s.length-2):s;if(l.isFormulaString(c)){if(i.f===c)return null;const d=t.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(jc(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 zc=Object.defineProperty,Yc=Object.getOwnPropertyDescriptor,Xc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Yc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&zc(e,t,o),o},De=(i,e)=>(t,n)=>e(t,n,i);let vn=class extends l.RxDisposable{constructor(e,t,n,o,r,s,a,c,d,u){super();C(this,"_loadedMap",new Set);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=n,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=a,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(D.takeUntil(this.dispose$)).subscribe(e=>{e===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._loadedMap.has(e)||(this._initialMain(e),this._loadedMap.add(e)))}),this._textSelectionManagerService.textSelection$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{unitId:t}=e;t!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(D.takeUntil(this.dispose$)).subscribe(()=>{var t;if(this._contextService.getContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(l.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0);const n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown});const r=(t=n==null?void 0:n.getBody())==null?void 0:t.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const a=[{startOffset:s.length,endOffset:s.length}],c={unitId:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(Q.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(a)}})}_listenFoldBtnClick(){this._formulaEditorManagerService.foldBtnStatus$.pipe(D.takeUntil(this.dispose$)).subscribe(()=>{this._textSelectionManagerService.refreshSelection()})}_initialMain(e){const t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:n}=t;n!=null&&this.disposeWithMe(l.toDisposable(n.onPointerDownObserver.add(()=>{this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(l.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(D.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=Yn(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||n==null)return;const{width:o,height:r}=e,{engine:s}=t;n.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.currentEditCellState$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{e==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(e)}),this._editorBridgeService.visible$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{if(e==null||e.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const t=this._editorBridgeService.getLatestEditCellState();t!=null&&this._editorSyncHandler(t)})}_editorSyncHandler(e){var s;const t=(s=e.documentLayoutObject.documentModel)==null?void 0:s.getBody();let n=t==null?void 0:t.dataStream,o=t==null?void 0:t.paragraphs,r=[];n==null||o==null||(e.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===b.DeviceInputEventType.Dblclick?(n=`\r
20
- `,o=[{startIndex:0}]):e.isInArrayFormulaRange===!0&&(r=(t==null?void 0:t.textRuns)||[]),this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,n,o,r),this._autoScroll())}_commandExecutedListener(){const e=[Q.RichTextEditingMutation.id,Xn.id],t=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s;if(e.includes(o.id)){const a=o.params,{unitId:c}=a;if(t.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===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(u==null||h==null)return;this._syncContentAndRender(m,u,h),this._autoScroll()}}}));const n=[S.SetRangeValuesMutation.id,S.MoveRangeMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s,a,c,d;if(n.includes(o.id)){const u=this._editorBridgeService.getLatestEditCellState();if(u==null)return;let h=!1;const{row:m,column:g}=u;if(o.id===S.SetRangeValuesMutation.id&&o.params?(s=(r=o.params.cellValue)==null?void 0:r[m])!=null&&s[g]&&(h=!0):o.id===S.MoveRangeMutation.id&&o.params&&(c=(a=o.params.to.value)==null?void 0:a[m])!=null&&c[g]&&(h=!0),h){const _=(d=u.documentLayoutObject.documentModel)==null?void 0:d.getBody();if(_==null)return;const{dataStream:f,paragraphs:v=[]}=_;this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,f,v),this._autoScroll()}}}))}_syncContentAndRender(e,t,n,o=[]){var h;const r=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(e),a=this._univerInstanceService.getUniverDocInstance(e),c=this._docViewModelManagerService.getViewModel(e);if(a==null||c==null||s==null)return;a.getBody().dataStream=t,a.getBody().paragraphs=this._clearParagraph(n),e===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(a.getBody().textRuns=[]),o.length>0&&(a.getBody().textRuns=o),c.reset(a);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 t=l.Tools.deepClone(e);for(const n of t)n.paragraphStyle&&(n.paragraphStyle.horizontalAlign=l.HorizontalAlign.UNSPECIFIED);return t}_autoScroll(){var _,f;const e=(_=this._docSkeletonManagerService.getSkeletonByUnitId(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:_.skeleton,t=this._formulaEditorManagerService.getPosition(),n=this._renderManagerService.getRenderById(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||t==null||n==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:a,mainComponent:c}=n;let{actualHeight:d}=e.getActualSize();d+=r+s;const{width:u,height:h}=t,m=a.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN);let g=m==null?void 0:m.getScrollBar();a.transformByState({width:u,height:d}),c==null||c.resize(u,d),d>h?g==null?m&&new b.ScrollBar(m,{enableHorizontal:!1,barSize:8}):m==null||m.resetSizeAndScrollBar():(g=null,m==null||m.scrollTo({x:0,y:0}),(f=m==null?void 0:m.getScrollBar())==null||f.dispose())}};vn=Xc([l.OnLifecycle(l.LifecycleStages.Steady,vn),De(0,l.IUniverInstanceService),De(1,b.IRenderManagerService),De(2,Te),De(3,N.Inject(Q.DocSkeletonManagerService)),De(4,N.Inject(Q.DocViewModelManagerService)),De(5,l.ICommandService),De(6,l.IContextService),De(7,qn),De(8,l.IUndoRedoService),De(9,N.Inject(Q.TextSelectionManagerService))],vn);var Zc=Object.defineProperty,Gc=Object.getOwnPropertyDescriptor,Kc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Gc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Zc(e,t,o),o},qc=(i,e)=>(t,n)=>e(t,n,i);let Cn=class extends l.Disposable{constructor(i){super(),this._currentUniverService=i,setTimeout(()=>{this._initialize()},0)}_initialize(){this._currentUniverService.createDoc({id:l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}});const i={id:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.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:l.HorizontalAlign.UNSPECIFIED,verticalAlign:l.VerticalAlign.UNSPECIFIED,centerAngle:0,vertexAngle:0,wrapStrategy:l.WrapStrategy.WRAP}}};this._currentUniverService.createDoc(i)}};Cn=Kc([l.OnLifecycle(l.LifecycleStages.Rendered,Cn),qc(0,l.IUniverInstanceService)],Cn);const Jc="36",Qc="univer-sheet-container",zr={sheetFooterBarHeight:Jc,sheetContainer:Qc};var ed=Object.defineProperty,td=Object.getOwnPropertyDescriptor,nd=(i,e,t,n)=>{for(var o=n>1?void 0:n?td(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ed(e,t,o),o},ye=(i,e)=>(t,n)=>e(t,n,i);const Oo=-1e3,xo=5,id=2;let In=class extends l.Disposable{constructor(e,t,n,o,r,s,a,c,d,u,h){super();C(this,"_onInputSubscription");C(this,"_onInputActivateSubscription");C(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=e,this._docViewModelManagerService=t,this._contextService=n,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=a,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._initialize(),this._commandExecutedListener()}dispose(){var e,t;(e=this._onInputSubscription)==null||e.unsubscribe(),(t=this._onInputActivateSubscription)==null||t.unsubscribe()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const e=this._getEditorObject();e!=null&&this.disposeWithMe(l.toDisposable(e.document.onPointerDownObserver.add(()=>{var t;if(this._editorBridgeService.isVisible()){const n=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(n==null||o==null)return;const r=(t=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:t.skeleton;if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u}=n;this._fitTextSize(s,c,r,a,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:t,documentLayoutObject:n,scaleX:o,editorUnitId:r}=e;if(this._getEditorObject()==null)return;const{startX:a,endX:c}=t,{textRotation:d,wrapStrategy:u,documentModel:h}=n,{a:m}=d;h.updateDocumentId(r),u===l.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-a)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(Oo,Oo)})}_fitTextSize(e,t,n,o,r=1,s=1){const{startX:a,startY:c,endX:d,endY:u}=e,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:g}=this._predictingSize(e,t,n,o,r,s),{verticalAlign:_,paddingData:f,fill:v}=o;let R=d-a,M=u-c;if(R<m&&(R=m),M<g)M=g,h.updateDocumentDataMargin(f);else{let T=M-g||0;_===l.VerticalAlign.MIDDLE?T=(M-g)/2:_===l.VerticalAlign.TOP&&(T=f.t||0),T/=s,T=T<(f.t||0)?f.t||0:T,h.updateDocumentDataMargin({t:T})}n.calculate(),this._editAreaProcessing(R,M,e,t,v,r,s)}_predictingSize(e,t,n,o,r=1,s=1){const{startX:a,endX:c}=e,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,g=document.body.clientWidth;if(u===l.WrapStrategy.WRAP&&m===0){const{actualWidth:v,actualHeight:R}=n.getActualSize();return{actualWidth:v*r,actualHeight:R*s}}h==null||h.updateDocumentDataPageSize((g-a-t.left)/r),n.calculate();const _=n.getActualSize();let f=c-a;return f<_.actualWidth*r+xo*r&&(f=_.actualWidth*r+xo*r),h==null||h.updateDocumentDataPageSize(f/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:l.HorizontalAlign.UNSPECIFIED}),{actualWidth:f,actualHeight:_.actualHeight*s}}_editAreaProcessing(e,t,n,o,r,s=1,a=1){var w;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=n;const{document:h,scene:m,engine:g}=c,_=m.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN),f=document.body.clientHeight-u-Number.parseFloat(zr.sheetFooterBarHeight)-o.top-id*2,v=document.body.clientWidth-d-o.left;let R=t,M=_==null?void 0:_.getScrollBar();R>f?(R=f,M==null?_&&new b.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetSizeAndScrollBar()):(M=null,(w=_==null?void 0:_.getScrollBar())==null||w.dispose()),e+=(M==null?void 0:M.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,t/a,r);const{scaleX:T,scaleY:E}=m.getPrecisionScale();m.transformByState({width:e/s,height:t/a,scaleX:s,scaleY:a}),h.resize(e/s,t/a),requestIdleCallback(()=>{g.resizeBySize(b.fixLineWidthByScale(e,T),b.fixLineWidthByScale(R,E))}),this._cellEditorManagerService.setState({startX:d,startY:u,endX:e+d,endY:R+u,show:!0})}_addBackground(e,t,n,o){const r="_backgroundRectHelperColor_",s=e.getObject(r);s==null&&o==null||(s==null?e.addObjects([new b.Rect(r,{width:t,height:n,fill:o,evented:!1})],Q.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:t,height:n})))}_initialStartEdit(){this._onInputActivateSubscription=this._editorBridgeService.visible$.subscribe(e=>{var E,w,y;const{visible:t,eventType:n,keycode:o}=e;if(t===this._editorVisiblePrevious||(this._editorVisiblePrevious=t,t===!1))return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:g=!1}=r,_=this._getEditorObject();if(_==null)return;const{document:f,scene:v}=_;this._contextService.setContextValue(l.EDITOR_ACTIVATED,!0);const{documentModel:R}=a,M=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(M==null||R==null)return;const{skeleton:T}=M;if(this._fitTextSize(s,c,T,a,d,u),n===b.DeviceInputEventType.Keyboard||n===b.DeviceInputEventType.Dblclick&&g){const O=l.Tools.deepClone(R.snapshot),x=(E=this._docViewModelManagerService.getCurrent())==null?void 0:E.docViewModel;this._resetBodyStyle(O.body),R.reset(O),x.reset(R),f.makeDirty(),(o===I.KeyCode.BACKSPACE||n===b.DeviceInputEventType.Dblclick)&&(T.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(n===b.DeviceInputEventType.Dblclick){const O=R.getBody().dataStream.length-2||0;(w=v.getViewport(Q.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=l.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 t=this._contextService.getContextValue(l.FOCUSING_FORMULA_EDITOR);this._contextService.getContextValue(l.FOCUSING_SHEET)&&!t&&this._showEditorByKeyboard(e)})}_showEditorByKeyboard(e){if(e==null)return;const t=e.event;this._commandService.executeCommand(He.id,{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:t.which})}_commandExecutedListener(){const e=[Q.RichTextEditingMutation.id,Xn.id],t=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var o;if(e.includes(n.id)){const r=n.params,{unitId:s}=r,a=this._editorBridgeService.getCurrentEditorId();if(a==null)return;this._editorBridgeService.changeEditorDirty(!0);const c=(o=this._docSkeletonManagerService.getSkeletonByUnitId(a))==null?void 0:o.skeleton;if(c==null||!t.includes(s))return;const d=this._editorBridgeService.getEditCellState();if(d==null)return;const{position:u,documentLayoutObject:h,canvasOffset:m,scaleX:g,scaleY:_}=d;this._fitTextSize(u,m,c,h,g,_)}}))}_getEditorObject(){return Yn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};In=nd([l.OnLifecycle(l.LifecycleStages.Steady,In),ye(0,N.Inject(Q.DocSkeletonManagerService)),ye(1,N.Inject(Q.DocViewModelManagerService)),ye(2,l.IContextService),ye(3,l.IUniverInstanceService),ye(4,b.IRenderManagerService),ye(5,Te),ye(6,tn),ye(7,b.ITextSelectionRenderManager),ye(8,N.Inject(Q.TextSelectionManagerService)),ye(9,l.ICommandService),ye(10,N.Inject(l.LocaleService))],In);const Jn={id:"sheet.command.change-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{delta:t,reset:n}=e,o=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();let c=n?100:Math.round((r.getConfig().zoomRatio+t)*100);c=Math.max(Ci[0],c),c=Math.min(Ci[1],c);const d=c/100;return i.get(l.ICommandService).executeCommand(ze.id,{unitId:s,subUnitId:a,zoomRatio:d})}},Qn={id:"sheet.command.set-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,zoomRatio:o}=e;return i.get(l.ICommandService).executeCommand(ze.id,{unitId:t,subUnitId:n,zoomRatio:o})}},Yr={id:"sheet.operation.set-activate-cell-edit",type:l.CommandType.OPERATION,handler:(i,e)=>(i.get(Te).setEditCell(e),!0)};var od=Object.defineProperty,rd=Object.getOwnPropertyDescriptor,sd=(i,e,t,n)=>{for(var o=n>1?void 0:n?rd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&od(e,t,o),o},ct=(i,e)=>(t,n)=>e(t,n,i);let Rn=class extends l.RxDisposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._editorBridgeService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener()}_initSelectionChangeListener(){D.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(D.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==S.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const t=this._sheetSkeletonManagerService.getCurrent();if(t==null||i==null||i.length===0||i[i.length-1]==null)return;const{primary:n}=i[i.length-1];if(n==null)return;const o=this._getSheetObject();if(o==null)return;const{unitId:r,sheetId:s}=t,{scene:a,engine:c}=o;this._commandService.executeCommand(Yr.id,{scene:a,engine:c,primary:n,unitId:r,sheetId:s})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:e,spreadsheetColumnHeader:t,spreadsheetLeftTopPlaceholder:n,spreadsheetRowHeader:o}=i;e.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(He.id,{visible:!0,eventType:b.DeviceInputEventType.Dblclick})}),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.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(He.id,{visible:!1,eventType:b.DeviceInputEventType.PointerDown}),setTimeout(()=>{this._selectionManagerService.makeDirty(!0)},0))}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}_commandExecutedListener(){const i=S.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{t!=null&&t.fromCollab||(e.id===S.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(e.id)&&this._hideEditor())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===Qn.id&&this._editorBridgeService.refreshEditCellState()}))}};Rn=sd([l.OnLifecycle(l.LifecycleStages.Rendered,Rn),ct(0,N.Inject(exports.SheetSkeletonManagerService)),ct(1,l.IUniverInstanceService),ct(2,l.ICommandService),ct(3,b.IRenderManagerService),ct(4,Te),ct(5,N.Inject(S.SelectionManagerService))],Rn);var ad=Object.defineProperty,ld=Object.getOwnPropertyDescriptor,cd=(i,e,t,n)=>{for(var o=n>1?void 0:n?ld(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ad(e,t,o),o},Vt=(i,e)=>(t,n)=>e(t,n,i);let Mn=class extends l.Disposable{constructor(i,e,t,n,o){super(),this._commandService=i,this._formatPainterService=e,this._currentUniverService=t,this._renderManagerService=n,this._selectionRenderService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:e}=this._getSheetObject()||{};e&&(i!==Oe.OFF?e.setDefaultCursor(b.CURSOR_TYPE.CELL):e.setDefaultCursor(b.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(l.toDisposable(this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{if(this._formatPainterService.getStatus()!==Oe.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()===Oe.ONCE&&this._commandService.executeCommand(Wi.id)}})))}async _applyFormatPainter(i){const{styles:e,merges:t}=this._formatPainterService.getSelectionFormat(),n=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!e)return;const{startRow:r,startColumn:s,endRow:a,endColumn:c}=e.getDataRange(),d=a-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,R)=>{const M=f%d+r,T=R%u+s,E=e.getValue(M,T);E&&(h[f][R].s=E)})}),t.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)),R=Math.max(1,Math.floor((i.endColumn-i.startColumn+1)/u));for(let M=0;M<v;M++)for(let T=0;T<R;T++)m.push({startRow:f.startRow+M*d+i.startRow,startColumn:f.startColumn+T*u+i.startColumn,endRow:f.endRow+M*d+i.startRow,endColumn:f.endColumn+T*u+i.startColumn})});const g={subUnitId:o,unitId:n,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(Hr.id,g)}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}};Mn=cd([l.OnLifecycle(l.LifecycleStages.Rendered,Mn),Vt(0,l.ICommandService),Vt(1,Tt),Vt(2,l.IUniverInstanceService),Vt(3,b.IRenderManagerService),Vt(4,_e)],Mn);const bn={id:"sheet.command.set-scroll-relative",type:l.CommandType.COMMAND,handler:async(i,e={offsetX:0,offsetY:0})=>{const t=i.get(l.ICommandService),n=i.get(Je),r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:a,ySplit:c}=s.getConfig().freeze,d=n.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=e||{},{sheetViewStartRow:m=0,sheetViewStartColumn:g=0,offsetX:_=0,offsetY:f=0}=d||{};return t.executeCommand(wt.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:g+a,offsetX:_+u,offsetY:f+h})}},pt={id:"sheet.command.scroll-view",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet(),s=i.get(Je).getCurrentScroll();if(!o)return!1;const a=i.get(l.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=e,{sheetViewStartColumn:m,sheetViewStartRow:g,offsetX:_,offsetY:f}=s||{},{xSplit:v,ySplit:R}=o.getConfig().freeze;return a.executeCommand(wt.id,{unitId:n.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c!=null?c:(g!=null?g:0)+R,sheetViewStartColumn:d!=null?d:(m!=null?m:0)+v,offsetX:u!=null?u:_,offsetY:h!=null?h:f})}};l.CommandType.COMMAND;var dd=Object.defineProperty,ud=Object.getOwnPropertyDescriptor,hd=(i,e,t,n)=>{for(var o=n>1?void 0:n?ud(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&dd(e,t,o),o},Pe=(i,e)=>(t,n)=>e(t,n,i);const md="__SpreadsheetFreezeRowMainName__",gd="__SpreadsheetFreezeRowHeaderName__",_d="__SpreadsheetFreezeColumnMainName__",Sd="__SpreadsheetFreezeColumnHeaderName__",ui=4,fd=.01;let wn=class extends l.Disposable{constructor(e,t,n,o,r,s,a,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=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=a,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,t){var O;const n=t!=null?t:this._getFreeze();if(n==null)return;const o=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(o==null)return;const{startRow:r,startColumn:s}=n,a=this._getPositionByIndex(r,s);if(a==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:g,startY:_}=a,{rowTotalHeight:f,columnTotalWidth:v,rowHeaderWidthAndMarginLeft:R,columnHeaderHeightAndMarginTop:M}=o,T=u>v+R?u:v+M,E=h>f+M?h:f+M;this._changeToRow=r,this._changeToColumn=s,this._changeToOffsetX=g,this._changeToOffsetY=_;const w=Math.max(m.scaleX,m.scaleY),y=ui/(w<1?1:w);if(e===0){const x=y;this._rowFreezeHeaderRect=new b.Rect(gd,{fill:this._freezeNormalHeaderColor,width:R,height:y,left:0,top:_-x,zIndex:3});let A=this._freezeNormalHeaderColor;(r===-1||r===0)&&(A=this._freezeNormalMainColor),this._rowFreezeMainRect=new b.Rect(md,{fill:A,width:T*2,height:y,left:R,top:_-x,zIndex:3}),m.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],qe)}else{const x=y;this._columnFreezeHeaderRect=new b.Rect(Sd,{fill:this._freezeNormalHeaderColor,width:y,height:M,left:g-x,top:0,zIndex:3});let A=this._freezeNormalHeaderColor;(s===-1||s===0)&&(A=this._freezeNormalMainColor),this._columnFreezeMainRect=new b.Rect(_d,{fill:A,width:y,height:E*2,left:g-x,top:M,zIndex:3}),m.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],qe)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,n=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,n=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(t==null?void 0:t.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(t==null?void 0:t.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(t==null?void 0:t.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)}))}_getCurrentLastVisibleRow(){var h,m,g,_;const e=this._getSheetObject();if(e==null)return;const t=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(t==null)return;const n=e.scene,o=Math.max(n.scaleX,n.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(e.engine.height-t.columnHeaderHeight)/o,a=(m=r==null?void 0:r.sheetViewStartRow)!=null?m:0,c=a===0?-((g=r==null?void 0:r.offsetY)!=null?g:0):t.rowHeightAccumulation[a-1]-((_=r==null?void 0:r.offsetY)!=null?_:0);let d=0,u=!1;for(let f=a,v=t.rowHeightAccumulation.length;f<v;f++)if(t.rowHeightAccumulation[f]-c>s){d=f,u=!0;break}return u||(d=t.rowHeightAccumulation.length-1),d}_getActiveViewport(e){var n;const t=(n=this._getSheetObject())==null?void 0:n.scene.getViewports();return t&&t.find(o=>o.isHit(new b.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,n,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:a}=s;a.setCursor(b.CURSOR_TYPE.GRABBING),a.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=a.onPointerMoveObserver.add(m=>{var T,E,w,y;const g=this._getActiveViewport(m),{startX:_,startY:f,row:v,column:R}=Rt(m.offsetX,m.offsetY,a,r,g||void 0);a.setCursor(b.CURSOR_TYPE.GRABBING);const M=ui/Math.max(a.scaleX,a.scaleY);o===0?((T=t.transformByState({top:Math.min(f,d)-M/2}))==null||T.setProps({fill:this._freezeActiveColor}),(E=n.transformByState({top:Math.min(f,d)-M/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=g):((w=t.transformByState({left:_-M/2}))==null||w.setProps({fill:this._freezeActiveColor}),(y=n.transformByState({left:_-M/2}))==null||y.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=R,this._changeToOffsetX=_,this._activeViewport=g)}),this._upObserver=a.onPointerUpObserver.add(()=>{var x,A;a.resetCursor(),a.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:g}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),n.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),n==null||n.setProps({fill:this._freezeNormalHeaderColor}));const _=ui/Math.max(a.scaleX,a.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:g-_}),n.transformByState({top:g-_})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:m-_}),n.transformByState({left:m-_}));const f=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:v,sheetViewStartColumn:R}=f;if(R==null||v==null)return;const M=this._currentUniverService.getCurrentUniverSheetInstance(),T=M.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=(A=this._activeViewport)==null?void 0:A.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-R,w=w<0?0:w),this._commandService.executeCommand(S.SetFrozenCommand.id,{startRow:y===0?-1:this._changeToRow,startColumn:w===0?-1:this._changeToColumn,ySplit:y,xSplit:w,unitId:M.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,n=t.getViewport(V.VIEW_COLUMN_LEFT),o=t.getViewport(V.VIEW_COLUMN_RIGHT),r=t.getViewport(V.VIEW_ROW_TOP),s=t.getViewport(V.VIEW_ROW_BOTTOM),a=t.getViewport(V.VIEW_LEFT_TOP),c=t.getViewport(V.VIEW_MAIN),d=t.getViewport(V.VIEW_MAIN_LEFT_TOP),u=t.getViewport(V.VIEW_MAIN_LEFT),h=t.getViewport(V.VIEW_MAIN_TOP);if(!(n==null||o==null||r==null||s==null||a==null||c==null||d==null||u==null||h==null))return{viewMain:c,viewMainLeftTop:d,viewMainLeft:u,viewMainTop:h,viewColumnLeft:n,viewColumnRight:o,viewRowTop:r,viewRowBottom:s,viewLeftTop:a}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewMain:t,viewRowBottom:n,viewColumnRight:o,viewMainLeft:r,viewMainTop:s}=e;this.disposeWithMe(t.onScrollAfterObserver.add(a=>{const{scrollX:c,scrollY:d,actualScrollX:u,actualScrollY:h}=a;n.isActive&&n.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,t=-1,n=0,o=0,r=3){var O;const s=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(s==null)return;const{rowHeaderWidthAndMarginLeft:a,columnHeaderHeightAndMarginTop:c}=s,d=this._getViewports();if(!d)return;const{viewMain:u,viewMainLeftTop:h,viewMainLeft:m,viewMainTop:g,viewColumnLeft:_,viewColumnRight:f,viewRowTop:v,viewRowBottom:R,viewLeftTop:M}=d;f.resize({left:a,top:0,height:c,right:0}),R.resize({left:0,top:c,bottom:0,width:a}),M.resize({left:0,top:0,width:a,height:c});let T=!0,E=!0;h.enable(),(e===-1||e===0)&&(T=!1),(t===-1||t===0)&&(E=!1);const w=s.getNoMergeCellPositionByIndexWithNoHeader(e-n,t-o),y=s.getNoMergeCellPositionByIndexWithNoHeader(e,t);if(h.disable(),g.disable(),m.disable(),v.disable(),_.disable(),h.resetPadding(),g.resetPadding(),m.resetPadding(),v.resetPadding(),_.resetPadding(),T===!1&&E===!1)u.resize({left:a,top:c,bottom:0,right:0}),u.resetPadding();else if(T===!0&&E===!1){const x=y.startY-w.startY;u.resize({left:a,top:c+x,bottom:0,right:0}),u.setPadding({startY:w.startY,endY:y.startY,startX:0,endX:0}),r&2&&this._commandService.executeCommand(pt.id,{sheetViewStartRow:0,offsetY:0}),g.resize({left:a,top:c,height:x,right:0}),g.updateScroll({actualScrollY:w.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),v.resize({left:0,top:c,width:a,height:x}),v.updateScroll({actualScrollY:w.startY}).makeDirty(!0),R.resize({left:0,top:c+x,bottom:0,width:a}),g.enable(),v.enable()}else if(T===!1&&E===!0){const x=y.startX-w.startX;u.resize({left:a+x,top:c,bottom:0,right:0}),u.setPadding({startX:w.startX,endX:y.startX,startY:0,endY:0}),r&1&&this._commandService.executeCommand(pt.id,{sheetViewStartColumn:0,offsetX:0}),m.resize({left:a,top:c,width:x,bottom:0,right:0}),m.updateScroll({actualScrollX:w.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),_.resize({left:a,top:0,width:x,height:c}),_.updateScroll({actualScrollX:w.startX}).makeDirty(!0),f.resize({left:a+x,top:0,height:c,right:0}),m.enable(),_.enable()}else{const x=y.startX-w.startX,A=y.startY-w.startY;u.resize({left:a+x,top:c+A,bottom:0,right:0}),u.setPadding({startY:w.startY,endY:y.startY,startX:w.startX,endX:y.startX}),r&&this._commandService.executeCommand(pt.id,{...r&1?{sheetViewStartColumn:0,offsetX:0}:null,...r&2?{sheetViewStartRow:0,offsetY:0}:null}),m.resize({left:a,top:c+A,width:x,bottom:0}),m.updateScroll({actualScrollX:w.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),g.resize({left:a+x,top:c,height:A,right:0}),g.updateScroll({actualScrollY:w.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),h.resize({left:a,top:c,width:x,height:A}),h.updateScroll({actualScrollX:w.startX,actualScrollY:w.startY}).makeDirty(!0),v.resize({left:0,top:c,width:a,height:A}),v.updateScroll({actualScrollY:w.startY}).makeDirty(!0),R.resize({left:0,top:c+A,bottom:0,width:a}),_.resize({left:a,top:0,width:x,height:c}),_.updateScroll({actualScrollX:w.startX}).makeDirty(!0),f.resize({left:a+x,top:0,height:c,right:0}),h.enable(),g.enable(),m.enable(),v.enable(),_.enable()}}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[S.SetWorksheetActiveOperation.id,S.InsertRangeMoveDownCommand.id,S.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:a=0}=n;this._refreshFreeze(o,r,s,a,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(l.toDisposable(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()})))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new l.ColorKit(e.grey400).setAlpha(fd).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},n=this._getFreeze();if(!n)return t;const o=r=>{const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getUnitId(),d=s.getActiveSheet().getSheetId();this._refreshFreeze(r.startRow,r.startColumn,r.ySplit,r.xSplit,0);const u={...r,unitId:a,subUnitId:d,resetScroll:!1},h=S.SetFrozenMutationFactory(this._injector,u);return{undos:[{id:S.SetFrozenMutation.id,params:h}],redos:[{id:S.SetFrozenMutation.id,params:u}]}};if(e.id===S.MoveColsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startColumn:s},toRange:{startColumn:a}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===l.RANGE_TYPE.COLUMN&&v.range.startColumn<=s&&s<=v.range.endColumn);if(!(c!=null&&c.length))return t;const d=c[0].range,u={...d,startColumn:a,endColumn:a+d.endColumn-d.startColumn};if(!n||n.startColumn<=0||d.startColumn>=n.startColumn&&u.startColumn>=n.startColumn||d.startColumn===u.startColumn||d.endColumn<n.startColumn&&u.startColumn<n.startColumn)return t;const h=d.endColumn-d.startColumn+1,m=Math.max(Math.min(n.startColumn,d.endColumn+1)-d.startColumn,0);let g,_;u.startColumn>=n.startColumn?(g=Math.max(n.startColumn-m,1),_=Math.max(n.xSplit-m,1)):(g=n.startColumn+h-m,_=n.xSplit+h-m);const f={...n,startColumn:g,xSplit:_};return o(f)}if(e.id===S.MoveRowsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startRow:s},toRange:{startRow:a}}=e.params,c=r==null?void 0:r.filter(v=>v.range.rangeType===l.RANGE_TYPE.ROW&&v.range.startRow<=s&&s<=v.range.endRow);if(!(c!=null&&c.length))return t;const d=c[0].range,u={...d,startRow:a,endRow:a+d.endRow-d.startRow};if(!n||n.startRow<=0||d.startRow>=n.startRow&&u.startRow>=n.startRow||d.startRow===u.startRow||d.endRow<n.startRow&&u.startRow<n.startRow)return t;const h=d.endRow-d.startRow+1,m=Math.max(Math.min(n.startRow,d.endRow+1)-d.startRow,0);let g,_;u.startRow>=n.startRow?(g=Math.max(n.startRow-m,1),_=Math.max(n.ySplit-m,1)):(g=n.startRow+h-m,_=n.ySplit+h-m);const f={...n,startRow:g,ySplit:_};return o(f)}if(e.id===S.RemoveColCommand.id||e.id===S.RemoveRowCommand.id){const r=e.params,s=r.range;if(s.rangeType===l.RANGE_TYPE.COLUMN&&s.startColumn<n.startColumn){const a=Math.min(n.startColumn,s.endColumn+1)-s.startColumn,c={...n,startColumn:Math.max(1,n.startColumn-a),xSplit:Math.max(1,n.xSplit-a)};return o(c)}if(r.range.rangeType===l.RANGE_TYPE.ROW&&s.startRow<n.startRow){const a=Math.min(n.startRow,s.endRow+1)-s.startRow,c={...n,startRow:Math.max(1,n.startRow-a),ySplit:Math.max(1,n.ySplit-a)};return o(c)}}return t}}))}_commandExecutedListener(){const e=[S.SetFrozenMutation.id,ze.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._lastFreeze,o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=t.params,{unitId:a,subUnitId:c}=s;if(!(a===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:g=0,xSplit:_=0}=d;(!n||n.startRow!==h||n.ySplit!==g)&&(u|=2),(!n||n.startColumn!==m||n.xSplit!==_)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,m,g,_,u)}else if(t.id===S.SetWorksheetRowHeightMutation.id){const n=this._getFreeze();t.params&&n&&t.params.ranges.some(o=>o.startRow<n.startRow)&&this._refreshCurrent()}else if(t.id===S.SetWorksheetColWidthMutation.id){const n=this._getFreeze();t.params&&n&&t.params.ranges.some(o=>o.startColumn<n.startColumn)&&this._refreshCurrent()}else if(t.id===S.SetWorksheetRowAutoHeightMutation.id){const n=t.params,o=this._getFreeze();if(o&&o.startRow>-1&&n.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}else if(t.id===S.SetColHiddenMutation.id||t.id===S.SetColVisibleMutation.id){const n=t.params,o=this._getFreeze(),r=n.ranges;o&&o.startColumn>-1&&r.some(s=>s.startColumn<o.startColumn)&&this._refreshCurrent()}else if(t.id===S.SetRowHiddenMutation.id||t.id===S.SetRowVisibleMutation.id){const n=t.params,o=this._getFreeze(),r=n.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:t}=e;t.onTransformChangeObservable.add(n=>{n.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var n,o,r,s;(n=this._rowFreezeHeaderRect)==null||n.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:t}=e;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(a=>{t.onPointerDownObserver.remove(a),t.onPointerMoveObserver.remove(a),t.onPointerLeaveObserver.remove(a)}),t.onPointerEnterObserver.remove(this._moveObserver),t.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(e,t){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,t);if(o==null)return;if(r!=null&&(!isNaN(r.endX)||!isNaN(r.endY)))return r;const{rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=o;return{startX:s,endX:s,startY:a,endY:a}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}_refreshFreeze(e,t,n,o,r){var a;const s={startRow:e,startColumn:t,ySplit:n,xSplit:o};this._clearFreeze(),this._createFreeze(0,s),this._createFreeze(1,s),this._updateViewport(e,t,n,o,r),(a=this._getSheetObject())==null||a.spreadsheet.makeForceDirty()}};wn=hd([l.OnLifecycle(l.LifecycleStages.Rendered,wn),Pe(0,N.Inject(exports.SheetSkeletonManagerService)),Pe(1,l.IUniverInstanceService),Pe(2,l.ICommandService),Pe(3,b.IRenderManagerService),Pe(4,_e),Pe(5,N.Inject(S.SelectionManagerService)),Pe(6,N.Inject(Je)),Pe(7,N.Inject(l.ThemeService)),Pe(8,N.Inject(S.SheetInterceptorService)),Pe(9,N.Inject(N.Injector))],wn);var Ti=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(Ti||{});const pd="rgba(0, 0, 0, 0.15)",je="rgb(0, 0, 0)",ln="rgb(255, 255, 255, 1)";class vd extends b.Shape{constructor(t,n){super(t,n);C(this,"_size",12);C(this,"_iconRatio",.4);C(this,"_mode",0);this.setShapeProps(n)}setShapeProps(t){t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),this.transformByState({width:this._size,height:this._size})}_draw(t){this._mode===1&&b.Rect.drawWith(t,{width:this._size,height:this._size,radius:this._size,fill:pd});const n=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=n*Math.sin(o),s=n*Math.cos(o);b.RegularPolygon.drawWith(t,{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:n+this._size/2}]],fill:je})}}var Cd=Object.defineProperty,Id=Object.getOwnPropertyDescriptor,Rd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Id(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Cd(e,t,o),o},dt=(i,e)=>(t,n)=>e(t,n,i);const Md="__SpreadsheetHeaderMenuSHAPEControllerShape__",bd="__SpreadsheetHeaderMenuMAINControllerShape__",wd="rgba(0, 0, 0, 0.1)";let Tn=class extends l.Disposable{constructor(e,t,n,o,r,s){super();C(this,"_hoverRect");C(this,"_hoverMenu");C(this,"_currentColumn",Number.POSITIVE_INFINITY);C(this,"_observers",[]);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,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:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerEnterObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)})}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._hoverRect=new b.Rect(Md,{fill:wd,evented:!1}),this._hoverMenu=new vd(bd,{zIndex:100,visible:!1}),t.addObjects([this._hoverRect,this._hoverMenu],qe),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetColumnHeader:n,spreadsheetRowHeader:o}=t,r=e===0?o:n;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,R,M;const a=(v=this._sheetSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(a==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=a,{startX:h,startY:m,endX:g,endY:_,column:f}=Rt(s.offsetX,s.offsetY,c.scene,a);if(e===0)(R=this._hoverRect)==null||R.transformByState({width:d,height:_-m,left:0,top:m});else{if(this._currentColumn=f,(M=this._hoverRect)==null||M.transformByState({width:g-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(g-h<u*2){this._hoverMenu.hide();return}const T=u*.8;this._hoverMenu.transformByState({left:g-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,a;(s=this._hoverRect)==null||s.hide(),(a=this._hoverMenu)==null||a.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ti.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:Ti.NORMAL,visible:!1}),e.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(e=>{if(!this._getSheetObject())return;const n=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();if(!!!(o!=null&&o.filter(s=>s.rangeType===l.RANGE_TYPE.COLUMN).find(s=>{const{startColumn:a,endColumn:c}=s;return n>=a&&n<=c}))){const s=this._getSelectionOnColumn(n);this._commandService.syncExecuteCommand(S.SetSelectionsOperation.id,s)}e.stopPropagation(),e.preventDefault(),this._contextMenuService.triggerContextMenu(e,ce.COL_HEADER_CONTEXT_MENU)}))}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}_getSelectionOnColumn(e){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet();return{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:{startRow:0,startColumn:e,endRow:n.getRowCount()-1,endColumn:e,rangeType:l.RANGE_TYPE.COLUMN},primary:{startRow:0,startColumn:e,endRow:0,endColumn:e,actualRow:0,actualColumn:e,isMerged:!1,isMergedMainCell:!1},style:null}]}}};Tn=Rd([l.OnLifecycle(l.LifecycleStages.Rendered,Tn),dt(0,N.Inject(exports.SheetSkeletonManagerService)),dt(1,l.IUniverInstanceService),dt(2,b.IRenderManagerService),dt(3,I.IContextMenuService),dt(4,l.ICommandService),dt(5,N.Inject(S.SelectionManagerService))],Tn);var Td=Object.defineProperty,Ed=Object.getOwnPropertyDescriptor,yd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ed(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Td(e,t,o),o},ut=(i,e)=>(t,n)=>e(t,n,i);const Od="__SpreadsheetHeaderMoveControllerBackground__",xd="__SpreadsheetHeaderMoveControllerShapeLine__",Ad="rgba(0, 0, 0, 0.1)",Nd="rgb(119, 119, 119)",Dd=4;let En=class extends l.Disposable{constructor(e,t,n,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=t,this._renderManagerService=n,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:t,spreadsheetColumnHeader:n,scene:o}=e;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(a=>{t.onPointerDownObserver.remove(a),n.onPointerDownObserver.remove(a)}),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:t,spreadsheetRowHeader:n,scene:o}=this._sheetObject,r=e===0?n:t;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const a=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(a==null)return;const{row:c,column:d}=Rt(s.offsetX,s.offsetY,o,a);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,a;(s=this._moveHelperBackgroundShape)==null||s.hide(),(a=this._moveHelperLineShape)==null||a.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var w;const a=(w=this._sheetSkeletonManagerService.getCurrent())==null?void 0:w.skeleton;if(a==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:g,column:_}=Rt(s.offsetX,s.offsetY,o,a);let f;e===0?(this._changeFromRow=g,f=b.ScrollTimerType.Y):(this._changeFromColumn=_,f=b.ScrollTimerType.X);const v=this._checkInHeaderRange(e===0?g:_,e);if(v===!1)return;const R=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(b.CURSOR_TYPE.GRABBING),o.disableEvent();let M=!1,T;const E=()=>{if(M)return;T=b.ScrollTimer.create(o,f);const y=o.getViewport(V.VIEW_MAIN);T.startScroll(h,m,y),this._scrollTimer=T,M=!0};this._moveObserver=o.onPointerMoveObserver.add(y=>{E();const{offsetX:O,offsetY:x}=y,{x:A,y:B}=o.getRelativeCoord(b.Vector2.FromArray([O,x]));o.setCursor(b.CURSOR_TYPE.GRABBING),this._rowColumnMoving(A,B,v,R,e),T.scrolling(A,B,()=>{this._rowColumnMoving(A,B,v,R,e)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var O,x,A;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 P=(x=((y==null?void 0:y.filter(F=>F.range.rangeType===l.RANGE_TYPE.ROW&&F.range.startRow<=this._changeFromRow&&this._changeFromRow<=F.range.endRow))||[])[0])==null?void 0:x.range;P&&this._commandService.executeCommand(S.MoveRowsCommand.id,{fromRange:P,toRange:{...P,startRow:this._changeToRow,endRow:this._changeToRow+P.endRow-P.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const P=(A=((y==null?void 0:y.filter(F=>F.range.rangeType===l.RANGE_TYPE.COLUMN&&F.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=F.range.endColumn))||[])[0])==null?void 0:A.range;P&&this._commandService.executeCommand(S.MoveColsCommand.id,{fromRange:P,toRange:{...P,startColumn:this._changeToColumn,endColumn:this._changeToColumn+P.endColumn-P.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})}))}_rowColumnMoving(e,t,n,o,r){var J,re,Y,U,L,X,ee;const{scene:s}=this._sheetObject,a=(J=this._sheetSkeletonManagerService.getCurrent())==null?void 0:J.skeleton;if(a==null)return;const{rowHeaderWidth:c,columnHeaderHeight:d,rowTotalHeight:u,columnTotalWidth:h}=a,m=s.getScrollXY(s.getViewport(V.VIEW_MAIN)),{scaleX:g,scaleY:_}=s.getAncestorScale(),f=a.getCellPositionByOffset(e,t,g,_,m),{row:v,column:R}=f,M=a.getNoMergeCellPositionByIndex(v,R),{startX:T,startY:E,endX:w,endY:y}=M,O=this._selectionRenderService.convertRangeDataToSelection(n.range);if(O==null)return;const x=Math.max(g,g),{startX:A,endX:B,startY:P,endY:F,startRow:k,startColumn:j,endRow:$,endColumn:G}=O;r===0?(re=this._moveHelperBackgroundShape)==null||re.transformByState({height:F-P,width:h+c,left:0,top:P+(t-this._startOffsetY)/x+m.y-o.y}):(Y=this._moveHelperBackgroundShape)==null||Y.transformByState({height:u+d,width:B-A,left:A+(e-this._startOffsetX)/x+m.x-o.x,top:0}),(U=this._moveHelperBackgroundShape)==null||U.show();const W=Dd/x;if(r===0){let ie=0;if(v<=k)ie=E-W/2,this._changeToRow=v;else if(v>$)ie=y-W/2,this._changeToRow=v+1;else return;(L=this._moveHelperLineShape)==null||L.transformByState({height:W,width:h,left:c,top:ie})}else{let ie=0;if(R<=j)ie=T-W/2,this._changeToColumn=R;else if(R>G)ie=w-W/2,this._changeToColumn=R+1;else return;(X=this._moveHelperLineShape)==null||X.transformByState({height:u,width:W,left:ie,top:d})}(ee=this._moveHelperLineShape)==null||ee.show()}_checkInHeaderRange(e,t=0){var a;const n=this._selectionManagerService.getSelections();if(((a=this._selectionManagerService.getCurrent())==null?void 0:a.pluginName)!==S.NORMAL_SELECTION_PLUGIN_NAME)return!1;const r=n==null?void 0:n.find(c=>{const d=c.range,{startRow:u,endRow:h,startColumn:m,endColumn:g,rangeType:_}=d;return t===1?e>=m&&e<=g&&l.RANGE_TYPE.COLUMN===_:e>=u&&e<=h&&l.RANGE_TYPE.ROW===_}),s=r==null?void 0:r.range;return r==null||s==null||s.rangeType===l.RANGE_TYPE.ALL||s.rangeType===l.RANGE_TYPE.NORMAL||s.rangeType===l.RANGE_TYPE.ROW&&t!==0||s.rangeType===l.RANGE_TYPE.COLUMN&&t!==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(Od,{fill:Ad,evented:!1,zIndex:100}),this._moveHelperLineShape=new b.Rect(xd,{fill:Nd,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],qe)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}};En=yd([l.OnLifecycle(l.LifecycleStages.Rendered,En),ut(0,N.Inject(exports.SheetSkeletonManagerService)),ut(1,l.IUniverInstanceService),ut(2,b.IRenderManagerService),ut(3,l.ICommandService),ut(4,_e),ut(5,N.Inject(S.SelectionManagerService))],En);var Ei=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(Ei||{});const Pd="rgba(120, 120, 120, 0.01)",hi="rgb(68, 71, 70)",Wt=12,yi=4;class Ao extends b.Shape{constructor(t,n){super(t,n);C(this,"_size",Wt);C(this,"_color",hi);C(this,"_mode",0);this.setShapeProps(n)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(t){let{width:n,height:o}=this,r=0,s=0;const a=this.getScene(),{scaleX:c,scaleY:d}=a.getAncestorScale(),u=Math.max(c,d),h=Wt/u,m=yi/u;this.mode===0?(n=m,r=h-m):(o=m,s=h-m),b.Rect.drawWith(t,{width:this.width,height:this.height,left:0,top:0,fill:Pd}),b.Rect.drawWith(t,{width:n,height:o,fill:hi,radius:m}),t.save(),t.transform(1,0,0,1,r,s),b.Rect.drawWith(t,{width:n,height:o,fill:hi,radius:m}),t.restore()}setShapeProps(t){return t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),t!=null&&t.color&&(this._color=t.color),this.mode===0?this.transformByState({width:Wt,height:this.size}):this.transformByState({width:this.size,height:Wt}),this}}var Hd=Object.defineProperty,Ld=Object.getOwnPropertyDescriptor,Ud=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ld(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Hd(e,t,o),o},Bt=(i,e)=>(t,n)=>e(t,n,i);const kd="__SpreadsheetHeaderResizeControllerShapeRow__",Vd="__SpreadsheetHeaderResizeControllerShapeColumn__",No="__SpreadsheetHeaderResizeControllerShapeHelper__",Do="rgb(199, 199, 199)",Bd=2;let yn=class extends l.Disposable{constructor(e,t,n,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=t,this._commandService=n,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:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._rowResizeRect=new Ao(kd,{visible:!1,mode:Ei.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Ao(Vd,{visible:!1,mode:Ei.VERTICAL,zIndex:100}),t.addObjects([this._rowResizeRect,this._columnResizeRect],qe),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:o,scene:r}=t,s=e===0?n:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((a,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:g,endX:_,endY:f,row:v,column:R}=Rt(a.offsetX,a.offsetY,r,d),M=hn(a.offsetX,a.offsetY,r),{scaleX:T,scaleY:E}=r.getAncestorScale(),w=Math.max(T,E),y=Wt/w;if(e===0){let x=g-y/2;if(M.y<=g+y/2&&M.y>=g)this._currentRow=v-1;else if(M.y>=f-y/2&&M.y<=f)this._currentRow=v,x=f-y/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const A=u/3;this._rowResizeRect.transformByState({left:u/2-A/2,top:x}),this._rowResizeRect.setShapeProps({size:A}),this._rowResizeRect.show()}else{let x=m-y/2;if(M.x<=m+y/2&&M.x>=m)this._currentColumn=R-1;else if(M.x>=_-y/2&&M.x<=_)this._currentColumn=R,x=_-y/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const A=h*.7;this._columnResizeRect.transformByState({left:x,top:h/2-A/2}),this._columnResizeRect.setShapeProps({size:A}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((a,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(e=0){const t=this._getSheetObject();if(t==null)return;const{scene:n}=t,o=e===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=n.getEngine(),s=(r==null?void 0:r.width)||0,a=(r==null?void 0:r.height)||0;this.disposeWithMe(l.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),n.setCursor(e===0?b.CURSOR_TYPE.ROW_RESIZE:b.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(l.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),n.resetCursor())}))),this.disposeWithMe(l.toDisposable(o.onPointerDownObserver.add((c,d)=>{var re,Y,U,L,X,ee,ie;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,g=m.getViewport(V.VIEW_MAIN),_=(((U=(Y=g==null?void 0:g.getScrollBar())==null?void 0:Y.horizonBarRect)==null?void 0:U.height)||0)+10,f=(((X=(L=g==null?void 0:g.getScrollBar())==null?void 0:L.verticalBarRect)==null?void 0:X.width)||0)+10,v=hn(c.offsetX,c.offsetY,m),{scaleX:R,scaleY:M}=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:A,rowHeaderWidth:B,rowTotalHeight:P,columnHeaderHeight:F}=u,k=s>A+B?s:A+B,j=a>P+F?a:P+F,$=Math.max(R,M),G=yi/$;e===0?this._resizeHelperShape=new b.Rect(No,{width:k,height:G,fill:Do,left:0,top:E-G/2}):this._resizeHelperShape=new b.Rect(No,{width:G,height:j,fill:Do,left:T-G/2,top:0});const W=((ee=this._columnResizeRect)==null?void 0:ee.left)||0,J=((ie=this._rowResizeRect)==null?void 0:ie.top)||0;m.addObject(this._resizeHelperShape,qe),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(z=>{var Ve,ve,At,Nt,Dt,Pt;const Z=m.getRelativeCoord(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),K=m.getScrollXYByRelativeCoords(Z,g),le=hn(z.offsetX,z.offsetY,m),{x:se,y:me}=le,{scaleX:ke,scaleY:pe}=m.getAncestorScale(),ue=Math.max(ke,pe),ae=yi/ue;O=se-this._startOffsetX-ae/2,x=me-this._startOffsetY-ae/2,Math.abs(e===0?x:O)>=Bd&&(y=!0),e===0?(x>a-_+K.y-w.startY&&(x=a-_+K.y-w.startY),x<-(w.endY-w.startY)+2&&(x=-(w.endY-w.startY)+2),y&&((Ve=this._resizeHelperShape)==null||Ve.transformByState({top:E+x}),(ve=this._rowResizeRect)==null||ve.transformByState({top:J+x+ae/2}),(At=this._rowResizeRect)==null||At.show(),m.setCursor(b.CURSOR_TYPE.ROW_RESIZE))):(O>s-f+K.x-w.startX&&(O=s-f+K.x-w.startX),O<-(w.endX-w.startX)+2&&(O=-(w.endX-w.startX)+2),y&&((Nt=this._resizeHelperShape)==null||Nt.transformByState({left:T+O}),(Dt=this._columnResizeRect)==null||Dt.transformByState({left:W+O+ae/2}),(Pt=this._columnResizeRect)==null||Pt.show(),m.setCursor(b.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(z=>{var le,se,me;const Z=Ce(this._currentUniverService,this._renderManagerService);if(Z==null)return;this._clearObserverEvent(),(le=this._resizeHelperShape)==null||le.dispose(),this._resizeHelperShape=null;const{scene:K}=Z;K.enableEvent(),y&&(K.resetCursor(),(se=this._rowResizeRect)==null||se.hide(),(me=this._columnResizeRect)==null||me.hide(),e===0?this._commandService.executeCommand(S.DeltaRowHeightCommand.id,{deltaY:x,anchorRow:this._currentRow}):this._commandService.executeCommand(S.DeltaColumnWidthCommand.id,{deltaX:O,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(l.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(S.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}};yn=Ud([l.OnLifecycle(l.LifecycleStages.Rendered,yn),Bt(0,N.Inject(exports.SheetSkeletonManagerService)),Bt(1,l.IUniverInstanceService),Bt(2,l.ICommandService),Bt(3,b.IRenderManagerService),Bt(4,Te)],yn);var Oi=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(Oi||{});const jt=12,Fd=.4;class Po extends b.Shape{constructor(t,n,o){super(t,n);C(this,"_size",jt);C(this,"_iconRatio",Fd);C(this,"_hovered",!0);C(this,"_hasPrevious",!0);C(this,"_hasNext",!0);C(this,"_unhideType");n&&this.setShapeProps(n),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(t){t.type!==void 0&&(this._unhideType=t.type),t.hovered!==void 0&&(this._hovered=t.hovered),t.hasPrevious!==void 0&&(this._hasPrevious=t.hasPrevious),t.hasNext!==void 0&&(this._hasNext=t.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(t){this._unhideType===0?this._drawOnRow(t):this._drawOnCol(t)}_drawOnRow(t){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(t,{width:this._size,height:this._size,stroke:je,fill:ln}):b.Rect.drawWith(t,{width:this._size,height:2*this._size,stroke:je,fill:ln}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(t,{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:je}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:this._size/2,y:this._size*a/2+s},{x:this._size/2-s,y:this._size*a/2-r},{x:this._size/2+s,y:this._size*a/2-r}]],fill:je})}}_drawOnCol(t){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(t,{width:this._size,height:this._size,stroke:je,fill:ln}):b.Rect.drawWith(t,{width:2*this._size,height:this._size,stroke:je,fill:ln}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(t,{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:je}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:r+this._size*a/2,y:this._size/2},{x:-s+this._size*a/2,y:this._size/2-s},{x:-s+this._size*a/2,y:this._size/2+s}]],fill:je})}}}var Wd=Object.defineProperty,jd=Object.getOwnPropertyDescriptor,$d=(i,e,t,n)=>{for(var o=n>1?void 0:n?jd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Wd(e,t,o),o},cn=(i,e)=>(t,n)=>e(t,n,i);const Ho="__SpreadsheetHeaderUnhideSHAPEControllerShape__",zd=[S.SetRowHiddenMutation.id,S.SetRowVisibleMutation.id,S.SetColHiddenMutation.id,S.SetColVisibleMutation.id];let On=class extends l.RxDisposable{constructor(e,t,n,o){super();C(this,"_shapes",new Map);this._sheetSkeletonManagerService=e,this._cmdSrv=t,this._univerInstanceService=n,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const t=this._univerInstanceService.getCurrentUniverSheetInstance(),n=t.getActiveSheet();n&&this._initForWorksheet(t,n),this._sheetSkeletonManagerService.currentSkeleton$.pipe(D.takeUntil(this.dispose$),D.startWith(void 0),D.pairwise()).subscribe(([o,r])=>{if(r){const s=this._univerInstanceService.getUniverSheetInstance(r.unitId),a=s.getSheetBySheetId(r.sheetId);this._updateWorksheet(s,a,o==null?void 0:o.sheetId)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!zd.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,t){var m;const n=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!n)return;const o=t.getHiddenRows(),r=t.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:a}=s,c=t.getRowCount(),d=o.map(g=>{const{startRow:_,endRow:f}=g,v=wi(_,0,a,n),R=_!==0,M=f!==c-1;return new Po(Ho,{type:Oi.ROW,hovered:!1,hasPrevious:R,hasNext:M,top:v.startY-(R?jt:0),left:v.startX-jt},()=>this._cmdSrv.executeCommand(S.SetSpecificRowsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[g]}))}),u=t.getColumnCount(),h=r.map(g=>{const{startColumn:_,endColumn:f}=g,v=wi(0,_,a,n),R=_!==0,M=f!==u-1;return new Po(Ho,{type:Oi.COLUMN,hovered:!1,hasPrevious:R,hasNext:M,left:v.startX-(R?jt:0),top:20-jt},()=>this._cmdSrv.executeCommand(S.SetSpecificColsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[g]}))});a.addObjects(h,co),a.addObjects(d,co),this._shapes.set(l.getWorksheetUID(e,t),{cols:h,rows:d})}_updateWorksheet(e,t,n){if(n){const o=this._shapes.get(`${e.getUnitId()}|${n}`);o==null||o.cols.forEach(r=>r.dispose()),o==null||o.rows.forEach(r=>r.dispose())}this._initForWorksheet(e,t)}_getSheetObject(){return Ce(this._univerInstanceService,this._rendererManagerService)}};On=$d([l.OnLifecycle(l.LifecycleStages.Rendered,On),cn(0,N.Inject(exports.SheetSkeletonManagerService)),cn(1,l.ICommandService),cn(2,l.IUniverInstanceService),cn(3,b.IRenderManagerService)],On);var Yd=Object.defineProperty,Xd=Object.getOwnPropertyDescriptor,Zd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Xd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Yd(e,t,o),o},mi=(i,e)=>(t,n)=>e(t,n,i);let xn=class extends l.Disposable{constructor(i,e,t){super(),this._markSelectionService=i,this._commandService=e,this._sheetSkeletonManagerService=t,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[He.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)?this._markSelectionService.removeAllShapes():this._markSelectionService.getShapeMap().forEach((n,o)=>{n.exits.includes(e.id)&&this._markSelectionService.removeShape(o)})}))}_addRefreshListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};xn=Zd([l.OnLifecycle(l.LifecycleStages.Steady,xn),mi(0,N.Inject(qt)),mi(1,l.ICommandService),mi(2,N.Inject(exports.SheetSkeletonManagerService))],xn);var Gd=Object.defineProperty,Kd=Object.getOwnPropertyDescriptor,qd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Kd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Gd(e,t,o),o},gi=(i,e)=>(t,n)=>e(t,n,i);let An=class extends l.Disposable{constructor(e,t,n){super();C(this,"_initialize",()=>{const e=new l.DisposableCollection;this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{e.dispose();const t=this._selectionManagerService.getCurrent();if((t==null?void 0:t.pluginName)!==S.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{e.add(l.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),a={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(a.startRow===c.startRow&&a.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:a,toRange:c};this._commandService.executeCommand(S.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=e,this._selectionManagerService=t,this._commandService=n,this._initialize()}};An=qd([l.OnLifecycle(l.LifecycleStages.Steady,An),gi(0,N.Inject(_e)),gi(1,N.Inject(S.SelectionManagerService)),gi(2,N.Inject(l.ICommandService))],An);var Jd=Object.defineProperty,Qd=Object.getOwnPropertyDescriptor,eu=(i,e,t,n)=>{for(var o=n>1?void 0:n?Qd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Jd(e,t,o),o},ht=(i,e)=>(t,n)=>e(t,n,i);let vt=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}scrollToVisible(i=!0){var F,k,j,$;let e,t;const n=this._selectionManagerService.getLast();if(n==null)return;const{startRow:o,startColumn:r,actualRow:s,actualColumn:a}=n.primary,c=i?s:o,d=i?a:r,{rowHeightAccumulation:u,columnWidthAccumulation:h}=(k=(F=this._sheetSkeletonManagerService.getCurrent())==null?void 0:F.skeleton)!=null?k:{};if(u==null||h==null)return;const m=(j=this._getSheetObject())==null?void 0:j.scene;if(m==null)return;const g=m.getViewport(V.VIEW_MAIN);if(g==null||this._getSheetObject()==null)return;const f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:v,startRow:R,ySplit:M,xSplit:T}=f.getFreeze(),E=g.getBounding(),w=($=this._sheetSkeletonManagerService.getCurrent())==null?void 0:$.skeleton;if(w==null)return;const{startRow:y,startColumn:O,endRow:x,endColumn:A}=w.getRowColumnSegment(E);if(c>=R&&d>=v-T&&(c<=y&&(e=c),c>=x)){const G=u[c]-g.height;for(let W=y;W<=c;W++)if(u[W]>=G){e=W+1;break}}if(d>=v&&c>=R-M&&(d<=O&&(t=d),d>=A)){const G=h[d]-g.width;for(let W=O;W<=d;W++)if(h[W]>=G){t=W+1;break}}if(e===void 0&&t===void 0)return;const{offsetX:B,offsetY:P}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(pt.id,{sheetViewStartRow:e,sheetViewStartColumn:t,offsetX:t===void 0?B:0,offsetY:e===void 0?P: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 t;const i=(t=this._getSheetObject())==null?void 0:t.scene;if(i==null)return;const e=i.getViewport(V.VIEW_MAIN);this.disposeWithMe(l.toDisposable(e==null?void 0:e.onScrollAfterObserver.add(n=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,a);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(l.toDisposable(e==null?void 0:e.onScrollByBarObserver.add(n=>{var g;const o=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,c=this._getFreeze(),{row:d,column:u,rowOffset:h,columnOffset:m}=o.getDecomposedOffset(s,a);this._commandService.executeCommand(pt.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(l.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var _;const e=(_=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_.skeleton,t=this._getSheetObject();if(e==null||t==null)return;const n=t.scene;t.scene.getAncestorScale();const o=n.getViewport(V.VIEW_MAIN);if(o==null)return;if(i==null){o.scrollTo({x:0,y:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:a,offsetY:c}=i,{startX:d,startY:u}=e.getCellByIndexWithNoHeader(r,s),h=d+a,m=u+c,g=o.getBarScroll(h,m);o.scrollTo(g)})))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t}=i;this._renderManagerService.getRenderById(e)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:e,sheetId:t}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:e,unitId:t}=i,n=(c=this._renderManagerService.getRenderById(t))==null?void 0:c.scene;if(e==null||n==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=e;n==null||n.transformByState({width:s+r,height:a+o})}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}};vt=eu([l.OnLifecycle(l.LifecycleStages.Rendered,vt),ht(0,N.Inject(exports.SheetSkeletonManagerService)),ht(1,l.IUniverInstanceService),ht(2,l.ICommandService),ht(3,b.IRenderManagerService),ht(4,N.Inject(S.SelectionManagerService)),ht(5,N.Inject(Je))],vt);var tu=Object.defineProperty,nu=Object.getOwnPropertyDescriptor,iu=(i,e,t,n)=>{for(var o=n>1?void 0:n?nu(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&tu(e,t,o),o},Lo=(i,e)=>(t,n)=>e(t,n,i);const ou=[we.id,lt.id];let Nn=class extends l.Disposable{constructor(i,e){super(),this._commandService=i,this._scrollController=e,this.disposeWithMe(this._commandService.onCommandExecuted(t=>{ou.includes(t.id)&&this._scrollController.scrollToVisible()}))}};Nn=iu([l.OnLifecycle(l.LifecycleStages.Rendered,Nn),Lo(0,l.ICommandService),Lo(1,N.Inject(vt))],Nn);var ru=Object.defineProperty,su=Object.getOwnPropertyDescriptor,au=(i,e,t,n)=>{for(var o=n>1?void 0:n?su(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ru(e,t,o),o},Ze=(i,e)=>(t,n)=>e(t,n,i);let Dn=class extends l.Disposable{constructor(i,e,t,n,o,r,s,a){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._scrollController=a,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),e=i.getActiveSheet(),t=this._getSheetObject();if(t==null)return;this._initViewMainListener(t),this._initRowHeader(t),this._initColumnHeader(t),this._initLeftTop(t),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const n=i.getUnitId(),o=e.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:S.NORMAL_SELECTION_PLUGIN_NAME,unitId:n,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(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,n)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,e.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(t)),t.button!==2&&n.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(l.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)!==S.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){const e=i.map(t=>{const n=this._selectionRenderService.convertSelectionRangeToData(t);return n.style=S.getNormalSelectionStyle(this._themeService),n});this._selectionRenderService.updateControlForCurrentByRangeData(e)}_initRowHeader(i){const{spreadsheetRowHeader:e,spreadsheet:t}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((t==null?void 0:t.zIndex)||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(n),b.ScrollTimerType.Y),n.button!==2&&o.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:e,spreadsheet:t}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((t==null?void 0:t.zIndex)||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(n),b.ScrollTimerType.X),n.button!==2&&o.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:e}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,n)=>{var a;const o=(a=this._sheetSkeletonManagerService.getCurrent())==null?void 0:a.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(),t.button!==2&&n.stopPropagation()})))}_initSelectionChangeListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const e of i){if(e==null)continue;const t=this._selectionRenderService.convertSelectionRangeToData(e);this._selectionRenderService.addControlToCurrentByRangeData(t)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,S.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,S.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,S.SelectionMoveType.MOVE_END)})}_move(i,e){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId(),o=t.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(S.SetSelectionsOperation.id,{unitId:n,subUnitId:o,type:e,pluginName:(r==null?void 0:r.pluginName)||S.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>S.convertSelectionDataToRange(s))})}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[ze.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t,skeleton:n}=i,o=this._renderManagerService.getRenderById(e);if(o==null)return;const{scene:r}=o,s=r.getViewport(V.VIEW_MAIN);this._selectionRenderService.changeRuntime(n,r,s);const a=this._selectionManagerService.getCurrent(),c=(a==null?void 0:a.pluginName)||S.NORMAL_SELECTION_PLUGIN_NAME;if((a==null?void 0:a.unitId)===e&&a.sheetId===t){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:e,sheetId:t});c===S.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(n)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const e=i.mergeData;return S.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}}};Dn=au([l.OnLifecycle(l.LifecycleStages.Rendered,Dn),Ze(0,N.Inject(exports.SheetSkeletonManagerService)),Ze(1,l.IUniverInstanceService),Ze(2,l.ICommandService),Ze(3,b.IRenderManagerService),Ze(4,_e),Ze(5,N.Inject(S.SelectionManagerService)),Ze(6,N.Inject(l.ThemeService)),Ze(7,N.Inject(vt))],Dn);var lu=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,du=(i,e,t,n)=>{for(var o=n>1?void 0:n?cu(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&lu(e,t,o),o},mt=(i,e)=>(t,n)=>e(t,n,i);let Pn=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:t,sheetId:n}=i,o=this._currentUniverService.getUniverSheetInstance(t),r=o==null?void 0:o.getSheetBySheetId(n);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(t);if(s==null)return;const{mainComponent:a,components:c,scene:d}=s,u=a,h=c.get(Se.ROW),m=c.get(Se.COLUMN),g=c.get(Se.LEFT_TOP),{rowHeaderWidth:_,columnHeaderHeight:f}=e;u==null||u.updateSkeleton(e),h==null||h.updateSkeleton(e),m==null||m.updateSkeleton(e),g==null||g.transformByState({width:_,height:f})})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((i,e)=>{var o,r;const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId();if(S.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const s=t.getActiveSheet(),a=s.getSheetId(),c=i.params,{unitId:d,subUnitId:u}=c;if(!(d===t.getUnitId()&&u===s.getSheetId()))return;i.id!==S.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:d,sheetId:a,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:d,sheetId:a,commandId:i.id})}else S.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===l.CommandType.MUTATION&&((r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.mainComponent)==null||r.makeDirty())}))}};Pn=du([l.OnLifecycle(l.LifecycleStages.Ready,Pn),mt(0,N.Inject(exports.SheetSkeletonManagerService)),mt(1,l.IUniverInstanceService),mt(2,b.IRenderManagerService),mt(3,l.ICommandService),mt(4,_e),mt(5,N.Inject(S.SelectionManagerService))],Pn);const Ye={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,e)=>{const t=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(I.IConfirmService),s=i.get(l.LocaleService),a=e.unitId,c=e.subUnitId,d=e.selections,u=S.getAddMergeMutationRangeByType(d,e.value),h=o.getUniverSheetInstance(a).getSheetBySheetId(c),m=[],g=[],_=Nr(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:a,subUnitId:c,ranges:u},v={unitId:a,subUnitId:c,ranges:u};m.push({id:S.RemoveWorksheetMergeMutation.id,params:f}),m.push({id:S.AddWorksheetMergeMutation.id,params:v});const R=S.RemoveMergeUndoMutationFactory(i,f),M=S.AddMergeUndoMutationFactory(i,v);if(g.push({id:S.RemoveWorksheetMergeMutation.id,params:M}),g.push({id:S.AddWorksheetMergeMutation.id,params:R}),_){const E=Dr(i,a,h,u);m.unshift(...E.redos),g.push(...E.undos)}return l.sequenceExecute(m,t).result?(n.pushUndoRedo({unitID:a,undoMutations:g,redoMutations:m}),!0):!1}},Xr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(S.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ye.id,{selections:n,unitId:a,subUnitId:c})}},Zr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(S.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ye.id,{value:l.Dimension.COLUMNS,selections:n,unitId:a,subUnitId:c})}},Gr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(S.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ye.id,{value:l.Dimension.ROWS,selections:n,unitId:a,subUnitId:c})}},zi={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(S.SelectionManagerService),r=i.get(l.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=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const _=l.Rectangle.getIntersects(g,d);return _?u(g)>u(_):!1})||await e.confirm({id:zi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(S.DeleteRangeMoveLeftCommand.id):!0}},Yi={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(S.SelectionManagerService),r=i.get(l.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=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const _=l.Rectangle.getIntersects(g,d);return _?u(g)>u(_):!1})||await e.confirm({id:Yi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(S.DeleteRangeMoveUpCommand.id):!0}},Xi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(S.SelectionManagerService),r=i.get(l.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=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const _=l.Rectangle.getIntersects(g,d);return _?u(g)>u(_):!1})||await e.confirm({id:Xi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(S.InsertRangeMoveDownCommand.id):!0}},Zi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(S.SelectionManagerService),r=i.get(l.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=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const _=l.Rectangle.getIntersects(g,d);return _?u(g)>u(_):!1})||await e.confirm({id:Zi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(S.InsertRangeMoveRightCommand.id):!0}},Kr={id:"sheet.command.refill",type:l.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(Jt);return t.applyType=e.type,!0}},qr={id:"sheet.command.remove-row-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{var d;const t=i.get(S.SelectionManagerService);let n=e==null?void 0:e.range;if(n||(n=(d=t.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(cr(c,[n])){const u=i.get(I.IConfirmService),h=i.get(l.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(S.RemoveRowCommand.id,{range:n}),!0}},Jr={id:"sheet.command.remove-col-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{var d;const t=i.get(S.SelectionManagerService);let n=e==null?void 0:e.range;if(n||(n=(d=t.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(dr(c,[n])){const u=i.get(I.IConfirmService),h=i.get(l.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(S.RemoveColCommand.id,{range:n}),!0}},Qr={id:"sheet.command.remove-sheet-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{const{subUnitId:t}=e,n=i.get(I.IConfirmService),o=i.get(l.ICommandService),r=i.get(l.LocaleService);return await n.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(S.RemoveSheetCommand.id,{subUnitId:t}),!0):!1}},xt=N.createIdentifier("univer.sheetbar-service");class uu extends l.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 D.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new D.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new D.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new D.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new D.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(t){this._renameId$.next(t)}setRemoveId(t){this._removeId$.next(t)}setScroll(t){this._scroll$.next(t)}setScrollX(t){this._scrollX$.next(t)}setAddSheet(t){this._addSheet$.next(t)}triggerSheetBarMenu(){var t;(t=this._currentHandler)==null||t.handleSheetBarMenu()}registerSheetBarMenuHandler(t){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=t,l.toDisposable(()=>{this._currentHandler=null})}}const es={id:"ui-sheet.command.show-menu-list",type:l.CommandType.OPERATION,handler:async i=>(i.get(xt).triggerSheetBarMenu(),!0)},ts={id:"sheet.operation.rename-sheet",type:l.CommandType.OPERATION,handler:async(i,e)=>{const t=i.get(xt);return e&&t.setRenameId(e.subUnitId),!0}},hu=()=>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"})]}),mu=()=>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"})]}),gu=()=>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"})]}),_u=()=>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"})]}),Su=()=>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"})}),fu=()=>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"})]}),pu=()=>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"})]}),vu=()=>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"})}),Uo=()=>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 ko(i){const{type:e=l.BorderStyleTypes.THIN}=i;switch(e){case l.BorderStyleTypes.DASH_DOT:return p.jsx(hu,{});case l.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(mu,{});case l.BorderStyleTypes.DASHED:return p.jsx(gu,{});case l.BorderStyleTypes.HAIR:return p.jsx(_u,{});case l.BorderStyleTypes.MEDIUM:return p.jsx(Su,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(fu,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(pu,{});case l.BorderStyleTypes.MEDIUM_DASHED:return p.jsx(vu,{});case l.BorderStyleTypes.THICK:return p.jsx(Cu,{});case l.BorderStyleTypes.THIN:return p.jsx(Uo,{});default:return p.jsx(Uo,{})}}const Iu="univer-ui-plugin-sheets-border-panel",Ru="univer-ui-plugin-sheets-border-panel-position",Mu="univer-ui-plugin-sheets-border-panel-position-item",bu="univer-ui-plugin-sheets-border-panel-styles",wu="univer-ui-plugin-sheets-border-panel-board",Tu="univer-ui-plugin-sheets-border-panel-button",Eu="univer-ui-plugin-sheets-border-panel-more-icon",We={uiPluginSheetsBorderPanel:Iu,uiPluginSheetsBorderPanelPosition:Ru,uiPluginSheetsBorderPanelPositionItem:Mu,uiPluginSheetsBorderPanelStyles:bu,uiPluginSheetsBorderPanelBoard:wu,uiPluginSheetsBorderPanelButton:Tu,uiPluginSheetsBorderPanelMoreIcon:Eu},ns=`${Et}_BORDER_PANEL_COMPONENT`,is=[{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"}],yu=[{label:l.BorderStyleTypes.THIN,value:l.BorderStyleTypes.THIN},{label:l.BorderStyleTypes.HAIR,value:l.BorderStyleTypes.HAIR},{label:l.BorderStyleTypes.DOTTED,value:l.BorderStyleTypes.DOTTED},{label:l.BorderStyleTypes.DASHED,value:l.BorderStyleTypes.DASHED},{label:l.BorderStyleTypes.DASH_DOT,value:l.BorderStyleTypes.DASH_DOT},{label:l.BorderStyleTypes.DASH_DOT_DOT,value:l.BorderStyleTypes.DASH_DOT_DOT},{label:l.BorderStyleTypes.MEDIUM,value:l.BorderStyleTypes.MEDIUM},{label:l.BorderStyleTypes.MEDIUM_DASHED,value:l.BorderStyleTypes.MEDIUM_DASHED},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:l.BorderStyleTypes.THICK,value:l.BorderStyleTypes.THICK}];function Ou(i){var a;const e=q.useDependency(I.ComponentManager),{onChange:t,value:n}=i;function o(c,d){t==null||t({...n,[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:We.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:We.uiPluginSheetsBorderPanelPosition,children:is.map(c=>p.jsx("div",{className:We.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(c.value,"type"),children:r(c.icon)},c.value))}),p.jsxs("div",{className:We.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(ge.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:We.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(ge.ColorPicker,{onChange:c=>o(c,"color")})}),children:p.jsxs("a",{className:We.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(nl,{extend:{colorChannel1:(a=n.color)!=null?a:"rgb(var(--primary-color))"}}),p.jsx("span",{className:We.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Mi,{})})]})})}),p.jsx("div",{children:p.jsx(ge.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(ge.Menu,{children:yu.map(c=>p.jsx(ge.MenuItem,{eventKey:c.value.toString(),onClick:()=>o(c.value,"style"),children:p.jsx(ko,{type:c.value})},c.value))})}),children:p.jsxs("a",{className:We.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(ko,{type:l.BorderStyleTypes.THIN}),p.jsx("span",{className:We.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Mi,{})})]})})})]})]})}const xu="univer-count-bar",Au={countBar:xu},Nu=[50,80,100,130,150,170,200,400],Du=100;function Pu(){const i=q.useDependency(l.ICommandService),e=q.useDependency(l.IUniverInstanceService),t=q.useDependency(l.IContextService),n=c(),[o,r]=H.useState(n),a=!ge.useObservable(()=>D.combineLatest(t.subscribeContextValue$(l.FOCUSING_UNIVER_EDITOR),t.subscribeContextValue$(l.EDITOR_ACTIVATED)).pipe(D.map(([u,h])=>u&&!h),D.debounceTime(Du)),!1,!0,[l.FOCUSING_UNIVER_EDITOR]);H.useEffect(()=>i.onCommandExecuted(h=>{if(h.id===ze.id||h.id===S.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 g=u/100;i.executeCommand(Qn.id,{unitId:h.getUnitId(),subUnitId:m.getSheetId(),zoomRatio:g})}return p.jsx(ge.Slider,{disabled:a,min:Ci[0],value:o,shortcuts:Nu,onChange:d})}function Hu(i){return p.jsx("section",{className:Au.countBar,children:p.jsx(Pu,{})})}const Lu="univer-editor-container",Uu="univer-editor-input",Vo={editorContainer:Lu,editorInput:Uu},$n=-1e3,Bo={width:0,height:0,top:$n,left:$n},ku=()=>{const[i,e]=H.useState({...Bo}),t=H.useRef(null),n=q.useDependency(b.IRenderManagerService),o=q.useDependency(tn);return H.useEffect(()=>{const r=t.current;if(!r)return;const s=n.currentRender$.pipe(jo.switchMap(()=>{var c;const a=(c=n.getRenderById(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:c.engine;return a==null||a.setContainer(r),o.state$})).subscribe(a=>{if(a==null)return;const{startX:c=$n,startY:d=$n,endX:u=0,endY:h=0,show:m=!1}=a;if(!m)e({...Bo});else{e({width:u-c,height:h-d,left:c,top:d});const g=t.current;if(!g)return;const{left:_,top:f,width:v,height:R}=g.getBoundingClientRect();o.setRect({left:_,top:f,width:v,height:R})}});return()=>{s.unsubscribe()}},[]),H.useEffect(()=>{o.setFocus(!0)},[i]),p.jsx("div",{className:Vo.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx("div",{className:Vo.editorInput,ref:t})})},Vu="univer-formula-box",Bu="univer-name-ranges",Fu="univer-name-ranges-input",Wu="univer-formula-bar",ju="univer-formula-icon",$u="univer-formula-icon-wrapper",zu="univer-icon-container",Yu="univer-icon-container-success",Xu="univer-formula-active",Zu="univer-icon-container-error",Gu="univer-formula-input",Ku="univer-formula-content",qu="univer-arrow-container",he={formulaBox:Vu,nameRanges:Bu,nameRangesInput:Fu,formulaBar:Wu,formulaIcon:ju,formulaIconWrapper:$u,iconContainer:zu,iconContainerSuccess:Yu,formulaActive:Xu,iconContainerError:Zu,formulaInput:Gu,formulaContent:Ku,arrowContainer:qu};function Ju(){const[i,e]=H.useState(he.formulaGrey),[t,n]=H.useState(0),o=H.useRef(null),r=q.useDependency(b.IRenderManagerService),s=q.useDependency(qn),a=q.useDependency(Te);H.useEffect(()=>{const m=o.current;if(!m)return;const g=r.currentRender$.subscribe(f=>{var R;if(f!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const v=(R=r.getRenderById(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:R.engine;v==null||v.setContainer(m)}),_=new ResizeObserver(()=>{const f=m.getBoundingClientRect();s.setPosition(f)});return _.observe(m),a.visible$.subscribe(f=>{e(f.visible?he.formulaActive:he.formulaGrey)}),()=>{_.unobserve(m),g.unsubscribe()}},[]);function c(){n(t===0?1:0),setTimeout(()=>{s.handleFoldBtnClick(t===1)},150)}function d(){a.isVisible().visible&&a.changeVisible({visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC})}function u(){a.isVisible().visible&&a.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})}function h(){s.handleFxBtnClick(!0)}return p.jsxs("div",{className:he.formulaBox,style:{height:t===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:zt(he.iconContainer,he.iconContainerError,i),onClick:d,children:p.jsx(ja,{})}),p.jsx("span",{className:zt(he.iconContainer,he.iconContainerSuccess,i),onClick:u,children:p.jsx(Wn,{})}),p.jsx("span",{className:he.iconContainer,onClick:h,children:p.jsx(Ka,{})})]})}),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:t===0?p.jsx(Io,{}):p.jsx(Io,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const Qu="univer-operate-container",eh="univer-auto-fill-popup-menu",th="univer-auto-fill-popup-menu-item",nh="univer-auto-fill-popup-menu-item-icon",ih="univer-auto-fill-popup-menu-item-title",oh="univer-auto-fill-popup-menu-item-hide",rh="univer-btn-container",sh="univer-btn-container-expand",ot={operateContainer:Qu,autoFillPopupMenu:eh,autoFillPopupMenuItem:th,autoFillPopupMenuItemIcon:nh,autoFillPopupMenuItemTitle:ih,autoFillPopupMenuItemHide:oh,btnContainer:rh,btnContainerExpand:sh},ah=()=>{const[,i]=H.useState({});return H.useCallback(()=>i(e=>!e),[])},lh=()=>{var re;const i=q.useDependency(l.ICommandService),e=q.useDependency(exports.SheetSkeletonManagerService),t=q.useDependency(l.IUniverInstanceService),n=q.useDependency(b.IRenderManagerService),o=q.useDependency(_e),r=q.useDependency(Jt),s=q.useDependency(l.LocaleService),[a,c]=H.useState([]),[d,u]=H.useState(!1),[h,m]=H.useState({row:-1,col:-1}),[g,_]=H.useState(oe.SERIES),[f,v]=H.useState(!1),R=()=>{v(!0)},M=()=>{v(!1)},T=ah(),E=Ce(t,n);if(E==null)return null;const{scene:w}=E;if(H.useEffect(()=>{const Y=[He.id,un.id,ze.id,S.SetWorksheetActiveOperation.id,S.MoveRangeMutation.id];return i.onCommandExecuted(L=>{L.id===wt.id&&T(),Y.includes(L.id)&&m({row:-1,col:-1})}).dispose},[T,i]),H.useEffect(()=>l.toDisposable(r.menu$.subscribe(U=>{c(U.map(L=>({...L,index:U.indexOf(L)})))})).dispose,[r]),H.useEffect(()=>l.toDisposable(r.showMenu$.subscribe(U=>{const{source:L,target:X}=r.autoFillLocation||{source:null,target:null};if(U&&L&&X){const ee=l.Rectangle.union(L,X);m({row:ee.endRow,col:ee.endColumn})}})).dispose,[r]),H.useEffect(()=>l.toDisposable(r.applyType$.subscribe(U=>{_(U)})).dispose,[r]),H.useEffect(()=>{function Y(){u(!1)}return document.addEventListener("wheel",Y),()=>{document.removeEventListener("wheel",Y)}},[d]),h.col<0||h.row<0)return null;const y=(re=e.getCurrent())==null?void 0:re.skeleton,O=o.getViewPort(),x=w==null?void 0:w.scaleX,A=w==null?void 0:w.scaleY,B=w==null?void 0:w.getScrollXY(O);if(!x||!w||!x||!A||!B)return null;const P=(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,k=y==null?void 0:y.convertTransformToOffsetX(P,x,B),j=y==null?void 0:y.convertTransformToOffsetY(F,A,B);if(k==null||j==null)return null;const $=Y=>{u(Y)},G=Y=>{i.executeCommand(Kr.id,{type:Y.value})},W=d||f,J=a.filter(Y=>!Y.disable);return p.jsx("div",{onMouseEnter:R,onMouseLeave:M,style:{left:`${k+2}px`,top:`${j+2}px`,position:"absolute"},children:p.jsx(ge.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:ot.autoFillPopupMenu,children:J.map(Y=>p.jsxs("li",{onClick:()=>G(Y),className:ot.autoFillPopupMenuItem,children:[p.jsx("span",{className:ot.autoFillPopupMenuItemIcon,children:Y.value===g&&p.jsx(Wn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:ot.autoFillPopupMenuItemTitle,children:s.t(Y.label)})]},Y.index))}),visible:d,onVisibleChange:$,children:p.jsxs("div",{className:zt(ot.btnContainer,{[ot.btnContainerExpand]:d}),children:[p.jsx(Ba,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),W&&p.jsx(Mi,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},ch=()=>p.jsx("div",{className:ot.operateContainer,children:p.jsx(lh,{})}),dh="univer-sheet-bar",uh="univer-sheet-bar-options",hh="univer-sheet-bar-options-divider",dn={sheetBar:dh,sheetBarOptions:uh,sheetBarOptionsDivider:hh},mh="univer-sheet-bar-btn",gh={sheetBarBtn:mh};function Hn(i){const{children:e,className:t,style:n,disabled:o=!1,onClick:r,...s}=i,a=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:gh.sheetBarBtn,style:n,disabled:o,onClick:a,...s,children:e})}const _h="univer-sheet-bar-menu",Sh="univer-sheet-bar-menu-item",fh="univer-sheet-bar-menu-item-icon",ph="univer-sheet-bar-menu-item-hide",vh="univer-sheet-bar-menu-item-select",Ch="univer-sheet-bar-menu-item-label",Ge={sheetBarMenu:_h,sheetBarMenuItem:Sh,sheetBarMenuItemIcon:fh,sheetBarMenuItemHide:ph,sheetBarMenuItemSelect:vh,sheetBarMenuItemLabel:Ch};function Ih(i){const{style:e}=i,[t,n]=H.useState([]),[o,r]=H.useState(!1),s=q.useDependency(l.IUniverInstanceService),a=q.useDependency(l.ICommandService),c=q.useDependency(xt),d=s.getCurrentUniverSheetInstance(),u=f=>{const{sheetId:v}=f;v&&(f.hidden?a.executeCommand(S.SetWorksheetShowCommand.id,{value:v}):f.selected||a.executeCommand(S.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:v}),r(!1))};H.useEffect(()=>{m();const f=new l.DisposableCollection;return f.add(h()),f.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>{f.dispose()}},[]);const h=()=>a.onCommandExecuted(f=>{switch(f.id){case S.SetWorksheetHideMutation.id:case S.RemoveSheetMutation.id:case S.SetWorksheetNameMutation.id:case S.InsertSheetMutation.id:case S.SetWorksheetOrderMutation.id:case S.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const f=d.getSheets(),v=d.getActiveSheet(),R=f.map((M,T)=>({label:M.getName(),index:`${T}`,sheetId:M.getSheetId(),hidden:M.isSheetHidden()===l.BooleanNumber.TRUE,selected:v===M}));n(R)};function g(){r(!0)}const _=f=>{r(f)};return p.jsx(ge.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:Ge.sheetBarMenu,style:{...e},children:t.map(f=>p.jsxs("li",{onClick:()=>u(f),className:f.selected?`${Ge.sheetBarMenuItem} ${Ge.sheetBarMenuItemSelect}`:f.hidden?`${Ge.sheetBarMenuItem} ${Ge.sheetBarMenuItemHide}`:Ge.sheetBarMenuItem,children:[p.jsx("span",{className:Ge.sheetBarMenuItemIcon,children:f.selected?p.jsx(Wn,{}):f.hidden?p.jsx(Za,{}):p.jsx(Wn,{})}),p.jsx("span",{className:Ge.sheetBarMenuItemLabel,children:f.label})]},f.index))}),visible:o,onVisibleChange:_,children:p.jsx(Hn,{children:p.jsx(za,{})})})}const Rh="univer-slide-tab-bar-container",Mh="univer-slide-tab-bar",bh="univer-slide-tab-item",wh="univer-slide-tab-active",Th="univer-slide-tab-span",Eh="univer-slide-tab-span-edit",yh="univer-slide-tab-item-dropdown",Re={slideTabBarContainer:Rh,slideTabBar:Mh,slideTabItem:bh,slideTabActive:wh,slideTabSpan:Th,slideTabSpanEdit:Eh,slideTabItemDropdown:yh};function Oh(i){const{sheetId:e,label:t,color:n,selected:o}=i,[r,s]=H.useState(o),a=q.useDependency(l.ThemeService);H.useEffect(()=>{s(o)},[o]);const c=d=>{const u=a.getCurrentTheme(),h=u.textColor,m=u.colorWhite;return new l.ColorKit(d).isDark()?m:h};return p.jsx("div",{"data-id":e,className:r?`${Re.slideTabActive} ${Re.slideTabItem}`:Re.slideTabItem,style:{backgroundColor:!r&&n?n:"",color:!r&&n?c(n):"",boxShadow:r&&n?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${n}`:""},children:p.jsx("span",{className:Re.slideTabSpan,children:t})},e)}const xh={easeOutStrong(i,e,t,n){return-t*((i=i/n-1)*i*i*i-1)+e},backOut(i,e,t,n,o){return typeof o>"u"&&(o=.7),t*((i=i/n-1)*i*((o+1)*i+o)+1)+e}},Ah={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class Nh{constructor(e){C(this,"_config");C(this,"_status",0);C(this,"_start",0);C(this,"_handle",0);C(this,"_delayHandle",null);this._config={...Ah,...e},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...e){let t=0;return new Promise(n=>{for(let o=0;o<e.length;o++){const r=e[o],s=r._config,a=s.success;s.loop||(s.success=d=>{t++,a&&a.call(r,d),t===e.length&&n()})}})}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 n=xh[this._config.type](e,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(n),this._status===1){this._config.cancel(n),this._config.complete(n);return}if(e===this._config.duration){this._config.success(n),this._config.complete(n);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class st{constructor(e,t){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=t,this._placeholder=null,this._scrollbar=t.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,t){const n=[];return e.forEach(o=>n.push(new st(o,t))),n}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&&Ct.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 t=!0;if(this._editMode===!1){const n=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,n&&(n.removeAttribute("contentEditable"),n.removeEventListener("blur",o),n.removeEventListener("compositionstart",s),n.removeEventListener("compositionend",a),n.removeEventListener("input",c),n.removeEventListener("keydown",r),n.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(n==null?void 0:n.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}e&&e(d)}};let r=d=>{n&&(d.stopPropagation(),d.key==="Enter"&&n.blur())};const s=d=>{t=!1},a=d=>{t=!0},c=d=>{if(!n)return;const u=50;setTimeout(()=>{if(t){const h=n.innerText;h.length>u&&(n.innerText=h.substring(0,u),Ct.keepLastIndex(n))}},0)};n&&(n.setAttribute("contentEditable","true"),n.addEventListener("blur",o),n.addEventListener("compositionstart",s),n.addEventListener("compositionend",a),n.addEventListener("input",c),n.addEventListener("keydown",r),n.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,Ct.keepSelectAll(n))}}nameCheck(){const e=this._slideTabItem.querySelector("span");if(!e)return!1;const t=e.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(t)}animate(){return{translateX:e=>{this._translateX!==e&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Nh({begin:this._translateX,end:e,receive:t=>{this._slideTabItem.style.transform=`translateX(${t}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"),t=this.getBoundingRect(),n=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=e,this._placeholder.style.width=`${t.width}px`,this._placeholder.style.height=`${t.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=n.margin,this._slideTabItem.style.background=n.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=n.boxSizing,this._slideTabItem.style.fontSize=n.fontSize,this._slideTabItem.style.fontFamily=n.fontFamily,this._slideTabItem.style.fontWeight=n.fontWeight,this._slideTabItem.style.color=n.color,this._slideTabItem.style.borderRadius=n.borderRadius,this._slideTabItem.style.left=`${t.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${t.y}px`,this._slideTabItem.style.width=`${t.width}px`,this._slideTabItem.style.height=`${t.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(e),document.body.appendChild(this._slideTabItem)}addEventListener(e,t,n){this._slideTabItem.addEventListener(e,t,n)}removeEventListener(e,t,n){this._slideTabItem.removeEventListener(e,t,n)}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 Dh{constructor(e){C(this,"_slideTabBar");C(this,"_scrollX");const t=e.primeval();this._scrollX=t.scrollLeft,this._slideTabBar=e}scrollX(e){const t=this._slideTabBar.primeval();t.scrollLeft=e,this._scrollX=t.scrollLeft}scrollRight(){const e=this._slideTabBar.primeval();e.scrollLeft=e.scrollWidth,this._scrollX=e.scrollLeft}getScrollX(){return this._scrollX}}const ft=class ft{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 t=e.slideTabBarContainer.querySelector(`.${(s=e.slideTabBarClassName)!=null?s:"slide-tab-bar"}`);if(t==null)throw new Error("not found slide-tab-bar");this._slideTabBar=t,this._slideScrollbar=new Dh(this),this._config=e,this._initConfig();let n=0,o=0,r=0;this._downAction=a=>{var y,O,x,A,B,P;if((y=this._activeTabItem)!=null&&y.isEditMode())return;const c=(x=(O=a.target)==null?void 0:O.closest(`.${e.slideTabBarItemClassName}`))==null?void 0:x.getAttribute("data-id"),d=this._slideTabItems.findIndex(F=>F.getId()===c);if(c==null||d===-1)return;if(this._activeTabItemIndex!==d){(A=this._activeTabItem)==null||A.removeEventListener("pointermove",this._moveAction),(B=this._activeTabItem)==null||B.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(a,c);return}if(this._compareIndex=d,this._downActionX=a.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(a.pointerId),(P=this._activeTabItem)==null||P.addEventListener("pointerup",this._upAction);const{x:h,width:m}=this._activeTabItem.getBoundingRect(),{x:g,width:_}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(h-f),this._rightBoundingLine=h-f+m-this._downActionX,this._leftMoveX=h-g-f,this._rightMoveX=g+_-(h+m)+f,a.button===2||this._hasEditItem())return;const{pageX:v,pageY:R}=a,M=Date.now(),T=M-r<=ft.DoubleClickDelay,E=Math.abs(v-n)<10,w=Math.abs(R-o)<10;T&&E&&w&&this._activeTabItem.setEditor(),n=v,o=R,r=M,this._longPressTimer=setTimeout(()=>{var F,k;(F=this._activeTabItem)==null||F.enableFixed(),this._startAutoScroll(),u&&(u.setPointerCapture(a.pointerId),u.style.cursor="move",(k=this._activeTabItem)==null||k.addEventListener("pointermove",this._moveAction))},ft.LongPressDelay)},this._upAction=a=>{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(a.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(a,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=a=>{this._activeTabItem&&(this._moveActionX=a.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(a),this._scrollRight(a))},this._wheelAction=a=>{this.setScroll(a.deltaY)},this.addListener()}static checkedSkipSlide(e){let t=e.target;for(;t!=null&&t!==document.body;){if(t.getAttribute("data-slide-skip"))return!0;t=t.parentElement}return!1}static keepLastIndex(e){setTimeout(()=>{const t=window.getSelection();t&&(t.selectAllChildren(e),t.collapseToEnd())})}static keepSelectAll(e){setTimeout(()=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)})}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 t=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(e){if(e>0){const t=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c<s&&c+d+n*2>s?(t=e?c-r.left-n:c+d-s+n,!0):!1}),t}calculateRightScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c-n*2<s&&c+d>s?(t=e?c+d-r.left-r.width+n:c-s-n,!0):!1}),t}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 t=this.getBoundingRect(),n=e.pageX-t.x;n<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(n-this._leftBoundingLine)*.1,50))}_scrollRight(e){const t=this.getBoundingRect(),n=e.pageX-t.x;n>t.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(n-(t.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 t=this._slideTabItems[e],n=this._slideTabItems[e+1];n&&t.after(n)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),t=this._slideTabItems.length,n=[];for(let r=0;r<e&&!(r>=e);r++)n.push(this._slideTabItems[r]);for(let r=e+1;r<t;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=n.length-1;r>=0;r--){const s=n[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)),t=this._slideTabItems.length,n=[];for(let r=e+1;r<t;r++)n.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<n.length;r++){const s=n[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 t;const e=this._slideTabBar.querySelectorAll(`.${(t=this._config.slideTabBarItemClassName)!=null?t:"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(ft,"LongPressDelay",500),C(ft,"DoubleClickDelay",300);let Ct=ft;function Ph(){const[i,e]=H.useState([]),[t,n]=H.useState(""),[o,r]=H.useState(""),[s,a]=H.useState(!1),[c,d]=H.useState([0,0]),u=H.useRef({slideTabBar:null}),h=H.useRef(null),m=q.useDependency(l.IUniverInstanceService),g=q.useDependency(l.ICommandService),_=q.useDependency(xt),f=q.useDependency(l.LocaleService),v=q.useDependency(I.IConfirmService),R=q.useDependency(_e),M=q.useDependency(Te),T=q.useInjector(),E=m.getCurrentUniverSheetInstance();H.useEffect(()=>{F();const U=w(),L=P(),X=[k(),j(),$(),G()];return()=>{L.dispose(),U.destroy(),X.forEach(ee=>ee.unsubscribe())}},[]),H.useEffect(()=>{i.length>0&&B()},[i]);const w=()=>{const U=new Ct({slideTabBarClassName:Re.slideTabBar,slideTabBarItemActiveClassName:Re.slideTabActive,slideTabBarItemClassName:Re.slideTabItem,slideTabBarSpanEditClassName:Re.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(L,X)=>{g.executeCommand(S.SetWorksheetNameCommand.id,{subUnitId:L,name:X})},onSlideEnd:(L,X)=>{g.executeCommand(S.SetWorksheetOrderCommand.id,{order:X})},onChangeTab:(L,X)=>{g.executeCommand(S.SetWorksheetActivateCommand.id,{subUnitId:X,unitId:E.getUnitId()}).then(()=>{L.button===2&&Y(!0)}),setTimeout(()=>{T.get(b.ITextSelectionRenderManager).focus()},0)},onScroll:L=>{_.setScroll(L)},onNameCheckAlert:L=>y(L)||O(L)});return u.current.slideTabBar=U,re(U),U},y=U=>{if(U.trim()===""){const L="sheetNameEmptyAlert";return v.open({id:L,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(L)},onConfirm(){x(),v.close(L)}}),!0}return!1},O=U=>{const L=m.getCurrentUniverSheetInstance();if(L.getActiveSheet().getName()===U)return!1;const ie=L.checkSheetName(U);if(ie){const z="sheetNameRepeatAlert";v.open({id:z,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(z),x()},onConfirm(){v.close(z),x()}})}return ie},x=()=>{R.endSelection(),setTimeout(()=>{var L;const U=(L=u.current.slideTabBar)==null?void 0:L.getActiveItem();U&&(U.focus(),U.selectAll())},0)},A=()=>{var U,L;(L=(U=u.current.slideTabBar)==null?void 0:U.getActiveItem())==null||L.setEditor()},B=()=>{var L;const U=i.findIndex(X=>X.selected);(L=u.current.slideTabBar)==null||L.update(U)},P=()=>g.onCommandExecuted(U=>{switch(U.id){case S.SetTabColorMutation.id:case S.SetWorksheetHideMutation.id:case S.RemoveSheetMutation.id:case S.SetWorksheetNameMutation.id:case S.InsertSheetMutation.id:case S.SetWorksheetOrderMutation.id:case S.SetWorksheetActiveOperation.id:F();break}}),F=()=>{const U=E.getActiveSheet().getSheetId();n(U);const L=E.getSheets(),X=E.getActiveSheet(),ee=L.filter(ie=>!ie.isSheetHidden()).map((ie,z)=>{var Z;return{sheetId:ie.getSheetId(),label:ie.getName(),index:z,selected:X===ie,color:(Z=ie.getTabColor())!=null?Z:void 0}});e(ee)},k=()=>_.scroll$.subscribe(U=>{W(U)}),j=()=>_.scrollX$.subscribe(U=>{var L;(L=u.current.slideTabBar)==null||L.flipPage(U)}),$=()=>_.renameId$.subscribe(()=>{A()}),G=()=>_.addSheet$.subscribe(()=>{var U;(U=u.current.slideTabBar)==null||U.getScrollbar().scrollRight()}),W=U=>{const{leftEnd:L,rightEnd:X}=U;let ee="";L&&X?ee="":L&&!X?ee="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!L&&X?ee="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!L&&!X&&(ee="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(ee)},J=U=>{_.setScroll({leftEnd:U.isLeftEnd(),rightEnd:U.isRightEnd()})},re=U=>{var ee;const L=(ee=h.current)==null?void 0:ee.querySelector(`.${Re.slideTabBar}`);if(!L)return;new ResizeObserver(()=>{J(U)}).observe(L)},Y=U=>{var L,X,ee,ie,z;if(!M.isForceKeepVisible()){if(U){const{left:Z}=(X=(L=h.current)==null?void 0:L.getBoundingClientRect())!=null?X:{},{left:K}=(z=(ie=(ee=u.current.slideTabBar)==null?void 0:ee.getActiveItem())==null?void 0:ie.getSlideTabItem().getBoundingClientRect())!=null?z:{};Z!==void 0&&K!==void 0&&d([K-Z,0])}a(U)}};return p.jsx(ge.Dropdown,{className:Re.slideTabItemDropdown,visible:s,align:{offset:c},trigger:["contextMenu"],overlay:p.jsx(I.Menu,{menuType:ce.SHEET_BAR,onOptionSelect:U=>{const{label:L,value:X}=U;g.executeCommand(L,{value:X,subUnitId:t}),a(!1)}}),onVisibleChange:Y,children:p.jsx("div",{className:Re.slideTabBarContainer,ref:h,children:p.jsx("div",{className:Re.slideTabBar,style:{boxShadow:o},children:i.map(U=>H.createElement(Oh,{...U,key:U.sheetId,selected:t===U.sheetId}))})})})}const Fo=100,Hh=()=>{const[i,e]=H.useState(!0),[t,n]=H.useState(!0),o=q.useDependency(l.ICommandService),r=q.useDependency(xt);H.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;e(h),n(m)},a=()=>{o.executeCommand(S.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-Fo)},d=()=>{r.setScrollX(Fo)};return p.jsxs("div",{className:dn.sheetBar,children:[p.jsxs("div",{className:dn.sheetBarOptions,children:[p.jsx(Hn,{onClick:a,children:p.jsx(Ja,{})}),p.jsx(Ih,{})]}),p.jsx(Ph,{}),(!i||!t)&&p.jsxs("div",{className:`${dn.sheetBarOptions} ${dn.sheetBarOptionsDivider}`,children:[p.jsx(Hn,{disabled:i,onClick:c,children:p.jsx(Ro,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(Hn,{disabled:t,onClick:d,children:p.jsx(Ro,{})})]})]})};class Lh{constructor(){C(this,"_functions",[{func:te.FUNCTION_NAMES_STATISTICAL.MAX,filter:e=>{var t,n,o,r;return((n=(t=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n: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 t,n,o,r;return((n=(t=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n: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 t,n,o,r;return((n=(t=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n: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 t,n;return((n=(t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n:0)>1}},{func:te.FUNCTION_NAMES_STATISTICAL.COUNT,filter:e=>{var t,n,o,r;return((n=(t=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n: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 t,n,o,r;return((n=(t=e.values.find(s=>s.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)!=null?n: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 D.BehaviorSubject(null));C(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(e){var n;const t={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))&&t.values.push(o)}),t.pattern=(n=e==null?void 0:e.pattern)!=null?n:null,this._state$.next(t)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(e){this._functions.push(...e)}}const Gi=N.createIdentifier("univer.sheet-status-bar.service"),Uh="univer-status-bar",kh="univer-single-mode",Vh="univer-status-bar-div",Bh="univer-statistic-list",Fh="univer-statistic-list-column",Wh="univer-statistic-item",jh="univer-statistic-picker",$h="univer-statistic-picker-item",zh="univer-statistic-more",_t={statusBar:Uh,singleMode:kh,statusBarDiv:Vh,statisticList:Bh,statisticListColumn:Fh,statisticItem:Wh,statisticPicker:jh,statisticPickerItem:$h,statisticMore:zh},Yh=[te.FUNCTION_NAMES_MATH.SUM,te.FUNCTION_NAMES_STATISTICAL.AVERAGE,te.FUNCTION_NAMES_STATISTICAL.MIN,te.FUNCTION_NAMES_STATISTICAL.MAX],_i={[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"},Si=i=>{const e=q.useDependency(l.LocaleService),t=q.useDependency(I.IMessageService),n=q.useDependency(I.IClipboardInterfaceService),o=Xh(i),r=async()=>{await n.writeText(i.value.toString()),t.show({type:ge.MessageType.Success,content:e.t("statusbar.copied")})};return p.jsx(ge.Tooltip,{title:e.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:_t.statisticItem,onClick:r,children:p.jsx("span",{children:`${e.t((_i==null?void 0:_i[i.name])||i.name)}: ${o}`})},i.name)})};function Xh(i){const{pattern:e,value:t}=i;return typeof t!="number"?"Invalid input":t>=1e8?t.toExponential(2):e&&Yh.includes(i.name)?ss.format(e,t):t.toLocaleString()}const Wo=800,Zh=3,Gh=()=>{const[i,e]=H.useState(window.innerWidth<Wo),[t,n]=H.useState(!0),o=q.useDependency(Gi),r=o.getFunctions().map((m,g)=>({name:m.func,value:0,show:!0,disable:!1,pattern:null})),[s,a]=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(g=>{const _=g==null?void 0:g.values;if(!_||_.length===0)n(!1);else{n(!0);const f=s.map(v=>{var M;const R=_.find(T=>T.func===v.name);return R?(v.value=R.value,v.disable=!1):v.disable=!0,v.pattern=(M=g==null?void 0:g.pattern)!=null?M:null,v});a(f)}});return()=>{m.unsubscribe()}},[o]);const u=Kh(()=>{const m=window.innerWidth<Wo;i!==m&&e(m)},100);H.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>Zh){const m=[];d.forEach((g,_)=>{_%2===0&&m.push(d.slice(_,_+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((g,_)=>p.jsxs("div",{className:_t.statisticListColumn,children:[(g==null?void 0:g[0])&&p.jsx(Si,{...g==null?void 0:g[0]},g==null?void 0:g[0].name),(g==null?void 0:g[1])&&p.jsx(Si,{...g==null?void 0:g[1]},g==null?void 0:g[1].name)]},`stat-col-${_}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(Si,{...m},m.name))});return t&&p.jsxs("div",{className:zt(_t.statusBar,{[_t.singleMode]:i}),children:[p.jsx("div",{className:zt(_t.statisticList),children:h}),p.jsx("div",{className:_t.statusBarDiv})]})};function Kh(i,e){let t;return function(...n){const o=this,r=function(){t=null,i.apply(o,n)};clearTimeout(t),t=setTimeout(r,e)}}function qh(){return p.jsxs("section",{className:zr.sheetContainer,"data-range-selector":!0,children:[p.jsx(Hh,{}),p.jsx(Gh,{}),p.jsx(Hu,{})]})}function Jh(){return p.jsx(p.Fragment,{children:p.jsx(Ju,{})})}function Qh(){return p.jsxs(p.Fragment,{children:[p.jsx(ku,{}),p.jsx(ch,{})]})}function em(i){const e=i.get(S.BorderStyleManagerService),t=S.getCurrentSheetDisabled$(i);return{id:S.SetBorderBasicCommand.id,icon:new D.Observable(n=>{const o="AllBorderSingle",r=i.get(S.BorderStyleManagerService),s=i.get(l.ICommandService).onCommandExecuted(a=>{var m;if(a.id!==S.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=is.find(g=>g.value===d),h=(m=u==null?void 0:u.icon)!=null?m:o;n.next(h)});return n.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:ns,hoverable:!1},value$:e.borderInfo$}],value$:e.borderInfo$,hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:t}}const ei="sheet.menu.clear-selection";function tm(){return{id:ei,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[I.MenuPosition.CONTEXT_MENU,ce.COL_HEADER_CONTEXT_MENU,ce.ROW_HEADER_CONTEXT_MENU]}}function nm(){return{id:S.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[ei]}}function im(){return{id:S.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[ei]}}function om(){return{id:S.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[ei]}}const nn="sheet.menu.delete";function rm(){return{id:nn,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[I.MenuPosition.CONTEXT_MENU]}}function sm(){return{id:Jr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[nn,ce.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function am(){return{id:qr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteRow",positions:[nn,ce.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function lm(){return{id:zi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[nn]}}function cm(){return{id:Yi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[nn]}}const Ki="sheet.menu.col-insert";function dm(){return{id:Ki,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ce.COL_HEADER_CONTEXT_MENU]}}const qi="sheet.menu.row-insert";function um(){return{id:qi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ce.ROW_HEADER_CONTEXT_MENU]}}const on="sheet.menu.cell-insert";function hm(){return{id:on,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[I.MenuPosition.CONTEXT_MENU]}}function mm(i){const e=i.get(S.SelectionManagerService);return{id:S.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[qi,on],hidden$:new D.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function gm(i){const e=i.get(S.SelectionManagerService);return{id:S.InsertRowAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[qi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new D.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function _m(i){const e=i.get(S.SelectionManagerService);return{id:S.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,positions:[Ki,on],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new D.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function Sm(i){const e=i.get(S.SelectionManagerService);return{id:S.InsertColAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[Ki],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new D.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function fm(){return{id:Zi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[on]}}function pm(){return{id:Xi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[on]}}function vm(i){const e=S.getCurrentSheetDisabled$(i);return{id:Ye.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,l.UniverInstanceType.SHEET),disabled$:e}}function Cm(i){return{id:Xr.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[Ye.id]}}function Im(i){return{id:Zr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[Ye.id]}}function Rm(i){return{id:Gr.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[Ye.id]}}function Mm(i){return{id:S.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[Ye.id]}}function bm(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:Qr.id,type:I.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.delete",disabled$:new D.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===S.RemoveSheetMutation.id||s===S.InsertSheetMutation.id||s===S.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function wm(){return{id:S.CopySheetCommand.id,type:I.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.copy"}}function Tm(){return{id:ts.id,type:I.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.rename"}}function Em(){return{id:S.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[ce.SHEET_BAR],type:I.MenuItemType.SELECTOR,selections:[{label:{name:Kn,hoverable:!1}}]}}function ym(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:S.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.hide",disabled$:new D.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===S.RemoveSheetMutation.id||s===S.InsertSheetMutation.id||s===S.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function Om(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:es.id,type:I.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.unhide",disabled$:new D.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===S.RemoveSheetMutation.id||s===S.InsertSheetMutation.id||s===S.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values());n.next(c.length===1)}});return n.next(!1),o.dispose})}}const xm={id:S.SetRowHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},Am={id:S.SetColHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},Nm={id:we.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.DOWN}},Dm={id:we.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.UP}},Pm={id:we.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.LEFT}},Hm={id:we.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT}},Lm={id:lt.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT,keycode:I.KeyCode.TAB}},Um={id:lt.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.LEFT,keycode:I.KeyCode.TAB}},km={id:lt.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.DOWN,keycode:I.KeyCode.ENTER}},Vm={id:lt.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.UP,keycode:I.KeyCode.ENTER}},Bm={id:we.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:l.Direction.DOWN,jumpOver:Le.moveGap}},Fm={id:we.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:l.Direction.UP,jumpOver:Le.moveGap}},Wm={id:we.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:l.Direction.LEFT,jumpOver:Le.moveGap}},jm={id:we.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:l.Direction.RIGHT,jumpOver:Le.moveGap}},$m={id:Ue.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.DOWN}},zm={id:Ue.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.UP}},Ym={id:Ue.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.LEFT}},Xm={id:Ue.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT}},Zm={id:Ue.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:l.Direction.DOWN,jumpOver:Le.moveGap}},Gm={id:Ue.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:l.Direction.UP,jumpOver:Le.moveGap}},Km={id:Ue.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:l.Direction.LEFT,jumpOver:Le.moveGap}},qm={id:Ue.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:l.Direction.RIGHT,jumpOver:Le.moveGap}},Jm={id:ur.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}},Qm={id:Ui.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},eg={id:ki.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},tg={id:Vi.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},ng={id:Bi.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},ig={id:S.ClearSelectionContentCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},og={id:Jn.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}},rg={id:l.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},sg={id:Jn.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}},ag={id:l.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},lg={id:Jn.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}},cg={id:l.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var dg=Object.defineProperty,ug=Object.getOwnPropertyDescriptor,hg=(i,e,t,n)=>{for(var o=n>1?void 0:n?ug(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&dg(e,t,o),o},gt=(i,e)=>(t,n)=>e(t,n,i);let Ln=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._injector=i,this._componentManager=e,this._commandService=t,this._shortcutService=n,this._menuService=o,this._uiController=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ji,Nl)),this.disposeWithMe(i.register(ns,Ou)),this.disposeWithMe(i.register(Kn,ge.ColorPicker)),this.disposeWithMe(i.register(Vr,I.FontFamily)),this.disposeWithMe(i.register(Br,I.FontFamilyItem)),this.disposeWithMe(i.register(Fr,I.FontSize))}_initCommands(){[Xr,Ye,Gr,Zr,Jn,Ue,we,lt,ts,Qr,qr,Jr,yr,Or,pt,ur,Yr,Xn,S.SetBoldCommand,Gt,He,Ui,ki,Vi,Bi,Rl,Ml,xr,Ar,jn,S.SetItalicCommand,S.SetStrikeThroughCommand,S.SetFontFamilyCommand,S.SetFontSizeCommand,Fi,Pr,Wi,Hr,wt,bn,Gn,Lr,Ur,kr,S.SetUnderlineCommand,Qn,ze,es,Kr,Xi,Yi,Zi,zi].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[Zl,Gl,Kl,ql,Jl,Ql,ec,nm,im,om,tm,dm,um,hm,mm,gm,_m,Sm,am,lc,dc,cc,uc,sm,hc,tc,mc,rm,lm,cm,fm,pm,oc,rc,sc,ac,nc,ic,Dl,Pl,Hl,Ll,Ul,kl,Vl,Bl,Fl,Wl,jl,em,vm,Cm,Im,Rm,Mm,$l,zl,Yl,Xl,bm,wm,Tm,Em,ym,Om].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[Nm,Dm,Pm,Hm,Lm,Um,km,Vm,Bm,Fm,Wm,jm,$m,zm,Ym,Xm,Zm,Gm,Km,qm,Jm,og,sg,lg,cg,rg,ag,Qm,eg,tg,ng,ig,...Dc(),Pc,Hc,Uc,kc,Vc,Lc,xm,Am].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>q.connectInjector(Jh,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>q.connectInjector(qh,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>q.connectInjector(Qh,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts()}};Ln=hg([l.OnLifecycle(l.LifecycleStages.Ready,Ln),gt(0,N.Inject(N.Injector)),gt(1,N.Inject(I.ComponentManager)),gt(2,l.ICommandService),gt(3,I.IShortcutService),gt(4,I.IMenuService),gt(5,I.IUIController)],Ln);var mg=Object.defineProperty,gg=Object.getOwnPropertyDescriptor,_g=(i,e,t,n)=>{for(var o=n>1?void 0:n?gg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&mg(e,t,o),o},nt=(i,e)=>(t,n)=>e(t,n,i);let Un=class extends l.Disposable{constructor(e,t,n,o,r,s,a){super();C(this,"_calculateTimeout",-1);this._univerInstanceService=e,this._selectionManagerService=t,this._functionService=n,this._statusBarService=o,this._commandService=r,this._formulaDataModel=s,this._numfmtService=a,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(e=>{var t;((t=this._selectionManagerService.getCurrent())==null?void 0:t.pluginName)===S.NORMAL_SELECTION_PLUGIN_NAME&&e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{const n=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),n)},100))}))),this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.pipe(D.debounceTime(100)).subscribe(e=>{var t;if(((t=this._selectionManagerService.getCurrent())==null?void 0:t.pluginName)===S.NORMAL_SELECTION_PLUGIN_NAME&&e){const n=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),n)}}))),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===S.SetRangeValuesMutation.id){const t=this._selectionManagerService.getSelections();t&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(t.map(n=>n.range))},100))}}))}_calculateSelection(e,t){var c;const n=this._univerInstanceService.getCurrentUniverSheetInstance(),o=n.getUnitId(),r=n.getActiveSheet().getSheetId(),s={},a=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(d=>{const u=d.getConfig();s[d.getSheetId()]={cellData:new l.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}),a&&f.setArrayFormulaCellData(te.convertUnitDataToRuntime(a))});const h=this._statusBarService.getFunctions().map(f=>{const v=this._functionService.getExecutor(f.func);if(!v)return;const R=d.map(E=>E.toArrayValueObject(!1)),M=v==null?void 0:v.calculate(...R),T=M==null?void 0:M.getValue();if(T)return{func:f.func,value:T}});if(h.every(f=>f===void 0))return;let m=null;if(t){const{actualRow:f,actualColumn:v}=t;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}};Un=_g([l.OnLifecycle(l.LifecycleStages.Ready,Un),nt(0,l.IUniverInstanceService),nt(1,N.Inject(S.SelectionManagerService)),nt(2,te.IFunctionService),nt(3,Gi),nt(4,l.ICommandService),nt(5,N.Inject(te.FormulaDataModel)),nt(6,N.Inject(S.INumfmtService))],Un);var Sg=Object.defineProperty,fg=Object.getOwnPropertyDescriptor,pg=(i,e,t,n)=>{for(var o=n>1?void 0:n?fg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Sg(e,t,o),o},it=(i,e)=>(t,n)=>e(t,n,i);let kn=class extends l.Disposable{constructor(i,e,t,n,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,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(l.toDisposable(i.onMouseWheelObserver.add((t,n)=>{if(!t.ctrlKey)return;const o=Math.abs(t.deltaX);let r=o<40?.2:o<80?.4:.2;r*=t.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getActiveSheet(),c=a.getZoomRatio();let d=+Number.parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Qn.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:a.getSheetId()}),t.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(n)})))}_commandExecutedListener(){const i=[ze.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;const a=n.getConfig().zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return Ce(this._currentUniverService,this._renderManagerService)}};kn=pg([l.OnLifecycle(l.LifecycleStages.Rendered,kn),it(0,N.Inject(exports.SheetSkeletonManagerService)),it(1,l.IUniverInstanceService),it(2,l.ICommandService),it(3,b.IRenderManagerService),it(4,_e),it(5,N.Inject(S.SelectionManagerService)),it(6,N.Inject(Je))],kn);var vg=Object.defineProperty,Cg=Object.getOwnPropertyDescriptor,Ig=(i,e,t,n)=>{for(var o=n>1?void 0:n?Cg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&vg(e,t,o),o},Ft=(i,e)=>(t,n)=>e(t,n,i);exports.SheetCanvasView=class extends l.RxDisposable{constructor(t,n,o,r,s){super();C(this,"_scene");C(this,"_currentWorkbook");C(this,"_loadedMap",new Set);C(this,"_isLoadedEditor",!1);C(this,"_fps$",new D.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._currentUniverService.currentSheet$.subscribe(a=>{if(a==null)return;const c=a.getUnitId();this._loadedMap.has(c)||(this._currentWorkbook=a,this._addNewRender(),this._loadedMap.add(c))})}dispose(){this._fps$.complete()}_addNewRender(){const t=this._currentWorkbook,n=t.getUnitId(),o=t.getContainer(),r=t.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(n,r):this._renderManagerService.createRender(n);const a=this._renderManagerService.getRenderById(n);if(a==null)return;const{scene:c,engine:d}=a;c.openTransformer(),this._scene=c,c.addLayer(new b.Layer(c,[],0),new b.Layer(c,[],2)),a!=null&&this._addComponent(a),t.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();this._addViewport(r);const c=new b.Spreadsheet(Se.MAIN),d=new b.SpreadsheetRowHeader(Se.ROW),u=new b.SpreadsheetColumnHeader(Se.COLUMN),h=new b.Rect(Se.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});t.mainComponent=c,t.components.set(Se.MAIN,c),t.components.set(Se.ROW,d),t.components.set(Se.COLUMN,u),t.components.set(Se.LEFT_TOP,h),n.addObjects([c],lo),n.addObjects([d,u,h],qe),n.enableLayerCache(lo,qe),this._sheetSkeletonManagerService.setCurrent({sheetId:a,unitId:s})}_addViewport(t){const n=this._scene;if(n==null)return;const{rowHeader:o,columnHeader:r}=t.getConfig(),s=new b.Viewport(V.VIEW_MAIN,n,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0});return new b.Viewport(V.VIEW_ROW_TOP,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_ROW_BOTTOM,n,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_LEFT,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_RIGHT,n,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_LEFT_TOP,n,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_MAIN_LEFT_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_LEFT,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),n.onMouseWheelObserver.add((a,c)=>{if(a.ctrlKey)return;let d=0,u=0;const h=s.limitedScroll();if(a.inputIndex===b.PointerInput.MouseWheelX){const g=Math.abs(a.deltaX);a.deltaX>0?d=g:d=-g,this._commandService.executeCommand(bn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()}if(a.inputIndex===b.PointerInput.MouseWheelY){let g=Math.abs(a.deltaY);a.shiftKey?(g*=3,a.deltaY>0?d=g:d=-g,this._commandService.executeCommand(bn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()):(a.deltaY>0?u=g:u=-g,this._commandService.executeCommand(bn.id,{offsetY:u}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedY||c.stopPropagation():s.isWheelPreventDefaultY?a.preventDefault():h!=null&&h.isLimitedY||a.preventDefault())}a.inputIndex,b.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}),new b.ScrollBar(s),n.attachControl(),s}};exports.SheetCanvasView=Ig([l.OnLifecycle(l.LifecycleStages.Ready,exports.SheetCanvasView),Ft(0,l.IUniverInstanceService),Ft(1,l.ICommandService),Ft(2,b.IRenderManagerService),Ft(3,_e),Ft(4,N.Inject(exports.SheetSkeletonManagerService))],exports.SheetCanvasView);var Rg=Object.defineProperty,Mg=Object.getOwnPropertyDescriptor,bg=(i,e,t,n)=>{for(var o=n>1?void 0:n?Mg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Rg(e,t,o),o},fi=(i,e)=>(t,n)=>e(t,n,i),pi;exports.UniverSheetsUIPlugin=(pi=class extends l.Plugin{constructor(e,t,n,o){super(Xo),this._injector=t,this._localeService=n,this._currentUniverService=o,this._localeService.load({zhCN:Wr})}onStarting(e){[[exports.SheetCanvasView],[Xt],[Te,{useClass:exports.EditorBridgeService}],[Mt,{useClass:exports.SheetClipboardService}],[xt,{useClass:uu}],[Tt,{useClass:bi}],[tn,{useClass:jr}],[qn,{useClass:Sc}],[Jt,{useClass:exports.AutoFillService}],[Je],[exports.SheetSkeletonManagerService],[_e,{useClass:exports.SelectionRenderService}],[Gi,{useClass:Lh}],[qt,{useClass:exports.MarkSelectionService}],[mn],[gn],[Rn],[pn],[vn],[Mn],[wn],[Tn],[En],[yn],[On],[Cn],[An],[vt],[Dn],[_n],[Sn],[Nn],[Pn],[Ln],[In],[kn],[exports.AutoFillController],[Un],[fn],[xn]].forEach(t=>e.add(t))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const e=this._currentUniverService;e.currentSheet$.pipe(jo.filter(t=>!!t)).subscribe(t=>{e.focusUniverInstance(t.getUnitId())})}},C(pi,"type",l.PluginType.Sheet),pi);exports.UniverSheetsUIPlugin=bg([fi(1,N.Inject(N.Injector)),fi(2,N.Inject(l.LocaleService)),fi(3,l.IUniverInstanceService)],exports.UniverSheetsUIPlugin);exports.APPLY_TYPE=oe;exports.AutoFillCommand=Ko;exports.COPY_TYPE=rt;exports.CellEditorManagerService=jr;exports.DATA_TYPE=de;exports.DefaultRightMenuConfig=$o;exports.DefaultSheetContainerConfig=Yo;exports.DefaultSheetUIConfig=as;exports.DefaultToolbarConfig=zo;exports.ExpandSelectionCommand=Ue;exports.IAutoFillService=Jt;exports.ICellEditorManagerService=tn;exports.IEditorBridgeService=Te;exports.IFormulaEditorManagerService=qn;exports.IMarkSelectionService=qt;exports.ISelectionRenderService=_e;exports.ISheetClipboardService=Mt;exports.JumpOver=Le;exports.MoveSelectionCommand=we;exports.PASTE_SPECIAL_MENU_ID=Ot;exports.PREDEFINED_HOOK_NAME=fe;exports.RangeSelector=cl;exports.SHEET_UI_PLUGIN_NAME=Xo;exports.SelectionShape=Fn;exports.SetCellEditVisibleArrowOperation=Gt;exports.SetEditorResizeOperation=Xn;exports.SetScrollOperation=wt;exports.SetZoomRatioOperation=ze;exports.SheetCopyCommand=ir;exports.SheetPasteCommand=bt;exports.VIEWPORT_KEY=V;exports.enUS=gc;exports.getAutoFillRepeatRange=Is;exports.getCoordByCell=wi;exports.getCoordByOffset=Rt;exports.getEditorObject=Yn;exports.getRepeatRange=_c;exports.getSheetObject=Ce;exports.getTransformCoord=hn;exports.whenFormulaEditorActivated=Ms;exports.whenSheetEditorFocused=ne;exports.zhCN=Wr;
17
+ */var Ta=P,Ea=Symbol.for("react.element"),Oa=Symbol.for("react.fragment"),ya=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 cr(i,t,e){var n,o={},r=null,s=null;e!==void 0&&(r=""+e),t.key!==void 0&&(r=""+t.key),t.ref!==void 0&&(s=t.ref);for(n in t)ya.call(t,n)&&!Aa.hasOwnProperty(n)&&(o[n]=t[n]);if(i&&i.defaultProps)for(n in t=i.defaultProps,t)o[n]===void 0&&(o[n]=t[n]);return{$$typeof:Ea,type:i,key:r,ref:s,props:o,_owner:xa.current}}Yn.Fragment=Oa;Yn.jsx=cr;Yn.jsxs=cr;lr.exports=Yn;var p=lr.exports,be=function(){return be=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(i[o]=t[o])}return i},be.apply(this,arguments)},Na=function(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(i);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(i,n[o])&&(e[n[o]]=i[n[o]]);return e},Ie=P.forwardRef(function(i,t){var e=i.icon,n=i.id,o=i.className,r=i.extend,s=Na(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),c=P.useRef("_".concat(La()));return dr(e,"".concat(n),{defIds:e.defIds,idSuffix:c.current},be({ref:t,className:a},s),r)});function dr(i,t,e,n,o){return P.createElement(i.tag,be(be({key:t},Da(i,e,o)),n),(Ha(i,e).children||[]).map(function(r,s){return dr(r,"".concat(t,"-").concat(i.tag,"-").concat(s),e,void 0,o)}))}function Da(i,t,e){var n=be({},i.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1);var o=t.defIds;return!o||o.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(r){var s=r[0],a=r[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Ha(i,t){var e,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?be(be({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.indexOf(o.attrs.id)>-1?be(be({},o),{attrs:be(be({},o.attrs),{id:o.attrs.id+t.idSuffix})}):o})}):i}function La(){return Math.random().toString(36).substring(2,8)}Ie.displayName="UniverIcon";var Pa={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"}}]},ur=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"autofill",ref:t,icon:Pa}))});ur.displayName="Autofill";const Ua=ur;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"}}]},hr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"check-mark-single",ref:t,icon:ka}))});hr.displayName="CheckMarkSingle";const Fn=hr;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"}}]},mr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"close-single",ref:t,icon:Va}))});mr.displayName="CloseSingle";const Ba=mr;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"}}]}]},gr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"convert-single",ref:t,icon:Fa}))});gr.displayName="ConvertSingle";const Wa=gr;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"}}]}]},Sr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"dropdown-single",ref:t,icon:ja}))});Sr.displayName="DropdownSingle";const po=Sr;var $a={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"}}]},_r=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"eyelash-single",ref:t,icon:$a}))});_r.displayName="EyelashSingle";const za=_r;var Ya={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"}}]}]},fr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"fx-single",ref:t,icon:Ya}))});fr.displayName="FxSingle";const Xa=fr;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"}}]}]},pr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"increase-single",ref:t,icon:Za}))});pr.displayName="IncreaseSingle";const Ga=pr;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"}}]}]},Cr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"more-down-single",ref:t,icon:Ka}))});Cr.displayName="MoreDownSingle";const Ii=Cr;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"}}]},vr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"more-single",ref:t,icon:qa}))});vr.displayName="MoreSingle";const Co=vr;var Ja={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"}}]}]},Ir=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"paint-bucket",ref:t,icon:Ja}))});Ir.displayName="PaintBucket";const Qa=Ir;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"}}]},Rr=P.forwardRef(function(i,t){return P.createElement(Ie,Object.assign({},i,{id:"select-range-single",ref:t,icon:el}))});Rr.displayName="SelectRangeSingle";const tl=Rr,nl="univer-range-selector",il="univer-range-selector-editor",ol="univer-range-selector-icon",rl="univer-range-selector-active",nt={rangeSelector:nl,rangeSelectorEditor:il,rangeSelectorIcon:ol,rangeSelectorActive:rl};function sl(i){const{onChange:t,onActive:e}=i,[n,o]=P.useState(!1),r=P.useRef(null),s=K.useDependency(l.LocaleService),a=K.useDependency(_.SelectionManagerService);P.useEffect(()=>{var m;if(n){e(n);const g=a.selectionMoveEnd$.subscribe(S=>{const f=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],C=Math.floor(Math.random()*f.length),R=f[C];r.current&&(r.current.innerHTML=R)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),g.unsubscribe()}}t(((m=r.current)==null?void 0:m.innerHTML)||"")},[n]);function c(m){var C,R,M;if(((C=m.target)==null?void 0:C.closest('[data-range-selector="true"]'))||m.target===r.current)return;const S=(R=m.target)==null?void 0:R.closest(`.${nt.rangeSelector}`);(S==null?void 0:S.querySelector(`.${nt.rangeSelectorEditor}`))!==r.current&&(o(!1),(M=r.current)==null||M.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(!n){(m=r.current)==null||m.focus();return}o(!n)}return p.jsxs("div",{className:n?`${nt.rangeSelector} ${nt.rangeSelectorActive}`:nt.rangeSelector,children:[p.jsx("div",{ref:r,className:nt.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(ge.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:nt.rangeSelectorIcon,onClick:h,children:p.jsx(tl,{})})})]})}var St=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(St||{}),de=(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))(de||{}),ie=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(ie||{});const al={type:de.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===l.CellValueType.NUMBER,isContinue:(i,t)=>i.type===de.NUMBER,applyFunctions:{[ie.SERIES]:(i,t,e)=>{const{data:n}=i;return e===l.Direction.LEFT||e===l.Direction.UP?(n.reverse(),no(n,t,e).reverse()):no(n,t,e)}}},Mr={type:de.OTHER,priority:0,match:()=>!0,isContinue:(i,t)=>i.type===de.OTHER},ll={type:de.EXTEND_NUMBER,priority:900,match:i=>rn(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,t)=>{var e;if(i.type===de.EXTEND_NUMBER){const{beforeTxt:n,afterTxt:o}=rn(`${(e=i.cellData)==null?void 0:e.v}`||""),{beforeTxt:r,afterTxt:s}=rn(`${t==null?void 0:t.v}`||"");if(n===r&&o===s)return!0}return!1},applyFunctions:{[ie.SERIES]:(i,t,e)=>{var a;const{data:n}=i,o=e===l.Direction.UP||e===l.Direction.LEFT;let r;if(n.length===1)return r=o?-1:1,we(io(n,t,r),o);const s=[];for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;d&&s.push(Number(rn(d).matchTxt))}return o&&(n.reverse(),s.reverse()),Kt(s)?(r=s[1]-s[0],we(io(n,t,r),o)):ct(n,t)}}},cl={type:de.CHN_NUMBER,priority:830,match:i=>!!ls(`${i==null?void 0:i.v}`||""),isContinue:(i,t)=>i.type===de.CHN_NUMBER,applyFunctions:{[ie.SERIES]:(i,t,e)=>{var c,d,u;const{data:n}=i,o=e===l.Direction.LEFT||e===l.Direction.UP;if(n.length===1){const h=`${(c=n[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||ze(h)<7)?we(vt(n,t,m),o):we(oo(n,t,m),o)}let r=!1;for(let h=0;h<n.length;h++)if(((d=n[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let a=0;for(let h=0;h<n.length;h++){const m=`${(u=n[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(a++,s.push(a*7)):r&&ze(m)>0&&ze(m)<7?s.push(ze(m)+a*7):s.push(ze(m))}if(o&&(n.reverse(),s.reverse()),Kt(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 we(vt(n,t,m),o)}const h=s[1]-s[0];return we(oo(n,t,h),o)}return ct(n,t)}}},dl={type:de.CHN_WEEK2,priority:820,match:i=>!!cs(`${i==null?void 0:i.v}`||""),isContinue:(i,t)=>i.type===de.CHN_WEEK2,applyFunctions:{[ie.SERIES]:(i,t,e)=>{var a;const{data:n}=i,o=e===l.Direction.LEFT||e===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,we(vt(n,t,c,1),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.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(ze(u)+s*7)}if(o&&(n.reverse(),r.reverse()),Kt(r)){const c=r[1]-r[0];return we(vt(n,t,c,1),o)}return ct(n,t)}}},ul={type:de.CHN_WEEK3,priority:810,match:i=>ds(`${i==null?void 0:i.v}`||""),isContinue:(i,t)=>i.type===de.CHN_WEEK3,applyFunctions:{[ie.SERIES]:(i,t,e)=>{var a;const{data:n}=i,o=e===l.Direction.LEFT||e===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,we(vt(n,t,c,2),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(ze(u)+s*7)}}if(o&&(n.reverse(),r.reverse()),Kt(r)){const c=r[1]-r[0];return we(vt(n,t,c,2),o)}return ct(n,t)}}},hl={type:de.LOOP_SERIES,priority:800,match:i=>fs(`${i==null?void 0:i.v}`||""),isContinue:(i,t)=>{var e;return i.type===de.LOOP_SERIES?ii(`${(e=i.cellData)==null?void 0:e.v}`||"").name===ii(`${t==null?void 0:t.v}`||"").name:!1},applyFunctions:{[ie.SERIES]:(i,t,e)=>{var c,d;const{data:n}=i,o=e===l.Direction.LEFT||e===l.Direction.UP,{series:r}=ii(`${(c=n[0])==null?void 0:c.v}`||"");if(n.length===1){let u;return o?u=-1:u=1,we(ro(n,t,u,r),o)}const s=[];let a=0;for(let u=0;u<n.length;u++){const h=`${(d=n[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(a++,s.push(a*r.length)):s.push(r.indexOf(h)+a*7))}if(o&&(n.reverse(),s.reverse()),Kt(s)){const u=s[1]-s[0];return we(ro(n,t,u,r),o)}return ct(n,t)}}};function we(i,t){return t?i.reverse():i}var ml=Object.defineProperty,gl=Object.getOwnPropertyDescriptor,Sl=(i,t,e,n)=>{for(var o=n>1?void 0:n?gl(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&ml(t,e,o),o},ri=(i,t)=>(e,n)=>t(e,n,i);exports.AutoFillService=class extends l.Disposable{constructor(e,n,o){super();I(this,"_rules",[]);I(this,"_hooks",[]);I(this,"_applyType$",new H.BehaviorSubject(ie.SERIES));I(this,"_isFillingStyle",!0);I(this,"_autoFillLocation$",new H.BehaviorSubject(null));I(this,"autoFillLocation$",this._autoFillLocation$.asObservable());I(this,"_showMenu$",new H.BehaviorSubject(!1));I(this,"showMenu$",this._showMenu$.asObservable());I(this,"_direction",l.Direction.DOWN);I(this,"applyType$",this._applyType$.asObservable());I(this,"_menu$",new H.BehaviorSubject([{label:"autoFill.copy",value:ie.COPY,disable:!1},{label:"autoFill.series",value:ie.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ie.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ie.NO_FORMAT,disable:!1}]));I(this,"menu$",this._menu$.asObservable());this._sheetInterceptorService=e,this._univerInstanceService=n,this._selectionManagerService=o,this._init()}_init(){this._rules=[al,ll,cl,dl,ul,hl,Mr].sort((e,n)=>n.priority-e.priority),this._isFillingStyle=!0}getOneByPriority(e){return e.length<=0?[]:[e.reduce((o,r)=>(r.priority||0)>(o.priority||0)?r:o,e[0])]}addHook(e){if(this._hooks.find(n=>n.id===e.id))throw new Error(`Add hook failed, hook id '${e.id}' already exist!`);return e.priority===void 0&&(e.priority=0),e.type===void 0&&(e.type=St.Append),this._hooks.push(e),l.toDisposable(()=>{const n=this._hooks.findIndex(o=>o===e);n>-1&&this._hooks.splice(n,1)})}registerRule(e){if(this._rules.find(o=>o.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const n=this._rules.findIndex(o=>o.priority<e.priority);this._rules.splice(n===-1?this._rules.length:n,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:n,unitId:o,subUnitId:r}=this.autoFillLocation||{};if(!e||!n||!o||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:n,unitId:o,subUnitId:r},this._direction,this.applyType))}),a=s.filter(u=>u.type===St.Only);if(a.length>0)return this.getOneByPriority(a);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(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,n){this._menu$.next(this._menu$.getValue().map(o=>o.value===e?{...o,disable:n}:o))}setShowMenu(e){this._showMenu$.next(e)}};exports.AutoFillService=Sl([l.OnLifecycle(l.LifecycleStages.Rendered,exports.AutoFillService),ri(0,N.Inject(_.SheetInterceptorService)),ri(1,N.Inject(l.IUniverInstanceService)),ri(2,N.Inject(_.SelectionManagerService))],exports.AutoFillService);const Jt=N.createIdentifier("univer.auto-fill-service");var _l=Object.defineProperty,fl=Object.getOwnPropertyDescriptor,pl=(i,t,e,n)=>{for(var o=n>1?void 0:n?fl(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&_l(t,e,o),o},We=(i,t)=>(e,n)=>t(e,n,i);exports.AutoFillController=class extends l.Disposable{constructor(e,n,o,r,s,a,c,d,u){super();I(this,"_beforeApplyData",[]);I(this,"_copyData",[]);I(this,"_defaultHook");this._univerInstanceService=e,this._selectionRenderService=n,this._commandService=o,this._undoRedoService=r,this._autoFillService=s,this._editorBridgeService=a,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,g)=>this._fillData(h,m,g)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[Yo,un].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initDefaultHook(){this._autoFillService.addHook(this._defaultHook)}_onSelectionControlFillChanged(){const e=new l.DisposableCollection;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==_.SetSelectionsOperation.id)return;const o=this._selectionManagerService.getCurrent();if((o==null?void 0:o.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return;e.dispose(),this._selectionRenderService.getCurrentControls().forEach(s=>{e.add(l.toDisposable(s.selectionFilled$.subscribe(a=>{if(a==null||a.startColumn===-1||a.startRow===-1||a.endColumn===-1||a.endRow===-1)return;const c={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow},d={startColumn:a.startColumn,endColumn:a.endColumn,startRow:a.startRow,endRow:a.endRow};this._triggerAutoFill(c,d)}))),e.add(l.toDisposable(s.fillControl.onDblclickObserver.add(()=>{const a={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow};this._handleDbClickFill(a)}))),e.add(l.toDisposable(s.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})})))})}))}_onApplyTypeChanged(){this.disposeWithMe(l.toDisposable(this._autoFillService.applyType$.subscribe(()=>{this._handleFillData()})))}_triggerAutoFill(e,n){var d;if(e.startColumn===n.startColumn&&e.startRow===n.startRow&&e.endColumn===n.endColumn&&e.endRow===n.endRow)return;if(n.endColumn<e.endColumn&&n.endColumn>e.startColumn){this._commandService.executeCommand(un.id,{clearRange:{startRow:n.startRow,endRow:n.endRow,startColumn:n.endColumn+1,endColumn:e.endColumn},selectionRange:n});return}if(n.endRow<e.endRow&&n.endRow>e.startRow){this._commandService.executeCommand(un.id,{clearRange:{startRow:n.endRow+1,endRow:e.endRow,startColumn:n.startColumn,endColumn:n.endColumn},selectionRange:n});return}const o={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn};let r=null;if(n.startRow<e.startRow)r=l.Direction.UP,o.endRow=e.startRow-1;else if(n.endRow>e.endRow)r=l.Direction.DOWN,o.startRow=e.endRow+1;else if(n.startColumn<e.startColumn)r=l.Direction.LEFT,o.endColumn=e.startColumn-1;else if(n.endColumn>e.endColumn)r=l.Direction.RIGHT,o.startColumn=e.endColumn+1;else return;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),a=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._autoFillService.direction=r,this._autoFillService.autoFillLocation={source:e,target:o,unitId:s,subUnitId:a},this._autoFillService.getActiveHooks().forEach(u=>{var h;(h=u==null?void 0:u.onBeforeFillData)==null||h.call(u,{source:e,target:o,unitId:s,subUnitId:a},r)}),(d=this._autoFillService.menu.find(u=>u.value===ie.SERIES))!=null&&d.disable?this._autoFillService.applyType=ie.COPY:this._autoFillService.applyType=ie.SERIES}_handleDbClickFill(e){const n=this._detectFillRange(e);n.endRow<=e.endRow||this._triggerAutoFill(e,n)}_detectFillRange(e){var m,g,S,f,C,R;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=e,a=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!a)return e;const c=a.getCellMatrix(),d=a.getMaxRows()-1,u=a.getMaxColumns()-1;let h=o;if(r>0&&((g=c.getValue(n,r-1))==null?void 0:g.v)!=null){let M=n;for(;((S=c.getValue(M,r-1))==null?void 0:S.v)!=null&&M<d;)M+=1;h=M-1}else if(s<u&&((f=c.getValue(o,s+1))==null?void 0:f.v)!=null){let M=n;for(;((C=c.getValue(M,s+1))==null?void 0:C.v)!=null&&M<d;)M+=1;h=M-1}for(let M=o+1;M<=h;M++)for(let w=r;w<=s;w++)if(((R=c.getValue(M,w))==null?void 0:R.v)!=null){h=M-1;break}return{startColumn:r,endColumn:s,startRow:n,endRow:h}}_handleFillData(){const{source:e,target:n,unitId:o=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:r=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=this._autoFillService.autoFillLocation||{},s=this._autoFillService.direction;if(!e||!n)return;const a=l.Rectangle.union(e,n),c=this._autoFillService.applyType,d=this._autoFillService.getActiveHooks();this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,{selections:[{primary:{...a,actualRow:a.startRow,actualColumn:a.startColumn,endColumn:a.startColumn,endRow:a.startRow},range:{...a,rangeType:l.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:r});const u=[],h=[];d.forEach(g=>{var C;const{undos:S,redos:f}=((C=g.onFillData)==null?void 0:C.call(g,{source:e,target:n,unitId:o,subUnitId:r},s,c))||{};S&&u.push(...S),f&&h.push(...f)}),h.every(g=>this._commandService.syncExecuteCommand(g.id,g.params))&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:u,redoMutations:h}),d.forEach(g=>{var S;(S=g.onAfterFillData)==null||S.call(g,{source:e,target:n,unitId:o,subUnitId:r},s,c)}),this._autoFillService.setShowMenu(!0)}_getApplyData(e,n,o,r,s,a=!0){const c=[],d=Math.floor(o/n),u=o%n,h=this._autoFillService.getRules();if(!a&&s===ie.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(g=>{m[g.type]=[]}),h.forEach(g=>{const{type:S,applyFunctions:f={}}=g,C=e[S];C&&C.forEach(R=>{const M=us(R.index,u),w=R.index.length*d+M,E=this._applyFunctions(R,w,r,s,f,e),T=hs(n,o,R.index);m[S].push({data:E,index:T})})});for(let g=0;g<o;g++)h.forEach(S=>{const{type:f}=S,C=m[f];for(let R=0;R<C.length;R++)g in C[R].index&&c.push(C[R].data[C[R].index[g]])});return c}_applyFunctions(e,n,o,r,s,a){const{data:c}=e,d=o===l.Direction.UP||o===l.Direction.LEFT;if(r===ie.COPY){const u=s==null?void 0:s[ie.COPY];return u?u(e,n,o,a):(d&&c.reverse(),ct(c,n))}if(r===ie.SERIES){const u=s==null?void 0:s[ie.SERIES];return u?u(e,n,o,a):(d&&c.reverse(),s!=null&&s[ie.COPY]?s[ie.COPY](e,n,o,a):ct(c,n))}if(r===ie.ONLY_FORMAT){const u=s==null?void 0:s[ie.ONLY_FORMAT];return u?u(e,n,o,a):ms(c,n)}}_getCopyData(e,n){const{startRow:o,startColumn:r,endRow:s,endColumn:a}=e,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=n===l.Direction.DOWN||n===l.Direction.UP;let m,g,S,f;h?(m=r,g=a,S=o,f=s):(m=o,g=s,S=r,f=a);for(let C=m;C<=g;C++){const R=this._getEmptyCopyDataPiece(),M={type:void 0,cellData:void 0};for(let w=S;w<=f;w++){let E;h?E=c.getValue(w,C):E=c.getValue(C,w);const{type:T,isContinue:O}=d.find(y=>y.match(E))||Mr;if(O(M,E)){const y=R[T],x=y[y.length-1];x.data.push(E),x.index.push(w-S)}else{const y=R[T];y?y.push({data:[E],index:[w-S]}):R[T]=[{data:[E],index:[w-S]}]}M.type=T,M.cellData=E}u.push(R)}return u}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(n=>{e[n.type]=[]}),e}_getMergeApplyData(e,n,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),a=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:g,endColumn:S}=b.getCellInfoInMergeData(c,d,s);if(u){if(o===l.Direction.DOWN){let f=h+r,C=g+r;for(;C<=n.endRow;)a.push({startRow:f,startColumn:m,endRow:C,endColumn:S}),f+=r,C+=r}else if(o===l.Direction.UP){let f=h-r,C=g-r;for(;f>=n.startRow;)a.push({startRow:f,startColumn:m,endRow:C,endColumn:S}),f-=r,C-=r}else if(o===l.Direction.RIGHT){let f=m+r,C=S+r;for(;C<=n.endColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:C}),f+=r,C+=r}else if(o===l.Direction.LEFT){let f=m-r,C=S-r;for(;f>=n.startColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:C}),f-=r,C-=r}}}return a}_presetAndCacheData(e,n){const{source:o,target:r}=e,s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),a=[];for(let c=r.startRow;c<=r.endRow;c++){const d=[];for(let u=r.startColumn;u<=r.endColumn;u++)d.push(l.Tools.deepClone(s.getValue(c,u)));a.push(d)}this._beforeApplyData=a,this._copyData=this._getCopyData(o,n),this._hasSeries(this._copyData)?this._autoFillService.setDisableApplyType(ie.SERIES,!1):this._autoFillService.setDisableApplyType(ie.SERIES,!0)}_fillData(e,n,o){var oe,re;const r=[],s=[];let a=!0;o===ie.NO_FORMAT&&(a=!1,o=ie.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||n==null)return{undos:r,redos:s};const{startRow:m,startColumn:g,endRow:S,endColumn:f}=c,{startRow:C,startColumn:R,endRow:M,endColumn:w}=d,E=this._copyData;let T;n===l.Direction.DOWN||n===l.Direction.UP?T=S-m+1:T=f-g+1;const O=[];if(n===l.Direction.DOWN||n===l.Direction.UP){const Y=M-C+1,X=[];for(let Q=R;Q<=w;Q++){const le=E[Q-R],se=this._getApplyData(le,T,Y,n,o,a);X.push(se)}for(let Q=0;Q<X[0].length;Q++){const le=[];for(let se=0;se<X.length;se++)le.push({s:null,...X[se][Q]});O.push(le)}}else{const Y=w-R+1;for(let X=C;X<=M;X++){const Q=E[X-C],le=this._getApplyData(Q,T,Y,n,o,a),se=[];for(let me=0;me<le.length;me++)se.push({s:null,...le[me]});O.push(se)}}let y=[];const x=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();a?(y=this._getMergeApplyData(c,d,n,T),O.forEach(Y=>{Y.forEach(X=>{X&&x&&x&&(X.s=x.getStyleByCell(X))})})):O.forEach((Y,X)=>{Y.forEach((Q,le)=>{Q&&x&&(Q.s=x.getStyleByCell(this._beforeApplyData[X][le])||null)})}),o===ie.ONLY_FORMAT&&O.forEach((Y,X)=>{Y.forEach((Q,le)=>{if(Q){const se=this._beforeApplyData[X][le]||{};Q.f=se.f,Q.si=se.si,Q.t=se.t,Q.v=se.v}})});const A={get:this._injector.get.bind(this._injector)},k=[],L=(re=(oe=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:oe.getSheetBySheetId(h))==null?void 0:re.getMergeData();L&&L.forEach(Y=>{l.Rectangle.intersects(Y,d)&&k.push(Y)});const F={unitId:u,subUnitId:h,ranges:k},V=_.RemoveMergeUndoMutationFactory(A,F);s.push({id:_.RemoveWorksheetMergeMutation.id,params:F}),r.push({id:_.AddWorksheetMergeMutation.id,params:V});const j={subUnitId:h,unitId:u,cellValue:zo([d])},$=_.SetRangeValuesUndoMutationFactory(A,j),Z=this._sheetInterceptorService.onCommandExecute({id:_.ClearSelectionContentCommand.id});s.push({id:_.SetRangeValuesMutation.id,params:j},...Z.redos),r.push(...Z.undos,{id:_.SetRangeValuesMutation.id,params:$});const W=new l.ObjectMatrix,{startRow:G,startColumn:ne,endRow:D,endColumn:U}=d;for(let Y=0;Y<=D-G;Y++)for(let X=0;X<=U-ne;X++)O[Y][X]&&W.setValue(Y+G,X+ne,O[Y][X]);const z={subUnitId:h,unitId:u,cellValue:W.getMatrix()},q=_.SetRangeValuesUndoMutationFactory(A,z);if(r.push({id:_.SetRangeValuesMutation.id,params:q}),s.push({id:_.SetRangeValuesMutation.id,params:z}),y!=null&&y.length){const Y=_.getAddMergeMutationRangeByType(y),X={unitId:u,subUnitId:h,ranges:Y},Q=_.AddMergeUndoMutationFactory(A,X);r.push({id:_.RemoveWorksheetMergeMutation.id,params:Q}),s.push({id:_.AddWorksheetMergeMutation.id,params:X})}return{undos:r,redos:s}}_hasSeries(e){return e.some(n=>Object.keys(n).some(r=>{var s;return!!((s=n[r])!=null&&s.length&&![de.OTHER,de.FORMULA].includes(r))}))}};exports.AutoFillController=pl([l.OnLifecycle(l.LifecycleStages.Steady,exports.AutoFillController),We(0,l.IUniverInstanceService),We(1,fe),We(2,l.ICommandService),We(3,l.IUndoRedoService),We(4,Jt),We(5,Ee),We(6,N.Inject(_.SheetInterceptorService)),We(7,N.Inject(_.SelectionManagerService)),We(8,N.Inject(N.Injector))],exports.AutoFillController);const br={id:"sheet.command.hide-row-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const e=(c=i.get(_.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(rr(a,e)){const d=i.get(v.IConfirmService),u=i.get(l.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 n.executeCommand(_.SetRowHiddenCommand.id),!0}},wr={id:"sheet.command.hide-col-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const e=(c=i.get(_.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(sr(a,e)){const d=i.get(v.IConfirmService),u=i.get(l.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 n.executeCommand(_.SetColHiddenCommand.id),!0}},Li={type:l.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatBoldCommand.id):t.executeCommand(_.SetBoldCommand.id)}},Pi={type:l.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatItalicCommand.id):t.executeCommand(_.SetItalicCommand.id)}},Ui={type:l.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatUnderlineCommand.id):t.executeCommand(_.SetUnderlineCommand.id)}},ki={type:l.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatStrikethroughCommand.id):t.executeCommand(_.SetStrikeThroughCommand.id)}},Cl={type:l.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},vl={type:l.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},Tr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,t)=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontSizeCommand.id,t):e.executeCommand(_.SetFontSizeCommand.id,t)}},Er={type:l.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,t)=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontFamilyCommand.id,t):e.executeCommand(_.SetFontFamilyCommand.id,t)}},Wn={type:l.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,t)=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatTextColorCommand.id,t):e.executeCommand(_.SetTextColorCommand.id,t)}};function Or(i,t){return t.some(e=>Il(i,e))}function Il(i,t){const{startRow:e,startColumn:n,endColumn:o,endRow:r}=t,s=i.getMatrixWithMergedCells(e,n,r,o);let a=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==n)&&i.cellHasValue(u))return a=!0,!1}),a}function yr(i,t,e,n){const o=[],r=[],s=e.getSheetId();return n.forEach(a=>{const c=Rl(e,a),d={unitId:t,subUnitId:s,cellValue:c.getData()},u=_.SetRangeValuesUndoMutationFactory(i,d);o.push({id:_.SetRangeValuesMutation.id,params:u}),r.push({id:_.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function Rl(i,t){const{startRow:e,startColumn:n,endColumn:o,endRow:r}=t,s=i.getMatrixWithMergedCells(e,n,r,o),a=new l.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==e||d!==n)&&a.setValue(c,d,null)}),a}var Ml=Object.defineProperty,bl=Object.getOwnPropertyDescriptor,wl=(i,t,e,n)=>{for(var o=n>1?void 0:n?bl(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Ml(t,e,o),o},si=(i,t)=>(e,n)=>t(e,n,i),ye=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(ye||{});const wt=N.createIdentifier("univer.format-painter-service");let Ri=class extends l.Disposable{constructor(t,e,n){super();I(this,"status$");I(this,"_selectionFormat");I(this,"_markId",null);I(this,"_status$");this._selectionManagerService=t,this._univerInstanceService=e,this._markSelectionService=n,this._status$=new H.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new l.ObjectMatrix,merges:[]}}setStatus(t){t!==0&&this._getSelectionRangeFormat(),this._updateRangeMark(t),this._status$.next(t)}getStatus(){return this._status$.getValue()}_updateRangeMark(t){if(this._markSelectionService.removeAllShapes(),this._markId=null,t!==0){const e=this._selectionManagerService.getLast();if(e){const n=this._selectionManagerService.createCopyPasteSelection();t===2?this._markId=this._markSelectionService.addShape({...e,style:n}):this._markId=this._markSelectionService.addShape({...e,style:n},[_.SetRangeValuesMutation.id])}}}_getSelectionRangeFormat(){const t=this._selectionManagerService.getLast(),e=t==null?void 0:t.range;if(!e)return;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=e,a=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(a==null?void 0:a.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=a.getStyles(),m=new l.ObjectMatrix;for(let g=n;g<=o;g++)for(let S=r;S<=s;S++){const f=d.getValue(g,S);m.setValue(g,S,h.getStyleByCell(f)||{});const{isMergedMainCell:C,...R}=b.getCellInfoInMergeData(g,S,u);C&&this._selectionFormat.merges.push({startRow:R.startRow,startColumn:R.startColumn,endRow:R.endRow,endColumn:R.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};Ri=wl([si(0,N.Inject(_.SelectionManagerService)),si(1,l.IUniverInstanceService),si(2,qt)],Ri);const Vi={id:"sheet.operation.set-format-painter",type:l.CommandType.OPERATION,handler:(i,t)=>t?(i.get(wt).setStatus(t.status),!0):!1},xr={type:l.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const e=i.get(wt).getStatus();let n;return e!==ye.OFF?n=ye.OFF:n=ye.INFINITE,i.get(l.ICommandService).executeCommand(Vi.id,{status:n})}},Bi={type:l.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const e=i.get(wt).getStatus();let n;return e!==ye.OFF?n=ye.OFF:n=ye.ONCE,i.get(l.ICommandService).executeCommand(Vi.id,{status:n})}},Ar={type:l.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,t)=>{const e=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(_.SelectionManagerService),s=i.get(_.SheetInterceptorService),{styleValues:a,styleRange:c,mergeRanges:d,unitId:u=o.getCurrentUniverSheetInstance().getUnitId(),subUnitId:h=o.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=t,m=c?[c]:r.getSelectionRanges();if(!m||!m.length)return!1;const g=new l.ObjectMatrix;let S;if(l.Tools.isArray(a))for(let j=0;j<m.length;j++){const{startRow:$,startColumn:Z,endRow:W,endColumn:G}=m[j];for(let ne=0;ne<=W-$;ne++)for(let D=0;D<=G-Z;D++)g.setValue(ne+$,D+Z,a[ne][D])}else if(l.isICellData(a))for(let j=0;j<m.length;j++){const{startRow:$,startColumn:Z}=m[j];g.setValue($,Z,a)}else S=a;const f={subUnitId:h,unitId:u,cellValue:S!=null?S:g.getMatrix()},C=_.SetRangeValuesUndoMutationFactory(i,f);if(!s.fetchThroughInterceptors(_.INTERCEPTOR_POINT.PERMISSION)(null,{id:_.SetRangeValuesCommand.id,params:f}))return!1;const R=e.syncExecuteCommand(_.SetRangeValuesMutation.id,f),{undos:M,redos:w}=s.onCommandExecute({id:_.SetRangeValuesCommand.id,params:{...f,range:m}}),E=_.getAddMergeMutationRangeByType(d),T=o.getUniverSheetInstance(u).getSheetBySheetId(h),O=[],y=[],x=Or(T,E),A={unitId:u,subUnitId:h,ranges:E},k={unitId:u,subUnitId:h,ranges:E};O.push({id:_.RemoveWorksheetMergeMutation.id,params:A}),O.push({id:_.AddWorksheetMergeMutation.id,params:k});const L=_.RemoveMergeUndoMutationFactory(i,A),F=_.AddMergeUndoMutationFactory(i,k);if(y.push({id:_.RemoveWorksheetMergeMutation.id,params:F}),y.push({id:_.AddWorksheetMergeMutation.id,params:L}),x){const j=yr(i,u,T,E);O.unshift(...j.redos),y.push(...j.undos)}const V=await l.sequenceExecute([...w,...O],e);return R&&V.result?(n.pushUndoRedo({unitID:u,undoMutations:[{id:_.SetRangeValuesMutation.id,params:C},...M,...y],redoMutations:[{id:_.SetRangeValuesMutation.id,params:f},...w,...O]}),!0):!1}},Xn={type:l.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,t)=>{const{type:e}=t||{},n=i.get(l.IUniverInstanceService),o=i.get(l.IUndoRedoService),r=n.getCurrentUniverSheetInstance().getUnitId(),s=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),a=i.get(l.ICommandService),d=i.get(_.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(Qe),{sheetViewStartRow:g=0,sheetViewStartColumn:S=0}=m.getCurrentScroll()||{};let f,C,R,M;const{startRow:w,startColumn:E,rangeType:T}=h;if(T===l.RANGE_TYPE.ROW||e===1)f=w,R=w-g,C=-1,M=0;else if(T===l.RANGE_TYPE.COLUMN||e===2)f=-1,R=0,C=E,M=E-S;else if(T===l.RANGE_TYPE.NORMAL)f=w,R=w-g,C=E,M=E-S;else return!1;const O={unitId:r,subUnitId:s,startRow:f,startColumn:C,xSplit:C>0?Math.max(1,M):M,ySplit:f>0?Math.max(1,R):R},y=_.SetFrozenMutationFactory(i,O);return a.syncExecuteCommand(_.SetFrozenMutation.id,O)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:_.SetFrozenMutation.id,params:y}],redoMutations:[{id:_.SetFrozenMutation.id,params:O}]}),!0}},Nr={type:l.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(Xn.id,{type:1}),!0)},Dr={type:l.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(Xn.id,{type:2}),!0)},Hr={type:l.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(l.IUndoRedoService),o=e.getCurrentUniverSheetInstance().getUnitId(),r=e.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},a=_.SetFrozenMutationFactory(i,s);return t.syncExecuteCommand(_.SetFrozenMutation.id,s)&&n.pushUndoRedo({unitID:o,undoMutations:[{id:_.SetFrozenMutation.id,params:a}],redoMutations:[{id:_.SetFrozenMutation.id,params:s}]}),!0}},Tt="UI_PLUGIN_SHEETS",Zn=`${Tt}_COLOR_PICKER_COMPONENT`,Lr=`${Tt}_FONT_FAMILY_COMPONENT`,Pr=`${Tt}_FONT_FAMILY_ITEM_COMPONENT`,Ur=`${Tt}_FONT_SIZE_COMPONENT`,Fi=`${Tt}_MENU_ITEM_INPUT_COMPONENT`,Tl="univer-sheets-ui-context-menu-input",El="univer-sheets-ui-context-menu-input-container",Ol="univer-sheets-ui-context-menu-input-number",ai={sheetsUiContextMenuInput:Tl,sheetsUiContextMenuInputContainer:El,sheetsUiContextMenuInputNumber:Ol},yl=i=>{const{prefix:t,suffix:e,value:n,onChange:o,min:r=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=i,a=K.useDependency(l.LocaleService),[c,d]=P.useState(),u=m=>{var g;d(m==null?void 0:m.toString()),o((g=m==null?void 0:m.toString())!=null?g:"")};P.useEffect(()=>{d(n)},[n]);function h(m){m.key==="Backspace"&&m.stopPropagation()}return p.jsxs("div",{className:ai.sheetsUiContextMenuInput,children:[a.t(t),p.jsx("span",{className:ai.sheetsUiContextMenuInputContainer,onClick:m=>m.stopPropagation(),children:p.jsx(ge.InputNumber,{className:ai.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:h,onChange:u,min:r,max:s})}),a.t(e)]})};var ce=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(ce||{});function xl(i){const t=i.get(wt);return{id:Bi.id,subId:xr.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",positions:[v.MenuPosition.TOOLBAR_START],activated$:new H.Observable(e=>{let n=!1;const o=t.status$.subscribe(r=>{n=r!==ye.OFF,e.next(n)});return e.next(n),()=>{o.unsubscribe()}}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function Al(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(l.IContextService),o=i.get(_.SelectionManagerService);return{id:Li.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[v.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=t.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=o.getLast())==null?void 0:d.primary,m=e.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontWeight.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getFontWeight()}r.next(g===l.FontWeight.BOLD)}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&n.getContextValue(l.EDITOR_ACTIVATED)&&n.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.bl;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Nl(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:Pi.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[v.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=t.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=e.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontItalic.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getFontStyle()}r.next(g===l.FontItalic.ITALIC)}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.it;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Dl(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:Ui.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[v.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=t.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=e.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getUnderline()}r.next(!!(g&&g.s))}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.ul;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Hl(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:ki.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[v.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=t.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=e.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getStrikeThrough()}r.next(!!(g&&g.s))}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=en(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.st;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Ll(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:Er.id,tooltip:"toolbar.font",group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.SELECTOR,label:Lr,positions:[v.MenuPosition.TOOLBAR_START],selections:v.FONT_FAMILY_LIST.map(o=>({label:{name:Pr,hoverable:!0},value:o.value})),disabled$:_.getCurrentSheetDisabled$(i),value$:new H.Observable(o=>{const r=v.FONT_FAMILY_LIST[0].value,s=t.onCommandExecuted(a=>{var m;const c=a.id;if(c!==_.SetRangeValuesMutation.id&&c!==_.SetSelectionsOperation.id)return;const d=(m=n.getLast())==null?void 0:m.primary,u=e.getCurrentUniverSheetInstance().getActiveSheet();let h;if(d!=null){const g=u.getRange(d.startRow,d.startColumn);h=g==null?void 0:g.getFontFamily()}o.next(h!=null?h:r)});return o.next(r),s.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Pl(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService),r=_.getCurrentSheetDisabled$(i);return{id:Tr.id,group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ur,props:{min:1,max:400,disabled$:r}},positions:[v.MenuPosition.TOOLBAR_START],selections:v.FONT_SIZE_LIST,disabled$:r,value$:new H.Observable(s=>{const c=t.onCommandExecuted(d=>{var h,m;const u=d.id;if(u===_.SetRangeValuesMutation.id||u===_.SetSelectionsOperation.id){const g=(h=n.getLast())==null?void 0:h.primary,S=e.getCurrentUniverSheetInstance().getActiveSheet();let f;if(g!=null){const C=S.getRange(g.startRow,g.startColumn);f=C==null?void 0:C.getFontSize()}s.next(f!=null?f:14)}if((u===J.SetTextSelectionsOperation.id||u===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const g=en(i);if(g==null)return;const S=(m=g.ts)==null?void 0:m.fs;s.next(S!=null?S:14)}});return s.next(14),c.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Ul(i){return{id:_.ResetTextColorCommand.id,type:v.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:Wn.id,disabled$:_.getCurrentSheetDisabled$(i)}}function kl(i){const t=i.get(l.ICommandService),e=i.get(l.ThemeService);return{id:Wn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON_SELECTOR,positions:[v.MenuPosition.TOOLBAR_START],selections:[{label:{name:Zn,hoverable:!1}}],value$:new H.Observable(n=>{const o=e.getCurrentTheme().textColor,r=t.onCommandExecuted(s=>{if(s.id===Wn.id){const a=s.params.value;n.next(a!=null?a:o)}});return n.next(o),r.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function Vl(i){return{id:_.ResetBackgroundColorCommand.id,type:v.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:_.SetBackgroundColorCommand.id,disabled$:_.getCurrentSheetDisabled$(i)}}function Bl(i){const t=i.get(l.ICommandService),e=i.get(l.ThemeService);return{id:_.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:v.MenuGroup.TOOLBAR_FORMAT,type:v.MenuItemType.BUTTON_SELECTOR,positions:[v.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Zn,hoverable:!1}}],value$:new H.Observable(n=>{const o=e.getCurrentTheme().primaryColor,r=t.onCommandExecuted(s=>{if(s.id===_.SetBackgroundColorCommand.id){const a=s.params.value;n.next(a!=null?a:o)}});return n.next(o),r.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const vo=[{label:"align.left",icon:"LeftJustifyingSingle",value:l.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:l.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:l.HorizontalAlign.RIGHT}];function Fl(i){const t=i.get(l.IUniverInstanceService),e=i.get(_.SelectionManagerService);return{id:_.SetHorizontalTextAlignCommand.id,icon:vo[0].icon,positions:[v.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:v.MenuGroup.TOOLBAR_LAYOUT,type:v.MenuItemType.SELECTOR,selections:vo,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetHorizontalTextAlignCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}n.next(d!=null?d:l.HorizontalAlign.LEFT)});return n.next(l.HorizontalAlign.LEFT),o.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const Io=[{label:"align.top",icon:"AlignTopSingle",value:l.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:l.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:l.VerticalAlign.BOTTOM}];function Wl(i){const t=i.get(l.IUniverInstanceService),e=i.get(_.SelectionManagerService);return{id:_.SetVerticalTextAlignCommand.id,icon:Io[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:v.MenuGroup.TOOLBAR_LAYOUT,type:v.MenuItemType.SELECTOR,positions:[v.MenuPosition.TOOLBAR_START],selections:Io,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetVerticalTextAlignCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getVerticalAlignment()}n.next(d!=null?d:l.VerticalAlign.TOP)});return n.next(l.VerticalAlign.TOP),o.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const Ro=[{label:"textWrap.overflow",icon:"OverflowSingle",value:l.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:l.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:l.WrapStrategy.CLIP}];function jl(i){const t=i.get(_.SelectionManagerService),e=i.get(l.IUniverInstanceService);return{id:_.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:Ro[0].icon,group:v.MenuGroup.TOOLBAR_LAYOUT,type:v.MenuItemType.SELECTOR,positions:[v.MenuPosition.TOOLBAR_START],selections:Ro,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetTextWrapCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getWrapStrategy()}n.next(d!=null?d:l.WrapStrategy.OVERFLOW)});return n.next(l.WrapStrategy.OVERFLOW),o.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const Mo=[{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 $l(i){const t=i.get(_.SelectionManagerService),e=i.get(l.IUniverInstanceService);return{id:_.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Mo[0].icon,group:v.MenuGroup.TOOLBAR_LAYOUT,type:v.MenuItemType.SELECTOR,selections:Mo,positions:[v.MenuPosition.TOOLBAR_START],value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u,h;const s=r.id;if(s!==_.SetTextRotationCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const m=c.getRange(a.startRow,a.startColumn);d=m==null?void 0:m.getTextRotation()}(d==null?void 0:d.v)===l.BooleanNumber.TRUE?n.next("v"):n.next((h=d&&d.a)!=null?h:0)});return n.next(0),o.dispose}),hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function Et(i){return new H.Observable(t=>t.next(!i.get(v.IClipboardInterfaceService).supportClipboard))}function zl(){return{id:v.CopyCommand.id,group:v.MenuGroup.CONTEXT_MENU_FORMAT,type:v.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",positions:[v.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Yl(i){return{id:v.PasteCommand.id,group:v.MenuGroup.CONTEXT_MENU_FORMAT,type:v.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:Et(i),positions:[v.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const Ot="sheet.menu.paste-special";function Xl(i){return{id:Ot,group:v.MenuGroup.CONTEXT_MENU_FORMAT,type:v.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",disabled$:Et(i),positions:[v.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Zl(i){return{id:er.id,type:v.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[Ot],disabled$:Et(i)}}function Gl(i){return{id:tr.id,type:v.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[Ot],disabled$:Et(i)}}function Kl(i){return{id:nr.id,type:v.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[Ot],disabled$:Et(i)}}function ql(i){return{id:ir.id,type:v.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[Ot],disabled$:Et(i)}}function Jl(){return{id:_.SetWorksheetRowIsAutoHeightCommand.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Qt="sheet.menu.sheet-frozen";function Ql(){return{id:Qt,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[v.MenuPosition.CONTEXT_MENU]}}const Wi="sheet.header-menu.sheet-frozen";function ec(){return{id:Wi,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function tc(){return{id:Xn.id,type:v.MenuItemType.BUTTON,positions:[Qt,Wi],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function nc(){return{id:Nr.id,type:v.MenuItemType.BUTTON,positions:[Qt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function ic(){return{id:Dr.id,type:v.MenuItemType.BUTTON,positions:[Qt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function oc(){return{id:Hr.id,type:v.MenuItemType.BUTTON,positions:[Qt,Wi],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function rc(){return{id:br.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function sc(){return{id:wr.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function ac(i){const t=i.get(l.IUniverInstanceService),e=i.get(_.SelectionManagerService);function n(){var a;const r=t.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=e.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.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(l.ICommandService);return{id:_.SetSelectedRowsVisibleCommand.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new H.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===_.SetSelectionsOperation.id||a.id===_.SetRowHiddenMutation.id||a.id===_.SetRowVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function lc(i){const t=i.get(l.IUniverInstanceService),e=i.get(_.SelectionManagerService);function n(){var a;const r=t.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=e.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.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(l.ICommandService);return{id:_.SetSelectedColsVisibleCommand.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new H.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===_.SetSelectionsOperation.id||a.id===_.SetColHiddenMutation.id||a.id===_.SetColVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function cc(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:_.SetRowHeightCommand.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:Fi,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:new H.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;a!=null&&(d=c.getRowHeight(a.startRow)),o.next(d!=null?d:0)}const s=t.onCommandExecuted(a=>{const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function dc(i){const t=i.get(l.ICommandService),e=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:_.SetColWidthCommand.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:Fi,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:new H.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d=0;a!=null&&(d=c.getColumnWidth(a.startColumn)),o.next(d)}const s=t.onCommandExecuted(a=>{const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function en(i){var c;const t=i.get(l.IUniverInstanceService),e=i.get(J.TextSelectionManagerService),n=t.getUniverDocInstance(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=e.getActiveRange();if(n==null||o==null)return;const r=(c=n.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,t){const n=i.getCurrentUniverSheetInstance().getUnitId(),o=t.getRenderById(n);if(o==null)return;const{components:r,mainComponent:s,scene:a,engine:c}=o,d=s,u=r.get(Se.ROW),h=r.get(Se.COLUMN),m=r.get(Se.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:a,engine:c}}function Mi(i,t,e,n){const{startX:o,startY:r,endX:s,endY:a}=n.getCellByIndex(i,t);return{startX:o,startY:r,endX:s,endY:a}}function It(i,t,e,n,o){const r=e.getRelativeCoord(b.Vector2.FromArray([i,t])),{x:s,y:a}=r,c=e.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=e.getAncestorScale(),h=n.getCellPositionByOffset(s,a,d,u,c),{row:m,column:g}=h,S=n.getNoMergeCellPositionByIndex(m,g),{startX:f,startY:C,endX:R,endY:M}=S;return{startX:f,startY:C,endX:R,endY:M,row:m,column:g}}function hn(i,t,e,n){const o=e.getRelativeCoord(b.Vector2.FromArray([i,t])),r=e.getViewport(B.VIEW_MAIN),s=e.getScrollXYByRelativeCoords(o,r),{scaleX:a,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=i/a+d,m=t/c+u;return{x:h,y:m}}const uc={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",conditionalalFormat:"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"},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"},hc=uc,mc={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":"编辑表格"},kr=mc,gc=(i,t,e=!1)=>{const n=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=n(t)%n(i),s=o(t)%o(i),a={startRow:0,endRow:n(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(n(t)/n(i)),d=Math.floor(o(t)/o(i)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let m=1;m<=d;m++){const g=n(i)*(h-1),S=o(i)*(m-1),f={startRow:g+t.startRow,endRow:g+t.startRow,startColumn:S+t.startColumn,endColumn:S+t.startColumn};u.push({repeatRelativeRange:a,startRange:f})}else if(!r&&s&&!e)for(let h=1;h<=c;h++){const m=n(i)*(h-1),g=0,S={startRow:m+t.startRow,endRow:m+t.startRow,startColumn:g+t.startColumn,endColumn:g+t.startColumn};u.push({repeatRelativeRange:a,startRange:S})}else if(r&&!s&&!e)for(let h=1;h<=d;h++){const g=o(i)*(h-1),S={startRow:0+t.startRow,endRow:0+t.startRow,startColumn:g+t.startColumn,endColumn:g+t.startColumn};u.push({repeatRelativeRange:a,startRange:S})}else{const h={startRow:t.startRow,endRow:t.startRow,startColumn:t.startColumn,endColumn:t.startColumn};u.push({startRange:h,repeatRelativeRange:a})}return u};class Vr{constructor(){I(this,"_state",null);I(this,"_rect",null);I(this,"_focus",!1);I(this,"_state$",new H.BehaviorSubject(null));I(this,"state$",this._state$.asObservable());I(this,"_rect$",new H.BehaviorSubject(null));I(this,"rect$",this._rect$.asObservable());I(this,"_focus$",new H.BehaviorSubject(this._focus));I(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(t){this._state=t,this._refresh(t)}getRect(){return this._rect}setRect(t){this._rect=t,this._rect$.next(t)}getState(){return this._state}setFocus(t=!1){this._focus=t,this._focus$.next(t)}_refresh(t){this._state$.next(t)}}const tn=N.createIdentifier("univer.sheet-cell-editor-manager.service");class Sc{constructor(){I(this,"_position",null);I(this,"_position$",new H.BehaviorSubject(null));I(this,"position$",this._position$.asObservable());I(this,"_focus",!1);I(this,"_focus$",new H.BehaviorSubject(this._focus));I(this,"focus$",this._focus$.asObservable());I(this,"_fxBtnClick$",new H.BehaviorSubject(!1));I(this,"fxBtnClick$",this._fxBtnClick$.asObservable());I(this,"_foldBtnStatus$",new H.BehaviorSubject(!1));I(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(t){this._position=t,this._refresh(t)}getPosition(){return this._position}setFocus(t=!1){this._focus=t,this._focus$.next(t)}handleFxBtnClick(t){this._fxBtnClick$.next(t)}handleFoldBtnClick(t){this._foldBtnStatus$.next(t)}_refresh(t){this._position$.next(t)}}const Gn=N.createIdentifier("univer.sheet-formula-editor-manager.service");var _c=Object.defineProperty,fc=Object.getOwnPropertyDescriptor,pc=(i,t,e,n)=>{for(var o=n>1?void 0:n?fc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&_c(t,e,o),o},bo=(i,t)=>(e,n)=>t(e,n,i);let mn=class extends l.Disposable{constructor(t,e){super();I(this,"_previousSheetIndex",-1);this._commandService=t,this._univerInstanceService=e,this.disposeWithMe(this._commandService.beforeCommandExecuted((n,o)=>{if(n.id===_.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(n)})),this.disposeWithMe(this._commandService.onCommandExecuted((n,o)=>{if(n.id===_.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(n);if(n.id===_.SetWorksheetHideMutation.id&&n.params.hidden)return this._adjustActiveSheetOnHideSheet(n);if(!(o!=null&&o.fromCollab)){if(n.id===_.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(n);if(n.id===_.SetWorksheetHideMutation.id&&!n.params.hidden)return this._adjustActiveSheetOnShowSheet(n)}}))}_adjustActiveSheetOnHideSheet(t){const{unitId:e,subUnitId:n}=t.params,o=this._univerInstanceService.getUniverSheetInstance(e);if(!o||o.getActiveSheet().getSheetId()!==n)return;const s=o.getActiveSheetIndex(),a=wo(o,s);this._switchToNextSheet(e,a)}_beforeAdjustActiveSheetOnRemoveSheet(t){const{unitId:e,subUnitId:n}=t.params,o=this._univerInstanceService.getUniverSheetInstance(e);if(!o)return;const r=o.getSheetBySheetId(n);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(t){if(this._previousSheetIndex===-1)return;const{unitId:e}=t.params,n=this._univerInstanceService.getUniverSheetInstance(e);if(!n||n.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,a=wo(n,s);this._switchToNextSheet(e,a)}_adjustActiveSheetOnInsertSheet(t){const{unitId:e,sheet:n}=t.params;this._switchToNextSheet(e,n.id)}_adjustActiveSheetOnShowSheet(t){const{unitId:e,subUnitId:n}=t.params;this._switchToNextSheet(e,n)}_switchToNextSheet(t,e){this._commandService.executeCommand(_.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:e})}};mn=pc([l.OnLifecycle(l.LifecycleStages.Ready,mn),bo(0,l.ICommandService),bo(1,l.IUniverInstanceService)],mn);function wo(i,t){const e=i.getSheetSize();for(let n=t;n>-1;n--){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}for(let n=t;n<e;n++){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var Cc=Object.defineProperty,vc=Object.getOwnPropertyDescriptor,Ic=(i,t,e,n)=>{for(var o=n>1?void 0:n?vc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Cc(t,e,o),o},Ut=(i,t)=>(e,n)=>t(e,n,i);let gn=class{constructor(i,t,e,n,o){this._injector=i,this._sheetInterceptorService=t,this._selectionManagerService=e,this._univerInstanceService=n,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:t,_sheetSkeletonManagerService:e,_injector:n}=this,{skeleton:o}=e.getCurrent(),r=o.calculateAutoHeightInRange(i),s=t.getCurrentUniverSheetInstance(),a=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:a,rowsAutoHeightInfo:r},u=_.SetWorksheetRowAutoHeightMutationFactory(n,d);return{undos:[{id:_.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:_.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:t}=this;i.interceptCommand({getMutations:e=>e.id!==_.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(e.params.range)}),i.interceptCommand({getMutations:e=>e.id!==_.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(e.params.ranges)}),i.interceptCommand({getMutations:e=>{var r;if(e.id!==_.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=e.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=t.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};gn=Ic([l.OnLifecycle(l.LifecycleStages.Ready,gn),Ut(0,N.Inject(N.Injector)),Ut(1,N.Inject(_.SheetInterceptorService)),Ut(2,N.Inject(_.SelectionManagerService)),Ut(3,N.Inject(l.IUniverInstanceService)),Ut(4,N.Inject(exports.SheetSkeletonManagerService))],gn);var Rc=Object.defineProperty,Mc=Object.getOwnPropertyDescriptor,bc=(i,t,e,n)=>{for(var o=n>1?void 0:n?Mc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Rc(t,e,o),o},Oe=(i,t)=>(e,n)=>t(e,n,i);let Sn=class extends l.RxDisposable{constructor(i,t,e,n,o,r,s,a,c,d,u){var h;super(),this._injector=i,this._currentUniverSheet=t,this._commandService=e,this._contextService=n,this._configService=o,this._sheetClipboardService=r,this._clipboardInterfaceService=s,this._messageService=a,this._sheetSkeletonManagerService=c,this._localService=d,this._textSelectionRenderManager=u,this._init(),this._clipboardInterfaceService.supportClipboard||(h=this._textSelectionRenderManager)==null||h.onPaste$.pipe(H.takeUntil(this.dispose$)).subscribe(m=>{var C,R;if(!te(this._contextService))return;m.event.preventDefault();const g=m.event,S=(C=g.clipboardData)==null?void 0:C.getData("text/html"),f=(R=g.clipboardData)==null?void 0:R.getData("text/plain");this._sheetClipboardService.legacyPaste(S,f)})}_init(){[Qo,ua,Mt].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t))),[er,tr,nr,ir].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t))),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initCopyingHooks())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initPastingHook()));const i=this._initSpecialPasteHooks().map(t=>this._sheetClipboardService.addClipboardHook(t));this.disposeWithMe({dispose:()=>i.forEach(t=>t.dispose())})}_initCopyingHooks(){const i=this;let t=null;return{id:_e.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(e,n){t=i._getWorksheet(e,n)},onCopyCellContent(e,n){const o=t.getCell(e,n);return`${(o==null?void 0:o.v)||""}`},onCopyCellStyle:(e,n,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=t.getRange(e,n).getTextStyle();let d="";return c&&(d=l.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(e){return{width:`${t.getColumnWidth(e)}`}},onCopyRow(e){return{style:`height: ${t.getRowHeight(e)}px;`}},onAfterCopy(){t=null}}}_initPastingHook(){const i=this;let t=null,e=null,n=null;return{id:_e.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste({unitId:o,subUnitId:r,range:s}){n=i._getWorksheet(o,r),t=o,e=r;const a=i._configService.getConfig(_.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return a&&c*d>a?(i._messageService.show({type:ge.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const{range:s}=o,a=[],c=n.getMaxRows(),d=s.endRow-c,u=r.length-d;if(d>0){const g={};r.slice(u).forEach((f,C)=>{const{style:R,height:M}=f||{};if(R){const w=R.split(";");let E=l.DEFAULT_WORKSHEET_ROW_HEIGHT;w.find(T=>{T=T.toLowerCase();const O=v.textTrim(T.substr(0,T.indexOf(":"))),y=v.textTrim(T.substr(T.indexOf(":")+1));return O==="height"?(E=Number.parseFloat(y),!0):!1}),g[C]={h:E,hd:l.BooleanNumber.FALSE}}else M&&(g[C]={h:Number.parseFloat(M),hd:l.BooleanNumber.FALSE})});const S={unitId:t,subUnitId:e,range:{...s,startRow:c},rowInfo:g};a.push({id:_.InsertRowMutation.id,params:S})}const h={};r.slice(0,u).forEach((g,S)=>{const{style:f,height:C}=g;if(f){const R=f.split(";");let M=l.DEFAULT_WORKSHEET_ROW_HEIGHT;R.find(w=>{w=w.toLowerCase();const E=v.textTrim(w.substr(0,w.indexOf(":"))),T=v.textTrim(w.substr(w.indexOf(":")+1));return E==="height"?(M=Number.parseFloat(T),!0):!1}),h[S+s.startRow]=M}else C&&(h[S+s.startRow]=Number.parseFloat(C))});const m={unitId:t,subUnitId:e,ranges:[{...s,endRow:Math.min(s.endRow,c)}],rowHeight:h};return a.push({id:_.SetWorksheetRowHeightMutation.id,params:m}),{redos:a,undos:[]}},onPasteColumns(o,r,s){var S;const{range:a}=o,c=[],d=n.getMaxColumns(),u=a.endColumn-d,h=r.length-u,m=(S=i._configService.getConfig(l.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?S:l.DEFAULT_WORKSHEET_COLUMN_WIDTH;if(u>0){const f={unitId:t,subUnitId:e,range:{...a,startColumn:d},colInfo:r.slice(h).map(C=>({w:C.width?+C.width:m,hd:l.BooleanNumber.FALSE}))};c.push({id:_.InsertColMutation.id,params:f})}const g={unitId:t,subUnitId:e,ranges:[{...a,endRow:Math.min(a.endColumn,d)}],colWidth:r.slice(0,h).map(f=>f.width?+f.width:m)};return c.push({id:_.SetWorksheetColWidthMutation.id,params:g}),{redos:c,undos:[]}},onPastePlainText(o,r,s){return i._onPastePlainText(o,r,s)},onPasteCells(o,r,s,a){return i._onPasteCells(o,r,s,a)},onAfterPaste(o){n=null}}}_generateDocumentDataModelSnapshot(i){var s;const t=this._sheetSkeletonManagerService.getCurrent();if(t==null)return null;const{skeleton:e}=t,n=(s=e.getBlankCellDocumentModel())==null?void 0:s.documentModel,r={...n==null?void 0:n.getSnapshot(),...i};return n==null||n.reset(r),n==null?void 0:n.getSnapshot()}_onPastePlainText(i,t,e){const{range:n,unitId:o,subUnitId:r}=i;let s;if(/\r|\n/.test(t)){const c=Jo(t),d=this._generateDocumentDataModelSnapshot({body:c});s={[n.startRow]:{[n.startColumn]:{p:d}}}}else s={[n.startRow]:{[n.startColumn]:{v:t}}};const a={unitId:o,subUnitId:r,cellValue:s};return{redos:[{id:_.SetRangeValuesMutation.id,params:a}],undos:[{id:_.SetRangeValuesMutation.id,params:_.SetRangeValuesUndoMutationFactory(this._injector,a)}]}}_onPasteCells(i,t,e,n){const o={get:this._injector.get.bind(this._injector)};return Vs(i,t,e,n,o)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},t=this,e={id:_e.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,a,c,d)=>{const u=t._currentUniverSheet.getCurrentUniverSheetInstance();return u.getUnitId(),u.getActiveSheet().getSheetId(),Go(a,c,i)}},n={id:_e.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,a,c,d){const u=t._currentUniverSheet.getCurrentUniverSheetInstance();u.getUnitId(),u.getActiveSheet().getSheetId();const h=[],m=[],{undos:g,redos:S}=qo(a,c,i);h.push(...S),m.push(...g);const{undos:f,redos:C}=Ci(a,c,i);h.push(...C),m.push(...f);const{undos:R,redos:M}=Ko(a,c,i);return h.push(...M),m.push(...R),{undos:m,redos:h}}},o={id:_e.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,a,c){var E;const d=t._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],g=t._getWorksheet(u,h),{range:S}=s,f=g.getMaxColumns(),C=S.endColumn-f,R=a.length-C,M=(E=t._configService.getConfig(l.DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY))!=null?E:l.DEFAULT_WORKSHEET_COLUMN_WIDTH,w={unitId:u,subUnitId:h,ranges:[{...S,endRow:Math.min(S.endColumn,f)}],colWidth:a.slice(0,R).map(T=>T.width?+T.width:M)};return m.push({id:_.SetWorksheetColWidthMutation.id,params:w}),m.push({id:_.SetWorksheetColWidthMutation.id,params:w}),{redos:m,undos:[]}}},r={id:_e.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,a,c,d){t._currentUniverSheet.getCurrentUniverSheetInstance();const u=[],h=[],{range:m,unitId:g,subUnitId:S}=a,{startColumn:f,startRow:C,endColumn:R,endRow:M}=m,w=new l.ObjectMatrix;c.forValue((x,A,k)=>{const L=k.s;typeof L=="object"&&w.setValue(x+C,A+f,{s:{...L,bd:void 0},v:k.v})});const E={unitId:g,subUnitId:S,cellValue:w.getData()};u.push({id:_.SetRangeValuesMutation.id,params:E});const T=_.SetRangeValuesUndoMutationFactory(i,E);h.push({id:_.SetRangeValuesMutation.id,params:T});const{undos:O,redos:y}=Ci(a,c,i);return h.push(...O),u.push(...y),{redos:u,undos:h}}};return[e,n,o,r]}_getWorksheet(i,t){var n;const e=(n=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:n.getSheetBySheetId(t);if(!e)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${t}.`);return e}};Sn=bc([l.OnLifecycle(l.LifecycleStages.Steady,Sn),Oe(0,N.Inject(N.Injector)),Oe(1,l.IUniverInstanceService),Oe(2,l.ICommandService),Oe(3,l.IContextService),Oe(4,l.IConfigService),Oe(5,Rt),Oe(6,v.IClipboardInterfaceService),Oe(7,v.IMessageService),Oe(8,N.Inject(exports.SheetSkeletonManagerService)),Oe(9,N.Inject(l.LocaleService)),Oe(10,N.Optional(b.ITextSelectionRenderManager))],Sn);var wc=Object.defineProperty,Tc=Object.getOwnPropertyDescriptor,Ec=(i,t,e,n)=>{for(var o=n>1?void 0:n?Tc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&wc(t,e,o),o},kt=(i,t)=>(e,n)=>t(e,n,i);let _n=class extends l.Disposable{constructor(i,t,e,n,o){super(),this._currentUniverService=i,this._contextMenuService=t,this._renderManagerService=e,this._selectionManagerService=n,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 t=i.spreadsheet.onPointerDownObserver,e=t.add(a=>{if(a.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=a.offsetX,f=a.offsetY;switch(u){case l.RANGE_TYPE.ROW:return h.startY<=f&&h.endY>=f;case l.RANGE_TYPE.COLUMN:return h.startX<=S&&h.endX>=S;default:return h.startX<=S&&h.endX>=S&&h.startY<=f&&h.endY>=f}},g=S=>{this._contextMenuService.triggerContextMenu(a,S)};m()?u===l.RANGE_TYPE.COLUMN?g(ce.COL_HEADER_CONTEXT_MENU):u===l.RANGE_TYPE.ROW?g(ce.ROW_HEADER_CONTEXT_MENU):g(v.MenuPosition.CONTEXT_MENU):g(v.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(l.toDisposable(()=>t.remove(e)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,ce.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>t.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,ce.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>t.remove(s)))}};_n=Ec([l.OnLifecycle(l.LifecycleStages.Rendered,_n),kt(0,l.IUniverInstanceService),kt(1,v.IContextMenuService),kt(2,b.IRenderManagerService),kt(3,N.Inject(_.SelectionManagerService)),kt(4,fe)],_n);var Oc=Object.defineProperty,yc=Object.getOwnPropertyDescriptor,xc=(i,t,e,n)=>{for(var o=n>1?void 0:n?yc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Oc(t,e,o),o},li=(i,t)=>(e,n)=>t(e,n,i);let fn=class extends l.RxDisposable{constructor(i,t,e){super(),this._currentUniverService=i,this._renderManagerService=t,this._undoRedoService=e,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(H.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(t=>{const e=t.getConfig();i[t.getSheetId()]={cellData:new l.ObjectMatrix(e.cellData),rowCount:e.rowCount,columnCount:e.columnCount}})}_commandExecutedListener(){}_getDocObject(){return J.getDocObject(this._currentUniverService,this._renderManagerService)}};fn=xc([l.OnLifecycle(l.LifecycleStages.Steady,fn),li(0,l.IUniverInstanceService),li(1,b.IRenderManagerService),li(2,N.Inject(l.IUndoRedoService))],fn);const Br=[v.KeyCode.ARROW_DOWN,v.KeyCode.ARROW_UP,v.KeyCode.ARROW_LEFT,v.KeyCode.ARROW_RIGHT],Ac=[v.KeyCode.ENTER,v.KeyCode.TAB,...Br];function Nc(){const i=[];for(const t of Br)i.push({id:Gt.id,binding:t,preconditions:e=>Vn(e),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:t,isShift:!1}}),i.push({id:Gt.id,binding:t|v.MetaKeys.SHIFT,preconditions:e=>Vn(e),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:t,isShift:!0}});return i}const Dc={id:Pe.id,binding:v.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>Vn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:v.KeyCode.ENTER}},Hc={id:Pe.id,binding:v.KeyCode.TAB,preconditions:i=>Vn(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:v.KeyCode.TAB}},Lc={id:Pe.id,binding:v.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>Xo(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:v.KeyCode.ESC}},Pc={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>Xo(i),binding:v.KeyCode.ENTER|v.MetaKeys.ALT},Uc={id:J.DeleteLeftCommand.id,preconditions:i=>Cs(i)||Zo(i),binding:v.KeyCode.BACKSPACE},kc={id:Pe.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>te(i)&&!Zo(i),binding:v.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:v.KeyCode.BACKSPACE}};var Vc=Object.defineProperty,Bc=Object.getOwnPropertyDescriptor,Fc=(i,t,e,n)=>{for(var o=n>1?void 0:n?Bc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Vc(t,e,o),o},Ne=(i,t)=>(e,n)=>t(e,n,i);function Wc(i){const{textRuns:t=[],paragraphs:e=[]}=i;return t.some(n=>n.ts&&!l.Tools.isEmptyObject(n.ts))||e.some(n=>n.bullet)||e.length>=2}let pn=class extends l.Disposable{constructor(t,e,n,o,r,s,a,c,d,u){super();I(this,"_cursorChangeObservers");I(this,"_editorVisiblePrevious",!1);I(this,"_isCursorChange",0);this._currentUniverService=t,this._renderManagerService=e,this._commandService=n,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=a,this._undoRedoService=c,this._selectionManagerService=d,this._editorService=u,this._initialize(),this._commandExecutedListener()}dispose(){const t=this._getEditorObject();if(t==null)return;const{document:e}=t;e.onPointerDownObserver.remove(this._cursorChangeObservers),super.dispose()}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(t=>{const{visible:e,keycode:n,eventType:o}=t;if(e===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=e,e===!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:a,sheetId:c,pluginName:d}=s;if(this._exitInput(t),n===v.KeyCode.ESC){this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,{unitId:a,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getEditCellState();if(u==null)return;const{unitId:h,sheetId:m,row:g,column:S,documentLayoutObject:f}=u;if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(n);return}const R=this._currentUniverService.getUniverSheetInstance(h),M=R==null?void 0:R.getSheetBySheetId(m);if(M==null)return;const w=jc(M.getCellRaw(g,S)||{},f,this._lexerTreeBuilder);if(w==null){this._moveCursor(n);return}const E={subUnitId:m,unitId:h,workbook:R,worksheet:M,row:g,col:S},T=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(w,E);this._commandService.executeCommand(_.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:g,startColumn:S,endRow:g,endColumn:S},value:T}),this._moveCursor(n),a===h&&m!==c&&this._editorBridgeService.isForceKeepVisible()&&this._commandService.executeCommand(_.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h}),this._selectionManagerService.refreshSelection()}))}_exitInput(t){this._contextService.setContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(l.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:t.visible});const e=this._editorBridgeService.getCurrentEditorId();e==null||!this._editorService.isSheetEditor(e)||(this._undoRedoService.clearUndoRedo(e),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(t){if(t==null||!Ac.includes(t))return;let e=l.Direction.LEFT;switch(t){case v.KeyCode.ENTER:e=l.Direction.DOWN;break;case v.KeyCode.TAB:e=l.Direction.RIGHT;break;case v.KeyCode.ARROW_DOWN:e=l.Direction.DOWN;break;case v.KeyCode.ARROW_UP:e=l.Direction.UP;break;case v.KeyCode.ARROW_LEFT:e=l.Direction.LEFT;break;case v.KeyCode.ARROW_RIGHT:e=l.Direction.RIGHT;break}t===v.KeyCode.ENTER||t===v.KeyCode.TAB?this._commandService.executeCommand(dt.id,{keycode:t,direction:e}):this._commandService.executeCommand(Te.id,{direction:e})}_cursorStateListener(){const t=this._getEditorObject();if(t==null)return;const{document:e}=t;this.disposeWithMe(l.toDisposable(e.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})))}_commandExecutedListener(){const t=[Gt.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{keycode:o,isShift:r}=n;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(n)}}))}_moveInEditor(t,e){let n=l.Direction.LEFT;t===v.KeyCode.ARROW_DOWN?n=l.Direction.DOWN:t===v.KeyCode.ARROW_UP?n=l.Direction.UP:t===v.KeyCode.ARROW_RIGHT&&(n=l.Direction.RIGHT),e?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:n})}_getEditorObject(){return zn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};pn=Fc([l.OnLifecycle(l.LifecycleStages.Steady,pn),Ne(0,l.IUniverInstanceService),Ne(1,b.IRenderManagerService),Ne(2,l.ICommandService),Ne(3,Ee),Ne(4,l.IContextService),Ne(5,tn),Ne(6,N.Inject(ee.LexerTreeBuilder)),Ne(7,l.IUndoRedoService),Ne(8,N.Inject(_.SelectionManagerService)),Ne(9,v.IEditorService)],pn);function jc(i,t,e){i=l.Tools.deepClone(i);const{documentModel:n}=t;if(n==null)return null;const o=n.getSnapshot(),{body:r}=o;if(r==null)return null;const s=r.dataStream;let c=s.substring(s.length-2,s.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?s.substring(0,s.length-2):s;if(l.isFormulaString(c)){if(i.f===c)return null;const d=e.checkIfAddBracket(c);for(let u=0;u<d;u++)c+=ee.matchToken.CLOSE_BRACKET;i.f=c,i.v=null,i.p=null}else if(Wc(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 $c=Object.defineProperty,zc=Object.getOwnPropertyDescriptor,Yc=(i,t,e,n)=>{for(var o=n>1?void 0:n?zc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&$c(t,e,o),o},De=(i,t)=>(e,n)=>t(e,n,i);let Cn=class extends l.RxDisposable{constructor(t,e,n,o,r,s,a,c,d,u){super();I(this,"_loadedMap",new WeakSet);this._univerInstanceService=t,this._renderManagerService=e,this._editorBridgeService=n,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=a,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(H.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._create(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._textSelectionManagerService.textSelection$.pipe(H.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{unitId:e}=t;e!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_create(t){if(t!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const e=this._renderManagerService.getRenderById(t);if(e==null)return;const{mainComponent:n}=e;n!=null&&(this._loadedMap.has(n)||(this._initialMain(t),this._loadedMap.add(n)))}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(H.takeUntil(this.dispose$)).subscribe(()=>{var e;if(this._contextService.getContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(l.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0);const n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown});const r=(e=n==null?void 0:n.getBody())==null?void 0:e.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const a=[{startOffset:s.length,endOffset:s.length}],c={unitId:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(J.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(a)}})}_listenFoldBtnClick(){this._formulaEditorManagerService.foldBtnStatus$.pipe(H.takeUntil(this.dispose$)).subscribe(()=>{this._textSelectionManagerService.refreshSelection()})}_initialMain(t){const e=this._renderManagerService.getRenderById(t);if(e==null)return;const{mainComponent:n}=e;n!=null&&this.disposeWithMe(l.toDisposable(n.onPointerDownObserver.add(()=>{this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(l.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(H.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const e=zn(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||n==null)return;const{width:o,height:r}=t,{engine:s}=e;n.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.currentEditCellState$.pipe(H.takeUntil(this.dispose$)).subscribe(t=>{t==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(t)}),this._editorBridgeService.visible$.pipe(H.takeUntil(this.dispose$)).subscribe(t=>{if(t==null||t.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const e=this._editorBridgeService.getLatestEditCellState();e!=null&&this._editorSyncHandler(e)})}_editorSyncHandler(t){var s;const e=(s=t.documentLayoutObject.documentModel)==null?void 0:s.getBody();let n=e==null?void 0:e.dataStream,o=e==null?void 0:e.paragraphs,r=[];n==null||o==null||(t.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===b.DeviceInputEventType.Dblclick?(n=`\r
20
+ `,o=[{startIndex:0}]):t.isInArrayFormulaRange===!0&&(r=(e==null?void 0:e.textRuns)||[]),this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,n,o,r),this._autoScroll())}_commandExecutedListener(){const t=[J.RichTextEditingMutation.id,v.SetEditorResizeOperation.id],e=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s;if(t.includes(o.id)){const a=o.params,{unitId:c}=a;if(e.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===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(u==null||h==null)return;this._syncContentAndRender(m,u,h),this._autoScroll()}}}));const n=[_.SetRangeValuesMutation.id,_.MoveRangeMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s,a,c,d;if(n.includes(o.id)){const u=this._editorBridgeService.getLatestEditCellState();if(u==null)return;let h=!1;const{row:m,column:g}=u;if(o.id===_.SetRangeValuesMutation.id&&o.params?(s=(r=o.params.cellValue)==null?void 0:r[m])!=null&&s[g]&&(h=!0):o.id===_.MoveRangeMutation.id&&o.params&&(c=(a=o.params.to.value)==null?void 0:a[m])!=null&&c[g]&&(h=!0),h){const S=(d=u.documentLayoutObject.documentModel)==null?void 0:d.getBody();if(S==null)return;const{dataStream:f,paragraphs:C=[]}=S;this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,f,C),this._autoScroll()}}}))}_syncContentAndRender(t,e,n,o=[]){var h;const r=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(t),a=this._univerInstanceService.getUniverDocInstance(t),c=this._docViewModelManagerService.getViewModel(t);if(a==null||c==null||s==null)return;a.getBody().dataStream=e,a.getBody().paragraphs=this._clearParagraph(n),t===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(a.getBody().textRuns=[]),o.length>0&&(a.getBody().textRuns=o),c.reset(a);const{skeleton:d}=s,u=this._renderManagerService.getRenderById(t);u!=null&&(d.calculate(),r.includes(t)&&((h=u.mainComponent)==null||h.makeDirty()))}_clearParagraph(t){const e=l.Tools.deepClone(t);for(const n of e)n.paragraphStyle&&(n.paragraphStyle.horizontalAlign=l.HorizontalAlign.UNSPECIFIED);return e}_autoScroll(){var S,f;const t=(S=this._docSkeletonManagerService.getSkeletonByUnitId(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:S.skeleton,e=this._formulaEditorManagerService.getPosition(),n=this._renderManagerService.getRenderById(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||e==null||n==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:a,mainComponent:c}=n;let{actualHeight:d}=t.getActualSize();d+=r+s;const{width:u,height:h}=e,m=a.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);let g=m==null?void 0:m.getScrollBar();a.transformByState({width:u,height:d}),c==null||c.resize(u,d),d>h?g==null?m&&new b.ScrollBar(m,{enableHorizontal:!1,barSize:8}):m==null||m.resetSizeAndScrollBar():(g=null,m==null||m.scrollTo({x:0,y:0}),(f=m==null?void 0:m.getScrollBar())==null||f.dispose())}};Cn=Yc([l.OnLifecycle(l.LifecycleStages.Steady,Cn),De(0,l.IUniverInstanceService),De(1,b.IRenderManagerService),De(2,Ee),De(3,N.Inject(J.DocSkeletonManagerService)),De(4,N.Inject(J.DocViewModelManagerService)),De(5,l.ICommandService),De(6,l.IContextService),De(7,Gn),De(8,l.IUndoRedoService),De(9,N.Inject(J.TextSelectionManagerService))],Cn);const Xc="36",Zc="univer-sheet-container",Fr={sheetFooterBarHeight:Xc,sheetContainer:Zc};var Gc=Object.defineProperty,Kc=Object.getOwnPropertyDescriptor,qc=(i,t,e,n)=>{for(var o=n>1?void 0:n?Kc(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Gc(t,e,o),o},Re=(i,t)=>(e,n)=>t(e,n,i);const To=-1e3,Eo=5,Jc=2;let vn=class extends l.Disposable{constructor(t,e,n,o,r,s,a,c,d,u,h,m){super();I(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=t,this._docViewModelManagerService=e,this._contextService=n,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=a,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._editorService=m,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const t=this._getEditorObject();t!=null&&this.disposeWithMe(l.toDisposable(t.document.onPointerDownObserver.add(()=>{var e;if(this._editorBridgeService.isVisible()){const n=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(n==null||o==null||!this._editorService.isSheetEditor(o))return;const r=(e=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:e.skeleton;if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u}=n;this._fitTextSize(s,c,r,a,d,u)}})))}_initialCursorSync(){this.disposeWithMe(this._cellEditorManagerService.focus$.subscribe(()=>{this._textSelectionRenderManager.sync()}))}_initialEditFocusListener(){this.disposeWithMe(this._editorBridgeService.currentEditCellState$.subscribe(t=>{if(t==null||this._editorBridgeService.isForceKeepVisible())return;const{position:e,documentLayoutObject:n,scaleX:o,editorUnitId:r}=t;if(this._getEditorObject()==null)return;const{startX:a,endX:c}=e,{textRotation:d,wrapStrategy:u,documentModel:h}=n,{a:m}=d;h.updateDocumentId(r),u===l.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-a)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(To,To)}))}_fitTextSize(t,e,n,o,r=1,s=1){const{startX:a,startY:c,endX:d,endY:u}=t,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:g}=this._predictingSize(t,e,n,o,r,s),{verticalAlign:S,paddingData:f,fill:C}=o;let R=d-a,M=u-c;if(R<m&&(R=m),M<g)M=g,h.updateDocumentDataMargin(f);else{let w=M-g||0;S===l.VerticalAlign.MIDDLE?w=(M-g)/2:S===l.VerticalAlign.TOP&&(w=f.t||0),w/=s,w=w<(f.t||0)?f.t||0:w,h.updateDocumentDataMargin({t:w})}n.calculate(),this._editAreaProcessing(R,M,t,e,C,r,s)}_predictingSize(t,e,n,o,r=1,s=1){const{startX:a,endX:c}=t,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,g=document.body.clientWidth;if(u===l.WrapStrategy.WRAP&&m===0){const{actualWidth:C,actualHeight:R}=n.getActualSize();return{actualWidth:C*r,actualHeight:R*s}}h==null||h.updateDocumentDataPageSize((g-a-e.left)/r),n.calculate();const S=n.getActualSize();let f=c-a;return f<S.actualWidth*r+Eo*r&&(f=S.actualWidth*r+Eo*r),h==null||h.updateDocumentDataPageSize(f/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:l.HorizontalAlign.UNSPECIFIED}),{actualWidth:f,actualHeight:S.actualHeight*s}}_editAreaProcessing(t,e,n,o,r,s=1,a=1){var T;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=n;const{document:h,scene:m,engine:g}=c,S=m.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),f=document.body.clientHeight-u-Number.parseFloat(Fr.sheetFooterBarHeight)-o.top-Jc*2,C=document.body.clientWidth-d-o.left;let R=e,M=S==null?void 0:S.getScrollBar();R>f?(R=f,M==null?S&&new b.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetSizeAndScrollBar()):(M=null,(T=S==null?void 0:S.getScrollBar())==null||T.dispose()),t+=(M==null?void 0:M.barSize)||0,t>C&&(t=C),d-=b.FIX_ONE_PIXEL_BLUR_OFFSET,u-=b.FIX_ONE_PIXEL_BLUR_OFFSET,this._addBackground(m,t/s,e/a,r);const{scaleX:w,scaleY:E}=m.getPrecisionScale();m.transformByState({width:t/s,height:e/a,scaleX:s,scaleY:a}),h.resize(t/s,e/a),requestIdleCallback(()=>{g.resizeBySize(b.fixLineWidthByScale(t,w),b.fixLineWidthByScale(R,E))}),this._cellEditorManagerService.setState({startX:d,startY:u,endX:t+d,endY:R+u,show:!0})}_addBackground(t,e,n,o){const r="_backgroundRectHelperColor_",s=t.getObject(r);s==null&&o==null||(s==null?t.addObjects([new b.Rect(r,{width:e,height:n,fill:o,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:e,height:n})))}_initialStartEdit(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(t=>{var E,T;const{visible:e,eventType:n,keycode:o}=t;if(e===this._editorVisiblePrevious||(this._editorVisiblePrevious=e,e===!1))return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:g=!1}=r,S=this._getEditorObject();if(S==null)return;const{document:f,scene:C}=S;this._contextService.setContextValue(l.EDITOR_ACTIVATED,!0);const{documentModel:R}=a,M=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(M==null||R==null)return;const{skeleton:w}=M;if(this._fitTextSize(s,c,w,a,d,u),n===b.DeviceInputEventType.Keyboard||n===b.DeviceInputEventType.Dblclick&&g){const O=l.Tools.deepClone(R.snapshot),y=this._docViewModelManagerService.getViewModel(h);if(y==null)return;this._resetBodyStyle(O.body),R.reset(O),y.reset(R),f.makeDirty(),(o===v.KeyCode.BACKSPACE||n===b.DeviceInputEventType.Dblclick)&&(w.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(n===b.DeviceInputEventType.Dblclick){const O=R.getBody().dataStream.length-2||0;(E=C.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||E.scrollTo({y:Number.POSITIVE_INFINITY}),this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O}])}(T=this._renderManagerService.getRenderById(m))==null||T.scene.resetCursor()}))}_resetBodyStyle(t){t.dataStream=l.DEFAULT_EMPTY_DOCUMENT_VALUE,t.textRuns!=null&&(t.textRuns.length===1?(t.textRuns[0].st=0,t.textRuns[0].ed=1):t.textRuns=void 0),t.paragraphs!=null&&(t.paragraphs.length===1?t.paragraphs[0].startIndex=0:t.paragraphs=[{startIndex:0}]),t.sectionBreaks!=null&&(t.sectionBreaks=void 0),t.tables!=null&&(t.tables=void 0),t.customRanges!=null&&(t.customRanges=void 0),t.customBlocks!=null&&(t.customBlocks=void 0)}_initialKeyboardListener(){this.disposeWithMe(this._textSelectionRenderManager.onInputBefore$.subscribe(t=>{const e=this._contextService.getContextValue(l.FOCUSING_FORMULA_EDITOR),n=this._contextService.getContextValue(l.FOCUSING_SHEET),o=this._currentUniverService.getCurrentUniverDocInstance().getUnitId();n&&!e&&this._editorService.isSheetEditor(o)&&this._showEditorByKeyboard(t)}))}_showEditorByKeyboard(t){if(t==null)return;const e=t.event;this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:e.which})}_commandExecutedListener(){const t=[J.RichTextEditingMutation.id,v.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const o=e.params,{unitId:r}=o;if(!this._editorService.isSheetEditor(r))return;const s=this._editorBridgeService.getCurrentEditorId();if(s==null)return;this._editorBridgeService.changeEditorDirty(!0);const a=(n=this._docSkeletonManagerService.getSkeletonByUnitId(s))==null?void 0:n.skeleton;if(a==null)return;const c=this._editorBridgeService.getEditCellState();if(c==null)return;const{position:d,documentLayoutObject:u,canvasOffset:h,scaleX:m,scaleY:g}=c;this._fitTextSize(d,h,a,u,m,g)}}))}_getEditorObject(){return zn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};vn=qc([l.OnLifecycle(l.LifecycleStages.Steady,vn),Re(0,N.Inject(J.DocSkeletonManagerService)),Re(1,N.Inject(J.DocViewModelManagerService)),Re(2,l.IContextService),Re(3,l.IUniverInstanceService),Re(4,b.IRenderManagerService),Re(5,Ee),Re(6,tn),Re(7,b.ITextSelectionRenderManager),Re(8,N.Inject(J.TextSelectionManagerService)),Re(9,l.ICommandService),Re(10,N.Inject(l.LocaleService)),Re(11,v.IEditorService)],vn);const Kn={id:"sheet.command.change-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{delta:e,reset:n}=t,o=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();let c=n?100:Math.round((r.getConfig().zoomRatio+e)*100);c=Math.max(pi[0],c),c=Math.min(pi[1],c);const d=c/100;return i.get(l.ICommandService).executeCommand(Ye.id,{unitId:s,subUnitId:a,zoomRatio:d})}},qn={id:"sheet.command.set-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{unitId:e,subUnitId:n,zoomRatio:o}=t;return i.get(l.ICommandService).executeCommand(Ye.id,{unitId:e,subUnitId:n,zoomRatio:o})}},Wr={id:"sheet.operation.set-activate-cell-edit",type:l.CommandType.OPERATION,handler:(i,t)=>(i.get(Ee).setEditCell(t),!0)};var Qc=Object.defineProperty,ed=Object.getOwnPropertyDescriptor,td=(i,t,e,n)=>{for(var o=n>1?void 0:n?ed(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Qc(t,e,o),o},He=(i,t)=>(e,n)=>t(e,n,i);let In=class extends l.RxDisposable{constructor(i,t,e,n,o,r,s,a,c,d){super(),this._injector=i,this._sheetSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=o,this._editorBridgeService=r,this._layoutService=s,this._editorService=a,this._contextService=c,this._selectionManagerService=d,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener(),this._initialChangeEditorListener()}_initSelectionChangeListener(){H.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(H.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){const t=this._selectionManagerService.getCurrent();if((t==null?void 0:t.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const e=this._injector.get(b.ITextSelectionRenderManager,N.Quantity.OPTIONAL);if(!this._layoutService.checkCanvasIsFocused()&&e&&!e.hasFocus())return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null||i==null||i.length===0||i[i.length-1]==null)return;const{primary:o}=i[i.length-1];if(o==null)return;const r=this._getSheetObject();if(r==null)return;const{unitId:s,sheetId:a}=n,{scene:c,engine:d}=r;this._commandService.executeCommand(Wr.id,{scene:c,engine:d,primary:o,unitId:s,sheetId:a})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:t,spreadsheetColumnHeader:e,spreadsheetLeftTopPlaceholder:n,spreadsheetRowHeader:o}=i;t.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(Pe.id,{visible:!0,eventType:b.DeviceInputEventType.Dblclick})}),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),o.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this))}_initialChangeEditorListener(){this.disposeWithMe(this._currentUniverService.currentDoc$.subscribe(i=>{if(i==null)return;const t=i.getUnitId();this._editorService.isEditor(t)&&(this._editorService.isSheetEditor(t)?(this._contextService.setContextValue(l.FOCUSING_DOC,!1),this._contextService.setContextValue(l.FOCUSING_SHEET,!0)):(this._contextService.setContextValue(l.FOCUSING_SHEET,!1),this._contextService.setContextValue(l.FOCUSING_DOC,!0),this._hideEditor()))}))}_keepVisibleHideEditor(){this._editorBridgeService.isForceKeepVisible()||(this._editorService.changeEditorFocus(),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=_.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((t,e)=>{e!=null&&e.fromCollab||(t.id===_.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(t.id)&&this._hideEditor())})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{t.id===qn.id&&this._editorBridgeService.refreshEditCellState()}))}};In=td([l.OnLifecycle(l.LifecycleStages.Rendered,In),He(0,N.Inject(N.Injector)),He(1,N.Inject(exports.SheetSkeletonManagerService)),He(2,l.IUniverInstanceService),He(3,l.ICommandService),He(4,b.IRenderManagerService),He(5,Ee),He(6,v.ILayoutService),He(7,v.IEditorService),He(8,l.IContextService),He(9,N.Inject(_.SelectionManagerService))],In);var nd=Object.defineProperty,id=Object.getOwnPropertyDescriptor,od=(i,t,e,n)=>{for(var o=n>1?void 0:n?id(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&nd(t,e,o),o},Vt=(i,t)=>(e,n)=>t(e,n,i);let Rn=class extends l.Disposable{constructor(i,t,e,n,o){super(),this._commandService=i,this._formatPainterService=t,this._currentUniverService=e,this._renderManagerService=n,this._selectionRenderService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:t}=this._getSheetObject()||{};t&&(i!==ye.OFF?t.setDefaultCursor(b.CURSOR_TYPE.CELL):t.setDefaultCursor(b.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(l.toDisposable(this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{if(this._formatPainterService.getStatus()!==ye.OFF){const{rangeWithCoord:t}=i[i.length-1];this._applyFormatPainter({startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}),this._formatPainterService.getStatus()===ye.ONCE&&this._commandService.executeCommand(Bi.id)}})))}async _applyFormatPainter(i){const{styles:t,merges:e}=this._formatPainterService.getSelectionFormat(),n=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!t)return;const{startRow:r,startColumn:s,endRow:a,endColumn:c}=t.getDataRange(),d=a-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((C,R)=>{const M=f%d+r,w=R%u+s,E=t.getValue(M,w);E&&(h[f][R].s=E)})}),e.forEach(S=>{const f={startRow:S.startRow-r,startColumn:S.startColumn-s,endRow:S.endRow-r,endColumn:S.endColumn-s},C=Math.max(1,Math.floor((i.endRow-i.startRow+1)/d)),R=Math.max(1,Math.floor((i.endColumn-i.startColumn+1)/u));for(let M=0;M<C;M++)for(let w=0;w<R;w++)m.push({startRow:f.startRow+M*d+i.startRow,startColumn:f.startColumn+w*u+i.startColumn,endRow:f.endRow+M*d+i.startRow,endColumn:f.endColumn+w*u+i.startColumn})});const g={subUnitId:o,unitId:n,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(Ar.id,g)}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Rn=od([l.OnLifecycle(l.LifecycleStages.Rendered,Rn),Vt(0,l.ICommandService),Vt(1,wt),Vt(2,l.IUniverInstanceService),Vt(3,b.IRenderManagerService),Vt(4,fe)],Rn);const Mn={id:"sheet.command.set-scroll-relative",type:l.CommandType.COMMAND,handler:async(i,t={offsetX:0,offsetY:0})=>{const e=i.get(l.ICommandService),n=i.get(Qe),r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:a,ySplit:c}=s.getConfig().freeze,d=n.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=t||{},{sheetViewStartRow:m=0,sheetViewStartColumn:g=0,offsetX:S=0,offsetY:f=0}=d||{};return e.executeCommand(bt.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:g+a,offsetX:S+u,offsetY:f+h})}},ft={id:"sheet.command.scroll-view",type:l.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet(),s=i.get(Qe).getCurrentScroll();if(!o)return!1;const a=i.get(l.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=t,{sheetViewStartColumn:m,sheetViewStartRow:g,offsetX:S,offsetY:f}=s||{},{xSplit:C,ySplit:R}=o.getConfig().freeze;return a.executeCommand(bt.id,{unitId:n.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c!=null?c:(g!=null?g:0)+R,sheetViewStartColumn:d!=null?d:(m!=null?m:0)+C,offsetX:u!=null?u:S,offsetY:h!=null?h:f})}};l.CommandType.COMMAND;var rd=Object.defineProperty,sd=Object.getOwnPropertyDescriptor,ad=(i,t,e,n)=>{for(var o=n>1?void 0:n?sd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&rd(t,e,o),o},Le=(i,t)=>(e,n)=>t(e,n,i);const ld="__SpreadsheetFreezeRowMainName__",cd="__SpreadsheetFreezeRowHeaderName__",dd="__SpreadsheetFreezeColumnMainName__",ud="__SpreadsheetFreezeColumnHeaderName__",ci=4,hd=.01;let bn=class extends l.Disposable{constructor(t,e,n,o,r,s,a,c,d,u){super();I(this,"_rowFreezeHeaderRect");I(this,"_rowFreezeMainRect");I(this,"_columnFreezeHeaderRect");I(this,"_columnFreezeMainRect");I(this,"_freezeDownObservers",[]);I(this,"_freezeMoveObservers",[]);I(this,"_freezeLeaveObservers",[]);I(this,"_moveObserver");I(this,"_upObserver");I(this,"_changeToRow",-1);I(this,"_changeToColumn",-1);I(this,"_changeToOffsetX",0);I(this,"_changeToOffsetY",0);I(this,"_activeViewport",null);I(this,"_freezeNormalHeaderColor","");I(this,"_freezeNormalMainColor","");I(this,"_freezeActiveColor","");I(this,"_freezeHoverColor","");I(this,"_lastFreeze");this._sheetSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=a,this._themeService=c,this._sheetInterceptorService=d,this._injector=u,this._initialize()}dispose(){super.dispose(),this._clearFreeze()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(t=0,e){var y;const n=e!=null?e:this._getFreeze();if(n==null)return;const o=(y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:y.skeleton;if(o==null)return;const{startRow:r,startColumn:s}=n,a=this._getPositionByIndex(r,s);if(a==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:g,startY:S}=a,{rowTotalHeight:f,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:R,columnHeaderHeightAndMarginTop:M}=o,w=u>C+R?u:C+M,E=h>f+M?h:f+M;this._changeToRow=r,this._changeToColumn=s,this._changeToOffsetX=g,this._changeToOffsetY=S;const T=Math.max(m.scaleX,m.scaleY),O=ci/(T<1?1:T);if(t===0){const x=O;this._rowFreezeHeaderRect=new b.Rect(cd,{fill:this._freezeNormalHeaderColor,width:R,height:O,left:0,top:S-x,zIndex:3});let A=this._freezeNormalHeaderColor;(r===-1||r===0)&&(A=this._freezeNormalMainColor),this._rowFreezeMainRect=new b.Rect(ld,{fill:A,width:w*2,height:O,left:R,top:S-x,zIndex:3}),m.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],Je)}else{const x=O;this._columnFreezeHeaderRect=new b.Rect(ud,{fill:this._freezeNormalHeaderColor,width:O,height:M,left:g-x,top:0,zIndex:3});let A=this._freezeNormalHeaderColor;(s===-1||s===0)&&(A=this._freezeNormalMainColor),this._columnFreezeMainRect=new b.Rect(dd,{fill:A,width:O,height:E*2,left:g-x,top:M,zIndex:3}),m.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],Je)}this._eventBinding(t)}_eventBinding(t=0){let e=this._rowFreezeHeaderRect,n=this._rowFreezeMainRect;t===1&&(e=this._columnFreezeHeaderRect,n=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(e==null?void 0:e.onPointerEnterObserver.add(()=>{e==null||e.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{e==null||e.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(e==null?void 0:e.onPointerLeaveObserver.add(()=>{e==null||e.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{e==null||e.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(e==null?void 0:e.onPointerDownObserver.add(s=>{this._freezeDown(s,e,n,t)})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,e,n,t)}))}_getCurrentLastVisibleRow(){var h,m,g,S;const t=this._getSheetObject();if(t==null)return;const e=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(e==null)return;const n=t.scene,o=Math.max(n.scaleX,n.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(t.engine.height-e.columnHeaderHeight)/o,a=(m=r==null?void 0:r.sheetViewStartRow)!=null?m:0,c=a===0?-((g=r==null?void 0:r.offsetY)!=null?g:0):e.rowHeightAccumulation[a-1]-((S=r==null?void 0:r.offsetY)!=null?S:0);let d=0,u=!1;for(let f=a,C=e.rowHeightAccumulation.length;f<C;f++)if(e.rowHeightAccumulation[f]-c>s){d=f,u=!0;break}return u||(d=e.rowHeightAccumulation.length-1),d}_getActiveViewport(t){var n;const e=(n=this._getSheetObject())==null?void 0:n.scene.getViewports();return e&&e.find(o=>o.isHit(new b.Vector2(t.offsetX,t.offsetY)))||null}_freezeDown(t,e,n,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:a}=s;a.setCursor(b.CURSOR_TYPE.GRABBING),a.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=a.onPointerMoveObserver.add(m=>{var w,E,T,O;const g=this._getActiveViewport(m),{startX:S,startY:f,row:C,column:R}=It(m.offsetX,m.offsetY,a,r,g||void 0);a.setCursor(b.CURSOR_TYPE.GRABBING);const M=ci/Math.max(a.scaleX,a.scaleY);o===0?((w=e.transformByState({top:Math.min(f,d)-M/2}))==null||w.setProps({fill:this._freezeActiveColor}),(E=n.transformByState({top:Math.min(f,d)-M/2}))==null||E.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=c===void 0?C:Math.min(C,c),this._changeToOffsetY=Math.min(f,d),this._activeViewport=g):((T=e.transformByState({left:S-M/2}))==null||T.setProps({fill:this._freezeActiveColor}),(O=n.transformByState({left:S-M/2}))==null||O.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=R,this._changeToOffsetX=S,this._activeViewport=g)}),this._upObserver=a.onPointerUpObserver.add(()=>{var x,A;a.resetCursor(),a.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:g}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(e.setProps({fill:this._freezeNormalHeaderColor}),n.setProps({fill:this._freezeNormalMainColor})):(e==null||e.setProps({fill:this._freezeNormalHeaderColor}),n==null||n.setProps({fill:this._freezeNormalHeaderColor}));const S=ci/Math.max(a.scaleX,a.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(e.transformByState({top:g-S}),n.transformByState({top:g-S})):(this._changeToColumn===0||this._changeToColumn===-1)&&(e.transformByState({left:m-S}),n.transformByState({left:m-S}));const f=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:C,sheetViewStartColumn:R}=f;if(R==null||C==null)return;const M=this._currentUniverService.getCurrentUniverSheetInstance(),w=M.getActiveSheet(),E=(x=w.getConfig())==null?void 0:x.freeze;let T=(E==null?void 0:E.xSplit)||0,O=(E==null?void 0:E.ySplit)||0;const y=(A=this._activeViewport)==null?void 0:A.viewPortKey;o===0&&(!y||y===B.VIEW_LEFT_TOP||y===B.VIEW_MAIN_LEFT_TOP||y===B.VIEW_MAIN_TOP||y===B.VIEW_ROW_TOP?O=this._changeToRow-(E.startRow-E.ySplit):O=this._changeToRow-C,O=O<0?0:O),o===1&&(!y||y===B.VIEW_LEFT_TOP||y===B.VIEW_MAIN_LEFT_TOP||y===B.VIEW_MAIN_LEFT||y===B.VIEW_COLUMN_LEFT?T=this._changeToColumn-(E.startColumn-E.xSplit):T=this._changeToColumn-R,T=T<0?0:T),this._commandService.executeCommand(_.SetFrozenCommand.id,{startRow:O===0?-1:this._changeToRow,startColumn:T===0?-1:this._changeToColumn,ySplit:O,xSplit:T,unitId:M.getUnitId(),subUnitId:w.getSheetId()})})}_getViewports(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t,n=e.getViewport(B.VIEW_COLUMN_LEFT),o=e.getViewport(B.VIEW_COLUMN_RIGHT),r=e.getViewport(B.VIEW_ROW_TOP),s=e.getViewport(B.VIEW_ROW_BOTTOM),a=e.getViewport(B.VIEW_LEFT_TOP),c=e.getViewport(B.VIEW_MAIN),d=e.getViewport(B.VIEW_MAIN_LEFT_TOP),u=e.getViewport(B.VIEW_MAIN_LEFT),h=e.getViewport(B.VIEW_MAIN_TOP);if(!(n==null||o==null||r==null||s==null||a==null||c==null||d==null||u==null||h==null))return{viewMain:c,viewMainLeftTop:d,viewMainLeft:u,viewMainTop:h,viewColumnLeft:n,viewColumnRight:o,viewRowTop:r,viewRowBottom:s,viewLeftTop:a}}_bindViewportScroll(){const t=this._getViewports();if(!t)return;const{viewMain:e,viewRowBottom:n,viewColumnRight:o,viewMainLeft:r,viewMainTop:s}=t;this.disposeWithMe(e.onScrollAfterObserver.add(a=>{const{scrollX:c,scrollY:d,actualScrollX:u,actualScrollY:h}=a;n.isActive&&n.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(t=-1,e=-1,n=0,o=0,r=3){var y;const s=(y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:y.skeleton;if(s==null)return;const{rowHeaderWidthAndMarginLeft:a,columnHeaderHeightAndMarginTop:c}=s,d=this._getViewports();if(!d)return;const{viewMain:u,viewMainLeftTop:h,viewMainLeft:m,viewMainTop:g,viewColumnLeft:S,viewColumnRight:f,viewRowTop:C,viewRowBottom:R,viewLeftTop:M}=d;f.resize({left:a,top:0,height:c,right:0}),R.resize({left:0,top:c,bottom:0,width:a}),M.resize({left:0,top:0,width:a,height:c});let w=!0,E=!0;h.enable(),(t===-1||t===0)&&(w=!1),(e===-1||e===0)&&(E=!1);const T=s.getNoMergeCellPositionByIndexWithNoHeader(t-n,e-o),O=s.getNoMergeCellPositionByIndexWithNoHeader(t,e);if(h.disable(),g.disable(),m.disable(),C.disable(),S.disable(),h.resetPadding(),g.resetPadding(),m.resetPadding(),C.resetPadding(),S.resetPadding(),w===!1&&E===!1)u.resize({left:a,top:c,bottom:0,right:0}),u.resetPadding();else if(w===!0&&E===!1){const x=O.startY-T.startY;u.resize({left:a,top:c+x,bottom:0,right:0}),u.setPadding({startY:T.startY,endY:O.startY,startX:0,endX:0}),r&2&&this._commandService.executeCommand(ft.id,{sheetViewStartRow:0,offsetY:0}),g.resize({left:a,top:c,height:x,right:0}),g.updateScroll({actualScrollY:T.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),C.resize({left:0,top:c,width:a,height:x}),C.updateScroll({actualScrollY:T.startY}).makeDirty(!0),R.resize({left:0,top:c+x,bottom:0,width:a}),g.enable(),C.enable()}else if(w===!1&&E===!0){const x=O.startX-T.startX;u.resize({left:a+x,top:c,bottom:0,right:0}),u.setPadding({startX:T.startX,endX:O.startX,startY:0,endY:0}),r&1&&this._commandService.executeCommand(ft.id,{sheetViewStartColumn:0,offsetX:0}),m.resize({left:a,top:c,width:x,bottom:0,right:0}),m.updateScroll({actualScrollX:T.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),S.resize({left:a,top:0,width:x,height:c}),S.updateScroll({actualScrollX:T.startX}).makeDirty(!0),f.resize({left:a+x,top:0,height:c,right:0}),m.enable(),S.enable()}else{const x=O.startX-T.startX,A=O.startY-T.startY;u.resize({left:a+x,top:c+A,bottom:0,right:0}),u.setPadding({startY:T.startY,endY:O.startY,startX:T.startX,endX:O.startX}),r&&this._commandService.executeCommand(ft.id,{...r&1?{sheetViewStartColumn:0,offsetX:0}:null,...r&2?{sheetViewStartRow:0,offsetY:0}:null}),m.resize({left:a,top:c+A,width:x,bottom:0}),m.updateScroll({actualScrollX:T.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),g.resize({left:a+x,top:c,height:A,right:0}),g.updateScroll({actualScrollY:T.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),h.resize({left:a,top:c,width:x,height:A}),h.updateScroll({actualScrollX:T.startX,actualScrollY:T.startY}).makeDirty(!0),C.resize({left:0,top:c,width:a,height:A}),C.updateScroll({actualScrollY:T.startY}).makeDirty(!0),R.resize({left:0,top:c+A,bottom:0,width:a}),S.resize({left:a,top:0,width:x,height:c}),S.updateScroll({actualScrollX:T.startX}).makeDirty(!0),f.resize({left:a+x,top:0,height:c,right:0}),h.enable(),g.enable(),m.enable(),C.enable(),S.enable()}}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{[_.SetWorksheetActiveOperation.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id].includes((t==null?void 0:t.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:a=0}=n;this._refreshFreeze(o,r,s,a,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(l.toDisposable(this._themeService.currentTheme$.subscribe(t=>{this._clearFreeze(),this._themeChange(t),this._refreshCurrent()})))}_themeChange(t){this._freezeNormalHeaderColor=t.grey400,this._freezeNormalMainColor=new l.ColorKit(t.grey400).setAlpha(hd).toRgbString(),this._freezeActiveColor=t.primaryColor,this._freezeHoverColor=t.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{const e={redos:[],undos:[]},n=this._getFreeze();if(!n)return e;const o=r=>{const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getUnitId(),d=s.getActiveSheet().getSheetId();this._refreshFreeze(r.startRow,r.startColumn,r.ySplit,r.xSplit,0);const u={...r,unitId:a,subUnitId:d,resetScroll:!1},h=_.SetFrozenMutationFactory(this._injector,u);return{undos:[{id:_.SetFrozenMutation.id,params:h}],redos:[{id:_.SetFrozenMutation.id,params:u}]}};if(t.id===_.MoveColsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startColumn:s},toRange:{startColumn:a}}=t.params,c=r==null?void 0:r.filter(C=>C.range.rangeType===l.RANGE_TYPE.COLUMN&&C.range.startColumn<=s&&s<=C.range.endColumn);if(!(c!=null&&c.length))return e;const d=c[0].range,u={...d,startColumn:a,endColumn:a+d.endColumn-d.startColumn};if(!n||n.startColumn<=0||d.startColumn>=n.startColumn&&u.startColumn>=n.startColumn||d.startColumn===u.startColumn||d.endColumn<n.startColumn&&u.startColumn<n.startColumn)return e;const h=d.endColumn-d.startColumn+1,m=Math.max(Math.min(n.startColumn,d.endColumn+1)-d.startColumn,0);let g,S;u.startColumn>=n.startColumn?(g=Math.max(n.startColumn-m,1),S=Math.max(n.xSplit-m,1)):(g=n.startColumn+h-m,S=n.xSplit+h-m);const f={...n,startColumn:g,xSplit:S};return o(f)}if(t.id===_.MoveRowsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startRow:s},toRange:{startRow:a}}=t.params,c=r==null?void 0:r.filter(C=>C.range.rangeType===l.RANGE_TYPE.ROW&&C.range.startRow<=s&&s<=C.range.endRow);if(!(c!=null&&c.length))return e;const d=c[0].range,u={...d,startRow:a,endRow:a+d.endRow-d.startRow};if(!n||n.startRow<=0||d.startRow>=n.startRow&&u.startRow>=n.startRow||d.startRow===u.startRow||d.endRow<n.startRow&&u.startRow<n.startRow)return e;const h=d.endRow-d.startRow+1,m=Math.max(Math.min(n.startRow,d.endRow+1)-d.startRow,0);let g,S;u.startRow>=n.startRow?(g=Math.max(n.startRow-m,1),S=Math.max(n.ySplit-m,1)):(g=n.startRow+h-m,S=n.ySplit+h-m);const f={...n,startRow:g,ySplit:S};return o(f)}if(t.id===_.RemoveColCommand.id||t.id===_.RemoveRowCommand.id){const r=t.params,s=r.range;if(s.rangeType===l.RANGE_TYPE.COLUMN&&s.startColumn<n.startColumn){const a=Math.min(n.startColumn,s.endColumn+1)-s.startColumn,c={...n,startColumn:Math.max(1,n.startColumn-a),xSplit:Math.max(1,n.xSplit-a)};return o(c)}if(r.range.rangeType===l.RANGE_TYPE.ROW&&s.startRow<n.startRow){const a=Math.min(n.startRow,s.endRow+1)-s.startRow,c={...n,startRow:Math.max(1,n.startRow-a),ySplit:Math.max(1,n.ySplit-a)};return o(c)}}return e}}))}_commandExecutedListener(){const t=[_.SetFrozenMutation.id,Ye.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=this._lastFreeze,o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=e.params,{unitId:a,subUnitId:c}=s;if(!(a===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:g=0,xSplit:S=0}=d;(!n||n.startRow!==h||n.ySplit!==g)&&(u|=2),(!n||n.startColumn!==m||n.xSplit!==S)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,m,g,S,u)}else if(e.id===_.SetWorksheetRowHeightMutation.id){const n=this._getFreeze();e.params&&n&&e.params.ranges.some(o=>o.startRow<n.startRow)&&this._refreshCurrent()}else if(e.id===_.SetWorksheetColWidthMutation.id){const n=this._getFreeze();e.params&&n&&e.params.ranges.some(o=>o.startColumn<n.startColumn)&&this._refreshCurrent()}else if(e.id===_.SetWorksheetRowAutoHeightMutation.id){const n=e.params,o=this._getFreeze();if(o&&o.startRow>-1&&n.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}else if(e.id===_.SetColHiddenMutation.id||e.id===_.SetColVisibleMutation.id){const n=e.params,o=this._getFreeze(),r=n.ranges;o&&o.startColumn>-1&&r.some(s=>s.startColumn<o.startColumn)&&this._refreshCurrent()}else if(e.id===_.SetRowHiddenMutation.id||e.id===_.SetRowVisibleMutation.id){const n=e.params,o=this._getFreeze(),r=n.ranges;o&&o.startRow>-1&&r.some(s=>s.startRow<o.startRow)&&this._refreshCurrent()}}))}_zoomRefresh(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;e.onTransformChangeObservable.add(n=>{n.type===b.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var n,o,r,s;(n=this._rowFreezeHeaderRect)==null||n.dispose(),(o=this._rowFreezeMainRect)==null||o.dispose(),(r=this._columnFreezeHeaderRect)==null||r.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose();const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(a=>{e.onPointerDownObserver.remove(a),e.onPointerMoveObserver.remove(a),e.onPointerLeaveObserver.remove(a)}),e.onPointerEnterObserver.remove(this._moveObserver),e.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(t,e){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(t,e);if(o==null)return;if(r!=null&&(!isNaN(r.endX)||!isNaN(r.endY)))return r;const{rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=o;return{startX:s,endX:s,startY:a,endY:a}}_getFreeze(){var e;const t=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(t!=null)return t.freeze}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_refreshFreeze(t,e,n,o,r){var a;const s={startRow:t,startColumn:e,ySplit:n,xSplit:o};this._clearFreeze(),this._createFreeze(0,s),this._createFreeze(1,s),this._updateViewport(t,e,n,o,r),(a=this._getSheetObject())==null||a.spreadsheet.makeForceDirty()}};bn=ad([l.OnLifecycle(l.LifecycleStages.Rendered,bn),Le(0,N.Inject(exports.SheetSkeletonManagerService)),Le(1,l.IUniverInstanceService),Le(2,l.ICommandService),Le(3,b.IRenderManagerService),Le(4,fe),Le(5,N.Inject(_.SelectionManagerService)),Le(6,N.Inject(Qe)),Le(7,N.Inject(l.ThemeService)),Le(8,N.Inject(_.SheetInterceptorService)),Le(9,N.Inject(N.Injector))],bn);var bi=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(bi||{});const md="rgba(0, 0, 0, 0.15)",$e="rgb(0, 0, 0)",an="rgb(255, 255, 255, 1)";class gd extends b.Shape{constructor(e,n){super(e,n);I(this,"_size",12);I(this,"_iconRatio",.4);I(this,"_mode",0);this.setShapeProps(n)}setShapeProps(e){e!=null&&e.size&&(this._size=e.size),e!=null&&e.mode&&(this._mode=e.mode),this.transformByState({width:this._size,height:this._size})}_draw(e){this._mode===1&&b.Rect.drawWith(e,{width:this._size,height:this._size,radius:this._size,fill:md});const n=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=n*Math.sin(o),s=n*Math.cos(o);b.RegularPolygon.drawWith(e,{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:n+this._size/2}]],fill:$e})}}var Sd=Object.defineProperty,_d=Object.getOwnPropertyDescriptor,fd=(i,t,e,n)=>{for(var o=n>1?void 0:n?_d(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Sd(t,e,o),o},ut=(i,t)=>(e,n)=>t(e,n,i);const pd="__SpreadsheetHeaderMenuSHAPEControllerShape__",Cd="__SpreadsheetHeaderMenuMAINControllerShape__",vd="rgba(0, 0, 0, 0.1)";let wn=class extends l.Disposable{constructor(t,e,n,o,r,s){super();I(this,"_hoverRect");I(this,"_hoverMenu");I(this,"_currentColumn",Number.POSITIVE_INFINITY);I(this,"_observers",[]);this._sheetSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,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 t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:e,spreadsheetColumnHeader:n}=t;this._observers.forEach(s=>{e.onPointerEnterObserver.remove(s),e.onPointerMoveObserver.remove(s),e.onPointerLeaveObserver.remove(s),n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)})}_initialize(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;this._hoverRect=new b.Rect(pd,{fill:vd,evented:!1}),this._hoverMenu=new gd(Cd,{zIndex:100,visible:!1}),e.addObjects([this._hoverRect,this._hoverMenu],Je),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(t=0){const e=this._getSheetObject();if(e==null)return;const{spreadsheetColumnHeader:n,spreadsheetRowHeader:o}=e,r=t===0?o:n;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 C,R,M;const a=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(a==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=a,{startX:h,startY:m,endX:g,endY:S,column:f}=It(s.offsetX,s.offsetY,c.scene,a);if(t===0)(R=this._hoverRect)==null||R.transformByState({width:d,height:S-m,left:0,top:m});else{if(this._currentColumn=f,(M=this._hoverRect)==null||M.transformByState({width:g-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(g-h<u*2){this._hoverMenu.hide();return}const w=u*.8;this._hoverMenu.transformByState({left:g-u,top:u/2-w/2}),this._hoverMenu.setShapeProps({size:w}),this._hoverMenu.show()}})),this._observers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,a;(s=this._hoverRect)==null||s.hide(),(a=this._hoverMenu)==null||a.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const t=this._getSheetObject();t!=null&&(this._hoverMenu.setProps({mode:bi.HIGHLIGHT,visible:!0}),t.scene.setCursor(b.CURSOR_TYPE.POINTER))}),this._hoverMenu.onPointerLeaveObserver.add(()=>{if(this._hoverMenu==null)return;const t=this._getSheetObject();t!=null&&(this._hoverMenu.setProps({mode:bi.NORMAL,visible:!1}),t.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(t=>{if(!this._getSheetObject())return;const n=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();if(!!!(o!=null&&o.filter(s=>s.rangeType===l.RANGE_TYPE.COLUMN).find(s=>{const{startColumn:a,endColumn:c}=s;return n>=a&&n<=c}))){const s=this._getSelectionOnColumn(n);this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,s)}t.stopPropagation(),t.preventDefault(),this._contextMenuService.triggerContextMenu(t,ce.COL_HEADER_CONTEXT_MENU)}))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_getSelectionOnColumn(t){const e=this._currentUniverService.getCurrentUniverSheetInstance(),n=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:{startRow:0,startColumn:t,endRow:n.getRowCount()-1,endColumn:t,rangeType:l.RANGE_TYPE.COLUMN},primary:{startRow:0,startColumn:t,endRow:0,endColumn:t,actualRow:0,actualColumn:t,isMerged:!1,isMergedMainCell:!1},style:null}]}}};wn=fd([l.OnLifecycle(l.LifecycleStages.Rendered,wn),ut(0,N.Inject(exports.SheetSkeletonManagerService)),ut(1,l.IUniverInstanceService),ut(2,b.IRenderManagerService),ut(3,v.IContextMenuService),ut(4,l.ICommandService),ut(5,N.Inject(_.SelectionManagerService))],wn);var Id=Object.defineProperty,Rd=Object.getOwnPropertyDescriptor,Md=(i,t,e,n)=>{for(var o=n>1?void 0:n?Rd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Id(t,e,o),o},ht=(i,t)=>(e,n)=>t(e,n,i);const bd="__SpreadsheetHeaderMoveControllerBackground__",wd="__SpreadsheetHeaderMoveControllerShapeLine__",Td="rgba(0, 0, 0, 0.1)",Ed="rgb(119, 119, 119)",Od=4;let Tn=class extends l.Disposable{constructor(t,e,n,o,r,s){super();I(this,"_startOffsetX",Number.NEGATIVE_INFINITY);I(this,"_startOffsetY",Number.NEGATIVE_INFINITY);I(this,"_moveHelperBackgroundShape");I(this,"_moveHelperLineShape");I(this,"_sheetObject");I(this,"_rowOrColumnDownObservers",[]);I(this,"_rowOrColumnMoveObservers",[]);I(this,"_rowOrColumnLeaveObservers",[]);I(this,"_moveObserver");I(this,"_upObserver");I(this,"_scrollTimer");I(this,"_changeFromColumn",-1);I(this,"_changeFromRow",-1);I(this,"_changeToColumn",-1);I(this,"_changeToRow",-1);this._sheetSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,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 t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:e,spreadsheetColumnHeader:n,scene:o}=t;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(a=>{e.onPointerDownObserver.remove(a),n.onPointerDownObserver.remove(a)}),o.onPointerMoveObserver.remove(this._moveObserver),o.onPointerUpObserver.remove(this._upObserver),this._scrollTimer.dispose()}_initialize(){const t=this._getSheetObject();t!=null&&(this._sheetObject=t,this._initialRowOrColumn(0),this._initialRowOrColumn(1))}_initialRowOrColumn(t=0){const{spreadsheetColumnHeader:e,spreadsheetRowHeader:n,scene:o}=this._sheetObject,r=t===0?n:e;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const a=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(a==null)return;const{row:c,column:d}=It(s.offsetX,s.offsetY,o,a);if(this._checkInHeaderRange(t===0?c:d,t)===!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,a;(s=this._moveHelperBackgroundShape)==null||s.hide(),(a=this._moveHelperLineShape)==null||a.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var T;const a=(T=this._sheetSkeletonManagerService.getCurrent())==null?void 0:T.skeleton;if(a==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:g,column:S}=It(s.offsetX,s.offsetY,o,a);let f;t===0?(this._changeFromRow=g,f=b.ScrollTimerType.Y):(this._changeFromColumn=S,f=b.ScrollTimerType.X);const C=this._checkInHeaderRange(t===0?g:S,t);if(C===!1)return;const R=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(b.CURSOR_TYPE.GRABBING),o.disableEvent();let M=!1,w;const E=()=>{if(M)return;w=b.ScrollTimer.create(o,f);const O=o.getViewport(B.VIEW_MAIN);w.startScroll(h,m,O),this._scrollTimer=w,M=!0};this._moveObserver=o.onPointerMoveObserver.add(O=>{E();const{offsetX:y,offsetY:x}=O,{x:A,y:k}=o.getRelativeCoord(b.Vector2.FromArray([y,x]));o.setCursor(b.CURSOR_TYPE.GRABBING),this._rowColumnMoving(A,k,C,R,t),w.scrolling(A,k,()=>{this._rowColumnMoving(A,k,C,R,t)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var y,x,A;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableEvent(),this._clearObserverEvent(),(y=this._scrollTimer)==null||y.dispose();const O=this._selectionManagerService.getSelections();if(t===0){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const L=(x=((O==null?void 0:O.filter(F=>F.range.rangeType===l.RANGE_TYPE.ROW&&F.range.startRow<=this._changeFromRow&&this._changeFromRow<=F.range.endRow))||[])[0])==null?void 0:x.range;L&&this._commandService.executeCommand(_.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=(A=((O==null?void 0:O.filter(F=>F.range.rangeType===l.RANGE_TYPE.COLUMN&&F.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=F.range.endColumn))||[])[0])==null?void 0:A.range;L&&this._commandService.executeCommand(_.MoveColsCommand.id,{fromRange:L,toRange:{...L,startColumn:this._changeToColumn,endColumn:this._changeToColumn+L.endColumn-L.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})}))}_rowColumnMoving(t,e,n,o,r){var G,ne,D,U,z,q,oe;const{scene:s}=this._sheetObject,a=(G=this._sheetSkeletonManagerService.getCurrent())==null?void 0:G.skeleton;if(a==null)return;const{rowHeaderWidth:c,columnHeaderHeight:d,rowTotalHeight:u,columnTotalWidth:h}=a,m=s.getScrollXY(s.getViewport(B.VIEW_MAIN)),{scaleX:g,scaleY:S}=s.getAncestorScale(),f=a.getCellPositionByOffset(t,e,g,S,m),{row:C,column:R}=f,M=a.getNoMergeCellPositionByIndex(C,R),{startX:w,startY:E,endX:T,endY:O}=M,y=this._selectionRenderService.convertRangeDataToSelection(n.range);if(y==null)return;const x=Math.max(g,g),{startX:A,endX:k,startY:L,endY:F,startRow:V,startColumn:j,endRow:$,endColumn:Z}=y;r===0?(ne=this._moveHelperBackgroundShape)==null||ne.transformByState({height:F-L,width:h+c,left:0,top:L+(e-this._startOffsetY)/x+m.y-o.y}):(D=this._moveHelperBackgroundShape)==null||D.transformByState({height:u+d,width:k-A,left:A+(t-this._startOffsetX)/x+m.x-o.x,top:0}),(U=this._moveHelperBackgroundShape)==null||U.show();const W=Od/x;if(r===0){let re=0;if(C<=V)re=E-W/2,this._changeToRow=C;else if(C>$)re=O-W/2,this._changeToRow=C+1;else return;(z=this._moveHelperLineShape)==null||z.transformByState({height:W,width:h,left:c,top:re})}else{let re=0;if(R<=j)re=w-W/2,this._changeToColumn=R;else if(R>Z)re=T-W/2,this._changeToColumn=R+1;else return;(q=this._moveHelperLineShape)==null||q.transformByState({height:u,width:W,left:re,top:d})}(oe=this._moveHelperLineShape)==null||oe.show()}_checkInHeaderRange(t,e=0){var a;const n=this._selectionManagerService.getSelections();if(((a=this._selectionManagerService.getCurrent())==null?void 0:a.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return!1;const r=n==null?void 0:n.find(c=>{const d=c.range,{startRow:u,endRow:h,startColumn:m,endColumn:g,rangeType:S}=d;return e===1?t>=m&&t<=g&&l.RANGE_TYPE.COLUMN===S:t>=u&&t<=h&&l.RANGE_TYPE.ROW===S}),s=r==null?void 0:r.range;return r==null||s==null||s.rangeType===l.RANGE_TYPE.ALL||s.rangeType===l.RANGE_TYPE.NORMAL||s.rangeType===l.RANGE_TYPE.ROW&&e!==0||s.rangeType===l.RANGE_TYPE.COLUMN&&e!==1?!1:r}_clearObserverEvent(){const{scene:t}=this._sheetObject;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_newBackgroundAndLine(){const{scene:t}=this._sheetObject;this._moveHelperBackgroundShape=new b.Rect(bd,{fill:Td,evented:!1,zIndex:100}),this._moveHelperLineShape=new b.Rect(wd,{fill:Ed,evented:!1,zIndex:100}),t.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],Je)}_disposeBackgroundAndLine(){var t,e;(t=this._moveHelperBackgroundShape)==null||t.dispose(),(e=this._moveHelperLineShape)==null||e.dispose()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Tn=Md([l.OnLifecycle(l.LifecycleStages.Rendered,Tn),ht(0,N.Inject(exports.SheetSkeletonManagerService)),ht(1,l.IUniverInstanceService),ht(2,b.IRenderManagerService),ht(3,l.ICommandService),ht(4,fe),ht(5,N.Inject(_.SelectionManagerService))],Tn);var wi=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(wi||{});const yd="rgba(120, 120, 120, 0.01)",di="rgb(68, 71, 70)",Wt=12,Ti=4;class Oo extends b.Shape{constructor(e,n){super(e,n);I(this,"_size",Wt);I(this,"_color",di);I(this,"_mode",0);this.setShapeProps(n)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){let{width:n,height:o}=this,r=0,s=0;const a=this.getScene(),{scaleX:c,scaleY:d}=a.getAncestorScale(),u=Math.max(c,d),h=Wt/u,m=Ti/u;this.mode===0?(n=m,r=h-m):(o=m,s=h-m),b.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:yd}),b.Rect.drawWith(e,{width:n,height:o,fill:di,radius:m}),e.save(),e.transform(1,0,0,1,r,s),b.Rect.drawWith(e,{width:n,height:o,fill:di,radius:m}),e.restore()}setShapeProps(e){return e!=null&&e.size&&(this._size=e.size),e!=null&&e.mode&&(this._mode=e.mode),e!=null&&e.color&&(this._color=e.color),this.mode===0?this.transformByState({width:Wt,height:this.size}):this.transformByState({width:this.size,height:Wt}),this}}var xd=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,Nd=(i,t,e,n)=>{for(var o=n>1?void 0:n?Ad(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&xd(t,e,o),o},Bt=(i,t)=>(e,n)=>t(e,n,i);const Dd="__SpreadsheetHeaderResizeControllerShapeRow__",Hd="__SpreadsheetHeaderResizeControllerShapeColumn__",yo="__SpreadsheetHeaderResizeControllerShapeHelper__",xo="rgb(199, 199, 199)",Ld=2;let En=class extends l.Disposable{constructor(t,e,n,o,r){super();I(this,"_currentRow",0);I(this,"_currentColumn",0);I(this,"_rowResizeRect");I(this,"_columnResizeRect");I(this,"_observers",[]);I(this,"_moveObserver");I(this,"_upObserver");I(this,"_resizeHelperShape");I(this,"_startOffsetX",Number.POSITIVE_INFINITY);I(this,"_startOffsetY",Number.POSITIVE_INFINITY);this._sheetSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,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 t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:e,spreadsheetColumnHeader:n}=t;this._observers.forEach(s=>{e.onPointerMoveObserver.remove(s),e.onPointerLeaveObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;this._rowResizeRect=new Oo(Dd,{visible:!1,mode:wi.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Oo(Hd,{visible:!1,mode:wi.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],Je),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(t=0){const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:o,scene:r}=e,s=t===0?n:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((a,c)=>{var y;const d=(y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:y.skeleton;if(d==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:u,columnHeaderHeight:h}=d,{startX:m,startY:g,endX:S,endY:f,row:C,column:R}=It(a.offsetX,a.offsetY,r,d),M=hn(a.offsetX,a.offsetY,r),{scaleX:w,scaleY:E}=r.getAncestorScale(),T=Math.max(w,E),O=Wt/T;if(t===0){let x=g-O/2;if(M.y<=g+O/2&&M.y>=g)this._currentRow=C-1;else if(M.y>=f-O/2&&M.y<=f)this._currentRow=C,x=f-O/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const A=u/3;this._rowResizeRect.transformByState({left:u/2-A/2,top:x}),this._rowResizeRect.setShapeProps({size:A}),this._rowResizeRect.show()}else{let x=m-O/2;if(M.x<=m+O/2&&M.x>=m)this._currentColumn=R-1;else if(M.x>=S-O/2&&M.x<=S)this._currentColumn=R,x=S-O/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const A=h*.7;this._columnResizeRect.transformByState({left:x,top:h/2-A/2}),this._columnResizeRect.setShapeProps({size:A}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((a,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(t=0){const e=this._getSheetObject();if(e==null)return;const{scene:n}=e,o=t===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=n.getEngine(),s=(r==null?void 0:r.width)||0,a=(r==null?void 0:r.height)||0;this.disposeWithMe(l.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),n.setCursor(t===0?b.CURSOR_TYPE.ROW_RESIZE:b.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(l.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),n.resetCursor())}))),this.disposeWithMe(l.toDisposable(o.onPointerDownObserver.add((c,d)=>{var ne,D,U,z,q,oe,re;const u=(ne=this._sheetSkeletonManagerService.getCurrent())==null?void 0:ne.skeleton;if(u==null)return;const h=this._getSheetObject();if(h==null)return;const{scene:m}=h,g=m.getViewport(B.VIEW_MAIN),S=(((U=(D=g==null?void 0:g.getScrollBar())==null?void 0:D.horizonBarRect)==null?void 0:U.height)||0)+10,f=(((q=(z=g==null?void 0:g.getScrollBar())==null?void 0:z.verticalBarRect)==null?void 0:q.width)||0)+10,C=hn(c.offsetX,c.offsetY,m),{scaleX:R,scaleY:M}=m.getAncestorScale();this._startOffsetX=C.x,this._startOffsetY=C.y;const w=u.getOffsetByPositionX(this._currentColumn),E=u.getOffsetByPositionY(this._currentRow),T=u.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let O=!1,y=0,x=0;const{columnTotalWidth:A,rowHeaderWidth:k,rowTotalHeight:L,columnHeaderHeight:F}=u,V=s>A+k?s:A+k,j=a>L+F?a:L+F,$=Math.max(R,M),Z=Ti/$;t===0?this._resizeHelperShape=new b.Rect(yo,{width:V,height:Z,fill:xo,left:0,top:E-Z/2}):this._resizeHelperShape=new b.Rect(yo,{width:Z,height:j,fill:xo,left:w-Z/2,top:0});const W=((oe=this._columnResizeRect)==null?void 0:oe.left)||0,G=((re=this._rowResizeRect)==null?void 0:re.top)||0;m.addObject(this._resizeHelperShape,Je),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(Y=>{var Be,Ce,xt,At,Nt,Dt;const X=m.getRelativeCoord(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Q=m.getScrollXYByRelativeCoords(X,g),le=hn(Y.offsetX,Y.offsetY,m),{x:se,y:me}=le,{scaleX:Ve,scaleY:pe}=m.getAncestorScale(),ue=Math.max(Ve,pe),ae=Ti/ue;y=se-this._startOffsetX-ae/2,x=me-this._startOffsetY-ae/2,Math.abs(t===0?x:y)>=Ld&&(O=!0),t===0?(x>a-S+Q.y-T.startY&&(x=a-S+Q.y-T.startY),x<-(T.endY-T.startY)+2&&(x=-(T.endY-T.startY)+2),O&&((Be=this._resizeHelperShape)==null||Be.transformByState({top:E+x}),(Ce=this._rowResizeRect)==null||Ce.transformByState({top:G+x+ae/2}),(xt=this._rowResizeRect)==null||xt.show(),m.setCursor(b.CURSOR_TYPE.ROW_RESIZE))):(y>s-f+Q.x-T.startX&&(y=s-f+Q.x-T.startX),y<-(T.endX-T.startX)+2&&(y=-(T.endX-T.startX)+2),O&&((At=this._resizeHelperShape)==null||At.transformByState({left:w+y}),(Nt=this._columnResizeRect)==null||Nt.transformByState({left:W+y+ae/2}),(Dt=this._columnResizeRect)==null||Dt.show(),m.setCursor(b.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(Y=>{var le,se,me;const X=ve(this._currentUniverService,this._renderManagerService);if(X==null)return;this._clearObserverEvent(),(le=this._resizeHelperShape)==null||le.dispose(),this._resizeHelperShape=null;const{scene:Q}=X;Q.enableEvent(),O&&(Q.resetCursor(),(se=this._rowResizeRect)==null||se.hide(),(me=this._columnResizeRect)==null||me.hide(),t===0?this._commandService.executeCommand(_.DeltaRowHeightCommand.id,{deltaY:x,anchorRow:this._currentRow}):this._commandService.executeCommand(_.DeltaColumnWidthCommand.id,{deltaX:y,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(l.toDisposable(o.onDblclickObserver.add(()=>{var c;if(t===0){const d=this._getSheetObject();if(d==null)return;const{scene:u}=d;u.resetCursor(),this._commandService.executeCommand(_.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const t=this._getSheetObject();if(t==null)return;const{scene:e}=t;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};En=Nd([l.OnLifecycle(l.LifecycleStages.Rendered,En),Bt(0,N.Inject(exports.SheetSkeletonManagerService)),Bt(1,l.IUniverInstanceService),Bt(2,l.ICommandService),Bt(3,b.IRenderManagerService),Bt(4,Ee)],En);var Ei=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(Ei||{});const jt=12,Pd=.4;class Ao extends b.Shape{constructor(e,n,o){super(e,n);I(this,"_size",jt);I(this,"_iconRatio",Pd);I(this,"_hovered",!0);I(this,"_hasPrevious",!0);I(this,"_hasNext",!0);I(this,"_unhideType");n&&this.setShapeProps(n),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(e){e.type!==void 0&&(this._unhideType=e.type),e.hovered!==void 0&&(this._hovered=e.hovered),e.hasPrevious!==void 0&&(this._hasPrevious=e.hasPrevious),e.hasNext!==void 0&&(this._hasNext=e.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(e){this._unhideType===0?this._drawOnRow(e):this._drawOnCol(e)}_drawOnRow(e){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(e,{width:this._size,height:this._size,stroke:$e,fill:an}):b.Rect.drawWith(e,{width:this._size,height:2*this._size,stroke:$e,fill:an}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(e,{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:$e}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(e,{pointsGroup:[[{x:this._size/2,y:this._size*a/2+s},{x:this._size/2-s,y:this._size*a/2-r},{x:this._size/2+s,y:this._size*a/2-r}]],fill:$e})}}_drawOnCol(e){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(e,{width:this._size,height:this._size,stroke:$e,fill:an}):b.Rect.drawWith(e,{width:2*this._size,height:this._size,stroke:$e,fill:an}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(e,{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:$e}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(e,{pointsGroup:[[{x:r+this._size*a/2,y:this._size/2},{x:-s+this._size*a/2,y:this._size/2-s},{x:-s+this._size*a/2,y:this._size/2+s}]],fill:$e})}}}var Ud=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Vd=(i,t,e,n)=>{for(var o=n>1?void 0:n?kd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Ud(t,e,o),o},ln=(i,t)=>(e,n)=>t(e,n,i);const No="__SpreadsheetHeaderUnhideSHAPEControllerShape__",Bd=[_.SetRowHiddenMutation.id,_.SetRowVisibleMutation.id,_.SetColHiddenMutation.id,_.SetColVisibleMutation.id];let On=class extends l.RxDisposable{constructor(t,e,n,o){super();I(this,"_shapes",new Map);this._sheetSkeletonManagerService=t,this._cmdSrv=e,this._univerInstanceService=n,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const e=this._univerInstanceService.getCurrentUniverSheetInstance(),n=e.getActiveSheet();n&&this._initForWorksheet(e,n),this._sheetSkeletonManagerService.currentSkeleton$.pipe(H.takeUntil(this.dispose$),H.startWith(void 0),H.pairwise()).subscribe(([o,r])=>{if(r){const s=this._univerInstanceService.getUniverSheetInstance(r.unitId),a=s.getSheetBySheetId(r.sheetId);this._updateWorksheet(s,a,o==null?void 0:o.sheetId)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!Bd.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(t,e){var m;const n=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!n)return;const o=e.getHiddenRows(),r=e.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:a}=s,c=e.getRowCount(),d=o.map(g=>{const{startRow:S,endRow:f}=g,C=Mi(S,0,a,n),R=S!==0,M=f!==c-1;return new Ao(No,{type:Ei.ROW,hovered:!1,hasPrevious:R,hasNext:M,top:C.startY-(R?jt:0),left:C.startX-jt},()=>this._cmdSrv.executeCommand(_.SetSpecificRowsVisibleCommand.id,{unitId:t.getUnitId(),subUnitId:e.getSheetId(),ranges:[g]}))}),u=e.getColumnCount(),h=r.map(g=>{const{startColumn:S,endColumn:f}=g,C=Mi(0,S,a,n),R=S!==0,M=f!==u-1;return new Ao(No,{type:Ei.COLUMN,hovered:!1,hasPrevious:R,hasNext:M,left:C.startX-(R?jt:0),top:20-jt},()=>this._cmdSrv.executeCommand(_.SetSpecificColsVisibleCommand.id,{unitId:t.getUnitId(),subUnitId:e.getSheetId(),ranges:[g]}))});a.addObjects(h,ao),a.addObjects(d,ao),this._shapes.set(l.getWorksheetUID(t,e),{cols:h,rows:d})}_updateWorksheet(t,e,n){if(n){const o=this._shapes.get(`${t.getUnitId()}|${n}`);o==null||o.cols.forEach(r=>r.dispose()),o==null||o.rows.forEach(r=>r.dispose())}this._initForWorksheet(t,e)}_getSheetObject(){return ve(this._univerInstanceService,this._rendererManagerService)}};On=Vd([l.OnLifecycle(l.LifecycleStages.Rendered,On),ln(0,N.Inject(exports.SheetSkeletonManagerService)),ln(1,l.ICommandService),ln(2,l.IUniverInstanceService),ln(3,b.IRenderManagerService)],On);var Fd=Object.defineProperty,Wd=Object.getOwnPropertyDescriptor,jd=(i,t,e,n)=>{for(var o=n>1?void 0:n?Wd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Fd(t,e,o),o},ui=(i,t)=>(e,n)=>t(e,n,i);let yn=class extends l.Disposable{constructor(i,t,e){super(),this._markSelectionService=i,this._commandService=t,this._sheetSkeletonManagerService=e,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[Pe.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{i.includes(t.id)?this._markSelectionService.removeAllShapes():this._markSelectionService.getShapeMap().forEach((n,o)=>{n.exits.includes(t.id)&&this._markSelectionService.removeShape(o)})}))}_addRefreshListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};yn=jd([l.OnLifecycle(l.LifecycleStages.Steady,yn),ui(0,N.Inject(qt)),ui(1,l.ICommandService),ui(2,N.Inject(exports.SheetSkeletonManagerService))],yn);var $d=Object.defineProperty,zd=Object.getOwnPropertyDescriptor,Yd=(i,t,e,n)=>{for(var o=n>1?void 0:n?zd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&$d(t,e,o),o},hi=(i,t)=>(e,n)=>t(e,n,i);let xn=class extends l.Disposable{constructor(t,e,n){super();I(this,"_initialize",()=>{const t=new l.DisposableCollection;this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{t.dispose();const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{t.add(l.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),a={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(a.startRow===c.startRow&&a.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:a,toRange:c};this._commandService.executeCommand(_.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=t,this._selectionManagerService=e,this._commandService=n,this._initialize()}};xn=Yd([l.OnLifecycle(l.LifecycleStages.Steady,xn),hi(0,N.Inject(fe)),hi(1,N.Inject(_.SelectionManagerService)),hi(2,N.Inject(l.ICommandService))],xn);var Xd=Object.defineProperty,Zd=Object.getOwnPropertyDescriptor,Gd=(i,t,e,n)=>{for(var o=n>1?void 0:n?Zd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Xd(t,e,o),o},mt=(i,t)=>(e,n)=>t(e,n,i);let pt=class extends l.Disposable{constructor(i,t,e,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=t,this._commandService=e,this._renderManagerService=n,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}scrollToVisible(i=!0){var F,V,j,$;let t,e;const n=this._selectionManagerService.getLast();if(n==null)return;const{startRow:o,startColumn:r,actualRow:s,actualColumn:a}=n.primary,c=i?s:o,d=i?a:r,{rowHeightAccumulation:u,columnWidthAccumulation:h}=(V=(F=this._sheetSkeletonManagerService.getCurrent())==null?void 0:F.skeleton)!=null?V:{};if(u==null||h==null)return;const m=(j=this._getSheetObject())==null?void 0:j.scene;if(m==null)return;const g=m.getViewport(B.VIEW_MAIN);if(g==null||this._getSheetObject()==null)return;const f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:C,startRow:R,ySplit:M,xSplit:w}=f.getFreeze(),E=g.getBounding(),T=($=this._sheetSkeletonManagerService.getCurrent())==null?void 0:$.skeleton;if(T==null)return;const{startRow:O,startColumn:y,endRow:x,endColumn:A}=T.getRowColumnSegment(E);if(c>=R&&d>=C-w&&(c<=O&&(t=c),c>=x)){const Z=u[c]-g.height;for(let W=O;W<=c;W++)if(u[W]>=Z){t=W+1;break}}if(d>=C&&c>=R-M&&(d<=y&&(e=d),d>=A)){const Z=h[d]-g.width;for(let W=y;W<=d;W++)if(h[W]>=Z){e=W+1;break}}if(t===void 0&&e===void 0)return;const{offsetX:k,offsetY:L}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(ft.id,{sheetViewStartRow:t,sheetViewStartColumn:e,offsetX:e===void 0?k:0,offsetY:t===void 0?L:0})}dispose(){super.dispose()}_initialize(){this._scrollEventBinding(),this._scrollSubscribeBinding(),this._skeletonListener()}_getFreeze(){var t;const i=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_scrollEventBinding(){var e;const i=(e=this._getSheetObject())==null?void 0:e.scene;if(i==null)return;const t=i.getViewport(B.VIEW_MAIN);this.disposeWithMe(l.toDisposable(t==null?void 0:t.onScrollAfterObserver.add(n=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,a);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(l.toDisposable(t==null?void 0:t.onScrollByBarObserver.add(n=>{var g;const o=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,c=this._getFreeze(),{row:d,column:u,rowOffset:h,columnOffset:m}=o.getDecomposedOffset(s,a);this._commandService.executeCommand(ft.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(l.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var S;const t=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,e=this._getSheetObject();if(t==null||e==null)return;const n=e.scene;e.scene.getAncestorScale();const o=n.getViewport(B.VIEW_MAIN);if(o==null)return;if(i==null){o.scrollTo({x:0,y:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:a,offsetY:c}=i,{startX:d,startY:u}=t.getCellByIndexWithNoHeader(r,s),h=d+a,m=u+c,g=o.getBarScroll(h,m);o.scrollTo(g)})))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:t,sheetId:e}=i;this._renderManagerService.getRenderById(t)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:t,sheetId:e}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:t,unitId:e}=i,n=(c=this._renderManagerService.getRenderById(e))==null?void 0:c.scene;if(t==null||n==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=t;n==null||n.transformByState({width:s+r,height:a+o})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};pt=Gd([l.OnLifecycle(l.LifecycleStages.Rendered,pt),mt(0,N.Inject(exports.SheetSkeletonManagerService)),mt(1,l.IUniverInstanceService),mt(2,l.ICommandService),mt(3,b.IRenderManagerService),mt(4,N.Inject(_.SelectionManagerService)),mt(5,N.Inject(Qe))],pt);var Kd=Object.defineProperty,qd=Object.getOwnPropertyDescriptor,Jd=(i,t,e,n)=>{for(var o=n>1?void 0:n?qd(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&Kd(t,e,o),o},Do=(i,t)=>(e,n)=>t(e,n,i);const Qd=[Te.id,dt.id];let An=class extends l.Disposable{constructor(i,t){super(),this._commandService=i,this._scrollController=t,this.disposeWithMe(this._commandService.onCommandExecuted(e=>{Qd.includes(e.id)&&this._scrollController.scrollToVisible()}))}};An=Jd([l.OnLifecycle(l.LifecycleStages.Rendered,An),Do(0,l.ICommandService),Do(1,N.Inject(pt))],An);var eu=Object.defineProperty,tu=Object.getOwnPropertyDescriptor,nu=(i,t,e,n)=>{for(var o=n>1?void 0:n?tu(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&eu(t,e,o),o},Ge=(i,t)=>(e,n)=>t(e,n,i);let Nn=class extends l.Disposable{constructor(i,t,e,n,o,r,s,a){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=t,this._commandService=e,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._scrollController=a,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),t=i.getActiveSheet(),e=this._getSheetObject();if(e==null)return;this._initViewMainListener(e),this._initRowHeader(e),this._initColumnHeader(e),this._initLeftTop(e),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const n=i.getUnitId(),o=t.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,unitId:n,sheetId:o})}_getActiveViewport(i){const t=this._getSheetObject();return t==null?void 0:t.scene.getActiveViewportByCoord(b.Vector2.FromArray([i.offsetX,i.offsetY]))}_initViewMainListener(i){const{spreadsheet:t}=i;this.disposeWithMe(l.toDisposable(t==null?void 0:t.onPointerDownObserver.add((e,n)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(e,t.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(e)),e.button!==2&&n.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(l.toDisposable(this._themeService.currentTheme$.subscribe(()=>{this._selectionRenderService.resetStyle();const i=this._selectionManagerService.getSelections(),t=this._selectionManagerService.getCurrent();i==null||(t==null?void 0:t.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){const t=i.map(e=>{const n=this._selectionRenderService.convertSelectionRangeToData(e);return n.style=_.getNormalSelectionStyle(this._themeService),n});this._selectionRenderService.updateControlForCurrentByRangeData(t)}_initRowHeader(i){const{spreadsheetRowHeader:t,spreadsheet:e}=i;this.disposeWithMe(l.toDisposable(t==null?void 0:t.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((e==null?void 0:e.zIndex)||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(n),b.ScrollTimerType.Y),n.button!==2&&o.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:t,spreadsheet:e}=i;this.disposeWithMe(l.toDisposable(t==null?void 0:t.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((e==null?void 0:e.zIndex)||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(n),b.ScrollTimerType.X),n.button!==2&&o.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:t}=i;this.disposeWithMe(l.toDisposable(t==null?void 0:t.onPointerDownObserver.add((e,n)=>{var a;const o=(a=this._sheetSkeletonManagerService.getCurrent())==null?void 0:a.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(),e.button!==2&&n.stopPropagation()})))}_initSelectionChangeListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const t of i){if(t==null)continue;const e=this._selectionRenderService.convertSelectionRangeToData(t);this._selectionRenderService.addControlToCurrentByRangeData(e)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVE_END)})}_move(i,t){const e=this._currentUniverService.getCurrentUniverSheetInstance(),n=e.getUnitId(),o=e.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(_.SetSelectionsOperation.id,{unitId:n,subUnitId:o,type:t,pluginName:(r==null?void 0:r.pluginName)||_.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>_.convertSelectionDataToRange(s))})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[Ye.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(i.includes(t.id)){const e=this._currentUniverService.getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=t.params,{unitId:r,subUnitId:s}=o;if(!(r===e.getUnitId()&&s===n.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:t,sheetId:e,skeleton:n}=i,o=this._renderManagerService.getRenderById(t);if(o==null)return;const{scene:r}=o,s=r.getViewport(B.VIEW_MAIN);this._selectionRenderService.changeRuntime(n,r,s);const a=this._selectionManagerService.getCurrent(),c=(a==null?void 0:a.pluginName)||_.NORMAL_SELECTION_PLUGIN_NAME;if((a==null?void 0:a.unitId)===t&&a.sheetId===e){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:t,sheetId:e});c===_.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(n)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const t=i.mergeData;return _.transformCellDataToSelectionData(0,0,t)||{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}}};Nn=nu([l.OnLifecycle(l.LifecycleStages.Rendered,Nn),Ge(0,N.Inject(exports.SheetSkeletonManagerService)),Ge(1,l.IUniverInstanceService),Ge(2,l.ICommandService),Ge(3,b.IRenderManagerService),Ge(4,fe),Ge(5,N.Inject(_.SelectionManagerService)),Ge(6,N.Inject(l.ThemeService)),Ge(7,N.Inject(pt))],Nn);var iu=Object.defineProperty,ou=Object.getOwnPropertyDescriptor,ru=(i,t,e,n)=>{for(var o=n>1?void 0:n?ou(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&iu(t,e,o),o},cn=(i,t)=>(e,n)=>t(e,n,i);let Dn=class extends l.Disposable{constructor(i,t,e,n){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=t,this._renderManagerService=e,this._commandService=n,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:t,unitId:e,sheetId:n}=i,o=this._currentUniverService.getUniverSheetInstance(e),r=o==null?void 0:o.getSheetBySheetId(n);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(e);if(s==null)return;const{mainComponent:a,components:c}=s,d=a,u=c.get(Se.ROW),h=c.get(Se.COLUMN),m=c.get(Se.LEFT_TOP),{rowHeaderWidth:g,columnHeaderHeight:S}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),m==null||m.transformByState({width:g,height:S})}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{var n,o;const t=this._currentUniverService.getCurrentUniverSheetInstance(),e=t.getUnitId();if(_.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const r=t.getActiveSheet(),s=r.getSheetId(),a=i.params,{unitId:c,subUnitId:d}=a;if(!(c===t.getUnitId()&&d===r.getSheetId()))return;i.id!==_.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:c,sheetId:s,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:c,sheetId:s,commandId:i.id})}else _.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===l.CommandType.MUTATION&&((o=(n=this._renderManagerService.getRenderById(e))==null?void 0:n.mainComponent)==null||o.makeDirty())}))}};Dn=ru([l.OnLifecycle(l.LifecycleStages.Ready,Dn),cn(0,N.Inject(exports.SheetSkeletonManagerService)),cn(1,l.IUniverInstanceService),cn(2,b.IRenderManagerService),cn(3,l.ICommandService)],Dn);const Xe={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,t)=>{const e=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(v.IConfirmService),s=i.get(l.LocaleService),a=t.unitId,c=t.subUnitId,d=t.selections,u=_.getAddMergeMutationRangeByType(d,t.value),h=o.getUniverSheetInstance(a).getSheetBySheetId(c),m=[],g=[],S=Or(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:a,subUnitId:c,ranges:u},C={unitId:a,subUnitId:c,ranges:u};m.push({id:_.RemoveWorksheetMergeMutation.id,params:f}),m.push({id:_.AddWorksheetMergeMutation.id,params:C});const R=_.RemoveMergeUndoMutationFactory(i,f),M=_.AddMergeUndoMutationFactory(i,C);if(g.push({id:_.RemoveWorksheetMergeMutation.id,params:M}),g.push({id:_.AddWorksheetMergeMutation.id,params:R}),S){const E=yr(i,a,h,u);m.unshift(...E.redos),g.push(...E.undos)}return l.sequenceExecute(m,e).result?(n.pushUndoRedo({unitID:a,undoMutations:g,redoMutations:m}),!0):!1}},jr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const t=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return t.executeCommand(Xe.id,{selections:n,unitId:a,subUnitId:c})}},$r={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const t=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return t.executeCommand(Xe.id,{value:l.Dimension.COLUMNS,selections:n,unitId:a,subUnitId:c})}},zr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const t=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return t.executeCommand(Xe.id,{value:l.Dimension.ROWS,selections:n,unitId:a,subUnitId:c})}},ji={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async i=>{const t=i.get(v.IConfirmService),e=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.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=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await t.confirm({id:ji.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?e.executeCommand(_.DeleteRangeMoveLeftCommand.id):!0}},$i={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async i=>{const t=i.get(v.IConfirmService),e=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.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=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await t.confirm({id:$i.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?e.executeCommand(_.DeleteRangeMoveUpCommand.id):!0}},zi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async i=>{const t=i.get(v.IConfirmService),e=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.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=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await t.confirm({id:zi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?e.executeCommand(_.InsertRangeMoveDownCommand.id):!0}},Yi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async i=>{const t=i.get(v.IConfirmService),e=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.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=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await t.confirm({id:Yi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?e.executeCommand(_.InsertRangeMoveRightCommand.id):!0}},Yr={id:"sheet.command.refill",type:l.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(Jt);return e.applyType=t.type,!0}},Xr={id:"sheet.command.remove-row-confirm",type:l.CommandType.COMMAND,handler:async(i,t)=>{var d;const e=i.get(_.SelectionManagerService);let n=t==null?void 0:t.range;if(n||(n=(d=e.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(rr(c,[n])){const u=i.get(v.IConfirmService),h=i.get(l.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(_.RemoveRowCommand.id,{range:n}),!0}},Zr={id:"sheet.command.remove-col-confirm",type:l.CommandType.COMMAND,handler:async(i,t)=>{var d;const e=i.get(_.SelectionManagerService);let n=t==null?void 0:t.range;if(n||(n=(d=e.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(sr(c,[n])){const u=i.get(v.IConfirmService),h=i.get(l.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(_.RemoveColCommand.id,{range:n}),!0}},Gr={id:"sheet.command.remove-sheet-confirm",type:l.CommandType.COMMAND,handler:async(i,t)=>{const{subUnitId:e}=t,n=i.get(v.IConfirmService),o=i.get(l.ICommandService),r=i.get(l.LocaleService);return await n.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(_.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},yt=N.createIdentifier("univer.sheetbar-service");class su extends l.Disposable{constructor(){super();I(this,"renameId$");I(this,"removeId$");I(this,"scroll$");I(this,"scrollX$");I(this,"addSheet$");I(this,"_renameId$");I(this,"_removeId$");I(this,"_scroll$");I(this,"_scrollX$");I(this,"_addSheet$");I(this,"_currentHandler",null);this._renameId$=new H.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new H.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new H.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new H.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new H.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(e){this._renameId$.next(e)}setRemoveId(e){this._removeId$.next(e)}setScroll(e){this._scroll$.next(e)}setScrollX(e){this._scrollX$.next(e)}setAddSheet(e){this._addSheet$.next(e)}triggerSheetBarMenu(){var e;(e=this._currentHandler)==null||e.handleSheetBarMenu()}registerSheetBarMenuHandler(e){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=e,l.toDisposable(()=>{this._currentHandler=null})}}const Kr={id:"ui-sheet.command.show-menu-list",type:l.CommandType.OPERATION,handler:async i=>(i.get(yt).triggerSheetBarMenu(),!0)},qr={id:"sheet.operation.rename-sheet",type:l.CommandType.OPERATION,handler:async(i,t)=>{const e=i.get(yt);return t&&e.setRenameId(t.subUnitId),!0}},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:"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"})]}),lu=()=>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"})]}),cu=()=>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"})]}),du=()=>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"})]}),uu=()=>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"})}),hu=()=>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"})]}),mu=()=>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"})]}),gu=()=>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"})]}),Su=()=>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"})}),Ho=()=>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 Lo(i){const{type:t=l.BorderStyleTypes.THIN}=i;switch(t){case l.BorderStyleTypes.DASH_DOT:return p.jsx(au,{});case l.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(lu,{});case l.BorderStyleTypes.DASHED:return p.jsx(cu,{});case l.BorderStyleTypes.HAIR:return p.jsx(du,{});case l.BorderStyleTypes.MEDIUM:return p.jsx(uu,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(hu,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(mu,{});case l.BorderStyleTypes.MEDIUM_DASHED:return p.jsx(gu,{});case l.BorderStyleTypes.THICK:return p.jsx(Su,{});case l.BorderStyleTypes.THIN:return p.jsx(Ho,{});default:return p.jsx(Ho,{})}}const _u="univer-ui-plugin-sheets-border-panel",fu="univer-ui-plugin-sheets-border-panel-position",pu="univer-ui-plugin-sheets-border-panel-position-item",Cu="univer-ui-plugin-sheets-border-panel-styles",vu="univer-ui-plugin-sheets-border-panel-board",Iu="univer-ui-plugin-sheets-border-panel-button",Ru="univer-ui-plugin-sheets-border-panel-more-icon",je={uiPluginSheetsBorderPanel:_u,uiPluginSheetsBorderPanelPosition:fu,uiPluginSheetsBorderPanelPositionItem:pu,uiPluginSheetsBorderPanelStyles:Cu,uiPluginSheetsBorderPanelBoard:vu,uiPluginSheetsBorderPanelButton:Iu,uiPluginSheetsBorderPanelMoreIcon:Ru},Jr=`${Tt}_BORDER_PANEL_COMPONENT`,Qr=[{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"}],Mu=[{label:l.BorderStyleTypes.THIN,value:l.BorderStyleTypes.THIN},{label:l.BorderStyleTypes.HAIR,value:l.BorderStyleTypes.HAIR},{label:l.BorderStyleTypes.DOTTED,value:l.BorderStyleTypes.DOTTED},{label:l.BorderStyleTypes.DASHED,value:l.BorderStyleTypes.DASHED},{label:l.BorderStyleTypes.DASH_DOT,value:l.BorderStyleTypes.DASH_DOT},{label:l.BorderStyleTypes.DASH_DOT_DOT,value:l.BorderStyleTypes.DASH_DOT_DOT},{label:l.BorderStyleTypes.MEDIUM,value:l.BorderStyleTypes.MEDIUM},{label:l.BorderStyleTypes.MEDIUM_DASHED,value:l.BorderStyleTypes.MEDIUM_DASHED},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:l.BorderStyleTypes.THICK,value:l.BorderStyleTypes.THICK}];function bu(i){var a;const t=K.useDependency(v.ComponentManager),{onChange:e,value:n}=i;function o(c,d){e==null||e({...n,[d]:c})}function r(c){const d=t.get(c);return d&&p.jsx(d,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function s(c){c.stopPropagation()}return p.jsxs("section",{className:je.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:je.uiPluginSheetsBorderPanelPosition,children:Qr.map(c=>p.jsx("div",{className:je.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(c.value,"type"),children:r(c.icon)},c.value))}),p.jsxs("div",{className:je.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(ge.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:je.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(ge.ColorPicker,{onChange:c=>o(c,"color")})}),children:p.jsxs("a",{className:je.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(Qa,{extend:{colorChannel1:(a=n.color)!=null?a:"rgb(var(--primary-color))"}}),p.jsx("span",{className:je.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Ii,{})})]})})}),p.jsx("div",{children:p.jsx(ge.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(ge.Menu,{children:Mu.map(c=>p.jsx(ge.MenuItem,{eventKey:c.value.toString(),onClick:()=>o(c.value,"style"),children:p.jsx(Lo,{type:c.value})},c.value))})}),children:p.jsxs("a",{className:je.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(Lo,{type:l.BorderStyleTypes.THIN}),p.jsx("span",{className:je.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(Ii,{})})]})})})]})]})}const wu="univer-count-bar",Tu={countBar:wu},Eu=[50,80,100,130,150,170,200,400],Ou=100;function yu(){const i=K.useDependency(l.ICommandService),t=K.useDependency(l.IUniverInstanceService),e=K.useDependency(l.IContextService),n=c(),[o,r]=P.useState(n),a=!ge.useObservable(()=>H.combineLatest(e.subscribeContextValue$(l.FOCUSING_UNIVER_EDITOR),e.subscribeContextValue$(l.EDITOR_ACTIVATED)).pipe(H.map(([u,h])=>u&&!h),H.debounceTime(Ou)),!1,!0,[l.FOCUSING_UNIVER_EDITOR]);P.useEffect(()=>i.onCommandExecuted(h=>{if(h.id===Ye.id||h.id===_.SetWorksheetActivateCommand.id){const m=c();r(m)}}).dispose,[i]);function c(){const u=t.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()*100||100;return Math.round(u)}function d(u){r(u);const h=t.getCurrentUniverSheetInstance(),m=h==null?void 0:h.getActiveSheet();if(m==null)return;const g=u/100;i.executeCommand(qn.id,{unitId:h.getUnitId(),subUnitId:m.getSheetId(),zoomRatio:g})}return p.jsx(ge.Slider,{disabled:a,min:pi[0],value:o,shortcuts:Eu,onChange:d})}function xu(i){return p.jsx("section",{className:Tu.countBar,children:p.jsx(yu,{})})}const Au="univer-editor-container",Nu="univer-editor-input",Po={editorContainer:Au,editorInput:Nu},jn=-1e3,Uo={width:0,height:0,top:jn,left:jn},Du=()=>{const[i,t]=P.useState({...Uo}),e=K.useDependency(tn),n=K.useDependency(v.IEditorService),o={id:l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}};return P.useEffect(()=>{e.state$.subscribe(r=>{if(r==null)return;const{startX:s=jn,startY:a=jn,endX:c=0,endY:d=0,show:u=!1}=r;if(!u)t({...Uo});else{t({width:c-s,height:d-a,left:s,top:a});const h=n.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(h==null)return;const{left:m,top:g,width:S,height:f}=h.getBoundingClientRect();e.setRect({left:m,top:g,width:S,height:f})}})},[]),P.useEffect(()=>{e.setFocus(!0)},[i]),p.jsx("div",{className:Po.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx(v.TextEditor,{id:l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:Po.editorInput,snapshot:o,cancelDefaultResizeListener:!0,isSheetEditor:!0})})},Hu="univer-formula-box",Lu="univer-name-ranges",Pu="univer-name-ranges-input",Uu="univer-formula-bar",ku="univer-formula-icon",Vu="univer-formula-icon-wrapper",Bu="univer-icon-container",Fu="univer-icon-container-success",Wu="univer-formula-active",ju="univer-icon-container-error",$u="univer-formula-input",zu="univer-formula-content",Yu="univer-arrow-container",he={formulaBox:Hu,nameRanges:Lu,nameRangesInput:Pu,formulaBar:Uu,formulaIcon:ku,formulaIconWrapper:Vu,iconContainer:Bu,iconContainerSuccess:Fu,formulaActive:Wu,iconContainerError:ju,formulaInput:$u,formulaContent:zu,arrowContainer:Yu};function Xu(){const[i,t]=P.useState(he.formulaGrey),[e,n]=P.useState(0),o=K.useDependency(Gn),r=K.useDependency(Ee),s={id:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.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:l.HorizontalAlign.UNSPECIFIED,verticalAlign:l.VerticalAlign.TOP,centerAngle:0,vertexAngle:0,wrapStrategy:l.WrapStrategy.WRAP}}};P.useEffect(()=>{r.visible$.subscribe(m=>{t(m.visible?he.formulaActive:he.formulaGrey)})},[]);function a(m){if(m==null)return;const g=m.getBoundingClientRect();o.setPosition(g)}function c(){n(e===0?1:0),setTimeout(()=>{o.handleFoldBtnClick(e===1)},150)}function d(){r.isVisible().visible&&r.changeVisible({visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:v.KeyCode.ESC})}function u(){r.isVisible().visible&&r.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})}function h(){o.handleFxBtnClick(!0)}return p.jsxs("div",{className:he.formulaBox,style:{height:e===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:zt(he.iconContainer,he.iconContainerError,i),onClick:d,children:p.jsx(Ba,{})}),p.jsx("span",{className:zt(he.iconContainer,he.iconContainerSuccess,i),onClick:u,children:p.jsx(Fn,{})}),p.jsx("span",{className:he.iconContainer,onClick:h,children:p.jsx(Xa,{})})]})}),p.jsxs("div",{className:he.formulaInput,children:[p.jsx(v.TextEditor,{id:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,isSheetEditor:!0,resizeCallBack:a,cancelDefaultResizeListener:!0,onContextMenu:m=>m.preventDefault(),className:he.formulaContent,snapshot:s}),p.jsx("div",{className:he.arrowContainer,onClick:c,children:e===0?p.jsx(po,{}):p.jsx(po,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const Zu="univer-operate-container",Gu="univer-auto-fill-popup-menu",Ku="univer-auto-fill-popup-menu-item",qu="univer-auto-fill-popup-menu-item-icon",Ju="univer-auto-fill-popup-menu-item-title",Qu="univer-auto-fill-popup-menu-item-hide",eh="univer-btn-container",th="univer-btn-container-expand",st={operateContainer:Zu,autoFillPopupMenu:Gu,autoFillPopupMenuItem:Ku,autoFillPopupMenuItemIcon:qu,autoFillPopupMenuItemTitle:Ju,autoFillPopupMenuItemHide:Qu,btnContainer:eh,btnContainerExpand:th},nh=()=>{const[,i]=P.useState({});return P.useCallback(()=>i(t=>!t),[])},ih=()=>{var ne;const i=K.useDependency(l.ICommandService),t=K.useDependency(exports.SheetSkeletonManagerService),e=K.useDependency(l.IUniverInstanceService),n=K.useDependency(b.IRenderManagerService),o=K.useDependency(fe),r=K.useDependency(Jt),s=K.useDependency(l.LocaleService),[a,c]=P.useState([]),[d,u]=P.useState(!1),[h,m]=P.useState({row:-1,col:-1}),[g,S]=P.useState(ie.SERIES),[f,C]=P.useState(!1),R=()=>{C(!0)},M=()=>{C(!1)},w=nh(),E=ve(e,n);if(E==null)return null;const{scene:T}=E;if(P.useEffect(()=>{const D=[Pe.id,un.id,Ye.id,_.SetWorksheetActiveOperation.id,_.MoveRangeMutation.id];return i.onCommandExecuted(z=>{z.id===bt.id&&w(),D.includes(z.id)&&m({row:-1,col:-1})}).dispose},[w,i]),P.useEffect(()=>l.toDisposable(r.menu$.subscribe(U=>{c(U.map(z=>({...z,index:U.indexOf(z)})))})).dispose,[r]),P.useEffect(()=>l.toDisposable(r.showMenu$.subscribe(U=>{const{source:z,target:q}=r.autoFillLocation||{source:null,target:null};if(U&&z&&q){const oe=l.Rectangle.union(z,q);m({row:oe.endRow,col:oe.endColumn})}})).dispose,[r]),P.useEffect(()=>l.toDisposable(r.applyType$.subscribe(U=>{S(U)})).dispose,[r]),P.useEffect(()=>{function D(){u(!1)}return document.addEventListener("wheel",D),()=>{document.removeEventListener("wheel",D)}},[d]),h.col<0||h.row<0)return null;const O=(ne=t.getCurrent())==null?void 0:ne.skeleton,y=o.getViewPort(),x=T==null?void 0:T.scaleX,A=T==null?void 0:T.scaleY,k=T==null?void 0:T.getScrollXY(y);if(!x||!T||!x||!A||!k)return null;const L=(O==null?void 0:O.getNoMergeCellPositionByIndex(h.row,h.col).endX)||0,F=(O==null?void 0:O.getNoMergeCellPositionByIndex(h.row,h.col).endY)||0,V=O==null?void 0:O.convertTransformToOffsetX(L,x,k),j=O==null?void 0:O.convertTransformToOffsetY(F,A,k);if(V==null||j==null)return null;const $=D=>{u(D)},Z=D=>{i.executeCommand(Yr.id,{type:D.value})},W=d||f,G=a.filter(D=>!D.disable);return p.jsx("div",{onMouseEnter:R,onMouseLeave:M,style:{left:`${V+2}px`,top:`${j+2}px`,position:"absolute"},children:p.jsx(ge.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:st.autoFillPopupMenu,children:G.map(D=>p.jsxs("li",{onClick:()=>Z(D),className:st.autoFillPopupMenuItem,children:[p.jsx("span",{className:st.autoFillPopupMenuItemIcon,children:D.value===g&&p.jsx(Fn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:st.autoFillPopupMenuItemTitle,children:s.t(D.label)})]},D.index))}),visible:d,onVisibleChange:$,children:p.jsxs("div",{className:zt(st.btnContainer,{[st.btnContainerExpand]:d}),children:[p.jsx(Ua,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),W&&p.jsx(Ii,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},oh=()=>p.jsx("div",{className:st.operateContainer,children:p.jsx(ih,{})}),rh="univer-sheet-bar",sh="univer-sheet-bar-options",ah="univer-sheet-bar-options-divider",dn={sheetBar:rh,sheetBarOptions:sh,sheetBarOptionsDivider:ah},lh="univer-sheet-bar-btn",ch={sheetBarBtn:lh};function Hn(i){const{children:t,className:e,style:n,disabled:o=!1,onClick:r,...s}=i,a=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:ch.sheetBarBtn,style:n,disabled:o,onClick:a,...s,children:t})}const dh="univer-sheet-bar-menu",uh="univer-sheet-bar-menu-item",hh="univer-sheet-bar-menu-item-icon",mh="univer-sheet-bar-menu-item-hide",gh="univer-sheet-bar-menu-item-select",Sh="univer-sheet-bar-menu-item-label",Ke={sheetBarMenu:dh,sheetBarMenuItem:uh,sheetBarMenuItemIcon:hh,sheetBarMenuItemHide:mh,sheetBarMenuItemSelect:gh,sheetBarMenuItemLabel:Sh};function _h(i){const{style:t}=i,[e,n]=P.useState([]),[o,r]=P.useState(!1),s=K.useDependency(l.IUniverInstanceService),a=K.useDependency(l.ICommandService),c=K.useDependency(yt),d=s.getCurrentUniverSheetInstance(),u=f=>{const{sheetId:C}=f;C&&(f.hidden?a.executeCommand(_.SetWorksheetShowCommand.id,{value:C}):f.selected||a.executeCommand(_.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:C}),r(!1))};P.useEffect(()=>{m();const f=new l.DisposableCollection;return f.add(h()),f.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>{f.dispose()}},[]);const h=()=>a.onCommandExecuted(f=>{switch(f.id){case _.SetWorksheetHideMutation.id:case _.RemoveSheetMutation.id:case _.SetWorksheetNameMutation.id:case _.InsertSheetMutation.id:case _.SetWorksheetOrderMutation.id:case _.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const f=d.getSheets(),C=d.getActiveSheet(),R=f.map((M,w)=>({label:M.getName(),index:`${w}`,sheetId:M.getSheetId(),hidden:M.isSheetHidden()===l.BooleanNumber.TRUE,selected:C===M}));n(R)};function g(){r(!0)}const S=f=>{r(f)};return p.jsx(ge.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:Ke.sheetBarMenu,style:{...t},children:e.map(f=>p.jsxs("li",{onClick:()=>u(f),className:f.selected?`${Ke.sheetBarMenuItem} ${Ke.sheetBarMenuItemSelect}`:f.hidden?`${Ke.sheetBarMenuItem} ${Ke.sheetBarMenuItemHide}`:Ke.sheetBarMenuItem,children:[p.jsx("span",{className:Ke.sheetBarMenuItemIcon,children:f.selected?p.jsx(Fn,{}):f.hidden?p.jsx(za,{}):p.jsx(Fn,{})}),p.jsx("span",{className:Ke.sheetBarMenuItemLabel,children:f.label})]},f.index))}),visible:o,onVisibleChange:S,children:p.jsx(Hn,{children:p.jsx(Wa,{})})})}const fh="univer-slide-tab-bar-container",ph="univer-slide-tab-bar",Ch="univer-slide-tab-item",vh="univer-slide-tab-active",Ih="univer-slide-tab-span",Rh="univer-slide-tab-span-edit",Mh="univer-slide-tab-item-dropdown",Me={slideTabBarContainer:fh,slideTabBar:ph,slideTabItem:Ch,slideTabActive:vh,slideTabSpan:Ih,slideTabSpanEdit:Rh,slideTabItemDropdown:Mh};function bh(i){const{sheetId:t,label:e,color:n,selected:o}=i,[r,s]=P.useState(o),a=K.useDependency(l.ThemeService);P.useEffect(()=>{s(o)},[o]);const c=d=>{const u=a.getCurrentTheme(),h=u.textColor,m=u.colorWhite;return new l.ColorKit(d).isDark()?m:h};return p.jsx("div",{"data-id":t,className:r?`${Me.slideTabActive} ${Me.slideTabItem}`:Me.slideTabItem,style:{backgroundColor:!r&&n?n:"",color:!r&&n?c(n):"",boxShadow:r&&n?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${n}`:""},children:p.jsx("span",{className:Me.slideTabSpan,children:e})},t)}const wh={easeOutStrong(i,t,e,n){return-e*((i=i/n-1)*i*i*i-1)+t},backOut(i,t,e,n,o){return typeof o>"u"&&(o=.7),e*((i=i/n-1)*i*((o+1)*i+o)+1)+t}},Th={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class Eh{constructor(t){I(this,"_config");I(this,"_status",0);I(this,"_start",0);I(this,"_handle",0);I(this,"_delayHandle",null);this._config={...Th,...t},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...t){let e=0;return new Promise(n=>{for(let o=0;o<t.length;o++){const r=t[o],s=r._config,a=s.success;s.loop||(s.success=d=>{e++,a&&a.call(r,d),e===t.length&&n()})}})}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 t=Date.now()-this._start;t=t>=this._config.duration?this._config.duration:t;const n=wh[this._config.type](t,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(n),this._status===1){this._config.cancel(n),this._config.complete(n);return}if(t===this._config.duration){this._config.success(n),this._config.complete(n);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class lt{constructor(t,e){I(this,"_slideTabItem");I(this,"_animate");I(this,"_midline",0);I(this,"_translateX");I(this,"_scrollbar");I(this,"_slideTabBar");I(this,"_editMode");I(this,"_placeholder");this._slideTabItem=t,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=e,this._placeholder=null,this._scrollbar=e.getScrollbar(),this.update()}static midline(t){return t.getBoundingRect().x+t.getBoundingRect().width/2}static leftLine(t){return t.getBoundingRect().x}static rightLine(t){return t.getBoundingRect().x+t.getBoundingRect().width}static make(t,e){const n=[];return t.forEach(o=>n.push(new lt(o,e))),n}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var t;(t=this.getEditor())==null||t.focus()}selectAll(){const t=this.getEditor();t&&Ct.keepSelectAll(t)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(t){return this._translateX=t,this._slideTabItem.style.transform=`translateX(${t}px)`,this.getTranslateXDirection()}setEditor(t){let e=!0;if(this._editMode===!1){const n=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,n&&(n.removeAttribute("contentEditable"),n.removeEventListener("blur",o),n.removeEventListener("compositionstart",s),n.removeEventListener("compositionend",a),n.removeEventListener("input",c),n.removeEventListener("keydown",r),n.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(n==null?void 0:n.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}t&&t(d)}};let r=d=>{n&&(d.stopPropagation(),d.key==="Enter"&&n.blur())};const s=d=>{e=!1},a=d=>{e=!0},c=d=>{if(!n)return;const u=50;setTimeout(()=>{if(e){const h=n.innerText;h.length>u&&(n.innerText=h.substring(0,u),Ct.keepLastIndex(n))}},0)};n&&(n.setAttribute("contentEditable","true"),n.addEventListener("blur",o),n.addEventListener("compositionstart",s),n.addEventListener("compositionend",a),n.addEventListener("input",c),n.addEventListener("keydown",r),n.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,Ct.keepSelectAll(n))}}nameCheck(){const t=this._slideTabItem.querySelector("span");if(!t)return!1;const e=t.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(e)}animate(){return{translateX:t=>{this._translateX!==t&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Eh({begin:this._translateX,end:t,receive:e=>{this._slideTabItem.style.transform=`translateX(${e}px)`}}),this._translateX=t,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(t){this._slideTabItem.after(t._slideTabItem||t)}update(){this._midline=lt.midline(this)}disableFixed(){if(this._placeholder){const t=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),t.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const t=document.createElement("div"),e=this.getBoundingRect(),n=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=t,this._placeholder.style.width=`${e.width}px`,this._placeholder.style.height=`${e.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=n.margin,this._slideTabItem.style.background=n.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=n.boxSizing,this._slideTabItem.style.fontSize=n.fontSize,this._slideTabItem.style.fontFamily=n.fontFamily,this._slideTabItem.style.fontWeight=n.fontWeight,this._slideTabItem.style.color=n.color,this._slideTabItem.style.borderRadius=n.borderRadius,this._slideTabItem.style.left=`${e.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${e.y}px`,this._slideTabItem.style.width=`${e.width}px`,this._slideTabItem.style.height=`${e.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(t),document.body.appendChild(this._slideTabItem)}addEventListener(t,e,n){this._slideTabItem.addEventListener(t,e,n)}removeEventListener(t,e,n){this._slideTabItem.removeEventListener(t,e,n)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const t=this._slideTabItem.getBoundingClientRect();return t.x+=this._scrollbar.getScrollX(),t}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const t=lt.midline(this);return t>this._midline?1:t<this._midline?-1:0}equals(t){return t&&t._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class Oh{constructor(t){I(this,"_slideTabBar");I(this,"_scrollX");const e=t.primeval();this._scrollX=e.scrollLeft,this._slideTabBar=t}scrollX(t){const e=this._slideTabBar.primeval();e.scrollLeft=t,this._scrollX=e.scrollLeft}scrollRight(){const t=this._slideTabBar.primeval();t.scrollLeft=t.scrollWidth,this._scrollX=t.scrollLeft}getScrollX(){return this._scrollX}}const _t=class _t{constructor(t){I(this,"_activeTabItemIndex",0);I(this,"_slideTabBar");I(this,"_slideTabItems",[]);I(this,"_config");I(this,"_downActionX",0);I(this,"_moveActionX",0);I(this,"_compareIndex",0);I(this,"_activeTabItem",null);I(this,"_moveAction");I(this,"_upAction");I(this,"_downAction");I(this,"_wheelAction");I(this,"_scrollIncremental",0);I(this,"_compareDirection",0);I(this,"_autoScrollTime",null);I(this,"_slideScrollbar");I(this,"_longPressTimer",null);I(this,"_leftBoundingLine",0);I(this,"_rightBoundingLine",0);I(this,"_leftMoveX",0);I(this,"_rightMoveX",0);var s;if(t.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const e=t.slideTabBarContainer.querySelector(`.${(s=t.slideTabBarClassName)!=null?s:"slide-tab-bar"}`);if(e==null)throw new Error("not found slide-tab-bar");this._slideTabBar=e,this._slideScrollbar=new Oh(this),this._config=t,this._initConfig();let n=0,o=0,r=0;this._downAction=a=>{var O,y,x,A,k,L;if((O=this._activeTabItem)!=null&&O.isEditMode())return;const c=(x=(y=a.target)==null?void 0:y.closest(`.${t.slideTabBarItemClassName}`))==null?void 0:x.getAttribute("data-id"),d=this._slideTabItems.findIndex(F=>F.getId()===c);if(c==null||d===-1)return;if(this._activeTabItemIndex!==d){(A=this._activeTabItem)==null||A.removeEventListener("pointermove",this._moveAction),(k=this._activeTabItem)==null||k.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(a,c);return}if(this._compareIndex=d,this._downActionX=a.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(a.pointerId),(L=this._activeTabItem)==null||L.addEventListener("pointerup",this._upAction);const{x:h,width:m}=this._activeTabItem.getBoundingRect(),{x:g,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-g-f,this._rightMoveX=g+S-(h+m)+f,a.button===2||this._hasEditItem())return;const{pageX:C,pageY:R}=a,M=Date.now(),w=M-r<=_t.DoubleClickDelay,E=Math.abs(C-n)<10,T=Math.abs(R-o)<10;w&&E&&T&&this._activeTabItem.setEditor(),n=C,o=R,r=M,this._longPressTimer=setTimeout(()=>{var F,V;(F=this._activeTabItem)==null||F.enableFixed(),this._startAutoScroll(),u&&(u.setPointerCapture(a.pointerId),u.style.cursor="move",(V=this._activeTabItem)==null||V.addEventListener("pointermove",this._moveAction))},_t.LongPressDelay)},this._upAction=a=>{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(a.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(a,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=a=>{this._activeTabItem&&(this._moveActionX=a.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(a),this._scrollRight(a))},this._wheelAction=a=>{this.setScroll(a.deltaY)},this.addListener()}static checkedSkipSlide(t){let e=t.target;for(;e!=null&&e!==document.body;){if(e.getAttribute("data-slide-skip"))return!0;e=e.parentElement}return!1}static keepLastIndex(t){setTimeout(()=>{const e=window.getSelection();e&&(e.selectAllChildren(t),e.collapseToEnd())})}static keepSelectAll(t){setTimeout(()=>{const e=window.getSelection();if(!e)return;const n=document.createRange();n.selectNodeContents(t),e.removeAllRanges(),e.addRange(n)})}update(t){this._config.currentIndex=t,this._initConfig(),this.removeListener(),this.addListener()}primeval(){return this._slideTabBar}updateItems(){for(let t=0;t<this._slideTabItems.length;t++)this._slideTabItems[t].animate().cancel(),this._slideTabItems[t].translateX(0),this._slideTabItems[t].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 t=this._slideTabBar.parentElement;return t?this._slideTabBar.scrollWidth-t.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(t=>{t.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(t=>{t.removeEventListener("pointerdown",this._downAction)})}setScroll(t){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t),t>0){const e=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(t<0){const e=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(t){if(t>0){const e=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(t<0){const e=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(t){let e=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c<s&&c+d+n*2>s?(e=t?c-r.left-n:c+d-s+n,!0):!1}),e}calculateRightScrollX(t){let e=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c-n*2<s&&c+d>s?(e=t?c+d-r.left-r.width+n:c-s-n,!0):!1}),e}destroy(){this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null,this.removeListener()}_hasEditItem(){for(let t=0;t<this._slideTabItems.length;t++)if(this._slideTabItems[t].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(t){const e=this.getBoundingRect(),n=t.pageX-e.x;n<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(n-this._leftBoundingLine)*.1,50))}_scrollRight(t){const e=this.getBoundingRect(),n=t.pageX-e.x;n>e.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(n-(e.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 t=0;t<this._slideTabItems.length;t++){const e=this._slideTabItems[t],n=this._slideTabItems[t+1];n&&e.after(n)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const t=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),e=this._slideTabItems.length,n=[];for(let r=0;r<t&&!(r>=t);r++)n.push(this._slideTabItems[r]);for(let r=t+1;r<e;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=n.length-1;r>=0;r--){const s=n[r];lt.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 t=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),e=this._slideTabItems.length,n=[];for(let r=t+1;r<e;r++)n.push(this._slideTabItems[r]);for(let r=0;r<t;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=0;r<n.length;r++){const s=n[r];lt.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=t+r+1,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){var e;const t=this._slideTabBar.querySelectorAll(`.${(e=this._config.slideTabBarItemClassName)!=null?e:"slide-tab-item"}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=lt.make(t,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};I(_t,"LongPressDelay",500),I(_t,"DoubleClickDelay",300);let Ct=_t;function yh(){const[i,t]=P.useState([]),[e,n]=P.useState(""),[o,r]=P.useState(""),[s,a]=P.useState(!1),[c,d]=P.useState([0,0]),u=P.useRef({slideTabBar:null}),h=P.useRef(null),m=K.useDependency(l.IUniverInstanceService),g=K.useDependency(l.ICommandService),S=K.useDependency(yt),f=K.useDependency(l.LocaleService),C=K.useDependency(v.IConfirmService),R=K.useDependency(fe),M=K.useDependency(Ee);K.useInjector();const w=m.getCurrentUniverSheetInstance();P.useEffect(()=>{L();const D=E(),U=k(),z=[F(),V(),j(),$()];return()=>{U.dispose(),D.destroy(),z.forEach(q=>q.unsubscribe())}},[]),P.useEffect(()=>{i.length>0&&A()},[i]);const E=()=>{const D=new Ct({slideTabBarClassName:Me.slideTabBar,slideTabBarItemActiveClassName:Me.slideTabActive,slideTabBarItemClassName:Me.slideTabItem,slideTabBarSpanEditClassName:Me.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(U,z)=>{g.executeCommand(_.SetWorksheetNameCommand.id,{subUnitId:U,name:z})},onSlideEnd:(U,z)=>{g.executeCommand(_.SetWorksheetOrderCommand.id,{order:z})},onChangeTab:(U,z)=>{g.executeCommand(_.SetWorksheetActivateCommand.id,{subUnitId:z,unitId:w.getUnitId()}).then(()=>{U.button===2&&ne(!0)})},onScroll:U=>{S.setScroll(U)},onNameCheckAlert:U=>T(U)||O(U)});return u.current.slideTabBar=D,G(D),D},T=D=>{if(D.trim()===""){const U="sheetNameEmptyAlert";return C.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(){y(),C.close(U)},onConfirm(){y(),C.close(U)}}),!0}return!1},O=D=>{const U=m.getCurrentUniverSheetInstance();if(U.getActiveSheet().getName()===D)return!1;const oe=U.checkSheetName(D);if(oe){const re="sheetNameRepeatAlert";C.open({id:re,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){C.close(re),y()},onConfirm(){C.close(re),y()}})}return oe},y=()=>{R.endSelection(),setTimeout(()=>{var U;const D=(U=u.current.slideTabBar)==null?void 0:U.getActiveItem();D&&(D.focus(),D.selectAll())},0)},x=()=>{var D,U;(U=(D=u.current.slideTabBar)==null?void 0:D.getActiveItem())==null||U.setEditor()},A=()=>{var U;const D=i.findIndex(z=>z.selected);(U=u.current.slideTabBar)==null||U.update(D)},k=()=>g.onCommandExecuted(D=>{switch(D.id){case _.SetTabColorMutation.id:case _.SetWorksheetHideMutation.id:case _.RemoveSheetMutation.id:case _.SetWorksheetNameMutation.id:case _.InsertSheetMutation.id:case _.SetWorksheetOrderMutation.id:case _.SetWorksheetActiveOperation.id:L();break}}),L=()=>{const D=w.getActiveSheet().getSheetId();n(D);const U=w.getSheets(),z=w.getActiveSheet(),q=U.filter(oe=>!oe.isSheetHidden()).map((oe,re)=>{var Y;return{sheetId:oe.getSheetId(),label:oe.getName(),index:re,selected:z===oe,color:(Y=oe.getTabColor())!=null?Y:void 0}});t(q)},F=()=>S.scroll$.subscribe(D=>{Z(D)}),V=()=>S.scrollX$.subscribe(D=>{var U;(U=u.current.slideTabBar)==null||U.flipPage(D)}),j=()=>S.renameId$.subscribe(()=>{x()}),$=()=>S.addSheet$.subscribe(()=>{var D;(D=u.current.slideTabBar)==null||D.getScrollbar().scrollRight()}),Z=D=>{const{leftEnd:U,rightEnd:z}=D;let q="";U&&z?q="":U&&!z?q="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&z?q="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&!z&&(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)},W=D=>{S.setScroll({leftEnd:D.isLeftEnd(),rightEnd:D.isRightEnd()})},G=D=>{var q;const U=(q=h.current)==null?void 0:q.querySelector(`.${Me.slideTabBar}`);if(!U)return;new ResizeObserver(()=>{W(D)}).observe(U)},ne=D=>{var U,z,q,oe,re;if(!M.isForceKeepVisible()){if(D){const{left:Y}=(z=(U=h.current)==null?void 0:U.getBoundingClientRect())!=null?z:{},{left:X}=(re=(oe=(q=u.current.slideTabBar)==null?void 0:q.getActiveItem())==null?void 0:oe.getSlideTabItem().getBoundingClientRect())!=null?re:{};Y!==void 0&&X!==void 0&&d([X-Y,0])}a(D)}};return p.jsx(ge.Dropdown,{className:Me.slideTabItemDropdown,visible:s,align:{offset:c},trigger:["contextMenu"],overlay:p.jsx(v.Menu,{menuType:ce.SHEET_BAR,onOptionSelect:D=>{const{label:U,value:z}=D;g.executeCommand(U,{value:z,subUnitId:e}),a(!1)}}),onVisibleChange:ne,children:p.jsx("div",{className:Me.slideTabBarContainer,ref:h,children:p.jsx("div",{className:Me.slideTabBar,style:{boxShadow:o},children:i.map(D=>P.createElement(bh,{...D,key:D.sheetId,selected:e===D.sheetId}))})})})}const ko=100,xh=()=>{const[i,t]=P.useState(!0),[e,n]=P.useState(!0),o=K.useDependency(l.ICommandService),r=K.useDependency(yt);P.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;t(h),n(m)},a=()=>{o.executeCommand(_.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-ko)},d=()=>{r.setScrollX(ko)};return p.jsxs("div",{className:dn.sheetBar,children:[p.jsxs("div",{className:dn.sheetBarOptions,children:[p.jsx(Hn,{onClick:a,children:p.jsx(Ga,{})}),p.jsx(_h,{})]}),p.jsx(yh,{}),(!i||!e)&&p.jsxs("div",{className:`${dn.sheetBarOptions} ${dn.sheetBarOptionsDivider}`,children:[p.jsx(Hn,{disabled:i,onClick:c,children:p.jsx(Co,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(Hn,{disabled:e,onClick:d,children:p.jsx(Co,{})})]})]})};class Ah{constructor(){I(this,"_functions",[{func:ee.FUNCTION_NAMES_STATISTICAL.MAX,filter:t=>{var e,n,o,r;return((n=(e=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1&&((r=(o=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ee.FUNCTION_NAMES_STATISTICAL.MIN,filter:t=>{var e,n,o,r;return((n=(e=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1&&((r=(o=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ee.FUNCTION_NAMES_MATH.SUM,filter:t=>{var e,n,o,r;return((n=(e=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1&&((r=(o=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ee.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:t=>{var e,n;return((n=(e=t.values.find(o=>o.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1}},{func:ee.FUNCTION_NAMES_STATISTICAL.COUNT,filter:t=>{var e,n,o,r;return((n=(e=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1&&((r=(o=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}},{func:ee.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:t=>{var e,n,o,r;return((n=(e=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?n:0)>1&&((r=(o=t.values.find(s=>s.func===ee.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:o.value)!=null?r:0)>0}}]);I(this,"_state$",new H.BehaviorSubject(null));I(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(t){var n;const e={values:[],pattern:null};t==null||t.values.forEach(o=>{const r=this._functions.find(s=>s.func===o.func);r&&(r.filter===void 0||r.filter(t))&&e.values.push(o)}),e.pattern=(n=t==null?void 0:t.pattern)!=null?n:null,this._state$.next(e)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(t){this._functions.push(...t)}}const Xi=N.createIdentifier("univer.sheet-status-bar.service"),Nh="univer-status-bar",Dh="univer-single-mode",Hh="univer-status-bar-div",Lh="univer-statistic-list",Ph="univer-statistic-list-column",Uh="univer-statistic-item",kh="univer-statistic-picker",Vh="univer-statistic-picker-item",Bh="univer-statistic-more",gt={statusBar:Nh,singleMode:Dh,statusBarDiv:Hh,statisticList:Lh,statisticListColumn:Ph,statisticItem:Uh,statisticPicker:kh,statisticPickerItem:Vh,statisticMore:Bh},Fh=[ee.FUNCTION_NAMES_MATH.SUM,ee.FUNCTION_NAMES_STATISTICAL.AVERAGE,ee.FUNCTION_NAMES_STATISTICAL.MIN,ee.FUNCTION_NAMES_STATISTICAL.MAX],mi={[ee.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[ee.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[ee.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[ee.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[ee.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[ee.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[ee.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},gi=i=>{const t=K.useDependency(l.LocaleService),e=K.useDependency(v.IMessageService),n=K.useDependency(v.IClipboardInterfaceService),o=Wh(i),r=async()=>{await n.writeText(i.value.toString()),e.show({type:ge.MessageType.Success,content:t.t("statusbar.copied")})};return p.jsx(ge.Tooltip,{title:t.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:gt.statisticItem,onClick:r,children:p.jsx("span",{children:`${t.t((mi==null?void 0:mi[i.name])||i.name)}: ${o}`})},i.name)})};function Wh(i){const{pattern:t,value:e}=i;return typeof e!="number"?"Invalid input":e>=1e8?e.toExponential(2):t&&Fh.includes(i.name)?is.format(t,e):e.toLocaleString()}const Vo=800,jh=3,$h=()=>{const[i,t]=P.useState(window.innerWidth<Vo),[e,n]=P.useState(!0),o=K.useDependency(Xi),r=o.getFunctions().map((m,g)=>({name:m.func,value:0,show:!0,disable:!1,pattern:null})),[s,a]=P.useState(r),c=s.find(m=>m.show&&!m.disable),d=i&&c?[c]:s.filter(m=>m.show&&!m.disable);P.useEffect(()=>{const m=o.state$.subscribe(g=>{const S=g==null?void 0:g.values;if(!S||S.length===0)n(!1);else{n(!0);const f=s.map(C=>{var M;const R=S.find(w=>w.func===C.name);return R?(C.value=R.value,C.disable=!1):C.disable=!0,C.pattern=(M=g==null?void 0:g.pattern)!=null?M:null,C});a(f)}});return()=>{m.unsubscribe()}},[o]);const u=zh(()=>{const m=window.innerWidth<Vo;i!==m&&t(m)},100);P.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>jh){const m=[];d.forEach((g,S)=>{S%2===0&&m.push(d.slice(S,S+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((g,S)=>p.jsxs("div",{className:gt.statisticListColumn,children:[(g==null?void 0:g[0])&&p.jsx(gi,{...g==null?void 0:g[0]},g==null?void 0:g[0].name),(g==null?void 0:g[1])&&p.jsx(gi,{...g==null?void 0:g[1]},g==null?void 0:g[1].name)]},`stat-col-${S}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(gi,{...m},m.name))});return e&&p.jsxs("div",{className:zt(gt.statusBar,{[gt.singleMode]:i}),children:[p.jsx("div",{className:zt(gt.statisticList),children:h}),p.jsx("div",{className:gt.statusBarDiv})]})};function zh(i,t){let e;return function(...n){const o=this,r=function(){e=null,i.apply(o,n)};clearTimeout(e),e=setTimeout(r,t)}}function Yh(){return p.jsxs("section",{className:Fr.sheetContainer,"data-range-selector":!0,children:[p.jsx(xh,{}),p.jsx($h,{}),p.jsx(xu,{})]})}function Xh(){return p.jsx(p.Fragment,{children:p.jsx(Xu,{})})}function Zh(){return p.jsxs(p.Fragment,{children:[p.jsx(Du,{}),p.jsx(oh,{})]})}function Gh(i){const t=i.get(_.BorderStyleManagerService),e=_.getCurrentSheetDisabled$(i);return{id:_.SetBorderBasicCommand.id,icon:new H.Observable(n=>{const o="AllBorderSingle",r=i.get(_.BorderStyleManagerService),s=i.get(l.ICommandService).onCommandExecuted(a=>{var m;if(a.id!==_.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=Qr.find(g=>g.value===d),h=(m=u==null?void 0:u.icon)!=null?m:o;n.next(h)});return n.next(o),s.dispose}),group:v.MenuGroup.TOOLBAR_FORMAT,tooltip:"toolbar.border.main",positions:[v.MenuPosition.TOOLBAR_START],type:v.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Jr,hoverable:!1},value$:t.borderInfo$}],value$:t.borderInfo$,hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:e}}const Jn="sheet.menu.clear-selection";function Kh(){return{id:Jn,group:v.MenuGroup.CONTEXT_MENU_FORMAT,type:v.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[v.MenuPosition.CONTEXT_MENU,ce.COL_HEADER_CONTEXT_MENU,ce.ROW_HEADER_CONTEXT_MENU]}}function qh(){return{id:_.ClearSelectionContentCommand.id,type:v.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[Jn]}}function Jh(){return{id:_.ClearSelectionFormatCommand.id,type:v.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[Jn]}}function Qh(){return{id:_.ClearSelectionAllCommand.id,type:v.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[Jn]}}const nn="sheet.menu.delete";function em(){return{id:nn,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[v.MenuPosition.CONTEXT_MENU]}}function tm(){return{id:Zr.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[nn,ce.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function nm(){return{id:Xr.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,icon:"DeleteRow",positions:[nn,ce.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function im(){return{id:ji.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[nn]}}function om(){return{id:$i.id,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[nn]}}const Zi="sheet.menu.col-insert";function rm(){return{id:Zi,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ce.COL_HEADER_CONTEXT_MENU]}}const Gi="sheet.menu.row-insert";function sm(){return{id:Gi,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ce.ROW_HEADER_CONTEXT_MENU]}}const on="sheet.menu.cell-insert";function am(){return{id:on,group:v.MenuGroup.CONTEXT_MENU_LAYOUT,type:v.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[v.MenuPosition.CONTEXT_MENU]}}function lm(i){const t=i.get(_.SelectionManagerService);return{id:_.InsertRowBeforeCommand.id,type:v.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[Gi,on],hidden$:new H.Observable(e=>{const n=t.getSelections();e.next((n==null?void 0:n.length)!==1)})}}function cm(i){const t=i.get(_.SelectionManagerService);return{id:_.InsertRowAfterCommand.id,type:v.MenuItemType.BUTTON,positions:[Gi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new H.Observable(e=>{const n=t.getSelections();e.next((n==null?void 0:n.length)!==1)})}}function dm(i){const t=i.get(_.SelectionManagerService);return{id:_.InsertColBeforeCommand.id,type:v.MenuItemType.BUTTON,positions:[Zi,on],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new H.Observable(e=>{const n=t.getSelections();e.next((n==null?void 0:n.length)!==1)})}}function um(i){const t=i.get(_.SelectionManagerService);return{id:_.InsertColAfterCommand.id,type:v.MenuItemType.BUTTON,positions:[Zi],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new H.Observable(e=>{const n=t.getSelections();e.next((n==null?void 0:n.length)!==1)})}}function hm(){return{id:Yi.id,type:v.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[on]}}function mm(){return{id:zi.id,type:v.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[on]}}function gm(i){const t=_.getCurrentSheetDisabled$(i);return{id:Xe.id,icon:"MergeAllSingle",tooltip:"toolbar.mergeCell.main",positions:[v.MenuPosition.TOOLBAR_START],group:v.MenuGroup.TOOLBAR_LAYOUT,type:v.MenuItemType.SUBITEMS,hidden$:v.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:t}}function Sm(i){return{id:jr.id,type:v.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[Xe.id]}}function _m(i){return{id:$r.id,type:v.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[Xe.id]}}function fm(i){return{id:zr.id,type:v.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[Xe.id]}}function pm(i){return{id:_.RemoveWorksheetMergeCommand.id,type:v.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[Xe.id]}}function Cm(i){const t=i.get(l.IUniverInstanceService),e=i.get(l.ICommandService);return{id:Gr.id,type:v.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.delete",disabled$:new H.Observable(n=>{const o=e.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=t.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function vm(){return{id:_.CopySheetCommand.id,type:v.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.copy"}}function Im(){return{id:qr.id,type:v.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.rename"}}function Rm(){return{id:_.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[ce.SHEET_BAR],type:v.MenuItemType.SELECTOR,selections:[{label:{name:Zn,hoverable:!1}}]}}function Mm(i){const t=i.get(l.IUniverInstanceService),e=i.get(l.ICommandService);return{id:_.SetWorksheetHideCommand.id,type:v.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.hide",disabled$:new H.Observable(n=>{const o=e.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=t.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function bm(i){const t=i.get(l.IUniverInstanceService),e=i.get(l.ICommandService);return{id:Kr.id,type:v.MenuItemType.BUTTON,positions:[ce.SHEET_BAR],title:"sheetConfig.unhide",disabled$:new H.Observable(n=>{const o=e.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=t.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values());n.next(c.length===1)}});return n.next(!1),o.dispose})}}const wm={id:_.SetRowHiddenCommand.id,preconditions:i=>te(i),binding:v.KeyCode.Digit9|v.MetaKeys.CTRL_COMMAND},Tm={id:_.SetColHiddenCommand.id,preconditions:i=>te(i),binding:v.KeyCode.Digit0|v.MetaKeys.CTRL_COMMAND|v.MetaKeys.SHIFT},Em={id:Te.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_DOWN,priority:100,preconditions:te,staticParameters:{direction:l.Direction.DOWN}},Om={id:Te.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_UP,priority:100,preconditions:te,staticParameters:{direction:l.Direction.UP}},ym={id:Te.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_LEFT,priority:100,preconditions:te,staticParameters:{direction:l.Direction.LEFT}},xm={id:Te.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_RIGHT,priority:100,preconditions:te,staticParameters:{direction:l.Direction.RIGHT}},Am={id:dt.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:v.KeyCode.TAB,priority:100,preconditions:te,staticParameters:{direction:l.Direction.RIGHT,keycode:v.KeyCode.TAB}},Nm={id:dt.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:v.KeyCode.TAB|v.MetaKeys.SHIFT,priority:100,preconditions:te,staticParameters:{direction:l.Direction.LEFT,keycode:v.KeyCode.TAB}},Dm={id:dt.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:v.KeyCode.ENTER,priority:100,preconditions:te,staticParameters:{direction:l.Direction.DOWN,keycode:v.KeyCode.ENTER}},Hm={id:dt.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:v.KeyCode.ENTER|v.MetaKeys.SHIFT,priority:100,preconditions:te,staticParameters:{direction:l.Direction.UP,keycode:v.KeyCode.ENTER}},Lm={id:Te.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_DOWN|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.DOWN,jumpOver:Ue.moveGap}},Pm={id:Te.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_UP|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.UP,jumpOver:Ue.moveGap}},Um={id:Te.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_LEFT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.LEFT,jumpOver:Ue.moveGap}},km={id:Te.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:v.KeyCode.ARROW_RIGHT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.RIGHT,jumpOver:Ue.moveGap}},Vm={id:ke.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:v.KeyCode.ARROW_DOWN|v.MetaKeys.SHIFT,preconditions:te,staticParameters:{direction:l.Direction.DOWN}},Bm={id:ke.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:v.KeyCode.ARROW_UP|v.MetaKeys.SHIFT,preconditions:te,staticParameters:{direction:l.Direction.UP}},Fm={id:ke.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:v.KeyCode.ARROW_LEFT|v.MetaKeys.SHIFT,preconditions:te,staticParameters:{direction:l.Direction.LEFT}},Wm={id:ke.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:v.KeyCode.ARROW_RIGHT|v.MetaKeys.SHIFT,preconditions:te,staticParameters:{direction:l.Direction.RIGHT}},jm={id:ke.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:v.KeyCode.ARROW_DOWN|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.DOWN,jumpOver:Ue.moveGap}},$m={id:ke.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:v.KeyCode.ARROW_UP|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.UP,jumpOver:Ue.moveGap}},zm={id:ke.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:v.KeyCode.ARROW_LEFT|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.LEFT,jumpOver:Ue.moveGap}},Ym={id:ke.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:v.KeyCode.ARROW_RIGHT|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{direction:l.Direction.RIGHT,jumpOver:Ue.moveGap}},Xm={id:ar.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:v.KeyCode.A|v.MetaKeys.CTRL_COMMAND,preconditions:te,staticParameters:{expandToGapFirst:!0,loop:!0}},Zm={id:Li.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>te(i),binding:v.KeyCode.B|v.MetaKeys.CTRL_COMMAND},Gm={id:Pi.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>te(i),binding:v.KeyCode.I|v.MetaKeys.CTRL_COMMAND},Km={id:Ui.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>te(i),binding:v.KeyCode.U|v.MetaKeys.CTRL_COMMAND},qm={id:ki.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:i=>te(i),binding:v.KeyCode.X|v.MetaKeys.SHIFT|v.MetaKeys.CTRL_COMMAND},Jm={id:_.ClearSelectionContentCommand.id,preconditions:i=>te(i),binding:v.KeyCode.DELETE,mac:v.KeyCode.BACKSPACE},Qm={id:Kn.id,description:"shortcut.sheet.zoom-in",binding:v.KeyCode.EQUAL|v.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:te,priority:1,staticParameters:{delta:.2}},eg={id:l.NilCommand.id,binding:v.KeyCode.EQUAL|v.MetaKeys.CTRL_COMMAND},tg={id:Kn.id,description:"shortcut.sheet.zoom-out",binding:v.KeyCode.MINUS|v.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:te,priority:1,staticParameters:{delta:-.2}},ng={id:l.NilCommand.id,binding:v.KeyCode.MINUS|v.MetaKeys.CTRL_COMMAND},ig={id:Kn.id,description:"shortcut.sheet.reset-zoom",binding:v.KeyCode.Digit0|v.MetaKeys.CTRL_COMMAND,preconditions:te,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},og={id:l.NilCommand.id,binding:v.KeyCode.Digit0|v.MetaKeys.CTRL_COMMAND};var rg=Object.defineProperty,sg=Object.getOwnPropertyDescriptor,ag=(i,t,e,n)=>{for(var o=n>1?void 0:n?sg(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&rg(t,e,o),o},it=(i,t)=>(e,n)=>t(e,n,i);let Ln=class extends l.Disposable{constructor(i,t,e,n,o,r,s){super(),this._injector=i,this._componentManager=t,this._commandService=e,this._shortcutService=n,this._menuService=o,this._uiController=r,this._layoutService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Fi,yl)),this.disposeWithMe(i.register(Jr,bu)),this.disposeWithMe(i.register(Zn,ge.ColorPicker)),this.disposeWithMe(i.register(Lr,v.FontFamily)),this.disposeWithMe(i.register(Pr,v.FontFamilyItem)),this.disposeWithMe(i.register(Ur,v.FontSize))}_initCommands(){[jr,Xe,zr,$r,Kn,ke,Te,dt,qr,Gr,Xr,Zr,br,wr,ft,ar,Wr,_.SetBoldCommand,Gt,Pe,Li,Pi,Ui,ki,Cl,vl,Tr,Er,Wn,_.SetItalicCommand,_.SetStrikeThroughCommand,_.SetFontFamilyCommand,_.SetFontSizeCommand,Vi,xr,Bi,Ar,bt,Mn,Xn,Nr,Dr,Hr,_.SetUnderlineCommand,qn,Ye,Kr,Yr,zi,$i,Yi,ji].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[zl,Yl,Xl,Zl,Gl,Kl,ql,qh,Jh,Qh,Kh,rm,sm,am,lm,cm,dm,um,nm,rc,ac,sc,lc,tm,cc,Jl,dc,em,im,om,hm,mm,tc,nc,ic,oc,Ql,ec,xl,Al,Nl,Dl,Hl,Ll,Pl,Ul,kl,Vl,Bl,Gh,gm,Sm,_m,fm,pm,Fl,Wl,jl,$l,Cm,vm,Im,Rm,Mm,bm].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[Em,Om,ym,xm,Am,Nm,Dm,Hm,Lm,Pm,Um,km,Vm,Bm,Fm,Wm,jm,$m,zm,Ym,Xm,Qm,tg,ig,og,eg,ng,Zm,Gm,Km,qm,Jm,...Nc(),Dc,Hc,Pc,Uc,kc,Lc,wm,Tm].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>K.connectInjector(Xh,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>K.connectInjector(Yh,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>K.connectInjector(Zh,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts(),this._initFocusHandler()}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(l.UniverInstanceType.SHEET,i=>{this._injector.get(b.ITextSelectionRenderManager).focus()}))}};Ln=ag([l.OnLifecycle(l.LifecycleStages.Ready,Ln),it(0,N.Inject(N.Injector)),it(1,N.Inject(v.ComponentManager)),it(2,l.ICommandService),it(3,v.IShortcutService),it(4,v.IMenuService),it(5,v.IUIController),it(6,v.ILayoutService)],Ln);var lg=Object.defineProperty,cg=Object.getOwnPropertyDescriptor,dg=(i,t,e,n)=>{for(var o=n>1?void 0:n?cg(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&lg(t,e,o),o},ot=(i,t)=>(e,n)=>t(e,n,i);let Pn=class extends l.Disposable{constructor(t,e,n,o,r,s,a){super();I(this,"_calculateTimeout",-1);this._univerInstanceService=t,this._selectionManagerService=e,this._functionService=n,this._statusBarService=o,this._commandService=r,this._formulaDataModel=s,this._numfmtService=a,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(t=>{var e;((e=this._selectionManagerService.getCurrent())==null?void 0:e.pluginName)===_.NORMAL_SELECTION_PLUGIN_NAME&&t&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{var o;const n=(o=t[t.length-1])==null?void 0:o.primary;this._calculateSelection(t.map(r=>r.range),n)},100))}))),this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.pipe(H.debounceTime(100)).subscribe(t=>{var e,n;if(((e=this._selectionManagerService.getCurrent())==null?void 0:e.pluginName)===_.NORMAL_SELECTION_PLUGIN_NAME&&t){const o=(n=t[t.length-1])==null?void 0:n.primary;this._calculateSelection(t.map(r=>r.range),o)}}))),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===_.SetRangeValuesMutation.id){const e=this._selectionManagerService.getSelections();e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(e.map(n=>n.range))},100))}}))}_calculateSelection(t,e){var c;const n=this._univerInstanceService.getCurrentUniverSheetInstance(),o=n.getUnitId(),r=n.getActiveSheet().getSheetId(),s={},a=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(d=>{const u=d.getConfig();s[d.getSheetId()]={cellData:new l.ObjectMatrix(u.cellData),rowCount:u.rowCount,columnCount:u.columnCount}}),t!=null&&t.length){const d=t.map(f=>new ee.RangeReferenceObject(f,r,o));d.forEach(f=>{f.setUnitData({[o]:s}),a&&f.setArrayFormulaCellData(ee.convertUnitDataToRuntime(a))});const h=this._statusBarService.getFunctions().map(f=>{const C=this._functionService.getExecutor(f.func);if(!C)return;const R=d.map(E=>E.toArrayValueObject(!1)),M=C==null?void 0:C.calculate(...R),w=M==null?void 0:M.getValue();if(w)return{func:f.func,value:w}});if(h.every(f=>f===void 0))return;let m=null;if(e){const{actualRow:f,actualColumn:C}=e;m=(c=this._numfmtService.getValue(o,r,f,C))==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(t){return t.startRow===t.endRow&&t.startColumn===t.endColumn}};Pn=dg([l.OnLifecycle(l.LifecycleStages.Ready,Pn),ot(0,l.IUniverInstanceService),ot(1,N.Inject(_.SelectionManagerService)),ot(2,ee.IFunctionService),ot(3,Xi),ot(4,l.ICommandService),ot(5,N.Inject(ee.FormulaDataModel)),ot(6,N.Inject(_.INumfmtService))],Pn);var ug=Object.defineProperty,hg=Object.getOwnPropertyDescriptor,mg=(i,t,e,n)=>{for(var o=n>1?void 0:n?hg(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&ug(t,e,o),o},rt=(i,t)=>(e,n)=>t(e,n,i);let Un=class extends l.Disposable{constructor(i,t,e,n,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=t,this._commandService=e,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._scrollManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._zoomEventBinding()}_zoomEventBinding(){var t;const i=(t=this._getSheetObject())==null?void 0:t.scene;i!=null&&(i.getViewport(B.VIEW_MAIN),this.disposeWithMe(l.toDisposable(i.onMouseWheelObserver.add((e,n)=>{if(!e.ctrlKey)return;const o=Math.abs(e.deltaX);let r=o<40?.2:o<80?.4:.2;r*=e.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getActiveSheet(),c=a.getZoomRatio();let d=+Number.parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(qn.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:a.getSheetId()}),e.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(n)})))}_commandExecutedListener(){const i=[Ye.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(i.includes(t.id)){const e=this._currentUniverService.getCurrentUniverSheetInstance(),n=e.getActiveSheet(),o=t.params,{unitId:r,subUnitId:s}=o;if(!(r===e.getUnitId()&&s===n.getSheetId()))return;const a=n.getConfig().zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(i){const t=this._getSheetObject();t==null||t.scene.scale(i,i),t==null||t.spreadsheet.makeForceDirty()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Un=mg([l.OnLifecycle(l.LifecycleStages.Rendered,Un),rt(0,N.Inject(exports.SheetSkeletonManagerService)),rt(1,l.IUniverInstanceService),rt(2,l.ICommandService),rt(3,b.IRenderManagerService),rt(4,fe),rt(5,N.Inject(_.SelectionManagerService)),rt(6,N.Inject(Qe))],Un);var gg=Object.defineProperty,Sg=Object.getOwnPropertyDescriptor,_g=(i,t,e,n)=>{for(var o=n>1?void 0:n?Sg(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&gg(t,e,o),o},Ft=(i,t)=>(e,n)=>t(e,n,i);exports.SheetCanvasView=class extends l.RxDisposable{constructor(e,n,o,r,s){super();I(this,"_scene");I(this,"_currentWorkbook");I(this,"_fps$",new H.BehaviorSubject(""));I(this,"fps$",this._fps$.asObservable());this._currentUniverService=e,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._initialize()}_initialize(){this._init()}dispose(){this._fps$.complete()}_init(){this._currentUniverService.currentSheet$.subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverSheetsInstance().forEach(e=>{this._create(e)})}_create(e){if(e==null)return;const n=e.getUnitId();this._renderManagerService.has(n)||(this._currentWorkbook=e,this._addNewRender())}_addNewRender(){const e=this._currentWorkbook,n=e.getUnitId(),o=e.getContainer(),r=e.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(n,r):this._renderManagerService.createRender(n);const a=this._renderManagerService.getRenderById(n);if(a==null)return;const{scene:c,engine:d}=a;c.openTransformer(),this._scene=c,c.addLayer(new b.Layer(c,[],0),new b.Layer(c,[],2)),a!=null&&this._addComponent(a),e.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(e){const n=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();this._addViewport(r);const c=new b.Spreadsheet(Se.MAIN),d=new b.SpreadsheetRowHeader(Se.ROW),u=new b.SpreadsheetColumnHeader(Se.COLUMN),h=new b.Rect(Se.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});e.mainComponent=c,e.components.set(Se.MAIN,c),e.components.set(Se.ROW,d),e.components.set(Se.COLUMN,u),e.components.set(Se.LEFT_TOP,h),n.addObjects([c],so),n.addObjects([d,u,h],Je),n.enableLayerCache(so,Je),this._sheetSkeletonManagerService.setCurrent({sheetId:a,unitId:s})}_addViewport(e){const n=this._scene;if(n==null)return;const{rowHeader:o,columnHeader:r}=e.getConfig(),s=new b.Viewport(B.VIEW_MAIN,n,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0});return new b.Viewport(B.VIEW_ROW_TOP,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(B.VIEW_ROW_BOTTOM,n,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),new b.Viewport(B.VIEW_COLUMN_LEFT,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(B.VIEW_COLUMN_RIGHT,n,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),new b.Viewport(B.VIEW_LEFT_TOP,n,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),new b.Viewport(B.VIEW_MAIN_LEFT_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(B.VIEW_MAIN_LEFT,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(B.VIEW_MAIN_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),this.disposeWithMe(l.toDisposable(n.onMouseWheelObserver.add((a,c)=>{if(a.ctrlKey)return;let d=0,u=0;const h=s.limitedScroll();if(a.inputIndex===b.PointerInput.MouseWheelX){const g=Math.abs(a.deltaX);a.deltaX>0?d=g:d=-g,this._commandService.executeCommand(Mn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()}if(a.inputIndex===b.PointerInput.MouseWheelY){let g=Math.abs(a.deltaY);a.shiftKey?(g*=3,a.deltaY>0?d=g:d=-g,this._commandService.executeCommand(Mn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()):(a.deltaY>0?u=g:u=-g,this._commandService.executeCommand(Mn.id,{offsetY:u}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedY||c.stopPropagation():s.isWheelPreventDefaultY?a.preventDefault():h!=null&&h.isLimitedY||a.preventDefault())}a.inputIndex,b.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}))),new b.ScrollBar(s),n.attachControl(),s}};exports.SheetCanvasView=_g([l.OnLifecycle(l.LifecycleStages.Ready,exports.SheetCanvasView),Ft(0,l.IUniverInstanceService),Ft(1,l.ICommandService),Ft(2,b.IRenderManagerService),Ft(3,fe),Ft(4,N.Inject(exports.SheetSkeletonManagerService))],exports.SheetCanvasView);var fg=Object.defineProperty,pg=Object.getOwnPropertyDescriptor,Cg=(i,t,e,n)=>{for(var o=n>1?void 0:n?pg(t,e):t,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&fg(t,e,o),o},Si=(i,t)=>(e,n)=>t(e,n,i),_i;exports.UniverSheetsUIPlugin=(_i=class extends l.Plugin{constructor(t,e,n,o){super(jo),this._injector=e,this._localeService=n,this._currentUniverService=o,this._localeService.load({zhCN:kr})}onStarting(t){[[exports.SheetCanvasView],[Xt],[Ee,{useClass:exports.EditorBridgeService}],[Rt,{useClass:exports.SheetClipboardService}],[yt,{useClass:su}],[wt,{useClass:Ri}],[tn,{useClass:Vr}],[Gn,{useClass:Sc}],[Jt,{useClass:exports.AutoFillService}],[Qe],[exports.SheetSkeletonManagerService],[fe,{useClass:exports.SelectionRenderService}],[Xi,{useClass:Ah}],[qt,{useClass:exports.MarkSelectionService}],[mn],[gn],[In],[pn],[Cn],[Rn],[bn],[wn],[Tn],[En],[On],[xn],[pt],[Nn],[Sn],[_n],[An],[Dn],[Ln],[vn],[Un],[exports.AutoFillController],[Pn],[fn],[yn]].forEach(e=>t.add(e))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const t=this._currentUniverService;t.currentSheet$.pipe(ns.filter(e=>!!e)).subscribe(e=>{t.focusUniverInstance(e.getUnitId())})}},I(_i,"type",l.PluginType.Sheet),_i);exports.UniverSheetsUIPlugin=Cg([Si(1,N.Inject(N.Injector)),Si(2,N.Inject(l.LocaleService)),Si(3,l.IUniverInstanceService)],exports.UniverSheetsUIPlugin);exports.APPLY_TYPE=ie;exports.AutoFillCommand=Yo;exports.COPY_TYPE=at;exports.CellEditorManagerService=Vr;exports.DATA_TYPE=de;exports.DefaultRightMenuConfig=Bo;exports.DefaultSheetContainerConfig=Wo;exports.DefaultSheetUIConfig=os;exports.DefaultToolbarConfig=Fo;exports.ExpandSelectionCommand=ke;exports.IAutoFillService=Jt;exports.ICellEditorManagerService=tn;exports.IEditorBridgeService=Ee;exports.IFormulaEditorManagerService=Gn;exports.IMarkSelectionService=qt;exports.ISelectionRenderService=fe;exports.ISheetClipboardService=Rt;exports.JumpOver=Ue;exports.MoveSelectionCommand=Te;exports.PASTE_SPECIAL_MENU_ID=Ot;exports.PREDEFINED_HOOK_NAME=_e;exports.RangeSelector=sl;exports.SHEET_UI_PLUGIN_NAME=jo;exports.SelectionShape=Bn;exports.SetCellEditVisibleArrowOperation=Gt;exports.SetScrollOperation=bt;exports.SetZoomRatioOperation=Ye;exports.SheetCopyCommand=Qo;exports.SheetPasteCommand=Mt;exports.VIEWPORT_KEY=B;exports.enUS=hc;exports.getAutoFillRepeatRange=ps;exports.getCoordByCell=Mi;exports.getCoordByOffset=It;exports.getEditorObject=zn;exports.getRepeatRange=gc;exports.getSheetObject=ve;exports.getTransformCoord=hn;exports.whenFormulaEditorActivated=vs;exports.whenSheetEditorFocused=te;exports.zhCN=kr;